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.

252389 lines
6.4MB

  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 0
  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 0
  152. #endif
  153. #if (JUCE_IPHONE || JUCE_LINUX) && JUCE_QUICKTIME
  154. #undef JUCE_QUICKTIME
  155. #endif
  156. #ifndef JUCE_OPENGL
  157. #define JUCE_OPENGL 1
  158. #endif
  159. #ifndef JUCE_USE_FLAC
  160. #define JUCE_USE_FLAC 1
  161. #endif
  162. #ifndef JUCE_USE_OGGVORBIS
  163. #define JUCE_USE_OGGVORBIS 1
  164. #endif
  165. #if (! defined (JUCE_USE_CDBURNER)) && ! (JUCE_WINDOWS && ! JUCE_MSVC)
  166. #define JUCE_USE_CDBURNER 0
  167. #endif
  168. #ifndef JUCE_USE_CDREADER
  169. #define JUCE_USE_CDREADER 1
  170. #endif
  171. #if (JUCE_QUICKTIME || JUCE_WINDOWS) && ! defined (JUCE_USE_CAMERA)
  172. // #define JUCE_USE_CAMERA 1
  173. #endif
  174. #ifndef JUCE_ENABLE_REPAINT_DEBUGGING
  175. // #define JUCE_ENABLE_REPAINT_DEBUGGING 1
  176. #endif
  177. #ifndef JUCE_USE_XINERAMA
  178. #define JUCE_USE_XINERAMA 1
  179. #endif
  180. #ifndef JUCE_USE_XSHM
  181. #define JUCE_USE_XSHM 1
  182. #endif
  183. #ifndef JUCE_USE_XRENDER
  184. //#define JUCE_USE_XRENDER 1
  185. #endif
  186. #ifndef JUCE_PLUGINHOST_VST
  187. // #define JUCE_PLUGINHOST_VST 1
  188. #endif
  189. #ifndef JUCE_PLUGINHOST_AU
  190. // #define JUCE_PLUGINHOST_AU 1
  191. #endif
  192. #ifndef JUCE_ONLY_BUILD_CORE_LIBRARY
  193. //#define JUCE_ONLY_BUILD_CORE_LIBRARY 1
  194. #endif
  195. #ifndef JUCE_WEB_BROWSER
  196. #define JUCE_WEB_BROWSER 0
  197. #endif
  198. #ifndef JUCE_SUPPORT_CARBON
  199. #define JUCE_SUPPORT_CARBON 1
  200. #endif
  201. #ifndef JUCE_INCLUDE_ZLIB_CODE
  202. #define JUCE_INCLUDE_ZLIB_CODE 1
  203. #endif
  204. #ifndef JUCE_INCLUDE_FLAC_CODE
  205. #define JUCE_INCLUDE_FLAC_CODE 1
  206. #endif
  207. #ifndef JUCE_INCLUDE_OGGVORBIS_CODE
  208. #define JUCE_INCLUDE_OGGVORBIS_CODE 1
  209. #endif
  210. #ifndef JUCE_INCLUDE_PNGLIB_CODE
  211. #define JUCE_INCLUDE_PNGLIB_CODE 1
  212. #endif
  213. #ifndef JUCE_INCLUDE_JPEGLIB_CODE
  214. #define JUCE_INCLUDE_JPEGLIB_CODE 1
  215. #endif
  216. #ifndef JUCE_CHECK_MEMORY_LEAKS
  217. #define JUCE_CHECK_MEMORY_LEAKS 1
  218. #endif
  219. #ifndef JUCE_CATCH_UNHANDLED_EXCEPTIONS
  220. #define JUCE_CATCH_UNHANDLED_EXCEPTIONS 1
  221. #endif
  222. // If only building the core classes, we can explicitly turn off some features to avoid including them:
  223. #if JUCE_ONLY_BUILD_CORE_LIBRARY
  224. #undef JUCE_QUICKTIME
  225. #define JUCE_QUICKTIME 0
  226. #undef JUCE_OPENGL
  227. #define JUCE_OPENGL 0
  228. #undef JUCE_USE_CDBURNER
  229. #define JUCE_USE_CDBURNER 0
  230. #undef JUCE_USE_CDREADER
  231. #define JUCE_USE_CDREADER 0
  232. #undef JUCE_WEB_BROWSER
  233. #define JUCE_WEB_BROWSER 0
  234. #undef JUCE_PLUGINHOST_AU
  235. #define JUCE_PLUGINHOST_AU 0
  236. #undef JUCE_PLUGINHOST_VST
  237. #define JUCE_PLUGINHOST_VST 0
  238. #endif
  239. #endif
  240. /*** End of inlined file: juce_Config.h ***/
  241. // FORCE_AMALGAMATOR_INCLUDE
  242. #ifndef JUCE_BUILD_CORE
  243. #define JUCE_BUILD_CORE 1
  244. #endif
  245. #ifndef JUCE_BUILD_MISC
  246. #define JUCE_BUILD_MISC 1
  247. #endif
  248. #ifndef JUCE_BUILD_GUI
  249. #define JUCE_BUILD_GUI 1
  250. #endif
  251. #ifndef JUCE_BUILD_NATIVE
  252. #define JUCE_BUILD_NATIVE 1
  253. #endif
  254. #if JUCE_ONLY_BUILD_CORE_LIBRARY
  255. #undef JUCE_BUILD_MISC
  256. #undef JUCE_BUILD_GUI
  257. #endif
  258. //==============================================================================
  259. #if JUCE_BUILD_NATIVE || JUCE_BUILD_CORE || (JUCE_BUILD_MISC && (JUCE_PLUGINHOST_VST || JUCE_PLUGINHOST_AU))
  260. #if JUCE_WINDOWS
  261. /*** Start of inlined file: juce_win32_NativeIncludes.h ***/
  262. #ifndef __JUCE_WIN32_NATIVEINCLUDES_JUCEHEADER__
  263. #define __JUCE_WIN32_NATIVEINCLUDES_JUCEHEADER__
  264. #ifndef STRICT
  265. #define STRICT 1
  266. #endif
  267. #undef WIN32_LEAN_AND_MEAN
  268. #define WIN32_LEAN_AND_MEAN 1
  269. #ifdef _MSC_VER
  270. #pragma warning (push)
  271. #pragma warning (disable : 4100 4201 4514 4312 4995)
  272. #endif
  273. #define _WIN32_WINNT 0x0500
  274. #define _UNICODE 1
  275. #define UNICODE 1
  276. #ifndef _WIN32_IE
  277. #define _WIN32_IE 0x0400
  278. #endif
  279. #include <windows.h>
  280. #include <windowsx.h>
  281. #include <commdlg.h>
  282. #include <shellapi.h>
  283. #include <mmsystem.h>
  284. #include <vfw.h>
  285. #include <tchar.h>
  286. #include <stddef.h>
  287. #include <ctime>
  288. #include <wininet.h>
  289. #include <nb30.h>
  290. #include <iphlpapi.h>
  291. #include <mapi.h>
  292. #include <float.h>
  293. #include <process.h>
  294. #include <Exdisp.h>
  295. #include <exdispid.h>
  296. #include <shlobj.h>
  297. #if ! JUCE_MINGW
  298. #include <crtdbg.h>
  299. #include <comutil.h>
  300. #endif
  301. #if JUCE_OPENGL
  302. #include <gl/gl.h>
  303. #endif
  304. #undef PACKED
  305. #if JUCE_ASIO
  306. #include "iasiodrv.h"
  307. #endif
  308. #if JUCE_USE_CDBURNER
  309. #include <imapi.h>
  310. #include <imapierror.h>
  311. #endif
  312. #if JUCE_USE_CAMERA
  313. #include <dshow.h>
  314. #include <qedit.h>
  315. #include <dshowasf.h>
  316. #endif
  317. #if JUCE_WASAPI
  318. #include <MMReg.h>
  319. #include <mmdeviceapi.h>
  320. #include <Audioclient.h>
  321. #include <Avrt.h>
  322. #include <functiondiscoverykeys.h>
  323. #endif
  324. #if JUCE_QUICKTIME
  325. #include <Movies.h>
  326. #include <QTML.h>
  327. #include <QuickTimeComponents.h>
  328. #include <MediaHandlers.h>
  329. #include <ImageCodec.h>
  330. #import <QTOLibrary.dll>
  331. #import <QTOControl.dll>
  332. #endif
  333. #ifdef _MSC_VER
  334. #pragma warning (pop)
  335. #endif
  336. template <class T>
  337. class ComSmartPtr
  338. {
  339. public:
  340. ComSmartPtr() throw() : p (0) {}
  341. ComSmartPtr (T* const p_) : p (p_) { if (p_ != 0) p_->AddRef(); }
  342. ComSmartPtr (const ComSmartPtr<T>& p_) : p (p_.p) { if (p != 0) p->AddRef(); }
  343. ~ComSmartPtr() { if (p != 0) p->Release(); }
  344. operator T*() const throw() { return p; }
  345. T& operator*() const throw() { return *p; }
  346. T** operator&() throw() { return &p; }
  347. T* operator->() const throw() { return p; }
  348. T* operator= (T* const newP)
  349. {
  350. if (newP != 0)
  351. newP->AddRef();
  352. if (p != 0)
  353. p->Release();
  354. p = newP;
  355. return newP;
  356. }
  357. T* operator= (const ComSmartPtr<T>& newP) { return operator= (newP.p); }
  358. HRESULT CoCreateInstance (REFCLSID rclsid, DWORD dwClsContext)
  359. {
  360. #ifndef __MINGW32__
  361. operator= (0);
  362. return ::CoCreateInstance (rclsid, 0, dwClsContext, __uuidof(T), (void**) &p);
  363. #else
  364. return S_FALSE;
  365. #endif
  366. }
  367. T* p;
  368. };
  369. #endif // __JUCE_WIN32_NATIVEINCLUDES_JUCEHEADER__
  370. /*** End of inlined file: juce_win32_NativeIncludes.h ***/
  371. #elif JUCE_LINUX
  372. /*** Start of inlined file: juce_linux_NativeIncludes.h ***/
  373. #ifndef __JUCE_LINUX_NATIVEINCLUDES_JUCEHEADER__
  374. #define __JUCE_LINUX_NATIVEINCLUDES_JUCEHEADER__
  375. #include <sched.h>
  376. #include <pthread.h>
  377. #include <sys/time.h>
  378. #include <errno.h>
  379. #include <sys/stat.h>
  380. #include <sys/dir.h>
  381. #include <sys/ptrace.h>
  382. #include <sys/vfs.h>
  383. #include <sys/wait.h>
  384. #include <fnmatch.h>
  385. #include <utime.h>
  386. #include <pwd.h>
  387. #include <fcntl.h>
  388. #include <dlfcn.h>
  389. #include <netdb.h>
  390. #include <arpa/inet.h>
  391. #include <netinet/in.h>
  392. #include <sys/types.h>
  393. #include <sys/ioctl.h>
  394. #include <sys/socket.h>
  395. #include <linux/if.h>
  396. #include <sys/sysinfo.h>
  397. #include <sys/file.h>
  398. #include <signal.h>
  399. #include <ft2build.h>
  400. #include FT_FREETYPE_H
  401. #include <X11/Xlib.h>
  402. #include <X11/Xatom.h>
  403. #include <X11/Xresource.h>
  404. #include <X11/Xutil.h>
  405. #include <X11/Xmd.h>
  406. #include <X11/keysym.h>
  407. #include <X11/cursorfont.h>
  408. #if JUCE_USE_XINERAMA
  409. #include <X11/extensions/Xinerama.h>
  410. #endif
  411. #if JUCE_USE_XSHM
  412. #include <X11/extensions/XShm.h>
  413. #include <sys/shm.h>
  414. #include <sys/ipc.h>
  415. #endif
  416. #if JUCE_USE_XRENDER
  417. // If you're missing these headers, try installing the libxrender-dev and libxcomposite-dev
  418. #include <X11/extensions/Xrender.h>
  419. #include <X11/extensions/Xcomposite.h>
  420. #endif
  421. #if JUCE_OPENGL
  422. #include <GL/glx.h>
  423. #endif
  424. #undef KeyPress
  425. #if JUCE_ALSA
  426. #include <alsa/asoundlib.h>
  427. #endif
  428. #if JUCE_JACK
  429. #include <jack/jack.h>
  430. //#include <jack/transport.h>
  431. #endif
  432. #undef SIZEOF
  433. #endif // __JUCE_LINUX_NATIVEINCLUDES_JUCEHEADER__
  434. /*** End of inlined file: juce_linux_NativeIncludes.h ***/
  435. #elif JUCE_MAC || JUCE_IPHONE
  436. /*** Start of inlined file: juce_mac_NativeIncludes.h ***/
  437. #ifndef __JUCE_MAC_NATIVEINCLUDES_JUCEHEADER__
  438. #define __JUCE_MAC_NATIVEINCLUDES_JUCEHEADER__
  439. #define USE_COREGRAPHICS_RENDERING 1
  440. #if JUCE_IPHONE
  441. #import <Foundation/Foundation.h>
  442. #import <UIKit/UIKit.h>
  443. #import <AudioToolbox/AudioToolbox.h>
  444. #import <AVFoundation/AVFoundation.h>
  445. #import <CoreData/CoreData.h>
  446. #import <MobileCoreServices/MobileCoreServices.h>
  447. #import <QuartzCore/QuartzCore.h>
  448. #include <sys/fcntl.h>
  449. #if JUCE_OPENGL
  450. #include <OpenGLES/ES1/gl.h>
  451. #include <OpenGLES/ES1/glext.h>
  452. #endif
  453. #else
  454. #import <Cocoa/Cocoa.h>
  455. #import <CoreAudio/HostTime.h>
  456. #import <CoreAudio/AudioHardware.h>
  457. #import <CoreMIDI/MIDIServices.h>
  458. #import <QTKit/QTKit.h>
  459. #import <WebKit/WebKit.h>
  460. #import <DiscRecording/DiscRecording.h>
  461. #import <IOKit/IOKitLib.h>
  462. #import <IOKit/IOCFPlugIn.h>
  463. #import <IOKit/hid/IOHIDLib.h>
  464. #import <IOKit/hid/IOHIDKeys.h>
  465. #import <IOKit/pwr_mgt/IOPMLib.h>
  466. #include <Carbon/Carbon.h>
  467. #include <sys/dir.h>
  468. #include <sys/socket.h>
  469. #endif
  470. #include <sys/sysctl.h>
  471. #include <sys/stat.h>
  472. #include <sys/param.h>
  473. #include <sys/mount.h>
  474. #include <fnmatch.h>
  475. #include <utime.h>
  476. #include <dlfcn.h>
  477. #include <ifaddrs.h>
  478. #include <net/if_dl.h>
  479. #include <mach/mach_time.h>
  480. #if MACOS_10_4_OR_EARLIER
  481. #include <GLUT/glut.h>
  482. #endif
  483. #if ! CGFLOAT_DEFINED
  484. #define CGFloat float
  485. #endif
  486. #endif // __JUCE_MAC_NATIVEINCLUDES_JUCEHEADER__
  487. /*** End of inlined file: juce_mac_NativeIncludes.h ***/
  488. #else
  489. #error "Unknown platform!"
  490. #endif
  491. #endif
  492. //==============================================================================
  493. #define DONT_SET_USING_JUCE_NAMESPACE 1
  494. #undef max
  495. #undef min
  496. #define NO_DUMMY_DECL
  497. #if JUCE_BUILD_NATIVE
  498. #include "juce_amalgamated.h" // FORCE_AMALGAMATOR_INCLUDE
  499. #endif
  500. #if (defined(_MSC_VER) && (_MSC_VER <= 1200))
  501. #pragma warning (disable: 4309 4305)
  502. #endif
  503. #if JUCE_MAC && JUCE_32BIT && JUCE_SUPPORT_CARBON && JUCE_BUILD_NATIVE && ! JUCE_ONLY_BUILD_CORE_LIBRARY
  504. BEGIN_JUCE_NAMESPACE
  505. /*** Start of inlined file: juce_mac_CarbonViewWrapperComponent.h ***/
  506. #ifndef __JUCE_MAC_CARBONVIEWWRAPPERCOMPONENT_JUCEHEADER__
  507. #define __JUCE_MAC_CARBONVIEWWRAPPERCOMPONENT_JUCEHEADER__
  508. class CarbonViewWrapperComponent : public Component,
  509. public ComponentMovementWatcher,
  510. public Timer
  511. {
  512. public:
  513. CarbonViewWrapperComponent()
  514. : ComponentMovementWatcher (this),
  515. wrapperWindow (0),
  516. embeddedView (0),
  517. recursiveResize (false)
  518. {
  519. }
  520. virtual ~CarbonViewWrapperComponent()
  521. {
  522. jassert (embeddedView == 0); // must call deleteWindow() in the subclass's destructor!
  523. }
  524. virtual HIViewRef attachView (WindowRef windowRef, HIViewRef rootView) = 0;
  525. virtual void removeView (HIViewRef embeddedView) = 0;
  526. virtual void mouseDown (int x, int y) {}
  527. virtual void paint() {}
  528. virtual bool getEmbeddedViewSize (int& w, int& h)
  529. {
  530. if (embeddedView == 0)
  531. return false;
  532. HIRect bounds;
  533. HIViewGetBounds (embeddedView, &bounds);
  534. w = jmax (1, roundToInt (bounds.size.width));
  535. h = jmax (1, roundToInt (bounds.size.height));
  536. return true;
  537. }
  538. void createWindow()
  539. {
  540. if (wrapperWindow == 0)
  541. {
  542. Rect r;
  543. r.left = getScreenX();
  544. r.top = getScreenY();
  545. r.right = r.left + getWidth();
  546. r.bottom = r.top + getHeight();
  547. CreateNewWindow (kDocumentWindowClass,
  548. (WindowAttributes) (kWindowStandardHandlerAttribute | kWindowCompositingAttribute
  549. | kWindowNoShadowAttribute | kWindowNoTitleBarAttribute),
  550. &r, &wrapperWindow);
  551. jassert (wrapperWindow != 0);
  552. if (wrapperWindow == 0)
  553. return;
  554. NSWindow* carbonWindow = [[NSWindow alloc] initWithWindowRef: wrapperWindow];
  555. NSWindow* ownerWindow = [((NSView*) getWindowHandle()) window];
  556. [ownerWindow addChildWindow: carbonWindow
  557. ordered: NSWindowAbove];
  558. embeddedView = attachView (wrapperWindow, HIViewGetRoot (wrapperWindow));
  559. EventTypeSpec windowEventTypes[] = { { kEventClassWindow, kEventWindowGetClickActivation },
  560. { kEventClassWindow, kEventWindowHandleDeactivate } };
  561. EventHandlerUPP upp = NewEventHandlerUPP (carbonEventCallback);
  562. InstallWindowEventHandler (wrapperWindow, upp,
  563. sizeof (windowEventTypes) / sizeof (EventTypeSpec),
  564. windowEventTypes, this, &eventHandlerRef);
  565. setOurSizeToEmbeddedViewSize();
  566. setEmbeddedWindowToOurSize();
  567. creationTime = Time::getCurrentTime();
  568. }
  569. }
  570. void deleteWindow()
  571. {
  572. removeView (embeddedView);
  573. embeddedView = 0;
  574. if (wrapperWindow != 0)
  575. {
  576. RemoveEventHandler (eventHandlerRef);
  577. DisposeWindow (wrapperWindow);
  578. wrapperWindow = 0;
  579. }
  580. }
  581. void setOurSizeToEmbeddedViewSize()
  582. {
  583. int w, h;
  584. if (getEmbeddedViewSize (w, h))
  585. {
  586. if (w != getWidth() || h != getHeight())
  587. {
  588. startTimer (50);
  589. setSize (w, h);
  590. if (getParentComponent() != 0)
  591. getParentComponent()->setSize (w, h);
  592. }
  593. else
  594. {
  595. startTimer (jlimit (50, 500, getTimerInterval() + 20));
  596. }
  597. }
  598. else
  599. {
  600. stopTimer();
  601. }
  602. }
  603. void setEmbeddedWindowToOurSize()
  604. {
  605. if (! recursiveResize)
  606. {
  607. recursiveResize = true;
  608. if (embeddedView != 0)
  609. {
  610. HIRect r;
  611. r.origin.x = 0;
  612. r.origin.y = 0;
  613. r.size.width = (float) getWidth();
  614. r.size.height = (float) getHeight();
  615. HIViewSetFrame (embeddedView, &r);
  616. }
  617. if (wrapperWindow != 0)
  618. {
  619. Rect wr;
  620. wr.left = getScreenX();
  621. wr.top = getScreenY();
  622. wr.right = wr.left + getWidth();
  623. wr.bottom = wr.top + getHeight();
  624. SetWindowBounds (wrapperWindow, kWindowContentRgn, &wr);
  625. ShowWindow (wrapperWindow);
  626. }
  627. recursiveResize = false;
  628. }
  629. }
  630. void componentMovedOrResized (bool /*wasMoved*/, bool /*wasResized*/)
  631. {
  632. setEmbeddedWindowToOurSize();
  633. }
  634. void componentPeerChanged()
  635. {
  636. deleteWindow();
  637. createWindow();
  638. }
  639. void componentVisibilityChanged (Component&)
  640. {
  641. if (isShowing())
  642. createWindow();
  643. else
  644. deleteWindow();
  645. setEmbeddedWindowToOurSize();
  646. }
  647. static void recursiveHIViewRepaint (HIViewRef view)
  648. {
  649. HIViewSetNeedsDisplay (view, true);
  650. HIViewRef child = HIViewGetFirstSubview (view);
  651. while (child != 0)
  652. {
  653. recursiveHIViewRepaint (child);
  654. child = HIViewGetNextView (child);
  655. }
  656. }
  657. void timerCallback()
  658. {
  659. setOurSizeToEmbeddedViewSize();
  660. // To avoid strange overpainting problems when the UI is first opened, we'll
  661. // repaint it a few times during the first second that it's on-screen..
  662. if ((Time::getCurrentTime() - creationTime).inMilliseconds() < 1000)
  663. recursiveHIViewRepaint (HIViewGetRoot (wrapperWindow));
  664. }
  665. OSStatus carbonEventHandler (EventHandlerCallRef nextHandlerRef,
  666. EventRef event)
  667. {
  668. switch (GetEventKind (event))
  669. {
  670. case kEventWindowHandleDeactivate:
  671. ActivateWindow (wrapperWindow, TRUE);
  672. break;
  673. case kEventWindowGetClickActivation:
  674. {
  675. getTopLevelComponent()->toFront (false);
  676. ClickActivationResult howToHandleClick = kActivateAndHandleClick;
  677. SetEventParameter (event, kEventParamClickActivation, typeClickActivationResult,
  678. sizeof (ClickActivationResult), &howToHandleClick);
  679. HIViewSetNeedsDisplay (embeddedView, true);
  680. }
  681. break;
  682. }
  683. return noErr;
  684. }
  685. static pascal OSStatus carbonEventCallback (EventHandlerCallRef nextHandlerRef,
  686. EventRef event, void* userData)
  687. {
  688. return ((CarbonViewWrapperComponent*) userData)->carbonEventHandler (nextHandlerRef, event);
  689. }
  690. protected:
  691. WindowRef wrapperWindow;
  692. HIViewRef embeddedView;
  693. bool recursiveResize;
  694. Time creationTime;
  695. EventHandlerRef eventHandlerRef;
  696. };
  697. #endif // __JUCE_MAC_CARBONVIEWWRAPPERCOMPONENT_JUCEHEADER__
  698. /*** End of inlined file: juce_mac_CarbonViewWrapperComponent.h ***/
  699. END_JUCE_NAMESPACE
  700. #endif
  701. #define JUCE_AMALGAMATED_TEMPLATE 1
  702. //==============================================================================
  703. #if JUCE_BUILD_CORE
  704. /*** Start of inlined file: juce_FileLogger.cpp ***/
  705. BEGIN_JUCE_NAMESPACE
  706. FileLogger::FileLogger (const File& logFile_,
  707. const String& welcomeMessage,
  708. const int maxInitialFileSizeBytes)
  709. : logFile (logFile_)
  710. {
  711. if (maxInitialFileSizeBytes >= 0)
  712. trimFileSize (maxInitialFileSizeBytes);
  713. if (! logFile_.exists())
  714. {
  715. // do this so that the parent directories get created..
  716. logFile_.create();
  717. }
  718. logStream = logFile_.createOutputStream (256);
  719. jassert (logStream != 0);
  720. String welcome;
  721. welcome << "\r\n**********************************************************\r\n"
  722. << welcomeMessage
  723. << "\r\nLog started: " << Time::getCurrentTime().toString (true, true)
  724. << "\r\n";
  725. logMessage (welcome);
  726. }
  727. FileLogger::~FileLogger()
  728. {
  729. }
  730. void FileLogger::logMessage (const String& message)
  731. {
  732. if (logStream != 0)
  733. {
  734. DBG (message);
  735. const ScopedLock sl (logLock);
  736. (*logStream) << message << T("\r\n");
  737. logStream->flush();
  738. }
  739. }
  740. void FileLogger::trimFileSize (int maxFileSizeBytes) const
  741. {
  742. if (maxFileSizeBytes <= 0)
  743. {
  744. logFile.deleteFile();
  745. }
  746. else
  747. {
  748. const int64 fileSize = logFile.getSize();
  749. if (fileSize > maxFileSizeBytes)
  750. {
  751. ScopedPointer <FileInputStream> in (logFile.createInputStream());
  752. jassert (in != 0);
  753. if (in != 0)
  754. {
  755. in->setPosition (fileSize - maxFileSizeBytes);
  756. String content;
  757. {
  758. MemoryBlock contentToSave;
  759. contentToSave.setSize (maxFileSizeBytes + 4);
  760. contentToSave.fillWith (0);
  761. in->read (contentToSave.getData(), maxFileSizeBytes);
  762. in = 0;
  763. content = contentToSave.toString();
  764. }
  765. int newStart = 0;
  766. while (newStart < fileSize
  767. && content[newStart] != '\n'
  768. && content[newStart] != '\r')
  769. ++newStart;
  770. logFile.deleteFile();
  771. logFile.appendText (content.substring (newStart), false, false);
  772. }
  773. }
  774. }
  775. }
  776. FileLogger* FileLogger::createDefaultAppLogger (const String& logFileSubDirectoryName,
  777. const String& logFileName,
  778. const String& welcomeMessage,
  779. const int maxInitialFileSizeBytes)
  780. {
  781. #if JUCE_MAC
  782. File logFile ("~/Library/Logs");
  783. logFile = logFile.getChildFile (logFileSubDirectoryName)
  784. .getChildFile (logFileName);
  785. #else
  786. File logFile (File::getSpecialLocation (File::userApplicationDataDirectory));
  787. if (logFile.isDirectory())
  788. {
  789. logFile = logFile.getChildFile (logFileSubDirectoryName)
  790. .getChildFile (logFileName);
  791. }
  792. #endif
  793. return new FileLogger (logFile, welcomeMessage, maxInitialFileSizeBytes);
  794. }
  795. END_JUCE_NAMESPACE
  796. /*** End of inlined file: juce_FileLogger.cpp ***/
  797. /*** Start of inlined file: juce_Logger.cpp ***/
  798. BEGIN_JUCE_NAMESPACE
  799. Logger::Logger()
  800. {
  801. }
  802. Logger::~Logger()
  803. {
  804. }
  805. static Logger* currentLogger = 0;
  806. void Logger::setCurrentLogger (Logger* const newLogger,
  807. const bool deleteOldLogger)
  808. {
  809. Logger* const oldLogger = currentLogger;
  810. currentLogger = newLogger;
  811. if (deleteOldLogger)
  812. delete oldLogger;
  813. }
  814. void Logger::writeToLog (const String& message)
  815. {
  816. if (currentLogger != 0)
  817. currentLogger->logMessage (message);
  818. else
  819. outputDebugString (message);
  820. }
  821. #if JUCE_LOG_ASSERTIONS
  822. void JUCE_API juce_LogAssertion (const char* filename, const int lineNum) throw()
  823. {
  824. String m ("JUCE Assertion failure in ");
  825. m << filename << ", line " << lineNum;
  826. Logger::writeToLog (m);
  827. }
  828. #endif
  829. END_JUCE_NAMESPACE
  830. /*** End of inlined file: juce_Logger.cpp ***/
  831. /*** Start of inlined file: juce_Random.cpp ***/
  832. BEGIN_JUCE_NAMESPACE
  833. Random::Random (const int64 seedValue) throw()
  834. : seed (seedValue)
  835. {
  836. }
  837. Random::~Random() throw()
  838. {
  839. }
  840. void Random::setSeed (const int64 newSeed) throw()
  841. {
  842. seed = newSeed;
  843. }
  844. void Random::combineSeed (const int64 seedValue) throw()
  845. {
  846. seed ^= nextInt64() ^ seedValue;
  847. }
  848. void Random::setSeedRandomly()
  849. {
  850. combineSeed ((int64) (pointer_sized_int) this);
  851. combineSeed (Time::getMillisecondCounter());
  852. combineSeed (Time::getHighResolutionTicks());
  853. combineSeed (Time::getHighResolutionTicksPerSecond());
  854. combineSeed (Time::currentTimeMillis());
  855. }
  856. int Random::nextInt() throw()
  857. {
  858. seed = (seed * literal64bit (0x5deece66d) + 11) & literal64bit (0xffffffffffff);
  859. return (int) (seed >> 16);
  860. }
  861. int Random::nextInt (const int maxValue) throw()
  862. {
  863. jassert (maxValue > 0);
  864. return (nextInt() & 0x7fffffff) % maxValue;
  865. }
  866. int64 Random::nextInt64() throw()
  867. {
  868. return (((int64) nextInt()) << 32) | (int64) (uint64) (uint32) nextInt();
  869. }
  870. bool Random::nextBool() throw()
  871. {
  872. return (nextInt() & 0x80000000) != 0;
  873. }
  874. float Random::nextFloat() throw()
  875. {
  876. return static_cast <uint32> (nextInt()) / (float) 0xffffffff;
  877. }
  878. double Random::nextDouble() throw()
  879. {
  880. return static_cast <uint32> (nextInt()) / (double) 0xffffffff;
  881. }
  882. const BigInteger Random::nextLargeNumber (const BigInteger& maximumValue)
  883. {
  884. BigInteger n;
  885. do
  886. {
  887. fillBitsRandomly (n, 0, maximumValue.getHighestBit() + 1);
  888. }
  889. while (n >= maximumValue);
  890. return n;
  891. }
  892. void Random::fillBitsRandomly (BigInteger& arrayToChange, int startBit, int numBits)
  893. {
  894. arrayToChange.setBit (startBit + numBits - 1, true); // to force the array to pre-allocate space
  895. while ((startBit & 31) != 0 && numBits > 0)
  896. {
  897. arrayToChange.setBit (startBit++, nextBool());
  898. --numBits;
  899. }
  900. while (numBits >= 32)
  901. {
  902. arrayToChange.setBitRangeAsInt (startBit, 32, (unsigned int) nextInt());
  903. startBit += 32;
  904. numBits -= 32;
  905. }
  906. while (--numBits >= 0)
  907. arrayToChange.setBit (startBit + numBits, nextBool());
  908. }
  909. Random& Random::getSystemRandom() throw()
  910. {
  911. static Random sysRand (1);
  912. return sysRand;
  913. }
  914. END_JUCE_NAMESPACE
  915. /*** End of inlined file: juce_Random.cpp ***/
  916. /*** Start of inlined file: juce_RelativeTime.cpp ***/
  917. BEGIN_JUCE_NAMESPACE
  918. RelativeTime::RelativeTime (const double seconds_) throw()
  919. : seconds (seconds_)
  920. {
  921. }
  922. RelativeTime::RelativeTime (const RelativeTime& other) throw()
  923. : seconds (other.seconds)
  924. {
  925. }
  926. RelativeTime::~RelativeTime() throw()
  927. {
  928. }
  929. const RelativeTime RelativeTime::milliseconds (const int milliseconds) throw()
  930. {
  931. return RelativeTime (milliseconds * 0.001);
  932. }
  933. const RelativeTime RelativeTime::milliseconds (const int64 milliseconds) throw()
  934. {
  935. return RelativeTime (milliseconds * 0.001);
  936. }
  937. const RelativeTime RelativeTime::minutes (const double numberOfMinutes) throw()
  938. {
  939. return RelativeTime (numberOfMinutes * 60.0);
  940. }
  941. const RelativeTime RelativeTime::hours (const double numberOfHours) throw()
  942. {
  943. return RelativeTime (numberOfHours * (60.0 * 60.0));
  944. }
  945. const RelativeTime RelativeTime::days (const double numberOfDays) throw()
  946. {
  947. return RelativeTime (numberOfDays * (60.0 * 60.0 * 24.0));
  948. }
  949. const RelativeTime RelativeTime::weeks (const double numberOfWeeks) throw()
  950. {
  951. return RelativeTime (numberOfWeeks * (60.0 * 60.0 * 24.0 * 7.0));
  952. }
  953. int64 RelativeTime::inMilliseconds() const throw()
  954. {
  955. return (int64)(seconds * 1000.0);
  956. }
  957. double RelativeTime::inMinutes() const throw()
  958. {
  959. return seconds / 60.0;
  960. }
  961. double RelativeTime::inHours() const throw()
  962. {
  963. return seconds / (60.0 * 60.0);
  964. }
  965. double RelativeTime::inDays() const throw()
  966. {
  967. return seconds / (60.0 * 60.0 * 24.0);
  968. }
  969. double RelativeTime::inWeeks() const throw()
  970. {
  971. return seconds / (60.0 * 60.0 * 24.0 * 7.0);
  972. }
  973. const String RelativeTime::getDescription (const String& returnValueForZeroTime) const throw()
  974. {
  975. if (seconds < 0.001 && seconds > -0.001)
  976. return returnValueForZeroTime;
  977. String result;
  978. if (seconds < 0)
  979. result = T("-");
  980. int fieldsShown = 0;
  981. int n = abs ((int) inWeeks());
  982. if (n > 0)
  983. {
  984. result << n << ((n == 1) ? TRANS(" week ")
  985. : TRANS(" weeks "));
  986. ++fieldsShown;
  987. }
  988. n = abs ((int) inDays()) % 7;
  989. if (n > 0)
  990. {
  991. result << n << ((n == 1) ? TRANS(" day ")
  992. : TRANS(" days "));
  993. ++fieldsShown;
  994. }
  995. if (fieldsShown < 2)
  996. {
  997. n = abs ((int) inHours()) % 24;
  998. if (n > 0)
  999. {
  1000. result << n << ((n == 1) ? TRANS(" hr ")
  1001. : TRANS(" hrs "));
  1002. ++fieldsShown;
  1003. }
  1004. if (fieldsShown < 2)
  1005. {
  1006. n = abs ((int) inMinutes()) % 60;
  1007. if (n > 0)
  1008. {
  1009. result << n << ((n == 1) ? TRANS(" min ")
  1010. : TRANS(" mins "));
  1011. ++fieldsShown;
  1012. }
  1013. if (fieldsShown < 2)
  1014. {
  1015. n = abs ((int) inSeconds()) % 60;
  1016. if (n > 0)
  1017. {
  1018. result << n << ((n == 1) ? TRANS(" sec ")
  1019. : TRANS(" secs "));
  1020. ++fieldsShown;
  1021. }
  1022. if (fieldsShown < 1)
  1023. {
  1024. n = abs ((int) inMilliseconds()) % 1000;
  1025. if (n > 0)
  1026. {
  1027. result << n << TRANS(" ms");
  1028. ++fieldsShown;
  1029. }
  1030. }
  1031. }
  1032. }
  1033. }
  1034. return result.trimEnd();
  1035. }
  1036. RelativeTime& RelativeTime::operator= (const RelativeTime& other) throw()
  1037. {
  1038. seconds = other.seconds;
  1039. return *this;
  1040. }
  1041. bool RelativeTime::operator== (const RelativeTime& other) const throw()
  1042. {
  1043. return seconds == other.seconds;
  1044. }
  1045. bool RelativeTime::operator!= (const RelativeTime& other) const throw()
  1046. {
  1047. return seconds != other.seconds;
  1048. }
  1049. bool RelativeTime::operator> (const RelativeTime& other) const throw()
  1050. {
  1051. return seconds > other.seconds;
  1052. }
  1053. bool RelativeTime::operator< (const RelativeTime& other) const throw()
  1054. {
  1055. return seconds < other.seconds;
  1056. }
  1057. bool RelativeTime::operator>= (const RelativeTime& other) const throw()
  1058. {
  1059. return seconds >= other.seconds;
  1060. }
  1061. bool RelativeTime::operator<= (const RelativeTime& other) const throw()
  1062. {
  1063. return seconds <= other.seconds;
  1064. }
  1065. const RelativeTime RelativeTime::operator+ (const RelativeTime& timeToAdd) const throw()
  1066. {
  1067. return RelativeTime (seconds + timeToAdd.seconds);
  1068. }
  1069. const RelativeTime RelativeTime::operator- (const RelativeTime& timeToSubtract) const throw()
  1070. {
  1071. return RelativeTime (seconds - timeToSubtract.seconds);
  1072. }
  1073. const RelativeTime RelativeTime::operator+ (const double secondsToAdd) const throw()
  1074. {
  1075. return RelativeTime (seconds + secondsToAdd);
  1076. }
  1077. const RelativeTime RelativeTime::operator- (const double secondsToSubtract) const throw()
  1078. {
  1079. return RelativeTime (seconds - secondsToSubtract);
  1080. }
  1081. const RelativeTime& RelativeTime::operator+= (const RelativeTime& timeToAdd) throw()
  1082. {
  1083. seconds += timeToAdd.seconds;
  1084. return *this;
  1085. }
  1086. const RelativeTime& RelativeTime::operator-= (const RelativeTime& timeToSubtract) throw()
  1087. {
  1088. seconds -= timeToSubtract.seconds;
  1089. return *this;
  1090. }
  1091. const RelativeTime& RelativeTime::operator+= (const double secondsToAdd) throw()
  1092. {
  1093. seconds += secondsToAdd;
  1094. return *this;
  1095. }
  1096. const RelativeTime& RelativeTime::operator-= (const double secondsToSubtract) throw()
  1097. {
  1098. seconds -= secondsToSubtract;
  1099. return *this;
  1100. }
  1101. END_JUCE_NAMESPACE
  1102. /*** End of inlined file: juce_RelativeTime.cpp ***/
  1103. /*** Start of inlined file: juce_SystemStats.cpp ***/
  1104. BEGIN_JUCE_NAMESPACE
  1105. const String SystemStats::getJUCEVersion() throw()
  1106. {
  1107. return "JUCE v" + String (JUCE_MAJOR_VERSION)
  1108. + "." + String (JUCE_MINOR_VERSION)
  1109. + "." + String (JUCE_BUILDNUMBER);
  1110. }
  1111. const StringArray SystemStats::getMACAddressStrings()
  1112. {
  1113. int64 macAddresses [16];
  1114. const int numAddresses = getMACAddresses (macAddresses, numElementsInArray (macAddresses), false);
  1115. StringArray s;
  1116. for (int i = 0; i < numAddresses; ++i)
  1117. {
  1118. s.add (String::toHexString (0xff & (int) (macAddresses [i] >> 40)).paddedLeft ('0', 2)
  1119. + "-" + String::toHexString (0xff & (int) (macAddresses [i] >> 32)).paddedLeft ('0', 2)
  1120. + "-" + String::toHexString (0xff & (int) (macAddresses [i] >> 24)).paddedLeft ('0', 2)
  1121. + "-" + String::toHexString (0xff & (int) (macAddresses [i] >> 16)).paddedLeft ('0', 2)
  1122. + "-" + String::toHexString (0xff & (int) (macAddresses [i] >> 8)).paddedLeft ('0', 2)
  1123. + "-" + String::toHexString (0xff & (int) (macAddresses [i] >> 0)).paddedLeft ('0', 2));
  1124. }
  1125. return s;
  1126. }
  1127. static bool juceInitialisedNonGUI = false;
  1128. void JUCE_PUBLIC_FUNCTION initialiseJuce_NonGUI()
  1129. {
  1130. if (! juceInitialisedNonGUI)
  1131. {
  1132. #if JUCE_MAC || JUCE_IPHONE
  1133. const ScopedAutoReleasePool pool;
  1134. #endif
  1135. #ifdef JUCE_DEBUG
  1136. {
  1137. // Some simple test code to keep an eye on things and make sure these functions
  1138. // work ok on all platforms. Let me know if any of these assertions fail!
  1139. static_jassert (sizeof (pointer_sized_int) == sizeof (void*));
  1140. char a1[7];
  1141. jassert (numElementsInArray(a1) == 7);
  1142. int a2[3];
  1143. jassert (numElementsInArray(a2) == 3);
  1144. int n = 1;
  1145. Atomic::increment (n);
  1146. jassert (Atomic::incrementAndReturn (n) == 3);
  1147. Atomic::decrement (n);
  1148. jassert (Atomic::decrementAndReturn (n) == 1);
  1149. jassert (ByteOrder::swap ((uint16) 0x1122) == 0x2211);
  1150. jassert (ByteOrder::swap ((uint32) 0x11223344) == 0x44332211);
  1151. // Some quick stream tests..
  1152. int randomInt = Random::getSystemRandom().nextInt();
  1153. int64 randomInt64 = Random::getSystemRandom().nextInt64();
  1154. double randomDouble = Random::getSystemRandom().nextDouble();
  1155. String randomString;
  1156. for (int i = 50; --i >= 0;)
  1157. randomString << (juce_wchar) (Random::getSystemRandom().nextInt() & 0xffff);
  1158. MemoryOutputStream mo;
  1159. mo.writeInt (randomInt);
  1160. mo.writeIntBigEndian (randomInt);
  1161. mo.writeCompressedInt (randomInt);
  1162. mo.writeString (randomString);
  1163. mo.writeInt64 (randomInt64);
  1164. mo.writeInt64BigEndian (randomInt64);
  1165. mo.writeDouble (randomDouble);
  1166. mo.writeDoubleBigEndian (randomDouble);
  1167. MemoryInputStream mi (mo.getData(), mo.getDataSize(), false);
  1168. jassert (mi.readInt() == randomInt);
  1169. jassert (mi.readIntBigEndian() == randomInt);
  1170. jassert (mi.readCompressedInt() == randomInt);
  1171. jassert (mi.readString() == randomString);
  1172. jassert (mi.readInt64() == randomInt64);
  1173. jassert (mi.readInt64BigEndian() == randomInt64);
  1174. jassert (mi.readDouble() == randomDouble);
  1175. jassert (mi.readDoubleBigEndian() == randomDouble);
  1176. }
  1177. #endif
  1178. // Now the real initialisation..
  1179. juceInitialisedNonGUI = true;
  1180. DBG (SystemStats::getJUCEVersion());
  1181. SystemStats::initialiseStats();
  1182. Random::getSystemRandom().setSeedRandomly(); // (mustn't call this before initialiseStats() because it relies on the time being set up)
  1183. }
  1184. }
  1185. #if JUCE_WINDOWS
  1186. // This is imported from the sockets code..
  1187. typedef int (__stdcall juce_CloseWin32SocketLibCall) (void);
  1188. extern juce_CloseWin32SocketLibCall* juce_CloseWin32SocketLib;
  1189. #endif
  1190. #if JUCE_DEBUG
  1191. extern void juce_CheckForDanglingStreams();
  1192. #endif
  1193. void JUCE_PUBLIC_FUNCTION shutdownJuce_NonGUI()
  1194. {
  1195. if (juceInitialisedNonGUI)
  1196. {
  1197. #if JUCE_MAC || JUCE_IPHONE
  1198. const ScopedAutoReleasePool pool;
  1199. #endif
  1200. #if JUCE_WINDOWS
  1201. // need to shut down sockets if they were used..
  1202. if (juce_CloseWin32SocketLib != 0)
  1203. (*juce_CloseWin32SocketLib)();
  1204. #endif
  1205. LocalisedStrings::setCurrentMappings (0);
  1206. Thread::stopAllThreads (3000);
  1207. #if JUCE_DEBUG
  1208. juce_CheckForDanglingStreams();
  1209. #endif
  1210. juceInitialisedNonGUI = false;
  1211. }
  1212. }
  1213. #ifdef JUCE_DLL
  1214. void* juce_Malloc (const int size)
  1215. {
  1216. return malloc (size);
  1217. }
  1218. void* juce_Calloc (const int size)
  1219. {
  1220. return calloc (1, size);
  1221. }
  1222. void* juce_Realloc (void* const block, const int size)
  1223. {
  1224. return realloc (block, size);
  1225. }
  1226. void juce_Free (void* const block)
  1227. {
  1228. free (block);
  1229. }
  1230. #if defined (JUCE_DEBUG) && JUCE_MSVC && JUCE_CHECK_MEMORY_LEAKS
  1231. void* juce_DebugMalloc (const int size, const char* file, const int line)
  1232. {
  1233. return _malloc_dbg (size, _NORMAL_BLOCK, file, line);
  1234. }
  1235. void* juce_DebugCalloc (const int size, const char* file, const int line)
  1236. {
  1237. return _calloc_dbg (1, size, _NORMAL_BLOCK, file, line);
  1238. }
  1239. void* juce_DebugRealloc (void* const block, const int size, const char* file, const int line)
  1240. {
  1241. return _realloc_dbg (block, size, _NORMAL_BLOCK, file, line);
  1242. }
  1243. void juce_DebugFree (void* const block)
  1244. {
  1245. _free_dbg (block, _NORMAL_BLOCK);
  1246. }
  1247. #endif
  1248. #endif
  1249. END_JUCE_NAMESPACE
  1250. /*** End of inlined file: juce_SystemStats.cpp ***/
  1251. /*** Start of inlined file: juce_Time.cpp ***/
  1252. #ifdef _MSC_VER
  1253. #pragma warning (disable: 4514)
  1254. #pragma warning (push)
  1255. #endif
  1256. #ifndef JUCE_WINDOWS
  1257. #include <sys/time.h>
  1258. #else
  1259. #include <ctime>
  1260. #endif
  1261. #include <sys/timeb.h>
  1262. BEGIN_JUCE_NAMESPACE
  1263. #ifdef _MSC_VER
  1264. #pragma warning (pop)
  1265. #ifdef _INC_TIME_INL
  1266. #define USE_NEW_SECURE_TIME_FNS
  1267. #endif
  1268. #endif
  1269. namespace TimeHelpers
  1270. {
  1271. static struct tm millisToLocal (const int64 millis) throw()
  1272. {
  1273. struct tm result;
  1274. const int64 seconds = millis / 1000;
  1275. if (seconds < literal64bit (86400) || seconds >= literal64bit (2145916800))
  1276. {
  1277. // use extended maths for dates beyond 1970 to 2037..
  1278. const int timeZoneAdjustment = 31536000 - (int) (Time (1971, 0, 1, 0, 0).toMilliseconds() / 1000);
  1279. const int64 jdm = seconds + timeZoneAdjustment + literal64bit (210866803200);
  1280. const int days = (int) (jdm / literal64bit (86400));
  1281. const int a = 32044 + days;
  1282. const int b = (4 * a + 3) / 146097;
  1283. const int c = a - (b * 146097) / 4;
  1284. const int d = (4 * c + 3) / 1461;
  1285. const int e = c - (d * 1461) / 4;
  1286. const int m = (5 * e + 2) / 153;
  1287. result.tm_mday = e - (153 * m + 2) / 5 + 1;
  1288. result.tm_mon = m + 2 - 12 * (m / 10);
  1289. result.tm_year = b * 100 + d - 6700 + (m / 10);
  1290. result.tm_wday = (days + 1) % 7;
  1291. result.tm_yday = -1;
  1292. int t = (int) (jdm % literal64bit (86400));
  1293. result.tm_hour = t / 3600;
  1294. t %= 3600;
  1295. result.tm_min = t / 60;
  1296. result.tm_sec = t % 60;
  1297. result.tm_isdst = -1;
  1298. }
  1299. else
  1300. {
  1301. time_t now = static_cast <time_t> (seconds);
  1302. #if JUCE_WINDOWS
  1303. #ifdef USE_NEW_SECURE_TIME_FNS
  1304. if (now >= 0 && now <= 0x793406fff)
  1305. localtime_s (&result, &now);
  1306. else
  1307. zeromem (&result, sizeof (result));
  1308. #else
  1309. result = *localtime (&now);
  1310. #endif
  1311. #else
  1312. // more thread-safe
  1313. localtime_r (&now, &result);
  1314. #endif
  1315. }
  1316. return result;
  1317. }
  1318. static int extendedModulo (const int64 value, const int modulo) throw()
  1319. {
  1320. return (int) (value >= 0 ? (value % modulo)
  1321. : (value - ((value / modulo) + 1) * modulo));
  1322. }
  1323. static uint32 lastMSCounterValue = 0;
  1324. }
  1325. Time::Time() throw()
  1326. : millisSinceEpoch (0)
  1327. {
  1328. }
  1329. Time::Time (const Time& other) throw()
  1330. : millisSinceEpoch (other.millisSinceEpoch)
  1331. {
  1332. }
  1333. Time::Time (const int64 ms) throw()
  1334. : millisSinceEpoch (ms)
  1335. {
  1336. }
  1337. Time::Time (const int year,
  1338. const int month,
  1339. const int day,
  1340. const int hours,
  1341. const int minutes,
  1342. const int seconds,
  1343. const int milliseconds,
  1344. const bool useLocalTime) throw()
  1345. {
  1346. jassert (year > 100); // year must be a 4-digit version
  1347. if (year < 1971 || year >= 2038 || ! useLocalTime)
  1348. {
  1349. // use extended maths for dates beyond 1970 to 2037..
  1350. const int timeZoneAdjustment = useLocalTime ? (31536000 - (int) (Time (1971, 0, 1, 0, 0).toMilliseconds() / 1000))
  1351. : 0;
  1352. const int a = (13 - month) / 12;
  1353. const int y = year + 4800 - a;
  1354. const int jd = day + (153 * (month + 12 * a - 2) + 2) / 5
  1355. + (y * 365) + (y / 4) - (y / 100) + (y / 400)
  1356. - 32045;
  1357. const int64 s = ((int64) jd) * literal64bit (86400) - literal64bit (210866803200);
  1358. millisSinceEpoch = 1000 * (s + (hours * 3600 + minutes * 60 + seconds - timeZoneAdjustment))
  1359. + milliseconds;
  1360. }
  1361. else
  1362. {
  1363. struct tm t;
  1364. t.tm_year = year - 1900;
  1365. t.tm_mon = month;
  1366. t.tm_mday = day;
  1367. t.tm_hour = hours;
  1368. t.tm_min = minutes;
  1369. t.tm_sec = seconds;
  1370. t.tm_isdst = -1;
  1371. millisSinceEpoch = 1000 * (int64) mktime (&t);
  1372. if (millisSinceEpoch < 0)
  1373. millisSinceEpoch = 0;
  1374. else
  1375. millisSinceEpoch += milliseconds;
  1376. }
  1377. }
  1378. Time::~Time() throw()
  1379. {
  1380. }
  1381. Time& Time::operator= (const Time& other) throw()
  1382. {
  1383. millisSinceEpoch = other.millisSinceEpoch;
  1384. return *this;
  1385. }
  1386. int64 Time::currentTimeMillis() throw()
  1387. {
  1388. static uint32 lastCounterResult = 0xffffffff;
  1389. static int64 correction = 0;
  1390. const uint32 now = getMillisecondCounter();
  1391. // check the counter hasn't wrapped (also triggered the first time this function is called)
  1392. if (now < lastCounterResult)
  1393. {
  1394. // double-check it's actually wrapped, in case multi-cpu machines have timers that drift a bit.
  1395. if (lastCounterResult == 0xffffffff || now < lastCounterResult - 10)
  1396. {
  1397. // get the time once using normal library calls, and store the difference needed to
  1398. // turn the millisecond counter into a real time.
  1399. #if JUCE_WINDOWS
  1400. struct _timeb t;
  1401. #ifdef USE_NEW_SECURE_TIME_FNS
  1402. _ftime_s (&t);
  1403. #else
  1404. _ftime (&t);
  1405. #endif
  1406. correction = (((int64) t.time) * 1000 + t.millitm) - now;
  1407. #else
  1408. struct timeval tv;
  1409. struct timezone tz;
  1410. gettimeofday (&tv, &tz);
  1411. correction = (((int64) tv.tv_sec) * 1000 + tv.tv_usec / 1000) - now;
  1412. #endif
  1413. }
  1414. }
  1415. lastCounterResult = now;
  1416. return correction + now;
  1417. }
  1418. uint32 juce_millisecondsSinceStartup() throw();
  1419. uint32 Time::getMillisecondCounter() throw()
  1420. {
  1421. const uint32 now = juce_millisecondsSinceStartup();
  1422. if (now < TimeHelpers::lastMSCounterValue)
  1423. {
  1424. // in multi-threaded apps this might be called concurrently, so
  1425. // make sure that our last counter value only increases and doesn't
  1426. // go backwards..
  1427. if (now < TimeHelpers::lastMSCounterValue - 1000)
  1428. TimeHelpers::lastMSCounterValue = now;
  1429. }
  1430. else
  1431. {
  1432. TimeHelpers::lastMSCounterValue = now;
  1433. }
  1434. return now;
  1435. }
  1436. uint32 Time::getApproximateMillisecondCounter() throw()
  1437. {
  1438. jassert (TimeHelpers::lastMSCounterValue != 0);
  1439. return TimeHelpers::lastMSCounterValue;
  1440. }
  1441. void Time::waitForMillisecondCounter (const uint32 targetTime) throw()
  1442. {
  1443. for (;;)
  1444. {
  1445. const uint32 now = getMillisecondCounter();
  1446. if (now >= targetTime)
  1447. break;
  1448. const int toWait = targetTime - now;
  1449. if (toWait > 2)
  1450. {
  1451. Thread::sleep (jmin (20, toWait >> 1));
  1452. }
  1453. else
  1454. {
  1455. // xxx should consider using mutex_pause on the mac as it apparently
  1456. // makes it seem less like a spinlock and avoids lowering the thread pri.
  1457. for (int i = 10; --i >= 0;)
  1458. Thread::yield();
  1459. }
  1460. }
  1461. }
  1462. double Time::highResolutionTicksToSeconds (const int64 ticks) throw()
  1463. {
  1464. return ticks / (double) getHighResolutionTicksPerSecond();
  1465. }
  1466. int64 Time::secondsToHighResolutionTicks (const double seconds) throw()
  1467. {
  1468. return (int64) (seconds * (double) getHighResolutionTicksPerSecond());
  1469. }
  1470. const Time JUCE_CALLTYPE Time::getCurrentTime() throw()
  1471. {
  1472. return Time (currentTimeMillis());
  1473. }
  1474. const String Time::toString (const bool includeDate,
  1475. const bool includeTime,
  1476. const bool includeSeconds,
  1477. const bool use24HourClock) const throw()
  1478. {
  1479. String result;
  1480. if (includeDate)
  1481. {
  1482. result << getDayOfMonth() << ' '
  1483. << getMonthName (true) << ' '
  1484. << getYear();
  1485. if (includeTime)
  1486. result << ' ';
  1487. }
  1488. if (includeTime)
  1489. {
  1490. const int mins = getMinutes();
  1491. result << (use24HourClock ? getHours() : getHoursInAmPmFormat())
  1492. << (mins < 10 ? ":0" : ":") << mins;
  1493. if (includeSeconds)
  1494. {
  1495. const int secs = getSeconds();
  1496. result << (secs < 10 ? ":0" : ":") << secs;
  1497. }
  1498. if (! use24HourClock)
  1499. result << (isAfternoon() ? "pm" : "am");
  1500. }
  1501. return result.trimEnd();
  1502. }
  1503. const String Time::formatted (const juce_wchar* const format) const throw()
  1504. {
  1505. String buffer;
  1506. int bufferSize = 128;
  1507. buffer.preallocateStorage (bufferSize);
  1508. struct tm t (TimeHelpers::millisToLocal (millisSinceEpoch));
  1509. while (CharacterFunctions::ftime (static_cast <juce_wchar*> (buffer), bufferSize, format, &t) <= 0)
  1510. {
  1511. bufferSize += 128;
  1512. buffer.preallocateStorage (bufferSize);
  1513. }
  1514. return buffer;
  1515. }
  1516. int Time::getYear() const throw()
  1517. {
  1518. return TimeHelpers::millisToLocal (millisSinceEpoch).tm_year + 1900;
  1519. }
  1520. int Time::getMonth() const throw()
  1521. {
  1522. return TimeHelpers::millisToLocal (millisSinceEpoch).tm_mon;
  1523. }
  1524. int Time::getDayOfMonth() const throw()
  1525. {
  1526. return TimeHelpers::millisToLocal (millisSinceEpoch).tm_mday;
  1527. }
  1528. int Time::getDayOfWeek() const throw()
  1529. {
  1530. return TimeHelpers::millisToLocal (millisSinceEpoch).tm_wday;
  1531. }
  1532. int Time::getHours() const throw()
  1533. {
  1534. return TimeHelpers::millisToLocal (millisSinceEpoch).tm_hour;
  1535. }
  1536. int Time::getHoursInAmPmFormat() const throw()
  1537. {
  1538. const int hours = getHours();
  1539. if (hours == 0)
  1540. return 12;
  1541. else if (hours <= 12)
  1542. return hours;
  1543. else
  1544. return hours - 12;
  1545. }
  1546. bool Time::isAfternoon() const throw()
  1547. {
  1548. return getHours() >= 12;
  1549. }
  1550. int Time::getMinutes() const throw()
  1551. {
  1552. return TimeHelpers::millisToLocal (millisSinceEpoch).tm_min;
  1553. }
  1554. int Time::getSeconds() const throw()
  1555. {
  1556. return TimeHelpers::extendedModulo (millisSinceEpoch / 1000, 60);
  1557. }
  1558. int Time::getMilliseconds() const throw()
  1559. {
  1560. return TimeHelpers::extendedModulo (millisSinceEpoch, 1000);
  1561. }
  1562. bool Time::isDaylightSavingTime() const throw()
  1563. {
  1564. return TimeHelpers::millisToLocal (millisSinceEpoch).tm_isdst != 0;
  1565. }
  1566. const String Time::getTimeZone() const throw()
  1567. {
  1568. String zone[2];
  1569. #if JUCE_WINDOWS
  1570. _tzset();
  1571. #ifdef USE_NEW_SECURE_TIME_FNS
  1572. {
  1573. char name [128];
  1574. size_t length;
  1575. for (int i = 0; i < 2; ++i)
  1576. {
  1577. zeromem (name, sizeof (name));
  1578. _get_tzname (&length, name, 127, i);
  1579. zone[i] = name;
  1580. }
  1581. }
  1582. #else
  1583. const char** const zonePtr = (const char**) _tzname;
  1584. zone[0] = zonePtr[0];
  1585. zone[1] = zonePtr[1];
  1586. #endif
  1587. #else
  1588. tzset();
  1589. const char** const zonePtr = (const char**) tzname;
  1590. zone[0] = zonePtr[0];
  1591. zone[1] = zonePtr[1];
  1592. #endif
  1593. if (isDaylightSavingTime())
  1594. {
  1595. zone[0] = zone[1];
  1596. if (zone[0].length() > 3
  1597. && zone[0].containsIgnoreCase (T("daylight"))
  1598. && zone[0].contains (T("GMT")))
  1599. zone[0] = "BST";
  1600. }
  1601. return zone[0].substring (0, 3);
  1602. }
  1603. const String Time::getMonthName (const bool threeLetterVersion) const throw()
  1604. {
  1605. return getMonthName (getMonth(), threeLetterVersion);
  1606. }
  1607. const String Time::getWeekdayName (const bool threeLetterVersion) const throw()
  1608. {
  1609. return getWeekdayName (getDayOfWeek(), threeLetterVersion);
  1610. }
  1611. const String Time::getMonthName (int monthNumber, const bool threeLetterVersion) throw()
  1612. {
  1613. const char* const shortMonthNames[] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };
  1614. const char* const longMonthNames[] = { "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" };
  1615. monthNumber %= 12;
  1616. return TRANS (threeLetterVersion ? shortMonthNames [monthNumber]
  1617. : longMonthNames [monthNumber]);
  1618. }
  1619. const String Time::getWeekdayName (int day, const bool threeLetterVersion) throw()
  1620. {
  1621. const char* const shortDayNames[] = { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" };
  1622. const char* const longDayNames[] = { "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" };
  1623. day %= 7;
  1624. return TRANS (threeLetterVersion ? shortDayNames [day]
  1625. : longDayNames [day]);
  1626. }
  1627. END_JUCE_NAMESPACE
  1628. /*** End of inlined file: juce_Time.cpp ***/
  1629. /*** Start of inlined file: juce_BitArray.cpp ***/
  1630. BEGIN_JUCE_NAMESPACE
  1631. BigInteger::BigInteger()
  1632. : numValues (4),
  1633. highestBit (-1),
  1634. negative (false)
  1635. {
  1636. values.calloc (numValues + 1);
  1637. }
  1638. BigInteger::BigInteger (const int value)
  1639. : numValues (4),
  1640. highestBit (31),
  1641. negative (value < 0)
  1642. {
  1643. values.calloc (numValues + 1);
  1644. values[0] = abs (value);
  1645. highestBit = getHighestBit();
  1646. }
  1647. BigInteger::BigInteger (int64 value)
  1648. : numValues (4),
  1649. highestBit (63),
  1650. negative (value < 0)
  1651. {
  1652. values.calloc (numValues + 1);
  1653. if (value < 0)
  1654. value = -value;
  1655. values[0] = (unsigned int) value;
  1656. values[1] = (unsigned int) (value >> 32);
  1657. highestBit = getHighestBit();
  1658. }
  1659. BigInteger::BigInteger (const unsigned int value)
  1660. : numValues (4),
  1661. highestBit (31),
  1662. negative (false)
  1663. {
  1664. values.calloc (numValues + 1);
  1665. values[0] = value;
  1666. highestBit = getHighestBit();
  1667. }
  1668. BigInteger::BigInteger (const BigInteger& other)
  1669. : numValues (jmax (4, (other.highestBit >> 5) + 1)),
  1670. highestBit (other.getHighestBit()),
  1671. negative (other.negative)
  1672. {
  1673. values.malloc (numValues + 1);
  1674. memcpy (values, other.values, sizeof (unsigned int) * (numValues + 1));
  1675. }
  1676. BigInteger::~BigInteger()
  1677. {
  1678. }
  1679. void BigInteger::swapWith (BigInteger& other) throw()
  1680. {
  1681. values.swapWith (other.values);
  1682. swapVariables (numValues, other.numValues);
  1683. swapVariables (highestBit, other.highestBit);
  1684. swapVariables (negative, other.negative);
  1685. }
  1686. BigInteger& BigInteger::operator= (const BigInteger& other)
  1687. {
  1688. if (this != &other)
  1689. {
  1690. highestBit = other.getHighestBit();
  1691. numValues = jmax (4, (highestBit >> 5) + 1);
  1692. negative = other.negative;
  1693. values.malloc (numValues + 1);
  1694. memcpy (values, other.values, sizeof (unsigned int) * (numValues + 1));
  1695. }
  1696. return *this;
  1697. }
  1698. void BigInteger::ensureSize (const int numVals)
  1699. {
  1700. if (numVals + 2 >= numValues)
  1701. {
  1702. int oldSize = numValues;
  1703. numValues = ((numVals + 2) * 3) / 2;
  1704. values.realloc (numValues + 1);
  1705. while (oldSize < numValues)
  1706. values [oldSize++] = 0;
  1707. }
  1708. }
  1709. bool BigInteger::operator[] (const int bit) const throw()
  1710. {
  1711. return bit <= highestBit && bit >= 0
  1712. && ((values [bit >> 5] & (1 << (bit & 31))) != 0);
  1713. }
  1714. int BigInteger::toInteger() const throw()
  1715. {
  1716. const int n = (int) (values[0] & 0x7fffffff);
  1717. return negative ? -n : n;
  1718. }
  1719. const BigInteger BigInteger::getBitRange (int startBit, int numBits) const
  1720. {
  1721. BigInteger r;
  1722. numBits = jmin (numBits, getHighestBit() + 1 - startBit);
  1723. r.ensureSize (numBits >> 5);
  1724. r.highestBit = numBits;
  1725. int i = 0;
  1726. while (numBits > 0)
  1727. {
  1728. r.values[i++] = getBitRangeAsInt (startBit, jmin (32, numBits));
  1729. numBits -= 32;
  1730. startBit += 32;
  1731. }
  1732. r.highestBit = r.getHighestBit();
  1733. return r;
  1734. }
  1735. int BigInteger::getBitRangeAsInt (const int startBit, int numBits) const throw()
  1736. {
  1737. if (numBits > 32)
  1738. {
  1739. jassertfalse // use getBitRange() if you need more than 32 bits..
  1740. numBits = 32;
  1741. }
  1742. numBits = jmin (numBits, highestBit + 1 - startBit);
  1743. if (numBits <= 0)
  1744. return 0;
  1745. const int pos = startBit >> 5;
  1746. const int offset = startBit & 31;
  1747. const int endSpace = 32 - numBits;
  1748. uint32 n = ((uint32) values [pos]) >> offset;
  1749. if (offset > endSpace)
  1750. n |= ((uint32) values [pos + 1]) << (32 - offset);
  1751. return (int) (n & (((uint32) 0xffffffff) >> endSpace));
  1752. }
  1753. void BigInteger::setBitRangeAsInt (const int startBit, int numBits, unsigned int valueToSet)
  1754. {
  1755. if (numBits > 32)
  1756. {
  1757. jassertfalse
  1758. numBits = 32;
  1759. }
  1760. for (int i = 0; i < numBits; ++i)
  1761. {
  1762. setBit (startBit + i, (valueToSet & 1) != 0);
  1763. valueToSet >>= 1;
  1764. }
  1765. }
  1766. void BigInteger::clear()
  1767. {
  1768. if (numValues > 16)
  1769. {
  1770. numValues = 4;
  1771. values.calloc (numValues + 1);
  1772. }
  1773. else
  1774. {
  1775. zeromem (values, sizeof (unsigned int) * (numValues + 1));
  1776. }
  1777. highestBit = -1;
  1778. negative = false;
  1779. }
  1780. void BigInteger::setBit (const int bit)
  1781. {
  1782. if (bit >= 0)
  1783. {
  1784. if (bit > highestBit)
  1785. {
  1786. ensureSize (bit >> 5);
  1787. highestBit = bit;
  1788. }
  1789. values [bit >> 5] |= (1 << (bit & 31));
  1790. }
  1791. }
  1792. void BigInteger::setBit (const int bit, const bool shouldBeSet)
  1793. {
  1794. if (shouldBeSet)
  1795. setBit (bit);
  1796. else
  1797. clearBit (bit);
  1798. }
  1799. void BigInteger::clearBit (const int bit) throw()
  1800. {
  1801. if (bit >= 0 && bit <= highestBit)
  1802. values [bit >> 5] &= ~(1 << (bit & 31));
  1803. }
  1804. void BigInteger::setRange (int startBit, int numBits, const bool shouldBeSet)
  1805. {
  1806. while (--numBits >= 0)
  1807. setBit (startBit++, shouldBeSet);
  1808. }
  1809. void BigInteger::insertBit (const int bit, const bool shouldBeSet)
  1810. {
  1811. if (bit >= 0)
  1812. shiftBits (1, bit);
  1813. setBit (bit, shouldBeSet);
  1814. }
  1815. bool BigInteger::isZero() const throw()
  1816. {
  1817. return getHighestBit() < 0;
  1818. }
  1819. bool BigInteger::isOne() const throw()
  1820. {
  1821. return getHighestBit() == 0 && ! negative;
  1822. }
  1823. bool BigInteger::isNegative() const throw()
  1824. {
  1825. return negative && ! isZero();
  1826. }
  1827. void BigInteger::setNegative (const bool neg) throw()
  1828. {
  1829. negative = neg;
  1830. }
  1831. void BigInteger::negate() throw()
  1832. {
  1833. negative = (! negative) && ! isZero();
  1834. }
  1835. int BigInteger::countNumberOfSetBits() const throw()
  1836. {
  1837. int total = 0;
  1838. for (int i = (highestBit >> 5) + 1; --i >= 0;)
  1839. {
  1840. unsigned int n = values[i];
  1841. if (n == 0xffffffff)
  1842. {
  1843. total += 32;
  1844. }
  1845. else
  1846. {
  1847. while (n != 0)
  1848. {
  1849. total += (n & 1);
  1850. n >>= 1;
  1851. }
  1852. }
  1853. }
  1854. return total;
  1855. }
  1856. int BigInteger::getHighestBit() const throw()
  1857. {
  1858. for (int i = highestBit + 1; --i >= 0;)
  1859. if ((values [i >> 5] & (1 << (i & 31))) != 0)
  1860. return i;
  1861. return -1;
  1862. }
  1863. int BigInteger::findNextSetBit (int i) const throw()
  1864. {
  1865. for (; i <= highestBit; ++i)
  1866. if ((values [i >> 5] & (1 << (i & 31))) != 0)
  1867. return i;
  1868. return -1;
  1869. }
  1870. int BigInteger::findNextClearBit (int i) const throw()
  1871. {
  1872. for (; i <= highestBit; ++i)
  1873. if ((values [i >> 5] & (1 << (i & 31))) == 0)
  1874. break;
  1875. return i;
  1876. }
  1877. BigInteger& BigInteger::operator+= (const BigInteger& other)
  1878. {
  1879. if (other.isNegative())
  1880. return operator-= (-other);
  1881. if (isNegative())
  1882. {
  1883. if (compareAbsolute (other) < 0)
  1884. {
  1885. BigInteger temp (*this);
  1886. temp.negate();
  1887. *this = other;
  1888. operator-= (temp);
  1889. }
  1890. else
  1891. {
  1892. negate();
  1893. operator-= (other);
  1894. negate();
  1895. }
  1896. }
  1897. else
  1898. {
  1899. if (other.highestBit > highestBit)
  1900. highestBit = other.highestBit;
  1901. ++highestBit;
  1902. const int numInts = (highestBit >> 5) + 1;
  1903. ensureSize (numInts);
  1904. int64 remainder = 0;
  1905. for (int i = 0; i <= numInts; ++i)
  1906. {
  1907. if (i < numValues)
  1908. remainder += values[i];
  1909. if (i < other.numValues)
  1910. remainder += other.values[i];
  1911. values[i] = (unsigned int) remainder;
  1912. remainder >>= 32;
  1913. }
  1914. jassert (remainder == 0);
  1915. highestBit = getHighestBit();
  1916. }
  1917. return *this;
  1918. }
  1919. BigInteger& BigInteger::operator-= (const BigInteger& other)
  1920. {
  1921. if (other.isNegative())
  1922. return operator+= (-other);
  1923. if (! isNegative())
  1924. {
  1925. if (compareAbsolute (other) < 0)
  1926. {
  1927. BigInteger temp (other);
  1928. swapWith (temp);
  1929. operator-= (temp);
  1930. negate();
  1931. return *this;
  1932. }
  1933. }
  1934. else
  1935. {
  1936. negate();
  1937. operator+= (other);
  1938. negate();
  1939. return *this;
  1940. }
  1941. const int numInts = (highestBit >> 5) + 1;
  1942. const int maxOtherInts = (other.highestBit >> 5) + 1;
  1943. int64 amountToSubtract = 0;
  1944. for (int i = 0; i <= numInts; ++i)
  1945. {
  1946. if (i <= maxOtherInts)
  1947. amountToSubtract += (int64) other.values[i];
  1948. if (values[i] >= amountToSubtract)
  1949. {
  1950. values[i] = (unsigned int) (values[i] - amountToSubtract);
  1951. amountToSubtract = 0;
  1952. }
  1953. else
  1954. {
  1955. const int64 n = ((int64) values[i] + (((int64) 1) << 32)) - amountToSubtract;
  1956. values[i] = (unsigned int) n;
  1957. amountToSubtract = 1;
  1958. }
  1959. }
  1960. return *this;
  1961. }
  1962. BigInteger& BigInteger::operator*= (const BigInteger& other)
  1963. {
  1964. BigInteger total;
  1965. highestBit = getHighestBit();
  1966. const bool wasNegative = isNegative();
  1967. setNegative (false);
  1968. for (int i = 0; i <= highestBit; ++i)
  1969. {
  1970. if (operator[](i))
  1971. {
  1972. BigInteger n (other);
  1973. n.setNegative (false);
  1974. n <<= i;
  1975. total += n;
  1976. }
  1977. }
  1978. total.setNegative (wasNegative ^ other.isNegative());
  1979. swapWith (total);
  1980. return *this;
  1981. }
  1982. void BigInteger::divideBy (const BigInteger& divisor, BigInteger& remainder)
  1983. {
  1984. jassert (this != &remainder); // (can't handle passing itself in to get the remainder)
  1985. const int divHB = divisor.getHighestBit();
  1986. const int ourHB = getHighestBit();
  1987. if (divHB < 0 || ourHB < 0)
  1988. {
  1989. // division by zero
  1990. remainder.clear();
  1991. clear();
  1992. }
  1993. else
  1994. {
  1995. const bool wasNegative = isNegative();
  1996. swapWith (remainder);
  1997. remainder.setNegative (false);
  1998. clear();
  1999. BigInteger temp (divisor);
  2000. temp.setNegative (false);
  2001. int leftShift = ourHB - divHB;
  2002. temp <<= leftShift;
  2003. while (leftShift >= 0)
  2004. {
  2005. if (remainder.compareAbsolute (temp) >= 0)
  2006. {
  2007. remainder -= temp;
  2008. setBit (leftShift);
  2009. }
  2010. if (--leftShift >= 0)
  2011. temp >>= 1;
  2012. }
  2013. negative = wasNegative ^ divisor.isNegative();
  2014. remainder.setNegative (wasNegative);
  2015. }
  2016. }
  2017. BigInteger& BigInteger::operator/= (const BigInteger& other)
  2018. {
  2019. BigInteger remainder;
  2020. divideBy (other, remainder);
  2021. return *this;
  2022. }
  2023. BigInteger& BigInteger::operator|= (const BigInteger& other)
  2024. {
  2025. // this operation doesn't take into account negative values..
  2026. jassert (isNegative() == other.isNegative());
  2027. if (other.highestBit >= 0)
  2028. {
  2029. ensureSize (other.highestBit >> 5);
  2030. int n = (other.highestBit >> 5) + 1;
  2031. while (--n >= 0)
  2032. values[n] |= other.values[n];
  2033. if (other.highestBit > highestBit)
  2034. highestBit = other.highestBit;
  2035. highestBit = getHighestBit();
  2036. }
  2037. return *this;
  2038. }
  2039. BigInteger& BigInteger::operator&= (const BigInteger& other)
  2040. {
  2041. // this operation doesn't take into account negative values..
  2042. jassert (isNegative() == other.isNegative());
  2043. int n = numValues;
  2044. while (n > other.numValues)
  2045. values[--n] = 0;
  2046. while (--n >= 0)
  2047. values[n] &= other.values[n];
  2048. if (other.highestBit < highestBit)
  2049. highestBit = other.highestBit;
  2050. highestBit = getHighestBit();
  2051. return *this;
  2052. }
  2053. BigInteger& BigInteger::operator^= (const BigInteger& other)
  2054. {
  2055. // this operation will only work with the absolute values
  2056. jassert (isNegative() == other.isNegative());
  2057. if (other.highestBit >= 0)
  2058. {
  2059. ensureSize (other.highestBit >> 5);
  2060. int n = (other.highestBit >> 5) + 1;
  2061. while (--n >= 0)
  2062. values[n] ^= other.values[n];
  2063. if (other.highestBit > highestBit)
  2064. highestBit = other.highestBit;
  2065. highestBit = getHighestBit();
  2066. }
  2067. return *this;
  2068. }
  2069. BigInteger& BigInteger::operator%= (const BigInteger& divisor)
  2070. {
  2071. BigInteger remainder;
  2072. divideBy (divisor, remainder);
  2073. swapWith (remainder);
  2074. return *this;
  2075. }
  2076. BigInteger& BigInteger::operator<<= (int numBitsToShift)
  2077. {
  2078. shiftBits (numBitsToShift, 0);
  2079. return *this;
  2080. }
  2081. BigInteger& BigInteger::operator>>= (int numBitsToShift)
  2082. {
  2083. return operator<<= (-numBitsToShift);
  2084. }
  2085. BigInteger& BigInteger::operator++() { return operator+= (1); }
  2086. BigInteger& BigInteger::operator--() { return operator-= (1); }
  2087. const BigInteger BigInteger::operator++ (int) { const BigInteger old (*this); operator+= (1); return old; }
  2088. const BigInteger BigInteger::operator-- (int) { const BigInteger old (*this); operator-= (1); return old; }
  2089. const BigInteger BigInteger::operator+ (const BigInteger& other) const { BigInteger b (*this); return b += other; }
  2090. const BigInteger BigInteger::operator- (const BigInteger& other) const { BigInteger b (*this); return b -= other; }
  2091. const BigInteger BigInteger::operator* (const BigInteger& other) const { BigInteger b (*this); return b *= other; }
  2092. const BigInteger BigInteger::operator/ (const BigInteger& other) const { BigInteger b (*this); return b /= other; }
  2093. const BigInteger BigInteger::operator| (const BigInteger& other) const { BigInteger b (*this); return b |= other; }
  2094. const BigInteger BigInteger::operator& (const BigInteger& other) const { BigInteger b (*this); return b &= other; }
  2095. const BigInteger BigInteger::operator^ (const BigInteger& other) const { BigInteger b (*this); return b ^= other; }
  2096. const BigInteger BigInteger::operator% (const BigInteger& other) const { BigInteger b (*this); return b %= other; }
  2097. const BigInteger BigInteger::operator<< (const int numBits) const { BigInteger b (*this); return b <<= numBits; }
  2098. const BigInteger BigInteger::operator>> (const int numBits) const { BigInteger b (*this); return b >>= numBits; }
  2099. const BigInteger BigInteger::operator-() const { BigInteger b (*this); b.negate(); return b; }
  2100. int BigInteger::compare (const BigInteger& other) const throw()
  2101. {
  2102. if (isNegative() == other.isNegative())
  2103. {
  2104. const int absComp = compareAbsolute (other);
  2105. return isNegative() ? -absComp : absComp;
  2106. }
  2107. else
  2108. {
  2109. return isNegative() ? -1 : 1;
  2110. }
  2111. }
  2112. int BigInteger::compareAbsolute (const BigInteger& other) const throw()
  2113. {
  2114. const int h1 = getHighestBit();
  2115. const int h2 = other.getHighestBit();
  2116. if (h1 > h2)
  2117. return 1;
  2118. else if (h1 < h2)
  2119. return -1;
  2120. for (int i = (h1 >> 5) + 1; --i >= 0;)
  2121. if (values[i] != other.values[i])
  2122. return (values[i] > other.values[i]) ? 1 : -1;
  2123. return 0;
  2124. }
  2125. bool BigInteger::operator== (const BigInteger& other) const throw() { return compare (other) == 0; }
  2126. bool BigInteger::operator!= (const BigInteger& other) const throw() { return compare (other) != 0; }
  2127. bool BigInteger::operator< (const BigInteger& other) const throw() { return compare (other) < 0; }
  2128. bool BigInteger::operator<= (const BigInteger& other) const throw() { return compare (other) <= 0; }
  2129. bool BigInteger::operator> (const BigInteger& other) const throw() { return compare (other) > 0; }
  2130. bool BigInteger::operator>= (const BigInteger& other) const throw() { return compare (other) >= 0; }
  2131. void BigInteger::shiftBits (int bits, const int startBit)
  2132. {
  2133. if (highestBit < 0)
  2134. return;
  2135. if (startBit > 0)
  2136. {
  2137. if (bits < 0)
  2138. {
  2139. // right shift
  2140. for (int i = startBit; i <= highestBit; ++i)
  2141. setBit (i, operator[] (i - bits));
  2142. highestBit = getHighestBit();
  2143. }
  2144. else if (bits > 0)
  2145. {
  2146. // left shift
  2147. for (int i = highestBit + 1; --i >= startBit;)
  2148. setBit (i + bits, operator[] (i));
  2149. while (--bits >= 0)
  2150. clearBit (bits + startBit);
  2151. }
  2152. }
  2153. else
  2154. {
  2155. if (bits < 0)
  2156. {
  2157. // right shift
  2158. bits = -bits;
  2159. if (bits > highestBit)
  2160. {
  2161. clear();
  2162. }
  2163. else
  2164. {
  2165. const int wordsToMove = bits >> 5;
  2166. int top = 1 + (highestBit >> 5) - wordsToMove;
  2167. highestBit -= bits;
  2168. if (wordsToMove > 0)
  2169. {
  2170. int i;
  2171. for (i = 0; i < top; ++i)
  2172. values [i] = values [i + wordsToMove];
  2173. for (i = 0; i < wordsToMove; ++i)
  2174. values [top + i] = 0;
  2175. bits &= 31;
  2176. }
  2177. if (bits != 0)
  2178. {
  2179. const int invBits = 32 - bits;
  2180. --top;
  2181. for (int i = 0; i < top; ++i)
  2182. values[i] = (values[i] >> bits) | (values [i + 1] << invBits);
  2183. values[top] = (values[top] >> bits);
  2184. }
  2185. highestBit = getHighestBit();
  2186. }
  2187. }
  2188. else if (bits > 0)
  2189. {
  2190. // left shift
  2191. ensureSize (((highestBit + bits) >> 5) + 1);
  2192. const int wordsToMove = bits >> 5;
  2193. int top = 1 + (highestBit >> 5);
  2194. highestBit += bits;
  2195. if (wordsToMove > 0)
  2196. {
  2197. int i;
  2198. for (i = top; --i >= 0;)
  2199. values [i + wordsToMove] = values [i];
  2200. for (i = 0; i < wordsToMove; ++i)
  2201. values [i] = 0;
  2202. bits &= 31;
  2203. }
  2204. if (bits != 0)
  2205. {
  2206. const int invBits = 32 - bits;
  2207. for (int i = top + 1 + wordsToMove; --i > wordsToMove;)
  2208. values[i] = (values[i] << bits) | (values [i - 1] >> invBits);
  2209. values [wordsToMove] = values [wordsToMove] << bits;
  2210. }
  2211. highestBit = getHighestBit();
  2212. }
  2213. }
  2214. }
  2215. const BigInteger BigInteger::simpleGCD (BigInteger* m, BigInteger* n)
  2216. {
  2217. while (! m->isZero())
  2218. {
  2219. if (n->compareAbsolute (*m) > 0)
  2220. swapVariables (m, n);
  2221. *m -= *n;
  2222. }
  2223. return *n;
  2224. }
  2225. const BigInteger BigInteger::findGreatestCommonDivisor (BigInteger n) const
  2226. {
  2227. BigInteger m (*this);
  2228. while (! n.isZero())
  2229. {
  2230. if (abs (m.getHighestBit() - n.getHighestBit()) <= 16)
  2231. return simpleGCD (&m, &n);
  2232. BigInteger temp1 (m), temp2;
  2233. temp1.divideBy (n, temp2);
  2234. m = n;
  2235. n = temp2;
  2236. }
  2237. return m;
  2238. }
  2239. void BigInteger::exponentModulo (const BigInteger& exponent, const BigInteger& modulus)
  2240. {
  2241. BigInteger exp (exponent);
  2242. exp %= modulus;
  2243. BigInteger value (1);
  2244. swapWith (value);
  2245. value %= modulus;
  2246. while (! exp.isZero())
  2247. {
  2248. if (exp [0])
  2249. {
  2250. operator*= (value);
  2251. operator%= (modulus);
  2252. }
  2253. value *= value;
  2254. value %= modulus;
  2255. exp >>= 1;
  2256. }
  2257. }
  2258. void BigInteger::inverseModulo (const BigInteger& modulus)
  2259. {
  2260. if (modulus.isOne() || modulus.isNegative())
  2261. {
  2262. clear();
  2263. return;
  2264. }
  2265. if (isNegative() || compareAbsolute (modulus) >= 0)
  2266. operator%= (modulus);
  2267. if (isOne())
  2268. return;
  2269. if (! (*this)[0])
  2270. {
  2271. // not invertible
  2272. clear();
  2273. return;
  2274. }
  2275. BigInteger a1 (modulus);
  2276. BigInteger a2 (*this);
  2277. BigInteger b1 (modulus);
  2278. BigInteger b2 (1);
  2279. while (! a2.isOne())
  2280. {
  2281. BigInteger temp1, temp2, multiplier (a1);
  2282. multiplier.divideBy (a2, temp1);
  2283. temp1 = a2;
  2284. temp1 *= multiplier;
  2285. temp2 = a1;
  2286. temp2 -= temp1;
  2287. a1 = a2;
  2288. a2 = temp2;
  2289. temp1 = b2;
  2290. temp1 *= multiplier;
  2291. temp2 = b1;
  2292. temp2 -= temp1;
  2293. b1 = b2;
  2294. b2 = temp2;
  2295. }
  2296. while (b2.isNegative())
  2297. b2 += modulus;
  2298. b2 %= modulus;
  2299. swapWith (b2);
  2300. }
  2301. OutputStream& JUCE_CALLTYPE operator<< (OutputStream& stream, const BigInteger& value)
  2302. {
  2303. return stream << value.toString (10);
  2304. }
  2305. const String BigInteger::toString (const int base, const int minimumNumCharacters) const
  2306. {
  2307. String s;
  2308. BigInteger v (*this);
  2309. if (base == 2 || base == 8 || base == 16)
  2310. {
  2311. const int bits = (base == 2) ? 1 : (base == 8 ? 3 : 4);
  2312. static const juce_wchar* const hexDigits = T("0123456789abcdef");
  2313. for (;;)
  2314. {
  2315. const int remainder = v.getBitRangeAsInt (0, bits);
  2316. v >>= bits;
  2317. if (remainder == 0 && v.isZero())
  2318. break;
  2319. s = String::charToString (hexDigits [remainder]) + s;
  2320. }
  2321. }
  2322. else if (base == 10)
  2323. {
  2324. const BigInteger ten (10);
  2325. BigInteger remainder;
  2326. for (;;)
  2327. {
  2328. v.divideBy (ten, remainder);
  2329. if (remainder.isZero() && v.isZero())
  2330. break;
  2331. s = String (remainder.getBitRangeAsInt (0, 8)) + s;
  2332. }
  2333. }
  2334. else
  2335. {
  2336. jassertfalse // can't do the specified base!
  2337. return String::empty;
  2338. }
  2339. s = s.paddedLeft ('0', minimumNumCharacters);
  2340. return isNegative() ? T("-") + s : s;
  2341. }
  2342. void BigInteger::parseString (const String& text, const int base)
  2343. {
  2344. clear();
  2345. const juce_wchar* t = (const juce_wchar*) text;
  2346. if (base == 2 || base == 8 || base == 16)
  2347. {
  2348. const int bits = (base == 2) ? 1 : (base == 8 ? 3 : 4);
  2349. for (;;)
  2350. {
  2351. const juce_wchar c = *t++;
  2352. const int digit = CharacterFunctions::getHexDigitValue (c);
  2353. if (((unsigned int) digit) < (unsigned int) base)
  2354. {
  2355. operator<<= (bits);
  2356. operator+= (digit);
  2357. }
  2358. else if (c == 0)
  2359. {
  2360. break;
  2361. }
  2362. }
  2363. }
  2364. else if (base == 10)
  2365. {
  2366. const BigInteger ten ((unsigned int) 10);
  2367. for (;;)
  2368. {
  2369. const juce_wchar c = *t++;
  2370. if (c >= T('0') && c <= T('9'))
  2371. {
  2372. operator*= (ten);
  2373. operator+= ((int) (c - T('0')));
  2374. }
  2375. else if (c == 0)
  2376. {
  2377. break;
  2378. }
  2379. }
  2380. }
  2381. setNegative (text.trimStart().startsWithChar (T('-')));
  2382. }
  2383. const MemoryBlock BigInteger::toMemoryBlock() const
  2384. {
  2385. const int numBytes = (getHighestBit() + 8) >> 3;
  2386. MemoryBlock mb ((size_t) numBytes);
  2387. for (int i = 0; i < numBytes; ++i)
  2388. mb[i] = (uint8) getBitRangeAsInt (i << 3, 8);
  2389. return mb;
  2390. }
  2391. void BigInteger::loadFromMemoryBlock (const MemoryBlock& data)
  2392. {
  2393. clear();
  2394. for (int i = (int) data.getSize(); --i >= 0;)
  2395. this->setBitRangeAsInt ((int) (i << 3), 8, data [i]);
  2396. }
  2397. END_JUCE_NAMESPACE
  2398. /*** End of inlined file: juce_BitArray.cpp ***/
  2399. /*** Start of inlined file: juce_MemoryBlock.cpp ***/
  2400. BEGIN_JUCE_NAMESPACE
  2401. MemoryBlock::MemoryBlock() throw()
  2402. : size (0)
  2403. {
  2404. }
  2405. MemoryBlock::MemoryBlock (const size_t initialSize,
  2406. const bool initialiseToZero) throw()
  2407. {
  2408. if (initialSize > 0)
  2409. {
  2410. size = initialSize;
  2411. data.allocate (initialSize, initialiseToZero);
  2412. }
  2413. else
  2414. {
  2415. size = 0;
  2416. }
  2417. }
  2418. MemoryBlock::MemoryBlock (const MemoryBlock& other) throw()
  2419. : size (other.size)
  2420. {
  2421. if (size > 0)
  2422. {
  2423. jassert (other.data != 0);
  2424. data.malloc (size);
  2425. memcpy (data, other.data, size);
  2426. }
  2427. }
  2428. MemoryBlock::MemoryBlock (const void* const dataToInitialiseFrom,
  2429. const size_t sizeInBytes) throw()
  2430. : size (jmax ((size_t) 0, sizeInBytes))
  2431. {
  2432. jassert (sizeInBytes >= 0);
  2433. if (size > 0)
  2434. {
  2435. jassert (dataToInitialiseFrom != 0); // non-zero size, but a zero pointer passed-in?
  2436. data.malloc (size);
  2437. if (dataToInitialiseFrom != 0)
  2438. memcpy (data, dataToInitialiseFrom, size);
  2439. }
  2440. }
  2441. MemoryBlock::~MemoryBlock() throw()
  2442. {
  2443. jassert (size >= 0); // should never happen
  2444. jassert (size == 0 || data != 0); // non-zero size but no data allocated?
  2445. }
  2446. MemoryBlock& MemoryBlock::operator= (const MemoryBlock& other) throw()
  2447. {
  2448. if (this != &other)
  2449. {
  2450. setSize (other.size, false);
  2451. memcpy (data, other.data, size);
  2452. }
  2453. return *this;
  2454. }
  2455. bool MemoryBlock::operator== (const MemoryBlock& other) const throw()
  2456. {
  2457. return matches (other.data, other.size);
  2458. }
  2459. bool MemoryBlock::operator!= (const MemoryBlock& other) const throw()
  2460. {
  2461. return ! operator== (other);
  2462. }
  2463. bool MemoryBlock::matches (const void* dataToCompare, size_t dataSize) const throw()
  2464. {
  2465. return size == dataSize
  2466. && memcmp (data, dataToCompare, size) == 0;
  2467. }
  2468. // this will resize the block to this size
  2469. void MemoryBlock::setSize (const size_t newSize,
  2470. const bool initialiseToZero) throw()
  2471. {
  2472. if (size != newSize)
  2473. {
  2474. if (newSize <= 0)
  2475. {
  2476. data.free();
  2477. size = 0;
  2478. }
  2479. else
  2480. {
  2481. if (data != 0)
  2482. {
  2483. data.realloc (newSize);
  2484. if (initialiseToZero && (newSize > size))
  2485. zeromem (data + size, newSize - size);
  2486. }
  2487. else
  2488. {
  2489. data.allocate (newSize, initialiseToZero);
  2490. }
  2491. size = newSize;
  2492. }
  2493. }
  2494. }
  2495. void MemoryBlock::ensureSize (const size_t minimumSize,
  2496. const bool initialiseToZero) throw()
  2497. {
  2498. if (size < minimumSize)
  2499. setSize (minimumSize, initialiseToZero);
  2500. }
  2501. void MemoryBlock::swapWith (MemoryBlock& other) throw()
  2502. {
  2503. swapVariables (size, other.size);
  2504. data.swapWith (other.data);
  2505. }
  2506. void MemoryBlock::fillWith (const uint8 value) throw()
  2507. {
  2508. memset (data, (int) value, size);
  2509. }
  2510. void MemoryBlock::append (const void* const srcData,
  2511. const size_t numBytes) throw()
  2512. {
  2513. if (numBytes > 0)
  2514. {
  2515. const size_t oldSize = size;
  2516. setSize (size + numBytes);
  2517. memcpy (data + oldSize, srcData, numBytes);
  2518. }
  2519. }
  2520. void MemoryBlock::copyFrom (const void* const src, int offset, size_t num) throw()
  2521. {
  2522. const char* d = static_cast<const char*> (src);
  2523. if (offset < 0)
  2524. {
  2525. d -= offset;
  2526. num -= offset;
  2527. offset = 0;
  2528. }
  2529. if (offset + num > size)
  2530. num = size - offset;
  2531. if (num > 0)
  2532. memcpy (data + offset, d, num);
  2533. }
  2534. void MemoryBlock::copyTo (void* const dst, int offset, size_t num) const throw()
  2535. {
  2536. char* d = static_cast<char*> (dst);
  2537. if (offset < 0)
  2538. {
  2539. zeromem (d, -offset);
  2540. d -= offset;
  2541. num += offset;
  2542. offset = 0;
  2543. }
  2544. if (offset + num > size)
  2545. {
  2546. const size_t newNum = size - offset;
  2547. zeromem (d + newNum, num - newNum);
  2548. num = newNum;
  2549. }
  2550. if (num > 0)
  2551. memcpy (d, data + offset, num);
  2552. }
  2553. void MemoryBlock::removeSection (size_t startByte, size_t numBytesToRemove) throw()
  2554. {
  2555. if (startByte < 0)
  2556. {
  2557. numBytesToRemove += startByte;
  2558. startByte = 0;
  2559. }
  2560. if (startByte + numBytesToRemove >= size)
  2561. {
  2562. setSize (startByte);
  2563. }
  2564. else if (numBytesToRemove > 0)
  2565. {
  2566. memmove (data + startByte,
  2567. data + startByte + numBytesToRemove,
  2568. size - (startByte + numBytesToRemove));
  2569. setSize (size - numBytesToRemove);
  2570. }
  2571. }
  2572. const String MemoryBlock::toString() const throw()
  2573. {
  2574. return String ((const char*) data, size);
  2575. }
  2576. int MemoryBlock::getBitRange (const size_t bitRangeStart, size_t numBits) const throw()
  2577. {
  2578. int res = 0;
  2579. size_t byte = bitRangeStart >> 3;
  2580. int offsetInByte = (int) bitRangeStart & 7;
  2581. size_t bitsSoFar = 0;
  2582. while (numBits > 0 && (size_t) byte < size)
  2583. {
  2584. const int bitsThisTime = jmin ((int) numBits, 8 - offsetInByte);
  2585. const int mask = (0xff >> (8 - bitsThisTime)) << offsetInByte;
  2586. res |= (((data[byte] & mask) >> offsetInByte) << bitsSoFar);
  2587. bitsSoFar += bitsThisTime;
  2588. numBits -= bitsThisTime;
  2589. ++byte;
  2590. offsetInByte = 0;
  2591. }
  2592. return res;
  2593. }
  2594. void MemoryBlock::setBitRange (const size_t bitRangeStart, size_t numBits, int bitsToSet) throw()
  2595. {
  2596. size_t byte = bitRangeStart >> 3;
  2597. int offsetInByte = (int) bitRangeStart & 7;
  2598. unsigned int mask = ~((((unsigned int) 0xffffffff) << (32 - numBits)) >> (32 - numBits));
  2599. while (numBits > 0 && (size_t) byte < size)
  2600. {
  2601. const int bitsThisTime = jmin ((int) numBits, 8 - offsetInByte);
  2602. const unsigned int tempMask = (mask << offsetInByte) | ~((((unsigned int) 0xffffffff) >> offsetInByte) << offsetInByte);
  2603. const unsigned int tempBits = bitsToSet << offsetInByte;
  2604. data[byte] = (char) ((data[byte] & tempMask) | tempBits);
  2605. ++byte;
  2606. numBits -= bitsThisTime;
  2607. bitsToSet >>= bitsThisTime;
  2608. mask >>= bitsThisTime;
  2609. offsetInByte = 0;
  2610. }
  2611. }
  2612. void MemoryBlock::loadFromHexString (const String& hex) throw()
  2613. {
  2614. ensureSize (hex.length() >> 1);
  2615. char* dest = data;
  2616. int i = 0;
  2617. for (;;)
  2618. {
  2619. int byte = 0;
  2620. for (int loop = 2; --loop >= 0;)
  2621. {
  2622. byte <<= 4;
  2623. for (;;)
  2624. {
  2625. const juce_wchar c = hex [i++];
  2626. if (c >= T('0') && c <= T('9'))
  2627. {
  2628. byte |= c - T('0');
  2629. break;
  2630. }
  2631. else if (c >= T('a') && c <= T('z'))
  2632. {
  2633. byte |= c - (T('a') - 10);
  2634. break;
  2635. }
  2636. else if (c >= T('A') && c <= T('Z'))
  2637. {
  2638. byte |= c - (T('A') - 10);
  2639. break;
  2640. }
  2641. else if (c == 0)
  2642. {
  2643. setSize (static_cast <size_t> (dest - data));
  2644. return;
  2645. }
  2646. }
  2647. }
  2648. *dest++ = (char) byte;
  2649. }
  2650. }
  2651. static const char* const encodingTable
  2652. = ".ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+";
  2653. const String MemoryBlock::toBase64Encoding() const throw()
  2654. {
  2655. const size_t numChars = ((size << 3) + 5) / 6;
  2656. String destString ((unsigned int) size); // store the length, followed by a '.', and then the data.
  2657. const int initialLen = destString.length();
  2658. destString.preallocateStorage (initialLen + 2 + numChars);
  2659. tchar* d = const_cast <tchar*> (((const tchar*) destString) + initialLen);
  2660. *d++ = T('.');
  2661. for (size_t i = 0; i < numChars; ++i)
  2662. *d++ = encodingTable [getBitRange (i * 6, 6)];
  2663. *d++ = 0;
  2664. return destString;
  2665. }
  2666. bool MemoryBlock::fromBase64Encoding (const String& s) throw()
  2667. {
  2668. const int startPos = s.indexOfChar (T('.')) + 1;
  2669. if (startPos <= 0)
  2670. return false;
  2671. const int numBytesNeeded = s.substring (0, startPos - 1).getIntValue();
  2672. setSize (numBytesNeeded, true);
  2673. const int numChars = s.length() - startPos;
  2674. const tchar* const srcChars = ((const tchar*) s) + startPos;
  2675. int pos = 0;
  2676. for (int i = 0; i < numChars; ++i)
  2677. {
  2678. const char c = (char) srcChars[i];
  2679. for (int j = 0; j < 64; ++j)
  2680. {
  2681. if (encodingTable[j] == c)
  2682. {
  2683. setBitRange (pos, 6, j);
  2684. pos += 6;
  2685. break;
  2686. }
  2687. }
  2688. }
  2689. return true;
  2690. }
  2691. END_JUCE_NAMESPACE
  2692. /*** End of inlined file: juce_MemoryBlock.cpp ***/
  2693. /*** Start of inlined file: juce_PropertySet.cpp ***/
  2694. BEGIN_JUCE_NAMESPACE
  2695. PropertySet::PropertySet (const bool ignoreCaseOfKeyNames) throw()
  2696. : properties (ignoreCaseOfKeyNames),
  2697. fallbackProperties (0),
  2698. ignoreCaseOfKeys (ignoreCaseOfKeyNames)
  2699. {
  2700. }
  2701. PropertySet::PropertySet (const PropertySet& other) throw()
  2702. : properties (other.properties),
  2703. fallbackProperties (other.fallbackProperties),
  2704. ignoreCaseOfKeys (other.ignoreCaseOfKeys)
  2705. {
  2706. }
  2707. PropertySet& PropertySet::operator= (const PropertySet& other) throw()
  2708. {
  2709. properties = other.properties;
  2710. fallbackProperties = other.fallbackProperties;
  2711. ignoreCaseOfKeys = other.ignoreCaseOfKeys;
  2712. propertyChanged();
  2713. return *this;
  2714. }
  2715. PropertySet::~PropertySet()
  2716. {
  2717. }
  2718. void PropertySet::clear()
  2719. {
  2720. const ScopedLock sl (lock);
  2721. if (properties.size() > 0)
  2722. {
  2723. properties.clear();
  2724. propertyChanged();
  2725. }
  2726. }
  2727. const String PropertySet::getValue (const String& keyName,
  2728. const String& defaultValue) const throw()
  2729. {
  2730. const ScopedLock sl (lock);
  2731. const int index = properties.getAllKeys().indexOf (keyName, ignoreCaseOfKeys);
  2732. if (index >= 0)
  2733. return properties.getAllValues() [index];
  2734. return fallbackProperties != 0 ? fallbackProperties->getValue (keyName, defaultValue)
  2735. : defaultValue;
  2736. }
  2737. int PropertySet::getIntValue (const String& keyName,
  2738. const int defaultValue) const throw()
  2739. {
  2740. const ScopedLock sl (lock);
  2741. const int index = properties.getAllKeys().indexOf (keyName, ignoreCaseOfKeys);
  2742. if (index >= 0)
  2743. return properties.getAllValues() [index].getIntValue();
  2744. return fallbackProperties != 0 ? fallbackProperties->getIntValue (keyName, defaultValue)
  2745. : defaultValue;
  2746. }
  2747. double PropertySet::getDoubleValue (const String& keyName,
  2748. const double defaultValue) const throw()
  2749. {
  2750. const ScopedLock sl (lock);
  2751. const int index = properties.getAllKeys().indexOf (keyName, ignoreCaseOfKeys);
  2752. if (index >= 0)
  2753. return properties.getAllValues()[index].getDoubleValue();
  2754. return fallbackProperties != 0 ? fallbackProperties->getDoubleValue (keyName, defaultValue)
  2755. : defaultValue;
  2756. }
  2757. bool PropertySet::getBoolValue (const String& keyName,
  2758. const bool defaultValue) const throw()
  2759. {
  2760. const ScopedLock sl (lock);
  2761. const int index = properties.getAllKeys().indexOf (keyName, ignoreCaseOfKeys);
  2762. if (index >= 0)
  2763. return properties.getAllValues() [index].getIntValue() != 0;
  2764. return fallbackProperties != 0 ? fallbackProperties->getBoolValue (keyName, defaultValue)
  2765. : defaultValue;
  2766. }
  2767. XmlElement* PropertySet::getXmlValue (const String& keyName) const
  2768. {
  2769. XmlDocument doc (getValue (keyName));
  2770. return doc.getDocumentElement();
  2771. }
  2772. void PropertySet::setValue (const String& keyName,
  2773. const String& value) throw()
  2774. {
  2775. jassert (keyName.isNotEmpty()); // shouldn't use an empty key name!
  2776. if (keyName.isNotEmpty())
  2777. {
  2778. const ScopedLock sl (lock);
  2779. const int index = properties.getAllKeys().indexOf (keyName, ignoreCaseOfKeys);
  2780. if (index < 0 || properties.getAllValues() [index] != value)
  2781. {
  2782. properties.set (keyName, value);
  2783. propertyChanged();
  2784. }
  2785. }
  2786. }
  2787. void PropertySet::removeValue (const String& keyName) throw()
  2788. {
  2789. if (keyName.isNotEmpty())
  2790. {
  2791. const ScopedLock sl (lock);
  2792. const int index = properties.getAllKeys().indexOf (keyName, ignoreCaseOfKeys);
  2793. if (index >= 0)
  2794. {
  2795. properties.remove (keyName);
  2796. propertyChanged();
  2797. }
  2798. }
  2799. }
  2800. void PropertySet::setValue (const String& keyName, const tchar* const value) throw()
  2801. {
  2802. setValue (keyName, String (value));
  2803. }
  2804. void PropertySet::setValue (const String& keyName, const int value) throw()
  2805. {
  2806. setValue (keyName, String (value));
  2807. }
  2808. void PropertySet::setValue (const String& keyName, const double value) throw()
  2809. {
  2810. setValue (keyName, String (value));
  2811. }
  2812. void PropertySet::setValue (const String& keyName, const bool value) throw()
  2813. {
  2814. setValue (keyName, String ((value) ? T("1") : T("0")));
  2815. }
  2816. void PropertySet::setValue (const String& keyName, const XmlElement* const xml)
  2817. {
  2818. setValue (keyName, (xml == 0) ? String::empty
  2819. : xml->createDocument (String::empty, true));
  2820. }
  2821. bool PropertySet::containsKey (const String& keyName) const throw()
  2822. {
  2823. const ScopedLock sl (lock);
  2824. return properties.getAllKeys().contains (keyName, ignoreCaseOfKeys);
  2825. }
  2826. void PropertySet::setFallbackPropertySet (PropertySet* fallbackProperties_) throw()
  2827. {
  2828. const ScopedLock sl (lock);
  2829. fallbackProperties = fallbackProperties_;
  2830. }
  2831. XmlElement* PropertySet::createXml (const String& nodeName) const throw()
  2832. {
  2833. const ScopedLock sl (lock);
  2834. XmlElement* const xml = new XmlElement (nodeName);
  2835. for (int i = 0; i < properties.getAllKeys().size(); ++i)
  2836. {
  2837. XmlElement* const e = xml->createNewChildElement ("VALUE");
  2838. e->setAttribute (T("name"), properties.getAllKeys()[i]);
  2839. e->setAttribute (T("val"), properties.getAllValues()[i]);
  2840. }
  2841. return xml;
  2842. }
  2843. void PropertySet::restoreFromXml (const XmlElement& xml) throw()
  2844. {
  2845. const ScopedLock sl (lock);
  2846. clear();
  2847. forEachXmlChildElementWithTagName (xml, e, T("VALUE"))
  2848. {
  2849. if (e->hasAttribute (T("name"))
  2850. && e->hasAttribute (T("val")))
  2851. {
  2852. properties.set (e->getStringAttribute (T("name")),
  2853. e->getStringAttribute (T("val")));
  2854. }
  2855. }
  2856. if (properties.size() > 0)
  2857. propertyChanged();
  2858. }
  2859. void PropertySet::propertyChanged()
  2860. {
  2861. }
  2862. END_JUCE_NAMESPACE
  2863. /*** End of inlined file: juce_PropertySet.cpp ***/
  2864. /*** Start of inlined file: juce_Variant.cpp ***/
  2865. BEGIN_JUCE_NAMESPACE
  2866. var::var() throw()
  2867. : type (voidType)
  2868. {
  2869. value.doubleValue = 0;
  2870. }
  2871. var::~var() throw()
  2872. {
  2873. if (type == stringType)
  2874. delete value.stringValue;
  2875. else if (type == objectType && value.objectValue != 0)
  2876. value.objectValue->decReferenceCount();
  2877. }
  2878. const var var::null;
  2879. var::var (const var& valueToCopy)
  2880. : type (valueToCopy.type),
  2881. value (valueToCopy.value)
  2882. {
  2883. if (type == stringType)
  2884. value.stringValue = new String (*(value.stringValue));
  2885. else if (type == objectType && value.objectValue != 0)
  2886. value.objectValue->incReferenceCount();
  2887. }
  2888. var::var (const int value_) throw()
  2889. : type (intType)
  2890. {
  2891. value.intValue = value_;
  2892. }
  2893. var::var (const bool value_) throw()
  2894. : type (boolType)
  2895. {
  2896. value.boolValue = value_;
  2897. }
  2898. var::var (const double value_) throw()
  2899. : type (doubleType)
  2900. {
  2901. value.doubleValue = value_;
  2902. }
  2903. var::var (const String& value_)
  2904. : type (stringType)
  2905. {
  2906. value.stringValue = new String (value_);
  2907. }
  2908. var::var (const char* const value_)
  2909. : type (stringType)
  2910. {
  2911. value.stringValue = new String (value_);
  2912. }
  2913. var::var (const juce_wchar* const value_)
  2914. : type (stringType)
  2915. {
  2916. value.stringValue = new String (value_);
  2917. }
  2918. var::var (DynamicObject* const object)
  2919. : type (objectType)
  2920. {
  2921. value.objectValue = object;
  2922. if (object != 0)
  2923. object->incReferenceCount();
  2924. }
  2925. var::var (MethodFunction method_) throw()
  2926. : type (methodType)
  2927. {
  2928. value.methodValue = method_;
  2929. }
  2930. void var::swapWith (var& other) throw()
  2931. {
  2932. swapVariables (type, other.type);
  2933. swapVariables (value, other.value);
  2934. }
  2935. var& var::operator= (const var& value_) { var newValue (value_); swapWith (newValue); return *this; }
  2936. var& var::operator= (int value_) { var newValue (value_); swapWith (newValue); return *this; }
  2937. var& var::operator= (bool value_) { var newValue (value_); swapWith (newValue); return *this; }
  2938. var& var::operator= (double value_) { var newValue (value_); swapWith (newValue); return *this; }
  2939. var& var::operator= (const char* value_) { var newValue (value_); swapWith (newValue); return *this; }
  2940. var& var::operator= (const juce_wchar* value_) { var newValue (value_); swapWith (newValue); return *this; }
  2941. var& var::operator= (const String& value_) { var newValue (value_); swapWith (newValue); return *this; }
  2942. var& var::operator= (DynamicObject* value_) { var newValue (value_); swapWith (newValue); return *this; }
  2943. var& var::operator= (MethodFunction value_) { var newValue (value_); swapWith (newValue); return *this; }
  2944. var::operator int() const
  2945. {
  2946. switch (type)
  2947. {
  2948. case voidType: break;
  2949. case intType: return value.intValue;
  2950. case boolType: return value.boolValue ? 1 : 0;
  2951. case doubleType: return static_cast <int> (value.doubleValue);
  2952. case stringType: return value.stringValue->getIntValue();
  2953. case objectType: break;
  2954. default: jassertfalse; break;
  2955. }
  2956. return 0;
  2957. }
  2958. var::operator bool() const
  2959. {
  2960. switch (type)
  2961. {
  2962. case voidType: break;
  2963. case intType: return value.intValue != 0;
  2964. case boolType: return value.boolValue;
  2965. case doubleType: return value.doubleValue != 0;
  2966. case stringType: return value.stringValue->getIntValue() != 0
  2967. || value.stringValue->trim().equalsIgnoreCase (T("true"))
  2968. || value.stringValue->trim().equalsIgnoreCase (T("yes"));
  2969. case objectType: return value.objectValue != 0;
  2970. default: jassertfalse; break;
  2971. }
  2972. return false;
  2973. }
  2974. var::operator float() const
  2975. {
  2976. return (float) operator double();
  2977. }
  2978. var::operator double() const
  2979. {
  2980. switch (type)
  2981. {
  2982. case voidType: break;
  2983. case intType: return value.intValue;
  2984. case boolType: return value.boolValue ? 1.0 : 0.0;
  2985. case doubleType: return value.doubleValue;
  2986. case stringType: return value.stringValue->getDoubleValue();
  2987. case objectType: break;
  2988. default: jassertfalse; break;
  2989. }
  2990. return 0.0;
  2991. }
  2992. const String var::toString() const
  2993. {
  2994. switch (type)
  2995. {
  2996. case voidType: return String::empty;
  2997. case intType: return String (value.intValue);
  2998. case boolType: return value.boolValue ? T("1") : T("0");
  2999. case doubleType: return String (value.doubleValue);
  3000. case stringType: return *(value.stringValue);
  3001. case objectType: return "Object 0x" + String::toHexString ((int) (pointer_sized_int) value.objectValue);
  3002. case methodType: return "Method";
  3003. default: jassertfalse; break;
  3004. }
  3005. return String::empty;
  3006. }
  3007. var::operator const String() const
  3008. {
  3009. return toString();
  3010. }
  3011. DynamicObject* var::getObject() const
  3012. {
  3013. return type == objectType ? value.objectValue : 0;
  3014. }
  3015. bool var::equals (const var& other) const throw()
  3016. {
  3017. switch (type)
  3018. {
  3019. case voidType: return other.isVoid();
  3020. case intType: return value.intValue == static_cast <int> (other);
  3021. case boolType: return value.boolValue == static_cast <bool> (other);
  3022. case doubleType: return value.doubleValue == static_cast <double> (other);
  3023. case stringType: return (*(value.stringValue)) == other.toString();
  3024. case objectType: return value.objectValue == other.getObject();
  3025. case methodType: return value.methodValue == other.value.methodValue && other.isMethod();
  3026. default: jassertfalse; break;
  3027. }
  3028. return false;
  3029. }
  3030. bool operator== (const var& v1, const var& v2) throw() { return v1.equals (v2); }
  3031. bool operator!= (const var& v1, const var& v2) throw() { return ! v1.equals (v2); }
  3032. bool operator== (const var& v1, const String& v2) throw() { return v1.toString() == v2; }
  3033. bool operator!= (const var& v1, const String& v2) throw() { return v1.toString() != v2; }
  3034. void var::writeToStream (OutputStream& output) const
  3035. {
  3036. switch (type)
  3037. {
  3038. case voidType: output.writeCompressedInt (0); break;
  3039. case intType: output.writeCompressedInt (5); output.writeByte (1); output.writeInt (value.intValue); break;
  3040. case boolType: output.writeCompressedInt (1); output.writeByte (value.boolValue ? 2 : 3); break;
  3041. case doubleType: output.writeCompressedInt (9); output.writeByte (4); output.writeDouble (value.doubleValue); break;
  3042. case stringType:
  3043. {
  3044. const int len = value.stringValue->getNumBytesAsUTF8() + 1;
  3045. output.writeCompressedInt (len + 1);
  3046. output.writeByte (5);
  3047. HeapBlock<char> temp (len);
  3048. value.stringValue->copyToUTF8 (temp, len);
  3049. output.write (temp, len);
  3050. break;
  3051. }
  3052. case objectType:
  3053. case methodType: output.writeCompressedInt (0); jassertfalse; break; // Can't write an object to a stream!
  3054. default: jassertfalse; break; // Is this a corrupted object?
  3055. }
  3056. }
  3057. const var var::readFromStream (InputStream& input)
  3058. {
  3059. const int numBytes = input.readCompressedInt();
  3060. if (numBytes > 0)
  3061. {
  3062. switch (input.readByte())
  3063. {
  3064. case 1: return var (input.readInt());
  3065. case 2: return var (true);
  3066. case 3: return var (false);
  3067. case 4: return var (input.readDouble());
  3068. case 5:
  3069. {
  3070. MemoryBlock mb;
  3071. input.readIntoMemoryBlock (mb, numBytes - 1);
  3072. return var (String::fromUTF8 ((const char*) mb.getData(), (int) mb.getSize()));
  3073. }
  3074. default: input.skipNextBytes (numBytes - 1); break;
  3075. }
  3076. }
  3077. return var::null;
  3078. }
  3079. const var var::operator[] (const var::identifier& propertyName) const
  3080. {
  3081. if (type == objectType && value.objectValue != 0)
  3082. return value.objectValue->getProperty (propertyName);
  3083. return var::null;
  3084. }
  3085. const var var::invoke (const var::identifier& method, const var* arguments, int numArguments) const
  3086. {
  3087. if (type == objectType && value.objectValue != 0)
  3088. return value.objectValue->invokeMethod (method, arguments, numArguments);
  3089. return var::null;
  3090. }
  3091. const var var::invoke (const var& targetObject, const var* arguments, int numArguments) const
  3092. {
  3093. if (isMethod())
  3094. {
  3095. DynamicObject* const target = targetObject.getObject();
  3096. if (target != 0)
  3097. return (target->*(value.methodValue)) (arguments, numArguments);
  3098. }
  3099. return var::null;
  3100. }
  3101. const var var::call (const var::identifier& method) const
  3102. {
  3103. return invoke (method, 0, 0);
  3104. }
  3105. const var var::call (const var::identifier& method, const var& arg1) const
  3106. {
  3107. return invoke (method, &arg1, 1);
  3108. }
  3109. const var var::call (const var::identifier& method, const var& arg1, const var& arg2) const
  3110. {
  3111. var args[] = { arg1, arg2 };
  3112. return invoke (method, args, 2);
  3113. }
  3114. const var var::call (const var::identifier& method, const var& arg1, const var& arg2, const var& arg3)
  3115. {
  3116. var args[] = { arg1, arg2, arg3 };
  3117. return invoke (method, args, 3);
  3118. }
  3119. const var var::call (const var::identifier& method, const var& arg1, const var& arg2, const var& arg3, const var& arg4) const
  3120. {
  3121. var args[] = { arg1, arg2, arg3, arg4 };
  3122. return invoke (method, args, 4);
  3123. }
  3124. const var var::call (const var::identifier& method, const var& arg1, const var& arg2, const var& arg3, const var& arg4, const var& arg5) const
  3125. {
  3126. var args[] = { arg1, arg2, arg3, arg4, arg5 };
  3127. return invoke (method, args, 5);
  3128. }
  3129. var::identifier::identifier() throw()
  3130. : hashCode (0)
  3131. {
  3132. }
  3133. var::identifier::identifier (const String& name_)
  3134. : name (name_),
  3135. hashCode (name_.hashCode())
  3136. {
  3137. /* An identifier string must be suitable for use as a script variable or XML
  3138. attribute, so it can only contain this limited set of characters.. */
  3139. jassert (name.containsOnly (T("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_")) && name.isNotEmpty());
  3140. }
  3141. var::identifier::identifier (const char* const name_)
  3142. : name (name_),
  3143. hashCode (name.hashCode())
  3144. {
  3145. /* An identifier string must be suitable for use as a script variable or XML
  3146. attribute, so it can only contain this limited set of characters.. */
  3147. jassert (name.containsOnly (T("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_")) && name.isNotEmpty());
  3148. }
  3149. var::identifier::~identifier()
  3150. {
  3151. }
  3152. END_JUCE_NAMESPACE
  3153. /*** End of inlined file: juce_Variant.cpp ***/
  3154. /*** Start of inlined file: juce_NamedValueSet.cpp ***/
  3155. BEGIN_JUCE_NAMESPACE
  3156. NamedValueSet::NamedValue::NamedValue() throw()
  3157. {
  3158. }
  3159. inline NamedValueSet::NamedValue::NamedValue (const var::identifier& name_, const var& value_)
  3160. : name (name_), value (value_)
  3161. {
  3162. }
  3163. NamedValueSet::NamedValueSet() throw()
  3164. {
  3165. }
  3166. NamedValueSet::NamedValueSet (const NamedValueSet& other)
  3167. : values (other.values)
  3168. {
  3169. }
  3170. NamedValueSet& NamedValueSet::operator= (const NamedValueSet& other)
  3171. {
  3172. values = other.values;
  3173. return *this;
  3174. }
  3175. NamedValueSet::~NamedValueSet()
  3176. {
  3177. }
  3178. int NamedValueSet::size() const throw()
  3179. {
  3180. return values.size();
  3181. }
  3182. const var& NamedValueSet::operator[] (const var::identifier& name) const
  3183. {
  3184. for (int i = values.size(); --i >= 0;)
  3185. {
  3186. const NamedValue& v = values.getReference(i);
  3187. if (v.name == name)
  3188. return v.value;
  3189. }
  3190. return var::null;
  3191. }
  3192. const var NamedValueSet::getWithDefault (const var::identifier& name, const var& defaultReturnValue) const
  3193. {
  3194. const var* v = getItem (name);
  3195. return v != 0 ? *v : defaultReturnValue;
  3196. }
  3197. var* NamedValueSet::getItem (const var::identifier& name) const
  3198. {
  3199. for (int i = values.size(); --i >= 0;)
  3200. {
  3201. NamedValue& v = values.getReference(i);
  3202. if (v.name == name)
  3203. return &(v.value);
  3204. }
  3205. return 0;
  3206. }
  3207. bool NamedValueSet::set (const var::identifier& name, const var& newValue)
  3208. {
  3209. for (int i = values.size(); --i >= 0;)
  3210. {
  3211. NamedValue& v = values.getReference(i);
  3212. if (v.name == name)
  3213. {
  3214. if (v.value == newValue)
  3215. return false;
  3216. v.value = newValue;
  3217. return true;
  3218. }
  3219. }
  3220. values.add (NamedValue (name, newValue));
  3221. return true;
  3222. }
  3223. bool NamedValueSet::contains (const var::identifier& name) const
  3224. {
  3225. return getItem (name) != 0;
  3226. }
  3227. bool NamedValueSet::remove (const var::identifier& name)
  3228. {
  3229. for (int i = values.size(); --i >= 0;)
  3230. {
  3231. if (values.getReference(i).name == name)
  3232. {
  3233. values.remove (i);
  3234. return true;
  3235. }
  3236. }
  3237. return false;
  3238. }
  3239. const var::identifier NamedValueSet::getName (int index) const
  3240. {
  3241. jassert (((unsigned int) index) < (unsigned int) values.size());
  3242. return values [index].name;
  3243. }
  3244. void NamedValueSet::clear()
  3245. {
  3246. values.clear();
  3247. }
  3248. END_JUCE_NAMESPACE
  3249. /*** End of inlined file: juce_NamedValueSet.cpp ***/
  3250. /*** Start of inlined file: juce_DynamicObject.cpp ***/
  3251. BEGIN_JUCE_NAMESPACE
  3252. DynamicObject::DynamicObject()
  3253. {
  3254. }
  3255. DynamicObject::~DynamicObject()
  3256. {
  3257. }
  3258. bool DynamicObject::hasProperty (const var::identifier& propertyName) const
  3259. {
  3260. var* const v = properties.getItem (propertyName);
  3261. return v != 0 && ! v->isMethod();
  3262. }
  3263. const var DynamicObject::getProperty (const var::identifier& propertyName) const
  3264. {
  3265. return properties [propertyName];
  3266. }
  3267. void DynamicObject::setProperty (const var::identifier& propertyName, const var& newValue)
  3268. {
  3269. properties.set (propertyName, newValue);
  3270. }
  3271. void DynamicObject::removeProperty (const var::identifier& propertyName)
  3272. {
  3273. properties.remove (propertyName);
  3274. }
  3275. bool DynamicObject::hasMethod (const var::identifier& methodName) const
  3276. {
  3277. return getProperty (methodName).isMethod();
  3278. }
  3279. const var DynamicObject::invokeMethod (const var::identifier& methodName,
  3280. const var* parameters,
  3281. int numParameters)
  3282. {
  3283. return properties [methodName].invoke (var (this), parameters, numParameters);
  3284. }
  3285. void DynamicObject::setMethod (const var::identifier& name,
  3286. var::MethodFunction methodFunction)
  3287. {
  3288. properties.set (name, var (methodFunction));
  3289. }
  3290. void DynamicObject::clear()
  3291. {
  3292. properties.clear();
  3293. }
  3294. END_JUCE_NAMESPACE
  3295. /*** End of inlined file: juce_DynamicObject.cpp ***/
  3296. /*** Start of inlined file: juce_BlowFish.cpp ***/
  3297. BEGIN_JUCE_NAMESPACE
  3298. BlowFish::BlowFish (const void* const keyData, const int keyBytes)
  3299. {
  3300. jassert (keyData != 0);
  3301. jassert (keyBytes > 0);
  3302. static const uint32 initialPValues [18] =
  3303. {
  3304. 0x243f6a88, 0x85a308d3, 0x13198a2e, 0x03707344, 0xa4093822, 0x299f31d0, 0x082efa98, 0xec4e6c89,
  3305. 0x452821e6, 0x38d01377, 0xbe5466cf, 0x34e90c6c, 0xc0ac29b7, 0xc97c50dd, 0x3f84d5b5, 0xb5470917,
  3306. 0x9216d5d9, 0x8979fb1b
  3307. };
  3308. static const uint32 initialSValues [4 * 256] =
  3309. {
  3310. 0xd1310ba6, 0x98dfb5ac, 0x2ffd72db, 0xd01adfb7, 0xb8e1afed, 0x6a267e96, 0xba7c9045, 0xf12c7f99,
  3311. 0x24a19947, 0xb3916cf7, 0x0801f2e2, 0x858efc16, 0x636920d8, 0x71574e69, 0xa458fea3, 0xf4933d7e,
  3312. 0x0d95748f, 0x728eb658, 0x718bcd58, 0x82154aee, 0x7b54a41d, 0xc25a59b5, 0x9c30d539, 0x2af26013,
  3313. 0xc5d1b023, 0x286085f0, 0xca417918, 0xb8db38ef, 0x8e79dcb0, 0x603a180e, 0x6c9e0e8b, 0xb01e8a3e,
  3314. 0xd71577c1, 0xbd314b27, 0x78af2fda, 0x55605c60, 0xe65525f3, 0xaa55ab94, 0x57489862, 0x63e81440,
  3315. 0x55ca396a, 0x2aab10b6, 0xb4cc5c34, 0x1141e8ce, 0xa15486af, 0x7c72e993, 0xb3ee1411, 0x636fbc2a,
  3316. 0x2ba9c55d, 0x741831f6, 0xce5c3e16, 0x9b87931e, 0xafd6ba33, 0x6c24cf5c, 0x7a325381, 0x28958677,
  3317. 0x3b8f4898, 0x6b4bb9af, 0xc4bfe81b, 0x66282193, 0x61d809cc, 0xfb21a991, 0x487cac60, 0x5dec8032,
  3318. 0xef845d5d, 0xe98575b1, 0xdc262302, 0xeb651b88, 0x23893e81, 0xd396acc5, 0x0f6d6ff3, 0x83f44239,
  3319. 0x2e0b4482, 0xa4842004, 0x69c8f04a, 0x9e1f9b5e, 0x21c66842, 0xf6e96c9a, 0x670c9c61, 0xabd388f0,
  3320. 0x6a51a0d2, 0xd8542f68, 0x960fa728, 0xab5133a3, 0x6eef0b6c, 0x137a3be4, 0xba3bf050, 0x7efb2a98,
  3321. 0xa1f1651d, 0x39af0176, 0x66ca593e, 0x82430e88, 0x8cee8619, 0x456f9fb4, 0x7d84a5c3, 0x3b8b5ebe,
  3322. 0xe06f75d8, 0x85c12073, 0x401a449f, 0x56c16aa6, 0x4ed3aa62, 0x363f7706, 0x1bfedf72, 0x429b023d,
  3323. 0x37d0d724, 0xd00a1248, 0xdb0fead3, 0x49f1c09b, 0x075372c9, 0x80991b7b, 0x25d479d8, 0xf6e8def7,
  3324. 0xe3fe501a, 0xb6794c3b, 0x976ce0bd, 0x04c006ba, 0xc1a94fb6, 0x409f60c4, 0x5e5c9ec2, 0x196a2463,
  3325. 0x68fb6faf, 0x3e6c53b5, 0x1339b2eb, 0x3b52ec6f, 0x6dfc511f, 0x9b30952c, 0xcc814544, 0xaf5ebd09,
  3326. 0xbee3d004, 0xde334afd, 0x660f2807, 0x192e4bb3, 0xc0cba857, 0x45c8740f, 0xd20b5f39, 0xb9d3fbdb,
  3327. 0x5579c0bd, 0x1a60320a, 0xd6a100c6, 0x402c7279, 0x679f25fe, 0xfb1fa3cc, 0x8ea5e9f8, 0xdb3222f8,
  3328. 0x3c7516df, 0xfd616b15, 0x2f501ec8, 0xad0552ab, 0x323db5fa, 0xfd238760, 0x53317b48, 0x3e00df82,
  3329. 0x9e5c57bb, 0xca6f8ca0, 0x1a87562e, 0xdf1769db, 0xd542a8f6, 0x287effc3, 0xac6732c6, 0x8c4f5573,
  3330. 0x695b27b0, 0xbbca58c8, 0xe1ffa35d, 0xb8f011a0, 0x10fa3d98, 0xfd2183b8, 0x4afcb56c, 0x2dd1d35b,
  3331. 0x9a53e479, 0xb6f84565, 0xd28e49bc, 0x4bfb9790, 0xe1ddf2da, 0xa4cb7e33, 0x62fb1341, 0xcee4c6e8,
  3332. 0xef20cada, 0x36774c01, 0xd07e9efe, 0x2bf11fb4, 0x95dbda4d, 0xae909198, 0xeaad8e71, 0x6b93d5a0,
  3333. 0xd08ed1d0, 0xafc725e0, 0x8e3c5b2f, 0x8e7594b7, 0x8ff6e2fb, 0xf2122b64, 0x8888b812, 0x900df01c,
  3334. 0x4fad5ea0, 0x688fc31c, 0xd1cff191, 0xb3a8c1ad, 0x2f2f2218, 0xbe0e1777, 0xea752dfe, 0x8b021fa1,
  3335. 0xe5a0cc0f, 0xb56f74e8, 0x18acf3d6, 0xce89e299, 0xb4a84fe0, 0xfd13e0b7, 0x7cc43b81, 0xd2ada8d9,
  3336. 0x165fa266, 0x80957705, 0x93cc7314, 0x211a1477, 0xe6ad2065, 0x77b5fa86, 0xc75442f5, 0xfb9d35cf,
  3337. 0xebcdaf0c, 0x7b3e89a0, 0xd6411bd3, 0xae1e7e49, 0x00250e2d, 0x2071b35e, 0x226800bb, 0x57b8e0af,
  3338. 0x2464369b, 0xf009b91e, 0x5563911d, 0x59dfa6aa, 0x78c14389, 0xd95a537f, 0x207d5ba2, 0x02e5b9c5,
  3339. 0x83260376, 0x6295cfa9, 0x11c81968, 0x4e734a41, 0xb3472dca, 0x7b14a94a, 0x1b510052, 0x9a532915,
  3340. 0xd60f573f, 0xbc9bc6e4, 0x2b60a476, 0x81e67400, 0x08ba6fb5, 0x571be91f, 0xf296ec6b, 0x2a0dd915,
  3341. 0xb6636521, 0xe7b9f9b6, 0xff34052e, 0xc5855664, 0x53b02d5d, 0xa99f8fa1, 0x08ba4799, 0x6e85076a,
  3342. 0x4b7a70e9, 0xb5b32944, 0xdb75092e, 0xc4192623, 0xad6ea6b0, 0x49a7df7d, 0x9cee60b8, 0x8fedb266,
  3343. 0xecaa8c71, 0x699a17ff, 0x5664526c, 0xc2b19ee1, 0x193602a5, 0x75094c29, 0xa0591340, 0xe4183a3e,
  3344. 0x3f54989a, 0x5b429d65, 0x6b8fe4d6, 0x99f73fd6, 0xa1d29c07, 0xefe830f5, 0x4d2d38e6, 0xf0255dc1,
  3345. 0x4cdd2086, 0x8470eb26, 0x6382e9c6, 0x021ecc5e, 0x09686b3f, 0x3ebaefc9, 0x3c971814, 0x6b6a70a1,
  3346. 0x687f3584, 0x52a0e286, 0xb79c5305, 0xaa500737, 0x3e07841c, 0x7fdeae5c, 0x8e7d44ec, 0x5716f2b8,
  3347. 0xb03ada37, 0xf0500c0d, 0xf01c1f04, 0x0200b3ff, 0xae0cf51a, 0x3cb574b2, 0x25837a58, 0xdc0921bd,
  3348. 0xd19113f9, 0x7ca92ff6, 0x94324773, 0x22f54701, 0x3ae5e581, 0x37c2dadc, 0xc8b57634, 0x9af3dda7,
  3349. 0xa9446146, 0x0fd0030e, 0xecc8c73e, 0xa4751e41, 0xe238cd99, 0x3bea0e2f, 0x3280bba1, 0x183eb331,
  3350. 0x4e548b38, 0x4f6db908, 0x6f420d03, 0xf60a04bf, 0x2cb81290, 0x24977c79, 0x5679b072, 0xbcaf89af,
  3351. 0xde9a771f, 0xd9930810, 0xb38bae12, 0xdccf3f2e, 0x5512721f, 0x2e6b7124, 0x501adde6, 0x9f84cd87,
  3352. 0x7a584718, 0x7408da17, 0xbc9f9abc, 0xe94b7d8c, 0xec7aec3a, 0xdb851dfa, 0x63094366, 0xc464c3d2,
  3353. 0xef1c1847, 0x3215d908, 0xdd433b37, 0x24c2ba16, 0x12a14d43, 0x2a65c451, 0x50940002, 0x133ae4dd,
  3354. 0x71dff89e, 0x10314e55, 0x81ac77d6, 0x5f11199b, 0x043556f1, 0xd7a3c76b, 0x3c11183b, 0x5924a509,
  3355. 0xf28fe6ed, 0x97f1fbfa, 0x9ebabf2c, 0x1e153c6e, 0x86e34570, 0xeae96fb1, 0x860e5e0a, 0x5a3e2ab3,
  3356. 0x771fe71c, 0x4e3d06fa, 0x2965dcb9, 0x99e71d0f, 0x803e89d6, 0x5266c825, 0x2e4cc978, 0x9c10b36a,
  3357. 0xc6150eba, 0x94e2ea78, 0xa5fc3c53, 0x1e0a2df4, 0xf2f74ea7, 0x361d2b3d, 0x1939260f, 0x19c27960,
  3358. 0x5223a708, 0xf71312b6, 0xebadfe6e, 0xeac31f66, 0xe3bc4595, 0xa67bc883, 0xb17f37d1, 0x018cff28,
  3359. 0xc332ddef, 0xbe6c5aa5, 0x65582185, 0x68ab9802, 0xeecea50f, 0xdb2f953b, 0x2aef7dad, 0x5b6e2f84,
  3360. 0x1521b628, 0x29076170, 0xecdd4775, 0x619f1510, 0x13cca830, 0xeb61bd96, 0x0334fe1e, 0xaa0363cf,
  3361. 0xb5735c90, 0x4c70a239, 0xd59e9e0b, 0xcbaade14, 0xeecc86bc, 0x60622ca7, 0x9cab5cab, 0xb2f3846e,
  3362. 0x648b1eaf, 0x19bdf0ca, 0xa02369b9, 0x655abb50, 0x40685a32, 0x3c2ab4b3, 0x319ee9d5, 0xc021b8f7,
  3363. 0x9b540b19, 0x875fa099, 0x95f7997e, 0x623d7da8, 0xf837889a, 0x97e32d77, 0x11ed935f, 0x16681281,
  3364. 0x0e358829, 0xc7e61fd6, 0x96dedfa1, 0x7858ba99, 0x57f584a5, 0x1b227263, 0x9b83c3ff, 0x1ac24696,
  3365. 0xcdb30aeb, 0x532e3054, 0x8fd948e4, 0x6dbc3128, 0x58ebf2ef, 0x34c6ffea, 0xfe28ed61, 0xee7c3c73,
  3366. 0x5d4a14d9, 0xe864b7e3, 0x42105d14, 0x203e13e0, 0x45eee2b6, 0xa3aaabea, 0xdb6c4f15, 0xfacb4fd0,
  3367. 0xc742f442, 0xef6abbb5, 0x654f3b1d, 0x41cd2105, 0xd81e799e, 0x86854dc7, 0xe44b476a, 0x3d816250,
  3368. 0xcf62a1f2, 0x5b8d2646, 0xfc8883a0, 0xc1c7b6a3, 0x7f1524c3, 0x69cb7492, 0x47848a0b, 0x5692b285,
  3369. 0x095bbf00, 0xad19489d, 0x1462b174, 0x23820e00, 0x58428d2a, 0x0c55f5ea, 0x1dadf43e, 0x233f7061,
  3370. 0x3372f092, 0x8d937e41, 0xd65fecf1, 0x6c223bdb, 0x7cde3759, 0xcbee7460, 0x4085f2a7, 0xce77326e,
  3371. 0xa6078084, 0x19f8509e, 0xe8efd855, 0x61d99735, 0xa969a7aa, 0xc50c06c2, 0x5a04abfc, 0x800bcadc,
  3372. 0x9e447a2e, 0xc3453484, 0xfdd56705, 0x0e1e9ec9, 0xdb73dbd3, 0x105588cd, 0x675fda79, 0xe3674340,
  3373. 0xc5c43465, 0x713e38d8, 0x3d28f89e, 0xf16dff20, 0x153e21e7, 0x8fb03d4a, 0xe6e39f2b, 0xdb83adf7,
  3374. 0xe93d5a68, 0x948140f7, 0xf64c261c, 0x94692934, 0x411520f7, 0x7602d4f7, 0xbcf46b2e, 0xd4a20068,
  3375. 0xd4082471, 0x3320f46a, 0x43b7d4b7, 0x500061af, 0x1e39f62e, 0x97244546, 0x14214f74, 0xbf8b8840,
  3376. 0x4d95fc1d, 0x96b591af, 0x70f4ddd3, 0x66a02f45, 0xbfbc09ec, 0x03bd9785, 0x7fac6dd0, 0x31cb8504,
  3377. 0x96eb27b3, 0x55fd3941, 0xda2547e6, 0xabca0a9a, 0x28507825, 0x530429f4, 0x0a2c86da, 0xe9b66dfb,
  3378. 0x68dc1462, 0xd7486900, 0x680ec0a4, 0x27a18dee, 0x4f3ffea2, 0xe887ad8c, 0xb58ce006, 0x7af4d6b6,
  3379. 0xaace1e7c, 0xd3375fec, 0xce78a399, 0x406b2a42, 0x20fe9e35, 0xd9f385b9, 0xee39d7ab, 0x3b124e8b,
  3380. 0x1dc9faf7, 0x4b6d1856, 0x26a36631, 0xeae397b2, 0x3a6efa74, 0xdd5b4332, 0x6841e7f7, 0xca7820fb,
  3381. 0xfb0af54e, 0xd8feb397, 0x454056ac, 0xba489527, 0x55533a3a, 0x20838d87, 0xfe6ba9b7, 0xd096954b,
  3382. 0x55a867bc, 0xa1159a58, 0xcca92963, 0x99e1db33, 0xa62a4a56, 0x3f3125f9, 0x5ef47e1c, 0x9029317c,
  3383. 0xfdf8e802, 0x04272f70, 0x80bb155c, 0x05282ce3, 0x95c11548, 0xe4c66d22, 0x48c1133f, 0xc70f86dc,
  3384. 0x07f9c9ee, 0x41041f0f, 0x404779a4, 0x5d886e17, 0x325f51eb, 0xd59bc0d1, 0xf2bcc18f, 0x41113564,
  3385. 0x257b7834, 0x602a9c60, 0xdff8e8a3, 0x1f636c1b, 0x0e12b4c2, 0x02e1329e, 0xaf664fd1, 0xcad18115,
  3386. 0x6b2395e0, 0x333e92e1, 0x3b240b62, 0xeebeb922, 0x85b2a20e, 0xe6ba0d99, 0xde720c8c, 0x2da2f728,
  3387. 0xd0127845, 0x95b794fd, 0x647d0862, 0xe7ccf5f0, 0x5449a36f, 0x877d48fa, 0xc39dfd27, 0xf33e8d1e,
  3388. 0x0a476341, 0x992eff74, 0x3a6f6eab, 0xf4f8fd37, 0xa812dc60, 0xa1ebddf8, 0x991be14c, 0xdb6e6b0d,
  3389. 0xc67b5510, 0x6d672c37, 0x2765d43b, 0xdcd0e804, 0xf1290dc7, 0xcc00ffa3, 0xb5390f92, 0x690fed0b,
  3390. 0x667b9ffb, 0xcedb7d9c, 0xa091cf0b, 0xd9155ea3, 0xbb132f88, 0x515bad24, 0x7b9479bf, 0x763bd6eb,
  3391. 0x37392eb3, 0xcc115979, 0x8026e297, 0xf42e312d, 0x6842ada7, 0xc66a2b3b, 0x12754ccc, 0x782ef11c,
  3392. 0x6a124237, 0xb79251e7, 0x06a1bbe6, 0x4bfb6350, 0x1a6b1018, 0x11caedfa, 0x3d25bdd8, 0xe2e1c3c9,
  3393. 0x44421659, 0x0a121386, 0xd90cec6e, 0xd5abea2a, 0x64af674e, 0xda86a85f, 0xbebfe988, 0x64e4c3fe,
  3394. 0x9dbc8057, 0xf0f7c086, 0x60787bf8, 0x6003604d, 0xd1fd8346, 0xf6381fb0, 0x7745ae04, 0xd736fccc,
  3395. 0x83426b33, 0xf01eab71, 0xb0804187, 0x3c005e5f, 0x77a057be, 0xbde8ae24, 0x55464299, 0xbf582e61,
  3396. 0x4e58f48f, 0xf2ddfda2, 0xf474ef38, 0x8789bdc2, 0x5366f9c3, 0xc8b38e74, 0xb475f255, 0x46fcd9b9,
  3397. 0x7aeb2661, 0x8b1ddf84, 0x846a0e79, 0x915f95e2, 0x466e598e, 0x20b45770, 0x8cd55591, 0xc902de4c,
  3398. 0xb90bace1, 0xbb8205d0, 0x11a86248, 0x7574a99e, 0xb77f19b6, 0xe0a9dc09, 0x662d09a1, 0xc4324633,
  3399. 0xe85a1f02, 0x09f0be8c, 0x4a99a025, 0x1d6efe10, 0x1ab93d1d, 0x0ba5a4df, 0xa186f20f, 0x2868f169,
  3400. 0xdcb7da83, 0x573906fe, 0xa1e2ce9b, 0x4fcd7f52, 0x50115e01, 0xa70683fa, 0xa002b5c4, 0x0de6d027,
  3401. 0x9af88c27, 0x773f8641, 0xc3604c06, 0x61a806b5, 0xf0177a28, 0xc0f586e0, 0x006058aa, 0x30dc7d62,
  3402. 0x11e69ed7, 0x2338ea63, 0x53c2dd94, 0xc2c21634, 0xbbcbee56, 0x90bcb6de, 0xebfc7da1, 0xce591d76,
  3403. 0x6f05e409, 0x4b7c0188, 0x39720a3d, 0x7c927c24, 0x86e3725f, 0x724d9db9, 0x1ac15bb4, 0xd39eb8fc,
  3404. 0xed545578, 0x08fca5b5, 0xd83d7cd3, 0x4dad0fc4, 0x1e50ef5e, 0xb161e6f8, 0xa28514d9, 0x6c51133c,
  3405. 0x6fd5c7e7, 0x56e14ec4, 0x362abfce, 0xddc6c837, 0xd79a3234, 0x92638212, 0x670efa8e, 0x406000e0,
  3406. 0x3a39ce37, 0xd3faf5cf, 0xabc27737, 0x5ac52d1b, 0x5cb0679e, 0x4fa33742, 0xd3822740, 0x99bc9bbe,
  3407. 0xd5118e9d, 0xbf0f7315, 0xd62d1c7e, 0xc700c47b, 0xb78c1b6b, 0x21a19045, 0xb26eb1be, 0x6a366eb4,
  3408. 0x5748ab2f, 0xbc946e79, 0xc6a376d2, 0x6549c2c8, 0x530ff8ee, 0x468dde7d, 0xd5730a1d, 0x4cd04dc6,
  3409. 0x2939bbdb, 0xa9ba4650, 0xac9526e8, 0xbe5ee304, 0xa1fad5f0, 0x6a2d519a, 0x63ef8ce2, 0x9a86ee22,
  3410. 0xc089c2b8, 0x43242ef6, 0xa51e03aa, 0x9cf2d0a4, 0x83c061ba, 0x9be96a4d, 0x8fe51550, 0xba645bd6,
  3411. 0x2826a2f9, 0xa73a3ae1, 0x4ba99586, 0xef5562e9, 0xc72fefd3, 0xf752f7da, 0x3f046f69, 0x77fa0a59,
  3412. 0x80e4a915, 0x87b08601, 0x9b09e6ad, 0x3b3ee593, 0xe990fd5a, 0x9e34d797, 0x2cf0b7d9, 0x022b8b51,
  3413. 0x96d5ac3a, 0x017da67d, 0xd1cf3ed6, 0x7c7d2d28, 0x1f9f25cf, 0xadf2b89b, 0x5ad6b472, 0x5a88f54c,
  3414. 0xe029ac71, 0xe019a5e6, 0x47b0acfd, 0xed93fa9b, 0xe8d3c48d, 0x283b57cc, 0xf8d56629, 0x79132e28,
  3415. 0x785f0191, 0xed756055, 0xf7960e44, 0xe3d35e8c, 0x15056dd4, 0x88f46dba, 0x03a16125, 0x0564f0bd,
  3416. 0xc3eb9e15, 0x3c9057a2, 0x97271aec, 0xa93a072a, 0x1b3f6d9b, 0x1e6321f5, 0xf59c66fb, 0x26dcf319,
  3417. 0x7533d928, 0xb155fdf5, 0x03563482, 0x8aba3cbb, 0x28517711, 0xc20ad9f8, 0xabcc5167, 0xccad925f,
  3418. 0x4de81751, 0x3830dc8e, 0x379d5862, 0x9320f991, 0xea7a90c2, 0xfb3e7bce, 0x5121ce64, 0x774fbe32,
  3419. 0xa8b6e37e, 0xc3293d46, 0x48de5369, 0x6413e680, 0xa2ae0810, 0xdd6db224, 0x69852dfd, 0x09072166,
  3420. 0xb39a460a, 0x6445c0dd, 0x586cdecf, 0x1c20c8ae, 0x5bbef7dd, 0x1b588d40, 0xccd2017f, 0x6bb4e3bb,
  3421. 0xdda26a7e, 0x3a59ff45, 0x3e350a44, 0xbcb4cdd5, 0x72eacea8, 0xfa6484bb, 0x8d6612ae, 0xbf3c6f47,
  3422. 0xd29be463, 0x542f5d9e, 0xaec2771b, 0xf64e6370, 0x740e0d8d, 0xe75b1357, 0xf8721671, 0xaf537d5d,
  3423. 0x4040cb08, 0x4eb4e2cc, 0x34d2466a, 0x0115af84, 0xe1b00428, 0x95983a1d, 0x06b89fb4, 0xce6ea048,
  3424. 0x6f3f3b82, 0x3520ab82, 0x011a1d4b, 0x277227f8, 0x611560b1, 0xe7933fdc, 0xbb3a792b, 0x344525bd,
  3425. 0xa08839e1, 0x51ce794b, 0x2f32c9b7, 0xa01fbac9, 0xe01cc87e, 0xbcc7d1f6, 0xcf0111c3, 0xa1e8aac7,
  3426. 0x1a908749, 0xd44fbd9a, 0xd0dadecb, 0xd50ada38, 0x0339c32a, 0xc6913667, 0x8df9317c, 0xe0b12b4f,
  3427. 0xf79e59b7, 0x43f5bb3a, 0xf2d519ff, 0x27d9459c, 0xbf97222c, 0x15e6fc2a, 0x0f91fc71, 0x9b941525,
  3428. 0xfae59361, 0xceb69ceb, 0xc2a86459, 0x12baa8d1, 0xb6c1075e, 0xe3056a0c, 0x10d25065, 0xcb03a442,
  3429. 0xe0ec6e0e, 0x1698db3b, 0x4c98a0be, 0x3278e964, 0x9f1f9532, 0xe0d392df, 0xd3a0342b, 0x8971f21e,
  3430. 0x1b0a7441, 0x4ba3348c, 0xc5be7120, 0xc37632d8, 0xdf359f8d, 0x9b992f2e, 0xe60b6f47, 0x0fe3f11d,
  3431. 0xe54cda54, 0x1edad891, 0xce6279cf, 0xcd3e7e6f, 0x1618b166, 0xfd2c1d05, 0x848fd2c5, 0xf6fb2299,
  3432. 0xf523f357, 0xa6327623, 0x93a83531, 0x56cccd02, 0xacf08162, 0x5a75ebb5, 0x6e163697, 0x88d273cc,
  3433. 0xde966292, 0x81b949d0, 0x4c50901b, 0x71c65614, 0xe6c6c7bd, 0x327a140a, 0x45e1d006, 0xc3f27b9a,
  3434. 0xc9aa53fd, 0x62a80f00, 0xbb25bfe2, 0x35bdd2f6, 0x71126905, 0xb2040222, 0xb6cbcf7c, 0xcd769c2b,
  3435. 0x53113ec0, 0x1640e3d3, 0x38abbd60, 0x2547adf0, 0xba38209c, 0xf746ce76, 0x77afa1c5, 0x20756060,
  3436. 0x85cbfe4e, 0x8ae88dd8, 0x7aaaf9b0, 0x4cf9aa7e, 0x1948c25c, 0x02fb8a8c, 0x01c36ae4, 0xd6ebe1f9,
  3437. 0x90d4f869, 0xa65cdea0, 0x3f09252d, 0xc208e69f, 0xb74e6132, 0xce77e25b, 0x578fdfe3, 0x3ac372e6
  3438. };
  3439. memcpy (p, initialPValues, sizeof (p));
  3440. int i, j = 0;
  3441. for (i = 4; --i >= 0;)
  3442. {
  3443. s[i].malloc (256);
  3444. memcpy (s[i], initialSValues + i * 256, 256 * sizeof (uint32));
  3445. }
  3446. for (i = 0; i < 18; ++i)
  3447. {
  3448. uint32 d = 0;
  3449. for (int k = 0; k < 4; ++k)
  3450. {
  3451. d = (d << 8) | static_cast <const uint8*> (keyData)[j];
  3452. if (++j >= keyBytes)
  3453. j = 0;
  3454. }
  3455. p[i] = initialPValues[i] ^ d;
  3456. }
  3457. uint32 l = 0, r = 0;
  3458. for (i = 0; i < 18; i += 2)
  3459. {
  3460. encrypt (l, r);
  3461. p[i] = l;
  3462. p[i + 1] = r;
  3463. }
  3464. for (i = 0; i < 4; ++i)
  3465. {
  3466. for (j = 0; j < 256; j += 2)
  3467. {
  3468. encrypt (l, r);
  3469. s[i][j] = l;
  3470. s[i][j + 1] = r;
  3471. }
  3472. }
  3473. }
  3474. BlowFish::BlowFish (const BlowFish& other)
  3475. {
  3476. for (int i = 4; --i >= 0;)
  3477. s[i].malloc (256);
  3478. operator= (other);
  3479. }
  3480. BlowFish& BlowFish::operator= (const BlowFish& other)
  3481. {
  3482. memcpy (p, other.p, sizeof (p));
  3483. for (int i = 4; --i >= 0;)
  3484. memcpy (s[i], other.s[i], 256 * sizeof (uint32));
  3485. return *this;
  3486. }
  3487. BlowFish::~BlowFish()
  3488. {
  3489. }
  3490. uint32 BlowFish::F (const uint32 x) const throw()
  3491. {
  3492. return ((s[0][(x >> 24) & 0xff] + s[1][(x >> 16) & 0xff])
  3493. ^ s[2][(x >> 8) & 0xff]) + s[3][x & 0xff];
  3494. }
  3495. void BlowFish::encrypt (uint32& data1, uint32& data2) const throw()
  3496. {
  3497. uint32 l = data1;
  3498. uint32 r = data2;
  3499. for (int i = 0; i < 16; ++i)
  3500. {
  3501. l ^= p[i];
  3502. r ^= F(l);
  3503. swapVariables (l, r);
  3504. }
  3505. data1 = r ^ p[17];
  3506. data2 = l ^ p[16];
  3507. }
  3508. void BlowFish::decrypt (uint32& data1, uint32& data2) const throw()
  3509. {
  3510. uint32 l = data1;
  3511. uint32 r = data2;
  3512. for (int i = 17; i > 1; --i)
  3513. {
  3514. l ^= p[i];
  3515. r ^= F(l);
  3516. swapVariables (l, r);
  3517. }
  3518. data1 = r ^ p[0];
  3519. data2 = l ^ p[1];
  3520. }
  3521. END_JUCE_NAMESPACE
  3522. /*** End of inlined file: juce_BlowFish.cpp ***/
  3523. /*** Start of inlined file: juce_MD5.cpp ***/
  3524. BEGIN_JUCE_NAMESPACE
  3525. MD5::MD5()
  3526. {
  3527. zerostruct (result);
  3528. }
  3529. MD5::MD5 (const MD5& other)
  3530. {
  3531. memcpy (result, other.result, sizeof (result));
  3532. }
  3533. MD5& MD5::operator= (const MD5& other)
  3534. {
  3535. memcpy (result, other.result, sizeof (result));
  3536. return *this;
  3537. }
  3538. MD5::MD5 (const MemoryBlock& data)
  3539. {
  3540. ProcessContext context;
  3541. context.processBlock ((const uint8*) data.getData(), data.getSize());
  3542. context.finish (result);
  3543. }
  3544. MD5::MD5 (const char* data, const size_t numBytes)
  3545. {
  3546. ProcessContext context;
  3547. context.processBlock ((const uint8*) data, numBytes);
  3548. context.finish (result);
  3549. }
  3550. MD5::MD5 (const String& text)
  3551. {
  3552. ProcessContext context;
  3553. const int len = text.length();
  3554. const juce_wchar* const t = text;
  3555. for (int i = 0; i < len; ++i)
  3556. {
  3557. // force the string into integer-sized unicode characters, to try to make it
  3558. // get the same results on all platforms + compilers.
  3559. uint32 unicodeChar = (uint32) t[i];
  3560. ByteOrder::swapIfBigEndian (unicodeChar);
  3561. context.processBlock ((const uint8*) &unicodeChar,
  3562. sizeof (unicodeChar));
  3563. }
  3564. context.finish (result);
  3565. }
  3566. void MD5::processStream (InputStream& input, int64 numBytesToRead)
  3567. {
  3568. ProcessContext context;
  3569. if (numBytesToRead < 0)
  3570. numBytesToRead = std::numeric_limits<int64>::max();
  3571. while (numBytesToRead > 0)
  3572. {
  3573. char tempBuffer [512];
  3574. const int bytesRead = input.read (tempBuffer, (int) jmin (numBytesToRead, (int64) sizeof (tempBuffer)));
  3575. if (bytesRead <= 0)
  3576. break;
  3577. numBytesToRead -= bytesRead;
  3578. context.processBlock ((const uint8*) tempBuffer, bytesRead);
  3579. }
  3580. context.finish (result);
  3581. }
  3582. MD5::MD5 (InputStream& input, int64 numBytesToRead)
  3583. {
  3584. processStream (input, numBytesToRead);
  3585. }
  3586. MD5::MD5 (const File& file)
  3587. {
  3588. const ScopedPointer <FileInputStream> fin (file.createInputStream());
  3589. if (fin != 0)
  3590. processStream (*fin, -1);
  3591. else
  3592. zerostruct (result);
  3593. }
  3594. MD5::~MD5()
  3595. {
  3596. }
  3597. namespace MD5Functions
  3598. {
  3599. static void encode (uint8* const output, const uint32* const input, const int numBytes) throw()
  3600. {
  3601. uint32* const o = (uint32*) output;
  3602. for (int i = 0; i < (numBytes >> 2); ++i)
  3603. o[i] = ByteOrder::swapIfBigEndian (input [i]);
  3604. }
  3605. static void decode (uint32* const output, const uint8* const input, const int numBytes) throw()
  3606. {
  3607. for (int i = 0; i < (numBytes >> 2); ++i)
  3608. output[i] = ByteOrder::littleEndianInt ((const char*) input + (i << 2));
  3609. }
  3610. static inline uint32 F (const uint32 x, const uint32 y, const uint32 z) throw() { return (x & y) | (~x & z); }
  3611. static inline uint32 G (const uint32 x, const uint32 y, const uint32 z) throw() { return (x & z) | (y & ~z); }
  3612. static inline uint32 H (const uint32 x, const uint32 y, const uint32 z) throw() { return x ^ y ^ z; }
  3613. static inline uint32 I (const uint32 x, const uint32 y, const uint32 z) throw() { return y ^ (x | ~z); }
  3614. static inline uint32 rotateLeft (const uint32 x, const uint32 n) throw() { return (x << n) | (x >> (32 - n)); }
  3615. static void FF (uint32& a, const uint32 b, const uint32 c, const uint32 d, const uint32 x, const uint32 s, const uint32 ac) throw()
  3616. {
  3617. a += F (b, c, d) + x + ac;
  3618. a = rotateLeft (a, s) + b;
  3619. }
  3620. static void GG (uint32& a, const uint32 b, const uint32 c, const uint32 d, const uint32 x, const uint32 s, const uint32 ac) throw()
  3621. {
  3622. a += G (b, c, d) + x + ac;
  3623. a = rotateLeft (a, s) + b;
  3624. }
  3625. static void HH (uint32& a, const uint32 b, const uint32 c, const uint32 d, const uint32 x, const uint32 s, const uint32 ac) throw()
  3626. {
  3627. a += H (b, c, d) + x + ac;
  3628. a = rotateLeft (a, s) + b;
  3629. }
  3630. static void II (uint32& a, const uint32 b, const uint32 c, const uint32 d, const uint32 x, const uint32 s, const uint32 ac) throw()
  3631. {
  3632. a += I (b, c, d) + x + ac;
  3633. a = rotateLeft (a, s) + b;
  3634. }
  3635. }
  3636. MD5::ProcessContext::ProcessContext()
  3637. {
  3638. state[0] = 0x67452301;
  3639. state[1] = 0xefcdab89;
  3640. state[2] = 0x98badcfe;
  3641. state[3] = 0x10325476;
  3642. count[0] = 0;
  3643. count[1] = 0;
  3644. }
  3645. void MD5::ProcessContext::processBlock (const uint8* const data, size_t dataSize)
  3646. {
  3647. int bufferPos = ((count[0] >> 3) & 0x3F);
  3648. count[0] += (uint32) (dataSize << 3);
  3649. if (count[0] < ((uint32) dataSize << 3))
  3650. count[1]++;
  3651. count[1] += (uint32) (dataSize >> 29);
  3652. const size_t spaceLeft = 64 - bufferPos;
  3653. size_t i = 0;
  3654. if (dataSize >= spaceLeft)
  3655. {
  3656. memcpy (buffer + bufferPos, data, spaceLeft);
  3657. transform (buffer);
  3658. i = spaceLeft;
  3659. while (i + 64 <= dataSize)
  3660. {
  3661. transform (data + i);
  3662. i += 64;
  3663. }
  3664. bufferPos = 0;
  3665. }
  3666. memcpy (buffer + bufferPos, data + i, dataSize - i);
  3667. }
  3668. void MD5::ProcessContext::finish (uint8* const result)
  3669. {
  3670. unsigned char encodedLength[8];
  3671. MD5Functions::encode (encodedLength, count, 8);
  3672. // Pad out to 56 mod 64.
  3673. const int index = (uint32) ((count[0] >> 3) & 0x3f);
  3674. const int paddingLength = (index < 56) ? (56 - index)
  3675. : (120 - index);
  3676. uint8 paddingBuffer [64];
  3677. zeromem (paddingBuffer, paddingLength);
  3678. paddingBuffer [0] = 0x80;
  3679. processBlock (paddingBuffer, paddingLength);
  3680. processBlock (encodedLength, 8);
  3681. MD5Functions::encode (result, state, 16);
  3682. zerostruct (buffer);
  3683. }
  3684. void MD5::ProcessContext::transform (const uint8* const bufferToTransform)
  3685. {
  3686. using namespace MD5Functions;
  3687. uint32 a = state[0];
  3688. uint32 b = state[1];
  3689. uint32 c = state[2];
  3690. uint32 d = state[3];
  3691. uint32 x[16];
  3692. decode (x, bufferToTransform, 64);
  3693. enum Constants
  3694. {
  3695. S11 = 7, S12 = 12, S13 = 17, S14 = 22, S21 = 5, S22 = 9, S23 = 14, S24 = 20,
  3696. S31 = 4, S32 = 11, S33 = 16, S34 = 23, S41 = 6, S42 = 10, S43 = 15, S44 = 21
  3697. };
  3698. FF (a, b, c, d, x[ 0], S11, 0xd76aa478); /* 1 */
  3699. FF (d, a, b, c, x[ 1], S12, 0xe8c7b756); /* 2 */
  3700. FF (c, d, a, b, x[ 2], S13, 0x242070db); /* 3 */
  3701. FF (b, c, d, a, x[ 3], S14, 0xc1bdceee); /* 4 */
  3702. FF (a, b, c, d, x[ 4], S11, 0xf57c0faf); /* 5 */
  3703. FF (d, a, b, c, x[ 5], S12, 0x4787c62a); /* 6 */
  3704. FF (c, d, a, b, x[ 6], S13, 0xa8304613); /* 7 */
  3705. FF (b, c, d, a, x[ 7], S14, 0xfd469501); /* 8 */
  3706. FF (a, b, c, d, x[ 8], S11, 0x698098d8); /* 9 */
  3707. FF (d, a, b, c, x[ 9], S12, 0x8b44f7af); /* 10 */
  3708. FF (c, d, a, b, x[10], S13, 0xffff5bb1); /* 11 */
  3709. FF (b, c, d, a, x[11], S14, 0x895cd7be); /* 12 */
  3710. FF (a, b, c, d, x[12], S11, 0x6b901122); /* 13 */
  3711. FF (d, a, b, c, x[13], S12, 0xfd987193); /* 14 */
  3712. FF (c, d, a, b, x[14], S13, 0xa679438e); /* 15 */
  3713. FF (b, c, d, a, x[15], S14, 0x49b40821); /* 16 */
  3714. GG (a, b, c, d, x[ 1], S21, 0xf61e2562); /* 17 */
  3715. GG (d, a, b, c, x[ 6], S22, 0xc040b340); /* 18 */
  3716. GG (c, d, a, b, x[11], S23, 0x265e5a51); /* 19 */
  3717. GG (b, c, d, a, x[ 0], S24, 0xe9b6c7aa); /* 20 */
  3718. GG (a, b, c, d, x[ 5], S21, 0xd62f105d); /* 21 */
  3719. GG (d, a, b, c, x[10], S22, 0x2441453); /* 22 */
  3720. GG (c, d, a, b, x[15], S23, 0xd8a1e681); /* 23 */
  3721. GG (b, c, d, a, x[ 4], S24, 0xe7d3fbc8); /* 24 */
  3722. GG (a, b, c, d, x[ 9], S21, 0x21e1cde6); /* 25 */
  3723. GG (d, a, b, c, x[14], S22, 0xc33707d6); /* 26 */
  3724. GG (c, d, a, b, x[ 3], S23, 0xf4d50d87); /* 27 */
  3725. GG (b, c, d, a, x[ 8], S24, 0x455a14ed); /* 28 */
  3726. GG (a, b, c, d, x[13], S21, 0xa9e3e905); /* 29 */
  3727. GG (d, a, b, c, x[ 2], S22, 0xfcefa3f8); /* 30 */
  3728. GG (c, d, a, b, x[ 7], S23, 0x676f02d9); /* 31 */
  3729. GG (b, c, d, a, x[12], S24, 0x8d2a4c8a); /* 32 */
  3730. HH (a, b, c, d, x[ 5], S31, 0xfffa3942); /* 33 */
  3731. HH (d, a, b, c, x[ 8], S32, 0x8771f681); /* 34 */
  3732. HH (c, d, a, b, x[11], S33, 0x6d9d6122); /* 35 */
  3733. HH (b, c, d, a, x[14], S34, 0xfde5380c); /* 36 */
  3734. HH (a, b, c, d, x[ 1], S31, 0xa4beea44); /* 37 */
  3735. HH (d, a, b, c, x[ 4], S32, 0x4bdecfa9); /* 38 */
  3736. HH (c, d, a, b, x[ 7], S33, 0xf6bb4b60); /* 39 */
  3737. HH (b, c, d, a, x[10], S34, 0xbebfbc70); /* 40 */
  3738. HH (a, b, c, d, x[13], S31, 0x289b7ec6); /* 41 */
  3739. HH (d, a, b, c, x[ 0], S32, 0xeaa127fa); /* 42 */
  3740. HH (c, d, a, b, x[ 3], S33, 0xd4ef3085); /* 43 */
  3741. HH (b, c, d, a, x[ 6], S34, 0x4881d05); /* 44 */
  3742. HH (a, b, c, d, x[ 9], S31, 0xd9d4d039); /* 45 */
  3743. HH (d, a, b, c, x[12], S32, 0xe6db99e5); /* 46 */
  3744. HH (c, d, a, b, x[15], S33, 0x1fa27cf8); /* 47 */
  3745. HH (b, c, d, a, x[ 2], S34, 0xc4ac5665); /* 48 */
  3746. II (a, b, c, d, x[ 0], S41, 0xf4292244); /* 49 */
  3747. II (d, a, b, c, x[ 7], S42, 0x432aff97); /* 50 */
  3748. II (c, d, a, b, x[14], S43, 0xab9423a7); /* 51 */
  3749. II (b, c, d, a, x[ 5], S44, 0xfc93a039); /* 52 */
  3750. II (a, b, c, d, x[12], S41, 0x655b59c3); /* 53 */
  3751. II (d, a, b, c, x[ 3], S42, 0x8f0ccc92); /* 54 */
  3752. II (c, d, a, b, x[10], S43, 0xffeff47d); /* 55 */
  3753. II (b, c, d, a, x[ 1], S44, 0x85845dd1); /* 56 */
  3754. II (a, b, c, d, x[ 8], S41, 0x6fa87e4f); /* 57 */
  3755. II (d, a, b, c, x[15], S42, 0xfe2ce6e0); /* 58 */
  3756. II (c, d, a, b, x[ 6], S43, 0xa3014314); /* 59 */
  3757. II (b, c, d, a, x[13], S44, 0x4e0811a1); /* 60 */
  3758. II (a, b, c, d, x[ 4], S41, 0xf7537e82); /* 61 */
  3759. II (d, a, b, c, x[11], S42, 0xbd3af235); /* 62 */
  3760. II (c, d, a, b, x[ 2], S43, 0x2ad7d2bb); /* 63 */
  3761. II (b, c, d, a, x[ 9], S44, 0xeb86d391); /* 64 */
  3762. state[0] += a;
  3763. state[1] += b;
  3764. state[2] += c;
  3765. state[3] += d;
  3766. zerostruct (x);
  3767. }
  3768. const MemoryBlock MD5::getRawChecksumData() const
  3769. {
  3770. return MemoryBlock (result, sizeof (result));
  3771. }
  3772. const String MD5::toHexString() const
  3773. {
  3774. return String::toHexString (result, sizeof (result), 0);
  3775. }
  3776. bool MD5::operator== (const MD5& other) const
  3777. {
  3778. return memcmp (result, other.result, sizeof (result)) == 0;
  3779. }
  3780. bool MD5::operator!= (const MD5& other) const
  3781. {
  3782. return ! operator== (other);
  3783. }
  3784. END_JUCE_NAMESPACE
  3785. /*** End of inlined file: juce_MD5.cpp ***/
  3786. /*** Start of inlined file: juce_Primes.cpp ***/
  3787. BEGIN_JUCE_NAMESPACE
  3788. namespace PrimesHelpers
  3789. {
  3790. static void createSmallSieve (const int numBits, BigInteger& result)
  3791. {
  3792. result.setBit (numBits);
  3793. result.clearBit (numBits); // to enlarge the array
  3794. result.setBit (0);
  3795. int n = 2;
  3796. do
  3797. {
  3798. for (int i = n + n; i < numBits; i += n)
  3799. result.setBit (i);
  3800. n = result.findNextClearBit (n + 1);
  3801. }
  3802. while (n <= (numBits >> 1));
  3803. }
  3804. static void bigSieve (const BigInteger& base, const int numBits, BigInteger& result,
  3805. const BigInteger& smallSieve, const int smallSieveSize)
  3806. {
  3807. jassert (! base[0]); // must be even!
  3808. result.setBit (numBits);
  3809. result.clearBit (numBits); // to enlarge the array
  3810. int index = smallSieve.findNextClearBit (0);
  3811. do
  3812. {
  3813. const int prime = (index << 1) + 1;
  3814. BigInteger r (base), remainder;
  3815. r.divideBy (prime, remainder);
  3816. int i = prime - remainder.getBitRangeAsInt (0, 32);
  3817. if (r.isZero())
  3818. i += prime;
  3819. if ((i & 1) == 0)
  3820. i += prime;
  3821. i = (i - 1) >> 1;
  3822. while (i < numBits)
  3823. {
  3824. result.setBit (i);
  3825. i += prime;
  3826. }
  3827. index = smallSieve.findNextClearBit (index + 1);
  3828. }
  3829. while (index < smallSieveSize);
  3830. }
  3831. static bool findCandidate (const BigInteger& base, const BigInteger& sieve,
  3832. const int numBits, BigInteger& result, const int certainty)
  3833. {
  3834. for (int i = 0; i < numBits; ++i)
  3835. {
  3836. if (! sieve[i])
  3837. {
  3838. result = base + (unsigned int) ((i << 1) + 1);
  3839. if (Primes::isProbablyPrime (result, certainty))
  3840. return true;
  3841. }
  3842. }
  3843. return false;
  3844. }
  3845. static bool passesMillerRabin (const BigInteger& n, int iterations)
  3846. {
  3847. const BigInteger one (1), two (2);
  3848. const BigInteger nMinusOne (n - one);
  3849. BigInteger d (nMinusOne);
  3850. const int s = d.findNextSetBit (0);
  3851. d >>= s;
  3852. BigInteger smallPrimes;
  3853. int numBitsInSmallPrimes = 0;
  3854. for (;;)
  3855. {
  3856. numBitsInSmallPrimes += 256;
  3857. createSmallSieve (numBitsInSmallPrimes, smallPrimes);
  3858. const int numPrimesFound = numBitsInSmallPrimes - smallPrimes.countNumberOfSetBits();
  3859. if (numPrimesFound > iterations + 1)
  3860. break;
  3861. }
  3862. int smallPrime = 2;
  3863. while (--iterations >= 0)
  3864. {
  3865. smallPrime = smallPrimes.findNextClearBit (smallPrime + 1);
  3866. BigInteger r (smallPrime);
  3867. r.exponentModulo (d, n);
  3868. if (r != one && r != nMinusOne)
  3869. {
  3870. for (int j = 0; j < s; ++j)
  3871. {
  3872. r.exponentModulo (two, n);
  3873. if (r == nMinusOne)
  3874. break;
  3875. }
  3876. if (r != nMinusOne)
  3877. return false;
  3878. }
  3879. }
  3880. return true;
  3881. }
  3882. }
  3883. const BigInteger Primes::createProbablePrime (const int bitLength,
  3884. const int certainty,
  3885. const int* randomSeeds,
  3886. int numRandomSeeds)
  3887. {
  3888. using namespace PrimesHelpers;
  3889. int defaultSeeds [16];
  3890. if (numRandomSeeds <= 0)
  3891. {
  3892. randomSeeds = defaultSeeds;
  3893. numRandomSeeds = numElementsInArray (defaultSeeds);
  3894. Random r (0);
  3895. for (int j = 10; --j >= 0;)
  3896. {
  3897. r.setSeedRandomly();
  3898. for (int i = numRandomSeeds; --i >= 0;)
  3899. defaultSeeds[i] ^= r.nextInt() ^ Random::getSystemRandom().nextInt();
  3900. }
  3901. }
  3902. BigInteger smallSieve;
  3903. const int smallSieveSize = 15000;
  3904. createSmallSieve (smallSieveSize, smallSieve);
  3905. BigInteger p;
  3906. for (int i = numRandomSeeds; --i >= 0;)
  3907. {
  3908. BigInteger p2;
  3909. Random r (randomSeeds[i]);
  3910. r.fillBitsRandomly (p2, 0, bitLength);
  3911. p ^= p2;
  3912. }
  3913. p.setBit (bitLength - 1);
  3914. p.clearBit (0);
  3915. const int searchLen = jmax (1024, (bitLength / 20) * 64);
  3916. while (p.getHighestBit() < bitLength)
  3917. {
  3918. p += 2 * searchLen;
  3919. BigInteger sieve;
  3920. bigSieve (p, searchLen, sieve,
  3921. smallSieve, smallSieveSize);
  3922. BigInteger candidate;
  3923. if (findCandidate (p, sieve, searchLen, candidate, certainty))
  3924. return candidate;
  3925. }
  3926. jassertfalse
  3927. return BigInteger();
  3928. }
  3929. bool Primes::isProbablyPrime (const BigInteger& number, const int certainty)
  3930. {
  3931. using namespace PrimesHelpers;
  3932. if (! number[0])
  3933. return false;
  3934. if (number.getHighestBit() <= 10)
  3935. {
  3936. const int num = number.getBitRangeAsInt (0, 10);
  3937. for (int i = num / 2; --i > 1;)
  3938. if (num % i == 0)
  3939. return false;
  3940. return true;
  3941. }
  3942. else
  3943. {
  3944. if (number.findGreatestCommonDivisor (2 * 3 * 5 * 7 * 11 * 13 * 17 * 19 * 23) != 1)
  3945. return false;
  3946. return passesMillerRabin (number, certainty);
  3947. }
  3948. }
  3949. END_JUCE_NAMESPACE
  3950. /*** End of inlined file: juce_Primes.cpp ***/
  3951. /*** Start of inlined file: juce_RSAKey.cpp ***/
  3952. BEGIN_JUCE_NAMESPACE
  3953. RSAKey::RSAKey()
  3954. {
  3955. }
  3956. RSAKey::RSAKey (const String& s)
  3957. {
  3958. if (s.containsChar (T(',')))
  3959. {
  3960. part1.parseString (s.upToFirstOccurrenceOf (T(","), false, false), 16);
  3961. part2.parseString (s.fromFirstOccurrenceOf (T(","), false, false), 16);
  3962. }
  3963. else
  3964. {
  3965. // the string needs to be two hex numbers, comma-separated..
  3966. jassertfalse;
  3967. }
  3968. }
  3969. RSAKey::~RSAKey()
  3970. {
  3971. }
  3972. const String RSAKey::toString() const
  3973. {
  3974. return part1.toString (16) + "," + part2.toString (16);
  3975. }
  3976. bool RSAKey::applyToValue (BigInteger& value) const
  3977. {
  3978. if (part1.isZero() || part2.isZero() || value <= 0)
  3979. {
  3980. jassertfalse // using an uninitialised key
  3981. value.clear();
  3982. return false;
  3983. }
  3984. BigInteger result;
  3985. while (! value.isZero())
  3986. {
  3987. result *= part2;
  3988. BigInteger remainder;
  3989. value.divideBy (part2, remainder);
  3990. remainder.exponentModulo (part1, part2);
  3991. result += remainder;
  3992. }
  3993. value.swapWith (result);
  3994. return true;
  3995. }
  3996. static const BigInteger findBestCommonDivisor (const BigInteger& p, const BigInteger& q)
  3997. {
  3998. // try 3, 5, 9, 17, etc first because these only contain 2 bits and so
  3999. // are fast to divide + multiply
  4000. for (int i = 2; i <= 65536; i *= 2)
  4001. {
  4002. const BigInteger e (1 + i);
  4003. if (e.findGreatestCommonDivisor (p).isOne() && e.findGreatestCommonDivisor (q).isOne())
  4004. return e;
  4005. }
  4006. BigInteger e (4);
  4007. while (! (e.findGreatestCommonDivisor (p).isOne() && e.findGreatestCommonDivisor (q).isOne()))
  4008. ++e;
  4009. return e;
  4010. }
  4011. void RSAKey::createKeyPair (RSAKey& publicKey, RSAKey& privateKey,
  4012. const int numBits, const int* randomSeeds, const int numRandomSeeds)
  4013. {
  4014. jassert (numBits > 16); // not much point using less than this..
  4015. BigInteger p (Primes::createProbablePrime (numBits / 2, 30, randomSeeds, numRandomSeeds));
  4016. BigInteger q (Primes::createProbablePrime (numBits - numBits / 2, 30, randomSeeds, numRandomSeeds));
  4017. const BigInteger n (p * q);
  4018. const BigInteger m (--p * --q);
  4019. const BigInteger e (findBestCommonDivisor (p, q));
  4020. BigInteger d (e);
  4021. d.inverseModulo (m);
  4022. publicKey.part1 = e;
  4023. publicKey.part2 = n;
  4024. privateKey.part1 = d;
  4025. privateKey.part2 = n;
  4026. }
  4027. END_JUCE_NAMESPACE
  4028. /*** End of inlined file: juce_RSAKey.cpp ***/
  4029. /*** Start of inlined file: juce_InputStream.cpp ***/
  4030. BEGIN_JUCE_NAMESPACE
  4031. char InputStream::readByte()
  4032. {
  4033. char temp = 0;
  4034. read (&temp, 1);
  4035. return temp;
  4036. }
  4037. bool InputStream::readBool()
  4038. {
  4039. return readByte() != 0;
  4040. }
  4041. short InputStream::readShort()
  4042. {
  4043. char temp[2];
  4044. if (read (temp, 2) == 2)
  4045. return (short) ByteOrder::littleEndianShort (temp);
  4046. return 0;
  4047. }
  4048. short InputStream::readShortBigEndian()
  4049. {
  4050. char temp[2];
  4051. if (read (temp, 2) == 2)
  4052. return (short) ByteOrder::bigEndianShort (temp);
  4053. return 0;
  4054. }
  4055. int InputStream::readInt()
  4056. {
  4057. char temp[4];
  4058. if (read (temp, 4) == 4)
  4059. return (int) ByteOrder::littleEndianInt (temp);
  4060. return 0;
  4061. }
  4062. int InputStream::readIntBigEndian()
  4063. {
  4064. char temp[4];
  4065. if (read (temp, 4) == 4)
  4066. return (int) ByteOrder::bigEndianInt (temp);
  4067. return 0;
  4068. }
  4069. int InputStream::readCompressedInt()
  4070. {
  4071. const unsigned char sizeByte = readByte();
  4072. if (sizeByte == 0)
  4073. return 0;
  4074. const int numBytes = (sizeByte & 0x7f);
  4075. if (numBytes > 4)
  4076. {
  4077. jassertfalse // trying to read corrupt data - this method must only be used
  4078. // to read data that was written by OutputStream::writeCompressedInt()
  4079. return 0;
  4080. }
  4081. char bytes[4] = { 0, 0, 0, 0 };
  4082. if (read (bytes, numBytes) != numBytes)
  4083. return 0;
  4084. const int num = (int) ByteOrder::littleEndianInt (bytes);
  4085. return (sizeByte >> 7) ? -num : num;
  4086. }
  4087. int64 InputStream::readInt64()
  4088. {
  4089. char temp[8];
  4090. if (read (temp, 8) == 8)
  4091. return (int64) ByteOrder::swapIfBigEndian (*reinterpret_cast <uint64*> (temp));
  4092. return 0;
  4093. }
  4094. int64 InputStream::readInt64BigEndian()
  4095. {
  4096. char temp[8];
  4097. if (read (temp, 8) == 8)
  4098. return (int64) ByteOrder::swapIfLittleEndian (*reinterpret_cast <uint64*> (temp));
  4099. return 0;
  4100. }
  4101. float InputStream::readFloat()
  4102. {
  4103. union { int asInt; float asFloat; } n;
  4104. n.asInt = readInt();
  4105. return n.asFloat;
  4106. }
  4107. float InputStream::readFloatBigEndian()
  4108. {
  4109. union { int asInt; float asFloat; } n;
  4110. n.asInt = readIntBigEndian();
  4111. return n.asFloat;
  4112. }
  4113. double InputStream::readDouble()
  4114. {
  4115. union { int64 asInt; double asDouble; } n;
  4116. n.asInt = readInt64();
  4117. return n.asDouble;
  4118. }
  4119. double InputStream::readDoubleBigEndian()
  4120. {
  4121. union { int64 asInt; double asDouble; } n;
  4122. n.asInt = readInt64BigEndian();
  4123. return n.asDouble;
  4124. }
  4125. const String InputStream::readString()
  4126. {
  4127. MemoryBlock buffer (256);
  4128. char* data = static_cast<char*> (buffer.getData());
  4129. size_t i = 0;
  4130. while ((data[i] = readByte()) != 0)
  4131. {
  4132. if (++i >= buffer.getSize())
  4133. {
  4134. buffer.setSize (buffer.getSize() + 512);
  4135. data = static_cast<char*> (buffer.getData());
  4136. }
  4137. }
  4138. return String::fromUTF8 (data, (int) i);
  4139. }
  4140. const String InputStream::readNextLine()
  4141. {
  4142. MemoryBlock buffer (256);
  4143. char* data = static_cast<char*> (buffer.getData());
  4144. size_t i = 0;
  4145. while ((data[i] = readByte()) != 0)
  4146. {
  4147. if (data[i] == '\n')
  4148. break;
  4149. if (data[i] == '\r')
  4150. {
  4151. const int64 lastPos = getPosition();
  4152. if (readByte() != '\n')
  4153. setPosition (lastPos);
  4154. break;
  4155. }
  4156. if (++i >= buffer.getSize())
  4157. {
  4158. buffer.setSize (buffer.getSize() + 512);
  4159. data = static_cast<char*> (buffer.getData());
  4160. }
  4161. }
  4162. return String::fromUTF8 (data, (int) i);
  4163. }
  4164. int InputStream::readIntoMemoryBlock (MemoryBlock& block, int numBytes)
  4165. {
  4166. const int64 totalLength = getTotalLength();
  4167. if (totalLength >= 0)
  4168. {
  4169. const int totalBytesRemaining = (int) jmin ((int64) 0x7fffffff,
  4170. totalLength - getPosition());
  4171. if (numBytes < 0)
  4172. numBytes = totalBytesRemaining;
  4173. else if (numBytes > 0)
  4174. numBytes = jmin (numBytes, totalBytesRemaining);
  4175. else
  4176. return 0;
  4177. }
  4178. const size_t originalBlockSize = block.getSize();
  4179. int totalBytesRead = 0;
  4180. if (numBytes > 0)
  4181. {
  4182. // know how many bytes we want, so we can resize the block first..
  4183. block.setSize (originalBlockSize + numBytes, false);
  4184. totalBytesRead = read (static_cast<char*> (block.getData()) + originalBlockSize, numBytes);
  4185. }
  4186. else
  4187. {
  4188. // read until end of stram..
  4189. const int chunkSize = 32768;
  4190. for (;;)
  4191. {
  4192. block.ensureSize (originalBlockSize + totalBytesRead + chunkSize, false);
  4193. const int bytesJustIn = read (static_cast<char*> (block.getData())
  4194. + originalBlockSize
  4195. + totalBytesRead,
  4196. chunkSize);
  4197. if (bytesJustIn == 0)
  4198. break;
  4199. totalBytesRead += bytesJustIn;
  4200. }
  4201. }
  4202. // trim off any excess left at the end
  4203. block.setSize (originalBlockSize + totalBytesRead, false);
  4204. return totalBytesRead;
  4205. }
  4206. const String InputStream::readEntireStreamAsString()
  4207. {
  4208. MemoryBlock mb;
  4209. const int size = readIntoMemoryBlock (mb);
  4210. return String::createStringFromData (static_cast<const char*> (mb.getData()), size);
  4211. }
  4212. void InputStream::skipNextBytes (int64 numBytesToSkip)
  4213. {
  4214. if (numBytesToSkip > 0)
  4215. {
  4216. const int skipBufferSize = (int) jmin (numBytesToSkip, (int64) 16384);
  4217. HeapBlock<char> temp (skipBufferSize);
  4218. while (numBytesToSkip > 0 && ! isExhausted())
  4219. numBytesToSkip -= read (temp, (int) jmin (numBytesToSkip, (int64) skipBufferSize));
  4220. }
  4221. }
  4222. END_JUCE_NAMESPACE
  4223. /*** End of inlined file: juce_InputStream.cpp ***/
  4224. /*** Start of inlined file: juce_OutputStream.cpp ***/
  4225. BEGIN_JUCE_NAMESPACE
  4226. #if JUCE_DEBUG
  4227. static CriticalSection activeStreamLock;
  4228. static VoidArray activeStreams;
  4229. void juce_CheckForDanglingStreams()
  4230. {
  4231. /*
  4232. It's always a bad idea to leak any object, but if you're leaking output
  4233. streams, then there's a good chance that you're failing to flush a file
  4234. to disk properly, which could result in corrupted data and other similar
  4235. nastiness..
  4236. */
  4237. jassert (activeStreams.size() == 0);
  4238. };
  4239. #endif
  4240. OutputStream::OutputStream()
  4241. {
  4242. #if JUCE_DEBUG
  4243. const ScopedLock sl (activeStreamLock);
  4244. activeStreams.add (this);
  4245. #endif
  4246. }
  4247. OutputStream::~OutputStream()
  4248. {
  4249. #if JUCE_DEBUG
  4250. const ScopedLock sl (activeStreamLock);
  4251. activeStreams.removeValue (this);
  4252. #endif
  4253. }
  4254. void OutputStream::writeBool (bool b)
  4255. {
  4256. writeByte ((b) ? (char) 1
  4257. : (char) 0);
  4258. }
  4259. void OutputStream::writeByte (char byte)
  4260. {
  4261. write (&byte, 1);
  4262. }
  4263. void OutputStream::writeShort (short value)
  4264. {
  4265. const unsigned short v = ByteOrder::swapIfBigEndian ((unsigned short) value);
  4266. write (&v, 2);
  4267. }
  4268. void OutputStream::writeShortBigEndian (short value)
  4269. {
  4270. const unsigned short v = ByteOrder::swapIfLittleEndian ((unsigned short) value);
  4271. write (&v, 2);
  4272. }
  4273. void OutputStream::writeInt (int value)
  4274. {
  4275. const unsigned int v = ByteOrder::swapIfBigEndian ((unsigned int) value);
  4276. write (&v, 4);
  4277. }
  4278. void OutputStream::writeIntBigEndian (int value)
  4279. {
  4280. const unsigned int v = ByteOrder::swapIfLittleEndian ((unsigned int) value);
  4281. write (&v, 4);
  4282. }
  4283. void OutputStream::writeCompressedInt (int value)
  4284. {
  4285. unsigned int un = (value < 0) ? (unsigned int) -value
  4286. : (unsigned int) value;
  4287. uint8 data[5];
  4288. int num = 0;
  4289. while (un > 0)
  4290. {
  4291. data[++num] = (uint8) un;
  4292. un >>= 8;
  4293. }
  4294. data[0] = (uint8) num;
  4295. if (value < 0)
  4296. data[0] |= 0x80;
  4297. write (data, num + 1);
  4298. }
  4299. void OutputStream::writeInt64 (int64 value)
  4300. {
  4301. const uint64 v = ByteOrder::swapIfBigEndian ((uint64) value);
  4302. write (&v, 8);
  4303. }
  4304. void OutputStream::writeInt64BigEndian (int64 value)
  4305. {
  4306. const uint64 v = ByteOrder::swapIfLittleEndian ((uint64) value);
  4307. write (&v, 8);
  4308. }
  4309. void OutputStream::writeFloat (float value)
  4310. {
  4311. union { int asInt; float asFloat; } n;
  4312. n.asFloat = value;
  4313. writeInt (n.asInt);
  4314. }
  4315. void OutputStream::writeFloatBigEndian (float value)
  4316. {
  4317. union { int asInt; float asFloat; } n;
  4318. n.asFloat = value;
  4319. writeIntBigEndian (n.asInt);
  4320. }
  4321. void OutputStream::writeDouble (double value)
  4322. {
  4323. union { int64 asInt; double asDouble; } n;
  4324. n.asDouble = value;
  4325. writeInt64 (n.asInt);
  4326. }
  4327. void OutputStream::writeDoubleBigEndian (double value)
  4328. {
  4329. union { int64 asInt; double asDouble; } n;
  4330. n.asDouble = value;
  4331. writeInt64BigEndian (n.asInt);
  4332. }
  4333. void OutputStream::writeString (const String& text)
  4334. {
  4335. // (This avoids using toUTF8() to prevent the memory bloat that it would leave behind
  4336. // if lots of large, persistent strings were to be written to streams).
  4337. const int numBytes = text.getNumBytesAsUTF8() + 1;
  4338. HeapBlock<char> temp (numBytes);
  4339. text.copyToUTF8 (temp, numBytes);
  4340. write (temp, numBytes);
  4341. }
  4342. void OutputStream::writeText (const String& text, const bool asUnicode,
  4343. const bool writeUnicodeHeaderBytes)
  4344. {
  4345. if (asUnicode)
  4346. {
  4347. if (writeUnicodeHeaderBytes)
  4348. write ("\x0ff\x0fe", 2);
  4349. const juce_wchar* src = (const juce_wchar*) text;
  4350. bool lastCharWasReturn = false;
  4351. while (*src != 0)
  4352. {
  4353. if (*src == L'\n' && ! lastCharWasReturn)
  4354. writeShort ((short) L'\r');
  4355. lastCharWasReturn = (*src == L'\r');
  4356. writeShort ((short) *src++);
  4357. }
  4358. }
  4359. else
  4360. {
  4361. const char* src = text.toUTF8();
  4362. const char* t = src;
  4363. for (;;)
  4364. {
  4365. if (*t == '\n')
  4366. {
  4367. if (t > src)
  4368. write (src, (int) (t - src));
  4369. write ("\r\n", 2);
  4370. src = t + 1;
  4371. }
  4372. else if (*t == '\r')
  4373. {
  4374. if (t[1] == '\n')
  4375. ++t;
  4376. }
  4377. else if (*t == 0)
  4378. {
  4379. if (t > src)
  4380. write (src, (int) (t - src));
  4381. break;
  4382. }
  4383. ++t;
  4384. }
  4385. }
  4386. }
  4387. int OutputStream::writeFromInputStream (InputStream& source, int numBytesToWrite)
  4388. {
  4389. if (numBytesToWrite < 0)
  4390. numBytesToWrite = 0x7fffffff;
  4391. int numWritten = 0;
  4392. while (numBytesToWrite > 0 && ! source.isExhausted())
  4393. {
  4394. char buffer [8192];
  4395. const int num = (int) source.read (buffer, (int) jmin ((size_t) numBytesToWrite, sizeof (buffer)));
  4396. if (num == 0)
  4397. break;
  4398. write (buffer, num);
  4399. numBytesToWrite -= num;
  4400. numWritten += num;
  4401. }
  4402. return numWritten;
  4403. }
  4404. OutputStream& JUCE_CALLTYPE operator<< (OutputStream& stream, const int number)
  4405. {
  4406. return stream << String (number);
  4407. }
  4408. OutputStream& JUCE_CALLTYPE operator<< (OutputStream& stream, const double number)
  4409. {
  4410. return stream << String (number);
  4411. }
  4412. OutputStream& JUCE_CALLTYPE operator<< (OutputStream& stream, const char character)
  4413. {
  4414. stream.writeByte (character);
  4415. return stream;
  4416. }
  4417. OutputStream& JUCE_CALLTYPE operator<< (OutputStream& stream, const char* const text)
  4418. {
  4419. stream.write (text, (int) strlen (text));
  4420. return stream;
  4421. }
  4422. END_JUCE_NAMESPACE
  4423. /*** End of inlined file: juce_OutputStream.cpp ***/
  4424. /*** Start of inlined file: juce_DirectoryIterator.cpp ***/
  4425. BEGIN_JUCE_NAMESPACE
  4426. void* juce_findFileStart (const String& directory, const String& wildCard, String& firstResultFile,
  4427. bool* isDirectory, bool* isHidden, int64* fileSize,
  4428. Time* modTime, Time* creationTime, bool* isReadOnly);
  4429. bool juce_findFileNext (void* handle, String& resultFile,
  4430. bool* isDirectory, bool* isHidden, int64* fileSize,
  4431. Time* modTime, Time* creationTime, bool* isReadOnly);
  4432. void juce_findFileClose (void* handle);
  4433. DirectoryIterator::DirectoryIterator (const File& directory,
  4434. bool isRecursive,
  4435. const String& wc,
  4436. const int whatToLookFor_)
  4437. : wildCard (wc),
  4438. index (-1),
  4439. whatToLookFor (whatToLookFor_)
  4440. {
  4441. // you have to specify the type of files you're looking for!
  4442. jassert ((whatToLookFor_ & (File::findFiles | File::findDirectories)) != 0);
  4443. jassert (whatToLookFor_ > 0 && whatToLookFor_ <= 7);
  4444. String path (directory.getFullPathName());
  4445. if (! path.endsWithChar (File::separator))
  4446. path += File::separator;
  4447. String filename;
  4448. bool isDirectory, isHidden;
  4449. void* const handle = juce_findFileStart (path,
  4450. isRecursive ? T("*") : wc,
  4451. filename, &isDirectory, &isHidden, 0, 0, 0, 0);
  4452. if (handle != 0)
  4453. {
  4454. do
  4455. {
  4456. if (! filename.containsOnly (T(".")))
  4457. {
  4458. bool addToList = false;
  4459. if (isDirectory)
  4460. {
  4461. if (isRecursive
  4462. && ((whatToLookFor_ & File::ignoreHiddenFiles) == 0
  4463. || ! isHidden))
  4464. {
  4465. dirsFound.add (File (path + filename, 0));
  4466. }
  4467. addToList = (whatToLookFor_ & File::findDirectories) != 0;
  4468. }
  4469. else
  4470. {
  4471. addToList = (whatToLookFor_ & File::findFiles) != 0;
  4472. }
  4473. // if it's recursive, we're not relying on the OS iterator
  4474. // to do the wildcard match, so do it now..
  4475. if (isRecursive && addToList)
  4476. addToList = filename.matchesWildcard (wc, true);
  4477. if (addToList && (whatToLookFor_ & File::ignoreHiddenFiles) != 0)
  4478. addToList = ! isHidden;
  4479. if (addToList)
  4480. filesFound.add (File (path + filename, 0));
  4481. }
  4482. } while (juce_findFileNext (handle, filename, &isDirectory, &isHidden, 0, 0, 0, 0));
  4483. juce_findFileClose (handle);
  4484. }
  4485. }
  4486. DirectoryIterator::~DirectoryIterator()
  4487. {
  4488. }
  4489. bool DirectoryIterator::next()
  4490. {
  4491. if (subIterator != 0)
  4492. {
  4493. if (subIterator->next())
  4494. return true;
  4495. subIterator = 0;
  4496. }
  4497. if (index >= filesFound.size() + dirsFound.size() - 1)
  4498. return false;
  4499. ++index;
  4500. if (index >= filesFound.size())
  4501. {
  4502. subIterator = new DirectoryIterator (dirsFound.getReference (index - filesFound.size()),
  4503. true, wildCard, whatToLookFor);
  4504. return next();
  4505. }
  4506. return true;
  4507. }
  4508. const File DirectoryIterator::getFile() const
  4509. {
  4510. if (subIterator != 0)
  4511. return subIterator->getFile();
  4512. return filesFound [index];
  4513. }
  4514. float DirectoryIterator::getEstimatedProgress() const
  4515. {
  4516. if (filesFound.size() + dirsFound.size() == 0)
  4517. {
  4518. return 0.0f;
  4519. }
  4520. else
  4521. {
  4522. const float detailedIndex = (subIterator != 0) ? index + subIterator->getEstimatedProgress()
  4523. : (float) index;
  4524. return detailedIndex / (filesFound.size() + dirsFound.size());
  4525. }
  4526. }
  4527. END_JUCE_NAMESPACE
  4528. /*** End of inlined file: juce_DirectoryIterator.cpp ***/
  4529. /*** Start of inlined file: juce_File.cpp ***/
  4530. #ifdef _MSC_VER
  4531. #pragma warning (disable: 4514)
  4532. #pragma warning (push)
  4533. #endif
  4534. #if ! JUCE_WINDOWS
  4535. #include <pwd.h>
  4536. #endif
  4537. BEGIN_JUCE_NAMESPACE
  4538. #ifdef _MSC_VER
  4539. #pragma warning (pop)
  4540. #endif
  4541. void* juce_fileOpen (const String& path, bool forWriting);
  4542. void juce_fileClose (void* handle);
  4543. int juce_fileWrite (void* handle, const void* buffer, int size);
  4544. int64 juce_fileGetPosition (void* handle);
  4545. int64 juce_fileSetPosition (void* handle, int64 pos);
  4546. void juce_fileFlush (void* handle);
  4547. bool juce_fileExists (const String& fileName, const bool dontCountDirectories);
  4548. bool juce_isDirectory (const String& fileName);
  4549. int64 juce_getFileSize (const String& fileName);
  4550. bool juce_canWriteToFile (const String& fileName);
  4551. bool juce_setFileReadOnly (const String& fileName, bool isReadOnly);
  4552. void juce_getFileTimes (const String& fileName, int64& modificationTime, int64& accessTime, int64& creationTime);
  4553. bool juce_setFileTimes (const String& fileName, int64 modificationTime, int64 accessTime, int64 creationTime);
  4554. bool juce_deleteFile (const String& fileName);
  4555. bool juce_copyFile (const String& source, const String& dest);
  4556. bool juce_moveFile (const String& source, const String& dest);
  4557. // this must also create all paths involved in the directory.
  4558. void juce_createDirectory (const String& fileName);
  4559. bool juce_launchFile (const String& fileName, const String& parameters);
  4560. const StringArray juce_getFileSystemRoots();
  4561. const String juce_getVolumeLabel (const String& filenameOnVolume, int& volumeSerialNumber);
  4562. // starts a directory search operation with a wildcard, returning a handle for
  4563. // use in calls to juce_findFileNext.
  4564. // juce_firstResultFile gets the name of the file (not the whole pathname) and
  4565. // the other pointers, if non-null, are set based on the properties of the file.
  4566. void* juce_findFileStart (const String& directory, const String& wildCard, String& firstResultFile,
  4567. bool* isDirectory, bool* isHidden, int64* fileSize, Time* modTime,
  4568. Time* creationTime, bool* isReadOnly);
  4569. // returns false when no more files are found
  4570. bool juce_findFileNext (void* handle, String& resultFile,
  4571. bool* isDirectory, bool* isHidden, int64* fileSize,
  4572. Time* modTime, Time* creationTime, bool* isReadOnly);
  4573. void juce_findFileClose (void* handle);
  4574. static const String juce_addTrailingSeparator (const String& path)
  4575. {
  4576. return path.endsWithChar (File::separator) ? path
  4577. : path + File::separator;
  4578. }
  4579. static const String parseAbsolutePath (String path)
  4580. {
  4581. if (path.isEmpty())
  4582. return String::empty;
  4583. #if JUCE_WINDOWS
  4584. // Windows..
  4585. path = path.replaceCharacter (T('/'), T('\\'));
  4586. if (path.startsWithChar (File::separator))
  4587. {
  4588. if (path[1] != File::separator)
  4589. {
  4590. /* When you supply a raw string to the File object constructor, it must be an absolute path.
  4591. If you're trying to parse a string that may be either a relative path or an absolute path,
  4592. you MUST provide a context against which the partial path can be evaluated - you can do
  4593. this by simply using File::getChildFile() instead of the File constructor. E.g. saying
  4594. "File::getCurrentWorkingDirectory().getChildFile (myUnknownPath)" would return an absolute
  4595. path if that's what was supplied, or would evaluate a partial path relative to the CWD.
  4596. */
  4597. jassertfalse
  4598. path = File::getCurrentWorkingDirectory().getFullPathName().substring (0, 2) + path;
  4599. }
  4600. }
  4601. else if (path.indexOfChar (T(':')) < 0)
  4602. {
  4603. if (path.isEmpty())
  4604. return String::empty;
  4605. /* When you supply a raw string to the File object constructor, it must be an absolute path.
  4606. If you're trying to parse a string that may be either a relative path or an absolute path,
  4607. you MUST provide a context against which the partial path can be evaluated - you can do
  4608. this by simply using File::getChildFile() instead of the File constructor. E.g. saying
  4609. "File::getCurrentWorkingDirectory().getChildFile (myUnknownPath)" would return an absolute
  4610. path if that's what was supplied, or would evaluate a partial path relative to the CWD.
  4611. */
  4612. jassertfalse
  4613. return File::getCurrentWorkingDirectory().getChildFile (path).getFullPathName();
  4614. }
  4615. #else
  4616. // Mac or Linux..
  4617. path = path.replaceCharacter (T('\\'), T('/'));
  4618. if (path.startsWithChar (T('~')))
  4619. {
  4620. const char* homeDir = 0;
  4621. if (path[1] == File::separator || path[1] == 0)
  4622. {
  4623. // expand a name of the form "~/abc"
  4624. path = File::getSpecialLocation (File::userHomeDirectory).getFullPathName()
  4625. + path.substring (1);
  4626. }
  4627. else
  4628. {
  4629. // expand a name of type "~dave/abc"
  4630. const String userName (path.substring (1).upToFirstOccurrenceOf (T("/"), false, false));
  4631. struct passwd* const pw = getpwnam (userName.toUTF8());
  4632. if (pw != 0)
  4633. {
  4634. String home (homeDir);
  4635. if (home.endsWithChar (File::separator))
  4636. home [home.length() - 1] = 0;
  4637. path = String (pw->pw_dir)
  4638. + path.substring (userName.length());
  4639. }
  4640. }
  4641. }
  4642. else if (! path.startsWithChar (File::separator))
  4643. {
  4644. /* When you supply a raw string to the File object constructor, it must be an absolute path.
  4645. If you're trying to parse a string that may be either a relative path or an absolute path,
  4646. you MUST provide a context against which the partial path can be evaluated - you can do
  4647. this by simply using File::getChildFile() instead of the File constructor. E.g. saying
  4648. "File::getCurrentWorkingDirectory().getChildFile (myUnknownPath)" would return an absolute
  4649. path if that's what was supplied, or would evaluate a partial path relative to the CWD.
  4650. */
  4651. jassert (path.startsWith (T("./"))); // (assume that a path "./xyz" is deliberately intended to be relative to the CWD)
  4652. return File::getCurrentWorkingDirectory().getChildFile (path).getFullPathName();
  4653. }
  4654. #endif
  4655. int len = path.length();
  4656. while (--len > 0 && path [len] == File::separator)
  4657. path [len] = 0;
  4658. return path;
  4659. }
  4660. const File File::nonexistent;
  4661. File::File (const String& fullPathName)
  4662. : fullPath (parseAbsolutePath (fullPathName))
  4663. {
  4664. }
  4665. File::File (const String& path, int)
  4666. : fullPath (path)
  4667. {
  4668. }
  4669. const File File::createFileWithoutCheckingPath (const String& path)
  4670. {
  4671. return File (path, 0);
  4672. }
  4673. File::File (const File& other)
  4674. : fullPath (other.fullPath)
  4675. {
  4676. }
  4677. File& File::operator= (const String& newPath)
  4678. {
  4679. fullPath = parseAbsolutePath (newPath);
  4680. return *this;
  4681. }
  4682. File& File::operator= (const File& other)
  4683. {
  4684. fullPath = other.fullPath;
  4685. return *this;
  4686. }
  4687. #if JUCE_LINUX
  4688. #define NAMES_ARE_CASE_SENSITIVE 1
  4689. #endif
  4690. bool File::areFileNamesCaseSensitive()
  4691. {
  4692. #if NAMES_ARE_CASE_SENSITIVE
  4693. return true;
  4694. #else
  4695. return false;
  4696. #endif
  4697. }
  4698. bool File::operator== (const File& other) const
  4699. {
  4700. // case-insensitive on Windows, but not on linux.
  4701. #if NAMES_ARE_CASE_SENSITIVE
  4702. return fullPath == other.fullPath;
  4703. #else
  4704. return fullPath.equalsIgnoreCase (other.fullPath);
  4705. #endif
  4706. }
  4707. bool File::operator!= (const File& other) const
  4708. {
  4709. return ! operator== (other);
  4710. }
  4711. bool File::exists() const
  4712. {
  4713. return juce_fileExists (fullPath, false);
  4714. }
  4715. bool File::existsAsFile() const
  4716. {
  4717. return juce_fileExists (fullPath, true);
  4718. }
  4719. bool File::isDirectory() const
  4720. {
  4721. return juce_isDirectory (fullPath);
  4722. }
  4723. bool File::hasWriteAccess() const
  4724. {
  4725. if (exists())
  4726. return juce_canWriteToFile (fullPath);
  4727. #if ! JUCE_WINDOWS
  4728. else if ((! isDirectory()) && fullPath.containsChar (separator))
  4729. return getParentDirectory().hasWriteAccess();
  4730. else
  4731. return false;
  4732. #else
  4733. // on windows, it seems that even read-only directories can still be written into,
  4734. // so checking the parent directory's permissions would return the wrong result..
  4735. else
  4736. return true;
  4737. #endif
  4738. }
  4739. bool File::setReadOnly (const bool shouldBeReadOnly,
  4740. const bool applyRecursively) const
  4741. {
  4742. bool worked = true;
  4743. if (applyRecursively && isDirectory())
  4744. {
  4745. Array <File> subFiles;
  4746. findChildFiles (subFiles, File::findFilesAndDirectories, false);
  4747. for (int i = subFiles.size(); --i >= 0;)
  4748. worked = subFiles.getReference(i).setReadOnly (shouldBeReadOnly, true) && worked;
  4749. }
  4750. return juce_setFileReadOnly (fullPath, shouldBeReadOnly) && worked;
  4751. }
  4752. bool File::deleteFile() const
  4753. {
  4754. return (! exists())
  4755. || juce_deleteFile (fullPath);
  4756. }
  4757. bool File::deleteRecursively() const
  4758. {
  4759. bool worked = true;
  4760. if (isDirectory())
  4761. {
  4762. Array<File> subFiles;
  4763. findChildFiles (subFiles, File::findFilesAndDirectories, false);
  4764. for (int i = subFiles.size(); --i >= 0;)
  4765. worked = subFiles.getReference(i).deleteRecursively() && worked;
  4766. }
  4767. return deleteFile() && worked;
  4768. }
  4769. bool File::moveFileTo (const File& newFile) const
  4770. {
  4771. if (newFile.fullPath == fullPath)
  4772. return true;
  4773. #if ! NAMES_ARE_CASE_SENSITIVE
  4774. if (*this != newFile)
  4775. #endif
  4776. if (! newFile.deleteFile())
  4777. return false;
  4778. return juce_moveFile (fullPath, newFile.fullPath);
  4779. }
  4780. bool File::copyFileTo (const File& newFile) const
  4781. {
  4782. if (*this == newFile)
  4783. return true;
  4784. if (! newFile.deleteFile())
  4785. return false;
  4786. return juce_copyFile (fullPath, newFile.fullPath);
  4787. }
  4788. bool File::copyDirectoryTo (const File& newDirectory) const
  4789. {
  4790. if (isDirectory() && newDirectory.createDirectory())
  4791. {
  4792. Array<File> subFiles;
  4793. findChildFiles (subFiles, File::findFiles, false);
  4794. int i;
  4795. for (i = 0; i < subFiles.size(); ++i)
  4796. if (! subFiles.getReference(i).copyFileTo (newDirectory.getChildFile (subFiles.getReference(i).getFileName())))
  4797. return false;
  4798. subFiles.clear();
  4799. findChildFiles (subFiles, File::findDirectories, false);
  4800. for (i = 0; i < subFiles.size(); ++i)
  4801. if (! subFiles.getReference(i).copyDirectoryTo (newDirectory.getChildFile (subFiles.getReference(i).getFileName())))
  4802. return false;
  4803. return true;
  4804. }
  4805. return false;
  4806. }
  4807. const String File::getPathUpToLastSlash() const
  4808. {
  4809. const int lastSlash = fullPath.lastIndexOfChar (separator);
  4810. if (lastSlash > 0)
  4811. return fullPath.substring (0, lastSlash);
  4812. else if (lastSlash == 0)
  4813. return separatorString;
  4814. else
  4815. return fullPath;
  4816. }
  4817. const File File::getParentDirectory() const
  4818. {
  4819. return File (getPathUpToLastSlash());
  4820. }
  4821. const String File::getFileName() const
  4822. {
  4823. return fullPath.substring (fullPath.lastIndexOfChar (separator) + 1);
  4824. }
  4825. int File::hashCode() const
  4826. {
  4827. return fullPath.hashCode();
  4828. }
  4829. int64 File::hashCode64() const
  4830. {
  4831. return fullPath.hashCode64();
  4832. }
  4833. const String File::getFileNameWithoutExtension() const
  4834. {
  4835. const int lastSlash = fullPath.lastIndexOfChar (separator) + 1;
  4836. const int lastDot = fullPath.lastIndexOfChar (T('.'));
  4837. if (lastDot > lastSlash)
  4838. return fullPath.substring (lastSlash, lastDot);
  4839. else
  4840. return fullPath.substring (lastSlash);
  4841. }
  4842. bool File::isAChildOf (const File& potentialParent) const
  4843. {
  4844. if (potentialParent == File::nonexistent)
  4845. return false;
  4846. const String ourPath (getPathUpToLastSlash());
  4847. #if NAMES_ARE_CASE_SENSITIVE
  4848. if (potentialParent.fullPath == ourPath)
  4849. #else
  4850. if (potentialParent.fullPath.equalsIgnoreCase (ourPath))
  4851. #endif
  4852. {
  4853. return true;
  4854. }
  4855. else if (potentialParent.fullPath.length() >= ourPath.length())
  4856. {
  4857. return false;
  4858. }
  4859. else
  4860. {
  4861. return getParentDirectory().isAChildOf (potentialParent);
  4862. }
  4863. }
  4864. bool File::isAbsolutePath (const String& path)
  4865. {
  4866. return path.startsWithChar (T('/')) || path.startsWithChar (T('\\'))
  4867. #if JUCE_WINDOWS
  4868. || (path.isNotEmpty() && ((const String&) path)[1] == T(':'));
  4869. #else
  4870. || path.startsWithChar (T('~'));
  4871. #endif
  4872. }
  4873. const File File::getChildFile (String relativePath) const
  4874. {
  4875. if (isAbsolutePath (relativePath))
  4876. {
  4877. // the path is really absolute..
  4878. return File (relativePath);
  4879. }
  4880. else
  4881. {
  4882. // it's relative, so remove any ../ or ./ bits at the start.
  4883. String path (fullPath);
  4884. if (relativePath[0] == T('.'))
  4885. {
  4886. #if JUCE_WINDOWS
  4887. relativePath = relativePath.replaceCharacter (T('/'), T('\\')).trimStart();
  4888. #else
  4889. relativePath = relativePath.replaceCharacter (T('\\'), T('/')).trimStart();
  4890. #endif
  4891. while (relativePath[0] == T('.'))
  4892. {
  4893. if (relativePath[1] == T('.'))
  4894. {
  4895. if (relativePath [2] == 0 || relativePath[2] == separator)
  4896. {
  4897. const int lastSlash = path.lastIndexOfChar (separator);
  4898. if (lastSlash >= 0)
  4899. path = path.substring (0, lastSlash);
  4900. relativePath = relativePath.substring (3);
  4901. }
  4902. else
  4903. {
  4904. break;
  4905. }
  4906. }
  4907. else if (relativePath[1] == separator)
  4908. {
  4909. relativePath = relativePath.substring (2);
  4910. }
  4911. else
  4912. {
  4913. break;
  4914. }
  4915. }
  4916. }
  4917. return File (juce_addTrailingSeparator (path) + relativePath);
  4918. }
  4919. }
  4920. const File File::getSiblingFile (const String& fileName) const
  4921. {
  4922. return getParentDirectory().getChildFile (fileName);
  4923. }
  4924. int64 File::getSize() const
  4925. {
  4926. return juce_getFileSize (fullPath);
  4927. }
  4928. const String File::descriptionOfSizeInBytes (const int64 bytes)
  4929. {
  4930. if (bytes == 1)
  4931. {
  4932. return "1 byte";
  4933. }
  4934. else if (bytes < 1024)
  4935. {
  4936. return String ((int) bytes) + " bytes";
  4937. }
  4938. else if (bytes < 1024 * 1024)
  4939. {
  4940. return String (bytes / 1024.0, 1) + " KB";
  4941. }
  4942. else if (bytes < 1024 * 1024 * 1024)
  4943. {
  4944. return String (bytes / (1024.0 * 1024.0), 1) + " MB";
  4945. }
  4946. else
  4947. {
  4948. return String (bytes / (1024.0 * 1024.0 * 1024.0), 1) + " GB";
  4949. }
  4950. }
  4951. bool File::create() const
  4952. {
  4953. if (! exists())
  4954. {
  4955. const File parentDir (getParentDirectory());
  4956. if (parentDir == *this || ! parentDir.createDirectory())
  4957. return false;
  4958. void* const fh = juce_fileOpen (fullPath, true);
  4959. if (fh == 0)
  4960. return false;
  4961. juce_fileClose (fh);
  4962. }
  4963. return true;
  4964. }
  4965. bool File::createDirectory() const
  4966. {
  4967. if (! isDirectory())
  4968. {
  4969. const File parentDir (getParentDirectory());
  4970. if (parentDir == *this || ! parentDir.createDirectory())
  4971. return false;
  4972. String dir (fullPath);
  4973. while (dir.endsWithChar (separator))
  4974. dir [dir.length() - 1] = 0;
  4975. juce_createDirectory (dir);
  4976. return isDirectory();
  4977. }
  4978. return true;
  4979. }
  4980. const Time File::getCreationTime() const
  4981. {
  4982. int64 m, a, c;
  4983. juce_getFileTimes (fullPath, m, a, c);
  4984. return Time (c);
  4985. }
  4986. bool File::setCreationTime (const Time& t) const
  4987. {
  4988. return juce_setFileTimes (fullPath, 0, 0, t.toMilliseconds());
  4989. }
  4990. const Time File::getLastModificationTime() const
  4991. {
  4992. int64 m, a, c;
  4993. juce_getFileTimes (fullPath, m, a, c);
  4994. return Time (m);
  4995. }
  4996. bool File::setLastModificationTime (const Time& t) const
  4997. {
  4998. return juce_setFileTimes (fullPath, t.toMilliseconds(), 0, 0);
  4999. }
  5000. const Time File::getLastAccessTime() const
  5001. {
  5002. int64 m, a, c;
  5003. juce_getFileTimes (fullPath, m, a, c);
  5004. return Time (a);
  5005. }
  5006. bool File::setLastAccessTime (const Time& t) const
  5007. {
  5008. return juce_setFileTimes (fullPath, 0, t.toMilliseconds(), 0);
  5009. }
  5010. bool File::loadFileAsData (MemoryBlock& destBlock) const
  5011. {
  5012. if (! existsAsFile())
  5013. return false;
  5014. FileInputStream in (*this);
  5015. return getSize() == in.readIntoMemoryBlock (destBlock);
  5016. }
  5017. const String File::loadFileAsString() const
  5018. {
  5019. if (! existsAsFile())
  5020. return String::empty;
  5021. FileInputStream in (*this);
  5022. return in.readEntireStreamAsString();
  5023. }
  5024. static inline bool fileTypeMatches (const int whatToLookFor,
  5025. const bool isDir,
  5026. const bool isHidden)
  5027. {
  5028. return (whatToLookFor & (isDir ? File::findDirectories
  5029. : File::findFiles)) != 0
  5030. && ((! isHidden)
  5031. || (whatToLookFor & File::ignoreHiddenFiles) == 0);
  5032. }
  5033. int File::findChildFiles (Array<File>& results,
  5034. const int whatToLookFor,
  5035. const bool searchRecursively,
  5036. const String& wildCardPattern) const
  5037. {
  5038. // you have to specify the type of files you're looking for!
  5039. jassert ((whatToLookFor & (findFiles | findDirectories)) != 0);
  5040. int total = 0;
  5041. // find child files or directories in this directory first..
  5042. if (isDirectory())
  5043. {
  5044. const String path (juce_addTrailingSeparator (fullPath));
  5045. String filename;
  5046. bool itemIsDirectory, itemIsHidden;
  5047. void* const handle = juce_findFileStart (path, wildCardPattern, filename,
  5048. &itemIsDirectory, &itemIsHidden,
  5049. 0, 0, 0, 0);
  5050. if (handle != 0)
  5051. {
  5052. do
  5053. {
  5054. if (fileTypeMatches (whatToLookFor, itemIsDirectory, itemIsHidden)
  5055. && ! filename.containsOnly (T(".")))
  5056. {
  5057. results.add (File (path + filename, 0));
  5058. ++total;
  5059. }
  5060. } while (juce_findFileNext (handle, filename, &itemIsDirectory, &itemIsHidden, 0, 0, 0, 0));
  5061. juce_findFileClose (handle);
  5062. }
  5063. }
  5064. else
  5065. {
  5066. // trying to search for files inside a non-directory?
  5067. //jassertfalse
  5068. }
  5069. // and recurse down if required.
  5070. if (searchRecursively)
  5071. {
  5072. Array<File> subDirectories;
  5073. findChildFiles (subDirectories, File::findDirectories, false);
  5074. for (int i = 0; i < subDirectories.size(); ++i)
  5075. {
  5076. total += subDirectories.getReference(i).findChildFiles (results, whatToLookFor,
  5077. true, wildCardPattern);
  5078. }
  5079. }
  5080. return total;
  5081. }
  5082. int File::getNumberOfChildFiles (const int whatToLookFor,
  5083. const String& wildCardPattern) const
  5084. {
  5085. // you have to specify the type of files you're looking for!
  5086. jassert (whatToLookFor > 0 && whatToLookFor <= 3);
  5087. int count = 0;
  5088. if (isDirectory())
  5089. {
  5090. String filename;
  5091. bool itemIsDirectory, itemIsHidden;
  5092. void* const handle = juce_findFileStart (fullPath, wildCardPattern, filename,
  5093. &itemIsDirectory, &itemIsHidden,
  5094. 0, 0, 0, 0);
  5095. if (handle != 0)
  5096. {
  5097. do
  5098. {
  5099. if (fileTypeMatches (whatToLookFor, itemIsDirectory, itemIsHidden)
  5100. && ! filename.containsOnly (T(".")))
  5101. {
  5102. ++count;
  5103. }
  5104. } while (juce_findFileNext (handle, filename, &itemIsDirectory, &itemIsHidden, 0, 0, 0, 0));
  5105. juce_findFileClose (handle);
  5106. }
  5107. }
  5108. else
  5109. {
  5110. // trying to search for files inside a non-directory?
  5111. jassertfalse
  5112. }
  5113. return count;
  5114. }
  5115. bool File::containsSubDirectories() const
  5116. {
  5117. bool result = false;
  5118. if (isDirectory())
  5119. {
  5120. String filename;
  5121. bool itemIsDirectory, itemIsHidden;
  5122. void* const handle = juce_findFileStart (juce_addTrailingSeparator (fullPath),
  5123. T("*"), filename,
  5124. &itemIsDirectory, &itemIsHidden, 0, 0, 0, 0);
  5125. if (handle != 0)
  5126. {
  5127. do
  5128. {
  5129. if (itemIsDirectory)
  5130. {
  5131. result = true;
  5132. break;
  5133. }
  5134. } while (juce_findFileNext (handle, filename, &itemIsDirectory, &itemIsHidden, 0, 0, 0, 0));
  5135. juce_findFileClose (handle);
  5136. }
  5137. }
  5138. return result;
  5139. }
  5140. const File File::getNonexistentChildFile (const String& prefix_,
  5141. const String& suffix,
  5142. bool putNumbersInBrackets) const
  5143. {
  5144. File f (getChildFile (prefix_ + suffix));
  5145. if (f.exists())
  5146. {
  5147. int num = 2;
  5148. String prefix (prefix_);
  5149. // remove any bracketed numbers that may already be on the end..
  5150. if (prefix.trim().endsWithChar (T(')')))
  5151. {
  5152. putNumbersInBrackets = true;
  5153. const int openBracks = prefix.lastIndexOfChar (T('('));
  5154. const int closeBracks = prefix.lastIndexOfChar (T(')'));
  5155. if (openBracks > 0
  5156. && closeBracks > openBracks
  5157. && prefix.substring (openBracks + 1, closeBracks).containsOnly (T("0123456789")))
  5158. {
  5159. num = prefix.substring (openBracks + 1, closeBracks).getIntValue() + 1;
  5160. prefix = prefix.substring (0, openBracks);
  5161. }
  5162. }
  5163. // also use brackets if it ends in a digit.
  5164. putNumbersInBrackets = putNumbersInBrackets
  5165. || CharacterFunctions::isDigit (prefix.getLastCharacter());
  5166. do
  5167. {
  5168. if (putNumbersInBrackets)
  5169. f = getChildFile (prefix + T('(') + String (num++) + T(')') + suffix);
  5170. else
  5171. f = getChildFile (prefix + String (num++) + suffix);
  5172. } while (f.exists());
  5173. }
  5174. return f;
  5175. }
  5176. const File File::getNonexistentSibling (const bool putNumbersInBrackets) const
  5177. {
  5178. if (exists())
  5179. {
  5180. return getParentDirectory()
  5181. .getNonexistentChildFile (getFileNameWithoutExtension(),
  5182. getFileExtension(),
  5183. putNumbersInBrackets);
  5184. }
  5185. else
  5186. {
  5187. return *this;
  5188. }
  5189. }
  5190. const String File::getFileExtension() const
  5191. {
  5192. String ext;
  5193. if (! isDirectory())
  5194. {
  5195. const int indexOfDot = fullPath.lastIndexOfChar (T('.'));
  5196. if (indexOfDot > fullPath.lastIndexOfChar (separator))
  5197. ext = fullPath.substring (indexOfDot);
  5198. }
  5199. return ext;
  5200. }
  5201. bool File::hasFileExtension (const String& possibleSuffix) const
  5202. {
  5203. if (possibleSuffix.isEmpty())
  5204. return fullPath.lastIndexOfChar (T('.')) <= fullPath.lastIndexOfChar (separator);
  5205. const int semicolon = possibleSuffix.indexOfChar (0, T(';'));
  5206. if (semicolon >= 0)
  5207. {
  5208. return hasFileExtension (possibleSuffix.substring (0, semicolon).trimEnd())
  5209. || hasFileExtension (possibleSuffix.substring (semicolon + 1).trimStart());
  5210. }
  5211. else
  5212. {
  5213. if (fullPath.endsWithIgnoreCase (possibleSuffix))
  5214. {
  5215. if (possibleSuffix.startsWithChar (T('.')))
  5216. return true;
  5217. const int dotPos = fullPath.length() - possibleSuffix.length() - 1;
  5218. if (dotPos >= 0)
  5219. return fullPath [dotPos] == T('.');
  5220. }
  5221. }
  5222. return false;
  5223. }
  5224. const File File::withFileExtension (const String& newExtension) const
  5225. {
  5226. if (fullPath.isEmpty())
  5227. return File::nonexistent;
  5228. String filePart (getFileName());
  5229. int i = filePart.lastIndexOfChar (T('.'));
  5230. if (i < 0)
  5231. i = filePart.length();
  5232. String newExt (newExtension);
  5233. if (newExt.isNotEmpty() && ! newExt.startsWithChar (T('.')))
  5234. newExt = T(".") + newExt;
  5235. return getSiblingFile (filePart.substring (0, i) + newExt);
  5236. }
  5237. bool File::startAsProcess (const String& parameters) const
  5238. {
  5239. return exists()
  5240. && juce_launchFile (fullPath, parameters);
  5241. }
  5242. FileInputStream* File::createInputStream() const
  5243. {
  5244. if (existsAsFile())
  5245. return new FileInputStream (*this);
  5246. else
  5247. return 0;
  5248. }
  5249. FileOutputStream* File::createOutputStream (const int bufferSize) const
  5250. {
  5251. ScopedPointer <FileOutputStream> out (new FileOutputStream (*this, bufferSize));
  5252. if (out->failedToOpen())
  5253. return 0;
  5254. return out.release();
  5255. }
  5256. bool File::appendData (const void* const dataToAppend,
  5257. const int numberOfBytes) const
  5258. {
  5259. if (numberOfBytes > 0)
  5260. {
  5261. const ScopedPointer <FileOutputStream> out (createOutputStream());
  5262. if (out == 0)
  5263. return false;
  5264. out->write (dataToAppend, numberOfBytes);
  5265. }
  5266. return true;
  5267. }
  5268. bool File::replaceWithData (const void* const dataToWrite,
  5269. const int numberOfBytes) const
  5270. {
  5271. jassert (numberOfBytes >= 0); // a negative number of bytes??
  5272. if (numberOfBytes <= 0)
  5273. return deleteFile();
  5274. TemporaryFile tempFile (*this, TemporaryFile::useHiddenFile);
  5275. tempFile.getFile().appendData (dataToWrite, numberOfBytes);
  5276. return tempFile.overwriteTargetFileWithTemporary();
  5277. }
  5278. bool File::appendText (const String& text,
  5279. const bool asUnicode,
  5280. const bool writeUnicodeHeaderBytes) const
  5281. {
  5282. const ScopedPointer <FileOutputStream> out (createOutputStream());
  5283. if (out != 0)
  5284. {
  5285. out->writeText (text, asUnicode, writeUnicodeHeaderBytes);
  5286. return true;
  5287. }
  5288. return false;
  5289. }
  5290. bool File::replaceWithText (const String& textToWrite,
  5291. const bool asUnicode,
  5292. const bool writeUnicodeHeaderBytes) const
  5293. {
  5294. TemporaryFile tempFile (*this, TemporaryFile::useHiddenFile);
  5295. tempFile.getFile().appendText (textToWrite, asUnicode, writeUnicodeHeaderBytes);
  5296. return tempFile.overwriteTargetFileWithTemporary();
  5297. }
  5298. const String File::createLegalPathName (const String& original)
  5299. {
  5300. String s (original);
  5301. String start;
  5302. if (s[1] == T(':'))
  5303. {
  5304. start = s.substring (0, 2);
  5305. s = s.substring (2);
  5306. }
  5307. return start + s.removeCharacters (T("\"#@,;:<>*^|?"))
  5308. .substring (0, 1024);
  5309. }
  5310. const String File::createLegalFileName (const String& original)
  5311. {
  5312. String s (original.removeCharacters (T("\"#@,;:<>*^|?\\/")));
  5313. const int maxLength = 128; // only the length of the filename, not the whole path
  5314. const int len = s.length();
  5315. if (len > maxLength)
  5316. {
  5317. const int lastDot = s.lastIndexOfChar (T('.'));
  5318. if (lastDot > jmax (0, len - 12))
  5319. {
  5320. s = s.substring (0, maxLength - (len - lastDot))
  5321. + s.substring (lastDot);
  5322. }
  5323. else
  5324. {
  5325. s = s.substring (0, maxLength);
  5326. }
  5327. }
  5328. return s;
  5329. }
  5330. const String File::getRelativePathFrom (const File& dir) const
  5331. {
  5332. String thisPath (fullPath);
  5333. {
  5334. int len = thisPath.length();
  5335. while (--len >= 0 && thisPath [len] == File::separator)
  5336. thisPath [len] = 0;
  5337. }
  5338. String dirPath (juce_addTrailingSeparator ((dir.existsAsFile()) ? dir.getParentDirectory().getFullPathName()
  5339. : dir.fullPath));
  5340. const int len = jmin (thisPath.length(), dirPath.length());
  5341. int commonBitLength = 0;
  5342. for (int i = 0; i < len; ++i)
  5343. {
  5344. #if NAMES_ARE_CASE_SENSITIVE
  5345. if (thisPath[i] != dirPath[i])
  5346. #else
  5347. if (CharacterFunctions::toLowerCase (thisPath[i])
  5348. != CharacterFunctions::toLowerCase (dirPath[i]))
  5349. #endif
  5350. {
  5351. break;
  5352. }
  5353. ++commonBitLength;
  5354. }
  5355. while (commonBitLength > 0 && thisPath [commonBitLength - 1] != File::separator)
  5356. --commonBitLength;
  5357. // if the only common bit is the root, then just return the full path..
  5358. if (commonBitLength <= 0
  5359. || (commonBitLength == 1 && thisPath [1] == File::separator))
  5360. return fullPath;
  5361. thisPath = thisPath.substring (commonBitLength);
  5362. dirPath = dirPath.substring (commonBitLength);
  5363. while (dirPath.isNotEmpty())
  5364. {
  5365. #if JUCE_WINDOWS
  5366. thisPath = T("..\\") + thisPath;
  5367. #else
  5368. thisPath = T("../") + thisPath;
  5369. #endif
  5370. const int sep = dirPath.indexOfChar (separator);
  5371. if (sep >= 0)
  5372. dirPath = dirPath.substring (sep + 1);
  5373. else
  5374. dirPath = String::empty;
  5375. }
  5376. return thisPath;
  5377. }
  5378. void File::findFileSystemRoots (Array<File>& destArray)
  5379. {
  5380. const StringArray roots (juce_getFileSystemRoots());
  5381. for (int i = 0; i < roots.size(); ++i)
  5382. destArray.add (File (roots[i]));
  5383. }
  5384. const String File::getVolumeLabel() const
  5385. {
  5386. int serialNum;
  5387. return juce_getVolumeLabel (fullPath, serialNum);
  5388. }
  5389. int File::getVolumeSerialNumber() const
  5390. {
  5391. int serialNum;
  5392. juce_getVolumeLabel (fullPath, serialNum);
  5393. return serialNum;
  5394. }
  5395. const File File::createTempFile (const String& fileNameEnding)
  5396. {
  5397. const File tempFile (getSpecialLocation (tempDirectory)
  5398. .getChildFile (T("temp_") + String (Random::getSystemRandom().nextInt()))
  5399. .withFileExtension (fileNameEnding));
  5400. if (tempFile.exists())
  5401. return createTempFile (fileNameEnding);
  5402. else
  5403. return tempFile;
  5404. }
  5405. END_JUCE_NAMESPACE
  5406. /*** End of inlined file: juce_File.cpp ***/
  5407. /*** Start of inlined file: juce_FileInputStream.cpp ***/
  5408. BEGIN_JUCE_NAMESPACE
  5409. void* juce_fileOpen (const String& path, bool forWriting);
  5410. void juce_fileClose (void* handle);
  5411. int juce_fileRead (void* handle, void* buffer, int size);
  5412. int64 juce_fileSetPosition (void* handle, int64 pos);
  5413. FileInputStream::FileInputStream (const File& f)
  5414. : file (f),
  5415. currentPosition (0),
  5416. needToSeek (true)
  5417. {
  5418. totalSize = f.getSize();
  5419. fileHandle = juce_fileOpen (f.getFullPathName(), false);
  5420. }
  5421. FileInputStream::~FileInputStream()
  5422. {
  5423. juce_fileClose (fileHandle);
  5424. }
  5425. int64 FileInputStream::getTotalLength()
  5426. {
  5427. return totalSize;
  5428. }
  5429. int FileInputStream::read (void* buffer, int bytesToRead)
  5430. {
  5431. int num = 0;
  5432. if (needToSeek)
  5433. {
  5434. if (juce_fileSetPosition (fileHandle, currentPosition) < 0)
  5435. return 0;
  5436. needToSeek = false;
  5437. }
  5438. num = juce_fileRead (fileHandle, buffer, bytesToRead);
  5439. currentPosition += num;
  5440. return num;
  5441. }
  5442. bool FileInputStream::isExhausted()
  5443. {
  5444. return currentPosition >= totalSize;
  5445. }
  5446. int64 FileInputStream::getPosition()
  5447. {
  5448. return currentPosition;
  5449. }
  5450. bool FileInputStream::setPosition (int64 pos)
  5451. {
  5452. pos = jlimit ((int64) 0, totalSize, pos);
  5453. needToSeek |= (currentPosition != pos);
  5454. currentPosition = pos;
  5455. return true;
  5456. }
  5457. END_JUCE_NAMESPACE
  5458. /*** End of inlined file: juce_FileInputStream.cpp ***/
  5459. /*** Start of inlined file: juce_FileOutputStream.cpp ***/
  5460. BEGIN_JUCE_NAMESPACE
  5461. void* juce_fileOpen (const String& path, bool forWriting);
  5462. void juce_fileClose (void* handle);
  5463. int juce_fileWrite (void* handle, const void* buffer, int size);
  5464. void juce_fileFlush (void* handle);
  5465. int64 juce_fileGetPosition (void* handle);
  5466. int64 juce_fileSetPosition (void* handle, int64 pos);
  5467. FileOutputStream::FileOutputStream (const File& f,
  5468. const int bufferSize_)
  5469. : file (f),
  5470. bufferSize (bufferSize_),
  5471. bytesInBuffer (0)
  5472. {
  5473. fileHandle = juce_fileOpen (f.getFullPathName(), true);
  5474. if (fileHandle != 0)
  5475. {
  5476. currentPosition = juce_fileGetPosition (fileHandle);
  5477. if (currentPosition < 0)
  5478. {
  5479. jassertfalse
  5480. juce_fileClose (fileHandle);
  5481. fileHandle = 0;
  5482. }
  5483. }
  5484. buffer.malloc (jmax (bufferSize_, 16));
  5485. }
  5486. FileOutputStream::~FileOutputStream()
  5487. {
  5488. flush();
  5489. juce_fileClose (fileHandle);
  5490. }
  5491. int64 FileOutputStream::getPosition()
  5492. {
  5493. return currentPosition;
  5494. }
  5495. bool FileOutputStream::setPosition (int64 newPosition)
  5496. {
  5497. if (newPosition != currentPosition)
  5498. {
  5499. flush();
  5500. currentPosition = juce_fileSetPosition (fileHandle, newPosition);
  5501. }
  5502. return newPosition == currentPosition;
  5503. }
  5504. void FileOutputStream::flush()
  5505. {
  5506. if (bytesInBuffer > 0)
  5507. {
  5508. juce_fileWrite (fileHandle, buffer, bytesInBuffer);
  5509. bytesInBuffer = 0;
  5510. }
  5511. juce_fileFlush (fileHandle);
  5512. }
  5513. bool FileOutputStream::write (const void* const src, const int numBytes)
  5514. {
  5515. if (bytesInBuffer + numBytes < bufferSize)
  5516. {
  5517. memcpy (buffer + bytesInBuffer, src, numBytes);
  5518. bytesInBuffer += numBytes;
  5519. currentPosition += numBytes;
  5520. }
  5521. else
  5522. {
  5523. if (bytesInBuffer > 0)
  5524. {
  5525. // flush the reservoir
  5526. const bool wroteOk = (juce_fileWrite (fileHandle, buffer, bytesInBuffer) == bytesInBuffer);
  5527. bytesInBuffer = 0;
  5528. if (! wroteOk)
  5529. return false;
  5530. }
  5531. if (numBytes < bufferSize)
  5532. {
  5533. memcpy (buffer + bytesInBuffer, src, numBytes);
  5534. bytesInBuffer += numBytes;
  5535. currentPosition += numBytes;
  5536. }
  5537. else
  5538. {
  5539. const int bytesWritten = juce_fileWrite (fileHandle, src, numBytes);
  5540. currentPosition += bytesWritten;
  5541. return bytesWritten == numBytes;
  5542. }
  5543. }
  5544. return true;
  5545. }
  5546. END_JUCE_NAMESPACE
  5547. /*** End of inlined file: juce_FileOutputStream.cpp ***/
  5548. /*** Start of inlined file: juce_FileSearchPath.cpp ***/
  5549. BEGIN_JUCE_NAMESPACE
  5550. FileSearchPath::FileSearchPath()
  5551. {
  5552. }
  5553. FileSearchPath::FileSearchPath (const String& path)
  5554. {
  5555. init (path);
  5556. }
  5557. FileSearchPath::FileSearchPath (const FileSearchPath& other)
  5558. : directories (other.directories)
  5559. {
  5560. }
  5561. FileSearchPath::~FileSearchPath()
  5562. {
  5563. }
  5564. FileSearchPath& FileSearchPath::operator= (const String& path)
  5565. {
  5566. init (path);
  5567. return *this;
  5568. }
  5569. void FileSearchPath::init (const String& path)
  5570. {
  5571. directories.clear();
  5572. directories.addTokens (path, T(";"), T("\""));
  5573. directories.trim();
  5574. directories.removeEmptyStrings();
  5575. for (int i = directories.size(); --i >= 0;)
  5576. directories.set (i, directories[i].unquoted());
  5577. }
  5578. int FileSearchPath::getNumPaths() const
  5579. {
  5580. return directories.size();
  5581. }
  5582. const File FileSearchPath::operator[] (const int index) const
  5583. {
  5584. return File (directories [index]);
  5585. }
  5586. const String FileSearchPath::toString() const
  5587. {
  5588. StringArray directories2 (directories);
  5589. for (int i = directories2.size(); --i >= 0;)
  5590. if (directories2[i].containsChar (T(';')))
  5591. directories2.set (i, directories2[i].quoted());
  5592. return directories2.joinIntoString (T(";"));
  5593. }
  5594. void FileSearchPath::add (const File& dir, const int insertIndex)
  5595. {
  5596. directories.insert (insertIndex, dir.getFullPathName());
  5597. }
  5598. void FileSearchPath::addIfNotAlreadyThere (const File& dir)
  5599. {
  5600. for (int i = 0; i < directories.size(); ++i)
  5601. if (File (directories[i]) == dir)
  5602. return;
  5603. add (dir);
  5604. }
  5605. void FileSearchPath::remove (const int index)
  5606. {
  5607. directories.remove (index);
  5608. }
  5609. void FileSearchPath::addPath (const FileSearchPath& other)
  5610. {
  5611. for (int i = 0; i < other.getNumPaths(); ++i)
  5612. addIfNotAlreadyThere (other[i]);
  5613. }
  5614. void FileSearchPath::removeRedundantPaths()
  5615. {
  5616. for (int i = directories.size(); --i >= 0;)
  5617. {
  5618. const File d1 (directories[i]);
  5619. for (int j = directories.size(); --j >= 0;)
  5620. {
  5621. const File d2 (directories[j]);
  5622. if ((i != j) && (d1.isAChildOf (d2) || d1 == d2))
  5623. {
  5624. directories.remove (i);
  5625. break;
  5626. }
  5627. }
  5628. }
  5629. }
  5630. void FileSearchPath::removeNonExistentPaths()
  5631. {
  5632. for (int i = directories.size(); --i >= 0;)
  5633. if (! File (directories[i]).isDirectory())
  5634. directories.remove (i);
  5635. }
  5636. int FileSearchPath::findChildFiles (Array<File>& results,
  5637. const int whatToLookFor,
  5638. const bool searchRecursively,
  5639. const String& wildCardPattern) const
  5640. {
  5641. int total = 0;
  5642. for (int i = 0; i < directories.size(); ++i)
  5643. total += operator[] (i).findChildFiles (results,
  5644. whatToLookFor,
  5645. searchRecursively,
  5646. wildCardPattern);
  5647. return total;
  5648. }
  5649. bool FileSearchPath::isFileInPath (const File& fileToCheck,
  5650. const bool checkRecursively) const
  5651. {
  5652. for (int i = directories.size(); --i >= 0;)
  5653. {
  5654. const File d (directories[i]);
  5655. if (checkRecursively)
  5656. {
  5657. if (fileToCheck.isAChildOf (d))
  5658. return true;
  5659. }
  5660. else
  5661. {
  5662. if (fileToCheck.getParentDirectory() == d)
  5663. return true;
  5664. }
  5665. }
  5666. return false;
  5667. }
  5668. END_JUCE_NAMESPACE
  5669. /*** End of inlined file: juce_FileSearchPath.cpp ***/
  5670. /*** Start of inlined file: juce_NamedPipe.cpp ***/
  5671. BEGIN_JUCE_NAMESPACE
  5672. NamedPipe::NamedPipe()
  5673. : internal (0)
  5674. {
  5675. }
  5676. NamedPipe::~NamedPipe()
  5677. {
  5678. close();
  5679. }
  5680. bool NamedPipe::openExisting (const String& pipeName)
  5681. {
  5682. currentPipeName = pipeName;
  5683. return openInternal (pipeName, false);
  5684. }
  5685. bool NamedPipe::createNewPipe (const String& pipeName)
  5686. {
  5687. currentPipeName = pipeName;
  5688. return openInternal (pipeName, true);
  5689. }
  5690. bool NamedPipe::isOpen() const
  5691. {
  5692. return internal != 0;
  5693. }
  5694. const String NamedPipe::getName() const
  5695. {
  5696. return currentPipeName;
  5697. }
  5698. // other methods for this class are implemented in the platform-specific files
  5699. END_JUCE_NAMESPACE
  5700. /*** End of inlined file: juce_NamedPipe.cpp ***/
  5701. /*** Start of inlined file: juce_TemporaryFile.cpp ***/
  5702. BEGIN_JUCE_NAMESPACE
  5703. TemporaryFile::TemporaryFile (const String& suffix, const int optionFlags)
  5704. {
  5705. createTempFile (File::getSpecialLocation (File::tempDirectory),
  5706. T("temp_") + String (Random::getSystemRandom().nextInt()),
  5707. suffix,
  5708. optionFlags);
  5709. }
  5710. TemporaryFile::TemporaryFile (const File& targetFile_, const int optionFlags)
  5711. : targetFile (targetFile_)
  5712. {
  5713. // If you use this constructor, you need to give it a valid target file!
  5714. jassert (targetFile != File::nonexistent);
  5715. createTempFile (targetFile.getParentDirectory(),
  5716. targetFile.getFileNameWithoutExtension() + T("_temp") + String (Random::getSystemRandom().nextInt()),
  5717. targetFile.getFileExtension(),
  5718. optionFlags);
  5719. }
  5720. void TemporaryFile::createTempFile (const File& parentDirectory, String name,
  5721. const String& suffix, const int optionFlags)
  5722. {
  5723. if ((optionFlags & useHiddenFile) != 0)
  5724. name = T(".") + name;
  5725. temporaryFile = parentDirectory.getNonexistentChildFile (name, suffix, (optionFlags & putNumbersInBrackets) != 0);
  5726. }
  5727. TemporaryFile::~TemporaryFile()
  5728. {
  5729. // Have a few attempts at deleting the file before giving up..
  5730. for (int i = 5; --i >= 0;)
  5731. {
  5732. if (temporaryFile.deleteFile())
  5733. return;
  5734. Thread::sleep (50);
  5735. }
  5736. // Failed to delete our temporary file! Check that you've deleted all the
  5737. // file output streams that were using it!
  5738. jassertfalse;
  5739. }
  5740. bool TemporaryFile::overwriteTargetFileWithTemporary() const
  5741. {
  5742. // This method only works if you created this object with the constructor
  5743. // that takes a target file!
  5744. jassert (targetFile != File::nonexistent);
  5745. if (temporaryFile.exists())
  5746. {
  5747. // Have a few attempts at overwriting the file before giving up..
  5748. for (int i = 5; --i >= 0;)
  5749. {
  5750. if (temporaryFile.moveFileTo (targetFile))
  5751. return true;
  5752. Thread::sleep (100);
  5753. }
  5754. }
  5755. else
  5756. {
  5757. // There's no temporary file to use. If your write failed, you should
  5758. // probably check, and not bother calling this method.
  5759. jassertfalse
  5760. }
  5761. return false;
  5762. }
  5763. END_JUCE_NAMESPACE
  5764. /*** End of inlined file: juce_TemporaryFile.cpp ***/
  5765. /*** Start of inlined file: juce_Socket.cpp ***/
  5766. #if JUCE_WINDOWS
  5767. #include <winsock2.h>
  5768. #ifdef _MSC_VER
  5769. #pragma warning (disable : 4127 4389 4018)
  5770. #endif
  5771. #else
  5772. #if JUCE_LINUX
  5773. #include <sys/types.h>
  5774. #include <sys/socket.h>
  5775. #include <sys/errno.h>
  5776. #include <unistd.h>
  5777. #include <netinet/in.h>
  5778. #elif (MACOSX_DEPLOYMENT_TARGET <= MAC_OS_X_VERSION_10_4) && ! JUCE_IPHONE
  5779. #include <CoreServices/CoreServices.h>
  5780. #endif
  5781. #include <fcntl.h>
  5782. #include <netdb.h>
  5783. #include <arpa/inet.h>
  5784. #include <netinet/tcp.h>
  5785. #endif
  5786. BEGIN_JUCE_NAMESPACE
  5787. #if defined (JUCE_LINUX) || defined (JUCE_MAC) || defined (JUCE_IPHONE)
  5788. typedef socklen_t juce_socklen_t;
  5789. #else
  5790. typedef int juce_socklen_t;
  5791. #endif
  5792. #if JUCE_WINDOWS
  5793. typedef int (__stdcall juce_CloseWin32SocketLibCall) (void);
  5794. juce_CloseWin32SocketLibCall* juce_CloseWin32SocketLib = 0;
  5795. static void initWin32Sockets()
  5796. {
  5797. static CriticalSection lock;
  5798. const ScopedLock sl (lock);
  5799. if (juce_CloseWin32SocketLib == 0)
  5800. {
  5801. WSADATA wsaData;
  5802. const WORD wVersionRequested = MAKEWORD (1, 1);
  5803. WSAStartup (wVersionRequested, &wsaData);
  5804. juce_CloseWin32SocketLib = &WSACleanup;
  5805. }
  5806. }
  5807. #endif
  5808. static bool resetSocketOptions (const int handle, const bool isDatagram, const bool allowBroadcast) throw()
  5809. {
  5810. const int sndBufSize = 65536;
  5811. const int rcvBufSize = 65536;
  5812. const int one = 1;
  5813. return handle > 0
  5814. && setsockopt (handle, SOL_SOCKET, SO_RCVBUF, (const char*) &rcvBufSize, sizeof (rcvBufSize)) == 0
  5815. && setsockopt (handle, SOL_SOCKET, SO_SNDBUF, (const char*) &sndBufSize, sizeof (sndBufSize)) == 0
  5816. && (isDatagram ? ((! allowBroadcast) || setsockopt (handle, SOL_SOCKET, SO_BROADCAST, (const char*) &one, sizeof (one)) == 0)
  5817. : (setsockopt (handle, IPPROTO_TCP, TCP_NODELAY, (const char*) &one, sizeof (one)) == 0));
  5818. }
  5819. static bool bindSocketToPort (const int handle, const int port) throw()
  5820. {
  5821. if (handle <= 0 || port <= 0)
  5822. return false;
  5823. struct sockaddr_in servTmpAddr;
  5824. zerostruct (servTmpAddr);
  5825. servTmpAddr.sin_family = PF_INET;
  5826. servTmpAddr.sin_addr.s_addr = htonl (INADDR_ANY);
  5827. servTmpAddr.sin_port = htons ((uint16) port);
  5828. return bind (handle, (struct sockaddr*) &servTmpAddr, sizeof (struct sockaddr_in)) >= 0;
  5829. }
  5830. static int readSocket (const int handle,
  5831. void* const destBuffer, const int maxBytesToRead,
  5832. bool volatile& connected,
  5833. const bool blockUntilSpecifiedAmountHasArrived) throw()
  5834. {
  5835. int bytesRead = 0;
  5836. while (bytesRead < maxBytesToRead)
  5837. {
  5838. int bytesThisTime;
  5839. #if JUCE_WINDOWS
  5840. bytesThisTime = recv (handle, ((char*) destBuffer) + bytesRead, maxBytesToRead - bytesRead, 0);
  5841. #else
  5842. while ((bytesThisTime = (int) ::read (handle, ((char*) destBuffer) + bytesRead, maxBytesToRead - bytesRead)) < 0
  5843. && errno == EINTR
  5844. && connected)
  5845. {
  5846. }
  5847. #endif
  5848. if (bytesThisTime <= 0 || ! connected)
  5849. {
  5850. if (bytesRead == 0)
  5851. bytesRead = -1;
  5852. break;
  5853. }
  5854. bytesRead += bytesThisTime;
  5855. if (! blockUntilSpecifiedAmountHasArrived)
  5856. break;
  5857. }
  5858. return bytesRead;
  5859. }
  5860. static int waitForReadiness (const int handle, const bool forReading,
  5861. const int timeoutMsecs) throw()
  5862. {
  5863. struct timeval timeout;
  5864. struct timeval* timeoutp;
  5865. if (timeoutMsecs >= 0)
  5866. {
  5867. timeout.tv_sec = timeoutMsecs / 1000;
  5868. timeout.tv_usec = (timeoutMsecs % 1000) * 1000;
  5869. timeoutp = &timeout;
  5870. }
  5871. else
  5872. {
  5873. timeoutp = 0;
  5874. }
  5875. fd_set rset, wset;
  5876. FD_ZERO (&rset);
  5877. FD_SET (handle, &rset);
  5878. FD_ZERO (&wset);
  5879. FD_SET (handle, &wset);
  5880. fd_set* const prset = forReading ? &rset : 0;
  5881. fd_set* const pwset = forReading ? 0 : &wset;
  5882. #if JUCE_WINDOWS
  5883. if (select (handle + 1, prset, pwset, 0, timeoutp) < 0)
  5884. return -1;
  5885. #else
  5886. {
  5887. int result;
  5888. while ((result = select (handle + 1, prset, pwset, 0, timeoutp)) < 0
  5889. && errno == EINTR)
  5890. {
  5891. }
  5892. if (result < 0)
  5893. return -1;
  5894. }
  5895. #endif
  5896. {
  5897. int opt;
  5898. juce_socklen_t len = sizeof (opt);
  5899. if (getsockopt (handle, SOL_SOCKET, SO_ERROR, (char*) &opt, &len) < 0
  5900. || opt != 0)
  5901. return -1;
  5902. }
  5903. if ((forReading && FD_ISSET (handle, &rset))
  5904. || ((! forReading) && FD_ISSET (handle, &wset)))
  5905. return 1;
  5906. return 0;
  5907. }
  5908. static bool setSocketBlockingState (const int handle, const bool shouldBlock) throw()
  5909. {
  5910. #if JUCE_WINDOWS
  5911. u_long nonBlocking = shouldBlock ? 0 : 1;
  5912. if (ioctlsocket (handle, FIONBIO, &nonBlocking) != 0)
  5913. return false;
  5914. #else
  5915. int socketFlags = fcntl (handle, F_GETFL, 0);
  5916. if (socketFlags == -1)
  5917. return false;
  5918. if (shouldBlock)
  5919. socketFlags &= ~O_NONBLOCK;
  5920. else
  5921. socketFlags |= O_NONBLOCK;
  5922. if (fcntl (handle, F_SETFL, socketFlags) != 0)
  5923. return false;
  5924. #endif
  5925. return true;
  5926. }
  5927. static bool connectSocket (int volatile& handle,
  5928. const bool isDatagram,
  5929. void** serverAddress,
  5930. const String& hostName,
  5931. const int portNumber,
  5932. const int timeOutMillisecs) throw()
  5933. {
  5934. struct hostent* const hostEnt = gethostbyname (hostName.toUTF8());
  5935. if (hostEnt == 0)
  5936. return false;
  5937. struct in_addr targetAddress;
  5938. memcpy (&targetAddress.s_addr,
  5939. *(hostEnt->h_addr_list),
  5940. sizeof (targetAddress.s_addr));
  5941. struct sockaddr_in servTmpAddr;
  5942. zerostruct (servTmpAddr);
  5943. servTmpAddr.sin_family = PF_INET;
  5944. servTmpAddr.sin_addr = targetAddress;
  5945. servTmpAddr.sin_port = htons ((uint16) portNumber);
  5946. if (handle < 0)
  5947. handle = (int) socket (AF_INET, isDatagram ? SOCK_DGRAM : SOCK_STREAM, 0);
  5948. if (handle < 0)
  5949. return false;
  5950. if (isDatagram)
  5951. {
  5952. *serverAddress = new struct sockaddr_in();
  5953. *((struct sockaddr_in*) *serverAddress) = servTmpAddr;
  5954. return true;
  5955. }
  5956. setSocketBlockingState (handle, false);
  5957. const int result = ::connect (handle, (struct sockaddr*) &servTmpAddr, sizeof (struct sockaddr_in));
  5958. if (result < 0)
  5959. {
  5960. #if JUCE_WINDOWS
  5961. if (result == SOCKET_ERROR && WSAGetLastError() == WSAEWOULDBLOCK)
  5962. #else
  5963. if (errno == EINPROGRESS)
  5964. #endif
  5965. {
  5966. if (waitForReadiness (handle, false, timeOutMillisecs) != 1)
  5967. {
  5968. setSocketBlockingState (handle, true);
  5969. return false;
  5970. }
  5971. }
  5972. }
  5973. setSocketBlockingState (handle, true);
  5974. resetSocketOptions (handle, false, false);
  5975. return true;
  5976. }
  5977. StreamingSocket::StreamingSocket()
  5978. : portNumber (0),
  5979. handle (-1),
  5980. connected (false),
  5981. isListener (false)
  5982. {
  5983. #if JUCE_WINDOWS
  5984. initWin32Sockets();
  5985. #endif
  5986. }
  5987. StreamingSocket::StreamingSocket (const String& hostName_,
  5988. const int portNumber_,
  5989. const int handle_)
  5990. : hostName (hostName_),
  5991. portNumber (portNumber_),
  5992. handle (handle_),
  5993. connected (true),
  5994. isListener (false)
  5995. {
  5996. #if JUCE_WINDOWS
  5997. initWin32Sockets();
  5998. #endif
  5999. resetSocketOptions (handle_, false, false);
  6000. }
  6001. StreamingSocket::~StreamingSocket()
  6002. {
  6003. close();
  6004. }
  6005. int StreamingSocket::read (void* destBuffer, const int maxBytesToRead, const bool blockUntilSpecifiedAmountHasArrived)
  6006. {
  6007. return (connected && ! isListener) ? readSocket (handle, destBuffer, maxBytesToRead, connected, blockUntilSpecifiedAmountHasArrived)
  6008. : -1;
  6009. }
  6010. int StreamingSocket::write (const void* sourceBuffer, const int numBytesToWrite)
  6011. {
  6012. if (isListener || ! connected)
  6013. return -1;
  6014. #if JUCE_WINDOWS
  6015. return send (handle, (const char*) sourceBuffer, numBytesToWrite, 0);
  6016. #else
  6017. int result;
  6018. while ((result = (int) ::write (handle, sourceBuffer, numBytesToWrite)) < 0
  6019. && errno == EINTR)
  6020. {
  6021. }
  6022. return result;
  6023. #endif
  6024. }
  6025. int StreamingSocket::waitUntilReady (const bool readyForReading,
  6026. const int timeoutMsecs) const
  6027. {
  6028. return connected ? waitForReadiness (handle, readyForReading, timeoutMsecs)
  6029. : -1;
  6030. }
  6031. bool StreamingSocket::bindToPort (const int port)
  6032. {
  6033. return bindSocketToPort (handle, port);
  6034. }
  6035. bool StreamingSocket::connect (const String& remoteHostName,
  6036. const int remotePortNumber,
  6037. const int timeOutMillisecs)
  6038. {
  6039. if (isListener)
  6040. {
  6041. jassertfalse // a listener socket can't connect to another one!
  6042. return false;
  6043. }
  6044. if (connected)
  6045. close();
  6046. hostName = remoteHostName;
  6047. portNumber = remotePortNumber;
  6048. isListener = false;
  6049. connected = connectSocket (handle, false, 0, remoteHostName,
  6050. remotePortNumber, timeOutMillisecs);
  6051. if (! (connected && resetSocketOptions (handle, false, false)))
  6052. {
  6053. close();
  6054. return false;
  6055. }
  6056. return true;
  6057. }
  6058. void StreamingSocket::close()
  6059. {
  6060. #if JUCE_WINDOWS
  6061. closesocket (handle);
  6062. connected = false;
  6063. #else
  6064. if (connected)
  6065. {
  6066. connected = false;
  6067. if (isListener)
  6068. {
  6069. // need to do this to interrupt the accept() function..
  6070. StreamingSocket temp;
  6071. temp.connect ("localhost", portNumber, 1000);
  6072. }
  6073. }
  6074. ::close (handle);
  6075. #endif
  6076. hostName = String::empty;
  6077. portNumber = 0;
  6078. handle = -1;
  6079. isListener = false;
  6080. }
  6081. bool StreamingSocket::createListener (const int newPortNumber, const String& localHostName)
  6082. {
  6083. if (connected)
  6084. close();
  6085. hostName = "listener";
  6086. portNumber = newPortNumber;
  6087. isListener = true;
  6088. struct sockaddr_in servTmpAddr;
  6089. zerostruct (servTmpAddr);
  6090. servTmpAddr.sin_family = PF_INET;
  6091. servTmpAddr.sin_addr.s_addr = htonl (INADDR_ANY);
  6092. if (localHostName.isNotEmpty())
  6093. servTmpAddr.sin_addr.s_addr = ::inet_addr (localHostName.toUTF8());
  6094. servTmpAddr.sin_port = htons ((uint16) portNumber);
  6095. handle = (int) socket (AF_INET, SOCK_STREAM, 0);
  6096. if (handle < 0)
  6097. return false;
  6098. const int reuse = 1;
  6099. setsockopt (handle, SOL_SOCKET, SO_REUSEADDR, (const char*) &reuse, sizeof (reuse));
  6100. if (bind (handle, (struct sockaddr*) &servTmpAddr, sizeof (struct sockaddr_in)) < 0
  6101. || listen (handle, SOMAXCONN) < 0)
  6102. {
  6103. close();
  6104. return false;
  6105. }
  6106. connected = true;
  6107. return true;
  6108. }
  6109. StreamingSocket* StreamingSocket::waitForNextConnection() const
  6110. {
  6111. jassert (isListener || ! connected); // to call this method, you first have to use createListener() to
  6112. // prepare this socket as a listener.
  6113. if (connected && isListener)
  6114. {
  6115. struct sockaddr address;
  6116. juce_socklen_t len = sizeof (sockaddr);
  6117. const int newSocket = (int) accept (handle, &address, &len);
  6118. if (newSocket >= 0 && connected)
  6119. return new StreamingSocket (inet_ntoa (((struct sockaddr_in*) &address)->sin_addr),
  6120. portNumber, newSocket);
  6121. }
  6122. return 0;
  6123. }
  6124. bool StreamingSocket::isLocal() const throw()
  6125. {
  6126. return hostName == T("127.0.0.1");
  6127. }
  6128. DatagramSocket::DatagramSocket (const int localPortNumber, const bool allowBroadcast_)
  6129. : portNumber (0),
  6130. handle (-1),
  6131. connected (true),
  6132. allowBroadcast (allowBroadcast_),
  6133. serverAddress (0)
  6134. {
  6135. #if JUCE_WINDOWS
  6136. initWin32Sockets();
  6137. #endif
  6138. handle = (int) socket (AF_INET, SOCK_DGRAM, 0);
  6139. bindToPort (localPortNumber);
  6140. }
  6141. DatagramSocket::DatagramSocket (const String& hostName_, const int portNumber_,
  6142. const int handle_, const int localPortNumber)
  6143. : hostName (hostName_),
  6144. portNumber (portNumber_),
  6145. handle (handle_),
  6146. connected (true),
  6147. allowBroadcast (false),
  6148. serverAddress (0)
  6149. {
  6150. #if JUCE_WINDOWS
  6151. initWin32Sockets();
  6152. #endif
  6153. resetSocketOptions (handle_, true, allowBroadcast);
  6154. bindToPort (localPortNumber);
  6155. }
  6156. DatagramSocket::~DatagramSocket()
  6157. {
  6158. close();
  6159. delete ((struct sockaddr_in*) serverAddress);
  6160. serverAddress = 0;
  6161. }
  6162. void DatagramSocket::close()
  6163. {
  6164. #if JUCE_WINDOWS
  6165. closesocket (handle);
  6166. connected = false;
  6167. #else
  6168. connected = false;
  6169. ::close (handle);
  6170. #endif
  6171. hostName = String::empty;
  6172. portNumber = 0;
  6173. handle = -1;
  6174. }
  6175. bool DatagramSocket::bindToPort (const int port)
  6176. {
  6177. return bindSocketToPort (handle, port);
  6178. }
  6179. bool DatagramSocket::connect (const String& remoteHostName,
  6180. const int remotePortNumber,
  6181. const int timeOutMillisecs)
  6182. {
  6183. if (connected)
  6184. close();
  6185. hostName = remoteHostName;
  6186. portNumber = remotePortNumber;
  6187. connected = connectSocket (handle, true, &serverAddress,
  6188. remoteHostName, remotePortNumber,
  6189. timeOutMillisecs);
  6190. if (! (connected && resetSocketOptions (handle, true, allowBroadcast)))
  6191. {
  6192. close();
  6193. return false;
  6194. }
  6195. return true;
  6196. }
  6197. DatagramSocket* DatagramSocket::waitForNextConnection() const
  6198. {
  6199. struct sockaddr address;
  6200. juce_socklen_t len = sizeof (sockaddr);
  6201. while (waitUntilReady (true, -1) == 1)
  6202. {
  6203. char buf[1];
  6204. if (recvfrom (handle, buf, 0, 0, &address, &len) > 0)
  6205. {
  6206. return new DatagramSocket (inet_ntoa (((struct sockaddr_in*) &address)->sin_addr),
  6207. ntohs (((struct sockaddr_in*) &address)->sin_port),
  6208. -1, -1);
  6209. }
  6210. }
  6211. return 0;
  6212. }
  6213. int DatagramSocket::waitUntilReady (const bool readyForReading,
  6214. const int timeoutMsecs) const
  6215. {
  6216. return connected ? waitForReadiness (handle, readyForReading, timeoutMsecs)
  6217. : -1;
  6218. }
  6219. int DatagramSocket::read (void* destBuffer, const int maxBytesToRead, const bool blockUntilSpecifiedAmountHasArrived)
  6220. {
  6221. return connected ? readSocket (handle, destBuffer, maxBytesToRead, connected, blockUntilSpecifiedAmountHasArrived)
  6222. : -1;
  6223. }
  6224. int DatagramSocket::write (const void* sourceBuffer, const int numBytesToWrite)
  6225. {
  6226. // You need to call connect() first to set the server address..
  6227. jassert (serverAddress != 0 && connected);
  6228. return connected ? (int) sendto (handle, (const char*) sourceBuffer,
  6229. numBytesToWrite, 0,
  6230. (const struct sockaddr*) serverAddress,
  6231. sizeof (struct sockaddr_in))
  6232. : -1;
  6233. }
  6234. bool DatagramSocket::isLocal() const throw()
  6235. {
  6236. return hostName == T("127.0.0.1");
  6237. }
  6238. END_JUCE_NAMESPACE
  6239. /*** End of inlined file: juce_Socket.cpp ***/
  6240. /*** Start of inlined file: juce_URL.cpp ***/
  6241. BEGIN_JUCE_NAMESPACE
  6242. URL::URL()
  6243. {
  6244. }
  6245. URL::URL (const String& url_)
  6246. : url (url_)
  6247. {
  6248. int i = url.indexOfChar (T('?'));
  6249. if (i >= 0)
  6250. {
  6251. do
  6252. {
  6253. const int nextAmp = url.indexOfChar (i + 1, T('&'));
  6254. const int equalsPos = url.indexOfChar (i + 1, T('='));
  6255. if (equalsPos > i + 1)
  6256. {
  6257. if (nextAmp < 0)
  6258. {
  6259. parameters.set (removeEscapeChars (url.substring (i + 1, equalsPos)),
  6260. removeEscapeChars (url.substring (equalsPos + 1)));
  6261. }
  6262. else if (nextAmp > 0 && equalsPos < nextAmp)
  6263. {
  6264. parameters.set (removeEscapeChars (url.substring (i + 1, equalsPos)),
  6265. removeEscapeChars (url.substring (equalsPos + 1, nextAmp)));
  6266. }
  6267. }
  6268. i = nextAmp;
  6269. }
  6270. while (i >= 0);
  6271. url = url.upToFirstOccurrenceOf (T("?"), false, false);
  6272. }
  6273. }
  6274. URL::URL (const URL& other)
  6275. : url (other.url),
  6276. postData (other.postData),
  6277. parameters (other.parameters),
  6278. filesToUpload (other.filesToUpload),
  6279. mimeTypes (other.mimeTypes)
  6280. {
  6281. }
  6282. URL& URL::operator= (const URL& other)
  6283. {
  6284. url = other.url;
  6285. postData = other.postData;
  6286. parameters = other.parameters;
  6287. filesToUpload = other.filesToUpload;
  6288. mimeTypes = other.mimeTypes;
  6289. return *this;
  6290. }
  6291. URL::~URL()
  6292. {
  6293. }
  6294. static const String getMangledParameters (const StringPairArray& parameters)
  6295. {
  6296. String p;
  6297. for (int i = 0; i < parameters.size(); ++i)
  6298. {
  6299. if (i > 0)
  6300. p += T("&");
  6301. p << URL::addEscapeChars (parameters.getAllKeys() [i], true)
  6302. << T("=")
  6303. << URL::addEscapeChars (parameters.getAllValues() [i], true);
  6304. }
  6305. return p;
  6306. }
  6307. const String URL::toString (const bool includeGetParameters) const
  6308. {
  6309. if (includeGetParameters && parameters.size() > 0)
  6310. return url + T("?") + getMangledParameters (parameters);
  6311. else
  6312. return url;
  6313. }
  6314. bool URL::isWellFormed() const
  6315. {
  6316. //xxx TODO
  6317. return url.isNotEmpty();
  6318. }
  6319. static int findStartOfDomain (const String& url)
  6320. {
  6321. int i = 0;
  6322. while (CharacterFunctions::isLetterOrDigit (url[i])
  6323. || CharacterFunctions::indexOfChar (T("+-."), url[i], false) >= 0)
  6324. ++i;
  6325. return url[i] == T(':') ? i + 1 : 0;
  6326. }
  6327. const String URL::getDomain() const
  6328. {
  6329. int start = findStartOfDomain (url);
  6330. while (url[start] == T('/'))
  6331. ++start;
  6332. const int end1 = url.indexOfChar (start, T('/'));
  6333. const int end2 = url.indexOfChar (start, T(':'));
  6334. const int end = (end1 < 0 || end2 < 0) ? jmax (end1, end2)
  6335. : jmin (end1, end2);
  6336. return url.substring (start, end);
  6337. }
  6338. const String URL::getSubPath() const
  6339. {
  6340. int start = findStartOfDomain (url);
  6341. while (url[start] == T('/'))
  6342. ++start;
  6343. const int startOfPath = url.indexOfChar (start, T('/')) + 1;
  6344. return startOfPath <= 0 ? String::empty
  6345. : url.substring (startOfPath);
  6346. }
  6347. const String URL::getScheme() const
  6348. {
  6349. return url.substring (0, findStartOfDomain (url) - 1);
  6350. }
  6351. const URL URL::withNewSubPath (const String& newPath) const
  6352. {
  6353. int start = findStartOfDomain (url);
  6354. while (url[start] == T('/'))
  6355. ++start;
  6356. const int startOfPath = url.indexOfChar (start, T('/')) + 1;
  6357. URL u (*this);
  6358. if (startOfPath > 0)
  6359. u.url = url.substring (0, startOfPath);
  6360. if (! u.url.endsWithChar (T('/')))
  6361. u.url << '/';
  6362. if (newPath.startsWithChar (T('/')))
  6363. u.url << newPath.substring (1);
  6364. else
  6365. u.url << newPath;
  6366. return u;
  6367. }
  6368. bool URL::isProbablyAWebsiteURL (const String& possibleURL)
  6369. {
  6370. if (possibleURL.startsWithIgnoreCase (T("http:"))
  6371. || possibleURL.startsWithIgnoreCase (T("ftp:")))
  6372. return true;
  6373. if (possibleURL.startsWithIgnoreCase (T("file:"))
  6374. || possibleURL.containsChar (T('@'))
  6375. || possibleURL.endsWithChar (T('.'))
  6376. || (! possibleURL.containsChar (T('.'))))
  6377. return false;
  6378. if (possibleURL.startsWithIgnoreCase (T("www."))
  6379. && possibleURL.substring (5).containsChar (T('.')))
  6380. return true;
  6381. const char* commonTLDs[] = { "com", "net", "org", "uk", "de", "fr", "jp" };
  6382. for (int i = 0; i < numElementsInArray (commonTLDs); ++i)
  6383. if ((possibleURL + T("/")).containsIgnoreCase (T(".") + String (commonTLDs[i]) + T("/")))
  6384. return true;
  6385. return false;
  6386. }
  6387. bool URL::isProbablyAnEmailAddress (const String& possibleEmailAddress)
  6388. {
  6389. const int atSign = possibleEmailAddress.indexOfChar (T('@'));
  6390. return atSign > 0
  6391. && possibleEmailAddress.lastIndexOfChar (T('.')) > (atSign + 1)
  6392. && (! possibleEmailAddress.endsWithChar (T('.')));
  6393. }
  6394. void* juce_openInternetFile (const String& url,
  6395. const String& headers,
  6396. const MemoryBlock& optionalPostData,
  6397. const bool isPost,
  6398. URL::OpenStreamProgressCallback* callback,
  6399. void* callbackContext,
  6400. int timeOutMs);
  6401. void juce_closeInternetFile (void* handle);
  6402. int juce_readFromInternetFile (void* handle, void* dest, int bytesToRead);
  6403. int juce_seekInInternetFile (void* handle, int newPosition);
  6404. int64 juce_getInternetFileContentLength (void* handle);
  6405. class WebInputStream : public InputStream
  6406. {
  6407. public:
  6408. WebInputStream (const URL& url,
  6409. const bool isPost_,
  6410. URL::OpenStreamProgressCallback* const progressCallback_,
  6411. void* const progressCallbackContext_,
  6412. const String& extraHeaders,
  6413. int timeOutMs_)
  6414. : position (0),
  6415. finished (false),
  6416. isPost (isPost_),
  6417. progressCallback (progressCallback_),
  6418. progressCallbackContext (progressCallbackContext_),
  6419. timeOutMs (timeOutMs_)
  6420. {
  6421. server = url.toString (! isPost);
  6422. if (isPost_)
  6423. createHeadersAndPostData (url);
  6424. headers += extraHeaders;
  6425. if (! headers.endsWithChar (T('\n')))
  6426. headers << "\r\n";
  6427. handle = juce_openInternetFile (server, headers, postData, isPost,
  6428. progressCallback_, progressCallbackContext_,
  6429. timeOutMs);
  6430. }
  6431. ~WebInputStream()
  6432. {
  6433. juce_closeInternetFile (handle);
  6434. }
  6435. bool isError() const
  6436. {
  6437. return handle == 0;
  6438. }
  6439. int64 getTotalLength()
  6440. {
  6441. return juce_getInternetFileContentLength (handle);
  6442. }
  6443. bool isExhausted()
  6444. {
  6445. return finished;
  6446. }
  6447. int read (void* dest, int bytes)
  6448. {
  6449. if (finished || isError())
  6450. {
  6451. return 0;
  6452. }
  6453. else
  6454. {
  6455. const int bytesRead = juce_readFromInternetFile (handle, dest, bytes);
  6456. position += bytesRead;
  6457. if (bytesRead == 0)
  6458. finished = true;
  6459. return bytesRead;
  6460. }
  6461. }
  6462. int64 getPosition()
  6463. {
  6464. return position;
  6465. }
  6466. bool setPosition (int64 wantedPos)
  6467. {
  6468. if (wantedPos != position)
  6469. {
  6470. finished = false;
  6471. const int actualPos = juce_seekInInternetFile (handle, (int) wantedPos);
  6472. if (actualPos == wantedPos)
  6473. {
  6474. position = wantedPos;
  6475. }
  6476. else
  6477. {
  6478. if (wantedPos < position)
  6479. {
  6480. juce_closeInternetFile (handle);
  6481. position = 0;
  6482. finished = false;
  6483. handle = juce_openInternetFile (server, headers, postData, isPost,
  6484. progressCallback, progressCallbackContext,
  6485. timeOutMs);
  6486. }
  6487. skipNextBytes (wantedPos - position);
  6488. }
  6489. }
  6490. return true;
  6491. }
  6492. juce_UseDebuggingNewOperator
  6493. private:
  6494. String server, headers;
  6495. MemoryBlock postData;
  6496. int64 position;
  6497. bool finished;
  6498. const bool isPost;
  6499. void* handle;
  6500. URL::OpenStreamProgressCallback* const progressCallback;
  6501. void* const progressCallbackContext;
  6502. const int timeOutMs;
  6503. void createHeadersAndPostData (const URL& url)
  6504. {
  6505. if (url.getFilesToUpload().size() > 0)
  6506. {
  6507. // need to upload some files, so do it as multi-part...
  6508. String boundary (String::toHexString (Random::getSystemRandom().nextInt64()));
  6509. headers << "Content-Type: multipart/form-data; boundary=" << boundary << "\r\n";
  6510. appendUTF8ToPostData ("--" + boundary);
  6511. int i;
  6512. for (i = 0; i < url.getParameters().size(); ++i)
  6513. {
  6514. String s;
  6515. s << "\r\nContent-Disposition: form-data; name=\""
  6516. << url.getParameters().getAllKeys() [i]
  6517. << "\"\r\n\r\n"
  6518. << url.getParameters().getAllValues() [i]
  6519. << "\r\n--"
  6520. << boundary;
  6521. appendUTF8ToPostData (s);
  6522. }
  6523. for (i = 0; i < url.getFilesToUpload().size(); ++i)
  6524. {
  6525. const File f (url.getFilesToUpload().getAllValues() [i]);
  6526. const String paramName (url.getFilesToUpload().getAllKeys() [i]);
  6527. String s;
  6528. s << "\r\nContent-Disposition: form-data; name=\""
  6529. << paramName
  6530. << "\"; filename=\""
  6531. << f.getFileName()
  6532. << "\"\r\n";
  6533. const String mimeType (url.getMimeTypesOfUploadFiles()
  6534. .getValue (paramName, String::empty));
  6535. if (mimeType.isNotEmpty())
  6536. s << "Content-Type: " << mimeType << "\r\n";
  6537. s << "Content-Transfer-Encoding: binary\r\n\r\n";
  6538. appendUTF8ToPostData (s);
  6539. f.loadFileAsData (postData);
  6540. s = "\r\n--" + boundary;
  6541. appendUTF8ToPostData (s);
  6542. }
  6543. appendUTF8ToPostData ("--\r\n");
  6544. }
  6545. else
  6546. {
  6547. appendUTF8ToPostData (getMangledParameters (url.getParameters()));
  6548. appendUTF8ToPostData (url.getPostData());
  6549. // just a short text attachment, so use simple url encoding..
  6550. headers = "Content-Type: application/x-www-form-urlencoded\r\nContent-length: "
  6551. + String ((unsigned int) postData.getSize())
  6552. + "\r\n";
  6553. }
  6554. }
  6555. void appendUTF8ToPostData (const String& text)
  6556. {
  6557. postData.append (text.toUTF8(),
  6558. (int) strlen (text.toUTF8()));
  6559. }
  6560. WebInputStream (const WebInputStream&);
  6561. WebInputStream& operator= (const WebInputStream&);
  6562. };
  6563. InputStream* URL::createInputStream (const bool usePostCommand,
  6564. OpenStreamProgressCallback* const progressCallback,
  6565. void* const progressCallbackContext,
  6566. const String& extraHeaders,
  6567. const int timeOutMs) const
  6568. {
  6569. ScopedPointer <WebInputStream> wi (new WebInputStream (*this, usePostCommand,
  6570. progressCallback, progressCallbackContext,
  6571. extraHeaders,
  6572. timeOutMs));
  6573. return wi->isError() ? 0 : wi.release();
  6574. }
  6575. bool URL::readEntireBinaryStream (MemoryBlock& destData,
  6576. const bool usePostCommand) const
  6577. {
  6578. const ScopedPointer <InputStream> in (createInputStream (usePostCommand));
  6579. if (in != 0)
  6580. {
  6581. in->readIntoMemoryBlock (destData, -1);
  6582. return true;
  6583. }
  6584. return false;
  6585. }
  6586. const String URL::readEntireTextStream (const bool usePostCommand) const
  6587. {
  6588. const ScopedPointer <InputStream> in (createInputStream (usePostCommand));
  6589. if (in != 0)
  6590. return in->readEntireStreamAsString();
  6591. return String::empty;
  6592. }
  6593. XmlElement* URL::readEntireXmlStream (const bool usePostCommand) const
  6594. {
  6595. XmlDocument doc (readEntireTextStream (usePostCommand));
  6596. return doc.getDocumentElement();
  6597. }
  6598. const URL URL::withParameter (const String& parameterName,
  6599. const String& parameterValue) const
  6600. {
  6601. URL u (*this);
  6602. u.parameters.set (parameterName, parameterValue);
  6603. return u;
  6604. }
  6605. const URL URL::withFileToUpload (const String& parameterName,
  6606. const File& fileToUpload,
  6607. const String& mimeType) const
  6608. {
  6609. jassert (mimeType.isNotEmpty()); // You need to supply a mime type!
  6610. URL u (*this);
  6611. u.filesToUpload.set (parameterName, fileToUpload.getFullPathName());
  6612. u.mimeTypes.set (parameterName, mimeType);
  6613. return u;
  6614. }
  6615. const URL URL::withPOSTData (const String& postData_) const
  6616. {
  6617. URL u (*this);
  6618. u.postData = postData_;
  6619. return u;
  6620. }
  6621. const StringPairArray& URL::getParameters() const
  6622. {
  6623. return parameters;
  6624. }
  6625. const StringPairArray& URL::getFilesToUpload() const
  6626. {
  6627. return filesToUpload;
  6628. }
  6629. const StringPairArray& URL::getMimeTypesOfUploadFiles() const
  6630. {
  6631. return mimeTypes;
  6632. }
  6633. const String URL::removeEscapeChars (const String& s)
  6634. {
  6635. const int len = s.length();
  6636. HeapBlock <char> resultUTF8 (len * 4);
  6637. char* r = resultUTF8;
  6638. for (int i = 0; i < len; ++i)
  6639. {
  6640. char c = (char) s[i];
  6641. if (c == 0)
  6642. break;
  6643. if (c == '+')
  6644. {
  6645. c = ' ';
  6646. }
  6647. else if (c == '%')
  6648. {
  6649. c = (char) s.substring (i + 1, i + 3).getHexValue32();
  6650. i += 2;
  6651. }
  6652. *r++ = c;
  6653. }
  6654. return String::fromUTF8 (resultUTF8);
  6655. }
  6656. const String URL::addEscapeChars (const String& s, const bool isParameter)
  6657. {
  6658. String result;
  6659. result.preallocateStorage (s.length() + 8);
  6660. const char* utf8 = s.toUTF8();
  6661. const char* legalChars = isParameter ? "_-.*!'()"
  6662. : "_-$.*!'(),";
  6663. while (*utf8 != 0)
  6664. {
  6665. const char c = *utf8++;
  6666. if (CharacterFunctions::isLetterOrDigit (c)
  6667. || CharacterFunctions::indexOfChar (legalChars, c, false) >= 0)
  6668. {
  6669. result << c;
  6670. }
  6671. else
  6672. {
  6673. const int v = (int) (uint8) c;
  6674. if (v < 0x10)
  6675. result << T("%0");
  6676. else
  6677. result << T('%');
  6678. result << String::toHexString (v);
  6679. }
  6680. }
  6681. return result;
  6682. }
  6683. extern bool juce_launchFile (const String& fileName, const String& parameters);
  6684. bool URL::launchInDefaultBrowser() const
  6685. {
  6686. String u (toString (true));
  6687. if (u.contains (T("@")) && ! u.contains (T(":")))
  6688. u = "mailto:" + u;
  6689. return juce_launchFile (u, String::empty);
  6690. }
  6691. END_JUCE_NAMESPACE
  6692. /*** End of inlined file: juce_URL.cpp ***/
  6693. /*** Start of inlined file: juce_BufferedInputStream.cpp ***/
  6694. BEGIN_JUCE_NAMESPACE
  6695. BufferedInputStream::BufferedInputStream (InputStream* const source_,
  6696. const int bufferSize_,
  6697. const bool deleteSourceWhenDestroyed)
  6698. : source (source_),
  6699. sourceToDelete (deleteSourceWhenDestroyed ? source_ : 0),
  6700. bufferSize (jmax (256, bufferSize_)),
  6701. position (source_->getPosition()),
  6702. lastReadPos (0),
  6703. bufferOverlap (128)
  6704. {
  6705. const int sourceSize = (int) source_->getTotalLength();
  6706. if (sourceSize >= 0)
  6707. bufferSize = jmin (jmax (32, sourceSize), bufferSize);
  6708. bufferStart = position;
  6709. buffer.malloc (bufferSize);
  6710. }
  6711. BufferedInputStream::~BufferedInputStream()
  6712. {
  6713. }
  6714. int64 BufferedInputStream::getTotalLength()
  6715. {
  6716. return source->getTotalLength();
  6717. }
  6718. int64 BufferedInputStream::getPosition()
  6719. {
  6720. return position;
  6721. }
  6722. bool BufferedInputStream::setPosition (int64 newPosition)
  6723. {
  6724. position = jmax ((int64) 0, newPosition);
  6725. return true;
  6726. }
  6727. bool BufferedInputStream::isExhausted()
  6728. {
  6729. return (position >= lastReadPos)
  6730. && source->isExhausted();
  6731. }
  6732. void BufferedInputStream::ensureBuffered()
  6733. {
  6734. const int64 bufferEndOverlap = lastReadPos - bufferOverlap;
  6735. if (position < bufferStart || position >= bufferEndOverlap)
  6736. {
  6737. int bytesRead;
  6738. if (position < lastReadPos
  6739. && position >= bufferEndOverlap
  6740. && position >= bufferStart)
  6741. {
  6742. const int bytesToKeep = (int) (lastReadPos - position);
  6743. memmove (buffer, buffer + (int) (position - bufferStart), bytesToKeep);
  6744. bufferStart = position;
  6745. bytesRead = source->read (buffer + bytesToKeep,
  6746. bufferSize - bytesToKeep);
  6747. lastReadPos += bytesRead;
  6748. bytesRead += bytesToKeep;
  6749. }
  6750. else
  6751. {
  6752. bufferStart = position;
  6753. source->setPosition (bufferStart);
  6754. bytesRead = source->read (buffer, bufferSize);
  6755. lastReadPos = bufferStart + bytesRead;
  6756. }
  6757. while (bytesRead < bufferSize)
  6758. buffer [bytesRead++] = 0;
  6759. }
  6760. }
  6761. int BufferedInputStream::read (void* destBuffer, int maxBytesToRead)
  6762. {
  6763. if (position >= bufferStart
  6764. && position + maxBytesToRead <= lastReadPos)
  6765. {
  6766. memcpy (destBuffer, buffer + (int) (position - bufferStart), maxBytesToRead);
  6767. position += maxBytesToRead;
  6768. return maxBytesToRead;
  6769. }
  6770. else
  6771. {
  6772. if (position < bufferStart || position >= lastReadPos)
  6773. ensureBuffered();
  6774. int bytesRead = 0;
  6775. while (maxBytesToRead > 0)
  6776. {
  6777. const int bytesAvailable = jmin (maxBytesToRead, (int) (lastReadPos - position));
  6778. if (bytesAvailable > 0)
  6779. {
  6780. memcpy (destBuffer, buffer + (int) (position - bufferStart), bytesAvailable);
  6781. maxBytesToRead -= bytesAvailable;
  6782. bytesRead += bytesAvailable;
  6783. position += bytesAvailable;
  6784. destBuffer = (void*) (((char*) destBuffer) + bytesAvailable);
  6785. }
  6786. const int64 oldLastReadPos = lastReadPos;
  6787. ensureBuffered();
  6788. if (oldLastReadPos == lastReadPos)
  6789. break; // if ensureBuffered() failed to read any more data, bail out
  6790. if (isExhausted())
  6791. break;
  6792. }
  6793. return bytesRead;
  6794. }
  6795. }
  6796. const String BufferedInputStream::readString()
  6797. {
  6798. if (position >= bufferStart
  6799. && position < lastReadPos)
  6800. {
  6801. const int maxChars = (int) (lastReadPos - position);
  6802. const char* const src = buffer + (int) (position - bufferStart);
  6803. for (int i = 0; i < maxChars; ++i)
  6804. {
  6805. if (src[i] == 0)
  6806. {
  6807. position += i + 1;
  6808. return String::fromUTF8 (src, i);
  6809. }
  6810. }
  6811. }
  6812. return InputStream::readString();
  6813. }
  6814. END_JUCE_NAMESPACE
  6815. /*** End of inlined file: juce_BufferedInputStream.cpp ***/
  6816. /*** Start of inlined file: juce_FileInputSource.cpp ***/
  6817. BEGIN_JUCE_NAMESPACE
  6818. FileInputSource::FileInputSource (const File& file_)
  6819. : file (file_)
  6820. {
  6821. }
  6822. FileInputSource::~FileInputSource()
  6823. {
  6824. }
  6825. InputStream* FileInputSource::createInputStream()
  6826. {
  6827. return file.createInputStream();
  6828. }
  6829. InputStream* FileInputSource::createInputStreamFor (const String& relatedItemPath)
  6830. {
  6831. return file.getSiblingFile (relatedItemPath).createInputStream();
  6832. }
  6833. int64 FileInputSource::hashCode() const
  6834. {
  6835. return file.hashCode();
  6836. }
  6837. END_JUCE_NAMESPACE
  6838. /*** End of inlined file: juce_FileInputSource.cpp ***/
  6839. /*** Start of inlined file: juce_MemoryInputStream.cpp ***/
  6840. BEGIN_JUCE_NAMESPACE
  6841. MemoryInputStream::MemoryInputStream (const void* const sourceData,
  6842. const size_t sourceDataSize,
  6843. const bool keepInternalCopy)
  6844. : data (static_cast <const char*> (sourceData)),
  6845. dataSize (sourceDataSize),
  6846. position (0)
  6847. {
  6848. if (keepInternalCopy)
  6849. {
  6850. internalCopy.append (data, sourceDataSize);
  6851. data = static_cast <const char*> (internalCopy.getData());
  6852. }
  6853. }
  6854. MemoryInputStream::MemoryInputStream (const MemoryBlock& sourceData,
  6855. const bool keepInternalCopy)
  6856. : data (static_cast <const char*> (sourceData.getData())),
  6857. dataSize (sourceData.getSize()),
  6858. position (0)
  6859. {
  6860. if (keepInternalCopy)
  6861. {
  6862. internalCopy = sourceData;
  6863. data = static_cast <const char*> (internalCopy.getData());
  6864. }
  6865. }
  6866. MemoryInputStream::~MemoryInputStream()
  6867. {
  6868. }
  6869. int64 MemoryInputStream::getTotalLength()
  6870. {
  6871. return dataSize;
  6872. }
  6873. int MemoryInputStream::read (void* const buffer, const int howMany)
  6874. {
  6875. jassert (howMany >= 0);
  6876. const int num = jmin (howMany, (int) (dataSize - position));
  6877. memcpy (buffer, data + position, num);
  6878. position += num;
  6879. return (int) num;
  6880. }
  6881. bool MemoryInputStream::isExhausted()
  6882. {
  6883. return (position >= dataSize);
  6884. }
  6885. bool MemoryInputStream::setPosition (const int64 pos)
  6886. {
  6887. position = (int) jlimit ((int64) 0, (int64) dataSize, pos);
  6888. return true;
  6889. }
  6890. int64 MemoryInputStream::getPosition()
  6891. {
  6892. return position;
  6893. }
  6894. END_JUCE_NAMESPACE
  6895. /*** End of inlined file: juce_MemoryInputStream.cpp ***/
  6896. /*** Start of inlined file: juce_MemoryOutputStream.cpp ***/
  6897. BEGIN_JUCE_NAMESPACE
  6898. MemoryOutputStream::MemoryOutputStream (const size_t initialSize,
  6899. const size_t blockSizeToIncreaseBy,
  6900. MemoryBlock* const memoryBlockToWriteTo)
  6901. : data (memoryBlockToWriteTo),
  6902. position (0),
  6903. size (0),
  6904. blockSize (jmax ((size_t) 16, blockSizeToIncreaseBy))
  6905. {
  6906. if (data == 0)
  6907. dataToDelete = data = new MemoryBlock (initialSize);
  6908. else
  6909. data->setSize (initialSize, false);
  6910. }
  6911. MemoryOutputStream::~MemoryOutputStream()
  6912. {
  6913. flush();
  6914. }
  6915. void MemoryOutputStream::flush()
  6916. {
  6917. if (dataToDelete == 0)
  6918. data->setSize (size, false);
  6919. }
  6920. void MemoryOutputStream::reset() throw()
  6921. {
  6922. position = 0;
  6923. size = 0;
  6924. }
  6925. bool MemoryOutputStream::write (const void* const buffer, int howMany)
  6926. {
  6927. if (howMany > 0)
  6928. {
  6929. size_t storageNeeded = position + howMany;
  6930. if (storageNeeded >= data->getSize())
  6931. {
  6932. // if we need more space, increase the block by at least 10%..
  6933. storageNeeded += jmax (blockSize, storageNeeded / 10);
  6934. storageNeeded = storageNeeded - (storageNeeded % blockSize) + blockSize;
  6935. data->ensureSize (storageNeeded);
  6936. }
  6937. data->copyFrom (buffer, (int) position, howMany);
  6938. position += howMany;
  6939. size = jmax (size, position);
  6940. }
  6941. return true;
  6942. }
  6943. const char* MemoryOutputStream::getData() const throw()
  6944. {
  6945. char* const d = static_cast <char*> (data->getData());
  6946. if (data->getSize() > size)
  6947. d [size] = 0;
  6948. return d;
  6949. }
  6950. size_t MemoryOutputStream::getDataSize() const throw()
  6951. {
  6952. return size;
  6953. }
  6954. int64 MemoryOutputStream::getPosition()
  6955. {
  6956. return position;
  6957. }
  6958. bool MemoryOutputStream::setPosition (int64 newPosition)
  6959. {
  6960. if (newPosition <= (int64) size)
  6961. {
  6962. // ok to seek backwards
  6963. position = jlimit ((size_t) 0, size, (size_t) newPosition);
  6964. return true;
  6965. }
  6966. else
  6967. {
  6968. // trying to make it bigger isn't a good thing to do..
  6969. return false;
  6970. }
  6971. }
  6972. END_JUCE_NAMESPACE
  6973. /*** End of inlined file: juce_MemoryOutputStream.cpp ***/
  6974. /*** Start of inlined file: juce_SubregionStream.cpp ***/
  6975. BEGIN_JUCE_NAMESPACE
  6976. SubregionStream::SubregionStream (InputStream* const sourceStream,
  6977. const int64 startPositionInSourceStream_,
  6978. const int64 lengthOfSourceStream_,
  6979. const bool deleteSourceWhenDestroyed) throw()
  6980. : source (sourceStream),
  6981. startPositionInSourceStream (startPositionInSourceStream_),
  6982. lengthOfSourceStream (lengthOfSourceStream_)
  6983. {
  6984. if (deleteSourceWhenDestroyed)
  6985. sourceToDelete = source;
  6986. setPosition (0);
  6987. }
  6988. SubregionStream::~SubregionStream() throw()
  6989. {
  6990. }
  6991. int64 SubregionStream::getTotalLength()
  6992. {
  6993. const int64 srcLen = source->getTotalLength() - startPositionInSourceStream;
  6994. return (lengthOfSourceStream >= 0) ? jmin (lengthOfSourceStream, srcLen)
  6995. : srcLen;
  6996. }
  6997. int64 SubregionStream::getPosition()
  6998. {
  6999. return source->getPosition() - startPositionInSourceStream;
  7000. }
  7001. bool SubregionStream::setPosition (int64 newPosition)
  7002. {
  7003. return source->setPosition (jmax ((int64) 0, newPosition + startPositionInSourceStream));
  7004. }
  7005. int SubregionStream::read (void* destBuffer, int maxBytesToRead)
  7006. {
  7007. if (lengthOfSourceStream < 0)
  7008. {
  7009. return source->read (destBuffer, maxBytesToRead);
  7010. }
  7011. else
  7012. {
  7013. maxBytesToRead = (int) jmin ((int64) maxBytesToRead, lengthOfSourceStream - getPosition());
  7014. if (maxBytesToRead <= 0)
  7015. return 0;
  7016. return source->read (destBuffer, maxBytesToRead);
  7017. }
  7018. }
  7019. bool SubregionStream::isExhausted()
  7020. {
  7021. if (lengthOfSourceStream >= 0)
  7022. return (getPosition() >= lengthOfSourceStream) || source->isExhausted();
  7023. else
  7024. return source->isExhausted();
  7025. }
  7026. END_JUCE_NAMESPACE
  7027. /*** End of inlined file: juce_SubregionStream.cpp ***/
  7028. /*** Start of inlined file: juce_PerformanceCounter.cpp ***/
  7029. BEGIN_JUCE_NAMESPACE
  7030. PerformanceCounter::PerformanceCounter (const String& name_,
  7031. int runsPerPrintout,
  7032. const File& loggingFile)
  7033. : name (name_),
  7034. numRuns (0),
  7035. runsPerPrint (runsPerPrintout),
  7036. totalTime (0),
  7037. outputFile (loggingFile)
  7038. {
  7039. if (outputFile != File::nonexistent)
  7040. {
  7041. String s ("**** Counter for \"");
  7042. s << name_ << "\" started at: "
  7043. << Time::getCurrentTime().toString (true, true)
  7044. << "\r\n";
  7045. outputFile.appendText (s, false, false);
  7046. }
  7047. }
  7048. PerformanceCounter::~PerformanceCounter()
  7049. {
  7050. printStatistics();
  7051. }
  7052. void PerformanceCounter::start()
  7053. {
  7054. started = Time::getHighResolutionTicks();
  7055. }
  7056. void PerformanceCounter::stop()
  7057. {
  7058. const int64 now = Time::getHighResolutionTicks();
  7059. totalTime += 1000.0 * Time::highResolutionTicksToSeconds (now - started);
  7060. if (++numRuns == runsPerPrint)
  7061. printStatistics();
  7062. }
  7063. void PerformanceCounter::printStatistics()
  7064. {
  7065. if (numRuns > 0)
  7066. {
  7067. String s ("Performance count for \"");
  7068. s << name << "\" - average over " << numRuns << " run(s) = ";
  7069. const int micros = (int) (totalTime * (1000.0 / numRuns));
  7070. if (micros > 10000)
  7071. s << (micros/1000) << " millisecs";
  7072. else
  7073. s << micros << " microsecs";
  7074. s << ", total = " << String (totalTime / 1000, 5) << " seconds";
  7075. Logger::outputDebugString (s);
  7076. s << "\r\n";
  7077. if (outputFile != File::nonexistent)
  7078. outputFile.appendText (s, false, false);
  7079. numRuns = 0;
  7080. totalTime = 0;
  7081. }
  7082. }
  7083. END_JUCE_NAMESPACE
  7084. /*** End of inlined file: juce_PerformanceCounter.cpp ***/
  7085. /*** Start of inlined file: juce_Uuid.cpp ***/
  7086. BEGIN_JUCE_NAMESPACE
  7087. Uuid::Uuid()
  7088. {
  7089. // Mix up any available MAC addresses with some time-based pseudo-random numbers
  7090. // to make it very very unlikely that two UUIDs will ever be the same..
  7091. static int64 macAddresses[2];
  7092. static bool hasCheckedMacAddresses = false;
  7093. if (! hasCheckedMacAddresses)
  7094. {
  7095. hasCheckedMacAddresses = true;
  7096. SystemStats::getMACAddresses (macAddresses, 2);
  7097. }
  7098. value.asInt64[0] = macAddresses[0];
  7099. value.asInt64[1] = macAddresses[1];
  7100. // We'll use both a local RNG that is re-seeded, plus the shared RNG,
  7101. // whose seed will carry over between calls to this method.
  7102. Random r (macAddresses[0] ^ macAddresses[1]
  7103. ^ Random::getSystemRandom().nextInt64());
  7104. for (int i = 4; --i >= 0;)
  7105. {
  7106. r.setSeedRandomly(); // calling this repeatedly improves randomness
  7107. value.asInt[i] ^= r.nextInt();
  7108. value.asInt[i] ^= Random::getSystemRandom().nextInt();
  7109. }
  7110. }
  7111. Uuid::~Uuid() throw()
  7112. {
  7113. }
  7114. Uuid::Uuid (const Uuid& other)
  7115. : value (other.value)
  7116. {
  7117. }
  7118. Uuid& Uuid::operator= (const Uuid& other)
  7119. {
  7120. value = other.value;
  7121. return *this;
  7122. }
  7123. bool Uuid::operator== (const Uuid& other) const
  7124. {
  7125. return memcmp (value.asBytes, other.value.asBytes, 16) == 0;
  7126. }
  7127. bool Uuid::operator!= (const Uuid& other) const
  7128. {
  7129. return ! operator== (other);
  7130. }
  7131. bool Uuid::isNull() const throw()
  7132. {
  7133. return (value.asInt64 [0] == 0) && (value.asInt64 [1] == 0);
  7134. }
  7135. const String Uuid::toString() const
  7136. {
  7137. return String::toHexString (value.asBytes, 16, 0);
  7138. }
  7139. Uuid::Uuid (const String& uuidString)
  7140. {
  7141. operator= (uuidString);
  7142. }
  7143. Uuid& Uuid::operator= (const String& uuidString)
  7144. {
  7145. int destIndex = 0;
  7146. int i = 0;
  7147. for (;;)
  7148. {
  7149. int byte = 0;
  7150. for (int loop = 2; --loop >= 0;)
  7151. {
  7152. byte <<= 4;
  7153. for (;;)
  7154. {
  7155. const tchar c = uuidString [i++];
  7156. if (c >= T('0') && c <= T('9'))
  7157. {
  7158. byte |= c - T('0');
  7159. break;
  7160. }
  7161. else if (c >= T('a') && c <= T('z'))
  7162. {
  7163. byte |= c - (T('a') - 10);
  7164. break;
  7165. }
  7166. else if (c >= T('A') && c <= T('Z'))
  7167. {
  7168. byte |= c - (T('A') - 10);
  7169. break;
  7170. }
  7171. else if (c == 0)
  7172. {
  7173. while (destIndex < 16)
  7174. value.asBytes [destIndex++] = 0;
  7175. return *this;
  7176. }
  7177. }
  7178. }
  7179. value.asBytes [destIndex++] = (uint8) byte;
  7180. }
  7181. }
  7182. Uuid::Uuid (const uint8* const rawData)
  7183. {
  7184. operator= (rawData);
  7185. }
  7186. Uuid& Uuid::operator= (const uint8* const rawData)
  7187. {
  7188. if (rawData != 0)
  7189. memcpy (value.asBytes, rawData, 16);
  7190. else
  7191. zeromem (value.asBytes, 16);
  7192. return *this;
  7193. }
  7194. END_JUCE_NAMESPACE
  7195. /*** End of inlined file: juce_Uuid.cpp ***/
  7196. /*** Start of inlined file: juce_ZipFile.cpp ***/
  7197. BEGIN_JUCE_NAMESPACE
  7198. class ZipFile::ZipEntryInfo
  7199. {
  7200. public:
  7201. ZipFile::ZipEntry entry;
  7202. int streamOffset;
  7203. int compressedSize;
  7204. bool compressed;
  7205. };
  7206. class ZipFile::ZipInputStream : public InputStream
  7207. {
  7208. public:
  7209. ZipInputStream (ZipFile& file_, ZipFile::ZipEntryInfo& zei)
  7210. : file (file_),
  7211. zipEntryInfo (zei),
  7212. pos (0),
  7213. headerSize (0),
  7214. inputStream (0)
  7215. {
  7216. inputStream = file_.inputStream;
  7217. if (file_.inputSource != 0)
  7218. {
  7219. inputStream = file.inputSource->createInputStream();
  7220. }
  7221. else
  7222. {
  7223. #ifdef JUCE_DEBUG
  7224. file_.numOpenStreams++;
  7225. #endif
  7226. }
  7227. char buffer [30];
  7228. if (inputStream != 0
  7229. && inputStream->setPosition (zei.streamOffset)
  7230. && inputStream->read (buffer, 30) == 30
  7231. && ByteOrder::littleEndianInt (buffer) == 0x04034b50)
  7232. {
  7233. headerSize = 30 + ByteOrder::littleEndianShort (buffer + 26)
  7234. + ByteOrder::littleEndianShort (buffer + 28);
  7235. }
  7236. }
  7237. ~ZipInputStream() throw()
  7238. {
  7239. #ifdef JUCE_DEBUG
  7240. if (inputStream != 0 && inputStream == file.inputStream)
  7241. file.numOpenStreams--;
  7242. #endif
  7243. if (inputStream != file.inputStream)
  7244. delete inputStream;
  7245. }
  7246. int64 getTotalLength() throw()
  7247. {
  7248. return zipEntryInfo.compressedSize;
  7249. }
  7250. int read (void* buffer, int howMany) throw()
  7251. {
  7252. if (headerSize <= 0)
  7253. return 0;
  7254. howMany = (int) jmin ((int64) howMany, zipEntryInfo.compressedSize - pos);
  7255. if (inputStream == 0)
  7256. return 0;
  7257. int num;
  7258. if (inputStream == file.inputStream)
  7259. {
  7260. const ScopedLock sl (file.lock);
  7261. inputStream->setPosition (pos + zipEntryInfo.streamOffset + headerSize);
  7262. num = inputStream->read (buffer, howMany);
  7263. }
  7264. else
  7265. {
  7266. inputStream->setPosition (pos + zipEntryInfo.streamOffset + headerSize);
  7267. num = inputStream->read (buffer, howMany);
  7268. }
  7269. pos += num;
  7270. return num;
  7271. }
  7272. bool isExhausted() throw()
  7273. {
  7274. return headerSize <= 0 || pos >= zipEntryInfo.compressedSize;
  7275. }
  7276. int64 getPosition() throw()
  7277. {
  7278. return pos;
  7279. }
  7280. bool setPosition (int64 newPos) throw()
  7281. {
  7282. pos = jlimit ((int64) 0, (int64) zipEntryInfo.compressedSize, newPos);
  7283. return true;
  7284. }
  7285. private:
  7286. ZipFile& file;
  7287. ZipEntryInfo zipEntryInfo;
  7288. int64 pos;
  7289. int headerSize;
  7290. InputStream* inputStream;
  7291. ZipInputStream (const ZipInputStream&);
  7292. ZipInputStream& operator= (const ZipInputStream&);
  7293. };
  7294. ZipFile::ZipFile (InputStream* const source_,
  7295. const bool deleteStreamWhenDestroyed) throw()
  7296. : inputStream (source_)
  7297. #ifdef JUCE_DEBUG
  7298. , numOpenStreams (0)
  7299. #endif
  7300. {
  7301. if (deleteStreamWhenDestroyed)
  7302. streamToDelete = inputStream;
  7303. init();
  7304. }
  7305. ZipFile::ZipFile (const File& file)
  7306. : inputStream (0)
  7307. #ifdef JUCE_DEBUG
  7308. , numOpenStreams (0)
  7309. #endif
  7310. {
  7311. inputSource = new FileInputSource (file);
  7312. init();
  7313. }
  7314. ZipFile::ZipFile (InputSource* const inputSource_)
  7315. : inputStream (0),
  7316. inputSource (inputSource_)
  7317. #ifdef JUCE_DEBUG
  7318. , numOpenStreams (0)
  7319. #endif
  7320. {
  7321. init();
  7322. }
  7323. ZipFile::~ZipFile() throw()
  7324. {
  7325. #ifdef JUCE_DEBUG
  7326. entries.clear();
  7327. // If you hit this assertion, it means you've created a stream to read
  7328. // one of the items in the zipfile, but you've forgotten to delete that
  7329. // stream object before deleting the file.. Streams can't be kept open
  7330. // after the file is deleted because they need to share the input
  7331. // stream that the file uses to read itself.
  7332. jassert (numOpenStreams == 0);
  7333. #endif
  7334. }
  7335. int ZipFile::getNumEntries() const throw()
  7336. {
  7337. return entries.size();
  7338. }
  7339. const ZipFile::ZipEntry* ZipFile::getEntry (const int index) const throw()
  7340. {
  7341. ZipEntryInfo* const zei = (ZipEntryInfo*) entries [index];
  7342. return (zei != 0) ? &(zei->entry)
  7343. : 0;
  7344. }
  7345. int ZipFile::getIndexOfFileName (const String& fileName) const throw()
  7346. {
  7347. for (int i = 0; i < entries.size(); ++i)
  7348. if (entries.getUnchecked (i)->entry.filename == fileName)
  7349. return i;
  7350. return -1;
  7351. }
  7352. const ZipFile::ZipEntry* ZipFile::getEntry (const String& fileName) const throw()
  7353. {
  7354. return getEntry (getIndexOfFileName (fileName));
  7355. }
  7356. InputStream* ZipFile::createStreamForEntry (const int index)
  7357. {
  7358. ZipEntryInfo* const zei = entries[index];
  7359. InputStream* stream = 0;
  7360. if (zei != 0)
  7361. {
  7362. stream = new ZipInputStream (*this, *zei);
  7363. if (zei->compressed)
  7364. {
  7365. stream = new GZIPDecompressorInputStream (stream, true, true,
  7366. zei->entry.uncompressedSize);
  7367. // (much faster to unzip in big blocks using a buffer..)
  7368. stream = new BufferedInputStream (stream, 32768, true);
  7369. }
  7370. }
  7371. return stream;
  7372. }
  7373. class ZipFile::ZipFilenameComparator
  7374. {
  7375. public:
  7376. int compareElements (const ZipFile::ZipEntryInfo* first, const ZipFile::ZipEntryInfo* second)
  7377. {
  7378. return first->entry.filename.compare (second->entry.filename);
  7379. }
  7380. };
  7381. void ZipFile::sortEntriesByFilename()
  7382. {
  7383. ZipFilenameComparator sorter;
  7384. entries.sort (sorter);
  7385. }
  7386. void ZipFile::init()
  7387. {
  7388. ScopedPointer <InputStream> toDelete;
  7389. InputStream* in = inputStream;
  7390. if (inputSource != 0)
  7391. {
  7392. in = inputSource->createInputStream();
  7393. toDelete = in;
  7394. }
  7395. if (in != 0)
  7396. {
  7397. int numEntries = 0;
  7398. int pos = findEndOfZipEntryTable (in, numEntries);
  7399. if (pos >= 0 && pos < in->getTotalLength())
  7400. {
  7401. const int size = (int) (in->getTotalLength() - pos);
  7402. in->setPosition (pos);
  7403. MemoryBlock headerData;
  7404. if (in->readIntoMemoryBlock (headerData, size) == size)
  7405. {
  7406. pos = 0;
  7407. for (int i = 0; i < numEntries; ++i)
  7408. {
  7409. if (pos + 46 > size)
  7410. break;
  7411. const char* const buffer = ((const char*) headerData.getData()) + pos;
  7412. const int fileNameLen = ByteOrder::littleEndianShort (buffer + 28);
  7413. if (pos + 46 + fileNameLen > size)
  7414. break;
  7415. ZipEntryInfo* const zei = new ZipEntryInfo();
  7416. zei->entry.filename = String::fromUTF8 (buffer + 46, fileNameLen);
  7417. const int time = ByteOrder::littleEndianShort (buffer + 12);
  7418. const int date = ByteOrder::littleEndianShort (buffer + 14);
  7419. const int year = 1980 + (date >> 9);
  7420. const int month = ((date >> 5) & 15) - 1;
  7421. const int day = date & 31;
  7422. const int hours = time >> 11;
  7423. const int minutes = (time >> 5) & 63;
  7424. const int seconds = (time & 31) << 1;
  7425. zei->entry.fileTime = Time (year, month, day, hours, minutes, seconds);
  7426. zei->compressed = ByteOrder::littleEndianShort (buffer + 10) != 0;
  7427. zei->compressedSize = ByteOrder::littleEndianInt (buffer + 20);
  7428. zei->entry.uncompressedSize = ByteOrder::littleEndianInt (buffer + 24);
  7429. zei->streamOffset = ByteOrder::littleEndianInt (buffer + 42);
  7430. entries.add (zei);
  7431. pos += 46 + fileNameLen
  7432. + ByteOrder::littleEndianShort (buffer + 30)
  7433. + ByteOrder::littleEndianShort (buffer + 32);
  7434. }
  7435. }
  7436. }
  7437. }
  7438. }
  7439. int ZipFile::findEndOfZipEntryTable (InputStream* input, int& numEntries)
  7440. {
  7441. BufferedInputStream in (input, 8192, false);
  7442. in.setPosition (in.getTotalLength());
  7443. int64 pos = in.getPosition();
  7444. const int64 lowestPos = jmax ((int64) 0, pos - 1024);
  7445. char buffer [32];
  7446. zeromem (buffer, sizeof (buffer));
  7447. while (pos > lowestPos)
  7448. {
  7449. in.setPosition (pos - 22);
  7450. pos = in.getPosition();
  7451. memcpy (buffer + 22, buffer, 4);
  7452. if (in.read (buffer, 22) != 22)
  7453. return 0;
  7454. for (int i = 0; i < 22; ++i)
  7455. {
  7456. if (ByteOrder::littleEndianInt (buffer + i) == 0x06054b50)
  7457. {
  7458. in.setPosition (pos + i);
  7459. in.read (buffer, 22);
  7460. numEntries = ByteOrder::littleEndianShort (buffer + 10);
  7461. return ByteOrder::littleEndianInt (buffer + 16);
  7462. }
  7463. }
  7464. }
  7465. return 0;
  7466. }
  7467. void ZipFile::uncompressTo (const File& targetDirectory,
  7468. const bool shouldOverwriteFiles)
  7469. {
  7470. for (int i = 0; i < entries.size(); ++i)
  7471. {
  7472. const ZipEntry& zei = entries.getUnchecked(i)->entry;
  7473. const File targetFile (targetDirectory.getChildFile (zei.filename));
  7474. if (zei.filename.endsWithChar (T('/')))
  7475. {
  7476. targetFile.createDirectory(); // (entry is a directory, not a file)
  7477. }
  7478. else
  7479. {
  7480. ScopedPointer <InputStream> in (createStreamForEntry (i));
  7481. if (in != 0)
  7482. {
  7483. if (shouldOverwriteFiles)
  7484. targetFile.deleteFile();
  7485. if ((! targetFile.exists())
  7486. && targetFile.getParentDirectory().createDirectory())
  7487. {
  7488. ScopedPointer <FileOutputStream> out (targetFile.createOutputStream());
  7489. if (out != 0)
  7490. {
  7491. out->writeFromInputStream (*in, -1);
  7492. out = 0;
  7493. targetFile.setCreationTime (zei.fileTime);
  7494. targetFile.setLastModificationTime (zei.fileTime);
  7495. targetFile.setLastAccessTime (zei.fileTime);
  7496. }
  7497. }
  7498. }
  7499. }
  7500. }
  7501. }
  7502. END_JUCE_NAMESPACE
  7503. /*** End of inlined file: juce_ZipFile.cpp ***/
  7504. /*** Start of inlined file: juce_CharacterFunctions.cpp ***/
  7505. #ifdef _MSC_VER
  7506. #pragma warning (disable: 4514 4996)
  7507. #pragma warning (push)
  7508. #endif
  7509. #include <cwctype>
  7510. #include <cctype>
  7511. #include <ctime>
  7512. #ifdef _MSC_VER
  7513. #pragma warning (pop)
  7514. #endif
  7515. BEGIN_JUCE_NAMESPACE
  7516. int CharacterFunctions::length (const char* const s) throw()
  7517. {
  7518. return (int) strlen (s);
  7519. }
  7520. int CharacterFunctions::length (const juce_wchar* const s) throw()
  7521. {
  7522. return (int) wcslen (s);
  7523. }
  7524. void CharacterFunctions::copy (char* dest, const char* src, const int maxChars) throw()
  7525. {
  7526. strncpy (dest, src, maxChars);
  7527. }
  7528. void CharacterFunctions::copy (juce_wchar* dest, const juce_wchar* src, int maxChars) throw()
  7529. {
  7530. wcsncpy (dest, src, maxChars);
  7531. }
  7532. void CharacterFunctions::copy (juce_wchar* dest, const char* src, const int maxChars) throw()
  7533. {
  7534. mbstowcs (dest, src, maxChars);
  7535. }
  7536. void CharacterFunctions::copy (char* dest, const juce_wchar* src, const int maxChars) throw()
  7537. {
  7538. wcstombs (dest, src, maxChars);
  7539. }
  7540. int CharacterFunctions::bytesRequiredForCopy (const juce_wchar* src) throw()
  7541. {
  7542. return (int) wcstombs (0, src, 0);
  7543. }
  7544. void CharacterFunctions::append (char* dest, const char* src) throw()
  7545. {
  7546. strcat (dest, src);
  7547. }
  7548. void CharacterFunctions::append (juce_wchar* dest, const juce_wchar* src) throw()
  7549. {
  7550. wcscat (dest, src);
  7551. }
  7552. int CharacterFunctions::compare (const char* const s1, const char* const s2) throw()
  7553. {
  7554. return strcmp (s1, s2);
  7555. }
  7556. int CharacterFunctions::compare (const juce_wchar* s1, const juce_wchar* s2) throw()
  7557. {
  7558. jassert (s1 != 0 && s2 != 0);
  7559. return wcscmp (s1, s2);
  7560. }
  7561. int CharacterFunctions::compare (const char* const s1, const char* const s2, const int maxChars) throw()
  7562. {
  7563. jassert (s1 != 0 && s2 != 0);
  7564. return strncmp (s1, s2, maxChars);
  7565. }
  7566. int CharacterFunctions::compare (const juce_wchar* s1, const juce_wchar* s2, int maxChars) throw()
  7567. {
  7568. jassert (s1 != 0 && s2 != 0);
  7569. return wcsncmp (s1, s2, maxChars);
  7570. }
  7571. int CharacterFunctions::compare (const juce_wchar* s1, const char* s2) throw()
  7572. {
  7573. jassert (s1 != 0 && s2 != 0);
  7574. for (;;)
  7575. {
  7576. const int diff = (int) (*s1 - (juce_wchar) (unsigned char) *s2);
  7577. if (diff != 0)
  7578. return diff;
  7579. else if (*s1 == 0)
  7580. break;
  7581. ++s1;
  7582. ++s2;
  7583. }
  7584. return 0;
  7585. }
  7586. int CharacterFunctions::compare (const char* s1, const juce_wchar* s2) throw()
  7587. {
  7588. return -compare (s2, s1);
  7589. }
  7590. int CharacterFunctions::compareIgnoreCase (const char* const s1, const char* const s2) throw()
  7591. {
  7592. jassert (s1 != 0 && s2 != 0);
  7593. #if JUCE_WIN32
  7594. return stricmp (s1, s2);
  7595. #else
  7596. return strcasecmp (s1, s2);
  7597. #endif
  7598. }
  7599. int CharacterFunctions::compareIgnoreCase (const juce_wchar* s1, const juce_wchar* s2) throw()
  7600. {
  7601. jassert (s1 != 0 && s2 != 0);
  7602. #if JUCE_WIN32
  7603. return _wcsicmp (s1, s2);
  7604. #else
  7605. for (;;)
  7606. {
  7607. if (*s1 != *s2)
  7608. {
  7609. const int diff = toUpperCase (*s1) - toUpperCase (*s2);
  7610. if (diff != 0)
  7611. return diff < 0 ? -1 : 1;
  7612. }
  7613. else if (*s1 == 0)
  7614. break;
  7615. ++s1;
  7616. ++s2;
  7617. }
  7618. return 0;
  7619. #endif
  7620. }
  7621. int CharacterFunctions::compareIgnoreCase (const char* const s1, const char* const s2, const int maxChars) throw()
  7622. {
  7623. jassert (s1 != 0 && s2 != 0);
  7624. #if JUCE_WIN32
  7625. return strnicmp (s1, s2, maxChars);
  7626. #else
  7627. return strncasecmp (s1, s2, maxChars);
  7628. #endif
  7629. }
  7630. int CharacterFunctions::compareIgnoreCase (const juce_wchar* s1, const juce_wchar* s2, int maxChars) throw()
  7631. {
  7632. jassert (s1 != 0 && s2 != 0);
  7633. #if JUCE_WIN32
  7634. return _wcsnicmp (s1, s2, maxChars);
  7635. #else
  7636. while (--maxChars >= 0)
  7637. {
  7638. if (*s1 != *s2)
  7639. {
  7640. const int diff = toUpperCase (*s1) - toUpperCase (*s2);
  7641. if (diff != 0)
  7642. return diff < 0 ? -1 : 1;
  7643. }
  7644. else if (*s1 == 0)
  7645. break;
  7646. ++s1;
  7647. ++s2;
  7648. }
  7649. return 0;
  7650. #endif
  7651. }
  7652. const char* CharacterFunctions::find (const char* const haystack, const char* const needle) throw()
  7653. {
  7654. return strstr (haystack, needle);
  7655. }
  7656. const juce_wchar* CharacterFunctions::find (const juce_wchar* haystack, const juce_wchar* const needle) throw()
  7657. {
  7658. return wcsstr (haystack, needle);
  7659. }
  7660. int CharacterFunctions::indexOfChar (const char* const haystack, const char needle, const bool ignoreCase) throw()
  7661. {
  7662. if (haystack != 0)
  7663. {
  7664. int i = 0;
  7665. if (ignoreCase)
  7666. {
  7667. const char n1 = toLowerCase (needle);
  7668. const char n2 = toUpperCase (needle);
  7669. if (n1 != n2) // if the char is the same in upper/lower case, fall through to the normal search
  7670. {
  7671. while (haystack[i] != 0)
  7672. {
  7673. if (haystack[i] == n1 || haystack[i] == n2)
  7674. return i;
  7675. ++i;
  7676. }
  7677. return -1;
  7678. }
  7679. jassert (n1 == needle);
  7680. }
  7681. while (haystack[i] != 0)
  7682. {
  7683. if (haystack[i] == needle)
  7684. return i;
  7685. ++i;
  7686. }
  7687. }
  7688. return -1;
  7689. }
  7690. int CharacterFunctions::indexOfChar (const juce_wchar* const haystack, const juce_wchar needle, const bool ignoreCase) throw()
  7691. {
  7692. if (haystack != 0)
  7693. {
  7694. int i = 0;
  7695. if (ignoreCase)
  7696. {
  7697. const juce_wchar n1 = toLowerCase (needle);
  7698. const juce_wchar n2 = toUpperCase (needle);
  7699. if (n1 != n2) // if the char is the same in upper/lower case, fall through to the normal search
  7700. {
  7701. while (haystack[i] != 0)
  7702. {
  7703. if (haystack[i] == n1 || haystack[i] == n2)
  7704. return i;
  7705. ++i;
  7706. }
  7707. return -1;
  7708. }
  7709. jassert (n1 == needle);
  7710. }
  7711. while (haystack[i] != 0)
  7712. {
  7713. if (haystack[i] == needle)
  7714. return i;
  7715. ++i;
  7716. }
  7717. }
  7718. return -1;
  7719. }
  7720. int CharacterFunctions::indexOfCharFast (const char* const haystack, const char needle) throw()
  7721. {
  7722. jassert (haystack != 0);
  7723. int i = 0;
  7724. while (haystack[i] != 0)
  7725. {
  7726. if (haystack[i] == needle)
  7727. return i;
  7728. ++i;
  7729. }
  7730. return -1;
  7731. }
  7732. int CharacterFunctions::indexOfCharFast (const juce_wchar* const haystack, const juce_wchar needle) throw()
  7733. {
  7734. jassert (haystack != 0);
  7735. int i = 0;
  7736. while (haystack[i] != 0)
  7737. {
  7738. if (haystack[i] == needle)
  7739. return i;
  7740. ++i;
  7741. }
  7742. return -1;
  7743. }
  7744. int CharacterFunctions::getIntialSectionContainingOnly (const char* const text, const char* const allowedChars) throw()
  7745. {
  7746. return allowedChars == 0 ? 0 : (int) strspn (text, allowedChars);
  7747. }
  7748. int CharacterFunctions::getIntialSectionContainingOnly (const juce_wchar* const text, const juce_wchar* const allowedChars) throw()
  7749. {
  7750. if (allowedChars == 0)
  7751. return 0;
  7752. int i = 0;
  7753. for (;;)
  7754. {
  7755. if (indexOfCharFast (allowedChars, text[i]) < 0)
  7756. break;
  7757. ++i;
  7758. }
  7759. return i;
  7760. }
  7761. int CharacterFunctions::ftime (char* const dest, const int maxChars, const char* const format, const struct tm* const tm) throw()
  7762. {
  7763. return (int) strftime (dest, maxChars, format, tm);
  7764. }
  7765. int CharacterFunctions::ftime (juce_wchar* const dest, const int maxChars, const juce_wchar* const format, const struct tm* const tm) throw()
  7766. {
  7767. return (int) wcsftime (dest, maxChars, format, tm);
  7768. }
  7769. int CharacterFunctions::getIntValue (const char* const s) throw()
  7770. {
  7771. return atoi (s);
  7772. }
  7773. int CharacterFunctions::getIntValue (const juce_wchar* s) throw()
  7774. {
  7775. #if JUCE_WIN32
  7776. return _wtoi (s);
  7777. #else
  7778. int v = 0;
  7779. while (isWhitespace (*s))
  7780. ++s;
  7781. const bool isNeg = *s == T('-');
  7782. if (isNeg)
  7783. ++s;
  7784. for (;;)
  7785. {
  7786. const wchar_t c = *s++;
  7787. if (c >= T('0') && c <= T('9'))
  7788. v = v * 10 + (int) (c - T('0'));
  7789. else
  7790. break;
  7791. }
  7792. return isNeg ? -v : v;
  7793. #endif
  7794. }
  7795. int64 CharacterFunctions::getInt64Value (const char* s) throw()
  7796. {
  7797. #if JUCE_LINUX
  7798. return atoll (s);
  7799. #elif defined (JUCE_WIN32)
  7800. return _atoi64 (s);
  7801. #else
  7802. int64 v = 0;
  7803. while (isWhitespace (*s))
  7804. ++s;
  7805. const bool isNeg = *s == T('-');
  7806. if (isNeg)
  7807. ++s;
  7808. for (;;)
  7809. {
  7810. const char c = *s++;
  7811. if (c >= '0' && c <= '9')
  7812. v = v * 10 + (int64) (c - '0');
  7813. else
  7814. break;
  7815. }
  7816. return isNeg ? -v : v;
  7817. #endif
  7818. }
  7819. int64 CharacterFunctions::getInt64Value (const juce_wchar* s) throw()
  7820. {
  7821. #if JUCE_WIN32
  7822. return _wtoi64 (s);
  7823. #else
  7824. int64 v = 0;
  7825. while (isWhitespace (*s))
  7826. ++s;
  7827. const bool isNeg = *s == T('-');
  7828. if (isNeg)
  7829. ++s;
  7830. for (;;)
  7831. {
  7832. const juce_wchar c = *s++;
  7833. if (c >= T('0') && c <= T('9'))
  7834. v = v * 10 + (int64) (c - T('0'));
  7835. else
  7836. break;
  7837. }
  7838. return isNeg ? -v : v;
  7839. #endif
  7840. }
  7841. static double juce_mulexp10 (const double value, int exponent) throw()
  7842. {
  7843. if (exponent == 0)
  7844. return value;
  7845. if (value == 0)
  7846. return 0;
  7847. const bool negative = (exponent < 0);
  7848. if (negative)
  7849. exponent = -exponent;
  7850. double result = 1.0, power = 10.0;
  7851. for (int bit = 1; exponent != 0; bit <<= 1)
  7852. {
  7853. if ((exponent & bit) != 0)
  7854. {
  7855. exponent ^= bit;
  7856. result *= power;
  7857. if (exponent == 0)
  7858. break;
  7859. }
  7860. power *= power;
  7861. }
  7862. return negative ? (value / result) : (value * result);
  7863. }
  7864. template <class CharType>
  7865. double juce_atof (const CharType* const original) throw()
  7866. {
  7867. double result[3] = { 0, 0, 0 }, accumulator[2] = { 0, 0 };
  7868. int exponentAdjustment[2] = { 0, 0 }, exponentAccumulator[2] = { -1, -1 };
  7869. int exponent = 0, decPointIndex = 0, digit = 0;
  7870. int lastDigit = 0, numSignificantDigits = 0;
  7871. bool isNegative = false, digitsFound = false;
  7872. const int maxSignificantDigits = 15 + 2;
  7873. const CharType* s = original;
  7874. while (CharacterFunctions::isWhitespace (*s))
  7875. ++s;
  7876. switch (*s)
  7877. {
  7878. case '-': isNegative = true; // fall-through..
  7879. case '+': ++s;
  7880. }
  7881. if (*s == 'n' || *s == 'N' || *s == 'i' || *s == 'I')
  7882. return atof (String (original).toUTF8()); // Let the c library deal with NAN and INF
  7883. for (;;)
  7884. {
  7885. if (CharacterFunctions::isDigit (*s))
  7886. {
  7887. lastDigit = digit;
  7888. digit = *s++ - '0';
  7889. digitsFound = true;
  7890. if (decPointIndex != 0)
  7891. exponentAdjustment[1]++;
  7892. if (numSignificantDigits == 0 && digit == 0)
  7893. continue;
  7894. if (++numSignificantDigits > maxSignificantDigits)
  7895. {
  7896. if (digit > 5)
  7897. ++accumulator [decPointIndex];
  7898. else if (digit == 5 && (lastDigit & 1) != 0)
  7899. ++accumulator [decPointIndex];
  7900. if (decPointIndex > 0)
  7901. exponentAdjustment[1]--;
  7902. else
  7903. exponentAdjustment[0]++;
  7904. while (CharacterFunctions::isDigit (*s))
  7905. {
  7906. ++s;
  7907. if (decPointIndex == 0)
  7908. exponentAdjustment[0]++;
  7909. }
  7910. }
  7911. else
  7912. {
  7913. const double maxAccumulatorValue = (double) ((std::numeric_limits<unsigned int>::max() - 9) / 10);
  7914. if (accumulator [decPointIndex] > maxAccumulatorValue)
  7915. {
  7916. result [decPointIndex] = juce_mulexp10 (result [decPointIndex], exponentAccumulator [decPointIndex])
  7917. + accumulator [decPointIndex];
  7918. accumulator [decPointIndex] = 0;
  7919. exponentAccumulator [decPointIndex] = 0;
  7920. }
  7921. accumulator [decPointIndex] = accumulator[decPointIndex] * 10 + digit;
  7922. exponentAccumulator [decPointIndex]++;
  7923. }
  7924. }
  7925. else if (decPointIndex == 0 && *s == '.')
  7926. {
  7927. ++s;
  7928. decPointIndex = 1;
  7929. if (numSignificantDigits > maxSignificantDigits)
  7930. {
  7931. while (CharacterFunctions::isDigit (*s))
  7932. ++s;
  7933. break;
  7934. }
  7935. }
  7936. else
  7937. {
  7938. break;
  7939. }
  7940. }
  7941. result[0] = juce_mulexp10 (result[0], exponentAccumulator[0]) + accumulator[0];
  7942. if (decPointIndex != 0)
  7943. result[1] = juce_mulexp10 (result[1], exponentAccumulator[1]) + accumulator[1];
  7944. if ((*s == 'e' || *s == 'E') && digitsFound)
  7945. {
  7946. bool negativeExponent = false;
  7947. switch (*++s)
  7948. {
  7949. case '-': negativeExponent = true; // fall-through..
  7950. case '+': ++s;
  7951. }
  7952. while (CharacterFunctions::isDigit (*s))
  7953. exponent = (exponent * 10) + (*s++ - '0');
  7954. if (negativeExponent)
  7955. exponent = -exponent;
  7956. }
  7957. double r = juce_mulexp10 (result[0], exponent + exponentAdjustment[0]);
  7958. if (decPointIndex != 0)
  7959. r += juce_mulexp10 (result[1], exponent - exponentAdjustment[1]);
  7960. return isNegative ? -r : r;
  7961. }
  7962. double CharacterFunctions::getDoubleValue (const char* const s) throw()
  7963. {
  7964. return juce_atof <char> (s);
  7965. }
  7966. double CharacterFunctions::getDoubleValue (const juce_wchar* const s) throw()
  7967. {
  7968. return juce_atof <juce_wchar> (s);
  7969. }
  7970. char CharacterFunctions::toUpperCase (const char character) throw()
  7971. {
  7972. return (char) toupper (character);
  7973. }
  7974. juce_wchar CharacterFunctions::toUpperCase (const juce_wchar character) throw()
  7975. {
  7976. return towupper (character);
  7977. }
  7978. void CharacterFunctions::toUpperCase (char* s) throw()
  7979. {
  7980. #if JUCE_WIN32
  7981. strupr (s);
  7982. #else
  7983. while (*s != 0)
  7984. {
  7985. *s = toUpperCase (*s);
  7986. ++s;
  7987. }
  7988. #endif
  7989. }
  7990. void CharacterFunctions::toUpperCase (juce_wchar* s) throw()
  7991. {
  7992. #if JUCE_WIN32
  7993. _wcsupr (s);
  7994. #else
  7995. while (*s != 0)
  7996. {
  7997. *s = toUpperCase (*s);
  7998. ++s;
  7999. }
  8000. #endif
  8001. }
  8002. bool CharacterFunctions::isUpperCase (const char character) throw()
  8003. {
  8004. return isupper (character) != 0;
  8005. }
  8006. bool CharacterFunctions::isUpperCase (const juce_wchar character) throw()
  8007. {
  8008. #if JUCE_WIN32
  8009. return iswupper (character) != 0;
  8010. #else
  8011. return toLowerCase (character) != character;
  8012. #endif
  8013. }
  8014. char CharacterFunctions::toLowerCase (const char character) throw()
  8015. {
  8016. return (char) tolower (character);
  8017. }
  8018. juce_wchar CharacterFunctions::toLowerCase (const juce_wchar character) throw()
  8019. {
  8020. return towlower (character);
  8021. }
  8022. void CharacterFunctions::toLowerCase (char* s) throw()
  8023. {
  8024. #if JUCE_WIN32
  8025. strlwr (s);
  8026. #else
  8027. while (*s != 0)
  8028. {
  8029. *s = toLowerCase (*s);
  8030. ++s;
  8031. }
  8032. #endif
  8033. }
  8034. void CharacterFunctions::toLowerCase (juce_wchar* s) throw()
  8035. {
  8036. #if JUCE_WIN32
  8037. _wcslwr (s);
  8038. #else
  8039. while (*s != 0)
  8040. {
  8041. *s = toLowerCase (*s);
  8042. ++s;
  8043. }
  8044. #endif
  8045. }
  8046. bool CharacterFunctions::isLowerCase (const char character) throw()
  8047. {
  8048. return islower (character) != 0;
  8049. }
  8050. bool CharacterFunctions::isLowerCase (const juce_wchar character) throw()
  8051. {
  8052. #if JUCE_WIN32
  8053. return iswlower (character) != 0;
  8054. #else
  8055. return toUpperCase (character) != character;
  8056. #endif
  8057. }
  8058. bool CharacterFunctions::isWhitespace (const char character) throw()
  8059. {
  8060. return character == T(' ') || (character <= 13 && character >= 9);
  8061. }
  8062. bool CharacterFunctions::isWhitespace (const juce_wchar character) throw()
  8063. {
  8064. return iswspace (character) != 0;
  8065. }
  8066. bool CharacterFunctions::isDigit (const char character) throw()
  8067. {
  8068. return (character >= '0' && character <= '9');
  8069. }
  8070. bool CharacterFunctions::isDigit (const juce_wchar character) throw()
  8071. {
  8072. return iswdigit (character) != 0;
  8073. }
  8074. bool CharacterFunctions::isLetter (const char character) throw()
  8075. {
  8076. return (character >= 'a' && character <= 'z')
  8077. || (character >= 'A' && character <= 'Z');
  8078. }
  8079. bool CharacterFunctions::isLetter (const juce_wchar character) throw()
  8080. {
  8081. return iswalpha (character) != 0;
  8082. }
  8083. bool CharacterFunctions::isLetterOrDigit (const char character) throw()
  8084. {
  8085. return (character >= 'a' && character <= 'z')
  8086. || (character >= 'A' && character <= 'Z')
  8087. || (character >= '0' && character <= '9');
  8088. }
  8089. bool CharacterFunctions::isLetterOrDigit (const juce_wchar character) throw()
  8090. {
  8091. return iswalnum (character) != 0;
  8092. }
  8093. int CharacterFunctions::getHexDigitValue (const juce_wchar digit) throw()
  8094. {
  8095. if (digit >= '0' && digit <= '9')
  8096. return digit - '0';
  8097. else if (digit >= 'a' && digit <= 'f')
  8098. return digit - ('a' - 10);
  8099. else if (digit >= 'A' && digit <= 'F')
  8100. return digit - ('A' - 10);
  8101. return -1;
  8102. }
  8103. END_JUCE_NAMESPACE
  8104. /*** End of inlined file: juce_CharacterFunctions.cpp ***/
  8105. /*** Start of inlined file: juce_LocalisedStrings.cpp ***/
  8106. BEGIN_JUCE_NAMESPACE
  8107. LocalisedStrings::LocalisedStrings (const String& fileContents)
  8108. {
  8109. loadFromText (fileContents);
  8110. }
  8111. LocalisedStrings::LocalisedStrings (const File& fileToLoad)
  8112. {
  8113. loadFromText (fileToLoad.loadFileAsString());
  8114. }
  8115. LocalisedStrings::~LocalisedStrings()
  8116. {
  8117. }
  8118. const String LocalisedStrings::translate (const String& text) const
  8119. {
  8120. return translations.getValue (text, text);
  8121. }
  8122. static int findCloseQuote (const String& text, int startPos)
  8123. {
  8124. tchar lastChar = 0;
  8125. for (;;)
  8126. {
  8127. const tchar c = text [startPos];
  8128. if (c == 0 || (c == T('"') && lastChar != T('\\')))
  8129. break;
  8130. lastChar = c;
  8131. ++startPos;
  8132. }
  8133. return startPos;
  8134. }
  8135. static const String unescapeString (const String& s)
  8136. {
  8137. return s.replace (T("\\\""), T("\""))
  8138. .replace (T("\\\'"), T("\'"))
  8139. .replace (T("\\t"), T("\t"))
  8140. .replace (T("\\r"), T("\r"))
  8141. .replace (T("\\n"), T("\n"));
  8142. }
  8143. void LocalisedStrings::loadFromText (const String& fileContents)
  8144. {
  8145. StringArray lines;
  8146. lines.addLines (fileContents);
  8147. for (int i = 0; i < lines.size(); ++i)
  8148. {
  8149. String line (lines[i].trim());
  8150. if (line.startsWithChar (T('"')))
  8151. {
  8152. int closeQuote = findCloseQuote (line, 1);
  8153. const String originalText (unescapeString (line.substring (1, closeQuote)));
  8154. if (originalText.isNotEmpty())
  8155. {
  8156. const int openingQuote = findCloseQuote (line, closeQuote + 1);
  8157. closeQuote = findCloseQuote (line, openingQuote + 1);
  8158. const String newText (unescapeString (line.substring (openingQuote + 1, closeQuote)));
  8159. if (newText.isNotEmpty())
  8160. translations.set (originalText, newText);
  8161. }
  8162. }
  8163. else if (line.startsWithIgnoreCase (T("language:")))
  8164. {
  8165. languageName = line.substring (9).trim();
  8166. }
  8167. else if (line.startsWithIgnoreCase (T("countries:")))
  8168. {
  8169. countryCodes.addTokens (line.substring (10).trim(), true);
  8170. countryCodes.trim();
  8171. countryCodes.removeEmptyStrings();
  8172. }
  8173. }
  8174. }
  8175. void LocalisedStrings::setIgnoresCase (const bool shouldIgnoreCase)
  8176. {
  8177. translations.setIgnoresCase (shouldIgnoreCase);
  8178. }
  8179. static CriticalSection currentMappingsLock;
  8180. static LocalisedStrings* currentMappings = 0;
  8181. void LocalisedStrings::setCurrentMappings (LocalisedStrings* newTranslations)
  8182. {
  8183. const ScopedLock sl (currentMappingsLock);
  8184. delete currentMappings;
  8185. currentMappings = newTranslations;
  8186. }
  8187. LocalisedStrings* LocalisedStrings::getCurrentMappings()
  8188. {
  8189. return currentMappings;
  8190. }
  8191. const String LocalisedStrings::translateWithCurrentMappings (const String& text)
  8192. {
  8193. const ScopedLock sl (currentMappingsLock);
  8194. if (currentMappings != 0)
  8195. return currentMappings->translate (text);
  8196. return text;
  8197. }
  8198. const String LocalisedStrings::translateWithCurrentMappings (const char* text)
  8199. {
  8200. return translateWithCurrentMappings (String (text));
  8201. }
  8202. END_JUCE_NAMESPACE
  8203. /*** End of inlined file: juce_LocalisedStrings.cpp ***/
  8204. /*** Start of inlined file: juce_String.cpp ***/
  8205. #ifdef _MSC_VER
  8206. #pragma warning (disable: 4514)
  8207. #pragma warning (push)
  8208. #endif
  8209. #include <locale>
  8210. #if JUCE_MSVC
  8211. #include <float.h>
  8212. #endif
  8213. BEGIN_JUCE_NAMESPACE
  8214. #ifdef _MSC_VER
  8215. #pragma warning (pop)
  8216. #endif
  8217. #if defined (JUCE_STRINGS_ARE_UNICODE) && ! JUCE_STRINGS_ARE_UNICODE
  8218. #error "JUCE_STRINGS_ARE_UNICODE is deprecated! All strings are now unicode by default."
  8219. #endif
  8220. class StringHolder
  8221. {
  8222. public:
  8223. StringHolder()
  8224. : refCount (0x3fffffff), allocatedNumChars (0)
  8225. {
  8226. text[0] = 0;
  8227. }
  8228. static juce_wchar* create (const size_t numChars)
  8229. {
  8230. StringHolder* const s = reinterpret_cast <StringHolder*> (juce_malloc (sizeof (StringHolder) + numChars * sizeof (juce_wchar)));
  8231. s->refCount = 0;
  8232. s->allocatedNumChars = numChars;
  8233. return &(s->text[0]);
  8234. }
  8235. static inline juce_wchar* getEmpty() throw()
  8236. {
  8237. return &(empty.text[0]);
  8238. }
  8239. static void retain (juce_wchar* const text) throw()
  8240. {
  8241. Atomic::increment (bufferFromText (text)->refCount);
  8242. }
  8243. static inline void release (StringHolder* const b) throw()
  8244. {
  8245. if (Atomic::decrementAndReturn (b->refCount) == -1 && b != &empty)
  8246. juce_free (b);
  8247. }
  8248. static void release (juce_wchar* const text) throw()
  8249. {
  8250. release (bufferFromText (text));
  8251. }
  8252. static juce_wchar* makeUnique (juce_wchar* const text)
  8253. {
  8254. StringHolder* const b = bufferFromText (text);
  8255. if (b->refCount <= 0)
  8256. return text;
  8257. juce_wchar* const newText = create (b->allocatedNumChars);
  8258. copyChars (newText, text, b->allocatedNumChars);
  8259. release (b);
  8260. return newText;
  8261. }
  8262. static juce_wchar* makeUniqueWithSize (juce_wchar* const text, size_t numChars)
  8263. {
  8264. StringHolder* const b = bufferFromText (text);
  8265. if (b->refCount <= 0 && b->allocatedNumChars >= numChars)
  8266. return text;
  8267. juce_wchar* const newText = create (jmax (b->allocatedNumChars, numChars));
  8268. copyChars (newText, text, b->allocatedNumChars);
  8269. release (b);
  8270. return newText;
  8271. }
  8272. static size_t getAllocatedNumChars (juce_wchar* const text) throw()
  8273. {
  8274. return bufferFromText (text)->allocatedNumChars;
  8275. }
  8276. static void copyChars (juce_wchar* const dest, const juce_wchar* const src, const size_t numChars) throw()
  8277. {
  8278. memcpy (dest, src, numChars * sizeof (juce_wchar));
  8279. dest [numChars] = 0;
  8280. }
  8281. int refCount;
  8282. size_t allocatedNumChars;
  8283. juce_wchar text[1];
  8284. static StringHolder empty;
  8285. private:
  8286. static inline StringHolder* bufferFromText (juce_wchar* const text) throw()
  8287. {
  8288. // (Can't use offsetof() here because of warnings about this not being a POD)
  8289. return reinterpret_cast <StringHolder*> (reinterpret_cast <char*> (text)
  8290. - (reinterpret_cast <size_t> (reinterpret_cast <StringHolder*> (1)->text) - 1));
  8291. }
  8292. };
  8293. StringHolder StringHolder::empty;
  8294. const String String::empty;
  8295. void String::createInternal (const juce_wchar* const t, const size_t numChars)
  8296. {
  8297. jassert (t[numChars] == 0); // must have a null terminator
  8298. text = StringHolder::create (numChars);
  8299. StringHolder::copyChars (text, t, numChars);
  8300. }
  8301. void String::appendInternal (const juce_wchar* const newText, const int numExtraChars)
  8302. {
  8303. if (numExtraChars > 0)
  8304. {
  8305. const int oldLen = length();
  8306. const int newTotalLen = oldLen + numExtraChars;
  8307. text = StringHolder::makeUniqueWithSize (text, newTotalLen);
  8308. StringHolder::copyChars (text + oldLen, newText, numExtraChars);
  8309. }
  8310. }
  8311. void String::preallocateStorage (const size_t numChars)
  8312. {
  8313. text = StringHolder::makeUniqueWithSize (text, numChars);
  8314. }
  8315. String::String() throw()
  8316. : text (StringHolder::getEmpty())
  8317. {
  8318. }
  8319. String::~String() throw()
  8320. {
  8321. StringHolder::release (text);
  8322. }
  8323. String::String (const String& other) throw()
  8324. : text (other.text)
  8325. {
  8326. StringHolder::retain (text);
  8327. }
  8328. void String::swapWith (String& other) throw()
  8329. {
  8330. swapVariables (text, other.text);
  8331. }
  8332. String& String::operator= (const String& other) throw()
  8333. {
  8334. juce_wchar* const newText = other.text;
  8335. StringHolder::retain (newText);
  8336. StringHolder::release (static_cast <juce_wchar*> (Atomic::swapPointers ((void* volatile*) &text, newText)));
  8337. return *this;
  8338. }
  8339. String::String (const size_t numChars, const int /*dummyVariable*/)
  8340. : text (StringHolder::create (numChars))
  8341. {
  8342. }
  8343. String::String (const String& stringToCopy, const size_t charsToAllocate)
  8344. {
  8345. const size_t otherSize = StringHolder::getAllocatedNumChars (stringToCopy.text);
  8346. text = StringHolder::create (jmax (charsToAllocate, otherSize));
  8347. StringHolder::copyChars (text, stringToCopy.text, otherSize);
  8348. }
  8349. String::String (const char* const t)
  8350. {
  8351. if (t != 0 && *t != 0)
  8352. {
  8353. const int len = CharacterFunctions::length (t);
  8354. text = StringHolder::create (len);
  8355. CharacterFunctions::copy (text, t, len + 1);
  8356. }
  8357. else
  8358. {
  8359. text = StringHolder::getEmpty();
  8360. }
  8361. }
  8362. String::String (const juce_wchar* const t)
  8363. {
  8364. if (t != 0 && *t != 0)
  8365. {
  8366. const int len = CharacterFunctions::length (t);
  8367. text = StringHolder::create (len);
  8368. StringHolder::copyChars (text, t, len);
  8369. }
  8370. else
  8371. {
  8372. text = StringHolder::getEmpty();
  8373. }
  8374. }
  8375. String::String (const char* const t, const size_t maxChars)
  8376. {
  8377. int i;
  8378. for (i = 0; (size_t) i < maxChars; ++i)
  8379. if (t[i] == 0)
  8380. break;
  8381. if (i > 0)
  8382. {
  8383. text = StringHolder::create (i);
  8384. CharacterFunctions::copy (text, t, i);
  8385. text[i] = 0;
  8386. }
  8387. else
  8388. {
  8389. text = StringHolder::getEmpty();
  8390. }
  8391. }
  8392. String::String (const juce_wchar* const t, const size_t maxChars)
  8393. {
  8394. int i;
  8395. for (i = 0; (size_t) i < maxChars; ++i)
  8396. if (t[i] == 0)
  8397. break;
  8398. if (i > 0)
  8399. {
  8400. text = StringHolder::create (i);
  8401. StringHolder::copyChars (text, t, i);
  8402. }
  8403. else
  8404. {
  8405. text = StringHolder::getEmpty();
  8406. }
  8407. }
  8408. const String String::charToString (const juce_wchar character)
  8409. {
  8410. juce_wchar temp[] = { character, 0 };
  8411. return String (temp);
  8412. }
  8413. namespace NumberToStringConverters
  8414. {
  8415. // pass in a pointer to the END of a buffer..
  8416. static juce_wchar* int64ToString (juce_wchar* t, const int64 n) throw()
  8417. {
  8418. *--t = 0;
  8419. int64 v = (n >= 0) ? n : -n;
  8420. do
  8421. {
  8422. *--t = (juce_wchar) (T('0') + (int) (v % 10));
  8423. v /= 10;
  8424. } while (v > 0);
  8425. if (n < 0)
  8426. *--t = T('-');
  8427. return t;
  8428. }
  8429. static juce_wchar* uint64ToString (juce_wchar* t, int64 v) throw()
  8430. {
  8431. *--t = 0;
  8432. do
  8433. {
  8434. *--t = (juce_wchar) (T('0') + (int) (v % 10));
  8435. v /= 10;
  8436. } while (v > 0);
  8437. return t;
  8438. }
  8439. static juce_wchar* intToString (juce_wchar* t, const int n) throw()
  8440. {
  8441. if (n == (int) 0x80000000) // (would cause an overflow)
  8442. return int64ToString (t, n);
  8443. *--t = 0;
  8444. int v = abs (n);
  8445. do
  8446. {
  8447. *--t = (juce_wchar) (T('0') + (v % 10));
  8448. v /= 10;
  8449. } while (v > 0);
  8450. if (n < 0)
  8451. *--t = T('-');
  8452. return t;
  8453. }
  8454. static juce_wchar* uintToString (juce_wchar* t, unsigned int v) throw()
  8455. {
  8456. *--t = 0;
  8457. do
  8458. {
  8459. *--t = (juce_wchar) (T('0') + (v % 10));
  8460. v /= 10;
  8461. } while (v > 0);
  8462. return t;
  8463. }
  8464. static juce_wchar getDecimalPoint()
  8465. {
  8466. #if JUCE_WINDOWS && _MSC_VER < 1400
  8467. static juce_wchar dp = std::_USE (std::locale(), std::numpunct <wchar_t>).decimal_point();
  8468. #else
  8469. static juce_wchar dp = std::use_facet <std::numpunct <wchar_t> > (std::locale()).decimal_point();
  8470. #endif
  8471. return dp;
  8472. }
  8473. static juce_wchar* doubleToString (juce_wchar* buffer, int numChars, double n, int numDecPlaces, size_t& len) throw()
  8474. {
  8475. if (numDecPlaces > 0 && n > -1.0e20 && n < 1.0e20)
  8476. {
  8477. juce_wchar* const end = buffer + numChars;
  8478. juce_wchar* t = end;
  8479. int64 v = (int64) (pow (10.0, numDecPlaces) * fabs (n) + 0.5);
  8480. *--t = (juce_wchar) 0;
  8481. while (numDecPlaces >= 0 || v > 0)
  8482. {
  8483. if (numDecPlaces == 0)
  8484. *--t = getDecimalPoint();
  8485. *--t = (juce_wchar) (T('0') + (v % 10));
  8486. v /= 10;
  8487. --numDecPlaces;
  8488. }
  8489. if (n < 0)
  8490. *--t = T('-');
  8491. len = end - t - 1;
  8492. return t;
  8493. }
  8494. else
  8495. {
  8496. #if JUCE_WIN32
  8497. #if _MSC_VER <= 1200
  8498. len = _snwprintf (buffer, numChars, L"%.9g", n);
  8499. #else
  8500. len = _snwprintf_s (buffer, numChars, _TRUNCATE, L"%.9g", n);
  8501. #endif
  8502. #else
  8503. len = swprintf (buffer, numChars, L"%.9g", n);
  8504. #endif
  8505. return buffer;
  8506. }
  8507. }
  8508. }
  8509. String::String (const int number)
  8510. {
  8511. juce_wchar buffer [16];
  8512. juce_wchar* const end = buffer + numElementsInArray (buffer);
  8513. juce_wchar* const start = NumberToStringConverters::intToString (end, number);
  8514. createInternal (start, end - start - 1);
  8515. }
  8516. String::String (const unsigned int number)
  8517. {
  8518. juce_wchar buffer [16];
  8519. juce_wchar* const end = buffer + numElementsInArray (buffer);
  8520. juce_wchar* const start = NumberToStringConverters::uintToString (end, number);
  8521. createInternal (start, end - start - 1);
  8522. }
  8523. String::String (const short number)
  8524. {
  8525. juce_wchar buffer [16];
  8526. juce_wchar* const end = buffer + numElementsInArray (buffer);
  8527. juce_wchar* const start = NumberToStringConverters::intToString (end, (int) number);
  8528. createInternal (start, end - start - 1);
  8529. }
  8530. String::String (const unsigned short number)
  8531. {
  8532. juce_wchar buffer [16];
  8533. juce_wchar* const end = buffer + numElementsInArray (buffer);
  8534. juce_wchar* const start = NumberToStringConverters::uintToString (end, (unsigned int) number);
  8535. createInternal (start, end - start - 1);
  8536. }
  8537. String::String (const int64 number)
  8538. {
  8539. juce_wchar buffer [32];
  8540. juce_wchar* const end = buffer + numElementsInArray (buffer);
  8541. juce_wchar* const start = NumberToStringConverters::int64ToString (end, number);
  8542. createInternal (start, end - start - 1);
  8543. }
  8544. String::String (const uint64 number)
  8545. {
  8546. juce_wchar buffer [32];
  8547. juce_wchar* const end = buffer + numElementsInArray (buffer);
  8548. juce_wchar* const start = NumberToStringConverters::uint64ToString (end, number);
  8549. createInternal (start, end - start - 1);
  8550. }
  8551. String::String (const float number, const int numberOfDecimalPlaces)
  8552. {
  8553. juce_wchar buffer [48];
  8554. size_t len;
  8555. juce_wchar* start = NumberToStringConverters::doubleToString (buffer, numElementsInArray (buffer), (double) number, numberOfDecimalPlaces, len);
  8556. createInternal (start, len);
  8557. }
  8558. String::String (const double number, const int numberOfDecimalPlaces)
  8559. {
  8560. juce_wchar buffer [48];
  8561. size_t len;
  8562. juce_wchar* start = NumberToStringConverters::doubleToString (buffer, numElementsInArray (buffer), number, numberOfDecimalPlaces, len);
  8563. createInternal (start, len);
  8564. }
  8565. int String::length() const throw()
  8566. {
  8567. return CharacterFunctions::length (text);
  8568. }
  8569. int String::hashCode() const throw()
  8570. {
  8571. const juce_wchar* t = text;
  8572. int result = 0;
  8573. while (*t != (juce_wchar) 0)
  8574. result = 31 * result + *t++;
  8575. return result;
  8576. }
  8577. int64 String::hashCode64() const throw()
  8578. {
  8579. const juce_wchar* t = text;
  8580. int64 result = 0;
  8581. while (*t != (juce_wchar) 0)
  8582. result = 101 * result + *t++;
  8583. return result;
  8584. }
  8585. bool JUCE_CALLTYPE operator== (const String& string1, const String& string2) throw()
  8586. {
  8587. return string1.compare (string2) == 0;
  8588. }
  8589. bool JUCE_CALLTYPE operator== (const String& string1, const char* string2) throw()
  8590. {
  8591. return string1.compare (string2) == 0;
  8592. }
  8593. bool JUCE_CALLTYPE operator== (const String& string1, const juce_wchar* string2) throw()
  8594. {
  8595. return string1.compare (string2) == 0;
  8596. }
  8597. bool JUCE_CALLTYPE operator!= (const String& string1, const String& string2) throw()
  8598. {
  8599. return string1.compare (string2) != 0;
  8600. }
  8601. bool JUCE_CALLTYPE operator!= (const String& string1, const char* string2) throw()
  8602. {
  8603. return string1.compare (string2) != 0;
  8604. }
  8605. bool JUCE_CALLTYPE operator!= (const String& string1, const juce_wchar* string2) throw()
  8606. {
  8607. return string1.compare (string2) != 0;
  8608. }
  8609. bool JUCE_CALLTYPE operator> (const String& string1, const String& string2) throw()
  8610. {
  8611. return string1.compare (string2) > 0;
  8612. }
  8613. bool JUCE_CALLTYPE operator< (const String& string1, const String& string2) throw()
  8614. {
  8615. return string1.compare (string2) < 0;
  8616. }
  8617. bool JUCE_CALLTYPE operator>= (const String& string1, const String& string2) throw()
  8618. {
  8619. return string1.compare (string2) >= 0;
  8620. }
  8621. bool JUCE_CALLTYPE operator<= (const String& string1, const String& string2) throw()
  8622. {
  8623. return string1.compare (string2) <= 0;
  8624. }
  8625. bool String::equalsIgnoreCase (const juce_wchar* t) const throw()
  8626. {
  8627. return t != 0 ? CharacterFunctions::compareIgnoreCase (text, t) == 0
  8628. : isEmpty();
  8629. }
  8630. bool String::equalsIgnoreCase (const String& other) const throw()
  8631. {
  8632. return text == other.text
  8633. || CharacterFunctions::compareIgnoreCase (text, other.text) == 0;
  8634. }
  8635. int String::compare (const String& other) const throw()
  8636. {
  8637. return (text == other.text) ? 0 : CharacterFunctions::compare (text, other.text);
  8638. }
  8639. int String::compare (const char* other) const throw()
  8640. {
  8641. return other == 0 ? isEmpty() : CharacterFunctions::compare (text, other);
  8642. }
  8643. int String::compare (const juce_wchar* other) const throw()
  8644. {
  8645. return other == 0 ? isEmpty() : CharacterFunctions::compare (text, other);
  8646. }
  8647. int String::compareIgnoreCase (const String& other) const throw()
  8648. {
  8649. return (text == other.text) ? 0 : CharacterFunctions::compareIgnoreCase (text, other.text);
  8650. }
  8651. int String::compareLexicographically (const String& other) const throw()
  8652. {
  8653. const juce_wchar* s1 = text;
  8654. while (*s1 != 0 && ! CharacterFunctions::isLetterOrDigit (*s1))
  8655. ++s1;
  8656. const juce_wchar* s2 = other.text;
  8657. while (*s2 != 0 && ! CharacterFunctions::isLetterOrDigit (*s2))
  8658. ++s2;
  8659. return CharacterFunctions::compareIgnoreCase (s1, s2);
  8660. }
  8661. String& String::operator+= (const juce_wchar* const t)
  8662. {
  8663. if (t != 0)
  8664. appendInternal (t, CharacterFunctions::length (t));
  8665. return *this;
  8666. }
  8667. String& String::operator+= (const String& other)
  8668. {
  8669. if (isEmpty())
  8670. operator= (other);
  8671. else
  8672. appendInternal (other.text, other.length());
  8673. return *this;
  8674. }
  8675. String& String::operator+= (const char ch)
  8676. {
  8677. const juce_wchar asString[] = { (juce_wchar) ch, 0 };
  8678. return operator+= ((const juce_wchar*) asString);
  8679. }
  8680. String& String::operator+= (const juce_wchar ch)
  8681. {
  8682. const juce_wchar asString[] = { (juce_wchar) ch, 0 };
  8683. return operator+= ((const juce_wchar*) asString);
  8684. }
  8685. String& String::operator+= (const int number)
  8686. {
  8687. juce_wchar buffer [16];
  8688. juce_wchar* const end = buffer + numElementsInArray (buffer);
  8689. juce_wchar* const start = NumberToStringConverters::intToString (end, number);
  8690. appendInternal (start, (int) (end - start));
  8691. return *this;
  8692. }
  8693. String& String::operator+= (const unsigned int number)
  8694. {
  8695. juce_wchar buffer [16];
  8696. juce_wchar* const end = buffer + numElementsInArray (buffer);
  8697. juce_wchar* const start = NumberToStringConverters::uintToString (end, number);
  8698. appendInternal (start, (int) (end - start));
  8699. return *this;
  8700. }
  8701. void String::append (const juce_wchar* const other, const int howMany)
  8702. {
  8703. if (howMany > 0)
  8704. {
  8705. int i;
  8706. for (i = 0; i < howMany; ++i)
  8707. if (other[i] == 0)
  8708. break;
  8709. appendInternal (other, i);
  8710. }
  8711. }
  8712. const String JUCE_CALLTYPE operator+ (const char* const string1, const String& string2)
  8713. {
  8714. String s (string1);
  8715. return s += string2;
  8716. }
  8717. const String JUCE_CALLTYPE operator+ (const juce_wchar* const string1, const String& string2)
  8718. {
  8719. String s (string1);
  8720. return s += string2;
  8721. }
  8722. const String JUCE_CALLTYPE operator+ (const char string1, const String& string2)
  8723. {
  8724. return String::charToString (string1) + string2;
  8725. }
  8726. const String JUCE_CALLTYPE operator+ (const juce_wchar string1, const String& string2)
  8727. {
  8728. return String::charToString (string1) + string2;
  8729. }
  8730. const String JUCE_CALLTYPE operator+ (String string1, const String& string2)
  8731. {
  8732. return string1 += string2;
  8733. }
  8734. const String JUCE_CALLTYPE operator+ (String string1, const char* const string2)
  8735. {
  8736. return string1 += string2;
  8737. }
  8738. const String JUCE_CALLTYPE operator+ (String string1, const juce_wchar* const string2)
  8739. {
  8740. return string1 += string2;
  8741. }
  8742. const String JUCE_CALLTYPE operator+ (String string1, const char string2)
  8743. {
  8744. return string1 += string2;
  8745. }
  8746. const String JUCE_CALLTYPE operator+ (String string1, const juce_wchar string2)
  8747. {
  8748. return string1 += string2;
  8749. }
  8750. String& JUCE_CALLTYPE operator<< (String& string1, const char characterToAppend)
  8751. {
  8752. return string1 += characterToAppend;
  8753. }
  8754. String& JUCE_CALLTYPE operator<< (String& string1, const juce_wchar characterToAppend)
  8755. {
  8756. return string1 += characterToAppend;
  8757. }
  8758. String& JUCE_CALLTYPE operator<< (String& string1, const char* const string2)
  8759. {
  8760. return string1 += string2;
  8761. }
  8762. String& JUCE_CALLTYPE operator<< (String& string1, const juce_wchar* const string2)
  8763. {
  8764. return string1 += string2;
  8765. }
  8766. String& JUCE_CALLTYPE operator<< (String& string1, const String& string2)
  8767. {
  8768. return string1 += string2;
  8769. }
  8770. String& JUCE_CALLTYPE operator<< (String& string1, const short number)
  8771. {
  8772. return string1 += (int) number;
  8773. }
  8774. String& JUCE_CALLTYPE operator<< (String& string1, const int number)
  8775. {
  8776. return string1 += number;
  8777. }
  8778. String& JUCE_CALLTYPE operator<< (String& string1, const unsigned int number)
  8779. {
  8780. return string1 += number;
  8781. }
  8782. String& JUCE_CALLTYPE operator<< (String& string1, const long number)
  8783. {
  8784. return string1 += (int) number;
  8785. }
  8786. String& JUCE_CALLTYPE operator<< (String& string1, const unsigned long number)
  8787. {
  8788. return string1 += (unsigned int) number;
  8789. }
  8790. String& JUCE_CALLTYPE operator<< (String& string1, const float number)
  8791. {
  8792. return string1 += String (number);
  8793. }
  8794. String& JUCE_CALLTYPE operator<< (String& string1, const double number)
  8795. {
  8796. return string1 += String (number);
  8797. }
  8798. OutputStream& JUCE_CALLTYPE operator<< (OutputStream& stream, const String& text)
  8799. {
  8800. // (This avoids using toUTF8() to prevent the memory bloat that it would leave behind
  8801. // if lots of large, persistent strings were to be written to streams).
  8802. const int numBytes = text.getNumBytesAsUTF8();
  8803. HeapBlock<char> temp (numBytes + 1);
  8804. text.copyToUTF8 (temp, numBytes + 1);
  8805. stream.write (temp, numBytes);
  8806. return stream;
  8807. }
  8808. int String::indexOfChar (const juce_wchar character) const throw()
  8809. {
  8810. const juce_wchar* t = text;
  8811. for (;;)
  8812. {
  8813. if (*t == character)
  8814. return (int) (t - text);
  8815. if (*t++ == 0)
  8816. return -1;
  8817. }
  8818. }
  8819. int String::lastIndexOfChar (const juce_wchar character) const throw()
  8820. {
  8821. for (int i = length(); --i >= 0;)
  8822. if (text[i] == character)
  8823. return i;
  8824. return -1;
  8825. }
  8826. int String::indexOf (const juce_wchar* const t) const throw()
  8827. {
  8828. const juce_wchar* const r = CharacterFunctions::find (text, t);
  8829. return (r == 0) ? -1
  8830. : (int) (r - text);
  8831. }
  8832. int String::indexOfChar (const int startIndex,
  8833. const juce_wchar character) const throw()
  8834. {
  8835. if (startIndex >= 0 && startIndex >= length())
  8836. return -1;
  8837. const juce_wchar* t = text + jmax (0, startIndex);
  8838. for (;;)
  8839. {
  8840. if (*t == character)
  8841. return (int) (t - text);
  8842. if (*t++ == 0)
  8843. return -1;
  8844. }
  8845. }
  8846. int String::indexOfAnyOf (const juce_wchar* const charactersToLookFor,
  8847. const int startIndex,
  8848. const bool ignoreCase) const throw()
  8849. {
  8850. if (charactersToLookFor == 0
  8851. || (startIndex >= 0 && startIndex >= length()))
  8852. return -1;
  8853. const juce_wchar* t = text + jmax (0, startIndex);
  8854. while (*t != 0)
  8855. {
  8856. if (CharacterFunctions::indexOfChar (charactersToLookFor, *t, ignoreCase) >= 0)
  8857. return (int) (t - text);
  8858. ++t;
  8859. }
  8860. return -1;
  8861. }
  8862. int String::indexOf (const int startIndex,
  8863. const juce_wchar* const other) const throw()
  8864. {
  8865. if (other == 0 || startIndex >= length())
  8866. return -1;
  8867. const juce_wchar* const found = CharacterFunctions::find (text + jmax (0, startIndex), other);
  8868. return (found == 0) ? -1
  8869. : (int) (found - text);
  8870. }
  8871. int String::indexOfIgnoreCase (const juce_wchar* const other) const throw()
  8872. {
  8873. if (other != 0 && *other != 0)
  8874. {
  8875. const int len = CharacterFunctions::length (other);
  8876. const int end = length() - len;
  8877. for (int i = 0; i <= end; ++i)
  8878. if (CharacterFunctions::compareIgnoreCase (text + i, other, len) == 0)
  8879. return i;
  8880. }
  8881. return -1;
  8882. }
  8883. int String::indexOfIgnoreCase (const int startIndex,
  8884. const juce_wchar* const other) const throw()
  8885. {
  8886. if (other != 0 && *other != 0)
  8887. {
  8888. const int len = CharacterFunctions::length (other);
  8889. const int end = length() - len;
  8890. for (int i = jmax (0, startIndex); i <= end; ++i)
  8891. if (CharacterFunctions::compareIgnoreCase (text + i, other, len) == 0)
  8892. return i;
  8893. }
  8894. return -1;
  8895. }
  8896. int String::lastIndexOf (const juce_wchar* const other) const throw()
  8897. {
  8898. if (other != 0 && *other != 0)
  8899. {
  8900. const int len = CharacterFunctions::length (other);
  8901. int i = length() - len;
  8902. if (i >= 0)
  8903. {
  8904. const juce_wchar* n = text + i;
  8905. while (i >= 0)
  8906. {
  8907. if (CharacterFunctions::compare (n--, other, len) == 0)
  8908. return i;
  8909. --i;
  8910. }
  8911. }
  8912. }
  8913. return -1;
  8914. }
  8915. int String::lastIndexOfIgnoreCase (const juce_wchar* const other) const throw()
  8916. {
  8917. if (other != 0 && *other != 0)
  8918. {
  8919. const int len = CharacterFunctions::length (other);
  8920. int i = length() - len;
  8921. if (i >= 0)
  8922. {
  8923. const juce_wchar* n = text + i;
  8924. while (i >= 0)
  8925. {
  8926. if (CharacterFunctions::compareIgnoreCase (n--, other, len) == 0)
  8927. return i;
  8928. --i;
  8929. }
  8930. }
  8931. }
  8932. return -1;
  8933. }
  8934. int String::lastIndexOfAnyOf (const juce_wchar* const charactersToLookFor,
  8935. const bool ignoreCase) const throw()
  8936. {
  8937. for (int i = length(); --i >= 0;)
  8938. if (CharacterFunctions::indexOfChar (charactersToLookFor, text[i], ignoreCase) >= 0)
  8939. return i;
  8940. return -1;
  8941. }
  8942. bool String::contains (const juce_wchar* const other) const throw()
  8943. {
  8944. return indexOf (other) >= 0;
  8945. }
  8946. bool String::containsChar (const juce_wchar character) const throw()
  8947. {
  8948. return indexOfChar (character) >= 0;
  8949. }
  8950. bool String::containsIgnoreCase (const juce_wchar* const t) const throw()
  8951. {
  8952. return indexOfIgnoreCase (t) >= 0;
  8953. }
  8954. int String::indexOfWholeWord (const juce_wchar* const word) const throw()
  8955. {
  8956. if (word != 0 && *word != 0)
  8957. {
  8958. const int wordLen = CharacterFunctions::length (word);
  8959. const int end = length() - wordLen;
  8960. const juce_wchar* t = text;
  8961. for (int i = 0; i <= end; ++i)
  8962. {
  8963. if (CharacterFunctions::compare (t, word, wordLen) == 0
  8964. && (i == 0 || ! CharacterFunctions::isLetterOrDigit (* (t - 1)))
  8965. && ! CharacterFunctions::isLetterOrDigit (t [wordLen]))
  8966. {
  8967. return i;
  8968. }
  8969. ++t;
  8970. }
  8971. }
  8972. return -1;
  8973. }
  8974. int String::indexOfWholeWordIgnoreCase (const juce_wchar* const word) const throw()
  8975. {
  8976. if (word != 0 && *word != 0)
  8977. {
  8978. const int wordLen = CharacterFunctions::length (word);
  8979. const int end = length() - wordLen;
  8980. const juce_wchar* t = text;
  8981. for (int i = 0; i <= end; ++i)
  8982. {
  8983. if (CharacterFunctions::compareIgnoreCase (t, word, wordLen) == 0
  8984. && (i == 0 || ! CharacterFunctions::isLetterOrDigit (* (t - 1)))
  8985. && ! CharacterFunctions::isLetterOrDigit (t [wordLen]))
  8986. {
  8987. return i;
  8988. }
  8989. ++t;
  8990. }
  8991. }
  8992. return -1;
  8993. }
  8994. bool String::containsWholeWord (const juce_wchar* const wordToLookFor) const throw()
  8995. {
  8996. return indexOfWholeWord (wordToLookFor) >= 0;
  8997. }
  8998. bool String::containsWholeWordIgnoreCase (const juce_wchar* const wordToLookFor) const throw()
  8999. {
  9000. return indexOfWholeWordIgnoreCase (wordToLookFor) >= 0;
  9001. }
  9002. static int indexOfMatch (const juce_wchar* const wildcard,
  9003. const juce_wchar* const test,
  9004. const bool ignoreCase) throw()
  9005. {
  9006. int start = 0;
  9007. while (test [start] != 0)
  9008. {
  9009. int i = 0;
  9010. for (;;)
  9011. {
  9012. const juce_wchar wc = wildcard [i];
  9013. const juce_wchar c = test [i + start];
  9014. if (wc == c
  9015. || (ignoreCase && CharacterFunctions::toLowerCase (wc) == CharacterFunctions::toLowerCase (c))
  9016. || (wc == T('?') && c != 0))
  9017. {
  9018. if (wc == 0)
  9019. return start;
  9020. ++i;
  9021. }
  9022. else
  9023. {
  9024. if (wc == T('*') && (wildcard [i + 1] == 0
  9025. || indexOfMatch (wildcard + i + 1,
  9026. test + start + i,
  9027. ignoreCase) >= 0))
  9028. {
  9029. return start;
  9030. }
  9031. break;
  9032. }
  9033. }
  9034. ++start;
  9035. }
  9036. return -1;
  9037. }
  9038. bool String::matchesWildcard (const juce_wchar* wildcard, const bool ignoreCase) const throw()
  9039. {
  9040. int i = 0;
  9041. for (;;)
  9042. {
  9043. const juce_wchar wc = wildcard [i];
  9044. const juce_wchar c = text [i];
  9045. if (wc == c
  9046. || (ignoreCase && CharacterFunctions::toLowerCase (wc) == CharacterFunctions::toLowerCase (c))
  9047. || (wc == T('?') && c != 0))
  9048. {
  9049. if (wc == 0)
  9050. return true;
  9051. ++i;
  9052. }
  9053. else
  9054. {
  9055. return wc == T('*') && (wildcard [i + 1] == 0
  9056. || indexOfMatch (wildcard + i + 1,
  9057. text + i,
  9058. ignoreCase) >= 0);
  9059. }
  9060. }
  9061. }
  9062. const String String::repeatedString (const juce_wchar* const stringToRepeat, int numberOfTimesToRepeat)
  9063. {
  9064. const int len = CharacterFunctions::length (stringToRepeat);
  9065. String result ((size_t) (len * numberOfTimesToRepeat + 1), (int) 0);
  9066. juce_wchar* n = result.text;
  9067. *n = 0;
  9068. while (--numberOfTimesToRepeat >= 0)
  9069. {
  9070. StringHolder::copyChars (n, stringToRepeat, len);
  9071. n += len;
  9072. }
  9073. return result;
  9074. }
  9075. const String String::paddedLeft (const juce_wchar padCharacter, int minimumLength) const
  9076. {
  9077. jassert (padCharacter != 0);
  9078. const int len = length();
  9079. if (len >= minimumLength || padCharacter == 0)
  9080. return *this;
  9081. String result ((size_t) minimumLength + 1, (int) 0);
  9082. juce_wchar* n = result.text;
  9083. minimumLength -= len;
  9084. while (--minimumLength >= 0)
  9085. *n++ = padCharacter;
  9086. StringHolder::copyChars (n, text, len);
  9087. return result;
  9088. }
  9089. const String String::paddedRight (const juce_wchar padCharacter, int minimumLength) const
  9090. {
  9091. jassert (padCharacter != 0);
  9092. const int len = length();
  9093. if (len >= minimumLength || padCharacter == 0)
  9094. return *this;
  9095. String result (*this, (size_t) minimumLength);
  9096. juce_wchar* n = result.text + len;
  9097. minimumLength -= len;
  9098. while (--minimumLength >= 0)
  9099. *n++ = padCharacter;
  9100. *n = 0;
  9101. return result;
  9102. }
  9103. const String String::replaceSection (int index, int numCharsToReplace,
  9104. const juce_wchar* const stringToInsert) const
  9105. {
  9106. if (index < 0)
  9107. {
  9108. // a negative index to replace from?
  9109. jassertfalse
  9110. index = 0;
  9111. }
  9112. if (numCharsToReplace < 0)
  9113. {
  9114. // replacing a negative number of characters?
  9115. numCharsToReplace = 0;
  9116. jassertfalse;
  9117. }
  9118. const int len = length();
  9119. if (index + numCharsToReplace > len)
  9120. {
  9121. if (index > len)
  9122. {
  9123. // replacing beyond the end of the string?
  9124. index = len;
  9125. jassertfalse
  9126. }
  9127. numCharsToReplace = len - index;
  9128. }
  9129. const int newStringLen = (stringToInsert != 0) ? CharacterFunctions::length (stringToInsert) : 0;
  9130. const int newTotalLen = len + newStringLen - numCharsToReplace;
  9131. if (newTotalLen <= 0)
  9132. return String::empty;
  9133. String result ((size_t) newTotalLen, (int) 0);
  9134. StringHolder::copyChars (result.text, text, index);
  9135. if (newStringLen > 0)
  9136. StringHolder::copyChars (result.text + index, stringToInsert, newStringLen);
  9137. const int endStringLen = newTotalLen - (index + newStringLen);
  9138. if (endStringLen > 0)
  9139. StringHolder::copyChars (result.text + (index + newStringLen),
  9140. text + (index + numCharsToReplace),
  9141. endStringLen);
  9142. return result;
  9143. }
  9144. const String String::replace (const juce_wchar* const stringToReplace,
  9145. const juce_wchar* const stringToInsert,
  9146. const bool ignoreCase) const
  9147. {
  9148. const int stringToReplaceLen = CharacterFunctions::length (stringToReplace);
  9149. const int stringToInsertLen = CharacterFunctions::length (stringToInsert);
  9150. int i = 0;
  9151. String result (*this);
  9152. while ((i = (ignoreCase ? result.indexOfIgnoreCase (i, stringToReplace)
  9153. : result.indexOf (i, stringToReplace))) >= 0)
  9154. {
  9155. result = result.replaceSection (i, stringToReplaceLen, stringToInsert);
  9156. i += stringToInsertLen;
  9157. }
  9158. return result;
  9159. }
  9160. const String String::replaceCharacter (const juce_wchar charToReplace, const juce_wchar charToInsert) const
  9161. {
  9162. const int index = indexOfChar (charToReplace);
  9163. if (index < 0)
  9164. return *this;
  9165. String result (*this, size_t());
  9166. juce_wchar* t = result.text + index;
  9167. while (*t != 0)
  9168. {
  9169. if (*t == charToReplace)
  9170. *t = charToInsert;
  9171. ++t;
  9172. }
  9173. return result;
  9174. }
  9175. const String String::replaceCharacters (const String& charactersToReplace,
  9176. const juce_wchar* const charactersToInsertInstead) const
  9177. {
  9178. String result (*this, size_t());
  9179. juce_wchar* t = result.text;
  9180. const int len2 = CharacterFunctions::length (charactersToInsertInstead);
  9181. // the two strings passed in are supposed to be the same length!
  9182. jassert (len2 == charactersToReplace.length());
  9183. while (*t != 0)
  9184. {
  9185. const int index = charactersToReplace.indexOfChar (*t);
  9186. if (((unsigned int) index) < (unsigned int) len2)
  9187. *t = charactersToInsertInstead [index];
  9188. ++t;
  9189. }
  9190. return result;
  9191. }
  9192. bool String::startsWith (const juce_wchar* const other) const throw()
  9193. {
  9194. return other != 0
  9195. && CharacterFunctions::compare (text, other, CharacterFunctions::length (other)) == 0;
  9196. }
  9197. bool String::startsWithIgnoreCase (const juce_wchar* const other) const throw()
  9198. {
  9199. return other != 0
  9200. && CharacterFunctions::compareIgnoreCase (text, other, CharacterFunctions::length (other)) == 0;
  9201. }
  9202. bool String::startsWithChar (const juce_wchar character) const throw()
  9203. {
  9204. jassert (character != 0); // strings can't contain a null character!
  9205. return text[0] == character;
  9206. }
  9207. bool String::endsWithChar (const juce_wchar character) const throw()
  9208. {
  9209. jassert (character != 0); // strings can't contain a null character!
  9210. return text[0] != 0
  9211. && text [length() - 1] == character;
  9212. }
  9213. bool String::endsWith (const juce_wchar* const other) const throw()
  9214. {
  9215. if (other == 0)
  9216. return false;
  9217. const int thisLen = length();
  9218. const int otherLen = CharacterFunctions::length (other);
  9219. return thisLen >= otherLen
  9220. && CharacterFunctions::compare (text + thisLen - otherLen, other) == 0;
  9221. }
  9222. bool String::endsWithIgnoreCase (const juce_wchar* const other) const throw()
  9223. {
  9224. if (other == 0)
  9225. return false;
  9226. const int thisLen = length();
  9227. const int otherLen = CharacterFunctions::length (other);
  9228. return thisLen >= otherLen
  9229. && CharacterFunctions::compareIgnoreCase (text + thisLen - otherLen, other) == 0;
  9230. }
  9231. const String String::toUpperCase() const
  9232. {
  9233. String result (*this, size_t());
  9234. CharacterFunctions::toUpperCase (result.text);
  9235. return result;
  9236. }
  9237. const String String::toLowerCase() const
  9238. {
  9239. String result (*this, size_t());
  9240. CharacterFunctions::toLowerCase (result.text);
  9241. return result;
  9242. }
  9243. juce_wchar& String::operator[] (const int index)
  9244. {
  9245. jassert (((unsigned int) index) <= (unsigned int) length());
  9246. text = StringHolder::makeUnique (text);
  9247. return text [index];
  9248. }
  9249. juce_wchar String::getLastCharacter() const throw()
  9250. {
  9251. return isEmpty() ? juce_wchar() : text [length() - 1];
  9252. }
  9253. const String String::substring (int start, int end) const
  9254. {
  9255. if (start < 0)
  9256. start = 0;
  9257. else if (end <= start)
  9258. return empty;
  9259. int len = 0;
  9260. const juce_wchar* const t = text;
  9261. while (len <= end && t [len] != 0)
  9262. ++len;
  9263. if (end >= len)
  9264. {
  9265. if (start == 0)
  9266. return *this;
  9267. end = len;
  9268. }
  9269. return String (text + start, end - start);
  9270. }
  9271. const String String::substring (const int start) const
  9272. {
  9273. if (start <= 0)
  9274. return *this;
  9275. const int len = length();
  9276. if (start >= len)
  9277. return empty;
  9278. else
  9279. return String (text + start, len - start);
  9280. }
  9281. const String String::dropLastCharacters (const int numberToDrop) const
  9282. {
  9283. return String (text, jmax (0, length() - numberToDrop));
  9284. }
  9285. const String String::getLastCharacters (const int numCharacters) const
  9286. {
  9287. return String (text + jmax (0, length() - jmax (0, numCharacters)));
  9288. }
  9289. const String String::fromFirstOccurrenceOf (const juce_wchar* const sub,
  9290. const bool includeSubString,
  9291. const bool ignoreCase) const
  9292. {
  9293. const int i = ignoreCase ? indexOfIgnoreCase (sub)
  9294. : indexOf (sub);
  9295. if (i < 0)
  9296. return empty;
  9297. else
  9298. return substring (includeSubString ? i : i + CharacterFunctions::length (sub));
  9299. }
  9300. const String String::fromLastOccurrenceOf (const juce_wchar* const sub,
  9301. const bool includeSubString,
  9302. const bool ignoreCase) const
  9303. {
  9304. const int i = ignoreCase ? lastIndexOfIgnoreCase (sub)
  9305. : lastIndexOf (sub);
  9306. if (i < 0)
  9307. return *this;
  9308. else
  9309. return substring (includeSubString ? i : i + CharacterFunctions::length (sub));
  9310. }
  9311. const String String::upToFirstOccurrenceOf (const juce_wchar* const sub,
  9312. const bool includeSubString,
  9313. const bool ignoreCase) const
  9314. {
  9315. const int i = ignoreCase ? indexOfIgnoreCase (sub)
  9316. : indexOf (sub);
  9317. if (i < 0)
  9318. return *this;
  9319. else
  9320. return substring (0, includeSubString ? i + CharacterFunctions::length (sub) : i);
  9321. }
  9322. const String String::upToLastOccurrenceOf (const juce_wchar* const sub,
  9323. const bool includeSubString,
  9324. const bool ignoreCase) const
  9325. {
  9326. const int i = ignoreCase ? lastIndexOfIgnoreCase (sub)
  9327. : lastIndexOf (sub);
  9328. if (i < 0)
  9329. return *this;
  9330. return substring (0, includeSubString ? i + CharacterFunctions::length (sub) : i);
  9331. }
  9332. bool String::isQuotedString() const
  9333. {
  9334. const String trimmed (trimStart());
  9335. return trimmed[0] == T('"')
  9336. || trimmed[0] == T('\'');
  9337. }
  9338. const String String::unquoted() const
  9339. {
  9340. String s (*this);
  9341. if (s.text[0] == T('"') || s.text[0] == T('\''))
  9342. s = s.substring (1);
  9343. const int lastCharIndex = s.length() - 1;
  9344. if (lastCharIndex >= 0
  9345. && (s [lastCharIndex] == T('"') || s[lastCharIndex] == T('\'')))
  9346. s [lastCharIndex] = 0;
  9347. return s;
  9348. }
  9349. const String String::quoted (const juce_wchar quoteCharacter) const
  9350. {
  9351. if (isEmpty())
  9352. return charToString (quoteCharacter) + quoteCharacter;
  9353. String t (*this);
  9354. if (! t.startsWithChar (quoteCharacter))
  9355. t = charToString (quoteCharacter) + t;
  9356. if (! t.endsWithChar (quoteCharacter))
  9357. t += quoteCharacter;
  9358. return t;
  9359. }
  9360. const String String::trim() const
  9361. {
  9362. if (isEmpty())
  9363. return empty;
  9364. int start = 0;
  9365. while (CharacterFunctions::isWhitespace (text [start]))
  9366. ++start;
  9367. const int len = length();
  9368. int end = len - 1;
  9369. while ((end >= start) && CharacterFunctions::isWhitespace (text [end]))
  9370. --end;
  9371. ++end;
  9372. if (end <= start)
  9373. return empty;
  9374. else if (start > 0 || end < len)
  9375. return String (text + start, end - start);
  9376. else
  9377. return *this;
  9378. }
  9379. const String String::trimStart() const
  9380. {
  9381. if (isEmpty())
  9382. return empty;
  9383. const juce_wchar* t = text;
  9384. while (CharacterFunctions::isWhitespace (*t))
  9385. ++t;
  9386. if (t == text)
  9387. return *this;
  9388. else
  9389. return String (t);
  9390. }
  9391. const String String::trimEnd() const
  9392. {
  9393. if (isEmpty())
  9394. return empty;
  9395. const juce_wchar* endT = text + (length() - 1);
  9396. while ((endT >= text) && CharacterFunctions::isWhitespace (*endT))
  9397. --endT;
  9398. return String (text, (int) (++endT - text));
  9399. }
  9400. const String String::trimCharactersAtStart (const juce_wchar* charactersToTrim) const
  9401. {
  9402. jassert (charactersToTrim != 0);
  9403. if (isEmpty())
  9404. return empty;
  9405. const juce_wchar* t = text;
  9406. while (CharacterFunctions::indexOfCharFast (charactersToTrim, *t) >= 0)
  9407. ++t;
  9408. if (t == text)
  9409. return *this;
  9410. else
  9411. return String (t);
  9412. }
  9413. const String String::trimCharactersAtEnd (const juce_wchar* charactersToTrim) const
  9414. {
  9415. jassert (charactersToTrim != 0);
  9416. if (isEmpty())
  9417. return empty;
  9418. const juce_wchar* endT = text + (length() - 1);
  9419. while ((endT >= text) && CharacterFunctions::indexOfCharFast (charactersToTrim, *endT) >= 0)
  9420. --endT;
  9421. return String (text, (int) (++endT - text));
  9422. }
  9423. const String String::retainCharacters (const juce_wchar* const charactersToRetain) const
  9424. {
  9425. jassert (charactersToRetain != 0);
  9426. if (isEmpty())
  9427. return empty;
  9428. String result (StringHolder::getAllocatedNumChars (text), (int) 0);
  9429. juce_wchar* dst = result.text;
  9430. const juce_wchar* src = text;
  9431. while (*src != 0)
  9432. {
  9433. if (CharacterFunctions::indexOfCharFast (charactersToRetain, *src) >= 0)
  9434. *dst++ = *src;
  9435. ++src;
  9436. }
  9437. *dst = 0;
  9438. return result;
  9439. }
  9440. const String String::removeCharacters (const juce_wchar* const charactersToRemove) const
  9441. {
  9442. jassert (charactersToRemove != 0);
  9443. if (isEmpty())
  9444. return empty;
  9445. String result (StringHolder::getAllocatedNumChars (text), (int) 0);
  9446. juce_wchar* dst = result.text;
  9447. const juce_wchar* src = text;
  9448. while (*src != 0)
  9449. {
  9450. if (CharacterFunctions::indexOfCharFast (charactersToRemove, *src) < 0)
  9451. *dst++ = *src;
  9452. ++src;
  9453. }
  9454. *dst = 0;
  9455. return result;
  9456. }
  9457. const String String::initialSectionContainingOnly (const juce_wchar* const permittedCharacters) const
  9458. {
  9459. return substring (0, CharacterFunctions::getIntialSectionContainingOnly (text, permittedCharacters));
  9460. }
  9461. const String String::initialSectionNotContaining (const juce_wchar* const charactersToStopAt) const
  9462. {
  9463. jassert (charactersToStopAt != 0);
  9464. const juce_wchar* const t = text;
  9465. int i = 0;
  9466. while (t[i] != 0)
  9467. {
  9468. if (CharacterFunctions::indexOfCharFast (charactersToStopAt, t[i]) >= 0)
  9469. return String (text, i);
  9470. ++i;
  9471. }
  9472. return empty;
  9473. }
  9474. bool String::containsOnly (const juce_wchar* const chars) const throw()
  9475. {
  9476. jassert (chars != 0);
  9477. const juce_wchar* t = text;
  9478. while (*t != 0)
  9479. if (CharacterFunctions::indexOfCharFast (chars, *t++) < 0)
  9480. return false;
  9481. return true;
  9482. }
  9483. bool String::containsAnyOf (const juce_wchar* const chars) const throw()
  9484. {
  9485. jassert (chars != 0);
  9486. const juce_wchar* t = text;
  9487. while (*t != 0)
  9488. if (CharacterFunctions::indexOfCharFast (chars, *t++) >= 0)
  9489. return true;
  9490. return false;
  9491. }
  9492. bool String::containsNonWhitespaceChars() const throw()
  9493. {
  9494. const juce_wchar* t = text;
  9495. while (*t != 0)
  9496. if (! CharacterFunctions::isWhitespace (*t++))
  9497. return true;
  9498. return false;
  9499. }
  9500. const String String::formatted (const juce_wchar* const pf, ... )
  9501. {
  9502. jassert (pf != 0);
  9503. va_list args;
  9504. va_start (args, pf);
  9505. size_t bufferSize = 256;
  9506. String result (bufferSize, (int) 0);
  9507. result.text[0] = 0;
  9508. for (;;)
  9509. {
  9510. #if JUCE_LINUX && JUCE_64BIT
  9511. va_list tempArgs;
  9512. va_copy (tempArgs, args);
  9513. const int num = (int) vswprintf (result.text, bufferSize - 1, pf, tempArgs);
  9514. va_end (tempArgs);
  9515. #elif JUCE_WINDOWS
  9516. const int num = (int) _vsnwprintf (result.text, bufferSize - 1, pf, args);
  9517. #else
  9518. const int num = (int) vswprintf (result.text, bufferSize - 1, pf, args);
  9519. #endif
  9520. if (num > 0)
  9521. return result;
  9522. bufferSize += 256;
  9523. if (num == 0 || bufferSize > 65536) // the upper limit is a sanity check to avoid situations where vprintf repeatedly
  9524. break; // returns -1 because of an error rather than because it needs more space.
  9525. result.preallocateStorage (bufferSize);
  9526. }
  9527. return empty;
  9528. }
  9529. int String::getIntValue() const throw()
  9530. {
  9531. return CharacterFunctions::getIntValue (text);
  9532. }
  9533. int String::getTrailingIntValue() const throw()
  9534. {
  9535. int n = 0;
  9536. int mult = 1;
  9537. const juce_wchar* t = text + length();
  9538. while (--t >= text)
  9539. {
  9540. const juce_wchar c = *t;
  9541. if (! CharacterFunctions::isDigit (c))
  9542. {
  9543. if (c == T('-'))
  9544. n = -n;
  9545. break;
  9546. }
  9547. n += mult * (c - T('0'));
  9548. mult *= 10;
  9549. }
  9550. return n;
  9551. }
  9552. int64 String::getLargeIntValue() const throw()
  9553. {
  9554. return CharacterFunctions::getInt64Value (text);
  9555. }
  9556. float String::getFloatValue() const throw()
  9557. {
  9558. return (float) CharacterFunctions::getDoubleValue (text);
  9559. }
  9560. double String::getDoubleValue() const throw()
  9561. {
  9562. return CharacterFunctions::getDoubleValue (text);
  9563. }
  9564. static const juce_wchar* const hexDigits = T("0123456789abcdef");
  9565. const String String::toHexString (const int number)
  9566. {
  9567. juce_wchar buffer[32];
  9568. juce_wchar* const end = buffer + 32;
  9569. juce_wchar* t = end;
  9570. *--t = 0;
  9571. unsigned int v = (unsigned int) number;
  9572. do
  9573. {
  9574. *--t = hexDigits [v & 15];
  9575. v >>= 4;
  9576. } while (v != 0);
  9577. return String (t, (int) (((char*) end) - (char*) t) - 1);
  9578. }
  9579. const String String::toHexString (const int64 number)
  9580. {
  9581. juce_wchar buffer[32];
  9582. juce_wchar* const end = buffer + 32;
  9583. juce_wchar* t = end;
  9584. *--t = 0;
  9585. uint64 v = (uint64) number;
  9586. do
  9587. {
  9588. *--t = hexDigits [(int) (v & 15)];
  9589. v >>= 4;
  9590. } while (v != 0);
  9591. return String (t, (int) (((char*) end) - (char*) t));
  9592. }
  9593. const String String::toHexString (const short number)
  9594. {
  9595. return toHexString ((int) (unsigned short) number);
  9596. }
  9597. const String String::toHexString (const unsigned char* data,
  9598. const int size,
  9599. const int groupSize)
  9600. {
  9601. if (size <= 0)
  9602. return empty;
  9603. int numChars = (size * 2) + 2;
  9604. if (groupSize > 0)
  9605. numChars += size / groupSize;
  9606. String s ((size_t) numChars, (int) 0);
  9607. juce_wchar* d = s.text;
  9608. for (int i = 0; i < size; ++i)
  9609. {
  9610. *d++ = hexDigits [(*data) >> 4];
  9611. *d++ = hexDigits [(*data) & 0xf];
  9612. ++data;
  9613. if (groupSize > 0 && (i % groupSize) == (groupSize - 1) && i < (size - 1))
  9614. *d++ = T(' ');
  9615. }
  9616. *d = 0;
  9617. return s;
  9618. }
  9619. int String::getHexValue32() const throw()
  9620. {
  9621. int result = 0;
  9622. const juce_wchar* c = text;
  9623. for (;;)
  9624. {
  9625. const int hexValue = CharacterFunctions::getHexDigitValue (*c);
  9626. if (hexValue >= 0)
  9627. result = (result << 4) | hexValue;
  9628. else if (*c == 0)
  9629. break;
  9630. ++c;
  9631. }
  9632. return result;
  9633. }
  9634. int64 String::getHexValue64() const throw()
  9635. {
  9636. int64 result = 0;
  9637. const juce_wchar* c = text;
  9638. for (;;)
  9639. {
  9640. const int hexValue = CharacterFunctions::getHexDigitValue (*c);
  9641. if (hexValue >= 0)
  9642. result = (result << 4) | hexValue;
  9643. else if (*c == 0)
  9644. break;
  9645. ++c;
  9646. }
  9647. return result;
  9648. }
  9649. const String String::createStringFromData (const void* const data_, const int size)
  9650. {
  9651. const char* const data = (const char*) data_;
  9652. if (size <= 0 || data == 0)
  9653. {
  9654. return empty;
  9655. }
  9656. else if (size < 2)
  9657. {
  9658. return charToString (data[0]);
  9659. }
  9660. else if ((data[0] == (char)-2 && data[1] == (char)-1)
  9661. || (data[0] == (char)-1 && data[1] == (char)-2))
  9662. {
  9663. // assume it's 16-bit unicode
  9664. const bool bigEndian = (data[0] == (char)-2);
  9665. const int numChars = size / 2 - 1;
  9666. String result;
  9667. result.preallocateStorage (numChars + 2);
  9668. const uint16* const src = (const uint16*) (data + 2);
  9669. juce_wchar* const dst = const_cast <juce_wchar*> ((const juce_wchar*) result);
  9670. if (bigEndian)
  9671. {
  9672. for (int i = 0; i < numChars; ++i)
  9673. dst[i] = (juce_wchar) ByteOrder::swapIfLittleEndian (src[i]);
  9674. }
  9675. else
  9676. {
  9677. for (int i = 0; i < numChars; ++i)
  9678. dst[i] = (juce_wchar) ByteOrder::swapIfBigEndian (src[i]);
  9679. }
  9680. dst [numChars] = 0;
  9681. return result;
  9682. }
  9683. else
  9684. {
  9685. return String::fromUTF8 (data, size);
  9686. }
  9687. }
  9688. const char* String::toUTF8() const
  9689. {
  9690. if (isEmpty())
  9691. {
  9692. return reinterpret_cast <const char*> (text);
  9693. }
  9694. else
  9695. {
  9696. const int currentLen = length() + 1;
  9697. const int utf8BytesNeeded = getNumBytesAsUTF8();
  9698. String* const mutableThis = const_cast <String*> (this);
  9699. mutableThis->text = StringHolder::makeUniqueWithSize (mutableThis->text, currentLen + 1 + utf8BytesNeeded / sizeof (juce_wchar));
  9700. char* const otherCopy = (char*) (text + currentLen);
  9701. copyToUTF8 (otherCopy, std::numeric_limits<int>::max());
  9702. return otherCopy;
  9703. }
  9704. }
  9705. int String::copyToUTF8 (char* const buffer, const int maxBufferSizeBytes) const throw()
  9706. {
  9707. jassert (maxBufferSizeBytes >= 0); // keep this value positive, or no characters will be copied!
  9708. int num = 0, index = 0;
  9709. for (;;)
  9710. {
  9711. const uint32 c = (uint32) text [index++];
  9712. if (c >= 0x80)
  9713. {
  9714. int numExtraBytes = 1;
  9715. if (c >= 0x800)
  9716. {
  9717. ++numExtraBytes;
  9718. if (c >= 0x10000)
  9719. {
  9720. ++numExtraBytes;
  9721. if (c >= 0x200000)
  9722. {
  9723. ++numExtraBytes;
  9724. if (c >= 0x4000000)
  9725. ++numExtraBytes;
  9726. }
  9727. }
  9728. }
  9729. if (buffer != 0)
  9730. {
  9731. if (num + numExtraBytes >= maxBufferSizeBytes)
  9732. {
  9733. buffer [num++] = 0;
  9734. break;
  9735. }
  9736. else
  9737. {
  9738. buffer [num++] = (uint8) ((0xff << (7 - numExtraBytes)) | (c >> (numExtraBytes * 6)));
  9739. while (--numExtraBytes >= 0)
  9740. buffer [num++] = (uint8) (0x80 | (0x3f & (c >> (numExtraBytes * 6))));
  9741. }
  9742. }
  9743. else
  9744. {
  9745. num += numExtraBytes + 1;
  9746. }
  9747. }
  9748. else
  9749. {
  9750. if (buffer != 0)
  9751. {
  9752. if (num + 1 >= maxBufferSizeBytes)
  9753. {
  9754. buffer [num++] = 0;
  9755. break;
  9756. }
  9757. buffer [num] = (uint8) c;
  9758. }
  9759. ++num;
  9760. }
  9761. if (c == 0)
  9762. break;
  9763. }
  9764. return num;
  9765. }
  9766. int String::getNumBytesAsUTF8() const throw()
  9767. {
  9768. int num = 0;
  9769. const juce_wchar* t = text;
  9770. for (;;)
  9771. {
  9772. const uint32 c = (uint32) *t;
  9773. if (c >= 0x80)
  9774. {
  9775. ++num;
  9776. if (c >= 0x800)
  9777. {
  9778. ++num;
  9779. if (c >= 0x10000)
  9780. {
  9781. ++num;
  9782. if (c >= 0x200000)
  9783. {
  9784. ++num;
  9785. if (c >= 0x4000000)
  9786. ++num;
  9787. }
  9788. }
  9789. }
  9790. }
  9791. else if (c == 0)
  9792. break;
  9793. ++num;
  9794. ++t;
  9795. }
  9796. return num;
  9797. }
  9798. const String String::fromUTF8 (const char* const buffer, int bufferSizeBytes)
  9799. {
  9800. if (buffer == 0)
  9801. return empty;
  9802. if (bufferSizeBytes < 0)
  9803. bufferSizeBytes = std::numeric_limits<int>::max();
  9804. size_t numBytes;
  9805. for (numBytes = 0; numBytes < (size_t) bufferSizeBytes; ++numBytes)
  9806. if (buffer [numBytes] == 0)
  9807. break;
  9808. String result ((size_t) numBytes + 1, (int) 0);
  9809. juce_wchar* dest = result.text;
  9810. size_t i = 0;
  9811. while (i < numBytes)
  9812. {
  9813. const char c = buffer [i++];
  9814. if (c < 0)
  9815. {
  9816. unsigned int mask = 0x7f;
  9817. int bit = 0x40;
  9818. int numExtraValues = 0;
  9819. while (bit != 0 && (c & bit) != 0)
  9820. {
  9821. bit >>= 1;
  9822. mask >>= 1;
  9823. ++numExtraValues;
  9824. }
  9825. int n = (mask & (unsigned char) c);
  9826. while (--numExtraValues >= 0 && i < (size_t) bufferSizeBytes)
  9827. {
  9828. const char nextByte = buffer[i];
  9829. if ((nextByte & 0xc0) != 0x80)
  9830. break;
  9831. n <<= 6;
  9832. n |= (nextByte & 0x3f);
  9833. ++i;
  9834. }
  9835. *dest++ = (juce_wchar) n;
  9836. }
  9837. else
  9838. {
  9839. *dest++ = (juce_wchar) c;
  9840. }
  9841. }
  9842. *dest = 0;
  9843. return result;
  9844. }
  9845. const char* String::toCString() const
  9846. {
  9847. if (isEmpty())
  9848. {
  9849. return reinterpret_cast <const char*> (text);
  9850. }
  9851. else
  9852. {
  9853. int len = length();
  9854. String* const mutableThis = const_cast <String*> (this);
  9855. mutableThis->text = StringHolder::makeUniqueWithSize (mutableThis->text, (len + 1) * 2);
  9856. char* otherCopy = (char*) (text + len + 1);
  9857. CharacterFunctions::copy (otherCopy, text, len);
  9858. otherCopy [len] = 0;
  9859. return otherCopy;
  9860. }
  9861. }
  9862. #ifdef _MSC_VER
  9863. #pragma warning (disable: 4514 4996)
  9864. #pragma warning (push)
  9865. #endif
  9866. int String::getNumBytesAsCString() const throw()
  9867. {
  9868. return (int) wcstombs (0, text, 0);
  9869. }
  9870. int String::copyToCString (char* destBuffer, const int maxBufferSizeBytes) const throw()
  9871. {
  9872. const int numBytes = (int) wcstombs (destBuffer, text, maxBufferSizeBytes);
  9873. if (destBuffer != 0 && numBytes >= 0)
  9874. destBuffer [numBytes] = 0;
  9875. return numBytes;
  9876. }
  9877. #ifdef _MSC_VER
  9878. #pragma warning (pop)
  9879. #endif
  9880. void String::copyToUnicode (juce_wchar* const destBuffer, const int maxCharsToCopy) const throw()
  9881. {
  9882. StringHolder::copyChars (destBuffer, text, jmin (maxCharsToCopy, length()));
  9883. }
  9884. String::Concatenator::Concatenator (String& stringToAppendTo)
  9885. : result (stringToAppendTo),
  9886. nextIndex (stringToAppendTo.length())
  9887. {
  9888. }
  9889. String::Concatenator::~Concatenator()
  9890. {
  9891. }
  9892. void String::Concatenator::append (const String& s)
  9893. {
  9894. const int len = s.length();
  9895. if (len > 0)
  9896. {
  9897. result.preallocateStorage (nextIndex + len);
  9898. s.copyToUnicode (((juce_wchar*) result) + nextIndex, len);
  9899. nextIndex += len;
  9900. }
  9901. }
  9902. END_JUCE_NAMESPACE
  9903. /*** End of inlined file: juce_String.cpp ***/
  9904. /*** Start of inlined file: juce_StringArray.cpp ***/
  9905. BEGIN_JUCE_NAMESPACE
  9906. StringArray::StringArray() throw()
  9907. {
  9908. }
  9909. StringArray::StringArray (const StringArray& other)
  9910. : strings (other.strings)
  9911. {
  9912. }
  9913. StringArray::StringArray (const juce_wchar** const initialStrings,
  9914. const int numberOfStrings)
  9915. {
  9916. for (int i = 0; i < numberOfStrings; ++i)
  9917. add (initialStrings [i]);
  9918. }
  9919. StringArray::StringArray (const char** const initialStrings,
  9920. const int numberOfStrings)
  9921. {
  9922. for (int i = 0; i < numberOfStrings; ++i)
  9923. add (initialStrings [i]);
  9924. }
  9925. StringArray::StringArray (const juce_wchar** const initialStrings)
  9926. {
  9927. int i = 0;
  9928. while (initialStrings[i] != 0)
  9929. add (initialStrings [i++]);
  9930. }
  9931. StringArray::StringArray (const char** const initialStrings)
  9932. {
  9933. int i = 0;
  9934. while (initialStrings[i] != 0)
  9935. add (initialStrings [i++]);
  9936. }
  9937. StringArray& StringArray::operator= (const StringArray& other)
  9938. {
  9939. strings = other.strings;
  9940. return *this;
  9941. }
  9942. StringArray::~StringArray()
  9943. {
  9944. }
  9945. bool StringArray::operator== (const StringArray& other) const
  9946. {
  9947. if (other.size() != size())
  9948. return false;
  9949. for (int i = size(); --i >= 0;)
  9950. if (other.strings.getReference(i) != strings.getReference(i))
  9951. return false;
  9952. return true;
  9953. }
  9954. bool StringArray::operator!= (const StringArray& other) const
  9955. {
  9956. return ! operator== (other);
  9957. }
  9958. void StringArray::clear()
  9959. {
  9960. strings.clear();
  9961. }
  9962. const String& StringArray::operator[] (const int index) const throw()
  9963. {
  9964. if (((unsigned int) index) < (unsigned int) strings.size())
  9965. return strings.getReference (index);
  9966. return String::empty;
  9967. }
  9968. void StringArray::add (const String& newString)
  9969. {
  9970. strings.add (newString);
  9971. }
  9972. void StringArray::insert (const int index, const String& newString)
  9973. {
  9974. strings.insert (index, newString);
  9975. }
  9976. void StringArray::addIfNotAlreadyThere (const String& newString, const bool ignoreCase)
  9977. {
  9978. if (! contains (newString, ignoreCase))
  9979. add (newString);
  9980. }
  9981. void StringArray::addArray (const StringArray& otherArray, int startIndex, int numElementsToAdd)
  9982. {
  9983. if (startIndex < 0)
  9984. {
  9985. jassertfalse
  9986. startIndex = 0;
  9987. }
  9988. if (numElementsToAdd < 0 || startIndex + numElementsToAdd > otherArray.size())
  9989. numElementsToAdd = otherArray.size() - startIndex;
  9990. while (--numElementsToAdd >= 0)
  9991. strings.add (otherArray.strings.getReference (startIndex++));
  9992. }
  9993. void StringArray::set (const int index, const String& newString)
  9994. {
  9995. strings.set (index, newString);
  9996. }
  9997. bool StringArray::contains (const String& stringToLookFor, const bool ignoreCase) const
  9998. {
  9999. if (ignoreCase)
  10000. {
  10001. for (int i = size(); --i >= 0;)
  10002. if (strings.getReference(i).equalsIgnoreCase (stringToLookFor))
  10003. return true;
  10004. }
  10005. else
  10006. {
  10007. for (int i = size(); --i >= 0;)
  10008. if (stringToLookFor == strings.getReference(i))
  10009. return true;
  10010. }
  10011. return false;
  10012. }
  10013. int StringArray::indexOf (const String& stringToLookFor, const bool ignoreCase, int i) const
  10014. {
  10015. if (i < 0)
  10016. i = 0;
  10017. const int numElements = size();
  10018. if (ignoreCase)
  10019. {
  10020. while (i < numElements)
  10021. {
  10022. if (strings.getReference(i).equalsIgnoreCase (stringToLookFor))
  10023. return i;
  10024. ++i;
  10025. }
  10026. }
  10027. else
  10028. {
  10029. while (i < numElements)
  10030. {
  10031. if (stringToLookFor == strings.getReference (i))
  10032. return i;
  10033. ++i;
  10034. }
  10035. }
  10036. return -1;
  10037. }
  10038. void StringArray::remove (const int index)
  10039. {
  10040. strings.remove (index);
  10041. }
  10042. void StringArray::removeString (const String& stringToRemove,
  10043. const bool ignoreCase)
  10044. {
  10045. if (ignoreCase)
  10046. {
  10047. for (int i = size(); --i >= 0;)
  10048. if (strings.getReference(i).equalsIgnoreCase (stringToRemove))
  10049. strings.remove (i);
  10050. }
  10051. else
  10052. {
  10053. for (int i = size(); --i >= 0;)
  10054. if (stringToRemove == strings.getReference (i))
  10055. strings.remove (i);
  10056. }
  10057. }
  10058. void StringArray::removeEmptyStrings (const bool removeWhitespaceStrings)
  10059. {
  10060. if (removeWhitespaceStrings)
  10061. {
  10062. for (int i = size(); --i >= 0;)
  10063. if (! strings.getReference(i).containsNonWhitespaceChars())
  10064. strings.remove (i);
  10065. }
  10066. else
  10067. {
  10068. for (int i = size(); --i >= 0;)
  10069. if (strings.getReference(i).isEmpty())
  10070. strings.remove (i);
  10071. }
  10072. }
  10073. void StringArray::trim()
  10074. {
  10075. for (int i = size(); --i >= 0;)
  10076. {
  10077. String& s = strings.getReference(i);
  10078. s = s.trim();
  10079. }
  10080. }
  10081. class InternalStringArrayComparator_CaseSensitive
  10082. {
  10083. public:
  10084. static int compareElements (String& first, String& second) { return first.compare (second); }
  10085. };
  10086. class InternalStringArrayComparator_CaseInsensitive
  10087. {
  10088. public:
  10089. static int compareElements (String& first, String& second) { return first.compareIgnoreCase (second); }
  10090. };
  10091. void StringArray::sort (const bool ignoreCase)
  10092. {
  10093. if (ignoreCase)
  10094. {
  10095. InternalStringArrayComparator_CaseInsensitive comp;
  10096. strings.sort (comp);
  10097. }
  10098. else
  10099. {
  10100. InternalStringArrayComparator_CaseSensitive comp;
  10101. strings.sort (comp);
  10102. }
  10103. }
  10104. void StringArray::move (const int currentIndex, int newIndex) throw()
  10105. {
  10106. strings.move (currentIndex, newIndex);
  10107. }
  10108. const String StringArray::joinIntoString (const String& separator, int start, int numberToJoin) const
  10109. {
  10110. const int last = (numberToJoin < 0) ? size()
  10111. : jmin (size(), start + numberToJoin);
  10112. if (start < 0)
  10113. start = 0;
  10114. if (start >= last)
  10115. return String::empty;
  10116. if (start == last - 1)
  10117. return strings.getReference (start);
  10118. const int separatorLen = separator.length();
  10119. int charsNeeded = separatorLen * (last - start - 1);
  10120. for (int i = start; i < last; ++i)
  10121. charsNeeded += strings.getReference(i).length();
  10122. String result;
  10123. result.preallocateStorage (charsNeeded);
  10124. juce_wchar* dest = (juce_wchar*) result;
  10125. while (start < last)
  10126. {
  10127. const String& s = strings.getReference (start);
  10128. const int len = s.length();
  10129. if (len > 0)
  10130. {
  10131. s.copyToUnicode (dest, len);
  10132. dest += len;
  10133. }
  10134. if (++start < last && separatorLen > 0)
  10135. {
  10136. separator.copyToUnicode (dest, separatorLen);
  10137. dest += separatorLen;
  10138. }
  10139. }
  10140. *dest = 0;
  10141. return result;
  10142. }
  10143. int StringArray::addTokens (const String& text, const bool preserveQuotedStrings)
  10144. {
  10145. return addTokens (text, T(" \n\r\t"), preserveQuotedStrings ? T("\"") : T(""));
  10146. }
  10147. int StringArray::addTokens (const String& text, const String& breakCharacters, const String& quoteCharacters)
  10148. {
  10149. int num = 0;
  10150. if (text.isNotEmpty())
  10151. {
  10152. bool insideQuotes = false;
  10153. juce_wchar currentQuoteChar = 0;
  10154. int i = 0;
  10155. int tokenStart = 0;
  10156. for (;;)
  10157. {
  10158. const juce_wchar c = text[i];
  10159. bool isBreak = (c == 0);
  10160. if (! (insideQuotes || isBreak))
  10161. {
  10162. const juce_wchar* b = breakCharacters;
  10163. while (*b != 0)
  10164. {
  10165. if (*b++ == c)
  10166. {
  10167. isBreak = true;
  10168. break;
  10169. }
  10170. }
  10171. }
  10172. if (! isBreak)
  10173. {
  10174. bool isQuote = false;
  10175. const juce_wchar* q = quoteCharacters;
  10176. while (*q != 0)
  10177. {
  10178. if (*q++ == c)
  10179. {
  10180. isQuote = true;
  10181. break;
  10182. }
  10183. }
  10184. if (isQuote)
  10185. {
  10186. if (insideQuotes)
  10187. {
  10188. // only break out of quotes-mode if we find a matching quote to the
  10189. // one that we opened with..
  10190. if (currentQuoteChar == c)
  10191. insideQuotes = false;
  10192. }
  10193. else
  10194. {
  10195. insideQuotes = true;
  10196. currentQuoteChar = c;
  10197. }
  10198. }
  10199. }
  10200. else
  10201. {
  10202. add (String (static_cast <const juce_wchar*> (text) + tokenStart, i - tokenStart));
  10203. ++num;
  10204. tokenStart = i + 1;
  10205. }
  10206. if (c == 0)
  10207. break;
  10208. ++i;
  10209. }
  10210. }
  10211. return num;
  10212. }
  10213. int StringArray::addLines (const String& sourceText)
  10214. {
  10215. int numLines = 0;
  10216. const juce_wchar* text = sourceText;
  10217. while (*text != 0)
  10218. {
  10219. const juce_wchar* const startOfLine = text;
  10220. while (*text != 0)
  10221. {
  10222. if (*text == T('\r'))
  10223. {
  10224. ++text;
  10225. if (*text == T('\n'))
  10226. ++text;
  10227. break;
  10228. }
  10229. if (*text == T('\n'))
  10230. {
  10231. ++text;
  10232. break;
  10233. }
  10234. ++text;
  10235. }
  10236. const juce_wchar* endOfLine = text;
  10237. if (endOfLine > startOfLine && (*(endOfLine - 1) == T('\r') || *(endOfLine - 1) == T('\n')))
  10238. --endOfLine;
  10239. if (endOfLine > startOfLine && (*(endOfLine - 1) == T('\r') || *(endOfLine - 1) == T('\n')))
  10240. --endOfLine;
  10241. add (String (startOfLine, jmax (0, (int) (endOfLine - startOfLine))));
  10242. ++numLines;
  10243. }
  10244. return numLines;
  10245. }
  10246. void StringArray::removeDuplicates (const bool ignoreCase)
  10247. {
  10248. for (int i = 0; i < size() - 1; ++i)
  10249. {
  10250. const String s (strings.getReference(i));
  10251. int nextIndex = i + 1;
  10252. for (;;)
  10253. {
  10254. nextIndex = indexOf (s, ignoreCase, nextIndex);
  10255. if (nextIndex < 0)
  10256. break;
  10257. strings.remove (nextIndex);
  10258. }
  10259. }
  10260. }
  10261. void StringArray::appendNumbersToDuplicates (const bool ignoreCase,
  10262. const bool appendNumberToFirstInstance,
  10263. const tchar* const preNumberString,
  10264. const tchar* const postNumberString)
  10265. {
  10266. for (int i = 0; i < size() - 1; ++i)
  10267. {
  10268. String& s = strings.getReference(i);
  10269. int nextIndex = indexOf (s, ignoreCase, i + 1);
  10270. if (nextIndex >= 0)
  10271. {
  10272. const String original (s);
  10273. int number = 0;
  10274. if (appendNumberToFirstInstance)
  10275. s = original + preNumberString + String (++number) + postNumberString;
  10276. else
  10277. ++number;
  10278. while (nextIndex >= 0)
  10279. {
  10280. set (nextIndex, (*this)[nextIndex] + preNumberString + String (++number) + postNumberString);
  10281. nextIndex = indexOf (original, ignoreCase, nextIndex + 1);
  10282. }
  10283. }
  10284. }
  10285. }
  10286. void StringArray::minimiseStorageOverheads()
  10287. {
  10288. strings.minimiseStorageOverheads();
  10289. }
  10290. END_JUCE_NAMESPACE
  10291. /*** End of inlined file: juce_StringArray.cpp ***/
  10292. /*** Start of inlined file: juce_StringPairArray.cpp ***/
  10293. BEGIN_JUCE_NAMESPACE
  10294. StringPairArray::StringPairArray (const bool ignoreCase_) throw()
  10295. : ignoreCase (ignoreCase_)
  10296. {
  10297. }
  10298. StringPairArray::StringPairArray (const StringPairArray& other) throw()
  10299. : keys (other.keys),
  10300. values (other.values),
  10301. ignoreCase (other.ignoreCase)
  10302. {
  10303. }
  10304. StringPairArray::~StringPairArray() throw()
  10305. {
  10306. }
  10307. StringPairArray& StringPairArray::operator= (const StringPairArray& other) throw()
  10308. {
  10309. keys = other.keys;
  10310. values = other.values;
  10311. return *this;
  10312. }
  10313. bool StringPairArray::operator== (const StringPairArray& other) const throw()
  10314. {
  10315. for (int i = keys.size(); --i >= 0;)
  10316. if (other [keys[i]] != values[i])
  10317. return false;
  10318. return true;
  10319. }
  10320. bool StringPairArray::operator!= (const StringPairArray& other) const throw()
  10321. {
  10322. return ! operator== (other);
  10323. }
  10324. const String& StringPairArray::operator[] (const String& key) const throw()
  10325. {
  10326. return values [keys.indexOf (key, ignoreCase)];
  10327. }
  10328. const String StringPairArray::getValue (const String& key, const String& defaultReturnValue) const
  10329. {
  10330. const int i = keys.indexOf (key, ignoreCase);
  10331. if (i >= 0)
  10332. return values[i];
  10333. return defaultReturnValue;
  10334. }
  10335. void StringPairArray::set (const String& key,
  10336. const String& value) throw()
  10337. {
  10338. const int i = keys.indexOf (key, ignoreCase);
  10339. if (i >= 0)
  10340. {
  10341. values.set (i, value);
  10342. }
  10343. else
  10344. {
  10345. keys.add (key);
  10346. values.add (value);
  10347. }
  10348. }
  10349. void StringPairArray::addArray (const StringPairArray& other)
  10350. {
  10351. for (int i = 0; i < other.size(); ++i)
  10352. set (other.keys[i], other.values[i]);
  10353. }
  10354. void StringPairArray::clear() throw()
  10355. {
  10356. keys.clear();
  10357. values.clear();
  10358. }
  10359. void StringPairArray::remove (const String& key) throw()
  10360. {
  10361. remove (keys.indexOf (key, ignoreCase));
  10362. }
  10363. void StringPairArray::remove (const int index) throw()
  10364. {
  10365. keys.remove (index);
  10366. values.remove (index);
  10367. }
  10368. void StringPairArray::setIgnoresCase (const bool shouldIgnoreCase) throw()
  10369. {
  10370. ignoreCase = shouldIgnoreCase;
  10371. }
  10372. const String StringPairArray::getDescription() const
  10373. {
  10374. String s;
  10375. for (int i = 0; i < keys.size(); ++i)
  10376. {
  10377. s << keys[i] << T(" = ") << values[i];
  10378. if (i < keys.size())
  10379. s << T(", ");
  10380. }
  10381. return s;
  10382. }
  10383. void StringPairArray::minimiseStorageOverheads() throw()
  10384. {
  10385. keys.minimiseStorageOverheads();
  10386. values.minimiseStorageOverheads();
  10387. }
  10388. END_JUCE_NAMESPACE
  10389. /*** End of inlined file: juce_StringPairArray.cpp ***/
  10390. /*** Start of inlined file: juce_XmlDocument.cpp ***/
  10391. BEGIN_JUCE_NAMESPACE
  10392. XmlDocument::XmlDocument (const String& documentText) throw()
  10393. : originalText (documentText),
  10394. ignoreEmptyTextElements (true)
  10395. {
  10396. }
  10397. XmlDocument::XmlDocument (const File& file)
  10398. {
  10399. inputSource = new FileInputSource (file);
  10400. }
  10401. XmlDocument::~XmlDocument() throw()
  10402. {
  10403. }
  10404. void XmlDocument::setInputSource (InputSource* const newSource) throw()
  10405. {
  10406. inputSource = newSource;
  10407. }
  10408. void XmlDocument::setEmptyTextElementsIgnored (const bool shouldBeIgnored) throw()
  10409. {
  10410. ignoreEmptyTextElements = shouldBeIgnored;
  10411. }
  10412. bool XmlDocument::isXmlIdentifierCharSlow (const juce_wchar c) throw()
  10413. {
  10414. return CharacterFunctions::isLetterOrDigit (c)
  10415. || c == T('_')
  10416. || c == T('-')
  10417. || c == T(':')
  10418. || c == T('.');
  10419. }
  10420. inline bool XmlDocument::isXmlIdentifierChar (const juce_wchar c) const throw()
  10421. {
  10422. return (c > 0 && c <= 127) ? identifierLookupTable [(int) c]
  10423. : isXmlIdentifierCharSlow (c);
  10424. }
  10425. XmlElement* XmlDocument::getDocumentElement (const bool onlyReadOuterDocumentElement)
  10426. {
  10427. String textToParse (originalText);
  10428. if (textToParse.isEmpty() && inputSource != 0)
  10429. {
  10430. ScopedPointer <InputStream> in (inputSource->createInputStream());
  10431. if (in != 0)
  10432. {
  10433. MemoryBlock data;
  10434. in->readIntoMemoryBlock (data, onlyReadOuterDocumentElement ? 8192 : -1);
  10435. if (data.getSize() >= 2
  10436. && ((data[0] == (char)-2 && data[1] == (char)-1)
  10437. || (data[0] == (char)-1 && data[1] == (char)-2)))
  10438. {
  10439. textToParse = String::createStringFromData ((const char*) data.getData(), (int) data.getSize());
  10440. }
  10441. else
  10442. {
  10443. textToParse = String::fromUTF8 ((const char*) data.getData(), (int) data.getSize());
  10444. }
  10445. if (! onlyReadOuterDocumentElement)
  10446. originalText = textToParse;
  10447. }
  10448. }
  10449. input = textToParse;
  10450. lastError = String::empty;
  10451. errorOccurred = false;
  10452. outOfData = false;
  10453. needToLoadDTD = true;
  10454. for (int i = 0; i < 128; ++i)
  10455. identifierLookupTable[i] = isXmlIdentifierCharSlow ((juce_wchar) i);
  10456. if (textToParse.isEmpty())
  10457. {
  10458. lastError = "not enough input";
  10459. }
  10460. else
  10461. {
  10462. skipHeader();
  10463. if (input != 0)
  10464. {
  10465. ScopedPointer <XmlElement> result (readNextElement (! onlyReadOuterDocumentElement));
  10466. if (! errorOccurred)
  10467. return result.release();
  10468. }
  10469. else
  10470. {
  10471. lastError = "incorrect xml header";
  10472. }
  10473. }
  10474. return 0;
  10475. }
  10476. const String& XmlDocument::getLastParseError() const throw()
  10477. {
  10478. return lastError;
  10479. }
  10480. void XmlDocument::setLastError (const String& desc, const bool carryOn) throw()
  10481. {
  10482. lastError = desc;
  10483. errorOccurred = ! carryOn;
  10484. }
  10485. const String XmlDocument::getFileContents (const String& filename) const
  10486. {
  10487. if (inputSource != 0)
  10488. {
  10489. const ScopedPointer <InputStream> in (inputSource->createInputStreamFor (filename.trim().unquoted()));
  10490. if (in != 0)
  10491. return in->readEntireStreamAsString();
  10492. }
  10493. return String::empty;
  10494. }
  10495. juce_wchar XmlDocument::readNextChar() throw()
  10496. {
  10497. if (*input != 0)
  10498. {
  10499. return *input++;
  10500. }
  10501. else
  10502. {
  10503. outOfData = true;
  10504. return 0;
  10505. }
  10506. }
  10507. int XmlDocument::findNextTokenLength() throw()
  10508. {
  10509. int len = 0;
  10510. juce_wchar c = *input;
  10511. while (isXmlIdentifierChar (c))
  10512. c = input [++len];
  10513. return len;
  10514. }
  10515. void XmlDocument::skipHeader() throw()
  10516. {
  10517. const juce_wchar* const found = CharacterFunctions::find (input, T("<?xml"));
  10518. if (found != 0)
  10519. {
  10520. input = found;
  10521. input = CharacterFunctions::find (input, T("?>"));
  10522. if (input == 0)
  10523. return;
  10524. input += 2;
  10525. }
  10526. skipNextWhiteSpace();
  10527. const juce_wchar* docType = CharacterFunctions::find (input, T("<!DOCTYPE"));
  10528. if (docType == 0)
  10529. return;
  10530. input = docType + 9;
  10531. int n = 1;
  10532. while (n > 0)
  10533. {
  10534. const juce_wchar c = readNextChar();
  10535. if (outOfData)
  10536. return;
  10537. if (c == T('<'))
  10538. ++n;
  10539. else if (c == T('>'))
  10540. --n;
  10541. }
  10542. docType += 9;
  10543. dtdText = String (docType, (int) (input - (docType + 1))).trim();
  10544. }
  10545. void XmlDocument::skipNextWhiteSpace() throw()
  10546. {
  10547. for (;;)
  10548. {
  10549. juce_wchar c = *input;
  10550. while (CharacterFunctions::isWhitespace (c))
  10551. c = *++input;
  10552. if (c == 0)
  10553. {
  10554. outOfData = true;
  10555. break;
  10556. }
  10557. else if (c == T('<'))
  10558. {
  10559. if (input[1] == T('!')
  10560. && input[2] == T('-')
  10561. && input[3] == T('-'))
  10562. {
  10563. const juce_wchar* const closeComment = CharacterFunctions::find (input, T("-->"));
  10564. if (closeComment == 0)
  10565. {
  10566. outOfData = true;
  10567. break;
  10568. }
  10569. input = closeComment + 3;
  10570. continue;
  10571. }
  10572. else if (input[1] == T('?'))
  10573. {
  10574. const juce_wchar* const closeBracket = CharacterFunctions::find (input, T("?>"));
  10575. if (closeBracket == 0)
  10576. {
  10577. outOfData = true;
  10578. break;
  10579. }
  10580. input = closeBracket + 2;
  10581. continue;
  10582. }
  10583. }
  10584. break;
  10585. }
  10586. }
  10587. void XmlDocument::readQuotedString (String& result) throw()
  10588. {
  10589. const juce_wchar quote = readNextChar();
  10590. while (! outOfData)
  10591. {
  10592. const juce_wchar c = readNextChar();
  10593. if (c == quote)
  10594. break;
  10595. if (c == T('&'))
  10596. {
  10597. --input;
  10598. readEntity (result);
  10599. }
  10600. else
  10601. {
  10602. --input;
  10603. const juce_wchar* const start = input;
  10604. for (;;)
  10605. {
  10606. const juce_wchar character = *input;
  10607. if (character == quote)
  10608. {
  10609. result.append (start, (int) (input - start));
  10610. ++input;
  10611. return;
  10612. }
  10613. else if (character == T('&'))
  10614. {
  10615. result.append (start, (int) (input - start));
  10616. break;
  10617. }
  10618. else if (character == 0)
  10619. {
  10620. outOfData = true;
  10621. setLastError ("unmatched quotes", false);
  10622. break;
  10623. }
  10624. ++input;
  10625. }
  10626. }
  10627. }
  10628. }
  10629. XmlElement* XmlDocument::readNextElement (const bool alsoParseSubElements) throw()
  10630. {
  10631. XmlElement* node = 0;
  10632. skipNextWhiteSpace();
  10633. if (outOfData)
  10634. return 0;
  10635. input = CharacterFunctions::find (input, T("<"));
  10636. if (input != 0)
  10637. {
  10638. ++input;
  10639. int tagLen = findNextTokenLength();
  10640. if (tagLen == 0)
  10641. {
  10642. // no tag name - but allow for a gap after the '<' before giving an error
  10643. skipNextWhiteSpace();
  10644. tagLen = findNextTokenLength();
  10645. if (tagLen == 0)
  10646. {
  10647. setLastError ("tag name missing", false);
  10648. return node;
  10649. }
  10650. }
  10651. node = new XmlElement (String (input, tagLen));
  10652. input += tagLen;
  10653. XmlElement::XmlAttributeNode* lastAttribute = 0;
  10654. // look for attributes
  10655. for (;;)
  10656. {
  10657. skipNextWhiteSpace();
  10658. const juce_wchar c = *input;
  10659. // empty tag..
  10660. if (c == T('/') && input[1] == T('>'))
  10661. {
  10662. input += 2;
  10663. break;
  10664. }
  10665. // parse the guts of the element..
  10666. if (c == T('>'))
  10667. {
  10668. ++input;
  10669. skipNextWhiteSpace();
  10670. if (alsoParseSubElements)
  10671. readChildElements (node);
  10672. break;
  10673. }
  10674. // get an attribute..
  10675. if (isXmlIdentifierChar (c))
  10676. {
  10677. const int attNameLen = findNextTokenLength();
  10678. if (attNameLen > 0)
  10679. {
  10680. const juce_wchar* attNameStart = input;
  10681. input += attNameLen;
  10682. skipNextWhiteSpace();
  10683. if (readNextChar() == T('='))
  10684. {
  10685. skipNextWhiteSpace();
  10686. const juce_wchar nextChar = *input;
  10687. if (nextChar == T('"') || nextChar == T('\''))
  10688. {
  10689. XmlElement::XmlAttributeNode* const newAtt
  10690. = new XmlElement::XmlAttributeNode (String (attNameStart, attNameLen),
  10691. String::empty);
  10692. readQuotedString (newAtt->value);
  10693. if (lastAttribute == 0)
  10694. node->attributes = newAtt;
  10695. else
  10696. lastAttribute->next = newAtt;
  10697. lastAttribute = newAtt;
  10698. continue;
  10699. }
  10700. }
  10701. }
  10702. }
  10703. else
  10704. {
  10705. if (! outOfData)
  10706. setLastError ("illegal character found in " + node->getTagName() + ": '" + c + "'", false);
  10707. }
  10708. break;
  10709. }
  10710. }
  10711. return node;
  10712. }
  10713. void XmlDocument::readChildElements (XmlElement* parent) throw()
  10714. {
  10715. XmlElement* lastChildNode = 0;
  10716. for (;;)
  10717. {
  10718. skipNextWhiteSpace();
  10719. if (outOfData)
  10720. {
  10721. setLastError ("unmatched tags", false);
  10722. break;
  10723. }
  10724. if (*input == T('<'))
  10725. {
  10726. if (input[1] == T('/'))
  10727. {
  10728. // our close tag..
  10729. input = CharacterFunctions::find (input, T(">"));
  10730. ++input;
  10731. break;
  10732. }
  10733. else if (input[1] == T('!')
  10734. && input[2] == T('[')
  10735. && input[3] == T('C')
  10736. && input[4] == T('D')
  10737. && input[5] == T('A')
  10738. && input[6] == T('T')
  10739. && input[7] == T('A')
  10740. && input[8] == T('['))
  10741. {
  10742. input += 9;
  10743. const juce_wchar* const inputStart = input;
  10744. int len = 0;
  10745. for (;;)
  10746. {
  10747. if (*input == 0)
  10748. {
  10749. setLastError ("unterminated CDATA section", false);
  10750. outOfData = true;
  10751. break;
  10752. }
  10753. else if (input[0] == T(']')
  10754. && input[1] == T(']')
  10755. && input[2] == T('>'))
  10756. {
  10757. input += 3;
  10758. break;
  10759. }
  10760. ++input;
  10761. ++len;
  10762. }
  10763. XmlElement* const e = new XmlElement ((int) 0);
  10764. e->setText (String (inputStart, len));
  10765. if (lastChildNode != 0)
  10766. lastChildNode->nextElement = e;
  10767. else
  10768. parent->addChildElement (e);
  10769. lastChildNode = e;
  10770. }
  10771. else
  10772. {
  10773. // this is some other element, so parse and add it..
  10774. XmlElement* const n = readNextElement (true);
  10775. if (n != 0)
  10776. {
  10777. if (lastChildNode == 0)
  10778. parent->addChildElement (n);
  10779. else
  10780. lastChildNode->nextElement = n;
  10781. lastChildNode = n;
  10782. }
  10783. else
  10784. {
  10785. return;
  10786. }
  10787. }
  10788. }
  10789. else
  10790. {
  10791. // read character block..
  10792. XmlElement* const e = new XmlElement ((int)0);
  10793. if (lastChildNode != 0)
  10794. lastChildNode->nextElement = e;
  10795. else
  10796. parent->addChildElement (e);
  10797. lastChildNode = e;
  10798. String textElementContent;
  10799. for (;;)
  10800. {
  10801. const juce_wchar c = *input;
  10802. if (c == T('<'))
  10803. break;
  10804. if (c == 0)
  10805. {
  10806. setLastError ("unmatched tags", false);
  10807. outOfData = true;
  10808. return;
  10809. }
  10810. if (c == T('&'))
  10811. {
  10812. String entity;
  10813. readEntity (entity);
  10814. if (entity.startsWithChar (T('<')) && entity [1] != 0)
  10815. {
  10816. const juce_wchar* const oldInput = input;
  10817. const bool oldOutOfData = outOfData;
  10818. input = entity;
  10819. outOfData = false;
  10820. for (;;)
  10821. {
  10822. XmlElement* const n = readNextElement (true);
  10823. if (n == 0)
  10824. break;
  10825. if (lastChildNode == 0)
  10826. parent->addChildElement (n);
  10827. else
  10828. lastChildNode->nextElement = n;
  10829. lastChildNode = n;
  10830. }
  10831. input = oldInput;
  10832. outOfData = oldOutOfData;
  10833. }
  10834. else
  10835. {
  10836. textElementContent += entity;
  10837. }
  10838. }
  10839. else
  10840. {
  10841. const juce_wchar* start = input;
  10842. int len = 0;
  10843. for (;;)
  10844. {
  10845. const juce_wchar nextChar = *input;
  10846. if (nextChar == T('<') || nextChar == T('&'))
  10847. {
  10848. break;
  10849. }
  10850. else if (nextChar == 0)
  10851. {
  10852. setLastError ("unmatched tags", false);
  10853. outOfData = true;
  10854. return;
  10855. }
  10856. ++input;
  10857. ++len;
  10858. }
  10859. textElementContent.append (start, len);
  10860. }
  10861. }
  10862. if (ignoreEmptyTextElements ? textElementContent.containsNonWhitespaceChars()
  10863. : textElementContent.isNotEmpty())
  10864. e->setText (textElementContent);
  10865. }
  10866. }
  10867. }
  10868. void XmlDocument::readEntity (String& result) throw()
  10869. {
  10870. // skip over the ampersand
  10871. ++input;
  10872. if (CharacterFunctions::compareIgnoreCase (input, T("amp;"), 4) == 0)
  10873. {
  10874. input += 4;
  10875. result += T("&");
  10876. }
  10877. else if (CharacterFunctions::compareIgnoreCase (input, T("quot;"), 5) == 0)
  10878. {
  10879. input += 5;
  10880. result += T("\"");
  10881. }
  10882. else if (CharacterFunctions::compareIgnoreCase (input, T("apos;"), 5) == 0)
  10883. {
  10884. input += 5;
  10885. result += T("\'");
  10886. }
  10887. else if (CharacterFunctions::compareIgnoreCase (input, T("lt;"), 3) == 0)
  10888. {
  10889. input += 3;
  10890. result += T("<");
  10891. }
  10892. else if (CharacterFunctions::compareIgnoreCase (input, T("gt;"), 3) == 0)
  10893. {
  10894. input += 3;
  10895. result += T(">");
  10896. }
  10897. else if (*input == T('#'))
  10898. {
  10899. int charCode = 0;
  10900. ++input;
  10901. if (*input == T('x') || *input == T('X'))
  10902. {
  10903. ++input;
  10904. int numChars = 0;
  10905. while (input[0] != T(';'))
  10906. {
  10907. const int hexValue = CharacterFunctions::getHexDigitValue (input[0]);
  10908. if (hexValue < 0 || ++numChars > 8)
  10909. {
  10910. setLastError ("illegal escape sequence", true);
  10911. break;
  10912. }
  10913. charCode = (charCode << 4) | hexValue;
  10914. ++input;
  10915. }
  10916. ++input;
  10917. }
  10918. else if (input[0] >= T('0') && input[0] <= T('9'))
  10919. {
  10920. int numChars = 0;
  10921. while (input[0] != T(';'))
  10922. {
  10923. if (++numChars > 12)
  10924. {
  10925. setLastError ("illegal escape sequence", true);
  10926. break;
  10927. }
  10928. charCode = charCode * 10 + (input[0] - T('0'));
  10929. ++input;
  10930. }
  10931. ++input;
  10932. }
  10933. else
  10934. {
  10935. setLastError ("illegal escape sequence", true);
  10936. result += T("&");
  10937. return;
  10938. }
  10939. result << (juce_wchar) charCode;
  10940. }
  10941. else
  10942. {
  10943. const juce_wchar* const entityNameStart = input;
  10944. const juce_wchar* const closingSemiColon = CharacterFunctions::find (input, T(";"));
  10945. if (closingSemiColon == 0)
  10946. {
  10947. outOfData = true;
  10948. result += T("&");
  10949. }
  10950. else
  10951. {
  10952. input = closingSemiColon + 1;
  10953. result += expandExternalEntity (String (entityNameStart,
  10954. (int) (closingSemiColon - entityNameStart)));
  10955. }
  10956. }
  10957. }
  10958. const String XmlDocument::expandEntity (const String& ent)
  10959. {
  10960. if (ent.equalsIgnoreCase (T("amp")))
  10961. {
  10962. return T("&");
  10963. }
  10964. else if (ent.equalsIgnoreCase (T("quot")))
  10965. {
  10966. return T("\"");
  10967. }
  10968. else if (ent.equalsIgnoreCase (T("apos")))
  10969. {
  10970. return T("\'");
  10971. }
  10972. else if (ent.equalsIgnoreCase (T("lt")))
  10973. {
  10974. return T("<");
  10975. }
  10976. else if (ent.equalsIgnoreCase (T("gt")))
  10977. {
  10978. return T(">");
  10979. }
  10980. else if (ent[0] == T('#'))
  10981. {
  10982. if (ent[1] == T('x') || ent[1] == T('X'))
  10983. {
  10984. return String::charToString (static_cast <juce_wchar> (ent.substring (2).getHexValue32()));
  10985. }
  10986. else if (ent[1] >= T('0') && ent[1] <= T('9'))
  10987. {
  10988. return String::charToString (static_cast <juce_wchar> (ent.substring (1).getIntValue()));
  10989. }
  10990. setLastError ("illegal escape sequence", false);
  10991. return T("&");
  10992. }
  10993. else
  10994. {
  10995. return expandExternalEntity (ent);
  10996. }
  10997. }
  10998. const String XmlDocument::expandExternalEntity (const String& entity)
  10999. {
  11000. if (needToLoadDTD)
  11001. {
  11002. if (dtdText.isNotEmpty())
  11003. {
  11004. while (dtdText.endsWithChar (T('>')))
  11005. dtdText = dtdText.dropLastCharacters (1);
  11006. tokenisedDTD.addTokens (dtdText, true);
  11007. if (tokenisedDTD [tokenisedDTD.size() - 2].equalsIgnoreCase (T("system"))
  11008. && tokenisedDTD [tokenisedDTD.size() - 1].isQuotedString())
  11009. {
  11010. const String fn (tokenisedDTD [tokenisedDTD.size() - 1]);
  11011. tokenisedDTD.clear();
  11012. tokenisedDTD.addTokens (getFileContents (fn), true);
  11013. }
  11014. else
  11015. {
  11016. tokenisedDTD.clear();
  11017. const int openBracket = dtdText.indexOfChar (T('['));
  11018. if (openBracket > 0)
  11019. {
  11020. const int closeBracket = dtdText.lastIndexOfChar (T(']'));
  11021. if (closeBracket > openBracket)
  11022. tokenisedDTD.addTokens (dtdText.substring (openBracket + 1,
  11023. closeBracket), true);
  11024. }
  11025. }
  11026. for (int i = tokenisedDTD.size(); --i >= 0;)
  11027. {
  11028. if (tokenisedDTD[i].startsWithChar (T('%'))
  11029. && tokenisedDTD[i].endsWithChar (T(';')))
  11030. {
  11031. const String parsed (getParameterEntity (tokenisedDTD[i].substring (1, tokenisedDTD[i].length() - 1)));
  11032. StringArray newToks;
  11033. newToks.addTokens (parsed, true);
  11034. tokenisedDTD.remove (i);
  11035. for (int j = newToks.size(); --j >= 0;)
  11036. tokenisedDTD.insert (i, newToks[j]);
  11037. }
  11038. }
  11039. }
  11040. needToLoadDTD = false;
  11041. }
  11042. for (int i = 0; i < tokenisedDTD.size(); ++i)
  11043. {
  11044. if (tokenisedDTD[i] == entity)
  11045. {
  11046. if (tokenisedDTD[i - 1].equalsIgnoreCase (T("<!entity")))
  11047. {
  11048. String ent (tokenisedDTD [i + 1]);
  11049. while (ent.endsWithChar (T('>')))
  11050. ent = ent.dropLastCharacters (1);
  11051. ent = ent.trim().unquoted();
  11052. // check for sub-entities..
  11053. int ampersand = ent.indexOfChar (T('&'));
  11054. while (ampersand >= 0)
  11055. {
  11056. const int semiColon = ent.indexOf (i + 1, T(";"));
  11057. if (semiColon < 0)
  11058. {
  11059. setLastError ("entity without terminating semi-colon", false);
  11060. break;
  11061. }
  11062. const String resolved (expandEntity (ent.substring (i + 1, semiColon)));
  11063. ent = ent.substring (0, ampersand)
  11064. + resolved
  11065. + ent.substring (semiColon + 1);
  11066. ampersand = ent.indexOfChar (semiColon + 1, T('&'));
  11067. }
  11068. return ent;
  11069. }
  11070. }
  11071. }
  11072. setLastError ("unknown entity", true);
  11073. return entity;
  11074. }
  11075. const String XmlDocument::getParameterEntity (const String& entity)
  11076. {
  11077. for (int i = 0; i < tokenisedDTD.size(); ++i)
  11078. {
  11079. if (tokenisedDTD[i] == entity)
  11080. {
  11081. if (tokenisedDTD [i - 1] == T("%")
  11082. && tokenisedDTD [i - 2].equalsIgnoreCase (T("<!entity")))
  11083. {
  11084. String ent (tokenisedDTD [i + 1]);
  11085. while (ent.endsWithChar (T('>')))
  11086. ent = ent.dropLastCharacters (1);
  11087. if (ent.equalsIgnoreCase (T("system")))
  11088. {
  11089. String filename (tokenisedDTD [i + 2]);
  11090. while (filename.endsWithChar (T('>')))
  11091. filename = filename.dropLastCharacters (1);
  11092. return getFileContents (filename);
  11093. }
  11094. else
  11095. {
  11096. return ent.trim().unquoted();
  11097. }
  11098. }
  11099. }
  11100. }
  11101. return entity;
  11102. }
  11103. END_JUCE_NAMESPACE
  11104. /*** End of inlined file: juce_XmlDocument.cpp ***/
  11105. /*** Start of inlined file: juce_XmlElement.cpp ***/
  11106. BEGIN_JUCE_NAMESPACE
  11107. XmlElement::XmlAttributeNode::XmlAttributeNode (const XmlAttributeNode& other) throw()
  11108. : name (other.name),
  11109. value (other.value),
  11110. next (0)
  11111. {
  11112. }
  11113. XmlElement::XmlAttributeNode::XmlAttributeNode (const String& name_,
  11114. const String& value_) throw()
  11115. : name (name_),
  11116. value (value_),
  11117. next (0)
  11118. {
  11119. }
  11120. XmlElement::XmlElement (const String& tagName_) throw()
  11121. : tagName (tagName_),
  11122. firstChildElement (0),
  11123. nextElement (0),
  11124. attributes (0)
  11125. {
  11126. // the tag name mustn't be empty, or it'll look like a text element!
  11127. jassert (tagName_.containsNonWhitespaceChars())
  11128. // The tag can't contain spaces or other characters that would create invalid XML!
  11129. jassert (! tagName_.containsAnyOf (T(" <>/&")));
  11130. }
  11131. XmlElement::XmlElement (int /*dummy*/) throw()
  11132. : firstChildElement (0),
  11133. nextElement (0),
  11134. attributes (0)
  11135. {
  11136. }
  11137. XmlElement::XmlElement (const XmlElement& other) throw()
  11138. : tagName (other.tagName),
  11139. firstChildElement (0),
  11140. nextElement (0),
  11141. attributes (0)
  11142. {
  11143. copyChildrenAndAttributesFrom (other);
  11144. }
  11145. XmlElement& XmlElement::operator= (const XmlElement& other) throw()
  11146. {
  11147. if (this != &other)
  11148. {
  11149. removeAllAttributes();
  11150. deleteAllChildElements();
  11151. tagName = other.tagName;
  11152. copyChildrenAndAttributesFrom (other);
  11153. }
  11154. return *this;
  11155. }
  11156. void XmlElement::copyChildrenAndAttributesFrom (const XmlElement& other) throw()
  11157. {
  11158. XmlElement* child = other.firstChildElement;
  11159. XmlElement* lastChild = 0;
  11160. while (child != 0)
  11161. {
  11162. XmlElement* const copiedChild = new XmlElement (*child);
  11163. if (lastChild != 0)
  11164. lastChild->nextElement = copiedChild;
  11165. else
  11166. firstChildElement = copiedChild;
  11167. lastChild = copiedChild;
  11168. child = child->nextElement;
  11169. }
  11170. const XmlAttributeNode* att = other.attributes;
  11171. XmlAttributeNode* lastAtt = 0;
  11172. while (att != 0)
  11173. {
  11174. XmlAttributeNode* const newAtt = new XmlAttributeNode (*att);
  11175. if (lastAtt != 0)
  11176. lastAtt->next = newAtt;
  11177. else
  11178. attributes = newAtt;
  11179. lastAtt = newAtt;
  11180. att = att->next;
  11181. }
  11182. }
  11183. XmlElement::~XmlElement() throw()
  11184. {
  11185. XmlElement* child = firstChildElement;
  11186. while (child != 0)
  11187. {
  11188. XmlElement* const nextChild = child->nextElement;
  11189. delete child;
  11190. child = nextChild;
  11191. }
  11192. XmlAttributeNode* att = attributes;
  11193. while (att != 0)
  11194. {
  11195. XmlAttributeNode* const nextAtt = att->next;
  11196. delete att;
  11197. att = nextAtt;
  11198. }
  11199. }
  11200. namespace XmlOutputFunctions
  11201. {
  11202. static bool isLegalXmlChar (const uint32 c) throw()
  11203. {
  11204. static const unsigned char legalChars[] = { 0, 0, 0, 0, 171, 255, 255, 175, 255, 255, 255, 191, 254, 255, 255, 111 };
  11205. return c < sizeof (legalChars) * 8
  11206. && (legalChars [c >> 3] & (1 << (c & 7))) != 0;
  11207. }
  11208. static void escapeIllegalXmlChars (OutputStream& outputStream, const String& text, const bool changeNewLines)
  11209. {
  11210. const juce_wchar* t = (const juce_wchar*) text;
  11211. for (;;)
  11212. {
  11213. const juce_wchar character = *t++;
  11214. if (character == 0)
  11215. {
  11216. break;
  11217. }
  11218. else if (isLegalXmlChar ((uint32) character))
  11219. {
  11220. outputStream << (char) character;
  11221. }
  11222. else
  11223. {
  11224. switch (character)
  11225. {
  11226. case '&': outputStream << "&amp;"; break;
  11227. case '"': outputStream << "&quot;"; break;
  11228. case '>': outputStream << "&gt;"; break;
  11229. case '<': outputStream << "&lt;"; break;
  11230. case '\n':
  11231. if (changeNewLines)
  11232. outputStream << "&#10;";
  11233. else
  11234. outputStream << (char) character;
  11235. break;
  11236. case '\r':
  11237. if (changeNewLines)
  11238. outputStream << "&#13;";
  11239. else
  11240. outputStream << (char) character;
  11241. break;
  11242. default:
  11243. outputStream << "&#" << ((int) (unsigned int) character) << ';';
  11244. break;
  11245. }
  11246. }
  11247. }
  11248. }
  11249. static void writeSpaces (OutputStream& out, int numSpaces)
  11250. {
  11251. if (numSpaces > 0)
  11252. {
  11253. const char* const blanks = " ";
  11254. const int blankSize = (int) sizeof (blanks) - 1;
  11255. while (numSpaces > blankSize)
  11256. {
  11257. out.write (blanks, blankSize);
  11258. numSpaces -= blankSize;
  11259. }
  11260. out.write (blanks, numSpaces);
  11261. }
  11262. }
  11263. }
  11264. void XmlElement::writeElementAsText (OutputStream& outputStream,
  11265. const int indentationLevel,
  11266. const int lineWrapLength) const
  11267. {
  11268. using namespace XmlOutputFunctions;
  11269. writeSpaces (outputStream, indentationLevel);
  11270. if (! isTextElement())
  11271. {
  11272. outputStream.writeByte ('<');
  11273. outputStream << tagName;
  11274. const int attIndent = indentationLevel + tagName.length() + 1;
  11275. int lineLen = 0;
  11276. const XmlAttributeNode* att = attributes;
  11277. while (att != 0)
  11278. {
  11279. if (lineLen > lineWrapLength && indentationLevel >= 0)
  11280. {
  11281. outputStream.write ("\r\n", 2);
  11282. writeSpaces (outputStream, attIndent);
  11283. lineLen = 0;
  11284. }
  11285. const int64 startPos = outputStream.getPosition();
  11286. outputStream.writeByte (' ');
  11287. outputStream << att->name;
  11288. outputStream.write ("=\"", 2);
  11289. escapeIllegalXmlChars (outputStream, att->value, true);
  11290. outputStream.writeByte ('"');
  11291. lineLen += (int) (outputStream.getPosition() - startPos);
  11292. att = att->next;
  11293. }
  11294. if (firstChildElement != 0)
  11295. {
  11296. XmlElement* child = firstChildElement;
  11297. if (child->nextElement == 0 && child->isTextElement())
  11298. {
  11299. outputStream.writeByte ('>');
  11300. escapeIllegalXmlChars (outputStream, child->getText(), false);
  11301. }
  11302. else
  11303. {
  11304. if (indentationLevel >= 0)
  11305. outputStream.write (">\r\n", 3);
  11306. else
  11307. outputStream.writeByte ('>');
  11308. bool lastWasTextNode = false;
  11309. while (child != 0)
  11310. {
  11311. if (child->isTextElement())
  11312. {
  11313. if ((! lastWasTextNode) && (indentationLevel >= 0))
  11314. writeSpaces (outputStream, indentationLevel + 2);
  11315. escapeIllegalXmlChars (outputStream, child->getText(), false);
  11316. lastWasTextNode = true;
  11317. }
  11318. else
  11319. {
  11320. if (indentationLevel >= 0)
  11321. {
  11322. if (lastWasTextNode)
  11323. outputStream.write ("\r\n", 2);
  11324. child->writeElementAsText (outputStream, indentationLevel + 2, lineWrapLength);
  11325. }
  11326. else
  11327. {
  11328. child->writeElementAsText (outputStream, indentationLevel, lineWrapLength);
  11329. }
  11330. lastWasTextNode = false;
  11331. }
  11332. child = child->nextElement;
  11333. }
  11334. if (indentationLevel >= 0)
  11335. {
  11336. if (lastWasTextNode)
  11337. outputStream.write ("\r\n", 2);
  11338. writeSpaces (outputStream, indentationLevel);
  11339. }
  11340. }
  11341. outputStream.write ("</", 2);
  11342. outputStream << tagName;
  11343. if (indentationLevel >= 0)
  11344. outputStream.write (">\r\n", 3);
  11345. else
  11346. outputStream.writeByte ('>');
  11347. }
  11348. else
  11349. {
  11350. if (indentationLevel >= 0)
  11351. outputStream.write ("/>\r\n", 4);
  11352. else
  11353. outputStream.write ("/>", 2);
  11354. }
  11355. }
  11356. else
  11357. {
  11358. if (indentationLevel >= 0)
  11359. writeSpaces (outputStream, indentationLevel + 2);
  11360. escapeIllegalXmlChars (outputStream, getText(), false);
  11361. }
  11362. }
  11363. const String XmlElement::createDocument (const String& dtdToUse,
  11364. const bool allOnOneLine,
  11365. const bool includeXmlHeader,
  11366. const String& encodingType,
  11367. const int lineWrapLength) const
  11368. {
  11369. MemoryOutputStream mem (2048, 4096);
  11370. writeToStream (mem, dtdToUse, allOnOneLine, includeXmlHeader, encodingType, lineWrapLength);
  11371. return String (mem.getData(), mem.getDataSize());
  11372. }
  11373. void XmlElement::writeToStream (OutputStream& output,
  11374. const String& dtdToUse,
  11375. const bool allOnOneLine,
  11376. const bool includeXmlHeader,
  11377. const String& encodingType,
  11378. const int lineWrapLength) const
  11379. {
  11380. if (includeXmlHeader)
  11381. {
  11382. output << "<?xml version=\"1.0\" encoding=\"" << encodingType;
  11383. if (allOnOneLine)
  11384. output << "\"?> ";
  11385. else
  11386. output << "\"?>\r\n\r\n";
  11387. }
  11388. if (dtdToUse.isNotEmpty())
  11389. {
  11390. output << dtdToUse;
  11391. if (allOnOneLine)
  11392. output << " ";
  11393. else
  11394. output << "\r\n";
  11395. }
  11396. writeElementAsText (output, allOnOneLine ? -1 : 0, lineWrapLength);
  11397. }
  11398. bool XmlElement::writeToFile (const File& file,
  11399. const String& dtdToUse,
  11400. const String& encodingType,
  11401. const int lineWrapLength) const
  11402. {
  11403. if (file.hasWriteAccess())
  11404. {
  11405. TemporaryFile tempFile (file);
  11406. ScopedPointer <FileOutputStream> out (tempFile.getFile().createOutputStream());
  11407. if (out != 0)
  11408. {
  11409. writeToStream (*out, dtdToUse, false, true, encodingType, lineWrapLength);
  11410. out = 0;
  11411. return tempFile.overwriteTargetFileWithTemporary();
  11412. }
  11413. }
  11414. return false;
  11415. }
  11416. bool XmlElement::hasTagName (const String& tagNameWanted) const throw()
  11417. {
  11418. #ifdef JUCE_DEBUG
  11419. // if debugging, check that the case is actually the same, because
  11420. // valid xml is case-sensitive, and although this lets it pass, it's
  11421. // better not to..
  11422. if (tagName.equalsIgnoreCase (tagNameWanted))
  11423. {
  11424. jassert (tagName == tagNameWanted);
  11425. return true;
  11426. }
  11427. else
  11428. {
  11429. return false;
  11430. }
  11431. #else
  11432. return tagName.equalsIgnoreCase (tagNameWanted);
  11433. #endif
  11434. }
  11435. XmlElement* XmlElement::getNextElementWithTagName (const String& requiredTagName) const
  11436. {
  11437. XmlElement* e = nextElement;
  11438. while (e != 0 && ! e->hasTagName (requiredTagName))
  11439. e = e->nextElement;
  11440. return e;
  11441. }
  11442. int XmlElement::getNumAttributes() const throw()
  11443. {
  11444. const XmlAttributeNode* att = attributes;
  11445. int count = 0;
  11446. while (att != 0)
  11447. {
  11448. att = att->next;
  11449. ++count;
  11450. }
  11451. return count;
  11452. }
  11453. const String& XmlElement::getAttributeName (const int index) const throw()
  11454. {
  11455. const XmlAttributeNode* att = attributes;
  11456. int count = 0;
  11457. while (att != 0)
  11458. {
  11459. if (count == index)
  11460. return att->name;
  11461. att = att->next;
  11462. ++count;
  11463. }
  11464. return String::empty;
  11465. }
  11466. const String& XmlElement::getAttributeValue (const int index) const throw()
  11467. {
  11468. const XmlAttributeNode* att = attributes;
  11469. int count = 0;
  11470. while (att != 0)
  11471. {
  11472. if (count == index)
  11473. return att->value;
  11474. att = att->next;
  11475. ++count;
  11476. }
  11477. return String::empty;
  11478. }
  11479. bool XmlElement::hasAttribute (const String& attributeName) const throw()
  11480. {
  11481. const XmlAttributeNode* att = attributes;
  11482. while (att != 0)
  11483. {
  11484. if (att->name.equalsIgnoreCase (attributeName))
  11485. return true;
  11486. att = att->next;
  11487. }
  11488. return false;
  11489. }
  11490. const String& XmlElement::getStringAttribute (const String& attributeName) const throw()
  11491. {
  11492. const XmlAttributeNode* att = attributes;
  11493. while (att != 0)
  11494. {
  11495. if (att->name.equalsIgnoreCase (attributeName))
  11496. return att->value;
  11497. att = att->next;
  11498. }
  11499. return String::empty;
  11500. }
  11501. const String XmlElement::getStringAttribute (const String& attributeName, const String& defaultReturnValue) const
  11502. {
  11503. const XmlAttributeNode* att = attributes;
  11504. while (att != 0)
  11505. {
  11506. if (att->name.equalsIgnoreCase (attributeName))
  11507. return att->value;
  11508. att = att->next;
  11509. }
  11510. return defaultReturnValue;
  11511. }
  11512. int XmlElement::getIntAttribute (const String& attributeName, const int defaultReturnValue) const
  11513. {
  11514. const XmlAttributeNode* att = attributes;
  11515. while (att != 0)
  11516. {
  11517. if (att->name.equalsIgnoreCase (attributeName))
  11518. return att->value.getIntValue();
  11519. att = att->next;
  11520. }
  11521. return defaultReturnValue;
  11522. }
  11523. double XmlElement::getDoubleAttribute (const String& attributeName, const double defaultReturnValue) const
  11524. {
  11525. const XmlAttributeNode* att = attributes;
  11526. while (att != 0)
  11527. {
  11528. if (att->name.equalsIgnoreCase (attributeName))
  11529. return att->value.getDoubleValue();
  11530. att = att->next;
  11531. }
  11532. return defaultReturnValue;
  11533. }
  11534. bool XmlElement::getBoolAttribute (const String& attributeName, const bool defaultReturnValue) const
  11535. {
  11536. const XmlAttributeNode* att = attributes;
  11537. while (att != 0)
  11538. {
  11539. if (att->name.equalsIgnoreCase (attributeName))
  11540. {
  11541. juce_wchar firstChar = att->value[0];
  11542. if (CharacterFunctions::isWhitespace (firstChar))
  11543. firstChar = att->value.trimStart() [0];
  11544. return firstChar == T('1')
  11545. || firstChar == T('t')
  11546. || firstChar == T('y')
  11547. || firstChar == T('T')
  11548. || firstChar == T('Y');
  11549. }
  11550. att = att->next;
  11551. }
  11552. return defaultReturnValue;
  11553. }
  11554. bool XmlElement::compareAttribute (const String& attributeName,
  11555. const String& stringToCompareAgainst,
  11556. const bool ignoreCase) const throw()
  11557. {
  11558. const XmlAttributeNode* att = attributes;
  11559. while (att != 0)
  11560. {
  11561. if (att->name.equalsIgnoreCase (attributeName))
  11562. {
  11563. if (ignoreCase)
  11564. return att->value.equalsIgnoreCase (stringToCompareAgainst);
  11565. else
  11566. return att->value == stringToCompareAgainst;
  11567. }
  11568. att = att->next;
  11569. }
  11570. return false;
  11571. }
  11572. void XmlElement::setAttribute (const String& attributeName, const String& value)
  11573. {
  11574. #ifdef JUCE_DEBUG
  11575. // check the identifier being passed in is legal..
  11576. const juce_wchar* t = attributeName;
  11577. while (*t != 0)
  11578. {
  11579. jassert (CharacterFunctions::isLetterOrDigit (*t)
  11580. || *t == T('_')
  11581. || *t == T('-')
  11582. || *t == T(':'));
  11583. ++t;
  11584. }
  11585. #endif
  11586. if (attributes == 0)
  11587. {
  11588. attributes = new XmlAttributeNode (attributeName, value);
  11589. }
  11590. else
  11591. {
  11592. XmlAttributeNode* att = attributes;
  11593. for (;;)
  11594. {
  11595. if (att->name.equalsIgnoreCase (attributeName))
  11596. {
  11597. att->value = value;
  11598. break;
  11599. }
  11600. else if (att->next == 0)
  11601. {
  11602. att->next = new XmlAttributeNode (attributeName, value);
  11603. break;
  11604. }
  11605. att = att->next;
  11606. }
  11607. }
  11608. }
  11609. void XmlElement::setAttribute (const String& attributeName, const int number)
  11610. {
  11611. setAttribute (attributeName, String (number));
  11612. }
  11613. void XmlElement::setAttribute (const String& attributeName, const double number)
  11614. {
  11615. setAttribute (attributeName, String (number));
  11616. }
  11617. void XmlElement::removeAttribute (const String& attributeName) throw()
  11618. {
  11619. XmlAttributeNode* att = attributes;
  11620. XmlAttributeNode* lastAtt = 0;
  11621. while (att != 0)
  11622. {
  11623. if (att->name.equalsIgnoreCase (attributeName))
  11624. {
  11625. if (lastAtt == 0)
  11626. attributes = att->next;
  11627. else
  11628. lastAtt->next = att->next;
  11629. delete att;
  11630. break;
  11631. }
  11632. lastAtt = att;
  11633. att = att->next;
  11634. }
  11635. }
  11636. void XmlElement::removeAllAttributes() throw()
  11637. {
  11638. while (attributes != 0)
  11639. {
  11640. XmlAttributeNode* const nextAtt = attributes->next;
  11641. delete attributes;
  11642. attributes = nextAtt;
  11643. }
  11644. }
  11645. int XmlElement::getNumChildElements() const throw()
  11646. {
  11647. int count = 0;
  11648. const XmlElement* child = firstChildElement;
  11649. while (child != 0)
  11650. {
  11651. ++count;
  11652. child = child->nextElement;
  11653. }
  11654. return count;
  11655. }
  11656. XmlElement* XmlElement::getChildElement (const int index) const throw()
  11657. {
  11658. int count = 0;
  11659. XmlElement* child = firstChildElement;
  11660. while (child != 0 && count < index)
  11661. {
  11662. child = child->nextElement;
  11663. ++count;
  11664. }
  11665. return child;
  11666. }
  11667. XmlElement* XmlElement::getChildByName (const String& childName) const throw()
  11668. {
  11669. XmlElement* child = firstChildElement;
  11670. while (child != 0)
  11671. {
  11672. if (child->hasTagName (childName))
  11673. break;
  11674. child = child->nextElement;
  11675. }
  11676. return child;
  11677. }
  11678. void XmlElement::addChildElement (XmlElement* const newNode) throw()
  11679. {
  11680. if (newNode != 0)
  11681. {
  11682. if (firstChildElement == 0)
  11683. {
  11684. firstChildElement = newNode;
  11685. }
  11686. else
  11687. {
  11688. XmlElement* child = firstChildElement;
  11689. while (child->nextElement != 0)
  11690. child = child->nextElement;
  11691. child->nextElement = newNode;
  11692. // if this is non-zero, then something's probably
  11693. // gone wrong..
  11694. jassert (newNode->nextElement == 0);
  11695. }
  11696. }
  11697. }
  11698. void XmlElement::insertChildElement (XmlElement* const newNode,
  11699. int indexToInsertAt) throw()
  11700. {
  11701. if (newNode != 0)
  11702. {
  11703. removeChildElement (newNode, false);
  11704. if (indexToInsertAt == 0)
  11705. {
  11706. newNode->nextElement = firstChildElement;
  11707. firstChildElement = newNode;
  11708. }
  11709. else
  11710. {
  11711. if (firstChildElement == 0)
  11712. {
  11713. firstChildElement = newNode;
  11714. }
  11715. else
  11716. {
  11717. if (indexToInsertAt < 0)
  11718. indexToInsertAt = std::numeric_limits<int>::max();
  11719. XmlElement* child = firstChildElement;
  11720. while (child->nextElement != 0 && --indexToInsertAt > 0)
  11721. child = child->nextElement;
  11722. newNode->nextElement = child->nextElement;
  11723. child->nextElement = newNode;
  11724. }
  11725. }
  11726. }
  11727. }
  11728. XmlElement* XmlElement::createNewChildElement (const String& tagName)
  11729. {
  11730. XmlElement* const newElement = new XmlElement (tagName);
  11731. addChildElement (newElement);
  11732. return newElement;
  11733. }
  11734. bool XmlElement::replaceChildElement (XmlElement* const currentChildElement,
  11735. XmlElement* const newNode) throw()
  11736. {
  11737. if (newNode != 0)
  11738. {
  11739. XmlElement* child = firstChildElement;
  11740. XmlElement* previousNode = 0;
  11741. while (child != 0)
  11742. {
  11743. if (child == currentChildElement)
  11744. {
  11745. if (child != newNode)
  11746. {
  11747. if (previousNode == 0)
  11748. firstChildElement = newNode;
  11749. else
  11750. previousNode->nextElement = newNode;
  11751. newNode->nextElement = child->nextElement;
  11752. delete child;
  11753. }
  11754. return true;
  11755. }
  11756. previousNode = child;
  11757. child = child->nextElement;
  11758. }
  11759. }
  11760. return false;
  11761. }
  11762. void XmlElement::removeChildElement (XmlElement* const childToRemove,
  11763. const bool shouldDeleteTheChild) throw()
  11764. {
  11765. if (childToRemove != 0)
  11766. {
  11767. if (firstChildElement == childToRemove)
  11768. {
  11769. firstChildElement = childToRemove->nextElement;
  11770. childToRemove->nextElement = 0;
  11771. }
  11772. else
  11773. {
  11774. XmlElement* child = firstChildElement;
  11775. XmlElement* last = 0;
  11776. while (child != 0)
  11777. {
  11778. if (child == childToRemove)
  11779. {
  11780. if (last == 0)
  11781. firstChildElement = child->nextElement;
  11782. else
  11783. last->nextElement = child->nextElement;
  11784. childToRemove->nextElement = 0;
  11785. break;
  11786. }
  11787. last = child;
  11788. child = child->nextElement;
  11789. }
  11790. }
  11791. if (shouldDeleteTheChild)
  11792. delete childToRemove;
  11793. }
  11794. }
  11795. bool XmlElement::isEquivalentTo (const XmlElement* const other,
  11796. const bool ignoreOrderOfAttributes) const throw()
  11797. {
  11798. if (this != other)
  11799. {
  11800. if (other == 0 || tagName != other->tagName)
  11801. {
  11802. return false;
  11803. }
  11804. if (ignoreOrderOfAttributes)
  11805. {
  11806. int totalAtts = 0;
  11807. const XmlAttributeNode* att = attributes;
  11808. while (att != 0)
  11809. {
  11810. if (! other->compareAttribute (att->name, att->value))
  11811. return false;
  11812. att = att->next;
  11813. ++totalAtts;
  11814. }
  11815. if (totalAtts != other->getNumAttributes())
  11816. return false;
  11817. }
  11818. else
  11819. {
  11820. const XmlAttributeNode* thisAtt = attributes;
  11821. const XmlAttributeNode* otherAtt = other->attributes;
  11822. for (;;)
  11823. {
  11824. if (thisAtt == 0 || otherAtt == 0)
  11825. {
  11826. if (thisAtt == otherAtt) // both 0, so it's a match
  11827. break;
  11828. return false;
  11829. }
  11830. if (thisAtt->name != otherAtt->name
  11831. || thisAtt->value != otherAtt->value)
  11832. {
  11833. return false;
  11834. }
  11835. thisAtt = thisAtt->next;
  11836. otherAtt = otherAtt->next;
  11837. }
  11838. }
  11839. const XmlElement* thisChild = firstChildElement;
  11840. const XmlElement* otherChild = other->firstChildElement;
  11841. for (;;)
  11842. {
  11843. if (thisChild == 0 || otherChild == 0)
  11844. {
  11845. if (thisChild == otherChild) // both 0, so it's a match
  11846. break;
  11847. return false;
  11848. }
  11849. if (! thisChild->isEquivalentTo (otherChild, ignoreOrderOfAttributes))
  11850. return false;
  11851. thisChild = thisChild->nextElement;
  11852. otherChild = otherChild->nextElement;
  11853. }
  11854. }
  11855. return true;
  11856. }
  11857. void XmlElement::deleteAllChildElements() throw()
  11858. {
  11859. while (firstChildElement != 0)
  11860. {
  11861. XmlElement* const nextChild = firstChildElement->nextElement;
  11862. delete firstChildElement;
  11863. firstChildElement = nextChild;
  11864. }
  11865. }
  11866. void XmlElement::deleteAllChildElementsWithTagName (const String& name) throw()
  11867. {
  11868. XmlElement* child = firstChildElement;
  11869. while (child != 0)
  11870. {
  11871. if (child->hasTagName (name))
  11872. {
  11873. XmlElement* const nextChild = child->nextElement;
  11874. removeChildElement (child, true);
  11875. child = nextChild;
  11876. }
  11877. else
  11878. {
  11879. child = child->nextElement;
  11880. }
  11881. }
  11882. }
  11883. bool XmlElement::containsChildElement (const XmlElement* const possibleChild) const throw()
  11884. {
  11885. const XmlElement* child = firstChildElement;
  11886. while (child != 0)
  11887. {
  11888. if (child == possibleChild)
  11889. return true;
  11890. child = child->nextElement;
  11891. }
  11892. return false;
  11893. }
  11894. XmlElement* XmlElement::findParentElementOf (const XmlElement* const elementToLookFor) throw()
  11895. {
  11896. if (this == elementToLookFor || elementToLookFor == 0)
  11897. return 0;
  11898. XmlElement* child = firstChildElement;
  11899. while (child != 0)
  11900. {
  11901. if (elementToLookFor == child)
  11902. return this;
  11903. XmlElement* const found = child->findParentElementOf (elementToLookFor);
  11904. if (found != 0)
  11905. return found;
  11906. child = child->nextElement;
  11907. }
  11908. return 0;
  11909. }
  11910. void XmlElement::getChildElementsAsArray (XmlElement** elems) const throw()
  11911. {
  11912. XmlElement* e = firstChildElement;
  11913. while (e != 0)
  11914. {
  11915. *elems++ = e;
  11916. e = e->nextElement;
  11917. }
  11918. }
  11919. void XmlElement::reorderChildElements (XmlElement** const elems, const int num) throw()
  11920. {
  11921. XmlElement* e = firstChildElement = elems[0];
  11922. for (int i = 1; i < num; ++i)
  11923. {
  11924. e->nextElement = elems[i];
  11925. e = e->nextElement;
  11926. }
  11927. e->nextElement = 0;
  11928. }
  11929. bool XmlElement::isTextElement() const throw()
  11930. {
  11931. return tagName.isEmpty();
  11932. }
  11933. static const juce_wchar* const juce_xmltextContentAttributeName = T("text");
  11934. const String XmlElement::getText() const throw()
  11935. {
  11936. jassert (isTextElement()); // you're trying to get the text from an element that
  11937. // isn't actually a text element.. If this contains text sub-nodes, you
  11938. // probably want to use getAllSubText instead.
  11939. return getStringAttribute (juce_xmltextContentAttributeName);
  11940. }
  11941. void XmlElement::setText (const String& newText) throw()
  11942. {
  11943. if (isTextElement())
  11944. {
  11945. setAttribute (juce_xmltextContentAttributeName, newText);
  11946. }
  11947. else
  11948. {
  11949. jassertfalse // you can only change the text in a text element, not a normal one.
  11950. }
  11951. }
  11952. const String XmlElement::getAllSubText() const throw()
  11953. {
  11954. String result;
  11955. String::Concatenator concatenator (result);
  11956. const XmlElement* child = firstChildElement;
  11957. while (child != 0)
  11958. {
  11959. if (child->isTextElement())
  11960. concatenator.append (child->getText());
  11961. child = child->nextElement;
  11962. }
  11963. return result;
  11964. }
  11965. const String XmlElement::getChildElementAllSubText (const String& childTagName,
  11966. const String& defaultReturnValue) const throw()
  11967. {
  11968. const XmlElement* const child = getChildByName (childTagName);
  11969. if (child != 0)
  11970. return child->getAllSubText();
  11971. return defaultReturnValue;
  11972. }
  11973. XmlElement* XmlElement::createTextElement (const String& text) throw()
  11974. {
  11975. XmlElement* const e = new XmlElement ((int) 0);
  11976. e->setAttribute (juce_xmltextContentAttributeName, text);
  11977. return e;
  11978. }
  11979. void XmlElement::addTextElement (const String& text) throw()
  11980. {
  11981. addChildElement (createTextElement (text));
  11982. }
  11983. void XmlElement::deleteAllTextElements() throw()
  11984. {
  11985. XmlElement* child = firstChildElement;
  11986. while (child != 0)
  11987. {
  11988. XmlElement* const next = child->nextElement;
  11989. if (child->isTextElement())
  11990. removeChildElement (child, true);
  11991. child = next;
  11992. }
  11993. }
  11994. END_JUCE_NAMESPACE
  11995. /*** End of inlined file: juce_XmlElement.cpp ***/
  11996. /*** Start of inlined file: juce_ReadWriteLock.cpp ***/
  11997. BEGIN_JUCE_NAMESPACE
  11998. ReadWriteLock::ReadWriteLock() throw()
  11999. : numWaitingWriters (0),
  12000. numWriters (0),
  12001. writerThreadId (0)
  12002. {
  12003. }
  12004. ReadWriteLock::~ReadWriteLock() throw()
  12005. {
  12006. jassert (readerThreads.size() == 0);
  12007. jassert (numWriters == 0);
  12008. }
  12009. void ReadWriteLock::enterRead() const throw()
  12010. {
  12011. const Thread::ThreadID threadId = Thread::getCurrentThreadId();
  12012. const ScopedLock sl (accessLock);
  12013. for (;;)
  12014. {
  12015. jassert (readerThreads.size() % 2 == 0);
  12016. int i;
  12017. for (i = 0; i < readerThreads.size(); i += 2)
  12018. if (readerThreads.getUnchecked(i) == threadId)
  12019. break;
  12020. if (i < readerThreads.size()
  12021. || numWriters + numWaitingWriters == 0
  12022. || (threadId == writerThreadId && numWriters > 0))
  12023. {
  12024. if (i < readerThreads.size())
  12025. {
  12026. readerThreads.set (i + 1, (Thread::ThreadID) (1 + (pointer_sized_int) readerThreads.getUnchecked (i + 1)));
  12027. }
  12028. else
  12029. {
  12030. readerThreads.add (threadId);
  12031. readerThreads.add ((Thread::ThreadID) 1);
  12032. }
  12033. return;
  12034. }
  12035. const ScopedUnlock ul (accessLock);
  12036. waitEvent.wait (100);
  12037. }
  12038. }
  12039. void ReadWriteLock::exitRead() const throw()
  12040. {
  12041. const Thread::ThreadID threadId = Thread::getCurrentThreadId();
  12042. const ScopedLock sl (accessLock);
  12043. for (int i = 0; i < readerThreads.size(); i += 2)
  12044. {
  12045. if (readerThreads.getUnchecked(i) == threadId)
  12046. {
  12047. const pointer_sized_int newCount = ((pointer_sized_int) readerThreads.getUnchecked (i + 1)) - 1;
  12048. if (newCount == 0)
  12049. {
  12050. readerThreads.removeRange (i, 2);
  12051. waitEvent.signal();
  12052. }
  12053. else
  12054. {
  12055. readerThreads.set (i + 1, (Thread::ThreadID) newCount);
  12056. }
  12057. return;
  12058. }
  12059. }
  12060. jassertfalse // unlocking a lock that wasn't locked..
  12061. }
  12062. void ReadWriteLock::enterWrite() const throw()
  12063. {
  12064. const Thread::ThreadID threadId = Thread::getCurrentThreadId();
  12065. const ScopedLock sl (accessLock);
  12066. for (;;)
  12067. {
  12068. if (readerThreads.size() + numWriters == 0
  12069. || threadId == writerThreadId
  12070. || (readerThreads.size() == 2
  12071. && readerThreads.getUnchecked(0) == threadId))
  12072. {
  12073. writerThreadId = threadId;
  12074. ++numWriters;
  12075. break;
  12076. }
  12077. ++numWaitingWriters;
  12078. accessLock.exit();
  12079. waitEvent.wait (100);
  12080. accessLock.enter();
  12081. --numWaitingWriters;
  12082. }
  12083. }
  12084. bool ReadWriteLock::tryEnterWrite() const throw()
  12085. {
  12086. const Thread::ThreadID threadId = Thread::getCurrentThreadId();
  12087. const ScopedLock sl (accessLock);
  12088. if (readerThreads.size() + numWriters == 0
  12089. || threadId == writerThreadId
  12090. || (readerThreads.size() == 2
  12091. && readerThreads.getUnchecked(0) == threadId))
  12092. {
  12093. writerThreadId = threadId;
  12094. ++numWriters;
  12095. return true;
  12096. }
  12097. return false;
  12098. }
  12099. void ReadWriteLock::exitWrite() const throw()
  12100. {
  12101. const ScopedLock sl (accessLock);
  12102. // check this thread actually had the lock..
  12103. jassert (numWriters > 0 && writerThreadId == Thread::getCurrentThreadId());
  12104. if (--numWriters == 0)
  12105. {
  12106. writerThreadId = 0;
  12107. waitEvent.signal();
  12108. }
  12109. }
  12110. END_JUCE_NAMESPACE
  12111. /*** End of inlined file: juce_ReadWriteLock.cpp ***/
  12112. /*** Start of inlined file: juce_Thread.cpp ***/
  12113. BEGIN_JUCE_NAMESPACE
  12114. // these functions are implemented in the platform-specific code.
  12115. void* juce_createThread (void* userData);
  12116. void juce_killThread (void* handle);
  12117. bool juce_setThreadPriority (void* handle, int priority);
  12118. void juce_setCurrentThreadName (const String& name);
  12119. #if JUCE_WIN32
  12120. void juce_CloseThreadHandle (void* handle);
  12121. #endif
  12122. void Thread::threadEntryPoint (Thread* const thread)
  12123. {
  12124. {
  12125. const ScopedLock sl (runningThreadsLock);
  12126. runningThreads.add (thread);
  12127. }
  12128. JUCE_TRY
  12129. {
  12130. thread->threadId_ = Thread::getCurrentThreadId();
  12131. if (thread->threadName_.isNotEmpty())
  12132. juce_setCurrentThreadName (thread->threadName_);
  12133. if (thread->startSuspensionEvent_.wait (10000))
  12134. {
  12135. if (thread->affinityMask_ != 0)
  12136. setCurrentThreadAffinityMask (thread->affinityMask_);
  12137. thread->run();
  12138. }
  12139. }
  12140. JUCE_CATCH_ALL_ASSERT
  12141. {
  12142. const ScopedLock sl (runningThreadsLock);
  12143. jassert (runningThreads.contains (thread));
  12144. runningThreads.removeValue (thread);
  12145. }
  12146. #if JUCE_WIN32
  12147. juce_CloseThreadHandle (thread->threadHandle_);
  12148. #endif
  12149. thread->threadHandle_ = 0;
  12150. thread->threadId_ = 0;
  12151. }
  12152. // used to wrap the incoming call from the platform-specific code
  12153. void JUCE_API juce_threadEntryPoint (void* userData)
  12154. {
  12155. Thread::threadEntryPoint ((Thread*) userData);
  12156. }
  12157. Thread::Thread (const String& threadName)
  12158. : threadName_ (threadName),
  12159. threadHandle_ (0),
  12160. threadPriority_ (5),
  12161. threadId_ (0),
  12162. affinityMask_ (0),
  12163. threadShouldExit_ (false)
  12164. {
  12165. }
  12166. Thread::~Thread()
  12167. {
  12168. stopThread (100);
  12169. }
  12170. void Thread::startThread()
  12171. {
  12172. const ScopedLock sl (startStopLock);
  12173. threadShouldExit_ = false;
  12174. if (threadHandle_ == 0)
  12175. {
  12176. threadHandle_ = juce_createThread ((void*) this);
  12177. juce_setThreadPriority (threadHandle_, threadPriority_);
  12178. startSuspensionEvent_.signal();
  12179. }
  12180. }
  12181. void Thread::startThread (const int priority)
  12182. {
  12183. const ScopedLock sl (startStopLock);
  12184. if (threadHandle_ == 0)
  12185. {
  12186. threadPriority_ = priority;
  12187. startThread();
  12188. }
  12189. else
  12190. {
  12191. setPriority (priority);
  12192. }
  12193. }
  12194. bool Thread::isThreadRunning() const
  12195. {
  12196. return threadHandle_ != 0;
  12197. }
  12198. void Thread::signalThreadShouldExit()
  12199. {
  12200. threadShouldExit_ = true;
  12201. }
  12202. bool Thread::waitForThreadToExit (const int timeOutMilliseconds) const
  12203. {
  12204. // Doh! So how exactly do you expect this thread to wait for itself to stop??
  12205. jassert (getThreadId() != getCurrentThreadId());
  12206. const int sleepMsPerIteration = 5;
  12207. int count = timeOutMilliseconds / sleepMsPerIteration;
  12208. while (isThreadRunning())
  12209. {
  12210. if (timeOutMilliseconds > 0 && --count < 0)
  12211. return false;
  12212. sleep (sleepMsPerIteration);
  12213. }
  12214. return true;
  12215. }
  12216. void Thread::stopThread (const int timeOutMilliseconds)
  12217. {
  12218. // agh! You can't stop the thread that's calling this method! How on earth
  12219. // would that work??
  12220. jassert (getCurrentThreadId() != getThreadId());
  12221. const ScopedLock sl (startStopLock);
  12222. if (isThreadRunning())
  12223. {
  12224. signalThreadShouldExit();
  12225. notify();
  12226. if (timeOutMilliseconds != 0)
  12227. waitForThreadToExit (timeOutMilliseconds);
  12228. if (isThreadRunning())
  12229. {
  12230. // very bad karma if this point is reached, as
  12231. // there are bound to be locks and events left in
  12232. // silly states when a thread is killed by force..
  12233. jassertfalse
  12234. Logger::writeToLog ("!! killing thread by force !!");
  12235. juce_killThread (threadHandle_);
  12236. threadHandle_ = 0;
  12237. threadId_ = 0;
  12238. const ScopedLock sl2 (runningThreadsLock);
  12239. runningThreads.removeValue (this);
  12240. }
  12241. }
  12242. }
  12243. bool Thread::setPriority (const int priority)
  12244. {
  12245. const ScopedLock sl (startStopLock);
  12246. const bool worked = juce_setThreadPriority (threadHandle_, priority);
  12247. if (worked)
  12248. threadPriority_ = priority;
  12249. return worked;
  12250. }
  12251. bool Thread::setCurrentThreadPriority (const int priority)
  12252. {
  12253. return juce_setThreadPriority (0, priority);
  12254. }
  12255. void Thread::setAffinityMask (const uint32 affinityMask)
  12256. {
  12257. affinityMask_ = affinityMask;
  12258. }
  12259. bool Thread::wait (const int timeOutMilliseconds) const
  12260. {
  12261. return defaultEvent_.wait (timeOutMilliseconds);
  12262. }
  12263. void Thread::notify() const
  12264. {
  12265. defaultEvent_.signal();
  12266. }
  12267. int Thread::getNumRunningThreads()
  12268. {
  12269. return runningThreads.size();
  12270. }
  12271. Thread* Thread::getCurrentThread()
  12272. {
  12273. const ThreadID thisId = getCurrentThreadId();
  12274. const ScopedLock sl (runningThreadsLock);
  12275. for (int i = runningThreads.size(); --i >= 0;)
  12276. {
  12277. Thread* const t = runningThreads.getUnchecked(i);
  12278. if (t->threadId_ == thisId)
  12279. return t;
  12280. }
  12281. return 0;
  12282. }
  12283. void Thread::stopAllThreads (const int timeOutMilliseconds)
  12284. {
  12285. {
  12286. const ScopedLock sl (runningThreadsLock);
  12287. for (int i = runningThreads.size(); --i >= 0;)
  12288. runningThreads.getUnchecked(i)->signalThreadShouldExit();
  12289. }
  12290. for (;;)
  12291. {
  12292. Thread* firstThread;
  12293. {
  12294. const ScopedLock sl (runningThreadsLock);
  12295. firstThread = runningThreads.getFirst();
  12296. }
  12297. if (firstThread == 0)
  12298. break;
  12299. firstThread->stopThread (timeOutMilliseconds);
  12300. }
  12301. }
  12302. Array<Thread*> Thread::runningThreads;
  12303. CriticalSection Thread::runningThreadsLock;
  12304. END_JUCE_NAMESPACE
  12305. /*** End of inlined file: juce_Thread.cpp ***/
  12306. /*** Start of inlined file: juce_ThreadPool.cpp ***/
  12307. BEGIN_JUCE_NAMESPACE
  12308. ThreadPoolJob::ThreadPoolJob (const String& name)
  12309. : jobName (name),
  12310. pool (0),
  12311. shouldStop (false),
  12312. isActive (false),
  12313. shouldBeDeleted (false)
  12314. {
  12315. }
  12316. ThreadPoolJob::~ThreadPoolJob()
  12317. {
  12318. // you mustn't delete a job while it's still in a pool! Use ThreadPool::removeJob()
  12319. // to remove it first!
  12320. jassert (pool == 0 || ! pool->contains (this));
  12321. }
  12322. const String ThreadPoolJob::getJobName() const
  12323. {
  12324. return jobName;
  12325. }
  12326. void ThreadPoolJob::setJobName (const String& newName)
  12327. {
  12328. jobName = newName;
  12329. }
  12330. void ThreadPoolJob::signalJobShouldExit()
  12331. {
  12332. shouldStop = true;
  12333. }
  12334. class ThreadPool::ThreadPoolThread : public Thread
  12335. {
  12336. public:
  12337. ThreadPoolThread (ThreadPool& pool_)
  12338. : Thread (T("Pool")),
  12339. pool (pool_),
  12340. busy (false)
  12341. {
  12342. }
  12343. ~ThreadPoolThread()
  12344. {
  12345. }
  12346. void run()
  12347. {
  12348. while (! threadShouldExit())
  12349. {
  12350. if (! pool.runNextJob())
  12351. wait (500);
  12352. }
  12353. }
  12354. private:
  12355. ThreadPool& pool;
  12356. bool volatile busy;
  12357. ThreadPoolThread (const ThreadPoolThread&);
  12358. ThreadPoolThread& operator= (const ThreadPoolThread&);
  12359. };
  12360. ThreadPool::ThreadPool (const int numThreads,
  12361. const bool startThreadsOnlyWhenNeeded,
  12362. const int stopThreadsWhenNotUsedTimeoutMs)
  12363. : threadStopTimeout (stopThreadsWhenNotUsedTimeoutMs),
  12364. priority (5)
  12365. {
  12366. jassert (numThreads > 0); // not much point having one of these with no threads in it.
  12367. for (int i = jmax (1, numThreads); --i >= 0;)
  12368. threads.add (new ThreadPoolThread (*this));
  12369. if (! startThreadsOnlyWhenNeeded)
  12370. for (int i = threads.size(); --i >= 0;)
  12371. threads.getUnchecked(i)->startThread (priority);
  12372. }
  12373. ThreadPool::~ThreadPool()
  12374. {
  12375. removeAllJobs (true, 4000);
  12376. int i;
  12377. for (i = threads.size(); --i >= 0;)
  12378. threads.getUnchecked(i)->signalThreadShouldExit();
  12379. for (i = threads.size(); --i >= 0;)
  12380. threads.getUnchecked(i)->stopThread (500);
  12381. }
  12382. void ThreadPool::addJob (ThreadPoolJob* const job)
  12383. {
  12384. jassert (job != 0);
  12385. jassert (job->pool == 0);
  12386. if (job->pool == 0)
  12387. {
  12388. job->pool = this;
  12389. job->shouldStop = false;
  12390. job->isActive = false;
  12391. {
  12392. const ScopedLock sl (lock);
  12393. jobs.add (job);
  12394. int numRunning = 0;
  12395. for (int i = threads.size(); --i >= 0;)
  12396. if (threads.getUnchecked(i)->isThreadRunning() && ! threads.getUnchecked(i)->threadShouldExit())
  12397. ++numRunning;
  12398. if (numRunning < threads.size())
  12399. {
  12400. bool startedOne = false;
  12401. int n = 1000;
  12402. while (--n >= 0 && ! startedOne)
  12403. {
  12404. for (int i = threads.size(); --i >= 0;)
  12405. {
  12406. if (! threads.getUnchecked(i)->isThreadRunning())
  12407. {
  12408. threads.getUnchecked(i)->startThread (priority);
  12409. startedOne = true;
  12410. break;
  12411. }
  12412. }
  12413. if (! startedOne)
  12414. Thread::sleep (2);
  12415. }
  12416. }
  12417. }
  12418. for (int i = threads.size(); --i >= 0;)
  12419. threads.getUnchecked(i)->notify();
  12420. }
  12421. }
  12422. int ThreadPool::getNumJobs() const
  12423. {
  12424. return jobs.size();
  12425. }
  12426. ThreadPoolJob* ThreadPool::getJob (const int index) const
  12427. {
  12428. const ScopedLock sl (lock);
  12429. return (ThreadPoolJob*) jobs [index];
  12430. }
  12431. bool ThreadPool::contains (const ThreadPoolJob* const job) const
  12432. {
  12433. const ScopedLock sl (lock);
  12434. return jobs.contains (const_cast <ThreadPoolJob*> (job));
  12435. }
  12436. bool ThreadPool::isJobRunning (const ThreadPoolJob* const job) const
  12437. {
  12438. const ScopedLock sl (lock);
  12439. return jobs.contains (const_cast <ThreadPoolJob*> (job)) && job->isActive;
  12440. }
  12441. bool ThreadPool::waitForJobToFinish (const ThreadPoolJob* const job,
  12442. const int timeOutMs) const
  12443. {
  12444. if (job != 0)
  12445. {
  12446. const uint32 start = Time::getMillisecondCounter();
  12447. while (contains (job))
  12448. {
  12449. if (timeOutMs >= 0 && Time::getMillisecondCounter() >= start + timeOutMs)
  12450. return false;
  12451. jobFinishedSignal.wait (2);
  12452. }
  12453. }
  12454. return true;
  12455. }
  12456. bool ThreadPool::removeJob (ThreadPoolJob* const job,
  12457. const bool interruptIfRunning,
  12458. const int timeOutMs)
  12459. {
  12460. bool dontWait = true;
  12461. if (job != 0)
  12462. {
  12463. const ScopedLock sl (lock);
  12464. if (jobs.contains (job))
  12465. {
  12466. if (job->isActive)
  12467. {
  12468. if (interruptIfRunning)
  12469. job->signalJobShouldExit();
  12470. dontWait = false;
  12471. }
  12472. else
  12473. {
  12474. jobs.removeValue (job);
  12475. }
  12476. }
  12477. }
  12478. return dontWait || waitForJobToFinish (job, timeOutMs);
  12479. }
  12480. bool ThreadPool::removeAllJobs (const bool interruptRunningJobs,
  12481. const int timeOutMs,
  12482. const bool deleteInactiveJobs,
  12483. ThreadPool::JobSelector* selectedJobsToRemove)
  12484. {
  12485. Array <ThreadPoolJob*> jobsToWaitFor;
  12486. {
  12487. const ScopedLock sl (lock);
  12488. for (int i = jobs.size(); --i >= 0;)
  12489. {
  12490. ThreadPoolJob* const job = jobs.getUnchecked(i);
  12491. if (selectedJobsToRemove == 0 || selectedJobsToRemove->isJobSuitable (job))
  12492. {
  12493. if (job->isActive)
  12494. {
  12495. jobsToWaitFor.add (job);
  12496. if (interruptRunningJobs)
  12497. job->signalJobShouldExit();
  12498. }
  12499. else
  12500. {
  12501. jobs.remove (i);
  12502. if (deleteInactiveJobs)
  12503. delete job;
  12504. }
  12505. }
  12506. }
  12507. }
  12508. const uint32 start = Time::getMillisecondCounter();
  12509. for (;;)
  12510. {
  12511. for (int i = jobsToWaitFor.size(); --i >= 0;)
  12512. if (! isJobRunning (jobsToWaitFor.getUnchecked (i)))
  12513. jobsToWaitFor.remove (i);
  12514. if (jobsToWaitFor.size() == 0)
  12515. break;
  12516. if (timeOutMs >= 0 && Time::getMillisecondCounter() >= start + timeOutMs)
  12517. return false;
  12518. jobFinishedSignal.wait (20);
  12519. }
  12520. return true;
  12521. }
  12522. const StringArray ThreadPool::getNamesOfAllJobs (const bool onlyReturnActiveJobs) const
  12523. {
  12524. StringArray s;
  12525. const ScopedLock sl (lock);
  12526. for (int i = 0; i < jobs.size(); ++i)
  12527. {
  12528. const ThreadPoolJob* const job = jobs.getUnchecked(i);
  12529. if (job->isActive || ! onlyReturnActiveJobs)
  12530. s.add (job->getJobName());
  12531. }
  12532. return s;
  12533. }
  12534. bool ThreadPool::setThreadPriorities (const int newPriority)
  12535. {
  12536. bool ok = true;
  12537. if (priority != newPriority)
  12538. {
  12539. priority = newPriority;
  12540. for (int i = threads.size(); --i >= 0;)
  12541. if (! threads.getUnchecked(i)->setPriority (newPriority))
  12542. ok = false;
  12543. }
  12544. return ok;
  12545. }
  12546. bool ThreadPool::runNextJob()
  12547. {
  12548. ThreadPoolJob* job = 0;
  12549. {
  12550. const ScopedLock sl (lock);
  12551. for (int i = 0; i < jobs.size(); ++i)
  12552. {
  12553. job = jobs[i];
  12554. if (job != 0 && ! (job->isActive || job->shouldStop))
  12555. break;
  12556. job = 0;
  12557. }
  12558. if (job != 0)
  12559. job->isActive = true;
  12560. }
  12561. if (job != 0)
  12562. {
  12563. JUCE_TRY
  12564. {
  12565. ThreadPoolJob::JobStatus result = job->runJob();
  12566. lastJobEndTime = Time::getApproximateMillisecondCounter();
  12567. const ScopedLock sl (lock);
  12568. if (jobs.contains (job))
  12569. {
  12570. job->isActive = false;
  12571. if (result != ThreadPoolJob::jobNeedsRunningAgain || job->shouldStop)
  12572. {
  12573. job->pool = 0;
  12574. job->shouldStop = true;
  12575. jobs.removeValue (job);
  12576. if (result == ThreadPoolJob::jobHasFinishedAndShouldBeDeleted)
  12577. delete job;
  12578. jobFinishedSignal.signal();
  12579. }
  12580. else
  12581. {
  12582. // move the job to the end of the queue if it wants another go
  12583. jobs.move (jobs.indexOf (job), -1);
  12584. }
  12585. }
  12586. }
  12587. #if JUCE_CATCH_UNHANDLED_EXCEPTIONS
  12588. catch (...)
  12589. {
  12590. const ScopedLock sl (lock);
  12591. jobs.removeValue (job);
  12592. }
  12593. #endif
  12594. }
  12595. else
  12596. {
  12597. if (threadStopTimeout > 0
  12598. && Time::getApproximateMillisecondCounter() > lastJobEndTime + threadStopTimeout)
  12599. {
  12600. const ScopedLock sl (lock);
  12601. if (jobs.size() == 0)
  12602. for (int i = threads.size(); --i >= 0;)
  12603. threads.getUnchecked(i)->signalThreadShouldExit();
  12604. }
  12605. else
  12606. {
  12607. return false;
  12608. }
  12609. }
  12610. return true;
  12611. }
  12612. END_JUCE_NAMESPACE
  12613. /*** End of inlined file: juce_ThreadPool.cpp ***/
  12614. /*** Start of inlined file: juce_TimeSliceThread.cpp ***/
  12615. BEGIN_JUCE_NAMESPACE
  12616. TimeSliceThread::TimeSliceThread (const String& threadName)
  12617. : Thread (threadName),
  12618. index (0),
  12619. clientBeingCalled (0),
  12620. clientsChanged (false)
  12621. {
  12622. }
  12623. TimeSliceThread::~TimeSliceThread()
  12624. {
  12625. stopThread (2000);
  12626. }
  12627. void TimeSliceThread::addTimeSliceClient (TimeSliceClient* const client)
  12628. {
  12629. const ScopedLock sl (listLock);
  12630. clients.addIfNotAlreadyThere (client);
  12631. clientsChanged = true;
  12632. notify();
  12633. }
  12634. void TimeSliceThread::removeTimeSliceClient (TimeSliceClient* const client)
  12635. {
  12636. const ScopedLock sl1 (listLock);
  12637. clientsChanged = true;
  12638. // if there's a chance we're in the middle of calling this client, we need to
  12639. // also lock the outer lock..
  12640. if (clientBeingCalled == client)
  12641. {
  12642. const ScopedUnlock ul (listLock); // unlock first to get the order right..
  12643. const ScopedLock sl2 (callbackLock);
  12644. const ScopedLock sl3 (listLock);
  12645. clients.removeValue (client);
  12646. }
  12647. else
  12648. {
  12649. clients.removeValue (client);
  12650. }
  12651. }
  12652. int TimeSliceThread::getNumClients() const
  12653. {
  12654. return clients.size();
  12655. }
  12656. TimeSliceClient* TimeSliceThread::getClient (const int i) const
  12657. {
  12658. const ScopedLock sl (listLock);
  12659. return clients [i];
  12660. }
  12661. void TimeSliceThread::run()
  12662. {
  12663. int numCallsSinceBusy = 0;
  12664. while (! threadShouldExit())
  12665. {
  12666. int timeToWait = 500;
  12667. {
  12668. const ScopedLock sl (callbackLock);
  12669. {
  12670. const ScopedLock sl2 (listLock);
  12671. if (clients.size() > 0)
  12672. {
  12673. index = (index + 1) % clients.size();
  12674. clientBeingCalled = clients [index];
  12675. }
  12676. else
  12677. {
  12678. index = 0;
  12679. clientBeingCalled = 0;
  12680. }
  12681. if (clientsChanged)
  12682. {
  12683. clientsChanged = false;
  12684. numCallsSinceBusy = 0;
  12685. }
  12686. }
  12687. if (clientBeingCalled != 0)
  12688. {
  12689. if (clientBeingCalled->useTimeSlice())
  12690. numCallsSinceBusy = 0;
  12691. else
  12692. ++numCallsSinceBusy;
  12693. if (numCallsSinceBusy >= clients.size())
  12694. timeToWait = 500;
  12695. else if (index == 0)
  12696. timeToWait = 1; // throw in an occasional pause, to stop everything locking up
  12697. else
  12698. timeToWait = 0;
  12699. }
  12700. }
  12701. if (timeToWait > 0)
  12702. wait (timeToWait);
  12703. }
  12704. }
  12705. END_JUCE_NAMESPACE
  12706. /*** End of inlined file: juce_TimeSliceThread.cpp ***/
  12707. #endif
  12708. #if JUCE_BUILD_MISC
  12709. /*** Start of inlined file: juce_ValueTree.cpp ***/
  12710. BEGIN_JUCE_NAMESPACE
  12711. class ValueTreeSetPropertyAction : public UndoableAction
  12712. {
  12713. public:
  12714. ValueTreeSetPropertyAction (const ValueTree::SharedObjectPtr& target_, const var::identifier& name_,
  12715. const var& newValue_, const bool isAddingNewProperty_, const bool isDeletingProperty_)
  12716. : target (target_), name (name_), newValue (newValue_),
  12717. isAddingNewProperty (isAddingNewProperty_),
  12718. isDeletingProperty (isDeletingProperty_)
  12719. {
  12720. if (! isAddingNewProperty)
  12721. oldValue = target_->getProperty (name_);
  12722. }
  12723. ~ValueTreeSetPropertyAction() {}
  12724. bool perform()
  12725. {
  12726. jassert (! (isAddingNewProperty && target->hasProperty (name)));
  12727. if (isDeletingProperty)
  12728. target->removeProperty (name, 0);
  12729. else
  12730. target->setProperty (name, newValue, 0);
  12731. return true;
  12732. }
  12733. bool undo()
  12734. {
  12735. if (isAddingNewProperty)
  12736. target->removeProperty (name, 0);
  12737. else
  12738. target->setProperty (name, oldValue, 0);
  12739. return true;
  12740. }
  12741. int getSizeInUnits()
  12742. {
  12743. return (int) sizeof (*this); //xxx should be more accurate
  12744. }
  12745. private:
  12746. const ValueTree::SharedObjectPtr target;
  12747. const var::identifier name;
  12748. const var newValue;
  12749. var oldValue;
  12750. const bool isAddingNewProperty, isDeletingProperty;
  12751. ValueTreeSetPropertyAction (const ValueTreeSetPropertyAction&);
  12752. ValueTreeSetPropertyAction& operator= (const ValueTreeSetPropertyAction&);
  12753. };
  12754. class ValueTreeChildChangeAction : public UndoableAction
  12755. {
  12756. public:
  12757. ValueTreeChildChangeAction (const ValueTree::SharedObjectPtr& target_, const int childIndex_,
  12758. const ValueTree::SharedObjectPtr& newChild_)
  12759. : target (target_),
  12760. child (newChild_ != 0 ? newChild_ : target_->children [childIndex_]),
  12761. childIndex (childIndex_),
  12762. isDeleting (newChild_ == 0)
  12763. {
  12764. jassert (child != 0);
  12765. }
  12766. ~ValueTreeChildChangeAction() {}
  12767. bool perform()
  12768. {
  12769. if (isDeleting)
  12770. target->removeChild (childIndex, 0);
  12771. else
  12772. target->addChild (child, childIndex, 0);
  12773. return true;
  12774. }
  12775. bool undo()
  12776. {
  12777. if (isDeleting)
  12778. target->addChild (child, childIndex, 0);
  12779. else
  12780. target->removeChild (childIndex, 0);
  12781. return true;
  12782. }
  12783. int getSizeInUnits()
  12784. {
  12785. return (int) sizeof (*this); //xxx should be more accurate
  12786. }
  12787. private:
  12788. const ValueTree::SharedObjectPtr target, child;
  12789. const int childIndex;
  12790. const bool isDeleting;
  12791. ValueTreeChildChangeAction (const ValueTreeChildChangeAction&);
  12792. ValueTreeChildChangeAction& operator= (const ValueTreeChildChangeAction&);
  12793. };
  12794. ValueTree::SharedObject::SharedObject (const String& type_)
  12795. : type (type_), parent (0)
  12796. {
  12797. }
  12798. ValueTree::SharedObject::SharedObject (const SharedObject& other)
  12799. : type (other.type), properties (other.properties), parent (0)
  12800. {
  12801. for (int i = 0; i < other.children.size(); ++i)
  12802. children.add (new SharedObject (*other.children.getUnchecked(i)));
  12803. }
  12804. ValueTree::SharedObject::~SharedObject()
  12805. {
  12806. jassert (parent == 0); // this should never happen unless something isn't obeying the ref-counting!
  12807. for (int i = children.size(); --i >= 0;)
  12808. {
  12809. const SharedObjectPtr c (children.getUnchecked(i));
  12810. c->parent = 0;
  12811. children.remove (i);
  12812. c->sendParentChangeMessage();
  12813. }
  12814. }
  12815. void ValueTree::SharedObject::sendPropertyChangeMessage (ValueTree& tree, const var::identifier& property)
  12816. {
  12817. for (int i = valueTreesWithListeners.size(); --i >= 0;)
  12818. {
  12819. ValueTree* const v = valueTreesWithListeners[i];
  12820. if (v != 0)
  12821. v->listeners.call (&ValueTree::Listener::valueTreePropertyChanged, tree, property);
  12822. }
  12823. }
  12824. void ValueTree::SharedObject::sendPropertyChangeMessage (const var::identifier& property)
  12825. {
  12826. ValueTree tree (this);
  12827. ValueTree::SharedObject* t = this;
  12828. while (t != 0)
  12829. {
  12830. t->sendPropertyChangeMessage (tree, property);
  12831. t = t->parent;
  12832. }
  12833. }
  12834. void ValueTree::SharedObject::sendChildChangeMessage (ValueTree& tree)
  12835. {
  12836. for (int i = valueTreesWithListeners.size(); --i >= 0;)
  12837. {
  12838. ValueTree* const v = valueTreesWithListeners[i];
  12839. if (v != 0)
  12840. v->listeners.call (&ValueTree::Listener::valueTreeChildrenChanged, tree);
  12841. }
  12842. }
  12843. void ValueTree::SharedObject::sendChildChangeMessage()
  12844. {
  12845. ValueTree tree (this);
  12846. ValueTree::SharedObject* t = this;
  12847. while (t != 0)
  12848. {
  12849. t->sendChildChangeMessage (tree);
  12850. t = t->parent;
  12851. }
  12852. }
  12853. void ValueTree::SharedObject::sendParentChangeMessage()
  12854. {
  12855. ValueTree tree (this);
  12856. int i;
  12857. for (i = children.size(); --i >= 0;)
  12858. {
  12859. SharedObject* const t = children[i];
  12860. if (t != 0)
  12861. t->sendParentChangeMessage();
  12862. }
  12863. for (i = valueTreesWithListeners.size(); --i >= 0;)
  12864. {
  12865. ValueTree* const v = valueTreesWithListeners[i];
  12866. if (v != 0)
  12867. v->listeners.call (&ValueTree::Listener::valueTreeParentChanged, tree);
  12868. }
  12869. }
  12870. const var& ValueTree::SharedObject::getProperty (const var::identifier& name) const
  12871. {
  12872. return properties [name];
  12873. }
  12874. void ValueTree::SharedObject::setProperty (const var::identifier& name, const var& newValue, UndoManager* const undoManager)
  12875. {
  12876. if (undoManager == 0)
  12877. {
  12878. if (properties.set (name, newValue))
  12879. sendPropertyChangeMessage (name);
  12880. }
  12881. else
  12882. {
  12883. var* const existingValue = properties.getItem (name);
  12884. if (existingValue != 0)
  12885. {
  12886. if (*existingValue != newValue)
  12887. undoManager->perform (new ValueTreeSetPropertyAction (this, name, newValue, false, false));
  12888. }
  12889. else
  12890. {
  12891. undoManager->perform (new ValueTreeSetPropertyAction (this, name, newValue, true, false));
  12892. }
  12893. }
  12894. }
  12895. bool ValueTree::SharedObject::hasProperty (const var::identifier& name) const
  12896. {
  12897. return properties.contains (name);
  12898. }
  12899. void ValueTree::SharedObject::removeProperty (const var::identifier& name, UndoManager* const undoManager)
  12900. {
  12901. if (undoManager == 0)
  12902. {
  12903. if (properties.remove (name))
  12904. sendPropertyChangeMessage (name);
  12905. }
  12906. else
  12907. {
  12908. if (properties.contains (name))
  12909. undoManager->perform (new ValueTreeSetPropertyAction (this, name, var::null, false, true));
  12910. }
  12911. }
  12912. void ValueTree::SharedObject::removeAllProperties (UndoManager* const undoManager)
  12913. {
  12914. if (undoManager == 0)
  12915. {
  12916. while (properties.size() > 0)
  12917. {
  12918. const var::identifier name (properties.getName (properties.size() - 1));
  12919. properties.remove (name);
  12920. sendPropertyChangeMessage (name);
  12921. }
  12922. }
  12923. else
  12924. {
  12925. for (int i = properties.size(); --i >= 0;)
  12926. undoManager->perform (new ValueTreeSetPropertyAction (this, properties.getName(i), var::null, false, true));
  12927. }
  12928. }
  12929. ValueTree ValueTree::SharedObject::getChildWithName (const String& typeToMatch) const
  12930. {
  12931. for (int i = 0; i < children.size(); ++i)
  12932. if (children.getUnchecked(i)->type == typeToMatch)
  12933. return (SharedObject*) children.getUnchecked(i);
  12934. return (SharedObject*) 0;
  12935. }
  12936. ValueTree ValueTree::SharedObject::getChildWithProperty (const var::identifier& propertyName, const var& propertyValue) const
  12937. {
  12938. for (int i = 0; i < children.size(); ++i)
  12939. if (children.getUnchecked(i)->getProperty (propertyName) == propertyValue)
  12940. return (SharedObject*) children.getUnchecked(i);
  12941. return (SharedObject*) 0;
  12942. }
  12943. bool ValueTree::SharedObject::isAChildOf (const SharedObject* const possibleParent) const
  12944. {
  12945. const SharedObject* p = parent;
  12946. while (p != 0)
  12947. {
  12948. if (p == possibleParent)
  12949. return true;
  12950. p = p->parent;
  12951. }
  12952. return false;
  12953. }
  12954. void ValueTree::SharedObject::addChild (SharedObject* child, int index, UndoManager* const undoManager)
  12955. {
  12956. if (child != 0 && child->parent != this)
  12957. {
  12958. if (child != this && ! isAChildOf (child))
  12959. {
  12960. // You should always make sure that a child is removed from its previous parent before
  12961. // adding it somewhere else - otherwise, it's ambiguous as to whether a different
  12962. // undomanager should be used when removing it from its current parent..
  12963. jassert (child->parent == 0);
  12964. if (child->parent != 0)
  12965. {
  12966. jassert (child->parent->children.indexOf (child) >= 0);
  12967. child->parent->removeChild (child->parent->children.indexOf (child), undoManager);
  12968. }
  12969. if (undoManager == 0)
  12970. {
  12971. children.insert (index, child);
  12972. child->parent = this;
  12973. sendChildChangeMessage();
  12974. child->sendParentChangeMessage();
  12975. }
  12976. else
  12977. {
  12978. undoManager->perform (new ValueTreeChildChangeAction (this, index, child));
  12979. }
  12980. }
  12981. else
  12982. {
  12983. // You're attempting to create a recursive loop! A node
  12984. // can't be a child of one of its own children!
  12985. jassertfalse
  12986. }
  12987. }
  12988. }
  12989. void ValueTree::SharedObject::removeChild (const int childIndex, UndoManager* const undoManager)
  12990. {
  12991. const SharedObjectPtr child (children [childIndex]);
  12992. if (child != 0)
  12993. {
  12994. if (undoManager == 0)
  12995. {
  12996. children.remove (childIndex);
  12997. child->parent = 0;
  12998. sendChildChangeMessage();
  12999. child->sendParentChangeMessage();
  13000. }
  13001. else
  13002. {
  13003. undoManager->perform (new ValueTreeChildChangeAction (this, childIndex, 0));
  13004. }
  13005. }
  13006. }
  13007. void ValueTree::SharedObject::removeAllChildren (UndoManager* const undoManager)
  13008. {
  13009. while (children.size() > 0)
  13010. removeChild (children.size() - 1, undoManager);
  13011. }
  13012. ValueTree::ValueTree (const String& type_)
  13013. : object (new ValueTree::SharedObject (type_))
  13014. {
  13015. jassert (type_.isNotEmpty()); // All objects should be given a sensible type name!
  13016. }
  13017. ValueTree::ValueTree (SharedObject* const object_)
  13018. : object (object_)
  13019. {
  13020. }
  13021. ValueTree::ValueTree (const ValueTree& other)
  13022. : object (other.object)
  13023. {
  13024. }
  13025. ValueTree& ValueTree::operator= (const ValueTree& other)
  13026. {
  13027. if (listeners.size() > 0)
  13028. {
  13029. if (object != 0)
  13030. object->valueTreesWithListeners.removeValue (this);
  13031. if (other.object != 0)
  13032. other.object->valueTreesWithListeners.add (this);
  13033. }
  13034. object = other.object;
  13035. return *this;
  13036. }
  13037. ValueTree::~ValueTree()
  13038. {
  13039. if (listeners.size() > 0 && object != 0)
  13040. object->valueTreesWithListeners.removeValue (this);
  13041. }
  13042. bool ValueTree::operator== (const ValueTree& other) const
  13043. {
  13044. return object == other.object;
  13045. }
  13046. bool ValueTree::operator!= (const ValueTree& other) const
  13047. {
  13048. return object != other.object;
  13049. }
  13050. ValueTree ValueTree::createCopy() const
  13051. {
  13052. return ValueTree (object != 0 ? new SharedObject (*object) : 0);
  13053. }
  13054. bool ValueTree::hasType (const String& typeName) const
  13055. {
  13056. return object != 0 && object->type == typeName;
  13057. }
  13058. const String ValueTree::getType() const
  13059. {
  13060. return object != 0 ? object->type : String::empty;
  13061. }
  13062. ValueTree ValueTree::getParent() const
  13063. {
  13064. return object != 0 ? ValueTree (object->parent) : ValueTree ((SharedObject*) 0);
  13065. }
  13066. const var& ValueTree::operator[] (const var::identifier& name) const
  13067. {
  13068. return object == 0 ? var::null : object->getProperty (name);
  13069. }
  13070. const var& ValueTree::getProperty (const var::identifier& name) const
  13071. {
  13072. return object == 0 ? var::null : object->getProperty (name);
  13073. }
  13074. void ValueTree::setProperty (const var::identifier& name, const var& newValue, UndoManager* const undoManager)
  13075. {
  13076. jassert (name.name.isNotEmpty());
  13077. if (object != 0 && name.name.isNotEmpty())
  13078. object->setProperty (name, newValue, undoManager);
  13079. }
  13080. bool ValueTree::hasProperty (const var::identifier& name) const
  13081. {
  13082. return object != 0 && object->hasProperty (name);
  13083. }
  13084. void ValueTree::removeProperty (const var::identifier& name, UndoManager* const undoManager)
  13085. {
  13086. if (object != 0)
  13087. object->removeProperty (name, undoManager);
  13088. }
  13089. void ValueTree::removeAllProperties (UndoManager* const undoManager)
  13090. {
  13091. if (object != 0)
  13092. object->removeAllProperties (undoManager);
  13093. }
  13094. int ValueTree::getNumProperties() const
  13095. {
  13096. return object == 0 ? 0 : object->properties.size();
  13097. }
  13098. const var::identifier ValueTree::getPropertyName (int index) const
  13099. {
  13100. return (object == 0) ? var::identifier()
  13101. : object->properties.getName (index);
  13102. }
  13103. class ValueTreePropertyValueSource : public Value::ValueSource,
  13104. public ValueTree::Listener
  13105. {
  13106. public:
  13107. ValueTreePropertyValueSource (const ValueTree& tree_,
  13108. const var::identifier& property_,
  13109. UndoManager* const undoManager_)
  13110. : tree (tree_),
  13111. property (property_),
  13112. undoManager (undoManager_)
  13113. {
  13114. tree.addListener (this);
  13115. }
  13116. ~ValueTreePropertyValueSource()
  13117. {
  13118. tree.removeListener (this);
  13119. }
  13120. const var getValue() const
  13121. {
  13122. return tree [property];
  13123. }
  13124. void setValue (const var& newValue)
  13125. {
  13126. tree.setProperty (property, newValue, undoManager);
  13127. }
  13128. void valueTreePropertyChanged (ValueTree& treeWhosePropertyHasChanged, const var::identifier& changedProperty)
  13129. {
  13130. if (tree == treeWhosePropertyHasChanged && property == changedProperty)
  13131. sendChangeMessage (false);
  13132. }
  13133. void valueTreeChildrenChanged (ValueTree&) {}
  13134. void valueTreeParentChanged (ValueTree&) {}
  13135. private:
  13136. ValueTree tree;
  13137. const var::identifier property;
  13138. UndoManager* const undoManager;
  13139. ValueTreePropertyValueSource& operator= (const ValueTreePropertyValueSource&);
  13140. };
  13141. Value ValueTree::getPropertyAsValue (const var::identifier& name, UndoManager* const undoManager) const
  13142. {
  13143. return Value (new ValueTreePropertyValueSource (*this, name, undoManager));
  13144. }
  13145. int ValueTree::getNumChildren() const
  13146. {
  13147. return object == 0 ? 0 : object->children.size();
  13148. }
  13149. ValueTree ValueTree::getChild (int index) const
  13150. {
  13151. return object != 0 ? (SharedObject*) object->children [index] : ValueTree ((SharedObject*) 0);
  13152. }
  13153. ValueTree ValueTree::getChildWithName (const String& type) const
  13154. {
  13155. return object != 0 ? object->getChildWithName (type) : ValueTree ((SharedObject*) 0);
  13156. }
  13157. ValueTree ValueTree::getChildWithProperty (const var::identifier& propertyName, const var& propertyValue) const
  13158. {
  13159. return object != 0 ? object->getChildWithProperty (propertyName, propertyValue) : ValueTree ((SharedObject*) 0);
  13160. }
  13161. bool ValueTree::isAChildOf (const ValueTree& possibleParent) const
  13162. {
  13163. return object != 0 && object->isAChildOf (possibleParent.object);
  13164. }
  13165. void ValueTree::addChild (ValueTree child, int index, UndoManager* const undoManager)
  13166. {
  13167. if (object != 0)
  13168. object->addChild (child.object, index, undoManager);
  13169. }
  13170. void ValueTree::removeChild (const int childIndex, UndoManager* const undoManager)
  13171. {
  13172. if (object != 0)
  13173. object->removeChild (childIndex, undoManager);
  13174. }
  13175. void ValueTree::removeChild (ValueTree& child, UndoManager* const undoManager)
  13176. {
  13177. if (object != 0)
  13178. object->removeChild (object->children.indexOf (child.object), undoManager);
  13179. }
  13180. void ValueTree::removeAllChildren (UndoManager* const undoManager)
  13181. {
  13182. if (object != 0)
  13183. object->removeAllChildren (undoManager);
  13184. }
  13185. void ValueTree::addListener (Listener* listener)
  13186. {
  13187. if (listener != 0)
  13188. {
  13189. if (listeners.size() == 0 && object != 0)
  13190. object->valueTreesWithListeners.add (this);
  13191. listeners.add (listener);
  13192. }
  13193. }
  13194. void ValueTree::removeListener (Listener* listener)
  13195. {
  13196. listeners.remove (listener);
  13197. if (listeners.size() == 0 && object != 0)
  13198. object->valueTreesWithListeners.removeValue (this);
  13199. }
  13200. XmlElement* ValueTree::SharedObject::createXml() const
  13201. {
  13202. XmlElement* xml = new XmlElement (type);
  13203. int i;
  13204. for (i = 0; i < properties.size(); ++i)
  13205. {
  13206. var::identifier name (properties.getName(i));
  13207. const var& v = properties [name];
  13208. jassert (! v.isObject()); // DynamicObjects can't be stored as XML!
  13209. xml->setAttribute (name.name, v.toString());
  13210. }
  13211. for (i = 0; i < children.size(); ++i)
  13212. xml->addChildElement (children.getUnchecked(i)->createXml());
  13213. return xml;
  13214. }
  13215. XmlElement* ValueTree::createXml() const
  13216. {
  13217. return object != 0 ? object->createXml() : 0;
  13218. }
  13219. ValueTree ValueTree::fromXml (const XmlElement& xml)
  13220. {
  13221. ValueTree v (xml.getTagName());
  13222. const int numAtts = xml.getNumAttributes(); // xxx inefficient - should write an att iterator..
  13223. for (int i = 0; i < numAtts; ++i)
  13224. v.setProperty (xml.getAttributeName (i), var (xml.getAttributeValue (i)), 0);
  13225. forEachXmlChildElement (xml, e)
  13226. {
  13227. v.addChild (fromXml (*e), -1, 0);
  13228. }
  13229. return v;
  13230. }
  13231. void ValueTree::writeToStream (OutputStream& output)
  13232. {
  13233. output.writeString (getType());
  13234. const int numProps = getNumProperties();
  13235. output.writeCompressedInt (numProps);
  13236. int i;
  13237. for (i = 0; i < numProps; ++i)
  13238. {
  13239. const var::identifier name (getPropertyName(i));
  13240. output.writeString (name.name);
  13241. getProperty(name).writeToStream (output);
  13242. }
  13243. const int numChildren = getNumChildren();
  13244. output.writeCompressedInt (numChildren);
  13245. for (i = 0; i < numChildren; ++i)
  13246. getChild (i).writeToStream (output);
  13247. }
  13248. ValueTree ValueTree::readFromStream (InputStream& input)
  13249. {
  13250. String type (input.readString());
  13251. if (type.isEmpty())
  13252. return ValueTree ((SharedObject*) 0);
  13253. ValueTree v (type);
  13254. const int numProps = input.readCompressedInt();
  13255. if (numProps < 0)
  13256. {
  13257. jassertfalse // trying to read corrupted data!
  13258. return v;
  13259. }
  13260. int i;
  13261. for (i = 0; i < numProps; ++i)
  13262. {
  13263. const String name (input.readString());
  13264. jassert (name.isNotEmpty());
  13265. const var value (var::readFromStream (input));
  13266. v.setProperty (name, value, 0);
  13267. }
  13268. const int numChildren = input.readCompressedInt();
  13269. for (i = 0; i < numChildren; ++i)
  13270. v.addChild (readFromStream (input), -1, 0);
  13271. return v;
  13272. }
  13273. END_JUCE_NAMESPACE
  13274. /*** End of inlined file: juce_ValueTree.cpp ***/
  13275. /*** Start of inlined file: juce_Value.cpp ***/
  13276. BEGIN_JUCE_NAMESPACE
  13277. Value::ValueSource::ValueSource()
  13278. {
  13279. }
  13280. Value::ValueSource::~ValueSource()
  13281. {
  13282. }
  13283. void Value::ValueSource::sendChangeMessage (const bool synchronous)
  13284. {
  13285. if (synchronous)
  13286. {
  13287. for (int i = valuesWithListeners.size(); --i >= 0;)
  13288. {
  13289. Value* const v = valuesWithListeners[i];
  13290. if (v != 0)
  13291. v->callListeners();
  13292. }
  13293. }
  13294. else
  13295. {
  13296. triggerAsyncUpdate();
  13297. }
  13298. }
  13299. void Value::ValueSource::handleAsyncUpdate()
  13300. {
  13301. sendChangeMessage (true);
  13302. }
  13303. class SimpleValueSource : public Value::ValueSource
  13304. {
  13305. public:
  13306. SimpleValueSource()
  13307. {
  13308. }
  13309. SimpleValueSource (const var& initialValue)
  13310. : value (initialValue)
  13311. {
  13312. }
  13313. ~SimpleValueSource()
  13314. {
  13315. }
  13316. const var getValue() const
  13317. {
  13318. return value;
  13319. }
  13320. void setValue (const var& newValue)
  13321. {
  13322. if (newValue != value)
  13323. {
  13324. value = newValue;
  13325. sendChangeMessage (false);
  13326. }
  13327. }
  13328. private:
  13329. var value;
  13330. SimpleValueSource (const SimpleValueSource&);
  13331. SimpleValueSource& operator= (const SimpleValueSource&);
  13332. };
  13333. Value::Value()
  13334. : value (new SimpleValueSource())
  13335. {
  13336. }
  13337. Value::Value (ValueSource* const value_)
  13338. : value (value_)
  13339. {
  13340. jassert (value_ != 0);
  13341. }
  13342. Value::Value (const var& initialValue)
  13343. : value (new SimpleValueSource (initialValue))
  13344. {
  13345. }
  13346. Value::Value (const Value& other)
  13347. : value (other.value)
  13348. {
  13349. }
  13350. Value& Value::operator= (const Value& other)
  13351. {
  13352. value = other.value;
  13353. return *this;
  13354. }
  13355. Value::~Value()
  13356. {
  13357. if (listeners.size() > 0)
  13358. value->valuesWithListeners.removeValue (this);
  13359. }
  13360. const var Value::getValue() const
  13361. {
  13362. return value->getValue();
  13363. }
  13364. Value::operator const var() const
  13365. {
  13366. return getValue();
  13367. }
  13368. void Value::setValue (const var& newValue)
  13369. {
  13370. value->setValue (newValue);
  13371. }
  13372. const String Value::toString() const
  13373. {
  13374. return value->getValue().toString();
  13375. }
  13376. Value& Value::operator= (const var& newValue)
  13377. {
  13378. value->setValue (newValue);
  13379. return *this;
  13380. }
  13381. void Value::referTo (const Value& valueToReferTo)
  13382. {
  13383. if (valueToReferTo.value != value)
  13384. {
  13385. if (listeners.size() > 0)
  13386. {
  13387. value->valuesWithListeners.removeValue (this);
  13388. valueToReferTo.value->valuesWithListeners.add (this);
  13389. }
  13390. value = valueToReferTo.value;
  13391. callListeners();
  13392. }
  13393. }
  13394. bool Value::refersToSameSourceAs (const Value& other) const
  13395. {
  13396. return value == other.value;
  13397. }
  13398. bool Value::operator== (const Value& other) const
  13399. {
  13400. return value == other.value || value->getValue() == other.getValue();
  13401. }
  13402. bool Value::operator!= (const Value& other) const
  13403. {
  13404. return value != other.value && value->getValue() != other.getValue();
  13405. }
  13406. void Value::addListener (Listener* const listener)
  13407. {
  13408. if (listener != 0)
  13409. {
  13410. if (listeners.size() == 0)
  13411. value->valuesWithListeners.add (this);
  13412. listeners.add (listener);
  13413. }
  13414. }
  13415. void Value::removeListener (Listener* const listener)
  13416. {
  13417. listeners.remove (listener);
  13418. if (listeners.size() == 0)
  13419. value->valuesWithListeners.removeValue (this);
  13420. }
  13421. void Value::callListeners()
  13422. {
  13423. Value v (*this); // (create a copy in case this gets deleted by a callback)
  13424. listeners.call (&Listener::valueChanged, v);
  13425. }
  13426. OutputStream& JUCE_CALLTYPE operator<< (OutputStream& stream, const Value& value)
  13427. {
  13428. return stream << value.toString();
  13429. }
  13430. END_JUCE_NAMESPACE
  13431. /*** End of inlined file: juce_Value.cpp ***/
  13432. /*** Start of inlined file: juce_Application.cpp ***/
  13433. #if JUCE_MSVC
  13434. #pragma warning (push)
  13435. #pragma warning (disable: 4245 4514 4100)
  13436. #include <crtdbg.h>
  13437. #pragma warning (pop)
  13438. #endif
  13439. BEGIN_JUCE_NAMESPACE
  13440. void juce_setCurrentThreadName (const String& name);
  13441. static JUCEApplication* appInstance = 0;
  13442. JUCEApplication::JUCEApplication()
  13443. : appReturnValue (0),
  13444. stillInitialising (true)
  13445. {
  13446. }
  13447. JUCEApplication::~JUCEApplication()
  13448. {
  13449. if (appLock != 0)
  13450. {
  13451. appLock->exit();
  13452. appLock = 0;
  13453. }
  13454. }
  13455. JUCEApplication* JUCEApplication::getInstance() throw()
  13456. {
  13457. return appInstance;
  13458. }
  13459. bool JUCEApplication::isInitialising() const throw()
  13460. {
  13461. return stillInitialising;
  13462. }
  13463. const String JUCEApplication::getApplicationVersion()
  13464. {
  13465. return String::empty;
  13466. }
  13467. bool JUCEApplication::moreThanOneInstanceAllowed()
  13468. {
  13469. return true;
  13470. }
  13471. void JUCEApplication::anotherInstanceStarted (const String&)
  13472. {
  13473. }
  13474. void JUCEApplication::systemRequestedQuit()
  13475. {
  13476. quit();
  13477. }
  13478. void JUCEApplication::quit()
  13479. {
  13480. MessageManager::getInstance()->stopDispatchLoop();
  13481. }
  13482. void JUCEApplication::setApplicationReturnValue (const int newReturnValue) throw()
  13483. {
  13484. appReturnValue = newReturnValue;
  13485. }
  13486. void JUCEApplication::unhandledException (const std::exception*,
  13487. const String&,
  13488. const int)
  13489. {
  13490. jassertfalse
  13491. }
  13492. void JUCEApplication::sendUnhandledException (const std::exception* const e,
  13493. const char* const sourceFile,
  13494. const int lineNumber)
  13495. {
  13496. if (appInstance != 0)
  13497. appInstance->unhandledException (e, sourceFile, lineNumber);
  13498. }
  13499. ApplicationCommandTarget* JUCEApplication::getNextCommandTarget()
  13500. {
  13501. return 0;
  13502. }
  13503. void JUCEApplication::getAllCommands (Array <CommandID>& commands)
  13504. {
  13505. commands.add (StandardApplicationCommandIDs::quit);
  13506. }
  13507. void JUCEApplication::getCommandInfo (const CommandID commandID, ApplicationCommandInfo& result)
  13508. {
  13509. if (commandID == StandardApplicationCommandIDs::quit)
  13510. {
  13511. result.setInfo (TRANS("Quit"),
  13512. TRANS("Quits the application"),
  13513. "Application",
  13514. 0);
  13515. result.defaultKeypresses.add (KeyPress (T('q'), ModifierKeys::commandModifier, 0));
  13516. }
  13517. }
  13518. bool JUCEApplication::perform (const InvocationInfo& info)
  13519. {
  13520. if (info.commandID == StandardApplicationCommandIDs::quit)
  13521. {
  13522. systemRequestedQuit();
  13523. return true;
  13524. }
  13525. return false;
  13526. }
  13527. int JUCEApplication::main (String& commandLine, JUCEApplication* const app)
  13528. {
  13529. if (! app->initialiseApp (commandLine))
  13530. return 0;
  13531. // now loop until a quit message is received..
  13532. JUCE_TRY
  13533. {
  13534. MessageManager::getInstance()->runDispatchLoop();
  13535. }
  13536. #if JUCE_CATCH_UNHANDLED_EXCEPTIONS
  13537. catch (const std::exception& e)
  13538. {
  13539. app->unhandledException (&e, __FILE__, __LINE__);
  13540. }
  13541. catch (...)
  13542. {
  13543. app->unhandledException (0, __FILE__, __LINE__);
  13544. }
  13545. #endif
  13546. return shutdownAppAndClearUp();
  13547. }
  13548. bool JUCEApplication::initialiseApp (String& commandLine)
  13549. {
  13550. jassert (appInstance == 0);
  13551. appInstance = this;
  13552. commandLineParameters = commandLine.trim();
  13553. commandLine = String::empty;
  13554. initialiseJuce_GUI();
  13555. #if ! JUCE_IPHONE
  13556. jassert (appLock == 0); // initialiseApp must only be called once!
  13557. if (! moreThanOneInstanceAllowed())
  13558. {
  13559. appLock = new InterProcessLock ("juceAppLock_" + getApplicationName());
  13560. if (! appLock->enter(0))
  13561. {
  13562. MessageManager::broadcastMessage (getApplicationName() + "/" + commandLineParameters);
  13563. delete appInstance;
  13564. appInstance = 0;
  13565. DBG ("Another instance is running - quitting...");
  13566. return false;
  13567. }
  13568. }
  13569. #endif
  13570. // let the app do its setting-up..
  13571. initialise (commandLineParameters);
  13572. // register for broadcast new app messages
  13573. MessageManager::getInstance()->registerBroadcastListener (this);
  13574. stillInitialising = false;
  13575. return true;
  13576. }
  13577. int JUCEApplication::shutdownAppAndClearUp()
  13578. {
  13579. jassert (appInstance != 0);
  13580. ScopedPointer<JUCEApplication> app (appInstance);
  13581. int returnValue = 0;
  13582. MessageManager::getInstance()->deregisterBroadcastListener ((JUCEApplication*) app);
  13583. static bool reentrancyCheck = false;
  13584. if (! reentrancyCheck)
  13585. {
  13586. reentrancyCheck = true;
  13587. JUCE_TRY
  13588. {
  13589. // give the app a chance to clean up..
  13590. app->shutdown();
  13591. }
  13592. #if JUCE_CATCH_UNHANDLED_EXCEPTIONS
  13593. catch (const std::exception& e)
  13594. {
  13595. app->unhandledException (&e, __FILE__, __LINE__);
  13596. }
  13597. catch (...)
  13598. {
  13599. app->unhandledException (0, __FILE__, __LINE__);
  13600. }
  13601. #endif
  13602. JUCE_TRY
  13603. {
  13604. shutdownJuce_GUI();
  13605. returnValue = app->getApplicationReturnValue();
  13606. appInstance = 0;
  13607. app = 0;
  13608. }
  13609. JUCE_CATCH_ALL_ASSERT
  13610. reentrancyCheck = false;
  13611. }
  13612. return returnValue;
  13613. }
  13614. #if JUCE_IPHONE
  13615. extern int juce_IPhoneMain (int argc, const char* argv[], JUCEApplication* app);
  13616. #endif
  13617. #if ! JUCE_WINDOWS
  13618. extern const char* juce_Argv0;
  13619. #endif
  13620. int JUCEApplication::main (int argc, const char* argv[], JUCEApplication* const newApp)
  13621. {
  13622. #if ! JUCE_WINDOWS
  13623. juce_Argv0 = argv[0];
  13624. #endif
  13625. #if JUCE_IPHONE
  13626. const ScopedAutoReleasePool pool;
  13627. return juce_IPhoneMain (argc, argv, newApp);
  13628. #else
  13629. #if JUCE_MAC
  13630. const ScopedAutoReleasePool pool;
  13631. #endif
  13632. String cmd;
  13633. for (int i = 1; i < argc; ++i)
  13634. cmd << argv[i] << ' ';
  13635. return JUCEApplication::main (cmd, newApp);
  13636. #endif
  13637. }
  13638. void JUCEApplication::actionListenerCallback (const String& message)
  13639. {
  13640. if (message.startsWith (getApplicationName() + "/"))
  13641. anotherInstanceStarted (message.substring (getApplicationName().length() + 1));
  13642. }
  13643. static bool juceInitialisedGUI = false;
  13644. void JUCE_PUBLIC_FUNCTION initialiseJuce_GUI()
  13645. {
  13646. if (! juceInitialisedGUI)
  13647. {
  13648. #if JUCE_MAC || JUCE_IPHONE
  13649. const ScopedAutoReleasePool pool;
  13650. #endif
  13651. juceInitialisedGUI = true;
  13652. initialiseJuce_NonGUI();
  13653. MessageManager::getInstance();
  13654. LookAndFeel::setDefaultLookAndFeel (0);
  13655. juce_setCurrentThreadName ("Juce Message Thread");
  13656. #if JUCE_WINDOWS && JUCE_DEBUG
  13657. // This section is just for catching people who mess up their project settings and
  13658. // turn RTTI off..
  13659. try
  13660. {
  13661. TextButton tb (String::empty);
  13662. Component* c = &tb;
  13663. // Got an exception here? Then TURN ON RTTI in your compiler settings!!
  13664. c = dynamic_cast <Button*> (c);
  13665. }
  13666. catch (...)
  13667. {
  13668. // Ended up here? If so, TURN ON RTTI in your compiler settings!! And if you
  13669. // got as far as this catch statement, then why haven't you got exception catching
  13670. // turned on in the debugger???
  13671. jassertfalse
  13672. }
  13673. #endif
  13674. }
  13675. }
  13676. void JUCE_PUBLIC_FUNCTION shutdownJuce_GUI()
  13677. {
  13678. if (juceInitialisedGUI)
  13679. {
  13680. #if JUCE_MAC
  13681. const ScopedAutoReleasePool pool;
  13682. #endif
  13683. {
  13684. DeletedAtShutdown::deleteAll();
  13685. LookAndFeel::clearDefaultLookAndFeel();
  13686. }
  13687. delete MessageManager::getInstance();
  13688. shutdownJuce_NonGUI();
  13689. juceInitialisedGUI = false;
  13690. }
  13691. }
  13692. END_JUCE_NAMESPACE
  13693. /*** End of inlined file: juce_Application.cpp ***/
  13694. /*** Start of inlined file: juce_ApplicationCommandInfo.cpp ***/
  13695. BEGIN_JUCE_NAMESPACE
  13696. ApplicationCommandInfo::ApplicationCommandInfo (const CommandID commandID_) throw()
  13697. : commandID (commandID_),
  13698. flags (0)
  13699. {
  13700. }
  13701. void ApplicationCommandInfo::setInfo (const String& shortName_,
  13702. const String& description_,
  13703. const String& categoryName_,
  13704. const int flags_) throw()
  13705. {
  13706. shortName = shortName_;
  13707. description = description_;
  13708. categoryName = categoryName_;
  13709. flags = flags_;
  13710. }
  13711. void ApplicationCommandInfo::setActive (const bool b) throw()
  13712. {
  13713. if (b)
  13714. flags &= ~isDisabled;
  13715. else
  13716. flags |= isDisabled;
  13717. }
  13718. void ApplicationCommandInfo::setTicked (const bool b) throw()
  13719. {
  13720. if (b)
  13721. flags |= isTicked;
  13722. else
  13723. flags &= ~isTicked;
  13724. }
  13725. void ApplicationCommandInfo::addDefaultKeypress (const int keyCode, const ModifierKeys& modifiers) throw()
  13726. {
  13727. defaultKeypresses.add (KeyPress (keyCode, modifiers, 0));
  13728. }
  13729. END_JUCE_NAMESPACE
  13730. /*** End of inlined file: juce_ApplicationCommandInfo.cpp ***/
  13731. /*** Start of inlined file: juce_ApplicationCommandManager.cpp ***/
  13732. BEGIN_JUCE_NAMESPACE
  13733. ApplicationCommandManager::ApplicationCommandManager()
  13734. : firstTarget (0)
  13735. {
  13736. keyMappings = new KeyPressMappingSet (this);
  13737. Desktop::getInstance().addFocusChangeListener (this);
  13738. }
  13739. ApplicationCommandManager::~ApplicationCommandManager()
  13740. {
  13741. Desktop::getInstance().removeFocusChangeListener (this);
  13742. keyMappings = 0;
  13743. }
  13744. void ApplicationCommandManager::clearCommands()
  13745. {
  13746. commands.clear();
  13747. keyMappings->clearAllKeyPresses();
  13748. triggerAsyncUpdate();
  13749. }
  13750. void ApplicationCommandManager::registerCommand (const ApplicationCommandInfo& newCommand)
  13751. {
  13752. // zero isn't a valid command ID!
  13753. jassert (newCommand.commandID != 0);
  13754. // the name isn't optional!
  13755. jassert (newCommand.shortName.isNotEmpty());
  13756. if (getCommandForID (newCommand.commandID) == 0)
  13757. {
  13758. ApplicationCommandInfo* const newInfo = new ApplicationCommandInfo (newCommand);
  13759. newInfo->flags &= ~ApplicationCommandInfo::isTicked;
  13760. commands.add (newInfo);
  13761. keyMappings->resetToDefaultMapping (newCommand.commandID);
  13762. triggerAsyncUpdate();
  13763. }
  13764. else
  13765. {
  13766. // trying to re-register the same command with different parameters?
  13767. jassert (newCommand.shortName == getCommandForID (newCommand.commandID)->shortName
  13768. && (newCommand.description == getCommandForID (newCommand.commandID)->description || newCommand.description.isEmpty())
  13769. && newCommand.categoryName == getCommandForID (newCommand.commandID)->categoryName
  13770. && newCommand.defaultKeypresses == getCommandForID (newCommand.commandID)->defaultKeypresses
  13771. && (newCommand.flags & (ApplicationCommandInfo::wantsKeyUpDownCallbacks | ApplicationCommandInfo::hiddenFromKeyEditor | ApplicationCommandInfo::readOnlyInKeyEditor))
  13772. == (getCommandForID (newCommand.commandID)->flags & (ApplicationCommandInfo::wantsKeyUpDownCallbacks | ApplicationCommandInfo::hiddenFromKeyEditor | ApplicationCommandInfo::readOnlyInKeyEditor)));
  13773. }
  13774. }
  13775. void ApplicationCommandManager::registerAllCommandsForTarget (ApplicationCommandTarget* target)
  13776. {
  13777. if (target != 0)
  13778. {
  13779. Array <CommandID> commandIDs;
  13780. target->getAllCommands (commandIDs);
  13781. for (int i = 0; i < commandIDs.size(); ++i)
  13782. {
  13783. ApplicationCommandInfo info (commandIDs.getUnchecked(i));
  13784. target->getCommandInfo (info.commandID, info);
  13785. registerCommand (info);
  13786. }
  13787. }
  13788. }
  13789. void ApplicationCommandManager::removeCommand (const CommandID commandID)
  13790. {
  13791. for (int i = commands.size(); --i >= 0;)
  13792. {
  13793. if (commands.getUnchecked (i)->commandID == commandID)
  13794. {
  13795. commands.remove (i);
  13796. triggerAsyncUpdate();
  13797. const Array <KeyPress> keys (keyMappings->getKeyPressesAssignedToCommand (commandID));
  13798. for (int j = keys.size(); --j >= 0;)
  13799. keyMappings->removeKeyPress (keys.getReference (j));
  13800. }
  13801. }
  13802. }
  13803. void ApplicationCommandManager::commandStatusChanged()
  13804. {
  13805. triggerAsyncUpdate();
  13806. }
  13807. const ApplicationCommandInfo* ApplicationCommandManager::getCommandForID (const CommandID commandID) const throw()
  13808. {
  13809. for (int i = commands.size(); --i >= 0;)
  13810. if (commands.getUnchecked(i)->commandID == commandID)
  13811. return commands.getUnchecked(i);
  13812. return 0;
  13813. }
  13814. const String ApplicationCommandManager::getNameOfCommand (const CommandID commandID) const throw()
  13815. {
  13816. const ApplicationCommandInfo* const ci = getCommandForID (commandID);
  13817. return (ci != 0) ? ci->shortName : String::empty;
  13818. }
  13819. const String ApplicationCommandManager::getDescriptionOfCommand (const CommandID commandID) const throw()
  13820. {
  13821. const ApplicationCommandInfo* const ci = getCommandForID (commandID);
  13822. return (ci != 0) ? (ci->description.isNotEmpty() ? ci->description : ci->shortName)
  13823. : String::empty;
  13824. }
  13825. const StringArray ApplicationCommandManager::getCommandCategories() const throw()
  13826. {
  13827. StringArray s;
  13828. for (int i = 0; i < commands.size(); ++i)
  13829. s.addIfNotAlreadyThere (commands.getUnchecked(i)->categoryName, false);
  13830. return s;
  13831. }
  13832. const Array <CommandID> ApplicationCommandManager::getCommandsInCategory (const String& categoryName) const throw()
  13833. {
  13834. Array <CommandID> results;
  13835. for (int i = 0; i < commands.size(); ++i)
  13836. if (commands.getUnchecked(i)->categoryName == categoryName)
  13837. results.add (commands.getUnchecked(i)->commandID);
  13838. return results;
  13839. }
  13840. bool ApplicationCommandManager::invokeDirectly (const CommandID commandID, const bool asynchronously)
  13841. {
  13842. ApplicationCommandTarget::InvocationInfo info (commandID);
  13843. info.invocationMethod = ApplicationCommandTarget::InvocationInfo::direct;
  13844. return invoke (info, asynchronously);
  13845. }
  13846. bool ApplicationCommandManager::invoke (const ApplicationCommandTarget::InvocationInfo& info_, const bool asynchronously)
  13847. {
  13848. // This call isn't thread-safe for use from a non-UI thread without locking the message
  13849. // manager first..
  13850. jassert (MessageManager::getInstance()->currentThreadHasLockedMessageManager());
  13851. ApplicationCommandTarget* const target = getFirstCommandTarget (info_.commandID);
  13852. if (target == 0)
  13853. return false;
  13854. ApplicationCommandInfo commandInfo (0);
  13855. target->getCommandInfo (info_.commandID, commandInfo);
  13856. ApplicationCommandTarget::InvocationInfo info (info_);
  13857. info.commandFlags = commandInfo.flags;
  13858. sendListenerInvokeCallback (info);
  13859. const bool ok = target->invoke (info, asynchronously);
  13860. commandStatusChanged();
  13861. return ok;
  13862. }
  13863. ApplicationCommandTarget* ApplicationCommandManager::getFirstCommandTarget (const CommandID)
  13864. {
  13865. return firstTarget != 0 ? firstTarget
  13866. : findDefaultComponentTarget();
  13867. }
  13868. void ApplicationCommandManager::setFirstCommandTarget (ApplicationCommandTarget* const newTarget) throw()
  13869. {
  13870. firstTarget = newTarget;
  13871. }
  13872. ApplicationCommandTarget* ApplicationCommandManager::getTargetForCommand (const CommandID commandID,
  13873. ApplicationCommandInfo& upToDateInfo)
  13874. {
  13875. ApplicationCommandTarget* target = getFirstCommandTarget (commandID);
  13876. if (target == 0)
  13877. target = JUCEApplication::getInstance();
  13878. if (target != 0)
  13879. target = target->getTargetForCommand (commandID);
  13880. if (target != 0)
  13881. target->getCommandInfo (commandID, upToDateInfo);
  13882. return target;
  13883. }
  13884. ApplicationCommandTarget* ApplicationCommandManager::findTargetForComponent (Component* c)
  13885. {
  13886. ApplicationCommandTarget* target = dynamic_cast <ApplicationCommandTarget*> (c);
  13887. if (target == 0 && c != 0)
  13888. // (unable to use the syntax findParentComponentOfClass <ApplicationCommandTarget> () because of a VC6 compiler bug)
  13889. target = c->findParentComponentOfClass ((ApplicationCommandTarget*) 0);
  13890. return target;
  13891. }
  13892. ApplicationCommandTarget* ApplicationCommandManager::findDefaultComponentTarget()
  13893. {
  13894. Component* c = Component::getCurrentlyFocusedComponent();
  13895. if (c == 0)
  13896. {
  13897. TopLevelWindow* const activeWindow = TopLevelWindow::getActiveTopLevelWindow();
  13898. if (activeWindow != 0)
  13899. {
  13900. c = activeWindow->getPeer()->getLastFocusedSubcomponent();
  13901. if (c == 0)
  13902. c = activeWindow;
  13903. }
  13904. }
  13905. if (c == 0 && Process::isForegroundProcess())
  13906. {
  13907. // getting a bit desperate now - try all desktop comps..
  13908. for (int i = Desktop::getInstance().getNumComponents(); --i >= 0;)
  13909. {
  13910. ApplicationCommandTarget* const target
  13911. = findTargetForComponent (Desktop::getInstance().getComponent (i)
  13912. ->getPeer()->getLastFocusedSubcomponent());
  13913. if (target != 0)
  13914. return target;
  13915. }
  13916. }
  13917. if (c != 0)
  13918. {
  13919. ResizableWindow* const resizableWindow = dynamic_cast <ResizableWindow*> (c);
  13920. // if we're focused on a ResizableWindow, chances are that it's the content
  13921. // component that really should get the event. And if not, the event will
  13922. // still be passed up to the top level window anyway, so let's send it to the
  13923. // content comp.
  13924. if (resizableWindow != 0 && resizableWindow->getContentComponent() != 0)
  13925. c = resizableWindow->getContentComponent();
  13926. ApplicationCommandTarget* const target = findTargetForComponent (c);
  13927. if (target != 0)
  13928. return target;
  13929. }
  13930. return JUCEApplication::getInstance();
  13931. }
  13932. void ApplicationCommandManager::addListener (ApplicationCommandManagerListener* const listener) throw()
  13933. {
  13934. listeners.add (listener);
  13935. }
  13936. void ApplicationCommandManager::removeListener (ApplicationCommandManagerListener* const listener) throw()
  13937. {
  13938. listeners.remove (listener);
  13939. }
  13940. void ApplicationCommandManager::sendListenerInvokeCallback (const ApplicationCommandTarget::InvocationInfo& info)
  13941. {
  13942. listeners.call (&ApplicationCommandManagerListener::applicationCommandInvoked, info);
  13943. }
  13944. void ApplicationCommandManager::handleAsyncUpdate()
  13945. {
  13946. listeners.call (&ApplicationCommandManagerListener::applicationCommandListChanged);
  13947. }
  13948. void ApplicationCommandManager::globalFocusChanged (Component*)
  13949. {
  13950. commandStatusChanged();
  13951. }
  13952. END_JUCE_NAMESPACE
  13953. /*** End of inlined file: juce_ApplicationCommandManager.cpp ***/
  13954. /*** Start of inlined file: juce_ApplicationCommandTarget.cpp ***/
  13955. BEGIN_JUCE_NAMESPACE
  13956. ApplicationCommandTarget::ApplicationCommandTarget()
  13957. {
  13958. }
  13959. ApplicationCommandTarget::~ApplicationCommandTarget()
  13960. {
  13961. messageInvoker = 0;
  13962. }
  13963. bool ApplicationCommandTarget::tryToInvoke (const InvocationInfo& info, const bool async)
  13964. {
  13965. if (isCommandActive (info.commandID))
  13966. {
  13967. if (async)
  13968. {
  13969. if (messageInvoker == 0)
  13970. messageInvoker = new CommandTargetMessageInvoker (this);
  13971. messageInvoker->postMessage (new Message (0, 0, 0, new ApplicationCommandTarget::InvocationInfo (info)));
  13972. return true;
  13973. }
  13974. else
  13975. {
  13976. const bool success = perform (info);
  13977. jassert (success); // hmm - your target should have been able to perform this command. If it can't
  13978. // do it at the moment for some reason, it should clear the 'isActive' flag when it
  13979. // returns the command's info.
  13980. return success;
  13981. }
  13982. }
  13983. return false;
  13984. }
  13985. ApplicationCommandTarget* ApplicationCommandTarget::findFirstTargetParentComponent()
  13986. {
  13987. Component* c = dynamic_cast <Component*> (this);
  13988. if (c != 0)
  13989. // (unable to use the syntax findParentComponentOfClass <ApplicationCommandTarget> () because of a VC6 compiler bug)
  13990. return c->findParentComponentOfClass ((ApplicationCommandTarget*) 0);
  13991. return 0;
  13992. }
  13993. ApplicationCommandTarget* ApplicationCommandTarget::getTargetForCommand (const CommandID commandID)
  13994. {
  13995. ApplicationCommandTarget* target = this;
  13996. int depth = 0;
  13997. while (target != 0)
  13998. {
  13999. Array <CommandID> commandIDs;
  14000. target->getAllCommands (commandIDs);
  14001. if (commandIDs.contains (commandID))
  14002. return target;
  14003. target = target->getNextCommandTarget();
  14004. ++depth;
  14005. jassert (depth < 100); // could be a recursive command chain??
  14006. jassert (target != this); // definitely a recursive command chain!
  14007. if (depth > 100 || target == this)
  14008. break;
  14009. }
  14010. if (target == 0)
  14011. {
  14012. target = JUCEApplication::getInstance();
  14013. if (target != 0)
  14014. {
  14015. Array <CommandID> commandIDs;
  14016. target->getAllCommands (commandIDs);
  14017. if (commandIDs.contains (commandID))
  14018. return target;
  14019. }
  14020. }
  14021. return 0;
  14022. }
  14023. bool ApplicationCommandTarget::isCommandActive (const CommandID commandID)
  14024. {
  14025. ApplicationCommandInfo info (commandID);
  14026. info.flags = ApplicationCommandInfo::isDisabled;
  14027. getCommandInfo (commandID, info);
  14028. return (info.flags & ApplicationCommandInfo::isDisabled) == 0;
  14029. }
  14030. bool ApplicationCommandTarget::invoke (const InvocationInfo& info, const bool async)
  14031. {
  14032. ApplicationCommandTarget* target = this;
  14033. int depth = 0;
  14034. while (target != 0)
  14035. {
  14036. if (target->tryToInvoke (info, async))
  14037. return true;
  14038. target = target->getNextCommandTarget();
  14039. ++depth;
  14040. jassert (depth < 100); // could be a recursive command chain??
  14041. jassert (target != this); // definitely a recursive command chain!
  14042. if (depth > 100 || target == this)
  14043. break;
  14044. }
  14045. if (target == 0)
  14046. {
  14047. target = JUCEApplication::getInstance();
  14048. if (target != 0)
  14049. return target->tryToInvoke (info, async);
  14050. }
  14051. return false;
  14052. }
  14053. bool ApplicationCommandTarget::invokeDirectly (const CommandID commandID, const bool asynchronously)
  14054. {
  14055. ApplicationCommandTarget::InvocationInfo info (commandID);
  14056. info.invocationMethod = ApplicationCommandTarget::InvocationInfo::direct;
  14057. return invoke (info, asynchronously);
  14058. }
  14059. ApplicationCommandTarget::InvocationInfo::InvocationInfo (const CommandID commandID_) throw()
  14060. : commandID (commandID_),
  14061. commandFlags (0),
  14062. invocationMethod (direct),
  14063. originatingComponent (0),
  14064. isKeyDown (false),
  14065. millisecsSinceKeyPressed (0)
  14066. {
  14067. }
  14068. ApplicationCommandTarget::CommandTargetMessageInvoker::CommandTargetMessageInvoker (ApplicationCommandTarget* const owner_)
  14069. : owner (owner_)
  14070. {
  14071. }
  14072. ApplicationCommandTarget::CommandTargetMessageInvoker::~CommandTargetMessageInvoker()
  14073. {
  14074. }
  14075. void ApplicationCommandTarget::CommandTargetMessageInvoker::handleMessage (const Message& message)
  14076. {
  14077. const ScopedPointer <InvocationInfo> info ((InvocationInfo*) message.pointerParameter);
  14078. owner->tryToInvoke (*info, false);
  14079. }
  14080. END_JUCE_NAMESPACE
  14081. /*** End of inlined file: juce_ApplicationCommandTarget.cpp ***/
  14082. /*** Start of inlined file: juce_ApplicationProperties.cpp ***/
  14083. BEGIN_JUCE_NAMESPACE
  14084. juce_ImplementSingleton (ApplicationProperties)
  14085. ApplicationProperties::ApplicationProperties() throw()
  14086. : msBeforeSaving (3000),
  14087. options (PropertiesFile::storeAsBinary),
  14088. commonSettingsAreReadOnly (0)
  14089. {
  14090. }
  14091. ApplicationProperties::~ApplicationProperties()
  14092. {
  14093. closeFiles();
  14094. clearSingletonInstance();
  14095. }
  14096. void ApplicationProperties::setStorageParameters (const String& applicationName,
  14097. const String& fileNameSuffix,
  14098. const String& folderName_,
  14099. const int millisecondsBeforeSaving,
  14100. const int propertiesFileOptions) throw()
  14101. {
  14102. appName = applicationName;
  14103. fileSuffix = fileNameSuffix;
  14104. folderName = folderName_;
  14105. msBeforeSaving = millisecondsBeforeSaving;
  14106. options = propertiesFileOptions;
  14107. }
  14108. bool ApplicationProperties::testWriteAccess (const bool testUserSettings,
  14109. const bool testCommonSettings,
  14110. const bool showWarningDialogOnFailure)
  14111. {
  14112. const bool userOk = (! testUserSettings) || getUserSettings()->save();
  14113. const bool commonOk = (! testCommonSettings) || getCommonSettings (false)->save();
  14114. if (! (userOk && commonOk))
  14115. {
  14116. if (showWarningDialogOnFailure)
  14117. {
  14118. String filenames;
  14119. if (userProps != 0 && ! userOk)
  14120. filenames << '\n' << userProps->getFile().getFullPathName();
  14121. if (commonProps != 0 && ! commonOk)
  14122. filenames << '\n' << commonProps->getFile().getFullPathName();
  14123. AlertWindow::showMessageBox (AlertWindow::WarningIcon,
  14124. appName + TRANS(" - Unable to save settings"),
  14125. TRANS("An error occurred when trying to save the application's settings file...\n\nIn order to save and restore its settings, ")
  14126. + appName + TRANS(" needs to be able to write to the following files:\n")
  14127. + filenames
  14128. + TRANS("\n\nMake sure that these files aren't read-only, and that the disk isn't full."));
  14129. }
  14130. return false;
  14131. }
  14132. return true;
  14133. }
  14134. void ApplicationProperties::openFiles() throw()
  14135. {
  14136. // You need to call setStorageParameters() before trying to get hold of the
  14137. // properties!
  14138. jassert (appName.isNotEmpty());
  14139. if (appName.isNotEmpty())
  14140. {
  14141. if (userProps == 0)
  14142. userProps = PropertiesFile::createDefaultAppPropertiesFile (appName, fileSuffix, folderName,
  14143. false, msBeforeSaving, options);
  14144. if (commonProps == 0)
  14145. commonProps = PropertiesFile::createDefaultAppPropertiesFile (appName, fileSuffix, folderName,
  14146. true, msBeforeSaving, options);
  14147. userProps->setFallbackPropertySet (commonProps);
  14148. }
  14149. }
  14150. PropertiesFile* ApplicationProperties::getUserSettings() throw()
  14151. {
  14152. if (userProps == 0)
  14153. openFiles();
  14154. return userProps;
  14155. }
  14156. PropertiesFile* ApplicationProperties::getCommonSettings (const bool returnUserPropsIfReadOnly) throw()
  14157. {
  14158. if (commonProps == 0)
  14159. openFiles();
  14160. if (returnUserPropsIfReadOnly)
  14161. {
  14162. if (commonSettingsAreReadOnly == 0)
  14163. commonSettingsAreReadOnly = commonProps->save() ? -1 : 1;
  14164. if (commonSettingsAreReadOnly > 0)
  14165. return userProps;
  14166. }
  14167. return commonProps;
  14168. }
  14169. bool ApplicationProperties::saveIfNeeded()
  14170. {
  14171. return (userProps == 0 || userProps->saveIfNeeded())
  14172. && (commonProps == 0 || commonProps->saveIfNeeded());
  14173. }
  14174. void ApplicationProperties::closeFiles()
  14175. {
  14176. userProps = 0;
  14177. commonProps = 0;
  14178. }
  14179. END_JUCE_NAMESPACE
  14180. /*** End of inlined file: juce_ApplicationProperties.cpp ***/
  14181. /*** Start of inlined file: juce_DeletedAtShutdown.cpp ***/
  14182. BEGIN_JUCE_NAMESPACE
  14183. static VoidArray objectsToDelete;
  14184. static CriticalSection lock;
  14185. DeletedAtShutdown::DeletedAtShutdown()
  14186. {
  14187. const ScopedLock sl (lock);
  14188. objectsToDelete.add (this);
  14189. }
  14190. DeletedAtShutdown::~DeletedAtShutdown()
  14191. {
  14192. const ScopedLock sl (lock);
  14193. objectsToDelete.removeValue (this);
  14194. }
  14195. void DeletedAtShutdown::deleteAll()
  14196. {
  14197. // make a local copy of the array, so it can't get into a loop if something
  14198. // creates another DeletedAtShutdown object during its destructor.
  14199. VoidArray localCopy;
  14200. {
  14201. const ScopedLock sl (lock);
  14202. localCopy = objectsToDelete;
  14203. }
  14204. for (int i = localCopy.size(); --i >= 0;)
  14205. {
  14206. JUCE_TRY
  14207. {
  14208. DeletedAtShutdown* deletee = (DeletedAtShutdown*) localCopy.getUnchecked(i);
  14209. // double-check that it's not already been deleted during another object's destructor.
  14210. {
  14211. const ScopedLock sl (lock);
  14212. if (! objectsToDelete.contains (deletee))
  14213. deletee = 0;
  14214. }
  14215. delete deletee;
  14216. }
  14217. JUCE_CATCH_EXCEPTION
  14218. }
  14219. // if no objects got re-created during shutdown, this should have been emptied by their
  14220. // destructors
  14221. jassert (objectsToDelete.size() == 0);
  14222. objectsToDelete.clear(); // just to make sure the array doesn't have any memory still allocated
  14223. }
  14224. END_JUCE_NAMESPACE
  14225. /*** End of inlined file: juce_DeletedAtShutdown.cpp ***/
  14226. /*** Start of inlined file: juce_PropertiesFile.cpp ***/
  14227. BEGIN_JUCE_NAMESPACE
  14228. namespace PropertyFileConstants
  14229. {
  14230. static const int magicNumber = (int) ByteOrder::littleEndianInt ("PROP");
  14231. static const int magicNumberCompressed = (int) ByteOrder::littleEndianInt ("CPRP");
  14232. static const char* const fileTag = "PROPERTIES";
  14233. static const char* const valueTag = "VALUE";
  14234. static const char* const nameAttribute = "name";
  14235. static const char* const valueAttribute = "val";
  14236. }
  14237. PropertiesFile::PropertiesFile (const File& f, const int millisecondsBeforeSaving, const int options_)
  14238. : PropertySet (ignoreCaseOfKeyNames),
  14239. file (f),
  14240. timerInterval (millisecondsBeforeSaving),
  14241. options (options_),
  14242. loadedOk (false),
  14243. needsWriting (false)
  14244. {
  14245. // You need to correctly specify just one storage format for the file
  14246. jassert ((options_ & (storeAsBinary | storeAsCompressedBinary | storeAsXML)) == storeAsBinary
  14247. || (options_ & (storeAsBinary | storeAsCompressedBinary | storeAsXML)) == storeAsCompressedBinary
  14248. || (options_ & (storeAsBinary | storeAsCompressedBinary | storeAsXML)) == storeAsXML);
  14249. ScopedPointer<InputStream> fileStream (f.createInputStream());
  14250. if (fileStream != 0)
  14251. {
  14252. int magicNumber = fileStream->readInt();
  14253. if (magicNumber == PropertyFileConstants::magicNumberCompressed)
  14254. {
  14255. fileStream = new GZIPDecompressorInputStream (new SubregionStream (fileStream.release(), 4, -1, true), true);
  14256. magicNumber = PropertyFileConstants::magicNumber;
  14257. }
  14258. if (magicNumber == PropertyFileConstants::magicNumber)
  14259. {
  14260. loadedOk = true;
  14261. BufferedInputStream in (fileStream.release(), 2048, true);
  14262. int numValues = in.readInt();
  14263. while (--numValues >= 0 && ! in.isExhausted())
  14264. {
  14265. const String key (in.readString());
  14266. const String value (in.readString());
  14267. jassert (key.isNotEmpty());
  14268. if (key.isNotEmpty())
  14269. getAllProperties().set (key, value);
  14270. }
  14271. }
  14272. else
  14273. {
  14274. // Not a binary props file - let's see if it's XML..
  14275. fileStream = 0;
  14276. XmlDocument parser (f);
  14277. ScopedPointer<XmlElement> doc (parser.getDocumentElement (true));
  14278. if (doc != 0 && doc->hasTagName (PropertyFileConstants::fileTag))
  14279. {
  14280. doc = parser.getDocumentElement();
  14281. if (doc != 0)
  14282. {
  14283. loadedOk = true;
  14284. forEachXmlChildElementWithTagName (*doc, e, PropertyFileConstants::valueTag)
  14285. {
  14286. const String name (e->getStringAttribute (PropertyFileConstants::nameAttribute));
  14287. if (name.isNotEmpty())
  14288. {
  14289. getAllProperties().set (name,
  14290. e->getFirstChildElement() != 0
  14291. ? e->getFirstChildElement()->createDocument (String::empty, true)
  14292. : e->getStringAttribute (PropertyFileConstants::valueAttribute));
  14293. }
  14294. }
  14295. }
  14296. else
  14297. {
  14298. // must be a pretty broken XML file we're trying to parse here!
  14299. jassertfalse
  14300. }
  14301. }
  14302. }
  14303. }
  14304. else
  14305. {
  14306. loadedOk = ! f.exists();
  14307. }
  14308. }
  14309. PropertiesFile::~PropertiesFile()
  14310. {
  14311. if (! saveIfNeeded())
  14312. jassertfalse;
  14313. }
  14314. bool PropertiesFile::saveIfNeeded()
  14315. {
  14316. const ScopedLock sl (getLock());
  14317. return (! needsWriting) || save();
  14318. }
  14319. bool PropertiesFile::needsToBeSaved() const
  14320. {
  14321. const ScopedLock sl (getLock());
  14322. return needsWriting;
  14323. }
  14324. void PropertiesFile::setNeedsToBeSaved (const bool needsToBeSaved)
  14325. {
  14326. const ScopedLock sl (getLock());
  14327. needsWriting = needsToBeSaved;
  14328. }
  14329. bool PropertiesFile::save()
  14330. {
  14331. const ScopedLock sl (getLock());
  14332. stopTimer();
  14333. if (file == File::nonexistent
  14334. || file.isDirectory()
  14335. || ! file.getParentDirectory().createDirectory())
  14336. return false;
  14337. if ((options & storeAsXML) != 0)
  14338. {
  14339. XmlElement doc (PropertyFileConstants::fileTag);
  14340. for (int i = 0; i < getAllProperties().size(); ++i)
  14341. {
  14342. XmlElement* const e = doc.createNewChildElement (PropertyFileConstants::valueTag);
  14343. e->setAttribute (PropertyFileConstants::nameAttribute, getAllProperties().getAllKeys() [i]);
  14344. // if the value seems to contain xml, store it as such..
  14345. XmlDocument xmlContent (getAllProperties().getAllValues() [i]);
  14346. XmlElement* const childElement = xmlContent.getDocumentElement();
  14347. if (childElement != 0)
  14348. e->addChildElement (childElement);
  14349. else
  14350. e->setAttribute (PropertyFileConstants::valueAttribute,
  14351. getAllProperties().getAllValues() [i]);
  14352. }
  14353. if (doc.writeToFile (file, String::empty))
  14354. {
  14355. needsWriting = false;
  14356. return true;
  14357. }
  14358. }
  14359. else
  14360. {
  14361. TemporaryFile tempFile (file);
  14362. ScopedPointer <OutputStream> out (tempFile.getFile().createOutputStream());
  14363. if (out != 0)
  14364. {
  14365. if ((options & storeAsCompressedBinary) != 0)
  14366. {
  14367. out->writeInt (PropertyFileConstants::magicNumberCompressed);
  14368. out->flush();
  14369. out = new GZIPCompressorOutputStream (out.release(), 9, true);
  14370. }
  14371. else
  14372. {
  14373. // have you set up the storage option flags correctly?
  14374. jassert ((options & storeAsBinary) != 0);
  14375. out->writeInt (PropertyFileConstants::magicNumber);
  14376. }
  14377. const int numProperties = getAllProperties().size();
  14378. out->writeInt (numProperties);
  14379. for (int i = 0; i < numProperties; ++i)
  14380. {
  14381. out->writeString (getAllProperties().getAllKeys() [i]);
  14382. out->writeString (getAllProperties().getAllValues() [i]);
  14383. }
  14384. out = 0;
  14385. if (tempFile.overwriteTargetFileWithTemporary())
  14386. {
  14387. needsWriting = false;
  14388. return true;
  14389. }
  14390. }
  14391. }
  14392. return false;
  14393. }
  14394. void PropertiesFile::timerCallback()
  14395. {
  14396. saveIfNeeded();
  14397. }
  14398. void PropertiesFile::propertyChanged()
  14399. {
  14400. sendChangeMessage (this);
  14401. needsWriting = true;
  14402. if (timerInterval > 0)
  14403. startTimer (timerInterval);
  14404. else if (timerInterval == 0)
  14405. saveIfNeeded();
  14406. }
  14407. const File PropertiesFile::getDefaultAppSettingsFile (const String& applicationName,
  14408. const String& fileNameSuffix,
  14409. const String& folderName,
  14410. const bool commonToAllUsers)
  14411. {
  14412. // mustn't have illegal characters in this name..
  14413. jassert (applicationName == File::createLegalFileName (applicationName));
  14414. #if JUCE_MAC || JUCE_IPHONE
  14415. File dir (commonToAllUsers ? "/Library/Preferences"
  14416. : "~/Library/Preferences");
  14417. if (folderName.isNotEmpty())
  14418. dir = dir.getChildFile (folderName);
  14419. #endif
  14420. #ifdef JUCE_LINUX
  14421. const File dir ((commonToAllUsers ? "/var/" : "~/")
  14422. + (folderName.isNotEmpty() ? folderName
  14423. : ("." + applicationName)));
  14424. #endif
  14425. #if JUCE_WIN32
  14426. File dir (File::getSpecialLocation (commonToAllUsers ? File::commonApplicationDataDirectory
  14427. : File::userApplicationDataDirectory));
  14428. if (dir == File::nonexistent)
  14429. return File::nonexistent;
  14430. dir = dir.getChildFile (folderName.isNotEmpty() ? folderName
  14431. : applicationName);
  14432. #endif
  14433. return dir.getChildFile (applicationName)
  14434. .withFileExtension (fileNameSuffix);
  14435. }
  14436. PropertiesFile* PropertiesFile::createDefaultAppPropertiesFile (const String& applicationName,
  14437. const String& fileNameSuffix,
  14438. const String& folderName,
  14439. const bool commonToAllUsers,
  14440. const int millisecondsBeforeSaving,
  14441. const int propertiesFileOptions)
  14442. {
  14443. const File file (getDefaultAppSettingsFile (applicationName,
  14444. fileNameSuffix,
  14445. folderName,
  14446. commonToAllUsers));
  14447. jassert (file != File::nonexistent);
  14448. if (file == File::nonexistent)
  14449. return 0;
  14450. return new PropertiesFile (file, millisecondsBeforeSaving, propertiesFileOptions);
  14451. }
  14452. END_JUCE_NAMESPACE
  14453. /*** End of inlined file: juce_PropertiesFile.cpp ***/
  14454. /*** Start of inlined file: juce_FileBasedDocument.cpp ***/
  14455. BEGIN_JUCE_NAMESPACE
  14456. FileBasedDocument::FileBasedDocument (const String& fileExtension_,
  14457. const String& fileWildcard_,
  14458. const String& openFileDialogTitle_,
  14459. const String& saveFileDialogTitle_)
  14460. : changedSinceSave (false),
  14461. fileExtension (fileExtension_),
  14462. fileWildcard (fileWildcard_),
  14463. openFileDialogTitle (openFileDialogTitle_),
  14464. saveFileDialogTitle (saveFileDialogTitle_)
  14465. {
  14466. }
  14467. FileBasedDocument::~FileBasedDocument()
  14468. {
  14469. }
  14470. void FileBasedDocument::setChangedFlag (const bool hasChanged)
  14471. {
  14472. changedSinceSave = hasChanged;
  14473. }
  14474. void FileBasedDocument::changed()
  14475. {
  14476. changedSinceSave = true;
  14477. sendChangeMessage (this);
  14478. }
  14479. void FileBasedDocument::setFile (const File& newFile)
  14480. {
  14481. if (documentFile != newFile)
  14482. {
  14483. documentFile = newFile;
  14484. changedSinceSave = true;
  14485. }
  14486. }
  14487. bool FileBasedDocument::loadFrom (const File& newFile,
  14488. const bool showMessageOnFailure)
  14489. {
  14490. MouseCursor::showWaitCursor();
  14491. const File oldFile (documentFile);
  14492. documentFile = newFile;
  14493. String error;
  14494. if (newFile.existsAsFile())
  14495. {
  14496. error = loadDocument (newFile);
  14497. if (error.isEmpty())
  14498. {
  14499. setChangedFlag (false);
  14500. MouseCursor::hideWaitCursor();
  14501. setLastDocumentOpened (newFile);
  14502. return true;
  14503. }
  14504. }
  14505. else
  14506. {
  14507. error = "The file doesn't exist";
  14508. }
  14509. documentFile = oldFile;
  14510. MouseCursor::hideWaitCursor();
  14511. if (showMessageOnFailure)
  14512. {
  14513. AlertWindow::showMessageBox (AlertWindow::WarningIcon,
  14514. TRANS("Failed to open file..."),
  14515. TRANS("There was an error while trying to load the file:\n\n")
  14516. + newFile.getFullPathName()
  14517. + T("\n\n")
  14518. + error);
  14519. }
  14520. return false;
  14521. }
  14522. bool FileBasedDocument::loadFromUserSpecifiedFile (const bool showMessageOnFailure)
  14523. {
  14524. FileChooser fc (openFileDialogTitle,
  14525. getLastDocumentOpened(),
  14526. fileWildcard);
  14527. if (fc.browseForFileToOpen())
  14528. return loadFrom (fc.getResult(), showMessageOnFailure);
  14529. return false;
  14530. }
  14531. FileBasedDocument::SaveResult FileBasedDocument::save (const bool askUserForFileIfNotSpecified,
  14532. const bool showMessageOnFailure)
  14533. {
  14534. return saveAs (documentFile,
  14535. false,
  14536. askUserForFileIfNotSpecified,
  14537. showMessageOnFailure);
  14538. }
  14539. FileBasedDocument::SaveResult FileBasedDocument::saveAs (const File& newFile,
  14540. const bool warnAboutOverwritingExistingFiles,
  14541. const bool askUserForFileIfNotSpecified,
  14542. const bool showMessageOnFailure)
  14543. {
  14544. if (newFile == File::nonexistent)
  14545. {
  14546. if (askUserForFileIfNotSpecified)
  14547. {
  14548. return saveAsInteractive (true);
  14549. }
  14550. else
  14551. {
  14552. // can't save to an unspecified file
  14553. jassertfalse
  14554. return failedToWriteToFile;
  14555. }
  14556. }
  14557. if (warnAboutOverwritingExistingFiles && newFile.exists())
  14558. {
  14559. if (! AlertWindow::showOkCancelBox (AlertWindow::WarningIcon,
  14560. TRANS("File already exists"),
  14561. TRANS("There's already a file called:\n\n")
  14562. + newFile.getFullPathName()
  14563. + TRANS("\n\nAre you sure you want to overwrite it?"),
  14564. TRANS("overwrite"),
  14565. TRANS("cancel")))
  14566. {
  14567. return userCancelledSave;
  14568. }
  14569. }
  14570. MouseCursor::showWaitCursor();
  14571. const File oldFile (documentFile);
  14572. documentFile = newFile;
  14573. String error (saveDocument (newFile));
  14574. if (error.isEmpty())
  14575. {
  14576. setChangedFlag (false);
  14577. MouseCursor::hideWaitCursor();
  14578. return savedOk;
  14579. }
  14580. documentFile = oldFile;
  14581. MouseCursor::hideWaitCursor();
  14582. if (showMessageOnFailure)
  14583. {
  14584. AlertWindow::showMessageBox (AlertWindow::WarningIcon,
  14585. TRANS("Error writing to file..."),
  14586. TRANS("An error occurred while trying to save \"")
  14587. + getDocumentTitle()
  14588. + TRANS("\" to the file:\n\n")
  14589. + newFile.getFullPathName()
  14590. + T("\n\n")
  14591. + error);
  14592. }
  14593. return failedToWriteToFile;
  14594. }
  14595. FileBasedDocument::SaveResult FileBasedDocument::saveIfNeededAndUserAgrees()
  14596. {
  14597. if (! hasChangedSinceSaved())
  14598. return savedOk;
  14599. const int r = AlertWindow::showYesNoCancelBox (AlertWindow::QuestionIcon,
  14600. TRANS("Closing document..."),
  14601. TRANS("Do you want to save the changes to \"")
  14602. + getDocumentTitle() + T("\"?"),
  14603. TRANS("save"),
  14604. TRANS("discard changes"),
  14605. TRANS("cancel"));
  14606. if (r == 1)
  14607. {
  14608. // save changes
  14609. return save (true, true);
  14610. }
  14611. else if (r == 2)
  14612. {
  14613. // discard changes
  14614. return savedOk;
  14615. }
  14616. return userCancelledSave;
  14617. }
  14618. FileBasedDocument::SaveResult FileBasedDocument::saveAsInteractive (const bool warnAboutOverwritingExistingFiles)
  14619. {
  14620. File f;
  14621. if (documentFile.existsAsFile())
  14622. f = documentFile;
  14623. else
  14624. f = getLastDocumentOpened();
  14625. String legalFilename (File::createLegalFileName (getDocumentTitle()));
  14626. if (legalFilename.isEmpty())
  14627. legalFilename = "unnamed";
  14628. if (f.existsAsFile() || f.getParentDirectory().isDirectory())
  14629. f = f.getSiblingFile (legalFilename);
  14630. else
  14631. f = File::getSpecialLocation (File::userDocumentsDirectory).getChildFile (legalFilename);
  14632. f = f.withFileExtension (fileExtension)
  14633. .getNonexistentSibling (true);
  14634. FileChooser fc (saveFileDialogTitle, f, fileWildcard);
  14635. if (fc.browseForFileToSave (warnAboutOverwritingExistingFiles))
  14636. {
  14637. setLastDocumentOpened (fc.getResult());
  14638. File chosen (fc.getResult());
  14639. if (chosen.getFileExtension().isEmpty())
  14640. {
  14641. chosen = chosen.withFileExtension (fileExtension);
  14642. if (chosen.exists())
  14643. {
  14644. if (! AlertWindow::showOkCancelBox (AlertWindow::WarningIcon,
  14645. TRANS("File already exists"),
  14646. TRANS("There's already a file called:\n\n")
  14647. + chosen.getFullPathName()
  14648. + T("\n\nAre you sure you want to overwrite it?"),
  14649. TRANS("overwrite"),
  14650. TRANS("cancel")))
  14651. {
  14652. return userCancelledSave;
  14653. }
  14654. }
  14655. }
  14656. return saveAs (chosen, false, false, true);
  14657. }
  14658. return userCancelledSave;
  14659. }
  14660. END_JUCE_NAMESPACE
  14661. /*** End of inlined file: juce_FileBasedDocument.cpp ***/
  14662. /*** Start of inlined file: juce_RecentlyOpenedFilesList.cpp ***/
  14663. BEGIN_JUCE_NAMESPACE
  14664. RecentlyOpenedFilesList::RecentlyOpenedFilesList()
  14665. : maxNumberOfItems (10)
  14666. {
  14667. }
  14668. RecentlyOpenedFilesList::~RecentlyOpenedFilesList()
  14669. {
  14670. }
  14671. void RecentlyOpenedFilesList::setMaxNumberOfItems (const int newMaxNumber)
  14672. {
  14673. maxNumberOfItems = jmax (1, newMaxNumber);
  14674. while (getNumFiles() > maxNumberOfItems)
  14675. files.remove (getNumFiles() - 1);
  14676. }
  14677. int RecentlyOpenedFilesList::getNumFiles() const
  14678. {
  14679. return files.size();
  14680. }
  14681. const File RecentlyOpenedFilesList::getFile (const int index) const
  14682. {
  14683. return File (files [index]);
  14684. }
  14685. void RecentlyOpenedFilesList::clear()
  14686. {
  14687. files.clear();
  14688. }
  14689. void RecentlyOpenedFilesList::addFile (const File& file)
  14690. {
  14691. const String path (file.getFullPathName());
  14692. files.removeString (path, true);
  14693. files.insert (0, path);
  14694. setMaxNumberOfItems (maxNumberOfItems);
  14695. }
  14696. void RecentlyOpenedFilesList::removeNonExistentFiles()
  14697. {
  14698. for (int i = getNumFiles(); --i >= 0;)
  14699. if (! getFile(i).exists())
  14700. files.remove (i);
  14701. }
  14702. int RecentlyOpenedFilesList::createPopupMenuItems (PopupMenu& menuToAddTo,
  14703. const int baseItemId,
  14704. const bool showFullPaths,
  14705. const bool dontAddNonExistentFiles,
  14706. const File** filesToAvoid)
  14707. {
  14708. int num = 0;
  14709. for (int i = 0; i < getNumFiles(); ++i)
  14710. {
  14711. const File f (getFile(i));
  14712. if ((! dontAddNonExistentFiles) || f.exists())
  14713. {
  14714. bool needsAvoiding = false;
  14715. if (filesToAvoid != 0)
  14716. {
  14717. const File** avoid = filesToAvoid;
  14718. while (*avoid != 0)
  14719. {
  14720. if (f == **avoid)
  14721. {
  14722. needsAvoiding = true;
  14723. break;
  14724. }
  14725. ++avoid;
  14726. }
  14727. }
  14728. if (! needsAvoiding)
  14729. {
  14730. menuToAddTo.addItem (baseItemId + i,
  14731. showFullPaths ? f.getFullPathName()
  14732. : f.getFileName());
  14733. ++num;
  14734. }
  14735. }
  14736. }
  14737. return num;
  14738. }
  14739. const String RecentlyOpenedFilesList::toString() const
  14740. {
  14741. return files.joinIntoString (T("\n"));
  14742. }
  14743. void RecentlyOpenedFilesList::restoreFromString (const String& stringifiedVersion)
  14744. {
  14745. clear();
  14746. files.addLines (stringifiedVersion);
  14747. setMaxNumberOfItems (maxNumberOfItems);
  14748. }
  14749. END_JUCE_NAMESPACE
  14750. /*** End of inlined file: juce_RecentlyOpenedFilesList.cpp ***/
  14751. /*** Start of inlined file: juce_UndoManager.cpp ***/
  14752. BEGIN_JUCE_NAMESPACE
  14753. UndoManager::UndoManager (const int maxNumberOfUnitsToKeep,
  14754. const int minimumTransactions)
  14755. : totalUnitsStored (0),
  14756. nextIndex (0),
  14757. newTransaction (true),
  14758. reentrancyCheck (false)
  14759. {
  14760. setMaxNumberOfStoredUnits (maxNumberOfUnitsToKeep,
  14761. minimumTransactions);
  14762. }
  14763. UndoManager::~UndoManager()
  14764. {
  14765. clearUndoHistory();
  14766. }
  14767. void UndoManager::clearUndoHistory()
  14768. {
  14769. transactions.clear();
  14770. transactionNames.clear();
  14771. totalUnitsStored = 0;
  14772. nextIndex = 0;
  14773. sendChangeMessage (this);
  14774. }
  14775. int UndoManager::getNumberOfUnitsTakenUpByStoredCommands() const
  14776. {
  14777. return totalUnitsStored;
  14778. }
  14779. void UndoManager::setMaxNumberOfStoredUnits (const int maxNumberOfUnitsToKeep,
  14780. const int minimumTransactions)
  14781. {
  14782. maxNumUnitsToKeep = jmax (1, maxNumberOfUnitsToKeep);
  14783. minimumTransactionsToKeep = jmax (1, minimumTransactions);
  14784. }
  14785. bool UndoManager::perform (UndoableAction* const command, const String& actionName)
  14786. {
  14787. if (command != 0)
  14788. {
  14789. if (actionName.isNotEmpty())
  14790. currentTransactionName = actionName;
  14791. if (reentrancyCheck)
  14792. {
  14793. jassertfalse // don't call perform() recursively from the UndoableAction::perform() or
  14794. // undo() methods, or else these actions won't actually get done.
  14795. return false;
  14796. }
  14797. else
  14798. {
  14799. bool success = false;
  14800. JUCE_TRY
  14801. {
  14802. success = command->perform();
  14803. }
  14804. JUCE_CATCH_EXCEPTION
  14805. jassert (success);
  14806. if (success)
  14807. {
  14808. if (nextIndex > 0 && ! newTransaction)
  14809. {
  14810. OwnedArray<UndoableAction>* commandSet = transactions [nextIndex - 1];
  14811. jassert (commandSet != 0);
  14812. if (commandSet == 0)
  14813. return false;
  14814. commandSet->add (command);
  14815. }
  14816. else
  14817. {
  14818. OwnedArray<UndoableAction>* commandSet = new OwnedArray<UndoableAction>();
  14819. commandSet->add (command);
  14820. transactions.insert (nextIndex, commandSet);
  14821. transactionNames.insert (nextIndex, currentTransactionName);
  14822. ++nextIndex;
  14823. }
  14824. totalUnitsStored += command->getSizeInUnits();
  14825. newTransaction = false;
  14826. }
  14827. while (nextIndex < transactions.size())
  14828. {
  14829. const OwnedArray <UndoableAction>* const lastSet = transactions.getLast();
  14830. for (int i = lastSet->size(); --i >= 0;)
  14831. totalUnitsStored -= lastSet->getUnchecked (i)->getSizeInUnits();
  14832. transactions.removeLast();
  14833. transactionNames.remove (transactionNames.size() - 1);
  14834. }
  14835. while (nextIndex > 0
  14836. && totalUnitsStored > maxNumUnitsToKeep
  14837. && transactions.size() > minimumTransactionsToKeep)
  14838. {
  14839. const OwnedArray <UndoableAction>* const firstSet = transactions.getFirst();
  14840. for (int i = firstSet->size(); --i >= 0;)
  14841. totalUnitsStored -= firstSet->getUnchecked (i)->getSizeInUnits();
  14842. jassert (totalUnitsStored >= 0); // something fishy going on if this fails!
  14843. transactions.remove (0);
  14844. transactionNames.remove (0);
  14845. --nextIndex;
  14846. }
  14847. sendChangeMessage (this);
  14848. return success;
  14849. }
  14850. }
  14851. return false;
  14852. }
  14853. void UndoManager::beginNewTransaction (const String& actionName)
  14854. {
  14855. newTransaction = true;
  14856. currentTransactionName = actionName;
  14857. }
  14858. void UndoManager::setCurrentTransactionName (const String& newName)
  14859. {
  14860. currentTransactionName = newName;
  14861. }
  14862. bool UndoManager::canUndo() const
  14863. {
  14864. return nextIndex > 0;
  14865. }
  14866. bool UndoManager::canRedo() const
  14867. {
  14868. return nextIndex < transactions.size();
  14869. }
  14870. const String UndoManager::getUndoDescription() const
  14871. {
  14872. return transactionNames [nextIndex - 1];
  14873. }
  14874. const String UndoManager::getRedoDescription() const
  14875. {
  14876. return transactionNames [nextIndex];
  14877. }
  14878. bool UndoManager::undo()
  14879. {
  14880. const OwnedArray<UndoableAction>* const commandSet = transactions [nextIndex - 1];
  14881. if (commandSet == 0)
  14882. return false;
  14883. reentrancyCheck = true;
  14884. bool failed = false;
  14885. for (int i = commandSet->size(); --i >= 0;)
  14886. {
  14887. if (! commandSet->getUnchecked(i)->undo())
  14888. {
  14889. jassertfalse
  14890. failed = true;
  14891. break;
  14892. }
  14893. }
  14894. reentrancyCheck = false;
  14895. if (failed)
  14896. {
  14897. clearUndoHistory();
  14898. }
  14899. else
  14900. {
  14901. --nextIndex;
  14902. }
  14903. beginNewTransaction();
  14904. sendChangeMessage (this);
  14905. return true;
  14906. }
  14907. bool UndoManager::redo()
  14908. {
  14909. const OwnedArray<UndoableAction>* const commandSet = transactions [nextIndex];
  14910. if (commandSet == 0)
  14911. return false;
  14912. reentrancyCheck = true;
  14913. bool failed = false;
  14914. for (int i = 0; i < commandSet->size(); ++i)
  14915. {
  14916. if (! commandSet->getUnchecked(i)->perform())
  14917. {
  14918. jassertfalse
  14919. failed = true;
  14920. break;
  14921. }
  14922. }
  14923. reentrancyCheck = false;
  14924. if (failed)
  14925. {
  14926. clearUndoHistory();
  14927. }
  14928. else
  14929. {
  14930. ++nextIndex;
  14931. }
  14932. beginNewTransaction();
  14933. sendChangeMessage (this);
  14934. return true;
  14935. }
  14936. bool UndoManager::undoCurrentTransactionOnly()
  14937. {
  14938. return newTransaction ? false
  14939. : undo();
  14940. }
  14941. void UndoManager::getActionsInCurrentTransaction (Array <const UndoableAction*>& actionsFound) const
  14942. {
  14943. const OwnedArray <UndoableAction>* const commandSet = transactions [nextIndex - 1];
  14944. if (commandSet != 0 && ! newTransaction)
  14945. {
  14946. for (int i = 0; i < commandSet->size(); ++i)
  14947. actionsFound.add (commandSet->getUnchecked(i));
  14948. }
  14949. }
  14950. int UndoManager::getNumActionsInCurrentTransaction() const
  14951. {
  14952. const OwnedArray <UndoableAction>* const commandSet = transactions [nextIndex - 1];
  14953. if (commandSet != 0 && ! newTransaction)
  14954. return commandSet->size();
  14955. return 0;
  14956. }
  14957. END_JUCE_NAMESPACE
  14958. /*** End of inlined file: juce_UndoManager.cpp ***/
  14959. /*** Start of inlined file: juce_AiffAudioFormat.cpp ***/
  14960. BEGIN_JUCE_NAMESPACE
  14961. static const char* const aiffFormatName = "AIFF file";
  14962. static const tchar* const aiffExtensions[] = { T(".aiff"), T(".aif"), 0 };
  14963. class AiffAudioFormatReader : public AudioFormatReader
  14964. {
  14965. public:
  14966. int bytesPerFrame;
  14967. int64 dataChunkStart;
  14968. bool littleEndian;
  14969. AiffAudioFormatReader (InputStream* in)
  14970. : AudioFormatReader (in, TRANS (aiffFormatName))
  14971. {
  14972. if (input->readInt() == chunkName ("FORM"))
  14973. {
  14974. const int len = input->readIntBigEndian();
  14975. const int64 end = input->getPosition() + len;
  14976. const int nextType = input->readInt();
  14977. if (nextType == chunkName ("AIFF") || nextType == chunkName ("AIFC"))
  14978. {
  14979. bool hasGotVer = false;
  14980. bool hasGotData = false;
  14981. bool hasGotType = false;
  14982. while (input->getPosition() < end)
  14983. {
  14984. const int type = input->readInt();
  14985. const uint32 length = (uint32) input->readIntBigEndian();
  14986. const int64 chunkEnd = input->getPosition() + length;
  14987. if (type == chunkName ("FVER"))
  14988. {
  14989. hasGotVer = true;
  14990. const int ver = input->readIntBigEndian();
  14991. if (ver != 0 && ver != (int)0xa2805140)
  14992. break;
  14993. }
  14994. else if (type == chunkName ("COMM"))
  14995. {
  14996. hasGotType = true;
  14997. numChannels = (unsigned int)input->readShortBigEndian();
  14998. lengthInSamples = input->readIntBigEndian();
  14999. bitsPerSample = input->readShortBigEndian();
  15000. bytesPerFrame = (numChannels * bitsPerSample) >> 3;
  15001. unsigned char sampleRateBytes[10];
  15002. input->read (sampleRateBytes, 10);
  15003. const int byte0 = sampleRateBytes[0];
  15004. if ((byte0 & 0x80) != 0
  15005. || byte0 <= 0x3F || byte0 > 0x40
  15006. || (byte0 == 0x40 && sampleRateBytes[1] > 0x1C))
  15007. break;
  15008. unsigned int sampRate = ByteOrder::bigEndianInt ((char*) sampleRateBytes + 2);
  15009. sampRate >>= (16414 - ByteOrder::bigEndianShort ((char*) sampleRateBytes));
  15010. sampleRate = (int) sampRate;
  15011. if (length <= 18)
  15012. {
  15013. // some types don't have a chunk large enough to include a compression
  15014. // type, so assume it's just big-endian pcm
  15015. littleEndian = false;
  15016. }
  15017. else
  15018. {
  15019. const int compType = input->readInt();
  15020. if (compType == chunkName ("NONE") || compType == chunkName ("twos"))
  15021. {
  15022. littleEndian = false;
  15023. }
  15024. else if (compType == chunkName ("sowt"))
  15025. {
  15026. littleEndian = true;
  15027. }
  15028. else
  15029. {
  15030. sampleRate = 0;
  15031. break;
  15032. }
  15033. }
  15034. }
  15035. else if (type == chunkName ("SSND"))
  15036. {
  15037. hasGotData = true;
  15038. const int offset = input->readIntBigEndian();
  15039. dataChunkStart = input->getPosition() + 4 + offset;
  15040. lengthInSamples = (bytesPerFrame > 0) ? jmin (lengthInSamples, (int64) (length / bytesPerFrame)) : 0;
  15041. }
  15042. else if ((hasGotVer && hasGotData && hasGotType)
  15043. || chunkEnd < input->getPosition()
  15044. || input->isExhausted())
  15045. {
  15046. break;
  15047. }
  15048. input->setPosition (chunkEnd);
  15049. }
  15050. }
  15051. }
  15052. }
  15053. ~AiffAudioFormatReader()
  15054. {
  15055. }
  15056. bool readSamples (int** destSamples, int numDestChannels, int startOffsetInDestBuffer,
  15057. int64 startSampleInFile, int numSamples)
  15058. {
  15059. const int64 samplesAvailable = lengthInSamples - startSampleInFile;
  15060. if (samplesAvailable < numSamples)
  15061. {
  15062. for (int i = numDestChannels; --i >= 0;)
  15063. if (destSamples[i] != 0)
  15064. zeromem (destSamples[i] + startOffsetInDestBuffer, sizeof (int) * numSamples);
  15065. numSamples = (int) samplesAvailable;
  15066. }
  15067. if (numSamples <= 0)
  15068. return true;
  15069. input->setPosition (dataChunkStart + startSampleInFile * bytesPerFrame);
  15070. const int tempBufSize = 480 * 3 * 4; // (keep this a multiple of 3)
  15071. char tempBuffer [tempBufSize];
  15072. while (numSamples > 0)
  15073. {
  15074. int* left = destSamples[0];
  15075. if (left != 0)
  15076. left += startOffsetInDestBuffer;
  15077. int* right = numDestChannels > 1 ? destSamples[1] : 0;
  15078. if (right != 0)
  15079. right += startOffsetInDestBuffer;
  15080. const int numThisTime = jmin (tempBufSize / bytesPerFrame, numSamples);
  15081. const int bytesRead = input->read (tempBuffer, numThisTime * bytesPerFrame);
  15082. if (bytesRead < numThisTime * bytesPerFrame)
  15083. zeromem (tempBuffer + bytesRead, numThisTime * bytesPerFrame - bytesRead);
  15084. if (bitsPerSample == 16)
  15085. {
  15086. if (littleEndian)
  15087. {
  15088. const short* src = (const short*) tempBuffer;
  15089. if (numChannels > 1)
  15090. {
  15091. if (left == 0)
  15092. {
  15093. for (int i = numThisTime; --i >= 0;)
  15094. {
  15095. *right++ = (int) ByteOrder::swapIfBigEndian ((unsigned short) *src++) << 16;
  15096. ++src;
  15097. }
  15098. }
  15099. else if (right == 0)
  15100. {
  15101. for (int i = numThisTime; --i >= 0;)
  15102. {
  15103. ++src;
  15104. *left++ = (int) ByteOrder::swapIfBigEndian ((unsigned short) *src++) << 16;
  15105. }
  15106. }
  15107. else
  15108. {
  15109. for (int i = numThisTime; --i >= 0;)
  15110. {
  15111. *left++ = (int) ByteOrder::swapIfBigEndian ((unsigned short) *src++) << 16;
  15112. *right++ = (int) ByteOrder::swapIfBigEndian ((unsigned short) *src++) << 16;
  15113. }
  15114. }
  15115. }
  15116. else
  15117. {
  15118. for (int i = numThisTime; --i >= 0;)
  15119. {
  15120. *left++ = (int) ByteOrder::swapIfBigEndian ((unsigned short) *src++) << 16;
  15121. }
  15122. }
  15123. }
  15124. else
  15125. {
  15126. const char* src = (const char*) tempBuffer;
  15127. if (numChannels > 1)
  15128. {
  15129. if (left == 0)
  15130. {
  15131. for (int i = numThisTime; --i >= 0;)
  15132. {
  15133. *right++ = ByteOrder::bigEndianShort (src) << 16;
  15134. src += 4;
  15135. }
  15136. }
  15137. else if (right == 0)
  15138. {
  15139. for (int i = numThisTime; --i >= 0;)
  15140. {
  15141. src += 2;
  15142. *left++ = ByteOrder::bigEndianShort (src) << 16;
  15143. src += 2;
  15144. }
  15145. }
  15146. else
  15147. {
  15148. for (int i = numThisTime; --i >= 0;)
  15149. {
  15150. *left++ = ByteOrder::bigEndianShort (src) << 16;
  15151. src += 2;
  15152. *right++ = ByteOrder::bigEndianShort (src) << 16;
  15153. src += 2;
  15154. }
  15155. }
  15156. }
  15157. else
  15158. {
  15159. for (int i = numThisTime; --i >= 0;)
  15160. {
  15161. *left++ = ByteOrder::bigEndianShort (src) << 16;
  15162. src += 2;
  15163. }
  15164. }
  15165. }
  15166. }
  15167. else if (bitsPerSample == 24)
  15168. {
  15169. const char* src = (const char*)tempBuffer;
  15170. if (littleEndian)
  15171. {
  15172. if (numChannels > 1)
  15173. {
  15174. if (left == 0)
  15175. {
  15176. for (int i = numThisTime; --i >= 0;)
  15177. {
  15178. *right++ = ByteOrder::littleEndian24Bit (src) << 8;
  15179. src += 6;
  15180. }
  15181. }
  15182. else if (right == 0)
  15183. {
  15184. for (int i = numThisTime; --i >= 0;)
  15185. {
  15186. src += 3;
  15187. *left++ = ByteOrder::littleEndian24Bit (src) << 8;
  15188. src += 3;
  15189. }
  15190. }
  15191. else
  15192. {
  15193. for (int i = numThisTime; --i >= 0;)
  15194. {
  15195. *left++ = ByteOrder::littleEndian24Bit (src) << 8;
  15196. src += 3;
  15197. *right++ = ByteOrder::littleEndian24Bit (src) << 8;
  15198. src += 3;
  15199. }
  15200. }
  15201. }
  15202. else
  15203. {
  15204. for (int i = numThisTime; --i >= 0;)
  15205. {
  15206. *left++ = ByteOrder::littleEndian24Bit (src) << 8;
  15207. src += 3;
  15208. }
  15209. }
  15210. }
  15211. else
  15212. {
  15213. if (numChannels > 1)
  15214. {
  15215. if (left == 0)
  15216. {
  15217. for (int i = numThisTime; --i >= 0;)
  15218. {
  15219. *right++ = ByteOrder::bigEndian24Bit (src) << 8;
  15220. src += 6;
  15221. }
  15222. }
  15223. else if (right == 0)
  15224. {
  15225. for (int i = numThisTime; --i >= 0;)
  15226. {
  15227. src += 3;
  15228. *left++ = ByteOrder::bigEndian24Bit (src) << 8;
  15229. src += 3;
  15230. }
  15231. }
  15232. else
  15233. {
  15234. for (int i = numThisTime; --i >= 0;)
  15235. {
  15236. *left++ = ByteOrder::bigEndian24Bit (src) << 8;
  15237. src += 3;
  15238. *right++ = ByteOrder::bigEndian24Bit (src) << 8;
  15239. src += 3;
  15240. }
  15241. }
  15242. }
  15243. else
  15244. {
  15245. for (int i = numThisTime; --i >= 0;)
  15246. {
  15247. *left++ = ByteOrder::bigEndian24Bit (src) << 8;
  15248. src += 3;
  15249. }
  15250. }
  15251. }
  15252. }
  15253. else if (bitsPerSample == 32)
  15254. {
  15255. const unsigned int* src = (const unsigned int*) tempBuffer;
  15256. unsigned int* l = (unsigned int*) left;
  15257. unsigned int* r = (unsigned int*) right;
  15258. if (littleEndian)
  15259. {
  15260. if (numChannels > 1)
  15261. {
  15262. if (l == 0)
  15263. {
  15264. for (int i = numThisTime; --i >= 0;)
  15265. {
  15266. ++src;
  15267. *r++ = ByteOrder::swapIfBigEndian (*src++);
  15268. }
  15269. }
  15270. else if (r == 0)
  15271. {
  15272. for (int i = numThisTime; --i >= 0;)
  15273. {
  15274. *l++ = ByteOrder::swapIfBigEndian (*src++);
  15275. ++src;
  15276. }
  15277. }
  15278. else
  15279. {
  15280. for (int i = numThisTime; --i >= 0;)
  15281. {
  15282. *l++ = ByteOrder::swapIfBigEndian (*src++);
  15283. *r++ = ByteOrder::swapIfBigEndian (*src++);
  15284. }
  15285. }
  15286. }
  15287. else
  15288. {
  15289. for (int i = numThisTime; --i >= 0;)
  15290. {
  15291. *l++ = ByteOrder::swapIfBigEndian (*src++);
  15292. }
  15293. }
  15294. }
  15295. else
  15296. {
  15297. if (numChannels > 1)
  15298. {
  15299. if (l == 0)
  15300. {
  15301. for (int i = numThisTime; --i >= 0;)
  15302. {
  15303. ++src;
  15304. *r++ = ByteOrder::swapIfLittleEndian (*src++);
  15305. }
  15306. }
  15307. else if (r == 0)
  15308. {
  15309. for (int i = numThisTime; --i >= 0;)
  15310. {
  15311. *l++ = ByteOrder::swapIfLittleEndian (*src++);
  15312. ++src;
  15313. }
  15314. }
  15315. else
  15316. {
  15317. for (int i = numThisTime; --i >= 0;)
  15318. {
  15319. *l++ = ByteOrder::swapIfLittleEndian (*src++);
  15320. *r++ = ByteOrder::swapIfLittleEndian (*src++);
  15321. }
  15322. }
  15323. }
  15324. else
  15325. {
  15326. for (int i = numThisTime; --i >= 0;)
  15327. {
  15328. *l++ = ByteOrder::swapIfLittleEndian (*src++);
  15329. }
  15330. }
  15331. }
  15332. left = (int*) l;
  15333. right = (int*) r;
  15334. }
  15335. else if (bitsPerSample == 8)
  15336. {
  15337. const char* src = (const char*) tempBuffer;
  15338. if (numChannels > 1)
  15339. {
  15340. if (left == 0)
  15341. {
  15342. for (int i = numThisTime; --i >= 0;)
  15343. {
  15344. *right++ = ((int) *src++) << 24;
  15345. ++src;
  15346. }
  15347. }
  15348. else if (right == 0)
  15349. {
  15350. for (int i = numThisTime; --i >= 0;)
  15351. {
  15352. ++src;
  15353. *left++ = ((int) *src++) << 24;
  15354. }
  15355. }
  15356. else
  15357. {
  15358. for (int i = numThisTime; --i >= 0;)
  15359. {
  15360. *left++ = ((int) *src++) << 24;
  15361. *right++ = ((int) *src++) << 24;
  15362. }
  15363. }
  15364. }
  15365. else
  15366. {
  15367. for (int i = numThisTime; --i >= 0;)
  15368. {
  15369. *left++ = ((int) *src++) << 24;
  15370. }
  15371. }
  15372. }
  15373. startOffsetInDestBuffer += numThisTime;
  15374. numSamples -= numThisTime;
  15375. }
  15376. if (numSamples > 0)
  15377. {
  15378. for (int i = numDestChannels; --i >= 0;)
  15379. if (destSamples[i] != 0)
  15380. zeromem (destSamples[i] + startOffsetInDestBuffer,
  15381. sizeof (int) * numSamples);
  15382. }
  15383. return true;
  15384. }
  15385. juce_UseDebuggingNewOperator
  15386. private:
  15387. AiffAudioFormatReader (const AiffAudioFormatReader&);
  15388. AiffAudioFormatReader& operator= (const AiffAudioFormatReader&);
  15389. static inline int chunkName (const char* const name) { return (int) ByteOrder::littleEndianInt (name); }
  15390. };
  15391. class AiffAudioFormatWriter : public AudioFormatWriter
  15392. {
  15393. MemoryBlock tempBlock;
  15394. uint32 lengthInSamples, bytesWritten;
  15395. int64 headerPosition;
  15396. bool writeFailed;
  15397. static inline int chunkName (const char* const name) { return (int) ByteOrder::littleEndianInt (name); }
  15398. AiffAudioFormatWriter (const AiffAudioFormatWriter&);
  15399. AiffAudioFormatWriter& operator= (const AiffAudioFormatWriter&);
  15400. void writeHeader()
  15401. {
  15402. const bool couldSeekOk = output->setPosition (headerPosition);
  15403. (void) couldSeekOk;
  15404. // if this fails, you've given it an output stream that can't seek! It needs
  15405. // to be able to seek back to write the header
  15406. jassert (couldSeekOk);
  15407. const int headerLen = 54;
  15408. int audioBytes = lengthInSamples * ((bitsPerSample * numChannels) / 8);
  15409. audioBytes += (audioBytes & 1);
  15410. output->writeInt (chunkName ("FORM"));
  15411. output->writeIntBigEndian (headerLen + audioBytes - 8);
  15412. output->writeInt (chunkName ("AIFF"));
  15413. output->writeInt (chunkName ("COMM"));
  15414. output->writeIntBigEndian (18);
  15415. output->writeShortBigEndian ((short) numChannels);
  15416. output->writeIntBigEndian (lengthInSamples);
  15417. output->writeShortBigEndian ((short) bitsPerSample);
  15418. uint8 sampleRateBytes[10];
  15419. zeromem (sampleRateBytes, 10);
  15420. if (sampleRate <= 1)
  15421. {
  15422. sampleRateBytes[0] = 0x3f;
  15423. sampleRateBytes[1] = 0xff;
  15424. sampleRateBytes[2] = 0x80;
  15425. }
  15426. else
  15427. {
  15428. int mask = 0x40000000;
  15429. sampleRateBytes[0] = 0x40;
  15430. if (sampleRate >= mask)
  15431. {
  15432. jassertfalse
  15433. sampleRateBytes[1] = 0x1d;
  15434. }
  15435. else
  15436. {
  15437. int n = (int) sampleRate;
  15438. int i;
  15439. for (i = 0; i <= 32 ; ++i)
  15440. {
  15441. if ((n & mask) != 0)
  15442. break;
  15443. mask >>= 1;
  15444. }
  15445. n = n << (i + 1);
  15446. sampleRateBytes[1] = (uint8) (29 - i);
  15447. sampleRateBytes[2] = (uint8) ((n >> 24) & 0xff);
  15448. sampleRateBytes[3] = (uint8) ((n >> 16) & 0xff);
  15449. sampleRateBytes[4] = (uint8) ((n >> 8) & 0xff);
  15450. sampleRateBytes[5] = (uint8) (n & 0xff);
  15451. }
  15452. }
  15453. output->write (sampleRateBytes, 10);
  15454. output->writeInt (chunkName ("SSND"));
  15455. output->writeIntBigEndian (audioBytes + 8);
  15456. output->writeInt (0);
  15457. output->writeInt (0);
  15458. jassert (output->getPosition() == headerLen);
  15459. }
  15460. public:
  15461. AiffAudioFormatWriter (OutputStream* out,
  15462. const double sampleRate_,
  15463. const unsigned int chans,
  15464. const int bits)
  15465. : AudioFormatWriter (out,
  15466. TRANS (aiffFormatName),
  15467. sampleRate_,
  15468. chans,
  15469. bits),
  15470. lengthInSamples (0),
  15471. bytesWritten (0),
  15472. writeFailed (false)
  15473. {
  15474. headerPosition = out->getPosition();
  15475. writeHeader();
  15476. }
  15477. ~AiffAudioFormatWriter()
  15478. {
  15479. if ((bytesWritten & 1) != 0)
  15480. output->writeByte (0);
  15481. writeHeader();
  15482. }
  15483. bool write (const int** data, int numSamples)
  15484. {
  15485. if (writeFailed)
  15486. return false;
  15487. const int bytes = numChannels * numSamples * bitsPerSample / 8;
  15488. tempBlock.ensureSize (bytes, false);
  15489. char* buffer = (char*) tempBlock.getData();
  15490. const int* left = data[0];
  15491. const int* right = data[1];
  15492. if (right == 0)
  15493. right = left;
  15494. if (bitsPerSample == 16)
  15495. {
  15496. short* b = (short*) buffer;
  15497. if (numChannels > 1)
  15498. {
  15499. for (int i = numSamples; --i >= 0;)
  15500. {
  15501. *b++ = (short) ByteOrder::swapIfLittleEndian ((uint16) (*left++ >> 16));
  15502. *b++ = (short) ByteOrder::swapIfLittleEndian ((uint16) (*right++ >> 16));
  15503. }
  15504. }
  15505. else
  15506. {
  15507. for (int i = numSamples; --i >= 0;)
  15508. {
  15509. *b++ = (short) ByteOrder::swapIfLittleEndian ((uint16) (*left++ >> 16));
  15510. }
  15511. }
  15512. }
  15513. else if (bitsPerSample == 24)
  15514. {
  15515. char* b = (char*) buffer;
  15516. if (numChannels > 1)
  15517. {
  15518. for (int i = numSamples; --i >= 0;)
  15519. {
  15520. ByteOrder::bigEndian24BitToChars (*left++ >> 8, b);
  15521. b += 3;
  15522. ByteOrder::bigEndian24BitToChars (*right++ >> 8, b);
  15523. b += 3;
  15524. }
  15525. }
  15526. else
  15527. {
  15528. for (int i = numSamples; --i >= 0;)
  15529. {
  15530. ByteOrder::bigEndian24BitToChars (*left++ >> 8, b);
  15531. b += 3;
  15532. }
  15533. }
  15534. }
  15535. else if (bitsPerSample == 32)
  15536. {
  15537. uint32* b = (uint32*) buffer;
  15538. if (numChannels > 1)
  15539. {
  15540. for (int i = numSamples; --i >= 0;)
  15541. {
  15542. *b++ = ByteOrder::swapIfLittleEndian ((uint32) *left++);
  15543. *b++ = ByteOrder::swapIfLittleEndian ((uint32) *right++);
  15544. }
  15545. }
  15546. else
  15547. {
  15548. for (int i = numSamples; --i >= 0;)
  15549. {
  15550. *b++ = ByteOrder::swapIfLittleEndian ((uint32) *left++);
  15551. }
  15552. }
  15553. }
  15554. else if (bitsPerSample == 8)
  15555. {
  15556. char* b = (char*) buffer;
  15557. if (numChannels > 1)
  15558. {
  15559. for (int i = numSamples; --i >= 0;)
  15560. {
  15561. *b++ = (char) (*left++ >> 24);
  15562. *b++ = (char) (*right++ >> 24);
  15563. }
  15564. }
  15565. else
  15566. {
  15567. for (int i = numSamples; --i >= 0;)
  15568. {
  15569. *b++ = (char) (*left++ >> 24);
  15570. }
  15571. }
  15572. }
  15573. if (bytesWritten + bytes >= (uint32) 0xfff00000
  15574. || ! output->write (buffer, bytes))
  15575. {
  15576. // failed to write to disk, so let's try writing the header.
  15577. // If it's just run out of disk space, then if it does manage
  15578. // to write the header, we'll still have a useable file..
  15579. writeHeader();
  15580. writeFailed = true;
  15581. return false;
  15582. }
  15583. else
  15584. {
  15585. bytesWritten += bytes;
  15586. lengthInSamples += numSamples;
  15587. return true;
  15588. }
  15589. }
  15590. juce_UseDebuggingNewOperator
  15591. };
  15592. AiffAudioFormat::AiffAudioFormat()
  15593. : AudioFormat (TRANS (aiffFormatName), (const tchar**) aiffExtensions)
  15594. {
  15595. }
  15596. AiffAudioFormat::~AiffAudioFormat()
  15597. {
  15598. }
  15599. const Array <int> AiffAudioFormat::getPossibleSampleRates()
  15600. {
  15601. const int rates[] = { 22050, 32000, 44100, 48000, 88200, 96000, 176400, 192000, 0 };
  15602. return Array <int> (rates);
  15603. }
  15604. const Array <int> AiffAudioFormat::getPossibleBitDepths()
  15605. {
  15606. const int depths[] = { 8, 16, 24, 0 };
  15607. return Array <int> (depths);
  15608. }
  15609. bool AiffAudioFormat::canDoStereo()
  15610. {
  15611. return true;
  15612. }
  15613. bool AiffAudioFormat::canDoMono()
  15614. {
  15615. return true;
  15616. }
  15617. #if JUCE_MAC
  15618. bool AiffAudioFormat::canHandleFile (const File& f)
  15619. {
  15620. if (AudioFormat::canHandleFile (f))
  15621. return true;
  15622. const OSType type = PlatformUtilities::getTypeOfFile (f.getFullPathName());
  15623. return type == 'AIFF' || type == 'AIFC'
  15624. || type == 'aiff' || type == 'aifc';
  15625. }
  15626. #endif
  15627. AudioFormatReader* AiffAudioFormat::createReaderFor (InputStream* sourceStream,
  15628. const bool deleteStreamIfOpeningFails)
  15629. {
  15630. ScopedPointer <AiffAudioFormatReader> w (new AiffAudioFormatReader (sourceStream));
  15631. if (w->sampleRate != 0)
  15632. return w.release();
  15633. if (! deleteStreamIfOpeningFails)
  15634. w->input = 0;
  15635. return 0;
  15636. }
  15637. AudioFormatWriter* AiffAudioFormat::createWriterFor (OutputStream* out,
  15638. double sampleRate,
  15639. unsigned int chans,
  15640. int bitsPerSample,
  15641. const StringPairArray& /*metadataValues*/,
  15642. int /*qualityOptionIndex*/)
  15643. {
  15644. if (getPossibleBitDepths().contains (bitsPerSample))
  15645. {
  15646. return new AiffAudioFormatWriter (out,
  15647. sampleRate,
  15648. chans,
  15649. bitsPerSample);
  15650. }
  15651. return 0;
  15652. }
  15653. END_JUCE_NAMESPACE
  15654. /*** End of inlined file: juce_AiffAudioFormat.cpp ***/
  15655. /*** Start of inlined file: juce_AudioCDReader.cpp ***/
  15656. BEGIN_JUCE_NAMESPACE
  15657. #if JUCE_MAC && JUCE_USE_CDREADER
  15658. // Mac version doesn't need any native code because it's all done with files..
  15659. // Windows + Linux versions are in the platform-dependent code sections.
  15660. static void findCDs (Array<File>& cds)
  15661. {
  15662. File volumes ("/Volumes");
  15663. volumes.findChildFiles (cds, File::findDirectories, false);
  15664. for (int i = cds.size(); --i >= 0;)
  15665. if (! cds.getReference(i).getChildFile (".TOC.plist").exists())
  15666. cds.remove (i);
  15667. }
  15668. const StringArray AudioCDReader::getAvailableCDNames()
  15669. {
  15670. Array<File> cds;
  15671. findCDs (cds);
  15672. StringArray names;
  15673. for (int i = 0; i < cds.size(); ++i)
  15674. names.add (cds.getReference(i).getFileName());
  15675. return names;
  15676. }
  15677. AudioCDReader* AudioCDReader::createReaderForCD (const int index)
  15678. {
  15679. Array<File> cds;
  15680. findCDs (cds);
  15681. if (cds[index] != File::nonexistent)
  15682. return new AudioCDReader (cds[index]);
  15683. else
  15684. return 0;
  15685. }
  15686. AudioCDReader::AudioCDReader (const File& volume)
  15687. : AudioFormatReader (0, "CD Audio"),
  15688. volumeDir (volume),
  15689. currentReaderTrack (-1),
  15690. reader (0)
  15691. {
  15692. sampleRate = 44100.0;
  15693. bitsPerSample = 16;
  15694. numChannels = 2;
  15695. usesFloatingPointData = false;
  15696. refreshTrackLengths();
  15697. }
  15698. AudioCDReader::~AudioCDReader()
  15699. {
  15700. }
  15701. static int getTrackNumber (const File& file)
  15702. {
  15703. return file.getFileName()
  15704. .initialSectionContainingOnly (T("0123456789"))
  15705. .getIntValue();
  15706. }
  15707. int AudioCDReader::compareElements (const File& first, const File& second)
  15708. {
  15709. const int firstTrack = getTrackNumber (first);
  15710. const int secondTrack = getTrackNumber (second);
  15711. jassert (firstTrack > 0 && secondTrack > 0);
  15712. return firstTrack - secondTrack;
  15713. }
  15714. void AudioCDReader::refreshTrackLengths()
  15715. {
  15716. tracks.clear();
  15717. trackStartSamples.clear();
  15718. volumeDir.findChildFiles (tracks, File::findFiles | File::ignoreHiddenFiles, false, T("*.aiff"));
  15719. tracks.sort (*this);
  15720. AiffAudioFormat format;
  15721. int sample = 0;
  15722. for (int i = 0; i < tracks.size(); ++i)
  15723. {
  15724. trackStartSamples.add (sample);
  15725. FileInputStream* const in = tracks.getReference(i).createInputStream();
  15726. if (in != 0)
  15727. {
  15728. ScopedPointer <AudioFormatReader> r (format.createReaderFor (in, true));
  15729. if (r != 0)
  15730. sample += (int) r->lengthInSamples;
  15731. }
  15732. }
  15733. trackStartSamples.add (sample);
  15734. lengthInSamples = sample;
  15735. }
  15736. bool AudioCDReader::readSamples (int** destSamples, int numDestChannels, int startOffsetInDestBuffer,
  15737. int64 startSampleInFile, int numSamples)
  15738. {
  15739. while (numSamples > 0)
  15740. {
  15741. int track = -1;
  15742. for (int i = 0; i < trackStartSamples.size() - 1; ++i)
  15743. {
  15744. if (startSampleInFile < trackStartSamples.getUnchecked (i + 1))
  15745. {
  15746. track = i;
  15747. break;
  15748. }
  15749. }
  15750. if (track < 0)
  15751. return false;
  15752. if (track != currentReaderTrack)
  15753. {
  15754. reader = 0;
  15755. FileInputStream* const in = tracks [track].createInputStream();
  15756. if (in != 0)
  15757. {
  15758. BufferedInputStream* const bin = new BufferedInputStream (in, 65536, true);
  15759. AiffAudioFormat format;
  15760. reader = format.createReaderFor (bin, true);
  15761. if (reader == 0)
  15762. currentReaderTrack = -1;
  15763. else
  15764. currentReaderTrack = track;
  15765. }
  15766. }
  15767. if (reader == 0)
  15768. return false;
  15769. const int startPos = (int) (startSampleInFile - trackStartSamples.getUnchecked (track));
  15770. const int numAvailable = (int) jmin ((int64) numSamples, reader->lengthInSamples - startPos);
  15771. reader->readSamples (destSamples, numDestChannels, startOffsetInDestBuffer, startPos, numAvailable);
  15772. numSamples -= numAvailable;
  15773. startSampleInFile += numAvailable;
  15774. }
  15775. return true;
  15776. }
  15777. bool AudioCDReader::isCDStillPresent() const
  15778. {
  15779. return volumeDir.exists();
  15780. }
  15781. int AudioCDReader::getNumTracks() const
  15782. {
  15783. return tracks.size();
  15784. }
  15785. int AudioCDReader::getPositionOfTrackStart (int trackNum) const
  15786. {
  15787. return trackStartSamples [trackNum];
  15788. }
  15789. bool AudioCDReader::isTrackAudio (int trackNum) const
  15790. {
  15791. return tracks [trackNum] != File::nonexistent;
  15792. }
  15793. void AudioCDReader::enableIndexScanning (bool b)
  15794. {
  15795. // any way to do this on a Mac??
  15796. }
  15797. int AudioCDReader::getLastIndex() const
  15798. {
  15799. return 0;
  15800. }
  15801. const Array <int> AudioCDReader::findIndexesInTrack (const int trackNumber)
  15802. {
  15803. return Array <int>();
  15804. }
  15805. int AudioCDReader::getCDDBId()
  15806. {
  15807. return 0; //xxx
  15808. }
  15809. #endif
  15810. END_JUCE_NAMESPACE
  15811. /*** End of inlined file: juce_AudioCDReader.cpp ***/
  15812. /*** Start of inlined file: juce_AudioFormat.cpp ***/
  15813. BEGIN_JUCE_NAMESPACE
  15814. AudioFormatReader::AudioFormatReader (InputStream* const in,
  15815. const String& formatName_)
  15816. : sampleRate (0),
  15817. bitsPerSample (0),
  15818. lengthInSamples (0),
  15819. numChannels (0),
  15820. usesFloatingPointData (false),
  15821. input (in),
  15822. formatName (formatName_)
  15823. {
  15824. }
  15825. AudioFormatReader::~AudioFormatReader()
  15826. {
  15827. delete input;
  15828. }
  15829. bool AudioFormatReader::read (int** destSamples,
  15830. int numDestChannels,
  15831. int64 startSampleInSource,
  15832. int numSamplesToRead,
  15833. const bool fillLeftoverChannelsWithCopies)
  15834. {
  15835. jassert (numDestChannels > 0); // you have to actually give this some channels to work with!
  15836. int startOffsetInDestBuffer = 0;
  15837. if (startSampleInSource < 0)
  15838. {
  15839. const int silence = (int) jmin (-startSampleInSource, (int64) numSamplesToRead);
  15840. for (int i = numDestChannels; --i >= 0;)
  15841. if (destSamples[i] != 0)
  15842. zeromem (destSamples[i], sizeof (int) * silence);
  15843. startOffsetInDestBuffer += silence;
  15844. numSamplesToRead -= silence;
  15845. startSampleInSource = 0;
  15846. }
  15847. if (numSamplesToRead <= 0)
  15848. return true;
  15849. if (! readSamples (destSamples, jmin ((int) numChannels, numDestChannels), startOffsetInDestBuffer,
  15850. startSampleInSource, numSamplesToRead))
  15851. return false;
  15852. if (numDestChannels > (int) numChannels)
  15853. {
  15854. if (fillLeftoverChannelsWithCopies)
  15855. {
  15856. int* lastFullChannel = destSamples[0];
  15857. for (int i = numDestChannels; --i > 0;)
  15858. {
  15859. if (destSamples[i] != 0)
  15860. {
  15861. lastFullChannel = destSamples[i];
  15862. break;
  15863. }
  15864. }
  15865. if (lastFullChannel != 0)
  15866. for (int i = numChannels; i < numDestChannels; ++i)
  15867. if (destSamples[i] != 0)
  15868. memcpy (destSamples[i], lastFullChannel, sizeof (int) * numSamplesToRead);
  15869. }
  15870. else
  15871. {
  15872. for (int i = numChannels; i < numDestChannels; ++i)
  15873. if (destSamples[i] != 0)
  15874. zeromem (destSamples[i], sizeof (int) * numSamplesToRead);
  15875. }
  15876. }
  15877. return true;
  15878. }
  15879. static void findAudioBufferMaxMin (const float* const buffer, const int num, float& maxVal, float& minVal) throw()
  15880. {
  15881. float mn = buffer[0];
  15882. float mx = mn;
  15883. for (int i = 1; i < num; ++i)
  15884. {
  15885. const float s = buffer[i];
  15886. if (s > mx) mx = s;
  15887. if (s < mn) mn = s;
  15888. }
  15889. maxVal = mx;
  15890. minVal = mn;
  15891. }
  15892. void AudioFormatReader::readMaxLevels (int64 startSampleInFile,
  15893. int64 numSamples,
  15894. float& lowestLeft, float& highestLeft,
  15895. float& lowestRight, float& highestRight)
  15896. {
  15897. if (numSamples <= 0)
  15898. {
  15899. lowestLeft = 0;
  15900. lowestRight = 0;
  15901. highestLeft = 0;
  15902. highestRight = 0;
  15903. return;
  15904. }
  15905. const int bufferSize = (int) jmin (numSamples, (int64) 4096);
  15906. MemoryBlock tempSpace (bufferSize * sizeof (int) * 2 + 64);
  15907. int* tempBuffer[3];
  15908. tempBuffer[0] = (int*) tempSpace.getData();
  15909. tempBuffer[1] = ((int*) tempSpace.getData()) + bufferSize;
  15910. tempBuffer[2] = 0;
  15911. if (usesFloatingPointData)
  15912. {
  15913. float lmin = 1.0e6f;
  15914. float lmax = -lmin;
  15915. float rmin = lmin;
  15916. float rmax = lmax;
  15917. while (numSamples > 0)
  15918. {
  15919. const int numToDo = (int) jmin (numSamples, (int64) bufferSize);
  15920. read ((int**) tempBuffer, 2, startSampleInFile, numToDo, false);
  15921. numSamples -= numToDo;
  15922. startSampleInFile += numToDo;
  15923. float bufmin, bufmax;
  15924. findAudioBufferMaxMin ((float*) tempBuffer[0], numToDo, bufmax, bufmin);
  15925. lmin = jmin (lmin, bufmin);
  15926. lmax = jmax (lmax, bufmax);
  15927. if (numChannels > 1)
  15928. {
  15929. findAudioBufferMaxMin ((float*) tempBuffer[1], numToDo, bufmax, bufmin);
  15930. rmin = jmin (rmin, bufmin);
  15931. rmax = jmax (rmax, bufmax);
  15932. }
  15933. }
  15934. if (numChannels <= 1)
  15935. {
  15936. rmax = lmax;
  15937. rmin = lmin;
  15938. }
  15939. lowestLeft = lmin;
  15940. highestLeft = lmax;
  15941. lowestRight = rmin;
  15942. highestRight = rmax;
  15943. }
  15944. else
  15945. {
  15946. int lmax = std::numeric_limits<int>::min();
  15947. int lmin = std::numeric_limits<int>::max();
  15948. int rmax = std::numeric_limits<int>::min();
  15949. int rmin = std::numeric_limits<int>::max();
  15950. while (numSamples > 0)
  15951. {
  15952. const int numToDo = (int) jmin (numSamples, (int64) bufferSize);
  15953. read ((int**) tempBuffer, 2, startSampleInFile, numToDo, false);
  15954. numSamples -= numToDo;
  15955. startSampleInFile += numToDo;
  15956. for (int j = numChannels; --j >= 0;)
  15957. {
  15958. int bufMax = std::numeric_limits<int>::min();
  15959. int bufMin = std::numeric_limits<int>::max();
  15960. const int* const b = tempBuffer[j];
  15961. for (int i = 0; i < numToDo; ++i)
  15962. {
  15963. const int samp = b[i];
  15964. if (samp < bufMin)
  15965. bufMin = samp;
  15966. if (samp > bufMax)
  15967. bufMax = samp;
  15968. }
  15969. if (j == 0)
  15970. {
  15971. lmax = jmax (lmax, bufMax);
  15972. lmin = jmin (lmin, bufMin);
  15973. }
  15974. else
  15975. {
  15976. rmax = jmax (rmax, bufMax);
  15977. rmin = jmin (rmin, bufMin);
  15978. }
  15979. }
  15980. }
  15981. if (numChannels <= 1)
  15982. {
  15983. rmax = lmax;
  15984. rmin = lmin;
  15985. }
  15986. lowestLeft = lmin / (float) std::numeric_limits<int>::max();
  15987. highestLeft = lmax / (float) std::numeric_limits<int>::max();
  15988. lowestRight = rmin / (float) std::numeric_limits<int>::max();
  15989. highestRight = rmax / (float) std::numeric_limits<int>::max();
  15990. }
  15991. }
  15992. int64 AudioFormatReader::searchForLevel (int64 startSample,
  15993. int64 numSamplesToSearch,
  15994. const double magnitudeRangeMinimum,
  15995. const double magnitudeRangeMaximum,
  15996. const int minimumConsecutiveSamples)
  15997. {
  15998. if (numSamplesToSearch == 0)
  15999. return -1;
  16000. const int bufferSize = 4096;
  16001. MemoryBlock tempSpace (bufferSize * sizeof (int) * 2 + 64);
  16002. int* tempBuffer[3];
  16003. tempBuffer[0] = (int*) tempSpace.getData();
  16004. tempBuffer[1] = ((int*) tempSpace.getData()) + bufferSize;
  16005. tempBuffer[2] = 0;
  16006. int consecutive = 0;
  16007. int64 firstMatchPos = -1;
  16008. jassert (magnitudeRangeMaximum > magnitudeRangeMinimum);
  16009. const double doubleMin = jlimit (0.0, (double) std::numeric_limits<int>::max(), magnitudeRangeMinimum * std::numeric_limits<int>::max());
  16010. const double doubleMax = jlimit (doubleMin, (double) std::numeric_limits<int>::max(), magnitudeRangeMaximum * std::numeric_limits<int>::max());
  16011. const int intMagnitudeRangeMinimum = roundToInt (doubleMin);
  16012. const int intMagnitudeRangeMaximum = roundToInt (doubleMax);
  16013. while (numSamplesToSearch != 0)
  16014. {
  16015. const int numThisTime = (int) jmin (abs64 (numSamplesToSearch), (int64) bufferSize);
  16016. int64 bufferStart = startSample;
  16017. if (numSamplesToSearch < 0)
  16018. bufferStart -= numThisTime;
  16019. if (bufferStart >= (int) lengthInSamples)
  16020. break;
  16021. read ((int**) tempBuffer, 2, bufferStart, numThisTime, false);
  16022. int num = numThisTime;
  16023. while (--num >= 0)
  16024. {
  16025. if (numSamplesToSearch < 0)
  16026. --startSample;
  16027. bool matches = false;
  16028. const int index = (int) (startSample - bufferStart);
  16029. if (usesFloatingPointData)
  16030. {
  16031. const float sample1 = fabsf (((float*) tempBuffer[0]) [index]);
  16032. if (sample1 >= magnitudeRangeMinimum
  16033. && sample1 <= magnitudeRangeMaximum)
  16034. {
  16035. matches = true;
  16036. }
  16037. else if (numChannels > 1)
  16038. {
  16039. const float sample2 = fabsf (((float*) tempBuffer[1]) [index]);
  16040. matches = (sample2 >= magnitudeRangeMinimum
  16041. && sample2 <= magnitudeRangeMaximum);
  16042. }
  16043. }
  16044. else
  16045. {
  16046. const int sample1 = abs (tempBuffer[0] [index]);
  16047. if (sample1 >= intMagnitudeRangeMinimum
  16048. && sample1 <= intMagnitudeRangeMaximum)
  16049. {
  16050. matches = true;
  16051. }
  16052. else if (numChannels > 1)
  16053. {
  16054. const int sample2 = abs (tempBuffer[1][index]);
  16055. matches = (sample2 >= intMagnitudeRangeMinimum
  16056. && sample2 <= intMagnitudeRangeMaximum);
  16057. }
  16058. }
  16059. if (matches)
  16060. {
  16061. if (firstMatchPos < 0)
  16062. firstMatchPos = startSample;
  16063. if (++consecutive >= minimumConsecutiveSamples)
  16064. {
  16065. if (firstMatchPos < 0 || firstMatchPos >= lengthInSamples)
  16066. return -1;
  16067. return firstMatchPos;
  16068. }
  16069. }
  16070. else
  16071. {
  16072. consecutive = 0;
  16073. firstMatchPos = -1;
  16074. }
  16075. if (numSamplesToSearch > 0)
  16076. ++startSample;
  16077. }
  16078. if (numSamplesToSearch > 0)
  16079. numSamplesToSearch -= numThisTime;
  16080. else
  16081. numSamplesToSearch += numThisTime;
  16082. }
  16083. return -1;
  16084. }
  16085. AudioFormatWriter::AudioFormatWriter (OutputStream* const out,
  16086. const String& formatName_,
  16087. const double rate,
  16088. const unsigned int numChannels_,
  16089. const unsigned int bitsPerSample_)
  16090. : sampleRate (rate),
  16091. numChannels (numChannels_),
  16092. bitsPerSample (bitsPerSample_),
  16093. usesFloatingPointData (false),
  16094. output (out),
  16095. formatName (formatName_)
  16096. {
  16097. }
  16098. AudioFormatWriter::~AudioFormatWriter()
  16099. {
  16100. delete output;
  16101. }
  16102. bool AudioFormatWriter::writeFromAudioReader (AudioFormatReader& reader,
  16103. int64 startSample,
  16104. int64 numSamplesToRead)
  16105. {
  16106. const int bufferSize = 16384;
  16107. const int maxChans = 128;
  16108. AudioSampleBuffer tempBuffer (reader.numChannels, bufferSize);
  16109. int* buffers [maxChans];
  16110. for (int i = maxChans; --i >= 0;)
  16111. buffers[i] = 0;
  16112. if (numSamplesToRead < 0)
  16113. numSamplesToRead = reader.lengthInSamples;
  16114. while (numSamplesToRead > 0)
  16115. {
  16116. const int numToDo = (int) jmin (numSamplesToRead, (int64) bufferSize);
  16117. for (int i = tempBuffer.getNumChannels(); --i >= 0;)
  16118. buffers[i] = (int*) tempBuffer.getSampleData (i, 0);
  16119. if (! reader.read (buffers, maxChans, startSample, numToDo, false))
  16120. return false;
  16121. if (reader.usesFloatingPointData != isFloatingPoint())
  16122. {
  16123. int** bufferChan = buffers;
  16124. while (*bufferChan != 0)
  16125. {
  16126. int* b = *bufferChan++;
  16127. if (isFloatingPoint())
  16128. {
  16129. // int -> float
  16130. const double factor = 1.0 / std::numeric_limits<int>::max();
  16131. for (int i = 0; i < numToDo; ++i)
  16132. ((float*) b)[i] = (float) (factor * b[i]);
  16133. }
  16134. else
  16135. {
  16136. // float -> int
  16137. for (int i = 0; i < numToDo; ++i)
  16138. {
  16139. const double samp = *(const float*) b;
  16140. if (samp <= -1.0)
  16141. *b++ = std::numeric_limits<int>::min();
  16142. else if (samp >= 1.0)
  16143. *b++ = std::numeric_limits<int>::max();
  16144. else
  16145. *b++ = roundToInt (std::numeric_limits<int>::max() * samp);
  16146. }
  16147. }
  16148. }
  16149. }
  16150. if (! write ((const int**) buffers, numToDo))
  16151. return false;
  16152. numSamplesToRead -= numToDo;
  16153. startSample += numToDo;
  16154. }
  16155. return true;
  16156. }
  16157. bool AudioFormatWriter::writeFromAudioSource (AudioSource& source,
  16158. int numSamplesToRead,
  16159. const int samplesPerBlock)
  16160. {
  16161. const int maxChans = 128;
  16162. AudioSampleBuffer tempBuffer (getNumChannels(), samplesPerBlock);
  16163. int* buffers [maxChans];
  16164. while (numSamplesToRead > 0)
  16165. {
  16166. const int numToDo = jmin (numSamplesToRead, samplesPerBlock);
  16167. AudioSourceChannelInfo info;
  16168. info.buffer = &tempBuffer;
  16169. info.startSample = 0;
  16170. info.numSamples = numToDo;
  16171. info.clearActiveBufferRegion();
  16172. source.getNextAudioBlock (info);
  16173. int i;
  16174. for (i = maxChans; --i >= 0;)
  16175. buffers[i] = 0;
  16176. for (i = tempBuffer.getNumChannels(); --i >= 0;)
  16177. buffers[i] = (int*) tempBuffer.getSampleData (i, 0);
  16178. if (! isFloatingPoint())
  16179. {
  16180. int** bufferChan = buffers;
  16181. while (*bufferChan != 0)
  16182. {
  16183. int* b = *bufferChan++;
  16184. // float -> int
  16185. for (int j = numToDo; --j >= 0;)
  16186. {
  16187. const double samp = *(const float*) b;
  16188. if (samp <= -1.0)
  16189. *b++ = std::numeric_limits<int>::min();
  16190. else if (samp >= 1.0)
  16191. *b++ = std::numeric_limits<int>::max();
  16192. else
  16193. *b++ = roundToInt (std::numeric_limits<int>::max() * samp);
  16194. }
  16195. }
  16196. }
  16197. if (! write ((const int**) buffers, numToDo))
  16198. return false;
  16199. numSamplesToRead -= numToDo;
  16200. }
  16201. return true;
  16202. }
  16203. AudioFormat::AudioFormat (const String& name,
  16204. const tchar** const extensions)
  16205. : formatName (name),
  16206. fileExtensions (extensions)
  16207. {
  16208. }
  16209. AudioFormat::~AudioFormat()
  16210. {
  16211. }
  16212. const String& AudioFormat::getFormatName() const
  16213. {
  16214. return formatName;
  16215. }
  16216. const StringArray& AudioFormat::getFileExtensions() const
  16217. {
  16218. return fileExtensions;
  16219. }
  16220. bool AudioFormat::canHandleFile (const File& f)
  16221. {
  16222. for (int i = 0; i < fileExtensions.size(); ++i)
  16223. if (f.hasFileExtension (fileExtensions[i]))
  16224. return true;
  16225. return false;
  16226. }
  16227. bool AudioFormat::isCompressed()
  16228. {
  16229. return false;
  16230. }
  16231. const StringArray AudioFormat::getQualityOptions()
  16232. {
  16233. return StringArray();
  16234. }
  16235. END_JUCE_NAMESPACE
  16236. /*** End of inlined file: juce_AudioFormat.cpp ***/
  16237. /*** Start of inlined file: juce_AudioFormatManager.cpp ***/
  16238. BEGIN_JUCE_NAMESPACE
  16239. AudioFormatManager::AudioFormatManager()
  16240. : defaultFormatIndex (0)
  16241. {
  16242. }
  16243. AudioFormatManager::~AudioFormatManager()
  16244. {
  16245. clearFormats();
  16246. clearSingletonInstance();
  16247. }
  16248. juce_ImplementSingleton (AudioFormatManager);
  16249. void AudioFormatManager::registerFormat (AudioFormat* newFormat,
  16250. const bool makeThisTheDefaultFormat)
  16251. {
  16252. jassert (newFormat != 0);
  16253. if (newFormat != 0)
  16254. {
  16255. #ifdef JUCE_DEBUG
  16256. for (int i = getNumKnownFormats(); --i >= 0;)
  16257. {
  16258. if (getKnownFormat (i)->getFormatName() == newFormat->getFormatName())
  16259. {
  16260. jassertfalse // trying to add the same format twice!
  16261. }
  16262. }
  16263. #endif
  16264. if (makeThisTheDefaultFormat)
  16265. defaultFormatIndex = knownFormats.size();
  16266. knownFormats.add (newFormat);
  16267. }
  16268. }
  16269. void AudioFormatManager::registerBasicFormats()
  16270. {
  16271. #if JUCE_MAC
  16272. registerFormat (new AiffAudioFormat(), true);
  16273. registerFormat (new WavAudioFormat(), false);
  16274. #else
  16275. registerFormat (new WavAudioFormat(), true);
  16276. registerFormat (new AiffAudioFormat(), false);
  16277. #endif
  16278. #if JUCE_USE_FLAC
  16279. registerFormat (new FlacAudioFormat(), false);
  16280. #endif
  16281. #if JUCE_USE_OGGVORBIS
  16282. registerFormat (new OggVorbisAudioFormat(), false);
  16283. #endif
  16284. }
  16285. void AudioFormatManager::clearFormats()
  16286. {
  16287. for (int i = getNumKnownFormats(); --i >= 0;)
  16288. delete getKnownFormat(i);
  16289. knownFormats.clear();
  16290. defaultFormatIndex = 0;
  16291. }
  16292. int AudioFormatManager::getNumKnownFormats() const
  16293. {
  16294. return knownFormats.size();
  16295. }
  16296. AudioFormat* AudioFormatManager::getKnownFormat (const int index) const
  16297. {
  16298. return (AudioFormat*) knownFormats [index];
  16299. }
  16300. AudioFormat* AudioFormatManager::getDefaultFormat() const
  16301. {
  16302. return getKnownFormat (defaultFormatIndex);
  16303. }
  16304. AudioFormat* AudioFormatManager::findFormatForFileExtension (const String& fileExtension) const
  16305. {
  16306. String e (fileExtension);
  16307. if (! e.startsWithChar (T('.')))
  16308. e = T(".") + e;
  16309. for (int i = 0; i < getNumKnownFormats(); ++i)
  16310. if (getKnownFormat(i)->getFileExtensions().contains (e, true))
  16311. return getKnownFormat(i);
  16312. return 0;
  16313. }
  16314. const String AudioFormatManager::getWildcardForAllFormats() const
  16315. {
  16316. StringArray allExtensions;
  16317. int i;
  16318. for (i = 0; i < getNumKnownFormats(); ++i)
  16319. allExtensions.addArray (getKnownFormat (i)->getFileExtensions());
  16320. allExtensions.trim();
  16321. allExtensions.removeEmptyStrings();
  16322. String s;
  16323. for (i = 0; i < allExtensions.size(); ++i)
  16324. {
  16325. s << T('*');
  16326. if (! allExtensions[i].startsWithChar (T('.')))
  16327. s << T('.');
  16328. s << allExtensions[i];
  16329. if (i < allExtensions.size() - 1)
  16330. s << T(';');
  16331. }
  16332. return s;
  16333. }
  16334. AudioFormatReader* AudioFormatManager::createReaderFor (const File& file)
  16335. {
  16336. // you need to actually register some formats before the manager can
  16337. // use them to open a file!
  16338. jassert (knownFormats.size() > 0);
  16339. for (int i = 0; i < getNumKnownFormats(); ++i)
  16340. {
  16341. AudioFormat* const af = getKnownFormat(i);
  16342. if (af->canHandleFile (file))
  16343. {
  16344. InputStream* const in = file.createInputStream();
  16345. if (in != 0)
  16346. {
  16347. AudioFormatReader* const r = af->createReaderFor (in, true);
  16348. if (r != 0)
  16349. return r;
  16350. }
  16351. }
  16352. }
  16353. return 0;
  16354. }
  16355. AudioFormatReader* AudioFormatManager::createReaderFor (InputStream* audioFileStream)
  16356. {
  16357. // you need to actually register some formats before the manager can
  16358. // use them to open a file!
  16359. jassert (knownFormats.size() > 0);
  16360. ScopedPointer <InputStream> in (audioFileStream);
  16361. if (in != 0)
  16362. {
  16363. const int64 originalStreamPos = in->getPosition();
  16364. for (int i = 0; i < getNumKnownFormats(); ++i)
  16365. {
  16366. AudioFormatReader* const r = getKnownFormat(i)->createReaderFor (in, false);
  16367. if (r != 0)
  16368. {
  16369. in.release();
  16370. return r;
  16371. }
  16372. in->setPosition (originalStreamPos);
  16373. // the stream that is passed-in must be capable of being repositioned so
  16374. // that all the formats can have a go at opening it.
  16375. jassert (in->getPosition() == originalStreamPos);
  16376. }
  16377. }
  16378. return 0;
  16379. }
  16380. END_JUCE_NAMESPACE
  16381. /*** End of inlined file: juce_AudioFormatManager.cpp ***/
  16382. /*** Start of inlined file: juce_AudioSubsectionReader.cpp ***/
  16383. BEGIN_JUCE_NAMESPACE
  16384. AudioSubsectionReader::AudioSubsectionReader (AudioFormatReader* const source_,
  16385. const int64 startSample_,
  16386. const int64 length_,
  16387. const bool deleteSourceWhenDeleted_)
  16388. : AudioFormatReader (0, source_->getFormatName()),
  16389. source (source_),
  16390. startSample (startSample_),
  16391. deleteSourceWhenDeleted (deleteSourceWhenDeleted_)
  16392. {
  16393. length = jmin (jmax ((int64) 0, source->lengthInSamples - startSample), length_);
  16394. sampleRate = source->sampleRate;
  16395. bitsPerSample = source->bitsPerSample;
  16396. lengthInSamples = length;
  16397. numChannels = source->numChannels;
  16398. usesFloatingPointData = source->usesFloatingPointData;
  16399. }
  16400. AudioSubsectionReader::~AudioSubsectionReader()
  16401. {
  16402. if (deleteSourceWhenDeleted)
  16403. delete source;
  16404. }
  16405. bool AudioSubsectionReader::readSamples (int** destSamples, int numDestChannels, int startOffsetInDestBuffer,
  16406. int64 startSampleInFile, int numSamples)
  16407. {
  16408. if (startSampleInFile + numSamples > length)
  16409. {
  16410. for (int i = numDestChannels; --i >= 0;)
  16411. if (destSamples[i] != 0)
  16412. zeromem (destSamples[i], sizeof (int) * numSamples);
  16413. numSamples = jmin (numSamples, (int) (length - startSampleInFile));
  16414. if (numSamples <= 0)
  16415. return true;
  16416. }
  16417. return source->readSamples (destSamples, numDestChannels, startOffsetInDestBuffer,
  16418. startSampleInFile + startSample, numSamples);
  16419. }
  16420. void AudioSubsectionReader::readMaxLevels (int64 startSampleInFile,
  16421. int64 numSamples,
  16422. float& lowestLeft,
  16423. float& highestLeft,
  16424. float& lowestRight,
  16425. float& highestRight)
  16426. {
  16427. startSampleInFile = jmax ((int64) 0, startSampleInFile);
  16428. numSamples = jmax ((int64) 0, jmin (numSamples, length - startSampleInFile));
  16429. source->readMaxLevels (startSampleInFile + startSample,
  16430. numSamples,
  16431. lowestLeft,
  16432. highestLeft,
  16433. lowestRight,
  16434. highestRight);
  16435. }
  16436. END_JUCE_NAMESPACE
  16437. /*** End of inlined file: juce_AudioSubsectionReader.cpp ***/
  16438. /*** Start of inlined file: juce_AudioThumbnail.cpp ***/
  16439. BEGIN_JUCE_NAMESPACE
  16440. const int timeBeforeDeletingReader = 2000;
  16441. struct AudioThumbnailDataFormat
  16442. {
  16443. char thumbnailMagic[4];
  16444. int samplesPerThumbSample;
  16445. int64 totalSamples; // source samples
  16446. int64 numFinishedSamples; // source samples
  16447. int numThumbnailSamples;
  16448. int numChannels;
  16449. int sampleRate;
  16450. char future[16];
  16451. char data[1];
  16452. void swapEndiannessIfNeeded() throw()
  16453. {
  16454. #if JUCE_BIG_ENDIAN
  16455. flip (samplesPerThumbSample);
  16456. flip (totalSamples);
  16457. flip (numFinishedSamples);
  16458. flip (numThumbnailSamples);
  16459. flip (numChannels);
  16460. flip (sampleRate);
  16461. #endif
  16462. }
  16463. private:
  16464. #if JUCE_BIG_ENDIAN
  16465. static void flip (int& n) { n = (int) ByteOrder::swap ((uint32) n); }
  16466. static void flip (int64& n) { n = (int64) ByteOrder::swap ((uint64) n); }
  16467. #endif
  16468. };
  16469. AudioThumbnail::AudioThumbnail (const int orginalSamplesPerThumbnailSample_,
  16470. AudioFormatManager& formatManagerToUse_,
  16471. AudioThumbnailCache& cacheToUse)
  16472. : formatManagerToUse (formatManagerToUse_),
  16473. cache (cacheToUse),
  16474. orginalSamplesPerThumbnailSample (orginalSamplesPerThumbnailSample_)
  16475. {
  16476. clear();
  16477. }
  16478. AudioThumbnail::~AudioThumbnail()
  16479. {
  16480. cache.removeThumbnail (this);
  16481. const ScopedLock sl (readerLock);
  16482. reader = 0;
  16483. }
  16484. void AudioThumbnail::setSource (InputSource* const newSource)
  16485. {
  16486. cache.removeThumbnail (this);
  16487. timerCallback(); // stops the timer and deletes the reader
  16488. source = newSource;
  16489. clear();
  16490. if (newSource != 0
  16491. && ! (cache.loadThumb (*this, newSource->hashCode())
  16492. && isFullyLoaded()))
  16493. {
  16494. {
  16495. const ScopedLock sl (readerLock);
  16496. reader = createReader();
  16497. }
  16498. if (reader != 0)
  16499. {
  16500. initialiseFromAudioFile (*reader);
  16501. cache.addThumbnail (this);
  16502. }
  16503. }
  16504. sendChangeMessage (this);
  16505. }
  16506. bool AudioThumbnail::useTimeSlice()
  16507. {
  16508. const ScopedLock sl (readerLock);
  16509. if (isFullyLoaded())
  16510. {
  16511. if (reader != 0)
  16512. startTimer (timeBeforeDeletingReader);
  16513. cache.removeThumbnail (this);
  16514. return false;
  16515. }
  16516. if (reader == 0)
  16517. reader = createReader();
  16518. if (reader != 0)
  16519. {
  16520. readNextBlockFromAudioFile (*reader);
  16521. stopTimer();
  16522. sendChangeMessage (this);
  16523. const bool justFinished = isFullyLoaded();
  16524. if (justFinished)
  16525. cache.storeThumb (*this, source->hashCode());
  16526. return ! justFinished;
  16527. }
  16528. return false;
  16529. }
  16530. AudioFormatReader* AudioThumbnail::createReader() const
  16531. {
  16532. if (source != 0)
  16533. {
  16534. InputStream* const audioFileStream = source->createInputStream();
  16535. if (audioFileStream != 0)
  16536. return formatManagerToUse.createReaderFor (audioFileStream);
  16537. }
  16538. return 0;
  16539. }
  16540. void AudioThumbnail::timerCallback()
  16541. {
  16542. stopTimer();
  16543. const ScopedLock sl (readerLock);
  16544. reader = 0;
  16545. }
  16546. void AudioThumbnail::clear()
  16547. {
  16548. data.setSize (sizeof (AudioThumbnailDataFormat) + 3);
  16549. AudioThumbnailDataFormat* const d = (AudioThumbnailDataFormat*) data.getData();
  16550. d->thumbnailMagic[0] = 'j';
  16551. d->thumbnailMagic[1] = 'a';
  16552. d->thumbnailMagic[2] = 't';
  16553. d->thumbnailMagic[3] = 'm';
  16554. d->samplesPerThumbSample = orginalSamplesPerThumbnailSample;
  16555. d->totalSamples = 0;
  16556. d->numFinishedSamples = 0;
  16557. d->numThumbnailSamples = 0;
  16558. d->numChannels = 0;
  16559. d->sampleRate = 0;
  16560. numSamplesCached = 0;
  16561. cacheNeedsRefilling = true;
  16562. }
  16563. void AudioThumbnail::loadFrom (InputStream& input)
  16564. {
  16565. const ScopedLock sl (readerLock);
  16566. data.setSize (0);
  16567. input.readIntoMemoryBlock (data);
  16568. AudioThumbnailDataFormat* const d = (AudioThumbnailDataFormat*) data.getData();
  16569. d->swapEndiannessIfNeeded();
  16570. if (! (d->thumbnailMagic[0] == 'j'
  16571. && d->thumbnailMagic[1] == 'a'
  16572. && d->thumbnailMagic[2] == 't'
  16573. && d->thumbnailMagic[3] == 'm'))
  16574. {
  16575. clear();
  16576. }
  16577. numSamplesCached = 0;
  16578. cacheNeedsRefilling = true;
  16579. }
  16580. void AudioThumbnail::saveTo (OutputStream& output) const
  16581. {
  16582. AudioThumbnailDataFormat* const d = (AudioThumbnailDataFormat*) data.getData();
  16583. d->swapEndiannessIfNeeded();
  16584. output.write (data.getData(), (int) data.getSize());
  16585. d->swapEndiannessIfNeeded();
  16586. }
  16587. bool AudioThumbnail::initialiseFromAudioFile (AudioFormatReader& fileReader)
  16588. {
  16589. AudioThumbnailDataFormat* d = (AudioThumbnailDataFormat*) data.getData();
  16590. d->totalSamples = fileReader.lengthInSamples;
  16591. d->numChannels = jmin ((uint32) 2, fileReader.numChannels);
  16592. d->numFinishedSamples = 0;
  16593. d->sampleRate = roundToInt (fileReader.sampleRate);
  16594. d->numThumbnailSamples = (int) (d->totalSamples / d->samplesPerThumbSample) + 1;
  16595. data.setSize (sizeof (AudioThumbnailDataFormat) + 3 + d->numThumbnailSamples * d->numChannels * 2);
  16596. d = (AudioThumbnailDataFormat*) data.getData();
  16597. zeromem (&(d->data[0]), d->numThumbnailSamples * d->numChannels * 2);
  16598. return d->totalSamples > 0;
  16599. }
  16600. bool AudioThumbnail::readNextBlockFromAudioFile (AudioFormatReader& fileReader)
  16601. {
  16602. AudioThumbnailDataFormat* const d = (AudioThumbnailDataFormat*) data.getData();
  16603. if (d->numFinishedSamples < d->totalSamples)
  16604. {
  16605. const int numToDo = (int) jmin ((int64) 65536, d->totalSamples - d->numFinishedSamples);
  16606. generateSection (fileReader,
  16607. d->numFinishedSamples,
  16608. numToDo);
  16609. d->numFinishedSamples += numToDo;
  16610. }
  16611. cacheNeedsRefilling = true;
  16612. return (d->numFinishedSamples < d->totalSamples);
  16613. }
  16614. int AudioThumbnail::getNumChannels() const throw()
  16615. {
  16616. const AudioThumbnailDataFormat* const d = (const AudioThumbnailDataFormat*) data.getData();
  16617. jassert (d != 0);
  16618. return d->numChannels;
  16619. }
  16620. double AudioThumbnail::getTotalLength() const throw()
  16621. {
  16622. const AudioThumbnailDataFormat* const d = (const AudioThumbnailDataFormat*) data.getData();
  16623. jassert (d != 0);
  16624. if (d->sampleRate > 0)
  16625. return d->totalSamples / (double)d->sampleRate;
  16626. else
  16627. return 0.0;
  16628. }
  16629. void AudioThumbnail::generateSection (AudioFormatReader& fileReader,
  16630. int64 startSample,
  16631. int numSamples)
  16632. {
  16633. AudioThumbnailDataFormat* const d = (AudioThumbnailDataFormat*) data.getData();
  16634. jassert (d != 0);
  16635. int firstDataPos = (int) (startSample / d->samplesPerThumbSample);
  16636. int lastDataPos = (int) ((startSample + numSamples) / d->samplesPerThumbSample);
  16637. char* l = getChannelData (0);
  16638. char* r = getChannelData (1);
  16639. for (int i = firstDataPos; i < lastDataPos; ++i)
  16640. {
  16641. const int sourceStart = i * d->samplesPerThumbSample;
  16642. const int sourceEnd = sourceStart + d->samplesPerThumbSample;
  16643. float lowestLeft, highestLeft, lowestRight, highestRight;
  16644. fileReader.readMaxLevels (sourceStart,
  16645. sourceEnd - sourceStart,
  16646. lowestLeft,
  16647. highestLeft,
  16648. lowestRight,
  16649. highestRight);
  16650. int n = i * 2;
  16651. if (r != 0)
  16652. {
  16653. l [n] = (char) jlimit (-128.0f, 127.0f, lowestLeft * 127.0f);
  16654. r [n++] = (char) jlimit (-128.0f, 127.0f, lowestRight * 127.0f);
  16655. l [n] = (char) jlimit (-128.0f, 127.0f, highestLeft * 127.0f);
  16656. r [n++] = (char) jlimit (-128.0f, 127.0f, highestRight * 127.0f);
  16657. }
  16658. else
  16659. {
  16660. l [n++] = (char) jlimit (-128.0f, 127.0f, lowestLeft * 127.0f);
  16661. l [n++] = (char) jlimit (-128.0f, 127.0f, highestLeft * 127.0f);
  16662. }
  16663. }
  16664. }
  16665. char* AudioThumbnail::getChannelData (int channel) const
  16666. {
  16667. AudioThumbnailDataFormat* const d = (AudioThumbnailDataFormat*) data.getData();
  16668. jassert (d != 0);
  16669. if (channel >= 0 && channel < d->numChannels)
  16670. return d->data + (channel * 2 * d->numThumbnailSamples);
  16671. return 0;
  16672. }
  16673. bool AudioThumbnail::isFullyLoaded() const throw()
  16674. {
  16675. const AudioThumbnailDataFormat* const d = (const AudioThumbnailDataFormat*) data.getData();
  16676. jassert (d != 0);
  16677. return d->numFinishedSamples >= d->totalSamples;
  16678. }
  16679. void AudioThumbnail::refillCache (const int numSamples,
  16680. double startTime,
  16681. const double timePerPixel)
  16682. {
  16683. const AudioThumbnailDataFormat* const d = (const AudioThumbnailDataFormat*) data.getData();
  16684. jassert (d != 0);
  16685. if (numSamples <= 0
  16686. || timePerPixel <= 0.0
  16687. || d->sampleRate <= 0)
  16688. {
  16689. numSamplesCached = 0;
  16690. cacheNeedsRefilling = true;
  16691. return;
  16692. }
  16693. if (numSamples == numSamplesCached
  16694. && numChannelsCached == d->numChannels
  16695. && startTime == cachedStart
  16696. && timePerPixel == cachedTimePerPixel
  16697. && ! cacheNeedsRefilling)
  16698. {
  16699. return;
  16700. }
  16701. numSamplesCached = numSamples;
  16702. numChannelsCached = d->numChannels;
  16703. cachedStart = startTime;
  16704. cachedTimePerPixel = timePerPixel;
  16705. cachedLevels.ensureSize (2 * numChannelsCached * numSamples);
  16706. const bool needExtraDetail = (timePerPixel * d->sampleRate <= d->samplesPerThumbSample);
  16707. const ScopedLock sl (readerLock);
  16708. cacheNeedsRefilling = false;
  16709. if (needExtraDetail && reader == 0)
  16710. reader = createReader();
  16711. if (reader != 0 && timePerPixel * d->sampleRate <= d->samplesPerThumbSample)
  16712. {
  16713. startTimer (timeBeforeDeletingReader);
  16714. char* cacheData = (char*) cachedLevels.getData();
  16715. int sample = roundToInt (startTime * d->sampleRate);
  16716. for (int i = numSamples; --i >= 0;)
  16717. {
  16718. const int nextSample = roundToInt ((startTime + timePerPixel) * d->sampleRate);
  16719. if (sample >= 0)
  16720. {
  16721. if (sample >= reader->lengthInSamples)
  16722. break;
  16723. float lmin, lmax, rmin, rmax;
  16724. reader->readMaxLevels (sample,
  16725. jmax (1, nextSample - sample),
  16726. lmin, lmax, rmin, rmax);
  16727. cacheData[0] = (char) jlimit (-128, 127, roundFloatToInt (lmin * 127.0f));
  16728. cacheData[1] = (char) jlimit (-128, 127, roundFloatToInt (lmax * 127.0f));
  16729. if (numChannelsCached > 1)
  16730. {
  16731. cacheData[2] = (char) jlimit (-128, 127, roundFloatToInt (rmin * 127.0f));
  16732. cacheData[3] = (char) jlimit (-128, 127, roundFloatToInt (rmax * 127.0f));
  16733. }
  16734. cacheData += 2 * numChannelsCached;
  16735. }
  16736. startTime += timePerPixel;
  16737. sample = nextSample;
  16738. }
  16739. }
  16740. else
  16741. {
  16742. for (int channelNum = 0; channelNum < numChannelsCached; ++channelNum)
  16743. {
  16744. char* const channelData = getChannelData (channelNum);
  16745. char* cacheData = ((char*) cachedLevels.getData()) + channelNum * 2;
  16746. const double timeToThumbSampleFactor = d->sampleRate / (double) d->samplesPerThumbSample;
  16747. startTime = cachedStart;
  16748. int sample = roundToInt (startTime * timeToThumbSampleFactor);
  16749. const int numFinished = (int) (d->numFinishedSamples / d->samplesPerThumbSample);
  16750. for (int i = numSamples; --i >= 0;)
  16751. {
  16752. const int nextSample = roundToInt ((startTime + timePerPixel) * timeToThumbSampleFactor);
  16753. if (sample >= 0 && channelData != 0)
  16754. {
  16755. char mx = -128;
  16756. char mn = 127;
  16757. while (sample <= nextSample)
  16758. {
  16759. if (sample >= numFinished)
  16760. break;
  16761. const int n = sample << 1;
  16762. const char sampMin = channelData [n];
  16763. const char sampMax = channelData [n + 1];
  16764. if (sampMin < mn)
  16765. mn = sampMin;
  16766. if (sampMax > mx)
  16767. mx = sampMax;
  16768. ++sample;
  16769. }
  16770. if (mn <= mx)
  16771. {
  16772. cacheData[0] = mn;
  16773. cacheData[1] = mx;
  16774. }
  16775. else
  16776. {
  16777. cacheData[0] = 1;
  16778. cacheData[1] = 0;
  16779. }
  16780. }
  16781. else
  16782. {
  16783. cacheData[0] = 1;
  16784. cacheData[1] = 0;
  16785. }
  16786. cacheData += numChannelsCached * 2;
  16787. startTime += timePerPixel;
  16788. sample = nextSample;
  16789. }
  16790. }
  16791. }
  16792. }
  16793. void AudioThumbnail::drawChannel (Graphics& g,
  16794. int x, int y, int w, int h,
  16795. double startTime,
  16796. double endTime,
  16797. int channelNum,
  16798. const float verticalZoomFactor)
  16799. {
  16800. refillCache (w, startTime, (endTime - startTime) / w);
  16801. if (numSamplesCached >= w
  16802. && channelNum >= 0
  16803. && channelNum < numChannelsCached)
  16804. {
  16805. const float topY = (float) y;
  16806. const float bottomY = topY + h;
  16807. const float midY = topY + h * 0.5f;
  16808. const float vscale = verticalZoomFactor * h / 256.0f;
  16809. const Rectangle<int> clip (g.getClipBounds());
  16810. const int skipLeft = jlimit (0, w, clip.getX() - x);
  16811. w -= skipLeft;
  16812. x += skipLeft;
  16813. const char* cacheData = ((const char*) cachedLevels.getData())
  16814. + (channelNum << 1)
  16815. + skipLeft * (numChannelsCached << 1);
  16816. while (--w >= 0)
  16817. {
  16818. const char mn = cacheData[0];
  16819. const char mx = cacheData[1];
  16820. cacheData += numChannelsCached << 1;
  16821. if (mn <= mx) // if the wrong way round, signifies that the sample's not yet known
  16822. g.drawLine ((float) x, jmax (midY - mx * vscale - 0.3f, topY),
  16823. (float) x, jmin (midY - mn * vscale + 0.3f, bottomY));
  16824. ++x;
  16825. if (x >= clip.getRight())
  16826. break;
  16827. }
  16828. }
  16829. }
  16830. END_JUCE_NAMESPACE
  16831. /*** End of inlined file: juce_AudioThumbnail.cpp ***/
  16832. /*** Start of inlined file: juce_AudioThumbnailCache.cpp ***/
  16833. BEGIN_JUCE_NAMESPACE
  16834. struct ThumbnailCacheEntry
  16835. {
  16836. int64 hash;
  16837. uint32 lastUsed;
  16838. MemoryBlock data;
  16839. juce_UseDebuggingNewOperator
  16840. };
  16841. AudioThumbnailCache::AudioThumbnailCache (const int maxNumThumbsToStore_)
  16842. : TimeSliceThread (T("thumb cache")),
  16843. maxNumThumbsToStore (maxNumThumbsToStore_)
  16844. {
  16845. startThread (2);
  16846. }
  16847. AudioThumbnailCache::~AudioThumbnailCache()
  16848. {
  16849. }
  16850. bool AudioThumbnailCache::loadThumb (AudioThumbnail& thumb, const int64 hashCode)
  16851. {
  16852. for (int i = thumbs.size(); --i >= 0;)
  16853. {
  16854. if (thumbs[i]->hash == hashCode)
  16855. {
  16856. MemoryInputStream in ((const char*) thumbs[i]->data.getData(),
  16857. thumbs[i]->data.getSize(),
  16858. false);
  16859. thumb.loadFrom (in);
  16860. thumbs[i]->lastUsed = Time::getMillisecondCounter();
  16861. return true;
  16862. }
  16863. }
  16864. return false;
  16865. }
  16866. void AudioThumbnailCache::storeThumb (const AudioThumbnail& thumb,
  16867. const int64 hashCode)
  16868. {
  16869. MemoryOutputStream out;
  16870. thumb.saveTo (out);
  16871. ThumbnailCacheEntry* te = 0;
  16872. for (int i = thumbs.size(); --i >= 0;)
  16873. {
  16874. if (thumbs[i]->hash == hashCode)
  16875. {
  16876. te = thumbs[i];
  16877. break;
  16878. }
  16879. }
  16880. if (te == 0)
  16881. {
  16882. te = new ThumbnailCacheEntry();
  16883. te->hash = hashCode;
  16884. if (thumbs.size() < maxNumThumbsToStore)
  16885. {
  16886. thumbs.add (te);
  16887. }
  16888. else
  16889. {
  16890. int oldest = 0;
  16891. unsigned int oldestTime = Time::getMillisecondCounter() + 1;
  16892. int i;
  16893. for (i = thumbs.size(); --i >= 0;)
  16894. if (thumbs[i]->lastUsed < oldestTime)
  16895. oldest = i;
  16896. thumbs.set (i, te);
  16897. }
  16898. }
  16899. te->lastUsed = Time::getMillisecondCounter();
  16900. te->data.setSize (0);
  16901. te->data.append (out.getData(), out.getDataSize());
  16902. }
  16903. void AudioThumbnailCache::clear()
  16904. {
  16905. thumbs.clear();
  16906. }
  16907. void AudioThumbnailCache::addThumbnail (AudioThumbnail* const thumb)
  16908. {
  16909. addTimeSliceClient (thumb);
  16910. }
  16911. void AudioThumbnailCache::removeThumbnail (AudioThumbnail* const thumb)
  16912. {
  16913. removeTimeSliceClient (thumb);
  16914. }
  16915. END_JUCE_NAMESPACE
  16916. /*** End of inlined file: juce_AudioThumbnailCache.cpp ***/
  16917. /*** Start of inlined file: juce_QuickTimeAudioFormat.cpp ***/
  16918. #if JUCE_QUICKTIME && ! (JUCE_64BIT || JUCE_IPHONE)
  16919. #if ! JUCE_WINDOWS
  16920. #include <QuickTime/Movies.h>
  16921. #include <QuickTime/QTML.h>
  16922. #include <QuickTime/QuickTimeComponents.h>
  16923. #include <QuickTime/MediaHandlers.h>
  16924. #include <QuickTime/ImageCodec.h>
  16925. #else
  16926. #if JUCE_MSVC
  16927. #pragma warning (push)
  16928. #pragma warning (disable : 4100)
  16929. #endif
  16930. #include <Movies.h>
  16931. #include <QTML.h>
  16932. #include <QuickTimeComponents.h>
  16933. #include <MediaHandlers.h>
  16934. #include <ImageCodec.h>
  16935. #if JUCE_MSVC
  16936. #pragma warning (pop)
  16937. #endif
  16938. #endif
  16939. BEGIN_JUCE_NAMESPACE
  16940. bool juce_OpenQuickTimeMovieFromStream (InputStream* input, Movie& movie, Handle& dataHandle);
  16941. static const char* const quickTimeFormatName = "QuickTime file";
  16942. static const tchar* const quickTimeExtensions[] = { T(".mov"), T(".mp3"), T(".mp4"), 0 };
  16943. class QTAudioReader : public AudioFormatReader
  16944. {
  16945. public:
  16946. QTAudioReader (InputStream* const input_, const int trackNum_)
  16947. : AudioFormatReader (input_, TRANS (quickTimeFormatName)),
  16948. ok (false),
  16949. movie (0),
  16950. trackNum (trackNum_),
  16951. lastSampleRead (0),
  16952. lastThreadId (0),
  16953. extractor (0),
  16954. dataHandle (0)
  16955. {
  16956. bufferList.calloc (256, 1);
  16957. #ifdef WIN32
  16958. if (InitializeQTML (0) != noErr)
  16959. return;
  16960. #endif
  16961. if (EnterMovies() != noErr)
  16962. return;
  16963. bool opened = juce_OpenQuickTimeMovieFromStream (input_, movie, dataHandle);
  16964. if (! opened)
  16965. return;
  16966. {
  16967. const int numTracks = GetMovieTrackCount (movie);
  16968. int trackCount = 0;
  16969. for (int i = 1; i <= numTracks; ++i)
  16970. {
  16971. track = GetMovieIndTrack (movie, i);
  16972. media = GetTrackMedia (track);
  16973. OSType mediaType;
  16974. GetMediaHandlerDescription (media, &mediaType, 0, 0);
  16975. if (mediaType == SoundMediaType
  16976. && trackCount++ == trackNum_)
  16977. {
  16978. ok = true;
  16979. break;
  16980. }
  16981. }
  16982. }
  16983. if (! ok)
  16984. return;
  16985. ok = false;
  16986. lengthInSamples = GetMediaDecodeDuration (media);
  16987. usesFloatingPointData = false;
  16988. samplesPerFrame = (int) (GetMediaDecodeDuration (media) / GetMediaSampleCount (media));
  16989. trackUnitsPerFrame = GetMovieTimeScale (movie) * samplesPerFrame
  16990. / GetMediaTimeScale (media);
  16991. OSStatus err = MovieAudioExtractionBegin (movie, 0, &extractor);
  16992. unsigned long output_layout_size;
  16993. err = MovieAudioExtractionGetPropertyInfo (extractor,
  16994. kQTPropertyClass_MovieAudioExtraction_Audio,
  16995. kQTMovieAudioExtractionAudioPropertyID_AudioChannelLayout,
  16996. 0, &output_layout_size, 0);
  16997. if (err != noErr)
  16998. return;
  16999. HeapBlock <AudioChannelLayout> qt_audio_channel_layout;
  17000. qt_audio_channel_layout.calloc (output_layout_size, 1);
  17001. err = MovieAudioExtractionGetProperty (extractor,
  17002. kQTPropertyClass_MovieAudioExtraction_Audio,
  17003. kQTMovieAudioExtractionAudioPropertyID_AudioChannelLayout,
  17004. output_layout_size, qt_audio_channel_layout, 0);
  17005. qt_audio_channel_layout[0].mChannelLayoutTag = kAudioChannelLayoutTag_Stereo;
  17006. err = MovieAudioExtractionSetProperty (extractor,
  17007. kQTPropertyClass_MovieAudioExtraction_Audio,
  17008. kQTMovieAudioExtractionAudioPropertyID_AudioChannelLayout,
  17009. output_layout_size,
  17010. qt_audio_channel_layout);
  17011. err = MovieAudioExtractionGetProperty (extractor,
  17012. kQTPropertyClass_MovieAudioExtraction_Audio,
  17013. kQTMovieAudioExtractionAudioPropertyID_AudioStreamBasicDescription,
  17014. sizeof (inputStreamDesc),
  17015. &inputStreamDesc, 0);
  17016. if (err != noErr)
  17017. return;
  17018. inputStreamDesc.mFormatFlags = kAudioFormatFlagIsSignedInteger
  17019. | kAudioFormatFlagIsPacked
  17020. | kAudioFormatFlagsNativeEndian;
  17021. inputStreamDesc.mBitsPerChannel = sizeof (SInt16) * 8;
  17022. inputStreamDesc.mChannelsPerFrame = jmin ((UInt32) 2, inputStreamDesc.mChannelsPerFrame);
  17023. inputStreamDesc.mBytesPerFrame = sizeof (SInt16) * inputStreamDesc.mChannelsPerFrame;
  17024. inputStreamDesc.mBytesPerPacket = inputStreamDesc.mBytesPerFrame;
  17025. err = MovieAudioExtractionSetProperty (extractor,
  17026. kQTPropertyClass_MovieAudioExtraction_Audio,
  17027. kQTMovieAudioExtractionAudioPropertyID_AudioStreamBasicDescription,
  17028. sizeof (inputStreamDesc),
  17029. &inputStreamDesc);
  17030. if (err != noErr)
  17031. return;
  17032. Boolean allChannelsDiscrete = false;
  17033. err = MovieAudioExtractionSetProperty (extractor,
  17034. kQTPropertyClass_MovieAudioExtraction_Movie,
  17035. kQTMovieAudioExtractionMoviePropertyID_AllChannelsDiscrete,
  17036. sizeof (allChannelsDiscrete),
  17037. &allChannelsDiscrete);
  17038. if (err != noErr)
  17039. return;
  17040. bufferList->mNumberBuffers = 1;
  17041. bufferList->mBuffers[0].mNumberChannels = inputStreamDesc.mChannelsPerFrame;
  17042. bufferList->mBuffers[0].mDataByteSize = (UInt32) (samplesPerFrame * inputStreamDesc.mBytesPerFrame) + 16;
  17043. bufferList->mBuffers[0].mData = malloc (bufferList->mBuffers[0].mDataByteSize);
  17044. sampleRate = inputStreamDesc.mSampleRate;
  17045. bitsPerSample = 16;
  17046. numChannels = inputStreamDesc.mChannelsPerFrame;
  17047. detachThread();
  17048. ok = true;
  17049. }
  17050. ~QTAudioReader()
  17051. {
  17052. if (dataHandle != 0)
  17053. DisposeHandle (dataHandle);
  17054. if (extractor != 0)
  17055. {
  17056. MovieAudioExtractionEnd (extractor);
  17057. extractor = 0;
  17058. }
  17059. checkThreadIsAttached();
  17060. DisposeMovie (movie);
  17061. juce_free (bufferList->mBuffers[0].mData);
  17062. #if JUCE_MAC
  17063. ExitMoviesOnThread ();
  17064. #endif
  17065. }
  17066. bool readSamples (int** destSamples, int numDestChannels, int startOffsetInDestBuffer,
  17067. int64 startSampleInFile, int numSamples)
  17068. {
  17069. checkThreadIsAttached();
  17070. while (numSamples > 0)
  17071. {
  17072. if (! loadFrame ((int) startSampleInFile))
  17073. return false;
  17074. const int numToDo = jmin (numSamples, samplesPerFrame);
  17075. for (int j = numDestChannels; --j >= 0;)
  17076. {
  17077. if (destSamples[j] != 0)
  17078. {
  17079. const short* const src = ((const short*) bufferList->mBuffers[0].mData) + j;
  17080. for (int i = 0; i < numToDo; ++i)
  17081. destSamples[j][startOffsetInDestBuffer + i] = src [i << 1] << 16;
  17082. }
  17083. }
  17084. startOffsetInDestBuffer += numToDo;
  17085. startSampleInFile += numToDo;
  17086. numSamples -= numToDo;
  17087. }
  17088. detachThread();
  17089. return true;
  17090. }
  17091. bool loadFrame (const int sampleNum)
  17092. {
  17093. if (lastSampleRead != sampleNum)
  17094. {
  17095. TimeRecord time;
  17096. time.scale = (TimeScale) inputStreamDesc.mSampleRate;
  17097. time.base = 0;
  17098. time.value.hi = 0;
  17099. time.value.lo = (UInt32) sampleNum;
  17100. OSStatus err = MovieAudioExtractionSetProperty (extractor,
  17101. kQTPropertyClass_MovieAudioExtraction_Movie,
  17102. kQTMovieAudioExtractionMoviePropertyID_CurrentTime,
  17103. sizeof (time), &time);
  17104. if (err != noErr)
  17105. return false;
  17106. }
  17107. bufferList->mBuffers[0].mDataByteSize = inputStreamDesc.mBytesPerFrame * samplesPerFrame;
  17108. UInt32 outFlags = 0;
  17109. UInt32 actualNumSamples = samplesPerFrame;
  17110. OSStatus err = MovieAudioExtractionFillBuffer (extractor, &actualNumSamples,
  17111. bufferList, &outFlags);
  17112. lastSampleRead = sampleNum + samplesPerFrame;
  17113. return err == noErr;
  17114. }
  17115. juce_UseDebuggingNewOperator
  17116. bool ok;
  17117. private:
  17118. Movie movie;
  17119. Media media;
  17120. Track track;
  17121. const int trackNum;
  17122. double trackUnitsPerFrame;
  17123. int samplesPerFrame;
  17124. int lastSampleRead;
  17125. Thread::ThreadID lastThreadId;
  17126. MovieAudioExtractionRef extractor;
  17127. AudioStreamBasicDescription inputStreamDesc;
  17128. HeapBlock <AudioBufferList> bufferList;
  17129. Handle dataHandle;
  17130. void checkThreadIsAttached()
  17131. {
  17132. #if JUCE_MAC
  17133. if (Thread::getCurrentThreadId() != lastThreadId)
  17134. EnterMoviesOnThread (0);
  17135. AttachMovieToCurrentThread (movie);
  17136. #endif
  17137. }
  17138. void detachThread()
  17139. {
  17140. #if JUCE_MAC
  17141. DetachMovieFromCurrentThread (movie);
  17142. #endif
  17143. }
  17144. QTAudioReader (const QTAudioReader&);
  17145. QTAudioReader& operator= (const QTAudioReader&);
  17146. };
  17147. QuickTimeAudioFormat::QuickTimeAudioFormat()
  17148. : AudioFormat (TRANS (quickTimeFormatName), (const tchar**) quickTimeExtensions)
  17149. {
  17150. }
  17151. QuickTimeAudioFormat::~QuickTimeAudioFormat()
  17152. {
  17153. }
  17154. const Array <int> QuickTimeAudioFormat::getPossibleSampleRates()
  17155. {
  17156. return Array<int>();
  17157. }
  17158. const Array <int> QuickTimeAudioFormat::getPossibleBitDepths()
  17159. {
  17160. return Array<int>();
  17161. }
  17162. bool QuickTimeAudioFormat::canDoStereo()
  17163. {
  17164. return true;
  17165. }
  17166. bool QuickTimeAudioFormat::canDoMono()
  17167. {
  17168. return true;
  17169. }
  17170. AudioFormatReader* QuickTimeAudioFormat::createReaderFor (InputStream* sourceStream,
  17171. const bool deleteStreamIfOpeningFails)
  17172. {
  17173. ScopedPointer <QTAudioReader> r (new QTAudioReader (sourceStream, 0));
  17174. if (r->ok)
  17175. return r.release();
  17176. if (! deleteStreamIfOpeningFails)
  17177. r->input = 0;
  17178. return 0;
  17179. }
  17180. AudioFormatWriter* QuickTimeAudioFormat::createWriterFor (OutputStream* /*streamToWriteTo*/,
  17181. double /*sampleRateToUse*/,
  17182. unsigned int /*numberOfChannels*/,
  17183. int /*bitsPerSample*/,
  17184. const StringPairArray& /*metadataValues*/,
  17185. int /*qualityOptionIndex*/)
  17186. {
  17187. jassertfalse // not yet implemented!
  17188. return 0;
  17189. }
  17190. END_JUCE_NAMESPACE
  17191. #endif
  17192. /*** End of inlined file: juce_QuickTimeAudioFormat.cpp ***/
  17193. /*** Start of inlined file: juce_WavAudioFormat.cpp ***/
  17194. BEGIN_JUCE_NAMESPACE
  17195. static const char* const wavFormatName = "WAV file";
  17196. static const tchar* const wavExtensions[] = { T(".wav"), T(".bwf"), 0 };
  17197. const tchar* const WavAudioFormat::bwavDescription = T("bwav description");
  17198. const tchar* const WavAudioFormat::bwavOriginator = T("bwav originator");
  17199. const tchar* const WavAudioFormat::bwavOriginatorRef = T("bwav originator ref");
  17200. const tchar* const WavAudioFormat::bwavOriginationDate = T("bwav origination date");
  17201. const tchar* const WavAudioFormat::bwavOriginationTime = T("bwav origination time");
  17202. const tchar* const WavAudioFormat::bwavTimeReference = T("bwav time reference");
  17203. const tchar* const WavAudioFormat::bwavCodingHistory = T("bwav coding history");
  17204. const StringPairArray WavAudioFormat::createBWAVMetadata (const String& description,
  17205. const String& originator,
  17206. const String& originatorRef,
  17207. const Time& date,
  17208. const int64 timeReferenceSamples,
  17209. const String& codingHistory)
  17210. {
  17211. StringPairArray m;
  17212. m.set (bwavDescription, description);
  17213. m.set (bwavOriginator, originator);
  17214. m.set (bwavOriginatorRef, originatorRef);
  17215. m.set (bwavOriginationDate, date.formatted (T("%Y-%m-%d")));
  17216. m.set (bwavOriginationTime, date.formatted (T("%H:%M:%S")));
  17217. m.set (bwavTimeReference, String (timeReferenceSamples));
  17218. m.set (bwavCodingHistory, codingHistory);
  17219. return m;
  17220. }
  17221. #if JUCE_MSVC
  17222. #pragma pack (push, 1)
  17223. #define PACKED
  17224. #elif JUCE_GCC
  17225. #define PACKED __attribute__((packed))
  17226. #else
  17227. #define PACKED
  17228. #endif
  17229. struct BWAVChunk
  17230. {
  17231. char description [256];
  17232. char originator [32];
  17233. char originatorRef [32];
  17234. char originationDate [10];
  17235. char originationTime [8];
  17236. uint32 timeRefLow;
  17237. uint32 timeRefHigh;
  17238. uint16 version;
  17239. uint8 umid[64];
  17240. uint8 reserved[190];
  17241. char codingHistory[1];
  17242. void copyTo (StringPairArray& values) const
  17243. {
  17244. values.set (WavAudioFormat::bwavDescription, String::fromUTF8 (description, 256));
  17245. values.set (WavAudioFormat::bwavOriginator, String::fromUTF8 (originator, 32));
  17246. values.set (WavAudioFormat::bwavOriginatorRef, String::fromUTF8 (originatorRef, 32));
  17247. values.set (WavAudioFormat::bwavOriginationDate, String::fromUTF8 (originationDate, 10));
  17248. values.set (WavAudioFormat::bwavOriginationTime, String::fromUTF8 (originationTime, 8));
  17249. const uint32 timeLow = ByteOrder::swapIfBigEndian (timeRefLow);
  17250. const uint32 timeHigh = ByteOrder::swapIfBigEndian (timeRefHigh);
  17251. const int64 time = (((int64)timeHigh) << 32) + timeLow;
  17252. values.set (WavAudioFormat::bwavTimeReference, String (time));
  17253. values.set (WavAudioFormat::bwavCodingHistory, String::fromUTF8 (codingHistory));
  17254. }
  17255. static MemoryBlock createFrom (const StringPairArray& values)
  17256. {
  17257. const size_t sizeNeeded = sizeof (BWAVChunk) + values [WavAudioFormat::bwavCodingHistory].getNumBytesAsUTF8();
  17258. MemoryBlock data ((sizeNeeded + 3) & ~3);
  17259. data.fillWith (0);
  17260. BWAVChunk* b = (BWAVChunk*) data.getData();
  17261. // Allow these calls to overwrite an extra byte at the end, which is fine as long
  17262. // as they get called in the right order..
  17263. values [WavAudioFormat::bwavDescription].copyToUTF8 (b->description, 257);
  17264. values [WavAudioFormat::bwavOriginator].copyToUTF8 (b->originator, 33);
  17265. values [WavAudioFormat::bwavOriginatorRef].copyToUTF8 (b->originatorRef, 33);
  17266. values [WavAudioFormat::bwavOriginationDate].copyToUTF8 (b->originationDate, 11);
  17267. values [WavAudioFormat::bwavOriginationTime].copyToUTF8 (b->originationTime, 9);
  17268. const int64 time = values [WavAudioFormat::bwavTimeReference].getLargeIntValue();
  17269. b->timeRefLow = ByteOrder::swapIfBigEndian ((uint32) (time & 0xffffffff));
  17270. b->timeRefHigh = ByteOrder::swapIfBigEndian ((uint32) (time >> 32));
  17271. values [WavAudioFormat::bwavCodingHistory].copyToUTF8 (b->codingHistory, 0x7fffffff);
  17272. if (b->description[0] != 0
  17273. || b->originator[0] != 0
  17274. || b->originationDate[0] != 0
  17275. || b->originationTime[0] != 0
  17276. || b->codingHistory[0] != 0
  17277. || time != 0)
  17278. {
  17279. return data;
  17280. }
  17281. return MemoryBlock();
  17282. }
  17283. } PACKED;
  17284. struct SMPLChunk
  17285. {
  17286. struct SampleLoop
  17287. {
  17288. uint32 identifier;
  17289. uint32 type;
  17290. uint32 start;
  17291. uint32 end;
  17292. uint32 fraction;
  17293. uint32 playCount;
  17294. } PACKED;
  17295. uint32 manufacturer;
  17296. uint32 product;
  17297. uint32 samplePeriod;
  17298. uint32 midiUnityNote;
  17299. uint32 midiPitchFraction;
  17300. uint32 smpteFormat;
  17301. uint32 smpteOffset;
  17302. uint32 numSampleLoops;
  17303. uint32 samplerData;
  17304. SampleLoop loops[1];
  17305. void copyTo (StringPairArray& values, const int totalSize) const
  17306. {
  17307. values.set ("Manufacturer", String (ByteOrder::swapIfBigEndian (manufacturer)));
  17308. values.set ("Product", String (ByteOrder::swapIfBigEndian (product)));
  17309. values.set ("SamplePeriod", String (ByteOrder::swapIfBigEndian (samplePeriod)));
  17310. values.set ("MidiUnityNote", String (ByteOrder::swapIfBigEndian (midiUnityNote)));
  17311. values.set ("MidiPitchFraction", String (ByteOrder::swapIfBigEndian (midiPitchFraction)));
  17312. values.set ("SmpteFormat", String (ByteOrder::swapIfBigEndian (smpteFormat)));
  17313. values.set ("SmpteOffset", String (ByteOrder::swapIfBigEndian (smpteOffset)));
  17314. values.set ("NumSampleLoops", String (ByteOrder::swapIfBigEndian (numSampleLoops)));
  17315. values.set ("SamplerData", String (ByteOrder::swapIfBigEndian (samplerData)));
  17316. for (uint32 i = 0; i < numSampleLoops; ++i)
  17317. {
  17318. if ((uint8*) (loops + (i + 1)) > ((uint8*) this) + totalSize)
  17319. break;
  17320. const String prefix ("Loop" + String(i));
  17321. values.set (prefix + "Identifier", String (ByteOrder::swapIfBigEndian (loops[i].identifier)));
  17322. values.set (prefix + "Type", String (ByteOrder::swapIfBigEndian (loops[i].type)));
  17323. values.set (prefix + "Start", String (ByteOrder::swapIfBigEndian (loops[i].start)));
  17324. values.set (prefix + "End", String (ByteOrder::swapIfBigEndian (loops[i].end)));
  17325. values.set (prefix + "Fraction", String (ByteOrder::swapIfBigEndian (loops[i].fraction)));
  17326. values.set (prefix + "PlayCount", String (ByteOrder::swapIfBigEndian (loops[i].playCount)));
  17327. }
  17328. }
  17329. static MemoryBlock createFrom (const StringPairArray& values)
  17330. {
  17331. const int numLoops = jmin (64, values.getValue ("NumSampleLoops", "0").getIntValue());
  17332. if (numLoops <= 0)
  17333. return MemoryBlock();
  17334. const size_t sizeNeeded = sizeof (SMPLChunk) + (numLoops - 1) * sizeof (SampleLoop);
  17335. MemoryBlock data ((sizeNeeded + 3) & ~3);
  17336. data.fillWith (0);
  17337. SMPLChunk* s = (SMPLChunk*) data.getData();
  17338. // Allow these calls to overwrite an extra byte at the end, which is fine as long
  17339. // as they get called in the right order..
  17340. s->manufacturer = ByteOrder::swapIfBigEndian ((uint32) values.getValue ("Manufacturer", "0").getIntValue());
  17341. s->product = ByteOrder::swapIfBigEndian ((uint32) values.getValue ("Product", "0").getIntValue());
  17342. s->samplePeriod = ByteOrder::swapIfBigEndian ((uint32) values.getValue ("SamplePeriod", "0").getIntValue());
  17343. s->midiUnityNote = ByteOrder::swapIfBigEndian ((uint32) values.getValue ("MidiUnityNote", "60").getIntValue());
  17344. s->midiPitchFraction = ByteOrder::swapIfBigEndian ((uint32) values.getValue ("MidiPitchFraction", "0").getIntValue());
  17345. s->smpteFormat = ByteOrder::swapIfBigEndian ((uint32) values.getValue ("SmpteFormat", "0").getIntValue());
  17346. s->smpteOffset = ByteOrder::swapIfBigEndian ((uint32) values.getValue ("SmpteOffset", "0").getIntValue());
  17347. s->numSampleLoops = ByteOrder::swapIfBigEndian ((uint32) numLoops);
  17348. s->samplerData = ByteOrder::swapIfBigEndian ((uint32) values.getValue ("SamplerData", "0").getIntValue());
  17349. for (int i = 0; i < numLoops; ++i)
  17350. {
  17351. const String prefix ("Loop" + String(i));
  17352. s->loops[i].identifier = ByteOrder::swapIfBigEndian ((uint32) values.getValue (prefix + "Identifier", "0").getIntValue());
  17353. s->loops[i].type = ByteOrder::swapIfBigEndian ((uint32) values.getValue (prefix + "Type", "0").getIntValue());
  17354. s->loops[i].start = ByteOrder::swapIfBigEndian ((uint32) values.getValue (prefix + "Start", "0").getIntValue());
  17355. s->loops[i].end = ByteOrder::swapIfBigEndian ((uint32) values.getValue (prefix + "End", "0").getIntValue());
  17356. s->loops[i].fraction = ByteOrder::swapIfBigEndian ((uint32) values.getValue (prefix + "Fraction", "0").getIntValue());
  17357. s->loops[i].playCount = ByteOrder::swapIfBigEndian ((uint32) values.getValue (prefix + "PlayCount", "0").getIntValue());
  17358. }
  17359. return data;
  17360. }
  17361. } PACKED;
  17362. struct ExtensibleWavSubFormat
  17363. {
  17364. uint32 data1;
  17365. uint16 data2;
  17366. uint16 data3;
  17367. uint8 data4[8];
  17368. } PACKED;
  17369. #if JUCE_MSVC
  17370. #pragma pack (pop)
  17371. #endif
  17372. #undef PACKED
  17373. class WavAudioFormatReader : public AudioFormatReader
  17374. {
  17375. int bytesPerFrame;
  17376. int64 dataChunkStart, dataLength;
  17377. static inline int chunkName (const char* const name) { return (int) ByteOrder::littleEndianInt (name); }
  17378. WavAudioFormatReader (const WavAudioFormatReader&);
  17379. WavAudioFormatReader& operator= (const WavAudioFormatReader&);
  17380. public:
  17381. int64 bwavChunkStart, bwavSize;
  17382. WavAudioFormatReader (InputStream* const in)
  17383. : AudioFormatReader (in, TRANS (wavFormatName)),
  17384. dataLength (0),
  17385. bwavChunkStart (0),
  17386. bwavSize (0)
  17387. {
  17388. if (input->readInt() == chunkName ("RIFF"))
  17389. {
  17390. const uint32 len = (uint32) input->readInt();
  17391. const int64 end = input->getPosition() + len;
  17392. bool hasGotType = false;
  17393. bool hasGotData = false;
  17394. if (input->readInt() == chunkName ("WAVE"))
  17395. {
  17396. while (input->getPosition() < end
  17397. && ! input->isExhausted())
  17398. {
  17399. const int chunkType = input->readInt();
  17400. uint32 length = (uint32) input->readInt();
  17401. const int64 chunkEnd = input->getPosition() + length + (length & 1);
  17402. if (chunkType == chunkName ("fmt "))
  17403. {
  17404. // read the format chunk
  17405. const unsigned short format = input->readShort();
  17406. const short numChans = input->readShort();
  17407. sampleRate = input->readInt();
  17408. const int bytesPerSec = input->readInt();
  17409. numChannels = numChans;
  17410. bytesPerFrame = bytesPerSec / (int)sampleRate;
  17411. bitsPerSample = 8 * bytesPerFrame / numChans;
  17412. if (format == 3)
  17413. {
  17414. usesFloatingPointData = true;
  17415. }
  17416. else if (format == 0xfffe /*WAVE_FORMAT_EXTENSIBLE*/)
  17417. {
  17418. if (length < 40) // too short
  17419. {
  17420. bytesPerFrame = 0;
  17421. }
  17422. else
  17423. {
  17424. input->skipNextBytes (12); // skip over blockAlign, bitsPerSample and speakerPosition mask
  17425. ExtensibleWavSubFormat subFormat;
  17426. subFormat.data1 = input->readInt();
  17427. subFormat.data2 = input->readShort();
  17428. subFormat.data3 = input->readShort();
  17429. input->read (subFormat.data4, sizeof (subFormat.data4));
  17430. const ExtensibleWavSubFormat pcmFormat
  17431. = { 0x00000001, 0x0000, 0x0010, { 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71 } };
  17432. if (memcmp (&subFormat, &pcmFormat, sizeof (subFormat)) != 0)
  17433. {
  17434. const ExtensibleWavSubFormat ambisonicFormat
  17435. = { 0x00000001, 0x0721, 0x11d3, { 0x86, 0x44, 0xC8, 0xC1, 0xCA, 0x00, 0x00, 0x00 } };
  17436. if (memcmp (&subFormat, &ambisonicFormat, sizeof (subFormat)) != 0)
  17437. bytesPerFrame = 0;
  17438. }
  17439. }
  17440. }
  17441. else if (format != 1)
  17442. {
  17443. bytesPerFrame = 0;
  17444. }
  17445. hasGotType = true;
  17446. }
  17447. else if (chunkType == chunkName ("data"))
  17448. {
  17449. // get the data chunk's position
  17450. dataLength = length;
  17451. dataChunkStart = input->getPosition();
  17452. lengthInSamples = (bytesPerFrame > 0) ? (dataLength / bytesPerFrame) : 0;
  17453. hasGotData = true;
  17454. }
  17455. else if (chunkType == chunkName ("bext"))
  17456. {
  17457. bwavChunkStart = input->getPosition();
  17458. bwavSize = length;
  17459. // Broadcast-wav extension chunk..
  17460. HeapBlock <BWAVChunk> bwav;
  17461. bwav.calloc (jmax ((size_t) length + 1, sizeof (BWAVChunk)), 1);
  17462. input->read (bwav, length);
  17463. bwav->copyTo (metadataValues);
  17464. }
  17465. else if (chunkType == chunkName ("smpl"))
  17466. {
  17467. HeapBlock <SMPLChunk> smpl;
  17468. smpl.calloc (jmax ((size_t) length + 1, sizeof (SMPLChunk)), 1);
  17469. input->read (smpl, length);
  17470. smpl->copyTo (metadataValues, length);
  17471. }
  17472. else if (chunkEnd <= input->getPosition())
  17473. {
  17474. break;
  17475. }
  17476. input->setPosition (chunkEnd);
  17477. }
  17478. }
  17479. }
  17480. }
  17481. ~WavAudioFormatReader()
  17482. {
  17483. }
  17484. bool readSamples (int** destSamples, int numDestChannels, int startOffsetInDestBuffer,
  17485. int64 startSampleInFile, int numSamples)
  17486. {
  17487. const int64 samplesAvailable = lengthInSamples - startSampleInFile;
  17488. if (samplesAvailable < numSamples)
  17489. {
  17490. for (int i = numDestChannels; --i >= 0;)
  17491. if (destSamples[i] != 0)
  17492. zeromem (destSamples[i] + startOffsetInDestBuffer, sizeof (int) * numSamples);
  17493. numSamples = (int) samplesAvailable;
  17494. }
  17495. if (numSamples <= 0)
  17496. return true;
  17497. input->setPosition (dataChunkStart + startSampleInFile * bytesPerFrame);
  17498. const int tempBufSize = 480 * 3 * 4; // (keep this a multiple of 3)
  17499. char tempBuffer [tempBufSize];
  17500. while (numSamples > 0)
  17501. {
  17502. int* left = destSamples[0];
  17503. if (left != 0)
  17504. left += startOffsetInDestBuffer;
  17505. int* right = numDestChannels > 1 ? destSamples[1] : 0;
  17506. if (right != 0)
  17507. right += startOffsetInDestBuffer;
  17508. const int numThisTime = jmin (tempBufSize / bytesPerFrame, numSamples);
  17509. const int bytesRead = input->read (tempBuffer, numThisTime * bytesPerFrame);
  17510. if (bytesRead < numThisTime * bytesPerFrame)
  17511. zeromem (tempBuffer + bytesRead, numThisTime * bytesPerFrame - bytesRead);
  17512. if (bitsPerSample == 16)
  17513. {
  17514. const short* src = (const short*) tempBuffer;
  17515. if (numChannels > 1)
  17516. {
  17517. if (left == 0)
  17518. {
  17519. for (int i = numThisTime; --i >= 0;)
  17520. {
  17521. ++src;
  17522. *right++ = (int) ByteOrder::swapIfBigEndian ((unsigned short) *src++) << 16;
  17523. }
  17524. }
  17525. else if (right == 0)
  17526. {
  17527. for (int i = numThisTime; --i >= 0;)
  17528. {
  17529. *left++ = (int) ByteOrder::swapIfBigEndian ((unsigned short) *src++) << 16;
  17530. ++src;
  17531. }
  17532. }
  17533. else
  17534. {
  17535. for (int i = numThisTime; --i >= 0;)
  17536. {
  17537. *left++ = (int) ByteOrder::swapIfBigEndian ((unsigned short) *src++) << 16;
  17538. *right++ = (int) ByteOrder::swapIfBigEndian ((unsigned short) *src++) << 16;
  17539. }
  17540. }
  17541. }
  17542. else
  17543. {
  17544. for (int i = numThisTime; --i >= 0;)
  17545. {
  17546. *left++ = (int) ByteOrder::swapIfBigEndian ((unsigned short) *src++) << 16;
  17547. }
  17548. }
  17549. }
  17550. else if (bitsPerSample == 24)
  17551. {
  17552. const char* src = (const char*) tempBuffer;
  17553. if (numChannels > 1)
  17554. {
  17555. if (left == 0)
  17556. {
  17557. for (int i = numThisTime; --i >= 0;)
  17558. {
  17559. src += 3;
  17560. *right++ = ByteOrder::littleEndian24Bit (src) << 8;
  17561. src += 3;
  17562. }
  17563. }
  17564. else if (right == 0)
  17565. {
  17566. for (int i = numThisTime; --i >= 0;)
  17567. {
  17568. *left++ = ByteOrder::littleEndian24Bit (src) << 8;
  17569. src += 6;
  17570. }
  17571. }
  17572. else
  17573. {
  17574. for (int i = 0; i < numThisTime; ++i)
  17575. {
  17576. *left++ = ByteOrder::littleEndian24Bit (src) << 8;
  17577. src += 3;
  17578. *right++ = ByteOrder::littleEndian24Bit (src) << 8;
  17579. src += 3;
  17580. }
  17581. }
  17582. }
  17583. else
  17584. {
  17585. for (int i = 0; i < numThisTime; ++i)
  17586. {
  17587. *left++ = ByteOrder::littleEndian24Bit (src) << 8;
  17588. src += 3;
  17589. }
  17590. }
  17591. }
  17592. else if (bitsPerSample == 32)
  17593. {
  17594. const unsigned int* src = (const unsigned int*) tempBuffer;
  17595. unsigned int* l = (unsigned int*) left;
  17596. unsigned int* r = (unsigned int*) right;
  17597. if (numChannels > 1)
  17598. {
  17599. if (l == 0)
  17600. {
  17601. for (int i = numThisTime; --i >= 0;)
  17602. {
  17603. ++src;
  17604. *r++ = ByteOrder::swapIfBigEndian (*src++);
  17605. }
  17606. }
  17607. else if (r == 0)
  17608. {
  17609. for (int i = numThisTime; --i >= 0;)
  17610. {
  17611. *l++ = ByteOrder::swapIfBigEndian (*src++);
  17612. ++src;
  17613. }
  17614. }
  17615. else
  17616. {
  17617. for (int i = numThisTime; --i >= 0;)
  17618. {
  17619. *l++ = ByteOrder::swapIfBigEndian (*src++);
  17620. *r++ = ByteOrder::swapIfBigEndian (*src++);
  17621. }
  17622. }
  17623. }
  17624. else
  17625. {
  17626. for (int i = numThisTime; --i >= 0;)
  17627. {
  17628. *l++ = ByteOrder::swapIfBigEndian (*src++);
  17629. }
  17630. }
  17631. left = (int*)l;
  17632. right = (int*)r;
  17633. }
  17634. else if (bitsPerSample == 8)
  17635. {
  17636. const unsigned char* src = (const unsigned char*) tempBuffer;
  17637. if (numChannels > 1)
  17638. {
  17639. if (left == 0)
  17640. {
  17641. for (int i = numThisTime; --i >= 0;)
  17642. {
  17643. ++src;
  17644. *right++ = ((int) *src++ - 128) << 24;
  17645. }
  17646. }
  17647. else if (right == 0)
  17648. {
  17649. for (int i = numThisTime; --i >= 0;)
  17650. {
  17651. *left++ = ((int) *src++ - 128) << 24;
  17652. ++src;
  17653. }
  17654. }
  17655. else
  17656. {
  17657. for (int i = numThisTime; --i >= 0;)
  17658. {
  17659. *left++ = ((int) *src++ - 128) << 24;
  17660. *right++ = ((int) *src++ - 128) << 24;
  17661. }
  17662. }
  17663. }
  17664. else
  17665. {
  17666. for (int i = numThisTime; --i >= 0;)
  17667. {
  17668. *left++ = ((int)*src++ - 128) << 24;
  17669. }
  17670. }
  17671. }
  17672. startOffsetInDestBuffer += numThisTime;
  17673. numSamples -= numThisTime;
  17674. }
  17675. if (numSamples > 0)
  17676. {
  17677. for (int i = numDestChannels; --i >= 0;)
  17678. if (destSamples[i] != 0)
  17679. zeromem (destSamples[i] + startOffsetInDestBuffer,
  17680. sizeof (int) * numSamples);
  17681. }
  17682. return true;
  17683. }
  17684. juce_UseDebuggingNewOperator
  17685. };
  17686. class WavAudioFormatWriter : public AudioFormatWriter
  17687. {
  17688. MemoryBlock tempBlock, bwavChunk, smplChunk;
  17689. uint32 lengthInSamples, bytesWritten;
  17690. int64 headerPosition;
  17691. bool writeFailed;
  17692. static inline int chunkName (const char* const name) { return (int) ByteOrder::littleEndianInt (name); }
  17693. WavAudioFormatWriter (const WavAudioFormatWriter&);
  17694. WavAudioFormatWriter& operator= (const WavAudioFormatWriter&);
  17695. void writeHeader()
  17696. {
  17697. const bool seekedOk = output->setPosition (headerPosition);
  17698. (void) seekedOk;
  17699. // if this fails, you've given it an output stream that can't seek! It needs
  17700. // to be able to seek back to write the header
  17701. jassert (seekedOk);
  17702. const int bytesPerFrame = numChannels * bitsPerSample / 8;
  17703. output->writeInt (chunkName ("RIFF"));
  17704. output->writeInt ((int) (lengthInSamples * bytesPerFrame
  17705. + ((bwavChunk.getSize() > 0) ? (44 + bwavChunk.getSize()) : 36)));
  17706. output->writeInt (chunkName ("WAVE"));
  17707. output->writeInt (chunkName ("fmt "));
  17708. output->writeInt (16);
  17709. output->writeShort ((bitsPerSample < 32) ? (short) 1 /*WAVE_FORMAT_PCM*/
  17710. : (short) 3 /*WAVE_FORMAT_IEEE_FLOAT*/);
  17711. output->writeShort ((short) numChannels);
  17712. output->writeInt ((int) sampleRate);
  17713. output->writeInt (bytesPerFrame * (int) sampleRate);
  17714. output->writeShort ((short) bytesPerFrame);
  17715. output->writeShort ((short) bitsPerSample);
  17716. if (bwavChunk.getSize() > 0)
  17717. {
  17718. output->writeInt (chunkName ("bext"));
  17719. output->writeInt ((int) bwavChunk.getSize());
  17720. output->write (bwavChunk.getData(), (int) bwavChunk.getSize());
  17721. }
  17722. if (smplChunk.getSize() > 0)
  17723. {
  17724. output->writeInt (chunkName ("smpl"));
  17725. output->writeInt ((int) smplChunk.getSize());
  17726. output->write (smplChunk.getData(), (int) smplChunk.getSize());
  17727. }
  17728. output->writeInt (chunkName ("data"));
  17729. output->writeInt (lengthInSamples * bytesPerFrame);
  17730. usesFloatingPointData = (bitsPerSample == 32);
  17731. }
  17732. public:
  17733. WavAudioFormatWriter (OutputStream* const out,
  17734. const double sampleRate_,
  17735. const unsigned int numChannels_,
  17736. const int bits,
  17737. const StringPairArray& metadataValues)
  17738. : AudioFormatWriter (out,
  17739. TRANS (wavFormatName),
  17740. sampleRate_,
  17741. numChannels_,
  17742. bits),
  17743. lengthInSamples (0),
  17744. bytesWritten (0),
  17745. writeFailed (false)
  17746. {
  17747. if (metadataValues.size() > 0)
  17748. {
  17749. bwavChunk = BWAVChunk::createFrom (metadataValues);
  17750. smplChunk = SMPLChunk::createFrom (metadataValues);
  17751. }
  17752. headerPosition = out->getPosition();
  17753. writeHeader();
  17754. }
  17755. ~WavAudioFormatWriter()
  17756. {
  17757. writeHeader();
  17758. }
  17759. bool write (const int** data, int numSamples)
  17760. {
  17761. if (writeFailed)
  17762. return false;
  17763. const int bytes = numChannels * numSamples * bitsPerSample / 8;
  17764. tempBlock.ensureSize (bytes, false);
  17765. char* buffer = (char*) tempBlock.getData();
  17766. const int* left = data[0];
  17767. const int* right = data[1];
  17768. if (right == 0)
  17769. right = left;
  17770. if (bitsPerSample == 16)
  17771. {
  17772. short* b = (short*) buffer;
  17773. if (numChannels > 1)
  17774. {
  17775. for (int i = numSamples; --i >= 0;)
  17776. {
  17777. *b++ = (short) ByteOrder::swapIfBigEndian ((unsigned short) (*left++ >> 16));
  17778. *b++ = (short) ByteOrder::swapIfBigEndian ((unsigned short) (*right++ >> 16));
  17779. }
  17780. }
  17781. else
  17782. {
  17783. for (int i = numSamples; --i >= 0;)
  17784. {
  17785. *b++ = (short) ByteOrder::swapIfBigEndian ((unsigned short) (*left++ >> 16));
  17786. }
  17787. }
  17788. }
  17789. else if (bitsPerSample == 24)
  17790. {
  17791. char* b = (char*) buffer;
  17792. if (numChannels > 1)
  17793. {
  17794. for (int i = numSamples; --i >= 0;)
  17795. {
  17796. ByteOrder::littleEndian24BitToChars ((*left++) >> 8, b);
  17797. b += 3;
  17798. ByteOrder::littleEndian24BitToChars ((*right++) >> 8, b);
  17799. b += 3;
  17800. }
  17801. }
  17802. else
  17803. {
  17804. for (int i = numSamples; --i >= 0;)
  17805. {
  17806. ByteOrder::littleEndian24BitToChars ((*left++) >> 8, b);
  17807. b += 3;
  17808. }
  17809. }
  17810. }
  17811. else if (bitsPerSample == 32)
  17812. {
  17813. unsigned int* b = (unsigned int*) buffer;
  17814. if (numChannels > 1)
  17815. {
  17816. for (int i = numSamples; --i >= 0;)
  17817. {
  17818. *b++ = ByteOrder::swapIfBigEndian ((unsigned int) *left++);
  17819. *b++ = ByteOrder::swapIfBigEndian ((unsigned int) *right++);
  17820. }
  17821. }
  17822. else
  17823. {
  17824. for (int i = numSamples; --i >= 0;)
  17825. {
  17826. *b++ = ByteOrder::swapIfBigEndian ((unsigned int) *left++);
  17827. }
  17828. }
  17829. }
  17830. else if (bitsPerSample == 8)
  17831. {
  17832. unsigned char* b = (unsigned char*) buffer;
  17833. if (numChannels > 1)
  17834. {
  17835. for (int i = numSamples; --i >= 0;)
  17836. {
  17837. *b++ = (unsigned char) (128 + (*left++ >> 24));
  17838. *b++ = (unsigned char) (128 + (*right++ >> 24));
  17839. }
  17840. }
  17841. else
  17842. {
  17843. for (int i = numSamples; --i >= 0;)
  17844. {
  17845. *b++ = (unsigned char) (128 + (*left++ >> 24));
  17846. }
  17847. }
  17848. }
  17849. if (bytesWritten + bytes >= (uint32) 0xfff00000
  17850. || ! output->write (buffer, bytes))
  17851. {
  17852. // failed to write to disk, so let's try writing the header.
  17853. // If it's just run out of disk space, then if it does manage
  17854. // to write the header, we'll still have a useable file..
  17855. writeHeader();
  17856. writeFailed = true;
  17857. return false;
  17858. }
  17859. else
  17860. {
  17861. bytesWritten += bytes;
  17862. lengthInSamples += numSamples;
  17863. return true;
  17864. }
  17865. }
  17866. juce_UseDebuggingNewOperator
  17867. };
  17868. WavAudioFormat::WavAudioFormat()
  17869. : AudioFormat (TRANS (wavFormatName), (const tchar**) wavExtensions)
  17870. {
  17871. }
  17872. WavAudioFormat::~WavAudioFormat()
  17873. {
  17874. }
  17875. const Array <int> WavAudioFormat::getPossibleSampleRates()
  17876. {
  17877. const int rates[] = { 22050, 32000, 44100, 48000, 88200, 96000, 176400, 192000, 0 };
  17878. return Array <int> (rates);
  17879. }
  17880. const Array <int> WavAudioFormat::getPossibleBitDepths()
  17881. {
  17882. const int depths[] = { 8, 16, 24, 32, 0 };
  17883. return Array <int> (depths);
  17884. }
  17885. bool WavAudioFormat::canDoStereo()
  17886. {
  17887. return true;
  17888. }
  17889. bool WavAudioFormat::canDoMono()
  17890. {
  17891. return true;
  17892. }
  17893. AudioFormatReader* WavAudioFormat::createReaderFor (InputStream* sourceStream,
  17894. const bool deleteStreamIfOpeningFails)
  17895. {
  17896. ScopedPointer <WavAudioFormatReader> r (new WavAudioFormatReader (sourceStream));
  17897. if (r->sampleRate != 0)
  17898. return r.release();
  17899. if (! deleteStreamIfOpeningFails)
  17900. r->input = 0;
  17901. return 0;
  17902. }
  17903. AudioFormatWriter* WavAudioFormat::createWriterFor (OutputStream* out,
  17904. double sampleRate,
  17905. unsigned int numChannels,
  17906. int bitsPerSample,
  17907. const StringPairArray& metadataValues,
  17908. int /*qualityOptionIndex*/)
  17909. {
  17910. if (getPossibleBitDepths().contains (bitsPerSample))
  17911. {
  17912. return new WavAudioFormatWriter (out,
  17913. sampleRate,
  17914. numChannels,
  17915. bitsPerSample,
  17916. metadataValues);
  17917. }
  17918. return 0;
  17919. }
  17920. static bool juce_slowCopyOfWavFileWithNewMetadata (const File& file, const StringPairArray& metadata)
  17921. {
  17922. TemporaryFile tempFile (file);
  17923. WavAudioFormat wav;
  17924. ScopedPointer <AudioFormatReader> reader (wav.createReaderFor (file.createInputStream(), true));
  17925. if (reader != 0)
  17926. {
  17927. ScopedPointer <OutputStream> outStream (tempFile.getFile().createOutputStream());
  17928. if (outStream != 0)
  17929. {
  17930. ScopedPointer <AudioFormatWriter> writer (wav.createWriterFor (outStream, reader->sampleRate,
  17931. reader->numChannels, reader->bitsPerSample,
  17932. metadata, 0));
  17933. if (writer != 0)
  17934. {
  17935. outStream.release();
  17936. bool ok = writer->writeFromAudioReader (*reader, 0, -1);
  17937. writer = 0;
  17938. reader = 0;
  17939. return ok && tempFile.overwriteTargetFileWithTemporary();
  17940. }
  17941. }
  17942. }
  17943. return false;
  17944. }
  17945. bool WavAudioFormat::replaceMetadataInFile (const File& wavFile, const StringPairArray& newMetadata)
  17946. {
  17947. ScopedPointer <WavAudioFormatReader> reader ((WavAudioFormatReader*) createReaderFor (wavFile.createInputStream(), true));
  17948. if (reader != 0)
  17949. {
  17950. const int64 bwavPos = reader->bwavChunkStart;
  17951. const int64 bwavSize = reader->bwavSize;
  17952. reader = 0;
  17953. if (bwavSize > 0)
  17954. {
  17955. MemoryBlock chunk = BWAVChunk::createFrom (newMetadata);
  17956. if (chunk.getSize() <= (size_t) bwavSize)
  17957. {
  17958. // the new one will fit in the space available, so write it directly..
  17959. const int64 oldSize = wavFile.getSize();
  17960. {
  17961. ScopedPointer <FileOutputStream> out (wavFile.createOutputStream());
  17962. out->setPosition (bwavPos);
  17963. out->write (chunk.getData(), (int) chunk.getSize());
  17964. out->setPosition (oldSize);
  17965. }
  17966. jassert (wavFile.getSize() == oldSize);
  17967. return true;
  17968. }
  17969. }
  17970. }
  17971. return juce_slowCopyOfWavFileWithNewMetadata (wavFile, newMetadata);
  17972. }
  17973. END_JUCE_NAMESPACE
  17974. /*** End of inlined file: juce_WavAudioFormat.cpp ***/
  17975. /*** Start of inlined file: juce_AudioFormatReaderSource.cpp ***/
  17976. BEGIN_JUCE_NAMESPACE
  17977. AudioFormatReaderSource::AudioFormatReaderSource (AudioFormatReader* const reader_,
  17978. const bool deleteReaderWhenThisIsDeleted)
  17979. : reader (reader_),
  17980. deleteReader (deleteReaderWhenThisIsDeleted),
  17981. nextPlayPos (0),
  17982. looping (false)
  17983. {
  17984. jassert (reader != 0);
  17985. }
  17986. AudioFormatReaderSource::~AudioFormatReaderSource()
  17987. {
  17988. releaseResources();
  17989. if (deleteReader)
  17990. delete reader;
  17991. }
  17992. void AudioFormatReaderSource::setNextReadPosition (int newPosition)
  17993. {
  17994. nextPlayPos = newPosition;
  17995. }
  17996. void AudioFormatReaderSource::setLooping (const bool shouldLoop) throw()
  17997. {
  17998. looping = shouldLoop;
  17999. }
  18000. int AudioFormatReaderSource::getNextReadPosition() const
  18001. {
  18002. return (looping) ? (nextPlayPos % (int) reader->lengthInSamples)
  18003. : nextPlayPos;
  18004. }
  18005. int AudioFormatReaderSource::getTotalLength() const
  18006. {
  18007. return (int) reader->lengthInSamples;
  18008. }
  18009. void AudioFormatReaderSource::prepareToPlay (int /*samplesPerBlockExpected*/,
  18010. double /*sampleRate*/)
  18011. {
  18012. }
  18013. void AudioFormatReaderSource::releaseResources()
  18014. {
  18015. }
  18016. void AudioFormatReaderSource::getNextAudioBlock (const AudioSourceChannelInfo& info)
  18017. {
  18018. if (info.numSamples > 0)
  18019. {
  18020. const int start = nextPlayPos;
  18021. if (looping)
  18022. {
  18023. const int newStart = start % (int) reader->lengthInSamples;
  18024. const int newEnd = (start + info.numSamples) % (int) reader->lengthInSamples;
  18025. if (newEnd > newStart)
  18026. {
  18027. info.buffer->readFromAudioReader (reader,
  18028. info.startSample,
  18029. newEnd - newStart,
  18030. newStart,
  18031. true, true);
  18032. }
  18033. else
  18034. {
  18035. const int endSamps = (int) reader->lengthInSamples - newStart;
  18036. info.buffer->readFromAudioReader (reader,
  18037. info.startSample,
  18038. endSamps,
  18039. newStart,
  18040. true, true);
  18041. info.buffer->readFromAudioReader (reader,
  18042. info.startSample + endSamps,
  18043. newEnd,
  18044. 0,
  18045. true, true);
  18046. }
  18047. nextPlayPos = newEnd;
  18048. }
  18049. else
  18050. {
  18051. info.buffer->readFromAudioReader (reader,
  18052. info.startSample,
  18053. info.numSamples,
  18054. start,
  18055. true, true);
  18056. nextPlayPos += info.numSamples;
  18057. }
  18058. }
  18059. }
  18060. END_JUCE_NAMESPACE
  18061. /*** End of inlined file: juce_AudioFormatReaderSource.cpp ***/
  18062. /*** Start of inlined file: juce_AudioSourcePlayer.cpp ***/
  18063. BEGIN_JUCE_NAMESPACE
  18064. AudioSourcePlayer::AudioSourcePlayer()
  18065. : source (0),
  18066. sampleRate (0),
  18067. bufferSize (0),
  18068. tempBuffer (2, 8),
  18069. lastGain (1.0f),
  18070. gain (1.0f)
  18071. {
  18072. }
  18073. AudioSourcePlayer::~AudioSourcePlayer()
  18074. {
  18075. setSource (0);
  18076. }
  18077. void AudioSourcePlayer::setSource (AudioSource* newSource)
  18078. {
  18079. if (source != newSource)
  18080. {
  18081. AudioSource* const oldSource = source;
  18082. if (newSource != 0 && bufferSize > 0 && sampleRate > 0)
  18083. newSource->prepareToPlay (bufferSize, sampleRate);
  18084. {
  18085. const ScopedLock sl (readLock);
  18086. source = newSource;
  18087. }
  18088. if (oldSource != 0)
  18089. oldSource->releaseResources();
  18090. }
  18091. }
  18092. void AudioSourcePlayer::setGain (const float newGain) throw()
  18093. {
  18094. gain = newGain;
  18095. }
  18096. void AudioSourcePlayer::audioDeviceIOCallback (const float** inputChannelData,
  18097. int totalNumInputChannels,
  18098. float** outputChannelData,
  18099. int totalNumOutputChannels,
  18100. int numSamples)
  18101. {
  18102. // these should have been prepared by audioDeviceAboutToStart()...
  18103. jassert (sampleRate > 0 && bufferSize > 0);
  18104. const ScopedLock sl (readLock);
  18105. if (source != 0)
  18106. {
  18107. AudioSourceChannelInfo info;
  18108. int i, numActiveChans = 0, numInputs = 0, numOutputs = 0;
  18109. // messy stuff needed to compact the channels down into an array
  18110. // of non-zero pointers..
  18111. for (i = 0; i < totalNumInputChannels; ++i)
  18112. {
  18113. if (inputChannelData[i] != 0)
  18114. {
  18115. inputChans [numInputs++] = inputChannelData[i];
  18116. if (numInputs >= numElementsInArray (inputChans))
  18117. break;
  18118. }
  18119. }
  18120. for (i = 0; i < totalNumOutputChannels; ++i)
  18121. {
  18122. if (outputChannelData[i] != 0)
  18123. {
  18124. outputChans [numOutputs++] = outputChannelData[i];
  18125. if (numOutputs >= numElementsInArray (outputChans))
  18126. break;
  18127. }
  18128. }
  18129. if (numInputs > numOutputs)
  18130. {
  18131. // if there aren't enough output channels for the number of
  18132. // inputs, we need to create some temporary extra ones (can't
  18133. // use the input data in case it gets written to)
  18134. tempBuffer.setSize (numInputs - numOutputs, numSamples,
  18135. false, false, true);
  18136. for (i = 0; i < numOutputs; ++i)
  18137. {
  18138. channels[numActiveChans] = outputChans[i];
  18139. memcpy (channels[numActiveChans], inputChans[i], sizeof (float) * numSamples);
  18140. ++numActiveChans;
  18141. }
  18142. for (i = numOutputs; i < numInputs; ++i)
  18143. {
  18144. channels[numActiveChans] = tempBuffer.getSampleData (i - numOutputs, 0);
  18145. memcpy (channels[numActiveChans], inputChans[i], sizeof (float) * numSamples);
  18146. ++numActiveChans;
  18147. }
  18148. }
  18149. else
  18150. {
  18151. for (i = 0; i < numInputs; ++i)
  18152. {
  18153. channels[numActiveChans] = outputChans[i];
  18154. memcpy (channels[numActiveChans], inputChans[i], sizeof (float) * numSamples);
  18155. ++numActiveChans;
  18156. }
  18157. for (i = numInputs; i < numOutputs; ++i)
  18158. {
  18159. channels[numActiveChans] = outputChans[i];
  18160. zeromem (channels[numActiveChans], sizeof (float) * numSamples);
  18161. ++numActiveChans;
  18162. }
  18163. }
  18164. AudioSampleBuffer buffer (channels, numActiveChans, numSamples);
  18165. info.buffer = &buffer;
  18166. info.startSample = 0;
  18167. info.numSamples = numSamples;
  18168. source->getNextAudioBlock (info);
  18169. for (i = info.buffer->getNumChannels(); --i >= 0;)
  18170. info.buffer->applyGainRamp (i, info.startSample, info.numSamples, lastGain, gain);
  18171. lastGain = gain;
  18172. }
  18173. else
  18174. {
  18175. for (int i = 0; i < totalNumOutputChannels; ++i)
  18176. if (outputChannelData[i] != 0)
  18177. zeromem (outputChannelData[i], sizeof (float) * numSamples);
  18178. }
  18179. }
  18180. void AudioSourcePlayer::audioDeviceAboutToStart (AudioIODevice* device)
  18181. {
  18182. sampleRate = device->getCurrentSampleRate();
  18183. bufferSize = device->getCurrentBufferSizeSamples();
  18184. zeromem (channels, sizeof (channels));
  18185. if (source != 0)
  18186. source->prepareToPlay (bufferSize, sampleRate);
  18187. }
  18188. void AudioSourcePlayer::audioDeviceStopped()
  18189. {
  18190. if (source != 0)
  18191. source->releaseResources();
  18192. sampleRate = 0.0;
  18193. bufferSize = 0;
  18194. tempBuffer.setSize (2, 8);
  18195. }
  18196. END_JUCE_NAMESPACE
  18197. /*** End of inlined file: juce_AudioSourcePlayer.cpp ***/
  18198. /*** Start of inlined file: juce_AudioTransportSource.cpp ***/
  18199. BEGIN_JUCE_NAMESPACE
  18200. AudioTransportSource::AudioTransportSource()
  18201. : source (0),
  18202. resamplerSource (0),
  18203. bufferingSource (0),
  18204. positionableSource (0),
  18205. masterSource (0),
  18206. gain (1.0f),
  18207. lastGain (1.0f),
  18208. playing (false),
  18209. stopped (true),
  18210. sampleRate (44100.0),
  18211. sourceSampleRate (0.0),
  18212. blockSize (128),
  18213. readAheadBufferSize (0),
  18214. isPrepared (false),
  18215. inputStreamEOF (false)
  18216. {
  18217. }
  18218. AudioTransportSource::~AudioTransportSource()
  18219. {
  18220. setSource (0);
  18221. releaseResources();
  18222. }
  18223. void AudioTransportSource::setSource (PositionableAudioSource* const newSource,
  18224. int readAheadBufferSize_,
  18225. double sourceSampleRateToCorrectFor)
  18226. {
  18227. if (source == newSource)
  18228. {
  18229. if (source == 0)
  18230. return;
  18231. setSource (0, 0, 0); // deselect and reselect to avoid releasing resources wrongly
  18232. }
  18233. readAheadBufferSize = readAheadBufferSize_;
  18234. sourceSampleRate = sourceSampleRateToCorrectFor;
  18235. ResamplingAudioSource* newResamplerSource = 0;
  18236. BufferingAudioSource* newBufferingSource = 0;
  18237. PositionableAudioSource* newPositionableSource = 0;
  18238. AudioSource* newMasterSource = 0;
  18239. ScopedPointer <ResamplingAudioSource> oldResamplerSource (resamplerSource);
  18240. ScopedPointer <BufferingAudioSource> oldBufferingSource (bufferingSource);
  18241. AudioSource* oldMasterSource = masterSource;
  18242. if (newSource != 0)
  18243. {
  18244. newPositionableSource = newSource;
  18245. if (readAheadBufferSize_ > 0)
  18246. newPositionableSource = newBufferingSource
  18247. = new BufferingAudioSource (newPositionableSource, false, readAheadBufferSize_);
  18248. newPositionableSource->setNextReadPosition (0);
  18249. if (sourceSampleRateToCorrectFor != 0)
  18250. newMasterSource = newResamplerSource
  18251. = new ResamplingAudioSource (newPositionableSource, false);
  18252. else
  18253. newMasterSource = newPositionableSource;
  18254. if (isPrepared)
  18255. {
  18256. if (newResamplerSource != 0 && sourceSampleRate > 0 && sampleRate > 0)
  18257. newResamplerSource->setResamplingRatio (sourceSampleRate / sampleRate);
  18258. newMasterSource->prepareToPlay (blockSize, sampleRate);
  18259. }
  18260. }
  18261. {
  18262. const ScopedLock sl (callbackLock);
  18263. source = newSource;
  18264. resamplerSource = newResamplerSource;
  18265. bufferingSource = newBufferingSource;
  18266. masterSource = newMasterSource;
  18267. positionableSource = newPositionableSource;
  18268. playing = false;
  18269. }
  18270. if (oldMasterSource != 0)
  18271. oldMasterSource->releaseResources();
  18272. }
  18273. void AudioTransportSource::start()
  18274. {
  18275. if ((! playing) && masterSource != 0)
  18276. {
  18277. {
  18278. const ScopedLock sl (callbackLock);
  18279. playing = true;
  18280. stopped = false;
  18281. inputStreamEOF = false;
  18282. }
  18283. sendChangeMessage (this);
  18284. }
  18285. }
  18286. void AudioTransportSource::stop()
  18287. {
  18288. if (playing)
  18289. {
  18290. {
  18291. const ScopedLock sl (callbackLock);
  18292. playing = false;
  18293. }
  18294. int n = 500;
  18295. while (--n >= 0 && ! stopped)
  18296. Thread::sleep (2);
  18297. sendChangeMessage (this);
  18298. }
  18299. }
  18300. void AudioTransportSource::setPosition (double newPosition)
  18301. {
  18302. if (sampleRate > 0.0)
  18303. setNextReadPosition (roundToInt (newPosition * sampleRate));
  18304. }
  18305. double AudioTransportSource::getCurrentPosition() const
  18306. {
  18307. if (sampleRate > 0.0)
  18308. return getNextReadPosition() / sampleRate;
  18309. else
  18310. return 0.0;
  18311. }
  18312. void AudioTransportSource::setNextReadPosition (int newPosition)
  18313. {
  18314. if (positionableSource != 0)
  18315. {
  18316. if (sampleRate > 0 && sourceSampleRate > 0)
  18317. newPosition = roundToInt (newPosition * sourceSampleRate / sampleRate);
  18318. positionableSource->setNextReadPosition (newPosition);
  18319. }
  18320. }
  18321. int AudioTransportSource::getNextReadPosition() const
  18322. {
  18323. if (positionableSource != 0)
  18324. {
  18325. const double ratio = (sampleRate > 0 && sourceSampleRate > 0) ? sampleRate / sourceSampleRate : 1.0;
  18326. return roundToInt (positionableSource->getNextReadPosition() * ratio);
  18327. }
  18328. return 0;
  18329. }
  18330. int AudioTransportSource::getTotalLength() const
  18331. {
  18332. const ScopedLock sl (callbackLock);
  18333. if (positionableSource != 0)
  18334. {
  18335. const double ratio = (sampleRate > 0 && sourceSampleRate > 0) ? sampleRate / sourceSampleRate : 1.0;
  18336. return roundToInt (positionableSource->getTotalLength() * ratio);
  18337. }
  18338. return 0;
  18339. }
  18340. bool AudioTransportSource::isLooping() const
  18341. {
  18342. const ScopedLock sl (callbackLock);
  18343. return positionableSource != 0
  18344. && positionableSource->isLooping();
  18345. }
  18346. void AudioTransportSource::setGain (const float newGain) throw()
  18347. {
  18348. gain = newGain;
  18349. }
  18350. void AudioTransportSource::prepareToPlay (int samplesPerBlockExpected,
  18351. double sampleRate_)
  18352. {
  18353. const ScopedLock sl (callbackLock);
  18354. sampleRate = sampleRate_;
  18355. blockSize = samplesPerBlockExpected;
  18356. if (masterSource != 0)
  18357. masterSource->prepareToPlay (samplesPerBlockExpected, sampleRate);
  18358. if (resamplerSource != 0 && sourceSampleRate != 0)
  18359. resamplerSource->setResamplingRatio (sourceSampleRate / sampleRate);
  18360. isPrepared = true;
  18361. }
  18362. void AudioTransportSource::releaseResources()
  18363. {
  18364. const ScopedLock sl (callbackLock);
  18365. if (masterSource != 0)
  18366. masterSource->releaseResources();
  18367. isPrepared = false;
  18368. }
  18369. void AudioTransportSource::getNextAudioBlock (const AudioSourceChannelInfo& info)
  18370. {
  18371. const ScopedLock sl (callbackLock);
  18372. inputStreamEOF = false;
  18373. if (masterSource != 0 && ! stopped)
  18374. {
  18375. masterSource->getNextAudioBlock (info);
  18376. if (! playing)
  18377. {
  18378. // just stopped playing, so fade out the last block..
  18379. for (int i = info.buffer->getNumChannels(); --i >= 0;)
  18380. info.buffer->applyGainRamp (i, info.startSample, jmin (256, info.numSamples), 1.0f, 0.0f);
  18381. if (info.numSamples > 256)
  18382. info.buffer->clear (info.startSample + 256, info.numSamples - 256);
  18383. }
  18384. if (positionableSource->getNextReadPosition() > positionableSource->getTotalLength() + 1
  18385. && ! positionableSource->isLooping())
  18386. {
  18387. playing = false;
  18388. inputStreamEOF = true;
  18389. sendChangeMessage (this);
  18390. }
  18391. stopped = ! playing;
  18392. for (int i = info.buffer->getNumChannels(); --i >= 0;)
  18393. {
  18394. info.buffer->applyGainRamp (i, info.startSample, info.numSamples,
  18395. lastGain, gain);
  18396. }
  18397. }
  18398. else
  18399. {
  18400. info.clearActiveBufferRegion();
  18401. stopped = true;
  18402. }
  18403. lastGain = gain;
  18404. }
  18405. END_JUCE_NAMESPACE
  18406. /*** End of inlined file: juce_AudioTransportSource.cpp ***/
  18407. /*** Start of inlined file: juce_BufferingAudioSource.cpp ***/
  18408. BEGIN_JUCE_NAMESPACE
  18409. class SharedBufferingAudioSourceThread : public DeletedAtShutdown,
  18410. public Thread,
  18411. private Timer
  18412. {
  18413. public:
  18414. SharedBufferingAudioSourceThread()
  18415. : Thread ("Audio Buffer")
  18416. {
  18417. }
  18418. ~SharedBufferingAudioSourceThread()
  18419. {
  18420. stopThread (10000);
  18421. clearSingletonInstance();
  18422. }
  18423. juce_DeclareSingleton (SharedBufferingAudioSourceThread, false)
  18424. void addSource (BufferingAudioSource* source)
  18425. {
  18426. const ScopedLock sl (lock);
  18427. if (! sources.contains ((void*) source))
  18428. {
  18429. sources.add ((void*) source);
  18430. startThread();
  18431. stopTimer();
  18432. }
  18433. notify();
  18434. }
  18435. void removeSource (BufferingAudioSource* source)
  18436. {
  18437. const ScopedLock sl (lock);
  18438. sources.removeValue ((void*) source);
  18439. if (sources.size() == 0)
  18440. startTimer (5000);
  18441. }
  18442. private:
  18443. VoidArray sources;
  18444. CriticalSection lock;
  18445. void run()
  18446. {
  18447. while (! threadShouldExit())
  18448. {
  18449. bool busy = false;
  18450. for (int i = sources.size(); --i >= 0;)
  18451. {
  18452. if (threadShouldExit())
  18453. return;
  18454. const ScopedLock sl (lock);
  18455. BufferingAudioSource* const b = (BufferingAudioSource*) sources[i];
  18456. if (b != 0 && b->readNextBufferChunk())
  18457. busy = true;
  18458. }
  18459. if (! busy)
  18460. wait (500);
  18461. }
  18462. }
  18463. void timerCallback()
  18464. {
  18465. stopTimer();
  18466. if (sources.size() == 0)
  18467. deleteInstance();
  18468. }
  18469. SharedBufferingAudioSourceThread (const SharedBufferingAudioSourceThread&);
  18470. SharedBufferingAudioSourceThread& operator= (const SharedBufferingAudioSourceThread&);
  18471. };
  18472. juce_ImplementSingleton (SharedBufferingAudioSourceThread)
  18473. BufferingAudioSource::BufferingAudioSource (PositionableAudioSource* source_,
  18474. const bool deleteSourceWhenDeleted_,
  18475. int numberOfSamplesToBuffer_)
  18476. : source (source_),
  18477. deleteSourceWhenDeleted (deleteSourceWhenDeleted_),
  18478. numberOfSamplesToBuffer (jmax (1024, numberOfSamplesToBuffer_)),
  18479. buffer (2, 0),
  18480. bufferValidStart (0),
  18481. bufferValidEnd (0),
  18482. nextPlayPos (0),
  18483. wasSourceLooping (false)
  18484. {
  18485. jassert (source_ != 0);
  18486. jassert (numberOfSamplesToBuffer_ > 1024); // not much point using this class if you're
  18487. // not using a larger buffer..
  18488. }
  18489. BufferingAudioSource::~BufferingAudioSource()
  18490. {
  18491. SharedBufferingAudioSourceThread* const thread = SharedBufferingAudioSourceThread::getInstanceWithoutCreating();
  18492. if (thread != 0)
  18493. thread->removeSource (this);
  18494. if (deleteSourceWhenDeleted)
  18495. delete source;
  18496. }
  18497. void BufferingAudioSource::prepareToPlay (int samplesPerBlockExpected, double sampleRate_)
  18498. {
  18499. source->prepareToPlay (samplesPerBlockExpected, sampleRate_);
  18500. sampleRate = sampleRate_;
  18501. buffer.setSize (2, jmax (samplesPerBlockExpected * 2, numberOfSamplesToBuffer));
  18502. buffer.clear();
  18503. bufferValidStart = 0;
  18504. bufferValidEnd = 0;
  18505. SharedBufferingAudioSourceThread::getInstance()->addSource (this);
  18506. while (bufferValidEnd - bufferValidStart < jmin (((int) sampleRate_) / 4,
  18507. buffer.getNumSamples() / 2))
  18508. {
  18509. SharedBufferingAudioSourceThread::getInstance()->notify();
  18510. Thread::sleep (5);
  18511. }
  18512. }
  18513. void BufferingAudioSource::releaseResources()
  18514. {
  18515. SharedBufferingAudioSourceThread* const thread = SharedBufferingAudioSourceThread::getInstanceWithoutCreating();
  18516. if (thread != 0)
  18517. thread->removeSource (this);
  18518. buffer.setSize (2, 0);
  18519. source->releaseResources();
  18520. }
  18521. void BufferingAudioSource::getNextAudioBlock (const AudioSourceChannelInfo& info)
  18522. {
  18523. const ScopedLock sl (bufferStartPosLock);
  18524. const int validStart = jlimit (bufferValidStart, bufferValidEnd, nextPlayPos) - nextPlayPos;
  18525. const int validEnd = jlimit (bufferValidStart, bufferValidEnd, nextPlayPos + info.numSamples) - nextPlayPos;
  18526. if (validStart == validEnd)
  18527. {
  18528. // total cache miss
  18529. info.clearActiveBufferRegion();
  18530. }
  18531. else
  18532. {
  18533. if (validStart > 0)
  18534. info.buffer->clear (info.startSample, validStart); // partial cache miss at start
  18535. if (validEnd < info.numSamples)
  18536. info.buffer->clear (info.startSample + validEnd,
  18537. info.numSamples - validEnd); // partial cache miss at end
  18538. if (validStart < validEnd)
  18539. {
  18540. for (int chan = jmin (2, info.buffer->getNumChannels()); --chan >= 0;)
  18541. {
  18542. const int startBufferIndex = (validStart + nextPlayPos) % buffer.getNumSamples();
  18543. const int endBufferIndex = (validEnd + nextPlayPos) % buffer.getNumSamples();
  18544. if (startBufferIndex < endBufferIndex)
  18545. {
  18546. info.buffer->copyFrom (chan, info.startSample + validStart,
  18547. buffer,
  18548. chan, startBufferIndex,
  18549. validEnd - validStart);
  18550. }
  18551. else
  18552. {
  18553. const int initialSize = buffer.getNumSamples() - startBufferIndex;
  18554. info.buffer->copyFrom (chan, info.startSample + validStart,
  18555. buffer,
  18556. chan, startBufferIndex,
  18557. initialSize);
  18558. info.buffer->copyFrom (chan, info.startSample + validStart + initialSize,
  18559. buffer,
  18560. chan, 0,
  18561. (validEnd - validStart) - initialSize);
  18562. }
  18563. }
  18564. }
  18565. nextPlayPos += info.numSamples;
  18566. if (source->isLooping() && nextPlayPos > 0)
  18567. nextPlayPos %= source->getTotalLength();
  18568. }
  18569. SharedBufferingAudioSourceThread* const thread = SharedBufferingAudioSourceThread::getInstanceWithoutCreating();
  18570. if (thread != 0)
  18571. thread->notify();
  18572. }
  18573. int BufferingAudioSource::getNextReadPosition() const
  18574. {
  18575. return (source->isLooping() && nextPlayPos > 0)
  18576. ? nextPlayPos % source->getTotalLength()
  18577. : nextPlayPos;
  18578. }
  18579. void BufferingAudioSource::setNextReadPosition (int newPosition)
  18580. {
  18581. const ScopedLock sl (bufferStartPosLock);
  18582. nextPlayPos = newPosition;
  18583. SharedBufferingAudioSourceThread* const thread = SharedBufferingAudioSourceThread::getInstanceWithoutCreating();
  18584. if (thread != 0)
  18585. thread->notify();
  18586. }
  18587. bool BufferingAudioSource::readNextBufferChunk()
  18588. {
  18589. int newBVS, newBVE, sectionToReadStart, sectionToReadEnd;
  18590. {
  18591. const ScopedLock sl (bufferStartPosLock);
  18592. if (wasSourceLooping != isLooping())
  18593. {
  18594. wasSourceLooping = isLooping();
  18595. bufferValidStart = 0;
  18596. bufferValidEnd = 0;
  18597. }
  18598. newBVS = jmax (0, nextPlayPos);
  18599. newBVE = newBVS + buffer.getNumSamples() - 4;
  18600. sectionToReadStart = 0;
  18601. sectionToReadEnd = 0;
  18602. const int maxChunkSize = 2048;
  18603. if (newBVS < bufferValidStart || newBVS >= bufferValidEnd)
  18604. {
  18605. newBVE = jmin (newBVE, newBVS + maxChunkSize);
  18606. sectionToReadStart = newBVS;
  18607. sectionToReadEnd = newBVE;
  18608. bufferValidStart = 0;
  18609. bufferValidEnd = 0;
  18610. }
  18611. else if (abs (newBVS - bufferValidStart) > 512
  18612. || abs (newBVE - bufferValidEnd) > 512)
  18613. {
  18614. newBVE = jmin (newBVE, bufferValidEnd + maxChunkSize);
  18615. sectionToReadStart = bufferValidEnd;
  18616. sectionToReadEnd = newBVE;
  18617. bufferValidStart = newBVS;
  18618. bufferValidEnd = jmin (bufferValidEnd, newBVE);
  18619. }
  18620. }
  18621. if (sectionToReadStart != sectionToReadEnd)
  18622. {
  18623. const int bufferIndexStart = sectionToReadStart % buffer.getNumSamples();
  18624. const int bufferIndexEnd = sectionToReadEnd % buffer.getNumSamples();
  18625. if (bufferIndexStart < bufferIndexEnd)
  18626. {
  18627. readBufferSection (sectionToReadStart,
  18628. sectionToReadEnd - sectionToReadStart,
  18629. bufferIndexStart);
  18630. }
  18631. else
  18632. {
  18633. const int initialSize = buffer.getNumSamples() - bufferIndexStart;
  18634. readBufferSection (sectionToReadStart,
  18635. initialSize,
  18636. bufferIndexStart);
  18637. readBufferSection (sectionToReadStart + initialSize,
  18638. (sectionToReadEnd - sectionToReadStart) - initialSize,
  18639. 0);
  18640. }
  18641. const ScopedLock sl2 (bufferStartPosLock);
  18642. bufferValidStart = newBVS;
  18643. bufferValidEnd = newBVE;
  18644. return true;
  18645. }
  18646. else
  18647. {
  18648. return false;
  18649. }
  18650. }
  18651. void BufferingAudioSource::readBufferSection (int start, int length, int bufferOffset)
  18652. {
  18653. if (source->getNextReadPosition() != start)
  18654. source->setNextReadPosition (start);
  18655. AudioSourceChannelInfo info;
  18656. info.buffer = &buffer;
  18657. info.startSample = bufferOffset;
  18658. info.numSamples = length;
  18659. source->getNextAudioBlock (info);
  18660. }
  18661. END_JUCE_NAMESPACE
  18662. /*** End of inlined file: juce_BufferingAudioSource.cpp ***/
  18663. /*** Start of inlined file: juce_ChannelRemappingAudioSource.cpp ***/
  18664. BEGIN_JUCE_NAMESPACE
  18665. ChannelRemappingAudioSource::ChannelRemappingAudioSource (AudioSource* const source_,
  18666. const bool deleteSourceWhenDeleted_)
  18667. : requiredNumberOfChannels (2),
  18668. source (source_),
  18669. deleteSourceWhenDeleted (deleteSourceWhenDeleted_),
  18670. buffer (2, 16)
  18671. {
  18672. remappedInfo.buffer = &buffer;
  18673. remappedInfo.startSample = 0;
  18674. }
  18675. ChannelRemappingAudioSource::~ChannelRemappingAudioSource()
  18676. {
  18677. if (deleteSourceWhenDeleted)
  18678. delete source;
  18679. }
  18680. void ChannelRemappingAudioSource::setNumberOfChannelsToProduce (const int requiredNumberOfChannels_) throw()
  18681. {
  18682. const ScopedLock sl (lock);
  18683. requiredNumberOfChannels = requiredNumberOfChannels_;
  18684. }
  18685. void ChannelRemappingAudioSource::clearAllMappings() throw()
  18686. {
  18687. const ScopedLock sl (lock);
  18688. remappedInputs.clear();
  18689. remappedOutputs.clear();
  18690. }
  18691. void ChannelRemappingAudioSource::setInputChannelMapping (const int destIndex, const int sourceIndex) throw()
  18692. {
  18693. const ScopedLock sl (lock);
  18694. while (remappedInputs.size() < destIndex)
  18695. remappedInputs.add (-1);
  18696. remappedInputs.set (destIndex, sourceIndex);
  18697. }
  18698. void ChannelRemappingAudioSource::setOutputChannelMapping (const int sourceIndex, const int destIndex) throw()
  18699. {
  18700. const ScopedLock sl (lock);
  18701. while (remappedOutputs.size() < sourceIndex)
  18702. remappedOutputs.add (-1);
  18703. remappedOutputs.set (sourceIndex, destIndex);
  18704. }
  18705. int ChannelRemappingAudioSource::getRemappedInputChannel (const int inputChannelIndex) const throw()
  18706. {
  18707. const ScopedLock sl (lock);
  18708. if (inputChannelIndex >= 0 && inputChannelIndex < remappedInputs.size())
  18709. return remappedInputs.getUnchecked (inputChannelIndex);
  18710. return -1;
  18711. }
  18712. int ChannelRemappingAudioSource::getRemappedOutputChannel (const int outputChannelIndex) const throw()
  18713. {
  18714. const ScopedLock sl (lock);
  18715. if (outputChannelIndex >= 0 && outputChannelIndex < remappedOutputs.size())
  18716. return remappedOutputs .getUnchecked (outputChannelIndex);
  18717. return -1;
  18718. }
  18719. void ChannelRemappingAudioSource::prepareToPlay (int samplesPerBlockExpected, double sampleRate)
  18720. {
  18721. source->prepareToPlay (samplesPerBlockExpected, sampleRate);
  18722. }
  18723. void ChannelRemappingAudioSource::releaseResources()
  18724. {
  18725. source->releaseResources();
  18726. }
  18727. void ChannelRemappingAudioSource::getNextAudioBlock (const AudioSourceChannelInfo& bufferToFill)
  18728. {
  18729. const ScopedLock sl (lock);
  18730. buffer.setSize (requiredNumberOfChannels, bufferToFill.numSamples, false, false, true);
  18731. const int numChans = bufferToFill.buffer->getNumChannels();
  18732. int i;
  18733. for (i = 0; i < buffer.getNumChannels(); ++i)
  18734. {
  18735. const int remappedChan = getRemappedInputChannel (i);
  18736. if (remappedChan >= 0 && remappedChan < numChans)
  18737. {
  18738. buffer.copyFrom (i, 0, *bufferToFill.buffer,
  18739. remappedChan,
  18740. bufferToFill.startSample,
  18741. bufferToFill.numSamples);
  18742. }
  18743. else
  18744. {
  18745. buffer.clear (i, 0, bufferToFill.numSamples);
  18746. }
  18747. }
  18748. remappedInfo.numSamples = bufferToFill.numSamples;
  18749. source->getNextAudioBlock (remappedInfo);
  18750. bufferToFill.clearActiveBufferRegion();
  18751. for (i = 0; i < requiredNumberOfChannels; ++i)
  18752. {
  18753. const int remappedChan = getRemappedOutputChannel (i);
  18754. if (remappedChan >= 0 && remappedChan < numChans)
  18755. {
  18756. bufferToFill.buffer->addFrom (remappedChan, bufferToFill.startSample,
  18757. buffer, i, 0, bufferToFill.numSamples);
  18758. }
  18759. }
  18760. }
  18761. XmlElement* ChannelRemappingAudioSource::createXml() const throw()
  18762. {
  18763. XmlElement* e = new XmlElement (T("MAPPINGS"));
  18764. String ins, outs;
  18765. int i;
  18766. const ScopedLock sl (lock);
  18767. for (i = 0; i < remappedInputs.size(); ++i)
  18768. ins << remappedInputs.getUnchecked(i) << T(' ');
  18769. for (i = 0; i < remappedOutputs.size(); ++i)
  18770. outs << remappedOutputs.getUnchecked(i) << T(' ');
  18771. e->setAttribute (T("inputs"), ins.trimEnd());
  18772. e->setAttribute (T("outputs"), outs.trimEnd());
  18773. return e;
  18774. }
  18775. void ChannelRemappingAudioSource::restoreFromXml (const XmlElement& e) throw()
  18776. {
  18777. if (e.hasTagName (T("MAPPINGS")))
  18778. {
  18779. const ScopedLock sl (lock);
  18780. clearAllMappings();
  18781. StringArray ins, outs;
  18782. ins.addTokens (e.getStringAttribute (T("inputs")), false);
  18783. outs.addTokens (e.getStringAttribute (T("outputs")), false);
  18784. int i;
  18785. for (i = 0; i < ins.size(); ++i)
  18786. remappedInputs.add (ins[i].getIntValue());
  18787. for (i = 0; i < outs.size(); ++i)
  18788. remappedOutputs.add (outs[i].getIntValue());
  18789. }
  18790. }
  18791. END_JUCE_NAMESPACE
  18792. /*** End of inlined file: juce_ChannelRemappingAudioSource.cpp ***/
  18793. /*** Start of inlined file: juce_IIRFilterAudioSource.cpp ***/
  18794. BEGIN_JUCE_NAMESPACE
  18795. IIRFilterAudioSource::IIRFilterAudioSource (AudioSource* const inputSource,
  18796. const bool deleteInputWhenDeleted_)
  18797. : input (inputSource),
  18798. deleteInputWhenDeleted (deleteInputWhenDeleted_)
  18799. {
  18800. jassert (inputSource != 0);
  18801. for (int i = 2; --i >= 0;)
  18802. iirFilters.add (new IIRFilter());
  18803. }
  18804. IIRFilterAudioSource::~IIRFilterAudioSource()
  18805. {
  18806. if (deleteInputWhenDeleted)
  18807. delete input;
  18808. }
  18809. void IIRFilterAudioSource::setFilterParameters (const IIRFilter& newSettings)
  18810. {
  18811. for (int i = iirFilters.size(); --i >= 0;)
  18812. iirFilters.getUnchecked(i)->copyCoefficientsFrom (newSettings);
  18813. }
  18814. void IIRFilterAudioSource::prepareToPlay (int samplesPerBlockExpected, double sampleRate)
  18815. {
  18816. input->prepareToPlay (samplesPerBlockExpected, sampleRate);
  18817. for (int i = iirFilters.size(); --i >= 0;)
  18818. iirFilters.getUnchecked(i)->reset();
  18819. }
  18820. void IIRFilterAudioSource::releaseResources()
  18821. {
  18822. input->releaseResources();
  18823. }
  18824. void IIRFilterAudioSource::getNextAudioBlock (const AudioSourceChannelInfo& bufferToFill)
  18825. {
  18826. input->getNextAudioBlock (bufferToFill);
  18827. const int numChannels = bufferToFill.buffer->getNumChannels();
  18828. while (numChannels > iirFilters.size())
  18829. iirFilters.add (new IIRFilter (*iirFilters.getUnchecked (0)));
  18830. for (int i = 0; i < numChannels; ++i)
  18831. iirFilters.getUnchecked(i)
  18832. ->processSamples (bufferToFill.buffer->getSampleData (i, bufferToFill.startSample),
  18833. bufferToFill.numSamples);
  18834. }
  18835. END_JUCE_NAMESPACE
  18836. /*** End of inlined file: juce_IIRFilterAudioSource.cpp ***/
  18837. /*** Start of inlined file: juce_MixerAudioSource.cpp ***/
  18838. BEGIN_JUCE_NAMESPACE
  18839. MixerAudioSource::MixerAudioSource()
  18840. : tempBuffer (2, 0),
  18841. currentSampleRate (0.0),
  18842. bufferSizeExpected (0)
  18843. {
  18844. }
  18845. MixerAudioSource::~MixerAudioSource()
  18846. {
  18847. removeAllInputs();
  18848. }
  18849. void MixerAudioSource::addInputSource (AudioSource* input, const bool deleteWhenRemoved)
  18850. {
  18851. if (input != 0 && ! inputs.contains (input))
  18852. {
  18853. double localRate;
  18854. int localBufferSize;
  18855. {
  18856. const ScopedLock sl (lock);
  18857. localRate = currentSampleRate;
  18858. localBufferSize = bufferSizeExpected;
  18859. }
  18860. if (localRate != 0.0)
  18861. input->prepareToPlay (localBufferSize, localRate);
  18862. const ScopedLock sl (lock);
  18863. inputsToDelete.setBit (inputs.size(), deleteWhenRemoved);
  18864. inputs.add (input);
  18865. }
  18866. }
  18867. void MixerAudioSource::removeInputSource (AudioSource* input, const bool deleteInput)
  18868. {
  18869. if (input != 0)
  18870. {
  18871. int index;
  18872. {
  18873. const ScopedLock sl (lock);
  18874. index = inputs.indexOf ((void*) input);
  18875. if (index >= 0)
  18876. {
  18877. inputsToDelete.shiftBits (index, 1);
  18878. inputs.remove (index);
  18879. }
  18880. }
  18881. if (index >= 0)
  18882. {
  18883. input->releaseResources();
  18884. if (deleteInput)
  18885. delete input;
  18886. }
  18887. }
  18888. }
  18889. void MixerAudioSource::removeAllInputs()
  18890. {
  18891. VoidArray inputsCopy;
  18892. BigInteger inputsToDeleteCopy;
  18893. {
  18894. const ScopedLock sl (lock);
  18895. inputsCopy = inputs;
  18896. inputsToDeleteCopy = inputsToDelete;
  18897. }
  18898. for (int i = inputsCopy.size(); --i >= 0;)
  18899. if (inputsToDeleteCopy[i])
  18900. delete (AudioSource*) inputsCopy[i];
  18901. }
  18902. void MixerAudioSource::prepareToPlay (int samplesPerBlockExpected, double sampleRate)
  18903. {
  18904. tempBuffer.setSize (2, samplesPerBlockExpected);
  18905. const ScopedLock sl (lock);
  18906. currentSampleRate = sampleRate;
  18907. bufferSizeExpected = samplesPerBlockExpected;
  18908. for (int i = inputs.size(); --i >= 0;)
  18909. ((AudioSource*) inputs.getUnchecked(i))->prepareToPlay (samplesPerBlockExpected,
  18910. sampleRate);
  18911. }
  18912. void MixerAudioSource::releaseResources()
  18913. {
  18914. const ScopedLock sl (lock);
  18915. for (int i = inputs.size(); --i >= 0;)
  18916. ((AudioSource*) inputs.getUnchecked(i))->releaseResources();
  18917. tempBuffer.setSize (2, 0);
  18918. currentSampleRate = 0;
  18919. bufferSizeExpected = 0;
  18920. }
  18921. void MixerAudioSource::getNextAudioBlock (const AudioSourceChannelInfo& info)
  18922. {
  18923. const ScopedLock sl (lock);
  18924. if (inputs.size() > 0)
  18925. {
  18926. ((AudioSource*) inputs.getUnchecked(0))->getNextAudioBlock (info);
  18927. if (inputs.size() > 1)
  18928. {
  18929. tempBuffer.setSize (jmax (1, info.buffer->getNumChannels()),
  18930. info.buffer->getNumSamples());
  18931. AudioSourceChannelInfo info2;
  18932. info2.buffer = &tempBuffer;
  18933. info2.numSamples = info.numSamples;
  18934. info2.startSample = 0;
  18935. for (int i = 1; i < inputs.size(); ++i)
  18936. {
  18937. ((AudioSource*) inputs.getUnchecked(i))->getNextAudioBlock (info2);
  18938. for (int chan = 0; chan < info.buffer->getNumChannels(); ++chan)
  18939. info.buffer->addFrom (chan, info.startSample, tempBuffer, chan, 0, info.numSamples);
  18940. }
  18941. }
  18942. }
  18943. else
  18944. {
  18945. info.clearActiveBufferRegion();
  18946. }
  18947. }
  18948. END_JUCE_NAMESPACE
  18949. /*** End of inlined file: juce_MixerAudioSource.cpp ***/
  18950. /*** Start of inlined file: juce_ResamplingAudioSource.cpp ***/
  18951. BEGIN_JUCE_NAMESPACE
  18952. ResamplingAudioSource::ResamplingAudioSource (AudioSource* const inputSource,
  18953. const bool deleteInputWhenDeleted_)
  18954. : input (inputSource),
  18955. deleteInputWhenDeleted (deleteInputWhenDeleted_),
  18956. ratio (1.0),
  18957. lastRatio (1.0),
  18958. buffer (2, 0),
  18959. sampsInBuffer (0)
  18960. {
  18961. jassert (input != 0);
  18962. }
  18963. ResamplingAudioSource::~ResamplingAudioSource()
  18964. {
  18965. if (deleteInputWhenDeleted)
  18966. delete input;
  18967. }
  18968. void ResamplingAudioSource::setResamplingRatio (const double samplesInPerOutputSample)
  18969. {
  18970. jassert (samplesInPerOutputSample > 0);
  18971. const ScopedLock sl (ratioLock);
  18972. ratio = jmax (0.0, samplesInPerOutputSample);
  18973. }
  18974. void ResamplingAudioSource::prepareToPlay (int samplesPerBlockExpected,
  18975. double sampleRate)
  18976. {
  18977. const ScopedLock sl (ratioLock);
  18978. input->prepareToPlay (samplesPerBlockExpected, sampleRate);
  18979. buffer.setSize (2, roundToInt (samplesPerBlockExpected * ratio) + 32);
  18980. buffer.clear();
  18981. sampsInBuffer = 0;
  18982. bufferPos = 0;
  18983. subSampleOffset = 0.0;
  18984. createLowPass (ratio);
  18985. resetFilters();
  18986. }
  18987. void ResamplingAudioSource::releaseResources()
  18988. {
  18989. input->releaseResources();
  18990. buffer.setSize (2, 0);
  18991. }
  18992. void ResamplingAudioSource::getNextAudioBlock (const AudioSourceChannelInfo& info)
  18993. {
  18994. const ScopedLock sl (ratioLock);
  18995. if (lastRatio != ratio)
  18996. {
  18997. createLowPass (ratio);
  18998. lastRatio = ratio;
  18999. }
  19000. const int sampsNeeded = roundToInt (info.numSamples * ratio) + 2;
  19001. int bufferSize = buffer.getNumSamples();
  19002. if (bufferSize < sampsNeeded + 8)
  19003. {
  19004. bufferPos %= bufferSize;
  19005. bufferSize = sampsNeeded + 32;
  19006. buffer.setSize (buffer.getNumChannels(), bufferSize, true, true);
  19007. }
  19008. bufferPos %= bufferSize;
  19009. int endOfBufferPos = bufferPos + sampsInBuffer;
  19010. while (sampsNeeded > sampsInBuffer)
  19011. {
  19012. endOfBufferPos %= bufferSize;
  19013. int numToDo = jmin (sampsNeeded - sampsInBuffer,
  19014. bufferSize - endOfBufferPos);
  19015. AudioSourceChannelInfo readInfo;
  19016. readInfo.buffer = &buffer;
  19017. readInfo.numSamples = numToDo;
  19018. readInfo.startSample = endOfBufferPos;
  19019. input->getNextAudioBlock (readInfo);
  19020. if (ratio > 1.0001)
  19021. {
  19022. // for down-sampling, pre-apply the filter..
  19023. for (int i = jmin (2, info.buffer->getNumChannels()); --i >= 0;)
  19024. applyFilter (buffer.getSampleData (i, endOfBufferPos), numToDo, filterStates[i]);
  19025. }
  19026. sampsInBuffer += numToDo;
  19027. endOfBufferPos += numToDo;
  19028. }
  19029. float* dl = info.buffer->getSampleData (0, info.startSample);
  19030. float* dr = (info.buffer->getNumChannels() > 1) ? info.buffer->getSampleData (1, info.startSample) : 0;
  19031. const float* const bl = buffer.getSampleData (0, 0);
  19032. const float* const br = buffer.getSampleData (1, 0);
  19033. int nextPos = (bufferPos + 1) % bufferSize;
  19034. for (int m = info.numSamples; --m >= 0;)
  19035. {
  19036. const float alpha = (float) subSampleOffset;
  19037. const float invAlpha = 1.0f - alpha;
  19038. *dl++ = bl [bufferPos] * invAlpha + bl [nextPos] * alpha;
  19039. if (dr != 0)
  19040. *dr++ = br [bufferPos] * invAlpha + br [nextPos] * alpha;
  19041. subSampleOffset += ratio;
  19042. jassert (sampsInBuffer > 0);
  19043. while (subSampleOffset >= 1.0)
  19044. {
  19045. if (++bufferPos >= bufferSize)
  19046. bufferPos = 0;
  19047. --sampsInBuffer;
  19048. nextPos = (bufferPos + 1) % bufferSize;
  19049. subSampleOffset -= 1.0;
  19050. }
  19051. }
  19052. if (ratio < 0.9999)
  19053. {
  19054. // for up-sampling, apply the filter after transposing..
  19055. for (int i = jmin (2, info.buffer->getNumChannels()); --i >= 0;)
  19056. applyFilter (info.buffer->getSampleData (i, info.startSample), info.numSamples, filterStates[i]);
  19057. }
  19058. else if (ratio <= 1.0001)
  19059. {
  19060. // if the filter's not currently being applied, keep it stoked with the last couple of samples to avoid discontinuities
  19061. for (int i = jmin (2, info.buffer->getNumChannels()); --i >= 0;)
  19062. {
  19063. const float* const endOfBuffer = info.buffer->getSampleData (i, info.startSample + info.numSamples - 1);
  19064. FilterState& fs = filterStates[i];
  19065. if (info.numSamples > 1)
  19066. {
  19067. fs.y2 = fs.x2 = *(endOfBuffer - 1);
  19068. }
  19069. else
  19070. {
  19071. fs.y2 = fs.y1;
  19072. fs.x2 = fs.x1;
  19073. }
  19074. fs.y1 = fs.x1 = *endOfBuffer;
  19075. }
  19076. }
  19077. jassert (sampsInBuffer >= 0);
  19078. }
  19079. void ResamplingAudioSource::createLowPass (const double frequencyRatio)
  19080. {
  19081. const double proportionalRate = (frequencyRatio > 1.0) ? 0.5 / frequencyRatio
  19082. : 0.5 * frequencyRatio;
  19083. const double n = 1.0 / tan (double_Pi * jmax (0.001, proportionalRate));
  19084. const double nSquared = n * n;
  19085. const double c1 = 1.0 / (1.0 + sqrt (2.0) * n + nSquared);
  19086. setFilterCoefficients (c1,
  19087. c1 * 2.0f,
  19088. c1,
  19089. 1.0,
  19090. c1 * 2.0 * (1.0 - nSquared),
  19091. c1 * (1.0 - sqrt (2.0) * n + nSquared));
  19092. }
  19093. void ResamplingAudioSource::setFilterCoefficients (double c1, double c2, double c3, double c4, double c5, double c6)
  19094. {
  19095. const double a = 1.0 / c4;
  19096. c1 *= a;
  19097. c2 *= a;
  19098. c3 *= a;
  19099. c5 *= a;
  19100. c6 *= a;
  19101. coefficients[0] = c1;
  19102. coefficients[1] = c2;
  19103. coefficients[2] = c3;
  19104. coefficients[3] = c4;
  19105. coefficients[4] = c5;
  19106. coefficients[5] = c6;
  19107. }
  19108. void ResamplingAudioSource::resetFilters()
  19109. {
  19110. zeromem (filterStates, sizeof (filterStates));
  19111. }
  19112. void ResamplingAudioSource::applyFilter (float* samples, int num, FilterState& fs)
  19113. {
  19114. while (--num >= 0)
  19115. {
  19116. const double in = *samples;
  19117. double out = coefficients[0] * in
  19118. + coefficients[1] * fs.x1
  19119. + coefficients[2] * fs.x2
  19120. - coefficients[4] * fs.y1
  19121. - coefficients[5] * fs.y2;
  19122. #if JUCE_INTEL
  19123. if (! (out < -1.0e-8 || out > 1.0e-8))
  19124. out = 0;
  19125. #endif
  19126. fs.x2 = fs.x1;
  19127. fs.x1 = in;
  19128. fs.y2 = fs.y1;
  19129. fs.y1 = out;
  19130. *samples++ = (float) out;
  19131. }
  19132. }
  19133. END_JUCE_NAMESPACE
  19134. /*** End of inlined file: juce_ResamplingAudioSource.cpp ***/
  19135. /*** Start of inlined file: juce_ToneGeneratorAudioSource.cpp ***/
  19136. BEGIN_JUCE_NAMESPACE
  19137. ToneGeneratorAudioSource::ToneGeneratorAudioSource()
  19138. : frequency (1000.0),
  19139. sampleRate (44100.0),
  19140. currentPhase (0.0),
  19141. phasePerSample (0.0),
  19142. amplitude (0.5f)
  19143. {
  19144. }
  19145. ToneGeneratorAudioSource::~ToneGeneratorAudioSource()
  19146. {
  19147. }
  19148. void ToneGeneratorAudioSource::setAmplitude (const float newAmplitude)
  19149. {
  19150. amplitude = newAmplitude;
  19151. }
  19152. void ToneGeneratorAudioSource::setFrequency (const double newFrequencyHz)
  19153. {
  19154. frequency = newFrequencyHz;
  19155. phasePerSample = 0.0;
  19156. }
  19157. void ToneGeneratorAudioSource::prepareToPlay (int /*samplesPerBlockExpected*/,
  19158. double sampleRate_)
  19159. {
  19160. currentPhase = 0.0;
  19161. phasePerSample = 0.0;
  19162. sampleRate = sampleRate_;
  19163. }
  19164. void ToneGeneratorAudioSource::releaseResources()
  19165. {
  19166. }
  19167. void ToneGeneratorAudioSource::getNextAudioBlock (const AudioSourceChannelInfo& info)
  19168. {
  19169. if (phasePerSample == 0.0)
  19170. phasePerSample = double_Pi * 2.0 / (sampleRate / frequency);
  19171. for (int i = 0; i < info.numSamples; ++i)
  19172. {
  19173. const float sample = amplitude * (float) sin (currentPhase);
  19174. currentPhase += phasePerSample;
  19175. for (int j = info.buffer->getNumChannels(); --j >= 0;)
  19176. *info.buffer->getSampleData (j, info.startSample + i) = sample;
  19177. }
  19178. }
  19179. END_JUCE_NAMESPACE
  19180. /*** End of inlined file: juce_ToneGeneratorAudioSource.cpp ***/
  19181. /*** Start of inlined file: juce_AudioDeviceManager.cpp ***/
  19182. BEGIN_JUCE_NAMESPACE
  19183. AudioDeviceManager::AudioDeviceSetup::AudioDeviceSetup()
  19184. : sampleRate (0),
  19185. bufferSize (0),
  19186. useDefaultInputChannels (true),
  19187. useDefaultOutputChannels (true)
  19188. {
  19189. }
  19190. bool AudioDeviceManager::AudioDeviceSetup::operator== (const AudioDeviceManager::AudioDeviceSetup& other) const
  19191. {
  19192. return outputDeviceName == other.outputDeviceName
  19193. && inputDeviceName == other.inputDeviceName
  19194. && sampleRate == other.sampleRate
  19195. && bufferSize == other.bufferSize
  19196. && inputChannels == other.inputChannels
  19197. && useDefaultInputChannels == other.useDefaultInputChannels
  19198. && outputChannels == other.outputChannels
  19199. && useDefaultOutputChannels == other.useDefaultOutputChannels;
  19200. }
  19201. AudioDeviceManager::AudioDeviceManager()
  19202. : currentAudioDevice (0),
  19203. numInputChansNeeded (0),
  19204. numOutputChansNeeded (2),
  19205. listNeedsScanning (true),
  19206. useInputNames (false),
  19207. inputLevelMeasurementEnabledCount (0),
  19208. inputLevel (0),
  19209. tempBuffer (2, 2),
  19210. defaultMidiOutput (0),
  19211. cpuUsageMs (0),
  19212. timeToCpuScale (0)
  19213. {
  19214. callbackHandler.owner = this;
  19215. }
  19216. AudioDeviceManager::~AudioDeviceManager()
  19217. {
  19218. currentAudioDevice = 0;
  19219. defaultMidiOutput = 0;
  19220. }
  19221. void AudioDeviceManager::createDeviceTypesIfNeeded()
  19222. {
  19223. if (availableDeviceTypes.size() == 0)
  19224. {
  19225. createAudioDeviceTypes (availableDeviceTypes);
  19226. while (lastDeviceTypeConfigs.size() < availableDeviceTypes.size())
  19227. lastDeviceTypeConfigs.add (new AudioDeviceSetup());
  19228. if (availableDeviceTypes.size() > 0)
  19229. currentDeviceType = availableDeviceTypes.getUnchecked(0)->getTypeName();
  19230. }
  19231. }
  19232. const OwnedArray <AudioIODeviceType>& AudioDeviceManager::getAvailableDeviceTypes()
  19233. {
  19234. scanDevicesIfNeeded();
  19235. return availableDeviceTypes;
  19236. }
  19237. AudioIODeviceType* juce_createAudioIODeviceType_CoreAudio();
  19238. AudioIODeviceType* juce_createAudioIODeviceType_iPhoneAudio();
  19239. AudioIODeviceType* juce_createAudioIODeviceType_WASAPI();
  19240. AudioIODeviceType* juce_createAudioIODeviceType_DirectSound();
  19241. AudioIODeviceType* juce_createAudioIODeviceType_ASIO();
  19242. AudioIODeviceType* juce_createAudioIODeviceType_ALSA();
  19243. AudioIODeviceType* juce_createAudioIODeviceType_JACK();
  19244. void AudioDeviceManager::createAudioDeviceTypes (OwnedArray <AudioIODeviceType>& list)
  19245. {
  19246. #if JUCE_WINDOWS
  19247. #if JUCE_WASAPI
  19248. if (SystemStats::getOperatingSystemType() >= SystemStats::WinVista)
  19249. list.add (juce_createAudioIODeviceType_WASAPI());
  19250. #endif
  19251. #if JUCE_DIRECTSOUND
  19252. list.add (juce_createAudioIODeviceType_DirectSound());
  19253. #endif
  19254. #if JUCE_ASIO
  19255. list.add (juce_createAudioIODeviceType_ASIO());
  19256. #endif
  19257. #endif
  19258. #if JUCE_MAC
  19259. list.add (juce_createAudioIODeviceType_CoreAudio());
  19260. #endif
  19261. #if JUCE_IPHONE
  19262. list.add (juce_createAudioIODeviceType_iPhoneAudio());
  19263. #endif
  19264. #if JUCE_LINUX && JUCE_ALSA
  19265. list.add (juce_createAudioIODeviceType_ALSA());
  19266. #endif
  19267. #if JUCE_LINUX && JUCE_JACK
  19268. list.add (juce_createAudioIODeviceType_JACK());
  19269. #endif
  19270. }
  19271. const String AudioDeviceManager::initialise (const int numInputChannelsNeeded,
  19272. const int numOutputChannelsNeeded,
  19273. const XmlElement* const e,
  19274. const bool selectDefaultDeviceOnFailure,
  19275. const String& preferredDefaultDeviceName,
  19276. const AudioDeviceSetup* preferredSetupOptions)
  19277. {
  19278. scanDevicesIfNeeded();
  19279. numInputChansNeeded = numInputChannelsNeeded;
  19280. numOutputChansNeeded = numOutputChannelsNeeded;
  19281. if (e != 0 && e->hasTagName (T("DEVICESETUP")))
  19282. {
  19283. lastExplicitSettings = new XmlElement (*e);
  19284. String error;
  19285. AudioDeviceSetup setup;
  19286. if (preferredSetupOptions != 0)
  19287. setup = *preferredSetupOptions;
  19288. if (e->getStringAttribute (T("audioDeviceName")).isNotEmpty())
  19289. {
  19290. setup.inputDeviceName = setup.outputDeviceName
  19291. = e->getStringAttribute (T("audioDeviceName"));
  19292. }
  19293. else
  19294. {
  19295. setup.inputDeviceName = e->getStringAttribute (T("audioInputDeviceName"));
  19296. setup.outputDeviceName = e->getStringAttribute (T("audioOutputDeviceName"));
  19297. }
  19298. currentDeviceType = e->getStringAttribute (T("deviceType"));
  19299. if (currentDeviceType.isEmpty())
  19300. {
  19301. AudioIODeviceType* const type = findType (setup.inputDeviceName, setup.outputDeviceName);
  19302. if (type != 0)
  19303. currentDeviceType = type->getTypeName();
  19304. else if (availableDeviceTypes.size() > 0)
  19305. currentDeviceType = availableDeviceTypes[0]->getTypeName();
  19306. }
  19307. setup.bufferSize = e->getIntAttribute (T("audioDeviceBufferSize"));
  19308. setup.sampleRate = e->getDoubleAttribute (T("audioDeviceRate"));
  19309. setup.inputChannels.parseString (e->getStringAttribute (T("audioDeviceInChans"), T("11")), 2);
  19310. setup.outputChannels.parseString (e->getStringAttribute (T("audioDeviceOutChans"), T("11")), 2);
  19311. setup.useDefaultInputChannels = ! e->hasAttribute (T("audioDeviceInChans"));
  19312. setup.useDefaultOutputChannels = ! e->hasAttribute (T("audioDeviceOutChans"));
  19313. error = setAudioDeviceSetup (setup, true);
  19314. midiInsFromXml.clear();
  19315. forEachXmlChildElementWithTagName (*e, c, T("MIDIINPUT"))
  19316. midiInsFromXml.add (c->getStringAttribute (T("name")));
  19317. const StringArray allMidiIns (MidiInput::getDevices());
  19318. for (int i = allMidiIns.size(); --i >= 0;)
  19319. setMidiInputEnabled (allMidiIns[i], midiInsFromXml.contains (allMidiIns[i]));
  19320. if (error.isNotEmpty() && selectDefaultDeviceOnFailure)
  19321. error = initialise (numInputChannelsNeeded, numOutputChannelsNeeded, 0,
  19322. false, preferredDefaultDeviceName);
  19323. setDefaultMidiOutput (e->getStringAttribute (T("defaultMidiOutput")));
  19324. return error;
  19325. }
  19326. else
  19327. {
  19328. AudioDeviceSetup setup;
  19329. if (preferredSetupOptions != 0)
  19330. {
  19331. setup = *preferredSetupOptions;
  19332. }
  19333. else if (preferredDefaultDeviceName.isNotEmpty())
  19334. {
  19335. for (int j = availableDeviceTypes.size(); --j >= 0;)
  19336. {
  19337. AudioIODeviceType* const type = availableDeviceTypes.getUnchecked(j);
  19338. StringArray outs (type->getDeviceNames (false));
  19339. int i;
  19340. for (i = 0; i < outs.size(); ++i)
  19341. {
  19342. if (outs[i].matchesWildcard (preferredDefaultDeviceName, true))
  19343. {
  19344. setup.outputDeviceName = outs[i];
  19345. break;
  19346. }
  19347. }
  19348. StringArray ins (type->getDeviceNames (true));
  19349. for (i = 0; i < ins.size(); ++i)
  19350. {
  19351. if (ins[i].matchesWildcard (preferredDefaultDeviceName, true))
  19352. {
  19353. setup.inputDeviceName = ins[i];
  19354. break;
  19355. }
  19356. }
  19357. }
  19358. }
  19359. insertDefaultDeviceNames (setup);
  19360. return setAudioDeviceSetup (setup, false);
  19361. }
  19362. }
  19363. void AudioDeviceManager::insertDefaultDeviceNames (AudioDeviceSetup& setup) const
  19364. {
  19365. AudioIODeviceType* type = getCurrentDeviceTypeObject();
  19366. if (type != 0)
  19367. {
  19368. if (setup.outputDeviceName.isEmpty())
  19369. setup.outputDeviceName = type->getDeviceNames (false) [type->getDefaultDeviceIndex (false)];
  19370. if (setup.inputDeviceName.isEmpty())
  19371. setup.inputDeviceName = type->getDeviceNames (true) [type->getDefaultDeviceIndex (true)];
  19372. }
  19373. }
  19374. XmlElement* AudioDeviceManager::createStateXml() const
  19375. {
  19376. return lastExplicitSettings != 0 ? new XmlElement (*lastExplicitSettings) : 0;
  19377. }
  19378. void AudioDeviceManager::scanDevicesIfNeeded()
  19379. {
  19380. if (listNeedsScanning)
  19381. {
  19382. listNeedsScanning = false;
  19383. createDeviceTypesIfNeeded();
  19384. for (int i = availableDeviceTypes.size(); --i >= 0;)
  19385. availableDeviceTypes.getUnchecked(i)->scanForDevices();
  19386. }
  19387. }
  19388. AudioIODeviceType* AudioDeviceManager::findType (const String& inputName, const String& outputName)
  19389. {
  19390. scanDevicesIfNeeded();
  19391. for (int i = availableDeviceTypes.size(); --i >= 0;)
  19392. {
  19393. AudioIODeviceType* const type = availableDeviceTypes.getUnchecked(i);
  19394. if ((inputName.isNotEmpty() && type->getDeviceNames (true).contains (inputName, true))
  19395. || (outputName.isNotEmpty() && type->getDeviceNames (false).contains (outputName, true)))
  19396. {
  19397. return type;
  19398. }
  19399. }
  19400. return 0;
  19401. }
  19402. void AudioDeviceManager::getAudioDeviceSetup (AudioDeviceSetup& setup)
  19403. {
  19404. setup = currentSetup;
  19405. }
  19406. void AudioDeviceManager::deleteCurrentDevice()
  19407. {
  19408. currentAudioDevice = 0;
  19409. currentSetup.inputDeviceName = String::empty;
  19410. currentSetup.outputDeviceName = String::empty;
  19411. }
  19412. void AudioDeviceManager::setCurrentAudioDeviceType (const String& type,
  19413. const bool treatAsChosenDevice)
  19414. {
  19415. for (int i = 0; i < availableDeviceTypes.size(); ++i)
  19416. {
  19417. if (availableDeviceTypes.getUnchecked(i)->getTypeName() == type
  19418. && currentDeviceType != type)
  19419. {
  19420. currentDeviceType = type;
  19421. AudioDeviceSetup s (*lastDeviceTypeConfigs.getUnchecked(i));
  19422. insertDefaultDeviceNames (s);
  19423. setAudioDeviceSetup (s, treatAsChosenDevice);
  19424. sendChangeMessage (this);
  19425. break;
  19426. }
  19427. }
  19428. }
  19429. AudioIODeviceType* AudioDeviceManager::getCurrentDeviceTypeObject() const
  19430. {
  19431. for (int i = 0; i < availableDeviceTypes.size(); ++i)
  19432. if (availableDeviceTypes[i]->getTypeName() == currentDeviceType)
  19433. return availableDeviceTypes[i];
  19434. return availableDeviceTypes[0];
  19435. }
  19436. const String AudioDeviceManager::setAudioDeviceSetup (const AudioDeviceSetup& newSetup,
  19437. const bool treatAsChosenDevice)
  19438. {
  19439. jassert (&newSetup != &currentSetup); // this will have no effect
  19440. if (newSetup == currentSetup && currentAudioDevice != 0)
  19441. return String::empty;
  19442. if (! (newSetup == currentSetup))
  19443. sendChangeMessage (this);
  19444. stopDevice();
  19445. const String newInputDeviceName (numInputChansNeeded == 0 ? String::empty : newSetup.inputDeviceName);
  19446. const String newOutputDeviceName (numOutputChansNeeded == 0 ? String::empty : newSetup.outputDeviceName);
  19447. String error;
  19448. AudioIODeviceType* type = getCurrentDeviceTypeObject();
  19449. if (type == 0 || (newInputDeviceName.isEmpty() && newOutputDeviceName.isEmpty()))
  19450. {
  19451. deleteCurrentDevice();
  19452. if (treatAsChosenDevice)
  19453. updateXml();
  19454. return String::empty;
  19455. }
  19456. if (currentSetup.inputDeviceName != newInputDeviceName
  19457. || currentSetup.outputDeviceName != newOutputDeviceName
  19458. || currentAudioDevice == 0)
  19459. {
  19460. deleteCurrentDevice();
  19461. scanDevicesIfNeeded();
  19462. if (newOutputDeviceName.isNotEmpty()
  19463. && ! type->getDeviceNames (false).contains (newOutputDeviceName))
  19464. {
  19465. return "No such device: " + newOutputDeviceName;
  19466. }
  19467. if (newInputDeviceName.isNotEmpty()
  19468. && ! type->getDeviceNames (true).contains (newInputDeviceName))
  19469. {
  19470. return "No such device: " + newInputDeviceName;
  19471. }
  19472. currentAudioDevice = type->createDevice (newOutputDeviceName, newInputDeviceName);
  19473. if (currentAudioDevice == 0)
  19474. 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!";
  19475. else
  19476. error = currentAudioDevice->getLastError();
  19477. if (error.isNotEmpty())
  19478. {
  19479. deleteCurrentDevice();
  19480. return error;
  19481. }
  19482. if (newSetup.useDefaultInputChannels)
  19483. {
  19484. inputChannels.clear();
  19485. inputChannels.setRange (0, numInputChansNeeded, true);
  19486. }
  19487. if (newSetup.useDefaultOutputChannels)
  19488. {
  19489. outputChannels.clear();
  19490. outputChannels.setRange (0, numOutputChansNeeded, true);
  19491. }
  19492. if (newInputDeviceName.isEmpty())
  19493. inputChannels.clear();
  19494. if (newOutputDeviceName.isEmpty())
  19495. outputChannels.clear();
  19496. }
  19497. if (! newSetup.useDefaultInputChannels)
  19498. inputChannels = newSetup.inputChannels;
  19499. if (! newSetup.useDefaultOutputChannels)
  19500. outputChannels = newSetup.outputChannels;
  19501. currentSetup = newSetup;
  19502. currentSetup.sampleRate = chooseBestSampleRate (newSetup.sampleRate);
  19503. error = currentAudioDevice->open (inputChannels,
  19504. outputChannels,
  19505. currentSetup.sampleRate,
  19506. currentSetup.bufferSize);
  19507. if (error.isEmpty())
  19508. {
  19509. currentDeviceType = currentAudioDevice->getTypeName();
  19510. currentAudioDevice->start (&callbackHandler);
  19511. currentSetup.sampleRate = currentAudioDevice->getCurrentSampleRate();
  19512. currentSetup.bufferSize = currentAudioDevice->getCurrentBufferSizeSamples();
  19513. currentSetup.inputChannels = currentAudioDevice->getActiveInputChannels();
  19514. currentSetup.outputChannels = currentAudioDevice->getActiveOutputChannels();
  19515. for (int i = 0; i < availableDeviceTypes.size(); ++i)
  19516. if (availableDeviceTypes.getUnchecked (i)->getTypeName() == currentDeviceType)
  19517. *(lastDeviceTypeConfigs.getUnchecked (i)) = currentSetup;
  19518. if (treatAsChosenDevice)
  19519. updateXml();
  19520. }
  19521. else
  19522. {
  19523. deleteCurrentDevice();
  19524. }
  19525. return error;
  19526. }
  19527. double AudioDeviceManager::chooseBestSampleRate (double rate) const
  19528. {
  19529. jassert (currentAudioDevice != 0);
  19530. if (rate > 0)
  19531. {
  19532. bool ok = false;
  19533. for (int i = currentAudioDevice->getNumSampleRates(); --i >= 0;)
  19534. {
  19535. const double sr = currentAudioDevice->getSampleRate (i);
  19536. if (sr == rate)
  19537. ok = true;
  19538. }
  19539. if (! ok)
  19540. rate = 0;
  19541. }
  19542. if (rate == 0)
  19543. {
  19544. double lowestAbove44 = 0.0;
  19545. for (int i = currentAudioDevice->getNumSampleRates(); --i >= 0;)
  19546. {
  19547. const double sr = currentAudioDevice->getSampleRate (i);
  19548. if (sr >= 44100.0 && (lowestAbove44 == 0 || sr < lowestAbove44))
  19549. lowestAbove44 = sr;
  19550. }
  19551. if (lowestAbove44 == 0.0)
  19552. rate = currentAudioDevice->getSampleRate (0);
  19553. else
  19554. rate = lowestAbove44;
  19555. }
  19556. return rate;
  19557. }
  19558. void AudioDeviceManager::stopDevice()
  19559. {
  19560. if (currentAudioDevice != 0)
  19561. currentAudioDevice->stop();
  19562. testSound = 0;
  19563. }
  19564. void AudioDeviceManager::closeAudioDevice()
  19565. {
  19566. stopDevice();
  19567. currentAudioDevice = 0;
  19568. }
  19569. void AudioDeviceManager::restartLastAudioDevice()
  19570. {
  19571. if (currentAudioDevice == 0)
  19572. {
  19573. if (currentSetup.inputDeviceName.isEmpty()
  19574. && currentSetup.outputDeviceName.isEmpty())
  19575. {
  19576. // This method will only reload the last device that was running
  19577. // before closeAudioDevice() was called - you need to actually open
  19578. // one first, with setAudioDevice().
  19579. jassertfalse
  19580. return;
  19581. }
  19582. AudioDeviceSetup s (currentSetup);
  19583. setAudioDeviceSetup (s, false);
  19584. }
  19585. }
  19586. void AudioDeviceManager::updateXml()
  19587. {
  19588. lastExplicitSettings = new XmlElement ("DEVICESETUP");
  19589. lastExplicitSettings->setAttribute ("deviceType", currentDeviceType);
  19590. lastExplicitSettings->setAttribute ("audioOutputDeviceName", currentSetup.outputDeviceName);
  19591. lastExplicitSettings->setAttribute ("audioInputDeviceName", currentSetup.inputDeviceName);
  19592. if (currentAudioDevice != 0)
  19593. {
  19594. lastExplicitSettings->setAttribute ("audioDeviceRate", currentAudioDevice->getCurrentSampleRate());
  19595. if (currentAudioDevice->getDefaultBufferSize() != currentAudioDevice->getCurrentBufferSizeSamples())
  19596. lastExplicitSettings->setAttribute ("audioDeviceBufferSize", currentAudioDevice->getCurrentBufferSizeSamples());
  19597. if (! currentSetup.useDefaultInputChannels)
  19598. lastExplicitSettings->setAttribute ("audioDeviceInChans", currentSetup.inputChannels.toString (2));
  19599. if (! currentSetup.useDefaultOutputChannels)
  19600. lastExplicitSettings->setAttribute ("audioDeviceOutChans", currentSetup.outputChannels.toString (2));
  19601. }
  19602. for (int i = 0; i < enabledMidiInputs.size(); ++i)
  19603. {
  19604. XmlElement* const m = lastExplicitSettings->createNewChildElement ("MIDIINPUT");
  19605. m->setAttribute ("name", enabledMidiInputs[i]->getName());
  19606. }
  19607. if (midiInsFromXml.size() > 0)
  19608. {
  19609. // Add any midi devices that have been enabled before, but which aren't currently
  19610. // open because the device has been disconnected.
  19611. const StringArray availableMidiDevices (MidiInput::getDevices());
  19612. for (int i = 0; i < midiInsFromXml.size(); ++i)
  19613. {
  19614. if (! availableMidiDevices.contains (midiInsFromXml[i], true))
  19615. {
  19616. XmlElement* const m = lastExplicitSettings->createNewChildElement ("MIDIINPUT");
  19617. m->setAttribute ("name", midiInsFromXml[i]);
  19618. }
  19619. }
  19620. }
  19621. if (defaultMidiOutputName.isNotEmpty())
  19622. lastExplicitSettings->setAttribute ("defaultMidiOutput", defaultMidiOutputName);
  19623. }
  19624. void AudioDeviceManager::addAudioCallback (AudioIODeviceCallback* newCallback)
  19625. {
  19626. {
  19627. const ScopedLock sl (audioCallbackLock);
  19628. if (callbacks.contains (newCallback))
  19629. return;
  19630. }
  19631. if (currentAudioDevice != 0 && newCallback != 0)
  19632. newCallback->audioDeviceAboutToStart (currentAudioDevice);
  19633. const ScopedLock sl (audioCallbackLock);
  19634. callbacks.add (newCallback);
  19635. }
  19636. void AudioDeviceManager::removeAudioCallback (AudioIODeviceCallback* callback)
  19637. {
  19638. if (callback != 0)
  19639. {
  19640. bool needsDeinitialising = currentAudioDevice != 0;
  19641. {
  19642. const ScopedLock sl (audioCallbackLock);
  19643. needsDeinitialising = needsDeinitialising && callbacks.contains (callback);
  19644. callbacks.removeValue (callback);
  19645. }
  19646. if (needsDeinitialising)
  19647. callback->audioDeviceStopped();
  19648. }
  19649. }
  19650. void AudioDeviceManager::audioDeviceIOCallbackInt (const float** inputChannelData,
  19651. int numInputChannels,
  19652. float** outputChannelData,
  19653. int numOutputChannels,
  19654. int numSamples)
  19655. {
  19656. const ScopedLock sl (audioCallbackLock);
  19657. if (inputLevelMeasurementEnabledCount > 0)
  19658. {
  19659. for (int j = 0; j < numSamples; ++j)
  19660. {
  19661. float s = 0;
  19662. for (int i = 0; i < numInputChannels; ++i)
  19663. s += fabsf (inputChannelData[i][j]);
  19664. s /= numInputChannels;
  19665. const double decayFactor = 0.99992;
  19666. if (s > inputLevel)
  19667. inputLevel = s;
  19668. else if (inputLevel > 0.001f)
  19669. inputLevel *= decayFactor;
  19670. else
  19671. inputLevel = 0;
  19672. }
  19673. }
  19674. if (callbacks.size() > 0)
  19675. {
  19676. const double callbackStartTime = Time::getMillisecondCounterHiRes();
  19677. tempBuffer.setSize (jmax (1, numOutputChannels), jmax (1, numSamples), false, false, true);
  19678. callbacks.getUnchecked(0)->audioDeviceIOCallback (inputChannelData, numInputChannels,
  19679. outputChannelData, numOutputChannels, numSamples);
  19680. float** const tempChans = tempBuffer.getArrayOfChannels();
  19681. for (int i = callbacks.size(); --i > 0;)
  19682. {
  19683. callbacks.getUnchecked(i)->audioDeviceIOCallback (inputChannelData, numInputChannels,
  19684. tempChans, numOutputChannels, numSamples);
  19685. for (int chan = 0; chan < numOutputChannels; ++chan)
  19686. {
  19687. const float* const src = tempChans [chan];
  19688. float* const dst = outputChannelData [chan];
  19689. if (src != 0 && dst != 0)
  19690. for (int j = 0; j < numSamples; ++j)
  19691. dst[j] += src[j];
  19692. }
  19693. }
  19694. const double msTaken = Time::getMillisecondCounterHiRes() - callbackStartTime;
  19695. const double filterAmount = 0.2;
  19696. cpuUsageMs += filterAmount * (msTaken - cpuUsageMs);
  19697. }
  19698. else
  19699. {
  19700. for (int i = 0; i < numOutputChannels; ++i)
  19701. zeromem (outputChannelData[i], sizeof (float) * numSamples);
  19702. }
  19703. if (testSound != 0)
  19704. {
  19705. const int numSamps = jmin (numSamples, testSound->getNumSamples() - testSoundPosition);
  19706. const float* const src = testSound->getSampleData (0, testSoundPosition);
  19707. for (int i = 0; i < numOutputChannels; ++i)
  19708. for (int j = 0; j < numSamps; ++j)
  19709. outputChannelData [i][j] += src[j];
  19710. testSoundPosition += numSamps;
  19711. if (testSoundPosition >= testSound->getNumSamples())
  19712. testSound = 0;
  19713. }
  19714. }
  19715. void AudioDeviceManager::audioDeviceAboutToStartInt (AudioIODevice* const device)
  19716. {
  19717. cpuUsageMs = 0;
  19718. const double sampleRate = device->getCurrentSampleRate();
  19719. const int blockSize = device->getCurrentBufferSizeSamples();
  19720. if (sampleRate > 0.0 && blockSize > 0)
  19721. {
  19722. const double msPerBlock = 1000.0 * blockSize / sampleRate;
  19723. timeToCpuScale = (msPerBlock > 0.0) ? (1.0 / msPerBlock) : 0.0;
  19724. }
  19725. {
  19726. const ScopedLock sl (audioCallbackLock);
  19727. for (int i = callbacks.size(); --i >= 0;)
  19728. callbacks.getUnchecked(i)->audioDeviceAboutToStart (device);
  19729. }
  19730. sendChangeMessage (this);
  19731. }
  19732. void AudioDeviceManager::audioDeviceStoppedInt()
  19733. {
  19734. cpuUsageMs = 0;
  19735. timeToCpuScale = 0;
  19736. sendChangeMessage (this);
  19737. const ScopedLock sl (audioCallbackLock);
  19738. for (int i = callbacks.size(); --i >= 0;)
  19739. callbacks.getUnchecked(i)->audioDeviceStopped();
  19740. }
  19741. double AudioDeviceManager::getCpuUsage() const
  19742. {
  19743. return jlimit (0.0, 1.0, timeToCpuScale * cpuUsageMs);
  19744. }
  19745. void AudioDeviceManager::setMidiInputEnabled (const String& name,
  19746. const bool enabled)
  19747. {
  19748. if (enabled != isMidiInputEnabled (name))
  19749. {
  19750. if (enabled)
  19751. {
  19752. const int index = MidiInput::getDevices().indexOf (name);
  19753. if (index >= 0)
  19754. {
  19755. MidiInput* const min = MidiInput::openDevice (index, &callbackHandler);
  19756. if (min != 0)
  19757. {
  19758. enabledMidiInputs.add (min);
  19759. min->start();
  19760. }
  19761. }
  19762. }
  19763. else
  19764. {
  19765. for (int i = enabledMidiInputs.size(); --i >= 0;)
  19766. if (enabledMidiInputs[i]->getName() == name)
  19767. enabledMidiInputs.remove (i);
  19768. }
  19769. updateXml();
  19770. sendChangeMessage (this);
  19771. }
  19772. }
  19773. bool AudioDeviceManager::isMidiInputEnabled (const String& name) const
  19774. {
  19775. for (int i = enabledMidiInputs.size(); --i >= 0;)
  19776. if (enabledMidiInputs[i]->getName() == name)
  19777. return true;
  19778. return false;
  19779. }
  19780. void AudioDeviceManager::addMidiInputCallback (const String& name,
  19781. MidiInputCallback* callback)
  19782. {
  19783. removeMidiInputCallback (name, callback);
  19784. if (name.isEmpty())
  19785. {
  19786. midiCallbacks.add (callback);
  19787. midiCallbackDevices.add (0);
  19788. }
  19789. else
  19790. {
  19791. for (int i = enabledMidiInputs.size(); --i >= 0;)
  19792. {
  19793. if (enabledMidiInputs[i]->getName() == name)
  19794. {
  19795. const ScopedLock sl (midiCallbackLock);
  19796. midiCallbacks.add (callback);
  19797. midiCallbackDevices.add (enabledMidiInputs[i]);
  19798. break;
  19799. }
  19800. }
  19801. }
  19802. }
  19803. void AudioDeviceManager::removeMidiInputCallback (const String& name,
  19804. MidiInputCallback* /*callback*/)
  19805. {
  19806. const ScopedLock sl (midiCallbackLock);
  19807. for (int i = midiCallbacks.size(); --i >= 0;)
  19808. {
  19809. String devName;
  19810. if (midiCallbackDevices.getUnchecked(i) != 0)
  19811. devName = midiCallbackDevices.getUnchecked(i)->getName();
  19812. if (devName == name)
  19813. {
  19814. midiCallbacks.remove (i);
  19815. midiCallbackDevices.remove (i);
  19816. }
  19817. }
  19818. }
  19819. void AudioDeviceManager::handleIncomingMidiMessageInt (MidiInput* source,
  19820. const MidiMessage& message)
  19821. {
  19822. if (! message.isActiveSense())
  19823. {
  19824. const bool isDefaultSource = (source == 0 || source == enabledMidiInputs.getFirst());
  19825. const ScopedLock sl (midiCallbackLock);
  19826. for (int i = midiCallbackDevices.size(); --i >= 0;)
  19827. {
  19828. MidiInput* const md = midiCallbackDevices.getUnchecked(i);
  19829. if (md == source || (md == 0 && isDefaultSource))
  19830. midiCallbacks.getUnchecked(i)->handleIncomingMidiMessage (source, message);
  19831. }
  19832. }
  19833. }
  19834. void AudioDeviceManager::setDefaultMidiOutput (const String& deviceName)
  19835. {
  19836. if (defaultMidiOutputName != deviceName)
  19837. {
  19838. SortedSet <AudioIODeviceCallback*> oldCallbacks;
  19839. {
  19840. const ScopedLock sl (audioCallbackLock);
  19841. oldCallbacks = callbacks;
  19842. callbacks.clear();
  19843. }
  19844. if (currentAudioDevice != 0)
  19845. for (int i = oldCallbacks.size(); --i >= 0;)
  19846. oldCallbacks.getUnchecked(i)->audioDeviceStopped();
  19847. defaultMidiOutput = 0;
  19848. defaultMidiOutputName = deviceName;
  19849. if (deviceName.isNotEmpty())
  19850. defaultMidiOutput = MidiOutput::openDevice (MidiOutput::getDevices().indexOf (deviceName));
  19851. if (currentAudioDevice != 0)
  19852. for (int i = oldCallbacks.size(); --i >= 0;)
  19853. oldCallbacks.getUnchecked(i)->audioDeviceAboutToStart (currentAudioDevice);
  19854. {
  19855. const ScopedLock sl (audioCallbackLock);
  19856. callbacks = oldCallbacks;
  19857. }
  19858. updateXml();
  19859. sendChangeMessage (this);
  19860. }
  19861. }
  19862. void AudioDeviceManager::CallbackHandler::audioDeviceIOCallback (const float** inputChannelData,
  19863. int numInputChannels,
  19864. float** outputChannelData,
  19865. int numOutputChannels,
  19866. int numSamples)
  19867. {
  19868. owner->audioDeviceIOCallbackInt (inputChannelData, numInputChannels, outputChannelData, numOutputChannels, numSamples);
  19869. }
  19870. void AudioDeviceManager::CallbackHandler::audioDeviceAboutToStart (AudioIODevice* device)
  19871. {
  19872. owner->audioDeviceAboutToStartInt (device);
  19873. }
  19874. void AudioDeviceManager::CallbackHandler::audioDeviceStopped()
  19875. {
  19876. owner->audioDeviceStoppedInt();
  19877. }
  19878. void AudioDeviceManager::CallbackHandler::handleIncomingMidiMessage (MidiInput* source, const MidiMessage& message)
  19879. {
  19880. owner->handleIncomingMidiMessageInt (source, message);
  19881. }
  19882. void AudioDeviceManager::playTestSound()
  19883. {
  19884. { // cunningly nested to swap, unlock and delete in that order.
  19885. ScopedPointer <AudioSampleBuffer> oldSound;
  19886. {
  19887. const ScopedLock sl (audioCallbackLock);
  19888. oldSound = testSound;
  19889. }
  19890. }
  19891. testSoundPosition = 0;
  19892. if (currentAudioDevice != 0)
  19893. {
  19894. const double sampleRate = currentAudioDevice->getCurrentSampleRate();
  19895. const int soundLength = (int) sampleRate;
  19896. AudioSampleBuffer* const newSound = new AudioSampleBuffer (1, soundLength);
  19897. float* samples = newSound->getSampleData (0);
  19898. const double frequency = MidiMessage::getMidiNoteInHertz (80);
  19899. const float amplitude = 0.5f;
  19900. const double phasePerSample = double_Pi * 2.0 / (sampleRate / frequency);
  19901. for (int i = 0; i < soundLength; ++i)
  19902. samples[i] = amplitude * (float) sin (i * phasePerSample);
  19903. newSound->applyGainRamp (0, 0, soundLength / 10, 0.0f, 1.0f);
  19904. newSound->applyGainRamp (0, soundLength - soundLength / 4, soundLength / 4, 1.0f, 0.0f);
  19905. const ScopedLock sl (audioCallbackLock);
  19906. testSound = newSound;
  19907. }
  19908. }
  19909. void AudioDeviceManager::enableInputLevelMeasurement (const bool enableMeasurement)
  19910. {
  19911. const ScopedLock sl (audioCallbackLock);
  19912. if (enableMeasurement)
  19913. ++inputLevelMeasurementEnabledCount;
  19914. else
  19915. --inputLevelMeasurementEnabledCount;
  19916. inputLevel = 0;
  19917. }
  19918. double AudioDeviceManager::getCurrentInputLevel() const
  19919. {
  19920. jassert (inputLevelMeasurementEnabledCount > 0); // you need to call enableInputLevelMeasurement() before using this!
  19921. return inputLevel;
  19922. }
  19923. END_JUCE_NAMESPACE
  19924. /*** End of inlined file: juce_AudioDeviceManager.cpp ***/
  19925. /*** Start of inlined file: juce_AudioIODevice.cpp ***/
  19926. BEGIN_JUCE_NAMESPACE
  19927. AudioIODevice::AudioIODevice (const String& deviceName, const String& typeName_)
  19928. : name (deviceName),
  19929. typeName (typeName_)
  19930. {
  19931. }
  19932. AudioIODevice::~AudioIODevice()
  19933. {
  19934. }
  19935. bool AudioIODevice::hasControlPanel() const
  19936. {
  19937. return false;
  19938. }
  19939. bool AudioIODevice::showControlPanel()
  19940. {
  19941. jassertfalse // this should only be called for devices which return true from
  19942. // their hasControlPanel() method.
  19943. return false;
  19944. }
  19945. END_JUCE_NAMESPACE
  19946. /*** End of inlined file: juce_AudioIODevice.cpp ***/
  19947. /*** Start of inlined file: juce_AudioIODeviceType.cpp ***/
  19948. BEGIN_JUCE_NAMESPACE
  19949. AudioIODeviceType::AudioIODeviceType (const tchar* const name)
  19950. : typeName (name)
  19951. {
  19952. }
  19953. AudioIODeviceType::~AudioIODeviceType()
  19954. {
  19955. }
  19956. END_JUCE_NAMESPACE
  19957. /*** End of inlined file: juce_AudioIODeviceType.cpp ***/
  19958. /*** Start of inlined file: juce_MidiOutput.cpp ***/
  19959. BEGIN_JUCE_NAMESPACE
  19960. MidiOutput::MidiOutput()
  19961. : Thread ("midi out"),
  19962. internal (0),
  19963. firstMessage (0)
  19964. {
  19965. }
  19966. MidiOutput::PendingMessage::PendingMessage (const uint8* const data, const int len,
  19967. const double sampleNumber)
  19968. : message (data, len, sampleNumber)
  19969. {
  19970. }
  19971. void MidiOutput::sendBlockOfMessages (const MidiBuffer& buffer,
  19972. const double millisecondCounterToStartAt,
  19973. double samplesPerSecondForBuffer)
  19974. {
  19975. // You've got to call startBackgroundThread() for this to actually work..
  19976. jassert (isThreadRunning());
  19977. // this needs to be a value in the future - RTFM for this method!
  19978. jassert (millisecondCounterToStartAt > 0);
  19979. const double timeScaleFactor = 1000.0 / samplesPerSecondForBuffer;
  19980. MidiBuffer::Iterator i (buffer);
  19981. const uint8* data;
  19982. int len, time;
  19983. while (i.getNextEvent (data, len, time))
  19984. {
  19985. const double eventTime = millisecondCounterToStartAt + timeScaleFactor * time;
  19986. PendingMessage* const m
  19987. = new PendingMessage (data, len, eventTime);
  19988. const ScopedLock sl (lock);
  19989. if (firstMessage == 0 || firstMessage->message.getTimeStamp() > eventTime)
  19990. {
  19991. m->next = firstMessage;
  19992. firstMessage = m;
  19993. }
  19994. else
  19995. {
  19996. PendingMessage* mm = firstMessage;
  19997. while (mm->next != 0 && mm->next->message.getTimeStamp() <= eventTime)
  19998. mm = mm->next;
  19999. m->next = mm->next;
  20000. mm->next = m;
  20001. }
  20002. }
  20003. notify();
  20004. }
  20005. void MidiOutput::clearAllPendingMessages()
  20006. {
  20007. const ScopedLock sl (lock);
  20008. while (firstMessage != 0)
  20009. {
  20010. PendingMessage* const m = firstMessage;
  20011. firstMessage = firstMessage->next;
  20012. delete m;
  20013. }
  20014. }
  20015. void MidiOutput::startBackgroundThread()
  20016. {
  20017. startThread (9);
  20018. }
  20019. void MidiOutput::stopBackgroundThread()
  20020. {
  20021. stopThread (5000);
  20022. }
  20023. void MidiOutput::run()
  20024. {
  20025. while (! threadShouldExit())
  20026. {
  20027. uint32 now = Time::getMillisecondCounter();
  20028. uint32 eventTime = 0;
  20029. uint32 timeToWait = 500;
  20030. PendingMessage* message;
  20031. {
  20032. const ScopedLock sl (lock);
  20033. message = firstMessage;
  20034. if (message != 0)
  20035. {
  20036. eventTime = roundToInt (message->message.getTimeStamp());
  20037. if (eventTime > now + 20)
  20038. {
  20039. timeToWait = eventTime - (now + 20);
  20040. message = 0;
  20041. }
  20042. else
  20043. {
  20044. firstMessage = message->next;
  20045. }
  20046. }
  20047. }
  20048. if (message != 0)
  20049. {
  20050. if (eventTime > now)
  20051. {
  20052. Time::waitForMillisecondCounter (eventTime);
  20053. if (threadShouldExit())
  20054. break;
  20055. }
  20056. if (eventTime > now - 200)
  20057. sendMessageNow (message->message);
  20058. delete message;
  20059. }
  20060. else
  20061. {
  20062. jassert (timeToWait < 1000 * 30);
  20063. wait (timeToWait);
  20064. }
  20065. }
  20066. clearAllPendingMessages();
  20067. }
  20068. END_JUCE_NAMESPACE
  20069. /*** End of inlined file: juce_MidiOutput.cpp ***/
  20070. /*** Start of inlined file: juce_AudioDataConverters.cpp ***/
  20071. BEGIN_JUCE_NAMESPACE
  20072. void AudioDataConverters::convertFloatToInt16LE (const float* source, void* dest, int numSamples, const int destBytesPerSample)
  20073. {
  20074. const double maxVal = (double) 0x7fff;
  20075. char* intData = (char*) dest;
  20076. if (dest != (void*) source || destBytesPerSample <= 4)
  20077. {
  20078. for (int i = 0; i < numSamples; ++i)
  20079. {
  20080. *(uint16*)intData = ByteOrder::swapIfBigEndian ((uint16) (short) roundToInt (jlimit (-maxVal, maxVal, maxVal * source[i])));
  20081. intData += destBytesPerSample;
  20082. }
  20083. }
  20084. else
  20085. {
  20086. intData += destBytesPerSample * numSamples;
  20087. for (int i = numSamples; --i >= 0;)
  20088. {
  20089. intData -= destBytesPerSample;
  20090. *(uint16*)intData = ByteOrder::swapIfBigEndian ((uint16) (short) roundToInt (jlimit (-maxVal, maxVal, maxVal * source[i])));
  20091. }
  20092. }
  20093. }
  20094. void AudioDataConverters::convertFloatToInt16BE (const float* source, void* dest, int numSamples, const int destBytesPerSample)
  20095. {
  20096. const double maxVal = (double) 0x7fff;
  20097. char* intData = (char*) dest;
  20098. if (dest != (void*) source || destBytesPerSample <= 4)
  20099. {
  20100. for (int i = 0; i < numSamples; ++i)
  20101. {
  20102. *(uint16*) intData = ByteOrder::swapIfLittleEndian ((uint16) (short) roundToInt (jlimit (-maxVal, maxVal, maxVal * source[i])));
  20103. intData += destBytesPerSample;
  20104. }
  20105. }
  20106. else
  20107. {
  20108. intData += destBytesPerSample * numSamples;
  20109. for (int i = numSamples; --i >= 0;)
  20110. {
  20111. intData -= destBytesPerSample;
  20112. *(uint16*)intData = ByteOrder::swapIfLittleEndian ((uint16) (short) roundToInt (jlimit (-maxVal, maxVal, maxVal * source[i])));
  20113. }
  20114. }
  20115. }
  20116. void AudioDataConverters::convertFloatToInt24LE (const float* source, void* dest, int numSamples, const int destBytesPerSample)
  20117. {
  20118. const double maxVal = (double) 0x7fffff;
  20119. char* intData = (char*) dest;
  20120. if (dest != (void*) source || destBytesPerSample <= 4)
  20121. {
  20122. for (int i = 0; i < numSamples; ++i)
  20123. {
  20124. ByteOrder::littleEndian24BitToChars ((uint32) roundToInt (jlimit (-maxVal, maxVal, maxVal * source[i])), intData);
  20125. intData += destBytesPerSample;
  20126. }
  20127. }
  20128. else
  20129. {
  20130. intData += destBytesPerSample * numSamples;
  20131. for (int i = numSamples; --i >= 0;)
  20132. {
  20133. intData -= destBytesPerSample;
  20134. ByteOrder::littleEndian24BitToChars ((uint32) roundToInt (jlimit (-maxVal, maxVal, maxVal * source[i])), intData);
  20135. }
  20136. }
  20137. }
  20138. void AudioDataConverters::convertFloatToInt24BE (const float* source, void* dest, int numSamples, const int destBytesPerSample)
  20139. {
  20140. const double maxVal = (double) 0x7fffff;
  20141. char* intData = (char*) dest;
  20142. if (dest != (void*) source || destBytesPerSample <= 4)
  20143. {
  20144. for (int i = 0; i < numSamples; ++i)
  20145. {
  20146. ByteOrder::bigEndian24BitToChars ((uint32) roundToInt (jlimit (-maxVal, maxVal, maxVal * source[i])), intData);
  20147. intData += destBytesPerSample;
  20148. }
  20149. }
  20150. else
  20151. {
  20152. intData += destBytesPerSample * numSamples;
  20153. for (int i = numSamples; --i >= 0;)
  20154. {
  20155. intData -= destBytesPerSample;
  20156. ByteOrder::bigEndian24BitToChars ((uint32) roundToInt (jlimit (-maxVal, maxVal, maxVal * source[i])), intData);
  20157. }
  20158. }
  20159. }
  20160. void AudioDataConverters::convertFloatToInt32LE (const float* source, void* dest, int numSamples, const int destBytesPerSample)
  20161. {
  20162. const double maxVal = (double) 0x7fffffff;
  20163. char* intData = (char*) dest;
  20164. if (dest != (void*) source || destBytesPerSample <= 4)
  20165. {
  20166. for (int i = 0; i < numSamples; ++i)
  20167. {
  20168. *(uint32*)intData = ByteOrder::swapIfBigEndian ((uint32) roundToInt (jlimit (-maxVal, maxVal, maxVal * source[i])));
  20169. intData += destBytesPerSample;
  20170. }
  20171. }
  20172. else
  20173. {
  20174. intData += destBytesPerSample * numSamples;
  20175. for (int i = numSamples; --i >= 0;)
  20176. {
  20177. intData -= destBytesPerSample;
  20178. *(uint32*)intData = ByteOrder::swapIfBigEndian ((uint32) roundToInt (jlimit (-maxVal, maxVal, maxVal * source[i])));
  20179. }
  20180. }
  20181. }
  20182. void AudioDataConverters::convertFloatToInt32BE (const float* source, void* dest, int numSamples, const int destBytesPerSample)
  20183. {
  20184. const double maxVal = (double) 0x7fffffff;
  20185. char* intData = (char*) dest;
  20186. if (dest != (void*) source || destBytesPerSample <= 4)
  20187. {
  20188. for (int i = 0; i < numSamples; ++i)
  20189. {
  20190. *(uint32*)intData = ByteOrder::swapIfLittleEndian ((uint32) roundToInt (jlimit (-maxVal, maxVal, maxVal * source[i])));
  20191. intData += destBytesPerSample;
  20192. }
  20193. }
  20194. else
  20195. {
  20196. intData += destBytesPerSample * numSamples;
  20197. for (int i = numSamples; --i >= 0;)
  20198. {
  20199. intData -= destBytesPerSample;
  20200. *(uint32*)intData = ByteOrder::swapIfLittleEndian ((uint32) roundToInt (jlimit (-maxVal, maxVal, maxVal * source[i])));
  20201. }
  20202. }
  20203. }
  20204. void AudioDataConverters::convertFloatToFloat32LE (const float* source, void* dest, int numSamples, const int destBytesPerSample)
  20205. {
  20206. jassert (dest != (void*) source || destBytesPerSample <= 4); // This op can't be performed on in-place data!
  20207. char* d = (char*) dest;
  20208. for (int i = 0; i < numSamples; ++i)
  20209. {
  20210. *(float*) d = source[i];
  20211. #if JUCE_BIG_ENDIAN
  20212. *(uint32*) d = ByteOrder::swap (*(uint32*) d);
  20213. #endif
  20214. d += destBytesPerSample;
  20215. }
  20216. }
  20217. void AudioDataConverters::convertFloatToFloat32BE (const float* source, void* dest, int numSamples, const int destBytesPerSample)
  20218. {
  20219. jassert (dest != (void*) source || destBytesPerSample <= 4); // This op can't be performed on in-place data!
  20220. char* d = (char*) dest;
  20221. for (int i = 0; i < numSamples; ++i)
  20222. {
  20223. *(float*) d = source[i];
  20224. #if JUCE_LITTLE_ENDIAN
  20225. *(uint32*) d = ByteOrder::swap (*(uint32*) d);
  20226. #endif
  20227. d += destBytesPerSample;
  20228. }
  20229. }
  20230. void AudioDataConverters::convertInt16LEToFloat (const void* const source, float* const dest, int numSamples, const int srcBytesPerSample)
  20231. {
  20232. const float scale = 1.0f / 0x7fff;
  20233. const char* intData = (const char*) source;
  20234. if (source != (void*) dest || srcBytesPerSample >= 4)
  20235. {
  20236. for (int i = 0; i < numSamples; ++i)
  20237. {
  20238. dest[i] = scale * (short) ByteOrder::swapIfBigEndian (*(uint16*)intData);
  20239. intData += srcBytesPerSample;
  20240. }
  20241. }
  20242. else
  20243. {
  20244. intData += srcBytesPerSample * numSamples;
  20245. for (int i = numSamples; --i >= 0;)
  20246. {
  20247. intData -= srcBytesPerSample;
  20248. dest[i] = scale * (short) ByteOrder::swapIfBigEndian (*(uint16*)intData);
  20249. }
  20250. }
  20251. }
  20252. void AudioDataConverters::convertInt16BEToFloat (const void* const source, float* const dest, int numSamples, const int srcBytesPerSample)
  20253. {
  20254. const float scale = 1.0f / 0x7fff;
  20255. const char* intData = (const char*) source;
  20256. if (source != (void*) dest || srcBytesPerSample >= 4)
  20257. {
  20258. for (int i = 0; i < numSamples; ++i)
  20259. {
  20260. dest[i] = scale * (short) ByteOrder::swapIfLittleEndian (*(uint16*)intData);
  20261. intData += srcBytesPerSample;
  20262. }
  20263. }
  20264. else
  20265. {
  20266. intData += srcBytesPerSample * numSamples;
  20267. for (int i = numSamples; --i >= 0;)
  20268. {
  20269. intData -= srcBytesPerSample;
  20270. dest[i] = scale * (short) ByteOrder::swapIfLittleEndian (*(uint16*)intData);
  20271. }
  20272. }
  20273. }
  20274. void AudioDataConverters::convertInt24LEToFloat (const void* const source, float* const dest, int numSamples, const int srcBytesPerSample)
  20275. {
  20276. const float scale = 1.0f / 0x7fffff;
  20277. const char* intData = (const char*) source;
  20278. if (source != (void*) dest || srcBytesPerSample >= 4)
  20279. {
  20280. for (int i = 0; i < numSamples; ++i)
  20281. {
  20282. dest[i] = scale * (short) ByteOrder::littleEndian24Bit (intData);
  20283. intData += srcBytesPerSample;
  20284. }
  20285. }
  20286. else
  20287. {
  20288. intData += srcBytesPerSample * numSamples;
  20289. for (int i = numSamples; --i >= 0;)
  20290. {
  20291. intData -= srcBytesPerSample;
  20292. dest[i] = scale * (short) ByteOrder::littleEndian24Bit (intData);
  20293. }
  20294. }
  20295. }
  20296. void AudioDataConverters::convertInt24BEToFloat (const void* const source, float* const dest, int numSamples, const int srcBytesPerSample)
  20297. {
  20298. const float scale = 1.0f / 0x7fffff;
  20299. const char* intData = (const char*) source;
  20300. if (source != (void*) dest || srcBytesPerSample >= 4)
  20301. {
  20302. for (int i = 0; i < numSamples; ++i)
  20303. {
  20304. dest[i] = scale * (short) ByteOrder::bigEndian24Bit (intData);
  20305. intData += srcBytesPerSample;
  20306. }
  20307. }
  20308. else
  20309. {
  20310. intData += srcBytesPerSample * numSamples;
  20311. for (int i = numSamples; --i >= 0;)
  20312. {
  20313. intData -= srcBytesPerSample;
  20314. dest[i] = scale * (short) ByteOrder::bigEndian24Bit (intData);
  20315. }
  20316. }
  20317. }
  20318. void AudioDataConverters::convertInt32LEToFloat (const void* const source, float* const dest, int numSamples, const int srcBytesPerSample)
  20319. {
  20320. const float scale = 1.0f / 0x7fffffff;
  20321. const char* intData = (const char*) source;
  20322. if (source != (void*) dest || srcBytesPerSample >= 4)
  20323. {
  20324. for (int i = 0; i < numSamples; ++i)
  20325. {
  20326. dest[i] = scale * (int) ByteOrder::swapIfBigEndian (*(uint32*) intData);
  20327. intData += srcBytesPerSample;
  20328. }
  20329. }
  20330. else
  20331. {
  20332. intData += srcBytesPerSample * numSamples;
  20333. for (int i = numSamples; --i >= 0;)
  20334. {
  20335. intData -= srcBytesPerSample;
  20336. dest[i] = scale * (int) ByteOrder::swapIfBigEndian (*(uint32*) intData);
  20337. }
  20338. }
  20339. }
  20340. void AudioDataConverters::convertInt32BEToFloat (const void* const source, float* const dest, int numSamples, const int srcBytesPerSample)
  20341. {
  20342. const float scale = 1.0f / 0x7fffffff;
  20343. const char* intData = (const char*) source;
  20344. if (source != (void*) dest || srcBytesPerSample >= 4)
  20345. {
  20346. for (int i = 0; i < numSamples; ++i)
  20347. {
  20348. dest[i] = scale * (int) ByteOrder::swapIfLittleEndian (*(uint32*) intData);
  20349. intData += srcBytesPerSample;
  20350. }
  20351. }
  20352. else
  20353. {
  20354. intData += srcBytesPerSample * numSamples;
  20355. for (int i = numSamples; --i >= 0;)
  20356. {
  20357. intData -= srcBytesPerSample;
  20358. dest[i] = scale * (int) ByteOrder::swapIfLittleEndian (*(uint32*) intData);
  20359. }
  20360. }
  20361. }
  20362. void AudioDataConverters::convertFloat32LEToFloat (const void* const source, float* const dest, int numSamples, const int srcBytesPerSample)
  20363. {
  20364. const char* s = (const char*) source;
  20365. for (int i = 0; i < numSamples; ++i)
  20366. {
  20367. dest[i] = *(float*)s;
  20368. #if JUCE_BIG_ENDIAN
  20369. uint32* const d = (uint32*) (dest + i);
  20370. *d = ByteOrder::swap (*d);
  20371. #endif
  20372. s += srcBytesPerSample;
  20373. }
  20374. }
  20375. void AudioDataConverters::convertFloat32BEToFloat (const void* const source, float* const dest, int numSamples, const int srcBytesPerSample)
  20376. {
  20377. const char* s = (const char*) source;
  20378. for (int i = 0; i < numSamples; ++i)
  20379. {
  20380. dest[i] = *(float*)s;
  20381. #if JUCE_LITTLE_ENDIAN
  20382. uint32* const d = (uint32*) (dest + i);
  20383. *d = ByteOrder::swap (*d);
  20384. #endif
  20385. s += srcBytesPerSample;
  20386. }
  20387. }
  20388. void AudioDataConverters::convertFloatToFormat (const DataFormat destFormat,
  20389. const float* const source,
  20390. void* const dest,
  20391. const int numSamples)
  20392. {
  20393. switch (destFormat)
  20394. {
  20395. case int16LE:
  20396. convertFloatToInt16LE (source, dest, numSamples);
  20397. break;
  20398. case int16BE:
  20399. convertFloatToInt16BE (source, dest, numSamples);
  20400. break;
  20401. case int24LE:
  20402. convertFloatToInt24LE (source, dest, numSamples);
  20403. break;
  20404. case int24BE:
  20405. convertFloatToInt24BE (source, dest, numSamples);
  20406. break;
  20407. case int32LE:
  20408. convertFloatToInt32LE (source, dest, numSamples);
  20409. break;
  20410. case int32BE:
  20411. convertFloatToInt32BE (source, dest, numSamples);
  20412. break;
  20413. case float32LE:
  20414. convertFloatToFloat32LE (source, dest, numSamples);
  20415. break;
  20416. case float32BE:
  20417. convertFloatToFloat32BE (source, dest, numSamples);
  20418. break;
  20419. default:
  20420. jassertfalse
  20421. break;
  20422. }
  20423. }
  20424. void AudioDataConverters::convertFormatToFloat (const DataFormat sourceFormat,
  20425. const void* const source,
  20426. float* const dest,
  20427. const int numSamples)
  20428. {
  20429. switch (sourceFormat)
  20430. {
  20431. case int16LE:
  20432. convertInt16LEToFloat (source, dest, numSamples);
  20433. break;
  20434. case int16BE:
  20435. convertInt16BEToFloat (source, dest, numSamples);
  20436. break;
  20437. case int24LE:
  20438. convertInt24LEToFloat (source, dest, numSamples);
  20439. break;
  20440. case int24BE:
  20441. convertInt24BEToFloat (source, dest, numSamples);
  20442. break;
  20443. case int32LE:
  20444. convertInt32LEToFloat (source, dest, numSamples);
  20445. break;
  20446. case int32BE:
  20447. convertInt32BEToFloat (source, dest, numSamples);
  20448. break;
  20449. case float32LE:
  20450. convertFloat32LEToFloat (source, dest, numSamples);
  20451. break;
  20452. case float32BE:
  20453. convertFloat32BEToFloat (source, dest, numSamples);
  20454. break;
  20455. default:
  20456. jassertfalse
  20457. break;
  20458. }
  20459. }
  20460. void AudioDataConverters::interleaveSamples (const float** const source,
  20461. float* const dest,
  20462. const int numSamples,
  20463. const int numChannels)
  20464. {
  20465. for (int chan = 0; chan < numChannels; ++chan)
  20466. {
  20467. int i = chan;
  20468. const float* src = source [chan];
  20469. for (int j = 0; j < numSamples; ++j)
  20470. {
  20471. dest [i] = src [j];
  20472. i += numChannels;
  20473. }
  20474. }
  20475. }
  20476. void AudioDataConverters::deinterleaveSamples (const float* const source,
  20477. float** const dest,
  20478. const int numSamples,
  20479. const int numChannels)
  20480. {
  20481. for (int chan = 0; chan < numChannels; ++chan)
  20482. {
  20483. int i = chan;
  20484. float* dst = dest [chan];
  20485. for (int j = 0; j < numSamples; ++j)
  20486. {
  20487. dst [j] = source [i];
  20488. i += numChannels;
  20489. }
  20490. }
  20491. }
  20492. END_JUCE_NAMESPACE
  20493. /*** End of inlined file: juce_AudioDataConverters.cpp ***/
  20494. /*** Start of inlined file: juce_AudioSampleBuffer.cpp ***/
  20495. BEGIN_JUCE_NAMESPACE
  20496. AudioSampleBuffer::AudioSampleBuffer (const int numChannels_,
  20497. const int numSamples) throw()
  20498. : numChannels (numChannels_),
  20499. size (numSamples)
  20500. {
  20501. jassert (numSamples >= 0);
  20502. jassert (numChannels_ > 0);
  20503. allocateData();
  20504. }
  20505. AudioSampleBuffer::AudioSampleBuffer (const AudioSampleBuffer& other) throw()
  20506. : numChannels (other.numChannels),
  20507. size (other.size)
  20508. {
  20509. allocateData();
  20510. const size_t numBytes = size * sizeof (float);
  20511. for (int i = 0; i < numChannels; ++i)
  20512. memcpy (channels[i], other.channels[i], numBytes);
  20513. }
  20514. void AudioSampleBuffer::allocateData()
  20515. {
  20516. const size_t channelListSize = (numChannels + 1) * sizeof (float*);
  20517. allocatedBytes = (int) (numChannels * size * sizeof (float) + channelListSize + 32);
  20518. allocatedData.malloc (allocatedBytes);
  20519. channels = reinterpret_cast <float**> (allocatedData.getData());
  20520. float* chan = (float*) (allocatedData + channelListSize);
  20521. for (int i = 0; i < numChannels; ++i)
  20522. {
  20523. channels[i] = chan;
  20524. chan += size;
  20525. }
  20526. channels [numChannels] = 0;
  20527. }
  20528. AudioSampleBuffer::AudioSampleBuffer (float** dataToReferTo,
  20529. const int numChannels_,
  20530. const int numSamples) throw()
  20531. : numChannels (numChannels_),
  20532. size (numSamples),
  20533. allocatedBytes (0)
  20534. {
  20535. jassert (numChannels_ > 0);
  20536. allocateChannels (dataToReferTo);
  20537. }
  20538. void AudioSampleBuffer::setDataToReferTo (float** dataToReferTo,
  20539. const int newNumChannels,
  20540. const int newNumSamples) throw()
  20541. {
  20542. jassert (newNumChannels > 0);
  20543. allocatedBytes = 0;
  20544. allocatedData.free();
  20545. numChannels = newNumChannels;
  20546. size = newNumSamples;
  20547. allocateChannels (dataToReferTo);
  20548. }
  20549. void AudioSampleBuffer::allocateChannels (float** const dataToReferTo)
  20550. {
  20551. // (try to avoid doing a malloc here, as that'll blow up things like Pro-Tools)
  20552. if (numChannels < numElementsInArray (preallocatedChannelSpace))
  20553. {
  20554. channels = static_cast <float**> (preallocatedChannelSpace);
  20555. }
  20556. else
  20557. {
  20558. allocatedData.malloc (numChannels + 1, sizeof (float*));
  20559. channels = reinterpret_cast <float**> (allocatedData.getData());
  20560. }
  20561. for (int i = 0; i < numChannels; ++i)
  20562. {
  20563. // you have to pass in the same number of valid pointers as numChannels
  20564. jassert (dataToReferTo[i] != 0);
  20565. channels[i] = dataToReferTo[i];
  20566. }
  20567. channels [numChannels] = 0;
  20568. }
  20569. AudioSampleBuffer& AudioSampleBuffer::operator= (const AudioSampleBuffer& other) throw()
  20570. {
  20571. if (this != &other)
  20572. {
  20573. setSize (other.getNumChannels(), other.getNumSamples(), false, false, false);
  20574. const size_t numBytes = size * sizeof (float);
  20575. for (int i = 0; i < numChannels; ++i)
  20576. memcpy (channels[i], other.channels[i], numBytes);
  20577. }
  20578. return *this;
  20579. }
  20580. AudioSampleBuffer::~AudioSampleBuffer() throw()
  20581. {
  20582. }
  20583. void AudioSampleBuffer::setSize (const int newNumChannels,
  20584. const int newNumSamples,
  20585. const bool keepExistingContent,
  20586. const bool clearExtraSpace,
  20587. const bool avoidReallocating) throw()
  20588. {
  20589. jassert (newNumChannels > 0);
  20590. if (newNumSamples != size || newNumChannels != numChannels)
  20591. {
  20592. const size_t channelListSize = (newNumChannels + 1) * sizeof (float*);
  20593. const size_t newTotalBytes = (newNumChannels * newNumSamples * sizeof (float)) + channelListSize + 32;
  20594. if (keepExistingContent)
  20595. {
  20596. HeapBlock <char> newData;
  20597. newData.allocate (newTotalBytes, clearExtraSpace);
  20598. const int numChansToCopy = jmin (numChannels, newNumChannels);
  20599. const size_t numBytesToCopy = sizeof (float) * jmin (newNumSamples, size);
  20600. float** const newChannels = reinterpret_cast <float**> (newData.getData());
  20601. float* newChan = reinterpret_cast <float*> (newData + channelListSize);
  20602. for (int i = 0; i < numChansToCopy; ++i)
  20603. {
  20604. memcpy (newChan, channels[i], numBytesToCopy);
  20605. newChannels[i] = newChan;
  20606. newChan += newNumSamples;
  20607. }
  20608. allocatedData.swapWith (newData);
  20609. allocatedBytes = (int) newTotalBytes;
  20610. channels = newChannels;
  20611. }
  20612. else
  20613. {
  20614. if (avoidReallocating && allocatedBytes >= newTotalBytes)
  20615. {
  20616. if (clearExtraSpace)
  20617. zeromem (allocatedData, newTotalBytes);
  20618. }
  20619. else
  20620. {
  20621. allocatedBytes = newTotalBytes;
  20622. allocatedData.allocate (newTotalBytes, clearExtraSpace);
  20623. channels = reinterpret_cast <float**> (allocatedData.getData());
  20624. }
  20625. float* chan = reinterpret_cast <float*> (allocatedData + channelListSize);
  20626. for (int i = 0; i < newNumChannels; ++i)
  20627. {
  20628. channels[i] = chan;
  20629. chan += newNumSamples;
  20630. }
  20631. }
  20632. channels [newNumChannels] = 0;
  20633. size = newNumSamples;
  20634. numChannels = newNumChannels;
  20635. }
  20636. }
  20637. void AudioSampleBuffer::clear() throw()
  20638. {
  20639. for (int i = 0; i < numChannels; ++i)
  20640. zeromem (channels[i], size * sizeof (float));
  20641. }
  20642. void AudioSampleBuffer::clear (const int startSample,
  20643. const int numSamples) throw()
  20644. {
  20645. jassert (startSample >= 0 && startSample + numSamples <= size);
  20646. for (int i = 0; i < numChannels; ++i)
  20647. zeromem (channels [i] + startSample, numSamples * sizeof (float));
  20648. }
  20649. void AudioSampleBuffer::clear (const int channel,
  20650. const int startSample,
  20651. const int numSamples) throw()
  20652. {
  20653. jassert (((unsigned int) channel) < (unsigned int) numChannels);
  20654. jassert (startSample >= 0 && startSample + numSamples <= size);
  20655. zeromem (channels [channel] + startSample, numSamples * sizeof (float));
  20656. }
  20657. void AudioSampleBuffer::applyGain (const int channel,
  20658. const int startSample,
  20659. int numSamples,
  20660. const float gain) throw()
  20661. {
  20662. jassert (((unsigned int) channel) < (unsigned int) numChannels);
  20663. jassert (startSample >= 0 && startSample + numSamples <= size);
  20664. if (gain != 1.0f)
  20665. {
  20666. float* d = channels [channel] + startSample;
  20667. if (gain == 0.0f)
  20668. {
  20669. zeromem (d, sizeof (float) * numSamples);
  20670. }
  20671. else
  20672. {
  20673. while (--numSamples >= 0)
  20674. *d++ *= gain;
  20675. }
  20676. }
  20677. }
  20678. void AudioSampleBuffer::applyGainRamp (const int channel,
  20679. const int startSample,
  20680. int numSamples,
  20681. float startGain,
  20682. float endGain) throw()
  20683. {
  20684. if (startGain == endGain)
  20685. {
  20686. applyGain (channel, startSample, numSamples, startGain);
  20687. }
  20688. else
  20689. {
  20690. jassert (((unsigned int) channel) < (unsigned int) numChannels);
  20691. jassert (startSample >= 0 && startSample + numSamples <= size);
  20692. const float increment = (endGain - startGain) / numSamples;
  20693. float* d = channels [channel] + startSample;
  20694. while (--numSamples >= 0)
  20695. {
  20696. *d++ *= startGain;
  20697. startGain += increment;
  20698. }
  20699. }
  20700. }
  20701. void AudioSampleBuffer::applyGain (const int startSample,
  20702. const int numSamples,
  20703. const float gain) throw()
  20704. {
  20705. for (int i = 0; i < numChannels; ++i)
  20706. applyGain (i, startSample, numSamples, gain);
  20707. }
  20708. void AudioSampleBuffer::addFrom (const int destChannel,
  20709. const int destStartSample,
  20710. const AudioSampleBuffer& source,
  20711. const int sourceChannel,
  20712. const int sourceStartSample,
  20713. int numSamples,
  20714. const float gain) throw()
  20715. {
  20716. jassert (&source != this || sourceChannel != destChannel);
  20717. jassert (((unsigned int) destChannel) < (unsigned int) numChannels);
  20718. jassert (destStartSample >= 0 && destStartSample + numSamples <= size);
  20719. jassert (((unsigned int) sourceChannel) < (unsigned int) source.numChannels);
  20720. jassert (sourceStartSample >= 0 && sourceStartSample + numSamples <= source.size);
  20721. if (gain != 0.0f && numSamples > 0)
  20722. {
  20723. float* d = channels [destChannel] + destStartSample;
  20724. const float* s = source.channels [sourceChannel] + sourceStartSample;
  20725. if (gain != 1.0f)
  20726. {
  20727. while (--numSamples >= 0)
  20728. *d++ += gain * *s++;
  20729. }
  20730. else
  20731. {
  20732. while (--numSamples >= 0)
  20733. *d++ += *s++;
  20734. }
  20735. }
  20736. }
  20737. void AudioSampleBuffer::addFrom (const int destChannel,
  20738. const int destStartSample,
  20739. const float* source,
  20740. int numSamples,
  20741. const float gain) throw()
  20742. {
  20743. jassert (((unsigned int) destChannel) < (unsigned int) numChannels);
  20744. jassert (destStartSample >= 0 && destStartSample + numSamples <= size);
  20745. jassert (source != 0);
  20746. if (gain != 0.0f && numSamples > 0)
  20747. {
  20748. float* d = channels [destChannel] + destStartSample;
  20749. if (gain != 1.0f)
  20750. {
  20751. while (--numSamples >= 0)
  20752. *d++ += gain * *source++;
  20753. }
  20754. else
  20755. {
  20756. while (--numSamples >= 0)
  20757. *d++ += *source++;
  20758. }
  20759. }
  20760. }
  20761. void AudioSampleBuffer::addFromWithRamp (const int destChannel,
  20762. const int destStartSample,
  20763. const float* source,
  20764. int numSamples,
  20765. float startGain,
  20766. const float endGain) throw()
  20767. {
  20768. jassert (((unsigned int) destChannel) < (unsigned int) numChannels);
  20769. jassert (destStartSample >= 0 && destStartSample + numSamples <= size);
  20770. jassert (source != 0);
  20771. if (startGain == endGain)
  20772. {
  20773. addFrom (destChannel,
  20774. destStartSample,
  20775. source,
  20776. numSamples,
  20777. startGain);
  20778. }
  20779. else
  20780. {
  20781. if (numSamples > 0 && (startGain != 0.0f || endGain != 0.0f))
  20782. {
  20783. const float increment = (endGain - startGain) / numSamples;
  20784. float* d = channels [destChannel] + destStartSample;
  20785. while (--numSamples >= 0)
  20786. {
  20787. *d++ += startGain * *source++;
  20788. startGain += increment;
  20789. }
  20790. }
  20791. }
  20792. }
  20793. void AudioSampleBuffer::copyFrom (const int destChannel,
  20794. const int destStartSample,
  20795. const AudioSampleBuffer& source,
  20796. const int sourceChannel,
  20797. const int sourceStartSample,
  20798. int numSamples) throw()
  20799. {
  20800. jassert (&source != this || sourceChannel != destChannel);
  20801. jassert (((unsigned int) destChannel) < (unsigned int) numChannels);
  20802. jassert (destStartSample >= 0 && destStartSample + numSamples <= size);
  20803. jassert (((unsigned int) sourceChannel) < (unsigned int) source.numChannels);
  20804. jassert (sourceStartSample >= 0 && sourceStartSample + numSamples <= source.size);
  20805. if (numSamples > 0)
  20806. {
  20807. memcpy (channels [destChannel] + destStartSample,
  20808. source.channels [sourceChannel] + sourceStartSample,
  20809. sizeof (float) * numSamples);
  20810. }
  20811. }
  20812. void AudioSampleBuffer::copyFrom (const int destChannel,
  20813. const int destStartSample,
  20814. const float* source,
  20815. int numSamples) throw()
  20816. {
  20817. jassert (((unsigned int) destChannel) < (unsigned int) numChannels);
  20818. jassert (destStartSample >= 0 && destStartSample + numSamples <= size);
  20819. jassert (source != 0);
  20820. if (numSamples > 0)
  20821. {
  20822. memcpy (channels [destChannel] + destStartSample,
  20823. source,
  20824. sizeof (float) * numSamples);
  20825. }
  20826. }
  20827. void AudioSampleBuffer::copyFrom (const int destChannel,
  20828. const int destStartSample,
  20829. const float* source,
  20830. int numSamples,
  20831. const float gain) throw()
  20832. {
  20833. jassert (((unsigned int) destChannel) < (unsigned int) numChannels);
  20834. jassert (destStartSample >= 0 && destStartSample + numSamples <= size);
  20835. jassert (source != 0);
  20836. if (numSamples > 0)
  20837. {
  20838. float* d = channels [destChannel] + destStartSample;
  20839. if (gain != 1.0f)
  20840. {
  20841. if (gain == 0)
  20842. {
  20843. zeromem (d, sizeof (float) * numSamples);
  20844. }
  20845. else
  20846. {
  20847. while (--numSamples >= 0)
  20848. *d++ = gain * *source++;
  20849. }
  20850. }
  20851. else
  20852. {
  20853. memcpy (d, source, sizeof (float) * numSamples);
  20854. }
  20855. }
  20856. }
  20857. void AudioSampleBuffer::copyFromWithRamp (const int destChannel,
  20858. const int destStartSample,
  20859. const float* source,
  20860. int numSamples,
  20861. float startGain,
  20862. float endGain) throw()
  20863. {
  20864. jassert (((unsigned int) destChannel) < (unsigned int) numChannels);
  20865. jassert (destStartSample >= 0 && destStartSample + numSamples <= size);
  20866. jassert (source != 0);
  20867. if (startGain == endGain)
  20868. {
  20869. copyFrom (destChannel,
  20870. destStartSample,
  20871. source,
  20872. numSamples,
  20873. startGain);
  20874. }
  20875. else
  20876. {
  20877. if (numSamples > 0 && (startGain != 0.0f || endGain != 0.0f))
  20878. {
  20879. const float increment = (endGain - startGain) / numSamples;
  20880. float* d = channels [destChannel] + destStartSample;
  20881. while (--numSamples >= 0)
  20882. {
  20883. *d++ = startGain * *source++;
  20884. startGain += increment;
  20885. }
  20886. }
  20887. }
  20888. }
  20889. void AudioSampleBuffer::findMinMax (const int channel,
  20890. const int startSample,
  20891. int numSamples,
  20892. float& minVal,
  20893. float& maxVal) const throw()
  20894. {
  20895. jassert (((unsigned int) channel) < (unsigned int) numChannels);
  20896. jassert (startSample >= 0 && startSample + numSamples <= size);
  20897. if (numSamples <= 0)
  20898. {
  20899. minVal = 0.0f;
  20900. maxVal = 0.0f;
  20901. }
  20902. else
  20903. {
  20904. const float* d = channels [channel] + startSample;
  20905. float mn = *d++;
  20906. float mx = mn;
  20907. while (--numSamples > 0) // (> 0 rather than >= 0 because we've already taken the first sample)
  20908. {
  20909. const float samp = *d++;
  20910. if (samp > mx)
  20911. mx = samp;
  20912. if (samp < mn)
  20913. mn = samp;
  20914. }
  20915. maxVal = mx;
  20916. minVal = mn;
  20917. }
  20918. }
  20919. float AudioSampleBuffer::getMagnitude (const int channel,
  20920. const int startSample,
  20921. const int numSamples) const throw()
  20922. {
  20923. jassert (((unsigned int) channel) < (unsigned int) numChannels);
  20924. jassert (startSample >= 0 && startSample + numSamples <= size);
  20925. float mn, mx;
  20926. findMinMax (channel, startSample, numSamples, mn, mx);
  20927. return jmax (mn, -mn, mx, -mx);
  20928. }
  20929. float AudioSampleBuffer::getMagnitude (const int startSample,
  20930. const int numSamples) const throw()
  20931. {
  20932. float mag = 0.0f;
  20933. for (int i = 0; i < numChannels; ++i)
  20934. mag = jmax (mag, getMagnitude (i, startSample, numSamples));
  20935. return mag;
  20936. }
  20937. float AudioSampleBuffer::getRMSLevel (const int channel,
  20938. const int startSample,
  20939. const int numSamples) const throw()
  20940. {
  20941. jassert (((unsigned int) channel) < (unsigned int) numChannels);
  20942. jassert (startSample >= 0 && startSample + numSamples <= size);
  20943. if (numSamples <= 0 || channel < 0 || channel >= numChannels)
  20944. return 0.0f;
  20945. const float* const data = channels [channel] + startSample;
  20946. double sum = 0.0;
  20947. for (int i = 0; i < numSamples; ++i)
  20948. {
  20949. const float sample = data [i];
  20950. sum += sample * sample;
  20951. }
  20952. return (float) sqrt (sum / numSamples);
  20953. }
  20954. void AudioSampleBuffer::readFromAudioReader (AudioFormatReader* reader,
  20955. const int startSample,
  20956. const int numSamples,
  20957. const int readerStartSample,
  20958. const bool useLeftChan,
  20959. const bool useRightChan) throw()
  20960. {
  20961. jassert (reader != 0);
  20962. jassert (startSample >= 0 && startSample + numSamples <= size);
  20963. if (numSamples > 0)
  20964. {
  20965. int* chans[3];
  20966. if (useLeftChan == useRightChan)
  20967. {
  20968. chans[0] = (int*) getSampleData (0, startSample);
  20969. chans[1] = (reader->numChannels > 1 && getNumChannels() > 1) ? (int*) getSampleData (1, startSample) : 0;
  20970. }
  20971. else if (useLeftChan || (reader->numChannels == 1))
  20972. {
  20973. chans[0] = (int*) getSampleData (0, startSample);
  20974. chans[1] = 0;
  20975. }
  20976. else if (useRightChan)
  20977. {
  20978. chans[0] = 0;
  20979. chans[1] = (int*) getSampleData (0, startSample);
  20980. }
  20981. chans[2] = 0;
  20982. reader->read (chans, 2, readerStartSample, numSamples, true);
  20983. if (! reader->usesFloatingPointData)
  20984. {
  20985. for (int j = 0; j < 2; ++j)
  20986. {
  20987. float* const d = (float*) (chans[j]);
  20988. if (d != 0)
  20989. {
  20990. const float multiplier = 1.0f / 0x7fffffff;
  20991. for (int i = 0; i < numSamples; ++i)
  20992. d[i] = *(int*)(d + i) * multiplier;
  20993. }
  20994. }
  20995. }
  20996. if (numChannels > 1 && (chans[0] == 0 || chans[1] == 0))
  20997. {
  20998. // if this is a stereo buffer and the source was mono, dupe the first channel..
  20999. memcpy (getSampleData (1, startSample),
  21000. getSampleData (0, startSample),
  21001. sizeof (float) * numSamples);
  21002. }
  21003. }
  21004. }
  21005. void AudioSampleBuffer::writeToAudioWriter (AudioFormatWriter* writer,
  21006. const int startSample,
  21007. const int numSamples) const throw()
  21008. {
  21009. jassert (startSample >= 0 && startSample + numSamples <= size);
  21010. if (numSamples > 0)
  21011. {
  21012. int* chans [3];
  21013. if (writer->isFloatingPoint())
  21014. {
  21015. chans[0] = (int*) getSampleData (0, startSample);
  21016. if (numChannels > 1)
  21017. chans[1] = (int*) getSampleData (1, startSample);
  21018. else
  21019. chans[1] = 0;
  21020. chans[2] = 0;
  21021. writer->write ((const int**) chans, numSamples);
  21022. }
  21023. else
  21024. {
  21025. HeapBlock <int> tempBuffer (numSamples * 2);
  21026. chans[0] = tempBuffer;
  21027. if (numChannels > 1)
  21028. chans[1] = chans[0] + numSamples;
  21029. else
  21030. chans[1] = 0;
  21031. chans[2] = 0;
  21032. for (int j = 0; j < 2; ++j)
  21033. {
  21034. int* const dest = chans[j];
  21035. if (dest != 0)
  21036. {
  21037. const float* const src = channels [j] + startSample;
  21038. for (int i = 0; i < numSamples; ++i)
  21039. {
  21040. const double samp = src[i];
  21041. if (samp <= -1.0)
  21042. dest[i] = std::numeric_limits<int>::min();
  21043. else if (samp >= 1.0)
  21044. dest[i] = std::numeric_limits<int>::max();
  21045. else
  21046. dest[i] = roundToInt (std::numeric_limits<int>::max() * samp);
  21047. }
  21048. }
  21049. }
  21050. writer->write ((const int**) chans, numSamples);
  21051. }
  21052. }
  21053. }
  21054. END_JUCE_NAMESPACE
  21055. /*** End of inlined file: juce_AudioSampleBuffer.cpp ***/
  21056. /*** Start of inlined file: juce_IIRFilter.cpp ***/
  21057. BEGIN_JUCE_NAMESPACE
  21058. IIRFilter::IIRFilter() throw()
  21059. : active (false)
  21060. {
  21061. reset();
  21062. }
  21063. IIRFilter::IIRFilter (const IIRFilter& other) throw()
  21064. : active (other.active)
  21065. {
  21066. const ScopedLock sl (other.processLock);
  21067. memcpy (coefficients, other.coefficients, sizeof (coefficients));
  21068. reset();
  21069. }
  21070. IIRFilter::~IIRFilter() throw()
  21071. {
  21072. }
  21073. void IIRFilter::reset() throw()
  21074. {
  21075. const ScopedLock sl (processLock);
  21076. x1 = 0;
  21077. x2 = 0;
  21078. y1 = 0;
  21079. y2 = 0;
  21080. }
  21081. float IIRFilter::processSingleSampleRaw (const float in) throw()
  21082. {
  21083. float out = coefficients[0] * in
  21084. + coefficients[1] * x1
  21085. + coefficients[2] * x2
  21086. - coefficients[4] * y1
  21087. - coefficients[5] * y2;
  21088. #if JUCE_INTEL
  21089. if (! (out < -1.0e-8 || out > 1.0e-8))
  21090. out = 0;
  21091. #endif
  21092. x2 = x1;
  21093. x1 = in;
  21094. y2 = y1;
  21095. y1 = out;
  21096. return out;
  21097. }
  21098. void IIRFilter::processSamples (float* const samples,
  21099. const int numSamples) throw()
  21100. {
  21101. const ScopedLock sl (processLock);
  21102. if (active)
  21103. {
  21104. for (int i = 0; i < numSamples; ++i)
  21105. {
  21106. const float in = samples[i];
  21107. float out = coefficients[0] * in
  21108. + coefficients[1] * x1
  21109. + coefficients[2] * x2
  21110. - coefficients[4] * y1
  21111. - coefficients[5] * y2;
  21112. #if JUCE_INTEL
  21113. if (! (out < -1.0e-8 || out > 1.0e-8))
  21114. out = 0;
  21115. #endif
  21116. x2 = x1;
  21117. x1 = in;
  21118. y2 = y1;
  21119. y1 = out;
  21120. samples[i] = out;
  21121. }
  21122. }
  21123. }
  21124. void IIRFilter::makeLowPass (const double sampleRate,
  21125. const double frequency) throw()
  21126. {
  21127. jassert (sampleRate > 0);
  21128. const double n = 1.0 / tan (double_Pi * frequency / sampleRate);
  21129. const double nSquared = n * n;
  21130. const double c1 = 1.0 / (1.0 + sqrt (2.0) * n + nSquared);
  21131. setCoefficients (c1,
  21132. c1 * 2.0f,
  21133. c1,
  21134. 1.0,
  21135. c1 * 2.0 * (1.0 - nSquared),
  21136. c1 * (1.0 - sqrt (2.0) * n + nSquared));
  21137. }
  21138. void IIRFilter::makeHighPass (const double sampleRate,
  21139. const double frequency) throw()
  21140. {
  21141. const double n = tan (double_Pi * frequency / sampleRate);
  21142. const double nSquared = n * n;
  21143. const double c1 = 1.0 / (1.0 + sqrt (2.0) * n + nSquared);
  21144. setCoefficients (c1,
  21145. c1 * -2.0f,
  21146. c1,
  21147. 1.0,
  21148. c1 * 2.0 * (nSquared - 1.0),
  21149. c1 * (1.0 - sqrt (2.0) * n + nSquared));
  21150. }
  21151. void IIRFilter::makeLowShelf (const double sampleRate,
  21152. const double cutOffFrequency,
  21153. const double Q,
  21154. const float gainFactor) throw()
  21155. {
  21156. jassert (sampleRate > 0);
  21157. jassert (Q > 0);
  21158. const double A = jmax (0.0f, gainFactor);
  21159. const double aminus1 = A - 1.0;
  21160. const double aplus1 = A + 1.0;
  21161. const double omega = (double_Pi * 2.0 * jmax (cutOffFrequency, 2.0)) / sampleRate;
  21162. const double coso = cos (omega);
  21163. const double beta = sin (omega) * sqrt (A) / Q;
  21164. const double aminus1TimesCoso = aminus1 * coso;
  21165. setCoefficients (A * (aplus1 - aminus1TimesCoso + beta),
  21166. A * 2.0 * (aminus1 - aplus1 * coso),
  21167. A * (aplus1 - aminus1TimesCoso - beta),
  21168. aplus1 + aminus1TimesCoso + beta,
  21169. -2.0 * (aminus1 + aplus1 * coso),
  21170. aplus1 + aminus1TimesCoso - beta);
  21171. }
  21172. void IIRFilter::makeHighShelf (const double sampleRate,
  21173. const double cutOffFrequency,
  21174. const double Q,
  21175. const float gainFactor) throw()
  21176. {
  21177. jassert (sampleRate > 0);
  21178. jassert (Q > 0);
  21179. const double A = jmax (0.0f, gainFactor);
  21180. const double aminus1 = A - 1.0;
  21181. const double aplus1 = A + 1.0;
  21182. const double omega = (double_Pi * 2.0 * jmax (cutOffFrequency, 2.0)) / sampleRate;
  21183. const double coso = cos (omega);
  21184. const double beta = sin (omega) * sqrt (A) / Q;
  21185. const double aminus1TimesCoso = aminus1 * coso;
  21186. setCoefficients (A * (aplus1 + aminus1TimesCoso + beta),
  21187. A * -2.0 * (aminus1 + aplus1 * coso),
  21188. A * (aplus1 + aminus1TimesCoso - beta),
  21189. aplus1 - aminus1TimesCoso + beta,
  21190. 2.0 * (aminus1 - aplus1 * coso),
  21191. aplus1 - aminus1TimesCoso - beta);
  21192. }
  21193. void IIRFilter::makeBandPass (const double sampleRate,
  21194. const double centreFrequency,
  21195. const double Q,
  21196. const float gainFactor) throw()
  21197. {
  21198. jassert (sampleRate > 0);
  21199. jassert (Q > 0);
  21200. const double A = jmax (0.0f, gainFactor);
  21201. const double omega = (double_Pi * 2.0 * jmax (centreFrequency, 2.0)) / sampleRate;
  21202. const double alpha = 0.5 * sin (omega) / Q;
  21203. const double c2 = -2.0 * cos (omega);
  21204. const double alphaTimesA = alpha * A;
  21205. const double alphaOverA = alpha / A;
  21206. setCoefficients (1.0 + alphaTimesA,
  21207. c2,
  21208. 1.0 - alphaTimesA,
  21209. 1.0 + alphaOverA,
  21210. c2,
  21211. 1.0 - alphaOverA);
  21212. }
  21213. void IIRFilter::makeInactive() throw()
  21214. {
  21215. const ScopedLock sl (processLock);
  21216. active = false;
  21217. }
  21218. void IIRFilter::copyCoefficientsFrom (const IIRFilter& other) throw()
  21219. {
  21220. const ScopedLock sl (processLock);
  21221. memcpy (coefficients, other.coefficients, sizeof (coefficients));
  21222. active = other.active;
  21223. }
  21224. void IIRFilter::setCoefficients (double c1,
  21225. double c2,
  21226. double c3,
  21227. double c4,
  21228. double c5,
  21229. double c6) throw()
  21230. {
  21231. const double a = 1.0 / c4;
  21232. c1 *= a;
  21233. c2 *= a;
  21234. c3 *= a;
  21235. c5 *= a;
  21236. c6 *= a;
  21237. const ScopedLock sl (processLock);
  21238. coefficients[0] = (float) c1;
  21239. coefficients[1] = (float) c2;
  21240. coefficients[2] = (float) c3;
  21241. coefficients[3] = (float) c4;
  21242. coefficients[4] = (float) c5;
  21243. coefficients[5] = (float) c6;
  21244. active = true;
  21245. }
  21246. END_JUCE_NAMESPACE
  21247. /*** End of inlined file: juce_IIRFilter.cpp ***/
  21248. /*** Start of inlined file: juce_MidiBuffer.cpp ***/
  21249. BEGIN_JUCE_NAMESPACE
  21250. MidiBuffer::MidiBuffer() throw()
  21251. : bytesUsed (0)
  21252. {
  21253. }
  21254. MidiBuffer::MidiBuffer (const MidiMessage& message) throw()
  21255. : bytesUsed (0)
  21256. {
  21257. addEvent (message, 0);
  21258. }
  21259. MidiBuffer::MidiBuffer (const MidiBuffer& other) throw()
  21260. : data (other.data),
  21261. bytesUsed (other.bytesUsed)
  21262. {
  21263. }
  21264. MidiBuffer& MidiBuffer::operator= (const MidiBuffer& other) throw()
  21265. {
  21266. bytesUsed = other.bytesUsed;
  21267. data = other.data;
  21268. return *this;
  21269. }
  21270. void MidiBuffer::swap (MidiBuffer& other)
  21271. {
  21272. data.swapWith (other.data);
  21273. swapVariables <int> (bytesUsed, other.bytesUsed);
  21274. }
  21275. MidiBuffer::~MidiBuffer() throw()
  21276. {
  21277. }
  21278. void MidiBuffer::clear() throw()
  21279. {
  21280. bytesUsed = 0;
  21281. }
  21282. void MidiBuffer::clear (const int startSample,
  21283. const int numSamples) throw()
  21284. {
  21285. uint8* const start = findEventAfter (getData(), startSample - 1);
  21286. uint8* const end = findEventAfter (start, startSample + numSamples - 1);
  21287. if (end > start)
  21288. {
  21289. const int bytesToMove = bytesUsed - (int) (end - getData());
  21290. if (bytesToMove > 0)
  21291. memmove (start, end, bytesToMove);
  21292. bytesUsed -= (int) (end - start);
  21293. }
  21294. }
  21295. void MidiBuffer::addEvent (const MidiMessage& m,
  21296. const int sampleNumber) throw()
  21297. {
  21298. addEvent (m.getRawData(), m.getRawDataSize(), sampleNumber);
  21299. }
  21300. static int findActualEventLength (const uint8* const data,
  21301. const int maxBytes) throw()
  21302. {
  21303. unsigned int byte = (unsigned int) *data;
  21304. int size = 0;
  21305. if (byte == 0xf0 || byte == 0xf7)
  21306. {
  21307. const uint8* d = data + 1;
  21308. while (d < data + maxBytes)
  21309. if (*d++ == 0xf7)
  21310. break;
  21311. size = (int) (d - data);
  21312. }
  21313. else if (byte == 0xff)
  21314. {
  21315. int n;
  21316. const int bytesLeft = MidiMessage::readVariableLengthVal (data + 1, n);
  21317. size = jmin (maxBytes, n + 2 + bytesLeft);
  21318. }
  21319. else if (byte >= 0x80)
  21320. {
  21321. size = jmin (maxBytes, MidiMessage::getMessageLengthFromFirstByte ((uint8) byte));
  21322. }
  21323. return size;
  21324. }
  21325. void MidiBuffer::addEvent (const uint8* const newData,
  21326. const int maxBytes,
  21327. const int sampleNumber) throw()
  21328. {
  21329. const int numBytes = findActualEventLength (newData, maxBytes);
  21330. if (numBytes > 0)
  21331. {
  21332. int spaceNeeded = bytesUsed + numBytes + 6;
  21333. data.ensureSize ((spaceNeeded + spaceNeeded / 2 + 8) & ~7);
  21334. uint8* d = findEventAfter (getData(), sampleNumber);
  21335. const int bytesToMove = bytesUsed - (int) (d - getData());
  21336. if (bytesToMove > 0)
  21337. memmove (d + numBytes + 6,
  21338. d,
  21339. bytesToMove);
  21340. *(int*) d = sampleNumber;
  21341. d += 4;
  21342. *(uint16*) d = (uint16) numBytes;
  21343. d += 2;
  21344. memcpy (d, newData, numBytes);
  21345. bytesUsed += numBytes + 6;
  21346. }
  21347. }
  21348. void MidiBuffer::addEvents (const MidiBuffer& otherBuffer,
  21349. const int startSample,
  21350. const int numSamples,
  21351. const int sampleDeltaToAdd) throw()
  21352. {
  21353. Iterator i (otherBuffer);
  21354. i.setNextSamplePosition (startSample);
  21355. const uint8* eventData;
  21356. int eventSize, position;
  21357. while (i.getNextEvent (eventData, eventSize, position)
  21358. && (position < startSample + numSamples || numSamples < 0))
  21359. {
  21360. addEvent (eventData, eventSize, position + sampleDeltaToAdd);
  21361. }
  21362. }
  21363. bool MidiBuffer::isEmpty() const throw()
  21364. {
  21365. return bytesUsed == 0;
  21366. }
  21367. int MidiBuffer::getNumEvents() const throw()
  21368. {
  21369. int n = 0;
  21370. const uint8* d = getData();
  21371. const uint8* const end = d + bytesUsed;
  21372. while (d < end)
  21373. {
  21374. d += 4;
  21375. d += 2 + *(const uint16*) d;
  21376. ++n;
  21377. }
  21378. return n;
  21379. }
  21380. int MidiBuffer::getFirstEventTime() const throw()
  21381. {
  21382. return (bytesUsed > 0) ? *reinterpret_cast <const int*> (data.getData()) : 0;
  21383. }
  21384. int MidiBuffer::getLastEventTime() const throw()
  21385. {
  21386. if (bytesUsed == 0)
  21387. return 0;
  21388. const uint8* d = getData();
  21389. const uint8* const endData = d + bytesUsed;
  21390. for (;;)
  21391. {
  21392. const uint8* nextOne = d + 6 + * (const uint16*) (d + 4);
  21393. if (nextOne >= endData)
  21394. return *(const int*) d;
  21395. d = nextOne;
  21396. }
  21397. }
  21398. uint8* MidiBuffer::findEventAfter (uint8* d, const int samplePosition) const throw()
  21399. {
  21400. const uint8* const endData = getData() + bytesUsed;
  21401. while (d < endData && *(int*) d <= samplePosition)
  21402. {
  21403. d += 4;
  21404. d += 2 + *(uint16*) d;
  21405. }
  21406. return d;
  21407. }
  21408. MidiBuffer::Iterator::Iterator (const MidiBuffer& buffer_) throw()
  21409. : buffer (buffer_),
  21410. data (buffer_.getData())
  21411. {
  21412. }
  21413. MidiBuffer::Iterator::~Iterator() throw()
  21414. {
  21415. }
  21416. void MidiBuffer::Iterator::setNextSamplePosition (const int samplePosition) throw()
  21417. {
  21418. data = buffer.getData();
  21419. const uint8* dataEnd = data + buffer.bytesUsed;
  21420. while (data < dataEnd && *reinterpret_cast<const int*> (data) < samplePosition)
  21421. {
  21422. data += 4;
  21423. data += 2 + *(uint16*) data;
  21424. }
  21425. }
  21426. bool MidiBuffer::Iterator::getNextEvent (const uint8* &midiData,
  21427. int& numBytes,
  21428. int& samplePosition) throw()
  21429. {
  21430. if (data >= buffer.getData() + buffer.bytesUsed)
  21431. return false;
  21432. samplePosition = *(int*) data;
  21433. data += 4;
  21434. numBytes = *(uint16*) data;
  21435. data += 2;
  21436. midiData = data;
  21437. data += numBytes;
  21438. return true;
  21439. }
  21440. bool MidiBuffer::Iterator::getNextEvent (MidiMessage& result,
  21441. int& samplePosition) throw()
  21442. {
  21443. if (data >= buffer.getData() + buffer.bytesUsed)
  21444. return false;
  21445. samplePosition = *reinterpret_cast <const int*> (data);
  21446. data += 4;
  21447. const int numBytes = *reinterpret_cast <const uint16*> (data);
  21448. data += 2;
  21449. result = MidiMessage (data, numBytes, samplePosition);
  21450. data += numBytes;
  21451. return true;
  21452. }
  21453. END_JUCE_NAMESPACE
  21454. /*** End of inlined file: juce_MidiBuffer.cpp ***/
  21455. /*** Start of inlined file: juce_MidiFile.cpp ***/
  21456. BEGIN_JUCE_NAMESPACE
  21457. namespace MidiFileHelpers
  21458. {
  21459. static void writeVariableLengthInt (OutputStream& out, unsigned int v)
  21460. {
  21461. unsigned int buffer = v & 0x7F;
  21462. while ((v >>= 7) != 0)
  21463. {
  21464. buffer <<= 8;
  21465. buffer |= ((v & 0x7F) | 0x80);
  21466. }
  21467. for (;;)
  21468. {
  21469. out.writeByte ((char) buffer);
  21470. if (buffer & 0x80)
  21471. buffer >>= 8;
  21472. else
  21473. break;
  21474. }
  21475. }
  21476. static bool parseMidiHeader (const char* &data, short& timeFormat, short& fileType, short& numberOfTracks) throw()
  21477. {
  21478. unsigned int ch = (int) ByteOrder::bigEndianInt (data);
  21479. data += 4;
  21480. if (ch != ByteOrder::bigEndianInt ("MThd"))
  21481. {
  21482. bool ok = false;
  21483. if (ch == ByteOrder::bigEndianInt ("RIFF"))
  21484. {
  21485. for (int i = 0; i < 8; ++i)
  21486. {
  21487. ch = ByteOrder::bigEndianInt (data);
  21488. data += 4;
  21489. if (ch == ByteOrder::bigEndianInt ("MThd"))
  21490. {
  21491. ok = true;
  21492. break;
  21493. }
  21494. }
  21495. }
  21496. if (! ok)
  21497. return false;
  21498. }
  21499. unsigned int bytesRemaining = ByteOrder::bigEndianInt (data);
  21500. data += 4;
  21501. fileType = (short) ByteOrder::bigEndianShort (data);
  21502. data += 2;
  21503. numberOfTracks = (short) ByteOrder::bigEndianShort (data);
  21504. data += 2;
  21505. timeFormat = (short) ByteOrder::bigEndianShort (data);
  21506. data += 2;
  21507. bytesRemaining -= 6;
  21508. data += bytesRemaining;
  21509. return true;
  21510. }
  21511. static double convertTicksToSeconds (const double time,
  21512. const MidiMessageSequence& tempoEvents,
  21513. const int timeFormat)
  21514. {
  21515. if (timeFormat > 0)
  21516. {
  21517. int numer = 4, denom = 4;
  21518. double tempoTime = 0.0, correctedTempoTime = 0.0;
  21519. const double tickLen = 1.0 / (timeFormat & 0x7fff);
  21520. double secsPerTick = 0.5 * tickLen;
  21521. const int numEvents = tempoEvents.getNumEvents();
  21522. for (int i = 0; i < numEvents; ++i)
  21523. {
  21524. const MidiMessage& m = tempoEvents.getEventPointer(i)->message;
  21525. if (time <= m.getTimeStamp())
  21526. break;
  21527. if (timeFormat > 0)
  21528. {
  21529. correctedTempoTime = correctedTempoTime
  21530. + (m.getTimeStamp() - tempoTime) * secsPerTick;
  21531. }
  21532. else
  21533. {
  21534. correctedTempoTime = tickLen * m.getTimeStamp() / (((timeFormat & 0x7fff) >> 8) * (timeFormat & 0xff));
  21535. }
  21536. tempoTime = m.getTimeStamp();
  21537. if (m.isTempoMetaEvent())
  21538. secsPerTick = tickLen * m.getTempoSecondsPerQuarterNote();
  21539. else if (m.isTimeSignatureMetaEvent())
  21540. m.getTimeSignatureInfo (numer, denom);
  21541. while (i + 1 < numEvents)
  21542. {
  21543. const MidiMessage& m2 = tempoEvents.getEventPointer(i + 1)->message;
  21544. if (m2.getTimeStamp() == tempoTime)
  21545. {
  21546. ++i;
  21547. if (m2.isTempoMetaEvent())
  21548. secsPerTick = tickLen * m2.getTempoSecondsPerQuarterNote();
  21549. else if (m2.isTimeSignatureMetaEvent())
  21550. m2.getTimeSignatureInfo (numer, denom);
  21551. }
  21552. else
  21553. {
  21554. break;
  21555. }
  21556. }
  21557. }
  21558. return correctedTempoTime + (time - tempoTime) * secsPerTick;
  21559. }
  21560. else
  21561. {
  21562. return time / (((timeFormat & 0x7fff) >> 8) * (timeFormat & 0xff));
  21563. }
  21564. }
  21565. }
  21566. MidiFile::MidiFile() throw()
  21567. : timeFormat ((short) (unsigned short) 0xe728)
  21568. {
  21569. }
  21570. MidiFile::~MidiFile() throw()
  21571. {
  21572. clear();
  21573. }
  21574. void MidiFile::clear() throw()
  21575. {
  21576. tracks.clear();
  21577. }
  21578. int MidiFile::getNumTracks() const throw()
  21579. {
  21580. return tracks.size();
  21581. }
  21582. const MidiMessageSequence* MidiFile::getTrack (const int index) const throw()
  21583. {
  21584. return tracks [index];
  21585. }
  21586. void MidiFile::addTrack (const MidiMessageSequence& trackSequence) throw()
  21587. {
  21588. tracks.add (new MidiMessageSequence (trackSequence));
  21589. }
  21590. short MidiFile::getTimeFormat() const throw()
  21591. {
  21592. return timeFormat;
  21593. }
  21594. void MidiFile::setTicksPerQuarterNote (const int ticks) throw()
  21595. {
  21596. timeFormat = (short)ticks;
  21597. }
  21598. void MidiFile::setSmpteTimeFormat (const int framesPerSecond,
  21599. const int subframeResolution) throw()
  21600. {
  21601. timeFormat = (short) (((-framesPerSecond) << 8) | subframeResolution);
  21602. }
  21603. void MidiFile::findAllTempoEvents (MidiMessageSequence& tempoChangeEvents) const
  21604. {
  21605. for (int i = tracks.size(); --i >= 0;)
  21606. {
  21607. const int numEvents = tracks.getUnchecked(i)->getNumEvents();
  21608. for (int j = 0; j < numEvents; ++j)
  21609. {
  21610. const MidiMessage& m = tracks.getUnchecked(i)->getEventPointer (j)->message;
  21611. if (m.isTempoMetaEvent())
  21612. tempoChangeEvents.addEvent (m);
  21613. }
  21614. }
  21615. }
  21616. void MidiFile::findAllTimeSigEvents (MidiMessageSequence& timeSigEvents) const
  21617. {
  21618. for (int i = tracks.size(); --i >= 0;)
  21619. {
  21620. const int numEvents = tracks.getUnchecked(i)->getNumEvents();
  21621. for (int j = 0; j < numEvents; ++j)
  21622. {
  21623. const MidiMessage& m = tracks.getUnchecked(i)->getEventPointer (j)->message;
  21624. if (m.isTimeSignatureMetaEvent())
  21625. timeSigEvents.addEvent (m);
  21626. }
  21627. }
  21628. }
  21629. double MidiFile::getLastTimestamp() const
  21630. {
  21631. double t = 0.0;
  21632. for (int i = tracks.size(); --i >= 0;)
  21633. t = jmax (t, tracks.getUnchecked(i)->getEndTime());
  21634. return t;
  21635. }
  21636. bool MidiFile::readFrom (InputStream& sourceStream)
  21637. {
  21638. clear();
  21639. MemoryBlock data;
  21640. const int maxSensibleMidiFileSize = 2 * 1024 * 1024;
  21641. // (put a sanity-check on the file size, as midi files are generally small)
  21642. if (sourceStream.readIntoMemoryBlock (data, maxSensibleMidiFileSize))
  21643. {
  21644. size_t size = data.getSize();
  21645. const char* d = (char*) data.getData();
  21646. short fileType, expectedTracks;
  21647. if (size > 16 && MidiFileHelpers::parseMidiHeader (d, timeFormat, fileType, expectedTracks))
  21648. {
  21649. size -= (int) (d - (char*) data.getData());
  21650. int track = 0;
  21651. while (size > 0 && track < expectedTracks)
  21652. {
  21653. const int chunkType = (int) ByteOrder::bigEndianInt (d);
  21654. d += 4;
  21655. const int chunkSize = (int) ByteOrder::bigEndianInt (d);
  21656. d += 4;
  21657. if (chunkSize <= 0)
  21658. break;
  21659. if (size < 0)
  21660. return false;
  21661. if (chunkType == (int) ByteOrder::bigEndianInt ("MTrk"))
  21662. {
  21663. readNextTrack (d, chunkSize);
  21664. }
  21665. size -= chunkSize + 8;
  21666. d += chunkSize;
  21667. ++track;
  21668. }
  21669. return true;
  21670. }
  21671. }
  21672. return false;
  21673. }
  21674. // a comparator that puts all the note-offs before note-ons that have the same time
  21675. int MidiFile::compareElements (const MidiMessageSequence::MidiEventHolder* const first,
  21676. const MidiMessageSequence::MidiEventHolder* const second) throw()
  21677. {
  21678. const double diff = (first->message.getTimeStamp() - second->message.getTimeStamp());
  21679. if (diff == 0)
  21680. {
  21681. if (first->message.isNoteOff() && second->message.isNoteOn())
  21682. return -1;
  21683. else if (first->message.isNoteOn() && second->message.isNoteOff())
  21684. return 1;
  21685. else
  21686. return 0;
  21687. }
  21688. else
  21689. {
  21690. return (diff > 0) ? 1 : -1;
  21691. }
  21692. }
  21693. void MidiFile::readNextTrack (const char* data, int size)
  21694. {
  21695. double time = 0;
  21696. char lastStatusByte = 0;
  21697. MidiMessageSequence result;
  21698. while (size > 0)
  21699. {
  21700. int bytesUsed;
  21701. const int delay = MidiMessage::readVariableLengthVal ((const uint8*) data, bytesUsed);
  21702. data += bytesUsed;
  21703. size -= bytesUsed;
  21704. time += delay;
  21705. int messSize = 0;
  21706. const MidiMessage mm ((const uint8*) data, size, messSize, lastStatusByte, time);
  21707. if (messSize <= 0)
  21708. break;
  21709. size -= messSize;
  21710. data += messSize;
  21711. result.addEvent (mm);
  21712. const char firstByte = *(mm.getRawData());
  21713. if ((firstByte & 0xf0) != 0xf0)
  21714. lastStatusByte = firstByte;
  21715. }
  21716. // use a sort that puts all the note-offs before note-ons that have the same time
  21717. result.list.sort (*this, true);
  21718. result.updateMatchedPairs();
  21719. addTrack (result);
  21720. }
  21721. void MidiFile::convertTimestampTicksToSeconds()
  21722. {
  21723. MidiMessageSequence tempoEvents;
  21724. findAllTempoEvents (tempoEvents);
  21725. findAllTimeSigEvents (tempoEvents);
  21726. for (int i = 0; i < tracks.size(); ++i)
  21727. {
  21728. MidiMessageSequence& ms = *tracks.getUnchecked(i);
  21729. for (int j = ms.getNumEvents(); --j >= 0;)
  21730. {
  21731. MidiMessage& m = ms.getEventPointer(j)->message;
  21732. m.setTimeStamp (MidiFileHelpers::convertTicksToSeconds (m.getTimeStamp(),
  21733. tempoEvents,
  21734. timeFormat));
  21735. }
  21736. }
  21737. }
  21738. bool MidiFile::writeTo (OutputStream& out)
  21739. {
  21740. out.writeIntBigEndian ((int) ByteOrder::bigEndianInt ("MThd"));
  21741. out.writeIntBigEndian (6);
  21742. out.writeShortBigEndian (1); // type
  21743. out.writeShortBigEndian ((short) tracks.size());
  21744. out.writeShortBigEndian (timeFormat);
  21745. for (int i = 0; i < tracks.size(); ++i)
  21746. writeTrack (out, i);
  21747. out.flush();
  21748. return true;
  21749. }
  21750. void MidiFile::writeTrack (OutputStream& mainOut,
  21751. const int trackNum)
  21752. {
  21753. MemoryOutputStream out;
  21754. const MidiMessageSequence& ms = *tracks[trackNum];
  21755. int lastTick = 0;
  21756. char lastStatusByte = 0;
  21757. for (int i = 0; i < ms.getNumEvents(); ++i)
  21758. {
  21759. const MidiMessage& mm = ms.getEventPointer(i)->message;
  21760. const int tick = roundToInt (mm.getTimeStamp());
  21761. const int delta = jmax (0, tick - lastTick);
  21762. MidiFileHelpers::writeVariableLengthInt (out, delta);
  21763. lastTick = tick;
  21764. const char statusByte = *(mm.getRawData());
  21765. if ((statusByte == lastStatusByte)
  21766. && ((statusByte & 0xf0) != 0xf0)
  21767. && i > 0
  21768. && mm.getRawDataSize() > 1)
  21769. {
  21770. out.write (mm.getRawData() + 1, mm.getRawDataSize() - 1);
  21771. }
  21772. else
  21773. {
  21774. out.write (mm.getRawData(), mm.getRawDataSize());
  21775. }
  21776. lastStatusByte = statusByte;
  21777. }
  21778. out.writeByte (0);
  21779. const MidiMessage m (MidiMessage::endOfTrack());
  21780. out.write (m.getRawData(),
  21781. m.getRawDataSize());
  21782. mainOut.writeIntBigEndian ((int) ByteOrder::bigEndianInt ("MTrk"));
  21783. mainOut.writeIntBigEndian ((int) out.getDataSize());
  21784. mainOut.write (out.getData(), (int) out.getDataSize());
  21785. }
  21786. END_JUCE_NAMESPACE
  21787. /*** End of inlined file: juce_MidiFile.cpp ***/
  21788. /*** Start of inlined file: juce_MidiKeyboardState.cpp ***/
  21789. BEGIN_JUCE_NAMESPACE
  21790. MidiKeyboardState::MidiKeyboardState()
  21791. {
  21792. zeromem (noteStates, sizeof (noteStates));
  21793. }
  21794. MidiKeyboardState::~MidiKeyboardState()
  21795. {
  21796. }
  21797. void MidiKeyboardState::reset()
  21798. {
  21799. const ScopedLock sl (lock);
  21800. zeromem (noteStates, sizeof (noteStates));
  21801. eventsToAdd.clear();
  21802. }
  21803. bool MidiKeyboardState::isNoteOn (const int midiChannel, const int n) const throw()
  21804. {
  21805. jassert (midiChannel >= 0 && midiChannel <= 16);
  21806. return ((unsigned int) n) < 128
  21807. && (noteStates[n] & (1 << (midiChannel - 1))) != 0;
  21808. }
  21809. bool MidiKeyboardState::isNoteOnForChannels (const int midiChannelMask, const int n) const throw()
  21810. {
  21811. return ((unsigned int) n) < 128
  21812. && (noteStates[n] & midiChannelMask) != 0;
  21813. }
  21814. void MidiKeyboardState::noteOn (const int midiChannel, const int midiNoteNumber, const float velocity)
  21815. {
  21816. jassert (midiChannel >= 0 && midiChannel <= 16);
  21817. jassert (((unsigned int) midiNoteNumber) < 128);
  21818. const ScopedLock sl (lock);
  21819. if (((unsigned int) midiNoteNumber) < 128)
  21820. {
  21821. const int timeNow = (int) Time::getMillisecondCounter();
  21822. eventsToAdd.addEvent (MidiMessage::noteOn (midiChannel, midiNoteNumber, velocity), timeNow);
  21823. eventsToAdd.clear (0, timeNow - 500);
  21824. noteOnInternal (midiChannel, midiNoteNumber, velocity);
  21825. }
  21826. }
  21827. void MidiKeyboardState::noteOnInternal (const int midiChannel, const int midiNoteNumber, const float velocity)
  21828. {
  21829. if (((unsigned int) midiNoteNumber) < 128)
  21830. {
  21831. noteStates [midiNoteNumber] |= (1 << (midiChannel - 1));
  21832. for (int i = listeners.size(); --i >= 0;)
  21833. ((MidiKeyboardStateListener*) listeners.getUnchecked(i))
  21834. ->handleNoteOn (this, midiChannel, midiNoteNumber, velocity);
  21835. }
  21836. }
  21837. void MidiKeyboardState::noteOff (const int midiChannel, const int midiNoteNumber)
  21838. {
  21839. const ScopedLock sl (lock);
  21840. if (isNoteOn (midiChannel, midiNoteNumber))
  21841. {
  21842. const int timeNow = (int) Time::getMillisecondCounter();
  21843. eventsToAdd.addEvent (MidiMessage::noteOff (midiChannel, midiNoteNumber), timeNow);
  21844. eventsToAdd.clear (0, timeNow - 500);
  21845. noteOffInternal (midiChannel, midiNoteNumber);
  21846. }
  21847. }
  21848. void MidiKeyboardState::noteOffInternal (const int midiChannel, const int midiNoteNumber)
  21849. {
  21850. if (isNoteOn (midiChannel, midiNoteNumber))
  21851. {
  21852. noteStates [midiNoteNumber] &= ~(1 << (midiChannel - 1));
  21853. for (int i = listeners.size(); --i >= 0;)
  21854. ((MidiKeyboardStateListener*) listeners.getUnchecked(i))
  21855. ->handleNoteOff (this, midiChannel, midiNoteNumber);
  21856. }
  21857. }
  21858. void MidiKeyboardState::allNotesOff (const int midiChannel)
  21859. {
  21860. const ScopedLock sl (lock);
  21861. if (midiChannel <= 0)
  21862. {
  21863. for (int i = 1; i <= 16; ++i)
  21864. allNotesOff (i);
  21865. }
  21866. else
  21867. {
  21868. for (int i = 0; i < 128; ++i)
  21869. noteOff (midiChannel, i);
  21870. }
  21871. }
  21872. void MidiKeyboardState::processNextMidiEvent (const MidiMessage& message)
  21873. {
  21874. if (message.isNoteOn())
  21875. {
  21876. noteOnInternal (message.getChannel(), message.getNoteNumber(), message.getFloatVelocity());
  21877. }
  21878. else if (message.isNoteOff())
  21879. {
  21880. noteOffInternal (message.getChannel(), message.getNoteNumber());
  21881. }
  21882. else if (message.isAllNotesOff())
  21883. {
  21884. for (int i = 0; i < 128; ++i)
  21885. noteOffInternal (message.getChannel(), i);
  21886. }
  21887. }
  21888. void MidiKeyboardState::processNextMidiBuffer (MidiBuffer& buffer,
  21889. const int startSample,
  21890. const int numSamples,
  21891. const bool injectIndirectEvents)
  21892. {
  21893. MidiBuffer::Iterator i (buffer);
  21894. MidiMessage message (0xf4, 0.0);
  21895. int time;
  21896. const ScopedLock sl (lock);
  21897. while (i.getNextEvent (message, time))
  21898. processNextMidiEvent (message);
  21899. if (injectIndirectEvents)
  21900. {
  21901. MidiBuffer::Iterator i2 (eventsToAdd);
  21902. const int firstEventToAdd = eventsToAdd.getFirstEventTime();
  21903. const double scaleFactor = numSamples / (double) (eventsToAdd.getLastEventTime() + 1 - firstEventToAdd);
  21904. while (i2.getNextEvent (message, time))
  21905. {
  21906. const int pos = jlimit (0, numSamples - 1, roundToInt ((time - firstEventToAdd) * scaleFactor));
  21907. buffer.addEvent (message, startSample + pos);
  21908. }
  21909. }
  21910. eventsToAdd.clear();
  21911. }
  21912. void MidiKeyboardState::addListener (MidiKeyboardStateListener* const listener) throw()
  21913. {
  21914. const ScopedLock sl (lock);
  21915. listeners.addIfNotAlreadyThere (listener);
  21916. }
  21917. void MidiKeyboardState::removeListener (MidiKeyboardStateListener* const listener) throw()
  21918. {
  21919. const ScopedLock sl (lock);
  21920. listeners.removeValue (listener);
  21921. }
  21922. END_JUCE_NAMESPACE
  21923. /*** End of inlined file: juce_MidiKeyboardState.cpp ***/
  21924. /*** Start of inlined file: juce_MidiMessage.cpp ***/
  21925. BEGIN_JUCE_NAMESPACE
  21926. int MidiMessage::readVariableLengthVal (const uint8* data,
  21927. int& numBytesUsed) throw()
  21928. {
  21929. numBytesUsed = 0;
  21930. int v = 0;
  21931. int i;
  21932. do
  21933. {
  21934. i = (int) *data++;
  21935. if (++numBytesUsed > 6)
  21936. break;
  21937. v = (v << 7) + (i & 0x7f);
  21938. } while (i & 0x80);
  21939. return v;
  21940. }
  21941. int MidiMessage::getMessageLengthFromFirstByte (const uint8 firstByte) throw()
  21942. {
  21943. // this method only works for valid starting bytes of a short midi message
  21944. jassert (firstByte >= 0x80
  21945. && firstByte != 0xf0
  21946. && firstByte != 0xf7);
  21947. static const char messageLengths[] =
  21948. {
  21949. 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
  21950. 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
  21951. 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
  21952. 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
  21953. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  21954. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  21955. 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
  21956. 1, 2, 3, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1
  21957. };
  21958. return messageLengths [firstByte & 0x7f];
  21959. }
  21960. MidiMessage::MidiMessage (const uint8* const d,
  21961. const int dataSize,
  21962. const double t) throw()
  21963. : timeStamp (t),
  21964. message (0),
  21965. size (dataSize)
  21966. {
  21967. jassert (dataSize > 0);
  21968. if (dataSize <= 4)
  21969. data = (uint8*) &message;
  21970. else
  21971. data = (uint8*) juce_malloc (dataSize);
  21972. memcpy (data, d, dataSize);
  21973. // check that the length matches the data..
  21974. jassert (size > 3 || *d >= 0xf0 || getMessageLengthFromFirstByte (*d) == size);
  21975. }
  21976. MidiMessage::MidiMessage (const int byte1,
  21977. const double t) throw()
  21978. : timeStamp (t),
  21979. data ((uint8*) &message),
  21980. size (1)
  21981. {
  21982. data[0] = (uint8) byte1;
  21983. // check that the length matches the data..
  21984. jassert (byte1 >= 0xf0 || getMessageLengthFromFirstByte ((uint8) byte1) == 1);
  21985. }
  21986. MidiMessage::MidiMessage (const int byte1,
  21987. const int byte2,
  21988. const double t) throw()
  21989. : timeStamp (t),
  21990. data ((uint8*) &message),
  21991. size (2)
  21992. {
  21993. data[0] = (uint8) byte1;
  21994. data[1] = (uint8) byte2;
  21995. // check that the length matches the data..
  21996. jassert (byte1 >= 0xf0 || getMessageLengthFromFirstByte ((uint8) byte1) == 2);
  21997. }
  21998. MidiMessage::MidiMessage (const int byte1,
  21999. const int byte2,
  22000. const int byte3,
  22001. const double t) throw()
  22002. : timeStamp (t),
  22003. data ((uint8*) &message),
  22004. size (3)
  22005. {
  22006. data[0] = (uint8) byte1;
  22007. data[1] = (uint8) byte2;
  22008. data[2] = (uint8) byte3;
  22009. // check that the length matches the data..
  22010. jassert (byte1 >= 0xf0 || getMessageLengthFromFirstByte ((uint8) byte1) == 3);
  22011. }
  22012. MidiMessage::MidiMessage (const MidiMessage& other) throw()
  22013. : timeStamp (other.timeStamp),
  22014. message (other.message),
  22015. size (other.size)
  22016. {
  22017. if (other.data != (uint8*) &other.message)
  22018. {
  22019. data = (uint8*) juce_malloc (size);
  22020. memcpy (data, other.data, size);
  22021. }
  22022. else
  22023. {
  22024. data = (uint8*) &message;
  22025. }
  22026. }
  22027. MidiMessage::MidiMessage (const MidiMessage& other,
  22028. const double newTimeStamp) throw()
  22029. : timeStamp (newTimeStamp),
  22030. message (other.message),
  22031. size (other.size)
  22032. {
  22033. if (other.data != (uint8*) &other.message)
  22034. {
  22035. data = (uint8*) juce_malloc (size);
  22036. memcpy (data, other.data, size);
  22037. }
  22038. else
  22039. {
  22040. data = (uint8*) &message;
  22041. }
  22042. }
  22043. MidiMessage::MidiMessage (const uint8* src,
  22044. int sz,
  22045. int& numBytesUsed,
  22046. const uint8 lastStatusByte,
  22047. double t) throw()
  22048. : timeStamp (t),
  22049. data ((uint8*) &message),
  22050. message (0)
  22051. {
  22052. unsigned int byte = (unsigned int) *src;
  22053. if (byte < 0x80)
  22054. {
  22055. byte = (unsigned int) (uint8) lastStatusByte;
  22056. numBytesUsed = -1;
  22057. }
  22058. else
  22059. {
  22060. numBytesUsed = 0;
  22061. --sz;
  22062. ++src;
  22063. }
  22064. if (byte >= 0x80)
  22065. {
  22066. if (byte == 0xf0)
  22067. {
  22068. const uint8* d = (const uint8*) src;
  22069. while (d < src + sz)
  22070. {
  22071. if (*d >= 0x80) // stop if we hit a status byte, and don't include it in this message
  22072. {
  22073. if (*d == 0xf7) // include an 0xf7 if we hit one
  22074. ++d;
  22075. break;
  22076. }
  22077. ++d;
  22078. }
  22079. size = 1 + (int) (d - src);
  22080. data = (uint8*) juce_malloc (size);
  22081. *data = (uint8) byte;
  22082. memcpy (data + 1, src, size - 1);
  22083. }
  22084. else if (byte == 0xff)
  22085. {
  22086. int n;
  22087. const int bytesLeft = readVariableLengthVal (src + 1, n);
  22088. size = jmin (sz + 1, n + 2 + bytesLeft);
  22089. data = (uint8*) juce_malloc (size);
  22090. *data = (uint8) byte;
  22091. memcpy (data + 1, src, size - 1);
  22092. }
  22093. else
  22094. {
  22095. size = getMessageLengthFromFirstByte ((uint8) byte);
  22096. *data = (uint8) byte;
  22097. if (size > 1)
  22098. {
  22099. data[1] = src[0];
  22100. if (size > 2)
  22101. data[2] = src[1];
  22102. }
  22103. }
  22104. numBytesUsed += size;
  22105. }
  22106. else
  22107. {
  22108. message = 0;
  22109. size = 0;
  22110. }
  22111. }
  22112. MidiMessage& MidiMessage::operator= (const MidiMessage& other) throw()
  22113. {
  22114. if (this != &other)
  22115. {
  22116. timeStamp = other.timeStamp;
  22117. size = other.size;
  22118. message = other.message;
  22119. if (data != (uint8*) &message)
  22120. juce_free (data);
  22121. if (other.data != (uint8*) &other.message)
  22122. {
  22123. data = (uint8*) juce_malloc (size);
  22124. memcpy (data, other.data, size);
  22125. }
  22126. else
  22127. {
  22128. data = (uint8*) &message;
  22129. }
  22130. }
  22131. return *this;
  22132. }
  22133. MidiMessage::~MidiMessage() throw()
  22134. {
  22135. if (data != (uint8*) &message)
  22136. juce_free (data);
  22137. }
  22138. int MidiMessage::getChannel() const throw()
  22139. {
  22140. if ((data[0] & 0xf0) != 0xf0)
  22141. return (data[0] & 0xf) + 1;
  22142. else
  22143. return 0;
  22144. }
  22145. bool MidiMessage::isForChannel (const int channel) const throw()
  22146. {
  22147. jassert (channel > 0 && channel <= 16); // valid channels are numbered 1 to 16
  22148. return ((data[0] & 0xf) == channel - 1)
  22149. && ((data[0] & 0xf0) != 0xf0);
  22150. }
  22151. void MidiMessage::setChannel (const int channel) throw()
  22152. {
  22153. jassert (channel > 0 && channel <= 16); // valid channels are numbered 1 to 16
  22154. if ((data[0] & 0xf0) != (uint8) 0xf0)
  22155. data[0] = (uint8) ((data[0] & (uint8)0xf0)
  22156. | (uint8)(channel - 1));
  22157. }
  22158. bool MidiMessage::isNoteOn (const bool returnTrueForVelocity0) const throw()
  22159. {
  22160. return ((data[0] & 0xf0) == 0x90)
  22161. && (returnTrueForVelocity0 || data[2] != 0);
  22162. }
  22163. bool MidiMessage::isNoteOff (const bool returnTrueForNoteOnVelocity0) const throw()
  22164. {
  22165. return ((data[0] & 0xf0) == 0x80)
  22166. || (returnTrueForNoteOnVelocity0 && (data[2] == 0) && ((data[0] & 0xf0) == 0x90));
  22167. }
  22168. bool MidiMessage::isNoteOnOrOff() const throw()
  22169. {
  22170. const int d = data[0] & 0xf0;
  22171. return (d == 0x90) || (d == 0x80);
  22172. }
  22173. int MidiMessage::getNoteNumber() const throw()
  22174. {
  22175. return data[1];
  22176. }
  22177. void MidiMessage::setNoteNumber (const int newNoteNumber) throw()
  22178. {
  22179. if (isNoteOnOrOff())
  22180. data[1] = (uint8) jlimit (0, 127, newNoteNumber);
  22181. }
  22182. uint8 MidiMessage::getVelocity() const throw()
  22183. {
  22184. if (isNoteOnOrOff())
  22185. return data[2];
  22186. else
  22187. return 0;
  22188. }
  22189. float MidiMessage::getFloatVelocity() const throw()
  22190. {
  22191. return getVelocity() * (1.0f / 127.0f);
  22192. }
  22193. void MidiMessage::setVelocity (const float newVelocity) throw()
  22194. {
  22195. if (isNoteOnOrOff())
  22196. data[2] = (uint8) jlimit (0, 0x7f, roundToInt (newVelocity * 127.0f));
  22197. }
  22198. void MidiMessage::multiplyVelocity (const float scaleFactor) throw()
  22199. {
  22200. if (isNoteOnOrOff())
  22201. data[2] = (uint8) jlimit (0, 0x7f, roundToInt (scaleFactor * data[2]));
  22202. }
  22203. bool MidiMessage::isAftertouch() const throw()
  22204. {
  22205. return (data[0] & 0xf0) == 0xa0;
  22206. }
  22207. int MidiMessage::getAfterTouchValue() const throw()
  22208. {
  22209. return data[2];
  22210. }
  22211. const MidiMessage MidiMessage::aftertouchChange (const int channel,
  22212. const int noteNum,
  22213. const int aftertouchValue) throw()
  22214. {
  22215. jassert (channel > 0 && channel <= 16); // valid channels are numbered 1 to 16
  22216. jassert (((unsigned int) noteNum) <= 127);
  22217. jassert (((unsigned int) aftertouchValue) <= 127);
  22218. return MidiMessage (0xa0 | jlimit (0, 15, channel - 1),
  22219. noteNum & 0x7f,
  22220. aftertouchValue & 0x7f);
  22221. }
  22222. bool MidiMessage::isChannelPressure() const throw()
  22223. {
  22224. return (data[0] & 0xf0) == 0xd0;
  22225. }
  22226. int MidiMessage::getChannelPressureValue() const throw()
  22227. {
  22228. jassert (isChannelPressure());
  22229. return data[1];
  22230. }
  22231. const MidiMessage MidiMessage::channelPressureChange (const int channel,
  22232. const int pressure) throw()
  22233. {
  22234. jassert (channel > 0 && channel <= 16); // valid channels are numbered 1 to 16
  22235. jassert (((unsigned int) pressure) <= 127);
  22236. return MidiMessage (0xd0 | jlimit (0, 15, channel - 1),
  22237. pressure & 0x7f);
  22238. }
  22239. bool MidiMessage::isProgramChange() const throw()
  22240. {
  22241. return (data[0] & 0xf0) == 0xc0;
  22242. }
  22243. int MidiMessage::getProgramChangeNumber() const throw()
  22244. {
  22245. return data[1];
  22246. }
  22247. const MidiMessage MidiMessage::programChange (const int channel,
  22248. const int programNumber) throw()
  22249. {
  22250. jassert (channel > 0 && channel <= 16); // valid channels are numbered 1 to 16
  22251. return MidiMessage (0xc0 | jlimit (0, 15, channel - 1),
  22252. programNumber & 0x7f);
  22253. }
  22254. bool MidiMessage::isPitchWheel() const throw()
  22255. {
  22256. return (data[0] & 0xf0) == 0xe0;
  22257. }
  22258. int MidiMessage::getPitchWheelValue() const throw()
  22259. {
  22260. return data[1] | (data[2] << 7);
  22261. }
  22262. const MidiMessage MidiMessage::pitchWheel (const int channel,
  22263. const int position) throw()
  22264. {
  22265. jassert (channel > 0 && channel <= 16); // valid channels are numbered 1 to 16
  22266. jassert (((unsigned int) position) <= 0x3fff);
  22267. return MidiMessage (0xe0 | jlimit (0, 15, channel - 1),
  22268. position & 127,
  22269. (position >> 7) & 127);
  22270. }
  22271. bool MidiMessage::isController() const throw()
  22272. {
  22273. return (data[0] & 0xf0) == 0xb0;
  22274. }
  22275. int MidiMessage::getControllerNumber() const throw()
  22276. {
  22277. jassert (isController());
  22278. return data[1];
  22279. }
  22280. int MidiMessage::getControllerValue() const throw()
  22281. {
  22282. jassert (isController());
  22283. return data[2];
  22284. }
  22285. const MidiMessage MidiMessage::controllerEvent (const int channel,
  22286. const int controllerType,
  22287. const int value) throw()
  22288. {
  22289. // the channel must be between 1 and 16 inclusive
  22290. jassert (channel > 0 && channel <= 16);
  22291. return MidiMessage (0xb0 | jlimit (0, 15, channel - 1),
  22292. controllerType & 127,
  22293. value & 127);
  22294. }
  22295. const MidiMessage MidiMessage::noteOn (const int channel,
  22296. const int noteNumber,
  22297. const float velocity) throw()
  22298. {
  22299. return noteOn (channel, noteNumber, (uint8)(velocity * 127.0f));
  22300. }
  22301. const MidiMessage MidiMessage::noteOn (const int channel,
  22302. const int noteNumber,
  22303. const uint8 velocity) throw()
  22304. {
  22305. jassert (channel > 0 && channel <= 16);
  22306. jassert (((unsigned int) noteNumber) <= 127);
  22307. return MidiMessage (0x90 | jlimit (0, 15, channel - 1),
  22308. noteNumber & 127,
  22309. jlimit (0, 127, roundToInt (velocity)));
  22310. }
  22311. const MidiMessage MidiMessage::noteOff (const int channel,
  22312. const int noteNumber) throw()
  22313. {
  22314. jassert (channel > 0 && channel <= 16);
  22315. jassert (((unsigned int) noteNumber) <= 127);
  22316. return MidiMessage (0x80 | jlimit (0, 15, channel - 1), noteNumber & 127, 0);
  22317. }
  22318. const MidiMessage MidiMessage::allNotesOff (const int channel) throw()
  22319. {
  22320. jassert (channel > 0 && channel <= 16);
  22321. return controllerEvent (channel, 123, 0);
  22322. }
  22323. bool MidiMessage::isAllNotesOff() const throw()
  22324. {
  22325. return (data[0] & 0xf0) == 0xb0
  22326. && data[1] == 123;
  22327. }
  22328. const MidiMessage MidiMessage::allSoundOff (const int channel) throw()
  22329. {
  22330. return controllerEvent (channel, 120, 0);
  22331. }
  22332. bool MidiMessage::isAllSoundOff() const throw()
  22333. {
  22334. return (data[0] & 0xf0) == 0xb0
  22335. && data[1] == 120;
  22336. }
  22337. const MidiMessage MidiMessage::allControllersOff (const int channel) throw()
  22338. {
  22339. return controllerEvent (channel, 121, 0);
  22340. }
  22341. const MidiMessage MidiMessage::masterVolume (const float volume) throw()
  22342. {
  22343. const int vol = jlimit (0, 0x3fff, roundToInt (volume * 0x4000));
  22344. uint8 buf[8];
  22345. buf[0] = 0xf0;
  22346. buf[1] = 0x7f;
  22347. buf[2] = 0x7f;
  22348. buf[3] = 0x04;
  22349. buf[4] = 0x01;
  22350. buf[5] = (uint8) (vol & 0x7f);
  22351. buf[6] = (uint8) (vol >> 7);
  22352. buf[7] = 0xf7;
  22353. return MidiMessage (buf, 8);
  22354. }
  22355. bool MidiMessage::isSysEx() const throw()
  22356. {
  22357. return *data == 0xf0;
  22358. }
  22359. const MidiMessage MidiMessage::createSysExMessage (const uint8* sysexData,
  22360. const int dataSize) throw()
  22361. {
  22362. MemoryBlock mm (dataSize + 2);
  22363. uint8* const m = (uint8*) mm.getData();
  22364. m[0] = 0xf0;
  22365. memcpy (m + 1, sysexData, dataSize);
  22366. m[dataSize + 1] = 0xf7;
  22367. return MidiMessage (m, dataSize + 2);
  22368. }
  22369. const uint8* MidiMessage::getSysExData() const throw()
  22370. {
  22371. return (isSysEx()) ? getRawData() + 1
  22372. : 0;
  22373. }
  22374. int MidiMessage::getSysExDataSize() const throw()
  22375. {
  22376. return (isSysEx()) ? size - 2
  22377. : 0;
  22378. }
  22379. bool MidiMessage::isMetaEvent() const throw()
  22380. {
  22381. return *data == 0xff;
  22382. }
  22383. bool MidiMessage::isActiveSense() const throw()
  22384. {
  22385. return *data == 0xfe;
  22386. }
  22387. int MidiMessage::getMetaEventType() const throw()
  22388. {
  22389. if (*data != 0xff)
  22390. return -1;
  22391. else
  22392. return data[1];
  22393. }
  22394. int MidiMessage::getMetaEventLength() const throw()
  22395. {
  22396. if (*data == 0xff)
  22397. {
  22398. int n;
  22399. return jmin (size - 2, readVariableLengthVal (data + 2, n));
  22400. }
  22401. return 0;
  22402. }
  22403. const uint8* MidiMessage::getMetaEventData() const throw()
  22404. {
  22405. int n;
  22406. const uint8* d = data + 2;
  22407. readVariableLengthVal (d, n);
  22408. return d + n;
  22409. }
  22410. bool MidiMessage::isTrackMetaEvent() const throw()
  22411. {
  22412. return getMetaEventType() == 0;
  22413. }
  22414. bool MidiMessage::isEndOfTrackMetaEvent() const throw()
  22415. {
  22416. return getMetaEventType() == 47;
  22417. }
  22418. bool MidiMessage::isTextMetaEvent() const throw()
  22419. {
  22420. const int t = getMetaEventType();
  22421. return t > 0 && t < 16;
  22422. }
  22423. const String MidiMessage::getTextFromTextMetaEvent() const throw()
  22424. {
  22425. return String ((const char*) getMetaEventData(),
  22426. getMetaEventLength());
  22427. }
  22428. bool MidiMessage::isTrackNameEvent() const throw()
  22429. {
  22430. return (data[1] == 3)
  22431. && (*data == 0xff);
  22432. }
  22433. bool MidiMessage::isTempoMetaEvent() const throw()
  22434. {
  22435. return (data[1] == 81)
  22436. && (*data == 0xff);
  22437. }
  22438. bool MidiMessage::isMidiChannelMetaEvent() const throw()
  22439. {
  22440. return (data[1] == 0x20)
  22441. && (*data == 0xff)
  22442. && (data[2] == 1);
  22443. }
  22444. int MidiMessage::getMidiChannelMetaEventChannel() const throw()
  22445. {
  22446. return data[3] + 1;
  22447. }
  22448. double MidiMessage::getTempoSecondsPerQuarterNote() const throw()
  22449. {
  22450. if (! isTempoMetaEvent())
  22451. return 0.0;
  22452. const uint8* const d = getMetaEventData();
  22453. return (((unsigned int) d[0] << 16)
  22454. | ((unsigned int) d[1] << 8)
  22455. | d[2])
  22456. / 1000000.0;
  22457. }
  22458. double MidiMessage::getTempoMetaEventTickLength (const short timeFormat) const throw()
  22459. {
  22460. if (timeFormat > 0)
  22461. {
  22462. if (! isTempoMetaEvent())
  22463. return 0.5 / timeFormat;
  22464. return getTempoSecondsPerQuarterNote() / timeFormat;
  22465. }
  22466. else
  22467. {
  22468. const int frameCode = (-timeFormat) >> 8;
  22469. double framesPerSecond;
  22470. switch (frameCode)
  22471. {
  22472. case 24: framesPerSecond = 24.0; break;
  22473. case 25: framesPerSecond = 25.0; break;
  22474. case 29: framesPerSecond = 29.97; break;
  22475. case 30: framesPerSecond = 30.0; break;
  22476. default: framesPerSecond = 30.0; break;
  22477. }
  22478. return (1.0 / framesPerSecond) / (timeFormat & 0xff);
  22479. }
  22480. }
  22481. const MidiMessage MidiMessage::tempoMetaEvent (int microsecondsPerQuarterNote) throw()
  22482. {
  22483. uint8 d[8];
  22484. d[0] = 0xff;
  22485. d[1] = 81;
  22486. d[2] = 3;
  22487. d[3] = (uint8) (microsecondsPerQuarterNote >> 16);
  22488. d[4] = (uint8) ((microsecondsPerQuarterNote >> 8) & 0xff);
  22489. d[5] = (uint8) (microsecondsPerQuarterNote & 0xff);
  22490. return MidiMessage (d, 6, 0.0);
  22491. }
  22492. bool MidiMessage::isTimeSignatureMetaEvent() const throw()
  22493. {
  22494. return (data[1] == 0x58)
  22495. && (*data == (uint8) 0xff);
  22496. }
  22497. void MidiMessage::getTimeSignatureInfo (int& numerator,
  22498. int& denominator) const throw()
  22499. {
  22500. if (isTimeSignatureMetaEvent())
  22501. {
  22502. const uint8* const d = getMetaEventData();
  22503. numerator = d[0];
  22504. denominator = 1 << d[1];
  22505. }
  22506. else
  22507. {
  22508. numerator = 4;
  22509. denominator = 4;
  22510. }
  22511. }
  22512. const MidiMessage MidiMessage::timeSignatureMetaEvent (const int numerator,
  22513. const int denominator) throw()
  22514. {
  22515. uint8 d[8];
  22516. d[0] = 0xff;
  22517. d[1] = 0x58;
  22518. d[2] = 0x04;
  22519. d[3] = (uint8) numerator;
  22520. int n = 1;
  22521. int powerOfTwo = 0;
  22522. while (n < denominator)
  22523. {
  22524. n <<= 1;
  22525. ++powerOfTwo;
  22526. }
  22527. d[4] = (uint8) powerOfTwo;
  22528. d[5] = 0x01;
  22529. d[6] = 96;
  22530. return MidiMessage (d, 7, 0.0);
  22531. }
  22532. const MidiMessage MidiMessage::midiChannelMetaEvent (const int channel) throw()
  22533. {
  22534. uint8 d[8];
  22535. d[0] = 0xff;
  22536. d[1] = 0x20;
  22537. d[2] = 0x01;
  22538. d[3] = (uint8) jlimit (0, 0xff, channel - 1);
  22539. return MidiMessage (d, 4, 0.0);
  22540. }
  22541. bool MidiMessage::isKeySignatureMetaEvent() const throw()
  22542. {
  22543. return getMetaEventType() == 89;
  22544. }
  22545. int MidiMessage::getKeySignatureNumberOfSharpsOrFlats() const throw()
  22546. {
  22547. return (int) *getMetaEventData();
  22548. }
  22549. const MidiMessage MidiMessage::endOfTrack() throw()
  22550. {
  22551. return MidiMessage (0xff, 0x2f, 0, 0.0);
  22552. }
  22553. bool MidiMessage::isSongPositionPointer() const throw()
  22554. {
  22555. return *data == 0xf2;
  22556. }
  22557. int MidiMessage::getSongPositionPointerMidiBeat() const throw()
  22558. {
  22559. return data[1] | (data[2] << 7);
  22560. }
  22561. const MidiMessage MidiMessage::songPositionPointer (const int positionInMidiBeats) throw()
  22562. {
  22563. return MidiMessage (0xf2,
  22564. positionInMidiBeats & 127,
  22565. (positionInMidiBeats >> 7) & 127);
  22566. }
  22567. bool MidiMessage::isMidiStart() const throw()
  22568. {
  22569. return *data == 0xfa;
  22570. }
  22571. const MidiMessage MidiMessage::midiStart() throw()
  22572. {
  22573. return MidiMessage (0xfa);
  22574. }
  22575. bool MidiMessage::isMidiContinue() const throw()
  22576. {
  22577. return *data == 0xfb;
  22578. }
  22579. const MidiMessage MidiMessage::midiContinue() throw()
  22580. {
  22581. return MidiMessage (0xfb);
  22582. }
  22583. bool MidiMessage::isMidiStop() const throw()
  22584. {
  22585. return *data == 0xfc;
  22586. }
  22587. const MidiMessage MidiMessage::midiStop() throw()
  22588. {
  22589. return MidiMessage (0xfc);
  22590. }
  22591. bool MidiMessage::isMidiClock() const throw()
  22592. {
  22593. return *data == 0xf8;
  22594. }
  22595. const MidiMessage MidiMessage::midiClock() throw()
  22596. {
  22597. return MidiMessage (0xf8);
  22598. }
  22599. bool MidiMessage::isQuarterFrame() const throw()
  22600. {
  22601. return *data == 0xf1;
  22602. }
  22603. int MidiMessage::getQuarterFrameSequenceNumber() const throw()
  22604. {
  22605. return ((int) data[1]) >> 4;
  22606. }
  22607. int MidiMessage::getQuarterFrameValue() const throw()
  22608. {
  22609. return ((int) data[1]) & 0x0f;
  22610. }
  22611. const MidiMessage MidiMessage::quarterFrame (const int sequenceNumber,
  22612. const int value) throw()
  22613. {
  22614. return MidiMessage (0xf1, (sequenceNumber << 4) | value);
  22615. }
  22616. bool MidiMessage::isFullFrame() const throw()
  22617. {
  22618. return data[0] == 0xf0
  22619. && data[1] == 0x7f
  22620. && size >= 10
  22621. && data[3] == 0x01
  22622. && data[4] == 0x01;
  22623. }
  22624. void MidiMessage::getFullFrameParameters (int& hours,
  22625. int& minutes,
  22626. int& seconds,
  22627. int& frames,
  22628. MidiMessage::SmpteTimecodeType& timecodeType) const throw()
  22629. {
  22630. jassert (isFullFrame());
  22631. timecodeType = (SmpteTimecodeType) (data[5] >> 5);
  22632. hours = data[5] & 0x1f;
  22633. minutes = data[6];
  22634. seconds = data[7];
  22635. frames = data[8];
  22636. }
  22637. const MidiMessage MidiMessage::fullFrame (const int hours,
  22638. const int minutes,
  22639. const int seconds,
  22640. const int frames,
  22641. MidiMessage::SmpteTimecodeType timecodeType)
  22642. {
  22643. uint8 d[10];
  22644. d[0] = 0xf0;
  22645. d[1] = 0x7f;
  22646. d[2] = 0x7f;
  22647. d[3] = 0x01;
  22648. d[4] = 0x01;
  22649. d[5] = (uint8) ((hours & 0x01f) | (timecodeType << 5));
  22650. d[6] = (uint8) minutes;
  22651. d[7] = (uint8) seconds;
  22652. d[8] = (uint8) frames;
  22653. d[9] = 0xf7;
  22654. return MidiMessage (d, 10, 0.0);
  22655. }
  22656. bool MidiMessage::isMidiMachineControlMessage() const throw()
  22657. {
  22658. return data[0] == 0xf0
  22659. && data[1] == 0x7f
  22660. && data[3] == 0x06
  22661. && size > 5;
  22662. }
  22663. MidiMessage::MidiMachineControlCommand MidiMessage::getMidiMachineControlCommand() const throw()
  22664. {
  22665. jassert (isMidiMachineControlMessage());
  22666. return (MidiMachineControlCommand) data[4];
  22667. }
  22668. const MidiMessage MidiMessage::midiMachineControlCommand (MidiMessage::MidiMachineControlCommand command)
  22669. {
  22670. uint8 d[6];
  22671. d[0] = 0xf0;
  22672. d[1] = 0x7f;
  22673. d[2] = 0x00;
  22674. d[3] = 0x06;
  22675. d[4] = (uint8) command;
  22676. d[5] = 0xf7;
  22677. return MidiMessage (d, 6, 0.0);
  22678. }
  22679. bool MidiMessage::isMidiMachineControlGoto (int& hours,
  22680. int& minutes,
  22681. int& seconds,
  22682. int& frames) const throw()
  22683. {
  22684. if (size >= 12
  22685. && data[0] == 0xf0
  22686. && data[1] == 0x7f
  22687. && data[3] == 0x06
  22688. && data[4] == 0x44
  22689. && data[5] == 0x06
  22690. && data[6] == 0x01)
  22691. {
  22692. hours = data[7] % 24; // (that some machines send out hours > 24)
  22693. minutes = data[8];
  22694. seconds = data[9];
  22695. frames = data[10];
  22696. return true;
  22697. }
  22698. return false;
  22699. }
  22700. const MidiMessage MidiMessage::midiMachineControlGoto (int hours,
  22701. int minutes,
  22702. int seconds,
  22703. int frames)
  22704. {
  22705. uint8 d[12];
  22706. d[0] = 0xf0;
  22707. d[1] = 0x7f;
  22708. d[2] = 0x00;
  22709. d[3] = 0x06;
  22710. d[4] = 0x44;
  22711. d[5] = 0x06;
  22712. d[6] = 0x01;
  22713. d[7] = (uint8) hours;
  22714. d[8] = (uint8) minutes;
  22715. d[9] = (uint8) seconds;
  22716. d[10] = (uint8) frames;
  22717. d[11] = 0xf7;
  22718. return MidiMessage (d, 12, 0.0);
  22719. }
  22720. const String MidiMessage::getMidiNoteName (int note,
  22721. bool useSharps,
  22722. bool includeOctaveNumber,
  22723. int octaveNumForMiddleC) throw()
  22724. {
  22725. static const char* const sharpNoteNames[] = { "C", "C#", "D", "D#", "E",
  22726. "F", "F#", "G", "G#", "A",
  22727. "A#", "B" };
  22728. static const char* const flatNoteNames[] = { "C", "Db", "D", "Eb", "E",
  22729. "F", "Gb", "G", "Ab", "A",
  22730. "Bb", "B" };
  22731. if (((unsigned int) note) < 128)
  22732. {
  22733. const String s ((useSharps) ? sharpNoteNames [note % 12]
  22734. : flatNoteNames [note % 12]);
  22735. if (includeOctaveNumber)
  22736. return s + String (note / 12 + (octaveNumForMiddleC - 5));
  22737. else
  22738. return s;
  22739. }
  22740. return String::empty;
  22741. }
  22742. const double MidiMessage::getMidiNoteInHertz (int noteNumber) throw()
  22743. {
  22744. noteNumber -= 12 * 6 + 9; // now 0 = A440
  22745. return 440.0 * pow (2.0, noteNumber / 12.0);
  22746. }
  22747. const String MidiMessage::getGMInstrumentName (int n) throw()
  22748. {
  22749. const char *names[] =
  22750. {
  22751. "Acoustic Grand Piano", "Bright Acoustic Piano", "Electric Grand Piano", "Honky-tonk Piano",
  22752. "Electric Piano 1", "Electric Piano 2", "Harpsichord", "Clavinet", "Celesta", "Glockenspiel",
  22753. "Music Box", "Vibraphone", "Marimba", "Xylophone", "Tubular Bells", "Dulcimer", "Drawbar Organ",
  22754. "Percussive Organ", "Rock Organ", "Church Organ", "Reed Organ", "Accordion", "Harmonica",
  22755. "Tango Accordion", "Acoustic Guitar (nylon)", "Acoustic Guitar (steel)", "Electric Guitar (jazz)",
  22756. "Electric Guitar (clean)", "Electric Guitar (mute)", "Overdriven Guitar", "Distortion Guitar",
  22757. "Guitar Harmonics", "Acoustic Bass", "Electric Bass (finger)", "Electric Bass (pick)",
  22758. "Fretless Bass", "Slap Bass 1", "Slap Bass 2", "Synth Bass 1", "Synth Bass 2", "Violin",
  22759. "Viola", "Cello", "Contrabass", "Tremolo Strings", "Pizzicato Strings", "Orchestral Harp",
  22760. "Timpani", "String Ensemble 1", "String Ensemble 2", "SynthStrings 1", "SynthStrings 2",
  22761. "Choir Aahs", "Voice Oohs", "Synth Voice", "Orchestra Hit", "Trumpet", "Trombone", "Tuba",
  22762. "Muted Trumpet", "French Horn", "Brass Section", "SynthBrass 1", "SynthBrass 2", "Soprano Sax",
  22763. "Alto Sax", "Tenor Sax", "Baritone Sax", "Oboe", "English Horn", "Bassoon", "Clarinet",
  22764. "Piccolo", "Flute", "Recorder", "Pan Flute", "Blown Bottle", "Shakuhachi", "Whistle",
  22765. "Ocarina", "Lead 1 (square)", "Lead 2 (sawtooth)", "Lead 3 (calliope)", "Lead 4 (chiff)",
  22766. "Lead 5 (charang)", "Lead 6 (voice)", "Lead 7 (fifths)", "Lead 8 (bass+lead)", "Pad 1 (new age)",
  22767. "Pad 2 (warm)", "Pad 3 (polysynth)", "Pad 4 (choir)", "Pad 5 (bowed)", "Pad 6 (metallic)",
  22768. "Pad 7 (halo)", "Pad 8 (sweep)", "FX 1 (rain)", "FX 2 (soundtrack)", "FX 3 (crystal)",
  22769. "FX 4 (atmosphere)", "FX 5 (brightness)", "FX 6 (goblins)", "FX 7 (echoes)", "FX 8 (sci-fi)",
  22770. "Sitar", "Banjo", "Shamisen", "Koto", "Kalimba", "Bag pipe", "Fiddle", "Shanai", "Tinkle Bell",
  22771. "Agogo", "Steel Drums", "Woodblock", "Taiko Drum", "Melodic Tom", "Synth Drum", "Reverse Cymbal",
  22772. "Guitar Fret Noise", "Breath Noise", "Seashore", "Bird Tweet", "Telephone Ring", "Helicopter",
  22773. "Applause", "Gunshot"
  22774. };
  22775. return (((unsigned int) n) < 128) ? names[n]
  22776. : (const char*)0;
  22777. }
  22778. const String MidiMessage::getGMInstrumentBankName (int n) throw()
  22779. {
  22780. const char* names[] =
  22781. {
  22782. "Piano", "Chromatic Percussion", "Organ", "Guitar",
  22783. "Bass", "Strings", "Ensemble", "Brass",
  22784. "Reed", "Pipe", "Synth Lead", "Synth Pad",
  22785. "Synth Effects", "Ethnic", "Percussive", "Sound Effects"
  22786. };
  22787. return (((unsigned int) n) <= 15) ? names[n]
  22788. : (const char*)0;
  22789. }
  22790. const String MidiMessage::getRhythmInstrumentName (int n) throw()
  22791. {
  22792. const char* names[] =
  22793. {
  22794. "Acoustic Bass Drum", "Bass Drum 1", "Side Stick", "Acoustic Snare",
  22795. "Hand Clap", "Electric Snare", "Low Floor Tom", "Closed Hi-Hat", "High Floor Tom",
  22796. "Pedal Hi-Hat", "Low Tom", "Open Hi-Hat", "Low-Mid Tom", "Hi-Mid Tom", "Crash Cymbal 1",
  22797. "High Tom", "Ride Cymbal 1", "Chinese Cymbal", "Ride Bell", "Tambourine", "Splash Cymbal",
  22798. "Cowbell", "Crash Cymbal 2", "Vibraslap", "Ride Cymbal 2", "Hi Bongo", "Low Bongo",
  22799. "Mute Hi Conga", "Open Hi Conga", "Low Conga", "High Timbale", "Low Timbale", "High Agogo",
  22800. "Low Agogo", "Cabasa", "Maracas", "Short Whistle", "Long Whistle", "Short Guiro",
  22801. "Long Guiro", "Claves", "Hi Wood Block", "Low Wood Block", "Mute Cuica", "Open Cuica",
  22802. "Mute Triangle", "Open Triangle"
  22803. };
  22804. return (n >= 35 && n <= 81) ? names [n - 35]
  22805. : (const char*)0;
  22806. }
  22807. const String MidiMessage::getControllerName (int n) throw()
  22808. {
  22809. const char* names[] =
  22810. {
  22811. "Bank Select", "Modulation Wheel (coarse)", "Breath controller (coarse)",
  22812. 0, "Foot Pedal (coarse)", "Portamento Time (coarse)",
  22813. "Data Entry (coarse)", "Volume (coarse)", "Balance (coarse)",
  22814. 0, "Pan position (coarse)", "Expression (coarse)", "Effect Control 1 (coarse)",
  22815. "Effect Control 2 (coarse)", 0, 0, "General Purpose Slider 1", "General Purpose Slider 2",
  22816. "General Purpose Slider 3", "General Purpose Slider 4", 0, 0, 0, 0, 0, 0, 0, 0,
  22817. 0, 0, 0, 0, "Bank Select (fine)", "Modulation Wheel (fine)", "Breath controller (fine)",
  22818. 0, "Foot Pedal (fine)", "Portamento Time (fine)", "Data Entry (fine)", "Volume (fine)",
  22819. "Balance (fine)", 0, "Pan position (fine)", "Expression (fine)", "Effect Control 1 (fine)",
  22820. "Effect Control 2 (fine)", 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  22821. "Hold Pedal (on/off)", "Portamento (on/off)", "Sustenuto Pedal (on/off)", "Soft Pedal (on/off)",
  22822. "Legato Pedal (on/off)", "Hold 2 Pedal (on/off)", "Sound Variation", "Sound Timbre",
  22823. "Sound Release Time", "Sound Attack Time", "Sound Brightness", "Sound Control 6",
  22824. "Sound Control 7", "Sound Control 8", "Sound Control 9", "Sound Control 10",
  22825. "General Purpose Button 1 (on/off)", "General Purpose Button 2 (on/off)",
  22826. "General Purpose Button 3 (on/off)", "General Purpose Button 4 (on/off)",
  22827. 0, 0, 0, 0, 0, 0, 0, "Reverb Level", "Tremolo Level", "Chorus Level", "Celeste Level",
  22828. "Phaser Level", "Data Button increment", "Data Button decrement", "Non-registered Parameter (fine)",
  22829. "Non-registered Parameter (coarse)", "Registered Parameter (fine)", "Registered Parameter (coarse)",
  22830. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "All Sound Off", "All Controllers Off",
  22831. "Local Keyboard (on/off)", "All Notes Off", "Omni Mode Off", "Omni Mode On", "Mono Operation",
  22832. "Poly Operation"
  22833. };
  22834. return (((unsigned int) n) < 128) ? names[n]
  22835. : (const char*)0;
  22836. }
  22837. END_JUCE_NAMESPACE
  22838. /*** End of inlined file: juce_MidiMessage.cpp ***/
  22839. /*** Start of inlined file: juce_MidiMessageCollector.cpp ***/
  22840. BEGIN_JUCE_NAMESPACE
  22841. MidiMessageCollector::MidiMessageCollector()
  22842. : lastCallbackTime (0),
  22843. sampleRate (44100.0001)
  22844. {
  22845. }
  22846. MidiMessageCollector::~MidiMessageCollector()
  22847. {
  22848. }
  22849. void MidiMessageCollector::reset (const double sampleRate_)
  22850. {
  22851. jassert (sampleRate_ > 0);
  22852. const ScopedLock sl (midiCallbackLock);
  22853. sampleRate = sampleRate_;
  22854. incomingMessages.clear();
  22855. lastCallbackTime = Time::getMillisecondCounterHiRes();
  22856. }
  22857. void MidiMessageCollector::addMessageToQueue (const MidiMessage& message)
  22858. {
  22859. // you need to call reset() to set the correct sample rate before using this object
  22860. jassert (sampleRate != 44100.0001);
  22861. // the messages that come in here need to be time-stamped correctly - see MidiInput
  22862. // for details of what the number should be.
  22863. jassert (message.getTimeStamp() != 0);
  22864. const ScopedLock sl (midiCallbackLock);
  22865. const int sampleNumber
  22866. = (int) ((message.getTimeStamp() - 0.001 * lastCallbackTime) * sampleRate);
  22867. incomingMessages.addEvent (message, sampleNumber);
  22868. // if the messages don't get used for over a second, we'd better
  22869. // get rid of any old ones to avoid the queue getting too big
  22870. if (sampleNumber > sampleRate)
  22871. incomingMessages.clear (0, sampleNumber - (int) sampleRate);
  22872. }
  22873. void MidiMessageCollector::removeNextBlockOfMessages (MidiBuffer& destBuffer,
  22874. const int numSamples)
  22875. {
  22876. // you need to call reset() to set the correct sample rate before using this object
  22877. jassert (sampleRate != 44100.0001);
  22878. const double timeNow = Time::getMillisecondCounterHiRes();
  22879. const double msElapsed = timeNow - lastCallbackTime;
  22880. const ScopedLock sl (midiCallbackLock);
  22881. lastCallbackTime = timeNow;
  22882. if (! incomingMessages.isEmpty())
  22883. {
  22884. int numSourceSamples = jmax (1, roundToInt (msElapsed * 0.001 * sampleRate));
  22885. int startSample = 0;
  22886. int scale = 1 << 16;
  22887. const uint8* midiData;
  22888. int numBytes, samplePosition;
  22889. MidiBuffer::Iterator iter (incomingMessages);
  22890. if (numSourceSamples > numSamples)
  22891. {
  22892. // if our list of events is longer than the buffer we're being
  22893. // asked for, scale them down to squeeze them all in..
  22894. const int maxBlockLengthToUse = numSamples << 5;
  22895. if (numSourceSamples > maxBlockLengthToUse)
  22896. {
  22897. startSample = numSourceSamples - maxBlockLengthToUse;
  22898. numSourceSamples = maxBlockLengthToUse;
  22899. iter.setNextSamplePosition (startSample);
  22900. }
  22901. scale = (numSamples << 10) / numSourceSamples;
  22902. while (iter.getNextEvent (midiData, numBytes, samplePosition))
  22903. {
  22904. samplePosition = ((samplePosition - startSample) * scale) >> 10;
  22905. destBuffer.addEvent (midiData, numBytes,
  22906. jlimit (0, numSamples - 1, samplePosition));
  22907. }
  22908. }
  22909. else
  22910. {
  22911. // if our event list is shorter than the number we need, put them
  22912. // towards the end of the buffer
  22913. startSample = numSamples - numSourceSamples;
  22914. while (iter.getNextEvent (midiData, numBytes, samplePosition))
  22915. {
  22916. destBuffer.addEvent (midiData, numBytes,
  22917. jlimit (0, numSamples - 1, samplePosition + startSample));
  22918. }
  22919. }
  22920. incomingMessages.clear();
  22921. }
  22922. }
  22923. void MidiMessageCollector::handleNoteOn (MidiKeyboardState*, int midiChannel, int midiNoteNumber, float velocity)
  22924. {
  22925. MidiMessage m (MidiMessage::noteOn (midiChannel, midiNoteNumber, velocity));
  22926. m.setTimeStamp (Time::getMillisecondCounterHiRes() * 0.001);
  22927. addMessageToQueue (m);
  22928. }
  22929. void MidiMessageCollector::handleNoteOff (MidiKeyboardState*, int midiChannel, int midiNoteNumber)
  22930. {
  22931. MidiMessage m (MidiMessage::noteOff (midiChannel, midiNoteNumber));
  22932. m.setTimeStamp (Time::getMillisecondCounterHiRes() * 0.001);
  22933. addMessageToQueue (m);
  22934. }
  22935. void MidiMessageCollector::handleIncomingMidiMessage (MidiInput*, const MidiMessage& message)
  22936. {
  22937. addMessageToQueue (message);
  22938. }
  22939. END_JUCE_NAMESPACE
  22940. /*** End of inlined file: juce_MidiMessageCollector.cpp ***/
  22941. /*** Start of inlined file: juce_MidiMessageSequence.cpp ***/
  22942. BEGIN_JUCE_NAMESPACE
  22943. MidiMessageSequence::MidiMessageSequence()
  22944. {
  22945. }
  22946. MidiMessageSequence::MidiMessageSequence (const MidiMessageSequence& other)
  22947. {
  22948. list.ensureStorageAllocated (other.list.size());
  22949. for (int i = 0; i < other.list.size(); ++i)
  22950. list.add (new MidiEventHolder (other.list.getUnchecked(i)->message));
  22951. }
  22952. MidiMessageSequence& MidiMessageSequence::operator= (const MidiMessageSequence& other)
  22953. {
  22954. MidiMessageSequence otherCopy (other);
  22955. swapWith (otherCopy);
  22956. return *this;
  22957. }
  22958. void MidiMessageSequence::swapWith (MidiMessageSequence& other) throw()
  22959. {
  22960. list.swapWithArray (other.list);
  22961. }
  22962. MidiMessageSequence::~MidiMessageSequence()
  22963. {
  22964. }
  22965. void MidiMessageSequence::clear()
  22966. {
  22967. list.clear();
  22968. }
  22969. int MidiMessageSequence::getNumEvents() const
  22970. {
  22971. return list.size();
  22972. }
  22973. MidiMessageSequence::MidiEventHolder* MidiMessageSequence::getEventPointer (const int index) const
  22974. {
  22975. return list [index];
  22976. }
  22977. double MidiMessageSequence::getTimeOfMatchingKeyUp (const int index) const
  22978. {
  22979. const MidiEventHolder* const meh = list [index];
  22980. if (meh != 0 && meh->noteOffObject != 0)
  22981. return meh->noteOffObject->message.getTimeStamp();
  22982. else
  22983. return 0.0;
  22984. }
  22985. int MidiMessageSequence::getIndexOfMatchingKeyUp (const int index) const
  22986. {
  22987. const MidiEventHolder* const meh = list [index];
  22988. return (meh != 0) ? list.indexOf (meh->noteOffObject) : -1;
  22989. }
  22990. int MidiMessageSequence::getIndexOf (MidiEventHolder* const event) const
  22991. {
  22992. return list.indexOf (event);
  22993. }
  22994. int MidiMessageSequence::getNextIndexAtTime (const double timeStamp) const
  22995. {
  22996. const int numEvents = list.size();
  22997. int i;
  22998. for (i = 0; i < numEvents; ++i)
  22999. if (list.getUnchecked(i)->message.getTimeStamp() >= timeStamp)
  23000. break;
  23001. return i;
  23002. }
  23003. double MidiMessageSequence::getStartTime() const
  23004. {
  23005. if (list.size() > 0)
  23006. return list.getUnchecked(0)->message.getTimeStamp();
  23007. else
  23008. return 0;
  23009. }
  23010. double MidiMessageSequence::getEndTime() const
  23011. {
  23012. if (list.size() > 0)
  23013. return list.getLast()->message.getTimeStamp();
  23014. else
  23015. return 0;
  23016. }
  23017. double MidiMessageSequence::getEventTime (const int index) const
  23018. {
  23019. if (((unsigned int) index) < (unsigned int) list.size())
  23020. return list.getUnchecked (index)->message.getTimeStamp();
  23021. return 0.0;
  23022. }
  23023. void MidiMessageSequence::addEvent (const MidiMessage& newMessage,
  23024. double timeAdjustment)
  23025. {
  23026. MidiEventHolder* const newOne = new MidiEventHolder (newMessage);
  23027. timeAdjustment += newMessage.getTimeStamp();
  23028. newOne->message.setTimeStamp (timeAdjustment);
  23029. int i;
  23030. for (i = list.size(); --i >= 0;)
  23031. if (list.getUnchecked(i)->message.getTimeStamp() <= timeAdjustment)
  23032. break;
  23033. list.insert (i + 1, newOne);
  23034. }
  23035. void MidiMessageSequence::deleteEvent (const int index,
  23036. const bool deleteMatchingNoteUp)
  23037. {
  23038. if (((unsigned int) index) < (unsigned int) list.size())
  23039. {
  23040. if (deleteMatchingNoteUp)
  23041. deleteEvent (getIndexOfMatchingKeyUp (index), false);
  23042. list.remove (index);
  23043. }
  23044. }
  23045. void MidiMessageSequence::addSequence (const MidiMessageSequence& other,
  23046. double timeAdjustment,
  23047. double firstAllowableTime,
  23048. double endOfAllowableDestTimes)
  23049. {
  23050. firstAllowableTime -= timeAdjustment;
  23051. endOfAllowableDestTimes -= timeAdjustment;
  23052. for (int i = 0; i < other.list.size(); ++i)
  23053. {
  23054. const MidiMessage& m = other.list.getUnchecked(i)->message;
  23055. const double t = m.getTimeStamp();
  23056. if (t >= firstAllowableTime && t < endOfAllowableDestTimes)
  23057. {
  23058. MidiEventHolder* const newOne = new MidiEventHolder (m);
  23059. newOne->message.setTimeStamp (timeAdjustment + t);
  23060. list.add (newOne);
  23061. }
  23062. }
  23063. sort();
  23064. }
  23065. int MidiMessageSequence::compareElements (const MidiMessageSequence::MidiEventHolder* const first,
  23066. const MidiMessageSequence::MidiEventHolder* const second) throw()
  23067. {
  23068. const double diff = first->message.getTimeStamp()
  23069. - second->message.getTimeStamp();
  23070. return (diff > 0) - (diff < 0);
  23071. }
  23072. void MidiMessageSequence::sort()
  23073. {
  23074. list.sort (*this, true);
  23075. }
  23076. void MidiMessageSequence::updateMatchedPairs()
  23077. {
  23078. for (int i = 0; i < list.size(); ++i)
  23079. {
  23080. const MidiMessage& m1 = list.getUnchecked(i)->message;
  23081. if (m1.isNoteOn())
  23082. {
  23083. list.getUnchecked(i)->noteOffObject = 0;
  23084. const int note = m1.getNoteNumber();
  23085. const int chan = m1.getChannel();
  23086. const int len = list.size();
  23087. for (int j = i + 1; j < len; ++j)
  23088. {
  23089. const MidiMessage& m = list.getUnchecked(j)->message;
  23090. if (m.getNoteNumber() == note && m.getChannel() == chan)
  23091. {
  23092. if (m.isNoteOff())
  23093. {
  23094. list.getUnchecked(i)->noteOffObject = list[j];
  23095. break;
  23096. }
  23097. else if (m.isNoteOn())
  23098. {
  23099. list.insert (j, new MidiEventHolder (MidiMessage::noteOff (chan, note)));
  23100. list.getUnchecked(j)->message.setTimeStamp (m.getTimeStamp());
  23101. list.getUnchecked(i)->noteOffObject = list[j];
  23102. break;
  23103. }
  23104. }
  23105. }
  23106. }
  23107. }
  23108. }
  23109. void MidiMessageSequence::addTimeToMessages (const double delta)
  23110. {
  23111. for (int i = list.size(); --i >= 0;)
  23112. list.getUnchecked (i)->message.setTimeStamp (list.getUnchecked (i)->message.getTimeStamp()
  23113. + delta);
  23114. }
  23115. void MidiMessageSequence::extractMidiChannelMessages (const int channelNumberToExtract,
  23116. MidiMessageSequence& destSequence,
  23117. const bool alsoIncludeMetaEvents) const
  23118. {
  23119. for (int i = 0; i < list.size(); ++i)
  23120. {
  23121. const MidiMessage& mm = list.getUnchecked(i)->message;
  23122. if (mm.isForChannel (channelNumberToExtract)
  23123. || (alsoIncludeMetaEvents && mm.isMetaEvent()))
  23124. {
  23125. destSequence.addEvent (mm);
  23126. }
  23127. }
  23128. }
  23129. void MidiMessageSequence::extractSysExMessages (MidiMessageSequence& destSequence) const
  23130. {
  23131. for (int i = 0; i < list.size(); ++i)
  23132. {
  23133. const MidiMessage& mm = list.getUnchecked(i)->message;
  23134. if (mm.isSysEx())
  23135. destSequence.addEvent (mm);
  23136. }
  23137. }
  23138. void MidiMessageSequence::deleteMidiChannelMessages (const int channelNumberToRemove)
  23139. {
  23140. for (int i = list.size(); --i >= 0;)
  23141. if (list.getUnchecked(i)->message.isForChannel (channelNumberToRemove))
  23142. list.remove(i);
  23143. }
  23144. void MidiMessageSequence::deleteSysExMessages()
  23145. {
  23146. for (int i = list.size(); --i >= 0;)
  23147. if (list.getUnchecked(i)->message.isSysEx())
  23148. list.remove(i);
  23149. }
  23150. void MidiMessageSequence::createControllerUpdatesForTime (const int channelNumber,
  23151. const double time,
  23152. OwnedArray<MidiMessage>& dest)
  23153. {
  23154. bool doneProg = false;
  23155. bool donePitchWheel = false;
  23156. Array <int> doneControllers;
  23157. doneControllers.ensureStorageAllocated (32);
  23158. for (int i = list.size(); --i >= 0;)
  23159. {
  23160. const MidiMessage& mm = list.getUnchecked(i)->message;
  23161. if (mm.isForChannel (channelNumber)
  23162. && mm.getTimeStamp() <= time)
  23163. {
  23164. if (mm.isProgramChange())
  23165. {
  23166. if (! doneProg)
  23167. {
  23168. dest.add (new MidiMessage (mm, 0.0));
  23169. doneProg = true;
  23170. }
  23171. }
  23172. else if (mm.isController())
  23173. {
  23174. if (! doneControllers.contains (mm.getControllerNumber()))
  23175. {
  23176. dest.add (new MidiMessage (mm, 0.0));
  23177. doneControllers.add (mm.getControllerNumber());
  23178. }
  23179. }
  23180. else if (mm.isPitchWheel())
  23181. {
  23182. if (! donePitchWheel)
  23183. {
  23184. dest.add (new MidiMessage (mm, 0.0));
  23185. donePitchWheel = true;
  23186. }
  23187. }
  23188. }
  23189. }
  23190. }
  23191. MidiMessageSequence::MidiEventHolder::MidiEventHolder (const MidiMessage& message_)
  23192. : message (message_),
  23193. noteOffObject (0)
  23194. {
  23195. }
  23196. MidiMessageSequence::MidiEventHolder::~MidiEventHolder()
  23197. {
  23198. }
  23199. END_JUCE_NAMESPACE
  23200. /*** End of inlined file: juce_MidiMessageSequence.cpp ***/
  23201. /*** Start of inlined file: juce_AudioPluginFormat.cpp ***/
  23202. BEGIN_JUCE_NAMESPACE
  23203. AudioPluginFormat::AudioPluginFormat() throw()
  23204. {
  23205. }
  23206. AudioPluginFormat::~AudioPluginFormat()
  23207. {
  23208. }
  23209. END_JUCE_NAMESPACE
  23210. /*** End of inlined file: juce_AudioPluginFormat.cpp ***/
  23211. /*** Start of inlined file: juce_AudioPluginFormatManager.cpp ***/
  23212. BEGIN_JUCE_NAMESPACE
  23213. AudioPluginFormatManager::AudioPluginFormatManager() throw()
  23214. {
  23215. }
  23216. AudioPluginFormatManager::~AudioPluginFormatManager() throw()
  23217. {
  23218. clearSingletonInstance();
  23219. }
  23220. juce_ImplementSingleton_SingleThreaded (AudioPluginFormatManager);
  23221. void AudioPluginFormatManager::addDefaultFormats()
  23222. {
  23223. #ifdef JUCE_DEBUG
  23224. // you should only call this method once!
  23225. for (int i = formats.size(); --i >= 0;)
  23226. {
  23227. #if JUCE_PLUGINHOST_VST && ! (JUCE_MAC && JUCE_64BIT)
  23228. jassert (dynamic_cast <VSTPluginFormat*> (formats[i]) == 0);
  23229. #endif
  23230. #if JUCE_PLUGINHOST_AU && JUCE_MAC
  23231. jassert (dynamic_cast <AudioUnitPluginFormat*> (formats[i]) == 0);
  23232. #endif
  23233. #if JUCE_PLUGINHOST_DX && JUCE_WIN32
  23234. jassert (dynamic_cast <DirectXPluginFormat*> (formats[i]) == 0);
  23235. #endif
  23236. #if JUCE_PLUGINHOST_LADSPA && JUCE_LINUX
  23237. jassert (dynamic_cast <LADSPAPluginFormat*> (formats[i]) == 0);
  23238. #endif
  23239. }
  23240. #endif
  23241. #if JUCE_PLUGINHOST_AU && JUCE_MAC
  23242. formats.add (new AudioUnitPluginFormat());
  23243. #endif
  23244. #if JUCE_PLUGINHOST_VST && ! (JUCE_MAC && JUCE_64BIT)
  23245. formats.add (new VSTPluginFormat());
  23246. #endif
  23247. #if JUCE_PLUGINHOST_DX && JUCE_WIN32
  23248. formats.add (new DirectXPluginFormat());
  23249. #endif
  23250. #if JUCE_PLUGINHOST_LADSPA && JUCE_LINUX
  23251. formats.add (new LADSPAPluginFormat());
  23252. #endif
  23253. }
  23254. int AudioPluginFormatManager::getNumFormats() throw()
  23255. {
  23256. return formats.size();
  23257. }
  23258. AudioPluginFormat* AudioPluginFormatManager::getFormat (const int index) throw()
  23259. {
  23260. return formats [index];
  23261. }
  23262. void AudioPluginFormatManager::addFormat (AudioPluginFormat* const format) throw()
  23263. {
  23264. formats.add (format);
  23265. }
  23266. AudioPluginInstance* AudioPluginFormatManager::createPluginInstance (const PluginDescription& description,
  23267. String& errorMessage) const
  23268. {
  23269. AudioPluginInstance* result = 0;
  23270. for (int i = 0; i < formats.size(); ++i)
  23271. {
  23272. result = formats.getUnchecked(i)->createInstanceFromDescription (description);
  23273. if (result != 0)
  23274. break;
  23275. }
  23276. if (result == 0)
  23277. {
  23278. if (! doesPluginStillExist (description))
  23279. errorMessage = TRANS ("This plug-in file no longer exists");
  23280. else
  23281. errorMessage = TRANS ("This plug-in failed to load correctly");
  23282. }
  23283. return result;
  23284. }
  23285. bool AudioPluginFormatManager::doesPluginStillExist (const PluginDescription& description) const
  23286. {
  23287. for (int i = 0; i < formats.size(); ++i)
  23288. if (formats.getUnchecked(i)->getName() == description.pluginFormatName)
  23289. return formats.getUnchecked(i)->doesPluginStillExist (description);
  23290. return false;
  23291. }
  23292. END_JUCE_NAMESPACE
  23293. /*** End of inlined file: juce_AudioPluginFormatManager.cpp ***/
  23294. /*** Start of inlined file: juce_AudioPluginInstance.cpp ***/
  23295. #define JUCE_PLUGIN_HOST 1
  23296. BEGIN_JUCE_NAMESPACE
  23297. AudioPluginInstance::AudioPluginInstance()
  23298. {
  23299. }
  23300. AudioPluginInstance::~AudioPluginInstance()
  23301. {
  23302. }
  23303. END_JUCE_NAMESPACE
  23304. /*** End of inlined file: juce_AudioPluginInstance.cpp ***/
  23305. /*** Start of inlined file: juce_KnownPluginList.cpp ***/
  23306. BEGIN_JUCE_NAMESPACE
  23307. KnownPluginList::KnownPluginList()
  23308. {
  23309. }
  23310. KnownPluginList::~KnownPluginList()
  23311. {
  23312. }
  23313. void KnownPluginList::clear()
  23314. {
  23315. if (types.size() > 0)
  23316. {
  23317. types.clear();
  23318. sendChangeMessage (this);
  23319. }
  23320. }
  23321. PluginDescription* KnownPluginList::getTypeForFile (const String& fileOrIdentifier) const throw()
  23322. {
  23323. for (int i = 0; i < types.size(); ++i)
  23324. if (types.getUnchecked(i)->fileOrIdentifier == fileOrIdentifier)
  23325. return types.getUnchecked(i);
  23326. return 0;
  23327. }
  23328. PluginDescription* KnownPluginList::getTypeForIdentifierString (const String& identifierString) const throw()
  23329. {
  23330. for (int i = 0; i < types.size(); ++i)
  23331. if (types.getUnchecked(i)->createIdentifierString() == identifierString)
  23332. return types.getUnchecked(i);
  23333. return 0;
  23334. }
  23335. bool KnownPluginList::addType (const PluginDescription& type)
  23336. {
  23337. for (int i = types.size(); --i >= 0;)
  23338. {
  23339. if (types.getUnchecked(i)->isDuplicateOf (type))
  23340. {
  23341. // strange - found a duplicate plugin with different info..
  23342. jassert (types.getUnchecked(i)->name == type.name);
  23343. jassert (types.getUnchecked(i)->isInstrument == type.isInstrument);
  23344. *types.getUnchecked(i) = type;
  23345. return false;
  23346. }
  23347. }
  23348. types.add (new PluginDescription (type));
  23349. sendChangeMessage (this);
  23350. return true;
  23351. }
  23352. void KnownPluginList::removeType (const int index) throw()
  23353. {
  23354. types.remove (index);
  23355. sendChangeMessage (this);
  23356. }
  23357. static Time getFileModTime (const String& fileOrIdentifier) throw()
  23358. {
  23359. if (fileOrIdentifier.startsWithChar (T('/'))
  23360. || fileOrIdentifier[1] == T(':'))
  23361. {
  23362. return File (fileOrIdentifier).getLastModificationTime();
  23363. }
  23364. return Time (0);
  23365. }
  23366. static bool timesAreDifferent (const Time& t1, const Time& t2) throw()
  23367. {
  23368. return t1 != t2 || t1 == Time (0);
  23369. }
  23370. bool KnownPluginList::isListingUpToDate (const String& fileOrIdentifier) const throw()
  23371. {
  23372. if (getTypeForFile (fileOrIdentifier) == 0)
  23373. return false;
  23374. for (int i = types.size(); --i >= 0;)
  23375. {
  23376. const PluginDescription* const d = types.getUnchecked(i);
  23377. if (d->fileOrIdentifier == fileOrIdentifier
  23378. && timesAreDifferent (d->lastFileModTime, getFileModTime (fileOrIdentifier)))
  23379. {
  23380. return false;
  23381. }
  23382. }
  23383. return true;
  23384. }
  23385. bool KnownPluginList::scanAndAddFile (const String& fileOrIdentifier,
  23386. const bool dontRescanIfAlreadyInList,
  23387. OwnedArray <PluginDescription>& typesFound,
  23388. AudioPluginFormat& format)
  23389. {
  23390. bool addedOne = false;
  23391. if (dontRescanIfAlreadyInList
  23392. && getTypeForFile (fileOrIdentifier) != 0)
  23393. {
  23394. bool needsRescanning = false;
  23395. for (int i = types.size(); --i >= 0;)
  23396. {
  23397. const PluginDescription* const d = types.getUnchecked(i);
  23398. if (d->fileOrIdentifier == fileOrIdentifier)
  23399. {
  23400. if (timesAreDifferent (d->lastFileModTime, getFileModTime (fileOrIdentifier)))
  23401. needsRescanning = true;
  23402. else
  23403. typesFound.add (new PluginDescription (*d));
  23404. }
  23405. }
  23406. if (! needsRescanning)
  23407. return false;
  23408. }
  23409. OwnedArray <PluginDescription> found;
  23410. format.findAllTypesForFile (found, fileOrIdentifier);
  23411. for (int i = 0; i < found.size(); ++i)
  23412. {
  23413. PluginDescription* const desc = found.getUnchecked(i);
  23414. jassert (desc != 0);
  23415. if (addType (*desc))
  23416. addedOne = true;
  23417. typesFound.add (new PluginDescription (*desc));
  23418. }
  23419. return addedOne;
  23420. }
  23421. void KnownPluginList::scanAndAddDragAndDroppedFiles (const StringArray& files,
  23422. OwnedArray <PluginDescription>& typesFound)
  23423. {
  23424. for (int i = 0; i < files.size(); ++i)
  23425. {
  23426. bool loaded = false;
  23427. for (int j = 0; j < AudioPluginFormatManager::getInstance()->getNumFormats(); ++j)
  23428. {
  23429. AudioPluginFormat* const format = AudioPluginFormatManager::getInstance()->getFormat (j);
  23430. if (scanAndAddFile (files[i], true, typesFound, *format))
  23431. loaded = true;
  23432. }
  23433. if (! loaded)
  23434. {
  23435. const File f (files[i]);
  23436. if (f.isDirectory())
  23437. {
  23438. StringArray s;
  23439. {
  23440. Array<File> subFiles;
  23441. f.findChildFiles (subFiles, File::findFilesAndDirectories, false);
  23442. for (int j = 0; j < subFiles.size(); ++j)
  23443. s.add (subFiles.getReference(j).getFullPathName());
  23444. }
  23445. scanAndAddDragAndDroppedFiles (s, typesFound);
  23446. }
  23447. }
  23448. }
  23449. }
  23450. class PluginSorter
  23451. {
  23452. public:
  23453. KnownPluginList::SortMethod method;
  23454. PluginSorter() throw() {}
  23455. int compareElements (const PluginDescription* const first,
  23456. const PluginDescription* const second) const throw()
  23457. {
  23458. int diff = 0;
  23459. if (method == KnownPluginList::sortByCategory)
  23460. diff = first->category.compareLexicographically (second->category);
  23461. else if (method == KnownPluginList::sortByManufacturer)
  23462. diff = first->manufacturerName.compareLexicographically (second->manufacturerName);
  23463. else if (method == KnownPluginList::sortByFileSystemLocation)
  23464. diff = first->fileOrIdentifier.replaceCharacter (T('\\'), T('/'))
  23465. .upToLastOccurrenceOf (T("/"), false, false)
  23466. .compare (second->fileOrIdentifier.replaceCharacter (T('\\'), T('/'))
  23467. .upToLastOccurrenceOf (T("/"), false, false));
  23468. if (diff == 0)
  23469. diff = first->name.compareLexicographically (second->name);
  23470. return diff;
  23471. }
  23472. };
  23473. void KnownPluginList::sort (const SortMethod method)
  23474. {
  23475. if (method != defaultOrder)
  23476. {
  23477. PluginSorter sorter;
  23478. sorter.method = method;
  23479. types.sort (sorter, true);
  23480. sendChangeMessage (this);
  23481. }
  23482. }
  23483. XmlElement* KnownPluginList::createXml() const
  23484. {
  23485. XmlElement* const e = new XmlElement (T("KNOWNPLUGINS"));
  23486. for (int i = 0; i < types.size(); ++i)
  23487. e->addChildElement (types.getUnchecked(i)->createXml());
  23488. return e;
  23489. }
  23490. void KnownPluginList::recreateFromXml (const XmlElement& xml)
  23491. {
  23492. clear();
  23493. if (xml.hasTagName (T("KNOWNPLUGINS")))
  23494. {
  23495. forEachXmlChildElement (xml, e)
  23496. {
  23497. PluginDescription info;
  23498. if (info.loadFromXml (*e))
  23499. addType (info);
  23500. }
  23501. }
  23502. }
  23503. const int menuIdBase = 0x324503f4;
  23504. // This is used to turn a bunch of paths into a nested menu structure.
  23505. struct PluginFilesystemTree
  23506. {
  23507. private:
  23508. String folder;
  23509. OwnedArray <PluginFilesystemTree> subFolders;
  23510. Array <PluginDescription*> plugins;
  23511. void addPlugin (PluginDescription* const pd, const String& path)
  23512. {
  23513. if (path.isEmpty())
  23514. {
  23515. plugins.add (pd);
  23516. }
  23517. else
  23518. {
  23519. const String firstSubFolder (path.upToFirstOccurrenceOf (T("/"), false, false));
  23520. const String remainingPath (path.fromFirstOccurrenceOf (T("/"), false, false));
  23521. for (int i = subFolders.size(); --i >= 0;)
  23522. {
  23523. if (subFolders.getUnchecked(i)->folder.equalsIgnoreCase (firstSubFolder))
  23524. {
  23525. subFolders.getUnchecked(i)->addPlugin (pd, remainingPath);
  23526. return;
  23527. }
  23528. }
  23529. PluginFilesystemTree* const newFolder = new PluginFilesystemTree();
  23530. newFolder->folder = firstSubFolder;
  23531. subFolders.add (newFolder);
  23532. newFolder->addPlugin (pd, remainingPath);
  23533. }
  23534. }
  23535. // removes any deeply nested folders that don't contain any actual plugins
  23536. void optimise()
  23537. {
  23538. for (int i = subFolders.size(); --i >= 0;)
  23539. {
  23540. PluginFilesystemTree* const sub = subFolders.getUnchecked(i);
  23541. sub->optimise();
  23542. if (sub->plugins.size() == 0)
  23543. {
  23544. for (int j = 0; j < sub->subFolders.size(); ++j)
  23545. subFolders.add (sub->subFolders.getUnchecked(j));
  23546. sub->subFolders.clear (false);
  23547. subFolders.remove (i);
  23548. }
  23549. }
  23550. }
  23551. public:
  23552. void buildTree (const Array <PluginDescription*>& allPlugins)
  23553. {
  23554. for (int i = 0; i < allPlugins.size(); ++i)
  23555. {
  23556. String path (allPlugins.getUnchecked(i)
  23557. ->fileOrIdentifier.replaceCharacter (T('\\'), T('/'))
  23558. .upToLastOccurrenceOf (T("/"), false, false));
  23559. if (path.substring (1, 2) == T(":"))
  23560. path = path.substring (2);
  23561. addPlugin (allPlugins.getUnchecked(i), path);
  23562. }
  23563. optimise();
  23564. }
  23565. void addToMenu (PopupMenu& m, const OwnedArray <PluginDescription>& allPlugins) const
  23566. {
  23567. int i;
  23568. for (i = 0; i < subFolders.size(); ++i)
  23569. {
  23570. const PluginFilesystemTree* const sub = subFolders.getUnchecked(i);
  23571. PopupMenu subMenu;
  23572. sub->addToMenu (subMenu, allPlugins);
  23573. #if JUCE_MAC
  23574. // avoid the special AU formatting nonsense on Mac..
  23575. m.addSubMenu (sub->folder.fromFirstOccurrenceOf (T(":"), false, false), subMenu);
  23576. #else
  23577. m.addSubMenu (sub->folder, subMenu);
  23578. #endif
  23579. }
  23580. for (i = 0; i < plugins.size(); ++i)
  23581. {
  23582. PluginDescription* const plugin = plugins.getUnchecked(i);
  23583. m.addItem (allPlugins.indexOf (plugin) + menuIdBase,
  23584. plugin->name, true, false);
  23585. }
  23586. }
  23587. };
  23588. void KnownPluginList::addToMenu (PopupMenu& menu, const SortMethod sortMethod) const
  23589. {
  23590. Array <PluginDescription*> sorted;
  23591. {
  23592. PluginSorter sorter;
  23593. sorter.method = sortMethod;
  23594. for (int i = 0; i < types.size(); ++i)
  23595. sorted.addSorted (sorter, types.getUnchecked(i));
  23596. }
  23597. if (sortMethod == sortByCategory
  23598. || sortMethod == sortByManufacturer)
  23599. {
  23600. String lastSubMenuName;
  23601. PopupMenu sub;
  23602. for (int i = 0; i < sorted.size(); ++i)
  23603. {
  23604. const PluginDescription* const pd = sorted.getUnchecked(i);
  23605. String thisSubMenuName (sortMethod == sortByCategory ? pd->category
  23606. : pd->manufacturerName);
  23607. if (! thisSubMenuName.containsNonWhitespaceChars())
  23608. thisSubMenuName = T("Other");
  23609. if (thisSubMenuName != lastSubMenuName)
  23610. {
  23611. if (sub.getNumItems() > 0)
  23612. {
  23613. menu.addSubMenu (lastSubMenuName, sub);
  23614. sub.clear();
  23615. }
  23616. lastSubMenuName = thisSubMenuName;
  23617. }
  23618. sub.addItem (types.indexOf (pd) + menuIdBase, pd->name, true, false);
  23619. }
  23620. if (sub.getNumItems() > 0)
  23621. menu.addSubMenu (lastSubMenuName, sub);
  23622. }
  23623. else if (sortMethod == sortByFileSystemLocation)
  23624. {
  23625. PluginFilesystemTree root;
  23626. root.buildTree (sorted);
  23627. root.addToMenu (menu, types);
  23628. }
  23629. else
  23630. {
  23631. for (int i = 0; i < sorted.size(); ++i)
  23632. {
  23633. const PluginDescription* const pd = sorted.getUnchecked(i);
  23634. menu.addItem (types.indexOf (pd) + menuIdBase, pd->name, true, false);
  23635. }
  23636. }
  23637. }
  23638. int KnownPluginList::getIndexChosenByMenu (const int menuResultCode) const
  23639. {
  23640. const int i = menuResultCode - menuIdBase;
  23641. return (((unsigned int) i) < (unsigned int) types.size()) ? i : -1;
  23642. }
  23643. END_JUCE_NAMESPACE
  23644. /*** End of inlined file: juce_KnownPluginList.cpp ***/
  23645. /*** Start of inlined file: juce_PluginDescription.cpp ***/
  23646. BEGIN_JUCE_NAMESPACE
  23647. PluginDescription::PluginDescription() throw()
  23648. : uid (0),
  23649. isInstrument (false),
  23650. numInputChannels (0),
  23651. numOutputChannels (0)
  23652. {
  23653. }
  23654. PluginDescription::~PluginDescription() throw()
  23655. {
  23656. }
  23657. PluginDescription::PluginDescription (const PluginDescription& other) throw()
  23658. : name (other.name),
  23659. pluginFormatName (other.pluginFormatName),
  23660. category (other.category),
  23661. manufacturerName (other.manufacturerName),
  23662. version (other.version),
  23663. fileOrIdentifier (other.fileOrIdentifier),
  23664. lastFileModTime (other.lastFileModTime),
  23665. uid (other.uid),
  23666. isInstrument (other.isInstrument),
  23667. numInputChannels (other.numInputChannels),
  23668. numOutputChannels (other.numOutputChannels)
  23669. {
  23670. }
  23671. PluginDescription& PluginDescription::operator= (const PluginDescription& other) throw()
  23672. {
  23673. name = other.name;
  23674. pluginFormatName = other.pluginFormatName;
  23675. category = other.category;
  23676. manufacturerName = other.manufacturerName;
  23677. version = other.version;
  23678. fileOrIdentifier = other.fileOrIdentifier;
  23679. uid = other.uid;
  23680. isInstrument = other.isInstrument;
  23681. lastFileModTime = other.lastFileModTime;
  23682. numInputChannels = other.numInputChannels;
  23683. numOutputChannels = other.numOutputChannels;
  23684. return *this;
  23685. }
  23686. bool PluginDescription::isDuplicateOf (const PluginDescription& other) const
  23687. {
  23688. return fileOrIdentifier == other.fileOrIdentifier
  23689. && uid == other.uid;
  23690. }
  23691. const String PluginDescription::createIdentifierString() const throw()
  23692. {
  23693. return pluginFormatName
  23694. + T("-") + name
  23695. + T("-") + String::toHexString (fileOrIdentifier.hashCode())
  23696. + T("-") + String::toHexString (uid);
  23697. }
  23698. XmlElement* PluginDescription::createXml() const
  23699. {
  23700. XmlElement* const e = new XmlElement (T("PLUGIN"));
  23701. e->setAttribute (T("name"), name);
  23702. e->setAttribute (T("format"), pluginFormatName);
  23703. e->setAttribute (T("category"), category);
  23704. e->setAttribute (T("manufacturer"), manufacturerName);
  23705. e->setAttribute (T("version"), version);
  23706. e->setAttribute (T("file"), fileOrIdentifier);
  23707. e->setAttribute (T("uid"), String::toHexString (uid));
  23708. e->setAttribute (T("isInstrument"), isInstrument);
  23709. e->setAttribute (T("fileTime"), String::toHexString (lastFileModTime.toMilliseconds()));
  23710. e->setAttribute (T("numInputs"), numInputChannels);
  23711. e->setAttribute (T("numOutputs"), numOutputChannels);
  23712. return e;
  23713. }
  23714. bool PluginDescription::loadFromXml (const XmlElement& xml)
  23715. {
  23716. if (xml.hasTagName (T("PLUGIN")))
  23717. {
  23718. name = xml.getStringAttribute (T("name"));
  23719. pluginFormatName = xml.getStringAttribute (T("format"));
  23720. category = xml.getStringAttribute (T("category"));
  23721. manufacturerName = xml.getStringAttribute (T("manufacturer"));
  23722. version = xml.getStringAttribute (T("version"));
  23723. fileOrIdentifier = xml.getStringAttribute (T("file"));
  23724. uid = xml.getStringAttribute (T("uid")).getHexValue32();
  23725. isInstrument = xml.getBoolAttribute (T("isInstrument"), false);
  23726. lastFileModTime = Time (xml.getStringAttribute (T("fileTime")).getHexValue64());
  23727. numInputChannels = xml.getIntAttribute (T("numInputs"));
  23728. numOutputChannels = xml.getIntAttribute (T("numOutputs"));
  23729. return true;
  23730. }
  23731. return false;
  23732. }
  23733. END_JUCE_NAMESPACE
  23734. /*** End of inlined file: juce_PluginDescription.cpp ***/
  23735. /*** Start of inlined file: juce_PluginDirectoryScanner.cpp ***/
  23736. BEGIN_JUCE_NAMESPACE
  23737. PluginDirectoryScanner::PluginDirectoryScanner (KnownPluginList& listToAddTo,
  23738. AudioPluginFormat& formatToLookFor,
  23739. FileSearchPath directoriesToSearch,
  23740. const bool recursive,
  23741. const File& deadMansPedalFile_)
  23742. : list (listToAddTo),
  23743. format (formatToLookFor),
  23744. deadMansPedalFile (deadMansPedalFile_),
  23745. nextIndex (0),
  23746. progress (0)
  23747. {
  23748. directoriesToSearch.removeRedundantPaths();
  23749. filesOrIdentifiersToScan = format.searchPathsForPlugins (directoriesToSearch, recursive);
  23750. // If any plugins have crashed recently when being loaded, move them to the
  23751. // end of the list to give the others a chance to load correctly..
  23752. const StringArray crashedPlugins (getDeadMansPedalFile());
  23753. for (int i = 0; i < crashedPlugins.size(); ++i)
  23754. {
  23755. const String f = crashedPlugins[i];
  23756. for (int j = filesOrIdentifiersToScan.size(); --j >= 0;)
  23757. if (f == filesOrIdentifiersToScan[j])
  23758. filesOrIdentifiersToScan.move (j, -1);
  23759. }
  23760. }
  23761. PluginDirectoryScanner::~PluginDirectoryScanner()
  23762. {
  23763. }
  23764. const String PluginDirectoryScanner::getNextPluginFileThatWillBeScanned() const throw()
  23765. {
  23766. return format.getNameOfPluginFromIdentifier (filesOrIdentifiersToScan [nextIndex]);
  23767. }
  23768. bool PluginDirectoryScanner::scanNextFile (const bool dontRescanIfAlreadyInList)
  23769. {
  23770. String file (filesOrIdentifiersToScan [nextIndex]);
  23771. if (file.isNotEmpty())
  23772. {
  23773. if (! list.isListingUpToDate (file))
  23774. {
  23775. OwnedArray <PluginDescription> typesFound;
  23776. // Add this plugin to the end of the dead-man's pedal list in case it crashes...
  23777. StringArray crashedPlugins (getDeadMansPedalFile());
  23778. crashedPlugins.removeString (file);
  23779. crashedPlugins.add (file);
  23780. setDeadMansPedalFile (crashedPlugins);
  23781. list.scanAndAddFile (file,
  23782. dontRescanIfAlreadyInList,
  23783. typesFound,
  23784. format);
  23785. // Managed to load without crashing, so remove it from the dead-man's-pedal..
  23786. crashedPlugins.removeString (file);
  23787. setDeadMansPedalFile (crashedPlugins);
  23788. if (typesFound.size() == 0)
  23789. failedFiles.add (file);
  23790. }
  23791. ++nextIndex;
  23792. progress = nextIndex / (float) filesOrIdentifiersToScan.size();
  23793. }
  23794. return nextIndex < filesOrIdentifiersToScan.size();
  23795. }
  23796. const StringArray PluginDirectoryScanner::getDeadMansPedalFile() throw()
  23797. {
  23798. StringArray lines;
  23799. if (deadMansPedalFile != File::nonexistent)
  23800. {
  23801. lines.addLines (deadMansPedalFile.loadFileAsString());
  23802. lines.removeEmptyStrings();
  23803. }
  23804. return lines;
  23805. }
  23806. void PluginDirectoryScanner::setDeadMansPedalFile (const StringArray& newContents) throw()
  23807. {
  23808. if (deadMansPedalFile != File::nonexistent)
  23809. deadMansPedalFile.replaceWithText (newContents.joinIntoString ("\n"), true, true);
  23810. }
  23811. END_JUCE_NAMESPACE
  23812. /*** End of inlined file: juce_PluginDirectoryScanner.cpp ***/
  23813. /*** Start of inlined file: juce_PluginListComponent.cpp ***/
  23814. BEGIN_JUCE_NAMESPACE
  23815. PluginListComponent::PluginListComponent (KnownPluginList& listToEdit,
  23816. const File& deadMansPedalFile_,
  23817. PropertiesFile* const propertiesToUse_)
  23818. : list (listToEdit),
  23819. deadMansPedalFile (deadMansPedalFile_),
  23820. propertiesToUse (propertiesToUse_)
  23821. {
  23822. addAndMakeVisible (listBox = new ListBox (String::empty, this));
  23823. addAndMakeVisible (optionsButton = new TextButton ("Options..."));
  23824. optionsButton->addButtonListener (this);
  23825. optionsButton->setTriggeredOnMouseDown (true);
  23826. setSize (400, 600);
  23827. list.addChangeListener (this);
  23828. }
  23829. PluginListComponent::~PluginListComponent()
  23830. {
  23831. list.removeChangeListener (this);
  23832. deleteAllChildren();
  23833. }
  23834. void PluginListComponent::resized()
  23835. {
  23836. listBox->setBounds (0, 0, getWidth(), getHeight() - 30);
  23837. optionsButton->changeWidthToFitText (24);
  23838. optionsButton->setTopLeftPosition (8, getHeight() - 28);
  23839. }
  23840. void PluginListComponent::changeListenerCallback (void*)
  23841. {
  23842. listBox->updateContent();
  23843. listBox->repaint();
  23844. }
  23845. int PluginListComponent::getNumRows()
  23846. {
  23847. return list.getNumTypes();
  23848. }
  23849. void PluginListComponent::paintListBoxItem (int row,
  23850. Graphics& g,
  23851. int width, int height,
  23852. bool rowIsSelected)
  23853. {
  23854. if (rowIsSelected)
  23855. g.fillAll (findColour (TextEditor::highlightColourId));
  23856. const PluginDescription* const pd = list.getType (row);
  23857. if (pd != 0)
  23858. {
  23859. GlyphArrangement ga;
  23860. ga.addCurtailedLineOfText (Font (height * 0.7f, Font::bold), pd->name, 8.0f, height * 0.8f, width - 10.0f, true);
  23861. g.setColour (Colours::black);
  23862. ga.draw (g);
  23863. float x, y, r, b;
  23864. ga.getBoundingBox (0, -1, x, y, r, b, false);
  23865. String desc;
  23866. desc << pd->pluginFormatName
  23867. << (pd->isInstrument ? " instrument" : " effect")
  23868. << " - "
  23869. << pd->numInputChannels << (pd->numInputChannels == 1 ? " in" : " ins")
  23870. << " / "
  23871. << pd->numOutputChannels << (pd->numOutputChannels == 1 ? " out" : " outs");
  23872. if (pd->manufacturerName.isNotEmpty())
  23873. desc << " - " << pd->manufacturerName;
  23874. if (pd->version.isNotEmpty())
  23875. desc << " - " << pd->version;
  23876. if (pd->category.isNotEmpty())
  23877. desc << " - category: '" << pd->category << '\'';
  23878. g.setColour (Colours::grey);
  23879. ga.clear();
  23880. ga.addCurtailedLineOfText (Font (height * 0.6f), desc, r + 10.0f, height * 0.8f, width - r - 12.0f, true);
  23881. ga.draw (g);
  23882. }
  23883. }
  23884. void PluginListComponent::deleteKeyPressed (int lastRowSelected)
  23885. {
  23886. list.removeType (lastRowSelected);
  23887. }
  23888. void PluginListComponent::buttonClicked (Button* b)
  23889. {
  23890. if (optionsButton == b)
  23891. {
  23892. PopupMenu menu;
  23893. menu.addItem (1, TRANS("Clear list"));
  23894. menu.addItem (5, TRANS("Remove selected plugin from list"), listBox->getNumSelectedRows() > 0);
  23895. menu.addItem (6, TRANS("Show folder containing selected plugin"), listBox->getNumSelectedRows() > 0);
  23896. menu.addItem (7, TRANS("Remove any plugins whose files no longer exist"));
  23897. menu.addSeparator();
  23898. menu.addItem (2, TRANS("Sort alphabetically"));
  23899. menu.addItem (3, TRANS("Sort by category"));
  23900. menu.addItem (4, TRANS("Sort by manufacturer"));
  23901. menu.addSeparator();
  23902. for (int i = 0; i < AudioPluginFormatManager::getInstance()->getNumFormats(); ++i)
  23903. {
  23904. AudioPluginFormat* const format = AudioPluginFormatManager::getInstance()->getFormat (i);
  23905. if (format->getDefaultLocationsToSearch().getNumPaths() > 0)
  23906. menu.addItem (10 + i, "Scan for new or updated " + format->getName() + " plugins...");
  23907. }
  23908. const int r = menu.showAt (optionsButton);
  23909. if (r == 1)
  23910. {
  23911. list.clear();
  23912. }
  23913. else if (r == 2)
  23914. {
  23915. list.sort (KnownPluginList::sortAlphabetically);
  23916. }
  23917. else if (r == 3)
  23918. {
  23919. list.sort (KnownPluginList::sortByCategory);
  23920. }
  23921. else if (r == 4)
  23922. {
  23923. list.sort (KnownPluginList::sortByManufacturer);
  23924. }
  23925. else if (r == 5)
  23926. {
  23927. const SparseSet <int> selected (listBox->getSelectedRows());
  23928. for (int i = list.getNumTypes(); --i >= 0;)
  23929. if (selected.contains (i))
  23930. list.removeType (i);
  23931. }
  23932. else if (r == 6)
  23933. {
  23934. const PluginDescription* const desc = list.getType (listBox->getSelectedRow());
  23935. if (desc != 0)
  23936. {
  23937. if (File (desc->fileOrIdentifier).existsAsFile())
  23938. File (desc->fileOrIdentifier).getParentDirectory().startAsProcess();
  23939. }
  23940. }
  23941. else if (r == 7)
  23942. {
  23943. for (int i = list.getNumTypes(); --i >= 0;)
  23944. {
  23945. if (! AudioPluginFormatManager::getInstance()->doesPluginStillExist (*list.getType (i)))
  23946. {
  23947. list.removeType (i);
  23948. }
  23949. }
  23950. }
  23951. else if (r != 0)
  23952. {
  23953. typeToScan = r - 10;
  23954. startTimer (1);
  23955. }
  23956. }
  23957. }
  23958. void PluginListComponent::timerCallback()
  23959. {
  23960. stopTimer();
  23961. scanFor (AudioPluginFormatManager::getInstance()->getFormat (typeToScan));
  23962. }
  23963. bool PluginListComponent::isInterestedInFileDrag (const StringArray& /*files*/)
  23964. {
  23965. return true;
  23966. }
  23967. void PluginListComponent::filesDropped (const StringArray& files, int, int)
  23968. {
  23969. OwnedArray <PluginDescription> typesFound;
  23970. list.scanAndAddDragAndDroppedFiles (files, typesFound);
  23971. }
  23972. void PluginListComponent::scanFor (AudioPluginFormat* format)
  23973. {
  23974. if (format == 0)
  23975. return;
  23976. FileSearchPath path (format->getDefaultLocationsToSearch());
  23977. if (propertiesToUse != 0)
  23978. path = propertiesToUse->getValue ("lastPluginScanPath_" + format->getName(), path.toString());
  23979. {
  23980. AlertWindow aw (TRANS("Select folders to scan..."), String::empty, AlertWindow::NoIcon);
  23981. FileSearchPathListComponent pathList;
  23982. pathList.setSize (500, 300);
  23983. pathList.setPath (path);
  23984. aw.addCustomComponent (&pathList);
  23985. aw.addButton (TRANS("Scan"), 1, KeyPress::returnKey);
  23986. aw.addButton (TRANS("Cancel"), 0, KeyPress (KeyPress::escapeKey));
  23987. if (aw.runModalLoop() == 0)
  23988. return;
  23989. path = pathList.getPath();
  23990. }
  23991. if (propertiesToUse != 0)
  23992. {
  23993. propertiesToUse->setValue ("lastPluginScanPath_" + format->getName(), path.toString());
  23994. propertiesToUse->saveIfNeeded();
  23995. }
  23996. double progress = 0.0;
  23997. AlertWindow aw (TRANS("Scanning for plugins..."),
  23998. TRANS("Searching for all possible plugin files..."), AlertWindow::NoIcon);
  23999. aw.addButton (TRANS("Cancel"), 0, KeyPress (KeyPress::escapeKey));
  24000. aw.addProgressBarComponent (progress);
  24001. aw.enterModalState();
  24002. MessageManager::getInstance()->runDispatchLoopUntil (300);
  24003. PluginDirectoryScanner scanner (list, *format, path, true, deadMansPedalFile);
  24004. for (;;)
  24005. {
  24006. aw.setMessage (TRANS("Testing:\n\n")
  24007. + scanner.getNextPluginFileThatWillBeScanned());
  24008. MessageManager::getInstance()->runDispatchLoopUntil (20);
  24009. if (! scanner.scanNextFile (true))
  24010. break;
  24011. if (! aw.isCurrentlyModal())
  24012. break;
  24013. progress = scanner.getProgress();
  24014. }
  24015. if (scanner.getFailedFiles().size() > 0)
  24016. {
  24017. StringArray shortNames;
  24018. for (int i = 0; i < scanner.getFailedFiles().size(); ++i)
  24019. shortNames.add (File (scanner.getFailedFiles()[i]).getFileName());
  24020. AlertWindow::showMessageBox (AlertWindow::InfoIcon,
  24021. TRANS("Scan complete"),
  24022. TRANS("Note that the following files appeared to be plugin files, but failed to load correctly:\n\n")
  24023. + shortNames.joinIntoString (", "));
  24024. }
  24025. }
  24026. END_JUCE_NAMESPACE
  24027. /*** End of inlined file: juce_PluginListComponent.cpp ***/
  24028. /*** Start of inlined file: juce_AudioUnitPluginFormat.mm ***/
  24029. #if JUCE_PLUGINHOST_AU && (! (defined (LINUX) || defined (_WIN32)))
  24030. #include <AudioUnit/AudioUnit.h>
  24031. #include <AudioUnit/AUCocoaUIView.h>
  24032. #include <CoreAudioKit/AUGenericView.h>
  24033. #if JUCE_SUPPORT_CARBON
  24034. #include <AudioToolbox/AudioUnitUtilities.h>
  24035. #include <AudioUnit/AudioUnitCarbonView.h>
  24036. #endif
  24037. BEGIN_JUCE_NAMESPACE
  24038. #if JUCE_MAC && JUCE_SUPPORT_CARBON
  24039. #endif
  24040. #if JUCE_MAC
  24041. // Change this to disable logging of various activities
  24042. #ifndef AU_LOGGING
  24043. #define AU_LOGGING 1
  24044. #endif
  24045. #if AU_LOGGING
  24046. #define log(a) Logger::writeToLog(a);
  24047. #else
  24048. #define log(a)
  24049. #endif
  24050. static int insideCallback = 0;
  24051. static const String osTypeToString (OSType type)
  24052. {
  24053. char s[4];
  24054. s[0] = (char) (((uint32) type) >> 24);
  24055. s[1] = (char) (((uint32) type) >> 16);
  24056. s[2] = (char) (((uint32) type) >> 8);
  24057. s[3] = (char) ((uint32) type);
  24058. return String (s, 4);
  24059. }
  24060. static OSType stringToOSType (const String& s1)
  24061. {
  24062. const String s (s1 + " ");
  24063. return (((OSType) (unsigned char) s[0]) << 24)
  24064. | (((OSType) (unsigned char) s[1]) << 16)
  24065. | (((OSType) (unsigned char) s[2]) << 8)
  24066. | ((OSType) (unsigned char) s[3]);
  24067. }
  24068. static const tchar* auIdentifierPrefix = T("AudioUnit:");
  24069. static const String createAUPluginIdentifier (const ComponentDescription& desc)
  24070. {
  24071. jassert (osTypeToString ('abcd') == T("abcd")); // agh, must have got the endianness wrong..
  24072. jassert (stringToOSType ("abcd") == (OSType) 'abcd'); // ditto
  24073. String s (auIdentifierPrefix);
  24074. if (desc.componentType == kAudioUnitType_MusicDevice)
  24075. s << "Synths/";
  24076. else if (desc.componentType == kAudioUnitType_MusicEffect
  24077. || desc.componentType == kAudioUnitType_Effect)
  24078. s << "Effects/";
  24079. else if (desc.componentType == kAudioUnitType_Generator)
  24080. s << "Generators/";
  24081. else if (desc.componentType == kAudioUnitType_Panner)
  24082. s << "Panners/";
  24083. s << osTypeToString (desc.componentType) << ","
  24084. << osTypeToString (desc.componentSubType) << ","
  24085. << osTypeToString (desc.componentManufacturer);
  24086. return s;
  24087. }
  24088. static void getAUDetails (ComponentRecord* comp, String& name, String& manufacturer)
  24089. {
  24090. Handle componentNameHandle = NewHandle (sizeof (void*));
  24091. Handle componentInfoHandle = NewHandle (sizeof (void*));
  24092. if (componentNameHandle != 0 && componentInfoHandle != 0)
  24093. {
  24094. ComponentDescription desc;
  24095. if (GetComponentInfo (comp, &desc, componentNameHandle, componentInfoHandle, 0) == noErr)
  24096. {
  24097. ConstStr255Param nameString = (ConstStr255Param) (*componentNameHandle);
  24098. ConstStr255Param infoString = (ConstStr255Param) (*componentInfoHandle);
  24099. if (nameString != 0 && nameString[0] != 0)
  24100. {
  24101. const String all ((const char*) nameString + 1, nameString[0]);
  24102. DBG ("name: "+ all);
  24103. manufacturer = all.upToFirstOccurrenceOf (T(":"), false, false).trim();
  24104. name = all.fromFirstOccurrenceOf (T(":"), false, false).trim();
  24105. }
  24106. if (infoString != 0 && infoString[0] != 0)
  24107. {
  24108. DBG ("info: " + String ((const char*) infoString + 1, infoString[0]));
  24109. }
  24110. if (name.isEmpty())
  24111. name = "<Unknown>";
  24112. }
  24113. DisposeHandle (componentNameHandle);
  24114. DisposeHandle (componentInfoHandle);
  24115. }
  24116. }
  24117. static bool getComponentDescFromIdentifier (const String& fileOrIdentifier, ComponentDescription& desc,
  24118. String& name, String& version, String& manufacturer)
  24119. {
  24120. zerostruct (desc);
  24121. if (fileOrIdentifier.startsWithIgnoreCase (auIdentifierPrefix))
  24122. {
  24123. String s (fileOrIdentifier.substring (jmax (fileOrIdentifier.lastIndexOfChar (T(':')),
  24124. fileOrIdentifier.lastIndexOfChar (T('/'))) + 1));
  24125. StringArray tokens;
  24126. tokens.addTokens (s, T(","), String::empty);
  24127. tokens.trim();
  24128. tokens.removeEmptyStrings();
  24129. if (tokens.size() == 3)
  24130. {
  24131. desc.componentType = stringToOSType (tokens[0]);
  24132. desc.componentSubType = stringToOSType (tokens[1]);
  24133. desc.componentManufacturer = stringToOSType (tokens[2]);
  24134. ComponentRecord* comp = FindNextComponent (0, &desc);
  24135. if (comp != 0)
  24136. {
  24137. getAUDetails (comp, name, manufacturer);
  24138. return true;
  24139. }
  24140. }
  24141. }
  24142. return false;
  24143. }
  24144. class AudioUnitPluginWindowCarbon;
  24145. class AudioUnitPluginWindowCocoa;
  24146. class AudioUnitPluginInstance : public AudioPluginInstance
  24147. {
  24148. public:
  24149. ~AudioUnitPluginInstance();
  24150. // AudioPluginInstance methods:
  24151. void fillInPluginDescription (PluginDescription& desc) const
  24152. {
  24153. desc.name = pluginName;
  24154. desc.fileOrIdentifier = createAUPluginIdentifier (componentDesc);
  24155. desc.uid = ((int) componentDesc.componentType)
  24156. ^ ((int) componentDesc.componentSubType)
  24157. ^ ((int) componentDesc.componentManufacturer);
  24158. desc.lastFileModTime = 0;
  24159. desc.pluginFormatName = "AudioUnit";
  24160. desc.category = getCategory();
  24161. desc.manufacturerName = manufacturer;
  24162. desc.version = version;
  24163. desc.numInputChannels = getNumInputChannels();
  24164. desc.numOutputChannels = getNumOutputChannels();
  24165. desc.isInstrument = (componentDesc.componentType == kAudioUnitType_MusicDevice);
  24166. }
  24167. const String getName() const { return pluginName; }
  24168. bool acceptsMidi() const { return wantsMidiMessages; }
  24169. bool producesMidi() const { return false; }
  24170. // AudioProcessor methods:
  24171. void prepareToPlay (double sampleRate, int estimatedSamplesPerBlock);
  24172. void releaseResources();
  24173. void processBlock (AudioSampleBuffer& buffer,
  24174. MidiBuffer& midiMessages);
  24175. AudioProcessorEditor* createEditor();
  24176. const String getInputChannelName (const int index) const;
  24177. bool isInputChannelStereoPair (int index) const;
  24178. const String getOutputChannelName (const int index) const;
  24179. bool isOutputChannelStereoPair (int index) const;
  24180. int getNumParameters();
  24181. float getParameter (int index);
  24182. void setParameter (int index, float newValue);
  24183. const String getParameterName (int index);
  24184. const String getParameterText (int index);
  24185. bool isParameterAutomatable (int index) const;
  24186. int getNumPrograms();
  24187. int getCurrentProgram();
  24188. void setCurrentProgram (int index);
  24189. const String getProgramName (int index);
  24190. void changeProgramName (int index, const String& newName);
  24191. void getStateInformation (MemoryBlock& destData);
  24192. void getCurrentProgramStateInformation (MemoryBlock& destData);
  24193. void setStateInformation (const void* data, int sizeInBytes);
  24194. void setCurrentProgramStateInformation (const void* data, int sizeInBytes);
  24195. juce_UseDebuggingNewOperator
  24196. private:
  24197. friend class AudioUnitPluginWindowCarbon;
  24198. friend class AudioUnitPluginWindowCocoa;
  24199. friend class AudioUnitPluginFormat;
  24200. ComponentDescription componentDesc;
  24201. String pluginName, manufacturer, version;
  24202. String fileOrIdentifier;
  24203. CriticalSection lock;
  24204. bool initialised, wantsMidiMessages, wasPlaying;
  24205. HeapBlock <AudioBufferList> outputBufferList;
  24206. AudioTimeStamp timeStamp;
  24207. AudioSampleBuffer* currentBuffer;
  24208. AudioUnit audioUnit;
  24209. Array <int> parameterIds;
  24210. bool getComponentDescFromFile (const String& fileOrIdentifier);
  24211. void initialise();
  24212. OSStatus renderGetInput (AudioUnitRenderActionFlags* ioActionFlags,
  24213. const AudioTimeStamp* inTimeStamp,
  24214. UInt32 inBusNumber,
  24215. UInt32 inNumberFrames,
  24216. AudioBufferList* ioData) const;
  24217. static OSStatus renderGetInputCallback (void* inRefCon,
  24218. AudioUnitRenderActionFlags* ioActionFlags,
  24219. const AudioTimeStamp* inTimeStamp,
  24220. UInt32 inBusNumber,
  24221. UInt32 inNumberFrames,
  24222. AudioBufferList* ioData)
  24223. {
  24224. return ((AudioUnitPluginInstance*) inRefCon)
  24225. ->renderGetInput (ioActionFlags, inTimeStamp, inBusNumber, inNumberFrames, ioData);
  24226. }
  24227. OSStatus getBeatAndTempo (Float64* outCurrentBeat, Float64* outCurrentTempo) const;
  24228. OSStatus getMusicalTimeLocation (UInt32* outDeltaSampleOffsetToNextBeat, Float32* outTimeSig_Numerator,
  24229. UInt32* outTimeSig_Denominator, Float64* outCurrentMeasureDownBeat) const;
  24230. OSStatus getTransportState (Boolean* outIsPlaying, Boolean* outTransportStateChanged,
  24231. Float64* outCurrentSampleInTimeLine, Boolean* outIsCycling,
  24232. Float64* outCycleStartBeat, Float64* outCycleEndBeat);
  24233. static OSStatus getBeatAndTempoCallback (void* inHostUserData, Float64* outCurrentBeat, Float64* outCurrentTempo)
  24234. {
  24235. return ((AudioUnitPluginInstance*) inHostUserData)->getBeatAndTempo (outCurrentBeat, outCurrentTempo);
  24236. }
  24237. static OSStatus getMusicalTimeLocationCallback (void* inHostUserData, UInt32* outDeltaSampleOffsetToNextBeat,
  24238. Float32* outTimeSig_Numerator, UInt32* outTimeSig_Denominator,
  24239. Float64* outCurrentMeasureDownBeat)
  24240. {
  24241. return ((AudioUnitPluginInstance*) inHostUserData)
  24242. ->getMusicalTimeLocation (outDeltaSampleOffsetToNextBeat, outTimeSig_Numerator,
  24243. outTimeSig_Denominator, outCurrentMeasureDownBeat);
  24244. }
  24245. static OSStatus getTransportStateCallback (void* inHostUserData, Boolean* outIsPlaying, Boolean* outTransportStateChanged,
  24246. Float64* outCurrentSampleInTimeLine, Boolean* outIsCycling,
  24247. Float64* outCycleStartBeat, Float64* outCycleEndBeat)
  24248. {
  24249. return ((AudioUnitPluginInstance*) inHostUserData)
  24250. ->getTransportState (outIsPlaying, outTransportStateChanged,
  24251. outCurrentSampleInTimeLine, outIsCycling,
  24252. outCycleStartBeat, outCycleEndBeat);
  24253. }
  24254. void getNumChannels (int& numIns, int& numOuts)
  24255. {
  24256. numIns = 0;
  24257. numOuts = 0;
  24258. AUChannelInfo supportedChannels [128];
  24259. UInt32 supportedChannelsSize = sizeof (supportedChannels);
  24260. if (AudioUnitGetProperty (audioUnit, kAudioUnitProperty_SupportedNumChannels, kAudioUnitScope_Global,
  24261. 0, supportedChannels, &supportedChannelsSize) == noErr
  24262. && supportedChannelsSize > 0)
  24263. {
  24264. for (int i = 0; i < supportedChannelsSize / sizeof (AUChannelInfo); ++i)
  24265. {
  24266. numIns = jmax (numIns, (int) supportedChannels[i].inChannels);
  24267. numOuts = jmax (numOuts, (int) supportedChannels[i].outChannels);
  24268. }
  24269. }
  24270. else
  24271. {
  24272. // (this really means the plugin will take any number of ins/outs as long
  24273. // as they are the same)
  24274. numIns = numOuts = 2;
  24275. }
  24276. }
  24277. const String getCategory() const;
  24278. AudioUnitPluginInstance (const String& fileOrIdentifier);
  24279. };
  24280. AudioUnitPluginInstance::AudioUnitPluginInstance (const String& fileOrIdentifier)
  24281. : fileOrIdentifier (fileOrIdentifier),
  24282. initialised (false),
  24283. wantsMidiMessages (false),
  24284. audioUnit (0),
  24285. currentBuffer (0)
  24286. {
  24287. try
  24288. {
  24289. ++insideCallback;
  24290. log (T("Opening AU: ") + fileOrIdentifier);
  24291. if (getComponentDescFromFile (fileOrIdentifier))
  24292. {
  24293. ComponentRecord* const comp = FindNextComponent (0, &componentDesc);
  24294. if (comp != 0)
  24295. {
  24296. audioUnit = (AudioUnit) OpenComponent (comp);
  24297. wantsMidiMessages = componentDesc.componentType == kAudioUnitType_MusicDevice
  24298. || componentDesc.componentType == kAudioUnitType_MusicEffect;
  24299. }
  24300. }
  24301. --insideCallback;
  24302. }
  24303. catch (...)
  24304. {
  24305. --insideCallback;
  24306. }
  24307. }
  24308. AudioUnitPluginInstance::~AudioUnitPluginInstance()
  24309. {
  24310. const ScopedLock sl (lock);
  24311. jassert (insideCallback == 0);
  24312. if (audioUnit != 0)
  24313. {
  24314. AudioUnitUninitialize (audioUnit);
  24315. CloseComponent (audioUnit);
  24316. audioUnit = 0;
  24317. }
  24318. }
  24319. bool AudioUnitPluginInstance::getComponentDescFromFile (const String& fileOrIdentifier)
  24320. {
  24321. zerostruct (componentDesc);
  24322. if (getComponentDescFromIdentifier (fileOrIdentifier, componentDesc, pluginName, version, manufacturer))
  24323. return true;
  24324. const File file (fileOrIdentifier);
  24325. if (! file.hasFileExtension (T(".component")))
  24326. return false;
  24327. const char* const utf8 = fileOrIdentifier.toUTF8();
  24328. CFURLRef url = CFURLCreateFromFileSystemRepresentation (0, (const UInt8*) utf8,
  24329. strlen (utf8), file.isDirectory());
  24330. if (url != 0)
  24331. {
  24332. CFBundleRef bundleRef = CFBundleCreate (kCFAllocatorDefault, url);
  24333. CFRelease (url);
  24334. if (bundleRef != 0)
  24335. {
  24336. CFTypeRef name = CFBundleGetValueForInfoDictionaryKey (bundleRef, CFSTR("CFBundleName"));
  24337. if (name != 0 && CFGetTypeID (name) == CFStringGetTypeID())
  24338. pluginName = PlatformUtilities::cfStringToJuceString ((CFStringRef) name);
  24339. if (pluginName.isEmpty())
  24340. pluginName = file.getFileNameWithoutExtension();
  24341. CFTypeRef versionString = CFBundleGetValueForInfoDictionaryKey (bundleRef, CFSTR("CFBundleVersion"));
  24342. if (versionString != 0 && CFGetTypeID (versionString) == CFStringGetTypeID())
  24343. version = PlatformUtilities::cfStringToJuceString ((CFStringRef) versionString);
  24344. CFTypeRef manuString = CFBundleGetValueForInfoDictionaryKey (bundleRef, CFSTR("CFBundleGetInfoString"));
  24345. if (manuString != 0 && CFGetTypeID (manuString) == CFStringGetTypeID())
  24346. manufacturer = PlatformUtilities::cfStringToJuceString ((CFStringRef) manuString);
  24347. short resFileId = CFBundleOpenBundleResourceMap (bundleRef);
  24348. UseResFile (resFileId);
  24349. for (int i = 1; i <= Count1Resources ('thng'); ++i)
  24350. {
  24351. Handle h = Get1IndResource ('thng', i);
  24352. if (h != 0)
  24353. {
  24354. HLock (h);
  24355. const uint32* const types = (const uint32*) *h;
  24356. if (types[0] == kAudioUnitType_MusicDevice
  24357. || types[0] == kAudioUnitType_MusicEffect
  24358. || types[0] == kAudioUnitType_Effect
  24359. || types[0] == kAudioUnitType_Generator
  24360. || types[0] == kAudioUnitType_Panner)
  24361. {
  24362. componentDesc.componentType = types[0];
  24363. componentDesc.componentSubType = types[1];
  24364. componentDesc.componentManufacturer = types[2];
  24365. break;
  24366. }
  24367. HUnlock (h);
  24368. ReleaseResource (h);
  24369. }
  24370. }
  24371. CFBundleCloseBundleResourceMap (bundleRef, resFileId);
  24372. CFRelease (bundleRef);
  24373. }
  24374. }
  24375. return componentDesc.componentType != 0 && componentDesc.componentSubType != 0;
  24376. }
  24377. void AudioUnitPluginInstance::initialise()
  24378. {
  24379. if (initialised || audioUnit == 0)
  24380. return;
  24381. log (T("Initialising AU: ") + pluginName);
  24382. parameterIds.clear();
  24383. {
  24384. UInt32 paramListSize = 0;
  24385. AudioUnitGetProperty (audioUnit, kAudioUnitProperty_ParameterList, kAudioUnitScope_Global,
  24386. 0, 0, &paramListSize);
  24387. if (paramListSize > 0)
  24388. {
  24389. parameterIds.insertMultiple (0, 0, paramListSize / sizeof (int));
  24390. AudioUnitGetProperty (audioUnit, kAudioUnitProperty_ParameterList, kAudioUnitScope_Global,
  24391. 0, &parameterIds.getReference(0), &paramListSize);
  24392. }
  24393. }
  24394. {
  24395. AURenderCallbackStruct info;
  24396. zerostruct (info);
  24397. info.inputProcRefCon = this;
  24398. info.inputProc = renderGetInputCallback;
  24399. AudioUnitSetProperty (audioUnit, kAudioUnitProperty_SetRenderCallback, kAudioUnitScope_Input,
  24400. 0, &info, sizeof (info));
  24401. }
  24402. {
  24403. HostCallbackInfo info;
  24404. zerostruct (info);
  24405. info.hostUserData = this;
  24406. info.beatAndTempoProc = getBeatAndTempoCallback;
  24407. info.musicalTimeLocationProc = getMusicalTimeLocationCallback;
  24408. info.transportStateProc = getTransportStateCallback;
  24409. AudioUnitSetProperty (audioUnit, kAudioUnitProperty_HostCallbacks, kAudioUnitScope_Global,
  24410. 0, &info, sizeof (info));
  24411. }
  24412. int numIns, numOuts;
  24413. getNumChannels (numIns, numOuts);
  24414. setPlayConfigDetails (numIns, numOuts, 0, 0);
  24415. initialised = AudioUnitInitialize (audioUnit) == noErr;
  24416. setLatencySamples (0);
  24417. }
  24418. void AudioUnitPluginInstance::prepareToPlay (double sampleRate_,
  24419. int samplesPerBlockExpected)
  24420. {
  24421. initialise();
  24422. if (initialised)
  24423. {
  24424. int numIns, numOuts;
  24425. getNumChannels (numIns, numOuts);
  24426. setPlayConfigDetails (numIns, numOuts, sampleRate_, samplesPerBlockExpected);
  24427. Float64 latencySecs = 0.0;
  24428. UInt32 latencySize = sizeof (latencySecs);
  24429. AudioUnitGetProperty (audioUnit, kAudioUnitProperty_Latency, kAudioUnitScope_Global,
  24430. 0, &latencySecs, &latencySize);
  24431. setLatencySamples (roundToInt (latencySecs * sampleRate_));
  24432. AudioUnitReset (audioUnit, kAudioUnitScope_Input, 0);
  24433. AudioUnitReset (audioUnit, kAudioUnitScope_Output, 0);
  24434. AudioUnitReset (audioUnit, kAudioUnitScope_Global, 0);
  24435. AudioStreamBasicDescription stream;
  24436. zerostruct (stream);
  24437. stream.mSampleRate = sampleRate_;
  24438. stream.mFormatID = kAudioFormatLinearPCM;
  24439. stream.mFormatFlags = kAudioFormatFlagsNativeFloatPacked | kAudioFormatFlagIsNonInterleaved;
  24440. stream.mFramesPerPacket = 1;
  24441. stream.mBytesPerPacket = 4;
  24442. stream.mBytesPerFrame = 4;
  24443. stream.mBitsPerChannel = 32;
  24444. stream.mChannelsPerFrame = numIns;
  24445. OSStatus err = AudioUnitSetProperty (audioUnit,
  24446. kAudioUnitProperty_StreamFormat,
  24447. kAudioUnitScope_Input,
  24448. 0, &stream, sizeof (stream));
  24449. stream.mChannelsPerFrame = numOuts;
  24450. err = AudioUnitSetProperty (audioUnit,
  24451. kAudioUnitProperty_StreamFormat,
  24452. kAudioUnitScope_Output,
  24453. 0, &stream, sizeof (stream));
  24454. outputBufferList.calloc (sizeof (AudioBufferList) + sizeof (AudioBuffer) * (numOuts + 1), 1);
  24455. outputBufferList->mNumberBuffers = numOuts;
  24456. for (int i = numOuts; --i >= 0;)
  24457. outputBufferList->mBuffers[i].mNumberChannels = 1;
  24458. zerostruct (timeStamp);
  24459. timeStamp.mSampleTime = 0;
  24460. timeStamp.mHostTime = AudioGetCurrentHostTime();
  24461. timeStamp.mFlags = kAudioTimeStampSampleTimeValid | kAudioTimeStampHostTimeValid;
  24462. currentBuffer = 0;
  24463. wasPlaying = false;
  24464. }
  24465. }
  24466. void AudioUnitPluginInstance::releaseResources()
  24467. {
  24468. if (initialised)
  24469. {
  24470. AudioUnitReset (audioUnit, kAudioUnitScope_Input, 0);
  24471. AudioUnitReset (audioUnit, kAudioUnitScope_Output, 0);
  24472. AudioUnitReset (audioUnit, kAudioUnitScope_Global, 0);
  24473. outputBufferList.free();
  24474. currentBuffer = 0;
  24475. }
  24476. }
  24477. OSStatus AudioUnitPluginInstance::renderGetInput (AudioUnitRenderActionFlags* ioActionFlags,
  24478. const AudioTimeStamp* inTimeStamp,
  24479. UInt32 inBusNumber,
  24480. UInt32 inNumberFrames,
  24481. AudioBufferList* ioData) const
  24482. {
  24483. if (inBusNumber == 0
  24484. && currentBuffer != 0)
  24485. {
  24486. jassert (inNumberFrames == currentBuffer->getNumSamples()); // if this ever happens, might need to add extra handling
  24487. for (int i = 0; i < ioData->mNumberBuffers; ++i)
  24488. {
  24489. if (i < currentBuffer->getNumChannels())
  24490. {
  24491. memcpy (ioData->mBuffers[i].mData,
  24492. currentBuffer->getSampleData (i, 0),
  24493. sizeof (float) * inNumberFrames);
  24494. }
  24495. else
  24496. {
  24497. zeromem (ioData->mBuffers[i].mData, sizeof (float) * inNumberFrames);
  24498. }
  24499. }
  24500. }
  24501. return noErr;
  24502. }
  24503. void AudioUnitPluginInstance::processBlock (AudioSampleBuffer& buffer,
  24504. MidiBuffer& midiMessages)
  24505. {
  24506. const int numSamples = buffer.getNumSamples();
  24507. if (initialised)
  24508. {
  24509. AudioUnitRenderActionFlags flags = 0;
  24510. timeStamp.mHostTime = AudioGetCurrentHostTime();
  24511. for (int i = getNumOutputChannels(); --i >= 0;)
  24512. {
  24513. outputBufferList->mBuffers[i].mDataByteSize = sizeof (float) * numSamples;
  24514. outputBufferList->mBuffers[i].mData = buffer.getSampleData (i, 0);
  24515. }
  24516. currentBuffer = &buffer;
  24517. if (wantsMidiMessages)
  24518. {
  24519. const uint8* midiEventData;
  24520. int midiEventSize, midiEventPosition;
  24521. MidiBuffer::Iterator i (midiMessages);
  24522. while (i.getNextEvent (midiEventData, midiEventSize, midiEventPosition))
  24523. {
  24524. if (midiEventSize <= 3)
  24525. MusicDeviceMIDIEvent (audioUnit,
  24526. midiEventData[0], midiEventData[1], midiEventData[2],
  24527. midiEventPosition);
  24528. else
  24529. MusicDeviceSysEx (audioUnit, midiEventData, midiEventSize);
  24530. }
  24531. midiMessages.clear();
  24532. }
  24533. AudioUnitRender (audioUnit, &flags, &timeStamp,
  24534. 0, numSamples, outputBufferList);
  24535. timeStamp.mSampleTime += numSamples;
  24536. }
  24537. else
  24538. {
  24539. // Not initialised, so just bypass..
  24540. for (int i = getNumInputChannels(); i < getNumOutputChannels(); ++i)
  24541. buffer.clear (i, 0, buffer.getNumSamples());
  24542. }
  24543. }
  24544. OSStatus AudioUnitPluginInstance::getBeatAndTempo (Float64* outCurrentBeat, Float64* outCurrentTempo) const
  24545. {
  24546. AudioPlayHead* const ph = getPlayHead();
  24547. AudioPlayHead::CurrentPositionInfo result;
  24548. if (ph != 0 && ph->getCurrentPosition (result))
  24549. {
  24550. if (outCurrentBeat != 0)
  24551. *outCurrentBeat = result.ppqPosition;
  24552. if (outCurrentTempo != 0)
  24553. *outCurrentTempo = result.bpm;
  24554. }
  24555. else
  24556. {
  24557. if (outCurrentBeat != 0)
  24558. *outCurrentBeat = 0;
  24559. if (outCurrentTempo != 0)
  24560. *outCurrentTempo = 120.0;
  24561. }
  24562. return noErr;
  24563. }
  24564. OSStatus AudioUnitPluginInstance::getMusicalTimeLocation (UInt32* outDeltaSampleOffsetToNextBeat,
  24565. Float32* outTimeSig_Numerator,
  24566. UInt32* outTimeSig_Denominator,
  24567. Float64* outCurrentMeasureDownBeat) const
  24568. {
  24569. AudioPlayHead* const ph = getPlayHead();
  24570. AudioPlayHead::CurrentPositionInfo result;
  24571. if (ph != 0 && ph->getCurrentPosition (result))
  24572. {
  24573. if (outTimeSig_Numerator != 0)
  24574. *outTimeSig_Numerator = result.timeSigNumerator;
  24575. if (outTimeSig_Denominator != 0)
  24576. *outTimeSig_Denominator = result.timeSigDenominator;
  24577. if (outDeltaSampleOffsetToNextBeat != 0)
  24578. *outDeltaSampleOffsetToNextBeat = 0; //xxx
  24579. if (outCurrentMeasureDownBeat != 0)
  24580. *outCurrentMeasureDownBeat = result.ppqPositionOfLastBarStart; //xxx wrong
  24581. }
  24582. else
  24583. {
  24584. if (outDeltaSampleOffsetToNextBeat != 0)
  24585. *outDeltaSampleOffsetToNextBeat = 0;
  24586. if (outTimeSig_Numerator != 0)
  24587. *outTimeSig_Numerator = 4;
  24588. if (outTimeSig_Denominator != 0)
  24589. *outTimeSig_Denominator = 4;
  24590. if (outCurrentMeasureDownBeat != 0)
  24591. *outCurrentMeasureDownBeat = 0;
  24592. }
  24593. return noErr;
  24594. }
  24595. OSStatus AudioUnitPluginInstance::getTransportState (Boolean* outIsPlaying,
  24596. Boolean* outTransportStateChanged,
  24597. Float64* outCurrentSampleInTimeLine,
  24598. Boolean* outIsCycling,
  24599. Float64* outCycleStartBeat,
  24600. Float64* outCycleEndBeat)
  24601. {
  24602. AudioPlayHead* const ph = getPlayHead();
  24603. AudioPlayHead::CurrentPositionInfo result;
  24604. if (ph != 0 && ph->getCurrentPosition (result))
  24605. {
  24606. if (outIsPlaying != 0)
  24607. *outIsPlaying = result.isPlaying;
  24608. if (outTransportStateChanged != 0)
  24609. {
  24610. *outTransportStateChanged = result.isPlaying != wasPlaying;
  24611. wasPlaying = result.isPlaying;
  24612. }
  24613. if (outCurrentSampleInTimeLine != 0)
  24614. *outCurrentSampleInTimeLine = roundToInt (result.timeInSeconds * getSampleRate());
  24615. if (outIsCycling != 0)
  24616. *outIsCycling = false;
  24617. if (outCycleStartBeat != 0)
  24618. *outCycleStartBeat = 0;
  24619. if (outCycleEndBeat != 0)
  24620. *outCycleEndBeat = 0;
  24621. }
  24622. else
  24623. {
  24624. if (outIsPlaying != 0)
  24625. *outIsPlaying = false;
  24626. if (outTransportStateChanged != 0)
  24627. *outTransportStateChanged = false;
  24628. if (outCurrentSampleInTimeLine != 0)
  24629. *outCurrentSampleInTimeLine = 0;
  24630. if (outIsCycling != 0)
  24631. *outIsCycling = false;
  24632. if (outCycleStartBeat != 0)
  24633. *outCycleStartBeat = 0;
  24634. if (outCycleEndBeat != 0)
  24635. *outCycleEndBeat = 0;
  24636. }
  24637. return noErr;
  24638. }
  24639. static VoidArray activeWindows;
  24640. class AudioUnitPluginWindowCocoa : public AudioProcessorEditor
  24641. {
  24642. public:
  24643. AudioUnitPluginWindowCocoa (AudioUnitPluginInstance& plugin_, const bool createGenericViewIfNeeded)
  24644. : AudioProcessorEditor (&plugin_),
  24645. plugin (plugin_),
  24646. wrapper (0)
  24647. {
  24648. addAndMakeVisible (wrapper = new NSViewComponent());
  24649. activeWindows.add (this);
  24650. setOpaque (true);
  24651. setVisible (true);
  24652. setSize (100, 100);
  24653. createView (createGenericViewIfNeeded);
  24654. }
  24655. ~AudioUnitPluginWindowCocoa()
  24656. {
  24657. const bool wasValid = isValid();
  24658. wrapper->setView (0);
  24659. activeWindows.removeValue (this);
  24660. if (wasValid)
  24661. plugin.editorBeingDeleted (this);
  24662. delete wrapper;
  24663. }
  24664. bool isValid() const { return wrapper->getView() != 0; }
  24665. void paint (Graphics& g)
  24666. {
  24667. g.fillAll (Colours::white);
  24668. }
  24669. void resized()
  24670. {
  24671. wrapper->setSize (getWidth(), getHeight());
  24672. }
  24673. private:
  24674. AudioUnitPluginInstance& plugin;
  24675. NSViewComponent* wrapper;
  24676. bool createView (const bool createGenericViewIfNeeded)
  24677. {
  24678. NSView* pluginView = 0;
  24679. UInt32 dataSize = 0;
  24680. Boolean isWritable = false;
  24681. if (AudioUnitGetPropertyInfo (plugin.audioUnit, kAudioUnitProperty_CocoaUI, kAudioUnitScope_Global,
  24682. 0, &dataSize, &isWritable) == noErr
  24683. && dataSize != 0
  24684. && AudioUnitGetPropertyInfo (plugin.audioUnit, kAudioUnitProperty_CocoaUI, kAudioUnitScope_Global,
  24685. 0, &dataSize, &isWritable) == noErr)
  24686. {
  24687. HeapBlock <AudioUnitCocoaViewInfo> info;
  24688. info.calloc (dataSize, 1);
  24689. if (AudioUnitGetProperty (plugin.audioUnit, kAudioUnitProperty_CocoaUI, kAudioUnitScope_Global,
  24690. 0, info, &dataSize) == noErr)
  24691. {
  24692. NSString* viewClassName = (NSString*) (info->mCocoaAUViewClass[0]);
  24693. NSString* path = (NSString*) CFURLCopyPath (info->mCocoaAUViewBundleLocation);
  24694. NSBundle* viewBundle = [NSBundle bundleWithPath: [path autorelease]];
  24695. Class viewClass = [viewBundle classNamed: viewClassName];
  24696. if ([viewClass conformsToProtocol: @protocol (AUCocoaUIBase)]
  24697. && [viewClass instancesRespondToSelector: @selector (interfaceVersion)]
  24698. && [viewClass instancesRespondToSelector: @selector (uiViewForAudioUnit: withSize:)])
  24699. {
  24700. id factory = [[[viewClass alloc] init] autorelease];
  24701. pluginView = [factory uiViewForAudioUnit: plugin.audioUnit
  24702. withSize: NSMakeSize (getWidth(), getHeight())];
  24703. }
  24704. for (int i = (dataSize - sizeof (CFURLRef)) / sizeof (CFStringRef); --i >= 0;)
  24705. {
  24706. CFRelease (info->mCocoaAUViewClass[i]);
  24707. CFRelease (info->mCocoaAUViewBundleLocation);
  24708. }
  24709. }
  24710. }
  24711. if (createGenericViewIfNeeded && (pluginView == 0))
  24712. pluginView = [[AUGenericView alloc] initWithAudioUnit: plugin.audioUnit];
  24713. wrapper->setView (pluginView);
  24714. if (pluginView != 0)
  24715. setSize ([pluginView frame].size.width,
  24716. [pluginView frame].size.height);
  24717. return pluginView != 0;
  24718. }
  24719. };
  24720. #if JUCE_SUPPORT_CARBON
  24721. class AudioUnitPluginWindowCarbon : public AudioProcessorEditor
  24722. {
  24723. public:
  24724. AudioUnitPluginWindowCarbon (AudioUnitPluginInstance& plugin_)
  24725. : AudioProcessorEditor (&plugin_),
  24726. plugin (plugin_),
  24727. viewComponent (0)
  24728. {
  24729. addAndMakeVisible (innerWrapper = new InnerWrapperComponent (this));
  24730. activeWindows.add (this);
  24731. setOpaque (true);
  24732. setVisible (true);
  24733. setSize (400, 300);
  24734. ComponentDescription viewList [16];
  24735. UInt32 viewListSize = sizeof (viewList);
  24736. AudioUnitGetProperty (plugin.audioUnit, kAudioUnitProperty_GetUIComponentList, kAudioUnitScope_Global,
  24737. 0, &viewList, &viewListSize);
  24738. componentRecord = FindNextComponent (0, &viewList[0]);
  24739. }
  24740. ~AudioUnitPluginWindowCarbon()
  24741. {
  24742. deleteAndZero (innerWrapper);
  24743. activeWindows.removeValue (this);
  24744. if (isValid())
  24745. plugin.editorBeingDeleted (this);
  24746. }
  24747. bool isValid() const throw() { return componentRecord != 0; }
  24748. void paint (Graphics& g)
  24749. {
  24750. g.fillAll (Colours::black);
  24751. }
  24752. void resized()
  24753. {
  24754. innerWrapper->setSize (getWidth(), getHeight());
  24755. }
  24756. bool keyStateChanged (const bool)
  24757. {
  24758. return false;
  24759. }
  24760. bool keyPressed (const KeyPress&)
  24761. {
  24762. return false;
  24763. }
  24764. void broughtToFront()
  24765. {
  24766. activeWindows.removeValue (this);
  24767. activeWindows.add (this);
  24768. }
  24769. AudioUnit getAudioUnit() const { return plugin.audioUnit; }
  24770. AudioUnitCarbonView getViewComponent()
  24771. {
  24772. if (viewComponent == 0 && componentRecord != 0)
  24773. viewComponent = (AudioUnitCarbonView) OpenComponent (componentRecord);
  24774. return viewComponent;
  24775. }
  24776. void closeViewComponent()
  24777. {
  24778. if (viewComponent != 0)
  24779. {
  24780. CloseComponent (viewComponent);
  24781. viewComponent = 0;
  24782. }
  24783. }
  24784. juce_UseDebuggingNewOperator
  24785. private:
  24786. AudioUnitPluginInstance& plugin;
  24787. ComponentRecord* componentRecord;
  24788. AudioUnitCarbonView viewComponent;
  24789. class InnerWrapperComponent : public CarbonViewWrapperComponent
  24790. {
  24791. public:
  24792. InnerWrapperComponent (AudioUnitPluginWindowCarbon* const owner_)
  24793. : owner (owner_)
  24794. {
  24795. }
  24796. ~InnerWrapperComponent()
  24797. {
  24798. deleteWindow();
  24799. }
  24800. HIViewRef attachView (WindowRef windowRef, HIViewRef rootView)
  24801. {
  24802. log (T("Opening AU GUI: ") + owner->plugin.getName());
  24803. AudioUnitCarbonView viewComponent = owner->getViewComponent();
  24804. if (viewComponent == 0)
  24805. return 0;
  24806. Float32Point pos = { 0, 0 };
  24807. Float32Point size = { 250, 200 };
  24808. HIViewRef pluginView = 0;
  24809. AudioUnitCarbonViewCreate (viewComponent,
  24810. owner->getAudioUnit(),
  24811. windowRef,
  24812. rootView,
  24813. &pos,
  24814. &size,
  24815. (ControlRef*) &pluginView);
  24816. return pluginView;
  24817. }
  24818. void removeView (HIViewRef)
  24819. {
  24820. log (T("Closing AU GUI: ") + owner->plugin.getName());
  24821. owner->closeViewComponent();
  24822. }
  24823. private:
  24824. AudioUnitPluginWindowCarbon* const owner;
  24825. };
  24826. friend class InnerWrapperComponent;
  24827. InnerWrapperComponent* innerWrapper;
  24828. };
  24829. #endif
  24830. AudioProcessorEditor* AudioUnitPluginInstance::createEditor()
  24831. {
  24832. ScopedPointer <AudioProcessorEditor> w (new AudioUnitPluginWindowCocoa (*this, false));
  24833. if (! static_cast <AudioUnitPluginWindowCocoa*> (static_cast <AudioProcessorEditor*> (w))->isValid())
  24834. w = 0;
  24835. #if JUCE_SUPPORT_CARBON
  24836. if (w == 0)
  24837. {
  24838. w = new AudioUnitPluginWindowCarbon (*this);
  24839. if (! static_cast <AudioUnitPluginWindowCocoa*> (static_cast <AudioProcessorEditor*> (w))->isValid())
  24840. w = 0;
  24841. }
  24842. #endif
  24843. if (w == 0)
  24844. w = new AudioUnitPluginWindowCocoa (*this, true); // use AUGenericView as a fallback
  24845. return w.release();
  24846. }
  24847. const String AudioUnitPluginInstance::getCategory() const
  24848. {
  24849. const char* result = 0;
  24850. switch (componentDesc.componentType)
  24851. {
  24852. case kAudioUnitType_Effect:
  24853. case kAudioUnitType_MusicEffect:
  24854. result = "Effect";
  24855. break;
  24856. case kAudioUnitType_MusicDevice:
  24857. result = "Synth";
  24858. break;
  24859. case kAudioUnitType_Generator:
  24860. result = "Generator";
  24861. break;
  24862. case kAudioUnitType_Panner:
  24863. result = "Panner";
  24864. break;
  24865. default:
  24866. break;
  24867. }
  24868. return result;
  24869. }
  24870. int AudioUnitPluginInstance::getNumParameters()
  24871. {
  24872. return parameterIds.size();
  24873. }
  24874. float AudioUnitPluginInstance::getParameter (int index)
  24875. {
  24876. const ScopedLock sl (lock);
  24877. Float32 value = 0.0f;
  24878. if (audioUnit != 0 && ((unsigned int) index) < (unsigned int) parameterIds.size())
  24879. {
  24880. AudioUnitGetParameter (audioUnit,
  24881. (UInt32) parameterIds.getUnchecked (index),
  24882. kAudioUnitScope_Global, 0,
  24883. &value);
  24884. }
  24885. return value;
  24886. }
  24887. void AudioUnitPluginInstance::setParameter (int index, float newValue)
  24888. {
  24889. const ScopedLock sl (lock);
  24890. if (audioUnit != 0 && ((unsigned int) index) < (unsigned int) parameterIds.size())
  24891. {
  24892. AudioUnitSetParameter (audioUnit,
  24893. (UInt32) parameterIds.getUnchecked (index),
  24894. kAudioUnitScope_Global, 0,
  24895. newValue, 0);
  24896. }
  24897. }
  24898. const String AudioUnitPluginInstance::getParameterName (int index)
  24899. {
  24900. AudioUnitParameterInfo info;
  24901. zerostruct (info);
  24902. UInt32 sz = sizeof (info);
  24903. String name;
  24904. if (AudioUnitGetProperty (audioUnit,
  24905. kAudioUnitProperty_ParameterInfo,
  24906. kAudioUnitScope_Global,
  24907. parameterIds [index], &info, &sz) == noErr)
  24908. {
  24909. if ((info.flags & kAudioUnitParameterFlag_HasCFNameString) != 0)
  24910. name = PlatformUtilities::cfStringToJuceString (info.cfNameString);
  24911. else
  24912. name = String (info.name, sizeof (info.name));
  24913. }
  24914. return name;
  24915. }
  24916. const String AudioUnitPluginInstance::getParameterText (int index)
  24917. {
  24918. return String (getParameter (index));
  24919. }
  24920. bool AudioUnitPluginInstance::isParameterAutomatable (int index) const
  24921. {
  24922. AudioUnitParameterInfo info;
  24923. UInt32 sz = sizeof (info);
  24924. if (AudioUnitGetProperty (audioUnit,
  24925. kAudioUnitProperty_ParameterInfo,
  24926. kAudioUnitScope_Global,
  24927. parameterIds [index], &info, &sz) == noErr)
  24928. {
  24929. return (info.flags & kAudioUnitParameterFlag_NonRealTime) == 0;
  24930. }
  24931. return true;
  24932. }
  24933. int AudioUnitPluginInstance::getNumPrograms()
  24934. {
  24935. CFArrayRef presets;
  24936. UInt32 sz = sizeof (CFArrayRef);
  24937. int num = 0;
  24938. if (AudioUnitGetProperty (audioUnit,
  24939. kAudioUnitProperty_FactoryPresets,
  24940. kAudioUnitScope_Global,
  24941. 0, &presets, &sz) == noErr)
  24942. {
  24943. num = (int) CFArrayGetCount (presets);
  24944. CFRelease (presets);
  24945. }
  24946. return num;
  24947. }
  24948. int AudioUnitPluginInstance::getCurrentProgram()
  24949. {
  24950. AUPreset current;
  24951. current.presetNumber = 0;
  24952. UInt32 sz = sizeof (AUPreset);
  24953. AudioUnitGetProperty (audioUnit,
  24954. kAudioUnitProperty_FactoryPresets,
  24955. kAudioUnitScope_Global,
  24956. 0, &current, &sz);
  24957. return current.presetNumber;
  24958. }
  24959. void AudioUnitPluginInstance::setCurrentProgram (int newIndex)
  24960. {
  24961. AUPreset current;
  24962. current.presetNumber = newIndex;
  24963. current.presetName = 0;
  24964. AudioUnitSetProperty (audioUnit,
  24965. kAudioUnitProperty_FactoryPresets,
  24966. kAudioUnitScope_Global,
  24967. 0, &current, sizeof (AUPreset));
  24968. }
  24969. const String AudioUnitPluginInstance::getProgramName (int index)
  24970. {
  24971. String s;
  24972. CFArrayRef presets;
  24973. UInt32 sz = sizeof (CFArrayRef);
  24974. if (AudioUnitGetProperty (audioUnit,
  24975. kAudioUnitProperty_FactoryPresets,
  24976. kAudioUnitScope_Global,
  24977. 0, &presets, &sz) == noErr)
  24978. {
  24979. for (CFIndex i = 0; i < CFArrayGetCount (presets); ++i)
  24980. {
  24981. const AUPreset* p = (const AUPreset*) CFArrayGetValueAtIndex (presets, i);
  24982. if (p != 0 && p->presetNumber == index)
  24983. {
  24984. s = PlatformUtilities::cfStringToJuceString (p->presetName);
  24985. break;
  24986. }
  24987. }
  24988. CFRelease (presets);
  24989. }
  24990. return s;
  24991. }
  24992. void AudioUnitPluginInstance::changeProgramName (int index, const String& newName)
  24993. {
  24994. jassertfalse // xxx not implemented!
  24995. }
  24996. const String AudioUnitPluginInstance::getInputChannelName (const int index) const
  24997. {
  24998. if (((unsigned int) index) < (unsigned int) getNumInputChannels())
  24999. return T("Input ") + String (index + 1);
  25000. return String::empty;
  25001. }
  25002. bool AudioUnitPluginInstance::isInputChannelStereoPair (int index) const
  25003. {
  25004. if (((unsigned int) index) >= (unsigned int) getNumInputChannels())
  25005. return false;
  25006. return true;
  25007. }
  25008. const String AudioUnitPluginInstance::getOutputChannelName (const int index) const
  25009. {
  25010. if (((unsigned int) index) < (unsigned int) getNumOutputChannels())
  25011. return T("Output ") + String (index + 1);
  25012. return String::empty;
  25013. }
  25014. bool AudioUnitPluginInstance::isOutputChannelStereoPair (int index) const
  25015. {
  25016. if (((unsigned int) index) >= (unsigned int) getNumOutputChannels())
  25017. return false;
  25018. return true;
  25019. }
  25020. void AudioUnitPluginInstance::getStateInformation (MemoryBlock& destData)
  25021. {
  25022. getCurrentProgramStateInformation (destData);
  25023. }
  25024. void AudioUnitPluginInstance::getCurrentProgramStateInformation (MemoryBlock& destData)
  25025. {
  25026. CFPropertyListRef propertyList = 0;
  25027. UInt32 sz = sizeof (CFPropertyListRef);
  25028. if (AudioUnitGetProperty (audioUnit,
  25029. kAudioUnitProperty_ClassInfo,
  25030. kAudioUnitScope_Global,
  25031. 0, &propertyList, &sz) == noErr)
  25032. {
  25033. CFWriteStreamRef stream = CFWriteStreamCreateWithAllocatedBuffers (kCFAllocatorDefault, kCFAllocatorDefault);
  25034. CFWriteStreamOpen (stream);
  25035. CFIndex bytesWritten = CFPropertyListWriteToStream (propertyList, stream, kCFPropertyListBinaryFormat_v1_0, 0);
  25036. CFWriteStreamClose (stream);
  25037. CFDataRef data = (CFDataRef) CFWriteStreamCopyProperty (stream, kCFStreamPropertyDataWritten);
  25038. destData.setSize (bytesWritten);
  25039. destData.copyFrom (CFDataGetBytePtr (data), 0, destData.getSize());
  25040. CFRelease (data);
  25041. CFRelease (stream);
  25042. CFRelease (propertyList);
  25043. }
  25044. }
  25045. void AudioUnitPluginInstance::setStateInformation (const void* data, int sizeInBytes)
  25046. {
  25047. setCurrentProgramStateInformation (data, sizeInBytes);
  25048. }
  25049. void AudioUnitPluginInstance::setCurrentProgramStateInformation (const void* data, int sizeInBytes)
  25050. {
  25051. CFReadStreamRef stream = CFReadStreamCreateWithBytesNoCopy (kCFAllocatorDefault,
  25052. (const UInt8*) data,
  25053. sizeInBytes,
  25054. kCFAllocatorNull);
  25055. CFReadStreamOpen (stream);
  25056. CFPropertyListFormat format = kCFPropertyListBinaryFormat_v1_0;
  25057. CFPropertyListRef propertyList = CFPropertyListCreateFromStream (kCFAllocatorDefault,
  25058. stream,
  25059. 0,
  25060. kCFPropertyListImmutable,
  25061. &format,
  25062. 0);
  25063. CFRelease (stream);
  25064. if (propertyList != 0)
  25065. AudioUnitSetProperty (audioUnit,
  25066. kAudioUnitProperty_ClassInfo,
  25067. kAudioUnitScope_Global,
  25068. 0, &propertyList, sizeof (propertyList));
  25069. }
  25070. AudioUnitPluginFormat::AudioUnitPluginFormat()
  25071. {
  25072. }
  25073. AudioUnitPluginFormat::~AudioUnitPluginFormat()
  25074. {
  25075. }
  25076. void AudioUnitPluginFormat::findAllTypesForFile (OwnedArray <PluginDescription>& results,
  25077. const String& fileOrIdentifier)
  25078. {
  25079. if (! fileMightContainThisPluginType (fileOrIdentifier))
  25080. return;
  25081. PluginDescription desc;
  25082. desc.fileOrIdentifier = fileOrIdentifier;
  25083. desc.uid = 0;
  25084. try
  25085. {
  25086. ScopedPointer <AudioPluginInstance> createdInstance (createInstanceFromDescription (desc));
  25087. AudioUnitPluginInstance* const auInstance = dynamic_cast <AudioUnitPluginInstance*> ((AudioPluginInstance*) createdInstance);
  25088. if (auInstance != 0)
  25089. {
  25090. auInstance->fillInPluginDescription (desc);
  25091. results.add (new PluginDescription (desc));
  25092. }
  25093. }
  25094. catch (...)
  25095. {
  25096. // crashed while loading...
  25097. }
  25098. }
  25099. AudioPluginInstance* AudioUnitPluginFormat::createInstanceFromDescription (const PluginDescription& desc)
  25100. {
  25101. if (fileMightContainThisPluginType (desc.fileOrIdentifier))
  25102. {
  25103. ScopedPointer <AudioUnitPluginInstance> result (new AudioUnitPluginInstance (desc.fileOrIdentifier));
  25104. if (result->audioUnit != 0)
  25105. {
  25106. result->initialise();
  25107. return result.release();
  25108. }
  25109. }
  25110. return 0;
  25111. }
  25112. const StringArray AudioUnitPluginFormat::searchPathsForPlugins (const FileSearchPath& /*directoriesToSearch*/,
  25113. const bool /*recursive*/)
  25114. {
  25115. StringArray result;
  25116. ComponentRecord* comp = 0;
  25117. ComponentDescription desc;
  25118. zerostruct (desc);
  25119. for (;;)
  25120. {
  25121. zerostruct (desc);
  25122. comp = FindNextComponent (comp, &desc);
  25123. if (comp == 0)
  25124. break;
  25125. GetComponentInfo (comp, &desc, 0, 0, 0);
  25126. if (desc.componentType == kAudioUnitType_MusicDevice
  25127. || desc.componentType == kAudioUnitType_MusicEffect
  25128. || desc.componentType == kAudioUnitType_Effect
  25129. || desc.componentType == kAudioUnitType_Generator
  25130. || desc.componentType == kAudioUnitType_Panner)
  25131. {
  25132. const String s (createAUPluginIdentifier (desc));
  25133. DBG (s);
  25134. result.add (s);
  25135. }
  25136. }
  25137. return result;
  25138. }
  25139. bool AudioUnitPluginFormat::fileMightContainThisPluginType (const String& fileOrIdentifier)
  25140. {
  25141. ComponentDescription desc;
  25142. String name, version, manufacturer;
  25143. if (getComponentDescFromIdentifier (fileOrIdentifier, desc, name, version, manufacturer))
  25144. return FindNextComponent (0, &desc) != 0;
  25145. const File f (fileOrIdentifier);
  25146. return f.hasFileExtension (T(".component"))
  25147. && f.isDirectory();
  25148. }
  25149. const String AudioUnitPluginFormat::getNameOfPluginFromIdentifier (const String& fileOrIdentifier)
  25150. {
  25151. ComponentDescription desc;
  25152. String name, version, manufacturer;
  25153. getComponentDescFromIdentifier (fileOrIdentifier, desc, name, version, manufacturer);
  25154. if (name.isEmpty())
  25155. name = fileOrIdentifier;
  25156. return name;
  25157. }
  25158. bool AudioUnitPluginFormat::doesPluginStillExist (const PluginDescription& desc)
  25159. {
  25160. if (desc.fileOrIdentifier.startsWithIgnoreCase (auIdentifierPrefix))
  25161. return fileMightContainThisPluginType (desc.fileOrIdentifier);
  25162. else
  25163. return File (desc.fileOrIdentifier).exists();
  25164. }
  25165. const FileSearchPath AudioUnitPluginFormat::getDefaultLocationsToSearch()
  25166. {
  25167. return FileSearchPath ("/(Default AudioUnit locations)");
  25168. }
  25169. #endif
  25170. END_JUCE_NAMESPACE
  25171. #undef log
  25172. #endif
  25173. /*** End of inlined file: juce_AudioUnitPluginFormat.mm ***/
  25174. /*** Start of inlined file: juce_VSTPluginFormat.mm ***/
  25175. // This file just wraps juce_VSTPluginFormat.cpp in an objective-C wrapper
  25176. #define JUCE_MAC_VST_INCLUDED 1
  25177. /*** Start of inlined file: juce_VSTPluginFormat.cpp ***/
  25178. #if JUCE_PLUGINHOST_VST
  25179. #if (defined (_WIN32) || defined (_WIN64))
  25180. #undef _WIN32_WINNT
  25181. #define _WIN32_WINNT 0x500
  25182. #undef STRICT
  25183. #define STRICT
  25184. #include <windows.h>
  25185. #include <float.h>
  25186. #pragma warning (disable : 4312 4355)
  25187. #elif defined (LINUX) || defined (__linux__)
  25188. #include <float.h>
  25189. #include <sys/time.h>
  25190. #include <X11/Xlib.h>
  25191. #include <X11/Xutil.h>
  25192. #include <X11/Xatom.h>
  25193. #undef Font
  25194. #undef KeyPress
  25195. #undef Drawable
  25196. #undef Time
  25197. #else
  25198. #ifndef JUCE_MAC_VST_INCLUDED
  25199. // On the mac, this file needs to be compiled indirectly, by using
  25200. // juce_VSTPluginFormat.mm instead - that wraps it as an objective-C file for cocoa
  25201. #error
  25202. #endif
  25203. #include <Cocoa/Cocoa.h>
  25204. #include <Carbon/Carbon.h>
  25205. #endif
  25206. #if ! (JUCE_MAC && JUCE_64BIT)
  25207. BEGIN_JUCE_NAMESPACE
  25208. #if JUCE_MAC && JUCE_SUPPORT_CARBON
  25209. #endif
  25210. #undef PRAGMA_ALIGN_SUPPORTED
  25211. #define VST_FORCE_DEPRECATED 0
  25212. #ifdef _MSC_VER
  25213. #pragma warning (push)
  25214. #pragma warning (disable: 4996)
  25215. #endif
  25216. #include "pluginterfaces/vst2.x/aeffectx.h"
  25217. #ifdef _MSC_VER
  25218. #pragma warning (pop)
  25219. #endif
  25220. #if JUCE_LINUX
  25221. #define Font JUCE_NAMESPACE::Font
  25222. #define KeyPress JUCE_NAMESPACE::KeyPress
  25223. #define Drawable JUCE_NAMESPACE::Drawable
  25224. #define Time JUCE_NAMESPACE::Time
  25225. #endif
  25226. /*** Start of inlined file: juce_VSTMidiEventList.h ***/
  25227. #ifdef __aeffect__
  25228. #ifndef __JUCE_VSTMIDIEVENTLIST_JUCEHEADER__
  25229. #define __JUCE_VSTMIDIEVENTLIST_JUCEHEADER__
  25230. class VSTMidiEventList
  25231. {
  25232. public:
  25233. VSTMidiEventList()
  25234. : numEventsUsed (0), numEventsAllocated (0)
  25235. {
  25236. }
  25237. ~VSTMidiEventList()
  25238. {
  25239. freeEvents();
  25240. }
  25241. void clear()
  25242. {
  25243. numEventsUsed = 0;
  25244. if (events != 0)
  25245. events->numEvents = 0;
  25246. }
  25247. void addEvent (const void* const midiData, const int numBytes, const int frameOffset)
  25248. {
  25249. ensureSize (numEventsUsed + 1);
  25250. VstMidiEvent* const e = (VstMidiEvent*) (events->events [numEventsUsed]);
  25251. events->numEvents = ++numEventsUsed;
  25252. if (numBytes <= 4)
  25253. {
  25254. if (e->type == kVstSysExType)
  25255. {
  25256. juce_free (((VstMidiSysexEvent*) e)->sysexDump);
  25257. e->type = kVstMidiType;
  25258. e->byteSize = sizeof (VstMidiEvent);
  25259. e->noteLength = 0;
  25260. e->noteOffset = 0;
  25261. e->detune = 0;
  25262. e->noteOffVelocity = 0;
  25263. }
  25264. e->deltaFrames = frameOffset;
  25265. memcpy (e->midiData, midiData, numBytes);
  25266. }
  25267. else
  25268. {
  25269. VstMidiSysexEvent* const se = (VstMidiSysexEvent*) e;
  25270. if (se->type == kVstSysExType)
  25271. se->sysexDump = (char*) juce_realloc (se->sysexDump, numBytes);
  25272. else
  25273. se->sysexDump = (char*) juce_malloc (numBytes);
  25274. memcpy (se->sysexDump, midiData, numBytes);
  25275. se->type = kVstSysExType;
  25276. se->byteSize = sizeof (VstMidiSysexEvent);
  25277. se->deltaFrames = frameOffset;
  25278. se->flags = 0;
  25279. se->dumpBytes = numBytes;
  25280. se->resvd1 = 0;
  25281. se->resvd2 = 0;
  25282. }
  25283. }
  25284. // Handy method to pull the events out of an event buffer supplied by the host
  25285. // or plugin.
  25286. static void addEventsToMidiBuffer (const VstEvents* events, MidiBuffer& dest)
  25287. {
  25288. for (int i = 0; i < events->numEvents; ++i)
  25289. {
  25290. const VstEvent* const e = events->events[i];
  25291. if (e != 0)
  25292. {
  25293. if (e->type == kVstMidiType)
  25294. {
  25295. dest.addEvent ((const JUCE_NAMESPACE::uint8*) ((const VstMidiEvent*) e)->midiData,
  25296. 4, e->deltaFrames);
  25297. }
  25298. else if (e->type == kVstSysExType)
  25299. {
  25300. dest.addEvent ((const JUCE_NAMESPACE::uint8*) ((const VstMidiSysexEvent*) e)->sysexDump,
  25301. (int) ((const VstMidiSysexEvent*) e)->dumpBytes,
  25302. e->deltaFrames);
  25303. }
  25304. }
  25305. }
  25306. }
  25307. void ensureSize (int numEventsNeeded)
  25308. {
  25309. if (numEventsNeeded > numEventsAllocated)
  25310. {
  25311. numEventsNeeded = (numEventsNeeded + 32) & ~31;
  25312. const int size = 20 + sizeof (VstEvent*) * numEventsNeeded;
  25313. if (events == 0)
  25314. events.calloc (size, 1);
  25315. else
  25316. events.realloc (size, 1);
  25317. for (int i = numEventsAllocated; i < numEventsNeeded; ++i)
  25318. {
  25319. VstMidiEvent* const e = (VstMidiEvent*) juce_calloc (jmax ((int) sizeof (VstMidiEvent),
  25320. (int) sizeof (VstMidiSysexEvent)));
  25321. e->type = kVstMidiType;
  25322. e->byteSize = sizeof (VstMidiEvent);
  25323. events->events[i] = (VstEvent*) e;
  25324. }
  25325. numEventsAllocated = numEventsNeeded;
  25326. }
  25327. }
  25328. void freeEvents()
  25329. {
  25330. if (events != 0)
  25331. {
  25332. for (int i = numEventsAllocated; --i >= 0;)
  25333. {
  25334. VstMidiEvent* const e = (VstMidiEvent*) (events->events[i]);
  25335. if (e->type == kVstSysExType)
  25336. juce_free (((VstMidiSysexEvent*) e)->sysexDump);
  25337. juce_free (e);
  25338. }
  25339. events.free();
  25340. numEventsUsed = 0;
  25341. numEventsAllocated = 0;
  25342. }
  25343. }
  25344. HeapBlock <VstEvents> events;
  25345. private:
  25346. int numEventsUsed, numEventsAllocated;
  25347. };
  25348. #endif // __JUCE_VSTMIDIEVENTLIST_JUCEHEADER__
  25349. #endif // __JUCE_VSTMIDIEVENTLIST_JUCEHEADER__
  25350. /*** End of inlined file: juce_VSTMidiEventList.h ***/
  25351. #if ! JUCE_WIN32
  25352. static void _fpreset() {}
  25353. static void _clearfp() {}
  25354. #endif
  25355. extern void juce_callAnyTimersSynchronously();
  25356. const int fxbVersionNum = 1;
  25357. struct fxProgram
  25358. {
  25359. long chunkMagic; // 'CcnK'
  25360. long byteSize; // of this chunk, excl. magic + byteSize
  25361. long fxMagic; // 'FxCk'
  25362. long version;
  25363. long fxID; // fx unique id
  25364. long fxVersion;
  25365. long numParams;
  25366. char prgName[28];
  25367. float params[1]; // variable no. of parameters
  25368. };
  25369. struct fxSet
  25370. {
  25371. long chunkMagic; // 'CcnK'
  25372. long byteSize; // of this chunk, excl. magic + byteSize
  25373. long fxMagic; // 'FxBk'
  25374. long version;
  25375. long fxID; // fx unique id
  25376. long fxVersion;
  25377. long numPrograms;
  25378. char future[128];
  25379. fxProgram programs[1]; // variable no. of programs
  25380. };
  25381. struct fxChunkSet
  25382. {
  25383. long chunkMagic; // 'CcnK'
  25384. long byteSize; // of this chunk, excl. magic + byteSize
  25385. long fxMagic; // 'FxCh', 'FPCh', or 'FBCh'
  25386. long version;
  25387. long fxID; // fx unique id
  25388. long fxVersion;
  25389. long numPrograms;
  25390. char future[128];
  25391. long chunkSize;
  25392. char chunk[8]; // variable
  25393. };
  25394. struct fxProgramSet
  25395. {
  25396. long chunkMagic; // 'CcnK'
  25397. long byteSize; // of this chunk, excl. magic + byteSize
  25398. long fxMagic; // 'FxCh', 'FPCh', or 'FBCh'
  25399. long version;
  25400. long fxID; // fx unique id
  25401. long fxVersion;
  25402. long numPrograms;
  25403. char name[28];
  25404. long chunkSize;
  25405. char chunk[8]; // variable
  25406. };
  25407. static long vst_swap (const long x) throw()
  25408. {
  25409. #ifdef JUCE_LITTLE_ENDIAN
  25410. return (long) ByteOrder::swap ((uint32) x);
  25411. #else
  25412. return x;
  25413. #endif
  25414. }
  25415. static float vst_swapFloat (const float x) throw()
  25416. {
  25417. #ifdef JUCE_LITTLE_ENDIAN
  25418. union { uint32 asInt; float asFloat; } n;
  25419. n.asFloat = x;
  25420. n.asInt = ByteOrder::swap (n.asInt);
  25421. return n.asFloat;
  25422. #else
  25423. return x;
  25424. #endif
  25425. }
  25426. typedef AEffect* (*MainCall) (audioMasterCallback);
  25427. static VstIntPtr VSTCALLBACK audioMaster (AEffect* effect, VstInt32 opcode, VstInt32 index, VstIntPtr value, void* ptr, float opt);
  25428. static int shellUIDToCreate = 0;
  25429. static int insideVSTCallback = 0;
  25430. class VSTPluginWindow;
  25431. // Change this to disable logging of various VST activities
  25432. #ifndef VST_LOGGING
  25433. #define VST_LOGGING 1
  25434. #endif
  25435. #if VST_LOGGING
  25436. #define log(a) Logger::writeToLog(a);
  25437. #else
  25438. #define log(a)
  25439. #endif
  25440. #if JUCE_MAC && JUCE_PPC
  25441. static void* NewCFMFromMachO (void* const machofp) throw()
  25442. {
  25443. void* result = juce_malloc (8);
  25444. ((void**) result)[0] = machofp;
  25445. ((void**) result)[1] = result;
  25446. return result;
  25447. }
  25448. #endif
  25449. #if JUCE_LINUX
  25450. extern Display* display;
  25451. extern XContext improbableNumber;
  25452. typedef void (*EventProcPtr) (XEvent* ev);
  25453. static bool xErrorTriggered;
  25454. static int temporaryErrorHandler (Display*, XErrorEvent*)
  25455. {
  25456. xErrorTriggered = true;
  25457. return 0;
  25458. }
  25459. static int getPropertyFromXWindow (Window handle, Atom atom)
  25460. {
  25461. XErrorHandler oldErrorHandler = XSetErrorHandler (temporaryErrorHandler);
  25462. xErrorTriggered = false;
  25463. int userSize;
  25464. unsigned long bytes, userCount;
  25465. unsigned char* data;
  25466. Atom userType;
  25467. XGetWindowProperty (display, handle, atom, 0, 1, false, AnyPropertyType,
  25468. &userType, &userSize, &userCount, &bytes, &data);
  25469. XSetErrorHandler (oldErrorHandler);
  25470. return (userCount == 1 && ! xErrorTriggered) ? *(int*) data
  25471. : 0;
  25472. }
  25473. static Window getChildWindow (Window windowToCheck)
  25474. {
  25475. Window rootWindow, parentWindow;
  25476. Window* childWindows;
  25477. unsigned int numChildren;
  25478. XQueryTree (display,
  25479. windowToCheck,
  25480. &rootWindow,
  25481. &parentWindow,
  25482. &childWindows,
  25483. &numChildren);
  25484. if (numChildren > 0)
  25485. return childWindows [0];
  25486. return 0;
  25487. }
  25488. static void translateJuceToXButtonModifiers (const MouseEvent& e, XEvent& ev) throw()
  25489. {
  25490. if (e.mods.isLeftButtonDown())
  25491. {
  25492. ev.xbutton.button = Button1;
  25493. ev.xbutton.state |= Button1Mask;
  25494. }
  25495. else if (e.mods.isRightButtonDown())
  25496. {
  25497. ev.xbutton.button = Button3;
  25498. ev.xbutton.state |= Button3Mask;
  25499. }
  25500. else if (e.mods.isMiddleButtonDown())
  25501. {
  25502. ev.xbutton.button = Button2;
  25503. ev.xbutton.state |= Button2Mask;
  25504. }
  25505. }
  25506. static void translateJuceToXMotionModifiers (const MouseEvent& e, XEvent& ev) throw()
  25507. {
  25508. if (e.mods.isLeftButtonDown())
  25509. ev.xmotion.state |= Button1Mask;
  25510. else if (e.mods.isRightButtonDown())
  25511. ev.xmotion.state |= Button3Mask;
  25512. else if (e.mods.isMiddleButtonDown())
  25513. ev.xmotion.state |= Button2Mask;
  25514. }
  25515. static void translateJuceToXCrossingModifiers (const MouseEvent& e, XEvent& ev) throw()
  25516. {
  25517. if (e.mods.isLeftButtonDown())
  25518. ev.xcrossing.state |= Button1Mask;
  25519. else if (e.mods.isRightButtonDown())
  25520. ev.xcrossing.state |= Button3Mask;
  25521. else if (e.mods.isMiddleButtonDown())
  25522. ev.xcrossing.state |= Button2Mask;
  25523. }
  25524. static void translateJuceToXMouseWheelModifiers (const MouseEvent& e, const float increment, XEvent& ev) throw()
  25525. {
  25526. if (increment < 0)
  25527. {
  25528. ev.xbutton.button = Button5;
  25529. ev.xbutton.state |= Button5Mask;
  25530. }
  25531. else if (increment > 0)
  25532. {
  25533. ev.xbutton.button = Button4;
  25534. ev.xbutton.state |= Button4Mask;
  25535. }
  25536. }
  25537. #endif
  25538. static VoidArray activeModules;
  25539. class ModuleHandle : public ReferenceCountedObject
  25540. {
  25541. public:
  25542. File file;
  25543. MainCall moduleMain;
  25544. String pluginName;
  25545. static ModuleHandle* findOrCreateModule (const File& file)
  25546. {
  25547. for (int i = activeModules.size(); --i >= 0;)
  25548. {
  25549. ModuleHandle* const module = (ModuleHandle*) activeModules.getUnchecked(i);
  25550. if (module->file == file)
  25551. return module;
  25552. }
  25553. _fpreset(); // (doesn't do any harm)
  25554. ++insideVSTCallback;
  25555. shellUIDToCreate = 0;
  25556. log ("Attempting to load VST: " + file.getFullPathName());
  25557. ScopedPointer <ModuleHandle> m (new ModuleHandle (file));
  25558. if (! m->open())
  25559. m = 0;
  25560. --insideVSTCallback;
  25561. _fpreset(); // (doesn't do any harm)
  25562. return m.release();
  25563. }
  25564. ModuleHandle (const File& file_)
  25565. : file (file_),
  25566. moduleMain (0),
  25567. #if JUCE_WIN32 || JUCE_LINUX
  25568. hModule (0)
  25569. #elif JUCE_MAC
  25570. fragId (0),
  25571. resHandle (0),
  25572. bundleRef (0),
  25573. resFileId (0)
  25574. #endif
  25575. {
  25576. activeModules.add (this);
  25577. #if JUCE_WIN32 || JUCE_LINUX
  25578. fullParentDirectoryPathName = file_.getParentDirectory().getFullPathName();
  25579. #elif JUCE_MAC
  25580. FSRef ref;
  25581. PlatformUtilities::makeFSRefFromPath (&ref, file_.getParentDirectory().getFullPathName());
  25582. FSGetCatalogInfo (&ref, kFSCatInfoNone, 0, 0, &parentDirFSSpec, 0);
  25583. #endif
  25584. }
  25585. ~ModuleHandle()
  25586. {
  25587. activeModules.removeValue (this);
  25588. close();
  25589. }
  25590. juce_UseDebuggingNewOperator
  25591. #if JUCE_WIN32 || JUCE_LINUX
  25592. void* hModule;
  25593. String fullParentDirectoryPathName;
  25594. bool open()
  25595. {
  25596. #if JUCE_WIN32
  25597. static bool timePeriodSet = false;
  25598. if (! timePeriodSet)
  25599. {
  25600. timePeriodSet = true;
  25601. timeBeginPeriod (2);
  25602. }
  25603. #endif
  25604. pluginName = file.getFileNameWithoutExtension();
  25605. hModule = PlatformUtilities::loadDynamicLibrary (file.getFullPathName());
  25606. moduleMain = (MainCall) PlatformUtilities::getProcedureEntryPoint (hModule, "VSTPluginMain");
  25607. if (moduleMain == 0)
  25608. moduleMain = (MainCall) PlatformUtilities::getProcedureEntryPoint (hModule, "main");
  25609. return moduleMain != 0;
  25610. }
  25611. void close()
  25612. {
  25613. _fpreset(); // (doesn't do any harm)
  25614. PlatformUtilities::freeDynamicLibrary (hModule);
  25615. }
  25616. void closeEffect (AEffect* eff)
  25617. {
  25618. eff->dispatcher (eff, effClose, 0, 0, 0, 0);
  25619. }
  25620. #else
  25621. CFragConnectionID fragId;
  25622. Handle resHandle;
  25623. CFBundleRef bundleRef;
  25624. FSSpec parentDirFSSpec;
  25625. short resFileId;
  25626. bool open()
  25627. {
  25628. bool ok = false;
  25629. const String filename (file.getFullPathName());
  25630. if (file.hasFileExtension (T(".vst")))
  25631. {
  25632. const char* const utf8 = filename.toUTF8();
  25633. CFURLRef url = CFURLCreateFromFileSystemRepresentation (0, (const UInt8*) utf8,
  25634. strlen (utf8), file.isDirectory());
  25635. if (url != 0)
  25636. {
  25637. bundleRef = CFBundleCreate (kCFAllocatorDefault, url);
  25638. CFRelease (url);
  25639. if (bundleRef != 0)
  25640. {
  25641. if (CFBundleLoadExecutable (bundleRef))
  25642. {
  25643. moduleMain = (MainCall) CFBundleGetFunctionPointerForName (bundleRef, CFSTR("main_macho"));
  25644. if (moduleMain == 0)
  25645. moduleMain = (MainCall) CFBundleGetFunctionPointerForName (bundleRef, CFSTR("VSTPluginMain"));
  25646. if (moduleMain != 0)
  25647. {
  25648. CFTypeRef name = CFBundleGetValueForInfoDictionaryKey (bundleRef, CFSTR("CFBundleName"));
  25649. if (name != 0)
  25650. {
  25651. if (CFGetTypeID (name) == CFStringGetTypeID())
  25652. {
  25653. char buffer[1024];
  25654. if (CFStringGetCString ((CFStringRef) name, buffer, sizeof (buffer), CFStringGetSystemEncoding()))
  25655. pluginName = buffer;
  25656. }
  25657. }
  25658. if (pluginName.isEmpty())
  25659. pluginName = file.getFileNameWithoutExtension();
  25660. resFileId = CFBundleOpenBundleResourceMap (bundleRef);
  25661. ok = true;
  25662. }
  25663. }
  25664. if (! ok)
  25665. {
  25666. CFBundleUnloadExecutable (bundleRef);
  25667. CFRelease (bundleRef);
  25668. bundleRef = 0;
  25669. }
  25670. }
  25671. }
  25672. }
  25673. #if JUCE_PPC
  25674. else
  25675. {
  25676. FSRef fn;
  25677. if (FSPathMakeRef ((UInt8*) filename.toUTF8(), &fn, 0) == noErr)
  25678. {
  25679. resFileId = FSOpenResFile (&fn, fsRdPerm);
  25680. if (resFileId != -1)
  25681. {
  25682. const int numEffs = Count1Resources ('aEff');
  25683. for (int i = 0; i < numEffs; ++i)
  25684. {
  25685. resHandle = Get1IndResource ('aEff', i + 1);
  25686. if (resHandle != 0)
  25687. {
  25688. OSType type;
  25689. Str255 name;
  25690. SInt16 id;
  25691. GetResInfo (resHandle, &id, &type, name);
  25692. pluginName = String ((const char*) name + 1, name[0]);
  25693. DetachResource (resHandle);
  25694. HLock (resHandle);
  25695. Ptr ptr;
  25696. Str255 errorText;
  25697. OSErr err = GetMemFragment (*resHandle, GetHandleSize (resHandle),
  25698. name, kPrivateCFragCopy,
  25699. &fragId, &ptr, errorText);
  25700. if (err == noErr)
  25701. {
  25702. moduleMain = (MainCall) newMachOFromCFM (ptr);
  25703. ok = true;
  25704. }
  25705. else
  25706. {
  25707. HUnlock (resHandle);
  25708. }
  25709. break;
  25710. }
  25711. }
  25712. if (! ok)
  25713. CloseResFile (resFileId);
  25714. }
  25715. }
  25716. }
  25717. #endif
  25718. return ok;
  25719. }
  25720. void close()
  25721. {
  25722. #if JUCE_PPC
  25723. if (fragId != 0)
  25724. {
  25725. if (moduleMain != 0)
  25726. disposeMachOFromCFM ((void*) moduleMain);
  25727. CloseConnection (&fragId);
  25728. HUnlock (resHandle);
  25729. if (resFileId != 0)
  25730. CloseResFile (resFileId);
  25731. }
  25732. else
  25733. #endif
  25734. if (bundleRef != 0)
  25735. {
  25736. CFBundleCloseBundleResourceMap (bundleRef, resFileId);
  25737. if (CFGetRetainCount (bundleRef) == 1)
  25738. CFBundleUnloadExecutable (bundleRef);
  25739. if (CFGetRetainCount (bundleRef) > 0)
  25740. CFRelease (bundleRef);
  25741. }
  25742. }
  25743. void closeEffect (AEffect* eff)
  25744. {
  25745. #if JUCE_PPC
  25746. if (fragId != 0)
  25747. {
  25748. VoidArray thingsToDelete;
  25749. thingsToDelete.add ((void*) eff->dispatcher);
  25750. thingsToDelete.add ((void*) eff->process);
  25751. thingsToDelete.add ((void*) eff->setParameter);
  25752. thingsToDelete.add ((void*) eff->getParameter);
  25753. thingsToDelete.add ((void*) eff->processReplacing);
  25754. eff->dispatcher (eff, effClose, 0, 0, 0, 0);
  25755. for (int i = thingsToDelete.size(); --i >= 0;)
  25756. disposeMachOFromCFM (thingsToDelete[i]);
  25757. }
  25758. else
  25759. #endif
  25760. {
  25761. eff->dispatcher (eff, effClose, 0, 0, 0, 0);
  25762. }
  25763. }
  25764. #if JUCE_PPC
  25765. static void* newMachOFromCFM (void* cfmfp)
  25766. {
  25767. if (cfmfp == 0)
  25768. return 0;
  25769. UInt32* const mfp = (UInt32*) juce_malloc (sizeof (UInt32) * 6);
  25770. mfp[0] = 0x3d800000 | ((UInt32) cfmfp >> 16);
  25771. mfp[1] = 0x618c0000 | ((UInt32) cfmfp & 0xffff);
  25772. mfp[2] = 0x800c0000;
  25773. mfp[3] = 0x804c0004;
  25774. mfp[4] = 0x7c0903a6;
  25775. mfp[5] = 0x4e800420;
  25776. MakeDataExecutable (mfp, sizeof (UInt32) * 6);
  25777. return mfp;
  25778. }
  25779. static void disposeMachOFromCFM (void* ptr)
  25780. {
  25781. juce_free (ptr);
  25782. }
  25783. void coerceAEffectFunctionCalls (AEffect* eff)
  25784. {
  25785. if (fragId != 0)
  25786. {
  25787. eff->dispatcher = (AEffectDispatcherProc) newMachOFromCFM ((void*) eff->dispatcher);
  25788. eff->process = (AEffectProcessProc) newMachOFromCFM ((void*) eff->process);
  25789. eff->setParameter = (AEffectSetParameterProc) newMachOFromCFM ((void*) eff->setParameter);
  25790. eff->getParameter = (AEffectGetParameterProc) newMachOFromCFM ((void*) eff->getParameter);
  25791. eff->processReplacing = (AEffectProcessProc) newMachOFromCFM ((void*) eff->processReplacing);
  25792. }
  25793. }
  25794. #endif
  25795. #endif
  25796. };
  25797. class VSTPluginInstance : public AudioPluginInstance,
  25798. private Timer,
  25799. private AsyncUpdater
  25800. {
  25801. public:
  25802. ~VSTPluginInstance();
  25803. // AudioPluginInstance methods:
  25804. void fillInPluginDescription (PluginDescription& desc) const
  25805. {
  25806. desc.name = name;
  25807. desc.fileOrIdentifier = module->file.getFullPathName();
  25808. desc.uid = getUID();
  25809. desc.lastFileModTime = module->file.getLastModificationTime();
  25810. desc.pluginFormatName = "VST";
  25811. desc.category = getCategory();
  25812. {
  25813. char buffer [kVstMaxVendorStrLen + 8];
  25814. zerostruct (buffer);
  25815. dispatch (effGetVendorString, 0, 0, buffer, 0);
  25816. desc.manufacturerName = buffer;
  25817. }
  25818. desc.version = getVersion();
  25819. desc.numInputChannels = getNumInputChannels();
  25820. desc.numOutputChannels = getNumOutputChannels();
  25821. desc.isInstrument = (effect != 0 && (effect->flags & effFlagsIsSynth) != 0);
  25822. }
  25823. const String getName() const { return name; }
  25824. int getUID() const throw();
  25825. bool acceptsMidi() const { return wantsMidiMessages; }
  25826. bool producesMidi() const { return dispatch (effCanDo, 0, 0, (void*) "sendVstMidiEvent", 0) > 0; }
  25827. // AudioProcessor methods:
  25828. void prepareToPlay (double sampleRate, int estimatedSamplesPerBlock);
  25829. void releaseResources();
  25830. void processBlock (AudioSampleBuffer& buffer,
  25831. MidiBuffer& midiMessages);
  25832. AudioProcessorEditor* createEditor();
  25833. const String getInputChannelName (const int index) const;
  25834. bool isInputChannelStereoPair (int index) const;
  25835. const String getOutputChannelName (const int index) const;
  25836. bool isOutputChannelStereoPair (int index) const;
  25837. int getNumParameters() { return effect != 0 ? effect->numParams : 0; }
  25838. float getParameter (int index);
  25839. void setParameter (int index, float newValue);
  25840. const String getParameterName (int index);
  25841. const String getParameterText (int index);
  25842. bool isParameterAutomatable (int index) const;
  25843. int getNumPrograms() { return effect != 0 ? effect->numPrograms : 0; }
  25844. int getCurrentProgram() { return dispatch (effGetProgram, 0, 0, 0, 0); }
  25845. void setCurrentProgram (int index);
  25846. const String getProgramName (int index);
  25847. void changeProgramName (int index, const String& newName);
  25848. void getStateInformation (MemoryBlock& destData);
  25849. void getCurrentProgramStateInformation (MemoryBlock& destData);
  25850. void setStateInformation (const void* data, int sizeInBytes);
  25851. void setCurrentProgramStateInformation (const void* data, int sizeInBytes);
  25852. void timerCallback();
  25853. void handleAsyncUpdate();
  25854. VstIntPtr handleCallback (VstInt32 opcode, VstInt32 index, VstInt32 value, void *ptr, float opt);
  25855. juce_UseDebuggingNewOperator
  25856. private:
  25857. friend class VSTPluginWindow;
  25858. friend class VSTPluginFormat;
  25859. AEffect* effect;
  25860. String name;
  25861. CriticalSection lock;
  25862. bool wantsMidiMessages, initialised, isPowerOn;
  25863. mutable StringArray programNames;
  25864. AudioSampleBuffer tempBuffer;
  25865. CriticalSection midiInLock;
  25866. MidiBuffer incomingMidi;
  25867. VSTMidiEventList midiEventsToSend;
  25868. VstTimeInfo vstHostTime;
  25869. HeapBlock <float*> channels;
  25870. ReferenceCountedObjectPtr <ModuleHandle> module;
  25871. int dispatch (const int opcode, const int index, const int value, void* const ptr, float opt) const;
  25872. bool restoreProgramSettings (const fxProgram* const prog);
  25873. const String getCurrentProgramName();
  25874. void setParamsInProgramBlock (fxProgram* const prog) throw();
  25875. void updateStoredProgramNames();
  25876. void initialise();
  25877. void handleMidiFromPlugin (const VstEvents* const events);
  25878. void createTempParameterStore (MemoryBlock& dest);
  25879. void restoreFromTempParameterStore (const MemoryBlock& mb);
  25880. const String getParameterLabel (int index) const;
  25881. bool usesChunks() const throw() { return effect != 0 && (effect->flags & effFlagsProgramChunks) != 0; }
  25882. void getChunkData (MemoryBlock& mb, bool isPreset, int maxSizeMB) const;
  25883. void setChunkData (const char* data, int size, bool isPreset);
  25884. bool loadFromFXBFile (const void* data, int numBytes);
  25885. bool saveToFXBFile (MemoryBlock& dest, bool isFXB, int maxSizeMB);
  25886. int getVersionNumber() const throw() { return effect != 0 ? effect->version : 0; }
  25887. const String getVersion() const throw();
  25888. const String getCategory() const throw();
  25889. bool hasEditor() const throw() { return effect != 0 && (effect->flags & effFlagsHasEditor) != 0; }
  25890. void setPower (const bool on);
  25891. VSTPluginInstance (const ReferenceCountedObjectPtr <ModuleHandle>& module);
  25892. };
  25893. VSTPluginInstance::VSTPluginInstance (const ReferenceCountedObjectPtr <ModuleHandle>& module_)
  25894. : effect (0),
  25895. wantsMidiMessages (false),
  25896. initialised (false),
  25897. isPowerOn (false),
  25898. tempBuffer (1, 1),
  25899. module (module_)
  25900. {
  25901. try
  25902. {
  25903. _fpreset();
  25904. ++insideVSTCallback;
  25905. name = module->pluginName;
  25906. log (T("Creating VST instance: ") + name);
  25907. #if JUCE_MAC
  25908. if (module->resFileId != 0)
  25909. UseResFile (module->resFileId);
  25910. #if JUCE_PPC
  25911. if (module->fragId != 0)
  25912. {
  25913. static void* audioMasterCoerced = 0;
  25914. if (audioMasterCoerced == 0)
  25915. audioMasterCoerced = NewCFMFromMachO ((void*) &audioMaster);
  25916. effect = module->moduleMain ((audioMasterCallback) audioMasterCoerced);
  25917. }
  25918. else
  25919. #endif
  25920. #endif
  25921. {
  25922. effect = module->moduleMain (&audioMaster);
  25923. }
  25924. --insideVSTCallback;
  25925. if (effect != 0 && effect->magic == kEffectMagic)
  25926. {
  25927. #if JUCE_PPC
  25928. module->coerceAEffectFunctionCalls (effect);
  25929. #endif
  25930. jassert (effect->resvd2 == 0);
  25931. jassert (effect->object != 0);
  25932. _fpreset(); // some dodgy plugs fuck around with this
  25933. }
  25934. else
  25935. {
  25936. effect = 0;
  25937. }
  25938. }
  25939. catch (...)
  25940. {
  25941. --insideVSTCallback;
  25942. }
  25943. }
  25944. VSTPluginInstance::~VSTPluginInstance()
  25945. {
  25946. {
  25947. const ScopedLock sl (lock);
  25948. jassert (insideVSTCallback == 0);
  25949. if (effect != 0 && effect->magic == kEffectMagic)
  25950. {
  25951. try
  25952. {
  25953. #if JUCE_MAC
  25954. if (module->resFileId != 0)
  25955. UseResFile (module->resFileId);
  25956. #endif
  25957. // Must delete any editors before deleting the plugin instance!
  25958. jassert (getActiveEditor() == 0);
  25959. _fpreset(); // some dodgy plugs fuck around with this
  25960. module->closeEffect (effect);
  25961. }
  25962. catch (...)
  25963. {}
  25964. }
  25965. module = 0;
  25966. effect = 0;
  25967. }
  25968. }
  25969. void VSTPluginInstance::initialise()
  25970. {
  25971. if (initialised || effect == 0)
  25972. return;
  25973. log (T("Initialising VST: ") + module->pluginName);
  25974. initialised = true;
  25975. dispatch (effIdentify, 0, 0, 0, 0);
  25976. // this code would ask the plugin for its name, but so few plugins
  25977. // actually bother implementing this correctly, that it's better to
  25978. // just ignore it and use the file name instead.
  25979. if (getSampleRate() > 0)
  25980. dispatch (effSetSampleRate, 0, 0, 0, (float) getSampleRate());
  25981. if (getBlockSize() > 0)
  25982. dispatch (effSetBlockSize, 0, jmax (32, getBlockSize()), 0, 0);
  25983. dispatch (effOpen, 0, 0, 0, 0);
  25984. setPlayConfigDetails (effect->numInputs, effect->numOutputs,
  25985. getSampleRate(), getBlockSize());
  25986. if (getNumPrograms() > 1)
  25987. setCurrentProgram (0);
  25988. else
  25989. dispatch (effSetProgram, 0, 0, 0, 0);
  25990. int i;
  25991. for (i = effect->numInputs; --i >= 0;)
  25992. dispatch (effConnectInput, i, 1, 0, 0);
  25993. for (i = effect->numOutputs; --i >= 0;)
  25994. dispatch (effConnectOutput, i, 1, 0, 0);
  25995. updateStoredProgramNames();
  25996. wantsMidiMessages = dispatch (effCanDo, 0, 0, (void*) "receiveVstMidiEvent", 0) > 0;
  25997. setLatencySamples (effect->initialDelay);
  25998. }
  25999. void VSTPluginInstance::prepareToPlay (double sampleRate_,
  26000. int samplesPerBlockExpected)
  26001. {
  26002. setPlayConfigDetails (effect->numInputs, effect->numOutputs,
  26003. sampleRate_, samplesPerBlockExpected);
  26004. setLatencySamples (effect->initialDelay);
  26005. channels.calloc (jmax (16, getNumOutputChannels(), getNumInputChannels()) + 2);
  26006. vstHostTime.tempo = 120.0;
  26007. vstHostTime.timeSigNumerator = 4;
  26008. vstHostTime.timeSigDenominator = 4;
  26009. vstHostTime.sampleRate = sampleRate_;
  26010. vstHostTime.samplePos = 0;
  26011. vstHostTime.flags = kVstNanosValid; /*| kVstTransportPlaying | kVstTempoValid | kVstTimeSigValid*/;
  26012. initialise();
  26013. if (initialised)
  26014. {
  26015. wantsMidiMessages = wantsMidiMessages
  26016. || (dispatch (effCanDo, 0, 0, (void*) "receiveVstMidiEvent", 0) > 0);
  26017. if (wantsMidiMessages)
  26018. midiEventsToSend.ensureSize (256);
  26019. else
  26020. midiEventsToSend.freeEvents();
  26021. incomingMidi.clear();
  26022. dispatch (effSetSampleRate, 0, 0, 0, (float) sampleRate_);
  26023. dispatch (effSetBlockSize, 0, jmax (16, samplesPerBlockExpected), 0, 0);
  26024. tempBuffer.setSize (jmax (1, effect->numOutputs), samplesPerBlockExpected);
  26025. if (! isPowerOn)
  26026. setPower (true);
  26027. // dodgy hack to force some plugins to initialise the sample rate..
  26028. if ((! hasEditor()) && getNumParameters() > 0)
  26029. {
  26030. const float old = getParameter (0);
  26031. setParameter (0, (old < 0.5f) ? 1.0f : 0.0f);
  26032. setParameter (0, old);
  26033. }
  26034. dispatch (effStartProcess, 0, 0, 0, 0);
  26035. }
  26036. }
  26037. void VSTPluginInstance::releaseResources()
  26038. {
  26039. if (initialised)
  26040. {
  26041. dispatch (effStopProcess, 0, 0, 0, 0);
  26042. setPower (false);
  26043. }
  26044. tempBuffer.setSize (1, 1);
  26045. incomingMidi.clear();
  26046. midiEventsToSend.freeEvents();
  26047. channels.free();
  26048. }
  26049. void VSTPluginInstance::processBlock (AudioSampleBuffer& buffer,
  26050. MidiBuffer& midiMessages)
  26051. {
  26052. const int numSamples = buffer.getNumSamples();
  26053. if (initialised)
  26054. {
  26055. AudioPlayHead* playHead = getPlayHead();
  26056. if (playHead != 0)
  26057. {
  26058. AudioPlayHead::CurrentPositionInfo position;
  26059. playHead->getCurrentPosition (position);
  26060. vstHostTime.tempo = position.bpm;
  26061. vstHostTime.timeSigNumerator = position.timeSigNumerator;
  26062. vstHostTime.timeSigDenominator = position.timeSigDenominator;
  26063. vstHostTime.ppqPos = position.ppqPosition;
  26064. vstHostTime.barStartPos = position.ppqPositionOfLastBarStart;
  26065. vstHostTime.flags |= kVstTempoValid | kVstTimeSigValid | kVstPpqPosValid | kVstBarsValid;
  26066. if (position.isPlaying)
  26067. vstHostTime.flags |= kVstTransportPlaying;
  26068. else
  26069. vstHostTime.flags &= ~kVstTransportPlaying;
  26070. }
  26071. #if JUCE_WIN32
  26072. vstHostTime.nanoSeconds = timeGetTime() * 1000000.0;
  26073. #elif JUCE_LINUX
  26074. timeval micro;
  26075. gettimeofday (&micro, 0);
  26076. vstHostTime.nanoSeconds = micro.tv_usec * 1000.0;
  26077. #elif JUCE_MAC
  26078. UnsignedWide micro;
  26079. Microseconds (&micro);
  26080. vstHostTime.nanoSeconds = micro.lo * 1000.0;
  26081. #endif
  26082. if (wantsMidiMessages)
  26083. {
  26084. midiEventsToSend.clear();
  26085. midiEventsToSend.ensureSize (1);
  26086. MidiBuffer::Iterator iter (midiMessages);
  26087. const uint8* midiData;
  26088. int numBytesOfMidiData, samplePosition;
  26089. while (iter.getNextEvent (midiData, numBytesOfMidiData, samplePosition))
  26090. {
  26091. midiEventsToSend.addEvent (midiData, numBytesOfMidiData,
  26092. jlimit (0, numSamples - 1, samplePosition));
  26093. }
  26094. try
  26095. {
  26096. effect->dispatcher (effect, effProcessEvents, 0, 0, midiEventsToSend.events, 0);
  26097. }
  26098. catch (...)
  26099. {}
  26100. }
  26101. int i;
  26102. const int maxChans = jmax (effect->numInputs, effect->numOutputs);
  26103. for (i = 0; i < maxChans; ++i)
  26104. channels[i] = buffer.getSampleData (i);
  26105. channels [maxChans] = 0;
  26106. _clearfp();
  26107. if ((effect->flags & effFlagsCanReplacing) != 0)
  26108. {
  26109. try
  26110. {
  26111. effect->processReplacing (effect, channels, channels, numSamples);
  26112. }
  26113. catch (...)
  26114. {}
  26115. }
  26116. else
  26117. {
  26118. tempBuffer.setSize (effect->numOutputs, numSamples);
  26119. tempBuffer.clear();
  26120. float* outs [64];
  26121. for (i = effect->numOutputs; --i >= 0;)
  26122. outs[i] = tempBuffer.getSampleData (i);
  26123. outs [effect->numOutputs] = 0;
  26124. try
  26125. {
  26126. effect->process (effect, channels, outs, numSamples);
  26127. }
  26128. catch (...)
  26129. {}
  26130. for (i = effect->numOutputs; --i >= 0;)
  26131. buffer.copyFrom (i, 0, outs[i], numSamples);
  26132. }
  26133. }
  26134. else
  26135. {
  26136. // Not initialised, so just bypass..
  26137. for (int i = getNumInputChannels(); i < getNumOutputChannels(); ++i)
  26138. buffer.clear (i, 0, buffer.getNumSamples());
  26139. }
  26140. {
  26141. // copy any incoming midi..
  26142. const ScopedLock sl (midiInLock);
  26143. midiMessages = incomingMidi;
  26144. incomingMidi.clear();
  26145. }
  26146. }
  26147. void VSTPluginInstance::handleMidiFromPlugin (const VstEvents* const events)
  26148. {
  26149. if (events != 0)
  26150. {
  26151. const ScopedLock sl (midiInLock);
  26152. VSTMidiEventList::addEventsToMidiBuffer (events, incomingMidi);
  26153. }
  26154. }
  26155. static Array <VSTPluginWindow*> activeVSTWindows;
  26156. class VSTPluginWindow : public AudioProcessorEditor,
  26157. #if ! JUCE_MAC
  26158. public ComponentMovementWatcher,
  26159. #endif
  26160. public Timer
  26161. {
  26162. public:
  26163. VSTPluginWindow (VSTPluginInstance& plugin_)
  26164. : AudioProcessorEditor (&plugin_),
  26165. #if ! JUCE_MAC
  26166. ComponentMovementWatcher (this),
  26167. #endif
  26168. plugin (plugin_),
  26169. isOpen (false),
  26170. wasShowing (false),
  26171. pluginRefusesToResize (false),
  26172. pluginWantsKeys (false),
  26173. alreadyInside (false),
  26174. recursiveResize (false)
  26175. {
  26176. #if JUCE_WIN32
  26177. sizeCheckCount = 0;
  26178. pluginHWND = 0;
  26179. #elif JUCE_LINUX
  26180. pluginWindow = None;
  26181. pluginProc = None;
  26182. #else
  26183. addAndMakeVisible (innerWrapper = new InnerWrapperComponent (this));
  26184. #endif
  26185. activeVSTWindows.add (this);
  26186. setSize (1, 1);
  26187. setOpaque (true);
  26188. setVisible (true);
  26189. }
  26190. ~VSTPluginWindow()
  26191. {
  26192. #if JUCE_MAC
  26193. innerWrapper = 0;
  26194. #else
  26195. closePluginWindow();
  26196. #endif
  26197. activeVSTWindows.removeValue (this);
  26198. plugin.editorBeingDeleted (this);
  26199. }
  26200. #if ! JUCE_MAC
  26201. void componentMovedOrResized (bool /*wasMoved*/, bool /*wasResized*/)
  26202. {
  26203. if (recursiveResize)
  26204. return;
  26205. Component* const topComp = getTopLevelComponent();
  26206. if (topComp->getPeer() != 0)
  26207. {
  26208. const Point<int> pos (relativePositionToOtherComponent (topComp, Point<int>()));
  26209. recursiveResize = true;
  26210. #if JUCE_WIN32
  26211. if (pluginHWND != 0)
  26212. MoveWindow (pluginHWND, pos.getX(), pos.getY(), getWidth(), getHeight(), TRUE);
  26213. #elif JUCE_LINUX
  26214. if (pluginWindow != 0)
  26215. {
  26216. XResizeWindow (display, pluginWindow, getWidth(), getHeight());
  26217. XMoveWindow (display, pluginWindow, pos.getX(), pos.getY());
  26218. XMapRaised (display, pluginWindow);
  26219. }
  26220. #endif
  26221. recursiveResize = false;
  26222. }
  26223. }
  26224. void componentVisibilityChanged (Component&)
  26225. {
  26226. const bool isShowingNow = isShowing();
  26227. if (wasShowing != isShowingNow)
  26228. {
  26229. wasShowing = isShowingNow;
  26230. if (isShowingNow)
  26231. openPluginWindow();
  26232. else
  26233. closePluginWindow();
  26234. }
  26235. componentMovedOrResized (true, true);
  26236. }
  26237. void componentPeerChanged()
  26238. {
  26239. closePluginWindow();
  26240. openPluginWindow();
  26241. }
  26242. #endif
  26243. bool keyStateChanged (const bool)
  26244. {
  26245. return pluginWantsKeys;
  26246. }
  26247. bool keyPressed (const KeyPress&)
  26248. {
  26249. return pluginWantsKeys;
  26250. }
  26251. #if JUCE_MAC
  26252. void paint (Graphics& g)
  26253. {
  26254. g.fillAll (Colours::black);
  26255. }
  26256. #else
  26257. void paint (Graphics& g)
  26258. {
  26259. if (isOpen)
  26260. {
  26261. ComponentPeer* const peer = getPeer();
  26262. if (peer != 0)
  26263. {
  26264. const Point<int> pos (getScreenPosition() - peer->getScreenPosition());
  26265. peer->addMaskedRegion (pos.getX(), pos.getY(), getWidth(), getHeight());
  26266. #if JUCE_LINUX
  26267. if (pluginWindow != 0)
  26268. {
  26269. const Rectangle<int> clip (g.getClipBounds());
  26270. XEvent ev;
  26271. zerostruct (ev);
  26272. ev.xexpose.type = Expose;
  26273. ev.xexpose.display = display;
  26274. ev.xexpose.window = pluginWindow;
  26275. ev.xexpose.x = clip.getX();
  26276. ev.xexpose.y = clip.getY();
  26277. ev.xexpose.width = clip.getWidth();
  26278. ev.xexpose.height = clip.getHeight();
  26279. sendEventToChild (&ev);
  26280. }
  26281. #endif
  26282. }
  26283. }
  26284. else
  26285. {
  26286. g.fillAll (Colours::black);
  26287. }
  26288. }
  26289. #endif
  26290. void timerCallback()
  26291. {
  26292. #if JUCE_WIN32
  26293. if (--sizeCheckCount <= 0)
  26294. {
  26295. sizeCheckCount = 10;
  26296. checkPluginWindowSize();
  26297. }
  26298. #endif
  26299. try
  26300. {
  26301. static bool reentrant = false;
  26302. if (! reentrant)
  26303. {
  26304. reentrant = true;
  26305. plugin.dispatch (effEditIdle, 0, 0, 0, 0);
  26306. reentrant = false;
  26307. }
  26308. }
  26309. catch (...)
  26310. {}
  26311. }
  26312. void mouseDown (const MouseEvent& e)
  26313. {
  26314. #if JUCE_LINUX
  26315. if (pluginWindow == 0)
  26316. return;
  26317. toFront (true);
  26318. XEvent ev;
  26319. zerostruct (ev);
  26320. ev.xbutton.display = display;
  26321. ev.xbutton.type = ButtonPress;
  26322. ev.xbutton.window = pluginWindow;
  26323. ev.xbutton.root = RootWindow (display, DefaultScreen (display));
  26324. ev.xbutton.time = CurrentTime;
  26325. ev.xbutton.x = e.x;
  26326. ev.xbutton.y = e.y;
  26327. ev.xbutton.x_root = e.getScreenX();
  26328. ev.xbutton.y_root = e.getScreenY();
  26329. translateJuceToXButtonModifiers (e, ev);
  26330. sendEventToChild (&ev);
  26331. #elif JUCE_WIN32
  26332. (void) e;
  26333. toFront (true);
  26334. #endif
  26335. }
  26336. void broughtToFront()
  26337. {
  26338. activeVSTWindows.removeValue (this);
  26339. activeVSTWindows.add (this);
  26340. #if JUCE_MAC
  26341. dispatch (effEditTop, 0, 0, 0, 0);
  26342. #endif
  26343. }
  26344. juce_UseDebuggingNewOperator
  26345. private:
  26346. VSTPluginInstance& plugin;
  26347. bool isOpen, wasShowing, recursiveResize;
  26348. bool pluginWantsKeys, pluginRefusesToResize, alreadyInside;
  26349. #if JUCE_WIN32
  26350. HWND pluginHWND;
  26351. void* originalWndProc;
  26352. int sizeCheckCount;
  26353. #elif JUCE_LINUX
  26354. Window pluginWindow;
  26355. EventProcPtr pluginProc;
  26356. #endif
  26357. #if JUCE_MAC
  26358. void openPluginWindow (WindowRef parentWindow)
  26359. {
  26360. if (isOpen || parentWindow == 0)
  26361. return;
  26362. isOpen = true;
  26363. ERect* rect = 0;
  26364. dispatch (effEditGetRect, 0, 0, &rect, 0);
  26365. dispatch (effEditOpen, 0, 0, parentWindow, 0);
  26366. // do this before and after like in the steinberg example
  26367. dispatch (effEditGetRect, 0, 0, &rect, 0);
  26368. dispatch (effGetProgram, 0, 0, 0, 0); // also in steinberg code
  26369. // Install keyboard hooks
  26370. pluginWantsKeys = (dispatch (effKeysRequired, 0, 0, 0, 0) == 0);
  26371. // double-check it's not too tiny
  26372. int w = 250, h = 150;
  26373. if (rect != 0)
  26374. {
  26375. w = rect->right - rect->left;
  26376. h = rect->bottom - rect->top;
  26377. if (w == 0 || h == 0)
  26378. {
  26379. w = 250;
  26380. h = 150;
  26381. }
  26382. }
  26383. w = jmax (w, 32);
  26384. h = jmax (h, 32);
  26385. setSize (w, h);
  26386. startTimer (18 + JUCE_NAMESPACE::Random::getSystemRandom().nextInt (5));
  26387. repaint();
  26388. }
  26389. #else
  26390. void openPluginWindow()
  26391. {
  26392. if (isOpen || getWindowHandle() == 0)
  26393. return;
  26394. log (T("Opening VST UI: ") + plugin.name);
  26395. isOpen = true;
  26396. ERect* rect = 0;
  26397. dispatch (effEditGetRect, 0, 0, &rect, 0);
  26398. dispatch (effEditOpen, 0, 0, getWindowHandle(), 0);
  26399. // do this before and after like in the steinberg example
  26400. dispatch (effEditGetRect, 0, 0, &rect, 0);
  26401. dispatch (effGetProgram, 0, 0, 0, 0); // also in steinberg code
  26402. // Install keyboard hooks
  26403. pluginWantsKeys = (dispatch (effKeysRequired, 0, 0, 0, 0) == 0);
  26404. #if JUCE_WIN32
  26405. originalWndProc = 0;
  26406. pluginHWND = GetWindow ((HWND) getWindowHandle(), GW_CHILD);
  26407. if (pluginHWND == 0)
  26408. {
  26409. isOpen = false;
  26410. setSize (300, 150);
  26411. return;
  26412. }
  26413. #pragma warning (push)
  26414. #pragma warning (disable: 4244)
  26415. originalWndProc = (void*) GetWindowLongPtr (pluginHWND, GWL_WNDPROC);
  26416. if (! pluginWantsKeys)
  26417. SetWindowLongPtr (pluginHWND, GWL_WNDPROC, (LONG_PTR) vstHookWndProc);
  26418. #pragma warning (pop)
  26419. int w, h;
  26420. RECT r;
  26421. GetWindowRect (pluginHWND, &r);
  26422. w = r.right - r.left;
  26423. h = r.bottom - r.top;
  26424. if (rect != 0)
  26425. {
  26426. const int rw = rect->right - rect->left;
  26427. const int rh = rect->bottom - rect->top;
  26428. if ((rw > 50 && rh > 50 && rw < 2000 && rh < 2000 && rw != w && rh != h)
  26429. || ((w == 0 && rw > 0) || (h == 0 && rh > 0)))
  26430. {
  26431. // very dodgy logic to decide which size is right.
  26432. if (abs (rw - w) > 350 || abs (rh - h) > 350)
  26433. {
  26434. SetWindowPos (pluginHWND, 0,
  26435. 0, 0, rw, rh,
  26436. SWP_NOMOVE | SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOZORDER);
  26437. GetWindowRect (pluginHWND, &r);
  26438. w = r.right - r.left;
  26439. h = r.bottom - r.top;
  26440. pluginRefusesToResize = (w != rw) || (h != rh);
  26441. w = rw;
  26442. h = rh;
  26443. }
  26444. }
  26445. }
  26446. #elif JUCE_LINUX
  26447. pluginWindow = getChildWindow ((Window) getWindowHandle());
  26448. if (pluginWindow != 0)
  26449. pluginProc = (EventProcPtr) getPropertyFromXWindow (pluginWindow,
  26450. XInternAtom (display, "_XEventProc", False));
  26451. int w = 250, h = 150;
  26452. if (rect != 0)
  26453. {
  26454. w = rect->right - rect->left;
  26455. h = rect->bottom - rect->top;
  26456. if (w == 0 || h == 0)
  26457. {
  26458. w = 250;
  26459. h = 150;
  26460. }
  26461. }
  26462. if (pluginWindow != 0)
  26463. XMapRaised (display, pluginWindow);
  26464. #endif
  26465. // double-check it's not too tiny
  26466. w = jmax (w, 32);
  26467. h = jmax (h, 32);
  26468. setSize (w, h);
  26469. #if JUCE_WIN32
  26470. checkPluginWindowSize();
  26471. #endif
  26472. startTimer (18 + JUCE_NAMESPACE::Random::getSystemRandom().nextInt (5));
  26473. repaint();
  26474. }
  26475. #endif
  26476. #if ! JUCE_MAC
  26477. void closePluginWindow()
  26478. {
  26479. if (isOpen)
  26480. {
  26481. log (T("Closing VST UI: ") + plugin.getName());
  26482. isOpen = false;
  26483. dispatch (effEditClose, 0, 0, 0, 0);
  26484. #if JUCE_WIN32
  26485. #pragma warning (push)
  26486. #pragma warning (disable: 4244)
  26487. if (pluginHWND != 0 && IsWindow (pluginHWND))
  26488. SetWindowLongPtr (pluginHWND, GWL_WNDPROC, (LONG_PTR) originalWndProc);
  26489. #pragma warning (pop)
  26490. stopTimer();
  26491. if (pluginHWND != 0 && IsWindow (pluginHWND))
  26492. DestroyWindow (pluginHWND);
  26493. pluginHWND = 0;
  26494. #elif JUCE_LINUX
  26495. stopTimer();
  26496. pluginWindow = 0;
  26497. pluginProc = 0;
  26498. #endif
  26499. }
  26500. }
  26501. #endif
  26502. int dispatch (const int opcode, const int index, const int value, void* const ptr, float opt)
  26503. {
  26504. return plugin.dispatch (opcode, index, value, ptr, opt);
  26505. }
  26506. #if JUCE_WIN32
  26507. void checkPluginWindowSize() throw()
  26508. {
  26509. RECT r;
  26510. GetWindowRect (pluginHWND, &r);
  26511. const int w = r.right - r.left;
  26512. const int h = r.bottom - r.top;
  26513. if (isShowing() && w > 0 && h > 0
  26514. && (w != getWidth() || h != getHeight())
  26515. && ! pluginRefusesToResize)
  26516. {
  26517. setSize (w, h);
  26518. sizeCheckCount = 0;
  26519. }
  26520. }
  26521. // hooks to get keyboard events from VST windows..
  26522. static LRESULT CALLBACK vstHookWndProc (HWND hW, UINT message, WPARAM wParam, LPARAM lParam)
  26523. {
  26524. for (int i = activeVSTWindows.size(); --i >= 0;)
  26525. {
  26526. const VSTPluginWindow* const w = (const VSTPluginWindow*) activeVSTWindows.getUnchecked (i);
  26527. if (w->pluginHWND == hW)
  26528. {
  26529. if (message == WM_CHAR
  26530. || message == WM_KEYDOWN
  26531. || message == WM_SYSKEYDOWN
  26532. || message == WM_KEYUP
  26533. || message == WM_SYSKEYUP
  26534. || message == WM_APPCOMMAND)
  26535. {
  26536. SendMessage ((HWND) w->getTopLevelComponent()->getWindowHandle(),
  26537. message, wParam, lParam);
  26538. }
  26539. return CallWindowProc ((WNDPROC) (w->originalWndProc),
  26540. (HWND) w->pluginHWND,
  26541. message,
  26542. wParam,
  26543. lParam);
  26544. }
  26545. }
  26546. return DefWindowProc (hW, message, wParam, lParam);
  26547. }
  26548. #endif
  26549. #if JUCE_LINUX
  26550. // overload mouse/keyboard events to forward them to the plugin's inner window..
  26551. void sendEventToChild (XEvent* event)
  26552. {
  26553. if (pluginProc != 0)
  26554. {
  26555. // if the plugin publishes an event procedure, pass the event directly..
  26556. pluginProc (event);
  26557. }
  26558. else if (pluginWindow != 0)
  26559. {
  26560. // if the plugin has a window, then send the event to the window so that
  26561. // its message thread will pick it up..
  26562. XSendEvent (display, pluginWindow, False, 0L, event);
  26563. XFlush (display);
  26564. }
  26565. }
  26566. void mouseEnter (const MouseEvent& e)
  26567. {
  26568. if (pluginWindow != 0)
  26569. {
  26570. XEvent ev;
  26571. zerostruct (ev);
  26572. ev.xcrossing.display = display;
  26573. ev.xcrossing.type = EnterNotify;
  26574. ev.xcrossing.window = pluginWindow;
  26575. ev.xcrossing.root = RootWindow (display, DefaultScreen (display));
  26576. ev.xcrossing.time = CurrentTime;
  26577. ev.xcrossing.x = e.x;
  26578. ev.xcrossing.y = e.y;
  26579. ev.xcrossing.x_root = e.getScreenX();
  26580. ev.xcrossing.y_root = e.getScreenY();
  26581. ev.xcrossing.mode = NotifyNormal; // NotifyGrab, NotifyUngrab
  26582. ev.xcrossing.detail = NotifyAncestor; // NotifyVirtual, NotifyInferior, NotifyNonlinear,NotifyNonlinearVirtual
  26583. translateJuceToXCrossingModifiers (e, ev);
  26584. sendEventToChild (&ev);
  26585. }
  26586. }
  26587. void mouseExit (const MouseEvent& e)
  26588. {
  26589. if (pluginWindow != 0)
  26590. {
  26591. XEvent ev;
  26592. zerostruct (ev);
  26593. ev.xcrossing.display = display;
  26594. ev.xcrossing.type = LeaveNotify;
  26595. ev.xcrossing.window = pluginWindow;
  26596. ev.xcrossing.root = RootWindow (display, DefaultScreen (display));
  26597. ev.xcrossing.time = CurrentTime;
  26598. ev.xcrossing.x = e.x;
  26599. ev.xcrossing.y = e.y;
  26600. ev.xcrossing.x_root = e.getScreenX();
  26601. ev.xcrossing.y_root = e.getScreenY();
  26602. ev.xcrossing.mode = NotifyNormal; // NotifyGrab, NotifyUngrab
  26603. ev.xcrossing.detail = NotifyAncestor; // NotifyVirtual, NotifyInferior, NotifyNonlinear,NotifyNonlinearVirtual
  26604. ev.xcrossing.focus = hasKeyboardFocus (true); // TODO - yes ?
  26605. translateJuceToXCrossingModifiers (e, ev);
  26606. sendEventToChild (&ev);
  26607. }
  26608. }
  26609. void mouseMove (const MouseEvent& e)
  26610. {
  26611. if (pluginWindow != 0)
  26612. {
  26613. XEvent ev;
  26614. zerostruct (ev);
  26615. ev.xmotion.display = display;
  26616. ev.xmotion.type = MotionNotify;
  26617. ev.xmotion.window = pluginWindow;
  26618. ev.xmotion.root = RootWindow (display, DefaultScreen (display));
  26619. ev.xmotion.time = CurrentTime;
  26620. ev.xmotion.is_hint = NotifyNormal;
  26621. ev.xmotion.x = e.x;
  26622. ev.xmotion.y = e.y;
  26623. ev.xmotion.x_root = e.getScreenX();
  26624. ev.xmotion.y_root = e.getScreenY();
  26625. sendEventToChild (&ev);
  26626. }
  26627. }
  26628. void mouseDrag (const MouseEvent& e)
  26629. {
  26630. if (pluginWindow != 0)
  26631. {
  26632. XEvent ev;
  26633. zerostruct (ev);
  26634. ev.xmotion.display = display;
  26635. ev.xmotion.type = MotionNotify;
  26636. ev.xmotion.window = pluginWindow;
  26637. ev.xmotion.root = RootWindow (display, DefaultScreen (display));
  26638. ev.xmotion.time = CurrentTime;
  26639. ev.xmotion.x = e.x ;
  26640. ev.xmotion.y = e.y;
  26641. ev.xmotion.x_root = e.getScreenX();
  26642. ev.xmotion.y_root = e.getScreenY();
  26643. ev.xmotion.is_hint = NotifyNormal;
  26644. translateJuceToXMotionModifiers (e, ev);
  26645. sendEventToChild (&ev);
  26646. }
  26647. }
  26648. void mouseUp (const MouseEvent& e)
  26649. {
  26650. if (pluginWindow != 0)
  26651. {
  26652. XEvent ev;
  26653. zerostruct (ev);
  26654. ev.xbutton.display = display;
  26655. ev.xbutton.type = ButtonRelease;
  26656. ev.xbutton.window = pluginWindow;
  26657. ev.xbutton.root = RootWindow (display, DefaultScreen (display));
  26658. ev.xbutton.time = CurrentTime;
  26659. ev.xbutton.x = e.x;
  26660. ev.xbutton.y = e.y;
  26661. ev.xbutton.x_root = e.getScreenX();
  26662. ev.xbutton.y_root = e.getScreenY();
  26663. translateJuceToXButtonModifiers (e, ev);
  26664. sendEventToChild (&ev);
  26665. }
  26666. }
  26667. void mouseWheelMove (const MouseEvent& e,
  26668. float incrementX,
  26669. float incrementY)
  26670. {
  26671. if (pluginWindow != 0)
  26672. {
  26673. XEvent ev;
  26674. zerostruct (ev);
  26675. ev.xbutton.display = display;
  26676. ev.xbutton.type = ButtonPress;
  26677. ev.xbutton.window = pluginWindow;
  26678. ev.xbutton.root = RootWindow (display, DefaultScreen (display));
  26679. ev.xbutton.time = CurrentTime;
  26680. ev.xbutton.x = e.x;
  26681. ev.xbutton.y = e.y;
  26682. ev.xbutton.x_root = e.getScreenX();
  26683. ev.xbutton.y_root = e.getScreenY();
  26684. translateJuceToXMouseWheelModifiers (e, incrementY, ev);
  26685. sendEventToChild (&ev);
  26686. // TODO - put a usleep here ?
  26687. ev.xbutton.type = ButtonRelease;
  26688. sendEventToChild (&ev);
  26689. }
  26690. }
  26691. #endif
  26692. #if JUCE_MAC
  26693. #if ! JUCE_SUPPORT_CARBON
  26694. #error "To build VSTs, you need to enable the JUCE_SUPPORT_CARBON flag in your config!"
  26695. #endif
  26696. class InnerWrapperComponent : public CarbonViewWrapperComponent
  26697. {
  26698. public:
  26699. InnerWrapperComponent (VSTPluginWindow* const owner_)
  26700. : owner (owner_),
  26701. alreadyInside (false)
  26702. {
  26703. }
  26704. ~InnerWrapperComponent()
  26705. {
  26706. deleteWindow();
  26707. }
  26708. HIViewRef attachView (WindowRef windowRef, HIViewRef rootView)
  26709. {
  26710. owner->openPluginWindow (windowRef);
  26711. return 0;
  26712. }
  26713. void removeView (HIViewRef)
  26714. {
  26715. owner->dispatch (effEditClose, 0, 0, 0, 0);
  26716. owner->dispatch (effEditSleep, 0, 0, 0, 0);
  26717. }
  26718. bool getEmbeddedViewSize (int& w, int& h)
  26719. {
  26720. ERect* rect = 0;
  26721. owner->dispatch (effEditGetRect, 0, 0, &rect, 0);
  26722. w = rect->right - rect->left;
  26723. h = rect->bottom - rect->top;
  26724. return true;
  26725. }
  26726. void mouseDown (int x, int y)
  26727. {
  26728. if (! alreadyInside)
  26729. {
  26730. alreadyInside = true;
  26731. getTopLevelComponent()->toFront (true);
  26732. owner->dispatch (effEditMouse, x, y, 0, 0);
  26733. alreadyInside = false;
  26734. }
  26735. else
  26736. {
  26737. PostEvent (::mouseDown, 0);
  26738. }
  26739. }
  26740. void paint()
  26741. {
  26742. ComponentPeer* const peer = getPeer();
  26743. if (peer != 0)
  26744. {
  26745. const Point<int> pos (getScreenPosition() - peer->getScreenPosition());
  26746. ERect r;
  26747. r.left = pos.getX();
  26748. r.right = r.left + getWidth();
  26749. r.top = pos.getY();
  26750. r.bottom = r.top + getHeight();
  26751. owner->dispatch (effEditDraw, 0, 0, &r, 0);
  26752. }
  26753. }
  26754. private:
  26755. VSTPluginWindow* const owner;
  26756. bool alreadyInside;
  26757. };
  26758. friend class InnerWrapperComponent;
  26759. ScopedPointer <InnerWrapperComponent> innerWrapper;
  26760. void resized()
  26761. {
  26762. innerWrapper->setSize (getWidth(), getHeight());
  26763. }
  26764. #endif
  26765. };
  26766. AudioProcessorEditor* VSTPluginInstance::createEditor()
  26767. {
  26768. if (hasEditor())
  26769. return new VSTPluginWindow (*this);
  26770. return 0;
  26771. }
  26772. void VSTPluginInstance::handleAsyncUpdate()
  26773. {
  26774. // indicates that something about the plugin has changed..
  26775. updateHostDisplay();
  26776. }
  26777. bool VSTPluginInstance::restoreProgramSettings (const fxProgram* const prog)
  26778. {
  26779. if (vst_swap (prog->chunkMagic) == 'CcnK' && vst_swap (prog->fxMagic) == 'FxCk')
  26780. {
  26781. changeProgramName (getCurrentProgram(), prog->prgName);
  26782. for (int i = 0; i < vst_swap (prog->numParams); ++i)
  26783. setParameter (i, vst_swapFloat (prog->params[i]));
  26784. return true;
  26785. }
  26786. return false;
  26787. }
  26788. bool VSTPluginInstance::loadFromFXBFile (const void* const data,
  26789. const int dataSize)
  26790. {
  26791. if (dataSize < 28)
  26792. return false;
  26793. const fxSet* const set = (const fxSet*) data;
  26794. if ((vst_swap (set->chunkMagic) != 'CcnK' && vst_swap (set->chunkMagic) != 'KncC')
  26795. || vst_swap (set->version) > fxbVersionNum)
  26796. return false;
  26797. if (vst_swap (set->fxMagic) == 'FxBk')
  26798. {
  26799. // bank of programs
  26800. if (vst_swap (set->numPrograms) >= 0)
  26801. {
  26802. const int oldProg = getCurrentProgram();
  26803. const int numParams = vst_swap (((const fxProgram*) (set->programs))->numParams);
  26804. const int progLen = sizeof (fxProgram) + (numParams - 1) * sizeof (float);
  26805. for (int i = 0; i < vst_swap (set->numPrograms); ++i)
  26806. {
  26807. if (i != oldProg)
  26808. {
  26809. const fxProgram* const prog = (const fxProgram*) (((const char*) (set->programs)) + i * progLen);
  26810. if (((const char*) prog) - ((const char*) set) >= dataSize)
  26811. return false;
  26812. if (vst_swap (set->numPrograms) > 0)
  26813. setCurrentProgram (i);
  26814. if (! restoreProgramSettings (prog))
  26815. return false;
  26816. }
  26817. }
  26818. if (vst_swap (set->numPrograms) > 0)
  26819. setCurrentProgram (oldProg);
  26820. const fxProgram* const prog = (const fxProgram*) (((const char*) (set->programs)) + oldProg * progLen);
  26821. if (((const char*) prog) - ((const char*) set) >= dataSize)
  26822. return false;
  26823. if (! restoreProgramSettings (prog))
  26824. return false;
  26825. }
  26826. }
  26827. else if (vst_swap (set->fxMagic) == 'FxCk')
  26828. {
  26829. // single program
  26830. const fxProgram* const prog = (const fxProgram*) data;
  26831. if (vst_swap (prog->chunkMagic) != 'CcnK')
  26832. return false;
  26833. changeProgramName (getCurrentProgram(), prog->prgName);
  26834. for (int i = 0; i < vst_swap (prog->numParams); ++i)
  26835. setParameter (i, vst_swapFloat (prog->params[i]));
  26836. }
  26837. else if (vst_swap (set->fxMagic) == 'FBCh' || vst_swap (set->fxMagic) == 'hCBF')
  26838. {
  26839. // non-preset chunk
  26840. const fxChunkSet* const cset = (const fxChunkSet*) data;
  26841. if (vst_swap (cset->chunkSize) + sizeof (fxChunkSet) - 8 > (unsigned int) dataSize)
  26842. return false;
  26843. setChunkData (cset->chunk, vst_swap (cset->chunkSize), false);
  26844. }
  26845. else if (vst_swap (set->fxMagic) == 'FPCh' || vst_swap (set->fxMagic) == 'hCPF')
  26846. {
  26847. // preset chunk
  26848. const fxProgramSet* const cset = (const fxProgramSet*) data;
  26849. if (vst_swap (cset->chunkSize) + sizeof (fxProgramSet) - 8 > (unsigned int) dataSize)
  26850. return false;
  26851. setChunkData (cset->chunk, vst_swap (cset->chunkSize), true);
  26852. changeProgramName (getCurrentProgram(), cset->name);
  26853. }
  26854. else
  26855. {
  26856. return false;
  26857. }
  26858. return true;
  26859. }
  26860. void VSTPluginInstance::setParamsInProgramBlock (fxProgram* const prog) throw()
  26861. {
  26862. const int numParams = getNumParameters();
  26863. prog->chunkMagic = vst_swap ('CcnK');
  26864. prog->byteSize = 0;
  26865. prog->fxMagic = vst_swap ('FxCk');
  26866. prog->version = vst_swap (fxbVersionNum);
  26867. prog->fxID = vst_swap (getUID());
  26868. prog->fxVersion = vst_swap (getVersionNumber());
  26869. prog->numParams = vst_swap (numParams);
  26870. getCurrentProgramName().copyToCString (prog->prgName, sizeof (prog->prgName) - 1);
  26871. for (int i = 0; i < numParams; ++i)
  26872. prog->params[i] = vst_swapFloat (getParameter (i));
  26873. }
  26874. bool VSTPluginInstance::saveToFXBFile (MemoryBlock& dest, bool isFXB, int maxSizeMB)
  26875. {
  26876. const int numPrograms = getNumPrograms();
  26877. const int numParams = getNumParameters();
  26878. if (usesChunks())
  26879. {
  26880. if (isFXB)
  26881. {
  26882. MemoryBlock chunk;
  26883. getChunkData (chunk, false, maxSizeMB);
  26884. const size_t totalLen = sizeof (fxChunkSet) + chunk.getSize() - 8;
  26885. dest.setSize (totalLen, true);
  26886. fxChunkSet* const set = (fxChunkSet*) dest.getData();
  26887. set->chunkMagic = vst_swap ('CcnK');
  26888. set->byteSize = 0;
  26889. set->fxMagic = vst_swap ('FBCh');
  26890. set->version = vst_swap (fxbVersionNum);
  26891. set->fxID = vst_swap (getUID());
  26892. set->fxVersion = vst_swap (getVersionNumber());
  26893. set->numPrograms = vst_swap (numPrograms);
  26894. set->chunkSize = vst_swap ((long) chunk.getSize());
  26895. chunk.copyTo (set->chunk, 0, chunk.getSize());
  26896. }
  26897. else
  26898. {
  26899. MemoryBlock chunk;
  26900. getChunkData (chunk, true, maxSizeMB);
  26901. const size_t totalLen = sizeof (fxProgramSet) + chunk.getSize() - 8;
  26902. dest.setSize (totalLen, true);
  26903. fxProgramSet* const set = (fxProgramSet*) dest.getData();
  26904. set->chunkMagic = vst_swap ('CcnK');
  26905. set->byteSize = 0;
  26906. set->fxMagic = vst_swap ('FPCh');
  26907. set->version = vst_swap (fxbVersionNum);
  26908. set->fxID = vst_swap (getUID());
  26909. set->fxVersion = vst_swap (getVersionNumber());
  26910. set->numPrograms = vst_swap (numPrograms);
  26911. set->chunkSize = vst_swap ((long) chunk.getSize());
  26912. getCurrentProgramName().copyToCString (set->name, sizeof (set->name) - 1);
  26913. chunk.copyTo (set->chunk, 0, chunk.getSize());
  26914. }
  26915. }
  26916. else
  26917. {
  26918. if (isFXB)
  26919. {
  26920. const int progLen = sizeof (fxProgram) + (numParams - 1) * sizeof (float);
  26921. const int len = (sizeof (fxSet) - sizeof (fxProgram)) + progLen * jmax (1, numPrograms);
  26922. dest.setSize (len, true);
  26923. fxSet* const set = (fxSet*) dest.getData();
  26924. set->chunkMagic = vst_swap ('CcnK');
  26925. set->byteSize = 0;
  26926. set->fxMagic = vst_swap ('FxBk');
  26927. set->version = vst_swap (fxbVersionNum);
  26928. set->fxID = vst_swap (getUID());
  26929. set->fxVersion = vst_swap (getVersionNumber());
  26930. set->numPrograms = vst_swap (numPrograms);
  26931. const int oldProgram = getCurrentProgram();
  26932. MemoryBlock oldSettings;
  26933. createTempParameterStore (oldSettings);
  26934. setParamsInProgramBlock ((fxProgram*) (((char*) (set->programs)) + oldProgram * progLen));
  26935. for (int i = 0; i < numPrograms; ++i)
  26936. {
  26937. if (i != oldProgram)
  26938. {
  26939. setCurrentProgram (i);
  26940. setParamsInProgramBlock ((fxProgram*) (((char*) (set->programs)) + i * progLen));
  26941. }
  26942. }
  26943. setCurrentProgram (oldProgram);
  26944. restoreFromTempParameterStore (oldSettings);
  26945. }
  26946. else
  26947. {
  26948. const int totalLen = sizeof (fxProgram) + (numParams - 1) * sizeof (float);
  26949. dest.setSize (totalLen, true);
  26950. setParamsInProgramBlock ((fxProgram*) dest.getData());
  26951. }
  26952. }
  26953. return true;
  26954. }
  26955. void VSTPluginInstance::getChunkData (MemoryBlock& mb, bool isPreset, int maxSizeMB) const
  26956. {
  26957. if (usesChunks())
  26958. {
  26959. void* data = 0;
  26960. const int bytes = dispatch (effGetChunk, isPreset ? 1 : 0, 0, &data, 0.0f);
  26961. if (data != 0 && bytes <= maxSizeMB * 1024 * 1024)
  26962. {
  26963. mb.setSize (bytes);
  26964. mb.copyFrom (data, 0, bytes);
  26965. }
  26966. }
  26967. }
  26968. void VSTPluginInstance::setChunkData (const char* data, int size, bool isPreset)
  26969. {
  26970. if (size > 0 && usesChunks())
  26971. {
  26972. dispatch (effSetChunk, isPreset ? 1 : 0, size, (void*) data, 0.0f);
  26973. if (! isPreset)
  26974. updateStoredProgramNames();
  26975. }
  26976. }
  26977. void VSTPluginInstance::timerCallback()
  26978. {
  26979. if (dispatch (effIdle, 0, 0, 0, 0) == 0)
  26980. stopTimer();
  26981. }
  26982. int VSTPluginInstance::dispatch (const int opcode, const int index, const int value, void* const ptr, float opt) const
  26983. {
  26984. const ScopedLock sl (lock);
  26985. ++insideVSTCallback;
  26986. int result = 0;
  26987. try
  26988. {
  26989. if (effect != 0)
  26990. {
  26991. #if JUCE_MAC
  26992. if (module->resFileId != 0)
  26993. UseResFile (module->resFileId);
  26994. CGrafPtr oldPort;
  26995. if (getActiveEditor() != 0)
  26996. {
  26997. const Point<int> pos (getActiveEditor()->relativePositionToOtherComponent (getActiveEditor()->getTopLevelComponent(), Point<int>()));
  26998. GetPort (&oldPort);
  26999. SetPortWindowPort ((WindowRef) getActiveEditor()->getWindowHandle());
  27000. SetOrigin (-pos.getX(), -pos.getY());
  27001. }
  27002. #endif
  27003. result = effect->dispatcher (effect, opcode, index, value, ptr, opt);
  27004. #if JUCE_MAC
  27005. if (getActiveEditor() != 0)
  27006. SetPort (oldPort);
  27007. module->resFileId = CurResFile();
  27008. #endif
  27009. --insideVSTCallback;
  27010. return result;
  27011. }
  27012. }
  27013. catch (...)
  27014. {
  27015. }
  27016. --insideVSTCallback;
  27017. return result;
  27018. }
  27019. // handles non plugin-specific callbacks..
  27020. static const int defaultVSTSampleRateValue = 16384;
  27021. static const int defaultVSTBlockSizeValue = 512;
  27022. static VstIntPtr handleGeneralCallback (VstInt32 opcode, VstInt32 index, VstInt32 value, void *ptr, float opt)
  27023. {
  27024. (void) index;
  27025. (void) value;
  27026. (void) opt;
  27027. switch (opcode)
  27028. {
  27029. case audioMasterCanDo:
  27030. {
  27031. static const char* canDos[] = { "supplyIdle",
  27032. "sendVstEvents",
  27033. "sendVstMidiEvent",
  27034. "sendVstTimeInfo",
  27035. "receiveVstEvents",
  27036. "receiveVstMidiEvent",
  27037. "supportShell",
  27038. "shellCategory" };
  27039. for (int i = 0; i < numElementsInArray (canDos); ++i)
  27040. if (strcmp (canDos[i], (const char*) ptr) == 0)
  27041. return 1;
  27042. return 0;
  27043. }
  27044. case audioMasterVersion:
  27045. return 0x2400;
  27046. case audioMasterCurrentId:
  27047. return shellUIDToCreate;
  27048. case audioMasterGetNumAutomatableParameters:
  27049. return 0;
  27050. case audioMasterGetAutomationState:
  27051. return 1;
  27052. case audioMasterGetVendorVersion:
  27053. return 0x0101;
  27054. case audioMasterGetVendorString:
  27055. case audioMasterGetProductString:
  27056. {
  27057. String hostName ("Juce VST Host");
  27058. if (JUCEApplication::getInstance() != 0)
  27059. hostName = JUCEApplication::getInstance()->getApplicationName();
  27060. hostName.copyToCString ((char*) ptr, jmin (kVstMaxVendorStrLen, kVstMaxProductStrLen) - 1);
  27061. }
  27062. break;
  27063. case audioMasterGetSampleRate:
  27064. return (VstIntPtr) defaultVSTSampleRateValue;
  27065. case audioMasterGetBlockSize:
  27066. return (VstIntPtr) defaultVSTBlockSizeValue;
  27067. case audioMasterSetOutputSampleRate:
  27068. return 0;
  27069. default:
  27070. DBG ("*** Unhandled VST Callback: " + String ((int) opcode));
  27071. break;
  27072. }
  27073. return 0;
  27074. }
  27075. // handles callbacks for a specific plugin
  27076. VstIntPtr VSTPluginInstance::handleCallback (VstInt32 opcode, VstInt32 index, VstInt32 value, void *ptr, float opt)
  27077. {
  27078. switch (opcode)
  27079. {
  27080. case audioMasterAutomate:
  27081. sendParamChangeMessageToListeners (index, opt);
  27082. break;
  27083. case audioMasterProcessEvents:
  27084. handleMidiFromPlugin ((const VstEvents*) ptr);
  27085. break;
  27086. case audioMasterGetTime:
  27087. #ifdef _MSC_VER
  27088. #pragma warning (push)
  27089. #pragma warning (disable: 4311)
  27090. #endif
  27091. return (VstIntPtr) &vstHostTime;
  27092. #ifdef _MSC_VER
  27093. #pragma warning (pop)
  27094. #endif
  27095. break;
  27096. case audioMasterIdle:
  27097. if (insideVSTCallback == 0 && MessageManager::getInstance()->isThisTheMessageThread())
  27098. {
  27099. ++insideVSTCallback;
  27100. #if JUCE_MAC
  27101. if (getActiveEditor() != 0)
  27102. dispatch (effEditIdle, 0, 0, 0, 0);
  27103. #endif
  27104. juce_callAnyTimersSynchronously();
  27105. handleUpdateNowIfNeeded();
  27106. for (int i = ComponentPeer::getNumPeers(); --i >= 0;)
  27107. ComponentPeer::getPeer (i)->performAnyPendingRepaintsNow();
  27108. --insideVSTCallback;
  27109. }
  27110. break;
  27111. case audioMasterUpdateDisplay:
  27112. triggerAsyncUpdate();
  27113. break;
  27114. case audioMasterTempoAt:
  27115. // returns (10000 * bpm)
  27116. break;
  27117. case audioMasterNeedIdle:
  27118. startTimer (50);
  27119. break;
  27120. case audioMasterSizeWindow:
  27121. if (getActiveEditor() != 0)
  27122. getActiveEditor()->setSize (index, value);
  27123. return 1;
  27124. case audioMasterGetSampleRate:
  27125. return (VstIntPtr) (getSampleRate() > 0 ? getSampleRate() : defaultVSTSampleRateValue);
  27126. case audioMasterGetBlockSize:
  27127. return (VstIntPtr) (getBlockSize() > 0 ? getBlockSize() : defaultVSTBlockSizeValue);
  27128. case audioMasterWantMidi:
  27129. wantsMidiMessages = true;
  27130. break;
  27131. case audioMasterGetDirectory:
  27132. #if JUCE_MAC
  27133. return (VstIntPtr) (void*) &module->parentDirFSSpec;
  27134. #else
  27135. return (VstIntPtr) (pointer_sized_uint) module->fullParentDirectoryPathName.toUTF8();
  27136. #endif
  27137. case audioMasterGetAutomationState:
  27138. // returns 0: not supported, 1: off, 2:read, 3:write, 4:read/write
  27139. break;
  27140. // none of these are handled (yet)..
  27141. case audioMasterBeginEdit:
  27142. case audioMasterEndEdit:
  27143. case audioMasterSetTime:
  27144. case audioMasterPinConnected:
  27145. case audioMasterGetParameterQuantization:
  27146. case audioMasterIOChanged:
  27147. case audioMasterGetInputLatency:
  27148. case audioMasterGetOutputLatency:
  27149. case audioMasterGetPreviousPlug:
  27150. case audioMasterGetNextPlug:
  27151. case audioMasterWillReplaceOrAccumulate:
  27152. case audioMasterGetCurrentProcessLevel:
  27153. case audioMasterOfflineStart:
  27154. case audioMasterOfflineRead:
  27155. case audioMasterOfflineWrite:
  27156. case audioMasterOfflineGetCurrentPass:
  27157. case audioMasterOfflineGetCurrentMetaPass:
  27158. case audioMasterVendorSpecific:
  27159. case audioMasterSetIcon:
  27160. case audioMasterGetLanguage:
  27161. case audioMasterOpenWindow:
  27162. case audioMasterCloseWindow:
  27163. break;
  27164. default:
  27165. return handleGeneralCallback (opcode, index, value, ptr, opt);
  27166. }
  27167. return 0;
  27168. }
  27169. // entry point for all callbacks from the plugin
  27170. static VstIntPtr VSTCALLBACK audioMaster (AEffect* effect, VstInt32 opcode, VstInt32 index, VstIntPtr value, void* ptr, float opt)
  27171. {
  27172. try
  27173. {
  27174. if (effect != 0 && effect->resvd2 != 0)
  27175. {
  27176. return ((VSTPluginInstance*)(effect->resvd2))
  27177. ->handleCallback (opcode, index, value, ptr, opt);
  27178. }
  27179. return handleGeneralCallback (opcode, index, value, ptr, opt);
  27180. }
  27181. catch (...)
  27182. {
  27183. return 0;
  27184. }
  27185. }
  27186. const String VSTPluginInstance::getVersion() const throw()
  27187. {
  27188. unsigned int v = dispatch (effGetVendorVersion, 0, 0, 0, 0);
  27189. String s;
  27190. if (v == 0 || v == -1)
  27191. v = getVersionNumber();
  27192. if (v != 0)
  27193. {
  27194. int versionBits[4];
  27195. int n = 0;
  27196. while (v != 0)
  27197. {
  27198. versionBits [n++] = (v & 0xff);
  27199. v >>= 8;
  27200. }
  27201. s << 'V';
  27202. while (n > 0)
  27203. {
  27204. s << versionBits [--n];
  27205. if (n > 0)
  27206. s << '.';
  27207. }
  27208. }
  27209. return s;
  27210. }
  27211. int VSTPluginInstance::getUID() const throw()
  27212. {
  27213. int uid = effect != 0 ? effect->uniqueID : 0;
  27214. if (uid == 0)
  27215. uid = module->file.hashCode();
  27216. return uid;
  27217. }
  27218. const String VSTPluginInstance::getCategory() const throw()
  27219. {
  27220. const char* result = 0;
  27221. switch (dispatch (effGetPlugCategory, 0, 0, 0, 0))
  27222. {
  27223. case kPlugCategEffect:
  27224. result = "Effect";
  27225. break;
  27226. case kPlugCategSynth:
  27227. result = "Synth";
  27228. break;
  27229. case kPlugCategAnalysis:
  27230. result = "Anaylsis";
  27231. break;
  27232. case kPlugCategMastering:
  27233. result = "Mastering";
  27234. break;
  27235. case kPlugCategSpacializer:
  27236. result = "Spacial";
  27237. break;
  27238. case kPlugCategRoomFx:
  27239. result = "Reverb";
  27240. break;
  27241. case kPlugSurroundFx:
  27242. result = "Surround";
  27243. break;
  27244. case kPlugCategRestoration:
  27245. result = "Restoration";
  27246. break;
  27247. case kPlugCategGenerator:
  27248. result = "Tone generation";
  27249. break;
  27250. default:
  27251. break;
  27252. }
  27253. return result;
  27254. }
  27255. float VSTPluginInstance::getParameter (int index)
  27256. {
  27257. if (effect != 0 && ((unsigned int) index) < (unsigned int) effect->numParams)
  27258. {
  27259. try
  27260. {
  27261. const ScopedLock sl (lock);
  27262. return effect->getParameter (effect, index);
  27263. }
  27264. catch (...)
  27265. {
  27266. }
  27267. }
  27268. return 0.0f;
  27269. }
  27270. void VSTPluginInstance::setParameter (int index, float newValue)
  27271. {
  27272. if (effect != 0 && ((unsigned int) index) < (unsigned int) effect->numParams)
  27273. {
  27274. try
  27275. {
  27276. const ScopedLock sl (lock);
  27277. if (effect->getParameter (effect, index) != newValue)
  27278. effect->setParameter (effect, index, newValue);
  27279. }
  27280. catch (...)
  27281. {
  27282. }
  27283. }
  27284. }
  27285. const String VSTPluginInstance::getParameterName (int index)
  27286. {
  27287. if (effect != 0)
  27288. {
  27289. jassert (index >= 0 && index < effect->numParams);
  27290. char nm [256];
  27291. zerostruct (nm);
  27292. dispatch (effGetParamName, index, 0, nm, 0);
  27293. return String (nm).trim();
  27294. }
  27295. return String::empty;
  27296. }
  27297. const String VSTPluginInstance::getParameterLabel (int index) const
  27298. {
  27299. if (effect != 0)
  27300. {
  27301. jassert (index >= 0 && index < effect->numParams);
  27302. char nm [256];
  27303. zerostruct (nm);
  27304. dispatch (effGetParamLabel, index, 0, nm, 0);
  27305. return String (nm).trim();
  27306. }
  27307. return String::empty;
  27308. }
  27309. const String VSTPluginInstance::getParameterText (int index)
  27310. {
  27311. if (effect != 0)
  27312. {
  27313. jassert (index >= 0 && index < effect->numParams);
  27314. char nm [256];
  27315. zerostruct (nm);
  27316. dispatch (effGetParamDisplay, index, 0, nm, 0);
  27317. return String (nm).trim();
  27318. }
  27319. return String::empty;
  27320. }
  27321. bool VSTPluginInstance::isParameterAutomatable (int index) const
  27322. {
  27323. if (effect != 0)
  27324. {
  27325. jassert (index >= 0 && index < effect->numParams);
  27326. return dispatch (effCanBeAutomated, index, 0, 0, 0) != 0;
  27327. }
  27328. return false;
  27329. }
  27330. void VSTPluginInstance::createTempParameterStore (MemoryBlock& dest)
  27331. {
  27332. dest.setSize (64 + 4 * getNumParameters());
  27333. dest.fillWith (0);
  27334. getCurrentProgramName().copyToCString ((char*) dest.getData(), 63);
  27335. float* const p = (float*) (((char*) dest.getData()) + 64);
  27336. for (int i = 0; i < getNumParameters(); ++i)
  27337. p[i] = getParameter(i);
  27338. }
  27339. void VSTPluginInstance::restoreFromTempParameterStore (const MemoryBlock& m)
  27340. {
  27341. changeProgramName (getCurrentProgram(), (const char*) m.getData());
  27342. float* p = (float*) (((char*) m.getData()) + 64);
  27343. for (int i = 0; i < getNumParameters(); ++i)
  27344. setParameter (i, p[i]);
  27345. }
  27346. void VSTPluginInstance::setCurrentProgram (int newIndex)
  27347. {
  27348. if (getNumPrograms() > 0 && newIndex != getCurrentProgram())
  27349. dispatch (effSetProgram, 0, jlimit (0, getNumPrograms() - 1, newIndex), 0, 0);
  27350. }
  27351. const String VSTPluginInstance::getProgramName (int index)
  27352. {
  27353. if (index == getCurrentProgram())
  27354. {
  27355. return getCurrentProgramName();
  27356. }
  27357. else if (effect != 0)
  27358. {
  27359. char nm [256];
  27360. zerostruct (nm);
  27361. if (dispatch (effGetProgramNameIndexed,
  27362. jlimit (0, getNumPrograms(), index),
  27363. -1, nm, 0) != 0)
  27364. {
  27365. return String (nm).trim();
  27366. }
  27367. }
  27368. return programNames [index];
  27369. }
  27370. void VSTPluginInstance::changeProgramName (int index, const String& newName)
  27371. {
  27372. if (index == getCurrentProgram())
  27373. {
  27374. if (getNumPrograms() > 0 && newName != getCurrentProgramName())
  27375. dispatch (effSetProgramName, 0, 0, (void*) newName.substring (0, 24).toCString(), 0.0f);
  27376. }
  27377. else
  27378. {
  27379. jassertfalse // xxx not implemented!
  27380. }
  27381. }
  27382. void VSTPluginInstance::updateStoredProgramNames()
  27383. {
  27384. if (effect != 0 && getNumPrograms() > 0)
  27385. {
  27386. char nm [256];
  27387. zerostruct (nm);
  27388. // only do this if the plugin can't use indexed names..
  27389. if (dispatch (effGetProgramNameIndexed, 0, -1, nm, 0) == 0)
  27390. {
  27391. const int oldProgram = getCurrentProgram();
  27392. MemoryBlock oldSettings;
  27393. createTempParameterStore (oldSettings);
  27394. for (int i = 0; i < getNumPrograms(); ++i)
  27395. {
  27396. setCurrentProgram (i);
  27397. getCurrentProgramName(); // (this updates the list)
  27398. }
  27399. setCurrentProgram (oldProgram);
  27400. restoreFromTempParameterStore (oldSettings);
  27401. }
  27402. }
  27403. }
  27404. const String VSTPluginInstance::getCurrentProgramName()
  27405. {
  27406. if (effect != 0)
  27407. {
  27408. char nm [256];
  27409. zerostruct (nm);
  27410. dispatch (effGetProgramName, 0, 0, nm, 0);
  27411. const int index = getCurrentProgram();
  27412. if (programNames[index].isEmpty())
  27413. {
  27414. while (programNames.size() < index)
  27415. programNames.add (String::empty);
  27416. programNames.set (index, String (nm).trim());
  27417. }
  27418. return String (nm).trim();
  27419. }
  27420. return String::empty;
  27421. }
  27422. const String VSTPluginInstance::getInputChannelName (const int index) const
  27423. {
  27424. if (index >= 0 && index < getNumInputChannels())
  27425. {
  27426. VstPinProperties pinProps;
  27427. if (dispatch (effGetInputProperties, index, 0, &pinProps, 0.0f) != 0)
  27428. return String (pinProps.label, sizeof (pinProps.label));
  27429. }
  27430. return String::empty;
  27431. }
  27432. bool VSTPluginInstance::isInputChannelStereoPair (int index) const
  27433. {
  27434. if (index < 0 || index >= getNumInputChannels())
  27435. return false;
  27436. VstPinProperties pinProps;
  27437. if (dispatch (effGetInputProperties, index, 0, &pinProps, 0.0f) != 0)
  27438. return (pinProps.flags & kVstPinIsStereo) != 0;
  27439. return true;
  27440. }
  27441. const String VSTPluginInstance::getOutputChannelName (const int index) const
  27442. {
  27443. if (index >= 0 && index < getNumOutputChannels())
  27444. {
  27445. VstPinProperties pinProps;
  27446. if (dispatch (effGetOutputProperties, index, 0, &pinProps, 0.0f) != 0)
  27447. return String (pinProps.label, sizeof (pinProps.label));
  27448. }
  27449. return String::empty;
  27450. }
  27451. bool VSTPluginInstance::isOutputChannelStereoPair (int index) const
  27452. {
  27453. if (index < 0 || index >= getNumOutputChannels())
  27454. return false;
  27455. VstPinProperties pinProps;
  27456. if (dispatch (effGetOutputProperties, index, 0, &pinProps, 0.0f) != 0)
  27457. return (pinProps.flags & kVstPinIsStereo) != 0;
  27458. return true;
  27459. }
  27460. void VSTPluginInstance::setPower (const bool on)
  27461. {
  27462. dispatch (effMainsChanged, 0, on ? 1 : 0, 0, 0);
  27463. isPowerOn = on;
  27464. }
  27465. const int defaultMaxSizeMB = 64;
  27466. void VSTPluginInstance::getStateInformation (MemoryBlock& destData)
  27467. {
  27468. saveToFXBFile (destData, true, defaultMaxSizeMB);
  27469. }
  27470. void VSTPluginInstance::getCurrentProgramStateInformation (MemoryBlock& destData)
  27471. {
  27472. saveToFXBFile (destData, false, defaultMaxSizeMB);
  27473. }
  27474. void VSTPluginInstance::setStateInformation (const void* data, int sizeInBytes)
  27475. {
  27476. loadFromFXBFile (data, sizeInBytes);
  27477. }
  27478. void VSTPluginInstance::setCurrentProgramStateInformation (const void* data, int sizeInBytes)
  27479. {
  27480. loadFromFXBFile (data, sizeInBytes);
  27481. }
  27482. VSTPluginFormat::VSTPluginFormat()
  27483. {
  27484. }
  27485. VSTPluginFormat::~VSTPluginFormat()
  27486. {
  27487. }
  27488. void VSTPluginFormat::findAllTypesForFile (OwnedArray <PluginDescription>& results,
  27489. const String& fileOrIdentifier)
  27490. {
  27491. if (! fileMightContainThisPluginType (fileOrIdentifier))
  27492. return;
  27493. PluginDescription desc;
  27494. desc.fileOrIdentifier = fileOrIdentifier;
  27495. desc.uid = 0;
  27496. ScopedPointer <VSTPluginInstance> instance (dynamic_cast <VSTPluginInstance*> (createInstanceFromDescription (desc)));
  27497. if (instance == 0)
  27498. return;
  27499. try
  27500. {
  27501. #if JUCE_MAC
  27502. if (instance->module->resFileId != 0)
  27503. UseResFile (instance->module->resFileId);
  27504. #endif
  27505. instance->fillInPluginDescription (desc);
  27506. VstPlugCategory category = (VstPlugCategory) instance->dispatch (effGetPlugCategory, 0, 0, 0, 0);
  27507. if (category != kPlugCategShell)
  27508. {
  27509. // Normal plugin...
  27510. results.add (new PluginDescription (desc));
  27511. ++insideVSTCallback;
  27512. instance->dispatch (effOpen, 0, 0, 0, 0);
  27513. --insideVSTCallback;
  27514. }
  27515. else
  27516. {
  27517. // It's a shell plugin, so iterate all the subtypes...
  27518. char shellEffectName [64];
  27519. for (;;)
  27520. {
  27521. zerostruct (shellEffectName);
  27522. const int uid = instance->dispatch (effShellGetNextPlugin, 0, 0, shellEffectName, 0);
  27523. if (uid == 0)
  27524. {
  27525. break;
  27526. }
  27527. else
  27528. {
  27529. desc.uid = uid;
  27530. desc.name = shellEffectName;
  27531. bool alreadyThere = false;
  27532. for (int i = results.size(); --i >= 0;)
  27533. {
  27534. PluginDescription* const d = results.getUnchecked(i);
  27535. if (d->isDuplicateOf (desc))
  27536. {
  27537. alreadyThere = true;
  27538. break;
  27539. }
  27540. }
  27541. if (! alreadyThere)
  27542. results.add (new PluginDescription (desc));
  27543. }
  27544. }
  27545. }
  27546. }
  27547. catch (...)
  27548. {
  27549. // crashed while loading...
  27550. }
  27551. }
  27552. AudioPluginInstance* VSTPluginFormat::createInstanceFromDescription (const PluginDescription& desc)
  27553. {
  27554. ScopedPointer <VSTPluginInstance> result;
  27555. if (fileMightContainThisPluginType (desc.fileOrIdentifier))
  27556. {
  27557. File file (desc.fileOrIdentifier);
  27558. const File previousWorkingDirectory (File::getCurrentWorkingDirectory());
  27559. file.getParentDirectory().setAsCurrentWorkingDirectory();
  27560. const ReferenceCountedObjectPtr <ModuleHandle> module (ModuleHandle::findOrCreateModule (file));
  27561. if (module != 0)
  27562. {
  27563. shellUIDToCreate = desc.uid;
  27564. result = new VSTPluginInstance (module);
  27565. if (result->effect != 0)
  27566. {
  27567. result->effect->resvd2 = (VstIntPtr) (pointer_sized_int) (VSTPluginInstance*) result;
  27568. result->initialise();
  27569. }
  27570. else
  27571. {
  27572. result = 0;
  27573. }
  27574. }
  27575. previousWorkingDirectory.setAsCurrentWorkingDirectory();
  27576. }
  27577. return result.release();
  27578. }
  27579. bool VSTPluginFormat::fileMightContainThisPluginType (const String& fileOrIdentifier)
  27580. {
  27581. const File f (fileOrIdentifier);
  27582. #if JUCE_MAC
  27583. if (f.isDirectory() && f.hasFileExtension (T(".vst")))
  27584. return true;
  27585. #if JUCE_PPC
  27586. FSRef fileRef;
  27587. if (PlatformUtilities::makeFSRefFromPath (&fileRef, f.getFullPathName()))
  27588. {
  27589. const short resFileId = FSOpenResFile (&fileRef, fsRdPerm);
  27590. if (resFileId != -1)
  27591. {
  27592. const int numEffects = Count1Resources ('aEff');
  27593. CloseResFile (resFileId);
  27594. if (numEffects > 0)
  27595. return true;
  27596. }
  27597. }
  27598. #endif
  27599. return false;
  27600. #elif JUCE_WIN32
  27601. return f.existsAsFile()
  27602. && f.hasFileExtension (T(".dll"));
  27603. #elif JUCE_LINUX
  27604. return f.existsAsFile()
  27605. && f.hasFileExtension (T(".so"));
  27606. #endif
  27607. }
  27608. const String VSTPluginFormat::getNameOfPluginFromIdentifier (const String& fileOrIdentifier)
  27609. {
  27610. return fileOrIdentifier;
  27611. }
  27612. bool VSTPluginFormat::doesPluginStillExist (const PluginDescription& desc)
  27613. {
  27614. return File (desc.fileOrIdentifier).exists();
  27615. }
  27616. const StringArray VSTPluginFormat::searchPathsForPlugins (const FileSearchPath& directoriesToSearch, const bool recursive)
  27617. {
  27618. StringArray results;
  27619. for (int j = 0; j < directoriesToSearch.getNumPaths(); ++j)
  27620. recursiveFileSearch (results, directoriesToSearch [j], recursive);
  27621. return results;
  27622. }
  27623. void VSTPluginFormat::recursiveFileSearch (StringArray& results, const File& dir, const bool recursive)
  27624. {
  27625. // avoid allowing the dir iterator to be recursive, because we want to avoid letting it delve inside
  27626. // .component or .vst directories.
  27627. DirectoryIterator iter (dir, false, "*", File::findFilesAndDirectories);
  27628. while (iter.next())
  27629. {
  27630. const File f (iter.getFile());
  27631. bool isPlugin = false;
  27632. if (fileMightContainThisPluginType (f.getFullPathName()))
  27633. {
  27634. isPlugin = true;
  27635. results.add (f.getFullPathName());
  27636. }
  27637. if (recursive && (! isPlugin) && f.isDirectory())
  27638. recursiveFileSearch (results, f, true);
  27639. }
  27640. }
  27641. const FileSearchPath VSTPluginFormat::getDefaultLocationsToSearch()
  27642. {
  27643. #if JUCE_MAC
  27644. return FileSearchPath ("~/Library/Audio/Plug-Ins/VST;/Library/Audio/Plug-Ins/VST");
  27645. #elif JUCE_WIN32
  27646. const String programFiles (File::getSpecialLocation (File::globalApplicationsDirectory).getFullPathName());
  27647. return FileSearchPath (programFiles + "\\Steinberg\\VstPlugins");
  27648. #elif JUCE_LINUX
  27649. return FileSearchPath ("/usr/lib/vst");
  27650. #endif
  27651. }
  27652. END_JUCE_NAMESPACE
  27653. #endif
  27654. #undef log
  27655. #endif
  27656. /*** End of inlined file: juce_VSTPluginFormat.cpp ***/
  27657. /*** End of inlined file: juce_VSTPluginFormat.mm ***/
  27658. /*** Start of inlined file: juce_AudioProcessor.cpp ***/
  27659. BEGIN_JUCE_NAMESPACE
  27660. AudioProcessor::AudioProcessor()
  27661. : playHead (0),
  27662. activeEditor (0),
  27663. sampleRate (0),
  27664. blockSize (0),
  27665. numInputChannels (0),
  27666. numOutputChannels (0),
  27667. latencySamples (0),
  27668. suspended (false),
  27669. nonRealtime (false)
  27670. {
  27671. }
  27672. AudioProcessor::~AudioProcessor()
  27673. {
  27674. // ooh, nasty - the editor should have been deleted before the filter
  27675. // that it refers to is deleted..
  27676. jassert (activeEditor == 0);
  27677. #ifdef JUCE_DEBUG
  27678. // This will fail if you've called beginParameterChangeGesture() for one
  27679. // or more parameters without having made a corresponding call to endParameterChangeGesture...
  27680. jassert (changingParams.countNumberOfSetBits() == 0);
  27681. #endif
  27682. }
  27683. void AudioProcessor::setPlayHead (AudioPlayHead* const newPlayHead) throw()
  27684. {
  27685. playHead = newPlayHead;
  27686. }
  27687. void AudioProcessor::addListener (AudioProcessorListener* const newListener) throw()
  27688. {
  27689. const ScopedLock sl (listenerLock);
  27690. listeners.addIfNotAlreadyThere (newListener);
  27691. }
  27692. void AudioProcessor::removeListener (AudioProcessorListener* const listenerToRemove) throw()
  27693. {
  27694. const ScopedLock sl (listenerLock);
  27695. listeners.removeValue (listenerToRemove);
  27696. }
  27697. void AudioProcessor::setPlayConfigDetails (const int numIns,
  27698. const int numOuts,
  27699. const double sampleRate_,
  27700. const int blockSize_) throw()
  27701. {
  27702. numInputChannels = numIns;
  27703. numOutputChannels = numOuts;
  27704. sampleRate = sampleRate_;
  27705. blockSize = blockSize_;
  27706. }
  27707. void AudioProcessor::setNonRealtime (const bool nonRealtime_) throw()
  27708. {
  27709. nonRealtime = nonRealtime_;
  27710. }
  27711. void AudioProcessor::setLatencySamples (const int newLatency)
  27712. {
  27713. if (latencySamples != newLatency)
  27714. {
  27715. latencySamples = newLatency;
  27716. updateHostDisplay();
  27717. }
  27718. }
  27719. void AudioProcessor::setParameterNotifyingHost (const int parameterIndex,
  27720. const float newValue)
  27721. {
  27722. setParameter (parameterIndex, newValue);
  27723. sendParamChangeMessageToListeners (parameterIndex, newValue);
  27724. }
  27725. void AudioProcessor::sendParamChangeMessageToListeners (const int parameterIndex, const float newValue)
  27726. {
  27727. jassert (((unsigned int) parameterIndex) < (unsigned int) getNumParameters());
  27728. for (int i = listeners.size(); --i >= 0;)
  27729. {
  27730. AudioProcessorListener* l;
  27731. {
  27732. const ScopedLock sl (listenerLock);
  27733. l = (AudioProcessorListener*) listeners [i];
  27734. }
  27735. if (l != 0)
  27736. l->audioProcessorParameterChanged (this, parameterIndex, newValue);
  27737. }
  27738. }
  27739. void AudioProcessor::beginParameterChangeGesture (int parameterIndex)
  27740. {
  27741. jassert (((unsigned int) parameterIndex) < (unsigned int) getNumParameters());
  27742. #ifdef JUCE_DEBUG
  27743. // This means you've called beginParameterChangeGesture twice in succession without a matching
  27744. // call to endParameterChangeGesture. That might be fine in most hosts, but better to avoid doing it.
  27745. jassert (! changingParams [parameterIndex]);
  27746. changingParams.setBit (parameterIndex);
  27747. #endif
  27748. for (int i = listeners.size(); --i >= 0;)
  27749. {
  27750. AudioProcessorListener* l;
  27751. {
  27752. const ScopedLock sl (listenerLock);
  27753. l = (AudioProcessorListener*) listeners [i];
  27754. }
  27755. if (l != 0)
  27756. l->audioProcessorParameterChangeGestureBegin (this, parameterIndex);
  27757. }
  27758. }
  27759. void AudioProcessor::endParameterChangeGesture (int parameterIndex)
  27760. {
  27761. jassert (((unsigned int) parameterIndex) < (unsigned int) getNumParameters());
  27762. #ifdef JUCE_DEBUG
  27763. // This means you've called endParameterChangeGesture without having previously called
  27764. // endParameterChangeGesture. That might be fine in most hosts, but better to keep the
  27765. // calls matched correctly.
  27766. jassert (changingParams [parameterIndex]);
  27767. changingParams.clearBit (parameterIndex);
  27768. #endif
  27769. for (int i = listeners.size(); --i >= 0;)
  27770. {
  27771. AudioProcessorListener* l;
  27772. {
  27773. const ScopedLock sl (listenerLock);
  27774. l = (AudioProcessorListener*) listeners [i];
  27775. }
  27776. if (l != 0)
  27777. l->audioProcessorParameterChangeGestureEnd (this, parameterIndex);
  27778. }
  27779. }
  27780. void AudioProcessor::updateHostDisplay()
  27781. {
  27782. for (int i = listeners.size(); --i >= 0;)
  27783. {
  27784. AudioProcessorListener* l;
  27785. {
  27786. const ScopedLock sl (listenerLock);
  27787. l = (AudioProcessorListener*) listeners [i];
  27788. }
  27789. if (l != 0)
  27790. l->audioProcessorChanged (this);
  27791. }
  27792. }
  27793. bool AudioProcessor::isParameterAutomatable (int /*parameterIndex*/) const
  27794. {
  27795. return true;
  27796. }
  27797. bool AudioProcessor::isMetaParameter (int /*parameterIndex*/) const
  27798. {
  27799. return false;
  27800. }
  27801. void AudioProcessor::suspendProcessing (const bool shouldBeSuspended)
  27802. {
  27803. const ScopedLock sl (callbackLock);
  27804. suspended = shouldBeSuspended;
  27805. }
  27806. void AudioProcessor::reset()
  27807. {
  27808. }
  27809. void AudioProcessor::editorBeingDeleted (AudioProcessorEditor* const editor) throw()
  27810. {
  27811. const ScopedLock sl (callbackLock);
  27812. jassert (activeEditor == editor);
  27813. if (activeEditor == editor)
  27814. activeEditor = 0;
  27815. }
  27816. AudioProcessorEditor* AudioProcessor::createEditorIfNeeded()
  27817. {
  27818. if (activeEditor != 0)
  27819. return activeEditor;
  27820. AudioProcessorEditor* const ed = createEditor();
  27821. if (ed != 0)
  27822. {
  27823. // you must give your editor comp a size before returning it..
  27824. jassert (ed->getWidth() > 0 && ed->getHeight() > 0);
  27825. const ScopedLock sl (callbackLock);
  27826. activeEditor = ed;
  27827. }
  27828. return ed;
  27829. }
  27830. void AudioProcessor::getCurrentProgramStateInformation (JUCE_NAMESPACE::MemoryBlock& destData)
  27831. {
  27832. getStateInformation (destData);
  27833. }
  27834. void AudioProcessor::setCurrentProgramStateInformation (const void* data, int sizeInBytes)
  27835. {
  27836. setStateInformation (data, sizeInBytes);
  27837. }
  27838. // magic number to identify memory blocks that we've stored as XML
  27839. const uint32 magicXmlNumber = 0x21324356;
  27840. void AudioProcessor::copyXmlToBinary (const XmlElement& xml,
  27841. JUCE_NAMESPACE::MemoryBlock& destData)
  27842. {
  27843. const String xmlString (xml.createDocument (String::empty, true, false));
  27844. const int stringLength = xmlString.getNumBytesAsUTF8();
  27845. destData.setSize (stringLength + 10);
  27846. char* const d = (char*) destData.getData();
  27847. *(uint32*) d = ByteOrder::swapIfBigEndian ((const uint32) magicXmlNumber);
  27848. *(uint32*) (d + 4) = ByteOrder::swapIfBigEndian ((const uint32) stringLength);
  27849. xmlString.copyToUTF8 (d + 8, stringLength + 1);
  27850. }
  27851. XmlElement* AudioProcessor::getXmlFromBinary (const void* data,
  27852. const int sizeInBytes)
  27853. {
  27854. if (sizeInBytes > 8
  27855. && ByteOrder::littleEndianInt ((const char*) data) == magicXmlNumber)
  27856. {
  27857. const int stringLength = (int) ByteOrder::littleEndianInt (((const char*) data) + 4);
  27858. if (stringLength > 0)
  27859. {
  27860. XmlDocument doc (String::fromUTF8 (((const char*) data) + 8,
  27861. jmin ((sizeInBytes - 8), stringLength)));
  27862. return doc.getDocumentElement();
  27863. }
  27864. }
  27865. return 0;
  27866. }
  27867. void AudioProcessorListener::audioProcessorParameterChangeGestureBegin (AudioProcessor*, int)
  27868. {
  27869. }
  27870. void AudioProcessorListener::audioProcessorParameterChangeGestureEnd (AudioProcessor*, int)
  27871. {
  27872. }
  27873. END_JUCE_NAMESPACE
  27874. /*** End of inlined file: juce_AudioProcessor.cpp ***/
  27875. /*** Start of inlined file: juce_AudioProcessorEditor.cpp ***/
  27876. BEGIN_JUCE_NAMESPACE
  27877. AudioProcessorEditor::AudioProcessorEditor (AudioProcessor* const owner_)
  27878. : owner (owner_)
  27879. {
  27880. // the filter must be valid..
  27881. jassert (owner != 0);
  27882. }
  27883. AudioProcessorEditor::~AudioProcessorEditor()
  27884. {
  27885. // if this fails, then the wrapper hasn't called editorBeingDeleted() on the
  27886. // filter for some reason..
  27887. jassert (owner->getActiveEditor() != this);
  27888. }
  27889. END_JUCE_NAMESPACE
  27890. /*** End of inlined file: juce_AudioProcessorEditor.cpp ***/
  27891. /*** Start of inlined file: juce_AudioProcessorGraph.cpp ***/
  27892. BEGIN_JUCE_NAMESPACE
  27893. const int AudioProcessorGraph::midiChannelIndex = 0x1000;
  27894. AudioProcessorGraph::Node::Node (const uint32 id_, AudioProcessor* const processor_)
  27895. : id (id_),
  27896. processor (processor_),
  27897. isPrepared (false)
  27898. {
  27899. jassert (processor_ != 0);
  27900. }
  27901. AudioProcessorGraph::Node::~Node()
  27902. {
  27903. delete processor;
  27904. }
  27905. void AudioProcessorGraph::Node::prepare (const double sampleRate, const int blockSize,
  27906. AudioProcessorGraph* const graph)
  27907. {
  27908. if (! isPrepared)
  27909. {
  27910. isPrepared = true;
  27911. AudioProcessorGraph::AudioGraphIOProcessor* const ioProc
  27912. = dynamic_cast <AudioProcessorGraph::AudioGraphIOProcessor*> (processor);
  27913. if (ioProc != 0)
  27914. ioProc->setParentGraph (graph);
  27915. processor->setPlayConfigDetails (processor->getNumInputChannels(),
  27916. processor->getNumOutputChannels(),
  27917. sampleRate, blockSize);
  27918. processor->prepareToPlay (sampleRate, blockSize);
  27919. }
  27920. }
  27921. void AudioProcessorGraph::Node::unprepare()
  27922. {
  27923. if (isPrepared)
  27924. {
  27925. isPrepared = false;
  27926. processor->releaseResources();
  27927. }
  27928. }
  27929. AudioProcessorGraph::AudioProcessorGraph()
  27930. : lastNodeId (0),
  27931. renderingBuffers (1, 1),
  27932. currentAudioOutputBuffer (1, 1)
  27933. {
  27934. }
  27935. AudioProcessorGraph::~AudioProcessorGraph()
  27936. {
  27937. clearRenderingSequence();
  27938. clear();
  27939. }
  27940. const String AudioProcessorGraph::getName() const
  27941. {
  27942. return "Audio Graph";
  27943. }
  27944. void AudioProcessorGraph::clear()
  27945. {
  27946. nodes.clear();
  27947. connections.clear();
  27948. triggerAsyncUpdate();
  27949. }
  27950. AudioProcessorGraph::Node* AudioProcessorGraph::getNodeForId (const uint32 nodeId) const
  27951. {
  27952. for (int i = nodes.size(); --i >= 0;)
  27953. if (nodes.getUnchecked(i)->id == nodeId)
  27954. return nodes.getUnchecked(i);
  27955. return 0;
  27956. }
  27957. AudioProcessorGraph::Node* AudioProcessorGraph::addNode (AudioProcessor* const newProcessor,
  27958. uint32 nodeId)
  27959. {
  27960. if (newProcessor == 0)
  27961. {
  27962. jassertfalse
  27963. return 0;
  27964. }
  27965. if (nodeId == 0)
  27966. {
  27967. nodeId = ++lastNodeId;
  27968. }
  27969. else
  27970. {
  27971. // you can't add a node with an id that already exists in the graph..
  27972. jassert (getNodeForId (nodeId) == 0);
  27973. removeNode (nodeId);
  27974. }
  27975. lastNodeId = nodeId;
  27976. Node* const n = new Node (nodeId, newProcessor);
  27977. nodes.add (n);
  27978. triggerAsyncUpdate();
  27979. AudioProcessorGraph::AudioGraphIOProcessor* const ioProc
  27980. = dynamic_cast <AudioProcessorGraph::AudioGraphIOProcessor*> (n->processor);
  27981. if (ioProc != 0)
  27982. ioProc->setParentGraph (this);
  27983. return n;
  27984. }
  27985. bool AudioProcessorGraph::removeNode (const uint32 nodeId)
  27986. {
  27987. disconnectNode (nodeId);
  27988. for (int i = nodes.size(); --i >= 0;)
  27989. {
  27990. if (nodes.getUnchecked(i)->id == nodeId)
  27991. {
  27992. AudioProcessorGraph::AudioGraphIOProcessor* const ioProc
  27993. = dynamic_cast <AudioProcessorGraph::AudioGraphIOProcessor*> (nodes.getUnchecked(i)->processor);
  27994. if (ioProc != 0)
  27995. ioProc->setParentGraph (0);
  27996. nodes.remove (i);
  27997. triggerAsyncUpdate();
  27998. return true;
  27999. }
  28000. }
  28001. return false;
  28002. }
  28003. const AudioProcessorGraph::Connection* AudioProcessorGraph::getConnectionBetween (const uint32 sourceNodeId,
  28004. const int sourceChannelIndex,
  28005. const uint32 destNodeId,
  28006. const int destChannelIndex) const
  28007. {
  28008. for (int i = connections.size(); --i >= 0;)
  28009. {
  28010. const Connection* const c = connections.getUnchecked(i);
  28011. if (c->sourceNodeId == sourceNodeId
  28012. && c->destNodeId == destNodeId
  28013. && c->sourceChannelIndex == sourceChannelIndex
  28014. && c->destChannelIndex == destChannelIndex)
  28015. {
  28016. return c;
  28017. }
  28018. }
  28019. return 0;
  28020. }
  28021. bool AudioProcessorGraph::isConnected (const uint32 possibleSourceNodeId,
  28022. const uint32 possibleDestNodeId) const
  28023. {
  28024. for (int i = connections.size(); --i >= 0;)
  28025. {
  28026. const Connection* const c = connections.getUnchecked(i);
  28027. if (c->sourceNodeId == possibleSourceNodeId
  28028. && c->destNodeId == possibleDestNodeId)
  28029. {
  28030. return true;
  28031. }
  28032. }
  28033. return false;
  28034. }
  28035. bool AudioProcessorGraph::canConnect (const uint32 sourceNodeId,
  28036. const int sourceChannelIndex,
  28037. const uint32 destNodeId,
  28038. const int destChannelIndex) const
  28039. {
  28040. if (sourceChannelIndex < 0
  28041. || destChannelIndex < 0
  28042. || sourceNodeId == destNodeId
  28043. || (destChannelIndex == midiChannelIndex) != (sourceChannelIndex == midiChannelIndex))
  28044. return false;
  28045. const Node* const source = getNodeForId (sourceNodeId);
  28046. if (source == 0
  28047. || (sourceChannelIndex != midiChannelIndex && sourceChannelIndex >= source->processor->getNumOutputChannels())
  28048. || (sourceChannelIndex == midiChannelIndex && ! source->processor->producesMidi()))
  28049. return false;
  28050. const Node* const dest = getNodeForId (destNodeId);
  28051. if (dest == 0
  28052. || (destChannelIndex != midiChannelIndex && destChannelIndex >= dest->processor->getNumInputChannels())
  28053. || (destChannelIndex == midiChannelIndex && ! dest->processor->acceptsMidi()))
  28054. return false;
  28055. return getConnectionBetween (sourceNodeId, sourceChannelIndex,
  28056. destNodeId, destChannelIndex) == 0;
  28057. }
  28058. bool AudioProcessorGraph::addConnection (const uint32 sourceNodeId,
  28059. const int sourceChannelIndex,
  28060. const uint32 destNodeId,
  28061. const int destChannelIndex)
  28062. {
  28063. if (! canConnect (sourceNodeId, sourceChannelIndex, destNodeId, destChannelIndex))
  28064. return false;
  28065. Connection* const c = new Connection();
  28066. c->sourceNodeId = sourceNodeId;
  28067. c->sourceChannelIndex = sourceChannelIndex;
  28068. c->destNodeId = destNodeId;
  28069. c->destChannelIndex = destChannelIndex;
  28070. connections.add (c);
  28071. triggerAsyncUpdate();
  28072. return true;
  28073. }
  28074. void AudioProcessorGraph::removeConnection (const int index)
  28075. {
  28076. connections.remove (index);
  28077. triggerAsyncUpdate();
  28078. }
  28079. bool AudioProcessorGraph::removeConnection (const uint32 sourceNodeId, const int sourceChannelIndex,
  28080. const uint32 destNodeId, const int destChannelIndex)
  28081. {
  28082. bool doneAnything = false;
  28083. for (int i = connections.size(); --i >= 0;)
  28084. {
  28085. const Connection* const c = connections.getUnchecked(i);
  28086. if (c->sourceNodeId == sourceNodeId
  28087. && c->destNodeId == destNodeId
  28088. && c->sourceChannelIndex == sourceChannelIndex
  28089. && c->destChannelIndex == destChannelIndex)
  28090. {
  28091. removeConnection (i);
  28092. doneAnything = true;
  28093. triggerAsyncUpdate();
  28094. }
  28095. }
  28096. return doneAnything;
  28097. }
  28098. bool AudioProcessorGraph::disconnectNode (const uint32 nodeId)
  28099. {
  28100. bool doneAnything = false;
  28101. for (int i = connections.size(); --i >= 0;)
  28102. {
  28103. const Connection* const c = connections.getUnchecked(i);
  28104. if (c->sourceNodeId == nodeId || c->destNodeId == nodeId)
  28105. {
  28106. removeConnection (i);
  28107. doneAnything = true;
  28108. triggerAsyncUpdate();
  28109. }
  28110. }
  28111. return doneAnything;
  28112. }
  28113. bool AudioProcessorGraph::removeIllegalConnections()
  28114. {
  28115. bool doneAnything = false;
  28116. for (int i = connections.size(); --i >= 0;)
  28117. {
  28118. const Connection* const c = connections.getUnchecked(i);
  28119. const Node* const source = getNodeForId (c->sourceNodeId);
  28120. const Node* const dest = getNodeForId (c->destNodeId);
  28121. if (source == 0 || dest == 0
  28122. || (c->sourceChannelIndex != midiChannelIndex
  28123. && (((unsigned int) c->sourceChannelIndex) >= (unsigned int) source->processor->getNumOutputChannels()))
  28124. || (c->sourceChannelIndex == midiChannelIndex
  28125. && ! source->processor->producesMidi())
  28126. || (c->destChannelIndex != midiChannelIndex
  28127. && (((unsigned int) c->destChannelIndex) >= (unsigned int) dest->processor->getNumInputChannels()))
  28128. || (c->destChannelIndex == midiChannelIndex
  28129. && ! dest->processor->acceptsMidi()))
  28130. {
  28131. removeConnection (i);
  28132. doneAnything = true;
  28133. triggerAsyncUpdate();
  28134. }
  28135. }
  28136. return doneAnything;
  28137. }
  28138. namespace GraphRenderingOps
  28139. {
  28140. class AudioGraphRenderingOp
  28141. {
  28142. public:
  28143. AudioGraphRenderingOp() {}
  28144. virtual ~AudioGraphRenderingOp() {}
  28145. virtual void perform (AudioSampleBuffer& sharedBufferChans,
  28146. const OwnedArray <MidiBuffer>& sharedMidiBuffers,
  28147. const int numSamples) = 0;
  28148. juce_UseDebuggingNewOperator
  28149. };
  28150. class ClearChannelOp : public AudioGraphRenderingOp
  28151. {
  28152. public:
  28153. ClearChannelOp (const int channelNum_)
  28154. : channelNum (channelNum_)
  28155. {}
  28156. ~ClearChannelOp() {}
  28157. void perform (AudioSampleBuffer& sharedBufferChans, const OwnedArray <MidiBuffer>&, const int numSamples)
  28158. {
  28159. sharedBufferChans.clear (channelNum, 0, numSamples);
  28160. }
  28161. private:
  28162. const int channelNum;
  28163. ClearChannelOp (const ClearChannelOp&);
  28164. ClearChannelOp& operator= (const ClearChannelOp&);
  28165. };
  28166. class CopyChannelOp : public AudioGraphRenderingOp
  28167. {
  28168. public:
  28169. CopyChannelOp (const int srcChannelNum_, const int dstChannelNum_)
  28170. : srcChannelNum (srcChannelNum_),
  28171. dstChannelNum (dstChannelNum_)
  28172. {}
  28173. ~CopyChannelOp() {}
  28174. void perform (AudioSampleBuffer& sharedBufferChans, const OwnedArray <MidiBuffer>&, const int numSamples)
  28175. {
  28176. sharedBufferChans.copyFrom (dstChannelNum, 0, sharedBufferChans, srcChannelNum, 0, numSamples);
  28177. }
  28178. private:
  28179. const int srcChannelNum, dstChannelNum;
  28180. CopyChannelOp (const CopyChannelOp&);
  28181. CopyChannelOp& operator= (const CopyChannelOp&);
  28182. };
  28183. class AddChannelOp : public AudioGraphRenderingOp
  28184. {
  28185. public:
  28186. AddChannelOp (const int srcChannelNum_, const int dstChannelNum_)
  28187. : srcChannelNum (srcChannelNum_),
  28188. dstChannelNum (dstChannelNum_)
  28189. {}
  28190. ~AddChannelOp() {}
  28191. void perform (AudioSampleBuffer& sharedBufferChans, const OwnedArray <MidiBuffer>&, const int numSamples)
  28192. {
  28193. sharedBufferChans.addFrom (dstChannelNum, 0, sharedBufferChans, srcChannelNum, 0, numSamples);
  28194. }
  28195. private:
  28196. const int srcChannelNum, dstChannelNum;
  28197. AddChannelOp (const AddChannelOp&);
  28198. AddChannelOp& operator= (const AddChannelOp&);
  28199. };
  28200. class ClearMidiBufferOp : public AudioGraphRenderingOp
  28201. {
  28202. public:
  28203. ClearMidiBufferOp (const int bufferNum_)
  28204. : bufferNum (bufferNum_)
  28205. {}
  28206. ~ClearMidiBufferOp() {}
  28207. void perform (AudioSampleBuffer&, const OwnedArray <MidiBuffer>& sharedMidiBuffers, const int)
  28208. {
  28209. sharedMidiBuffers.getUnchecked (bufferNum)->clear();
  28210. }
  28211. private:
  28212. const int bufferNum;
  28213. ClearMidiBufferOp (const ClearMidiBufferOp&);
  28214. ClearMidiBufferOp& operator= (const ClearMidiBufferOp&);
  28215. };
  28216. class CopyMidiBufferOp : public AudioGraphRenderingOp
  28217. {
  28218. public:
  28219. CopyMidiBufferOp (const int srcBufferNum_, const int dstBufferNum_)
  28220. : srcBufferNum (srcBufferNum_),
  28221. dstBufferNum (dstBufferNum_)
  28222. {}
  28223. ~CopyMidiBufferOp() {}
  28224. void perform (AudioSampleBuffer&, const OwnedArray <MidiBuffer>& sharedMidiBuffers, const int)
  28225. {
  28226. *sharedMidiBuffers.getUnchecked (dstBufferNum) = *sharedMidiBuffers.getUnchecked (srcBufferNum);
  28227. }
  28228. private:
  28229. const int srcBufferNum, dstBufferNum;
  28230. CopyMidiBufferOp (const CopyMidiBufferOp&);
  28231. CopyMidiBufferOp& operator= (const CopyMidiBufferOp&);
  28232. };
  28233. class AddMidiBufferOp : public AudioGraphRenderingOp
  28234. {
  28235. public:
  28236. AddMidiBufferOp (const int srcBufferNum_, const int dstBufferNum_)
  28237. : srcBufferNum (srcBufferNum_),
  28238. dstBufferNum (dstBufferNum_)
  28239. {}
  28240. ~AddMidiBufferOp() {}
  28241. void perform (AudioSampleBuffer&, const OwnedArray <MidiBuffer>& sharedMidiBuffers, const int numSamples)
  28242. {
  28243. sharedMidiBuffers.getUnchecked (dstBufferNum)
  28244. ->addEvents (*sharedMidiBuffers.getUnchecked (srcBufferNum), 0, numSamples, 0);
  28245. }
  28246. private:
  28247. const int srcBufferNum, dstBufferNum;
  28248. AddMidiBufferOp (const AddMidiBufferOp&);
  28249. AddMidiBufferOp& operator= (const AddMidiBufferOp&);
  28250. };
  28251. class ProcessBufferOp : public AudioGraphRenderingOp
  28252. {
  28253. public:
  28254. ProcessBufferOp (const AudioProcessorGraph::Node::Ptr& node_,
  28255. const Array <int>& audioChannelsToUse_,
  28256. const int totalChans_,
  28257. const int midiBufferToUse_)
  28258. : node (node_),
  28259. processor (node_->processor),
  28260. audioChannelsToUse (audioChannelsToUse_),
  28261. totalChans (jmax (1, totalChans_)),
  28262. midiBufferToUse (midiBufferToUse_)
  28263. {
  28264. channels.calloc (totalChans);
  28265. while (audioChannelsToUse.size() < totalChans)
  28266. audioChannelsToUse.add (0);
  28267. }
  28268. ~ProcessBufferOp()
  28269. {
  28270. }
  28271. void perform (AudioSampleBuffer& sharedBufferChans, const OwnedArray <MidiBuffer>& sharedMidiBuffers, const int numSamples)
  28272. {
  28273. for (int i = totalChans; --i >= 0;)
  28274. channels[i] = sharedBufferChans.getSampleData (audioChannelsToUse.getUnchecked (i), 0);
  28275. AudioSampleBuffer buffer (channels, totalChans, numSamples);
  28276. processor->processBlock (buffer, *sharedMidiBuffers.getUnchecked (midiBufferToUse));
  28277. }
  28278. const AudioProcessorGraph::Node::Ptr node;
  28279. AudioProcessor* const processor;
  28280. private:
  28281. Array <int> audioChannelsToUse;
  28282. HeapBlock <float*> channels;
  28283. int totalChans;
  28284. int midiBufferToUse;
  28285. ProcessBufferOp (const ProcessBufferOp&);
  28286. ProcessBufferOp& operator= (const ProcessBufferOp&);
  28287. };
  28288. class RenderingOpSequenceCalculator
  28289. {
  28290. public:
  28291. RenderingOpSequenceCalculator (AudioProcessorGraph& graph_,
  28292. const VoidArray& orderedNodes_,
  28293. VoidArray& renderingOps)
  28294. : graph (graph_),
  28295. orderedNodes (orderedNodes_)
  28296. {
  28297. nodeIds.add (-2); // first buffer is read-only zeros
  28298. channels.add (0);
  28299. midiNodeIds.add (-2);
  28300. for (int i = 0; i < orderedNodes.size(); ++i)
  28301. {
  28302. createRenderingOpsForNode ((AudioProcessorGraph::Node*) orderedNodes.getUnchecked(i),
  28303. renderingOps, i);
  28304. markAnyUnusedBuffersAsFree (i);
  28305. }
  28306. }
  28307. int getNumBuffersNeeded() const { return nodeIds.size(); }
  28308. int getNumMidiBuffersNeeded() const { return midiNodeIds.size(); }
  28309. juce_UseDebuggingNewOperator
  28310. private:
  28311. AudioProcessorGraph& graph;
  28312. const VoidArray& orderedNodes;
  28313. Array <int> nodeIds, channels, midiNodeIds;
  28314. void createRenderingOpsForNode (AudioProcessorGraph::Node* const node,
  28315. VoidArray& renderingOps,
  28316. const int ourRenderingIndex)
  28317. {
  28318. const int numIns = node->processor->getNumInputChannels();
  28319. const int numOuts = node->processor->getNumOutputChannels();
  28320. const int totalChans = jmax (numIns, numOuts);
  28321. Array <int> audioChannelsToUse;
  28322. int midiBufferToUse = -1;
  28323. for (int inputChan = 0; inputChan < numIns; ++inputChan)
  28324. {
  28325. // get a list of all the inputs to this node
  28326. Array <int> sourceNodes, sourceOutputChans;
  28327. for (int i = graph.getNumConnections(); --i >= 0;)
  28328. {
  28329. const AudioProcessorGraph::Connection* const c = graph.getConnection (i);
  28330. if (c->destNodeId == node->id && c->destChannelIndex == inputChan)
  28331. {
  28332. sourceNodes.add (c->sourceNodeId);
  28333. sourceOutputChans.add (c->sourceChannelIndex);
  28334. }
  28335. }
  28336. int bufIndex = -1;
  28337. if (sourceNodes.size() == 0)
  28338. {
  28339. // unconnected input channel
  28340. if (inputChan >= numOuts)
  28341. {
  28342. bufIndex = getReadOnlyEmptyBuffer();
  28343. jassert (bufIndex >= 0);
  28344. }
  28345. else
  28346. {
  28347. bufIndex = getFreeBuffer (false);
  28348. renderingOps.add (new ClearChannelOp (bufIndex));
  28349. }
  28350. }
  28351. else if (sourceNodes.size() == 1)
  28352. {
  28353. // channel with a straightforward single input..
  28354. const int srcNode = sourceNodes.getUnchecked(0);
  28355. const int srcChan = sourceOutputChans.getUnchecked(0);
  28356. bufIndex = getBufferContaining (srcNode, srcChan);
  28357. if (bufIndex < 0)
  28358. {
  28359. // if not found, this is probably a feedback loop
  28360. bufIndex = getReadOnlyEmptyBuffer();
  28361. jassert (bufIndex >= 0);
  28362. }
  28363. if (inputChan < numOuts
  28364. && isBufferNeededLater (ourRenderingIndex,
  28365. inputChan,
  28366. srcNode, srcChan))
  28367. {
  28368. // can't mess up this channel because it's needed later by another node, so we
  28369. // need to use a copy of it..
  28370. const int newFreeBuffer = getFreeBuffer (false);
  28371. renderingOps.add (new CopyChannelOp (bufIndex, newFreeBuffer));
  28372. bufIndex = newFreeBuffer;
  28373. }
  28374. }
  28375. else
  28376. {
  28377. // channel with a mix of several inputs..
  28378. // try to find a re-usable channel from our inputs..
  28379. int reusableInputIndex = -1;
  28380. for (int i = 0; i < sourceNodes.size(); ++i)
  28381. {
  28382. const int sourceBufIndex = getBufferContaining (sourceNodes.getUnchecked(i),
  28383. sourceOutputChans.getUnchecked(i));
  28384. if (sourceBufIndex >= 0
  28385. && ! isBufferNeededLater (ourRenderingIndex,
  28386. inputChan,
  28387. sourceNodes.getUnchecked(i),
  28388. sourceOutputChans.getUnchecked(i)))
  28389. {
  28390. // we've found one of our input chans that can be re-used..
  28391. reusableInputIndex = i;
  28392. bufIndex = sourceBufIndex;
  28393. break;
  28394. }
  28395. }
  28396. if (reusableInputIndex < 0)
  28397. {
  28398. // can't re-use any of our input chans, so get a new one and copy everything into it..
  28399. bufIndex = getFreeBuffer (false);
  28400. jassert (bufIndex != 0);
  28401. const int srcIndex = getBufferContaining (sourceNodes.getUnchecked (0),
  28402. sourceOutputChans.getUnchecked (0));
  28403. if (srcIndex < 0)
  28404. {
  28405. // if not found, this is probably a feedback loop
  28406. renderingOps.add (new ClearChannelOp (bufIndex));
  28407. }
  28408. else
  28409. {
  28410. renderingOps.add (new CopyChannelOp (srcIndex, bufIndex));
  28411. }
  28412. reusableInputIndex = 0;
  28413. }
  28414. for (int j = 0; j < sourceNodes.size(); ++j)
  28415. {
  28416. if (j != reusableInputIndex)
  28417. {
  28418. const int srcIndex = getBufferContaining (sourceNodes.getUnchecked(j),
  28419. sourceOutputChans.getUnchecked(j));
  28420. if (srcIndex >= 0)
  28421. renderingOps.add (new AddChannelOp (srcIndex, bufIndex));
  28422. }
  28423. }
  28424. }
  28425. jassert (bufIndex >= 0);
  28426. audioChannelsToUse.add (bufIndex);
  28427. if (inputChan < numOuts)
  28428. markBufferAsContaining (bufIndex, node->id, inputChan);
  28429. }
  28430. for (int outputChan = numIns; outputChan < numOuts; ++outputChan)
  28431. {
  28432. const int bufIndex = getFreeBuffer (false);
  28433. jassert (bufIndex != 0);
  28434. audioChannelsToUse.add (bufIndex);
  28435. markBufferAsContaining (bufIndex, node->id, outputChan);
  28436. }
  28437. // Now the same thing for midi..
  28438. Array <int> midiSourceNodes;
  28439. for (int i = graph.getNumConnections(); --i >= 0;)
  28440. {
  28441. const AudioProcessorGraph::Connection* const c = graph.getConnection (i);
  28442. if (c->destNodeId == node->id && c->destChannelIndex == AudioProcessorGraph::midiChannelIndex)
  28443. midiSourceNodes.add (c->sourceNodeId);
  28444. }
  28445. if (midiSourceNodes.size() == 0)
  28446. {
  28447. // No midi inputs..
  28448. midiBufferToUse = getFreeBuffer (true); // need to pick a buffer even if the processor doesn't use midi
  28449. if (node->processor->acceptsMidi() || node->processor->producesMidi())
  28450. renderingOps.add (new ClearMidiBufferOp (midiBufferToUse));
  28451. }
  28452. else if (midiSourceNodes.size() == 1)
  28453. {
  28454. // One midi input..
  28455. midiBufferToUse = getBufferContaining (midiSourceNodes.getUnchecked(0),
  28456. AudioProcessorGraph::midiChannelIndex);
  28457. if (midiBufferToUse >= 0)
  28458. {
  28459. if (isBufferNeededLater (ourRenderingIndex,
  28460. AudioProcessorGraph::midiChannelIndex,
  28461. midiSourceNodes.getUnchecked(0),
  28462. AudioProcessorGraph::midiChannelIndex))
  28463. {
  28464. // can't mess up this channel because it's needed later by another node, so we
  28465. // need to use a copy of it..
  28466. const int newFreeBuffer = getFreeBuffer (true);
  28467. renderingOps.add (new CopyMidiBufferOp (midiBufferToUse, newFreeBuffer));
  28468. midiBufferToUse = newFreeBuffer;
  28469. }
  28470. }
  28471. else
  28472. {
  28473. // probably a feedback loop, so just use an empty one..
  28474. midiBufferToUse = getFreeBuffer (true); // need to pick a buffer even if the processor doesn't use midi
  28475. }
  28476. }
  28477. else
  28478. {
  28479. // More than one midi input being mixed..
  28480. int reusableInputIndex = -1;
  28481. for (int i = 0; i < midiSourceNodes.size(); ++i)
  28482. {
  28483. const int sourceBufIndex = getBufferContaining (midiSourceNodes.getUnchecked(i),
  28484. AudioProcessorGraph::midiChannelIndex);
  28485. if (sourceBufIndex >= 0
  28486. && ! isBufferNeededLater (ourRenderingIndex,
  28487. AudioProcessorGraph::midiChannelIndex,
  28488. midiSourceNodes.getUnchecked(i),
  28489. AudioProcessorGraph::midiChannelIndex))
  28490. {
  28491. // we've found one of our input buffers that can be re-used..
  28492. reusableInputIndex = i;
  28493. midiBufferToUse = sourceBufIndex;
  28494. break;
  28495. }
  28496. }
  28497. if (reusableInputIndex < 0)
  28498. {
  28499. // can't re-use any of our input buffers, so get a new one and copy everything into it..
  28500. midiBufferToUse = getFreeBuffer (true);
  28501. jassert (midiBufferToUse >= 0);
  28502. const int srcIndex = getBufferContaining (midiSourceNodes.getUnchecked(0),
  28503. AudioProcessorGraph::midiChannelIndex);
  28504. if (srcIndex >= 0)
  28505. renderingOps.add (new CopyMidiBufferOp (srcIndex, midiBufferToUse));
  28506. else
  28507. renderingOps.add (new ClearMidiBufferOp (midiBufferToUse));
  28508. reusableInputIndex = 0;
  28509. }
  28510. for (int j = 0; j < midiSourceNodes.size(); ++j)
  28511. {
  28512. if (j != reusableInputIndex)
  28513. {
  28514. const int srcIndex = getBufferContaining (midiSourceNodes.getUnchecked(j),
  28515. AudioProcessorGraph::midiChannelIndex);
  28516. if (srcIndex >= 0)
  28517. renderingOps.add (new AddMidiBufferOp (srcIndex, midiBufferToUse));
  28518. }
  28519. }
  28520. }
  28521. if (node->processor->producesMidi())
  28522. markBufferAsContaining (midiBufferToUse, node->id,
  28523. AudioProcessorGraph::midiChannelIndex);
  28524. renderingOps.add (new ProcessBufferOp (node, audioChannelsToUse,
  28525. totalChans, midiBufferToUse));
  28526. }
  28527. int getFreeBuffer (const bool forMidi)
  28528. {
  28529. if (forMidi)
  28530. {
  28531. for (int i = 1; i < midiNodeIds.size(); ++i)
  28532. if (midiNodeIds.getUnchecked(i) < 0)
  28533. return i;
  28534. midiNodeIds.add (-1);
  28535. return midiNodeIds.size() - 1;
  28536. }
  28537. else
  28538. {
  28539. for (int i = 1; i < nodeIds.size(); ++i)
  28540. if (nodeIds.getUnchecked(i) < 0)
  28541. return i;
  28542. nodeIds.add (-1);
  28543. channels.add (0);
  28544. return nodeIds.size() - 1;
  28545. }
  28546. }
  28547. int getReadOnlyEmptyBuffer() const
  28548. {
  28549. return 0;
  28550. }
  28551. int getBufferContaining (const int nodeId, const int outputChannel) const
  28552. {
  28553. if (outputChannel == AudioProcessorGraph::midiChannelIndex)
  28554. {
  28555. for (int i = midiNodeIds.size(); --i >= 0;)
  28556. if (midiNodeIds.getUnchecked(i) == nodeId)
  28557. return i;
  28558. }
  28559. else
  28560. {
  28561. for (int i = nodeIds.size(); --i >= 0;)
  28562. if (nodeIds.getUnchecked(i) == nodeId
  28563. && channels.getUnchecked(i) == outputChannel)
  28564. return i;
  28565. }
  28566. return -1;
  28567. }
  28568. void markAnyUnusedBuffersAsFree (const int stepIndex)
  28569. {
  28570. int i;
  28571. for (i = 0; i < nodeIds.size(); ++i)
  28572. {
  28573. if (nodeIds.getUnchecked(i) >= 0
  28574. && ! isBufferNeededLater (stepIndex, -1,
  28575. nodeIds.getUnchecked(i),
  28576. channels.getUnchecked(i)))
  28577. {
  28578. nodeIds.set (i, -1);
  28579. }
  28580. }
  28581. for (i = 0; i < midiNodeIds.size(); ++i)
  28582. {
  28583. if (midiNodeIds.getUnchecked(i) >= 0
  28584. && ! isBufferNeededLater (stepIndex, -1,
  28585. midiNodeIds.getUnchecked(i),
  28586. AudioProcessorGraph::midiChannelIndex))
  28587. {
  28588. midiNodeIds.set (i, -1);
  28589. }
  28590. }
  28591. }
  28592. bool isBufferNeededLater (int stepIndexToSearchFrom,
  28593. int inputChannelOfIndexToIgnore,
  28594. const int nodeId,
  28595. const int outputChanIndex) const
  28596. {
  28597. while (stepIndexToSearchFrom < orderedNodes.size())
  28598. {
  28599. const AudioProcessorGraph::Node* const node = (const AudioProcessorGraph::Node*) orderedNodes.getUnchecked (stepIndexToSearchFrom);
  28600. if (outputChanIndex == AudioProcessorGraph::midiChannelIndex)
  28601. {
  28602. if (inputChannelOfIndexToIgnore != AudioProcessorGraph::midiChannelIndex
  28603. && graph.getConnectionBetween (nodeId, AudioProcessorGraph::midiChannelIndex,
  28604. node->id, AudioProcessorGraph::midiChannelIndex) != 0)
  28605. return true;
  28606. }
  28607. else
  28608. {
  28609. for (int i = 0; i < node->processor->getNumInputChannels(); ++i)
  28610. if (i != inputChannelOfIndexToIgnore
  28611. && graph.getConnectionBetween (nodeId, outputChanIndex,
  28612. node->id, i) != 0)
  28613. return true;
  28614. }
  28615. inputChannelOfIndexToIgnore = -1;
  28616. ++stepIndexToSearchFrom;
  28617. }
  28618. return false;
  28619. }
  28620. void markBufferAsContaining (int bufferNum, int nodeId, int outputIndex)
  28621. {
  28622. if (outputIndex == AudioProcessorGraph::midiChannelIndex)
  28623. {
  28624. jassert (bufferNum > 0 && bufferNum < midiNodeIds.size());
  28625. midiNodeIds.set (bufferNum, nodeId);
  28626. }
  28627. else
  28628. {
  28629. jassert (bufferNum >= 0 && bufferNum < nodeIds.size());
  28630. nodeIds.set (bufferNum, nodeId);
  28631. channels.set (bufferNum, outputIndex);
  28632. }
  28633. }
  28634. RenderingOpSequenceCalculator (const RenderingOpSequenceCalculator&);
  28635. RenderingOpSequenceCalculator& operator= (const RenderingOpSequenceCalculator&);
  28636. };
  28637. }
  28638. void AudioProcessorGraph::clearRenderingSequence()
  28639. {
  28640. const ScopedLock sl (renderLock);
  28641. for (int i = renderingOps.size(); --i >= 0;)
  28642. {
  28643. GraphRenderingOps::AudioGraphRenderingOp* const r
  28644. = (GraphRenderingOps::AudioGraphRenderingOp*) renderingOps.getUnchecked(i);
  28645. renderingOps.remove (i);
  28646. delete r;
  28647. }
  28648. }
  28649. bool AudioProcessorGraph::isAnInputTo (const uint32 possibleInputId,
  28650. const uint32 possibleDestinationId,
  28651. const int recursionCheck) const
  28652. {
  28653. if (recursionCheck > 0)
  28654. {
  28655. for (int i = connections.size(); --i >= 0;)
  28656. {
  28657. const AudioProcessorGraph::Connection* const c = connections.getUnchecked (i);
  28658. if (c->destNodeId == possibleDestinationId
  28659. && (c->sourceNodeId == possibleInputId
  28660. || isAnInputTo (possibleInputId, c->sourceNodeId, recursionCheck - 1)))
  28661. return true;
  28662. }
  28663. }
  28664. return false;
  28665. }
  28666. void AudioProcessorGraph::buildRenderingSequence()
  28667. {
  28668. VoidArray newRenderingOps;
  28669. int numRenderingBuffersNeeded = 2;
  28670. int numMidiBuffersNeeded = 1;
  28671. {
  28672. MessageManagerLock mml;
  28673. VoidArray orderedNodes;
  28674. int i;
  28675. for (i = 0; i < nodes.size(); ++i)
  28676. {
  28677. Node* const node = nodes.getUnchecked(i);
  28678. node->prepare (getSampleRate(), getBlockSize(), this);
  28679. int j = 0;
  28680. for (; j < orderedNodes.size(); ++j)
  28681. if (isAnInputTo (node->id,
  28682. ((Node*) orderedNodes.getUnchecked (j))->id,
  28683. nodes.size() + 1))
  28684. break;
  28685. orderedNodes.insert (j, node);
  28686. }
  28687. GraphRenderingOps::RenderingOpSequenceCalculator calculator (*this, orderedNodes, newRenderingOps);
  28688. numRenderingBuffersNeeded = calculator.getNumBuffersNeeded();
  28689. numMidiBuffersNeeded = calculator.getNumMidiBuffersNeeded();
  28690. }
  28691. VoidArray oldRenderingOps (renderingOps);
  28692. {
  28693. // swap over to the new rendering sequence..
  28694. const ScopedLock sl (renderLock);
  28695. renderingBuffers.setSize (numRenderingBuffersNeeded, getBlockSize());
  28696. renderingBuffers.clear();
  28697. for (int i = midiBuffers.size(); --i >= 0;)
  28698. midiBuffers.getUnchecked(i)->clear();
  28699. while (midiBuffers.size() < numMidiBuffersNeeded)
  28700. midiBuffers.add (new MidiBuffer());
  28701. renderingOps = newRenderingOps;
  28702. }
  28703. for (int i = oldRenderingOps.size(); --i >= 0;)
  28704. delete (GraphRenderingOps::AudioGraphRenderingOp*) oldRenderingOps.getUnchecked(i);
  28705. }
  28706. void AudioProcessorGraph::handleAsyncUpdate()
  28707. {
  28708. buildRenderingSequence();
  28709. }
  28710. void AudioProcessorGraph::prepareToPlay (double /*sampleRate*/, int estimatedSamplesPerBlock)
  28711. {
  28712. currentAudioInputBuffer = 0;
  28713. currentAudioOutputBuffer.setSize (jmax (1, getNumOutputChannels()), estimatedSamplesPerBlock);
  28714. currentMidiInputBuffer = 0;
  28715. currentMidiOutputBuffer.clear();
  28716. clearRenderingSequence();
  28717. buildRenderingSequence();
  28718. }
  28719. void AudioProcessorGraph::releaseResources()
  28720. {
  28721. for (int i = 0; i < nodes.size(); ++i)
  28722. nodes.getUnchecked(i)->unprepare();
  28723. renderingBuffers.setSize (1, 1);
  28724. midiBuffers.clear();
  28725. currentAudioInputBuffer = 0;
  28726. currentAudioOutputBuffer.setSize (1, 1);
  28727. currentMidiInputBuffer = 0;
  28728. currentMidiOutputBuffer.clear();
  28729. }
  28730. void AudioProcessorGraph::processBlock (AudioSampleBuffer& buffer, MidiBuffer& midiMessages)
  28731. {
  28732. const int numSamples = buffer.getNumSamples();
  28733. const ScopedLock sl (renderLock);
  28734. currentAudioInputBuffer = &buffer;
  28735. currentAudioOutputBuffer.setSize (jmax (1, buffer.getNumChannels()), numSamples);
  28736. currentAudioOutputBuffer.clear();
  28737. currentMidiInputBuffer = &midiMessages;
  28738. currentMidiOutputBuffer.clear();
  28739. int i;
  28740. for (i = 0; i < renderingOps.size(); ++i)
  28741. {
  28742. GraphRenderingOps::AudioGraphRenderingOp* const op
  28743. = (GraphRenderingOps::AudioGraphRenderingOp*) renderingOps.getUnchecked(i);
  28744. op->perform (renderingBuffers, midiBuffers, numSamples);
  28745. }
  28746. for (i = 0; i < buffer.getNumChannels(); ++i)
  28747. buffer.copyFrom (i, 0, currentAudioOutputBuffer, i, 0, numSamples);
  28748. midiMessages.clear();
  28749. midiMessages.addEvents (currentMidiOutputBuffer, 0, buffer.getNumSamples(), 0);
  28750. }
  28751. const String AudioProcessorGraph::getInputChannelName (const int channelIndex) const
  28752. {
  28753. return "Input " + String (channelIndex + 1);
  28754. }
  28755. const String AudioProcessorGraph::getOutputChannelName (const int channelIndex) const
  28756. {
  28757. return "Output " + String (channelIndex + 1);
  28758. }
  28759. bool AudioProcessorGraph::isInputChannelStereoPair (int /*index*/) const
  28760. {
  28761. return true;
  28762. }
  28763. bool AudioProcessorGraph::isOutputChannelStereoPair (int /*index*/) const
  28764. {
  28765. return true;
  28766. }
  28767. bool AudioProcessorGraph::acceptsMidi() const
  28768. {
  28769. return true;
  28770. }
  28771. bool AudioProcessorGraph::producesMidi() const
  28772. {
  28773. return true;
  28774. }
  28775. void AudioProcessorGraph::getStateInformation (JUCE_NAMESPACE::MemoryBlock& /*destData*/)
  28776. {
  28777. }
  28778. void AudioProcessorGraph::setStateInformation (const void* /*data*/, int /*sizeInBytes*/)
  28779. {
  28780. }
  28781. AudioProcessorGraph::AudioGraphIOProcessor::AudioGraphIOProcessor (const IODeviceType type_)
  28782. : type (type_),
  28783. graph (0)
  28784. {
  28785. }
  28786. AudioProcessorGraph::AudioGraphIOProcessor::~AudioGraphIOProcessor()
  28787. {
  28788. }
  28789. const String AudioProcessorGraph::AudioGraphIOProcessor::getName() const
  28790. {
  28791. switch (type)
  28792. {
  28793. case audioOutputNode:
  28794. return "Audio Output";
  28795. case audioInputNode:
  28796. return "Audio Input";
  28797. case midiOutputNode:
  28798. return "Midi Output";
  28799. case midiInputNode:
  28800. return "Midi Input";
  28801. default:
  28802. break;
  28803. }
  28804. return String::empty;
  28805. }
  28806. void AudioProcessorGraph::AudioGraphIOProcessor::fillInPluginDescription (PluginDescription& d) const
  28807. {
  28808. d.name = getName();
  28809. d.uid = d.name.hashCode();
  28810. d.category = "I/O devices";
  28811. d.pluginFormatName = "Internal";
  28812. d.manufacturerName = "Raw Material Software";
  28813. d.version = "1.0";
  28814. d.isInstrument = false;
  28815. d.numInputChannels = getNumInputChannels();
  28816. if (type == audioOutputNode && graph != 0)
  28817. d.numInputChannels = graph->getNumInputChannels();
  28818. d.numOutputChannels = getNumOutputChannels();
  28819. if (type == audioInputNode && graph != 0)
  28820. d.numOutputChannels = graph->getNumOutputChannels();
  28821. }
  28822. void AudioProcessorGraph::AudioGraphIOProcessor::prepareToPlay (double, int)
  28823. {
  28824. jassert (graph != 0);
  28825. }
  28826. void AudioProcessorGraph::AudioGraphIOProcessor::releaseResources()
  28827. {
  28828. }
  28829. void AudioProcessorGraph::AudioGraphIOProcessor::processBlock (AudioSampleBuffer& buffer,
  28830. MidiBuffer& midiMessages)
  28831. {
  28832. jassert (graph != 0);
  28833. switch (type)
  28834. {
  28835. case audioOutputNode:
  28836. {
  28837. for (int i = jmin (graph->currentAudioOutputBuffer.getNumChannels(),
  28838. buffer.getNumChannels()); --i >= 0;)
  28839. {
  28840. graph->currentAudioOutputBuffer.addFrom (i, 0, buffer, i, 0, buffer.getNumSamples());
  28841. }
  28842. break;
  28843. }
  28844. case audioInputNode:
  28845. {
  28846. for (int i = jmin (graph->currentAudioInputBuffer->getNumChannels(),
  28847. buffer.getNumChannels()); --i >= 0;)
  28848. {
  28849. buffer.copyFrom (i, 0, *graph->currentAudioInputBuffer, i, 0, buffer.getNumSamples());
  28850. }
  28851. break;
  28852. }
  28853. case midiOutputNode:
  28854. graph->currentMidiOutputBuffer.addEvents (midiMessages, 0, buffer.getNumSamples(), 0);
  28855. break;
  28856. case midiInputNode:
  28857. midiMessages.addEvents (*graph->currentMidiInputBuffer, 0, buffer.getNumSamples(), 0);
  28858. break;
  28859. default:
  28860. break;
  28861. }
  28862. }
  28863. bool AudioProcessorGraph::AudioGraphIOProcessor::acceptsMidi() const
  28864. {
  28865. return type == midiOutputNode;
  28866. }
  28867. bool AudioProcessorGraph::AudioGraphIOProcessor::producesMidi() const
  28868. {
  28869. return type == midiInputNode;
  28870. }
  28871. const String AudioProcessorGraph::AudioGraphIOProcessor::getInputChannelName (const int channelIndex) const
  28872. {
  28873. switch (type)
  28874. {
  28875. case audioOutputNode:
  28876. return "Output " + String (channelIndex + 1);
  28877. case midiOutputNode:
  28878. return "Midi Output";
  28879. default:
  28880. break;
  28881. }
  28882. return String::empty;
  28883. }
  28884. const String AudioProcessorGraph::AudioGraphIOProcessor::getOutputChannelName (const int channelIndex) const
  28885. {
  28886. switch (type)
  28887. {
  28888. case audioInputNode:
  28889. return "Input " + String (channelIndex + 1);
  28890. case midiInputNode:
  28891. return "Midi Input";
  28892. default:
  28893. break;
  28894. }
  28895. return String::empty;
  28896. }
  28897. bool AudioProcessorGraph::AudioGraphIOProcessor::isInputChannelStereoPair (int /*index*/) const
  28898. {
  28899. return type == audioInputNode || type == audioOutputNode;
  28900. }
  28901. bool AudioProcessorGraph::AudioGraphIOProcessor::isOutputChannelStereoPair (int index) const
  28902. {
  28903. return isInputChannelStereoPair (index);
  28904. }
  28905. bool AudioProcessorGraph::AudioGraphIOProcessor::isInput() const
  28906. {
  28907. return type == audioInputNode || type == midiInputNode;
  28908. }
  28909. bool AudioProcessorGraph::AudioGraphIOProcessor::isOutput() const
  28910. {
  28911. return type == audioOutputNode || type == midiOutputNode;
  28912. }
  28913. AudioProcessorEditor* AudioProcessorGraph::AudioGraphIOProcessor::createEditor()
  28914. {
  28915. return 0;
  28916. }
  28917. int AudioProcessorGraph::AudioGraphIOProcessor::getNumParameters() { return 0; }
  28918. const String AudioProcessorGraph::AudioGraphIOProcessor::getParameterName (int) { return String::empty; }
  28919. float AudioProcessorGraph::AudioGraphIOProcessor::getParameter (int) { return 0.0f; }
  28920. const String AudioProcessorGraph::AudioGraphIOProcessor::getParameterText (int) { return String::empty; }
  28921. void AudioProcessorGraph::AudioGraphIOProcessor::setParameter (int, float) { }
  28922. int AudioProcessorGraph::AudioGraphIOProcessor::getNumPrograms() { return 0; }
  28923. int AudioProcessorGraph::AudioGraphIOProcessor::getCurrentProgram() { return 0; }
  28924. void AudioProcessorGraph::AudioGraphIOProcessor::setCurrentProgram (int) { }
  28925. const String AudioProcessorGraph::AudioGraphIOProcessor::getProgramName (int) { return String::empty; }
  28926. void AudioProcessorGraph::AudioGraphIOProcessor::changeProgramName (int, const String&) { }
  28927. void AudioProcessorGraph::AudioGraphIOProcessor::getStateInformation (JUCE_NAMESPACE::MemoryBlock&)
  28928. {
  28929. }
  28930. void AudioProcessorGraph::AudioGraphIOProcessor::setStateInformation (const void*, int)
  28931. {
  28932. }
  28933. void AudioProcessorGraph::AudioGraphIOProcessor::setParentGraph (AudioProcessorGraph* const newGraph)
  28934. {
  28935. graph = newGraph;
  28936. if (graph != 0)
  28937. {
  28938. setPlayConfigDetails (type == audioOutputNode ? graph->getNumOutputChannels() : 0,
  28939. type == audioInputNode ? graph->getNumInputChannels() : 0,
  28940. getSampleRate(),
  28941. getBlockSize());
  28942. updateHostDisplay();
  28943. }
  28944. }
  28945. END_JUCE_NAMESPACE
  28946. /*** End of inlined file: juce_AudioProcessorGraph.cpp ***/
  28947. /*** Start of inlined file: juce_AudioProcessorPlayer.cpp ***/
  28948. BEGIN_JUCE_NAMESPACE
  28949. AudioProcessorPlayer::AudioProcessorPlayer()
  28950. : processor (0),
  28951. sampleRate (0),
  28952. blockSize (0),
  28953. isPrepared (false),
  28954. numInputChans (0),
  28955. numOutputChans (0),
  28956. tempBuffer (1, 1)
  28957. {
  28958. }
  28959. AudioProcessorPlayer::~AudioProcessorPlayer()
  28960. {
  28961. setProcessor (0);
  28962. }
  28963. void AudioProcessorPlayer::setProcessor (AudioProcessor* const processorToPlay)
  28964. {
  28965. if (processor != processorToPlay)
  28966. {
  28967. if (processorToPlay != 0 && sampleRate > 0 && blockSize > 0)
  28968. {
  28969. processorToPlay->setPlayConfigDetails (numInputChans, numOutputChans,
  28970. sampleRate, blockSize);
  28971. processorToPlay->prepareToPlay (sampleRate, blockSize);
  28972. }
  28973. AudioProcessor* oldOne;
  28974. {
  28975. const ScopedLock sl (lock);
  28976. oldOne = isPrepared ? processor : 0;
  28977. processor = processorToPlay;
  28978. isPrepared = true;
  28979. }
  28980. if (oldOne != 0)
  28981. oldOne->releaseResources();
  28982. }
  28983. }
  28984. void AudioProcessorPlayer::audioDeviceIOCallback (const float** inputChannelData,
  28985. int numInputChannels,
  28986. float** outputChannelData,
  28987. int numOutputChannels,
  28988. int numSamples)
  28989. {
  28990. // these should have been prepared by audioDeviceAboutToStart()...
  28991. jassert (sampleRate > 0 && blockSize > 0);
  28992. incomingMidi.clear();
  28993. messageCollector.removeNextBlockOfMessages (incomingMidi, numSamples);
  28994. int i, totalNumChans = 0;
  28995. if (numInputChannels > numOutputChannels)
  28996. {
  28997. // if there aren't enough output channels for the number of
  28998. // inputs, we need to create some temporary extra ones (can't
  28999. // use the input data in case it gets written to)
  29000. tempBuffer.setSize (numInputChannels - numOutputChannels, numSamples,
  29001. false, false, true);
  29002. for (i = 0; i < numOutputChannels; ++i)
  29003. {
  29004. channels[totalNumChans] = outputChannelData[i];
  29005. memcpy (channels[totalNumChans], inputChannelData[i], sizeof (float) * numSamples);
  29006. ++totalNumChans;
  29007. }
  29008. for (i = numOutputChannels; i < numInputChannels; ++i)
  29009. {
  29010. channels[totalNumChans] = tempBuffer.getSampleData (i - numOutputChannels, 0);
  29011. memcpy (channels[totalNumChans], inputChannelData[i], sizeof (float) * numSamples);
  29012. ++totalNumChans;
  29013. }
  29014. }
  29015. else
  29016. {
  29017. for (i = 0; i < numInputChannels; ++i)
  29018. {
  29019. channels[totalNumChans] = outputChannelData[i];
  29020. memcpy (channels[totalNumChans], inputChannelData[i], sizeof (float) * numSamples);
  29021. ++totalNumChans;
  29022. }
  29023. for (i = numInputChannels; i < numOutputChannels; ++i)
  29024. {
  29025. channels[totalNumChans] = outputChannelData[i];
  29026. zeromem (channels[totalNumChans], sizeof (float) * numSamples);
  29027. ++totalNumChans;
  29028. }
  29029. }
  29030. AudioSampleBuffer buffer (channels, totalNumChans, numSamples);
  29031. const ScopedLock sl (lock);
  29032. if (processor != 0)
  29033. processor->processBlock (buffer, incomingMidi);
  29034. }
  29035. void AudioProcessorPlayer::audioDeviceAboutToStart (AudioIODevice* device)
  29036. {
  29037. const ScopedLock sl (lock);
  29038. sampleRate = device->getCurrentSampleRate();
  29039. blockSize = device->getCurrentBufferSizeSamples();
  29040. numInputChans = device->getActiveInputChannels().countNumberOfSetBits();
  29041. numOutputChans = device->getActiveOutputChannels().countNumberOfSetBits();
  29042. messageCollector.reset (sampleRate);
  29043. zeromem (channels, sizeof (channels));
  29044. if (processor != 0)
  29045. {
  29046. if (isPrepared)
  29047. processor->releaseResources();
  29048. AudioProcessor* const oldProcessor = processor;
  29049. setProcessor (0);
  29050. setProcessor (oldProcessor);
  29051. }
  29052. }
  29053. void AudioProcessorPlayer::audioDeviceStopped()
  29054. {
  29055. const ScopedLock sl (lock);
  29056. if (processor != 0 && isPrepared)
  29057. processor->releaseResources();
  29058. sampleRate = 0.0;
  29059. blockSize = 0;
  29060. isPrepared = false;
  29061. tempBuffer.setSize (1, 1);
  29062. }
  29063. void AudioProcessorPlayer::handleIncomingMidiMessage (MidiInput*, const MidiMessage& message)
  29064. {
  29065. messageCollector.addMessageToQueue (message);
  29066. }
  29067. END_JUCE_NAMESPACE
  29068. /*** End of inlined file: juce_AudioProcessorPlayer.cpp ***/
  29069. /*** Start of inlined file: juce_GenericAudioProcessorEditor.cpp ***/
  29070. BEGIN_JUCE_NAMESPACE
  29071. class ProcessorParameterPropertyComp : public PropertyComponent,
  29072. public AudioProcessorListener,
  29073. public AsyncUpdater
  29074. {
  29075. public:
  29076. ProcessorParameterPropertyComp (const String& name,
  29077. AudioProcessor* const owner_,
  29078. const int index_)
  29079. : PropertyComponent (name),
  29080. owner (owner_),
  29081. index (index_)
  29082. {
  29083. addAndMakeVisible (slider = new ParamSlider (owner_, index_));
  29084. owner_->addListener (this);
  29085. }
  29086. ~ProcessorParameterPropertyComp()
  29087. {
  29088. owner->removeListener (this);
  29089. deleteAllChildren();
  29090. }
  29091. void refresh()
  29092. {
  29093. slider->setValue (owner->getParameter (index), false);
  29094. }
  29095. void audioProcessorChanged (AudioProcessor*) {}
  29096. void audioProcessorParameterChanged (AudioProcessor*, int parameterIndex, float)
  29097. {
  29098. if (parameterIndex == index)
  29099. triggerAsyncUpdate();
  29100. }
  29101. void handleAsyncUpdate()
  29102. {
  29103. refresh();
  29104. }
  29105. juce_UseDebuggingNewOperator
  29106. private:
  29107. AudioProcessor* const owner;
  29108. const int index;
  29109. Slider* slider;
  29110. class ParamSlider : public Slider
  29111. {
  29112. public:
  29113. ParamSlider (AudioProcessor* const owner_, const int index_)
  29114. : Slider (String::empty),
  29115. owner (owner_),
  29116. index (index_)
  29117. {
  29118. setRange (0.0, 1.0, 0.0);
  29119. setSliderStyle (Slider::LinearBar);
  29120. setTextBoxIsEditable (false);
  29121. setScrollWheelEnabled (false);
  29122. }
  29123. ~ParamSlider()
  29124. {
  29125. }
  29126. void valueChanged()
  29127. {
  29128. const float newVal = (float) getValue();
  29129. if (owner->getParameter (index) != newVal)
  29130. owner->setParameter (index, newVal);
  29131. }
  29132. const String getTextFromValue (double /*value*/)
  29133. {
  29134. return owner->getParameterText (index);
  29135. }
  29136. juce_UseDebuggingNewOperator
  29137. private:
  29138. AudioProcessor* const owner;
  29139. const int index;
  29140. ParamSlider (const ParamSlider&);
  29141. ParamSlider& operator= (const ParamSlider&);
  29142. };
  29143. ProcessorParameterPropertyComp (const ProcessorParameterPropertyComp&);
  29144. ProcessorParameterPropertyComp& operator= (const ProcessorParameterPropertyComp&);
  29145. };
  29146. GenericAudioProcessorEditor::GenericAudioProcessorEditor (AudioProcessor* const owner_)
  29147. : AudioProcessorEditor (owner_)
  29148. {
  29149. setOpaque (true);
  29150. addAndMakeVisible (panel = new PropertyPanel());
  29151. Array <PropertyComponent*> params;
  29152. const int numParams = owner_->getNumParameters();
  29153. int totalHeight = 0;
  29154. for (int i = 0; i < numParams; ++i)
  29155. {
  29156. String name (owner_->getParameterName (i));
  29157. if (name.trim().isEmpty())
  29158. name = "Unnamed";
  29159. ProcessorParameterPropertyComp* const pc = new ProcessorParameterPropertyComp (name, owner_, i);
  29160. params.add (pc);
  29161. totalHeight += pc->getPreferredHeight();
  29162. }
  29163. panel->addProperties (params);
  29164. setSize (400, jlimit (25, 400, totalHeight));
  29165. }
  29166. GenericAudioProcessorEditor::~GenericAudioProcessorEditor()
  29167. {
  29168. deleteAllChildren();
  29169. }
  29170. void GenericAudioProcessorEditor::paint (Graphics& g)
  29171. {
  29172. g.fillAll (Colours::white);
  29173. }
  29174. void GenericAudioProcessorEditor::resized()
  29175. {
  29176. panel->setSize (getWidth(), getHeight());
  29177. }
  29178. END_JUCE_NAMESPACE
  29179. /*** End of inlined file: juce_GenericAudioProcessorEditor.cpp ***/
  29180. /*** Start of inlined file: juce_Sampler.cpp ***/
  29181. BEGIN_JUCE_NAMESPACE
  29182. SamplerSound::SamplerSound (const String& name_,
  29183. AudioFormatReader& source,
  29184. const BigInteger& midiNotes_,
  29185. const int midiNoteForNormalPitch,
  29186. const double attackTimeSecs,
  29187. const double releaseTimeSecs,
  29188. const double maxSampleLengthSeconds)
  29189. : name (name_),
  29190. midiNotes (midiNotes_),
  29191. midiRootNote (midiNoteForNormalPitch)
  29192. {
  29193. sourceSampleRate = source.sampleRate;
  29194. if (sourceSampleRate <= 0 || source.lengthInSamples <= 0)
  29195. {
  29196. length = 0;
  29197. attackSamples = 0;
  29198. releaseSamples = 0;
  29199. }
  29200. else
  29201. {
  29202. length = jmin ((int) source.lengthInSamples,
  29203. (int) (maxSampleLengthSeconds * sourceSampleRate));
  29204. data = new AudioSampleBuffer (jmin (2, (int) source.numChannels), length + 4);
  29205. data->readFromAudioReader (&source, 0, length + 4, 0, true, true);
  29206. attackSamples = roundToInt (attackTimeSecs * sourceSampleRate);
  29207. releaseSamples = roundToInt (releaseTimeSecs * sourceSampleRate);
  29208. }
  29209. }
  29210. SamplerSound::~SamplerSound()
  29211. {
  29212. }
  29213. bool SamplerSound::appliesToNote (const int midiNoteNumber)
  29214. {
  29215. return midiNotes [midiNoteNumber];
  29216. }
  29217. bool SamplerSound::appliesToChannel (const int /*midiChannel*/)
  29218. {
  29219. return true;
  29220. }
  29221. SamplerVoice::SamplerVoice()
  29222. : pitchRatio (0.0),
  29223. sourceSamplePosition (0.0),
  29224. lgain (0.0f),
  29225. rgain (0.0f),
  29226. isInAttack (false),
  29227. isInRelease (false)
  29228. {
  29229. }
  29230. SamplerVoice::~SamplerVoice()
  29231. {
  29232. }
  29233. bool SamplerVoice::canPlaySound (SynthesiserSound* sound)
  29234. {
  29235. return dynamic_cast <const SamplerSound*> (sound) != 0;
  29236. }
  29237. void SamplerVoice::startNote (const int midiNoteNumber,
  29238. const float velocity,
  29239. SynthesiserSound* s,
  29240. const int /*currentPitchWheelPosition*/)
  29241. {
  29242. const SamplerSound* const sound = dynamic_cast <const SamplerSound*> (s);
  29243. jassert (sound != 0); // this object can only play SamplerSounds!
  29244. if (sound != 0)
  29245. {
  29246. const double targetFreq = MidiMessage::getMidiNoteInHertz (midiNoteNumber);
  29247. const double naturalFreq = MidiMessage::getMidiNoteInHertz (sound->midiRootNote);
  29248. pitchRatio = (targetFreq * sound->sourceSampleRate) / (naturalFreq * getSampleRate());
  29249. sourceSamplePosition = 0.0;
  29250. lgain = velocity;
  29251. rgain = velocity;
  29252. isInAttack = (sound->attackSamples > 0);
  29253. isInRelease = false;
  29254. if (isInAttack)
  29255. {
  29256. attackReleaseLevel = 0.0f;
  29257. attackDelta = (float) (pitchRatio / sound->attackSamples);
  29258. }
  29259. else
  29260. {
  29261. attackReleaseLevel = 1.0f;
  29262. attackDelta = 0.0f;
  29263. }
  29264. if (sound->releaseSamples > 0)
  29265. {
  29266. releaseDelta = (float) (-pitchRatio / sound->releaseSamples);
  29267. }
  29268. else
  29269. {
  29270. releaseDelta = 0.0f;
  29271. }
  29272. }
  29273. }
  29274. void SamplerVoice::stopNote (const bool allowTailOff)
  29275. {
  29276. if (allowTailOff)
  29277. {
  29278. isInAttack = false;
  29279. isInRelease = true;
  29280. }
  29281. else
  29282. {
  29283. clearCurrentNote();
  29284. }
  29285. }
  29286. void SamplerVoice::pitchWheelMoved (const int /*newValue*/)
  29287. {
  29288. }
  29289. void SamplerVoice::controllerMoved (const int /*controllerNumber*/,
  29290. const int /*newValue*/)
  29291. {
  29292. }
  29293. void SamplerVoice::renderNextBlock (AudioSampleBuffer& outputBuffer, int startSample, int numSamples)
  29294. {
  29295. const SamplerSound* const playingSound = (SamplerSound*) (SynthesiserSound*) getCurrentlyPlayingSound();
  29296. if (playingSound != 0)
  29297. {
  29298. const float* const inL = playingSound->data->getSampleData (0, 0);
  29299. const float* const inR = playingSound->data->getNumChannels() > 1
  29300. ? playingSound->data->getSampleData (1, 0) : 0;
  29301. float* outL = outputBuffer.getSampleData (0, startSample);
  29302. float* outR = outputBuffer.getNumChannels() > 1 ? outputBuffer.getSampleData (1, startSample) : 0;
  29303. while (--numSamples >= 0)
  29304. {
  29305. const int pos = (int) sourceSamplePosition;
  29306. const float alpha = (float) (sourceSamplePosition - pos);
  29307. const float invAlpha = 1.0f - alpha;
  29308. // just using a very simple linear interpolation here..
  29309. float l = (inL [pos] * invAlpha + inL [pos + 1] * alpha);
  29310. float r = (inR != 0) ? (inR [pos] * invAlpha + inR [pos + 1] * alpha)
  29311. : l;
  29312. l *= lgain;
  29313. r *= rgain;
  29314. if (isInAttack)
  29315. {
  29316. l *= attackReleaseLevel;
  29317. r *= attackReleaseLevel;
  29318. attackReleaseLevel += attackDelta;
  29319. if (attackReleaseLevel >= 1.0f)
  29320. {
  29321. attackReleaseLevel = 1.0f;
  29322. isInAttack = false;
  29323. }
  29324. }
  29325. else if (isInRelease)
  29326. {
  29327. l *= attackReleaseLevel;
  29328. r *= attackReleaseLevel;
  29329. attackReleaseLevel += releaseDelta;
  29330. if (attackReleaseLevel <= 0.0f)
  29331. {
  29332. stopNote (false);
  29333. break;
  29334. }
  29335. }
  29336. if (outR != 0)
  29337. {
  29338. *outL++ += l;
  29339. *outR++ += r;
  29340. }
  29341. else
  29342. {
  29343. *outL++ += (l + r) * 0.5f;
  29344. }
  29345. sourceSamplePosition += pitchRatio;
  29346. if (sourceSamplePosition > playingSound->length)
  29347. {
  29348. stopNote (false);
  29349. break;
  29350. }
  29351. }
  29352. }
  29353. }
  29354. END_JUCE_NAMESPACE
  29355. /*** End of inlined file: juce_Sampler.cpp ***/
  29356. /*** Start of inlined file: juce_Synthesiser.cpp ***/
  29357. BEGIN_JUCE_NAMESPACE
  29358. SynthesiserSound::SynthesiserSound()
  29359. {
  29360. }
  29361. SynthesiserSound::~SynthesiserSound()
  29362. {
  29363. }
  29364. SynthesiserVoice::SynthesiserVoice()
  29365. : currentSampleRate (44100.0),
  29366. currentlyPlayingNote (-1),
  29367. noteOnTime (0),
  29368. currentlyPlayingSound (0)
  29369. {
  29370. }
  29371. SynthesiserVoice::~SynthesiserVoice()
  29372. {
  29373. }
  29374. bool SynthesiserVoice::isPlayingChannel (const int midiChannel) const
  29375. {
  29376. return currentlyPlayingSound != 0
  29377. && currentlyPlayingSound->appliesToChannel (midiChannel);
  29378. }
  29379. void SynthesiserVoice::setCurrentPlaybackSampleRate (const double newRate)
  29380. {
  29381. currentSampleRate = newRate;
  29382. }
  29383. void SynthesiserVoice::clearCurrentNote()
  29384. {
  29385. currentlyPlayingNote = -1;
  29386. currentlyPlayingSound = 0;
  29387. }
  29388. Synthesiser::Synthesiser()
  29389. : sampleRate (0),
  29390. lastNoteOnCounter (0),
  29391. shouldStealNotes (true)
  29392. {
  29393. for (int i = 0; i < numElementsInArray (lastPitchWheelValues); ++i)
  29394. lastPitchWheelValues[i] = 0x2000;
  29395. }
  29396. Synthesiser::~Synthesiser()
  29397. {
  29398. }
  29399. SynthesiserVoice* Synthesiser::getVoice (const int index) const
  29400. {
  29401. const ScopedLock sl (lock);
  29402. return voices [index];
  29403. }
  29404. void Synthesiser::clearVoices()
  29405. {
  29406. const ScopedLock sl (lock);
  29407. voices.clear();
  29408. }
  29409. void Synthesiser::addVoice (SynthesiserVoice* const newVoice)
  29410. {
  29411. const ScopedLock sl (lock);
  29412. voices.add (newVoice);
  29413. }
  29414. void Synthesiser::removeVoice (const int index)
  29415. {
  29416. const ScopedLock sl (lock);
  29417. voices.remove (index);
  29418. }
  29419. void Synthesiser::clearSounds()
  29420. {
  29421. const ScopedLock sl (lock);
  29422. sounds.clear();
  29423. }
  29424. void Synthesiser::addSound (const SynthesiserSound::Ptr& newSound)
  29425. {
  29426. const ScopedLock sl (lock);
  29427. sounds.add (newSound);
  29428. }
  29429. void Synthesiser::removeSound (const int index)
  29430. {
  29431. const ScopedLock sl (lock);
  29432. sounds.remove (index);
  29433. }
  29434. void Synthesiser::setNoteStealingEnabled (const bool shouldStealNotes_)
  29435. {
  29436. shouldStealNotes = shouldStealNotes_;
  29437. }
  29438. void Synthesiser::setCurrentPlaybackSampleRate (const double newRate)
  29439. {
  29440. if (sampleRate != newRate)
  29441. {
  29442. const ScopedLock sl (lock);
  29443. allNotesOff (0, false);
  29444. sampleRate = newRate;
  29445. for (int i = voices.size(); --i >= 0;)
  29446. voices.getUnchecked (i)->setCurrentPlaybackSampleRate (newRate);
  29447. }
  29448. }
  29449. void Synthesiser::renderNextBlock (AudioSampleBuffer& outputBuffer,
  29450. const MidiBuffer& midiData,
  29451. int startSample,
  29452. int numSamples)
  29453. {
  29454. // must set the sample rate before using this!
  29455. jassert (sampleRate != 0);
  29456. const ScopedLock sl (lock);
  29457. MidiBuffer::Iterator midiIterator (midiData);
  29458. midiIterator.setNextSamplePosition (startSample);
  29459. MidiMessage m (0xf4, 0.0);
  29460. while (numSamples > 0)
  29461. {
  29462. int midiEventPos;
  29463. const bool useEvent = midiIterator.getNextEvent (m, midiEventPos)
  29464. && midiEventPos < startSample + numSamples;
  29465. const int numThisTime = useEvent ? midiEventPos - startSample
  29466. : numSamples;
  29467. if (numThisTime > 0)
  29468. {
  29469. for (int i = voices.size(); --i >= 0;)
  29470. voices.getUnchecked (i)->renderNextBlock (outputBuffer, startSample, numThisTime);
  29471. }
  29472. if (useEvent)
  29473. {
  29474. if (m.isNoteOn())
  29475. {
  29476. const int channel = m.getChannel();
  29477. noteOn (channel,
  29478. m.getNoteNumber(),
  29479. m.getFloatVelocity());
  29480. }
  29481. else if (m.isNoteOff())
  29482. {
  29483. noteOff (m.getChannel(),
  29484. m.getNoteNumber(),
  29485. true);
  29486. }
  29487. else if (m.isAllNotesOff() || m.isAllSoundOff())
  29488. {
  29489. allNotesOff (m.getChannel(), true);
  29490. }
  29491. else if (m.isPitchWheel())
  29492. {
  29493. const int channel = m.getChannel();
  29494. const int wheelPos = m.getPitchWheelValue();
  29495. lastPitchWheelValues [channel - 1] = wheelPos;
  29496. handlePitchWheel (channel, wheelPos);
  29497. }
  29498. else if (m.isController())
  29499. {
  29500. handleController (m.getChannel(),
  29501. m.getControllerNumber(),
  29502. m.getControllerValue());
  29503. }
  29504. }
  29505. startSample += numThisTime;
  29506. numSamples -= numThisTime;
  29507. }
  29508. }
  29509. void Synthesiser::noteOn (const int midiChannel,
  29510. const int midiNoteNumber,
  29511. const float velocity)
  29512. {
  29513. const ScopedLock sl (lock);
  29514. for (int i = sounds.size(); --i >= 0;)
  29515. {
  29516. SynthesiserSound* const sound = sounds.getUnchecked(i);
  29517. if (sound->appliesToNote (midiNoteNumber)
  29518. && sound->appliesToChannel (midiChannel))
  29519. {
  29520. startVoice (findFreeVoice (sound, shouldStealNotes),
  29521. sound, midiChannel, midiNoteNumber, velocity);
  29522. }
  29523. }
  29524. }
  29525. void Synthesiser::startVoice (SynthesiserVoice* const voice,
  29526. SynthesiserSound* const sound,
  29527. const int midiChannel,
  29528. const int midiNoteNumber,
  29529. const float velocity)
  29530. {
  29531. if (voice != 0 && sound != 0)
  29532. {
  29533. if (voice->currentlyPlayingSound != 0)
  29534. voice->stopNote (false);
  29535. voice->startNote (midiNoteNumber,
  29536. velocity,
  29537. sound,
  29538. lastPitchWheelValues [midiChannel - 1]);
  29539. voice->currentlyPlayingNote = midiNoteNumber;
  29540. voice->noteOnTime = ++lastNoteOnCounter;
  29541. voice->currentlyPlayingSound = sound;
  29542. }
  29543. }
  29544. void Synthesiser::noteOff (const int midiChannel,
  29545. const int midiNoteNumber,
  29546. const bool allowTailOff)
  29547. {
  29548. const ScopedLock sl (lock);
  29549. for (int i = voices.size(); --i >= 0;)
  29550. {
  29551. SynthesiserVoice* const voice = voices.getUnchecked (i);
  29552. if (voice->getCurrentlyPlayingNote() == midiNoteNumber)
  29553. {
  29554. SynthesiserSound* const sound = voice->getCurrentlyPlayingSound();
  29555. if (sound != 0
  29556. && sound->appliesToNote (midiNoteNumber)
  29557. && sound->appliesToChannel (midiChannel))
  29558. {
  29559. voice->stopNote (allowTailOff);
  29560. // the subclass MUST call clearCurrentNote() if it's not tailing off! RTFM for stopNote()!
  29561. jassert (allowTailOff || (voice->getCurrentlyPlayingNote() < 0 && voice->getCurrentlyPlayingSound() == 0));
  29562. }
  29563. }
  29564. }
  29565. }
  29566. void Synthesiser::allNotesOff (const int midiChannel,
  29567. const bool allowTailOff)
  29568. {
  29569. const ScopedLock sl (lock);
  29570. for (int i = voices.size(); --i >= 0;)
  29571. {
  29572. SynthesiserVoice* const voice = voices.getUnchecked (i);
  29573. if (midiChannel <= 0 || voice->isPlayingChannel (midiChannel))
  29574. voice->stopNote (allowTailOff);
  29575. }
  29576. }
  29577. void Synthesiser::handlePitchWheel (const int midiChannel,
  29578. const int wheelValue)
  29579. {
  29580. const ScopedLock sl (lock);
  29581. for (int i = voices.size(); --i >= 0;)
  29582. {
  29583. SynthesiserVoice* const voice = voices.getUnchecked (i);
  29584. if (midiChannel <= 0 || voice->isPlayingChannel (midiChannel))
  29585. {
  29586. voice->pitchWheelMoved (wheelValue);
  29587. }
  29588. }
  29589. }
  29590. void Synthesiser::handleController (const int midiChannel,
  29591. const int controllerNumber,
  29592. const int controllerValue)
  29593. {
  29594. const ScopedLock sl (lock);
  29595. for (int i = voices.size(); --i >= 0;)
  29596. {
  29597. SynthesiserVoice* const voice = voices.getUnchecked (i);
  29598. if (midiChannel <= 0 || voice->isPlayingChannel (midiChannel))
  29599. voice->controllerMoved (controllerNumber, controllerValue);
  29600. }
  29601. }
  29602. SynthesiserVoice* Synthesiser::findFreeVoice (SynthesiserSound* soundToPlay,
  29603. const bool stealIfNoneAvailable) const
  29604. {
  29605. const ScopedLock sl (lock);
  29606. for (int i = voices.size(); --i >= 0;)
  29607. if (voices.getUnchecked (i)->getCurrentlyPlayingNote() < 0
  29608. && voices.getUnchecked (i)->canPlaySound (soundToPlay))
  29609. return voices.getUnchecked (i);
  29610. if (stealIfNoneAvailable)
  29611. {
  29612. // currently this just steals the one that's been playing the longest, but could be made a bit smarter..
  29613. SynthesiserVoice* oldest = 0;
  29614. for (int i = voices.size(); --i >= 0;)
  29615. {
  29616. SynthesiserVoice* const voice = voices.getUnchecked (i);
  29617. if (voice->canPlaySound (soundToPlay)
  29618. && (oldest == 0 || oldest->noteOnTime > voice->noteOnTime))
  29619. oldest = voice;
  29620. }
  29621. jassert (oldest != 0);
  29622. return oldest;
  29623. }
  29624. return 0;
  29625. }
  29626. END_JUCE_NAMESPACE
  29627. /*** End of inlined file: juce_Synthesiser.cpp ***/
  29628. /*** Start of inlined file: juce_ActionBroadcaster.cpp ***/
  29629. BEGIN_JUCE_NAMESPACE
  29630. ActionBroadcaster::ActionBroadcaster() throw()
  29631. {
  29632. // are you trying to create this object before or after juce has been intialised??
  29633. jassert (MessageManager::instance != 0);
  29634. }
  29635. ActionBroadcaster::~ActionBroadcaster()
  29636. {
  29637. // all event-based objects must be deleted BEFORE juce is shut down!
  29638. jassert (MessageManager::instance != 0);
  29639. }
  29640. void ActionBroadcaster::addActionListener (ActionListener* const listener)
  29641. {
  29642. actionListenerList.addActionListener (listener);
  29643. }
  29644. void ActionBroadcaster::removeActionListener (ActionListener* const listener)
  29645. {
  29646. jassert (actionListenerList.isValidMessageListener());
  29647. if (actionListenerList.isValidMessageListener())
  29648. actionListenerList.removeActionListener (listener);
  29649. }
  29650. void ActionBroadcaster::removeAllActionListeners()
  29651. {
  29652. actionListenerList.removeAllActionListeners();
  29653. }
  29654. void ActionBroadcaster::sendActionMessage (const String& message) const
  29655. {
  29656. actionListenerList.sendActionMessage (message);
  29657. }
  29658. END_JUCE_NAMESPACE
  29659. /*** End of inlined file: juce_ActionBroadcaster.cpp ***/
  29660. /*** Start of inlined file: juce_ActionListenerList.cpp ***/
  29661. BEGIN_JUCE_NAMESPACE
  29662. // special message of our own with a string in it
  29663. class ActionMessage : public Message
  29664. {
  29665. public:
  29666. const String message;
  29667. ActionMessage (const String& messageText,
  29668. void* const listener_) throw()
  29669. : message (messageText)
  29670. {
  29671. pointerParameter = listener_;
  29672. }
  29673. ~ActionMessage() throw()
  29674. {
  29675. }
  29676. private:
  29677. ActionMessage (const ActionMessage&);
  29678. ActionMessage& operator= (const ActionMessage&);
  29679. };
  29680. ActionListenerList::ActionListenerList() throw()
  29681. {
  29682. }
  29683. ActionListenerList::~ActionListenerList() throw()
  29684. {
  29685. }
  29686. void ActionListenerList::addActionListener (ActionListener* const listener) throw()
  29687. {
  29688. const ScopedLock sl (actionListenerLock_);
  29689. jassert (listener != 0);
  29690. jassert (! actionListeners_.contains (listener)); // trying to add a listener to the list twice!
  29691. if (listener != 0)
  29692. actionListeners_.add (listener);
  29693. }
  29694. void ActionListenerList::removeActionListener (ActionListener* const listener) throw()
  29695. {
  29696. const ScopedLock sl (actionListenerLock_);
  29697. jassert (actionListeners_.contains (listener)); // trying to remove a listener that isn't on the list!
  29698. actionListeners_.removeValue (listener);
  29699. }
  29700. void ActionListenerList::removeAllActionListeners() throw()
  29701. {
  29702. const ScopedLock sl (actionListenerLock_);
  29703. actionListeners_.clear();
  29704. }
  29705. void ActionListenerList::sendActionMessage (const String& message) const
  29706. {
  29707. const ScopedLock sl (actionListenerLock_);
  29708. for (int i = actionListeners_.size(); --i >= 0;)
  29709. {
  29710. postMessage (new ActionMessage (message,
  29711. (ActionListener*) actionListeners_.getUnchecked(i)));
  29712. }
  29713. }
  29714. void ActionListenerList::handleMessage (const Message& message)
  29715. {
  29716. const ActionMessage& am = (const ActionMessage&) message;
  29717. if (actionListeners_.contains (am.pointerParameter))
  29718. ((ActionListener*) am.pointerParameter)->actionListenerCallback (am.message);
  29719. }
  29720. END_JUCE_NAMESPACE
  29721. /*** End of inlined file: juce_ActionListenerList.cpp ***/
  29722. /*** Start of inlined file: juce_AsyncUpdater.cpp ***/
  29723. BEGIN_JUCE_NAMESPACE
  29724. AsyncUpdater::AsyncUpdater() throw()
  29725. : asyncMessagePending (false)
  29726. {
  29727. internalAsyncHandler.owner = this;
  29728. }
  29729. AsyncUpdater::~AsyncUpdater()
  29730. {
  29731. }
  29732. void AsyncUpdater::triggerAsyncUpdate() throw()
  29733. {
  29734. if (! asyncMessagePending)
  29735. {
  29736. asyncMessagePending = true;
  29737. internalAsyncHandler.postMessage (new Message());
  29738. }
  29739. }
  29740. void AsyncUpdater::cancelPendingUpdate() throw()
  29741. {
  29742. asyncMessagePending = false;
  29743. }
  29744. void AsyncUpdater::handleUpdateNowIfNeeded()
  29745. {
  29746. if (asyncMessagePending)
  29747. {
  29748. asyncMessagePending = false;
  29749. handleAsyncUpdate();
  29750. }
  29751. }
  29752. void AsyncUpdater::AsyncUpdaterInternal::handleMessage (const Message&)
  29753. {
  29754. owner->handleUpdateNowIfNeeded();
  29755. }
  29756. END_JUCE_NAMESPACE
  29757. /*** End of inlined file: juce_AsyncUpdater.cpp ***/
  29758. /*** Start of inlined file: juce_ChangeBroadcaster.cpp ***/
  29759. BEGIN_JUCE_NAMESPACE
  29760. ChangeBroadcaster::ChangeBroadcaster() throw()
  29761. {
  29762. // are you trying to create this object before or after juce has been intialised??
  29763. jassert (MessageManager::instance != 0);
  29764. }
  29765. ChangeBroadcaster::~ChangeBroadcaster()
  29766. {
  29767. // all event-based objects must be deleted BEFORE juce is shut down!
  29768. jassert (MessageManager::instance != 0);
  29769. }
  29770. void ChangeBroadcaster::addChangeListener (ChangeListener* const listener) throw()
  29771. {
  29772. changeListenerList.addChangeListener (listener);
  29773. }
  29774. void ChangeBroadcaster::removeChangeListener (ChangeListener* const listener) throw()
  29775. {
  29776. jassert (changeListenerList.isValidMessageListener());
  29777. if (changeListenerList.isValidMessageListener())
  29778. changeListenerList.removeChangeListener (listener);
  29779. }
  29780. void ChangeBroadcaster::removeAllChangeListeners() throw()
  29781. {
  29782. changeListenerList.removeAllChangeListeners();
  29783. }
  29784. void ChangeBroadcaster::sendChangeMessage (void* objectThatHasChanged) throw()
  29785. {
  29786. changeListenerList.sendChangeMessage (objectThatHasChanged);
  29787. }
  29788. void ChangeBroadcaster::sendSynchronousChangeMessage (void* objectThatHasChanged)
  29789. {
  29790. changeListenerList.sendSynchronousChangeMessage (objectThatHasChanged);
  29791. }
  29792. void ChangeBroadcaster::dispatchPendingMessages()
  29793. {
  29794. changeListenerList.dispatchPendingMessages();
  29795. }
  29796. END_JUCE_NAMESPACE
  29797. /*** End of inlined file: juce_ChangeBroadcaster.cpp ***/
  29798. /*** Start of inlined file: juce_ChangeListenerList.cpp ***/
  29799. BEGIN_JUCE_NAMESPACE
  29800. ChangeListenerList::ChangeListenerList() throw()
  29801. : lastChangedObject (0),
  29802. messagePending (false)
  29803. {
  29804. }
  29805. ChangeListenerList::~ChangeListenerList() throw()
  29806. {
  29807. }
  29808. void ChangeListenerList::addChangeListener (ChangeListener* const listener) throw()
  29809. {
  29810. const ScopedLock sl (lock);
  29811. jassert (listener != 0);
  29812. if (listener != 0)
  29813. listeners.add (listener);
  29814. }
  29815. void ChangeListenerList::removeChangeListener (ChangeListener* const listener) throw()
  29816. {
  29817. const ScopedLock sl (lock);
  29818. listeners.removeValue (listener);
  29819. }
  29820. void ChangeListenerList::removeAllChangeListeners() throw()
  29821. {
  29822. const ScopedLock sl (lock);
  29823. listeners.clear();
  29824. }
  29825. void ChangeListenerList::sendChangeMessage (void* const objectThatHasChanged) throw()
  29826. {
  29827. const ScopedLock sl (lock);
  29828. if ((! messagePending) && (listeners.size() > 0))
  29829. {
  29830. lastChangedObject = objectThatHasChanged;
  29831. postMessage (new Message (0, 0, 0, objectThatHasChanged));
  29832. messagePending = true;
  29833. }
  29834. }
  29835. void ChangeListenerList::handleMessage (const Message& message)
  29836. {
  29837. sendSynchronousChangeMessage (message.pointerParameter);
  29838. }
  29839. void ChangeListenerList::sendSynchronousChangeMessage (void* const objectThatHasChanged)
  29840. {
  29841. const ScopedLock sl (lock);
  29842. messagePending = false;
  29843. for (int i = listeners.size(); --i >= 0;)
  29844. {
  29845. ChangeListener* const l = (ChangeListener*) listeners.getUnchecked (i);
  29846. {
  29847. const ScopedUnlock tempUnlocker (lock);
  29848. l->changeListenerCallback (objectThatHasChanged);
  29849. }
  29850. i = jmin (i, listeners.size());
  29851. }
  29852. }
  29853. void ChangeListenerList::dispatchPendingMessages()
  29854. {
  29855. if (messagePending)
  29856. sendSynchronousChangeMessage (lastChangedObject);
  29857. }
  29858. END_JUCE_NAMESPACE
  29859. /*** End of inlined file: juce_ChangeListenerList.cpp ***/
  29860. /*** Start of inlined file: juce_InterprocessConnection.cpp ***/
  29861. BEGIN_JUCE_NAMESPACE
  29862. InterprocessConnection::InterprocessConnection (const bool callbacksOnMessageThread,
  29863. const uint32 magicMessageHeaderNumber)
  29864. : Thread ("Juce IPC connection"),
  29865. callbackConnectionState (false),
  29866. useMessageThread (callbacksOnMessageThread),
  29867. magicMessageHeader (magicMessageHeaderNumber),
  29868. pipeReceiveMessageTimeout (-1)
  29869. {
  29870. }
  29871. InterprocessConnection::~InterprocessConnection()
  29872. {
  29873. callbackConnectionState = false;
  29874. disconnect();
  29875. }
  29876. bool InterprocessConnection::connectToSocket (const String& hostName,
  29877. const int portNumber,
  29878. const int timeOutMillisecs)
  29879. {
  29880. disconnect();
  29881. const ScopedLock sl (pipeAndSocketLock);
  29882. socket = new StreamingSocket();
  29883. if (socket->connect (hostName, portNumber, timeOutMillisecs))
  29884. {
  29885. connectionMadeInt();
  29886. startThread();
  29887. return true;
  29888. }
  29889. else
  29890. {
  29891. socket = 0;
  29892. return false;
  29893. }
  29894. }
  29895. bool InterprocessConnection::connectToPipe (const String& pipeName,
  29896. const int pipeReceiveMessageTimeoutMs)
  29897. {
  29898. disconnect();
  29899. ScopedPointer <NamedPipe> newPipe (new NamedPipe());
  29900. if (newPipe->openExisting (pipeName))
  29901. {
  29902. const ScopedLock sl (pipeAndSocketLock);
  29903. pipeReceiveMessageTimeout = pipeReceiveMessageTimeoutMs;
  29904. initialiseWithPipe (newPipe.release());
  29905. return true;
  29906. }
  29907. return false;
  29908. }
  29909. bool InterprocessConnection::createPipe (const String& pipeName,
  29910. const int pipeReceiveMessageTimeoutMs)
  29911. {
  29912. disconnect();
  29913. ScopedPointer <NamedPipe> newPipe (new NamedPipe());
  29914. if (newPipe->createNewPipe (pipeName))
  29915. {
  29916. const ScopedLock sl (pipeAndSocketLock);
  29917. pipeReceiveMessageTimeout = pipeReceiveMessageTimeoutMs;
  29918. initialiseWithPipe (newPipe.release());
  29919. return true;
  29920. }
  29921. return false;
  29922. }
  29923. void InterprocessConnection::disconnect()
  29924. {
  29925. if (socket != 0)
  29926. socket->close();
  29927. if (pipe != 0)
  29928. {
  29929. pipe->cancelPendingReads();
  29930. pipe->close();
  29931. }
  29932. stopThread (4000);
  29933. {
  29934. const ScopedLock sl (pipeAndSocketLock);
  29935. socket = 0;
  29936. pipe = 0;
  29937. }
  29938. connectionLostInt();
  29939. }
  29940. bool InterprocessConnection::isConnected() const
  29941. {
  29942. const ScopedLock sl (pipeAndSocketLock);
  29943. return ((socket != 0 && socket->isConnected())
  29944. || (pipe != 0 && pipe->isOpen()))
  29945. && isThreadRunning();
  29946. }
  29947. const String InterprocessConnection::getConnectedHostName() const
  29948. {
  29949. if (pipe != 0)
  29950. {
  29951. return "localhost";
  29952. }
  29953. else if (socket != 0)
  29954. {
  29955. if (! socket->isLocal())
  29956. return socket->getHostName();
  29957. return "localhost";
  29958. }
  29959. return String::empty;
  29960. }
  29961. bool InterprocessConnection::sendMessage (const MemoryBlock& message)
  29962. {
  29963. uint32 messageHeader[2];
  29964. messageHeader [0] = ByteOrder::swapIfBigEndian (magicMessageHeader);
  29965. messageHeader [1] = ByteOrder::swapIfBigEndian ((uint32) message.getSize());
  29966. MemoryBlock messageData (sizeof (messageHeader) + message.getSize());
  29967. messageData.copyFrom (messageHeader, 0, sizeof (messageHeader));
  29968. messageData.copyFrom (message.getData(), sizeof (messageHeader), message.getSize());
  29969. size_t bytesWritten = 0;
  29970. const ScopedLock sl (pipeAndSocketLock);
  29971. if (socket != 0)
  29972. {
  29973. bytesWritten = socket->write (messageData.getData(), (int) messageData.getSize());
  29974. }
  29975. else if (pipe != 0)
  29976. {
  29977. bytesWritten = pipe->write (messageData.getData(), (int) messageData.getSize());
  29978. }
  29979. if (bytesWritten < 0)
  29980. {
  29981. // error..
  29982. return false;
  29983. }
  29984. return (bytesWritten == messageData.getSize());
  29985. }
  29986. void InterprocessConnection::initialiseWithSocket (StreamingSocket* const socket_)
  29987. {
  29988. jassert (socket == 0);
  29989. socket = socket_;
  29990. connectionMadeInt();
  29991. startThread();
  29992. }
  29993. void InterprocessConnection::initialiseWithPipe (NamedPipe* const pipe_)
  29994. {
  29995. jassert (pipe == 0);
  29996. pipe = pipe_;
  29997. connectionMadeInt();
  29998. startThread();
  29999. }
  30000. const int messageMagicNumber = 0xb734128b;
  30001. void InterprocessConnection::handleMessage (const Message& message)
  30002. {
  30003. if (message.intParameter1 == messageMagicNumber)
  30004. {
  30005. switch (message.intParameter2)
  30006. {
  30007. case 0:
  30008. {
  30009. ScopedPointer <MemoryBlock> data ((MemoryBlock*) message.pointerParameter);
  30010. messageReceived (*data);
  30011. break;
  30012. }
  30013. case 1:
  30014. connectionMade();
  30015. break;
  30016. case 2:
  30017. connectionLost();
  30018. break;
  30019. }
  30020. }
  30021. }
  30022. void InterprocessConnection::connectionMadeInt()
  30023. {
  30024. if (! callbackConnectionState)
  30025. {
  30026. callbackConnectionState = true;
  30027. if (useMessageThread)
  30028. postMessage (new Message (messageMagicNumber, 1, 0, 0));
  30029. else
  30030. connectionMade();
  30031. }
  30032. }
  30033. void InterprocessConnection::connectionLostInt()
  30034. {
  30035. if (callbackConnectionState)
  30036. {
  30037. callbackConnectionState = false;
  30038. if (useMessageThread)
  30039. postMessage (new Message (messageMagicNumber, 2, 0, 0));
  30040. else
  30041. connectionLost();
  30042. }
  30043. }
  30044. void InterprocessConnection::deliverDataInt (const MemoryBlock& data)
  30045. {
  30046. jassert (callbackConnectionState);
  30047. if (useMessageThread)
  30048. postMessage (new Message (messageMagicNumber, 0, 0, new MemoryBlock (data)));
  30049. else
  30050. messageReceived (data);
  30051. }
  30052. bool InterprocessConnection::readNextMessageInt()
  30053. {
  30054. const int maximumMessageSize = 1024 * 1024 * 10; // sanity check
  30055. uint32 messageHeader[2];
  30056. const int bytes = (socket != 0) ? socket->read (messageHeader, sizeof (messageHeader), true)
  30057. : pipe->read (messageHeader, sizeof (messageHeader), pipeReceiveMessageTimeout);
  30058. if (bytes == sizeof (messageHeader)
  30059. && ByteOrder::swapIfBigEndian (messageHeader[0]) == magicMessageHeader)
  30060. {
  30061. int bytesInMessage = (int) ByteOrder::swapIfBigEndian (messageHeader[1]);
  30062. if (bytesInMessage > 0 && bytesInMessage < maximumMessageSize)
  30063. {
  30064. MemoryBlock messageData (bytesInMessage, true);
  30065. int bytesRead = 0;
  30066. while (bytesInMessage > 0)
  30067. {
  30068. if (threadShouldExit())
  30069. return false;
  30070. const int numThisTime = jmin (bytesInMessage, 65536);
  30071. const int bytesIn = (socket != 0) ? socket->read (static_cast <char*> (messageData.getData()) + bytesRead, numThisTime, true)
  30072. : pipe->read (static_cast <char*> (messageData.getData()) + bytesRead, numThisTime, pipeReceiveMessageTimeout);
  30073. if (bytesIn <= 0)
  30074. break;
  30075. bytesRead += bytesIn;
  30076. bytesInMessage -= bytesIn;
  30077. }
  30078. if (bytesRead >= 0)
  30079. deliverDataInt (messageData);
  30080. }
  30081. }
  30082. else if (bytes < 0)
  30083. {
  30084. {
  30085. const ScopedLock sl (pipeAndSocketLock);
  30086. socket = 0;
  30087. }
  30088. connectionLostInt();
  30089. return false;
  30090. }
  30091. return true;
  30092. }
  30093. void InterprocessConnection::run()
  30094. {
  30095. while (! threadShouldExit())
  30096. {
  30097. if (socket != 0)
  30098. {
  30099. const int ready = socket->waitUntilReady (true, 0);
  30100. if (ready < 0)
  30101. {
  30102. {
  30103. const ScopedLock sl (pipeAndSocketLock);
  30104. socket = 0;
  30105. }
  30106. connectionLostInt();
  30107. break;
  30108. }
  30109. else if (ready > 0)
  30110. {
  30111. if (! readNextMessageInt())
  30112. break;
  30113. }
  30114. else
  30115. {
  30116. Thread::sleep (2);
  30117. }
  30118. }
  30119. else if (pipe != 0)
  30120. {
  30121. if (! pipe->isOpen())
  30122. {
  30123. {
  30124. const ScopedLock sl (pipeAndSocketLock);
  30125. pipe = 0;
  30126. }
  30127. connectionLostInt();
  30128. break;
  30129. }
  30130. else
  30131. {
  30132. if (! readNextMessageInt())
  30133. break;
  30134. }
  30135. }
  30136. else
  30137. {
  30138. break;
  30139. }
  30140. }
  30141. }
  30142. END_JUCE_NAMESPACE
  30143. /*** End of inlined file: juce_InterprocessConnection.cpp ***/
  30144. /*** Start of inlined file: juce_InterprocessConnectionServer.cpp ***/
  30145. BEGIN_JUCE_NAMESPACE
  30146. InterprocessConnectionServer::InterprocessConnectionServer()
  30147. : Thread ("Juce IPC server")
  30148. {
  30149. }
  30150. InterprocessConnectionServer::~InterprocessConnectionServer()
  30151. {
  30152. stop();
  30153. }
  30154. bool InterprocessConnectionServer::beginWaitingForSocket (const int portNumber)
  30155. {
  30156. stop();
  30157. socket = new StreamingSocket();
  30158. if (socket->createListener (portNumber))
  30159. {
  30160. startThread();
  30161. return true;
  30162. }
  30163. socket = 0;
  30164. return false;
  30165. }
  30166. void InterprocessConnectionServer::stop()
  30167. {
  30168. signalThreadShouldExit();
  30169. if (socket != 0)
  30170. socket->close();
  30171. stopThread (4000);
  30172. socket = 0;
  30173. }
  30174. void InterprocessConnectionServer::run()
  30175. {
  30176. while ((! threadShouldExit()) && socket != 0)
  30177. {
  30178. ScopedPointer <StreamingSocket> clientSocket (socket->waitForNextConnection());
  30179. if (clientSocket != 0)
  30180. {
  30181. InterprocessConnection* newConnection = createConnectionObject();
  30182. if (newConnection != 0)
  30183. newConnection->initialiseWithSocket (clientSocket.release());
  30184. }
  30185. }
  30186. }
  30187. END_JUCE_NAMESPACE
  30188. /*** End of inlined file: juce_InterprocessConnectionServer.cpp ***/
  30189. /*** Start of inlined file: juce_Message.cpp ***/
  30190. BEGIN_JUCE_NAMESPACE
  30191. Message::Message() throw()
  30192. {
  30193. }
  30194. Message::~Message() throw()
  30195. {
  30196. }
  30197. Message::Message (const int intParameter1_,
  30198. const int intParameter2_,
  30199. const int intParameter3_,
  30200. void* const pointerParameter_) throw()
  30201. : intParameter1 (intParameter1_),
  30202. intParameter2 (intParameter2_),
  30203. intParameter3 (intParameter3_),
  30204. pointerParameter (pointerParameter_)
  30205. {
  30206. }
  30207. END_JUCE_NAMESPACE
  30208. /*** End of inlined file: juce_Message.cpp ***/
  30209. /*** Start of inlined file: juce_MessageListener.cpp ***/
  30210. BEGIN_JUCE_NAMESPACE
  30211. MessageListener::MessageListener() throw()
  30212. {
  30213. // are you trying to create a messagelistener before or after juce has been intialised??
  30214. jassert (MessageManager::instance != 0);
  30215. if (MessageManager::instance != 0)
  30216. MessageManager::instance->messageListeners.add (this);
  30217. }
  30218. MessageListener::~MessageListener()
  30219. {
  30220. if (MessageManager::instance != 0)
  30221. MessageManager::instance->messageListeners.removeValue (this);
  30222. }
  30223. void MessageListener::postMessage (Message* const message) const throw()
  30224. {
  30225. message->messageRecipient = const_cast <MessageListener*> (this);
  30226. if (MessageManager::instance == 0)
  30227. MessageManager::getInstance();
  30228. MessageManager::instance->postMessageToQueue (message);
  30229. }
  30230. bool MessageListener::isValidMessageListener() const throw()
  30231. {
  30232. return (MessageManager::instance != 0)
  30233. && MessageManager::instance->messageListeners.contains (this);
  30234. }
  30235. END_JUCE_NAMESPACE
  30236. /*** End of inlined file: juce_MessageListener.cpp ***/
  30237. /*** Start of inlined file: juce_MessageManager.cpp ***/
  30238. BEGIN_JUCE_NAMESPACE
  30239. // platform-specific functions..
  30240. bool juce_dispatchNextMessageOnSystemQueue (bool returnIfNoPendingMessages);
  30241. bool juce_postMessageToSystemQueue (void* message);
  30242. MessageManager* MessageManager::instance = 0;
  30243. static const int quitMessageId = 0xfffff321;
  30244. MessageManager::MessageManager() throw()
  30245. : quitMessagePosted (false),
  30246. quitMessageReceived (false),
  30247. threadWithLock (0)
  30248. {
  30249. messageThreadId = Thread::getCurrentThreadId();
  30250. }
  30251. MessageManager::~MessageManager() throw()
  30252. {
  30253. broadcastListeners = 0;
  30254. doPlatformSpecificShutdown();
  30255. jassert (instance == this);
  30256. instance = 0; // do this last in case this instance is still needed by doPlatformSpecificShutdown()
  30257. }
  30258. MessageManager* MessageManager::getInstance() throw()
  30259. {
  30260. if (instance == 0)
  30261. {
  30262. instance = new MessageManager();
  30263. doPlatformSpecificInitialisation();
  30264. }
  30265. return instance;
  30266. }
  30267. void MessageManager::postMessageToQueue (Message* const message)
  30268. {
  30269. if (quitMessagePosted || ! juce_postMessageToSystemQueue (message))
  30270. delete message;
  30271. }
  30272. CallbackMessage::CallbackMessage() throw() {}
  30273. CallbackMessage::~CallbackMessage() throw() {}
  30274. void CallbackMessage::post()
  30275. {
  30276. if (MessageManager::instance != 0)
  30277. MessageManager::instance->postCallbackMessage (this);
  30278. }
  30279. void MessageManager::postCallbackMessage (Message* const message)
  30280. {
  30281. message->messageRecipient = 0;
  30282. postMessageToQueue (message);
  30283. }
  30284. // not for public use..
  30285. void MessageManager::deliverMessage (void* message)
  30286. {
  30287. const ScopedPointer <Message> m ((Message*) message);
  30288. MessageListener* const recipient = m->messageRecipient;
  30289. JUCE_TRY
  30290. {
  30291. if (messageListeners.contains (recipient))
  30292. {
  30293. recipient->handleMessage (*m);
  30294. }
  30295. else if (recipient == 0)
  30296. {
  30297. if (m->intParameter1 == quitMessageId)
  30298. {
  30299. quitMessageReceived = true;
  30300. }
  30301. else
  30302. {
  30303. CallbackMessage* const cm = dynamic_cast <CallbackMessage*> ((Message*) m);
  30304. if (cm != 0)
  30305. cm->messageCallback();
  30306. }
  30307. }
  30308. }
  30309. JUCE_CATCH_EXCEPTION
  30310. }
  30311. #if ! (JUCE_MAC || JUCE_IPHONE)
  30312. void MessageManager::runDispatchLoop()
  30313. {
  30314. jassert (isThisTheMessageThread()); // must only be called by the message thread
  30315. runDispatchLoopUntil (-1);
  30316. }
  30317. void MessageManager::stopDispatchLoop()
  30318. {
  30319. Message* const m = new Message (quitMessageId, 0, 0, 0);
  30320. m->messageRecipient = 0;
  30321. postMessageToQueue (m);
  30322. quitMessagePosted = true;
  30323. }
  30324. bool MessageManager::runDispatchLoopUntil (int millisecondsToRunFor)
  30325. {
  30326. jassert (isThisTheMessageThread()); // must only be called by the message thread
  30327. const int64 endTime = Time::currentTimeMillis() + millisecondsToRunFor;
  30328. while ((millisecondsToRunFor < 0 || endTime > Time::currentTimeMillis())
  30329. && ! quitMessageReceived)
  30330. {
  30331. JUCE_TRY
  30332. {
  30333. if (! juce_dispatchNextMessageOnSystemQueue (millisecondsToRunFor >= 0))
  30334. {
  30335. const int msToWait = (int) (endTime - Time::currentTimeMillis());
  30336. if (msToWait > 0)
  30337. Thread::sleep (jmin (5, msToWait));
  30338. }
  30339. }
  30340. JUCE_CATCH_EXCEPTION
  30341. }
  30342. return ! quitMessageReceived;
  30343. }
  30344. #endif
  30345. void MessageManager::deliverBroadcastMessage (const String& value)
  30346. {
  30347. if (broadcastListeners != 0)
  30348. broadcastListeners->sendActionMessage (value);
  30349. }
  30350. void MessageManager::registerBroadcastListener (ActionListener* const listener) throw()
  30351. {
  30352. if (broadcastListeners == 0)
  30353. broadcastListeners = new ActionListenerList();
  30354. broadcastListeners->addActionListener (listener);
  30355. }
  30356. void MessageManager::deregisterBroadcastListener (ActionListener* const listener) throw()
  30357. {
  30358. if (broadcastListeners != 0)
  30359. broadcastListeners->removeActionListener (listener);
  30360. }
  30361. bool MessageManager::isThisTheMessageThread() const throw()
  30362. {
  30363. return Thread::getCurrentThreadId() == messageThreadId;
  30364. }
  30365. void MessageManager::setCurrentThreadAsMessageThread()
  30366. {
  30367. if (messageThreadId != Thread::getCurrentThreadId())
  30368. {
  30369. messageThreadId = Thread::getCurrentThreadId();
  30370. // This is needed on windows to make sure the message window is created by this thread
  30371. doPlatformSpecificShutdown();
  30372. doPlatformSpecificInitialisation();
  30373. }
  30374. }
  30375. bool MessageManager::currentThreadHasLockedMessageManager() const throw()
  30376. {
  30377. const Thread::ThreadID thisThread = Thread::getCurrentThreadId();
  30378. return thisThread == messageThreadId || thisThread == threadWithLock;
  30379. }
  30380. class MessageManagerLock::SharedEvents : public ReferenceCountedObject
  30381. {
  30382. public:
  30383. SharedEvents() {}
  30384. ~SharedEvents() {}
  30385. WaitableEvent lockedEvent, releaseEvent;
  30386. private:
  30387. SharedEvents (const SharedEvents&);
  30388. SharedEvents& operator= (const SharedEvents&);
  30389. };
  30390. class MessageManagerLock::BlockingMessage : public CallbackMessage
  30391. {
  30392. public:
  30393. BlockingMessage (MessageManagerLock::SharedEvents* const events_) : events (events_) {}
  30394. ~BlockingMessage() throw() {}
  30395. void messageCallback()
  30396. {
  30397. events->lockedEvent.signal();
  30398. events->releaseEvent.wait();
  30399. }
  30400. juce_UseDebuggingNewOperator
  30401. private:
  30402. ReferenceCountedObjectPtr <MessageManagerLock::SharedEvents> events;
  30403. BlockingMessage (const BlockingMessage&);
  30404. BlockingMessage& operator= (const BlockingMessage&);
  30405. };
  30406. MessageManagerLock::MessageManagerLock (Thread* const threadToCheck) throw()
  30407. : sharedEvents (0),
  30408. locked (false)
  30409. {
  30410. init (threadToCheck, 0);
  30411. }
  30412. MessageManagerLock::MessageManagerLock (ThreadPoolJob* const jobToCheckForExitSignal) throw()
  30413. : sharedEvents (0),
  30414. locked (false)
  30415. {
  30416. init (0, jobToCheckForExitSignal);
  30417. }
  30418. void MessageManagerLock::init (Thread* const threadToCheck, ThreadPoolJob* const job) throw()
  30419. {
  30420. if (MessageManager::instance != 0)
  30421. {
  30422. if (MessageManager::instance->currentThreadHasLockedMessageManager())
  30423. {
  30424. locked = true; // either we're on the message thread, or this is a re-entrant call.
  30425. }
  30426. else
  30427. {
  30428. if (threadToCheck == 0 && job == 0)
  30429. {
  30430. MessageManager::instance->lockingLock.enter();
  30431. }
  30432. else
  30433. {
  30434. while (! MessageManager::instance->lockingLock.tryEnter())
  30435. {
  30436. if ((threadToCheck != 0 && threadToCheck->threadShouldExit())
  30437. || (job != 0 && job->shouldExit()))
  30438. return;
  30439. Thread::sleep (1);
  30440. }
  30441. }
  30442. sharedEvents = new SharedEvents();
  30443. sharedEvents->incReferenceCount();
  30444. (new BlockingMessage (sharedEvents))->post();
  30445. while (! sharedEvents->lockedEvent.wait (50))
  30446. {
  30447. if ((threadToCheck != 0 && threadToCheck->threadShouldExit())
  30448. || (job != 0 && job->shouldExit()))
  30449. {
  30450. sharedEvents->releaseEvent.signal();
  30451. sharedEvents->decReferenceCount();
  30452. sharedEvents = 0;
  30453. MessageManager::instance->lockingLock.exit();
  30454. return;
  30455. }
  30456. }
  30457. jassert (MessageManager::instance->threadWithLock == 0);
  30458. MessageManager::instance->threadWithLock = Thread::getCurrentThreadId();
  30459. locked = true;
  30460. }
  30461. }
  30462. }
  30463. MessageManagerLock::~MessageManagerLock() throw()
  30464. {
  30465. if (sharedEvents != 0)
  30466. {
  30467. jassert (MessageManager::instance == 0 || MessageManager::instance->currentThreadHasLockedMessageManager());
  30468. sharedEvents->releaseEvent.signal();
  30469. sharedEvents->decReferenceCount();
  30470. if (MessageManager::instance != 0)
  30471. {
  30472. MessageManager::instance->threadWithLock = 0;
  30473. MessageManager::instance->lockingLock.exit();
  30474. }
  30475. }
  30476. }
  30477. END_JUCE_NAMESPACE
  30478. /*** End of inlined file: juce_MessageManager.cpp ***/
  30479. /*** Start of inlined file: juce_MultiTimer.cpp ***/
  30480. BEGIN_JUCE_NAMESPACE
  30481. class MultiTimer::MultiTimerCallback : public Timer
  30482. {
  30483. public:
  30484. MultiTimerCallback (const int timerId_, MultiTimer& owner_)
  30485. : timerId (timerId_),
  30486. owner (owner_)
  30487. {
  30488. }
  30489. ~MultiTimerCallback()
  30490. {
  30491. }
  30492. void timerCallback()
  30493. {
  30494. owner.timerCallback (timerId);
  30495. }
  30496. const int timerId;
  30497. private:
  30498. MultiTimer& owner;
  30499. };
  30500. MultiTimer::MultiTimer() throw()
  30501. {
  30502. }
  30503. MultiTimer::MultiTimer (const MultiTimer&) throw()
  30504. {
  30505. }
  30506. MultiTimer::~MultiTimer()
  30507. {
  30508. const ScopedLock sl (timerListLock);
  30509. timers.clear();
  30510. }
  30511. void MultiTimer::startTimer (const int timerId, const int intervalInMilliseconds) throw()
  30512. {
  30513. const ScopedLock sl (timerListLock);
  30514. for (int i = timers.size(); --i >= 0;)
  30515. {
  30516. MultiTimerCallback* const t = timers.getUnchecked(i);
  30517. if (t->timerId == timerId)
  30518. {
  30519. t->startTimer (intervalInMilliseconds);
  30520. return;
  30521. }
  30522. }
  30523. MultiTimerCallback* const newTimer = new MultiTimerCallback (timerId, *this);
  30524. timers.add (newTimer);
  30525. newTimer->startTimer (intervalInMilliseconds);
  30526. }
  30527. void MultiTimer::stopTimer (const int timerId) throw()
  30528. {
  30529. const ScopedLock sl (timerListLock);
  30530. for (int i = timers.size(); --i >= 0;)
  30531. {
  30532. MultiTimerCallback* const t = timers.getUnchecked(i);
  30533. if (t->timerId == timerId)
  30534. t->stopTimer();
  30535. }
  30536. }
  30537. bool MultiTimer::isTimerRunning (const int timerId) const throw()
  30538. {
  30539. const ScopedLock sl (timerListLock);
  30540. for (int i = timers.size(); --i >= 0;)
  30541. {
  30542. const MultiTimerCallback* const t = timers.getUnchecked(i);
  30543. if (t->timerId == timerId)
  30544. return t->isTimerRunning();
  30545. }
  30546. return false;
  30547. }
  30548. int MultiTimer::getTimerInterval (const int timerId) const throw()
  30549. {
  30550. const ScopedLock sl (timerListLock);
  30551. for (int i = timers.size(); --i >= 0;)
  30552. {
  30553. const MultiTimerCallback* const t = timers.getUnchecked(i);
  30554. if (t->timerId == timerId)
  30555. return t->getTimerInterval();
  30556. }
  30557. return 0;
  30558. }
  30559. END_JUCE_NAMESPACE
  30560. /*** End of inlined file: juce_MultiTimer.cpp ***/
  30561. /*** Start of inlined file: juce_Timer.cpp ***/
  30562. BEGIN_JUCE_NAMESPACE
  30563. class InternalTimerThread : private Thread,
  30564. private MessageListener,
  30565. private DeletedAtShutdown,
  30566. private AsyncUpdater
  30567. {
  30568. public:
  30569. InternalTimerThread()
  30570. : Thread ("Juce Timer"),
  30571. firstTimer (0),
  30572. callbackNeeded (false)
  30573. {
  30574. triggerAsyncUpdate();
  30575. }
  30576. ~InternalTimerThread() throw()
  30577. {
  30578. stopThread (4000);
  30579. jassert (instance == this || instance == 0);
  30580. if (instance == this)
  30581. instance = 0;
  30582. }
  30583. void run()
  30584. {
  30585. uint32 lastTime = Time::getMillisecondCounter();
  30586. while (! threadShouldExit())
  30587. {
  30588. const uint32 now = Time::getMillisecondCounter();
  30589. if (now <= lastTime)
  30590. {
  30591. wait (2);
  30592. continue;
  30593. }
  30594. const int elapsed = now - lastTime;
  30595. lastTime = now;
  30596. int timeUntilFirstTimer = 1000;
  30597. {
  30598. const ScopedLock sl (lock);
  30599. decrementAllCounters (elapsed);
  30600. if (firstTimer != 0)
  30601. timeUntilFirstTimer = firstTimer->countdownMs;
  30602. }
  30603. if (timeUntilFirstTimer <= 0)
  30604. {
  30605. if (callbackNeeded.set (true))
  30606. {
  30607. postMessage (new Message());
  30608. const uint32 messageDeliveryTimeout = now + 2000;
  30609. while (callbackNeeded.get())
  30610. {
  30611. wait (4);
  30612. if (threadShouldExit())
  30613. return;
  30614. if (Time::getMillisecondCounter() > messageDeliveryTimeout)
  30615. break;
  30616. }
  30617. }
  30618. }
  30619. else
  30620. {
  30621. // don't wait for too long because running this loop also helps keep the
  30622. // Time::getApproximateMillisecondTimer value stay up-to-date
  30623. wait (jlimit (1, 50, timeUntilFirstTimer));
  30624. }
  30625. }
  30626. }
  30627. void callTimers()
  30628. {
  30629. const ScopedLock sl (lock);
  30630. while (firstTimer != 0 && firstTimer->countdownMs <= 0)
  30631. {
  30632. Timer* const t = firstTimer;
  30633. t->countdownMs = t->periodMs;
  30634. removeTimer (t);
  30635. addTimer (t);
  30636. const ScopedUnlock ul (lock);
  30637. JUCE_TRY
  30638. {
  30639. t->timerCallback();
  30640. }
  30641. JUCE_CATCH_EXCEPTION
  30642. }
  30643. callbackNeeded.set (false);
  30644. }
  30645. void handleMessage (const Message&)
  30646. {
  30647. callTimers();
  30648. }
  30649. void callTimersSynchronously()
  30650. {
  30651. if (! isThreadRunning())
  30652. {
  30653. // (This is relied on by some plugins in cases where the MM has
  30654. // had to restart and the async callback never started)
  30655. cancelPendingUpdate();
  30656. triggerAsyncUpdate();
  30657. }
  30658. callTimers();
  30659. }
  30660. static void callAnyTimersSynchronously()
  30661. {
  30662. if (InternalTimerThread::instance != 0)
  30663. InternalTimerThread::instance->callTimersSynchronously();
  30664. }
  30665. static inline void add (Timer* const tim) throw()
  30666. {
  30667. if (instance == 0)
  30668. instance = new InternalTimerThread();
  30669. const ScopedLock sl (instance->lock);
  30670. instance->addTimer (tim);
  30671. }
  30672. static inline void remove (Timer* const tim) throw()
  30673. {
  30674. if (instance != 0)
  30675. {
  30676. const ScopedLock sl (instance->lock);
  30677. instance->removeTimer (tim);
  30678. }
  30679. }
  30680. static inline void resetCounter (Timer* const tim,
  30681. const int newCounter) throw()
  30682. {
  30683. if (instance != 0)
  30684. {
  30685. tim->countdownMs = newCounter;
  30686. tim->periodMs = newCounter;
  30687. if ((tim->next != 0 && tim->next->countdownMs < tim->countdownMs)
  30688. || (tim->previous != 0 && tim->previous->countdownMs > tim->countdownMs))
  30689. {
  30690. const ScopedLock sl (instance->lock);
  30691. instance->removeTimer (tim);
  30692. instance->addTimer (tim);
  30693. }
  30694. }
  30695. }
  30696. private:
  30697. friend class Timer;
  30698. static InternalTimerThread* instance;
  30699. static CriticalSection lock;
  30700. Timer* volatile firstTimer;
  30701. class AtomicBool
  30702. {
  30703. public:
  30704. AtomicBool (const bool value) throw() : value (static_cast<int32> (value)) {}
  30705. ~AtomicBool() throw() {}
  30706. bool get() const throw() { return value != 0; }
  30707. bool set (const bool newValue) { return Atomic::compareAndExchange (value, newValue ? 1 : 0, value) != 0; }
  30708. private:
  30709. int32 value;
  30710. AtomicBool (const AtomicBool&);
  30711. AtomicBool& operator= (const AtomicBool&);
  30712. };
  30713. AtomicBool callbackNeeded;
  30714. void addTimer (Timer* const t) throw()
  30715. {
  30716. #ifdef JUCE_DEBUG
  30717. Timer* tt = firstTimer;
  30718. while (tt != 0)
  30719. {
  30720. // trying to add a timer that's already here - shouldn't get to this point,
  30721. // so if you get this assertion, let me know!
  30722. jassert (tt != t);
  30723. tt = tt->next;
  30724. }
  30725. jassert (t->previous == 0 && t->next == 0);
  30726. #endif
  30727. Timer* i = firstTimer;
  30728. if (i == 0 || i->countdownMs > t->countdownMs)
  30729. {
  30730. t->next = firstTimer;
  30731. firstTimer = t;
  30732. }
  30733. else
  30734. {
  30735. while (i->next != 0 && i->next->countdownMs <= t->countdownMs)
  30736. i = i->next;
  30737. jassert (i != 0);
  30738. t->next = i->next;
  30739. t->previous = i;
  30740. i->next = t;
  30741. }
  30742. if (t->next != 0)
  30743. t->next->previous = t;
  30744. jassert ((t->next == 0 || t->next->countdownMs >= t->countdownMs)
  30745. && (t->previous == 0 || t->previous->countdownMs <= t->countdownMs));
  30746. notify();
  30747. }
  30748. void removeTimer (Timer* const t) throw()
  30749. {
  30750. #ifdef JUCE_DEBUG
  30751. Timer* tt = firstTimer;
  30752. bool found = false;
  30753. while (tt != 0)
  30754. {
  30755. if (tt == t)
  30756. {
  30757. found = true;
  30758. break;
  30759. }
  30760. tt = tt->next;
  30761. }
  30762. // trying to remove a timer that's not here - shouldn't get to this point,
  30763. // so if you get this assertion, let me know!
  30764. jassert (found);
  30765. #endif
  30766. if (t->previous != 0)
  30767. {
  30768. jassert (firstTimer != t);
  30769. t->previous->next = t->next;
  30770. }
  30771. else
  30772. {
  30773. jassert (firstTimer == t);
  30774. firstTimer = t->next;
  30775. }
  30776. if (t->next != 0)
  30777. t->next->previous = t->previous;
  30778. t->next = 0;
  30779. t->previous = 0;
  30780. }
  30781. void decrementAllCounters (const int numMillisecs) const
  30782. {
  30783. Timer* t = firstTimer;
  30784. while (t != 0)
  30785. {
  30786. t->countdownMs -= numMillisecs;
  30787. t = t->next;
  30788. }
  30789. }
  30790. void handleAsyncUpdate()
  30791. {
  30792. startThread (7);
  30793. }
  30794. InternalTimerThread (const InternalTimerThread&);
  30795. InternalTimerThread& operator= (const InternalTimerThread&);
  30796. };
  30797. InternalTimerThread* InternalTimerThread::instance = 0;
  30798. CriticalSection InternalTimerThread::lock;
  30799. void juce_callAnyTimersSynchronously()
  30800. {
  30801. InternalTimerThread::callAnyTimersSynchronously();
  30802. }
  30803. #ifdef JUCE_DEBUG
  30804. static SortedSet <Timer*> activeTimers;
  30805. #endif
  30806. Timer::Timer() throw()
  30807. : countdownMs (0),
  30808. periodMs (0),
  30809. previous (0),
  30810. next (0)
  30811. {
  30812. #ifdef JUCE_DEBUG
  30813. activeTimers.add (this);
  30814. #endif
  30815. }
  30816. Timer::Timer (const Timer&) throw()
  30817. : countdownMs (0),
  30818. periodMs (0),
  30819. previous (0),
  30820. next (0)
  30821. {
  30822. #ifdef JUCE_DEBUG
  30823. activeTimers.add (this);
  30824. #endif
  30825. }
  30826. Timer::~Timer()
  30827. {
  30828. stopTimer();
  30829. #ifdef JUCE_DEBUG
  30830. activeTimers.removeValue (this);
  30831. #endif
  30832. }
  30833. void Timer::startTimer (const int interval) throw()
  30834. {
  30835. const ScopedLock sl (InternalTimerThread::lock);
  30836. #ifdef JUCE_DEBUG
  30837. // this isn't a valid object! Your timer might be a dangling pointer or something..
  30838. jassert (activeTimers.contains (this));
  30839. #endif
  30840. if (periodMs == 0)
  30841. {
  30842. countdownMs = interval;
  30843. periodMs = jmax (1, interval);
  30844. InternalTimerThread::add (this);
  30845. }
  30846. else
  30847. {
  30848. InternalTimerThread::resetCounter (this, interval);
  30849. }
  30850. }
  30851. void Timer::stopTimer() throw()
  30852. {
  30853. const ScopedLock sl (InternalTimerThread::lock);
  30854. #ifdef JUCE_DEBUG
  30855. // this isn't a valid object! Your timer might be a dangling pointer or something..
  30856. jassert (activeTimers.contains (this));
  30857. #endif
  30858. if (periodMs > 0)
  30859. {
  30860. InternalTimerThread::remove (this);
  30861. periodMs = 0;
  30862. }
  30863. }
  30864. END_JUCE_NAMESPACE
  30865. /*** End of inlined file: juce_Timer.cpp ***/
  30866. #endif
  30867. #if JUCE_BUILD_GUI
  30868. /*** Start of inlined file: juce_Component.cpp ***/
  30869. BEGIN_JUCE_NAMESPACE
  30870. Component* Component::currentlyFocusedComponent = 0;
  30871. static Array <Component*> modalComponentStack, modalComponentReturnValueKeys;
  30872. static Array <int> modalReturnValues;
  30873. enum ComponentMessageNumbers
  30874. {
  30875. customCommandMessage = 0x7fff0001,
  30876. exitModalStateMessage = 0x7fff0002
  30877. };
  30878. #define checkMessageManagerIsLocked jassert (MessageManager::getInstance()->currentThreadHasLockedMessageManager());
  30879. static uint32 nextComponentUID = 0;
  30880. Component::Component()
  30881. : parentComponent_ (0),
  30882. componentUID (++nextComponentUID),
  30883. numDeepMouseListeners (0),
  30884. lookAndFeel_ (0),
  30885. effect_ (0),
  30886. bufferedImage_ (0),
  30887. mouseListeners_ (0),
  30888. keyListeners_ (0),
  30889. componentFlags_ (0)
  30890. {
  30891. }
  30892. Component::Component (const String& name)
  30893. : componentName_ (name),
  30894. parentComponent_ (0),
  30895. componentUID (++nextComponentUID),
  30896. numDeepMouseListeners (0),
  30897. lookAndFeel_ (0),
  30898. effect_ (0),
  30899. bufferedImage_ (0),
  30900. mouseListeners_ (0),
  30901. keyListeners_ (0),
  30902. componentFlags_ (0)
  30903. {
  30904. }
  30905. Component::~Component()
  30906. {
  30907. componentListeners.call (&ComponentListener::componentBeingDeleted, *this);
  30908. if (parentComponent_ != 0)
  30909. {
  30910. parentComponent_->removeChildComponent (this);
  30911. }
  30912. else if ((currentlyFocusedComponent == this)
  30913. || isParentOf (currentlyFocusedComponent))
  30914. {
  30915. giveAwayFocus();
  30916. }
  30917. if (flags.hasHeavyweightPeerFlag)
  30918. removeFromDesktop();
  30919. modalComponentStack.removeValue (this);
  30920. for (int i = childComponentList_.size(); --i >= 0;)
  30921. childComponentList_.getUnchecked(i)->parentComponent_ = 0;
  30922. delete bufferedImage_;
  30923. delete mouseListeners_;
  30924. delete keyListeners_;
  30925. }
  30926. void Component::setName (const String& name)
  30927. {
  30928. // if component methods are being called from threads other than the message
  30929. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  30930. checkMessageManagerIsLocked
  30931. if (componentName_ != name)
  30932. {
  30933. componentName_ = name;
  30934. if (flags.hasHeavyweightPeerFlag)
  30935. {
  30936. ComponentPeer* const peer = getPeer();
  30937. jassert (peer != 0);
  30938. if (peer != 0)
  30939. peer->setTitle (name);
  30940. }
  30941. BailOutChecker checker (this);
  30942. componentListeners.callChecked (checker, &ComponentListener::componentNameChanged, *this);
  30943. }
  30944. }
  30945. void Component::setVisible (bool shouldBeVisible)
  30946. {
  30947. if (flags.visibleFlag != shouldBeVisible)
  30948. {
  30949. // if component methods are being called from threads other than the message
  30950. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  30951. checkMessageManagerIsLocked
  30952. SafePointer<Component> safePointer (this);
  30953. flags.visibleFlag = shouldBeVisible;
  30954. internalRepaint (0, 0, getWidth(), getHeight());
  30955. sendFakeMouseMove();
  30956. if (! shouldBeVisible)
  30957. {
  30958. if (currentlyFocusedComponent == this
  30959. || isParentOf (currentlyFocusedComponent))
  30960. {
  30961. if (parentComponent_ != 0)
  30962. parentComponent_->grabKeyboardFocus();
  30963. else
  30964. giveAwayFocus();
  30965. }
  30966. }
  30967. sendVisibilityChangeMessage();
  30968. if (safePointer != 0 && flags.hasHeavyweightPeerFlag)
  30969. {
  30970. ComponentPeer* const peer = getPeer();
  30971. jassert (peer != 0);
  30972. if (peer != 0)
  30973. {
  30974. peer->setVisible (shouldBeVisible);
  30975. internalHierarchyChanged();
  30976. }
  30977. }
  30978. }
  30979. }
  30980. void Component::visibilityChanged()
  30981. {
  30982. }
  30983. void Component::sendVisibilityChangeMessage()
  30984. {
  30985. BailOutChecker checker (this);
  30986. visibilityChanged();
  30987. if (! checker.shouldBailOut())
  30988. componentListeners.callChecked (checker, &ComponentListener::componentVisibilityChanged, *this);
  30989. }
  30990. bool Component::isShowing() const
  30991. {
  30992. if (flags.visibleFlag)
  30993. {
  30994. if (parentComponent_ != 0)
  30995. {
  30996. return parentComponent_->isShowing();
  30997. }
  30998. else
  30999. {
  31000. const ComponentPeer* const peer = getPeer();
  31001. return peer != 0 && ! peer->isMinimised();
  31002. }
  31003. }
  31004. return false;
  31005. }
  31006. class FadeOutProxyComponent : public Component,
  31007. public Timer
  31008. {
  31009. public:
  31010. FadeOutProxyComponent (Component* comp,
  31011. const int fadeLengthMs,
  31012. const int deltaXToMove,
  31013. const int deltaYToMove,
  31014. const float scaleFactorAtEnd)
  31015. : lastTime (0),
  31016. alpha (1.0f),
  31017. scale (1.0f)
  31018. {
  31019. image = comp->createComponentSnapshot (Rectangle<int> (0, 0, comp->getWidth(), comp->getHeight()));
  31020. setBounds (comp->getBounds());
  31021. comp->getParentComponent()->addAndMakeVisible (this);
  31022. toBehind (comp);
  31023. alphaChangePerMs = -1.0f / (float)fadeLengthMs;
  31024. centreX = comp->getX() + comp->getWidth() * 0.5f;
  31025. xChangePerMs = deltaXToMove / (float)fadeLengthMs;
  31026. centreY = comp->getY() + comp->getHeight() * 0.5f;
  31027. yChangePerMs = deltaYToMove / (float)fadeLengthMs;
  31028. scaleChangePerMs = (scaleFactorAtEnd - 1.0f) / (float)fadeLengthMs;
  31029. setInterceptsMouseClicks (false, false);
  31030. // 30 fps is enough for a fade, but we need a higher rate if it's moving as well..
  31031. startTimer (1000 / ((deltaXToMove == 0 && deltaYToMove == 0) ? 30 : 50));
  31032. }
  31033. ~FadeOutProxyComponent()
  31034. {
  31035. delete image;
  31036. }
  31037. void paint (Graphics& g)
  31038. {
  31039. g.setOpacity (alpha);
  31040. g.drawImage (image,
  31041. 0, 0, getWidth(), getHeight(),
  31042. 0, 0, image->getWidth(), image->getHeight());
  31043. }
  31044. void timerCallback()
  31045. {
  31046. const uint32 now = Time::getMillisecondCounter();
  31047. if (lastTime == 0)
  31048. lastTime = now;
  31049. const int msPassed = (now > lastTime) ? now - lastTime : 0;
  31050. lastTime = now;
  31051. alpha += alphaChangePerMs * msPassed;
  31052. if (alpha > 0)
  31053. {
  31054. if (xChangePerMs != 0.0f || yChangePerMs != 0.0f || scaleChangePerMs != 0.0f)
  31055. {
  31056. centreX += xChangePerMs * msPassed;
  31057. centreY += yChangePerMs * msPassed;
  31058. scale += scaleChangePerMs * msPassed;
  31059. const int w = roundToInt (image->getWidth() * scale);
  31060. const int h = roundToInt (image->getHeight() * scale);
  31061. setBounds (roundToInt (centreX) - w / 2,
  31062. roundToInt (centreY) - h / 2,
  31063. w, h);
  31064. }
  31065. repaint();
  31066. }
  31067. else
  31068. {
  31069. delete this;
  31070. }
  31071. }
  31072. juce_UseDebuggingNewOperator
  31073. private:
  31074. Image* image;
  31075. uint32 lastTime;
  31076. float alpha, alphaChangePerMs;
  31077. float centreX, xChangePerMs;
  31078. float centreY, yChangePerMs;
  31079. float scale, scaleChangePerMs;
  31080. FadeOutProxyComponent (const FadeOutProxyComponent&);
  31081. FadeOutProxyComponent& operator= (const FadeOutProxyComponent&);
  31082. };
  31083. void Component::fadeOutComponent (const int millisecondsToFade,
  31084. const int deltaXToMove,
  31085. const int deltaYToMove,
  31086. const float scaleFactorAtEnd)
  31087. {
  31088. //xxx won't work for comps without parents
  31089. if (isShowing() && millisecondsToFade > 0)
  31090. new FadeOutProxyComponent (this, millisecondsToFade,
  31091. deltaXToMove, deltaYToMove, scaleFactorAtEnd);
  31092. setVisible (false);
  31093. }
  31094. bool Component::isValidComponent() const
  31095. {
  31096. return (this != 0) && isValidMessageListener();
  31097. }
  31098. void* Component::getWindowHandle() const
  31099. {
  31100. const ComponentPeer* const peer = getPeer();
  31101. if (peer != 0)
  31102. return peer->getNativeHandle();
  31103. return 0;
  31104. }
  31105. void Component::addToDesktop (int styleWanted, void* nativeWindowToAttachTo)
  31106. {
  31107. // if component methods are being called from threads other than the message
  31108. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  31109. checkMessageManagerIsLocked
  31110. if (isOpaque())
  31111. styleWanted &= ~ComponentPeer::windowIsSemiTransparent;
  31112. else
  31113. styleWanted |= ComponentPeer::windowIsSemiTransparent;
  31114. int currentStyleFlags = 0;
  31115. // don't use getPeer(), so that we only get the peer that's specifically
  31116. // for this comp, and not for one of its parents.
  31117. ComponentPeer* peer = ComponentPeer::getPeerFor (this);
  31118. if (peer != 0)
  31119. currentStyleFlags = peer->getStyleFlags();
  31120. if (styleWanted != currentStyleFlags || ! flags.hasHeavyweightPeerFlag)
  31121. {
  31122. SafePointer<Component> safePointer (this);
  31123. #if JUCE_LINUX
  31124. // it's wise to give the component a non-zero size before
  31125. // putting it on the desktop, as X windows get confused by this, and
  31126. // a (1, 1) minimum size is enforced here.
  31127. setSize (jmax (1, getWidth()),
  31128. jmax (1, getHeight()));
  31129. #endif
  31130. const Point<int> topLeft (relativePositionToGlobal (Point<int> (0, 0)));
  31131. bool wasFullscreen = false;
  31132. bool wasMinimised = false;
  31133. ComponentBoundsConstrainer* currentConstainer = 0;
  31134. Rectangle<int> oldNonFullScreenBounds;
  31135. if (peer != 0)
  31136. {
  31137. wasFullscreen = peer->isFullScreen();
  31138. wasMinimised = peer->isMinimised();
  31139. currentConstainer = peer->getConstrainer();
  31140. oldNonFullScreenBounds = peer->getNonFullScreenBounds();
  31141. removeFromDesktop();
  31142. setTopLeftPosition (topLeft.getX(), topLeft.getY());
  31143. }
  31144. if (parentComponent_ != 0)
  31145. parentComponent_->removeChildComponent (this);
  31146. if (safePointer != 0)
  31147. {
  31148. flags.hasHeavyweightPeerFlag = true;
  31149. peer = createNewPeer (styleWanted, nativeWindowToAttachTo);
  31150. Desktop::getInstance().addDesktopComponent (this);
  31151. bounds_.setPosition (topLeft);
  31152. peer->setBounds (topLeft.getX(), topLeft.getY(), getWidth(), getHeight(), false);
  31153. peer->setVisible (isVisible());
  31154. if (wasFullscreen)
  31155. {
  31156. peer->setFullScreen (true);
  31157. peer->setNonFullScreenBounds (oldNonFullScreenBounds);
  31158. }
  31159. if (wasMinimised)
  31160. peer->setMinimised (true);
  31161. if (isAlwaysOnTop())
  31162. peer->setAlwaysOnTop (true);
  31163. peer->setConstrainer (currentConstainer);
  31164. repaint();
  31165. }
  31166. internalHierarchyChanged();
  31167. }
  31168. }
  31169. void Component::removeFromDesktop()
  31170. {
  31171. // if component methods are being called from threads other than the message
  31172. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  31173. checkMessageManagerIsLocked
  31174. if (flags.hasHeavyweightPeerFlag)
  31175. {
  31176. ComponentPeer* const peer = ComponentPeer::getPeerFor (this);
  31177. flags.hasHeavyweightPeerFlag = false;
  31178. jassert (peer != 0);
  31179. delete peer;
  31180. Desktop::getInstance().removeDesktopComponent (this);
  31181. }
  31182. }
  31183. bool Component::isOnDesktop() const throw()
  31184. {
  31185. return flags.hasHeavyweightPeerFlag;
  31186. }
  31187. void Component::userTriedToCloseWindow()
  31188. {
  31189. /* This means that the user's trying to get rid of your window with the 'close window' system
  31190. menu option (on windows) or possibly the task manager - you should really handle this
  31191. and delete or hide your component in an appropriate way.
  31192. If you want to ignore the event and don't want to trigger this assertion, just override
  31193. this method and do nothing.
  31194. */
  31195. jassertfalse
  31196. }
  31197. void Component::minimisationStateChanged (bool)
  31198. {
  31199. }
  31200. void Component::setOpaque (const bool shouldBeOpaque)
  31201. {
  31202. if (shouldBeOpaque != flags.opaqueFlag)
  31203. {
  31204. flags.opaqueFlag = shouldBeOpaque;
  31205. if (flags.hasHeavyweightPeerFlag)
  31206. {
  31207. const ComponentPeer* const peer = ComponentPeer::getPeerFor (this);
  31208. if (peer != 0)
  31209. {
  31210. // to make it recreate the heavyweight window
  31211. addToDesktop (peer->getStyleFlags());
  31212. }
  31213. }
  31214. repaint();
  31215. }
  31216. }
  31217. bool Component::isOpaque() const throw()
  31218. {
  31219. return flags.opaqueFlag;
  31220. }
  31221. void Component::setBufferedToImage (const bool shouldBeBuffered)
  31222. {
  31223. if (shouldBeBuffered != flags.bufferToImageFlag)
  31224. {
  31225. deleteAndZero (bufferedImage_);
  31226. flags.bufferToImageFlag = shouldBeBuffered;
  31227. }
  31228. }
  31229. void Component::toFront (const bool setAsForeground)
  31230. {
  31231. // if component methods are being called from threads other than the message
  31232. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  31233. checkMessageManagerIsLocked
  31234. if (flags.hasHeavyweightPeerFlag)
  31235. {
  31236. ComponentPeer* const peer = getPeer();
  31237. if (peer != 0)
  31238. {
  31239. peer->toFront (setAsForeground);
  31240. if (setAsForeground && ! hasKeyboardFocus (true))
  31241. grabKeyboardFocus();
  31242. }
  31243. }
  31244. else if (parentComponent_ != 0)
  31245. {
  31246. if (parentComponent_->childComponentList_.getLast() != this)
  31247. {
  31248. const int index = parentComponent_->childComponentList_.indexOf (this);
  31249. if (index >= 0)
  31250. {
  31251. int insertIndex = -1;
  31252. if (! flags.alwaysOnTopFlag)
  31253. {
  31254. insertIndex = parentComponent_->childComponentList_.size() - 1;
  31255. while (insertIndex > 0
  31256. && parentComponent_->childComponentList_.getUnchecked (insertIndex)->isAlwaysOnTop())
  31257. {
  31258. --insertIndex;
  31259. }
  31260. }
  31261. if (index != insertIndex)
  31262. {
  31263. parentComponent_->childComponentList_.move (index, insertIndex);
  31264. sendFakeMouseMove();
  31265. repaintParent();
  31266. }
  31267. }
  31268. }
  31269. if (setAsForeground)
  31270. {
  31271. internalBroughtToFront();
  31272. grabKeyboardFocus();
  31273. }
  31274. }
  31275. }
  31276. void Component::toBehind (Component* const other)
  31277. {
  31278. if (other != 0)
  31279. {
  31280. // the two components must belong to the same parent..
  31281. jassert (parentComponent_ == other->parentComponent_);
  31282. if (parentComponent_ != 0)
  31283. {
  31284. const int index = parentComponent_->childComponentList_.indexOf (this);
  31285. int otherIndex = parentComponent_->childComponentList_.indexOf (other);
  31286. if (index >= 0
  31287. && otherIndex >= 0
  31288. && index != otherIndex - 1
  31289. && other != this)
  31290. {
  31291. if (index < otherIndex)
  31292. --otherIndex;
  31293. parentComponent_->childComponentList_.move (index, otherIndex);
  31294. sendFakeMouseMove();
  31295. repaintParent();
  31296. }
  31297. }
  31298. else if (isOnDesktop())
  31299. {
  31300. jassert (other->isOnDesktop());
  31301. if (other->isOnDesktop())
  31302. {
  31303. ComponentPeer* const us = getPeer();
  31304. ComponentPeer* const them = other->getPeer();
  31305. jassert (us != 0 && them != 0);
  31306. if (us != 0 && them != 0)
  31307. us->toBehind (them);
  31308. }
  31309. }
  31310. }
  31311. }
  31312. void Component::toBack()
  31313. {
  31314. if (isOnDesktop())
  31315. {
  31316. jassertfalse //xxx need to add this to native window
  31317. }
  31318. else if (parentComponent_ != 0
  31319. && parentComponent_->childComponentList_.getFirst() != this)
  31320. {
  31321. const int index = parentComponent_->childComponentList_.indexOf (this);
  31322. if (index > 0)
  31323. {
  31324. int insertIndex = 0;
  31325. if (flags.alwaysOnTopFlag)
  31326. {
  31327. while (insertIndex < parentComponent_->childComponentList_.size()
  31328. && ! parentComponent_->childComponentList_.getUnchecked (insertIndex)->isAlwaysOnTop())
  31329. {
  31330. ++insertIndex;
  31331. }
  31332. }
  31333. if (index != insertIndex)
  31334. {
  31335. parentComponent_->childComponentList_.move (index, insertIndex);
  31336. sendFakeMouseMove();
  31337. repaintParent();
  31338. }
  31339. }
  31340. }
  31341. }
  31342. void Component::setAlwaysOnTop (const bool shouldStayOnTop)
  31343. {
  31344. if (shouldStayOnTop != flags.alwaysOnTopFlag)
  31345. {
  31346. flags.alwaysOnTopFlag = shouldStayOnTop;
  31347. if (isOnDesktop())
  31348. {
  31349. ComponentPeer* const peer = getPeer();
  31350. jassert (peer != 0);
  31351. if (peer != 0)
  31352. {
  31353. if (! peer->setAlwaysOnTop (shouldStayOnTop))
  31354. {
  31355. // some kinds of peer can't change their always-on-top status, so
  31356. // for these, we'll need to create a new window
  31357. const int oldFlags = peer->getStyleFlags();
  31358. removeFromDesktop();
  31359. addToDesktop (oldFlags);
  31360. }
  31361. }
  31362. }
  31363. if (shouldStayOnTop)
  31364. toFront (false);
  31365. internalHierarchyChanged();
  31366. }
  31367. }
  31368. bool Component::isAlwaysOnTop() const throw()
  31369. {
  31370. return flags.alwaysOnTopFlag;
  31371. }
  31372. int Component::proportionOfWidth (const float proportion) const throw()
  31373. {
  31374. return roundToInt (proportion * bounds_.getWidth());
  31375. }
  31376. int Component::proportionOfHeight (const float proportion) const throw()
  31377. {
  31378. return roundToInt (proportion * bounds_.getHeight());
  31379. }
  31380. int Component::getParentWidth() const throw()
  31381. {
  31382. return (parentComponent_ != 0) ? parentComponent_->getWidth()
  31383. : getParentMonitorArea().getWidth();
  31384. }
  31385. int Component::getParentHeight() const throw()
  31386. {
  31387. return (parentComponent_ != 0) ? parentComponent_->getHeight()
  31388. : getParentMonitorArea().getHeight();
  31389. }
  31390. int Component::getScreenX() const
  31391. {
  31392. return getScreenPosition().getX();
  31393. }
  31394. int Component::getScreenY() const
  31395. {
  31396. return getScreenPosition().getY();
  31397. }
  31398. const Point<int> Component::getScreenPosition() const
  31399. {
  31400. return (parentComponent_ != 0) ? parentComponent_->getScreenPosition() + getPosition()
  31401. : (flags.hasHeavyweightPeerFlag ? getPeer()->getScreenPosition()
  31402. : getPosition());
  31403. }
  31404. const Rectangle<int> Component::getScreenBounds() const
  31405. {
  31406. return bounds_.withPosition (getScreenPosition());
  31407. }
  31408. const Point<int> Component::relativePositionToGlobal (const Point<int>& relativePosition) const
  31409. {
  31410. const Component* c = this;
  31411. Point<int> p (relativePosition);
  31412. do
  31413. {
  31414. if (c->flags.hasHeavyweightPeerFlag)
  31415. return c->getPeer()->relativePositionToGlobal (p);
  31416. p += c->getPosition();
  31417. c = c->parentComponent_;
  31418. }
  31419. while (c != 0);
  31420. return p;
  31421. }
  31422. const Point<int> Component::globalPositionToRelative (const Point<int>& screenPosition) const
  31423. {
  31424. if (flags.hasHeavyweightPeerFlag)
  31425. {
  31426. return getPeer()->globalPositionToRelative (screenPosition);
  31427. }
  31428. else
  31429. {
  31430. if (parentComponent_ != 0)
  31431. return parentComponent_->globalPositionToRelative (screenPosition) - getPosition();
  31432. return screenPosition - getPosition();
  31433. }
  31434. }
  31435. const Point<int> Component::relativePositionToOtherComponent (const Component* const targetComponent, const Point<int>& positionRelativeToThis) const
  31436. {
  31437. Point<int> p (positionRelativeToThis);
  31438. if (targetComponent != 0)
  31439. {
  31440. const Component* c = this;
  31441. do
  31442. {
  31443. if (c == targetComponent)
  31444. return p;
  31445. if (c->flags.hasHeavyweightPeerFlag)
  31446. {
  31447. p = c->getPeer()->relativePositionToGlobal (p);
  31448. break;
  31449. }
  31450. p += c->getPosition();
  31451. c = c->parentComponent_;
  31452. }
  31453. while (c != 0);
  31454. p = targetComponent->globalPositionToRelative (p);
  31455. }
  31456. return p;
  31457. }
  31458. void Component::setBounds (int x, int y, int w, int h)
  31459. {
  31460. // if component methods are being called from threads other than the message
  31461. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  31462. checkMessageManagerIsLocked
  31463. if (w < 0) w = 0;
  31464. if (h < 0) h = 0;
  31465. const bool wasResized = (getWidth() != w || getHeight() != h);
  31466. const bool wasMoved = (getX() != x || getY() != y);
  31467. #ifdef JUCE_DEBUG
  31468. // It's a very bad idea to try to resize a window during its paint() method!
  31469. jassert (! (flags.isInsidePaintCall && wasResized && isOnDesktop()));
  31470. #endif
  31471. if (wasMoved || wasResized)
  31472. {
  31473. if (flags.visibleFlag)
  31474. {
  31475. // send a fake mouse move to trigger enter/exit messages if needed..
  31476. sendFakeMouseMove();
  31477. if (! flags.hasHeavyweightPeerFlag)
  31478. repaintParent();
  31479. }
  31480. bounds_.setBounds (x, y, w, h);
  31481. if (wasResized)
  31482. repaint();
  31483. else if (! flags.hasHeavyweightPeerFlag)
  31484. repaintParent();
  31485. if (flags.hasHeavyweightPeerFlag)
  31486. {
  31487. ComponentPeer* const peer = getPeer();
  31488. if (peer != 0)
  31489. {
  31490. if (wasMoved && wasResized)
  31491. peer->setBounds (getX(), getY(), getWidth(), getHeight(), false);
  31492. else if (wasMoved)
  31493. peer->setPosition (getX(), getY());
  31494. else if (wasResized)
  31495. peer->setSize (getWidth(), getHeight());
  31496. }
  31497. }
  31498. sendMovedResizedMessages (wasMoved, wasResized);
  31499. }
  31500. }
  31501. void Component::sendMovedResizedMessages (const bool wasMoved, const bool wasResized)
  31502. {
  31503. JUCE_TRY
  31504. {
  31505. if (wasMoved)
  31506. moved();
  31507. if (wasResized)
  31508. {
  31509. resized();
  31510. for (int i = childComponentList_.size(); --i >= 0;)
  31511. {
  31512. childComponentList_.getUnchecked(i)->parentSizeChanged();
  31513. i = jmin (i, childComponentList_.size());
  31514. }
  31515. }
  31516. BailOutChecker checker (this);
  31517. if (parentComponent_ != 0)
  31518. parentComponent_->childBoundsChanged (this);
  31519. if (! checker.shouldBailOut())
  31520. componentListeners.callChecked (checker, &ComponentListener::componentMovedOrResized,
  31521. *this, wasMoved, wasResized);
  31522. }
  31523. JUCE_CATCH_EXCEPTION
  31524. }
  31525. void Component::setSize (const int w, const int h)
  31526. {
  31527. setBounds (getX(), getY(), w, h);
  31528. }
  31529. void Component::setTopLeftPosition (const int x, const int y)
  31530. {
  31531. setBounds (x, y, getWidth(), getHeight());
  31532. }
  31533. void Component::setTopRightPosition (const int x, const int y)
  31534. {
  31535. setTopLeftPosition (x - getWidth(), y);
  31536. }
  31537. void Component::setBounds (const Rectangle<int>& r)
  31538. {
  31539. setBounds (r.getX(),
  31540. r.getY(),
  31541. r.getWidth(),
  31542. r.getHeight());
  31543. }
  31544. void Component::setBoundsRelative (const float x, const float y,
  31545. const float w, const float h)
  31546. {
  31547. const int pw = getParentWidth();
  31548. const int ph = getParentHeight();
  31549. setBounds (roundToInt (x * pw),
  31550. roundToInt (y * ph),
  31551. roundToInt (w * pw),
  31552. roundToInt (h * ph));
  31553. }
  31554. void Component::setCentrePosition (const int x, const int y)
  31555. {
  31556. setTopLeftPosition (x - getWidth() / 2,
  31557. y - getHeight() / 2);
  31558. }
  31559. void Component::setCentreRelative (const float x, const float y)
  31560. {
  31561. setCentrePosition (roundToInt (getParentWidth() * x),
  31562. roundToInt (getParentHeight() * y));
  31563. }
  31564. void Component::centreWithSize (const int width, const int height)
  31565. {
  31566. setBounds ((getParentWidth() - width) / 2,
  31567. (getParentHeight() - height) / 2,
  31568. width,
  31569. height);
  31570. }
  31571. void Component::setBoundsInset (const BorderSize& borders)
  31572. {
  31573. setBounds (borders.getLeft(),
  31574. borders.getTop(),
  31575. getParentWidth() - (borders.getLeftAndRight()),
  31576. getParentHeight() - (borders.getTopAndBottom()));
  31577. }
  31578. void Component::setBoundsToFit (int x, int y, int width, int height,
  31579. const Justification& justification,
  31580. const bool onlyReduceInSize)
  31581. {
  31582. // it's no good calling this method unless both the component and
  31583. // target rectangle have a finite size.
  31584. jassert (getWidth() > 0 && getHeight() > 0 && width > 0 && height > 0);
  31585. if (getWidth() > 0 && getHeight() > 0
  31586. && width > 0 && height > 0)
  31587. {
  31588. int newW, newH;
  31589. if (onlyReduceInSize && getWidth() <= width && getHeight() <= height)
  31590. {
  31591. newW = getWidth();
  31592. newH = getHeight();
  31593. }
  31594. else
  31595. {
  31596. const double imageRatio = getHeight() / (double) getWidth();
  31597. const double targetRatio = height / (double) width;
  31598. if (imageRatio <= targetRatio)
  31599. {
  31600. newW = width;
  31601. newH = jmin (height, roundToInt (newW * imageRatio));
  31602. }
  31603. else
  31604. {
  31605. newH = height;
  31606. newW = jmin (width, roundToInt (newH / imageRatio));
  31607. }
  31608. }
  31609. if (newW > 0 && newH > 0)
  31610. {
  31611. int newX, newY;
  31612. justification.applyToRectangle (newX, newY, newW, newH,
  31613. x, y, width, height);
  31614. setBounds (newX, newY, newW, newH);
  31615. }
  31616. }
  31617. }
  31618. bool Component::hitTest (int x, int y)
  31619. {
  31620. if (! flags.ignoresMouseClicksFlag)
  31621. return true;
  31622. if (flags.allowChildMouseClicksFlag)
  31623. {
  31624. for (int i = getNumChildComponents(); --i >= 0;)
  31625. {
  31626. Component* const c = getChildComponent (i);
  31627. if (c->isVisible()
  31628. && c->bounds_.contains (x, y)
  31629. && c->hitTest (x - c->getX(),
  31630. y - c->getY()))
  31631. {
  31632. return true;
  31633. }
  31634. }
  31635. }
  31636. return false;
  31637. }
  31638. void Component::setInterceptsMouseClicks (const bool allowClicks,
  31639. const bool allowClicksOnChildComponents) throw()
  31640. {
  31641. flags.ignoresMouseClicksFlag = ! allowClicks;
  31642. flags.allowChildMouseClicksFlag = allowClicksOnChildComponents;
  31643. }
  31644. void Component::getInterceptsMouseClicks (bool& allowsClicksOnThisComponent,
  31645. bool& allowsClicksOnChildComponents) const throw()
  31646. {
  31647. allowsClicksOnThisComponent = ! flags.ignoresMouseClicksFlag;
  31648. allowsClicksOnChildComponents = flags.allowChildMouseClicksFlag;
  31649. }
  31650. bool Component::contains (const int x, const int y)
  31651. {
  31652. if (((unsigned int) x) < (unsigned int) getWidth()
  31653. && ((unsigned int) y) < (unsigned int) getHeight()
  31654. && hitTest (x, y))
  31655. {
  31656. if (parentComponent_ != 0)
  31657. {
  31658. return parentComponent_->contains (x + getX(),
  31659. y + getY());
  31660. }
  31661. else if (flags.hasHeavyweightPeerFlag)
  31662. {
  31663. const ComponentPeer* const peer = getPeer();
  31664. if (peer != 0)
  31665. return peer->contains (Point<int> (x, y), true);
  31666. }
  31667. }
  31668. return false;
  31669. }
  31670. bool Component::reallyContains (int x, int y, const bool returnTrueIfWithinAChild)
  31671. {
  31672. if (! contains (x, y))
  31673. return false;
  31674. Component* p = this;
  31675. while (p->parentComponent_ != 0)
  31676. {
  31677. x += p->getX();
  31678. y += p->getY();
  31679. p = p->parentComponent_;
  31680. }
  31681. const Component* const c = p->getComponentAt (x, y);
  31682. return (c == this) || (returnTrueIfWithinAChild && isParentOf (c));
  31683. }
  31684. Component* Component::getComponentAt (const Point<int>& position)
  31685. {
  31686. return getComponentAt (position.getX(), position.getY());
  31687. }
  31688. Component* Component::getComponentAt (const int x, const int y)
  31689. {
  31690. if (flags.visibleFlag
  31691. && ((unsigned int) x) < (unsigned int) getWidth()
  31692. && ((unsigned int) y) < (unsigned int) getHeight()
  31693. && hitTest (x, y))
  31694. {
  31695. for (int i = childComponentList_.size(); --i >= 0;)
  31696. {
  31697. Component* const child = childComponentList_.getUnchecked(i);
  31698. Component* const c = child->getComponentAt (x - child->getX(),
  31699. y - child->getY());
  31700. if (c != 0)
  31701. return c;
  31702. }
  31703. return this;
  31704. }
  31705. return 0;
  31706. }
  31707. void Component::addChildComponent (Component* const child, int zOrder)
  31708. {
  31709. // if component methods are being called from threads other than the message
  31710. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  31711. checkMessageManagerIsLocked
  31712. if (child != 0 && child->parentComponent_ != this)
  31713. {
  31714. if (child->parentComponent_ != 0)
  31715. child->parentComponent_->removeChildComponent (child);
  31716. else
  31717. child->removeFromDesktop();
  31718. child->parentComponent_ = this;
  31719. if (child->isVisible())
  31720. child->repaintParent();
  31721. if (! child->isAlwaysOnTop())
  31722. {
  31723. if (zOrder < 0 || zOrder > childComponentList_.size())
  31724. zOrder = childComponentList_.size();
  31725. while (zOrder > 0)
  31726. {
  31727. if (! childComponentList_.getUnchecked (zOrder - 1)->isAlwaysOnTop())
  31728. break;
  31729. --zOrder;
  31730. }
  31731. }
  31732. childComponentList_.insert (zOrder, child);
  31733. child->internalHierarchyChanged();
  31734. internalChildrenChanged();
  31735. }
  31736. }
  31737. void Component::addAndMakeVisible (Component* const child, int zOrder)
  31738. {
  31739. if (child != 0)
  31740. {
  31741. child->setVisible (true);
  31742. addChildComponent (child, zOrder);
  31743. }
  31744. }
  31745. void Component::removeChildComponent (Component* const child)
  31746. {
  31747. removeChildComponent (childComponentList_.indexOf (child));
  31748. }
  31749. Component* Component::removeChildComponent (const int index)
  31750. {
  31751. // if component methods are being called from threads other than the message
  31752. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  31753. checkMessageManagerIsLocked
  31754. Component* const child = childComponentList_ [index];
  31755. if (child != 0)
  31756. {
  31757. sendFakeMouseMove();
  31758. child->repaintParent();
  31759. childComponentList_.remove (index);
  31760. child->parentComponent_ = 0;
  31761. JUCE_TRY
  31762. {
  31763. if ((currentlyFocusedComponent == child)
  31764. || child->isParentOf (currentlyFocusedComponent))
  31765. {
  31766. // get rid first to force the grabKeyboardFocus to change to us.
  31767. giveAwayFocus();
  31768. grabKeyboardFocus();
  31769. }
  31770. }
  31771. #if JUCE_CATCH_UNHANDLED_EXCEPTIONS
  31772. catch (const std::exception& e)
  31773. {
  31774. currentlyFocusedComponent = 0;
  31775. Desktop::getInstance().triggerFocusCallback();
  31776. JUCEApplication::sendUnhandledException (&e, __FILE__, __LINE__);
  31777. }
  31778. catch (...)
  31779. {
  31780. currentlyFocusedComponent = 0;
  31781. Desktop::getInstance().triggerFocusCallback();
  31782. JUCEApplication::sendUnhandledException (0, __FILE__, __LINE__);
  31783. }
  31784. #endif
  31785. child->internalHierarchyChanged();
  31786. internalChildrenChanged();
  31787. }
  31788. return child;
  31789. }
  31790. void Component::removeAllChildren()
  31791. {
  31792. for (int i = childComponentList_.size(); --i >= 0;)
  31793. removeChildComponent (i);
  31794. }
  31795. void Component::deleteAllChildren()
  31796. {
  31797. for (int i = childComponentList_.size(); --i >= 0;)
  31798. delete (removeChildComponent (i));
  31799. }
  31800. int Component::getNumChildComponents() const throw()
  31801. {
  31802. return childComponentList_.size();
  31803. }
  31804. Component* Component::getChildComponent (const int index) const throw()
  31805. {
  31806. return childComponentList_ [index];
  31807. }
  31808. int Component::getIndexOfChildComponent (const Component* const child) const throw()
  31809. {
  31810. return childComponentList_.indexOf (const_cast <Component*> (child));
  31811. }
  31812. Component* Component::getTopLevelComponent() const throw()
  31813. {
  31814. const Component* comp = this;
  31815. while (comp->parentComponent_ != 0)
  31816. comp = comp->parentComponent_;
  31817. return const_cast <Component*> (comp);
  31818. }
  31819. bool Component::isParentOf (const Component* possibleChild) const throw()
  31820. {
  31821. if (! possibleChild->isValidComponent())
  31822. {
  31823. jassert (possibleChild == 0);
  31824. return false;
  31825. }
  31826. while (possibleChild != 0)
  31827. {
  31828. possibleChild = possibleChild->parentComponent_;
  31829. if (possibleChild == this)
  31830. return true;
  31831. }
  31832. return false;
  31833. }
  31834. void Component::parentHierarchyChanged()
  31835. {
  31836. }
  31837. void Component::childrenChanged()
  31838. {
  31839. }
  31840. void Component::internalChildrenChanged()
  31841. {
  31842. if (componentListeners.isEmpty())
  31843. {
  31844. childrenChanged();
  31845. }
  31846. else
  31847. {
  31848. BailOutChecker checker (this);
  31849. childrenChanged();
  31850. if (! checker.shouldBailOut())
  31851. componentListeners.callChecked (checker, &ComponentListener::componentChildrenChanged, *this);
  31852. }
  31853. }
  31854. void Component::internalHierarchyChanged()
  31855. {
  31856. BailOutChecker checker (this);
  31857. parentHierarchyChanged();
  31858. if (checker.shouldBailOut())
  31859. return;
  31860. componentListeners.callChecked (checker, &ComponentListener::componentParentHierarchyChanged, *this);
  31861. if (checker.shouldBailOut())
  31862. return;
  31863. for (int i = childComponentList_.size(); --i >= 0;)
  31864. {
  31865. childComponentList_.getUnchecked (i)->internalHierarchyChanged();
  31866. if (checker.shouldBailOut())
  31867. {
  31868. // you really shouldn't delete the parent component during a callback telling you
  31869. // that it's changed..
  31870. jassertfalse;
  31871. return;
  31872. }
  31873. i = jmin (i, childComponentList_.size());
  31874. }
  31875. }
  31876. void* Component::runModalLoopCallback (void* userData)
  31877. {
  31878. return (void*) (pointer_sized_int) ((Component*) userData)->runModalLoop();
  31879. }
  31880. int Component::runModalLoop()
  31881. {
  31882. if (! MessageManager::getInstance()->isThisTheMessageThread())
  31883. {
  31884. // use a callback so this can be called from non-gui threads
  31885. return (int) (pointer_sized_int)
  31886. MessageManager::getInstance()
  31887. ->callFunctionOnMessageThread (&runModalLoopCallback, (void*) this);
  31888. }
  31889. SafePointer<Component> prevFocused (getCurrentlyFocusedComponent());
  31890. if (! isCurrentlyModal())
  31891. enterModalState();
  31892. JUCE_TRY
  31893. {
  31894. while (flags.currentlyModalFlag && flags.visibleFlag)
  31895. {
  31896. if (! MessageManager::getInstance()->runDispatchLoopUntil (20))
  31897. break;
  31898. // check whether this component was deleted during the last message
  31899. if (! isValidMessageListener())
  31900. break;
  31901. }
  31902. }
  31903. #if JUCE_CATCH_UNHANDLED_EXCEPTIONS
  31904. catch (const std::exception& e)
  31905. {
  31906. JUCEApplication::sendUnhandledException (&e, __FILE__, __LINE__);
  31907. return 0;
  31908. }
  31909. catch (...)
  31910. {
  31911. JUCEApplication::sendUnhandledException (0, __FILE__, __LINE__);
  31912. return 0;
  31913. }
  31914. #endif
  31915. const int modalIndex = modalComponentReturnValueKeys.indexOf (this);
  31916. int returnValue = 0;
  31917. if (modalIndex >= 0)
  31918. {
  31919. modalComponentReturnValueKeys.remove (modalIndex);
  31920. returnValue = modalReturnValues.remove (modalIndex);
  31921. }
  31922. modalComponentStack.removeValue (this);
  31923. if (prevFocused != 0)
  31924. prevFocused->grabKeyboardFocus();
  31925. return returnValue;
  31926. }
  31927. void Component::enterModalState (const bool takeKeyboardFocus_)
  31928. {
  31929. // if component methods are being called from threads other than the message
  31930. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  31931. checkMessageManagerIsLocked
  31932. // Check for an attempt to make a component modal when it already is!
  31933. // This can cause nasty problems..
  31934. jassert (! flags.currentlyModalFlag);
  31935. if (! isCurrentlyModal())
  31936. {
  31937. modalComponentStack.add (this);
  31938. modalComponentReturnValueKeys.add (this);
  31939. modalReturnValues.add (0);
  31940. flags.currentlyModalFlag = true;
  31941. setVisible (true);
  31942. if (takeKeyboardFocus_)
  31943. grabKeyboardFocus();
  31944. }
  31945. }
  31946. void Component::exitModalState (const int returnValue)
  31947. {
  31948. if (isCurrentlyModal())
  31949. {
  31950. if (MessageManager::getInstance()->isThisTheMessageThread())
  31951. {
  31952. const int modalIndex = modalComponentReturnValueKeys.indexOf (this);
  31953. if (modalIndex >= 0)
  31954. {
  31955. modalReturnValues.set (modalIndex, returnValue);
  31956. }
  31957. else
  31958. {
  31959. modalComponentReturnValueKeys.add (this);
  31960. modalReturnValues.add (returnValue);
  31961. }
  31962. modalComponentStack.removeValue (this);
  31963. flags.currentlyModalFlag = false;
  31964. bringModalComponentToFront();
  31965. }
  31966. else
  31967. {
  31968. postMessage (new Message (exitModalStateMessage, returnValue, 0, 0));
  31969. }
  31970. }
  31971. }
  31972. bool Component::isCurrentlyModal() const throw()
  31973. {
  31974. return flags.currentlyModalFlag
  31975. && getCurrentlyModalComponent() == this;
  31976. }
  31977. bool Component::isCurrentlyBlockedByAnotherModalComponent() const
  31978. {
  31979. Component* const mc = getCurrentlyModalComponent();
  31980. return mc != 0
  31981. && mc != this
  31982. && (! mc->isParentOf (this))
  31983. && ! mc->canModalEventBeSentToComponent (this);
  31984. }
  31985. int JUCE_CALLTYPE Component::getNumCurrentlyModalComponents() throw()
  31986. {
  31987. return modalComponentStack.size();
  31988. }
  31989. Component* JUCE_CALLTYPE Component::getCurrentlyModalComponent (int index) throw()
  31990. {
  31991. Component* const c = static_cast <Component*> (modalComponentStack [modalComponentStack.size() - index - 1]);
  31992. return c->isValidComponent() ? c : 0;
  31993. }
  31994. void Component::bringModalComponentToFront()
  31995. {
  31996. ComponentPeer* lastOne = 0;
  31997. for (int i = 0; i < getNumCurrentlyModalComponents(); ++i)
  31998. {
  31999. Component* const c = getCurrentlyModalComponent (i);
  32000. if (c == 0)
  32001. break;
  32002. ComponentPeer* peer = c->getPeer();
  32003. if (peer != 0 && peer != lastOne)
  32004. {
  32005. if (lastOne == 0)
  32006. {
  32007. peer->toFront (true);
  32008. peer->grabFocus();
  32009. }
  32010. else
  32011. peer->toBehind (lastOne);
  32012. lastOne = peer;
  32013. }
  32014. }
  32015. }
  32016. void Component::setBroughtToFrontOnMouseClick (const bool shouldBeBroughtToFront) throw()
  32017. {
  32018. flags.bringToFrontOnClickFlag = shouldBeBroughtToFront;
  32019. }
  32020. bool Component::isBroughtToFrontOnMouseClick() const throw()
  32021. {
  32022. return flags.bringToFrontOnClickFlag;
  32023. }
  32024. void Component::setMouseCursor (const MouseCursor& cursor)
  32025. {
  32026. if (cursor_ != cursor)
  32027. {
  32028. cursor_ = cursor;
  32029. if (flags.visibleFlag)
  32030. updateMouseCursor();
  32031. }
  32032. }
  32033. const MouseCursor Component::getMouseCursor()
  32034. {
  32035. return cursor_;
  32036. }
  32037. void Component::updateMouseCursor() const
  32038. {
  32039. sendFakeMouseMove();
  32040. }
  32041. void Component::setRepaintsOnMouseActivity (const bool shouldRepaint) throw()
  32042. {
  32043. flags.repaintOnMouseActivityFlag = shouldRepaint;
  32044. }
  32045. void Component::repaintParent()
  32046. {
  32047. if (flags.visibleFlag)
  32048. internalRepaint (0, 0, getWidth(), getHeight());
  32049. }
  32050. void Component::repaint()
  32051. {
  32052. repaint (0, 0, getWidth(), getHeight());
  32053. }
  32054. void Component::repaint (const int x, const int y,
  32055. const int w, const int h)
  32056. {
  32057. deleteAndZero (bufferedImage_);
  32058. if (flags.visibleFlag)
  32059. internalRepaint (x, y, w, h);
  32060. }
  32061. void Component::internalRepaint (int x, int y, int w, int h)
  32062. {
  32063. // if component methods are being called from threads other than the message
  32064. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  32065. checkMessageManagerIsLocked
  32066. if (x < 0)
  32067. {
  32068. w += x;
  32069. x = 0;
  32070. }
  32071. if (x + w > getWidth())
  32072. w = getWidth() - x;
  32073. if (w > 0)
  32074. {
  32075. if (y < 0)
  32076. {
  32077. h += y;
  32078. y = 0;
  32079. }
  32080. if (y + h > getHeight())
  32081. h = getHeight() - y;
  32082. if (h > 0)
  32083. {
  32084. if (parentComponent_ != 0)
  32085. {
  32086. x += getX();
  32087. y += getY();
  32088. if (parentComponent_->flags.visibleFlag)
  32089. parentComponent_->internalRepaint (x, y, w, h);
  32090. }
  32091. else if (flags.hasHeavyweightPeerFlag)
  32092. {
  32093. ComponentPeer* const peer = getPeer();
  32094. if (peer != 0)
  32095. peer->repaint (x, y, w, h);
  32096. }
  32097. }
  32098. }
  32099. }
  32100. void Component::renderComponent (Graphics& g)
  32101. {
  32102. const Rectangle<int> clipBounds (g.getClipBounds());
  32103. g.saveState();
  32104. clipObscuredRegions (g, clipBounds, 0, 0);
  32105. if (! g.isClipEmpty())
  32106. {
  32107. if (flags.bufferToImageFlag)
  32108. {
  32109. if (bufferedImage_ == 0)
  32110. {
  32111. bufferedImage_ = Image::createNativeImage (flags.opaqueFlag ? Image::RGB : Image::ARGB,
  32112. getWidth(), getHeight(), ! flags.opaqueFlag);
  32113. Graphics imG (*bufferedImage_);
  32114. paint (imG);
  32115. }
  32116. g.setColour (Colours::black);
  32117. g.drawImageAt (bufferedImage_, 0, 0);
  32118. }
  32119. else
  32120. {
  32121. paint (g);
  32122. }
  32123. }
  32124. g.restoreState();
  32125. for (int i = 0; i < childComponentList_.size(); ++i)
  32126. {
  32127. Component* const child = childComponentList_.getUnchecked (i);
  32128. if (child->isVisible() && clipBounds.intersects (child->getBounds()))
  32129. {
  32130. g.saveState();
  32131. if (g.reduceClipRegion (child->getX(), child->getY(),
  32132. child->getWidth(), child->getHeight()))
  32133. {
  32134. for (int j = i + 1; j < childComponentList_.size(); ++j)
  32135. {
  32136. const Component* const sibling = childComponentList_.getUnchecked (j);
  32137. if (sibling->flags.opaqueFlag && sibling->isVisible())
  32138. g.excludeClipRegion (sibling->getBounds());
  32139. }
  32140. if (! g.isClipEmpty())
  32141. {
  32142. g.setOrigin (child->getX(), child->getY());
  32143. child->paintEntireComponent (g);
  32144. }
  32145. }
  32146. g.restoreState();
  32147. }
  32148. }
  32149. g.saveState();
  32150. paintOverChildren (g);
  32151. g.restoreState();
  32152. }
  32153. void Component::paintEntireComponent (Graphics& g)
  32154. {
  32155. jassert (! g.isClipEmpty());
  32156. #ifdef JUCE_DEBUG
  32157. flags.isInsidePaintCall = true;
  32158. #endif
  32159. if (effect_ != 0)
  32160. {
  32161. ScopedPointer<Image> effectImage (Image::createNativeImage (flags.opaqueFlag ? Image::RGB : Image::ARGB,
  32162. getWidth(), getHeight(),
  32163. ! flags.opaqueFlag));
  32164. {
  32165. Graphics g2 (*effectImage);
  32166. renderComponent (g2);
  32167. }
  32168. effect_->applyEffect (*effectImage, g);
  32169. }
  32170. else
  32171. {
  32172. renderComponent (g);
  32173. }
  32174. #ifdef JUCE_DEBUG
  32175. flags.isInsidePaintCall = false;
  32176. #endif
  32177. }
  32178. Image* Component::createComponentSnapshot (const Rectangle<int>& areaToGrab,
  32179. const bool clipImageToComponentBounds)
  32180. {
  32181. Rectangle<int> r (areaToGrab);
  32182. if (clipImageToComponentBounds)
  32183. r = r.getIntersection (Rectangle<int> (0, 0, getWidth(), getHeight()));
  32184. ScopedPointer<Image> componentImage (Image::createNativeImage (flags.opaqueFlag ? Image::RGB : Image::ARGB,
  32185. jmax (1, r.getWidth()),
  32186. jmax (1, r.getHeight()),
  32187. true));
  32188. Graphics imageContext (*componentImage);
  32189. imageContext.setOrigin (-r.getX(), -r.getY());
  32190. paintEntireComponent (imageContext);
  32191. return componentImage.release();
  32192. }
  32193. void Component::setComponentEffect (ImageEffectFilter* const effect)
  32194. {
  32195. if (effect_ != effect)
  32196. {
  32197. effect_ = effect;
  32198. repaint();
  32199. }
  32200. }
  32201. LookAndFeel& Component::getLookAndFeel() const throw()
  32202. {
  32203. const Component* c = this;
  32204. do
  32205. {
  32206. if (c->lookAndFeel_ != 0)
  32207. return *(c->lookAndFeel_);
  32208. c = c->parentComponent_;
  32209. }
  32210. while (c != 0);
  32211. return LookAndFeel::getDefaultLookAndFeel();
  32212. }
  32213. void Component::setLookAndFeel (LookAndFeel* const newLookAndFeel)
  32214. {
  32215. if (lookAndFeel_ != newLookAndFeel)
  32216. {
  32217. lookAndFeel_ = newLookAndFeel;
  32218. sendLookAndFeelChange();
  32219. }
  32220. }
  32221. void Component::lookAndFeelChanged()
  32222. {
  32223. }
  32224. void Component::sendLookAndFeelChange()
  32225. {
  32226. repaint();
  32227. lookAndFeelChanged();
  32228. // (it's not a great idea to do anything that would delete this component
  32229. // during the lookAndFeelChanged() callback)
  32230. jassert (isValidComponent());
  32231. SafePointer<Component> safePointer (this);
  32232. for (int i = childComponentList_.size(); --i >= 0;)
  32233. {
  32234. childComponentList_.getUnchecked (i)->sendLookAndFeelChange();
  32235. if (safePointer == 0)
  32236. return;
  32237. i = jmin (i, childComponentList_.size());
  32238. }
  32239. }
  32240. static const var::identifier getColourPropertyId (const int colourId)
  32241. {
  32242. String s;
  32243. s.preallocateStorage (18);
  32244. s << T("jcclr_") << String::toHexString (colourId);
  32245. return s;
  32246. }
  32247. const Colour Component::findColour (const int colourId, const bool inheritFromParent) const
  32248. {
  32249. var* v = properties.getItem (getColourPropertyId (colourId));
  32250. if (v != 0)
  32251. return Colour ((int) *v);
  32252. if (inheritFromParent && parentComponent_ != 0)
  32253. return parentComponent_->findColour (colourId, true);
  32254. return getLookAndFeel().findColour (colourId);
  32255. }
  32256. bool Component::isColourSpecified (const int colourId) const
  32257. {
  32258. return properties.contains (getColourPropertyId (colourId));
  32259. }
  32260. void Component::removeColour (const int colourId)
  32261. {
  32262. if (properties.remove (getColourPropertyId (colourId)))
  32263. colourChanged();
  32264. }
  32265. void Component::setColour (const int colourId, const Colour& colour)
  32266. {
  32267. if (properties.set (getColourPropertyId (colourId), (int) colour.getARGB()))
  32268. colourChanged();
  32269. }
  32270. void Component::copyAllExplicitColoursTo (Component& target) const
  32271. {
  32272. bool changed = false;
  32273. for (int i = properties.size(); --i >= 0;)
  32274. {
  32275. const var::identifier name (properties.getName(i));
  32276. if (name.name.startsWith (T("jcclr_")))
  32277. if (target.properties.set (name, properties [name]))
  32278. changed = true;
  32279. }
  32280. if (changed)
  32281. target.colourChanged();
  32282. }
  32283. void Component::colourChanged()
  32284. {
  32285. }
  32286. const Rectangle<int> Component::getUnclippedArea() const
  32287. {
  32288. int x = 0, y = 0, w = getWidth(), h = getHeight();
  32289. Component* p = parentComponent_;
  32290. int px = getX();
  32291. int py = getY();
  32292. while (p != 0)
  32293. {
  32294. if (! Rectangle<int>::intersectRectangles (x, y, w, h, -px, -py, p->getWidth(), p->getHeight()))
  32295. return Rectangle<int>();
  32296. px += p->getX();
  32297. py += p->getY();
  32298. p = p->parentComponent_;
  32299. }
  32300. return Rectangle<int> (x, y, w, h);
  32301. }
  32302. void Component::clipObscuredRegions (Graphics& g, const Rectangle<int>& clipRect,
  32303. const int deltaX, const int deltaY) const
  32304. {
  32305. for (int i = childComponentList_.size(); --i >= 0;)
  32306. {
  32307. const Component* const c = childComponentList_.getUnchecked(i);
  32308. if (c->isVisible())
  32309. {
  32310. const Rectangle<int> newClip (clipRect.getIntersection (c->bounds_));
  32311. if (! newClip.isEmpty())
  32312. {
  32313. if (c->isOpaque())
  32314. {
  32315. g.excludeClipRegion (newClip.translated (deltaX, deltaY));
  32316. }
  32317. else
  32318. {
  32319. c->clipObscuredRegions (g, newClip.translated (-c->getX(), -c->getY()),
  32320. c->getX() + deltaX,
  32321. c->getY() + deltaY);
  32322. }
  32323. }
  32324. }
  32325. }
  32326. }
  32327. void Component::getVisibleArea (RectangleList& result,
  32328. const bool includeSiblings) const
  32329. {
  32330. result.clear();
  32331. const Rectangle<int> unclipped (getUnclippedArea());
  32332. if (! unclipped.isEmpty())
  32333. {
  32334. result.add (unclipped);
  32335. if (includeSiblings)
  32336. {
  32337. const Component* const c = getTopLevelComponent();
  32338. c->subtractObscuredRegions (result, c->relativePositionToOtherComponent (this, Point<int>()),
  32339. Rectangle<int> (0, 0, c->getWidth(), c->getHeight()),
  32340. this);
  32341. }
  32342. subtractObscuredRegions (result, Point<int>(), unclipped, 0);
  32343. result.consolidate();
  32344. }
  32345. }
  32346. void Component::subtractObscuredRegions (RectangleList& result,
  32347. const Point<int>& delta,
  32348. const Rectangle<int>& clipRect,
  32349. const Component* const compToAvoid) const
  32350. {
  32351. for (int i = childComponentList_.size(); --i >= 0;)
  32352. {
  32353. const Component* const c = childComponentList_.getUnchecked(i);
  32354. if (c != compToAvoid && c->isVisible())
  32355. {
  32356. if (c->isOpaque())
  32357. {
  32358. Rectangle<int> childBounds (c->bounds_.getIntersection (clipRect));
  32359. childBounds.translate (delta.getX(), delta.getY());
  32360. result.subtract (childBounds);
  32361. }
  32362. else
  32363. {
  32364. Rectangle<int> newClip (clipRect.getIntersection (c->bounds_));
  32365. newClip.translate (-c->getX(), -c->getY());
  32366. c->subtractObscuredRegions (result, c->getPosition() + delta,
  32367. newClip, compToAvoid);
  32368. }
  32369. }
  32370. }
  32371. }
  32372. void Component::mouseEnter (const MouseEvent&)
  32373. {
  32374. // base class does nothing
  32375. }
  32376. void Component::mouseExit (const MouseEvent&)
  32377. {
  32378. // base class does nothing
  32379. }
  32380. void Component::mouseDown (const MouseEvent&)
  32381. {
  32382. // base class does nothing
  32383. }
  32384. void Component::mouseUp (const MouseEvent&)
  32385. {
  32386. // base class does nothing
  32387. }
  32388. void Component::mouseDrag (const MouseEvent&)
  32389. {
  32390. // base class does nothing
  32391. }
  32392. void Component::mouseMove (const MouseEvent&)
  32393. {
  32394. // base class does nothing
  32395. }
  32396. void Component::mouseDoubleClick (const MouseEvent&)
  32397. {
  32398. // base class does nothing
  32399. }
  32400. void Component::mouseWheelMove (const MouseEvent& e, float wheelIncrementX, float wheelIncrementY)
  32401. {
  32402. // the base class just passes this event up to its parent..
  32403. if (parentComponent_ != 0)
  32404. parentComponent_->mouseWheelMove (e.getEventRelativeTo (parentComponent_),
  32405. wheelIncrementX, wheelIncrementY);
  32406. }
  32407. void Component::resized()
  32408. {
  32409. // base class does nothing
  32410. }
  32411. void Component::moved()
  32412. {
  32413. // base class does nothing
  32414. }
  32415. void Component::childBoundsChanged (Component*)
  32416. {
  32417. // base class does nothing
  32418. }
  32419. void Component::parentSizeChanged()
  32420. {
  32421. // base class does nothing
  32422. }
  32423. void Component::addComponentListener (ComponentListener* const newListener)
  32424. {
  32425. componentListeners.add (newListener);
  32426. }
  32427. void Component::removeComponentListener (ComponentListener* const listenerToRemove)
  32428. {
  32429. jassert (isValidComponent());
  32430. componentListeners.remove (listenerToRemove);
  32431. }
  32432. void Component::inputAttemptWhenModal()
  32433. {
  32434. bringModalComponentToFront();
  32435. getLookAndFeel().playAlertSound();
  32436. }
  32437. bool Component::canModalEventBeSentToComponent (const Component*)
  32438. {
  32439. return false;
  32440. }
  32441. void Component::internalModalInputAttempt()
  32442. {
  32443. Component* const current = getCurrentlyModalComponent();
  32444. if (current != 0)
  32445. current->inputAttemptWhenModal();
  32446. }
  32447. void Component::paint (Graphics&)
  32448. {
  32449. // all painting is done in the subclasses
  32450. jassert (! isOpaque()); // if your component's opaque, you've gotta paint it!
  32451. }
  32452. void Component::paintOverChildren (Graphics&)
  32453. {
  32454. // all painting is done in the subclasses
  32455. }
  32456. void Component::handleMessage (const Message& message)
  32457. {
  32458. if (message.intParameter1 == exitModalStateMessage)
  32459. {
  32460. exitModalState (message.intParameter2);
  32461. }
  32462. else if (message.intParameter1 == customCommandMessage)
  32463. {
  32464. handleCommandMessage (message.intParameter2);
  32465. }
  32466. }
  32467. void Component::postCommandMessage (const int commandId)
  32468. {
  32469. postMessage (new Message (customCommandMessage, commandId, 0, 0));
  32470. }
  32471. void Component::handleCommandMessage (int)
  32472. {
  32473. // used by subclasses
  32474. }
  32475. void Component::addMouseListener (MouseListener* const newListener,
  32476. const bool wantsEventsForAllNestedChildComponents)
  32477. {
  32478. // if component methods are being called from threads other than the message
  32479. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  32480. checkMessageManagerIsLocked
  32481. if (mouseListeners_ == 0)
  32482. mouseListeners_ = new VoidArray();
  32483. if (! mouseListeners_->contains (newListener))
  32484. {
  32485. if (wantsEventsForAllNestedChildComponents)
  32486. {
  32487. mouseListeners_->insert (0, newListener);
  32488. ++numDeepMouseListeners;
  32489. }
  32490. else
  32491. {
  32492. mouseListeners_->add (newListener);
  32493. }
  32494. }
  32495. }
  32496. void Component::removeMouseListener (MouseListener* const listenerToRemove)
  32497. {
  32498. // if component methods are being called from threads other than the message
  32499. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  32500. checkMessageManagerIsLocked
  32501. if (mouseListeners_ != 0)
  32502. {
  32503. const int index = mouseListeners_->indexOf (listenerToRemove);
  32504. if (index >= 0)
  32505. {
  32506. if (index < numDeepMouseListeners)
  32507. --numDeepMouseListeners;
  32508. mouseListeners_->remove (index);
  32509. }
  32510. }
  32511. }
  32512. void Component::internalMouseEnter (MouseInputSource& source, const Point<int>& relativePos, const Time& time)
  32513. {
  32514. if (isCurrentlyBlockedByAnotherModalComponent())
  32515. {
  32516. // if something else is modal, always just show a normal mouse cursor
  32517. source.showMouseCursor (MouseCursor::NormalCursor);
  32518. return;
  32519. }
  32520. if (! flags.mouseInsideFlag)
  32521. {
  32522. flags.mouseInsideFlag = true;
  32523. flags.mouseOverFlag = true;
  32524. flags.draggingFlag = false;
  32525. BailOutChecker checker (this);
  32526. if (flags.repaintOnMouseActivityFlag)
  32527. repaint();
  32528. const MouseEvent me (source, relativePos, source.getCurrentModifiers(),
  32529. this, time, relativePos,
  32530. time, 0, false);
  32531. mouseEnter (me);
  32532. if (checker.shouldBailOut())
  32533. return;
  32534. Desktop::getInstance().resetTimer();
  32535. Desktop::getInstance().mouseListeners.callChecked (checker, &MouseListener::mouseEnter, me);
  32536. if (checker.shouldBailOut())
  32537. return;
  32538. if (mouseListeners_ != 0)
  32539. {
  32540. for (int i = mouseListeners_->size(); --i >= 0;)
  32541. {
  32542. ((MouseListener*) mouseListeners_->getUnchecked(i))->mouseEnter (me);
  32543. if (checker.shouldBailOut())
  32544. return;
  32545. i = jmin (i, mouseListeners_->size());
  32546. }
  32547. }
  32548. Component* p = parentComponent_;
  32549. while (p != 0)
  32550. {
  32551. if (p->numDeepMouseListeners > 0)
  32552. {
  32553. BailOutChecker checker (this, p);
  32554. for (int i = p->numDeepMouseListeners; --i >= 0;)
  32555. {
  32556. ((MouseListener*) (p->mouseListeners_->getUnchecked(i)))->mouseEnter (me);
  32557. if (checker.shouldBailOut())
  32558. return;
  32559. i = jmin (i, p->numDeepMouseListeners);
  32560. }
  32561. }
  32562. p = p->parentComponent_;
  32563. }
  32564. }
  32565. }
  32566. void Component::internalMouseExit (MouseInputSource& source, const Point<int>& relativePos, const Time& time)
  32567. {
  32568. BailOutChecker checker (this);
  32569. if (flags.draggingFlag)
  32570. {
  32571. internalMouseUp (source, relativePos, time, source.getCurrentModifiers().getRawFlags());
  32572. if (checker.shouldBailOut())
  32573. return;
  32574. }
  32575. if (flags.mouseInsideFlag || flags.mouseOverFlag)
  32576. {
  32577. flags.mouseInsideFlag = false;
  32578. flags.mouseOverFlag = false;
  32579. flags.draggingFlag = false;
  32580. if (flags.repaintOnMouseActivityFlag)
  32581. repaint();
  32582. const MouseEvent me (source, relativePos, source.getCurrentModifiers(),
  32583. this, time, relativePos,
  32584. time, 0, false);
  32585. mouseExit (me);
  32586. if (checker.shouldBailOut())
  32587. return;
  32588. Desktop::getInstance().resetTimer();
  32589. Desktop::getInstance().mouseListeners.callChecked (checker, &MouseListener::mouseExit, me);
  32590. if (checker.shouldBailOut())
  32591. return;
  32592. if (mouseListeners_ != 0)
  32593. {
  32594. for (int i = mouseListeners_->size(); --i >= 0;)
  32595. {
  32596. ((MouseListener*) mouseListeners_->getUnchecked (i))->mouseExit (me);
  32597. if (checker.shouldBailOut())
  32598. return;
  32599. i = jmin (i, mouseListeners_->size());
  32600. }
  32601. }
  32602. Component* p = parentComponent_;
  32603. while (p != 0)
  32604. {
  32605. if (p->numDeepMouseListeners > 0)
  32606. {
  32607. BailOutChecker checker (this, p);
  32608. for (int i = p->numDeepMouseListeners; --i >= 0;)
  32609. {
  32610. ((MouseListener*) (p->mouseListeners_->getUnchecked (i)))->mouseExit (me);
  32611. if (checker.shouldBailOut())
  32612. return;
  32613. i = jmin (i, p->numDeepMouseListeners);
  32614. }
  32615. }
  32616. p = p->parentComponent_;
  32617. }
  32618. }
  32619. }
  32620. class InternalDragRepeater : public Timer
  32621. {
  32622. public:
  32623. InternalDragRepeater()
  32624. {}
  32625. ~InternalDragRepeater()
  32626. {
  32627. clearSingletonInstance();
  32628. }
  32629. juce_DeclareSingleton_SingleThreaded_Minimal (InternalDragRepeater)
  32630. void timerCallback()
  32631. {
  32632. Desktop& desktop = Desktop::getInstance();
  32633. int numMiceDown = 0;
  32634. for (int i = desktop.getNumMouseSources(); --i >= 0;)
  32635. {
  32636. MouseInputSource* const source = desktop.getMouseSource(i);
  32637. if (source->isDragging())
  32638. {
  32639. source->triggerFakeMove();
  32640. ++numMiceDown;
  32641. }
  32642. }
  32643. if (numMiceDown == 0)
  32644. deleteInstance();
  32645. }
  32646. juce_UseDebuggingNewOperator
  32647. private:
  32648. InternalDragRepeater (const InternalDragRepeater&);
  32649. InternalDragRepeater& operator= (const InternalDragRepeater&);
  32650. };
  32651. juce_ImplementSingleton_SingleThreaded (InternalDragRepeater)
  32652. void Component::beginDragAutoRepeat (const int interval)
  32653. {
  32654. if (interval > 0)
  32655. {
  32656. if (InternalDragRepeater::getInstance()->getTimerInterval() != interval)
  32657. InternalDragRepeater::getInstance()->startTimer (interval);
  32658. }
  32659. else
  32660. {
  32661. InternalDragRepeater::deleteInstance();
  32662. }
  32663. }
  32664. void Component::internalMouseDown (MouseInputSource& source, const Point<int>& relativePos, const Time& time)
  32665. {
  32666. Desktop& desktop = Desktop::getInstance();
  32667. BailOutChecker checker (this);
  32668. if (isCurrentlyBlockedByAnotherModalComponent())
  32669. {
  32670. internalModalInputAttempt();
  32671. if (checker.shouldBailOut())
  32672. return;
  32673. // If processing the input attempt has exited the modal loop, we'll allow the event
  32674. // to be delivered..
  32675. if (isCurrentlyBlockedByAnotherModalComponent())
  32676. {
  32677. // allow blocked mouse-events to go to global listeners..
  32678. const MouseEvent me (source, relativePos, source.getCurrentModifiers(),
  32679. this, time, relativePos, time,
  32680. source.getNumberOfMultipleClicks(), false);
  32681. desktop.resetTimer();
  32682. desktop.mouseListeners.callChecked (checker, &MouseListener::mouseDown, me);
  32683. return;
  32684. }
  32685. }
  32686. {
  32687. Component* c = this;
  32688. while (c != 0)
  32689. {
  32690. if (c->isBroughtToFrontOnMouseClick())
  32691. {
  32692. c->toFront (true);
  32693. if (checker.shouldBailOut())
  32694. return;
  32695. }
  32696. c = c->parentComponent_;
  32697. }
  32698. }
  32699. if (! flags.dontFocusOnMouseClickFlag)
  32700. {
  32701. grabFocusInternal (focusChangedByMouseClick);
  32702. if (checker.shouldBailOut())
  32703. return;
  32704. }
  32705. flags.draggingFlag = true;
  32706. flags.mouseOverFlag = true;
  32707. if (flags.repaintOnMouseActivityFlag)
  32708. repaint();
  32709. const MouseEvent me (source, relativePos, source.getCurrentModifiers(),
  32710. this, time, relativePos, time,
  32711. source.getNumberOfMultipleClicks(), false);
  32712. mouseDown (me);
  32713. if (checker.shouldBailOut())
  32714. return;
  32715. desktop.resetTimer();
  32716. desktop.mouseListeners.callChecked (checker, &MouseListener::mouseDown, me);
  32717. if (checker.shouldBailOut())
  32718. return;
  32719. if (mouseListeners_ != 0)
  32720. {
  32721. for (int i = mouseListeners_->size(); --i >= 0;)
  32722. {
  32723. ((MouseListener*) mouseListeners_->getUnchecked (i))->mouseDown (me);
  32724. if (checker.shouldBailOut())
  32725. return;
  32726. i = jmin (i, mouseListeners_->size());
  32727. }
  32728. }
  32729. Component* p = parentComponent_;
  32730. while (p != 0)
  32731. {
  32732. if (p->numDeepMouseListeners > 0)
  32733. {
  32734. BailOutChecker checker (this, p);
  32735. for (int i = p->numDeepMouseListeners; --i >= 0;)
  32736. {
  32737. ((MouseListener*) (p->mouseListeners_->getUnchecked (i)))->mouseDown (me);
  32738. if (checker.shouldBailOut())
  32739. return;
  32740. i = jmin (i, p->numDeepMouseListeners);
  32741. }
  32742. }
  32743. p = p->parentComponent_;
  32744. }
  32745. }
  32746. void Component::internalMouseUp (MouseInputSource& source, const Point<int>& relativePos, const Time& time, const ModifierKeys& oldModifiers)
  32747. {
  32748. if (flags.draggingFlag)
  32749. {
  32750. Desktop& desktop = Desktop::getInstance();
  32751. flags.draggingFlag = false;
  32752. BailOutChecker checker (this);
  32753. if (flags.repaintOnMouseActivityFlag)
  32754. repaint();
  32755. const MouseEvent me (source, relativePos,
  32756. oldModifiers, this, time,
  32757. globalPositionToRelative (source.getLastMouseDownPosition()),
  32758. source.getLastMouseDownTime(),
  32759. source.getNumberOfMultipleClicks(),
  32760. source.hasMouseMovedSignificantlySincePressed());
  32761. mouseUp (me);
  32762. if (checker.shouldBailOut())
  32763. return;
  32764. desktop.resetTimer();
  32765. desktop.mouseListeners.callChecked (checker, &MouseListener::mouseUp, me);
  32766. if (checker.shouldBailOut())
  32767. return;
  32768. if (mouseListeners_ != 0)
  32769. {
  32770. for (int i = mouseListeners_->size(); --i >= 0;)
  32771. {
  32772. ((MouseListener*) mouseListeners_->getUnchecked (i))->mouseUp (me);
  32773. if (checker.shouldBailOut())
  32774. return;
  32775. i = jmin (i, mouseListeners_->size());
  32776. }
  32777. }
  32778. {
  32779. Component* p = parentComponent_;
  32780. while (p != 0)
  32781. {
  32782. if (p->numDeepMouseListeners > 0)
  32783. {
  32784. BailOutChecker checker (this, p);
  32785. for (int i = p->numDeepMouseListeners; --i >= 0;)
  32786. {
  32787. ((MouseListener*) (p->mouseListeners_->getUnchecked (i)))->mouseUp (me);
  32788. if (checker.shouldBailOut())
  32789. return;
  32790. i = jmin (i, p->numDeepMouseListeners);
  32791. }
  32792. }
  32793. p = p->parentComponent_;
  32794. }
  32795. }
  32796. // check for double-click
  32797. if (me.getNumberOfClicks() >= 2)
  32798. {
  32799. const int numListeners = (mouseListeners_ != 0) ? mouseListeners_->size() : 0;
  32800. mouseDoubleClick (me);
  32801. if (checker.shouldBailOut())
  32802. return;
  32803. desktop.mouseListeners.callChecked (checker, &MouseListener::mouseDoubleClick, me);
  32804. if (checker.shouldBailOut())
  32805. return;
  32806. for (int i = numListeners; --i >= 0;)
  32807. {
  32808. if (checker.shouldBailOut())
  32809. return;
  32810. MouseListener* const ml = (MouseListener*)((*mouseListeners_)[i]);
  32811. if (ml != 0)
  32812. ml->mouseDoubleClick (me);
  32813. }
  32814. if (checker.shouldBailOut())
  32815. return;
  32816. Component* p = parentComponent_;
  32817. while (p != 0)
  32818. {
  32819. if (p->numDeepMouseListeners > 0)
  32820. {
  32821. BailOutChecker checker (this, p);
  32822. for (int i = p->numDeepMouseListeners; --i >= 0;)
  32823. {
  32824. ((MouseListener*) (p->mouseListeners_->getUnchecked (i)))->mouseDoubleClick (me);
  32825. if (checker.shouldBailOut())
  32826. return;
  32827. i = jmin (i, p->numDeepMouseListeners);
  32828. }
  32829. }
  32830. p = p->parentComponent_;
  32831. }
  32832. }
  32833. }
  32834. }
  32835. void Component::internalMouseDrag (MouseInputSource& source, const Point<int>& relativePos, const Time& time)
  32836. {
  32837. if (flags.draggingFlag)
  32838. {
  32839. Desktop& desktop = Desktop::getInstance();
  32840. flags.mouseOverFlag = reallyContains (relativePos.getX(), relativePos.getY(), false);
  32841. BailOutChecker checker (this);
  32842. const MouseEvent me (source, relativePos,
  32843. source.getCurrentModifiers(), this, time,
  32844. globalPositionToRelative (source.getLastMouseDownPosition()),
  32845. source.getLastMouseDownTime(),
  32846. source.getNumberOfMultipleClicks(),
  32847. source.hasMouseMovedSignificantlySincePressed());
  32848. mouseDrag (me);
  32849. if (checker.shouldBailOut())
  32850. return;
  32851. desktop.resetTimer();
  32852. desktop.mouseListeners.callChecked (checker, &MouseListener::mouseDrag, me);
  32853. if (checker.shouldBailOut())
  32854. return;
  32855. if (mouseListeners_ != 0)
  32856. {
  32857. for (int i = mouseListeners_->size(); --i >= 0;)
  32858. {
  32859. ((MouseListener*) mouseListeners_->getUnchecked (i))->mouseDrag (me);
  32860. if (checker.shouldBailOut())
  32861. return;
  32862. i = jmin (i, mouseListeners_->size());
  32863. }
  32864. }
  32865. Component* p = parentComponent_;
  32866. while (p != 0)
  32867. {
  32868. if (p->numDeepMouseListeners > 0)
  32869. {
  32870. BailOutChecker checker (this, p);
  32871. for (int i = p->numDeepMouseListeners; --i >= 0;)
  32872. {
  32873. ((MouseListener*) (p->mouseListeners_->getUnchecked (i)))->mouseDrag (me);
  32874. if (checker.shouldBailOut())
  32875. return;
  32876. i = jmin (i, p->numDeepMouseListeners);
  32877. }
  32878. }
  32879. p = p->parentComponent_;
  32880. }
  32881. }
  32882. }
  32883. void Component::internalMouseMove (MouseInputSource& source, const Point<int>& relativePos, const Time& time)
  32884. {
  32885. Desktop& desktop = Desktop::getInstance();
  32886. BailOutChecker checker (this);
  32887. const MouseEvent me (source, relativePos, source.getCurrentModifiers(),
  32888. this, time, relativePos,
  32889. time, 0, false);
  32890. if (isCurrentlyBlockedByAnotherModalComponent())
  32891. {
  32892. // allow blocked mouse-events to go to global listeners..
  32893. desktop.sendMouseMove();
  32894. }
  32895. else
  32896. {
  32897. flags.mouseOverFlag = true;
  32898. mouseMove (me);
  32899. if (checker.shouldBailOut())
  32900. return;
  32901. desktop.resetTimer();
  32902. desktop.mouseListeners.callChecked (checker, &MouseListener::mouseMove, me);
  32903. if (checker.shouldBailOut())
  32904. return;
  32905. if (mouseListeners_ != 0)
  32906. {
  32907. for (int i = mouseListeners_->size(); --i >= 0;)
  32908. {
  32909. ((MouseListener*) mouseListeners_->getUnchecked (i))->mouseMove (me);
  32910. if (checker.shouldBailOut())
  32911. return;
  32912. i = jmin (i, mouseListeners_->size());
  32913. }
  32914. }
  32915. Component* p = parentComponent_;
  32916. while (p != 0)
  32917. {
  32918. if (p->numDeepMouseListeners > 0)
  32919. {
  32920. BailOutChecker checker (this, p);
  32921. for (int i = p->numDeepMouseListeners; --i >= 0;)
  32922. {
  32923. ((MouseListener*) (p->mouseListeners_->getUnchecked (i)))->mouseMove (me);
  32924. if (checker.shouldBailOut())
  32925. return;
  32926. i = jmin (i, p->numDeepMouseListeners);
  32927. }
  32928. }
  32929. p = p->parentComponent_;
  32930. }
  32931. }
  32932. }
  32933. void Component::internalMouseWheel (MouseInputSource& source, const Point<int>& relativePos,
  32934. const Time& time, const float amountX, const float amountY)
  32935. {
  32936. Desktop& desktop = Desktop::getInstance();
  32937. BailOutChecker checker (this);
  32938. const float wheelIncrementX = amountX * (1.0f / 256.0f);
  32939. const float wheelIncrementY = amountY * (1.0f / 256.0f);
  32940. const MouseEvent me (source, relativePos, source.getCurrentModifiers(),
  32941. this, time, relativePos, time, 0, false);
  32942. if (isCurrentlyBlockedByAnotherModalComponent())
  32943. {
  32944. // allow blocked mouse-events to go to global listeners..
  32945. desktop.mouseListeners.callChecked (checker, &MouseListener::mouseWheelMove, me, wheelIncrementX, wheelIncrementY);
  32946. }
  32947. else
  32948. {
  32949. mouseWheelMove (me, wheelIncrementX, wheelIncrementY);
  32950. if (checker.shouldBailOut())
  32951. return;
  32952. desktop.mouseListeners.callChecked (checker, &MouseListener::mouseWheelMove, me, wheelIncrementX, wheelIncrementY);
  32953. if (checker.shouldBailOut())
  32954. return;
  32955. if (mouseListeners_ != 0)
  32956. {
  32957. for (int i = mouseListeners_->size(); --i >= 0;)
  32958. {
  32959. ((MouseListener*) mouseListeners_->getUnchecked (i))->mouseWheelMove (me, wheelIncrementX, wheelIncrementY);
  32960. if (checker.shouldBailOut())
  32961. return;
  32962. i = jmin (i, mouseListeners_->size());
  32963. }
  32964. }
  32965. Component* p = parentComponent_;
  32966. while (p != 0)
  32967. {
  32968. if (p->numDeepMouseListeners > 0)
  32969. {
  32970. BailOutChecker checker (this, p);
  32971. for (int i = p->numDeepMouseListeners; --i >= 0;)
  32972. {
  32973. ((MouseListener*) (p->mouseListeners_->getUnchecked (i)))->mouseWheelMove (me, wheelIncrementX, wheelIncrementY);
  32974. if (checker.shouldBailOut())
  32975. return;
  32976. i = jmin (i, p->numDeepMouseListeners);
  32977. }
  32978. }
  32979. p = p->parentComponent_;
  32980. }
  32981. }
  32982. }
  32983. void Component::sendFakeMouseMove() const
  32984. {
  32985. Desktop::getInstance().getMainMouseSource().triggerFakeMove();
  32986. }
  32987. void Component::broughtToFront()
  32988. {
  32989. }
  32990. void Component::internalBroughtToFront()
  32991. {
  32992. if (! isValidComponent())
  32993. return;
  32994. if (flags.hasHeavyweightPeerFlag)
  32995. Desktop::getInstance().componentBroughtToFront (this);
  32996. BailOutChecker checker (this);
  32997. broughtToFront();
  32998. if (checker.shouldBailOut())
  32999. return;
  33000. componentListeners.callChecked (checker, &ComponentListener::componentBroughtToFront, *this);
  33001. if (checker.shouldBailOut())
  33002. return;
  33003. // When brought to the front and there's a modal component blocking this one,
  33004. // we need to bring the modal one to the front instead..
  33005. Component* const cm = getCurrentlyModalComponent();
  33006. if (cm != 0 && cm->getTopLevelComponent() != getTopLevelComponent())
  33007. bringModalComponentToFront();
  33008. }
  33009. void Component::focusGained (FocusChangeType)
  33010. {
  33011. // base class does nothing
  33012. }
  33013. void Component::internalFocusGain (const FocusChangeType cause)
  33014. {
  33015. SafePointer<Component> safePointer (this);
  33016. focusGained (cause);
  33017. if (safePointer != 0)
  33018. internalChildFocusChange (cause);
  33019. }
  33020. void Component::focusLost (FocusChangeType)
  33021. {
  33022. // base class does nothing
  33023. }
  33024. void Component::internalFocusLoss (const FocusChangeType cause)
  33025. {
  33026. SafePointer<Component> safePointer (this);
  33027. focusLost (focusChangedDirectly);
  33028. if (safePointer != 0)
  33029. internalChildFocusChange (cause);
  33030. }
  33031. void Component::focusOfChildComponentChanged (FocusChangeType /*cause*/)
  33032. {
  33033. // base class does nothing
  33034. }
  33035. void Component::internalChildFocusChange (FocusChangeType cause)
  33036. {
  33037. const bool childIsNowFocused = hasKeyboardFocus (true);
  33038. if (flags.childCompFocusedFlag != childIsNowFocused)
  33039. {
  33040. flags.childCompFocusedFlag = childIsNowFocused;
  33041. SafePointer<Component> safePointer (this);
  33042. focusOfChildComponentChanged (cause);
  33043. if (safePointer == 0)
  33044. return;
  33045. }
  33046. if (parentComponent_ != 0)
  33047. parentComponent_->internalChildFocusChange (cause);
  33048. }
  33049. bool Component::isEnabled() const throw()
  33050. {
  33051. return (! flags.isDisabledFlag)
  33052. && (parentComponent_ == 0 || parentComponent_->isEnabled());
  33053. }
  33054. void Component::setEnabled (const bool shouldBeEnabled)
  33055. {
  33056. if (flags.isDisabledFlag == shouldBeEnabled)
  33057. {
  33058. flags.isDisabledFlag = ! shouldBeEnabled;
  33059. // if any parent components are disabled, setting our flag won't make a difference,
  33060. // so no need to send a change message
  33061. if (parentComponent_ == 0 || parentComponent_->isEnabled())
  33062. sendEnablementChangeMessage();
  33063. }
  33064. }
  33065. void Component::sendEnablementChangeMessage()
  33066. {
  33067. SafePointer<Component> safePointer (this);
  33068. enablementChanged();
  33069. if (safePointer == 0)
  33070. return;
  33071. for (int i = getNumChildComponents(); --i >= 0;)
  33072. {
  33073. Component* const c = getChildComponent (i);
  33074. if (c != 0)
  33075. {
  33076. c->sendEnablementChangeMessage();
  33077. if (safePointer == 0)
  33078. return;
  33079. }
  33080. }
  33081. }
  33082. void Component::enablementChanged()
  33083. {
  33084. }
  33085. void Component::setWantsKeyboardFocus (const bool wantsFocus) throw()
  33086. {
  33087. flags.wantsFocusFlag = wantsFocus;
  33088. }
  33089. void Component::setMouseClickGrabsKeyboardFocus (const bool shouldGrabFocus)
  33090. {
  33091. flags.dontFocusOnMouseClickFlag = ! shouldGrabFocus;
  33092. }
  33093. bool Component::getMouseClickGrabsKeyboardFocus() const throw()
  33094. {
  33095. return ! flags.dontFocusOnMouseClickFlag;
  33096. }
  33097. bool Component::getWantsKeyboardFocus() const throw()
  33098. {
  33099. return flags.wantsFocusFlag && ! flags.isDisabledFlag;
  33100. }
  33101. void Component::setFocusContainer (const bool shouldBeFocusContainer) throw()
  33102. {
  33103. flags.isFocusContainerFlag = shouldBeFocusContainer;
  33104. }
  33105. bool Component::isFocusContainer() const throw()
  33106. {
  33107. return flags.isFocusContainerFlag;
  33108. }
  33109. int Component::getExplicitFocusOrder() const
  33110. {
  33111. return properties ["_jexfo"];
  33112. }
  33113. void Component::setExplicitFocusOrder (const int newFocusOrderIndex)
  33114. {
  33115. properties.set ("_jexfo", newFocusOrderIndex);
  33116. }
  33117. KeyboardFocusTraverser* Component::createFocusTraverser()
  33118. {
  33119. if (flags.isFocusContainerFlag || parentComponent_ == 0)
  33120. return new KeyboardFocusTraverser();
  33121. return parentComponent_->createFocusTraverser();
  33122. }
  33123. void Component::takeKeyboardFocus (const FocusChangeType cause)
  33124. {
  33125. // give the focus to this component
  33126. if (currentlyFocusedComponent != this)
  33127. {
  33128. JUCE_TRY
  33129. {
  33130. // get the focus onto our desktop window
  33131. ComponentPeer* const peer = getPeer();
  33132. if (peer != 0)
  33133. {
  33134. SafePointer<Component> safePointer (this);
  33135. peer->grabFocus();
  33136. if (peer->isFocused() && currentlyFocusedComponent != this)
  33137. {
  33138. Component* const componentLosingFocus = currentlyFocusedComponent;
  33139. currentlyFocusedComponent = this;
  33140. Desktop::getInstance().triggerFocusCallback();
  33141. // call this after setting currentlyFocusedComponent so that the one that's
  33142. // losing it has a chance to see where focus is going
  33143. if (componentLosingFocus->isValidComponent())
  33144. componentLosingFocus->internalFocusLoss (cause);
  33145. if (currentlyFocusedComponent == this)
  33146. {
  33147. focusGained (cause);
  33148. if (safePointer != 0)
  33149. internalChildFocusChange (cause);
  33150. }
  33151. }
  33152. }
  33153. }
  33154. #if JUCE_CATCH_UNHANDLED_EXCEPTIONS
  33155. catch (const std::exception& e)
  33156. {
  33157. currentlyFocusedComponent = 0;
  33158. Desktop::getInstance().triggerFocusCallback();
  33159. JUCEApplication::sendUnhandledException (&e, __FILE__, __LINE__);
  33160. }
  33161. catch (...)
  33162. {
  33163. currentlyFocusedComponent = 0;
  33164. Desktop::getInstance().triggerFocusCallback();
  33165. JUCEApplication::sendUnhandledException (0, __FILE__, __LINE__);
  33166. }
  33167. #endif
  33168. }
  33169. }
  33170. void Component::grabFocusInternal (const FocusChangeType cause, const bool canTryParent)
  33171. {
  33172. if (isShowing())
  33173. {
  33174. if (flags.wantsFocusFlag && (isEnabled() || parentComponent_ == 0))
  33175. {
  33176. takeKeyboardFocus (cause);
  33177. }
  33178. else
  33179. {
  33180. if (isParentOf (currentlyFocusedComponent)
  33181. && currentlyFocusedComponent->isShowing())
  33182. {
  33183. // do nothing if the focused component is actually a child of ours..
  33184. }
  33185. else
  33186. {
  33187. // find the default child component..
  33188. ScopedPointer <KeyboardFocusTraverser> traverser (createFocusTraverser());
  33189. if (traverser != 0)
  33190. {
  33191. Component* const defaultComp = traverser->getDefaultComponent (this);
  33192. traverser = 0;
  33193. if (defaultComp != 0)
  33194. {
  33195. defaultComp->grabFocusInternal (cause, false);
  33196. return;
  33197. }
  33198. }
  33199. if (canTryParent && parentComponent_ != 0)
  33200. {
  33201. // if no children want it and we're allowed to try our parent comp,
  33202. // then pass up to parent, which will try our siblings.
  33203. parentComponent_->grabFocusInternal (cause, true);
  33204. }
  33205. }
  33206. }
  33207. }
  33208. }
  33209. void Component::grabKeyboardFocus()
  33210. {
  33211. // if component methods are being called from threads other than the message
  33212. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  33213. checkMessageManagerIsLocked
  33214. grabFocusInternal (focusChangedDirectly);
  33215. }
  33216. void Component::moveKeyboardFocusToSibling (const bool moveToNext)
  33217. {
  33218. // if component methods are being called from threads other than the message
  33219. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  33220. checkMessageManagerIsLocked
  33221. if (parentComponent_ != 0)
  33222. {
  33223. ScopedPointer <KeyboardFocusTraverser> traverser (createFocusTraverser());
  33224. if (traverser != 0)
  33225. {
  33226. Component* const nextComp = moveToNext ? traverser->getNextComponent (this)
  33227. : traverser->getPreviousComponent (this);
  33228. traverser = 0;
  33229. if (nextComp != 0)
  33230. {
  33231. if (nextComp->isCurrentlyBlockedByAnotherModalComponent())
  33232. {
  33233. SafePointer<Component> safePointer (this);
  33234. internalModalInputAttempt();
  33235. if (safePointer == 0 || nextComp->isCurrentlyBlockedByAnotherModalComponent())
  33236. return;
  33237. }
  33238. nextComp->grabFocusInternal (focusChangedByTabKey);
  33239. return;
  33240. }
  33241. }
  33242. parentComponent_->moveKeyboardFocusToSibling (moveToNext);
  33243. }
  33244. }
  33245. bool Component::hasKeyboardFocus (const bool trueIfChildIsFocused) const
  33246. {
  33247. return (currentlyFocusedComponent == this)
  33248. || (trueIfChildIsFocused && isParentOf (currentlyFocusedComponent));
  33249. }
  33250. Component* JUCE_CALLTYPE Component::getCurrentlyFocusedComponent() throw()
  33251. {
  33252. return currentlyFocusedComponent;
  33253. }
  33254. void Component::giveAwayFocus()
  33255. {
  33256. // use a copy so we can clear the value before the call
  33257. Component* const componentLosingFocus = currentlyFocusedComponent;
  33258. currentlyFocusedComponent = 0;
  33259. Desktop::getInstance().triggerFocusCallback();
  33260. if (componentLosingFocus->isValidComponent())
  33261. componentLosingFocus->internalFocusLoss (focusChangedDirectly);
  33262. }
  33263. bool Component::isMouseOver() const throw()
  33264. {
  33265. return flags.mouseOverFlag;
  33266. }
  33267. bool Component::isMouseButtonDown() const throw()
  33268. {
  33269. return flags.draggingFlag;
  33270. }
  33271. bool Component::isMouseOverOrDragging() const throw()
  33272. {
  33273. return flags.mouseOverFlag || flags.draggingFlag;
  33274. }
  33275. bool JUCE_CALLTYPE Component::isMouseButtonDownAnywhere() throw()
  33276. {
  33277. return ModifierKeys::getCurrentModifiers().isAnyMouseButtonDown();
  33278. }
  33279. const Point<int> Component::getMouseXYRelative() const
  33280. {
  33281. return globalPositionToRelative (Desktop::getMousePosition());
  33282. }
  33283. const Rectangle<int> Component::getParentMonitorArea() const
  33284. {
  33285. return Desktop::getInstance()
  33286. .getMonitorAreaContaining (relativePositionToGlobal (Point<int> (getWidth() / 2,
  33287. getHeight() / 2)));
  33288. }
  33289. void Component::addKeyListener (KeyListener* const newListener)
  33290. {
  33291. if (keyListeners_ == 0)
  33292. keyListeners_ = new VoidArray();
  33293. keyListeners_->addIfNotAlreadyThere (newListener);
  33294. }
  33295. void Component::removeKeyListener (KeyListener* const listenerToRemove)
  33296. {
  33297. if (keyListeners_ != 0)
  33298. keyListeners_->removeValue (listenerToRemove);
  33299. }
  33300. bool Component::keyPressed (const KeyPress&)
  33301. {
  33302. return false;
  33303. }
  33304. bool Component::keyStateChanged (const bool /*isKeyDown*/)
  33305. {
  33306. return false;
  33307. }
  33308. void Component::modifierKeysChanged (const ModifierKeys& modifiers)
  33309. {
  33310. if (parentComponent_ != 0)
  33311. parentComponent_->modifierKeysChanged (modifiers);
  33312. }
  33313. void Component::internalModifierKeysChanged()
  33314. {
  33315. sendFakeMouseMove();
  33316. modifierKeysChanged (ModifierKeys::getCurrentModifiers());
  33317. }
  33318. ComponentPeer* Component::getPeer() const
  33319. {
  33320. if (flags.hasHeavyweightPeerFlag)
  33321. return ComponentPeer::getPeerFor (this);
  33322. else if (parentComponent_ != 0)
  33323. return parentComponent_->getPeer();
  33324. else
  33325. return 0;
  33326. }
  33327. Component::BailOutChecker::BailOutChecker (Component* const component1, Component* const component2_)
  33328. : safePointer1 (component1), safePointer2 (component2_), component2 (component2_)
  33329. {
  33330. jassert (component1 != 0);
  33331. }
  33332. bool Component::BailOutChecker::shouldBailOut() const throw()
  33333. {
  33334. return safePointer1 == 0 || safePointer2.getComponent() != component2;
  33335. }
  33336. END_JUCE_NAMESPACE
  33337. /*** End of inlined file: juce_Component.cpp ***/
  33338. /*** Start of inlined file: juce_ComponentListener.cpp ***/
  33339. BEGIN_JUCE_NAMESPACE
  33340. void ComponentListener::componentMovedOrResized (Component&, bool, bool) {}
  33341. void ComponentListener::componentBroughtToFront (Component&) {}
  33342. void ComponentListener::componentVisibilityChanged (Component&) {}
  33343. void ComponentListener::componentChildrenChanged (Component&) {}
  33344. void ComponentListener::componentParentHierarchyChanged (Component&) {}
  33345. void ComponentListener::componentNameChanged (Component&) {}
  33346. void ComponentListener::componentBeingDeleted (Component&) {}
  33347. END_JUCE_NAMESPACE
  33348. /*** End of inlined file: juce_ComponentListener.cpp ***/
  33349. /*** Start of inlined file: juce_Desktop.cpp ***/
  33350. BEGIN_JUCE_NAMESPACE
  33351. Desktop::Desktop()
  33352. : mouseClickCounter (0),
  33353. kioskModeComponent (0)
  33354. {
  33355. createMouseInputSources();
  33356. refreshMonitorSizes();
  33357. }
  33358. Desktop::~Desktop()
  33359. {
  33360. jassert (instance == this);
  33361. instance = 0;
  33362. // doh! If you don't delete all your windows before exiting, you're going to
  33363. // be leaking memory!
  33364. jassert (desktopComponents.size() == 0);
  33365. }
  33366. Desktop& JUCE_CALLTYPE Desktop::getInstance()
  33367. {
  33368. if (instance == 0)
  33369. instance = new Desktop();
  33370. return *instance;
  33371. }
  33372. Desktop* Desktop::instance = 0;
  33373. extern void juce_updateMultiMonitorInfo (Array <Rectangle<int> >& monitorCoords,
  33374. const bool clipToWorkArea);
  33375. void Desktop::refreshMonitorSizes()
  33376. {
  33377. const Array <Rectangle<int> > oldClipped (monitorCoordsClipped);
  33378. const Array <Rectangle<int> > oldUnclipped (monitorCoordsUnclipped);
  33379. monitorCoordsClipped.clear();
  33380. monitorCoordsUnclipped.clear();
  33381. juce_updateMultiMonitorInfo (monitorCoordsClipped, true);
  33382. juce_updateMultiMonitorInfo (monitorCoordsUnclipped, false);
  33383. jassert (monitorCoordsClipped.size() > 0
  33384. && monitorCoordsClipped.size() == monitorCoordsUnclipped.size());
  33385. if (oldClipped != monitorCoordsClipped
  33386. || oldUnclipped != monitorCoordsUnclipped)
  33387. {
  33388. for (int i = ComponentPeer::getNumPeers(); --i >= 0;)
  33389. {
  33390. ComponentPeer* const p = ComponentPeer::getPeer (i);
  33391. if (p != 0)
  33392. p->handleScreenSizeChange();
  33393. }
  33394. }
  33395. }
  33396. int Desktop::getNumDisplayMonitors() const throw()
  33397. {
  33398. return monitorCoordsClipped.size();
  33399. }
  33400. const Rectangle<int> Desktop::getDisplayMonitorCoordinates (const int index, const bool clippedToWorkArea) const throw()
  33401. {
  33402. return clippedToWorkArea ? monitorCoordsClipped [index]
  33403. : monitorCoordsUnclipped [index];
  33404. }
  33405. const RectangleList Desktop::getAllMonitorDisplayAreas (const bool clippedToWorkArea) const throw()
  33406. {
  33407. RectangleList rl;
  33408. for (int i = 0; i < getNumDisplayMonitors(); ++i)
  33409. rl.addWithoutMerging (getDisplayMonitorCoordinates (i, clippedToWorkArea));
  33410. return rl;
  33411. }
  33412. const Rectangle<int> Desktop::getMainMonitorArea (const bool clippedToWorkArea) const throw()
  33413. {
  33414. return getDisplayMonitorCoordinates (0, clippedToWorkArea);
  33415. }
  33416. const Rectangle<int> Desktop::getMonitorAreaContaining (const Point<int>& position, const bool clippedToWorkArea) const
  33417. {
  33418. Rectangle<int> best (getMainMonitorArea (clippedToWorkArea));
  33419. double bestDistance = 1.0e10;
  33420. for (int i = getNumDisplayMonitors(); --i >= 0;)
  33421. {
  33422. const Rectangle<int> rect (getDisplayMonitorCoordinates (i, clippedToWorkArea));
  33423. if (rect.contains (position))
  33424. return rect;
  33425. const double distance = rect.getCentre().getDistanceFrom (position);
  33426. if (distance < bestDistance)
  33427. {
  33428. bestDistance = distance;
  33429. best = rect;
  33430. }
  33431. }
  33432. return best;
  33433. }
  33434. int Desktop::getNumComponents() const throw()
  33435. {
  33436. return desktopComponents.size();
  33437. }
  33438. Component* Desktop::getComponent (const int index) const throw()
  33439. {
  33440. return desktopComponents [index];
  33441. }
  33442. Component* Desktop::findComponentAt (const Point<int>& screenPosition) const
  33443. {
  33444. for (int i = desktopComponents.size(); --i >= 0;)
  33445. {
  33446. Component* const c = desktopComponents.getUnchecked(i);
  33447. const Point<int> relative (c->globalPositionToRelative (screenPosition));
  33448. if (c->contains (relative.getX(), relative.getY()))
  33449. return c->getComponentAt (relative.getX(), relative.getY());
  33450. }
  33451. return 0;
  33452. }
  33453. void Desktop::addDesktopComponent (Component* const c)
  33454. {
  33455. jassert (c != 0);
  33456. jassert (! desktopComponents.contains (c));
  33457. desktopComponents.addIfNotAlreadyThere (c);
  33458. }
  33459. void Desktop::removeDesktopComponent (Component* const c)
  33460. {
  33461. desktopComponents.removeValue (c);
  33462. }
  33463. void Desktop::componentBroughtToFront (Component* const c)
  33464. {
  33465. const int index = desktopComponents.indexOf (c);
  33466. jassert (index >= 0);
  33467. if (index >= 0)
  33468. {
  33469. int newIndex = -1;
  33470. if (! c->isAlwaysOnTop())
  33471. {
  33472. newIndex = desktopComponents.size();
  33473. while (newIndex > 0 && desktopComponents.getUnchecked (newIndex - 1)->isAlwaysOnTop())
  33474. --newIndex;
  33475. --newIndex;
  33476. }
  33477. desktopComponents.move (index, newIndex);
  33478. }
  33479. }
  33480. const Point<int> Desktop::getLastMouseDownPosition() throw()
  33481. {
  33482. return getInstance().getMainMouseSource().getLastMouseDownPosition();
  33483. }
  33484. int Desktop::getMouseButtonClickCounter() throw()
  33485. {
  33486. return getInstance().mouseClickCounter;
  33487. }
  33488. void Desktop::incrementMouseClickCounter() throw()
  33489. {
  33490. ++mouseClickCounter;
  33491. }
  33492. int Desktop::getNumDraggingMouseSources() const throw()
  33493. {
  33494. int num = 0;
  33495. for (int i = mouseSources.size(); --i >= 0;)
  33496. if (mouseSources.getUnchecked(i)->isDragging())
  33497. ++num;
  33498. return num;
  33499. }
  33500. MouseInputSource* Desktop::getDraggingMouseSource (int index) const throw()
  33501. {
  33502. int num = 0;
  33503. for (int i = mouseSources.size(); --i >= 0;)
  33504. {
  33505. MouseInputSource* const mi = mouseSources.getUnchecked(i);
  33506. if (mi->isDragging())
  33507. {
  33508. if (index == num)
  33509. return mi;
  33510. ++num;
  33511. }
  33512. }
  33513. return 0;
  33514. }
  33515. void Desktop::addFocusChangeListener (FocusChangeListener* const listener)
  33516. {
  33517. focusListeners.add (listener);
  33518. }
  33519. void Desktop::removeFocusChangeListener (FocusChangeListener* const listener)
  33520. {
  33521. focusListeners.remove (listener);
  33522. }
  33523. void Desktop::triggerFocusCallback()
  33524. {
  33525. triggerAsyncUpdate();
  33526. }
  33527. void Desktop::handleAsyncUpdate()
  33528. {
  33529. Component* currentFocus = Component::getCurrentlyFocusedComponent();
  33530. focusListeners.call (&FocusChangeListener::globalFocusChanged, currentFocus);
  33531. }
  33532. void Desktop::addGlobalMouseListener (MouseListener* const listener)
  33533. {
  33534. mouseListeners.add (listener);
  33535. resetTimer();
  33536. }
  33537. void Desktop::removeGlobalMouseListener (MouseListener* const listener)
  33538. {
  33539. mouseListeners.remove (listener);
  33540. resetTimer();
  33541. }
  33542. void Desktop::timerCallback()
  33543. {
  33544. if (lastFakeMouseMove != getMousePosition())
  33545. sendMouseMove();
  33546. }
  33547. void Desktop::sendMouseMove()
  33548. {
  33549. if (! mouseListeners.isEmpty())
  33550. {
  33551. startTimer (20);
  33552. lastFakeMouseMove = getMousePosition();
  33553. Component* const target = findComponentAt (lastFakeMouseMove);
  33554. if (target != 0)
  33555. {
  33556. Component::BailOutChecker checker (target);
  33557. const Point<int> pos (target->globalPositionToRelative (lastFakeMouseMove));
  33558. const Time now (Time::getCurrentTime());
  33559. const MouseEvent me (getMainMouseSource(), pos, ModifierKeys::getCurrentModifiers(),
  33560. target, now, pos, now, 0, false);
  33561. if (me.mods.isAnyMouseButtonDown())
  33562. mouseListeners.callChecked (checker, &MouseListener::mouseDrag, me);
  33563. else
  33564. mouseListeners.callChecked (checker, &MouseListener::mouseMove, me);
  33565. }
  33566. }
  33567. }
  33568. void Desktop::resetTimer()
  33569. {
  33570. if (mouseListeners.size() == 0)
  33571. stopTimer();
  33572. else
  33573. startTimer (100);
  33574. lastFakeMouseMove = getMousePosition();
  33575. }
  33576. extern void juce_setKioskComponent (Component* kioskModeComponent, bool enableOrDisable, bool allowMenusAndBars);
  33577. void Desktop::setKioskModeComponent (Component* componentToUse, const bool allowMenusAndBars)
  33578. {
  33579. if (kioskModeComponent != componentToUse)
  33580. {
  33581. // agh! Don't delete a component without first stopping it being the kiosk comp
  33582. jassert (kioskModeComponent == 0 || kioskModeComponent->isValidComponent());
  33583. // agh! Don't remove a component from the desktop if it's the kiosk comp!
  33584. jassert (kioskModeComponent == 0 || kioskModeComponent->isOnDesktop());
  33585. if (kioskModeComponent->isValidComponent())
  33586. {
  33587. juce_setKioskComponent (kioskModeComponent, false, allowMenusAndBars);
  33588. kioskModeComponent->setBounds (kioskComponentOriginalBounds);
  33589. }
  33590. kioskModeComponent = componentToUse;
  33591. if (kioskModeComponent != 0)
  33592. {
  33593. jassert (kioskModeComponent->isValidComponent());
  33594. // Only components that are already on the desktop can be put into kiosk mode!
  33595. jassert (kioskModeComponent->isOnDesktop());
  33596. kioskComponentOriginalBounds = kioskModeComponent->getBounds();
  33597. juce_setKioskComponent (kioskModeComponent, true, allowMenusAndBars);
  33598. }
  33599. }
  33600. }
  33601. END_JUCE_NAMESPACE
  33602. /*** End of inlined file: juce_Desktop.cpp ***/
  33603. /*** Start of inlined file: juce_ArrowButton.cpp ***/
  33604. BEGIN_JUCE_NAMESPACE
  33605. ArrowButton::ArrowButton (const String& name,
  33606. float arrowDirectionInRadians,
  33607. const Colour& arrowColour)
  33608. : Button (name),
  33609. colour (arrowColour)
  33610. {
  33611. path.lineTo (0.0f, 1.0f);
  33612. path.lineTo (1.0f, 0.5f);
  33613. path.closeSubPath();
  33614. path.applyTransform (AffineTransform::rotation (float_Pi * 2.0f * arrowDirectionInRadians,
  33615. 0.5f, 0.5f));
  33616. setComponentEffect (&shadow);
  33617. buttonStateChanged();
  33618. }
  33619. ArrowButton::~ArrowButton()
  33620. {
  33621. }
  33622. void ArrowButton::paintButton (Graphics& g,
  33623. bool /*isMouseOverButton*/,
  33624. bool /*isButtonDown*/)
  33625. {
  33626. g.setColour (colour);
  33627. g.fillPath (path, path.getTransformToScaleToFit ((float) offset,
  33628. (float) offset,
  33629. (float) (getWidth() - 3),
  33630. (float) (getHeight() - 3),
  33631. false));
  33632. }
  33633. void ArrowButton::buttonStateChanged()
  33634. {
  33635. offset = (isDown()) ? 1 : 0;
  33636. shadow.setShadowProperties ((isDown()) ? 1.2f : 3.0f,
  33637. 0.3f, -1, 0);
  33638. }
  33639. END_JUCE_NAMESPACE
  33640. /*** End of inlined file: juce_ArrowButton.cpp ***/
  33641. /*** Start of inlined file: juce_Button.cpp ***/
  33642. BEGIN_JUCE_NAMESPACE
  33643. class Button::RepeatTimer : public Timer
  33644. {
  33645. public:
  33646. RepeatTimer (Button& owner_) : owner (owner_) {}
  33647. void timerCallback() { owner.repeatTimerCallback(); }
  33648. juce_UseDebuggingNewOperator
  33649. private:
  33650. Button& owner;
  33651. RepeatTimer (const RepeatTimer&);
  33652. RepeatTimer& operator= (const RepeatTimer&);
  33653. };
  33654. Button::Button (const String& name)
  33655. : Component (name),
  33656. text (name),
  33657. buttonPressTime (0),
  33658. lastTimeCallbackTime (0),
  33659. commandManagerToUse (0),
  33660. autoRepeatDelay (-1),
  33661. autoRepeatSpeed (0),
  33662. autoRepeatMinimumDelay (-1),
  33663. radioGroupId (0),
  33664. commandID (0),
  33665. connectedEdgeFlags (0),
  33666. buttonState (buttonNormal),
  33667. lastToggleState (false),
  33668. clickTogglesState (false),
  33669. needsToRelease (false),
  33670. needsRepainting (false),
  33671. isKeyDown (false),
  33672. triggerOnMouseDown (false),
  33673. generateTooltip (false)
  33674. {
  33675. setWantsKeyboardFocus (true);
  33676. isOn.addListener (this);
  33677. }
  33678. Button::~Button()
  33679. {
  33680. isOn.removeListener (this);
  33681. if (commandManagerToUse != 0)
  33682. commandManagerToUse->removeListener (this);
  33683. repeatTimer = 0;
  33684. clearShortcuts();
  33685. }
  33686. void Button::setButtonText (const String& newText)
  33687. {
  33688. if (text != newText)
  33689. {
  33690. text = newText;
  33691. repaint();
  33692. }
  33693. }
  33694. void Button::setTooltip (const String& newTooltip)
  33695. {
  33696. SettableTooltipClient::setTooltip (newTooltip);
  33697. generateTooltip = false;
  33698. }
  33699. const String Button::getTooltip()
  33700. {
  33701. if (generateTooltip && commandManagerToUse != 0 && commandID != 0)
  33702. {
  33703. String tt (commandManagerToUse->getDescriptionOfCommand (commandID));
  33704. Array <KeyPress> keyPresses (commandManagerToUse->getKeyMappings()->getKeyPressesAssignedToCommand (commandID));
  33705. for (int i = 0; i < keyPresses.size(); ++i)
  33706. {
  33707. const String key (keyPresses.getReference(i).getTextDescription());
  33708. tt << " [";
  33709. if (key.length() == 1)
  33710. tt << TRANS("shortcut") << ": '" << key << "']";
  33711. else
  33712. tt << key << ']';
  33713. }
  33714. return tt;
  33715. }
  33716. return SettableTooltipClient::getTooltip();
  33717. }
  33718. void Button::setConnectedEdges (const int connectedEdgeFlags_)
  33719. {
  33720. if (connectedEdgeFlags != connectedEdgeFlags_)
  33721. {
  33722. connectedEdgeFlags = connectedEdgeFlags_;
  33723. repaint();
  33724. }
  33725. }
  33726. void Button::setToggleState (const bool shouldBeOn,
  33727. const bool sendChangeNotification)
  33728. {
  33729. if (shouldBeOn != lastToggleState)
  33730. {
  33731. isOn = shouldBeOn;
  33732. lastToggleState = shouldBeOn;
  33733. repaint();
  33734. if (sendChangeNotification)
  33735. {
  33736. Component::SafePointer<Component> deletionWatcher (this);
  33737. sendClickMessage (ModifierKeys());
  33738. if (deletionWatcher == 0)
  33739. return;
  33740. }
  33741. if (lastToggleState)
  33742. turnOffOtherButtonsInGroup (sendChangeNotification);
  33743. }
  33744. }
  33745. void Button::setClickingTogglesState (const bool shouldToggle) throw()
  33746. {
  33747. clickTogglesState = shouldToggle;
  33748. // if you've got clickTogglesState turned on, you shouldn't also connect the button
  33749. // up to be a command invoker. Instead, your command handler must flip the state of whatever
  33750. // it is that this button represents, and the button will update its state to reflect this
  33751. // in the applicationCommandListChanged() method.
  33752. jassert (commandManagerToUse == 0 || ! clickTogglesState);
  33753. }
  33754. bool Button::getClickingTogglesState() const throw()
  33755. {
  33756. return clickTogglesState;
  33757. }
  33758. void Button::valueChanged (Value& value)
  33759. {
  33760. if (value.refersToSameSourceAs (isOn))
  33761. setToggleState (isOn.getValue(), true);
  33762. }
  33763. void Button::setRadioGroupId (const int newGroupId)
  33764. {
  33765. if (radioGroupId != newGroupId)
  33766. {
  33767. radioGroupId = newGroupId;
  33768. if (lastToggleState)
  33769. turnOffOtherButtonsInGroup (true);
  33770. }
  33771. }
  33772. void Button::turnOffOtherButtonsInGroup (const bool sendChangeNotification)
  33773. {
  33774. Component* const p = getParentComponent();
  33775. if (p != 0 && radioGroupId != 0)
  33776. {
  33777. Component::SafePointer<Component> deletionWatcher (this);
  33778. for (int i = p->getNumChildComponents(); --i >= 0;)
  33779. {
  33780. Component* const c = p->getChildComponent (i);
  33781. if (c != this)
  33782. {
  33783. Button* const b = dynamic_cast <Button*> (c);
  33784. if (b != 0 && b->getRadioGroupId() == radioGroupId)
  33785. {
  33786. b->setToggleState (false, sendChangeNotification);
  33787. if (deletionWatcher == 0)
  33788. return;
  33789. }
  33790. }
  33791. }
  33792. }
  33793. }
  33794. void Button::enablementChanged()
  33795. {
  33796. updateState (0);
  33797. repaint();
  33798. }
  33799. Button::ButtonState Button::updateState (const MouseEvent* const e)
  33800. {
  33801. ButtonState state = buttonNormal;
  33802. if (isEnabled() && isVisible() && ! isCurrentlyBlockedByAnotherModalComponent())
  33803. {
  33804. Point<int> mousePos;
  33805. if (e == 0)
  33806. mousePos = getMouseXYRelative();
  33807. else
  33808. mousePos = e->getEventRelativeTo (this).getPosition();
  33809. const bool over = reallyContains (mousePos.getX(), mousePos.getY(), true);
  33810. const bool down = isMouseButtonDown();
  33811. if ((down && (over || (triggerOnMouseDown && buttonState == buttonDown))) || isKeyDown)
  33812. state = buttonDown;
  33813. else if (over)
  33814. state = buttonOver;
  33815. }
  33816. setState (state);
  33817. return state;
  33818. }
  33819. void Button::setState (const ButtonState newState)
  33820. {
  33821. if (buttonState != newState)
  33822. {
  33823. buttonState = newState;
  33824. repaint();
  33825. if (buttonState == buttonDown)
  33826. {
  33827. buttonPressTime = Time::getApproximateMillisecondCounter();
  33828. lastTimeCallbackTime = buttonPressTime;
  33829. }
  33830. sendStateMessage();
  33831. }
  33832. }
  33833. bool Button::isDown() const throw()
  33834. {
  33835. return buttonState == buttonDown;
  33836. }
  33837. bool Button::isOver() const throw()
  33838. {
  33839. return buttonState != buttonNormal;
  33840. }
  33841. void Button::buttonStateChanged()
  33842. {
  33843. }
  33844. uint32 Button::getMillisecondsSinceButtonDown() const throw()
  33845. {
  33846. const uint32 now = Time::getApproximateMillisecondCounter();
  33847. return now > buttonPressTime ? now - buttonPressTime : 0;
  33848. }
  33849. void Button::setTriggeredOnMouseDown (const bool isTriggeredOnMouseDown) throw()
  33850. {
  33851. triggerOnMouseDown = isTriggeredOnMouseDown;
  33852. }
  33853. void Button::clicked()
  33854. {
  33855. }
  33856. void Button::clicked (const ModifierKeys& /*modifiers*/)
  33857. {
  33858. clicked();
  33859. }
  33860. static const int clickMessageId = 0x2f3f4f99;
  33861. void Button::triggerClick()
  33862. {
  33863. postCommandMessage (clickMessageId);
  33864. }
  33865. void Button::internalClickCallback (const ModifierKeys& modifiers)
  33866. {
  33867. if (clickTogglesState)
  33868. setToggleState ((radioGroupId != 0) || ! lastToggleState, false);
  33869. sendClickMessage (modifiers);
  33870. }
  33871. void Button::flashButtonState()
  33872. {
  33873. if (isEnabled())
  33874. {
  33875. needsToRelease = true;
  33876. setState (buttonDown);
  33877. getRepeatTimer().startTimer (100);
  33878. }
  33879. }
  33880. void Button::handleCommandMessage (int commandId)
  33881. {
  33882. if (commandId == clickMessageId)
  33883. {
  33884. if (isEnabled())
  33885. {
  33886. flashButtonState();
  33887. internalClickCallback (ModifierKeys::getCurrentModifiers());
  33888. }
  33889. }
  33890. else
  33891. {
  33892. Component::handleCommandMessage (commandId);
  33893. }
  33894. }
  33895. void Button::addButtonListener (ButtonListener* const newListener)
  33896. {
  33897. buttonListeners.add (newListener);
  33898. }
  33899. void Button::removeButtonListener (ButtonListener* const listener)
  33900. {
  33901. buttonListeners.remove (listener);
  33902. }
  33903. void Button::sendClickMessage (const ModifierKeys& modifiers)
  33904. {
  33905. Component::BailOutChecker checker (this);
  33906. if (commandManagerToUse != 0 && commandID != 0)
  33907. {
  33908. ApplicationCommandTarget::InvocationInfo info (commandID);
  33909. info.invocationMethod = ApplicationCommandTarget::InvocationInfo::fromButton;
  33910. info.originatingComponent = this;
  33911. commandManagerToUse->invoke (info, true);
  33912. }
  33913. clicked (modifiers);
  33914. if (! checker.shouldBailOut())
  33915. buttonListeners.callChecked (checker, &ButtonListener::buttonClicked, this);
  33916. }
  33917. void Button::sendStateMessage()
  33918. {
  33919. Component::BailOutChecker checker (this);
  33920. buttonStateChanged();
  33921. if (! checker.shouldBailOut())
  33922. buttonListeners.callChecked (checker, &ButtonListener::buttonStateChanged, this);
  33923. }
  33924. void Button::paint (Graphics& g)
  33925. {
  33926. if (needsToRelease && isEnabled())
  33927. {
  33928. needsToRelease = false;
  33929. needsRepainting = true;
  33930. }
  33931. paintButton (g, isOver(), isDown());
  33932. }
  33933. void Button::mouseEnter (const MouseEvent& e)
  33934. {
  33935. updateState (&e);
  33936. }
  33937. void Button::mouseExit (const MouseEvent& e)
  33938. {
  33939. updateState (&e);
  33940. }
  33941. void Button::mouseDown (const MouseEvent& e)
  33942. {
  33943. updateState (&e);
  33944. if (isDown())
  33945. {
  33946. if (autoRepeatDelay >= 0)
  33947. getRepeatTimer().startTimer (autoRepeatDelay);
  33948. if (triggerOnMouseDown)
  33949. internalClickCallback (e.mods);
  33950. }
  33951. }
  33952. void Button::mouseUp (const MouseEvent& e)
  33953. {
  33954. const bool wasDown = isDown();
  33955. updateState (&e);
  33956. if (wasDown && isOver() && ! triggerOnMouseDown)
  33957. internalClickCallback (e.mods);
  33958. }
  33959. void Button::mouseDrag (const MouseEvent& e)
  33960. {
  33961. const ButtonState oldState = buttonState;
  33962. updateState (&e);
  33963. if (autoRepeatDelay >= 0 && buttonState != oldState && isDown())
  33964. getRepeatTimer().startTimer (autoRepeatSpeed);
  33965. }
  33966. void Button::focusGained (FocusChangeType)
  33967. {
  33968. updateState (0);
  33969. repaint();
  33970. }
  33971. void Button::focusLost (FocusChangeType)
  33972. {
  33973. updateState (0);
  33974. repaint();
  33975. }
  33976. void Button::setVisible (bool shouldBeVisible)
  33977. {
  33978. if (shouldBeVisible != isVisible())
  33979. {
  33980. Component::setVisible (shouldBeVisible);
  33981. if (! shouldBeVisible)
  33982. needsToRelease = false;
  33983. updateState (0);
  33984. }
  33985. else
  33986. {
  33987. Component::setVisible (shouldBeVisible);
  33988. }
  33989. }
  33990. void Button::parentHierarchyChanged()
  33991. {
  33992. Component* const newKeySource = (shortcuts.size() == 0) ? 0 : getTopLevelComponent();
  33993. if (newKeySource != keySource.getComponent())
  33994. {
  33995. if (keySource != 0)
  33996. keySource->removeKeyListener (this);
  33997. keySource = newKeySource;
  33998. if (keySource != 0)
  33999. keySource->addKeyListener (this);
  34000. }
  34001. }
  34002. void Button::setCommandToTrigger (ApplicationCommandManager* const commandManagerToUse_,
  34003. const int commandID_,
  34004. const bool generateTooltip_)
  34005. {
  34006. commandID = commandID_;
  34007. generateTooltip = generateTooltip_;
  34008. if (commandManagerToUse != commandManagerToUse_)
  34009. {
  34010. if (commandManagerToUse != 0)
  34011. commandManagerToUse->removeListener (this);
  34012. commandManagerToUse = commandManagerToUse_;
  34013. if (commandManagerToUse != 0)
  34014. commandManagerToUse->addListener (this);
  34015. // if you've got clickTogglesState turned on, you shouldn't also connect the button
  34016. // up to be a command invoker. Instead, your command handler must flip the state of whatever
  34017. // it is that this button represents, and the button will update its state to reflect this
  34018. // in the applicationCommandListChanged() method.
  34019. jassert (commandManagerToUse == 0 || ! clickTogglesState);
  34020. }
  34021. if (commandManagerToUse != 0)
  34022. applicationCommandListChanged();
  34023. else
  34024. setEnabled (true);
  34025. }
  34026. void Button::applicationCommandInvoked (const ApplicationCommandTarget::InvocationInfo& info)
  34027. {
  34028. if (info.commandID == commandID
  34029. && (info.commandFlags & ApplicationCommandInfo::dontTriggerVisualFeedback) == 0)
  34030. {
  34031. flashButtonState();
  34032. }
  34033. }
  34034. void Button::applicationCommandListChanged()
  34035. {
  34036. if (commandManagerToUse != 0)
  34037. {
  34038. ApplicationCommandInfo info (0);
  34039. ApplicationCommandTarget* const target = commandManagerToUse->getTargetForCommand (commandID, info);
  34040. setEnabled (target != 0 && (info.flags & ApplicationCommandInfo::isDisabled) == 0);
  34041. if (target != 0)
  34042. setToggleState ((info.flags & ApplicationCommandInfo::isTicked) != 0, false);
  34043. }
  34044. }
  34045. void Button::addShortcut (const KeyPress& key)
  34046. {
  34047. if (key.isValid())
  34048. {
  34049. jassert (! isRegisteredForShortcut (key)); // already registered!
  34050. shortcuts.add (key);
  34051. parentHierarchyChanged();
  34052. }
  34053. }
  34054. void Button::clearShortcuts()
  34055. {
  34056. shortcuts.clear();
  34057. parentHierarchyChanged();
  34058. }
  34059. bool Button::isShortcutPressed() const
  34060. {
  34061. if (! isCurrentlyBlockedByAnotherModalComponent())
  34062. {
  34063. for (int i = shortcuts.size(); --i >= 0;)
  34064. if (shortcuts.getReference(i).isCurrentlyDown())
  34065. return true;
  34066. }
  34067. return false;
  34068. }
  34069. bool Button::isRegisteredForShortcut (const KeyPress& key) const
  34070. {
  34071. for (int i = shortcuts.size(); --i >= 0;)
  34072. if (key == shortcuts.getReference(i))
  34073. return true;
  34074. return false;
  34075. }
  34076. bool Button::keyStateChanged (const bool, Component*)
  34077. {
  34078. if (! isEnabled())
  34079. return false;
  34080. const bool wasDown = isKeyDown;
  34081. isKeyDown = isShortcutPressed();
  34082. if (autoRepeatDelay >= 0 && (isKeyDown && ! wasDown))
  34083. getRepeatTimer().startTimer (autoRepeatDelay);
  34084. updateState (0);
  34085. if (isEnabled() && wasDown && ! isKeyDown)
  34086. {
  34087. internalClickCallback (ModifierKeys::getCurrentModifiers());
  34088. // (return immediately - this button may now have been deleted)
  34089. return true;
  34090. }
  34091. return wasDown || isKeyDown;
  34092. }
  34093. bool Button::keyPressed (const KeyPress&, Component*)
  34094. {
  34095. // returning true will avoid forwarding events for keys that we're using as shortcuts
  34096. return isShortcutPressed();
  34097. }
  34098. bool Button::keyPressed (const KeyPress& key)
  34099. {
  34100. if (isEnabled() && key.isKeyCode (KeyPress::returnKey))
  34101. {
  34102. triggerClick();
  34103. return true;
  34104. }
  34105. return false;
  34106. }
  34107. void Button::setRepeatSpeed (const int initialDelayMillisecs,
  34108. const int repeatMillisecs,
  34109. const int minimumDelayInMillisecs) throw()
  34110. {
  34111. autoRepeatDelay = initialDelayMillisecs;
  34112. autoRepeatSpeed = repeatMillisecs;
  34113. autoRepeatMinimumDelay = jmin (autoRepeatSpeed, minimumDelayInMillisecs);
  34114. }
  34115. void Button::repeatTimerCallback()
  34116. {
  34117. if (needsRepainting)
  34118. {
  34119. getRepeatTimer().stopTimer();
  34120. updateState (0);
  34121. needsRepainting = false;
  34122. }
  34123. else if (autoRepeatSpeed > 0 && (isKeyDown || (updateState (0) == buttonDown)))
  34124. {
  34125. int repeatSpeed = autoRepeatSpeed;
  34126. if (autoRepeatMinimumDelay >= 0)
  34127. {
  34128. double timeHeldDown = jmin (1.0, getMillisecondsSinceButtonDown() / 4000.0);
  34129. timeHeldDown *= timeHeldDown;
  34130. repeatSpeed = repeatSpeed + (int) (timeHeldDown * (autoRepeatMinimumDelay - repeatSpeed));
  34131. }
  34132. repeatSpeed = jmax (1, repeatSpeed);
  34133. getRepeatTimer().startTimer (repeatSpeed);
  34134. const uint32 now = Time::getApproximateMillisecondCounter();
  34135. const int numTimesToCallback = (now > lastTimeCallbackTime) ? jmax (1, (int) (now - lastTimeCallbackTime) / repeatSpeed) : 1;
  34136. lastTimeCallbackTime = now;
  34137. Component::SafePointer<Component> deletionWatcher (this);
  34138. for (int i = numTimesToCallback; --i >= 0;)
  34139. {
  34140. internalClickCallback (ModifierKeys::getCurrentModifiers());
  34141. if (deletionWatcher == 0 || ! isDown())
  34142. return;
  34143. }
  34144. }
  34145. else if (! needsToRelease)
  34146. {
  34147. getRepeatTimer().stopTimer();
  34148. }
  34149. }
  34150. Button::RepeatTimer& Button::getRepeatTimer()
  34151. {
  34152. if (repeatTimer == 0)
  34153. repeatTimer = new RepeatTimer (*this);
  34154. return *repeatTimer;
  34155. }
  34156. END_JUCE_NAMESPACE
  34157. /*** End of inlined file: juce_Button.cpp ***/
  34158. /*** Start of inlined file: juce_DrawableButton.cpp ***/
  34159. BEGIN_JUCE_NAMESPACE
  34160. DrawableButton::DrawableButton (const String& name,
  34161. const DrawableButton::ButtonStyle buttonStyle)
  34162. : Button (name),
  34163. style (buttonStyle),
  34164. edgeIndent (3)
  34165. {
  34166. if (buttonStyle == ImageOnButtonBackground)
  34167. {
  34168. backgroundOff = Colour (0xffbbbbff);
  34169. backgroundOn = Colour (0xff3333ff);
  34170. }
  34171. else
  34172. {
  34173. backgroundOff = Colours::transparentBlack;
  34174. backgroundOn = Colour (0xaabbbbff);
  34175. }
  34176. }
  34177. DrawableButton::~DrawableButton()
  34178. {
  34179. deleteImages();
  34180. }
  34181. void DrawableButton::deleteImages()
  34182. {
  34183. }
  34184. void DrawableButton::setImages (const Drawable* normal,
  34185. const Drawable* over,
  34186. const Drawable* down,
  34187. const Drawable* disabled,
  34188. const Drawable* normalOn,
  34189. const Drawable* overOn,
  34190. const Drawable* downOn,
  34191. const Drawable* disabledOn)
  34192. {
  34193. deleteImages();
  34194. jassert (normal != 0); // you really need to give it at least a normal image..
  34195. if (normal != 0)
  34196. normalImage = normal->createCopy();
  34197. if (over != 0)
  34198. overImage = over->createCopy();
  34199. if (down != 0)
  34200. downImage = down->createCopy();
  34201. if (disabled != 0)
  34202. disabledImage = disabled->createCopy();
  34203. if (normalOn != 0)
  34204. normalImageOn = normalOn->createCopy();
  34205. if (overOn != 0)
  34206. overImageOn = overOn->createCopy();
  34207. if (downOn != 0)
  34208. downImageOn = downOn->createCopy();
  34209. if (disabledOn != 0)
  34210. disabledImageOn = disabledOn->createCopy();
  34211. repaint();
  34212. }
  34213. void DrawableButton::setButtonStyle (const DrawableButton::ButtonStyle newStyle)
  34214. {
  34215. if (style != newStyle)
  34216. {
  34217. style = newStyle;
  34218. repaint();
  34219. }
  34220. }
  34221. void DrawableButton::setBackgroundColours (const Colour& toggledOffColour,
  34222. const Colour& toggledOnColour)
  34223. {
  34224. if (backgroundOff != toggledOffColour
  34225. || backgroundOn != toggledOnColour)
  34226. {
  34227. backgroundOff = toggledOffColour;
  34228. backgroundOn = toggledOnColour;
  34229. repaint();
  34230. }
  34231. }
  34232. const Colour& DrawableButton::getBackgroundColour() const throw()
  34233. {
  34234. return getToggleState() ? backgroundOn
  34235. : backgroundOff;
  34236. }
  34237. void DrawableButton::setEdgeIndent (const int numPixelsIndent)
  34238. {
  34239. edgeIndent = numPixelsIndent;
  34240. repaint();
  34241. }
  34242. void DrawableButton::paintButton (Graphics& g,
  34243. bool isMouseOverButton,
  34244. bool isButtonDown)
  34245. {
  34246. Rectangle<int> imageSpace;
  34247. if (style == ImageOnButtonBackground)
  34248. {
  34249. const int insetX = getWidth() / 4;
  34250. const int insetY = getHeight() / 4;
  34251. imageSpace.setBounds (insetX, insetY, getWidth() - insetX * 2, getHeight() - insetY * 2);
  34252. getLookAndFeel().drawButtonBackground (g, *this,
  34253. getBackgroundColour(),
  34254. isMouseOverButton,
  34255. isButtonDown);
  34256. }
  34257. else
  34258. {
  34259. g.fillAll (getBackgroundColour());
  34260. const int textH = (style == ImageAboveTextLabel)
  34261. ? jmin (16, proportionOfHeight (0.25f))
  34262. : 0;
  34263. const int indentX = jmin (edgeIndent, proportionOfWidth (0.3f));
  34264. const int indentY = jmin (edgeIndent, proportionOfHeight (0.3f));
  34265. imageSpace.setBounds (indentX, indentY,
  34266. getWidth() - indentX * 2,
  34267. getHeight() - indentY * 2 - textH);
  34268. if (textH > 0)
  34269. {
  34270. g.setFont ((float) textH);
  34271. g.setColour (Colours::black.withAlpha (isEnabled() ? 1.0f : 0.4f));
  34272. g.drawFittedText (getButtonText(),
  34273. 2, getHeight() - textH - 1,
  34274. getWidth() - 4, textH,
  34275. Justification::centred, 1);
  34276. }
  34277. }
  34278. g.setImageResamplingQuality (Graphics::mediumResamplingQuality);
  34279. g.setOpacity (1.0f);
  34280. const Drawable* imageToDraw = 0;
  34281. if (isEnabled())
  34282. {
  34283. imageToDraw = getCurrentImage();
  34284. }
  34285. else
  34286. {
  34287. imageToDraw = getToggleState() ? disabledImageOn
  34288. : disabledImage;
  34289. if (imageToDraw == 0)
  34290. {
  34291. g.setOpacity (0.4f);
  34292. imageToDraw = getNormalImage();
  34293. }
  34294. }
  34295. if (imageToDraw != 0)
  34296. {
  34297. if (style == ImageRaw)
  34298. {
  34299. imageToDraw->draw (g, 1.0f);
  34300. }
  34301. else
  34302. {
  34303. imageToDraw->drawWithin (g,
  34304. imageSpace.getX(),
  34305. imageSpace.getY(),
  34306. imageSpace.getWidth(),
  34307. imageSpace.getHeight(),
  34308. RectanglePlacement::centred,
  34309. 1.0f);
  34310. }
  34311. }
  34312. }
  34313. const Drawable* DrawableButton::getCurrentImage() const throw()
  34314. {
  34315. if (isDown())
  34316. return getDownImage();
  34317. if (isOver())
  34318. return getOverImage();
  34319. return getNormalImage();
  34320. }
  34321. const Drawable* DrawableButton::getNormalImage() const throw()
  34322. {
  34323. return (getToggleState() && normalImageOn != 0) ? normalImageOn
  34324. : normalImage;
  34325. }
  34326. const Drawable* DrawableButton::getOverImage() const throw()
  34327. {
  34328. const Drawable* d = normalImage;
  34329. if (getToggleState())
  34330. {
  34331. if (overImageOn != 0)
  34332. d = overImageOn;
  34333. else if (normalImageOn != 0)
  34334. d = normalImageOn;
  34335. else if (overImage != 0)
  34336. d = overImage;
  34337. }
  34338. else
  34339. {
  34340. if (overImage != 0)
  34341. d = overImage;
  34342. }
  34343. return d;
  34344. }
  34345. const Drawable* DrawableButton::getDownImage() const throw()
  34346. {
  34347. const Drawable* d = normalImage;
  34348. if (getToggleState())
  34349. {
  34350. if (downImageOn != 0)
  34351. d = downImageOn;
  34352. else if (overImageOn != 0)
  34353. d = overImageOn;
  34354. else if (normalImageOn != 0)
  34355. d = normalImageOn;
  34356. else if (downImage != 0)
  34357. d = downImage;
  34358. else
  34359. d = getOverImage();
  34360. }
  34361. else
  34362. {
  34363. if (downImage != 0)
  34364. d = downImage;
  34365. else
  34366. d = getOverImage();
  34367. }
  34368. return d;
  34369. }
  34370. END_JUCE_NAMESPACE
  34371. /*** End of inlined file: juce_DrawableButton.cpp ***/
  34372. /*** Start of inlined file: juce_HyperlinkButton.cpp ***/
  34373. BEGIN_JUCE_NAMESPACE
  34374. HyperlinkButton::HyperlinkButton (const String& linkText,
  34375. const URL& linkURL)
  34376. : Button (linkText),
  34377. url (linkURL),
  34378. font (14.0f, Font::underlined),
  34379. resizeFont (true),
  34380. justification (Justification::centred)
  34381. {
  34382. setMouseCursor (MouseCursor::PointingHandCursor);
  34383. setTooltip (linkURL.toString (false));
  34384. }
  34385. HyperlinkButton::~HyperlinkButton()
  34386. {
  34387. }
  34388. void HyperlinkButton::setFont (const Font& newFont,
  34389. const bool resizeToMatchComponentHeight,
  34390. const Justification& justificationType)
  34391. {
  34392. font = newFont;
  34393. resizeFont = resizeToMatchComponentHeight;
  34394. justification = justificationType;
  34395. repaint();
  34396. }
  34397. void HyperlinkButton::setURL (const URL& newURL) throw()
  34398. {
  34399. url = newURL;
  34400. setTooltip (newURL.toString (false));
  34401. }
  34402. const Font HyperlinkButton::getFontToUse() const
  34403. {
  34404. Font f (font);
  34405. if (resizeFont)
  34406. f.setHeight (getHeight() * 0.7f);
  34407. return f;
  34408. }
  34409. void HyperlinkButton::changeWidthToFitText()
  34410. {
  34411. setSize (getFontToUse().getStringWidth (getName()) + 6, getHeight());
  34412. }
  34413. void HyperlinkButton::colourChanged()
  34414. {
  34415. repaint();
  34416. }
  34417. void HyperlinkButton::clicked()
  34418. {
  34419. if (url.isWellFormed())
  34420. url.launchInDefaultBrowser();
  34421. }
  34422. void HyperlinkButton::paintButton (Graphics& g,
  34423. bool isMouseOverButton,
  34424. bool isButtonDown)
  34425. {
  34426. const Colour textColour (findColour (textColourId));
  34427. if (isEnabled())
  34428. g.setColour ((isMouseOverButton) ? textColour.darker ((isButtonDown) ? 1.3f : 0.4f)
  34429. : textColour);
  34430. else
  34431. g.setColour (textColour.withMultipliedAlpha (0.4f));
  34432. g.setFont (getFontToUse());
  34433. g.drawText (getButtonText(),
  34434. 2, 0, getWidth() - 2, getHeight(),
  34435. justification.getOnlyHorizontalFlags() | Justification::verticallyCentred,
  34436. true);
  34437. }
  34438. END_JUCE_NAMESPACE
  34439. /*** End of inlined file: juce_HyperlinkButton.cpp ***/
  34440. /*** Start of inlined file: juce_ImageButton.cpp ***/
  34441. BEGIN_JUCE_NAMESPACE
  34442. ImageButton::ImageButton (const String& text_)
  34443. : Button (text_),
  34444. scaleImageToFit (true),
  34445. preserveProportions (true),
  34446. alphaThreshold (0),
  34447. imageX (0),
  34448. imageY (0),
  34449. imageW (0),
  34450. imageH (0),
  34451. normalImage (0),
  34452. overImage (0),
  34453. downImage (0)
  34454. {
  34455. }
  34456. ImageButton::~ImageButton()
  34457. {
  34458. deleteImages();
  34459. }
  34460. void ImageButton::deleteImages()
  34461. {
  34462. ImageCache::releaseOrDelete (normalImage);
  34463. ImageCache::releaseOrDelete (overImage);
  34464. ImageCache::releaseOrDelete (downImage);
  34465. }
  34466. void ImageButton::setImages (const bool resizeButtonNowToFitThisImage,
  34467. const bool rescaleImagesWhenButtonSizeChanges,
  34468. const bool preserveImageProportions,
  34469. Image* const normalImage_,
  34470. const float imageOpacityWhenNormal,
  34471. const Colour& overlayColourWhenNormal,
  34472. Image* const overImage_,
  34473. const float imageOpacityWhenOver,
  34474. const Colour& overlayColourWhenOver,
  34475. Image* const downImage_,
  34476. const float imageOpacityWhenDown,
  34477. const Colour& overlayColourWhenDown,
  34478. const float hitTestAlphaThreshold)
  34479. {
  34480. deleteImages();
  34481. normalImage = normalImage_;
  34482. overImage = overImage_;
  34483. downImage = downImage_;
  34484. if (resizeButtonNowToFitThisImage && normalImage != 0)
  34485. {
  34486. imageW = normalImage->getWidth();
  34487. imageH = normalImage->getHeight();
  34488. setSize (imageW, imageH);
  34489. }
  34490. scaleImageToFit = rescaleImagesWhenButtonSizeChanges;
  34491. preserveProportions = preserveImageProportions;
  34492. normalOpacity = imageOpacityWhenNormal;
  34493. normalOverlay = overlayColourWhenNormal;
  34494. overOpacity = imageOpacityWhenOver;
  34495. overOverlay = overlayColourWhenOver;
  34496. downOpacity = imageOpacityWhenDown;
  34497. downOverlay = overlayColourWhenDown;
  34498. alphaThreshold = (unsigned char) jlimit (0, 0xff, roundToInt (255.0f * hitTestAlphaThreshold));
  34499. repaint();
  34500. }
  34501. Image* ImageButton::getCurrentImage() const
  34502. {
  34503. if (isDown() || getToggleState())
  34504. return getDownImage();
  34505. if (isOver())
  34506. return getOverImage();
  34507. return getNormalImage();
  34508. }
  34509. Image* ImageButton::getNormalImage() const throw()
  34510. {
  34511. return normalImage;
  34512. }
  34513. Image* ImageButton::getOverImage() const throw()
  34514. {
  34515. return (overImage != 0) ? overImage
  34516. : normalImage;
  34517. }
  34518. Image* ImageButton::getDownImage() const throw()
  34519. {
  34520. return (downImage != 0) ? downImage
  34521. : getOverImage();
  34522. }
  34523. void ImageButton::paintButton (Graphics& g,
  34524. bool isMouseOverButton,
  34525. bool isButtonDown)
  34526. {
  34527. if (! isEnabled())
  34528. {
  34529. isMouseOverButton = false;
  34530. isButtonDown = false;
  34531. }
  34532. Image* const im = getCurrentImage();
  34533. if (im != 0)
  34534. {
  34535. const int iw = im->getWidth();
  34536. const int ih = im->getHeight();
  34537. imageW = getWidth();
  34538. imageH = getHeight();
  34539. imageX = (imageW - iw) >> 1;
  34540. imageY = (imageH - ih) >> 1;
  34541. if (scaleImageToFit)
  34542. {
  34543. if (preserveProportions)
  34544. {
  34545. int newW, newH;
  34546. const float imRatio = ih / (float)iw;
  34547. const float destRatio = imageH / (float)imageW;
  34548. if (imRatio > destRatio)
  34549. {
  34550. newW = roundToInt (imageH / imRatio);
  34551. newH = imageH;
  34552. }
  34553. else
  34554. {
  34555. newW = imageW;
  34556. newH = roundToInt (imageW * imRatio);
  34557. }
  34558. imageX = (imageW - newW) / 2;
  34559. imageY = (imageH - newH) / 2;
  34560. imageW = newW;
  34561. imageH = newH;
  34562. }
  34563. else
  34564. {
  34565. imageX = 0;
  34566. imageY = 0;
  34567. }
  34568. }
  34569. if (! scaleImageToFit)
  34570. {
  34571. imageW = iw;
  34572. imageH = ih;
  34573. }
  34574. getLookAndFeel().drawImageButton (g, im, imageX, imageY, imageW, imageH,
  34575. isButtonDown ? downOverlay
  34576. : (isMouseOverButton ? overOverlay
  34577. : normalOverlay),
  34578. isButtonDown ? downOpacity
  34579. : (isMouseOverButton ? overOpacity
  34580. : normalOpacity),
  34581. *this);
  34582. }
  34583. }
  34584. bool ImageButton::hitTest (int x, int y)
  34585. {
  34586. if (alphaThreshold == 0)
  34587. return true;
  34588. Image* const im = getCurrentImage();
  34589. return im == 0
  34590. || (imageW > 0 && imageH > 0
  34591. && alphaThreshold < im->getPixelAt (((x - imageX) * im->getWidth()) / imageW,
  34592. ((y - imageY) * im->getHeight()) / imageH).getAlpha());
  34593. }
  34594. END_JUCE_NAMESPACE
  34595. /*** End of inlined file: juce_ImageButton.cpp ***/
  34596. /*** Start of inlined file: juce_ShapeButton.cpp ***/
  34597. BEGIN_JUCE_NAMESPACE
  34598. ShapeButton::ShapeButton (const String& text_,
  34599. const Colour& normalColour_,
  34600. const Colour& overColour_,
  34601. const Colour& downColour_)
  34602. : Button (text_),
  34603. normalColour (normalColour_),
  34604. overColour (overColour_),
  34605. downColour (downColour_),
  34606. maintainShapeProportions (false),
  34607. outlineWidth (0.0f)
  34608. {
  34609. }
  34610. ShapeButton::~ShapeButton()
  34611. {
  34612. }
  34613. void ShapeButton::setColours (const Colour& newNormalColour,
  34614. const Colour& newOverColour,
  34615. const Colour& newDownColour)
  34616. {
  34617. normalColour = newNormalColour;
  34618. overColour = newOverColour;
  34619. downColour = newDownColour;
  34620. }
  34621. void ShapeButton::setOutline (const Colour& newOutlineColour,
  34622. const float newOutlineWidth)
  34623. {
  34624. outlineColour = newOutlineColour;
  34625. outlineWidth = newOutlineWidth;
  34626. }
  34627. void ShapeButton::setShape (const Path& newShape,
  34628. const bool resizeNowToFitThisShape,
  34629. const bool maintainShapeProportions_,
  34630. const bool hasShadow)
  34631. {
  34632. shape = newShape;
  34633. maintainShapeProportions = maintainShapeProportions_;
  34634. shadow.setShadowProperties (3.0f, 0.5f, 0, 0);
  34635. setComponentEffect ((hasShadow) ? &shadow : 0);
  34636. if (resizeNowToFitThisShape)
  34637. {
  34638. Rectangle<float> bounds (shape.getBounds());
  34639. if (hasShadow)
  34640. bounds.expand (4.0f, 4.0f);
  34641. shape.applyTransform (AffineTransform::translation (-bounds.getX(), -bounds.getY()));
  34642. setSize (1 + (int) (bounds.getWidth() + outlineWidth),
  34643. 1 + (int) (bounds.getHeight() + outlineWidth));
  34644. }
  34645. }
  34646. void ShapeButton::paintButton (Graphics& g, bool isMouseOverButton, bool isButtonDown)
  34647. {
  34648. if (! isEnabled())
  34649. {
  34650. isMouseOverButton = false;
  34651. isButtonDown = false;
  34652. }
  34653. g.setColour ((isButtonDown) ? downColour
  34654. : (isMouseOverButton) ? overColour
  34655. : normalColour);
  34656. int w = getWidth();
  34657. int h = getHeight();
  34658. if (getComponentEffect() != 0)
  34659. {
  34660. w -= 4;
  34661. h -= 4;
  34662. }
  34663. const float offset = (outlineWidth * 0.5f) + (isButtonDown ? 1.5f : 0.0f);
  34664. const AffineTransform trans (shape.getTransformToScaleToFit (offset, offset,
  34665. w - offset - outlineWidth,
  34666. h - offset - outlineWidth,
  34667. maintainShapeProportions));
  34668. g.fillPath (shape, trans);
  34669. if (outlineWidth > 0.0f)
  34670. {
  34671. g.setColour (outlineColour);
  34672. g.strokePath (shape, PathStrokeType (outlineWidth), trans);
  34673. }
  34674. }
  34675. END_JUCE_NAMESPACE
  34676. /*** End of inlined file: juce_ShapeButton.cpp ***/
  34677. /*** Start of inlined file: juce_TextButton.cpp ***/
  34678. BEGIN_JUCE_NAMESPACE
  34679. TextButton::TextButton (const String& name,
  34680. const String& toolTip)
  34681. : Button (name)
  34682. {
  34683. setTooltip (toolTip);
  34684. }
  34685. TextButton::~TextButton()
  34686. {
  34687. }
  34688. void TextButton::paintButton (Graphics& g,
  34689. bool isMouseOverButton,
  34690. bool isButtonDown)
  34691. {
  34692. getLookAndFeel().drawButtonBackground (g, *this,
  34693. findColour (getToggleState() ? buttonOnColourId
  34694. : buttonColourId),
  34695. isMouseOverButton,
  34696. isButtonDown);
  34697. getLookAndFeel().drawButtonText (g, *this,
  34698. isMouseOverButton,
  34699. isButtonDown);
  34700. }
  34701. void TextButton::colourChanged()
  34702. {
  34703. repaint();
  34704. }
  34705. const Font TextButton::getFont()
  34706. {
  34707. return Font (jmin (15.0f, getHeight() * 0.6f));
  34708. }
  34709. void TextButton::changeWidthToFitText (const int newHeight)
  34710. {
  34711. if (newHeight >= 0)
  34712. setSize (jmax (1, getWidth()), newHeight);
  34713. setSize (getFont().getStringWidth (getButtonText()) + getHeight(),
  34714. getHeight());
  34715. }
  34716. END_JUCE_NAMESPACE
  34717. /*** End of inlined file: juce_TextButton.cpp ***/
  34718. /*** Start of inlined file: juce_ToggleButton.cpp ***/
  34719. BEGIN_JUCE_NAMESPACE
  34720. ToggleButton::ToggleButton (const String& buttonText)
  34721. : Button (buttonText)
  34722. {
  34723. setClickingTogglesState (true);
  34724. }
  34725. ToggleButton::~ToggleButton()
  34726. {
  34727. }
  34728. void ToggleButton::paintButton (Graphics& g,
  34729. bool isMouseOverButton,
  34730. bool isButtonDown)
  34731. {
  34732. getLookAndFeel().drawToggleButton (g, *this,
  34733. isMouseOverButton,
  34734. isButtonDown);
  34735. }
  34736. void ToggleButton::changeWidthToFitText()
  34737. {
  34738. getLookAndFeel().changeToggleButtonWidthToFitText (*this);
  34739. }
  34740. void ToggleButton::colourChanged()
  34741. {
  34742. repaint();
  34743. }
  34744. END_JUCE_NAMESPACE
  34745. /*** End of inlined file: juce_ToggleButton.cpp ***/
  34746. /*** Start of inlined file: juce_ToolbarButton.cpp ***/
  34747. BEGIN_JUCE_NAMESPACE
  34748. ToolbarButton::ToolbarButton (const int itemId_,
  34749. const String& buttonText,
  34750. Drawable* const normalImage_,
  34751. Drawable* const toggledOnImage_)
  34752. : ToolbarItemComponent (itemId_, buttonText, true),
  34753. normalImage (normalImage_),
  34754. toggledOnImage (toggledOnImage_)
  34755. {
  34756. }
  34757. ToolbarButton::~ToolbarButton()
  34758. {
  34759. }
  34760. bool ToolbarButton::getToolbarItemSizes (int toolbarDepth,
  34761. bool /*isToolbarVertical*/,
  34762. int& preferredSize,
  34763. int& minSize, int& maxSize)
  34764. {
  34765. preferredSize = minSize = maxSize = toolbarDepth;
  34766. return true;
  34767. }
  34768. void ToolbarButton::paintButtonArea (Graphics& g,
  34769. int width, int height,
  34770. bool /*isMouseOver*/,
  34771. bool /*isMouseDown*/)
  34772. {
  34773. Drawable* d = normalImage;
  34774. if (getToggleState() && toggledOnImage != 0)
  34775. d = toggledOnImage;
  34776. if (! isEnabled())
  34777. {
  34778. Image im (Image::ARGB, width, height, true);
  34779. Graphics g2 (im);
  34780. d->drawWithin (g2, 0, 0, width, height, RectanglePlacement::centred, 1.0f);
  34781. im.desaturate();
  34782. g.drawImageAt (&im, 0, 0);
  34783. }
  34784. else
  34785. {
  34786. d->drawWithin (g, 0, 0, width, height, RectanglePlacement::centred, 1.0f);
  34787. }
  34788. }
  34789. void ToolbarButton::contentAreaChanged (const Rectangle<int>&)
  34790. {
  34791. }
  34792. END_JUCE_NAMESPACE
  34793. /*** End of inlined file: juce_ToolbarButton.cpp ***/
  34794. /*** Start of inlined file: juce_CodeDocument.cpp ***/
  34795. BEGIN_JUCE_NAMESPACE
  34796. class CodeDocumentLine
  34797. {
  34798. public:
  34799. CodeDocumentLine (const tchar* const line_,
  34800. const int lineLength_,
  34801. const int numNewLineChars,
  34802. const int lineStartInFile_)
  34803. : line (line_, lineLength_),
  34804. lineStartInFile (lineStartInFile_),
  34805. lineLength (lineLength_),
  34806. lineLengthWithoutNewLines (lineLength_ - numNewLineChars)
  34807. {
  34808. }
  34809. ~CodeDocumentLine()
  34810. {
  34811. }
  34812. static void createLines (Array <CodeDocumentLine*>& newLines, const String& text)
  34813. {
  34814. const tchar* const t = (const tchar*) text;
  34815. int pos = 0;
  34816. while (t [pos] != 0)
  34817. {
  34818. const int startOfLine = pos;
  34819. int numNewLineChars = 0;
  34820. while (t[pos] != 0)
  34821. {
  34822. if (t[pos] == T('\r'))
  34823. {
  34824. ++numNewLineChars;
  34825. ++pos;
  34826. if (t[pos] == T('\n'))
  34827. {
  34828. ++numNewLineChars;
  34829. ++pos;
  34830. }
  34831. break;
  34832. }
  34833. if (t[pos] == T('\n'))
  34834. {
  34835. ++numNewLineChars;
  34836. ++pos;
  34837. break;
  34838. }
  34839. ++pos;
  34840. }
  34841. newLines.add (new CodeDocumentLine (t + startOfLine, pos - startOfLine,
  34842. numNewLineChars, startOfLine));
  34843. }
  34844. jassert (pos == text.length());
  34845. }
  34846. bool endsWithLineBreak() const throw()
  34847. {
  34848. return lineLengthWithoutNewLines != lineLength;
  34849. }
  34850. void updateLength() throw()
  34851. {
  34852. lineLengthWithoutNewLines = lineLength = line.length();
  34853. while (lineLengthWithoutNewLines > 0
  34854. && (line [lineLengthWithoutNewLines - 1] == '\n'
  34855. || line [lineLengthWithoutNewLines - 1] == '\r'))
  34856. {
  34857. --lineLengthWithoutNewLines;
  34858. }
  34859. }
  34860. String line;
  34861. int lineStartInFile, lineLength, lineLengthWithoutNewLines;
  34862. };
  34863. CodeDocument::Iterator::Iterator (CodeDocument* const document_)
  34864. : document (document_),
  34865. currentLine (document_->lines[0]),
  34866. line (0),
  34867. position (0)
  34868. {
  34869. }
  34870. CodeDocument::Iterator::Iterator (const CodeDocument::Iterator& other)
  34871. : document (other.document),
  34872. currentLine (other.currentLine),
  34873. line (other.line),
  34874. position (other.position)
  34875. {
  34876. }
  34877. CodeDocument::Iterator& CodeDocument::Iterator::operator= (const CodeDocument::Iterator& other) throw()
  34878. {
  34879. document = other.document;
  34880. currentLine = other.currentLine;
  34881. line = other.line;
  34882. position = other.position;
  34883. return *this;
  34884. }
  34885. CodeDocument::Iterator::~Iterator() throw()
  34886. {
  34887. }
  34888. juce_wchar CodeDocument::Iterator::nextChar()
  34889. {
  34890. if (currentLine == 0)
  34891. return 0;
  34892. jassert (currentLine == document->lines.getUnchecked (line));
  34893. const juce_wchar result = currentLine->line [position - currentLine->lineStartInFile];
  34894. if (++position >= currentLine->lineStartInFile + currentLine->lineLength)
  34895. {
  34896. ++line;
  34897. currentLine = document->lines [line];
  34898. }
  34899. return result;
  34900. }
  34901. void CodeDocument::Iterator::skip()
  34902. {
  34903. if (currentLine != 0)
  34904. {
  34905. jassert (currentLine == document->lines.getUnchecked (line));
  34906. if (++position >= currentLine->lineStartInFile + currentLine->lineLength)
  34907. {
  34908. ++line;
  34909. currentLine = document->lines [line];
  34910. }
  34911. }
  34912. }
  34913. void CodeDocument::Iterator::skipToEndOfLine()
  34914. {
  34915. if (currentLine != 0)
  34916. {
  34917. jassert (currentLine == document->lines.getUnchecked (line));
  34918. ++line;
  34919. currentLine = document->lines [line];
  34920. if (currentLine != 0)
  34921. position = currentLine->lineStartInFile;
  34922. else
  34923. position = document->getNumCharacters();
  34924. }
  34925. }
  34926. juce_wchar CodeDocument::Iterator::peekNextChar() const
  34927. {
  34928. if (currentLine == 0)
  34929. return 0;
  34930. jassert (currentLine == document->lines.getUnchecked (line));
  34931. return const_cast <const String&> (currentLine->line) [position - currentLine->lineStartInFile];
  34932. }
  34933. void CodeDocument::Iterator::skipWhitespace()
  34934. {
  34935. while (CharacterFunctions::isWhitespace (peekNextChar()))
  34936. skip();
  34937. }
  34938. bool CodeDocument::Iterator::isEOF() const throw()
  34939. {
  34940. return currentLine == 0;
  34941. }
  34942. CodeDocument::Position::Position() throw()
  34943. : owner (0), characterPos (0), line (0),
  34944. indexInLine (0), positionMaintained (false)
  34945. {
  34946. }
  34947. CodeDocument::Position::Position (const CodeDocument* const ownerDocument,
  34948. const int line_, const int indexInLine_) throw()
  34949. : owner (const_cast <CodeDocument*> (ownerDocument)),
  34950. characterPos (0), line (line_),
  34951. indexInLine (indexInLine_), positionMaintained (false)
  34952. {
  34953. setLineAndIndex (line_, indexInLine_);
  34954. }
  34955. CodeDocument::Position::Position (const CodeDocument* const ownerDocument,
  34956. const int characterPos_) throw()
  34957. : owner (const_cast <CodeDocument*> (ownerDocument)),
  34958. positionMaintained (false)
  34959. {
  34960. setPosition (characterPos_);
  34961. }
  34962. CodeDocument::Position::Position (const Position& other) throw()
  34963. : owner (other.owner), characterPos (other.characterPos), line (other.line),
  34964. indexInLine (other.indexInLine), positionMaintained (false)
  34965. {
  34966. jassert (*this == other);
  34967. }
  34968. CodeDocument::Position::~Position() throw()
  34969. {
  34970. setPositionMaintained (false);
  34971. }
  34972. CodeDocument::Position& CodeDocument::Position::operator= (const Position& other) throw()
  34973. {
  34974. if (this != &other)
  34975. {
  34976. const bool wasPositionMaintained = positionMaintained;
  34977. if (owner != other.owner)
  34978. setPositionMaintained (false);
  34979. owner = other.owner;
  34980. line = other.line;
  34981. indexInLine = other.indexInLine;
  34982. characterPos = other.characterPos;
  34983. setPositionMaintained (wasPositionMaintained);
  34984. jassert (*this == other);
  34985. }
  34986. return *this;
  34987. }
  34988. bool CodeDocument::Position::operator== (const Position& other) const throw()
  34989. {
  34990. jassert ((characterPos == other.characterPos)
  34991. == (line == other.line && indexInLine == other.indexInLine));
  34992. return characterPos == other.characterPos
  34993. && line == other.line
  34994. && indexInLine == other.indexInLine
  34995. && owner == other.owner;
  34996. }
  34997. bool CodeDocument::Position::operator!= (const Position& other) const throw()
  34998. {
  34999. return ! operator== (other);
  35000. }
  35001. void CodeDocument::Position::setLineAndIndex (const int newLine, const int newIndexInLine) throw()
  35002. {
  35003. jassert (owner != 0);
  35004. if (owner->lines.size() == 0)
  35005. {
  35006. line = 0;
  35007. indexInLine = 0;
  35008. characterPos = 0;
  35009. }
  35010. else
  35011. {
  35012. if (newLine >= owner->lines.size())
  35013. {
  35014. line = owner->lines.size() - 1;
  35015. CodeDocumentLine* const l = owner->lines.getUnchecked (line);
  35016. jassert (l != 0);
  35017. indexInLine = l->lineLengthWithoutNewLines;
  35018. characterPos = l->lineStartInFile + indexInLine;
  35019. }
  35020. else
  35021. {
  35022. line = jmax (0, newLine);
  35023. CodeDocumentLine* const l = owner->lines.getUnchecked (line);
  35024. jassert (l != 0);
  35025. if (l->lineLengthWithoutNewLines > 0)
  35026. indexInLine = jlimit (0, l->lineLengthWithoutNewLines, newIndexInLine);
  35027. else
  35028. indexInLine = 0;
  35029. characterPos = l->lineStartInFile + indexInLine;
  35030. }
  35031. }
  35032. }
  35033. void CodeDocument::Position::setPosition (const int newPosition) throw()
  35034. {
  35035. jassert (owner != 0);
  35036. line = 0;
  35037. indexInLine = 0;
  35038. characterPos = 0;
  35039. if (newPosition > 0)
  35040. {
  35041. int lineStart = 0;
  35042. int lineEnd = owner->lines.size();
  35043. for (;;)
  35044. {
  35045. if (lineEnd - lineStart < 4)
  35046. {
  35047. for (int i = lineStart; i < lineEnd; ++i)
  35048. {
  35049. CodeDocumentLine* const l = owner->lines.getUnchecked (i);
  35050. int index = newPosition - l->lineStartInFile;
  35051. if (index >= 0 && (index < l->lineLength || i == lineEnd - 1))
  35052. {
  35053. line = i;
  35054. indexInLine = jmin (l->lineLengthWithoutNewLines, index);
  35055. characterPos = l->lineStartInFile + indexInLine;
  35056. }
  35057. }
  35058. break;
  35059. }
  35060. else
  35061. {
  35062. const int midIndex = (lineStart + lineEnd + 1) / 2;
  35063. CodeDocumentLine* const mid = owner->lines.getUnchecked (midIndex);
  35064. if (newPosition >= mid->lineStartInFile)
  35065. lineStart = midIndex;
  35066. else
  35067. lineEnd = midIndex;
  35068. }
  35069. }
  35070. }
  35071. }
  35072. void CodeDocument::Position::moveBy (int characterDelta) throw()
  35073. {
  35074. jassert (owner != 0);
  35075. if (characterDelta == 1)
  35076. {
  35077. setPosition (getPosition());
  35078. // If moving right, make sure we don't get stuck between the \r and \n characters..
  35079. if (line < owner->lines.size())
  35080. {
  35081. CodeDocumentLine* const l = owner->lines.getUnchecked (line);
  35082. if (indexInLine + characterDelta < l->lineLength
  35083. && indexInLine + characterDelta >= l->lineLengthWithoutNewLines + 1)
  35084. ++characterDelta;
  35085. }
  35086. }
  35087. setPosition (characterPos + characterDelta);
  35088. }
  35089. const CodeDocument::Position CodeDocument::Position::movedBy (const int characterDelta) const throw()
  35090. {
  35091. CodeDocument::Position p (*this);
  35092. p.moveBy (characterDelta);
  35093. return p;
  35094. }
  35095. const CodeDocument::Position CodeDocument::Position::movedByLines (const int deltaLines) const throw()
  35096. {
  35097. CodeDocument::Position p (*this);
  35098. p.setLineAndIndex (getLineNumber() + deltaLines, getIndexInLine());
  35099. return p;
  35100. }
  35101. const tchar CodeDocument::Position::getCharacter() const throw()
  35102. {
  35103. const CodeDocumentLine* const l = owner->lines [line];
  35104. return l == 0 ? 0 : l->line [getIndexInLine()];
  35105. }
  35106. const String CodeDocument::Position::getLineText() const throw()
  35107. {
  35108. const CodeDocumentLine* const l = owner->lines [line];
  35109. return l == 0 ? String::empty : l->line;
  35110. }
  35111. void CodeDocument::Position::setPositionMaintained (const bool isMaintained) throw()
  35112. {
  35113. if (isMaintained != positionMaintained)
  35114. {
  35115. positionMaintained = isMaintained;
  35116. if (owner != 0)
  35117. {
  35118. if (isMaintained)
  35119. {
  35120. jassert (! owner->positionsToMaintain.contains (this));
  35121. owner->positionsToMaintain.add (this);
  35122. }
  35123. else
  35124. {
  35125. jassert (owner->positionsToMaintain.contains (this));
  35126. owner->positionsToMaintain.removeValue (this);
  35127. }
  35128. }
  35129. }
  35130. }
  35131. CodeDocument::CodeDocument()
  35132. : undoManager (std::numeric_limits<int>::max(), 10000),
  35133. currentActionIndex (0),
  35134. indexOfSavedState (-1),
  35135. maximumLineLength (-1),
  35136. newLineChars ("\r\n")
  35137. {
  35138. }
  35139. CodeDocument::~CodeDocument()
  35140. {
  35141. }
  35142. const String CodeDocument::getAllContent() const throw()
  35143. {
  35144. return getTextBetween (Position (this, 0),
  35145. Position (this, lines.size(), 0));
  35146. }
  35147. const String CodeDocument::getTextBetween (const Position& start, const Position& end) const throw()
  35148. {
  35149. if (end.getPosition() <= start.getPosition())
  35150. return String::empty;
  35151. const int startLine = start.getLineNumber();
  35152. const int endLine = end.getLineNumber();
  35153. if (startLine == endLine)
  35154. {
  35155. CodeDocumentLine* const line = lines [startLine];
  35156. return (line == 0) ? String::empty : line->line.substring (start.getIndexInLine(), end.getIndexInLine());
  35157. }
  35158. String result;
  35159. result.preallocateStorage (end.getPosition() - start.getPosition() + 4);
  35160. String::Concatenator concatenator (result);
  35161. const int maxLine = jmin (lines.size() - 1, endLine);
  35162. for (int i = jmax (0, startLine); i <= maxLine; ++i)
  35163. {
  35164. const CodeDocumentLine* line = lines.getUnchecked(i);
  35165. int len = line->lineLength;
  35166. if (i == startLine)
  35167. {
  35168. const int index = start.getIndexInLine();
  35169. concatenator.append (line->line.substring (index, len));
  35170. }
  35171. else if (i == endLine)
  35172. {
  35173. len = end.getIndexInLine();
  35174. concatenator.append (line->line.substring (0, len));
  35175. }
  35176. else
  35177. {
  35178. concatenator.append (line->line);
  35179. }
  35180. }
  35181. return result;
  35182. }
  35183. int CodeDocument::getNumCharacters() const throw()
  35184. {
  35185. const CodeDocumentLine* const lastLine = lines.getLast();
  35186. return (lastLine == 0) ? 0 : lastLine->lineStartInFile + lastLine->lineLength;
  35187. }
  35188. const String CodeDocument::getLine (const int lineIndex) const throw()
  35189. {
  35190. const CodeDocumentLine* const line = lines [lineIndex];
  35191. return (line == 0) ? String::empty : line->line;
  35192. }
  35193. int CodeDocument::getMaximumLineLength() throw()
  35194. {
  35195. if (maximumLineLength < 0)
  35196. {
  35197. maximumLineLength = 0;
  35198. for (int i = lines.size(); --i >= 0;)
  35199. maximumLineLength = jmax (maximumLineLength, lines.getUnchecked(i)->lineLength);
  35200. }
  35201. return maximumLineLength;
  35202. }
  35203. void CodeDocument::deleteSection (const Position& startPosition, const Position& endPosition)
  35204. {
  35205. remove (startPosition.getPosition(), endPosition.getPosition(), true);
  35206. }
  35207. void CodeDocument::insertText (const Position& position, const String& text)
  35208. {
  35209. insert (text, position.getPosition(), true);
  35210. }
  35211. void CodeDocument::replaceAllContent (const String& newContent)
  35212. {
  35213. remove (0, getNumCharacters(), true);
  35214. insert (newContent, 0, true);
  35215. }
  35216. bool CodeDocument::loadFromStream (InputStream& stream)
  35217. {
  35218. replaceAllContent (stream.readEntireStreamAsString());
  35219. setSavePoint();
  35220. clearUndoHistory();
  35221. return true;
  35222. }
  35223. bool CodeDocument::writeToStream (OutputStream& stream)
  35224. {
  35225. for (int i = 0; i < lines.size(); ++i)
  35226. {
  35227. String temp (lines.getUnchecked(i)->line); // use a copy to avoid bloating the memory footprint of the stored string.
  35228. const char* utf8 = temp.toUTF8();
  35229. if (! stream.write (utf8, (int) strlen (utf8)))
  35230. return false;
  35231. }
  35232. return true;
  35233. }
  35234. void CodeDocument::setNewLineCharacters (const String& newLine) throw()
  35235. {
  35236. jassert (newLine == T("\r\n") || newLine == T("\n") || newLine == T("\r"));
  35237. newLineChars = newLine;
  35238. }
  35239. void CodeDocument::newTransaction()
  35240. {
  35241. undoManager.beginNewTransaction (String::empty);
  35242. }
  35243. void CodeDocument::undo()
  35244. {
  35245. newTransaction();
  35246. undoManager.undo();
  35247. }
  35248. void CodeDocument::redo()
  35249. {
  35250. undoManager.redo();
  35251. }
  35252. void CodeDocument::clearUndoHistory()
  35253. {
  35254. undoManager.clearUndoHistory();
  35255. }
  35256. void CodeDocument::setSavePoint() throw()
  35257. {
  35258. indexOfSavedState = currentActionIndex;
  35259. }
  35260. bool CodeDocument::hasChangedSinceSavePoint() const throw()
  35261. {
  35262. return currentActionIndex != indexOfSavedState;
  35263. }
  35264. static int getCodeCharacterCategory (const tchar character) throw()
  35265. {
  35266. return (CharacterFunctions::isLetterOrDigit (character) || character == '_')
  35267. ? 2 : (CharacterFunctions::isWhitespace (character) ? 0 : 1);
  35268. }
  35269. const CodeDocument::Position CodeDocument::findWordBreakAfter (const Position& position) const throw()
  35270. {
  35271. Position p (position);
  35272. const int maxDistance = 256;
  35273. int i = 0;
  35274. while (i < maxDistance
  35275. && CharacterFunctions::isWhitespace (p.getCharacter())
  35276. && (i == 0 || (p.getCharacter() != T('\n')
  35277. && p.getCharacter() != T('\r'))))
  35278. {
  35279. ++i;
  35280. p.moveBy (1);
  35281. }
  35282. if (i == 0)
  35283. {
  35284. const int type = getCodeCharacterCategory (p.getCharacter());
  35285. while (i < maxDistance && type == getCodeCharacterCategory (p.getCharacter()))
  35286. {
  35287. ++i;
  35288. p.moveBy (1);
  35289. }
  35290. while (i < maxDistance
  35291. && CharacterFunctions::isWhitespace (p.getCharacter())
  35292. && (i == 0 || (p.getCharacter() != T('\n')
  35293. && p.getCharacter() != T('\r'))))
  35294. {
  35295. ++i;
  35296. p.moveBy (1);
  35297. }
  35298. }
  35299. return p;
  35300. }
  35301. const CodeDocument::Position CodeDocument::findWordBreakBefore (const Position& position) const throw()
  35302. {
  35303. Position p (position);
  35304. const int maxDistance = 256;
  35305. int i = 0;
  35306. bool stoppedAtLineStart = false;
  35307. while (i < maxDistance)
  35308. {
  35309. const tchar c = p.movedBy (-1).getCharacter();
  35310. if (c == T('\r') || c == T('\n'))
  35311. {
  35312. stoppedAtLineStart = true;
  35313. if (i > 0)
  35314. break;
  35315. }
  35316. if (! CharacterFunctions::isWhitespace (c))
  35317. break;
  35318. p.moveBy (-1);
  35319. ++i;
  35320. }
  35321. if (i < maxDistance && ! stoppedAtLineStart)
  35322. {
  35323. const int type = getCodeCharacterCategory (p.movedBy (-1).getCharacter());
  35324. while (i < maxDistance && type == getCodeCharacterCategory (p.movedBy (-1).getCharacter()))
  35325. {
  35326. p.moveBy (-1);
  35327. ++i;
  35328. }
  35329. }
  35330. return p;
  35331. }
  35332. void CodeDocument::checkLastLineStatus()
  35333. {
  35334. while (lines.size() > 0
  35335. && lines.getLast()->lineLength == 0
  35336. && (lines.size() == 1 || ! lines.getUnchecked (lines.size() - 2)->endsWithLineBreak()))
  35337. {
  35338. // remove any empty lines at the end if the preceding line doesn't end in a newline.
  35339. lines.removeLast();
  35340. }
  35341. const CodeDocumentLine* const lastLine = lines.getLast();
  35342. if (lastLine != 0 && lastLine->endsWithLineBreak())
  35343. {
  35344. // check that there's an empty line at the end if the preceding one ends in a newline..
  35345. lines.add (new CodeDocumentLine (String::empty, 0, 0, lastLine->lineStartInFile + lastLine->lineLength));
  35346. }
  35347. }
  35348. void CodeDocument::addListener (CodeDocument::Listener* const listener) throw()
  35349. {
  35350. listeners.addIfNotAlreadyThere (listener);
  35351. }
  35352. void CodeDocument::removeListener (CodeDocument::Listener* const listener) throw()
  35353. {
  35354. listeners.removeValue (listener);
  35355. }
  35356. void CodeDocument::sendListenerChangeMessage (const int startLine, const int endLine)
  35357. {
  35358. const Position startPos (this, startLine, 0);
  35359. const Position endPos (this, endLine, 0);
  35360. for (int i = listeners.size(); --i >= 0;)
  35361. {
  35362. Listener* const l = (Listener*) listeners[i];
  35363. if (l != 0)
  35364. l->codeDocumentChanged (startPos, endPos);
  35365. }
  35366. }
  35367. class CodeDocumentInsertAction : public UndoableAction
  35368. {
  35369. CodeDocument& owner;
  35370. const String text;
  35371. int insertPos;
  35372. CodeDocumentInsertAction (const CodeDocumentInsertAction&);
  35373. CodeDocumentInsertAction& operator= (const CodeDocumentInsertAction&);
  35374. public:
  35375. CodeDocumentInsertAction (CodeDocument& owner_, const String& text_, const int insertPos_) throw()
  35376. : owner (owner_),
  35377. text (text_),
  35378. insertPos (insertPos_)
  35379. {
  35380. }
  35381. ~CodeDocumentInsertAction() {}
  35382. bool perform()
  35383. {
  35384. owner.currentActionIndex++;
  35385. owner.insert (text, insertPos, false);
  35386. return true;
  35387. }
  35388. bool undo()
  35389. {
  35390. owner.currentActionIndex--;
  35391. owner.remove (insertPos, insertPos + text.length(), false);
  35392. return true;
  35393. }
  35394. int getSizeInUnits() { return text.length() + 32; }
  35395. };
  35396. void CodeDocument::insert (const String& text, const int insertPos, const bool undoable)
  35397. {
  35398. if (text.isEmpty())
  35399. return;
  35400. if (undoable)
  35401. {
  35402. undoManager.perform (new CodeDocumentInsertAction (*this, text, insertPos));
  35403. }
  35404. else
  35405. {
  35406. Position pos (this, insertPos);
  35407. const int firstAffectedLine = pos.getLineNumber();
  35408. int lastAffectedLine = firstAffectedLine + 1;
  35409. CodeDocumentLine* const firstLine = lines [firstAffectedLine];
  35410. String textInsideOriginalLine (text);
  35411. if (firstLine != 0)
  35412. {
  35413. const int index = pos.getIndexInLine();
  35414. textInsideOriginalLine = firstLine->line.substring (0, index)
  35415. + textInsideOriginalLine
  35416. + firstLine->line.substring (index);
  35417. }
  35418. maximumLineLength = -1;
  35419. Array <CodeDocumentLine*> newLines;
  35420. CodeDocumentLine::createLines (newLines, textInsideOriginalLine);
  35421. jassert (newLines.size() > 0);
  35422. CodeDocumentLine* const newFirstLine = newLines.getUnchecked (0);
  35423. newFirstLine->lineStartInFile = firstLine != 0 ? firstLine->lineStartInFile : 0;
  35424. lines.set (firstAffectedLine, newFirstLine);
  35425. if (newLines.size() > 1)
  35426. {
  35427. for (int i = 1; i < newLines.size(); ++i)
  35428. {
  35429. CodeDocumentLine* const l = newLines.getUnchecked (i);
  35430. lines.insert (firstAffectedLine + i, l);
  35431. }
  35432. lastAffectedLine = lines.size();
  35433. }
  35434. int i, lineStart = newFirstLine->lineStartInFile;
  35435. for (i = firstAffectedLine; i < lines.size(); ++i)
  35436. {
  35437. CodeDocumentLine* const l = lines.getUnchecked (i);
  35438. l->lineStartInFile = lineStart;
  35439. lineStart += l->lineLength;
  35440. }
  35441. checkLastLineStatus();
  35442. const int newTextLength = text.length();
  35443. for (i = 0; i < positionsToMaintain.size(); ++i)
  35444. {
  35445. CodeDocument::Position* const p = positionsToMaintain.getUnchecked(i);
  35446. if (p->getPosition() >= insertPos)
  35447. p->setPosition (p->getPosition() + newTextLength);
  35448. }
  35449. sendListenerChangeMessage (firstAffectedLine, lastAffectedLine);
  35450. }
  35451. }
  35452. class CodeDocumentDeleteAction : public UndoableAction
  35453. {
  35454. CodeDocument& owner;
  35455. int startPos, endPos;
  35456. String removedText;
  35457. CodeDocumentDeleteAction (const CodeDocumentDeleteAction&);
  35458. CodeDocumentDeleteAction& operator= (const CodeDocumentDeleteAction&);
  35459. public:
  35460. CodeDocumentDeleteAction (CodeDocument& owner_, const int startPos_, const int endPos_) throw()
  35461. : owner (owner_),
  35462. startPos (startPos_),
  35463. endPos (endPos_)
  35464. {
  35465. removedText = owner.getTextBetween (CodeDocument::Position (&owner, startPos),
  35466. CodeDocument::Position (&owner, endPos));
  35467. }
  35468. ~CodeDocumentDeleteAction() {}
  35469. bool perform()
  35470. {
  35471. owner.currentActionIndex++;
  35472. owner.remove (startPos, endPos, false);
  35473. return true;
  35474. }
  35475. bool undo()
  35476. {
  35477. owner.currentActionIndex--;
  35478. owner.insert (removedText, startPos, false);
  35479. return true;
  35480. }
  35481. int getSizeInUnits() { return removedText.length() + 32; }
  35482. };
  35483. void CodeDocument::remove (const int startPos, const int endPos, const bool undoable)
  35484. {
  35485. if (endPos <= startPos)
  35486. return;
  35487. if (undoable)
  35488. {
  35489. undoManager.perform (new CodeDocumentDeleteAction (*this, startPos, endPos));
  35490. }
  35491. else
  35492. {
  35493. Position startPosition (this, startPos);
  35494. Position endPosition (this, endPos);
  35495. maximumLineLength = -1;
  35496. const int firstAffectedLine = startPosition.getLineNumber();
  35497. const int endLine = endPosition.getLineNumber();
  35498. int lastAffectedLine = firstAffectedLine + 1;
  35499. CodeDocumentLine* const firstLine = lines.getUnchecked (firstAffectedLine);
  35500. if (firstAffectedLine == endLine)
  35501. {
  35502. firstLine->line = firstLine->line.substring (0, startPosition.getIndexInLine())
  35503. + firstLine->line.substring (endPosition.getIndexInLine());
  35504. firstLine->updateLength();
  35505. }
  35506. else
  35507. {
  35508. lastAffectedLine = lines.size();
  35509. CodeDocumentLine* const lastLine = lines.getUnchecked (endLine);
  35510. jassert (lastLine != 0);
  35511. firstLine->line = firstLine->line.substring (0, startPosition.getIndexInLine())
  35512. + lastLine->line.substring (endPosition.getIndexInLine());
  35513. firstLine->updateLength();
  35514. int numLinesToRemove = endLine - firstAffectedLine;
  35515. lines.removeRange (firstAffectedLine + 1, numLinesToRemove);
  35516. }
  35517. int i;
  35518. for (i = firstAffectedLine + 1; i < lines.size(); ++i)
  35519. {
  35520. CodeDocumentLine* const l = lines.getUnchecked (i);
  35521. const CodeDocumentLine* const previousLine = lines.getUnchecked (i - 1);
  35522. l->lineStartInFile = previousLine->lineStartInFile + previousLine->lineLength;
  35523. }
  35524. checkLastLineStatus();
  35525. const int totalChars = getNumCharacters();
  35526. for (i = 0; i < positionsToMaintain.size(); ++i)
  35527. {
  35528. CodeDocument::Position* p = positionsToMaintain.getUnchecked(i);
  35529. if (p->getPosition() > startPosition.getPosition())
  35530. p->setPosition (jmax (startPos, p->getPosition() + startPos - endPos));
  35531. if (p->getPosition() > totalChars)
  35532. p->setPosition (totalChars);
  35533. }
  35534. sendListenerChangeMessage (firstAffectedLine, lastAffectedLine);
  35535. }
  35536. }
  35537. END_JUCE_NAMESPACE
  35538. /*** End of inlined file: juce_CodeDocument.cpp ***/
  35539. /*** Start of inlined file: juce_CodeEditorComponent.cpp ***/
  35540. BEGIN_JUCE_NAMESPACE
  35541. class CaretComponent : public Component,
  35542. public Timer
  35543. {
  35544. public:
  35545. CaretComponent()
  35546. {
  35547. setAlwaysOnTop (true);
  35548. setInterceptsMouseClicks (false, false);
  35549. }
  35550. ~CaretComponent()
  35551. {
  35552. }
  35553. void paint (Graphics& g)
  35554. {
  35555. if (getParentComponent()->hasKeyboardFocus (true))
  35556. g.fillAll (findColour (CodeEditorComponent::caretColourId));
  35557. }
  35558. void timerCallback()
  35559. {
  35560. setVisible (! isVisible());
  35561. }
  35562. void updatePosition (CodeEditorComponent& owner)
  35563. {
  35564. startTimer (400);
  35565. setVisible (true);
  35566. const Rectangle<int> pos (owner.getCharacterBounds (owner.getCaretPos()));
  35567. setBounds (pos.getX(), pos.getY(), 2, pos.getHeight());
  35568. }
  35569. };
  35570. class CodeEditorComponent::CodeEditorLine
  35571. {
  35572. public:
  35573. CodeEditorLine() throw()
  35574. {
  35575. }
  35576. ~CodeEditorLine() throw()
  35577. {
  35578. }
  35579. bool update (CodeDocument& document, int lineNum,
  35580. CodeDocument::Iterator& source,
  35581. CodeTokeniser* analyser, const int spacesPerTab,
  35582. const CodeDocument::Position& selectionStart,
  35583. const CodeDocument::Position& selectionEnd)
  35584. {
  35585. Array <SyntaxToken> newTokens;
  35586. newTokens.ensureStorageAllocated (8);
  35587. if (analyser == 0)
  35588. {
  35589. newTokens.add (SyntaxToken (document.getLine (lineNum), -1));
  35590. }
  35591. else if (lineNum < document.getNumLines())
  35592. {
  35593. const CodeDocument::Position pos (&document, lineNum, 0);
  35594. createTokens (pos.getPosition(), pos.getLineText(),
  35595. source, analyser, newTokens);
  35596. }
  35597. replaceTabsWithSpaces (newTokens, spacesPerTab);
  35598. int newHighlightStart = 0;
  35599. int newHighlightEnd = 0;
  35600. if (selectionStart.getLineNumber() <= lineNum && selectionEnd.getLineNumber() >= lineNum)
  35601. {
  35602. const String line (document.getLine (lineNum));
  35603. CodeDocument::Position lineStart (&document, lineNum, 0), lineEnd (&document, lineNum + 1, 0);
  35604. newHighlightStart = indexToColumn (jmax (0, selectionStart.getPosition() - lineStart.getPosition()),
  35605. line, spacesPerTab);
  35606. newHighlightEnd = indexToColumn (jmin (lineEnd.getPosition() - lineStart.getPosition(), selectionEnd.getPosition() - lineStart.getPosition()),
  35607. line, spacesPerTab);
  35608. }
  35609. if (newHighlightStart != highlightColumnStart || newHighlightEnd != highlightColumnEnd)
  35610. {
  35611. highlightColumnStart = newHighlightStart;
  35612. highlightColumnEnd = newHighlightEnd;
  35613. }
  35614. else
  35615. {
  35616. if (tokens.size() == newTokens.size())
  35617. {
  35618. bool allTheSame = true;
  35619. for (int i = newTokens.size(); --i >= 0;)
  35620. {
  35621. if (tokens.getReference(i) != newTokens.getReference(i))
  35622. {
  35623. allTheSame = false;
  35624. break;
  35625. }
  35626. }
  35627. if (allTheSame)
  35628. return false;
  35629. }
  35630. }
  35631. tokens.swapWithArray (newTokens);
  35632. return true;
  35633. }
  35634. void draw (CodeEditorComponent& owner, Graphics& g, const Font& font,
  35635. float x, const int y, const int baselineOffset, const int lineHeight,
  35636. const Colour& highlightColour) const throw()
  35637. {
  35638. if (highlightColumnStart < highlightColumnEnd)
  35639. {
  35640. g.setColour (highlightColour);
  35641. g.fillRect (roundToInt (x + highlightColumnStart * owner.getCharWidth()), y,
  35642. roundToInt ((highlightColumnEnd - highlightColumnStart) * owner.getCharWidth()), lineHeight);
  35643. }
  35644. int lastType = std::numeric_limits<int>::min();
  35645. for (int i = 0; i < tokens.size(); ++i)
  35646. {
  35647. SyntaxToken& token = tokens.getReference(i);
  35648. if (lastType != token.tokenType)
  35649. {
  35650. lastType = token.tokenType;
  35651. g.setColour (owner.getColourForTokenType (lastType));
  35652. }
  35653. g.drawSingleLineText (token.text, roundToInt (x), y + baselineOffset);
  35654. if (i < tokens.size() - 1)
  35655. {
  35656. if (token.width < 0)
  35657. token.width = font.getStringWidthFloat (token.text);
  35658. x += token.width;
  35659. }
  35660. }
  35661. }
  35662. private:
  35663. struct SyntaxToken
  35664. {
  35665. String text;
  35666. int tokenType;
  35667. float width;
  35668. SyntaxToken (const String& text_, const int type) throw()
  35669. : text (text_), tokenType (type), width (-1.0f)
  35670. {
  35671. }
  35672. bool operator!= (const SyntaxToken& other) const throw()
  35673. {
  35674. return text != other.text || tokenType != other.tokenType;
  35675. }
  35676. };
  35677. Array <SyntaxToken> tokens;
  35678. int highlightColumnStart, highlightColumnEnd;
  35679. static void createTokens (int startPosition, const String& lineText,
  35680. CodeDocument::Iterator& source,
  35681. CodeTokeniser* analyser,
  35682. Array <SyntaxToken>& newTokens)
  35683. {
  35684. CodeDocument::Iterator lastIterator (source);
  35685. const int lineLength = lineText.length();
  35686. for (;;)
  35687. {
  35688. int tokenType = analyser->readNextToken (source);
  35689. int tokenStart = lastIterator.getPosition();
  35690. int tokenEnd = source.getPosition();
  35691. if (tokenEnd <= tokenStart)
  35692. break;
  35693. tokenEnd -= startPosition;
  35694. if (tokenEnd > 0)
  35695. {
  35696. tokenStart -= startPosition;
  35697. newTokens.add (SyntaxToken (lineText.substring (jmax (0, tokenStart), tokenEnd),
  35698. tokenType));
  35699. if (tokenEnd >= lineLength)
  35700. break;
  35701. }
  35702. lastIterator = source;
  35703. }
  35704. source = lastIterator;
  35705. }
  35706. static void replaceTabsWithSpaces (Array <SyntaxToken>& tokens, const int spacesPerTab) throw()
  35707. {
  35708. int x = 0;
  35709. for (int i = 0; i < tokens.size(); ++i)
  35710. {
  35711. SyntaxToken& t = tokens.getReference(i);
  35712. for (;;)
  35713. {
  35714. int tabPos = t.text.indexOfChar (T('\t'));
  35715. if (tabPos < 0)
  35716. break;
  35717. const int spacesNeeded = spacesPerTab - ((tabPos + x) % spacesPerTab);
  35718. t.text = t.text.replaceSection (tabPos, 1, String::repeatedString (T(" "), spacesNeeded));
  35719. }
  35720. x += t.text.length();
  35721. }
  35722. }
  35723. int indexToColumn (int index, const String& line, int spacesPerTab) const throw()
  35724. {
  35725. jassert (index <= line.length());
  35726. int col = 0;
  35727. for (int i = 0; i < index; ++i)
  35728. {
  35729. if (line[i] != T('\t'))
  35730. ++col;
  35731. else
  35732. col += spacesPerTab - (col % spacesPerTab);
  35733. }
  35734. return col;
  35735. }
  35736. };
  35737. CodeEditorComponent::CodeEditorComponent (CodeDocument& document_,
  35738. CodeTokeniser* const codeTokeniser_)
  35739. : document (document_),
  35740. firstLineOnScreen (0),
  35741. gutter (5),
  35742. spacesPerTab (4),
  35743. lineHeight (0),
  35744. linesOnScreen (0),
  35745. columnsOnScreen (0),
  35746. scrollbarThickness (16),
  35747. columnToTryToMaintain (-1),
  35748. useSpacesForTabs (false),
  35749. xOffset (0),
  35750. codeTokeniser (codeTokeniser_)
  35751. {
  35752. caretPos = CodeDocument::Position (&document_, 0, 0);
  35753. caretPos.setPositionMaintained (true);
  35754. selectionStart = CodeDocument::Position (&document_, 0, 0);
  35755. selectionStart.setPositionMaintained (true);
  35756. selectionEnd = CodeDocument::Position (&document_, 0, 0);
  35757. selectionEnd.setPositionMaintained (true);
  35758. setOpaque (true);
  35759. setMouseCursor (MouseCursor (MouseCursor::IBeamCursor));
  35760. setWantsKeyboardFocus (true);
  35761. addAndMakeVisible (verticalScrollBar = new ScrollBar (true));
  35762. verticalScrollBar->setSingleStepSize (1.0);
  35763. addAndMakeVisible (horizontalScrollBar = new ScrollBar (false));
  35764. horizontalScrollBar->setSingleStepSize (1.0);
  35765. addAndMakeVisible (caret = new CaretComponent());
  35766. Font f (12.0f);
  35767. f.setTypefaceName (Font::getDefaultMonospacedFontName());
  35768. setFont (f);
  35769. resetToDefaultColours();
  35770. verticalScrollBar->addListener (this);
  35771. horizontalScrollBar->addListener (this);
  35772. document.addListener (this);
  35773. }
  35774. CodeEditorComponent::~CodeEditorComponent()
  35775. {
  35776. document.removeListener (this);
  35777. deleteAllChildren();
  35778. }
  35779. void CodeEditorComponent::loadContent (const String& newContent)
  35780. {
  35781. clearCachedIterators (0);
  35782. document.replaceAllContent (newContent);
  35783. document.clearUndoHistory();
  35784. document.setSavePoint();
  35785. caretPos.setPosition (0);
  35786. selectionStart.setPosition (0);
  35787. selectionEnd.setPosition (0);
  35788. scrollToLine (0);
  35789. }
  35790. void CodeEditorComponent::codeDocumentChanged (const CodeDocument::Position& affectedTextStart,
  35791. const CodeDocument::Position& affectedTextEnd)
  35792. {
  35793. clearCachedIterators (affectedTextStart.getLineNumber());
  35794. triggerAsyncUpdate();
  35795. ((CaretComponent*) caret)->updatePosition (*this);
  35796. columnToTryToMaintain = -1;
  35797. if (affectedTextEnd.getPosition() >= selectionStart.getPosition()
  35798. && affectedTextStart.getPosition() <= selectionEnd.getPosition())
  35799. deselectAll();
  35800. if (caretPos.getPosition() > affectedTextEnd.getPosition()
  35801. || caretPos.getPosition() < affectedTextStart.getPosition())
  35802. moveCaretTo (affectedTextStart, false);
  35803. updateScrollBars();
  35804. }
  35805. void CodeEditorComponent::resized()
  35806. {
  35807. linesOnScreen = (getHeight() - scrollbarThickness) / lineHeight;
  35808. columnsOnScreen = (int) ((getWidth() - scrollbarThickness) / charWidth);
  35809. lines.clear();
  35810. rebuildLineTokens();
  35811. ((CaretComponent*) caret)->updatePosition (*this);
  35812. verticalScrollBar->setBounds (getWidth() - scrollbarThickness, 0, scrollbarThickness, getHeight() - scrollbarThickness);
  35813. horizontalScrollBar->setBounds (gutter, getHeight() - scrollbarThickness, getWidth() - scrollbarThickness - gutter, scrollbarThickness);
  35814. updateScrollBars();
  35815. }
  35816. void CodeEditorComponent::paint (Graphics& g)
  35817. {
  35818. handleUpdateNowIfNeeded();
  35819. g.fillAll (findColour (CodeEditorComponent::backgroundColourId));
  35820. g.reduceClipRegion (gutter, 0, verticalScrollBar->getX() - gutter, horizontalScrollBar->getY());
  35821. g.setFont (font);
  35822. const int baselineOffset = (int) font.getAscent();
  35823. const Colour defaultColour (findColour (CodeEditorComponent::defaultTextColourId));
  35824. const Colour highlightColour (findColour (CodeEditorComponent::highlightColourId));
  35825. const Rectangle<int> clip (g.getClipBounds());
  35826. const int firstLineToDraw = jmax (0, clip.getY() / lineHeight);
  35827. const int lastLineToDraw = jmin (lines.size(), clip.getBottom() / lineHeight + 1);
  35828. for (int j = firstLineToDraw; j < lastLineToDraw; ++j)
  35829. {
  35830. lines.getUnchecked(j)->draw (*this, g, font,
  35831. (float) (gutter - xOffset * charWidth),
  35832. lineHeight * j, baselineOffset, lineHeight,
  35833. highlightColour);
  35834. }
  35835. }
  35836. void CodeEditorComponent::setScrollbarThickness (const int thickness) throw()
  35837. {
  35838. if (scrollbarThickness != thickness)
  35839. {
  35840. scrollbarThickness = thickness;
  35841. resized();
  35842. }
  35843. }
  35844. void CodeEditorComponent::handleAsyncUpdate()
  35845. {
  35846. rebuildLineTokens();
  35847. }
  35848. void CodeEditorComponent::rebuildLineTokens()
  35849. {
  35850. cancelPendingUpdate();
  35851. const int numNeeded = linesOnScreen + 1;
  35852. int minLineToRepaint = numNeeded;
  35853. int maxLineToRepaint = 0;
  35854. if (numNeeded != lines.size())
  35855. {
  35856. lines.clear();
  35857. for (int i = numNeeded; --i >= 0;)
  35858. lines.add (new CodeEditorLine());
  35859. minLineToRepaint = 0;
  35860. maxLineToRepaint = numNeeded;
  35861. }
  35862. jassert (numNeeded == lines.size());
  35863. CodeDocument::Iterator source (&document);
  35864. getIteratorForPosition (CodeDocument::Position (&document, firstLineOnScreen, 0).getPosition(), source);
  35865. for (int i = 0; i < numNeeded; ++i)
  35866. {
  35867. CodeEditorLine* const line = lines.getUnchecked(i);
  35868. if (line->update (document, firstLineOnScreen + i, source, codeTokeniser, spacesPerTab,
  35869. selectionStart, selectionEnd))
  35870. {
  35871. minLineToRepaint = jmin (minLineToRepaint, i);
  35872. maxLineToRepaint = jmax (maxLineToRepaint, i);
  35873. }
  35874. }
  35875. if (minLineToRepaint <= maxLineToRepaint)
  35876. {
  35877. repaint (gutter, lineHeight * minLineToRepaint - 1,
  35878. verticalScrollBar->getX() - gutter,
  35879. lineHeight * (1 + maxLineToRepaint - minLineToRepaint) + 2);
  35880. }
  35881. }
  35882. void CodeEditorComponent::moveCaretTo (const CodeDocument::Position& newPos, const bool highlighting)
  35883. {
  35884. caretPos = newPos;
  35885. columnToTryToMaintain = -1;
  35886. if (highlighting)
  35887. {
  35888. if (dragType == notDragging)
  35889. {
  35890. if (abs (caretPos.getPosition() - selectionStart.getPosition())
  35891. < abs (caretPos.getPosition() - selectionEnd.getPosition()))
  35892. dragType = draggingSelectionStart;
  35893. else
  35894. dragType = draggingSelectionEnd;
  35895. }
  35896. if (dragType == draggingSelectionStart)
  35897. {
  35898. selectionStart = caretPos;
  35899. if (selectionEnd.getPosition() < selectionStart.getPosition())
  35900. {
  35901. const CodeDocument::Position temp (selectionStart);
  35902. selectionStart = selectionEnd;
  35903. selectionEnd = temp;
  35904. dragType = draggingSelectionEnd;
  35905. }
  35906. }
  35907. else
  35908. {
  35909. selectionEnd = caretPos;
  35910. if (selectionEnd.getPosition() < selectionStart.getPosition())
  35911. {
  35912. const CodeDocument::Position temp (selectionStart);
  35913. selectionStart = selectionEnd;
  35914. selectionEnd = temp;
  35915. dragType = draggingSelectionStart;
  35916. }
  35917. }
  35918. triggerAsyncUpdate();
  35919. }
  35920. else
  35921. {
  35922. deselectAll();
  35923. }
  35924. ((CaretComponent*) caret)->updatePosition (*this);
  35925. scrollToKeepCaretOnScreen();
  35926. updateScrollBars();
  35927. }
  35928. void CodeEditorComponent::deselectAll()
  35929. {
  35930. if (selectionStart != selectionEnd)
  35931. triggerAsyncUpdate();
  35932. selectionStart = caretPos;
  35933. selectionEnd = caretPos;
  35934. }
  35935. void CodeEditorComponent::updateScrollBars()
  35936. {
  35937. verticalScrollBar->setRangeLimits (0, jmax (document.getNumLines(), firstLineOnScreen + linesOnScreen));
  35938. verticalScrollBar->setCurrentRange (firstLineOnScreen, linesOnScreen);
  35939. horizontalScrollBar->setRangeLimits (0, jmax ((double) document.getMaximumLineLength(), xOffset + columnsOnScreen));
  35940. horizontalScrollBar->setCurrentRange (xOffset, columnsOnScreen);
  35941. }
  35942. void CodeEditorComponent::scrollToLineInternal (int newFirstLineOnScreen)
  35943. {
  35944. newFirstLineOnScreen = jlimit (0, jmax (0, document.getNumLines() - 1),
  35945. newFirstLineOnScreen);
  35946. if (newFirstLineOnScreen != firstLineOnScreen)
  35947. {
  35948. firstLineOnScreen = newFirstLineOnScreen;
  35949. ((CaretComponent*) caret)->updatePosition (*this);
  35950. updateCachedIterators (firstLineOnScreen);
  35951. triggerAsyncUpdate();
  35952. }
  35953. }
  35954. void CodeEditorComponent::scrollToColumnInternal (double column)
  35955. {
  35956. const double newOffset = jlimit (0.0, document.getMaximumLineLength() + 3.0, column);
  35957. if (xOffset != newOffset)
  35958. {
  35959. xOffset = newOffset;
  35960. ((CaretComponent*) caret)->updatePosition (*this);
  35961. repaint();
  35962. }
  35963. }
  35964. void CodeEditorComponent::scrollToLine (int newFirstLineOnScreen)
  35965. {
  35966. scrollToLineInternal (newFirstLineOnScreen);
  35967. updateScrollBars();
  35968. }
  35969. void CodeEditorComponent::scrollToColumn (int newFirstColumnOnScreen)
  35970. {
  35971. scrollToColumnInternal (newFirstColumnOnScreen);
  35972. updateScrollBars();
  35973. }
  35974. void CodeEditorComponent::scrollBy (int deltaLines)
  35975. {
  35976. scrollToLine (firstLineOnScreen + deltaLines);
  35977. }
  35978. void CodeEditorComponent::scrollToKeepCaretOnScreen()
  35979. {
  35980. if (caretPos.getLineNumber() < firstLineOnScreen)
  35981. scrollBy (caretPos.getLineNumber() - firstLineOnScreen);
  35982. else if (caretPos.getLineNumber() >= firstLineOnScreen + linesOnScreen)
  35983. scrollBy (caretPos.getLineNumber() - (firstLineOnScreen + linesOnScreen - 1));
  35984. const int column = indexToColumn (caretPos.getLineNumber(), caretPos.getIndexInLine());
  35985. if (column >= xOffset + columnsOnScreen - 1)
  35986. scrollToColumn (column + 1 - columnsOnScreen);
  35987. else if (column < xOffset)
  35988. scrollToColumn (column);
  35989. }
  35990. const Rectangle<int> CodeEditorComponent::getCharacterBounds (const CodeDocument::Position& pos) const throw()
  35991. {
  35992. return Rectangle<int> (roundToInt ((gutter - xOffset * charWidth) + indexToColumn (pos.getLineNumber(), pos.getIndexInLine()) * charWidth),
  35993. (pos.getLineNumber() - firstLineOnScreen) * lineHeight,
  35994. roundToInt (charWidth),
  35995. lineHeight);
  35996. }
  35997. const CodeDocument::Position CodeEditorComponent::getPositionAt (int x, int y)
  35998. {
  35999. const int line = y / lineHeight + firstLineOnScreen;
  36000. const int column = roundToInt ((x - (gutter - xOffset * charWidth)) / charWidth);
  36001. const int index = columnToIndex (line, column);
  36002. return CodeDocument::Position (&document, line, index);
  36003. }
  36004. void CodeEditorComponent::insertTextAtCaret (const String& newText)
  36005. {
  36006. document.deleteSection (selectionStart, selectionEnd);
  36007. if (newText.isNotEmpty())
  36008. document.insertText (caretPos, newText);
  36009. scrollToKeepCaretOnScreen();
  36010. }
  36011. void CodeEditorComponent::insertTabAtCaret()
  36012. {
  36013. if (CharacterFunctions::isWhitespace (caretPos.getCharacter())
  36014. && caretPos.getLineNumber() == caretPos.movedBy (1).getLineNumber())
  36015. {
  36016. moveCaretTo (document.findWordBreakAfter (caretPos), false);
  36017. }
  36018. if (useSpacesForTabs)
  36019. {
  36020. const int caretCol = indexToColumn (caretPos.getLineNumber(), caretPos.getIndexInLine());
  36021. const int spacesNeeded = spacesPerTab - (caretCol % spacesPerTab);
  36022. insertTextAtCaret (String::repeatedString (T(" "), spacesNeeded));
  36023. }
  36024. else
  36025. {
  36026. insertTextAtCaret (T("\t"));
  36027. }
  36028. }
  36029. void CodeEditorComponent::cut()
  36030. {
  36031. insertTextAtCaret (String::empty);
  36032. }
  36033. void CodeEditorComponent::copy()
  36034. {
  36035. newTransaction();
  36036. const String selection (document.getTextBetween (selectionStart, selectionEnd));
  36037. if (selection.isNotEmpty())
  36038. SystemClipboard::copyTextToClipboard (selection);
  36039. }
  36040. void CodeEditorComponent::copyThenCut()
  36041. {
  36042. copy();
  36043. cut();
  36044. newTransaction();
  36045. }
  36046. void CodeEditorComponent::paste()
  36047. {
  36048. newTransaction();
  36049. const String clip (SystemClipboard::getTextFromClipboard());
  36050. if (clip.isNotEmpty())
  36051. insertTextAtCaret (clip);
  36052. newTransaction();
  36053. }
  36054. void CodeEditorComponent::cursorLeft (const bool moveInWholeWordSteps, const bool selecting)
  36055. {
  36056. newTransaction();
  36057. if (moveInWholeWordSteps)
  36058. moveCaretTo (document.findWordBreakBefore (caretPos), selecting);
  36059. else
  36060. moveCaretTo (caretPos.movedBy (-1), selecting);
  36061. }
  36062. void CodeEditorComponent::cursorRight (const bool moveInWholeWordSteps, const bool selecting)
  36063. {
  36064. newTransaction();
  36065. if (moveInWholeWordSteps)
  36066. moveCaretTo (document.findWordBreakAfter (caretPos), selecting);
  36067. else
  36068. moveCaretTo (caretPos.movedBy (1), selecting);
  36069. }
  36070. void CodeEditorComponent::moveLineDelta (const int delta, const bool selecting)
  36071. {
  36072. CodeDocument::Position pos (caretPos);
  36073. const int newLineNum = pos.getLineNumber() + delta;
  36074. if (columnToTryToMaintain < 0)
  36075. columnToTryToMaintain = indexToColumn (pos.getLineNumber(), pos.getIndexInLine());
  36076. pos.setLineAndIndex (newLineNum, columnToIndex (newLineNum, columnToTryToMaintain));
  36077. const int colToMaintain = columnToTryToMaintain;
  36078. moveCaretTo (pos, selecting);
  36079. columnToTryToMaintain = colToMaintain;
  36080. }
  36081. void CodeEditorComponent::cursorDown (const bool selecting)
  36082. {
  36083. newTransaction();
  36084. if (caretPos.getLineNumber() == document.getNumLines() - 1)
  36085. moveCaretTo (CodeDocument::Position (&document, std::numeric_limits<int>::max(), std::numeric_limits<int>::max()), selecting);
  36086. else
  36087. moveLineDelta (1, selecting);
  36088. }
  36089. void CodeEditorComponent::cursorUp (const bool selecting)
  36090. {
  36091. newTransaction();
  36092. if (caretPos.getLineNumber() == 0)
  36093. moveCaretTo (CodeDocument::Position (&document, 0, 0), selecting);
  36094. else
  36095. moveLineDelta (-1, selecting);
  36096. }
  36097. void CodeEditorComponent::pageDown (const bool selecting)
  36098. {
  36099. newTransaction();
  36100. scrollBy (jlimit (0, linesOnScreen, 1 + document.getNumLines() - firstLineOnScreen - linesOnScreen));
  36101. moveLineDelta (linesOnScreen, selecting);
  36102. }
  36103. void CodeEditorComponent::pageUp (const bool selecting)
  36104. {
  36105. newTransaction();
  36106. scrollBy (-linesOnScreen);
  36107. moveLineDelta (-linesOnScreen, selecting);
  36108. }
  36109. void CodeEditorComponent::scrollUp()
  36110. {
  36111. newTransaction();
  36112. scrollBy (1);
  36113. if (caretPos.getLineNumber() < firstLineOnScreen)
  36114. moveLineDelta (1, false);
  36115. }
  36116. void CodeEditorComponent::scrollDown()
  36117. {
  36118. newTransaction();
  36119. scrollBy (-1);
  36120. if (caretPos.getLineNumber() >= firstLineOnScreen + linesOnScreen)
  36121. moveLineDelta (-1, false);
  36122. }
  36123. void CodeEditorComponent::goToStartOfDocument (const bool selecting)
  36124. {
  36125. newTransaction();
  36126. moveCaretTo (CodeDocument::Position (&document, 0, 0), selecting);
  36127. }
  36128. static int findFirstNonWhitespaceChar (const String& line) throw()
  36129. {
  36130. const int len = line.length();
  36131. for (int i = 0; i < len; ++i)
  36132. if (! CharacterFunctions::isWhitespace (line [i]))
  36133. return i;
  36134. return 0;
  36135. }
  36136. void CodeEditorComponent::goToStartOfLine (const bool selecting)
  36137. {
  36138. newTransaction();
  36139. int index = findFirstNonWhitespaceChar (caretPos.getLineText());
  36140. if (index >= caretPos.getIndexInLine() && caretPos.getIndexInLine() > 0)
  36141. index = 0;
  36142. moveCaretTo (CodeDocument::Position (&document, caretPos.getLineNumber(), index), selecting);
  36143. }
  36144. void CodeEditorComponent::goToEndOfDocument (const bool selecting)
  36145. {
  36146. newTransaction();
  36147. moveCaretTo (CodeDocument::Position (&document, std::numeric_limits<int>::max(), std::numeric_limits<int>::max()), selecting);
  36148. }
  36149. void CodeEditorComponent::goToEndOfLine (const bool selecting)
  36150. {
  36151. newTransaction();
  36152. moveCaretTo (CodeDocument::Position (&document, caretPos.getLineNumber(), std::numeric_limits<int>::max()), selecting);
  36153. }
  36154. void CodeEditorComponent::backspace (const bool moveInWholeWordSteps)
  36155. {
  36156. if (moveInWholeWordSteps)
  36157. {
  36158. cut(); // in case something is already highlighted
  36159. moveCaretTo (document.findWordBreakBefore (caretPos), true);
  36160. }
  36161. else
  36162. {
  36163. if (selectionStart == selectionEnd)
  36164. selectionStart.moveBy (-1);
  36165. }
  36166. cut();
  36167. }
  36168. void CodeEditorComponent::deleteForward (const bool moveInWholeWordSteps)
  36169. {
  36170. if (moveInWholeWordSteps)
  36171. {
  36172. cut(); // in case something is already highlighted
  36173. moveCaretTo (document.findWordBreakAfter (caretPos), true);
  36174. }
  36175. else
  36176. {
  36177. if (selectionStart == selectionEnd)
  36178. selectionEnd.moveBy (1);
  36179. else
  36180. newTransaction();
  36181. }
  36182. cut();
  36183. }
  36184. void CodeEditorComponent::selectAll()
  36185. {
  36186. newTransaction();
  36187. moveCaretTo (CodeDocument::Position (&document, std::numeric_limits<int>::max(), std::numeric_limits<int>::max()), false);
  36188. moveCaretTo (CodeDocument::Position (&document, 0, 0), true);
  36189. }
  36190. void CodeEditorComponent::undo()
  36191. {
  36192. document.undo();
  36193. scrollToKeepCaretOnScreen();
  36194. }
  36195. void CodeEditorComponent::redo()
  36196. {
  36197. document.redo();
  36198. scrollToKeepCaretOnScreen();
  36199. }
  36200. void CodeEditorComponent::newTransaction()
  36201. {
  36202. document.newTransaction();
  36203. startTimer (600);
  36204. }
  36205. void CodeEditorComponent::timerCallback()
  36206. {
  36207. newTransaction();
  36208. }
  36209. const Range<int> CodeEditorComponent::getHighlightedRegion() const
  36210. {
  36211. return Range<int> (selectionStart.getPosition(), selectionEnd.getPosition());
  36212. }
  36213. void CodeEditorComponent::setHighlightedRegion (const Range<int>& newRange)
  36214. {
  36215. moveCaretTo (CodeDocument::Position (&document, newRange.getStart()), false);
  36216. moveCaretTo (CodeDocument::Position (&document, newRange.getEnd()), true);
  36217. }
  36218. const String CodeEditorComponent::getTextInRange (const Range<int>& range) const
  36219. {
  36220. return document.getTextBetween (CodeDocument::Position (&document, range.getStart()),
  36221. CodeDocument::Position (&document, range.getEnd()));
  36222. }
  36223. bool CodeEditorComponent::keyPressed (const KeyPress& key)
  36224. {
  36225. const bool moveInWholeWordSteps = key.getModifiers().isCtrlDown() || key.getModifiers().isAltDown();
  36226. const bool shiftDown = key.getModifiers().isShiftDown();
  36227. if (key.isKeyCode (KeyPress::leftKey))
  36228. {
  36229. cursorLeft (moveInWholeWordSteps, shiftDown);
  36230. }
  36231. else if (key.isKeyCode (KeyPress::rightKey))
  36232. {
  36233. cursorRight (moveInWholeWordSteps, shiftDown);
  36234. }
  36235. else if (key.isKeyCode (KeyPress::upKey))
  36236. {
  36237. if (key.getModifiers().isCtrlDown() && ! shiftDown)
  36238. scrollDown();
  36239. #if JUCE_MAC
  36240. else if (key.getModifiers().isCommandDown())
  36241. goToStartOfDocument (shiftDown);
  36242. #endif
  36243. else
  36244. cursorUp (shiftDown);
  36245. }
  36246. else if (key.isKeyCode (KeyPress::downKey))
  36247. {
  36248. if (key.getModifiers().isCtrlDown() && ! shiftDown)
  36249. scrollUp();
  36250. #if JUCE_MAC
  36251. else if (key.getModifiers().isCommandDown())
  36252. goToEndOfDocument (shiftDown);
  36253. #endif
  36254. else
  36255. cursorDown (shiftDown);
  36256. }
  36257. else if (key.isKeyCode (KeyPress::pageDownKey))
  36258. {
  36259. pageDown (shiftDown);
  36260. }
  36261. else if (key.isKeyCode (KeyPress::pageUpKey))
  36262. {
  36263. pageUp (shiftDown);
  36264. }
  36265. else if (key.isKeyCode (KeyPress::homeKey))
  36266. {
  36267. if (moveInWholeWordSteps)
  36268. goToStartOfDocument (shiftDown);
  36269. else
  36270. goToStartOfLine (shiftDown);
  36271. }
  36272. else if (key.isKeyCode (KeyPress::endKey))
  36273. {
  36274. if (moveInWholeWordSteps)
  36275. goToEndOfDocument (shiftDown);
  36276. else
  36277. goToEndOfLine (shiftDown);
  36278. }
  36279. else if (key.isKeyCode (KeyPress::backspaceKey))
  36280. {
  36281. backspace (moveInWholeWordSteps);
  36282. }
  36283. else if (key.isKeyCode (KeyPress::deleteKey))
  36284. {
  36285. deleteForward (moveInWholeWordSteps);
  36286. }
  36287. else if (key == KeyPress (T('c'), ModifierKeys::commandModifier, 0))
  36288. {
  36289. copy();
  36290. }
  36291. else if (key == KeyPress (T('x'), ModifierKeys::commandModifier, 0))
  36292. {
  36293. copyThenCut();
  36294. }
  36295. else if (key == KeyPress (T('v'), ModifierKeys::commandModifier, 0))
  36296. {
  36297. paste();
  36298. }
  36299. else if (key == KeyPress (T('z'), ModifierKeys::commandModifier, 0))
  36300. {
  36301. undo();
  36302. }
  36303. else if (key == KeyPress (T('y'), ModifierKeys::commandModifier, 0)
  36304. || key == KeyPress (T('z'), ModifierKeys::commandModifier | ModifierKeys::shiftModifier, 0))
  36305. {
  36306. redo();
  36307. }
  36308. else if (key == KeyPress (T('a'), ModifierKeys::commandModifier, 0))
  36309. {
  36310. selectAll();
  36311. }
  36312. else if (key == KeyPress::tabKey || key.getTextCharacter() == '\t')
  36313. {
  36314. insertTabAtCaret();
  36315. }
  36316. else if (key == KeyPress::returnKey)
  36317. {
  36318. newTransaction();
  36319. insertTextAtCaret (document.getNewLineCharacters());
  36320. }
  36321. else if (key.isKeyCode (KeyPress::escapeKey))
  36322. {
  36323. newTransaction();
  36324. }
  36325. else if (key.getTextCharacter() >= ' ')
  36326. {
  36327. insertTextAtCaret (String::charToString (key.getTextCharacter()));
  36328. }
  36329. else
  36330. {
  36331. return false;
  36332. }
  36333. return true;
  36334. }
  36335. void CodeEditorComponent::mouseDown (const MouseEvent& e)
  36336. {
  36337. newTransaction();
  36338. dragType = notDragging;
  36339. if (! e.mods.isPopupMenu())
  36340. {
  36341. beginDragAutoRepeat (100);
  36342. moveCaretTo (getPositionAt (e.x, e.y), e.mods.isShiftDown());
  36343. }
  36344. else
  36345. {
  36346. }
  36347. }
  36348. void CodeEditorComponent::mouseDrag (const MouseEvent& e)
  36349. {
  36350. if (! e.mods.isPopupMenu())
  36351. moveCaretTo (getPositionAt (e.x, e.y), true);
  36352. }
  36353. void CodeEditorComponent::mouseUp (const MouseEvent&)
  36354. {
  36355. newTransaction();
  36356. beginDragAutoRepeat (0);
  36357. dragType = notDragging;
  36358. }
  36359. void CodeEditorComponent::mouseDoubleClick (const MouseEvent& e)
  36360. {
  36361. CodeDocument::Position tokenStart (getPositionAt (e.x, e.y));
  36362. CodeDocument::Position tokenEnd (tokenStart);
  36363. if (e.getNumberOfClicks() > 2)
  36364. {
  36365. tokenStart.setLineAndIndex (tokenStart.getLineNumber(), 0);
  36366. tokenEnd.setLineAndIndex (tokenStart.getLineNumber() + 1, 0);
  36367. }
  36368. else
  36369. {
  36370. while (CharacterFunctions::isLetterOrDigit (tokenEnd.getCharacter()))
  36371. tokenEnd.moveBy (1);
  36372. tokenStart = tokenEnd;
  36373. while (tokenStart.getIndexInLine() > 0
  36374. && CharacterFunctions::isLetterOrDigit (tokenStart.movedBy (-1).getCharacter()))
  36375. tokenStart.moveBy (-1);
  36376. }
  36377. moveCaretTo (tokenEnd, false);
  36378. moveCaretTo (tokenStart, true);
  36379. }
  36380. void CodeEditorComponent::mouseWheelMove (const MouseEvent& e, float wheelIncrementX, float wheelIncrementY)
  36381. {
  36382. verticalScrollBar->mouseWheelMove (e, 0, wheelIncrementY);
  36383. horizontalScrollBar->mouseWheelMove (e, wheelIncrementX, 0);
  36384. }
  36385. void CodeEditorComponent::scrollBarMoved (ScrollBar* scrollBarThatHasMoved, double newRangeStart)
  36386. {
  36387. if (scrollBarThatHasMoved == verticalScrollBar)
  36388. scrollToLineInternal ((int) newRangeStart);
  36389. else
  36390. scrollToColumnInternal (newRangeStart);
  36391. }
  36392. void CodeEditorComponent::setTabSize (const int numSpaces, const bool insertSpaces) throw()
  36393. {
  36394. useSpacesForTabs = insertSpaces;
  36395. if (spacesPerTab != numSpaces)
  36396. {
  36397. spacesPerTab = numSpaces;
  36398. triggerAsyncUpdate();
  36399. }
  36400. }
  36401. int CodeEditorComponent::indexToColumn (int lineNum, int index) const throw()
  36402. {
  36403. const String line (document.getLine (lineNum));
  36404. jassert (index <= line.length());
  36405. int col = 0;
  36406. for (int i = 0; i < index; ++i)
  36407. {
  36408. if (line[i] != T('\t'))
  36409. ++col;
  36410. else
  36411. col += getTabSize() - (col % getTabSize());
  36412. }
  36413. return col;
  36414. }
  36415. int CodeEditorComponent::columnToIndex (int lineNum, int column) const throw()
  36416. {
  36417. const String line (document.getLine (lineNum));
  36418. const int lineLength = line.length();
  36419. int i, col = 0;
  36420. for (i = 0; i < lineLength; ++i)
  36421. {
  36422. if (line[i] != T('\t'))
  36423. ++col;
  36424. else
  36425. col += getTabSize() - (col % getTabSize());
  36426. if (col > column)
  36427. break;
  36428. }
  36429. return i;
  36430. }
  36431. void CodeEditorComponent::setFont (const Font& newFont)
  36432. {
  36433. font = newFont;
  36434. charWidth = font.getStringWidthFloat (T("0"));
  36435. lineHeight = roundToInt (font.getHeight());
  36436. resized();
  36437. }
  36438. void CodeEditorComponent::resetToDefaultColours()
  36439. {
  36440. coloursForTokenCategories.clear();
  36441. if (codeTokeniser != 0)
  36442. {
  36443. for (int i = codeTokeniser->getTokenTypes().size(); --i >= 0;)
  36444. setColourForTokenType (i, codeTokeniser->getDefaultColour (i));
  36445. }
  36446. }
  36447. void CodeEditorComponent::setColourForTokenType (const int tokenType, const Colour& colour)
  36448. {
  36449. jassert (tokenType < 256);
  36450. while (coloursForTokenCategories.size() < tokenType)
  36451. coloursForTokenCategories.add (Colours::black);
  36452. coloursForTokenCategories.set (tokenType, colour);
  36453. repaint();
  36454. }
  36455. const Colour CodeEditorComponent::getColourForTokenType (const int tokenType) const throw()
  36456. {
  36457. if (((unsigned int) tokenType) >= (unsigned int) coloursForTokenCategories.size())
  36458. return findColour (CodeEditorComponent::defaultTextColourId);
  36459. return coloursForTokenCategories.getReference (tokenType);
  36460. }
  36461. void CodeEditorComponent::clearCachedIterators (const int firstLineToBeInvalid) throw()
  36462. {
  36463. int i;
  36464. for (i = cachedIterators.size(); --i >= 0;)
  36465. if (cachedIterators.getUnchecked (i)->getLine() < firstLineToBeInvalid)
  36466. break;
  36467. cachedIterators.removeRange (jmax (0, i - 1), cachedIterators.size());
  36468. }
  36469. void CodeEditorComponent::updateCachedIterators (int maxLineNum)
  36470. {
  36471. const int maxNumCachedPositions = 5000;
  36472. const int linesBetweenCachedSources = jmax (10, document.getNumLines() / maxNumCachedPositions);
  36473. if (cachedIterators.size() == 0)
  36474. cachedIterators.add (new CodeDocument::Iterator (&document));
  36475. if (codeTokeniser == 0)
  36476. return;
  36477. for (;;)
  36478. {
  36479. CodeDocument::Iterator* last = cachedIterators.getLast();
  36480. if (last->getLine() >= maxLineNum)
  36481. break;
  36482. CodeDocument::Iterator* t = new CodeDocument::Iterator (*last);
  36483. cachedIterators.add (t);
  36484. const int targetLine = last->getLine() + linesBetweenCachedSources;
  36485. for (;;)
  36486. {
  36487. codeTokeniser->readNextToken (*t);
  36488. if (t->getLine() >= targetLine)
  36489. break;
  36490. if (t->isEOF())
  36491. return;
  36492. }
  36493. }
  36494. }
  36495. void CodeEditorComponent::getIteratorForPosition (int position, CodeDocument::Iterator& source)
  36496. {
  36497. if (codeTokeniser == 0)
  36498. return;
  36499. for (int i = cachedIterators.size(); --i >= 0;)
  36500. {
  36501. CodeDocument::Iterator* t = cachedIterators.getUnchecked (i);
  36502. if (t->getPosition() <= position)
  36503. {
  36504. source = *t;
  36505. break;
  36506. }
  36507. }
  36508. while (source.getPosition() < position)
  36509. {
  36510. const CodeDocument::Iterator original (source);
  36511. codeTokeniser->readNextToken (source);
  36512. if (source.getPosition() > position || source.isEOF())
  36513. {
  36514. source = original;
  36515. break;
  36516. }
  36517. }
  36518. }
  36519. END_JUCE_NAMESPACE
  36520. /*** End of inlined file: juce_CodeEditorComponent.cpp ***/
  36521. /*** Start of inlined file: juce_CPlusPlusCodeTokeniser.cpp ***/
  36522. BEGIN_JUCE_NAMESPACE
  36523. CPlusPlusCodeTokeniser::CPlusPlusCodeTokeniser()
  36524. {
  36525. }
  36526. CPlusPlusCodeTokeniser::~CPlusPlusCodeTokeniser()
  36527. {
  36528. }
  36529. namespace CppTokeniser
  36530. {
  36531. static bool isIdentifierStart (const tchar c) throw()
  36532. {
  36533. return CharacterFunctions::isLetter (c)
  36534. || c == T('_') || c == T('@');
  36535. }
  36536. static bool isIdentifierBody (const tchar c) throw()
  36537. {
  36538. return CharacterFunctions::isLetter (c)
  36539. || CharacterFunctions::isDigit (c)
  36540. || c == T('_') || c == T('@');
  36541. }
  36542. static int parseIdentifier (CodeDocument::Iterator& source) throw()
  36543. {
  36544. static const tchar* keywords2Char[] =
  36545. { T("if"), T("do"), T("or"), 0 };
  36546. static const tchar* keywords3Char[] =
  36547. { T("for"), T("int"), T("new"), T("try"), T("xor"), T("and"), T("asm"), T("not"), 0 };
  36548. static const tchar* keywords4Char[] =
  36549. { T("bool"), T("void"), T("this"), T("true"), T("long"), T("else"), T("char"),
  36550. T("enum"), T("case"), T("goto"), T("auto"), 0 };
  36551. static const tchar* keywords5Char[] =
  36552. { T("while"), T("bitor"), T("break"), T("catch"), T("class"), T("compl"), T("const"), T("false"),
  36553. T("float"), T("short"), T("throw"), T("union"), T("using"), T("or_eq"), 0 };
  36554. static const tchar* keywords6Char[] =
  36555. { T("return"), T("struct"), T("and_eq"), T("bitand"), T("delete"), T("double"), T("extern"),
  36556. T("friend"), T("inline"), T("not_eq"), T("public"), T("sizeof"), T("static"), T("signed"),
  36557. T("switch"), T("typeid"), T("wchar_t"), T("xor_eq"), 0};
  36558. static const tchar* keywordsOther[] =
  36559. { T("const_cast"), T("continue"), T("default"), T("explicit"), T("mutable"), T("namespace"),
  36560. T("operator"), T("private"), T("protected"), T("register"), T("reinterpret_cast"), T("static_cast"),
  36561. T("template"), T("typedef"), T("typename"), T("unsigned"), T("virtual"), T("volatile"),
  36562. T("@implementation"), T("@interface"), T("@end"), T("@synthesize"), T("@dynamic"), T("@public"),
  36563. T("@private"), T("@property"), T("@protected"), T("@class"), 0 };
  36564. int tokenLength = 0;
  36565. tchar possibleIdentifier [19];
  36566. while (isIdentifierBody (source.peekNextChar()))
  36567. {
  36568. const tchar c = source.nextChar();
  36569. if (tokenLength < numElementsInArray (possibleIdentifier) - 1)
  36570. possibleIdentifier [tokenLength] = c;
  36571. ++tokenLength;
  36572. }
  36573. if (tokenLength > 1 && tokenLength <= 16)
  36574. {
  36575. possibleIdentifier [tokenLength] = 0;
  36576. const tchar** k;
  36577. switch (tokenLength)
  36578. {
  36579. case 2: k = keywords2Char; break;
  36580. case 3: k = keywords3Char; break;
  36581. case 4: k = keywords4Char; break;
  36582. case 5: k = keywords5Char; break;
  36583. case 6: k = keywords6Char; break;
  36584. default: k = keywordsOther; break;
  36585. }
  36586. int i = 0;
  36587. while (k[i] != 0)
  36588. {
  36589. if (k[i][0] == possibleIdentifier[0] && CharacterFunctions::compare (k[i], possibleIdentifier) == 0)
  36590. return CPlusPlusCodeTokeniser::tokenType_builtInKeyword;
  36591. ++i;
  36592. }
  36593. }
  36594. return CPlusPlusCodeTokeniser::tokenType_identifier;
  36595. }
  36596. static bool skipNumberSuffix (CodeDocument::Iterator& source)
  36597. {
  36598. const juce_wchar c = source.peekNextChar();
  36599. if (c == 'l' || c == 'L' || c == 'u' || c == 'U')
  36600. source.skip();
  36601. if (CharacterFunctions::isLetterOrDigit (source.peekNextChar()))
  36602. return false;
  36603. return true;
  36604. }
  36605. static bool isHexDigit (const juce_wchar c) throw()
  36606. {
  36607. return (c >= '0' && c <= '9')
  36608. || (c >= 'a' && c <= 'f')
  36609. || (c >= 'A' && c <= 'F');
  36610. }
  36611. static bool parseHexLiteral (CodeDocument::Iterator& source) throw()
  36612. {
  36613. if (source.nextChar() != '0')
  36614. return false;
  36615. juce_wchar c = source.nextChar();
  36616. if (c != 'x' && c != 'X')
  36617. return false;
  36618. int numDigits = 0;
  36619. while (isHexDigit (source.peekNextChar()))
  36620. {
  36621. ++numDigits;
  36622. source.skip();
  36623. }
  36624. if (numDigits == 0)
  36625. return false;
  36626. return skipNumberSuffix (source);
  36627. }
  36628. static bool isOctalDigit (const juce_wchar c) throw()
  36629. {
  36630. return c >= '0' && c <= '7';
  36631. }
  36632. static bool parseOctalLiteral (CodeDocument::Iterator& source) throw()
  36633. {
  36634. if (source.nextChar() != '0')
  36635. return false;
  36636. if (! isOctalDigit (source.nextChar()))
  36637. return false;
  36638. while (isOctalDigit (source.peekNextChar()))
  36639. source.skip();
  36640. return skipNumberSuffix (source);
  36641. }
  36642. static bool isDecimalDigit (const juce_wchar c) throw()
  36643. {
  36644. return c >= '0' && c <= '9';
  36645. }
  36646. static bool parseDecimalLiteral (CodeDocument::Iterator& source) throw()
  36647. {
  36648. int numChars = 0;
  36649. while (isDecimalDigit (source.peekNextChar()))
  36650. {
  36651. ++numChars;
  36652. source.skip();
  36653. }
  36654. if (numChars == 0)
  36655. return false;
  36656. return skipNumberSuffix (source);
  36657. }
  36658. static bool parseFloatLiteral (CodeDocument::Iterator& source) throw()
  36659. {
  36660. int numDigits = 0;
  36661. while (isDecimalDigit (source.peekNextChar()))
  36662. {
  36663. source.skip();
  36664. ++numDigits;
  36665. }
  36666. const bool hasPoint = (source.peekNextChar() == '.');
  36667. if (hasPoint)
  36668. {
  36669. source.skip();
  36670. while (isDecimalDigit (source.peekNextChar()))
  36671. {
  36672. source.skip();
  36673. ++numDigits;
  36674. }
  36675. }
  36676. if (numDigits == 0)
  36677. return false;
  36678. juce_wchar c = source.peekNextChar();
  36679. const bool hasExponent = (c == 'e' || c == 'E');
  36680. if (hasExponent)
  36681. {
  36682. source.skip();
  36683. c = source.peekNextChar();
  36684. if (c == '+' || c == '-')
  36685. source.skip();
  36686. int numExpDigits = 0;
  36687. while (isDecimalDigit (source.peekNextChar()))
  36688. {
  36689. source.skip();
  36690. ++numExpDigits;
  36691. }
  36692. if (numExpDigits == 0)
  36693. return false;
  36694. }
  36695. c = source.peekNextChar();
  36696. if (c == 'f' || c == 'F')
  36697. source.skip();
  36698. else if (! (hasExponent || hasPoint))
  36699. return false;
  36700. return true;
  36701. }
  36702. static int parseNumber (CodeDocument::Iterator& source)
  36703. {
  36704. const CodeDocument::Iterator original (source);
  36705. if (parseFloatLiteral (source))
  36706. return CPlusPlusCodeTokeniser::tokenType_floatLiteral;
  36707. source = original;
  36708. if (parseHexLiteral (source))
  36709. return CPlusPlusCodeTokeniser::tokenType_integerLiteral;
  36710. source = original;
  36711. if (parseOctalLiteral (source))
  36712. return CPlusPlusCodeTokeniser::tokenType_integerLiteral;
  36713. source = original;
  36714. if (parseDecimalLiteral (source))
  36715. return CPlusPlusCodeTokeniser::tokenType_integerLiteral;
  36716. source = original;
  36717. source.skip();
  36718. return CPlusPlusCodeTokeniser::tokenType_error;
  36719. }
  36720. static void skipQuotedString (CodeDocument::Iterator& source) throw()
  36721. {
  36722. const juce_wchar quote = source.nextChar();
  36723. for (;;)
  36724. {
  36725. const juce_wchar c = source.nextChar();
  36726. if (c == quote || c == 0)
  36727. break;
  36728. if (c == '\\')
  36729. source.skip();
  36730. }
  36731. }
  36732. static void skipComment (CodeDocument::Iterator& source) throw()
  36733. {
  36734. bool lastWasStar = false;
  36735. for (;;)
  36736. {
  36737. const juce_wchar c = source.nextChar();
  36738. if (c == 0 || (c == T('/') && lastWasStar))
  36739. break;
  36740. lastWasStar = (c == '*');
  36741. }
  36742. }
  36743. }
  36744. int CPlusPlusCodeTokeniser::readNextToken (CodeDocument::Iterator& source)
  36745. {
  36746. int result = tokenType_error;
  36747. source.skipWhitespace();
  36748. tchar firstChar = source.peekNextChar();
  36749. switch (firstChar)
  36750. {
  36751. case 0:
  36752. source.skip();
  36753. break;
  36754. case T('0'):
  36755. case T('1'):
  36756. case T('2'):
  36757. case T('3'):
  36758. case T('4'):
  36759. case T('5'):
  36760. case T('6'):
  36761. case T('7'):
  36762. case T('8'):
  36763. case T('9'):
  36764. result = CppTokeniser::parseNumber (source);
  36765. break;
  36766. case T('.'):
  36767. result = CppTokeniser::parseNumber (source);
  36768. if (result == tokenType_error)
  36769. result = tokenType_punctuation;
  36770. break;
  36771. case T(','):
  36772. case T(';'):
  36773. case T(':'):
  36774. source.skip();
  36775. result = tokenType_punctuation;
  36776. break;
  36777. case T('('):
  36778. case T(')'):
  36779. case T('{'):
  36780. case T('}'):
  36781. case T('['):
  36782. case T(']'):
  36783. source.skip();
  36784. result = tokenType_bracket;
  36785. break;
  36786. case T('"'):
  36787. case T('\''):
  36788. CppTokeniser::skipQuotedString (source);
  36789. result = tokenType_stringLiteral;
  36790. break;
  36791. case T('+'):
  36792. result = tokenType_operator;
  36793. source.skip();
  36794. if (source.peekNextChar() == T('+'))
  36795. source.skip();
  36796. else if (source.peekNextChar() == T('='))
  36797. source.skip();
  36798. break;
  36799. case T('-'):
  36800. source.skip();
  36801. result = CppTokeniser::parseNumber (source);
  36802. if (result == tokenType_error)
  36803. {
  36804. result = tokenType_operator;
  36805. if (source.peekNextChar() == T('-'))
  36806. source.skip();
  36807. else if (source.peekNextChar() == T('='))
  36808. source.skip();
  36809. }
  36810. break;
  36811. case T('*'):
  36812. case T('%'):
  36813. case T('='):
  36814. case T('!'):
  36815. result = tokenType_operator;
  36816. source.skip();
  36817. if (source.peekNextChar() == T('='))
  36818. source.skip();
  36819. break;
  36820. case T('/'):
  36821. result = tokenType_operator;
  36822. source.skip();
  36823. if (source.peekNextChar() == T('='))
  36824. {
  36825. source.skip();
  36826. }
  36827. else if (source.peekNextChar() == T('/'))
  36828. {
  36829. result = tokenType_comment;
  36830. source.skipToEndOfLine();
  36831. }
  36832. else if (source.peekNextChar() == T('*'))
  36833. {
  36834. source.skip();
  36835. result = tokenType_comment;
  36836. CppTokeniser::skipComment (source);
  36837. }
  36838. break;
  36839. case T('?'):
  36840. case T('~'):
  36841. source.skip();
  36842. result = tokenType_operator;
  36843. break;
  36844. case T('<'):
  36845. source.skip();
  36846. result = tokenType_operator;
  36847. if (source.peekNextChar() == T('='))
  36848. {
  36849. source.skip();
  36850. }
  36851. else if (source.peekNextChar() == T('<'))
  36852. {
  36853. source.skip();
  36854. if (source.peekNextChar() == T('='))
  36855. source.skip();
  36856. }
  36857. break;
  36858. case T('>'):
  36859. source.skip();
  36860. result = tokenType_operator;
  36861. if (source.peekNextChar() == T('='))
  36862. {
  36863. source.skip();
  36864. }
  36865. else if (source.peekNextChar() == T('<'))
  36866. {
  36867. source.skip();
  36868. if (source.peekNextChar() == T('='))
  36869. source.skip();
  36870. }
  36871. break;
  36872. case T('|'):
  36873. source.skip();
  36874. result = tokenType_operator;
  36875. if (source.peekNextChar() == T('='))
  36876. {
  36877. source.skip();
  36878. }
  36879. else if (source.peekNextChar() == T('|'))
  36880. {
  36881. source.skip();
  36882. if (source.peekNextChar() == T('='))
  36883. source.skip();
  36884. }
  36885. break;
  36886. case T('&'):
  36887. source.skip();
  36888. result = tokenType_operator;
  36889. if (source.peekNextChar() == T('='))
  36890. {
  36891. source.skip();
  36892. }
  36893. else if (source.peekNextChar() == T('&'))
  36894. {
  36895. source.skip();
  36896. if (source.peekNextChar() == T('='))
  36897. source.skip();
  36898. }
  36899. break;
  36900. case T('^'):
  36901. source.skip();
  36902. result = tokenType_operator;
  36903. if (source.peekNextChar() == T('='))
  36904. {
  36905. source.skip();
  36906. }
  36907. else if (source.peekNextChar() == T('^'))
  36908. {
  36909. source.skip();
  36910. if (source.peekNextChar() == T('='))
  36911. source.skip();
  36912. }
  36913. break;
  36914. case T('#'):
  36915. result = tokenType_preprocessor;
  36916. source.skipToEndOfLine();
  36917. break;
  36918. default:
  36919. if (CppTokeniser::isIdentifierStart (firstChar))
  36920. result = CppTokeniser::parseIdentifier (source);
  36921. else
  36922. source.skip();
  36923. break;
  36924. }
  36925. //jassert (result != tokenType_unknown);
  36926. return result;
  36927. }
  36928. const StringArray CPlusPlusCodeTokeniser::getTokenTypes()
  36929. {
  36930. StringArray s;
  36931. s.add ("Error");
  36932. s.add ("Comment");
  36933. s.add ("C++ keyword");
  36934. s.add ("Identifier");
  36935. s.add ("Integer literal");
  36936. s.add ("Float literal");
  36937. s.add ("String literal");
  36938. s.add ("Operator");
  36939. s.add ("Bracket");
  36940. s.add ("Punctuation");
  36941. s.add ("Preprocessor line");
  36942. return s;
  36943. }
  36944. const Colour CPlusPlusCodeTokeniser::getDefaultColour (const int tokenType)
  36945. {
  36946. const uint32 colours[] =
  36947. {
  36948. 0xffcc0000, // error
  36949. 0xff00aa00, // comment
  36950. 0xff0000cc, // keyword
  36951. 0xff000000, // identifier
  36952. 0xff880000, // int literal
  36953. 0xff885500, // float literal
  36954. 0xff990099, // string literal
  36955. 0xff225500, // operator
  36956. 0xff000055, // bracket
  36957. 0xff004400, // punctuation
  36958. 0xff660000 // preprocessor
  36959. };
  36960. if (tokenType >= 0 && tokenType < numElementsInArray (colours))
  36961. return Colour (colours [tokenType]);
  36962. return Colours::black;
  36963. }
  36964. END_JUCE_NAMESPACE
  36965. /*** End of inlined file: juce_CPlusPlusCodeTokeniser.cpp ***/
  36966. /*** Start of inlined file: juce_ComboBox.cpp ***/
  36967. BEGIN_JUCE_NAMESPACE
  36968. ComboBox::ComboBox (const String& name)
  36969. : Component (name),
  36970. lastCurrentId (0),
  36971. isButtonDown (false),
  36972. separatorPending (false),
  36973. menuActive (false),
  36974. label (0)
  36975. {
  36976. noChoicesMessage = TRANS("(no choices)");
  36977. setRepaintsOnMouseActivity (true);
  36978. lookAndFeelChanged();
  36979. currentId.addListener (this);
  36980. }
  36981. ComboBox::~ComboBox()
  36982. {
  36983. currentId.removeListener (this);
  36984. if (menuActive)
  36985. PopupMenu::dismissAllActiveMenus();
  36986. label = 0;
  36987. deleteAllChildren();
  36988. }
  36989. void ComboBox::setEditableText (const bool isEditable)
  36990. {
  36991. label->setEditable (isEditable, isEditable, false);
  36992. setWantsKeyboardFocus (! isEditable);
  36993. resized();
  36994. }
  36995. bool ComboBox::isTextEditable() const throw()
  36996. {
  36997. return label->isEditable();
  36998. }
  36999. void ComboBox::setJustificationType (const Justification& justification) throw()
  37000. {
  37001. label->setJustificationType (justification);
  37002. }
  37003. const Justification ComboBox::getJustificationType() const throw()
  37004. {
  37005. return label->getJustificationType();
  37006. }
  37007. void ComboBox::setTooltip (const String& newTooltip)
  37008. {
  37009. SettableTooltipClient::setTooltip (newTooltip);
  37010. label->setTooltip (newTooltip);
  37011. }
  37012. void ComboBox::addItem (const String& newItemText,
  37013. const int newItemId) throw()
  37014. {
  37015. // you can't add empty strings to the list..
  37016. jassert (newItemText.isNotEmpty());
  37017. // IDs must be non-zero, as zero is used to indicate a lack of selecion.
  37018. jassert (newItemId != 0);
  37019. // you shouldn't use duplicate item IDs!
  37020. jassert (getItemForId (newItemId) == 0);
  37021. if (newItemText.isNotEmpty() && newItemId != 0)
  37022. {
  37023. if (separatorPending)
  37024. {
  37025. separatorPending = false;
  37026. ItemInfo* const item = new ItemInfo();
  37027. item->itemId = 0;
  37028. item->isEnabled = false;
  37029. item->isHeading = false;
  37030. items.add (item);
  37031. }
  37032. ItemInfo* const item = new ItemInfo();
  37033. item->name = newItemText;
  37034. item->itemId = newItemId;
  37035. item->isEnabled = true;
  37036. item->isHeading = false;
  37037. items.add (item);
  37038. }
  37039. }
  37040. void ComboBox::addSeparator() throw()
  37041. {
  37042. separatorPending = (items.size() > 0);
  37043. }
  37044. void ComboBox::addSectionHeading (const String& headingName) throw()
  37045. {
  37046. // you can't add empty strings to the list..
  37047. jassert (headingName.isNotEmpty());
  37048. if (headingName.isNotEmpty())
  37049. {
  37050. if (separatorPending)
  37051. {
  37052. separatorPending = false;
  37053. ItemInfo* const item = new ItemInfo();
  37054. item->itemId = 0;
  37055. item->isEnabled = false;
  37056. item->isHeading = false;
  37057. items.add (item);
  37058. }
  37059. ItemInfo* const item = new ItemInfo();
  37060. item->name = headingName;
  37061. item->itemId = 0;
  37062. item->isEnabled = true;
  37063. item->isHeading = true;
  37064. items.add (item);
  37065. }
  37066. }
  37067. void ComboBox::setItemEnabled (const int itemId,
  37068. const bool shouldBeEnabled) throw()
  37069. {
  37070. ItemInfo* const item = getItemForId (itemId);
  37071. if (item != 0)
  37072. item->isEnabled = shouldBeEnabled;
  37073. }
  37074. void ComboBox::changeItemText (const int itemId,
  37075. const String& newText) throw()
  37076. {
  37077. ItemInfo* const item = getItemForId (itemId);
  37078. jassert (item != 0);
  37079. if (item != 0)
  37080. item->name = newText;
  37081. }
  37082. void ComboBox::clear (const bool dontSendChangeMessage)
  37083. {
  37084. items.clear();
  37085. separatorPending = false;
  37086. if (! label->isEditable())
  37087. setSelectedItemIndex (-1, dontSendChangeMessage);
  37088. }
  37089. bool ComboBox::ItemInfo::isSeparator() const throw()
  37090. {
  37091. return name.isEmpty();
  37092. }
  37093. bool ComboBox::ItemInfo::isRealItem() const throw()
  37094. {
  37095. return ! (isHeading || name.isEmpty());
  37096. }
  37097. ComboBox::ItemInfo* ComboBox::getItemForId (const int itemId) const throw()
  37098. {
  37099. if (itemId != 0)
  37100. {
  37101. for (int i = items.size(); --i >= 0;)
  37102. if (items.getUnchecked(i)->itemId == itemId)
  37103. return items.getUnchecked(i);
  37104. }
  37105. return 0;
  37106. }
  37107. ComboBox::ItemInfo* ComboBox::getItemForIndex (const int index) const throw()
  37108. {
  37109. int n = 0;
  37110. for (int i = 0; i < items.size(); ++i)
  37111. {
  37112. ItemInfo* const item = items.getUnchecked(i);
  37113. if (item->isRealItem())
  37114. if (n++ == index)
  37115. return item;
  37116. }
  37117. return 0;
  37118. }
  37119. int ComboBox::getNumItems() const throw()
  37120. {
  37121. int n = 0;
  37122. for (int i = items.size(); --i >= 0;)
  37123. if (items.getUnchecked(i)->isRealItem())
  37124. ++n;
  37125. return n;
  37126. }
  37127. const String ComboBox::getItemText (const int index) const throw()
  37128. {
  37129. const ItemInfo* const item = getItemForIndex (index);
  37130. if (item != 0)
  37131. return item->name;
  37132. return String::empty;
  37133. }
  37134. int ComboBox::getItemId (const int index) const throw()
  37135. {
  37136. const ItemInfo* const item = getItemForIndex (index);
  37137. return (item != 0) ? item->itemId : 0;
  37138. }
  37139. int ComboBox::indexOfItemId (const int itemId) const throw()
  37140. {
  37141. int n = 0;
  37142. for (int i = 0; i < items.size(); ++i)
  37143. {
  37144. const ItemInfo* const item = items.getUnchecked(i);
  37145. if (item->isRealItem())
  37146. {
  37147. if (item->itemId == itemId)
  37148. return n;
  37149. ++n;
  37150. }
  37151. }
  37152. return -1;
  37153. }
  37154. int ComboBox::getSelectedItemIndex() const throw()
  37155. {
  37156. int index = indexOfItemId (currentId.getValue());
  37157. if (getText() != getItemText (index))
  37158. index = -1;
  37159. return index;
  37160. }
  37161. void ComboBox::setSelectedItemIndex (const int index,
  37162. const bool dontSendChangeMessage) throw()
  37163. {
  37164. setSelectedId (getItemId (index), dontSendChangeMessage);
  37165. }
  37166. int ComboBox::getSelectedId() const throw()
  37167. {
  37168. const ItemInfo* const item = getItemForId (currentId.getValue());
  37169. return (item != 0 && getText() == item->name)
  37170. ? item->itemId
  37171. : 0;
  37172. }
  37173. void ComboBox::setSelectedId (const int newItemId,
  37174. const bool dontSendChangeMessage) throw()
  37175. {
  37176. const ItemInfo* const item = getItemForId (newItemId);
  37177. const String newItemText (item != 0 ? item->name : String::empty);
  37178. if (lastCurrentId != newItemId || label->getText() != newItemText)
  37179. {
  37180. if (! dontSendChangeMessage)
  37181. triggerAsyncUpdate();
  37182. label->setText (newItemText, false);
  37183. lastCurrentId = newItemId;
  37184. currentId = newItemId;
  37185. repaint(); // for the benefit of the 'none selected' text
  37186. }
  37187. }
  37188. void ComboBox::valueChanged (Value&)
  37189. {
  37190. if (lastCurrentId != (int) currentId.getValue())
  37191. setSelectedId (currentId.getValue(), false);
  37192. }
  37193. const String ComboBox::getText() const throw()
  37194. {
  37195. return label->getText();
  37196. }
  37197. void ComboBox::setText (const String& newText,
  37198. const bool dontSendChangeMessage) throw()
  37199. {
  37200. for (int i = items.size(); --i >= 0;)
  37201. {
  37202. const ItemInfo* const item = items.getUnchecked(i);
  37203. if (item->isRealItem()
  37204. && item->name == newText)
  37205. {
  37206. setSelectedId (item->itemId, dontSendChangeMessage);
  37207. return;
  37208. }
  37209. }
  37210. lastCurrentId = 0;
  37211. currentId = 0;
  37212. if (label->getText() != newText)
  37213. {
  37214. label->setText (newText, false);
  37215. if (! dontSendChangeMessage)
  37216. triggerAsyncUpdate();
  37217. }
  37218. repaint();
  37219. }
  37220. void ComboBox::showEditor()
  37221. {
  37222. jassert (isTextEditable()); // you probably shouldn't do this to a non-editable combo box?
  37223. label->showEditor();
  37224. }
  37225. void ComboBox::setTextWhenNothingSelected (const String& newMessage) throw()
  37226. {
  37227. textWhenNothingSelected = newMessage;
  37228. repaint();
  37229. }
  37230. const String ComboBox::getTextWhenNothingSelected() const throw()
  37231. {
  37232. return textWhenNothingSelected;
  37233. }
  37234. void ComboBox::setTextWhenNoChoicesAvailable (const String& newMessage) throw()
  37235. {
  37236. noChoicesMessage = newMessage;
  37237. }
  37238. const String ComboBox::getTextWhenNoChoicesAvailable() const throw()
  37239. {
  37240. return noChoicesMessage;
  37241. }
  37242. void ComboBox::paint (Graphics& g)
  37243. {
  37244. getLookAndFeel().drawComboBox (g,
  37245. getWidth(),
  37246. getHeight(),
  37247. isButtonDown,
  37248. label->getRight(),
  37249. 0,
  37250. getWidth() - label->getRight(),
  37251. getHeight(),
  37252. *this);
  37253. if (textWhenNothingSelected.isNotEmpty()
  37254. && label->getText().isEmpty()
  37255. && ! label->isBeingEdited())
  37256. {
  37257. g.setColour (findColour (textColourId).withMultipliedAlpha (0.5f));
  37258. g.setFont (label->getFont());
  37259. g.drawFittedText (textWhenNothingSelected,
  37260. label->getX() + 2, label->getY() + 1,
  37261. label->getWidth() - 4, label->getHeight() - 2,
  37262. label->getJustificationType(),
  37263. jmax (1, (int) (label->getHeight() / label->getFont().getHeight())));
  37264. }
  37265. }
  37266. void ComboBox::resized()
  37267. {
  37268. if (getHeight() > 0 && getWidth() > 0)
  37269. getLookAndFeel().positionComboBoxText (*this, *label);
  37270. }
  37271. void ComboBox::enablementChanged()
  37272. {
  37273. repaint();
  37274. }
  37275. void ComboBox::lookAndFeelChanged()
  37276. {
  37277. repaint();
  37278. Label* const newLabel = getLookAndFeel().createComboBoxTextBox (*this);
  37279. if (label != 0)
  37280. {
  37281. newLabel->setEditable (label->isEditable());
  37282. newLabel->setJustificationType (label->getJustificationType());
  37283. newLabel->setTooltip (label->getTooltip());
  37284. newLabel->setText (label->getText(), false);
  37285. }
  37286. label = newLabel;
  37287. addAndMakeVisible (newLabel);
  37288. newLabel->addListener (this);
  37289. newLabel->addMouseListener (this, false);
  37290. newLabel->setColour (Label::backgroundColourId, Colours::transparentBlack);
  37291. newLabel->setColour (Label::textColourId, findColour (ComboBox::textColourId));
  37292. newLabel->setColour (TextEditor::textColourId, findColour (ComboBox::textColourId));
  37293. newLabel->setColour (TextEditor::backgroundColourId, Colours::transparentBlack);
  37294. newLabel->setColour (TextEditor::highlightColourId, findColour (TextEditor::highlightColourId));
  37295. newLabel->setColour (TextEditor::outlineColourId, Colours::transparentBlack);
  37296. resized();
  37297. }
  37298. void ComboBox::colourChanged()
  37299. {
  37300. lookAndFeelChanged();
  37301. }
  37302. bool ComboBox::keyPressed (const KeyPress& key)
  37303. {
  37304. bool used = false;
  37305. if (key.isKeyCode (KeyPress::upKey)
  37306. || key.isKeyCode (KeyPress::leftKey))
  37307. {
  37308. setSelectedItemIndex (jmax (0, getSelectedItemIndex() - 1));
  37309. used = true;
  37310. }
  37311. else if (key.isKeyCode (KeyPress::downKey)
  37312. || key.isKeyCode (KeyPress::rightKey))
  37313. {
  37314. setSelectedItemIndex (jmin (getSelectedItemIndex() + 1, getNumItems() - 1));
  37315. used = true;
  37316. }
  37317. else if (key.isKeyCode (KeyPress::returnKey))
  37318. {
  37319. showPopup();
  37320. used = true;
  37321. }
  37322. return used;
  37323. }
  37324. bool ComboBox::keyStateChanged (const bool isKeyDown)
  37325. {
  37326. // only forward key events that aren't used by this component
  37327. return isKeyDown
  37328. && (KeyPress::isKeyCurrentlyDown (KeyPress::upKey)
  37329. || KeyPress::isKeyCurrentlyDown (KeyPress::leftKey)
  37330. || KeyPress::isKeyCurrentlyDown (KeyPress::downKey)
  37331. || KeyPress::isKeyCurrentlyDown (KeyPress::rightKey));
  37332. }
  37333. void ComboBox::focusGained (FocusChangeType)
  37334. {
  37335. repaint();
  37336. }
  37337. void ComboBox::focusLost (FocusChangeType)
  37338. {
  37339. repaint();
  37340. }
  37341. void ComboBox::labelTextChanged (Label*)
  37342. {
  37343. triggerAsyncUpdate();
  37344. }
  37345. void ComboBox::showPopup()
  37346. {
  37347. if (! menuActive)
  37348. {
  37349. const int selectedId = getSelectedId();
  37350. Component::SafePointer<Component> deletionWatcher (this);
  37351. PopupMenu menu;
  37352. menu.setLookAndFeel (&getLookAndFeel());
  37353. for (int i = 0; i < items.size(); ++i)
  37354. {
  37355. const ItemInfo* const item = items.getUnchecked(i);
  37356. if (item->isSeparator())
  37357. menu.addSeparator();
  37358. else if (item->isHeading)
  37359. menu.addSectionHeader (item->name);
  37360. else
  37361. menu.addItem (item->itemId, item->name,
  37362. item->isEnabled, item->itemId == selectedId);
  37363. }
  37364. if (items.size() == 0)
  37365. menu.addItem (1, noChoicesMessage, false);
  37366. const int itemHeight = jlimit (12, 24, getHeight());
  37367. menuActive = true;
  37368. const int resultId = menu.showAt (this, selectedId,
  37369. getWidth(), 1, itemHeight);
  37370. if (deletionWatcher == 0)
  37371. return;
  37372. menuActive = false;
  37373. if (resultId != 0)
  37374. setSelectedId (resultId);
  37375. }
  37376. }
  37377. void ComboBox::mouseDown (const MouseEvent& e)
  37378. {
  37379. beginDragAutoRepeat (300);
  37380. isButtonDown = isEnabled();
  37381. if (isButtonDown
  37382. && (e.eventComponent == this || ! label->isEditable()))
  37383. {
  37384. showPopup();
  37385. }
  37386. }
  37387. void ComboBox::mouseDrag (const MouseEvent& e)
  37388. {
  37389. beginDragAutoRepeat (50);
  37390. if (isButtonDown && ! e.mouseWasClicked())
  37391. showPopup();
  37392. }
  37393. void ComboBox::mouseUp (const MouseEvent& e2)
  37394. {
  37395. if (isButtonDown)
  37396. {
  37397. isButtonDown = false;
  37398. repaint();
  37399. const MouseEvent e (e2.getEventRelativeTo (this));
  37400. if (reallyContains (e.x, e.y, true)
  37401. && (e2.eventComponent == this || ! label->isEditable()))
  37402. {
  37403. showPopup();
  37404. }
  37405. }
  37406. }
  37407. void ComboBox::addListener (ComboBoxListener* const listener) throw()
  37408. {
  37409. listeners.add (listener);
  37410. }
  37411. void ComboBox::removeListener (ComboBoxListener* const listener) throw()
  37412. {
  37413. listeners.remove (listener);
  37414. }
  37415. void ComboBox::handleAsyncUpdate()
  37416. {
  37417. Component::BailOutChecker checker (this);
  37418. listeners.callChecked (checker, &ComboBoxListener::comboBoxChanged, this);
  37419. }
  37420. END_JUCE_NAMESPACE
  37421. /*** End of inlined file: juce_ComboBox.cpp ***/
  37422. /*** Start of inlined file: juce_Label.cpp ***/
  37423. BEGIN_JUCE_NAMESPACE
  37424. Label::Label (const String& componentName,
  37425. const String& labelText)
  37426. : Component (componentName),
  37427. textValue (labelText),
  37428. lastTextValue (labelText),
  37429. font (15.0f),
  37430. justification (Justification::centredLeft),
  37431. ownerComponent (0),
  37432. horizontalBorderSize (5),
  37433. verticalBorderSize (1),
  37434. minimumHorizontalScale (0.7f),
  37435. editSingleClick (false),
  37436. editDoubleClick (false),
  37437. lossOfFocusDiscardsChanges (false)
  37438. {
  37439. setColour (TextEditor::textColourId, Colours::black);
  37440. setColour (TextEditor::backgroundColourId, Colours::transparentBlack);
  37441. setColour (TextEditor::outlineColourId, Colours::transparentBlack);
  37442. textValue.addListener (this);
  37443. }
  37444. Label::~Label()
  37445. {
  37446. textValue.removeListener (this);
  37447. if (ownerComponent != 0)
  37448. ownerComponent->removeComponentListener (this);
  37449. editor = 0;
  37450. }
  37451. void Label::setText (const String& newText,
  37452. const bool broadcastChangeMessage)
  37453. {
  37454. hideEditor (true);
  37455. if (lastTextValue != newText)
  37456. {
  37457. lastTextValue = newText;
  37458. textValue = newText;
  37459. repaint();
  37460. textWasChanged();
  37461. if (ownerComponent != 0)
  37462. componentMovedOrResized (*ownerComponent, true, true);
  37463. if (broadcastChangeMessage)
  37464. callChangeListeners();
  37465. }
  37466. }
  37467. const String Label::getText (const bool returnActiveEditorContents) const throw()
  37468. {
  37469. return (returnActiveEditorContents && isBeingEdited())
  37470. ? editor->getText()
  37471. : textValue.toString();
  37472. }
  37473. void Label::valueChanged (Value&)
  37474. {
  37475. if (lastTextValue != textValue.toString())
  37476. setText (textValue.toString(), true);
  37477. }
  37478. void Label::setFont (const Font& newFont) throw()
  37479. {
  37480. font = newFont;
  37481. repaint();
  37482. }
  37483. const Font& Label::getFont() const throw()
  37484. {
  37485. return font;
  37486. }
  37487. void Label::setEditable (const bool editOnSingleClick,
  37488. const bool editOnDoubleClick,
  37489. const bool lossOfFocusDiscardsChanges_) throw()
  37490. {
  37491. editSingleClick = editOnSingleClick;
  37492. editDoubleClick = editOnDoubleClick;
  37493. lossOfFocusDiscardsChanges = lossOfFocusDiscardsChanges_;
  37494. setWantsKeyboardFocus (editOnSingleClick || editOnDoubleClick);
  37495. setFocusContainer (editOnSingleClick || editOnDoubleClick);
  37496. }
  37497. void Label::setJustificationType (const Justification& justification_) throw()
  37498. {
  37499. justification = justification_;
  37500. repaint();
  37501. }
  37502. void Label::setBorderSize (int h, int v)
  37503. {
  37504. horizontalBorderSize = h;
  37505. verticalBorderSize = v;
  37506. repaint();
  37507. }
  37508. Component* Label::getAttachedComponent() const
  37509. {
  37510. return static_cast<Component*> (ownerComponent);
  37511. }
  37512. void Label::attachToComponent (Component* owner,
  37513. const bool onLeft)
  37514. {
  37515. if (ownerComponent != 0)
  37516. ownerComponent->removeComponentListener (this);
  37517. ownerComponent = owner;
  37518. leftOfOwnerComp = onLeft;
  37519. if (ownerComponent != 0)
  37520. {
  37521. setVisible (owner->isVisible());
  37522. ownerComponent->addComponentListener (this);
  37523. componentParentHierarchyChanged (*ownerComponent);
  37524. componentMovedOrResized (*ownerComponent, true, true);
  37525. }
  37526. }
  37527. void Label::componentMovedOrResized (Component& component,
  37528. bool /*wasMoved*/,
  37529. bool /*wasResized*/)
  37530. {
  37531. if (leftOfOwnerComp)
  37532. {
  37533. setSize (jmin (getFont().getStringWidth (textValue.toString()) + 8, component.getX()),
  37534. component.getHeight());
  37535. setTopRightPosition (component.getX(), component.getY());
  37536. }
  37537. else
  37538. {
  37539. setSize (component.getWidth(),
  37540. 8 + roundToInt (getFont().getHeight()));
  37541. setTopLeftPosition (component.getX(), component.getY() - getHeight());
  37542. }
  37543. }
  37544. void Label::componentParentHierarchyChanged (Component& component)
  37545. {
  37546. if (component.getParentComponent() != 0)
  37547. component.getParentComponent()->addChildComponent (this);
  37548. }
  37549. void Label::componentVisibilityChanged (Component& component)
  37550. {
  37551. setVisible (component.isVisible());
  37552. }
  37553. void Label::textWasEdited()
  37554. {
  37555. }
  37556. void Label::textWasChanged()
  37557. {
  37558. }
  37559. void Label::showEditor()
  37560. {
  37561. if (editor == 0)
  37562. {
  37563. addAndMakeVisible (editor = createEditorComponent());
  37564. editor->setText (getText(), false);
  37565. editor->addListener (this);
  37566. editor->grabKeyboardFocus();
  37567. editor->setHighlightedRegion (Range<int> (0, textValue.toString().length()));
  37568. editor->addListener (this);
  37569. resized();
  37570. repaint();
  37571. editorShown (editor);
  37572. enterModalState();
  37573. editor->grabKeyboardFocus();
  37574. }
  37575. }
  37576. void Label::editorShown (TextEditor* /*editorComponent*/)
  37577. {
  37578. }
  37579. void Label::editorAboutToBeHidden (TextEditor* /*editorComponent*/)
  37580. {
  37581. }
  37582. bool Label::updateFromTextEditorContents()
  37583. {
  37584. jassert (editor != 0);
  37585. const String newText (editor->getText());
  37586. if (textValue.toString() != newText)
  37587. {
  37588. lastTextValue = newText;
  37589. textValue = newText;
  37590. repaint();
  37591. textWasChanged();
  37592. if (ownerComponent != 0)
  37593. componentMovedOrResized (*ownerComponent, true, true);
  37594. return true;
  37595. }
  37596. return false;
  37597. }
  37598. void Label::hideEditor (const bool discardCurrentEditorContents)
  37599. {
  37600. if (editor != 0)
  37601. {
  37602. Component::SafePointer<Component> deletionChecker (this);
  37603. editorAboutToBeHidden (editor);
  37604. const bool changed = (! discardCurrentEditorContents)
  37605. && updateFromTextEditorContents();
  37606. editor = 0;
  37607. repaint();
  37608. if (changed)
  37609. textWasEdited();
  37610. if (deletionChecker != 0)
  37611. exitModalState (0);
  37612. if (changed && deletionChecker != 0)
  37613. callChangeListeners();
  37614. }
  37615. }
  37616. void Label::inputAttemptWhenModal()
  37617. {
  37618. if (editor != 0)
  37619. {
  37620. if (lossOfFocusDiscardsChanges)
  37621. textEditorEscapeKeyPressed (*editor);
  37622. else
  37623. textEditorReturnKeyPressed (*editor);
  37624. }
  37625. }
  37626. bool Label::isBeingEdited() const throw()
  37627. {
  37628. return editor != 0;
  37629. }
  37630. TextEditor* Label::createEditorComponent()
  37631. {
  37632. TextEditor* const ed = new TextEditor (getName());
  37633. ed->setFont (font);
  37634. // copy these colours from our own settings..
  37635. const int cols[] = { TextEditor::backgroundColourId,
  37636. TextEditor::textColourId,
  37637. TextEditor::highlightColourId,
  37638. TextEditor::highlightedTextColourId,
  37639. TextEditor::caretColourId,
  37640. TextEditor::outlineColourId,
  37641. TextEditor::focusedOutlineColourId,
  37642. TextEditor::shadowColourId };
  37643. for (int i = 0; i < numElementsInArray (cols); ++i)
  37644. ed->setColour (cols[i], findColour (cols[i]));
  37645. return ed;
  37646. }
  37647. void Label::paint (Graphics& g)
  37648. {
  37649. getLookAndFeel().drawLabel (g, *this);
  37650. }
  37651. void Label::mouseUp (const MouseEvent& e)
  37652. {
  37653. if (editSingleClick
  37654. && e.mouseWasClicked()
  37655. && contains (e.x, e.y)
  37656. && ! e.mods.isPopupMenu())
  37657. {
  37658. showEditor();
  37659. }
  37660. }
  37661. void Label::mouseDoubleClick (const MouseEvent& e)
  37662. {
  37663. if (editDoubleClick && ! e.mods.isPopupMenu())
  37664. showEditor();
  37665. }
  37666. void Label::resized()
  37667. {
  37668. if (editor != 0)
  37669. editor->setBoundsInset (BorderSize (0));
  37670. }
  37671. void Label::focusGained (FocusChangeType cause)
  37672. {
  37673. if (editSingleClick && cause == focusChangedByTabKey)
  37674. showEditor();
  37675. }
  37676. void Label::enablementChanged()
  37677. {
  37678. repaint();
  37679. }
  37680. void Label::colourChanged()
  37681. {
  37682. repaint();
  37683. }
  37684. void Label::setMinimumHorizontalScale (const float newScale)
  37685. {
  37686. if (minimumHorizontalScale != newScale)
  37687. {
  37688. minimumHorizontalScale = newScale;
  37689. repaint();
  37690. }
  37691. }
  37692. // We'll use a custom focus traverser here to make sure focus goes from the
  37693. // text editor to another component rather than back to the label itself.
  37694. class LabelKeyboardFocusTraverser : public KeyboardFocusTraverser
  37695. {
  37696. public:
  37697. LabelKeyboardFocusTraverser() {}
  37698. Component* getNextComponent (Component* current)
  37699. {
  37700. return KeyboardFocusTraverser::getNextComponent (dynamic_cast <TextEditor*> (current) != 0
  37701. ? current->getParentComponent() : current);
  37702. }
  37703. Component* getPreviousComponent (Component* current)
  37704. {
  37705. return KeyboardFocusTraverser::getPreviousComponent (dynamic_cast <TextEditor*> (current) != 0
  37706. ? current->getParentComponent() : current);
  37707. }
  37708. };
  37709. KeyboardFocusTraverser* Label::createFocusTraverser()
  37710. {
  37711. return new LabelKeyboardFocusTraverser();
  37712. }
  37713. void Label::addListener (LabelListener* const listener) throw()
  37714. {
  37715. listeners.add (listener);
  37716. }
  37717. void Label::removeListener (LabelListener* const listener) throw()
  37718. {
  37719. listeners.remove (listener);
  37720. }
  37721. void Label::callChangeListeners()
  37722. {
  37723. Component::BailOutChecker checker (this);
  37724. listeners.callChecked (checker, &LabelListener::labelTextChanged, this);
  37725. }
  37726. void Label::textEditorTextChanged (TextEditor& ed)
  37727. {
  37728. if (editor != 0)
  37729. {
  37730. jassert (&ed == editor);
  37731. if (! (hasKeyboardFocus (true) || isCurrentlyBlockedByAnotherModalComponent()))
  37732. {
  37733. if (lossOfFocusDiscardsChanges)
  37734. textEditorEscapeKeyPressed (ed);
  37735. else
  37736. textEditorReturnKeyPressed (ed);
  37737. }
  37738. }
  37739. }
  37740. void Label::textEditorReturnKeyPressed (TextEditor& ed)
  37741. {
  37742. if (editor != 0)
  37743. {
  37744. jassert (&ed == editor);
  37745. (void) ed;
  37746. const bool changed = updateFromTextEditorContents();
  37747. hideEditor (true);
  37748. if (changed)
  37749. {
  37750. Component::SafePointer<Component> deletionChecker (this);
  37751. textWasEdited();
  37752. if (deletionChecker != 0)
  37753. callChangeListeners();
  37754. }
  37755. }
  37756. }
  37757. void Label::textEditorEscapeKeyPressed (TextEditor& ed)
  37758. {
  37759. if (editor != 0)
  37760. {
  37761. jassert (&ed == editor);
  37762. (void) ed;
  37763. editor->setText (textValue.toString(), false);
  37764. hideEditor (true);
  37765. }
  37766. }
  37767. void Label::textEditorFocusLost (TextEditor& ed)
  37768. {
  37769. textEditorTextChanged (ed);
  37770. }
  37771. END_JUCE_NAMESPACE
  37772. /*** End of inlined file: juce_Label.cpp ***/
  37773. /*** Start of inlined file: juce_ListBox.cpp ***/
  37774. BEGIN_JUCE_NAMESPACE
  37775. class ListBoxRowComponent : public Component,
  37776. public TooltipClient
  37777. {
  37778. public:
  37779. ListBoxRowComponent (ListBox& owner_)
  37780. : owner (owner_),
  37781. row (-1),
  37782. selected (false),
  37783. isDragging (false)
  37784. {
  37785. }
  37786. ~ListBoxRowComponent()
  37787. {
  37788. deleteAllChildren();
  37789. }
  37790. void paint (Graphics& g)
  37791. {
  37792. if (owner.getModel() != 0)
  37793. owner.getModel()->paintListBoxItem (row, g, getWidth(), getHeight(), selected);
  37794. }
  37795. void update (const int row_, const bool selected_)
  37796. {
  37797. if (row != row_ || selected != selected_)
  37798. {
  37799. repaint();
  37800. row = row_;
  37801. selected = selected_;
  37802. }
  37803. if (owner.getModel() != 0)
  37804. {
  37805. Component* const customComp = owner.getModel()->refreshComponentForRow (row_, selected_, getChildComponent (0));
  37806. if (customComp != 0)
  37807. {
  37808. addAndMakeVisible (customComp);
  37809. customComp->setBounds (0, 0, getWidth(), getHeight());
  37810. for (int i = getNumChildComponents(); --i >= 0;)
  37811. if (getChildComponent (i) != customComp)
  37812. delete getChildComponent (i);
  37813. }
  37814. else
  37815. {
  37816. deleteAllChildren();
  37817. }
  37818. }
  37819. }
  37820. void mouseDown (const MouseEvent& e)
  37821. {
  37822. isDragging = false;
  37823. selectRowOnMouseUp = false;
  37824. if (isEnabled())
  37825. {
  37826. if (! selected)
  37827. {
  37828. owner.selectRowsBasedOnModifierKeys (row, e.mods);
  37829. if (owner.getModel() != 0)
  37830. owner.getModel()->listBoxItemClicked (row, e);
  37831. }
  37832. else
  37833. {
  37834. selectRowOnMouseUp = true;
  37835. }
  37836. }
  37837. }
  37838. void mouseUp (const MouseEvent& e)
  37839. {
  37840. if (isEnabled() && selectRowOnMouseUp && ! isDragging)
  37841. {
  37842. owner.selectRowsBasedOnModifierKeys (row, e.mods);
  37843. if (owner.getModel() != 0)
  37844. owner.getModel()->listBoxItemClicked (row, e);
  37845. }
  37846. }
  37847. void mouseDoubleClick (const MouseEvent& e)
  37848. {
  37849. if (owner.getModel() != 0 && isEnabled())
  37850. owner.getModel()->listBoxItemDoubleClicked (row, e);
  37851. }
  37852. void mouseDrag (const MouseEvent& e)
  37853. {
  37854. if (isEnabled() && owner.getModel() != 0 && ! (e.mouseWasClicked() || isDragging))
  37855. {
  37856. const SparseSet <int> selectedRows (owner.getSelectedRows());
  37857. if (selectedRows.size() > 0)
  37858. {
  37859. const String dragDescription (owner.getModel()->getDragSourceDescription (selectedRows));
  37860. if (dragDescription.isNotEmpty())
  37861. {
  37862. isDragging = true;
  37863. owner.startDragAndDrop (e, dragDescription);
  37864. }
  37865. }
  37866. }
  37867. }
  37868. void resized()
  37869. {
  37870. if (getNumChildComponents() > 0)
  37871. getChildComponent(0)->setBounds (0, 0, getWidth(), getHeight());
  37872. }
  37873. const String getTooltip()
  37874. {
  37875. if (owner.getModel() != 0)
  37876. return owner.getModel()->getTooltipForRow (row);
  37877. return String::empty;
  37878. }
  37879. juce_UseDebuggingNewOperator
  37880. bool neededFlag;
  37881. private:
  37882. ListBox& owner;
  37883. int row;
  37884. bool selected, isDragging, selectRowOnMouseUp;
  37885. ListBoxRowComponent (const ListBoxRowComponent&);
  37886. ListBoxRowComponent& operator= (const ListBoxRowComponent&);
  37887. };
  37888. class ListViewport : public Viewport
  37889. {
  37890. public:
  37891. int firstIndex, firstWholeIndex, lastWholeIndex;
  37892. bool hasUpdated;
  37893. ListViewport (ListBox& owner_)
  37894. : owner (owner_)
  37895. {
  37896. setWantsKeyboardFocus (false);
  37897. setViewedComponent (new Component());
  37898. getViewedComponent()->addMouseListener (this, false);
  37899. getViewedComponent()->setWantsKeyboardFocus (false);
  37900. }
  37901. ~ListViewport()
  37902. {
  37903. getViewedComponent()->removeMouseListener (this);
  37904. getViewedComponent()->deleteAllChildren();
  37905. }
  37906. ListBoxRowComponent* getComponentForRow (const int row) const throw()
  37907. {
  37908. return (ListBoxRowComponent*) getViewedComponent()
  37909. ->getChildComponent (row % jmax (1, getViewedComponent()->getNumChildComponents()));
  37910. }
  37911. int getRowNumberOfComponent (Component* const rowComponent) const throw()
  37912. {
  37913. const int index = getIndexOfChildComponent (rowComponent);
  37914. const int num = getViewedComponent()->getNumChildComponents();
  37915. for (int i = num; --i >= 0;)
  37916. if (((firstIndex + i) % jmax (1, num)) == index)
  37917. return firstIndex + i;
  37918. return -1;
  37919. }
  37920. Component* getComponentForRowIfOnscreen (const int row) const throw()
  37921. {
  37922. return (row >= firstIndex && row < firstIndex + getViewedComponent()->getNumChildComponents())
  37923. ? getComponentForRow (row) : 0;
  37924. }
  37925. void visibleAreaChanged (int, int, int, int)
  37926. {
  37927. updateVisibleArea (true);
  37928. if (owner.getModel() != 0)
  37929. owner.getModel()->listWasScrolled();
  37930. }
  37931. void updateVisibleArea (const bool makeSureItUpdatesContent)
  37932. {
  37933. hasUpdated = false;
  37934. const int newX = getViewedComponent()->getX();
  37935. int newY = getViewedComponent()->getY();
  37936. const int newW = jmax (owner.minimumRowWidth, getMaximumVisibleWidth());
  37937. const int newH = owner.totalItems * owner.getRowHeight();
  37938. if (newY + newH < getMaximumVisibleHeight() && newH > getMaximumVisibleHeight())
  37939. newY = getMaximumVisibleHeight() - newH;
  37940. getViewedComponent()->setBounds (newX, newY, newW, newH);
  37941. if (makeSureItUpdatesContent && ! hasUpdated)
  37942. updateContents();
  37943. }
  37944. void updateContents()
  37945. {
  37946. hasUpdated = true;
  37947. const int rowHeight = owner.getRowHeight();
  37948. if (rowHeight > 0)
  37949. {
  37950. const int y = getViewPositionY();
  37951. const int w = getViewedComponent()->getWidth();
  37952. const int numNeeded = 2 + getMaximumVisibleHeight() / rowHeight;
  37953. while (numNeeded > getViewedComponent()->getNumChildComponents())
  37954. getViewedComponent()->addAndMakeVisible (new ListBoxRowComponent (owner));
  37955. jassert (numNeeded >= 0);
  37956. while (numNeeded < getViewedComponent()->getNumChildComponents())
  37957. {
  37958. Component* const rowToRemove
  37959. = getViewedComponent()->getChildComponent (getViewedComponent()->getNumChildComponents() - 1);
  37960. delete rowToRemove;
  37961. }
  37962. firstIndex = y / rowHeight;
  37963. firstWholeIndex = (y + rowHeight - 1) / rowHeight;
  37964. lastWholeIndex = (y + getMaximumVisibleHeight() - 1) / rowHeight;
  37965. for (int i = 0; i < numNeeded; ++i)
  37966. {
  37967. const int row = i + firstIndex;
  37968. ListBoxRowComponent* const rowComp = getComponentForRow (row);
  37969. if (rowComp != 0)
  37970. {
  37971. rowComp->setBounds (0, row * rowHeight, w, rowHeight);
  37972. rowComp->update (row, owner.isRowSelected (row));
  37973. }
  37974. }
  37975. }
  37976. if (owner.headerComponent != 0)
  37977. owner.headerComponent->setBounds (owner.outlineThickness + getViewedComponent()->getX(),
  37978. owner.outlineThickness,
  37979. jmax (owner.getWidth() - owner.outlineThickness * 2,
  37980. getViewedComponent()->getWidth()),
  37981. owner.headerComponent->getHeight());
  37982. }
  37983. void paint (Graphics& g)
  37984. {
  37985. if (isOpaque())
  37986. g.fillAll (owner.findColour (ListBox::backgroundColourId));
  37987. }
  37988. bool keyPressed (const KeyPress& key)
  37989. {
  37990. if (key.isKeyCode (KeyPress::upKey)
  37991. || key.isKeyCode (KeyPress::downKey)
  37992. || key.isKeyCode (KeyPress::pageUpKey)
  37993. || key.isKeyCode (KeyPress::pageDownKey)
  37994. || key.isKeyCode (KeyPress::homeKey)
  37995. || key.isKeyCode (KeyPress::endKey))
  37996. {
  37997. // we want to avoid these keypresses going to the viewport, and instead allow
  37998. // them to pass up to our listbox..
  37999. return false;
  38000. }
  38001. return Viewport::keyPressed (key);
  38002. }
  38003. juce_UseDebuggingNewOperator
  38004. private:
  38005. ListBox& owner;
  38006. ListViewport (const ListViewport&);
  38007. ListViewport& operator= (const ListViewport&);
  38008. };
  38009. ListBox::ListBox (const String& name, ListBoxModel* const model_)
  38010. : Component (name),
  38011. model (model_),
  38012. headerComponent (0),
  38013. totalItems (0),
  38014. rowHeight (22),
  38015. minimumRowWidth (0),
  38016. outlineThickness (0),
  38017. lastRowSelected (-1),
  38018. mouseMoveSelects (false),
  38019. multipleSelection (false),
  38020. hasDoneInitialUpdate (false)
  38021. {
  38022. addAndMakeVisible (viewport = new ListViewport (*this));
  38023. setWantsKeyboardFocus (true);
  38024. colourChanged();
  38025. }
  38026. ListBox::~ListBox()
  38027. {
  38028. deleteAllChildren();
  38029. }
  38030. void ListBox::setModel (ListBoxModel* const newModel)
  38031. {
  38032. if (model != newModel)
  38033. {
  38034. model = newModel;
  38035. updateContent();
  38036. }
  38037. }
  38038. void ListBox::setMultipleSelectionEnabled (bool b)
  38039. {
  38040. multipleSelection = b;
  38041. }
  38042. void ListBox::setMouseMoveSelectsRows (bool b)
  38043. {
  38044. mouseMoveSelects = b;
  38045. if (b)
  38046. addMouseListener (this, true);
  38047. }
  38048. void ListBox::paint (Graphics& g)
  38049. {
  38050. if (! hasDoneInitialUpdate)
  38051. updateContent();
  38052. g.fillAll (findColour (backgroundColourId));
  38053. }
  38054. void ListBox::paintOverChildren (Graphics& g)
  38055. {
  38056. if (outlineThickness > 0)
  38057. {
  38058. g.setColour (findColour (outlineColourId));
  38059. g.drawRect (0, 0, getWidth(), getHeight(), outlineThickness);
  38060. }
  38061. }
  38062. void ListBox::resized()
  38063. {
  38064. viewport->setBoundsInset (BorderSize (outlineThickness + ((headerComponent != 0) ? headerComponent->getHeight() : 0),
  38065. outlineThickness,
  38066. outlineThickness,
  38067. outlineThickness));
  38068. viewport->setSingleStepSizes (20, getRowHeight());
  38069. viewport->updateVisibleArea (false);
  38070. }
  38071. void ListBox::visibilityChanged()
  38072. {
  38073. viewport->updateVisibleArea (true);
  38074. }
  38075. Viewport* ListBox::getViewport() const throw()
  38076. {
  38077. return viewport;
  38078. }
  38079. void ListBox::updateContent()
  38080. {
  38081. hasDoneInitialUpdate = true;
  38082. totalItems = (model != 0) ? model->getNumRows() : 0;
  38083. bool selectionChanged = false;
  38084. if (selected [selected.size() - 1] >= totalItems)
  38085. {
  38086. selected.removeRange (totalItems, std::numeric_limits<int>::max() - totalItems);
  38087. lastRowSelected = getSelectedRow (0);
  38088. selectionChanged = true;
  38089. }
  38090. viewport->updateVisibleArea (isVisible());
  38091. viewport->resized();
  38092. if (selectionChanged && model != 0)
  38093. model->selectedRowsChanged (lastRowSelected);
  38094. }
  38095. void ListBox::selectRow (const int row,
  38096. bool dontScroll,
  38097. bool deselectOthersFirst)
  38098. {
  38099. selectRowInternal (row, dontScroll, deselectOthersFirst, false);
  38100. }
  38101. void ListBox::selectRowInternal (const int row,
  38102. bool dontScroll,
  38103. bool deselectOthersFirst,
  38104. bool isMouseClick)
  38105. {
  38106. if (! multipleSelection)
  38107. deselectOthersFirst = true;
  38108. if ((! isRowSelected (row))
  38109. || (deselectOthersFirst && getNumSelectedRows() > 1))
  38110. {
  38111. if (((unsigned int) row) < (unsigned int) totalItems)
  38112. {
  38113. if (deselectOthersFirst)
  38114. selected.clear();
  38115. selected.addRange (row, 1);
  38116. if (getHeight() == 0 || getWidth() == 0)
  38117. dontScroll = true;
  38118. viewport->hasUpdated = false;
  38119. if (row < viewport->firstWholeIndex && ! dontScroll)
  38120. {
  38121. viewport->setViewPosition (viewport->getViewPositionX(),
  38122. row * getRowHeight());
  38123. }
  38124. else if (row >= viewport->lastWholeIndex && ! dontScroll)
  38125. {
  38126. const int rowsOnScreen = viewport->lastWholeIndex - viewport->firstWholeIndex;
  38127. if (row >= lastRowSelected + rowsOnScreen
  38128. && rowsOnScreen < totalItems - 1
  38129. && ! isMouseClick)
  38130. {
  38131. viewport->setViewPosition (viewport->getViewPositionX(),
  38132. jlimit (0, jmax (0, totalItems - rowsOnScreen), row)
  38133. * getRowHeight());
  38134. }
  38135. else
  38136. {
  38137. viewport->setViewPosition (viewport->getViewPositionX(),
  38138. jmax (0, (row + 1) * getRowHeight() - viewport->getMaximumVisibleHeight()));
  38139. }
  38140. }
  38141. if (! viewport->hasUpdated)
  38142. viewport->updateContents();
  38143. lastRowSelected = row;
  38144. model->selectedRowsChanged (row);
  38145. }
  38146. else
  38147. {
  38148. if (deselectOthersFirst)
  38149. deselectAllRows();
  38150. }
  38151. }
  38152. }
  38153. void ListBox::deselectRow (const int row)
  38154. {
  38155. if (selected.contains (row))
  38156. {
  38157. selected.removeRange (row, 1);
  38158. if (row == lastRowSelected)
  38159. lastRowSelected = getSelectedRow (0);
  38160. viewport->updateContents();
  38161. model->selectedRowsChanged (lastRowSelected);
  38162. }
  38163. }
  38164. void ListBox::setSelectedRows (const SparseSet<int>& setOfRowsToBeSelected,
  38165. const bool sendNotificationEventToModel)
  38166. {
  38167. selected = setOfRowsToBeSelected;
  38168. selected.removeRange (totalItems, std::numeric_limits<int>::max() - totalItems);
  38169. if (! isRowSelected (lastRowSelected))
  38170. lastRowSelected = getSelectedRow (0);
  38171. viewport->updateContents();
  38172. if ((model != 0) && sendNotificationEventToModel)
  38173. model->selectedRowsChanged (lastRowSelected);
  38174. }
  38175. const SparseSet<int> ListBox::getSelectedRows() const
  38176. {
  38177. return selected;
  38178. }
  38179. void ListBox::selectRangeOfRows (int firstRow, int lastRow)
  38180. {
  38181. if (multipleSelection && (firstRow != lastRow))
  38182. {
  38183. const int numRows = totalItems - 1;
  38184. firstRow = jlimit (0, jmax (0, numRows), firstRow);
  38185. lastRow = jlimit (0, jmax (0, numRows), lastRow);
  38186. selected.addRange (jmin (firstRow, lastRow),
  38187. abs (firstRow - lastRow) + 1);
  38188. selected.removeRange (lastRow, 1);
  38189. }
  38190. selectRowInternal (lastRow, false, false, true);
  38191. }
  38192. void ListBox::flipRowSelection (const int row)
  38193. {
  38194. if (isRowSelected (row))
  38195. deselectRow (row);
  38196. else
  38197. selectRowInternal (row, false, false, true);
  38198. }
  38199. void ListBox::deselectAllRows()
  38200. {
  38201. if (! selected.isEmpty())
  38202. {
  38203. selected.clear();
  38204. lastRowSelected = -1;
  38205. viewport->updateContents();
  38206. if (model != 0)
  38207. model->selectedRowsChanged (lastRowSelected);
  38208. }
  38209. }
  38210. void ListBox::selectRowsBasedOnModifierKeys (const int row,
  38211. const ModifierKeys& mods)
  38212. {
  38213. if (multipleSelection && mods.isCommandDown())
  38214. {
  38215. flipRowSelection (row);
  38216. }
  38217. else if (multipleSelection && mods.isShiftDown() && lastRowSelected >= 0)
  38218. {
  38219. selectRangeOfRows (lastRowSelected, row);
  38220. }
  38221. else if ((! mods.isPopupMenu()) || ! isRowSelected (row))
  38222. {
  38223. selectRowInternal (row, false, true, true);
  38224. }
  38225. }
  38226. int ListBox::getNumSelectedRows() const
  38227. {
  38228. return selected.size();
  38229. }
  38230. int ListBox::getSelectedRow (const int index) const
  38231. {
  38232. return (((unsigned int) index) < (unsigned int) selected.size())
  38233. ? selected [index] : -1;
  38234. }
  38235. bool ListBox::isRowSelected (const int row) const
  38236. {
  38237. return selected.contains (row);
  38238. }
  38239. int ListBox::getLastRowSelected() const
  38240. {
  38241. return (isRowSelected (lastRowSelected)) ? lastRowSelected : -1;
  38242. }
  38243. int ListBox::getRowContainingPosition (const int x, const int y) const throw()
  38244. {
  38245. if (((unsigned int) x) < (unsigned int) getWidth())
  38246. {
  38247. const int row = (viewport->getViewPositionY() + y - viewport->getY()) / rowHeight;
  38248. if (((unsigned int) row) < (unsigned int) totalItems)
  38249. return row;
  38250. }
  38251. return -1;
  38252. }
  38253. int ListBox::getInsertionIndexForPosition (const int x, const int y) const throw()
  38254. {
  38255. if (((unsigned int) x) < (unsigned int) getWidth())
  38256. {
  38257. const int row = (viewport->getViewPositionY() + y + rowHeight / 2 - viewport->getY()) / rowHeight;
  38258. return jlimit (0, totalItems, row);
  38259. }
  38260. return -1;
  38261. }
  38262. Component* ListBox::getComponentForRowNumber (const int row) const throw()
  38263. {
  38264. Component* const listRowComp = viewport->getComponentForRowIfOnscreen (row);
  38265. return listRowComp != 0 ? listRowComp->getChildComponent (0) : 0;
  38266. }
  38267. int ListBox::getRowNumberOfComponent (Component* const rowComponent) const throw()
  38268. {
  38269. return viewport->getRowNumberOfComponent (rowComponent);
  38270. }
  38271. const Rectangle<int> ListBox::getRowPosition (const int rowNumber,
  38272. const bool relativeToComponentTopLeft) const throw()
  38273. {
  38274. const int rowHeight = getRowHeight();
  38275. int y = viewport->getY() + rowHeight * rowNumber;
  38276. if (relativeToComponentTopLeft)
  38277. y -= viewport->getViewPositionY();
  38278. return Rectangle<int> (viewport->getX(), y,
  38279. viewport->getViewedComponent()->getWidth(), rowHeight);
  38280. }
  38281. void ListBox::setVerticalPosition (const double proportion)
  38282. {
  38283. const int offscreen = viewport->getViewedComponent()->getHeight() - viewport->getHeight();
  38284. viewport->setViewPosition (viewport->getViewPositionX(),
  38285. jmax (0, roundToInt (proportion * offscreen)));
  38286. }
  38287. double ListBox::getVerticalPosition() const
  38288. {
  38289. const int offscreen = viewport->getViewedComponent()->getHeight() - viewport->getHeight();
  38290. return (offscreen > 0) ? viewport->getViewPositionY() / (double) offscreen
  38291. : 0;
  38292. }
  38293. int ListBox::getVisibleRowWidth() const throw()
  38294. {
  38295. return viewport->getViewWidth();
  38296. }
  38297. void ListBox::scrollToEnsureRowIsOnscreen (const int row)
  38298. {
  38299. if (row < viewport->firstWholeIndex)
  38300. {
  38301. viewport->setViewPosition (viewport->getViewPositionX(),
  38302. row * getRowHeight());
  38303. }
  38304. else if (row >= viewport->lastWholeIndex)
  38305. {
  38306. viewport->setViewPosition (viewport->getViewPositionX(),
  38307. jmax (0, (row + 1) * getRowHeight() - viewport->getMaximumVisibleHeight()));
  38308. }
  38309. }
  38310. bool ListBox::keyPressed (const KeyPress& key)
  38311. {
  38312. const int numVisibleRows = viewport->getHeight() / getRowHeight();
  38313. const bool multiple = multipleSelection
  38314. && (lastRowSelected >= 0)
  38315. && (key.getModifiers().isShiftDown()
  38316. || key.getModifiers().isCtrlDown()
  38317. || key.getModifiers().isCommandDown());
  38318. if (key.isKeyCode (KeyPress::upKey))
  38319. {
  38320. if (multiple)
  38321. selectRangeOfRows (lastRowSelected, lastRowSelected - 1);
  38322. else
  38323. selectRow (jmax (0, lastRowSelected - 1));
  38324. }
  38325. else if (key.isKeyCode (KeyPress::returnKey)
  38326. && isRowSelected (lastRowSelected))
  38327. {
  38328. if (model != 0)
  38329. model->returnKeyPressed (lastRowSelected);
  38330. }
  38331. else if (key.isKeyCode (KeyPress::pageUpKey))
  38332. {
  38333. if (multiple)
  38334. selectRangeOfRows (lastRowSelected, lastRowSelected - numVisibleRows);
  38335. else
  38336. selectRow (jmax (0, jmax (0, lastRowSelected) - numVisibleRows));
  38337. }
  38338. else if (key.isKeyCode (KeyPress::pageDownKey))
  38339. {
  38340. if (multiple)
  38341. selectRangeOfRows (lastRowSelected, lastRowSelected + numVisibleRows);
  38342. else
  38343. selectRow (jmin (totalItems - 1, jmax (0, lastRowSelected) + numVisibleRows));
  38344. }
  38345. else if (key.isKeyCode (KeyPress::homeKey))
  38346. {
  38347. if (multiple && key.getModifiers().isShiftDown())
  38348. selectRangeOfRows (lastRowSelected, 0);
  38349. else
  38350. selectRow (0);
  38351. }
  38352. else if (key.isKeyCode (KeyPress::endKey))
  38353. {
  38354. if (multiple && key.getModifiers().isShiftDown())
  38355. selectRangeOfRows (lastRowSelected, totalItems - 1);
  38356. else
  38357. selectRow (totalItems - 1);
  38358. }
  38359. else if (key.isKeyCode (KeyPress::downKey))
  38360. {
  38361. if (multiple)
  38362. selectRangeOfRows (lastRowSelected, lastRowSelected + 1);
  38363. else
  38364. selectRow (jmin (totalItems - 1, jmax (0, lastRowSelected) + 1));
  38365. }
  38366. else if ((key.isKeyCode (KeyPress::deleteKey) || key.isKeyCode (KeyPress::backspaceKey))
  38367. && isRowSelected (lastRowSelected))
  38368. {
  38369. if (model != 0)
  38370. model->deleteKeyPressed (lastRowSelected);
  38371. }
  38372. else if (multiple && key == KeyPress (T('a'), ModifierKeys::commandModifier, 0))
  38373. {
  38374. selectRangeOfRows (0, std::numeric_limits<int>::max());
  38375. }
  38376. else
  38377. {
  38378. return false;
  38379. }
  38380. return true;
  38381. }
  38382. bool ListBox::keyStateChanged (const bool isKeyDown)
  38383. {
  38384. return isKeyDown
  38385. && (KeyPress::isKeyCurrentlyDown (KeyPress::upKey)
  38386. || KeyPress::isKeyCurrentlyDown (KeyPress::pageUpKey)
  38387. || KeyPress::isKeyCurrentlyDown (KeyPress::downKey)
  38388. || KeyPress::isKeyCurrentlyDown (KeyPress::pageDownKey)
  38389. || KeyPress::isKeyCurrentlyDown (KeyPress::homeKey)
  38390. || KeyPress::isKeyCurrentlyDown (KeyPress::endKey)
  38391. || KeyPress::isKeyCurrentlyDown (KeyPress::returnKey));
  38392. }
  38393. void ListBox::mouseWheelMove (const MouseEvent& e, float wheelIncrementX, float wheelIncrementY)
  38394. {
  38395. getHorizontalScrollBar()->mouseWheelMove (e, wheelIncrementX, 0);
  38396. getVerticalScrollBar()->mouseWheelMove (e, 0, wheelIncrementY);
  38397. }
  38398. void ListBox::mouseMove (const MouseEvent& e)
  38399. {
  38400. if (mouseMoveSelects)
  38401. {
  38402. const MouseEvent e2 (e.getEventRelativeTo (this));
  38403. selectRow (getRowContainingPosition (e2.x, e2.y), true);
  38404. }
  38405. }
  38406. void ListBox::mouseExit (const MouseEvent& e)
  38407. {
  38408. mouseMove (e);
  38409. }
  38410. void ListBox::mouseUp (const MouseEvent& e)
  38411. {
  38412. if (e.mouseWasClicked() && model != 0)
  38413. model->backgroundClicked();
  38414. }
  38415. void ListBox::setRowHeight (const int newHeight)
  38416. {
  38417. rowHeight = jmax (1, newHeight);
  38418. viewport->setSingleStepSizes (20, rowHeight);
  38419. updateContent();
  38420. }
  38421. int ListBox::getNumRowsOnScreen() const throw()
  38422. {
  38423. return viewport->getMaximumVisibleHeight() / rowHeight;
  38424. }
  38425. void ListBox::setMinimumContentWidth (const int newMinimumWidth)
  38426. {
  38427. minimumRowWidth = newMinimumWidth;
  38428. updateContent();
  38429. }
  38430. int ListBox::getVisibleContentWidth() const throw()
  38431. {
  38432. return viewport->getMaximumVisibleWidth();
  38433. }
  38434. ScrollBar* ListBox::getVerticalScrollBar() const throw()
  38435. {
  38436. return viewport->getVerticalScrollBar();
  38437. }
  38438. ScrollBar* ListBox::getHorizontalScrollBar() const throw()
  38439. {
  38440. return viewport->getHorizontalScrollBar();
  38441. }
  38442. void ListBox::colourChanged()
  38443. {
  38444. setOpaque (findColour (backgroundColourId).isOpaque());
  38445. viewport->setOpaque (isOpaque());
  38446. repaint();
  38447. }
  38448. void ListBox::setOutlineThickness (const int outlineThickness_)
  38449. {
  38450. outlineThickness = outlineThickness_;
  38451. resized();
  38452. }
  38453. void ListBox::setHeaderComponent (Component* const newHeaderComponent)
  38454. {
  38455. if (headerComponent != newHeaderComponent)
  38456. {
  38457. delete headerComponent;
  38458. headerComponent = newHeaderComponent;
  38459. addAndMakeVisible (newHeaderComponent);
  38460. ListBox::resized();
  38461. }
  38462. }
  38463. void ListBox::repaintRow (const int rowNumber) throw()
  38464. {
  38465. const Rectangle<int> r (getRowPosition (rowNumber, true));
  38466. repaint (r.getX(), r.getY(), r.getWidth(), r.getHeight());
  38467. }
  38468. Image* ListBox::createSnapshotOfSelectedRows (int& imageX, int& imageY)
  38469. {
  38470. Rectangle<int> imageArea;
  38471. const int firstRow = getRowContainingPosition (0, 0);
  38472. int i;
  38473. for (i = getNumRowsOnScreen() + 2; --i >= 0;)
  38474. {
  38475. Component* rowComp = viewport->getComponentForRowIfOnscreen (firstRow + i);
  38476. if (rowComp != 0 && isRowSelected (firstRow + i))
  38477. {
  38478. const Point<int> pos (rowComp->relativePositionToOtherComponent (this, Point<int>()));
  38479. const Rectangle<int> rowRect (pos.getX(), pos.getY(), rowComp->getWidth(), rowComp->getHeight());
  38480. if (imageArea.isEmpty())
  38481. imageArea = rowRect;
  38482. else
  38483. imageArea = imageArea.getUnion (rowRect);
  38484. }
  38485. }
  38486. imageArea = imageArea.getIntersection (Rectangle<int> (0, 0, getWidth(), getHeight()));
  38487. imageX = imageArea.getX();
  38488. imageY = imageArea.getY();
  38489. Image* snapshot = Image::createNativeImage (Image::ARGB, imageArea.getWidth(), imageArea.getHeight(), true);
  38490. for (i = getNumRowsOnScreen() + 2; --i >= 0;)
  38491. {
  38492. Component* rowComp = viewport->getComponentForRowIfOnscreen (firstRow + i);
  38493. if (rowComp != 0 && isRowSelected (firstRow + i))
  38494. {
  38495. const Point<int> pos (rowComp->relativePositionToOtherComponent (this, Point<int>()));
  38496. Graphics g (*snapshot);
  38497. g.setOrigin (pos.getX() - imageX, pos.getY() - imageY);
  38498. if (g.reduceClipRegion (0, 0, rowComp->getWidth(), rowComp->getHeight()))
  38499. rowComp->paintEntireComponent (g);
  38500. }
  38501. }
  38502. return snapshot;
  38503. }
  38504. void ListBox::startDragAndDrop (const MouseEvent& e, const String& dragDescription)
  38505. {
  38506. DragAndDropContainer* const dragContainer
  38507. = DragAndDropContainer::findParentDragContainerFor (this);
  38508. if (dragContainer != 0)
  38509. {
  38510. int x, y;
  38511. Image* dragImage = createSnapshotOfSelectedRows (x, y);
  38512. dragImage->multiplyAllAlphas (0.6f);
  38513. MouseEvent e2 (e.getEventRelativeTo (this));
  38514. const Point<int> p (x - e2.x, y - e2.y);
  38515. dragContainer->startDragging (dragDescription, this, dragImage, true, &p);
  38516. }
  38517. else
  38518. {
  38519. // to be able to do a drag-and-drop operation, the listbox needs to
  38520. // be inside a component which is also a DragAndDropContainer.
  38521. jassertfalse
  38522. }
  38523. }
  38524. Component* ListBoxModel::refreshComponentForRow (int, bool, Component* existingComponentToUpdate)
  38525. {
  38526. (void) existingComponentToUpdate;
  38527. jassert (existingComponentToUpdate == 0); // indicates a failure in the code the recycles the components
  38528. return 0;
  38529. }
  38530. void ListBoxModel::listBoxItemClicked (int, const MouseEvent&)
  38531. {
  38532. }
  38533. void ListBoxModel::listBoxItemDoubleClicked (int, const MouseEvent&)
  38534. {
  38535. }
  38536. void ListBoxModel::backgroundClicked()
  38537. {
  38538. }
  38539. void ListBoxModel::selectedRowsChanged (int)
  38540. {
  38541. }
  38542. void ListBoxModel::deleteKeyPressed (int)
  38543. {
  38544. }
  38545. void ListBoxModel::returnKeyPressed (int)
  38546. {
  38547. }
  38548. void ListBoxModel::listWasScrolled()
  38549. {
  38550. }
  38551. const String ListBoxModel::getDragSourceDescription (const SparseSet<int>&)
  38552. {
  38553. return String::empty;
  38554. }
  38555. const String ListBoxModel::getTooltipForRow (int)
  38556. {
  38557. return String::empty;
  38558. }
  38559. END_JUCE_NAMESPACE
  38560. /*** End of inlined file: juce_ListBox.cpp ***/
  38561. /*** Start of inlined file: juce_ProgressBar.cpp ***/
  38562. BEGIN_JUCE_NAMESPACE
  38563. ProgressBar::ProgressBar (double& progress_)
  38564. : progress (progress_),
  38565. displayPercentage (true),
  38566. lastCallbackTime (0)
  38567. {
  38568. currentValue = jlimit (0.0, 1.0, progress);
  38569. }
  38570. ProgressBar::~ProgressBar()
  38571. {
  38572. }
  38573. void ProgressBar::setPercentageDisplay (const bool shouldDisplayPercentage)
  38574. {
  38575. displayPercentage = shouldDisplayPercentage;
  38576. repaint();
  38577. }
  38578. void ProgressBar::setTextToDisplay (const String& text)
  38579. {
  38580. displayPercentage = false;
  38581. displayedMessage = text;
  38582. }
  38583. void ProgressBar::lookAndFeelChanged()
  38584. {
  38585. setOpaque (findColour (backgroundColourId).isOpaque());
  38586. }
  38587. void ProgressBar::colourChanged()
  38588. {
  38589. lookAndFeelChanged();
  38590. }
  38591. void ProgressBar::paint (Graphics& g)
  38592. {
  38593. String text;
  38594. if (displayPercentage)
  38595. {
  38596. if (currentValue >= 0 && currentValue <= 1.0)
  38597. text << roundToInt (currentValue * 100.0) << T("%");
  38598. }
  38599. else
  38600. {
  38601. text = displayedMessage;
  38602. }
  38603. getLookAndFeel().drawProgressBar (g, *this,
  38604. getWidth(), getHeight(),
  38605. currentValue, text);
  38606. }
  38607. void ProgressBar::visibilityChanged()
  38608. {
  38609. if (isVisible())
  38610. startTimer (30);
  38611. else
  38612. stopTimer();
  38613. }
  38614. void ProgressBar::timerCallback()
  38615. {
  38616. double newProgress = progress;
  38617. const uint32 now = Time::getMillisecondCounter();
  38618. const int timeSinceLastCallback = (int) (now - lastCallbackTime);
  38619. lastCallbackTime = now;
  38620. if (currentValue != newProgress
  38621. || newProgress < 0 || newProgress >= 1.0
  38622. || currentMessage != displayedMessage)
  38623. {
  38624. if (currentValue < newProgress
  38625. && newProgress >= 0 && newProgress < 1.0
  38626. && currentValue >= 0 && currentValue < 1.0)
  38627. {
  38628. newProgress = jmin (currentValue + 0.0008 * timeSinceLastCallback,
  38629. newProgress);
  38630. }
  38631. currentValue = newProgress;
  38632. currentMessage = displayedMessage;
  38633. repaint();
  38634. }
  38635. }
  38636. END_JUCE_NAMESPACE
  38637. /*** End of inlined file: juce_ProgressBar.cpp ***/
  38638. /*** Start of inlined file: juce_Slider.cpp ***/
  38639. BEGIN_JUCE_NAMESPACE
  38640. class SliderPopupDisplayComponent : public BubbleComponent
  38641. {
  38642. public:
  38643. SliderPopupDisplayComponent (Slider* const owner_)
  38644. : owner (owner_),
  38645. font (15.0f, Font::bold)
  38646. {
  38647. setAlwaysOnTop (true);
  38648. }
  38649. ~SliderPopupDisplayComponent()
  38650. {
  38651. }
  38652. void paintContent (Graphics& g, int w, int h)
  38653. {
  38654. g.setFont (font);
  38655. g.setColour (Colours::black);
  38656. g.drawFittedText (text, 0, 0, w, h, Justification::centred, 1);
  38657. }
  38658. void getContentSize (int& w, int& h)
  38659. {
  38660. w = font.getStringWidth (text) + 18;
  38661. h = (int) (font.getHeight() * 1.6f);
  38662. }
  38663. void updatePosition (const String& newText)
  38664. {
  38665. if (text != newText)
  38666. {
  38667. text = newText;
  38668. repaint();
  38669. }
  38670. BubbleComponent::setPosition (owner);
  38671. }
  38672. juce_UseDebuggingNewOperator
  38673. private:
  38674. Slider* owner;
  38675. Font font;
  38676. String text;
  38677. SliderPopupDisplayComponent (const SliderPopupDisplayComponent&);
  38678. SliderPopupDisplayComponent& operator= (const SliderPopupDisplayComponent&);
  38679. };
  38680. Slider::Slider (const String& name)
  38681. : Component (name),
  38682. lastCurrentValue (0),
  38683. lastValueMin (0),
  38684. lastValueMax (0),
  38685. minimum (0),
  38686. maximum (10),
  38687. interval (0),
  38688. skewFactor (1.0),
  38689. velocityModeSensitivity (1.0),
  38690. velocityModeOffset (0.0),
  38691. velocityModeThreshold (1),
  38692. rotaryStart (float_Pi * 1.2f),
  38693. rotaryEnd (float_Pi * 2.8f),
  38694. numDecimalPlaces (7),
  38695. sliderRegionStart (0),
  38696. sliderRegionSize (1),
  38697. sliderBeingDragged (-1),
  38698. pixelsForFullDragExtent (250),
  38699. style (LinearHorizontal),
  38700. textBoxPos (TextBoxLeft),
  38701. textBoxWidth (80),
  38702. textBoxHeight (20),
  38703. incDecButtonMode (incDecButtonsNotDraggable),
  38704. editableText (true),
  38705. doubleClickToValue (false),
  38706. isVelocityBased (false),
  38707. userKeyOverridesVelocity (true),
  38708. rotaryStop (true),
  38709. incDecButtonsSideBySide (false),
  38710. sendChangeOnlyOnRelease (false),
  38711. popupDisplayEnabled (false),
  38712. menuEnabled (false),
  38713. menuShown (false),
  38714. scrollWheelEnabled (true),
  38715. snapsToMousePos (true),
  38716. valueBox (0),
  38717. incButton (0),
  38718. decButton (0),
  38719. popupDisplay (0),
  38720. parentForPopupDisplay (0)
  38721. {
  38722. setWantsKeyboardFocus (false);
  38723. setRepaintsOnMouseActivity (true);
  38724. lookAndFeelChanged();
  38725. updateText();
  38726. currentValue.addListener (this);
  38727. valueMin.addListener (this);
  38728. valueMax.addListener (this);
  38729. }
  38730. Slider::~Slider()
  38731. {
  38732. currentValue.removeListener (this);
  38733. valueMin.removeListener (this);
  38734. valueMax.removeListener (this);
  38735. popupDisplay = 0;
  38736. deleteAllChildren();
  38737. }
  38738. void Slider::handleAsyncUpdate()
  38739. {
  38740. cancelPendingUpdate();
  38741. Component::BailOutChecker checker (this);
  38742. listeners.callChecked (checker, &SliderListener::sliderValueChanged, this);
  38743. }
  38744. void Slider::sendDragStart()
  38745. {
  38746. startedDragging();
  38747. Component::BailOutChecker checker (this);
  38748. listeners.callChecked (checker, &SliderListener::sliderDragStarted, this);
  38749. }
  38750. void Slider::sendDragEnd()
  38751. {
  38752. stoppedDragging();
  38753. sliderBeingDragged = -1;
  38754. Component::BailOutChecker checker (this);
  38755. listeners.callChecked (checker, &SliderListener::sliderDragEnded, this);
  38756. }
  38757. void Slider::addListener (SliderListener* const listener)
  38758. {
  38759. listeners.add (listener);
  38760. }
  38761. void Slider::removeListener (SliderListener* const listener)
  38762. {
  38763. listeners.remove (listener);
  38764. }
  38765. void Slider::setSliderStyle (const SliderStyle newStyle)
  38766. {
  38767. if (style != newStyle)
  38768. {
  38769. style = newStyle;
  38770. repaint();
  38771. lookAndFeelChanged();
  38772. }
  38773. }
  38774. void Slider::setRotaryParameters (const float startAngleRadians,
  38775. const float endAngleRadians,
  38776. const bool stopAtEnd)
  38777. {
  38778. // make sure the values are sensible..
  38779. jassert (rotaryStart >= 0 && rotaryEnd >= 0);
  38780. jassert (rotaryStart < float_Pi * 4.0f && rotaryEnd < float_Pi * 4.0f);
  38781. jassert (rotaryStart < rotaryEnd);
  38782. rotaryStart = startAngleRadians;
  38783. rotaryEnd = endAngleRadians;
  38784. rotaryStop = stopAtEnd;
  38785. }
  38786. void Slider::setVelocityBasedMode (const bool velBased)
  38787. {
  38788. isVelocityBased = velBased;
  38789. }
  38790. void Slider::setVelocityModeParameters (const double sensitivity,
  38791. const int threshold,
  38792. const double offset,
  38793. const bool userCanPressKeyToSwapMode)
  38794. {
  38795. jassert (threshold >= 0);
  38796. jassert (sensitivity > 0);
  38797. jassert (offset >= 0);
  38798. velocityModeSensitivity = sensitivity;
  38799. velocityModeOffset = offset;
  38800. velocityModeThreshold = threshold;
  38801. userKeyOverridesVelocity = userCanPressKeyToSwapMode;
  38802. }
  38803. void Slider::setSkewFactor (const double factor)
  38804. {
  38805. skewFactor = factor;
  38806. }
  38807. void Slider::setSkewFactorFromMidPoint (const double sliderValueToShowAtMidPoint)
  38808. {
  38809. if (maximum > minimum)
  38810. skewFactor = log (0.5) / log ((sliderValueToShowAtMidPoint - minimum)
  38811. / (maximum - minimum));
  38812. }
  38813. void Slider::setMouseDragSensitivity (const int distanceForFullScaleDrag)
  38814. {
  38815. jassert (distanceForFullScaleDrag > 0);
  38816. pixelsForFullDragExtent = distanceForFullScaleDrag;
  38817. }
  38818. void Slider::setIncDecButtonsMode (const IncDecButtonMode mode)
  38819. {
  38820. if (incDecButtonMode != mode)
  38821. {
  38822. incDecButtonMode = mode;
  38823. lookAndFeelChanged();
  38824. }
  38825. }
  38826. void Slider::setTextBoxStyle (const TextEntryBoxPosition newPosition,
  38827. const bool isReadOnly,
  38828. const int textEntryBoxWidth,
  38829. const int textEntryBoxHeight)
  38830. {
  38831. textBoxPos = newPosition;
  38832. editableText = ! isReadOnly;
  38833. textBoxWidth = textEntryBoxWidth;
  38834. textBoxHeight = textEntryBoxHeight;
  38835. repaint();
  38836. lookAndFeelChanged();
  38837. }
  38838. void Slider::setTextBoxIsEditable (const bool shouldBeEditable)
  38839. {
  38840. editableText = shouldBeEditable;
  38841. if (valueBox != 0)
  38842. valueBox->setEditable (shouldBeEditable && isEnabled());
  38843. }
  38844. void Slider::showTextBox()
  38845. {
  38846. jassert (editableText); // this should probably be avoided in read-only sliders.
  38847. if (valueBox != 0)
  38848. valueBox->showEditor();
  38849. }
  38850. void Slider::hideTextBox (const bool discardCurrentEditorContents)
  38851. {
  38852. if (valueBox != 0)
  38853. {
  38854. valueBox->hideEditor (discardCurrentEditorContents);
  38855. if (discardCurrentEditorContents)
  38856. updateText();
  38857. }
  38858. }
  38859. void Slider::setChangeNotificationOnlyOnRelease (const bool onlyNotifyOnRelease)
  38860. {
  38861. sendChangeOnlyOnRelease = onlyNotifyOnRelease;
  38862. }
  38863. void Slider::setSliderSnapsToMousePosition (const bool shouldSnapToMouse)
  38864. {
  38865. snapsToMousePos = shouldSnapToMouse;
  38866. }
  38867. void Slider::setPopupDisplayEnabled (const bool enabled,
  38868. Component* const parentComponentToUse)
  38869. {
  38870. popupDisplayEnabled = enabled;
  38871. parentForPopupDisplay = parentComponentToUse;
  38872. }
  38873. void Slider::colourChanged()
  38874. {
  38875. lookAndFeelChanged();
  38876. }
  38877. void Slider::lookAndFeelChanged()
  38878. {
  38879. const String previousTextBoxContent (valueBox != 0 ? valueBox->getText()
  38880. : getTextFromValue (currentValue.getValue()));
  38881. deleteAllChildren();
  38882. valueBox = 0;
  38883. LookAndFeel& lf = getLookAndFeel();
  38884. if (textBoxPos != NoTextBox)
  38885. {
  38886. addAndMakeVisible (valueBox = getLookAndFeel().createSliderTextBox (*this));
  38887. valueBox->setWantsKeyboardFocus (false);
  38888. valueBox->setText (previousTextBoxContent, false);
  38889. valueBox->setEditable (editableText && isEnabled());
  38890. valueBox->addListener (this);
  38891. if (style == LinearBar)
  38892. valueBox->addMouseListener (this, false);
  38893. valueBox->setTooltip (getTooltip());
  38894. }
  38895. if (style == IncDecButtons)
  38896. {
  38897. addAndMakeVisible (incButton = lf.createSliderButton (true));
  38898. incButton->addButtonListener (this);
  38899. addAndMakeVisible (decButton = lf.createSliderButton (false));
  38900. decButton->addButtonListener (this);
  38901. if (incDecButtonMode != incDecButtonsNotDraggable)
  38902. {
  38903. incButton->addMouseListener (this, false);
  38904. decButton->addMouseListener (this, false);
  38905. }
  38906. else
  38907. {
  38908. incButton->setRepeatSpeed (300, 100, 20);
  38909. incButton->addMouseListener (decButton, false);
  38910. decButton->setRepeatSpeed (300, 100, 20);
  38911. decButton->addMouseListener (incButton, false);
  38912. }
  38913. incButton->setTooltip (getTooltip());
  38914. decButton->setTooltip (getTooltip());
  38915. }
  38916. setComponentEffect (lf.getSliderEffect());
  38917. resized();
  38918. repaint();
  38919. }
  38920. void Slider::setRange (const double newMin,
  38921. const double newMax,
  38922. const double newInt)
  38923. {
  38924. if (minimum != newMin
  38925. || maximum != newMax
  38926. || interval != newInt)
  38927. {
  38928. minimum = newMin;
  38929. maximum = newMax;
  38930. interval = newInt;
  38931. // figure out the number of DPs needed to display all values at this
  38932. // interval setting.
  38933. numDecimalPlaces = 7;
  38934. if (newInt != 0)
  38935. {
  38936. int v = abs ((int) (newInt * 10000000));
  38937. while ((v % 10) == 0)
  38938. {
  38939. --numDecimalPlaces;
  38940. v /= 10;
  38941. }
  38942. }
  38943. // keep the current values inside the new range..
  38944. if (style != TwoValueHorizontal && style != TwoValueVertical)
  38945. {
  38946. setValue (getValue(), false, false);
  38947. }
  38948. else
  38949. {
  38950. setMinValue (getMinValue(), false, false);
  38951. setMaxValue (getMaxValue(), false, false);
  38952. }
  38953. updateText();
  38954. }
  38955. }
  38956. void Slider::triggerChangeMessage (const bool synchronous)
  38957. {
  38958. if (synchronous)
  38959. handleAsyncUpdate();
  38960. else
  38961. triggerAsyncUpdate();
  38962. valueChanged();
  38963. }
  38964. void Slider::valueChanged (Value& value)
  38965. {
  38966. if (value.refersToSameSourceAs (currentValue))
  38967. {
  38968. if (style != TwoValueHorizontal && style != TwoValueVertical)
  38969. setValue (currentValue.getValue(), false, false);
  38970. }
  38971. else if (value.refersToSameSourceAs (valueMin))
  38972. setMinValue (valueMin.getValue(), false, false, true);
  38973. else if (value.refersToSameSourceAs (valueMax))
  38974. setMaxValue (valueMax.getValue(), false, false, true);
  38975. }
  38976. double Slider::getValue() const
  38977. {
  38978. // for a two-value style slider, you should use the getMinValue() and getMaxValue()
  38979. // methods to get the two values.
  38980. jassert (style != TwoValueHorizontal && style != TwoValueVertical);
  38981. return currentValue.getValue();
  38982. }
  38983. void Slider::setValue (double newValue,
  38984. const bool sendUpdateMessage,
  38985. const bool sendMessageSynchronously)
  38986. {
  38987. // for a two-value style slider, you should use the setMinValue() and setMaxValue()
  38988. // methods to set the two values.
  38989. jassert (style != TwoValueHorizontal && style != TwoValueVertical);
  38990. newValue = constrainedValue (newValue);
  38991. if (style == ThreeValueHorizontal || style == ThreeValueVertical)
  38992. {
  38993. jassert ((double) valueMin.getValue() <= (double) valueMax.getValue());
  38994. newValue = jlimit ((double) valueMin.getValue(),
  38995. (double) valueMax.getValue(),
  38996. newValue);
  38997. }
  38998. if (newValue != lastCurrentValue)
  38999. {
  39000. if (valueBox != 0)
  39001. valueBox->hideEditor (true);
  39002. lastCurrentValue = newValue;
  39003. currentValue = newValue;
  39004. updateText();
  39005. repaint();
  39006. if (popupDisplay != 0)
  39007. {
  39008. static_cast <SliderPopupDisplayComponent*> (static_cast <Component*> (popupDisplay))
  39009. ->updatePosition (getTextFromValue (newValue));
  39010. popupDisplay->repaint();
  39011. }
  39012. if (sendUpdateMessage)
  39013. triggerChangeMessage (sendMessageSynchronously);
  39014. }
  39015. }
  39016. double Slider::getMinValue() const
  39017. {
  39018. // The minimum value only applies to sliders that are in two- or three-value mode.
  39019. jassert (style == TwoValueHorizontal || style == TwoValueVertical
  39020. || style == ThreeValueHorizontal || style == ThreeValueVertical);
  39021. return valueMin.getValue();
  39022. }
  39023. double Slider::getMaxValue() const
  39024. {
  39025. // The maximum value only applies to sliders that are in two- or three-value mode.
  39026. jassert (style == TwoValueHorizontal || style == TwoValueVertical
  39027. || style == ThreeValueHorizontal || style == ThreeValueVertical);
  39028. return valueMax.getValue();
  39029. }
  39030. void Slider::setMinValue (double newValue, const bool sendUpdateMessage, const bool sendMessageSynchronously, const bool allowNudgingOfOtherValues)
  39031. {
  39032. // The minimum value only applies to sliders that are in two- or three-value mode.
  39033. jassert (style == TwoValueHorizontal || style == TwoValueVertical
  39034. || style == ThreeValueHorizontal || style == ThreeValueVertical);
  39035. newValue = constrainedValue (newValue);
  39036. if (style == TwoValueHorizontal || style == TwoValueVertical)
  39037. {
  39038. if (allowNudgingOfOtherValues && newValue > (double) valueMax.getValue())
  39039. setMaxValue (newValue, sendUpdateMessage, sendMessageSynchronously);
  39040. newValue = jmin ((double) valueMax.getValue(), newValue);
  39041. }
  39042. else
  39043. {
  39044. if (allowNudgingOfOtherValues && newValue > lastCurrentValue)
  39045. setValue (newValue, sendUpdateMessage, sendMessageSynchronously);
  39046. newValue = jmin (lastCurrentValue, newValue);
  39047. }
  39048. if (lastValueMin != newValue)
  39049. {
  39050. lastValueMin = newValue;
  39051. valueMin = newValue;
  39052. repaint();
  39053. if (popupDisplay != 0)
  39054. {
  39055. static_cast <SliderPopupDisplayComponent*> (static_cast <Component*> (popupDisplay))
  39056. ->updatePosition (getTextFromValue (newValue));
  39057. popupDisplay->repaint();
  39058. }
  39059. if (sendUpdateMessage)
  39060. triggerChangeMessage (sendMessageSynchronously);
  39061. }
  39062. }
  39063. void Slider::setMaxValue (double newValue, const bool sendUpdateMessage, const bool sendMessageSynchronously, const bool allowNudgingOfOtherValues)
  39064. {
  39065. // The maximum value only applies to sliders that are in two- or three-value mode.
  39066. jassert (style == TwoValueHorizontal || style == TwoValueVertical
  39067. || style == ThreeValueHorizontal || style == ThreeValueVertical);
  39068. newValue = constrainedValue (newValue);
  39069. if (style == TwoValueHorizontal || style == TwoValueVertical)
  39070. {
  39071. if (allowNudgingOfOtherValues && newValue < (double) valueMin.getValue())
  39072. setMinValue (newValue, sendUpdateMessage, sendMessageSynchronously);
  39073. newValue = jmax ((double) valueMin.getValue(), newValue);
  39074. }
  39075. else
  39076. {
  39077. if (allowNudgingOfOtherValues && newValue < lastCurrentValue)
  39078. setValue (newValue, sendUpdateMessage, sendMessageSynchronously);
  39079. newValue = jmax (lastCurrentValue, newValue);
  39080. }
  39081. if (lastValueMax != newValue)
  39082. {
  39083. lastValueMax = newValue;
  39084. valueMax = newValue;
  39085. repaint();
  39086. if (popupDisplay != 0)
  39087. {
  39088. static_cast <SliderPopupDisplayComponent*> (static_cast <Component*> (popupDisplay))
  39089. ->updatePosition (getTextFromValue (valueMax.getValue()));
  39090. popupDisplay->repaint();
  39091. }
  39092. if (sendUpdateMessage)
  39093. triggerChangeMessage (sendMessageSynchronously);
  39094. }
  39095. }
  39096. void Slider::setDoubleClickReturnValue (const bool isDoubleClickEnabled,
  39097. const double valueToSetOnDoubleClick)
  39098. {
  39099. doubleClickToValue = isDoubleClickEnabled;
  39100. doubleClickReturnValue = valueToSetOnDoubleClick;
  39101. }
  39102. double Slider::getDoubleClickReturnValue (bool& isEnabled_) const
  39103. {
  39104. isEnabled_ = doubleClickToValue;
  39105. return doubleClickReturnValue;
  39106. }
  39107. void Slider::updateText()
  39108. {
  39109. if (valueBox != 0)
  39110. valueBox->setText (getTextFromValue (currentValue.getValue()), false);
  39111. }
  39112. void Slider::setTextValueSuffix (const String& suffix)
  39113. {
  39114. if (textSuffix != suffix)
  39115. {
  39116. textSuffix = suffix;
  39117. updateText();
  39118. }
  39119. }
  39120. const String Slider::getTextFromValue (double v)
  39121. {
  39122. if (numDecimalPlaces > 0)
  39123. return String (v, numDecimalPlaces) + textSuffix;
  39124. else
  39125. return String (roundToInt (v)) + textSuffix;
  39126. }
  39127. double Slider::getValueFromText (const String& text)
  39128. {
  39129. String t (text.trimStart());
  39130. if (t.endsWith (textSuffix))
  39131. t = t.substring (0, t.length() - textSuffix.length());
  39132. while (t.startsWithChar (T('+')))
  39133. t = t.substring (1).trimStart();
  39134. return t.initialSectionContainingOnly (T("0123456789.,-"))
  39135. .getDoubleValue();
  39136. }
  39137. double Slider::proportionOfLengthToValue (double proportion)
  39138. {
  39139. if (skewFactor != 1.0 && proportion > 0.0)
  39140. proportion = exp (log (proportion) / skewFactor);
  39141. return minimum + (maximum - minimum) * proportion;
  39142. }
  39143. double Slider::valueToProportionOfLength (double value)
  39144. {
  39145. const double n = (value - minimum) / (maximum - minimum);
  39146. return skewFactor == 1.0 ? n : pow (n, skewFactor);
  39147. }
  39148. double Slider::snapValue (double attemptedValue, const bool)
  39149. {
  39150. return attemptedValue;
  39151. }
  39152. void Slider::startedDragging()
  39153. {
  39154. }
  39155. void Slider::stoppedDragging()
  39156. {
  39157. }
  39158. void Slider::valueChanged()
  39159. {
  39160. }
  39161. void Slider::enablementChanged()
  39162. {
  39163. repaint();
  39164. }
  39165. void Slider::setPopupMenuEnabled (const bool menuEnabled_)
  39166. {
  39167. menuEnabled = menuEnabled_;
  39168. }
  39169. void Slider::setScrollWheelEnabled (const bool enabled)
  39170. {
  39171. scrollWheelEnabled = enabled;
  39172. }
  39173. void Slider::labelTextChanged (Label* label)
  39174. {
  39175. const double newValue = snapValue (getValueFromText (label->getText()), false);
  39176. if (newValue != (double) currentValue.getValue())
  39177. {
  39178. sendDragStart();
  39179. setValue (newValue, true, true);
  39180. sendDragEnd();
  39181. }
  39182. updateText(); // force a clean-up of the text, needed in case setValue() hasn't done this.
  39183. }
  39184. void Slider::buttonClicked (Button* button)
  39185. {
  39186. if (style == IncDecButtons)
  39187. {
  39188. sendDragStart();
  39189. if (button == incButton)
  39190. setValue (snapValue (getValue() + interval, false), true, true);
  39191. else if (button == decButton)
  39192. setValue (snapValue (getValue() - interval, false), true, true);
  39193. sendDragEnd();
  39194. }
  39195. }
  39196. double Slider::constrainedValue (double value) const
  39197. {
  39198. if (interval > 0)
  39199. value = minimum + interval * floor ((value - minimum) / interval + 0.5);
  39200. if (value <= minimum || maximum <= minimum)
  39201. value = minimum;
  39202. else if (value >= maximum)
  39203. value = maximum;
  39204. return value;
  39205. }
  39206. float Slider::getLinearSliderPos (const double value)
  39207. {
  39208. double sliderPosProportional;
  39209. if (maximum > minimum)
  39210. {
  39211. if (value < minimum)
  39212. {
  39213. sliderPosProportional = 0.0;
  39214. }
  39215. else if (value > maximum)
  39216. {
  39217. sliderPosProportional = 1.0;
  39218. }
  39219. else
  39220. {
  39221. sliderPosProportional = valueToProportionOfLength (value);
  39222. jassert (sliderPosProportional >= 0 && sliderPosProportional <= 1.0);
  39223. }
  39224. }
  39225. else
  39226. {
  39227. sliderPosProportional = 0.5;
  39228. }
  39229. if (isVertical() || style == IncDecButtons)
  39230. sliderPosProportional = 1.0 - sliderPosProportional;
  39231. return (float) (sliderRegionStart + sliderPosProportional * sliderRegionSize);
  39232. }
  39233. bool Slider::isHorizontal() const
  39234. {
  39235. return style == LinearHorizontal
  39236. || style == LinearBar
  39237. || style == TwoValueHorizontal
  39238. || style == ThreeValueHorizontal;
  39239. }
  39240. bool Slider::isVertical() const
  39241. {
  39242. return style == LinearVertical
  39243. || style == TwoValueVertical
  39244. || style == ThreeValueVertical;
  39245. }
  39246. bool Slider::incDecDragDirectionIsHorizontal() const
  39247. {
  39248. return incDecButtonMode == incDecButtonsDraggable_Horizontal
  39249. || (incDecButtonMode == incDecButtonsDraggable_AutoDirection && incDecButtonsSideBySide);
  39250. }
  39251. float Slider::getPositionOfValue (const double value)
  39252. {
  39253. if (isHorizontal() || isVertical())
  39254. {
  39255. return getLinearSliderPos (value);
  39256. }
  39257. else
  39258. {
  39259. jassertfalse // not a valid call on a slider that doesn't work linearly!
  39260. return 0.0f;
  39261. }
  39262. }
  39263. void Slider::paint (Graphics& g)
  39264. {
  39265. if (style != IncDecButtons)
  39266. {
  39267. if (style == Rotary || style == RotaryHorizontalDrag || style == RotaryVerticalDrag)
  39268. {
  39269. const float sliderPos = (float) valueToProportionOfLength (lastCurrentValue);
  39270. jassert (sliderPos >= 0 && sliderPos <= 1.0f);
  39271. getLookAndFeel().drawRotarySlider (g,
  39272. sliderRect.getX(),
  39273. sliderRect.getY(),
  39274. sliderRect.getWidth(),
  39275. sliderRect.getHeight(),
  39276. sliderPos,
  39277. rotaryStart, rotaryEnd,
  39278. *this);
  39279. }
  39280. else
  39281. {
  39282. getLookAndFeel().drawLinearSlider (g,
  39283. sliderRect.getX(),
  39284. sliderRect.getY(),
  39285. sliderRect.getWidth(),
  39286. sliderRect.getHeight(),
  39287. getLinearSliderPos (lastCurrentValue),
  39288. getLinearSliderPos (lastValueMin),
  39289. getLinearSliderPos (lastValueMax),
  39290. style,
  39291. *this);
  39292. }
  39293. if (style == LinearBar && valueBox == 0)
  39294. {
  39295. g.setColour (findColour (Slider::textBoxOutlineColourId));
  39296. g.drawRect (0, 0, getWidth(), getHeight(), 1);
  39297. }
  39298. }
  39299. }
  39300. void Slider::resized()
  39301. {
  39302. int minXSpace = 0;
  39303. int minYSpace = 0;
  39304. if (textBoxPos == TextBoxLeft || textBoxPos == TextBoxRight)
  39305. minXSpace = 30;
  39306. else
  39307. minYSpace = 15;
  39308. const int tbw = jmax (0, jmin (textBoxWidth, getWidth() - minXSpace));
  39309. const int tbh = jmax (0, jmin (textBoxHeight, getHeight() - minYSpace));
  39310. if (style == LinearBar)
  39311. {
  39312. if (valueBox != 0)
  39313. valueBox->setBounds (0, 0, getWidth(), getHeight());
  39314. }
  39315. else
  39316. {
  39317. if (textBoxPos == NoTextBox)
  39318. {
  39319. sliderRect.setBounds (0, 0, getWidth(), getHeight());
  39320. }
  39321. else if (textBoxPos == TextBoxLeft)
  39322. {
  39323. valueBox->setBounds (0, (getHeight() - tbh) / 2, tbw, tbh);
  39324. sliderRect.setBounds (tbw, 0, getWidth() - tbw, getHeight());
  39325. }
  39326. else if (textBoxPos == TextBoxRight)
  39327. {
  39328. valueBox->setBounds (getWidth() - tbw, (getHeight() - tbh) / 2, tbw, tbh);
  39329. sliderRect.setBounds (0, 0, getWidth() - tbw, getHeight());
  39330. }
  39331. else if (textBoxPos == TextBoxAbove)
  39332. {
  39333. valueBox->setBounds ((getWidth() - tbw) / 2, 0, tbw, tbh);
  39334. sliderRect.setBounds (0, tbh, getWidth(), getHeight() - tbh);
  39335. }
  39336. else if (textBoxPos == TextBoxBelow)
  39337. {
  39338. valueBox->setBounds ((getWidth() - tbw) / 2, getHeight() - tbh, tbw, tbh);
  39339. sliderRect.setBounds (0, 0, getWidth(), getHeight() - tbh);
  39340. }
  39341. }
  39342. const int indent = getLookAndFeel().getSliderThumbRadius (*this);
  39343. if (style == LinearBar)
  39344. {
  39345. const int barIndent = 1;
  39346. sliderRegionStart = barIndent;
  39347. sliderRegionSize = getWidth() - barIndent * 2;
  39348. sliderRect.setBounds (sliderRegionStart, barIndent,
  39349. sliderRegionSize, getHeight() - barIndent * 2);
  39350. }
  39351. else if (isHorizontal())
  39352. {
  39353. sliderRegionStart = sliderRect.getX() + indent;
  39354. sliderRegionSize = jmax (1, sliderRect.getWidth() - indent * 2);
  39355. sliderRect.setBounds (sliderRegionStart, sliderRect.getY(),
  39356. sliderRegionSize, sliderRect.getHeight());
  39357. }
  39358. else if (isVertical())
  39359. {
  39360. sliderRegionStart = sliderRect.getY() + indent;
  39361. sliderRegionSize = jmax (1, sliderRect.getHeight() - indent * 2);
  39362. sliderRect.setBounds (sliderRect.getX(), sliderRegionStart,
  39363. sliderRect.getWidth(), sliderRegionSize);
  39364. }
  39365. else
  39366. {
  39367. sliderRegionStart = 0;
  39368. sliderRegionSize = 100;
  39369. }
  39370. if (style == IncDecButtons)
  39371. {
  39372. Rectangle<int> buttonRect (sliderRect);
  39373. if (textBoxPos == TextBoxLeft || textBoxPos == TextBoxRight)
  39374. buttonRect.expand (-2, 0);
  39375. else
  39376. buttonRect.expand (0, -2);
  39377. incDecButtonsSideBySide = buttonRect.getWidth() > buttonRect.getHeight();
  39378. if (incDecButtonsSideBySide)
  39379. {
  39380. decButton->setBounds (buttonRect.getX(),
  39381. buttonRect.getY(),
  39382. buttonRect.getWidth() / 2,
  39383. buttonRect.getHeight());
  39384. decButton->setConnectedEdges (Button::ConnectedOnRight);
  39385. incButton->setBounds (buttonRect.getCentreX(),
  39386. buttonRect.getY(),
  39387. buttonRect.getWidth() / 2,
  39388. buttonRect.getHeight());
  39389. incButton->setConnectedEdges (Button::ConnectedOnLeft);
  39390. }
  39391. else
  39392. {
  39393. incButton->setBounds (buttonRect.getX(),
  39394. buttonRect.getY(),
  39395. buttonRect.getWidth(),
  39396. buttonRect.getHeight() / 2);
  39397. incButton->setConnectedEdges (Button::ConnectedOnBottom);
  39398. decButton->setBounds (buttonRect.getX(),
  39399. buttonRect.getCentreY(),
  39400. buttonRect.getWidth(),
  39401. buttonRect.getHeight() / 2);
  39402. decButton->setConnectedEdges (Button::ConnectedOnTop);
  39403. }
  39404. }
  39405. }
  39406. void Slider::focusOfChildComponentChanged (FocusChangeType)
  39407. {
  39408. repaint();
  39409. }
  39410. void Slider::mouseDown (const MouseEvent& e)
  39411. {
  39412. mouseWasHidden = false;
  39413. incDecDragged = false;
  39414. mouseXWhenLastDragged = e.x;
  39415. mouseYWhenLastDragged = e.y;
  39416. mouseDragStartX = e.getMouseDownX();
  39417. mouseDragStartY = e.getMouseDownY();
  39418. if (isEnabled())
  39419. {
  39420. if (e.mods.isPopupMenu() && menuEnabled)
  39421. {
  39422. menuShown = true;
  39423. PopupMenu m;
  39424. m.setLookAndFeel (&getLookAndFeel());
  39425. m.addItem (1, TRANS ("velocity-sensitive mode"), true, isVelocityBased);
  39426. m.addSeparator();
  39427. if (style == Rotary || style == RotaryHorizontalDrag || style == RotaryVerticalDrag)
  39428. {
  39429. PopupMenu rotaryMenu;
  39430. rotaryMenu.addItem (2, TRANS ("use circular dragging"), true, style == Rotary);
  39431. rotaryMenu.addItem (3, TRANS ("use left-right dragging"), true, style == RotaryHorizontalDrag);
  39432. rotaryMenu.addItem (4, TRANS ("use up-down dragging"), true, style == RotaryVerticalDrag);
  39433. m.addSubMenu (TRANS ("rotary mode"), rotaryMenu);
  39434. }
  39435. const int r = m.show();
  39436. if (r == 1)
  39437. {
  39438. setVelocityBasedMode (! isVelocityBased);
  39439. }
  39440. else if (r == 2)
  39441. {
  39442. setSliderStyle (Rotary);
  39443. }
  39444. else if (r == 3)
  39445. {
  39446. setSliderStyle (RotaryHorizontalDrag);
  39447. }
  39448. else if (r == 4)
  39449. {
  39450. setSliderStyle (RotaryVerticalDrag);
  39451. }
  39452. }
  39453. else if (maximum > minimum)
  39454. {
  39455. menuShown = false;
  39456. if (valueBox != 0)
  39457. valueBox->hideEditor (true);
  39458. sliderBeingDragged = 0;
  39459. if (style == TwoValueHorizontal
  39460. || style == TwoValueVertical
  39461. || style == ThreeValueHorizontal
  39462. || style == ThreeValueVertical)
  39463. {
  39464. const float mousePos = (float) (isVertical() ? e.y : e.x);
  39465. const float normalPosDistance = fabsf (getLinearSliderPos (currentValue.getValue()) - mousePos);
  39466. const float minPosDistance = fabsf (getLinearSliderPos (valueMin.getValue()) - 0.1f - mousePos);
  39467. const float maxPosDistance = fabsf (getLinearSliderPos (valueMax.getValue()) + 0.1f - mousePos);
  39468. if (style == TwoValueHorizontal || style == TwoValueVertical)
  39469. {
  39470. if (maxPosDistance <= minPosDistance)
  39471. sliderBeingDragged = 2;
  39472. else
  39473. sliderBeingDragged = 1;
  39474. }
  39475. else if (style == ThreeValueHorizontal || style == ThreeValueVertical)
  39476. {
  39477. if (normalPosDistance >= minPosDistance && maxPosDistance >= minPosDistance)
  39478. sliderBeingDragged = 1;
  39479. else if (normalPosDistance >= maxPosDistance)
  39480. sliderBeingDragged = 2;
  39481. }
  39482. }
  39483. minMaxDiff = (double) valueMax.getValue() - (double) valueMin.getValue();
  39484. lastAngle = rotaryStart + (rotaryEnd - rotaryStart)
  39485. * valueToProportionOfLength (currentValue.getValue());
  39486. valueWhenLastDragged = ((sliderBeingDragged == 2) ? valueMax
  39487. : ((sliderBeingDragged == 1) ? valueMin
  39488. : currentValue)).getValue();
  39489. valueOnMouseDown = valueWhenLastDragged;
  39490. if (popupDisplayEnabled)
  39491. {
  39492. SliderPopupDisplayComponent* const popup = new SliderPopupDisplayComponent (this);
  39493. popupDisplay = popup;
  39494. if (parentForPopupDisplay != 0)
  39495. {
  39496. parentForPopupDisplay->addChildComponent (popup);
  39497. }
  39498. else
  39499. {
  39500. popup->addToDesktop (0);
  39501. }
  39502. popup->setVisible (true);
  39503. }
  39504. sendDragStart();
  39505. mouseDrag (e);
  39506. }
  39507. }
  39508. }
  39509. void Slider::mouseUp (const MouseEvent&)
  39510. {
  39511. if (isEnabled()
  39512. && (! menuShown)
  39513. && (maximum > minimum)
  39514. && (style != IncDecButtons || incDecDragged))
  39515. {
  39516. restoreMouseIfHidden();
  39517. if (sendChangeOnlyOnRelease && valueOnMouseDown != (double) currentValue.getValue())
  39518. triggerChangeMessage (false);
  39519. sendDragEnd();
  39520. popupDisplay = 0;
  39521. if (style == IncDecButtons)
  39522. {
  39523. incButton->setState (Button::buttonNormal);
  39524. decButton->setState (Button::buttonNormal);
  39525. }
  39526. }
  39527. }
  39528. void Slider::restoreMouseIfHidden()
  39529. {
  39530. if (mouseWasHidden)
  39531. {
  39532. mouseWasHidden = false;
  39533. for (int i = Desktop::getInstance().getNumMouseSources(); --i >= 0;)
  39534. Desktop::getInstance().getMouseSource(i)->enableUnboundedMouseMovement (false);
  39535. const double pos = (sliderBeingDragged == 2) ? getMaxValue()
  39536. : ((sliderBeingDragged == 1) ? getMinValue()
  39537. : (double) currentValue.getValue());
  39538. Point<int> mousePos;
  39539. if (style == RotaryHorizontalDrag || style == RotaryVerticalDrag)
  39540. {
  39541. mousePos = Desktop::getLastMouseDownPosition();
  39542. if (style == RotaryHorizontalDrag)
  39543. {
  39544. const double posDiff = valueToProportionOfLength (pos) - valueToProportionOfLength (valueOnMouseDown);
  39545. mousePos += Point<int> (roundToInt (pixelsForFullDragExtent * posDiff), 0);
  39546. }
  39547. else
  39548. {
  39549. const double posDiff = valueToProportionOfLength (valueOnMouseDown) - valueToProportionOfLength (pos);
  39550. mousePos += Point<int> (0, roundToInt (pixelsForFullDragExtent * posDiff));
  39551. }
  39552. }
  39553. else
  39554. {
  39555. const int pixelPos = (int) getLinearSliderPos (pos);
  39556. mousePos = relativePositionToGlobal (Point<int> (isHorizontal() ? pixelPos : (getWidth() / 2),
  39557. isVertical() ? pixelPos : (getHeight() / 2)));
  39558. }
  39559. Desktop::setMousePosition (mousePos);
  39560. }
  39561. }
  39562. void Slider::modifierKeysChanged (const ModifierKeys& modifiers)
  39563. {
  39564. if (isEnabled()
  39565. && style != IncDecButtons
  39566. && style != Rotary
  39567. && isVelocityBased == modifiers.isAnyModifierKeyDown())
  39568. {
  39569. restoreMouseIfHidden();
  39570. }
  39571. }
  39572. static double smallestAngleBetween (double a1, double a2)
  39573. {
  39574. return jmin (fabs (a1 - a2),
  39575. fabs (a1 + double_Pi * 2.0 - a2),
  39576. fabs (a2 + double_Pi * 2.0 - a1));
  39577. }
  39578. void Slider::mouseDrag (const MouseEvent& e)
  39579. {
  39580. if (isEnabled()
  39581. && (! menuShown)
  39582. && (maximum > minimum))
  39583. {
  39584. if (style == Rotary)
  39585. {
  39586. int dx = e.x - sliderRect.getCentreX();
  39587. int dy = e.y - sliderRect.getCentreY();
  39588. if (dx * dx + dy * dy > 25)
  39589. {
  39590. double angle = atan2 ((double) dx, (double) -dy);
  39591. while (angle < 0.0)
  39592. angle += double_Pi * 2.0;
  39593. if (rotaryStop && ! e.mouseWasClicked())
  39594. {
  39595. if (fabs (angle - lastAngle) > double_Pi)
  39596. {
  39597. if (angle >= lastAngle)
  39598. angle -= double_Pi * 2.0;
  39599. else
  39600. angle += double_Pi * 2.0;
  39601. }
  39602. if (angle >= lastAngle)
  39603. angle = jmin (angle, (double) jmax (rotaryStart, rotaryEnd));
  39604. else
  39605. angle = jmax (angle, (double) jmin (rotaryStart, rotaryEnd));
  39606. }
  39607. else
  39608. {
  39609. while (angle < rotaryStart)
  39610. angle += double_Pi * 2.0;
  39611. if (angle > rotaryEnd)
  39612. {
  39613. if (smallestAngleBetween (angle, rotaryStart) <= smallestAngleBetween (angle, rotaryEnd))
  39614. angle = rotaryStart;
  39615. else
  39616. angle = rotaryEnd;
  39617. }
  39618. }
  39619. const double proportion = (angle - rotaryStart) / (rotaryEnd - rotaryStart);
  39620. valueWhenLastDragged = proportionOfLengthToValue (jlimit (0.0, 1.0, proportion));
  39621. lastAngle = angle;
  39622. }
  39623. }
  39624. else
  39625. {
  39626. if (style == LinearBar && e.mouseWasClicked()
  39627. && valueBox != 0 && valueBox->isEditable())
  39628. return;
  39629. if (style == IncDecButtons && ! incDecDragged)
  39630. {
  39631. if (e.getDistanceFromDragStart() < 10 || e.mouseWasClicked())
  39632. return;
  39633. incDecDragged = true;
  39634. mouseDragStartX = e.x;
  39635. mouseDragStartY = e.y;
  39636. }
  39637. if ((isVelocityBased == (userKeyOverridesVelocity ? e.mods.testFlags (ModifierKeys::ctrlModifier | ModifierKeys::commandModifier | ModifierKeys::altModifier)
  39638. : false))
  39639. || ((maximum - minimum) / sliderRegionSize < interval))
  39640. {
  39641. const int mousePos = (isHorizontal() || style == RotaryHorizontalDrag) ? e.x : e.y;
  39642. double scaledMousePos = (mousePos - sliderRegionStart) / (double) sliderRegionSize;
  39643. if (style == RotaryHorizontalDrag
  39644. || style == RotaryVerticalDrag
  39645. || style == IncDecButtons
  39646. || ((style == LinearHorizontal || style == LinearVertical || style == LinearBar)
  39647. && ! snapsToMousePos))
  39648. {
  39649. const int mouseDiff = (style == RotaryHorizontalDrag
  39650. || style == LinearHorizontal
  39651. || style == LinearBar
  39652. || (style == IncDecButtons && incDecDragDirectionIsHorizontal()))
  39653. ? e.x - mouseDragStartX
  39654. : mouseDragStartY - e.y;
  39655. double newPos = valueToProportionOfLength (valueOnMouseDown)
  39656. + mouseDiff * (1.0 / pixelsForFullDragExtent);
  39657. valueWhenLastDragged = proportionOfLengthToValue (jlimit (0.0, 1.0, newPos));
  39658. if (style == IncDecButtons)
  39659. {
  39660. incButton->setState (mouseDiff < 0 ? Button::buttonNormal : Button::buttonDown);
  39661. decButton->setState (mouseDiff > 0 ? Button::buttonNormal : Button::buttonDown);
  39662. }
  39663. }
  39664. else
  39665. {
  39666. if (isVertical())
  39667. scaledMousePos = 1.0 - scaledMousePos;
  39668. valueWhenLastDragged = proportionOfLengthToValue (jlimit (0.0, 1.0, scaledMousePos));
  39669. }
  39670. }
  39671. else
  39672. {
  39673. const int mouseDiff = (isHorizontal() || style == RotaryHorizontalDrag
  39674. || (style == IncDecButtons && incDecDragDirectionIsHorizontal()))
  39675. ? e.x - mouseXWhenLastDragged
  39676. : e.y - mouseYWhenLastDragged;
  39677. const double maxSpeed = jmax (200, sliderRegionSize);
  39678. double speed = jlimit (0.0, maxSpeed, (double) abs (mouseDiff));
  39679. if (speed != 0)
  39680. {
  39681. speed = 0.2 * velocityModeSensitivity
  39682. * (1.0 + sin (double_Pi * (1.5 + jmin (0.5, velocityModeOffset
  39683. + jmax (0.0, (double) (speed - velocityModeThreshold))
  39684. / maxSpeed))));
  39685. if (mouseDiff < 0)
  39686. speed = -speed;
  39687. if (isVertical() || style == RotaryVerticalDrag
  39688. || (style == IncDecButtons && ! incDecDragDirectionIsHorizontal()))
  39689. speed = -speed;
  39690. const double currentPos = valueToProportionOfLength (valueWhenLastDragged);
  39691. valueWhenLastDragged = proportionOfLengthToValue (jlimit (0.0, 1.0, currentPos + speed));
  39692. e.source.enableUnboundedMouseMovement (true, false);
  39693. mouseWasHidden = true;
  39694. }
  39695. }
  39696. }
  39697. valueWhenLastDragged = jlimit (minimum, maximum, valueWhenLastDragged);
  39698. if (sliderBeingDragged == 0)
  39699. {
  39700. setValue (snapValue (valueWhenLastDragged, true),
  39701. ! sendChangeOnlyOnRelease, true);
  39702. }
  39703. else if (sliderBeingDragged == 1)
  39704. {
  39705. setMinValue (snapValue (valueWhenLastDragged, true),
  39706. ! sendChangeOnlyOnRelease, false, true);
  39707. if (e.mods.isShiftDown())
  39708. setMaxValue (getMinValue() + minMaxDiff, false, false, true);
  39709. else
  39710. minMaxDiff = (double) valueMax.getValue() - (double) valueMin.getValue();
  39711. }
  39712. else
  39713. {
  39714. jassert (sliderBeingDragged == 2);
  39715. setMaxValue (snapValue (valueWhenLastDragged, true),
  39716. ! sendChangeOnlyOnRelease, false, true);
  39717. if (e.mods.isShiftDown())
  39718. setMinValue (getMaxValue() - minMaxDiff, false, false, true);
  39719. else
  39720. minMaxDiff = (double) valueMax.getValue() - (double) valueMin.getValue();
  39721. }
  39722. mouseXWhenLastDragged = e.x;
  39723. mouseYWhenLastDragged = e.y;
  39724. }
  39725. }
  39726. void Slider::mouseDoubleClick (const MouseEvent&)
  39727. {
  39728. if (doubleClickToValue
  39729. && isEnabled()
  39730. && style != IncDecButtons
  39731. && minimum <= doubleClickReturnValue
  39732. && maximum >= doubleClickReturnValue)
  39733. {
  39734. sendDragStart();
  39735. setValue (doubleClickReturnValue, true, true);
  39736. sendDragEnd();
  39737. }
  39738. }
  39739. void Slider::mouseWheelMove (const MouseEvent& e, float wheelIncrementX, float wheelIncrementY)
  39740. {
  39741. if (scrollWheelEnabled && isEnabled()
  39742. && style != TwoValueHorizontal
  39743. && style != TwoValueVertical)
  39744. {
  39745. if (maximum > minimum && ! e.mods.isAnyMouseButtonDown())
  39746. {
  39747. if (valueBox != 0)
  39748. valueBox->hideEditor (false);
  39749. const double value = (double) currentValue.getValue();
  39750. const double proportionDelta = (wheelIncrementX != 0 ? -wheelIncrementX : wheelIncrementY) * 0.15f;
  39751. const double currentPos = valueToProportionOfLength (value);
  39752. const double newValue = proportionOfLengthToValue (jlimit (0.0, 1.0, currentPos + proportionDelta));
  39753. double delta = (newValue != value)
  39754. ? jmax (fabs (newValue - value), interval) : 0;
  39755. if (value > newValue)
  39756. delta = -delta;
  39757. sendDragStart();
  39758. setValue (snapValue (value + delta, false), true, true);
  39759. sendDragEnd();
  39760. }
  39761. }
  39762. else
  39763. {
  39764. Component::mouseWheelMove (e, wheelIncrementX, wheelIncrementY);
  39765. }
  39766. }
  39767. void SliderListener::sliderDragStarted (Slider*)
  39768. {
  39769. }
  39770. void SliderListener::sliderDragEnded (Slider*)
  39771. {
  39772. }
  39773. END_JUCE_NAMESPACE
  39774. /*** End of inlined file: juce_Slider.cpp ***/
  39775. /*** Start of inlined file: juce_TableHeaderComponent.cpp ***/
  39776. BEGIN_JUCE_NAMESPACE
  39777. class DragOverlayComp : public Component
  39778. {
  39779. public:
  39780. DragOverlayComp (Image* const image_)
  39781. : image (image_)
  39782. {
  39783. image->multiplyAllAlphas (0.8f);
  39784. setAlwaysOnTop (true);
  39785. }
  39786. ~DragOverlayComp()
  39787. {
  39788. }
  39789. void paint (Graphics& g)
  39790. {
  39791. g.drawImageAt (image, 0, 0);
  39792. }
  39793. private:
  39794. ScopedPointer <Image> image;
  39795. DragOverlayComp (const DragOverlayComp&);
  39796. DragOverlayComp& operator= (const DragOverlayComp&);
  39797. };
  39798. TableHeaderComponent::TableHeaderComponent()
  39799. : columnsChanged (false),
  39800. columnsResized (false),
  39801. sortChanged (false),
  39802. menuActive (true),
  39803. stretchToFit (false),
  39804. columnIdBeingResized (0),
  39805. columnIdBeingDragged (0),
  39806. columnIdUnderMouse (0),
  39807. lastDeliberateWidth (0)
  39808. {
  39809. }
  39810. TableHeaderComponent::~TableHeaderComponent()
  39811. {
  39812. dragOverlayComp = 0;
  39813. }
  39814. void TableHeaderComponent::setPopupMenuActive (const bool hasMenu)
  39815. {
  39816. menuActive = hasMenu;
  39817. }
  39818. bool TableHeaderComponent::isPopupMenuActive() const { return menuActive; }
  39819. int TableHeaderComponent::getNumColumns (const bool onlyCountVisibleColumns) const
  39820. {
  39821. if (onlyCountVisibleColumns)
  39822. {
  39823. int num = 0;
  39824. for (int i = columns.size(); --i >= 0;)
  39825. if (columns.getUnchecked(i)->isVisible())
  39826. ++num;
  39827. return num;
  39828. }
  39829. else
  39830. {
  39831. return columns.size();
  39832. }
  39833. }
  39834. const String TableHeaderComponent::getColumnName (const int columnId) const
  39835. {
  39836. const ColumnInfo* const ci = getInfoForId (columnId);
  39837. return ci != 0 ? ci->name : String::empty;
  39838. }
  39839. void TableHeaderComponent::setColumnName (const int columnId, const String& newName)
  39840. {
  39841. ColumnInfo* const ci = getInfoForId (columnId);
  39842. if (ci != 0 && ci->name != newName)
  39843. {
  39844. ci->name = newName;
  39845. sendColumnsChanged();
  39846. }
  39847. }
  39848. void TableHeaderComponent::addColumn (const String& columnName,
  39849. const int columnId,
  39850. const int width,
  39851. const int minimumWidth,
  39852. const int maximumWidth,
  39853. const int propertyFlags,
  39854. const int insertIndex)
  39855. {
  39856. // can't have a duplicate or null ID!
  39857. jassert (columnId != 0 && getIndexOfColumnId (columnId, false) < 0);
  39858. jassert (width > 0);
  39859. ColumnInfo* const ci = new ColumnInfo();
  39860. ci->name = columnName;
  39861. ci->id = columnId;
  39862. ci->width = width;
  39863. ci->lastDeliberateWidth = width;
  39864. ci->minimumWidth = minimumWidth;
  39865. ci->maximumWidth = maximumWidth;
  39866. if (ci->maximumWidth < 0)
  39867. ci->maximumWidth = std::numeric_limits<int>::max();
  39868. jassert (ci->maximumWidth >= ci->minimumWidth);
  39869. ci->propertyFlags = propertyFlags;
  39870. columns.insert (insertIndex, ci);
  39871. sendColumnsChanged();
  39872. }
  39873. void TableHeaderComponent::removeColumn (const int columnIdToRemove)
  39874. {
  39875. const int index = getIndexOfColumnId (columnIdToRemove, false);
  39876. if (index >= 0)
  39877. {
  39878. columns.remove (index);
  39879. sortChanged = true;
  39880. sendColumnsChanged();
  39881. }
  39882. }
  39883. void TableHeaderComponent::removeAllColumns()
  39884. {
  39885. if (columns.size() > 0)
  39886. {
  39887. columns.clear();
  39888. sendColumnsChanged();
  39889. }
  39890. }
  39891. void TableHeaderComponent::moveColumn (const int columnId, int newIndex)
  39892. {
  39893. const int currentIndex = getIndexOfColumnId (columnId, false);
  39894. newIndex = visibleIndexToTotalIndex (newIndex);
  39895. if (columns [currentIndex] != 0 && currentIndex != newIndex)
  39896. {
  39897. columns.move (currentIndex, newIndex);
  39898. sendColumnsChanged();
  39899. }
  39900. }
  39901. int TableHeaderComponent::getColumnWidth (const int columnId) const
  39902. {
  39903. const ColumnInfo* const ci = getInfoForId (columnId);
  39904. return ci != 0 ? ci->width : 0;
  39905. }
  39906. void TableHeaderComponent::setColumnWidth (const int columnId, const int newWidth)
  39907. {
  39908. ColumnInfo* const ci = getInfoForId (columnId);
  39909. if (ci != 0 && ci->width != newWidth)
  39910. {
  39911. const int numColumns = getNumColumns (true);
  39912. ci->lastDeliberateWidth = ci->width
  39913. = jlimit (ci->minimumWidth, ci->maximumWidth, newWidth);
  39914. if (stretchToFit)
  39915. {
  39916. const int index = getIndexOfColumnId (columnId, true) + 1;
  39917. if (((unsigned int) index) < (unsigned int) numColumns)
  39918. {
  39919. const int x = getColumnPosition (index).getX();
  39920. if (lastDeliberateWidth == 0)
  39921. lastDeliberateWidth = getTotalWidth();
  39922. resizeColumnsToFit (visibleIndexToTotalIndex (index), lastDeliberateWidth - x);
  39923. }
  39924. }
  39925. repaint();
  39926. columnsResized = true;
  39927. triggerAsyncUpdate();
  39928. }
  39929. }
  39930. int TableHeaderComponent::getIndexOfColumnId (const int columnId, const bool onlyCountVisibleColumns) const
  39931. {
  39932. int n = 0;
  39933. for (int i = 0; i < columns.size(); ++i)
  39934. {
  39935. if ((! onlyCountVisibleColumns) || columns.getUnchecked(i)->isVisible())
  39936. {
  39937. if (columns.getUnchecked(i)->id == columnId)
  39938. return n;
  39939. ++n;
  39940. }
  39941. }
  39942. return -1;
  39943. }
  39944. int TableHeaderComponent::getColumnIdOfIndex (int index, const bool onlyCountVisibleColumns) const
  39945. {
  39946. if (onlyCountVisibleColumns)
  39947. index = visibleIndexToTotalIndex (index);
  39948. const ColumnInfo* const ci = columns [index];
  39949. return (ci != 0) ? ci->id : 0;
  39950. }
  39951. const Rectangle<int> TableHeaderComponent::getColumnPosition (const int index) const
  39952. {
  39953. int x = 0, width = 0, n = 0;
  39954. for (int i = 0; i < columns.size(); ++i)
  39955. {
  39956. x += width;
  39957. if (columns.getUnchecked(i)->isVisible())
  39958. {
  39959. width = columns.getUnchecked(i)->width;
  39960. if (n++ == index)
  39961. break;
  39962. }
  39963. else
  39964. {
  39965. width = 0;
  39966. }
  39967. }
  39968. return Rectangle<int> (x, 0, width, getHeight());
  39969. }
  39970. int TableHeaderComponent::getColumnIdAtX (const int xToFind) const
  39971. {
  39972. if (xToFind >= 0)
  39973. {
  39974. int x = 0;
  39975. for (int i = 0; i < columns.size(); ++i)
  39976. {
  39977. const ColumnInfo* const ci = columns.getUnchecked(i);
  39978. if (ci->isVisible())
  39979. {
  39980. x += ci->width;
  39981. if (xToFind < x)
  39982. return ci->id;
  39983. }
  39984. }
  39985. }
  39986. return 0;
  39987. }
  39988. int TableHeaderComponent::getTotalWidth() const
  39989. {
  39990. int w = 0;
  39991. for (int i = columns.size(); --i >= 0;)
  39992. if (columns.getUnchecked(i)->isVisible())
  39993. w += columns.getUnchecked(i)->width;
  39994. return w;
  39995. }
  39996. void TableHeaderComponent::setStretchToFitActive (const bool shouldStretchToFit)
  39997. {
  39998. stretchToFit = shouldStretchToFit;
  39999. lastDeliberateWidth = getTotalWidth();
  40000. resized();
  40001. }
  40002. bool TableHeaderComponent::isStretchToFitActive() const
  40003. {
  40004. return stretchToFit;
  40005. }
  40006. void TableHeaderComponent::resizeAllColumnsToFit (int targetTotalWidth)
  40007. {
  40008. if (stretchToFit && getWidth() > 0
  40009. && columnIdBeingResized == 0 && columnIdBeingDragged == 0)
  40010. {
  40011. lastDeliberateWidth = targetTotalWidth;
  40012. resizeColumnsToFit (0, targetTotalWidth);
  40013. }
  40014. }
  40015. void TableHeaderComponent::resizeColumnsToFit (int firstColumnIndex, int targetTotalWidth)
  40016. {
  40017. targetTotalWidth = jmax (targetTotalWidth, 0);
  40018. StretchableObjectResizer sor;
  40019. int i;
  40020. for (i = firstColumnIndex; i < columns.size(); ++i)
  40021. {
  40022. ColumnInfo* const ci = columns.getUnchecked(i);
  40023. if (ci->isVisible())
  40024. sor.addItem (ci->lastDeliberateWidth, ci->minimumWidth, ci->maximumWidth);
  40025. }
  40026. sor.resizeToFit (targetTotalWidth);
  40027. int visIndex = 0;
  40028. for (i = firstColumnIndex; i < columns.size(); ++i)
  40029. {
  40030. ColumnInfo* const ci = columns.getUnchecked(i);
  40031. if (ci->isVisible())
  40032. {
  40033. const int newWidth = jlimit (ci->minimumWidth, ci->maximumWidth,
  40034. (int) floor (sor.getItemSize (visIndex++)));
  40035. if (newWidth != ci->width)
  40036. {
  40037. ci->width = newWidth;
  40038. repaint();
  40039. columnsResized = true;
  40040. triggerAsyncUpdate();
  40041. }
  40042. }
  40043. }
  40044. }
  40045. void TableHeaderComponent::setColumnVisible (const int columnId, const bool shouldBeVisible)
  40046. {
  40047. ColumnInfo* const ci = getInfoForId (columnId);
  40048. if (ci != 0 && shouldBeVisible != ci->isVisible())
  40049. {
  40050. if (shouldBeVisible)
  40051. ci->propertyFlags |= visible;
  40052. else
  40053. ci->propertyFlags &= ~visible;
  40054. sendColumnsChanged();
  40055. resized();
  40056. }
  40057. }
  40058. bool TableHeaderComponent::isColumnVisible (const int columnId) const
  40059. {
  40060. const ColumnInfo* const ci = getInfoForId (columnId);
  40061. return ci != 0 && ci->isVisible();
  40062. }
  40063. void TableHeaderComponent::setSortColumnId (const int columnId, const bool sortForwards)
  40064. {
  40065. if (getSortColumnId() != columnId || isSortedForwards() != sortForwards)
  40066. {
  40067. for (int i = columns.size(); --i >= 0;)
  40068. columns.getUnchecked(i)->propertyFlags &= ~(sortedForwards | sortedBackwards);
  40069. ColumnInfo* const ci = getInfoForId (columnId);
  40070. if (ci != 0)
  40071. ci->propertyFlags |= (sortForwards ? sortedForwards : sortedBackwards);
  40072. reSortTable();
  40073. }
  40074. }
  40075. int TableHeaderComponent::getSortColumnId() const
  40076. {
  40077. for (int i = columns.size(); --i >= 0;)
  40078. if ((columns.getUnchecked(i)->propertyFlags & (sortedForwards | sortedBackwards)) != 0)
  40079. return columns.getUnchecked(i)->id;
  40080. return 0;
  40081. }
  40082. bool TableHeaderComponent::isSortedForwards() const
  40083. {
  40084. for (int i = columns.size(); --i >= 0;)
  40085. if ((columns.getUnchecked(i)->propertyFlags & (sortedForwards | sortedBackwards)) != 0)
  40086. return (columns.getUnchecked(i)->propertyFlags & sortedForwards) != 0;
  40087. return true;
  40088. }
  40089. void TableHeaderComponent::reSortTable()
  40090. {
  40091. sortChanged = true;
  40092. repaint();
  40093. triggerAsyncUpdate();
  40094. }
  40095. const String TableHeaderComponent::toString() const
  40096. {
  40097. String s;
  40098. XmlElement doc ("TABLELAYOUT");
  40099. doc.setAttribute ("sortedCol", getSortColumnId());
  40100. doc.setAttribute ("sortForwards", isSortedForwards());
  40101. for (int i = 0; i < columns.size(); ++i)
  40102. {
  40103. const ColumnInfo* const ci = columns.getUnchecked (i);
  40104. XmlElement* const e = doc.createNewChildElement ("COLUMN");
  40105. e->setAttribute ("id", ci->id);
  40106. e->setAttribute ("visible", ci->isVisible());
  40107. e->setAttribute ("width", ci->width);
  40108. }
  40109. return doc.createDocument (String::empty, true, false);
  40110. }
  40111. void TableHeaderComponent::restoreFromString (const String& storedVersion)
  40112. {
  40113. XmlDocument doc (storedVersion);
  40114. ScopedPointer <XmlElement> storedXml (doc.getDocumentElement());
  40115. int index = 0;
  40116. if (storedXml != 0 && storedXml->hasTagName ("TABLELAYOUT"))
  40117. {
  40118. forEachXmlChildElement (*storedXml, col)
  40119. {
  40120. const int tabId = col->getIntAttribute ("id");
  40121. ColumnInfo* const ci = getInfoForId (tabId);
  40122. if (ci != 0)
  40123. {
  40124. columns.move (columns.indexOf (ci), index);
  40125. ci->width = col->getIntAttribute ("width");
  40126. setColumnVisible (tabId, col->getBoolAttribute ("visible"));
  40127. }
  40128. ++index;
  40129. }
  40130. columnsResized = true;
  40131. sendColumnsChanged();
  40132. setSortColumnId (storedXml->getIntAttribute ("sortedCol"),
  40133. storedXml->getBoolAttribute ("sortForwards", true));
  40134. }
  40135. }
  40136. void TableHeaderComponent::addListener (TableHeaderListener* const newListener)
  40137. {
  40138. listeners.addIfNotAlreadyThere (newListener);
  40139. }
  40140. void TableHeaderComponent::removeListener (TableHeaderListener* const listenerToRemove)
  40141. {
  40142. listeners.removeValue (listenerToRemove);
  40143. }
  40144. void TableHeaderComponent::columnClicked (int columnId, const ModifierKeys& mods)
  40145. {
  40146. const ColumnInfo* const ci = getInfoForId (columnId);
  40147. if (ci != 0 && (ci->propertyFlags & sortable) != 0 && ! mods.isPopupMenu())
  40148. setSortColumnId (columnId, (ci->propertyFlags & sortedForwards) == 0);
  40149. }
  40150. void TableHeaderComponent::addMenuItems (PopupMenu& menu, const int /*columnIdClicked*/)
  40151. {
  40152. for (int i = 0; i < columns.size(); ++i)
  40153. {
  40154. const ColumnInfo* const ci = columns.getUnchecked(i);
  40155. if ((ci->propertyFlags & appearsOnColumnMenu) != 0)
  40156. menu.addItem (ci->id, ci->name,
  40157. (ci->propertyFlags & (sortedForwards | sortedBackwards)) == 0,
  40158. isColumnVisible (ci->id));
  40159. }
  40160. }
  40161. void TableHeaderComponent::reactToMenuItem (const int menuReturnId, const int /*columnIdClicked*/)
  40162. {
  40163. if (getIndexOfColumnId (menuReturnId, false) >= 0)
  40164. setColumnVisible (menuReturnId, ! isColumnVisible (menuReturnId));
  40165. }
  40166. void TableHeaderComponent::paint (Graphics& g)
  40167. {
  40168. LookAndFeel& lf = getLookAndFeel();
  40169. lf.drawTableHeaderBackground (g, *this);
  40170. const Rectangle<int> clip (g.getClipBounds());
  40171. int x = 0;
  40172. for (int i = 0; i < columns.size(); ++i)
  40173. {
  40174. const ColumnInfo* const ci = columns.getUnchecked(i);
  40175. if (ci->isVisible())
  40176. {
  40177. if (x + ci->width > clip.getX()
  40178. && (ci->id != columnIdBeingDragged
  40179. || dragOverlayComp == 0
  40180. || ! dragOverlayComp->isVisible()))
  40181. {
  40182. g.saveState();
  40183. g.setOrigin (x, 0);
  40184. g.reduceClipRegion (0, 0, ci->width, getHeight());
  40185. lf.drawTableHeaderColumn (g, ci->name, ci->id, ci->width, getHeight(),
  40186. ci->id == columnIdUnderMouse,
  40187. ci->id == columnIdUnderMouse && isMouseButtonDown(),
  40188. ci->propertyFlags);
  40189. g.restoreState();
  40190. }
  40191. x += ci->width;
  40192. if (x >= clip.getRight())
  40193. break;
  40194. }
  40195. }
  40196. }
  40197. void TableHeaderComponent::resized()
  40198. {
  40199. }
  40200. void TableHeaderComponent::mouseMove (const MouseEvent& e)
  40201. {
  40202. updateColumnUnderMouse (e.x, e.y);
  40203. }
  40204. void TableHeaderComponent::mouseEnter (const MouseEvent& e)
  40205. {
  40206. updateColumnUnderMouse (e.x, e.y);
  40207. }
  40208. void TableHeaderComponent::mouseExit (const MouseEvent& e)
  40209. {
  40210. updateColumnUnderMouse (e.x, e.y);
  40211. }
  40212. void TableHeaderComponent::mouseDown (const MouseEvent& e)
  40213. {
  40214. repaint();
  40215. columnIdBeingResized = 0;
  40216. columnIdBeingDragged = 0;
  40217. if (columnIdUnderMouse != 0)
  40218. {
  40219. draggingColumnOffset = e.x - getColumnPosition (getIndexOfColumnId (columnIdUnderMouse, true)).getX();
  40220. if (e.mods.isPopupMenu())
  40221. columnClicked (columnIdUnderMouse, e.mods);
  40222. }
  40223. if (menuActive && e.mods.isPopupMenu())
  40224. showColumnChooserMenu (columnIdUnderMouse);
  40225. }
  40226. void TableHeaderComponent::mouseDrag (const MouseEvent& e)
  40227. {
  40228. if (columnIdBeingResized == 0
  40229. && columnIdBeingDragged == 0
  40230. && ! (e.mouseWasClicked() || e.mods.isPopupMenu()))
  40231. {
  40232. dragOverlayComp = 0;
  40233. columnIdBeingResized = getResizeDraggerAt (e.getMouseDownX());
  40234. if (columnIdBeingResized != 0)
  40235. {
  40236. const ColumnInfo* const ci = getInfoForId (columnIdBeingResized);
  40237. initialColumnWidth = ci->width;
  40238. }
  40239. else
  40240. {
  40241. beginDrag (e);
  40242. }
  40243. }
  40244. if (columnIdBeingResized != 0)
  40245. {
  40246. const ColumnInfo* const ci = getInfoForId (columnIdBeingResized);
  40247. if (ci != 0)
  40248. {
  40249. int w = jlimit (ci->minimumWidth, ci->maximumWidth,
  40250. initialColumnWidth + e.getDistanceFromDragStartX());
  40251. if (stretchToFit)
  40252. {
  40253. // prevent us dragging a column too far right if we're in stretch-to-fit mode
  40254. int minWidthOnRight = 0;
  40255. for (int i = getIndexOfColumnId (columnIdBeingResized, false) + 1; i < columns.size(); ++i)
  40256. if (columns.getUnchecked (i)->isVisible())
  40257. minWidthOnRight += columns.getUnchecked (i)->minimumWidth;
  40258. const Rectangle<int> currentPos (getColumnPosition (getIndexOfColumnId (columnIdBeingResized, true)));
  40259. w = jmax (ci->minimumWidth, jmin (w, getWidth() - minWidthOnRight - currentPos.getX()));
  40260. }
  40261. setColumnWidth (columnIdBeingResized, w);
  40262. }
  40263. }
  40264. else if (columnIdBeingDragged != 0)
  40265. {
  40266. if (e.y >= -50 && e.y < getHeight() + 50)
  40267. {
  40268. if (dragOverlayComp != 0)
  40269. {
  40270. dragOverlayComp->setVisible (true);
  40271. dragOverlayComp->setBounds (jlimit (0,
  40272. jmax (0, getTotalWidth() - dragOverlayComp->getWidth()),
  40273. e.x - draggingColumnOffset),
  40274. 0,
  40275. dragOverlayComp->getWidth(),
  40276. getHeight());
  40277. for (int i = columns.size(); --i >= 0;)
  40278. {
  40279. const int currentIndex = getIndexOfColumnId (columnIdBeingDragged, true);
  40280. int newIndex = currentIndex;
  40281. if (newIndex > 0)
  40282. {
  40283. // if the previous column isn't draggable, we can't move our column
  40284. // past it, because that'd change the undraggable column's position..
  40285. const ColumnInfo* const previous = columns.getUnchecked (newIndex - 1);
  40286. if ((previous->propertyFlags & draggable) != 0)
  40287. {
  40288. const int leftOfPrevious = getColumnPosition (newIndex - 1).getX();
  40289. const int rightOfCurrent = getColumnPosition (newIndex).getRight();
  40290. if (abs (dragOverlayComp->getX() - leftOfPrevious)
  40291. < abs (dragOverlayComp->getRight() - rightOfCurrent))
  40292. {
  40293. --newIndex;
  40294. }
  40295. }
  40296. }
  40297. if (newIndex < columns.size() - 1)
  40298. {
  40299. // if the next column isn't draggable, we can't move our column
  40300. // past it, because that'd change the undraggable column's position..
  40301. const ColumnInfo* const nextCol = columns.getUnchecked (newIndex + 1);
  40302. if ((nextCol->propertyFlags & draggable) != 0)
  40303. {
  40304. const int leftOfCurrent = getColumnPosition (newIndex).getX();
  40305. const int rightOfNext = getColumnPosition (newIndex + 1).getRight();
  40306. if (abs (dragOverlayComp->getX() - leftOfCurrent)
  40307. > abs (dragOverlayComp->getRight() - rightOfNext))
  40308. {
  40309. ++newIndex;
  40310. }
  40311. }
  40312. }
  40313. if (newIndex != currentIndex)
  40314. moveColumn (columnIdBeingDragged, newIndex);
  40315. else
  40316. break;
  40317. }
  40318. }
  40319. }
  40320. else
  40321. {
  40322. endDrag (draggingColumnOriginalIndex);
  40323. }
  40324. }
  40325. }
  40326. void TableHeaderComponent::beginDrag (const MouseEvent& e)
  40327. {
  40328. if (columnIdBeingDragged == 0)
  40329. {
  40330. columnIdBeingDragged = getColumnIdAtX (e.getMouseDownX());
  40331. const ColumnInfo* const ci = getInfoForId (columnIdBeingDragged);
  40332. if (ci == 0 || (ci->propertyFlags & draggable) == 0)
  40333. {
  40334. columnIdBeingDragged = 0;
  40335. }
  40336. else
  40337. {
  40338. draggingColumnOriginalIndex = getIndexOfColumnId (columnIdBeingDragged, true);
  40339. const Rectangle<int> columnRect (getColumnPosition (draggingColumnOriginalIndex));
  40340. const int temp = columnIdBeingDragged;
  40341. columnIdBeingDragged = 0;
  40342. addAndMakeVisible (dragOverlayComp = new DragOverlayComp (createComponentSnapshot (columnRect, false)));
  40343. columnIdBeingDragged = temp;
  40344. dragOverlayComp->setBounds (columnRect);
  40345. for (int i = listeners.size(); --i >= 0;)
  40346. {
  40347. listeners.getUnchecked(i)->tableColumnDraggingChanged (this, columnIdBeingDragged);
  40348. i = jmin (i, listeners.size() - 1);
  40349. }
  40350. }
  40351. }
  40352. }
  40353. void TableHeaderComponent::endDrag (const int finalIndex)
  40354. {
  40355. if (columnIdBeingDragged != 0)
  40356. {
  40357. moveColumn (columnIdBeingDragged, finalIndex);
  40358. columnIdBeingDragged = 0;
  40359. repaint();
  40360. for (int i = listeners.size(); --i >= 0;)
  40361. {
  40362. listeners.getUnchecked(i)->tableColumnDraggingChanged (this, 0);
  40363. i = jmin (i, listeners.size() - 1);
  40364. }
  40365. }
  40366. }
  40367. void TableHeaderComponent::mouseUp (const MouseEvent& e)
  40368. {
  40369. mouseDrag (e);
  40370. for (int i = columns.size(); --i >= 0;)
  40371. if (columns.getUnchecked (i)->isVisible())
  40372. columns.getUnchecked (i)->lastDeliberateWidth = columns.getUnchecked (i)->width;
  40373. columnIdBeingResized = 0;
  40374. repaint();
  40375. endDrag (getIndexOfColumnId (columnIdBeingDragged, true));
  40376. updateColumnUnderMouse (e.x, e.y);
  40377. if (columnIdUnderMouse != 0 && e.mouseWasClicked() && ! e.mods.isPopupMenu())
  40378. columnClicked (columnIdUnderMouse, e.mods);
  40379. dragOverlayComp = 0;
  40380. }
  40381. const MouseCursor TableHeaderComponent::getMouseCursor()
  40382. {
  40383. if (columnIdBeingResized != 0 || (getResizeDraggerAt (getMouseXYRelative().getX()) != 0 && ! isMouseButtonDown()))
  40384. return MouseCursor (MouseCursor::LeftRightResizeCursor);
  40385. return Component::getMouseCursor();
  40386. }
  40387. bool TableHeaderComponent::ColumnInfo::isVisible() const
  40388. {
  40389. return (propertyFlags & TableHeaderComponent::visible) != 0;
  40390. }
  40391. TableHeaderComponent::ColumnInfo* TableHeaderComponent::getInfoForId (const int id) const
  40392. {
  40393. for (int i = columns.size(); --i >= 0;)
  40394. if (columns.getUnchecked(i)->id == id)
  40395. return columns.getUnchecked(i);
  40396. return 0;
  40397. }
  40398. int TableHeaderComponent::visibleIndexToTotalIndex (const int visibleIndex) const
  40399. {
  40400. int n = 0;
  40401. for (int i = 0; i < columns.size(); ++i)
  40402. {
  40403. if (columns.getUnchecked(i)->isVisible())
  40404. {
  40405. if (n == visibleIndex)
  40406. return i;
  40407. ++n;
  40408. }
  40409. }
  40410. return -1;
  40411. }
  40412. void TableHeaderComponent::sendColumnsChanged()
  40413. {
  40414. if (stretchToFit && lastDeliberateWidth > 0)
  40415. resizeAllColumnsToFit (lastDeliberateWidth);
  40416. repaint();
  40417. columnsChanged = true;
  40418. triggerAsyncUpdate();
  40419. }
  40420. void TableHeaderComponent::handleAsyncUpdate()
  40421. {
  40422. const bool changed = columnsChanged || sortChanged;
  40423. const bool sized = columnsResized || changed;
  40424. const bool sorted = sortChanged;
  40425. columnsChanged = false;
  40426. columnsResized = false;
  40427. sortChanged = false;
  40428. if (sorted)
  40429. {
  40430. for (int i = listeners.size(); --i >= 0;)
  40431. {
  40432. listeners.getUnchecked(i)->tableSortOrderChanged (this);
  40433. i = jmin (i, listeners.size() - 1);
  40434. }
  40435. }
  40436. if (changed)
  40437. {
  40438. for (int i = listeners.size(); --i >= 0;)
  40439. {
  40440. listeners.getUnchecked(i)->tableColumnsChanged (this);
  40441. i = jmin (i, listeners.size() - 1);
  40442. }
  40443. }
  40444. if (sized)
  40445. {
  40446. for (int i = listeners.size(); --i >= 0;)
  40447. {
  40448. listeners.getUnchecked(i)->tableColumnsResized (this);
  40449. i = jmin (i, listeners.size() - 1);
  40450. }
  40451. }
  40452. }
  40453. int TableHeaderComponent::getResizeDraggerAt (const int mouseX) const
  40454. {
  40455. if (((unsigned int) mouseX) < (unsigned int) getWidth())
  40456. {
  40457. const int draggableDistance = 3;
  40458. int x = 0;
  40459. for (int i = 0; i < columns.size(); ++i)
  40460. {
  40461. const ColumnInfo* const ci = columns.getUnchecked(i);
  40462. if (ci->isVisible())
  40463. {
  40464. if (abs (mouseX - (x + ci->width)) <= draggableDistance
  40465. && (ci->propertyFlags & resizable) != 0)
  40466. return ci->id;
  40467. x += ci->width;
  40468. }
  40469. }
  40470. }
  40471. return 0;
  40472. }
  40473. void TableHeaderComponent::updateColumnUnderMouse (int x, int y)
  40474. {
  40475. const int newCol = (reallyContains (x, y, true) && getResizeDraggerAt (x) == 0)
  40476. ? getColumnIdAtX (x) : 0;
  40477. if (newCol != columnIdUnderMouse)
  40478. {
  40479. columnIdUnderMouse = newCol;
  40480. repaint();
  40481. }
  40482. }
  40483. void TableHeaderComponent::showColumnChooserMenu (const int columnIdClicked)
  40484. {
  40485. PopupMenu m;
  40486. addMenuItems (m, columnIdClicked);
  40487. if (m.getNumItems() > 0)
  40488. {
  40489. m.setLookAndFeel (&getLookAndFeel());
  40490. const int result = m.show();
  40491. if (result != 0)
  40492. reactToMenuItem (result, columnIdClicked);
  40493. }
  40494. }
  40495. void TableHeaderListener::tableColumnDraggingChanged (TableHeaderComponent*, int)
  40496. {
  40497. }
  40498. END_JUCE_NAMESPACE
  40499. /*** End of inlined file: juce_TableHeaderComponent.cpp ***/
  40500. /*** Start of inlined file: juce_TableListBox.cpp ***/
  40501. BEGIN_JUCE_NAMESPACE
  40502. static const char* const tableColumnPropertyTag = "_tableColumnID";
  40503. class TableListRowComp : public Component,
  40504. public TooltipClient
  40505. {
  40506. public:
  40507. TableListRowComp (TableListBox& owner_)
  40508. : owner (owner_),
  40509. row (-1),
  40510. isSelected (false)
  40511. {
  40512. }
  40513. ~TableListRowComp()
  40514. {
  40515. deleteAllChildren();
  40516. }
  40517. void paint (Graphics& g)
  40518. {
  40519. TableListBoxModel* const model = owner.getModel();
  40520. if (model != 0)
  40521. {
  40522. const TableHeaderComponent* const header = owner.getHeader();
  40523. model->paintRowBackground (g, row, getWidth(), getHeight(), isSelected);
  40524. const int numColumns = header->getNumColumns (true);
  40525. for (int i = 0; i < numColumns; ++i)
  40526. {
  40527. if (! columnsWithComponents [i])
  40528. {
  40529. const int columnId = header->getColumnIdOfIndex (i, true);
  40530. Rectangle<int> columnRect (header->getColumnPosition (i));
  40531. columnRect.setSize (columnRect.getWidth(), getHeight());
  40532. g.saveState();
  40533. g.reduceClipRegion (columnRect);
  40534. g.setOrigin (columnRect.getX(), 0);
  40535. model->paintCell (g, row, columnId, columnRect.getWidth(), columnRect.getHeight(), isSelected);
  40536. g.restoreState();
  40537. }
  40538. }
  40539. }
  40540. }
  40541. void update (const int newRow, const bool isNowSelected)
  40542. {
  40543. if (newRow != row || isNowSelected != isSelected)
  40544. {
  40545. row = newRow;
  40546. isSelected = isNowSelected;
  40547. repaint();
  40548. }
  40549. if (row < owner.getNumRows())
  40550. {
  40551. jassert (row >= 0);
  40552. const var::identifier tagPropertyName ("_tableLastUseNum");
  40553. const int newTag = Random::getSystemRandom().nextInt();
  40554. const TableHeaderComponent* const header = owner.getHeader();
  40555. const int numColumns = header->getNumColumns (true);
  40556. int i;
  40557. columnsWithComponents.clear();
  40558. if (owner.getModel() != 0)
  40559. {
  40560. for (i = 0; i < numColumns; ++i)
  40561. {
  40562. const int columnId = header->getColumnIdOfIndex (i, true);
  40563. Component* const newComp
  40564. = owner.getModel()->refreshComponentForCell (row, columnId, isSelected,
  40565. findChildComponentForColumn (columnId));
  40566. if (newComp != 0)
  40567. {
  40568. addAndMakeVisible (newComp);
  40569. newComp->getProperties().set (tagPropertyName, newTag);
  40570. newComp->getProperties().set (tableColumnPropertyTag, columnId);
  40571. const Rectangle<int> columnRect (header->getColumnPosition (i));
  40572. newComp->setBounds (columnRect.getX(), 0, columnRect.getWidth(), getHeight());
  40573. columnsWithComponents.setBit (i);
  40574. }
  40575. }
  40576. }
  40577. for (i = getNumChildComponents(); --i >= 0;)
  40578. {
  40579. Component* const c = getChildComponent (i);
  40580. if ((int) c->getProperties() [tagPropertyName] != newTag)
  40581. delete c;
  40582. }
  40583. }
  40584. else
  40585. {
  40586. columnsWithComponents.clear();
  40587. deleteAllChildren();
  40588. }
  40589. }
  40590. void resized()
  40591. {
  40592. for (int i = getNumChildComponents(); --i >= 0;)
  40593. {
  40594. Component* const c = getChildComponent (i);
  40595. const int columnId = c->getProperties() [tableColumnPropertyTag];
  40596. if (columnId != 0)
  40597. {
  40598. const Rectangle<int> columnRect (owner.getHeader()->getColumnPosition (owner.getHeader()->getIndexOfColumnId (columnId, true)));
  40599. c->setBounds (columnRect.getX(), 0, columnRect.getWidth(), getHeight());
  40600. }
  40601. }
  40602. }
  40603. void mouseDown (const MouseEvent& e)
  40604. {
  40605. isDragging = false;
  40606. selectRowOnMouseUp = false;
  40607. if (isEnabled())
  40608. {
  40609. if (! isSelected)
  40610. {
  40611. owner.selectRowsBasedOnModifierKeys (row, e.mods);
  40612. const int columnId = owner.getHeader()->getColumnIdAtX (e.x);
  40613. if (columnId != 0 && owner.getModel() != 0)
  40614. owner.getModel()->cellClicked (row, columnId, e);
  40615. }
  40616. else
  40617. {
  40618. selectRowOnMouseUp = true;
  40619. }
  40620. }
  40621. }
  40622. void mouseDrag (const MouseEvent& e)
  40623. {
  40624. if (isEnabled() && owner.getModel() != 0 && ! (e.mouseWasClicked() || isDragging))
  40625. {
  40626. const SparseSet <int> selectedRows (owner.getSelectedRows());
  40627. if (selectedRows.size() > 0)
  40628. {
  40629. const String dragDescription (owner.getModel()->getDragSourceDescription (selectedRows));
  40630. if (dragDescription.isNotEmpty())
  40631. {
  40632. isDragging = true;
  40633. owner.startDragAndDrop (e, dragDescription);
  40634. }
  40635. }
  40636. }
  40637. }
  40638. void mouseUp (const MouseEvent& e)
  40639. {
  40640. if (selectRowOnMouseUp && e.mouseWasClicked() && isEnabled())
  40641. {
  40642. owner.selectRowsBasedOnModifierKeys (row, e.mods);
  40643. const int columnId = owner.getHeader()->getColumnIdAtX (e.x);
  40644. if (columnId != 0 && owner.getModel() != 0)
  40645. owner.getModel()->cellClicked (row, columnId, e);
  40646. }
  40647. }
  40648. void mouseDoubleClick (const MouseEvent& e)
  40649. {
  40650. const int columnId = owner.getHeader()->getColumnIdAtX (e.x);
  40651. if (columnId != 0 && owner.getModel() != 0)
  40652. owner.getModel()->cellDoubleClicked (row, columnId, e);
  40653. }
  40654. const String getTooltip()
  40655. {
  40656. const int columnId = owner.getHeader()->getColumnIdAtX (getMouseXYRelative().getX());
  40657. if (columnId != 0 && owner.getModel() != 0)
  40658. return owner.getModel()->getCellTooltip (row, columnId);
  40659. return String::empty;
  40660. }
  40661. juce_UseDebuggingNewOperator
  40662. private:
  40663. TableListBox& owner;
  40664. int row;
  40665. bool isSelected, isDragging, selectRowOnMouseUp;
  40666. BigInteger columnsWithComponents;
  40667. Component* findChildComponentForColumn (const int columnId) const
  40668. {
  40669. for (int i = getNumChildComponents(); --i >= 0;)
  40670. {
  40671. Component* const c = getChildComponent (i);
  40672. if ((int) c->getProperties() [tableColumnPropertyTag] == columnId)
  40673. return c;
  40674. }
  40675. return 0;
  40676. }
  40677. TableListRowComp (const TableListRowComp&);
  40678. TableListRowComp& operator= (const TableListRowComp&);
  40679. };
  40680. class TableListBoxHeader : public TableHeaderComponent
  40681. {
  40682. public:
  40683. TableListBoxHeader (TableListBox& owner_)
  40684. : owner (owner_)
  40685. {
  40686. }
  40687. ~TableListBoxHeader()
  40688. {
  40689. }
  40690. void addMenuItems (PopupMenu& menu, const int columnIdClicked)
  40691. {
  40692. if (owner.isAutoSizeMenuOptionShown())
  40693. {
  40694. menu.addItem (0xf836743, TRANS("Auto-size this column"), columnIdClicked != 0);
  40695. menu.addItem (0xf836744, TRANS("Auto-size all columns"), owner.getHeader()->getNumColumns (true) > 0);
  40696. menu.addSeparator();
  40697. }
  40698. TableHeaderComponent::addMenuItems (menu, columnIdClicked);
  40699. }
  40700. void reactToMenuItem (const int menuReturnId, const int columnIdClicked)
  40701. {
  40702. if (menuReturnId == 0xf836743)
  40703. {
  40704. owner.autoSizeColumn (columnIdClicked);
  40705. }
  40706. else if (menuReturnId == 0xf836744)
  40707. {
  40708. owner.autoSizeAllColumns();
  40709. }
  40710. else
  40711. {
  40712. TableHeaderComponent::reactToMenuItem (menuReturnId, columnIdClicked);
  40713. }
  40714. }
  40715. juce_UseDebuggingNewOperator
  40716. private:
  40717. TableListBox& owner;
  40718. TableListBoxHeader (const TableListBoxHeader&);
  40719. TableListBoxHeader& operator= (const TableListBoxHeader&);
  40720. };
  40721. TableListBox::TableListBox (const String& name, TableListBoxModel* const model_)
  40722. : ListBox (name, 0),
  40723. model (model_),
  40724. autoSizeOptionsShown (true)
  40725. {
  40726. ListBox::model = this;
  40727. header = new TableListBoxHeader (*this);
  40728. header->setSize (100, 28);
  40729. header->addListener (this);
  40730. setHeaderComponent (header);
  40731. }
  40732. TableListBox::~TableListBox()
  40733. {
  40734. deleteAllChildren();
  40735. }
  40736. void TableListBox::setModel (TableListBoxModel* const newModel)
  40737. {
  40738. if (model != newModel)
  40739. {
  40740. model = newModel;
  40741. updateContent();
  40742. }
  40743. }
  40744. int TableListBox::getHeaderHeight() const
  40745. {
  40746. return header->getHeight();
  40747. }
  40748. void TableListBox::setHeaderHeight (const int newHeight)
  40749. {
  40750. header->setSize (header->getWidth(), newHeight);
  40751. resized();
  40752. }
  40753. void TableListBox::autoSizeColumn (const int columnId)
  40754. {
  40755. const int width = model != 0 ? model->getColumnAutoSizeWidth (columnId) : 0;
  40756. if (width > 0)
  40757. header->setColumnWidth (columnId, width);
  40758. }
  40759. void TableListBox::autoSizeAllColumns()
  40760. {
  40761. for (int i = 0; i < header->getNumColumns (true); ++i)
  40762. autoSizeColumn (header->getColumnIdOfIndex (i, true));
  40763. }
  40764. void TableListBox::setAutoSizeMenuOptionShown (const bool shouldBeShown)
  40765. {
  40766. autoSizeOptionsShown = shouldBeShown;
  40767. }
  40768. bool TableListBox::isAutoSizeMenuOptionShown() const
  40769. {
  40770. return autoSizeOptionsShown;
  40771. }
  40772. const Rectangle<int> TableListBox::getCellPosition (const int columnId,
  40773. const int rowNumber,
  40774. const bool relativeToComponentTopLeft) const
  40775. {
  40776. Rectangle<int> headerCell (header->getColumnPosition (header->getIndexOfColumnId (columnId, true)));
  40777. if (relativeToComponentTopLeft)
  40778. headerCell.translate (header->getX(), 0);
  40779. const Rectangle<int> row (getRowPosition (rowNumber, relativeToComponentTopLeft));
  40780. return Rectangle<int> (headerCell.getX(), row.getY(),
  40781. headerCell.getWidth(), row.getHeight());
  40782. }
  40783. void TableListBox::scrollToEnsureColumnIsOnscreen (const int columnId)
  40784. {
  40785. ScrollBar* const scrollbar = getHorizontalScrollBar();
  40786. if (scrollbar != 0)
  40787. {
  40788. const Rectangle<int> pos (header->getColumnPosition (header->getIndexOfColumnId (columnId, true)));
  40789. double x = scrollbar->getCurrentRangeStart();
  40790. const double w = scrollbar->getCurrentRangeSize();
  40791. if (pos.getX() < x)
  40792. x = pos.getX();
  40793. else if (pos.getRight() > x + w)
  40794. x += jmax (0.0, pos.getRight() - (x + w));
  40795. scrollbar->setCurrentRangeStart (x);
  40796. }
  40797. }
  40798. int TableListBox::getNumRows()
  40799. {
  40800. return model != 0 ? model->getNumRows() : 0;
  40801. }
  40802. void TableListBox::paintListBoxItem (int, Graphics&, int, int, bool)
  40803. {
  40804. }
  40805. Component* TableListBox::refreshComponentForRow (int rowNumber, bool isRowSelected_, Component* existingComponentToUpdate)
  40806. {
  40807. if (existingComponentToUpdate == 0)
  40808. existingComponentToUpdate = new TableListRowComp (*this);
  40809. ((TableListRowComp*) existingComponentToUpdate)->update (rowNumber, isRowSelected_);
  40810. return existingComponentToUpdate;
  40811. }
  40812. void TableListBox::selectedRowsChanged (int row)
  40813. {
  40814. if (model != 0)
  40815. model->selectedRowsChanged (row);
  40816. }
  40817. void TableListBox::deleteKeyPressed (int row)
  40818. {
  40819. if (model != 0)
  40820. model->deleteKeyPressed (row);
  40821. }
  40822. void TableListBox::returnKeyPressed (int row)
  40823. {
  40824. if (model != 0)
  40825. model->returnKeyPressed (row);
  40826. }
  40827. void TableListBox::backgroundClicked()
  40828. {
  40829. if (model != 0)
  40830. model->backgroundClicked();
  40831. }
  40832. void TableListBox::listWasScrolled()
  40833. {
  40834. if (model != 0)
  40835. model->listWasScrolled();
  40836. }
  40837. void TableListBox::tableColumnsChanged (TableHeaderComponent*)
  40838. {
  40839. setMinimumContentWidth (header->getTotalWidth());
  40840. repaint();
  40841. updateColumnComponents();
  40842. }
  40843. void TableListBox::tableColumnsResized (TableHeaderComponent*)
  40844. {
  40845. setMinimumContentWidth (header->getTotalWidth());
  40846. repaint();
  40847. updateColumnComponents();
  40848. }
  40849. void TableListBox::tableSortOrderChanged (TableHeaderComponent*)
  40850. {
  40851. if (model != 0)
  40852. model->sortOrderChanged (header->getSortColumnId(),
  40853. header->isSortedForwards());
  40854. }
  40855. void TableListBox::tableColumnDraggingChanged (TableHeaderComponent*, int columnIdNowBeingDragged_)
  40856. {
  40857. columnIdNowBeingDragged = columnIdNowBeingDragged_;
  40858. repaint();
  40859. }
  40860. void TableListBox::resized()
  40861. {
  40862. ListBox::resized();
  40863. header->resizeAllColumnsToFit (getVisibleContentWidth());
  40864. setMinimumContentWidth (header->getTotalWidth());
  40865. }
  40866. void TableListBox::updateColumnComponents() const
  40867. {
  40868. const int firstRow = getRowContainingPosition (0, 0);
  40869. for (int i = firstRow + getNumRowsOnScreen() + 2; --i >= firstRow;)
  40870. {
  40871. TableListRowComp* const rowComp = dynamic_cast <TableListRowComp*> (getComponentForRowNumber (i));
  40872. if (rowComp != 0)
  40873. rowComp->resized();
  40874. }
  40875. }
  40876. void TableListBoxModel::cellClicked (int, int, const MouseEvent&)
  40877. {
  40878. }
  40879. void TableListBoxModel::cellDoubleClicked (int, int, const MouseEvent&)
  40880. {
  40881. }
  40882. void TableListBoxModel::backgroundClicked()
  40883. {
  40884. }
  40885. void TableListBoxModel::sortOrderChanged (int, const bool)
  40886. {
  40887. }
  40888. int TableListBoxModel::getColumnAutoSizeWidth (int)
  40889. {
  40890. return 0;
  40891. }
  40892. void TableListBoxModel::selectedRowsChanged (int)
  40893. {
  40894. }
  40895. void TableListBoxModel::deleteKeyPressed (int)
  40896. {
  40897. }
  40898. void TableListBoxModel::returnKeyPressed (int)
  40899. {
  40900. }
  40901. void TableListBoxModel::listWasScrolled()
  40902. {
  40903. }
  40904. const String TableListBoxModel::getCellTooltip (int /*rowNumber*/, int /*columnId*/)
  40905. {
  40906. return String::empty;
  40907. }
  40908. const String TableListBoxModel::getDragSourceDescription (const SparseSet<int>&)
  40909. {
  40910. return String::empty;
  40911. }
  40912. Component* TableListBoxModel::refreshComponentForCell (int, int, bool, Component* existingComponentToUpdate)
  40913. {
  40914. (void) existingComponentToUpdate;
  40915. jassert (existingComponentToUpdate == 0); // indicates a failure in the code the recycles the components
  40916. return 0;
  40917. }
  40918. END_JUCE_NAMESPACE
  40919. /*** End of inlined file: juce_TableListBox.cpp ***/
  40920. /*** Start of inlined file: juce_TextEditor.cpp ***/
  40921. BEGIN_JUCE_NAMESPACE
  40922. // a word or space that can't be broken down any further
  40923. struct TextAtom
  40924. {
  40925. String atomText;
  40926. float width;
  40927. uint16 numChars;
  40928. bool isWhitespace() const { return CharacterFunctions::isWhitespace (atomText[0]); }
  40929. bool isNewLine() const { return atomText[0] == T('\r') || atomText[0] == T('\n'); }
  40930. const String getText (const tchar passwordCharacter) const
  40931. {
  40932. if (passwordCharacter == 0)
  40933. return atomText;
  40934. else
  40935. return String::repeatedString (String::charToString (passwordCharacter),
  40936. atomText.length());
  40937. }
  40938. const String getTrimmedText (const tchar passwordCharacter) const
  40939. {
  40940. if (passwordCharacter == 0)
  40941. return atomText.substring (0, numChars);
  40942. else if (isNewLine())
  40943. return String::empty;
  40944. else
  40945. return String::repeatedString (String::charToString (passwordCharacter), numChars);
  40946. }
  40947. };
  40948. // a run of text with a single font and colour
  40949. class UniformTextSection
  40950. {
  40951. public:
  40952. UniformTextSection (const String& text,
  40953. const Font& font_,
  40954. const Colour& colour_,
  40955. const tchar passwordCharacter)
  40956. : font (font_),
  40957. colour (colour_)
  40958. {
  40959. initialiseAtoms (text, passwordCharacter);
  40960. }
  40961. UniformTextSection (const UniformTextSection& other)
  40962. : font (other.font),
  40963. colour (other.colour)
  40964. {
  40965. atoms.ensureStorageAllocated (other.atoms.size());
  40966. for (int i = 0; i < other.atoms.size(); ++i)
  40967. atoms.add (new TextAtom (*(const TextAtom*) other.atoms.getUnchecked(i)));
  40968. }
  40969. ~UniformTextSection()
  40970. {
  40971. // (no need to delete the atoms, as they're explicitly deleted by the caller)
  40972. }
  40973. void clear()
  40974. {
  40975. for (int i = atoms.size(); --i >= 0;)
  40976. delete getAtom(i);
  40977. atoms.clear();
  40978. }
  40979. int getNumAtoms() const
  40980. {
  40981. return atoms.size();
  40982. }
  40983. TextAtom* getAtom (const int index) const
  40984. {
  40985. return (TextAtom*) atoms.getUnchecked (index);
  40986. }
  40987. void append (const UniformTextSection& other, const tchar passwordCharacter)
  40988. {
  40989. if (other.atoms.size() > 0)
  40990. {
  40991. TextAtom* const lastAtom = (TextAtom*) atoms.getLast();
  40992. int i = 0;
  40993. if (lastAtom != 0)
  40994. {
  40995. if (! CharacterFunctions::isWhitespace (lastAtom->atomText.getLastCharacter()))
  40996. {
  40997. TextAtom* const first = other.getAtom(0);
  40998. if (! CharacterFunctions::isWhitespace (first->atomText[0]))
  40999. {
  41000. lastAtom->atomText += first->atomText;
  41001. lastAtom->numChars = (uint16) (lastAtom->numChars + first->numChars);
  41002. lastAtom->width = font.getStringWidthFloat (lastAtom->getText (passwordCharacter));
  41003. delete first;
  41004. ++i;
  41005. }
  41006. }
  41007. }
  41008. atoms.ensureStorageAllocated (atoms.size() + other.atoms.size() - i);
  41009. while (i < other.atoms.size())
  41010. {
  41011. atoms.add (other.getAtom(i));
  41012. ++i;
  41013. }
  41014. }
  41015. }
  41016. UniformTextSection* split (const int indexToBreakAt,
  41017. const tchar passwordCharacter)
  41018. {
  41019. UniformTextSection* const section2 = new UniformTextSection (String::empty,
  41020. font, colour,
  41021. passwordCharacter);
  41022. int index = 0;
  41023. for (int i = 0; i < atoms.size(); ++i)
  41024. {
  41025. TextAtom* const atom = getAtom(i);
  41026. const int nextIndex = index + atom->numChars;
  41027. if (index == indexToBreakAt)
  41028. {
  41029. int j;
  41030. for (j = i; j < atoms.size(); ++j)
  41031. section2->atoms.add (getAtom (j));
  41032. for (j = atoms.size(); --j >= i;)
  41033. atoms.remove (j);
  41034. break;
  41035. }
  41036. else if (indexToBreakAt >= index && indexToBreakAt < nextIndex)
  41037. {
  41038. TextAtom* const secondAtom = new TextAtom();
  41039. secondAtom->atomText = atom->atomText.substring (indexToBreakAt - index);
  41040. secondAtom->width = font.getStringWidthFloat (secondAtom->getText (passwordCharacter));
  41041. secondAtom->numChars = (uint16) secondAtom->atomText.length();
  41042. section2->atoms.add (secondAtom);
  41043. atom->atomText = atom->atomText.substring (0, indexToBreakAt - index);
  41044. atom->width = font.getStringWidthFloat (atom->getText (passwordCharacter));
  41045. atom->numChars = (uint16) (indexToBreakAt - index);
  41046. int j;
  41047. for (j = i + 1; j < atoms.size(); ++j)
  41048. section2->atoms.add (getAtom (j));
  41049. for (j = atoms.size(); --j > i;)
  41050. atoms.remove (j);
  41051. break;
  41052. }
  41053. index = nextIndex;
  41054. }
  41055. return section2;
  41056. }
  41057. void appendAllText (String::Concatenator& concatenator) const
  41058. {
  41059. for (int i = 0; i < atoms.size(); ++i)
  41060. concatenator.append (getAtom(i)->atomText);
  41061. }
  41062. void appendSubstring (String::Concatenator& concatenator,
  41063. const Range<int>& range) const
  41064. {
  41065. int index = 0;
  41066. for (int i = 0; i < atoms.size(); ++i)
  41067. {
  41068. const TextAtom* const atom = getAtom (i);
  41069. const int nextIndex = index + atom->numChars;
  41070. if (range.getStart() < nextIndex)
  41071. {
  41072. if (range.getEnd() <= index)
  41073. break;
  41074. const Range<int> r ((range - index).getIntersectionWith (Range<int> (0, (int) atom->numChars)));
  41075. if (! r.isEmpty())
  41076. concatenator.append (atom->atomText.substring (r.getStart(), r.getEnd()));
  41077. }
  41078. index = nextIndex;
  41079. }
  41080. }
  41081. int getTotalLength() const
  41082. {
  41083. int total = 0;
  41084. for (int i = atoms.size(); --i >= 0;)
  41085. total += getAtom(i)->numChars;
  41086. return total;
  41087. }
  41088. void setFont (const Font& newFont,
  41089. const tchar passwordCharacter)
  41090. {
  41091. if (font != newFont)
  41092. {
  41093. font = newFont;
  41094. for (int i = atoms.size(); --i >= 0;)
  41095. {
  41096. TextAtom* const atom = (TextAtom*) atoms.getUnchecked(i);
  41097. atom->width = newFont.getStringWidthFloat (atom->getText (passwordCharacter));
  41098. }
  41099. }
  41100. }
  41101. juce_UseDebuggingNewOperator
  41102. Font font;
  41103. Colour colour;
  41104. private:
  41105. VoidArray atoms;
  41106. void initialiseAtoms (const String& textToParse,
  41107. const tchar passwordCharacter)
  41108. {
  41109. int i = 0;
  41110. const int len = textToParse.length();
  41111. const tchar* const text = (const tchar*) textToParse;
  41112. while (i < len)
  41113. {
  41114. int start = i;
  41115. // create a whitespace atom unless it starts with non-ws
  41116. if (CharacterFunctions::isWhitespace (text[i])
  41117. && text[i] != T('\r')
  41118. && text[i] != T('\n'))
  41119. {
  41120. while (i < len
  41121. && CharacterFunctions::isWhitespace (text[i])
  41122. && text[i] != T('\r')
  41123. && text[i] != T('\n'))
  41124. {
  41125. ++i;
  41126. }
  41127. }
  41128. else
  41129. {
  41130. if (text[i] == T('\r'))
  41131. {
  41132. ++i;
  41133. if ((i < len) && (text[i] == T('\n')))
  41134. {
  41135. ++start;
  41136. ++i;
  41137. }
  41138. }
  41139. else if (text[i] == T('\n'))
  41140. {
  41141. ++i;
  41142. }
  41143. else
  41144. {
  41145. while ((i < len) && ! CharacterFunctions::isWhitespace (text[i]))
  41146. ++i;
  41147. }
  41148. }
  41149. TextAtom* const atom = new TextAtom();
  41150. atom->atomText = String (text + start, i - start);
  41151. atom->width = font.getStringWidthFloat (atom->getText (passwordCharacter));
  41152. atom->numChars = (uint16) (i - start);
  41153. atoms.add (atom);
  41154. }
  41155. }
  41156. UniformTextSection& operator= (const UniformTextSection& other);
  41157. };
  41158. class TextEditorIterator
  41159. {
  41160. public:
  41161. TextEditorIterator (const VoidArray& sections_,
  41162. const float wordWrapWidth_,
  41163. const tchar passwordCharacter_)
  41164. : indexInText (0),
  41165. lineY (0),
  41166. lineHeight (0),
  41167. maxDescent (0),
  41168. atomX (0),
  41169. atomRight (0),
  41170. atom (0),
  41171. currentSection (0),
  41172. sections (sections_),
  41173. sectionIndex (0),
  41174. atomIndex (0),
  41175. wordWrapWidth (wordWrapWidth_),
  41176. passwordCharacter (passwordCharacter_)
  41177. {
  41178. jassert (wordWrapWidth_ > 0);
  41179. if (sections.size() > 0)
  41180. {
  41181. currentSection = (const UniformTextSection*) sections.getUnchecked (sectionIndex);
  41182. if (currentSection != 0)
  41183. beginNewLine();
  41184. }
  41185. }
  41186. TextEditorIterator (const TextEditorIterator& other)
  41187. : indexInText (other.indexInText),
  41188. lineY (other.lineY),
  41189. lineHeight (other.lineHeight),
  41190. maxDescent (other.maxDescent),
  41191. atomX (other.atomX),
  41192. atomRight (other.atomRight),
  41193. atom (other.atom),
  41194. currentSection (other.currentSection),
  41195. sections (other.sections),
  41196. sectionIndex (other.sectionIndex),
  41197. atomIndex (other.atomIndex),
  41198. wordWrapWidth (other.wordWrapWidth),
  41199. passwordCharacter (other.passwordCharacter),
  41200. tempAtom (other.tempAtom)
  41201. {
  41202. }
  41203. ~TextEditorIterator()
  41204. {
  41205. }
  41206. bool next()
  41207. {
  41208. if (atom == &tempAtom)
  41209. {
  41210. const int numRemaining = tempAtom.atomText.length() - tempAtom.numChars;
  41211. if (numRemaining > 0)
  41212. {
  41213. tempAtom.atomText = tempAtom.atomText.substring (tempAtom.numChars);
  41214. atomX = 0;
  41215. if (tempAtom.numChars > 0)
  41216. lineY += lineHeight;
  41217. indexInText += tempAtom.numChars;
  41218. GlyphArrangement g;
  41219. g.addLineOfText (currentSection->font, atom->getText (passwordCharacter), 0.0f, 0.0f);
  41220. int split;
  41221. for (split = 0; split < g.getNumGlyphs(); ++split)
  41222. if (shouldWrap (g.getGlyph (split).getRight()))
  41223. break;
  41224. if (split > 0 && split <= numRemaining)
  41225. {
  41226. tempAtom.numChars = (uint16) split;
  41227. tempAtom.width = g.getGlyph (split - 1).getRight();
  41228. atomRight = atomX + tempAtom.width;
  41229. return true;
  41230. }
  41231. }
  41232. }
  41233. bool forceNewLine = false;
  41234. if (sectionIndex >= sections.size())
  41235. {
  41236. moveToEndOfLastAtom();
  41237. return false;
  41238. }
  41239. else if (atomIndex >= currentSection->getNumAtoms() - 1)
  41240. {
  41241. if (atomIndex >= currentSection->getNumAtoms())
  41242. {
  41243. if (++sectionIndex >= sections.size())
  41244. {
  41245. moveToEndOfLastAtom();
  41246. return false;
  41247. }
  41248. atomIndex = 0;
  41249. currentSection = (const UniformTextSection*) sections.getUnchecked (sectionIndex);
  41250. }
  41251. else
  41252. {
  41253. const TextAtom* const lastAtom = currentSection->getAtom (atomIndex);
  41254. if (! lastAtom->isWhitespace())
  41255. {
  41256. // handle the case where the last atom in a section is actually part of the same
  41257. // word as the first atom of the next section...
  41258. float right = atomRight + lastAtom->width;
  41259. float lineHeight2 = lineHeight;
  41260. float maxDescent2 = maxDescent;
  41261. for (int section = sectionIndex + 1; section < sections.size(); ++section)
  41262. {
  41263. const UniformTextSection* const s = (const UniformTextSection*) sections.getUnchecked (section);
  41264. if (s->getNumAtoms() == 0)
  41265. break;
  41266. const TextAtom* const nextAtom = s->getAtom (0);
  41267. if (nextAtom->isWhitespace())
  41268. break;
  41269. right += nextAtom->width;
  41270. lineHeight2 = jmax (lineHeight2, s->font.getHeight());
  41271. maxDescent2 = jmax (maxDescent2, s->font.getDescent());
  41272. if (shouldWrap (right))
  41273. {
  41274. lineHeight = lineHeight2;
  41275. maxDescent = maxDescent2;
  41276. forceNewLine = true;
  41277. break;
  41278. }
  41279. if (s->getNumAtoms() > 1)
  41280. break;
  41281. }
  41282. }
  41283. }
  41284. }
  41285. if (atom != 0)
  41286. {
  41287. atomX = atomRight;
  41288. indexInText += atom->numChars;
  41289. if (atom->isNewLine())
  41290. beginNewLine();
  41291. }
  41292. atom = currentSection->getAtom (atomIndex);
  41293. atomRight = atomX + atom->width;
  41294. ++atomIndex;
  41295. if (shouldWrap (atomRight) || forceNewLine)
  41296. {
  41297. if (atom->isWhitespace())
  41298. {
  41299. // leave whitespace at the end of a line, but truncate it to avoid scrolling
  41300. atomRight = jmin (atomRight, wordWrapWidth);
  41301. }
  41302. else
  41303. {
  41304. atomRight = atom->width;
  41305. if (shouldWrap (atomRight)) // atom too big to fit on a line, so break it up..
  41306. {
  41307. tempAtom = *atom;
  41308. tempAtom.width = 0;
  41309. tempAtom.numChars = 0;
  41310. atom = &tempAtom;
  41311. if (atomX > 0)
  41312. beginNewLine();
  41313. return next();
  41314. }
  41315. beginNewLine();
  41316. return true;
  41317. }
  41318. }
  41319. return true;
  41320. }
  41321. void beginNewLine()
  41322. {
  41323. atomX = 0;
  41324. lineY += lineHeight;
  41325. int tempSectionIndex = sectionIndex;
  41326. int tempAtomIndex = atomIndex;
  41327. const UniformTextSection* section = (const UniformTextSection*) sections.getUnchecked (tempSectionIndex);
  41328. lineHeight = section->font.getHeight();
  41329. maxDescent = section->font.getDescent();
  41330. float x = (atom != 0) ? atom->width : 0;
  41331. while (! shouldWrap (x))
  41332. {
  41333. if (tempSectionIndex >= sections.size())
  41334. break;
  41335. bool checkSize = false;
  41336. if (tempAtomIndex >= section->getNumAtoms())
  41337. {
  41338. if (++tempSectionIndex >= sections.size())
  41339. break;
  41340. tempAtomIndex = 0;
  41341. section = (const UniformTextSection*) sections.getUnchecked (tempSectionIndex);
  41342. checkSize = true;
  41343. }
  41344. const TextAtom* const nextAtom = section->getAtom (tempAtomIndex);
  41345. if (nextAtom == 0)
  41346. break;
  41347. x += nextAtom->width;
  41348. if (shouldWrap (x) || nextAtom->isNewLine())
  41349. break;
  41350. if (checkSize)
  41351. {
  41352. lineHeight = jmax (lineHeight, section->font.getHeight());
  41353. maxDescent = jmax (maxDescent, section->font.getDescent());
  41354. }
  41355. ++tempAtomIndex;
  41356. }
  41357. }
  41358. void draw (Graphics& g, const UniformTextSection*& lastSection) const
  41359. {
  41360. if (passwordCharacter != 0 || ! atom->isWhitespace())
  41361. {
  41362. if (lastSection != currentSection)
  41363. {
  41364. lastSection = currentSection;
  41365. g.setColour (currentSection->colour);
  41366. g.setFont (currentSection->font);
  41367. }
  41368. jassert (atom->getTrimmedText (passwordCharacter).isNotEmpty());
  41369. GlyphArrangement ga;
  41370. ga.addLineOfText (currentSection->font,
  41371. atom->getTrimmedText (passwordCharacter),
  41372. atomX,
  41373. (float) roundToInt (lineY + lineHeight - maxDescent));
  41374. ga.draw (g);
  41375. }
  41376. }
  41377. void drawSelection (Graphics& g,
  41378. const Range<int>& selection) const
  41379. {
  41380. const int startX = roundToInt (indexToX (selection.getStart()));
  41381. const int endX = roundToInt (indexToX (selection.getEnd()));
  41382. const int y = roundToInt (lineY);
  41383. const int nextY = roundToInt (lineY + lineHeight);
  41384. g.fillRect (startX, y, endX - startX, nextY - y);
  41385. }
  41386. void drawSelectedText (Graphics& g,
  41387. const Range<int>& selection,
  41388. const Colour& selectedTextColour) const
  41389. {
  41390. if (passwordCharacter != 0 || ! atom->isWhitespace())
  41391. {
  41392. GlyphArrangement ga;
  41393. ga.addLineOfText (currentSection->font,
  41394. atom->getTrimmedText (passwordCharacter),
  41395. atomX,
  41396. (float) roundToInt (lineY + lineHeight - maxDescent));
  41397. if (selection.getEnd() < indexInText + atom->numChars)
  41398. {
  41399. GlyphArrangement ga2 (ga);
  41400. ga2.removeRangeOfGlyphs (0, selection.getEnd() - indexInText);
  41401. ga.removeRangeOfGlyphs (selection.getEnd() - indexInText, -1);
  41402. g.setColour (currentSection->colour);
  41403. ga2.draw (g);
  41404. }
  41405. if (selection.getStart() > indexInText)
  41406. {
  41407. GlyphArrangement ga2 (ga);
  41408. ga2.removeRangeOfGlyphs (selection.getStart() - indexInText, -1);
  41409. ga.removeRangeOfGlyphs (0, selection.getStart() - indexInText);
  41410. g.setColour (currentSection->colour);
  41411. ga2.draw (g);
  41412. }
  41413. g.setColour (selectedTextColour);
  41414. ga.draw (g);
  41415. }
  41416. }
  41417. float indexToX (const int indexToFind) const
  41418. {
  41419. if (indexToFind <= indexInText)
  41420. return atomX;
  41421. if (indexToFind >= indexInText + atom->numChars)
  41422. return atomRight;
  41423. GlyphArrangement g;
  41424. g.addLineOfText (currentSection->font,
  41425. atom->getText (passwordCharacter),
  41426. atomX, 0.0f);
  41427. if (indexToFind - indexInText >= g.getNumGlyphs())
  41428. return atomRight;
  41429. return jmin (atomRight, g.getGlyph (indexToFind - indexInText).getLeft());
  41430. }
  41431. int xToIndex (const float xToFind) const
  41432. {
  41433. if (xToFind <= atomX || atom->isNewLine())
  41434. return indexInText;
  41435. if (xToFind >= atomRight)
  41436. return indexInText + atom->numChars;
  41437. GlyphArrangement g;
  41438. g.addLineOfText (currentSection->font,
  41439. atom->getText (passwordCharacter),
  41440. atomX, 0.0f);
  41441. int j;
  41442. for (j = 0; j < g.getNumGlyphs(); ++j)
  41443. if ((g.getGlyph(j).getLeft() + g.getGlyph(j).getRight()) / 2 > xToFind)
  41444. break;
  41445. return indexInText + j;
  41446. }
  41447. bool getCharPosition (const int index, float& cx, float& cy, float& lineHeight_)
  41448. {
  41449. while (next())
  41450. {
  41451. if (indexInText + atom->numChars > index)
  41452. {
  41453. cx = indexToX (index);
  41454. cy = lineY;
  41455. lineHeight_ = lineHeight;
  41456. return true;
  41457. }
  41458. }
  41459. cx = atomX;
  41460. cy = lineY;
  41461. lineHeight_ = lineHeight;
  41462. return false;
  41463. }
  41464. juce_UseDebuggingNewOperator
  41465. int indexInText;
  41466. float lineY, lineHeight, maxDescent;
  41467. float atomX, atomRight;
  41468. const TextAtom* atom;
  41469. const UniformTextSection* currentSection;
  41470. private:
  41471. const VoidArray& sections;
  41472. int sectionIndex, atomIndex;
  41473. const float wordWrapWidth;
  41474. const tchar passwordCharacter;
  41475. TextAtom tempAtom;
  41476. TextEditorIterator& operator= (const TextEditorIterator&);
  41477. void moveToEndOfLastAtom()
  41478. {
  41479. if (atom != 0)
  41480. {
  41481. atomX = atomRight;
  41482. if (atom->isNewLine())
  41483. {
  41484. atomX = 0.0f;
  41485. lineY += lineHeight;
  41486. }
  41487. }
  41488. }
  41489. bool shouldWrap (const float x) const
  41490. {
  41491. return (x - 0.0001f) >= wordWrapWidth;
  41492. }
  41493. };
  41494. class TextEditorInsertAction : public UndoableAction
  41495. {
  41496. TextEditor& owner;
  41497. const String text;
  41498. const int insertIndex, oldCaretPos, newCaretPos;
  41499. const Font font;
  41500. const Colour colour;
  41501. TextEditorInsertAction (const TextEditorInsertAction&);
  41502. TextEditorInsertAction& operator= (const TextEditorInsertAction&);
  41503. public:
  41504. TextEditorInsertAction (TextEditor& owner_,
  41505. const String& text_,
  41506. const int insertIndex_,
  41507. const Font& font_,
  41508. const Colour& colour_,
  41509. const int oldCaretPos_,
  41510. const int newCaretPos_)
  41511. : owner (owner_),
  41512. text (text_),
  41513. insertIndex (insertIndex_),
  41514. oldCaretPos (oldCaretPos_),
  41515. newCaretPos (newCaretPos_),
  41516. font (font_),
  41517. colour (colour_)
  41518. {
  41519. }
  41520. ~TextEditorInsertAction()
  41521. {
  41522. }
  41523. bool perform()
  41524. {
  41525. owner.insert (text, insertIndex, font, colour, 0, newCaretPos);
  41526. return true;
  41527. }
  41528. bool undo()
  41529. {
  41530. owner.remove (Range<int> (insertIndex, insertIndex + text.length()), 0, oldCaretPos);
  41531. return true;
  41532. }
  41533. int getSizeInUnits()
  41534. {
  41535. return text.length() + 16;
  41536. }
  41537. };
  41538. class TextEditorRemoveAction : public UndoableAction
  41539. {
  41540. TextEditor& owner;
  41541. const Range<int> range;
  41542. const int oldCaretPos, newCaretPos;
  41543. VoidArray removedSections;
  41544. TextEditorRemoveAction (const TextEditorRemoveAction&);
  41545. TextEditorRemoveAction& operator= (const TextEditorRemoveAction&);
  41546. public:
  41547. TextEditorRemoveAction (TextEditor& owner_,
  41548. const Range<int> range_,
  41549. const int oldCaretPos_,
  41550. const int newCaretPos_,
  41551. const VoidArray& removedSections_)
  41552. : owner (owner_),
  41553. range (range_),
  41554. oldCaretPos (oldCaretPos_),
  41555. newCaretPos (newCaretPos_),
  41556. removedSections (removedSections_)
  41557. {
  41558. }
  41559. ~TextEditorRemoveAction()
  41560. {
  41561. for (int i = removedSections.size(); --i >= 0;)
  41562. {
  41563. UniformTextSection* const section = (UniformTextSection*) removedSections.getUnchecked (i);
  41564. section->clear();
  41565. delete section;
  41566. }
  41567. }
  41568. bool perform()
  41569. {
  41570. owner.remove (range, 0, newCaretPos);
  41571. return true;
  41572. }
  41573. bool undo()
  41574. {
  41575. owner.reinsert (range.getStart(), removedSections);
  41576. owner.moveCursorTo (oldCaretPos, false);
  41577. return true;
  41578. }
  41579. int getSizeInUnits()
  41580. {
  41581. int n = 0;
  41582. for (int i = removedSections.size(); --i >= 0;)
  41583. {
  41584. UniformTextSection* const section = (UniformTextSection*) removedSections.getUnchecked (i);
  41585. n += section->getTotalLength();
  41586. }
  41587. return n + 16;
  41588. }
  41589. };
  41590. class TextHolderComponent : public Component,
  41591. public Timer,
  41592. public Value::Listener
  41593. {
  41594. TextEditor& owner;
  41595. TextHolderComponent (const TextHolderComponent&);
  41596. TextHolderComponent& operator= (const TextHolderComponent&);
  41597. public:
  41598. TextHolderComponent (TextEditor& owner_)
  41599. : owner (owner_)
  41600. {
  41601. setWantsKeyboardFocus (false);
  41602. setInterceptsMouseClicks (false, true);
  41603. owner.getTextValue().addListener (this);
  41604. }
  41605. ~TextHolderComponent()
  41606. {
  41607. owner.getTextValue().removeListener (this);
  41608. }
  41609. void paint (Graphics& g)
  41610. {
  41611. owner.drawContent (g);
  41612. }
  41613. void timerCallback()
  41614. {
  41615. owner.timerCallbackInt();
  41616. }
  41617. const MouseCursor getMouseCursor()
  41618. {
  41619. return owner.getMouseCursor();
  41620. }
  41621. void valueChanged (Value&)
  41622. {
  41623. owner.textWasChangedByValue();
  41624. }
  41625. };
  41626. class TextEditorViewport : public Viewport
  41627. {
  41628. TextEditor* const owner;
  41629. float lastWordWrapWidth;
  41630. TextEditorViewport (const TextEditorViewport&);
  41631. TextEditorViewport& operator= (const TextEditorViewport&);
  41632. public:
  41633. TextEditorViewport (TextEditor* const owner_)
  41634. : owner (owner_),
  41635. lastWordWrapWidth (0)
  41636. {
  41637. }
  41638. ~TextEditorViewport()
  41639. {
  41640. }
  41641. void visibleAreaChanged (int, int, int, int)
  41642. {
  41643. const float wordWrapWidth = owner->getWordWrapWidth();
  41644. if (wordWrapWidth != lastWordWrapWidth)
  41645. {
  41646. lastWordWrapWidth = wordWrapWidth;
  41647. owner->updateTextHolderSize();
  41648. }
  41649. }
  41650. };
  41651. namespace TextEditorDefs
  41652. {
  41653. const int flashSpeedIntervalMs = 380;
  41654. const int textChangeMessageId = 0x10003001;
  41655. const int returnKeyMessageId = 0x10003002;
  41656. const int escapeKeyMessageId = 0x10003003;
  41657. const int focusLossMessageId = 0x10003004;
  41658. const int maxActionsPerTransaction = 100;
  41659. }
  41660. TextEditor::TextEditor (const String& name,
  41661. const tchar passwordCharacter_)
  41662. : Component (name),
  41663. borderSize (1, 1, 1, 3),
  41664. readOnly (false),
  41665. multiline (false),
  41666. wordWrap (false),
  41667. returnKeyStartsNewLine (false),
  41668. caretVisible (true),
  41669. popupMenuEnabled (true),
  41670. selectAllTextWhenFocused (false),
  41671. scrollbarVisible (true),
  41672. wasFocused (false),
  41673. caretFlashState (true),
  41674. keepCursorOnScreen (true),
  41675. tabKeyUsed (false),
  41676. menuActive (false),
  41677. valueTextNeedsUpdating (false),
  41678. cursorX (0),
  41679. cursorY (0),
  41680. cursorHeight (0),
  41681. maxTextLength (0),
  41682. leftIndent (4),
  41683. topIndent (4),
  41684. lastTransactionTime (0),
  41685. currentFont (14.0f),
  41686. totalNumChars (0),
  41687. caretPosition (0),
  41688. passwordCharacter (passwordCharacter_),
  41689. dragType (notDragging)
  41690. {
  41691. setOpaque (true);
  41692. addAndMakeVisible (viewport = new TextEditorViewport (this));
  41693. viewport->setViewedComponent (textHolder = new TextHolderComponent (*this));
  41694. viewport->setWantsKeyboardFocus (false);
  41695. viewport->setScrollBarsShown (false, false);
  41696. setMouseCursor (MouseCursor::IBeamCursor);
  41697. setWantsKeyboardFocus (true);
  41698. }
  41699. TextEditor::~TextEditor()
  41700. {
  41701. textValue.referTo (Value());
  41702. clearInternal (0);
  41703. viewport = 0;
  41704. textHolder = 0;
  41705. }
  41706. void TextEditor::newTransaction()
  41707. {
  41708. lastTransactionTime = Time::getApproximateMillisecondCounter();
  41709. undoManager.beginNewTransaction();
  41710. }
  41711. void TextEditor::doUndoRedo (const bool isRedo)
  41712. {
  41713. if (! isReadOnly())
  41714. {
  41715. if (isRedo ? undoManager.redo()
  41716. : undoManager.undo())
  41717. {
  41718. scrollToMakeSureCursorIsVisible();
  41719. repaint();
  41720. textChanged();
  41721. }
  41722. }
  41723. }
  41724. void TextEditor::setMultiLine (const bool shouldBeMultiLine,
  41725. const bool shouldWordWrap)
  41726. {
  41727. multiline = shouldBeMultiLine;
  41728. wordWrap = shouldWordWrap && shouldBeMultiLine;
  41729. setScrollbarsShown (scrollbarVisible);
  41730. viewport->setViewPosition (0, 0);
  41731. resized();
  41732. scrollToMakeSureCursorIsVisible();
  41733. }
  41734. bool TextEditor::isMultiLine() const
  41735. {
  41736. return multiline;
  41737. }
  41738. void TextEditor::setScrollbarsShown (bool enabled)
  41739. {
  41740. scrollbarVisible = enabled;
  41741. enabled = enabled && isMultiLine();
  41742. viewport->setScrollBarsShown (enabled, enabled);
  41743. }
  41744. void TextEditor::setReadOnly (const bool shouldBeReadOnly)
  41745. {
  41746. readOnly = shouldBeReadOnly;
  41747. enablementChanged();
  41748. }
  41749. bool TextEditor::isReadOnly() const
  41750. {
  41751. return readOnly || ! isEnabled();
  41752. }
  41753. void TextEditor::setReturnKeyStartsNewLine (const bool shouldStartNewLine)
  41754. {
  41755. returnKeyStartsNewLine = shouldStartNewLine;
  41756. }
  41757. void TextEditor::setTabKeyUsedAsCharacter (const bool shouldTabKeyBeUsed)
  41758. {
  41759. tabKeyUsed = shouldTabKeyBeUsed;
  41760. }
  41761. void TextEditor::setPopupMenuEnabled (const bool b)
  41762. {
  41763. popupMenuEnabled = b;
  41764. }
  41765. void TextEditor::setSelectAllWhenFocused (const bool b)
  41766. {
  41767. selectAllTextWhenFocused = b;
  41768. }
  41769. const Font TextEditor::getFont() const
  41770. {
  41771. return currentFont;
  41772. }
  41773. void TextEditor::setFont (const Font& newFont)
  41774. {
  41775. currentFont = newFont;
  41776. scrollToMakeSureCursorIsVisible();
  41777. }
  41778. void TextEditor::applyFontToAllText (const Font& newFont)
  41779. {
  41780. currentFont = newFont;
  41781. const Colour overallColour (findColour (textColourId));
  41782. for (int i = sections.size(); --i >= 0;)
  41783. {
  41784. UniformTextSection* const uts = (UniformTextSection*) sections.getUnchecked(i);
  41785. uts->setFont (newFont, passwordCharacter);
  41786. uts->colour = overallColour;
  41787. }
  41788. coalesceSimilarSections();
  41789. updateTextHolderSize();
  41790. scrollToMakeSureCursorIsVisible();
  41791. repaint();
  41792. }
  41793. void TextEditor::colourChanged()
  41794. {
  41795. setOpaque (findColour (backgroundColourId).isOpaque());
  41796. repaint();
  41797. }
  41798. void TextEditor::setCaretVisible (const bool shouldCaretBeVisible)
  41799. {
  41800. caretVisible = shouldCaretBeVisible;
  41801. if (shouldCaretBeVisible)
  41802. textHolder->startTimer (TextEditorDefs::flashSpeedIntervalMs);
  41803. setMouseCursor (shouldCaretBeVisible ? MouseCursor::IBeamCursor
  41804. : MouseCursor::NormalCursor);
  41805. }
  41806. void TextEditor::setInputRestrictions (const int maxLen,
  41807. const String& chars)
  41808. {
  41809. maxTextLength = jmax (0, maxLen);
  41810. allowedCharacters = chars;
  41811. }
  41812. void TextEditor::setTextToShowWhenEmpty (const String& text, const Colour& colourToUse)
  41813. {
  41814. textToShowWhenEmpty = text;
  41815. colourForTextWhenEmpty = colourToUse;
  41816. }
  41817. void TextEditor::setPasswordCharacter (const tchar newPasswordCharacter)
  41818. {
  41819. if (passwordCharacter != newPasswordCharacter)
  41820. {
  41821. passwordCharacter = newPasswordCharacter;
  41822. resized();
  41823. repaint();
  41824. }
  41825. }
  41826. void TextEditor::setScrollBarThickness (const int newThicknessPixels)
  41827. {
  41828. viewport->setScrollBarThickness (newThicknessPixels);
  41829. }
  41830. void TextEditor::setScrollBarButtonVisibility (const bool buttonsVisible)
  41831. {
  41832. viewport->setScrollBarButtonVisibility (buttonsVisible);
  41833. }
  41834. void TextEditor::clear()
  41835. {
  41836. clearInternal (0);
  41837. updateTextHolderSize();
  41838. undoManager.clearUndoHistory();
  41839. }
  41840. void TextEditor::setText (const String& newText,
  41841. const bool sendTextChangeMessage)
  41842. {
  41843. const int newLength = newText.length();
  41844. if (newLength != getTotalNumChars() || getText() != newText)
  41845. {
  41846. const int oldCursorPos = caretPosition;
  41847. const bool cursorWasAtEnd = oldCursorPos >= getTotalNumChars();
  41848. clearInternal (0);
  41849. insert (newText, 0, currentFont, findColour (textColourId), 0, caretPosition);
  41850. // if you're adding text with line-feeds to a single-line text editor, it
  41851. // ain't gonna look right!
  41852. jassert (multiline || ! newText.containsAnyOf (T("\r\n")));
  41853. if (cursorWasAtEnd && ! isMultiLine())
  41854. moveCursorTo (getTotalNumChars(), false);
  41855. else
  41856. moveCursorTo (oldCursorPos, false);
  41857. if (sendTextChangeMessage)
  41858. textChanged();
  41859. repaint();
  41860. }
  41861. updateTextHolderSize();
  41862. scrollToMakeSureCursorIsVisible();
  41863. undoManager.clearUndoHistory();
  41864. }
  41865. Value& TextEditor::getTextValue()
  41866. {
  41867. if (valueTextNeedsUpdating)
  41868. {
  41869. valueTextNeedsUpdating = false;
  41870. textValue = getText();
  41871. }
  41872. return textValue;
  41873. }
  41874. void TextEditor::textWasChangedByValue()
  41875. {
  41876. if (textValue.getValueSource().getReferenceCount() > 1)
  41877. setText (textValue.getValue());
  41878. }
  41879. void TextEditor::textChanged()
  41880. {
  41881. updateTextHolderSize();
  41882. postCommandMessage (TextEditorDefs::textChangeMessageId);
  41883. if (textValue.getValueSource().getReferenceCount() > 1)
  41884. {
  41885. valueTextNeedsUpdating = false;
  41886. textValue = getText();
  41887. }
  41888. }
  41889. void TextEditor::returnPressed()
  41890. {
  41891. postCommandMessage (TextEditorDefs::returnKeyMessageId);
  41892. }
  41893. void TextEditor::escapePressed()
  41894. {
  41895. postCommandMessage (TextEditorDefs::escapeKeyMessageId);
  41896. }
  41897. void TextEditor::addListener (TextEditorListener* const newListener)
  41898. {
  41899. listeners.add (newListener);
  41900. }
  41901. void TextEditor::removeListener (TextEditorListener* const listenerToRemove)
  41902. {
  41903. listeners.remove (listenerToRemove);
  41904. }
  41905. void TextEditor::timerCallbackInt()
  41906. {
  41907. const bool newState = (! caretFlashState) && ! isCurrentlyBlockedByAnotherModalComponent();
  41908. if (caretFlashState != newState)
  41909. {
  41910. caretFlashState = newState;
  41911. if (caretFlashState)
  41912. wasFocused = true;
  41913. if (caretVisible
  41914. && hasKeyboardFocus (false)
  41915. && ! isReadOnly())
  41916. {
  41917. repaintCaret();
  41918. }
  41919. }
  41920. const unsigned int now = Time::getApproximateMillisecondCounter();
  41921. if (now > lastTransactionTime + 200)
  41922. newTransaction();
  41923. }
  41924. void TextEditor::repaintCaret()
  41925. {
  41926. if (! findColour (caretColourId).isTransparent())
  41927. repaint (borderSize.getLeft() + textHolder->getX() + leftIndent + roundToInt (cursorX) - 1,
  41928. borderSize.getTop() + textHolder->getY() + topIndent + roundToInt (cursorY) - 1,
  41929. 4,
  41930. roundToInt (cursorHeight) + 2);
  41931. }
  41932. void TextEditor::repaintText (const Range<int>& range)
  41933. {
  41934. if (! range.isEmpty())
  41935. {
  41936. float x = 0, y = 0, lh = currentFont.getHeight();
  41937. const float wordWrapWidth = getWordWrapWidth();
  41938. if (wordWrapWidth > 0)
  41939. {
  41940. TextEditorIterator i (sections, wordWrapWidth, passwordCharacter);
  41941. i.getCharPosition (range.getStart(), x, y, lh);
  41942. const int y1 = (int) y;
  41943. int y2;
  41944. if (range.getEnd() >= getTotalNumChars())
  41945. {
  41946. y2 = textHolder->getHeight();
  41947. }
  41948. else
  41949. {
  41950. i.getCharPosition (range.getEnd(), x, y, lh);
  41951. y2 = (int) (y + lh * 2.0f);
  41952. }
  41953. textHolder->repaint (0, y1, textHolder->getWidth(), y2 - y1);
  41954. }
  41955. }
  41956. }
  41957. void TextEditor::moveCaret (int newCaretPos)
  41958. {
  41959. if (newCaretPos < 0)
  41960. newCaretPos = 0;
  41961. else if (newCaretPos > getTotalNumChars())
  41962. newCaretPos = getTotalNumChars();
  41963. if (newCaretPos != getCaretPosition())
  41964. {
  41965. repaintCaret();
  41966. caretFlashState = true;
  41967. caretPosition = newCaretPos;
  41968. textHolder->startTimer (TextEditorDefs::flashSpeedIntervalMs);
  41969. scrollToMakeSureCursorIsVisible();
  41970. repaintCaret();
  41971. }
  41972. }
  41973. void TextEditor::setCaretPosition (const int newIndex)
  41974. {
  41975. moveCursorTo (newIndex, false);
  41976. }
  41977. int TextEditor::getCaretPosition() const
  41978. {
  41979. return caretPosition;
  41980. }
  41981. void TextEditor::scrollEditorToPositionCaret (const int desiredCaretX,
  41982. const int desiredCaretY)
  41983. {
  41984. updateCaretPosition();
  41985. int vx = roundToInt (cursorX) - desiredCaretX;
  41986. int vy = roundToInt (cursorY) - desiredCaretY;
  41987. if (desiredCaretX < jmax (1, proportionOfWidth (0.05f)))
  41988. {
  41989. vx += desiredCaretX - proportionOfWidth (0.2f);
  41990. }
  41991. else if (desiredCaretX > jmax (0, viewport->getMaximumVisibleWidth() - (wordWrap ? 2 : 10)))
  41992. {
  41993. vx += desiredCaretX + (isMultiLine() ? proportionOfWidth (0.2f) : 10) - viewport->getMaximumVisibleWidth();
  41994. }
  41995. vx = jlimit (0, jmax (0, textHolder->getWidth() + 8 - viewport->getMaximumVisibleWidth()), vx);
  41996. if (! isMultiLine())
  41997. {
  41998. vy = viewport->getViewPositionY();
  41999. }
  42000. else
  42001. {
  42002. vy = jlimit (0, jmax (0, textHolder->getHeight() - viewport->getMaximumVisibleHeight()), vy);
  42003. const int curH = roundToInt (cursorHeight);
  42004. if (desiredCaretY < 0)
  42005. {
  42006. vy = jmax (0, desiredCaretY + vy);
  42007. }
  42008. else if (desiredCaretY > jmax (0, viewport->getMaximumVisibleHeight() - topIndent - curH))
  42009. {
  42010. vy += desiredCaretY + 2 + curH + topIndent - viewport->getMaximumVisibleHeight();
  42011. }
  42012. }
  42013. viewport->setViewPosition (vx, vy);
  42014. }
  42015. const Rectangle<int> TextEditor::getCaretRectangle()
  42016. {
  42017. updateCaretPosition();
  42018. return Rectangle<int> (roundToInt (cursorX) - viewport->getX(),
  42019. roundToInt (cursorY) - viewport->getY(),
  42020. 1, roundToInt (cursorHeight));
  42021. }
  42022. float TextEditor::getWordWrapWidth() const
  42023. {
  42024. return (wordWrap) ? (float) (viewport->getMaximumVisibleWidth() - leftIndent - leftIndent / 2)
  42025. : 1.0e10f;
  42026. }
  42027. void TextEditor::updateTextHolderSize()
  42028. {
  42029. const float wordWrapWidth = getWordWrapWidth();
  42030. if (wordWrapWidth > 0)
  42031. {
  42032. float maxWidth = 0.0f;
  42033. TextEditorIterator i (sections, wordWrapWidth, passwordCharacter);
  42034. while (i.next())
  42035. maxWidth = jmax (maxWidth, i.atomRight);
  42036. const int w = leftIndent + roundToInt (maxWidth);
  42037. const int h = topIndent + roundToInt (jmax (i.lineY + i.lineHeight,
  42038. currentFont.getHeight()));
  42039. textHolder->setSize (w + 1, h + 1);
  42040. }
  42041. }
  42042. int TextEditor::getTextWidth() const
  42043. {
  42044. return textHolder->getWidth();
  42045. }
  42046. int TextEditor::getTextHeight() const
  42047. {
  42048. return textHolder->getHeight();
  42049. }
  42050. void TextEditor::setIndents (const int newLeftIndent,
  42051. const int newTopIndent)
  42052. {
  42053. leftIndent = newLeftIndent;
  42054. topIndent = newTopIndent;
  42055. }
  42056. void TextEditor::setBorder (const BorderSize& border)
  42057. {
  42058. borderSize = border;
  42059. resized();
  42060. }
  42061. const BorderSize TextEditor::getBorder() const
  42062. {
  42063. return borderSize;
  42064. }
  42065. void TextEditor::setScrollToShowCursor (const bool shouldScrollToShowCursor)
  42066. {
  42067. keepCursorOnScreen = shouldScrollToShowCursor;
  42068. }
  42069. void TextEditor::updateCaretPosition()
  42070. {
  42071. cursorHeight = currentFont.getHeight(); // (in case the text is empty and the call below doesn't set this value)
  42072. getCharPosition (caretPosition, cursorX, cursorY, cursorHeight);
  42073. }
  42074. void TextEditor::scrollToMakeSureCursorIsVisible()
  42075. {
  42076. updateCaretPosition();
  42077. if (keepCursorOnScreen)
  42078. {
  42079. int x = viewport->getViewPositionX();
  42080. int y = viewport->getViewPositionY();
  42081. const int relativeCursorX = roundToInt (cursorX) - x;
  42082. const int relativeCursorY = roundToInt (cursorY) - y;
  42083. if (relativeCursorX < jmax (1, proportionOfWidth (0.05f)))
  42084. {
  42085. x += relativeCursorX - proportionOfWidth (0.2f);
  42086. }
  42087. else if (relativeCursorX > jmax (0, viewport->getMaximumVisibleWidth() - (wordWrap ? 2 : 10)))
  42088. {
  42089. x += relativeCursorX + (isMultiLine() ? proportionOfWidth (0.2f) : 10) - viewport->getMaximumVisibleWidth();
  42090. }
  42091. x = jlimit (0, jmax (0, textHolder->getWidth() + 8 - viewport->getMaximumVisibleWidth()), x);
  42092. if (! isMultiLine())
  42093. {
  42094. y = (getHeight() - textHolder->getHeight() - topIndent) / -2;
  42095. }
  42096. else
  42097. {
  42098. const int curH = roundToInt (cursorHeight);
  42099. if (relativeCursorY < 0)
  42100. {
  42101. y = jmax (0, relativeCursorY + y);
  42102. }
  42103. else if (relativeCursorY > jmax (0, viewport->getMaximumVisibleHeight() - topIndent - curH))
  42104. {
  42105. y += relativeCursorY + 2 + curH + topIndent - viewport->getMaximumVisibleHeight();
  42106. }
  42107. }
  42108. viewport->setViewPosition (x, y);
  42109. }
  42110. }
  42111. void TextEditor::moveCursorTo (const int newPosition,
  42112. const bool isSelecting)
  42113. {
  42114. if (isSelecting)
  42115. {
  42116. moveCaret (newPosition);
  42117. const Range<int> oldSelection (selection);
  42118. if (dragType == notDragging)
  42119. {
  42120. if (abs (getCaretPosition() - selection.getStart()) < abs (getCaretPosition() - selection.getEnd()))
  42121. dragType = draggingSelectionStart;
  42122. else
  42123. dragType = draggingSelectionEnd;
  42124. }
  42125. if (dragType == draggingSelectionStart)
  42126. {
  42127. if (getCaretPosition() >= selection.getEnd())
  42128. dragType = draggingSelectionEnd;
  42129. selection = Range<int>::between (getCaretPosition(), selection.getEnd());
  42130. }
  42131. else
  42132. {
  42133. if (getCaretPosition() < selection.getStart())
  42134. dragType = draggingSelectionStart;
  42135. selection = Range<int>::between (getCaretPosition(), selection.getStart());
  42136. }
  42137. repaintText (selection.getUnionWith (oldSelection));
  42138. }
  42139. else
  42140. {
  42141. dragType = notDragging;
  42142. repaintText (selection);
  42143. moveCaret (newPosition);
  42144. selection = Range<int>::emptyRange (getCaretPosition());
  42145. }
  42146. }
  42147. int TextEditor::getTextIndexAt (const int x,
  42148. const int y)
  42149. {
  42150. return indexAtPosition ((float) (x + viewport->getViewPositionX() - leftIndent),
  42151. (float) (y + viewport->getViewPositionY() - topIndent));
  42152. }
  42153. void TextEditor::insertTextAtCaret (const String& newText_)
  42154. {
  42155. String newText (newText_);
  42156. if (allowedCharacters.isNotEmpty())
  42157. newText = newText.retainCharacters (allowedCharacters);
  42158. if (! isMultiLine())
  42159. newText = newText.replaceCharacters (T("\r\n"), T(" "));
  42160. else
  42161. newText = newText.replace (T("\r\n"), T("\n"));
  42162. const int newCaretPos = selection.getStart() + newText.length();
  42163. const int insertIndex = selection.getStart();
  42164. remove (selection, getUndoManager(),
  42165. newText.isNotEmpty() ? newCaretPos - 1 : newCaretPos);
  42166. if (maxTextLength > 0)
  42167. newText = newText.substring (0, maxTextLength - getTotalNumChars());
  42168. if (newText.isNotEmpty())
  42169. insert (newText,
  42170. insertIndex,
  42171. currentFont,
  42172. findColour (textColourId),
  42173. getUndoManager(),
  42174. newCaretPos);
  42175. textChanged();
  42176. }
  42177. void TextEditor::setHighlightedRegion (const Range<int>& newSelection)
  42178. {
  42179. moveCursorTo (newSelection.getStart(), false);
  42180. moveCursorTo (newSelection.getEnd(), true);
  42181. }
  42182. void TextEditor::copy()
  42183. {
  42184. if (passwordCharacter == 0)
  42185. {
  42186. const String selection (getHighlightedText());
  42187. if (selection.isNotEmpty())
  42188. SystemClipboard::copyTextToClipboard (selection);
  42189. }
  42190. }
  42191. void TextEditor::paste()
  42192. {
  42193. if (! isReadOnly())
  42194. {
  42195. const String clip (SystemClipboard::getTextFromClipboard());
  42196. if (clip.isNotEmpty())
  42197. insertTextAtCaret (clip);
  42198. }
  42199. }
  42200. void TextEditor::cut()
  42201. {
  42202. if (! isReadOnly())
  42203. {
  42204. moveCaret (selection.getEnd());
  42205. insertTextAtCaret (String::empty);
  42206. }
  42207. }
  42208. void TextEditor::drawContent (Graphics& g)
  42209. {
  42210. const float wordWrapWidth = getWordWrapWidth();
  42211. if (wordWrapWidth > 0)
  42212. {
  42213. g.setOrigin (leftIndent, topIndent);
  42214. const Rectangle<int> clip (g.getClipBounds());
  42215. Colour selectedTextColour;
  42216. TextEditorIterator i (sections, wordWrapWidth, passwordCharacter);
  42217. while (i.lineY + 200.0 < clip.getY() && i.next())
  42218. {}
  42219. if (! selection.isEmpty())
  42220. {
  42221. g.setColour (findColour (highlightColourId)
  42222. .withMultipliedAlpha (hasKeyboardFocus (true) ? 1.0f : 0.5f));
  42223. selectedTextColour = findColour (highlightedTextColourId);
  42224. TextEditorIterator i2 (i);
  42225. while (i2.next() && i2.lineY < clip.getBottom())
  42226. {
  42227. if (i2.lineY + i2.lineHeight >= clip.getY()
  42228. && selection.intersects (Range<int> (i2.indexInText, i2.indexInText + i2.atom->numChars)))
  42229. {
  42230. i2.drawSelection (g, selection);
  42231. }
  42232. }
  42233. }
  42234. const UniformTextSection* lastSection = 0;
  42235. while (i.next() && i.lineY < clip.getBottom())
  42236. {
  42237. if (i.lineY + i.lineHeight >= clip.getY())
  42238. {
  42239. if (selection.intersects (Range<int> (i.indexInText, i.indexInText + i.atom->numChars)))
  42240. {
  42241. i.drawSelectedText (g, selection, selectedTextColour);
  42242. lastSection = 0;
  42243. }
  42244. else
  42245. {
  42246. i.draw (g, lastSection);
  42247. }
  42248. }
  42249. }
  42250. }
  42251. }
  42252. void TextEditor::paint (Graphics& g)
  42253. {
  42254. getLookAndFeel().fillTextEditorBackground (g, getWidth(), getHeight(), *this);
  42255. }
  42256. void TextEditor::paintOverChildren (Graphics& g)
  42257. {
  42258. if (caretFlashState
  42259. && hasKeyboardFocus (false)
  42260. && caretVisible
  42261. && ! isReadOnly())
  42262. {
  42263. g.setColour (findColour (caretColourId));
  42264. g.fillRect (borderSize.getLeft() + textHolder->getX() + leftIndent + cursorX,
  42265. borderSize.getTop() + textHolder->getY() + topIndent + cursorY,
  42266. 2.0f, cursorHeight);
  42267. }
  42268. if (textToShowWhenEmpty.isNotEmpty()
  42269. && (! hasKeyboardFocus (false))
  42270. && getTotalNumChars() == 0)
  42271. {
  42272. g.setColour (colourForTextWhenEmpty);
  42273. g.setFont (getFont());
  42274. if (isMultiLine())
  42275. {
  42276. g.drawText (textToShowWhenEmpty,
  42277. 0, 0, getWidth(), getHeight(),
  42278. Justification::centred, true);
  42279. }
  42280. else
  42281. {
  42282. g.drawText (textToShowWhenEmpty,
  42283. leftIndent, topIndent,
  42284. viewport->getWidth() - leftIndent,
  42285. viewport->getHeight() - topIndent,
  42286. Justification::centredLeft, true);
  42287. }
  42288. }
  42289. getLookAndFeel().drawTextEditorOutline (g, getWidth(), getHeight(), *this);
  42290. }
  42291. void TextEditor::mouseDown (const MouseEvent& e)
  42292. {
  42293. beginDragAutoRepeat (100);
  42294. newTransaction();
  42295. if (wasFocused || ! selectAllTextWhenFocused)
  42296. {
  42297. if (! (popupMenuEnabled && e.mods.isPopupMenu()))
  42298. {
  42299. moveCursorTo (getTextIndexAt (e.x, e.y),
  42300. e.mods.isShiftDown());
  42301. }
  42302. else
  42303. {
  42304. PopupMenu m;
  42305. m.setLookAndFeel (&getLookAndFeel());
  42306. addPopupMenuItems (m, &e);
  42307. menuActive = true;
  42308. const int result = m.show();
  42309. menuActive = false;
  42310. if (result != 0)
  42311. performPopupMenuAction (result);
  42312. }
  42313. }
  42314. }
  42315. void TextEditor::mouseDrag (const MouseEvent& e)
  42316. {
  42317. if (wasFocused || ! selectAllTextWhenFocused)
  42318. {
  42319. if (! (popupMenuEnabled && e.mods.isPopupMenu()))
  42320. {
  42321. moveCursorTo (getTextIndexAt (e.x, e.y), true);
  42322. }
  42323. }
  42324. }
  42325. void TextEditor::mouseUp (const MouseEvent& e)
  42326. {
  42327. newTransaction();
  42328. textHolder->startTimer (TextEditorDefs::flashSpeedIntervalMs);
  42329. if (wasFocused || ! selectAllTextWhenFocused)
  42330. {
  42331. if (e.mouseWasClicked() && ! (popupMenuEnabled && e.mods.isPopupMenu()))
  42332. {
  42333. moveCaret (getTextIndexAt (e.x, e.y));
  42334. }
  42335. }
  42336. wasFocused = true;
  42337. }
  42338. void TextEditor::mouseDoubleClick (const MouseEvent& e)
  42339. {
  42340. int tokenEnd = getTextIndexAt (e.x, e.y);
  42341. int tokenStart = tokenEnd;
  42342. if (e.getNumberOfClicks() > 3)
  42343. {
  42344. tokenStart = 0;
  42345. tokenEnd = getTotalNumChars();
  42346. }
  42347. else
  42348. {
  42349. const String t (getText());
  42350. const int totalLength = getTotalNumChars();
  42351. while (tokenEnd < totalLength)
  42352. {
  42353. if (CharacterFunctions::isLetterOrDigit (t [tokenEnd]))
  42354. ++tokenEnd;
  42355. else
  42356. break;
  42357. }
  42358. tokenStart = tokenEnd;
  42359. while (tokenStart > 0)
  42360. {
  42361. if (CharacterFunctions::isLetterOrDigit (t [tokenStart - 1]))
  42362. --tokenStart;
  42363. else
  42364. break;
  42365. }
  42366. if (e.getNumberOfClicks() > 2)
  42367. {
  42368. while (tokenEnd < totalLength)
  42369. {
  42370. if (t [tokenEnd] != T('\r') && t [tokenEnd] != T('\n'))
  42371. ++tokenEnd;
  42372. else
  42373. break;
  42374. }
  42375. while (tokenStart > 0)
  42376. {
  42377. if (t [tokenStart - 1] != T('\r') && t [tokenStart - 1] != T('\n'))
  42378. --tokenStart;
  42379. else
  42380. break;
  42381. }
  42382. }
  42383. }
  42384. moveCursorTo (tokenEnd, false);
  42385. moveCursorTo (tokenStart, true);
  42386. }
  42387. void TextEditor::mouseWheelMove (const MouseEvent& e, float wheelIncrementX, float wheelIncrementY)
  42388. {
  42389. if (! viewport->useMouseWheelMoveIfNeeded (e, wheelIncrementX, wheelIncrementY))
  42390. Component::mouseWheelMove (e, wheelIncrementX, wheelIncrementY);
  42391. }
  42392. bool TextEditor::keyPressed (const KeyPress& key)
  42393. {
  42394. if (isReadOnly() && key != KeyPress (T('c'), ModifierKeys::commandModifier, 0))
  42395. return false;
  42396. const bool moveInWholeWordSteps = key.getModifiers().isCtrlDown() || key.getModifiers().isAltDown();
  42397. if (key.isKeyCode (KeyPress::leftKey)
  42398. || key.isKeyCode (KeyPress::upKey))
  42399. {
  42400. newTransaction();
  42401. int newPos;
  42402. if (isMultiLine() && key.isKeyCode (KeyPress::upKey))
  42403. newPos = indexAtPosition (cursorX, cursorY - 1);
  42404. else if (moveInWholeWordSteps)
  42405. newPos = findWordBreakBefore (getCaretPosition());
  42406. else
  42407. newPos = getCaretPosition() - 1;
  42408. moveCursorTo (newPos, key.getModifiers().isShiftDown());
  42409. }
  42410. else if (key.isKeyCode (KeyPress::rightKey)
  42411. || key.isKeyCode (KeyPress::downKey))
  42412. {
  42413. newTransaction();
  42414. int newPos;
  42415. if (isMultiLine() && key.isKeyCode (KeyPress::downKey))
  42416. newPos = indexAtPosition (cursorX, cursorY + cursorHeight + 1);
  42417. else if (moveInWholeWordSteps)
  42418. newPos = findWordBreakAfter (getCaretPosition());
  42419. else
  42420. newPos = getCaretPosition() + 1;
  42421. moveCursorTo (newPos, key.getModifiers().isShiftDown());
  42422. }
  42423. else if (key.isKeyCode (KeyPress::pageDownKey) && isMultiLine())
  42424. {
  42425. newTransaction();
  42426. moveCursorTo (indexAtPosition (cursorX, cursorY + cursorHeight + viewport->getViewHeight()),
  42427. key.getModifiers().isShiftDown());
  42428. }
  42429. else if (key.isKeyCode (KeyPress::pageUpKey) && isMultiLine())
  42430. {
  42431. newTransaction();
  42432. moveCursorTo (indexAtPosition (cursorX, cursorY - viewport->getViewHeight()),
  42433. key.getModifiers().isShiftDown());
  42434. }
  42435. else if (key.isKeyCode (KeyPress::homeKey))
  42436. {
  42437. newTransaction();
  42438. if (isMultiLine() && ! moveInWholeWordSteps)
  42439. moveCursorTo (indexAtPosition (0.0f, cursorY),
  42440. key.getModifiers().isShiftDown());
  42441. else
  42442. moveCursorTo (0, key.getModifiers().isShiftDown());
  42443. }
  42444. else if (key.isKeyCode (KeyPress::endKey))
  42445. {
  42446. newTransaction();
  42447. if (isMultiLine() && ! moveInWholeWordSteps)
  42448. moveCursorTo (indexAtPosition ((float) textHolder->getWidth(), cursorY),
  42449. key.getModifiers().isShiftDown());
  42450. else
  42451. moveCursorTo (getTotalNumChars(), key.getModifiers().isShiftDown());
  42452. }
  42453. else if (key.isKeyCode (KeyPress::backspaceKey))
  42454. {
  42455. if (moveInWholeWordSteps)
  42456. {
  42457. moveCursorTo (findWordBreakBefore (getCaretPosition()), true);
  42458. }
  42459. else
  42460. {
  42461. if (selection.isEmpty() && selection.getStart() > 0)
  42462. selection.setStart (selection.getEnd() - 1);
  42463. }
  42464. cut();
  42465. }
  42466. else if (key.isKeyCode (KeyPress::deleteKey))
  42467. {
  42468. if (key.getModifiers().isShiftDown())
  42469. copy();
  42470. if (selection.isEmpty() && selection.getStart() < getTotalNumChars())
  42471. selection.setEnd (selection.getStart() + 1);
  42472. cut();
  42473. }
  42474. else if (key == KeyPress (T('c'), ModifierKeys::commandModifier, 0)
  42475. || key == KeyPress (KeyPress::insertKey, ModifierKeys::ctrlModifier, 0))
  42476. {
  42477. newTransaction();
  42478. copy();
  42479. }
  42480. else if (key == KeyPress (T('x'), ModifierKeys::commandModifier, 0))
  42481. {
  42482. newTransaction();
  42483. copy();
  42484. cut();
  42485. }
  42486. else if (key == KeyPress (T('v'), ModifierKeys::commandModifier, 0)
  42487. || key == KeyPress (KeyPress::insertKey, ModifierKeys::shiftModifier, 0))
  42488. {
  42489. newTransaction();
  42490. paste();
  42491. }
  42492. else if (key == KeyPress (T('z'), ModifierKeys::commandModifier, 0))
  42493. {
  42494. newTransaction();
  42495. doUndoRedo (false);
  42496. }
  42497. else if (key == KeyPress (T('y'), ModifierKeys::commandModifier, 0))
  42498. {
  42499. newTransaction();
  42500. doUndoRedo (true);
  42501. }
  42502. else if (key == KeyPress (T('a'), ModifierKeys::commandModifier, 0))
  42503. {
  42504. newTransaction();
  42505. moveCursorTo (getTotalNumChars(), false);
  42506. moveCursorTo (0, true);
  42507. }
  42508. else if (key == KeyPress::returnKey)
  42509. {
  42510. newTransaction();
  42511. if (returnKeyStartsNewLine)
  42512. insertTextAtCaret (T("\n"));
  42513. else
  42514. returnPressed();
  42515. }
  42516. else if (key.isKeyCode (KeyPress::escapeKey))
  42517. {
  42518. newTransaction();
  42519. moveCursorTo (getCaretPosition(), false);
  42520. escapePressed();
  42521. }
  42522. else if (key.getTextCharacter() >= ' '
  42523. || (tabKeyUsed && (key.getTextCharacter() == '\t')))
  42524. {
  42525. insertTextAtCaret (String::charToString (key.getTextCharacter()));
  42526. lastTransactionTime = Time::getApproximateMillisecondCounter();
  42527. }
  42528. else
  42529. {
  42530. return false;
  42531. }
  42532. return true;
  42533. }
  42534. bool TextEditor::keyStateChanged (const bool isKeyDown)
  42535. {
  42536. if (! isKeyDown)
  42537. return false;
  42538. #if JUCE_WIN32
  42539. if (KeyPress (KeyPress::F4Key, ModifierKeys::altModifier, 0).isCurrentlyDown())
  42540. return false; // We need to explicitly allow alt-F4 to pass through on Windows
  42541. #endif
  42542. // (overridden to avoid forwarding key events to the parent)
  42543. return ! ModifierKeys::getCurrentModifiers().isCommandDown();
  42544. }
  42545. const int baseMenuItemID = 0x7fff0000;
  42546. void TextEditor::addPopupMenuItems (PopupMenu& m, const MouseEvent*)
  42547. {
  42548. const bool writable = ! isReadOnly();
  42549. if (passwordCharacter == 0)
  42550. {
  42551. m.addItem (baseMenuItemID + 1, TRANS("cut"), writable);
  42552. m.addItem (baseMenuItemID + 2, TRANS("copy"), ! selection.isEmpty());
  42553. m.addItem (baseMenuItemID + 3, TRANS("paste"), writable);
  42554. }
  42555. m.addItem (baseMenuItemID + 4, TRANS("delete"), writable);
  42556. m.addSeparator();
  42557. m.addItem (baseMenuItemID + 5, TRANS("select all"));
  42558. m.addSeparator();
  42559. if (getUndoManager() != 0)
  42560. {
  42561. m.addItem (baseMenuItemID + 6, TRANS("undo"), undoManager.canUndo());
  42562. m.addItem (baseMenuItemID + 7, TRANS("redo"), undoManager.canRedo());
  42563. }
  42564. }
  42565. void TextEditor::performPopupMenuAction (const int menuItemID)
  42566. {
  42567. switch (menuItemID)
  42568. {
  42569. case baseMenuItemID + 1:
  42570. copy();
  42571. cut();
  42572. break;
  42573. case baseMenuItemID + 2:
  42574. copy();
  42575. break;
  42576. case baseMenuItemID + 3:
  42577. paste();
  42578. break;
  42579. case baseMenuItemID + 4:
  42580. cut();
  42581. break;
  42582. case baseMenuItemID + 5:
  42583. moveCursorTo (getTotalNumChars(), false);
  42584. moveCursorTo (0, true);
  42585. break;
  42586. case baseMenuItemID + 6:
  42587. doUndoRedo (false);
  42588. break;
  42589. case baseMenuItemID + 7:
  42590. doUndoRedo (true);
  42591. break;
  42592. default:
  42593. break;
  42594. }
  42595. }
  42596. void TextEditor::focusGained (FocusChangeType)
  42597. {
  42598. newTransaction();
  42599. caretFlashState = true;
  42600. if (selectAllTextWhenFocused)
  42601. {
  42602. moveCursorTo (0, false);
  42603. moveCursorTo (getTotalNumChars(), true);
  42604. }
  42605. repaint();
  42606. if (caretVisible)
  42607. textHolder->startTimer (TextEditorDefs::flashSpeedIntervalMs);
  42608. ComponentPeer* const peer = getPeer();
  42609. if (peer != 0 && ! isReadOnly())
  42610. peer->textInputRequired (getScreenPosition() - peer->getScreenPosition());
  42611. }
  42612. void TextEditor::focusLost (FocusChangeType)
  42613. {
  42614. newTransaction();
  42615. wasFocused = false;
  42616. textHolder->stopTimer();
  42617. caretFlashState = false;
  42618. postCommandMessage (TextEditorDefs::focusLossMessageId);
  42619. repaint();
  42620. }
  42621. void TextEditor::resized()
  42622. {
  42623. viewport->setBoundsInset (borderSize);
  42624. viewport->setSingleStepSizes (16, roundToInt (currentFont.getHeight()));
  42625. updateTextHolderSize();
  42626. if (! isMultiLine())
  42627. {
  42628. scrollToMakeSureCursorIsVisible();
  42629. }
  42630. else
  42631. {
  42632. updateCaretPosition();
  42633. }
  42634. }
  42635. void TextEditor::handleCommandMessage (const int commandId)
  42636. {
  42637. Component::BailOutChecker checker (this);
  42638. switch (commandId)
  42639. {
  42640. case TextEditorDefs::textChangeMessageId:
  42641. listeners.callChecked (checker, &TextEditorListener::textEditorTextChanged, (TextEditor&) *this);
  42642. break;
  42643. case TextEditorDefs::returnKeyMessageId:
  42644. listeners.callChecked (checker, &TextEditorListener::textEditorReturnKeyPressed, (TextEditor&) *this);
  42645. break;
  42646. case TextEditorDefs::escapeKeyMessageId:
  42647. listeners.callChecked (checker, &TextEditorListener::textEditorEscapeKeyPressed, (TextEditor&) *this);
  42648. break;
  42649. case TextEditorDefs::focusLossMessageId:
  42650. listeners.callChecked (checker, &TextEditorListener::textEditorFocusLost, (TextEditor&) *this);
  42651. break;
  42652. default:
  42653. jassertfalse
  42654. break;
  42655. }
  42656. }
  42657. void TextEditor::enablementChanged()
  42658. {
  42659. setMouseCursor (isReadOnly() ? MouseCursor::NormalCursor
  42660. : MouseCursor::IBeamCursor);
  42661. repaint();
  42662. }
  42663. UndoManager* TextEditor::getUndoManager() throw()
  42664. {
  42665. return isReadOnly() ? &undoManager : 0;
  42666. }
  42667. void TextEditor::clearInternal (UndoManager* const um)
  42668. {
  42669. remove (Range<int> (0, getTotalNumChars()), um, caretPosition);
  42670. }
  42671. void TextEditor::insert (const String& text,
  42672. const int insertIndex,
  42673. const Font& font,
  42674. const Colour& colour,
  42675. UndoManager* const um,
  42676. const int caretPositionToMoveTo)
  42677. {
  42678. if (text.isNotEmpty())
  42679. {
  42680. if (um != 0)
  42681. {
  42682. if (um->getNumActionsInCurrentTransaction() > TextEditorDefs::maxActionsPerTransaction)
  42683. newTransaction();
  42684. um->perform (new TextEditorInsertAction (*this,
  42685. text,
  42686. insertIndex,
  42687. font,
  42688. colour,
  42689. caretPosition,
  42690. caretPositionToMoveTo));
  42691. }
  42692. else
  42693. {
  42694. repaintText (Range<int> (insertIndex, getTotalNumChars())); // must do this before and after changing the data, in case
  42695. // a line gets moved due to word wrap
  42696. int index = 0;
  42697. int nextIndex = 0;
  42698. for (int i = 0; i < sections.size(); ++i)
  42699. {
  42700. nextIndex = index + ((UniformTextSection*) sections.getUnchecked(i))->getTotalLength();
  42701. if (insertIndex == index)
  42702. {
  42703. sections.insert (i, new UniformTextSection (text,
  42704. font, colour,
  42705. passwordCharacter));
  42706. break;
  42707. }
  42708. else if (insertIndex > index && insertIndex < nextIndex)
  42709. {
  42710. splitSection (i, insertIndex - index);
  42711. sections.insert (i + 1, new UniformTextSection (text,
  42712. font, colour,
  42713. passwordCharacter));
  42714. break;
  42715. }
  42716. index = nextIndex;
  42717. }
  42718. if (nextIndex == insertIndex)
  42719. sections.add (new UniformTextSection (text,
  42720. font, colour,
  42721. passwordCharacter));
  42722. coalesceSimilarSections();
  42723. totalNumChars = -1;
  42724. valueTextNeedsUpdating = true;
  42725. moveCursorTo (caretPositionToMoveTo, false);
  42726. repaintText (Range<int> (insertIndex, getTotalNumChars()));
  42727. }
  42728. }
  42729. }
  42730. void TextEditor::reinsert (const int insertIndex,
  42731. const VoidArray& sectionsToInsert)
  42732. {
  42733. int index = 0;
  42734. int nextIndex = 0;
  42735. for (int i = 0; i < sections.size(); ++i)
  42736. {
  42737. nextIndex = index + ((UniformTextSection*) sections.getUnchecked(i))->getTotalLength();
  42738. if (insertIndex == index)
  42739. {
  42740. for (int j = sectionsToInsert.size(); --j >= 0;)
  42741. sections.insert (i, new UniformTextSection (*(UniformTextSection*) sectionsToInsert.getUnchecked(j)));
  42742. break;
  42743. }
  42744. else if (insertIndex > index && insertIndex < nextIndex)
  42745. {
  42746. splitSection (i, insertIndex - index);
  42747. for (int j = sectionsToInsert.size(); --j >= 0;)
  42748. sections.insert (i + 1, new UniformTextSection (*(UniformTextSection*) sectionsToInsert.getUnchecked(j)));
  42749. break;
  42750. }
  42751. index = nextIndex;
  42752. }
  42753. if (nextIndex == insertIndex)
  42754. {
  42755. for (int j = 0; j < sectionsToInsert.size(); ++j)
  42756. sections.add (new UniformTextSection (*(UniformTextSection*) sectionsToInsert.getUnchecked(j)));
  42757. }
  42758. coalesceSimilarSections();
  42759. totalNumChars = -1;
  42760. valueTextNeedsUpdating = true;
  42761. }
  42762. void TextEditor::remove (const Range<int>& range,
  42763. UndoManager* const um,
  42764. const int caretPositionToMoveTo)
  42765. {
  42766. if (! range.isEmpty())
  42767. {
  42768. int index = 0;
  42769. for (int i = 0; i < sections.size(); ++i)
  42770. {
  42771. const int nextIndex = index + ((UniformTextSection*) sections[i])->getTotalLength();
  42772. if (range.getStart() > index && range.getStart() < nextIndex)
  42773. {
  42774. splitSection (i, range.getStart() - index);
  42775. --i;
  42776. }
  42777. else if (range.getEnd() > index && range.getEnd() < nextIndex)
  42778. {
  42779. splitSection (i, range.getEnd() - index);
  42780. --i;
  42781. }
  42782. else
  42783. {
  42784. index = nextIndex;
  42785. if (index > range.getEnd())
  42786. break;
  42787. }
  42788. }
  42789. index = 0;
  42790. if (um != 0)
  42791. {
  42792. VoidArray removedSections;
  42793. for (int i = 0; i < sections.size(); ++i)
  42794. {
  42795. if (range.getEnd() <= range.getStart())
  42796. break;
  42797. UniformTextSection* const section = (UniformTextSection*) sections.getUnchecked (i);
  42798. const int nextIndex = index + section->getTotalLength();
  42799. if (range.getStart() <= index && range.getEnd() >= nextIndex)
  42800. removedSections.add (new UniformTextSection (*section));
  42801. index = nextIndex;
  42802. }
  42803. if (um->getNumActionsInCurrentTransaction() > TextEditorDefs::maxActionsPerTransaction)
  42804. newTransaction();
  42805. um->perform (new TextEditorRemoveAction (*this,
  42806. range,
  42807. caretPosition,
  42808. caretPositionToMoveTo,
  42809. removedSections));
  42810. }
  42811. else
  42812. {
  42813. Range<int> remainingRange (range);
  42814. for (int i = 0; i < sections.size(); ++i)
  42815. {
  42816. UniformTextSection* const section = (UniformTextSection*) sections.getUnchecked (i);
  42817. const int nextIndex = index + section->getTotalLength();
  42818. if (remainingRange.getStart() <= index && remainingRange.getEnd() >= nextIndex)
  42819. {
  42820. sections.remove(i);
  42821. section->clear();
  42822. delete section;
  42823. remainingRange.setEnd (remainingRange.getEnd() - (nextIndex - index));
  42824. if (remainingRange.isEmpty())
  42825. break;
  42826. --i;
  42827. }
  42828. else
  42829. {
  42830. index = nextIndex;
  42831. }
  42832. }
  42833. coalesceSimilarSections();
  42834. totalNumChars = -1;
  42835. valueTextNeedsUpdating = true;
  42836. moveCursorTo (caretPositionToMoveTo, false);
  42837. repaintText (Range<int> (range.getStart(), getTotalNumChars()));
  42838. }
  42839. }
  42840. }
  42841. const String TextEditor::getText() const
  42842. {
  42843. String t;
  42844. t.preallocateStorage (getTotalNumChars());
  42845. String::Concatenator concatenator (t);
  42846. for (int i = 0; i < sections.size(); ++i)
  42847. ((const UniformTextSection*) sections.getUnchecked(i))->appendAllText (concatenator);
  42848. return t;
  42849. }
  42850. const String TextEditor::getTextInRange (const Range<int>& range) const
  42851. {
  42852. String t;
  42853. if (! range.isEmpty())
  42854. {
  42855. t.preallocateStorage (jmin (getTotalNumChars(), range.getLength()));
  42856. String::Concatenator concatenator (t);
  42857. int index = 0;
  42858. for (int i = 0; i < sections.size(); ++i)
  42859. {
  42860. const UniformTextSection* const s = (const UniformTextSection*) sections.getUnchecked(i);
  42861. const int nextIndex = index + s->getTotalLength();
  42862. if (range.getStart() < nextIndex)
  42863. {
  42864. if (range.getEnd() <= index)
  42865. break;
  42866. s->appendSubstring (concatenator, range - index);
  42867. }
  42868. index = nextIndex;
  42869. }
  42870. }
  42871. return t;
  42872. }
  42873. const String TextEditor::getHighlightedText() const
  42874. {
  42875. return getTextInRange (selection);
  42876. }
  42877. int TextEditor::getTotalNumChars() const
  42878. {
  42879. if (totalNumChars < 0)
  42880. {
  42881. totalNumChars = 0;
  42882. for (int i = sections.size(); --i >= 0;)
  42883. totalNumChars += ((const UniformTextSection*) sections.getUnchecked(i))->getTotalLength();
  42884. }
  42885. return totalNumChars;
  42886. }
  42887. bool TextEditor::isEmpty() const
  42888. {
  42889. return getTotalNumChars() == 0;
  42890. }
  42891. void TextEditor::getCharPosition (const int index, float& cx, float& cy, float& lineHeight) const
  42892. {
  42893. const float wordWrapWidth = getWordWrapWidth();
  42894. if (wordWrapWidth > 0 && sections.size() > 0)
  42895. {
  42896. TextEditorIterator i (sections, wordWrapWidth, passwordCharacter);
  42897. i.getCharPosition (index, cx, cy, lineHeight);
  42898. }
  42899. else
  42900. {
  42901. cx = cy = 0;
  42902. lineHeight = currentFont.getHeight();
  42903. }
  42904. }
  42905. int TextEditor::indexAtPosition (const float x, const float y)
  42906. {
  42907. const float wordWrapWidth = getWordWrapWidth();
  42908. if (wordWrapWidth > 0)
  42909. {
  42910. TextEditorIterator i (sections, wordWrapWidth, passwordCharacter);
  42911. while (i.next())
  42912. {
  42913. if (i.lineY + i.lineHeight > y)
  42914. {
  42915. if (i.lineY > y)
  42916. return jmax (0, i.indexInText - 1);
  42917. if (i.atomX >= x)
  42918. return i.indexInText;
  42919. if (x < i.atomRight)
  42920. return i.xToIndex (x);
  42921. }
  42922. }
  42923. }
  42924. return getTotalNumChars();
  42925. }
  42926. static int getCharacterCategory (const tchar character)
  42927. {
  42928. return CharacterFunctions::isLetterOrDigit (character)
  42929. ? 2 : (CharacterFunctions::isWhitespace (character) ? 0 : 1);
  42930. }
  42931. int TextEditor::findWordBreakAfter (const int position) const
  42932. {
  42933. const String t (getTextInRange (Range<int> (position, position + 512)));
  42934. const int totalLength = t.length();
  42935. int i = 0;
  42936. while (i < totalLength && CharacterFunctions::isWhitespace (t[i]))
  42937. ++i;
  42938. const int type = getCharacterCategory (t[i]);
  42939. while (i < totalLength && type == getCharacterCategory (t[i]))
  42940. ++i;
  42941. while (i < totalLength && CharacterFunctions::isWhitespace (t[i]))
  42942. ++i;
  42943. return position + i;
  42944. }
  42945. int TextEditor::findWordBreakBefore (const int position) const
  42946. {
  42947. if (position <= 0)
  42948. return 0;
  42949. const int startOfBuffer = jmax (0, position - 512);
  42950. const String t (getTextInRange (Range<int> (startOfBuffer, position)));
  42951. int i = position - startOfBuffer;
  42952. while (i > 0 && CharacterFunctions::isWhitespace (t [i - 1]))
  42953. --i;
  42954. if (i > 0)
  42955. {
  42956. const int type = getCharacterCategory (t [i - 1]);
  42957. while (i > 0 && type == getCharacterCategory (t [i - 1]))
  42958. --i;
  42959. }
  42960. jassert (startOfBuffer + i >= 0);
  42961. return startOfBuffer + i;
  42962. }
  42963. void TextEditor::splitSection (const int sectionIndex,
  42964. const int charToSplitAt)
  42965. {
  42966. jassert (sections[sectionIndex] != 0);
  42967. sections.insert (sectionIndex + 1,
  42968. ((UniformTextSection*) sections.getUnchecked (sectionIndex))
  42969. ->split (charToSplitAt, passwordCharacter));
  42970. }
  42971. void TextEditor::coalesceSimilarSections()
  42972. {
  42973. for (int i = 0; i < sections.size() - 1; ++i)
  42974. {
  42975. UniformTextSection* const s1 = (UniformTextSection*) sections.getUnchecked (i);
  42976. UniformTextSection* const s2 = (UniformTextSection*) sections.getUnchecked (i + 1);
  42977. if (s1->font == s2->font
  42978. && s1->colour == s2->colour)
  42979. {
  42980. s1->append (*s2, passwordCharacter);
  42981. sections.remove (i + 1);
  42982. delete s2;
  42983. --i;
  42984. }
  42985. }
  42986. }
  42987. END_JUCE_NAMESPACE
  42988. /*** End of inlined file: juce_TextEditor.cpp ***/
  42989. /*** Start of inlined file: juce_Toolbar.cpp ***/
  42990. BEGIN_JUCE_NAMESPACE
  42991. const tchar* const Toolbar::toolbarDragDescriptor = T("_toolbarItem_");
  42992. class ToolbarSpacerComp : public ToolbarItemComponent
  42993. {
  42994. public:
  42995. ToolbarSpacerComp (const int itemId_, const float fixedSize_, const bool drawBar_)
  42996. : ToolbarItemComponent (itemId_, String::empty, false),
  42997. fixedSize (fixedSize_),
  42998. drawBar (drawBar_)
  42999. {
  43000. }
  43001. ~ToolbarSpacerComp()
  43002. {
  43003. }
  43004. bool getToolbarItemSizes (int toolbarThickness, bool /*isToolbarVertical*/,
  43005. int& preferredSize, int& minSize, int& maxSize)
  43006. {
  43007. if (fixedSize <= 0)
  43008. {
  43009. preferredSize = toolbarThickness * 2;
  43010. minSize = 4;
  43011. maxSize = 32768;
  43012. }
  43013. else
  43014. {
  43015. maxSize = roundToInt (toolbarThickness * fixedSize);
  43016. minSize = drawBar ? maxSize : jmin (4, maxSize);
  43017. preferredSize = maxSize;
  43018. if (getEditingMode() == editableOnPalette)
  43019. preferredSize = maxSize = toolbarThickness / (drawBar ? 3 : 2);
  43020. }
  43021. return true;
  43022. }
  43023. void paintButtonArea (Graphics&, int, int, bool, bool)
  43024. {
  43025. }
  43026. void contentAreaChanged (const Rectangle<int>&)
  43027. {
  43028. }
  43029. int getResizeOrder() const throw()
  43030. {
  43031. return fixedSize <= 0 ? 0 : 1;
  43032. }
  43033. void paint (Graphics& g)
  43034. {
  43035. const int w = getWidth();
  43036. const int h = getHeight();
  43037. if (drawBar)
  43038. {
  43039. g.setColour (findColour (Toolbar::separatorColourId, true));
  43040. const float thickness = 0.2f;
  43041. if (isToolbarVertical())
  43042. g.fillRect (w * 0.1f, h * (0.5f - thickness * 0.5f), w * 0.8f, h * thickness);
  43043. else
  43044. g.fillRect (w * (0.5f - thickness * 0.5f), h * 0.1f, w * thickness, h * 0.8f);
  43045. }
  43046. if (getEditingMode() != normalMode && ! drawBar)
  43047. {
  43048. g.setColour (findColour (Toolbar::separatorColourId, true));
  43049. const int indentX = jmin (2, (w - 3) / 2);
  43050. const int indentY = jmin (2, (h - 3) / 2);
  43051. g.drawRect (indentX, indentY, w - indentX * 2, h - indentY * 2, 1);
  43052. if (fixedSize <= 0)
  43053. {
  43054. float x1, y1, x2, y2, x3, y3, x4, y4, hw, hl;
  43055. if (isToolbarVertical())
  43056. {
  43057. x1 = w * 0.5f;
  43058. y1 = h * 0.4f;
  43059. x2 = x1;
  43060. y2 = indentX * 2.0f;
  43061. x3 = x1;
  43062. y3 = h * 0.6f;
  43063. x4 = x1;
  43064. y4 = h - y2;
  43065. hw = w * 0.15f;
  43066. hl = w * 0.2f;
  43067. }
  43068. else
  43069. {
  43070. x1 = w * 0.4f;
  43071. y1 = h * 0.5f;
  43072. x2 = indentX * 2.0f;
  43073. y2 = y1;
  43074. x3 = w * 0.6f;
  43075. y3 = y1;
  43076. x4 = w - x2;
  43077. y4 = y1;
  43078. hw = h * 0.15f;
  43079. hl = h * 0.2f;
  43080. }
  43081. Path p;
  43082. p.addArrow (x1, y1, x2, y2, 1.5f, hw, hl);
  43083. p.addArrow (x3, y3, x4, y4, 1.5f, hw, hl);
  43084. g.fillPath (p);
  43085. }
  43086. }
  43087. }
  43088. juce_UseDebuggingNewOperator
  43089. private:
  43090. const float fixedSize;
  43091. const bool drawBar;
  43092. ToolbarSpacerComp (const ToolbarSpacerComp&);
  43093. ToolbarSpacerComp& operator= (const ToolbarSpacerComp&);
  43094. };
  43095. class MissingItemsComponent : public PopupMenuCustomComponent
  43096. {
  43097. public:
  43098. MissingItemsComponent (Toolbar& owner_, const int height_)
  43099. : PopupMenuCustomComponent (true),
  43100. owner (owner_),
  43101. height (height_)
  43102. {
  43103. for (int i = owner_.items.size(); --i >= 0;)
  43104. {
  43105. ToolbarItemComponent* const tc = owner_.items.getUnchecked(i);
  43106. if (dynamic_cast <ToolbarSpacerComp*> (tc) == 0 && ! tc->isVisible())
  43107. {
  43108. oldIndexes.insert (0, i);
  43109. addAndMakeVisible (tc, 0);
  43110. }
  43111. }
  43112. layout (400);
  43113. }
  43114. ~MissingItemsComponent()
  43115. {
  43116. // deleting the toolbar while its menu it open??
  43117. jassert (owner.isValidComponent());
  43118. for (int i = 0; i < getNumChildComponents(); ++i)
  43119. {
  43120. ToolbarItemComponent* const tc = dynamic_cast <ToolbarItemComponent*> (getChildComponent (i));
  43121. if (tc != 0)
  43122. {
  43123. tc->setVisible (false);
  43124. const int index = oldIndexes.remove (i);
  43125. owner.addChildComponent (tc, index);
  43126. --i;
  43127. }
  43128. }
  43129. owner.resized();
  43130. }
  43131. void layout (const int preferredWidth)
  43132. {
  43133. const int indent = 8;
  43134. int x = indent;
  43135. int y = indent;
  43136. int maxX = 0;
  43137. for (int i = 0; i < getNumChildComponents(); ++i)
  43138. {
  43139. ToolbarItemComponent* const tc = dynamic_cast <ToolbarItemComponent*> (getChildComponent (i));
  43140. if (tc != 0)
  43141. {
  43142. int preferredSize = 1, minSize = 1, maxSize = 1;
  43143. if (tc->getToolbarItemSizes (height, false, preferredSize, minSize, maxSize))
  43144. {
  43145. if (x + preferredSize > preferredWidth && x > indent)
  43146. {
  43147. x = indent;
  43148. y += height;
  43149. }
  43150. tc->setBounds (x, y, preferredSize, height);
  43151. x += preferredSize;
  43152. maxX = jmax (maxX, x);
  43153. }
  43154. }
  43155. }
  43156. setSize (maxX + 8, y + height + 8);
  43157. }
  43158. void getIdealSize (int& idealWidth, int& idealHeight)
  43159. {
  43160. idealWidth = getWidth();
  43161. idealHeight = getHeight();
  43162. }
  43163. juce_UseDebuggingNewOperator
  43164. private:
  43165. Toolbar& owner;
  43166. const int height;
  43167. Array <int> oldIndexes;
  43168. MissingItemsComponent (const MissingItemsComponent&);
  43169. MissingItemsComponent& operator= (const MissingItemsComponent&);
  43170. };
  43171. Toolbar::Toolbar()
  43172. : vertical (false),
  43173. isEditingActive (false),
  43174. toolbarStyle (Toolbar::iconsOnly)
  43175. {
  43176. addChildComponent (missingItemsButton = getLookAndFeel().createToolbarMissingItemsButton (*this));
  43177. missingItemsButton->setAlwaysOnTop (true);
  43178. missingItemsButton->addButtonListener (this);
  43179. }
  43180. Toolbar::~Toolbar()
  43181. {
  43182. animator.cancelAllAnimations (true);
  43183. deleteAllChildren();
  43184. }
  43185. void Toolbar::setVertical (const bool shouldBeVertical)
  43186. {
  43187. if (vertical != shouldBeVertical)
  43188. {
  43189. vertical = shouldBeVertical;
  43190. resized();
  43191. }
  43192. }
  43193. void Toolbar::clear()
  43194. {
  43195. for (int i = items.size(); --i >= 0;)
  43196. {
  43197. ToolbarItemComponent* const tc = items.getUnchecked(i);
  43198. items.remove (i);
  43199. delete tc;
  43200. }
  43201. resized();
  43202. }
  43203. ToolbarItemComponent* Toolbar::createItem (ToolbarItemFactory& factory, const int itemId)
  43204. {
  43205. if (itemId == ToolbarItemFactory::separatorBarId)
  43206. return new ToolbarSpacerComp (itemId, 0.1f, true);
  43207. else if (itemId == ToolbarItemFactory::spacerId)
  43208. return new ToolbarSpacerComp (itemId, 0.5f, false);
  43209. else if (itemId == ToolbarItemFactory::flexibleSpacerId)
  43210. return new ToolbarSpacerComp (itemId, 0, false);
  43211. return factory.createItem (itemId);
  43212. }
  43213. void Toolbar::addItemInternal (ToolbarItemFactory& factory,
  43214. const int itemId,
  43215. const int insertIndex)
  43216. {
  43217. // An ID can't be zero - this might indicate a mistake somewhere?
  43218. jassert (itemId != 0);
  43219. ToolbarItemComponent* const tc = createItem (factory, itemId);
  43220. if (tc != 0)
  43221. {
  43222. #ifdef JUCE_DEBUG
  43223. Array <int> allowedIds;
  43224. factory.getAllToolbarItemIds (allowedIds);
  43225. // If your factory can create an item for a given ID, it must also return
  43226. // that ID from its getAllToolbarItemIds() method!
  43227. jassert (allowedIds.contains (itemId));
  43228. #endif
  43229. items.insert (insertIndex, tc);
  43230. addAndMakeVisible (tc, insertIndex);
  43231. }
  43232. }
  43233. void Toolbar::addItem (ToolbarItemFactory& factory,
  43234. const int itemId,
  43235. const int insertIndex)
  43236. {
  43237. addItemInternal (factory, itemId, insertIndex);
  43238. resized();
  43239. }
  43240. void Toolbar::addDefaultItems (ToolbarItemFactory& factoryToUse)
  43241. {
  43242. Array <int> ids;
  43243. factoryToUse.getDefaultItemSet (ids);
  43244. clear();
  43245. for (int i = 0; i < ids.size(); ++i)
  43246. addItemInternal (factoryToUse, ids.getUnchecked (i), -1);
  43247. resized();
  43248. }
  43249. void Toolbar::removeToolbarItem (const int itemIndex)
  43250. {
  43251. ToolbarItemComponent* const tc = getItemComponent (itemIndex);
  43252. if (tc != 0)
  43253. {
  43254. items.removeValue (tc);
  43255. delete tc;
  43256. resized();
  43257. }
  43258. }
  43259. int Toolbar::getNumItems() const throw()
  43260. {
  43261. return items.size();
  43262. }
  43263. int Toolbar::getItemId (const int itemIndex) const throw()
  43264. {
  43265. ToolbarItemComponent* const tc = getItemComponent (itemIndex);
  43266. return tc != 0 ? tc->getItemId() : 0;
  43267. }
  43268. ToolbarItemComponent* Toolbar::getItemComponent (const int itemIndex) const throw()
  43269. {
  43270. return items [itemIndex];
  43271. }
  43272. ToolbarItemComponent* Toolbar::getNextActiveComponent (int index, const int delta) const
  43273. {
  43274. for (;;)
  43275. {
  43276. index += delta;
  43277. ToolbarItemComponent* const tc = getItemComponent (index);
  43278. if (tc == 0)
  43279. break;
  43280. if (tc->isActive)
  43281. return tc;
  43282. }
  43283. return 0;
  43284. }
  43285. void Toolbar::setStyle (const ToolbarItemStyle& newStyle)
  43286. {
  43287. if (toolbarStyle != newStyle)
  43288. {
  43289. toolbarStyle = newStyle;
  43290. updateAllItemPositions (false);
  43291. }
  43292. }
  43293. const String Toolbar::toString() const
  43294. {
  43295. String s (T("TB:"));
  43296. for (int i = 0; i < getNumItems(); ++i)
  43297. s << getItemId(i) << T(' ');
  43298. return s.trimEnd();
  43299. }
  43300. bool Toolbar::restoreFromString (ToolbarItemFactory& factoryToUse,
  43301. const String& savedVersion)
  43302. {
  43303. if (! savedVersion.startsWith (T("TB:")))
  43304. return false;
  43305. StringArray tokens;
  43306. tokens.addTokens (savedVersion.substring (3), false);
  43307. clear();
  43308. for (int i = 0; i < tokens.size(); ++i)
  43309. addItemInternal (factoryToUse, tokens[i].getIntValue(), -1);
  43310. resized();
  43311. return true;
  43312. }
  43313. void Toolbar::paint (Graphics& g)
  43314. {
  43315. getLookAndFeel().paintToolbarBackground (g, getWidth(), getHeight(), *this);
  43316. }
  43317. int Toolbar::getThickness() const throw()
  43318. {
  43319. return vertical ? getWidth() : getHeight();
  43320. }
  43321. int Toolbar::getLength() const throw()
  43322. {
  43323. return vertical ? getHeight() : getWidth();
  43324. }
  43325. void Toolbar::setEditingActive (const bool active)
  43326. {
  43327. if (isEditingActive != active)
  43328. {
  43329. isEditingActive = active;
  43330. updateAllItemPositions (false);
  43331. }
  43332. }
  43333. void Toolbar::resized()
  43334. {
  43335. updateAllItemPositions (false);
  43336. }
  43337. void Toolbar::updateAllItemPositions (const bool animate)
  43338. {
  43339. if (getWidth() > 0 && getHeight() > 0)
  43340. {
  43341. StretchableObjectResizer resizer;
  43342. int i;
  43343. for (i = 0; i < items.size(); ++i)
  43344. {
  43345. ToolbarItemComponent* const tc = items.getUnchecked(i);
  43346. tc->setEditingMode (isEditingActive ? ToolbarItemComponent::editableOnToolbar
  43347. : ToolbarItemComponent::normalMode);
  43348. tc->setStyle (toolbarStyle);
  43349. ToolbarSpacerComp* const spacer = dynamic_cast <ToolbarSpacerComp*> (tc);
  43350. int preferredSize = 1, minSize = 1, maxSize = 1;
  43351. if (tc->getToolbarItemSizes (getThickness(), isVertical(),
  43352. preferredSize, minSize, maxSize))
  43353. {
  43354. tc->isActive = true;
  43355. resizer.addItem (preferredSize, minSize, maxSize,
  43356. spacer != 0 ? spacer->getResizeOrder() : 2);
  43357. }
  43358. else
  43359. {
  43360. tc->isActive = false;
  43361. tc->setVisible (false);
  43362. }
  43363. }
  43364. resizer.resizeToFit (getLength());
  43365. int totalLength = 0;
  43366. for (i = 0; i < resizer.getNumItems(); ++i)
  43367. totalLength += (int) resizer.getItemSize (i);
  43368. const bool itemsOffTheEnd = totalLength > getLength();
  43369. const int extrasButtonSize = getThickness() / 2;
  43370. missingItemsButton->setSize (extrasButtonSize, extrasButtonSize);
  43371. missingItemsButton->setVisible (itemsOffTheEnd);
  43372. missingItemsButton->setEnabled (! isEditingActive);
  43373. if (vertical)
  43374. missingItemsButton->setCentrePosition (getWidth() / 2,
  43375. getHeight() - 4 - extrasButtonSize / 2);
  43376. else
  43377. missingItemsButton->setCentrePosition (getWidth() - 4 - extrasButtonSize / 2,
  43378. getHeight() / 2);
  43379. const int maxLength = itemsOffTheEnd ? (vertical ? missingItemsButton->getY()
  43380. : missingItemsButton->getX()) - 4
  43381. : getLength();
  43382. int pos = 0, activeIndex = 0;
  43383. for (i = 0; i < items.size(); ++i)
  43384. {
  43385. ToolbarItemComponent* const tc = items.getUnchecked(i);
  43386. if (tc->isActive)
  43387. {
  43388. const int size = (int) resizer.getItemSize (activeIndex++);
  43389. Rectangle<int> newBounds;
  43390. if (vertical)
  43391. newBounds.setBounds (0, pos, getWidth(), size);
  43392. else
  43393. newBounds.setBounds (pos, 0, size, getHeight());
  43394. if (animate)
  43395. {
  43396. animator.animateComponent (tc, newBounds, 200, 3.0, 0.0);
  43397. }
  43398. else
  43399. {
  43400. animator.cancelAnimation (tc, false);
  43401. tc->setBounds (newBounds);
  43402. }
  43403. pos += size;
  43404. tc->setVisible (pos <= maxLength
  43405. && ((! tc->isBeingDragged)
  43406. || tc->getEditingMode() == ToolbarItemComponent::editableOnPalette));
  43407. }
  43408. }
  43409. }
  43410. }
  43411. void Toolbar::buttonClicked (Button*)
  43412. {
  43413. jassert (missingItemsButton->isShowing());
  43414. if (missingItemsButton->isShowing())
  43415. {
  43416. PopupMenu m;
  43417. m.addCustomItem (1, new MissingItemsComponent (*this, getThickness()));
  43418. m.showAt (missingItemsButton);
  43419. }
  43420. }
  43421. bool Toolbar::isInterestedInDragSource (const String& sourceDescription,
  43422. Component* /*sourceComponent*/)
  43423. {
  43424. return sourceDescription == toolbarDragDescriptor && isEditingActive;
  43425. }
  43426. void Toolbar::itemDragMove (const String&, Component* sourceComponent, int x, int y)
  43427. {
  43428. ToolbarItemComponent* const tc = dynamic_cast <ToolbarItemComponent*> (sourceComponent);
  43429. if (tc != 0)
  43430. {
  43431. if (getNumItems() == 0)
  43432. {
  43433. if (tc->getEditingMode() == ToolbarItemComponent::editableOnPalette)
  43434. {
  43435. ToolbarItemPalette* const palette = tc->findParentComponentOfClass ((ToolbarItemPalette*) 0);
  43436. if (palette != 0)
  43437. palette->replaceComponent (tc);
  43438. }
  43439. else
  43440. {
  43441. jassert (tc->getEditingMode() == ToolbarItemComponent::editableOnToolbar);
  43442. }
  43443. items.add (tc);
  43444. addChildComponent (tc);
  43445. updateAllItemPositions (false);
  43446. }
  43447. else
  43448. {
  43449. for (int i = getNumItems(); --i >= 0;)
  43450. {
  43451. int currentIndex = getIndexOfChildComponent (tc);
  43452. if (currentIndex < 0)
  43453. {
  43454. if (tc->getEditingMode() == ToolbarItemComponent::editableOnPalette)
  43455. {
  43456. ToolbarItemPalette* const palette = tc->findParentComponentOfClass ((ToolbarItemPalette*) 0);
  43457. if (palette != 0)
  43458. palette->replaceComponent (tc);
  43459. }
  43460. else
  43461. {
  43462. jassert (tc->getEditingMode() == ToolbarItemComponent::editableOnToolbar);
  43463. }
  43464. items.add (tc);
  43465. addChildComponent (tc);
  43466. currentIndex = getIndexOfChildComponent (tc);
  43467. updateAllItemPositions (true);
  43468. }
  43469. int newIndex = currentIndex;
  43470. const int dragObjectLeft = vertical ? (y - tc->dragOffsetY) : (x - tc->dragOffsetX);
  43471. const int dragObjectRight = dragObjectLeft + (vertical ? tc->getHeight() : tc->getWidth());
  43472. const Rectangle<int> current (animator.getComponentDestination (getChildComponent (newIndex)));
  43473. ToolbarItemComponent* const prev = getNextActiveComponent (newIndex, -1);
  43474. if (prev != 0)
  43475. {
  43476. const Rectangle<int> previousPos (animator.getComponentDestination (prev));
  43477. if (abs (dragObjectLeft - (vertical ? previousPos.getY() : previousPos.getX())
  43478. < abs (dragObjectRight - (vertical ? current.getBottom() : current.getRight()))))
  43479. {
  43480. newIndex = getIndexOfChildComponent (prev);
  43481. }
  43482. }
  43483. ToolbarItemComponent* const next = getNextActiveComponent (newIndex, 1);
  43484. if (next != 0)
  43485. {
  43486. const Rectangle<int> nextPos (animator.getComponentDestination (next));
  43487. if (abs (dragObjectLeft - (vertical ? current.getY() : current.getX())
  43488. > abs (dragObjectRight - (vertical ? nextPos.getBottom() : nextPos.getRight()))))
  43489. {
  43490. newIndex = getIndexOfChildComponent (next) + 1;
  43491. }
  43492. }
  43493. if (newIndex != currentIndex)
  43494. {
  43495. items.removeValue (tc);
  43496. removeChildComponent (tc);
  43497. addChildComponent (tc, newIndex);
  43498. items.insert (newIndex, tc);
  43499. updateAllItemPositions (true);
  43500. }
  43501. else
  43502. {
  43503. break;
  43504. }
  43505. }
  43506. }
  43507. }
  43508. }
  43509. void Toolbar::itemDragExit (const String&, Component* sourceComponent)
  43510. {
  43511. ToolbarItemComponent* const tc = dynamic_cast <ToolbarItemComponent*> (sourceComponent);
  43512. if (tc != 0)
  43513. {
  43514. if (isParentOf (tc))
  43515. {
  43516. items.removeValue (tc);
  43517. removeChildComponent (tc);
  43518. updateAllItemPositions (true);
  43519. }
  43520. }
  43521. }
  43522. void Toolbar::itemDropped (const String&, Component*, int, int)
  43523. {
  43524. }
  43525. void Toolbar::mouseDown (const MouseEvent& e)
  43526. {
  43527. if (e.mods.isPopupMenu())
  43528. {
  43529. }
  43530. }
  43531. class ToolbarCustomisationDialog : public DialogWindow
  43532. {
  43533. public:
  43534. ToolbarCustomisationDialog (ToolbarItemFactory& factory,
  43535. Toolbar* const toolbar_,
  43536. const int optionFlags)
  43537. : DialogWindow (TRANS("Add/remove items from toolbar"), Colours::white, true, true),
  43538. toolbar (toolbar_)
  43539. {
  43540. setContentComponent (new CustomiserPanel (factory, toolbar, optionFlags), true, true);
  43541. setResizable (true, true);
  43542. setResizeLimits (400, 300, 1500, 1000);
  43543. positionNearBar();
  43544. }
  43545. ~ToolbarCustomisationDialog()
  43546. {
  43547. setContentComponent (0, true);
  43548. }
  43549. void closeButtonPressed()
  43550. {
  43551. setVisible (false);
  43552. }
  43553. bool canModalEventBeSentToComponent (const Component* comp)
  43554. {
  43555. return toolbar->isParentOf (comp);
  43556. }
  43557. void positionNearBar()
  43558. {
  43559. const Rectangle<int> screenSize (toolbar->getParentMonitorArea());
  43560. const int tbx = toolbar->getScreenX();
  43561. const int tby = toolbar->getScreenY();
  43562. const int gap = 8;
  43563. int x, y;
  43564. if (toolbar->isVertical())
  43565. {
  43566. y = tby;
  43567. if (tbx > screenSize.getCentreX())
  43568. x = tbx - getWidth() - gap;
  43569. else
  43570. x = tbx + toolbar->getWidth() + gap;
  43571. }
  43572. else
  43573. {
  43574. x = tbx + (toolbar->getWidth() - getWidth()) / 2;
  43575. if (tby > screenSize.getCentreY())
  43576. y = tby - getHeight() - gap;
  43577. else
  43578. y = tby + toolbar->getHeight() + gap;
  43579. }
  43580. setTopLeftPosition (x, y);
  43581. }
  43582. private:
  43583. Toolbar* const toolbar;
  43584. class CustomiserPanel : public Component,
  43585. private ComboBoxListener,
  43586. private ButtonListener
  43587. {
  43588. public:
  43589. CustomiserPanel (ToolbarItemFactory& factory_,
  43590. Toolbar* const toolbar_,
  43591. const int optionFlags)
  43592. : factory (factory_),
  43593. toolbar (toolbar_),
  43594. styleBox (0),
  43595. defaultButton (0)
  43596. {
  43597. addAndMakeVisible (palette = new ToolbarItemPalette (factory, toolbar));
  43598. if ((optionFlags & (Toolbar::allowIconsOnlyChoice
  43599. | Toolbar::allowIconsWithTextChoice
  43600. | Toolbar::allowTextOnlyChoice)) != 0)
  43601. {
  43602. addAndMakeVisible (styleBox = new ComboBox (String::empty));
  43603. styleBox->setEditableText (false);
  43604. if ((optionFlags & Toolbar::allowIconsOnlyChoice) != 0)
  43605. styleBox->addItem (TRANS("Show icons only"), 1);
  43606. if ((optionFlags & Toolbar::allowIconsWithTextChoice) != 0)
  43607. styleBox->addItem (TRANS("Show icons and descriptions"), 2);
  43608. if ((optionFlags & Toolbar::allowTextOnlyChoice) != 0)
  43609. styleBox->addItem (TRANS("Show descriptions only"), 3);
  43610. if (toolbar_->getStyle() == Toolbar::iconsOnly)
  43611. styleBox->setSelectedId (1);
  43612. else if (toolbar_->getStyle() == Toolbar::iconsWithText)
  43613. styleBox->setSelectedId (2);
  43614. else if (toolbar_->getStyle() == Toolbar::textOnly)
  43615. styleBox->setSelectedId (3);
  43616. styleBox->addListener (this);
  43617. }
  43618. if ((optionFlags & Toolbar::showResetToDefaultsButton) != 0)
  43619. {
  43620. addAndMakeVisible (defaultButton = new TextButton (TRANS ("Restore to default set of items")));
  43621. defaultButton->addButtonListener (this);
  43622. }
  43623. addAndMakeVisible (instructions = new Label (String::empty,
  43624. 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.")));
  43625. instructions->setFont (Font (13.0f));
  43626. setSize (500, 300);
  43627. }
  43628. ~CustomiserPanel()
  43629. {
  43630. deleteAllChildren();
  43631. }
  43632. void comboBoxChanged (ComboBox*)
  43633. {
  43634. if (styleBox->getSelectedId() == 1)
  43635. toolbar->setStyle (Toolbar::iconsOnly);
  43636. else if (styleBox->getSelectedId() == 2)
  43637. toolbar->setStyle (Toolbar::iconsWithText);
  43638. else if (styleBox->getSelectedId() == 3)
  43639. toolbar->setStyle (Toolbar::textOnly);
  43640. palette->resized(); // to make it update the styles
  43641. }
  43642. void buttonClicked (Button*)
  43643. {
  43644. toolbar->addDefaultItems (factory);
  43645. }
  43646. void paint (Graphics& g)
  43647. {
  43648. Colour background;
  43649. DialogWindow* const dw = findParentComponentOfClass ((DialogWindow*) 0);
  43650. if (dw != 0)
  43651. background = dw->getBackgroundColour();
  43652. g.setColour (background.contrasting().withAlpha (0.3f));
  43653. g.fillRect (palette->getX(), palette->getBottom() - 1, palette->getWidth(), 1);
  43654. }
  43655. void resized()
  43656. {
  43657. palette->setBounds (0, 0, getWidth(), getHeight() - 120);
  43658. if (styleBox != 0)
  43659. styleBox->setBounds (10, getHeight() - 110, 200, 22);
  43660. if (defaultButton != 0)
  43661. {
  43662. defaultButton->changeWidthToFitText (22);
  43663. defaultButton->setTopLeftPosition (240, getHeight() - 110);
  43664. }
  43665. instructions->setBounds (10, getHeight() - 80, getWidth() - 20, 80);
  43666. }
  43667. private:
  43668. ToolbarItemFactory& factory;
  43669. Toolbar* const toolbar;
  43670. Label* instructions;
  43671. ToolbarItemPalette* palette;
  43672. ComboBox* styleBox;
  43673. TextButton* defaultButton;
  43674. };
  43675. };
  43676. void Toolbar::showCustomisationDialog (ToolbarItemFactory& factory, const int optionFlags)
  43677. {
  43678. setEditingActive (true);
  43679. ToolbarCustomisationDialog dw (factory, this, optionFlags);
  43680. dw.runModalLoop();
  43681. jassert (isValidComponent()); // ? deleting the toolbar while it's being edited?
  43682. setEditingActive (false);
  43683. }
  43684. END_JUCE_NAMESPACE
  43685. /*** End of inlined file: juce_Toolbar.cpp ***/
  43686. /*** Start of inlined file: juce_ToolbarItemComponent.cpp ***/
  43687. BEGIN_JUCE_NAMESPACE
  43688. ToolbarItemFactory::ToolbarItemFactory()
  43689. {
  43690. }
  43691. ToolbarItemFactory::~ToolbarItemFactory()
  43692. {
  43693. }
  43694. class ItemDragAndDropOverlayComponent : public Component
  43695. {
  43696. public:
  43697. ItemDragAndDropOverlayComponent()
  43698. : isDragging (false)
  43699. {
  43700. setAlwaysOnTop (true);
  43701. setRepaintsOnMouseActivity (true);
  43702. setMouseCursor (MouseCursor::DraggingHandCursor);
  43703. }
  43704. ~ItemDragAndDropOverlayComponent()
  43705. {
  43706. }
  43707. void paint (Graphics& g)
  43708. {
  43709. ToolbarItemComponent* const tc = dynamic_cast <ToolbarItemComponent*> (getParentComponent());
  43710. if (isMouseOverOrDragging()
  43711. && tc != 0
  43712. && tc->getEditingMode() == ToolbarItemComponent::editableOnToolbar)
  43713. {
  43714. g.setColour (findColour (Toolbar::editingModeOutlineColourId, true));
  43715. g.drawRect (0, 0, getWidth(), getHeight(),
  43716. jmin (2, (getWidth() - 1) / 2, (getHeight() - 1) / 2));
  43717. }
  43718. }
  43719. void mouseDown (const MouseEvent& e)
  43720. {
  43721. isDragging = false;
  43722. ToolbarItemComponent* const tc = dynamic_cast <ToolbarItemComponent*> (getParentComponent());
  43723. if (tc != 0)
  43724. {
  43725. tc->dragOffsetX = e.x;
  43726. tc->dragOffsetY = e.y;
  43727. }
  43728. }
  43729. void mouseDrag (const MouseEvent& e)
  43730. {
  43731. if (! (isDragging || e.mouseWasClicked()))
  43732. {
  43733. isDragging = true;
  43734. DragAndDropContainer* const dnd = DragAndDropContainer::findParentDragContainerFor (this);
  43735. if (dnd != 0)
  43736. {
  43737. dnd->startDragging (Toolbar::toolbarDragDescriptor, getParentComponent(), 0, true);
  43738. ToolbarItemComponent* const tc = dynamic_cast <ToolbarItemComponent*> (getParentComponent());
  43739. if (tc != 0)
  43740. {
  43741. tc->isBeingDragged = true;
  43742. if (tc->getEditingMode() == ToolbarItemComponent::editableOnToolbar)
  43743. tc->setVisible (false);
  43744. }
  43745. }
  43746. }
  43747. }
  43748. void mouseUp (const MouseEvent&)
  43749. {
  43750. isDragging = false;
  43751. ToolbarItemComponent* const tc = dynamic_cast <ToolbarItemComponent*> (getParentComponent());
  43752. if (tc != 0)
  43753. {
  43754. tc->isBeingDragged = false;
  43755. Toolbar* const tb = tc->getToolbar();
  43756. if (tb != 0)
  43757. tb->updateAllItemPositions (true);
  43758. else if (tc->getEditingMode() == ToolbarItemComponent::editableOnToolbar)
  43759. delete tc;
  43760. }
  43761. }
  43762. void parentSizeChanged()
  43763. {
  43764. setBounds (0, 0, getParentWidth(), getParentHeight());
  43765. }
  43766. juce_UseDebuggingNewOperator
  43767. private:
  43768. bool isDragging;
  43769. ItemDragAndDropOverlayComponent (const ItemDragAndDropOverlayComponent&);
  43770. ItemDragAndDropOverlayComponent& operator= (const ItemDragAndDropOverlayComponent&);
  43771. };
  43772. ToolbarItemComponent::ToolbarItemComponent (const int itemId_,
  43773. const String& labelText,
  43774. const bool isBeingUsedAsAButton_)
  43775. : Button (labelText),
  43776. itemId (itemId_),
  43777. mode (normalMode),
  43778. toolbarStyle (Toolbar::iconsOnly),
  43779. dragOffsetX (0),
  43780. dragOffsetY (0),
  43781. isActive (true),
  43782. isBeingDragged (false),
  43783. isBeingUsedAsAButton (isBeingUsedAsAButton_)
  43784. {
  43785. // Your item ID can't be 0!
  43786. jassert (itemId_ != 0);
  43787. }
  43788. ToolbarItemComponent::~ToolbarItemComponent()
  43789. {
  43790. jassert (overlayComp == 0 || overlayComp->isValidComponent());
  43791. overlayComp = 0;
  43792. }
  43793. Toolbar* ToolbarItemComponent::getToolbar() const
  43794. {
  43795. return dynamic_cast <Toolbar*> (getParentComponent());
  43796. }
  43797. bool ToolbarItemComponent::isToolbarVertical() const
  43798. {
  43799. const Toolbar* const t = getToolbar();
  43800. return t != 0 && t->isVertical();
  43801. }
  43802. void ToolbarItemComponent::setStyle (const Toolbar::ToolbarItemStyle& newStyle)
  43803. {
  43804. if (toolbarStyle != newStyle)
  43805. {
  43806. toolbarStyle = newStyle;
  43807. repaint();
  43808. resized();
  43809. }
  43810. }
  43811. void ToolbarItemComponent::paintButton (Graphics& g, bool isMouseOver, bool isMouseDown)
  43812. {
  43813. if (isBeingUsedAsAButton)
  43814. getLookAndFeel().paintToolbarButtonBackground (g, getWidth(), getHeight(),
  43815. isMouseOver, isMouseDown, *this);
  43816. if (toolbarStyle != Toolbar::iconsOnly)
  43817. {
  43818. const int indent = contentArea.getX();
  43819. int y = indent;
  43820. int h = getHeight() - indent * 2;
  43821. if (toolbarStyle == Toolbar::iconsWithText)
  43822. {
  43823. y = contentArea.getBottom() + indent / 2;
  43824. h -= contentArea.getHeight();
  43825. }
  43826. getLookAndFeel().paintToolbarButtonLabel (g, indent, y, getWidth() - indent * 2, h,
  43827. getButtonText(), *this);
  43828. }
  43829. if (! contentArea.isEmpty())
  43830. {
  43831. g.saveState();
  43832. g.setOrigin (contentArea.getX(), contentArea.getY());
  43833. g.reduceClipRegion (0, 0, contentArea.getWidth(), contentArea.getHeight());
  43834. paintButtonArea (g, contentArea.getWidth(), contentArea.getHeight(), isMouseOver, isMouseDown);
  43835. g.restoreState();
  43836. }
  43837. }
  43838. void ToolbarItemComponent::resized()
  43839. {
  43840. if (toolbarStyle != Toolbar::textOnly)
  43841. {
  43842. const int indent = jmin (proportionOfWidth (0.08f),
  43843. proportionOfHeight (0.08f));
  43844. contentArea = Rectangle<int> (indent, indent,
  43845. getWidth() - indent * 2,
  43846. toolbarStyle == Toolbar::iconsWithText ? proportionOfHeight (0.55f)
  43847. : (getHeight() - indent * 2));
  43848. }
  43849. else
  43850. {
  43851. contentArea = Rectangle<int>();
  43852. }
  43853. contentAreaChanged (contentArea);
  43854. }
  43855. void ToolbarItemComponent::setEditingMode (const ToolbarEditingMode newMode)
  43856. {
  43857. if (mode != newMode)
  43858. {
  43859. mode = newMode;
  43860. repaint();
  43861. if (mode == normalMode)
  43862. {
  43863. jassert (overlayComp == 0 || overlayComp->isValidComponent());
  43864. overlayComp = 0;
  43865. }
  43866. else if (overlayComp == 0)
  43867. {
  43868. addAndMakeVisible (overlayComp = new ItemDragAndDropOverlayComponent());
  43869. overlayComp->parentSizeChanged();
  43870. }
  43871. resized();
  43872. }
  43873. }
  43874. END_JUCE_NAMESPACE
  43875. /*** End of inlined file: juce_ToolbarItemComponent.cpp ***/
  43876. /*** Start of inlined file: juce_ToolbarItemPalette.cpp ***/
  43877. BEGIN_JUCE_NAMESPACE
  43878. ToolbarItemPalette::ToolbarItemPalette (ToolbarItemFactory& factory_,
  43879. Toolbar* const toolbar_)
  43880. : factory (factory_),
  43881. toolbar (toolbar_)
  43882. {
  43883. Component* const itemHolder = new Component();
  43884. Array <int> allIds;
  43885. factory_.getAllToolbarItemIds (allIds);
  43886. for (int i = 0; i < allIds.size(); ++i)
  43887. {
  43888. ToolbarItemComponent* const tc = Toolbar::createItem (factory_, allIds.getUnchecked (i));
  43889. jassert (tc != 0);
  43890. if (tc != 0)
  43891. {
  43892. itemHolder->addAndMakeVisible (tc);
  43893. tc->setEditingMode (ToolbarItemComponent::editableOnPalette);
  43894. }
  43895. }
  43896. viewport = new Viewport();
  43897. viewport->setViewedComponent (itemHolder);
  43898. addAndMakeVisible (viewport);
  43899. }
  43900. ToolbarItemPalette::~ToolbarItemPalette()
  43901. {
  43902. viewport->getViewedComponent()->deleteAllChildren();
  43903. deleteAllChildren();
  43904. }
  43905. void ToolbarItemPalette::resized()
  43906. {
  43907. viewport->setBoundsInset (BorderSize (1));
  43908. Component* const itemHolder = viewport->getViewedComponent();
  43909. const int indent = 8;
  43910. const int preferredWidth = viewport->getWidth() - viewport->getScrollBarThickness() - indent;
  43911. const int height = toolbar->getThickness();
  43912. int x = indent;
  43913. int y = indent;
  43914. int maxX = 0;
  43915. for (int i = 0; i < itemHolder->getNumChildComponents(); ++i)
  43916. {
  43917. ToolbarItemComponent* const tc = dynamic_cast <ToolbarItemComponent*> (itemHolder->getChildComponent (i));
  43918. if (tc != 0)
  43919. {
  43920. tc->setStyle (toolbar->getStyle());
  43921. int preferredSize = 1, minSize = 1, maxSize = 1;
  43922. if (tc->getToolbarItemSizes (height, false, preferredSize, minSize, maxSize))
  43923. {
  43924. if (x + preferredSize > preferredWidth && x > indent)
  43925. {
  43926. x = indent;
  43927. y += height;
  43928. }
  43929. tc->setBounds (x, y, preferredSize, height);
  43930. x += preferredSize + 8;
  43931. maxX = jmax (maxX, x);
  43932. }
  43933. }
  43934. }
  43935. itemHolder->setSize (maxX, y + height + 8);
  43936. }
  43937. void ToolbarItemPalette::replaceComponent (ToolbarItemComponent* const comp)
  43938. {
  43939. ToolbarItemComponent* const tc = Toolbar::createItem (factory, comp->getItemId());
  43940. jassert (tc != 0);
  43941. if (tc != 0)
  43942. {
  43943. tc->setBounds (comp->getBounds());
  43944. tc->setStyle (toolbar->getStyle());
  43945. tc->setEditingMode (comp->getEditingMode());
  43946. viewport->getViewedComponent()->addAndMakeVisible (tc, getIndexOfChildComponent (comp));
  43947. }
  43948. }
  43949. END_JUCE_NAMESPACE
  43950. /*** End of inlined file: juce_ToolbarItemPalette.cpp ***/
  43951. /*** Start of inlined file: juce_TreeView.cpp ***/
  43952. BEGIN_JUCE_NAMESPACE
  43953. class TreeViewContentComponent : public Component,
  43954. public TooltipClient
  43955. {
  43956. public:
  43957. TreeViewContentComponent (TreeView* const owner_)
  43958. : owner (owner_),
  43959. buttonUnderMouse (0),
  43960. isDragging (false)
  43961. {
  43962. }
  43963. ~TreeViewContentComponent()
  43964. {
  43965. deleteAllChildren();
  43966. }
  43967. void mouseDown (const MouseEvent& e)
  43968. {
  43969. updateButtonUnderMouse (e);
  43970. isDragging = false;
  43971. needSelectionOnMouseUp = false;
  43972. Rectangle<int> pos;
  43973. TreeViewItem* const item = findItemAt (e.y, pos);
  43974. if (item == 0)
  43975. return;
  43976. // (if the open/close buttons are hidden, we'll treat clicks to the left of the item
  43977. // as selection clicks)
  43978. if (e.x < pos.getX() && owner->openCloseButtonsVisible)
  43979. {
  43980. if (e.x >= pos.getX() - owner->getIndentSize())
  43981. item->setOpen (! item->isOpen());
  43982. // (clicks to the left of an open/close button are ignored)
  43983. }
  43984. else
  43985. {
  43986. // mouse-down inside the body of the item..
  43987. if (! owner->isMultiSelectEnabled())
  43988. item->setSelected (true, true);
  43989. else if (item->isSelected())
  43990. needSelectionOnMouseUp = ! e.mods.isPopupMenu();
  43991. else
  43992. selectBasedOnModifiers (item, e.mods);
  43993. if (e.x >= pos.getX())
  43994. item->itemClicked (e.withNewPosition (e.getPosition() - pos.getPosition()));
  43995. }
  43996. }
  43997. void mouseUp (const MouseEvent& e)
  43998. {
  43999. updateButtonUnderMouse (e);
  44000. if (needSelectionOnMouseUp && e.mouseWasClicked())
  44001. {
  44002. Rectangle<int> pos;
  44003. TreeViewItem* const item = findItemAt (e.y, pos);
  44004. if (item != 0)
  44005. selectBasedOnModifiers (item, e.mods);
  44006. }
  44007. }
  44008. void mouseDoubleClick (const MouseEvent& e)
  44009. {
  44010. if (e.getNumberOfClicks() != 3) // ignore triple clicks
  44011. {
  44012. Rectangle<int> pos;
  44013. TreeViewItem* const item = findItemAt (e.y, pos);
  44014. if (item != 0 && (e.x >= pos.getX() || ! owner->openCloseButtonsVisible))
  44015. item->itemDoubleClicked (e.withNewPosition (e.getPosition() - pos.getPosition()));
  44016. }
  44017. }
  44018. void mouseDrag (const MouseEvent& e)
  44019. {
  44020. if (isEnabled()
  44021. && ! (isDragging || e.mouseWasClicked()
  44022. || e.getDistanceFromDragStart() < 5
  44023. || e.mods.isPopupMenu()))
  44024. {
  44025. isDragging = true;
  44026. Rectangle<int> pos;
  44027. TreeViewItem* const item = findItemAt (e.getMouseDownY(), pos);
  44028. if (item != 0 && e.getMouseDownX() >= pos.getX())
  44029. {
  44030. const String dragDescription (item->getDragSourceDescription());
  44031. if (dragDescription.isNotEmpty())
  44032. {
  44033. DragAndDropContainer* const dragContainer
  44034. = DragAndDropContainer::findParentDragContainerFor (this);
  44035. if (dragContainer != 0)
  44036. {
  44037. pos.setSize (pos.getWidth(), item->itemHeight);
  44038. Image* dragImage = Component::createComponentSnapshot (pos, true);
  44039. dragImage->multiplyAllAlphas (0.6f);
  44040. Point<int> imageOffset (pos.getX() - e.x, pos.getY() - e.y);
  44041. dragContainer->startDragging (dragDescription, owner, dragImage, true, &imageOffset);
  44042. }
  44043. else
  44044. {
  44045. // to be able to do a drag-and-drop operation, the treeview needs to
  44046. // be inside a component which is also a DragAndDropContainer.
  44047. jassertfalse
  44048. }
  44049. }
  44050. }
  44051. }
  44052. }
  44053. void mouseMove (const MouseEvent& e)
  44054. {
  44055. updateButtonUnderMouse (e);
  44056. }
  44057. void mouseExit (const MouseEvent& e)
  44058. {
  44059. updateButtonUnderMouse (e);
  44060. }
  44061. void paint (Graphics& g);
  44062. TreeViewItem* findItemAt (int y, Rectangle<int>& itemPosition) const;
  44063. static bool isMouseDraggingInChildCompOf (Component* const comp)
  44064. {
  44065. for (int i = Desktop::getInstance().getNumMouseSources(); --i >= 0;)
  44066. {
  44067. MouseInputSource* source = Desktop::getInstance().getMouseSource(i);
  44068. if (source->isDragging())
  44069. {
  44070. Component* const underMouse = source->getComponentUnderMouse();
  44071. if (underMouse != 0 && (comp == underMouse || comp->isParentOf (underMouse)))
  44072. return true;
  44073. }
  44074. }
  44075. return false;
  44076. }
  44077. void updateComponents()
  44078. {
  44079. const int visibleTop = -getY();
  44080. const int visibleBottom = visibleTop + getParentHeight();
  44081. BigInteger itemsToKeep;
  44082. TreeViewItem* item = owner->rootItem;
  44083. int y = (item != 0 && !owner->rootItemVisible) ? -item->itemHeight : 0;
  44084. while (item != 0 && y < visibleBottom)
  44085. {
  44086. y += item->itemHeight;
  44087. if (y >= visibleTop)
  44088. {
  44089. const int index = rowComponentIds.indexOf (item->uid);
  44090. if (index < 0)
  44091. {
  44092. Component* const comp = item->createItemComponent();
  44093. if (comp != 0)
  44094. {
  44095. addAndMakeVisible (comp);
  44096. itemsToKeep.setBit (rowComponentItems.size());
  44097. rowComponentItems.add (item);
  44098. rowComponentIds.add (item->uid);
  44099. rowComponents.add (comp);
  44100. }
  44101. }
  44102. else
  44103. {
  44104. itemsToKeep.setBit (index);
  44105. }
  44106. }
  44107. item = item->getNextVisibleItem (true);
  44108. }
  44109. for (int i = rowComponentItems.size(); --i >= 0;)
  44110. {
  44111. Component* const comp = (Component*) rowComponents.getUnchecked(i);
  44112. bool keep = false;
  44113. if (isParentOf (comp))
  44114. {
  44115. if (itemsToKeep[i])
  44116. {
  44117. const TreeViewItem* const item = (TreeViewItem*) rowComponentItems.getUnchecked(i);
  44118. Rectangle<int> pos (item->getItemPosition (false));
  44119. pos.setSize (pos.getWidth(), item->itemHeight);
  44120. if (pos.getBottom() >= visibleTop && pos.getY() < visibleBottom)
  44121. {
  44122. keep = true;
  44123. comp->setBounds (pos);
  44124. }
  44125. }
  44126. if ((! keep) && isMouseDraggingInChildCompOf (comp))
  44127. {
  44128. keep = true;
  44129. comp->setSize (0, 0);
  44130. }
  44131. }
  44132. if (! keep)
  44133. {
  44134. delete comp;
  44135. rowComponents.remove (i);
  44136. rowComponentIds.remove (i);
  44137. rowComponentItems.remove (i);
  44138. }
  44139. }
  44140. }
  44141. void updateButtonUnderMouse (const MouseEvent& e)
  44142. {
  44143. TreeViewItem* newItem = 0;
  44144. if (owner->openCloseButtonsVisible)
  44145. {
  44146. Rectangle<int> pos;
  44147. TreeViewItem* item = findItemAt (e.y, pos);
  44148. if (item != 0 && e.x < pos.getX() && e.x >= pos.getX() - owner->getIndentSize())
  44149. {
  44150. newItem = item;
  44151. if (! newItem->mightContainSubItems())
  44152. newItem = 0;
  44153. }
  44154. }
  44155. if (buttonUnderMouse != newItem)
  44156. {
  44157. if (buttonUnderMouse != 0 && containsItem (buttonUnderMouse))
  44158. {
  44159. const Rectangle<int> r (buttonUnderMouse->getItemPosition (false));
  44160. repaint (0, r.getY(), r.getX(), buttonUnderMouse->getItemHeight());
  44161. }
  44162. buttonUnderMouse = newItem;
  44163. if (buttonUnderMouse != 0)
  44164. {
  44165. const Rectangle<int> r (buttonUnderMouse->getItemPosition (false));
  44166. repaint (0, r.getY(), r.getX(), buttonUnderMouse->getItemHeight());
  44167. }
  44168. }
  44169. }
  44170. bool isMouseOverButton (TreeViewItem* item) const throw()
  44171. {
  44172. return item == buttonUnderMouse;
  44173. }
  44174. void resized()
  44175. {
  44176. owner->itemsChanged();
  44177. }
  44178. const String getTooltip()
  44179. {
  44180. Rectangle<int> pos;
  44181. TreeViewItem* const item = findItemAt (getMouseXYRelative().getY(), pos);
  44182. if (item != 0)
  44183. return item->getTooltip();
  44184. return owner->getTooltip();
  44185. }
  44186. juce_UseDebuggingNewOperator
  44187. private:
  44188. TreeView* const owner;
  44189. VoidArray rowComponentItems;
  44190. Array <int> rowComponentIds;
  44191. VoidArray rowComponents;
  44192. TreeViewItem* buttonUnderMouse;
  44193. bool isDragging, needSelectionOnMouseUp;
  44194. TreeViewContentComponent (const TreeViewContentComponent&);
  44195. TreeViewContentComponent& operator= (const TreeViewContentComponent&);
  44196. void selectBasedOnModifiers (TreeViewItem* const item, const ModifierKeys& modifiers)
  44197. {
  44198. TreeViewItem* firstSelected = 0;
  44199. if (modifiers.isShiftDown() && ((firstSelected = owner->getSelectedItem (0)) != 0))
  44200. {
  44201. TreeViewItem* const lastSelected = owner->getSelectedItem (owner->getNumSelectedItems() - 1);
  44202. jassert (lastSelected != 0);
  44203. int rowStart = firstSelected->getRowNumberInTree();
  44204. int rowEnd = lastSelected->getRowNumberInTree();
  44205. if (rowStart > rowEnd)
  44206. swapVariables (rowStart, rowEnd);
  44207. int ourRow = item->getRowNumberInTree();
  44208. int otherEnd = ourRow < rowEnd ? rowStart : rowEnd;
  44209. if (ourRow > otherEnd)
  44210. swapVariables (ourRow, otherEnd);
  44211. for (int i = ourRow; i <= otherEnd; ++i)
  44212. owner->getItemOnRow (i)->setSelected (true, false);
  44213. }
  44214. else
  44215. {
  44216. const bool cmd = modifiers.isCommandDown();
  44217. item->setSelected ((! cmd) || (! item->isSelected()), ! cmd);
  44218. }
  44219. }
  44220. bool containsItem (TreeViewItem* const item) const
  44221. {
  44222. for (int i = rowComponentItems.size(); --i >= 0;)
  44223. if ((TreeViewItem*) rowComponentItems.getUnchecked (i) == item)
  44224. return true;
  44225. return false;
  44226. }
  44227. };
  44228. class TreeViewport : public Viewport
  44229. {
  44230. public:
  44231. TreeViewport() throw() {}
  44232. ~TreeViewport() throw() {}
  44233. void updateComponents()
  44234. {
  44235. if (getViewedComponent() != 0)
  44236. ((TreeViewContentComponent*) getViewedComponent())->updateComponents();
  44237. repaint();
  44238. }
  44239. void visibleAreaChanged (int, int, int, int)
  44240. {
  44241. updateComponents();
  44242. }
  44243. juce_UseDebuggingNewOperator
  44244. private:
  44245. TreeViewport (const TreeViewport&);
  44246. TreeViewport& operator= (const TreeViewport&);
  44247. };
  44248. TreeView::TreeView (const String& componentName)
  44249. : Component (componentName),
  44250. rootItem (0),
  44251. dragInsertPointHighlight (0),
  44252. dragTargetGroupHighlight (0),
  44253. indentSize (24),
  44254. defaultOpenness (false),
  44255. needsRecalculating (true),
  44256. rootItemVisible (true),
  44257. multiSelectEnabled (false),
  44258. openCloseButtonsVisible (true)
  44259. {
  44260. addAndMakeVisible (viewport = new TreeViewport());
  44261. viewport->setViewedComponent (new TreeViewContentComponent (this));
  44262. viewport->setWantsKeyboardFocus (false);
  44263. setWantsKeyboardFocus (true);
  44264. }
  44265. TreeView::~TreeView()
  44266. {
  44267. if (rootItem != 0)
  44268. rootItem->setOwnerView (0);
  44269. deleteAllChildren();
  44270. }
  44271. void TreeView::setRootItem (TreeViewItem* const newRootItem)
  44272. {
  44273. if (rootItem != newRootItem)
  44274. {
  44275. if (newRootItem != 0)
  44276. {
  44277. jassert (newRootItem->ownerView == 0); // can't use a tree item in more than one tree at once..
  44278. if (newRootItem->ownerView != 0)
  44279. newRootItem->ownerView->setRootItem (0);
  44280. }
  44281. if (rootItem != 0)
  44282. rootItem->setOwnerView (0);
  44283. rootItem = newRootItem;
  44284. if (newRootItem != 0)
  44285. newRootItem->setOwnerView (this);
  44286. needsRecalculating = true;
  44287. handleAsyncUpdate();
  44288. if (rootItem != 0 && (defaultOpenness || ! rootItemVisible))
  44289. {
  44290. rootItem->setOpen (false); // force a re-open
  44291. rootItem->setOpen (true);
  44292. }
  44293. }
  44294. }
  44295. void TreeView::deleteRootItem()
  44296. {
  44297. const ScopedPointer <TreeViewItem> deleter (rootItem);
  44298. setRootItem (0);
  44299. }
  44300. void TreeView::setRootItemVisible (const bool shouldBeVisible)
  44301. {
  44302. rootItemVisible = shouldBeVisible;
  44303. if (rootItem != 0 && (defaultOpenness || ! rootItemVisible))
  44304. {
  44305. rootItem->setOpen (false); // force a re-open
  44306. rootItem->setOpen (true);
  44307. }
  44308. itemsChanged();
  44309. }
  44310. void TreeView::colourChanged()
  44311. {
  44312. setOpaque (findColour (backgroundColourId).isOpaque());
  44313. repaint();
  44314. }
  44315. void TreeView::setIndentSize (const int newIndentSize)
  44316. {
  44317. if (indentSize != newIndentSize)
  44318. {
  44319. indentSize = newIndentSize;
  44320. resized();
  44321. }
  44322. }
  44323. void TreeView::setDefaultOpenness (const bool isOpenByDefault)
  44324. {
  44325. if (defaultOpenness != isOpenByDefault)
  44326. {
  44327. defaultOpenness = isOpenByDefault;
  44328. itemsChanged();
  44329. }
  44330. }
  44331. void TreeView::setMultiSelectEnabled (const bool canMultiSelect)
  44332. {
  44333. multiSelectEnabled = canMultiSelect;
  44334. }
  44335. void TreeView::setOpenCloseButtonsVisible (const bool shouldBeVisible)
  44336. {
  44337. if (openCloseButtonsVisible != shouldBeVisible)
  44338. {
  44339. openCloseButtonsVisible = shouldBeVisible;
  44340. itemsChanged();
  44341. }
  44342. }
  44343. void TreeView::clearSelectedItems()
  44344. {
  44345. if (rootItem != 0)
  44346. rootItem->deselectAllRecursively();
  44347. }
  44348. int TreeView::getNumSelectedItems() const throw()
  44349. {
  44350. return (rootItem != 0) ? rootItem->countSelectedItemsRecursively() : 0;
  44351. }
  44352. TreeViewItem* TreeView::getSelectedItem (const int index) const throw()
  44353. {
  44354. return (rootItem != 0) ? rootItem->getSelectedItemWithIndex (index) : 0;
  44355. }
  44356. int TreeView::getNumRowsInTree() const
  44357. {
  44358. if (rootItem != 0)
  44359. return rootItem->getNumRows() - (rootItemVisible ? 0 : 1);
  44360. return 0;
  44361. }
  44362. TreeViewItem* TreeView::getItemOnRow (int index) const
  44363. {
  44364. if (! rootItemVisible)
  44365. ++index;
  44366. if (rootItem != 0 && index >= 0)
  44367. return rootItem->getItemOnRow (index);
  44368. return 0;
  44369. }
  44370. TreeViewItem* TreeView::getItemAt (int y) const throw()
  44371. {
  44372. TreeViewContentComponent* const tc = (TreeViewContentComponent*) viewport->getViewedComponent();
  44373. Rectangle<int> pos;
  44374. return tc->findItemAt (relativePositionToOtherComponent (tc, Point<int> (0, y)).getY(), pos);
  44375. }
  44376. TreeViewItem* TreeView::findItemFromIdentifierString (const String& identifierString) const
  44377. {
  44378. if (rootItem == 0)
  44379. return 0;
  44380. return rootItem->findItemFromIdentifierString (identifierString);
  44381. }
  44382. XmlElement* TreeView::getOpennessState (const bool alsoIncludeScrollPosition) const
  44383. {
  44384. XmlElement* e = 0;
  44385. if (rootItem != 0)
  44386. {
  44387. e = rootItem->getOpennessState();
  44388. if (e != 0 && alsoIncludeScrollPosition)
  44389. e->setAttribute (T("scrollPos"), viewport->getViewPositionY());
  44390. }
  44391. return e;
  44392. }
  44393. void TreeView::restoreOpennessState (const XmlElement& newState)
  44394. {
  44395. if (rootItem != 0)
  44396. {
  44397. rootItem->restoreOpennessState (newState);
  44398. if (newState.hasAttribute (T("scrollPos")))
  44399. viewport->setViewPosition (viewport->getViewPositionX(),
  44400. newState.getIntAttribute (T("scrollPos")));
  44401. }
  44402. }
  44403. void TreeView::paint (Graphics& g)
  44404. {
  44405. g.fillAll (findColour (backgroundColourId));
  44406. }
  44407. void TreeView::resized()
  44408. {
  44409. viewport->setBounds (0, 0, getWidth(), getHeight());
  44410. itemsChanged();
  44411. handleAsyncUpdate();
  44412. }
  44413. void TreeView::enablementChanged()
  44414. {
  44415. repaint();
  44416. }
  44417. void TreeView::moveSelectedRow (int delta)
  44418. {
  44419. if (delta == 0)
  44420. return;
  44421. int rowSelected = 0;
  44422. TreeViewItem* const firstSelected = getSelectedItem (0);
  44423. if (firstSelected != 0)
  44424. rowSelected = firstSelected->getRowNumberInTree();
  44425. rowSelected = jlimit (0, getNumRowsInTree() - 1, rowSelected + delta);
  44426. for (;;)
  44427. {
  44428. TreeViewItem* item = getItemOnRow (rowSelected);
  44429. if (item != 0)
  44430. {
  44431. if (! item->canBeSelected())
  44432. {
  44433. // if the row we want to highlight doesn't allow it, try skipping
  44434. // to the next item..
  44435. const int nextRowToTry = jlimit (0, getNumRowsInTree() - 1,
  44436. rowSelected + (delta < 0 ? -1 : 1));
  44437. if (rowSelected != nextRowToTry)
  44438. {
  44439. rowSelected = nextRowToTry;
  44440. continue;
  44441. }
  44442. else
  44443. {
  44444. break;
  44445. }
  44446. }
  44447. item->setSelected (true, true);
  44448. scrollToKeepItemVisible (item);
  44449. }
  44450. break;
  44451. }
  44452. }
  44453. void TreeView::scrollToKeepItemVisible (TreeViewItem* item)
  44454. {
  44455. if (item != 0 && item->ownerView == this)
  44456. {
  44457. handleAsyncUpdate();
  44458. item = item->getDeepestOpenParentItem();
  44459. int y = item->y;
  44460. int viewTop = viewport->getViewPositionY();
  44461. if (y < viewTop)
  44462. {
  44463. viewport->setViewPosition (viewport->getViewPositionX(), y);
  44464. }
  44465. else if (y + item->itemHeight > viewTop + viewport->getViewHeight())
  44466. {
  44467. viewport->setViewPosition (viewport->getViewPositionX(),
  44468. (y + item->itemHeight) - viewport->getViewHeight());
  44469. }
  44470. }
  44471. }
  44472. bool TreeView::keyPressed (const KeyPress& key)
  44473. {
  44474. if (key.isKeyCode (KeyPress::upKey))
  44475. {
  44476. moveSelectedRow (-1);
  44477. }
  44478. else if (key.isKeyCode (KeyPress::downKey))
  44479. {
  44480. moveSelectedRow (1);
  44481. }
  44482. else if (key.isKeyCode (KeyPress::pageDownKey) || key.isKeyCode (KeyPress::pageUpKey))
  44483. {
  44484. if (rootItem != 0)
  44485. {
  44486. int rowsOnScreen = getHeight() / jmax (1, rootItem->itemHeight);
  44487. if (key.isKeyCode (KeyPress::pageUpKey))
  44488. rowsOnScreen = -rowsOnScreen;
  44489. moveSelectedRow (rowsOnScreen);
  44490. }
  44491. }
  44492. else if (key.isKeyCode (KeyPress::homeKey))
  44493. {
  44494. moveSelectedRow (-0x3fffffff);
  44495. }
  44496. else if (key.isKeyCode (KeyPress::endKey))
  44497. {
  44498. moveSelectedRow (0x3fffffff);
  44499. }
  44500. else if (key.isKeyCode (KeyPress::returnKey))
  44501. {
  44502. TreeViewItem* const firstSelected = getSelectedItem (0);
  44503. if (firstSelected != 0)
  44504. firstSelected->setOpen (! firstSelected->isOpen());
  44505. }
  44506. else if (key.isKeyCode (KeyPress::leftKey))
  44507. {
  44508. TreeViewItem* const firstSelected = getSelectedItem (0);
  44509. if (firstSelected != 0)
  44510. {
  44511. if (firstSelected->isOpen())
  44512. {
  44513. firstSelected->setOpen (false);
  44514. }
  44515. else
  44516. {
  44517. TreeViewItem* parent = firstSelected->parentItem;
  44518. if ((! rootItemVisible) && parent == rootItem)
  44519. parent = 0;
  44520. if (parent != 0)
  44521. {
  44522. parent->setSelected (true, true);
  44523. scrollToKeepItemVisible (parent);
  44524. }
  44525. }
  44526. }
  44527. }
  44528. else if (key.isKeyCode (KeyPress::rightKey))
  44529. {
  44530. TreeViewItem* const firstSelected = getSelectedItem (0);
  44531. if (firstSelected != 0)
  44532. {
  44533. if (firstSelected->isOpen() || ! firstSelected->mightContainSubItems())
  44534. moveSelectedRow (1);
  44535. else
  44536. firstSelected->setOpen (true);
  44537. }
  44538. }
  44539. else
  44540. {
  44541. return false;
  44542. }
  44543. return true;
  44544. }
  44545. void TreeView::itemsChanged() throw()
  44546. {
  44547. needsRecalculating = true;
  44548. repaint();
  44549. triggerAsyncUpdate();
  44550. }
  44551. void TreeView::handleAsyncUpdate()
  44552. {
  44553. if (needsRecalculating)
  44554. {
  44555. needsRecalculating = false;
  44556. const ScopedLock sl (nodeAlterationLock);
  44557. if (rootItem != 0)
  44558. rootItem->updatePositions (rootItemVisible ? 0 : -rootItem->itemHeight);
  44559. ((TreeViewport*) viewport)->updateComponents();
  44560. if (rootItem != 0)
  44561. {
  44562. viewport->getViewedComponent()
  44563. ->setSize (jmax (viewport->getMaximumVisibleWidth(), rootItem->totalWidth),
  44564. rootItem->totalHeight - (rootItemVisible ? 0 : rootItem->itemHeight));
  44565. }
  44566. else
  44567. {
  44568. viewport->getViewedComponent()->setSize (0, 0);
  44569. }
  44570. }
  44571. }
  44572. class TreeViewDragInsertPointHighlight : public Component
  44573. {
  44574. public:
  44575. TreeViewDragInsertPointHighlight()
  44576. : lastItem (0)
  44577. {
  44578. setSize (100, 12);
  44579. setAlwaysOnTop (true);
  44580. setInterceptsMouseClicks (false, false);
  44581. }
  44582. ~TreeViewDragInsertPointHighlight() {}
  44583. void setTargetPosition (TreeViewItem* const item, int insertIndex, const int x, const int y, const int width) throw()
  44584. {
  44585. lastItem = item;
  44586. lastIndex = insertIndex;
  44587. const int offset = getHeight() / 2;
  44588. setBounds (x - offset, y - offset, width - (x - offset), getHeight());
  44589. }
  44590. void paint (Graphics& g)
  44591. {
  44592. Path p;
  44593. const float h = (float) getHeight();
  44594. p.addEllipse (2.0f, 2.0f, h - 4.0f, h - 4.0f);
  44595. p.startNewSubPath (h - 2.0f, h / 2.0f);
  44596. p.lineTo ((float) getWidth(), h / 2.0f);
  44597. g.setColour (findColour (TreeView::dragAndDropIndicatorColourId, true));
  44598. g.strokePath (p, PathStrokeType (2.0f));
  44599. }
  44600. TreeViewItem* lastItem;
  44601. int lastIndex;
  44602. };
  44603. class TreeViewDragTargetGroupHighlight : public Component
  44604. {
  44605. public:
  44606. TreeViewDragTargetGroupHighlight()
  44607. {
  44608. setAlwaysOnTop (true);
  44609. setInterceptsMouseClicks (false, false);
  44610. }
  44611. ~TreeViewDragTargetGroupHighlight() {}
  44612. void setTargetPosition (TreeViewItem* const item) throw()
  44613. {
  44614. Rectangle<int> r (item->getItemPosition (true));
  44615. r.setHeight (item->getItemHeight());
  44616. setBounds (r);
  44617. }
  44618. void paint (Graphics& g)
  44619. {
  44620. g.setColour (findColour (TreeView::dragAndDropIndicatorColourId, true));
  44621. g.drawRoundedRectangle (1.0f, 1.0f, getWidth() - 2.0f, getHeight() - 2.0f, 3.0f, 2.0f);
  44622. }
  44623. };
  44624. void TreeView::showDragHighlight (TreeViewItem* item, int insertIndex, int x, int y) throw()
  44625. {
  44626. beginDragAutoRepeat (1000 / 30);
  44627. if (dragInsertPointHighlight == 0)
  44628. {
  44629. addAndMakeVisible (dragInsertPointHighlight = new TreeViewDragInsertPointHighlight());
  44630. addAndMakeVisible (dragTargetGroupHighlight = new TreeViewDragTargetGroupHighlight());
  44631. }
  44632. ((TreeViewDragInsertPointHighlight*) dragInsertPointHighlight)
  44633. ->setTargetPosition (item, insertIndex, x, y, viewport->getViewWidth());
  44634. ((TreeViewDragTargetGroupHighlight*) dragTargetGroupHighlight)
  44635. ->setTargetPosition (item);
  44636. }
  44637. void TreeView::hideDragHighlight() throw()
  44638. {
  44639. deleteAndZero (dragInsertPointHighlight);
  44640. deleteAndZero (dragTargetGroupHighlight);
  44641. }
  44642. TreeViewItem* TreeView::getInsertPosition (int& x, int& y, int& insertIndex,
  44643. const StringArray& files, const String& sourceDescription,
  44644. Component* sourceComponent) const throw()
  44645. {
  44646. insertIndex = 0;
  44647. TreeViewItem* item = getItemAt (y);
  44648. if (item == 0)
  44649. return 0;
  44650. Rectangle<int> itemPos (item->getItemPosition (true));
  44651. insertIndex = item->getIndexInParent();
  44652. const int oldY = y;
  44653. y = itemPos.getY();
  44654. if (item->getNumSubItems() == 0 || ! item->isOpen())
  44655. {
  44656. if (files.size() > 0 ? item->isInterestedInFileDrag (files)
  44657. : item->isInterestedInDragSource (sourceDescription, sourceComponent))
  44658. {
  44659. // Check if we're trying to drag into an empty group item..
  44660. if (oldY > itemPos.getY() + itemPos.getHeight() / 4
  44661. && oldY < itemPos.getBottom() - itemPos.getHeight() / 4)
  44662. {
  44663. insertIndex = 0;
  44664. x = itemPos.getX() + getIndentSize();
  44665. y = itemPos.getBottom();
  44666. return item;
  44667. }
  44668. }
  44669. }
  44670. if (oldY > itemPos.getCentreY())
  44671. {
  44672. y += item->getItemHeight();
  44673. while (item->isLastOfSiblings() && item->parentItem != 0
  44674. && item->parentItem->parentItem != 0)
  44675. {
  44676. if (x > itemPos.getX())
  44677. break;
  44678. item = item->parentItem;
  44679. itemPos = item->getItemPosition (true);
  44680. insertIndex = item->getIndexInParent();
  44681. }
  44682. ++insertIndex;
  44683. }
  44684. x = itemPos.getX();
  44685. return item->parentItem;
  44686. }
  44687. void TreeView::handleDrag (const StringArray& files, const String& sourceDescription, Component* sourceComponent, int x, int y)
  44688. {
  44689. const bool scrolled = viewport->autoScroll (x, y, 20, 10);
  44690. int insertIndex;
  44691. TreeViewItem* const item = getInsertPosition (x, y, insertIndex, files, sourceDescription, sourceComponent);
  44692. if (item != 0)
  44693. {
  44694. if (scrolled || dragInsertPointHighlight == 0
  44695. || ((TreeViewDragInsertPointHighlight*) dragInsertPointHighlight)->lastItem != item
  44696. || ((TreeViewDragInsertPointHighlight*) dragInsertPointHighlight)->lastIndex != insertIndex)
  44697. {
  44698. if (files.size() > 0 ? item->isInterestedInFileDrag (files)
  44699. : item->isInterestedInDragSource (sourceDescription, sourceComponent))
  44700. showDragHighlight (item, insertIndex, x, y);
  44701. else
  44702. hideDragHighlight();
  44703. }
  44704. }
  44705. else
  44706. {
  44707. hideDragHighlight();
  44708. }
  44709. }
  44710. void TreeView::handleDrop (const StringArray& files, const String& sourceDescription, Component* sourceComponent, int x, int y)
  44711. {
  44712. hideDragHighlight();
  44713. int insertIndex;
  44714. TreeViewItem* const item = getInsertPosition (x, y, insertIndex, files, sourceDescription, sourceComponent);
  44715. if (item != 0)
  44716. {
  44717. if (files.size() > 0)
  44718. {
  44719. if (item->isInterestedInFileDrag (files))
  44720. item->filesDropped (files, insertIndex);
  44721. }
  44722. else
  44723. {
  44724. if (item->isInterestedInDragSource (sourceDescription, sourceComponent))
  44725. item->itemDropped (sourceDescription, sourceComponent, insertIndex);
  44726. }
  44727. }
  44728. }
  44729. bool TreeView::isInterestedInFileDrag (const StringArray&)
  44730. {
  44731. return true;
  44732. }
  44733. void TreeView::fileDragEnter (const StringArray& files, int x, int y)
  44734. {
  44735. fileDragMove (files, x, y);
  44736. }
  44737. void TreeView::fileDragMove (const StringArray& files, int x, int y)
  44738. {
  44739. handleDrag (files, String::empty, 0, x, y);
  44740. }
  44741. void TreeView::fileDragExit (const StringArray&)
  44742. {
  44743. hideDragHighlight();
  44744. }
  44745. void TreeView::filesDropped (const StringArray& files, int x, int y)
  44746. {
  44747. handleDrop (files, String::empty, 0, x, y);
  44748. }
  44749. bool TreeView::isInterestedInDragSource (const String& /*sourceDescription*/, Component* /*sourceComponent*/)
  44750. {
  44751. return true;
  44752. }
  44753. void TreeView::itemDragEnter (const String& sourceDescription, Component* sourceComponent, int x, int y)
  44754. {
  44755. itemDragMove (sourceDescription, sourceComponent, x, y);
  44756. }
  44757. void TreeView::itemDragMove (const String& sourceDescription, Component* sourceComponent, int x, int y)
  44758. {
  44759. handleDrag (StringArray(), sourceDescription, sourceComponent, x, y);
  44760. }
  44761. void TreeView::itemDragExit (const String& /*sourceDescription*/, Component* /*sourceComponent*/)
  44762. {
  44763. hideDragHighlight();
  44764. }
  44765. void TreeView::itemDropped (const String& sourceDescription, Component* sourceComponent, int x, int y)
  44766. {
  44767. handleDrop (StringArray(), sourceDescription, sourceComponent, x, y);
  44768. }
  44769. void TreeViewContentComponent::paint (Graphics& g)
  44770. {
  44771. if (owner->rootItem != 0)
  44772. {
  44773. owner->handleAsyncUpdate();
  44774. if (! owner->rootItemVisible)
  44775. g.setOrigin (0, -owner->rootItem->itemHeight);
  44776. owner->rootItem->paintRecursively (g, getWidth());
  44777. }
  44778. }
  44779. TreeViewItem* TreeViewContentComponent::findItemAt (int y, Rectangle<int>& itemPosition) const
  44780. {
  44781. if (owner->rootItem != 0)
  44782. {
  44783. owner->handleAsyncUpdate();
  44784. if (! owner->rootItemVisible)
  44785. y += owner->rootItem->itemHeight;
  44786. TreeViewItem* const ti = owner->rootItem->findItemRecursively (y);
  44787. if (ti != 0)
  44788. itemPosition = ti->getItemPosition (false);
  44789. return ti;
  44790. }
  44791. return 0;
  44792. }
  44793. enum TreeViewOpenness
  44794. {
  44795. opennessDefault = 0,
  44796. opennessClosed = 1,
  44797. opennessOpen = 2
  44798. };
  44799. TreeViewItem::TreeViewItem()
  44800. : ownerView (0),
  44801. parentItem (0),
  44802. y (0),
  44803. itemHeight (0),
  44804. totalHeight (0),
  44805. selected (false),
  44806. redrawNeeded (true),
  44807. drawLinesInside (true),
  44808. drawsInLeftMargin (false),
  44809. openness (opennessDefault)
  44810. {
  44811. static int nextUID = 0;
  44812. uid = nextUID++;
  44813. }
  44814. TreeViewItem::~TreeViewItem()
  44815. {
  44816. }
  44817. const String TreeViewItem::getUniqueName() const
  44818. {
  44819. return String::empty;
  44820. }
  44821. void TreeViewItem::itemOpennessChanged (bool)
  44822. {
  44823. }
  44824. int TreeViewItem::getNumSubItems() const throw()
  44825. {
  44826. return subItems.size();
  44827. }
  44828. TreeViewItem* TreeViewItem::getSubItem (const int index) const throw()
  44829. {
  44830. return subItems [index];
  44831. }
  44832. void TreeViewItem::clearSubItems()
  44833. {
  44834. if (subItems.size() > 0)
  44835. {
  44836. if (ownerView != 0)
  44837. {
  44838. const ScopedLock sl (ownerView->nodeAlterationLock);
  44839. subItems.clear();
  44840. treeHasChanged();
  44841. }
  44842. else
  44843. {
  44844. subItems.clear();
  44845. }
  44846. }
  44847. }
  44848. void TreeViewItem::addSubItem (TreeViewItem* const newItem, const int insertPosition)
  44849. {
  44850. if (newItem != 0)
  44851. {
  44852. newItem->parentItem = this;
  44853. newItem->setOwnerView (ownerView);
  44854. newItem->y = 0;
  44855. newItem->itemHeight = newItem->getItemHeight();
  44856. newItem->totalHeight = 0;
  44857. newItem->itemWidth = newItem->getItemWidth();
  44858. newItem->totalWidth = 0;
  44859. if (ownerView != 0)
  44860. {
  44861. const ScopedLock sl (ownerView->nodeAlterationLock);
  44862. subItems.insert (insertPosition, newItem);
  44863. treeHasChanged();
  44864. if (newItem->isOpen())
  44865. newItem->itemOpennessChanged (true);
  44866. }
  44867. else
  44868. {
  44869. subItems.insert (insertPosition, newItem);
  44870. if (newItem->isOpen())
  44871. newItem->itemOpennessChanged (true);
  44872. }
  44873. }
  44874. }
  44875. void TreeViewItem::removeSubItem (const int index, const bool deleteItem)
  44876. {
  44877. if (ownerView != 0)
  44878. {
  44879. const ScopedLock sl (ownerView->nodeAlterationLock);
  44880. if (((unsigned int) index) < (unsigned int) subItems.size())
  44881. {
  44882. subItems.remove (index, deleteItem);
  44883. treeHasChanged();
  44884. }
  44885. }
  44886. else
  44887. {
  44888. subItems.remove (index, deleteItem);
  44889. }
  44890. }
  44891. bool TreeViewItem::isOpen() const throw()
  44892. {
  44893. if (openness == opennessDefault)
  44894. return ownerView != 0 && ownerView->defaultOpenness;
  44895. else
  44896. return openness == opennessOpen;
  44897. }
  44898. void TreeViewItem::setOpen (const bool shouldBeOpen)
  44899. {
  44900. if (isOpen() != shouldBeOpen)
  44901. {
  44902. openness = shouldBeOpen ? opennessOpen
  44903. : opennessClosed;
  44904. treeHasChanged();
  44905. itemOpennessChanged (isOpen());
  44906. }
  44907. }
  44908. bool TreeViewItem::isSelected() const throw()
  44909. {
  44910. return selected;
  44911. }
  44912. void TreeViewItem::deselectAllRecursively()
  44913. {
  44914. setSelected (false, false);
  44915. for (int i = 0; i < subItems.size(); ++i)
  44916. subItems.getUnchecked(i)->deselectAllRecursively();
  44917. }
  44918. void TreeViewItem::setSelected (const bool shouldBeSelected,
  44919. const bool deselectOtherItemsFirst)
  44920. {
  44921. if (shouldBeSelected && ! canBeSelected())
  44922. return;
  44923. if (deselectOtherItemsFirst)
  44924. getTopLevelItem()->deselectAllRecursively();
  44925. if (shouldBeSelected != selected)
  44926. {
  44927. selected = shouldBeSelected;
  44928. if (ownerView != 0)
  44929. ownerView->repaint();
  44930. itemSelectionChanged (shouldBeSelected);
  44931. }
  44932. }
  44933. void TreeViewItem::paintItem (Graphics&, int, int)
  44934. {
  44935. }
  44936. void TreeViewItem::paintOpenCloseButton (Graphics& g, int width, int height, bool isMouseOver)
  44937. {
  44938. ownerView->getLookAndFeel()
  44939. .drawTreeviewPlusMinusBox (g, 0, 0, width, height, ! isOpen(), isMouseOver);
  44940. }
  44941. void TreeViewItem::itemClicked (const MouseEvent&)
  44942. {
  44943. }
  44944. void TreeViewItem::itemDoubleClicked (const MouseEvent&)
  44945. {
  44946. if (mightContainSubItems())
  44947. setOpen (! isOpen());
  44948. }
  44949. void TreeViewItem::itemSelectionChanged (bool)
  44950. {
  44951. }
  44952. const String TreeViewItem::getTooltip()
  44953. {
  44954. return String::empty;
  44955. }
  44956. const String TreeViewItem::getDragSourceDescription()
  44957. {
  44958. return String::empty;
  44959. }
  44960. bool TreeViewItem::isInterestedInFileDrag (const StringArray&)
  44961. {
  44962. return false;
  44963. }
  44964. void TreeViewItem::filesDropped (const StringArray& /*files*/, int /*insertIndex*/)
  44965. {
  44966. }
  44967. bool TreeViewItem::isInterestedInDragSource (const String& /*sourceDescription*/, Component* /*sourceComponent*/)
  44968. {
  44969. return false;
  44970. }
  44971. void TreeViewItem::itemDropped (const String& /*sourceDescription*/, Component* /*sourceComponent*/, int /*insertIndex*/)
  44972. {
  44973. }
  44974. const Rectangle<int> TreeViewItem::getItemPosition (const bool relativeToTreeViewTopLeft) const throw()
  44975. {
  44976. const int indentX = getIndentX();
  44977. int width = itemWidth;
  44978. if (ownerView != 0 && width < 0)
  44979. width = ownerView->viewport->getViewWidth() - indentX;
  44980. Rectangle<int> r (indentX, y, jmax (0, width), totalHeight);
  44981. if (relativeToTreeViewTopLeft)
  44982. r.setPosition (r.getX() - ownerView->viewport->getViewPositionX(),
  44983. r.getY() - ownerView->viewport->getViewPositionY());
  44984. return r;
  44985. }
  44986. void TreeViewItem::treeHasChanged() const throw()
  44987. {
  44988. if (ownerView != 0)
  44989. ownerView->itemsChanged();
  44990. }
  44991. void TreeViewItem::repaintItem() const
  44992. {
  44993. if (ownerView != 0 && areAllParentsOpen())
  44994. {
  44995. const Rectangle<int> r (getItemPosition (true));
  44996. ownerView->viewport->repaint (0, r.getY(), r.getRight(), r.getHeight());
  44997. }
  44998. }
  44999. bool TreeViewItem::areAllParentsOpen() const throw()
  45000. {
  45001. return parentItem == 0
  45002. || (parentItem->isOpen() && parentItem->areAllParentsOpen());
  45003. }
  45004. void TreeViewItem::updatePositions (int newY)
  45005. {
  45006. y = newY;
  45007. itemHeight = getItemHeight();
  45008. totalHeight = itemHeight;
  45009. itemWidth = getItemWidth();
  45010. totalWidth = jmax (itemWidth, 0) + getIndentX();
  45011. if (isOpen())
  45012. {
  45013. newY += totalHeight;
  45014. for (int i = 0; i < subItems.size(); ++i)
  45015. {
  45016. TreeViewItem* const ti = subItems.getUnchecked(i);
  45017. ti->updatePositions (newY);
  45018. newY += ti->totalHeight;
  45019. totalHeight += ti->totalHeight;
  45020. totalWidth = jmax (totalWidth, ti->totalWidth);
  45021. }
  45022. }
  45023. }
  45024. TreeViewItem* TreeViewItem::getDeepestOpenParentItem() throw()
  45025. {
  45026. TreeViewItem* result = this;
  45027. TreeViewItem* item = this;
  45028. while (item->parentItem != 0)
  45029. {
  45030. item = item->parentItem;
  45031. if (! item->isOpen())
  45032. result = item;
  45033. }
  45034. return result;
  45035. }
  45036. void TreeViewItem::setOwnerView (TreeView* const newOwner) throw()
  45037. {
  45038. ownerView = newOwner;
  45039. for (int i = subItems.size(); --i >= 0;)
  45040. subItems.getUnchecked(i)->setOwnerView (newOwner);
  45041. }
  45042. int TreeViewItem::getIndentX() const throw()
  45043. {
  45044. const int indentWidth = ownerView->getIndentSize();
  45045. int x = ownerView->rootItemVisible ? indentWidth : 0;
  45046. if (! ownerView->openCloseButtonsVisible)
  45047. x -= indentWidth;
  45048. TreeViewItem* p = parentItem;
  45049. while (p != 0)
  45050. {
  45051. x += indentWidth;
  45052. p = p->parentItem;
  45053. }
  45054. return x;
  45055. }
  45056. void TreeViewItem::setDrawsInLeftMargin (bool canDrawInLeftMargin) throw()
  45057. {
  45058. drawsInLeftMargin = canDrawInLeftMargin;
  45059. }
  45060. void TreeViewItem::paintRecursively (Graphics& g, int width)
  45061. {
  45062. jassert (ownerView != 0);
  45063. if (ownerView == 0)
  45064. return;
  45065. const int indent = getIndentX();
  45066. const int itemW = itemWidth < 0 ? width - indent : itemWidth;
  45067. g.setColour (ownerView->findColour (TreeView::linesColourId));
  45068. const float halfH = itemHeight * 0.5f;
  45069. int depth = 0;
  45070. TreeViewItem* p = parentItem;
  45071. while (p != 0)
  45072. {
  45073. ++depth;
  45074. p = p->parentItem;
  45075. }
  45076. if (! ownerView->rootItemVisible)
  45077. --depth;
  45078. const int indentWidth = ownerView->getIndentSize();
  45079. if (depth >= 0 && ownerView->openCloseButtonsVisible)
  45080. {
  45081. float x = (depth + 0.5f) * indentWidth;
  45082. if (depth >= 0)
  45083. {
  45084. if (parentItem != 0 && parentItem->drawLinesInside)
  45085. g.drawLine (x, 0, x, isLastOfSiblings() ? halfH : (float) itemHeight);
  45086. if ((parentItem != 0 && parentItem->drawLinesInside)
  45087. || (parentItem == 0 && drawLinesInside))
  45088. g.drawLine (x, halfH, x + indentWidth / 2, halfH);
  45089. }
  45090. p = parentItem;
  45091. int d = depth;
  45092. while (p != 0 && --d >= 0)
  45093. {
  45094. x -= (float) indentWidth;
  45095. if ((p->parentItem == 0 || p->parentItem->drawLinesInside)
  45096. && ! p->isLastOfSiblings())
  45097. {
  45098. g.drawLine (x, 0, x, (float) itemHeight);
  45099. }
  45100. p = p->parentItem;
  45101. }
  45102. if (mightContainSubItems())
  45103. {
  45104. g.saveState();
  45105. g.setOrigin (depth * indentWidth, 0);
  45106. g.reduceClipRegion (0, 0, indentWidth, itemHeight);
  45107. paintOpenCloseButton (g, indentWidth, itemHeight,
  45108. ((TreeViewContentComponent*) ownerView->viewport->getViewedComponent())
  45109. ->isMouseOverButton (this));
  45110. g.restoreState();
  45111. }
  45112. }
  45113. {
  45114. g.saveState();
  45115. g.setOrigin (indent, 0);
  45116. if (g.reduceClipRegion (drawsInLeftMargin ? -indent : 0, 0,
  45117. drawsInLeftMargin ? itemW + indent : itemW, itemHeight))
  45118. paintItem (g, itemW, itemHeight);
  45119. g.restoreState();
  45120. }
  45121. if (isOpen())
  45122. {
  45123. const Rectangle<int> clip (g.getClipBounds());
  45124. for (int i = 0; i < subItems.size(); ++i)
  45125. {
  45126. TreeViewItem* const ti = subItems.getUnchecked(i);
  45127. const int relY = ti->y - y;
  45128. if (relY >= clip.getBottom())
  45129. break;
  45130. if (relY + ti->totalHeight >= clip.getY())
  45131. {
  45132. g.saveState();
  45133. g.setOrigin (0, relY);
  45134. if (g.reduceClipRegion (0, 0, width, ti->totalHeight))
  45135. ti->paintRecursively (g, width);
  45136. g.restoreState();
  45137. }
  45138. }
  45139. }
  45140. }
  45141. bool TreeViewItem::isLastOfSiblings() const throw()
  45142. {
  45143. return parentItem == 0
  45144. || parentItem->subItems.getLast() == this;
  45145. }
  45146. int TreeViewItem::getIndexInParent() const throw()
  45147. {
  45148. if (parentItem == 0)
  45149. return 0;
  45150. return parentItem->subItems.indexOf (this);
  45151. }
  45152. TreeViewItem* TreeViewItem::getTopLevelItem() throw()
  45153. {
  45154. return (parentItem == 0) ? this
  45155. : parentItem->getTopLevelItem();
  45156. }
  45157. int TreeViewItem::getNumRows() const throw()
  45158. {
  45159. int num = 1;
  45160. if (isOpen())
  45161. {
  45162. for (int i = subItems.size(); --i >= 0;)
  45163. num += subItems.getUnchecked(i)->getNumRows();
  45164. }
  45165. return num;
  45166. }
  45167. TreeViewItem* TreeViewItem::getItemOnRow (int index) throw()
  45168. {
  45169. if (index == 0)
  45170. return this;
  45171. if (index > 0 && isOpen())
  45172. {
  45173. --index;
  45174. for (int i = 0; i < subItems.size(); ++i)
  45175. {
  45176. TreeViewItem* const item = subItems.getUnchecked(i);
  45177. if (index == 0)
  45178. return item;
  45179. const int numRows = item->getNumRows();
  45180. if (numRows > index)
  45181. return item->getItemOnRow (index);
  45182. index -= numRows;
  45183. }
  45184. }
  45185. return 0;
  45186. }
  45187. TreeViewItem* TreeViewItem::findItemRecursively (int targetY) throw()
  45188. {
  45189. if (((unsigned int) targetY) < (unsigned int) totalHeight)
  45190. {
  45191. const int h = itemHeight;
  45192. if (targetY < h)
  45193. return this;
  45194. if (isOpen())
  45195. {
  45196. targetY -= h;
  45197. for (int i = 0; i < subItems.size(); ++i)
  45198. {
  45199. TreeViewItem* const ti = subItems.getUnchecked(i);
  45200. if (targetY < ti->totalHeight)
  45201. return ti->findItemRecursively (targetY);
  45202. targetY -= ti->totalHeight;
  45203. }
  45204. }
  45205. }
  45206. return 0;
  45207. }
  45208. int TreeViewItem::countSelectedItemsRecursively() const throw()
  45209. {
  45210. int total = 0;
  45211. if (isSelected())
  45212. ++total;
  45213. for (int i = subItems.size(); --i >= 0;)
  45214. total += subItems.getUnchecked(i)->countSelectedItemsRecursively();
  45215. return total;
  45216. }
  45217. TreeViewItem* TreeViewItem::getSelectedItemWithIndex (int index) throw()
  45218. {
  45219. if (isSelected())
  45220. {
  45221. if (index == 0)
  45222. return this;
  45223. --index;
  45224. }
  45225. if (index >= 0)
  45226. {
  45227. for (int i = 0; i < subItems.size(); ++i)
  45228. {
  45229. TreeViewItem* const item = subItems.getUnchecked(i);
  45230. TreeViewItem* const found = item->getSelectedItemWithIndex (index);
  45231. if (found != 0)
  45232. return found;
  45233. index -= item->countSelectedItemsRecursively();
  45234. }
  45235. }
  45236. return 0;
  45237. }
  45238. int TreeViewItem::getRowNumberInTree() const throw()
  45239. {
  45240. if (parentItem != 0 && ownerView != 0)
  45241. {
  45242. int n = 1 + parentItem->getRowNumberInTree();
  45243. int ourIndex = parentItem->subItems.indexOf (this);
  45244. jassert (ourIndex >= 0);
  45245. while (--ourIndex >= 0)
  45246. n += parentItem->subItems [ourIndex]->getNumRows();
  45247. if (parentItem->parentItem == 0
  45248. && ! ownerView->rootItemVisible)
  45249. --n;
  45250. return n;
  45251. }
  45252. else
  45253. {
  45254. return 0;
  45255. }
  45256. }
  45257. void TreeViewItem::setLinesDrawnForSubItems (const bool drawLines) throw()
  45258. {
  45259. drawLinesInside = drawLines;
  45260. }
  45261. TreeViewItem* TreeViewItem::getNextVisibleItem (const bool recurse) const throw()
  45262. {
  45263. if (recurse && isOpen() && subItems.size() > 0)
  45264. return subItems [0];
  45265. if (parentItem != 0)
  45266. {
  45267. const int nextIndex = parentItem->subItems.indexOf (this) + 1;
  45268. if (nextIndex >= parentItem->subItems.size())
  45269. return parentItem->getNextVisibleItem (false);
  45270. return parentItem->subItems [nextIndex];
  45271. }
  45272. return 0;
  45273. }
  45274. const String TreeViewItem::getItemIdentifierString() const
  45275. {
  45276. String s;
  45277. if (parentItem != 0)
  45278. s = parentItem->getItemIdentifierString();
  45279. return s + T("/") + getUniqueName().replaceCharacter (T('/'), T('\\'));
  45280. }
  45281. TreeViewItem* TreeViewItem::findItemFromIdentifierString (const String& identifierString)
  45282. {
  45283. const String uid (getUniqueName());
  45284. if (uid == identifierString)
  45285. return this;
  45286. if (identifierString.startsWith (uid + T("/")))
  45287. {
  45288. const String remainingPath (identifierString.substring (uid.length() + 1));
  45289. bool wasOpen = isOpen();
  45290. setOpen (true);
  45291. for (int i = subItems.size(); --i >= 0;)
  45292. {
  45293. TreeViewItem* item = subItems.getUnchecked(i)->findItemFromIdentifierString (remainingPath);
  45294. if (item != 0)
  45295. return item;
  45296. }
  45297. setOpen (wasOpen);
  45298. }
  45299. return 0;
  45300. }
  45301. void TreeViewItem::restoreOpennessState (const XmlElement& e) throw()
  45302. {
  45303. if (e.hasTagName (T("CLOSED")))
  45304. {
  45305. setOpen (false);
  45306. }
  45307. else if (e.hasTagName (T("OPEN")))
  45308. {
  45309. setOpen (true);
  45310. forEachXmlChildElement (e, n)
  45311. {
  45312. const String id (n->getStringAttribute (T("id")));
  45313. for (int i = 0; i < subItems.size(); ++i)
  45314. {
  45315. TreeViewItem* const ti = subItems.getUnchecked(i);
  45316. if (ti->getUniqueName() == id)
  45317. {
  45318. ti->restoreOpennessState (*n);
  45319. break;
  45320. }
  45321. }
  45322. }
  45323. }
  45324. }
  45325. XmlElement* TreeViewItem::getOpennessState() const throw()
  45326. {
  45327. const String name (getUniqueName());
  45328. if (name.isNotEmpty())
  45329. {
  45330. XmlElement* e;
  45331. if (isOpen())
  45332. {
  45333. e = new XmlElement (T("OPEN"));
  45334. for (int i = 0; i < subItems.size(); ++i)
  45335. e->addChildElement (subItems.getUnchecked(i)->getOpennessState());
  45336. }
  45337. else
  45338. {
  45339. e = new XmlElement (T("CLOSED"));
  45340. }
  45341. e->setAttribute (T("id"), name);
  45342. return e;
  45343. }
  45344. else
  45345. {
  45346. // trying to save the openness for an element that has no name - this won't
  45347. // work because it needs the names to identify what to open.
  45348. jassertfalse
  45349. }
  45350. return 0;
  45351. }
  45352. END_JUCE_NAMESPACE
  45353. /*** End of inlined file: juce_TreeView.cpp ***/
  45354. /*** Start of inlined file: juce_DirectoryContentsDisplayComponent.cpp ***/
  45355. BEGIN_JUCE_NAMESPACE
  45356. DirectoryContentsDisplayComponent::DirectoryContentsDisplayComponent (DirectoryContentsList& listToShow)
  45357. : fileList (listToShow)
  45358. {
  45359. }
  45360. DirectoryContentsDisplayComponent::~DirectoryContentsDisplayComponent()
  45361. {
  45362. }
  45363. FileBrowserListener::~FileBrowserListener()
  45364. {
  45365. }
  45366. void DirectoryContentsDisplayComponent::addListener (FileBrowserListener* const listener) throw()
  45367. {
  45368. listeners.add (listener);
  45369. }
  45370. void DirectoryContentsDisplayComponent::removeListener (FileBrowserListener* const listener) throw()
  45371. {
  45372. listeners.remove (listener);
  45373. }
  45374. void DirectoryContentsDisplayComponent::sendSelectionChangeMessage()
  45375. {
  45376. Component::BailOutChecker checker (dynamic_cast <Component*> (this));
  45377. listeners.callChecked (checker, &FileBrowserListener::selectionChanged);
  45378. }
  45379. void DirectoryContentsDisplayComponent::sendMouseClickMessage (const File& file, const MouseEvent& e)
  45380. {
  45381. if (fileList.getDirectory().exists())
  45382. {
  45383. Component::BailOutChecker checker (dynamic_cast <Component*> (this));
  45384. listeners.callChecked (checker, &FileBrowserListener::fileClicked, file, e);
  45385. }
  45386. }
  45387. void DirectoryContentsDisplayComponent::sendDoubleClickMessage (const File& file)
  45388. {
  45389. if (fileList.getDirectory().exists())
  45390. {
  45391. Component::BailOutChecker checker (dynamic_cast <Component*> (this));
  45392. listeners.callChecked (checker, &FileBrowserListener::fileDoubleClicked, file);
  45393. }
  45394. }
  45395. END_JUCE_NAMESPACE
  45396. /*** End of inlined file: juce_DirectoryContentsDisplayComponent.cpp ***/
  45397. /*** Start of inlined file: juce_DirectoryContentsList.cpp ***/
  45398. BEGIN_JUCE_NAMESPACE
  45399. void* juce_findFileStart (const String& directory, const String& wildCard, String& firstResultFile,
  45400. bool* isDirectory, bool* isHidden, int64* fileSize, Time* modTime,
  45401. Time* creationTime, bool* isReadOnly);
  45402. bool juce_findFileNext (void* handle, String& resultFile,
  45403. bool* isDirectory, bool* isHidden, int64* fileSize,
  45404. Time* modTime, Time* creationTime, bool* isReadOnly);
  45405. void juce_findFileClose (void* handle);
  45406. DirectoryContentsList::DirectoryContentsList (const FileFilter* const fileFilter_,
  45407. TimeSliceThread& thread_)
  45408. : fileFilter (fileFilter_),
  45409. thread (thread_),
  45410. includeDirectories (false),
  45411. includeFiles (false),
  45412. ignoreHiddenFiles (true),
  45413. fileFindHandle (0),
  45414. shouldStop (true)
  45415. {
  45416. }
  45417. DirectoryContentsList::~DirectoryContentsList()
  45418. {
  45419. clear();
  45420. }
  45421. void DirectoryContentsList::setIgnoresHiddenFiles (const bool shouldIgnoreHiddenFiles)
  45422. {
  45423. ignoreHiddenFiles = shouldIgnoreHiddenFiles;
  45424. }
  45425. const File& DirectoryContentsList::getDirectory() const
  45426. {
  45427. return root;
  45428. }
  45429. void DirectoryContentsList::setDirectory (const File& directory,
  45430. const bool includeDirectories_,
  45431. const bool includeFiles_)
  45432. {
  45433. if (directory != root
  45434. || includeDirectories != includeDirectories_
  45435. || includeFiles != includeFiles_)
  45436. {
  45437. clear();
  45438. root = directory;
  45439. includeDirectories = includeDirectories_;
  45440. includeFiles = includeFiles_;
  45441. refresh();
  45442. }
  45443. }
  45444. void DirectoryContentsList::clear()
  45445. {
  45446. shouldStop = true;
  45447. thread.removeTimeSliceClient (this);
  45448. if (fileFindHandle != 0)
  45449. {
  45450. juce_findFileClose (fileFindHandle);
  45451. fileFindHandle = 0;
  45452. }
  45453. if (files.size() > 0)
  45454. {
  45455. files.clear();
  45456. changed();
  45457. }
  45458. }
  45459. void DirectoryContentsList::refresh()
  45460. {
  45461. clear();
  45462. if (root.isDirectory())
  45463. {
  45464. String fileFound;
  45465. bool fileFoundIsDir, isHidden, isReadOnly;
  45466. int64 fileSize;
  45467. Time modTime, creationTime;
  45468. String path (root.getFullPathName());
  45469. if (! path.endsWithChar (File::separator))
  45470. path += File::separator;
  45471. jassert (fileFindHandle == 0);
  45472. fileFindHandle = juce_findFileStart (path, T("*"), fileFound,
  45473. &fileFoundIsDir,
  45474. &isHidden,
  45475. &fileSize,
  45476. &modTime,
  45477. &creationTime,
  45478. &isReadOnly);
  45479. if (fileFindHandle != 0 && fileFound.isNotEmpty())
  45480. {
  45481. if (addFile (fileFound, fileFoundIsDir, isHidden,
  45482. fileSize, modTime, creationTime, isReadOnly))
  45483. {
  45484. changed();
  45485. }
  45486. }
  45487. shouldStop = false;
  45488. thread.addTimeSliceClient (this);
  45489. }
  45490. }
  45491. int DirectoryContentsList::getNumFiles() const
  45492. {
  45493. return files.size();
  45494. }
  45495. bool DirectoryContentsList::getFileInfo (const int index,
  45496. FileInfo& result) const
  45497. {
  45498. const ScopedLock sl (fileListLock);
  45499. const FileInfo* const info = files [index];
  45500. if (info != 0)
  45501. {
  45502. result = *info;
  45503. return true;
  45504. }
  45505. return false;
  45506. }
  45507. const File DirectoryContentsList::getFile (const int index) const
  45508. {
  45509. const ScopedLock sl (fileListLock);
  45510. const FileInfo* const info = files [index];
  45511. if (info != 0)
  45512. return root.getChildFile (info->filename);
  45513. return File::nonexistent;
  45514. }
  45515. bool DirectoryContentsList::isStillLoading() const
  45516. {
  45517. return fileFindHandle != 0;
  45518. }
  45519. void DirectoryContentsList::changed()
  45520. {
  45521. sendChangeMessage (this);
  45522. }
  45523. bool DirectoryContentsList::useTimeSlice()
  45524. {
  45525. const uint32 startTime = Time::getApproximateMillisecondCounter();
  45526. bool hasChanged = false;
  45527. for (int i = 100; --i >= 0;)
  45528. {
  45529. if (! checkNextFile (hasChanged))
  45530. {
  45531. if (hasChanged)
  45532. changed();
  45533. return false;
  45534. }
  45535. if (shouldStop || (Time::getApproximateMillisecondCounter() > startTime + 150))
  45536. break;
  45537. }
  45538. if (hasChanged)
  45539. changed();
  45540. return true;
  45541. }
  45542. bool DirectoryContentsList::checkNextFile (bool& hasChanged)
  45543. {
  45544. if (fileFindHandle != 0)
  45545. {
  45546. String fileFound;
  45547. bool fileFoundIsDir, isHidden, isReadOnly;
  45548. int64 fileSize;
  45549. Time modTime, creationTime;
  45550. if (juce_findFileNext (fileFindHandle, fileFound,
  45551. &fileFoundIsDir, &isHidden,
  45552. &fileSize,
  45553. &modTime,
  45554. &creationTime,
  45555. &isReadOnly))
  45556. {
  45557. if (addFile (fileFound, fileFoundIsDir, isHidden, fileSize,
  45558. modTime, creationTime, isReadOnly))
  45559. {
  45560. hasChanged = true;
  45561. }
  45562. return true;
  45563. }
  45564. else
  45565. {
  45566. juce_findFileClose (fileFindHandle);
  45567. fileFindHandle = 0;
  45568. }
  45569. }
  45570. return false;
  45571. }
  45572. int DirectoryContentsList::compareElements (const DirectoryContentsList::FileInfo* const first,
  45573. const DirectoryContentsList::FileInfo* const second)
  45574. {
  45575. #if JUCE_WINDOWS
  45576. if (first->isDirectory != second->isDirectory)
  45577. return first->isDirectory ? -1 : 1;
  45578. #endif
  45579. return first->filename.compareIgnoreCase (second->filename);
  45580. }
  45581. bool DirectoryContentsList::addFile (const String& filename,
  45582. const bool isDir,
  45583. const bool isHidden,
  45584. const int64 fileSize,
  45585. const Time& modTime,
  45586. const Time& creationTime,
  45587. const bool isReadOnly)
  45588. {
  45589. if (filename == T("..")
  45590. || filename == T(".")
  45591. || (ignoreHiddenFiles && isHidden))
  45592. return false;
  45593. const File file (root.getChildFile (filename));
  45594. if (((isDir && includeDirectories) || ((! isDir) && includeFiles))
  45595. && (fileFilter == 0
  45596. || ((! isDir) && fileFilter->isFileSuitable (file))
  45597. || (isDir && fileFilter->isDirectorySuitable (file))))
  45598. {
  45599. ScopedPointer <FileInfo> info (new FileInfo());
  45600. info->filename = filename;
  45601. info->fileSize = fileSize;
  45602. info->modificationTime = modTime;
  45603. info->creationTime = creationTime;
  45604. info->isDirectory = isDir;
  45605. info->isReadOnly = isReadOnly;
  45606. const ScopedLock sl (fileListLock);
  45607. for (int i = files.size(); --i >= 0;)
  45608. if (files.getUnchecked(i)->filename == info->filename)
  45609. return false;
  45610. files.addSorted (*this, info.release());
  45611. return true;
  45612. }
  45613. return false;
  45614. }
  45615. END_JUCE_NAMESPACE
  45616. /*** End of inlined file: juce_DirectoryContentsList.cpp ***/
  45617. /*** Start of inlined file: juce_FileBrowserComponent.cpp ***/
  45618. BEGIN_JUCE_NAMESPACE
  45619. FileBrowserComponent::FileBrowserComponent (int flags_,
  45620. const File& initialFileOrDirectory,
  45621. const FileFilter* fileFilter_,
  45622. FilePreviewComponent* previewComp_)
  45623. : FileFilter (String::empty),
  45624. fileFilter (fileFilter_),
  45625. flags (flags_),
  45626. previewComp (previewComp_),
  45627. thread ("Juce FileBrowser")
  45628. {
  45629. // You need to specify one or other of the open/save flags..
  45630. jassert ((flags & (saveMode | openMode)) != 0);
  45631. jassert ((flags & (saveMode | openMode)) != (saveMode | openMode));
  45632. // You need to specify at least one of these flags..
  45633. jassert ((flags & (canSelectFiles | canSelectDirectories)) != 0);
  45634. String filename;
  45635. if (initialFileOrDirectory == File::nonexistent)
  45636. {
  45637. currentRoot = File::getCurrentWorkingDirectory();
  45638. }
  45639. else if (initialFileOrDirectory.isDirectory())
  45640. {
  45641. currentRoot = initialFileOrDirectory;
  45642. }
  45643. else
  45644. {
  45645. chosenFiles.add (initialFileOrDirectory);
  45646. currentRoot = initialFileOrDirectory.getParentDirectory();
  45647. filename = initialFileOrDirectory.getFileName();
  45648. }
  45649. fileList = new DirectoryContentsList (this, thread);
  45650. if ((flags & useTreeView) != 0)
  45651. {
  45652. FileTreeComponent* const tree = new FileTreeComponent (*fileList);
  45653. if ((flags & canSelectMultipleItems) != 0)
  45654. tree->setMultiSelectEnabled (true);
  45655. addAndMakeVisible (tree);
  45656. fileListComponent = tree;
  45657. }
  45658. else
  45659. {
  45660. FileListComponent* const list = new FileListComponent (*fileList);
  45661. list->setOutlineThickness (1);
  45662. if ((flags & canSelectMultipleItems) != 0)
  45663. list->setMultipleSelectionEnabled (true);
  45664. addAndMakeVisible (list);
  45665. fileListComponent = list;
  45666. }
  45667. fileListComponent->addListener (this);
  45668. addAndMakeVisible (currentPathBox = new ComboBox ("path"));
  45669. currentPathBox->setEditableText (true);
  45670. StringArray rootNames, rootPaths;
  45671. const BigInteger separators (getRoots (rootNames, rootPaths));
  45672. for (int i = 0; i < rootNames.size(); ++i)
  45673. {
  45674. if (separators [i])
  45675. currentPathBox->addSeparator();
  45676. currentPathBox->addItem (rootNames[i], i + 1);
  45677. }
  45678. currentPathBox->addSeparator();
  45679. currentPathBox->addListener (this);
  45680. addAndMakeVisible (filenameBox = new TextEditor());
  45681. filenameBox->setMultiLine (false);
  45682. filenameBox->setSelectAllWhenFocused (true);
  45683. filenameBox->setText (filename, false);
  45684. filenameBox->addListener (this);
  45685. filenameBox->setReadOnly ((flags & (filenameBoxIsReadOnly | canSelectMultipleItems)) != 0);
  45686. Label* label = new Label ("f", TRANS("file:"));
  45687. addAndMakeVisible (label);
  45688. label->attachToComponent (filenameBox, true);
  45689. addAndMakeVisible (goUpButton = getLookAndFeel().createFileBrowserGoUpButton());
  45690. goUpButton->addButtonListener (this);
  45691. goUpButton->setTooltip (TRANS ("go up to parent directory"));
  45692. if (previewComp != 0)
  45693. addAndMakeVisible (previewComp);
  45694. setRoot (currentRoot);
  45695. thread.startThread (4);
  45696. }
  45697. FileBrowserComponent::~FileBrowserComponent()
  45698. {
  45699. if (previewComp != 0)
  45700. removeChildComponent (previewComp);
  45701. deleteAllChildren();
  45702. fileList = 0;
  45703. thread.stopThread (10000);
  45704. }
  45705. void FileBrowserComponent::addListener (FileBrowserListener* const newListener) throw()
  45706. {
  45707. listeners.add (newListener);
  45708. }
  45709. void FileBrowserComponent::removeListener (FileBrowserListener* const listener) throw()
  45710. {
  45711. listeners.remove (listener);
  45712. }
  45713. bool FileBrowserComponent::isSaveMode() const throw()
  45714. {
  45715. return (flags & saveMode) != 0;
  45716. }
  45717. int FileBrowserComponent::getNumSelectedFiles() const throw()
  45718. {
  45719. if (chosenFiles.size() == 0 && currentFileIsValid())
  45720. return 1;
  45721. return chosenFiles.size();
  45722. }
  45723. const File FileBrowserComponent::getSelectedFile (int index) const throw()
  45724. {
  45725. if (! filenameBox->isReadOnly())
  45726. return currentRoot.getChildFile (filenameBox->getText());
  45727. else
  45728. return chosenFiles[index];
  45729. }
  45730. bool FileBrowserComponent::currentFileIsValid() const
  45731. {
  45732. if (isSaveMode())
  45733. return ! getSelectedFile (0).isDirectory();
  45734. else
  45735. return getSelectedFile (0).exists();
  45736. }
  45737. const File FileBrowserComponent::getHighlightedFile() const throw()
  45738. {
  45739. return fileListComponent->getSelectedFile (0);
  45740. }
  45741. bool FileBrowserComponent::isFileSuitable (const File& file) const
  45742. {
  45743. return (flags & canSelectFiles) != 0 ? (fileFilter == 0 || fileFilter->isFileSuitable (file))
  45744. : false;
  45745. }
  45746. bool FileBrowserComponent::isDirectorySuitable (const File&) const
  45747. {
  45748. return true;
  45749. }
  45750. bool FileBrowserComponent::isFileOrDirSuitable (const File& f) const
  45751. {
  45752. if (f.isDirectory())
  45753. return (flags & canSelectDirectories) != 0 && (fileFilter == 0 || fileFilter->isDirectorySuitable (f));
  45754. return (flags & canSelectFiles) != 0 && f.exists()
  45755. && (fileFilter == 0 || fileFilter->isFileSuitable (f));
  45756. }
  45757. const File FileBrowserComponent::getRoot() const
  45758. {
  45759. return currentRoot;
  45760. }
  45761. void FileBrowserComponent::setRoot (const File& newRootDirectory)
  45762. {
  45763. if (currentRoot != newRootDirectory)
  45764. {
  45765. fileListComponent->scrollToTop();
  45766. String path (newRootDirectory.getFullPathName());
  45767. if (path.isEmpty())
  45768. path += File::separator;
  45769. StringArray rootNames, rootPaths;
  45770. getRoots (rootNames, rootPaths);
  45771. if (! rootPaths.contains (path, true))
  45772. {
  45773. bool alreadyListed = false;
  45774. for (int i = currentPathBox->getNumItems(); --i >= 0;)
  45775. {
  45776. if (currentPathBox->getItemText (i).equalsIgnoreCase (path))
  45777. {
  45778. alreadyListed = true;
  45779. break;
  45780. }
  45781. }
  45782. if (! alreadyListed)
  45783. currentPathBox->addItem (path, currentPathBox->getNumItems() + 2);
  45784. }
  45785. }
  45786. currentRoot = newRootDirectory;
  45787. fileList->setDirectory (currentRoot, true, true);
  45788. String currentRootName (currentRoot.getFullPathName());
  45789. if (currentRootName.isEmpty())
  45790. currentRootName += File::separator;
  45791. currentPathBox->setText (currentRootName, true);
  45792. goUpButton->setEnabled (currentRoot.getParentDirectory().isDirectory()
  45793. && currentRoot.getParentDirectory() != currentRoot);
  45794. }
  45795. void FileBrowserComponent::goUp()
  45796. {
  45797. setRoot (getRoot().getParentDirectory());
  45798. }
  45799. void FileBrowserComponent::refresh()
  45800. {
  45801. fileList->refresh();
  45802. }
  45803. const String FileBrowserComponent::getActionVerb() const
  45804. {
  45805. return isSaveMode() ? TRANS("Save") : TRANS("Open");
  45806. }
  45807. FilePreviewComponent* FileBrowserComponent::getPreviewComponent() const throw()
  45808. {
  45809. return previewComp;
  45810. }
  45811. void FileBrowserComponent::resized()
  45812. {
  45813. getLookAndFeel()
  45814. .layoutFileBrowserComponent (*this, fileListComponent,
  45815. previewComp, currentPathBox,
  45816. filenameBox, goUpButton);
  45817. }
  45818. void FileBrowserComponent::sendListenerChangeMessage()
  45819. {
  45820. Component::BailOutChecker checker (this);
  45821. if (previewComp != 0)
  45822. previewComp->selectedFileChanged (getSelectedFile (0));
  45823. // You shouldn't delete the browser when the file gets changed!
  45824. jassert (! checker.shouldBailOut());
  45825. listeners.callChecked (checker, &FileBrowserListener::selectionChanged);
  45826. }
  45827. void FileBrowserComponent::selectionChanged()
  45828. {
  45829. StringArray newFilenames;
  45830. bool resetChosenFiles = true;
  45831. for (int i = 0; i < fileListComponent->getNumSelectedFiles(); ++i)
  45832. {
  45833. const File f (fileListComponent->getSelectedFile (i));
  45834. if (isFileOrDirSuitable (f))
  45835. {
  45836. if (resetChosenFiles)
  45837. {
  45838. chosenFiles.clear();
  45839. resetChosenFiles = false;
  45840. }
  45841. chosenFiles.add (f);
  45842. newFilenames.add (f.getRelativePathFrom (getRoot()));
  45843. }
  45844. }
  45845. if (newFilenames.size() > 0)
  45846. filenameBox->setText (newFilenames.joinIntoString (T(", ")), false);
  45847. sendListenerChangeMessage();
  45848. }
  45849. void FileBrowserComponent::fileClicked (const File& f, const MouseEvent& e)
  45850. {
  45851. Component::BailOutChecker checker (this);
  45852. listeners.callChecked (checker, &FileBrowserListener::fileClicked, f, e);
  45853. }
  45854. void FileBrowserComponent::fileDoubleClicked (const File& f)
  45855. {
  45856. if (f.isDirectory())
  45857. {
  45858. setRoot (f);
  45859. }
  45860. else
  45861. {
  45862. Component::BailOutChecker checker (this);
  45863. listeners.callChecked (checker, &FileBrowserListener::fileDoubleClicked, f);
  45864. }
  45865. }
  45866. bool FileBrowserComponent::keyPressed (const KeyPress& key)
  45867. {
  45868. #if JUCE_LINUX || JUCE_WINDOWS
  45869. if (key.getModifiers().isCommandDown()
  45870. && (key.getKeyCode() == 'H' || key.getKeyCode() == 'h'))
  45871. {
  45872. fileList->setIgnoresHiddenFiles (! fileList->ignoresHiddenFiles());
  45873. fileList->refresh();
  45874. return true;
  45875. }
  45876. #endif
  45877. return false;
  45878. }
  45879. void FileBrowserComponent::textEditorTextChanged (TextEditor&)
  45880. {
  45881. sendListenerChangeMessage();
  45882. }
  45883. void FileBrowserComponent::textEditorReturnKeyPressed (TextEditor&)
  45884. {
  45885. if (filenameBox->getText().containsChar (File::separator))
  45886. {
  45887. const File f (currentRoot.getChildFile (filenameBox->getText()));
  45888. if (f.isDirectory())
  45889. {
  45890. setRoot (f);
  45891. chosenFiles.clear();
  45892. filenameBox->setText (String::empty);
  45893. }
  45894. else
  45895. {
  45896. setRoot (f.getParentDirectory());
  45897. chosenFiles.clear();
  45898. chosenFiles.add (f);
  45899. filenameBox->setText (f.getFileName());
  45900. }
  45901. }
  45902. else
  45903. {
  45904. fileDoubleClicked (getSelectedFile (0));
  45905. }
  45906. }
  45907. void FileBrowserComponent::textEditorEscapeKeyPressed (TextEditor&)
  45908. {
  45909. }
  45910. void FileBrowserComponent::textEditorFocusLost (TextEditor&)
  45911. {
  45912. if (! isSaveMode())
  45913. selectionChanged();
  45914. }
  45915. void FileBrowserComponent::buttonClicked (Button*)
  45916. {
  45917. goUp();
  45918. }
  45919. void FileBrowserComponent::comboBoxChanged (ComboBox*)
  45920. {
  45921. const String newText (currentPathBox->getText().trim().unquoted());
  45922. if (newText.isNotEmpty())
  45923. {
  45924. const int index = currentPathBox->getSelectedId() - 1;
  45925. StringArray rootNames, rootPaths;
  45926. getRoots (rootNames, rootPaths);
  45927. if (rootPaths [index].isNotEmpty())
  45928. {
  45929. setRoot (File (rootPaths [index]));
  45930. }
  45931. else
  45932. {
  45933. File f (newText);
  45934. for (;;)
  45935. {
  45936. if (f.isDirectory())
  45937. {
  45938. setRoot (f);
  45939. break;
  45940. }
  45941. if (f.getParentDirectory() == f)
  45942. break;
  45943. f = f.getParentDirectory();
  45944. }
  45945. }
  45946. }
  45947. }
  45948. const BigInteger FileBrowserComponent::getRoots (StringArray& rootNames, StringArray& rootPaths)
  45949. {
  45950. BigInteger separators;
  45951. #if JUCE_WINDOWS
  45952. Array<File> roots;
  45953. File::findFileSystemRoots (roots);
  45954. rootPaths.clear();
  45955. for (int i = 0; i < roots.size(); ++i)
  45956. {
  45957. const File& drive = roots.getReference(i);
  45958. String name (drive.getFullPathName());
  45959. rootPaths.add (name);
  45960. if (drive.isOnHardDisk())
  45961. {
  45962. String volume (drive.getVolumeLabel());
  45963. if (volume.isEmpty())
  45964. volume = TRANS("Hard Drive");
  45965. name << " [" << drive.getVolumeLabel() << ']';
  45966. }
  45967. else if (drive.isOnCDRomDrive())
  45968. {
  45969. name << TRANS(" [CD/DVD drive]");
  45970. }
  45971. rootNames.add (name);
  45972. }
  45973. separators.setBit (rootPaths.size());
  45974. rootPaths.add (File::getSpecialLocation (File::userDocumentsDirectory).getFullPathName());
  45975. rootNames.add ("Documents");
  45976. rootPaths.add (File::getSpecialLocation (File::userDesktopDirectory).getFullPathName());
  45977. rootNames.add ("Desktop");
  45978. #endif
  45979. #if JUCE_MAC
  45980. rootPaths.add (File::getSpecialLocation (File::userHomeDirectory).getFullPathName());
  45981. rootNames.add ("Home folder");
  45982. rootPaths.add (File::getSpecialLocation (File::userDocumentsDirectory).getFullPathName());
  45983. rootNames.add ("Documents");
  45984. rootPaths.add (File::getSpecialLocation (File::userDesktopDirectory).getFullPathName());
  45985. rootNames.add ("Desktop");
  45986. separators.setBit (rootPaths.size());
  45987. Array <File> volumes;
  45988. File vol ("/Volumes");
  45989. vol.findChildFiles (volumes, File::findDirectories, false);
  45990. for (int i = 0; i < volumes.size(); ++i)
  45991. {
  45992. const File& volume = volumes.getReference(i);
  45993. if (volume.isDirectory() && ! volume.getFileName().startsWithChar (T('.')))
  45994. {
  45995. rootPaths.add (volume.getFullPathName());
  45996. rootNames.add (volume.getFileName());
  45997. }
  45998. }
  45999. #endif
  46000. #if JUCE_LINUX
  46001. rootPaths.add ("/");
  46002. rootNames.add ("/");
  46003. rootPaths.add (File::getSpecialLocation (File::userHomeDirectory).getFullPathName());
  46004. rootNames.add ("Home folder");
  46005. rootPaths.add (File::getSpecialLocation (File::userDesktopDirectory).getFullPathName());
  46006. rootNames.add ("Desktop");
  46007. #endif
  46008. return separators;
  46009. }
  46010. END_JUCE_NAMESPACE
  46011. /*** End of inlined file: juce_FileBrowserComponent.cpp ***/
  46012. /*** Start of inlined file: juce_FileChooser.cpp ***/
  46013. BEGIN_JUCE_NAMESPACE
  46014. FileChooser::FileChooser (const String& chooserBoxTitle,
  46015. const File& currentFileOrDirectory,
  46016. const String& fileFilters,
  46017. const bool useNativeDialogBox_)
  46018. : title (chooserBoxTitle),
  46019. filters (fileFilters),
  46020. startingFile (currentFileOrDirectory),
  46021. useNativeDialogBox (useNativeDialogBox_)
  46022. {
  46023. #if JUCE_LINUX
  46024. useNativeDialogBox = false;
  46025. #endif
  46026. if (! fileFilters.containsNonWhitespaceChars())
  46027. filters = T("*");
  46028. }
  46029. FileChooser::~FileChooser()
  46030. {
  46031. }
  46032. bool FileChooser::browseForFileToOpen (FilePreviewComponent* previewComponent)
  46033. {
  46034. return showDialog (false, true, false, false, false, previewComponent);
  46035. }
  46036. bool FileChooser::browseForMultipleFilesToOpen (FilePreviewComponent* previewComponent)
  46037. {
  46038. return showDialog (false, true, false, false, true, previewComponent);
  46039. }
  46040. bool FileChooser::browseForMultipleFilesOrDirectories (FilePreviewComponent* previewComponent)
  46041. {
  46042. return showDialog (true, true, false, false, true, previewComponent);
  46043. }
  46044. bool FileChooser::browseForFileToSave (const bool warnAboutOverwritingExistingFiles)
  46045. {
  46046. return showDialog (false, true, true, warnAboutOverwritingExistingFiles, false, 0);
  46047. }
  46048. bool FileChooser::browseForDirectory()
  46049. {
  46050. return showDialog (true, false, false, false, false, 0);
  46051. }
  46052. const File FileChooser::getResult() const
  46053. {
  46054. // if you've used a multiple-file select, you should use the getResults() method
  46055. // to retrieve all the files that were chosen.
  46056. jassert (results.size() <= 1);
  46057. return results.getFirst();
  46058. }
  46059. const Array<File>& FileChooser::getResults() const
  46060. {
  46061. return results;
  46062. }
  46063. bool FileChooser::showDialog (const bool selectsDirectories,
  46064. const bool selectsFiles,
  46065. const bool isSave,
  46066. const bool warnAboutOverwritingExistingFiles,
  46067. const bool selectMultipleFiles,
  46068. FilePreviewComponent* const previewComponent)
  46069. {
  46070. Component::SafePointer<Component> previouslyFocused (Component::getCurrentlyFocusedComponent());
  46071. results.clear();
  46072. // the preview component needs to be the right size before you pass it in here..
  46073. jassert (previewComponent == 0 || (previewComponent->getWidth() > 10
  46074. && previewComponent->getHeight() > 10));
  46075. #if JUCE_WINDOWS
  46076. if (useNativeDialogBox && ! (selectsFiles && selectsDirectories))
  46077. #elif JUCE_MAC
  46078. if (useNativeDialogBox && (previewComponent == 0))
  46079. #else
  46080. if (false)
  46081. #endif
  46082. {
  46083. showPlatformDialog (results, title, startingFile, filters,
  46084. selectsDirectories, selectsFiles, isSave,
  46085. warnAboutOverwritingExistingFiles,
  46086. selectMultipleFiles,
  46087. previewComponent);
  46088. }
  46089. else
  46090. {
  46091. WildcardFileFilter wildcard (selectsFiles ? filters : String::empty,
  46092. selectsDirectories ? "*" : String::empty,
  46093. String::empty);
  46094. int flags = isSave ? FileBrowserComponent::saveMode
  46095. : FileBrowserComponent::openMode;
  46096. if (selectsFiles)
  46097. flags |= FileBrowserComponent::canSelectFiles;
  46098. if (selectsDirectories)
  46099. flags |= FileBrowserComponent::canSelectDirectories;
  46100. if (selectMultipleFiles)
  46101. flags |= FileBrowserComponent::canSelectMultipleItems;
  46102. FileBrowserComponent browserComponent (flags, startingFile, &wildcard, previewComponent);
  46103. FileChooserDialogBox box (title, String::empty,
  46104. browserComponent,
  46105. warnAboutOverwritingExistingFiles,
  46106. browserComponent.findColour (AlertWindow::backgroundColourId));
  46107. if (box.show())
  46108. {
  46109. for (int i = 0; i < browserComponent.getNumSelectedFiles(); ++i)
  46110. results.add (browserComponent.getSelectedFile (i));
  46111. }
  46112. }
  46113. if (previouslyFocused != 0)
  46114. previouslyFocused->grabKeyboardFocus();
  46115. return results.size() > 0;
  46116. }
  46117. FilePreviewComponent::FilePreviewComponent()
  46118. {
  46119. }
  46120. FilePreviewComponent::~FilePreviewComponent()
  46121. {
  46122. }
  46123. END_JUCE_NAMESPACE
  46124. /*** End of inlined file: juce_FileChooser.cpp ***/
  46125. /*** Start of inlined file: juce_FileChooserDialogBox.cpp ***/
  46126. BEGIN_JUCE_NAMESPACE
  46127. FileChooserDialogBox::FileChooserDialogBox (const String& name,
  46128. const String& instructions,
  46129. FileBrowserComponent& chooserComponent,
  46130. const bool warnAboutOverwritingExistingFiles_,
  46131. const Colour& backgroundColour)
  46132. : ResizableWindow (name, backgroundColour, true),
  46133. warnAboutOverwritingExistingFiles (warnAboutOverwritingExistingFiles_)
  46134. {
  46135. content = new ContentComponent();
  46136. content->setName (name);
  46137. content->instructions = instructions;
  46138. content->chooserComponent = &chooserComponent;
  46139. content->addAndMakeVisible (&chooserComponent);
  46140. content->okButton = new TextButton (chooserComponent.getActionVerb());
  46141. content->addAndMakeVisible (content->okButton);
  46142. content->okButton->addButtonListener (this);
  46143. content->okButton->setEnabled (chooserComponent.currentFileIsValid());
  46144. content->okButton->addShortcut (KeyPress (KeyPress::returnKey, 0, 0));
  46145. content->cancelButton = new TextButton (TRANS("Cancel"));
  46146. content->addAndMakeVisible (content->cancelButton);
  46147. content->cancelButton->addButtonListener (this);
  46148. content->cancelButton->addShortcut (KeyPress (KeyPress::escapeKey, 0, 0));
  46149. setContentComponent (content);
  46150. setResizable (true, true);
  46151. setResizeLimits (300, 300, 1200, 1000);
  46152. content->chooserComponent->addListener (this);
  46153. }
  46154. FileChooserDialogBox::~FileChooserDialogBox()
  46155. {
  46156. content->chooserComponent->removeListener (this);
  46157. }
  46158. bool FileChooserDialogBox::show (int w, int h)
  46159. {
  46160. if (w <= 0)
  46161. {
  46162. Component* const previewComp = content->chooserComponent->getPreviewComponent();
  46163. if (previewComp != 0)
  46164. w = 400 + previewComp->getWidth();
  46165. else
  46166. w = 600;
  46167. }
  46168. if (h <= 0)
  46169. h = 500;
  46170. centreWithSize (w, h);
  46171. const bool ok = (runModalLoop() != 0);
  46172. setVisible (false);
  46173. return ok;
  46174. }
  46175. void FileChooserDialogBox::buttonClicked (Button* button)
  46176. {
  46177. if (button == content->okButton)
  46178. {
  46179. if (warnAboutOverwritingExistingFiles
  46180. && content->chooserComponent->isSaveMode()
  46181. && content->chooserComponent->getSelectedFile(0).exists())
  46182. {
  46183. if (! AlertWindow::showOkCancelBox (AlertWindow::WarningIcon,
  46184. TRANS("File already exists"),
  46185. TRANS("There's already a file called:\n\n")
  46186. + content->chooserComponent->getSelectedFile(0).getFullPathName()
  46187. + T("\n\nAre you sure you want to overwrite it?"),
  46188. TRANS("overwrite"),
  46189. TRANS("cancel")))
  46190. {
  46191. return;
  46192. }
  46193. }
  46194. exitModalState (1);
  46195. }
  46196. else if (button == content->cancelButton)
  46197. closeButtonPressed();
  46198. }
  46199. void FileChooserDialogBox::closeButtonPressed()
  46200. {
  46201. setVisible (false);
  46202. }
  46203. void FileChooserDialogBox::selectionChanged()
  46204. {
  46205. content->okButton->setEnabled (content->chooserComponent->currentFileIsValid());
  46206. }
  46207. void FileChooserDialogBox::fileClicked (const File&, const MouseEvent&)
  46208. {
  46209. }
  46210. void FileChooserDialogBox::fileDoubleClicked (const File&)
  46211. {
  46212. selectionChanged();
  46213. content->okButton->triggerClick();
  46214. }
  46215. FileChooserDialogBox::ContentComponent::ContentComponent()
  46216. {
  46217. setInterceptsMouseClicks (false, true);
  46218. }
  46219. FileChooserDialogBox::ContentComponent::~ContentComponent()
  46220. {
  46221. delete okButton;
  46222. delete cancelButton;
  46223. }
  46224. void FileChooserDialogBox::ContentComponent::paint (Graphics& g)
  46225. {
  46226. g.setColour (getLookAndFeel().findColour (FileChooserDialogBox::titleTextColourId));
  46227. text.draw (g);
  46228. }
  46229. void FileChooserDialogBox::ContentComponent::resized()
  46230. {
  46231. getLookAndFeel().createFileChooserHeaderText (getName(), instructions, text, getWidth());
  46232. float left, top, right, bottom;
  46233. text.getBoundingBox (0, text.getNumGlyphs(), left, top, right, bottom, false);
  46234. const int y = roundToInt (bottom) + 10;
  46235. const int buttonHeight = 26;
  46236. const int buttonY = getHeight() - buttonHeight - 8;
  46237. chooserComponent->setBounds (0, y, getWidth(), buttonY - y - 20);
  46238. okButton->setBounds (proportionOfWidth (0.25f), buttonY,
  46239. proportionOfWidth (0.2f), buttonHeight);
  46240. cancelButton->setBounds (proportionOfWidth (0.55f), buttonY,
  46241. proportionOfWidth (0.2f), buttonHeight);
  46242. }
  46243. END_JUCE_NAMESPACE
  46244. /*** End of inlined file: juce_FileChooserDialogBox.cpp ***/
  46245. /*** Start of inlined file: juce_FileFilter.cpp ***/
  46246. BEGIN_JUCE_NAMESPACE
  46247. FileFilter::FileFilter (const String& filterDescription)
  46248. : description (filterDescription)
  46249. {
  46250. }
  46251. FileFilter::~FileFilter()
  46252. {
  46253. }
  46254. const String& FileFilter::getDescription() const throw()
  46255. {
  46256. return description;
  46257. }
  46258. END_JUCE_NAMESPACE
  46259. /*** End of inlined file: juce_FileFilter.cpp ***/
  46260. /*** Start of inlined file: juce_FileListComponent.cpp ***/
  46261. BEGIN_JUCE_NAMESPACE
  46262. Image* juce_createIconForFile (const File& file);
  46263. FileListComponent::FileListComponent (DirectoryContentsList& listToShow)
  46264. : ListBox (String::empty, 0),
  46265. DirectoryContentsDisplayComponent (listToShow)
  46266. {
  46267. setModel (this);
  46268. fileList.addChangeListener (this);
  46269. }
  46270. FileListComponent::~FileListComponent()
  46271. {
  46272. fileList.removeChangeListener (this);
  46273. deleteAllChildren();
  46274. }
  46275. int FileListComponent::getNumSelectedFiles() const
  46276. {
  46277. return getNumSelectedRows();
  46278. }
  46279. const File FileListComponent::getSelectedFile (int index) const
  46280. {
  46281. return fileList.getFile (getSelectedRow (index));
  46282. }
  46283. void FileListComponent::scrollToTop()
  46284. {
  46285. getVerticalScrollBar()->setCurrentRangeStart (0);
  46286. }
  46287. void FileListComponent::changeListenerCallback (void*)
  46288. {
  46289. updateContent();
  46290. if (lastDirectory != fileList.getDirectory())
  46291. {
  46292. lastDirectory = fileList.getDirectory();
  46293. deselectAllRows();
  46294. }
  46295. }
  46296. class FileListItemComponent : public Component,
  46297. public TimeSliceClient,
  46298. public AsyncUpdater
  46299. {
  46300. public:
  46301. FileListItemComponent (FileListComponent& owner_,
  46302. TimeSliceThread& thread_) throw()
  46303. : owner (owner_),
  46304. thread (thread_),
  46305. icon (0)
  46306. {
  46307. }
  46308. ~FileListItemComponent() throw()
  46309. {
  46310. thread.removeTimeSliceClient (this);
  46311. clearIcon();
  46312. }
  46313. void paint (Graphics& g)
  46314. {
  46315. getLookAndFeel().drawFileBrowserRow (g, getWidth(), getHeight(),
  46316. file.getFileName(),
  46317. icon,
  46318. fileSize, modTime,
  46319. isDirectory, highlighted,
  46320. index);
  46321. }
  46322. void mouseDown (const MouseEvent& e)
  46323. {
  46324. owner.selectRowsBasedOnModifierKeys (index, e.mods);
  46325. owner.sendMouseClickMessage (file, e);
  46326. }
  46327. void mouseDoubleClick (const MouseEvent&)
  46328. {
  46329. owner.sendDoubleClickMessage (file);
  46330. }
  46331. void update (const File& root,
  46332. const DirectoryContentsList::FileInfo* const fileInfo,
  46333. const int index_,
  46334. const bool highlighted_) throw()
  46335. {
  46336. thread.removeTimeSliceClient (this);
  46337. if (highlighted_ != highlighted
  46338. || index_ != index)
  46339. {
  46340. index = index_;
  46341. highlighted = highlighted_;
  46342. repaint();
  46343. }
  46344. File newFile;
  46345. String newFileSize;
  46346. String newModTime;
  46347. if (fileInfo != 0)
  46348. {
  46349. newFile = root.getChildFile (fileInfo->filename);
  46350. newFileSize = File::descriptionOfSizeInBytes (fileInfo->fileSize);
  46351. newModTime = fileInfo->modificationTime.formatted (T("%d %b '%y %H:%M"));
  46352. }
  46353. if (newFile != file
  46354. || fileSize != newFileSize
  46355. || modTime != newModTime)
  46356. {
  46357. file = newFile;
  46358. fileSize = newFileSize;
  46359. modTime = newModTime;
  46360. isDirectory = fileInfo != 0 && fileInfo->isDirectory;
  46361. repaint();
  46362. clearIcon();
  46363. }
  46364. if (file != File::nonexistent
  46365. && icon == 0 && ! isDirectory)
  46366. {
  46367. updateIcon (true);
  46368. if (icon == 0)
  46369. thread.addTimeSliceClient (this);
  46370. }
  46371. }
  46372. bool useTimeSlice()
  46373. {
  46374. updateIcon (false);
  46375. return false;
  46376. }
  46377. void handleAsyncUpdate()
  46378. {
  46379. repaint();
  46380. }
  46381. juce_UseDebuggingNewOperator
  46382. private:
  46383. FileListComponent& owner;
  46384. TimeSliceThread& thread;
  46385. bool highlighted;
  46386. int index;
  46387. File file;
  46388. String fileSize;
  46389. String modTime;
  46390. Image* icon;
  46391. bool isDirectory;
  46392. void clearIcon() throw()
  46393. {
  46394. ImageCache::release (icon);
  46395. icon = 0;
  46396. }
  46397. void updateIcon (const bool onlyUpdateIfCached) throw()
  46398. {
  46399. if (icon == 0)
  46400. {
  46401. const int hashCode = (file.getFullPathName() + T("_iconCacheSalt")).hashCode();
  46402. Image* im = ImageCache::getFromHashCode (hashCode);
  46403. if (im == 0 && ! onlyUpdateIfCached)
  46404. {
  46405. im = juce_createIconForFile (file);
  46406. if (im != 0)
  46407. ImageCache::addImageToCache (im, hashCode);
  46408. }
  46409. if (im != 0)
  46410. {
  46411. icon = im;
  46412. triggerAsyncUpdate();
  46413. }
  46414. }
  46415. }
  46416. };
  46417. int FileListComponent::getNumRows()
  46418. {
  46419. return fileList.getNumFiles();
  46420. }
  46421. void FileListComponent::paintListBoxItem (int, Graphics&, int, int, bool)
  46422. {
  46423. }
  46424. Component* FileListComponent::refreshComponentForRow (int row, bool isSelected, Component* existingComponentToUpdate)
  46425. {
  46426. FileListItemComponent* comp = dynamic_cast <FileListItemComponent*> (existingComponentToUpdate);
  46427. if (comp == 0)
  46428. {
  46429. delete existingComponentToUpdate;
  46430. comp = new FileListItemComponent (*this, fileList.getTimeSliceThread());
  46431. }
  46432. DirectoryContentsList::FileInfo fileInfo;
  46433. if (fileList.getFileInfo (row, fileInfo))
  46434. comp->update (fileList.getDirectory(), &fileInfo, row, isSelected);
  46435. else
  46436. comp->update (fileList.getDirectory(), 0, row, isSelected);
  46437. return comp;
  46438. }
  46439. void FileListComponent::selectedRowsChanged (int /*lastRowSelected*/)
  46440. {
  46441. sendSelectionChangeMessage();
  46442. }
  46443. void FileListComponent::deleteKeyPressed (int /*currentSelectedRow*/)
  46444. {
  46445. }
  46446. void FileListComponent::returnKeyPressed (int currentSelectedRow)
  46447. {
  46448. sendDoubleClickMessage (fileList.getFile (currentSelectedRow));
  46449. }
  46450. END_JUCE_NAMESPACE
  46451. /*** End of inlined file: juce_FileListComponent.cpp ***/
  46452. /*** Start of inlined file: juce_FilenameComponent.cpp ***/
  46453. BEGIN_JUCE_NAMESPACE
  46454. FilenameComponent::FilenameComponent (const String& name,
  46455. const File& currentFile,
  46456. const bool canEditFilename,
  46457. const bool isDirectory,
  46458. const bool isForSaving,
  46459. const String& fileBrowserWildcard,
  46460. const String& enforcedSuffix_,
  46461. const String& textWhenNothingSelected)
  46462. : Component (name),
  46463. maxRecentFiles (30),
  46464. isDir (isDirectory),
  46465. isSaving (isForSaving),
  46466. isFileDragOver (false),
  46467. wildcard (fileBrowserWildcard),
  46468. enforcedSuffix (enforcedSuffix_)
  46469. {
  46470. addAndMakeVisible (filenameBox = new ComboBox (T("fn")));
  46471. filenameBox->setEditableText (canEditFilename);
  46472. filenameBox->addListener (this);
  46473. filenameBox->setTextWhenNothingSelected (textWhenNothingSelected);
  46474. filenameBox->setTextWhenNoChoicesAvailable (TRANS("(no recently seleced files)"));
  46475. browseButton = 0;
  46476. setBrowseButtonText (T("..."));
  46477. setCurrentFile (currentFile, true);
  46478. }
  46479. FilenameComponent::~FilenameComponent()
  46480. {
  46481. deleteAllChildren();
  46482. }
  46483. void FilenameComponent::paintOverChildren (Graphics& g)
  46484. {
  46485. if (isFileDragOver)
  46486. {
  46487. g.setColour (Colours::red.withAlpha (0.2f));
  46488. g.drawRect (0, 0, getWidth(), getHeight(), 3);
  46489. }
  46490. }
  46491. void FilenameComponent::resized()
  46492. {
  46493. getLookAndFeel().layoutFilenameComponent (*this, filenameBox, browseButton);
  46494. }
  46495. void FilenameComponent::setBrowseButtonText (const String& newBrowseButtonText)
  46496. {
  46497. browseButtonText = newBrowseButtonText;
  46498. lookAndFeelChanged();
  46499. }
  46500. void FilenameComponent::lookAndFeelChanged()
  46501. {
  46502. deleteAndZero (browseButton);
  46503. addAndMakeVisible (browseButton = getLookAndFeel().createFilenameComponentBrowseButton (browseButtonText));
  46504. browseButton->setConnectedEdges (Button::ConnectedOnLeft);
  46505. resized();
  46506. browseButton->addButtonListener (this);
  46507. }
  46508. void FilenameComponent::setTooltip (const String& newTooltip)
  46509. {
  46510. SettableTooltipClient::setTooltip (newTooltip);
  46511. filenameBox->setTooltip (newTooltip);
  46512. }
  46513. void FilenameComponent::setDefaultBrowseTarget (const File& newDefaultDirectory) throw()
  46514. {
  46515. defaultBrowseFile = newDefaultDirectory;
  46516. }
  46517. void FilenameComponent::buttonClicked (Button*)
  46518. {
  46519. FileChooser fc (TRANS("Choose a new file"),
  46520. getCurrentFile() == File::nonexistent ? defaultBrowseFile
  46521. : getCurrentFile(),
  46522. wildcard);
  46523. if (isDir ? fc.browseForDirectory()
  46524. : (isSaving ? fc.browseForFileToSave (false)
  46525. : fc.browseForFileToOpen()))
  46526. {
  46527. setCurrentFile (fc.getResult(), true);
  46528. }
  46529. }
  46530. void FilenameComponent::comboBoxChanged (ComboBox*)
  46531. {
  46532. setCurrentFile (getCurrentFile(), true);
  46533. }
  46534. bool FilenameComponent::isInterestedInFileDrag (const StringArray&)
  46535. {
  46536. return true;
  46537. }
  46538. void FilenameComponent::filesDropped (const StringArray& filenames, int, int)
  46539. {
  46540. isFileDragOver = false;
  46541. repaint();
  46542. const File f (filenames[0]);
  46543. if (f.exists() && (f.isDirectory() == isDir))
  46544. setCurrentFile (f, true);
  46545. }
  46546. void FilenameComponent::fileDragEnter (const StringArray&, int, int)
  46547. {
  46548. isFileDragOver = true;
  46549. repaint();
  46550. }
  46551. void FilenameComponent::fileDragExit (const StringArray&)
  46552. {
  46553. isFileDragOver = false;
  46554. repaint();
  46555. }
  46556. const File FilenameComponent::getCurrentFile() const
  46557. {
  46558. File f (filenameBox->getText());
  46559. if (enforcedSuffix.isNotEmpty())
  46560. f = f.withFileExtension (enforcedSuffix);
  46561. return f;
  46562. }
  46563. void FilenameComponent::setCurrentFile (File newFile,
  46564. const bool addToRecentlyUsedList,
  46565. const bool sendChangeNotification)
  46566. {
  46567. if (enforcedSuffix.isNotEmpty())
  46568. newFile = newFile.withFileExtension (enforcedSuffix);
  46569. if (newFile.getFullPathName() != lastFilename)
  46570. {
  46571. lastFilename = newFile.getFullPathName();
  46572. if (addToRecentlyUsedList)
  46573. addRecentlyUsedFile (newFile);
  46574. filenameBox->setText (lastFilename, true);
  46575. if (sendChangeNotification)
  46576. triggerAsyncUpdate();
  46577. }
  46578. }
  46579. void FilenameComponent::setFilenameIsEditable (const bool shouldBeEditable)
  46580. {
  46581. filenameBox->setEditableText (shouldBeEditable);
  46582. }
  46583. const StringArray FilenameComponent::getRecentlyUsedFilenames() const
  46584. {
  46585. StringArray names;
  46586. for (int i = 0; i < filenameBox->getNumItems(); ++i)
  46587. names.add (filenameBox->getItemText (i));
  46588. return names;
  46589. }
  46590. void FilenameComponent::setRecentlyUsedFilenames (const StringArray& filenames)
  46591. {
  46592. if (filenames != getRecentlyUsedFilenames())
  46593. {
  46594. filenameBox->clear();
  46595. for (int i = 0; i < jmin (filenames.size(), maxRecentFiles); ++i)
  46596. filenameBox->addItem (filenames[i], i + 1);
  46597. }
  46598. }
  46599. void FilenameComponent::setMaxNumberOfRecentFiles (const int newMaximum)
  46600. {
  46601. maxRecentFiles = jmax (1, newMaximum);
  46602. setRecentlyUsedFilenames (getRecentlyUsedFilenames());
  46603. }
  46604. void FilenameComponent::addRecentlyUsedFile (const File& file)
  46605. {
  46606. StringArray files (getRecentlyUsedFilenames());
  46607. if (file.getFullPathName().isNotEmpty())
  46608. {
  46609. files.removeString (file.getFullPathName(), true);
  46610. files.insert (0, file.getFullPathName());
  46611. setRecentlyUsedFilenames (files);
  46612. }
  46613. }
  46614. void FilenameComponent::addListener (FilenameComponentListener* const listener) throw()
  46615. {
  46616. listeners.add (listener);
  46617. }
  46618. void FilenameComponent::removeListener (FilenameComponentListener* const listener) throw()
  46619. {
  46620. listeners.remove (listener);
  46621. }
  46622. void FilenameComponent::handleAsyncUpdate()
  46623. {
  46624. Component::BailOutChecker checker (this);
  46625. listeners.callChecked (checker, &FilenameComponentListener::filenameComponentChanged, this);
  46626. }
  46627. END_JUCE_NAMESPACE
  46628. /*** End of inlined file: juce_FilenameComponent.cpp ***/
  46629. /*** Start of inlined file: juce_FileSearchPathListComponent.cpp ***/
  46630. BEGIN_JUCE_NAMESPACE
  46631. FileSearchPathListComponent::FileSearchPathListComponent()
  46632. {
  46633. addAndMakeVisible (listBox = new ListBox (String::empty, this));
  46634. listBox->setColour (ListBox::backgroundColourId, Colours::black.withAlpha (0.02f));
  46635. listBox->setColour (ListBox::outlineColourId, Colours::black.withAlpha (0.1f));
  46636. listBox->setOutlineThickness (1);
  46637. addAndMakeVisible (addButton = new TextButton ("+"));
  46638. addButton->addButtonListener (this);
  46639. addButton->setConnectedEdges (Button::ConnectedOnLeft | Button::ConnectedOnRight | Button::ConnectedOnBottom | Button::ConnectedOnTop);
  46640. addAndMakeVisible (removeButton = new TextButton ("-"));
  46641. removeButton->addButtonListener (this);
  46642. removeButton->setConnectedEdges (Button::ConnectedOnLeft | Button::ConnectedOnRight | Button::ConnectedOnBottom | Button::ConnectedOnTop);
  46643. addAndMakeVisible (changeButton = new TextButton (TRANS("change...")));
  46644. changeButton->addButtonListener (this);
  46645. addAndMakeVisible (upButton = new DrawableButton (String::empty, DrawableButton::ImageOnButtonBackground));
  46646. upButton->addButtonListener (this);
  46647. {
  46648. Path arrowPath;
  46649. arrowPath.addArrow (50.0f, 100.0f, 50.0f, 0.0f, 40.0f, 100.0f, 50.0f);
  46650. DrawablePath arrowImage;
  46651. arrowImage.setFill (Colours::black.withAlpha (0.4f));
  46652. arrowImage.setPath (arrowPath);
  46653. ((DrawableButton*) upButton)->setImages (&arrowImage);
  46654. }
  46655. addAndMakeVisible (downButton = new DrawableButton (String::empty, DrawableButton::ImageOnButtonBackground));
  46656. downButton->addButtonListener (this);
  46657. {
  46658. Path arrowPath;
  46659. arrowPath.addArrow (50.0f, 0.0f, 50.0f, 100.0f, 40.0f, 100.0f, 50.0f);
  46660. DrawablePath arrowImage;
  46661. arrowImage.setFill (Colours::black.withAlpha (0.4f));
  46662. arrowImage.setPath (arrowPath);
  46663. ((DrawableButton*) downButton)->setImages (&arrowImage);
  46664. }
  46665. updateButtons();
  46666. }
  46667. FileSearchPathListComponent::~FileSearchPathListComponent()
  46668. {
  46669. deleteAllChildren();
  46670. }
  46671. void FileSearchPathListComponent::updateButtons() throw()
  46672. {
  46673. const bool anythingSelected = listBox->getNumSelectedRows() > 0;
  46674. removeButton->setEnabled (anythingSelected);
  46675. changeButton->setEnabled (anythingSelected);
  46676. upButton->setEnabled (anythingSelected);
  46677. downButton->setEnabled (anythingSelected);
  46678. }
  46679. void FileSearchPathListComponent::changed() throw()
  46680. {
  46681. listBox->updateContent();
  46682. listBox->repaint();
  46683. updateButtons();
  46684. }
  46685. void FileSearchPathListComponent::setPath (const FileSearchPath& newPath)
  46686. {
  46687. if (newPath.toString() != path.toString())
  46688. {
  46689. path = newPath;
  46690. changed();
  46691. }
  46692. }
  46693. void FileSearchPathListComponent::setDefaultBrowseTarget (const File& newDefaultDirectory) throw()
  46694. {
  46695. defaultBrowseTarget = newDefaultDirectory;
  46696. }
  46697. int FileSearchPathListComponent::getNumRows()
  46698. {
  46699. return path.getNumPaths();
  46700. }
  46701. void FileSearchPathListComponent::paintListBoxItem (int rowNumber, Graphics& g, int width, int height, bool rowIsSelected)
  46702. {
  46703. if (rowIsSelected)
  46704. g.fillAll (findColour (TextEditor::highlightColourId));
  46705. g.setColour (findColour (ListBox::textColourId));
  46706. Font f (height * 0.7f);
  46707. f.setHorizontalScale (0.9f);
  46708. g.setFont (f);
  46709. g.drawText (path [rowNumber].getFullPathName(),
  46710. 4, 0, width - 6, height,
  46711. Justification::centredLeft, true);
  46712. }
  46713. void FileSearchPathListComponent::deleteKeyPressed (int row)
  46714. {
  46715. if (((unsigned int) row) < (unsigned int) path.getNumPaths())
  46716. {
  46717. path.remove (row);
  46718. changed();
  46719. }
  46720. }
  46721. void FileSearchPathListComponent::returnKeyPressed (int row)
  46722. {
  46723. FileChooser chooser (TRANS("Change folder..."), path [row], T("*"));
  46724. if (chooser.browseForDirectory())
  46725. {
  46726. path.remove (row);
  46727. path.add (chooser.getResult(), row);
  46728. changed();
  46729. }
  46730. }
  46731. void FileSearchPathListComponent::listBoxItemDoubleClicked (int row, const MouseEvent&)
  46732. {
  46733. returnKeyPressed (row);
  46734. }
  46735. void FileSearchPathListComponent::selectedRowsChanged (int)
  46736. {
  46737. updateButtons();
  46738. }
  46739. void FileSearchPathListComponent::paint (Graphics& g)
  46740. {
  46741. g.fillAll (findColour (backgroundColourId));
  46742. }
  46743. void FileSearchPathListComponent::resized()
  46744. {
  46745. const int buttonH = 22;
  46746. const int buttonY = getHeight() - buttonH - 4;
  46747. listBox->setBounds (2, 2, getWidth() - 4, buttonY - 5);
  46748. addButton->setBounds (2, buttonY, buttonH, buttonH);
  46749. removeButton->setBounds (addButton->getRight(), buttonY, buttonH, buttonH);
  46750. ((TextButton*) changeButton)->changeWidthToFitText (buttonH);
  46751. downButton->setSize (buttonH * 2, buttonH);
  46752. upButton->setSize (buttonH * 2, buttonH);
  46753. downButton->setTopRightPosition (getWidth() - 2, buttonY);
  46754. upButton->setTopRightPosition (downButton->getX() - 4, buttonY);
  46755. changeButton->setTopRightPosition (upButton->getX() - 8, buttonY);
  46756. }
  46757. bool FileSearchPathListComponent::isInterestedInFileDrag (const StringArray&)
  46758. {
  46759. return true;
  46760. }
  46761. void FileSearchPathListComponent::filesDropped (const StringArray& filenames, int, int mouseY)
  46762. {
  46763. for (int i = filenames.size(); --i >= 0;)
  46764. {
  46765. const File f (filenames[i]);
  46766. if (f.isDirectory())
  46767. {
  46768. const int row = listBox->getRowContainingPosition (0, mouseY - listBox->getY());
  46769. path.add (f, row);
  46770. changed();
  46771. }
  46772. }
  46773. }
  46774. void FileSearchPathListComponent::buttonClicked (Button* button)
  46775. {
  46776. const int currentRow = listBox->getSelectedRow();
  46777. if (button == removeButton)
  46778. {
  46779. deleteKeyPressed (currentRow);
  46780. }
  46781. else if (button == addButton)
  46782. {
  46783. File start (defaultBrowseTarget);
  46784. if (start == File::nonexistent)
  46785. start = path [0];
  46786. if (start == File::nonexistent)
  46787. start = File::getCurrentWorkingDirectory();
  46788. FileChooser chooser (TRANS("Add a folder..."), start, T("*"));
  46789. if (chooser.browseForDirectory())
  46790. {
  46791. path.add (chooser.getResult(), currentRow);
  46792. }
  46793. }
  46794. else if (button == changeButton)
  46795. {
  46796. returnKeyPressed (currentRow);
  46797. }
  46798. else if (button == upButton)
  46799. {
  46800. if (currentRow > 0 && currentRow < path.getNumPaths())
  46801. {
  46802. const File f (path[currentRow]);
  46803. path.remove (currentRow);
  46804. path.add (f, currentRow - 1);
  46805. listBox->selectRow (currentRow - 1);
  46806. }
  46807. }
  46808. else if (button == downButton)
  46809. {
  46810. if (currentRow >= 0 && currentRow < path.getNumPaths() - 1)
  46811. {
  46812. const File f (path[currentRow]);
  46813. path.remove (currentRow);
  46814. path.add (f, currentRow + 1);
  46815. listBox->selectRow (currentRow + 1);
  46816. }
  46817. }
  46818. changed();
  46819. }
  46820. END_JUCE_NAMESPACE
  46821. /*** End of inlined file: juce_FileSearchPathListComponent.cpp ***/
  46822. /*** Start of inlined file: juce_FileTreeComponent.cpp ***/
  46823. BEGIN_JUCE_NAMESPACE
  46824. Image* juce_createIconForFile (const File& file);
  46825. class FileListTreeItem : public TreeViewItem,
  46826. public TimeSliceClient,
  46827. public AsyncUpdater,
  46828. public ChangeListener
  46829. {
  46830. public:
  46831. FileListTreeItem (FileTreeComponent& owner_,
  46832. DirectoryContentsList* const parentContentsList_,
  46833. const int indexInContentsList_,
  46834. const File& file_,
  46835. TimeSliceThread& thread_) throw()
  46836. : file (file_),
  46837. owner (owner_),
  46838. parentContentsList (parentContentsList_),
  46839. indexInContentsList (indexInContentsList_),
  46840. subContentsList (0),
  46841. canDeleteSubContentsList (false),
  46842. thread (thread_),
  46843. icon (0)
  46844. {
  46845. DirectoryContentsList::FileInfo fileInfo;
  46846. if (parentContentsList_ != 0
  46847. && parentContentsList_->getFileInfo (indexInContentsList_, fileInfo))
  46848. {
  46849. fileSize = File::descriptionOfSizeInBytes (fileInfo.fileSize);
  46850. modTime = fileInfo.modificationTime.formatted (T("%d %b '%y %H:%M"));
  46851. isDirectory = fileInfo.isDirectory;
  46852. }
  46853. else
  46854. {
  46855. isDirectory = true;
  46856. }
  46857. }
  46858. ~FileListTreeItem() throw()
  46859. {
  46860. thread.removeTimeSliceClient (this);
  46861. clearSubItems();
  46862. ImageCache::release (icon);
  46863. if (canDeleteSubContentsList)
  46864. delete subContentsList;
  46865. }
  46866. bool mightContainSubItems() { return isDirectory; }
  46867. const String getUniqueName() const { return file.getFullPathName(); }
  46868. int getItemHeight() const { return 22; }
  46869. const String getDragSourceDescription() { return owner.getDragAndDropDescription(); }
  46870. void itemOpennessChanged (bool isNowOpen)
  46871. {
  46872. if (isNowOpen)
  46873. {
  46874. clearSubItems();
  46875. isDirectory = file.isDirectory();
  46876. if (isDirectory)
  46877. {
  46878. if (subContentsList == 0)
  46879. {
  46880. jassert (parentContentsList != 0);
  46881. DirectoryContentsList* const l = new DirectoryContentsList (parentContentsList->getFilter(), thread);
  46882. l->setDirectory (file, true, true);
  46883. setSubContentsList (l);
  46884. canDeleteSubContentsList = true;
  46885. }
  46886. changeListenerCallback (0);
  46887. }
  46888. }
  46889. }
  46890. void setSubContentsList (DirectoryContentsList* newList) throw()
  46891. {
  46892. jassert (subContentsList == 0);
  46893. subContentsList = newList;
  46894. newList->addChangeListener (this);
  46895. }
  46896. void changeListenerCallback (void*)
  46897. {
  46898. clearSubItems();
  46899. if (isOpen() && subContentsList != 0)
  46900. {
  46901. for (int i = 0; i < subContentsList->getNumFiles(); ++i)
  46902. {
  46903. FileListTreeItem* const item
  46904. = new FileListTreeItem (owner, subContentsList, i, subContentsList->getFile(i), thread);
  46905. addSubItem (item);
  46906. }
  46907. }
  46908. }
  46909. void paintItem (Graphics& g, int width, int height)
  46910. {
  46911. if (file != File::nonexistent)
  46912. {
  46913. updateIcon (true);
  46914. if (icon == 0)
  46915. thread.addTimeSliceClient (this);
  46916. }
  46917. owner.getLookAndFeel()
  46918. .drawFileBrowserRow (g, width, height,
  46919. file.getFileName(),
  46920. icon,
  46921. fileSize, modTime,
  46922. isDirectory, isSelected(),
  46923. indexInContentsList);
  46924. }
  46925. void itemClicked (const MouseEvent& e)
  46926. {
  46927. owner.sendMouseClickMessage (file, e);
  46928. }
  46929. void itemDoubleClicked (const MouseEvent& e)
  46930. {
  46931. TreeViewItem::itemDoubleClicked (e);
  46932. owner.sendDoubleClickMessage (file);
  46933. }
  46934. void itemSelectionChanged (bool)
  46935. {
  46936. owner.sendSelectionChangeMessage();
  46937. }
  46938. bool useTimeSlice()
  46939. {
  46940. updateIcon (false);
  46941. thread.removeTimeSliceClient (this);
  46942. return false;
  46943. }
  46944. void handleAsyncUpdate()
  46945. {
  46946. owner.repaint();
  46947. }
  46948. const File file;
  46949. juce_UseDebuggingNewOperator
  46950. private:
  46951. FileTreeComponent& owner;
  46952. DirectoryContentsList* parentContentsList;
  46953. int indexInContentsList;
  46954. DirectoryContentsList* subContentsList;
  46955. bool isDirectory, canDeleteSubContentsList;
  46956. TimeSliceThread& thread;
  46957. Image* icon;
  46958. String fileSize;
  46959. String modTime;
  46960. void updateIcon (const bool onlyUpdateIfCached) throw()
  46961. {
  46962. if (icon == 0)
  46963. {
  46964. const int hashCode = (file.getFullPathName() + T("_iconCacheSalt")).hashCode();
  46965. Image* im = ImageCache::getFromHashCode (hashCode);
  46966. if (im == 0 && ! onlyUpdateIfCached)
  46967. {
  46968. im = juce_createIconForFile (file);
  46969. if (im != 0)
  46970. ImageCache::addImageToCache (im, hashCode);
  46971. }
  46972. if (im != 0)
  46973. {
  46974. icon = im;
  46975. triggerAsyncUpdate();
  46976. }
  46977. }
  46978. }
  46979. };
  46980. FileTreeComponent::FileTreeComponent (DirectoryContentsList& listToShow)
  46981. : DirectoryContentsDisplayComponent (listToShow)
  46982. {
  46983. FileListTreeItem* const root
  46984. = new FileListTreeItem (*this, 0, 0, listToShow.getDirectory(),
  46985. listToShow.getTimeSliceThread());
  46986. root->setSubContentsList (&listToShow);
  46987. setRootItemVisible (false);
  46988. setRootItem (root);
  46989. }
  46990. FileTreeComponent::~FileTreeComponent()
  46991. {
  46992. deleteRootItem();
  46993. }
  46994. const File FileTreeComponent::getSelectedFile (const int index) const
  46995. {
  46996. const FileListTreeItem* const item = dynamic_cast <const FileListTreeItem*> (getSelectedItem (index));
  46997. if (item != 0)
  46998. return item->file;
  46999. return File::nonexistent;
  47000. }
  47001. void FileTreeComponent::scrollToTop()
  47002. {
  47003. getViewport()->getVerticalScrollBar()->setCurrentRangeStart (0);
  47004. }
  47005. void FileTreeComponent::setDragAndDropDescription (const String& description) throw()
  47006. {
  47007. dragAndDropDescription = description;
  47008. }
  47009. END_JUCE_NAMESPACE
  47010. /*** End of inlined file: juce_FileTreeComponent.cpp ***/
  47011. /*** Start of inlined file: juce_ImagePreviewComponent.cpp ***/
  47012. BEGIN_JUCE_NAMESPACE
  47013. ImagePreviewComponent::ImagePreviewComponent()
  47014. {
  47015. }
  47016. ImagePreviewComponent::~ImagePreviewComponent()
  47017. {
  47018. }
  47019. void ImagePreviewComponent::getThumbSize (int& w, int& h) const
  47020. {
  47021. const int availableW = proportionOfWidth (0.97f);
  47022. const int availableH = getHeight() - 13 * 4;
  47023. const double scale = jmin (1.0,
  47024. availableW / (double) w,
  47025. availableH / (double) h);
  47026. w = roundToInt (scale * w);
  47027. h = roundToInt (scale * h);
  47028. }
  47029. void ImagePreviewComponent::selectedFileChanged (const File& file)
  47030. {
  47031. if (fileToLoad != file)
  47032. {
  47033. fileToLoad = file;
  47034. startTimer (100);
  47035. }
  47036. }
  47037. void ImagePreviewComponent::timerCallback()
  47038. {
  47039. stopTimer();
  47040. currentThumbnail = 0;
  47041. currentDetails = String::empty;
  47042. repaint();
  47043. ScopedPointer <FileInputStream> in (fileToLoad.createInputStream());
  47044. if (in != 0)
  47045. {
  47046. ImageFileFormat* const format = ImageFileFormat::findImageFormatForStream (*in);
  47047. if (format != 0)
  47048. {
  47049. currentThumbnail = format->decodeImage (*in);
  47050. if (currentThumbnail != 0)
  47051. {
  47052. int w = currentThumbnail->getWidth();
  47053. int h = currentThumbnail->getHeight();
  47054. currentDetails
  47055. << fileToLoad.getFileName() << "\n"
  47056. << format->getFormatName() << "\n"
  47057. << w << " x " << h << " pixels\n"
  47058. << File::descriptionOfSizeInBytes (fileToLoad.getSize());
  47059. getThumbSize (w, h);
  47060. currentThumbnail = currentThumbnail->createCopy (w, h);
  47061. }
  47062. }
  47063. }
  47064. }
  47065. void ImagePreviewComponent::paint (Graphics& g)
  47066. {
  47067. if (currentThumbnail != 0)
  47068. {
  47069. g.setFont (13.0f);
  47070. int w = currentThumbnail->getWidth();
  47071. int h = currentThumbnail->getHeight();
  47072. getThumbSize (w, h);
  47073. const int numLines = 4;
  47074. const int totalH = 13 * numLines + h + 4;
  47075. const int y = (getHeight() - totalH) / 2;
  47076. g.drawImageWithin (currentThumbnail,
  47077. (getWidth() - w) / 2, y, w, h,
  47078. RectanglePlacement::centred | RectanglePlacement::onlyReduceInSize,
  47079. false);
  47080. g.drawFittedText (currentDetails,
  47081. 0, y + h + 4, getWidth(), 100,
  47082. Justification::centredTop, numLines);
  47083. }
  47084. }
  47085. END_JUCE_NAMESPACE
  47086. /*** End of inlined file: juce_ImagePreviewComponent.cpp ***/
  47087. /*** Start of inlined file: juce_WildcardFileFilter.cpp ***/
  47088. BEGIN_JUCE_NAMESPACE
  47089. WildcardFileFilter::WildcardFileFilter (const String& fileWildcardPatterns,
  47090. const String& directoryWildcardPatterns,
  47091. const String& description_)
  47092. : FileFilter (description_.isEmpty() ? fileWildcardPatterns
  47093. : (description_ + T(" (") + fileWildcardPatterns + T(")")))
  47094. {
  47095. parse (fileWildcardPatterns, fileWildcards);
  47096. parse (directoryWildcardPatterns, directoryWildcards);
  47097. }
  47098. WildcardFileFilter::~WildcardFileFilter()
  47099. {
  47100. }
  47101. bool WildcardFileFilter::isFileSuitable (const File& file) const
  47102. {
  47103. return match (file, fileWildcards);
  47104. }
  47105. bool WildcardFileFilter::isDirectorySuitable (const File& file) const
  47106. {
  47107. return match (file, directoryWildcards);
  47108. }
  47109. void WildcardFileFilter::parse (const String& pattern, StringArray& result) throw()
  47110. {
  47111. result.addTokens (pattern.toLowerCase(), T(";,"), T("\"'"));
  47112. result.trim();
  47113. result.removeEmptyStrings();
  47114. // special case for *.*, because people use it to mean "any file", but it
  47115. // would actually ignore files with no extension.
  47116. for (int i = result.size(); --i >= 0;)
  47117. if (result[i] == T("*.*"))
  47118. result.set (i, T("*"));
  47119. }
  47120. bool WildcardFileFilter::match (const File& file, const StringArray& wildcards) throw()
  47121. {
  47122. const String filename (file.getFileName());
  47123. for (int i = wildcards.size(); --i >= 0;)
  47124. if (filename.matchesWildcard (wildcards[i], true))
  47125. return true;
  47126. return false;
  47127. }
  47128. END_JUCE_NAMESPACE
  47129. /*** End of inlined file: juce_WildcardFileFilter.cpp ***/
  47130. /*** Start of inlined file: juce_KeyboardFocusTraverser.cpp ***/
  47131. BEGIN_JUCE_NAMESPACE
  47132. KeyboardFocusTraverser::KeyboardFocusTraverser()
  47133. {
  47134. }
  47135. KeyboardFocusTraverser::~KeyboardFocusTraverser()
  47136. {
  47137. }
  47138. namespace KeyboardFocusHelpers
  47139. {
  47140. // This will sort a set of components, so that they are ordered in terms of
  47141. // left-to-right and then top-to-bottom.
  47142. class ScreenPositionComparator
  47143. {
  47144. public:
  47145. ScreenPositionComparator() {}
  47146. static int compareElements (const Component* const first, const Component* const second) throw()
  47147. {
  47148. int explicitOrder1 = first->getExplicitFocusOrder();
  47149. if (explicitOrder1 <= 0)
  47150. explicitOrder1 = std::numeric_limits<int>::max() / 2;
  47151. int explicitOrder2 = second->getExplicitFocusOrder();
  47152. if (explicitOrder2 <= 0)
  47153. explicitOrder2 = std::numeric_limits<int>::max() / 2;
  47154. if (explicitOrder1 != explicitOrder2)
  47155. return explicitOrder1 - explicitOrder2;
  47156. const int diff = first->getY() - second->getY();
  47157. return (diff == 0) ? first->getX() - second->getX()
  47158. : diff;
  47159. }
  47160. };
  47161. static void findAllFocusableComponents (Component* const parent, Array <Component*>& comps)
  47162. {
  47163. if (parent->getNumChildComponents() > 0)
  47164. {
  47165. Array <Component*> localComps;
  47166. ScreenPositionComparator comparator;
  47167. int i;
  47168. for (i = parent->getNumChildComponents(); --i >= 0;)
  47169. {
  47170. Component* const c = parent->getChildComponent (i);
  47171. if (c->isVisible() && c->isEnabled())
  47172. localComps.addSorted (comparator, c);
  47173. }
  47174. for (i = 0; i < localComps.size(); ++i)
  47175. {
  47176. Component* const c = localComps.getUnchecked (i);
  47177. if (c->getWantsKeyboardFocus())
  47178. comps.add (c);
  47179. if (! c->isFocusContainer())
  47180. findAllFocusableComponents (c, comps);
  47181. }
  47182. }
  47183. }
  47184. }
  47185. static Component* getIncrementedComponent (Component* const current, const int delta) throw()
  47186. {
  47187. Component* focusContainer = current->getParentComponent();
  47188. if (focusContainer != 0)
  47189. {
  47190. while (focusContainer->getParentComponent() != 0 && ! focusContainer->isFocusContainer())
  47191. focusContainer = focusContainer->getParentComponent();
  47192. if (focusContainer != 0)
  47193. {
  47194. Array <Component*> comps;
  47195. KeyboardFocusHelpers::findAllFocusableComponents (focusContainer, comps);
  47196. if (comps.size() > 0)
  47197. {
  47198. const int index = comps.indexOf (current);
  47199. return comps [(index + comps.size() + delta) % comps.size()];
  47200. }
  47201. }
  47202. }
  47203. return 0;
  47204. }
  47205. Component* KeyboardFocusTraverser::getNextComponent (Component* current)
  47206. {
  47207. return getIncrementedComponent (current, 1);
  47208. }
  47209. Component* KeyboardFocusTraverser::getPreviousComponent (Component* current)
  47210. {
  47211. return getIncrementedComponent (current, -1);
  47212. }
  47213. Component* KeyboardFocusTraverser::getDefaultComponent (Component* parentComponent)
  47214. {
  47215. Array <Component*> comps;
  47216. if (parentComponent != 0)
  47217. KeyboardFocusHelpers::findAllFocusableComponents (parentComponent, comps);
  47218. return comps.getFirst();
  47219. }
  47220. END_JUCE_NAMESPACE
  47221. /*** End of inlined file: juce_KeyboardFocusTraverser.cpp ***/
  47222. /*** Start of inlined file: juce_KeyListener.cpp ***/
  47223. BEGIN_JUCE_NAMESPACE
  47224. bool KeyListener::keyStateChanged (const bool, Component*)
  47225. {
  47226. return false;
  47227. }
  47228. END_JUCE_NAMESPACE
  47229. /*** End of inlined file: juce_KeyListener.cpp ***/
  47230. /*** Start of inlined file: juce_KeyMappingEditorComponent.cpp ***/
  47231. BEGIN_JUCE_NAMESPACE
  47232. // N.B. these two includes are put here deliberately to avoid problems with
  47233. // old GCCs failing on long include paths
  47234. const int maxKeys = 3;
  47235. class KeyMappingChangeButton : public Button
  47236. {
  47237. public:
  47238. KeyMappingChangeButton (KeyMappingEditorComponent* const owner_,
  47239. const CommandID commandID_,
  47240. const String& keyName,
  47241. const int keyNum_)
  47242. : Button (keyName),
  47243. owner (owner_),
  47244. commandID (commandID_),
  47245. keyNum (keyNum_)
  47246. {
  47247. setWantsKeyboardFocus (false);
  47248. setTriggeredOnMouseDown (keyNum >= 0);
  47249. if (keyNum_ < 0)
  47250. setTooltip (TRANS("adds a new key-mapping"));
  47251. else
  47252. setTooltip (TRANS("click to change this key-mapping"));
  47253. }
  47254. ~KeyMappingChangeButton()
  47255. {
  47256. }
  47257. void paintButton (Graphics& g, bool /*isOver*/, bool /*isDown*/)
  47258. {
  47259. getLookAndFeel().drawKeymapChangeButton (g, getWidth(), getHeight(), *this,
  47260. keyNum >= 0 ? getName() : String::empty);
  47261. }
  47262. void clicked()
  47263. {
  47264. if (keyNum >= 0)
  47265. {
  47266. // existing key clicked..
  47267. PopupMenu m;
  47268. m.addItem (1, TRANS("change this key-mapping"));
  47269. m.addSeparator();
  47270. m.addItem (2, TRANS("remove this key-mapping"));
  47271. const int res = m.show();
  47272. if (res == 1)
  47273. {
  47274. owner->assignNewKey (commandID, keyNum);
  47275. }
  47276. else if (res == 2)
  47277. {
  47278. owner->getMappings()->removeKeyPress (commandID, keyNum);
  47279. }
  47280. }
  47281. else
  47282. {
  47283. // + button pressed..
  47284. owner->assignNewKey (commandID, -1);
  47285. }
  47286. }
  47287. void fitToContent (const int h) throw()
  47288. {
  47289. if (keyNum < 0)
  47290. {
  47291. setSize (h, h);
  47292. }
  47293. else
  47294. {
  47295. Font f (h * 0.6f);
  47296. setSize (jlimit (h * 4, h * 8, 6 + f.getStringWidth (getName())), h);
  47297. }
  47298. }
  47299. juce_UseDebuggingNewOperator
  47300. private:
  47301. KeyMappingEditorComponent* const owner;
  47302. const CommandID commandID;
  47303. const int keyNum;
  47304. KeyMappingChangeButton (const KeyMappingChangeButton&);
  47305. KeyMappingChangeButton& operator= (const KeyMappingChangeButton&);
  47306. };
  47307. class KeyMappingItemComponent : public Component
  47308. {
  47309. public:
  47310. KeyMappingItemComponent (KeyMappingEditorComponent* const owner_,
  47311. const CommandID commandID_)
  47312. : owner (owner_),
  47313. commandID (commandID_)
  47314. {
  47315. setInterceptsMouseClicks (false, true);
  47316. const bool isReadOnly = owner_->isCommandReadOnly (commandID);
  47317. const Array <KeyPress> keyPresses (owner_->getMappings()->getKeyPressesAssignedToCommand (commandID));
  47318. for (int i = 0; i < jmin (maxKeys, keyPresses.size()); ++i)
  47319. {
  47320. KeyMappingChangeButton* const kb
  47321. = new KeyMappingChangeButton (owner_, commandID,
  47322. owner_->getDescriptionForKeyPress (keyPresses.getReference (i)), i);
  47323. kb->setEnabled (! isReadOnly);
  47324. addAndMakeVisible (kb);
  47325. }
  47326. KeyMappingChangeButton* const kb
  47327. = new KeyMappingChangeButton (owner_, commandID, String::empty, -1);
  47328. addChildComponent (kb);
  47329. kb->setVisible (keyPresses.size() < maxKeys && ! isReadOnly);
  47330. }
  47331. ~KeyMappingItemComponent()
  47332. {
  47333. deleteAllChildren();
  47334. }
  47335. void paint (Graphics& g)
  47336. {
  47337. g.setFont (getHeight() * 0.7f);
  47338. g.setColour (findColour (KeyMappingEditorComponent::textColourId));
  47339. g.drawFittedText (owner->getMappings()->getCommandManager()->getNameOfCommand (commandID),
  47340. 4, 0, jmax (40, getChildComponent (0)->getX() - 5), getHeight(),
  47341. Justification::centredLeft, true);
  47342. }
  47343. void resized()
  47344. {
  47345. int x = getWidth() - 4;
  47346. for (int i = getNumChildComponents(); --i >= 0;)
  47347. {
  47348. KeyMappingChangeButton* const kb = dynamic_cast <KeyMappingChangeButton*> (getChildComponent (i));
  47349. kb->fitToContent (getHeight() - 2);
  47350. kb->setTopRightPosition (x, 1);
  47351. x -= kb->getWidth() + 5;
  47352. }
  47353. }
  47354. juce_UseDebuggingNewOperator
  47355. private:
  47356. KeyMappingEditorComponent* const owner;
  47357. const CommandID commandID;
  47358. KeyMappingItemComponent (const KeyMappingItemComponent&);
  47359. KeyMappingItemComponent& operator= (const KeyMappingItemComponent&);
  47360. };
  47361. class KeyMappingTreeViewItem : public TreeViewItem
  47362. {
  47363. public:
  47364. KeyMappingTreeViewItem (KeyMappingEditorComponent* const owner_,
  47365. const CommandID commandID_)
  47366. : owner (owner_),
  47367. commandID (commandID_)
  47368. {
  47369. }
  47370. ~KeyMappingTreeViewItem()
  47371. {
  47372. }
  47373. const String getUniqueName() const { return String ((int) commandID) + "_id"; }
  47374. bool mightContainSubItems() { return false; }
  47375. int getItemHeight() const { return 20; }
  47376. Component* createItemComponent()
  47377. {
  47378. return new KeyMappingItemComponent (owner, commandID);
  47379. }
  47380. juce_UseDebuggingNewOperator
  47381. private:
  47382. KeyMappingEditorComponent* const owner;
  47383. const CommandID commandID;
  47384. KeyMappingTreeViewItem (const KeyMappingTreeViewItem&);
  47385. KeyMappingTreeViewItem& operator= (const KeyMappingTreeViewItem&);
  47386. };
  47387. class KeyCategoryTreeViewItem : public TreeViewItem
  47388. {
  47389. public:
  47390. KeyCategoryTreeViewItem (KeyMappingEditorComponent* const owner_,
  47391. const String& name)
  47392. : owner (owner_),
  47393. categoryName (name)
  47394. {
  47395. }
  47396. ~KeyCategoryTreeViewItem()
  47397. {
  47398. }
  47399. const String getUniqueName() const { return categoryName + "_cat"; }
  47400. bool mightContainSubItems() { return true; }
  47401. int getItemHeight() const { return 28; }
  47402. void paintItem (Graphics& g, int width, int height)
  47403. {
  47404. g.setFont (height * 0.6f, Font::bold);
  47405. g.setColour (owner->findColour (KeyMappingEditorComponent::textColourId));
  47406. g.drawText (categoryName,
  47407. 2, 0, width - 2, height,
  47408. Justification::centredLeft, true);
  47409. }
  47410. void itemOpennessChanged (bool isNowOpen)
  47411. {
  47412. if (isNowOpen)
  47413. {
  47414. if (getNumSubItems() == 0)
  47415. {
  47416. Array <CommandID> commands (owner->getMappings()->getCommandManager()->getCommandsInCategory (categoryName));
  47417. for (int i = 0; i < commands.size(); ++i)
  47418. {
  47419. if (owner->shouldCommandBeIncluded (commands[i]))
  47420. addSubItem (new KeyMappingTreeViewItem (owner, commands[i]));
  47421. }
  47422. }
  47423. }
  47424. else
  47425. {
  47426. clearSubItems();
  47427. }
  47428. }
  47429. juce_UseDebuggingNewOperator
  47430. private:
  47431. KeyMappingEditorComponent* owner;
  47432. String categoryName;
  47433. KeyCategoryTreeViewItem (const KeyCategoryTreeViewItem&);
  47434. KeyCategoryTreeViewItem& operator= (const KeyCategoryTreeViewItem&);
  47435. };
  47436. KeyMappingEditorComponent::KeyMappingEditorComponent (KeyPressMappingSet* const mappingManager,
  47437. const bool showResetToDefaultButton)
  47438. : mappings (mappingManager)
  47439. {
  47440. jassert (mappingManager != 0); // can't be null!
  47441. mappingManager->addChangeListener (this);
  47442. setLinesDrawnForSubItems (false);
  47443. resetButton = 0;
  47444. if (showResetToDefaultButton)
  47445. {
  47446. addAndMakeVisible (resetButton = new TextButton (TRANS("reset to defaults")));
  47447. resetButton->addButtonListener (this);
  47448. }
  47449. addAndMakeVisible (tree = new TreeView());
  47450. tree->setColour (TreeView::backgroundColourId, findColour (backgroundColourId));
  47451. tree->setRootItemVisible (false);
  47452. tree->setDefaultOpenness (true);
  47453. tree->setRootItem (this);
  47454. }
  47455. KeyMappingEditorComponent::~KeyMappingEditorComponent()
  47456. {
  47457. mappings->removeChangeListener (this);
  47458. deleteAllChildren();
  47459. }
  47460. bool KeyMappingEditorComponent::mightContainSubItems()
  47461. {
  47462. return true;
  47463. }
  47464. const String KeyMappingEditorComponent::getUniqueName() const
  47465. {
  47466. return T("keys");
  47467. }
  47468. void KeyMappingEditorComponent::setColours (const Colour& mainBackground,
  47469. const Colour& textColour)
  47470. {
  47471. setColour (backgroundColourId, mainBackground);
  47472. setColour (textColourId, textColour);
  47473. tree->setColour (TreeView::backgroundColourId, mainBackground);
  47474. }
  47475. void KeyMappingEditorComponent::parentHierarchyChanged()
  47476. {
  47477. changeListenerCallback (0);
  47478. }
  47479. void KeyMappingEditorComponent::resized()
  47480. {
  47481. int h = getHeight();
  47482. if (resetButton != 0)
  47483. {
  47484. const int buttonHeight = 20;
  47485. h -= buttonHeight + 8;
  47486. int x = getWidth() - 8;
  47487. const int y = h + 6;
  47488. resetButton->changeWidthToFitText (buttonHeight);
  47489. resetButton->setTopRightPosition (x, y);
  47490. }
  47491. tree->setBounds (0, 0, getWidth(), h);
  47492. }
  47493. void KeyMappingEditorComponent::buttonClicked (Button* button)
  47494. {
  47495. if (button == resetButton)
  47496. {
  47497. if (AlertWindow::showOkCancelBox (AlertWindow::QuestionIcon,
  47498. TRANS("Reset to defaults"),
  47499. TRANS("Are you sure you want to reset all the key-mappings to their default state?"),
  47500. TRANS("Reset")))
  47501. {
  47502. mappings->resetToDefaultMappings();
  47503. }
  47504. }
  47505. }
  47506. void KeyMappingEditorComponent::changeListenerCallback (void*)
  47507. {
  47508. ScopedPointer <XmlElement> openness (tree->getOpennessState (true));
  47509. clearSubItems();
  47510. const StringArray categories (mappings->getCommandManager()->getCommandCategories());
  47511. for (int i = 0; i < categories.size(); ++i)
  47512. {
  47513. const Array <CommandID> commands (mappings->getCommandManager()->getCommandsInCategory (categories[i]));
  47514. int count = 0;
  47515. for (int j = 0; j < commands.size(); ++j)
  47516. if (shouldCommandBeIncluded (commands[j]))
  47517. ++count;
  47518. if (count > 0)
  47519. addSubItem (new KeyCategoryTreeViewItem (this, categories[i]));
  47520. }
  47521. if (openness != 0)
  47522. tree->restoreOpennessState (*openness);
  47523. }
  47524. class KeyEntryWindow : public AlertWindow
  47525. {
  47526. public:
  47527. KeyEntryWindow (KeyMappingEditorComponent* const owner_)
  47528. : AlertWindow (TRANS("New key-mapping"),
  47529. TRANS("Please press a key combination now..."),
  47530. AlertWindow::NoIcon),
  47531. owner (owner_)
  47532. {
  47533. addButton (TRANS("ok"), 1);
  47534. addButton (TRANS("cancel"), 0);
  47535. // (avoid return + escape keys getting processed by the buttons..)
  47536. for (int i = getNumChildComponents(); --i >= 0;)
  47537. getChildComponent (i)->setWantsKeyboardFocus (false);
  47538. setWantsKeyboardFocus (true);
  47539. grabKeyboardFocus();
  47540. }
  47541. ~KeyEntryWindow()
  47542. {
  47543. }
  47544. bool keyPressed (const KeyPress& key)
  47545. {
  47546. lastPress = key;
  47547. String message (TRANS("Key: ") + owner->getDescriptionForKeyPress (key));
  47548. const CommandID previousCommand = owner->getMappings()->findCommandForKeyPress (key);
  47549. if (previousCommand != 0)
  47550. {
  47551. message << "\n\n"
  47552. << TRANS("(Currently assigned to \"")
  47553. << owner->getMappings()->getCommandManager()->getNameOfCommand (previousCommand)
  47554. << "\")";
  47555. }
  47556. setMessage (message);
  47557. return true;
  47558. }
  47559. bool keyStateChanged (const bool)
  47560. {
  47561. return true;
  47562. }
  47563. KeyPress lastPress;
  47564. juce_UseDebuggingNewOperator
  47565. private:
  47566. KeyMappingEditorComponent* owner;
  47567. KeyEntryWindow (const KeyEntryWindow&);
  47568. KeyEntryWindow& operator= (const KeyEntryWindow&);
  47569. };
  47570. void KeyMappingEditorComponent::assignNewKey (const CommandID commandID, const int index)
  47571. {
  47572. KeyEntryWindow entryWindow (this);
  47573. if (entryWindow.runModalLoop() != 0)
  47574. {
  47575. entryWindow.setVisible (false);
  47576. if (entryWindow.lastPress.isValid())
  47577. {
  47578. const CommandID previousCommand = mappings->findCommandForKeyPress (entryWindow.lastPress);
  47579. if (previousCommand != 0)
  47580. {
  47581. if (! AlertWindow::showOkCancelBox (AlertWindow::WarningIcon,
  47582. TRANS("Change key-mapping"),
  47583. TRANS("This key is already assigned to the command \"")
  47584. + mappings->getCommandManager()->getNameOfCommand (previousCommand)
  47585. + TRANS("\"\n\nDo you want to re-assign it to this new command instead?"),
  47586. TRANS("re-assign"),
  47587. TRANS("cancel")))
  47588. {
  47589. return;
  47590. }
  47591. }
  47592. mappings->removeKeyPress (entryWindow.lastPress);
  47593. if (index >= 0)
  47594. mappings->removeKeyPress (commandID, index);
  47595. mappings->addKeyPress (commandID, entryWindow.lastPress, index);
  47596. }
  47597. }
  47598. }
  47599. bool KeyMappingEditorComponent::shouldCommandBeIncluded (const CommandID commandID)
  47600. {
  47601. const ApplicationCommandInfo* const ci = mappings->getCommandManager()->getCommandForID (commandID);
  47602. return (ci != 0) && ((ci->flags & ApplicationCommandInfo::hiddenFromKeyEditor) == 0);
  47603. }
  47604. bool KeyMappingEditorComponent::isCommandReadOnly (const CommandID commandID)
  47605. {
  47606. const ApplicationCommandInfo* const ci = mappings->getCommandManager()->getCommandForID (commandID);
  47607. return (ci != 0) && ((ci->flags & ApplicationCommandInfo::readOnlyInKeyEditor) != 0);
  47608. }
  47609. const String KeyMappingEditorComponent::getDescriptionForKeyPress (const KeyPress& key)
  47610. {
  47611. return key.getTextDescription();
  47612. }
  47613. END_JUCE_NAMESPACE
  47614. /*** End of inlined file: juce_KeyMappingEditorComponent.cpp ***/
  47615. /*** Start of inlined file: juce_KeyPress.cpp ***/
  47616. BEGIN_JUCE_NAMESPACE
  47617. KeyPress::KeyPress() throw()
  47618. : keyCode (0),
  47619. mods (0),
  47620. textCharacter (0)
  47621. {
  47622. }
  47623. KeyPress::KeyPress (const int keyCode_,
  47624. const ModifierKeys& mods_,
  47625. const juce_wchar textCharacter_) throw()
  47626. : keyCode (keyCode_),
  47627. mods (mods_),
  47628. textCharacter (textCharacter_)
  47629. {
  47630. }
  47631. KeyPress::KeyPress (const int keyCode_) throw()
  47632. : keyCode (keyCode_),
  47633. textCharacter (0)
  47634. {
  47635. }
  47636. KeyPress::KeyPress (const KeyPress& other) throw()
  47637. : keyCode (other.keyCode),
  47638. mods (other.mods),
  47639. textCharacter (other.textCharacter)
  47640. {
  47641. }
  47642. KeyPress& KeyPress::operator= (const KeyPress& other) throw()
  47643. {
  47644. keyCode = other.keyCode;
  47645. mods = other.mods;
  47646. textCharacter = other.textCharacter;
  47647. return *this;
  47648. }
  47649. bool KeyPress::operator== (const KeyPress& other) const throw()
  47650. {
  47651. return mods.getRawFlags() == other.mods.getRawFlags()
  47652. && (textCharacter == other.textCharacter
  47653. || textCharacter == 0
  47654. || other.textCharacter == 0)
  47655. && (keyCode == other.keyCode
  47656. || (keyCode < 256
  47657. && other.keyCode < 256
  47658. && CharacterFunctions::toLowerCase ((tchar) keyCode)
  47659. == CharacterFunctions::toLowerCase ((tchar) other.keyCode)));
  47660. }
  47661. bool KeyPress::operator!= (const KeyPress& other) const throw()
  47662. {
  47663. return ! operator== (other);
  47664. }
  47665. bool KeyPress::isCurrentlyDown() const throw()
  47666. {
  47667. return isKeyCurrentlyDown (keyCode)
  47668. && (ModifierKeys::getCurrentModifiers().getRawFlags() & ModifierKeys::allKeyboardModifiers)
  47669. == (mods.getRawFlags() & ModifierKeys::allKeyboardModifiers);
  47670. }
  47671. struct KeyNameAndCode
  47672. {
  47673. const char* name;
  47674. int code;
  47675. };
  47676. static const KeyNameAndCode keyNameTranslations[] =
  47677. {
  47678. { "spacebar", KeyPress::spaceKey },
  47679. { "return", KeyPress::returnKey },
  47680. { "escape", KeyPress::escapeKey },
  47681. { "backspace", KeyPress::backspaceKey },
  47682. { "cursor left", KeyPress::leftKey },
  47683. { "cursor right", KeyPress::rightKey },
  47684. { "cursor up", KeyPress::upKey },
  47685. { "cursor down", KeyPress::downKey },
  47686. { "page up", KeyPress::pageUpKey },
  47687. { "page down", KeyPress::pageDownKey },
  47688. { "home", KeyPress::homeKey },
  47689. { "end", KeyPress::endKey },
  47690. { "delete", KeyPress::deleteKey },
  47691. { "insert", KeyPress::insertKey },
  47692. { "tab", KeyPress::tabKey },
  47693. { "play", KeyPress::playKey },
  47694. { "stop", KeyPress::stopKey },
  47695. { "fast forward", KeyPress::fastForwardKey },
  47696. { "rewind", KeyPress::rewindKey }
  47697. };
  47698. static const tchar* const numberPadPrefix = T("numpad ");
  47699. const KeyPress KeyPress::createFromDescription (const String& desc) throw()
  47700. {
  47701. int modifiers = 0;
  47702. if (desc.containsWholeWordIgnoreCase (T("ctrl"))
  47703. || desc.containsWholeWordIgnoreCase (T("control"))
  47704. || desc.containsWholeWordIgnoreCase (T("ctl")))
  47705. modifiers |= ModifierKeys::ctrlModifier;
  47706. if (desc.containsWholeWordIgnoreCase (T("shift"))
  47707. || desc.containsWholeWordIgnoreCase (T("shft")))
  47708. modifiers |= ModifierKeys::shiftModifier;
  47709. if (desc.containsWholeWordIgnoreCase (T("alt"))
  47710. || desc.containsWholeWordIgnoreCase (T("option")))
  47711. modifiers |= ModifierKeys::altModifier;
  47712. if (desc.containsWholeWordIgnoreCase (T("command"))
  47713. || desc.containsWholeWordIgnoreCase (T("cmd")))
  47714. modifiers |= ModifierKeys::commandModifier;
  47715. int key = 0;
  47716. for (int i = 0; i < numElementsInArray (keyNameTranslations); ++i)
  47717. {
  47718. if (desc.containsWholeWordIgnoreCase (String (keyNameTranslations[i].name)))
  47719. {
  47720. key = keyNameTranslations[i].code;
  47721. break;
  47722. }
  47723. }
  47724. if (key == 0)
  47725. {
  47726. // see if it's a numpad key..
  47727. if (desc.containsIgnoreCase (numberPadPrefix))
  47728. {
  47729. const tchar lastChar = desc.trimEnd().getLastCharacter();
  47730. if (lastChar >= T('0') && lastChar <= T('9'))
  47731. key = numberPad0 + lastChar - T('0');
  47732. else if (lastChar == T('+'))
  47733. key = numberPadAdd;
  47734. else if (lastChar == T('-'))
  47735. key = numberPadSubtract;
  47736. else if (lastChar == T('*'))
  47737. key = numberPadMultiply;
  47738. else if (lastChar == T('/'))
  47739. key = numberPadDivide;
  47740. else if (lastChar == T('.'))
  47741. key = numberPadDecimalPoint;
  47742. else if (lastChar == T('='))
  47743. key = numberPadEquals;
  47744. else if (desc.endsWith (T("separator")))
  47745. key = numberPadSeparator;
  47746. else if (desc.endsWith (T("delete")))
  47747. key = numberPadDelete;
  47748. }
  47749. if (key == 0)
  47750. {
  47751. // see if it's a function key..
  47752. for (int i = 1; i <= 12; ++i)
  47753. if (desc.containsWholeWordIgnoreCase (T("f") + String (i)))
  47754. key = F1Key + i - 1;
  47755. if (key == 0)
  47756. {
  47757. // give up and use the hex code..
  47758. const int hexCode = desc.fromFirstOccurrenceOf (T("#"), false, false)
  47759. .toLowerCase()
  47760. .retainCharacters (T("0123456789abcdef"))
  47761. .getHexValue32();
  47762. if (hexCode > 0)
  47763. key = hexCode;
  47764. else
  47765. key = CharacterFunctions::toUpperCase (desc.getLastCharacter());
  47766. }
  47767. }
  47768. }
  47769. return KeyPress (key, ModifierKeys (modifiers), 0);
  47770. }
  47771. const String KeyPress::getTextDescription() const throw()
  47772. {
  47773. String desc;
  47774. if (keyCode > 0)
  47775. {
  47776. // some keyboard layouts use a shift-key to get the slash, but in those cases, we
  47777. // want to store it as being a slash, not shift+whatever.
  47778. if (textCharacter == T('/'))
  47779. return "/";
  47780. if (mods.isCtrlDown())
  47781. desc << "ctrl + ";
  47782. if (mods.isShiftDown())
  47783. desc << "shift + ";
  47784. #if JUCE_MAC
  47785. // only do this on the mac, because on Windows ctrl and command are the same,
  47786. // and this would get confusing
  47787. if (mods.isCommandDown())
  47788. desc << "command + ";
  47789. if (mods.isAltDown())
  47790. desc << "option + ";
  47791. #else
  47792. if (mods.isAltDown())
  47793. desc << "alt + ";
  47794. #endif
  47795. for (int i = 0; i < numElementsInArray (keyNameTranslations); ++i)
  47796. if (keyCode == keyNameTranslations[i].code)
  47797. return desc + keyNameTranslations[i].name;
  47798. if (keyCode >= F1Key && keyCode <= F16Key)
  47799. desc << 'F' << (1 + keyCode - F1Key);
  47800. else if (keyCode >= numberPad0 && keyCode <= numberPad9)
  47801. desc << numberPadPrefix << (keyCode - numberPad0);
  47802. else if (keyCode >= 33 && keyCode < 176)
  47803. desc += CharacterFunctions::toUpperCase ((tchar) keyCode);
  47804. else if (keyCode == numberPadAdd)
  47805. desc << numberPadPrefix << '+';
  47806. else if (keyCode == numberPadSubtract)
  47807. desc << numberPadPrefix << '-';
  47808. else if (keyCode == numberPadMultiply)
  47809. desc << numberPadPrefix << '*';
  47810. else if (keyCode == numberPadDivide)
  47811. desc << numberPadPrefix << '/';
  47812. else if (keyCode == numberPadSeparator)
  47813. desc << numberPadPrefix << "separator";
  47814. else if (keyCode == numberPadDecimalPoint)
  47815. desc << numberPadPrefix << '.';
  47816. else if (keyCode == numberPadDelete)
  47817. desc << numberPadPrefix << "delete";
  47818. else
  47819. desc << '#' << String::toHexString (keyCode);
  47820. }
  47821. return desc;
  47822. }
  47823. END_JUCE_NAMESPACE
  47824. /*** End of inlined file: juce_KeyPress.cpp ***/
  47825. /*** Start of inlined file: juce_KeyPressMappingSet.cpp ***/
  47826. BEGIN_JUCE_NAMESPACE
  47827. KeyPressMappingSet::KeyPressMappingSet (ApplicationCommandManager* const commandManager_) throw()
  47828. : commandManager (commandManager_)
  47829. {
  47830. // A manager is needed to get the descriptions of commands, and will be called when
  47831. // a command is invoked. So you can't leave this null..
  47832. jassert (commandManager_ != 0);
  47833. Desktop::getInstance().addFocusChangeListener (this);
  47834. }
  47835. KeyPressMappingSet::KeyPressMappingSet (const KeyPressMappingSet& other) throw()
  47836. : commandManager (other.commandManager)
  47837. {
  47838. Desktop::getInstance().addFocusChangeListener (this);
  47839. }
  47840. KeyPressMappingSet::~KeyPressMappingSet()
  47841. {
  47842. Desktop::getInstance().removeFocusChangeListener (this);
  47843. }
  47844. const Array <KeyPress> KeyPressMappingSet::getKeyPressesAssignedToCommand (const CommandID commandID) const throw()
  47845. {
  47846. for (int i = 0; i < mappings.size(); ++i)
  47847. if (mappings.getUnchecked(i)->commandID == commandID)
  47848. return mappings.getUnchecked (i)->keypresses;
  47849. return Array <KeyPress> ();
  47850. }
  47851. void KeyPressMappingSet::addKeyPress (const CommandID commandID,
  47852. const KeyPress& newKeyPress,
  47853. int insertIndex) throw()
  47854. {
  47855. // If you specify an upper-case letter but no shift key, how is the user supposed to press it!?
  47856. // Stick to lower-case letters when defining a keypress, to avoid ambiguity.
  47857. jassert (! (CharacterFunctions::isUpperCase (newKeyPress.getTextCharacter())
  47858. && ! newKeyPress.getModifiers().isShiftDown()));
  47859. if (findCommandForKeyPress (newKeyPress) != commandID)
  47860. {
  47861. removeKeyPress (newKeyPress);
  47862. if (newKeyPress.isValid())
  47863. {
  47864. for (int i = mappings.size(); --i >= 0;)
  47865. {
  47866. if (mappings.getUnchecked(i)->commandID == commandID)
  47867. {
  47868. mappings.getUnchecked(i)->keypresses.insert (insertIndex, newKeyPress);
  47869. sendChangeMessage (this);
  47870. return;
  47871. }
  47872. }
  47873. const ApplicationCommandInfo* const ci = commandManager->getCommandForID (commandID);
  47874. if (ci != 0)
  47875. {
  47876. CommandMapping* const cm = new CommandMapping();
  47877. cm->commandID = commandID;
  47878. cm->keypresses.add (newKeyPress);
  47879. cm->wantsKeyUpDownCallbacks = (ci->flags & ApplicationCommandInfo::wantsKeyUpDownCallbacks) != 0;
  47880. mappings.add (cm);
  47881. sendChangeMessage (this);
  47882. }
  47883. }
  47884. }
  47885. }
  47886. void KeyPressMappingSet::resetToDefaultMappings() throw()
  47887. {
  47888. mappings.clear();
  47889. for (int i = 0; i < commandManager->getNumCommands(); ++i)
  47890. {
  47891. const ApplicationCommandInfo* const ci = commandManager->getCommandForIndex (i);
  47892. for (int j = 0; j < ci->defaultKeypresses.size(); ++j)
  47893. {
  47894. addKeyPress (ci->commandID,
  47895. ci->defaultKeypresses.getReference (j));
  47896. }
  47897. }
  47898. sendChangeMessage (this);
  47899. }
  47900. void KeyPressMappingSet::resetToDefaultMapping (const CommandID commandID) throw()
  47901. {
  47902. clearAllKeyPresses (commandID);
  47903. const ApplicationCommandInfo* const ci = commandManager->getCommandForID (commandID);
  47904. for (int j = 0; j < ci->defaultKeypresses.size(); ++j)
  47905. {
  47906. addKeyPress (ci->commandID,
  47907. ci->defaultKeypresses.getReference (j));
  47908. }
  47909. }
  47910. void KeyPressMappingSet::clearAllKeyPresses() throw()
  47911. {
  47912. if (mappings.size() > 0)
  47913. {
  47914. sendChangeMessage (this);
  47915. mappings.clear();
  47916. }
  47917. }
  47918. void KeyPressMappingSet::clearAllKeyPresses (const CommandID commandID) throw()
  47919. {
  47920. for (int i = mappings.size(); --i >= 0;)
  47921. {
  47922. if (mappings.getUnchecked(i)->commandID == commandID)
  47923. {
  47924. mappings.remove (i);
  47925. sendChangeMessage (this);
  47926. }
  47927. }
  47928. }
  47929. void KeyPressMappingSet::removeKeyPress (const KeyPress& keypress) throw()
  47930. {
  47931. if (keypress.isValid())
  47932. {
  47933. for (int i = mappings.size(); --i >= 0;)
  47934. {
  47935. CommandMapping* const cm = mappings.getUnchecked(i);
  47936. for (int j = cm->keypresses.size(); --j >= 0;)
  47937. {
  47938. if (keypress == cm->keypresses [j])
  47939. {
  47940. cm->keypresses.remove (j);
  47941. sendChangeMessage (this);
  47942. }
  47943. }
  47944. }
  47945. }
  47946. }
  47947. void KeyPressMappingSet::removeKeyPress (const CommandID commandID,
  47948. const int keyPressIndex) throw()
  47949. {
  47950. for (int i = mappings.size(); --i >= 0;)
  47951. {
  47952. if (mappings.getUnchecked(i)->commandID == commandID)
  47953. {
  47954. mappings.getUnchecked(i)->keypresses.remove (keyPressIndex);
  47955. sendChangeMessage (this);
  47956. break;
  47957. }
  47958. }
  47959. }
  47960. CommandID KeyPressMappingSet::findCommandForKeyPress (const KeyPress& keyPress) const throw()
  47961. {
  47962. for (int i = 0; i < mappings.size(); ++i)
  47963. if (mappings.getUnchecked(i)->keypresses.contains (keyPress))
  47964. return mappings.getUnchecked(i)->commandID;
  47965. return 0;
  47966. }
  47967. bool KeyPressMappingSet::containsMapping (const CommandID commandID,
  47968. const KeyPress& keyPress) const throw()
  47969. {
  47970. for (int i = mappings.size(); --i >= 0;)
  47971. if (mappings.getUnchecked(i)->commandID == commandID)
  47972. return mappings.getUnchecked(i)->keypresses.contains (keyPress);
  47973. return false;
  47974. }
  47975. void KeyPressMappingSet::invokeCommand (const CommandID commandID,
  47976. const KeyPress& key,
  47977. const bool isKeyDown,
  47978. const int millisecsSinceKeyPressed,
  47979. Component* const originatingComponent) const
  47980. {
  47981. ApplicationCommandTarget::InvocationInfo info (commandID);
  47982. info.invocationMethod = ApplicationCommandTarget::InvocationInfo::fromKeyPress;
  47983. info.isKeyDown = isKeyDown;
  47984. info.keyPress = key;
  47985. info.millisecsSinceKeyPressed = millisecsSinceKeyPressed;
  47986. info.originatingComponent = originatingComponent;
  47987. commandManager->invoke (info, false);
  47988. }
  47989. bool KeyPressMappingSet::restoreFromXml (const XmlElement& xmlVersion)
  47990. {
  47991. if (xmlVersion.hasTagName (T("KEYMAPPINGS")))
  47992. {
  47993. if (xmlVersion.getBoolAttribute (T("basedOnDefaults"), true))
  47994. {
  47995. // if the XML was created as a set of differences from the default mappings,
  47996. // (i.e. by calling createXml (true)), then we need to first restore the defaults.
  47997. resetToDefaultMappings();
  47998. }
  47999. else
  48000. {
  48001. // if the XML was created calling createXml (false), then we need to clear all
  48002. // the keys and treat the xml as describing the entire set of mappings.
  48003. clearAllKeyPresses();
  48004. }
  48005. forEachXmlChildElement (xmlVersion, map)
  48006. {
  48007. const CommandID commandId = map->getStringAttribute (T("commandId")).getHexValue32();
  48008. if (commandId != 0)
  48009. {
  48010. const KeyPress key (KeyPress::createFromDescription (map->getStringAttribute (T("key"))));
  48011. if (map->hasTagName (T("MAPPING")))
  48012. {
  48013. addKeyPress (commandId, key);
  48014. }
  48015. else if (map->hasTagName (T("UNMAPPING")))
  48016. {
  48017. if (containsMapping (commandId, key))
  48018. removeKeyPress (key);
  48019. }
  48020. }
  48021. }
  48022. return true;
  48023. }
  48024. return false;
  48025. }
  48026. XmlElement* KeyPressMappingSet::createXml (const bool saveDifferencesFromDefaultSet) const
  48027. {
  48028. ScopedPointer <KeyPressMappingSet> defaultSet;
  48029. if (saveDifferencesFromDefaultSet)
  48030. {
  48031. defaultSet = new KeyPressMappingSet (commandManager);
  48032. defaultSet->resetToDefaultMappings();
  48033. }
  48034. XmlElement* const doc = new XmlElement (T("KEYMAPPINGS"));
  48035. doc->setAttribute (T("basedOnDefaults"), saveDifferencesFromDefaultSet);
  48036. int i;
  48037. for (i = 0; i < mappings.size(); ++i)
  48038. {
  48039. const CommandMapping* const cm = mappings.getUnchecked(i);
  48040. for (int j = 0; j < cm->keypresses.size(); ++j)
  48041. {
  48042. if (defaultSet == 0
  48043. || ! defaultSet->containsMapping (cm->commandID, cm->keypresses.getReference (j)))
  48044. {
  48045. XmlElement* const map = doc->createNewChildElement ("MAPPING");
  48046. map->setAttribute (T("commandId"), String::toHexString ((int) cm->commandID));
  48047. map->setAttribute (T("description"), commandManager->getDescriptionOfCommand (cm->commandID));
  48048. map->setAttribute (T("key"), cm->keypresses.getReference (j).getTextDescription());
  48049. }
  48050. }
  48051. }
  48052. if (defaultSet != 0)
  48053. {
  48054. for (i = 0; i < defaultSet->mappings.size(); ++i)
  48055. {
  48056. const CommandMapping* const cm = defaultSet->mappings.getUnchecked(i);
  48057. for (int j = 0; j < cm->keypresses.size(); ++j)
  48058. {
  48059. if (! containsMapping (cm->commandID, cm->keypresses.getReference (j)))
  48060. {
  48061. XmlElement* const map = doc->createNewChildElement ("UNMAPPING");
  48062. map->setAttribute (T("commandId"), String::toHexString ((int) cm->commandID));
  48063. map->setAttribute (T("description"), commandManager->getDescriptionOfCommand (cm->commandID));
  48064. map->setAttribute (T("key"), cm->keypresses.getReference (j).getTextDescription());
  48065. }
  48066. }
  48067. }
  48068. }
  48069. return doc;
  48070. }
  48071. bool KeyPressMappingSet::keyPressed (const KeyPress& key,
  48072. Component* originatingComponent)
  48073. {
  48074. bool used = false;
  48075. const CommandID commandID = findCommandForKeyPress (key);
  48076. const ApplicationCommandInfo* const ci = commandManager->getCommandForID (commandID);
  48077. if (ci != 0
  48078. && (ci->flags & ApplicationCommandInfo::wantsKeyUpDownCallbacks) == 0)
  48079. {
  48080. ApplicationCommandInfo info (0);
  48081. if (commandManager->getTargetForCommand (commandID, info) != 0
  48082. && (info.flags & ApplicationCommandInfo::isDisabled) == 0)
  48083. {
  48084. invokeCommand (commandID, key, true, 0, originatingComponent);
  48085. used = true;
  48086. }
  48087. else
  48088. {
  48089. if (originatingComponent != 0)
  48090. originatingComponent->getLookAndFeel().playAlertSound();
  48091. }
  48092. }
  48093. return used;
  48094. }
  48095. bool KeyPressMappingSet::keyStateChanged (const bool /*isKeyDown*/, Component* originatingComponent)
  48096. {
  48097. bool used = false;
  48098. const uint32 now = Time::getMillisecondCounter();
  48099. for (int i = mappings.size(); --i >= 0;)
  48100. {
  48101. CommandMapping* const cm = mappings.getUnchecked(i);
  48102. if (cm->wantsKeyUpDownCallbacks)
  48103. {
  48104. for (int j = cm->keypresses.size(); --j >= 0;)
  48105. {
  48106. const KeyPress key (cm->keypresses.getReference (j));
  48107. const bool isDown = key.isCurrentlyDown();
  48108. int keyPressEntryIndex = 0;
  48109. bool wasDown = false;
  48110. for (int k = keysDown.size(); --k >= 0;)
  48111. {
  48112. if (key == keysDown.getUnchecked(k)->key)
  48113. {
  48114. keyPressEntryIndex = k;
  48115. wasDown = true;
  48116. used = true;
  48117. break;
  48118. }
  48119. }
  48120. if (isDown != wasDown)
  48121. {
  48122. int millisecs = 0;
  48123. if (isDown)
  48124. {
  48125. KeyPressTime* const k = new KeyPressTime();
  48126. k->key = key;
  48127. k->timeWhenPressed = now;
  48128. keysDown.add (k);
  48129. }
  48130. else
  48131. {
  48132. const uint32 pressTime = keysDown.getUnchecked (keyPressEntryIndex)->timeWhenPressed;
  48133. if (now > pressTime)
  48134. millisecs = now - pressTime;
  48135. keysDown.remove (keyPressEntryIndex);
  48136. }
  48137. invokeCommand (cm->commandID, key, isDown, millisecs, originatingComponent);
  48138. used = true;
  48139. }
  48140. }
  48141. }
  48142. }
  48143. return used;
  48144. }
  48145. void KeyPressMappingSet::globalFocusChanged (Component* focusedComponent)
  48146. {
  48147. if (focusedComponent != 0)
  48148. focusedComponent->keyStateChanged (false);
  48149. }
  48150. END_JUCE_NAMESPACE
  48151. /*** End of inlined file: juce_KeyPressMappingSet.cpp ***/
  48152. /*** Start of inlined file: juce_ModifierKeys.cpp ***/
  48153. BEGIN_JUCE_NAMESPACE
  48154. ModifierKeys::ModifierKeys (const int flags_) throw()
  48155. : flags (flags_)
  48156. {
  48157. }
  48158. ModifierKeys::ModifierKeys (const ModifierKeys& other) throw()
  48159. : flags (other.flags)
  48160. {
  48161. }
  48162. ModifierKeys& ModifierKeys::operator= (const ModifierKeys& other) throw()
  48163. {
  48164. flags = other.flags;
  48165. return *this;
  48166. }
  48167. ModifierKeys ModifierKeys::currentModifiers;
  48168. const ModifierKeys ModifierKeys::getCurrentModifiers() throw()
  48169. {
  48170. return currentModifiers;
  48171. }
  48172. int ModifierKeys::getNumMouseButtonsDown() const throw()
  48173. {
  48174. int num = 0;
  48175. if (isLeftButtonDown()) ++num;
  48176. if (isRightButtonDown()) ++num;
  48177. if (isMiddleButtonDown()) ++num;
  48178. return num;
  48179. }
  48180. END_JUCE_NAMESPACE
  48181. /*** End of inlined file: juce_ModifierKeys.cpp ***/
  48182. /*** Start of inlined file: juce_ComponentAnimator.cpp ***/
  48183. BEGIN_JUCE_NAMESPACE
  48184. struct AnimationTask
  48185. {
  48186. AnimationTask (Component* const comp)
  48187. : component (comp)
  48188. {
  48189. }
  48190. Component::SafePointer<Component> component;
  48191. Rectangle<int> destination;
  48192. int msElapsed, msTotal;
  48193. double startSpeed, midSpeed, endSpeed, lastProgress;
  48194. double left, top, right, bottom;
  48195. bool useTimeslice (const int elapsed)
  48196. {
  48197. if (component == 0)
  48198. return false;
  48199. msElapsed += elapsed;
  48200. double newProgress = msElapsed / (double) msTotal;
  48201. if (newProgress >= 0 && newProgress < 1.0)
  48202. {
  48203. newProgress = timeToDistance (newProgress);
  48204. const double delta = (newProgress - lastProgress) / (1.0 - lastProgress);
  48205. jassert (newProgress >= lastProgress);
  48206. lastProgress = newProgress;
  48207. left += (destination.getX() - left) * delta;
  48208. top += (destination.getY() - top) * delta;
  48209. right += (destination.getRight() - right) * delta;
  48210. bottom += (destination.getBottom() - bottom) * delta;
  48211. if (delta < 1.0)
  48212. {
  48213. const Rectangle<int> newBounds (roundToInt (left),
  48214. roundToInt (top),
  48215. roundToInt (right - left),
  48216. roundToInt (bottom - top));
  48217. if (newBounds != destination)
  48218. {
  48219. component->setBounds (newBounds);
  48220. return true;
  48221. }
  48222. }
  48223. }
  48224. component->setBounds (destination);
  48225. return false;
  48226. }
  48227. void moveToFinalDestination()
  48228. {
  48229. if (component != 0)
  48230. component->setBounds (destination);
  48231. }
  48232. private:
  48233. inline double timeToDistance (const double time) const
  48234. {
  48235. return (time < 0.5) ? time * (startSpeed + time * (midSpeed - startSpeed))
  48236. : 0.5 * (startSpeed + 0.5 * (midSpeed - startSpeed))
  48237. + (time - 0.5) * (midSpeed + (time - 0.5) * (endSpeed - midSpeed));
  48238. }
  48239. };
  48240. ComponentAnimator::ComponentAnimator()
  48241. : lastTime (0)
  48242. {
  48243. }
  48244. ComponentAnimator::~ComponentAnimator()
  48245. {
  48246. cancelAllAnimations (false);
  48247. jassert (tasks.size() == 0);
  48248. }
  48249. void* ComponentAnimator::findTaskFor (Component* const component) const
  48250. {
  48251. for (int i = tasks.size(); --i >= 0;)
  48252. if (component == ((AnimationTask*) tasks.getUnchecked(i))->component.getComponent())
  48253. return tasks.getUnchecked(i);
  48254. return 0;
  48255. }
  48256. void ComponentAnimator::animateComponent (Component* const component,
  48257. const Rectangle<int>& finalPosition,
  48258. const int millisecondsToSpendMoving,
  48259. const double startSpeed,
  48260. const double endSpeed)
  48261. {
  48262. if (component != 0)
  48263. {
  48264. AnimationTask* at = (AnimationTask*) findTaskFor (component);
  48265. if (at == 0)
  48266. {
  48267. at = new AnimationTask (component);
  48268. tasks.add (at);
  48269. sendChangeMessage (this);
  48270. }
  48271. at->msElapsed = 0;
  48272. at->lastProgress = 0;
  48273. at->msTotal = jmax (1, millisecondsToSpendMoving);
  48274. at->destination = finalPosition;
  48275. // the speeds must be 0 or greater!
  48276. jassert (startSpeed >= 0 && endSpeed >= 0)
  48277. const double invTotalDistance = 4.0 / (startSpeed + endSpeed + 2.0);
  48278. at->startSpeed = jmax (0.0, startSpeed * invTotalDistance);
  48279. at->midSpeed = invTotalDistance;
  48280. at->endSpeed = jmax (0.0, endSpeed * invTotalDistance);
  48281. at->left = component->getX();
  48282. at->top = component->getY();
  48283. at->right = component->getRight();
  48284. at->bottom = component->getBottom();
  48285. if (! isTimerRunning())
  48286. {
  48287. lastTime = Time::getMillisecondCounter();
  48288. startTimer (1000 / 50);
  48289. }
  48290. }
  48291. }
  48292. void ComponentAnimator::cancelAllAnimations (const bool moveComponentsToTheirFinalPositions)
  48293. {
  48294. for (int i = tasks.size(); --i >= 0;)
  48295. {
  48296. AnimationTask* const at = (AnimationTask*) tasks.getUnchecked(i);
  48297. if (moveComponentsToTheirFinalPositions)
  48298. at->moveToFinalDestination();
  48299. delete at;
  48300. tasks.remove (i);
  48301. sendChangeMessage (this);
  48302. }
  48303. }
  48304. void ComponentAnimator::cancelAnimation (Component* const component,
  48305. const bool moveComponentToItsFinalPosition)
  48306. {
  48307. AnimationTask* const at = (AnimationTask*) findTaskFor (component);
  48308. if (at != 0)
  48309. {
  48310. if (moveComponentToItsFinalPosition)
  48311. at->moveToFinalDestination();
  48312. tasks.removeValue (at);
  48313. delete at;
  48314. sendChangeMessage (this);
  48315. }
  48316. }
  48317. const Rectangle<int> ComponentAnimator::getComponentDestination (Component* const component)
  48318. {
  48319. AnimationTask* const at = (AnimationTask*) findTaskFor (component);
  48320. if (at != 0)
  48321. return at->destination;
  48322. else if (component != 0)
  48323. return component->getBounds();
  48324. return Rectangle<int>();
  48325. }
  48326. bool ComponentAnimator::isAnimating (Component* component) const
  48327. {
  48328. return findTaskFor (component) != 0;
  48329. }
  48330. void ComponentAnimator::timerCallback()
  48331. {
  48332. const uint32 timeNow = Time::getMillisecondCounter();
  48333. if (lastTime == 0 || lastTime == timeNow)
  48334. lastTime = timeNow;
  48335. const int elapsed = timeNow - lastTime;
  48336. for (int i = tasks.size(); --i >= 0;)
  48337. {
  48338. AnimationTask* const at = (AnimationTask*) tasks.getUnchecked(i);
  48339. if (! at->useTimeslice (elapsed))
  48340. {
  48341. tasks.remove (i);
  48342. delete at;
  48343. sendChangeMessage (this);
  48344. }
  48345. }
  48346. lastTime = timeNow;
  48347. if (tasks.size() == 0)
  48348. stopTimer();
  48349. }
  48350. END_JUCE_NAMESPACE
  48351. /*** End of inlined file: juce_ComponentAnimator.cpp ***/
  48352. /*** Start of inlined file: juce_ComponentBoundsConstrainer.cpp ***/
  48353. BEGIN_JUCE_NAMESPACE
  48354. ComponentBoundsConstrainer::ComponentBoundsConstrainer() throw()
  48355. : minW (0),
  48356. maxW (0x3fffffff),
  48357. minH (0),
  48358. maxH (0x3fffffff),
  48359. minOffTop (0),
  48360. minOffLeft (0),
  48361. minOffBottom (0),
  48362. minOffRight (0),
  48363. aspectRatio (0.0)
  48364. {
  48365. }
  48366. ComponentBoundsConstrainer::~ComponentBoundsConstrainer()
  48367. {
  48368. }
  48369. void ComponentBoundsConstrainer::setMinimumWidth (const int minimumWidth) throw()
  48370. {
  48371. minW = minimumWidth;
  48372. }
  48373. void ComponentBoundsConstrainer::setMaximumWidth (const int maximumWidth) throw()
  48374. {
  48375. maxW = maximumWidth;
  48376. }
  48377. void ComponentBoundsConstrainer::setMinimumHeight (const int minimumHeight) throw()
  48378. {
  48379. minH = minimumHeight;
  48380. }
  48381. void ComponentBoundsConstrainer::setMaximumHeight (const int maximumHeight) throw()
  48382. {
  48383. maxH = maximumHeight;
  48384. }
  48385. void ComponentBoundsConstrainer::setMinimumSize (const int minimumWidth, const int minimumHeight) throw()
  48386. {
  48387. jassert (maxW >= minimumWidth);
  48388. jassert (maxH >= minimumHeight);
  48389. jassert (minimumWidth > 0 && minimumHeight > 0);
  48390. minW = minimumWidth;
  48391. minH = minimumHeight;
  48392. if (minW > maxW)
  48393. maxW = minW;
  48394. if (minH > maxH)
  48395. maxH = minH;
  48396. }
  48397. void ComponentBoundsConstrainer::setMaximumSize (const int maximumWidth, const int maximumHeight) throw()
  48398. {
  48399. jassert (maximumWidth >= minW);
  48400. jassert (maximumHeight >= minH);
  48401. jassert (maximumWidth > 0 && maximumHeight > 0);
  48402. maxW = jmax (minW, maximumWidth);
  48403. maxH = jmax (minH, maximumHeight);
  48404. }
  48405. void ComponentBoundsConstrainer::setSizeLimits (const int minimumWidth,
  48406. const int minimumHeight,
  48407. const int maximumWidth,
  48408. const int maximumHeight) throw()
  48409. {
  48410. jassert (maximumWidth >= minimumWidth);
  48411. jassert (maximumHeight >= minimumHeight);
  48412. jassert (maximumWidth > 0 && maximumHeight > 0);
  48413. jassert (minimumWidth > 0 && minimumHeight > 0);
  48414. minW = jmax (0, minimumWidth);
  48415. minH = jmax (0, minimumHeight);
  48416. maxW = jmax (minW, maximumWidth);
  48417. maxH = jmax (minH, maximumHeight);
  48418. }
  48419. void ComponentBoundsConstrainer::setMinimumOnscreenAmounts (const int minimumWhenOffTheTop,
  48420. const int minimumWhenOffTheLeft,
  48421. const int minimumWhenOffTheBottom,
  48422. const int minimumWhenOffTheRight) throw()
  48423. {
  48424. minOffTop = minimumWhenOffTheTop;
  48425. minOffLeft = minimumWhenOffTheLeft;
  48426. minOffBottom = minimumWhenOffTheBottom;
  48427. minOffRight = minimumWhenOffTheRight;
  48428. }
  48429. void ComponentBoundsConstrainer::setFixedAspectRatio (const double widthOverHeight) throw()
  48430. {
  48431. aspectRatio = jmax (0.0, widthOverHeight);
  48432. }
  48433. double ComponentBoundsConstrainer::getFixedAspectRatio() const throw()
  48434. {
  48435. return aspectRatio;
  48436. }
  48437. void ComponentBoundsConstrainer::setBoundsForComponent (Component* const component,
  48438. const Rectangle<int>& targetBounds,
  48439. const bool isStretchingTop,
  48440. const bool isStretchingLeft,
  48441. const bool isStretchingBottom,
  48442. const bool isStretchingRight)
  48443. {
  48444. jassert (component != 0);
  48445. Rectangle<int> limits, bounds (targetBounds);
  48446. BorderSize border;
  48447. Component* const parent = component->getParentComponent();
  48448. if (parent == 0)
  48449. {
  48450. ComponentPeer* peer = component->getPeer();
  48451. if (peer != 0)
  48452. border = peer->getFrameSize();
  48453. limits = Desktop::getInstance().getMonitorAreaContaining (bounds.getCentre());
  48454. }
  48455. else
  48456. {
  48457. limits.setSize (parent->getWidth(), parent->getHeight());
  48458. }
  48459. border.addTo (bounds);
  48460. checkBounds (bounds,
  48461. border.addedTo (component->getBounds()), limits,
  48462. isStretchingTop, isStretchingLeft,
  48463. isStretchingBottom, isStretchingRight);
  48464. border.subtractFrom (bounds);
  48465. applyBoundsToComponent (component, bounds);
  48466. }
  48467. void ComponentBoundsConstrainer::checkComponentBounds (Component* component)
  48468. {
  48469. setBoundsForComponent (component, component->getBounds(),
  48470. false, false, false, false);
  48471. }
  48472. void ComponentBoundsConstrainer::applyBoundsToComponent (Component* component,
  48473. const Rectangle<int>& bounds)
  48474. {
  48475. component->setBounds (bounds);
  48476. }
  48477. void ComponentBoundsConstrainer::resizeStart()
  48478. {
  48479. }
  48480. void ComponentBoundsConstrainer::resizeEnd()
  48481. {
  48482. }
  48483. void ComponentBoundsConstrainer::checkBounds (Rectangle<int>& bounds,
  48484. const Rectangle<int>& old,
  48485. const Rectangle<int>& limits,
  48486. const bool isStretchingTop,
  48487. const bool isStretchingLeft,
  48488. const bool isStretchingBottom,
  48489. const bool isStretchingRight)
  48490. {
  48491. int x = bounds.getX();
  48492. int y = bounds.getY();
  48493. int w = bounds.getWidth();
  48494. int h = bounds.getHeight();
  48495. // constrain the size if it's being stretched..
  48496. if (isStretchingLeft)
  48497. {
  48498. x = jlimit (old.getRight() - maxW, old.getRight() - minW, x);
  48499. w = old.getRight() - x;
  48500. }
  48501. if (isStretchingRight)
  48502. {
  48503. w = jlimit (minW, maxW, w);
  48504. }
  48505. if (isStretchingTop)
  48506. {
  48507. y = jlimit (old.getBottom() - maxH, old.getBottom() - minH, y);
  48508. h = old.getBottom() - y;
  48509. }
  48510. if (isStretchingBottom)
  48511. {
  48512. h = jlimit (minH, maxH, h);
  48513. }
  48514. // constrain the aspect ratio if one has been specified..
  48515. if (aspectRatio > 0.0 && w > 0 && h > 0)
  48516. {
  48517. bool adjustWidth;
  48518. if ((isStretchingTop || isStretchingBottom) && ! (isStretchingLeft || isStretchingRight))
  48519. {
  48520. adjustWidth = true;
  48521. }
  48522. else if ((isStretchingLeft || isStretchingRight) && ! (isStretchingTop || isStretchingBottom))
  48523. {
  48524. adjustWidth = false;
  48525. }
  48526. else
  48527. {
  48528. const double oldRatio = (old.getHeight() > 0) ? fabs (old.getWidth() / (double) old.getHeight()) : 0.0;
  48529. const double newRatio = fabs (w / (double) h);
  48530. adjustWidth = (oldRatio > newRatio);
  48531. }
  48532. if (adjustWidth)
  48533. {
  48534. w = roundToInt (h * aspectRatio);
  48535. if (w > maxW || w < minW)
  48536. {
  48537. w = jlimit (minW, maxW, w);
  48538. h = roundToInt (w / aspectRatio);
  48539. }
  48540. }
  48541. else
  48542. {
  48543. h = roundToInt (w / aspectRatio);
  48544. if (h > maxH || h < minH)
  48545. {
  48546. h = jlimit (minH, maxH, h);
  48547. w = roundToInt (h * aspectRatio);
  48548. }
  48549. }
  48550. if ((isStretchingTop || isStretchingBottom) && ! (isStretchingLeft || isStretchingRight))
  48551. {
  48552. x = old.getX() + (old.getWidth() - w) / 2;
  48553. }
  48554. else if ((isStretchingLeft || isStretchingRight) && ! (isStretchingTop || isStretchingBottom))
  48555. {
  48556. y = old.getY() + (old.getHeight() - h) / 2;
  48557. }
  48558. else
  48559. {
  48560. if (isStretchingLeft)
  48561. x = old.getRight() - w;
  48562. if (isStretchingTop)
  48563. y = old.getBottom() - h;
  48564. }
  48565. }
  48566. // ...and constrain the position if limits have been set for that.
  48567. if (minOffTop > 0 || minOffLeft > 0 || minOffBottom > 0 || minOffRight > 0)
  48568. {
  48569. if (minOffTop > 0)
  48570. {
  48571. const int limit = limits.getY() + jmin (minOffTop - h, 0);
  48572. if (y < limit)
  48573. {
  48574. if (isStretchingTop)
  48575. h -= (limit - y);
  48576. y = limit;
  48577. }
  48578. }
  48579. if (minOffLeft > 0)
  48580. {
  48581. const int limit = limits.getX() + jmin (minOffLeft - w, 0);
  48582. if (x < limit)
  48583. {
  48584. if (isStretchingLeft)
  48585. w -= (limit - x);
  48586. x = limit;
  48587. }
  48588. }
  48589. if (minOffBottom > 0)
  48590. {
  48591. const int limit = limits.getBottom() - jmin (minOffBottom, h);
  48592. if (y > limit)
  48593. {
  48594. if (isStretchingBottom)
  48595. h += (limit - y);
  48596. else
  48597. y = limit;
  48598. }
  48599. }
  48600. if (minOffRight > 0)
  48601. {
  48602. const int limit = limits.getRight() - jmin (minOffRight, w);
  48603. if (x > limit)
  48604. {
  48605. if (isStretchingRight)
  48606. w += (limit - x);
  48607. else
  48608. x = limit;
  48609. }
  48610. }
  48611. }
  48612. jassert (w >= 0 && h >= 0);
  48613. bounds = Rectangle<int> (x, y, w, h);
  48614. }
  48615. END_JUCE_NAMESPACE
  48616. /*** End of inlined file: juce_ComponentBoundsConstrainer.cpp ***/
  48617. /*** Start of inlined file: juce_ComponentMovementWatcher.cpp ***/
  48618. BEGIN_JUCE_NAMESPACE
  48619. ComponentMovementWatcher::ComponentMovementWatcher (Component* const component_)
  48620. : component (component_),
  48621. lastPeer (0),
  48622. reentrant (false)
  48623. {
  48624. jassert (component != 0); // can't use this with a null pointer..
  48625. component->addComponentListener (this);
  48626. registerWithParentComps();
  48627. }
  48628. ComponentMovementWatcher::~ComponentMovementWatcher()
  48629. {
  48630. component->removeComponentListener (this);
  48631. unregister();
  48632. }
  48633. void ComponentMovementWatcher::componentParentHierarchyChanged (Component&)
  48634. {
  48635. // agh! don't delete the target component without deleting this object first!
  48636. jassert (component != 0);
  48637. if (! reentrant)
  48638. {
  48639. reentrant = true;
  48640. ComponentPeer* const peer = component->getPeer();
  48641. if (peer != lastPeer)
  48642. {
  48643. componentPeerChanged();
  48644. if (component == 0)
  48645. return;
  48646. lastPeer = peer;
  48647. }
  48648. unregister();
  48649. registerWithParentComps();
  48650. reentrant = false;
  48651. componentMovedOrResized (*component, true, true);
  48652. }
  48653. }
  48654. void ComponentMovementWatcher::componentMovedOrResized (Component&, bool wasMoved, bool wasResized)
  48655. {
  48656. // agh! don't delete the target component without deleting this object first!
  48657. jassert (component != 0);
  48658. if (wasMoved)
  48659. {
  48660. const Point<int> pos (component->relativePositionToOtherComponent (component->getTopLevelComponent(), Point<int>()));
  48661. wasMoved = lastBounds.getPosition() != pos;
  48662. lastBounds.setPosition (pos);
  48663. }
  48664. wasResized = (lastBounds.getWidth() != component->getWidth() || lastBounds.getHeight() != component->getHeight());
  48665. lastBounds.setSize (component->getWidth(), component->getHeight());
  48666. if (wasMoved || wasResized)
  48667. componentMovedOrResized (wasMoved, wasResized);
  48668. }
  48669. void ComponentMovementWatcher::registerWithParentComps() throw()
  48670. {
  48671. Component* p = component->getParentComponent();
  48672. while (p != 0)
  48673. {
  48674. p->addComponentListener (this);
  48675. registeredParentComps.add (p);
  48676. p = p->getParentComponent();
  48677. }
  48678. }
  48679. void ComponentMovementWatcher::unregister() throw()
  48680. {
  48681. for (int i = registeredParentComps.size(); --i >= 0;)
  48682. ((Component*) registeredParentComps.getUnchecked(i))->removeComponentListener (this);
  48683. registeredParentComps.clear();
  48684. }
  48685. END_JUCE_NAMESPACE
  48686. /*** End of inlined file: juce_ComponentMovementWatcher.cpp ***/
  48687. /*** Start of inlined file: juce_GroupComponent.cpp ***/
  48688. BEGIN_JUCE_NAMESPACE
  48689. GroupComponent::GroupComponent (const String& componentName,
  48690. const String& labelText)
  48691. : Component (componentName),
  48692. text (labelText),
  48693. justification (Justification::left)
  48694. {
  48695. setInterceptsMouseClicks (false, true);
  48696. }
  48697. GroupComponent::~GroupComponent()
  48698. {
  48699. }
  48700. void GroupComponent::setText (const String& newText) throw()
  48701. {
  48702. if (text != newText)
  48703. {
  48704. text = newText;
  48705. repaint();
  48706. }
  48707. }
  48708. const String GroupComponent::getText() const throw()
  48709. {
  48710. return text;
  48711. }
  48712. void GroupComponent::setTextLabelPosition (const Justification& newJustification)
  48713. {
  48714. if (justification.getFlags() != newJustification.getFlags())
  48715. {
  48716. justification = newJustification;
  48717. repaint();
  48718. }
  48719. }
  48720. void GroupComponent::paint (Graphics& g)
  48721. {
  48722. getLookAndFeel()
  48723. .drawGroupComponentOutline (g, getWidth(), getHeight(),
  48724. text, justification,
  48725. *this);
  48726. }
  48727. void GroupComponent::enablementChanged()
  48728. {
  48729. repaint();
  48730. }
  48731. void GroupComponent::colourChanged()
  48732. {
  48733. repaint();
  48734. }
  48735. END_JUCE_NAMESPACE
  48736. /*** End of inlined file: juce_GroupComponent.cpp ***/
  48737. /*** Start of inlined file: juce_MultiDocumentPanel.cpp ***/
  48738. BEGIN_JUCE_NAMESPACE
  48739. MultiDocumentPanelWindow::MultiDocumentPanelWindow (const Colour& backgroundColour)
  48740. : DocumentWindow (String::empty, backgroundColour,
  48741. DocumentWindow::maximiseButton | DocumentWindow::closeButton, false)
  48742. {
  48743. }
  48744. MultiDocumentPanelWindow::~MultiDocumentPanelWindow()
  48745. {
  48746. }
  48747. void MultiDocumentPanelWindow::maximiseButtonPressed()
  48748. {
  48749. MultiDocumentPanel* const owner = getOwner();
  48750. jassert (owner != 0); // these windows are only designed to be used inside a MultiDocumentPanel!
  48751. if (owner != 0)
  48752. owner->setLayoutMode (MultiDocumentPanel::MaximisedWindowsWithTabs);
  48753. }
  48754. void MultiDocumentPanelWindow::closeButtonPressed()
  48755. {
  48756. MultiDocumentPanel* const owner = getOwner();
  48757. jassert (owner != 0); // these windows are only designed to be used inside a MultiDocumentPanel!
  48758. if (owner != 0)
  48759. owner->closeDocument (getContentComponent(), true);
  48760. }
  48761. void MultiDocumentPanelWindow::activeWindowStatusChanged()
  48762. {
  48763. DocumentWindow::activeWindowStatusChanged();
  48764. updateOrder();
  48765. }
  48766. void MultiDocumentPanelWindow::broughtToFront()
  48767. {
  48768. DocumentWindow::broughtToFront();
  48769. updateOrder();
  48770. }
  48771. void MultiDocumentPanelWindow::updateOrder()
  48772. {
  48773. MultiDocumentPanel* const owner = getOwner();
  48774. if (owner != 0)
  48775. owner->updateOrder();
  48776. }
  48777. MultiDocumentPanel* MultiDocumentPanelWindow::getOwner() const throw()
  48778. {
  48779. // (unable to use the syntax findParentComponentOfClass <MultiDocumentPanel> () because of a VC6 compiler bug)
  48780. return findParentComponentOfClass ((MultiDocumentPanel*) 0);
  48781. }
  48782. class MDITabbedComponentInternal : public TabbedComponent
  48783. {
  48784. public:
  48785. MDITabbedComponentInternal()
  48786. : TabbedComponent (TabbedButtonBar::TabsAtTop)
  48787. {
  48788. }
  48789. ~MDITabbedComponentInternal()
  48790. {
  48791. }
  48792. void currentTabChanged (const int, const String&)
  48793. {
  48794. // (unable to use the syntax findParentComponentOfClass <MultiDocumentPanel> () because of a VC6 compiler bug)
  48795. MultiDocumentPanel* const owner = findParentComponentOfClass ((MultiDocumentPanel*) 0);
  48796. if (owner != 0)
  48797. owner->updateOrder();
  48798. }
  48799. };
  48800. MultiDocumentPanel::MultiDocumentPanel()
  48801. : mode (MaximisedWindowsWithTabs),
  48802. tabComponent (0),
  48803. backgroundColour (Colours::lightblue),
  48804. maximumNumDocuments (0),
  48805. numDocsBeforeTabsUsed (0)
  48806. {
  48807. setOpaque (true);
  48808. }
  48809. MultiDocumentPanel::~MultiDocumentPanel()
  48810. {
  48811. closeAllDocuments (false);
  48812. }
  48813. static bool shouldDeleteComp (Component* const c)
  48814. {
  48815. return c->getProperties() ["mdiDocumentDelete_"];
  48816. }
  48817. bool MultiDocumentPanel::closeAllDocuments (const bool checkItsOkToCloseFirst)
  48818. {
  48819. while (components.size() > 0)
  48820. if (! closeDocument (components.getLast(), checkItsOkToCloseFirst))
  48821. return false;
  48822. return true;
  48823. }
  48824. MultiDocumentPanelWindow* MultiDocumentPanel::createNewDocumentWindow()
  48825. {
  48826. return new MultiDocumentPanelWindow (backgroundColour);
  48827. }
  48828. void MultiDocumentPanel::addWindow (Component* component)
  48829. {
  48830. MultiDocumentPanelWindow* const dw = createNewDocumentWindow();
  48831. dw->setResizable (true, false);
  48832. dw->setContentComponent (component, false, true);
  48833. dw->setName (component->getName());
  48834. const var bkg (component->getProperties() ["mdiDocumentBkg_"]);
  48835. dw->setBackgroundColour (bkg.isVoid() ? backgroundColour : Colour ((int) bkg));
  48836. int x = 4;
  48837. Component* const topComp = getChildComponent (getNumChildComponents() - 1);
  48838. if (topComp != 0 && topComp->getX() == x && topComp->getY() == x)
  48839. x += 16;
  48840. dw->setTopLeftPosition (x, x);
  48841. const var pos (component->getProperties() ["mdiDocumentPos_"]);
  48842. if (pos.toString().isNotEmpty())
  48843. dw->restoreWindowStateFromString (pos.toString());
  48844. addAndMakeVisible (dw);
  48845. dw->toFront (true);
  48846. }
  48847. bool MultiDocumentPanel::addDocument (Component* const component,
  48848. const Colour& docColour,
  48849. const bool deleteWhenRemoved)
  48850. {
  48851. // If you try passing a full DocumentWindow or ResizableWindow in here, you'll end up
  48852. // with a frame-within-a-frame! Just pass in the bare content component.
  48853. jassert (dynamic_cast <ResizableWindow*> (component) == 0);
  48854. if (component == 0 || (maximumNumDocuments > 0 && components.size() >= maximumNumDocuments))
  48855. return false;
  48856. components.add (component);
  48857. component->getProperties().set ("mdiDocumentDelete_", deleteWhenRemoved);
  48858. component->getProperties().set ("mdiDocumentBkg_", (int) docColour.getARGB());
  48859. component->addComponentListener (this);
  48860. if (mode == FloatingWindows)
  48861. {
  48862. if (isFullscreenWhenOneDocument())
  48863. {
  48864. if (components.size() == 1)
  48865. {
  48866. addAndMakeVisible (component);
  48867. }
  48868. else
  48869. {
  48870. if (components.size() == 2)
  48871. addWindow (components.getFirst());
  48872. addWindow (component);
  48873. }
  48874. }
  48875. else
  48876. {
  48877. addWindow (component);
  48878. }
  48879. }
  48880. else
  48881. {
  48882. if (tabComponent == 0 && components.size() > numDocsBeforeTabsUsed)
  48883. {
  48884. addAndMakeVisible (tabComponent = new MDITabbedComponentInternal());
  48885. Array <Component*> temp (components);
  48886. for (int i = 0; i < temp.size(); ++i)
  48887. tabComponent->addTab (temp[i]->getName(), docColour, temp[i], false);
  48888. resized();
  48889. }
  48890. else
  48891. {
  48892. if (tabComponent != 0)
  48893. tabComponent->addTab (component->getName(), docColour, component, false);
  48894. else
  48895. addAndMakeVisible (component);
  48896. }
  48897. setActiveDocument (component);
  48898. }
  48899. resized();
  48900. activeDocumentChanged();
  48901. return true;
  48902. }
  48903. bool MultiDocumentPanel::closeDocument (Component* component,
  48904. const bool checkItsOkToCloseFirst)
  48905. {
  48906. if (components.contains (component))
  48907. {
  48908. if (checkItsOkToCloseFirst && ! tryToCloseDocument (component))
  48909. return false;
  48910. component->removeComponentListener (this);
  48911. const bool shouldDelete = shouldDeleteComp (component);
  48912. component->getProperties().remove ("mdiDocumentDelete_");
  48913. component->getProperties().remove ("mdiDocumentBkg_");
  48914. if (mode == FloatingWindows)
  48915. {
  48916. for (int i = getNumChildComponents(); --i >= 0;)
  48917. {
  48918. MultiDocumentPanelWindow* const dw = dynamic_cast <MultiDocumentPanelWindow*> (getChildComponent (i));
  48919. if (dw != 0 && dw->getContentComponent() == component)
  48920. {
  48921. dw->setContentComponent (0, false);
  48922. delete dw;
  48923. break;
  48924. }
  48925. }
  48926. if (shouldDelete)
  48927. delete component;
  48928. components.removeValue (component);
  48929. if (isFullscreenWhenOneDocument() && components.size() == 1)
  48930. {
  48931. for (int i = getNumChildComponents(); --i >= 0;)
  48932. {
  48933. MultiDocumentPanelWindow* const dw = dynamic_cast <MultiDocumentPanelWindow*> (getChildComponent (i));
  48934. if (dw != 0)
  48935. {
  48936. dw->setContentComponent (0, false);
  48937. delete dw;
  48938. }
  48939. }
  48940. addAndMakeVisible (components.getFirst());
  48941. }
  48942. }
  48943. else
  48944. {
  48945. jassert (components.indexOf (component) >= 0);
  48946. if (tabComponent != 0)
  48947. {
  48948. for (int i = tabComponent->getNumTabs(); --i >= 0;)
  48949. if (tabComponent->getTabContentComponent (i) == component)
  48950. tabComponent->removeTab (i);
  48951. }
  48952. else
  48953. {
  48954. removeChildComponent (component);
  48955. }
  48956. if (shouldDelete)
  48957. delete component;
  48958. if (tabComponent != 0 && tabComponent->getNumTabs() <= numDocsBeforeTabsUsed)
  48959. deleteAndZero (tabComponent);
  48960. components.removeValue (component);
  48961. if (components.size() > 0 && tabComponent == 0)
  48962. addAndMakeVisible (components.getFirst());
  48963. }
  48964. resized();
  48965. activeDocumentChanged();
  48966. }
  48967. else
  48968. {
  48969. jassertfalse
  48970. }
  48971. return true;
  48972. }
  48973. int MultiDocumentPanel::getNumDocuments() const throw()
  48974. {
  48975. return components.size();
  48976. }
  48977. Component* MultiDocumentPanel::getDocument (const int index) const throw()
  48978. {
  48979. return components [index];
  48980. }
  48981. Component* MultiDocumentPanel::getActiveDocument() const throw()
  48982. {
  48983. if (mode == FloatingWindows)
  48984. {
  48985. for (int i = getNumChildComponents(); --i >= 0;)
  48986. {
  48987. MultiDocumentPanelWindow* const dw = dynamic_cast <MultiDocumentPanelWindow*> (getChildComponent (i));
  48988. if (dw != 0 && dw->isActiveWindow())
  48989. return dw->getContentComponent();
  48990. }
  48991. }
  48992. return components.getLast();
  48993. }
  48994. void MultiDocumentPanel::setActiveDocument (Component* component)
  48995. {
  48996. if (mode == FloatingWindows)
  48997. {
  48998. component = getContainerComp (component);
  48999. if (component != 0)
  49000. component->toFront (true);
  49001. }
  49002. else if (tabComponent != 0)
  49003. {
  49004. jassert (components.indexOf (component) >= 0);
  49005. for (int i = tabComponent->getNumTabs(); --i >= 0;)
  49006. {
  49007. if (tabComponent->getTabContentComponent (i) == component)
  49008. {
  49009. tabComponent->setCurrentTabIndex (i);
  49010. break;
  49011. }
  49012. }
  49013. }
  49014. else
  49015. {
  49016. component->grabKeyboardFocus();
  49017. }
  49018. }
  49019. void MultiDocumentPanel::activeDocumentChanged()
  49020. {
  49021. }
  49022. void MultiDocumentPanel::setMaximumNumDocuments (const int newNumber)
  49023. {
  49024. maximumNumDocuments = newNumber;
  49025. }
  49026. void MultiDocumentPanel::useFullscreenWhenOneDocument (const bool shouldUseTabs)
  49027. {
  49028. numDocsBeforeTabsUsed = shouldUseTabs ? 1 : 0;
  49029. }
  49030. bool MultiDocumentPanel::isFullscreenWhenOneDocument() const throw()
  49031. {
  49032. return numDocsBeforeTabsUsed != 0;
  49033. }
  49034. void MultiDocumentPanel::setLayoutMode (const LayoutMode newLayoutMode)
  49035. {
  49036. if (mode != newLayoutMode)
  49037. {
  49038. mode = newLayoutMode;
  49039. if (mode == FloatingWindows)
  49040. {
  49041. deleteAndZero (tabComponent);
  49042. }
  49043. else
  49044. {
  49045. for (int i = getNumChildComponents(); --i >= 0;)
  49046. {
  49047. MultiDocumentPanelWindow* const dw = dynamic_cast <MultiDocumentPanelWindow*> (getChildComponent (i));
  49048. if (dw != 0)
  49049. {
  49050. dw->getContentComponent()->getProperties().set ("mdiDocumentPos_", dw->getWindowStateAsString());
  49051. dw->setContentComponent (0, false);
  49052. delete dw;
  49053. }
  49054. }
  49055. }
  49056. resized();
  49057. const Array <Component*> tempComps (components);
  49058. components.clear();
  49059. for (int i = 0; i < tempComps.size(); ++i)
  49060. {
  49061. Component* const c = tempComps.getUnchecked(i);
  49062. addDocument (c,
  49063. Colour ((int) c->getProperties().getWithDefault ("mdiDocumentBkg_", (int) Colours::white.getARGB())),
  49064. shouldDeleteComp (c));
  49065. }
  49066. }
  49067. }
  49068. void MultiDocumentPanel::setBackgroundColour (const Colour& newBackgroundColour)
  49069. {
  49070. if (backgroundColour != newBackgroundColour)
  49071. {
  49072. backgroundColour = newBackgroundColour;
  49073. setOpaque (newBackgroundColour.isOpaque());
  49074. repaint();
  49075. }
  49076. }
  49077. void MultiDocumentPanel::paint (Graphics& g)
  49078. {
  49079. g.fillAll (backgroundColour);
  49080. }
  49081. void MultiDocumentPanel::resized()
  49082. {
  49083. if (mode == MaximisedWindowsWithTabs || components.size() == numDocsBeforeTabsUsed)
  49084. {
  49085. for (int i = getNumChildComponents(); --i >= 0;)
  49086. getChildComponent (i)->setBounds (0, 0, getWidth(), getHeight());
  49087. }
  49088. setWantsKeyboardFocus (components.size() == 0);
  49089. }
  49090. Component* MultiDocumentPanel::getContainerComp (Component* c) const
  49091. {
  49092. if (mode == FloatingWindows)
  49093. {
  49094. for (int i = 0; i < getNumChildComponents(); ++i)
  49095. {
  49096. MultiDocumentPanelWindow* const dw = dynamic_cast <MultiDocumentPanelWindow*> (getChildComponent (i));
  49097. if (dw != 0 && dw->getContentComponent() == c)
  49098. {
  49099. c = dw;
  49100. break;
  49101. }
  49102. }
  49103. }
  49104. return c;
  49105. }
  49106. void MultiDocumentPanel::componentNameChanged (Component&)
  49107. {
  49108. if (mode == FloatingWindows)
  49109. {
  49110. for (int i = 0; i < getNumChildComponents(); ++i)
  49111. {
  49112. MultiDocumentPanelWindow* const dw = dynamic_cast <MultiDocumentPanelWindow*> (getChildComponent (i));
  49113. if (dw != 0)
  49114. dw->setName (dw->getContentComponent()->getName());
  49115. }
  49116. }
  49117. else if (tabComponent != 0)
  49118. {
  49119. for (int i = tabComponent->getNumTabs(); --i >= 0;)
  49120. tabComponent->setTabName (i, tabComponent->getTabContentComponent (i)->getName());
  49121. }
  49122. }
  49123. void MultiDocumentPanel::updateOrder()
  49124. {
  49125. const Array <Component*> oldList (components);
  49126. if (mode == FloatingWindows)
  49127. {
  49128. components.clear();
  49129. for (int i = 0; i < getNumChildComponents(); ++i)
  49130. {
  49131. MultiDocumentPanelWindow* const dw = dynamic_cast <MultiDocumentPanelWindow*> (getChildComponent (i));
  49132. if (dw != 0)
  49133. components.add (dw->getContentComponent());
  49134. }
  49135. }
  49136. else
  49137. {
  49138. if (tabComponent != 0)
  49139. {
  49140. Component* const current = tabComponent->getCurrentContentComponent();
  49141. if (current != 0)
  49142. {
  49143. components.removeValue (current);
  49144. components.add (current);
  49145. }
  49146. }
  49147. }
  49148. if (components != oldList)
  49149. activeDocumentChanged();
  49150. }
  49151. END_JUCE_NAMESPACE
  49152. /*** End of inlined file: juce_MultiDocumentPanel.cpp ***/
  49153. /*** Start of inlined file: juce_ResizableBorderComponent.cpp ***/
  49154. BEGIN_JUCE_NAMESPACE
  49155. enum ResizableBorderComponentZones
  49156. {
  49157. zoneL = 1,
  49158. zoneR = 2,
  49159. zoneT = 4,
  49160. zoneB = 8
  49161. };
  49162. ResizableBorderComponent::ResizableBorderComponent (Component* const componentToResize,
  49163. ComponentBoundsConstrainer* const constrainer_)
  49164. : component (componentToResize),
  49165. constrainer (constrainer_),
  49166. borderSize (5),
  49167. mouseZone (0)
  49168. {
  49169. }
  49170. ResizableBorderComponent::~ResizableBorderComponent()
  49171. {
  49172. }
  49173. void ResizableBorderComponent::paint (Graphics& g)
  49174. {
  49175. getLookAndFeel().drawResizableFrame (g, getWidth(), getHeight(), borderSize);
  49176. }
  49177. void ResizableBorderComponent::mouseEnter (const MouseEvent& e)
  49178. {
  49179. updateMouseZone (e);
  49180. }
  49181. void ResizableBorderComponent::mouseMove (const MouseEvent& e)
  49182. {
  49183. updateMouseZone (e);
  49184. }
  49185. void ResizableBorderComponent::mouseDown (const MouseEvent& e)
  49186. {
  49187. if (component == 0)
  49188. {
  49189. jassertfalse // You've deleted the component that this resizer was supposed to be using!
  49190. return;
  49191. }
  49192. updateMouseZone (e);
  49193. originalBounds = component->getBounds();
  49194. if (constrainer != 0)
  49195. constrainer->resizeStart();
  49196. }
  49197. void ResizableBorderComponent::mouseDrag (const MouseEvent& e)
  49198. {
  49199. if (component == 0)
  49200. {
  49201. jassertfalse // You've deleted the component that this resizer was supposed to be using!
  49202. return;
  49203. }
  49204. Rectangle<int> bounds (originalBounds);
  49205. if ((mouseZone & zoneL) != 0)
  49206. bounds.setLeft (bounds.getX() + e.getDistanceFromDragStartX());
  49207. if ((mouseZone & zoneT) != 0)
  49208. bounds.setTop (bounds.getY() + e.getDistanceFromDragStartY());
  49209. if ((mouseZone & zoneR) != 0)
  49210. bounds.setWidth (bounds.getWidth() + e.getDistanceFromDragStartX());
  49211. if ((mouseZone & zoneB) != 0)
  49212. bounds.setHeight (bounds.getHeight() + e.getDistanceFromDragStartY());
  49213. if (constrainer != 0)
  49214. constrainer->setBoundsForComponent (component, bounds,
  49215. (mouseZone & zoneT) != 0,
  49216. (mouseZone & zoneL) != 0,
  49217. (mouseZone & zoneB) != 0,
  49218. (mouseZone & zoneR) != 0);
  49219. else
  49220. component->setBounds (bounds);
  49221. }
  49222. void ResizableBorderComponent::mouseUp (const MouseEvent&)
  49223. {
  49224. if (constrainer != 0)
  49225. constrainer->resizeEnd();
  49226. }
  49227. bool ResizableBorderComponent::hitTest (int x, int y)
  49228. {
  49229. return x < borderSize.getLeft()
  49230. || x >= getWidth() - borderSize.getRight()
  49231. || y < borderSize.getTop()
  49232. || y >= getHeight() - borderSize.getBottom();
  49233. }
  49234. void ResizableBorderComponent::setBorderThickness (const BorderSize& newBorderSize)
  49235. {
  49236. if (borderSize != newBorderSize)
  49237. {
  49238. borderSize = newBorderSize;
  49239. repaint();
  49240. }
  49241. }
  49242. const BorderSize ResizableBorderComponent::getBorderThickness() const
  49243. {
  49244. return borderSize;
  49245. }
  49246. void ResizableBorderComponent::updateMouseZone (const MouseEvent& e)
  49247. {
  49248. int newZone = 0;
  49249. if (ResizableBorderComponent::hitTest (e.x, e.y))
  49250. {
  49251. if (e.x < jmax (borderSize.getLeft(),
  49252. proportionOfWidth (0.1f),
  49253. jmin (10, proportionOfWidth (0.33f))))
  49254. newZone |= zoneL;
  49255. else if (e.x >= jmin (getWidth() - borderSize.getRight(),
  49256. proportionOfWidth (0.9f),
  49257. getWidth() - jmin (10, proportionOfWidth (0.33f))))
  49258. newZone |= zoneR;
  49259. if (e.y < jmax (borderSize.getTop(),
  49260. proportionOfHeight (0.1f),
  49261. jmin (10, proportionOfHeight (0.33f))))
  49262. newZone |= zoneT;
  49263. else if (e.y >= jmin (getHeight() - borderSize.getBottom(),
  49264. proportionOfHeight (0.9f),
  49265. getHeight() - jmin (10, proportionOfHeight (0.33f))))
  49266. newZone |= zoneB;
  49267. }
  49268. if (mouseZone != newZone)
  49269. {
  49270. mouseZone = newZone;
  49271. MouseCursor::StandardCursorType mc = MouseCursor::NormalCursor;
  49272. switch (newZone)
  49273. {
  49274. case (zoneL | zoneT): mc = MouseCursor::TopLeftCornerResizeCursor; break;
  49275. case zoneT: mc = MouseCursor::TopEdgeResizeCursor; break;
  49276. case (zoneR | zoneT): mc = MouseCursor::TopRightCornerResizeCursor; break;
  49277. case zoneL: mc = MouseCursor::LeftEdgeResizeCursor; break;
  49278. case zoneR: mc = MouseCursor::RightEdgeResizeCursor; break;
  49279. case (zoneL | zoneB): mc = MouseCursor::BottomLeftCornerResizeCursor; break;
  49280. case zoneB: mc = MouseCursor::BottomEdgeResizeCursor; break;
  49281. case (zoneR | zoneB): mc = MouseCursor::BottomRightCornerResizeCursor; break;
  49282. default: break;
  49283. }
  49284. setMouseCursor (mc);
  49285. }
  49286. }
  49287. END_JUCE_NAMESPACE
  49288. /*** End of inlined file: juce_ResizableBorderComponent.cpp ***/
  49289. /*** Start of inlined file: juce_ResizableCornerComponent.cpp ***/
  49290. BEGIN_JUCE_NAMESPACE
  49291. ResizableCornerComponent::ResizableCornerComponent (Component* const componentToResize,
  49292. ComponentBoundsConstrainer* const constrainer_)
  49293. : component (componentToResize),
  49294. constrainer (constrainer_)
  49295. {
  49296. setRepaintsOnMouseActivity (true);
  49297. setMouseCursor (MouseCursor::BottomRightCornerResizeCursor);
  49298. }
  49299. ResizableCornerComponent::~ResizableCornerComponent()
  49300. {
  49301. }
  49302. void ResizableCornerComponent::paint (Graphics& g)
  49303. {
  49304. getLookAndFeel()
  49305. .drawCornerResizer (g, getWidth(), getHeight(),
  49306. isMouseOverOrDragging(),
  49307. isMouseButtonDown());
  49308. }
  49309. void ResizableCornerComponent::mouseDown (const MouseEvent&)
  49310. {
  49311. if (component == 0)
  49312. {
  49313. jassertfalse; // You've deleted the component that this resizer is supposed to be controlling!
  49314. return;
  49315. }
  49316. originalBounds = component->getBounds();
  49317. if (constrainer != 0)
  49318. constrainer->resizeStart();
  49319. }
  49320. void ResizableCornerComponent::mouseDrag (const MouseEvent& e)
  49321. {
  49322. if (component == 0)
  49323. {
  49324. jassertfalse; // You've deleted the component that this resizer is supposed to be controlling!
  49325. return;
  49326. }
  49327. Rectangle<int> r (originalBounds.withSize (originalBounds.getWidth() + e.getDistanceFromDragStartX(),
  49328. originalBounds.getHeight() + e.getDistanceFromDragStartY()));
  49329. if (constrainer != 0)
  49330. constrainer->setBoundsForComponent (component, r, false, false, true, true);
  49331. else
  49332. component->setBounds (r);
  49333. }
  49334. void ResizableCornerComponent::mouseUp (const MouseEvent&)
  49335. {
  49336. if (constrainer != 0)
  49337. constrainer->resizeStart();
  49338. }
  49339. bool ResizableCornerComponent::hitTest (int x, int y)
  49340. {
  49341. if (getWidth() <= 0)
  49342. return false;
  49343. const int yAtX = getHeight() - (getHeight() * x / getWidth());
  49344. return y >= yAtX - getHeight() / 4;
  49345. }
  49346. END_JUCE_NAMESPACE
  49347. /*** End of inlined file: juce_ResizableCornerComponent.cpp ***/
  49348. /*** Start of inlined file: juce_ScrollBar.cpp ***/
  49349. BEGIN_JUCE_NAMESPACE
  49350. class ScrollbarButton : public Button
  49351. {
  49352. public:
  49353. int direction;
  49354. ScrollbarButton (const int direction_,
  49355. ScrollBar& owner_) throw()
  49356. : Button (String::empty),
  49357. direction (direction_),
  49358. owner (owner_)
  49359. {
  49360. setWantsKeyboardFocus (false);
  49361. }
  49362. ~ScrollbarButton()
  49363. {
  49364. }
  49365. void paintButton (Graphics& g,
  49366. bool isMouseOver,
  49367. bool isMouseDown)
  49368. {
  49369. getLookAndFeel()
  49370. .drawScrollbarButton (g, owner,
  49371. getWidth(), getHeight(),
  49372. direction,
  49373. owner.isVertical(),
  49374. isMouseOver, isMouseDown);
  49375. }
  49376. void clicked()
  49377. {
  49378. owner.moveScrollbarInSteps ((direction == 1 || direction == 2) ? 1 : -1);
  49379. }
  49380. juce_UseDebuggingNewOperator
  49381. private:
  49382. ScrollBar& owner;
  49383. ScrollbarButton (const ScrollbarButton&);
  49384. ScrollbarButton& operator= (const ScrollbarButton&);
  49385. };
  49386. ScrollBar::ScrollBar (const bool vertical_,
  49387. const bool buttonsAreVisible)
  49388. : minimum (0.0),
  49389. maximum (1.0),
  49390. rangeStart (0.0),
  49391. rangeSize (0.1),
  49392. singleStepSize (0.1),
  49393. thumbAreaStart (0),
  49394. thumbAreaSize (0),
  49395. thumbStart (0),
  49396. thumbSize (0),
  49397. initialDelayInMillisecs (100),
  49398. repeatDelayInMillisecs (50),
  49399. minimumDelayInMillisecs (10),
  49400. vertical (vertical_),
  49401. isDraggingThumb (false),
  49402. alwaysVisible (false),
  49403. upButton (0),
  49404. downButton (0)
  49405. {
  49406. setButtonVisibility (buttonsAreVisible);
  49407. setRepaintsOnMouseActivity (true);
  49408. setFocusContainer (true);
  49409. }
  49410. ScrollBar::~ScrollBar()
  49411. {
  49412. deleteAllChildren();
  49413. }
  49414. void ScrollBar::setRangeLimits (const double newMinimum,
  49415. const double newMaximum) throw()
  49416. {
  49417. minimum = newMinimum;
  49418. maximum = newMaximum;
  49419. jassert (maximum >= minimum); // these can't be the wrong way round!
  49420. setCurrentRangeStart (rangeStart);
  49421. updateThumbPosition();
  49422. }
  49423. void ScrollBar::setCurrentRange (double newStart,
  49424. double newSize) throw()
  49425. {
  49426. newSize = jlimit (0.0, maximum - minimum, newSize);
  49427. newStart = jlimit (minimum, maximum - newSize, newStart);
  49428. if (rangeStart != newStart
  49429. || rangeSize != newSize)
  49430. {
  49431. rangeStart = newStart;
  49432. rangeSize = newSize;
  49433. updateThumbPosition();
  49434. triggerAsyncUpdate();
  49435. }
  49436. }
  49437. void ScrollBar::setCurrentRangeStart (double newStart) throw()
  49438. {
  49439. setCurrentRange (newStart, rangeSize);
  49440. }
  49441. void ScrollBar::setSingleStepSize (const double newSingleStepSize) throw()
  49442. {
  49443. singleStepSize = newSingleStepSize;
  49444. }
  49445. void ScrollBar::moveScrollbarInSteps (const int howManySteps) throw()
  49446. {
  49447. setCurrentRangeStart (rangeStart + howManySteps * singleStepSize);
  49448. }
  49449. void ScrollBar::moveScrollbarInPages (const int howManyPages) throw()
  49450. {
  49451. setCurrentRangeStart (rangeStart + howManyPages * rangeSize);
  49452. }
  49453. void ScrollBar::scrollToTop() throw()
  49454. {
  49455. setCurrentRangeStart (minimum);
  49456. }
  49457. void ScrollBar::scrollToBottom() throw()
  49458. {
  49459. setCurrentRangeStart (maximum - rangeSize);
  49460. }
  49461. void ScrollBar::setButtonRepeatSpeed (const int initialDelayInMillisecs_,
  49462. const int repeatDelayInMillisecs_,
  49463. const int minimumDelayInMillisecs_) throw()
  49464. {
  49465. initialDelayInMillisecs = initialDelayInMillisecs_;
  49466. repeatDelayInMillisecs = repeatDelayInMillisecs_;
  49467. minimumDelayInMillisecs = minimumDelayInMillisecs_;
  49468. if (upButton != 0)
  49469. {
  49470. upButton->setRepeatSpeed (initialDelayInMillisecs, repeatDelayInMillisecs, minimumDelayInMillisecs);
  49471. downButton->setRepeatSpeed (initialDelayInMillisecs, repeatDelayInMillisecs, minimumDelayInMillisecs);
  49472. }
  49473. }
  49474. void ScrollBar::addListener (ScrollBarListener* const listener) throw()
  49475. {
  49476. listeners.add (listener);
  49477. }
  49478. void ScrollBar::removeListener (ScrollBarListener* const listener) throw()
  49479. {
  49480. listeners.remove (listener);
  49481. }
  49482. void ScrollBar::handleAsyncUpdate()
  49483. {
  49484. listeners.call (&ScrollBarListener::scrollBarMoved, this, rangeStart);
  49485. }
  49486. void ScrollBar::updateThumbPosition() throw()
  49487. {
  49488. int newThumbSize = roundToInt ((maximum > minimum) ? (rangeSize * thumbAreaSize) / (maximum - minimum)
  49489. : thumbAreaSize);
  49490. if (newThumbSize < getLookAndFeel().getMinimumScrollbarThumbSize (*this))
  49491. newThumbSize = jmin (getLookAndFeel().getMinimumScrollbarThumbSize (*this), thumbAreaSize - 1);
  49492. if (newThumbSize > thumbAreaSize)
  49493. newThumbSize = thumbAreaSize;
  49494. int newThumbStart = thumbAreaStart;
  49495. if (maximum - minimum > rangeSize)
  49496. newThumbStart += roundToInt (((rangeStart - minimum) * (thumbAreaSize - newThumbSize))
  49497. / ((maximum - minimum) - rangeSize));
  49498. setVisible (alwaysVisible || (maximum - minimum > rangeSize && rangeSize > 0.0));
  49499. if (thumbStart != newThumbStart || thumbSize != newThumbSize)
  49500. {
  49501. const int repaintStart = jmin (thumbStart, newThumbStart) - 4;
  49502. const int repaintSize = jmax (thumbStart + thumbSize, newThumbStart + newThumbSize) + 8 - repaintStart;
  49503. if (vertical)
  49504. repaint (0, repaintStart, getWidth(), repaintSize);
  49505. else
  49506. repaint (repaintStart, 0, repaintSize, getHeight());
  49507. thumbStart = newThumbStart;
  49508. thumbSize = newThumbSize;
  49509. }
  49510. }
  49511. void ScrollBar::setOrientation (const bool shouldBeVertical) throw()
  49512. {
  49513. if (vertical != shouldBeVertical)
  49514. {
  49515. vertical = shouldBeVertical;
  49516. if (upButton != 0)
  49517. {
  49518. ((ScrollbarButton*) upButton)->direction = (vertical) ? 0 : 3;
  49519. ((ScrollbarButton*) downButton)->direction = (vertical) ? 2 : 1;
  49520. }
  49521. updateThumbPosition();
  49522. }
  49523. }
  49524. void ScrollBar::setButtonVisibility (const bool buttonsAreVisible)
  49525. {
  49526. deleteAndZero (upButton);
  49527. deleteAndZero (downButton);
  49528. if (buttonsAreVisible)
  49529. {
  49530. addAndMakeVisible (upButton = new ScrollbarButton ((vertical) ? 0 : 3, *this));
  49531. addAndMakeVisible (downButton = new ScrollbarButton ((vertical) ? 2 : 1, *this));
  49532. setButtonRepeatSpeed (initialDelayInMillisecs, repeatDelayInMillisecs, minimumDelayInMillisecs);
  49533. }
  49534. updateThumbPosition();
  49535. }
  49536. void ScrollBar::setAutoHide (const bool shouldHideWhenFullRange)
  49537. {
  49538. alwaysVisible = ! shouldHideWhenFullRange;
  49539. updateThumbPosition();
  49540. }
  49541. void ScrollBar::paint (Graphics& g)
  49542. {
  49543. if (thumbAreaSize > 0)
  49544. {
  49545. LookAndFeel& lf = getLookAndFeel();
  49546. const int thumb = (thumbAreaSize > lf.getMinimumScrollbarThumbSize (*this))
  49547. ? thumbSize : 0;
  49548. if (vertical)
  49549. {
  49550. lf.drawScrollbar (g, *this,
  49551. 0, thumbAreaStart,
  49552. getWidth(), thumbAreaSize,
  49553. vertical,
  49554. thumbStart, thumb,
  49555. isMouseOver(), isMouseButtonDown());
  49556. }
  49557. else
  49558. {
  49559. lf.drawScrollbar (g, *this,
  49560. thumbAreaStart, 0,
  49561. thumbAreaSize, getHeight(),
  49562. vertical,
  49563. thumbStart, thumb,
  49564. isMouseOver(), isMouseButtonDown());
  49565. }
  49566. }
  49567. }
  49568. void ScrollBar::lookAndFeelChanged()
  49569. {
  49570. setComponentEffect (getLookAndFeel().getScrollbarEffect());
  49571. }
  49572. void ScrollBar::resized()
  49573. {
  49574. const int length = ((vertical) ? getHeight() : getWidth());
  49575. const int buttonSize = (upButton != 0) ? jmin (getLookAndFeel().getScrollbarButtonSize (*this), (length >> 1))
  49576. : 0;
  49577. if (length < 32 + getLookAndFeel().getMinimumScrollbarThumbSize (*this))
  49578. {
  49579. thumbAreaStart = length >> 1;
  49580. thumbAreaSize = 0;
  49581. }
  49582. else
  49583. {
  49584. thumbAreaStart = buttonSize;
  49585. thumbAreaSize = length - (buttonSize << 1);
  49586. }
  49587. if (upButton != 0)
  49588. {
  49589. if (vertical)
  49590. {
  49591. upButton->setBounds (0, 0, getWidth(), buttonSize);
  49592. downButton->setBounds (0, thumbAreaStart + thumbAreaSize, getWidth(), buttonSize);
  49593. }
  49594. else
  49595. {
  49596. upButton->setBounds (0, 0, buttonSize, getHeight());
  49597. downButton->setBounds (thumbAreaStart + thumbAreaSize, 0, buttonSize, getHeight());
  49598. }
  49599. }
  49600. updateThumbPosition();
  49601. }
  49602. void ScrollBar::mouseDown (const MouseEvent& e)
  49603. {
  49604. isDraggingThumb = false;
  49605. lastMousePos = vertical ? e.y : e.x;
  49606. dragStartMousePos = lastMousePos;
  49607. dragStartRange = rangeStart;
  49608. if (dragStartMousePos < thumbStart)
  49609. {
  49610. moveScrollbarInPages (-1);
  49611. startTimer (400);
  49612. }
  49613. else if (dragStartMousePos >= thumbStart + thumbSize)
  49614. {
  49615. moveScrollbarInPages (1);
  49616. startTimer (400);
  49617. }
  49618. else
  49619. {
  49620. isDraggingThumb = (thumbAreaSize > getLookAndFeel().getMinimumScrollbarThumbSize (*this))
  49621. && (thumbAreaSize > thumbSize);
  49622. }
  49623. }
  49624. void ScrollBar::mouseDrag (const MouseEvent& e)
  49625. {
  49626. if (isDraggingThumb)
  49627. {
  49628. const int deltaPixels = ((vertical) ? e.y : e.x) - dragStartMousePos;
  49629. setCurrentRangeStart (dragStartRange
  49630. + deltaPixels * ((maximum - minimum) - rangeSize)
  49631. / (thumbAreaSize - thumbSize));
  49632. }
  49633. else
  49634. {
  49635. lastMousePos = (vertical) ? e.y : e.x;
  49636. }
  49637. }
  49638. void ScrollBar::mouseUp (const MouseEvent&)
  49639. {
  49640. isDraggingThumb = false;
  49641. stopTimer();
  49642. repaint();
  49643. }
  49644. void ScrollBar::mouseWheelMove (const MouseEvent&,
  49645. float wheelIncrementX,
  49646. float wheelIncrementY)
  49647. {
  49648. float increment = vertical ? wheelIncrementY : wheelIncrementX;
  49649. if (increment < 0)
  49650. increment = jmin (increment * 10.0f, -1.0f);
  49651. else if (increment > 0)
  49652. increment = jmax (increment * 10.0f, 1.0f);
  49653. setCurrentRangeStart (rangeStart - singleStepSize * increment);
  49654. }
  49655. void ScrollBar::timerCallback()
  49656. {
  49657. if (isMouseButtonDown())
  49658. {
  49659. startTimer (40);
  49660. if (lastMousePos < thumbStart)
  49661. setCurrentRangeStart (rangeStart - rangeSize);
  49662. else if (lastMousePos > thumbStart + thumbSize)
  49663. setCurrentRangeStart (rangeStart + rangeSize);
  49664. }
  49665. else
  49666. {
  49667. stopTimer();
  49668. }
  49669. }
  49670. bool ScrollBar::keyPressed (const KeyPress& key)
  49671. {
  49672. if (! isVisible())
  49673. return false;
  49674. if (key.isKeyCode (KeyPress::upKey) || key.isKeyCode (KeyPress::leftKey))
  49675. moveScrollbarInSteps (-1);
  49676. else if (key.isKeyCode (KeyPress::downKey) || key.isKeyCode (KeyPress::rightKey))
  49677. moveScrollbarInSteps (1);
  49678. else if (key.isKeyCode (KeyPress::pageUpKey))
  49679. moveScrollbarInPages (-1);
  49680. else if (key.isKeyCode (KeyPress::pageDownKey))
  49681. moveScrollbarInPages (1);
  49682. else if (key.isKeyCode (KeyPress::homeKey))
  49683. scrollToTop();
  49684. else if (key.isKeyCode (KeyPress::endKey))
  49685. scrollToBottom();
  49686. else
  49687. return false;
  49688. return true;
  49689. }
  49690. END_JUCE_NAMESPACE
  49691. /*** End of inlined file: juce_ScrollBar.cpp ***/
  49692. /*** Start of inlined file: juce_StretchableLayoutManager.cpp ***/
  49693. BEGIN_JUCE_NAMESPACE
  49694. StretchableLayoutManager::StretchableLayoutManager()
  49695. : totalSize (0)
  49696. {
  49697. }
  49698. StretchableLayoutManager::~StretchableLayoutManager()
  49699. {
  49700. }
  49701. void StretchableLayoutManager::clearAllItems()
  49702. {
  49703. items.clear();
  49704. totalSize = 0;
  49705. }
  49706. void StretchableLayoutManager::setItemLayout (const int itemIndex,
  49707. const double minimumSize,
  49708. const double maximumSize,
  49709. const double preferredSize)
  49710. {
  49711. ItemLayoutProperties* layout = getInfoFor (itemIndex);
  49712. if (layout == 0)
  49713. {
  49714. layout = new ItemLayoutProperties();
  49715. layout->itemIndex = itemIndex;
  49716. int i;
  49717. for (i = 0; i < items.size(); ++i)
  49718. if (items.getUnchecked (i)->itemIndex > itemIndex)
  49719. break;
  49720. items.insert (i, layout);
  49721. }
  49722. layout->minSize = minimumSize;
  49723. layout->maxSize = maximumSize;
  49724. layout->preferredSize = preferredSize;
  49725. layout->currentSize = 0;
  49726. }
  49727. bool StretchableLayoutManager::getItemLayout (const int itemIndex,
  49728. double& minimumSize,
  49729. double& maximumSize,
  49730. double& preferredSize) const
  49731. {
  49732. const ItemLayoutProperties* const layout = getInfoFor (itemIndex);
  49733. if (layout != 0)
  49734. {
  49735. minimumSize = layout->minSize;
  49736. maximumSize = layout->maxSize;
  49737. preferredSize = layout->preferredSize;
  49738. return true;
  49739. }
  49740. return false;
  49741. }
  49742. void StretchableLayoutManager::setTotalSize (const int newTotalSize)
  49743. {
  49744. totalSize = newTotalSize;
  49745. fitComponentsIntoSpace (0, items.size(), totalSize, 0);
  49746. }
  49747. int StretchableLayoutManager::getItemCurrentPosition (const int itemIndex) const
  49748. {
  49749. int pos = 0;
  49750. for (int i = 0; i < itemIndex; ++i)
  49751. {
  49752. const ItemLayoutProperties* const layout = getInfoFor (i);
  49753. if (layout != 0)
  49754. pos += layout->currentSize;
  49755. }
  49756. return pos;
  49757. }
  49758. int StretchableLayoutManager::getItemCurrentAbsoluteSize (const int itemIndex) const
  49759. {
  49760. const ItemLayoutProperties* const layout = getInfoFor (itemIndex);
  49761. if (layout != 0)
  49762. return layout->currentSize;
  49763. return 0;
  49764. }
  49765. double StretchableLayoutManager::getItemCurrentRelativeSize (const int itemIndex) const
  49766. {
  49767. const ItemLayoutProperties* const layout = getInfoFor (itemIndex);
  49768. if (layout != 0)
  49769. return -layout->currentSize / (double) totalSize;
  49770. return 0;
  49771. }
  49772. void StretchableLayoutManager::setItemPosition (const int itemIndex,
  49773. int newPosition)
  49774. {
  49775. for (int i = items.size(); --i >= 0;)
  49776. {
  49777. const ItemLayoutProperties* const layout = items.getUnchecked(i);
  49778. if (layout->itemIndex == itemIndex)
  49779. {
  49780. int realTotalSize = jmax (totalSize, getMinimumSizeOfItems (0, items.size()));
  49781. const int minSizeAfterThisComp = getMinimumSizeOfItems (i, items.size());
  49782. const int maxSizeAfterThisComp = getMaximumSizeOfItems (i + 1, items.size());
  49783. newPosition = jmax (newPosition, totalSize - maxSizeAfterThisComp - layout->currentSize);
  49784. newPosition = jmin (newPosition, realTotalSize - minSizeAfterThisComp);
  49785. int endPos = fitComponentsIntoSpace (0, i, newPosition, 0);
  49786. endPos += layout->currentSize;
  49787. fitComponentsIntoSpace (i + 1, items.size(), totalSize - endPos, endPos);
  49788. updatePrefSizesToMatchCurrentPositions();
  49789. break;
  49790. }
  49791. }
  49792. }
  49793. void StretchableLayoutManager::layOutComponents (Component** const components,
  49794. int numComponents,
  49795. int x, int y, int w, int h,
  49796. const bool vertically,
  49797. const bool resizeOtherDimension)
  49798. {
  49799. setTotalSize (vertically ? h : w);
  49800. int pos = vertically ? y : x;
  49801. for (int i = 0; i < numComponents; ++i)
  49802. {
  49803. const ItemLayoutProperties* const layout = getInfoFor (i);
  49804. if (layout != 0)
  49805. {
  49806. Component* const c = components[i];
  49807. if (c != 0)
  49808. {
  49809. if (i == numComponents - 1)
  49810. {
  49811. // if it's the last item, crop it to exactly fit the available space..
  49812. if (resizeOtherDimension)
  49813. {
  49814. if (vertically)
  49815. c->setBounds (x, pos, w, jmax (layout->currentSize, h - pos));
  49816. else
  49817. c->setBounds (pos, y, jmax (layout->currentSize, w - pos), h);
  49818. }
  49819. else
  49820. {
  49821. if (vertically)
  49822. c->setBounds (c->getX(), pos, c->getWidth(), jmax (layout->currentSize, h - pos));
  49823. else
  49824. c->setBounds (pos, c->getY(), jmax (layout->currentSize, w - pos), c->getHeight());
  49825. }
  49826. }
  49827. else
  49828. {
  49829. if (resizeOtherDimension)
  49830. {
  49831. if (vertically)
  49832. c->setBounds (x, pos, w, layout->currentSize);
  49833. else
  49834. c->setBounds (pos, y, layout->currentSize, h);
  49835. }
  49836. else
  49837. {
  49838. if (vertically)
  49839. c->setBounds (c->getX(), pos, c->getWidth(), layout->currentSize);
  49840. else
  49841. c->setBounds (pos, c->getY(), layout->currentSize, c->getHeight());
  49842. }
  49843. }
  49844. }
  49845. pos += layout->currentSize;
  49846. }
  49847. }
  49848. }
  49849. StretchableLayoutManager::ItemLayoutProperties* StretchableLayoutManager::getInfoFor (const int itemIndex) const
  49850. {
  49851. for (int i = items.size(); --i >= 0;)
  49852. if (items.getUnchecked(i)->itemIndex == itemIndex)
  49853. return items.getUnchecked(i);
  49854. return 0;
  49855. }
  49856. int StretchableLayoutManager::fitComponentsIntoSpace (const int startIndex,
  49857. const int endIndex,
  49858. const int availableSpace,
  49859. int startPos)
  49860. {
  49861. // calculate the total sizes
  49862. int i;
  49863. double totalIdealSize = 0.0;
  49864. int totalMinimums = 0;
  49865. for (i = startIndex; i < endIndex; ++i)
  49866. {
  49867. ItemLayoutProperties* const layout = items.getUnchecked (i);
  49868. layout->currentSize = sizeToRealSize (layout->minSize, totalSize);
  49869. totalMinimums += layout->currentSize;
  49870. totalIdealSize += sizeToRealSize (layout->preferredSize, availableSpace);
  49871. }
  49872. if (totalIdealSize <= 0)
  49873. totalIdealSize = 1.0;
  49874. // now calc the best sizes..
  49875. int extraSpace = availableSpace - totalMinimums;
  49876. while (extraSpace > 0)
  49877. {
  49878. int numWantingMoreSpace = 0;
  49879. int numHavingTakenExtraSpace = 0;
  49880. // first figure out how many comps want a slice of the extra space..
  49881. for (i = startIndex; i < endIndex; ++i)
  49882. {
  49883. ItemLayoutProperties* const layout = items.getUnchecked (i);
  49884. double sizeWanted = sizeToRealSize (layout->preferredSize, availableSpace);
  49885. const int bestSize = jlimit (layout->currentSize,
  49886. jmax (layout->currentSize,
  49887. sizeToRealSize (layout->maxSize, totalSize)),
  49888. roundToInt (sizeWanted * availableSpace / totalIdealSize));
  49889. if (bestSize > layout->currentSize)
  49890. ++numWantingMoreSpace;
  49891. }
  49892. // ..share out the extra space..
  49893. for (i = startIndex; i < endIndex; ++i)
  49894. {
  49895. ItemLayoutProperties* const layout = items.getUnchecked (i);
  49896. double sizeWanted = sizeToRealSize (layout->preferredSize, availableSpace);
  49897. int bestSize = jlimit (layout->currentSize,
  49898. jmax (layout->currentSize, sizeToRealSize (layout->maxSize, totalSize)),
  49899. roundToInt (sizeWanted * availableSpace / totalIdealSize));
  49900. const int extraWanted = bestSize - layout->currentSize;
  49901. if (extraWanted > 0)
  49902. {
  49903. const int extraAllowed = jmin (extraWanted,
  49904. extraSpace / jmax (1, numWantingMoreSpace));
  49905. if (extraAllowed > 0)
  49906. {
  49907. ++numHavingTakenExtraSpace;
  49908. --numWantingMoreSpace;
  49909. layout->currentSize += extraAllowed;
  49910. extraSpace -= extraAllowed;
  49911. }
  49912. }
  49913. }
  49914. if (numHavingTakenExtraSpace <= 0)
  49915. break;
  49916. }
  49917. // ..and calculate the end position
  49918. for (i = startIndex; i < endIndex; ++i)
  49919. {
  49920. ItemLayoutProperties* const layout = items.getUnchecked(i);
  49921. startPos += layout->currentSize;
  49922. }
  49923. return startPos;
  49924. }
  49925. int StretchableLayoutManager::getMinimumSizeOfItems (const int startIndex,
  49926. const int endIndex) const
  49927. {
  49928. int totalMinimums = 0;
  49929. for (int i = startIndex; i < endIndex; ++i)
  49930. totalMinimums += sizeToRealSize (items.getUnchecked (i)->minSize, totalSize);
  49931. return totalMinimums;
  49932. }
  49933. int StretchableLayoutManager::getMaximumSizeOfItems (const int startIndex, const int endIndex) const
  49934. {
  49935. int totalMaximums = 0;
  49936. for (int i = startIndex; i < endIndex; ++i)
  49937. totalMaximums += sizeToRealSize (items.getUnchecked (i)->maxSize, totalSize);
  49938. return totalMaximums;
  49939. }
  49940. void StretchableLayoutManager::updatePrefSizesToMatchCurrentPositions()
  49941. {
  49942. for (int i = 0; i < items.size(); ++i)
  49943. {
  49944. ItemLayoutProperties* const layout = items.getUnchecked (i);
  49945. layout->preferredSize
  49946. = (layout->preferredSize < 0) ? getItemCurrentRelativeSize (i)
  49947. : getItemCurrentAbsoluteSize (i);
  49948. }
  49949. }
  49950. int StretchableLayoutManager::sizeToRealSize (double size, int totalSpace)
  49951. {
  49952. if (size < 0)
  49953. size *= -totalSpace;
  49954. return roundToInt (size);
  49955. }
  49956. END_JUCE_NAMESPACE
  49957. /*** End of inlined file: juce_StretchableLayoutManager.cpp ***/
  49958. /*** Start of inlined file: juce_StretchableLayoutResizerBar.cpp ***/
  49959. BEGIN_JUCE_NAMESPACE
  49960. StretchableLayoutResizerBar::StretchableLayoutResizerBar (StretchableLayoutManager* layout_,
  49961. const int itemIndex_,
  49962. const bool isVertical_)
  49963. : layout (layout_),
  49964. itemIndex (itemIndex_),
  49965. isVertical (isVertical_)
  49966. {
  49967. setRepaintsOnMouseActivity (true);
  49968. setMouseCursor (MouseCursor (isVertical_ ? MouseCursor::LeftRightResizeCursor
  49969. : MouseCursor::UpDownResizeCursor));
  49970. }
  49971. StretchableLayoutResizerBar::~StretchableLayoutResizerBar()
  49972. {
  49973. }
  49974. void StretchableLayoutResizerBar::paint (Graphics& g)
  49975. {
  49976. getLookAndFeel().drawStretchableLayoutResizerBar (g,
  49977. getWidth(), getHeight(),
  49978. isVertical,
  49979. isMouseOver(),
  49980. isMouseButtonDown());
  49981. }
  49982. void StretchableLayoutResizerBar::mouseDown (const MouseEvent&)
  49983. {
  49984. mouseDownPos = layout->getItemCurrentPosition (itemIndex);
  49985. }
  49986. void StretchableLayoutResizerBar::mouseDrag (const MouseEvent& e)
  49987. {
  49988. const int desiredPos = mouseDownPos + (isVertical ? e.getDistanceFromDragStartX()
  49989. : e.getDistanceFromDragStartY());
  49990. layout->setItemPosition (itemIndex, desiredPos);
  49991. hasBeenMoved();
  49992. }
  49993. void StretchableLayoutResizerBar::hasBeenMoved()
  49994. {
  49995. if (getParentComponent() != 0)
  49996. getParentComponent()->resized();
  49997. }
  49998. END_JUCE_NAMESPACE
  49999. /*** End of inlined file: juce_StretchableLayoutResizerBar.cpp ***/
  50000. /*** Start of inlined file: juce_StretchableObjectResizer.cpp ***/
  50001. BEGIN_JUCE_NAMESPACE
  50002. StretchableObjectResizer::StretchableObjectResizer()
  50003. {
  50004. }
  50005. StretchableObjectResizer::~StretchableObjectResizer()
  50006. {
  50007. }
  50008. void StretchableObjectResizer::addItem (const double size,
  50009. const double minSize, const double maxSize,
  50010. const int order)
  50011. {
  50012. // the order must be >= 0 but less than the maximum integer value.
  50013. jassert (order >= 0 && order < std::numeric_limits<int>::max());
  50014. Item* const item = new Item();
  50015. item->size = size;
  50016. item->minSize = minSize;
  50017. item->maxSize = maxSize;
  50018. item->order = order;
  50019. items.add (item);
  50020. }
  50021. double StretchableObjectResizer::getItemSize (const int index) const throw()
  50022. {
  50023. const Item* const it = items [index];
  50024. return it != 0 ? it->size : 0;
  50025. }
  50026. void StretchableObjectResizer::resizeToFit (const double targetSize)
  50027. {
  50028. int order = 0;
  50029. for (;;)
  50030. {
  50031. double currentSize = 0;
  50032. double minSize = 0;
  50033. double maxSize = 0;
  50034. int nextHighestOrder = std::numeric_limits<int>::max();
  50035. for (int i = 0; i < items.size(); ++i)
  50036. {
  50037. const Item* const it = items.getUnchecked(i);
  50038. currentSize += it->size;
  50039. if (it->order <= order)
  50040. {
  50041. minSize += it->minSize;
  50042. maxSize += it->maxSize;
  50043. }
  50044. else
  50045. {
  50046. minSize += it->size;
  50047. maxSize += it->size;
  50048. nextHighestOrder = jmin (nextHighestOrder, it->order);
  50049. }
  50050. }
  50051. const double thisIterationTarget = jlimit (minSize, maxSize, targetSize);
  50052. if (thisIterationTarget >= currentSize)
  50053. {
  50054. const double availableExtraSpace = maxSize - currentSize;
  50055. const double targetAmountOfExtraSpace = thisIterationTarget - currentSize;
  50056. const double scale = targetAmountOfExtraSpace / availableExtraSpace;
  50057. for (int i = 0; i < items.size(); ++i)
  50058. {
  50059. Item* const it = items.getUnchecked(i);
  50060. if (it->order <= order)
  50061. it->size = jmin (it->maxSize, it->size + (it->maxSize - it->size) * scale);
  50062. }
  50063. }
  50064. else
  50065. {
  50066. const double amountOfSlack = currentSize - minSize;
  50067. const double targetAmountOfSlack = thisIterationTarget - minSize;
  50068. const double scale = targetAmountOfSlack / amountOfSlack;
  50069. for (int i = 0; i < items.size(); ++i)
  50070. {
  50071. Item* const it = items.getUnchecked(i);
  50072. if (it->order <= order)
  50073. it->size = jmax (it->minSize, it->minSize + (it->size - it->minSize) * scale);
  50074. }
  50075. }
  50076. if (nextHighestOrder < std::numeric_limits<int>::max())
  50077. order = nextHighestOrder;
  50078. else
  50079. break;
  50080. }
  50081. }
  50082. END_JUCE_NAMESPACE
  50083. /*** End of inlined file: juce_StretchableObjectResizer.cpp ***/
  50084. /*** Start of inlined file: juce_TabbedButtonBar.cpp ***/
  50085. BEGIN_JUCE_NAMESPACE
  50086. TabBarButton::TabBarButton (const String& name,
  50087. TabbedButtonBar* const owner_,
  50088. const int index)
  50089. : Button (name),
  50090. owner (owner_),
  50091. tabIndex (index),
  50092. overlapPixels (0)
  50093. {
  50094. shadow.setShadowProperties (2.2f, 0.7f, 0, 0);
  50095. setComponentEffect (&shadow);
  50096. setWantsKeyboardFocus (false);
  50097. }
  50098. TabBarButton::~TabBarButton()
  50099. {
  50100. }
  50101. void TabBarButton::paintButton (Graphics& g,
  50102. bool isMouseOverButton,
  50103. bool isButtonDown)
  50104. {
  50105. int x, y, w, h;
  50106. getActiveArea (x, y, w, h);
  50107. g.setOrigin (x, y);
  50108. getLookAndFeel()
  50109. .drawTabButton (g, w, h,
  50110. owner->getTabBackgroundColour (tabIndex),
  50111. tabIndex, getButtonText(), *this,
  50112. owner->getOrientation(),
  50113. isMouseOverButton, isButtonDown,
  50114. getToggleState());
  50115. }
  50116. void TabBarButton::clicked (const ModifierKeys& mods)
  50117. {
  50118. if (mods.isPopupMenu())
  50119. owner->popupMenuClickOnTab (tabIndex, getButtonText());
  50120. else
  50121. owner->setCurrentTabIndex (tabIndex);
  50122. }
  50123. bool TabBarButton::hitTest (int mx, int my)
  50124. {
  50125. int x, y, w, h;
  50126. getActiveArea (x, y, w, h);
  50127. if (owner->getOrientation() == TabbedButtonBar::TabsAtLeft
  50128. || owner->getOrientation() == TabbedButtonBar::TabsAtRight)
  50129. {
  50130. if (((unsigned int) mx) < (unsigned int) getWidth()
  50131. && my >= y + overlapPixels
  50132. && my < y + h - overlapPixels)
  50133. return true;
  50134. }
  50135. else
  50136. {
  50137. if (mx >= x + overlapPixels && mx < x + w - overlapPixels
  50138. && ((unsigned int) my) < (unsigned int) getHeight())
  50139. return true;
  50140. }
  50141. Path p;
  50142. getLookAndFeel()
  50143. .createTabButtonShape (p, w, h, tabIndex, getButtonText(), *this,
  50144. owner->getOrientation(),
  50145. false, false, getToggleState());
  50146. return p.contains ((float) (mx - x),
  50147. (float) (my - y));
  50148. }
  50149. int TabBarButton::getBestTabLength (const int depth)
  50150. {
  50151. return jlimit (depth * 2,
  50152. depth * 7,
  50153. getLookAndFeel().getTabButtonBestWidth (tabIndex, getButtonText(), depth, *this));
  50154. }
  50155. void TabBarButton::getActiveArea (int& x, int& y, int& w, int& h)
  50156. {
  50157. x = 0;
  50158. y = 0;
  50159. int r = getWidth();
  50160. int b = getHeight();
  50161. const int spaceAroundImage = getLookAndFeel().getTabButtonSpaceAroundImage();
  50162. if (owner->getOrientation() != TabbedButtonBar::TabsAtLeft)
  50163. r -= spaceAroundImage;
  50164. if (owner->getOrientation() != TabbedButtonBar::TabsAtRight)
  50165. x += spaceAroundImage;
  50166. if (owner->getOrientation() != TabbedButtonBar::TabsAtBottom)
  50167. y += spaceAroundImage;
  50168. if (owner->getOrientation() != TabbedButtonBar::TabsAtTop)
  50169. b -= spaceAroundImage;
  50170. w = r - x;
  50171. h = b - y;
  50172. }
  50173. class TabAreaBehindFrontButtonComponent : public Component
  50174. {
  50175. public:
  50176. TabAreaBehindFrontButtonComponent (TabbedButtonBar* const owner_)
  50177. : owner (owner_)
  50178. {
  50179. setInterceptsMouseClicks (false, false);
  50180. }
  50181. ~TabAreaBehindFrontButtonComponent()
  50182. {
  50183. }
  50184. void paint (Graphics& g)
  50185. {
  50186. getLookAndFeel()
  50187. .drawTabAreaBehindFrontButton (g, getWidth(), getHeight(),
  50188. *owner, owner->getOrientation());
  50189. }
  50190. void enablementChanged()
  50191. {
  50192. repaint();
  50193. }
  50194. private:
  50195. TabbedButtonBar* const owner;
  50196. TabAreaBehindFrontButtonComponent (const TabAreaBehindFrontButtonComponent&);
  50197. TabAreaBehindFrontButtonComponent& operator= (const TabAreaBehindFrontButtonComponent&);
  50198. };
  50199. TabbedButtonBar::TabbedButtonBar (const Orientation orientation_)
  50200. : orientation (orientation_),
  50201. currentTabIndex (-1),
  50202. extraTabsButton (0)
  50203. {
  50204. setInterceptsMouseClicks (false, true);
  50205. addAndMakeVisible (behindFrontTab = new TabAreaBehindFrontButtonComponent (this));
  50206. setFocusContainer (true);
  50207. }
  50208. TabbedButtonBar::~TabbedButtonBar()
  50209. {
  50210. deleteAllChildren();
  50211. }
  50212. void TabbedButtonBar::setOrientation (const Orientation newOrientation)
  50213. {
  50214. orientation = newOrientation;
  50215. for (int i = getNumChildComponents(); --i >= 0;)
  50216. getChildComponent (i)->resized();
  50217. resized();
  50218. }
  50219. TabBarButton* TabbedButtonBar::createTabButton (const String& name, const int index)
  50220. {
  50221. return new TabBarButton (name, this, index);
  50222. }
  50223. void TabbedButtonBar::clearTabs()
  50224. {
  50225. tabs.clear();
  50226. tabColours.clear();
  50227. currentTabIndex = -1;
  50228. deleteAndZero (extraTabsButton);
  50229. removeChildComponent (behindFrontTab);
  50230. deleteAllChildren();
  50231. addChildComponent (behindFrontTab);
  50232. setCurrentTabIndex (-1);
  50233. }
  50234. void TabbedButtonBar::addTab (const String& tabName,
  50235. const Colour& tabBackgroundColour,
  50236. int insertIndex)
  50237. {
  50238. jassert (tabName.isNotEmpty()); // you have to give them all a name..
  50239. if (tabName.isNotEmpty())
  50240. {
  50241. if (((unsigned int) insertIndex) > (unsigned int) tabs.size())
  50242. insertIndex = tabs.size();
  50243. for (int i = tabs.size(); --i >= insertIndex;)
  50244. {
  50245. TabBarButton* const tb = getTabButton (i);
  50246. if (tb != 0)
  50247. tb->tabIndex++;
  50248. }
  50249. tabs.insert (insertIndex, tabName);
  50250. tabColours.insert (insertIndex, tabBackgroundColour);
  50251. TabBarButton* const tb = createTabButton (tabName, insertIndex);
  50252. jassert (tb != 0); // your createTabButton() mustn't return zero!
  50253. addAndMakeVisible (tb, insertIndex);
  50254. resized();
  50255. if (currentTabIndex < 0)
  50256. setCurrentTabIndex (0);
  50257. }
  50258. }
  50259. void TabbedButtonBar::setTabName (const int tabIndex,
  50260. const String& newName)
  50261. {
  50262. if (((unsigned int) tabIndex) < (unsigned int) tabs.size()
  50263. && tabs[tabIndex] != newName)
  50264. {
  50265. tabs.set (tabIndex, newName);
  50266. TabBarButton* const tb = getTabButton (tabIndex);
  50267. if (tb != 0)
  50268. tb->setButtonText (newName);
  50269. resized();
  50270. }
  50271. }
  50272. void TabbedButtonBar::removeTab (const int tabIndex)
  50273. {
  50274. if (((unsigned int) tabIndex) < (unsigned int) tabs.size())
  50275. {
  50276. const int oldTabIndex = currentTabIndex;
  50277. if (currentTabIndex == tabIndex)
  50278. currentTabIndex = -1;
  50279. tabs.remove (tabIndex);
  50280. tabColours.remove (tabIndex);
  50281. delete getTabButton (tabIndex);
  50282. for (int i = tabIndex + 1; i <= tabs.size(); ++i)
  50283. {
  50284. TabBarButton* const tb = getTabButton (i);
  50285. if (tb != 0)
  50286. tb->tabIndex--;
  50287. }
  50288. resized();
  50289. setCurrentTabIndex (jlimit (0, jmax (0, tabs.size() - 1), oldTabIndex));
  50290. }
  50291. }
  50292. void TabbedButtonBar::moveTab (const int currentIndex,
  50293. const int newIndex)
  50294. {
  50295. tabs.move (currentIndex, newIndex);
  50296. tabColours.move (currentIndex, newIndex);
  50297. resized();
  50298. }
  50299. int TabbedButtonBar::getNumTabs() const
  50300. {
  50301. return tabs.size();
  50302. }
  50303. const StringArray TabbedButtonBar::getTabNames() const
  50304. {
  50305. return tabs;
  50306. }
  50307. void TabbedButtonBar::setCurrentTabIndex (int newIndex, const bool sendChangeMessage_)
  50308. {
  50309. if (currentTabIndex != newIndex)
  50310. {
  50311. if (((unsigned int) newIndex) >= (unsigned int) tabs.size())
  50312. newIndex = -1;
  50313. currentTabIndex = newIndex;
  50314. for (int i = 0; i < getNumChildComponents(); ++i)
  50315. {
  50316. TabBarButton* const tb = dynamic_cast <TabBarButton*> (getChildComponent (i));
  50317. if (tb != 0)
  50318. tb->setToggleState (tb->tabIndex == newIndex, false);
  50319. }
  50320. resized();
  50321. if (sendChangeMessage_)
  50322. sendChangeMessage (this);
  50323. currentTabChanged (newIndex, newIndex >= 0 ? tabs [newIndex] : String::empty);
  50324. }
  50325. }
  50326. TabBarButton* TabbedButtonBar::getTabButton (const int index) const
  50327. {
  50328. for (int i = getNumChildComponents(); --i >= 0;)
  50329. {
  50330. TabBarButton* const tb = dynamic_cast <TabBarButton*> (getChildComponent (i));
  50331. if (tb != 0 && tb->tabIndex == index)
  50332. return tb;
  50333. }
  50334. return 0;
  50335. }
  50336. void TabbedButtonBar::lookAndFeelChanged()
  50337. {
  50338. deleteAndZero (extraTabsButton);
  50339. resized();
  50340. }
  50341. void TabbedButtonBar::resized()
  50342. {
  50343. const double minimumScale = 0.7;
  50344. int depth = getWidth();
  50345. int length = getHeight();
  50346. if (orientation == TabsAtTop || orientation == TabsAtBottom)
  50347. swapVariables (depth, length);
  50348. const int overlap = getLookAndFeel().getTabButtonOverlap (depth)
  50349. + getLookAndFeel().getTabButtonSpaceAroundImage() * 2;
  50350. int i, totalLength = overlap;
  50351. int numVisibleButtons = tabs.size();
  50352. for (i = 0; i < getNumChildComponents(); ++i)
  50353. {
  50354. TabBarButton* const tb = dynamic_cast <TabBarButton*> (getChildComponent (i));
  50355. if (tb != 0)
  50356. {
  50357. totalLength += tb->getBestTabLength (depth) - overlap;
  50358. tb->overlapPixels = overlap / 2;
  50359. }
  50360. }
  50361. double scale = 1.0;
  50362. if (totalLength > length)
  50363. scale = jmax (minimumScale, length / (double) totalLength);
  50364. const bool isTooBig = totalLength * scale > length;
  50365. int tabsButtonPos = 0;
  50366. if (isTooBig)
  50367. {
  50368. if (extraTabsButton == 0)
  50369. {
  50370. addAndMakeVisible (extraTabsButton = getLookAndFeel().createTabBarExtrasButton());
  50371. extraTabsButton->addButtonListener (this);
  50372. extraTabsButton->setAlwaysOnTop (true);
  50373. extraTabsButton->setTriggeredOnMouseDown (true);
  50374. }
  50375. const int buttonSize = jmin (proportionOfWidth (0.7f), proportionOfHeight (0.7f));
  50376. extraTabsButton->setSize (buttonSize, buttonSize);
  50377. if (orientation == TabsAtTop || orientation == TabsAtBottom)
  50378. {
  50379. tabsButtonPos = getWidth() - buttonSize / 2 - 1;
  50380. extraTabsButton->setCentrePosition (tabsButtonPos, getHeight() / 2);
  50381. }
  50382. else
  50383. {
  50384. tabsButtonPos = getHeight() - buttonSize / 2 - 1;
  50385. extraTabsButton->setCentrePosition (getWidth() / 2, tabsButtonPos);
  50386. }
  50387. totalLength = 0;
  50388. for (i = 0; i < tabs.size(); ++i)
  50389. {
  50390. TabBarButton* const tb = getTabButton (i);
  50391. if (tb != 0)
  50392. {
  50393. const int newLength = totalLength + tb->getBestTabLength (depth);
  50394. if (i > 0 && newLength * minimumScale > tabsButtonPos)
  50395. {
  50396. totalLength += overlap;
  50397. break;
  50398. }
  50399. numVisibleButtons = i + 1;
  50400. totalLength = newLength - overlap;
  50401. }
  50402. }
  50403. scale = jmax (minimumScale, tabsButtonPos / (double) totalLength);
  50404. }
  50405. else
  50406. {
  50407. deleteAndZero (extraTabsButton);
  50408. }
  50409. int pos = 0;
  50410. TabBarButton* frontTab = 0;
  50411. for (i = 0; i < tabs.size(); ++i)
  50412. {
  50413. TabBarButton* const tb = getTabButton (i);
  50414. if (tb != 0)
  50415. {
  50416. const int bestLength = roundToInt (scale * tb->getBestTabLength (depth));
  50417. if (i < numVisibleButtons)
  50418. {
  50419. if (orientation == TabsAtTop || orientation == TabsAtBottom)
  50420. tb->setBounds (pos, 0, bestLength, getHeight());
  50421. else
  50422. tb->setBounds (0, pos, getWidth(), bestLength);
  50423. tb->toBack();
  50424. if (tb->tabIndex == currentTabIndex)
  50425. frontTab = tb;
  50426. tb->setVisible (true);
  50427. }
  50428. else
  50429. {
  50430. tb->setVisible (false);
  50431. }
  50432. pos += bestLength - overlap;
  50433. }
  50434. }
  50435. behindFrontTab->setBounds (0, 0, getWidth(), getHeight());
  50436. if (frontTab != 0)
  50437. {
  50438. frontTab->toFront (false);
  50439. behindFrontTab->toBehind (frontTab);
  50440. }
  50441. }
  50442. const Colour TabbedButtonBar::getTabBackgroundColour (const int tabIndex)
  50443. {
  50444. return tabColours [tabIndex];
  50445. }
  50446. void TabbedButtonBar::setTabBackgroundColour (const int tabIndex, const Colour& newColour)
  50447. {
  50448. if (((unsigned int) tabIndex) < (unsigned int) tabColours.size()
  50449. && tabColours [tabIndex] != newColour)
  50450. {
  50451. tabColours.set (tabIndex, newColour);
  50452. repaint();
  50453. }
  50454. }
  50455. void TabbedButtonBar::buttonClicked (Button* button)
  50456. {
  50457. if (extraTabsButton == button)
  50458. {
  50459. PopupMenu m;
  50460. for (int i = 0; i < tabs.size(); ++i)
  50461. {
  50462. TabBarButton* const tb = getTabButton (i);
  50463. if (tb != 0 && ! tb->isVisible())
  50464. m.addItem (tb->tabIndex + 1, tabs[i], true, i == currentTabIndex);
  50465. }
  50466. const int res = m.showAt (extraTabsButton);
  50467. if (res != 0)
  50468. setCurrentTabIndex (res - 1);
  50469. }
  50470. }
  50471. void TabbedButtonBar::currentTabChanged (const int, const String&)
  50472. {
  50473. }
  50474. void TabbedButtonBar::popupMenuClickOnTab (const int, const String&)
  50475. {
  50476. }
  50477. END_JUCE_NAMESPACE
  50478. /*** End of inlined file: juce_TabbedButtonBar.cpp ***/
  50479. /*** Start of inlined file: juce_TabbedComponent.cpp ***/
  50480. BEGIN_JUCE_NAMESPACE
  50481. class TabCompButtonBar : public TabbedButtonBar
  50482. {
  50483. public:
  50484. TabCompButtonBar (TabbedComponent* const owner_,
  50485. const TabbedButtonBar::Orientation orientation)
  50486. : TabbedButtonBar (orientation),
  50487. owner (owner_)
  50488. {
  50489. }
  50490. ~TabCompButtonBar()
  50491. {
  50492. }
  50493. void currentTabChanged (const int newCurrentTabIndex,
  50494. const String& newTabName)
  50495. {
  50496. owner->changeCallback (newCurrentTabIndex, newTabName);
  50497. }
  50498. void popupMenuClickOnTab (const int tabIndex,
  50499. const String& tabName)
  50500. {
  50501. owner->popupMenuClickOnTab (tabIndex, tabName);
  50502. }
  50503. const Colour getTabBackgroundColour (const int tabIndex)
  50504. {
  50505. return owner->tabs->getTabBackgroundColour (tabIndex);
  50506. }
  50507. TabBarButton* createTabButton (const String& tabName, const int tabIndex)
  50508. {
  50509. return owner->createTabButton (tabName, tabIndex);
  50510. }
  50511. juce_UseDebuggingNewOperator
  50512. private:
  50513. TabbedComponent* const owner;
  50514. TabCompButtonBar (const TabCompButtonBar&);
  50515. TabCompButtonBar& operator= (const TabCompButtonBar&);
  50516. };
  50517. TabbedComponent::TabbedComponent (const TabbedButtonBar::Orientation orientation)
  50518. : panelComponent (0),
  50519. tabDepth (30),
  50520. outlineThickness (1),
  50521. edgeIndent (0)
  50522. {
  50523. addAndMakeVisible (tabs = new TabCompButtonBar (this, orientation));
  50524. }
  50525. TabbedComponent::~TabbedComponent()
  50526. {
  50527. clearTabs();
  50528. delete tabs;
  50529. }
  50530. void TabbedComponent::setOrientation (const TabbedButtonBar::Orientation orientation)
  50531. {
  50532. tabs->setOrientation (orientation);
  50533. resized();
  50534. }
  50535. TabbedButtonBar::Orientation TabbedComponent::getOrientation() const throw()
  50536. {
  50537. return tabs->getOrientation();
  50538. }
  50539. void TabbedComponent::setTabBarDepth (const int newDepth)
  50540. {
  50541. if (tabDepth != newDepth)
  50542. {
  50543. tabDepth = newDepth;
  50544. resized();
  50545. }
  50546. }
  50547. TabBarButton* TabbedComponent::createTabButton (const String& tabName, const int tabIndex)
  50548. {
  50549. return new TabBarButton (tabName, tabs, tabIndex);
  50550. }
  50551. void TabbedComponent::clearTabs()
  50552. {
  50553. if (panelComponent != 0)
  50554. {
  50555. panelComponent->setVisible (false);
  50556. removeChildComponent (panelComponent);
  50557. panelComponent = 0;
  50558. }
  50559. tabs->clearTabs();
  50560. for (int i = contentComponents.size(); --i >= 0;)
  50561. {
  50562. Component* const c = contentComponents.getUnchecked(i);
  50563. // be careful not to delete these components until they've been removed from the tab component
  50564. jassert (c == 0 || c->isValidComponent());
  50565. if (c != 0 && (bool) c->getProperties() ["deleteByTabComp_"])
  50566. delete c;
  50567. }
  50568. contentComponents.clear();
  50569. }
  50570. void TabbedComponent::addTab (const String& tabName,
  50571. const Colour& tabBackgroundColour,
  50572. Component* const contentComponent,
  50573. const bool deleteComponentWhenNotNeeded,
  50574. const int insertIndex)
  50575. {
  50576. contentComponents.insert (insertIndex, contentComponent);
  50577. if (contentComponent != 0)
  50578. contentComponent->getProperties().set ("deleteByTabComp_", deleteComponentWhenNotNeeded);
  50579. tabs->addTab (tabName, tabBackgroundColour, insertIndex);
  50580. }
  50581. void TabbedComponent::setTabName (const int tabIndex,
  50582. const String& newName)
  50583. {
  50584. tabs->setTabName (tabIndex, newName);
  50585. }
  50586. void TabbedComponent::removeTab (const int tabIndex)
  50587. {
  50588. Component* const c = contentComponents [tabIndex];
  50589. if (c != 0 && (bool) c->getProperties() ["deleteByTabComp_"])
  50590. {
  50591. if (c == panelComponent)
  50592. panelComponent = 0;
  50593. delete c;
  50594. }
  50595. contentComponents.remove (tabIndex);
  50596. tabs->removeTab (tabIndex);
  50597. }
  50598. int TabbedComponent::getNumTabs() const
  50599. {
  50600. return tabs->getNumTabs();
  50601. }
  50602. const StringArray TabbedComponent::getTabNames() const
  50603. {
  50604. return tabs->getTabNames();
  50605. }
  50606. Component* TabbedComponent::getTabContentComponent (const int tabIndex) const throw()
  50607. {
  50608. return contentComponents [tabIndex];
  50609. }
  50610. const Colour TabbedComponent::getTabBackgroundColour (const int tabIndex) const throw()
  50611. {
  50612. return tabs->getTabBackgroundColour (tabIndex);
  50613. }
  50614. void TabbedComponent::setTabBackgroundColour (const int tabIndex, const Colour& newColour)
  50615. {
  50616. tabs->setTabBackgroundColour (tabIndex, newColour);
  50617. if (getCurrentTabIndex() == tabIndex)
  50618. repaint();
  50619. }
  50620. void TabbedComponent::setCurrentTabIndex (const int newTabIndex, const bool sendChangeMessage)
  50621. {
  50622. tabs->setCurrentTabIndex (newTabIndex, sendChangeMessage);
  50623. }
  50624. int TabbedComponent::getCurrentTabIndex() const
  50625. {
  50626. return tabs->getCurrentTabIndex();
  50627. }
  50628. const String& TabbedComponent::getCurrentTabName() const
  50629. {
  50630. return tabs->getCurrentTabName();
  50631. }
  50632. void TabbedComponent::setOutline (int thickness)
  50633. {
  50634. outlineThickness = thickness;
  50635. repaint();
  50636. }
  50637. void TabbedComponent::setIndent (const int indentThickness)
  50638. {
  50639. edgeIndent = indentThickness;
  50640. }
  50641. void TabbedComponent::paint (Graphics& g)
  50642. {
  50643. g.fillAll (findColour (backgroundColourId));
  50644. const TabbedButtonBar::Orientation o = getOrientation();
  50645. int x = 0;
  50646. int y = 0;
  50647. int r = getWidth();
  50648. int b = getHeight();
  50649. if (o == TabbedButtonBar::TabsAtTop)
  50650. y += tabDepth;
  50651. else if (o == TabbedButtonBar::TabsAtBottom)
  50652. b -= tabDepth;
  50653. else if (o == TabbedButtonBar::TabsAtLeft)
  50654. x += tabDepth;
  50655. else if (o == TabbedButtonBar::TabsAtRight)
  50656. r -= tabDepth;
  50657. g.reduceClipRegion (x, y, r - x, b - y);
  50658. g.fillAll (tabs->getTabBackgroundColour (getCurrentTabIndex()));
  50659. if (outlineThickness > 0)
  50660. {
  50661. if (o == TabbedButtonBar::TabsAtTop)
  50662. --y;
  50663. else if (o == TabbedButtonBar::TabsAtBottom)
  50664. ++b;
  50665. else if (o == TabbedButtonBar::TabsAtLeft)
  50666. --x;
  50667. else if (o == TabbedButtonBar::TabsAtRight)
  50668. ++r;
  50669. g.setColour (findColour (outlineColourId));
  50670. g.drawRect (x, y, r - x, b - y, outlineThickness);
  50671. }
  50672. }
  50673. void TabbedComponent::resized()
  50674. {
  50675. const TabbedButtonBar::Orientation o = getOrientation();
  50676. const int indent = edgeIndent + outlineThickness;
  50677. BorderSize indents (indent);
  50678. if (o == TabbedButtonBar::TabsAtTop)
  50679. {
  50680. tabs->setBounds (0, 0, getWidth(), tabDepth);
  50681. indents.setTop (tabDepth + edgeIndent);
  50682. }
  50683. else if (o == TabbedButtonBar::TabsAtBottom)
  50684. {
  50685. tabs->setBounds (0, getHeight() - tabDepth, getWidth(), tabDepth);
  50686. indents.setBottom (tabDepth + edgeIndent);
  50687. }
  50688. else if (o == TabbedButtonBar::TabsAtLeft)
  50689. {
  50690. tabs->setBounds (0, 0, tabDepth, getHeight());
  50691. indents.setLeft (tabDepth + edgeIndent);
  50692. }
  50693. else if (o == TabbedButtonBar::TabsAtRight)
  50694. {
  50695. tabs->setBounds (getWidth() - tabDepth, 0, tabDepth, getHeight());
  50696. indents.setRight (tabDepth + edgeIndent);
  50697. }
  50698. const Rectangle<int> bounds (indents.subtractedFrom (Rectangle<int> (0, 0, getWidth(), getHeight())));
  50699. for (int i = contentComponents.size(); --i >= 0;)
  50700. if (contentComponents.getUnchecked (i) != 0)
  50701. contentComponents.getUnchecked (i)->setBounds (bounds);
  50702. }
  50703. void TabbedComponent::lookAndFeelChanged()
  50704. {
  50705. for (int i = contentComponents.size(); --i >= 0;)
  50706. if (contentComponents.getUnchecked (i) != 0)
  50707. contentComponents.getUnchecked (i)->lookAndFeelChanged();
  50708. }
  50709. void TabbedComponent::changeCallback (const int newCurrentTabIndex,
  50710. const String& newTabName)
  50711. {
  50712. if (panelComponent != 0)
  50713. {
  50714. panelComponent->setVisible (false);
  50715. removeChildComponent (panelComponent);
  50716. panelComponent = 0;
  50717. }
  50718. if (getCurrentTabIndex() >= 0)
  50719. {
  50720. panelComponent = contentComponents [getCurrentTabIndex()];
  50721. if (panelComponent != 0)
  50722. {
  50723. // do these ops as two stages instead of addAndMakeVisible() so that the
  50724. // component has always got a parent when it gets the visibilityChanged() callback
  50725. addChildComponent (panelComponent);
  50726. panelComponent->setVisible (true);
  50727. panelComponent->toFront (true);
  50728. }
  50729. repaint();
  50730. }
  50731. resized();
  50732. currentTabChanged (newCurrentTabIndex, newTabName);
  50733. }
  50734. void TabbedComponent::currentTabChanged (const int, const String&)
  50735. {
  50736. }
  50737. void TabbedComponent::popupMenuClickOnTab (const int, const String&)
  50738. {
  50739. }
  50740. END_JUCE_NAMESPACE
  50741. /*** End of inlined file: juce_TabbedComponent.cpp ***/
  50742. /*** Start of inlined file: juce_Viewport.cpp ***/
  50743. BEGIN_JUCE_NAMESPACE
  50744. Viewport::Viewport (const String& componentName)
  50745. : Component (componentName),
  50746. contentComp (0),
  50747. lastVX (0),
  50748. lastVY (0),
  50749. lastVW (0),
  50750. lastVH (0),
  50751. scrollBarThickness (0),
  50752. singleStepX (16),
  50753. singleStepY (16),
  50754. showHScrollbar (true),
  50755. showVScrollbar (true)
  50756. {
  50757. // content holder is used to clip the contents so they don't overlap the scrollbars
  50758. addAndMakeVisible (contentHolder = new Component());
  50759. contentHolder->setInterceptsMouseClicks (false, true);
  50760. verticalScrollBar = new ScrollBar (true);
  50761. horizontalScrollBar = new ScrollBar (false);
  50762. addChildComponent (verticalScrollBar);
  50763. addChildComponent (horizontalScrollBar);
  50764. verticalScrollBar->addListener (this);
  50765. horizontalScrollBar->addListener (this);
  50766. setInterceptsMouseClicks (false, true);
  50767. setWantsKeyboardFocus (true);
  50768. }
  50769. Viewport::~Viewport()
  50770. {
  50771. contentHolder->deleteAllChildren();
  50772. deleteAllChildren();
  50773. }
  50774. void Viewport::visibleAreaChanged (int, int, int, int)
  50775. {
  50776. }
  50777. void Viewport::setViewedComponent (Component* const newViewedComponent)
  50778. {
  50779. if (contentComp.getComponent() != newViewedComponent)
  50780. {
  50781. {
  50782. ScopedPointer<Component> oldCompDeleter (contentComp);
  50783. contentComp = 0;
  50784. }
  50785. contentComp = newViewedComponent;
  50786. if (contentComp != 0)
  50787. {
  50788. contentComp->setTopLeftPosition (0, 0);
  50789. contentHolder->addAndMakeVisible (contentComp);
  50790. contentComp->addComponentListener (this);
  50791. }
  50792. updateVisibleRegion();
  50793. }
  50794. }
  50795. int Viewport::getMaximumVisibleWidth() const throw()
  50796. {
  50797. return jmax (0, getWidth() - (verticalScrollBar->isVisible() ? getScrollBarThickness() : 0));
  50798. }
  50799. int Viewport::getMaximumVisibleHeight() const throw()
  50800. {
  50801. return jmax (0, getHeight() - (horizontalScrollBar->isVisible() ? getScrollBarThickness() : 0));
  50802. }
  50803. void Viewport::setViewPosition (const int xPixelsOffset,
  50804. const int yPixelsOffset)
  50805. {
  50806. if (contentComp != 0)
  50807. contentComp->setTopLeftPosition (-xPixelsOffset,
  50808. -yPixelsOffset);
  50809. }
  50810. void Viewport::setViewPositionProportionately (const double x,
  50811. const double y)
  50812. {
  50813. if (contentComp != 0)
  50814. setViewPosition (jmax (0, roundToInt (x * (contentComp->getWidth() - getWidth()))),
  50815. jmax (0, roundToInt (y * (contentComp->getHeight() - getHeight()))));
  50816. }
  50817. bool Viewport::autoScroll (int mouseX, int mouseY, int activeBorderThickness, int maximumSpeed)
  50818. {
  50819. if (contentComp != 0)
  50820. {
  50821. int dx = 0, dy = 0;
  50822. if (mouseX < activeBorderThickness)
  50823. dx = activeBorderThickness - mouseX;
  50824. else if (mouseX >= contentHolder->getWidth() - activeBorderThickness)
  50825. dx = (contentHolder->getWidth() - activeBorderThickness) - mouseX;
  50826. if (dx < 0)
  50827. dx = jmax (dx, -maximumSpeed, contentHolder->getWidth() - contentComp->getRight());
  50828. else
  50829. dx = jmin (dx, maximumSpeed, -contentComp->getX());
  50830. if (mouseY < activeBorderThickness)
  50831. dy = activeBorderThickness - mouseY;
  50832. else if (mouseY >= contentHolder->getHeight() - activeBorderThickness)
  50833. dy = (contentHolder->getHeight() - activeBorderThickness) - mouseY;
  50834. if (dy < 0)
  50835. dy = jmax (dy, -maximumSpeed, contentHolder->getHeight() - contentComp->getBottom());
  50836. else
  50837. dy = jmin (dy, maximumSpeed, -contentComp->getY());
  50838. if (dx != 0 || dy != 0)
  50839. {
  50840. contentComp->setTopLeftPosition (contentComp->getX() + dx,
  50841. contentComp->getY() + dy);
  50842. return true;
  50843. }
  50844. }
  50845. return false;
  50846. }
  50847. void Viewport::componentMovedOrResized (Component&, bool, bool)
  50848. {
  50849. updateVisibleRegion();
  50850. }
  50851. void Viewport::resized()
  50852. {
  50853. updateVisibleRegion();
  50854. }
  50855. void Viewport::updateVisibleRegion()
  50856. {
  50857. if (contentComp != 0)
  50858. {
  50859. const int newVX = -contentComp->getX();
  50860. const int newVY = -contentComp->getY();
  50861. if (newVX == 0 && newVY == 0
  50862. && contentComp->getWidth() <= getWidth()
  50863. && contentComp->getHeight() <= getHeight())
  50864. {
  50865. horizontalScrollBar->setVisible (false);
  50866. verticalScrollBar->setVisible (false);
  50867. }
  50868. horizontalScrollBar->setRangeLimits (0.0, contentComp->getWidth());
  50869. horizontalScrollBar->setCurrentRange (newVX, getMaximumVisibleWidth());
  50870. horizontalScrollBar->setSingleStepSize (singleStepX);
  50871. if (! (contentComp->getWidth() > 0 && showHScrollbar && getHeight() > getScrollBarThickness()))
  50872. horizontalScrollBar->setVisible (false);
  50873. verticalScrollBar->setRangeLimits (0.0, contentComp->getHeight());
  50874. verticalScrollBar->setCurrentRange (newVY, getMaximumVisibleHeight());
  50875. verticalScrollBar->setSingleStepSize (singleStepY);
  50876. if (! (contentComp->getHeight() > 0 && showVScrollbar && getWidth() > getScrollBarThickness()))
  50877. verticalScrollBar->setVisible (false);
  50878. if (verticalScrollBar->isVisible())
  50879. {
  50880. horizontalScrollBar->setCurrentRange (newVX, getMaximumVisibleWidth());
  50881. verticalScrollBar->setCurrentRange (newVY, getMaximumVisibleHeight());
  50882. verticalScrollBar
  50883. ->setBounds (getMaximumVisibleWidth(), 0,
  50884. getScrollBarThickness(), getMaximumVisibleHeight());
  50885. }
  50886. if (horizontalScrollBar->isVisible())
  50887. {
  50888. horizontalScrollBar->setCurrentRange (newVX, getMaximumVisibleWidth());
  50889. horizontalScrollBar
  50890. ->setBounds (0, getMaximumVisibleHeight(),
  50891. getMaximumVisibleWidth(), getScrollBarThickness());
  50892. }
  50893. contentHolder->setSize (getMaximumVisibleWidth(),
  50894. getMaximumVisibleHeight());
  50895. const int newVW = jmin (contentComp->getRight(), getMaximumVisibleWidth());
  50896. const int newVH = jmin (contentComp->getBottom(), getMaximumVisibleHeight());
  50897. if (newVX != lastVX
  50898. || newVY != lastVY
  50899. || newVW != lastVW
  50900. || newVH != lastVH)
  50901. {
  50902. lastVX = newVX;
  50903. lastVY = newVY;
  50904. lastVW = newVW;
  50905. lastVH = newVH;
  50906. visibleAreaChanged (newVX, newVY, newVW, newVH);
  50907. }
  50908. horizontalScrollBar->handleUpdateNowIfNeeded();
  50909. verticalScrollBar->handleUpdateNowIfNeeded();
  50910. }
  50911. else
  50912. {
  50913. horizontalScrollBar->setVisible (false);
  50914. verticalScrollBar->setVisible (false);
  50915. }
  50916. }
  50917. void Viewport::setSingleStepSizes (const int stepX,
  50918. const int stepY)
  50919. {
  50920. singleStepX = stepX;
  50921. singleStepY = stepY;
  50922. updateVisibleRegion();
  50923. }
  50924. void Viewport::setScrollBarsShown (const bool showVerticalScrollbarIfNeeded,
  50925. const bool showHorizontalScrollbarIfNeeded)
  50926. {
  50927. showVScrollbar = showVerticalScrollbarIfNeeded;
  50928. showHScrollbar = showHorizontalScrollbarIfNeeded;
  50929. updateVisibleRegion();
  50930. }
  50931. void Viewport::setScrollBarThickness (const int thickness)
  50932. {
  50933. scrollBarThickness = thickness;
  50934. updateVisibleRegion();
  50935. }
  50936. int Viewport::getScrollBarThickness() const throw()
  50937. {
  50938. return (scrollBarThickness > 0) ? scrollBarThickness
  50939. : getLookAndFeel().getDefaultScrollbarWidth();
  50940. }
  50941. void Viewport::setScrollBarButtonVisibility (const bool buttonsVisible)
  50942. {
  50943. verticalScrollBar->setButtonVisibility (buttonsVisible);
  50944. horizontalScrollBar->setButtonVisibility (buttonsVisible);
  50945. }
  50946. void Viewport::scrollBarMoved (ScrollBar* scrollBarThatHasMoved, double newRangeStart)
  50947. {
  50948. if (scrollBarThatHasMoved == horizontalScrollBar)
  50949. {
  50950. setViewPosition (roundToInt (newRangeStart), getViewPositionY());
  50951. }
  50952. else if (scrollBarThatHasMoved == verticalScrollBar)
  50953. {
  50954. setViewPosition (getViewPositionX(), roundToInt (newRangeStart));
  50955. }
  50956. }
  50957. void Viewport::mouseWheelMove (const MouseEvent& e, float wheelIncrementX, float wheelIncrementY)
  50958. {
  50959. if (! useMouseWheelMoveIfNeeded (e, wheelIncrementX, wheelIncrementY))
  50960. Component::mouseWheelMove (e, wheelIncrementX, wheelIncrementY);
  50961. }
  50962. bool Viewport::useMouseWheelMoveIfNeeded (const MouseEvent& e, float wheelIncrementX, float wheelIncrementY)
  50963. {
  50964. if (! (e.mods.isAltDown() || e.mods.isCtrlDown()))
  50965. {
  50966. const bool hasVertBar = verticalScrollBar->isVisible();
  50967. const bool hasHorzBar = horizontalScrollBar->isVisible();
  50968. if (hasHorzBar && (wheelIncrementX != 0 || e.mods.isShiftDown() || ! hasVertBar))
  50969. {
  50970. if (wheelIncrementX == 0 && ! hasVertBar)
  50971. wheelIncrementX = wheelIncrementY;
  50972. horizontalScrollBar->mouseWheelMove (e.getEventRelativeTo (horizontalScrollBar),
  50973. wheelIncrementX, wheelIncrementY);
  50974. return true;
  50975. }
  50976. else if (hasVertBar && wheelIncrementY != 0)
  50977. {
  50978. verticalScrollBar->mouseWheelMove (e.getEventRelativeTo (verticalScrollBar),
  50979. wheelIncrementX, wheelIncrementY);
  50980. return true;
  50981. }
  50982. }
  50983. return false;
  50984. }
  50985. bool Viewport::keyPressed (const KeyPress& key)
  50986. {
  50987. const bool isUpDownKey = key.isKeyCode (KeyPress::upKey)
  50988. || key.isKeyCode (KeyPress::downKey)
  50989. || key.isKeyCode (KeyPress::pageUpKey)
  50990. || key.isKeyCode (KeyPress::pageDownKey)
  50991. || key.isKeyCode (KeyPress::homeKey)
  50992. || key.isKeyCode (KeyPress::endKey);
  50993. if (verticalScrollBar->isVisible() && isUpDownKey)
  50994. return verticalScrollBar->keyPressed (key);
  50995. const bool isLeftRightKey = key.isKeyCode (KeyPress::leftKey)
  50996. || key.isKeyCode (KeyPress::rightKey);
  50997. if (horizontalScrollBar->isVisible() && (isUpDownKey || isLeftRightKey))
  50998. return horizontalScrollBar->keyPressed (key);
  50999. return false;
  51000. }
  51001. END_JUCE_NAMESPACE
  51002. /*** End of inlined file: juce_Viewport.cpp ***/
  51003. /*** Start of inlined file: juce_LookAndFeel.cpp ***/
  51004. BEGIN_JUCE_NAMESPACE
  51005. static const Colour createBaseColour (const Colour& buttonColour,
  51006. const bool hasKeyboardFocus,
  51007. const bool isMouseOverButton,
  51008. const bool isButtonDown) throw()
  51009. {
  51010. const float sat = hasKeyboardFocus ? 1.3f : 0.9f;
  51011. const Colour baseColour (buttonColour.withMultipliedSaturation (sat));
  51012. if (isButtonDown)
  51013. return baseColour.contrasting (0.2f);
  51014. else if (isMouseOverButton)
  51015. return baseColour.contrasting (0.1f);
  51016. return baseColour;
  51017. }
  51018. static String defaultSansName, defaultSerifName, defaultFixedName;
  51019. void clearUpDefaultFontNames() throw()
  51020. {
  51021. defaultSansName = String::empty;
  51022. defaultSerifName = String::empty;
  51023. defaultFixedName = String::empty;
  51024. }
  51025. LookAndFeel::LookAndFeel()
  51026. {
  51027. /* if this fails it means you're trying to create a LookAndFeel object before
  51028. the static Colours have been initialised. That ain't gonna work. It probably
  51029. means that you're using a static LookAndFeel object and that your compiler has
  51030. decided to intialise it before the Colours class.
  51031. */
  51032. jassert (Colours::white == Colour (0xffffffff));
  51033. // set up the standard set of colours..
  51034. const int textButtonColour = 0xffbbbbff;
  51035. const int textHighlightColour = 0x401111ee;
  51036. const int standardOutlineColour = 0xb2808080;
  51037. static const int standardColours[] =
  51038. {
  51039. TextButton::buttonColourId, textButtonColour,
  51040. TextButton::buttonOnColourId, 0xff4444ff,
  51041. TextButton::textColourOnId, 0xff000000,
  51042. TextButton::textColourOffId, 0xff000000,
  51043. ComboBox::buttonColourId, 0xffbbbbff,
  51044. ComboBox::outlineColourId, standardOutlineColour,
  51045. ToggleButton::textColourId, 0xff000000,
  51046. TextEditor::backgroundColourId, 0xffffffff,
  51047. TextEditor::textColourId, 0xff000000,
  51048. TextEditor::highlightColourId, textHighlightColour,
  51049. TextEditor::highlightedTextColourId, 0xff000000,
  51050. TextEditor::caretColourId, 0xff000000,
  51051. TextEditor::outlineColourId, 0x00000000,
  51052. TextEditor::focusedOutlineColourId, textButtonColour,
  51053. TextEditor::shadowColourId, 0x38000000,
  51054. Label::backgroundColourId, 0x00000000,
  51055. Label::textColourId, 0xff000000,
  51056. Label::outlineColourId, 0x00000000,
  51057. ScrollBar::backgroundColourId, 0x00000000,
  51058. ScrollBar::thumbColourId, 0xffffffff,
  51059. ScrollBar::trackColourId, 0xffffffff,
  51060. TreeView::linesColourId, 0x4c000000,
  51061. TreeView::backgroundColourId, 0x00000000,
  51062. TreeView::dragAndDropIndicatorColourId, 0x80ff0000,
  51063. PopupMenu::backgroundColourId, 0xffffffff,
  51064. PopupMenu::textColourId, 0xff000000,
  51065. PopupMenu::headerTextColourId, 0xff000000,
  51066. PopupMenu::highlightedTextColourId, 0xffffffff,
  51067. PopupMenu::highlightedBackgroundColourId, 0x991111aa,
  51068. ComboBox::textColourId, 0xff000000,
  51069. ComboBox::backgroundColourId, 0xffffffff,
  51070. ComboBox::arrowColourId, 0x99000000,
  51071. ListBox::backgroundColourId, 0xffffffff,
  51072. ListBox::outlineColourId, standardOutlineColour,
  51073. ListBox::textColourId, 0xff000000,
  51074. Slider::backgroundColourId, 0x00000000,
  51075. Slider::thumbColourId, textButtonColour,
  51076. Slider::trackColourId, 0x7fffffff,
  51077. Slider::rotarySliderFillColourId, 0x7f0000ff,
  51078. Slider::rotarySliderOutlineColourId, 0x66000000,
  51079. Slider::textBoxTextColourId, 0xff000000,
  51080. Slider::textBoxBackgroundColourId, 0xffffffff,
  51081. Slider::textBoxHighlightColourId, textHighlightColour,
  51082. Slider::textBoxOutlineColourId, standardOutlineColour,
  51083. ResizableWindow::backgroundColourId, 0xff777777,
  51084. //DocumentWindow::textColourId, 0xff000000, // (this is deliberately not set)
  51085. AlertWindow::backgroundColourId, 0xffededed,
  51086. AlertWindow::textColourId, 0xff000000,
  51087. AlertWindow::outlineColourId, 0xff666666,
  51088. ProgressBar::backgroundColourId, 0xffeeeeee,
  51089. ProgressBar::foregroundColourId, 0xffaaaaee,
  51090. TooltipWindow::backgroundColourId, 0xffeeeebb,
  51091. TooltipWindow::textColourId, 0xff000000,
  51092. TooltipWindow::outlineColourId, 0x4c000000,
  51093. TabbedComponent::backgroundColourId, 0x00000000,
  51094. TabbedComponent::outlineColourId, 0xff777777,
  51095. TabbedButtonBar::tabOutlineColourId, 0x80000000,
  51096. TabbedButtonBar::frontOutlineColourId, 0x90000000,
  51097. Toolbar::backgroundColourId, 0xfff6f8f9,
  51098. Toolbar::separatorColourId, 0x4c000000,
  51099. Toolbar::buttonMouseOverBackgroundColourId, 0x4c0000ff,
  51100. Toolbar::buttonMouseDownBackgroundColourId, 0x800000ff,
  51101. Toolbar::labelTextColourId, 0xff000000,
  51102. Toolbar::editingModeOutlineColourId, 0xffff0000,
  51103. HyperlinkButton::textColourId, 0xcc1111ee,
  51104. GroupComponent::outlineColourId, 0x66000000,
  51105. GroupComponent::textColourId, 0xff000000,
  51106. DirectoryContentsDisplayComponent::highlightColourId, textHighlightColour,
  51107. DirectoryContentsDisplayComponent::textColourId, 0xff000000,
  51108. 0x1000440, /*LassoComponent::lassoFillColourId*/ 0x66dddddd,
  51109. 0x1000441, /*LassoComponent::lassoOutlineColourId*/ 0x99111111,
  51110. MidiKeyboardComponent::whiteNoteColourId, 0xffffffff,
  51111. MidiKeyboardComponent::blackNoteColourId, 0xff000000,
  51112. MidiKeyboardComponent::keySeparatorLineColourId, 0x66000000,
  51113. MidiKeyboardComponent::mouseOverKeyOverlayColourId, 0x80ffff00,
  51114. MidiKeyboardComponent::keyDownOverlayColourId, 0xffb6b600,
  51115. MidiKeyboardComponent::textLabelColourId, 0xff000000,
  51116. MidiKeyboardComponent::upDownButtonBackgroundColourId, 0xffd3d3d3,
  51117. MidiKeyboardComponent::upDownButtonArrowColourId, 0xff000000,
  51118. CodeEditorComponent::backgroundColourId, 0xffffffff,
  51119. CodeEditorComponent::caretColourId, 0xff000000,
  51120. CodeEditorComponent::highlightColourId, textHighlightColour,
  51121. CodeEditorComponent::defaultTextColourId, 0xff000000,
  51122. ColourSelector::backgroundColourId, 0xffe5e5e5,
  51123. ColourSelector::labelTextColourId, 0xff000000,
  51124. KeyMappingEditorComponent::backgroundColourId, 0x00000000,
  51125. KeyMappingEditorComponent::textColourId, 0xff000000,
  51126. FileSearchPathListComponent::backgroundColourId, 0xffffffff,
  51127. FileChooserDialogBox::titleTextColourId, 0xff000000,
  51128. };
  51129. for (int i = 0; i < numElementsInArray (standardColours); i += 2)
  51130. setColour (standardColours [i], Colour (standardColours [i + 1]));
  51131. if (defaultSansName.isEmpty())
  51132. Font::getPlatformDefaultFontNames (defaultSansName, defaultSerifName, defaultFixedName);
  51133. defaultSans = defaultSansName;
  51134. defaultSerif = defaultSerifName;
  51135. defaultFixed = defaultFixedName;
  51136. }
  51137. LookAndFeel::~LookAndFeel()
  51138. {
  51139. }
  51140. const Colour LookAndFeel::findColour (const int colourId) const throw()
  51141. {
  51142. const int index = colourIds.indexOf (colourId);
  51143. if (index >= 0)
  51144. return colours [index];
  51145. jassertfalse
  51146. return Colours::black;
  51147. }
  51148. void LookAndFeel::setColour (const int colourId, const Colour& colour) throw()
  51149. {
  51150. const int index = colourIds.indexOf (colourId);
  51151. if (index >= 0)
  51152. colours.set (index, colour);
  51153. colourIds.add (colourId);
  51154. colours.add (colour);
  51155. }
  51156. bool LookAndFeel::isColourSpecified (const int colourId) const throw()
  51157. {
  51158. return colourIds.contains (colourId);
  51159. }
  51160. static LookAndFeel* defaultLF = 0;
  51161. static LookAndFeel* currentDefaultLF = 0;
  51162. LookAndFeel& LookAndFeel::getDefaultLookAndFeel() throw()
  51163. {
  51164. // if this happens, your app hasn't initialised itself properly.. if you're
  51165. // trying to hack your own main() function, have a look at
  51166. // JUCEApplication::initialiseForGUI()
  51167. jassert (currentDefaultLF != 0);
  51168. return *currentDefaultLF;
  51169. }
  51170. void LookAndFeel::setDefaultLookAndFeel (LookAndFeel* newDefaultLookAndFeel) throw()
  51171. {
  51172. if (newDefaultLookAndFeel == 0)
  51173. {
  51174. if (defaultLF == 0)
  51175. defaultLF = new LookAndFeel();
  51176. newDefaultLookAndFeel = defaultLF;
  51177. }
  51178. currentDefaultLF = newDefaultLookAndFeel;
  51179. for (int i = Desktop::getInstance().getNumComponents(); --i >= 0;)
  51180. {
  51181. Component* const c = Desktop::getInstance().getComponent (i);
  51182. if (c != 0)
  51183. c->sendLookAndFeelChange();
  51184. }
  51185. }
  51186. void LookAndFeel::clearDefaultLookAndFeel() throw()
  51187. {
  51188. if (currentDefaultLF == defaultLF)
  51189. currentDefaultLF = 0;
  51190. deleteAndZero (defaultLF);
  51191. }
  51192. const Typeface::Ptr LookAndFeel::getTypefaceForFont (const Font& font)
  51193. {
  51194. String faceName (font.getTypefaceName());
  51195. if (faceName == Font::getDefaultSansSerifFontName())
  51196. faceName = defaultSans;
  51197. else if (faceName == Font::getDefaultSerifFontName())
  51198. faceName = defaultSerif;
  51199. else if (faceName == Font::getDefaultMonospacedFontName())
  51200. faceName = defaultFixed;
  51201. Font f (font);
  51202. f.setTypefaceName (faceName);
  51203. return Typeface::createSystemTypefaceFor (f);
  51204. }
  51205. void LookAndFeel::setDefaultSansSerifTypefaceName (const String& newName)
  51206. {
  51207. defaultSans = newName;
  51208. }
  51209. const MouseCursor LookAndFeel::getMouseCursorFor (Component& component)
  51210. {
  51211. return component.getMouseCursor();
  51212. }
  51213. void LookAndFeel::drawButtonBackground (Graphics& g,
  51214. Button& button,
  51215. const Colour& backgroundColour,
  51216. bool isMouseOverButton,
  51217. bool isButtonDown)
  51218. {
  51219. const int width = button.getWidth();
  51220. const int height = button.getHeight();
  51221. const float outlineThickness = button.isEnabled() ? ((isButtonDown || isMouseOverButton) ? 1.2f : 0.7f) : 0.4f;
  51222. const float halfThickness = outlineThickness * 0.5f;
  51223. const float indentL = button.isConnectedOnLeft() ? 0.1f : halfThickness;
  51224. const float indentR = button.isConnectedOnRight() ? 0.1f : halfThickness;
  51225. const float indentT = button.isConnectedOnTop() ? 0.1f : halfThickness;
  51226. const float indentB = button.isConnectedOnBottom() ? 0.1f : halfThickness;
  51227. const Colour baseColour (createBaseColour (backgroundColour,
  51228. button.hasKeyboardFocus (true),
  51229. isMouseOverButton, isButtonDown)
  51230. .withMultipliedAlpha (button.isEnabled() ? 1.0f : 0.5f));
  51231. drawGlassLozenge (g,
  51232. indentL,
  51233. indentT,
  51234. width - indentL - indentR,
  51235. height - indentT - indentB,
  51236. baseColour, outlineThickness, -1.0f,
  51237. button.isConnectedOnLeft(),
  51238. button.isConnectedOnRight(),
  51239. button.isConnectedOnTop(),
  51240. button.isConnectedOnBottom());
  51241. }
  51242. const Font LookAndFeel::getFontForTextButton (TextButton& button)
  51243. {
  51244. return button.getFont();
  51245. }
  51246. void LookAndFeel::drawButtonText (Graphics& g, TextButton& button,
  51247. bool /*isMouseOverButton*/, bool /*isButtonDown*/)
  51248. {
  51249. Font font (getFontForTextButton (button));
  51250. g.setFont (font);
  51251. g.setColour (button.findColour (button.getToggleState() ? TextButton::textColourOnId
  51252. : TextButton::textColourOffId)
  51253. .withMultipliedAlpha (button.isEnabled() ? 1.0f : 0.5f));
  51254. const int yIndent = jmin (4, button.proportionOfHeight (0.3f));
  51255. const int cornerSize = jmin (button.getHeight(), button.getWidth()) / 2;
  51256. const int fontHeight = roundToInt (font.getHeight() * 0.6f);
  51257. const int leftIndent = jmin (fontHeight, 2 + cornerSize / (button.isConnectedOnLeft() ? 4 : 2));
  51258. const int rightIndent = jmin (fontHeight, 2 + cornerSize / (button.isConnectedOnRight() ? 4 : 2));
  51259. g.drawFittedText (button.getButtonText(),
  51260. leftIndent,
  51261. yIndent,
  51262. button.getWidth() - leftIndent - rightIndent,
  51263. button.getHeight() - yIndent * 2,
  51264. Justification::centred, 2);
  51265. }
  51266. void LookAndFeel::drawTickBox (Graphics& g,
  51267. Component& component,
  51268. float x, float y, float w, float h,
  51269. const bool ticked,
  51270. const bool isEnabled,
  51271. const bool isMouseOverButton,
  51272. const bool isButtonDown)
  51273. {
  51274. const float boxSize = w * 0.7f;
  51275. drawGlassSphere (g, x, y + (h - boxSize) * 0.5f, boxSize,
  51276. createBaseColour (component.findColour (TextButton::buttonColourId)
  51277. .withMultipliedAlpha (isEnabled ? 1.0f : 0.5f),
  51278. true,
  51279. isMouseOverButton,
  51280. isButtonDown),
  51281. isEnabled ? ((isButtonDown || isMouseOverButton) ? 1.1f : 0.5f) : 0.3f);
  51282. if (ticked)
  51283. {
  51284. Path tick;
  51285. tick.startNewSubPath (1.5f, 3.0f);
  51286. tick.lineTo (3.0f, 6.0f);
  51287. tick.lineTo (6.0f, 0.0f);
  51288. g.setColour (isEnabled ? Colours::black : Colours::grey);
  51289. const AffineTransform trans (AffineTransform::scale (w / 9.0f, h / 9.0f)
  51290. .translated (x, y));
  51291. g.strokePath (tick, PathStrokeType (2.5f), trans);
  51292. }
  51293. }
  51294. void LookAndFeel::drawToggleButton (Graphics& g,
  51295. ToggleButton& button,
  51296. bool isMouseOverButton,
  51297. bool isButtonDown)
  51298. {
  51299. if (button.hasKeyboardFocus (true))
  51300. {
  51301. g.setColour (button.findColour (TextEditor::focusedOutlineColourId));
  51302. g.drawRect (0, 0, button.getWidth(), button.getHeight());
  51303. }
  51304. float fontSize = jmin (15.0f, button.getHeight() * 0.75f);
  51305. const float tickWidth = fontSize * 1.1f;
  51306. drawTickBox (g, button, 4.0f, (button.getHeight() - tickWidth) * 0.5f,
  51307. tickWidth, tickWidth,
  51308. button.getToggleState(),
  51309. button.isEnabled(),
  51310. isMouseOverButton,
  51311. isButtonDown);
  51312. g.setColour (button.findColour (ToggleButton::textColourId));
  51313. g.setFont (fontSize);
  51314. if (! button.isEnabled())
  51315. g.setOpacity (0.5f);
  51316. const int textX = (int) tickWidth + 5;
  51317. g.drawFittedText (button.getButtonText(),
  51318. textX, 0,
  51319. button.getWidth() - textX - 2, button.getHeight(),
  51320. Justification::centredLeft, 10);
  51321. }
  51322. void LookAndFeel::changeToggleButtonWidthToFitText (ToggleButton& button)
  51323. {
  51324. Font font (jmin (15.0f, button.getHeight() * 0.6f));
  51325. const int tickWidth = jmin (24, button.getHeight());
  51326. button.setSize (font.getStringWidth (button.getButtonText()) + tickWidth + 8,
  51327. button.getHeight());
  51328. }
  51329. AlertWindow* LookAndFeel::createAlertWindow (const String& title,
  51330. const String& message,
  51331. const String& button1,
  51332. const String& button2,
  51333. const String& button3,
  51334. AlertWindow::AlertIconType iconType,
  51335. int numButtons,
  51336. Component* associatedComponent)
  51337. {
  51338. AlertWindow* aw = new AlertWindow (title, message, iconType, associatedComponent);
  51339. if (numButtons == 1)
  51340. {
  51341. aw->addButton (button1, 0,
  51342. KeyPress (KeyPress::escapeKey, 0, 0),
  51343. KeyPress (KeyPress::returnKey, 0, 0));
  51344. }
  51345. else
  51346. {
  51347. const KeyPress button1ShortCut (CharacterFunctions::toLowerCase (button1[0]), 0, 0);
  51348. KeyPress button2ShortCut (CharacterFunctions::toLowerCase (button2[0]), 0, 0);
  51349. if (button1ShortCut == button2ShortCut)
  51350. button2ShortCut = KeyPress();
  51351. if (numButtons == 2)
  51352. {
  51353. aw->addButton (button1, 1, KeyPress (KeyPress::returnKey, 0, 0), button1ShortCut);
  51354. aw->addButton (button2, 0, KeyPress (KeyPress::escapeKey, 0, 0), button2ShortCut);
  51355. }
  51356. else if (numButtons == 3)
  51357. {
  51358. aw->addButton (button1, 1, button1ShortCut);
  51359. aw->addButton (button2, 2, button2ShortCut);
  51360. aw->addButton (button3, 0, KeyPress (KeyPress::escapeKey, 0, 0));
  51361. }
  51362. }
  51363. return aw;
  51364. }
  51365. void LookAndFeel::drawAlertBox (Graphics& g,
  51366. AlertWindow& alert,
  51367. const Rectangle<int>& textArea,
  51368. TextLayout& textLayout)
  51369. {
  51370. g.fillAll (alert.findColour (AlertWindow::backgroundColourId));
  51371. int iconSpaceUsed = 0;
  51372. Justification alignment (Justification::horizontallyCentred);
  51373. const int iconWidth = 80;
  51374. int iconSize = jmin (iconWidth + 50, alert.getHeight() + 20);
  51375. if (alert.containsAnyExtraComponents() || alert.getNumButtons() > 2)
  51376. iconSize = jmin (iconSize, textArea.getHeight() + 50);
  51377. const Rectangle<int> iconRect (iconSize / -10, iconSize / -10,
  51378. iconSize, iconSize);
  51379. if (alert.getAlertType() != AlertWindow::NoIcon)
  51380. {
  51381. Path icon;
  51382. uint32 colour;
  51383. char character;
  51384. if (alert.getAlertType() == AlertWindow::WarningIcon)
  51385. {
  51386. colour = 0x55ff5555;
  51387. character = '!';
  51388. icon.addTriangle (iconRect.getX() + iconRect.getWidth() * 0.5f, (float) iconRect.getY(),
  51389. (float) iconRect.getRight(), (float) iconRect.getBottom(),
  51390. (float) iconRect.getX(), (float) iconRect.getBottom());
  51391. icon = icon.createPathWithRoundedCorners (5.0f);
  51392. }
  51393. else
  51394. {
  51395. colour = alert.getAlertType() == AlertWindow::InfoIcon ? 0x605555ff : 0x40b69900;
  51396. character = alert.getAlertType() == AlertWindow::InfoIcon ? 'i' : '?';
  51397. icon.addEllipse ((float) iconRect.getX(), (float) iconRect.getY(),
  51398. (float) iconRect.getWidth(), (float) iconRect.getHeight());
  51399. }
  51400. GlyphArrangement ga;
  51401. ga.addFittedText (Font (iconRect.getHeight() * 0.9f, Font::bold),
  51402. String::charToString (character),
  51403. (float) iconRect.getX(), (float) iconRect.getY(),
  51404. (float) iconRect.getWidth(), (float) iconRect.getHeight(),
  51405. Justification::centred, false);
  51406. ga.createPath (icon);
  51407. icon.setUsingNonZeroWinding (false);
  51408. g.setColour (Colour (colour));
  51409. g.fillPath (icon);
  51410. iconSpaceUsed = iconWidth;
  51411. alignment = Justification::left;
  51412. }
  51413. g.setColour (alert.findColour (AlertWindow::textColourId));
  51414. textLayout.drawWithin (g,
  51415. textArea.getX() + iconSpaceUsed, textArea.getY(),
  51416. textArea.getWidth() - iconSpaceUsed, textArea.getHeight(),
  51417. alignment.getFlags() | Justification::top);
  51418. g.setColour (alert.findColour (AlertWindow::outlineColourId));
  51419. g.drawRect (0, 0, alert.getWidth(), alert.getHeight());
  51420. }
  51421. int LookAndFeel::getAlertBoxWindowFlags()
  51422. {
  51423. return ComponentPeer::windowAppearsOnTaskbar
  51424. | ComponentPeer::windowHasDropShadow;
  51425. }
  51426. int LookAndFeel::getAlertWindowButtonHeight()
  51427. {
  51428. return 28;
  51429. }
  51430. const Font LookAndFeel::getAlertWindowFont()
  51431. {
  51432. return Font (12.0f);
  51433. }
  51434. void LookAndFeel::drawProgressBar (Graphics& g, ProgressBar& progressBar,
  51435. int width, int height,
  51436. double progress, const String& textToShow)
  51437. {
  51438. const Colour background (progressBar.findColour (ProgressBar::backgroundColourId));
  51439. const Colour foreground (progressBar.findColour (ProgressBar::foregroundColourId));
  51440. g.fillAll (background);
  51441. if (progress >= 0.0f && progress < 1.0f)
  51442. {
  51443. drawGlassLozenge (g, 1.0f, 1.0f,
  51444. (float) jlimit (0.0, width - 2.0, progress * (width - 2.0)),
  51445. (float) (height - 2),
  51446. foreground,
  51447. 0.5f, 0.0f,
  51448. true, true, true, true);
  51449. }
  51450. else
  51451. {
  51452. // spinning bar..
  51453. g.setColour (foreground);
  51454. const int stripeWidth = height * 2;
  51455. const int position = (Time::getMillisecondCounter() / 15) % stripeWidth;
  51456. Path p;
  51457. for (float x = (float) (- position); x < width + stripeWidth; x += stripeWidth)
  51458. p.addQuadrilateral (x, 0.0f,
  51459. x + stripeWidth * 0.5f, 0.0f,
  51460. x, (float) height,
  51461. x - stripeWidth * 0.5f, (float) height);
  51462. Image im (Image::ARGB, width, height, true);
  51463. {
  51464. Graphics g2 (im);
  51465. drawGlassLozenge (g2, 1.0f, 1.0f,
  51466. (float) (width - 2),
  51467. (float) (height - 2),
  51468. foreground,
  51469. 0.5f, 0.0f,
  51470. true, true, true, true);
  51471. }
  51472. g.setTiledImageFill (im, 0, 0, 0.85f);
  51473. g.fillPath (p);
  51474. }
  51475. if (textToShow.isNotEmpty())
  51476. {
  51477. g.setColour (Colour::contrasting (background, foreground));
  51478. g.setFont (height * 0.6f);
  51479. g.drawText (textToShow, 0, 0, width, height, Justification::centred, false);
  51480. }
  51481. }
  51482. void LookAndFeel::drawSpinningWaitAnimation (Graphics& g, const Colour& colour, int x, int y, int w, int h)
  51483. {
  51484. const float radius = jmin (w, h) * 0.4f;
  51485. const float thickness = radius * 0.15f;
  51486. Path p;
  51487. p.addRoundedRectangle (radius * 0.4f, thickness * -0.5f,
  51488. radius * 0.6f, thickness,
  51489. thickness * 0.5f);
  51490. const float cx = x + w * 0.5f;
  51491. const float cy = y + h * 0.5f;
  51492. const uint32 animationIndex = (Time::getMillisecondCounter() / (1000 / 10)) % 12;
  51493. for (int i = 0; i < 12; ++i)
  51494. {
  51495. const int n = (i + 12 - animationIndex) % 12;
  51496. g.setColour (colour.withMultipliedAlpha ((n + 1) / 12.0f));
  51497. g.fillPath (p, AffineTransform::rotation (i * (float_Pi / 6.0f))
  51498. .translated (cx, cy));
  51499. }
  51500. }
  51501. void LookAndFeel::drawScrollbarButton (Graphics& g,
  51502. ScrollBar& scrollbar,
  51503. int width, int height,
  51504. int buttonDirection,
  51505. bool /*isScrollbarVertical*/,
  51506. bool /*isMouseOverButton*/,
  51507. bool isButtonDown)
  51508. {
  51509. Path p;
  51510. if (buttonDirection == 0)
  51511. p.addTriangle (width * 0.5f, height * 0.2f,
  51512. width * 0.1f, height * 0.7f,
  51513. width * 0.9f, height * 0.7f);
  51514. else if (buttonDirection == 1)
  51515. p.addTriangle (width * 0.8f, height * 0.5f,
  51516. width * 0.3f, height * 0.1f,
  51517. width * 0.3f, height * 0.9f);
  51518. else if (buttonDirection == 2)
  51519. p.addTriangle (width * 0.5f, height * 0.8f,
  51520. width * 0.1f, height * 0.3f,
  51521. width * 0.9f, height * 0.3f);
  51522. else if (buttonDirection == 3)
  51523. p.addTriangle (width * 0.2f, height * 0.5f,
  51524. width * 0.7f, height * 0.1f,
  51525. width * 0.7f, height * 0.9f);
  51526. if (isButtonDown)
  51527. g.setColour (scrollbar.findColour (ScrollBar::thumbColourId).contrasting (0.2f));
  51528. else
  51529. g.setColour (scrollbar.findColour (ScrollBar::thumbColourId));
  51530. g.fillPath (p);
  51531. g.setColour (Colour (0x80000000));
  51532. g.strokePath (p, PathStrokeType (0.5f));
  51533. }
  51534. void LookAndFeel::drawScrollbar (Graphics& g,
  51535. ScrollBar& scrollbar,
  51536. int x, int y,
  51537. int width, int height,
  51538. bool isScrollbarVertical,
  51539. int thumbStartPosition,
  51540. int thumbSize,
  51541. bool /*isMouseOver*/,
  51542. bool /*isMouseDown*/)
  51543. {
  51544. g.fillAll (scrollbar.findColour (ScrollBar::backgroundColourId));
  51545. Path slotPath, thumbPath;
  51546. const float slotIndent = jmin (width, height) > 15 ? 1.0f : 0.0f;
  51547. const float slotIndentx2 = slotIndent * 2.0f;
  51548. const float thumbIndent = slotIndent + 1.0f;
  51549. const float thumbIndentx2 = thumbIndent * 2.0f;
  51550. float gx1 = 0.0f, gy1 = 0.0f, gx2 = 0.0f, gy2 = 0.0f;
  51551. if (isScrollbarVertical)
  51552. {
  51553. slotPath.addRoundedRectangle (x + slotIndent,
  51554. y + slotIndent,
  51555. width - slotIndentx2,
  51556. height - slotIndentx2,
  51557. (width - slotIndentx2) * 0.5f);
  51558. if (thumbSize > 0)
  51559. thumbPath.addRoundedRectangle (x + thumbIndent,
  51560. thumbStartPosition + thumbIndent,
  51561. width - thumbIndentx2,
  51562. thumbSize - thumbIndentx2,
  51563. (width - thumbIndentx2) * 0.5f);
  51564. gx1 = (float) x;
  51565. gx2 = x + width * 0.7f;
  51566. }
  51567. else
  51568. {
  51569. slotPath.addRoundedRectangle (x + slotIndent,
  51570. y + slotIndent,
  51571. width - slotIndentx2,
  51572. height - slotIndentx2,
  51573. (height - slotIndentx2) * 0.5f);
  51574. if (thumbSize > 0)
  51575. thumbPath.addRoundedRectangle (thumbStartPosition + thumbIndent,
  51576. y + thumbIndent,
  51577. thumbSize - thumbIndentx2,
  51578. height - thumbIndentx2,
  51579. (height - thumbIndentx2) * 0.5f);
  51580. gy1 = (float) y;
  51581. gy2 = y + height * 0.7f;
  51582. }
  51583. const Colour thumbColour (scrollbar.findColour (ScrollBar::thumbColourId));
  51584. g.setGradientFill (ColourGradient (thumbColour.overlaidWith (Colour (0x44000000)), gx1, gy1,
  51585. thumbColour.overlaidWith (Colour (0x19000000)), gx2, gy2, false));
  51586. g.fillPath (slotPath);
  51587. if (isScrollbarVertical)
  51588. {
  51589. gx1 = x + width * 0.6f;
  51590. gx2 = (float) x + width;
  51591. }
  51592. else
  51593. {
  51594. gy1 = y + height * 0.6f;
  51595. gy2 = (float) y + height;
  51596. }
  51597. g.setGradientFill (ColourGradient (Colours::transparentBlack,gx1, gy1,
  51598. Colour (0x19000000), gx2, gy2, false));
  51599. g.fillPath (slotPath);
  51600. g.setColour (thumbColour);
  51601. g.fillPath (thumbPath);
  51602. g.setGradientFill (ColourGradient (Colour (0x10000000), gx1, gy1,
  51603. Colours::transparentBlack, gx2, gy2, false));
  51604. g.saveState();
  51605. if (isScrollbarVertical)
  51606. g.reduceClipRegion (x + width / 2, y, width, height);
  51607. else
  51608. g.reduceClipRegion (x, y + height / 2, width, height);
  51609. g.fillPath (thumbPath);
  51610. g.restoreState();
  51611. g.setColour (Colour (0x4c000000));
  51612. g.strokePath (thumbPath, PathStrokeType (0.4f));
  51613. }
  51614. ImageEffectFilter* LookAndFeel::getScrollbarEffect()
  51615. {
  51616. return 0;
  51617. }
  51618. int LookAndFeel::getMinimumScrollbarThumbSize (ScrollBar& scrollbar)
  51619. {
  51620. return jmin (scrollbar.getWidth(), scrollbar.getHeight()) * 2;
  51621. }
  51622. int LookAndFeel::getDefaultScrollbarWidth()
  51623. {
  51624. return 18;
  51625. }
  51626. int LookAndFeel::getScrollbarButtonSize (ScrollBar& scrollbar)
  51627. {
  51628. return 2 + (scrollbar.isVertical() ? scrollbar.getWidth()
  51629. : scrollbar.getHeight());
  51630. }
  51631. const Path LookAndFeel::getTickShape (const float height)
  51632. {
  51633. static const unsigned char tickShapeData[] =
  51634. {
  51635. 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,
  51636. 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,
  51637. 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,
  51638. 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,
  51639. 96,140,68,0,128,188,67,0,224,168,68,0,0,119,67,99,101
  51640. };
  51641. Path p;
  51642. p.loadPathFromData (tickShapeData, sizeof (tickShapeData));
  51643. p.scaleToFit (0, 0, height * 2.0f, height, true);
  51644. return p;
  51645. }
  51646. const Path LookAndFeel::getCrossShape (const float height)
  51647. {
  51648. static const unsigned char crossShapeData[] =
  51649. {
  51650. 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,
  51651. 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,
  51652. 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,
  51653. 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,
  51654. 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,
  51655. 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,
  51656. 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
  51657. };
  51658. Path p;
  51659. p.loadPathFromData (crossShapeData, sizeof (crossShapeData));
  51660. p.scaleToFit (0, 0, height * 2.0f, height, true);
  51661. return p;
  51662. }
  51663. void LookAndFeel::drawTreeviewPlusMinusBox (Graphics& g, int x, int y, int w, int h, bool isPlus, bool /*isMouseOver*/)
  51664. {
  51665. const int boxSize = ((jmin (16, w, h) << 1) / 3) | 1;
  51666. x += (w - boxSize) >> 1;
  51667. y += (h - boxSize) >> 1;
  51668. w = boxSize;
  51669. h = boxSize;
  51670. g.setColour (Colour (0xe5ffffff));
  51671. g.fillRect (x, y, w, h);
  51672. g.setColour (Colour (0x80000000));
  51673. g.drawRect (x, y, w, h);
  51674. const float size = boxSize / 2 + 1.0f;
  51675. const float centre = (float) (boxSize / 2);
  51676. g.fillRect (x + (w - size) * 0.5f, y + centre, size, 1.0f);
  51677. if (isPlus)
  51678. g.fillRect (x + centre, y + (h - size) * 0.5f, 1.0f, size);
  51679. }
  51680. void LookAndFeel::drawBubble (Graphics& g,
  51681. float tipX, float tipY,
  51682. float boxX, float boxY,
  51683. float boxW, float boxH)
  51684. {
  51685. int side = 0;
  51686. if (tipX < boxX)
  51687. side = 1;
  51688. else if (tipX > boxX + boxW)
  51689. side = 3;
  51690. else if (tipY > boxY + boxH)
  51691. side = 2;
  51692. const float indent = 2.0f;
  51693. Path p;
  51694. p.addBubble (boxX + indent,
  51695. boxY + indent,
  51696. boxW - indent * 2.0f,
  51697. boxH - indent * 2.0f,
  51698. 5.0f,
  51699. tipX, tipY,
  51700. side,
  51701. 0.5f,
  51702. jmin (15.0f, boxW * 0.3f, boxH * 0.3f));
  51703. //xxx need to take comp as param for colour
  51704. g.setColour (findColour (TooltipWindow::backgroundColourId).withAlpha (0.9f));
  51705. g.fillPath (p);
  51706. //xxx as above
  51707. g.setColour (findColour (TooltipWindow::textColourId).withAlpha (0.4f));
  51708. g.strokePath (p, PathStrokeType (1.33f));
  51709. }
  51710. const Font LookAndFeel::getPopupMenuFont()
  51711. {
  51712. return Font (17.0f);
  51713. }
  51714. void LookAndFeel::getIdealPopupMenuItemSize (const String& text,
  51715. const bool isSeparator,
  51716. int standardMenuItemHeight,
  51717. int& idealWidth,
  51718. int& idealHeight)
  51719. {
  51720. if (isSeparator)
  51721. {
  51722. idealWidth = 50;
  51723. idealHeight = standardMenuItemHeight > 0 ? standardMenuItemHeight / 2 : 10;
  51724. }
  51725. else
  51726. {
  51727. Font font (getPopupMenuFont());
  51728. if (standardMenuItemHeight > 0 && font.getHeight() > standardMenuItemHeight / 1.3f)
  51729. font.setHeight (standardMenuItemHeight / 1.3f);
  51730. idealHeight = standardMenuItemHeight > 0 ? standardMenuItemHeight : roundToInt (font.getHeight() * 1.3f);
  51731. idealWidth = font.getStringWidth (text) + idealHeight * 2;
  51732. }
  51733. }
  51734. void LookAndFeel::drawPopupMenuBackground (Graphics& g, int width, int height)
  51735. {
  51736. const Colour background (findColour (PopupMenu::backgroundColourId));
  51737. g.fillAll (background);
  51738. g.setColour (background.overlaidWith (Colour (0x2badd8e6)));
  51739. for (int i = 0; i < height; i += 3)
  51740. g.fillRect (0, i, width, 1);
  51741. #if ! JUCE_MAC
  51742. g.setColour (findColour (PopupMenu::textColourId).withAlpha (0.6f));
  51743. g.drawRect (0, 0, width, height);
  51744. #endif
  51745. }
  51746. void LookAndFeel::drawPopupMenuUpDownArrow (Graphics& g,
  51747. int width, int height,
  51748. bool isScrollUpArrow)
  51749. {
  51750. const Colour background (findColour (PopupMenu::backgroundColourId));
  51751. g.setGradientFill (ColourGradient (background, 0.0f, height * 0.5f,
  51752. background.withAlpha (0.0f),
  51753. 0.0f, isScrollUpArrow ? ((float) height) : 0.0f,
  51754. false));
  51755. g.fillRect (1, 1, width - 2, height - 2);
  51756. const float hw = width * 0.5f;
  51757. const float arrowW = height * 0.3f;
  51758. const float y1 = height * (isScrollUpArrow ? 0.6f : 0.3f);
  51759. const float y2 = height * (isScrollUpArrow ? 0.3f : 0.6f);
  51760. Path p;
  51761. p.addTriangle (hw - arrowW, y1,
  51762. hw + arrowW, y1,
  51763. hw, y2);
  51764. g.setColour (findColour (PopupMenu::textColourId).withAlpha (0.5f));
  51765. g.fillPath (p);
  51766. }
  51767. void LookAndFeel::drawPopupMenuItem (Graphics& g,
  51768. int width, int height,
  51769. const bool isSeparator,
  51770. const bool isActive,
  51771. const bool isHighlighted,
  51772. const bool isTicked,
  51773. const bool hasSubMenu,
  51774. const String& text,
  51775. const String& shortcutKeyText,
  51776. Image* image,
  51777. const Colour* const textColourToUse)
  51778. {
  51779. const float halfH = height * 0.5f;
  51780. if (isSeparator)
  51781. {
  51782. const float separatorIndent = 5.5f;
  51783. g.setColour (Colour (0x33000000));
  51784. g.drawLine (separatorIndent, halfH, width - separatorIndent, halfH);
  51785. g.setColour (Colour (0x66ffffff));
  51786. g.drawLine (separatorIndent, halfH + 1.0f, width - separatorIndent, halfH + 1.0f);
  51787. }
  51788. else
  51789. {
  51790. Colour textColour (findColour (PopupMenu::textColourId));
  51791. if (textColourToUse != 0)
  51792. textColour = *textColourToUse;
  51793. if (isHighlighted)
  51794. {
  51795. g.setColour (findColour (PopupMenu::highlightedBackgroundColourId));
  51796. g.fillRect (1, 1, width - 2, height - 2);
  51797. g.setColour (findColour (PopupMenu::highlightedTextColourId));
  51798. }
  51799. else
  51800. {
  51801. g.setColour (textColour);
  51802. }
  51803. if (! isActive)
  51804. g.setOpacity (0.3f);
  51805. Font font (getPopupMenuFont());
  51806. if (font.getHeight() > height / 1.3f)
  51807. font.setHeight (height / 1.3f);
  51808. g.setFont (font);
  51809. const int leftBorder = (height * 5) / 4;
  51810. const int rightBorder = 4;
  51811. if (image != 0)
  51812. {
  51813. g.drawImageWithin (image,
  51814. 2, 1, leftBorder - 4, height - 2,
  51815. RectanglePlacement::centred | RectanglePlacement::onlyReduceInSize, false);
  51816. }
  51817. else if (isTicked)
  51818. {
  51819. const Path tick (getTickShape (1.0f));
  51820. const float th = font.getAscent();
  51821. const float ty = halfH - th * 0.5f;
  51822. g.fillPath (tick, tick.getTransformToScaleToFit (2.0f, ty, (float) (leftBorder - 4),
  51823. th, true));
  51824. }
  51825. g.drawFittedText (text,
  51826. leftBorder, 0,
  51827. width - (leftBorder + rightBorder), height,
  51828. Justification::centredLeft, 1);
  51829. if (shortcutKeyText.isNotEmpty())
  51830. {
  51831. Font f2 (font);
  51832. f2.setHeight (f2.getHeight() * 0.75f);
  51833. f2.setHorizontalScale (0.95f);
  51834. g.setFont (f2);
  51835. g.drawText (shortcutKeyText,
  51836. leftBorder,
  51837. 0,
  51838. width - (leftBorder + rightBorder + 4),
  51839. height,
  51840. Justification::centredRight,
  51841. true);
  51842. }
  51843. if (hasSubMenu)
  51844. {
  51845. const float arrowH = 0.6f * getPopupMenuFont().getAscent();
  51846. const float x = width - height * 0.6f;
  51847. Path p;
  51848. p.addTriangle (x, halfH - arrowH * 0.5f,
  51849. x, halfH + arrowH * 0.5f,
  51850. x + arrowH * 0.6f, halfH);
  51851. g.fillPath (p);
  51852. }
  51853. }
  51854. }
  51855. int LookAndFeel::getMenuWindowFlags()
  51856. {
  51857. return ComponentPeer::windowHasDropShadow;
  51858. }
  51859. void LookAndFeel::drawMenuBarBackground (Graphics& g, int width, int height,
  51860. bool, MenuBarComponent& menuBar)
  51861. {
  51862. const Colour baseColour (createBaseColour (menuBar.findColour (PopupMenu::backgroundColourId), false, false, false));
  51863. if (menuBar.isEnabled())
  51864. {
  51865. drawShinyButtonShape (g,
  51866. -4.0f, 0.0f,
  51867. width + 8.0f, (float) height,
  51868. 0.0f,
  51869. baseColour,
  51870. 0.4f,
  51871. true, true, true, true);
  51872. }
  51873. else
  51874. {
  51875. g.fillAll (baseColour);
  51876. }
  51877. }
  51878. const Font LookAndFeel::getMenuBarFont (MenuBarComponent& menuBar, int /*itemIndex*/, const String& /*itemText*/)
  51879. {
  51880. return Font (menuBar.getHeight() * 0.7f);
  51881. }
  51882. int LookAndFeel::getMenuBarItemWidth (MenuBarComponent& menuBar, int itemIndex, const String& itemText)
  51883. {
  51884. return getMenuBarFont (menuBar, itemIndex, itemText)
  51885. .getStringWidth (itemText) + menuBar.getHeight();
  51886. }
  51887. void LookAndFeel::drawMenuBarItem (Graphics& g,
  51888. int width, int height,
  51889. int itemIndex,
  51890. const String& itemText,
  51891. bool isMouseOverItem,
  51892. bool isMenuOpen,
  51893. bool /*isMouseOverBar*/,
  51894. MenuBarComponent& menuBar)
  51895. {
  51896. if (! menuBar.isEnabled())
  51897. {
  51898. g.setColour (menuBar.findColour (PopupMenu::textColourId)
  51899. .withMultipliedAlpha (0.5f));
  51900. }
  51901. else if (isMenuOpen || isMouseOverItem)
  51902. {
  51903. g.fillAll (menuBar.findColour (PopupMenu::highlightedBackgroundColourId));
  51904. g.setColour (menuBar.findColour (PopupMenu::highlightedTextColourId));
  51905. }
  51906. else
  51907. {
  51908. g.setColour (menuBar.findColour (PopupMenu::textColourId));
  51909. }
  51910. g.setFont (getMenuBarFont (menuBar, itemIndex, itemText));
  51911. g.drawFittedText (itemText, 0, 0, width, height, Justification::centred, 1);
  51912. }
  51913. void LookAndFeel::fillTextEditorBackground (Graphics& g, int /*width*/, int /*height*/,
  51914. TextEditor& textEditor)
  51915. {
  51916. g.fillAll (textEditor.findColour (TextEditor::backgroundColourId));
  51917. }
  51918. void LookAndFeel::drawTextEditorOutline (Graphics& g, int width, int height, TextEditor& textEditor)
  51919. {
  51920. if (textEditor.isEnabled())
  51921. {
  51922. if (textEditor.hasKeyboardFocus (true) && ! textEditor.isReadOnly())
  51923. {
  51924. const int border = 2;
  51925. g.setColour (textEditor.findColour (TextEditor::focusedOutlineColourId));
  51926. g.drawRect (0, 0, width, height, border);
  51927. g.setOpacity (1.0f);
  51928. const Colour shadowColour (textEditor.findColour (TextEditor::shadowColourId).withMultipliedAlpha (0.75f));
  51929. g.drawBevel (0, 0, width, height + 2, border + 2, shadowColour, shadowColour);
  51930. }
  51931. else
  51932. {
  51933. g.setColour (textEditor.findColour (TextEditor::outlineColourId));
  51934. g.drawRect (0, 0, width, height);
  51935. g.setOpacity (1.0f);
  51936. const Colour shadowColour (textEditor.findColour (TextEditor::shadowColourId));
  51937. g.drawBevel (0, 0, width, height + 2, 3, shadowColour, shadowColour);
  51938. }
  51939. }
  51940. }
  51941. void LookAndFeel::drawComboBox (Graphics& g, int width, int height,
  51942. const bool isButtonDown,
  51943. int buttonX, int buttonY,
  51944. int buttonW, int buttonH,
  51945. ComboBox& box)
  51946. {
  51947. g.fillAll (box.findColour (ComboBox::backgroundColourId));
  51948. if (box.isEnabled() && box.hasKeyboardFocus (false))
  51949. {
  51950. g.setColour (box.findColour (TextButton::buttonColourId));
  51951. g.drawRect (0, 0, width, height, 2);
  51952. }
  51953. else
  51954. {
  51955. g.setColour (box.findColour (ComboBox::outlineColourId));
  51956. g.drawRect (0, 0, width, height);
  51957. }
  51958. const float outlineThickness = box.isEnabled() ? (isButtonDown ? 1.2f : 0.5f) : 0.3f;
  51959. const Colour baseColour (createBaseColour (box.findColour (ComboBox::buttonColourId),
  51960. box.hasKeyboardFocus (true),
  51961. false, isButtonDown)
  51962. .withMultipliedAlpha (box.isEnabled() ? 1.0f : 0.5f));
  51963. drawGlassLozenge (g,
  51964. buttonX + outlineThickness, buttonY + outlineThickness,
  51965. buttonW - outlineThickness * 2.0f, buttonH - outlineThickness * 2.0f,
  51966. baseColour, outlineThickness, -1.0f,
  51967. true, true, true, true);
  51968. if (box.isEnabled())
  51969. {
  51970. const float arrowX = 0.3f;
  51971. const float arrowH = 0.2f;
  51972. Path p;
  51973. p.addTriangle (buttonX + buttonW * 0.5f, buttonY + buttonH * (0.45f - arrowH),
  51974. buttonX + buttonW * (1.0f - arrowX), buttonY + buttonH * 0.45f,
  51975. buttonX + buttonW * arrowX, buttonY + buttonH * 0.45f);
  51976. p.addTriangle (buttonX + buttonW * 0.5f, buttonY + buttonH * (0.55f + arrowH),
  51977. buttonX + buttonW * (1.0f - arrowX), buttonY + buttonH * 0.55f,
  51978. buttonX + buttonW * arrowX, buttonY + buttonH * 0.55f);
  51979. g.setColour (box.findColour (ComboBox::arrowColourId));
  51980. g.fillPath (p);
  51981. }
  51982. }
  51983. const Font LookAndFeel::getComboBoxFont (ComboBox& box)
  51984. {
  51985. return Font (jmin (15.0f, box.getHeight() * 0.85f));
  51986. }
  51987. Label* LookAndFeel::createComboBoxTextBox (ComboBox&)
  51988. {
  51989. return new Label (String::empty, String::empty);
  51990. }
  51991. void LookAndFeel::positionComboBoxText (ComboBox& box, Label& label)
  51992. {
  51993. label.setBounds (1, 1,
  51994. box.getWidth() + 3 - box.getHeight(),
  51995. box.getHeight() - 2);
  51996. label.setFont (getComboBoxFont (box));
  51997. }
  51998. void LookAndFeel::drawLabel (Graphics& g, Label& label)
  51999. {
  52000. g.fillAll (label.findColour (Label::backgroundColourId));
  52001. if (! label.isBeingEdited())
  52002. {
  52003. const float alpha = label.isEnabled() ? 1.0f : 0.5f;
  52004. g.setColour (label.findColour (Label::textColourId).withMultipliedAlpha (alpha));
  52005. g.setFont (label.getFont());
  52006. g.drawFittedText (label.getText(),
  52007. label.getHorizontalBorderSize(),
  52008. label.getVerticalBorderSize(),
  52009. label.getWidth() - 2 * label.getHorizontalBorderSize(),
  52010. label.getHeight() - 2 * label.getVerticalBorderSize(),
  52011. label.getJustificationType(),
  52012. jmax (1, (int) (label.getHeight() / label.getFont().getHeight())),
  52013. label.getMinimumHorizontalScale());
  52014. g.setColour (label.findColour (Label::outlineColourId).withMultipliedAlpha (alpha));
  52015. g.drawRect (0, 0, label.getWidth(), label.getHeight());
  52016. }
  52017. else if (label.isEnabled())
  52018. {
  52019. g.setColour (label.findColour (Label::outlineColourId));
  52020. g.drawRect (0, 0, label.getWidth(), label.getHeight());
  52021. }
  52022. }
  52023. void LookAndFeel::drawLinearSliderBackground (Graphics& g,
  52024. int x, int y,
  52025. int width, int height,
  52026. float /*sliderPos*/,
  52027. float /*minSliderPos*/,
  52028. float /*maxSliderPos*/,
  52029. const Slider::SliderStyle /*style*/,
  52030. Slider& slider)
  52031. {
  52032. const float sliderRadius = (float) (getSliderThumbRadius (slider) - 2);
  52033. const Colour trackColour (slider.findColour (Slider::trackColourId));
  52034. const Colour gradCol1 (trackColour.overlaidWith (Colours::black.withAlpha (slider.isEnabled() ? 0.25f : 0.13f)));
  52035. const Colour gradCol2 (trackColour.overlaidWith (Colour (0x14000000)));
  52036. Path indent;
  52037. if (slider.isHorizontal())
  52038. {
  52039. const float iy = y + height * 0.5f - sliderRadius * 0.5f;
  52040. const float ih = sliderRadius;
  52041. g.setGradientFill (ColourGradient (gradCol1, 0.0f, iy,
  52042. gradCol2, 0.0f, iy + ih, false));
  52043. indent.addRoundedRectangle (x - sliderRadius * 0.5f, iy,
  52044. width + sliderRadius, ih,
  52045. 5.0f);
  52046. g.fillPath (indent);
  52047. }
  52048. else
  52049. {
  52050. const float ix = x + width * 0.5f - sliderRadius * 0.5f;
  52051. const float iw = sliderRadius;
  52052. g.setGradientFill (ColourGradient (gradCol1, ix, 0.0f,
  52053. gradCol2, ix + iw, 0.0f, false));
  52054. indent.addRoundedRectangle (ix, y - sliderRadius * 0.5f,
  52055. iw, height + sliderRadius,
  52056. 5.0f);
  52057. g.fillPath (indent);
  52058. }
  52059. g.setColour (Colour (0x4c000000));
  52060. g.strokePath (indent, PathStrokeType (0.5f));
  52061. }
  52062. void LookAndFeel::drawLinearSliderThumb (Graphics& g,
  52063. int x, int y,
  52064. int width, int height,
  52065. float sliderPos,
  52066. float minSliderPos,
  52067. float maxSliderPos,
  52068. const Slider::SliderStyle style,
  52069. Slider& slider)
  52070. {
  52071. const float sliderRadius = (float) (getSliderThumbRadius (slider) - 2);
  52072. Colour knobColour (createBaseColour (slider.findColour (Slider::thumbColourId),
  52073. slider.hasKeyboardFocus (false) && slider.isEnabled(),
  52074. slider.isMouseOverOrDragging() && slider.isEnabled(),
  52075. slider.isMouseButtonDown() && slider.isEnabled()));
  52076. const float outlineThickness = slider.isEnabled() ? 0.8f : 0.3f;
  52077. if (style == Slider::LinearHorizontal || style == Slider::LinearVertical)
  52078. {
  52079. float kx, ky;
  52080. if (style == Slider::LinearVertical)
  52081. {
  52082. kx = x + width * 0.5f;
  52083. ky = sliderPos;
  52084. }
  52085. else
  52086. {
  52087. kx = sliderPos;
  52088. ky = y + height * 0.5f;
  52089. }
  52090. drawGlassSphere (g,
  52091. kx - sliderRadius,
  52092. ky - sliderRadius,
  52093. sliderRadius * 2.0f,
  52094. knobColour, outlineThickness);
  52095. }
  52096. else
  52097. {
  52098. if (style == Slider::ThreeValueVertical)
  52099. {
  52100. drawGlassSphere (g, x + width * 0.5f - sliderRadius,
  52101. sliderPos - sliderRadius,
  52102. sliderRadius * 2.0f,
  52103. knobColour, outlineThickness);
  52104. }
  52105. else if (style == Slider::ThreeValueHorizontal)
  52106. {
  52107. drawGlassSphere (g,sliderPos - sliderRadius,
  52108. y + height * 0.5f - sliderRadius,
  52109. sliderRadius * 2.0f,
  52110. knobColour, outlineThickness);
  52111. }
  52112. if (style == Slider::TwoValueVertical || style == Slider::ThreeValueVertical)
  52113. {
  52114. const float sr = jmin (sliderRadius, width * 0.4f);
  52115. drawGlassPointer (g, jmax (0.0f, x + width * 0.5f - sliderRadius * 2.0f),
  52116. minSliderPos - sliderRadius,
  52117. sliderRadius * 2.0f, knobColour, outlineThickness, 1);
  52118. drawGlassPointer (g, jmin (x + width - sliderRadius * 2.0f, x + width * 0.5f), maxSliderPos - sr,
  52119. sliderRadius * 2.0f, knobColour, outlineThickness, 3);
  52120. }
  52121. else if (style == Slider::TwoValueHorizontal || style == Slider::ThreeValueHorizontal)
  52122. {
  52123. const float sr = jmin (sliderRadius, height * 0.4f);
  52124. drawGlassPointer (g, minSliderPos - sr,
  52125. jmax (0.0f, y + height * 0.5f - sliderRadius * 2.0f),
  52126. sliderRadius * 2.0f, knobColour, outlineThickness, 2);
  52127. drawGlassPointer (g, maxSliderPos - sliderRadius,
  52128. jmin (y + height - sliderRadius * 2.0f, y + height * 0.5f),
  52129. sliderRadius * 2.0f, knobColour, outlineThickness, 4);
  52130. }
  52131. }
  52132. }
  52133. void LookAndFeel::drawLinearSlider (Graphics& g,
  52134. int x, int y,
  52135. int width, int height,
  52136. float sliderPos,
  52137. float minSliderPos,
  52138. float maxSliderPos,
  52139. const Slider::SliderStyle style,
  52140. Slider& slider)
  52141. {
  52142. g.fillAll (slider.findColour (Slider::backgroundColourId));
  52143. if (style == Slider::LinearBar)
  52144. {
  52145. const bool isMouseOver = slider.isMouseOverOrDragging() && slider.isEnabled();
  52146. Colour baseColour (createBaseColour (slider.findColour (Slider::thumbColourId)
  52147. .withMultipliedSaturation (slider.isEnabled() ? 1.0f : 0.5f),
  52148. false,
  52149. isMouseOver,
  52150. isMouseOver || slider.isMouseButtonDown()));
  52151. drawShinyButtonShape (g,
  52152. (float) x, (float) y, sliderPos - (float) x, (float) height, 0.0f,
  52153. baseColour,
  52154. slider.isEnabled() ? 0.9f : 0.3f,
  52155. true, true, true, true);
  52156. }
  52157. else
  52158. {
  52159. drawLinearSliderBackground (g, x, y, width, height, sliderPos, minSliderPos, maxSliderPos, style, slider);
  52160. drawLinearSliderThumb (g, x, y, width, height, sliderPos, minSliderPos, maxSliderPos, style, slider);
  52161. }
  52162. }
  52163. int LookAndFeel::getSliderThumbRadius (Slider& slider)
  52164. {
  52165. return jmin (7,
  52166. slider.getHeight() / 2,
  52167. slider.getWidth() / 2) + 2;
  52168. }
  52169. void LookAndFeel::drawRotarySlider (Graphics& g,
  52170. int x, int y,
  52171. int width, int height,
  52172. float sliderPos,
  52173. const float rotaryStartAngle,
  52174. const float rotaryEndAngle,
  52175. Slider& slider)
  52176. {
  52177. const float radius = jmin (width / 2, height / 2) - 2.0f;
  52178. const float centreX = x + width * 0.5f;
  52179. const float centreY = y + height * 0.5f;
  52180. const float rx = centreX - radius;
  52181. const float ry = centreY - radius;
  52182. const float rw = radius * 2.0f;
  52183. const float angle = rotaryStartAngle + sliderPos * (rotaryEndAngle - rotaryStartAngle);
  52184. const bool isMouseOver = slider.isMouseOverOrDragging() && slider.isEnabled();
  52185. if (radius > 12.0f)
  52186. {
  52187. if (slider.isEnabled())
  52188. g.setColour (slider.findColour (Slider::rotarySliderFillColourId).withAlpha (isMouseOver ? 1.0f : 0.7f));
  52189. else
  52190. g.setColour (Colour (0x80808080));
  52191. const float thickness = 0.7f;
  52192. {
  52193. Path filledArc;
  52194. filledArc.addPieSegment (rx, ry, rw, rw,
  52195. rotaryStartAngle,
  52196. angle,
  52197. thickness);
  52198. g.fillPath (filledArc);
  52199. }
  52200. if (thickness > 0)
  52201. {
  52202. const float innerRadius = radius * 0.2f;
  52203. Path p;
  52204. p.addTriangle (-innerRadius, 0.0f,
  52205. 0.0f, -radius * thickness * 1.1f,
  52206. innerRadius, 0.0f);
  52207. p.addEllipse (-innerRadius, -innerRadius, innerRadius * 2.0f, innerRadius * 2.0f);
  52208. g.fillPath (p, AffineTransform::rotation (angle).translated (centreX, centreY));
  52209. }
  52210. if (slider.isEnabled())
  52211. g.setColour (slider.findColour (Slider::rotarySliderOutlineColourId));
  52212. else
  52213. g.setColour (Colour (0x80808080));
  52214. Path outlineArc;
  52215. outlineArc.addPieSegment (rx, ry, rw, rw, rotaryStartAngle, rotaryEndAngle, thickness);
  52216. outlineArc.closeSubPath();
  52217. g.strokePath (outlineArc, PathStrokeType (slider.isEnabled() ? (isMouseOver ? 2.0f : 1.2f) : 0.3f));
  52218. }
  52219. else
  52220. {
  52221. if (slider.isEnabled())
  52222. g.setColour (slider.findColour (Slider::rotarySliderFillColourId).withAlpha (isMouseOver ? 1.0f : 0.7f));
  52223. else
  52224. g.setColour (Colour (0x80808080));
  52225. Path p;
  52226. p.addEllipse (-0.4f * rw, -0.4f * rw, rw * 0.8f, rw * 0.8f);
  52227. PathStrokeType (rw * 0.1f).createStrokedPath (p, p);
  52228. p.addLineSegment (0.0f, 0.0f, 0.0f, -radius, rw * 0.2f);
  52229. g.fillPath (p, AffineTransform::rotation (angle).translated (centreX, centreY));
  52230. }
  52231. }
  52232. Button* LookAndFeel::createSliderButton (const bool isIncrement)
  52233. {
  52234. return new TextButton (isIncrement ? "+" : "-", String::empty);
  52235. }
  52236. class SliderLabelComp : public Label
  52237. {
  52238. public:
  52239. SliderLabelComp() : Label (String::empty, String::empty) {}
  52240. ~SliderLabelComp() {}
  52241. void mouseWheelMove (const MouseEvent&, float, float) {}
  52242. };
  52243. Label* LookAndFeel::createSliderTextBox (Slider& slider)
  52244. {
  52245. Label* const l = new SliderLabelComp();
  52246. l->setJustificationType (Justification::centred);
  52247. l->setColour (Label::textColourId, slider.findColour (Slider::textBoxTextColourId));
  52248. l->setColour (Label::backgroundColourId,
  52249. (slider.getSliderStyle() == Slider::LinearBar) ? Colours::transparentBlack
  52250. : slider.findColour (Slider::textBoxBackgroundColourId));
  52251. l->setColour (Label::outlineColourId, slider.findColour (Slider::textBoxOutlineColourId));
  52252. l->setColour (TextEditor::textColourId, slider.findColour (Slider::textBoxTextColourId));
  52253. l->setColour (TextEditor::backgroundColourId,
  52254. slider.findColour (Slider::textBoxBackgroundColourId)
  52255. .withAlpha (slider.getSliderStyle() == Slider::LinearBar ? 0.7f : 1.0f));
  52256. l->setColour (TextEditor::outlineColourId, slider.findColour (Slider::textBoxOutlineColourId));
  52257. return l;
  52258. }
  52259. ImageEffectFilter* LookAndFeel::getSliderEffect()
  52260. {
  52261. return 0;
  52262. }
  52263. static const TextLayout layoutTooltipText (const String& text) throw()
  52264. {
  52265. const float tooltipFontSize = 12.0f;
  52266. const int maxToolTipWidth = 400;
  52267. const Font f (tooltipFontSize, Font::bold);
  52268. TextLayout tl (text, f);
  52269. tl.layout (maxToolTipWidth, Justification::left, true);
  52270. return tl;
  52271. }
  52272. void LookAndFeel::getTooltipSize (const String& tipText, int& width, int& height)
  52273. {
  52274. const TextLayout tl (layoutTooltipText (tipText));
  52275. width = tl.getWidth() + 14;
  52276. height = tl.getHeight() + 6;
  52277. }
  52278. void LookAndFeel::drawTooltip (Graphics& g, const String& text, int width, int height)
  52279. {
  52280. g.fillAll (findColour (TooltipWindow::backgroundColourId));
  52281. const Colour textCol (findColour (TooltipWindow::textColourId));
  52282. #if ! JUCE_MAC // The mac windows already have a non-optional 1 pix outline, so don't double it here..
  52283. g.setColour (findColour (TooltipWindow::outlineColourId));
  52284. g.drawRect (0, 0, width, height, 1);
  52285. #endif
  52286. const TextLayout tl (layoutTooltipText (text));
  52287. g.setColour (findColour (TooltipWindow::textColourId));
  52288. tl.drawWithin (g, 0, 0, width, height, Justification::centred);
  52289. }
  52290. Button* LookAndFeel::createFilenameComponentBrowseButton (const String& text)
  52291. {
  52292. return new TextButton (text, TRANS("click to browse for a different file"));
  52293. }
  52294. void LookAndFeel::layoutFilenameComponent (FilenameComponent& filenameComp,
  52295. ComboBox* filenameBox,
  52296. Button* browseButton)
  52297. {
  52298. browseButton->setSize (80, filenameComp.getHeight());
  52299. TextButton* const tb = dynamic_cast <TextButton*> (browseButton);
  52300. if (tb != 0)
  52301. tb->changeWidthToFitText();
  52302. browseButton->setTopRightPosition (filenameComp.getWidth(), 0);
  52303. filenameBox->setBounds (0, 0, browseButton->getX(), filenameComp.getHeight());
  52304. }
  52305. void LookAndFeel::drawImageButton (Graphics& g, Image* image,
  52306. int imageX, int imageY, int imageW, int imageH,
  52307. const Colour& overlayColour,
  52308. float imageOpacity,
  52309. ImageButton& button)
  52310. {
  52311. if (! button.isEnabled())
  52312. imageOpacity *= 0.3f;
  52313. if (! overlayColour.isOpaque())
  52314. {
  52315. g.setOpacity (imageOpacity);
  52316. g.drawImage (image, imageX, imageY, imageW, imageH,
  52317. 0, 0, image->getWidth(), image->getHeight(), false);
  52318. }
  52319. if (! overlayColour.isTransparent())
  52320. {
  52321. g.setColour (overlayColour);
  52322. g.drawImage (image, imageX, imageY, imageW, imageH,
  52323. 0, 0, image->getWidth(), image->getHeight(), true);
  52324. }
  52325. }
  52326. void LookAndFeel::drawCornerResizer (Graphics& g,
  52327. int w, int h,
  52328. bool /*isMouseOver*/,
  52329. bool /*isMouseDragging*/)
  52330. {
  52331. const float lineThickness = jmin (w, h) * 0.075f;
  52332. for (float i = 0.0f; i < 1.0f; i += 0.3f)
  52333. {
  52334. g.setColour (Colours::lightgrey);
  52335. g.drawLine (w * i,
  52336. h + 1.0f,
  52337. w + 1.0f,
  52338. h * i,
  52339. lineThickness);
  52340. g.setColour (Colours::darkgrey);
  52341. g.drawLine (w * i + lineThickness,
  52342. h + 1.0f,
  52343. w + 1.0f,
  52344. h * i + lineThickness,
  52345. lineThickness);
  52346. }
  52347. }
  52348. void LookAndFeel::drawResizableFrame (Graphics&, int /*w*/, int /*h*/,
  52349. const BorderSize& /*borders*/)
  52350. {
  52351. }
  52352. void LookAndFeel::fillResizableWindowBackground (Graphics& g, int /*w*/, int /*h*/,
  52353. const BorderSize& /*border*/, ResizableWindow& window)
  52354. {
  52355. g.fillAll (window.getBackgroundColour());
  52356. }
  52357. void LookAndFeel::drawResizableWindowBorder (Graphics& g, int w, int h,
  52358. const BorderSize& border, ResizableWindow&)
  52359. {
  52360. g.setColour (Colour (0x80000000));
  52361. g.drawRect (0, 0, w, h);
  52362. g.setColour (Colour (0x19000000));
  52363. g.drawRect (border.getLeft() - 1,
  52364. border.getTop() - 1,
  52365. w + 2 - border.getLeftAndRight(),
  52366. h + 2 - border.getTopAndBottom());
  52367. }
  52368. void LookAndFeel::drawDocumentWindowTitleBar (DocumentWindow& window,
  52369. Graphics& g, int w, int h,
  52370. int titleSpaceX, int titleSpaceW,
  52371. const Image* icon,
  52372. bool drawTitleTextOnLeft)
  52373. {
  52374. const bool isActive = window.isActiveWindow();
  52375. g.setGradientFill (ColourGradient (window.getBackgroundColour(),
  52376. 0.0f, 0.0f,
  52377. window.getBackgroundColour().contrasting (isActive ? 0.15f : 0.05f),
  52378. 0.0f, (float) h, false));
  52379. g.fillAll();
  52380. Font font (h * 0.65f, Font::bold);
  52381. g.setFont (font);
  52382. int textW = font.getStringWidth (window.getName());
  52383. int iconW = 0;
  52384. int iconH = 0;
  52385. if (icon != 0)
  52386. {
  52387. iconH = (int) font.getHeight();
  52388. iconW = icon->getWidth() * iconH / icon->getHeight() + 4;
  52389. }
  52390. textW = jmin (titleSpaceW, textW + iconW);
  52391. int textX = drawTitleTextOnLeft ? titleSpaceX
  52392. : jmax (titleSpaceX, (w - textW) / 2);
  52393. if (textX + textW > titleSpaceX + titleSpaceW)
  52394. textX = titleSpaceX + titleSpaceW - textW;
  52395. if (icon != 0)
  52396. {
  52397. g.setOpacity (isActive ? 1.0f : 0.6f);
  52398. g.drawImageWithin (icon, textX, (h - iconH) / 2, iconW, iconH,
  52399. RectanglePlacement::centred, false);
  52400. textX += iconW;
  52401. textW -= iconW;
  52402. }
  52403. if (window.isColourSpecified (DocumentWindow::textColourId) || isColourSpecified (DocumentWindow::textColourId))
  52404. g.setColour (findColour (DocumentWindow::textColourId));
  52405. else
  52406. g.setColour (window.getBackgroundColour().contrasting (isActive ? 0.7f : 0.4f));
  52407. g.drawText (window.getName(), textX, 0, textW, h, Justification::centredLeft, true);
  52408. }
  52409. class GlassWindowButton : public Button
  52410. {
  52411. public:
  52412. GlassWindowButton (const String& name, const Colour& col,
  52413. const Path& normalShape_,
  52414. const Path& toggledShape_) throw()
  52415. : Button (name),
  52416. colour (col),
  52417. normalShape (normalShape_),
  52418. toggledShape (toggledShape_)
  52419. {
  52420. }
  52421. ~GlassWindowButton()
  52422. {
  52423. }
  52424. void paintButton (Graphics& g, bool isMouseOverButton, bool isButtonDown)
  52425. {
  52426. float alpha = isMouseOverButton ? (isButtonDown ? 1.0f : 0.8f) : 0.55f;
  52427. if (! isEnabled())
  52428. alpha *= 0.5f;
  52429. float x = 0, y = 0, diam;
  52430. if (getWidth() < getHeight())
  52431. {
  52432. diam = (float) getWidth();
  52433. y = (getHeight() - getWidth()) * 0.5f;
  52434. }
  52435. else
  52436. {
  52437. diam = (float) getHeight();
  52438. y = (getWidth() - getHeight()) * 0.5f;
  52439. }
  52440. x += diam * 0.05f;
  52441. y += diam * 0.05f;
  52442. diam *= 0.9f;
  52443. g.setGradientFill (ColourGradient (Colour::greyLevel (0.9f).withAlpha (alpha), 0, y + diam,
  52444. Colour::greyLevel (0.6f).withAlpha (alpha), 0, y, false));
  52445. g.fillEllipse (x, y, diam, diam);
  52446. x += 2.0f;
  52447. y += 2.0f;
  52448. diam -= 4.0f;
  52449. LookAndFeel::drawGlassSphere (g, x, y, diam, colour.withAlpha (alpha), 1.0f);
  52450. Path& p = getToggleState() ? toggledShape : normalShape;
  52451. const AffineTransform t (p.getTransformToScaleToFit (x + diam * 0.3f, y + diam * 0.3f,
  52452. diam * 0.4f, diam * 0.4f, true));
  52453. g.setColour (Colours::black.withAlpha (alpha * 0.6f));
  52454. g.fillPath (p, t);
  52455. }
  52456. juce_UseDebuggingNewOperator
  52457. private:
  52458. Colour colour;
  52459. Path normalShape, toggledShape;
  52460. GlassWindowButton (const GlassWindowButton&);
  52461. GlassWindowButton& operator= (const GlassWindowButton&);
  52462. };
  52463. Button* LookAndFeel::createDocumentWindowButton (int buttonType)
  52464. {
  52465. Path shape;
  52466. const float crossThickness = 0.25f;
  52467. if (buttonType == DocumentWindow::closeButton)
  52468. {
  52469. shape.addLineSegment (0.0f, 0.0f, 1.0f, 1.0f, crossThickness * 1.4f);
  52470. shape.addLineSegment (1.0f, 0.0f, 0.0f, 1.0f, crossThickness * 1.4f);
  52471. return new GlassWindowButton ("close", Colour (0xffdd1100), shape, shape);
  52472. }
  52473. else if (buttonType == DocumentWindow::minimiseButton)
  52474. {
  52475. shape.addLineSegment (0.0f, 0.5f, 1.0f, 0.5f, crossThickness);
  52476. return new GlassWindowButton ("minimise", Colour (0xffaa8811), shape, shape);
  52477. }
  52478. else if (buttonType == DocumentWindow::maximiseButton)
  52479. {
  52480. shape.addLineSegment (0.5f, 0.0f, 0.5f, 1.0f, crossThickness);
  52481. shape.addLineSegment (0.0f, 0.5f, 1.0f, 0.5f, crossThickness);
  52482. Path fullscreenShape;
  52483. fullscreenShape.startNewSubPath (45.0f, 100.0f);
  52484. fullscreenShape.lineTo (0.0f, 100.0f);
  52485. fullscreenShape.lineTo (0.0f, 0.0f);
  52486. fullscreenShape.lineTo (100.0f, 0.0f);
  52487. fullscreenShape.lineTo (100.0f, 45.0f);
  52488. fullscreenShape.addRectangle (45.0f, 45.0f, 100.0f, 100.0f);
  52489. PathStrokeType (30.0f).createStrokedPath (fullscreenShape, fullscreenShape);
  52490. return new GlassWindowButton ("maximise", Colour (0xff119911), shape, fullscreenShape);
  52491. }
  52492. jassertfalse
  52493. return 0;
  52494. }
  52495. void LookAndFeel::positionDocumentWindowButtons (DocumentWindow&,
  52496. int titleBarX,
  52497. int titleBarY,
  52498. int titleBarW,
  52499. int titleBarH,
  52500. Button* minimiseButton,
  52501. Button* maximiseButton,
  52502. Button* closeButton,
  52503. bool positionTitleBarButtonsOnLeft)
  52504. {
  52505. const int buttonW = titleBarH - titleBarH / 8;
  52506. int x = positionTitleBarButtonsOnLeft ? titleBarX + 4
  52507. : titleBarX + titleBarW - buttonW - buttonW / 4;
  52508. if (closeButton != 0)
  52509. {
  52510. closeButton->setBounds (x, titleBarY, buttonW, titleBarH);
  52511. x += positionTitleBarButtonsOnLeft ? buttonW : -(buttonW + buttonW / 4);
  52512. }
  52513. if (positionTitleBarButtonsOnLeft)
  52514. swapVariables (minimiseButton, maximiseButton);
  52515. if (maximiseButton != 0)
  52516. {
  52517. maximiseButton->setBounds (x, titleBarY, buttonW, titleBarH);
  52518. x += positionTitleBarButtonsOnLeft ? buttonW : -buttonW;
  52519. }
  52520. if (minimiseButton != 0)
  52521. minimiseButton->setBounds (x, titleBarY, buttonW, titleBarH);
  52522. }
  52523. int LookAndFeel::getDefaultMenuBarHeight()
  52524. {
  52525. return 24;
  52526. }
  52527. DropShadower* LookAndFeel::createDropShadowerForComponent (Component*)
  52528. {
  52529. return new DropShadower (0.4f, 1, 5, 10);
  52530. }
  52531. void LookAndFeel::drawStretchableLayoutResizerBar (Graphics& g,
  52532. int w, int h,
  52533. bool /*isVerticalBar*/,
  52534. bool isMouseOver,
  52535. bool isMouseDragging)
  52536. {
  52537. float alpha = 0.5f;
  52538. if (isMouseOver || isMouseDragging)
  52539. {
  52540. g.fillAll (Colour (0x190000ff));
  52541. alpha = 1.0f;
  52542. }
  52543. const float cx = w * 0.5f;
  52544. const float cy = h * 0.5f;
  52545. const float cr = jmin (w, h) * 0.4f;
  52546. g.setGradientFill (ColourGradient (Colours::white.withAlpha (alpha), cx + cr * 0.1f, cy + cr,
  52547. Colours::black.withAlpha (alpha), cx, cy - cr * 4.0f,
  52548. true));
  52549. g.fillEllipse (cx - cr, cy - cr, cr * 2.0f, cr * 2.0f);
  52550. }
  52551. void LookAndFeel::drawGroupComponentOutline (Graphics& g, int width, int height,
  52552. const String& text,
  52553. const Justification& position,
  52554. GroupComponent& group)
  52555. {
  52556. const float textH = 15.0f;
  52557. const float indent = 3.0f;
  52558. const float textEdgeGap = 4.0f;
  52559. float cs = 5.0f;
  52560. Font f (textH);
  52561. Path p;
  52562. float x = indent;
  52563. float y = f.getAscent() - 3.0f;
  52564. float w = jmax (0.0f, width - x * 2.0f);
  52565. float h = jmax (0.0f, height - y - indent);
  52566. cs = jmin (cs, w * 0.5f, h * 0.5f);
  52567. const float cs2 = 2.0f * cs;
  52568. float textW = text.isEmpty() ? 0 : jlimit (0.0f, jmax (0.0f, w - cs2 - textEdgeGap * 2), f.getStringWidth (text) + textEdgeGap * 2.0f);
  52569. float textX = cs + textEdgeGap;
  52570. if (position.testFlags (Justification::horizontallyCentred))
  52571. textX = cs + (w - cs2 - textW) * 0.5f;
  52572. else if (position.testFlags (Justification::right))
  52573. textX = w - cs - textW - textEdgeGap;
  52574. p.startNewSubPath (x + textX + textW, y);
  52575. p.lineTo (x + w - cs, y);
  52576. p.addArc (x + w - cs2, y, cs2, cs2, 0, float_Pi * 0.5f);
  52577. p.lineTo (x + w, y + h - cs);
  52578. p.addArc (x + w - cs2, y + h - cs2, cs2, cs2, float_Pi * 0.5f, float_Pi);
  52579. p.lineTo (x + cs, y + h);
  52580. p.addArc (x, y + h - cs2, cs2, cs2, float_Pi, float_Pi * 1.5f);
  52581. p.lineTo (x, y + cs);
  52582. p.addArc (x, y, cs2, cs2, float_Pi * 1.5f, float_Pi * 2.0f);
  52583. p.lineTo (x + textX, y);
  52584. const float alpha = group.isEnabled() ? 1.0f : 0.5f;
  52585. g.setColour (group.findColour (GroupComponent::outlineColourId)
  52586. .withMultipliedAlpha (alpha));
  52587. g.strokePath (p, PathStrokeType (2.0f));
  52588. g.setColour (group.findColour (GroupComponent::textColourId)
  52589. .withMultipliedAlpha (alpha));
  52590. g.setFont (f);
  52591. g.drawText (text,
  52592. roundToInt (x + textX), 0,
  52593. roundToInt (textW),
  52594. roundToInt (textH),
  52595. Justification::centred, true);
  52596. }
  52597. int LookAndFeel::getTabButtonOverlap (int tabDepth)
  52598. {
  52599. return 1 + tabDepth / 3;
  52600. }
  52601. int LookAndFeel::getTabButtonSpaceAroundImage()
  52602. {
  52603. return 4;
  52604. }
  52605. void LookAndFeel::createTabButtonShape (Path& p,
  52606. int width, int height,
  52607. int /*tabIndex*/,
  52608. const String& /*text*/,
  52609. Button& /*button*/,
  52610. TabbedButtonBar::Orientation orientation,
  52611. const bool /*isMouseOver*/,
  52612. const bool /*isMouseDown*/,
  52613. const bool /*isFrontTab*/)
  52614. {
  52615. const float w = (float) width;
  52616. const float h = (float) height;
  52617. float length = w;
  52618. float depth = h;
  52619. if (orientation == TabbedButtonBar::TabsAtLeft
  52620. || orientation == TabbedButtonBar::TabsAtRight)
  52621. {
  52622. swapVariables (length, depth);
  52623. }
  52624. const float indent = (float) getTabButtonOverlap ((int) depth);
  52625. const float overhang = 4.0f;
  52626. if (orientation == TabbedButtonBar::TabsAtLeft)
  52627. {
  52628. p.startNewSubPath (w, 0.0f);
  52629. p.lineTo (0.0f, indent);
  52630. p.lineTo (0.0f, h - indent);
  52631. p.lineTo (w, h);
  52632. p.lineTo (w + overhang, h + overhang);
  52633. p.lineTo (w + overhang, -overhang);
  52634. }
  52635. else if (orientation == TabbedButtonBar::TabsAtRight)
  52636. {
  52637. p.startNewSubPath (0.0f, 0.0f);
  52638. p.lineTo (w, indent);
  52639. p.lineTo (w, h - indent);
  52640. p.lineTo (0.0f, h);
  52641. p.lineTo (-overhang, h + overhang);
  52642. p.lineTo (-overhang, -overhang);
  52643. }
  52644. else if (orientation == TabbedButtonBar::TabsAtBottom)
  52645. {
  52646. p.startNewSubPath (0.0f, 0.0f);
  52647. p.lineTo (indent, h);
  52648. p.lineTo (w - indent, h);
  52649. p.lineTo (w, 0.0f);
  52650. p.lineTo (w + overhang, -overhang);
  52651. p.lineTo (-overhang, -overhang);
  52652. }
  52653. else
  52654. {
  52655. p.startNewSubPath (0.0f, h);
  52656. p.lineTo (indent, 0.0f);
  52657. p.lineTo (w - indent, 0.0f);
  52658. p.lineTo (w, h);
  52659. p.lineTo (w + overhang, h + overhang);
  52660. p.lineTo (-overhang, h + overhang);
  52661. }
  52662. p.closeSubPath();
  52663. p = p.createPathWithRoundedCorners (3.0f);
  52664. }
  52665. void LookAndFeel::fillTabButtonShape (Graphics& g,
  52666. const Path& path,
  52667. const Colour& preferredColour,
  52668. int /*tabIndex*/,
  52669. const String& /*text*/,
  52670. Button& button,
  52671. TabbedButtonBar::Orientation /*orientation*/,
  52672. const bool /*isMouseOver*/,
  52673. const bool /*isMouseDown*/,
  52674. const bool isFrontTab)
  52675. {
  52676. g.setColour (isFrontTab ? preferredColour
  52677. : preferredColour.withMultipliedAlpha (0.9f));
  52678. g.fillPath (path);
  52679. g.setColour (button.findColour (isFrontTab ? TabbedButtonBar::frontOutlineColourId
  52680. : TabbedButtonBar::tabOutlineColourId, false)
  52681. .withMultipliedAlpha (button.isEnabled() ? 1.0f : 0.5f));
  52682. g.strokePath (path, PathStrokeType (isFrontTab ? 1.0f : 0.5f));
  52683. }
  52684. void LookAndFeel::drawTabButtonText (Graphics& g,
  52685. int x, int y, int w, int h,
  52686. const Colour& preferredBackgroundColour,
  52687. int /*tabIndex*/,
  52688. const String& text,
  52689. Button& button,
  52690. TabbedButtonBar::Orientation orientation,
  52691. const bool isMouseOver,
  52692. const bool isMouseDown,
  52693. const bool isFrontTab)
  52694. {
  52695. int length = w;
  52696. int depth = h;
  52697. if (orientation == TabbedButtonBar::TabsAtLeft
  52698. || orientation == TabbedButtonBar::TabsAtRight)
  52699. {
  52700. swapVariables (length, depth);
  52701. }
  52702. Font font (depth * 0.6f);
  52703. font.setUnderline (button.hasKeyboardFocus (false));
  52704. GlyphArrangement textLayout;
  52705. textLayout.addFittedText (font, text.trim(),
  52706. 0.0f, 0.0f, (float) length, (float) depth,
  52707. Justification::centred,
  52708. jmax (1, depth / 12));
  52709. AffineTransform transform;
  52710. if (orientation == TabbedButtonBar::TabsAtLeft)
  52711. {
  52712. transform = transform.rotated (float_Pi * -0.5f)
  52713. .translated ((float) x, (float) (y + h));
  52714. }
  52715. else if (orientation == TabbedButtonBar::TabsAtRight)
  52716. {
  52717. transform = transform.rotated (float_Pi * 0.5f)
  52718. .translated ((float) (x + w), (float) y);
  52719. }
  52720. else
  52721. {
  52722. transform = transform.translated ((float) x, (float) y);
  52723. }
  52724. if (isFrontTab && (button.isColourSpecified (TabbedButtonBar::frontTextColourId) || isColourSpecified (TabbedButtonBar::frontTextColourId)))
  52725. g.setColour (findColour (TabbedButtonBar::frontTextColourId));
  52726. else if (button.isColourSpecified (TabbedButtonBar::tabTextColourId) || isColourSpecified (TabbedButtonBar::tabTextColourId))
  52727. g.setColour (findColour (TabbedButtonBar::tabTextColourId));
  52728. else
  52729. g.setColour (preferredBackgroundColour.contrasting());
  52730. if (! (isMouseOver || isMouseDown))
  52731. g.setOpacity (0.8f);
  52732. if (! button.isEnabled())
  52733. g.setOpacity (0.3f);
  52734. textLayout.draw (g, transform);
  52735. }
  52736. int LookAndFeel::getTabButtonBestWidth (int /*tabIndex*/,
  52737. const String& text,
  52738. int tabDepth,
  52739. Button&)
  52740. {
  52741. Font f (tabDepth * 0.6f);
  52742. return f.getStringWidth (text.trim()) + getTabButtonOverlap (tabDepth) * 2;
  52743. }
  52744. void LookAndFeel::drawTabButton (Graphics& g,
  52745. int w, int h,
  52746. const Colour& preferredColour,
  52747. int tabIndex,
  52748. const String& text,
  52749. Button& button,
  52750. TabbedButtonBar::Orientation orientation,
  52751. const bool isMouseOver,
  52752. const bool isMouseDown,
  52753. const bool isFrontTab)
  52754. {
  52755. int length = w;
  52756. int depth = h;
  52757. if (orientation == TabbedButtonBar::TabsAtLeft
  52758. || orientation == TabbedButtonBar::TabsAtRight)
  52759. {
  52760. swapVariables (length, depth);
  52761. }
  52762. Path tabShape;
  52763. createTabButtonShape (tabShape, w, h,
  52764. tabIndex, text, button, orientation,
  52765. isMouseOver, isMouseDown, isFrontTab);
  52766. fillTabButtonShape (g, tabShape, preferredColour,
  52767. tabIndex, text, button, orientation,
  52768. isMouseOver, isMouseDown, isFrontTab);
  52769. const int indent = getTabButtonOverlap (depth);
  52770. int x = 0, y = 0;
  52771. if (orientation == TabbedButtonBar::TabsAtLeft
  52772. || orientation == TabbedButtonBar::TabsAtRight)
  52773. {
  52774. y += indent;
  52775. h -= indent * 2;
  52776. }
  52777. else
  52778. {
  52779. x += indent;
  52780. w -= indent * 2;
  52781. }
  52782. drawTabButtonText (g, x, y, w, h, preferredColour,
  52783. tabIndex, text, button, orientation,
  52784. isMouseOver, isMouseDown, isFrontTab);
  52785. }
  52786. void LookAndFeel::drawTabAreaBehindFrontButton (Graphics& g,
  52787. int w, int h,
  52788. TabbedButtonBar& tabBar,
  52789. TabbedButtonBar::Orientation orientation)
  52790. {
  52791. const float shadowSize = 0.2f;
  52792. float x1 = 0.0f, y1 = 0.0f, x2 = 0.0f, y2 = 0.0f;
  52793. Rectangle<int> shadowRect;
  52794. if (orientation == TabbedButtonBar::TabsAtLeft)
  52795. {
  52796. x1 = (float) w;
  52797. x2 = w * (1.0f - shadowSize);
  52798. shadowRect.setBounds ((int) x2, 0, w - (int) x2, h);
  52799. }
  52800. else if (orientation == TabbedButtonBar::TabsAtRight)
  52801. {
  52802. x2 = w * shadowSize;
  52803. shadowRect.setBounds (0, 0, (int) x2, h);
  52804. }
  52805. else if (orientation == TabbedButtonBar::TabsAtBottom)
  52806. {
  52807. y2 = h * shadowSize;
  52808. shadowRect.setBounds (0, 0, w, (int) y2);
  52809. }
  52810. else
  52811. {
  52812. y1 = (float) h;
  52813. y2 = h * (1.0f - shadowSize);
  52814. shadowRect.setBounds (0, (int) y2, w, h - (int) y2);
  52815. }
  52816. g.setGradientFill (ColourGradient (Colours::black.withAlpha (tabBar.isEnabled() ? 0.3f : 0.15f), x1, y1,
  52817. Colours::transparentBlack, x2, y2, false));
  52818. shadowRect.expand (2, 2);
  52819. g.fillRect (shadowRect);
  52820. g.setColour (Colour (0x80000000));
  52821. if (orientation == TabbedButtonBar::TabsAtLeft)
  52822. {
  52823. g.fillRect (w - 1, 0, 1, h);
  52824. }
  52825. else if (orientation == TabbedButtonBar::TabsAtRight)
  52826. {
  52827. g.fillRect (0, 0, 1, h);
  52828. }
  52829. else if (orientation == TabbedButtonBar::TabsAtBottom)
  52830. {
  52831. g.fillRect (0, 0, w, 1);
  52832. }
  52833. else
  52834. {
  52835. g.fillRect (0, h - 1, w, 1);
  52836. }
  52837. }
  52838. Button* LookAndFeel::createTabBarExtrasButton()
  52839. {
  52840. const float thickness = 7.0f;
  52841. const float indent = 22.0f;
  52842. Path p;
  52843. p.addEllipse (-10.0f, -10.0f, 120.0f, 120.0f);
  52844. DrawablePath ellipse;
  52845. ellipse.setPath (p);
  52846. ellipse.setFill (Colour (0x99ffffff));
  52847. p.clear();
  52848. p.addEllipse (0.0f, 0.0f, 100.0f, 100.0f);
  52849. p.addRectangle (indent, 50.0f - thickness, 100.0f - indent * 2.0f, thickness * 2.0f);
  52850. p.addRectangle (50.0f - thickness, indent, thickness * 2.0f, 50.0f - indent - thickness);
  52851. p.addRectangle (50.0f - thickness, 50.0f + thickness, thickness * 2.0f, 50.0f - indent - thickness);
  52852. p.setUsingNonZeroWinding (false);
  52853. DrawablePath dp;
  52854. dp.setPath (p);
  52855. dp.setFill (Colour (0x59000000));
  52856. DrawableComposite normalImage;
  52857. normalImage.insertDrawable (ellipse);
  52858. normalImage.insertDrawable (dp);
  52859. dp.setFill (Colour (0xcc000000));
  52860. DrawableComposite overImage;
  52861. overImage.insertDrawable (ellipse);
  52862. overImage.insertDrawable (dp);
  52863. DrawableButton* db = new DrawableButton (T("tabs"), DrawableButton::ImageFitted);
  52864. db->setImages (&normalImage, &overImage, 0);
  52865. return db;
  52866. }
  52867. void LookAndFeel::drawTableHeaderBackground (Graphics& g, TableHeaderComponent& header)
  52868. {
  52869. g.fillAll (Colours::white);
  52870. const int w = header.getWidth();
  52871. const int h = header.getHeight();
  52872. g.setGradientFill (ColourGradient (Colour (0xffe8ebf9), 0.0f, h * 0.5f,
  52873. Colour (0xfff6f8f9), 0.0f, h - 1.0f,
  52874. false));
  52875. g.fillRect (0, h / 2, w, h);
  52876. g.setColour (Colour (0x33000000));
  52877. g.fillRect (0, h - 1, w, 1);
  52878. for (int i = header.getNumColumns (true); --i >= 0;)
  52879. g.fillRect (header.getColumnPosition (i).getRight() - 1, 0, 1, h - 1);
  52880. }
  52881. void LookAndFeel::drawTableHeaderColumn (Graphics& g, const String& columnName, int /*columnId*/,
  52882. int width, int height,
  52883. bool isMouseOver, bool isMouseDown,
  52884. int columnFlags)
  52885. {
  52886. if (isMouseDown)
  52887. g.fillAll (Colour (0x8899aadd));
  52888. else if (isMouseOver)
  52889. g.fillAll (Colour (0x5599aadd));
  52890. int rightOfText = width - 4;
  52891. if ((columnFlags & (TableHeaderComponent::sortedForwards | TableHeaderComponent::sortedBackwards)) != 0)
  52892. {
  52893. const float top = height * ((columnFlags & TableHeaderComponent::sortedForwards) != 0 ? 0.35f : (1.0f - 0.35f));
  52894. const float bottom = height - top;
  52895. const float w = height * 0.5f;
  52896. const float x = rightOfText - (w * 1.25f);
  52897. rightOfText = (int) x;
  52898. Path sortArrow;
  52899. sortArrow.addTriangle (x, bottom, x + w * 0.5f, top, x + w, bottom);
  52900. g.setColour (Colour (0x99000000));
  52901. g.fillPath (sortArrow);
  52902. }
  52903. g.setColour (Colours::black);
  52904. g.setFont (height * 0.5f, Font::bold);
  52905. const int textX = 4;
  52906. g.drawFittedText (columnName, textX, 0, rightOfText - textX, height, Justification::centredLeft, 1);
  52907. }
  52908. void LookAndFeel::paintToolbarBackground (Graphics& g, int w, int h, Toolbar& toolbar)
  52909. {
  52910. const Colour background (toolbar.findColour (Toolbar::backgroundColourId));
  52911. g.setGradientFill (ColourGradient (background, 0.0f, 0.0f,
  52912. background.darker (0.1f),
  52913. toolbar.isVertical() ? w - 1.0f : 0.0f,
  52914. toolbar.isVertical() ? 0.0f : h - 1.0f,
  52915. false));
  52916. g.fillAll();
  52917. }
  52918. Button* LookAndFeel::createToolbarMissingItemsButton (Toolbar& /*toolbar*/)
  52919. {
  52920. return createTabBarExtrasButton();
  52921. }
  52922. void LookAndFeel::paintToolbarButtonBackground (Graphics& g, int /*width*/, int /*height*/,
  52923. bool isMouseOver, bool isMouseDown,
  52924. ToolbarItemComponent& component)
  52925. {
  52926. if (isMouseDown)
  52927. g.fillAll (component.findColour (Toolbar::buttonMouseDownBackgroundColourId, true));
  52928. else if (isMouseOver)
  52929. g.fillAll (component.findColour (Toolbar::buttonMouseOverBackgroundColourId, true));
  52930. }
  52931. void LookAndFeel::paintToolbarButtonLabel (Graphics& g, int x, int y, int width, int height,
  52932. const String& text, ToolbarItemComponent& component)
  52933. {
  52934. g.setColour (component.findColour (Toolbar::labelTextColourId, true)
  52935. .withAlpha (component.isEnabled() ? 1.0f : 0.25f));
  52936. const float fontHeight = jmin (14.0f, height * 0.85f);
  52937. g.setFont (fontHeight);
  52938. g.drawFittedText (text,
  52939. x, y, width, height,
  52940. Justification::centred,
  52941. jmax (1, height / (int) fontHeight));
  52942. }
  52943. void LookAndFeel::drawPropertyPanelSectionHeader (Graphics& g, const String& name,
  52944. bool isOpen, int width, int height)
  52945. {
  52946. const int buttonSize = (height * 3) / 4;
  52947. const int buttonIndent = (height - buttonSize) / 2;
  52948. drawTreeviewPlusMinusBox (g, buttonIndent, buttonIndent, buttonSize, buttonSize, ! isOpen, false);
  52949. const int textX = buttonIndent * 2 + buttonSize + 2;
  52950. g.setColour (Colours::black);
  52951. g.setFont (height * 0.7f, Font::bold);
  52952. g.drawText (name, textX, 0, width - textX - 4, height, Justification::centredLeft, true);
  52953. }
  52954. void LookAndFeel::drawPropertyComponentBackground (Graphics& g, int width, int height,
  52955. PropertyComponent&)
  52956. {
  52957. g.setColour (Colour (0x66ffffff));
  52958. g.fillRect (0, 0, width, height - 1);
  52959. }
  52960. void LookAndFeel::drawPropertyComponentLabel (Graphics& g, int, int height,
  52961. PropertyComponent& component)
  52962. {
  52963. g.setColour (Colours::black);
  52964. if (! component.isEnabled())
  52965. g.setOpacity (0.6f);
  52966. g.setFont (jmin (height, 24) * 0.65f);
  52967. const Rectangle<int> r (getPropertyComponentContentPosition (component));
  52968. g.drawFittedText (component.getName(),
  52969. 3, r.getY(), r.getX() - 5, r.getHeight(),
  52970. Justification::centredLeft, 2);
  52971. }
  52972. const Rectangle<int> LookAndFeel::getPropertyComponentContentPosition (PropertyComponent& component)
  52973. {
  52974. return Rectangle<int> (component.getWidth() / 3, 1,
  52975. component.getWidth() - component.getWidth() / 3 - 1, component.getHeight() - 3);
  52976. }
  52977. void LookAndFeel::createFileChooserHeaderText (const String& title,
  52978. const String& instructions,
  52979. GlyphArrangement& text,
  52980. int width)
  52981. {
  52982. text.clear();
  52983. text.addJustifiedText (Font (17.0f, Font::bold), title,
  52984. 8.0f, 22.0f, width - 16.0f,
  52985. Justification::centred);
  52986. text.addJustifiedText (Font (14.0f), instructions,
  52987. 8.0f, 24.0f + 16.0f, width - 16.0f,
  52988. Justification::centred);
  52989. }
  52990. void LookAndFeel::drawFileBrowserRow (Graphics& g, int width, int height,
  52991. const String& filename, Image* icon,
  52992. const String& fileSizeDescription,
  52993. const String& fileTimeDescription,
  52994. const bool isDirectory,
  52995. const bool isItemSelected,
  52996. const int /*itemIndex*/)
  52997. {
  52998. if (isItemSelected)
  52999. g.fillAll (findColour (DirectoryContentsDisplayComponent::highlightColourId));
  53000. g.setColour (findColour (DirectoryContentsDisplayComponent::textColourId));
  53001. g.setFont (height * 0.7f);
  53002. Image* im = icon;
  53003. Image* toRelease = 0;
  53004. if (im == 0)
  53005. {
  53006. toRelease = im = (isDirectory ? getDefaultFolderImage()
  53007. : getDefaultDocumentFileImage());
  53008. }
  53009. const int x = 32;
  53010. if (im != 0)
  53011. {
  53012. g.drawImageWithin (im, 2, 2, x - 4, height - 4,
  53013. RectanglePlacement::centred | RectanglePlacement::onlyReduceInSize,
  53014. false);
  53015. ImageCache::release (toRelease);
  53016. }
  53017. if (width > 450 && ! isDirectory)
  53018. {
  53019. const int sizeX = roundToInt (width * 0.7f);
  53020. const int dateX = roundToInt (width * 0.8f);
  53021. g.drawFittedText (filename,
  53022. x, 0, sizeX - x, height,
  53023. Justification::centredLeft, 1);
  53024. g.setFont (height * 0.5f);
  53025. g.setColour (Colours::darkgrey);
  53026. if (! isDirectory)
  53027. {
  53028. g.drawFittedText (fileSizeDescription,
  53029. sizeX, 0, dateX - sizeX - 8, height,
  53030. Justification::centredRight, 1);
  53031. g.drawFittedText (fileTimeDescription,
  53032. dateX, 0, width - 8 - dateX, height,
  53033. Justification::centredRight, 1);
  53034. }
  53035. }
  53036. else
  53037. {
  53038. g.drawFittedText (filename,
  53039. x, 0, width - x, height,
  53040. Justification::centredLeft, 1);
  53041. }
  53042. }
  53043. Button* LookAndFeel::createFileBrowserGoUpButton()
  53044. {
  53045. DrawableButton* goUpButton = new DrawableButton ("up", DrawableButton::ImageOnButtonBackground);
  53046. Path arrowPath;
  53047. arrowPath.addArrow (50.0f, 100.0f, 50.0f, 0.0f, 40.0f, 100.0f, 50.0f);
  53048. DrawablePath arrowImage;
  53049. arrowImage.setFill (Colours::black.withAlpha (0.4f));
  53050. arrowImage.setPath (arrowPath);
  53051. goUpButton->setImages (&arrowImage);
  53052. return goUpButton;
  53053. }
  53054. void LookAndFeel::layoutFileBrowserComponent (FileBrowserComponent& browserComp,
  53055. DirectoryContentsDisplayComponent* fileListComponent,
  53056. FilePreviewComponent* previewComp,
  53057. ComboBox* currentPathBox,
  53058. TextEditor* filenameBox,
  53059. Button* goUpButton)
  53060. {
  53061. const int x = 8;
  53062. int w = browserComp.getWidth() - x - x;
  53063. if (previewComp != 0)
  53064. {
  53065. const int previewWidth = w / 3;
  53066. previewComp->setBounds (x + w - previewWidth, 0, previewWidth, browserComp.getHeight());
  53067. w -= previewWidth + 4;
  53068. }
  53069. int y = 4;
  53070. const int controlsHeight = 22;
  53071. const int bottomSectionHeight = controlsHeight + 8;
  53072. const int upButtonWidth = 50;
  53073. currentPathBox->setBounds (x, y, w - upButtonWidth - 6, controlsHeight);
  53074. goUpButton->setBounds (x + w - upButtonWidth, y, upButtonWidth, controlsHeight);
  53075. y += controlsHeight + 4;
  53076. Component* const listAsComp = dynamic_cast <Component*> (fileListComponent);
  53077. listAsComp->setBounds (x, y, w, browserComp.getHeight() - y - bottomSectionHeight);
  53078. y = listAsComp->getBottom() + 4;
  53079. filenameBox->setBounds (x + 50, y, w - 50, controlsHeight);
  53080. }
  53081. Image* LookAndFeel::getDefaultFolderImage()
  53082. {
  53083. 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,
  53084. 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,
  53085. 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,
  53086. 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,
  53087. 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,
  53088. 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,
  53089. 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,
  53090. 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,
  53091. 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,
  53092. 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,
  53093. 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,
  53094. 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,
  53095. 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,
  53096. 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,
  53097. 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,
  53098. 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,
  53099. 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,
  53100. 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,
  53101. 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,
  53102. 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,
  53103. 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,
  53104. 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,
  53105. 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,
  53106. 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,
  53107. 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,
  53108. 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,
  53109. 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,
  53110. 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,
  53111. 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,
  53112. 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,
  53113. 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,
  53114. 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,
  53115. 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,
  53116. 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,
  53117. 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,
  53118. 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,
  53119. 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,
  53120. 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,
  53121. 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,
  53122. 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,
  53123. 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,
  53124. 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,
  53125. 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,
  53126. 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};
  53127. return ImageCache::getFromMemory (foldericon_png, sizeof (foldericon_png));
  53128. }
  53129. Image* LookAndFeel::getDefaultDocumentFileImage()
  53130. {
  53131. 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,
  53132. 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,
  53133. 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,
  53134. 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,
  53135. 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,
  53136. 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,
  53137. 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,
  53138. 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,
  53139. 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,
  53140. 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,
  53141. 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,
  53142. 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,
  53143. 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,
  53144. 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,
  53145. 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,
  53146. 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,
  53147. 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,
  53148. 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,
  53149. 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,
  53150. 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,
  53151. 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,
  53152. 174,66,96,130,0,0};
  53153. return ImageCache::getFromMemory (fileicon_png, sizeof (fileicon_png));
  53154. }
  53155. void LookAndFeel::playAlertSound()
  53156. {
  53157. PlatformUtilities::beep();
  53158. }
  53159. void LookAndFeel::drawLevelMeter (Graphics& g, int width, int height, float level)
  53160. {
  53161. g.setColour (Colours::white.withAlpha (0.7f));
  53162. g.fillRoundedRectangle (0.0f, 0.0f, (float) width, (float) height, 3.0f);
  53163. g.setColour (Colours::black.withAlpha (0.2f));
  53164. g.drawRoundedRectangle (1.0f, 1.0f, width - 2.0f, height - 2.0f, 3.0f, 1.0f);
  53165. const int totalBlocks = 7;
  53166. const int numBlocks = roundToInt (totalBlocks * level);
  53167. const float w = (width - 6.0f) / (float) totalBlocks;
  53168. for (int i = 0; i < totalBlocks; ++i)
  53169. {
  53170. if (i >= numBlocks)
  53171. g.setColour (Colours::lightblue.withAlpha (0.6f));
  53172. else
  53173. g.setColour (i < totalBlocks - 1 ? Colours::blue.withAlpha (0.5f)
  53174. : Colours::red);
  53175. g.fillRoundedRectangle (3.0f + i * w + w * 0.1f, 3.0f, w * 0.8f, height - 6.0f, w * 0.4f);
  53176. }
  53177. }
  53178. void LookAndFeel::drawKeymapChangeButton (Graphics& g, int width, int height, Button& button, const String& keyDescription)
  53179. {
  53180. const Colour textColour (button.findColour (KeyMappingEditorComponent::textColourId, true));
  53181. if (keyDescription.isNotEmpty())
  53182. {
  53183. if (button.isEnabled())
  53184. {
  53185. const float alpha = button.isDown() ? 0.3f : (button.isOver() ? 0.15f : 0.08f);
  53186. g.fillAll (textColour.withAlpha (alpha));
  53187. g.setOpacity (0.3f);
  53188. g.drawBevel (0, 0, width, height, 2);
  53189. }
  53190. g.setColour (textColour);
  53191. g.setFont (height * 0.6f);
  53192. g.drawFittedText (keyDescription,
  53193. 3, 0, width - 6, height,
  53194. Justification::centred, 1);
  53195. }
  53196. else
  53197. {
  53198. const float thickness = 7.0f;
  53199. const float indent = 22.0f;
  53200. Path p;
  53201. p.addEllipse (0.0f, 0.0f, 100.0f, 100.0f);
  53202. p.addRectangle (indent, 50.0f - thickness, 100.0f - indent * 2.0f, thickness * 2.0f);
  53203. p.addRectangle (50.0f - thickness, indent, thickness * 2.0f, 50.0f - indent - thickness);
  53204. p.addRectangle (50.0f - thickness, 50.0f + thickness, thickness * 2.0f, 50.0f - indent - thickness);
  53205. p.setUsingNonZeroWinding (false);
  53206. g.setColour (textColour.withAlpha (button.isDown() ? 0.7f : (button.isOver() ? 0.5f : 0.3f)));
  53207. g.fillPath (p, p.getTransformToScaleToFit (2.0f, 2.0f, width - 4.0f, height - 4.0f, true));
  53208. }
  53209. if (button.hasKeyboardFocus (false))
  53210. {
  53211. g.setColour (textColour.withAlpha (0.4f));
  53212. g.drawRect (0, 0, width, height);
  53213. }
  53214. }
  53215. static void createRoundedPath (Path& p,
  53216. const float x, const float y,
  53217. const float w, const float h,
  53218. const float cs,
  53219. const bool curveTopLeft, const bool curveTopRight,
  53220. const bool curveBottomLeft, const bool curveBottomRight) throw()
  53221. {
  53222. const float cs2 = 2.0f * cs;
  53223. if (curveTopLeft)
  53224. {
  53225. p.startNewSubPath (x, y + cs);
  53226. p.addArc (x, y, cs2, cs2, float_Pi * 1.5f, float_Pi * 2.0f);
  53227. }
  53228. else
  53229. {
  53230. p.startNewSubPath (x, y);
  53231. }
  53232. if (curveTopRight)
  53233. {
  53234. p.lineTo (x + w - cs, y);
  53235. p.addArc (x + w - cs2, y, cs2, cs2, 0.0f, float_Pi * 0.5f);
  53236. }
  53237. else
  53238. {
  53239. p.lineTo (x + w, y);
  53240. }
  53241. if (curveBottomRight)
  53242. {
  53243. p.lineTo (x + w, y + h - cs);
  53244. p.addArc (x + w - cs2, y + h - cs2, cs2, cs2, float_Pi * 0.5f, float_Pi);
  53245. }
  53246. else
  53247. {
  53248. p.lineTo (x + w, y + h);
  53249. }
  53250. if (curveBottomLeft)
  53251. {
  53252. p.lineTo (x + cs, y + h);
  53253. p.addArc (x, y + h - cs2, cs2, cs2, float_Pi, float_Pi * 1.5f);
  53254. }
  53255. else
  53256. {
  53257. p.lineTo (x, y + h);
  53258. }
  53259. p.closeSubPath();
  53260. }
  53261. void LookAndFeel::drawShinyButtonShape (Graphics& g,
  53262. float x, float y, float w, float h,
  53263. float maxCornerSize,
  53264. const Colour& baseColour,
  53265. const float strokeWidth,
  53266. const bool flatOnLeft,
  53267. const bool flatOnRight,
  53268. const bool flatOnTop,
  53269. const bool flatOnBottom) throw()
  53270. {
  53271. if (w <= strokeWidth * 1.1f || h <= strokeWidth * 1.1f)
  53272. return;
  53273. const float cs = jmin (maxCornerSize, w * 0.5f, h * 0.5f);
  53274. Path outline;
  53275. createRoundedPath (outline, x, y, w, h, cs,
  53276. ! (flatOnLeft || flatOnTop),
  53277. ! (flatOnRight || flatOnTop),
  53278. ! (flatOnLeft || flatOnBottom),
  53279. ! (flatOnRight || flatOnBottom));
  53280. ColourGradient cg (baseColour, 0.0f, y,
  53281. baseColour.overlaidWith (Colour (0x070000ff)), 0.0f, y + h,
  53282. false);
  53283. cg.addColour (0.5, baseColour.overlaidWith (Colour (0x33ffffff)));
  53284. cg.addColour (0.51, baseColour.overlaidWith (Colour (0x110000ff)));
  53285. g.setGradientFill (cg);
  53286. g.fillPath (outline);
  53287. g.setColour (Colour (0x80000000));
  53288. g.strokePath (outline, PathStrokeType (strokeWidth));
  53289. }
  53290. void LookAndFeel::drawGlassSphere (Graphics& g,
  53291. const float x, const float y,
  53292. const float diameter,
  53293. const Colour& colour,
  53294. const float outlineThickness) throw()
  53295. {
  53296. if (diameter <= outlineThickness)
  53297. return;
  53298. Path p;
  53299. p.addEllipse (x, y, diameter, diameter);
  53300. {
  53301. ColourGradient cg (Colours::white.overlaidWith (colour.withMultipliedAlpha (0.3f)), 0, y,
  53302. Colours::white.overlaidWith (colour.withMultipliedAlpha (0.3f)), 0, y + diameter, false);
  53303. cg.addColour (0.4, Colours::white.overlaidWith (colour));
  53304. g.setGradientFill (cg);
  53305. g.fillPath (p);
  53306. }
  53307. g.setGradientFill (ColourGradient (Colours::white, 0, y + diameter * 0.06f,
  53308. Colours::transparentWhite, 0, y + diameter * 0.3f, false));
  53309. g.fillEllipse (x + diameter * 0.2f, y + diameter * 0.05f, diameter * 0.6f, diameter * 0.4f);
  53310. ColourGradient cg (Colours::transparentBlack,
  53311. x + diameter * 0.5f, y + diameter * 0.5f,
  53312. Colours::black.withAlpha (0.5f * outlineThickness * colour.getFloatAlpha()),
  53313. x, y + diameter * 0.5f, true);
  53314. cg.addColour (0.7, Colours::transparentBlack);
  53315. cg.addColour (0.8, Colours::black.withAlpha (0.1f * outlineThickness));
  53316. g.setGradientFill (cg);
  53317. g.fillPath (p);
  53318. g.setColour (Colours::black.withAlpha (0.5f * colour.getFloatAlpha()));
  53319. g.drawEllipse (x, y, diameter, diameter, outlineThickness);
  53320. }
  53321. void LookAndFeel::drawGlassPointer (Graphics& g,
  53322. const float x, const float y,
  53323. const float diameter,
  53324. const Colour& colour, const float outlineThickness,
  53325. const int direction) throw()
  53326. {
  53327. if (diameter <= outlineThickness)
  53328. return;
  53329. Path p;
  53330. p.startNewSubPath (x + diameter * 0.5f, y);
  53331. p.lineTo (x + diameter, y + diameter * 0.6f);
  53332. p.lineTo (x + diameter, y + diameter);
  53333. p.lineTo (x, y + diameter);
  53334. p.lineTo (x, y + diameter * 0.6f);
  53335. p.closeSubPath();
  53336. p.applyTransform (AffineTransform::rotation (direction * (float_Pi * 0.5f), x + diameter * 0.5f, y + diameter * 0.5f));
  53337. {
  53338. ColourGradient cg (Colours::white.overlaidWith (colour.withMultipliedAlpha (0.3f)), 0, y,
  53339. Colours::white.overlaidWith (colour.withMultipliedAlpha (0.3f)), 0, y + diameter, false);
  53340. cg.addColour (0.4, Colours::white.overlaidWith (colour));
  53341. g.setGradientFill (cg);
  53342. g.fillPath (p);
  53343. }
  53344. ColourGradient cg (Colours::transparentBlack,
  53345. x + diameter * 0.5f, y + diameter * 0.5f,
  53346. Colours::black.withAlpha (0.5f * outlineThickness * colour.getFloatAlpha()),
  53347. x - diameter * 0.2f, y + diameter * 0.5f, true);
  53348. cg.addColour (0.5, Colours::transparentBlack);
  53349. cg.addColour (0.7, Colours::black.withAlpha (0.07f * outlineThickness));
  53350. g.setGradientFill (cg);
  53351. g.fillPath (p);
  53352. g.setColour (Colours::black.withAlpha (0.5f * colour.getFloatAlpha()));
  53353. g.strokePath (p, PathStrokeType (outlineThickness));
  53354. }
  53355. void LookAndFeel::drawGlassLozenge (Graphics& g,
  53356. const float x, const float y,
  53357. const float width, const float height,
  53358. const Colour& colour,
  53359. const float outlineThickness,
  53360. const float cornerSize,
  53361. const bool flatOnLeft,
  53362. const bool flatOnRight,
  53363. const bool flatOnTop,
  53364. const bool flatOnBottom) throw()
  53365. {
  53366. if (width <= outlineThickness || height <= outlineThickness)
  53367. return;
  53368. const int intX = (int) x;
  53369. const int intY = (int) y;
  53370. const int intW = (int) width;
  53371. const int intH = (int) height;
  53372. const float cs = cornerSize < 0 ? jmin (width * 0.5f, height * 0.5f) : cornerSize;
  53373. const float edgeBlurRadius = height * 0.75f + (height - cs * 2.0f);
  53374. const int intEdge = (int) edgeBlurRadius;
  53375. Path outline;
  53376. createRoundedPath (outline, x, y, width, height, cs,
  53377. ! (flatOnLeft || flatOnTop),
  53378. ! (flatOnRight || flatOnTop),
  53379. ! (flatOnLeft || flatOnBottom),
  53380. ! (flatOnRight || flatOnBottom));
  53381. {
  53382. ColourGradient cg (colour.darker (0.2f), 0, y,
  53383. colour.darker (0.2f), 0, y + height, false);
  53384. cg.addColour (0.03, colour.withMultipliedAlpha (0.3f));
  53385. cg.addColour (0.4, colour);
  53386. cg.addColour (0.97, colour.withMultipliedAlpha (0.3f));
  53387. g.setGradientFill (cg);
  53388. g.fillPath (outline);
  53389. }
  53390. ColourGradient cg (Colours::transparentBlack, x + edgeBlurRadius, y + height * 0.5f,
  53391. colour.darker (0.2f), x, y + height * 0.5f, true);
  53392. cg.addColour (jlimit (0.0, 1.0, 1.0 - (cs * 0.5f) / edgeBlurRadius), Colours::transparentBlack);
  53393. cg.addColour (jlimit (0.0, 1.0, 1.0 - (cs * 0.25f) / edgeBlurRadius), colour.darker (0.2f).withMultipliedAlpha (0.3f));
  53394. if (! (flatOnLeft || flatOnTop || flatOnBottom))
  53395. {
  53396. g.saveState();
  53397. g.setGradientFill (cg);
  53398. g.reduceClipRegion (intX, intY, intEdge, intH);
  53399. g.fillPath (outline);
  53400. g.restoreState();
  53401. }
  53402. if (! (flatOnRight || flatOnTop || flatOnBottom))
  53403. {
  53404. cg.x1 = x + width - edgeBlurRadius;
  53405. cg.x2 = x + width;
  53406. g.saveState();
  53407. g.setGradientFill (cg);
  53408. g.reduceClipRegion (intX + intW - intEdge, intY, 2 + intEdge, intH);
  53409. g.fillPath (outline);
  53410. g.restoreState();
  53411. }
  53412. {
  53413. const float leftIndent = flatOnLeft ? 0.0f : cs * 0.4f;
  53414. const float rightIndent = flatOnRight ? 0.0f : cs * 0.4f;
  53415. Path highlight;
  53416. createRoundedPath (highlight,
  53417. x + leftIndent,
  53418. y + cs * 0.1f,
  53419. width - (leftIndent + rightIndent),
  53420. height * 0.4f, cs * 0.4f,
  53421. ! (flatOnLeft || flatOnTop),
  53422. ! (flatOnRight || flatOnTop),
  53423. ! (flatOnLeft || flatOnBottom),
  53424. ! (flatOnRight || flatOnBottom));
  53425. g.setGradientFill (ColourGradient (colour.brighter (10.0f), 0, y + height * 0.06f,
  53426. Colours::transparentWhite, 0, y + height * 0.4f, false));
  53427. g.fillPath (highlight);
  53428. }
  53429. g.setColour (colour.darker().withMultipliedAlpha (1.5f));
  53430. g.strokePath (outline, PathStrokeType (outlineThickness));
  53431. }
  53432. END_JUCE_NAMESPACE
  53433. /*** End of inlined file: juce_LookAndFeel.cpp ***/
  53434. /*** Start of inlined file: juce_OldSchoolLookAndFeel.cpp ***/
  53435. BEGIN_JUCE_NAMESPACE
  53436. OldSchoolLookAndFeel::OldSchoolLookAndFeel()
  53437. {
  53438. setColour (TextButton::buttonColourId, Colour (0xffbbbbff));
  53439. setColour (ListBox::outlineColourId, findColour (ComboBox::outlineColourId));
  53440. setColour (ScrollBar::thumbColourId, Colour (0xffbbbbdd));
  53441. setColour (ScrollBar::backgroundColourId, Colours::transparentBlack);
  53442. setColour (Slider::thumbColourId, Colours::white);
  53443. setColour (Slider::trackColourId, Colour (0x7f000000));
  53444. setColour (Slider::textBoxOutlineColourId, Colours::grey);
  53445. setColour (ProgressBar::backgroundColourId, Colours::white.withAlpha (0.6f));
  53446. setColour (ProgressBar::foregroundColourId, Colours::green.withAlpha (0.7f));
  53447. setColour (PopupMenu::backgroundColourId, Colour (0xffeef5f8));
  53448. setColour (PopupMenu::highlightedBackgroundColourId, Colour (0xbfa4c2ce));
  53449. setColour (PopupMenu::highlightedTextColourId, Colours::black);
  53450. setColour (TextEditor::focusedOutlineColourId, findColour (TextButton::buttonColourId));
  53451. scrollbarShadow.setShadowProperties (2.2f, 0.5f, 0, 0);
  53452. }
  53453. OldSchoolLookAndFeel::~OldSchoolLookAndFeel()
  53454. {
  53455. }
  53456. void OldSchoolLookAndFeel::drawButtonBackground (Graphics& g,
  53457. Button& button,
  53458. const Colour& backgroundColour,
  53459. bool isMouseOverButton,
  53460. bool isButtonDown)
  53461. {
  53462. const int width = button.getWidth();
  53463. const int height = button.getHeight();
  53464. const float indent = 2.0f;
  53465. const int cornerSize = jmin (roundToInt (width * 0.4f),
  53466. roundToInt (height * 0.4f));
  53467. Path p;
  53468. p.addRoundedRectangle (indent, indent,
  53469. width - indent * 2.0f,
  53470. height - indent * 2.0f,
  53471. (float) cornerSize);
  53472. Colour bc (backgroundColour.withMultipliedSaturation (0.3f));
  53473. if (isMouseOverButton)
  53474. {
  53475. if (isButtonDown)
  53476. bc = bc.brighter();
  53477. else if (bc.getBrightness() > 0.5f)
  53478. bc = bc.darker (0.1f);
  53479. else
  53480. bc = bc.brighter (0.1f);
  53481. }
  53482. g.setColour (bc);
  53483. g.fillPath (p);
  53484. g.setColour (bc.contrasting().withAlpha ((isMouseOverButton) ? 0.6f : 0.4f));
  53485. g.strokePath (p, PathStrokeType ((isMouseOverButton) ? 2.0f : 1.4f));
  53486. }
  53487. void OldSchoolLookAndFeel::drawTickBox (Graphics& g,
  53488. Component& /*component*/,
  53489. float x, float y, float w, float h,
  53490. const bool ticked,
  53491. const bool isEnabled,
  53492. const bool /*isMouseOverButton*/,
  53493. const bool isButtonDown)
  53494. {
  53495. Path box;
  53496. box.addRoundedRectangle (0.0f, 2.0f, 6.0f, 6.0f, 1.0f);
  53497. g.setColour (isEnabled ? Colours::blue.withAlpha (isButtonDown ? 0.3f : 0.1f)
  53498. : Colours::lightgrey.withAlpha (0.1f));
  53499. AffineTransform trans (AffineTransform::scale (w / 9.0f, h / 9.0f).translated (x, y));
  53500. g.fillPath (box, trans);
  53501. g.setColour (Colours::black.withAlpha (0.6f));
  53502. g.strokePath (box, PathStrokeType (0.9f), trans);
  53503. if (ticked)
  53504. {
  53505. Path tick;
  53506. tick.startNewSubPath (1.5f, 3.0f);
  53507. tick.lineTo (3.0f, 6.0f);
  53508. tick.lineTo (6.0f, 0.0f);
  53509. g.setColour (isEnabled ? Colours::black : Colours::grey);
  53510. g.strokePath (tick, PathStrokeType (2.5f), trans);
  53511. }
  53512. }
  53513. void OldSchoolLookAndFeel::drawToggleButton (Graphics& g,
  53514. ToggleButton& button,
  53515. bool isMouseOverButton,
  53516. bool isButtonDown)
  53517. {
  53518. if (button.hasKeyboardFocus (true))
  53519. {
  53520. g.setColour (button.findColour (TextEditor::focusedOutlineColourId));
  53521. g.drawRect (0, 0, button.getWidth(), button.getHeight());
  53522. }
  53523. const int tickWidth = jmin (20, button.getHeight() - 4);
  53524. drawTickBox (g, button, 4.0f, (button.getHeight() - tickWidth) * 0.5f,
  53525. (float) tickWidth, (float) tickWidth,
  53526. button.getToggleState(),
  53527. button.isEnabled(),
  53528. isMouseOverButton,
  53529. isButtonDown);
  53530. g.setColour (button.findColour (ToggleButton::textColourId));
  53531. g.setFont (jmin (15.0f, button.getHeight() * 0.6f));
  53532. if (! button.isEnabled())
  53533. g.setOpacity (0.5f);
  53534. const int textX = tickWidth + 5;
  53535. g.drawFittedText (button.getButtonText(),
  53536. textX, 4,
  53537. button.getWidth() - textX - 2, button.getHeight() - 8,
  53538. Justification::centredLeft, 10);
  53539. }
  53540. void OldSchoolLookAndFeel::drawProgressBar (Graphics& g, ProgressBar& progressBar,
  53541. int width, int height,
  53542. double progress, const String& textToShow)
  53543. {
  53544. if (progress < 0 || progress >= 1.0)
  53545. {
  53546. LookAndFeel::drawProgressBar (g, progressBar, width, height, progress, textToShow);
  53547. }
  53548. else
  53549. {
  53550. const Colour background (progressBar.findColour (ProgressBar::backgroundColourId));
  53551. const Colour foreground (progressBar.findColour (ProgressBar::foregroundColourId));
  53552. g.fillAll (background);
  53553. g.setColour (foreground);
  53554. g.fillRect (1, 1,
  53555. jlimit (0, width - 2, roundToInt (progress * (width - 2))),
  53556. height - 2);
  53557. if (textToShow.isNotEmpty())
  53558. {
  53559. g.setColour (Colour::contrasting (background, foreground));
  53560. g.setFont (height * 0.6f);
  53561. g.drawText (textToShow, 0, 0, width, height, Justification::centred, false);
  53562. }
  53563. }
  53564. }
  53565. void OldSchoolLookAndFeel::drawScrollbarButton (Graphics& g,
  53566. ScrollBar& bar,
  53567. int width, int height,
  53568. int buttonDirection,
  53569. bool isScrollbarVertical,
  53570. bool isMouseOverButton,
  53571. bool isButtonDown)
  53572. {
  53573. if (isScrollbarVertical)
  53574. width -= 2;
  53575. else
  53576. height -= 2;
  53577. Path p;
  53578. if (buttonDirection == 0)
  53579. p.addTriangle (width * 0.5f, height * 0.2f,
  53580. width * 0.1f, height * 0.7f,
  53581. width * 0.9f, height * 0.7f);
  53582. else if (buttonDirection == 1)
  53583. p.addTriangle (width * 0.8f, height * 0.5f,
  53584. width * 0.3f, height * 0.1f,
  53585. width * 0.3f, height * 0.9f);
  53586. else if (buttonDirection == 2)
  53587. p.addTriangle (width * 0.5f, height * 0.8f,
  53588. width * 0.1f, height * 0.3f,
  53589. width * 0.9f, height * 0.3f);
  53590. else if (buttonDirection == 3)
  53591. p.addTriangle (width * 0.2f, height * 0.5f,
  53592. width * 0.7f, height * 0.1f,
  53593. width * 0.7f, height * 0.9f);
  53594. if (isButtonDown)
  53595. g.setColour (Colours::white);
  53596. else if (isMouseOverButton)
  53597. g.setColour (Colours::white.withAlpha (0.7f));
  53598. else
  53599. g.setColour (bar.findColour (ScrollBar::thumbColourId).withAlpha (0.5f));
  53600. g.fillPath (p);
  53601. g.setColour (Colours::black.withAlpha (0.5f));
  53602. g.strokePath (p, PathStrokeType (0.5f));
  53603. }
  53604. void OldSchoolLookAndFeel::drawScrollbar (Graphics& g,
  53605. ScrollBar& bar,
  53606. int x, int y,
  53607. int width, int height,
  53608. bool isScrollbarVertical,
  53609. int thumbStartPosition,
  53610. int thumbSize,
  53611. bool isMouseOver,
  53612. bool isMouseDown)
  53613. {
  53614. g.fillAll (bar.findColour (ScrollBar::backgroundColourId));
  53615. g.setColour (bar.findColour (ScrollBar::thumbColourId)
  53616. .withAlpha ((isMouseOver || isMouseDown) ? 0.4f : 0.15f));
  53617. if (thumbSize > 0.0f)
  53618. {
  53619. Rectangle<int> thumb;
  53620. if (isScrollbarVertical)
  53621. {
  53622. width -= 2;
  53623. g.fillRect (x + roundToInt (width * 0.35f), y,
  53624. roundToInt (width * 0.3f), height);
  53625. thumb.setBounds (x + 1, thumbStartPosition,
  53626. width - 2, thumbSize);
  53627. }
  53628. else
  53629. {
  53630. height -= 2;
  53631. g.fillRect (x, y + roundToInt (height * 0.35f),
  53632. width, roundToInt (height * 0.3f));
  53633. thumb.setBounds (thumbStartPosition, y + 1,
  53634. thumbSize, height - 2);
  53635. }
  53636. g.setColour (bar.findColour (ScrollBar::thumbColourId)
  53637. .withAlpha ((isMouseOver || isMouseDown) ? 0.95f : 0.7f));
  53638. g.fillRect (thumb);
  53639. g.setColour (Colours::black.withAlpha ((isMouseOver || isMouseDown) ? 0.4f : 0.25f));
  53640. g.drawRect (thumb.getX(), thumb.getY(), thumb.getWidth(), thumb.getHeight());
  53641. if (thumbSize > 16)
  53642. {
  53643. for (int i = 3; --i >= 0;)
  53644. {
  53645. const float linePos = thumbStartPosition + thumbSize / 2 + (i - 1) * 4.0f;
  53646. g.setColour (Colours::black.withAlpha (0.15f));
  53647. if (isScrollbarVertical)
  53648. {
  53649. g.drawLine (x + width * 0.2f, linePos, width * 0.8f, linePos);
  53650. g.setColour (Colours::white.withAlpha (0.15f));
  53651. g.drawLine (width * 0.2f, linePos - 1, width * 0.8f, linePos - 1);
  53652. }
  53653. else
  53654. {
  53655. g.drawLine (linePos, height * 0.2f, linePos, height * 0.8f);
  53656. g.setColour (Colours::white.withAlpha (0.15f));
  53657. g.drawLine (linePos - 1, height * 0.2f, linePos - 1, height * 0.8f);
  53658. }
  53659. }
  53660. }
  53661. }
  53662. }
  53663. ImageEffectFilter* OldSchoolLookAndFeel::getScrollbarEffect()
  53664. {
  53665. return &scrollbarShadow;
  53666. }
  53667. void OldSchoolLookAndFeel::drawPopupMenuBackground (Graphics& g, int width, int height)
  53668. {
  53669. g.fillAll (findColour (PopupMenu::backgroundColourId));
  53670. g.setColour (Colours::black.withAlpha (0.6f));
  53671. g.drawRect (0, 0, width, height);
  53672. }
  53673. void OldSchoolLookAndFeel::drawMenuBarBackground (Graphics& g, int /*width*/, int /*height*/,
  53674. bool, MenuBarComponent& menuBar)
  53675. {
  53676. g.fillAll (menuBar.findColour (PopupMenu::backgroundColourId));
  53677. }
  53678. void OldSchoolLookAndFeel::drawTextEditorOutline (Graphics& g, int width, int height, TextEditor& textEditor)
  53679. {
  53680. if (textEditor.isEnabled())
  53681. {
  53682. g.setColour (textEditor.findColour (TextEditor::outlineColourId));
  53683. g.drawRect (0, 0, width, height);
  53684. }
  53685. }
  53686. void OldSchoolLookAndFeel::drawComboBox (Graphics& g, int width, int height,
  53687. const bool isButtonDown,
  53688. int buttonX, int buttonY,
  53689. int buttonW, int buttonH,
  53690. ComboBox& box)
  53691. {
  53692. g.fillAll (box.findColour (ComboBox::backgroundColourId));
  53693. g.setColour (box.findColour ((isButtonDown) ? ComboBox::buttonColourId
  53694. : ComboBox::backgroundColourId));
  53695. g.fillRect (buttonX, buttonY, buttonW, buttonH);
  53696. g.setColour (box.findColour (ComboBox::outlineColourId));
  53697. g.drawRect (0, 0, width, height);
  53698. const float arrowX = 0.2f;
  53699. const float arrowH = 0.3f;
  53700. if (box.isEnabled())
  53701. {
  53702. Path p;
  53703. p.addTriangle (buttonX + buttonW * 0.5f, buttonY + buttonH * (0.45f - arrowH),
  53704. buttonX + buttonW * (1.0f - arrowX), buttonY + buttonH * 0.45f,
  53705. buttonX + buttonW * arrowX, buttonY + buttonH * 0.45f);
  53706. p.addTriangle (buttonX + buttonW * 0.5f, buttonY + buttonH * (0.55f + arrowH),
  53707. buttonX + buttonW * (1.0f - arrowX), buttonY + buttonH * 0.55f,
  53708. buttonX + buttonW * arrowX, buttonY + buttonH * 0.55f);
  53709. g.setColour (box.findColour ((isButtonDown) ? ComboBox::backgroundColourId
  53710. : ComboBox::buttonColourId));
  53711. g.fillPath (p);
  53712. }
  53713. }
  53714. const Font OldSchoolLookAndFeel::getComboBoxFont (ComboBox& box)
  53715. {
  53716. Font f (jmin (15.0f, box.getHeight() * 0.85f));
  53717. f.setHorizontalScale (0.9f);
  53718. return f;
  53719. }
  53720. static void drawTriangle (Graphics& g, float x1, float y1, float x2, float y2, float x3, float y3, const Colour& fill, const Colour& outline) throw()
  53721. {
  53722. Path p;
  53723. p.addTriangle (x1, y1, x2, y2, x3, y3);
  53724. g.setColour (fill);
  53725. g.fillPath (p);
  53726. g.setColour (outline);
  53727. g.strokePath (p, PathStrokeType (0.3f));
  53728. }
  53729. void OldSchoolLookAndFeel::drawLinearSlider (Graphics& g,
  53730. int x, int y,
  53731. int w, int h,
  53732. float sliderPos,
  53733. float minSliderPos,
  53734. float maxSliderPos,
  53735. const Slider::SliderStyle style,
  53736. Slider& slider)
  53737. {
  53738. g.fillAll (slider.findColour (Slider::backgroundColourId));
  53739. if (style == Slider::LinearBar)
  53740. {
  53741. g.setColour (slider.findColour (Slider::thumbColourId));
  53742. g.fillRect (x, y, (int) sliderPos - x, h);
  53743. g.setColour (slider.findColour (Slider::textBoxTextColourId).withMultipliedAlpha (0.5f));
  53744. g.drawRect (x, y, (int) sliderPos - x, h);
  53745. }
  53746. else
  53747. {
  53748. g.setColour (slider.findColour (Slider::trackColourId)
  53749. .withMultipliedAlpha (slider.isEnabled() ? 1.0f : 0.3f));
  53750. if (slider.isHorizontal())
  53751. {
  53752. g.fillRect (x, y + roundToInt (h * 0.6f),
  53753. w, roundToInt (h * 0.2f));
  53754. }
  53755. else
  53756. {
  53757. g.fillRect (x + roundToInt (w * 0.5f - jmin (3.0f, w * 0.1f)), y,
  53758. jmin (4, roundToInt (w * 0.2f)), h);
  53759. }
  53760. float alpha = 0.35f;
  53761. if (slider.isEnabled())
  53762. alpha = slider.isMouseOverOrDragging() ? 1.0f : 0.7f;
  53763. const Colour fill (slider.findColour (Slider::thumbColourId).withAlpha (alpha));
  53764. const Colour outline (Colours::black.withAlpha (slider.isEnabled() ? 0.7f : 0.35f));
  53765. if (style == Slider::TwoValueVertical || style == Slider::ThreeValueVertical)
  53766. {
  53767. drawTriangle (g, x + w * 0.5f + jmin (4.0f, w * 0.3f), minSliderPos,
  53768. x + w * 0.5f - jmin (8.0f, w * 0.4f), minSliderPos - 7.0f,
  53769. x + w * 0.5f - jmin (8.0f, w * 0.4f), minSliderPos,
  53770. fill, outline);
  53771. drawTriangle (g, x + w * 0.5f + jmin (4.0f, w * 0.3f), maxSliderPos,
  53772. x + w * 0.5f - jmin (8.0f, w * 0.4f), maxSliderPos,
  53773. x + w * 0.5f - jmin (8.0f, w * 0.4f), maxSliderPos + 7.0f,
  53774. fill, outline);
  53775. }
  53776. else if (style == Slider::TwoValueHorizontal || style == Slider::ThreeValueHorizontal)
  53777. {
  53778. drawTriangle (g, minSliderPos, y + h * 0.6f - jmin (4.0f, h * 0.3f),
  53779. minSliderPos - 7.0f, y + h * 0.9f ,
  53780. minSliderPos, y + h * 0.9f,
  53781. fill, outline);
  53782. drawTriangle (g, maxSliderPos, y + h * 0.6f - jmin (4.0f, h * 0.3f),
  53783. maxSliderPos, y + h * 0.9f,
  53784. maxSliderPos + 7.0f, y + h * 0.9f,
  53785. fill, outline);
  53786. }
  53787. if (style == Slider::LinearHorizontal || style == Slider::ThreeValueHorizontal)
  53788. {
  53789. drawTriangle (g, sliderPos, y + h * 0.9f,
  53790. sliderPos - 7.0f, y + h * 0.2f,
  53791. sliderPos + 7.0f, y + h * 0.2f,
  53792. fill, outline);
  53793. }
  53794. else if (style == Slider::LinearVertical || style == Slider::ThreeValueVertical)
  53795. {
  53796. drawTriangle (g, x + w * 0.5f - jmin (4.0f, w * 0.3f), sliderPos,
  53797. x + w * 0.5f + jmin (8.0f, w * 0.4f), sliderPos - 7.0f,
  53798. x + w * 0.5f + jmin (8.0f, w * 0.4f), sliderPos + 7.0f,
  53799. fill, outline);
  53800. }
  53801. }
  53802. }
  53803. Button* OldSchoolLookAndFeel::createSliderButton (const bool isIncrement)
  53804. {
  53805. if (isIncrement)
  53806. return new ArrowButton ("u", 0.75f, Colours::white.withAlpha (0.8f));
  53807. else
  53808. return new ArrowButton ("d", 0.25f, Colours::white.withAlpha (0.8f));
  53809. }
  53810. ImageEffectFilter* OldSchoolLookAndFeel::getSliderEffect()
  53811. {
  53812. return &scrollbarShadow;
  53813. }
  53814. int OldSchoolLookAndFeel::getSliderThumbRadius (Slider&)
  53815. {
  53816. return 8;
  53817. }
  53818. void OldSchoolLookAndFeel::drawCornerResizer (Graphics& g,
  53819. int w, int h,
  53820. bool isMouseOver,
  53821. bool isMouseDragging)
  53822. {
  53823. g.setColour ((isMouseOver || isMouseDragging) ? Colours::lightgrey
  53824. : Colours::darkgrey);
  53825. const float lineThickness = jmin (w, h) * 0.1f;
  53826. for (float i = 0.0f; i < 1.0f; i += 0.3f)
  53827. {
  53828. g.drawLine (w * i,
  53829. h + 1.0f,
  53830. w + 1.0f,
  53831. h * i,
  53832. lineThickness);
  53833. }
  53834. }
  53835. Button* OldSchoolLookAndFeel::createDocumentWindowButton (int buttonType)
  53836. {
  53837. Path shape;
  53838. if (buttonType == DocumentWindow::closeButton)
  53839. {
  53840. shape.addLineSegment (0.0f, 0.0f, 1.0f, 1.0f, 0.35f);
  53841. shape.addLineSegment (1.0f, 0.0f, 0.0f, 1.0f, 0.35f);
  53842. ShapeButton* const b = new ShapeButton ("close",
  53843. Colour (0x7fff3333),
  53844. Colour (0xd7ff3333),
  53845. Colour (0xf7ff3333));
  53846. b->setShape (shape, true, true, true);
  53847. return b;
  53848. }
  53849. else if (buttonType == DocumentWindow::minimiseButton)
  53850. {
  53851. shape.addLineSegment (0.0f, 0.5f, 1.0f, 0.5f, 0.25f);
  53852. DrawableButton* b = new DrawableButton ("minimise", DrawableButton::ImageFitted);
  53853. DrawablePath dp;
  53854. dp.setPath (shape);
  53855. dp.setFill (Colours::black.withAlpha (0.3f));
  53856. b->setImages (&dp);
  53857. return b;
  53858. }
  53859. else if (buttonType == DocumentWindow::maximiseButton)
  53860. {
  53861. shape.addLineSegment (0.5f, 0.0f, 0.5f, 1.0f, 0.25f);
  53862. shape.addLineSegment (0.0f, 0.5f, 1.0f, 0.5f, 0.25f);
  53863. DrawableButton* b = new DrawableButton ("maximise", DrawableButton::ImageFitted);
  53864. DrawablePath dp;
  53865. dp.setPath (shape);
  53866. dp.setFill (Colours::black.withAlpha (0.3f));
  53867. b->setImages (&dp);
  53868. return b;
  53869. }
  53870. jassertfalse
  53871. return 0;
  53872. }
  53873. void OldSchoolLookAndFeel::positionDocumentWindowButtons (DocumentWindow&,
  53874. int titleBarX,
  53875. int titleBarY,
  53876. int titleBarW,
  53877. int titleBarH,
  53878. Button* minimiseButton,
  53879. Button* maximiseButton,
  53880. Button* closeButton,
  53881. bool positionTitleBarButtonsOnLeft)
  53882. {
  53883. titleBarY += titleBarH / 8;
  53884. titleBarH -= titleBarH / 4;
  53885. const int buttonW = titleBarH;
  53886. int x = positionTitleBarButtonsOnLeft ? titleBarX + 4
  53887. : titleBarX + titleBarW - buttonW - 4;
  53888. if (closeButton != 0)
  53889. {
  53890. closeButton->setBounds (x, titleBarY, buttonW, titleBarH);
  53891. x += positionTitleBarButtonsOnLeft ? buttonW + buttonW / 5
  53892. : -(buttonW + buttonW / 5);
  53893. }
  53894. if (positionTitleBarButtonsOnLeft)
  53895. swapVariables (minimiseButton, maximiseButton);
  53896. if (maximiseButton != 0)
  53897. {
  53898. maximiseButton->setBounds (x, titleBarY - 2, buttonW, titleBarH);
  53899. x += positionTitleBarButtonsOnLeft ? buttonW : -buttonW;
  53900. }
  53901. if (minimiseButton != 0)
  53902. minimiseButton->setBounds (x, titleBarY - 2, buttonW, titleBarH);
  53903. }
  53904. END_JUCE_NAMESPACE
  53905. /*** End of inlined file: juce_OldSchoolLookAndFeel.cpp ***/
  53906. /*** Start of inlined file: juce_MenuBarComponent.cpp ***/
  53907. BEGIN_JUCE_NAMESPACE
  53908. class DummyMenuComponent : public Component
  53909. {
  53910. DummyMenuComponent (const DummyMenuComponent&);
  53911. DummyMenuComponent& operator= (const DummyMenuComponent&);
  53912. public:
  53913. DummyMenuComponent() {}
  53914. ~DummyMenuComponent() {}
  53915. void inputAttemptWhenModal()
  53916. {
  53917. exitModalState (0);
  53918. }
  53919. };
  53920. MenuBarComponent::MenuBarComponent (MenuBarModel* model_)
  53921. : model (0),
  53922. itemUnderMouse (-1),
  53923. currentPopupIndex (-1),
  53924. indexToShowAgain (-1),
  53925. lastMouseX (0),
  53926. lastMouseY (0),
  53927. inModalState (false)
  53928. {
  53929. setRepaintsOnMouseActivity (true);
  53930. setWantsKeyboardFocus (false);
  53931. setMouseClickGrabsKeyboardFocus (false);
  53932. setModel (model_);
  53933. }
  53934. MenuBarComponent::~MenuBarComponent()
  53935. {
  53936. setModel (0);
  53937. Desktop::getInstance().removeGlobalMouseListener (this);
  53938. currentPopup = 0;
  53939. }
  53940. void MenuBarComponent::setModel (MenuBarModel* const newModel)
  53941. {
  53942. if (model != newModel)
  53943. {
  53944. if (model != 0)
  53945. model->removeListener (this);
  53946. model = newModel;
  53947. if (model != 0)
  53948. model->addListener (this);
  53949. repaint();
  53950. menuBarItemsChanged (0);
  53951. }
  53952. }
  53953. void MenuBarComponent::paint (Graphics& g)
  53954. {
  53955. const bool isMouseOverBar = currentPopupIndex >= 0 || itemUnderMouse >= 0 || isMouseOver();
  53956. getLookAndFeel().drawMenuBarBackground (g,
  53957. getWidth(),
  53958. getHeight(),
  53959. isMouseOverBar,
  53960. *this);
  53961. if (model != 0)
  53962. {
  53963. for (int i = 0; i < menuNames.size(); ++i)
  53964. {
  53965. g.saveState();
  53966. g.setOrigin (xPositions [i], 0);
  53967. g.reduceClipRegion (0, 0, xPositions[i + 1] - xPositions[i], getHeight());
  53968. getLookAndFeel().drawMenuBarItem (g,
  53969. xPositions[i + 1] - xPositions[i],
  53970. getHeight(),
  53971. i,
  53972. menuNames[i],
  53973. i == itemUnderMouse,
  53974. i == currentPopupIndex,
  53975. isMouseOverBar,
  53976. *this);
  53977. g.restoreState();
  53978. }
  53979. }
  53980. }
  53981. void MenuBarComponent::resized()
  53982. {
  53983. xPositions.clear();
  53984. int x = 2;
  53985. xPositions.add (x);
  53986. for (int i = 0; i < menuNames.size(); ++i)
  53987. {
  53988. x += getLookAndFeel().getMenuBarItemWidth (*this, i, menuNames[i]);
  53989. xPositions.add (x);
  53990. }
  53991. }
  53992. int MenuBarComponent::getItemAt (const int x, const int y)
  53993. {
  53994. for (int i = 0; i < xPositions.size(); ++i)
  53995. if (x >= xPositions[i] && x < xPositions[i + 1])
  53996. return reallyContains (x, y, true) ? i : -1;
  53997. return -1;
  53998. }
  53999. void MenuBarComponent::repaintMenuItem (int index)
  54000. {
  54001. if (((unsigned int) index) < (unsigned int) xPositions.size())
  54002. {
  54003. const int x1 = xPositions [index];
  54004. const int x2 = xPositions [index + 1];
  54005. repaint (x1 - 2, 0, x2 - x1 + 4, getHeight());
  54006. }
  54007. }
  54008. void MenuBarComponent::updateItemUnderMouse (int x, int y)
  54009. {
  54010. const int newItem = getItemAt (x, y);
  54011. if (itemUnderMouse != newItem)
  54012. {
  54013. repaintMenuItem (itemUnderMouse);
  54014. itemUnderMouse = newItem;
  54015. repaintMenuItem (itemUnderMouse);
  54016. }
  54017. }
  54018. void MenuBarComponent::hideCurrentMenu()
  54019. {
  54020. currentPopup = 0;
  54021. repaint();
  54022. }
  54023. void MenuBarComponent::showMenu (int index)
  54024. {
  54025. if (index != currentPopupIndex)
  54026. {
  54027. if (inModalState)
  54028. {
  54029. hideCurrentMenu();
  54030. indexToShowAgain = index;
  54031. return;
  54032. }
  54033. indexToShowAgain = -1;
  54034. currentPopupIndex = -1;
  54035. itemUnderMouse = index;
  54036. currentPopup = 0;
  54037. menuBarItemsChanged (0);
  54038. Component::SafePointer<Component> prevFocused (getCurrentlyFocusedComponent());
  54039. Component::SafePointer<Component> deletionChecker (this);
  54040. enterModalState (false);
  54041. inModalState = true;
  54042. int result = 0;
  54043. ApplicationCommandManager* managerOfChosenCommand = 0;
  54044. Desktop::getInstance().addGlobalMouseListener (this);
  54045. for (;;)
  54046. {
  54047. const int x = getScreenX() + xPositions [itemUnderMouse];
  54048. const int w = xPositions [itemUnderMouse + 1] - xPositions [itemUnderMouse];
  54049. currentPopupIndex = itemUnderMouse;
  54050. indexToShowAgain = -1;
  54051. repaint();
  54052. if (((unsigned int) itemUnderMouse) < (unsigned int) menuNames.size())
  54053. {
  54054. PopupMenu m (model->getMenuForIndex (itemUnderMouse,
  54055. menuNames [itemUnderMouse]));
  54056. if (m.lookAndFeel == 0)
  54057. m.setLookAndFeel (&getLookAndFeel());
  54058. currentPopup = m.createMenuComponent (x, getScreenY(),
  54059. w, getHeight(),
  54060. 0, w, 0, 0,
  54061. true, this,
  54062. &managerOfChosenCommand,
  54063. this);
  54064. }
  54065. if (currentPopup == 0)
  54066. {
  54067. currentPopup = new DummyMenuComponent();
  54068. addAndMakeVisible (currentPopup);
  54069. }
  54070. currentPopup->enterModalState (false);
  54071. currentPopup->toFront (false); // need to do this after making it modal, or it could
  54072. // be stuck behind other comps that are already modal..
  54073. result = currentPopup->runModalLoop();
  54074. if (deletionChecker == 0)
  54075. return;
  54076. const int lastPopupIndex = currentPopupIndex;
  54077. currentPopup = 0;
  54078. currentPopupIndex = -1;
  54079. if (result != 0)
  54080. {
  54081. topLevelIndexClicked = lastPopupIndex;
  54082. break;
  54083. }
  54084. else if (indexToShowAgain >= 0)
  54085. {
  54086. menuBarItemsChanged (0);
  54087. repaint();
  54088. itemUnderMouse = indexToShowAgain;
  54089. if (((unsigned int) itemUnderMouse) >= (unsigned int) menuNames.size())
  54090. break;
  54091. }
  54092. else
  54093. {
  54094. break;
  54095. }
  54096. }
  54097. Desktop::getInstance().removeGlobalMouseListener (this);
  54098. inModalState = false;
  54099. exitModalState (0);
  54100. if (prevFocused != 0)
  54101. prevFocused->grabKeyboardFocus();
  54102. const Point<int> mousePos (getMouseXYRelative());
  54103. updateItemUnderMouse (mousePos.getX(), mousePos.getY());
  54104. repaint();
  54105. if (result != 0)
  54106. {
  54107. if (managerOfChosenCommand != 0)
  54108. {
  54109. ApplicationCommandTarget::InvocationInfo info (result);
  54110. info.invocationMethod = ApplicationCommandTarget::InvocationInfo::fromMenu;
  54111. managerOfChosenCommand->invoke (info, true);
  54112. }
  54113. postCommandMessage (result);
  54114. }
  54115. }
  54116. }
  54117. void MenuBarComponent::handleCommandMessage (int commandId)
  54118. {
  54119. if (model != 0)
  54120. model->menuItemSelected (commandId, topLevelIndexClicked);
  54121. }
  54122. void MenuBarComponent::mouseEnter (const MouseEvent& e)
  54123. {
  54124. if (e.eventComponent == this)
  54125. updateItemUnderMouse (e.x, e.y);
  54126. }
  54127. void MenuBarComponent::mouseExit (const MouseEvent& e)
  54128. {
  54129. if (e.eventComponent == this)
  54130. updateItemUnderMouse (e.x, e.y);
  54131. }
  54132. void MenuBarComponent::mouseDown (const MouseEvent& e)
  54133. {
  54134. if (currentPopupIndex < 0)
  54135. {
  54136. const MouseEvent e2 (e.getEventRelativeTo (this));
  54137. updateItemUnderMouse (e2.x, e2.y);
  54138. currentPopupIndex = -2;
  54139. showMenu (itemUnderMouse);
  54140. }
  54141. }
  54142. void MenuBarComponent::mouseDrag (const MouseEvent& e)
  54143. {
  54144. const MouseEvent e2 (e.getEventRelativeTo (this));
  54145. const int item = getItemAt (e2.x, e2.y);
  54146. if (item >= 0)
  54147. showMenu (item);
  54148. }
  54149. void MenuBarComponent::mouseUp (const MouseEvent& e)
  54150. {
  54151. const MouseEvent e2 (e.getEventRelativeTo (this));
  54152. updateItemUnderMouse (e2.x, e2.y);
  54153. if (itemUnderMouse < 0 && dynamic_cast <DummyMenuComponent*> ((Component*) currentPopup) != 0)
  54154. hideCurrentMenu();
  54155. }
  54156. void MenuBarComponent::mouseMove (const MouseEvent& e)
  54157. {
  54158. const MouseEvent e2 (e.getEventRelativeTo (this));
  54159. if (lastMouseX != e2.x || lastMouseY != e2.y)
  54160. {
  54161. if (currentPopupIndex >= 0)
  54162. {
  54163. const int item = getItemAt (e2.x, e2.y);
  54164. if (item >= 0)
  54165. showMenu (item);
  54166. }
  54167. else
  54168. {
  54169. updateItemUnderMouse (e2.x, e2.y);
  54170. }
  54171. lastMouseX = e2.x;
  54172. lastMouseY = e2.y;
  54173. }
  54174. }
  54175. bool MenuBarComponent::keyPressed (const KeyPress& key)
  54176. {
  54177. bool used = false;
  54178. const int numMenus = menuNames.size();
  54179. const int currentIndex = jlimit (0, menuNames.size() - 1, currentPopupIndex);
  54180. if (key.isKeyCode (KeyPress::leftKey))
  54181. {
  54182. showMenu ((currentIndex + numMenus - 1) % numMenus);
  54183. used = true;
  54184. }
  54185. else if (key.isKeyCode (KeyPress::rightKey))
  54186. {
  54187. showMenu ((currentIndex + 1) % numMenus);
  54188. used = true;
  54189. }
  54190. return used;
  54191. }
  54192. void MenuBarComponent::inputAttemptWhenModal()
  54193. {
  54194. hideCurrentMenu();
  54195. }
  54196. void MenuBarComponent::menuBarItemsChanged (MenuBarModel* /*menuBarModel*/)
  54197. {
  54198. StringArray newNames;
  54199. if (model != 0)
  54200. newNames = model->getMenuBarNames();
  54201. if (newNames != menuNames)
  54202. {
  54203. menuNames = newNames;
  54204. repaint();
  54205. resized();
  54206. }
  54207. }
  54208. void MenuBarComponent::menuCommandInvoked (MenuBarModel* /*menuBarModel*/,
  54209. const ApplicationCommandTarget::InvocationInfo& info)
  54210. {
  54211. if (model == 0
  54212. || (info.commandFlags & ApplicationCommandInfo::dontTriggerVisualFeedback) != 0)
  54213. return;
  54214. for (int i = 0; i < menuNames.size(); ++i)
  54215. {
  54216. const PopupMenu menu (model->getMenuForIndex (i, menuNames [i]));
  54217. if (menu.containsCommandItem (info.commandID))
  54218. {
  54219. itemUnderMouse = i;
  54220. repaintMenuItem (i);
  54221. startTimer (200);
  54222. break;
  54223. }
  54224. }
  54225. }
  54226. void MenuBarComponent::timerCallback()
  54227. {
  54228. stopTimer();
  54229. const Point<int> mousePos (getMouseXYRelative());
  54230. updateItemUnderMouse (mousePos.getX(), mousePos.getY());
  54231. }
  54232. END_JUCE_NAMESPACE
  54233. /*** End of inlined file: juce_MenuBarComponent.cpp ***/
  54234. /*** Start of inlined file: juce_MenuBarModel.cpp ***/
  54235. BEGIN_JUCE_NAMESPACE
  54236. MenuBarModel::MenuBarModel() throw()
  54237. : manager (0)
  54238. {
  54239. }
  54240. MenuBarModel::~MenuBarModel()
  54241. {
  54242. setApplicationCommandManagerToWatch (0);
  54243. }
  54244. void MenuBarModel::menuItemsChanged()
  54245. {
  54246. triggerAsyncUpdate();
  54247. }
  54248. void MenuBarModel::setApplicationCommandManagerToWatch (ApplicationCommandManager* const newManager) throw()
  54249. {
  54250. if (manager != newManager)
  54251. {
  54252. if (manager != 0)
  54253. manager->removeListener (this);
  54254. manager = newManager;
  54255. if (manager != 0)
  54256. manager->addListener (this);
  54257. }
  54258. }
  54259. void MenuBarModel::addListener (MenuBarModelListener* const newListener) throw()
  54260. {
  54261. listeners.add (newListener);
  54262. }
  54263. void MenuBarModel::removeListener (MenuBarModelListener* const listenerToRemove) throw()
  54264. {
  54265. // Trying to remove a listener that isn't on the list!
  54266. // If this assertion happens because this object is a dangling pointer, make sure you've not
  54267. // deleted this menu model while it's still being used by something (e.g. by a MenuBarComponent)
  54268. jassert (listeners.contains (listenerToRemove));
  54269. listeners.remove (listenerToRemove);
  54270. }
  54271. void MenuBarModel::handleAsyncUpdate()
  54272. {
  54273. listeners.call (&MenuBarModelListener::menuBarItemsChanged, this);
  54274. }
  54275. void MenuBarModel::applicationCommandInvoked (const ApplicationCommandTarget::InvocationInfo& info)
  54276. {
  54277. listeners.call (&MenuBarModelListener::menuCommandInvoked, this, info);
  54278. }
  54279. void MenuBarModel::applicationCommandListChanged()
  54280. {
  54281. menuItemsChanged();
  54282. }
  54283. END_JUCE_NAMESPACE
  54284. /*** End of inlined file: juce_MenuBarModel.cpp ***/
  54285. /*** Start of inlined file: juce_PopupMenu.cpp ***/
  54286. BEGIN_JUCE_NAMESPACE
  54287. class PopupMenu::Item
  54288. {
  54289. public:
  54290. Item()
  54291. : itemId (0), active (true), isSeparator (true), isTicked (false),
  54292. usesColour (false), customComp (0), commandManager (0)
  54293. {
  54294. }
  54295. Item (const int itemId_,
  54296. const String& text_,
  54297. const bool active_,
  54298. const bool isTicked_,
  54299. const Image* im,
  54300. const Colour& textColour_,
  54301. const bool usesColour_,
  54302. PopupMenuCustomComponent* const customComp_,
  54303. const PopupMenu* const subMenu_,
  54304. ApplicationCommandManager* const commandManager_)
  54305. : itemId (itemId_), text (text_), textColour (textColour_),
  54306. active (active_), isSeparator (false), isTicked (isTicked_),
  54307. usesColour (usesColour_), customComp (customComp_),
  54308. commandManager (commandManager_)
  54309. {
  54310. if (subMenu_ != 0)
  54311. subMenu = new PopupMenu (*subMenu_);
  54312. if (im != 0)
  54313. image = im->createCopy();
  54314. if (commandManager_ != 0 && itemId_ != 0)
  54315. {
  54316. String shortcutKey;
  54317. Array <KeyPress> keyPresses (commandManager_->getKeyMappings()
  54318. ->getKeyPressesAssignedToCommand (itemId_));
  54319. for (int i = 0; i < keyPresses.size(); ++i)
  54320. {
  54321. const String key (keyPresses.getReference(i).getTextDescription());
  54322. if (shortcutKey.isNotEmpty())
  54323. shortcutKey << ", ";
  54324. if (key.length() == 1)
  54325. shortcutKey << "shortcut: '" << key << '\'';
  54326. else
  54327. shortcutKey << key;
  54328. }
  54329. shortcutKey = shortcutKey.trim();
  54330. if (shortcutKey.isNotEmpty())
  54331. text << "<end>" << shortcutKey;
  54332. }
  54333. }
  54334. Item (const Item& other)
  54335. : itemId (other.itemId),
  54336. text (other.text),
  54337. textColour (other.textColour),
  54338. active (other.active),
  54339. isSeparator (other.isSeparator),
  54340. isTicked (other.isTicked),
  54341. usesColour (other.usesColour),
  54342. customComp (other.customComp),
  54343. commandManager (other.commandManager)
  54344. {
  54345. if (other.subMenu != 0)
  54346. subMenu = new PopupMenu (*(other.subMenu));
  54347. if (other.image != 0)
  54348. image = other.image->createCopy();
  54349. }
  54350. ~Item()
  54351. {
  54352. customComp = 0;
  54353. }
  54354. bool canBeTriggered() const throw()
  54355. {
  54356. return active && ! (isSeparator || (subMenu != 0));
  54357. }
  54358. bool hasActiveSubMenu() const throw()
  54359. {
  54360. return active && (subMenu != 0);
  54361. }
  54362. const int itemId;
  54363. String text;
  54364. const Colour textColour;
  54365. const bool active, isSeparator, isTicked, usesColour;
  54366. ScopedPointer <Image> image;
  54367. ReferenceCountedObjectPtr <PopupMenuCustomComponent> customComp;
  54368. ScopedPointer <PopupMenu> subMenu;
  54369. ApplicationCommandManager* const commandManager;
  54370. juce_UseDebuggingNewOperator
  54371. private:
  54372. Item& operator= (const Item&);
  54373. };
  54374. class PopupMenu::ItemComponent : public Component
  54375. {
  54376. public:
  54377. ItemComponent (const PopupMenu::Item& itemInfo_)
  54378. : itemInfo (itemInfo_),
  54379. isHighlighted (false)
  54380. {
  54381. if (itemInfo.customComp != 0)
  54382. addAndMakeVisible (itemInfo.customComp);
  54383. }
  54384. ~ItemComponent()
  54385. {
  54386. if (itemInfo.customComp != 0)
  54387. removeChildComponent (itemInfo.customComp);
  54388. }
  54389. void getIdealSize (int& idealWidth,
  54390. int& idealHeight,
  54391. const int standardItemHeight)
  54392. {
  54393. if (itemInfo.customComp != 0)
  54394. {
  54395. itemInfo.customComp->getIdealSize (idealWidth, idealHeight);
  54396. }
  54397. else
  54398. {
  54399. getLookAndFeel().getIdealPopupMenuItemSize (itemInfo.text,
  54400. itemInfo.isSeparator,
  54401. standardItemHeight,
  54402. idealWidth,
  54403. idealHeight);
  54404. }
  54405. }
  54406. void paint (Graphics& g)
  54407. {
  54408. if (itemInfo.customComp == 0)
  54409. {
  54410. String mainText (itemInfo.text);
  54411. String endText;
  54412. const int endIndex = mainText.indexOf (T("<end>"));
  54413. if (endIndex >= 0)
  54414. {
  54415. endText = mainText.substring (endIndex + 5).trim();
  54416. mainText = mainText.substring (0, endIndex);
  54417. }
  54418. getLookAndFeel()
  54419. .drawPopupMenuItem (g, getWidth(), getHeight(),
  54420. itemInfo.isSeparator,
  54421. itemInfo.active,
  54422. isHighlighted,
  54423. itemInfo.isTicked,
  54424. itemInfo.subMenu != 0,
  54425. mainText, endText,
  54426. itemInfo.image,
  54427. itemInfo.usesColour ? &(itemInfo.textColour) : 0);
  54428. }
  54429. }
  54430. void resized()
  54431. {
  54432. if (getNumChildComponents() > 0)
  54433. getChildComponent(0)->setBounds (2, 0, getWidth() - 4, getHeight());
  54434. }
  54435. void setHighlighted (bool shouldBeHighlighted)
  54436. {
  54437. shouldBeHighlighted = shouldBeHighlighted && itemInfo.active;
  54438. if (isHighlighted != shouldBeHighlighted)
  54439. {
  54440. isHighlighted = shouldBeHighlighted;
  54441. if (itemInfo.customComp != 0)
  54442. {
  54443. itemInfo.customComp->isHighlighted = shouldBeHighlighted;
  54444. itemInfo.customComp->repaint();
  54445. }
  54446. repaint();
  54447. }
  54448. }
  54449. PopupMenu::Item itemInfo;
  54450. juce_UseDebuggingNewOperator
  54451. private:
  54452. bool isHighlighted;
  54453. ItemComponent (const ItemComponent&);
  54454. ItemComponent& operator= (const ItemComponent&);
  54455. };
  54456. namespace PopupMenuSettings
  54457. {
  54458. static const int scrollZone = 24;
  54459. static const int borderSize = 2;
  54460. static const int timerInterval = 50;
  54461. static const int dismissCommandId = 0x6287345f;
  54462. }
  54463. class PopupMenu::Window : public Component,
  54464. private Timer
  54465. {
  54466. public:
  54467. Window()
  54468. : Component (T("menu")),
  54469. owner (0),
  54470. currentChild (0),
  54471. activeSubMenu (0),
  54472. menuBarComponent (0),
  54473. managerOfChosenCommand (0),
  54474. minimumWidth (0),
  54475. maximumNumColumns (7),
  54476. standardItemHeight (0),
  54477. isOver (false),
  54478. hasBeenOver (false),
  54479. isDown (false),
  54480. needsToScroll (false),
  54481. hideOnExit (false),
  54482. disableMouseMoves (false),
  54483. hasAnyJuceCompHadFocus (false),
  54484. numColumns (0),
  54485. contentHeight (0),
  54486. childYOffset (0),
  54487. timeEnteredCurrentChildComp (0),
  54488. scrollAcceleration (1.0)
  54489. {
  54490. menuCreationTime = lastFocused = lastScroll = Time::getMillisecondCounter();
  54491. setWantsKeyboardFocus (true);
  54492. setMouseClickGrabsKeyboardFocus (false);
  54493. setOpaque (true);
  54494. setAlwaysOnTop (true);
  54495. Desktop::getInstance().addGlobalMouseListener (this);
  54496. getActiveWindows().add (this);
  54497. }
  54498. ~Window()
  54499. {
  54500. getActiveWindows().removeValue (this);
  54501. Desktop::getInstance().removeGlobalMouseListener (this);
  54502. jassert (activeSubMenu == 0 || activeSubMenu->isValidComponent());
  54503. activeSubMenu = 0;
  54504. deleteAllChildren();
  54505. }
  54506. static Window* create (const PopupMenu& menu,
  54507. const bool dismissOnMouseUp,
  54508. Window* const owner_,
  54509. const int minX, const int maxX,
  54510. const int minY, const int maxY,
  54511. const int minimumWidth,
  54512. const int maximumNumColumns,
  54513. const int standardItemHeight,
  54514. const bool alignToRectangle,
  54515. const int itemIdThatMustBeVisible,
  54516. Component* const menuBarComponent,
  54517. ApplicationCommandManager** managerOfChosenCommand,
  54518. Component* const componentAttachedTo)
  54519. {
  54520. if (menu.items.size() > 0)
  54521. {
  54522. int totalItems = 0;
  54523. ScopedPointer <Window> mw (new Window());
  54524. mw->setLookAndFeel (menu.lookAndFeel);
  54525. mw->setWantsKeyboardFocus (false);
  54526. mw->minimumWidth = minimumWidth;
  54527. mw->maximumNumColumns = maximumNumColumns;
  54528. mw->standardItemHeight = standardItemHeight;
  54529. mw->dismissOnMouseUp = dismissOnMouseUp;
  54530. for (int i = 0; i < menu.items.size(); ++i)
  54531. {
  54532. PopupMenu::Item* const item = menu.items.getUnchecked(i);
  54533. mw->addItem (*item);
  54534. ++totalItems;
  54535. }
  54536. if (totalItems > 0)
  54537. {
  54538. mw->owner = owner_;
  54539. mw->menuBarComponent = menuBarComponent;
  54540. mw->managerOfChosenCommand = managerOfChosenCommand;
  54541. mw->componentAttachedTo = componentAttachedTo;
  54542. mw->componentAttachedToOriginal = componentAttachedTo;
  54543. mw->calculateWindowPos (minX, maxX, minY, maxY, alignToRectangle);
  54544. mw->setTopLeftPosition (mw->windowPos.getX(),
  54545. mw->windowPos.getY());
  54546. mw->updateYPositions();
  54547. if (itemIdThatMustBeVisible != 0)
  54548. {
  54549. const int y = minY - mw->windowPos.getY();
  54550. mw->ensureItemIsVisible (itemIdThatMustBeVisible,
  54551. (((unsigned int) y) < (unsigned int) mw->windowPos.getHeight()) ? y : -1);
  54552. }
  54553. mw->resizeToBestWindowPos();
  54554. mw->addToDesktop (ComponentPeer::windowIsTemporary
  54555. | mw->getLookAndFeel().getMenuWindowFlags());
  54556. return mw.release();
  54557. }
  54558. }
  54559. return 0;
  54560. }
  54561. void paint (Graphics& g)
  54562. {
  54563. getLookAndFeel().drawPopupMenuBackground (g, getWidth(), getHeight());
  54564. }
  54565. void paintOverChildren (Graphics& g)
  54566. {
  54567. if (isScrolling())
  54568. {
  54569. LookAndFeel& lf = getLookAndFeel();
  54570. if (isScrollZoneActive (false))
  54571. lf.drawPopupMenuUpDownArrow (g, getWidth(), PopupMenuSettings::scrollZone, true);
  54572. if (isScrollZoneActive (true))
  54573. {
  54574. g.setOrigin (0, getHeight() - PopupMenuSettings::scrollZone);
  54575. lf.drawPopupMenuUpDownArrow (g, getWidth(), PopupMenuSettings::scrollZone, false);
  54576. }
  54577. }
  54578. }
  54579. bool isScrollZoneActive (bool bottomOne) const
  54580. {
  54581. return isScrolling()
  54582. && (bottomOne
  54583. ? childYOffset < contentHeight - windowPos.getHeight()
  54584. : childYOffset > 0);
  54585. }
  54586. void addItem (const PopupMenu::Item& item)
  54587. {
  54588. PopupMenu::ItemComponent* const mic = new PopupMenu::ItemComponent (item);
  54589. addAndMakeVisible (mic);
  54590. int itemW = 80;
  54591. int itemH = 16;
  54592. mic->getIdealSize (itemW, itemH, standardItemHeight);
  54593. mic->setSize (itemW, jlimit (2, 600, itemH));
  54594. mic->addMouseListener (this, false);
  54595. }
  54596. // hide this and all sub-comps
  54597. void hide (const PopupMenu::Item* const item)
  54598. {
  54599. if (isVisible())
  54600. {
  54601. jassert (activeSubMenu == 0 || activeSubMenu->isValidComponent());
  54602. activeSubMenu = 0;
  54603. currentChild = 0;
  54604. exitModalState (item != 0 ? item->itemId : 0);
  54605. setVisible (false);
  54606. if (item != 0
  54607. && item->commandManager != 0
  54608. && item->itemId != 0)
  54609. {
  54610. *managerOfChosenCommand = item->commandManager;
  54611. }
  54612. }
  54613. }
  54614. void dismissMenu (const PopupMenu::Item* const item)
  54615. {
  54616. if (owner != 0)
  54617. {
  54618. owner->dismissMenu (item);
  54619. }
  54620. else
  54621. {
  54622. if (item != 0)
  54623. {
  54624. // need a copy of this on the stack as the one passed in will get deleted during this call
  54625. const PopupMenu::Item mi (*item);
  54626. hide (&mi);
  54627. }
  54628. else
  54629. {
  54630. hide (0);
  54631. }
  54632. }
  54633. }
  54634. void mouseMove (const MouseEvent&)
  54635. {
  54636. timerCallback();
  54637. }
  54638. void mouseDown (const MouseEvent&)
  54639. {
  54640. timerCallback();
  54641. }
  54642. void mouseDrag (const MouseEvent&)
  54643. {
  54644. timerCallback();
  54645. }
  54646. void mouseUp (const MouseEvent&)
  54647. {
  54648. timerCallback();
  54649. }
  54650. void mouseWheelMove (const MouseEvent&, float /*amountX*/, float amountY)
  54651. {
  54652. alterChildYPos (roundToInt (-10.0f * amountY * PopupMenuSettings::scrollZone));
  54653. lastMouse = Point<int> (-1, -1);
  54654. }
  54655. bool keyPressed (const KeyPress& key)
  54656. {
  54657. if (key.isKeyCode (KeyPress::downKey))
  54658. {
  54659. selectNextItem (1);
  54660. }
  54661. else if (key.isKeyCode (KeyPress::upKey))
  54662. {
  54663. selectNextItem (-1);
  54664. }
  54665. else if (key.isKeyCode (KeyPress::leftKey))
  54666. {
  54667. if (owner != 0)
  54668. {
  54669. Component::SafePointer<Window> parentWindow (owner);
  54670. PopupMenu::ItemComponent* currentChildOfParent = parentWindow->currentChild;
  54671. hide (0);
  54672. if (parentWindow != 0)
  54673. parentWindow->setCurrentlyHighlightedChild (currentChildOfParent);
  54674. disableTimerUntilMouseMoves();
  54675. }
  54676. else if (menuBarComponent != 0)
  54677. {
  54678. menuBarComponent->keyPressed (key);
  54679. }
  54680. }
  54681. else if (key.isKeyCode (KeyPress::rightKey))
  54682. {
  54683. disableTimerUntilMouseMoves();
  54684. if (showSubMenuFor (currentChild))
  54685. {
  54686. jassert (activeSubMenu == 0 || activeSubMenu->isValidComponent());
  54687. if (activeSubMenu != 0 && activeSubMenu->isVisible())
  54688. activeSubMenu->selectNextItem (1);
  54689. }
  54690. else if (menuBarComponent != 0)
  54691. {
  54692. menuBarComponent->keyPressed (key);
  54693. }
  54694. }
  54695. else if (key.isKeyCode (KeyPress::returnKey))
  54696. {
  54697. triggerCurrentlyHighlightedItem();
  54698. }
  54699. else if (key.isKeyCode (KeyPress::escapeKey))
  54700. {
  54701. dismissMenu (0);
  54702. }
  54703. else
  54704. {
  54705. return false;
  54706. }
  54707. return true;
  54708. }
  54709. void inputAttemptWhenModal()
  54710. {
  54711. timerCallback();
  54712. if (! isOverAnyMenu())
  54713. {
  54714. if (componentAttachedTo != 0)
  54715. {
  54716. // we want to dismiss the menu, but if we do it synchronously, then
  54717. // the mouse-click will be allowed to pass through. That's good, except
  54718. // when the user clicks on the button that orginally popped the menu up,
  54719. // as they'll expect the menu to go away, and in fact it'll just
  54720. // come back. So only dismiss synchronously if they're not on the original
  54721. // comp that we're attached to.
  54722. const Point<int> mousePos (componentAttachedTo->getMouseXYRelative());
  54723. if (componentAttachedTo->reallyContains (mousePos.getX(), mousePos.getY(), true))
  54724. {
  54725. postCommandMessage (PopupMenuSettings::dismissCommandId); // dismiss asynchrounously
  54726. return;
  54727. }
  54728. }
  54729. dismissMenu (0);
  54730. }
  54731. }
  54732. void handleCommandMessage (int commandId)
  54733. {
  54734. Component::handleCommandMessage (commandId);
  54735. if (commandId == PopupMenuSettings::dismissCommandId)
  54736. dismissMenu (0);
  54737. }
  54738. void timerCallback()
  54739. {
  54740. if (! isVisible())
  54741. return;
  54742. if (componentAttachedTo != componentAttachedToOriginal)
  54743. {
  54744. dismissMenu (0);
  54745. return;
  54746. }
  54747. Window* currentlyModalWindow = dynamic_cast <Window*> (Component::getCurrentlyModalComponent());
  54748. if (currentlyModalWindow != 0 && ! treeContains (currentlyModalWindow))
  54749. return;
  54750. startTimer (PopupMenuSettings::timerInterval); // do this in case it was called from a mouse
  54751. // move rather than a real timer callback
  54752. const Point<int> globalMousePos (Desktop::getMousePosition());
  54753. const Point<int> localMousePos (globalPositionToRelative (globalMousePos));
  54754. const uint32 now = Time::getMillisecondCounter();
  54755. if (now > timeEnteredCurrentChildComp + 100
  54756. && reallyContains (localMousePos.getX(), localMousePos.getY(), true)
  54757. && currentChild->isValidComponent()
  54758. && (! disableMouseMoves)
  54759. && ! (activeSubMenu != 0 && activeSubMenu->isVisible()))
  54760. {
  54761. showSubMenuFor (currentChild);
  54762. }
  54763. if (globalMousePos != lastMouse || now > lastMouseMoveTime + 350)
  54764. {
  54765. highlightItemUnderMouse (globalMousePos, localMousePos);
  54766. }
  54767. bool overScrollArea = false;
  54768. if (isScrolling()
  54769. && (isOver || (isDown && ((unsigned int) localMousePos.getX()) < (unsigned int) getWidth()))
  54770. && ((isScrollZoneActive (false) && localMousePos.getY() < PopupMenuSettings::scrollZone)
  54771. || (isScrollZoneActive (true) && localMousePos.getY() > getHeight() - PopupMenuSettings::scrollZone)))
  54772. {
  54773. if (now > lastScroll + 20)
  54774. {
  54775. scrollAcceleration = jmin (4.0, scrollAcceleration * 1.04);
  54776. int amount = 0;
  54777. for (int i = 0; i < getNumChildComponents() && amount == 0; ++i)
  54778. amount = ((int) scrollAcceleration) * getChildComponent (i)->getHeight();
  54779. alterChildYPos (localMousePos.getY() < PopupMenuSettings::scrollZone ? -amount : amount);
  54780. lastScroll = now;
  54781. }
  54782. overScrollArea = true;
  54783. lastMouse = Point<int> (-1, -1); // trigger a mouse-move
  54784. }
  54785. else
  54786. {
  54787. scrollAcceleration = 1.0;
  54788. }
  54789. const bool wasDown = isDown;
  54790. bool isOverAny = isOverAnyMenu();
  54791. if (hideOnExit && hasBeenOver && (! isOverAny) && activeSubMenu != 0)
  54792. {
  54793. activeSubMenu->updateMouseOverStatus (globalMousePos);
  54794. isOverAny = isOverAnyMenu();
  54795. }
  54796. if (hideOnExit && hasBeenOver && ! isOverAny)
  54797. {
  54798. hide (0);
  54799. }
  54800. else
  54801. {
  54802. isDown = hasBeenOver
  54803. && (ModifierKeys::getCurrentModifiers().isAnyMouseButtonDown()
  54804. || ModifierKeys::getCurrentModifiersRealtime().isAnyMouseButtonDown());
  54805. bool anyFocused = Process::isForegroundProcess();
  54806. if (anyFocused && Component::getCurrentlyFocusedComponent() == 0)
  54807. {
  54808. // because no component at all may have focus, our test here will
  54809. // only be triggered when something has focus and then loses it.
  54810. anyFocused = ! hasAnyJuceCompHadFocus;
  54811. for (int i = ComponentPeer::getNumPeers(); --i >= 0;)
  54812. {
  54813. if (ComponentPeer::getPeer (i)->isFocused())
  54814. {
  54815. anyFocused = true;
  54816. hasAnyJuceCompHadFocus = true;
  54817. break;
  54818. }
  54819. }
  54820. }
  54821. if (! anyFocused)
  54822. {
  54823. if (now > lastFocused + 10)
  54824. {
  54825. wasHiddenBecauseOfAppChange() = true;
  54826. dismissMenu (0);
  54827. return; // may have been deleted by the previous call..
  54828. }
  54829. }
  54830. else if (wasDown && now > menuCreationTime + 250
  54831. && ! (isDown || overScrollArea))
  54832. {
  54833. isOver = reallyContains (localMousePos.getX(), localMousePos.getY(), true);
  54834. if (isOver)
  54835. {
  54836. triggerCurrentlyHighlightedItem();
  54837. }
  54838. else if ((hasBeenOver || ! dismissOnMouseUp) && ! isOverAny)
  54839. {
  54840. dismissMenu (0);
  54841. }
  54842. return; // may have been deleted by the previous calls..
  54843. }
  54844. else
  54845. {
  54846. lastFocused = now;
  54847. }
  54848. }
  54849. }
  54850. static Array<Window*>& getActiveWindows()
  54851. {
  54852. static Array<Window*> activeMenuWindows;
  54853. return activeMenuWindows;
  54854. }
  54855. static bool& wasHiddenBecauseOfAppChange() throw()
  54856. {
  54857. static bool b = false;
  54858. return b;
  54859. }
  54860. juce_UseDebuggingNewOperator
  54861. private:
  54862. Window* owner;
  54863. PopupMenu::ItemComponent* currentChild;
  54864. ScopedPointer <Window> activeSubMenu;
  54865. Component* menuBarComponent;
  54866. ApplicationCommandManager** managerOfChosenCommand;
  54867. Component::SafePointer<Component> componentAttachedTo;
  54868. Component* componentAttachedToOriginal;
  54869. Rectangle<int> windowPos;
  54870. Point<int> lastMouse;
  54871. int minimumWidth, maximumNumColumns, standardItemHeight;
  54872. bool isOver, hasBeenOver, isDown, needsToScroll;
  54873. bool dismissOnMouseUp, hideOnExit, disableMouseMoves, hasAnyJuceCompHadFocus;
  54874. int numColumns, contentHeight, childYOffset;
  54875. Array <int> columnWidths;
  54876. uint32 menuCreationTime, lastFocused, lastScroll, lastMouseMoveTime, timeEnteredCurrentChildComp;
  54877. double scrollAcceleration;
  54878. bool overlaps (const Rectangle<int>& r) const
  54879. {
  54880. return r.intersects (getBounds())
  54881. || (owner != 0 && owner->overlaps (r));
  54882. }
  54883. bool isOverAnyMenu() const
  54884. {
  54885. return (owner != 0) ? owner->isOverAnyMenu()
  54886. : isOverChildren();
  54887. }
  54888. bool isOverChildren() const
  54889. {
  54890. jassert (activeSubMenu == 0 || activeSubMenu->isValidComponent());
  54891. return isVisible()
  54892. && (isOver || (activeSubMenu != 0 && activeSubMenu->isOverChildren()));
  54893. }
  54894. void updateMouseOverStatus (const Point<int>& globalMousePos)
  54895. {
  54896. const Point<int> relPos (globalPositionToRelative (globalMousePos));
  54897. isOver = reallyContains (relPos.getX(), relPos.getY(), true);
  54898. if (activeSubMenu != 0)
  54899. activeSubMenu->updateMouseOverStatus (globalMousePos);
  54900. }
  54901. bool treeContains (const Window* const window) const throw()
  54902. {
  54903. const Window* mw = this;
  54904. while (mw->owner != 0)
  54905. mw = mw->owner;
  54906. while (mw != 0)
  54907. {
  54908. if (mw == window)
  54909. return true;
  54910. mw = mw->activeSubMenu;
  54911. }
  54912. return false;
  54913. }
  54914. void calculateWindowPos (const int minX, const int maxX,
  54915. const int minY, const int maxY,
  54916. const bool alignToRectangle)
  54917. {
  54918. const Rectangle<int> mon (Desktop::getInstance()
  54919. .getMonitorAreaContaining (Point<int> ((minX + maxX) / 2,
  54920. (minY + maxY) / 2),
  54921. #if JUCE_MAC
  54922. true));
  54923. #else
  54924. false)); // on windows, don't stop the menu overlapping the taskbar
  54925. #endif
  54926. int x, y, widthToUse, heightToUse;
  54927. layoutMenuItems (mon.getWidth() - 24, widthToUse, heightToUse);
  54928. if (alignToRectangle)
  54929. {
  54930. x = minX;
  54931. const int spaceUnder = mon.getHeight() - (maxY - mon.getY());
  54932. const int spaceOver = minY - mon.getY();
  54933. if (heightToUse < spaceUnder - 30 || spaceUnder >= spaceOver)
  54934. y = maxY;
  54935. else
  54936. y = minY - heightToUse;
  54937. }
  54938. else
  54939. {
  54940. bool tendTowardsRight = (minX + maxX) / 2 < mon.getCentreX();
  54941. if (owner != 0)
  54942. {
  54943. if (owner->owner != 0)
  54944. {
  54945. const bool ownerGoingRight = (owner->getX() + owner->getWidth() / 2
  54946. > owner->owner->getX() + owner->owner->getWidth() / 2);
  54947. if (ownerGoingRight && maxX + widthToUse < mon.getRight() - 4)
  54948. tendTowardsRight = true;
  54949. else if ((! ownerGoingRight) && minX > widthToUse + 4)
  54950. tendTowardsRight = false;
  54951. }
  54952. else if (maxX + widthToUse < mon.getRight() - 32)
  54953. {
  54954. tendTowardsRight = true;
  54955. }
  54956. }
  54957. const int biggestSpace = jmax (mon.getRight() - maxX,
  54958. minX - mon.getX()) - 32;
  54959. if (biggestSpace < widthToUse)
  54960. {
  54961. layoutMenuItems (biggestSpace + (maxX - minX) / 3, widthToUse, heightToUse);
  54962. if (numColumns > 1)
  54963. layoutMenuItems (biggestSpace - 4, widthToUse, heightToUse);
  54964. tendTowardsRight = (mon.getRight() - maxX) >= (minX - mon.getX());
  54965. }
  54966. if (tendTowardsRight)
  54967. x = jmin (mon.getRight() - widthToUse - 4, maxX);
  54968. else
  54969. x = jmax (mon.getX() + 4, minX - widthToUse);
  54970. y = minY;
  54971. if ((minY + maxY) / 2 > mon.getCentreY())
  54972. y = jmax (mon.getY(), maxY - heightToUse);
  54973. }
  54974. x = jmax (mon.getX() + 1, jmin (mon.getRight() - (widthToUse + 6), x));
  54975. y = jmax (mon.getY() + 1, jmin (mon.getBottom() - (heightToUse + 6), y));
  54976. windowPos.setBounds (x, y, widthToUse, heightToUse);
  54977. // sets this flag if it's big enough to obscure any of its parent menus
  54978. hideOnExit = (owner != 0)
  54979. && owner->windowPos.intersects (windowPos.expanded (-4, -4));
  54980. }
  54981. void layoutMenuItems (const int maxMenuW, int& width, int& height)
  54982. {
  54983. numColumns = 0;
  54984. contentHeight = 0;
  54985. const int maxMenuH = getParentHeight() - 24;
  54986. int totalW;
  54987. do
  54988. {
  54989. ++numColumns;
  54990. totalW = workOutBestSize (maxMenuW);
  54991. if (totalW > maxMenuW)
  54992. {
  54993. numColumns = jmax (1, numColumns - 1);
  54994. totalW = workOutBestSize (maxMenuW); // to update col widths
  54995. break;
  54996. }
  54997. else if (totalW > maxMenuW / 2 || contentHeight < maxMenuH)
  54998. {
  54999. break;
  55000. }
  55001. } while (numColumns < maximumNumColumns);
  55002. const int actualH = jmin (contentHeight, maxMenuH);
  55003. needsToScroll = contentHeight > actualH;
  55004. width = updateYPositions();
  55005. height = actualH + PopupMenuSettings::borderSize * 2;
  55006. }
  55007. int workOutBestSize (const int maxMenuW)
  55008. {
  55009. int totalW = 0;
  55010. contentHeight = 0;
  55011. int childNum = 0;
  55012. for (int col = 0; col < numColumns; ++col)
  55013. {
  55014. int i, colW = 50, colH = 0;
  55015. const int numChildren = jmin (getNumChildComponents() - childNum,
  55016. (getNumChildComponents() + numColumns - 1) / numColumns);
  55017. for (i = numChildren; --i >= 0;)
  55018. {
  55019. colW = jmax (colW, getChildComponent (childNum + i)->getWidth());
  55020. colH += getChildComponent (childNum + i)->getHeight();
  55021. }
  55022. colW = jmin (maxMenuW / jmax (1, numColumns - 2), colW + PopupMenuSettings::borderSize * 2);
  55023. columnWidths.set (col, colW);
  55024. totalW += colW;
  55025. contentHeight = jmax (contentHeight, colH);
  55026. childNum += numChildren;
  55027. }
  55028. if (totalW < minimumWidth)
  55029. {
  55030. totalW = minimumWidth;
  55031. for (int col = 0; col < numColumns; ++col)
  55032. columnWidths.set (0, totalW / numColumns);
  55033. }
  55034. return totalW;
  55035. }
  55036. void ensureItemIsVisible (const int itemId, int wantedY)
  55037. {
  55038. jassert (itemId != 0)
  55039. for (int i = getNumChildComponents(); --i >= 0;)
  55040. {
  55041. PopupMenu::ItemComponent* const m = (PopupMenu::ItemComponent*) getChildComponent (i);
  55042. if (m != 0
  55043. && m->itemInfo.itemId == itemId
  55044. && windowPos.getHeight() > PopupMenuSettings::scrollZone * 4)
  55045. {
  55046. const int currentY = m->getY();
  55047. if (wantedY > 0 || currentY < 0 || m->getBottom() > windowPos.getHeight())
  55048. {
  55049. if (wantedY < 0)
  55050. wantedY = jlimit (PopupMenuSettings::scrollZone,
  55051. jmax (PopupMenuSettings::scrollZone,
  55052. windowPos.getHeight() - (PopupMenuSettings::scrollZone + m->getHeight())),
  55053. currentY);
  55054. const Rectangle<int> mon (Desktop::getInstance().getMonitorAreaContaining (windowPos.getPosition(), true));
  55055. int deltaY = wantedY - currentY;
  55056. windowPos.setSize (jmin (windowPos.getWidth(), mon.getWidth()),
  55057. jmin (windowPos.getHeight(), mon.getHeight()));
  55058. const int newY = jlimit (mon.getY(),
  55059. mon.getBottom() - windowPos.getHeight(),
  55060. windowPos.getY() + deltaY);
  55061. deltaY -= newY - windowPos.getY();
  55062. childYOffset -= deltaY;
  55063. windowPos.setPosition (windowPos.getX(), newY);
  55064. updateYPositions();
  55065. }
  55066. break;
  55067. }
  55068. }
  55069. }
  55070. void resizeToBestWindowPos()
  55071. {
  55072. Rectangle<int> r (windowPos);
  55073. if (childYOffset < 0)
  55074. {
  55075. r.setBounds (r.getX(), r.getY() - childYOffset,
  55076. r.getWidth(), r.getHeight() + childYOffset);
  55077. }
  55078. else if (childYOffset > 0)
  55079. {
  55080. const int spaceAtBottom = r.getHeight() - (contentHeight - childYOffset);
  55081. if (spaceAtBottom > 0)
  55082. r.setSize (r.getWidth(), r.getHeight() - spaceAtBottom);
  55083. }
  55084. setBounds (r);
  55085. updateYPositions();
  55086. }
  55087. void alterChildYPos (const int delta)
  55088. {
  55089. if (isScrolling())
  55090. {
  55091. childYOffset += delta;
  55092. if (delta < 0)
  55093. {
  55094. childYOffset = jmax (childYOffset, 0);
  55095. }
  55096. else if (delta > 0)
  55097. {
  55098. childYOffset = jmin (childYOffset,
  55099. contentHeight - windowPos.getHeight() + PopupMenuSettings::borderSize);
  55100. }
  55101. updateYPositions();
  55102. }
  55103. else
  55104. {
  55105. childYOffset = 0;
  55106. }
  55107. resizeToBestWindowPos();
  55108. repaint();
  55109. }
  55110. int updateYPositions()
  55111. {
  55112. int x = 0;
  55113. int childNum = 0;
  55114. for (int col = 0; col < numColumns; ++col)
  55115. {
  55116. const int numChildren = jmin (getNumChildComponents() - childNum,
  55117. (getNumChildComponents() + numColumns - 1) / numColumns);
  55118. const int colW = columnWidths [col];
  55119. int y = PopupMenuSettings::borderSize - (childYOffset + (getY() - windowPos.getY()));
  55120. for (int i = 0; i < numChildren; ++i)
  55121. {
  55122. Component* const c = getChildComponent (childNum + i);
  55123. c->setBounds (x, y, colW, c->getHeight());
  55124. y += c->getHeight();
  55125. }
  55126. x += colW;
  55127. childNum += numChildren;
  55128. }
  55129. return x;
  55130. }
  55131. bool isScrolling() const throw()
  55132. {
  55133. return childYOffset != 0 || needsToScroll;
  55134. }
  55135. void setCurrentlyHighlightedChild (PopupMenu::ItemComponent* const child)
  55136. {
  55137. if (currentChild->isValidComponent())
  55138. currentChild->setHighlighted (false);
  55139. currentChild = child;
  55140. if (currentChild != 0)
  55141. {
  55142. currentChild->setHighlighted (true);
  55143. timeEnteredCurrentChildComp = Time::getApproximateMillisecondCounter();
  55144. }
  55145. }
  55146. bool showSubMenuFor (PopupMenu::ItemComponent* const childComp)
  55147. {
  55148. jassert (activeSubMenu == 0 || activeSubMenu->isValidComponent());
  55149. activeSubMenu = 0;
  55150. if (childComp->isValidComponent() && childComp->itemInfo.hasActiveSubMenu())
  55151. {
  55152. const Point<int> topLeft (childComp->relativePositionToGlobal (Point<int>()));
  55153. const Point<int> bottomRight (childComp->relativePositionToGlobal (Point<int> (childComp->getWidth(), childComp->getHeight())));
  55154. activeSubMenu = Window::create (*(childComp->itemInfo.subMenu),
  55155. dismissOnMouseUp,
  55156. this,
  55157. topLeft.getX(), bottomRight.getX(), topLeft.getY(), bottomRight.getY(),
  55158. 0, maximumNumColumns,
  55159. standardItemHeight,
  55160. false, 0, menuBarComponent,
  55161. managerOfChosenCommand,
  55162. componentAttachedTo);
  55163. if (activeSubMenu != 0)
  55164. {
  55165. activeSubMenu->setVisible (true);
  55166. activeSubMenu->enterModalState (false);
  55167. activeSubMenu->toFront (false);
  55168. return true;
  55169. }
  55170. }
  55171. return false;
  55172. }
  55173. void highlightItemUnderMouse (const Point<int>& globalMousePos, const Point<int>& localMousePos)
  55174. {
  55175. isOver = reallyContains (localMousePos.getX(), localMousePos.getY(), true);
  55176. if (isOver)
  55177. hasBeenOver = true;
  55178. if (lastMouse.getDistanceFrom (globalMousePos) > 2)
  55179. {
  55180. lastMouseMoveTime = Time::getApproximateMillisecondCounter();
  55181. if (disableMouseMoves && isOver)
  55182. disableMouseMoves = false;
  55183. }
  55184. if (disableMouseMoves)
  55185. return;
  55186. bool isMovingTowardsMenu = false;
  55187. jassert (activeSubMenu == 0 || activeSubMenu->isValidComponent())
  55188. if (isOver && (activeSubMenu != 0) && globalMousePos != lastMouse)
  55189. {
  55190. // try to intelligently guess whether the user is moving the mouse towards a currently-open
  55191. // submenu. To do this, look at whether the mouse stays inside a triangular region that
  55192. // extends from the last mouse pos to the submenu's rectangle..
  55193. float subX = (float) activeSubMenu->getScreenX();
  55194. if (activeSubMenu->getX() > getX())
  55195. {
  55196. lastMouse -= Point<int> (2, 0); // to enlarge the triangle a bit, in case the mouse only moves a couple of pixels
  55197. }
  55198. else
  55199. {
  55200. lastMouse += Point<int> (2, 0);
  55201. subX += activeSubMenu->getWidth();
  55202. }
  55203. Path areaTowardsSubMenu;
  55204. areaTowardsSubMenu.addTriangle ((float) lastMouse.getX(),
  55205. (float) lastMouse.getY(),
  55206. subX,
  55207. (float) activeSubMenu->getScreenY(),
  55208. subX,
  55209. (float) (activeSubMenu->getScreenY() + activeSubMenu->getHeight()));
  55210. isMovingTowardsMenu = areaTowardsSubMenu.contains ((float) globalMousePos.getX(), (float) globalMousePos.getY());
  55211. }
  55212. lastMouse = globalMousePos;
  55213. if (! isMovingTowardsMenu)
  55214. {
  55215. Component* c = getComponentAt (localMousePos.getX(), localMousePos.getY());
  55216. if (c == this)
  55217. c = 0;
  55218. PopupMenu::ItemComponent* mic = dynamic_cast <PopupMenu::ItemComponent*> (c);
  55219. if (mic == 0 && c != 0)
  55220. mic = c->findParentComponentOfClass ((PopupMenu::ItemComponent*) 0);
  55221. if (mic != currentChild
  55222. && (isOver || (activeSubMenu == 0) || ! activeSubMenu->isVisible()))
  55223. {
  55224. if (isOver && (c != 0) && (activeSubMenu != 0))
  55225. {
  55226. activeSubMenu->hide (0);
  55227. }
  55228. if (! isOver)
  55229. mic = 0;
  55230. setCurrentlyHighlightedChild (mic);
  55231. }
  55232. }
  55233. }
  55234. void triggerCurrentlyHighlightedItem()
  55235. {
  55236. if (currentChild->isValidComponent()
  55237. && currentChild->itemInfo.canBeTriggered()
  55238. && (currentChild->itemInfo.customComp == 0
  55239. || currentChild->itemInfo.customComp->isTriggeredAutomatically))
  55240. {
  55241. dismissMenu (&currentChild->itemInfo);
  55242. }
  55243. }
  55244. void selectNextItem (const int delta)
  55245. {
  55246. disableTimerUntilMouseMoves();
  55247. PopupMenu::ItemComponent* mic = 0;
  55248. bool wasLastOne = (currentChild == 0);
  55249. const int numItems = getNumChildComponents();
  55250. for (int i = 0; i < numItems + 1; ++i)
  55251. {
  55252. int index = (delta > 0) ? i : (numItems - 1 - i);
  55253. index = (index + numItems) % numItems;
  55254. mic = dynamic_cast <PopupMenu::ItemComponent*> (getChildComponent (index));
  55255. if (mic != 0 && (mic->itemInfo.canBeTriggered() || mic->itemInfo.hasActiveSubMenu())
  55256. && wasLastOne)
  55257. break;
  55258. if (mic == currentChild)
  55259. wasLastOne = true;
  55260. }
  55261. setCurrentlyHighlightedChild (mic);
  55262. }
  55263. void disableTimerUntilMouseMoves()
  55264. {
  55265. disableMouseMoves = true;
  55266. if (owner != 0)
  55267. owner->disableTimerUntilMouseMoves();
  55268. }
  55269. Window (const Window&);
  55270. Window& operator= (const Window&);
  55271. };
  55272. PopupMenu::PopupMenu()
  55273. : lookAndFeel (0),
  55274. separatorPending (false)
  55275. {
  55276. }
  55277. PopupMenu::PopupMenu (const PopupMenu& other)
  55278. : lookAndFeel (other.lookAndFeel),
  55279. separatorPending (false)
  55280. {
  55281. items.ensureStorageAllocated (other.items.size());
  55282. for (int i = 0; i < other.items.size(); ++i)
  55283. items.add (new Item (*other.items.getUnchecked(i)));
  55284. }
  55285. PopupMenu& PopupMenu::operator= (const PopupMenu& other)
  55286. {
  55287. if (this != &other)
  55288. {
  55289. lookAndFeel = other.lookAndFeel;
  55290. clear();
  55291. items.ensureStorageAllocated (other.items.size());
  55292. for (int i = 0; i < other.items.size(); ++i)
  55293. items.add (new Item (*other.items.getUnchecked(i)));
  55294. }
  55295. return *this;
  55296. }
  55297. PopupMenu::~PopupMenu()
  55298. {
  55299. clear();
  55300. }
  55301. void PopupMenu::clear()
  55302. {
  55303. items.clear();
  55304. separatorPending = false;
  55305. }
  55306. void PopupMenu::addSeparatorIfPending()
  55307. {
  55308. if (separatorPending)
  55309. {
  55310. separatorPending = false;
  55311. if (items.size() > 0)
  55312. items.add (new Item());
  55313. }
  55314. }
  55315. void PopupMenu::addItem (const int itemResultId,
  55316. const String& itemText,
  55317. const bool isActive,
  55318. const bool isTicked,
  55319. const Image* const iconToUse)
  55320. {
  55321. jassert (itemResultId != 0); // 0 is used as a return value to indicate that the user
  55322. // didn't pick anything, so you shouldn't use it as the id
  55323. // for an item..
  55324. addSeparatorIfPending();
  55325. items.add (new Item (itemResultId, itemText, isActive, isTicked,
  55326. iconToUse, Colours::black, false, 0, 0, 0));
  55327. }
  55328. void PopupMenu::addCommandItem (ApplicationCommandManager* commandManager,
  55329. const int commandID,
  55330. const String& displayName)
  55331. {
  55332. jassert (commandManager != 0 && commandID != 0);
  55333. const ApplicationCommandInfo* const registeredInfo = commandManager->getCommandForID (commandID);
  55334. if (registeredInfo != 0)
  55335. {
  55336. ApplicationCommandInfo info (*registeredInfo);
  55337. ApplicationCommandTarget* const target = commandManager->getTargetForCommand (commandID, info);
  55338. addSeparatorIfPending();
  55339. items.add (new Item (commandID,
  55340. displayName.isNotEmpty() ? displayName
  55341. : info.shortName,
  55342. target != 0 && (info.flags & ApplicationCommandInfo::isDisabled) == 0,
  55343. (info.flags & ApplicationCommandInfo::isTicked) != 0,
  55344. 0,
  55345. Colours::black,
  55346. false,
  55347. 0, 0,
  55348. commandManager));
  55349. }
  55350. }
  55351. void PopupMenu::addColouredItem (const int itemResultId,
  55352. const String& itemText,
  55353. const Colour& itemTextColour,
  55354. const bool isActive,
  55355. const bool isTicked,
  55356. const Image* const iconToUse)
  55357. {
  55358. jassert (itemResultId != 0); // 0 is used as a return value to indicate that the user
  55359. // didn't pick anything, so you shouldn't use it as the id
  55360. // for an item..
  55361. addSeparatorIfPending();
  55362. items.add (new Item (itemResultId, itemText, isActive, isTicked,
  55363. iconToUse, itemTextColour, true, 0, 0, 0));
  55364. }
  55365. void PopupMenu::addCustomItem (const int itemResultId,
  55366. PopupMenuCustomComponent* const customComponent)
  55367. {
  55368. jassert (itemResultId != 0); // 0 is used as a return value to indicate that the user
  55369. // didn't pick anything, so you shouldn't use it as the id
  55370. // for an item..
  55371. addSeparatorIfPending();
  55372. items.add (new Item (itemResultId, String::empty, true, false, 0,
  55373. Colours::black, false, customComponent, 0, 0));
  55374. }
  55375. class NormalComponentWrapper : public PopupMenuCustomComponent
  55376. {
  55377. public:
  55378. NormalComponentWrapper (Component* const comp,
  55379. const int w, const int h,
  55380. const bool triggerMenuItemAutomaticallyWhenClicked)
  55381. : PopupMenuCustomComponent (triggerMenuItemAutomaticallyWhenClicked),
  55382. width (w),
  55383. height (h)
  55384. {
  55385. addAndMakeVisible (comp);
  55386. }
  55387. ~NormalComponentWrapper() {}
  55388. void getIdealSize (int& idealWidth, int& idealHeight)
  55389. {
  55390. idealWidth = width;
  55391. idealHeight = height;
  55392. }
  55393. void resized()
  55394. {
  55395. if (getChildComponent(0) != 0)
  55396. getChildComponent(0)->setBounds (0, 0, getWidth(), getHeight());
  55397. }
  55398. juce_UseDebuggingNewOperator
  55399. private:
  55400. const int width, height;
  55401. NormalComponentWrapper (const NormalComponentWrapper&);
  55402. NormalComponentWrapper& operator= (const NormalComponentWrapper&);
  55403. };
  55404. void PopupMenu::addCustomItem (const int itemResultId,
  55405. Component* customComponent,
  55406. int idealWidth, int idealHeight,
  55407. const bool triggerMenuItemAutomaticallyWhenClicked)
  55408. {
  55409. addCustomItem (itemResultId,
  55410. new NormalComponentWrapper (customComponent,
  55411. idealWidth, idealHeight,
  55412. triggerMenuItemAutomaticallyWhenClicked));
  55413. }
  55414. void PopupMenu::addSubMenu (const String& subMenuName,
  55415. const PopupMenu& subMenu,
  55416. const bool isActive,
  55417. Image* const iconToUse,
  55418. const bool isTicked)
  55419. {
  55420. addSeparatorIfPending();
  55421. items.add (new Item (0, subMenuName, isActive && (subMenu.getNumItems() > 0), isTicked,
  55422. iconToUse, Colours::black, false, 0, &subMenu, 0));
  55423. }
  55424. void PopupMenu::addSeparator()
  55425. {
  55426. separatorPending = true;
  55427. }
  55428. class HeaderItemComponent : public PopupMenuCustomComponent
  55429. {
  55430. public:
  55431. HeaderItemComponent (const String& name)
  55432. : PopupMenuCustomComponent (false)
  55433. {
  55434. setName (name);
  55435. }
  55436. ~HeaderItemComponent()
  55437. {
  55438. }
  55439. void paint (Graphics& g)
  55440. {
  55441. Font f (getLookAndFeel().getPopupMenuFont());
  55442. f.setBold (true);
  55443. g.setFont (f);
  55444. g.setColour (findColour (PopupMenu::headerTextColourId));
  55445. g.drawFittedText (getName(),
  55446. 12, 0, getWidth() - 16, proportionOfHeight (0.8f),
  55447. Justification::bottomLeft, 1);
  55448. }
  55449. void getIdealSize (int& idealWidth,
  55450. int& idealHeight)
  55451. {
  55452. getLookAndFeel().getIdealPopupMenuItemSize (getName(), false, -1, idealWidth, idealHeight);
  55453. idealHeight += idealHeight / 2;
  55454. idealWidth += idealWidth / 4;
  55455. }
  55456. juce_UseDebuggingNewOperator
  55457. };
  55458. void PopupMenu::addSectionHeader (const String& title)
  55459. {
  55460. addCustomItem (0X4734a34f, new HeaderItemComponent (title));
  55461. }
  55462. Component* PopupMenu::createMenuComponent (const int x, const int y, const int w, const int h,
  55463. const int itemIdThatMustBeVisible,
  55464. const int minimumWidth,
  55465. const int maximumNumColumns,
  55466. const int standardItemHeight,
  55467. const bool alignToRectangle,
  55468. Component* menuBarComponent,
  55469. ApplicationCommandManager** managerOfChosenCommand,
  55470. Component* const componentAttachedTo)
  55471. {
  55472. Window* const pw
  55473. = Window::create (*this,
  55474. ModifierKeys::getCurrentModifiers().isAnyMouseButtonDown(),
  55475. 0,
  55476. x, x + w,
  55477. y, y + h,
  55478. minimumWidth,
  55479. maximumNumColumns,
  55480. standardItemHeight,
  55481. alignToRectangle,
  55482. itemIdThatMustBeVisible,
  55483. menuBarComponent,
  55484. managerOfChosenCommand,
  55485. componentAttachedTo);
  55486. if (pw != 0)
  55487. pw->setVisible (true);
  55488. return pw;
  55489. }
  55490. int PopupMenu::showMenu (const int x, const int y, const int w, const int h,
  55491. const int itemIdThatMustBeVisible,
  55492. const int minimumWidth,
  55493. const int maximumNumColumns,
  55494. const int standardItemHeight,
  55495. const bool alignToRectangle,
  55496. Component* const componentAttachedTo)
  55497. {
  55498. Component::SafePointer<Component> prevFocused (Component::getCurrentlyFocusedComponent());
  55499. Component::SafePointer<Component> prevTopLevel ((prevFocused != 0) ? prevFocused->getTopLevelComponent() : 0);
  55500. Window::wasHiddenBecauseOfAppChange() = false;
  55501. int result = 0;
  55502. ApplicationCommandManager* managerOfChosenCommand = 0;
  55503. ScopedPointer <Component> popupComp (createMenuComponent (x, y, w, h,
  55504. itemIdThatMustBeVisible,
  55505. minimumWidth,
  55506. maximumNumColumns > 0 ? maximumNumColumns : 7,
  55507. standardItemHeight,
  55508. alignToRectangle, 0,
  55509. &managerOfChosenCommand,
  55510. componentAttachedTo));
  55511. if (popupComp != 0)
  55512. {
  55513. popupComp->enterModalState (false);
  55514. popupComp->toFront (false); // need to do this after making it modal, or it could
  55515. // be stuck behind other comps that are already modal..
  55516. result = popupComp->runModalLoop();
  55517. popupComp = 0;
  55518. if (! Window::wasHiddenBecauseOfAppChange())
  55519. {
  55520. if (prevTopLevel != 0)
  55521. prevTopLevel->toFront (true);
  55522. if (prevFocused != 0)
  55523. prevFocused->grabKeyboardFocus();
  55524. }
  55525. }
  55526. if (managerOfChosenCommand != 0 && result != 0)
  55527. {
  55528. ApplicationCommandTarget::InvocationInfo info (result);
  55529. info.invocationMethod = ApplicationCommandTarget::InvocationInfo::fromMenu;
  55530. managerOfChosenCommand->invoke (info, true);
  55531. }
  55532. return result;
  55533. }
  55534. int PopupMenu::show (const int itemIdThatMustBeVisible,
  55535. const int minimumWidth,
  55536. const int maximumNumColumns,
  55537. const int standardItemHeight)
  55538. {
  55539. const Point<int> mousePos (Desktop::getMousePosition());
  55540. return showAt (mousePos.getX(), mousePos.getY(),
  55541. itemIdThatMustBeVisible,
  55542. minimumWidth,
  55543. maximumNumColumns,
  55544. standardItemHeight);
  55545. }
  55546. int PopupMenu::showAt (const int screenX,
  55547. const int screenY,
  55548. const int itemIdThatMustBeVisible,
  55549. const int minimumWidth,
  55550. const int maximumNumColumns,
  55551. const int standardItemHeight)
  55552. {
  55553. return showMenu (screenX, screenY, 1, 1,
  55554. itemIdThatMustBeVisible,
  55555. minimumWidth, maximumNumColumns,
  55556. standardItemHeight,
  55557. false, 0);
  55558. }
  55559. int PopupMenu::showAt (Component* componentToAttachTo,
  55560. const int itemIdThatMustBeVisible,
  55561. const int minimumWidth,
  55562. const int maximumNumColumns,
  55563. const int standardItemHeight)
  55564. {
  55565. if (componentToAttachTo != 0)
  55566. {
  55567. return showMenu (componentToAttachTo->getScreenX(),
  55568. componentToAttachTo->getScreenY(),
  55569. componentToAttachTo->getWidth(),
  55570. componentToAttachTo->getHeight(),
  55571. itemIdThatMustBeVisible,
  55572. minimumWidth,
  55573. maximumNumColumns,
  55574. standardItemHeight,
  55575. true, componentToAttachTo);
  55576. }
  55577. else
  55578. {
  55579. return show (itemIdThatMustBeVisible,
  55580. minimumWidth,
  55581. maximumNumColumns,
  55582. standardItemHeight);
  55583. }
  55584. }
  55585. void JUCE_CALLTYPE PopupMenu::dismissAllActiveMenus()
  55586. {
  55587. for (int i = Window::getActiveWindows().size(); --i >= 0;)
  55588. {
  55589. Window* const pmw = Window::getActiveWindows()[i];
  55590. if (pmw != 0)
  55591. pmw->dismissMenu (0);
  55592. }
  55593. }
  55594. int PopupMenu::getNumItems() const throw()
  55595. {
  55596. int num = 0;
  55597. for (int i = items.size(); --i >= 0;)
  55598. if (! (items.getUnchecked(i))->isSeparator)
  55599. ++num;
  55600. return num;
  55601. }
  55602. bool PopupMenu::containsCommandItem (const int commandID) const
  55603. {
  55604. for (int i = items.size(); --i >= 0;)
  55605. {
  55606. const Item* mi = items.getUnchecked (i);
  55607. if ((mi->itemId == commandID && mi->commandManager != 0)
  55608. || (mi->subMenu != 0 && mi->subMenu->containsCommandItem (commandID)))
  55609. {
  55610. return true;
  55611. }
  55612. }
  55613. return false;
  55614. }
  55615. bool PopupMenu::containsAnyActiveItems() const throw()
  55616. {
  55617. for (int i = items.size(); --i >= 0;)
  55618. {
  55619. const Item* const mi = items.getUnchecked (i);
  55620. if (mi->subMenu != 0)
  55621. {
  55622. if (mi->subMenu->containsAnyActiveItems())
  55623. return true;
  55624. }
  55625. else if (mi->active)
  55626. {
  55627. return true;
  55628. }
  55629. }
  55630. return false;
  55631. }
  55632. void PopupMenu::setLookAndFeel (LookAndFeel* const newLookAndFeel)
  55633. {
  55634. lookAndFeel = newLookAndFeel;
  55635. }
  55636. PopupMenuCustomComponent::PopupMenuCustomComponent (const bool isTriggeredAutomatically_)
  55637. : isHighlighted (false),
  55638. isTriggeredAutomatically (isTriggeredAutomatically_)
  55639. {
  55640. }
  55641. PopupMenuCustomComponent::~PopupMenuCustomComponent()
  55642. {
  55643. }
  55644. void PopupMenuCustomComponent::triggerMenuItem()
  55645. {
  55646. PopupMenu::ItemComponent* const mic = dynamic_cast <PopupMenu::ItemComponent*> (getParentComponent());
  55647. if (mic != 0)
  55648. {
  55649. PopupMenu::Window* const pmw = dynamic_cast <PopupMenu::Window*> (mic->getParentComponent());
  55650. if (pmw != 0)
  55651. {
  55652. pmw->dismissMenu (&mic->itemInfo);
  55653. }
  55654. else
  55655. {
  55656. // something must have gone wrong with the component hierarchy if this happens..
  55657. jassertfalse
  55658. }
  55659. }
  55660. else
  55661. {
  55662. // why isn't this component inside a menu? Not much point triggering the item if
  55663. // there's no menu.
  55664. jassertfalse
  55665. }
  55666. }
  55667. PopupMenu::MenuItemIterator::MenuItemIterator (const PopupMenu& menu_)
  55668. : subMenu (0),
  55669. itemId (0),
  55670. isSeparator (false),
  55671. isTicked (false),
  55672. isEnabled (false),
  55673. isCustomComponent (false),
  55674. isSectionHeader (false),
  55675. customColour (0),
  55676. customImage (0),
  55677. menu (menu_),
  55678. index (0)
  55679. {
  55680. }
  55681. PopupMenu::MenuItemIterator::~MenuItemIterator()
  55682. {
  55683. }
  55684. bool PopupMenu::MenuItemIterator::next()
  55685. {
  55686. if (index >= menu.items.size())
  55687. return false;
  55688. const Item* const item = menu.items.getUnchecked (index);
  55689. ++index;
  55690. itemName = item->customComp != 0 ? item->customComp->getName() : item->text;
  55691. subMenu = item->subMenu;
  55692. itemId = item->itemId;
  55693. isSeparator = item->isSeparator;
  55694. isTicked = item->isTicked;
  55695. isEnabled = item->active;
  55696. isSectionHeader = dynamic_cast <HeaderItemComponent*> ((PopupMenuCustomComponent*) item->customComp) != 0;
  55697. isCustomComponent = (! isSectionHeader) && item->customComp != 0;
  55698. customColour = item->usesColour ? &(item->textColour) : 0;
  55699. customImage = item->image;
  55700. commandManager = item->commandManager;
  55701. return true;
  55702. }
  55703. END_JUCE_NAMESPACE
  55704. /*** End of inlined file: juce_PopupMenu.cpp ***/
  55705. /*** Start of inlined file: juce_ComponentDragger.cpp ***/
  55706. BEGIN_JUCE_NAMESPACE
  55707. ComponentDragger::ComponentDragger()
  55708. : constrainer (0)
  55709. {
  55710. }
  55711. ComponentDragger::~ComponentDragger()
  55712. {
  55713. }
  55714. void ComponentDragger::startDraggingComponent (Component* const componentToDrag,
  55715. ComponentBoundsConstrainer* const constrainer_)
  55716. {
  55717. jassert (componentToDrag->isValidComponent());
  55718. if (componentToDrag != 0)
  55719. {
  55720. constrainer = constrainer_;
  55721. originalPos = componentToDrag->relativePositionToGlobal (Point<int>());
  55722. }
  55723. }
  55724. void ComponentDragger::dragComponent (Component* const componentToDrag, const MouseEvent& e)
  55725. {
  55726. jassert (componentToDrag->isValidComponent());
  55727. jassert (e.mods.isAnyMouseButtonDown()); // (the event has to be a drag event..)
  55728. if (componentToDrag != 0)
  55729. {
  55730. Rectangle<int> bounds (componentToDrag->getBounds().withPosition (originalPos));
  55731. const Component* const parentComp = componentToDrag->getParentComponent();
  55732. if (parentComp != 0)
  55733. bounds.setPosition (parentComp->globalPositionToRelative (originalPos));
  55734. bounds.setPosition (bounds.getPosition() + e.getOffsetFromDragStart());
  55735. if (constrainer != 0)
  55736. constrainer->setBoundsForComponent (componentToDrag, bounds, false, false, false, false);
  55737. else
  55738. componentToDrag->setBounds (bounds);
  55739. }
  55740. }
  55741. END_JUCE_NAMESPACE
  55742. /*** End of inlined file: juce_ComponentDragger.cpp ***/
  55743. /*** Start of inlined file: juce_DragAndDropContainer.cpp ***/
  55744. BEGIN_JUCE_NAMESPACE
  55745. bool juce_performDragDropFiles (const StringArray& files, const bool copyFiles, bool& shouldStop);
  55746. bool juce_performDragDropText (const String& text, bool& shouldStop);
  55747. class DragImageComponent : public Component,
  55748. public Timer
  55749. {
  55750. public:
  55751. DragImageComponent (Image* const im,
  55752. const String& desc,
  55753. Component* const sourceComponent,
  55754. Component* const mouseDragSource_,
  55755. DragAndDropContainer* const o,
  55756. const Point<int>& imageOffset_)
  55757. : image (im),
  55758. source (sourceComponent),
  55759. mouseDragSource (mouseDragSource_),
  55760. owner (o),
  55761. dragDesc (desc),
  55762. imageOffset (imageOffset_),
  55763. hasCheckedForExternalDrag (false),
  55764. drawImage (true)
  55765. {
  55766. setSize (im->getWidth(), im->getHeight());
  55767. if (mouseDragSource == 0)
  55768. mouseDragSource = source;
  55769. mouseDragSource->addMouseListener (this, false);
  55770. startTimer (200);
  55771. setInterceptsMouseClicks (false, false);
  55772. setAlwaysOnTop (true);
  55773. }
  55774. ~DragImageComponent()
  55775. {
  55776. if (owner->dragImageComponent == this)
  55777. owner->dragImageComponent.release();
  55778. if (mouseDragSource != 0)
  55779. {
  55780. mouseDragSource->removeMouseListener (this);
  55781. if (getCurrentlyOver() != 0 && getCurrentlyOver()->isInterestedInDragSource (dragDesc, source))
  55782. getCurrentlyOver()->itemDragExit (dragDesc, source);
  55783. }
  55784. }
  55785. void paint (Graphics& g)
  55786. {
  55787. if (isOpaque())
  55788. g.fillAll (Colours::white);
  55789. if (drawImage)
  55790. {
  55791. g.setOpacity (1.0f);
  55792. g.drawImageAt (image, 0, 0);
  55793. }
  55794. }
  55795. DragAndDropTarget* findTarget (const Point<int>& screenPos, Point<int>& relativePos)
  55796. {
  55797. Component* hit = getParentComponent();
  55798. if (hit == 0)
  55799. {
  55800. hit = Desktop::getInstance().findComponentAt (screenPos);
  55801. }
  55802. else
  55803. {
  55804. const Point<int> relPos (hit->globalPositionToRelative (screenPos));
  55805. hit = hit->getComponentAt (relPos.getX(), relPos.getY());
  55806. }
  55807. // (note: use a local copy of the dragDesc member in case the callback runs
  55808. // a modal loop and deletes this object before the method completes)
  55809. const String dragDescLocal (dragDesc);
  55810. while (hit != 0)
  55811. {
  55812. DragAndDropTarget* const ddt = dynamic_cast <DragAndDropTarget*> (hit);
  55813. if (ddt != 0 && ddt->isInterestedInDragSource (dragDescLocal, source))
  55814. {
  55815. relativePos = hit->globalPositionToRelative (screenPos);
  55816. return ddt;
  55817. }
  55818. hit = hit->getParentComponent();
  55819. }
  55820. return 0;
  55821. }
  55822. void mouseUp (const MouseEvent& e)
  55823. {
  55824. if (e.originalComponent != this)
  55825. {
  55826. if (mouseDragSource != 0)
  55827. mouseDragSource->removeMouseListener (this);
  55828. bool dropAccepted = false;
  55829. DragAndDropTarget* ddt = 0;
  55830. Point<int> relPos;
  55831. if (isVisible())
  55832. {
  55833. setVisible (false);
  55834. ddt = findTarget (e.getScreenPosition(), relPos);
  55835. // fade this component and remove it - it'll be deleted later by the timer callback
  55836. dropAccepted = ddt != 0;
  55837. setVisible (true);
  55838. if (dropAccepted || source == 0)
  55839. {
  55840. fadeOutComponent (120);
  55841. }
  55842. else
  55843. {
  55844. const Point<int> target (source->relativePositionToGlobal (Point<int> (source->getWidth() / 2,
  55845. source->getHeight() / 2)));
  55846. const Point<int> ourCentre (relativePositionToGlobal (Point<int> (getWidth() / 2,
  55847. getHeight() / 2)));
  55848. fadeOutComponent (120,
  55849. target.getX() - ourCentre.getX(),
  55850. target.getY() - ourCentre.getY());
  55851. }
  55852. }
  55853. if (getParentComponent() != 0)
  55854. getParentComponent()->removeChildComponent (this);
  55855. if (dropAccepted && ddt != 0)
  55856. {
  55857. // (note: use a local copy of the dragDesc member in case the callback runs
  55858. // a modal loop and deletes this object before the method completes)
  55859. const String dragDescLocal (dragDesc);
  55860. currentlyOverComp = 0;
  55861. ddt->itemDropped (dragDescLocal, source, relPos.getX(), relPos.getY());
  55862. }
  55863. // careful - this object could now be deleted..
  55864. }
  55865. }
  55866. void updateLocation (const bool canDoExternalDrag, const Point<int>& screenPos)
  55867. {
  55868. // (note: use a local copy of the dragDesc member in case the callback runs
  55869. // a modal loop and deletes this object before it returns)
  55870. const String dragDescLocal (dragDesc);
  55871. Point<int> newPos (screenPos + imageOffset);
  55872. if (getParentComponent() != 0)
  55873. newPos = getParentComponent()->globalPositionToRelative (newPos);
  55874. //if (newX != getX() || newY != getY())
  55875. {
  55876. setTopLeftPosition (newPos.getX(), newPos.getY());
  55877. Point<int> relPos;
  55878. DragAndDropTarget* const ddt = findTarget (screenPos, relPos);
  55879. Component* ddtComp = dynamic_cast <Component*> (ddt);
  55880. drawImage = (ddt == 0) || ddt->shouldDrawDragImageWhenOver();
  55881. if (ddtComp != currentlyOverComp)
  55882. {
  55883. if (currentlyOverComp != 0 && source != 0
  55884. && getCurrentlyOver()->isInterestedInDragSource (dragDescLocal, source))
  55885. {
  55886. getCurrentlyOver()->itemDragExit (dragDescLocal, source);
  55887. }
  55888. currentlyOverComp = ddtComp;
  55889. if (ddt != 0 && ddt->isInterestedInDragSource (dragDescLocal, source))
  55890. ddt->itemDragEnter (dragDescLocal, source, relPos.getX(), relPos.getY());
  55891. }
  55892. if (getCurrentlyOver() != 0 && getCurrentlyOver()->isInterestedInDragSource (dragDescLocal, source))
  55893. getCurrentlyOver()->itemDragMove (dragDescLocal, source, relPos.getX(), relPos.getY());
  55894. if (getCurrentlyOver() == 0
  55895. && canDoExternalDrag
  55896. && ! hasCheckedForExternalDrag)
  55897. {
  55898. if (Desktop::getInstance().findComponentAt (screenPos) == 0)
  55899. {
  55900. hasCheckedForExternalDrag = true;
  55901. StringArray files;
  55902. bool canMoveFiles = false;
  55903. if (owner->shouldDropFilesWhenDraggedExternally (dragDescLocal, source, files, canMoveFiles)
  55904. && files.size() > 0)
  55905. {
  55906. Component::SafePointer<Component> cdw (this);
  55907. setVisible (false);
  55908. if (ModifierKeys::getCurrentModifiersRealtime().isAnyMouseButtonDown())
  55909. DragAndDropContainer::performExternalDragDropOfFiles (files, canMoveFiles);
  55910. if (cdw != 0)
  55911. delete this;
  55912. return;
  55913. }
  55914. }
  55915. }
  55916. }
  55917. }
  55918. void mouseDrag (const MouseEvent& e)
  55919. {
  55920. if (e.originalComponent != this)
  55921. updateLocation (true, e.getScreenPosition());
  55922. }
  55923. void timerCallback()
  55924. {
  55925. if (source == 0)
  55926. {
  55927. delete this;
  55928. }
  55929. else if (! isMouseButtonDownAnywhere())
  55930. {
  55931. if (mouseDragSource != 0)
  55932. mouseDragSource->removeMouseListener (this);
  55933. delete this;
  55934. }
  55935. }
  55936. private:
  55937. ScopedPointer<Image> image;
  55938. Component::SafePointer<Component> source;
  55939. Component::SafePointer<Component> mouseDragSource;
  55940. DragAndDropContainer* const owner;
  55941. Component::SafePointer<Component> currentlyOverComp;
  55942. DragAndDropTarget* getCurrentlyOver()
  55943. {
  55944. return dynamic_cast <DragAndDropTarget*> (static_cast <Component*> (currentlyOverComp));
  55945. }
  55946. String dragDesc;
  55947. const Point<int> imageOffset;
  55948. bool hasCheckedForExternalDrag, drawImage;
  55949. DragImageComponent (const DragImageComponent&);
  55950. DragImageComponent& operator= (const DragImageComponent&);
  55951. };
  55952. DragAndDropContainer::DragAndDropContainer()
  55953. {
  55954. }
  55955. DragAndDropContainer::~DragAndDropContainer()
  55956. {
  55957. dragImageComponent = 0;
  55958. }
  55959. void DragAndDropContainer::startDragging (const String& sourceDescription,
  55960. Component* sourceComponent,
  55961. Image* dragImage_,
  55962. const bool allowDraggingToExternalWindows,
  55963. const Point<int>* imageOffsetFromMouse)
  55964. {
  55965. ScopedPointer <Image> dragImage (dragImage_);
  55966. if (dragImageComponent == 0)
  55967. {
  55968. Component* const thisComp = dynamic_cast <Component*> (this);
  55969. if (thisComp == 0)
  55970. {
  55971. jassertfalse; // Your DragAndDropContainer needs to be a Component!
  55972. return;
  55973. }
  55974. MouseInputSource* draggingSource = Desktop::getInstance().getDraggingMouseSource (0);
  55975. if (draggingSource == 0 || ! draggingSource->isDragging())
  55976. {
  55977. jassertfalse; // You must call startDragging() from within a mouseDown or mouseDrag callback!
  55978. return;
  55979. }
  55980. const Point<int> lastMouseDown (Desktop::getLastMouseDownPosition());
  55981. Point<int> imageOffset;
  55982. if (dragImage == 0)
  55983. {
  55984. dragImage = sourceComponent->createComponentSnapshot (Rectangle<int> (0, 0, sourceComponent->getWidth(), sourceComponent->getHeight()));
  55985. if (dragImage->getFormat() != Image::ARGB)
  55986. {
  55987. Image* newIm = Image::createNativeImage (Image::ARGB, dragImage->getWidth(), dragImage->getHeight(), true);
  55988. Graphics g2 (*newIm);
  55989. g2.drawImageAt (dragImage, 0, 0);
  55990. dragImage = newIm;
  55991. }
  55992. dragImage->multiplyAllAlphas (0.6f);
  55993. const int lo = 150;
  55994. const int hi = 400;
  55995. Point<int> relPos (sourceComponent->globalPositionToRelative (lastMouseDown));
  55996. Point<int> clipped (Rectangle<int> (0, 0, dragImage->getWidth(), dragImage->getHeight())
  55997. .getConstrainedPoint (relPos));
  55998. for (int y = dragImage->getHeight(); --y >= 0;)
  55999. {
  56000. const double dy = (y - clipped.getY()) * (y - clipped.getY());
  56001. for (int x = dragImage->getWidth(); --x >= 0;)
  56002. {
  56003. const int dx = x - clipped.getX();
  56004. const int distance = roundToInt (sqrt (dx * dx + dy));
  56005. if (distance > lo)
  56006. {
  56007. const float alpha = (distance > hi) ? 0
  56008. : (hi - distance) / (float) (hi - lo)
  56009. + Random::getSystemRandom().nextFloat() * 0.008f;
  56010. dragImage->multiplyAlphaAt (x, y, alpha);
  56011. }
  56012. }
  56013. }
  56014. imageOffset = -clipped;
  56015. }
  56016. else
  56017. {
  56018. if (imageOffsetFromMouse == 0)
  56019. imageOffset = Point<int> (dragImage->getWidth() / -2,
  56020. dragImage->getHeight() / -2);
  56021. else
  56022. imageOffset = *imageOffsetFromMouse;
  56023. }
  56024. dragImageComponent = new DragImageComponent (dragImage.release(), sourceDescription, sourceComponent,
  56025. draggingSource->getComponentUnderMouse(), this, imageOffset);
  56026. currentDragDesc = sourceDescription;
  56027. if (allowDraggingToExternalWindows)
  56028. {
  56029. if (! Desktop::canUseSemiTransparentWindows())
  56030. dragImageComponent->setOpaque (true);
  56031. dragImageComponent->addToDesktop (ComponentPeer::windowIgnoresMouseClicks
  56032. | ComponentPeer::windowIsTemporary
  56033. | ComponentPeer::windowIgnoresKeyPresses);
  56034. }
  56035. else
  56036. thisComp->addChildComponent (dragImageComponent);
  56037. static_cast <DragImageComponent*> (static_cast <Component*> (dragImageComponent))->updateLocation (false, lastMouseDown);
  56038. dragImageComponent->setVisible (true);
  56039. }
  56040. }
  56041. bool DragAndDropContainer::isDragAndDropActive() const
  56042. {
  56043. return dragImageComponent != 0;
  56044. }
  56045. const String DragAndDropContainer::getCurrentDragDescription() const
  56046. {
  56047. return (dragImageComponent != 0) ? currentDragDesc
  56048. : String::empty;
  56049. }
  56050. DragAndDropContainer* DragAndDropContainer::findParentDragContainerFor (Component* c)
  56051. {
  56052. if (c == 0)
  56053. return 0;
  56054. // (unable to use the syntax findParentComponentOfClass <DragAndDropContainer> () because of a VC6 compiler bug)
  56055. return c->findParentComponentOfClass ((DragAndDropContainer*) 0);
  56056. }
  56057. bool DragAndDropContainer::shouldDropFilesWhenDraggedExternally (const String&, Component*, StringArray&, bool&)
  56058. {
  56059. return false;
  56060. }
  56061. void DragAndDropTarget::itemDragEnter (const String&, Component*, int, int)
  56062. {
  56063. }
  56064. void DragAndDropTarget::itemDragMove (const String&, Component*, int, int)
  56065. {
  56066. }
  56067. void DragAndDropTarget::itemDragExit (const String&, Component*)
  56068. {
  56069. }
  56070. bool DragAndDropTarget::shouldDrawDragImageWhenOver()
  56071. {
  56072. return true;
  56073. }
  56074. void FileDragAndDropTarget::fileDragEnter (const StringArray&, int, int)
  56075. {
  56076. }
  56077. void FileDragAndDropTarget::fileDragMove (const StringArray&, int, int)
  56078. {
  56079. }
  56080. void FileDragAndDropTarget::fileDragExit (const StringArray&)
  56081. {
  56082. }
  56083. END_JUCE_NAMESPACE
  56084. /*** End of inlined file: juce_DragAndDropContainer.cpp ***/
  56085. /*** Start of inlined file: juce_MouseCursor.cpp ***/
  56086. BEGIN_JUCE_NAMESPACE
  56087. void* juce_createMouseCursorFromImage (const Image& image, int hotspotX, int hotspotY) throw();
  56088. void* juce_createStandardMouseCursor (MouseCursor::StandardCursorType type) throw();
  56089. // isStandard set depending on which interface was used to create the cursor
  56090. void juce_deleteMouseCursor (void* const cursorHandle, const bool isStandard) throw();
  56091. static CriticalSection activeCursorListLock;
  56092. static VoidArray activeCursors;
  56093. class SharedMouseCursorInternal : public ReferenceCountedObject
  56094. {
  56095. public:
  56096. SharedMouseCursorInternal (const MouseCursor::StandardCursorType type) throw()
  56097. : standardType (type),
  56098. isStandard (true)
  56099. {
  56100. handle = juce_createStandardMouseCursor (standardType);
  56101. activeCursors.add (this);
  56102. }
  56103. SharedMouseCursorInternal (const Image& image, const int hotSpotX, const int hotSpotY) throw()
  56104. : standardType (MouseCursor::NormalCursor),
  56105. isStandard (false)
  56106. {
  56107. handle = juce_createMouseCursorFromImage (image, hotSpotX, hotSpotY);
  56108. }
  56109. ~SharedMouseCursorInternal() throw()
  56110. {
  56111. juce_deleteMouseCursor (handle, isStandard);
  56112. activeCursors.removeValue (this);
  56113. }
  56114. void* getHandle() const throw()
  56115. {
  56116. return handle;
  56117. }
  56118. static SharedMouseCursorInternal* findInstance (MouseCursor::StandardCursorType type) throw()
  56119. {
  56120. for (int i = activeCursors.size(); --i >= 0;)
  56121. {
  56122. SharedMouseCursorInternal* const r = (SharedMouseCursorInternal*) activeCursors.getUnchecked(i);
  56123. if (r->standardType == type)
  56124. return r;
  56125. }
  56126. return new SharedMouseCursorInternal (type);
  56127. }
  56128. juce_UseDebuggingNewOperator
  56129. private:
  56130. void* handle;
  56131. const MouseCursor::StandardCursorType standardType;
  56132. const bool isStandard;
  56133. SharedMouseCursorInternal& operator= (const SharedMouseCursorInternal&);
  56134. };
  56135. MouseCursor::MouseCursor() throw()
  56136. {
  56137. const ScopedLock sl (activeCursorListLock);
  56138. cursorHandle = SharedMouseCursorInternal::findInstance (NormalCursor);
  56139. }
  56140. MouseCursor::MouseCursor (const StandardCursorType type) throw()
  56141. {
  56142. const ScopedLock sl (activeCursorListLock);
  56143. cursorHandle = SharedMouseCursorInternal::findInstance (type);
  56144. }
  56145. MouseCursor::MouseCursor (const Image& image, const int hotSpotX, const int hotSpotY) throw()
  56146. {
  56147. const ScopedLock sl (activeCursorListLock);
  56148. cursorHandle = new SharedMouseCursorInternal (image, hotSpotX, hotSpotY);
  56149. }
  56150. MouseCursor::MouseCursor (const MouseCursor& other) throw()
  56151. : cursorHandle (other.cursorHandle)
  56152. {
  56153. }
  56154. MouseCursor::~MouseCursor() throw()
  56155. {
  56156. }
  56157. MouseCursor& MouseCursor::operator= (const MouseCursor& other) throw()
  56158. {
  56159. cursorHandle = other.cursorHandle;
  56160. return *this;
  56161. }
  56162. bool MouseCursor::operator== (const MouseCursor& other) const throw()
  56163. {
  56164. return cursorHandle == other.cursorHandle;
  56165. }
  56166. bool MouseCursor::operator!= (const MouseCursor& other) const throw()
  56167. {
  56168. return cursorHandle != other.cursorHandle;
  56169. }
  56170. void* MouseCursor::getHandle() const throw()
  56171. {
  56172. return cursorHandle->getHandle();
  56173. }
  56174. void MouseCursor::showWaitCursor() throw()
  56175. {
  56176. Desktop::getInstance().getMainMouseSource().showMouseCursor (MouseCursor::WaitCursor);
  56177. }
  56178. void MouseCursor::hideWaitCursor() throw()
  56179. {
  56180. Desktop::getInstance().getMainMouseSource().revealCursor();
  56181. }
  56182. END_JUCE_NAMESPACE
  56183. /*** End of inlined file: juce_MouseCursor.cpp ***/
  56184. /*** Start of inlined file: juce_MouseEvent.cpp ***/
  56185. BEGIN_JUCE_NAMESPACE
  56186. MouseEvent::MouseEvent (MouseInputSource& source_,
  56187. const Point<int>& position,
  56188. const ModifierKeys& mods_,
  56189. Component* const originator,
  56190. const Time& eventTime_,
  56191. const Point<int> mouseDownPos_,
  56192. const Time& mouseDownTime_,
  56193. const int numberOfClicks_,
  56194. const bool mouseWasDragged) throw()
  56195. : x (position.getX()),
  56196. y (position.getY()),
  56197. mods (mods_),
  56198. eventComponent (originator),
  56199. originalComponent (originator),
  56200. eventTime (eventTime_),
  56201. source (source_),
  56202. mouseDownPos (mouseDownPos_),
  56203. mouseDownTime (mouseDownTime_),
  56204. numberOfClicks (numberOfClicks_),
  56205. wasMovedSinceMouseDown (mouseWasDragged)
  56206. {
  56207. }
  56208. MouseEvent::~MouseEvent() throw()
  56209. {
  56210. }
  56211. const MouseEvent MouseEvent::getEventRelativeTo (Component* const otherComponent) const throw()
  56212. {
  56213. if (otherComponent == 0)
  56214. {
  56215. jassertfalse
  56216. return *this;
  56217. }
  56218. return MouseEvent (source, eventComponent->relativePositionToOtherComponent (otherComponent, getPosition()),
  56219. mods, originalComponent, eventTime,
  56220. eventComponent->relativePositionToOtherComponent (otherComponent, mouseDownPos),
  56221. mouseDownTime, numberOfClicks, wasMovedSinceMouseDown);
  56222. }
  56223. const MouseEvent MouseEvent::withNewPosition (const Point<int>& newPosition) const throw()
  56224. {
  56225. return MouseEvent (source, newPosition, mods, originalComponent,
  56226. eventTime, mouseDownPos, mouseDownTime,
  56227. numberOfClicks, wasMovedSinceMouseDown);
  56228. }
  56229. bool MouseEvent::mouseWasClicked() const throw()
  56230. {
  56231. return ! wasMovedSinceMouseDown;
  56232. }
  56233. int MouseEvent::getMouseDownX() const throw()
  56234. {
  56235. return mouseDownPos.getX();
  56236. }
  56237. int MouseEvent::getMouseDownY() const throw()
  56238. {
  56239. return mouseDownPos.getY();
  56240. }
  56241. const Point<int> MouseEvent::getMouseDownPosition() const throw()
  56242. {
  56243. return mouseDownPos;
  56244. }
  56245. int MouseEvent::getDistanceFromDragStartX() const throw()
  56246. {
  56247. return x - mouseDownPos.getX();
  56248. }
  56249. int MouseEvent::getDistanceFromDragStartY() const throw()
  56250. {
  56251. return y - mouseDownPos.getY();
  56252. }
  56253. int MouseEvent::getDistanceFromDragStart() const throw()
  56254. {
  56255. return mouseDownPos.getDistanceFrom (getPosition());
  56256. }
  56257. const Point<int> MouseEvent::getOffsetFromDragStart() const throw()
  56258. {
  56259. return getPosition() - mouseDownPos;
  56260. }
  56261. int MouseEvent::getLengthOfMousePress() const throw()
  56262. {
  56263. if (mouseDownTime.toMilliseconds() > 0)
  56264. return jmax (0, (int) (eventTime - mouseDownTime).inMilliseconds());
  56265. return 0;
  56266. }
  56267. const Point<int> MouseEvent::getPosition() const throw()
  56268. {
  56269. return Point<int> (x, y);
  56270. }
  56271. int MouseEvent::getScreenX() const
  56272. {
  56273. return getScreenPosition().getX();
  56274. }
  56275. int MouseEvent::getScreenY() const
  56276. {
  56277. return getScreenPosition().getY();
  56278. }
  56279. const Point<int> MouseEvent::getScreenPosition() const
  56280. {
  56281. return eventComponent->relativePositionToGlobal (Point<int> (x, y));
  56282. }
  56283. int MouseEvent::getMouseDownScreenX() const
  56284. {
  56285. return getMouseDownScreenPosition().getX();
  56286. }
  56287. int MouseEvent::getMouseDownScreenY() const
  56288. {
  56289. return getMouseDownScreenPosition().getY();
  56290. }
  56291. const Point<int> MouseEvent::getMouseDownScreenPosition() const
  56292. {
  56293. return eventComponent->relativePositionToGlobal (mouseDownPos);
  56294. }
  56295. static int doubleClickTimeOutMs = 400;
  56296. void MouseEvent::setDoubleClickTimeout (const int newTime) throw()
  56297. {
  56298. doubleClickTimeOutMs = newTime;
  56299. }
  56300. int MouseEvent::getDoubleClickTimeout() throw()
  56301. {
  56302. return doubleClickTimeOutMs;
  56303. }
  56304. END_JUCE_NAMESPACE
  56305. /*** End of inlined file: juce_MouseEvent.cpp ***/
  56306. /*** Start of inlined file: juce_MouseInputSource.cpp ***/
  56307. BEGIN_JUCE_NAMESPACE
  56308. class MouseInputSourceInternal : public AsyncUpdater
  56309. {
  56310. public:
  56311. MouseInputSourceInternal (MouseInputSource& source_, const int index_, const bool isMouseDevice_)
  56312. : index (index_), isMouseDevice (isMouseDevice_), source (source_), lastPeer (0), lastTime (0),
  56313. isUnboundedMouseModeOn (false), isCursorVisibleUntilOffscreen (false), currentCursorHandle (0)
  56314. {
  56315. zerostruct (mouseDowns);
  56316. }
  56317. ~MouseInputSourceInternal()
  56318. {
  56319. }
  56320. bool isDragging() const throw()
  56321. {
  56322. return buttonState.isAnyMouseButtonDown();
  56323. }
  56324. Component* getComponentUnderMouse() const
  56325. {
  56326. return static_cast <Component*> (componentUnderMouse);
  56327. }
  56328. const ModifierKeys getCurrentModifiers() const
  56329. {
  56330. return ModifierKeys::getCurrentModifiers().withoutMouseButtons().withFlags (buttonState.getRawFlags());
  56331. }
  56332. ComponentPeer* getPeer()
  56333. {
  56334. if (! ComponentPeer::isValidPeer (lastPeer))
  56335. lastPeer = 0;
  56336. return lastPeer;
  56337. }
  56338. Component* findComponentAt (const Point<int>& screenPos)
  56339. {
  56340. ComponentPeer* const peer = getPeer();
  56341. if (peer != 0)
  56342. {
  56343. Component* const comp = peer->getComponent();
  56344. const Point<int> relativePos (comp->globalPositionToRelative (screenPos));
  56345. // (the contains() call is needed to test for overlapping desktop windows)
  56346. if (comp->contains (relativePos.getX(), relativePos.getY()))
  56347. return comp->getComponentAt (relativePos);
  56348. }
  56349. return 0;
  56350. }
  56351. const Point<int> getScreenPosition() const throw()
  56352. {
  56353. return lastScreenPos + unboundedMouseOffset;
  56354. }
  56355. void sendMouseEnter (Component* const comp, const Point<int>& screenPos, const int64 time)
  56356. {
  56357. //DBG ("Mouse " + String (source.getIndex()) + " enter: " + comp->globalPositionToRelative (screenPos).toString() + " - Comp: " + String::toHexString ((int) comp));
  56358. comp->internalMouseEnter (source, comp->globalPositionToRelative (screenPos), time);
  56359. }
  56360. void sendMouseExit (Component* const comp, const Point<int>& screenPos, const int64 time)
  56361. {
  56362. //DBG ("Mouse " + String (source.getIndex()) + " exit: " + comp->globalPositionToRelative (screenPos).toString() + " - Comp: " + String::toHexString ((int) comp));
  56363. comp->internalMouseExit (source, comp->globalPositionToRelative (screenPos), time);
  56364. }
  56365. void sendMouseMove (Component* const comp, const Point<int>& screenPos, const int64 time)
  56366. {
  56367. //DBG ("Mouse " + String (source.getIndex()) + " move: " + comp->globalPositionToRelative (screenPos).toString() + " - Comp: " + String::toHexString ((int) comp));
  56368. comp->internalMouseMove (source, comp->globalPositionToRelative (screenPos), time);
  56369. }
  56370. void sendMouseDown (Component* const comp, const Point<int>& screenPos, const int64 time)
  56371. {
  56372. //DBG ("Mouse " + String (source.getIndex()) + " down: " + comp->globalPositionToRelative (screenPos).toString() + " - Comp: " + String::toHexString ((int) comp));
  56373. comp->internalMouseDown (source, comp->globalPositionToRelative (screenPos), time);
  56374. }
  56375. void sendMouseDrag (Component* const comp, const Point<int>& screenPos, const int64 time)
  56376. {
  56377. //DBG ("Mouse " + String (source.getIndex()) + " drag: " + comp->globalPositionToRelative (screenPos).toString() + " - Comp: " + String::toHexString ((int) comp));
  56378. comp->internalMouseDrag (source, comp->globalPositionToRelative (screenPos), time);
  56379. }
  56380. void sendMouseUp (Component* const comp, const Point<int>& screenPos, const int64 time)
  56381. {
  56382. //DBG ("Mouse " + String (source.getIndex()) + " up: " + comp->globalPositionToRelative (screenPos).toString() + " - Comp: " + String::toHexString ((int) comp));
  56383. comp->internalMouseUp (source, comp->globalPositionToRelative (screenPos), time, getCurrentModifiers());
  56384. }
  56385. void sendMouseWheel (Component* const comp, const Point<int>& screenPos, const int64 time, float x, float y)
  56386. {
  56387. //DBG ("Mouse " + String (source.getIndex()) + " wheel: " + comp->globalPositionToRelative (screenPos).toString() + " - Comp: " + String::toHexString ((int) comp));
  56388. comp->internalMouseWheel (source, comp->globalPositionToRelative (screenPos), time, x, y);
  56389. }
  56390. void setButtons (const Point<int>& screenPos, const int64 time, const ModifierKeys& newButtonState)
  56391. {
  56392. if (buttonState != newButtonState)
  56393. {
  56394. // (ignore secondary clicks when there's already a button down)
  56395. if (buttonState.isAnyMouseButtonDown() == newButtonState.isAnyMouseButtonDown())
  56396. {
  56397. buttonState = newButtonState;
  56398. return;
  56399. }
  56400. if (buttonState.isAnyMouseButtonDown())
  56401. {
  56402. Component* const current = getComponentUnderMouse();
  56403. if (current != 0)
  56404. sendMouseUp (current, screenPos + unboundedMouseOffset, time);
  56405. enableUnboundedMouseMovement (false, false);
  56406. }
  56407. buttonState = newButtonState;
  56408. if (buttonState.isAnyMouseButtonDown())
  56409. {
  56410. Desktop::getInstance().incrementMouseClickCounter();
  56411. Component* const current = getComponentUnderMouse();
  56412. if (current != 0)
  56413. {
  56414. registerMouseDown (screenPos, time, current);
  56415. sendMouseDown (current, screenPos, time);
  56416. }
  56417. }
  56418. }
  56419. }
  56420. void setComponentUnderMouse (Component* const newComponent, const Point<int>& screenPos, const int64 time)
  56421. {
  56422. Component* current = getComponentUnderMouse();
  56423. if (newComponent != current)
  56424. {
  56425. Component::SafePointer<Component> safeNewComp (newComponent);
  56426. const ModifierKeys originalButtonState (buttonState);
  56427. if (current != 0)
  56428. {
  56429. setButtons (screenPos, time, ModifierKeys());
  56430. sendMouseExit (current, screenPos, time);
  56431. buttonState = originalButtonState;
  56432. }
  56433. componentUnderMouse = safeNewComp;
  56434. current = getComponentUnderMouse();
  56435. if (current != 0)
  56436. sendMouseEnter (current, screenPos, time);
  56437. revealCursor (false);
  56438. setButtons (screenPos, time, originalButtonState);
  56439. }
  56440. }
  56441. void setPeer (ComponentPeer* const newPeer, const Point<int>& screenPos, const int64 time)
  56442. {
  56443. ModifierKeys::updateCurrentModifiers();
  56444. if (newPeer != lastPeer)
  56445. {
  56446. setComponentUnderMouse (0, screenPos, time);
  56447. lastPeer = newPeer;
  56448. setComponentUnderMouse (findComponentAt (screenPos), screenPos, time);
  56449. }
  56450. }
  56451. void setScreenPos (const Point<int>& newScreenPos, const int64 time, const bool forceUpdate)
  56452. {
  56453. if (! isDragging())
  56454. setComponentUnderMouse (findComponentAt (newScreenPos), newScreenPos, time);
  56455. if (newScreenPos != lastScreenPos || forceUpdate)
  56456. {
  56457. cancelPendingUpdate();
  56458. lastScreenPos = newScreenPos;
  56459. Component* const current = getComponentUnderMouse();
  56460. if (current != 0)
  56461. {
  56462. if (isDragging())
  56463. {
  56464. registerMouseDrag (newScreenPos);
  56465. sendMouseDrag (current, newScreenPos + unboundedMouseOffset, time);
  56466. if (isUnboundedMouseModeOn)
  56467. handleUnboundedDrag (current);
  56468. }
  56469. else
  56470. {
  56471. sendMouseMove (current, newScreenPos, time);
  56472. }
  56473. }
  56474. revealCursor (false);
  56475. }
  56476. }
  56477. void handleEvent (ComponentPeer* const newPeer, const Point<int>& positionWithinPeer, const int64 time, const ModifierKeys& newMods)
  56478. {
  56479. jassert (newPeer != 0);
  56480. lastTime = time;
  56481. const Point<int> screenPos (newPeer->relativePositionToGlobal (positionWithinPeer));
  56482. if (isDragging() && newMods.isAnyMouseButtonDown())
  56483. {
  56484. setScreenPos (screenPos, time, false);
  56485. }
  56486. else
  56487. {
  56488. setPeer (newPeer, screenPos, time);
  56489. ComponentPeer* peer = getPeer();
  56490. if (peer != 0)
  56491. {
  56492. setButtons (screenPos, time, newMods);
  56493. peer = getPeer();
  56494. if (peer != 0)
  56495. setScreenPos (peer->relativePositionToGlobal (positionWithinPeer), time, false);
  56496. }
  56497. }
  56498. }
  56499. void handleWheel (ComponentPeer* const peer, const Point<int>& positionWithinPeer, int64 time, float x, float y)
  56500. {
  56501. jassert (peer != 0);
  56502. lastTime = time;
  56503. const Point<int> screenPos (peer->relativePositionToGlobal (positionWithinPeer));
  56504. setPeer (peer, screenPos, time);
  56505. setScreenPos (screenPos, time, false);
  56506. triggerFakeMove();
  56507. if (! isDragging())
  56508. {
  56509. Component* current = getComponentUnderMouse();
  56510. if (current != 0)
  56511. sendMouseWheel (current, screenPos, time, x, y);
  56512. }
  56513. }
  56514. const Time getLastMouseDownTime() const throw()
  56515. {
  56516. return Time (mouseDowns[0].time);
  56517. }
  56518. const Point<int> getLastMouseDownPosition() const throw()
  56519. {
  56520. return mouseDowns[0].position;
  56521. }
  56522. int getNumberOfMultipleClicks() const throw()
  56523. {
  56524. int numClicks = 0;
  56525. if (mouseDowns[0].time != 0)
  56526. {
  56527. if (! mouseMovedSignificantlySincePressed)
  56528. ++numClicks;
  56529. for (int i = 1; i < numElementsInArray (mouseDowns); ++i)
  56530. {
  56531. if (mouseDowns[0].time - mouseDowns[i].time < (int) (MouseEvent::getDoubleClickTimeout() * (1.0 + 0.25 * (i - 1)))
  56532. && abs (mouseDowns[0].position.getX() - mouseDowns[i].position.getX()) < 8
  56533. && abs (mouseDowns[0].position.getY() - mouseDowns[i].position.getY()) < 8
  56534. && mouseDowns[0].component == mouseDowns[i].component)
  56535. {
  56536. ++numClicks;
  56537. }
  56538. else
  56539. {
  56540. break;
  56541. }
  56542. }
  56543. }
  56544. return numClicks;
  56545. }
  56546. bool hasMouseMovedSignificantlySincePressed() const throw()
  56547. {
  56548. return mouseMovedSignificantlySincePressed
  56549. || lastTime > mouseDowns[0].time + 300;
  56550. }
  56551. void triggerFakeMove()
  56552. {
  56553. triggerAsyncUpdate();
  56554. }
  56555. void handleAsyncUpdate()
  56556. {
  56557. if (! isDragging())
  56558. setScreenPos (Desktop::getMousePosition(), jmax (lastTime, Time::currentTimeMillis()), true);
  56559. }
  56560. void enableUnboundedMouseMovement (bool enable, bool keepCursorVisibleUntilOffscreen)
  56561. {
  56562. enable = enable && isDragging();
  56563. isCursorVisibleUntilOffscreen = keepCursorVisibleUntilOffscreen;
  56564. if (enable != isUnboundedMouseModeOn)
  56565. {
  56566. if ((! enable) && ((! isCursorVisibleUntilOffscreen) || ! unboundedMouseOffset.isOrigin()))
  56567. {
  56568. // when released, return the mouse to within the component's bounds
  56569. Component* current = getComponentUnderMouse();
  56570. if (current != 0)
  56571. Desktop::setMousePosition (current->getScreenBounds()
  56572. .getConstrainedPoint (current->getMouseXYRelative()));
  56573. }
  56574. isUnboundedMouseModeOn = enable;
  56575. unboundedMouseOffset = Point<int>();
  56576. revealCursor (true);
  56577. }
  56578. }
  56579. void handleUnboundedDrag (Component* current)
  56580. {
  56581. const Rectangle<int> screenArea (current->getParentMonitorArea().expanded (-2, -2));
  56582. if (! screenArea.contains (lastScreenPos))
  56583. {
  56584. const Point<int> componentCentre (current->getScreenBounds().getCentre());
  56585. unboundedMouseOffset += (lastScreenPos - componentCentre);
  56586. Desktop::setMousePosition (componentCentre);
  56587. }
  56588. else if (isCursorVisibleUntilOffscreen
  56589. && (! unboundedMouseOffset.isOrigin())
  56590. && screenArea.contains (lastScreenPos + unboundedMouseOffset))
  56591. {
  56592. Desktop::setMousePosition (lastScreenPos + unboundedMouseOffset);
  56593. unboundedMouseOffset = Point<int>();
  56594. }
  56595. }
  56596. void showMouseCursor (MouseCursor cursor, bool forcedUpdate)
  56597. {
  56598. if (isUnboundedMouseModeOn && ((! unboundedMouseOffset.isOrigin()) || ! isCursorVisibleUntilOffscreen))
  56599. {
  56600. cursor = MouseCursor::NoCursor;
  56601. forcedUpdate = true;
  56602. }
  56603. if (forcedUpdate || cursor.getHandle() != currentCursorHandle)
  56604. {
  56605. currentCursorHandle = cursor.getHandle();
  56606. cursor.showInWindow (getPeer());
  56607. }
  56608. }
  56609. void hideCursor()
  56610. {
  56611. showMouseCursor (MouseCursor::NoCursor, true);
  56612. }
  56613. void revealCursor (bool forcedUpdate)
  56614. {
  56615. MouseCursor mc (MouseCursor::NormalCursor);
  56616. Component* current = getComponentUnderMouse();
  56617. if (current != 0)
  56618. mc = current->getLookAndFeel().getMouseCursorFor (*current);
  56619. showMouseCursor (mc, forcedUpdate);
  56620. }
  56621. int index;
  56622. bool isMouseDevice;
  56623. Point<int> lastScreenPos;
  56624. ModifierKeys buttonState;
  56625. private:
  56626. MouseInputSource& source;
  56627. Component::SafePointer<Component> componentUnderMouse;
  56628. ComponentPeer* lastPeer;
  56629. Point<int> unboundedMouseOffset;
  56630. bool isUnboundedMouseModeOn, isCursorVisibleUntilOffscreen;
  56631. void* currentCursorHandle;
  56632. struct RecentMouseDown
  56633. {
  56634. Point<int> position;
  56635. int64 time;
  56636. Component* component;
  56637. };
  56638. RecentMouseDown mouseDowns[4];
  56639. bool mouseMovedSignificantlySincePressed;
  56640. int64 lastTime;
  56641. void registerMouseDown (const Point<int>& screenPos, const int64 time, Component* const component) throw()
  56642. {
  56643. for (int i = numElementsInArray (mouseDowns); --i > 0;)
  56644. mouseDowns[i] = mouseDowns[i - 1];
  56645. mouseDowns[0].position = screenPos;
  56646. mouseDowns[0].time = time;
  56647. mouseDowns[0].component = component;
  56648. mouseMovedSignificantlySincePressed = false;
  56649. }
  56650. void registerMouseDrag (const Point<int>& screenPos) throw()
  56651. {
  56652. mouseMovedSignificantlySincePressed = mouseMovedSignificantlySincePressed
  56653. || mouseDowns[0].position.getDistanceFrom (screenPos) >= 4;
  56654. }
  56655. };
  56656. MouseInputSource::MouseInputSource (const int index, const bool isMouseDevice)
  56657. {
  56658. pimpl = new MouseInputSourceInternal (*this, index, isMouseDevice);
  56659. }
  56660. MouseInputSource::~MouseInputSource()
  56661. {
  56662. }
  56663. bool MouseInputSource::isMouse() const { return pimpl->isMouseDevice; }
  56664. bool MouseInputSource::isTouch() const { return ! isMouse(); }
  56665. bool MouseInputSource::canHover() const { return isMouse(); }
  56666. bool MouseInputSource::hasMouseWheel() const { return isMouse(); }
  56667. int MouseInputSource::getIndex() const { return pimpl->index; }
  56668. bool MouseInputSource::isDragging() const { return pimpl->isDragging(); }
  56669. const Point<int> MouseInputSource::getScreenPosition() const { return pimpl->getScreenPosition(); }
  56670. const ModifierKeys MouseInputSource::getCurrentModifiers() const { return pimpl->getCurrentModifiers(); }
  56671. Component* MouseInputSource::getComponentUnderMouse() const { return pimpl->getComponentUnderMouse(); }
  56672. void MouseInputSource::triggerFakeMove() const { pimpl->triggerFakeMove(); }
  56673. int MouseInputSource::getNumberOfMultipleClicks() const throw() { return pimpl->getNumberOfMultipleClicks(); }
  56674. const Time MouseInputSource::getLastMouseDownTime() const throw() { return pimpl->getLastMouseDownTime(); }
  56675. const Point<int> MouseInputSource::getLastMouseDownPosition() const throw() { return pimpl->getLastMouseDownPosition(); }
  56676. bool MouseInputSource::hasMouseMovedSignificantlySincePressed() const throw() { return pimpl->hasMouseMovedSignificantlySincePressed(); }
  56677. bool MouseInputSource::canDoUnboundedMovement() const throw() { return isMouse(); }
  56678. void MouseInputSource::enableUnboundedMouseMovement (bool isEnabled, bool keepCursorVisibleUntilOffscreen) { pimpl->enableUnboundedMouseMovement (isEnabled, keepCursorVisibleUntilOffscreen); }
  56679. bool MouseInputSource::hasMouseCursor() const throw() { return isMouse(); }
  56680. void MouseInputSource::showMouseCursor (const MouseCursor& cursor) { pimpl->showMouseCursor (cursor, false); }
  56681. void MouseInputSource::hideCursor() { pimpl->hideCursor(); }
  56682. void MouseInputSource::revealCursor() { pimpl->revealCursor (false); }
  56683. void MouseInputSource::forceMouseCursorUpdate() { pimpl->revealCursor (true); }
  56684. void MouseInputSource::handleEvent (ComponentPeer* peer, const Point<int>& positionWithinPeer, const int64 time, const ModifierKeys& mods)
  56685. {
  56686. pimpl->handleEvent (peer, positionWithinPeer, time, mods.withOnlyMouseButtons());
  56687. }
  56688. void MouseInputSource::handleWheel (ComponentPeer* const peer, const Point<int>& positionWithinPeer, const int64 time, const float x, const float y)
  56689. {
  56690. pimpl->handleWheel (peer, positionWithinPeer, time, x, y);
  56691. }
  56692. END_JUCE_NAMESPACE
  56693. /*** End of inlined file: juce_MouseInputSource.cpp ***/
  56694. /*** Start of inlined file: juce_MouseHoverDetector.cpp ***/
  56695. BEGIN_JUCE_NAMESPACE
  56696. MouseHoverDetector::MouseHoverDetector (const int hoverTimeMillisecs_)
  56697. : source (0),
  56698. hoverTimeMillisecs (hoverTimeMillisecs_),
  56699. hasJustHovered (false)
  56700. {
  56701. internalTimer.owner = this;
  56702. }
  56703. MouseHoverDetector::~MouseHoverDetector()
  56704. {
  56705. setHoverComponent (0);
  56706. }
  56707. void MouseHoverDetector::setHoverTimeMillisecs (const int newTimeInMillisecs)
  56708. {
  56709. hoverTimeMillisecs = newTimeInMillisecs;
  56710. }
  56711. void MouseHoverDetector::setHoverComponent (Component* const newSourceComponent)
  56712. {
  56713. if (source != newSourceComponent)
  56714. {
  56715. internalTimer.stopTimer();
  56716. hasJustHovered = false;
  56717. if (source != 0)
  56718. {
  56719. // ! you need to delete the hover detector before deleting its component
  56720. jassert (source->isValidComponent());
  56721. source->removeMouseListener (&internalTimer);
  56722. }
  56723. source = newSourceComponent;
  56724. if (newSourceComponent != 0)
  56725. newSourceComponent->addMouseListener (&internalTimer, false);
  56726. }
  56727. }
  56728. void MouseHoverDetector::hoverTimerCallback()
  56729. {
  56730. internalTimer.stopTimer();
  56731. if (source != 0)
  56732. {
  56733. const Point<int> pos (source->getMouseXYRelative());
  56734. if (source->reallyContains (pos.getX(), pos.getY(), false))
  56735. {
  56736. hasJustHovered = true;
  56737. mouseHovered (pos.getX(), pos.getY());
  56738. }
  56739. }
  56740. }
  56741. void MouseHoverDetector::checkJustHoveredCallback()
  56742. {
  56743. if (hasJustHovered)
  56744. {
  56745. hasJustHovered = false;
  56746. mouseMovedAfterHover();
  56747. }
  56748. }
  56749. void MouseHoverDetector::HoverDetectorInternal::timerCallback()
  56750. {
  56751. owner->hoverTimerCallback();
  56752. }
  56753. void MouseHoverDetector::HoverDetectorInternal::mouseEnter (const MouseEvent&)
  56754. {
  56755. stopTimer();
  56756. owner->checkJustHoveredCallback();
  56757. }
  56758. void MouseHoverDetector::HoverDetectorInternal::mouseExit (const MouseEvent&)
  56759. {
  56760. stopTimer();
  56761. owner->checkJustHoveredCallback();
  56762. }
  56763. void MouseHoverDetector::HoverDetectorInternal::mouseDown (const MouseEvent&)
  56764. {
  56765. stopTimer();
  56766. owner->checkJustHoveredCallback();
  56767. }
  56768. void MouseHoverDetector::HoverDetectorInternal::mouseUp (const MouseEvent&)
  56769. {
  56770. stopTimer();
  56771. owner->checkJustHoveredCallback();
  56772. }
  56773. void MouseHoverDetector::HoverDetectorInternal::mouseMove (const MouseEvent& e)
  56774. {
  56775. if (lastX != e.x || lastY != e.y) // to avoid fake mouse-moves setting it off
  56776. {
  56777. lastX = e.x;
  56778. lastY = e.y;
  56779. if (owner->source != 0)
  56780. startTimer (owner->hoverTimeMillisecs);
  56781. owner->checkJustHoveredCallback();
  56782. }
  56783. }
  56784. void MouseHoverDetector::HoverDetectorInternal::mouseWheelMove (const MouseEvent&, float, float)
  56785. {
  56786. stopTimer();
  56787. owner->checkJustHoveredCallback();
  56788. }
  56789. END_JUCE_NAMESPACE
  56790. /*** End of inlined file: juce_MouseHoverDetector.cpp ***/
  56791. /*** Start of inlined file: juce_MouseListener.cpp ***/
  56792. BEGIN_JUCE_NAMESPACE
  56793. void MouseListener::mouseEnter (const MouseEvent&)
  56794. {
  56795. }
  56796. void MouseListener::mouseExit (const MouseEvent&)
  56797. {
  56798. }
  56799. void MouseListener::mouseDown (const MouseEvent&)
  56800. {
  56801. }
  56802. void MouseListener::mouseUp (const MouseEvent&)
  56803. {
  56804. }
  56805. void MouseListener::mouseDrag (const MouseEvent&)
  56806. {
  56807. }
  56808. void MouseListener::mouseMove (const MouseEvent&)
  56809. {
  56810. }
  56811. void MouseListener::mouseDoubleClick (const MouseEvent&)
  56812. {
  56813. }
  56814. void MouseListener::mouseWheelMove (const MouseEvent&, float, float)
  56815. {
  56816. }
  56817. END_JUCE_NAMESPACE
  56818. /*** End of inlined file: juce_MouseListener.cpp ***/
  56819. /*** Start of inlined file: juce_BooleanPropertyComponent.cpp ***/
  56820. BEGIN_JUCE_NAMESPACE
  56821. BooleanPropertyComponent::BooleanPropertyComponent (const String& name,
  56822. const String& buttonTextWhenTrue,
  56823. const String& buttonTextWhenFalse)
  56824. : PropertyComponent (name),
  56825. onText (buttonTextWhenTrue),
  56826. offText (buttonTextWhenFalse)
  56827. {
  56828. createButton();
  56829. button->addButtonListener (this);
  56830. }
  56831. BooleanPropertyComponent::BooleanPropertyComponent (const Value& valueToControl,
  56832. const String& name,
  56833. const String& buttonText)
  56834. : PropertyComponent (name),
  56835. onText (buttonText),
  56836. offText (buttonText)
  56837. {
  56838. createButton();
  56839. button->setButtonText (buttonText);
  56840. button->getToggleStateValue().referTo (valueToControl);
  56841. button->setClickingTogglesState (true);
  56842. }
  56843. BooleanPropertyComponent::~BooleanPropertyComponent()
  56844. {
  56845. deleteAllChildren();
  56846. }
  56847. void BooleanPropertyComponent::createButton()
  56848. {
  56849. addAndMakeVisible (button = new ToggleButton (String::empty));
  56850. button->setClickingTogglesState (false);
  56851. }
  56852. void BooleanPropertyComponent::setState (const bool newState)
  56853. {
  56854. button->setToggleState (newState, true);
  56855. }
  56856. bool BooleanPropertyComponent::getState() const
  56857. {
  56858. return button->getToggleState();
  56859. }
  56860. void BooleanPropertyComponent::paint (Graphics& g)
  56861. {
  56862. PropertyComponent::paint (g);
  56863. const Rectangle<int> r (button->getBounds());
  56864. g.setColour (Colours::white);
  56865. g.fillRect (r);
  56866. g.setColour (findColour (ComboBox::outlineColourId));
  56867. g.drawRect (r.getX(), r.getY(), r.getWidth(), r.getHeight());
  56868. }
  56869. void BooleanPropertyComponent::refresh()
  56870. {
  56871. button->setToggleState (getState(), false);
  56872. button->setButtonText (button->getToggleState() ? onText : offText);
  56873. }
  56874. void BooleanPropertyComponent::buttonClicked (Button*)
  56875. {
  56876. setState (! getState());
  56877. }
  56878. END_JUCE_NAMESPACE
  56879. /*** End of inlined file: juce_BooleanPropertyComponent.cpp ***/
  56880. /*** Start of inlined file: juce_ButtonPropertyComponent.cpp ***/
  56881. BEGIN_JUCE_NAMESPACE
  56882. ButtonPropertyComponent::ButtonPropertyComponent (const String& name,
  56883. const bool triggerOnMouseDown)
  56884. : PropertyComponent (name)
  56885. {
  56886. addAndMakeVisible (button = new TextButton (String::empty));
  56887. button->setTriggeredOnMouseDown (triggerOnMouseDown);
  56888. button->addButtonListener (this);
  56889. }
  56890. ButtonPropertyComponent::~ButtonPropertyComponent()
  56891. {
  56892. deleteAllChildren();
  56893. }
  56894. void ButtonPropertyComponent::refresh()
  56895. {
  56896. button->setButtonText (getButtonText());
  56897. }
  56898. void ButtonPropertyComponent::buttonClicked (Button*)
  56899. {
  56900. buttonClicked();
  56901. }
  56902. END_JUCE_NAMESPACE
  56903. /*** End of inlined file: juce_ButtonPropertyComponent.cpp ***/
  56904. /*** Start of inlined file: juce_ChoicePropertyComponent.cpp ***/
  56905. BEGIN_JUCE_NAMESPACE
  56906. ChoicePropertyComponent::ChoicePropertyComponent (const String& name)
  56907. : PropertyComponent (name),
  56908. comboBox (0)
  56909. {
  56910. }
  56911. ChoicePropertyComponent::ChoicePropertyComponent (const Value& valueToControl,
  56912. const String& name,
  56913. const StringArray& choices_,
  56914. const Array <int>* choiceIDs)
  56915. : PropertyComponent (name),
  56916. choices (choices_),
  56917. comboBox (0)
  56918. {
  56919. createComboBox (choiceIDs);
  56920. comboBox->getSelectedIdAsValue().referTo (valueToControl);
  56921. }
  56922. ChoicePropertyComponent::~ChoicePropertyComponent()
  56923. {
  56924. deleteAllChildren();
  56925. }
  56926. void ChoicePropertyComponent::createComboBox (const Array <int>* choiceIDs)
  56927. {
  56928. // The array of IDs must contain the same number of values as the choices list!
  56929. jassert (choiceIDs == 0 || choiceIDs->size() == choices.size());
  56930. addAndMakeVisible (comboBox = new ComboBox (String::empty));
  56931. for (int i = 0; i < choices.size(); ++i)
  56932. {
  56933. if (choices[i].isNotEmpty())
  56934. comboBox->addItem (choices[i], choiceIDs == 0 ? (i + 1)
  56935. : ((*choiceIDs)[i]));
  56936. else
  56937. comboBox->addSeparator();
  56938. }
  56939. comboBox->setEditableText (false);
  56940. }
  56941. void ChoicePropertyComponent::setIndex (const int newIndex)
  56942. {
  56943. comboBox->setSelectedId (comboBox->getItemId (newIndex));
  56944. }
  56945. int ChoicePropertyComponent::getIndex() const
  56946. {
  56947. return comboBox->getSelectedItemIndex();
  56948. }
  56949. const StringArray& ChoicePropertyComponent::getChoices() const
  56950. {
  56951. return choices;
  56952. }
  56953. void ChoicePropertyComponent::refresh()
  56954. {
  56955. if (comboBox == 0)
  56956. {
  56957. createComboBox (0);
  56958. comboBox->addListener (this);
  56959. }
  56960. comboBox->setSelectedId (getIndex() + 1, true);
  56961. }
  56962. void ChoicePropertyComponent::comboBoxChanged (ComboBox*)
  56963. {
  56964. const int newIndex = comboBox->getSelectedId() - 1;
  56965. if (newIndex != getIndex())
  56966. setIndex (newIndex);
  56967. }
  56968. END_JUCE_NAMESPACE
  56969. /*** End of inlined file: juce_ChoicePropertyComponent.cpp ***/
  56970. /*** Start of inlined file: juce_PropertyComponent.cpp ***/
  56971. BEGIN_JUCE_NAMESPACE
  56972. PropertyComponent::PropertyComponent (const String& name,
  56973. const int preferredHeight_)
  56974. : Component (name),
  56975. preferredHeight (preferredHeight_)
  56976. {
  56977. jassert (name.isNotEmpty());
  56978. }
  56979. PropertyComponent::~PropertyComponent()
  56980. {
  56981. }
  56982. void PropertyComponent::paint (Graphics& g)
  56983. {
  56984. getLookAndFeel().drawPropertyComponentBackground (g, getWidth(), getHeight(), *this);
  56985. getLookAndFeel().drawPropertyComponentLabel (g, getWidth(), getHeight(), *this);
  56986. }
  56987. void PropertyComponent::resized()
  56988. {
  56989. if (getNumChildComponents() > 0)
  56990. getChildComponent (0)->setBounds (getLookAndFeel().getPropertyComponentContentPosition (*this));
  56991. }
  56992. void PropertyComponent::enablementChanged()
  56993. {
  56994. repaint();
  56995. }
  56996. END_JUCE_NAMESPACE
  56997. /*** End of inlined file: juce_PropertyComponent.cpp ***/
  56998. /*** Start of inlined file: juce_PropertyPanel.cpp ***/
  56999. BEGIN_JUCE_NAMESPACE
  57000. class PropertyHolderComponent : public Component
  57001. {
  57002. public:
  57003. PropertyHolderComponent()
  57004. {
  57005. }
  57006. ~PropertyHolderComponent()
  57007. {
  57008. deleteAllChildren();
  57009. }
  57010. void paint (Graphics&)
  57011. {
  57012. }
  57013. void updateLayout (const int width);
  57014. void refreshAll() const;
  57015. };
  57016. class PropertySectionComponent : public Component
  57017. {
  57018. public:
  57019. PropertySectionComponent (const String& sectionTitle,
  57020. const Array <PropertyComponent*>& newProperties,
  57021. const bool open)
  57022. : Component (sectionTitle),
  57023. titleHeight (sectionTitle.isNotEmpty() ? 22 : 0),
  57024. isOpen_ (open)
  57025. {
  57026. for (int i = newProperties.size(); --i >= 0;)
  57027. {
  57028. addAndMakeVisible (newProperties.getUnchecked(i));
  57029. newProperties.getUnchecked(i)->refresh();
  57030. }
  57031. }
  57032. ~PropertySectionComponent()
  57033. {
  57034. deleteAllChildren();
  57035. }
  57036. void paint (Graphics& g)
  57037. {
  57038. if (titleHeight > 0)
  57039. getLookAndFeel().drawPropertyPanelSectionHeader (g, getName(), isOpen(), getWidth(), titleHeight);
  57040. }
  57041. void resized()
  57042. {
  57043. int y = titleHeight;
  57044. for (int i = getNumChildComponents(); --i >= 0;)
  57045. {
  57046. PropertyComponent* const pec = dynamic_cast <PropertyComponent*> (getChildComponent (i));
  57047. if (pec != 0)
  57048. {
  57049. const int prefH = pec->getPreferredHeight();
  57050. pec->setBounds (1, y, getWidth() - 2, prefH);
  57051. y += prefH;
  57052. }
  57053. }
  57054. }
  57055. int getPreferredHeight() const
  57056. {
  57057. int y = titleHeight;
  57058. if (isOpen())
  57059. {
  57060. for (int i = 0; i < getNumChildComponents(); ++i)
  57061. {
  57062. PropertyComponent* pec = dynamic_cast <PropertyComponent*> (getChildComponent (i));
  57063. if (pec != 0)
  57064. y += pec->getPreferredHeight();
  57065. }
  57066. }
  57067. return y;
  57068. }
  57069. void setOpen (const bool open)
  57070. {
  57071. if (isOpen_ != open)
  57072. {
  57073. isOpen_ = open;
  57074. for (int i = 0; i < getNumChildComponents(); ++i)
  57075. {
  57076. PropertyComponent* pec = dynamic_cast <PropertyComponent*> (getChildComponent (i));
  57077. if (pec != 0)
  57078. pec->setVisible (open);
  57079. }
  57080. // (unable to use the syntax findParentComponentOfClass <DragAndDropContainer> () because of a VC6 compiler bug)
  57081. PropertyPanel* const pp = findParentComponentOfClass ((PropertyPanel*) 0);
  57082. if (pp != 0)
  57083. pp->resized();
  57084. }
  57085. }
  57086. bool isOpen() const
  57087. {
  57088. return isOpen_;
  57089. }
  57090. void refreshAll() const
  57091. {
  57092. for (int i = 0; i < getNumChildComponents(); ++i)
  57093. {
  57094. PropertyComponent* pec = dynamic_cast <PropertyComponent*> (getChildComponent (i));
  57095. if (pec != 0)
  57096. pec->refresh();
  57097. }
  57098. }
  57099. void mouseDown (const MouseEvent&)
  57100. {
  57101. }
  57102. void mouseUp (const MouseEvent& e)
  57103. {
  57104. if (e.getMouseDownX() < titleHeight
  57105. && e.x < titleHeight
  57106. && e.y < titleHeight
  57107. && e.getNumberOfClicks() != 2)
  57108. {
  57109. setOpen (! isOpen());
  57110. }
  57111. }
  57112. void mouseDoubleClick (const MouseEvent& e)
  57113. {
  57114. if (e.y < titleHeight)
  57115. setOpen (! isOpen());
  57116. }
  57117. private:
  57118. int titleHeight;
  57119. bool isOpen_;
  57120. };
  57121. void PropertyHolderComponent::updateLayout (const int width)
  57122. {
  57123. int y = 0;
  57124. for (int i = getNumChildComponents(); --i >= 0;)
  57125. {
  57126. PropertySectionComponent* const section
  57127. = dynamic_cast <PropertySectionComponent*> (getChildComponent (i));
  57128. if (section != 0)
  57129. {
  57130. const int prefH = section->getPreferredHeight();
  57131. section->setBounds (0, y, width, prefH);
  57132. y += prefH;
  57133. }
  57134. }
  57135. setSize (width, y);
  57136. repaint();
  57137. }
  57138. void PropertyHolderComponent::refreshAll() const
  57139. {
  57140. for (int i = getNumChildComponents(); --i >= 0;)
  57141. {
  57142. PropertySectionComponent* const section
  57143. = dynamic_cast <PropertySectionComponent*> (getChildComponent (i));
  57144. if (section != 0)
  57145. section->refreshAll();
  57146. }
  57147. }
  57148. PropertyPanel::PropertyPanel()
  57149. {
  57150. messageWhenEmpty = TRANS("(nothing selected)");
  57151. addAndMakeVisible (viewport = new Viewport());
  57152. viewport->setViewedComponent (propertyHolderComponent = new PropertyHolderComponent());
  57153. viewport->setFocusContainer (true);
  57154. }
  57155. PropertyPanel::~PropertyPanel()
  57156. {
  57157. clear();
  57158. deleteAllChildren();
  57159. }
  57160. void PropertyPanel::paint (Graphics& g)
  57161. {
  57162. if (propertyHolderComponent->getNumChildComponents() == 0)
  57163. {
  57164. g.setColour (Colours::black.withAlpha (0.5f));
  57165. g.setFont (14.0f);
  57166. g.drawText (messageWhenEmpty, 0, 0, getWidth(), 30,
  57167. Justification::centred, true);
  57168. }
  57169. }
  57170. void PropertyPanel::resized()
  57171. {
  57172. viewport->setBounds (0, 0, getWidth(), getHeight());
  57173. updatePropHolderLayout();
  57174. }
  57175. void PropertyPanel::clear()
  57176. {
  57177. if (propertyHolderComponent->getNumChildComponents() > 0)
  57178. {
  57179. propertyHolderComponent->deleteAllChildren();
  57180. repaint();
  57181. }
  57182. }
  57183. void PropertyPanel::addProperties (const Array <PropertyComponent*>& newProperties)
  57184. {
  57185. if (propertyHolderComponent->getNumChildComponents() == 0)
  57186. repaint();
  57187. propertyHolderComponent->addAndMakeVisible (new PropertySectionComponent (String::empty,
  57188. newProperties,
  57189. true), 0);
  57190. updatePropHolderLayout();
  57191. }
  57192. void PropertyPanel::addSection (const String& sectionTitle,
  57193. const Array <PropertyComponent*>& newProperties,
  57194. const bool shouldBeOpen)
  57195. {
  57196. jassert (sectionTitle.isNotEmpty());
  57197. if (propertyHolderComponent->getNumChildComponents() == 0)
  57198. repaint();
  57199. propertyHolderComponent->addAndMakeVisible (new PropertySectionComponent (sectionTitle,
  57200. newProperties,
  57201. shouldBeOpen), 0);
  57202. updatePropHolderLayout();
  57203. }
  57204. void PropertyPanel::updatePropHolderLayout() const
  57205. {
  57206. const int maxWidth = viewport->getMaximumVisibleWidth();
  57207. ((PropertyHolderComponent*) propertyHolderComponent)->updateLayout (maxWidth);
  57208. const int newMaxWidth = viewport->getMaximumVisibleWidth();
  57209. if (maxWidth != newMaxWidth)
  57210. {
  57211. // need to do this twice because of scrollbars changing the size, etc.
  57212. ((PropertyHolderComponent*) propertyHolderComponent)->updateLayout (newMaxWidth);
  57213. }
  57214. }
  57215. void PropertyPanel::refreshAll() const
  57216. {
  57217. ((PropertyHolderComponent*) propertyHolderComponent)->refreshAll();
  57218. }
  57219. const StringArray PropertyPanel::getSectionNames() const
  57220. {
  57221. StringArray s;
  57222. for (int i = 0; i < propertyHolderComponent->getNumChildComponents(); ++i)
  57223. {
  57224. PropertySectionComponent* const section = dynamic_cast <PropertySectionComponent*> (propertyHolderComponent->getChildComponent (i));
  57225. if (section != 0 && section->getName().isNotEmpty())
  57226. s.add (section->getName());
  57227. }
  57228. return s;
  57229. }
  57230. bool PropertyPanel::isSectionOpen (const int sectionIndex) const
  57231. {
  57232. int index = 0;
  57233. for (int i = 0; i < propertyHolderComponent->getNumChildComponents(); ++i)
  57234. {
  57235. PropertySectionComponent* const section = dynamic_cast <PropertySectionComponent*> (propertyHolderComponent->getChildComponent (i));
  57236. if (section != 0 && section->getName().isNotEmpty())
  57237. {
  57238. if (index == sectionIndex)
  57239. return section->isOpen();
  57240. ++index;
  57241. }
  57242. }
  57243. return false;
  57244. }
  57245. void PropertyPanel::setSectionOpen (const int sectionIndex, const bool shouldBeOpen)
  57246. {
  57247. int index = 0;
  57248. for (int i = 0; i < propertyHolderComponent->getNumChildComponents(); ++i)
  57249. {
  57250. PropertySectionComponent* const section = dynamic_cast <PropertySectionComponent*> (propertyHolderComponent->getChildComponent (i));
  57251. if (section != 0 && section->getName().isNotEmpty())
  57252. {
  57253. if (index == sectionIndex)
  57254. {
  57255. section->setOpen (shouldBeOpen);
  57256. break;
  57257. }
  57258. ++index;
  57259. }
  57260. }
  57261. }
  57262. void PropertyPanel::setSectionEnabled (const int sectionIndex, const bool shouldBeEnabled)
  57263. {
  57264. int index = 0;
  57265. for (int i = 0; i < propertyHolderComponent->getNumChildComponents(); ++i)
  57266. {
  57267. PropertySectionComponent* const section = dynamic_cast <PropertySectionComponent*> (propertyHolderComponent->getChildComponent (i));
  57268. if (section != 0 && section->getName().isNotEmpty())
  57269. {
  57270. if (index == sectionIndex)
  57271. {
  57272. section->setEnabled (shouldBeEnabled);
  57273. break;
  57274. }
  57275. ++index;
  57276. }
  57277. }
  57278. }
  57279. XmlElement* PropertyPanel::getOpennessState() const
  57280. {
  57281. XmlElement* const xml = new XmlElement (T("PROPERTYPANELSTATE"));
  57282. xml->setAttribute ("scrollPos", viewport->getViewPositionY());
  57283. const StringArray sections (getSectionNames());
  57284. for (int i = 0; i < sections.size(); ++i)
  57285. {
  57286. if (sections[i].isNotEmpty())
  57287. {
  57288. XmlElement* const e = xml->createNewChildElement ("SECTION");
  57289. e->setAttribute ("name", sections[i]);
  57290. e->setAttribute ("open", isSectionOpen (i) ? 1 : 0);
  57291. }
  57292. }
  57293. return xml;
  57294. }
  57295. void PropertyPanel::restoreOpennessState (const XmlElement& xml)
  57296. {
  57297. if (xml.hasTagName (T("PROPERTYPANELSTATE")))
  57298. {
  57299. const StringArray sections (getSectionNames());
  57300. forEachXmlChildElementWithTagName (xml, e, T("SECTION"))
  57301. {
  57302. setSectionOpen (sections.indexOf (e->getStringAttribute (T("name"))),
  57303. e->getBoolAttribute (T("open")));
  57304. }
  57305. viewport->setViewPosition (viewport->getViewPositionX(),
  57306. xml.getIntAttribute ("scrollPos", viewport->getViewPositionY()));
  57307. }
  57308. }
  57309. void PropertyPanel::setMessageWhenEmpty (const String& newMessage)
  57310. {
  57311. if (messageWhenEmpty != newMessage)
  57312. {
  57313. messageWhenEmpty = newMessage;
  57314. repaint();
  57315. }
  57316. }
  57317. const String& PropertyPanel::getMessageWhenEmpty() const
  57318. {
  57319. return messageWhenEmpty;
  57320. }
  57321. END_JUCE_NAMESPACE
  57322. /*** End of inlined file: juce_PropertyPanel.cpp ***/
  57323. /*** Start of inlined file: juce_SliderPropertyComponent.cpp ***/
  57324. BEGIN_JUCE_NAMESPACE
  57325. SliderPropertyComponent::SliderPropertyComponent (const String& name,
  57326. const double rangeMin,
  57327. const double rangeMax,
  57328. const double interval,
  57329. const double skewFactor)
  57330. : PropertyComponent (name)
  57331. {
  57332. addAndMakeVisible (slider = new Slider (name));
  57333. slider->setRange (rangeMin, rangeMax, interval);
  57334. slider->setSkewFactor (skewFactor);
  57335. slider->setSliderStyle (Slider::LinearBar);
  57336. slider->addListener (this);
  57337. }
  57338. SliderPropertyComponent::SliderPropertyComponent (Value& valueToControl,
  57339. const String& name,
  57340. const double rangeMin,
  57341. const double rangeMax,
  57342. const double interval,
  57343. const double skewFactor)
  57344. : PropertyComponent (name)
  57345. {
  57346. addAndMakeVisible (slider = new Slider (name));
  57347. slider->setRange (rangeMin, rangeMax, interval);
  57348. slider->setSkewFactor (skewFactor);
  57349. slider->setSliderStyle (Slider::LinearBar);
  57350. slider->getValueObject().referTo (valueToControl);
  57351. }
  57352. SliderPropertyComponent::~SliderPropertyComponent()
  57353. {
  57354. deleteAllChildren();
  57355. }
  57356. void SliderPropertyComponent::setValue (const double /*newValue*/)
  57357. {
  57358. }
  57359. const double SliderPropertyComponent::getValue() const
  57360. {
  57361. return slider->getValue();
  57362. }
  57363. void SliderPropertyComponent::refresh()
  57364. {
  57365. slider->setValue (getValue(), false);
  57366. }
  57367. void SliderPropertyComponent::sliderValueChanged (Slider*)
  57368. {
  57369. if (getValue() != slider->getValue())
  57370. setValue (slider->getValue());
  57371. }
  57372. END_JUCE_NAMESPACE
  57373. /*** End of inlined file: juce_SliderPropertyComponent.cpp ***/
  57374. /*** Start of inlined file: juce_TextPropertyComponent.cpp ***/
  57375. BEGIN_JUCE_NAMESPACE
  57376. class TextPropLabel : public Label
  57377. {
  57378. TextPropertyComponent& owner;
  57379. int maxChars;
  57380. bool isMultiline;
  57381. public:
  57382. TextPropLabel (TextPropertyComponent& owner_,
  57383. const int maxChars_, const bool isMultiline_)
  57384. : Label (String::empty, String::empty),
  57385. owner (owner_),
  57386. maxChars (maxChars_),
  57387. isMultiline (isMultiline_)
  57388. {
  57389. setEditable (true, true, false);
  57390. setColour (backgroundColourId, Colours::white);
  57391. setColour (outlineColourId, findColour (ComboBox::outlineColourId));
  57392. }
  57393. ~TextPropLabel()
  57394. {
  57395. }
  57396. TextEditor* createEditorComponent()
  57397. {
  57398. TextEditor* const textEditor = Label::createEditorComponent();
  57399. textEditor->setInputRestrictions (maxChars);
  57400. if (isMultiline)
  57401. {
  57402. textEditor->setMultiLine (true, true);
  57403. textEditor->setReturnKeyStartsNewLine (true);
  57404. }
  57405. return textEditor;
  57406. }
  57407. void textWasEdited()
  57408. {
  57409. owner.textWasEdited();
  57410. }
  57411. };
  57412. TextPropertyComponent::TextPropertyComponent (const String& name,
  57413. const int maxNumChars,
  57414. const bool isMultiLine)
  57415. : PropertyComponent (name)
  57416. {
  57417. createEditor (maxNumChars, isMultiLine);
  57418. }
  57419. TextPropertyComponent::TextPropertyComponent (const Value& valueToControl,
  57420. const String& name,
  57421. const int maxNumChars,
  57422. const bool isMultiLine)
  57423. : PropertyComponent (name)
  57424. {
  57425. createEditor (maxNumChars, isMultiLine);
  57426. textEditor->getTextValue().referTo (valueToControl);
  57427. }
  57428. TextPropertyComponent::~TextPropertyComponent()
  57429. {
  57430. deleteAllChildren();
  57431. }
  57432. void TextPropertyComponent::setText (const String& newText)
  57433. {
  57434. textEditor->setText (newText, true);
  57435. }
  57436. const String TextPropertyComponent::getText() const
  57437. {
  57438. return textEditor->getText();
  57439. }
  57440. void TextPropertyComponent::createEditor (const int maxNumChars, const bool isMultiLine)
  57441. {
  57442. addAndMakeVisible (textEditor = new TextPropLabel (*this, maxNumChars, isMultiLine));
  57443. if (isMultiLine)
  57444. {
  57445. textEditor->setJustificationType (Justification::topLeft);
  57446. preferredHeight = 120;
  57447. }
  57448. }
  57449. void TextPropertyComponent::refresh()
  57450. {
  57451. textEditor->setText (getText(), false);
  57452. }
  57453. void TextPropertyComponent::textWasEdited()
  57454. {
  57455. const String newText (textEditor->getText());
  57456. if (getText() != newText)
  57457. setText (newText);
  57458. }
  57459. END_JUCE_NAMESPACE
  57460. /*** End of inlined file: juce_TextPropertyComponent.cpp ***/
  57461. /*** Start of inlined file: juce_AudioDeviceSelectorComponent.cpp ***/
  57462. BEGIN_JUCE_NAMESPACE
  57463. class SimpleDeviceManagerInputLevelMeter : public Component,
  57464. public Timer
  57465. {
  57466. public:
  57467. SimpleDeviceManagerInputLevelMeter (AudioDeviceManager* const manager_)
  57468. : manager (manager_),
  57469. level (0)
  57470. {
  57471. startTimer (50);
  57472. manager->enableInputLevelMeasurement (true);
  57473. }
  57474. ~SimpleDeviceManagerInputLevelMeter()
  57475. {
  57476. manager->enableInputLevelMeasurement (false);
  57477. }
  57478. void timerCallback()
  57479. {
  57480. const float newLevel = (float) manager->getCurrentInputLevel();
  57481. if (fabsf (level - newLevel) > 0.005f)
  57482. {
  57483. level = newLevel;
  57484. repaint();
  57485. }
  57486. }
  57487. void paint (Graphics& g)
  57488. {
  57489. getLookAndFeel().drawLevelMeter (g, getWidth(), getHeight(),
  57490. (float) exp (log (level) / 3.0)); // (add a bit of a skew to make the level more obvious)
  57491. }
  57492. private:
  57493. AudioDeviceManager* const manager;
  57494. float level;
  57495. SimpleDeviceManagerInputLevelMeter (const SimpleDeviceManagerInputLevelMeter&);
  57496. SimpleDeviceManagerInputLevelMeter& operator= (const SimpleDeviceManagerInputLevelMeter&);
  57497. };
  57498. class MidiInputSelectorComponentListBox : public ListBox,
  57499. public ListBoxModel
  57500. {
  57501. public:
  57502. MidiInputSelectorComponentListBox (AudioDeviceManager& deviceManager_,
  57503. const String& noItemsMessage_,
  57504. const int minNumber_,
  57505. const int maxNumber_)
  57506. : ListBox (String::empty, 0),
  57507. deviceManager (deviceManager_),
  57508. noItemsMessage (noItemsMessage_),
  57509. minNumber (minNumber_),
  57510. maxNumber (maxNumber_)
  57511. {
  57512. items = MidiInput::getDevices();
  57513. setModel (this);
  57514. setOutlineThickness (1);
  57515. }
  57516. ~MidiInputSelectorComponentListBox()
  57517. {
  57518. }
  57519. int getNumRows()
  57520. {
  57521. return items.size();
  57522. }
  57523. void paintListBoxItem (int row,
  57524. Graphics& g,
  57525. int width, int height,
  57526. bool rowIsSelected)
  57527. {
  57528. if (((unsigned int) row) < (unsigned int) items.size())
  57529. {
  57530. if (rowIsSelected)
  57531. g.fillAll (findColour (TextEditor::highlightColourId)
  57532. .withMultipliedAlpha (0.3f));
  57533. const String item (items [row]);
  57534. bool enabled = deviceManager.isMidiInputEnabled (item);
  57535. const int x = getTickX();
  57536. const float tickW = height * 0.75f;
  57537. getLookAndFeel().drawTickBox (g, *this, x - tickW, (height - tickW) / 2, tickW, tickW,
  57538. enabled, true, true, false);
  57539. g.setFont (height * 0.6f);
  57540. g.setColour (findColour (ListBox::textColourId, true).withMultipliedAlpha (enabled ? 1.0f : 0.6f));
  57541. g.drawText (item, x, 0, width - x - 2, height, Justification::centredLeft, true);
  57542. }
  57543. }
  57544. void listBoxItemClicked (int row, const MouseEvent& e)
  57545. {
  57546. selectRow (row);
  57547. if (e.x < getTickX())
  57548. flipEnablement (row);
  57549. }
  57550. void listBoxItemDoubleClicked (int row, const MouseEvent&)
  57551. {
  57552. flipEnablement (row);
  57553. }
  57554. void returnKeyPressed (int row)
  57555. {
  57556. flipEnablement (row);
  57557. }
  57558. void paint (Graphics& g)
  57559. {
  57560. ListBox::paint (g);
  57561. if (items.size() == 0)
  57562. {
  57563. g.setColour (Colours::grey);
  57564. g.setFont (13.0f);
  57565. g.drawText (noItemsMessage,
  57566. 0, 0, getWidth(), getHeight() / 2,
  57567. Justification::centred, true);
  57568. }
  57569. }
  57570. int getBestHeight (const int preferredHeight)
  57571. {
  57572. const int extra = getOutlineThickness() * 2;
  57573. return jmax (getRowHeight() * 2 + extra,
  57574. jmin (getRowHeight() * getNumRows() + extra,
  57575. preferredHeight));
  57576. }
  57577. juce_UseDebuggingNewOperator
  57578. private:
  57579. AudioDeviceManager& deviceManager;
  57580. const String noItemsMessage;
  57581. StringArray items;
  57582. int minNumber, maxNumber;
  57583. void flipEnablement (const int row)
  57584. {
  57585. if (((unsigned int) row) < (unsigned int) items.size())
  57586. {
  57587. const String item (items [row]);
  57588. deviceManager.setMidiInputEnabled (item, ! deviceManager.isMidiInputEnabled (item));
  57589. }
  57590. }
  57591. int getTickX() const
  57592. {
  57593. return getRowHeight() + 5;
  57594. }
  57595. MidiInputSelectorComponentListBox (const MidiInputSelectorComponentListBox&);
  57596. MidiInputSelectorComponentListBox& operator= (const MidiInputSelectorComponentListBox&);
  57597. };
  57598. class AudioDeviceSettingsPanel : public Component,
  57599. public ComboBoxListener,
  57600. public ChangeListener,
  57601. public ButtonListener
  57602. {
  57603. public:
  57604. AudioDeviceSettingsPanel (AudioIODeviceType* type_,
  57605. AudioIODeviceType::DeviceSetupDetails& setup_,
  57606. const bool hideAdvancedOptionsWithButton)
  57607. : type (type_),
  57608. setup (setup_)
  57609. {
  57610. sampleRateDropDown = 0;
  57611. sampleRateLabel = 0;
  57612. bufferSizeDropDown = 0;
  57613. bufferSizeLabel = 0;
  57614. outputDeviceDropDown = 0;
  57615. outputDeviceLabel = 0;
  57616. inputDeviceDropDown = 0;
  57617. inputDeviceLabel = 0;
  57618. testButton = 0;
  57619. inputLevelMeter = 0;
  57620. showUIButton = 0;
  57621. inputChanList = 0;
  57622. outputChanList = 0;
  57623. inputChanLabel = 0;
  57624. outputChanLabel = 0;
  57625. showAdvancedSettingsButton = 0;
  57626. if (hideAdvancedOptionsWithButton)
  57627. {
  57628. addAndMakeVisible (showAdvancedSettingsButton = new TextButton (TRANS("Show advanced settings...")));
  57629. showAdvancedSettingsButton->addButtonListener (this);
  57630. }
  57631. type->scanForDevices();
  57632. setup.manager->addChangeListener (this);
  57633. changeListenerCallback (0);
  57634. }
  57635. ~AudioDeviceSettingsPanel()
  57636. {
  57637. setup.manager->removeChangeListener (this);
  57638. deleteAndZero (outputDeviceLabel);
  57639. deleteAndZero (inputDeviceLabel);
  57640. deleteAndZero (sampleRateLabel);
  57641. deleteAndZero (bufferSizeLabel);
  57642. deleteAndZero (showUIButton);
  57643. deleteAndZero (inputChanLabel);
  57644. deleteAndZero (outputChanLabel);
  57645. deleteAndZero (showAdvancedSettingsButton);
  57646. deleteAllChildren();
  57647. }
  57648. void resized()
  57649. {
  57650. const int lx = proportionOfWidth (0.35f);
  57651. const int w = proportionOfWidth (0.4f);
  57652. const int h = 24;
  57653. const int space = 6;
  57654. const int dh = h + space;
  57655. int y = 0;
  57656. if (outputDeviceDropDown != 0)
  57657. {
  57658. outputDeviceDropDown->setBounds (lx, y, w, h);
  57659. if (testButton != 0)
  57660. testButton->setBounds (proportionOfWidth (0.77f),
  57661. outputDeviceDropDown->getY(),
  57662. proportionOfWidth (0.18f),
  57663. h);
  57664. y += dh;
  57665. }
  57666. if (inputDeviceDropDown != 0)
  57667. {
  57668. inputDeviceDropDown->setBounds (lx, y, w, h);
  57669. inputLevelMeter->setBounds (proportionOfWidth (0.77f),
  57670. inputDeviceDropDown->getY(),
  57671. proportionOfWidth (0.18f),
  57672. h);
  57673. y += dh;
  57674. }
  57675. const int maxBoxHeight = 100;//(getHeight() - y - dh * 2) / numBoxes;
  57676. if (outputChanList != 0)
  57677. {
  57678. const int bh = outputChanList->getBestHeight (maxBoxHeight);
  57679. outputChanList->setBounds (lx, y, proportionOfWidth (0.55f), bh);
  57680. y += bh + space;
  57681. }
  57682. if (inputChanList != 0)
  57683. {
  57684. const int bh = inputChanList->getBestHeight (maxBoxHeight);
  57685. inputChanList->setBounds (lx, y, proportionOfWidth (0.55f), bh);
  57686. y += bh + space;
  57687. }
  57688. y += space * 2;
  57689. if (showAdvancedSettingsButton != 0)
  57690. {
  57691. showAdvancedSettingsButton->changeWidthToFitText (h);
  57692. showAdvancedSettingsButton->setTopLeftPosition (lx, y);
  57693. }
  57694. if (sampleRateDropDown != 0)
  57695. {
  57696. sampleRateDropDown->setVisible (showAdvancedSettingsButton == 0
  57697. || ! showAdvancedSettingsButton->isVisible());
  57698. sampleRateDropDown->setBounds (lx, y, w, h);
  57699. y += dh;
  57700. }
  57701. if (bufferSizeDropDown != 0)
  57702. {
  57703. bufferSizeDropDown->setVisible (showAdvancedSettingsButton == 0
  57704. || ! showAdvancedSettingsButton->isVisible());
  57705. bufferSizeDropDown->setBounds (lx, y, w, h);
  57706. y += dh;
  57707. }
  57708. if (showUIButton != 0)
  57709. {
  57710. showUIButton->setVisible (showAdvancedSettingsButton == 0
  57711. || ! showAdvancedSettingsButton->isVisible());
  57712. showUIButton->changeWidthToFitText (h);
  57713. showUIButton->setTopLeftPosition (lx, y);
  57714. }
  57715. }
  57716. void comboBoxChanged (ComboBox* comboBoxThatHasChanged)
  57717. {
  57718. if (comboBoxThatHasChanged == 0)
  57719. return;
  57720. AudioDeviceManager::AudioDeviceSetup config;
  57721. setup.manager->getAudioDeviceSetup (config);
  57722. String error;
  57723. if (comboBoxThatHasChanged == outputDeviceDropDown
  57724. || comboBoxThatHasChanged == inputDeviceDropDown)
  57725. {
  57726. if (outputDeviceDropDown != 0)
  57727. config.outputDeviceName = outputDeviceDropDown->getSelectedId() < 0 ? String::empty
  57728. : outputDeviceDropDown->getText();
  57729. if (inputDeviceDropDown != 0)
  57730. config.inputDeviceName = inputDeviceDropDown->getSelectedId() < 0 ? String::empty
  57731. : inputDeviceDropDown->getText();
  57732. if (! type->hasSeparateInputsAndOutputs())
  57733. config.inputDeviceName = config.outputDeviceName;
  57734. if (comboBoxThatHasChanged == inputDeviceDropDown)
  57735. config.useDefaultInputChannels = true;
  57736. else
  57737. config.useDefaultOutputChannels = true;
  57738. error = setup.manager->setAudioDeviceSetup (config, true);
  57739. showCorrectDeviceName (inputDeviceDropDown, true);
  57740. showCorrectDeviceName (outputDeviceDropDown, false);
  57741. updateControlPanelButton();
  57742. resized();
  57743. }
  57744. else if (comboBoxThatHasChanged == sampleRateDropDown)
  57745. {
  57746. if (sampleRateDropDown->getSelectedId() > 0)
  57747. {
  57748. config.sampleRate = sampleRateDropDown->getSelectedId();
  57749. error = setup.manager->setAudioDeviceSetup (config, true);
  57750. }
  57751. }
  57752. else if (comboBoxThatHasChanged == bufferSizeDropDown)
  57753. {
  57754. if (bufferSizeDropDown->getSelectedId() > 0)
  57755. {
  57756. config.bufferSize = bufferSizeDropDown->getSelectedId();
  57757. error = setup.manager->setAudioDeviceSetup (config, true);
  57758. }
  57759. }
  57760. if (error.isNotEmpty())
  57761. {
  57762. AlertWindow::showMessageBox (AlertWindow::WarningIcon,
  57763. T("Error when trying to open audio device!"),
  57764. error);
  57765. }
  57766. }
  57767. void buttonClicked (Button* button)
  57768. {
  57769. if (button == showAdvancedSettingsButton)
  57770. {
  57771. showAdvancedSettingsButton->setVisible (false);
  57772. resized();
  57773. }
  57774. else if (button == showUIButton)
  57775. {
  57776. AudioIODevice* const device = setup.manager->getCurrentAudioDevice();
  57777. if (device != 0 && device->showControlPanel())
  57778. {
  57779. setup.manager->closeAudioDevice();
  57780. setup.manager->restartLastAudioDevice();
  57781. getTopLevelComponent()->toFront (true);
  57782. }
  57783. }
  57784. else if (button == testButton && testButton != 0)
  57785. {
  57786. setup.manager->playTestSound();
  57787. }
  57788. }
  57789. void updateControlPanelButton()
  57790. {
  57791. AudioIODevice* const currentDevice = setup.manager->getCurrentAudioDevice();
  57792. deleteAndZero (showUIButton);
  57793. if (currentDevice != 0 && currentDevice->hasControlPanel())
  57794. {
  57795. addAndMakeVisible (showUIButton = new TextButton (TRANS ("show this device's control panel"),
  57796. TRANS ("opens the device's own control panel")));
  57797. showUIButton->addButtonListener (this);
  57798. }
  57799. resized();
  57800. }
  57801. void changeListenerCallback (void*)
  57802. {
  57803. AudioIODevice* const currentDevice = setup.manager->getCurrentAudioDevice();
  57804. if (setup.maxNumOutputChannels > 0 || ! type->hasSeparateInputsAndOutputs())
  57805. {
  57806. if (outputDeviceDropDown == 0)
  57807. {
  57808. outputDeviceDropDown = new ComboBox (String::empty);
  57809. outputDeviceDropDown->addListener (this);
  57810. addAndMakeVisible (outputDeviceDropDown);
  57811. outputDeviceLabel = new Label (String::empty,
  57812. type->hasSeparateInputsAndOutputs() ? TRANS ("output:")
  57813. : TRANS ("device:"));
  57814. outputDeviceLabel->attachToComponent (outputDeviceDropDown, true);
  57815. if (setup.maxNumOutputChannels > 0)
  57816. {
  57817. addAndMakeVisible (testButton = new TextButton (TRANS ("Test")));
  57818. testButton->addButtonListener (this);
  57819. }
  57820. }
  57821. addNamesToDeviceBox (*outputDeviceDropDown, false);
  57822. }
  57823. if (setup.maxNumInputChannels > 0 && type->hasSeparateInputsAndOutputs())
  57824. {
  57825. if (inputDeviceDropDown == 0)
  57826. {
  57827. inputDeviceDropDown = new ComboBox (String::empty);
  57828. inputDeviceDropDown->addListener (this);
  57829. addAndMakeVisible (inputDeviceDropDown);
  57830. inputDeviceLabel = new Label (String::empty, TRANS ("input:"));
  57831. inputDeviceLabel->attachToComponent (inputDeviceDropDown, true);
  57832. addAndMakeVisible (inputLevelMeter
  57833. = new SimpleDeviceManagerInputLevelMeter (setup.manager));
  57834. }
  57835. addNamesToDeviceBox (*inputDeviceDropDown, true);
  57836. }
  57837. updateControlPanelButton();
  57838. showCorrectDeviceName (inputDeviceDropDown, true);
  57839. showCorrectDeviceName (outputDeviceDropDown, false);
  57840. if (currentDevice != 0)
  57841. {
  57842. if (setup.maxNumOutputChannels > 0
  57843. && setup.minNumOutputChannels < setup.manager->getCurrentAudioDevice()->getOutputChannelNames().size())
  57844. {
  57845. if (outputChanList == 0)
  57846. {
  57847. addAndMakeVisible (outputChanList
  57848. = new ChannelSelectorListBox (setup, ChannelSelectorListBox::audioOutputType,
  57849. TRANS ("(no audio output channels found)")));
  57850. outputChanLabel = new Label (String::empty, TRANS ("active output channels:"));
  57851. outputChanLabel->attachToComponent (outputChanList, true);
  57852. }
  57853. outputChanList->refresh();
  57854. }
  57855. else
  57856. {
  57857. deleteAndZero (outputChanLabel);
  57858. deleteAndZero (outputChanList);
  57859. }
  57860. if (setup.maxNumInputChannels > 0
  57861. && setup.minNumInputChannels < setup.manager->getCurrentAudioDevice()->getInputChannelNames().size())
  57862. {
  57863. if (inputChanList == 0)
  57864. {
  57865. addAndMakeVisible (inputChanList
  57866. = new ChannelSelectorListBox (setup, ChannelSelectorListBox::audioInputType,
  57867. TRANS ("(no audio input channels found)")));
  57868. inputChanLabel = new Label (String::empty, TRANS ("active input channels:"));
  57869. inputChanLabel->attachToComponent (inputChanList, true);
  57870. }
  57871. inputChanList->refresh();
  57872. }
  57873. else
  57874. {
  57875. deleteAndZero (inputChanLabel);
  57876. deleteAndZero (inputChanList);
  57877. }
  57878. // sample rate..
  57879. {
  57880. if (sampleRateDropDown == 0)
  57881. {
  57882. addAndMakeVisible (sampleRateDropDown = new ComboBox (String::empty));
  57883. sampleRateDropDown->addListener (this);
  57884. delete sampleRateLabel;
  57885. sampleRateLabel = new Label (String::empty, TRANS ("sample rate:"));
  57886. sampleRateLabel->attachToComponent (sampleRateDropDown, true);
  57887. }
  57888. else
  57889. {
  57890. sampleRateDropDown->clear();
  57891. sampleRateDropDown->removeListener (this);
  57892. }
  57893. const int numRates = currentDevice->getNumSampleRates();
  57894. for (int i = 0; i < numRates; ++i)
  57895. {
  57896. const int rate = roundToInt (currentDevice->getSampleRate (i));
  57897. sampleRateDropDown->addItem (String (rate) + T(" Hz"), rate);
  57898. }
  57899. sampleRateDropDown->setSelectedId (roundToInt (currentDevice->getCurrentSampleRate()), true);
  57900. sampleRateDropDown->addListener (this);
  57901. }
  57902. // buffer size
  57903. {
  57904. if (bufferSizeDropDown == 0)
  57905. {
  57906. addAndMakeVisible (bufferSizeDropDown = new ComboBox (String::empty));
  57907. bufferSizeDropDown->addListener (this);
  57908. delete bufferSizeLabel;
  57909. bufferSizeLabel = new Label (String::empty, TRANS ("audio buffer size:"));
  57910. bufferSizeLabel->attachToComponent (bufferSizeDropDown, true);
  57911. }
  57912. else
  57913. {
  57914. bufferSizeDropDown->clear();
  57915. }
  57916. const int numBufferSizes = currentDevice->getNumBufferSizesAvailable();
  57917. double currentRate = currentDevice->getCurrentSampleRate();
  57918. if (currentRate == 0)
  57919. currentRate = 48000.0;
  57920. for (int i = 0; i < numBufferSizes; ++i)
  57921. {
  57922. const int bs = currentDevice->getBufferSizeSamples (i);
  57923. bufferSizeDropDown->addItem (String (bs)
  57924. + T(" samples (")
  57925. + String (bs * 1000.0 / currentRate, 1)
  57926. + T(" ms)"),
  57927. bs);
  57928. }
  57929. bufferSizeDropDown->setSelectedId (currentDevice->getCurrentBufferSizeSamples(), true);
  57930. }
  57931. }
  57932. else
  57933. {
  57934. jassert (setup.manager->getCurrentAudioDevice() == 0); // not the correct device type!
  57935. deleteAndZero (sampleRateLabel);
  57936. deleteAndZero (bufferSizeLabel);
  57937. deleteAndZero (sampleRateDropDown);
  57938. deleteAndZero (bufferSizeDropDown);
  57939. if (outputDeviceDropDown != 0)
  57940. outputDeviceDropDown->setSelectedId (-1, true);
  57941. if (inputDeviceDropDown != 0)
  57942. inputDeviceDropDown->setSelectedId (-1, true);
  57943. }
  57944. resized();
  57945. setSize (getWidth(), getLowestY() + 4);
  57946. }
  57947. private:
  57948. AudioIODeviceType* const type;
  57949. const AudioIODeviceType::DeviceSetupDetails setup;
  57950. ComboBox* outputDeviceDropDown;
  57951. ComboBox* inputDeviceDropDown;
  57952. ComboBox* sampleRateDropDown;
  57953. ComboBox* bufferSizeDropDown;
  57954. Label* outputDeviceLabel;
  57955. Label* inputDeviceLabel;
  57956. Label* sampleRateLabel;
  57957. Label* bufferSizeLabel;
  57958. Label* inputChanLabel;
  57959. Label* outputChanLabel;
  57960. TextButton* testButton;
  57961. Component* inputLevelMeter;
  57962. TextButton* showUIButton;
  57963. TextButton* showAdvancedSettingsButton;
  57964. void showCorrectDeviceName (ComboBox* const box, const bool isInput)
  57965. {
  57966. if (box != 0)
  57967. {
  57968. AudioIODevice* const currentDevice = dynamic_cast <AudioIODevice*> (setup.manager->getCurrentAudioDevice());
  57969. const int index = type->getIndexOfDevice (currentDevice, isInput);
  57970. box->setSelectedId (index + 1, true);
  57971. if (testButton != 0 && ! isInput)
  57972. testButton->setEnabled (index >= 0);
  57973. }
  57974. }
  57975. void addNamesToDeviceBox (ComboBox& combo, bool isInputs)
  57976. {
  57977. const StringArray devs (type->getDeviceNames (isInputs));
  57978. combo.clear (true);
  57979. for (int i = 0; i < devs.size(); ++i)
  57980. combo.addItem (devs[i], i + 1);
  57981. combo.addItem (TRANS("<< none >>"), -1);
  57982. combo.setSelectedId (-1, true);
  57983. }
  57984. int getLowestY() const
  57985. {
  57986. int y = 0;
  57987. for (int i = getNumChildComponents(); --i >= 0;)
  57988. y = jmax (y, getChildComponent (i)->getBottom());
  57989. return y;
  57990. }
  57991. public:
  57992. class ChannelSelectorListBox : public ListBox,
  57993. public ListBoxModel
  57994. {
  57995. public:
  57996. enum BoxType
  57997. {
  57998. audioInputType,
  57999. audioOutputType
  58000. };
  58001. ChannelSelectorListBox (const AudioIODeviceType::DeviceSetupDetails& setup_,
  58002. const BoxType type_,
  58003. const String& noItemsMessage_)
  58004. : ListBox (String::empty, 0),
  58005. setup (setup_),
  58006. type (type_),
  58007. noItemsMessage (noItemsMessage_)
  58008. {
  58009. refresh();
  58010. setModel (this);
  58011. setOutlineThickness (1);
  58012. }
  58013. ~ChannelSelectorListBox()
  58014. {
  58015. }
  58016. void refresh()
  58017. {
  58018. items.clear();
  58019. AudioIODevice* const currentDevice = setup.manager->getCurrentAudioDevice();
  58020. if (currentDevice != 0)
  58021. {
  58022. if (type == audioInputType)
  58023. items = currentDevice->getInputChannelNames();
  58024. else if (type == audioOutputType)
  58025. items = currentDevice->getOutputChannelNames();
  58026. if (setup.useStereoPairs)
  58027. {
  58028. StringArray pairs;
  58029. for (int i = 0; i < items.size(); i += 2)
  58030. {
  58031. String name (items[i]);
  58032. String name2 (items[i + 1]);
  58033. String commonBit;
  58034. for (int j = 0; j < name.length(); ++j)
  58035. if (name.substring (0, j).equalsIgnoreCase (name2.substring (0, j)))
  58036. commonBit = name.substring (0, j);
  58037. pairs.add (name.trim()
  58038. + " + "
  58039. + name2.substring (commonBit.length()).trim());
  58040. }
  58041. items = pairs;
  58042. }
  58043. }
  58044. updateContent();
  58045. repaint();
  58046. }
  58047. int getNumRows()
  58048. {
  58049. return items.size();
  58050. }
  58051. void paintListBoxItem (int row,
  58052. Graphics& g,
  58053. int width, int height,
  58054. bool rowIsSelected)
  58055. {
  58056. if (((unsigned int) row) < (unsigned int) items.size())
  58057. {
  58058. if (rowIsSelected)
  58059. g.fillAll (findColour (TextEditor::highlightColourId)
  58060. .withMultipliedAlpha (0.3f));
  58061. const String item (items [row]);
  58062. bool enabled = false;
  58063. AudioDeviceManager::AudioDeviceSetup config;
  58064. setup.manager->getAudioDeviceSetup (config);
  58065. if (setup.useStereoPairs)
  58066. {
  58067. if (type == audioInputType)
  58068. enabled = config.inputChannels [row * 2] || config.inputChannels [row * 2 + 1];
  58069. else if (type == audioOutputType)
  58070. enabled = config.outputChannels [row * 2] || config.outputChannels [row * 2 + 1];
  58071. }
  58072. else
  58073. {
  58074. if (type == audioInputType)
  58075. enabled = config.inputChannels [row];
  58076. else if (type == audioOutputType)
  58077. enabled = config.outputChannels [row];
  58078. }
  58079. const int x = getTickX();
  58080. const float tickW = height * 0.75f;
  58081. getLookAndFeel().drawTickBox (g, *this, x - tickW, (height - tickW) / 2, tickW, tickW,
  58082. enabled, true, true, false);
  58083. g.setFont (height * 0.6f);
  58084. g.setColour (findColour (ListBox::textColourId, true).withMultipliedAlpha (enabled ? 1.0f : 0.6f));
  58085. g.drawText (item, x, 0, width - x - 2, height, Justification::centredLeft, true);
  58086. }
  58087. }
  58088. void listBoxItemClicked (int row, const MouseEvent& e)
  58089. {
  58090. selectRow (row);
  58091. if (e.x < getTickX())
  58092. flipEnablement (row);
  58093. }
  58094. void listBoxItemDoubleClicked (int row, const MouseEvent&)
  58095. {
  58096. flipEnablement (row);
  58097. }
  58098. void returnKeyPressed (int row)
  58099. {
  58100. flipEnablement (row);
  58101. }
  58102. void paint (Graphics& g)
  58103. {
  58104. ListBox::paint (g);
  58105. if (items.size() == 0)
  58106. {
  58107. g.setColour (Colours::grey);
  58108. g.setFont (13.0f);
  58109. g.drawText (noItemsMessage,
  58110. 0, 0, getWidth(), getHeight() / 2,
  58111. Justification::centred, true);
  58112. }
  58113. }
  58114. int getBestHeight (int maxHeight)
  58115. {
  58116. return getRowHeight() * jlimit (2, jmax (2, maxHeight / getRowHeight()),
  58117. getNumRows())
  58118. + getOutlineThickness() * 2;
  58119. }
  58120. juce_UseDebuggingNewOperator
  58121. private:
  58122. const AudioIODeviceType::DeviceSetupDetails setup;
  58123. const BoxType type;
  58124. const String noItemsMessage;
  58125. StringArray items;
  58126. void flipEnablement (const int row)
  58127. {
  58128. jassert (type == audioInputType || type == audioOutputType);
  58129. if (((unsigned int) row) < (unsigned int) items.size())
  58130. {
  58131. AudioDeviceManager::AudioDeviceSetup config;
  58132. setup.manager->getAudioDeviceSetup (config);
  58133. if (setup.useStereoPairs)
  58134. {
  58135. BigInteger bits;
  58136. BigInteger& original = (type == audioInputType ? config.inputChannels
  58137. : config.outputChannels);
  58138. int i;
  58139. for (i = 0; i < 256; i += 2)
  58140. bits.setBit (i / 2, original [i] || original [i + 1]);
  58141. if (type == audioInputType)
  58142. {
  58143. config.useDefaultInputChannels = false;
  58144. flipBit (bits, row, setup.minNumInputChannels / 2, setup.maxNumInputChannels / 2);
  58145. }
  58146. else
  58147. {
  58148. config.useDefaultOutputChannels = false;
  58149. flipBit (bits, row, setup.minNumOutputChannels / 2, setup.maxNumOutputChannels / 2);
  58150. }
  58151. for (i = 0; i < 256; ++i)
  58152. original.setBit (i, bits [i / 2]);
  58153. }
  58154. else
  58155. {
  58156. if (type == audioInputType)
  58157. {
  58158. config.useDefaultInputChannels = false;
  58159. flipBit (config.inputChannels, row, setup.minNumInputChannels, setup.maxNumInputChannels);
  58160. }
  58161. else
  58162. {
  58163. config.useDefaultOutputChannels = false;
  58164. flipBit (config.outputChannels, row, setup.minNumOutputChannels, setup.maxNumOutputChannels);
  58165. }
  58166. }
  58167. String error (setup.manager->setAudioDeviceSetup (config, true));
  58168. if (! error.isEmpty())
  58169. {
  58170. //xxx
  58171. }
  58172. }
  58173. }
  58174. static void flipBit (BigInteger& chans, int index, int minNumber, int maxNumber)
  58175. {
  58176. const int numActive = chans.countNumberOfSetBits();
  58177. if (chans [index])
  58178. {
  58179. if (numActive > minNumber)
  58180. chans.setBit (index, false);
  58181. }
  58182. else
  58183. {
  58184. if (numActive >= maxNumber)
  58185. {
  58186. const int firstActiveChan = chans.findNextSetBit();
  58187. chans.setBit (index > firstActiveChan
  58188. ? firstActiveChan : chans.getHighestBit(),
  58189. false);
  58190. }
  58191. chans.setBit (index, true);
  58192. }
  58193. }
  58194. int getTickX() const
  58195. {
  58196. return getRowHeight() + 5;
  58197. }
  58198. ChannelSelectorListBox (const ChannelSelectorListBox&);
  58199. ChannelSelectorListBox& operator= (const ChannelSelectorListBox&);
  58200. };
  58201. private:
  58202. ChannelSelectorListBox* inputChanList;
  58203. ChannelSelectorListBox* outputChanList;
  58204. AudioDeviceSettingsPanel (const AudioDeviceSettingsPanel&);
  58205. AudioDeviceSettingsPanel& operator= (const AudioDeviceSettingsPanel&);
  58206. };
  58207. AudioDeviceSelectorComponent::AudioDeviceSelectorComponent (AudioDeviceManager& deviceManager_,
  58208. const int minInputChannels_,
  58209. const int maxInputChannels_,
  58210. const int minOutputChannels_,
  58211. const int maxOutputChannels_,
  58212. const bool showMidiInputOptions,
  58213. const bool showMidiOutputSelector,
  58214. const bool showChannelsAsStereoPairs_,
  58215. const bool hideAdvancedOptionsWithButton_)
  58216. : deviceManager (deviceManager_),
  58217. deviceTypeDropDown (0),
  58218. deviceTypeDropDownLabel (0),
  58219. audioDeviceSettingsComp (0),
  58220. minOutputChannels (minOutputChannels_),
  58221. maxOutputChannels (maxOutputChannels_),
  58222. minInputChannels (minInputChannels_),
  58223. maxInputChannels (maxInputChannels_),
  58224. showChannelsAsStereoPairs (showChannelsAsStereoPairs_),
  58225. hideAdvancedOptionsWithButton (hideAdvancedOptionsWithButton_)
  58226. {
  58227. jassert (minOutputChannels >= 0 && minOutputChannels <= maxOutputChannels);
  58228. jassert (minInputChannels >= 0 && minInputChannels <= maxInputChannels);
  58229. if (deviceManager_.getAvailableDeviceTypes().size() > 1)
  58230. {
  58231. deviceTypeDropDown = new ComboBox (String::empty);
  58232. for (int i = 0; i < deviceManager_.getAvailableDeviceTypes().size(); ++i)
  58233. {
  58234. deviceTypeDropDown
  58235. ->addItem (deviceManager_.getAvailableDeviceTypes().getUnchecked(i)->getTypeName(),
  58236. i + 1);
  58237. }
  58238. addAndMakeVisible (deviceTypeDropDown);
  58239. deviceTypeDropDown->addListener (this);
  58240. deviceTypeDropDownLabel = new Label (String::empty, TRANS ("audio device type:"));
  58241. deviceTypeDropDownLabel->setJustificationType (Justification::centredRight);
  58242. deviceTypeDropDownLabel->attachToComponent (deviceTypeDropDown, true);
  58243. }
  58244. if (showMidiInputOptions)
  58245. {
  58246. addAndMakeVisible (midiInputsList
  58247. = new MidiInputSelectorComponentListBox (deviceManager,
  58248. TRANS("(no midi inputs available)"),
  58249. 0, 0));
  58250. midiInputsLabel = new Label (String::empty, TRANS ("active midi inputs:"));
  58251. midiInputsLabel->setJustificationType (Justification::topRight);
  58252. midiInputsLabel->attachToComponent (midiInputsList, true);
  58253. }
  58254. else
  58255. {
  58256. midiInputsList = 0;
  58257. midiInputsLabel = 0;
  58258. }
  58259. if (showMidiOutputSelector)
  58260. {
  58261. addAndMakeVisible (midiOutputSelector = new ComboBox (String::empty));
  58262. midiOutputSelector->addListener (this);
  58263. midiOutputLabel = new Label ("lm", TRANS("Midi Output:"));
  58264. midiOutputLabel->attachToComponent (midiOutputSelector, true);
  58265. }
  58266. else
  58267. {
  58268. midiOutputSelector = 0;
  58269. midiOutputLabel = 0;
  58270. }
  58271. deviceManager_.addChangeListener (this);
  58272. changeListenerCallback (0);
  58273. }
  58274. AudioDeviceSelectorComponent::~AudioDeviceSelectorComponent()
  58275. {
  58276. deviceManager.removeChangeListener (this);
  58277. deleteAllChildren();
  58278. }
  58279. void AudioDeviceSelectorComponent::resized()
  58280. {
  58281. const int lx = proportionOfWidth (0.35f);
  58282. const int w = proportionOfWidth (0.4f);
  58283. const int h = 24;
  58284. const int space = 6;
  58285. const int dh = h + space;
  58286. int y = 15;
  58287. if (deviceTypeDropDown != 0)
  58288. {
  58289. deviceTypeDropDown->setBounds (lx, y, proportionOfWidth (0.3f), h);
  58290. y += dh + space * 2;
  58291. }
  58292. if (audioDeviceSettingsComp != 0)
  58293. {
  58294. audioDeviceSettingsComp->setBounds (0, y, getWidth(), audioDeviceSettingsComp->getHeight());
  58295. y += audioDeviceSettingsComp->getHeight() + space;
  58296. }
  58297. if (midiInputsList != 0)
  58298. {
  58299. const int bh = midiInputsList->getBestHeight (jmin (h * 8, getHeight() - y - space - h));
  58300. midiInputsList->setBounds (lx, y, w, bh);
  58301. y += bh + space;
  58302. }
  58303. if (midiOutputSelector != 0)
  58304. midiOutputSelector->setBounds (lx, y, w, h);
  58305. }
  58306. void AudioDeviceSelectorComponent::childBoundsChanged (Component* child)
  58307. {
  58308. if (child == audioDeviceSettingsComp)
  58309. resized();
  58310. }
  58311. void AudioDeviceSelectorComponent::buttonClicked (Button*)
  58312. {
  58313. AudioIODevice* const device = deviceManager.getCurrentAudioDevice();
  58314. if (device != 0 && device->hasControlPanel())
  58315. {
  58316. if (device->showControlPanel())
  58317. deviceManager.restartLastAudioDevice();
  58318. getTopLevelComponent()->toFront (true);
  58319. }
  58320. }
  58321. void AudioDeviceSelectorComponent::comboBoxChanged (ComboBox* comboBoxThatHasChanged)
  58322. {
  58323. if (comboBoxThatHasChanged == deviceTypeDropDown)
  58324. {
  58325. AudioIODeviceType* const type = deviceManager.getAvailableDeviceTypes() [deviceTypeDropDown->getSelectedId() - 1];
  58326. if (type != 0)
  58327. {
  58328. deleteAndZero (audioDeviceSettingsComp);
  58329. deviceManager.setCurrentAudioDeviceType (type->getTypeName(), true);
  58330. changeListenerCallback (0); // needed in case the type hasn't actally changed
  58331. }
  58332. }
  58333. else if (comboBoxThatHasChanged == midiOutputSelector)
  58334. {
  58335. deviceManager.setDefaultMidiOutput (midiOutputSelector->getText());
  58336. }
  58337. }
  58338. void AudioDeviceSelectorComponent::changeListenerCallback (void*)
  58339. {
  58340. if (deviceTypeDropDown != 0)
  58341. {
  58342. deviceTypeDropDown->setText (deviceManager.getCurrentAudioDeviceType(), false);
  58343. }
  58344. if (audioDeviceSettingsComp == 0
  58345. || audioDeviceSettingsCompType != deviceManager.getCurrentAudioDeviceType())
  58346. {
  58347. audioDeviceSettingsCompType = deviceManager.getCurrentAudioDeviceType();
  58348. deleteAndZero (audioDeviceSettingsComp);
  58349. AudioIODeviceType* const type
  58350. = deviceManager.getAvailableDeviceTypes() [deviceTypeDropDown == 0
  58351. ? 0 : deviceTypeDropDown->getSelectedId() - 1];
  58352. if (type != 0)
  58353. {
  58354. AudioIODeviceType::DeviceSetupDetails details;
  58355. details.manager = &deviceManager;
  58356. details.minNumInputChannels = minInputChannels;
  58357. details.maxNumInputChannels = maxInputChannels;
  58358. details.minNumOutputChannels = minOutputChannels;
  58359. details.maxNumOutputChannels = maxOutputChannels;
  58360. details.useStereoPairs = showChannelsAsStereoPairs;
  58361. audioDeviceSettingsComp = new AudioDeviceSettingsPanel (type, details, hideAdvancedOptionsWithButton);
  58362. if (audioDeviceSettingsComp != 0)
  58363. {
  58364. addAndMakeVisible (audioDeviceSettingsComp);
  58365. audioDeviceSettingsComp->resized();
  58366. }
  58367. }
  58368. }
  58369. if (midiInputsList != 0)
  58370. {
  58371. midiInputsList->updateContent();
  58372. midiInputsList->repaint();
  58373. }
  58374. if (midiOutputSelector != 0)
  58375. {
  58376. midiOutputSelector->clear();
  58377. const StringArray midiOuts (MidiOutput::getDevices());
  58378. midiOutputSelector->addItem (TRANS("<< none >>"), -1);
  58379. midiOutputSelector->addSeparator();
  58380. for (int i = 0; i < midiOuts.size(); ++i)
  58381. midiOutputSelector->addItem (midiOuts[i], i + 1);
  58382. int current = -1;
  58383. if (deviceManager.getDefaultMidiOutput() != 0)
  58384. current = 1 + midiOuts.indexOf (deviceManager.getDefaultMidiOutputName());
  58385. midiOutputSelector->setSelectedId (current, true);
  58386. }
  58387. resized();
  58388. }
  58389. END_JUCE_NAMESPACE
  58390. /*** End of inlined file: juce_AudioDeviceSelectorComponent.cpp ***/
  58391. /*** Start of inlined file: juce_BubbleComponent.cpp ***/
  58392. BEGIN_JUCE_NAMESPACE
  58393. BubbleComponent::BubbleComponent()
  58394. : side (0),
  58395. allowablePlacements (above | below | left | right),
  58396. arrowTipX (0.0f),
  58397. arrowTipY (0.0f)
  58398. {
  58399. setInterceptsMouseClicks (false, false);
  58400. shadow.setShadowProperties (5.0f, 0.35f, 0, 0);
  58401. setComponentEffect (&shadow);
  58402. }
  58403. BubbleComponent::~BubbleComponent()
  58404. {
  58405. }
  58406. void BubbleComponent::paint (Graphics& g)
  58407. {
  58408. int x = content.getX();
  58409. int y = content.getY();
  58410. int w = content.getWidth();
  58411. int h = content.getHeight();
  58412. int cw, ch;
  58413. getContentSize (cw, ch);
  58414. if (side == 3)
  58415. x += w - cw;
  58416. else if (side != 1)
  58417. x += (w - cw) / 2;
  58418. w = cw;
  58419. if (side == 2)
  58420. y += h - ch;
  58421. else if (side != 0)
  58422. y += (h - ch) / 2;
  58423. h = ch;
  58424. getLookAndFeel().drawBubble (g, arrowTipX, arrowTipY,
  58425. (float) x, (float) y,
  58426. (float) w, (float) h);
  58427. const int cx = x + (w - cw) / 2;
  58428. const int cy = y + (h - ch) / 2;
  58429. const int indent = 3;
  58430. g.setOrigin (cx + indent, cy + indent);
  58431. g.reduceClipRegion (0, 0, cw - indent * 2, ch - indent * 2);
  58432. paintContent (g, cw - indent * 2, ch - indent * 2);
  58433. }
  58434. void BubbleComponent::setAllowedPlacement (const int newPlacement)
  58435. {
  58436. allowablePlacements = newPlacement;
  58437. }
  58438. void BubbleComponent::setPosition (Component* componentToPointTo)
  58439. {
  58440. jassert (componentToPointTo->isValidComponent());
  58441. Point<int> pos;
  58442. if (getParentComponent() != 0)
  58443. pos = componentToPointTo->relativePositionToOtherComponent (getParentComponent(), pos);
  58444. else
  58445. pos = componentToPointTo->relativePositionToGlobal (pos);
  58446. setPosition (Rectangle<int> (pos.getX(), pos.getY(), componentToPointTo->getWidth(), componentToPointTo->getHeight()));
  58447. }
  58448. void BubbleComponent::setPosition (const int arrowTipX_,
  58449. const int arrowTipY_)
  58450. {
  58451. setPosition (Rectangle<int> (arrowTipX_, arrowTipY_, 1, 1));
  58452. }
  58453. void BubbleComponent::setPosition (const Rectangle<int>& rectangleToPointTo)
  58454. {
  58455. Rectangle<int> availableSpace;
  58456. if (getParentComponent() != 0)
  58457. {
  58458. availableSpace.setSize (getParentComponent()->getWidth(),
  58459. getParentComponent()->getHeight());
  58460. }
  58461. else
  58462. {
  58463. availableSpace = getParentMonitorArea();
  58464. }
  58465. int x = 0;
  58466. int y = 0;
  58467. int w = 150;
  58468. int h = 30;
  58469. getContentSize (w, h);
  58470. w += 30;
  58471. h += 30;
  58472. const float edgeIndent = 2.0f;
  58473. const int arrowLength = jmin (10, h / 3, w / 3);
  58474. int spaceAbove = ((allowablePlacements & above) != 0) ? jmax (0, rectangleToPointTo.getY() - availableSpace.getY()) : -1;
  58475. int spaceBelow = ((allowablePlacements & below) != 0) ? jmax (0, availableSpace.getBottom() - rectangleToPointTo.getBottom()) : -1;
  58476. int spaceLeft = ((allowablePlacements & left) != 0) ? jmax (0, rectangleToPointTo.getX() - availableSpace.getX()) : -1;
  58477. int spaceRight = ((allowablePlacements & right) != 0) ? jmax (0, availableSpace.getRight() - rectangleToPointTo.getRight()) : -1;
  58478. // look at whether the component is elongated, and if so, try to position next to its longer dimension.
  58479. if (rectangleToPointTo.getWidth() > rectangleToPointTo.getHeight() * 2
  58480. && (spaceAbove > h + 20 || spaceBelow > h + 20))
  58481. {
  58482. spaceLeft = spaceRight = 0;
  58483. }
  58484. else if (rectangleToPointTo.getWidth() < rectangleToPointTo.getHeight() / 2
  58485. && (spaceLeft > w + 20 || spaceRight > w + 20))
  58486. {
  58487. spaceAbove = spaceBelow = 0;
  58488. }
  58489. if (jmax (spaceAbove, spaceBelow) >= jmax (spaceLeft, spaceRight))
  58490. {
  58491. x = rectangleToPointTo.getX() + (rectangleToPointTo.getWidth() - w) / 2;
  58492. arrowTipX = w * 0.5f;
  58493. content.setSize (w, h - arrowLength);
  58494. if (spaceAbove >= spaceBelow)
  58495. {
  58496. // above
  58497. y = rectangleToPointTo.getY() - h;
  58498. content.setPosition (0, 0);
  58499. arrowTipY = h - edgeIndent;
  58500. side = 2;
  58501. }
  58502. else
  58503. {
  58504. // below
  58505. y = rectangleToPointTo.getBottom();
  58506. content.setPosition (0, arrowLength);
  58507. arrowTipY = edgeIndent;
  58508. side = 0;
  58509. }
  58510. }
  58511. else
  58512. {
  58513. y = rectangleToPointTo.getY() + (rectangleToPointTo.getHeight() - h) / 2;
  58514. arrowTipY = h * 0.5f;
  58515. content.setSize (w - arrowLength, h);
  58516. if (spaceLeft > spaceRight)
  58517. {
  58518. // on the left
  58519. x = rectangleToPointTo.getX() - w;
  58520. content.setPosition (0, 0);
  58521. arrowTipX = w - edgeIndent;
  58522. side = 3;
  58523. }
  58524. else
  58525. {
  58526. // on the right
  58527. x = rectangleToPointTo.getRight();
  58528. content.setPosition (arrowLength, 0);
  58529. arrowTipX = edgeIndent;
  58530. side = 1;
  58531. }
  58532. }
  58533. setBounds (x, y, w, h);
  58534. }
  58535. END_JUCE_NAMESPACE
  58536. /*** End of inlined file: juce_BubbleComponent.cpp ***/
  58537. /*** Start of inlined file: juce_BubbleMessageComponent.cpp ***/
  58538. BEGIN_JUCE_NAMESPACE
  58539. BubbleMessageComponent::BubbleMessageComponent (int fadeOutLengthMs)
  58540. : fadeOutLength (fadeOutLengthMs),
  58541. deleteAfterUse (false)
  58542. {
  58543. }
  58544. BubbleMessageComponent::~BubbleMessageComponent()
  58545. {
  58546. fadeOutComponent (fadeOutLength);
  58547. }
  58548. void BubbleMessageComponent::showAt (int x, int y,
  58549. const String& text,
  58550. const int numMillisecondsBeforeRemoving,
  58551. const bool removeWhenMouseClicked,
  58552. const bool deleteSelfAfterUse)
  58553. {
  58554. textLayout.clear();
  58555. textLayout.setText (text, Font (14.0f));
  58556. textLayout.layout (256, Justification::centredLeft, true);
  58557. setPosition (x, y);
  58558. init (numMillisecondsBeforeRemoving, removeWhenMouseClicked, deleteSelfAfterUse);
  58559. }
  58560. void BubbleMessageComponent::showAt (Component* const component,
  58561. const String& text,
  58562. const int numMillisecondsBeforeRemoving,
  58563. const bool removeWhenMouseClicked,
  58564. const bool deleteSelfAfterUse)
  58565. {
  58566. textLayout.clear();
  58567. textLayout.setText (text, Font (14.0f));
  58568. textLayout.layout (256, Justification::centredLeft, true);
  58569. setPosition (component);
  58570. init (numMillisecondsBeforeRemoving, removeWhenMouseClicked, deleteSelfAfterUse);
  58571. }
  58572. void BubbleMessageComponent::init (const int numMillisecondsBeforeRemoving,
  58573. const bool removeWhenMouseClicked,
  58574. const bool deleteSelfAfterUse)
  58575. {
  58576. setVisible (true);
  58577. deleteAfterUse = deleteSelfAfterUse;
  58578. if (numMillisecondsBeforeRemoving > 0)
  58579. expiryTime = Time::getMillisecondCounter() + numMillisecondsBeforeRemoving;
  58580. else
  58581. expiryTime = 0;
  58582. startTimer (77);
  58583. mouseClickCounter = Desktop::getInstance().getMouseButtonClickCounter();
  58584. if (! (removeWhenMouseClicked && isShowing()))
  58585. mouseClickCounter += 0xfffff;
  58586. repaint();
  58587. }
  58588. void BubbleMessageComponent::getContentSize (int& w, int& h)
  58589. {
  58590. w = textLayout.getWidth() + 16;
  58591. h = textLayout.getHeight() + 16;
  58592. }
  58593. void BubbleMessageComponent::paintContent (Graphics& g, int w, int h)
  58594. {
  58595. g.setColour (findColour (TooltipWindow::textColourId));
  58596. textLayout.drawWithin (g, 0, 0, w, h, Justification::centred);
  58597. }
  58598. void BubbleMessageComponent::timerCallback()
  58599. {
  58600. if (Desktop::getInstance().getMouseButtonClickCounter() > mouseClickCounter)
  58601. {
  58602. stopTimer();
  58603. setVisible (false);
  58604. if (deleteAfterUse)
  58605. delete this;
  58606. }
  58607. else if (expiryTime != 0 && Time::getMillisecondCounter() > expiryTime)
  58608. {
  58609. stopTimer();
  58610. fadeOutComponent (fadeOutLength);
  58611. if (deleteAfterUse)
  58612. delete this;
  58613. }
  58614. }
  58615. END_JUCE_NAMESPACE
  58616. /*** End of inlined file: juce_BubbleMessageComponent.cpp ***/
  58617. /*** Start of inlined file: juce_ColourSelector.cpp ***/
  58618. BEGIN_JUCE_NAMESPACE
  58619. static const int swatchesPerRow = 8;
  58620. static const int swatchHeight = 22;
  58621. class ColourComponentSlider : public Slider
  58622. {
  58623. public:
  58624. ColourComponentSlider (const String& name)
  58625. : Slider (name)
  58626. {
  58627. setRange (0.0, 255.0, 1.0);
  58628. }
  58629. ~ColourComponentSlider()
  58630. {
  58631. }
  58632. const String getTextFromValue (double value)
  58633. {
  58634. return String::toHexString ((int) value).toUpperCase().paddedLeft ('0', 2);
  58635. }
  58636. double getValueFromText (const String& text)
  58637. {
  58638. return (double) text.getHexValue32();
  58639. }
  58640. private:
  58641. ColourComponentSlider (const ColourComponentSlider&);
  58642. ColourComponentSlider& operator= (const ColourComponentSlider&);
  58643. };
  58644. class ColourSpaceMarker : public Component
  58645. {
  58646. public:
  58647. ColourSpaceMarker()
  58648. {
  58649. setInterceptsMouseClicks (false, false);
  58650. }
  58651. ~ColourSpaceMarker()
  58652. {
  58653. }
  58654. void paint (Graphics& g)
  58655. {
  58656. g.setColour (Colour::greyLevel (0.1f));
  58657. g.drawEllipse (1.0f, 1.0f, getWidth() - 2.0f, getHeight() - 2.0f, 1.0f);
  58658. g.setColour (Colour::greyLevel (0.9f));
  58659. g.drawEllipse (2.0f, 2.0f, getWidth() - 4.0f, getHeight() - 4.0f, 1.0f);
  58660. }
  58661. private:
  58662. ColourSpaceMarker (const ColourSpaceMarker&);
  58663. ColourSpaceMarker& operator= (const ColourSpaceMarker&);
  58664. };
  58665. class ColourSpaceView : public Component
  58666. {
  58667. ColourSelector* const owner;
  58668. float& h;
  58669. float& s;
  58670. float& v;
  58671. float lastHue;
  58672. ColourSpaceMarker* marker;
  58673. const int edge;
  58674. public:
  58675. ColourSpaceView (ColourSelector* owner_,
  58676. float& h_, float& s_, float& v_,
  58677. const int edgeSize)
  58678. : owner (owner_),
  58679. h (h_), s (s_), v (v_),
  58680. lastHue (0.0f),
  58681. edge (edgeSize)
  58682. {
  58683. addAndMakeVisible (marker = new ColourSpaceMarker());
  58684. setMouseCursor (MouseCursor::CrosshairCursor);
  58685. }
  58686. ~ColourSpaceView()
  58687. {
  58688. deleteAllChildren();
  58689. }
  58690. void paint (Graphics& g)
  58691. {
  58692. if (colours == 0)
  58693. {
  58694. const int width = getWidth() / 2;
  58695. const int height = getHeight() / 2;
  58696. colours = new Image (Image::RGB, width, height, false);
  58697. Image::BitmapData pixels (*colours, 0, 0, width, height, true);
  58698. for (int y = 0; y < height; ++y)
  58699. {
  58700. const float v = 1.0f - y / (float) height;
  58701. for (int x = 0; x < width; ++x)
  58702. {
  58703. const float s = x / (float) width;
  58704. const Colour col (h, s, v, 1.0f);
  58705. PixelRGB* const pix = (PixelRGB*) pixels.getPixelPointer (x, y);
  58706. pix->set (col.getPixelARGB());
  58707. }
  58708. }
  58709. }
  58710. g.setOpacity (1.0f);
  58711. g.drawImage (colours, edge, edge, getWidth() - edge * 2, getHeight() - edge * 2,
  58712. 0, 0, colours->getWidth(), colours->getHeight());
  58713. }
  58714. void mouseDown (const MouseEvent& e)
  58715. {
  58716. mouseDrag (e);
  58717. }
  58718. void mouseDrag (const MouseEvent& e)
  58719. {
  58720. const float s = (e.x - edge) / (float) (getWidth() - edge * 2);
  58721. const float v = 1.0f - (e.y - edge) / (float) (getHeight() - edge * 2);
  58722. owner->setSV (s, v);
  58723. }
  58724. void updateIfNeeded()
  58725. {
  58726. if (lastHue != h)
  58727. {
  58728. lastHue = h;
  58729. colours = 0;
  58730. repaint();
  58731. }
  58732. updateMarker();
  58733. }
  58734. void resized()
  58735. {
  58736. colours = 0;
  58737. updateMarker();
  58738. }
  58739. private:
  58740. ScopedPointer <Image> colours;
  58741. void updateMarker() const throw()
  58742. {
  58743. marker->setBounds (roundToInt ((getWidth() - edge * 2) * s),
  58744. roundToInt ((getHeight() - edge * 2) * (1.0f - v)),
  58745. edge * 2, edge * 2);
  58746. }
  58747. ColourSpaceView (const ColourSpaceView&);
  58748. ColourSpaceView& operator= (const ColourSpaceView&);
  58749. };
  58750. class HueSelectorMarker : public Component
  58751. {
  58752. public:
  58753. HueSelectorMarker()
  58754. {
  58755. setInterceptsMouseClicks (false, false);
  58756. }
  58757. ~HueSelectorMarker()
  58758. {
  58759. }
  58760. void paint (Graphics& g)
  58761. {
  58762. Path p;
  58763. p.addTriangle (1.0f, 1.0f,
  58764. getWidth() * 0.3f, getHeight() * 0.5f,
  58765. 1.0f, getHeight() - 1.0f);
  58766. p.addTriangle (getWidth() - 1.0f, 1.0f,
  58767. getWidth() * 0.7f, getHeight() * 0.5f,
  58768. getWidth() - 1.0f, getHeight() - 1.0f);
  58769. g.setColour (Colours::white.withAlpha (0.75f));
  58770. g.fillPath (p);
  58771. g.setColour (Colours::black.withAlpha (0.75f));
  58772. g.strokePath (p, PathStrokeType (1.2f));
  58773. }
  58774. private:
  58775. HueSelectorMarker (const HueSelectorMarker&);
  58776. HueSelectorMarker& operator= (const HueSelectorMarker&);
  58777. };
  58778. class HueSelectorComp : public Component
  58779. {
  58780. public:
  58781. HueSelectorComp (ColourSelector* owner_,
  58782. float& h_, float& s_, float& v_,
  58783. const int edgeSize)
  58784. : owner (owner_),
  58785. h (h_), s (s_), v (v_),
  58786. lastHue (0.0f),
  58787. edge (edgeSize)
  58788. {
  58789. addAndMakeVisible (marker = new HueSelectorMarker());
  58790. }
  58791. ~HueSelectorComp()
  58792. {
  58793. deleteAllChildren();
  58794. }
  58795. void paint (Graphics& g)
  58796. {
  58797. const float yScale = 1.0f / (getHeight() - edge * 2);
  58798. const Rectangle<int> clip (g.getClipBounds());
  58799. for (int y = jmin (clip.getBottom(), getHeight() - edge); --y >= jmax (edge, clip.getY());)
  58800. {
  58801. g.setColour (Colour ((y - edge) * yScale, 1.0f, 1.0f, 1.0f));
  58802. g.fillRect (edge, y, getWidth() - edge * 2, 1);
  58803. }
  58804. }
  58805. void resized()
  58806. {
  58807. marker->setBounds (0, roundToInt ((getHeight() - edge * 2) * h),
  58808. getWidth(), edge * 2);
  58809. }
  58810. void mouseDown (const MouseEvent& e)
  58811. {
  58812. mouseDrag (e);
  58813. }
  58814. void mouseDrag (const MouseEvent& e)
  58815. {
  58816. const float hue = (e.y - edge) / (float) (getHeight() - edge * 2);
  58817. owner->setHue (hue);
  58818. }
  58819. void updateIfNeeded()
  58820. {
  58821. resized();
  58822. }
  58823. private:
  58824. ColourSelector* const owner;
  58825. float& h;
  58826. float& s;
  58827. float& v;
  58828. float lastHue;
  58829. HueSelectorMarker* marker;
  58830. const int edge;
  58831. HueSelectorComp (const HueSelectorComp&);
  58832. HueSelectorComp& operator= (const HueSelectorComp&);
  58833. };
  58834. class ColourSelector::SwatchComponent : public Component
  58835. {
  58836. public:
  58837. SwatchComponent (ColourSelector* owner_, int index_)
  58838. : owner (owner_),
  58839. index (index_)
  58840. {
  58841. }
  58842. ~SwatchComponent()
  58843. {
  58844. }
  58845. void paint (Graphics& g)
  58846. {
  58847. const Colour colour (owner->getSwatchColour (index));
  58848. g.fillCheckerBoard (0, 0, getWidth(), getHeight(),
  58849. 6, 6,
  58850. Colour (0xffdddddd).overlaidWith (colour),
  58851. Colour (0xffffffff).overlaidWith (colour));
  58852. }
  58853. void mouseDown (const MouseEvent&)
  58854. {
  58855. PopupMenu m;
  58856. m.addItem (1, TRANS("Use this swatch as the current colour"));
  58857. m.addSeparator();
  58858. m.addItem (2, TRANS("Set this swatch to the current colour"));
  58859. const int r = m.showAt (this);
  58860. if (r == 1)
  58861. {
  58862. owner->setCurrentColour (owner->getSwatchColour (index));
  58863. }
  58864. else if (r == 2)
  58865. {
  58866. if (owner->getSwatchColour (index) != owner->getCurrentColour())
  58867. {
  58868. owner->setSwatchColour (index, owner->getCurrentColour());
  58869. repaint();
  58870. }
  58871. }
  58872. }
  58873. private:
  58874. ColourSelector* const owner;
  58875. const int index;
  58876. SwatchComponent (const SwatchComponent&);
  58877. SwatchComponent& operator= (const SwatchComponent&);
  58878. };
  58879. ColourSelector::ColourSelector (const int flags_,
  58880. const int edgeGap_,
  58881. const int gapAroundColourSpaceComponent)
  58882. : colour (Colours::white),
  58883. flags (flags_),
  58884. topSpace (0),
  58885. edgeGap (edgeGap_)
  58886. {
  58887. // not much point having a selector with no components in it!
  58888. jassert ((flags_ & (showColourAtTop | showSliders | showColourspace)) != 0);
  58889. updateHSV();
  58890. if ((flags & showSliders) != 0)
  58891. {
  58892. addAndMakeVisible (sliders[0] = new ColourComponentSlider (TRANS ("red")));
  58893. addAndMakeVisible (sliders[1] = new ColourComponentSlider (TRANS ("green")));
  58894. addAndMakeVisible (sliders[2] = new ColourComponentSlider (TRANS ("blue")));
  58895. addChildComponent (sliders[3] = new ColourComponentSlider (TRANS ("alpha")));
  58896. sliders[3]->setVisible ((flags & showAlphaChannel) != 0);
  58897. for (int i = 4; --i >= 0;)
  58898. sliders[i]->addListener (this);
  58899. }
  58900. else
  58901. {
  58902. zeromem (sliders, sizeof (sliders));
  58903. }
  58904. if ((flags & showColourspace) != 0)
  58905. {
  58906. addAndMakeVisible (colourSpace = new ColourSpaceView (this, h, s, v, gapAroundColourSpaceComponent));
  58907. addAndMakeVisible (hueSelector = new HueSelectorComp (this, h, s, v, gapAroundColourSpaceComponent));
  58908. }
  58909. else
  58910. {
  58911. colourSpace = 0;
  58912. hueSelector = 0;
  58913. }
  58914. update();
  58915. }
  58916. ColourSelector::~ColourSelector()
  58917. {
  58918. dispatchPendingMessages();
  58919. swatchComponents.clear();
  58920. deleteAllChildren();
  58921. }
  58922. const Colour ColourSelector::getCurrentColour() const
  58923. {
  58924. return ((flags & showAlphaChannel) != 0) ? colour
  58925. : colour.withAlpha ((uint8) 0xff);
  58926. }
  58927. void ColourSelector::setCurrentColour (const Colour& c)
  58928. {
  58929. if (c != colour)
  58930. {
  58931. colour = ((flags & showAlphaChannel) != 0) ? c : c.withAlpha ((uint8) 0xff);
  58932. updateHSV();
  58933. update();
  58934. }
  58935. }
  58936. void ColourSelector::setHue (float newH)
  58937. {
  58938. newH = jlimit (0.0f, 1.0f, newH);
  58939. if (h != newH)
  58940. {
  58941. h = newH;
  58942. colour = Colour (h, s, v, colour.getFloatAlpha());
  58943. update();
  58944. }
  58945. }
  58946. void ColourSelector::setSV (float newS, float newV)
  58947. {
  58948. newS = jlimit (0.0f, 1.0f, newS);
  58949. newV = jlimit (0.0f, 1.0f, newV);
  58950. if (s != newS || v != newV)
  58951. {
  58952. s = newS;
  58953. v = newV;
  58954. colour = Colour (h, s, v, colour.getFloatAlpha());
  58955. update();
  58956. }
  58957. }
  58958. void ColourSelector::updateHSV()
  58959. {
  58960. colour.getHSB (h, s, v);
  58961. }
  58962. void ColourSelector::update()
  58963. {
  58964. if (sliders[0] != 0)
  58965. {
  58966. sliders[0]->setValue ((int) colour.getRed());
  58967. sliders[1]->setValue ((int) colour.getGreen());
  58968. sliders[2]->setValue ((int) colour.getBlue());
  58969. sliders[3]->setValue ((int) colour.getAlpha());
  58970. }
  58971. if (colourSpace != 0)
  58972. {
  58973. ((ColourSpaceView*) colourSpace)->updateIfNeeded();
  58974. ((HueSelectorComp*) hueSelector)->updateIfNeeded();
  58975. }
  58976. if ((flags & showColourAtTop) != 0)
  58977. repaint (0, edgeGap, getWidth(), topSpace - edgeGap);
  58978. sendChangeMessage (this);
  58979. }
  58980. void ColourSelector::paint (Graphics& g)
  58981. {
  58982. g.fillAll (findColour (backgroundColourId));
  58983. if ((flags & showColourAtTop) != 0)
  58984. {
  58985. const Colour colour (getCurrentColour());
  58986. g.fillCheckerBoard (edgeGap, edgeGap, getWidth() - edgeGap - edgeGap, topSpace - edgeGap - edgeGap,
  58987. 10, 10,
  58988. Colour (0xffdddddd).overlaidWith (colour),
  58989. Colour (0xffffffff).overlaidWith (colour));
  58990. g.setColour (Colours::white.overlaidWith (colour).contrasting());
  58991. g.setFont (14.0f, true);
  58992. g.drawText (colour.toDisplayString ((flags & showAlphaChannel) != 0),
  58993. 0, edgeGap, getWidth(), topSpace - edgeGap * 2,
  58994. Justification::centred, false);
  58995. }
  58996. if ((flags & showSliders) != 0)
  58997. {
  58998. g.setColour (findColour (labelTextColourId));
  58999. g.setFont (11.0f);
  59000. for (int i = 4; --i >= 0;)
  59001. {
  59002. if (sliders[i]->isVisible())
  59003. g.drawText (sliders[i]->getName() + T(":"),
  59004. 0, sliders[i]->getY(),
  59005. sliders[i]->getX() - 8, sliders[i]->getHeight(),
  59006. Justification::centredRight, false);
  59007. }
  59008. }
  59009. }
  59010. void ColourSelector::resized()
  59011. {
  59012. const int numSliders = ((flags & showAlphaChannel) != 0) ? 4 : 3;
  59013. const int numSwatches = getNumSwatches();
  59014. const int swatchSpace = numSwatches > 0 ? edgeGap + swatchHeight * ((numSwatches + 7) / swatchesPerRow) : 0;
  59015. const int sliderSpace = ((flags & showSliders) != 0) ? jmin (22 * numSliders + edgeGap, proportionOfHeight (0.3f)) : 0;
  59016. topSpace = ((flags & showColourAtTop) != 0) ? jmin (30 + edgeGap * 2, proportionOfHeight (0.2f)) : edgeGap;
  59017. int y = topSpace;
  59018. if ((flags & showColourspace) != 0)
  59019. {
  59020. const int hueWidth = jmin (50, proportionOfWidth (0.15f));
  59021. colourSpace->setBounds (edgeGap, y,
  59022. getWidth() - hueWidth - edgeGap - 4,
  59023. getHeight() - topSpace - sliderSpace - swatchSpace - edgeGap);
  59024. hueSelector->setBounds (colourSpace->getRight() + 4, y,
  59025. getWidth() - edgeGap - (colourSpace->getRight() + 4),
  59026. colourSpace->getHeight());
  59027. y = getHeight() - sliderSpace - swatchSpace - edgeGap;
  59028. }
  59029. if ((flags & showSliders) != 0)
  59030. {
  59031. const int sliderHeight = jmax (4, sliderSpace / numSliders);
  59032. for (int i = 0; i < numSliders; ++i)
  59033. {
  59034. sliders[i]->setBounds (proportionOfWidth (0.2f), y,
  59035. proportionOfWidth (0.72f), sliderHeight - 2);
  59036. y += sliderHeight;
  59037. }
  59038. }
  59039. if (numSwatches > 0)
  59040. {
  59041. const int startX = 8;
  59042. const int xGap = 4;
  59043. const int yGap = 4;
  59044. const int swatchWidth = (getWidth() - startX * 2) / swatchesPerRow;
  59045. y += edgeGap;
  59046. if (swatchComponents.size() != numSwatches)
  59047. {
  59048. swatchComponents.clear();
  59049. for (int i = 0; i < numSwatches; ++i)
  59050. {
  59051. SwatchComponent* const sc = new SwatchComponent (this, i);
  59052. swatchComponents.add (sc);
  59053. addAndMakeVisible (sc);
  59054. }
  59055. }
  59056. int x = startX;
  59057. for (int i = 0; i < swatchComponents.size(); ++i)
  59058. {
  59059. SwatchComponent* const sc = swatchComponents.getUnchecked(i);
  59060. sc->setBounds (x + xGap / 2,
  59061. y + yGap / 2,
  59062. swatchWidth - xGap,
  59063. swatchHeight - yGap);
  59064. if (((i + 1) % swatchesPerRow) == 0)
  59065. {
  59066. x = startX;
  59067. y += swatchHeight;
  59068. }
  59069. else
  59070. {
  59071. x += swatchWidth;
  59072. }
  59073. }
  59074. }
  59075. }
  59076. void ColourSelector::sliderValueChanged (Slider*)
  59077. {
  59078. if (sliders[0] != 0)
  59079. setCurrentColour (Colour ((uint8) sliders[0]->getValue(),
  59080. (uint8) sliders[1]->getValue(),
  59081. (uint8) sliders[2]->getValue(),
  59082. (uint8) sliders[3]->getValue()));
  59083. }
  59084. int ColourSelector::getNumSwatches() const
  59085. {
  59086. return 0;
  59087. }
  59088. const Colour ColourSelector::getSwatchColour (const int) const
  59089. {
  59090. jassertfalse // if you've overridden getNumSwatches(), you also need to implement this method
  59091. return Colours::black;
  59092. }
  59093. void ColourSelector::setSwatchColour (const int, const Colour&) const
  59094. {
  59095. jassertfalse // if you've overridden getNumSwatches(), you also need to implement this method
  59096. }
  59097. END_JUCE_NAMESPACE
  59098. /*** End of inlined file: juce_ColourSelector.cpp ***/
  59099. /*** Start of inlined file: juce_DropShadower.cpp ***/
  59100. BEGIN_JUCE_NAMESPACE
  59101. class ShadowWindow : public Component
  59102. {
  59103. Component* owner;
  59104. Image** shadowImageSections;
  59105. const int type; // 0 = left, 1 = right, 2 = top, 3 = bottom. left + right are full-height
  59106. public:
  59107. ShadowWindow (Component* const owner_,
  59108. const int type_,
  59109. Image** const shadowImageSections_)
  59110. : owner (owner_),
  59111. shadowImageSections (shadowImageSections_),
  59112. type (type_)
  59113. {
  59114. setInterceptsMouseClicks (false, false);
  59115. if (owner_->isOnDesktop())
  59116. {
  59117. setSize (1, 1); // to keep the OS happy by not having zero-size windows
  59118. addToDesktop (ComponentPeer::windowIgnoresMouseClicks
  59119. | ComponentPeer::windowIsTemporary
  59120. | ComponentPeer::windowIgnoresKeyPresses);
  59121. }
  59122. else if (owner_->getParentComponent() != 0)
  59123. {
  59124. owner_->getParentComponent()->addChildComponent (this);
  59125. }
  59126. }
  59127. ~ShadowWindow()
  59128. {
  59129. }
  59130. void paint (Graphics& g)
  59131. {
  59132. Image* const topLeft = shadowImageSections [type * 3];
  59133. Image* const bottomRight = shadowImageSections [type * 3 + 1];
  59134. Image* const filler = shadowImageSections [type * 3 + 2];
  59135. g.setOpacity (1.0f);
  59136. if (type < 2)
  59137. {
  59138. int imH = jmin (topLeft->getHeight(), getHeight() / 2);
  59139. g.drawImage (topLeft,
  59140. 0, 0, topLeft->getWidth(), imH,
  59141. 0, 0, topLeft->getWidth(), imH);
  59142. imH = jmin (bottomRight->getHeight(), getHeight() - getHeight() / 2);
  59143. g.drawImage (bottomRight,
  59144. 0, getHeight() - imH, bottomRight->getWidth(), imH,
  59145. 0, bottomRight->getHeight() - imH, bottomRight->getWidth(), imH);
  59146. g.setTiledImageFill (*filler, 0, 0, 1.0f);
  59147. g.fillRect (0, topLeft->getHeight(), getWidth(), getHeight() - (topLeft->getHeight() + bottomRight->getHeight()));
  59148. }
  59149. else
  59150. {
  59151. int imW = jmin (topLeft->getWidth(), getWidth() / 2);
  59152. g.drawImage (topLeft,
  59153. 0, 0, imW, topLeft->getHeight(),
  59154. 0, 0, imW, topLeft->getHeight());
  59155. imW = jmin (bottomRight->getWidth(), getWidth() - getWidth() / 2);
  59156. g.drawImage (bottomRight,
  59157. getWidth() - imW, 0, imW, bottomRight->getHeight(),
  59158. bottomRight->getWidth() - imW, 0, imW, bottomRight->getHeight());
  59159. g.setTiledImageFill (*filler, 0, 0, 1.0f);
  59160. g.fillRect (topLeft->getWidth(), 0, getWidth() - (topLeft->getWidth() + bottomRight->getWidth()), getHeight());
  59161. }
  59162. }
  59163. void resized()
  59164. {
  59165. repaint(); // (needed for correct repainting)
  59166. }
  59167. private:
  59168. ShadowWindow (const ShadowWindow&);
  59169. ShadowWindow& operator= (const ShadowWindow&);
  59170. };
  59171. DropShadower::DropShadower (const float alpha_,
  59172. const int xOffset_,
  59173. const int yOffset_,
  59174. const float blurRadius_)
  59175. : owner (0),
  59176. numShadows (0),
  59177. shadowEdge (jmax (xOffset_, yOffset_) + (int) blurRadius_),
  59178. xOffset (xOffset_),
  59179. yOffset (yOffset_),
  59180. alpha (alpha_),
  59181. blurRadius (blurRadius_),
  59182. inDestructor (false),
  59183. reentrant (false)
  59184. {
  59185. }
  59186. DropShadower::~DropShadower()
  59187. {
  59188. if (owner != 0)
  59189. owner->removeComponentListener (this);
  59190. inDestructor = true;
  59191. deleteShadowWindows();
  59192. }
  59193. void DropShadower::deleteShadowWindows()
  59194. {
  59195. if (numShadows > 0)
  59196. {
  59197. int i;
  59198. for (i = numShadows; --i >= 0;)
  59199. delete shadowWindows[i];
  59200. for (i = 12; --i >= 0;)
  59201. delete shadowImageSections[i];
  59202. numShadows = 0;
  59203. }
  59204. }
  59205. void DropShadower::setOwner (Component* componentToFollow)
  59206. {
  59207. if (componentToFollow != owner)
  59208. {
  59209. if (owner != 0)
  59210. owner->removeComponentListener (this);
  59211. // (the component can't be null)
  59212. jassert (componentToFollow != 0);
  59213. owner = componentToFollow;
  59214. jassert (owner != 0);
  59215. jassert (owner->isOpaque()); // doesn't work properly for semi-transparent comps!
  59216. owner->addComponentListener (this);
  59217. updateShadows();
  59218. }
  59219. }
  59220. void DropShadower::componentMovedOrResized (Component&, bool /*wasMoved*/, bool /*wasResized*/)
  59221. {
  59222. updateShadows();
  59223. }
  59224. void DropShadower::componentBroughtToFront (Component&)
  59225. {
  59226. bringShadowWindowsToFront();
  59227. }
  59228. void DropShadower::componentChildrenChanged (Component&)
  59229. {
  59230. }
  59231. void DropShadower::componentParentHierarchyChanged (Component&)
  59232. {
  59233. deleteShadowWindows();
  59234. updateShadows();
  59235. }
  59236. void DropShadower::componentVisibilityChanged (Component&)
  59237. {
  59238. updateShadows();
  59239. }
  59240. void DropShadower::updateShadows()
  59241. {
  59242. if (reentrant || inDestructor || (owner == 0))
  59243. return;
  59244. reentrant = true;
  59245. ComponentPeer* const nw = owner->getPeer();
  59246. const bool isOwnerVisible = owner->isVisible()
  59247. && (nw == 0 || ! nw->isMinimised());
  59248. const bool createShadowWindows = numShadows == 0
  59249. && owner->getWidth() > 0
  59250. && owner->getHeight() > 0
  59251. && isOwnerVisible
  59252. && (Desktop::canUseSemiTransparentWindows()
  59253. || owner->getParentComponent() != 0);
  59254. if (createShadowWindows)
  59255. {
  59256. // keep a cached version of the image to save doing the gaussian too often
  59257. String imageId;
  59258. imageId << shadowEdge << T(',')
  59259. << xOffset << T(',')
  59260. << yOffset << T(',')
  59261. << alpha;
  59262. const int hash = imageId.hashCode();
  59263. Image* bigIm = ImageCache::getFromHashCode (hash);
  59264. if (bigIm == 0)
  59265. {
  59266. bigIm = Image::createNativeImage (Image::ARGB, shadowEdge * 5, shadowEdge * 5, true);
  59267. Graphics bigG (*bigIm);
  59268. bigG.setColour (Colours::black.withAlpha (alpha));
  59269. bigG.fillRect (shadowEdge + xOffset,
  59270. shadowEdge + yOffset,
  59271. bigIm->getWidth() - (shadowEdge * 2),
  59272. bigIm->getHeight() - (shadowEdge * 2));
  59273. ImageConvolutionKernel blurKernel (roundToInt (blurRadius * 2.0f));
  59274. blurKernel.createGaussianBlur (blurRadius);
  59275. blurKernel.applyToImage (*bigIm, 0,
  59276. xOffset,
  59277. yOffset,
  59278. bigIm->getWidth(),
  59279. bigIm->getHeight());
  59280. ImageCache::addImageToCache (bigIm, hash);
  59281. }
  59282. const int iw = bigIm->getWidth();
  59283. const int ih = bigIm->getHeight();
  59284. const int shadowEdge2 = shadowEdge * 2;
  59285. setShadowImage (bigIm, 0, shadowEdge, shadowEdge2, 0, 0);
  59286. setShadowImage (bigIm, 1, shadowEdge, shadowEdge2, 0, ih - shadowEdge2);
  59287. setShadowImage (bigIm, 2, shadowEdge, shadowEdge, 0, shadowEdge2);
  59288. setShadowImage (bigIm, 3, shadowEdge, shadowEdge2, iw - shadowEdge, 0);
  59289. setShadowImage (bigIm, 4, shadowEdge, shadowEdge2, iw - shadowEdge, ih - shadowEdge2);
  59290. setShadowImage (bigIm, 5, shadowEdge, shadowEdge, iw - shadowEdge, shadowEdge2);
  59291. setShadowImage (bigIm, 6, shadowEdge, shadowEdge, shadowEdge, 0);
  59292. setShadowImage (bigIm, 7, shadowEdge, shadowEdge, iw - shadowEdge2, 0);
  59293. setShadowImage (bigIm, 8, shadowEdge, shadowEdge, shadowEdge2, 0);
  59294. setShadowImage (bigIm, 9, shadowEdge, shadowEdge, shadowEdge, ih - shadowEdge);
  59295. setShadowImage (bigIm, 10, shadowEdge, shadowEdge, iw - shadowEdge2, ih - shadowEdge);
  59296. setShadowImage (bigIm, 11, shadowEdge, shadowEdge, shadowEdge2, ih - shadowEdge);
  59297. ImageCache::release (bigIm);
  59298. for (int i = 0; i < 4; ++i)
  59299. {
  59300. shadowWindows[numShadows] = new ShadowWindow (owner, i, shadowImageSections);
  59301. ++numShadows;
  59302. }
  59303. }
  59304. if (numShadows > 0)
  59305. {
  59306. for (int i = numShadows; --i >= 0;)
  59307. {
  59308. shadowWindows[i]->setAlwaysOnTop (owner->isAlwaysOnTop());
  59309. shadowWindows[i]->setVisible (isOwnerVisible);
  59310. }
  59311. const int x = owner->getX();
  59312. const int y = owner->getY() - shadowEdge;
  59313. const int w = owner->getWidth();
  59314. const int h = owner->getHeight() + shadowEdge + shadowEdge;
  59315. shadowWindows[0]->setBounds (x - shadowEdge,
  59316. y,
  59317. shadowEdge,
  59318. h);
  59319. shadowWindows[1]->setBounds (x + w,
  59320. y,
  59321. shadowEdge,
  59322. h);
  59323. shadowWindows[2]->setBounds (x,
  59324. y,
  59325. w,
  59326. shadowEdge);
  59327. shadowWindows[3]->setBounds (x,
  59328. owner->getBottom(),
  59329. w,
  59330. shadowEdge);
  59331. }
  59332. reentrant = false;
  59333. if (createShadowWindows)
  59334. bringShadowWindowsToFront();
  59335. }
  59336. void DropShadower::setShadowImage (Image* const src,
  59337. const int num,
  59338. const int w,
  59339. const int h,
  59340. const int sx,
  59341. const int sy)
  59342. {
  59343. shadowImageSections[num] = new Image (Image::ARGB, w, h, true);
  59344. Graphics g (*shadowImageSections[num]);
  59345. g.drawImage (src, 0, 0, w, h, sx, sy, w, h);
  59346. }
  59347. void DropShadower::bringShadowWindowsToFront()
  59348. {
  59349. if (! (inDestructor || reentrant))
  59350. {
  59351. updateShadows();
  59352. reentrant = true;
  59353. for (int i = numShadows; --i >= 0;)
  59354. shadowWindows[i]->toBehind (owner);
  59355. reentrant = false;
  59356. }
  59357. }
  59358. END_JUCE_NAMESPACE
  59359. /*** End of inlined file: juce_DropShadower.cpp ***/
  59360. /*** Start of inlined file: juce_MagnifierComponent.cpp ***/
  59361. BEGIN_JUCE_NAMESPACE
  59362. class MagnifyingPeer : public ComponentPeer
  59363. {
  59364. public:
  59365. MagnifyingPeer (Component* const component_,
  59366. MagnifierComponent* const magnifierComp_)
  59367. : ComponentPeer (component_, 0),
  59368. magnifierComp (magnifierComp_)
  59369. {
  59370. }
  59371. ~MagnifyingPeer()
  59372. {
  59373. }
  59374. void* getNativeHandle() const { return 0; }
  59375. void setVisible (bool) {}
  59376. void setTitle (const String&) {}
  59377. void setPosition (int, int) {}
  59378. void setSize (int, int) {}
  59379. void setBounds (int, int, int, int, const bool) {}
  59380. void setMinimised (bool) {}
  59381. bool isMinimised() const { return false; }
  59382. void setFullScreen (bool) {}
  59383. bool isFullScreen() const { return false; }
  59384. const BorderSize getFrameSize() const { return BorderSize (0); }
  59385. bool setAlwaysOnTop (bool) { return true; }
  59386. void toFront (bool) {}
  59387. void toBehind (ComponentPeer*) {}
  59388. void setIcon (const Image&) {}
  59389. bool isFocused() const
  59390. {
  59391. return magnifierComp->hasKeyboardFocus (true);
  59392. }
  59393. void grabFocus()
  59394. {
  59395. ComponentPeer* peer = magnifierComp->getPeer();
  59396. if (peer != 0)
  59397. peer->grabFocus();
  59398. }
  59399. void textInputRequired (const Point<int>& position)
  59400. {
  59401. ComponentPeer* peer = magnifierComp->getPeer();
  59402. if (peer != 0)
  59403. peer->textInputRequired (position);
  59404. }
  59405. const Rectangle<int> getBounds() const
  59406. {
  59407. return Rectangle<int> (magnifierComp->getScreenX(), magnifierComp->getScreenY(),
  59408. component->getWidth(), component->getHeight());
  59409. }
  59410. const Point<int> getScreenPosition() const
  59411. {
  59412. return magnifierComp->getScreenPosition();
  59413. }
  59414. const Point<int> relativePositionToGlobal (const Point<int>& relativePosition)
  59415. {
  59416. const double zoom = magnifierComp->getScaleFactor();
  59417. return magnifierComp->relativePositionToGlobal (Point<int> (roundToInt (relativePosition.getX() * zoom),
  59418. roundToInt (relativePosition.getY() * zoom)));
  59419. }
  59420. const Point<int> globalPositionToRelative (const Point<int>& screenPosition)
  59421. {
  59422. const Point<int> p (magnifierComp->globalPositionToRelative (screenPosition));
  59423. const double zoom = magnifierComp->getScaleFactor();
  59424. return Point<int> (roundToInt (p.getX() / zoom),
  59425. roundToInt (p.getY() / zoom));
  59426. }
  59427. bool contains (const Point<int>& position, bool) const
  59428. {
  59429. return ((unsigned int) position.getX()) < (unsigned int) magnifierComp->getWidth()
  59430. && ((unsigned int) position.getY()) < (unsigned int) magnifierComp->getHeight();
  59431. }
  59432. void repaint (int x, int y, int w, int h)
  59433. {
  59434. const double zoom = magnifierComp->getScaleFactor();
  59435. magnifierComp->repaint ((int) (x * zoom),
  59436. (int) (y * zoom),
  59437. roundToInt (w * zoom) + 1,
  59438. roundToInt (h * zoom) + 1);
  59439. }
  59440. void performAnyPendingRepaintsNow()
  59441. {
  59442. }
  59443. juce_UseDebuggingNewOperator
  59444. private:
  59445. MagnifierComponent* const magnifierComp;
  59446. MagnifyingPeer (const MagnifyingPeer&);
  59447. MagnifyingPeer& operator= (const MagnifyingPeer&);
  59448. };
  59449. class PeerHolderComp : public Component
  59450. {
  59451. public:
  59452. PeerHolderComp (MagnifierComponent* const magnifierComp_)
  59453. : magnifierComp (magnifierComp_)
  59454. {
  59455. setVisible (true);
  59456. }
  59457. ~PeerHolderComp()
  59458. {
  59459. }
  59460. ComponentPeer* createNewPeer (int, void*)
  59461. {
  59462. return new MagnifyingPeer (this, magnifierComp);
  59463. }
  59464. void childBoundsChanged (Component* c)
  59465. {
  59466. if (c != 0)
  59467. {
  59468. setSize (c->getWidth(), c->getHeight());
  59469. magnifierComp->childBoundsChanged (this);
  59470. }
  59471. }
  59472. void mouseWheelMove (const MouseEvent& e, float ix, float iy)
  59473. {
  59474. // unhandled mouse wheel moves can be referred upwards to the parent comp..
  59475. Component* const p = magnifierComp->getParentComponent();
  59476. if (p != 0)
  59477. p->mouseWheelMove (e.getEventRelativeTo (p), ix, iy);
  59478. }
  59479. private:
  59480. MagnifierComponent* const magnifierComp;
  59481. PeerHolderComp (const PeerHolderComp&);
  59482. PeerHolderComp& operator= (const PeerHolderComp&);
  59483. };
  59484. MagnifierComponent::MagnifierComponent (Component* const content_,
  59485. const bool deleteContentCompWhenNoLongerNeeded)
  59486. : content (content_),
  59487. scaleFactor (0.0),
  59488. peer (0),
  59489. deleteContent (deleteContentCompWhenNoLongerNeeded),
  59490. quality (Graphics::lowResamplingQuality),
  59491. mouseSource (0, true)
  59492. {
  59493. holderComp = new PeerHolderComp (this);
  59494. setScaleFactor (1.0);
  59495. }
  59496. MagnifierComponent::~MagnifierComponent()
  59497. {
  59498. delete holderComp;
  59499. if (deleteContent)
  59500. delete content;
  59501. }
  59502. void MagnifierComponent::setScaleFactor (double newScaleFactor)
  59503. {
  59504. jassert (newScaleFactor > 0.0); // hmm - unlikely to work well with a negative scale factor
  59505. newScaleFactor = jlimit (1.0 / 8.0, 1000.0, newScaleFactor);
  59506. if (scaleFactor != newScaleFactor)
  59507. {
  59508. scaleFactor = newScaleFactor;
  59509. if (scaleFactor == 1.0)
  59510. {
  59511. holderComp->removeFromDesktop();
  59512. peer = 0;
  59513. addChildComponent (content);
  59514. childBoundsChanged (content);
  59515. }
  59516. else
  59517. {
  59518. holderComp->addAndMakeVisible (content);
  59519. holderComp->childBoundsChanged (content);
  59520. childBoundsChanged (holderComp);
  59521. holderComp->addToDesktop (0);
  59522. peer = holderComp->getPeer();
  59523. }
  59524. repaint();
  59525. }
  59526. }
  59527. void MagnifierComponent::setResamplingQuality (Graphics::ResamplingQuality newQuality)
  59528. {
  59529. quality = newQuality;
  59530. }
  59531. void MagnifierComponent::paint (Graphics& g)
  59532. {
  59533. const int w = holderComp->getWidth();
  59534. const int h = holderComp->getHeight();
  59535. if (w == 0 || h == 0)
  59536. return;
  59537. const Rectangle<int> r (g.getClipBounds());
  59538. const int srcX = (int) (r.getX() / scaleFactor);
  59539. const int srcY = (int) (r.getY() / scaleFactor);
  59540. int srcW = roundToInt (r.getRight() / scaleFactor) - srcX;
  59541. int srcH = roundToInt (r.getBottom() / scaleFactor) - srcY;
  59542. if (scaleFactor >= 1.0)
  59543. {
  59544. ++srcW;
  59545. ++srcH;
  59546. }
  59547. Image temp (Image::ARGB, jmax (w, srcX + srcW), jmax (h, srcY + srcH), false);
  59548. temp.clear (srcX, srcY, srcW, srcH);
  59549. {
  59550. Graphics g2 (temp);
  59551. g2.reduceClipRegion (srcX, srcY, srcW, srcH);
  59552. holderComp->paintEntireComponent (g2);
  59553. }
  59554. g.setImageResamplingQuality (quality);
  59555. g.drawImageTransformed (&temp, temp.getBounds(),
  59556. AffineTransform::scale ((float) scaleFactor, (float) scaleFactor),
  59557. false);
  59558. }
  59559. void MagnifierComponent::childBoundsChanged (Component* c)
  59560. {
  59561. if (c != 0)
  59562. setSize (roundToInt (c->getWidth() * scaleFactor),
  59563. roundToInt (c->getHeight() * scaleFactor));
  59564. }
  59565. void MagnifierComponent::passOnMouseEventToPeer (const MouseEvent& e)
  59566. {
  59567. if (peer != 0)
  59568. mouseSource.handleEvent (peer, Point<int> (scaleInt (e.x), scaleInt (e.y)),
  59569. e.eventTime.toMilliseconds(), ModifierKeys::getCurrentModifiers());
  59570. }
  59571. void MagnifierComponent::mouseDown (const MouseEvent& e)
  59572. {
  59573. passOnMouseEventToPeer (e);
  59574. }
  59575. void MagnifierComponent::mouseUp (const MouseEvent& e)
  59576. {
  59577. passOnMouseEventToPeer (e);
  59578. }
  59579. void MagnifierComponent::mouseDrag (const MouseEvent& e)
  59580. {
  59581. passOnMouseEventToPeer (e);
  59582. }
  59583. void MagnifierComponent::mouseMove (const MouseEvent& e)
  59584. {
  59585. passOnMouseEventToPeer (e);
  59586. }
  59587. void MagnifierComponent::mouseEnter (const MouseEvent& e)
  59588. {
  59589. passOnMouseEventToPeer (e);
  59590. }
  59591. void MagnifierComponent::mouseExit (const MouseEvent& e)
  59592. {
  59593. passOnMouseEventToPeer (e);
  59594. }
  59595. void MagnifierComponent::mouseWheelMove (const MouseEvent& e, float ix, float iy)
  59596. {
  59597. if (peer != 0)
  59598. peer->handleMouseWheel (e.source.getIndex(),
  59599. Point<int> (scaleInt (e.x), scaleInt (e.y)), e.eventTime.toMilliseconds(),
  59600. ix * 256.0f, iy * 256.0f);
  59601. else
  59602. Component::mouseWheelMove (e, ix, iy);
  59603. }
  59604. int MagnifierComponent::scaleInt (const int n) const
  59605. {
  59606. return roundToInt (n / scaleFactor);
  59607. }
  59608. END_JUCE_NAMESPACE
  59609. /*** End of inlined file: juce_MagnifierComponent.cpp ***/
  59610. /*** Start of inlined file: juce_MidiKeyboardComponent.cpp ***/
  59611. BEGIN_JUCE_NAMESPACE
  59612. class MidiKeyboardUpDownButton : public Button
  59613. {
  59614. public:
  59615. MidiKeyboardUpDownButton (MidiKeyboardComponent* const owner_,
  59616. const int delta_)
  59617. : Button (String::empty),
  59618. owner (owner_),
  59619. delta (delta_)
  59620. {
  59621. setOpaque (true);
  59622. }
  59623. ~MidiKeyboardUpDownButton()
  59624. {
  59625. }
  59626. void clicked()
  59627. {
  59628. int note = owner->getLowestVisibleKey();
  59629. if (delta < 0)
  59630. note = (note - 1) / 12;
  59631. else
  59632. note = note / 12 + 1;
  59633. owner->setLowestVisibleKey (note * 12);
  59634. }
  59635. void paintButton (Graphics& g,
  59636. bool isMouseOverButton,
  59637. bool isButtonDown)
  59638. {
  59639. owner->drawUpDownButton (g, getWidth(), getHeight(),
  59640. isMouseOverButton, isButtonDown,
  59641. delta > 0);
  59642. }
  59643. private:
  59644. MidiKeyboardComponent* const owner;
  59645. const int delta;
  59646. MidiKeyboardUpDownButton (const MidiKeyboardUpDownButton&);
  59647. MidiKeyboardUpDownButton& operator= (const MidiKeyboardUpDownButton&);
  59648. };
  59649. MidiKeyboardComponent::MidiKeyboardComponent (MidiKeyboardState& state_,
  59650. const Orientation orientation_)
  59651. : state (state_),
  59652. xOffset (0),
  59653. blackNoteLength (1),
  59654. keyWidth (16.0f),
  59655. orientation (orientation_),
  59656. midiChannel (1),
  59657. midiInChannelMask (0xffff),
  59658. velocity (1.0f),
  59659. noteUnderMouse (-1),
  59660. mouseDownNote (-1),
  59661. rangeStart (0),
  59662. rangeEnd (127),
  59663. firstKey (12 * 4),
  59664. canScroll (true),
  59665. mouseDragging (false),
  59666. useMousePositionForVelocity (true),
  59667. keyMappingOctave (6),
  59668. octaveNumForMiddleC (3)
  59669. {
  59670. addChildComponent (scrollDown = new MidiKeyboardUpDownButton (this, -1));
  59671. addChildComponent (scrollUp = new MidiKeyboardUpDownButton (this, 1));
  59672. // initialise with a default set of querty key-mappings..
  59673. const char* const keymap = "awsedftgyhujkolp;";
  59674. for (int i = String (keymap).length(); --i >= 0;)
  59675. setKeyPressForNote (KeyPress (keymap[i], 0, 0), i);
  59676. setOpaque (true);
  59677. setWantsKeyboardFocus (true);
  59678. state.addListener (this);
  59679. }
  59680. MidiKeyboardComponent::~MidiKeyboardComponent()
  59681. {
  59682. state.removeListener (this);
  59683. jassert (mouseDownNote < 0 && keysPressed.countNumberOfSetBits() == 0); // leaving stuck notes!
  59684. deleteAllChildren();
  59685. }
  59686. void MidiKeyboardComponent::setKeyWidth (const float widthInPixels)
  59687. {
  59688. keyWidth = widthInPixels;
  59689. resized();
  59690. }
  59691. void MidiKeyboardComponent::setOrientation (const Orientation newOrientation)
  59692. {
  59693. if (orientation != newOrientation)
  59694. {
  59695. orientation = newOrientation;
  59696. resized();
  59697. }
  59698. }
  59699. void MidiKeyboardComponent::setAvailableRange (const int lowestNote,
  59700. const int highestNote)
  59701. {
  59702. jassert (lowestNote >= 0 && lowestNote <= 127);
  59703. jassert (highestNote >= 0 && highestNote <= 127);
  59704. jassert (lowestNote <= highestNote);
  59705. if (rangeStart != lowestNote || rangeEnd != highestNote)
  59706. {
  59707. rangeStart = jlimit (0, 127, lowestNote);
  59708. rangeEnd = jlimit (0, 127, highestNote);
  59709. firstKey = jlimit (rangeStart, rangeEnd, firstKey);
  59710. resized();
  59711. }
  59712. }
  59713. void MidiKeyboardComponent::setLowestVisibleKey (int noteNumber)
  59714. {
  59715. noteNumber = jlimit (rangeStart, rangeEnd, noteNumber);
  59716. if (noteNumber != firstKey)
  59717. {
  59718. firstKey = noteNumber;
  59719. sendChangeMessage (this);
  59720. resized();
  59721. }
  59722. }
  59723. void MidiKeyboardComponent::setScrollButtonsVisible (const bool canScroll_)
  59724. {
  59725. if (canScroll != canScroll_)
  59726. {
  59727. canScroll = canScroll_;
  59728. resized();
  59729. }
  59730. }
  59731. void MidiKeyboardComponent::colourChanged()
  59732. {
  59733. repaint();
  59734. }
  59735. void MidiKeyboardComponent::setMidiChannel (const int midiChannelNumber)
  59736. {
  59737. jassert (midiChannelNumber > 0 && midiChannelNumber <= 16);
  59738. if (midiChannel != midiChannelNumber)
  59739. {
  59740. resetAnyKeysInUse();
  59741. midiChannel = jlimit (1, 16, midiChannelNumber);
  59742. }
  59743. }
  59744. void MidiKeyboardComponent::setMidiChannelsToDisplay (const int midiChannelMask)
  59745. {
  59746. midiInChannelMask = midiChannelMask;
  59747. triggerAsyncUpdate();
  59748. }
  59749. void MidiKeyboardComponent::setVelocity (const float velocity_, const bool useMousePositionForVelocity_)
  59750. {
  59751. velocity = jlimit (0.0f, 1.0f, velocity_);
  59752. useMousePositionForVelocity = useMousePositionForVelocity_;
  59753. }
  59754. void MidiKeyboardComponent::getKeyPosition (int midiNoteNumber, const float keyWidth, int& x, int& w) const
  59755. {
  59756. jassert (midiNoteNumber >= 0 && midiNoteNumber < 128);
  59757. static const float blackNoteWidth = 0.7f;
  59758. static const float notePos[] = { 0.0f, 1 - blackNoteWidth * 0.6f,
  59759. 1.0f, 2 - blackNoteWidth * 0.4f,
  59760. 2.0f, 3.0f, 4 - blackNoteWidth * 0.7f,
  59761. 4.0f, 5 - blackNoteWidth * 0.5f,
  59762. 5.0f, 6 - blackNoteWidth * 0.3f,
  59763. 6.0f };
  59764. static const float widths[] = { 1.0f, blackNoteWidth,
  59765. 1.0f, blackNoteWidth,
  59766. 1.0f, 1.0f, blackNoteWidth,
  59767. 1.0f, blackNoteWidth,
  59768. 1.0f, blackNoteWidth,
  59769. 1.0f };
  59770. const int octave = midiNoteNumber / 12;
  59771. const int note = midiNoteNumber % 12;
  59772. x = roundToInt (octave * 7.0f * keyWidth + notePos [note] * keyWidth);
  59773. w = roundToInt (widths [note] * keyWidth);
  59774. }
  59775. void MidiKeyboardComponent::getKeyPos (int midiNoteNumber, int& x, int& w) const
  59776. {
  59777. getKeyPosition (midiNoteNumber, keyWidth, x, w);
  59778. int rx, rw;
  59779. getKeyPosition (rangeStart, keyWidth, rx, rw);
  59780. x -= xOffset + rx;
  59781. }
  59782. int MidiKeyboardComponent::getKeyStartPosition (const int midiNoteNumber) const
  59783. {
  59784. int x, y;
  59785. getKeyPos (midiNoteNumber, x, y);
  59786. return x;
  59787. }
  59788. static const uint8 whiteNotes[] = { 0, 2, 4, 5, 7, 9, 11 };
  59789. static const uint8 blackNotes[] = { 1, 3, 6, 8, 10 };
  59790. int MidiKeyboardComponent::xyToNote (const Point<int>& pos, float& mousePositionVelocity)
  59791. {
  59792. if (! reallyContains (pos.getX(), pos.getY(), false))
  59793. return -1;
  59794. Point<int> p (pos);
  59795. if (orientation != horizontalKeyboard)
  59796. {
  59797. p = Point<int> (p.getY(), p.getX());
  59798. if (orientation == verticalKeyboardFacingLeft)
  59799. p = Point<int> (p.getX(), getWidth() - p.getY());
  59800. else
  59801. p = Point<int> (getHeight() - p.getX(), p.getY());
  59802. }
  59803. return remappedXYToNote (p + Point<int> (xOffset, 0), mousePositionVelocity);
  59804. }
  59805. int MidiKeyboardComponent::remappedXYToNote (const Point<int>& pos, float& mousePositionVelocity) const
  59806. {
  59807. if (pos.getY() < blackNoteLength)
  59808. {
  59809. for (int octaveStart = 12 * (rangeStart / 12); octaveStart <= rangeEnd; octaveStart += 12)
  59810. {
  59811. for (int i = 0; i < 5; ++i)
  59812. {
  59813. const int note = octaveStart + blackNotes [i];
  59814. if (note >= rangeStart && note <= rangeEnd)
  59815. {
  59816. int kx, kw;
  59817. getKeyPos (note, kx, kw);
  59818. kx += xOffset;
  59819. if (pos.getX() >= kx && pos.getX() < kx + kw)
  59820. {
  59821. mousePositionVelocity = pos.getY() / (float) blackNoteLength;
  59822. return note;
  59823. }
  59824. }
  59825. }
  59826. }
  59827. }
  59828. for (int octaveStart = 12 * (rangeStart / 12); octaveStart <= rangeEnd; octaveStart += 12)
  59829. {
  59830. for (int i = 0; i < 7; ++i)
  59831. {
  59832. const int note = octaveStart + whiteNotes [i];
  59833. if (note >= rangeStart && note <= rangeEnd)
  59834. {
  59835. int kx, kw;
  59836. getKeyPos (note, kx, kw);
  59837. kx += xOffset;
  59838. if (pos.getX() >= kx && pos.getX() < kx + kw)
  59839. {
  59840. const int whiteNoteLength = (orientation == horizontalKeyboard) ? getHeight() : getWidth();
  59841. mousePositionVelocity = pos.getY() / (float) whiteNoteLength;
  59842. return note;
  59843. }
  59844. }
  59845. }
  59846. }
  59847. mousePositionVelocity = 0;
  59848. return -1;
  59849. }
  59850. void MidiKeyboardComponent::repaintNote (const int noteNum)
  59851. {
  59852. if (noteNum >= rangeStart && noteNum <= rangeEnd)
  59853. {
  59854. int x, w;
  59855. getKeyPos (noteNum, x, w);
  59856. if (orientation == horizontalKeyboard)
  59857. repaint (x, 0, w, getHeight());
  59858. else if (orientation == verticalKeyboardFacingLeft)
  59859. repaint (0, x, getWidth(), w);
  59860. else if (orientation == verticalKeyboardFacingRight)
  59861. repaint (0, getHeight() - x - w, getWidth(), w);
  59862. }
  59863. }
  59864. void MidiKeyboardComponent::paint (Graphics& g)
  59865. {
  59866. g.fillAll (Colours::white.overlaidWith (findColour (whiteNoteColourId)));
  59867. const Colour lineColour (findColour (keySeparatorLineColourId));
  59868. const Colour textColour (findColour (textLabelColourId));
  59869. int x, w, octave;
  59870. for (octave = 0; octave < 128; octave += 12)
  59871. {
  59872. for (int white = 0; white < 7; ++white)
  59873. {
  59874. const int noteNum = octave + whiteNotes [white];
  59875. if (noteNum >= rangeStart && noteNum <= rangeEnd)
  59876. {
  59877. getKeyPos (noteNum, x, w);
  59878. if (orientation == horizontalKeyboard)
  59879. drawWhiteNote (noteNum, g, x, 0, w, getHeight(),
  59880. state.isNoteOnForChannels (midiInChannelMask, noteNum),
  59881. noteUnderMouse == noteNum,
  59882. lineColour, textColour);
  59883. else if (orientation == verticalKeyboardFacingLeft)
  59884. drawWhiteNote (noteNum, g, 0, x, getWidth(), w,
  59885. state.isNoteOnForChannels (midiInChannelMask, noteNum),
  59886. noteUnderMouse == noteNum,
  59887. lineColour, textColour);
  59888. else if (orientation == verticalKeyboardFacingRight)
  59889. drawWhiteNote (noteNum, g, 0, getHeight() - x - w, getWidth(), w,
  59890. state.isNoteOnForChannels (midiInChannelMask, noteNum),
  59891. noteUnderMouse == noteNum,
  59892. lineColour, textColour);
  59893. }
  59894. }
  59895. }
  59896. float x1 = 0.0f, y1 = 0.0f, x2 = 0.0f, y2 = 0.0f;
  59897. if (orientation == verticalKeyboardFacingLeft)
  59898. {
  59899. x1 = getWidth() - 1.0f;
  59900. x2 = getWidth() - 5.0f;
  59901. }
  59902. else if (orientation == verticalKeyboardFacingRight)
  59903. x2 = 5.0f;
  59904. else
  59905. y2 = 5.0f;
  59906. g.setGradientFill (ColourGradient (Colours::black.withAlpha (0.3f), x1, y1,
  59907. Colours::transparentBlack, x2, y2, false));
  59908. getKeyPos (rangeEnd, x, w);
  59909. x += w;
  59910. if (orientation == verticalKeyboardFacingLeft)
  59911. g.fillRect (getWidth() - 5, 0, 5, x);
  59912. else if (orientation == verticalKeyboardFacingRight)
  59913. g.fillRect (0, 0, 5, x);
  59914. else
  59915. g.fillRect (0, 0, x, 5);
  59916. g.setColour (lineColour);
  59917. if (orientation == verticalKeyboardFacingLeft)
  59918. g.fillRect (0, 0, 1, x);
  59919. else if (orientation == verticalKeyboardFacingRight)
  59920. g.fillRect (getWidth() - 1, 0, 1, x);
  59921. else
  59922. g.fillRect (0, getHeight() - 1, x, 1);
  59923. const Colour blackNoteColour (findColour (blackNoteColourId));
  59924. for (octave = 0; octave < 128; octave += 12)
  59925. {
  59926. for (int black = 0; black < 5; ++black)
  59927. {
  59928. const int noteNum = octave + blackNotes [black];
  59929. if (noteNum >= rangeStart && noteNum <= rangeEnd)
  59930. {
  59931. getKeyPos (noteNum, x, w);
  59932. if (orientation == horizontalKeyboard)
  59933. drawBlackNote (noteNum, g, x, 0, w, blackNoteLength,
  59934. state.isNoteOnForChannels (midiInChannelMask, noteNum),
  59935. noteUnderMouse == noteNum,
  59936. blackNoteColour);
  59937. else if (orientation == verticalKeyboardFacingLeft)
  59938. drawBlackNote (noteNum, g, getWidth() - blackNoteLength, x, blackNoteLength, w,
  59939. state.isNoteOnForChannels (midiInChannelMask, noteNum),
  59940. noteUnderMouse == noteNum,
  59941. blackNoteColour);
  59942. else if (orientation == verticalKeyboardFacingRight)
  59943. drawBlackNote (noteNum, g, 0, getHeight() - x - w, blackNoteLength, w,
  59944. state.isNoteOnForChannels (midiInChannelMask, noteNum),
  59945. noteUnderMouse == noteNum,
  59946. blackNoteColour);
  59947. }
  59948. }
  59949. }
  59950. }
  59951. void MidiKeyboardComponent::drawWhiteNote (int midiNoteNumber,
  59952. Graphics& g, int x, int y, int w, int h,
  59953. bool isDown, bool isOver,
  59954. const Colour& lineColour,
  59955. const Colour& textColour)
  59956. {
  59957. Colour c (Colours::transparentWhite);
  59958. if (isDown)
  59959. c = findColour (keyDownOverlayColourId);
  59960. if (isOver)
  59961. c = c.overlaidWith (findColour (mouseOverKeyOverlayColourId));
  59962. g.setColour (c);
  59963. g.fillRect (x, y, w, h);
  59964. const String text (getWhiteNoteText (midiNoteNumber));
  59965. if (! text.isEmpty())
  59966. {
  59967. g.setColour (textColour);
  59968. Font f (jmin (12.0f, keyWidth * 0.9f));
  59969. f.setHorizontalScale (0.8f);
  59970. g.setFont (f);
  59971. Justification justification (Justification::centredBottom);
  59972. if (orientation == verticalKeyboardFacingLeft)
  59973. justification = Justification::centredLeft;
  59974. else if (orientation == verticalKeyboardFacingRight)
  59975. justification = Justification::centredRight;
  59976. g.drawFittedText (text, x + 2, y + 2, w - 4, h - 4, justification, 1);
  59977. }
  59978. g.setColour (lineColour);
  59979. if (orientation == horizontalKeyboard)
  59980. g.fillRect (x, y, 1, h);
  59981. else if (orientation == verticalKeyboardFacingLeft)
  59982. g.fillRect (x, y, w, 1);
  59983. else if (orientation == verticalKeyboardFacingRight)
  59984. g.fillRect (x, y + h - 1, w, 1);
  59985. if (midiNoteNumber == rangeEnd)
  59986. {
  59987. if (orientation == horizontalKeyboard)
  59988. g.fillRect (x + w, y, 1, h);
  59989. else if (orientation == verticalKeyboardFacingLeft)
  59990. g.fillRect (x, y + h, w, 1);
  59991. else if (orientation == verticalKeyboardFacingRight)
  59992. g.fillRect (x, y - 1, w, 1);
  59993. }
  59994. }
  59995. void MidiKeyboardComponent::drawBlackNote (int /*midiNoteNumber*/,
  59996. Graphics& g, int x, int y, int w, int h,
  59997. bool isDown, bool isOver,
  59998. const Colour& noteFillColour)
  59999. {
  60000. Colour c (noteFillColour);
  60001. if (isDown)
  60002. c = c.overlaidWith (findColour (keyDownOverlayColourId));
  60003. if (isOver)
  60004. c = c.overlaidWith (findColour (mouseOverKeyOverlayColourId));
  60005. g.setColour (c);
  60006. g.fillRect (x, y, w, h);
  60007. if (isDown)
  60008. {
  60009. g.setColour (noteFillColour);
  60010. g.drawRect (x, y, w, h);
  60011. }
  60012. else
  60013. {
  60014. const int xIndent = jmax (1, jmin (w, h) / 8);
  60015. g.setColour (c.brighter());
  60016. if (orientation == horizontalKeyboard)
  60017. g.fillRect (x + xIndent, y, w - xIndent * 2, 7 * h / 8);
  60018. else if (orientation == verticalKeyboardFacingLeft)
  60019. g.fillRect (x + w / 8, y + xIndent, w - w / 8, h - xIndent * 2);
  60020. else if (orientation == verticalKeyboardFacingRight)
  60021. g.fillRect (x, y + xIndent, 7 * w / 8, h - xIndent * 2);
  60022. }
  60023. }
  60024. void MidiKeyboardComponent::setOctaveForMiddleC (const int octaveNumForMiddleC_) throw()
  60025. {
  60026. octaveNumForMiddleC = octaveNumForMiddleC_;
  60027. repaint();
  60028. }
  60029. const String MidiKeyboardComponent::getWhiteNoteText (const int midiNoteNumber)
  60030. {
  60031. if (keyWidth > 14.0f && midiNoteNumber % 12 == 0)
  60032. return MidiMessage::getMidiNoteName (midiNoteNumber, true, true, octaveNumForMiddleC);
  60033. return String::empty;
  60034. }
  60035. void MidiKeyboardComponent::drawUpDownButton (Graphics& g, int w, int h,
  60036. const bool isMouseOver,
  60037. const bool isButtonDown,
  60038. const bool movesOctavesUp)
  60039. {
  60040. g.fillAll (findColour (upDownButtonBackgroundColourId));
  60041. float angle;
  60042. if (orientation == MidiKeyboardComponent::horizontalKeyboard)
  60043. angle = movesOctavesUp ? 0.0f : 0.5f;
  60044. else if (orientation == MidiKeyboardComponent::verticalKeyboardFacingLeft)
  60045. angle = movesOctavesUp ? 0.25f : 0.75f;
  60046. else
  60047. angle = movesOctavesUp ? 0.75f : 0.25f;
  60048. Path path;
  60049. path.lineTo (0.0f, 1.0f);
  60050. path.lineTo (1.0f, 0.5f);
  60051. path.closeSubPath();
  60052. path.applyTransform (AffineTransform::rotation (float_Pi * 2.0f * angle, 0.5f, 0.5f));
  60053. g.setColour (findColour (upDownButtonArrowColourId)
  60054. .withAlpha (isButtonDown ? 1.0f : (isMouseOver ? 0.6f : 0.4f)));
  60055. g.fillPath (path, path.getTransformToScaleToFit (1.0f, 1.0f,
  60056. w - 2.0f,
  60057. h - 2.0f,
  60058. true));
  60059. }
  60060. void MidiKeyboardComponent::resized()
  60061. {
  60062. int w = getWidth();
  60063. int h = getHeight();
  60064. if (w > 0 && h > 0)
  60065. {
  60066. if (orientation != horizontalKeyboard)
  60067. swapVariables (w, h);
  60068. blackNoteLength = roundToInt (h * 0.7f);
  60069. int kx2, kw2;
  60070. getKeyPos (rangeEnd, kx2, kw2);
  60071. kx2 += kw2;
  60072. if (firstKey != rangeStart)
  60073. {
  60074. int kx1, kw1;
  60075. getKeyPos (rangeStart, kx1, kw1);
  60076. if (kx2 - kx1 <= w)
  60077. {
  60078. firstKey = rangeStart;
  60079. sendChangeMessage (this);
  60080. repaint();
  60081. }
  60082. }
  60083. const bool showScrollButtons = canScroll && (firstKey > rangeStart || kx2 > w + xOffset * 2);
  60084. scrollDown->setVisible (showScrollButtons);
  60085. scrollUp->setVisible (showScrollButtons);
  60086. xOffset = 0;
  60087. if (showScrollButtons)
  60088. {
  60089. const int scrollButtonW = jmin (12, w / 2);
  60090. if (orientation == horizontalKeyboard)
  60091. {
  60092. scrollDown->setBounds (0, 0, scrollButtonW, getHeight());
  60093. scrollUp->setBounds (getWidth() - scrollButtonW, 0, scrollButtonW, getHeight());
  60094. }
  60095. else if (orientation == verticalKeyboardFacingLeft)
  60096. {
  60097. scrollDown->setBounds (0, 0, getWidth(), scrollButtonW);
  60098. scrollUp->setBounds (0, getHeight() - scrollButtonW, getWidth(), scrollButtonW);
  60099. }
  60100. else if (orientation == verticalKeyboardFacingRight)
  60101. {
  60102. scrollDown->setBounds (0, getHeight() - scrollButtonW, getWidth(), scrollButtonW);
  60103. scrollUp->setBounds (0, 0, getWidth(), scrollButtonW);
  60104. }
  60105. int endOfLastKey, kw;
  60106. getKeyPos (rangeEnd, endOfLastKey, kw);
  60107. endOfLastKey += kw;
  60108. float mousePositionVelocity;
  60109. const int spaceAvailable = w - scrollButtonW * 2;
  60110. const int lastStartKey = remappedXYToNote (Point<int> (endOfLastKey - spaceAvailable, 0), mousePositionVelocity) + 1;
  60111. if (lastStartKey >= 0 && firstKey > lastStartKey)
  60112. {
  60113. firstKey = jlimit (rangeStart, rangeEnd, lastStartKey);
  60114. sendChangeMessage (this);
  60115. }
  60116. int newOffset = 0;
  60117. getKeyPos (firstKey, newOffset, kw);
  60118. xOffset = newOffset - scrollButtonW;
  60119. }
  60120. else
  60121. {
  60122. firstKey = rangeStart;
  60123. }
  60124. timerCallback();
  60125. repaint();
  60126. }
  60127. }
  60128. void MidiKeyboardComponent::handleNoteOn (MidiKeyboardState*, int /*midiChannel*/, int /*midiNoteNumber*/, float /*velocity*/)
  60129. {
  60130. triggerAsyncUpdate();
  60131. }
  60132. void MidiKeyboardComponent::handleNoteOff (MidiKeyboardState*, int /*midiChannel*/, int /*midiNoteNumber*/)
  60133. {
  60134. triggerAsyncUpdate();
  60135. }
  60136. void MidiKeyboardComponent::handleAsyncUpdate()
  60137. {
  60138. for (int i = rangeStart; i <= rangeEnd; ++i)
  60139. {
  60140. if (keysCurrentlyDrawnDown[i] != state.isNoteOnForChannels (midiInChannelMask, i))
  60141. {
  60142. keysCurrentlyDrawnDown.setBit (i, state.isNoteOnForChannels (midiInChannelMask, i));
  60143. repaintNote (i);
  60144. }
  60145. }
  60146. }
  60147. void MidiKeyboardComponent::resetAnyKeysInUse()
  60148. {
  60149. if (keysPressed.countNumberOfSetBits() > 0 || mouseDownNote > 0)
  60150. {
  60151. state.allNotesOff (midiChannel);
  60152. keysPressed.clear();
  60153. mouseDownNote = -1;
  60154. }
  60155. }
  60156. void MidiKeyboardComponent::updateNoteUnderMouse (const Point<int>& pos)
  60157. {
  60158. float mousePositionVelocity = 0.0f;
  60159. const int newNote = (mouseDragging || isMouseOver())
  60160. ? xyToNote (pos, mousePositionVelocity) : -1;
  60161. if (noteUnderMouse != newNote)
  60162. {
  60163. if (mouseDownNote >= 0)
  60164. {
  60165. state.noteOff (midiChannel, mouseDownNote);
  60166. mouseDownNote = -1;
  60167. }
  60168. if (mouseDragging && newNote >= 0)
  60169. {
  60170. if (! useMousePositionForVelocity)
  60171. mousePositionVelocity = 1.0f;
  60172. state.noteOn (midiChannel, newNote, mousePositionVelocity * velocity);
  60173. mouseDownNote = newNote;
  60174. }
  60175. repaintNote (noteUnderMouse);
  60176. noteUnderMouse = newNote;
  60177. repaintNote (noteUnderMouse);
  60178. }
  60179. else if (mouseDownNote >= 0 && ! mouseDragging)
  60180. {
  60181. state.noteOff (midiChannel, mouseDownNote);
  60182. mouseDownNote = -1;
  60183. }
  60184. }
  60185. void MidiKeyboardComponent::mouseMove (const MouseEvent& e)
  60186. {
  60187. updateNoteUnderMouse (e.getPosition());
  60188. stopTimer();
  60189. }
  60190. void MidiKeyboardComponent::mouseDrag (const MouseEvent& e)
  60191. {
  60192. float mousePositionVelocity;
  60193. const int newNote = xyToNote (e.getPosition(), mousePositionVelocity);
  60194. if (newNote >= 0)
  60195. mouseDraggedToKey (newNote, e);
  60196. updateNoteUnderMouse (e.getPosition());
  60197. }
  60198. bool MidiKeyboardComponent::mouseDownOnKey (int /*midiNoteNumber*/, const MouseEvent&)
  60199. {
  60200. return true;
  60201. }
  60202. void MidiKeyboardComponent::mouseDraggedToKey (int /*midiNoteNumber*/, const MouseEvent&)
  60203. {
  60204. }
  60205. void MidiKeyboardComponent::mouseDown (const MouseEvent& e)
  60206. {
  60207. float mousePositionVelocity;
  60208. const int newNote = xyToNote (e.getPosition(), mousePositionVelocity);
  60209. mouseDragging = false;
  60210. if (newNote >= 0 && mouseDownOnKey (newNote, e))
  60211. {
  60212. repaintNote (noteUnderMouse);
  60213. noteUnderMouse = -1;
  60214. mouseDragging = true;
  60215. updateNoteUnderMouse (e.getPosition());
  60216. startTimer (500);
  60217. }
  60218. }
  60219. void MidiKeyboardComponent::mouseUp (const MouseEvent& e)
  60220. {
  60221. mouseDragging = false;
  60222. updateNoteUnderMouse (e.getPosition());
  60223. stopTimer();
  60224. }
  60225. void MidiKeyboardComponent::mouseEnter (const MouseEvent& e)
  60226. {
  60227. updateNoteUnderMouse (e.getPosition());
  60228. }
  60229. void MidiKeyboardComponent::mouseExit (const MouseEvent& e)
  60230. {
  60231. updateNoteUnderMouse (e.getPosition());
  60232. }
  60233. void MidiKeyboardComponent::mouseWheelMove (const MouseEvent&, float ix, float iy)
  60234. {
  60235. setLowestVisibleKey (getLowestVisibleKey() + roundToInt ((ix != 0 ? ix : iy) * 5.0f));
  60236. }
  60237. void MidiKeyboardComponent::timerCallback()
  60238. {
  60239. updateNoteUnderMouse (getMouseXYRelative());
  60240. }
  60241. void MidiKeyboardComponent::clearKeyMappings()
  60242. {
  60243. resetAnyKeysInUse();
  60244. keyPressNotes.clear();
  60245. keyPresses.clear();
  60246. }
  60247. void MidiKeyboardComponent::setKeyPressForNote (const KeyPress& key,
  60248. const int midiNoteOffsetFromC)
  60249. {
  60250. removeKeyPressForNote (midiNoteOffsetFromC);
  60251. keyPressNotes.add (midiNoteOffsetFromC);
  60252. keyPresses.add (key);
  60253. }
  60254. void MidiKeyboardComponent::removeKeyPressForNote (const int midiNoteOffsetFromC)
  60255. {
  60256. for (int i = keyPressNotes.size(); --i >= 0;)
  60257. {
  60258. if (keyPressNotes.getUnchecked (i) == midiNoteOffsetFromC)
  60259. {
  60260. keyPressNotes.remove (i);
  60261. keyPresses.remove (i);
  60262. }
  60263. }
  60264. }
  60265. void MidiKeyboardComponent::setKeyPressBaseOctave (const int newOctaveNumber)
  60266. {
  60267. jassert (newOctaveNumber >= 0 && newOctaveNumber <= 10);
  60268. keyMappingOctave = newOctaveNumber;
  60269. }
  60270. bool MidiKeyboardComponent::keyStateChanged (const bool /*isKeyDown*/)
  60271. {
  60272. bool keyPressUsed = false;
  60273. for (int i = keyPresses.size(); --i >= 0;)
  60274. {
  60275. const int note = 12 * keyMappingOctave + keyPressNotes.getUnchecked (i);
  60276. if (keyPresses.getReference(i).isCurrentlyDown())
  60277. {
  60278. if (! keysPressed [note])
  60279. {
  60280. keysPressed.setBit (note);
  60281. state.noteOn (midiChannel, note, velocity);
  60282. keyPressUsed = true;
  60283. }
  60284. }
  60285. else
  60286. {
  60287. if (keysPressed [note])
  60288. {
  60289. keysPressed.clearBit (note);
  60290. state.noteOff (midiChannel, note);
  60291. keyPressUsed = true;
  60292. }
  60293. }
  60294. }
  60295. return keyPressUsed;
  60296. }
  60297. void MidiKeyboardComponent::focusLost (FocusChangeType)
  60298. {
  60299. resetAnyKeysInUse();
  60300. }
  60301. END_JUCE_NAMESPACE
  60302. /*** End of inlined file: juce_MidiKeyboardComponent.cpp ***/
  60303. /*** Start of inlined file: juce_OpenGLComponent.cpp ***/
  60304. #if JUCE_OPENGL
  60305. BEGIN_JUCE_NAMESPACE
  60306. extern void juce_glViewport (const int w, const int h);
  60307. OpenGLPixelFormat::OpenGLPixelFormat (const int bitsPerRGBComponent,
  60308. const int alphaBits_,
  60309. const int depthBufferBits_,
  60310. const int stencilBufferBits_)
  60311. : redBits (bitsPerRGBComponent),
  60312. greenBits (bitsPerRGBComponent),
  60313. blueBits (bitsPerRGBComponent),
  60314. alphaBits (alphaBits_),
  60315. depthBufferBits (depthBufferBits_),
  60316. stencilBufferBits (stencilBufferBits_),
  60317. accumulationBufferRedBits (0),
  60318. accumulationBufferGreenBits (0),
  60319. accumulationBufferBlueBits (0),
  60320. accumulationBufferAlphaBits (0),
  60321. fullSceneAntiAliasingNumSamples (0)
  60322. {
  60323. }
  60324. OpenGLPixelFormat::OpenGLPixelFormat (const OpenGLPixelFormat& other)
  60325. : redBits (other.redBits),
  60326. greenBits (other.greenBits),
  60327. blueBits (other.blueBits),
  60328. alphaBits (other.alphaBits),
  60329. depthBufferBits (other.depthBufferBits),
  60330. stencilBufferBits (other.stencilBufferBits),
  60331. accumulationBufferRedBits (other.accumulationBufferRedBits),
  60332. accumulationBufferGreenBits (other.accumulationBufferGreenBits),
  60333. accumulationBufferBlueBits (other.accumulationBufferBlueBits),
  60334. accumulationBufferAlphaBits (other.accumulationBufferAlphaBits),
  60335. fullSceneAntiAliasingNumSamples (other.fullSceneAntiAliasingNumSamples)
  60336. {
  60337. }
  60338. OpenGLPixelFormat& OpenGLPixelFormat::operator= (const OpenGLPixelFormat& other)
  60339. {
  60340. redBits = other.redBits;
  60341. greenBits = other.greenBits;
  60342. blueBits = other.blueBits;
  60343. alphaBits = other.alphaBits;
  60344. depthBufferBits = other.depthBufferBits;
  60345. stencilBufferBits = other.stencilBufferBits;
  60346. accumulationBufferRedBits = other.accumulationBufferRedBits;
  60347. accumulationBufferGreenBits = other.accumulationBufferGreenBits;
  60348. accumulationBufferBlueBits = other.accumulationBufferBlueBits;
  60349. accumulationBufferAlphaBits = other.accumulationBufferAlphaBits;
  60350. fullSceneAntiAliasingNumSamples = other.fullSceneAntiAliasingNumSamples;
  60351. return *this;
  60352. }
  60353. bool OpenGLPixelFormat::operator== (const OpenGLPixelFormat& other) const
  60354. {
  60355. return redBits == other.redBits
  60356. && greenBits == other.greenBits
  60357. && blueBits == other.blueBits
  60358. && alphaBits == other.alphaBits
  60359. && depthBufferBits == other.depthBufferBits
  60360. && stencilBufferBits == other.stencilBufferBits
  60361. && accumulationBufferRedBits == other.accumulationBufferRedBits
  60362. && accumulationBufferGreenBits == other.accumulationBufferGreenBits
  60363. && accumulationBufferBlueBits == other.accumulationBufferBlueBits
  60364. && accumulationBufferAlphaBits == other.accumulationBufferAlphaBits
  60365. && fullSceneAntiAliasingNumSamples == other.fullSceneAntiAliasingNumSamples;
  60366. }
  60367. static VoidArray knownContexts;
  60368. OpenGLContext::OpenGLContext() throw()
  60369. {
  60370. knownContexts.add (this);
  60371. }
  60372. OpenGLContext::~OpenGLContext()
  60373. {
  60374. knownContexts.removeValue (this);
  60375. }
  60376. OpenGLContext* OpenGLContext::getCurrentContext()
  60377. {
  60378. for (int i = knownContexts.size(); --i >= 0;)
  60379. {
  60380. OpenGLContext* const oglc = (OpenGLContext*) knownContexts.getUnchecked(i);
  60381. if (oglc->isActive())
  60382. return oglc;
  60383. }
  60384. return 0;
  60385. }
  60386. class OpenGLComponent::OpenGLComponentWatcher : public ComponentMovementWatcher
  60387. {
  60388. public:
  60389. OpenGLComponentWatcher (OpenGLComponent* const owner_)
  60390. : ComponentMovementWatcher (owner_),
  60391. owner (owner_),
  60392. wasShowing (false)
  60393. {
  60394. }
  60395. ~OpenGLComponentWatcher() {}
  60396. void componentMovedOrResized (bool /*wasMoved*/, bool /*wasResized*/)
  60397. {
  60398. owner->updateContextPosition();
  60399. }
  60400. void componentPeerChanged()
  60401. {
  60402. const ScopedLock sl (owner->getContextLock());
  60403. owner->deleteContext();
  60404. }
  60405. void componentVisibilityChanged (Component&)
  60406. {
  60407. const bool isShowingNow = owner->isShowing();
  60408. if (wasShowing != isShowingNow)
  60409. {
  60410. wasShowing = isShowingNow;
  60411. owner->updateContextPosition();
  60412. }
  60413. }
  60414. juce_UseDebuggingNewOperator
  60415. private:
  60416. OpenGLComponent* const owner;
  60417. bool wasShowing;
  60418. };
  60419. OpenGLComponent::OpenGLComponent (const OpenGLType type_)
  60420. : type (type_),
  60421. context (0),
  60422. contextToShareListsWith (0),
  60423. needToUpdateViewport (true)
  60424. {
  60425. setOpaque (true);
  60426. componentWatcher = new OpenGLComponentWatcher (this);
  60427. }
  60428. OpenGLComponent::~OpenGLComponent()
  60429. {
  60430. deleteContext();
  60431. componentWatcher = 0;
  60432. }
  60433. void OpenGLComponent::deleteContext()
  60434. {
  60435. const ScopedLock sl (contextLock);
  60436. deleteAndZero (context);
  60437. }
  60438. void OpenGLComponent::updateContextPosition()
  60439. {
  60440. needToUpdateViewport = true;
  60441. if (getWidth() > 0 && getHeight() > 0)
  60442. {
  60443. Component* const topComp = getTopLevelComponent();
  60444. if (topComp->getPeer() != 0)
  60445. {
  60446. const ScopedLock sl (contextLock);
  60447. if (context != 0)
  60448. context->updateWindowPosition (getScreenX() - topComp->getScreenX(),
  60449. getScreenY() - topComp->getScreenY(),
  60450. getWidth(),
  60451. getHeight(),
  60452. topComp->getHeight());
  60453. }
  60454. }
  60455. }
  60456. const OpenGLPixelFormat OpenGLComponent::getPixelFormat() const
  60457. {
  60458. OpenGLPixelFormat pf;
  60459. const ScopedLock sl (contextLock);
  60460. if (context != 0)
  60461. pf = context->getPixelFormat();
  60462. return pf;
  60463. }
  60464. void OpenGLComponent::setPixelFormat (const OpenGLPixelFormat& formatToUse)
  60465. {
  60466. if (! (preferredPixelFormat == formatToUse))
  60467. {
  60468. const ScopedLock sl (contextLock);
  60469. deleteContext();
  60470. preferredPixelFormat = formatToUse;
  60471. }
  60472. }
  60473. void OpenGLComponent::shareWith (OpenGLContext* c)
  60474. {
  60475. if (contextToShareListsWith != c)
  60476. {
  60477. const ScopedLock sl (contextLock);
  60478. deleteContext();
  60479. contextToShareListsWith = c;
  60480. }
  60481. }
  60482. bool OpenGLComponent::makeCurrentContextActive()
  60483. {
  60484. if (context == 0)
  60485. {
  60486. const ScopedLock sl (contextLock);
  60487. if (isShowing() && getTopLevelComponent()->getPeer() != 0)
  60488. {
  60489. context = createContext();
  60490. if (context != 0)
  60491. {
  60492. updateContextPosition();
  60493. if (context->makeActive())
  60494. newOpenGLContextCreated();
  60495. }
  60496. }
  60497. }
  60498. return context != 0 && context->makeActive();
  60499. }
  60500. void OpenGLComponent::makeCurrentContextInactive()
  60501. {
  60502. if (context != 0)
  60503. context->makeInactive();
  60504. }
  60505. bool OpenGLComponent::isActiveContext() const throw()
  60506. {
  60507. return context != 0 && context->isActive();
  60508. }
  60509. void OpenGLComponent::swapBuffers()
  60510. {
  60511. if (context != 0)
  60512. context->swapBuffers();
  60513. }
  60514. void OpenGLComponent::paint (Graphics&)
  60515. {
  60516. if (renderAndSwapBuffers())
  60517. {
  60518. ComponentPeer* const peer = getPeer();
  60519. if (peer != 0)
  60520. {
  60521. const Point<int> topLeft (getScreenPosition() - peer->getScreenPosition());
  60522. peer->addMaskedRegion (topLeft.getX(), topLeft.getY(), getWidth(), getHeight());
  60523. }
  60524. }
  60525. }
  60526. bool OpenGLComponent::renderAndSwapBuffers()
  60527. {
  60528. const ScopedLock sl (contextLock);
  60529. if (! makeCurrentContextActive())
  60530. return false;
  60531. if (needToUpdateViewport)
  60532. {
  60533. needToUpdateViewport = false;
  60534. juce_glViewport (getWidth(), getHeight());
  60535. }
  60536. renderOpenGL();
  60537. swapBuffers();
  60538. return true;
  60539. }
  60540. void OpenGLComponent::internalRepaint (int x, int y, int w, int h)
  60541. {
  60542. Component::internalRepaint (x, y, w, h);
  60543. if (context != 0)
  60544. context->repaint();
  60545. }
  60546. END_JUCE_NAMESPACE
  60547. #endif
  60548. /*** End of inlined file: juce_OpenGLComponent.cpp ***/
  60549. /*** Start of inlined file: juce_PreferencesPanel.cpp ***/
  60550. BEGIN_JUCE_NAMESPACE
  60551. PreferencesPanel::PreferencesPanel()
  60552. : buttonSize (70)
  60553. {
  60554. }
  60555. PreferencesPanel::~PreferencesPanel()
  60556. {
  60557. currentPage = 0;
  60558. deleteAllChildren();
  60559. }
  60560. void PreferencesPanel::addSettingsPage (const String& title,
  60561. const Drawable* icon,
  60562. const Drawable* overIcon,
  60563. const Drawable* downIcon)
  60564. {
  60565. DrawableButton* button = new DrawableButton (title, DrawableButton::ImageAboveTextLabel);
  60566. button->setImages (icon, overIcon, downIcon);
  60567. button->setRadioGroupId (1);
  60568. button->addButtonListener (this);
  60569. button->setClickingTogglesState (true);
  60570. button->setWantsKeyboardFocus (false);
  60571. addAndMakeVisible (button);
  60572. resized();
  60573. if (currentPage == 0)
  60574. setCurrentPage (title);
  60575. }
  60576. void PreferencesPanel::addSettingsPage (const String& title,
  60577. const char* imageData,
  60578. const int imageDataSize)
  60579. {
  60580. DrawableImage icon, iconOver, iconDown;
  60581. icon.setImage (ImageCache::getFromMemory (imageData, imageDataSize), true);
  60582. iconOver.setImage (ImageCache::getFromMemory (imageData, imageDataSize), true);
  60583. iconOver.setOverlayColour (Colours::black.withAlpha (0.12f));
  60584. iconDown.setImage (ImageCache::getFromMemory (imageData, imageDataSize), true);
  60585. iconDown.setOverlayColour (Colours::black.withAlpha (0.25f));
  60586. addSettingsPage (title, &icon, &iconOver, &iconDown);
  60587. }
  60588. class PrefsDialogWindow : public DialogWindow
  60589. {
  60590. public:
  60591. PrefsDialogWindow (const String& dialogtitle,
  60592. const Colour& backgroundColour)
  60593. : DialogWindow (dialogtitle, backgroundColour, true)
  60594. {
  60595. }
  60596. ~PrefsDialogWindow()
  60597. {
  60598. }
  60599. void closeButtonPressed()
  60600. {
  60601. exitModalState (0);
  60602. }
  60603. private:
  60604. PrefsDialogWindow (const PrefsDialogWindow&);
  60605. PrefsDialogWindow& operator= (const PrefsDialogWindow&);
  60606. };
  60607. void PreferencesPanel::showInDialogBox (const String& dialogtitle,
  60608. int dialogWidth,
  60609. int dialogHeight,
  60610. const Colour& backgroundColour)
  60611. {
  60612. setSize (dialogWidth, dialogHeight);
  60613. PrefsDialogWindow dw (dialogtitle, backgroundColour);
  60614. dw.setContentComponent (this, true, true);
  60615. dw.centreAroundComponent (0, dw.getWidth(), dw.getHeight());
  60616. dw.runModalLoop();
  60617. dw.setContentComponent (0, false, false);
  60618. }
  60619. void PreferencesPanel::resized()
  60620. {
  60621. int x = 0;
  60622. for (int i = 0; i < getNumChildComponents(); ++i)
  60623. {
  60624. Component* c = getChildComponent (i);
  60625. if (dynamic_cast <DrawableButton*> (c) == 0)
  60626. {
  60627. c->setBounds (0, buttonSize + 5, getWidth(), getHeight() - buttonSize - 5);
  60628. }
  60629. else
  60630. {
  60631. c->setBounds (x, 0, buttonSize, buttonSize);
  60632. x += buttonSize;
  60633. }
  60634. }
  60635. }
  60636. void PreferencesPanel::paint (Graphics& g)
  60637. {
  60638. g.setColour (Colours::grey);
  60639. g.fillRect (0, buttonSize + 2, getWidth(), 1);
  60640. }
  60641. void PreferencesPanel::setCurrentPage (const String& pageName)
  60642. {
  60643. if (currentPageName != pageName)
  60644. {
  60645. currentPageName = pageName;
  60646. currentPage = 0;
  60647. currentPage = createComponentForPage (pageName);
  60648. if (currentPage != 0)
  60649. {
  60650. addAndMakeVisible (currentPage);
  60651. currentPage->toBack();
  60652. resized();
  60653. }
  60654. for (int i = 0; i < getNumChildComponents(); ++i)
  60655. {
  60656. DrawableButton* db = dynamic_cast <DrawableButton*> (getChildComponent (i));
  60657. if (db != 0 && db->getName() == pageName)
  60658. {
  60659. db->setToggleState (true, false);
  60660. break;
  60661. }
  60662. }
  60663. }
  60664. }
  60665. void PreferencesPanel::buttonClicked (Button*)
  60666. {
  60667. for (int i = 0; i < getNumChildComponents(); ++i)
  60668. {
  60669. DrawableButton* db = dynamic_cast <DrawableButton*> (getChildComponent (i));
  60670. if (db != 0 && db->getToggleState())
  60671. {
  60672. setCurrentPage (db->getName());
  60673. break;
  60674. }
  60675. }
  60676. }
  60677. END_JUCE_NAMESPACE
  60678. /*** End of inlined file: juce_PreferencesPanel.cpp ***/
  60679. /*** Start of inlined file: juce_SystemTrayIconComponent.cpp ***/
  60680. #if JUCE_WINDOWS || JUCE_LINUX
  60681. BEGIN_JUCE_NAMESPACE
  60682. SystemTrayIconComponent::SystemTrayIconComponent()
  60683. {
  60684. addToDesktop (0);
  60685. }
  60686. SystemTrayIconComponent::~SystemTrayIconComponent()
  60687. {
  60688. }
  60689. END_JUCE_NAMESPACE
  60690. #endif
  60691. /*** End of inlined file: juce_SystemTrayIconComponent.cpp ***/
  60692. /*** Start of inlined file: juce_AlertWindow.cpp ***/
  60693. BEGIN_JUCE_NAMESPACE
  60694. static const int titleH = 24;
  60695. static const int iconWidth = 80;
  60696. class AlertWindowTextEditor : public TextEditor
  60697. {
  60698. public:
  60699. static const tchar passwordChar;
  60700. AlertWindowTextEditor (const String& name, const bool isPasswordBox)
  60701. : TextEditor (name, isPasswordBox ? passwordChar : 0)
  60702. {
  60703. setSelectAllWhenFocused (true);
  60704. }
  60705. ~AlertWindowTextEditor()
  60706. {
  60707. }
  60708. void returnPressed()
  60709. {
  60710. // pass these up the component hierarchy to be trigger the buttons
  60711. getParentComponent()->keyPressed (KeyPress (KeyPress::returnKey, 0, T('\n')));
  60712. }
  60713. void escapePressed()
  60714. {
  60715. // pass these up the component hierarchy to be trigger the buttons
  60716. getParentComponent()->keyPressed (KeyPress (KeyPress::escapeKey, 0, 0));
  60717. }
  60718. private:
  60719. AlertWindowTextEditor (const AlertWindowTextEditor&);
  60720. AlertWindowTextEditor& operator= (const AlertWindowTextEditor&);
  60721. };
  60722. #if JUCE_LINUX
  60723. const tchar AlertWindowTextEditor::passwordChar = 0x2022;
  60724. #else
  60725. const tchar AlertWindowTextEditor::passwordChar = 0x25cf;
  60726. #endif
  60727. AlertWindow::AlertWindow (const String& title,
  60728. const String& message,
  60729. AlertIconType iconType,
  60730. Component* associatedComponent_)
  60731. : TopLevelWindow (title, true),
  60732. alertIconType (iconType),
  60733. associatedComponent (associatedComponent_)
  60734. {
  60735. if (message.isEmpty())
  60736. text = T(" "); // to force an update if the message is empty
  60737. setMessage (message);
  60738. for (int i = Desktop::getInstance().getNumComponents(); --i >= 0;)
  60739. {
  60740. Component* const c = Desktop::getInstance().getComponent (i);
  60741. if (c != 0 && c->isAlwaysOnTop() && c->isShowing())
  60742. {
  60743. setAlwaysOnTop (true);
  60744. break;
  60745. }
  60746. }
  60747. if (JUCEApplication::getInstance() == 0)
  60748. setAlwaysOnTop (true); // for a plugin, make it always-on-top because the host windows are often top-level
  60749. lookAndFeelChanged();
  60750. constrainer.setMinimumOnscreenAmounts (0x10000, 0x10000, 0x10000, 0x10000);
  60751. }
  60752. AlertWindow::~AlertWindow()
  60753. {
  60754. for (int i = customComps.size(); --i >= 0;)
  60755. removeChildComponent ((Component*) customComps[i]);
  60756. deleteAllChildren();
  60757. }
  60758. void AlertWindow::userTriedToCloseWindow()
  60759. {
  60760. exitModalState (0);
  60761. }
  60762. void AlertWindow::setMessage (const String& message)
  60763. {
  60764. const String newMessage (message.substring (0, 2048));
  60765. if (text != newMessage)
  60766. {
  60767. text = newMessage;
  60768. font.setHeight (15.0f);
  60769. Font titleFont (font.getHeight() * 1.1f, Font::bold);
  60770. textLayout.setText (getName() + T("\n\n"), titleFont);
  60771. textLayout.appendText (text, font);
  60772. updateLayout (true);
  60773. repaint();
  60774. }
  60775. }
  60776. void AlertWindow::buttonClicked (Button* button)
  60777. {
  60778. for (int i = 0; i < buttons.size(); i++)
  60779. {
  60780. TextButton* const c = (TextButton*) buttons[i];
  60781. if (button->getName() == c->getName())
  60782. {
  60783. if (c->getParentComponent() != 0)
  60784. c->getParentComponent()->exitModalState (c->getCommandID());
  60785. break;
  60786. }
  60787. }
  60788. }
  60789. void AlertWindow::addButton (const String& name,
  60790. const int returnValue,
  60791. const KeyPress& shortcutKey1,
  60792. const KeyPress& shortcutKey2)
  60793. {
  60794. TextButton* const b = new TextButton (name, String::empty);
  60795. b->setWantsKeyboardFocus (true);
  60796. b->setMouseClickGrabsKeyboardFocus (false);
  60797. b->setCommandToTrigger (0, returnValue, false);
  60798. b->addShortcut (shortcutKey1);
  60799. b->addShortcut (shortcutKey2);
  60800. b->addButtonListener (this);
  60801. b->changeWidthToFitText (getLookAndFeel().getAlertWindowButtonHeight());
  60802. addAndMakeVisible (b, 0);
  60803. buttons.add (b);
  60804. updateLayout (false);
  60805. }
  60806. int AlertWindow::getNumButtons() const
  60807. {
  60808. return buttons.size();
  60809. }
  60810. void AlertWindow::addTextEditor (const String& name,
  60811. const String& initialContents,
  60812. const String& onScreenLabel,
  60813. const bool isPasswordBox)
  60814. {
  60815. AlertWindowTextEditor* const tc = new AlertWindowTextEditor (name, isPasswordBox);
  60816. tc->setColour (TextEditor::outlineColourId, findColour (ComboBox::outlineColourId));
  60817. tc->setFont (font);
  60818. tc->setText (initialContents);
  60819. tc->setCaretPosition (initialContents.length());
  60820. addAndMakeVisible (tc);
  60821. textBoxes.add (tc);
  60822. allComps.add (tc);
  60823. textboxNames.add (onScreenLabel);
  60824. updateLayout (false);
  60825. }
  60826. const String AlertWindow::getTextEditorContents (const String& nameOfTextEditor) const
  60827. {
  60828. for (int i = textBoxes.size(); --i >= 0;)
  60829. if (((TextEditor*)textBoxes[i])->getName() == nameOfTextEditor)
  60830. return ((TextEditor*)textBoxes[i])->getText();
  60831. return String::empty;
  60832. }
  60833. void AlertWindow::addComboBox (const String& name,
  60834. const StringArray& items,
  60835. const String& onScreenLabel)
  60836. {
  60837. ComboBox* const cb = new ComboBox (name);
  60838. for (int i = 0; i < items.size(); ++i)
  60839. cb->addItem (items[i], i + 1);
  60840. addAndMakeVisible (cb);
  60841. cb->setSelectedItemIndex (0);
  60842. comboBoxes.add (cb);
  60843. allComps.add (cb);
  60844. comboBoxNames.add (onScreenLabel);
  60845. updateLayout (false);
  60846. }
  60847. ComboBox* AlertWindow::getComboBoxComponent (const String& nameOfList) const
  60848. {
  60849. for (int i = comboBoxes.size(); --i >= 0;)
  60850. if (((ComboBox*) comboBoxes[i])->getName() == nameOfList)
  60851. return (ComboBox*) comboBoxes[i];
  60852. return 0;
  60853. }
  60854. class AlertTextComp : public TextEditor
  60855. {
  60856. public:
  60857. AlertTextComp (const String& message,
  60858. const Font& font)
  60859. {
  60860. setReadOnly (true);
  60861. setMultiLine (true, true);
  60862. setCaretVisible (false);
  60863. setScrollbarsShown (true);
  60864. lookAndFeelChanged();
  60865. setWantsKeyboardFocus (false);
  60866. setFont (font);
  60867. setText (message, false);
  60868. bestWidth = 2 * (int) sqrt (font.getHeight() * font.getStringWidth (message));
  60869. setColour (TextEditor::backgroundColourId, Colours::transparentBlack);
  60870. setColour (TextEditor::outlineColourId, Colours::transparentBlack);
  60871. setColour (TextEditor::shadowColourId, Colours::transparentBlack);
  60872. }
  60873. ~AlertTextComp()
  60874. {
  60875. }
  60876. int getPreferredWidth() const throw() { return bestWidth; }
  60877. void updateLayout (const int width)
  60878. {
  60879. TextLayout text;
  60880. text.appendText (getText(), getFont());
  60881. text.layout (width - 8, Justification::topLeft, true);
  60882. setSize (width, jmin (width, text.getHeight() + (int) getFont().getHeight()));
  60883. }
  60884. private:
  60885. int bestWidth;
  60886. AlertTextComp (const AlertTextComp&);
  60887. AlertTextComp& operator= (const AlertTextComp&);
  60888. };
  60889. void AlertWindow::addTextBlock (const String& text)
  60890. {
  60891. AlertTextComp* const c = new AlertTextComp (text, font);
  60892. textBlocks.add (c);
  60893. allComps.add (c);
  60894. addAndMakeVisible (c);
  60895. updateLayout (false);
  60896. }
  60897. void AlertWindow::addProgressBarComponent (double& progressValue)
  60898. {
  60899. ProgressBar* const pb = new ProgressBar (progressValue);
  60900. progressBars.add (pb);
  60901. allComps.add (pb);
  60902. addAndMakeVisible (pb);
  60903. updateLayout (false);
  60904. }
  60905. void AlertWindow::addCustomComponent (Component* const component)
  60906. {
  60907. customComps.add (component);
  60908. allComps.add (component);
  60909. addAndMakeVisible (component);
  60910. updateLayout (false);
  60911. }
  60912. int AlertWindow::getNumCustomComponents() const
  60913. {
  60914. return customComps.size();
  60915. }
  60916. Component* AlertWindow::getCustomComponent (const int index) const
  60917. {
  60918. return (Component*) customComps [index];
  60919. }
  60920. Component* AlertWindow::removeCustomComponent (const int index)
  60921. {
  60922. Component* const c = getCustomComponent (index);
  60923. if (c != 0)
  60924. {
  60925. customComps.removeValue (c);
  60926. allComps.removeValue (c);
  60927. removeChildComponent (c);
  60928. updateLayout (false);
  60929. }
  60930. return c;
  60931. }
  60932. void AlertWindow::paint (Graphics& g)
  60933. {
  60934. getLookAndFeel().drawAlertBox (g, *this, textArea, textLayout);
  60935. g.setColour (findColour (textColourId));
  60936. g.setFont (getLookAndFeel().getAlertWindowFont());
  60937. int i;
  60938. for (i = textBoxes.size(); --i >= 0;)
  60939. {
  60940. const TextEditor* const te = (TextEditor*) textBoxes[i];
  60941. g.drawFittedText (textboxNames[i],
  60942. te->getX(), te->getY() - 14,
  60943. te->getWidth(), 14,
  60944. Justification::centredLeft, 1);
  60945. }
  60946. for (i = comboBoxNames.size(); --i >= 0;)
  60947. {
  60948. const ComboBox* const cb = (ComboBox*) comboBoxes[i];
  60949. g.drawFittedText (comboBoxNames[i],
  60950. cb->getX(), cb->getY() - 14,
  60951. cb->getWidth(), 14,
  60952. Justification::centredLeft, 1);
  60953. }
  60954. for (i = customComps.size(); --i >= 0;)
  60955. {
  60956. const Component* const c = (Component*) customComps[i];
  60957. g.drawFittedText (c->getName(),
  60958. c->getX(), c->getY() - 14,
  60959. c->getWidth(), 14,
  60960. Justification::centredLeft, 1);
  60961. }
  60962. }
  60963. void AlertWindow::updateLayout (const bool onlyIncreaseSize)
  60964. {
  60965. const int wid = jmax (font.getStringWidth (text),
  60966. font.getStringWidth (getName()));
  60967. const int sw = (int) sqrt (font.getHeight() * wid);
  60968. int w = jmin (300 + sw * 2, (int) (getParentWidth() * 0.7f));
  60969. const int edgeGap = 10;
  60970. const int labelHeight = 18;
  60971. int iconSpace;
  60972. if (alertIconType == NoIcon)
  60973. {
  60974. textLayout.layout (w, Justification::horizontallyCentred, true);
  60975. iconSpace = 0;
  60976. }
  60977. else
  60978. {
  60979. textLayout.layout (w, Justification::left, true);
  60980. iconSpace = iconWidth;
  60981. }
  60982. w = jmax (350, textLayout.getWidth() + iconSpace + edgeGap * 4);
  60983. w = jmin (w, (int) (getParentWidth() * 0.7f));
  60984. const int textLayoutH = textLayout.getHeight();
  60985. const int textBottom = 16 + titleH + textLayoutH;
  60986. int h = textBottom;
  60987. int buttonW = 40;
  60988. int i;
  60989. for (i = 0; i < buttons.size(); ++i)
  60990. buttonW += 16 + ((const TextButton*) buttons[i])->getWidth();
  60991. w = jmax (buttonW, w);
  60992. h += (textBoxes.size() + comboBoxes.size() + progressBars.size()) * 50;
  60993. if (buttons.size() > 0)
  60994. h += 20 + ((TextButton*) buttons[0])->getHeight();
  60995. for (i = customComps.size(); --i >= 0;)
  60996. {
  60997. Component* c = (Component*) customComps[i];
  60998. w = jmax (w, (c->getWidth() * 100) / 80);
  60999. h += 10 + c->getHeight();
  61000. if (c->getName().isNotEmpty())
  61001. h += labelHeight;
  61002. }
  61003. for (i = textBlocks.size(); --i >= 0;)
  61004. {
  61005. const AlertTextComp* const ac = (AlertTextComp*) textBlocks[i];
  61006. w = jmax (w, ac->getPreferredWidth());
  61007. }
  61008. w = jmin (w, (int) (getParentWidth() * 0.7f));
  61009. for (i = textBlocks.size(); --i >= 0;)
  61010. {
  61011. AlertTextComp* const ac = (AlertTextComp*) textBlocks[i];
  61012. ac->updateLayout ((int) (w * 0.8f));
  61013. h += ac->getHeight() + 10;
  61014. }
  61015. h = jmin (getParentHeight() - 50, h);
  61016. if (onlyIncreaseSize)
  61017. {
  61018. w = jmax (w, getWidth());
  61019. h = jmax (h, getHeight());
  61020. }
  61021. if (! isVisible())
  61022. {
  61023. centreAroundComponent (associatedComponent, w, h);
  61024. }
  61025. else
  61026. {
  61027. const int cx = getX() + getWidth() / 2;
  61028. const int cy = getY() + getHeight() / 2;
  61029. setBounds (cx - w / 2,
  61030. cy - h / 2,
  61031. w, h);
  61032. }
  61033. textArea.setBounds (edgeGap, edgeGap, w - (edgeGap * 2), h - edgeGap);
  61034. const int spacer = 16;
  61035. int totalWidth = -spacer;
  61036. for (i = buttons.size(); --i >= 0;)
  61037. totalWidth += ((TextButton*) buttons[i])->getWidth() + spacer;
  61038. int x = (w - totalWidth) / 2;
  61039. int y = (int) (getHeight() * 0.95f);
  61040. for (i = 0; i < buttons.size(); ++i)
  61041. {
  61042. TextButton* const c = (TextButton*) buttons[i];
  61043. int ny = proportionOfHeight (0.95f) - c->getHeight();
  61044. c->setTopLeftPosition (x, ny);
  61045. if (ny < y)
  61046. y = ny;
  61047. x += c->getWidth() + spacer;
  61048. c->toFront (false);
  61049. }
  61050. y = textBottom;
  61051. for (i = 0; i < allComps.size(); ++i)
  61052. {
  61053. Component* const c = (Component*) allComps[i];
  61054. int h = 22;
  61055. const int comboIndex = comboBoxes.indexOf (c);
  61056. if (comboIndex >= 0 && comboBoxNames [comboIndex].isNotEmpty())
  61057. y += labelHeight;
  61058. const int tbIndex = textBoxes.indexOf (c);
  61059. if (tbIndex >= 0 && textboxNames[tbIndex].isNotEmpty())
  61060. y += labelHeight;
  61061. if (customComps.contains (c))
  61062. {
  61063. if (c->getName().isNotEmpty())
  61064. y += labelHeight;
  61065. c->setTopLeftPosition (proportionOfWidth (0.1f), y);
  61066. h = c->getHeight();
  61067. }
  61068. else if (textBlocks.contains (c))
  61069. {
  61070. c->setTopLeftPosition ((getWidth() - c->getWidth()) / 2, y);
  61071. h = c->getHeight();
  61072. }
  61073. else
  61074. {
  61075. c->setBounds (proportionOfWidth (0.1f), y, proportionOfWidth (0.8f), h);
  61076. }
  61077. y += h + 10;
  61078. }
  61079. setWantsKeyboardFocus (getNumChildComponents() == 0);
  61080. }
  61081. bool AlertWindow::containsAnyExtraComponents() const
  61082. {
  61083. return textBoxes.size()
  61084. + comboBoxes.size()
  61085. + progressBars.size()
  61086. + customComps.size() > 0;
  61087. }
  61088. void AlertWindow::mouseDown (const MouseEvent&)
  61089. {
  61090. dragger.startDraggingComponent (this, &constrainer);
  61091. }
  61092. void AlertWindow::mouseDrag (const MouseEvent& e)
  61093. {
  61094. dragger.dragComponent (this, e);
  61095. }
  61096. bool AlertWindow::keyPressed (const KeyPress& key)
  61097. {
  61098. for (int i = buttons.size(); --i >= 0;)
  61099. {
  61100. TextButton* const b = (TextButton*) buttons[i];
  61101. if (b->isRegisteredForShortcut (key))
  61102. {
  61103. b->triggerClick();
  61104. return true;
  61105. }
  61106. }
  61107. if (key.isKeyCode (KeyPress::escapeKey) && buttons.size() == 0)
  61108. {
  61109. exitModalState (0);
  61110. return true;
  61111. }
  61112. else if (key.isKeyCode (KeyPress::returnKey) && buttons.size() == 1)
  61113. {
  61114. ((TextButton*) buttons.getFirst())->triggerClick();
  61115. return true;
  61116. }
  61117. return false;
  61118. }
  61119. void AlertWindow::lookAndFeelChanged()
  61120. {
  61121. const int flags = getLookAndFeel().getAlertBoxWindowFlags();
  61122. setUsingNativeTitleBar ((flags & ComponentPeer::windowHasTitleBar) != 0);
  61123. setDropShadowEnabled (isOpaque() && (flags & ComponentPeer::windowHasDropShadow) != 0);
  61124. }
  61125. int AlertWindow::getDesktopWindowStyleFlags() const
  61126. {
  61127. return getLookAndFeel().getAlertBoxWindowFlags();
  61128. }
  61129. struct AlertWindowInfo
  61130. {
  61131. String title, message, button1, button2, button3;
  61132. AlertWindow::AlertIconType iconType;
  61133. int numButtons;
  61134. Component::SafePointer<Component> associatedComponent;
  61135. int run() const
  61136. {
  61137. return (int) (pointer_sized_int)
  61138. MessageManager::getInstance()->callFunctionOnMessageThread (showCallback, (void*) this);
  61139. }
  61140. private:
  61141. int show() const
  61142. {
  61143. LookAndFeel& lf = associatedComponent != 0 ? associatedComponent->getLookAndFeel()
  61144. : LookAndFeel::getDefaultLookAndFeel();
  61145. ScopedPointer <Component> alertBox (lf.createAlertWindow (title, message, button1, button2, button3,
  61146. iconType, numButtons, associatedComponent));
  61147. jassert (alertBox != 0); // you have to return one of these!
  61148. return alertBox->runModalLoop();
  61149. }
  61150. static void* showCallback (void* userData)
  61151. {
  61152. return (void*) (pointer_sized_int) ((const AlertWindowInfo*) userData)->show();
  61153. }
  61154. };
  61155. void AlertWindow::showMessageBox (AlertIconType iconType,
  61156. const String& title,
  61157. const String& message,
  61158. const String& buttonText,
  61159. Component* associatedComponent)
  61160. {
  61161. AlertWindowInfo info;
  61162. info.title = title;
  61163. info.message = message;
  61164. info.button1 = buttonText.isEmpty() ? TRANS("ok") : buttonText;
  61165. info.iconType = iconType;
  61166. info.numButtons = 1;
  61167. info.associatedComponent = associatedComponent;
  61168. info.run();
  61169. }
  61170. bool AlertWindow::showOkCancelBox (AlertIconType iconType,
  61171. const String& title,
  61172. const String& message,
  61173. const String& button1Text,
  61174. const String& button2Text,
  61175. Component* associatedComponent)
  61176. {
  61177. AlertWindowInfo info;
  61178. info.title = title;
  61179. info.message = message;
  61180. info.button1 = button1Text.isEmpty() ? TRANS("ok") : button1Text;
  61181. info.button2 = button2Text.isEmpty() ? TRANS("cancel") : button2Text;
  61182. info.iconType = iconType;
  61183. info.numButtons = 2;
  61184. info.associatedComponent = associatedComponent;
  61185. return info.run() != 0;
  61186. }
  61187. int AlertWindow::showYesNoCancelBox (AlertIconType iconType,
  61188. const String& title,
  61189. const String& message,
  61190. const String& button1Text,
  61191. const String& button2Text,
  61192. const String& button3Text,
  61193. Component* associatedComponent)
  61194. {
  61195. AlertWindowInfo info;
  61196. info.title = title;
  61197. info.message = message;
  61198. info.button1 = button1Text.isEmpty() ? TRANS("yes") : button1Text;
  61199. info.button2 = button2Text.isEmpty() ? TRANS("no") : button2Text;
  61200. info.button3 = button3Text.isEmpty() ? TRANS("cancel") : button3Text;
  61201. info.iconType = iconType;
  61202. info.numButtons = 3;
  61203. info.associatedComponent = associatedComponent;
  61204. return info.run();
  61205. }
  61206. END_JUCE_NAMESPACE
  61207. /*** End of inlined file: juce_AlertWindow.cpp ***/
  61208. /*** Start of inlined file: juce_ComponentPeer.cpp ***/
  61209. BEGIN_JUCE_NAMESPACE
  61210. //#define JUCE_ENABLE_REPAINT_DEBUGGING 1
  61211. static VoidArray heavyweightPeers;
  61212. ComponentPeer::ComponentPeer (Component* const component_,
  61213. const int styleFlags_) throw()
  61214. : component (component_),
  61215. styleFlags (styleFlags_),
  61216. lastPaintTime (0),
  61217. constrainer (0),
  61218. lastDragAndDropCompUnderMouse (0),
  61219. fakeMouseMessageSent (false),
  61220. isWindowMinimised (false)
  61221. {
  61222. heavyweightPeers.add (this);
  61223. }
  61224. ComponentPeer::~ComponentPeer()
  61225. {
  61226. heavyweightPeers.removeValue (this);
  61227. Desktop::getInstance().triggerFocusCallback();
  61228. }
  61229. int ComponentPeer::getNumPeers() throw()
  61230. {
  61231. return heavyweightPeers.size();
  61232. }
  61233. ComponentPeer* ComponentPeer::getPeer (const int index) throw()
  61234. {
  61235. return (ComponentPeer*) heavyweightPeers [index];
  61236. }
  61237. ComponentPeer* ComponentPeer::getPeerFor (const Component* const component) throw()
  61238. {
  61239. for (int i = heavyweightPeers.size(); --i >= 0;)
  61240. {
  61241. ComponentPeer* const peer = (ComponentPeer*) heavyweightPeers.getUnchecked(i);
  61242. if (peer->getComponent() == component)
  61243. return peer;
  61244. }
  61245. return 0;
  61246. }
  61247. bool ComponentPeer::isValidPeer (const ComponentPeer* const peer) throw()
  61248. {
  61249. return heavyweightPeers.contains (const_cast <ComponentPeer*> (peer));
  61250. }
  61251. void ComponentPeer::updateCurrentModifiers() throw()
  61252. {
  61253. ModifierKeys::updateCurrentModifiers();
  61254. }
  61255. void ComponentPeer::handleMouseEvent (const int touchIndex, const Point<int>& positionWithinPeer, const ModifierKeys& newMods, const int64 time)
  61256. {
  61257. MouseInputSource* const mouse = Desktop::getInstance().getMouseSource (touchIndex);
  61258. jassert (mouse != 0); // not enough sources!
  61259. mouse->handleEvent (this, positionWithinPeer, time, newMods);
  61260. }
  61261. void ComponentPeer::handleMouseWheel (const int touchIndex, const Point<int>& positionWithinPeer, const int64 time, const float x, const float y)
  61262. {
  61263. MouseInputSource* const mouse = Desktop::getInstance().getMouseSource (touchIndex);
  61264. jassert (mouse != 0); // not enough sources!
  61265. mouse->handleWheel (this, positionWithinPeer, time, x, y);
  61266. }
  61267. void ComponentPeer::handlePaint (LowLevelGraphicsContext& contextToPaintTo)
  61268. {
  61269. Graphics g (&contextToPaintTo);
  61270. #if JUCE_ENABLE_REPAINT_DEBUGGING
  61271. g.saveState();
  61272. #endif
  61273. JUCE_TRY
  61274. {
  61275. component->paintEntireComponent (g);
  61276. }
  61277. JUCE_CATCH_EXCEPTION
  61278. #if JUCE_ENABLE_REPAINT_DEBUGGING
  61279. // enabling this code will fill all areas that get repainted with a colour overlay, to show
  61280. // clearly when things are being repainted.
  61281. {
  61282. g.restoreState();
  61283. g.fillAll (Colour ((uint8) Random::getSystemRandom().nextInt (255),
  61284. (uint8) Random::getSystemRandom().nextInt (255),
  61285. (uint8) Random::getSystemRandom().nextInt (255),
  61286. (uint8) 0x50));
  61287. }
  61288. #endif
  61289. }
  61290. bool ComponentPeer::handleKeyPress (const int keyCode,
  61291. const juce_wchar textCharacter)
  61292. {
  61293. updateCurrentModifiers();
  61294. Component* target = Component::getCurrentlyFocusedComponent() != 0
  61295. ? Component::getCurrentlyFocusedComponent()
  61296. : component;
  61297. if (target->isCurrentlyBlockedByAnotherModalComponent())
  61298. {
  61299. Component* const currentModalComp = Component::getCurrentlyModalComponent();
  61300. if (currentModalComp != 0)
  61301. target = currentModalComp;
  61302. }
  61303. const KeyPress keyInfo (keyCode,
  61304. ModifierKeys::getCurrentModifiers().getRawFlags()
  61305. & ModifierKeys::allKeyboardModifiers,
  61306. textCharacter);
  61307. bool keyWasUsed = false;
  61308. while (target != 0)
  61309. {
  61310. const Component::SafePointer<Component> deletionChecker (target);
  61311. if (target->keyListeners_ != 0)
  61312. {
  61313. for (int i = target->keyListeners_->size(); --i >= 0;)
  61314. {
  61315. keyWasUsed = ((KeyListener*) target->keyListeners_->getUnchecked(i))->keyPressed (keyInfo, target);
  61316. if (keyWasUsed || deletionChecker == 0)
  61317. return keyWasUsed;
  61318. i = jmin (i, target->keyListeners_->size());
  61319. }
  61320. }
  61321. keyWasUsed = target->keyPressed (keyInfo);
  61322. if (keyWasUsed || deletionChecker == 0)
  61323. break;
  61324. if (keyInfo.isKeyCode (KeyPress::tabKey) && Component::getCurrentlyFocusedComponent() != 0)
  61325. {
  61326. Component* const currentlyFocused = Component::getCurrentlyFocusedComponent();
  61327. currentlyFocused->moveKeyboardFocusToSibling (! keyInfo.getModifiers().isShiftDown());
  61328. keyWasUsed = (currentlyFocused != Component::getCurrentlyFocusedComponent());
  61329. break;
  61330. }
  61331. target = target->parentComponent_;
  61332. }
  61333. return keyWasUsed;
  61334. }
  61335. bool ComponentPeer::handleKeyUpOrDown (const bool isKeyDown)
  61336. {
  61337. updateCurrentModifiers();
  61338. Component* target = Component::getCurrentlyFocusedComponent() != 0
  61339. ? Component::getCurrentlyFocusedComponent()
  61340. : component;
  61341. if (target->isCurrentlyBlockedByAnotherModalComponent())
  61342. {
  61343. Component* const currentModalComp = Component::getCurrentlyModalComponent();
  61344. if (currentModalComp != 0)
  61345. target = currentModalComp;
  61346. }
  61347. bool keyWasUsed = false;
  61348. while (target != 0)
  61349. {
  61350. const Component::SafePointer<Component> deletionChecker (target);
  61351. keyWasUsed = target->keyStateChanged (isKeyDown);
  61352. if (keyWasUsed || deletionChecker == 0)
  61353. break;
  61354. if (target->keyListeners_ != 0)
  61355. {
  61356. for (int i = target->keyListeners_->size(); --i >= 0;)
  61357. {
  61358. keyWasUsed = ((KeyListener*) target->keyListeners_->getUnchecked(i))->keyStateChanged (isKeyDown, target);
  61359. if (keyWasUsed || deletionChecker == 0)
  61360. return keyWasUsed;
  61361. i = jmin (i, target->keyListeners_->size());
  61362. }
  61363. }
  61364. target = target->parentComponent_;
  61365. }
  61366. return keyWasUsed;
  61367. }
  61368. void ComponentPeer::handleModifierKeysChange()
  61369. {
  61370. updateCurrentModifiers();
  61371. Component* target = Desktop::getInstance().getMainMouseSource().getComponentUnderMouse();
  61372. if (target == 0)
  61373. target = Component::getCurrentlyFocusedComponent();
  61374. if (target == 0)
  61375. target = component;
  61376. if (target != 0)
  61377. target->internalModifierKeysChanged();
  61378. }
  61379. TextInputTarget* ComponentPeer::findCurrentTextInputTarget()
  61380. {
  61381. Component* const c = Component::getCurrentlyFocusedComponent();
  61382. if (component->isParentOf (c))
  61383. return dynamic_cast <TextInputTarget*> (c);
  61384. return 0;
  61385. }
  61386. void ComponentPeer::handleBroughtToFront()
  61387. {
  61388. updateCurrentModifiers();
  61389. if (component != 0)
  61390. component->internalBroughtToFront();
  61391. }
  61392. void ComponentPeer::setConstrainer (ComponentBoundsConstrainer* const newConstrainer) throw()
  61393. {
  61394. constrainer = newConstrainer;
  61395. }
  61396. void ComponentPeer::handleMovedOrResized()
  61397. {
  61398. jassert (component->isValidComponent());
  61399. updateCurrentModifiers();
  61400. const bool nowMinimised = isMinimised();
  61401. if (component->flags.hasHeavyweightPeerFlag && ! nowMinimised)
  61402. {
  61403. const Component::SafePointer<Component> deletionChecker (component);
  61404. const Rectangle<int> newBounds (getBounds());
  61405. const bool wasMoved = (component->getPosition() != newBounds.getPosition());
  61406. const bool wasResized = (component->getWidth() != newBounds.getWidth() || component->getHeight() != newBounds.getHeight());
  61407. if (wasMoved || wasResized)
  61408. {
  61409. component->bounds_ = newBounds;
  61410. if (wasResized)
  61411. component->repaint();
  61412. component->sendMovedResizedMessages (wasMoved, wasResized);
  61413. if (deletionChecker == 0)
  61414. return;
  61415. }
  61416. }
  61417. if (isWindowMinimised != nowMinimised)
  61418. {
  61419. isWindowMinimised = nowMinimised;
  61420. component->minimisationStateChanged (nowMinimised);
  61421. component->sendVisibilityChangeMessage();
  61422. }
  61423. if (! isFullScreen())
  61424. lastNonFullscreenBounds = component->getBounds();
  61425. }
  61426. void ComponentPeer::handleFocusGain()
  61427. {
  61428. updateCurrentModifiers();
  61429. if (component->isParentOf (lastFocusedComponent))
  61430. {
  61431. Component::currentlyFocusedComponent = lastFocusedComponent;
  61432. Desktop::getInstance().triggerFocusCallback();
  61433. lastFocusedComponent->internalFocusGain (Component::focusChangedDirectly);
  61434. }
  61435. else
  61436. {
  61437. if (! component->isCurrentlyBlockedByAnotherModalComponent())
  61438. component->grabKeyboardFocus();
  61439. else
  61440. Component::bringModalComponentToFront();
  61441. }
  61442. }
  61443. void ComponentPeer::handleFocusLoss()
  61444. {
  61445. updateCurrentModifiers();
  61446. if (component->hasKeyboardFocus (true))
  61447. {
  61448. lastFocusedComponent = Component::currentlyFocusedComponent;
  61449. if (lastFocusedComponent != 0)
  61450. {
  61451. Component::currentlyFocusedComponent = 0;
  61452. Desktop::getInstance().triggerFocusCallback();
  61453. lastFocusedComponent->internalFocusLoss (Component::focusChangedByMouseClick);
  61454. }
  61455. }
  61456. }
  61457. Component* ComponentPeer::getLastFocusedSubcomponent() const throw()
  61458. {
  61459. return (component->isParentOf (lastFocusedComponent) && lastFocusedComponent->isShowing())
  61460. ? static_cast <Component*> (lastFocusedComponent)
  61461. : component;
  61462. }
  61463. void ComponentPeer::handleScreenSizeChange()
  61464. {
  61465. updateCurrentModifiers();
  61466. component->parentSizeChanged();
  61467. handleMovedOrResized();
  61468. }
  61469. void ComponentPeer::setNonFullScreenBounds (const Rectangle<int>& newBounds) throw()
  61470. {
  61471. lastNonFullscreenBounds = newBounds;
  61472. }
  61473. const Rectangle<int>& ComponentPeer::getNonFullScreenBounds() const throw()
  61474. {
  61475. return lastNonFullscreenBounds;
  61476. }
  61477. static FileDragAndDropTarget* findDragAndDropTarget (Component* c,
  61478. const StringArray& files,
  61479. FileDragAndDropTarget* const lastOne)
  61480. {
  61481. while (c != 0)
  61482. {
  61483. FileDragAndDropTarget* const t = dynamic_cast <FileDragAndDropTarget*> (c);
  61484. if (t != 0 && (t == lastOne || t->isInterestedInFileDrag (files)))
  61485. return t;
  61486. c = c->getParentComponent();
  61487. }
  61488. return 0;
  61489. }
  61490. void ComponentPeer::handleFileDragMove (const StringArray& files, const Point<int>& position)
  61491. {
  61492. updateCurrentModifiers();
  61493. FileDragAndDropTarget* lastTarget
  61494. = dynamic_cast<FileDragAndDropTarget*> (static_cast<Component*> (dragAndDropTargetComponent));
  61495. FileDragAndDropTarget* newTarget = 0;
  61496. Component* const compUnderMouse = component->getComponentAt (position);
  61497. if (compUnderMouse != lastDragAndDropCompUnderMouse)
  61498. {
  61499. lastDragAndDropCompUnderMouse = compUnderMouse;
  61500. newTarget = findDragAndDropTarget (compUnderMouse, files, lastTarget);
  61501. if (newTarget != lastTarget)
  61502. {
  61503. if (lastTarget != 0)
  61504. lastTarget->fileDragExit (files);
  61505. dragAndDropTargetComponent = 0;
  61506. if (newTarget != 0)
  61507. {
  61508. dragAndDropTargetComponent = dynamic_cast <Component*> (newTarget);
  61509. const Point<int> pos (component->relativePositionToOtherComponent (dragAndDropTargetComponent, position));
  61510. newTarget->fileDragEnter (files, pos.getX(), pos.getY());
  61511. }
  61512. }
  61513. }
  61514. else
  61515. {
  61516. newTarget = lastTarget;
  61517. }
  61518. if (newTarget != 0)
  61519. {
  61520. Component* const targetComp = dynamic_cast <Component*> (newTarget);
  61521. const Point<int> pos (component->relativePositionToOtherComponent (targetComp, position));
  61522. newTarget->fileDragMove (files, pos.getX(), pos.getY());
  61523. }
  61524. }
  61525. void ComponentPeer::handleFileDragExit (const StringArray& files)
  61526. {
  61527. handleFileDragMove (files, Point<int> (-1, -1));
  61528. jassert (dragAndDropTargetComponent == 0);
  61529. lastDragAndDropCompUnderMouse = 0;
  61530. }
  61531. void ComponentPeer::handleFileDragDrop (const StringArray& files, const Point<int>& position)
  61532. {
  61533. handleFileDragMove (files, position);
  61534. if (dragAndDropTargetComponent != 0)
  61535. {
  61536. FileDragAndDropTarget* const target
  61537. = dynamic_cast<FileDragAndDropTarget*> (static_cast<Component*> (dragAndDropTargetComponent));
  61538. dragAndDropTargetComponent = 0;
  61539. lastDragAndDropCompUnderMouse = 0;
  61540. if (target != 0)
  61541. {
  61542. Component* const targetComp = dynamic_cast <Component*> (target);
  61543. if (targetComp->isCurrentlyBlockedByAnotherModalComponent())
  61544. {
  61545. targetComp->internalModalInputAttempt();
  61546. if (targetComp->isCurrentlyBlockedByAnotherModalComponent())
  61547. return;
  61548. }
  61549. const Point<int> pos (component->relativePositionToOtherComponent (targetComp, position));
  61550. target->filesDropped (files, pos.getX(), pos.getY());
  61551. }
  61552. }
  61553. }
  61554. void ComponentPeer::handleUserClosingWindow()
  61555. {
  61556. updateCurrentModifiers();
  61557. component->userTriedToCloseWindow();
  61558. }
  61559. void ComponentPeer::bringModalComponentToFront()
  61560. {
  61561. Component::bringModalComponentToFront();
  61562. }
  61563. void ComponentPeer::clearMaskedRegion() throw()
  61564. {
  61565. maskedRegion.clear();
  61566. }
  61567. void ComponentPeer::addMaskedRegion (int x, int y, int w, int h) throw()
  61568. {
  61569. maskedRegion.add (x, y, w, h);
  61570. }
  61571. const StringArray ComponentPeer::getAvailableRenderingEngines() throw()
  61572. {
  61573. StringArray s;
  61574. s.add ("Software Renderer");
  61575. return s;
  61576. }
  61577. int ComponentPeer::getCurrentRenderingEngine() throw()
  61578. {
  61579. return 0;
  61580. }
  61581. void ComponentPeer::setCurrentRenderingEngine (int /*index*/) throw()
  61582. {
  61583. }
  61584. END_JUCE_NAMESPACE
  61585. /*** End of inlined file: juce_ComponentPeer.cpp ***/
  61586. /*** Start of inlined file: juce_DialogWindow.cpp ***/
  61587. BEGIN_JUCE_NAMESPACE
  61588. DialogWindow::DialogWindow (const String& name,
  61589. const Colour& backgroundColour_,
  61590. const bool escapeKeyTriggersCloseButton_,
  61591. const bool addToDesktop_)
  61592. : DocumentWindow (name, backgroundColour_, DocumentWindow::closeButton, addToDesktop_),
  61593. escapeKeyTriggersCloseButton (escapeKeyTriggersCloseButton_)
  61594. {
  61595. }
  61596. DialogWindow::~DialogWindow()
  61597. {
  61598. }
  61599. void DialogWindow::resized()
  61600. {
  61601. DocumentWindow::resized();
  61602. const KeyPress esc (KeyPress::escapeKey, 0, 0);
  61603. if (escapeKeyTriggersCloseButton
  61604. && getCloseButton() != 0
  61605. && ! getCloseButton()->isRegisteredForShortcut (esc))
  61606. {
  61607. getCloseButton()->addShortcut (esc);
  61608. }
  61609. }
  61610. class TempDialogWindow : public DialogWindow
  61611. {
  61612. public:
  61613. TempDialogWindow (const String& title, const Colour& colour, const bool escapeCloses)
  61614. : DialogWindow (title, colour, escapeCloses, true)
  61615. {
  61616. }
  61617. ~TempDialogWindow()
  61618. {
  61619. }
  61620. void closeButtonPressed()
  61621. {
  61622. setVisible (false);
  61623. }
  61624. private:
  61625. TempDialogWindow (const TempDialogWindow&);
  61626. TempDialogWindow& operator= (const TempDialogWindow&);
  61627. };
  61628. int DialogWindow::showModalDialog (const String& dialogTitle,
  61629. Component* contentComponent,
  61630. Component* componentToCentreAround,
  61631. const Colour& colour,
  61632. const bool escapeKeyTriggersCloseButton,
  61633. const bool shouldBeResizable,
  61634. const bool useBottomRightCornerResizer)
  61635. {
  61636. TempDialogWindow dw (dialogTitle, colour, escapeKeyTriggersCloseButton);
  61637. dw.setContentComponent (contentComponent, true, true);
  61638. dw.centreAroundComponent (componentToCentreAround, dw.getWidth(), dw.getHeight());
  61639. dw.setResizable (shouldBeResizable, useBottomRightCornerResizer);
  61640. const int result = dw.runModalLoop();
  61641. dw.setContentComponent (0, false);
  61642. return result;
  61643. }
  61644. END_JUCE_NAMESPACE
  61645. /*** End of inlined file: juce_DialogWindow.cpp ***/
  61646. /*** Start of inlined file: juce_DocumentWindow.cpp ***/
  61647. BEGIN_JUCE_NAMESPACE
  61648. class DocumentWindow::ButtonListenerProxy : public ButtonListener
  61649. {
  61650. public:
  61651. ButtonListenerProxy (DocumentWindow& owner_)
  61652. : owner (owner_)
  61653. {
  61654. }
  61655. void buttonClicked (Button* button)
  61656. {
  61657. if (button == owner.getMinimiseButton())
  61658. owner.minimiseButtonPressed();
  61659. else if (button == owner.getMaximiseButton())
  61660. owner.maximiseButtonPressed();
  61661. else if (button == owner.getCloseButton())
  61662. owner.closeButtonPressed();
  61663. }
  61664. juce_UseDebuggingNewOperator
  61665. private:
  61666. DocumentWindow& owner;
  61667. ButtonListenerProxy (const ButtonListenerProxy&);
  61668. ButtonListenerProxy& operator= (const ButtonListenerProxy&);
  61669. };
  61670. DocumentWindow::DocumentWindow (const String& title,
  61671. const Colour& backgroundColour,
  61672. const int requiredButtons_,
  61673. const bool addToDesktop_)
  61674. : ResizableWindow (title, backgroundColour, addToDesktop_),
  61675. titleBarHeight (26),
  61676. menuBarHeight (24),
  61677. requiredButtons (requiredButtons_),
  61678. #if JUCE_MAC
  61679. positionTitleBarButtonsOnLeft (true),
  61680. #else
  61681. positionTitleBarButtonsOnLeft (false),
  61682. #endif
  61683. drawTitleTextCentred (true),
  61684. menuBarModel (0)
  61685. {
  61686. setResizeLimits (128, 128, 32768, 32768);
  61687. lookAndFeelChanged();
  61688. }
  61689. DocumentWindow::~DocumentWindow()
  61690. {
  61691. for (int i = numElementsInArray (titleBarButtons); --i >= 0;)
  61692. titleBarButtons[i] = 0;
  61693. menuBar = 0;
  61694. }
  61695. void DocumentWindow::repaintTitleBar()
  61696. {
  61697. const Rectangle<int> titleBarArea (getTitleBarArea());
  61698. repaint (titleBarArea.getX(), titleBarArea.getY(),
  61699. titleBarArea.getWidth(), titleBarArea.getHeight());
  61700. }
  61701. void DocumentWindow::setName (const String& newName)
  61702. {
  61703. if (newName != getName())
  61704. {
  61705. Component::setName (newName);
  61706. repaintTitleBar();
  61707. }
  61708. }
  61709. void DocumentWindow::setIcon (const Image* imageToUse)
  61710. {
  61711. titleBarIcon = imageToUse != 0 ? imageToUse->createCopy() : 0;
  61712. repaintTitleBar();
  61713. }
  61714. void DocumentWindow::setTitleBarHeight (const int newHeight)
  61715. {
  61716. titleBarHeight = newHeight;
  61717. resized();
  61718. repaintTitleBar();
  61719. }
  61720. void DocumentWindow::setTitleBarButtonsRequired (const int requiredButtons_,
  61721. const bool positionTitleBarButtonsOnLeft_)
  61722. {
  61723. requiredButtons = requiredButtons_;
  61724. positionTitleBarButtonsOnLeft = positionTitleBarButtonsOnLeft_;
  61725. lookAndFeelChanged();
  61726. }
  61727. void DocumentWindow::setTitleBarTextCentred (const bool textShouldBeCentred)
  61728. {
  61729. drawTitleTextCentred = textShouldBeCentred;
  61730. repaintTitleBar();
  61731. }
  61732. void DocumentWindow::setMenuBar (MenuBarModel* menuBarModel_,
  61733. const int menuBarHeight_)
  61734. {
  61735. if (menuBarModel != menuBarModel_)
  61736. {
  61737. menuBar = 0;
  61738. menuBarModel = menuBarModel_;
  61739. menuBarHeight = (menuBarHeight_ > 0) ? menuBarHeight_
  61740. : getLookAndFeel().getDefaultMenuBarHeight();
  61741. if (menuBarModel != 0)
  61742. {
  61743. // (call the Component method directly to avoid the assertion in ResizableWindow)
  61744. Component::addAndMakeVisible (menuBar = new MenuBarComponent (menuBarModel));
  61745. menuBar->setEnabled (isActiveWindow());
  61746. }
  61747. resized();
  61748. }
  61749. }
  61750. void DocumentWindow::closeButtonPressed()
  61751. {
  61752. /* If you've got a close button, you have to override this method to get
  61753. rid of your window!
  61754. If the window is just a pop-up, you should override this method and make
  61755. it delete the window in whatever way is appropriate for your app. E.g. you
  61756. might just want to call "delete this".
  61757. If your app is centred around this window such that the whole app should quit when
  61758. the window is closed, then you will probably want to use this method as an opportunity
  61759. to call JUCEApplication::quit(), and leave the window to be deleted later by your
  61760. JUCEApplication::shutdown() method. (Doing it this way means that your window will
  61761. still get cleaned-up if the app is quit by some other means (e.g. a cmd-Q on the mac
  61762. or closing it via the taskbar icon on Windows).
  61763. */
  61764. jassertfalse
  61765. }
  61766. void DocumentWindow::minimiseButtonPressed()
  61767. {
  61768. setMinimised (true);
  61769. }
  61770. void DocumentWindow::maximiseButtonPressed()
  61771. {
  61772. setFullScreen (! isFullScreen());
  61773. }
  61774. void DocumentWindow::paint (Graphics& g)
  61775. {
  61776. ResizableWindow::paint (g);
  61777. if (resizableBorder == 0)
  61778. {
  61779. g.setColour (getBackgroundColour().overlaidWith (Colour (0x80000000)));
  61780. const BorderSize border (getBorderThickness());
  61781. g.fillRect (0, 0, getWidth(), border.getTop());
  61782. g.fillRect (0, border.getTop(), border.getLeft(), getHeight() - border.getTopAndBottom());
  61783. g.fillRect (getWidth() - border.getRight(), border.getTop(), border.getRight(), getHeight() - border.getTopAndBottom());
  61784. g.fillRect (0, getHeight() - border.getBottom(), getWidth(), border.getBottom());
  61785. }
  61786. const Rectangle<int> titleBarArea (getTitleBarArea());
  61787. g.setOrigin (titleBarArea.getX(), titleBarArea.getY());
  61788. g.reduceClipRegion (0, 0, titleBarArea.getWidth(), titleBarArea.getHeight());
  61789. int titleSpaceX1 = 6;
  61790. int titleSpaceX2 = titleBarArea.getWidth() - 6;
  61791. for (int i = 0; i < 3; ++i)
  61792. {
  61793. if (titleBarButtons[i] != 0)
  61794. {
  61795. if (positionTitleBarButtonsOnLeft)
  61796. titleSpaceX1 = jmax (titleSpaceX1, titleBarButtons[i]->getRight() + (getWidth() - titleBarButtons[i]->getRight()) / 8);
  61797. else
  61798. titleSpaceX2 = jmin (titleSpaceX2, titleBarButtons[i]->getX() - (titleBarButtons[i]->getX() / 8));
  61799. }
  61800. }
  61801. getLookAndFeel().drawDocumentWindowTitleBar (*this, g,
  61802. titleBarArea.getWidth(),
  61803. titleBarArea.getHeight(),
  61804. titleSpaceX1,
  61805. jmax (1, titleSpaceX2 - titleSpaceX1),
  61806. titleBarIcon,
  61807. ! drawTitleTextCentred);
  61808. }
  61809. void DocumentWindow::resized()
  61810. {
  61811. ResizableWindow::resized();
  61812. if (titleBarButtons[1] != 0)
  61813. titleBarButtons[1]->setToggleState (isFullScreen(), false);
  61814. const Rectangle<int> titleBarArea (getTitleBarArea());
  61815. getLookAndFeel()
  61816. .positionDocumentWindowButtons (*this,
  61817. titleBarArea.getX(), titleBarArea.getY(),
  61818. titleBarArea.getWidth(), titleBarArea.getHeight(),
  61819. titleBarButtons[0],
  61820. titleBarButtons[1],
  61821. titleBarButtons[2],
  61822. positionTitleBarButtonsOnLeft);
  61823. if (menuBar != 0)
  61824. menuBar->setBounds (titleBarArea.getX(), titleBarArea.getBottom(),
  61825. titleBarArea.getWidth(), menuBarHeight);
  61826. }
  61827. const BorderSize DocumentWindow::getBorderThickness()
  61828. {
  61829. return BorderSize ((isFullScreen() || isUsingNativeTitleBar())
  61830. ? 0 : (resizableBorder != 0 ? 4 : 1));
  61831. }
  61832. const BorderSize DocumentWindow::getContentComponentBorder()
  61833. {
  61834. BorderSize border (getBorderThickness());
  61835. border.setTop (border.getTop()
  61836. + (isUsingNativeTitleBar() ? 0 : titleBarHeight)
  61837. + (menuBar != 0 ? menuBarHeight : 0));
  61838. return border;
  61839. }
  61840. int DocumentWindow::getTitleBarHeight() const
  61841. {
  61842. return isUsingNativeTitleBar() ? 0 : jmin (titleBarHeight, getHeight() - 4);
  61843. }
  61844. const Rectangle<int> DocumentWindow::getTitleBarArea()
  61845. {
  61846. const BorderSize border (getBorderThickness());
  61847. return Rectangle<int> (border.getLeft(), border.getTop(),
  61848. getWidth() - border.getLeftAndRight(),
  61849. getTitleBarHeight());
  61850. }
  61851. Button* DocumentWindow::getCloseButton() const throw()
  61852. {
  61853. return titleBarButtons[2];
  61854. }
  61855. Button* DocumentWindow::getMinimiseButton() const throw()
  61856. {
  61857. return titleBarButtons[0];
  61858. }
  61859. Button* DocumentWindow::getMaximiseButton() const throw()
  61860. {
  61861. return titleBarButtons[1];
  61862. }
  61863. int DocumentWindow::getDesktopWindowStyleFlags() const
  61864. {
  61865. int flags = ResizableWindow::getDesktopWindowStyleFlags();
  61866. if ((requiredButtons & minimiseButton) != 0)
  61867. flags |= ComponentPeer::windowHasMinimiseButton;
  61868. if ((requiredButtons & maximiseButton) != 0)
  61869. flags |= ComponentPeer::windowHasMaximiseButton;
  61870. if ((requiredButtons & closeButton) != 0)
  61871. flags |= ComponentPeer::windowHasCloseButton;
  61872. return flags;
  61873. }
  61874. void DocumentWindow::lookAndFeelChanged()
  61875. {
  61876. int i;
  61877. for (i = numElementsInArray (titleBarButtons); --i >= 0;)
  61878. titleBarButtons[i] = 0;
  61879. if (! isUsingNativeTitleBar())
  61880. {
  61881. titleBarButtons[0] = ((requiredButtons & minimiseButton) != 0)
  61882. ? getLookAndFeel().createDocumentWindowButton (minimiseButton) : 0;
  61883. titleBarButtons[1] = ((requiredButtons & maximiseButton) != 0)
  61884. ? getLookAndFeel().createDocumentWindowButton (maximiseButton) : 0;
  61885. titleBarButtons[2] = ((requiredButtons & closeButton) != 0)
  61886. ? getLookAndFeel().createDocumentWindowButton (closeButton) : 0;
  61887. for (i = 0; i < 3; ++i)
  61888. {
  61889. if (titleBarButtons[i] != 0)
  61890. {
  61891. if (buttonListener == 0)
  61892. buttonListener = new ButtonListenerProxy (*this);
  61893. titleBarButtons[i]->addButtonListener (buttonListener);
  61894. titleBarButtons[i]->setWantsKeyboardFocus (false);
  61895. // (call the Component method directly to avoid the assertion in ResizableWindow)
  61896. Component::addAndMakeVisible (titleBarButtons[i]);
  61897. }
  61898. }
  61899. if (getCloseButton() != 0)
  61900. {
  61901. #if JUCE_MAC
  61902. getCloseButton()->addShortcut (KeyPress (T('w'), ModifierKeys::commandModifier, 0));
  61903. #else
  61904. getCloseButton()->addShortcut (KeyPress (KeyPress::F4Key, ModifierKeys::altModifier, 0));
  61905. #endif
  61906. }
  61907. }
  61908. activeWindowStatusChanged();
  61909. ResizableWindow::lookAndFeelChanged();
  61910. }
  61911. void DocumentWindow::parentHierarchyChanged()
  61912. {
  61913. lookAndFeelChanged();
  61914. }
  61915. void DocumentWindow::activeWindowStatusChanged()
  61916. {
  61917. ResizableWindow::activeWindowStatusChanged();
  61918. for (int i = numElementsInArray (titleBarButtons); --i >= 0;)
  61919. if (titleBarButtons[i] != 0)
  61920. titleBarButtons[i]->setEnabled (isActiveWindow());
  61921. if (menuBar != 0)
  61922. menuBar->setEnabled (isActiveWindow());
  61923. }
  61924. void DocumentWindow::mouseDoubleClick (const MouseEvent& e)
  61925. {
  61926. if (getTitleBarArea().contains (e.x, e.y)
  61927. && getMaximiseButton() != 0)
  61928. {
  61929. getMaximiseButton()->triggerClick();
  61930. }
  61931. }
  61932. void DocumentWindow::userTriedToCloseWindow()
  61933. {
  61934. closeButtonPressed();
  61935. }
  61936. END_JUCE_NAMESPACE
  61937. /*** End of inlined file: juce_DocumentWindow.cpp ***/
  61938. /*** Start of inlined file: juce_ResizableWindow.cpp ***/
  61939. BEGIN_JUCE_NAMESPACE
  61940. ResizableWindow::ResizableWindow (const String& name,
  61941. const bool addToDesktop_)
  61942. : TopLevelWindow (name, addToDesktop_),
  61943. resizeToFitContent (false),
  61944. fullscreen (false),
  61945. lastNonFullScreenPos (50, 50, 256, 256),
  61946. constrainer (0)
  61947. #ifdef JUCE_DEBUG
  61948. , hasBeenResized (false)
  61949. #endif
  61950. {
  61951. defaultConstrainer.setMinimumOnscreenAmounts (0x10000, 16, 24, 16);
  61952. lastNonFullScreenPos.setBounds (50, 50, 256, 256);
  61953. if (addToDesktop_)
  61954. Component::addToDesktop (getDesktopWindowStyleFlags());
  61955. }
  61956. ResizableWindow::ResizableWindow (const String& name,
  61957. const Colour& backgroundColour_,
  61958. const bool addToDesktop_)
  61959. : TopLevelWindow (name, addToDesktop_),
  61960. resizeToFitContent (false),
  61961. fullscreen (false),
  61962. lastNonFullScreenPos (50, 50, 256, 256),
  61963. constrainer (0)
  61964. #ifdef JUCE_DEBUG
  61965. , hasBeenResized (false)
  61966. #endif
  61967. {
  61968. setBackgroundColour (backgroundColour_);
  61969. defaultConstrainer.setMinimumOnscreenAmounts (0x10000, 16, 24, 16);
  61970. if (addToDesktop_)
  61971. Component::addToDesktop (getDesktopWindowStyleFlags());
  61972. }
  61973. ResizableWindow::~ResizableWindow()
  61974. {
  61975. resizableCorner = 0;
  61976. resizableBorder = 0;
  61977. contentComponent = 0;
  61978. // have you been adding your own components directly to this window..? tut tut tut.
  61979. // Read the instructions for using a ResizableWindow!
  61980. jassert (getNumChildComponents() == 0);
  61981. }
  61982. int ResizableWindow::getDesktopWindowStyleFlags() const
  61983. {
  61984. int flags = TopLevelWindow::getDesktopWindowStyleFlags();
  61985. if (isResizable() && (flags & ComponentPeer::windowHasTitleBar) != 0)
  61986. flags |= ComponentPeer::windowIsResizable;
  61987. return flags;
  61988. }
  61989. void ResizableWindow::setContentComponent (Component* const newContentComponent,
  61990. const bool deleteOldOne,
  61991. const bool resizeToFit)
  61992. {
  61993. resizeToFitContent = resizeToFit;
  61994. if (newContentComponent != (Component*) contentComponent)
  61995. {
  61996. if (! deleteOldOne)
  61997. removeChildComponent (contentComponent.release());
  61998. contentComponent = newContentComponent;
  61999. Component::addAndMakeVisible (contentComponent);
  62000. }
  62001. if (resizeToFit)
  62002. childBoundsChanged (contentComponent);
  62003. resized(); // must always be called to position the new content comp
  62004. }
  62005. void ResizableWindow::setContentComponentSize (int width, int height)
  62006. {
  62007. jassert (width > 0 && height > 0); // not a great idea to give it a zero size..
  62008. const BorderSize border (getContentComponentBorder());
  62009. setSize (width + border.getLeftAndRight(),
  62010. height + border.getTopAndBottom());
  62011. }
  62012. const BorderSize ResizableWindow::getBorderThickness()
  62013. {
  62014. return BorderSize (isUsingNativeTitleBar() ? 0 : ((resizableBorder != 0 && ! isFullScreen()) ? 5 : 3));
  62015. }
  62016. const BorderSize ResizableWindow::getContentComponentBorder()
  62017. {
  62018. return getBorderThickness();
  62019. }
  62020. void ResizableWindow::moved()
  62021. {
  62022. updateLastPos();
  62023. }
  62024. void ResizableWindow::visibilityChanged()
  62025. {
  62026. TopLevelWindow::visibilityChanged();
  62027. updateLastPos();
  62028. }
  62029. void ResizableWindow::resized()
  62030. {
  62031. if (resizableBorder != 0)
  62032. {
  62033. resizableBorder->setVisible (! isFullScreen());
  62034. resizableBorder->setBorderThickness (getBorderThickness());
  62035. resizableBorder->setSize (getWidth(), getHeight());
  62036. resizableBorder->toBack();
  62037. }
  62038. if (resizableCorner != 0)
  62039. {
  62040. resizableCorner->setVisible (! isFullScreen());
  62041. const int resizerSize = 18;
  62042. resizableCorner->setBounds (getWidth() - resizerSize,
  62043. getHeight() - resizerSize,
  62044. resizerSize, resizerSize);
  62045. }
  62046. if (contentComponent != 0)
  62047. contentComponent->setBoundsInset (getContentComponentBorder());
  62048. updateLastPos();
  62049. #ifdef JUCE_DEBUG
  62050. hasBeenResized = true;
  62051. #endif
  62052. }
  62053. void ResizableWindow::childBoundsChanged (Component* child)
  62054. {
  62055. if ((child == contentComponent) && (child != 0) && resizeToFitContent)
  62056. {
  62057. // not going to look very good if this component has a zero size..
  62058. jassert (child->getWidth() > 0);
  62059. jassert (child->getHeight() > 0);
  62060. const BorderSize borders (getContentComponentBorder());
  62061. setSize (child->getWidth() + borders.getLeftAndRight(),
  62062. child->getHeight() + borders.getTopAndBottom());
  62063. }
  62064. }
  62065. void ResizableWindow::activeWindowStatusChanged()
  62066. {
  62067. const BorderSize borders (getContentComponentBorder());
  62068. repaint (0, 0, getWidth(), borders.getTop());
  62069. repaint (0, borders.getTop(), borders.getLeft(), getHeight() - borders.getBottom() - borders.getTop());
  62070. repaint (0, getHeight() - borders.getBottom(), getWidth(), borders.getBottom());
  62071. repaint (getWidth() - borders.getRight(), borders.getTop(), borders.getRight(), getHeight() - borders.getBottom() - borders.getTop());
  62072. }
  62073. void ResizableWindow::setResizable (const bool shouldBeResizable,
  62074. const bool useBottomRightCornerResizer)
  62075. {
  62076. if (shouldBeResizable)
  62077. {
  62078. if (useBottomRightCornerResizer)
  62079. {
  62080. resizableBorder = 0;
  62081. if (resizableCorner == 0)
  62082. {
  62083. Component::addChildComponent (resizableCorner = new ResizableCornerComponent (this, constrainer));
  62084. resizableCorner->setAlwaysOnTop (true);
  62085. }
  62086. }
  62087. else
  62088. {
  62089. resizableCorner = 0;
  62090. if (resizableBorder == 0)
  62091. Component::addChildComponent (resizableBorder = new ResizableBorderComponent (this, constrainer));
  62092. }
  62093. }
  62094. else
  62095. {
  62096. resizableCorner = 0;
  62097. resizableBorder = 0;
  62098. }
  62099. if (isUsingNativeTitleBar())
  62100. recreateDesktopWindow();
  62101. childBoundsChanged (contentComponent);
  62102. resized();
  62103. }
  62104. bool ResizableWindow::isResizable() const throw()
  62105. {
  62106. return resizableCorner != 0
  62107. || resizableBorder != 0;
  62108. }
  62109. void ResizableWindow::setResizeLimits (const int newMinimumWidth,
  62110. const int newMinimumHeight,
  62111. const int newMaximumWidth,
  62112. const int newMaximumHeight) throw()
  62113. {
  62114. // if you've set up a custom constrainer then these settings won't have any effect..
  62115. jassert (constrainer == &defaultConstrainer || constrainer == 0);
  62116. if (constrainer == 0)
  62117. setConstrainer (&defaultConstrainer);
  62118. defaultConstrainer.setSizeLimits (newMinimumWidth, newMinimumHeight,
  62119. newMaximumWidth, newMaximumHeight);
  62120. setBoundsConstrained (getBounds());
  62121. }
  62122. void ResizableWindow::setConstrainer (ComponentBoundsConstrainer* newConstrainer)
  62123. {
  62124. if (constrainer != newConstrainer)
  62125. {
  62126. constrainer = newConstrainer;
  62127. const bool useBottomRightCornerResizer = resizableCorner != 0;
  62128. const bool shouldBeResizable = useBottomRightCornerResizer || resizableBorder != 0;
  62129. resizableCorner = 0;
  62130. resizableBorder = 0;
  62131. setResizable (shouldBeResizable, useBottomRightCornerResizer);
  62132. ComponentPeer* const peer = getPeer();
  62133. if (peer != 0)
  62134. peer->setConstrainer (newConstrainer);
  62135. }
  62136. }
  62137. void ResizableWindow::setBoundsConstrained (const Rectangle<int>& bounds)
  62138. {
  62139. if (constrainer != 0)
  62140. constrainer->setBoundsForComponent (this, bounds, false, false, false, false);
  62141. else
  62142. setBounds (bounds);
  62143. }
  62144. void ResizableWindow::paint (Graphics& g)
  62145. {
  62146. getLookAndFeel().fillResizableWindowBackground (g, getWidth(), getHeight(),
  62147. getBorderThickness(), *this);
  62148. if (! isFullScreen())
  62149. {
  62150. getLookAndFeel().drawResizableWindowBorder (g, getWidth(), getHeight(),
  62151. getBorderThickness(), *this);
  62152. }
  62153. #ifdef JUCE_DEBUG
  62154. /* If this fails, then you've probably written a subclass with a resized()
  62155. callback but forgotten to make it call its parent class's resized() method.
  62156. It's important when you override methods like resized(), moved(),
  62157. etc., that you make sure the base class methods also get called.
  62158. Of course you shouldn't really be overriding ResizableWindow::resized() anyway,
  62159. because your content should all be inside the content component - and it's the
  62160. content component's resized() method that you should be using to do your
  62161. layout.
  62162. */
  62163. jassert (hasBeenResized || (getWidth() == 0 && getHeight() == 0));
  62164. #endif
  62165. }
  62166. void ResizableWindow::lookAndFeelChanged()
  62167. {
  62168. resized();
  62169. if (isOnDesktop())
  62170. {
  62171. Component::addToDesktop (getDesktopWindowStyleFlags());
  62172. ComponentPeer* const peer = getPeer();
  62173. if (peer != 0)
  62174. peer->setConstrainer (constrainer);
  62175. }
  62176. }
  62177. const Colour ResizableWindow::getBackgroundColour() const throw()
  62178. {
  62179. return findColour (backgroundColourId, false);
  62180. }
  62181. void ResizableWindow::setBackgroundColour (const Colour& newColour)
  62182. {
  62183. Colour backgroundColour (newColour);
  62184. if (! Desktop::canUseSemiTransparentWindows())
  62185. backgroundColour = newColour.withAlpha (1.0f);
  62186. setColour (backgroundColourId, backgroundColour);
  62187. setOpaque (backgroundColour.isOpaque());
  62188. repaint();
  62189. }
  62190. bool ResizableWindow::isFullScreen() const
  62191. {
  62192. if (isOnDesktop())
  62193. {
  62194. ComponentPeer* const peer = getPeer();
  62195. return peer != 0 && peer->isFullScreen();
  62196. }
  62197. return fullscreen;
  62198. }
  62199. void ResizableWindow::setFullScreen (const bool shouldBeFullScreen)
  62200. {
  62201. if (shouldBeFullScreen != isFullScreen())
  62202. {
  62203. updateLastPos();
  62204. fullscreen = shouldBeFullScreen;
  62205. if (isOnDesktop())
  62206. {
  62207. ComponentPeer* const peer = getPeer();
  62208. if (peer != 0)
  62209. {
  62210. // keep a copy of this intact in case the real one gets messed-up while we're un-maximising
  62211. const Rectangle<int> lastPos (lastNonFullScreenPos);
  62212. peer->setFullScreen (shouldBeFullScreen);
  62213. if (! shouldBeFullScreen)
  62214. setBounds (lastPos);
  62215. }
  62216. else
  62217. {
  62218. jassertfalse
  62219. }
  62220. }
  62221. else
  62222. {
  62223. if (shouldBeFullScreen)
  62224. setBounds (0, 0, getParentWidth(), getParentHeight());
  62225. else
  62226. setBounds (lastNonFullScreenPos);
  62227. }
  62228. resized();
  62229. }
  62230. }
  62231. bool ResizableWindow::isMinimised() const
  62232. {
  62233. ComponentPeer* const peer = getPeer();
  62234. return (peer != 0) && peer->isMinimised();
  62235. }
  62236. void ResizableWindow::setMinimised (const bool shouldMinimise)
  62237. {
  62238. if (shouldMinimise != isMinimised())
  62239. {
  62240. ComponentPeer* const peer = getPeer();
  62241. if (peer != 0)
  62242. {
  62243. updateLastPos();
  62244. peer->setMinimised (shouldMinimise);
  62245. }
  62246. else
  62247. {
  62248. jassertfalse
  62249. }
  62250. }
  62251. }
  62252. void ResizableWindow::updateLastPos()
  62253. {
  62254. if (isShowing() && ! (isFullScreen() || isMinimised()))
  62255. {
  62256. lastNonFullScreenPos = getBounds();
  62257. }
  62258. }
  62259. void ResizableWindow::parentSizeChanged()
  62260. {
  62261. if (isFullScreen() && getParentComponent() != 0)
  62262. {
  62263. setBounds (0, 0, getParentWidth(), getParentHeight());
  62264. }
  62265. }
  62266. const String ResizableWindow::getWindowStateAsString()
  62267. {
  62268. updateLastPos();
  62269. return (isFullScreen() ? "fs " : "") + lastNonFullScreenPos.toString();
  62270. }
  62271. bool ResizableWindow::restoreWindowStateFromString (const String& s)
  62272. {
  62273. StringArray tokens;
  62274. tokens.addTokens (s, false);
  62275. tokens.removeEmptyStrings();
  62276. tokens.trim();
  62277. const bool fs = tokens[0].startsWithIgnoreCase (T("fs"));
  62278. const int firstCoord = fs ? 1 : 0;
  62279. if (tokens.size() != firstCoord + 4)
  62280. return false;
  62281. Rectangle<int> newPos (tokens[firstCoord].getIntValue(),
  62282. tokens[firstCoord + 1].getIntValue(),
  62283. tokens[firstCoord + 2].getIntValue(),
  62284. tokens[firstCoord + 3].getIntValue());
  62285. if (newPos.isEmpty())
  62286. return false;
  62287. const Rectangle<int> screen (Desktop::getInstance().getMonitorAreaContaining (newPos.getCentre()));
  62288. ComponentPeer* const peer = isOnDesktop() ? getPeer() : 0;
  62289. if (peer != 0)
  62290. peer->getFrameSize().addTo (newPos);
  62291. if (! screen.contains (newPos))
  62292. {
  62293. newPos.setSize (jmin (newPos.getWidth(), screen.getWidth()),
  62294. jmin (newPos.getHeight(), screen.getHeight()));
  62295. newPos.setPosition (jlimit (screen.getX(), screen.getRight() - newPos.getWidth(), newPos.getX()),
  62296. jlimit (screen.getY(), screen.getBottom() - newPos.getHeight(), newPos.getY()));
  62297. }
  62298. if (peer != 0)
  62299. {
  62300. peer->getFrameSize().subtractFrom (newPos);
  62301. peer->setNonFullScreenBounds (newPos);
  62302. }
  62303. lastNonFullScreenPos = newPos;
  62304. setFullScreen (fs);
  62305. if (! fs)
  62306. setBoundsConstrained (newPos);
  62307. return true;
  62308. }
  62309. void ResizableWindow::mouseDown (const MouseEvent&)
  62310. {
  62311. if (! isFullScreen())
  62312. dragger.startDraggingComponent (this, constrainer);
  62313. }
  62314. void ResizableWindow::mouseDrag (const MouseEvent& e)
  62315. {
  62316. if (! isFullScreen())
  62317. dragger.dragComponent (this, e);
  62318. }
  62319. #ifdef JUCE_DEBUG
  62320. void ResizableWindow::addChildComponent (Component* const child, int zOrder)
  62321. {
  62322. /* Agh! You shouldn't add components directly to a ResizableWindow - this class
  62323. manages its child components automatically, and if you add your own it'll cause
  62324. trouble. Instead, use setContentComponent() to give it a component which
  62325. will be automatically resized and kept in the right place - then you can add
  62326. subcomponents to the content comp. See the notes for the ResizableWindow class
  62327. for more info.
  62328. If you really know what you're doing and want to avoid this assertion, just call
  62329. Component::addChildComponent directly.
  62330. */
  62331. jassertfalse
  62332. Component::addChildComponent (child, zOrder);
  62333. }
  62334. void ResizableWindow::addAndMakeVisible (Component* const child, int zOrder)
  62335. {
  62336. /* Agh! You shouldn't add components directly to a ResizableWindow - this class
  62337. manages its child components automatically, and if you add your own it'll cause
  62338. trouble. Instead, use setContentComponent() to give it a component which
  62339. will be automatically resized and kept in the right place - then you can add
  62340. subcomponents to the content comp. See the notes for the ResizableWindow class
  62341. for more info.
  62342. If you really know what you're doing and want to avoid this assertion, just call
  62343. Component::addAndMakeVisible directly.
  62344. */
  62345. jassertfalse
  62346. Component::addAndMakeVisible (child, zOrder);
  62347. }
  62348. #endif
  62349. END_JUCE_NAMESPACE
  62350. /*** End of inlined file: juce_ResizableWindow.cpp ***/
  62351. /*** Start of inlined file: juce_SplashScreen.cpp ***/
  62352. BEGIN_JUCE_NAMESPACE
  62353. SplashScreen::SplashScreen()
  62354. : backgroundImage (0)
  62355. {
  62356. setOpaque (true);
  62357. }
  62358. SplashScreen::~SplashScreen()
  62359. {
  62360. ImageCache::releaseOrDelete (backgroundImage);
  62361. }
  62362. void SplashScreen::show (const String& title,
  62363. Image* const backgroundImage_,
  62364. const int minimumTimeToDisplayFor,
  62365. const bool useDropShadow,
  62366. const bool removeOnMouseClick)
  62367. {
  62368. backgroundImage = backgroundImage_;
  62369. jassert (backgroundImage_ != 0);
  62370. if (backgroundImage_ != 0)
  62371. {
  62372. setOpaque (! backgroundImage_->hasAlphaChannel());
  62373. show (title,
  62374. backgroundImage_->getWidth(),
  62375. backgroundImage_->getHeight(),
  62376. minimumTimeToDisplayFor,
  62377. useDropShadow,
  62378. removeOnMouseClick);
  62379. }
  62380. }
  62381. void SplashScreen::show (const String& title,
  62382. const int width,
  62383. const int height,
  62384. const int minimumTimeToDisplayFor,
  62385. const bool useDropShadow,
  62386. const bool removeOnMouseClick)
  62387. {
  62388. setName (title);
  62389. setAlwaysOnTop (true);
  62390. setVisible (true);
  62391. centreWithSize (width, height);
  62392. addToDesktop (useDropShadow ? ComponentPeer::windowHasDropShadow : 0);
  62393. toFront (false);
  62394. MessageManager::getInstance()->runDispatchLoopUntil (300);
  62395. repaint();
  62396. originalClickCounter = removeOnMouseClick
  62397. ? Desktop::getMouseButtonClickCounter()
  62398. : std::numeric_limits<int>::max();
  62399. earliestTimeToDelete = Time::getCurrentTime() + RelativeTime::milliseconds (minimumTimeToDisplayFor);
  62400. startTimer (50);
  62401. }
  62402. void SplashScreen::paint (Graphics& g)
  62403. {
  62404. if (backgroundImage != 0)
  62405. {
  62406. g.setOpacity (1.0f);
  62407. g.drawImage (backgroundImage,
  62408. 0, 0, getWidth(), getHeight(),
  62409. 0, 0, backgroundImage->getWidth(), backgroundImage->getHeight());
  62410. }
  62411. }
  62412. void SplashScreen::timerCallback()
  62413. {
  62414. if (Time::getCurrentTime() > earliestTimeToDelete
  62415. || Desktop::getMouseButtonClickCounter() > originalClickCounter)
  62416. {
  62417. delete this;
  62418. }
  62419. }
  62420. END_JUCE_NAMESPACE
  62421. /*** End of inlined file: juce_SplashScreen.cpp ***/
  62422. /*** Start of inlined file: juce_ThreadWithProgressWindow.cpp ***/
  62423. BEGIN_JUCE_NAMESPACE
  62424. ThreadWithProgressWindow::ThreadWithProgressWindow (const String& title,
  62425. const bool hasProgressBar,
  62426. const bool hasCancelButton,
  62427. const int timeOutMsWhenCancelling_,
  62428. const String& cancelButtonText)
  62429. : Thread ("Juce Progress Window"),
  62430. progress (0.0),
  62431. timeOutMsWhenCancelling (timeOutMsWhenCancelling_)
  62432. {
  62433. alertWindow = LookAndFeel::getDefaultLookAndFeel()
  62434. .createAlertWindow (title, String::empty, cancelButtonText,
  62435. String::empty, String::empty,
  62436. AlertWindow::NoIcon, hasCancelButton ? 1 : 0, 0);
  62437. if (hasProgressBar)
  62438. alertWindow->addProgressBarComponent (progress);
  62439. }
  62440. ThreadWithProgressWindow::~ThreadWithProgressWindow()
  62441. {
  62442. stopThread (timeOutMsWhenCancelling);
  62443. }
  62444. bool ThreadWithProgressWindow::runThread (const int priority)
  62445. {
  62446. startThread (priority);
  62447. startTimer (100);
  62448. {
  62449. const ScopedLock sl (messageLock);
  62450. alertWindow->setMessage (message);
  62451. }
  62452. const bool finishedNaturally = alertWindow->runModalLoop() != 0;
  62453. stopThread (timeOutMsWhenCancelling);
  62454. alertWindow->setVisible (false);
  62455. return finishedNaturally;
  62456. }
  62457. void ThreadWithProgressWindow::setProgress (const double newProgress)
  62458. {
  62459. progress = newProgress;
  62460. }
  62461. void ThreadWithProgressWindow::setStatusMessage (const String& newStatusMessage)
  62462. {
  62463. const ScopedLock sl (messageLock);
  62464. message = newStatusMessage;
  62465. }
  62466. void ThreadWithProgressWindow::timerCallback()
  62467. {
  62468. if (! isThreadRunning())
  62469. {
  62470. // thread has finished normally..
  62471. alertWindow->exitModalState (1);
  62472. alertWindow->setVisible (false);
  62473. }
  62474. else
  62475. {
  62476. const ScopedLock sl (messageLock);
  62477. alertWindow->setMessage (message);
  62478. }
  62479. }
  62480. END_JUCE_NAMESPACE
  62481. /*** End of inlined file: juce_ThreadWithProgressWindow.cpp ***/
  62482. /*** Start of inlined file: juce_TooltipWindow.cpp ***/
  62483. BEGIN_JUCE_NAMESPACE
  62484. TooltipWindow::TooltipWindow (Component* const parentComponent,
  62485. const int millisecondsBeforeTipAppears_)
  62486. : Component ("tooltip"),
  62487. millisecondsBeforeTipAppears (millisecondsBeforeTipAppears_),
  62488. lastHideTime (0),
  62489. lastComponentUnderMouse (0),
  62490. changedCompsSinceShown (true)
  62491. {
  62492. startTimer (123);
  62493. setAlwaysOnTop (true);
  62494. setOpaque (true);
  62495. if (parentComponent != 0)
  62496. parentComponent->addChildComponent (this);
  62497. }
  62498. TooltipWindow::~TooltipWindow()
  62499. {
  62500. hide();
  62501. }
  62502. void TooltipWindow::setMillisecondsBeforeTipAppears (const int newTimeMs) throw()
  62503. {
  62504. millisecondsBeforeTipAppears = newTimeMs;
  62505. }
  62506. void TooltipWindow::paint (Graphics& g)
  62507. {
  62508. getLookAndFeel().drawTooltip (g, tipShowing, getWidth(), getHeight());
  62509. }
  62510. void TooltipWindow::mouseEnter (const MouseEvent&)
  62511. {
  62512. hide();
  62513. }
  62514. void TooltipWindow::showFor (const String& tip)
  62515. {
  62516. jassert (tip.isNotEmpty());
  62517. tipShowing = tip;
  62518. Point<int> mousePos (Desktop::getMousePosition());
  62519. if (getParentComponent() != 0)
  62520. mousePos = getParentComponent()->globalPositionToRelative (mousePos);
  62521. int x, y, w, h;
  62522. getLookAndFeel().getTooltipSize (tip, w, h);
  62523. if (mousePos.getX() > getParentWidth() / 2)
  62524. x = mousePos.getX() - (w + 12);
  62525. else
  62526. x = mousePos.getX() + 24;
  62527. if (mousePos.getY() > getParentHeight() / 2)
  62528. y = mousePos.getY() - (h + 6);
  62529. else
  62530. y = mousePos.getY() + 6;
  62531. setBounds (x, y, w, h);
  62532. setVisible (true);
  62533. if (getParentComponent() == 0)
  62534. {
  62535. addToDesktop (ComponentPeer::windowHasDropShadow
  62536. | ComponentPeer::windowIsTemporary
  62537. | ComponentPeer::windowIgnoresKeyPresses);
  62538. }
  62539. toFront (false);
  62540. }
  62541. const String TooltipWindow::getTipFor (Component* const c)
  62542. {
  62543. if (c != 0
  62544. && Process::isForegroundProcess()
  62545. && ! Component::isMouseButtonDownAnywhere())
  62546. {
  62547. TooltipClient* const ttc = dynamic_cast <TooltipClient*> (c);
  62548. if (ttc != 0 && ! c->isCurrentlyBlockedByAnotherModalComponent())
  62549. return ttc->getTooltip();
  62550. }
  62551. return String::empty;
  62552. }
  62553. void TooltipWindow::hide()
  62554. {
  62555. tipShowing = String::empty;
  62556. removeFromDesktop();
  62557. setVisible (false);
  62558. }
  62559. void TooltipWindow::timerCallback()
  62560. {
  62561. const unsigned int now = Time::getApproximateMillisecondCounter();
  62562. Component* const newComp = Desktop::getInstance().getMainMouseSource().getComponentUnderMouse();
  62563. const String newTip (getTipFor (newComp));
  62564. const bool tipChanged = (newTip != lastTipUnderMouse || newComp != lastComponentUnderMouse);
  62565. lastComponentUnderMouse = newComp;
  62566. lastTipUnderMouse = newTip;
  62567. const int clickCount = Desktop::getInstance().getMouseButtonClickCounter();
  62568. const bool mouseWasClicked = clickCount > mouseClicks;
  62569. mouseClicks = clickCount;
  62570. const Point<int> mousePos (Desktop::getMousePosition());
  62571. const bool mouseMovedQuickly = mousePos.getDistanceFrom (lastMousePos) > 12;
  62572. lastMousePos = mousePos;
  62573. if (tipChanged || mouseWasClicked || mouseMovedQuickly)
  62574. lastCompChangeTime = now;
  62575. if (isVisible() || now < lastHideTime + 500)
  62576. {
  62577. // if a tip is currently visible (or has just disappeared), update to a new one
  62578. // immediately if needed..
  62579. if (newComp == 0 || mouseWasClicked || newTip.isEmpty())
  62580. {
  62581. if (isVisible())
  62582. {
  62583. lastHideTime = now;
  62584. hide();
  62585. }
  62586. }
  62587. else if (tipChanged)
  62588. {
  62589. showFor (newTip);
  62590. }
  62591. }
  62592. else
  62593. {
  62594. // if there isn't currently a tip, but one is needed, only let it
  62595. // appear after a timeout..
  62596. if (newTip.isNotEmpty()
  62597. && newTip != tipShowing
  62598. && now > lastCompChangeTime + millisecondsBeforeTipAppears)
  62599. {
  62600. showFor (newTip);
  62601. }
  62602. }
  62603. }
  62604. END_JUCE_NAMESPACE
  62605. /*** End of inlined file: juce_TooltipWindow.cpp ***/
  62606. /*** Start of inlined file: juce_TopLevelWindow.cpp ***/
  62607. BEGIN_JUCE_NAMESPACE
  62608. class TopLevelWindowManager : public Timer,
  62609. public DeletedAtShutdown
  62610. {
  62611. public:
  62612. TopLevelWindowManager()
  62613. : currentActive (0)
  62614. {
  62615. }
  62616. ~TopLevelWindowManager()
  62617. {
  62618. clearSingletonInstance();
  62619. }
  62620. juce_DeclareSingleton_SingleThreaded_Minimal (TopLevelWindowManager)
  62621. void timerCallback()
  62622. {
  62623. startTimer (jmin (1731, getTimerInterval() * 2));
  62624. TopLevelWindow* active = 0;
  62625. if (Process::isForegroundProcess())
  62626. {
  62627. active = currentActive;
  62628. Component* const c = Component::getCurrentlyFocusedComponent();
  62629. TopLevelWindow* tlw = dynamic_cast <TopLevelWindow*> (c);
  62630. if (tlw == 0 && c != 0)
  62631. // (unable to use the syntax findParentComponentOfClass <TopLevelWindow> () because of a VC6 compiler bug)
  62632. tlw = c->findParentComponentOfClass ((TopLevelWindow*) 0);
  62633. if (tlw != 0)
  62634. active = tlw;
  62635. }
  62636. if (active != currentActive)
  62637. {
  62638. currentActive = active;
  62639. for (int i = windows.size(); --i >= 0;)
  62640. {
  62641. TopLevelWindow* const tlw = (TopLevelWindow*) windows.getUnchecked (i);
  62642. tlw->setWindowActive (isWindowActive (tlw));
  62643. i = jmin (i, windows.size() - 1);
  62644. }
  62645. Desktop::getInstance().triggerFocusCallback();
  62646. }
  62647. }
  62648. bool addWindow (TopLevelWindow* const w) throw()
  62649. {
  62650. windows.add (w);
  62651. startTimer (10);
  62652. return isWindowActive (w);
  62653. }
  62654. void removeWindow (TopLevelWindow* const w) throw()
  62655. {
  62656. startTimer (10);
  62657. if (currentActive == w)
  62658. currentActive = 0;
  62659. windows.removeValue (w);
  62660. if (windows.size() == 0)
  62661. deleteInstance();
  62662. }
  62663. VoidArray windows;
  62664. private:
  62665. TopLevelWindow* currentActive;
  62666. bool isWindowActive (TopLevelWindow* const tlw) const throw()
  62667. {
  62668. return (tlw == currentActive
  62669. || tlw->isParentOf (currentActive)
  62670. || tlw->hasKeyboardFocus (true))
  62671. && tlw->isShowing();
  62672. }
  62673. TopLevelWindowManager (const TopLevelWindowManager&);
  62674. TopLevelWindowManager& operator= (const TopLevelWindowManager&);
  62675. };
  62676. juce_ImplementSingleton_SingleThreaded (TopLevelWindowManager)
  62677. void juce_CheckCurrentlyFocusedTopLevelWindow()
  62678. {
  62679. if (TopLevelWindowManager::getInstanceWithoutCreating() != 0)
  62680. TopLevelWindowManager::getInstanceWithoutCreating()->startTimer (20);
  62681. }
  62682. TopLevelWindow::TopLevelWindow (const String& name,
  62683. const bool addToDesktop_)
  62684. : Component (name),
  62685. useDropShadow (true),
  62686. useNativeTitleBar (false),
  62687. windowIsActive_ (false)
  62688. {
  62689. setOpaque (true);
  62690. if (addToDesktop_)
  62691. Component::addToDesktop (getDesktopWindowStyleFlags());
  62692. else
  62693. setDropShadowEnabled (true);
  62694. setWantsKeyboardFocus (true);
  62695. setBroughtToFrontOnMouseClick (true);
  62696. windowIsActive_ = TopLevelWindowManager::getInstance()->addWindow (this);
  62697. }
  62698. TopLevelWindow::~TopLevelWindow()
  62699. {
  62700. shadower = 0;
  62701. TopLevelWindowManager::getInstance()->removeWindow (this);
  62702. }
  62703. void TopLevelWindow::focusOfChildComponentChanged (FocusChangeType)
  62704. {
  62705. if (hasKeyboardFocus (true))
  62706. TopLevelWindowManager::getInstance()->timerCallback();
  62707. else
  62708. TopLevelWindowManager::getInstance()->startTimer (10);
  62709. }
  62710. void TopLevelWindow::setWindowActive (const bool isNowActive) throw()
  62711. {
  62712. if (windowIsActive_ != isNowActive)
  62713. {
  62714. windowIsActive_ = isNowActive;
  62715. activeWindowStatusChanged();
  62716. }
  62717. }
  62718. void TopLevelWindow::activeWindowStatusChanged()
  62719. {
  62720. }
  62721. void TopLevelWindow::parentHierarchyChanged()
  62722. {
  62723. setDropShadowEnabled (useDropShadow);
  62724. }
  62725. void TopLevelWindow::visibilityChanged()
  62726. {
  62727. if (isShowing())
  62728. toFront (true);
  62729. }
  62730. int TopLevelWindow::getDesktopWindowStyleFlags() const
  62731. {
  62732. int flags = ComponentPeer::windowAppearsOnTaskbar;
  62733. if (useDropShadow)
  62734. flags |= ComponentPeer::windowHasDropShadow;
  62735. if (useNativeTitleBar)
  62736. flags |= ComponentPeer::windowHasTitleBar;
  62737. return flags;
  62738. }
  62739. void TopLevelWindow::setDropShadowEnabled (const bool useShadow)
  62740. {
  62741. useDropShadow = useShadow;
  62742. if (isOnDesktop())
  62743. {
  62744. shadower = 0;
  62745. Component::addToDesktop (getDesktopWindowStyleFlags());
  62746. }
  62747. else
  62748. {
  62749. if (useShadow && isOpaque())
  62750. {
  62751. if (shadower == 0)
  62752. {
  62753. shadower = getLookAndFeel().createDropShadowerForComponent (this);
  62754. if (shadower != 0)
  62755. shadower->setOwner (this);
  62756. }
  62757. }
  62758. else
  62759. {
  62760. shadower = 0;
  62761. }
  62762. }
  62763. }
  62764. void TopLevelWindow::setUsingNativeTitleBar (const bool useNativeTitleBar_)
  62765. {
  62766. if (useNativeTitleBar != useNativeTitleBar_)
  62767. {
  62768. useNativeTitleBar = useNativeTitleBar_;
  62769. recreateDesktopWindow();
  62770. sendLookAndFeelChange();
  62771. }
  62772. }
  62773. void TopLevelWindow::recreateDesktopWindow()
  62774. {
  62775. if (isOnDesktop())
  62776. {
  62777. Component::addToDesktop (getDesktopWindowStyleFlags());
  62778. toFront (true);
  62779. }
  62780. }
  62781. void TopLevelWindow::addToDesktop (int windowStyleFlags, void* nativeWindowToAttachTo)
  62782. {
  62783. /* It's not recommended to change the desktop window flags directly for a TopLevelWindow,
  62784. because this class needs to make sure its layout corresponds with settings like whether
  62785. it's got a native title bar or not.
  62786. If you need custom flags for your window, you can override the getDesktopWindowStyleFlags()
  62787. method. If you do this, it's best to call the base class's getDesktopWindowStyleFlags()
  62788. method, then add or remove whatever flags are necessary from this value before returning it.
  62789. */
  62790. jassert ((windowStyleFlags & ~ComponentPeer::windowIsSemiTransparent)
  62791. == (getDesktopWindowStyleFlags() & ~ComponentPeer::windowIsSemiTransparent));
  62792. Component::addToDesktop (windowStyleFlags, nativeWindowToAttachTo);
  62793. if (windowStyleFlags != getDesktopWindowStyleFlags())
  62794. sendLookAndFeelChange();
  62795. }
  62796. void TopLevelWindow::centreAroundComponent (Component* c, const int width, const int height)
  62797. {
  62798. if (c == 0)
  62799. c = TopLevelWindow::getActiveTopLevelWindow();
  62800. if (c == 0)
  62801. {
  62802. centreWithSize (width, height);
  62803. }
  62804. else
  62805. {
  62806. Point<int> p (c->relativePositionToGlobal (Point<int> ((c->getWidth() - width) / 2,
  62807. (c->getHeight() - height) / 2)));
  62808. Rectangle<int> parentArea (c->getParentMonitorArea());
  62809. if (getParentComponent() != 0)
  62810. {
  62811. p = getParentComponent()->globalPositionToRelative (p);
  62812. parentArea.setBounds (0, 0, getParentWidth(), getParentHeight());
  62813. }
  62814. parentArea.reduce (12, 12);
  62815. setBounds (jlimit (parentArea.getX(), jmax (parentArea.getX(), parentArea.getRight() - width), p.getX()),
  62816. jlimit (parentArea.getY(), jmax (parentArea.getY(), parentArea.getBottom() - height), p.getY()),
  62817. width, height);
  62818. }
  62819. }
  62820. int TopLevelWindow::getNumTopLevelWindows() throw()
  62821. {
  62822. return TopLevelWindowManager::getInstance()->windows.size();
  62823. }
  62824. TopLevelWindow* TopLevelWindow::getTopLevelWindow (const int index) throw()
  62825. {
  62826. return (TopLevelWindow*) TopLevelWindowManager::getInstance()->windows [index];
  62827. }
  62828. TopLevelWindow* TopLevelWindow::getActiveTopLevelWindow() throw()
  62829. {
  62830. TopLevelWindow* best = 0;
  62831. int bestNumTWLParents = -1;
  62832. for (int i = TopLevelWindow::getNumTopLevelWindows(); --i >= 0;)
  62833. {
  62834. TopLevelWindow* const tlw = TopLevelWindow::getTopLevelWindow (i);
  62835. if (tlw->isActiveWindow())
  62836. {
  62837. int numTWLParents = 0;
  62838. const Component* c = tlw->getParentComponent();
  62839. while (c != 0)
  62840. {
  62841. if (dynamic_cast <const TopLevelWindow*> (c) != 0)
  62842. ++numTWLParents;
  62843. c = c->getParentComponent();
  62844. }
  62845. if (bestNumTWLParents < numTWLParents)
  62846. {
  62847. best = tlw;
  62848. bestNumTWLParents = numTWLParents;
  62849. }
  62850. }
  62851. }
  62852. return best;
  62853. }
  62854. END_JUCE_NAMESPACE
  62855. /*** End of inlined file: juce_TopLevelWindow.cpp ***/
  62856. /*** Start of inlined file: juce_Colour.cpp ***/
  62857. BEGIN_JUCE_NAMESPACE
  62858. namespace ColourHelpers
  62859. {
  62860. static uint8 floatAlphaToInt (const float alpha) throw()
  62861. {
  62862. return (uint8) jlimit (0, 0xff, roundToInt (alpha * 255.0f));
  62863. }
  62864. static void convertHSBtoRGB (float h, float s, float v,
  62865. uint8& r, uint8& g, uint8& b) throw()
  62866. {
  62867. v = jlimit (0.0f, 1.0f, v);
  62868. v *= 255.0f;
  62869. const uint8 intV = (uint8) roundToInt (v);
  62870. if (s <= 0)
  62871. {
  62872. r = intV;
  62873. g = intV;
  62874. b = intV;
  62875. }
  62876. else
  62877. {
  62878. s = jmin (1.0f, s);
  62879. h = jlimit (0.0f, 1.0f, h);
  62880. h = (h - floorf (h)) * 6.0f + 0.00001f; // need a small adjustment to compensate for rounding errors
  62881. const float f = h - floorf (h);
  62882. const uint8 x = (uint8) roundToInt (v * (1.0f - s));
  62883. const float y = v * (1.0f - s * f);
  62884. const float z = v * (1.0f - (s * (1.0f - f)));
  62885. if (h < 1.0f)
  62886. {
  62887. r = intV;
  62888. g = (uint8) roundToInt (z);
  62889. b = x;
  62890. }
  62891. else if (h < 2.0f)
  62892. {
  62893. r = (uint8) roundToInt (y);
  62894. g = intV;
  62895. b = x;
  62896. }
  62897. else if (h < 3.0f)
  62898. {
  62899. r = x;
  62900. g = intV;
  62901. b = (uint8) roundToInt (z);
  62902. }
  62903. else if (h < 4.0f)
  62904. {
  62905. r = x;
  62906. g = (uint8) roundToInt (y);
  62907. b = intV;
  62908. }
  62909. else if (h < 5.0f)
  62910. {
  62911. r = (uint8) roundToInt (z);
  62912. g = x;
  62913. b = intV;
  62914. }
  62915. else if (h < 6.0f)
  62916. {
  62917. r = intV;
  62918. g = x;
  62919. b = (uint8) roundToInt (y);
  62920. }
  62921. else
  62922. {
  62923. r = 0;
  62924. g = 0;
  62925. b = 0;
  62926. }
  62927. }
  62928. }
  62929. }
  62930. Colour::Colour() throw()
  62931. : argb (0)
  62932. {
  62933. }
  62934. Colour::Colour (const Colour& other) throw()
  62935. : argb (other.argb)
  62936. {
  62937. }
  62938. Colour& Colour::operator= (const Colour& other) throw()
  62939. {
  62940. argb = other.argb;
  62941. return *this;
  62942. }
  62943. bool Colour::operator== (const Colour& other) const throw()
  62944. {
  62945. return argb.getARGB() == other.argb.getARGB();
  62946. }
  62947. bool Colour::operator!= (const Colour& other) const throw()
  62948. {
  62949. return argb.getARGB() != other.argb.getARGB();
  62950. }
  62951. Colour::Colour (const uint32 argb_) throw()
  62952. : argb (argb_)
  62953. {
  62954. }
  62955. Colour::Colour (const uint8 red,
  62956. const uint8 green,
  62957. const uint8 blue) throw()
  62958. {
  62959. argb.setARGB (0xff, red, green, blue);
  62960. }
  62961. const Colour Colour::fromRGB (const uint8 red,
  62962. const uint8 green,
  62963. const uint8 blue) throw()
  62964. {
  62965. return Colour (red, green, blue);
  62966. }
  62967. Colour::Colour (const uint8 red,
  62968. const uint8 green,
  62969. const uint8 blue,
  62970. const uint8 alpha) throw()
  62971. {
  62972. argb.setARGB (alpha, red, green, blue);
  62973. }
  62974. const Colour Colour::fromRGBA (const uint8 red,
  62975. const uint8 green,
  62976. const uint8 blue,
  62977. const uint8 alpha) throw()
  62978. {
  62979. return Colour (red, green, blue, alpha);
  62980. }
  62981. Colour::Colour (const uint8 red,
  62982. const uint8 green,
  62983. const uint8 blue,
  62984. const float alpha) throw()
  62985. {
  62986. argb.setARGB (ColourHelpers::floatAlphaToInt (alpha), red, green, blue);
  62987. }
  62988. const Colour Colour::fromRGBAFloat (const uint8 red,
  62989. const uint8 green,
  62990. const uint8 blue,
  62991. const float alpha) throw()
  62992. {
  62993. return Colour (red, green, blue, alpha);
  62994. }
  62995. Colour::Colour (const float hue,
  62996. const float saturation,
  62997. const float brightness,
  62998. const float alpha) throw()
  62999. {
  63000. uint8 r = getRed(), g = getGreen(), b = getBlue();
  63001. ColourHelpers::convertHSBtoRGB (hue, saturation, brightness, r, g, b);
  63002. argb.setARGB (ColourHelpers::floatAlphaToInt (alpha), r, g, b);
  63003. }
  63004. const Colour Colour::fromHSV (const float hue,
  63005. const float saturation,
  63006. const float brightness,
  63007. const float alpha) throw()
  63008. {
  63009. return Colour (hue, saturation, brightness, alpha);
  63010. }
  63011. Colour::Colour (const float hue,
  63012. const float saturation,
  63013. const float brightness,
  63014. const uint8 alpha) throw()
  63015. {
  63016. uint8 r = getRed(), g = getGreen(), b = getBlue();
  63017. ColourHelpers::convertHSBtoRGB (hue, saturation, brightness, r, g, b);
  63018. argb.setARGB (alpha, r, g, b);
  63019. }
  63020. Colour::~Colour() throw()
  63021. {
  63022. }
  63023. const PixelARGB Colour::getPixelARGB() const throw()
  63024. {
  63025. PixelARGB p (argb);
  63026. p.premultiply();
  63027. return p;
  63028. }
  63029. uint32 Colour::getARGB() const throw()
  63030. {
  63031. return argb.getARGB();
  63032. }
  63033. bool Colour::isTransparent() const throw()
  63034. {
  63035. return getAlpha() == 0;
  63036. }
  63037. bool Colour::isOpaque() const throw()
  63038. {
  63039. return getAlpha() == 0xff;
  63040. }
  63041. const Colour Colour::withAlpha (const uint8 newAlpha) const throw()
  63042. {
  63043. PixelARGB newCol (argb);
  63044. newCol.setAlpha (newAlpha);
  63045. return Colour (newCol.getARGB());
  63046. }
  63047. const Colour Colour::withAlpha (const float newAlpha) const throw()
  63048. {
  63049. jassert (newAlpha >= 0 && newAlpha <= 1.0f);
  63050. PixelARGB newCol (argb);
  63051. newCol.setAlpha (ColourHelpers::floatAlphaToInt (newAlpha));
  63052. return Colour (newCol.getARGB());
  63053. }
  63054. const Colour Colour::withMultipliedAlpha (const float alphaMultiplier) const throw()
  63055. {
  63056. jassert (alphaMultiplier >= 0);
  63057. PixelARGB newCol (argb);
  63058. newCol.setAlpha ((uint8) jmin (0xff, roundToInt (alphaMultiplier * newCol.getAlpha())));
  63059. return Colour (newCol.getARGB());
  63060. }
  63061. const Colour Colour::overlaidWith (const Colour& src) const throw()
  63062. {
  63063. const int destAlpha = getAlpha();
  63064. if (destAlpha > 0)
  63065. {
  63066. const int invA = 0xff - (int) src.getAlpha();
  63067. const int resA = 0xff - (((0xff - destAlpha) * invA) >> 8);
  63068. if (resA > 0)
  63069. {
  63070. const int da = (invA * destAlpha) / resA;
  63071. return Colour ((uint8) (src.getRed() + ((((int) getRed() - src.getRed()) * da) >> 8)),
  63072. (uint8) (src.getGreen() + ((((int) getGreen() - src.getGreen()) * da) >> 8)),
  63073. (uint8) (src.getBlue() + ((((int) getBlue() - src.getBlue()) * da) >> 8)),
  63074. (uint8) resA);
  63075. }
  63076. return *this;
  63077. }
  63078. else
  63079. {
  63080. return src;
  63081. }
  63082. }
  63083. const Colour Colour::interpolatedWith (const Colour& other, float proportionOfOther) const throw()
  63084. {
  63085. if (proportionOfOther <= 0)
  63086. return *this;
  63087. if (proportionOfOther >= 1.0f)
  63088. return other;
  63089. PixelARGB c1 (getPixelARGB());
  63090. const PixelARGB c2 (other.getPixelARGB());
  63091. c1.tween (c2, roundToInt (proportionOfOther * 255.0f));
  63092. c1.unpremultiply();
  63093. return Colour (c1.getARGB());
  63094. }
  63095. float Colour::getFloatRed() const throw()
  63096. {
  63097. return getRed() / 255.0f;
  63098. }
  63099. float Colour::getFloatGreen() const throw()
  63100. {
  63101. return getGreen() / 255.0f;
  63102. }
  63103. float Colour::getFloatBlue() const throw()
  63104. {
  63105. return getBlue() / 255.0f;
  63106. }
  63107. float Colour::getFloatAlpha() const throw()
  63108. {
  63109. return getAlpha() / 255.0f;
  63110. }
  63111. void Colour::getHSB (float& h, float& s, float& v) const throw()
  63112. {
  63113. const int r = getRed();
  63114. const int g = getGreen();
  63115. const int b = getBlue();
  63116. const int hi = jmax (r, g, b);
  63117. const int lo = jmin (r, g, b);
  63118. if (hi != 0)
  63119. {
  63120. s = (hi - lo) / (float) hi;
  63121. if (s != 0)
  63122. {
  63123. const float invDiff = 1.0f / (hi - lo);
  63124. const float red = (hi - r) * invDiff;
  63125. const float green = (hi - g) * invDiff;
  63126. const float blue = (hi - b) * invDiff;
  63127. if (r == hi)
  63128. h = blue - green;
  63129. else if (g == hi)
  63130. h = 2.0f + red - blue;
  63131. else
  63132. h = 4.0f + green - red;
  63133. h *= 1.0f / 6.0f;
  63134. if (h < 0)
  63135. ++h;
  63136. }
  63137. else
  63138. {
  63139. h = 0;
  63140. }
  63141. }
  63142. else
  63143. {
  63144. s = 0;
  63145. h = 0;
  63146. }
  63147. v = hi / 255.0f;
  63148. }
  63149. float Colour::getHue() const throw()
  63150. {
  63151. float h, s, b;
  63152. getHSB (h, s, b);
  63153. return h;
  63154. }
  63155. const Colour Colour::withHue (const float hue) const throw()
  63156. {
  63157. float h, s, b;
  63158. getHSB (h, s, b);
  63159. return Colour (hue, s, b, getAlpha());
  63160. }
  63161. const Colour Colour::withRotatedHue (const float amountToRotate) const throw()
  63162. {
  63163. float h, s, b;
  63164. getHSB (h, s, b);
  63165. h += amountToRotate;
  63166. h -= floorf (h);
  63167. return Colour (h, s, b, getAlpha());
  63168. }
  63169. float Colour::getSaturation() const throw()
  63170. {
  63171. float h, s, b;
  63172. getHSB (h, s, b);
  63173. return s;
  63174. }
  63175. const Colour Colour::withSaturation (const float saturation) const throw()
  63176. {
  63177. float h, s, b;
  63178. getHSB (h, s, b);
  63179. return Colour (h, saturation, b, getAlpha());
  63180. }
  63181. const Colour Colour::withMultipliedSaturation (const float amount) const throw()
  63182. {
  63183. float h, s, b;
  63184. getHSB (h, s, b);
  63185. return Colour (h, jmin (1.0f, s * amount), b, getAlpha());
  63186. }
  63187. float Colour::getBrightness() const throw()
  63188. {
  63189. float h, s, b;
  63190. getHSB (h, s, b);
  63191. return b;
  63192. }
  63193. const Colour Colour::withBrightness (const float brightness) const throw()
  63194. {
  63195. float h, s, b;
  63196. getHSB (h, s, b);
  63197. return Colour (h, s, brightness, getAlpha());
  63198. }
  63199. const Colour Colour::withMultipliedBrightness (const float amount) const throw()
  63200. {
  63201. float h, s, b;
  63202. getHSB (h, s, b);
  63203. b *= amount;
  63204. if (b > 1.0f)
  63205. b = 1.0f;
  63206. return Colour (h, s, b, getAlpha());
  63207. }
  63208. const Colour Colour::brighter (float amount) const throw()
  63209. {
  63210. amount = 1.0f / (1.0f + amount);
  63211. return Colour ((uint8) (255 - (amount * (255 - getRed()))),
  63212. (uint8) (255 - (amount * (255 - getGreen()))),
  63213. (uint8) (255 - (amount * (255 - getBlue()))),
  63214. getAlpha());
  63215. }
  63216. const Colour Colour::darker (float amount) const throw()
  63217. {
  63218. amount = 1.0f / (1.0f + amount);
  63219. return Colour ((uint8) (amount * getRed()),
  63220. (uint8) (amount * getGreen()),
  63221. (uint8) (amount * getBlue()),
  63222. getAlpha());
  63223. }
  63224. const Colour Colour::greyLevel (const float brightness) throw()
  63225. {
  63226. const uint8 level
  63227. = (uint8) jlimit (0x00, 0xff, roundToInt (brightness * 255.0f));
  63228. return Colour (level, level, level);
  63229. }
  63230. const Colour Colour::contrasting (const float amount) const throw()
  63231. {
  63232. return overlaidWith ((((int) getRed() + (int) getGreen() + (int) getBlue() >= 3 * 128)
  63233. ? Colours::black
  63234. : Colours::white).withAlpha (amount));
  63235. }
  63236. const Colour Colour::contrasting (const Colour& colour1,
  63237. const Colour& colour2) throw()
  63238. {
  63239. const float b1 = colour1.getBrightness();
  63240. const float b2 = colour2.getBrightness();
  63241. float best = 0.0f;
  63242. float bestDist = 0.0f;
  63243. for (float i = 0.0f; i < 1.0f; i += 0.02f)
  63244. {
  63245. const float d1 = fabsf (i - b1);
  63246. const float d2 = fabsf (i - b2);
  63247. const float dist = jmin (d1, d2, 1.0f - d1, 1.0f - d2);
  63248. if (dist > bestDist)
  63249. {
  63250. best = i;
  63251. bestDist = dist;
  63252. }
  63253. }
  63254. return colour1.overlaidWith (colour2.withMultipliedAlpha (0.5f))
  63255. .withBrightness (best);
  63256. }
  63257. const String Colour::toString() const
  63258. {
  63259. return String::toHexString ((int) argb.getARGB());
  63260. }
  63261. const Colour Colour::fromString (const String& encodedColourString)
  63262. {
  63263. return Colour ((uint32) encodedColourString.getHexValue32());
  63264. }
  63265. const String Colour::toDisplayString (const bool includeAlphaValue) const
  63266. {
  63267. return String::toHexString ((int) (argb.getARGB() & (includeAlphaValue ? 0xffffffff : 0xffffff)))
  63268. .paddedLeft ('0', includeAlphaValue ? 8 : 6)
  63269. .toUpperCase();
  63270. }
  63271. END_JUCE_NAMESPACE
  63272. /*** End of inlined file: juce_Colour.cpp ***/
  63273. /*** Start of inlined file: juce_ColourGradient.cpp ***/
  63274. BEGIN_JUCE_NAMESPACE
  63275. ColourGradient::ColourGradient() throw()
  63276. {
  63277. #ifdef JUCE_DEBUG
  63278. x1 = 987654.0f;
  63279. #endif
  63280. }
  63281. ColourGradient::ColourGradient (const Colour& colour1,
  63282. const float x1_,
  63283. const float y1_,
  63284. const Colour& colour2,
  63285. const float x2_,
  63286. const float y2_,
  63287. const bool isRadial_) throw()
  63288. : x1 (x1_),
  63289. y1 (y1_),
  63290. x2 (x2_),
  63291. y2 (y2_),
  63292. isRadial (isRadial_)
  63293. {
  63294. colours.add (0);
  63295. colours.add (colour1.getARGB());
  63296. colours.add (1 << 16);
  63297. colours.add (colour2.getARGB());
  63298. }
  63299. ColourGradient::~ColourGradient() throw()
  63300. {
  63301. }
  63302. void ColourGradient::clearColours() throw()
  63303. {
  63304. colours.clear();
  63305. }
  63306. void ColourGradient::addColour (const double proportionAlongGradient,
  63307. const Colour& colour) throw()
  63308. {
  63309. // must be within the two end-points
  63310. jassert (proportionAlongGradient >= 0 && proportionAlongGradient <= 1.0);
  63311. const uint32 pos = jlimit (0, 65535, roundToInt (proportionAlongGradient * 65536.0));
  63312. int i;
  63313. for (i = 0; i < colours.size(); i += 2)
  63314. if (colours.getUnchecked(i) > pos)
  63315. break;
  63316. colours.insert (i, pos);
  63317. colours.insert (i + 1, colour.getARGB());
  63318. }
  63319. void ColourGradient::multiplyOpacity (const float multiplier) throw()
  63320. {
  63321. for (int i = 1; i < colours.size(); i += 2)
  63322. {
  63323. const Colour c (colours.getUnchecked(i));
  63324. colours.set (i, c.withMultipliedAlpha (multiplier).getARGB());
  63325. }
  63326. }
  63327. int ColourGradient::getNumColours() const throw()
  63328. {
  63329. return colours.size() >> 1;
  63330. }
  63331. double ColourGradient::getColourPosition (const int index) const throw()
  63332. {
  63333. return jlimit (0.0, 1.0, colours [index << 1] / 65535.0);
  63334. }
  63335. const Colour ColourGradient::getColour (const int index) const throw()
  63336. {
  63337. return Colour (colours [(index << 1) + 1]);
  63338. }
  63339. const Colour ColourGradient::getColourAtPosition (const float position) const throw()
  63340. {
  63341. jassert (colours.getUnchecked (0) == 0); // the first colour specified has to go at position 0
  63342. const int integerPos = jlimit (0, 65535, roundToInt (position * 65536.0f));
  63343. if (integerPos <= 0 || colours.size() <= 2)
  63344. return getColour (0);
  63345. int i = colours.size() - 2;
  63346. while (integerPos < (int) colours.getUnchecked(i))
  63347. i -= 2;
  63348. if (i >= colours.size() - 2)
  63349. return Colour (colours.getUnchecked(i));
  63350. const int pos1 = colours.getUnchecked (i);
  63351. const Colour col1 (colours.getUnchecked (i + 1));
  63352. const int pos2 = colours.getUnchecked (i + 2);
  63353. const Colour col2 (colours.getUnchecked (i + 3));
  63354. return col1.interpolatedWith (col2, (integerPos - pos1) / (float) (pos2 - pos1));
  63355. }
  63356. int ColourGradient::createLookupTable (const AffineTransform& transform, HeapBlock <PixelARGB>& lookupTable) const throw()
  63357. {
  63358. #ifdef JUCE_DEBUG
  63359. // trying to use the object without setting its co-ordinates? Have a careful read of
  63360. // the comments for the constructors.
  63361. jassert (x1 != 987654.0f);
  63362. #endif
  63363. const int numColours = colours.size() >> 1;
  63364. float tx1 = x1, ty1 = y1, tx2 = x2, ty2 = y2;
  63365. transform.transformPoint (tx1, ty1);
  63366. transform.transformPoint (tx2, ty2);
  63367. const double distance = juce_hypot (tx1 - tx2, ty1 - ty2);
  63368. const int numEntries = jlimit (1, (numColours - 1) << 8, 3 * (int) distance);
  63369. lookupTable.malloc (numEntries);
  63370. if (numColours >= 2)
  63371. {
  63372. jassert (colours.getUnchecked (0) == 0); // the first colour specified has to go at position 0
  63373. PixelARGB pix1 (colours.getUnchecked (1));
  63374. pix1.premultiply();
  63375. int index = 0;
  63376. for (int j = 2; j < colours.size(); j += 2)
  63377. {
  63378. const int numToDo = ((colours.getUnchecked (j) * (numEntries - 1)) >> 16) - index;
  63379. PixelARGB pix2 (colours.getUnchecked (j + 1));
  63380. pix2.premultiply();
  63381. for (int i = 0; i < numToDo; ++i)
  63382. {
  63383. jassert (index >= 0 && index < numEntries);
  63384. lookupTable[index] = pix1;
  63385. lookupTable[index].tween (pix2, (i << 8) / numToDo);
  63386. ++index;
  63387. }
  63388. pix1 = pix2;
  63389. }
  63390. while (index < numEntries)
  63391. lookupTable [index++] = pix1;
  63392. }
  63393. else
  63394. {
  63395. jassertfalse // no colours specified!
  63396. }
  63397. return numEntries;
  63398. }
  63399. bool ColourGradient::isOpaque() const throw()
  63400. {
  63401. for (int i = 1; i < colours.size(); i += 2)
  63402. if (PixelARGB (colours.getUnchecked(i)).getAlpha() < 0xff)
  63403. return false;
  63404. return true;
  63405. }
  63406. bool ColourGradient::isInvisible() const throw()
  63407. {
  63408. for (int i = 1; i < colours.size(); i += 2)
  63409. if (PixelARGB (colours.getUnchecked(i)).getAlpha() > 0)
  63410. return false;
  63411. return true;
  63412. }
  63413. END_JUCE_NAMESPACE
  63414. /*** End of inlined file: juce_ColourGradient.cpp ***/
  63415. /*** Start of inlined file: juce_Colours.cpp ***/
  63416. BEGIN_JUCE_NAMESPACE
  63417. const Colour Colours::transparentBlack (0);
  63418. const Colour Colours::transparentWhite (0x00ffffff);
  63419. const Colour Colours::aliceblue (0xfff0f8ff);
  63420. const Colour Colours::antiquewhite (0xfffaebd7);
  63421. const Colour Colours::aqua (0xff00ffff);
  63422. const Colour Colours::aquamarine (0xff7fffd4);
  63423. const Colour Colours::azure (0xfff0ffff);
  63424. const Colour Colours::beige (0xfff5f5dc);
  63425. const Colour Colours::bisque (0xffffe4c4);
  63426. const Colour Colours::black (0xff000000);
  63427. const Colour Colours::blanchedalmond (0xffffebcd);
  63428. const Colour Colours::blue (0xff0000ff);
  63429. const Colour Colours::blueviolet (0xff8a2be2);
  63430. const Colour Colours::brown (0xffa52a2a);
  63431. const Colour Colours::burlywood (0xffdeb887);
  63432. const Colour Colours::cadetblue (0xff5f9ea0);
  63433. const Colour Colours::chartreuse (0xff7fff00);
  63434. const Colour Colours::chocolate (0xffd2691e);
  63435. const Colour Colours::coral (0xffff7f50);
  63436. const Colour Colours::cornflowerblue (0xff6495ed);
  63437. const Colour Colours::cornsilk (0xfffff8dc);
  63438. const Colour Colours::crimson (0xffdc143c);
  63439. const Colour Colours::cyan (0xff00ffff);
  63440. const Colour Colours::darkblue (0xff00008b);
  63441. const Colour Colours::darkcyan (0xff008b8b);
  63442. const Colour Colours::darkgoldenrod (0xffb8860b);
  63443. const Colour Colours::darkgrey (0xff555555);
  63444. const Colour Colours::darkgreen (0xff006400);
  63445. const Colour Colours::darkkhaki (0xffbdb76b);
  63446. const Colour Colours::darkmagenta (0xff8b008b);
  63447. const Colour Colours::darkolivegreen (0xff556b2f);
  63448. const Colour Colours::darkorange (0xffff8c00);
  63449. const Colour Colours::darkorchid (0xff9932cc);
  63450. const Colour Colours::darkred (0xff8b0000);
  63451. const Colour Colours::darksalmon (0xffe9967a);
  63452. const Colour Colours::darkseagreen (0xff8fbc8f);
  63453. const Colour Colours::darkslateblue (0xff483d8b);
  63454. const Colour Colours::darkslategrey (0xff2f4f4f);
  63455. const Colour Colours::darkturquoise (0xff00ced1);
  63456. const Colour Colours::darkviolet (0xff9400d3);
  63457. const Colour Colours::deeppink (0xffff1493);
  63458. const Colour Colours::deepskyblue (0xff00bfff);
  63459. const Colour Colours::dimgrey (0xff696969);
  63460. const Colour Colours::dodgerblue (0xff1e90ff);
  63461. const Colour Colours::firebrick (0xffb22222);
  63462. const Colour Colours::floralwhite (0xfffffaf0);
  63463. const Colour Colours::forestgreen (0xff228b22);
  63464. const Colour Colours::fuchsia (0xffff00ff);
  63465. const Colour Colours::gainsboro (0xffdcdcdc);
  63466. const Colour Colours::gold (0xffffd700);
  63467. const Colour Colours::goldenrod (0xffdaa520);
  63468. const Colour Colours::grey (0xff808080);
  63469. const Colour Colours::green (0xff008000);
  63470. const Colour Colours::greenyellow (0xffadff2f);
  63471. const Colour Colours::honeydew (0xfff0fff0);
  63472. const Colour Colours::hotpink (0xffff69b4);
  63473. const Colour Colours::indianred (0xffcd5c5c);
  63474. const Colour Colours::indigo (0xff4b0082);
  63475. const Colour Colours::ivory (0xfffffff0);
  63476. const Colour Colours::khaki (0xfff0e68c);
  63477. const Colour Colours::lavender (0xffe6e6fa);
  63478. const Colour Colours::lavenderblush (0xfffff0f5);
  63479. const Colour Colours::lemonchiffon (0xfffffacd);
  63480. const Colour Colours::lightblue (0xffadd8e6);
  63481. const Colour Colours::lightcoral (0xfff08080);
  63482. const Colour Colours::lightcyan (0xffe0ffff);
  63483. const Colour Colours::lightgoldenrodyellow (0xfffafad2);
  63484. const Colour Colours::lightgreen (0xff90ee90);
  63485. const Colour Colours::lightgrey (0xffd3d3d3);
  63486. const Colour Colours::lightpink (0xffffb6c1);
  63487. const Colour Colours::lightsalmon (0xffffa07a);
  63488. const Colour Colours::lightseagreen (0xff20b2aa);
  63489. const Colour Colours::lightskyblue (0xff87cefa);
  63490. const Colour Colours::lightslategrey (0xff778899);
  63491. const Colour Colours::lightsteelblue (0xffb0c4de);
  63492. const Colour Colours::lightyellow (0xffffffe0);
  63493. const Colour Colours::lime (0xff00ff00);
  63494. const Colour Colours::limegreen (0xff32cd32);
  63495. const Colour Colours::linen (0xfffaf0e6);
  63496. const Colour Colours::magenta (0xffff00ff);
  63497. const Colour Colours::maroon (0xff800000);
  63498. const Colour Colours::mediumaquamarine (0xff66cdaa);
  63499. const Colour Colours::mediumblue (0xff0000cd);
  63500. const Colour Colours::mediumorchid (0xffba55d3);
  63501. const Colour Colours::mediumpurple (0xff9370db);
  63502. const Colour Colours::mediumseagreen (0xff3cb371);
  63503. const Colour Colours::mediumslateblue (0xff7b68ee);
  63504. const Colour Colours::mediumspringgreen (0xff00fa9a);
  63505. const Colour Colours::mediumturquoise (0xff48d1cc);
  63506. const Colour Colours::mediumvioletred (0xffc71585);
  63507. const Colour Colours::midnightblue (0xff191970);
  63508. const Colour Colours::mintcream (0xfff5fffa);
  63509. const Colour Colours::mistyrose (0xffffe4e1);
  63510. const Colour Colours::navajowhite (0xffffdead);
  63511. const Colour Colours::navy (0xff000080);
  63512. const Colour Colours::oldlace (0xfffdf5e6);
  63513. const Colour Colours::olive (0xff808000);
  63514. const Colour Colours::olivedrab (0xff6b8e23);
  63515. const Colour Colours::orange (0xffffa500);
  63516. const Colour Colours::orangered (0xffff4500);
  63517. const Colour Colours::orchid (0xffda70d6);
  63518. const Colour Colours::palegoldenrod (0xffeee8aa);
  63519. const Colour Colours::palegreen (0xff98fb98);
  63520. const Colour Colours::paleturquoise (0xffafeeee);
  63521. const Colour Colours::palevioletred (0xffdb7093);
  63522. const Colour Colours::papayawhip (0xffffefd5);
  63523. const Colour Colours::peachpuff (0xffffdab9);
  63524. const Colour Colours::peru (0xffcd853f);
  63525. const Colour Colours::pink (0xffffc0cb);
  63526. const Colour Colours::plum (0xffdda0dd);
  63527. const Colour Colours::powderblue (0xffb0e0e6);
  63528. const Colour Colours::purple (0xff800080);
  63529. const Colour Colours::red (0xffff0000);
  63530. const Colour Colours::rosybrown (0xffbc8f8f);
  63531. const Colour Colours::royalblue (0xff4169e1);
  63532. const Colour Colours::saddlebrown (0xff8b4513);
  63533. const Colour Colours::salmon (0xfffa8072);
  63534. const Colour Colours::sandybrown (0xfff4a460);
  63535. const Colour Colours::seagreen (0xff2e8b57);
  63536. const Colour Colours::seashell (0xfffff5ee);
  63537. const Colour Colours::sienna (0xffa0522d);
  63538. const Colour Colours::silver (0xffc0c0c0);
  63539. const Colour Colours::skyblue (0xff87ceeb);
  63540. const Colour Colours::slateblue (0xff6a5acd);
  63541. const Colour Colours::slategrey (0xff708090);
  63542. const Colour Colours::snow (0xfffffafa);
  63543. const Colour Colours::springgreen (0xff00ff7f);
  63544. const Colour Colours::steelblue (0xff4682b4);
  63545. const Colour Colours::tan (0xffd2b48c);
  63546. const Colour Colours::teal (0xff008080);
  63547. const Colour Colours::thistle (0xffd8bfd8);
  63548. const Colour Colours::tomato (0xffff6347);
  63549. const Colour Colours::turquoise (0xff40e0d0);
  63550. const Colour Colours::violet (0xffee82ee);
  63551. const Colour Colours::wheat (0xfff5deb3);
  63552. const Colour Colours::white (0xffffffff);
  63553. const Colour Colours::whitesmoke (0xfff5f5f5);
  63554. const Colour Colours::yellow (0xffffff00);
  63555. const Colour Colours::yellowgreen (0xff9acd32);
  63556. const Colour Colours::findColourForName (const String& colourName,
  63557. const Colour& defaultColour)
  63558. {
  63559. static const int presets[] =
  63560. {
  63561. // (first value is the string's hashcode, second is ARGB)
  63562. 0x05978fff, 0xff000000, /* black */
  63563. 0x06bdcc29, 0xffffffff, /* white */
  63564. 0x002e305a, 0xff0000ff, /* blue */
  63565. 0x00308adf, 0xff808080, /* grey */
  63566. 0x05e0cf03, 0xff008000, /* green */
  63567. 0x0001b891, 0xffff0000, /* red */
  63568. 0xd43c6474, 0xffffff00, /* yellow */
  63569. 0x620886da, 0xfff0f8ff, /* aliceblue */
  63570. 0x20a2676a, 0xfffaebd7, /* antiquewhite */
  63571. 0x002dcebc, 0xff00ffff, /* aqua */
  63572. 0x46bb5f7e, 0xff7fffd4, /* aquamarine */
  63573. 0x0590228f, 0xfff0ffff, /* azure */
  63574. 0x05947fe4, 0xfff5f5dc, /* beige */
  63575. 0xad388e35, 0xffffe4c4, /* bisque */
  63576. 0x00674f7e, 0xffffebcd, /* blanchedalmond */
  63577. 0x39129959, 0xff8a2be2, /* blueviolet */
  63578. 0x059a8136, 0xffa52a2a, /* brown */
  63579. 0x89cea8f9, 0xffdeb887, /* burlywood */
  63580. 0x0fa260cf, 0xff5f9ea0, /* cadetblue */
  63581. 0x6b748956, 0xff7fff00, /* chartreuse */
  63582. 0x2903623c, 0xffd2691e, /* chocolate */
  63583. 0x05a74431, 0xffff7f50, /* coral */
  63584. 0x618d42dd, 0xff6495ed, /* cornflowerblue */
  63585. 0xe4b479fd, 0xfffff8dc, /* cornsilk */
  63586. 0x3d8c4edf, 0xffdc143c, /* crimson */
  63587. 0x002ed323, 0xff00ffff, /* cyan */
  63588. 0x67cc74d0, 0xff00008b, /* darkblue */
  63589. 0x67cd1799, 0xff008b8b, /* darkcyan */
  63590. 0x31bbd168, 0xffb8860b, /* darkgoldenrod */
  63591. 0x67cecf55, 0xff555555, /* darkgrey */
  63592. 0x920b194d, 0xff006400, /* darkgreen */
  63593. 0x923edd4c, 0xffbdb76b, /* darkkhaki */
  63594. 0x5c293873, 0xff8b008b, /* darkmagenta */
  63595. 0x6b6671fe, 0xff556b2f, /* darkolivegreen */
  63596. 0xbcfd2524, 0xffff8c00, /* darkorange */
  63597. 0xbcfdf799, 0xff9932cc, /* darkorchid */
  63598. 0x55ee0d5b, 0xff8b0000, /* darkred */
  63599. 0xc2e5f564, 0xffe9967a, /* darksalmon */
  63600. 0x61be858a, 0xff8fbc8f, /* darkseagreen */
  63601. 0xc2b0f2bd, 0xff483d8b, /* darkslateblue */
  63602. 0xc2b34d42, 0xff2f4f4f, /* darkslategrey */
  63603. 0x7cf2b06b, 0xff00ced1, /* darkturquoise */
  63604. 0xc8769375, 0xff9400d3, /* darkviolet */
  63605. 0x25832862, 0xffff1493, /* deeppink */
  63606. 0xfcad568f, 0xff00bfff, /* deepskyblue */
  63607. 0x634c8b67, 0xff696969, /* dimgrey */
  63608. 0x45c1ce55, 0xff1e90ff, /* dodgerblue */
  63609. 0xef19e3cb, 0xffb22222, /* firebrick */
  63610. 0xb852b195, 0xfffffaf0, /* floralwhite */
  63611. 0xd086fd06, 0xff228b22, /* forestgreen */
  63612. 0xe106b6d7, 0xffff00ff, /* fuchsia */
  63613. 0x7880d61e, 0xffdcdcdc, /* gainsboro */
  63614. 0x00308060, 0xffffd700, /* gold */
  63615. 0xb3b3bc1e, 0xffdaa520, /* goldenrod */
  63616. 0xbab8a537, 0xffadff2f, /* greenyellow */
  63617. 0xe4cacafb, 0xfff0fff0, /* honeydew */
  63618. 0x41892743, 0xffff69b4, /* hotpink */
  63619. 0xd5796f1a, 0xffcd5c5c, /* indianred */
  63620. 0xb969fed2, 0xff4b0082, /* indigo */
  63621. 0x05fef6a9, 0xfffffff0, /* ivory */
  63622. 0x06149302, 0xfff0e68c, /* khaki */
  63623. 0xad5a05c7, 0xffe6e6fa, /* lavender */
  63624. 0x7c4d5b99, 0xfffff0f5, /* lavenderblush */
  63625. 0x195756f0, 0xfffffacd, /* lemonchiffon */
  63626. 0x28e4ea70, 0xffadd8e6, /* lightblue */
  63627. 0xf3c7ccdb, 0xfff08080, /* lightcoral */
  63628. 0x28e58d39, 0xffe0ffff, /* lightcyan */
  63629. 0x21234e3c, 0xfffafad2, /* lightgoldenrodyellow */
  63630. 0xf40157ad, 0xff90ee90, /* lightgreen */
  63631. 0x28e744f5, 0xffd3d3d3, /* lightgrey */
  63632. 0x28eb3b8c, 0xffffb6c1, /* lightpink */
  63633. 0x9fb78304, 0xffffa07a, /* lightsalmon */
  63634. 0x50632b2a, 0xff20b2aa, /* lightseagreen */
  63635. 0x68fb7b25, 0xff87cefa, /* lightskyblue */
  63636. 0xa8a35ba2, 0xff778899, /* lightslategrey */
  63637. 0xa20d484f, 0xffb0c4de, /* lightsteelblue */
  63638. 0xaa2cf10a, 0xffffffe0, /* lightyellow */
  63639. 0x0032afd5, 0xff00ff00, /* lime */
  63640. 0x607bbc4e, 0xff32cd32, /* limegreen */
  63641. 0x06234efa, 0xfffaf0e6, /* linen */
  63642. 0x316858a9, 0xffff00ff, /* magenta */
  63643. 0xbf8ca470, 0xff800000, /* maroon */
  63644. 0xbd58e0b3, 0xff66cdaa, /* mediumaquamarine */
  63645. 0x967dfd4f, 0xff0000cd, /* mediumblue */
  63646. 0x056f5c58, 0xffba55d3, /* mediumorchid */
  63647. 0x07556b71, 0xff9370db, /* mediumpurple */
  63648. 0x5369b689, 0xff3cb371, /* mediumseagreen */
  63649. 0x066be19e, 0xff7b68ee, /* mediumslateblue */
  63650. 0x3256b281, 0xff00fa9a, /* mediumspringgreen */
  63651. 0xc0ad9f4c, 0xff48d1cc, /* mediumturquoise */
  63652. 0x628e63dd, 0xffc71585, /* mediumvioletred */
  63653. 0x168eb32a, 0xff191970, /* midnightblue */
  63654. 0x4306b960, 0xfff5fffa, /* mintcream */
  63655. 0x4cbc0e6b, 0xffffe4e1, /* mistyrose */
  63656. 0xe97218a6, 0xffffdead, /* navajowhite */
  63657. 0x00337bb6, 0xff000080, /* navy */
  63658. 0xadd2d33e, 0xfffdf5e6, /* oldlace */
  63659. 0x064ee1db, 0xff808000, /* olive */
  63660. 0x9e33a98a, 0xff6b8e23, /* olivedrab */
  63661. 0xc3de262e, 0xffffa500, /* orange */
  63662. 0x58bebba3, 0xffff4500, /* orangered */
  63663. 0xc3def8a3, 0xffda70d6, /* orchid */
  63664. 0x28cb4834, 0xffeee8aa, /* palegoldenrod */
  63665. 0x3d9dd619, 0xff98fb98, /* palegreen */
  63666. 0x74022737, 0xffafeeee, /* paleturquoise */
  63667. 0x15e2ebc8, 0xffdb7093, /* palevioletred */
  63668. 0x5fd898e2, 0xffffefd5, /* papayawhip */
  63669. 0x93e1b776, 0xffffdab9, /* peachpuff */
  63670. 0x003472f8, 0xffcd853f, /* peru */
  63671. 0x00348176, 0xffffc0cb, /* pink */
  63672. 0x00348d94, 0xffdda0dd, /* plum */
  63673. 0xd036be93, 0xffb0e0e6, /* powderblue */
  63674. 0xc5c507bc, 0xff800080, /* purple */
  63675. 0xa89d65b3, 0xffbc8f8f, /* rosybrown */
  63676. 0xbd9413e1, 0xff4169e1, /* royalblue */
  63677. 0xf456044f, 0xff8b4513, /* saddlebrown */
  63678. 0xc9c6f66e, 0xfffa8072, /* salmon */
  63679. 0x0bb131e1, 0xfff4a460, /* sandybrown */
  63680. 0x34636c14, 0xff2e8b57, /* seagreen */
  63681. 0x3507fb41, 0xfffff5ee, /* seashell */
  63682. 0xca348772, 0xffa0522d, /* sienna */
  63683. 0xca37d30d, 0xffc0c0c0, /* silver */
  63684. 0x80da74fb, 0xff87ceeb, /* skyblue */
  63685. 0x44a8dd73, 0xff6a5acd, /* slateblue */
  63686. 0x44ab37f8, 0xff708090, /* slategrey */
  63687. 0x0035f183, 0xfffffafa, /* snow */
  63688. 0xd5440d16, 0xff00ff7f, /* springgreen */
  63689. 0x3e1524a5, 0xff4682b4, /* steelblue */
  63690. 0x0001bfa1, 0xffd2b48c, /* tan */
  63691. 0x0036425c, 0xff008080, /* teal */
  63692. 0xafc8858f, 0xffd8bfd8, /* thistle */
  63693. 0xcc41600a, 0xffff6347, /* tomato */
  63694. 0xfeea9b21, 0xff40e0d0, /* turquoise */
  63695. 0xcf57947f, 0xffee82ee, /* violet */
  63696. 0x06bdbae7, 0xfff5deb3, /* wheat */
  63697. 0x10802ee6, 0xfff5f5f5, /* whitesmoke */
  63698. 0xe1b5130f, 0xff9acd32 /* yellowgreen */
  63699. };
  63700. const int hash = colourName.trim().toLowerCase().hashCode();
  63701. for (int i = 0; i < numElementsInArray (presets); i += 2)
  63702. if (presets [i] == hash)
  63703. return Colour (presets [i + 1]);
  63704. return defaultColour;
  63705. }
  63706. END_JUCE_NAMESPACE
  63707. /*** End of inlined file: juce_Colours.cpp ***/
  63708. /*** Start of inlined file: juce_EdgeTable.cpp ***/
  63709. BEGIN_JUCE_NAMESPACE
  63710. const int juce_edgeTableDefaultEdgesPerLine = 32;
  63711. EdgeTable::EdgeTable (const Rectangle<int>& bounds_,
  63712. const Path& path, const AffineTransform& transform)
  63713. : bounds (bounds_),
  63714. maxEdgesPerLine (juce_edgeTableDefaultEdgesPerLine),
  63715. lineStrideElements ((juce_edgeTableDefaultEdgesPerLine << 1) + 1),
  63716. needToCheckEmptinesss (true)
  63717. {
  63718. table.malloc ((bounds.getHeight() + 1) * lineStrideElements);
  63719. int* t = table;
  63720. for (int i = bounds.getHeight(); --i >= 0;)
  63721. {
  63722. *t = 0;
  63723. t += lineStrideElements;
  63724. }
  63725. const int topLimit = bounds.getY() << 8;
  63726. const int heightLimit = bounds.getHeight() << 8;
  63727. const int leftLimit = bounds.getX() << 8;
  63728. const int rightLimit = bounds.getRight() << 8;
  63729. PathFlatteningIterator iter (path, transform);
  63730. while (iter.next())
  63731. {
  63732. int y1 = roundToInt (iter.y1 * 256.0f);
  63733. int y2 = roundToInt (iter.y2 * 256.0f);
  63734. if (y1 != y2)
  63735. {
  63736. y1 -= topLimit;
  63737. y2 -= topLimit;
  63738. const int startY = y1;
  63739. int direction = -1;
  63740. if (y1 > y2)
  63741. {
  63742. swapVariables (y1, y2);
  63743. direction = 1;
  63744. }
  63745. if (y1 < 0)
  63746. y1 = 0;
  63747. if (y2 > heightLimit)
  63748. y2 = heightLimit;
  63749. if (y1 < y2)
  63750. {
  63751. const double startX = 256.0f * iter.x1;
  63752. const double multiplier = (iter.x2 - iter.x1) / (iter.y2 - iter.y1);
  63753. const int stepSize = jlimit (1, 256, 256 / (1 + (int) fabs (multiplier)));
  63754. do
  63755. {
  63756. const int step = jmin (stepSize, y2 - y1, 256 - (y1 & 255));
  63757. int x = roundToInt (startX + multiplier * ((y1 + (step >> 1)) - startY));
  63758. if (x < leftLimit)
  63759. x = leftLimit;
  63760. else if (x >= rightLimit)
  63761. x = rightLimit - 1;
  63762. addEdgePoint (x, y1 >> 8, direction * step);
  63763. y1 += step;
  63764. }
  63765. while (y1 < y2);
  63766. }
  63767. }
  63768. }
  63769. sanitiseLevels (path.isUsingNonZeroWinding());
  63770. }
  63771. EdgeTable::EdgeTable (const Rectangle<int>& rectangleToAdd)
  63772. : bounds (rectangleToAdd),
  63773. maxEdgesPerLine (juce_edgeTableDefaultEdgesPerLine),
  63774. lineStrideElements ((juce_edgeTableDefaultEdgesPerLine << 1) + 1),
  63775. needToCheckEmptinesss (true)
  63776. {
  63777. table.malloc (jmax (1, bounds.getHeight()) * lineStrideElements);
  63778. table[0] = 0;
  63779. const int x1 = rectangleToAdd.getX() << 8;
  63780. const int x2 = rectangleToAdd.getRight() << 8;
  63781. int* t = table;
  63782. for (int i = rectangleToAdd.getHeight(); --i >= 0;)
  63783. {
  63784. t[0] = 2;
  63785. t[1] = x1;
  63786. t[2] = 255;
  63787. t[3] = x2;
  63788. t[4] = 0;
  63789. t += lineStrideElements;
  63790. }
  63791. }
  63792. EdgeTable::EdgeTable (const RectangleList& rectanglesToAdd)
  63793. : bounds (rectanglesToAdd.getBounds()),
  63794. maxEdgesPerLine (juce_edgeTableDefaultEdgesPerLine),
  63795. lineStrideElements ((juce_edgeTableDefaultEdgesPerLine << 1) + 1),
  63796. needToCheckEmptinesss (true)
  63797. {
  63798. table.malloc (jmax (1, bounds.getHeight()) * lineStrideElements);
  63799. int* t = table;
  63800. for (int i = bounds.getHeight(); --i >= 0;)
  63801. {
  63802. *t = 0;
  63803. t += lineStrideElements;
  63804. }
  63805. for (RectangleList::Iterator iter (rectanglesToAdd); iter.next();)
  63806. {
  63807. const Rectangle<int>* const r = iter.getRectangle();
  63808. const int x1 = r->getX() << 8;
  63809. const int x2 = r->getRight() << 8;
  63810. int y = r->getY() - bounds.getY();
  63811. for (int j = r->getHeight(); --j >= 0;)
  63812. {
  63813. addEdgePoint (x1, y, 255);
  63814. addEdgePoint (x2, y, -255);
  63815. ++y;
  63816. }
  63817. }
  63818. sanitiseLevels (true);
  63819. }
  63820. EdgeTable::EdgeTable (const float x, const float y, const float w, const float h)
  63821. : bounds (Rectangle<int> ((int) floorf (x), roundToInt (y * 256.0f) >> 8, 2 + (int) w, 2 + (int) h)),
  63822. maxEdgesPerLine (juce_edgeTableDefaultEdgesPerLine),
  63823. lineStrideElements ((juce_edgeTableDefaultEdgesPerLine << 1) + 1),
  63824. needToCheckEmptinesss (true)
  63825. {
  63826. jassert (w > 0 && h > 0);
  63827. table.malloc (jmax (1, bounds.getHeight()) * lineStrideElements);
  63828. table[0] = 0;
  63829. const int x1 = roundToInt (x * 256.0f);
  63830. const int x2 = roundToInt ((x + w) * 256.0f);
  63831. int y1 = roundToInt (y * 256.0f) - (bounds.getY() << 8);
  63832. jassert (y1 < 256);
  63833. int y2 = roundToInt ((y + h) * 256.0f) - (bounds.getY() << 8);
  63834. if (x2 <= x1 || y2 <= y1)
  63835. {
  63836. bounds.setHeight (0);
  63837. return;
  63838. }
  63839. int lineY = 0;
  63840. int* t = table;
  63841. if ((y1 >> 8) == (y2 >> 8))
  63842. {
  63843. t[0] = 2;
  63844. t[1] = x1;
  63845. t[2] = y2 - y1;
  63846. t[3] = x2;
  63847. t[4] = 0;
  63848. ++lineY;
  63849. t += lineStrideElements;
  63850. }
  63851. else
  63852. {
  63853. t[0] = 2;
  63854. t[1] = x1;
  63855. t[2] = 255 - (y1 & 255);
  63856. t[3] = x2;
  63857. t[4] = 0;
  63858. ++lineY;
  63859. t += lineStrideElements;
  63860. while (lineY < (y2 >> 8))
  63861. {
  63862. t[0] = 2;
  63863. t[1] = x1;
  63864. t[2] = 255;
  63865. t[3] = x2;
  63866. t[4] = 0;
  63867. ++lineY;
  63868. t += lineStrideElements;
  63869. }
  63870. jassert (lineY < bounds.getHeight());
  63871. t[0] = 2;
  63872. t[1] = x1;
  63873. t[2] = y2 & 255;
  63874. t[3] = x2;
  63875. t[4] = 0;
  63876. ++lineY;
  63877. t += lineStrideElements;
  63878. }
  63879. while (lineY < bounds.getHeight())
  63880. {
  63881. t[0] = 0;
  63882. t += lineStrideElements;
  63883. ++lineY;
  63884. }
  63885. }
  63886. EdgeTable::EdgeTable (const EdgeTable& other)
  63887. : table (0)
  63888. {
  63889. operator= (other);
  63890. }
  63891. EdgeTable& EdgeTable::operator= (const EdgeTable& other)
  63892. {
  63893. bounds = other.bounds;
  63894. maxEdgesPerLine = other.maxEdgesPerLine;
  63895. lineStrideElements = other.lineStrideElements;
  63896. needToCheckEmptinesss = other.needToCheckEmptinesss;
  63897. table.malloc (jmax (1, bounds.getHeight()) * lineStrideElements);
  63898. copyEdgeTableData (table, lineStrideElements, other.table, lineStrideElements, bounds.getHeight());
  63899. return *this;
  63900. }
  63901. EdgeTable::~EdgeTable()
  63902. {
  63903. }
  63904. void EdgeTable::copyEdgeTableData (int* dest, const int destLineStride, const int* src, const int srcLineStride, int numLines) throw()
  63905. {
  63906. while (--numLines >= 0)
  63907. {
  63908. memcpy (dest, src, (src[0] * 2 + 1) * sizeof (int));
  63909. src += srcLineStride;
  63910. dest += destLineStride;
  63911. }
  63912. }
  63913. void EdgeTable::sanitiseLevels (const bool useNonZeroWinding) throw()
  63914. {
  63915. // Convert the table from relative windings to absolute levels..
  63916. int* lineStart = table;
  63917. for (int i = bounds.getHeight(); --i >= 0;)
  63918. {
  63919. int* line = lineStart;
  63920. lineStart += lineStrideElements;
  63921. int num = *line;
  63922. if (num == 0)
  63923. continue;
  63924. int level = 0;
  63925. if (useNonZeroWinding)
  63926. {
  63927. while (--num > 0)
  63928. {
  63929. line += 2;
  63930. level += *line;
  63931. int corrected = abs (level);
  63932. if (corrected >> 8)
  63933. corrected = 255;
  63934. *line = corrected;
  63935. }
  63936. }
  63937. else
  63938. {
  63939. while (--num > 0)
  63940. {
  63941. line += 2;
  63942. level += *line;
  63943. int corrected = abs (level);
  63944. if (corrected >> 8)
  63945. {
  63946. corrected &= 511;
  63947. if (corrected >> 8)
  63948. corrected = 511 - corrected;
  63949. }
  63950. *line = corrected;
  63951. }
  63952. }
  63953. line[2] = 0; // force the last level to 0, just in case something went wrong in creating the table
  63954. }
  63955. }
  63956. void EdgeTable::remapTableForNumEdges (const int newNumEdgesPerLine) throw()
  63957. {
  63958. if (newNumEdgesPerLine != maxEdgesPerLine)
  63959. {
  63960. maxEdgesPerLine = newNumEdgesPerLine;
  63961. jassert (bounds.getHeight() > 0);
  63962. const int newLineStrideElements = maxEdgesPerLine * 2 + 1;
  63963. HeapBlock <int> newTable (bounds.getHeight() * newLineStrideElements);
  63964. copyEdgeTableData (newTable, newLineStrideElements, table, lineStrideElements, bounds.getHeight());
  63965. table.swapWith (newTable);
  63966. lineStrideElements = newLineStrideElements;
  63967. }
  63968. }
  63969. void EdgeTable::optimiseTable() throw()
  63970. {
  63971. int maxLineElements = 0;
  63972. for (int i = bounds.getHeight(); --i >= 0;)
  63973. maxLineElements = jmax (maxLineElements, table [i * lineStrideElements]);
  63974. remapTableForNumEdges (maxLineElements);
  63975. }
  63976. void EdgeTable::addEdgePoint (const int x, const int y, const int winding) throw()
  63977. {
  63978. jassert (y >= 0 && y < bounds.getHeight());
  63979. int* line = table + lineStrideElements * y;
  63980. const int numPoints = line[0];
  63981. int n = numPoints << 1;
  63982. if (n > 0)
  63983. {
  63984. while (n > 0)
  63985. {
  63986. const int cx = line [n - 1];
  63987. if (cx <= x)
  63988. {
  63989. if (cx == x)
  63990. {
  63991. line [n] += winding;
  63992. return;
  63993. }
  63994. break;
  63995. }
  63996. n -= 2;
  63997. }
  63998. if (numPoints >= maxEdgesPerLine)
  63999. {
  64000. remapTableForNumEdges (maxEdgesPerLine + juce_edgeTableDefaultEdgesPerLine);
  64001. jassert (numPoints < maxEdgesPerLine);
  64002. line = table + lineStrideElements * y;
  64003. }
  64004. memmove (line + (n + 3), line + (n + 1), sizeof (int) * ((numPoints << 1) - n));
  64005. }
  64006. line [n + 1] = x;
  64007. line [n + 2] = winding;
  64008. line[0]++;
  64009. }
  64010. void EdgeTable::translate (float dx, int dy) throw()
  64011. {
  64012. bounds.setPosition (bounds.getX() + (int) floorf (dx), bounds.getY() + dy);
  64013. int* lineStart = table;
  64014. const int intDx = (int) (dx * 256.0f);
  64015. for (int i = bounds.getHeight(); --i >= 0;)
  64016. {
  64017. int* line = lineStart;
  64018. lineStart += lineStrideElements;
  64019. int num = *line++;
  64020. while (--num >= 0)
  64021. {
  64022. *line += intDx;
  64023. line += 2;
  64024. }
  64025. }
  64026. }
  64027. void EdgeTable::intersectWithEdgeTableLine (const int y, const int* otherLine) throw()
  64028. {
  64029. jassert (y >= 0 && y < bounds.getHeight());
  64030. int* dest = table + lineStrideElements * y;
  64031. if (dest[0] == 0)
  64032. return;
  64033. int otherNumPoints = *otherLine;
  64034. if (otherNumPoints == 0)
  64035. {
  64036. *dest = 0;
  64037. return;
  64038. }
  64039. const int right = bounds.getRight() << 8;
  64040. // optimise for the common case where our line lies entirely within a
  64041. // single pair of points, as happens when clipping to a simple rect.
  64042. if (otherNumPoints == 2 && otherLine[2] >= 255)
  64043. {
  64044. clipEdgeTableLineToRange (dest, otherLine[1], jmin (right, otherLine[3]));
  64045. return;
  64046. }
  64047. ++otherLine;
  64048. const size_t lineSizeBytes = (dest[0] * 2 + 1) * sizeof (int);
  64049. int* temp = (int*) alloca (lineSizeBytes);
  64050. memcpy (temp, dest, lineSizeBytes);
  64051. const int* src1 = temp;
  64052. int srcNum1 = *src1++;
  64053. int x1 = *src1++;
  64054. const int* src2 = otherLine;
  64055. int srcNum2 = otherNumPoints;
  64056. int x2 = *src2++;
  64057. int destIndex = 0, destTotal = 0;
  64058. int level1 = 0, level2 = 0;
  64059. int lastX = std::numeric_limits<int>::min(), lastLevel = 0;
  64060. while (srcNum1 > 0 && srcNum2 > 0)
  64061. {
  64062. int nextX;
  64063. if (x1 < x2)
  64064. {
  64065. nextX = x1;
  64066. level1 = *src1++;
  64067. x1 = *src1++;
  64068. --srcNum1;
  64069. }
  64070. else if (x1 == x2)
  64071. {
  64072. nextX = x1;
  64073. level1 = *src1++;
  64074. level2 = *src2++;
  64075. x1 = *src1++;
  64076. x2 = *src2++;
  64077. --srcNum1;
  64078. --srcNum2;
  64079. }
  64080. else
  64081. {
  64082. nextX = x2;
  64083. level2 = *src2++;
  64084. x2 = *src2++;
  64085. --srcNum2;
  64086. }
  64087. if (nextX > lastX)
  64088. {
  64089. if (nextX >= right)
  64090. break;
  64091. lastX = nextX;
  64092. const int nextLevel = (level1 * (level2 + 1)) >> 8;
  64093. jassert (((unsigned int) nextLevel) < (unsigned int) 256);
  64094. if (nextLevel != lastLevel)
  64095. {
  64096. if (destTotal >= maxEdgesPerLine)
  64097. {
  64098. dest[0] = destTotal;
  64099. remapTableForNumEdges (maxEdgesPerLine + juce_edgeTableDefaultEdgesPerLine);
  64100. dest = table + lineStrideElements * y;
  64101. }
  64102. ++destTotal;
  64103. lastLevel = nextLevel;
  64104. dest[++destIndex] = nextX;
  64105. dest[++destIndex] = nextLevel;
  64106. }
  64107. }
  64108. }
  64109. if (lastLevel > 0)
  64110. {
  64111. if (destTotal >= maxEdgesPerLine)
  64112. {
  64113. dest[0] = destTotal;
  64114. remapTableForNumEdges (maxEdgesPerLine + juce_edgeTableDefaultEdgesPerLine);
  64115. dest = table + lineStrideElements * y;
  64116. }
  64117. ++destTotal;
  64118. dest[++destIndex] = right;
  64119. dest[++destIndex] = 0;
  64120. }
  64121. dest[0] = destTotal;
  64122. #if JUCE_DEBUG
  64123. int last = std::numeric_limits<int>::min();
  64124. for (int i = 0; i < dest[0]; ++i)
  64125. {
  64126. jassert (dest[i * 2 + 1] > last);
  64127. last = dest[i * 2 + 1];
  64128. }
  64129. jassert (dest [dest[0] * 2] == 0);
  64130. #endif
  64131. }
  64132. void EdgeTable::clipEdgeTableLineToRange (int* dest, const int x1, const int x2) throw()
  64133. {
  64134. int* lastItem = dest + (dest[0] * 2 - 1);
  64135. if (x2 < lastItem[0])
  64136. {
  64137. if (x2 <= dest[1])
  64138. {
  64139. dest[0] = 0;
  64140. return;
  64141. }
  64142. while (x2 < lastItem[-2])
  64143. {
  64144. --(dest[0]);
  64145. lastItem -= 2;
  64146. }
  64147. lastItem[0] = x2;
  64148. lastItem[1] = 0;
  64149. }
  64150. if (x1 > dest[1])
  64151. {
  64152. while (lastItem[0] > x1)
  64153. lastItem -= 2;
  64154. const int itemsRemoved = (int) (lastItem - (dest + 1)) / 2;
  64155. if (itemsRemoved > 0)
  64156. {
  64157. dest[0] -= itemsRemoved;
  64158. memmove (dest + 1, lastItem, dest[0] * (sizeof (int) * 2));
  64159. }
  64160. dest[1] = x1;
  64161. }
  64162. }
  64163. void EdgeTable::clipToRectangle (const Rectangle<int>& r) throw()
  64164. {
  64165. const Rectangle<int> clipped (r.getIntersection (bounds));
  64166. if (clipped.isEmpty())
  64167. {
  64168. needToCheckEmptinesss = false;
  64169. bounds.setHeight (0);
  64170. }
  64171. else
  64172. {
  64173. const int top = clipped.getY() - bounds.getY();
  64174. const int bottom = clipped.getBottom() - bounds.getY();
  64175. if (bottom < bounds.getHeight())
  64176. bounds.setHeight (bottom);
  64177. if (clipped.getRight() < bounds.getRight())
  64178. bounds.setRight (clipped.getRight());
  64179. for (int i = top; --i >= 0;)
  64180. table [lineStrideElements * i] = 0;
  64181. if (clipped.getX() > bounds.getX())
  64182. {
  64183. const int x1 = clipped.getX() << 8;
  64184. const int x2 = jmin (bounds.getRight(), clipped.getRight()) << 8;
  64185. int* line = table + lineStrideElements * top;
  64186. for (int i = bottom - top; --i >= 0;)
  64187. {
  64188. if (line[0] != 0)
  64189. clipEdgeTableLineToRange (line, x1, x2);
  64190. line += lineStrideElements;
  64191. }
  64192. }
  64193. needToCheckEmptinesss = true;
  64194. }
  64195. }
  64196. void EdgeTable::excludeRectangle (const Rectangle<int>& r) throw()
  64197. {
  64198. const Rectangle<int> clipped (r.getIntersection (bounds));
  64199. if (! clipped.isEmpty())
  64200. {
  64201. const int top = clipped.getY() - bounds.getY();
  64202. const int bottom = clipped.getBottom() - bounds.getY();
  64203. //XXX optimise here by shortening the table if it fills top or bottom
  64204. const int rectLine[] = { 4, std::numeric_limits<int>::min(), 255,
  64205. clipped.getX() << 8, 0,
  64206. clipped.getRight() << 8, 255,
  64207. std::numeric_limits<int>::max(), 0 };
  64208. for (int i = top; i < bottom; ++i)
  64209. intersectWithEdgeTableLine (i, rectLine);
  64210. needToCheckEmptinesss = true;
  64211. }
  64212. }
  64213. void EdgeTable::clipToEdgeTable (const EdgeTable& other)
  64214. {
  64215. const Rectangle<int> clipped (other.bounds.getIntersection (bounds));
  64216. if (clipped.isEmpty())
  64217. {
  64218. needToCheckEmptinesss = false;
  64219. bounds.setHeight (0);
  64220. }
  64221. else
  64222. {
  64223. const int top = clipped.getY() - bounds.getY();
  64224. const int bottom = clipped.getBottom() - bounds.getY();
  64225. if (bottom < bounds.getHeight())
  64226. bounds.setHeight (bottom);
  64227. if (clipped.getRight() < bounds.getRight())
  64228. bounds.setRight (clipped.getRight());
  64229. int i = 0;
  64230. for (i = top; --i >= 0;)
  64231. table [lineStrideElements * i] = 0;
  64232. const int* otherLine = other.table + other.lineStrideElements * (clipped.getY() - other.bounds.getY());
  64233. for (i = top; i < bottom; ++i)
  64234. {
  64235. intersectWithEdgeTableLine (i, otherLine);
  64236. otherLine += other.lineStrideElements;
  64237. }
  64238. needToCheckEmptinesss = true;
  64239. }
  64240. }
  64241. void EdgeTable::clipLineToMask (int x, int y, const uint8* mask, int maskStride, int numPixels) throw()
  64242. {
  64243. y -= bounds.getY();
  64244. if (y < 0 || y >= bounds.getHeight())
  64245. return;
  64246. needToCheckEmptinesss = true;
  64247. if (numPixels <= 0)
  64248. {
  64249. table [lineStrideElements * y] = 0;
  64250. return;
  64251. }
  64252. int* tempLine = (int*) alloca ((numPixels * 2 + 4) * sizeof (int));
  64253. int destIndex = 0, lastLevel = 0;
  64254. while (--numPixels >= 0)
  64255. {
  64256. const int alpha = *mask;
  64257. mask += maskStride;
  64258. if (alpha != lastLevel)
  64259. {
  64260. tempLine[++destIndex] = (x << 8);
  64261. tempLine[++destIndex] = alpha;
  64262. lastLevel = alpha;
  64263. }
  64264. ++x;
  64265. }
  64266. if (lastLevel > 0)
  64267. {
  64268. tempLine[++destIndex] = (x << 8);
  64269. tempLine[++destIndex] = 0;
  64270. }
  64271. tempLine[0] = destIndex >> 1;
  64272. intersectWithEdgeTableLine (y, tempLine);
  64273. }
  64274. bool EdgeTable::isEmpty() throw()
  64275. {
  64276. if (needToCheckEmptinesss)
  64277. {
  64278. needToCheckEmptinesss = false;
  64279. int* t = table;
  64280. for (int i = bounds.getHeight(); --i >= 0;)
  64281. {
  64282. if (t[0] > 1)
  64283. return false;
  64284. t += lineStrideElements;
  64285. }
  64286. bounds.setHeight (0);
  64287. }
  64288. return bounds.getHeight() == 0;
  64289. }
  64290. END_JUCE_NAMESPACE
  64291. /*** End of inlined file: juce_EdgeTable.cpp ***/
  64292. /*** Start of inlined file: juce_FillType.cpp ***/
  64293. BEGIN_JUCE_NAMESPACE
  64294. FillType::FillType() throw()
  64295. : colour (0xff000000), image (0)
  64296. {
  64297. }
  64298. FillType::FillType (const Colour& colour_) throw()
  64299. : colour (colour_), image (0)
  64300. {
  64301. }
  64302. FillType::FillType (const ColourGradient& gradient_) throw()
  64303. : colour (0xff000000), gradient (new ColourGradient (gradient_)), image (0)
  64304. {
  64305. }
  64306. FillType::FillType (const Image& image_, const AffineTransform& transform_) throw()
  64307. : colour (0xff000000), image (&image_), transform (transform_)
  64308. {
  64309. }
  64310. FillType::FillType (const FillType& other) throw()
  64311. : colour (other.colour),
  64312. gradient (other.gradient != 0 ? new ColourGradient (*other.gradient) : 0),
  64313. image (other.image), transform (other.transform)
  64314. {
  64315. }
  64316. FillType& FillType::operator= (const FillType& other) throw()
  64317. {
  64318. if (this != &other)
  64319. {
  64320. colour = other.colour;
  64321. gradient = (other.gradient != 0 ? new ColourGradient (*other.gradient) : 0);
  64322. image = other.image;
  64323. transform = other.transform;
  64324. }
  64325. return *this;
  64326. }
  64327. FillType::~FillType() throw()
  64328. {
  64329. }
  64330. void FillType::setColour (const Colour& newColour) throw()
  64331. {
  64332. gradient = 0;
  64333. image = 0;
  64334. colour = newColour;
  64335. }
  64336. void FillType::setGradient (const ColourGradient& newGradient) throw()
  64337. {
  64338. if (gradient != 0)
  64339. {
  64340. *gradient = newGradient;
  64341. }
  64342. else
  64343. {
  64344. image = 0;
  64345. gradient = new ColourGradient (newGradient);
  64346. colour = Colours::black;
  64347. }
  64348. }
  64349. void FillType::setTiledImage (const Image& image_, const AffineTransform& transform_) throw()
  64350. {
  64351. gradient = 0;
  64352. image = &image_;
  64353. transform = transform_;
  64354. colour = Colours::black;
  64355. }
  64356. void FillType::setOpacity (const float newOpacity) throw()
  64357. {
  64358. colour = colour.withAlpha (newOpacity);
  64359. }
  64360. END_JUCE_NAMESPACE
  64361. /*** End of inlined file: juce_FillType.cpp ***/
  64362. /*** Start of inlined file: juce_Graphics.cpp ***/
  64363. BEGIN_JUCE_NAMESPACE
  64364. static const Graphics::ResamplingQuality defaultQuality = Graphics::mediumResamplingQuality;
  64365. template <typename Type>
  64366. static bool areCoordsSensibleNumbers (Type x, Type y, Type w, Type h)
  64367. {
  64368. const int maxVal = 0x3fffffff;
  64369. return (int) x >= -maxVal && (int) x <= maxVal
  64370. && (int) y >= -maxVal && (int) y <= maxVal
  64371. && (int) w >= -maxVal && (int) w <= maxVal
  64372. && (int) h >= -maxVal && (int) h <= maxVal;
  64373. }
  64374. LowLevelGraphicsContext::LowLevelGraphicsContext()
  64375. {
  64376. }
  64377. LowLevelGraphicsContext::~LowLevelGraphicsContext()
  64378. {
  64379. }
  64380. Graphics::Graphics (Image& imageToDrawOnto) throw()
  64381. : context (imageToDrawOnto.createLowLevelContext()),
  64382. contextToDelete (context),
  64383. saveStatePending (false)
  64384. {
  64385. }
  64386. Graphics::Graphics (LowLevelGraphicsContext* const internalContext) throw()
  64387. : context (internalContext),
  64388. saveStatePending (false)
  64389. {
  64390. }
  64391. Graphics::~Graphics() throw()
  64392. {
  64393. }
  64394. void Graphics::resetToDefaultState() throw()
  64395. {
  64396. saveStateIfPending();
  64397. context->setFill (FillType());
  64398. context->setFont (Font());
  64399. context->setInterpolationQuality (defaultQuality);
  64400. }
  64401. bool Graphics::isVectorDevice() const throw()
  64402. {
  64403. return context->isVectorDevice();
  64404. }
  64405. bool Graphics::reduceClipRegion (const int x, const int y,
  64406. const int w, const int h) throw()
  64407. {
  64408. saveStateIfPending();
  64409. return context->clipToRectangle (Rectangle<int> (x, y, w, h));
  64410. }
  64411. bool Graphics::reduceClipRegion (const RectangleList& clipRegion) throw()
  64412. {
  64413. saveStateIfPending();
  64414. return context->clipToRectangleList (clipRegion);
  64415. }
  64416. bool Graphics::reduceClipRegion (const Path& path, const AffineTransform& transform) throw()
  64417. {
  64418. saveStateIfPending();
  64419. context->clipToPath (path, transform);
  64420. return ! context->isClipEmpty();
  64421. }
  64422. bool Graphics::reduceClipRegion (const Image& image, const Rectangle<int>& sourceClipRegion, const AffineTransform& transform) throw()
  64423. {
  64424. saveStateIfPending();
  64425. context->clipToImageAlpha (image, sourceClipRegion, transform);
  64426. return ! context->isClipEmpty();
  64427. }
  64428. void Graphics::excludeClipRegion (const Rectangle<int>& rectangleToExclude) throw()
  64429. {
  64430. saveStateIfPending();
  64431. context->excludeClipRectangle (rectangleToExclude);
  64432. }
  64433. bool Graphics::isClipEmpty() const throw()
  64434. {
  64435. return context->isClipEmpty();
  64436. }
  64437. const Rectangle<int> Graphics::getClipBounds() const throw()
  64438. {
  64439. return context->getClipBounds();
  64440. }
  64441. void Graphics::saveState() throw()
  64442. {
  64443. saveStateIfPending();
  64444. saveStatePending = true;
  64445. }
  64446. void Graphics::restoreState() throw()
  64447. {
  64448. if (saveStatePending)
  64449. saveStatePending = false;
  64450. else
  64451. context->restoreState();
  64452. }
  64453. void Graphics::saveStateIfPending() throw()
  64454. {
  64455. if (saveStatePending)
  64456. {
  64457. saveStatePending = false;
  64458. context->saveState();
  64459. }
  64460. }
  64461. void Graphics::setOrigin (const int newOriginX,
  64462. const int newOriginY) throw()
  64463. {
  64464. saveStateIfPending();
  64465. context->setOrigin (newOriginX, newOriginY);
  64466. }
  64467. bool Graphics::clipRegionIntersects (const int x, const int y,
  64468. const int w, const int h) const throw()
  64469. {
  64470. return context->clipRegionIntersects (Rectangle<int> (x, y, w, h));
  64471. }
  64472. void Graphics::setColour (const Colour& newColour) throw()
  64473. {
  64474. saveStateIfPending();
  64475. context->setFill (FillType (newColour));
  64476. }
  64477. void Graphics::setOpacity (const float newOpacity) throw()
  64478. {
  64479. saveStateIfPending();
  64480. context->setOpacity (newOpacity);
  64481. }
  64482. void Graphics::setGradientFill (const ColourGradient& gradient) throw()
  64483. {
  64484. saveStateIfPending();
  64485. context->setFill (FillType (gradient));
  64486. }
  64487. void Graphics::setTiledImageFill (const Image& imageToUse,
  64488. const int anchorX,
  64489. const int anchorY,
  64490. const float opacity) throw()
  64491. {
  64492. saveStateIfPending();
  64493. context->setFill (FillType (imageToUse, AffineTransform::translation ((float) anchorX, (float) anchorY)));
  64494. context->setOpacity (opacity);
  64495. }
  64496. void Graphics::setFillType (const FillType& newFill) throw()
  64497. {
  64498. saveStateIfPending();
  64499. context->setFill (newFill);
  64500. }
  64501. void Graphics::setFont (const Font& newFont) throw()
  64502. {
  64503. saveStateIfPending();
  64504. context->setFont (newFont);
  64505. }
  64506. void Graphics::setFont (const float newFontHeight,
  64507. const int newFontStyleFlags) throw()
  64508. {
  64509. saveStateIfPending();
  64510. Font f (context->getFont());
  64511. f.setSizeAndStyle (newFontHeight, newFontStyleFlags, 1.0f, 0);
  64512. context->setFont (f);
  64513. }
  64514. void Graphics::drawSingleLineText (const String& text,
  64515. const int startX,
  64516. const int baselineY) const throw()
  64517. {
  64518. if (text.isNotEmpty()
  64519. && startX < context->getClipBounds().getRight())
  64520. {
  64521. GlyphArrangement arr;
  64522. arr.addLineOfText (context->getFont(), text, (float) startX, (float) baselineY);
  64523. arr.draw (*this);
  64524. }
  64525. }
  64526. void Graphics::drawTextAsPath (const String& text,
  64527. const AffineTransform& transform) const throw()
  64528. {
  64529. if (text.isNotEmpty())
  64530. {
  64531. GlyphArrangement arr;
  64532. arr.addLineOfText (context->getFont(), text, 0.0f, 0.0f);
  64533. arr.draw (*this, transform);
  64534. }
  64535. }
  64536. void Graphics::drawMultiLineText (const String& text,
  64537. const int startX,
  64538. const int baselineY,
  64539. const int maximumLineWidth) const throw()
  64540. {
  64541. if (text.isNotEmpty()
  64542. && startX < context->getClipBounds().getRight())
  64543. {
  64544. GlyphArrangement arr;
  64545. arr.addJustifiedText (context->getFont(), text,
  64546. (float) startX, (float) baselineY, (float) maximumLineWidth,
  64547. Justification::left);
  64548. arr.draw (*this);
  64549. }
  64550. }
  64551. void Graphics::drawText (const String& text,
  64552. const int x,
  64553. const int y,
  64554. const int width,
  64555. const int height,
  64556. const Justification& justificationType,
  64557. const bool useEllipsesIfTooBig) const throw()
  64558. {
  64559. if (text.isNotEmpty() && context->clipRegionIntersects (Rectangle<int> (x, y, width, height)))
  64560. {
  64561. GlyphArrangement arr;
  64562. arr.addCurtailedLineOfText (context->getFont(), text,
  64563. 0.0f, 0.0f, (float)width,
  64564. useEllipsesIfTooBig);
  64565. arr.justifyGlyphs (0, arr.getNumGlyphs(),
  64566. (float) x, (float) y,
  64567. (float) width, (float) height,
  64568. justificationType);
  64569. arr.draw (*this);
  64570. }
  64571. }
  64572. void Graphics::drawFittedText (const String& text,
  64573. const int x,
  64574. const int y,
  64575. const int width,
  64576. const int height,
  64577. const Justification& justification,
  64578. const int maximumNumberOfLines,
  64579. const float minimumHorizontalScale) const throw()
  64580. {
  64581. if (text.isNotEmpty()
  64582. && width > 0 && height > 0
  64583. && context->clipRegionIntersects (Rectangle<int> (x, y, width, height)))
  64584. {
  64585. GlyphArrangement arr;
  64586. arr.addFittedText (context->getFont(), text,
  64587. (float) x, (float) y,
  64588. (float) width, (float) height,
  64589. justification,
  64590. maximumNumberOfLines,
  64591. minimumHorizontalScale);
  64592. arr.draw (*this);
  64593. }
  64594. }
  64595. void Graphics::fillRect (int x,
  64596. int y,
  64597. int width,
  64598. int height) const throw()
  64599. {
  64600. // passing in a silly number can cause maths problems in rendering!
  64601. jassert (areCoordsSensibleNumbers (x, y, width, height));
  64602. context->fillRect (Rectangle<int> (x, y, width, height), false);
  64603. }
  64604. void Graphics::fillRect (const Rectangle<int>& r) const throw()
  64605. {
  64606. context->fillRect (r, false);
  64607. }
  64608. void Graphics::fillRect (const float x,
  64609. const float y,
  64610. const float width,
  64611. const float height) const throw()
  64612. {
  64613. // passing in a silly number can cause maths problems in rendering!
  64614. jassert (areCoordsSensibleNumbers (x, y, width, height));
  64615. Path p;
  64616. p.addRectangle (x, y, width, height);
  64617. fillPath (p);
  64618. }
  64619. void Graphics::setPixel (int x, int y) const throw()
  64620. {
  64621. context->fillRect (Rectangle<int> (x, y, 1, 1), false);
  64622. }
  64623. void Graphics::fillAll() const throw()
  64624. {
  64625. fillRect (context->getClipBounds());
  64626. }
  64627. void Graphics::fillAll (const Colour& colourToUse) const throw()
  64628. {
  64629. if (! colourToUse.isTransparent())
  64630. {
  64631. const Rectangle<int> clip (context->getClipBounds());
  64632. context->saveState();
  64633. context->setFill (FillType (colourToUse));
  64634. context->fillRect (clip, false);
  64635. context->restoreState();
  64636. }
  64637. }
  64638. void Graphics::fillPath (const Path& path,
  64639. const AffineTransform& transform) const throw()
  64640. {
  64641. if ((! context->isClipEmpty()) && ! path.isEmpty())
  64642. context->fillPath (path, transform);
  64643. }
  64644. void Graphics::strokePath (const Path& path,
  64645. const PathStrokeType& strokeType,
  64646. const AffineTransform& transform) const throw()
  64647. {
  64648. Path stroke;
  64649. strokeType.createStrokedPath (stroke, path, transform);
  64650. fillPath (stroke);
  64651. }
  64652. void Graphics::drawRect (const int x,
  64653. const int y,
  64654. const int width,
  64655. const int height,
  64656. const int lineThickness) const throw()
  64657. {
  64658. // passing in a silly number can cause maths problems in rendering!
  64659. jassert (areCoordsSensibleNumbers (x, y, width, height));
  64660. context->fillRect (Rectangle<int> (x, y, width, lineThickness), false);
  64661. context->fillRect (Rectangle<int> (x, y + lineThickness, lineThickness, height - lineThickness * 2), false);
  64662. context->fillRect (Rectangle<int> (x + width - lineThickness, y + lineThickness, lineThickness, height - lineThickness * 2), false);
  64663. context->fillRect (Rectangle<int> (x, y + height - lineThickness, width, lineThickness), false);
  64664. }
  64665. void Graphics::drawRect (const float x,
  64666. const float y,
  64667. const float width,
  64668. const float height,
  64669. const float lineThickness) const throw()
  64670. {
  64671. // passing in a silly number can cause maths problems in rendering!
  64672. jassert (areCoordsSensibleNumbers (x, y, width, height));
  64673. Path p;
  64674. p.addRectangle (x, y, width, lineThickness);
  64675. p.addRectangle (x, y + lineThickness, lineThickness, height - lineThickness * 2.0f);
  64676. p.addRectangle (x + width - lineThickness, y + lineThickness, lineThickness, height - lineThickness * 2.0f);
  64677. p.addRectangle (x, y + height - lineThickness, width, lineThickness);
  64678. fillPath (p);
  64679. }
  64680. void Graphics::drawRect (const Rectangle<int>& r,
  64681. const int lineThickness) const throw()
  64682. {
  64683. drawRect (r.getX(), r.getY(),
  64684. r.getWidth(), r.getHeight(),
  64685. lineThickness);
  64686. }
  64687. void Graphics::drawBevel (const int x,
  64688. const int y,
  64689. const int width,
  64690. const int height,
  64691. const int bevelThickness,
  64692. const Colour& topLeftColour,
  64693. const Colour& bottomRightColour,
  64694. const bool useGradient,
  64695. const bool sharpEdgeOnOutside) const throw()
  64696. {
  64697. // passing in a silly number can cause maths problems in rendering!
  64698. jassert (areCoordsSensibleNumbers (x, y, width, height));
  64699. if (clipRegionIntersects (x, y, width, height))
  64700. {
  64701. context->saveState();
  64702. const float oldOpacity = 1.0f;//xxx state->colour.getFloatAlpha();
  64703. const float ramp = oldOpacity / bevelThickness;
  64704. for (int i = bevelThickness; --i >= 0;)
  64705. {
  64706. const float op = useGradient ? ramp * (sharpEdgeOnOutside ? bevelThickness - i : i)
  64707. : oldOpacity;
  64708. context->setFill (FillType (topLeftColour.withMultipliedAlpha (op)));
  64709. context->fillRect (Rectangle<int> (x + i, y + i, width - i * 2, 1), false);
  64710. context->setFill (FillType (topLeftColour.withMultipliedAlpha (op * 0.75f)));
  64711. context->fillRect (Rectangle<int> (x + i, y + i + 1, 1, height - i * 2 - 2), false);
  64712. context->setFill (FillType (bottomRightColour.withMultipliedAlpha (op)));
  64713. context->fillRect (Rectangle<int> (x + i, y + height - i - 1, width - i * 2, 1), false);
  64714. context->setFill (FillType (bottomRightColour.withMultipliedAlpha (op * 0.75f)));
  64715. context->fillRect (Rectangle<int> (x + width - i - 1, y + i + 1, 1, height - i * 2 - 2), false);
  64716. }
  64717. context->restoreState();
  64718. }
  64719. }
  64720. void Graphics::fillEllipse (const float x,
  64721. const float y,
  64722. const float width,
  64723. const float height) const throw()
  64724. {
  64725. // passing in a silly number can cause maths problems in rendering!
  64726. jassert (areCoordsSensibleNumbers (x, y, width, height));
  64727. Path p;
  64728. p.addEllipse (x, y, width, height);
  64729. fillPath (p);
  64730. }
  64731. void Graphics::drawEllipse (const float x,
  64732. const float y,
  64733. const float width,
  64734. const float height,
  64735. const float lineThickness) const throw()
  64736. {
  64737. // passing in a silly number can cause maths problems in rendering!
  64738. jassert (areCoordsSensibleNumbers (x, y, width, height));
  64739. Path p;
  64740. p.addEllipse (x, y, width, height);
  64741. strokePath (p, PathStrokeType (lineThickness));
  64742. }
  64743. void Graphics::fillRoundedRectangle (const float x,
  64744. const float y,
  64745. const float width,
  64746. const float height,
  64747. const float cornerSize) const throw()
  64748. {
  64749. // passing in a silly number can cause maths problems in rendering!
  64750. jassert (areCoordsSensibleNumbers (x, y, width, height));
  64751. Path p;
  64752. p.addRoundedRectangle (x, y, width, height, cornerSize);
  64753. fillPath (p);
  64754. }
  64755. void Graphics::fillRoundedRectangle (const Rectangle<int>& r,
  64756. const float cornerSize) const throw()
  64757. {
  64758. fillRoundedRectangle ((float) r.getX(),
  64759. (float) r.getY(),
  64760. (float) r.getWidth(),
  64761. (float) r.getHeight(),
  64762. cornerSize);
  64763. }
  64764. void Graphics::drawRoundedRectangle (const float x,
  64765. const float y,
  64766. const float width,
  64767. const float height,
  64768. const float cornerSize,
  64769. const float lineThickness) const throw()
  64770. {
  64771. // passing in a silly number can cause maths problems in rendering!
  64772. jassert (areCoordsSensibleNumbers (x, y, width, height));
  64773. Path p;
  64774. p.addRoundedRectangle (x, y, width, height, cornerSize);
  64775. strokePath (p, PathStrokeType (lineThickness));
  64776. }
  64777. void Graphics::drawRoundedRectangle (const Rectangle<int>& r,
  64778. const float cornerSize,
  64779. const float lineThickness) const throw()
  64780. {
  64781. drawRoundedRectangle ((float) r.getX(),
  64782. (float) r.getY(),
  64783. (float) r.getWidth(),
  64784. (float) r.getHeight(),
  64785. cornerSize, lineThickness);
  64786. }
  64787. void Graphics::drawArrow (const float startX,
  64788. const float startY,
  64789. const float endX,
  64790. const float endY,
  64791. const float lineThickness,
  64792. const float arrowheadWidth,
  64793. const float arrowheadLength) const throw()
  64794. {
  64795. Path p;
  64796. p.addArrow (startX, startY, endX, endY,
  64797. lineThickness, arrowheadWidth, arrowheadLength);
  64798. fillPath (p);
  64799. }
  64800. void Graphics::fillCheckerBoard (int x, int y,
  64801. int width, int height,
  64802. const int checkWidth,
  64803. const int checkHeight,
  64804. const Colour& colour1,
  64805. const Colour& colour2) const throw()
  64806. {
  64807. jassert (checkWidth > 0 && checkHeight > 0); // can't be zero or less!
  64808. if (checkWidth > 0 && checkHeight > 0)
  64809. {
  64810. context->saveState();
  64811. if (colour1 == colour2)
  64812. {
  64813. context->setFill (FillType (colour1));
  64814. context->fillRect (Rectangle<int> (x, y, width, height), false);
  64815. }
  64816. else
  64817. {
  64818. const Rectangle<int> clip (context->getClipBounds());
  64819. const int right = jmin (x + width, clip.getRight());
  64820. const int bottom = jmin (y + height, clip.getBottom());
  64821. int cy = 0;
  64822. while (y < bottom)
  64823. {
  64824. int cx = cy;
  64825. for (int xx = x; xx < right; xx += checkWidth)
  64826. {
  64827. context->setFill (FillType (((cx++ & 1) == 0) ? colour1 : colour2));
  64828. context->fillRect (Rectangle<int> (xx, y, jmin (checkWidth, right - xx), jmin (checkHeight, bottom - y)),
  64829. false);
  64830. }
  64831. ++cy;
  64832. y += checkHeight;
  64833. }
  64834. }
  64835. context->restoreState();
  64836. }
  64837. }
  64838. void Graphics::drawVerticalLine (const int x, float top, float bottom) const throw()
  64839. {
  64840. context->drawVerticalLine (x, top, bottom);
  64841. }
  64842. void Graphics::drawHorizontalLine (const int y, float left, float right) const throw()
  64843. {
  64844. context->drawHorizontalLine (y, left, right);
  64845. }
  64846. void Graphics::drawLine (float x1, float y1, float x2, float y2) const throw()
  64847. {
  64848. context->drawLine (x1, y1, x2, y2);
  64849. }
  64850. void Graphics::drawLine (const float startX,
  64851. const float startY,
  64852. const float endX,
  64853. const float endY,
  64854. const float lineThickness) const throw()
  64855. {
  64856. Path p;
  64857. p.addLineSegment (startX, startY, endX, endY, lineThickness);
  64858. fillPath (p);
  64859. }
  64860. void Graphics::drawLine (const Line& line) const throw()
  64861. {
  64862. drawLine (line.getStartX(), line.getStartY(), line.getEndX(), line.getEndY());
  64863. }
  64864. void Graphics::drawLine (const Line& line,
  64865. const float lineThickness) const throw()
  64866. {
  64867. drawLine (line.getStartX(), line.getStartY(), line.getEndX(), line.getEndY(), lineThickness);
  64868. }
  64869. void Graphics::drawDashedLine (const float startX,
  64870. const float startY,
  64871. const float endX,
  64872. const float endY,
  64873. const float* const dashLengths,
  64874. const int numDashLengths,
  64875. const float lineThickness) const throw()
  64876. {
  64877. const double dx = endX - startX;
  64878. const double dy = endY - startY;
  64879. const double totalLen = juce_hypot (dx, dy);
  64880. if (totalLen >= 0.5)
  64881. {
  64882. const double onePixAlpha = 1.0 / totalLen;
  64883. double alpha = 0.0;
  64884. float x = startX;
  64885. float y = startY;
  64886. int n = 0;
  64887. while (alpha < 1.0f)
  64888. {
  64889. alpha = jmin (1.0, alpha + dashLengths[n++] * onePixAlpha);
  64890. n = n % numDashLengths;
  64891. const float oldX = x;
  64892. const float oldY = y;
  64893. x = (float) (startX + dx * alpha);
  64894. y = (float) (startY + dy * alpha);
  64895. if ((n & 1) != 0)
  64896. {
  64897. if (lineThickness != 1.0f)
  64898. drawLine (oldX, oldY, x, y, lineThickness);
  64899. else
  64900. drawLine (oldX, oldY, x, y);
  64901. }
  64902. }
  64903. }
  64904. }
  64905. void Graphics::setImageResamplingQuality (const Graphics::ResamplingQuality newQuality) throw()
  64906. {
  64907. saveStateIfPending();
  64908. context->setInterpolationQuality (newQuality);
  64909. }
  64910. void Graphics::drawImageAt (const Image* const imageToDraw,
  64911. const int topLeftX,
  64912. const int topLeftY,
  64913. const bool fillAlphaChannelWithCurrentBrush) const throw()
  64914. {
  64915. if (imageToDraw != 0)
  64916. {
  64917. const int imageW = imageToDraw->getWidth();
  64918. const int imageH = imageToDraw->getHeight();
  64919. drawImage (imageToDraw,
  64920. topLeftX, topLeftY, imageW, imageH,
  64921. 0, 0, imageW, imageH,
  64922. fillAlphaChannelWithCurrentBrush);
  64923. }
  64924. }
  64925. void Graphics::drawImageWithin (const Image* const imageToDraw,
  64926. const int destX,
  64927. const int destY,
  64928. const int destW,
  64929. const int destH,
  64930. const RectanglePlacement& placementWithinTarget,
  64931. const bool fillAlphaChannelWithCurrentBrush) const throw()
  64932. {
  64933. // passing in a silly number can cause maths problems in rendering!
  64934. jassert (areCoordsSensibleNumbers (destX, destY, destW, destH));
  64935. if (imageToDraw != 0)
  64936. {
  64937. const int imageW = imageToDraw->getWidth();
  64938. const int imageH = imageToDraw->getHeight();
  64939. if (imageW > 0 && imageH > 0)
  64940. {
  64941. double newX = 0.0, newY = 0.0;
  64942. double newW = imageW;
  64943. double newH = imageH;
  64944. placementWithinTarget.applyTo (newX, newY, newW, newH,
  64945. destX, destY, destW, destH);
  64946. if (newW > 0 && newH > 0)
  64947. {
  64948. drawImage (imageToDraw,
  64949. roundToInt (newX), roundToInt (newY),
  64950. roundToInt (newW), roundToInt (newH),
  64951. 0, 0, imageW, imageH,
  64952. fillAlphaChannelWithCurrentBrush);
  64953. }
  64954. }
  64955. }
  64956. }
  64957. void Graphics::drawImage (const Image* const imageToDraw,
  64958. int dx, int dy, int dw, int dh,
  64959. int sx, int sy, int sw, int sh,
  64960. const bool fillAlphaChannelWithCurrentBrush) const throw()
  64961. {
  64962. // passing in a silly number can cause maths problems in rendering!
  64963. jassert (areCoordsSensibleNumbers (dx, dy, dw, dh));
  64964. jassert (areCoordsSensibleNumbers (sx, sy, sw, sh));
  64965. if (context->clipRegionIntersects (Rectangle<int> (dx, dy, dw, dh)))
  64966. {
  64967. drawImageTransformed (imageToDraw, Rectangle<int> (sx, sy, sw, sh),
  64968. AffineTransform::scale (dw / (float) sw, dh / (float) sh)
  64969. .translated ((float) dx, (float) dy),
  64970. fillAlphaChannelWithCurrentBrush);
  64971. }
  64972. }
  64973. void Graphics::drawImageTransformed (const Image* const imageToDraw,
  64974. const Rectangle<int>& imageSubRegion,
  64975. const AffineTransform& transform,
  64976. const bool fillAlphaChannelWithCurrentBrush) const throw()
  64977. {
  64978. if (imageToDraw != 0 && ! context->isClipEmpty())
  64979. {
  64980. const Rectangle<int> srcClip (imageSubRegion.getIntersection (imageToDraw->getBounds()));
  64981. if (fillAlphaChannelWithCurrentBrush)
  64982. {
  64983. context->saveState();
  64984. context->clipToImageAlpha (*imageToDraw, srcClip, transform);
  64985. fillAll();
  64986. context->restoreState();
  64987. }
  64988. else
  64989. {
  64990. context->drawImage (*imageToDraw, srcClip, transform, false);
  64991. }
  64992. }
  64993. }
  64994. END_JUCE_NAMESPACE
  64995. /*** End of inlined file: juce_Graphics.cpp ***/
  64996. /*** Start of inlined file: juce_Justification.cpp ***/
  64997. BEGIN_JUCE_NAMESPACE
  64998. Justification::Justification (const Justification& other) throw()
  64999. : flags (other.flags)
  65000. {
  65001. }
  65002. Justification& Justification::operator= (const Justification& other) throw()
  65003. {
  65004. flags = other.flags;
  65005. return *this;
  65006. }
  65007. int Justification::getOnlyVerticalFlags() const throw()
  65008. {
  65009. return flags & (top | bottom | verticallyCentred);
  65010. }
  65011. int Justification::getOnlyHorizontalFlags() const throw()
  65012. {
  65013. return flags & (left | right | horizontallyCentred | horizontallyJustified);
  65014. }
  65015. void Justification::applyToRectangle (int& x, int& y,
  65016. const int w, const int h,
  65017. const int spaceX, const int spaceY,
  65018. const int spaceW, const int spaceH) const throw()
  65019. {
  65020. if ((flags & horizontallyCentred) != 0)
  65021. {
  65022. x = spaceX + ((spaceW - w) >> 1);
  65023. }
  65024. else if ((flags & right) != 0)
  65025. {
  65026. x = spaceX + spaceW - w;
  65027. }
  65028. else
  65029. {
  65030. x = spaceX;
  65031. }
  65032. if ((flags & verticallyCentred) != 0)
  65033. {
  65034. y = spaceY + ((spaceH - h) >> 1);
  65035. }
  65036. else if ((flags & bottom) != 0)
  65037. {
  65038. y = spaceY + spaceH - h;
  65039. }
  65040. else
  65041. {
  65042. y = spaceY;
  65043. }
  65044. }
  65045. END_JUCE_NAMESPACE
  65046. /*** End of inlined file: juce_Justification.cpp ***/
  65047. /*** Start of inlined file: juce_LowLevelGraphicsPostScriptRenderer.cpp ***/
  65048. BEGIN_JUCE_NAMESPACE
  65049. // this will throw an assertion if you try to draw something that's not
  65050. // possible in postscript
  65051. #define WARN_ABOUT_NON_POSTSCRIPT_OPERATIONS 0
  65052. #if defined (JUCE_DEBUG) && WARN_ABOUT_NON_POSTSCRIPT_OPERATIONS
  65053. #define notPossibleInPostscriptAssert jassertfalse
  65054. #else
  65055. #define notPossibleInPostscriptAssert
  65056. #endif
  65057. LowLevelGraphicsPostScriptRenderer::LowLevelGraphicsPostScriptRenderer (OutputStream& resultingPostScript,
  65058. const String& documentTitle,
  65059. const int totalWidth_,
  65060. const int totalHeight_)
  65061. : out (resultingPostScript),
  65062. totalWidth (totalWidth_),
  65063. totalHeight (totalHeight_),
  65064. needToClip (true)
  65065. {
  65066. stateStack.add (new SavedState());
  65067. stateStack.getLast()->clip = Rectangle<int> (0, 0, totalWidth_, totalHeight_);
  65068. const float scale = jmin ((520.0f / totalWidth_), (750.0f / totalHeight));
  65069. out << "%!PS-Adobe-3.0 EPSF-3.0"
  65070. "\n%%BoundingBox: 0 0 600 824"
  65071. "\n%%Pages: 0"
  65072. "\n%%Creator: Raw Material Software JUCE"
  65073. "\n%%Title: " << documentTitle <<
  65074. "\n%%CreationDate: none"
  65075. "\n%%LanguageLevel: 2"
  65076. "\n%%EndComments"
  65077. "\n%%BeginProlog"
  65078. "\n%%BeginResource: JRes"
  65079. "\n/bd {bind def} bind def"
  65080. "\n/c {setrgbcolor} bd"
  65081. "\n/m {moveto} bd"
  65082. "\n/l {lineto} bd"
  65083. "\n/rl {rlineto} bd"
  65084. "\n/ct {curveto} bd"
  65085. "\n/cp {closepath} bd"
  65086. "\n/pr {3 index 3 index moveto 1 index 0 rlineto 0 1 index rlineto pop neg 0 rlineto pop pop closepath} bd"
  65087. "\n/doclip {initclip newpath} bd"
  65088. "\n/endclip {clip newpath} bd"
  65089. "\n%%EndResource"
  65090. "\n%%EndProlog"
  65091. "\n%%BeginSetup"
  65092. "\n%%EndSetup"
  65093. "\n%%Page: 1 1"
  65094. "\n%%BeginPageSetup"
  65095. "\n%%EndPageSetup\n\n"
  65096. << "40 800 translate\n"
  65097. << scale << ' ' << scale << " scale\n\n";
  65098. }
  65099. LowLevelGraphicsPostScriptRenderer::~LowLevelGraphicsPostScriptRenderer()
  65100. {
  65101. }
  65102. bool LowLevelGraphicsPostScriptRenderer::isVectorDevice() const
  65103. {
  65104. return true;
  65105. }
  65106. void LowLevelGraphicsPostScriptRenderer::setOrigin (int x, int y)
  65107. {
  65108. if (x != 0 || y != 0)
  65109. {
  65110. stateStack.getLast()->xOffset += x;
  65111. stateStack.getLast()->yOffset += y;
  65112. needToClip = true;
  65113. }
  65114. }
  65115. bool LowLevelGraphicsPostScriptRenderer::clipToRectangle (const Rectangle<int>& r)
  65116. {
  65117. needToClip = true;
  65118. return stateStack.getLast()->clip.clipTo (r.translated (stateStack.getLast()->xOffset, stateStack.getLast()->yOffset));
  65119. }
  65120. bool LowLevelGraphicsPostScriptRenderer::clipToRectangleList (const RectangleList& clipRegion)
  65121. {
  65122. needToClip = true;
  65123. return stateStack.getLast()->clip.clipTo (clipRegion);
  65124. }
  65125. void LowLevelGraphicsPostScriptRenderer::excludeClipRectangle (const Rectangle<int>& r)
  65126. {
  65127. needToClip = true;
  65128. stateStack.getLast()->clip.subtract (r.translated (stateStack.getLast()->xOffset, stateStack.getLast()->yOffset));
  65129. }
  65130. void LowLevelGraphicsPostScriptRenderer::clipToPath (const Path& path, const AffineTransform& transform)
  65131. {
  65132. writeClip();
  65133. Path p (path);
  65134. p.applyTransform (transform.translated ((float) stateStack.getLast()->xOffset, (float) stateStack.getLast()->yOffset));
  65135. writePath (p);
  65136. out << "clip\n";
  65137. }
  65138. void LowLevelGraphicsPostScriptRenderer::clipToImageAlpha (const Image& /*sourceImage*/, const Rectangle<int>& /*srcClip*/, const AffineTransform& /*transform*/)
  65139. {
  65140. needToClip = true;
  65141. jassertfalse // xxx
  65142. }
  65143. bool LowLevelGraphicsPostScriptRenderer::clipRegionIntersects (const Rectangle<int>& r)
  65144. {
  65145. return stateStack.getLast()->clip.intersectsRectangle (r.translated (stateStack.getLast()->xOffset, stateStack.getLast()->yOffset));
  65146. }
  65147. const Rectangle<int> LowLevelGraphicsPostScriptRenderer::getClipBounds() const
  65148. {
  65149. return stateStack.getLast()->clip.getBounds().translated (-stateStack.getLast()->xOffset,
  65150. -stateStack.getLast()->yOffset);
  65151. }
  65152. bool LowLevelGraphicsPostScriptRenderer::isClipEmpty() const
  65153. {
  65154. return stateStack.getLast()->clip.isEmpty();
  65155. }
  65156. LowLevelGraphicsPostScriptRenderer::SavedState::SavedState()
  65157. : xOffset (0),
  65158. yOffset (0)
  65159. {
  65160. }
  65161. LowLevelGraphicsPostScriptRenderer::SavedState::~SavedState()
  65162. {
  65163. }
  65164. void LowLevelGraphicsPostScriptRenderer::saveState()
  65165. {
  65166. stateStack.add (new SavedState (*stateStack.getLast()));
  65167. }
  65168. void LowLevelGraphicsPostScriptRenderer::restoreState()
  65169. {
  65170. jassert (stateStack.size() > 0);
  65171. if (stateStack.size() > 0)
  65172. stateStack.removeLast();
  65173. }
  65174. void LowLevelGraphicsPostScriptRenderer::writeClip()
  65175. {
  65176. if (needToClip)
  65177. {
  65178. needToClip = false;
  65179. out << "doclip ";
  65180. int itemsOnLine = 0;
  65181. for (RectangleList::Iterator i (stateStack.getLast()->clip); i.next();)
  65182. {
  65183. if (++itemsOnLine == 6)
  65184. {
  65185. itemsOnLine = 0;
  65186. out << '\n';
  65187. }
  65188. const Rectangle<int>& r = *i.getRectangle();
  65189. out << r.getX() << ' ' << -r.getY() << ' '
  65190. << r.getWidth() << ' ' << -r.getHeight() << " pr ";
  65191. }
  65192. out << "endclip\n";
  65193. }
  65194. }
  65195. void LowLevelGraphicsPostScriptRenderer::writeColour (const Colour& colour)
  65196. {
  65197. Colour c (Colours::white.overlaidWith (colour));
  65198. if (lastColour != c)
  65199. {
  65200. lastColour = c;
  65201. out << String (c.getFloatRed(), 3) << ' '
  65202. << String (c.getFloatGreen(), 3) << ' '
  65203. << String (c.getFloatBlue(), 3) << " c\n";
  65204. }
  65205. }
  65206. void LowLevelGraphicsPostScriptRenderer::writeXY (const float x, const float y) const
  65207. {
  65208. out << String (x, 2) << ' '
  65209. << String (-y, 2) << ' ';
  65210. }
  65211. void LowLevelGraphicsPostScriptRenderer::writePath (const Path& path) const
  65212. {
  65213. out << "newpath ";
  65214. float lastX = 0.0f;
  65215. float lastY = 0.0f;
  65216. int itemsOnLine = 0;
  65217. Path::Iterator i (path);
  65218. while (i.next())
  65219. {
  65220. if (++itemsOnLine == 4)
  65221. {
  65222. itemsOnLine = 0;
  65223. out << '\n';
  65224. }
  65225. switch (i.elementType)
  65226. {
  65227. case Path::Iterator::startNewSubPath:
  65228. writeXY (i.x1, i.y1);
  65229. lastX = i.x1;
  65230. lastY = i.y1;
  65231. out << "m ";
  65232. break;
  65233. case Path::Iterator::lineTo:
  65234. writeXY (i.x1, i.y1);
  65235. lastX = i.x1;
  65236. lastY = i.y1;
  65237. out << "l ";
  65238. break;
  65239. case Path::Iterator::quadraticTo:
  65240. {
  65241. const float cp1x = lastX + (i.x1 - lastX) * 2.0f / 3.0f;
  65242. const float cp1y = lastY + (i.y1 - lastY) * 2.0f / 3.0f;
  65243. const float cp2x = cp1x + (i.x2 - lastX) / 3.0f;
  65244. const float cp2y = cp1y + (i.y2 - lastY) / 3.0f;
  65245. writeXY (cp1x, cp1y);
  65246. writeXY (cp2x, cp2y);
  65247. writeXY (i.x2, i.y2);
  65248. out << "ct ";
  65249. lastX = i.x2;
  65250. lastY = i.y2;
  65251. }
  65252. break;
  65253. case Path::Iterator::cubicTo:
  65254. writeXY (i.x1, i.y1);
  65255. writeXY (i.x2, i.y2);
  65256. writeXY (i.x3, i.y3);
  65257. out << "ct ";
  65258. lastX = i.x3;
  65259. lastY = i.y3;
  65260. break;
  65261. case Path::Iterator::closePath:
  65262. out << "cp ";
  65263. break;
  65264. default:
  65265. jassertfalse
  65266. break;
  65267. }
  65268. }
  65269. out << '\n';
  65270. }
  65271. void LowLevelGraphicsPostScriptRenderer::writeTransform (const AffineTransform& trans) const
  65272. {
  65273. out << "[ "
  65274. << trans.mat00 << ' '
  65275. << trans.mat10 << ' '
  65276. << trans.mat01 << ' '
  65277. << trans.mat11 << ' '
  65278. << trans.mat02 << ' '
  65279. << trans.mat12 << " ] concat ";
  65280. }
  65281. void LowLevelGraphicsPostScriptRenderer::setFill (const FillType& fillType)
  65282. {
  65283. stateStack.getLast()->fillType = fillType;
  65284. }
  65285. void LowLevelGraphicsPostScriptRenderer::setOpacity (float /*opacity*/)
  65286. {
  65287. }
  65288. void LowLevelGraphicsPostScriptRenderer::setInterpolationQuality (Graphics::ResamplingQuality /*quality*/)
  65289. {
  65290. }
  65291. void LowLevelGraphicsPostScriptRenderer::fillRect (const Rectangle<int>& r, const bool /*replaceExistingContents*/)
  65292. {
  65293. if (stateStack.getLast()->fillType.isColour())
  65294. {
  65295. writeClip();
  65296. writeColour (stateStack.getLast()->fillType.colour);
  65297. Rectangle<int> r2 (r.translated (stateStack.getLast()->xOffset, stateStack.getLast()->yOffset));
  65298. out << r2.getX() << ' ' << -r2.getBottom() << ' ' << r2.getWidth() << ' ' << r2.getHeight() << " rectfill\n";
  65299. }
  65300. else
  65301. {
  65302. Path p;
  65303. p.addRectangle (r);
  65304. fillPath (p, AffineTransform::identity);
  65305. }
  65306. }
  65307. void LowLevelGraphicsPostScriptRenderer::fillPath (const Path& path, const AffineTransform& t)
  65308. {
  65309. if (stateStack.getLast()->fillType.isColour())
  65310. {
  65311. writeClip();
  65312. Path p (path);
  65313. p.applyTransform (t.translated ((float) stateStack.getLast()->xOffset,
  65314. (float) stateStack.getLast()->yOffset));
  65315. writePath (p);
  65316. writeColour (stateStack.getLast()->fillType.colour);
  65317. out << "fill\n";
  65318. }
  65319. else if (stateStack.getLast()->fillType.isGradient())
  65320. {
  65321. // this doesn't work correctly yet - it could be improved to handle solid gradients, but
  65322. // postscript can't do semi-transparent ones.
  65323. notPossibleInPostscriptAssert // you can disable this warning by setting the WARN_ABOUT_NON_POSTSCRIPT_OPERATIONS flag at the top of this file
  65324. writeClip();
  65325. out << "gsave ";
  65326. {
  65327. Path p (path);
  65328. p.applyTransform (t.translated ((float) stateStack.getLast()->xOffset, (float) stateStack.getLast()->yOffset));
  65329. writePath (p);
  65330. out << "clip\n";
  65331. }
  65332. const Rectangle<int> bounds (stateStack.getLast()->clip.getBounds());
  65333. // ideally this would draw lots of lines or ellipses to approximate the gradient, but for the
  65334. // time-being, this just fills it with the average colour..
  65335. writeColour (stateStack.getLast()->fillType.gradient->getColourAtPosition (0.5f));
  65336. out << bounds.getX() << ' ' << -bounds.getBottom() << ' ' << bounds.getWidth() << ' ' << bounds.getHeight() << " rectfill\n";
  65337. out << "grestore\n";
  65338. }
  65339. }
  65340. void LowLevelGraphicsPostScriptRenderer::writeImage (const Image& im,
  65341. const int sx, const int sy,
  65342. const int maxW, const int maxH) const
  65343. {
  65344. out << "{<\n";
  65345. const int w = jmin (maxW, im.getWidth());
  65346. const int h = jmin (maxH, im.getHeight());
  65347. int charsOnLine = 0;
  65348. const Image::BitmapData srcData (im, 0, 0, w, h);
  65349. Colour pixel;
  65350. for (int y = h; --y >= 0;)
  65351. {
  65352. for (int x = 0; x < w; ++x)
  65353. {
  65354. const uint8* pixelData = srcData.getPixelPointer (x, y);
  65355. if (x >= sx && y >= sy)
  65356. {
  65357. if (im.isARGB())
  65358. {
  65359. PixelARGB p (*(const PixelARGB*) pixelData);
  65360. p.unpremultiply();
  65361. pixel = Colours::white.overlaidWith (Colour (p.getARGB()));
  65362. }
  65363. else if (im.isRGB())
  65364. {
  65365. pixel = Colour (((const PixelRGB*) pixelData)->getARGB());
  65366. }
  65367. else
  65368. {
  65369. pixel = Colour ((uint8) 0, (uint8) 0, (uint8) 0, *pixelData);
  65370. }
  65371. }
  65372. else
  65373. {
  65374. pixel = Colours::transparentWhite;
  65375. }
  65376. const uint8 pixelValues[3] = { pixel.getRed(), pixel.getGreen(), pixel.getBlue() };
  65377. out << String::toHexString (pixelValues, 3, 0);
  65378. charsOnLine += 3;
  65379. if (charsOnLine > 100)
  65380. {
  65381. out << '\n';
  65382. charsOnLine = 0;
  65383. }
  65384. }
  65385. }
  65386. out << "\n>}\n";
  65387. }
  65388. void LowLevelGraphicsPostScriptRenderer::drawImage (const Image& sourceImage, const Rectangle<int>& srcClip,
  65389. const AffineTransform& transform, const bool /*fillEntireClipAsTiles*/)
  65390. {
  65391. const int w = jmin (sourceImage.getWidth(), srcClip.getRight());
  65392. const int h = jmin (sourceImage.getHeight(), srcClip.getBottom());
  65393. writeClip();
  65394. out << "gsave ";
  65395. writeTransform (transform.translated ((float) stateStack.getLast()->xOffset, (float) stateStack.getLast()->yOffset)
  65396. .scaled (1.0f, -1.0f));
  65397. RectangleList imageClip;
  65398. sourceImage.createSolidAreaMask (imageClip, 0.5f);
  65399. imageClip.clipTo (srcClip);
  65400. out << "newpath ";
  65401. int itemsOnLine = 0;
  65402. for (RectangleList::Iterator i (imageClip); i.next();)
  65403. {
  65404. if (++itemsOnLine == 6)
  65405. {
  65406. out << '\n';
  65407. itemsOnLine = 0;
  65408. }
  65409. const Rectangle<int>& r = *i.getRectangle();
  65410. out << r.getX() << ' ' << r.getY() << ' ' << r.getWidth() << ' ' << r.getHeight() << " pr ";
  65411. }
  65412. out << " clip newpath\n";
  65413. out << w << ' ' << h << " scale\n";
  65414. out << w << ' ' << h << " 8 [" << w << " 0 0 -" << h << ' ' << (int) 0 << ' ' << h << " ]\n";
  65415. writeImage (sourceImage, srcClip.getX(), srcClip.getY(), srcClip.getWidth(), srcClip.getHeight());
  65416. out << "false 3 colorimage grestore\n";
  65417. needToClip = true;
  65418. }
  65419. void LowLevelGraphicsPostScriptRenderer::drawLine (double x1, double y1, double x2, double y2)
  65420. {
  65421. Path p;
  65422. p.addLineSegment ((float) x1, (float) y1, (float) x2, (float) y2, 1.0f);
  65423. fillPath (p, AffineTransform::identity);
  65424. }
  65425. void LowLevelGraphicsPostScriptRenderer::drawVerticalLine (const int x, double top, double bottom)
  65426. {
  65427. drawLine (x, top, x, bottom);
  65428. }
  65429. void LowLevelGraphicsPostScriptRenderer::drawHorizontalLine (const int y, double left, double right)
  65430. {
  65431. drawLine (left, y, right, y);
  65432. }
  65433. void LowLevelGraphicsPostScriptRenderer::setFont (const Font& newFont)
  65434. {
  65435. stateStack.getLast()->font = newFont;
  65436. }
  65437. const Font LowLevelGraphicsPostScriptRenderer::getFont()
  65438. {
  65439. return stateStack.getLast()->font;
  65440. }
  65441. void LowLevelGraphicsPostScriptRenderer::drawGlyph (int glyphNumber, const AffineTransform& transform)
  65442. {
  65443. Path p;
  65444. Font& font = stateStack.getLast()->font;
  65445. font.getTypeface()->getOutlineForGlyph (glyphNumber, p);
  65446. fillPath (p, AffineTransform::scale (font.getHeight() * font.getHorizontalScale(), font.getHeight()).followedBy (transform));
  65447. }
  65448. END_JUCE_NAMESPACE
  65449. /*** End of inlined file: juce_LowLevelGraphicsPostScriptRenderer.cpp ***/
  65450. /*** Start of inlined file: juce_LowLevelGraphicsSoftwareRenderer.cpp ***/
  65451. BEGIN_JUCE_NAMESPACE
  65452. #if (JUCE_WINDOWS || JUCE_LINUX) && ! JUCE_64BIT
  65453. #define JUCE_USE_SSE_INSTRUCTIONS 1
  65454. #endif
  65455. #if JUCE_MSVC && JUCE_DEBUG
  65456. #pragma warning (disable: 4714) // warning about forcedinline methods not being inlined
  65457. #endif
  65458. #if JUCE_MSVC
  65459. #pragma warning (push)
  65460. #pragma warning (disable: 4127) // "expression is constant" warning
  65461. #endif
  65462. template <class PixelType, bool replaceExisting = false>
  65463. class SolidColourEdgeTableRenderer
  65464. {
  65465. public:
  65466. SolidColourEdgeTableRenderer (const Image::BitmapData& data_, const PixelARGB& colour) throw()
  65467. : data (data_),
  65468. sourceColour (colour)
  65469. {
  65470. if (sizeof (PixelType) == 3)
  65471. {
  65472. areRGBComponentsEqual = sourceColour.getRed() == sourceColour.getGreen()
  65473. && sourceColour.getGreen() == sourceColour.getBlue();
  65474. filler[0].set (sourceColour);
  65475. filler[1].set (sourceColour);
  65476. filler[2].set (sourceColour);
  65477. filler[3].set (sourceColour);
  65478. }
  65479. }
  65480. forcedinline void setEdgeTableYPos (const int y) throw()
  65481. {
  65482. linePixels = (PixelType*) data.getLinePointer (y);
  65483. }
  65484. forcedinline void handleEdgeTablePixel (const int x, const int alphaLevel) const throw()
  65485. {
  65486. if (replaceExisting)
  65487. linePixels[x].set (sourceColour);
  65488. else
  65489. linePixels[x].blend (sourceColour, alphaLevel);
  65490. }
  65491. forcedinline void handleEdgeTableLine (const int x, int width, const int alphaLevel) const throw()
  65492. {
  65493. PixelARGB p (sourceColour);
  65494. p.multiplyAlpha (alphaLevel);
  65495. PixelType* dest = linePixels + x;
  65496. if (replaceExisting || p.getAlpha() >= 0xff)
  65497. replaceLine (dest, p, width);
  65498. else
  65499. blendLine (dest, p, width);
  65500. }
  65501. private:
  65502. const Image::BitmapData& data;
  65503. PixelType* linePixels;
  65504. PixelARGB sourceColour;
  65505. PixelRGB filler [4];
  65506. bool areRGBComponentsEqual;
  65507. inline void blendLine (PixelType* dest, const PixelARGB& colour, int width) const throw()
  65508. {
  65509. do
  65510. {
  65511. dest->blend (colour);
  65512. ++dest;
  65513. } while (--width > 0);
  65514. }
  65515. forcedinline void replaceLine (PixelRGB* dest, const PixelARGB& colour, int width) const throw()
  65516. {
  65517. if (areRGBComponentsEqual) // if all the component values are the same, we can cheat..
  65518. {
  65519. memset (dest, colour.getRed(), width * 3);
  65520. }
  65521. else
  65522. {
  65523. if (width >> 5)
  65524. {
  65525. const int* const intFiller = (const int*) filler;
  65526. while (width > 8 && (((pointer_sized_int) dest) & 7) != 0)
  65527. {
  65528. dest->set (colour);
  65529. ++dest;
  65530. --width;
  65531. }
  65532. while (width > 4)
  65533. {
  65534. ((int*) dest) [0] = intFiller[0];
  65535. ((int*) dest) [1] = intFiller[1];
  65536. ((int*) dest) [2] = intFiller[2];
  65537. dest = (PixelRGB*) (((uint8*) dest) + 12);
  65538. width -= 4;
  65539. }
  65540. }
  65541. while (--width >= 0)
  65542. {
  65543. dest->set (colour);
  65544. ++dest;
  65545. }
  65546. }
  65547. }
  65548. forcedinline void replaceLine (PixelAlpha* dest, const PixelARGB& colour, int width) const throw()
  65549. {
  65550. memset (dest, colour.getAlpha(), width);
  65551. }
  65552. forcedinline void replaceLine (PixelARGB* dest, const PixelARGB& colour, int width) const throw()
  65553. {
  65554. do
  65555. {
  65556. dest->set (colour);
  65557. ++dest;
  65558. } while (--width > 0);
  65559. }
  65560. SolidColourEdgeTableRenderer (const SolidColourEdgeTableRenderer&);
  65561. SolidColourEdgeTableRenderer& operator= (const SolidColourEdgeTableRenderer&);
  65562. };
  65563. class LinearGradientPixelGenerator
  65564. {
  65565. public:
  65566. LinearGradientPixelGenerator (const ColourGradient& gradient, const AffineTransform& transform, const PixelARGB* const lookupTable_, const int numEntries_)
  65567. : lookupTable (lookupTable_), numEntries (numEntries_)
  65568. {
  65569. jassert (numEntries_ >= 0);
  65570. float x1 = gradient.x1;
  65571. float y1 = gradient.y1;
  65572. float x2 = gradient.x2;
  65573. float y2 = gradient.y2;
  65574. if (! transform.isIdentity())
  65575. {
  65576. const Line l (x2, y2, x1, y1);
  65577. const Point<float> p3 = l.getPointAlongLine (0.0f, 100.0f);
  65578. float x3 = p3.getX();
  65579. float y3 = p3.getY();
  65580. transform.transformPoint (x1, y1);
  65581. transform.transformPoint (x2, y2);
  65582. transform.transformPoint (x3, y3);
  65583. const Line l2 (x2, y2, x3, y3);
  65584. const float prop = l2.findNearestPointTo (x1, y1);
  65585. const Point<float> newP2 (l2.getPointAlongLineProportionally (prop));
  65586. x2 = newP2.getX();
  65587. y2 = newP2.getY();
  65588. }
  65589. vertical = fabs (x1 - x2) < 0.001f;
  65590. horizontal = fabs (y1 - y2) < 0.001f;
  65591. if (vertical)
  65592. {
  65593. scale = roundToInt ((numEntries << (int) numScaleBits) / (double) (y2 - y1));
  65594. start = roundToInt (y1 * scale);
  65595. }
  65596. else if (horizontal)
  65597. {
  65598. scale = roundToInt ((numEntries << (int) numScaleBits) / (double) (x2 - x1));
  65599. start = roundToInt (x1 * scale);
  65600. }
  65601. else
  65602. {
  65603. grad = (y2 - y1) / (double) (x1 - x2);
  65604. yTerm = y1 - x1 / grad;
  65605. scale = roundToInt ((numEntries << (int) numScaleBits) / (yTerm * grad - (y2 * grad - x2)));
  65606. grad *= scale;
  65607. }
  65608. }
  65609. forcedinline void setY (const int y) throw()
  65610. {
  65611. if (vertical)
  65612. linePix = lookupTable [jlimit (0, numEntries, (y * scale - start) >> (int) numScaleBits)];
  65613. else if (! horizontal)
  65614. start = roundToInt ((y - yTerm) * grad);
  65615. }
  65616. inline const PixelARGB getPixel (const int x) const throw()
  65617. {
  65618. return vertical ? linePix
  65619. : lookupTable [jlimit (0, numEntries, (x * scale - start) >> (int) numScaleBits)];
  65620. }
  65621. private:
  65622. const PixelARGB* const lookupTable;
  65623. const int numEntries;
  65624. PixelARGB linePix;
  65625. int start, scale;
  65626. double grad, yTerm;
  65627. bool vertical, horizontal;
  65628. enum { numScaleBits = 12 };
  65629. LinearGradientPixelGenerator (const LinearGradientPixelGenerator&);
  65630. LinearGradientPixelGenerator& operator= (const LinearGradientPixelGenerator&);
  65631. };
  65632. class RadialGradientPixelGenerator
  65633. {
  65634. public:
  65635. RadialGradientPixelGenerator (const ColourGradient& gradient, const AffineTransform&,
  65636. const PixelARGB* const lookupTable_, const int numEntries_) throw()
  65637. : lookupTable (lookupTable_),
  65638. numEntries (numEntries_),
  65639. gx1 (gradient.x1),
  65640. gy1 (gradient.y1)
  65641. {
  65642. jassert (numEntries_ >= 0);
  65643. const float gdx = gradient.x1 - gradient.x2;
  65644. const float gdy = gradient.y1 - gradient.y2;
  65645. maxDist = gdx * gdx + gdy * gdy;
  65646. invScale = numEntries / sqrt (maxDist);
  65647. jassert (roundToInt (sqrt (maxDist) * invScale) <= numEntries);
  65648. }
  65649. forcedinline void setY (const int y) throw()
  65650. {
  65651. dy = y - gy1;
  65652. dy *= dy;
  65653. }
  65654. inline const PixelARGB getPixel (const int px) const throw()
  65655. {
  65656. double x = px - gx1;
  65657. x *= x;
  65658. x += dy;
  65659. return lookupTable [x >= maxDist ? numEntries : roundToInt (sqrt (x) * invScale)];
  65660. }
  65661. protected:
  65662. const PixelARGB* const lookupTable;
  65663. const int numEntries;
  65664. const double gx1, gy1;
  65665. double maxDist, invScale, dy;
  65666. RadialGradientPixelGenerator (const RadialGradientPixelGenerator&);
  65667. RadialGradientPixelGenerator& operator= (const RadialGradientPixelGenerator&);
  65668. };
  65669. class TransformedRadialGradientPixelGenerator : public RadialGradientPixelGenerator
  65670. {
  65671. public:
  65672. TransformedRadialGradientPixelGenerator (const ColourGradient& gradient, const AffineTransform& transform,
  65673. const PixelARGB* const lookupTable_, const int numEntries_) throw()
  65674. : RadialGradientPixelGenerator (gradient, transform, lookupTable_, numEntries_),
  65675. inverseTransform (transform.inverted())
  65676. {
  65677. tM10 = inverseTransform.mat10;
  65678. tM00 = inverseTransform.mat00;
  65679. }
  65680. forcedinline void setY (const int y) throw()
  65681. {
  65682. lineYM01 = inverseTransform.mat01 * y + inverseTransform.mat02 - gx1;
  65683. lineYM11 = inverseTransform.mat11 * y + inverseTransform.mat12 - gy1;
  65684. }
  65685. inline const PixelARGB getPixel (const int px) const throw()
  65686. {
  65687. double x = px;
  65688. const double y = tM10 * x + lineYM11;
  65689. x = tM00 * x + lineYM01;
  65690. x *= x;
  65691. x += y * y;
  65692. if (x >= maxDist)
  65693. return lookupTable [numEntries];
  65694. else
  65695. return lookupTable [jmin (numEntries, roundToInt (sqrt (x) * invScale))];
  65696. }
  65697. private:
  65698. double tM10, tM00, lineYM01, lineYM11;
  65699. const AffineTransform inverseTransform;
  65700. TransformedRadialGradientPixelGenerator (const TransformedRadialGradientPixelGenerator&);
  65701. TransformedRadialGradientPixelGenerator& operator= (const TransformedRadialGradientPixelGenerator&);
  65702. };
  65703. template <class PixelType, class GradientType>
  65704. class GradientEdgeTableRenderer : public GradientType
  65705. {
  65706. public:
  65707. GradientEdgeTableRenderer (const Image::BitmapData& destData_, const ColourGradient& gradient, const AffineTransform& transform,
  65708. const PixelARGB* const lookupTable_, const int numEntries_) throw()
  65709. : GradientType (gradient, transform, lookupTable_, numEntries_ - 1),
  65710. destData (destData_)
  65711. {
  65712. }
  65713. forcedinline void setEdgeTableYPos (const int y) throw()
  65714. {
  65715. linePixels = (PixelType*) destData.getLinePointer (y);
  65716. GradientType::setY (y);
  65717. }
  65718. forcedinline void handleEdgeTablePixel (const int x, const int alphaLevel) const throw()
  65719. {
  65720. linePixels[x].blend (GradientType::getPixel (x), alphaLevel);
  65721. }
  65722. forcedinline void handleEdgeTableLine (int x, int width, const int alphaLevel) const throw()
  65723. {
  65724. PixelType* dest = linePixels + x;
  65725. if (alphaLevel < 0xff)
  65726. {
  65727. do
  65728. {
  65729. (dest++)->blend (GradientType::getPixel (x++), alphaLevel);
  65730. } while (--width > 0);
  65731. }
  65732. else
  65733. {
  65734. do
  65735. {
  65736. (dest++)->blend (GradientType::getPixel (x++));
  65737. } while (--width > 0);
  65738. }
  65739. }
  65740. private:
  65741. const Image::BitmapData& destData;
  65742. PixelType* linePixels;
  65743. GradientEdgeTableRenderer (const GradientEdgeTableRenderer&);
  65744. GradientEdgeTableRenderer& operator= (const GradientEdgeTableRenderer&);
  65745. };
  65746. static forcedinline int safeModulo (int n, const int divisor) throw()
  65747. {
  65748. jassert (divisor > 0);
  65749. n %= divisor;
  65750. return (n < 0) ? (n + divisor) : n;
  65751. }
  65752. template <class DestPixelType, class SrcPixelType, bool repeatPattern>
  65753. class ImageFillEdgeTableRenderer
  65754. {
  65755. public:
  65756. ImageFillEdgeTableRenderer (const Image::BitmapData& destData_,
  65757. const Image::BitmapData& srcData_,
  65758. const int extraAlpha_,
  65759. const int x, const int y) throw()
  65760. : destData (destData_),
  65761. srcData (srcData_),
  65762. extraAlpha (extraAlpha_ + 1),
  65763. xOffset (repeatPattern ? safeModulo (x, srcData_.width) - srcData_.width : x),
  65764. yOffset (repeatPattern ? safeModulo (y, srcData_.height) - srcData_.height : y)
  65765. {
  65766. }
  65767. forcedinline void setEdgeTableYPos (int y) throw()
  65768. {
  65769. linePixels = (DestPixelType*) destData.getLinePointer (y);
  65770. y -= yOffset;
  65771. if (repeatPattern)
  65772. {
  65773. jassert (y >= 0);
  65774. y %= srcData.height;
  65775. }
  65776. sourceLineStart = (SrcPixelType*) srcData.getLinePointer (y);
  65777. }
  65778. forcedinline void handleEdgeTablePixel (int x, int alphaLevel) const throw()
  65779. {
  65780. alphaLevel = (alphaLevel * extraAlpha) >> 8;
  65781. linePixels[x].blend (sourceLineStart [repeatPattern ? ((x - xOffset) % srcData.width) : (x - xOffset)], alphaLevel);
  65782. }
  65783. forcedinline void handleEdgeTableLine (int x, int width, int alphaLevel) const throw()
  65784. {
  65785. DestPixelType* dest = linePixels + x;
  65786. alphaLevel = (alphaLevel * extraAlpha) >> 8;
  65787. x -= xOffset;
  65788. jassert (repeatPattern || (x >= 0 && x + width <= srcData.width));
  65789. if (alphaLevel < 0xfe)
  65790. {
  65791. do
  65792. {
  65793. dest++ ->blend (sourceLineStart [repeatPattern ? (x++ % srcData.width) : x++], alphaLevel);
  65794. } while (--width > 0);
  65795. }
  65796. else
  65797. {
  65798. if (repeatPattern)
  65799. {
  65800. do
  65801. {
  65802. dest++ ->blend (sourceLineStart [x++ % srcData.width]);
  65803. } while (--width > 0);
  65804. }
  65805. else
  65806. {
  65807. copyRow (dest, sourceLineStart + x, width);
  65808. }
  65809. }
  65810. }
  65811. void clipEdgeTableLine (EdgeTable& et, int x, int y, int width) throw()
  65812. {
  65813. jassert (x - xOffset >= 0 && x + width - xOffset <= srcData.width);
  65814. SrcPixelType* s = (SrcPixelType*) srcData.getLinePointer (y - yOffset);
  65815. uint8* mask = (uint8*) (s + x - xOffset);
  65816. if (sizeof (SrcPixelType) == sizeof (PixelARGB))
  65817. mask += PixelARGB::indexA;
  65818. et.clipLineToMask (x, y, mask, sizeof (SrcPixelType), width);
  65819. }
  65820. private:
  65821. const Image::BitmapData& destData;
  65822. const Image::BitmapData& srcData;
  65823. const int extraAlpha, xOffset, yOffset;
  65824. DestPixelType* linePixels;
  65825. SrcPixelType* sourceLineStart;
  65826. template <class PixelType1, class PixelType2>
  65827. forcedinline static void copyRow (PixelType1* dest, PixelType2* src, int width) throw()
  65828. {
  65829. do
  65830. {
  65831. dest++ ->blend (*src++);
  65832. } while (--width > 0);
  65833. }
  65834. forcedinline static void copyRow (PixelRGB* dest, PixelRGB* src, int width) throw()
  65835. {
  65836. memcpy (dest, src, width * sizeof (PixelRGB));
  65837. }
  65838. ImageFillEdgeTableRenderer (const ImageFillEdgeTableRenderer&);
  65839. ImageFillEdgeTableRenderer& operator= (const ImageFillEdgeTableRenderer&);
  65840. };
  65841. template <class DestPixelType, class SrcPixelType, bool repeatPattern>
  65842. class TransformedImageFillEdgeTableRenderer
  65843. {
  65844. public:
  65845. TransformedImageFillEdgeTableRenderer (const Image::BitmapData& destData_,
  65846. const Image::BitmapData& srcData_,
  65847. const AffineTransform& transform,
  65848. const int extraAlpha_,
  65849. const bool betterQuality_) throw()
  65850. : interpolator (transform),
  65851. destData (destData_),
  65852. srcData (srcData_),
  65853. extraAlpha (extraAlpha_ + 1),
  65854. betterQuality (betterQuality_),
  65855. pixelOffset (betterQuality_ ? 0.5f : 0.0f),
  65856. pixelOffsetInt (betterQuality_ ? -128 : 0),
  65857. maxX (srcData_.width - 1),
  65858. maxY (srcData_.height - 1),
  65859. scratchSize (2048)
  65860. {
  65861. scratchBuffer.malloc (scratchSize);
  65862. }
  65863. ~TransformedImageFillEdgeTableRenderer() throw()
  65864. {
  65865. }
  65866. forcedinline void setEdgeTableYPos (const int newY) throw()
  65867. {
  65868. y = newY;
  65869. linePixels = (DestPixelType*) destData.getLinePointer (newY);
  65870. }
  65871. forcedinline void handleEdgeTablePixel (const int x, int alphaLevel) throw()
  65872. {
  65873. alphaLevel *= extraAlpha;
  65874. alphaLevel >>= 8;
  65875. SrcPixelType p;
  65876. generate (&p, x, 1);
  65877. linePixels[x].blend (p, alphaLevel);
  65878. }
  65879. forcedinline void handleEdgeTableLine (const int x, int width, int alphaLevel) throw()
  65880. {
  65881. if (width > scratchSize)
  65882. {
  65883. scratchSize = width;
  65884. scratchBuffer.malloc (scratchSize);
  65885. }
  65886. SrcPixelType* span = scratchBuffer;
  65887. generate (span, x, width);
  65888. DestPixelType* dest = linePixels + x;
  65889. alphaLevel *= extraAlpha;
  65890. alphaLevel >>= 8;
  65891. if (alphaLevel < 0xfe)
  65892. {
  65893. do
  65894. {
  65895. dest++ ->blend (*span++, alphaLevel);
  65896. } while (--width > 0);
  65897. }
  65898. else
  65899. {
  65900. do
  65901. {
  65902. dest++ ->blend (*span++);
  65903. } while (--width > 0);
  65904. }
  65905. }
  65906. void clipEdgeTableLine (EdgeTable& et, int x, int y_, int width) throw()
  65907. {
  65908. if (width > scratchSize)
  65909. {
  65910. scratchSize = width;
  65911. scratchBuffer.malloc (scratchSize);
  65912. }
  65913. y = y_;
  65914. generate (scratchBuffer, x, width);
  65915. const uint8* mask = reinterpret_cast <uint8*> (scratchBuffer.getData());
  65916. if (sizeof (SrcPixelType) == sizeof (PixelARGB))
  65917. mask += PixelARGB::indexA;
  65918. et.clipLineToMask (x, y_, mask, sizeof (SrcPixelType), width);
  65919. }
  65920. private:
  65921. void generate (PixelARGB* dest, const int x, int numPixels) throw()
  65922. {
  65923. this->interpolator.setStartOfLine (x + pixelOffset, y + pixelOffset, numPixels);
  65924. do
  65925. {
  65926. int hiResX, hiResY;
  65927. this->interpolator.next (hiResX, hiResY);
  65928. hiResX += pixelOffsetInt;
  65929. hiResY += pixelOffsetInt;
  65930. int loResX = hiResX >> 8;
  65931. int loResY = hiResY >> 8;
  65932. if (repeatPattern)
  65933. {
  65934. loResX = safeModulo (loResX, srcData.width);
  65935. loResY = safeModulo (loResY, srcData.height);
  65936. }
  65937. if (betterQuality
  65938. && ((unsigned int) loResX) < (unsigned int) maxX
  65939. && ((unsigned int) loResY) < (unsigned int) maxY)
  65940. {
  65941. uint32 c[4] = { 256 * 128, 256 * 128, 256 * 128, 256 * 128 };
  65942. hiResX &= 255;
  65943. hiResY &= 255;
  65944. const uint8* src = this->srcData.getPixelPointer (loResX, loResY);
  65945. uint32 weight = (256 - hiResX) * (256 - hiResY);
  65946. c[0] += weight * src[0];
  65947. c[1] += weight * src[1];
  65948. c[2] += weight * src[2];
  65949. c[3] += weight * src[3];
  65950. weight = hiResX * (256 - hiResY);
  65951. c[0] += weight * src[4];
  65952. c[1] += weight * src[5];
  65953. c[2] += weight * src[6];
  65954. c[3] += weight * src[7];
  65955. src += this->srcData.lineStride;
  65956. weight = (256 - hiResX) * hiResY;
  65957. c[0] += weight * src[0];
  65958. c[1] += weight * src[1];
  65959. c[2] += weight * src[2];
  65960. c[3] += weight * src[3];
  65961. weight = hiResX * hiResY;
  65962. c[0] += weight * src[4];
  65963. c[1] += weight * src[5];
  65964. c[2] += weight * src[6];
  65965. c[3] += weight * src[7];
  65966. dest->setARGB ((uint8) (c[PixelARGB::indexA] >> 16),
  65967. (uint8) (c[PixelARGB::indexR] >> 16),
  65968. (uint8) (c[PixelARGB::indexG] >> 16),
  65969. (uint8) (c[PixelARGB::indexB] >> 16));
  65970. }
  65971. else
  65972. {
  65973. if (! repeatPattern)
  65974. {
  65975. // Beyond the edges, just repeat the edge pixels and leave the anti-aliasing to be handled by the edgetable
  65976. if (loResX < 0) loResX = 0;
  65977. if (loResY < 0) loResY = 0;
  65978. if (loResX > maxX) loResX = maxX;
  65979. if (loResY > maxY) loResY = maxY;
  65980. }
  65981. dest->set (*(const PixelARGB*) this->srcData.getPixelPointer (loResX, loResY));
  65982. }
  65983. ++dest;
  65984. } while (--numPixels > 0);
  65985. }
  65986. void generate (PixelRGB* dest, const int x, int numPixels) throw()
  65987. {
  65988. this->interpolator.setStartOfLine (x + pixelOffset, y + pixelOffset, numPixels);
  65989. do
  65990. {
  65991. int hiResX, hiResY;
  65992. this->interpolator.next (hiResX, hiResY);
  65993. hiResX += pixelOffsetInt;
  65994. hiResY += pixelOffsetInt;
  65995. int loResX = hiResX >> 8;
  65996. int loResY = hiResY >> 8;
  65997. if (repeatPattern)
  65998. {
  65999. loResX = safeModulo (loResX, srcData.width);
  66000. loResY = safeModulo (loResY, srcData.height);
  66001. }
  66002. if (betterQuality
  66003. && ((unsigned int) loResX) < (unsigned int) maxX
  66004. && ((unsigned int) loResY) < (unsigned int) maxY)
  66005. {
  66006. uint32 c[3] = { 256 * 128, 256 * 128, 256 * 128 };
  66007. hiResX &= 255;
  66008. hiResY &= 255;
  66009. const uint8* src = this->srcData.getPixelPointer (loResX, loResY);
  66010. unsigned int weight = (256 - hiResX) * (256 - hiResY);
  66011. c[0] += weight * src[0];
  66012. c[1] += weight * src[1];
  66013. c[2] += weight * src[2];
  66014. weight = hiResX * (256 - hiResY);
  66015. c[0] += weight * src[3];
  66016. c[1] += weight * src[4];
  66017. c[2] += weight * src[5];
  66018. src += this->srcData.lineStride;
  66019. weight = (256 - hiResX) * hiResY;
  66020. c[0] += weight * src[0];
  66021. c[1] += weight * src[1];
  66022. c[2] += weight * src[2];
  66023. weight = hiResX * hiResY;
  66024. c[0] += weight * src[3];
  66025. c[1] += weight * src[4];
  66026. c[2] += weight * src[5];
  66027. dest->setARGB ((uint8) 255,
  66028. (uint8) (c[PixelRGB::indexR] >> 16),
  66029. (uint8) (c[PixelRGB::indexG] >> 16),
  66030. (uint8) (c[PixelRGB::indexB] >> 16));
  66031. }
  66032. else
  66033. {
  66034. if (! repeatPattern)
  66035. {
  66036. // Beyond the edges, just repeat the edge pixels and leave the anti-aliasing to be handled by the edgetable
  66037. if (loResX < 0) loResX = 0;
  66038. if (loResY < 0) loResY = 0;
  66039. if (loResX > maxX) loResX = maxX;
  66040. if (loResY > maxY) loResY = maxY;
  66041. }
  66042. dest->set (*(const PixelRGB*) this->srcData.getPixelPointer (loResX, loResY));
  66043. }
  66044. ++dest;
  66045. } while (--numPixels > 0);
  66046. }
  66047. void generate (PixelAlpha* dest, const int x, int numPixels) throw()
  66048. {
  66049. this->interpolator.setStartOfLine (x + pixelOffset, y + pixelOffset, numPixels);
  66050. do
  66051. {
  66052. int hiResX, hiResY;
  66053. this->interpolator.next (hiResX, hiResY);
  66054. hiResX += pixelOffsetInt;
  66055. hiResY += pixelOffsetInt;
  66056. int loResX = hiResX >> 8;
  66057. int loResY = hiResY >> 8;
  66058. if (repeatPattern)
  66059. {
  66060. loResX = safeModulo (loResX, srcData.width);
  66061. loResY = safeModulo (loResY, srcData.height);
  66062. }
  66063. if (betterQuality
  66064. && ((unsigned int) loResX) < (unsigned int) maxX
  66065. && ((unsigned int) loResY) < (unsigned int) maxY)
  66066. {
  66067. hiResX &= 255;
  66068. hiResY &= 255;
  66069. const uint8* src = this->srcData.getPixelPointer (loResX, loResY);
  66070. uint32 c = 256 * 128;
  66071. c += src[0] * ((256 - hiResX) * (256 - hiResY));
  66072. c += src[1] * (hiResX * (256 - hiResY));
  66073. src += this->srcData.lineStride;
  66074. c += src[0] * ((256 - hiResX) * hiResY);
  66075. c += src[1] * (hiResX * hiResY);
  66076. *((uint8*) dest) = (uint8) c;
  66077. }
  66078. else
  66079. {
  66080. if (! repeatPattern)
  66081. {
  66082. // Beyond the edges, just repeat the edge pixels and leave the anti-aliasing to be handled by the edgetable
  66083. if (loResX < 0) loResX = 0;
  66084. if (loResY < 0) loResY = 0;
  66085. if (loResX > maxX) loResX = maxX;
  66086. if (loResY > maxY) loResY = maxY;
  66087. }
  66088. *((uint8*) dest) = *(this->srcData.getPixelPointer (loResX, loResY));
  66089. }
  66090. ++dest;
  66091. } while (--numPixels > 0);
  66092. }
  66093. class TransformedImageSpanInterpolator
  66094. {
  66095. public:
  66096. TransformedImageSpanInterpolator (const AffineTransform& transform) throw()
  66097. : inverseTransform (transform.inverted())
  66098. {}
  66099. void setStartOfLine (float x, float y, const int numPixels) throw()
  66100. {
  66101. float x1 = x, y1 = y;
  66102. inverseTransform.transformPoint (x1, y1);
  66103. x += numPixels;
  66104. inverseTransform.transformPoint (x, y);
  66105. xBresenham.set ((int) (x1 * 256.0f), (int) (x * 256.0f), numPixels);
  66106. yBresenham.set ((int) (y1 * 256.0f), (int) (y * 256.0f), numPixels);
  66107. }
  66108. void next (int& x, int& y) throw()
  66109. {
  66110. x = xBresenham.n;
  66111. xBresenham.stepToNext();
  66112. y = yBresenham.n;
  66113. yBresenham.stepToNext();
  66114. }
  66115. private:
  66116. class BresenhamInterpolator
  66117. {
  66118. public:
  66119. BresenhamInterpolator() throw() {}
  66120. void set (const int n1, const int n2, const int numSteps_) throw()
  66121. {
  66122. numSteps = jmax (1, numSteps_);
  66123. step = (n2 - n1) / numSteps;
  66124. remainder = modulo = (n2 - n1) % numSteps;
  66125. n = n1;
  66126. if (modulo <= 0)
  66127. {
  66128. modulo += numSteps;
  66129. remainder += numSteps;
  66130. --step;
  66131. }
  66132. modulo -= numSteps;
  66133. }
  66134. forcedinline void stepToNext() throw()
  66135. {
  66136. modulo += remainder;
  66137. n += step;
  66138. if (modulo > 0)
  66139. {
  66140. modulo -= numSteps;
  66141. ++n;
  66142. }
  66143. }
  66144. int n;
  66145. private:
  66146. int numSteps, step, modulo, remainder;
  66147. };
  66148. const AffineTransform inverseTransform;
  66149. BresenhamInterpolator xBresenham, yBresenham;
  66150. TransformedImageSpanInterpolator (const TransformedImageSpanInterpolator&);
  66151. TransformedImageSpanInterpolator& operator= (const TransformedImageSpanInterpolator&);
  66152. };
  66153. TransformedImageSpanInterpolator interpolator;
  66154. const Image::BitmapData& destData;
  66155. const Image::BitmapData& srcData;
  66156. const int extraAlpha;
  66157. const bool betterQuality;
  66158. const float pixelOffset;
  66159. const int pixelOffsetInt, maxX, maxY;
  66160. int y;
  66161. DestPixelType* linePixels;
  66162. HeapBlock <SrcPixelType> scratchBuffer;
  66163. int scratchSize;
  66164. TransformedImageFillEdgeTableRenderer (const TransformedImageFillEdgeTableRenderer&);
  66165. TransformedImageFillEdgeTableRenderer& operator= (const TransformedImageFillEdgeTableRenderer&);
  66166. };
  66167. class LLGCSavedState
  66168. {
  66169. public:
  66170. LLGCSavedState (const Rectangle<int>& clip_, const int xOffset_, const int yOffset_,
  66171. const Font& font_, const FillType& fillType_,
  66172. const Graphics::ResamplingQuality interpolationQuality_) throw()
  66173. : edgeTable (new EdgeTableHolder (EdgeTable (clip_))),
  66174. xOffset (xOffset_), yOffset (yOffset_),
  66175. font (font_), fillType (fillType_),
  66176. interpolationQuality (interpolationQuality_)
  66177. {
  66178. }
  66179. LLGCSavedState (const LLGCSavedState& other) throw()
  66180. : edgeTable (other.edgeTable), xOffset (other.xOffset),
  66181. yOffset (other.yOffset), font (other.font),
  66182. fillType (other.fillType), interpolationQuality (other.interpolationQuality)
  66183. {
  66184. }
  66185. ~LLGCSavedState() throw()
  66186. {
  66187. }
  66188. bool clipToRectangle (const Rectangle<int>& r) throw()
  66189. {
  66190. dupeEdgeTableIfMultiplyReferenced();
  66191. edgeTable->edgeTable.clipToRectangle (r.translated (xOffset, yOffset));
  66192. return ! edgeTable->edgeTable.isEmpty();
  66193. }
  66194. bool clipToRectangleList (const RectangleList& r) throw()
  66195. {
  66196. dupeEdgeTableIfMultiplyReferenced();
  66197. RectangleList offsetList (r);
  66198. offsetList.offsetAll (xOffset, yOffset);
  66199. EdgeTable e2 (offsetList);
  66200. edgeTable->edgeTable.clipToEdgeTable (e2);
  66201. return ! edgeTable->edgeTable.isEmpty();
  66202. }
  66203. bool excludeClipRectangle (const Rectangle<int>& r) throw()
  66204. {
  66205. dupeEdgeTableIfMultiplyReferenced();
  66206. edgeTable->edgeTable.excludeRectangle (r.translated (xOffset, yOffset));
  66207. return ! edgeTable->edgeTable.isEmpty();
  66208. }
  66209. void clipToPath (const Path& p, const AffineTransform& transform) throw()
  66210. {
  66211. dupeEdgeTableIfMultiplyReferenced();
  66212. EdgeTable et (edgeTable->edgeTable.getMaximumBounds(), p, transform.translated ((float) xOffset, (float) yOffset));
  66213. edgeTable->edgeTable.clipToEdgeTable (et);
  66214. }
  66215. void fillEdgeTable (Image& image, EdgeTable& et, const bool replaceContents = false) throw()
  66216. {
  66217. et.clipToEdgeTable (edgeTable->edgeTable);
  66218. Image::BitmapData destData (image, 0, 0, image.getWidth(), image.getHeight(), true);
  66219. if (fillType.isGradient())
  66220. {
  66221. jassert (! replaceContents); // that option is just for solid colours
  66222. ColourGradient g2 (*(fillType.gradient));
  66223. g2.multiplyOpacity (fillType.getOpacity());
  66224. g2.x1 -= 0.5f; g2.y1 -= 0.5f;
  66225. g2.x2 -= 0.5f; g2.y2 -= 0.5f;
  66226. AffineTransform transform (fillType.transform.translated ((float) xOffset, (float) yOffset));
  66227. const bool isIdentity = transform.isOnlyTranslation();
  66228. if (isIdentity)
  66229. {
  66230. // If our translation doesn't involve any distortion, we can speed it up..
  66231. transform.transformPoint (g2.x1, g2.y1);
  66232. transform.transformPoint (g2.x2, g2.y2);
  66233. transform = AffineTransform::identity;
  66234. }
  66235. HeapBlock <PixelARGB> lookupTable;
  66236. const int numLookupEntries = g2.createLookupTable (transform, lookupTable);
  66237. jassert (numLookupEntries > 0);
  66238. switch (image.getFormat())
  66239. {
  66240. case Image::ARGB: renderGradient (et, destData, g2, transform, lookupTable, numLookupEntries, isIdentity, (PixelARGB*) 0); break;
  66241. case Image::RGB: renderGradient (et, destData, g2, transform, lookupTable, numLookupEntries, isIdentity, (PixelRGB*) 0); break;
  66242. default: renderGradient (et, destData, g2, transform, lookupTable, numLookupEntries, isIdentity, (PixelAlpha*) 0); break;
  66243. }
  66244. }
  66245. else if (fillType.isTiledImage())
  66246. {
  66247. renderImage (image, *(fillType.image), fillType.image->getBounds(), fillType.transform, &et);
  66248. }
  66249. else
  66250. {
  66251. const PixelARGB fillColour (fillType.colour.getPixelARGB());
  66252. switch (image.getFormat())
  66253. {
  66254. case Image::ARGB: renderSolidFill (et, destData, fillColour, replaceContents, (PixelARGB*) 0); break;
  66255. case Image::RGB: renderSolidFill (et, destData, fillColour, replaceContents, (PixelRGB*) 0); break;
  66256. default: renderSolidFill (et, destData, fillColour, replaceContents, (PixelAlpha*) 0); break;
  66257. }
  66258. }
  66259. }
  66260. void renderImage (Image& destImage, const Image& sourceImage, const Rectangle<int>& srcClip,
  66261. const AffineTransform& t, const EdgeTable* const tiledFillClipRegion) throw()
  66262. {
  66263. const AffineTransform transform (t.translated ((float) xOffset, (float) yOffset));
  66264. const Image::BitmapData destData (destImage, 0, 0, destImage.getWidth(), destImage.getHeight(), true);
  66265. const Image::BitmapData srcData (sourceImage, srcClip.getX(), srcClip.getY(), srcClip.getWidth(), srcClip.getHeight());
  66266. const int alpha = fillType.colour.getAlpha();
  66267. const bool betterQuality = (interpolationQuality != Graphics::lowResamplingQuality);
  66268. if (transform.isOnlyTranslation())
  66269. {
  66270. // If our translation doesn't involve any distortion, just use a simple blit..
  66271. int tx = (int) (transform.getTranslationX() * 256.0f);
  66272. int ty = (int) (transform.getTranslationY() * 256.0f);
  66273. if ((! betterQuality) || ((tx | ty) & 224) == 0)
  66274. {
  66275. tx = ((tx + 128) >> 8);
  66276. ty = ((ty + 128) >> 8);
  66277. if (tiledFillClipRegion != 0)
  66278. {
  66279. blittedRenderImage (sourceImage, destImage, *tiledFillClipRegion, destData, srcData, alpha, tx, ty, true);
  66280. }
  66281. else
  66282. {
  66283. EdgeTable et (Rectangle<int> (tx, ty, srcClip.getWidth(), srcClip.getHeight()).getIntersection (destImage.getBounds()));
  66284. et.clipToEdgeTable (edgeTable->edgeTable);
  66285. if (! et.isEmpty())
  66286. blittedRenderImage (sourceImage, destImage, et, destData, srcData, alpha, tx, ty, false);
  66287. }
  66288. return;
  66289. }
  66290. }
  66291. if (transform.isSingularity())
  66292. return;
  66293. if (tiledFillClipRegion != 0)
  66294. {
  66295. transformedRenderImage (sourceImage, destImage, *tiledFillClipRegion, destData, srcData, alpha, transform, betterQuality, true);
  66296. }
  66297. else
  66298. {
  66299. Path p;
  66300. p.addRectangle (0.0f, 0.0f, (float) srcClip.getWidth(), (float) srcClip.getHeight());
  66301. EdgeTable et (edgeTable->edgeTable.getMaximumBounds(), p, transform);
  66302. et.clipToEdgeTable (edgeTable->edgeTable);
  66303. if (! et.isEmpty())
  66304. transformedRenderImage (sourceImage, destImage, et, destData, srcData, alpha, transform, betterQuality, false);
  66305. }
  66306. }
  66307. void clipToImageAlpha (const Image& image, const Rectangle<int>& srcClip, const AffineTransform& t) throw()
  66308. {
  66309. if (! image.hasAlphaChannel())
  66310. {
  66311. Path p;
  66312. p.addRectangle (srcClip);
  66313. clipToPath (p, t);
  66314. return;
  66315. }
  66316. dupeEdgeTableIfMultiplyReferenced();
  66317. const AffineTransform transform (t.translated ((float) xOffset, (float) yOffset));
  66318. const Image::BitmapData srcData (image, srcClip.getX(), srcClip.getY(), srcClip.getWidth(), srcClip.getHeight());
  66319. const bool betterQuality = (interpolationQuality != Graphics::lowResamplingQuality);
  66320. EdgeTable& et = edgeTable->edgeTable;
  66321. if (transform.isOnlyTranslation())
  66322. {
  66323. // If our translation doesn't involve any distortion, just use a simple blit..
  66324. const int tx = (int) (transform.getTranslationX() * 256.0f);
  66325. const int ty = (int) (transform.getTranslationY() * 256.0f);
  66326. if ((! betterQuality) || ((tx | ty) & 224) == 0)
  66327. {
  66328. const int imageX = ((tx + 128) >> 8);
  66329. const int imageY = ((ty + 128) >> 8);
  66330. if (image.getFormat() == Image::ARGB)
  66331. straightClipImage (et, srcData, imageX, imageY, (PixelARGB*)0);
  66332. else
  66333. straightClipImage (et, srcData, imageX, imageY, (PixelAlpha*)0);
  66334. return;
  66335. }
  66336. }
  66337. if (transform.isSingularity())
  66338. {
  66339. et.clipToRectangle (Rectangle<int>());
  66340. return;
  66341. }
  66342. {
  66343. Path p;
  66344. p.addRectangle (0, 0, (float) srcData.width, (float) srcData.height);
  66345. EdgeTable et2 (et.getMaximumBounds(), p, transform);
  66346. et.clipToEdgeTable (et2);
  66347. }
  66348. if (! et.isEmpty())
  66349. {
  66350. if (image.getFormat() == Image::ARGB)
  66351. transformedClipImage (et, srcData, transform, betterQuality, (PixelARGB*)0);
  66352. else
  66353. transformedClipImage (et, srcData, transform, betterQuality, (PixelAlpha*)0);
  66354. }
  66355. }
  66356. template <class SrcPixelType>
  66357. void transformedClipImage (EdgeTable& et, const Image::BitmapData& srcData, const AffineTransform& transform, const bool betterQuality, const SrcPixelType *) throw()
  66358. {
  66359. TransformedImageFillEdgeTableRenderer <SrcPixelType, SrcPixelType, false> renderer (srcData, srcData, transform, 255, betterQuality);
  66360. for (int y = 0; y < et.getMaximumBounds().getHeight(); ++y)
  66361. renderer.clipEdgeTableLine (et, et.getMaximumBounds().getX(), y + et.getMaximumBounds().getY(),
  66362. et.getMaximumBounds().getWidth());
  66363. }
  66364. template <class SrcPixelType>
  66365. void straightClipImage (EdgeTable& et, const Image::BitmapData& srcData, int imageX, int imageY, const SrcPixelType *) throw()
  66366. {
  66367. Rectangle<int> r (imageX, imageY, srcData.width, srcData.height);
  66368. et.clipToRectangle (r);
  66369. ImageFillEdgeTableRenderer <SrcPixelType, SrcPixelType, false> renderer (srcData, srcData, 255, imageX, imageY);
  66370. for (int y = 0; y < r.getHeight(); ++y)
  66371. renderer.clipEdgeTableLine (et, r.getX(), y + r.getY(), r.getWidth());
  66372. }
  66373. class EdgeTableHolder : public ReferenceCountedObject
  66374. {
  66375. public:
  66376. EdgeTableHolder (const EdgeTable& e) throw() : edgeTable (e) {}
  66377. EdgeTable edgeTable;
  66378. };
  66379. ReferenceCountedObjectPtr<EdgeTableHolder> edgeTable;
  66380. int xOffset, yOffset;
  66381. Font font;
  66382. FillType fillType;
  66383. Graphics::ResamplingQuality interpolationQuality;
  66384. private:
  66385. LLGCSavedState& operator= (const LLGCSavedState&);
  66386. void dupeEdgeTableIfMultiplyReferenced() throw()
  66387. {
  66388. if (edgeTable->getReferenceCount() > 1)
  66389. edgeTable = new EdgeTableHolder (edgeTable->edgeTable);
  66390. }
  66391. template <class DestPixelType>
  66392. void renderGradient (EdgeTable& et, const Image::BitmapData& destData, const ColourGradient& g, const AffineTransform& transform,
  66393. const PixelARGB* const lookupTable, const int numLookupEntries, const bool isIdentity, DestPixelType*) throw()
  66394. {
  66395. jassert (destData.pixelStride == sizeof (DestPixelType));
  66396. if (g.isRadial)
  66397. {
  66398. if (isIdentity)
  66399. {
  66400. GradientEdgeTableRenderer <DestPixelType, RadialGradientPixelGenerator> renderer (destData, g, transform, lookupTable, numLookupEntries);
  66401. et.iterate (renderer);
  66402. }
  66403. else
  66404. {
  66405. GradientEdgeTableRenderer <DestPixelType, TransformedRadialGradientPixelGenerator> renderer (destData, g, transform, lookupTable, numLookupEntries);
  66406. et.iterate (renderer);
  66407. }
  66408. }
  66409. else
  66410. {
  66411. GradientEdgeTableRenderer <DestPixelType, LinearGradientPixelGenerator> renderer (destData, g, transform, lookupTable, numLookupEntries);
  66412. et.iterate (renderer);
  66413. }
  66414. }
  66415. template <class DestPixelType>
  66416. void renderSolidFill (EdgeTable& et, const Image::BitmapData& destData, const PixelARGB& fillColour, const bool replaceContents, DestPixelType*) throw()
  66417. {
  66418. jassert (destData.pixelStride == sizeof (DestPixelType));
  66419. if (replaceContents)
  66420. {
  66421. SolidColourEdgeTableRenderer <DestPixelType, true> r (destData, fillColour);
  66422. et.iterate (r);
  66423. }
  66424. else
  66425. {
  66426. SolidColourEdgeTableRenderer <DestPixelType, false> r (destData, fillColour);
  66427. et.iterate (r);
  66428. }
  66429. }
  66430. void transformedRenderImage (const Image& srcImage, Image& destImage, const EdgeTable& et, const Image::BitmapData& destData, const Image::BitmapData& srcData,
  66431. const int alpha, const AffineTransform& transform, const bool betterQuality, const bool repeatPattern) throw()
  66432. {
  66433. switch (destImage.getFormat())
  66434. {
  66435. case Image::ARGB:
  66436. switch (srcImage.getFormat())
  66437. {
  66438. case Image::ARGB:
  66439. if (repeatPattern) { TransformedImageFillEdgeTableRenderer <PixelARGB, PixelARGB, true> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66440. else { TransformedImageFillEdgeTableRenderer <PixelARGB, PixelARGB, false> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66441. break;
  66442. case Image::RGB:
  66443. if (repeatPattern) { TransformedImageFillEdgeTableRenderer <PixelARGB, PixelRGB, true> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66444. else { TransformedImageFillEdgeTableRenderer <PixelARGB, PixelRGB, false> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66445. break;
  66446. default:
  66447. if (repeatPattern) { TransformedImageFillEdgeTableRenderer <PixelARGB, PixelAlpha, true> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66448. else { TransformedImageFillEdgeTableRenderer <PixelARGB, PixelAlpha, false> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66449. break;
  66450. }
  66451. break;
  66452. case Image::RGB:
  66453. switch (srcImage.getFormat())
  66454. {
  66455. case Image::ARGB:
  66456. if (repeatPattern) { TransformedImageFillEdgeTableRenderer <PixelRGB, PixelARGB, true> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66457. else { TransformedImageFillEdgeTableRenderer <PixelRGB, PixelARGB, false> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66458. break;
  66459. case Image::RGB:
  66460. if (repeatPattern) { TransformedImageFillEdgeTableRenderer <PixelRGB, PixelRGB, true> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66461. else { TransformedImageFillEdgeTableRenderer <PixelRGB, PixelRGB, false> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66462. break;
  66463. default:
  66464. if (repeatPattern) { TransformedImageFillEdgeTableRenderer <PixelRGB, PixelAlpha, true> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66465. else { TransformedImageFillEdgeTableRenderer <PixelRGB, PixelAlpha, false> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66466. break;
  66467. }
  66468. break;
  66469. default:
  66470. switch (srcImage.getFormat())
  66471. {
  66472. case Image::ARGB:
  66473. if (repeatPattern) { TransformedImageFillEdgeTableRenderer <PixelAlpha, PixelARGB, true> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66474. else { TransformedImageFillEdgeTableRenderer <PixelAlpha, PixelARGB, false> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66475. break;
  66476. case Image::RGB:
  66477. if (repeatPattern) { TransformedImageFillEdgeTableRenderer <PixelAlpha, PixelRGB, true> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66478. else { TransformedImageFillEdgeTableRenderer <PixelAlpha, PixelRGB, false> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66479. break;
  66480. default:
  66481. if (repeatPattern) { TransformedImageFillEdgeTableRenderer <PixelAlpha, PixelAlpha, true> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66482. else { TransformedImageFillEdgeTableRenderer <PixelAlpha, PixelAlpha, false> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66483. break;
  66484. }
  66485. break;
  66486. }
  66487. }
  66488. void blittedRenderImage (const Image& srcImage, Image& destImage, const EdgeTable& et, const Image::BitmapData& destData,
  66489. const Image::BitmapData& srcData, const int alpha, int x, int y, const bool repeatPattern) throw()
  66490. {
  66491. switch (destImage.getFormat())
  66492. {
  66493. case Image::ARGB:
  66494. switch (srcImage.getFormat())
  66495. {
  66496. case Image::ARGB:
  66497. if (repeatPattern) { ImageFillEdgeTableRenderer <PixelARGB, PixelARGB, true> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66498. else { ImageFillEdgeTableRenderer <PixelARGB, PixelARGB, false> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66499. break;
  66500. case Image::RGB:
  66501. if (repeatPattern) { ImageFillEdgeTableRenderer <PixelARGB, PixelRGB, true> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66502. else { ImageFillEdgeTableRenderer <PixelARGB, PixelRGB, false> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66503. break;
  66504. default:
  66505. if (repeatPattern) { ImageFillEdgeTableRenderer <PixelARGB, PixelAlpha, true> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66506. else { ImageFillEdgeTableRenderer <PixelARGB, PixelAlpha, false> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66507. break;
  66508. }
  66509. break;
  66510. case Image::RGB:
  66511. switch (srcImage.getFormat())
  66512. {
  66513. case Image::ARGB:
  66514. if (repeatPattern) { ImageFillEdgeTableRenderer <PixelRGB, PixelARGB, true> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66515. else { ImageFillEdgeTableRenderer <PixelRGB, PixelARGB, false> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66516. break;
  66517. case Image::RGB:
  66518. if (repeatPattern) { ImageFillEdgeTableRenderer <PixelRGB, PixelRGB, true> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66519. else { ImageFillEdgeTableRenderer <PixelRGB, PixelRGB, false> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66520. break;
  66521. default:
  66522. if (repeatPattern) { ImageFillEdgeTableRenderer <PixelRGB, PixelAlpha, true> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66523. else { ImageFillEdgeTableRenderer <PixelRGB, PixelAlpha, false> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66524. break;
  66525. }
  66526. break;
  66527. default:
  66528. switch (srcImage.getFormat())
  66529. {
  66530. case Image::ARGB:
  66531. if (repeatPattern) { ImageFillEdgeTableRenderer <PixelAlpha, PixelARGB, true> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66532. else { ImageFillEdgeTableRenderer <PixelAlpha, PixelARGB, false> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66533. break;
  66534. case Image::RGB:
  66535. if (repeatPattern) { ImageFillEdgeTableRenderer <PixelAlpha, PixelRGB, true> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66536. else { ImageFillEdgeTableRenderer <PixelAlpha, PixelRGB, false> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66537. break;
  66538. default:
  66539. if (repeatPattern) { ImageFillEdgeTableRenderer <PixelAlpha, PixelAlpha, true> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66540. else { ImageFillEdgeTableRenderer <PixelAlpha, PixelAlpha, false> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66541. break;
  66542. }
  66543. break;
  66544. }
  66545. }
  66546. };
  66547. LowLevelGraphicsSoftwareRenderer::LowLevelGraphicsSoftwareRenderer (Image& image_)
  66548. : image (image_)
  66549. {
  66550. currentState = new LLGCSavedState (image_.getBounds(), 0, 0, Font(),
  66551. FillType(), Graphics::mediumResamplingQuality);
  66552. }
  66553. LowLevelGraphicsSoftwareRenderer::~LowLevelGraphicsSoftwareRenderer()
  66554. {
  66555. }
  66556. bool LowLevelGraphicsSoftwareRenderer::isVectorDevice() const
  66557. {
  66558. return false;
  66559. }
  66560. void LowLevelGraphicsSoftwareRenderer::setOrigin (int x, int y)
  66561. {
  66562. currentState->xOffset += x;
  66563. currentState->yOffset += y;
  66564. }
  66565. bool LowLevelGraphicsSoftwareRenderer::clipToRectangle (const Rectangle<int>& r)
  66566. {
  66567. return currentState->clipToRectangle (r);
  66568. }
  66569. bool LowLevelGraphicsSoftwareRenderer::clipToRectangleList (const RectangleList& clipRegion)
  66570. {
  66571. return currentState->clipToRectangleList (clipRegion);
  66572. }
  66573. void LowLevelGraphicsSoftwareRenderer::excludeClipRectangle (const Rectangle<int>& r)
  66574. {
  66575. currentState->excludeClipRectangle (r);
  66576. }
  66577. void LowLevelGraphicsSoftwareRenderer::clipToPath (const Path& path, const AffineTransform& transform)
  66578. {
  66579. currentState->clipToPath (path, transform);
  66580. }
  66581. void LowLevelGraphicsSoftwareRenderer::clipToImageAlpha (const Image& sourceImage, const Rectangle<int>& srcClip, const AffineTransform& transform)
  66582. {
  66583. currentState->clipToImageAlpha (sourceImage, srcClip, transform);
  66584. }
  66585. bool LowLevelGraphicsSoftwareRenderer::clipRegionIntersects (const Rectangle<int>& r)
  66586. {
  66587. return currentState->edgeTable->edgeTable.getMaximumBounds()
  66588. .intersects (r.translated (currentState->xOffset, currentState->yOffset));
  66589. }
  66590. const Rectangle<int> LowLevelGraphicsSoftwareRenderer::getClipBounds() const
  66591. {
  66592. return currentState->edgeTable->edgeTable.getMaximumBounds().translated (-currentState->xOffset, -currentState->yOffset);
  66593. }
  66594. bool LowLevelGraphicsSoftwareRenderer::isClipEmpty() const
  66595. {
  66596. return currentState->edgeTable->edgeTable.isEmpty();
  66597. }
  66598. void LowLevelGraphicsSoftwareRenderer::saveState()
  66599. {
  66600. stateStack.add (new LLGCSavedState (*currentState));
  66601. }
  66602. void LowLevelGraphicsSoftwareRenderer::restoreState()
  66603. {
  66604. LLGCSavedState* const top = stateStack.getLast();
  66605. if (top != 0)
  66606. {
  66607. currentState = top;
  66608. stateStack.removeLast (1, false);
  66609. }
  66610. else
  66611. {
  66612. jassertfalse // trying to pop with an empty stack!
  66613. }
  66614. }
  66615. void LowLevelGraphicsSoftwareRenderer::setFill (const FillType& fillType)
  66616. {
  66617. currentState->fillType = fillType;
  66618. }
  66619. void LowLevelGraphicsSoftwareRenderer::setOpacity (float newOpacity)
  66620. {
  66621. currentState->fillType.setOpacity (newOpacity);
  66622. }
  66623. void LowLevelGraphicsSoftwareRenderer::setInterpolationQuality (Graphics::ResamplingQuality quality)
  66624. {
  66625. currentState->interpolationQuality = quality;
  66626. }
  66627. void LowLevelGraphicsSoftwareRenderer::fillRect (const Rectangle<int>& r, const bool replaceExistingContents)
  66628. {
  66629. const Rectangle<int>& totalClip = currentState->edgeTable->edgeTable.getMaximumBounds();
  66630. const Rectangle<int> clipped (totalClip.getIntersection (r.translated (currentState->xOffset, currentState->yOffset)));
  66631. if (! clipped.isEmpty())
  66632. {
  66633. EdgeTable et (clipped);
  66634. currentState->fillEdgeTable (image, et, replaceExistingContents);
  66635. }
  66636. }
  66637. void LowLevelGraphicsSoftwareRenderer::fillPath (const Path& path, const AffineTransform& transform)
  66638. {
  66639. EdgeTable et (currentState->edgeTable->edgeTable.getMaximumBounds(),
  66640. path, transform.translated ((float) currentState->xOffset,
  66641. (float) currentState->yOffset));
  66642. currentState->fillEdgeTable (image, et);
  66643. }
  66644. void LowLevelGraphicsSoftwareRenderer::drawImage (const Image& sourceImage, const Rectangle<int>& srcClip,
  66645. const AffineTransform& transform, const bool fillEntireClipAsTiles)
  66646. {
  66647. jassert (sourceImage.getBounds().contains (srcClip));
  66648. currentState->renderImage (image, sourceImage, srcClip, transform,
  66649. fillEntireClipAsTiles ? &(currentState->edgeTable->edgeTable) : 0);
  66650. }
  66651. void LowLevelGraphicsSoftwareRenderer::drawLine (double x1, double y1, double x2, double y2)
  66652. {
  66653. Path p;
  66654. p.addLineSegment ((float) x1, (float) y1, (float) x2, (float) y2, 1.0f);
  66655. fillPath (p, AffineTransform::identity);
  66656. }
  66657. void LowLevelGraphicsSoftwareRenderer::drawVerticalLine (const int x, double top, double bottom)
  66658. {
  66659. if (bottom > top)
  66660. {
  66661. EdgeTable et ((float) (x + currentState->xOffset), (float) (top + currentState->yOffset), 1.0f, (float) (bottom - top));
  66662. currentState->fillEdgeTable (image, et);
  66663. }
  66664. }
  66665. void LowLevelGraphicsSoftwareRenderer::drawHorizontalLine (const int y, double left, double right)
  66666. {
  66667. if (right > left)
  66668. {
  66669. EdgeTable et ((float) (left + currentState->xOffset), (float) (y + currentState->yOffset),
  66670. (float) (right - left), 1.0f);
  66671. currentState->fillEdgeTable (image, et);
  66672. }
  66673. }
  66674. class GlyphCache : private DeletedAtShutdown
  66675. {
  66676. public:
  66677. GlyphCache() throw()
  66678. : accessCounter (0), hits (0), misses (0)
  66679. {
  66680. for (int i = 120; --i >= 0;)
  66681. glyphs.add (new CachedGlyph());
  66682. }
  66683. ~GlyphCache() throw()
  66684. {
  66685. clearSingletonInstance();
  66686. }
  66687. juce_DeclareSingleton_SingleThreaded_Minimal (GlyphCache);
  66688. void drawGlyph (LLGCSavedState& state, Image& image, const Font& font, const int glyphNumber, float x, float y) throw()
  66689. {
  66690. ++accessCounter;
  66691. int oldestCounter = std::numeric_limits<int>::max();
  66692. CachedGlyph* oldest = 0;
  66693. for (int i = glyphs.size(); --i >= 0;)
  66694. {
  66695. CachedGlyph* const glyph = glyphs.getUnchecked (i);
  66696. if (glyph->glyph == glyphNumber && glyph->font == font)
  66697. {
  66698. ++hits;
  66699. glyph->lastAccessCount = accessCounter;
  66700. glyph->draw (state, image, x, y);
  66701. return;
  66702. }
  66703. if (glyph->lastAccessCount <= oldestCounter)
  66704. {
  66705. oldestCounter = glyph->lastAccessCount;
  66706. oldest = glyph;
  66707. }
  66708. }
  66709. if (hits + ++misses > (glyphs.size() << 4))
  66710. {
  66711. if (misses * 2 > hits)
  66712. {
  66713. for (int i = 32; --i >= 0;)
  66714. glyphs.add (new CachedGlyph());
  66715. }
  66716. hits = misses = 0;
  66717. oldest = glyphs.getLast();
  66718. }
  66719. jassert (oldest != 0);
  66720. oldest->lastAccessCount = accessCounter;
  66721. oldest->generate (font, glyphNumber);
  66722. oldest->draw (state, image, x, y);
  66723. }
  66724. class CachedGlyph
  66725. {
  66726. public:
  66727. CachedGlyph() : glyph (0), lastAccessCount (0) {}
  66728. ~CachedGlyph() {}
  66729. void draw (LLGCSavedState& state, Image& image, const float x, const float y) const throw()
  66730. {
  66731. if (edgeTable != 0)
  66732. {
  66733. EdgeTable et (*edgeTable);
  66734. et.translate (x, roundToInt (y));
  66735. state.fillEdgeTable (image, et, false);
  66736. }
  66737. }
  66738. void generate (const Font& newFont, const int glyphNumber) throw()
  66739. {
  66740. font = newFont;
  66741. glyph = glyphNumber;
  66742. edgeTable = 0;
  66743. Path glyphPath;
  66744. font.getTypeface()->getOutlineForGlyph (glyphNumber, glyphPath);
  66745. if (! glyphPath.isEmpty())
  66746. {
  66747. const float fontHeight = font.getHeight();
  66748. const AffineTransform transform (AffineTransform::scale (fontHeight * font.getHorizontalScale(), fontHeight)
  66749. .translated (0.0f, -0.5f));
  66750. edgeTable = new EdgeTable (glyphPath.getBoundsTransformed (transform).getSmallestIntegerContainer().expanded (1, 0),
  66751. glyphPath, transform);
  66752. }
  66753. }
  66754. int glyph, lastAccessCount;
  66755. Font font;
  66756. juce_UseDebuggingNewOperator
  66757. private:
  66758. ScopedPointer <EdgeTable> edgeTable;
  66759. CachedGlyph (const CachedGlyph&);
  66760. CachedGlyph& operator= (const CachedGlyph&);
  66761. };
  66762. juce_UseDebuggingNewOperator
  66763. private:
  66764. OwnedArray <CachedGlyph> glyphs;
  66765. int accessCounter, hits, misses;
  66766. GlyphCache (const GlyphCache&);
  66767. GlyphCache& operator= (const GlyphCache&);
  66768. };
  66769. juce_ImplementSingleton_SingleThreaded (GlyphCache);
  66770. void LowLevelGraphicsSoftwareRenderer::setFont (const Font& newFont)
  66771. {
  66772. currentState->font = newFont;
  66773. }
  66774. const Font LowLevelGraphicsSoftwareRenderer::getFont()
  66775. {
  66776. return currentState->font;
  66777. }
  66778. void LowLevelGraphicsSoftwareRenderer::drawGlyph (int glyphNumber, const AffineTransform& transform)
  66779. {
  66780. Font& f = currentState->font;
  66781. if (transform.isOnlyTranslation())
  66782. {
  66783. GlyphCache::getInstance()->drawGlyph (*currentState, image, f, glyphNumber,
  66784. transform.getTranslationX() + (float) currentState->xOffset,
  66785. transform.getTranslationY() + (float) currentState->yOffset);
  66786. }
  66787. else
  66788. {
  66789. Path p;
  66790. f.getTypeface()->getOutlineForGlyph (glyphNumber, p);
  66791. fillPath (p, AffineTransform::scale (f.getHeight() * f.getHorizontalScale(), f.getHeight()).followedBy (transform));
  66792. }
  66793. }
  66794. #if JUCE_MSVC
  66795. #pragma warning (pop)
  66796. #endif
  66797. END_JUCE_NAMESPACE
  66798. /*** End of inlined file: juce_LowLevelGraphicsSoftwareRenderer.cpp ***/
  66799. /*** Start of inlined file: juce_RectanglePlacement.cpp ***/
  66800. BEGIN_JUCE_NAMESPACE
  66801. RectanglePlacement::RectanglePlacement (const RectanglePlacement& other) throw()
  66802. : flags (other.flags)
  66803. {
  66804. }
  66805. RectanglePlacement& RectanglePlacement::operator= (const RectanglePlacement& other) throw()
  66806. {
  66807. flags = other.flags;
  66808. return *this;
  66809. }
  66810. void RectanglePlacement::applyTo (double& x, double& y,
  66811. double& w, double& h,
  66812. const double dx, const double dy,
  66813. const double dw, const double dh) const throw()
  66814. {
  66815. if (w == 0 || h == 0)
  66816. return;
  66817. if ((flags & stretchToFit) != 0)
  66818. {
  66819. x = dx;
  66820. y = dy;
  66821. w = dw;
  66822. h = dh;
  66823. }
  66824. else
  66825. {
  66826. double scale = (flags & fillDestination) != 0 ? jmax (dw / w, dh / h)
  66827. : jmin (dw / w, dh / h);
  66828. if ((flags & onlyReduceInSize) != 0)
  66829. scale = jmin (scale, 1.0);
  66830. if ((flags & onlyIncreaseInSize) != 0)
  66831. scale = jmax (scale, 1.0);
  66832. w *= scale;
  66833. h *= scale;
  66834. if ((flags & xLeft) != 0)
  66835. x = dx;
  66836. else if ((flags & xRight) != 0)
  66837. x = dx + dw - w;
  66838. else
  66839. x = dx + (dw - w) * 0.5;
  66840. if ((flags & yTop) != 0)
  66841. y = dy;
  66842. else if ((flags & yBottom) != 0)
  66843. y = dy + dh - h;
  66844. else
  66845. y = dy + (dh - h) * 0.5;
  66846. }
  66847. }
  66848. const AffineTransform RectanglePlacement::getTransformToFit (float x, float y,
  66849. float w, float h,
  66850. const float dx, const float dy,
  66851. const float dw, const float dh) const throw()
  66852. {
  66853. if (w == 0 || h == 0)
  66854. return AffineTransform::identity;
  66855. const float scaleX = dw / w;
  66856. const float scaleY = dh / h;
  66857. if ((flags & stretchToFit) != 0)
  66858. return AffineTransform::translation (-x, -y)
  66859. .scaled (scaleX, scaleY)
  66860. .translated (dx, dy);
  66861. float scale = (flags & fillDestination) != 0 ? jmax (scaleX, scaleY)
  66862. : jmin (scaleX, scaleY);
  66863. if ((flags & onlyReduceInSize) != 0)
  66864. scale = jmin (scale, 1.0f);
  66865. if ((flags & onlyIncreaseInSize) != 0)
  66866. scale = jmax (scale, 1.0f);
  66867. w *= scale;
  66868. h *= scale;
  66869. float newX = dx;
  66870. if ((flags & xRight) != 0)
  66871. newX += dw - w; // right
  66872. else if ((flags & xLeft) == 0)
  66873. newX += (dw - w) / 2.0f; // centre
  66874. float newY = dy;
  66875. if ((flags & yBottom) != 0)
  66876. newY += dh - h; // bottom
  66877. else if ((flags & yTop) == 0)
  66878. newY += (dh - h) / 2.0f; // centre
  66879. return AffineTransform::translation (-x, -y)
  66880. .scaled (scale, scale)
  66881. .translated (newX, newY);
  66882. }
  66883. END_JUCE_NAMESPACE
  66884. /*** End of inlined file: juce_RectanglePlacement.cpp ***/
  66885. /*** Start of inlined file: juce_Drawable.cpp ***/
  66886. BEGIN_JUCE_NAMESPACE
  66887. Drawable::RenderingContext::RenderingContext (Graphics& g_,
  66888. const AffineTransform& transform_,
  66889. const float opacity_) throw()
  66890. : g (g_),
  66891. transform (transform_),
  66892. opacity (opacity_)
  66893. {
  66894. }
  66895. Drawable::Drawable()
  66896. {
  66897. }
  66898. Drawable::~Drawable()
  66899. {
  66900. }
  66901. void Drawable::draw (Graphics& g, const float opacity,
  66902. const AffineTransform& transform) const
  66903. {
  66904. render (RenderingContext (g, transform, opacity));
  66905. }
  66906. void Drawable::drawAt (Graphics& g, const float x, const float y, const float opacity) const
  66907. {
  66908. draw (g, opacity, AffineTransform::translation (x, y));
  66909. }
  66910. void Drawable::drawWithin (Graphics& g,
  66911. const int destX,
  66912. const int destY,
  66913. const int destW,
  66914. const int destH,
  66915. const RectanglePlacement& placement,
  66916. const float opacity) const
  66917. {
  66918. if (destW > 0 && destH > 0)
  66919. {
  66920. Rectangle<float> bounds (getBounds());
  66921. draw (g, opacity,
  66922. placement.getTransformToFit (bounds.getX(), bounds.getY(), bounds.getWidth(), bounds.getHeight(),
  66923. (float) destX, (float) destY,
  66924. (float) destW, (float) destH));
  66925. }
  66926. }
  66927. Drawable* Drawable::createFromImageData (const void* data, const size_t numBytes)
  66928. {
  66929. Drawable* result = 0;
  66930. Image* const image = ImageFileFormat::loadFrom (data, (int) numBytes);
  66931. if (image != 0)
  66932. {
  66933. DrawableImage* const di = new DrawableImage();
  66934. di->setImage (image, true);
  66935. result = di;
  66936. }
  66937. else
  66938. {
  66939. const String asString (String::createStringFromData (data, (int) numBytes));
  66940. XmlDocument doc (asString);
  66941. ScopedPointer <XmlElement> outer (doc.getDocumentElement (true));
  66942. if (outer != 0 && outer->hasTagName (T("svg")))
  66943. {
  66944. ScopedPointer <XmlElement> svg (doc.getDocumentElement());
  66945. if (svg != 0)
  66946. result = Drawable::createFromSVG (*svg);
  66947. }
  66948. }
  66949. return result;
  66950. }
  66951. Drawable* Drawable::createFromImageDataStream (InputStream& dataSource)
  66952. {
  66953. MemoryBlock mb;
  66954. dataSource.readIntoMemoryBlock (mb);
  66955. return createFromImageData (mb.getData(), mb.getSize());
  66956. }
  66957. Drawable* Drawable::createFromImageFile (const File& file)
  66958. {
  66959. const ScopedPointer <FileInputStream> fin (file.createInputStream());
  66960. return fin != 0 ? createFromImageDataStream (*fin) : 0;
  66961. }
  66962. Drawable* Drawable::createFromValueTree (const ValueTree& tree) throw()
  66963. {
  66964. Drawable* d = DrawablePath::createFromValueTree (tree);
  66965. if (d == 0)
  66966. {
  66967. d = DrawableComposite::createFromValueTree (tree);
  66968. if (d == 0)
  66969. {
  66970. d = DrawableImage::createFromValueTree (tree);
  66971. if (d == 0)
  66972. d = DrawableText::createFromValueTree (tree);
  66973. }
  66974. }
  66975. return d;
  66976. }
  66977. END_JUCE_NAMESPACE
  66978. /*** End of inlined file: juce_Drawable.cpp ***/
  66979. /*** Start of inlined file: juce_DrawableComposite.cpp ***/
  66980. BEGIN_JUCE_NAMESPACE
  66981. DrawableComposite::DrawableComposite()
  66982. {
  66983. }
  66984. DrawableComposite::~DrawableComposite()
  66985. {
  66986. }
  66987. void DrawableComposite::insertDrawable (Drawable* drawable,
  66988. const AffineTransform& transform,
  66989. const int index)
  66990. {
  66991. if (drawable != 0)
  66992. {
  66993. if (! drawables.contains (drawable))
  66994. {
  66995. drawables.insert (index, drawable);
  66996. if (transform.isIdentity())
  66997. transforms.insert (index, 0);
  66998. else
  66999. transforms.insert (index, new AffineTransform (transform));
  67000. }
  67001. else
  67002. {
  67003. jassertfalse // trying to add a drawable that's already in here!
  67004. }
  67005. }
  67006. }
  67007. void DrawableComposite::insertDrawable (const Drawable& drawable,
  67008. const AffineTransform& transform,
  67009. const int index)
  67010. {
  67011. insertDrawable (drawable.createCopy(), transform, index);
  67012. }
  67013. void DrawableComposite::removeDrawable (const int index, const bool deleteDrawable)
  67014. {
  67015. drawables.remove (index, deleteDrawable);
  67016. transforms.remove (index);
  67017. }
  67018. void DrawableComposite::bringToFront (const int index)
  67019. {
  67020. if (index >= 0 && index < drawables.size() - 1)
  67021. {
  67022. drawables.move (index, -1);
  67023. transforms.move (index, -1);
  67024. }
  67025. }
  67026. void DrawableComposite::render (const Drawable::RenderingContext& context) const
  67027. {
  67028. if (drawables.size() > 0 && context.opacity > 0)
  67029. {
  67030. if (context.opacity >= 1.0f || drawables.size() == 1)
  67031. {
  67032. Drawable::RenderingContext contextCopy (context);
  67033. for (int i = 0; i < drawables.size(); ++i)
  67034. {
  67035. const AffineTransform* const t = transforms.getUnchecked(i);
  67036. contextCopy.transform = (t == 0) ? context.transform
  67037. : t->followedBy (context.transform);
  67038. drawables.getUnchecked(i)->render (contextCopy);
  67039. }
  67040. }
  67041. else
  67042. {
  67043. // To correctly render a whole composite layer with an overall transparency,
  67044. // we need to render everything opaquely into a temp buffer, then blend that
  67045. // with the target opacity...
  67046. const Rectangle<int> clipBounds (context.g.getClipBounds());
  67047. Image tempImage (Image::ARGB, clipBounds.getWidth(), clipBounds.getHeight(), true);
  67048. {
  67049. Graphics tempG (tempImage);
  67050. tempG.setOrigin (-clipBounds.getX(), -clipBounds.getY());
  67051. Drawable::RenderingContext tempContext (tempG, context.transform, 1.0f);
  67052. render (tempContext);
  67053. }
  67054. context.g.setOpacity (context.opacity);
  67055. context.g.drawImageAt (&tempImage, clipBounds.getX(), clipBounds.getY());
  67056. }
  67057. }
  67058. }
  67059. const Rectangle<float> DrawableComposite::getBounds() const
  67060. {
  67061. Rectangle<float> bounds;
  67062. for (int i = 0; i < drawables.size(); ++i)
  67063. {
  67064. const Drawable* const d = drawables.getUnchecked(i);
  67065. const AffineTransform* const t = transforms.getUnchecked(i);
  67066. const Rectangle<float> childBounds (t == 0 ? d->getBounds()
  67067. : d->getBounds().transformed (*t));
  67068. if (bounds.isEmpty())
  67069. bounds = childBounds;
  67070. else if (! childBounds.isEmpty())
  67071. bounds = bounds.getUnion (childBounds);
  67072. }
  67073. return bounds;
  67074. }
  67075. bool DrawableComposite::hitTest (float x, float y) const
  67076. {
  67077. for (int i = 0; i < drawables.size(); ++i)
  67078. {
  67079. float tx = x;
  67080. float ty = y;
  67081. const AffineTransform* const t = transforms.getUnchecked(i);
  67082. if (t != 0)
  67083. t->inverted().transformPoint (tx, ty);
  67084. if (drawables.getUnchecked(i)->hitTest (tx, ty))
  67085. return true;
  67086. }
  67087. return false;
  67088. }
  67089. Drawable* DrawableComposite::createCopy() const
  67090. {
  67091. DrawableComposite* const dc = new DrawableComposite();
  67092. for (int i = 0; i < drawables.size(); ++i)
  67093. {
  67094. dc->drawables.add (drawables.getUnchecked(i)->createCopy());
  67095. const AffineTransform* const t = transforms.getUnchecked(i);
  67096. dc->transforms.add (t != 0 ? new AffineTransform (*t) : 0);
  67097. }
  67098. return dc;
  67099. }
  67100. ValueTree DrawableComposite::createValueTree() const throw()
  67101. {
  67102. ValueTree v (T("Group"));
  67103. if (getName().isNotEmpty())
  67104. v.setProperty ("id", getName(), 0);
  67105. for (int i = 0; i < drawables.size(); ++i)
  67106. {
  67107. Drawable* const d = drawables.getUnchecked(i);
  67108. ValueTree child (d->createValueTree());
  67109. AffineTransform* transform = transforms.getUnchecked(i);
  67110. if (transform != 0)
  67111. {
  67112. String t;
  67113. t << transform->mat00 << " " << transform->mat01 << " " << transform->mat02 << " "
  67114. << transform->mat10 << " " << transform->mat11 << " " << transform->mat12;
  67115. child.setProperty ("transform", t, 0);
  67116. }
  67117. v.addChild (child, -1, 0);
  67118. }
  67119. return v;
  67120. }
  67121. DrawableComposite* DrawableComposite::createFromValueTree (const ValueTree& tree) throw()
  67122. {
  67123. if (! tree.hasType ("Group"))
  67124. return 0;
  67125. DrawableComposite* dc = new DrawableComposite();
  67126. dc->setName (tree ["id"]);
  67127. for (int i = 0; i < tree.getNumChildren(); ++i)
  67128. {
  67129. ValueTree childTree (tree.getChild (i));
  67130. Drawable* d = Drawable::createFromValueTree (childTree);
  67131. if (d != 0)
  67132. {
  67133. AffineTransform transform;
  67134. const String transformAtt (childTree ["transform"].toString());
  67135. if (transformAtt.isNotEmpty())
  67136. {
  67137. StringArray tokens;
  67138. tokens.addTokens (transformAtt.trim(), false);
  67139. tokens.removeEmptyStrings (true);
  67140. if (tokens.size() == 6)
  67141. {
  67142. float f[6];
  67143. for (int j = 0; j < 6; ++j)
  67144. f[j] = (float) tokens[j].getDoubleValue();
  67145. transform = AffineTransform (f[0], f[1], f[2], f[3], f[4], f[5]);
  67146. }
  67147. }
  67148. dc->insertDrawable (d, transform);
  67149. }
  67150. }
  67151. return dc;
  67152. }
  67153. END_JUCE_NAMESPACE
  67154. /*** End of inlined file: juce_DrawableComposite.cpp ***/
  67155. /*** Start of inlined file: juce_DrawableImage.cpp ***/
  67156. BEGIN_JUCE_NAMESPACE
  67157. DrawableImage::DrawableImage()
  67158. : image (0),
  67159. canDeleteImage (false),
  67160. opacity (1.0f),
  67161. overlayColour (0x00000000)
  67162. {
  67163. }
  67164. DrawableImage::~DrawableImage()
  67165. {
  67166. clearImage();
  67167. }
  67168. void DrawableImage::clearImage()
  67169. {
  67170. if (canDeleteImage && image != 0)
  67171. ImageCache::releaseOrDelete (image);
  67172. image = 0;
  67173. }
  67174. void DrawableImage::setImage (const Image& imageToCopy)
  67175. {
  67176. clearImage();
  67177. image = new Image (imageToCopy);
  67178. canDeleteImage = true;
  67179. }
  67180. void DrawableImage::setImage (Image* imageToUse,
  67181. const bool releaseWhenNotNeeded)
  67182. {
  67183. clearImage();
  67184. image = imageToUse;
  67185. canDeleteImage = releaseWhenNotNeeded;
  67186. }
  67187. void DrawableImage::setOpacity (const float newOpacity)
  67188. {
  67189. opacity = newOpacity;
  67190. }
  67191. void DrawableImage::setOverlayColour (const Colour& newOverlayColour)
  67192. {
  67193. overlayColour = newOverlayColour;
  67194. }
  67195. void DrawableImage::render (const Drawable::RenderingContext& context) const
  67196. {
  67197. if (image != 0)
  67198. {
  67199. if (opacity > 0.0f && ! overlayColour.isOpaque())
  67200. {
  67201. context.g.setOpacity (context.opacity * opacity);
  67202. context.g.drawImageTransformed (image, image->getBounds(),
  67203. context.transform, false);
  67204. }
  67205. if (! overlayColour.isTransparent())
  67206. {
  67207. context.g.setColour (overlayColour.withMultipliedAlpha (context.opacity));
  67208. context.g.drawImageTransformed (image, image->getBounds(),
  67209. context.transform, true);
  67210. }
  67211. }
  67212. }
  67213. const Rectangle<float> DrawableImage::getBounds() const
  67214. {
  67215. if (image == 0)
  67216. return Rectangle<float>();
  67217. return Rectangle<float> (0, 0, (float) image->getWidth(), (float) image->getHeight());
  67218. }
  67219. bool DrawableImage::hitTest (float x, float y) const
  67220. {
  67221. return image != 0
  67222. && x >= 0.0f
  67223. && y >= 0.0f
  67224. && x < image->getWidth()
  67225. && y < image->getHeight()
  67226. && image->getPixelAt (roundToInt (x), roundToInt (y)).getAlpha() >= 127;
  67227. }
  67228. Drawable* DrawableImage::createCopy() const
  67229. {
  67230. DrawableImage* const di = new DrawableImage();
  67231. di->opacity = opacity;
  67232. di->overlayColour = overlayColour;
  67233. if (image != 0)
  67234. {
  67235. if ((! canDeleteImage) || ! ImageCache::isImageInCache (image))
  67236. {
  67237. di->setImage (*image);
  67238. }
  67239. else
  67240. {
  67241. ImageCache::incReferenceCount (image);
  67242. di->setImage (image, true);
  67243. }
  67244. }
  67245. return di;
  67246. }
  67247. ValueTree DrawableImage::createValueTree() const throw()
  67248. {
  67249. ValueTree v (T("Image"));
  67250. if (getName().isNotEmpty())
  67251. v.setProperty ("id", getName(), 0);
  67252. if (opacity < 1.0f)
  67253. v.setProperty ("opacity", (double) opacity, 0);
  67254. if (! overlayColour.isTransparent())
  67255. v.setProperty ("overlay", String::toHexString ((int) overlayColour.getARGB()), 0);
  67256. if (image != 0)
  67257. {
  67258. MemoryOutputStream imageData;
  67259. PNGImageFormat pngFormat;
  67260. if (pngFormat.writeImageToStream (*image, imageData))
  67261. {
  67262. String base64 (MemoryBlock (imageData.getData(), imageData.getDataSize()).toBase64Encoding());
  67263. for (int i = (base64.length() & ~127); i >= 0; i -= 128)
  67264. base64 = base64.substring (0, i) + "\n" + base64.substring (i);
  67265. v.setProperty ("data", base64, 0);
  67266. }
  67267. }
  67268. return v;
  67269. }
  67270. DrawableImage* DrawableImage::createFromValueTree (const ValueTree& tree) throw()
  67271. {
  67272. if (! tree.hasType ("Image"))
  67273. return 0;
  67274. DrawableImage* di = new DrawableImage();
  67275. di->setName (tree ["id"]);
  67276. di->opacity = tree.hasProperty ("opacity") ? (float) tree ["opacity"] : 1.0f;
  67277. di->overlayColour = Colour (tree ["overlay"].toString().getHexValue32());
  67278. MemoryBlock imageData;
  67279. if (imageData.fromBase64Encoding (tree ["data"]))
  67280. {
  67281. Image* const im = ImageFileFormat::loadFrom (imageData.getData(), (int) imageData.getSize());
  67282. if (im == 0)
  67283. return false;
  67284. di->setImage (im, true);
  67285. }
  67286. return di;
  67287. }
  67288. END_JUCE_NAMESPACE
  67289. /*** End of inlined file: juce_DrawableImage.cpp ***/
  67290. /*** Start of inlined file: juce_DrawablePath.cpp ***/
  67291. BEGIN_JUCE_NAMESPACE
  67292. DrawablePath::DrawablePath()
  67293. : mainFill (FillType (Colours::black)),
  67294. strokeFill (FillType (Colours::transparentBlack)),
  67295. strokeType (0.0f)
  67296. {
  67297. }
  67298. DrawablePath::~DrawablePath()
  67299. {
  67300. }
  67301. void DrawablePath::setPath (const Path& newPath) throw()
  67302. {
  67303. path = newPath;
  67304. updateOutline();
  67305. }
  67306. void DrawablePath::setFill (const FillType& newFill) throw()
  67307. {
  67308. mainFill = newFill;
  67309. }
  67310. void DrawablePath::setStrokeFill (const FillType& newFill) throw()
  67311. {
  67312. strokeFill = newFill;
  67313. }
  67314. void DrawablePath::setStrokeType (const PathStrokeType& newStrokeType) throw()
  67315. {
  67316. strokeType = newStrokeType;
  67317. updateOutline();
  67318. }
  67319. void DrawablePath::setStrokeThickness (const float newThickness) throw()
  67320. {
  67321. setStrokeType (PathStrokeType (newThickness, strokeType.getJointStyle(), strokeType.getEndStyle()));
  67322. }
  67323. void DrawablePath::render (const Drawable::RenderingContext& context) const
  67324. {
  67325. {
  67326. FillType f (mainFill);
  67327. if (f.isGradient())
  67328. f.gradient->multiplyOpacity (context.opacity);
  67329. f.transform = f.transform.followedBy (context.transform);
  67330. context.g.setFillType (f);
  67331. context.g.fillPath (path, context.transform);
  67332. }
  67333. if (strokeType.getStrokeThickness() > 0.0f)
  67334. {
  67335. FillType f (strokeFill);
  67336. if (f.isGradient())
  67337. f.gradient->multiplyOpacity (context.opacity);
  67338. f.transform = f.transform.followedBy (context.transform);
  67339. context.g.setFillType (f);
  67340. context.g.fillPath (stroke, context.transform);
  67341. }
  67342. }
  67343. void DrawablePath::updateOutline()
  67344. {
  67345. stroke.clear();
  67346. strokeType.createStrokedPath (stroke, path, AffineTransform::identity, 4.0f);
  67347. }
  67348. const Rectangle<float> DrawablePath::getBounds() const
  67349. {
  67350. if (strokeType.getStrokeThickness() > 0.0f)
  67351. return stroke.getBounds();
  67352. else
  67353. return path.getBounds();
  67354. }
  67355. bool DrawablePath::hitTest (float x, float y) const
  67356. {
  67357. return path.contains (x, y)
  67358. || stroke.contains (x, y);
  67359. }
  67360. Drawable* DrawablePath::createCopy() const
  67361. {
  67362. DrawablePath* const dp = new DrawablePath();
  67363. dp->path = path;
  67364. dp->stroke = stroke;
  67365. dp->mainFill = mainFill;
  67366. dp->strokeFill = strokeFill;
  67367. dp->strokeType = strokeType;
  67368. return dp;
  67369. }
  67370. static const FillType readFillTypeFromTree (const ValueTree& v)
  67371. {
  67372. const String type (v["type"].toString());
  67373. if (type.equalsIgnoreCase (T("solid")))
  67374. {
  67375. const String colour (v ["colour"].toString());
  67376. return FillType (Colour (colour.isEmpty() ? (uint32) 0xff000000
  67377. : (uint32) colour.getHexValue32()));
  67378. }
  67379. else if (type.equalsIgnoreCase ("gradient"))
  67380. {
  67381. ColourGradient g;
  67382. g.x1 = v["x1"];
  67383. g.y1 = v["y1"];
  67384. g.x2 = v["x2"];
  67385. g.y2 = v["y2"];
  67386. g.isRadial = v["radial"];
  67387. StringArray colours;
  67388. colours.addTokens (v["colours"].toString(), false);
  67389. for (int i = 0; i < colours.size() / 2; ++i)
  67390. g.addColour (colours[i * 2].getDoubleValue(),
  67391. Colour ((uint32) colours[i * 2 + 1].getHexValue32()));
  67392. return FillType (g);
  67393. }
  67394. jassertfalse
  67395. return FillType();
  67396. }
  67397. static ValueTree createTreeForFillType (const String& tagName, const FillType& fillType)
  67398. {
  67399. ValueTree v (tagName);
  67400. if (fillType.isColour())
  67401. {
  67402. v.setProperty ("type", T("solid"), 0);
  67403. v.setProperty ("colour", String::toHexString ((int) fillType.colour.getARGB()), 0);
  67404. }
  67405. else if (fillType.isGradient())
  67406. {
  67407. v.setProperty ("type", T("gradient"), 0);
  67408. v.setProperty ("x1", fillType.gradient->x1, 0);
  67409. v.setProperty ("y1", fillType.gradient->y1, 0);
  67410. v.setProperty ("x2", fillType.gradient->x2, 0);
  67411. v.setProperty ("y2", fillType.gradient->y2, 0);
  67412. v.setProperty ("radial", fillType.gradient->isRadial, 0);
  67413. String s;
  67414. for (int i = 0; i < fillType.gradient->getNumColours(); ++i)
  67415. s << " " << fillType.gradient->getColourPosition (i)
  67416. << " " << String::toHexString ((int) fillType.gradient->getColour(i).getARGB());
  67417. v.setProperty ("colours", s.trimStart(), 0);
  67418. }
  67419. else
  67420. {
  67421. jassertfalse //xxx
  67422. }
  67423. return v;
  67424. }
  67425. ValueTree DrawablePath::createValueTree() const throw()
  67426. {
  67427. ValueTree v (T("Path"));
  67428. v.addChild (createTreeForFillType (T("fill"), mainFill), -1, 0);
  67429. v.addChild (createTreeForFillType (T("stroke"), strokeFill), -1, 0);
  67430. if (getName().isNotEmpty())
  67431. v.setProperty ("id", getName(), 0);
  67432. v.setProperty ("strokeWidth", (double) strokeType.getStrokeThickness(), 0);
  67433. v.setProperty ("jointStyle", strokeType.getJointStyle() == PathStrokeType::mitered
  67434. ? T("miter") : (strokeType.getJointStyle() == PathStrokeType::curved ? T("curved") : T("bevel")), 0);
  67435. v.setProperty ("capStyle", strokeType.getEndStyle() == PathStrokeType::butt
  67436. ? T("butt") : (strokeType.getEndStyle() == PathStrokeType::square ? T("square") : T("round")), 0);
  67437. v.setProperty ("path", path.toString(), 0);
  67438. return v;
  67439. }
  67440. DrawablePath* DrawablePath::createFromValueTree (const ValueTree& tree) throw()
  67441. {
  67442. if (! tree.hasType ("Path"))
  67443. return 0;
  67444. DrawablePath* p = new DrawablePath();
  67445. p->setName (tree ["id"]);
  67446. p->mainFill = readFillTypeFromTree (tree.getChildWithName (T("fill")));
  67447. p->strokeFill = readFillTypeFromTree (tree.getChildWithName (T("stroke")));
  67448. const String jointStyle (tree ["jointStyle"].toString());
  67449. const String endStyle (tree ["capStyle"].toString());
  67450. p->strokeType
  67451. = PathStrokeType (tree ["strokeWidth"],
  67452. jointStyle.equalsIgnoreCase (T("curved")) ? PathStrokeType::curved
  67453. : (jointStyle.equalsIgnoreCase (T("bevel")) ? PathStrokeType::beveled
  67454. : PathStrokeType::mitered),
  67455. endStyle.equalsIgnoreCase (T("square")) ? PathStrokeType::square
  67456. : (endStyle.equalsIgnoreCase (T("round")) ? PathStrokeType::rounded
  67457. : PathStrokeType::butt));
  67458. p->path.clear();
  67459. p->path.restoreFromString (tree ["path"]);
  67460. p->updateOutline();
  67461. return p;
  67462. }
  67463. END_JUCE_NAMESPACE
  67464. /*** End of inlined file: juce_DrawablePath.cpp ***/
  67465. /*** Start of inlined file: juce_DrawableText.cpp ***/
  67466. BEGIN_JUCE_NAMESPACE
  67467. DrawableText::DrawableText()
  67468. : colour (Colours::white)
  67469. {
  67470. }
  67471. DrawableText::~DrawableText()
  67472. {
  67473. }
  67474. void DrawableText::setText (const GlyphArrangement& newText)
  67475. {
  67476. text = newText;
  67477. }
  67478. void DrawableText::setText (const String& newText, const Font& fontToUse)
  67479. {
  67480. text.clear();
  67481. text.addLineOfText (fontToUse, newText, 0.0f, 0.0f);
  67482. }
  67483. void DrawableText::setColour (const Colour& newColour)
  67484. {
  67485. colour = newColour;
  67486. }
  67487. void DrawableText::render (const Drawable::RenderingContext& context) const
  67488. {
  67489. context.g.setColour (colour.withMultipliedAlpha (context.opacity));
  67490. text.draw (context.g, context.transform);
  67491. }
  67492. const Rectangle<float> DrawableText::getBounds() const
  67493. {
  67494. float x, y, w, h;
  67495. text.getBoundingBox (0, -1, x, y, w, h, false); // (really returns top, left, bottom, right)
  67496. w -= x;
  67497. h -= y;
  67498. return Rectangle<float> (x, y, w, h);
  67499. }
  67500. bool DrawableText::hitTest (float x, float y) const
  67501. {
  67502. return text.findGlyphIndexAt (x, y) >= 0;
  67503. }
  67504. Drawable* DrawableText::createCopy() const
  67505. {
  67506. DrawableText* const dt = new DrawableText();
  67507. dt->text = text;
  67508. dt->colour = colour;
  67509. return dt;
  67510. }
  67511. ValueTree DrawableText::createValueTree() const throw()
  67512. {
  67513. ValueTree v (T("Text"));
  67514. if (getName().isNotEmpty())
  67515. v.setProperty ("id", getName(), 0);
  67516. jassertfalse // xxx not finished!
  67517. return v;
  67518. }
  67519. DrawableText* DrawableText::createFromValueTree (const ValueTree& tree) throw()
  67520. {
  67521. if (! tree.hasType ("Text"))
  67522. return 0;
  67523. DrawableText* dt = new DrawableText();
  67524. dt->setName (tree ["id"]);
  67525. jassertfalse // xxx not finished!
  67526. return dt;
  67527. }
  67528. END_JUCE_NAMESPACE
  67529. /*** End of inlined file: juce_DrawableText.cpp ***/
  67530. /*** Start of inlined file: juce_SVGParser.cpp ***/
  67531. BEGIN_JUCE_NAMESPACE
  67532. class SVGState
  67533. {
  67534. public:
  67535. SVGState (const XmlElement* const topLevel)
  67536. : topLevelXml (topLevel),
  67537. elementX (0), elementY (0),
  67538. width (512), height (512),
  67539. viewBoxW (0), viewBoxH (0)
  67540. {
  67541. }
  67542. ~SVGState()
  67543. {
  67544. }
  67545. Drawable* parseSVGElement (const XmlElement& xml)
  67546. {
  67547. if (! xml.hasTagName (T("svg")))
  67548. return 0;
  67549. DrawableComposite* const drawable = new DrawableComposite();
  67550. drawable->setName (xml.getStringAttribute (T("id")));
  67551. SVGState newState (*this);
  67552. if (xml.hasAttribute (T("transform")))
  67553. newState.addTransform (xml);
  67554. newState.elementX = getCoordLength (xml.getStringAttribute (T("x"), String (newState.elementX)), viewBoxW);
  67555. newState.elementY = getCoordLength (xml.getStringAttribute (T("y"), String (newState.elementY)), viewBoxH);
  67556. newState.width = getCoordLength (xml.getStringAttribute (T("width"), String (newState.width)), viewBoxW);
  67557. newState.height = getCoordLength (xml.getStringAttribute (T("height"), String (newState.height)), viewBoxH);
  67558. if (xml.hasAttribute (T("viewBox")))
  67559. {
  67560. const String viewParams (xml.getStringAttribute (T("viewBox")));
  67561. int i = 0;
  67562. float vx, vy, vw, vh;
  67563. if (parseCoords (viewParams, vx, vy, i, true)
  67564. && parseCoords (viewParams, vw, vh, i, true)
  67565. && vw > 0
  67566. && vh > 0)
  67567. {
  67568. newState.viewBoxW = vw;
  67569. newState.viewBoxH = vh;
  67570. int placementFlags = 0;
  67571. const String aspect (xml.getStringAttribute (T("preserveAspectRatio")));
  67572. if (aspect.containsIgnoreCase (T("none")))
  67573. {
  67574. placementFlags = RectanglePlacement::stretchToFit;
  67575. }
  67576. else
  67577. {
  67578. if (aspect.containsIgnoreCase (T("slice")))
  67579. placementFlags |= RectanglePlacement::fillDestination;
  67580. if (aspect.containsIgnoreCase (T("xMin")))
  67581. placementFlags |= RectanglePlacement::xLeft;
  67582. else if (aspect.containsIgnoreCase (T("xMax")))
  67583. placementFlags |= RectanglePlacement::xRight;
  67584. else
  67585. placementFlags |= RectanglePlacement::xMid;
  67586. if (aspect.containsIgnoreCase (T("yMin")))
  67587. placementFlags |= RectanglePlacement::yTop;
  67588. else if (aspect.containsIgnoreCase (T("yMax")))
  67589. placementFlags |= RectanglePlacement::yBottom;
  67590. else
  67591. placementFlags |= RectanglePlacement::yMid;
  67592. }
  67593. const RectanglePlacement placement (placementFlags);
  67594. newState.transform
  67595. = placement.getTransformToFit (vx, vy, vw, vh,
  67596. 0.0f, 0.0f, newState.width, newState.height)
  67597. .followedBy (newState.transform);
  67598. }
  67599. }
  67600. else
  67601. {
  67602. if (viewBoxW == 0)
  67603. newState.viewBoxW = newState.width;
  67604. if (viewBoxH == 0)
  67605. newState.viewBoxH = newState.height;
  67606. }
  67607. newState.parseSubElements (xml, drawable);
  67608. return drawable;
  67609. }
  67610. private:
  67611. const XmlElement* const topLevelXml;
  67612. float elementX, elementY, width, height, viewBoxW, viewBoxH;
  67613. AffineTransform transform;
  67614. String cssStyleText;
  67615. void parseSubElements (const XmlElement& xml, DrawableComposite* const parentDrawable)
  67616. {
  67617. forEachXmlChildElement (xml, e)
  67618. {
  67619. Drawable* d = 0;
  67620. if (e->hasTagName (T("g")))
  67621. d = parseGroupElement (*e);
  67622. else if (e->hasTagName (T("svg")))
  67623. d = parseSVGElement (*e);
  67624. else if (e->hasTagName (T("path")))
  67625. d = parsePath (*e);
  67626. else if (e->hasTagName (T("rect")))
  67627. d = parseRect (*e);
  67628. else if (e->hasTagName (T("circle")))
  67629. d = parseCircle (*e);
  67630. else if (e->hasTagName (T("ellipse")))
  67631. d = parseEllipse (*e);
  67632. else if (e->hasTagName (T("line")))
  67633. d = parseLine (*e);
  67634. else if (e->hasTagName (T("polyline")))
  67635. d = parsePolygon (*e, true);
  67636. else if (e->hasTagName (T("polygon")))
  67637. d = parsePolygon (*e, false);
  67638. else if (e->hasTagName (T("text")))
  67639. d = parseText (*e);
  67640. else if (e->hasTagName (T("switch")))
  67641. d = parseSwitch (*e);
  67642. else if (e->hasTagName (T("style")))
  67643. parseCSSStyle (*e);
  67644. parentDrawable->insertDrawable (d);
  67645. }
  67646. }
  67647. DrawableComposite* parseSwitch (const XmlElement& xml)
  67648. {
  67649. const XmlElement* const group = xml.getChildByName (T("g"));
  67650. if (group != 0)
  67651. return parseGroupElement (*group);
  67652. return 0;
  67653. }
  67654. DrawableComposite* parseGroupElement (const XmlElement& xml)
  67655. {
  67656. DrawableComposite* const drawable = new DrawableComposite();
  67657. drawable->setName (xml.getStringAttribute (T("id")));
  67658. if (xml.hasAttribute (T("transform")))
  67659. {
  67660. SVGState newState (*this);
  67661. newState.addTransform (xml);
  67662. newState.parseSubElements (xml, drawable);
  67663. }
  67664. else
  67665. {
  67666. parseSubElements (xml, drawable);
  67667. }
  67668. return drawable;
  67669. }
  67670. Drawable* parsePath (const XmlElement& xml) const
  67671. {
  67672. const String d (xml.getStringAttribute (T("d")).trimStart());
  67673. Path path;
  67674. if (getStyleAttribute (&xml, T("fill-rule")).trim().equalsIgnoreCase (T("evenodd")))
  67675. path.setUsingNonZeroWinding (false);
  67676. int index = 0;
  67677. float lastX = 0, lastY = 0;
  67678. float lastX2 = 0, lastY2 = 0;
  67679. tchar lastCommandChar = 0;
  67680. bool isRelative = true;
  67681. bool carryOn = true;
  67682. const String validCommandChars (T("MmLlHhVvCcSsQqTtAaZz"));
  67683. for (;;)
  67684. {
  67685. float x, y, x2, y2, x3, y3;
  67686. if (validCommandChars.containsChar (d[index]))
  67687. {
  67688. lastCommandChar = d [index++];
  67689. isRelative = (lastCommandChar >= 'a' && lastCommandChar <= 'z');
  67690. }
  67691. switch (lastCommandChar)
  67692. {
  67693. case T('M'):
  67694. case T('m'):
  67695. case T('L'):
  67696. case T('l'):
  67697. if (parseCoords (d, x, y, index, false))
  67698. {
  67699. if (isRelative)
  67700. {
  67701. x += lastX;
  67702. y += lastY;
  67703. }
  67704. if (lastCommandChar == T('M') || lastCommandChar == T('m'))
  67705. path.startNewSubPath (x, y);
  67706. else
  67707. path.lineTo (x, y);
  67708. lastX2 = lastX;
  67709. lastY2 = lastY;
  67710. lastX = x;
  67711. lastY = y;
  67712. }
  67713. else
  67714. {
  67715. ++index;
  67716. }
  67717. break;
  67718. case T('H'):
  67719. case T('h'):
  67720. if (parseCoord (d, x, index, false, true))
  67721. {
  67722. if (isRelative)
  67723. x += lastX;
  67724. path.lineTo (x, lastY);
  67725. lastX2 = lastX;
  67726. lastX = x;
  67727. }
  67728. else
  67729. {
  67730. ++index;
  67731. }
  67732. break;
  67733. case T('V'):
  67734. case T('v'):
  67735. if (parseCoord (d, y, index, false, false))
  67736. {
  67737. if (isRelative)
  67738. y += lastY;
  67739. path.lineTo (lastX, y);
  67740. lastY2 = lastY;
  67741. lastY = y;
  67742. }
  67743. else
  67744. {
  67745. ++index;
  67746. }
  67747. break;
  67748. case T('C'):
  67749. case T('c'):
  67750. if (parseCoords (d, x, y, index, false)
  67751. && parseCoords (d, x2, y2, index, false)
  67752. && parseCoords (d, x3, y3, index, false))
  67753. {
  67754. if (isRelative)
  67755. {
  67756. x += lastX;
  67757. y += lastY;
  67758. x2 += lastX;
  67759. y2 += lastY;
  67760. x3 += lastX;
  67761. y3 += lastY;
  67762. }
  67763. path.cubicTo (x, y, x2, y2, x3, y3);
  67764. lastX2 = x2;
  67765. lastY2 = y2;
  67766. lastX = x3;
  67767. lastY = y3;
  67768. }
  67769. else
  67770. {
  67771. ++index;
  67772. }
  67773. break;
  67774. case T('S'):
  67775. case T('s'):
  67776. if (parseCoords (d, x, y, index, false)
  67777. && parseCoords (d, x3, y3, index, false))
  67778. {
  67779. if (isRelative)
  67780. {
  67781. x += lastX;
  67782. y += lastY;
  67783. x3 += lastX;
  67784. y3 += lastY;
  67785. }
  67786. x2 = lastX + (lastX - lastX2);
  67787. y2 = lastY + (lastY - lastY2);
  67788. path.cubicTo (x2, y2, x, y, x3, y3);
  67789. lastX2 = x;
  67790. lastY2 = y;
  67791. lastX = x3;
  67792. lastY = y3;
  67793. }
  67794. else
  67795. {
  67796. ++index;
  67797. }
  67798. break;
  67799. case T('Q'):
  67800. case T('q'):
  67801. if (parseCoords (d, x, y, index, false)
  67802. && parseCoords (d, x2, y2, index, false))
  67803. {
  67804. if (isRelative)
  67805. {
  67806. x += lastX;
  67807. y += lastY;
  67808. x2 += lastX;
  67809. y2 += lastY;
  67810. }
  67811. path.quadraticTo (x, y, x2, y2);
  67812. lastX2 = x;
  67813. lastY2 = y;
  67814. lastX = x2;
  67815. lastY = y2;
  67816. }
  67817. else
  67818. {
  67819. ++index;
  67820. }
  67821. break;
  67822. case T('T'):
  67823. case T('t'):
  67824. if (parseCoords (d, x, y, index, false))
  67825. {
  67826. if (isRelative)
  67827. {
  67828. x += lastX;
  67829. y += lastY;
  67830. }
  67831. x2 = lastX + (lastX - lastX2);
  67832. y2 = lastY + (lastY - lastY2);
  67833. path.quadraticTo (x2, y2, x, y);
  67834. lastX2 = x2;
  67835. lastY2 = y2;
  67836. lastX = x;
  67837. lastY = y;
  67838. }
  67839. else
  67840. {
  67841. ++index;
  67842. }
  67843. break;
  67844. case T('A'):
  67845. case T('a'):
  67846. if (parseCoords (d, x, y, index, false))
  67847. {
  67848. String num;
  67849. if (parseNextNumber (d, num, index, false))
  67850. {
  67851. const float angle = num.getFloatValue() * (180.0f / float_Pi);
  67852. if (parseNextNumber (d, num, index, false))
  67853. {
  67854. const bool largeArc = num.getIntValue() != 0;
  67855. if (parseNextNumber (d, num, index, false))
  67856. {
  67857. const bool sweep = num.getIntValue() != 0;
  67858. if (parseCoords (d, x2, y2, index, false))
  67859. {
  67860. if (isRelative)
  67861. {
  67862. x2 += lastX;
  67863. y2 += lastY;
  67864. }
  67865. if (lastX != x2 || lastY != y2)
  67866. {
  67867. double centreX, centreY, startAngle, deltaAngle;
  67868. double rx = x, ry = y;
  67869. endpointToCentreParameters (lastX, lastY, x2, y2,
  67870. angle, largeArc, sweep,
  67871. rx, ry, centreX, centreY,
  67872. startAngle, deltaAngle);
  67873. path.addCentredArc ((float) centreX, (float) centreY,
  67874. (float) rx, (float) ry,
  67875. angle, (float) startAngle, (float) (startAngle + deltaAngle),
  67876. false);
  67877. path.lineTo (x2, y2);
  67878. }
  67879. lastX2 = lastX;
  67880. lastY2 = lastY;
  67881. lastX = x2;
  67882. lastY = y2;
  67883. }
  67884. }
  67885. }
  67886. }
  67887. }
  67888. else
  67889. {
  67890. ++index;
  67891. }
  67892. break;
  67893. case T('Z'):
  67894. case T('z'):
  67895. path.closeSubPath();
  67896. while (CharacterFunctions::isWhitespace (d [index]))
  67897. ++index;
  67898. break;
  67899. default:
  67900. carryOn = false;
  67901. break;
  67902. }
  67903. if (! carryOn)
  67904. break;
  67905. }
  67906. return parseShape (xml, path);
  67907. }
  67908. Drawable* parseRect (const XmlElement& xml) const
  67909. {
  67910. Path rect;
  67911. const bool hasRX = xml.hasAttribute (T("rx"));
  67912. const bool hasRY = xml.hasAttribute (T("ry"));
  67913. if (hasRX || hasRY)
  67914. {
  67915. float rx = getCoordLength (xml.getStringAttribute (T("rx")), viewBoxW);
  67916. float ry = getCoordLength (xml.getStringAttribute (T("ry")), viewBoxH);
  67917. if (! hasRX)
  67918. rx = ry;
  67919. else if (! hasRY)
  67920. ry = rx;
  67921. rect.addRoundedRectangle (getCoordLength (xml.getStringAttribute (T("x")), viewBoxW),
  67922. getCoordLength (xml.getStringAttribute (T("y")), viewBoxH),
  67923. getCoordLength (xml.getStringAttribute (T("width")), viewBoxW),
  67924. getCoordLength (xml.getStringAttribute (T("height")), viewBoxH),
  67925. rx, ry);
  67926. }
  67927. else
  67928. {
  67929. rect.addRectangle (getCoordLength (xml.getStringAttribute (T("x")), viewBoxW),
  67930. getCoordLength (xml.getStringAttribute (T("y")), viewBoxH),
  67931. getCoordLength (xml.getStringAttribute (T("width")), viewBoxW),
  67932. getCoordLength (xml.getStringAttribute (T("height")), viewBoxH));
  67933. }
  67934. return parseShape (xml, rect);
  67935. }
  67936. Drawable* parseCircle (const XmlElement& xml) const
  67937. {
  67938. Path circle;
  67939. const float cx = getCoordLength (xml.getStringAttribute (T("cx")), viewBoxW);
  67940. const float cy = getCoordLength (xml.getStringAttribute (T("cy")), viewBoxH);
  67941. const float radius = getCoordLength (xml.getStringAttribute (T("r")), viewBoxW);
  67942. circle.addEllipse (cx - radius, cy - radius, radius * 2.0f, radius * 2.0f);
  67943. return parseShape (xml, circle);
  67944. }
  67945. Drawable* parseEllipse (const XmlElement& xml) const
  67946. {
  67947. Path ellipse;
  67948. const float cx = getCoordLength (xml.getStringAttribute (T("cx")), viewBoxW);
  67949. const float cy = getCoordLength (xml.getStringAttribute (T("cy")), viewBoxH);
  67950. const float radiusX = getCoordLength (xml.getStringAttribute (T("rx")), viewBoxW);
  67951. const float radiusY = getCoordLength (xml.getStringAttribute (T("ry")), viewBoxH);
  67952. ellipse.addEllipse (cx - radiusX, cy - radiusY, radiusX * 2.0f, radiusY * 2.0f);
  67953. return parseShape (xml, ellipse);
  67954. }
  67955. Drawable* parseLine (const XmlElement& xml) const
  67956. {
  67957. Path line;
  67958. const float x1 = getCoordLength (xml.getStringAttribute (T("x1")), viewBoxW);
  67959. const float y1 = getCoordLength (xml.getStringAttribute (T("y1")), viewBoxH);
  67960. const float x2 = getCoordLength (xml.getStringAttribute (T("x2")), viewBoxW);
  67961. const float y2 = getCoordLength (xml.getStringAttribute (T("y2")), viewBoxH);
  67962. line.startNewSubPath (x1, y1);
  67963. line.lineTo (x2, y2);
  67964. return parseShape (xml, line);
  67965. }
  67966. Drawable* parsePolygon (const XmlElement& xml, const bool isPolyline) const
  67967. {
  67968. const String points (xml.getStringAttribute (T("points")));
  67969. Path path;
  67970. int index = 0;
  67971. float x, y;
  67972. if (parseCoords (points, x, y, index, true))
  67973. {
  67974. float firstX = x;
  67975. float firstY = y;
  67976. float lastX = 0, lastY = 0;
  67977. path.startNewSubPath (x, y);
  67978. while (parseCoords (points, x, y, index, true))
  67979. {
  67980. lastX = x;
  67981. lastY = y;
  67982. path.lineTo (x, y);
  67983. }
  67984. if ((! isPolyline) || (firstX == lastX && firstY == lastY))
  67985. path.closeSubPath();
  67986. }
  67987. return parseShape (xml, path);
  67988. }
  67989. Drawable* parseShape (const XmlElement& xml, Path& path,
  67990. const bool shouldParseTransform = true) const
  67991. {
  67992. if (shouldParseTransform && xml.hasAttribute (T("transform")))
  67993. {
  67994. SVGState newState (*this);
  67995. newState.addTransform (xml);
  67996. return newState.parseShape (xml, path, false);
  67997. }
  67998. DrawablePath* dp = new DrawablePath();
  67999. dp->setName (xml.getStringAttribute (T("id")));
  68000. dp->setFill (FillType (Colours::transparentBlack));
  68001. path.applyTransform (transform);
  68002. dp->setPath (path);
  68003. Path::Iterator iter (path);
  68004. bool containsClosedSubPath = false;
  68005. while (iter.next())
  68006. {
  68007. if (iter.elementType == Path::Iterator::closePath)
  68008. {
  68009. containsClosedSubPath = true;
  68010. break;
  68011. }
  68012. }
  68013. dp->setFill (getPathFillType (path,
  68014. getStyleAttribute (&xml, T("fill")),
  68015. getStyleAttribute (&xml, T("fill-opacity")),
  68016. getStyleAttribute (&xml, T("opacity")),
  68017. containsClosedSubPath ? Colours::black
  68018. : Colours::transparentBlack));
  68019. const String strokeType (getStyleAttribute (&xml, T("stroke")));
  68020. if (strokeType.isNotEmpty() && ! strokeType.equalsIgnoreCase (T("none")))
  68021. {
  68022. dp->setStrokeFill (getPathFillType (path, strokeType,
  68023. getStyleAttribute (&xml, T("stroke-opacity")),
  68024. getStyleAttribute (&xml, T("opacity")),
  68025. Colours::transparentBlack));
  68026. dp->setStrokeType (getStrokeFor (&xml));
  68027. }
  68028. return dp;
  68029. }
  68030. const XmlElement* findLinkedElement (const XmlElement* e) const
  68031. {
  68032. const String id (e->getStringAttribute (T("xlink:href")));
  68033. if (! id.startsWithChar (T('#')))
  68034. return 0;
  68035. return findElementForId (topLevelXml, id.substring (1));
  68036. }
  68037. void addGradientStopsIn (ColourGradient& cg, const XmlElement* const fillXml) const
  68038. {
  68039. if (fillXml == 0)
  68040. return;
  68041. forEachXmlChildElementWithTagName (*fillXml, e, T("stop"))
  68042. {
  68043. int index = 0;
  68044. Colour col (parseColour (getStyleAttribute (e, T("stop-color")), index, Colours::black));
  68045. const String opacity (getStyleAttribute (e, T("stop-opacity"), T("1")));
  68046. col = col.withMultipliedAlpha (jlimit (0.0f, 1.0f, opacity.getFloatValue()));
  68047. double offset = e->getDoubleAttribute (T("offset"));
  68048. if (e->getStringAttribute (T("offset")).containsChar (T('%')))
  68049. offset *= 0.01;
  68050. cg.addColour (jlimit (0.0, 1.0, offset), col);
  68051. }
  68052. }
  68053. const FillType getPathFillType (const Path& path,
  68054. const String& fill,
  68055. const String& fillOpacity,
  68056. const String& overallOpacity,
  68057. const Colour& defaultColour) const
  68058. {
  68059. float opacity = 1.0f;
  68060. if (overallOpacity.isNotEmpty())
  68061. opacity = jlimit (0.0f, 1.0f, overallOpacity.getFloatValue());
  68062. if (fillOpacity.isNotEmpty())
  68063. opacity *= (jlimit (0.0f, 1.0f, fillOpacity.getFloatValue()));
  68064. if (fill.startsWithIgnoreCase (T("url")))
  68065. {
  68066. const String id (fill.fromFirstOccurrenceOf (T("#"), false, false)
  68067. .upToLastOccurrenceOf (T(")"), false, false).trim());
  68068. const XmlElement* const fillXml = findElementForId (topLevelXml, id);
  68069. if (fillXml != 0
  68070. && (fillXml->hasTagName (T("linearGradient"))
  68071. || fillXml->hasTagName (T("radialGradient"))))
  68072. {
  68073. const XmlElement* inheritedFrom = findLinkedElement (fillXml);
  68074. ColourGradient gradient;
  68075. addGradientStopsIn (gradient, inheritedFrom);
  68076. addGradientStopsIn (gradient, fillXml);
  68077. if (gradient.getNumColours() > 0)
  68078. {
  68079. gradient.addColour (0.0, gradient.getColour (0));
  68080. gradient.addColour (1.0, gradient.getColour (gradient.getNumColours() - 1));
  68081. }
  68082. else
  68083. {
  68084. gradient.addColour (0.0, Colours::black);
  68085. gradient.addColour (1.0, Colours::black);
  68086. }
  68087. if (overallOpacity.isNotEmpty())
  68088. gradient.multiplyOpacity (overallOpacity.getFloatValue());
  68089. jassert (gradient.getNumColours() > 0);
  68090. gradient.isRadial = fillXml->hasTagName (T("radialGradient"));
  68091. float width = viewBoxW;
  68092. float height = viewBoxH;
  68093. float dx = 0.0f;
  68094. float dy = 0.0f;
  68095. const bool userSpace = fillXml->getStringAttribute (T("gradientUnits")).equalsIgnoreCase (T("userSpaceOnUse"));
  68096. if (! userSpace)
  68097. {
  68098. const Rectangle<float> bounds (path.getBounds());
  68099. dx = bounds.getX();
  68100. dy = bounds.getY();
  68101. width = bounds.getWidth();
  68102. height = bounds.getHeight();
  68103. }
  68104. if (gradient.isRadial)
  68105. {
  68106. gradient.x1 = dx + getCoordLength (fillXml->getStringAttribute (T("cx"), T("50%")), width);
  68107. gradient.y1 = dy + getCoordLength (fillXml->getStringAttribute (T("cy"), T("50%")), height);
  68108. const float radius = getCoordLength (fillXml->getStringAttribute (T("r"), T("50%")), width);
  68109. gradient.x2 = gradient.x1 + radius;
  68110. gradient.y2 = gradient.y1;
  68111. //xxx (the fx, fy focal point isn't handled properly here..)
  68112. }
  68113. else
  68114. {
  68115. gradient.x1 = dx + getCoordLength (fillXml->getStringAttribute (T("x1"), T("0%")), width);
  68116. gradient.y1 = dy + getCoordLength (fillXml->getStringAttribute (T("y1"), T("0%")), height);
  68117. gradient.x2 = dx + getCoordLength (fillXml->getStringAttribute (T("x2"), T("100%")), width);
  68118. gradient.y2 = dy + getCoordLength (fillXml->getStringAttribute (T("y2"), T("0%")), height);
  68119. if (gradient.x1 == gradient.x2 && gradient.y1 == gradient.y2)
  68120. return Colour (gradient.getColour (gradient.getNumColours() - 1));
  68121. }
  68122. FillType type (gradient);
  68123. type.transform = parseTransform (fillXml->getStringAttribute (T("gradientTransform")))
  68124. .followedBy (transform);
  68125. return type;
  68126. }
  68127. }
  68128. if (fill.equalsIgnoreCase (T("none")))
  68129. return Colours::transparentBlack;
  68130. int i = 0;
  68131. const Colour colour (parseColour (fill, i, defaultColour));
  68132. return colour.withMultipliedAlpha (opacity);
  68133. }
  68134. const PathStrokeType getStrokeFor (const XmlElement* const xml) const
  68135. {
  68136. const String width (getStyleAttribute (xml, T("stroke-width")));
  68137. const String cap (getStyleAttribute (xml, T("stroke-linecap")));
  68138. const String join (getStyleAttribute (xml, T("stroke-linejoin")));
  68139. //const String mitreLimit (getStyleAttribute (xml, T("stroke-miterlimit")));
  68140. //const String dashArray (getStyleAttribute (xml, T("stroke-dasharray")));
  68141. //const String dashOffset (getStyleAttribute (xml, T("stroke-dashoffset")));
  68142. PathStrokeType::JointStyle joinStyle = PathStrokeType::mitered;
  68143. PathStrokeType::EndCapStyle capStyle = PathStrokeType::butt;
  68144. if (join.equalsIgnoreCase (T("round")))
  68145. joinStyle = PathStrokeType::curved;
  68146. else if (join.equalsIgnoreCase (T("bevel")))
  68147. joinStyle = PathStrokeType::beveled;
  68148. if (cap.equalsIgnoreCase (T("round")))
  68149. capStyle = PathStrokeType::rounded;
  68150. else if (cap.equalsIgnoreCase (T("square")))
  68151. capStyle = PathStrokeType::square;
  68152. float ox = 0.0f, oy = 0.0f;
  68153. transform.transformPoint (ox, oy);
  68154. float x = getCoordLength (width, viewBoxW), y = 0.0f;
  68155. transform.transformPoint (x, y);
  68156. return PathStrokeType (width.isNotEmpty() ? juce_hypotf (x - ox, y - oy) : 1.0f,
  68157. joinStyle, capStyle);
  68158. }
  68159. Drawable* parseText (const XmlElement& xml)
  68160. {
  68161. Array <float> xCoords, yCoords, dxCoords, dyCoords;
  68162. getCoordList (xCoords, getInheritedAttribute (&xml, T("x")), true, true);
  68163. getCoordList (yCoords, getInheritedAttribute (&xml, T("y")), true, false);
  68164. getCoordList (dxCoords, getInheritedAttribute (&xml, T("dx")), true, true);
  68165. getCoordList (dyCoords, getInheritedAttribute (&xml, T("dy")), true, false);
  68166. //xxx not done text yet!
  68167. forEachXmlChildElement (xml, e)
  68168. {
  68169. if (e->isTextElement())
  68170. {
  68171. const String text (e->getText());
  68172. Path path;
  68173. Drawable* s = parseShape (*e, path);
  68174. delete s;
  68175. }
  68176. else if (e->hasTagName (T("tspan")))
  68177. {
  68178. Drawable* s = parseText (*e);
  68179. delete s;
  68180. }
  68181. }
  68182. return 0;
  68183. }
  68184. void addTransform (const XmlElement& xml)
  68185. {
  68186. transform = parseTransform (xml.getStringAttribute (T("transform")))
  68187. .followedBy (transform);
  68188. }
  68189. bool parseCoord (const String& s, float& value, int& index,
  68190. const bool allowUnits, const bool isX) const
  68191. {
  68192. String number;
  68193. if (! parseNextNumber (s, number, index, allowUnits))
  68194. {
  68195. value = 0;
  68196. return false;
  68197. }
  68198. value = getCoordLength (number, isX ? viewBoxW : viewBoxH);
  68199. return true;
  68200. }
  68201. bool parseCoords (const String& s, float& x, float& y,
  68202. int& index, const bool allowUnits) const
  68203. {
  68204. return parseCoord (s, x, index, allowUnits, true)
  68205. && parseCoord (s, y, index, allowUnits, false);
  68206. }
  68207. float getCoordLength (const String& s, const float sizeForProportions) const
  68208. {
  68209. float n = s.getFloatValue();
  68210. const int len = s.length();
  68211. if (len > 2)
  68212. {
  68213. const float dpi = 96.0f;
  68214. const tchar n1 = s [len - 2];
  68215. const tchar n2 = s [len - 1];
  68216. if (n1 == T('i') && n2 == T('n'))
  68217. n *= dpi;
  68218. else if (n1 == T('m') && n2 == T('m'))
  68219. n *= dpi / 25.4f;
  68220. else if (n1 == T('c') && n2 == T('m'))
  68221. n *= dpi / 2.54f;
  68222. else if (n1 == T('p') && n2 == T('c'))
  68223. n *= 15.0f;
  68224. else if (n2 == T('%'))
  68225. n *= 0.01f * sizeForProportions;
  68226. }
  68227. return n;
  68228. }
  68229. void getCoordList (Array <float>& coords, const String& list,
  68230. const bool allowUnits, const bool isX) const
  68231. {
  68232. int index = 0;
  68233. float value;
  68234. while (parseCoord (list, value, index, allowUnits, isX))
  68235. coords.add (value);
  68236. }
  68237. void parseCSSStyle (const XmlElement& xml)
  68238. {
  68239. cssStyleText = xml.getAllSubText() + T("\n") + cssStyleText;
  68240. }
  68241. const String getStyleAttribute (const XmlElement* xml, const String& attributeName,
  68242. const String& defaultValue = String::empty) const
  68243. {
  68244. if (xml->hasAttribute (attributeName))
  68245. return xml->getStringAttribute (attributeName, defaultValue);
  68246. const String styleAtt (xml->getStringAttribute (T("style")));
  68247. if (styleAtt.isNotEmpty())
  68248. {
  68249. const String value (getAttributeFromStyleList (styleAtt, attributeName, String::empty));
  68250. if (value.isNotEmpty())
  68251. return value;
  68252. }
  68253. else if (xml->hasAttribute (T("class")))
  68254. {
  68255. const String className (T(".") + xml->getStringAttribute (T("class")));
  68256. int index = cssStyleText.indexOfIgnoreCase (className + T(" "));
  68257. if (index < 0)
  68258. index = cssStyleText.indexOfIgnoreCase (className + T("{"));
  68259. if (index >= 0)
  68260. {
  68261. const int openBracket = cssStyleText.indexOfChar (index, T('{'));
  68262. if (openBracket > index)
  68263. {
  68264. const int closeBracket = cssStyleText.indexOfChar (openBracket, T('}'));
  68265. if (closeBracket > openBracket)
  68266. {
  68267. const String value (getAttributeFromStyleList (cssStyleText.substring (openBracket + 1, closeBracket), attributeName, defaultValue));
  68268. if (value.isNotEmpty())
  68269. return value;
  68270. }
  68271. }
  68272. }
  68273. }
  68274. xml = const_cast <XmlElement*> (topLevelXml)->findParentElementOf (xml);
  68275. if (xml != 0)
  68276. return getStyleAttribute (xml, attributeName, defaultValue);
  68277. return defaultValue;
  68278. }
  68279. const String getInheritedAttribute (const XmlElement* xml, const String& attributeName) const
  68280. {
  68281. if (xml->hasAttribute (attributeName))
  68282. return xml->getStringAttribute (attributeName);
  68283. xml = const_cast <XmlElement*> (topLevelXml)->findParentElementOf (xml);
  68284. if (xml != 0)
  68285. return getInheritedAttribute (xml, attributeName);
  68286. return String::empty;
  68287. }
  68288. static bool isIdentifierChar (const tchar c)
  68289. {
  68290. return CharacterFunctions::isLetter (c) || c == T('-');
  68291. }
  68292. static const String getAttributeFromStyleList (const String& list, const String& attributeName, const String& defaultValue)
  68293. {
  68294. int i = 0;
  68295. for (;;)
  68296. {
  68297. i = list.indexOf (i, attributeName);
  68298. if (i < 0)
  68299. break;
  68300. if ((i == 0 || (i > 0 && ! isIdentifierChar (list [i - 1])))
  68301. && ! isIdentifierChar (list [i + attributeName.length()]))
  68302. {
  68303. i = list.indexOfChar (i, T(':'));
  68304. if (i < 0)
  68305. break;
  68306. int end = list.indexOfChar (i, T(';'));
  68307. if (end < 0)
  68308. end = 0x7ffff;
  68309. return list.substring (i + 1, end).trim();
  68310. }
  68311. ++i;
  68312. }
  68313. return defaultValue;
  68314. }
  68315. static bool parseNextNumber (const String& source, String& value, int& index, const bool allowUnits)
  68316. {
  68317. const tchar* const s = (const tchar*) source;
  68318. while (CharacterFunctions::isWhitespace (s[index]) || s[index] == T(','))
  68319. ++index;
  68320. int start = index;
  68321. if (CharacterFunctions::isDigit (s[index]) || s[index] == T('.') || s[index] == T('-'))
  68322. ++index;
  68323. while (CharacterFunctions::isDigit (s[index]) || s[index] == T('.'))
  68324. ++index;
  68325. if ((s[index] == T('e') || s[index] == T('E'))
  68326. && (CharacterFunctions::isDigit (s[index + 1])
  68327. || s[index + 1] == T('-')
  68328. || s[index + 1] == T('+')))
  68329. {
  68330. index += 2;
  68331. while (CharacterFunctions::isDigit (s[index]))
  68332. ++index;
  68333. }
  68334. if (allowUnits)
  68335. {
  68336. while (CharacterFunctions::isLetter (s[index]))
  68337. ++index;
  68338. }
  68339. if (index == start)
  68340. return false;
  68341. value = String (s + start, index - start);
  68342. while (CharacterFunctions::isWhitespace (s[index]) || s[index] == T(','))
  68343. ++index;
  68344. return true;
  68345. }
  68346. static const Colour parseColour (const String& s, int& index, const Colour& defaultColour)
  68347. {
  68348. if (s [index] == T('#'))
  68349. {
  68350. uint32 hex [6];
  68351. zeromem (hex, sizeof (hex));
  68352. int numChars = 0;
  68353. for (int i = 6; --i >= 0;)
  68354. {
  68355. const int hexValue = CharacterFunctions::getHexDigitValue (s [++index]);
  68356. if (hexValue >= 0)
  68357. hex [numChars++] = hexValue;
  68358. else
  68359. break;
  68360. }
  68361. if (numChars <= 3)
  68362. return Colour ((uint8) (hex [0] * 0x11),
  68363. (uint8) (hex [1] * 0x11),
  68364. (uint8) (hex [2] * 0x11));
  68365. else
  68366. return Colour ((uint8) ((hex [0] << 4) + hex [1]),
  68367. (uint8) ((hex [2] << 4) + hex [3]),
  68368. (uint8) ((hex [4] << 4) + hex [5]));
  68369. }
  68370. else if (s [index] == T('r')
  68371. && s [index + 1] == T('g')
  68372. && s [index + 2] == T('b'))
  68373. {
  68374. const int openBracket = s.indexOfChar (index, T('('));
  68375. const int closeBracket = s.indexOfChar (openBracket, T(')'));
  68376. if (openBracket >= 3 && closeBracket > openBracket)
  68377. {
  68378. index = closeBracket;
  68379. StringArray tokens;
  68380. tokens.addTokens (s.substring (openBracket + 1, closeBracket), T(","), T(""));
  68381. tokens.trim();
  68382. tokens.removeEmptyStrings();
  68383. if (tokens[0].containsChar (T('%')))
  68384. return Colour ((uint8) roundToInt (2.55 * tokens[0].getDoubleValue()),
  68385. (uint8) roundToInt (2.55 * tokens[1].getDoubleValue()),
  68386. (uint8) roundToInt (2.55 * tokens[2].getDoubleValue()));
  68387. else
  68388. return Colour ((uint8) tokens[0].getIntValue(),
  68389. (uint8) tokens[1].getIntValue(),
  68390. (uint8) tokens[2].getIntValue());
  68391. }
  68392. }
  68393. return Colours::findColourForName (s, defaultColour);
  68394. }
  68395. static const AffineTransform parseTransform (String t)
  68396. {
  68397. AffineTransform result;
  68398. while (t.isNotEmpty())
  68399. {
  68400. StringArray tokens;
  68401. tokens.addTokens (t.fromFirstOccurrenceOf (T("("), false, false)
  68402. .upToFirstOccurrenceOf (T(")"), false, false),
  68403. T(", "), String::empty);
  68404. tokens.removeEmptyStrings (true);
  68405. float numbers [6];
  68406. for (int i = 0; i < 6; ++i)
  68407. numbers[i] = tokens[i].getFloatValue();
  68408. AffineTransform trans;
  68409. if (t.startsWithIgnoreCase (T("matrix")))
  68410. {
  68411. trans = AffineTransform (numbers[0], numbers[2], numbers[4],
  68412. numbers[1], numbers[3], numbers[5]);
  68413. }
  68414. else if (t.startsWithIgnoreCase (T("translate")))
  68415. {
  68416. jassert (tokens.size() == 2);
  68417. trans = AffineTransform::translation (numbers[0], numbers[1]);
  68418. }
  68419. else if (t.startsWithIgnoreCase (T("scale")))
  68420. {
  68421. if (tokens.size() == 1)
  68422. trans = AffineTransform::scale (numbers[0], numbers[0]);
  68423. else
  68424. trans = AffineTransform::scale (numbers[0], numbers[1]);
  68425. }
  68426. else if (t.startsWithIgnoreCase (T("rotate")))
  68427. {
  68428. if (tokens.size() != 3)
  68429. trans = AffineTransform::rotation (numbers[0] / (180.0f / float_Pi));
  68430. else
  68431. trans = AffineTransform::rotation (numbers[0] / (180.0f / float_Pi),
  68432. numbers[1], numbers[2]);
  68433. }
  68434. else if (t.startsWithIgnoreCase (T("skewX")))
  68435. {
  68436. trans = AffineTransform (1.0f, tanf (numbers[0] * (float_Pi / 180.0f)), 0.0f,
  68437. 0.0f, 1.0f, 0.0f);
  68438. }
  68439. else if (t.startsWithIgnoreCase (T("skewY")))
  68440. {
  68441. trans = AffineTransform (1.0f, 0.0f, 0.0f,
  68442. tanf (numbers[0] * (float_Pi / 180.0f)), 1.0f, 0.0f);
  68443. }
  68444. result = trans.followedBy (result);
  68445. t = t.fromFirstOccurrenceOf (T(")"), false, false).trimStart();
  68446. }
  68447. return result;
  68448. }
  68449. static void endpointToCentreParameters (const double x1, const double y1,
  68450. const double x2, const double y2,
  68451. const double angle,
  68452. const bool largeArc, const bool sweep,
  68453. double& rx, double& ry,
  68454. double& centreX, double& centreY,
  68455. double& startAngle, double& deltaAngle)
  68456. {
  68457. const double midX = (x1 - x2) * 0.5;
  68458. const double midY = (y1 - y2) * 0.5;
  68459. const double cosAngle = cos (angle);
  68460. const double sinAngle = sin (angle);
  68461. const double xp = cosAngle * midX + sinAngle * midY;
  68462. const double yp = cosAngle * midY - sinAngle * midX;
  68463. const double xp2 = xp * xp;
  68464. const double yp2 = yp * yp;
  68465. double rx2 = rx * rx;
  68466. double ry2 = ry * ry;
  68467. const double s = (xp2 / rx2) + (yp2 / ry2);
  68468. double c;
  68469. if (s <= 1.0)
  68470. {
  68471. c = sqrt (jmax (0.0, ((rx2 * ry2) - (rx2 * yp2) - (ry2 * xp2))
  68472. / (( rx2 * yp2) + (ry2 * xp2))));
  68473. if (largeArc == sweep)
  68474. c = -c;
  68475. }
  68476. else
  68477. {
  68478. const double s2 = sqrt (s);
  68479. rx *= s2;
  68480. ry *= s2;
  68481. rx2 = rx * rx;
  68482. ry2 = ry * ry;
  68483. c = 0;
  68484. }
  68485. const double cpx = ((rx * yp) / ry) * c;
  68486. const double cpy = ((-ry * xp) / rx) * c;
  68487. centreX = ((x1 + x2) * 0.5) + (cosAngle * cpx) - (sinAngle * cpy);
  68488. centreY = ((y1 + y2) * 0.5) + (sinAngle * cpx) + (cosAngle * cpy);
  68489. const double ux = (xp - cpx) / rx;
  68490. const double uy = (yp - cpy) / ry;
  68491. const double vx = (-xp - cpx) / rx;
  68492. const double vy = (-yp - cpy) / ry;
  68493. const double length = juce_hypot (ux, uy);
  68494. startAngle = acos (jlimit (-1.0, 1.0, ux / length));
  68495. if (uy < 0)
  68496. startAngle = -startAngle;
  68497. startAngle += double_Pi * 0.5;
  68498. deltaAngle = acos (jlimit (-1.0, 1.0, ((ux * vx) + (uy * vy))
  68499. / (length * juce_hypot (vx, vy))));
  68500. if ((ux * vy) - (uy * vx) < 0)
  68501. deltaAngle = -deltaAngle;
  68502. if (sweep)
  68503. {
  68504. if (deltaAngle < 0)
  68505. deltaAngle += double_Pi * 2.0;
  68506. }
  68507. else
  68508. {
  68509. if (deltaAngle > 0)
  68510. deltaAngle -= double_Pi * 2.0;
  68511. }
  68512. deltaAngle = fmod (deltaAngle, double_Pi * 2.0);
  68513. }
  68514. static const XmlElement* findElementForId (const XmlElement* const parent, const String& id)
  68515. {
  68516. forEachXmlChildElement (*parent, e)
  68517. {
  68518. if (e->compareAttribute (T("id"), id))
  68519. return e;
  68520. const XmlElement* const found = findElementForId (e, id);
  68521. if (found != 0)
  68522. return found;
  68523. }
  68524. return 0;
  68525. }
  68526. SVGState& operator= (const SVGState&);
  68527. };
  68528. Drawable* Drawable::createFromSVG (const XmlElement& svgDocument)
  68529. {
  68530. SVGState state (&svgDocument);
  68531. return state.parseSVGElement (svgDocument);
  68532. }
  68533. END_JUCE_NAMESPACE
  68534. /*** End of inlined file: juce_SVGParser.cpp ***/
  68535. /*** Start of inlined file: juce_DropShadowEffect.cpp ***/
  68536. BEGIN_JUCE_NAMESPACE
  68537. #if JUCE_MSVC
  68538. #pragma optimize ("t", on) // try to avoid slowing everything down in debug builds
  68539. #endif
  68540. DropShadowEffect::DropShadowEffect()
  68541. : offsetX (0),
  68542. offsetY (0),
  68543. radius (4),
  68544. opacity (0.6f)
  68545. {
  68546. }
  68547. DropShadowEffect::~DropShadowEffect()
  68548. {
  68549. }
  68550. void DropShadowEffect::setShadowProperties (const float newRadius,
  68551. const float newOpacity,
  68552. const int newShadowOffsetX,
  68553. const int newShadowOffsetY)
  68554. {
  68555. radius = jmax (1.1f, newRadius);
  68556. offsetX = newShadowOffsetX;
  68557. offsetY = newShadowOffsetY;
  68558. opacity = newOpacity;
  68559. }
  68560. void DropShadowEffect::applyEffect (Image& image, Graphics& g)
  68561. {
  68562. const int w = image.getWidth();
  68563. const int h = image.getHeight();
  68564. Image shadowImage (Image::SingleChannel, w, h, false);
  68565. const Image::BitmapData srcData (image, 0, 0, w, h);
  68566. const Image::BitmapData destData (shadowImage, 0, 0, w, h, true);
  68567. const int filter = roundToInt (63.0f / radius);
  68568. const int radiusMinus1 = roundToInt ((radius - 1.0f) * 63.0f);
  68569. for (int x = w; --x >= 0;)
  68570. {
  68571. int shadowAlpha = 0;
  68572. const PixelARGB* src = ((const PixelARGB*) srcData.data) + x;
  68573. uint8* shadowPix = destData.data + x;
  68574. for (int y = h; --y >= 0;)
  68575. {
  68576. shadowAlpha = ((shadowAlpha * radiusMinus1 + (src->getAlpha() << 6)) * filter) >> 12;
  68577. *shadowPix = (uint8) shadowAlpha;
  68578. src = (const PixelARGB*) (((const uint8*) src) + srcData.lineStride);
  68579. shadowPix += destData.lineStride;
  68580. }
  68581. }
  68582. for (int y = h; --y >= 0;)
  68583. {
  68584. int shadowAlpha = 0;
  68585. uint8* shadowPix = destData.getLinePointer (y);
  68586. for (int x = w; --x >= 0;)
  68587. {
  68588. shadowAlpha = ((shadowAlpha * radiusMinus1 + (*shadowPix << 6)) * filter) >> 12;
  68589. *shadowPix++ = (uint8) shadowAlpha;
  68590. }
  68591. }
  68592. g.setColour (Colours::black.withAlpha (opacity));
  68593. g.drawImageAt (&shadowImage, offsetX, offsetY, true);
  68594. g.setOpacity (1.0f);
  68595. g.drawImageAt (&image, 0, 0);
  68596. }
  68597. END_JUCE_NAMESPACE
  68598. /*** End of inlined file: juce_DropShadowEffect.cpp ***/
  68599. /*** Start of inlined file: juce_GlowEffect.cpp ***/
  68600. BEGIN_JUCE_NAMESPACE
  68601. GlowEffect::GlowEffect()
  68602. : radius (2.0f),
  68603. colour (Colours::white)
  68604. {
  68605. }
  68606. GlowEffect::~GlowEffect()
  68607. {
  68608. }
  68609. void GlowEffect::setGlowProperties (const float newRadius,
  68610. const Colour& newColour)
  68611. {
  68612. radius = newRadius;
  68613. colour = newColour;
  68614. }
  68615. void GlowEffect::applyEffect (Image& image, Graphics& g)
  68616. {
  68617. const int w = image.getWidth();
  68618. const int h = image.getHeight();
  68619. Image temp (image.getFormat(), w, h, true);
  68620. ImageConvolutionKernel blurKernel (roundToInt (radius * 2.0f));
  68621. blurKernel.createGaussianBlur (radius);
  68622. blurKernel.rescaleAllValues (radius);
  68623. blurKernel.applyToImage (temp, &image, 0, 0, w, h);
  68624. g.setColour (colour);
  68625. g.drawImageAt (&temp, 0, 0, true);
  68626. g.setOpacity (1.0f);
  68627. g.drawImageAt (&image, 0, 0, false);
  68628. }
  68629. END_JUCE_NAMESPACE
  68630. /*** End of inlined file: juce_GlowEffect.cpp ***/
  68631. /*** Start of inlined file: juce_ReduceOpacityEffect.cpp ***/
  68632. BEGIN_JUCE_NAMESPACE
  68633. ReduceOpacityEffect::ReduceOpacityEffect (const float opacity_)
  68634. : opacity (opacity_)
  68635. {
  68636. }
  68637. ReduceOpacityEffect::~ReduceOpacityEffect()
  68638. {
  68639. }
  68640. void ReduceOpacityEffect::setOpacity (const float newOpacity)
  68641. {
  68642. opacity = jlimit (0.0f, 1.0f, newOpacity);
  68643. }
  68644. void ReduceOpacityEffect::applyEffect (Image& image, Graphics& g)
  68645. {
  68646. g.setOpacity (opacity);
  68647. g.drawImageAt (&image, 0, 0);
  68648. }
  68649. END_JUCE_NAMESPACE
  68650. /*** End of inlined file: juce_ReduceOpacityEffect.cpp ***/
  68651. /*** Start of inlined file: juce_Font.cpp ***/
  68652. BEGIN_JUCE_NAMESPACE
  68653. static const float minFontHeight = 0.1f;
  68654. static const float maxFontHeight = 10000.0f;
  68655. static const float defaultFontHeight = 14.0f;
  68656. static const tchar* const juce_defaultFontNameSans = T("<Sans-Serif>");
  68657. static const tchar* const juce_defaultFontNameSerif = T("<Serif>");
  68658. static const tchar* const juce_defaultFontNameMono = T("<Monospaced>");
  68659. void clearUpDefaultFontNames() throw(); // in juce_LookAndFeel.cpp
  68660. Font::SharedFontInternal::SharedFontInternal (const String& typefaceName_, const float height_, const float horizontalScale_,
  68661. const float kerning_, const float ascent_, const int styleFlags_,
  68662. Typeface* const typeface_) throw()
  68663. : typefaceName (typefaceName_),
  68664. height (height_),
  68665. horizontalScale (horizontalScale_),
  68666. kerning (kerning_),
  68667. ascent (ascent_),
  68668. styleFlags (styleFlags_),
  68669. typeface (typeface_)
  68670. {
  68671. }
  68672. Font::SharedFontInternal::SharedFontInternal (const SharedFontInternal& other) throw()
  68673. : typefaceName (other.typefaceName),
  68674. height (other.height),
  68675. horizontalScale (other.horizontalScale),
  68676. kerning (other.kerning),
  68677. ascent (other.ascent),
  68678. styleFlags (other.styleFlags),
  68679. typeface (other.typeface)
  68680. {
  68681. }
  68682. Font::Font() throw()
  68683. : font (new SharedFontInternal (juce_defaultFontNameSans, defaultFontHeight,
  68684. 1.0f, 0, 0, Font::plain, 0))
  68685. {
  68686. }
  68687. Font::Font (const float fontHeight, const int styleFlags_) throw()
  68688. : font (new SharedFontInternal (juce_defaultFontNameSans, jlimit (minFontHeight, maxFontHeight, fontHeight),
  68689. 1.0f, 0, 0, styleFlags_, 0))
  68690. {
  68691. }
  68692. Font::Font (const String& typefaceName_,
  68693. const float fontHeight,
  68694. const int styleFlags_) throw()
  68695. : font (new SharedFontInternal (typefaceName_, jlimit (minFontHeight, maxFontHeight, fontHeight),
  68696. 1.0f, 0, 0, styleFlags_, 0))
  68697. {
  68698. }
  68699. Font::Font (const Font& other) throw()
  68700. : font (other.font)
  68701. {
  68702. }
  68703. Font& Font::operator= (const Font& other) throw()
  68704. {
  68705. font = other.font;
  68706. return *this;
  68707. }
  68708. Font::~Font() throw()
  68709. {
  68710. }
  68711. Font::Font (const Typeface::Ptr& typeface) throw()
  68712. : font (new SharedFontInternal (typeface->getName(), defaultFontHeight,
  68713. 1.0f, 0, 0, Font::plain, typeface))
  68714. {
  68715. }
  68716. bool Font::operator== (const Font& other) const throw()
  68717. {
  68718. return font == other.font
  68719. || (font->height == other.font->height
  68720. && font->styleFlags == other.font->styleFlags
  68721. && font->horizontalScale == other.font->horizontalScale
  68722. && font->kerning == other.font->kerning
  68723. && font->typefaceName == other.font->typefaceName);
  68724. }
  68725. bool Font::operator!= (const Font& other) const throw()
  68726. {
  68727. return ! operator== (other);
  68728. }
  68729. void Font::dupeInternalIfShared() throw()
  68730. {
  68731. if (font->getReferenceCount() > 1)
  68732. font = new SharedFontInternal (*font);
  68733. }
  68734. const String Font::getDefaultSansSerifFontName() throw()
  68735. {
  68736. return juce_defaultFontNameSans;
  68737. }
  68738. const String Font::getDefaultSerifFontName() throw()
  68739. {
  68740. return juce_defaultFontNameSerif;
  68741. }
  68742. const String Font::getDefaultMonospacedFontName() throw()
  68743. {
  68744. return juce_defaultFontNameMono;
  68745. }
  68746. void Font::setTypefaceName (const String& faceName) throw()
  68747. {
  68748. if (faceName != font->typefaceName)
  68749. {
  68750. dupeInternalIfShared();
  68751. font->typefaceName = faceName;
  68752. font->typeface = 0;
  68753. font->ascent = 0;
  68754. }
  68755. }
  68756. static String fallbackFont;
  68757. const String Font::getFallbackFontName() throw()
  68758. {
  68759. return fallbackFont;
  68760. }
  68761. void Font::setFallbackFontName (const String& name) throw()
  68762. {
  68763. fallbackFont = name;
  68764. }
  68765. void Font::setHeight (float newHeight) throw()
  68766. {
  68767. newHeight = jlimit (minFontHeight, maxFontHeight, newHeight);
  68768. if (font->height != newHeight)
  68769. {
  68770. dupeInternalIfShared();
  68771. font->height = newHeight;
  68772. }
  68773. }
  68774. void Font::setHeightWithoutChangingWidth (float newHeight) throw()
  68775. {
  68776. newHeight = jlimit (minFontHeight, maxFontHeight, newHeight);
  68777. if (font->height != newHeight)
  68778. {
  68779. dupeInternalIfShared();
  68780. font->horizontalScale *= (font->height / newHeight);
  68781. font->height = newHeight;
  68782. }
  68783. }
  68784. void Font::setStyleFlags (const int newFlags) throw()
  68785. {
  68786. if (font->styleFlags != newFlags)
  68787. {
  68788. dupeInternalIfShared();
  68789. font->styleFlags = newFlags;
  68790. font->typeface = 0;
  68791. font->ascent = 0;
  68792. }
  68793. }
  68794. void Font::setSizeAndStyle (float newHeight,
  68795. const int newStyleFlags,
  68796. const float newHorizontalScale,
  68797. const float newKerningAmount) throw()
  68798. {
  68799. newHeight = jlimit (minFontHeight, maxFontHeight, newHeight);
  68800. if (font->height != newHeight
  68801. || font->horizontalScale != newHorizontalScale
  68802. || font->kerning != newKerningAmount)
  68803. {
  68804. dupeInternalIfShared();
  68805. font->height = newHeight;
  68806. font->horizontalScale = newHorizontalScale;
  68807. font->kerning = newKerningAmount;
  68808. }
  68809. setStyleFlags (newStyleFlags);
  68810. }
  68811. void Font::setHorizontalScale (const float scaleFactor) throw()
  68812. {
  68813. dupeInternalIfShared();
  68814. font->horizontalScale = scaleFactor;
  68815. }
  68816. void Font::setExtraKerningFactor (const float extraKerning) throw()
  68817. {
  68818. dupeInternalIfShared();
  68819. font->kerning = extraKerning;
  68820. }
  68821. void Font::setBold (const bool shouldBeBold) throw()
  68822. {
  68823. setStyleFlags (shouldBeBold ? (font->styleFlags | bold)
  68824. : (font->styleFlags & ~bold));
  68825. }
  68826. bool Font::isBold() const throw()
  68827. {
  68828. return (font->styleFlags & bold) != 0;
  68829. }
  68830. void Font::setItalic (const bool shouldBeItalic) throw()
  68831. {
  68832. setStyleFlags (shouldBeItalic ? (font->styleFlags | italic)
  68833. : (font->styleFlags & ~italic));
  68834. }
  68835. bool Font::isItalic() const throw()
  68836. {
  68837. return (font->styleFlags & italic) != 0;
  68838. }
  68839. void Font::setUnderline (const bool shouldBeUnderlined) throw()
  68840. {
  68841. setStyleFlags (shouldBeUnderlined ? (font->styleFlags | underlined)
  68842. : (font->styleFlags & ~underlined));
  68843. }
  68844. bool Font::isUnderlined() const throw()
  68845. {
  68846. return (font->styleFlags & underlined) != 0;
  68847. }
  68848. float Font::getAscent() const throw()
  68849. {
  68850. if (font->ascent == 0)
  68851. font->ascent = getTypeface()->getAscent();
  68852. return font->height * font->ascent;
  68853. }
  68854. float Font::getDescent() const throw()
  68855. {
  68856. return font->height - getAscent();
  68857. }
  68858. int Font::getStringWidth (const String& text) const throw()
  68859. {
  68860. return roundToInt (getStringWidthFloat (text));
  68861. }
  68862. float Font::getStringWidthFloat (const String& text) const throw()
  68863. {
  68864. float w = getTypeface()->getStringWidth (text);
  68865. if (font->kerning != 0)
  68866. w += font->kerning * text.length();
  68867. return w * font->height * font->horizontalScale;
  68868. }
  68869. void Font::getGlyphPositions (const String& text, Array <int>& glyphs, Array <float>& xOffsets) const throw()
  68870. {
  68871. getTypeface()->getGlyphPositions (text, glyphs, xOffsets);
  68872. const float scale = font->height * font->horizontalScale;
  68873. const int num = xOffsets.size();
  68874. if (num > 0)
  68875. {
  68876. float* const x = &(xOffsets.getReference(0));
  68877. if (font->kerning != 0)
  68878. {
  68879. for (int i = 0; i < num; ++i)
  68880. x[i] = (x[i] + i * font->kerning) * scale;
  68881. }
  68882. else
  68883. {
  68884. for (int i = 0; i < num; ++i)
  68885. x[i] *= scale;
  68886. }
  68887. }
  68888. }
  68889. void Font::findFonts (Array<Font>& destArray) throw()
  68890. {
  68891. const StringArray names (findAllTypefaceNames());
  68892. for (int i = 0; i < names.size(); ++i)
  68893. destArray.add (Font (names[i], defaultFontHeight, Font::plain));
  68894. }
  68895. class TypefaceCache : public DeletedAtShutdown
  68896. {
  68897. public:
  68898. TypefaceCache (int numToCache = 10) throw()
  68899. : counter (1)
  68900. {
  68901. while (--numToCache >= 0)
  68902. faces.add (new CachedFace());
  68903. }
  68904. ~TypefaceCache()
  68905. {
  68906. clearUpDefaultFontNames();
  68907. clearSingletonInstance();
  68908. }
  68909. juce_DeclareSingleton_SingleThreaded_Minimal (TypefaceCache)
  68910. const Typeface::Ptr findTypefaceFor (const Font& font) throw()
  68911. {
  68912. const int flags = font.getStyleFlags() & (Font::bold | Font::italic);
  68913. const String faceName (font.getTypefaceName());
  68914. int i;
  68915. for (i = faces.size(); --i >= 0;)
  68916. {
  68917. CachedFace* const face = faces.getUnchecked(i);
  68918. if (face->flags == flags
  68919. && face->typefaceName == faceName)
  68920. {
  68921. face->lastUsageCount = ++counter;
  68922. return face->typeFace;
  68923. }
  68924. }
  68925. int replaceIndex = 0;
  68926. int bestLastUsageCount = std::numeric_limits<int>::max();
  68927. for (i = faces.size(); --i >= 0;)
  68928. {
  68929. const int lu = faces.getUnchecked(i)->lastUsageCount;
  68930. if (bestLastUsageCount > lu)
  68931. {
  68932. bestLastUsageCount = lu;
  68933. replaceIndex = i;
  68934. }
  68935. }
  68936. CachedFace* const face = faces.getUnchecked (replaceIndex);
  68937. face->typefaceName = faceName;
  68938. face->flags = flags;
  68939. face->lastUsageCount = ++counter;
  68940. face->typeFace = LookAndFeel::getDefaultLookAndFeel().getTypefaceForFont (font);
  68941. jassert (face->typeFace != 0); // the look and feel must return a typeface!
  68942. return face->typeFace;
  68943. }
  68944. juce_UseDebuggingNewOperator
  68945. private:
  68946. struct CachedFace
  68947. {
  68948. CachedFace() throw()
  68949. : lastUsageCount (0), flags (-1)
  68950. {
  68951. }
  68952. String typefaceName;
  68953. int lastUsageCount;
  68954. int flags;
  68955. Typeface::Ptr typeFace;
  68956. };
  68957. int counter;
  68958. OwnedArray <CachedFace> faces;
  68959. TypefaceCache (const TypefaceCache&);
  68960. TypefaceCache& operator= (const TypefaceCache&);
  68961. };
  68962. juce_ImplementSingleton_SingleThreaded (TypefaceCache)
  68963. Typeface* Font::getTypeface() const throw()
  68964. {
  68965. if (font->typeface == 0)
  68966. font->typeface = TypefaceCache::getInstance()->findTypefaceFor (*this);
  68967. return font->typeface;
  68968. }
  68969. END_JUCE_NAMESPACE
  68970. /*** End of inlined file: juce_Font.cpp ***/
  68971. /*** Start of inlined file: juce_GlyphArrangement.cpp ***/
  68972. BEGIN_JUCE_NAMESPACE
  68973. PositionedGlyph::PositionedGlyph (const float x_, const float y_, const float w_, const Font& font_,
  68974. const juce_wchar character_, const int glyph_)
  68975. : x (x_),
  68976. y (y_),
  68977. w (w_),
  68978. font (font_),
  68979. character (character_),
  68980. glyph (glyph_)
  68981. {
  68982. }
  68983. PositionedGlyph::PositionedGlyph (const PositionedGlyph& other)
  68984. : x (other.x),
  68985. y (other.y),
  68986. w (other.w),
  68987. font (other.font),
  68988. character (other.character),
  68989. glyph (other.glyph)
  68990. {
  68991. }
  68992. void PositionedGlyph::draw (const Graphics& g) const
  68993. {
  68994. if (! isWhitespace())
  68995. {
  68996. g.getInternalContext()->setFont (font);
  68997. g.getInternalContext()->drawGlyph (glyph, AffineTransform::translation (x, y));
  68998. }
  68999. }
  69000. void PositionedGlyph::draw (const Graphics& g,
  69001. const AffineTransform& transform) const
  69002. {
  69003. if (! isWhitespace())
  69004. {
  69005. g.getInternalContext()->setFont (font);
  69006. g.getInternalContext()->drawGlyph (glyph, AffineTransform::translation (x, y)
  69007. .followedBy (transform));
  69008. }
  69009. }
  69010. void PositionedGlyph::createPath (Path& path) const
  69011. {
  69012. if (! isWhitespace())
  69013. {
  69014. Typeface* const t = font.getTypeface();
  69015. if (t != 0)
  69016. {
  69017. Path p;
  69018. t->getOutlineForGlyph (glyph, p);
  69019. path.addPath (p, AffineTransform::scale (font.getHeight() * font.getHorizontalScale(), font.getHeight())
  69020. .translated (x, y));
  69021. }
  69022. }
  69023. }
  69024. bool PositionedGlyph::hitTest (float px, float py) const
  69025. {
  69026. if (px >= getLeft() && px < getRight()
  69027. && py >= getTop() && py < getBottom()
  69028. && ! isWhitespace())
  69029. {
  69030. Typeface* const t = font.getTypeface();
  69031. if (t != 0)
  69032. {
  69033. Path p;
  69034. t->getOutlineForGlyph (glyph, p);
  69035. AffineTransform::translation (-x, -y)
  69036. .scaled (1.0f / (font.getHeight() * font.getHorizontalScale()), 1.0f / font.getHeight())
  69037. .transformPoint (px, py);
  69038. return p.contains (px, py);
  69039. }
  69040. }
  69041. return false;
  69042. }
  69043. void PositionedGlyph::moveBy (const float deltaX,
  69044. const float deltaY)
  69045. {
  69046. x += deltaX;
  69047. y += deltaY;
  69048. }
  69049. GlyphArrangement::GlyphArrangement()
  69050. {
  69051. glyphs.ensureStorageAllocated (128);
  69052. }
  69053. GlyphArrangement::GlyphArrangement (const GlyphArrangement& other)
  69054. {
  69055. addGlyphArrangement (other);
  69056. }
  69057. GlyphArrangement& GlyphArrangement::operator= (const GlyphArrangement& other)
  69058. {
  69059. if (this != &other)
  69060. {
  69061. clear();
  69062. addGlyphArrangement (other);
  69063. }
  69064. return *this;
  69065. }
  69066. GlyphArrangement::~GlyphArrangement()
  69067. {
  69068. }
  69069. void GlyphArrangement::clear()
  69070. {
  69071. glyphs.clear();
  69072. }
  69073. PositionedGlyph& GlyphArrangement::getGlyph (const int index) const
  69074. {
  69075. jassert (((unsigned int) index) < (unsigned int) glyphs.size());
  69076. return *glyphs [index];
  69077. }
  69078. void GlyphArrangement::addGlyphArrangement (const GlyphArrangement& other)
  69079. {
  69080. glyphs.ensureStorageAllocated (glyphs.size() + other.glyphs.size());
  69081. for (int i = 0; i < other.glyphs.size(); ++i)
  69082. glyphs.add (new PositionedGlyph (*other.glyphs.getUnchecked (i)));
  69083. }
  69084. void GlyphArrangement::removeRangeOfGlyphs (int startIndex, const int num)
  69085. {
  69086. glyphs.removeRange (startIndex, num < 0 ? glyphs.size() : num);
  69087. }
  69088. void GlyphArrangement::addLineOfText (const Font& font,
  69089. const String& text,
  69090. const float xOffset,
  69091. const float yOffset)
  69092. {
  69093. addCurtailedLineOfText (font, text,
  69094. xOffset, yOffset,
  69095. 1.0e10f, false);
  69096. }
  69097. void GlyphArrangement::addCurtailedLineOfText (const Font& font,
  69098. const String& text,
  69099. float xOffset,
  69100. const float yOffset,
  69101. const float maxWidthPixels,
  69102. const bool useEllipsis)
  69103. {
  69104. if (text.isNotEmpty())
  69105. {
  69106. Array <int> newGlyphs;
  69107. Array <float> xOffsets;
  69108. font.getGlyphPositions (text, newGlyphs, xOffsets);
  69109. const int textLen = newGlyphs.size();
  69110. const juce_wchar* const unicodeText = (const juce_wchar*) text;
  69111. for (int i = 0; i < textLen; ++i)
  69112. {
  69113. const float thisX = xOffsets.getUnchecked (i);
  69114. const float nextX = xOffsets.getUnchecked (i + 1);
  69115. if (nextX > maxWidthPixels + 1.0f)
  69116. {
  69117. // curtail the string if it's too wide..
  69118. if (useEllipsis && textLen > 3 && glyphs.size() >= 3)
  69119. insertEllipsis (font, xOffset + maxWidthPixels, 0, glyphs.size());
  69120. break;
  69121. }
  69122. else
  69123. {
  69124. glyphs.add (new PositionedGlyph (xOffset + thisX, yOffset, nextX - thisX,
  69125. font, unicodeText[i], newGlyphs.getUnchecked(i)));
  69126. }
  69127. }
  69128. }
  69129. }
  69130. int GlyphArrangement::insertEllipsis (const Font& font, const float maxXPos,
  69131. const int startIndex, int endIndex)
  69132. {
  69133. int numDeleted = 0;
  69134. if (glyphs.size() > 0)
  69135. {
  69136. Array<int> dotGlyphs;
  69137. Array<float> dotXs;
  69138. font.getGlyphPositions (T(".."), dotGlyphs, dotXs);
  69139. const float dx = dotXs[1];
  69140. float xOffset = 0.0f, yOffset = 0.0f;
  69141. while (endIndex > startIndex)
  69142. {
  69143. const PositionedGlyph* pg = glyphs.getUnchecked (--endIndex);
  69144. xOffset = pg->x;
  69145. yOffset = pg->y;
  69146. glyphs.remove (endIndex);
  69147. ++numDeleted;
  69148. if (xOffset + dx * 3 <= maxXPos)
  69149. break;
  69150. }
  69151. for (int i = 3; --i >= 0;)
  69152. {
  69153. glyphs.insert (endIndex++, new PositionedGlyph (xOffset, yOffset, dx,
  69154. font, '.', dotGlyphs.getFirst()));
  69155. --numDeleted;
  69156. xOffset += dx;
  69157. if (xOffset > maxXPos)
  69158. break;
  69159. }
  69160. }
  69161. return numDeleted;
  69162. }
  69163. void GlyphArrangement::addJustifiedText (const Font& font,
  69164. const String& text,
  69165. float x, float y,
  69166. const float maxLineWidth,
  69167. const Justification& horizontalLayout)
  69168. {
  69169. int lineStartIndex = glyphs.size();
  69170. addLineOfText (font, text, x, y);
  69171. const float originalY = y;
  69172. while (lineStartIndex < glyphs.size())
  69173. {
  69174. int i = lineStartIndex;
  69175. if (glyphs.getUnchecked(i)->getCharacter() != T('\n')
  69176. && glyphs.getUnchecked(i)->getCharacter() != T('\r'))
  69177. ++i;
  69178. const float lineMaxX = glyphs.getUnchecked (lineStartIndex)->getLeft() + maxLineWidth;
  69179. int lastWordBreakIndex = -1;
  69180. while (i < glyphs.size())
  69181. {
  69182. const PositionedGlyph* pg = glyphs.getUnchecked (i);
  69183. const juce_wchar c = pg->getCharacter();
  69184. if (c == T('\r') || c == T('\n'))
  69185. {
  69186. ++i;
  69187. if (c == T('\r') && i < glyphs.size()
  69188. && glyphs.getUnchecked(i)->getCharacter() == T('\n'))
  69189. ++i;
  69190. break;
  69191. }
  69192. else if (pg->isWhitespace())
  69193. {
  69194. lastWordBreakIndex = i + 1;
  69195. }
  69196. else if (pg->getRight() - 0.0001f >= lineMaxX)
  69197. {
  69198. if (lastWordBreakIndex >= 0)
  69199. i = lastWordBreakIndex;
  69200. break;
  69201. }
  69202. ++i;
  69203. }
  69204. const float currentLineStartX = glyphs.getUnchecked (lineStartIndex)->getLeft();
  69205. float currentLineEndX = currentLineStartX;
  69206. for (int j = i; --j >= lineStartIndex;)
  69207. {
  69208. if (! glyphs.getUnchecked (j)->isWhitespace())
  69209. {
  69210. currentLineEndX = glyphs.getUnchecked (j)->getRight();
  69211. break;
  69212. }
  69213. }
  69214. float deltaX = 0.0f;
  69215. if (horizontalLayout.testFlags (Justification::horizontallyJustified))
  69216. spreadOutLine (lineStartIndex, i - lineStartIndex, maxLineWidth);
  69217. else if (horizontalLayout.testFlags (Justification::horizontallyCentred))
  69218. deltaX = (maxLineWidth - (currentLineEndX - currentLineStartX)) * 0.5f;
  69219. else if (horizontalLayout.testFlags (Justification::right))
  69220. deltaX = maxLineWidth - (currentLineEndX - currentLineStartX);
  69221. moveRangeOfGlyphs (lineStartIndex, i - lineStartIndex,
  69222. x + deltaX - currentLineStartX, y - originalY);
  69223. lineStartIndex = i;
  69224. y += font.getHeight();
  69225. }
  69226. }
  69227. void GlyphArrangement::addFittedText (const Font& f,
  69228. const String& text,
  69229. const float x, const float y,
  69230. const float width, const float height,
  69231. const Justification& layout,
  69232. int maximumLines,
  69233. const float minimumHorizontalScale)
  69234. {
  69235. // doesn't make much sense if this is outside a sensible range of 0.5 to 1.0
  69236. jassert (minimumHorizontalScale > 0 && minimumHorizontalScale <= 1.0f);
  69237. if (text.containsAnyOf (T("\r\n")))
  69238. {
  69239. GlyphArrangement ga;
  69240. ga.addJustifiedText (f, text, x, y, width, layout);
  69241. float l, t, r, b;
  69242. ga.getBoundingBox (0, -1, l, t, r, b, false);
  69243. float dy = y - t;
  69244. if (layout.testFlags (Justification::verticallyCentred))
  69245. dy += (height - (b - t)) * 0.5f;
  69246. else if (layout.testFlags (Justification::bottom))
  69247. dy += height - (b - t);
  69248. ga.moveRangeOfGlyphs (0, -1, 0.0f, dy);
  69249. glyphs.ensureStorageAllocated (glyphs.size() + ga.glyphs.size());
  69250. for (int i = 0; i < ga.glyphs.size(); ++i)
  69251. glyphs.add (ga.glyphs.getUnchecked (i));
  69252. ga.glyphs.clear (false);
  69253. return;
  69254. }
  69255. int startIndex = glyphs.size();
  69256. addLineOfText (f, text.trim(), x, y);
  69257. if (glyphs.size() > startIndex)
  69258. {
  69259. float lineWidth = glyphs.getUnchecked (glyphs.size() - 1)->getRight()
  69260. - glyphs.getUnchecked (startIndex)->getLeft();
  69261. if (lineWidth <= 0)
  69262. return;
  69263. if (lineWidth * minimumHorizontalScale < width)
  69264. {
  69265. if (lineWidth > width)
  69266. stretchRangeOfGlyphs (startIndex, glyphs.size() - startIndex,
  69267. width / lineWidth);
  69268. justifyGlyphs (startIndex, glyphs.size() - startIndex,
  69269. x, y, width, height, layout);
  69270. }
  69271. else if (maximumLines <= 1)
  69272. {
  69273. fitLineIntoSpace (startIndex, glyphs.size() - startIndex,
  69274. x, y, width, height, f, layout, minimumHorizontalScale);
  69275. }
  69276. else
  69277. {
  69278. Font font (f);
  69279. String txt (text.trim());
  69280. const int length = txt.length();
  69281. const int originalStartIndex = startIndex;
  69282. int numLines = 1;
  69283. if (length <= 12 && ! txt.containsAnyOf (T(" -\t\r\n")))
  69284. maximumLines = 1;
  69285. maximumLines = jmin (maximumLines, length);
  69286. while (numLines < maximumLines)
  69287. {
  69288. ++numLines;
  69289. const float newFontHeight = height / (float) numLines;
  69290. if (newFontHeight < font.getHeight())
  69291. {
  69292. font.setHeight (jmax (8.0f, newFontHeight));
  69293. removeRangeOfGlyphs (startIndex, -1);
  69294. addLineOfText (font, txt, x, y);
  69295. lineWidth = glyphs.getUnchecked (glyphs.size() - 1)->getRight()
  69296. - glyphs.getUnchecked (startIndex)->getLeft();
  69297. }
  69298. if (numLines > lineWidth / width || newFontHeight < 8.0f)
  69299. break;
  69300. }
  69301. if (numLines < 1)
  69302. numLines = 1;
  69303. float lineY = y;
  69304. float widthPerLine = lineWidth / numLines;
  69305. int lastLineStartIndex = 0;
  69306. for (int line = 0; line < numLines; ++line)
  69307. {
  69308. int i = startIndex;
  69309. lastLineStartIndex = i;
  69310. float lineStartX = glyphs.getUnchecked (startIndex)->getLeft();
  69311. if (line == numLines - 1)
  69312. {
  69313. widthPerLine = width;
  69314. i = glyphs.size();
  69315. }
  69316. else
  69317. {
  69318. while (i < glyphs.size())
  69319. {
  69320. lineWidth = (glyphs.getUnchecked (i)->getRight() - lineStartX);
  69321. if (lineWidth > widthPerLine)
  69322. {
  69323. // got to a point where the line's too long, so skip forward to find a
  69324. // good place to break it..
  69325. const int searchStartIndex = i;
  69326. while (i < glyphs.size())
  69327. {
  69328. if ((glyphs.getUnchecked (i)->getRight() - lineStartX) * minimumHorizontalScale < width)
  69329. {
  69330. if (glyphs.getUnchecked (i)->isWhitespace()
  69331. || glyphs.getUnchecked (i)->getCharacter() == T('-'))
  69332. {
  69333. ++i;
  69334. break;
  69335. }
  69336. }
  69337. else
  69338. {
  69339. // can't find a suitable break, so try looking backwards..
  69340. i = searchStartIndex;
  69341. for (int back = 1; back < jmin (5, i - startIndex - 1); ++back)
  69342. {
  69343. if (glyphs.getUnchecked (i - back)->isWhitespace()
  69344. || glyphs.getUnchecked (i - back)->getCharacter() == T('-'))
  69345. {
  69346. i -= back - 1;
  69347. break;
  69348. }
  69349. }
  69350. break;
  69351. }
  69352. ++i;
  69353. }
  69354. break;
  69355. }
  69356. ++i;
  69357. }
  69358. int wsStart = i;
  69359. while (wsStart > 0 && glyphs.getUnchecked (wsStart - 1)->isWhitespace())
  69360. --wsStart;
  69361. int wsEnd = i;
  69362. while (wsEnd < glyphs.size() && glyphs.getUnchecked (wsEnd)->isWhitespace())
  69363. ++wsEnd;
  69364. removeRangeOfGlyphs (wsStart, wsEnd - wsStart);
  69365. i = jmax (wsStart, startIndex + 1);
  69366. }
  69367. i -= fitLineIntoSpace (startIndex, i - startIndex,
  69368. x, lineY, width, font.getHeight(), font,
  69369. layout.getOnlyHorizontalFlags() | Justification::verticallyCentred,
  69370. minimumHorizontalScale);
  69371. startIndex = i;
  69372. lineY += font.getHeight();
  69373. if (startIndex >= glyphs.size())
  69374. break;
  69375. }
  69376. justifyGlyphs (originalStartIndex, glyphs.size() - originalStartIndex,
  69377. x, y, width, height, layout.getFlags() & ~Justification::horizontallyJustified);
  69378. }
  69379. }
  69380. }
  69381. void GlyphArrangement::moveRangeOfGlyphs (int startIndex, int num,
  69382. const float dx, const float dy)
  69383. {
  69384. jassert (startIndex >= 0);
  69385. if (dx != 0.0f || dy != 0.0f)
  69386. {
  69387. if (num < 0 || startIndex + num > glyphs.size())
  69388. num = glyphs.size() - startIndex;
  69389. while (--num >= 0)
  69390. glyphs.getUnchecked (startIndex++)->moveBy (dx, dy);
  69391. }
  69392. }
  69393. int GlyphArrangement::fitLineIntoSpace (int start, int numGlyphs, float x, float y, float w, float h, const Font& font,
  69394. const Justification& justification, float minimumHorizontalScale)
  69395. {
  69396. int numDeleted = 0;
  69397. const float lineStartX = glyphs.getUnchecked (start)->getLeft();
  69398. float lineWidth = glyphs.getUnchecked (start + numGlyphs - 1)->getRight() - lineStartX;
  69399. if (lineWidth > w)
  69400. {
  69401. if (minimumHorizontalScale < 1.0f)
  69402. {
  69403. stretchRangeOfGlyphs (start, numGlyphs, jmax (minimumHorizontalScale, w / lineWidth));
  69404. lineWidth = glyphs.getUnchecked (start + numGlyphs - 1)->getRight() - lineStartX - 0.5f;
  69405. }
  69406. if (lineWidth > w)
  69407. {
  69408. numDeleted = insertEllipsis (font, lineStartX + w, start, start + numGlyphs);
  69409. numGlyphs -= numDeleted;
  69410. }
  69411. }
  69412. justifyGlyphs (start, numGlyphs, x, y, w, h, justification);
  69413. return numDeleted;
  69414. }
  69415. void GlyphArrangement::stretchRangeOfGlyphs (int startIndex, int num,
  69416. const float horizontalScaleFactor)
  69417. {
  69418. jassert (startIndex >= 0);
  69419. if (num < 0 || startIndex + num > glyphs.size())
  69420. num = glyphs.size() - startIndex;
  69421. if (num > 0)
  69422. {
  69423. const float xAnchor = glyphs.getUnchecked (startIndex)->getLeft();
  69424. while (--num >= 0)
  69425. {
  69426. PositionedGlyph* const pg = glyphs.getUnchecked (startIndex++);
  69427. pg->x = xAnchor + (pg->x - xAnchor) * horizontalScaleFactor;
  69428. pg->font.setHorizontalScale (pg->font.getHorizontalScale() * horizontalScaleFactor);
  69429. pg->w *= horizontalScaleFactor;
  69430. }
  69431. }
  69432. }
  69433. void GlyphArrangement::getBoundingBox (int startIndex, int num,
  69434. float& left,
  69435. float& top,
  69436. float& right,
  69437. float& bottom,
  69438. const bool includeWhitespace) const
  69439. {
  69440. jassert (startIndex >= 0);
  69441. if (num < 0 || startIndex + num > glyphs.size())
  69442. num = glyphs.size() - startIndex;
  69443. left = 0.0f;
  69444. top = 0.0f;
  69445. right = 0.0f;
  69446. bottom = 0.0f;
  69447. bool isFirst = true;
  69448. while (--num >= 0)
  69449. {
  69450. const PositionedGlyph* const pg = glyphs.getUnchecked (startIndex++);
  69451. if (includeWhitespace || ! pg->isWhitespace())
  69452. {
  69453. if (isFirst)
  69454. {
  69455. isFirst = false;
  69456. left = pg->getLeft();
  69457. top = pg->getTop();
  69458. right = pg->getRight();
  69459. bottom = pg->getBottom();
  69460. }
  69461. else
  69462. {
  69463. left = jmin (left, pg->getLeft());
  69464. top = jmin (top, pg->getTop());
  69465. right = jmax (right, pg->getRight());
  69466. bottom = jmax (bottom, pg->getBottom());
  69467. }
  69468. }
  69469. }
  69470. }
  69471. void GlyphArrangement::justifyGlyphs (const int startIndex,
  69472. const int num,
  69473. const float x, const float y,
  69474. const float width, const float height,
  69475. const Justification& justification)
  69476. {
  69477. jassert (num >= 0 && startIndex >= 0);
  69478. if (glyphs.size() > 0 && num > 0)
  69479. {
  69480. float left, top, right, bottom;
  69481. getBoundingBox (startIndex, num, left, top, right, bottom,
  69482. ! justification.testFlags (Justification::horizontallyJustified
  69483. | Justification::horizontallyCentred));
  69484. float deltaX = 0.0f;
  69485. if (justification.testFlags (Justification::horizontallyJustified))
  69486. deltaX = x - left;
  69487. else if (justification.testFlags (Justification::horizontallyCentred))
  69488. deltaX = x + (width - (right - left)) * 0.5f - left;
  69489. else if (justification.testFlags (Justification::right))
  69490. deltaX = (x + width) - right;
  69491. else
  69492. deltaX = x - left;
  69493. float deltaY = 0.0f;
  69494. if (justification.testFlags (Justification::top))
  69495. deltaY = y - top;
  69496. else if (justification.testFlags (Justification::bottom))
  69497. deltaY = (y + height) - bottom;
  69498. else
  69499. deltaY = y + (height - (bottom - top)) * 0.5f - top;
  69500. moveRangeOfGlyphs (startIndex, num, deltaX, deltaY);
  69501. if (justification.testFlags (Justification::horizontallyJustified))
  69502. {
  69503. int lineStart = 0;
  69504. float baseY = glyphs.getUnchecked (startIndex)->getBaselineY();
  69505. int i;
  69506. for (i = 0; i < num; ++i)
  69507. {
  69508. const float glyphY = glyphs.getUnchecked (startIndex + i)->getBaselineY();
  69509. if (glyphY != baseY)
  69510. {
  69511. spreadOutLine (startIndex + lineStart, i - lineStart, width);
  69512. lineStart = i;
  69513. baseY = glyphY;
  69514. }
  69515. }
  69516. if (i > lineStart)
  69517. spreadOutLine (startIndex + lineStart, i - lineStart, width);
  69518. }
  69519. }
  69520. }
  69521. void GlyphArrangement::spreadOutLine (const int start, const int num, const float targetWidth)
  69522. {
  69523. if (start + num < glyphs.size()
  69524. && glyphs.getUnchecked (start + num - 1)->getCharacter() != T('\r')
  69525. && glyphs.getUnchecked (start + num - 1)->getCharacter() != T('\n'))
  69526. {
  69527. int numSpaces = 0;
  69528. int spacesAtEnd = 0;
  69529. for (int i = 0; i < num; ++i)
  69530. {
  69531. if (glyphs.getUnchecked (start + i)->isWhitespace())
  69532. {
  69533. ++spacesAtEnd;
  69534. ++numSpaces;
  69535. }
  69536. else
  69537. {
  69538. spacesAtEnd = 0;
  69539. }
  69540. }
  69541. numSpaces -= spacesAtEnd;
  69542. if (numSpaces > 0)
  69543. {
  69544. const float startX = glyphs.getUnchecked (start)->getLeft();
  69545. const float endX = glyphs.getUnchecked (start + num - 1 - spacesAtEnd)->getRight();
  69546. const float extraPaddingBetweenWords
  69547. = (targetWidth - (endX - startX)) / (float) numSpaces;
  69548. float deltaX = 0.0f;
  69549. for (int i = 0; i < num; ++i)
  69550. {
  69551. glyphs.getUnchecked (start + i)->moveBy (deltaX, 0.0f);
  69552. if (glyphs.getUnchecked (start + i)->isWhitespace())
  69553. deltaX += extraPaddingBetweenWords;
  69554. }
  69555. }
  69556. }
  69557. }
  69558. void GlyphArrangement::draw (const Graphics& g) const
  69559. {
  69560. for (int i = 0; i < glyphs.size(); ++i)
  69561. {
  69562. const PositionedGlyph* const pg = glyphs.getUnchecked(i);
  69563. if (pg->font.isUnderlined())
  69564. {
  69565. const float lineThickness = (pg->font.getDescent()) * 0.3f;
  69566. float nextX = pg->x + pg->w;
  69567. if (i < glyphs.size() - 1 && glyphs.getUnchecked (i + 1)->y == pg->y)
  69568. nextX = glyphs.getUnchecked (i + 1)->x;
  69569. g.fillRect (pg->x, pg->y + lineThickness * 2.0f,
  69570. nextX - pg->x, lineThickness);
  69571. }
  69572. pg->draw (g);
  69573. }
  69574. }
  69575. void GlyphArrangement::draw (const Graphics& g, const AffineTransform& transform) const
  69576. {
  69577. for (int i = 0; i < glyphs.size(); ++i)
  69578. {
  69579. const PositionedGlyph* const pg = glyphs.getUnchecked(i);
  69580. if (pg->font.isUnderlined())
  69581. {
  69582. const float lineThickness = (pg->font.getDescent()) * 0.3f;
  69583. float nextX = pg->x + pg->w;
  69584. if (i < glyphs.size() - 1 && glyphs.getUnchecked (i + 1)->y == pg->y)
  69585. nextX = glyphs.getUnchecked (i + 1)->x;
  69586. Path p;
  69587. p.addLineSegment (pg->x, pg->y + lineThickness * 2.0f,
  69588. nextX, pg->y + lineThickness * 2.0f,
  69589. lineThickness);
  69590. g.fillPath (p, transform);
  69591. }
  69592. pg->draw (g, transform);
  69593. }
  69594. }
  69595. void GlyphArrangement::createPath (Path& path) const
  69596. {
  69597. for (int i = 0; i < glyphs.size(); ++i)
  69598. glyphs.getUnchecked (i)->createPath (path);
  69599. }
  69600. int GlyphArrangement::findGlyphIndexAt (float x, float y) const
  69601. {
  69602. for (int i = 0; i < glyphs.size(); ++i)
  69603. if (glyphs.getUnchecked (i)->hitTest (x, y))
  69604. return i;
  69605. return -1;
  69606. }
  69607. END_JUCE_NAMESPACE
  69608. /*** End of inlined file: juce_GlyphArrangement.cpp ***/
  69609. /*** Start of inlined file: juce_TextLayout.cpp ***/
  69610. BEGIN_JUCE_NAMESPACE
  69611. class TextLayout::Token
  69612. {
  69613. public:
  69614. String text;
  69615. Font font;
  69616. int x, y, w, h;
  69617. int line, lineHeight;
  69618. bool isWhitespace, isNewLine;
  69619. Token (const String& t,
  69620. const Font& f,
  69621. const bool isWhitespace_) throw()
  69622. : text (t),
  69623. font (f),
  69624. x(0),
  69625. y(0),
  69626. isWhitespace (isWhitespace_)
  69627. {
  69628. w = font.getStringWidth (t);
  69629. h = roundToInt (f.getHeight());
  69630. isNewLine = t.containsAnyOf (T("\r\n"));
  69631. }
  69632. Token (const Token& other) throw()
  69633. : text (other.text),
  69634. font (other.font),
  69635. x (other.x),
  69636. y (other.y),
  69637. w (other.w),
  69638. h (other.h),
  69639. line (other.line),
  69640. lineHeight (other.lineHeight),
  69641. isWhitespace (other.isWhitespace),
  69642. isNewLine (other.isNewLine)
  69643. {
  69644. }
  69645. ~Token() throw()
  69646. {
  69647. }
  69648. void draw (Graphics& g,
  69649. const int xOffset,
  69650. const int yOffset) throw()
  69651. {
  69652. if (! isWhitespace)
  69653. {
  69654. g.setFont (font);
  69655. g.drawSingleLineText (text.trimEnd(),
  69656. xOffset + x,
  69657. yOffset + y + (lineHeight - h)
  69658. + roundToInt (font.getAscent()));
  69659. }
  69660. }
  69661. juce_UseDebuggingNewOperator
  69662. };
  69663. TextLayout::TextLayout() throw()
  69664. : totalLines (0)
  69665. {
  69666. tokens.ensureStorageAllocated (64);
  69667. }
  69668. TextLayout::TextLayout (const String& text,
  69669. const Font& font) throw()
  69670. : totalLines (0)
  69671. {
  69672. tokens.ensureStorageAllocated (64);
  69673. appendText (text, font);
  69674. }
  69675. TextLayout::TextLayout (const TextLayout& other) throw()
  69676. : totalLines (0)
  69677. {
  69678. *this = other;
  69679. }
  69680. TextLayout& TextLayout::operator= (const TextLayout& other) throw()
  69681. {
  69682. if (this != &other)
  69683. {
  69684. clear();
  69685. totalLines = other.totalLines;
  69686. for (int i = 0; i < other.tokens.size(); ++i)
  69687. tokens.add (new Token (*other.tokens.getUnchecked(i)));
  69688. }
  69689. return *this;
  69690. }
  69691. TextLayout::~TextLayout() throw()
  69692. {
  69693. clear();
  69694. }
  69695. void TextLayout::clear() throw()
  69696. {
  69697. tokens.clear();
  69698. totalLines = 0;
  69699. }
  69700. void TextLayout::appendText (const String& text,
  69701. const Font& font) throw()
  69702. {
  69703. const tchar* t = text;
  69704. String currentString;
  69705. int lastCharType = 0;
  69706. for (;;)
  69707. {
  69708. const tchar c = *t++;
  69709. if (c == 0)
  69710. break;
  69711. int charType;
  69712. if (c == T('\r') || c == T('\n'))
  69713. {
  69714. charType = 0;
  69715. }
  69716. else if (CharacterFunctions::isWhitespace (c))
  69717. {
  69718. charType = 2;
  69719. }
  69720. else
  69721. {
  69722. charType = 1;
  69723. }
  69724. if (charType == 0 || charType != lastCharType)
  69725. {
  69726. if (currentString.isNotEmpty())
  69727. {
  69728. tokens.add (new Token (currentString, font,
  69729. lastCharType == 2 || lastCharType == 0));
  69730. }
  69731. currentString = String::charToString (c);
  69732. if (c == T('\r') && *t == T('\n'))
  69733. currentString += *t++;
  69734. }
  69735. else
  69736. {
  69737. currentString += c;
  69738. }
  69739. lastCharType = charType;
  69740. }
  69741. if (currentString.isNotEmpty())
  69742. tokens.add (new Token (currentString, font, lastCharType == 2));
  69743. }
  69744. void TextLayout::setText (const String& text, const Font& font) throw()
  69745. {
  69746. clear();
  69747. appendText (text, font);
  69748. }
  69749. void TextLayout::layout (int maxWidth,
  69750. const Justification& justification,
  69751. const bool attemptToBalanceLineLengths) throw()
  69752. {
  69753. if (attemptToBalanceLineLengths)
  69754. {
  69755. const int originalW = maxWidth;
  69756. int bestWidth = maxWidth;
  69757. float bestLineProportion = 0.0f;
  69758. while (maxWidth > originalW / 2)
  69759. {
  69760. layout (maxWidth, justification, false);
  69761. if (getNumLines() <= 1)
  69762. return;
  69763. const int lastLineW = getLineWidth (getNumLines() - 1);
  69764. const int lastButOneLineW = getLineWidth (getNumLines() - 2);
  69765. const float prop = lastLineW / (float) lastButOneLineW;
  69766. if (prop > 0.9f)
  69767. return;
  69768. if (prop > bestLineProportion)
  69769. {
  69770. bestLineProportion = prop;
  69771. bestWidth = maxWidth;
  69772. }
  69773. maxWidth -= 10;
  69774. }
  69775. layout (bestWidth, justification, false);
  69776. }
  69777. else
  69778. {
  69779. int x = 0;
  69780. int y = 0;
  69781. int h = 0;
  69782. totalLines = 0;
  69783. int i;
  69784. for (i = 0; i < tokens.size(); ++i)
  69785. {
  69786. Token* const t = tokens.getUnchecked(i);
  69787. t->x = x;
  69788. t->y = y;
  69789. t->line = totalLines;
  69790. x += t->w;
  69791. h = jmax (h, t->h);
  69792. const Token* nextTok = tokens [i + 1];
  69793. if (nextTok == 0)
  69794. break;
  69795. if (t->isNewLine || ((! nextTok->isWhitespace) && x + nextTok->w > maxWidth))
  69796. {
  69797. // finished a line, so go back and update the heights of the things on it
  69798. for (int j = i; j >= 0; --j)
  69799. {
  69800. Token* const tok = tokens.getUnchecked(j);
  69801. if (tok->line == totalLines)
  69802. tok->lineHeight = h;
  69803. else
  69804. break;
  69805. }
  69806. x = 0;
  69807. y += h;
  69808. h = 0;
  69809. ++totalLines;
  69810. }
  69811. }
  69812. // finished a line, so go back and update the heights of the things on it
  69813. for (int j = jmin (i, tokens.size() - 1); j >= 0; --j)
  69814. {
  69815. Token* const t = tokens.getUnchecked(j);
  69816. if (t->line == totalLines)
  69817. t->lineHeight = h;
  69818. else
  69819. break;
  69820. }
  69821. ++totalLines;
  69822. if (! justification.testFlags (Justification::left))
  69823. {
  69824. int totalW = getWidth();
  69825. for (i = totalLines; --i >= 0;)
  69826. {
  69827. const int lineW = getLineWidth (i);
  69828. int dx = 0;
  69829. if (justification.testFlags (Justification::horizontallyCentred))
  69830. dx = (totalW - lineW) / 2;
  69831. else if (justification.testFlags (Justification::right))
  69832. dx = totalW - lineW;
  69833. for (int j = tokens.size(); --j >= 0;)
  69834. {
  69835. Token* const t = tokens.getUnchecked(j);
  69836. if (t->line == i)
  69837. t->x += dx;
  69838. }
  69839. }
  69840. }
  69841. }
  69842. }
  69843. int TextLayout::getLineWidth (const int lineNumber) const throw()
  69844. {
  69845. int maxW = 0;
  69846. for (int i = tokens.size(); --i >= 0;)
  69847. {
  69848. const Token* const t = tokens.getUnchecked(i);
  69849. if (t->line == lineNumber && ! t->isWhitespace)
  69850. maxW = jmax (maxW, t->x + t->w);
  69851. }
  69852. return maxW;
  69853. }
  69854. int TextLayout::getWidth() const throw()
  69855. {
  69856. int maxW = 0;
  69857. for (int i = tokens.size(); --i >= 0;)
  69858. {
  69859. const Token* const t = tokens.getUnchecked(i);
  69860. if (! t->isWhitespace)
  69861. maxW = jmax (maxW, t->x + t->w);
  69862. }
  69863. return maxW;
  69864. }
  69865. int TextLayout::getHeight() const throw()
  69866. {
  69867. int maxH = 0;
  69868. for (int i = tokens.size(); --i >= 0;)
  69869. {
  69870. const Token* const t = tokens.getUnchecked(i);
  69871. if (! t->isWhitespace)
  69872. maxH = jmax (maxH, t->y + t->h);
  69873. }
  69874. return maxH;
  69875. }
  69876. void TextLayout::draw (Graphics& g,
  69877. const int xOffset,
  69878. const int yOffset) const throw()
  69879. {
  69880. for (int i = tokens.size(); --i >= 0;)
  69881. tokens.getUnchecked(i)->draw (g, xOffset, yOffset);
  69882. }
  69883. void TextLayout::drawWithin (Graphics& g,
  69884. int x, int y, int w, int h,
  69885. const Justification& justification) const throw()
  69886. {
  69887. justification.applyToRectangle (x, y, getWidth(), getHeight(),
  69888. x, y, w, h);
  69889. draw (g, x, y);
  69890. }
  69891. END_JUCE_NAMESPACE
  69892. /*** End of inlined file: juce_TextLayout.cpp ***/
  69893. /*** Start of inlined file: juce_Typeface.cpp ***/
  69894. BEGIN_JUCE_NAMESPACE
  69895. Typeface::Typeface (const String& name_) throw()
  69896. : name (name_)
  69897. {
  69898. }
  69899. Typeface::~Typeface()
  69900. {
  69901. }
  69902. class CustomTypeface::GlyphInfo
  69903. {
  69904. public:
  69905. GlyphInfo (const juce_wchar character_, const Path& path_, const float width_) throw()
  69906. : character (character_), path (path_), width (width_)
  69907. {
  69908. }
  69909. ~GlyphInfo() throw()
  69910. {
  69911. }
  69912. struct KerningPair
  69913. {
  69914. juce_wchar character2;
  69915. float kerningAmount;
  69916. };
  69917. void addKerningPair (const juce_wchar subsequentCharacter,
  69918. const float extraKerningAmount) throw()
  69919. {
  69920. KerningPair kp;
  69921. kp.character2 = subsequentCharacter;
  69922. kp.kerningAmount = extraKerningAmount;
  69923. kerningPairs.add (kp);
  69924. }
  69925. float getHorizontalSpacing (const juce_wchar subsequentCharacter) const throw()
  69926. {
  69927. if (subsequentCharacter != 0)
  69928. {
  69929. for (int i = kerningPairs.size(); --i >= 0;)
  69930. if (kerningPairs.getReference(i).character2 == subsequentCharacter)
  69931. return width + kerningPairs.getReference(i).kerningAmount;
  69932. }
  69933. return width;
  69934. }
  69935. const juce_wchar character;
  69936. const Path path;
  69937. float width;
  69938. Array <KerningPair> kerningPairs;
  69939. juce_UseDebuggingNewOperator
  69940. private:
  69941. GlyphInfo (const GlyphInfo&);
  69942. GlyphInfo& operator= (const GlyphInfo&);
  69943. };
  69944. CustomTypeface::CustomTypeface()
  69945. : Typeface (String::empty)
  69946. {
  69947. clear();
  69948. }
  69949. CustomTypeface::CustomTypeface (InputStream& serialisedTypefaceStream)
  69950. : Typeface (String::empty)
  69951. {
  69952. clear();
  69953. GZIPDecompressorInputStream gzin (&serialisedTypefaceStream, false);
  69954. BufferedInputStream in (&gzin, 32768, false);
  69955. name = in.readString();
  69956. isBold = in.readBool();
  69957. isItalic = in.readBool();
  69958. ascent = in.readFloat();
  69959. defaultCharacter = (juce_wchar) in.readShort();
  69960. int i, numChars = in.readInt();
  69961. for (i = 0; i < numChars; ++i)
  69962. {
  69963. const juce_wchar c = (juce_wchar) in.readShort();
  69964. const float width = in.readFloat();
  69965. Path p;
  69966. p.loadPathFromStream (in);
  69967. addGlyph (c, p, width);
  69968. }
  69969. const int numKerningPairs = in.readInt();
  69970. for (i = 0; i < numKerningPairs; ++i)
  69971. {
  69972. const juce_wchar char1 = (juce_wchar) in.readShort();
  69973. const juce_wchar char2 = (juce_wchar) in.readShort();
  69974. addKerningPair (char1, char2, in.readFloat());
  69975. }
  69976. }
  69977. CustomTypeface::~CustomTypeface()
  69978. {
  69979. }
  69980. void CustomTypeface::clear()
  69981. {
  69982. defaultCharacter = 0;
  69983. ascent = 1.0f;
  69984. isBold = isItalic = false;
  69985. zeromem (lookupTable, sizeof (lookupTable));
  69986. glyphs.clear();
  69987. }
  69988. void CustomTypeface::setCharacteristics (const String& name_, const float ascent_, const bool isBold_,
  69989. const bool isItalic_, const juce_wchar defaultCharacter_) throw()
  69990. {
  69991. name = name_;
  69992. defaultCharacter = defaultCharacter_;
  69993. ascent = ascent_;
  69994. isBold = isBold_;
  69995. isItalic = isItalic_;
  69996. }
  69997. void CustomTypeface::addGlyph (const juce_wchar character, const Path& path, const float width) throw()
  69998. {
  69999. // Check that you're not trying to add the same character twice..
  70000. jassert (findGlyph (character, false) == 0);
  70001. if (((unsigned int) character) < (unsigned int) numElementsInArray (lookupTable))
  70002. lookupTable [character] = (short) glyphs.size();
  70003. glyphs.add (new GlyphInfo (character, path, width));
  70004. }
  70005. void CustomTypeface::addKerningPair (const juce_wchar char1, const juce_wchar char2, const float extraAmount) throw()
  70006. {
  70007. if (extraAmount != 0)
  70008. {
  70009. GlyphInfo* const g = findGlyph (char1, true);
  70010. jassert (g != 0); // can only add kerning pairs for characters that exist!
  70011. if (g != 0)
  70012. g->addKerningPair (char2, extraAmount);
  70013. }
  70014. }
  70015. CustomTypeface::GlyphInfo* CustomTypeface::findGlyph (const juce_wchar character, const bool loadIfNeeded) throw()
  70016. {
  70017. if (((unsigned int) character) < (unsigned int) numElementsInArray (lookupTable) && lookupTable [character] > 0)
  70018. return glyphs [(int) lookupTable [(int) character]];
  70019. for (int i = 0; i < glyphs.size(); ++i)
  70020. {
  70021. GlyphInfo* const g = glyphs.getUnchecked(i);
  70022. if (g->character == character)
  70023. return g;
  70024. }
  70025. if (loadIfNeeded && loadGlyphIfPossible (character))
  70026. return findGlyph (character, false);
  70027. return 0;
  70028. }
  70029. CustomTypeface::GlyphInfo* CustomTypeface::findGlyphSubstituting (const juce_wchar character) throw()
  70030. {
  70031. GlyphInfo* glyph = findGlyph (character, true);
  70032. if (glyph == 0)
  70033. {
  70034. if (CharacterFunctions::isWhitespace (character) && character != L' ')
  70035. glyph = findGlyph (L' ', true);
  70036. if (glyph == 0)
  70037. {
  70038. const Font fallbackFont (Font::getFallbackFontName(), 10, 0);
  70039. Typeface* const fallbackTypeface = fallbackFont.getTypeface();
  70040. if (fallbackTypeface != 0 && fallbackTypeface != this)
  70041. {
  70042. //xxx
  70043. }
  70044. if (glyph == 0)
  70045. glyph = findGlyph (defaultCharacter, true);
  70046. }
  70047. }
  70048. return glyph;
  70049. }
  70050. bool CustomTypeface::loadGlyphIfPossible (const juce_wchar /*characterNeeded*/)
  70051. {
  70052. return false;
  70053. }
  70054. void CustomTypeface::addGlyphsFromOtherTypeface (Typeface& typefaceToCopy, juce_wchar characterStartIndex, int numCharacters) throw()
  70055. {
  70056. for (int i = 0; i < numCharacters; ++i)
  70057. {
  70058. const juce_wchar c = (juce_wchar) (characterStartIndex + i);
  70059. Array <int> glyphIndexes;
  70060. Array <float> offsets;
  70061. typefaceToCopy.getGlyphPositions (String::charToString (c), glyphIndexes, offsets);
  70062. const int glyphIndex = glyphIndexes.getFirst();
  70063. if (glyphIndex >= 0 && glyphIndexes.size() > 0)
  70064. {
  70065. const float glyphWidth = offsets[1];
  70066. Path p;
  70067. typefaceToCopy.getOutlineForGlyph (glyphIndex, p);
  70068. addGlyph (c, p, glyphWidth);
  70069. for (int j = glyphs.size() - 1; --j >= 0;)
  70070. {
  70071. const juce_wchar char2 = glyphs.getUnchecked (j)->character;
  70072. glyphIndexes.clearQuick();
  70073. offsets.clearQuick();
  70074. typefaceToCopy.getGlyphPositions (String::charToString (c) + String::charToString (char2), glyphIndexes, offsets);
  70075. if (offsets.size() > 1)
  70076. addKerningPair (c, char2, offsets[1] - glyphWidth);
  70077. }
  70078. }
  70079. }
  70080. }
  70081. bool CustomTypeface::writeToStream (OutputStream& outputStream)
  70082. {
  70083. GZIPCompressorOutputStream out (&outputStream);
  70084. out.writeString (name);
  70085. out.writeBool (isBold);
  70086. out.writeBool (isItalic);
  70087. out.writeFloat (ascent);
  70088. out.writeShort ((short) (unsigned short) defaultCharacter);
  70089. out.writeInt (glyphs.size());
  70090. int i, numKerningPairs = 0;
  70091. for (i = 0; i < glyphs.size(); ++i)
  70092. {
  70093. const GlyphInfo* const g = glyphs.getUnchecked (i);
  70094. out.writeShort ((short) (unsigned short) g->character);
  70095. out.writeFloat (g->width);
  70096. g->path.writePathToStream (out);
  70097. numKerningPairs += g->kerningPairs.size();
  70098. }
  70099. out.writeInt (numKerningPairs);
  70100. for (i = 0; i < glyphs.size(); ++i)
  70101. {
  70102. const GlyphInfo* const g = glyphs.getUnchecked (i);
  70103. for (int j = 0; j < g->kerningPairs.size(); ++j)
  70104. {
  70105. const GlyphInfo::KerningPair& p = g->kerningPairs.getReference (j);
  70106. out.writeShort ((short) (unsigned short) g->character);
  70107. out.writeShort ((short) (unsigned short) p.character2);
  70108. out.writeFloat (p.kerningAmount);
  70109. }
  70110. }
  70111. return true;
  70112. }
  70113. float CustomTypeface::getAscent() const
  70114. {
  70115. return ascent;
  70116. }
  70117. float CustomTypeface::getDescent() const
  70118. {
  70119. return 1.0f - ascent;
  70120. }
  70121. float CustomTypeface::getStringWidth (const String& text)
  70122. {
  70123. float x = 0;
  70124. const juce_wchar* t = (const juce_wchar*) text;
  70125. while (*t != 0)
  70126. {
  70127. const GlyphInfo* const glyph = findGlyphSubstituting (*t++);
  70128. if (glyph != 0)
  70129. x += glyph->getHorizontalSpacing (*t);
  70130. }
  70131. return x;
  70132. }
  70133. void CustomTypeface::getGlyphPositions (const String& text, Array <int>& resultGlyphs, Array<float>& xOffsets)
  70134. {
  70135. xOffsets.add (0);
  70136. float x = 0;
  70137. const juce_wchar* t = (const juce_wchar*) text;
  70138. while (*t != 0)
  70139. {
  70140. const juce_wchar c = *t++;
  70141. const GlyphInfo* const glyph = findGlyphSubstituting (c);
  70142. if (glyph != 0)
  70143. {
  70144. x += glyph->getHorizontalSpacing (*t);
  70145. resultGlyphs.add ((int) glyph->character);
  70146. xOffsets.add (x);
  70147. }
  70148. }
  70149. }
  70150. bool CustomTypeface::getOutlineForGlyph (int glyphNumber, Path& path)
  70151. {
  70152. const GlyphInfo* const glyph = findGlyphSubstituting ((juce_wchar) glyphNumber);
  70153. if (glyph != 0)
  70154. {
  70155. path = glyph->path;
  70156. return true;
  70157. }
  70158. return false;
  70159. }
  70160. END_JUCE_NAMESPACE
  70161. /*** End of inlined file: juce_Typeface.cpp ***/
  70162. /*** Start of inlined file: juce_AffineTransform.cpp ***/
  70163. BEGIN_JUCE_NAMESPACE
  70164. AffineTransform::AffineTransform() throw()
  70165. : mat00 (1.0f),
  70166. mat01 (0),
  70167. mat02 (0),
  70168. mat10 (0),
  70169. mat11 (1.0f),
  70170. mat12 (0)
  70171. {
  70172. }
  70173. AffineTransform::AffineTransform (const AffineTransform& other) throw()
  70174. : mat00 (other.mat00),
  70175. mat01 (other.mat01),
  70176. mat02 (other.mat02),
  70177. mat10 (other.mat10),
  70178. mat11 (other.mat11),
  70179. mat12 (other.mat12)
  70180. {
  70181. }
  70182. AffineTransform::AffineTransform (const float mat00_,
  70183. const float mat01_,
  70184. const float mat02_,
  70185. const float mat10_,
  70186. const float mat11_,
  70187. const float mat12_) throw()
  70188. : mat00 (mat00_),
  70189. mat01 (mat01_),
  70190. mat02 (mat02_),
  70191. mat10 (mat10_),
  70192. mat11 (mat11_),
  70193. mat12 (mat12_)
  70194. {
  70195. }
  70196. AffineTransform& AffineTransform::operator= (const AffineTransform& other) throw()
  70197. {
  70198. mat00 = other.mat00;
  70199. mat01 = other.mat01;
  70200. mat02 = other.mat02;
  70201. mat10 = other.mat10;
  70202. mat11 = other.mat11;
  70203. mat12 = other.mat12;
  70204. return *this;
  70205. }
  70206. bool AffineTransform::operator== (const AffineTransform& other) const throw()
  70207. {
  70208. return mat00 == other.mat00
  70209. && mat01 == other.mat01
  70210. && mat02 == other.mat02
  70211. && mat10 == other.mat10
  70212. && mat11 == other.mat11
  70213. && mat12 == other.mat12;
  70214. }
  70215. bool AffineTransform::operator!= (const AffineTransform& other) const throw()
  70216. {
  70217. return ! operator== (other);
  70218. }
  70219. bool AffineTransform::isIdentity() const throw()
  70220. {
  70221. return (mat01 == 0)
  70222. && (mat02 == 0)
  70223. && (mat10 == 0)
  70224. && (mat12 == 0)
  70225. && (mat00 == 1.0f)
  70226. && (mat11 == 1.0f);
  70227. }
  70228. const AffineTransform AffineTransform::identity;
  70229. const AffineTransform AffineTransform::followedBy (const AffineTransform& other) const throw()
  70230. {
  70231. return AffineTransform (other.mat00 * mat00 + other.mat01 * mat10,
  70232. other.mat00 * mat01 + other.mat01 * mat11,
  70233. other.mat00 * mat02 + other.mat01 * mat12 + other.mat02,
  70234. other.mat10 * mat00 + other.mat11 * mat10,
  70235. other.mat10 * mat01 + other.mat11 * mat11,
  70236. other.mat10 * mat02 + other.mat11 * mat12 + other.mat12);
  70237. }
  70238. const AffineTransform AffineTransform::followedBy (const float omat00,
  70239. const float omat01,
  70240. const float omat02,
  70241. const float omat10,
  70242. const float omat11,
  70243. const float omat12) const throw()
  70244. {
  70245. return AffineTransform (omat00 * mat00 + omat01 * mat10,
  70246. omat00 * mat01 + omat01 * mat11,
  70247. omat00 * mat02 + omat01 * mat12 + omat02,
  70248. omat10 * mat00 + omat11 * mat10,
  70249. omat10 * mat01 + omat11 * mat11,
  70250. omat10 * mat02 + omat11 * mat12 + omat12);
  70251. }
  70252. const AffineTransform AffineTransform::translated (const float dx,
  70253. const float dy) const throw()
  70254. {
  70255. return AffineTransform (mat00, mat01, mat02 + dx,
  70256. mat10, mat11, mat12 + dy);
  70257. }
  70258. const AffineTransform AffineTransform::translation (const float dx,
  70259. const float dy) throw()
  70260. {
  70261. return AffineTransform (1.0f, 0, dx,
  70262. 0, 1.0f, dy);
  70263. }
  70264. const AffineTransform AffineTransform::rotated (const float rad) const throw()
  70265. {
  70266. const float cosRad = cosf (rad);
  70267. const float sinRad = sinf (rad);
  70268. return followedBy (cosRad, -sinRad, 0,
  70269. sinRad, cosRad, 0);
  70270. }
  70271. const AffineTransform AffineTransform::rotation (const float rad) throw()
  70272. {
  70273. const float cosRad = cosf (rad);
  70274. const float sinRad = sinf (rad);
  70275. return AffineTransform (cosRad, -sinRad, 0,
  70276. sinRad, cosRad, 0);
  70277. }
  70278. const AffineTransform AffineTransform::rotated (const float angle,
  70279. const float pivotX,
  70280. const float pivotY) const throw()
  70281. {
  70282. return translated (-pivotX, -pivotY)
  70283. .rotated (angle)
  70284. .translated (pivotX, pivotY);
  70285. }
  70286. const AffineTransform AffineTransform::rotation (const float angle,
  70287. const float pivotX,
  70288. const float pivotY) throw()
  70289. {
  70290. return translation (-pivotX, -pivotY)
  70291. .rotated (angle)
  70292. .translated (pivotX, pivotY);
  70293. }
  70294. const AffineTransform AffineTransform::scaled (const float factorX,
  70295. const float factorY) const throw()
  70296. {
  70297. return AffineTransform (factorX * mat00, factorX * mat01, factorX * mat02,
  70298. factorY * mat10, factorY * mat11, factorY * mat12);
  70299. }
  70300. const AffineTransform AffineTransform::scale (const float factorX,
  70301. const float factorY) throw()
  70302. {
  70303. return AffineTransform (factorX, 0, 0,
  70304. 0, factorY, 0);
  70305. }
  70306. const AffineTransform AffineTransform::sheared (const float shearX,
  70307. const float shearY) const throw()
  70308. {
  70309. return followedBy (1.0f, shearX, 0,
  70310. shearY, 1.0f, 0);
  70311. }
  70312. const AffineTransform AffineTransform::inverted() const throw()
  70313. {
  70314. double determinant = (mat00 * mat11 - mat10 * mat01);
  70315. if (determinant != 0.0)
  70316. {
  70317. determinant = 1.0 / determinant;
  70318. const float dst00 = (float) (mat11 * determinant);
  70319. const float dst10 = (float) (-mat10 * determinant);
  70320. const float dst01 = (float) (-mat01 * determinant);
  70321. const float dst11 = (float) (mat00 * determinant);
  70322. return AffineTransform (dst00, dst01, -mat02 * dst00 - mat12 * dst01,
  70323. dst10, dst11, -mat02 * dst10 - mat12 * dst11);
  70324. }
  70325. else
  70326. {
  70327. // singularity..
  70328. return *this;
  70329. }
  70330. }
  70331. bool AffineTransform::isSingularity() const throw()
  70332. {
  70333. return (mat00 * mat11 - mat10 * mat01) == 0.0;
  70334. }
  70335. bool AffineTransform::isOnlyTranslation() const throw()
  70336. {
  70337. return (mat01 == 0)
  70338. && (mat10 == 0)
  70339. && (mat00 == 1.0f)
  70340. && (mat11 == 1.0f);
  70341. }
  70342. void AffineTransform::transformPoint (float& x,
  70343. float& y) const throw()
  70344. {
  70345. const float oldX = x;
  70346. x = mat00 * oldX + mat01 * y + mat02;
  70347. y = mat10 * oldX + mat11 * y + mat12;
  70348. }
  70349. void AffineTransform::transformPoint (double& x,
  70350. double& y) const throw()
  70351. {
  70352. const double oldX = x;
  70353. x = mat00 * oldX + mat01 * y + mat02;
  70354. y = mat10 * oldX + mat11 * y + mat12;
  70355. }
  70356. END_JUCE_NAMESPACE
  70357. /*** End of inlined file: juce_AffineTransform.cpp ***/
  70358. /*** Start of inlined file: juce_BorderSize.cpp ***/
  70359. BEGIN_JUCE_NAMESPACE
  70360. BorderSize::BorderSize() throw()
  70361. : top (0),
  70362. left (0),
  70363. bottom (0),
  70364. right (0)
  70365. {
  70366. }
  70367. BorderSize::BorderSize (const BorderSize& other) throw()
  70368. : top (other.top),
  70369. left (other.left),
  70370. bottom (other.bottom),
  70371. right (other.right)
  70372. {
  70373. }
  70374. BorderSize::BorderSize (const int topGap,
  70375. const int leftGap,
  70376. const int bottomGap,
  70377. const int rightGap) throw()
  70378. : top (topGap),
  70379. left (leftGap),
  70380. bottom (bottomGap),
  70381. right (rightGap)
  70382. {
  70383. }
  70384. BorderSize::BorderSize (const int allGaps) throw()
  70385. : top (allGaps),
  70386. left (allGaps),
  70387. bottom (allGaps),
  70388. right (allGaps)
  70389. {
  70390. }
  70391. BorderSize::~BorderSize() throw()
  70392. {
  70393. }
  70394. void BorderSize::setTop (const int newTopGap) throw()
  70395. {
  70396. top = newTopGap;
  70397. }
  70398. void BorderSize::setLeft (const int newLeftGap) throw()
  70399. {
  70400. left = newLeftGap;
  70401. }
  70402. void BorderSize::setBottom (const int newBottomGap) throw()
  70403. {
  70404. bottom = newBottomGap;
  70405. }
  70406. void BorderSize::setRight (const int newRightGap) throw()
  70407. {
  70408. right = newRightGap;
  70409. }
  70410. const Rectangle<int> BorderSize::subtractedFrom (const Rectangle<int>& r) const throw()
  70411. {
  70412. return Rectangle<int> (r.getX() + left,
  70413. r.getY() + top,
  70414. r.getWidth() - (left + right),
  70415. r.getHeight() - (top + bottom));
  70416. }
  70417. void BorderSize::subtractFrom (Rectangle<int>& r) const throw()
  70418. {
  70419. r.setBounds (r.getX() + left,
  70420. r.getY() + top,
  70421. r.getWidth() - (left + right),
  70422. r.getHeight() - (top + bottom));
  70423. }
  70424. const Rectangle<int> BorderSize::addedTo (const Rectangle<int>& r) const throw()
  70425. {
  70426. return Rectangle<int> (r.getX() - left,
  70427. r.getY() - top,
  70428. r.getWidth() + (left + right),
  70429. r.getHeight() + (top + bottom));
  70430. }
  70431. void BorderSize::addTo (Rectangle<int>& r) const throw()
  70432. {
  70433. r.setBounds (r.getX() - left,
  70434. r.getY() - top,
  70435. r.getWidth() + (left + right),
  70436. r.getHeight() + (top + bottom));
  70437. }
  70438. bool BorderSize::operator== (const BorderSize& other) const throw()
  70439. {
  70440. return top == other.top
  70441. && left == other.left
  70442. && bottom == other.bottom
  70443. && right == other.right;
  70444. }
  70445. bool BorderSize::operator!= (const BorderSize& other) const throw()
  70446. {
  70447. return ! operator== (other);
  70448. }
  70449. END_JUCE_NAMESPACE
  70450. /*** End of inlined file: juce_BorderSize.cpp ***/
  70451. /*** Start of inlined file: juce_Line.cpp ***/
  70452. BEGIN_JUCE_NAMESPACE
  70453. static bool juce_lineIntersection (const float x1, const float y1,
  70454. const float x2, const float y2,
  70455. const float x3, const float y3,
  70456. const float x4, const float y4,
  70457. float& intersectionX,
  70458. float& intersectionY) throw()
  70459. {
  70460. if (x2 != x3 || y2 != y3)
  70461. {
  70462. const float dx1 = x2 - x1;
  70463. const float dy1 = y2 - y1;
  70464. const float dx2 = x4 - x3;
  70465. const float dy2 = y4 - y3;
  70466. const float divisor = dx1 * dy2 - dx2 * dy1;
  70467. if (divisor == 0)
  70468. {
  70469. if (! ((dx1 == 0 && dy1 == 0) || (dx2 == 0 && dy2 == 0)))
  70470. {
  70471. if (dy1 == 0 && dy2 != 0)
  70472. {
  70473. const float along = (y1 - y3) / dy2;
  70474. intersectionX = x3 + along * dx2;
  70475. intersectionY = y1;
  70476. return along >= 0 && along <= 1.0f;
  70477. }
  70478. else if (dy2 == 0 && dy1 != 0)
  70479. {
  70480. const float along = (y3 - y1) / dy1;
  70481. intersectionX = x1 + along * dx1;
  70482. intersectionY = y3;
  70483. return along >= 0 && along <= 1.0f;
  70484. }
  70485. else if (dx1 == 0 && dx2 != 0)
  70486. {
  70487. const float along = (x1 - x3) / dx2;
  70488. intersectionX = x1;
  70489. intersectionY = y3 + along * dy2;
  70490. return along >= 0 && along <= 1.0f;
  70491. }
  70492. else if (dx2 == 0 && dx1 != 0)
  70493. {
  70494. const float along = (x3 - x1) / dx1;
  70495. intersectionX = x3;
  70496. intersectionY = y1 + along * dy1;
  70497. return along >= 0 && along <= 1.0f;
  70498. }
  70499. }
  70500. intersectionX = 0.5f * (x2 + x3);
  70501. intersectionY = 0.5f * (y2 + y3);
  70502. return false;
  70503. }
  70504. const float along1 = ((y1 - y3) * dx2 - (x1 - x3) * dy2) / divisor;
  70505. intersectionX = x1 + along1 * dx1;
  70506. intersectionY = y1 + along1 * dy1;
  70507. if (along1 < 0 || along1 > 1.0f)
  70508. return false;
  70509. const float along2 = ((y1 - y3) * dx1 - (x1 - x3) * dy1) / divisor;
  70510. return along2 >= 0 && along2 <= 1.0f;
  70511. }
  70512. intersectionX = x2;
  70513. intersectionY = y2;
  70514. return true;
  70515. }
  70516. Line::Line() throw()
  70517. : startX (0.0f),
  70518. startY (0.0f),
  70519. endX (0.0f),
  70520. endY (0.0f)
  70521. {
  70522. }
  70523. Line::Line (const Line& other) throw()
  70524. : startX (other.startX),
  70525. startY (other.startY),
  70526. endX (other.endX),
  70527. endY (other.endY)
  70528. {
  70529. }
  70530. Line::Line (const float startX_, const float startY_,
  70531. const float endX_, const float endY_) throw()
  70532. : startX (startX_),
  70533. startY (startY_),
  70534. endX (endX_),
  70535. endY (endY_)
  70536. {
  70537. }
  70538. Line::Line (const Point<float>& start,
  70539. const Point<float>& end) throw()
  70540. : startX (start.getX()),
  70541. startY (start.getY()),
  70542. endX (end.getX()),
  70543. endY (end.getY())
  70544. {
  70545. }
  70546. Line& Line::operator= (const Line& other) throw()
  70547. {
  70548. startX = other.startX;
  70549. startY = other.startY;
  70550. endX = other.endX;
  70551. endY = other.endY;
  70552. return *this;
  70553. }
  70554. Line::~Line() throw()
  70555. {
  70556. }
  70557. const Point<float> Line::getStart() const throw()
  70558. {
  70559. return Point<float> (startX, startY);
  70560. }
  70561. const Point<float> Line::getEnd() const throw()
  70562. {
  70563. return Point<float> (endX, endY);
  70564. }
  70565. void Line::setStart (const float newStartX,
  70566. const float newStartY) throw()
  70567. {
  70568. startX = newStartX;
  70569. startY = newStartY;
  70570. }
  70571. void Line::setStart (const Point<float>& newStart) throw()
  70572. {
  70573. startX = newStart.getX();
  70574. startY = newStart.getY();
  70575. }
  70576. void Line::setEnd (const float newEndX,
  70577. const float newEndY) throw()
  70578. {
  70579. endX = newEndX;
  70580. endY = newEndY;
  70581. }
  70582. void Line::setEnd (const Point<float>& newEnd) throw()
  70583. {
  70584. endX = newEnd.getX();
  70585. endY = newEnd.getY();
  70586. }
  70587. bool Line::operator== (const Line& other) const throw()
  70588. {
  70589. return startX == other.startX
  70590. && startY == other.startY
  70591. && endX == other.endX
  70592. && endY == other.endY;
  70593. }
  70594. bool Line::operator!= (const Line& other) const throw()
  70595. {
  70596. return startX != other.startX
  70597. || startY != other.startY
  70598. || endX != other.endX
  70599. || endY != other.endY;
  70600. }
  70601. void Line::applyTransform (const AffineTransform& transform) throw()
  70602. {
  70603. transform.transformPoint (startX, startY);
  70604. transform.transformPoint (endX, endY);
  70605. }
  70606. float Line::getLength() const throw()
  70607. {
  70608. return (float) juce_hypot (startX - endX,
  70609. startY - endY);
  70610. }
  70611. float Line::getAngle() const throw()
  70612. {
  70613. return atan2f (endX - startX,
  70614. endY - startY);
  70615. }
  70616. const Point<float> Line::getPointAlongLine (const float distanceFromStart) const throw()
  70617. {
  70618. const float alpha = distanceFromStart / getLength();
  70619. return Point<float> (startX + (endX - startX) * alpha,
  70620. startY + (endY - startY) * alpha);
  70621. }
  70622. const Point<float> Line::getPointAlongLine (const float offsetX,
  70623. const float offsetY) const throw()
  70624. {
  70625. const float dx = endX - startX;
  70626. const float dy = endY - startY;
  70627. const double length = juce_hypot (dx, dy);
  70628. if (length == 0)
  70629. return Point<float> (startX, startY);
  70630. else
  70631. return Point<float> (startX + (float) (((dx * offsetX) - (dy * offsetY)) / length),
  70632. startY + (float) (((dy * offsetX) + (dx * offsetY)) / length));
  70633. }
  70634. const Point<float> Line::getPointAlongLineProportionally (const float alpha) const throw()
  70635. {
  70636. return Point<float> (startX + (endX - startX) * alpha,
  70637. startY + (endY - startY) * alpha);
  70638. }
  70639. float Line::getDistanceFromLine (const float x,
  70640. const float y) const throw()
  70641. {
  70642. const double dx = endX - startX;
  70643. const double dy = endY - startY;
  70644. const double length = dx * dx + dy * dy;
  70645. if (length > 0)
  70646. {
  70647. const double prop = ((x - startX) * dx + (y - startY) * dy) / length;
  70648. if (prop >= 0.0f && prop < 1.0f)
  70649. {
  70650. return (float) juce_hypot (x - (startX + prop * dx),
  70651. y - (startY + prop * dy));
  70652. }
  70653. }
  70654. return (float) jmin (juce_hypot (x - startX, y - startY),
  70655. juce_hypot (x - endX, y - endY));
  70656. }
  70657. float Line::findNearestPointTo (const float x,
  70658. const float y) const throw()
  70659. {
  70660. const double dx = endX - startX;
  70661. const double dy = endY - startY;
  70662. const double length = dx * dx + dy * dy;
  70663. if (length <= 0.0)
  70664. return 0.0f;
  70665. return jlimit (0.0f, 1.0f,
  70666. (float) (((x - startX) * dx + (y - startY) * dy) / length));
  70667. }
  70668. const Line Line::withShortenedStart (const float distanceToShortenBy) const throw()
  70669. {
  70670. const float length = getLength();
  70671. return Line (getPointAlongLine (jmin (distanceToShortenBy, length)),
  70672. getEnd());
  70673. }
  70674. const Line Line::withShortenedEnd (const float distanceToShortenBy) const throw()
  70675. {
  70676. const float length = getLength();
  70677. return Line (getStart(),
  70678. getPointAlongLine (length - jmin (distanceToShortenBy, length)));
  70679. }
  70680. bool Line::clipToPath (const Path& path,
  70681. const bool keepSectionOutsidePath) throw()
  70682. {
  70683. const bool startInside = path.contains (startX, startY);
  70684. const bool endInside = path.contains (endX, endY);
  70685. if (startInside == endInside)
  70686. {
  70687. if (keepSectionOutsidePath != startInside)
  70688. {
  70689. // entirely outside the path
  70690. return false;
  70691. }
  70692. else
  70693. {
  70694. // entirely inside the path
  70695. startX = 0.0f;
  70696. startY = 0.0f;
  70697. endX = 0.0f;
  70698. endY = 0.0f;
  70699. return true;
  70700. }
  70701. }
  70702. else
  70703. {
  70704. bool changed = false;
  70705. PathFlatteningIterator iter (path, AffineTransform::identity);
  70706. while (iter.next())
  70707. {
  70708. float ix, iy;
  70709. if (intersects (Line (iter.x1, iter.y1,
  70710. iter.x2, iter.y2),
  70711. ix, iy))
  70712. {
  70713. if ((startInside && keepSectionOutsidePath)
  70714. || (endInside && ! keepSectionOutsidePath))
  70715. {
  70716. setStart (ix, iy);
  70717. }
  70718. else
  70719. {
  70720. setEnd (ix, iy);
  70721. }
  70722. changed = true;
  70723. }
  70724. }
  70725. return changed;
  70726. }
  70727. }
  70728. bool Line::intersects (const Line& line,
  70729. float& intersectionX,
  70730. float& intersectionY) const throw()
  70731. {
  70732. return juce_lineIntersection (startX, startY,
  70733. endX, endY,
  70734. line.startX, line.startY,
  70735. line.endX, line.endY,
  70736. intersectionX,
  70737. intersectionY);
  70738. }
  70739. bool Line::isVertical() const throw()
  70740. {
  70741. return startX == endX;
  70742. }
  70743. bool Line::isHorizontal() const throw()
  70744. {
  70745. return startY == endY;
  70746. }
  70747. bool Line::isPointAbove (const float x, const float y) const throw()
  70748. {
  70749. return startX != endX
  70750. && y < ((endY - startY) * (x - startX)) / (endX - startX) + startY;
  70751. }
  70752. END_JUCE_NAMESPACE
  70753. /*** End of inlined file: juce_Line.cpp ***/
  70754. /*** Start of inlined file: juce_Path.cpp ***/
  70755. BEGIN_JUCE_NAMESPACE
  70756. // tests that some co-ords aren't NaNs
  70757. #define CHECK_COORDS_ARE_VALID(x, y) \
  70758. jassert (x == x && y == y);
  70759. namespace PathHelpers
  70760. {
  70761. static const float ellipseAngularIncrement = 0.05f;
  70762. static void perpendicularOffset (const float x1, const float y1,
  70763. const float x2, const float y2,
  70764. const float offsetX, const float offsetY,
  70765. float& resultX, float& resultY) throw()
  70766. {
  70767. const float dx = x2 - x1;
  70768. const float dy = y2 - y1;
  70769. const float len = juce_hypotf (dx, dy);
  70770. if (len == 0)
  70771. {
  70772. resultX = x1;
  70773. resultY = y1;
  70774. }
  70775. else
  70776. {
  70777. resultX = x1 + ((dx * offsetX) - (dy * offsetY)) / len;
  70778. resultY = y1 + ((dy * offsetX) + (dx * offsetY)) / len;
  70779. }
  70780. }
  70781. static const String nextToken (const tchar*& t)
  70782. {
  70783. while (CharacterFunctions::isWhitespace (*t))
  70784. ++t;
  70785. const tchar* const start = t;
  70786. while (*t != 0 && ! CharacterFunctions::isWhitespace (*t))
  70787. ++t;
  70788. const int length = (int) (t - start);
  70789. while (CharacterFunctions::isWhitespace (*t))
  70790. ++t;
  70791. return String (start, length);
  70792. }
  70793. }
  70794. const float Path::lineMarker = 100001.0f;
  70795. const float Path::moveMarker = 100002.0f;
  70796. const float Path::quadMarker = 100003.0f;
  70797. const float Path::cubicMarker = 100004.0f;
  70798. const float Path::closeSubPathMarker = 100005.0f;
  70799. Path::Path()
  70800. : numElements (0),
  70801. pathXMin (0),
  70802. pathXMax (0),
  70803. pathYMin (0),
  70804. pathYMax (0),
  70805. useNonZeroWinding (true)
  70806. {
  70807. }
  70808. Path::~Path()
  70809. {
  70810. }
  70811. Path::Path (const Path& other)
  70812. : numElements (other.numElements),
  70813. pathXMin (other.pathXMin),
  70814. pathXMax (other.pathXMax),
  70815. pathYMin (other.pathYMin),
  70816. pathYMax (other.pathYMax),
  70817. useNonZeroWinding (other.useNonZeroWinding)
  70818. {
  70819. if (numElements > 0)
  70820. {
  70821. data.setAllocatedSize (numElements);
  70822. memcpy (data.elements, other.data.elements, numElements * sizeof (float));
  70823. }
  70824. }
  70825. Path& Path::operator= (const Path& other)
  70826. {
  70827. if (this != &other)
  70828. {
  70829. data.ensureAllocatedSize (other.numElements);
  70830. numElements = other.numElements;
  70831. pathXMin = other.pathXMin;
  70832. pathXMax = other.pathXMax;
  70833. pathYMin = other.pathYMin;
  70834. pathYMax = other.pathYMax;
  70835. useNonZeroWinding = other.useNonZeroWinding;
  70836. if (numElements > 0)
  70837. memcpy (data.elements, other.data.elements, numElements * sizeof (float));
  70838. }
  70839. return *this;
  70840. }
  70841. void Path::clear() throw()
  70842. {
  70843. numElements = 0;
  70844. pathXMin = 0;
  70845. pathYMin = 0;
  70846. pathYMax = 0;
  70847. pathXMax = 0;
  70848. }
  70849. void Path::swapWithPath (Path& other)
  70850. {
  70851. data.swapWith (other.data);
  70852. swapVariables <size_t> (numElements, other.numElements);
  70853. swapVariables <float> (pathXMin, other.pathXMin);
  70854. swapVariables <float> (pathXMax, other.pathXMax);
  70855. swapVariables <float> (pathYMin, other.pathYMin);
  70856. swapVariables <float> (pathYMax, other.pathYMax);
  70857. swapVariables <bool> (useNonZeroWinding, other.useNonZeroWinding);
  70858. }
  70859. void Path::setUsingNonZeroWinding (const bool isNonZero) throw()
  70860. {
  70861. useNonZeroWinding = isNonZero;
  70862. }
  70863. void Path::scaleToFit (const float x, const float y, const float w, const float h,
  70864. const bool preserveProportions) throw()
  70865. {
  70866. applyTransform (getTransformToScaleToFit (x, y, w, h, preserveProportions));
  70867. }
  70868. bool Path::isEmpty() const throw()
  70869. {
  70870. size_t i = 0;
  70871. while (i < numElements)
  70872. {
  70873. const float type = data.elements [i++];
  70874. if (type == moveMarker)
  70875. {
  70876. i += 2;
  70877. }
  70878. else if (type == lineMarker
  70879. || type == quadMarker
  70880. || type == cubicMarker)
  70881. {
  70882. return false;
  70883. }
  70884. }
  70885. return true;
  70886. }
  70887. const Rectangle<float> Path::getBounds() const throw()
  70888. {
  70889. return Rectangle<float> (pathXMin, pathYMin,
  70890. pathXMax - pathXMin,
  70891. pathYMax - pathYMin);
  70892. }
  70893. const Rectangle<float> Path::getBoundsTransformed (const AffineTransform& transform) const throw()
  70894. {
  70895. return getBounds().transformed (transform);
  70896. }
  70897. void Path::startNewSubPath (const float x, const float y)
  70898. {
  70899. CHECK_COORDS_ARE_VALID (x, y);
  70900. if (numElements == 0)
  70901. {
  70902. pathXMin = pathXMax = x;
  70903. pathYMin = pathYMax = y;
  70904. }
  70905. else
  70906. {
  70907. pathXMin = jmin (pathXMin, x);
  70908. pathXMax = jmax (pathXMax, x);
  70909. pathYMin = jmin (pathYMin, y);
  70910. pathYMax = jmax (pathYMax, y);
  70911. }
  70912. data.ensureAllocatedSize (numElements + 3);
  70913. data.elements [numElements++] = moveMarker;
  70914. data.elements [numElements++] = x;
  70915. data.elements [numElements++] = y;
  70916. }
  70917. void Path::lineTo (const float x, const float y)
  70918. {
  70919. CHECK_COORDS_ARE_VALID (x, y);
  70920. if (numElements == 0)
  70921. startNewSubPath (0, 0);
  70922. data.ensureAllocatedSize (numElements + 3);
  70923. data.elements [numElements++] = lineMarker;
  70924. data.elements [numElements++] = x;
  70925. data.elements [numElements++] = y;
  70926. pathXMin = jmin (pathXMin, x);
  70927. pathXMax = jmax (pathXMax, x);
  70928. pathYMin = jmin (pathYMin, y);
  70929. pathYMax = jmax (pathYMax, y);
  70930. }
  70931. void Path::quadraticTo (const float x1, const float y1,
  70932. const float x2, const float y2)
  70933. {
  70934. CHECK_COORDS_ARE_VALID (x1, y1);
  70935. CHECK_COORDS_ARE_VALID (x2, y2);
  70936. if (numElements == 0)
  70937. startNewSubPath (0, 0);
  70938. data.ensureAllocatedSize (numElements + 5);
  70939. data.elements [numElements++] = quadMarker;
  70940. data.elements [numElements++] = x1;
  70941. data.elements [numElements++] = y1;
  70942. data.elements [numElements++] = x2;
  70943. data.elements [numElements++] = y2;
  70944. pathXMin = jmin (pathXMin, x1, x2);
  70945. pathXMax = jmax (pathXMax, x1, x2);
  70946. pathYMin = jmin (pathYMin, y1, y2);
  70947. pathYMax = jmax (pathYMax, y1, y2);
  70948. }
  70949. void Path::cubicTo (const float x1, const float y1,
  70950. const float x2, const float y2,
  70951. const float x3, const float y3)
  70952. {
  70953. CHECK_COORDS_ARE_VALID (x1, y1);
  70954. CHECK_COORDS_ARE_VALID (x2, y2);
  70955. CHECK_COORDS_ARE_VALID (x3, y3);
  70956. if (numElements == 0)
  70957. startNewSubPath (0, 0);
  70958. data.ensureAllocatedSize (numElements + 7);
  70959. data.elements [numElements++] = cubicMarker;
  70960. data.elements [numElements++] = x1;
  70961. data.elements [numElements++] = y1;
  70962. data.elements [numElements++] = x2;
  70963. data.elements [numElements++] = y2;
  70964. data.elements [numElements++] = x3;
  70965. data.elements [numElements++] = y3;
  70966. pathXMin = jmin (pathXMin, x1, x2, x3);
  70967. pathXMax = jmax (pathXMax, x1, x2, x3);
  70968. pathYMin = jmin (pathYMin, y1, y2, y3);
  70969. pathYMax = jmax (pathYMax, y1, y2, y3);
  70970. }
  70971. void Path::closeSubPath()
  70972. {
  70973. if (numElements > 0
  70974. && data.elements [numElements - 1] != closeSubPathMarker)
  70975. {
  70976. data.ensureAllocatedSize (numElements + 1);
  70977. data.elements [numElements++] = closeSubPathMarker;
  70978. }
  70979. }
  70980. const Point<float> Path::getCurrentPosition() const
  70981. {
  70982. int i = numElements - 1;
  70983. if (i > 0 && data.elements[i] == closeSubPathMarker)
  70984. {
  70985. while (i >= 0)
  70986. {
  70987. if (data.elements[i] == moveMarker)
  70988. {
  70989. i += 2;
  70990. break;
  70991. }
  70992. --i;
  70993. }
  70994. }
  70995. if (i > 0)
  70996. return Point<float> (data.elements [i - 1], data.elements [i]);
  70997. return Point<float>();
  70998. }
  70999. void Path::addRectangle (const float x, const float y,
  71000. const float w, const float h)
  71001. {
  71002. float x1 = x, y1 = y, x2 = x + w, y2 = y + h;
  71003. if (w < 0)
  71004. swapVariables (x1, x2);
  71005. if (h < 0)
  71006. swapVariables (y1, y2);
  71007. data.ensureAllocatedSize (numElements + 13);
  71008. if (numElements == 0)
  71009. {
  71010. pathXMin = x1;
  71011. pathXMax = x2;
  71012. pathYMin = y1;
  71013. pathYMax = y2;
  71014. }
  71015. else
  71016. {
  71017. pathXMin = jmin (pathXMin, x1);
  71018. pathXMax = jmax (pathXMax, x2);
  71019. pathYMin = jmin (pathYMin, y1);
  71020. pathYMax = jmax (pathYMax, y2);
  71021. }
  71022. data.elements [numElements++] = moveMarker;
  71023. data.elements [numElements++] = x1;
  71024. data.elements [numElements++] = y2;
  71025. data.elements [numElements++] = lineMarker;
  71026. data.elements [numElements++] = x1;
  71027. data.elements [numElements++] = y1;
  71028. data.elements [numElements++] = lineMarker;
  71029. data.elements [numElements++] = x2;
  71030. data.elements [numElements++] = y1;
  71031. data.elements [numElements++] = lineMarker;
  71032. data.elements [numElements++] = x2;
  71033. data.elements [numElements++] = y2;
  71034. data.elements [numElements++] = closeSubPathMarker;
  71035. }
  71036. void Path::addRectangle (const Rectangle<int>& rectangle)
  71037. {
  71038. addRectangle ((float) rectangle.getX(), (float) rectangle.getY(),
  71039. (float) rectangle.getWidth(), (float) rectangle.getHeight());
  71040. }
  71041. void Path::addRoundedRectangle (const float x, const float y,
  71042. const float w, const float h,
  71043. float csx,
  71044. float csy)
  71045. {
  71046. csx = jmin (csx, w * 0.5f);
  71047. csy = jmin (csy, h * 0.5f);
  71048. const float cs45x = csx * 0.45f;
  71049. const float cs45y = csy * 0.45f;
  71050. const float x2 = x + w;
  71051. const float y2 = y + h;
  71052. startNewSubPath (x + csx, y);
  71053. lineTo (x2 - csx, y);
  71054. cubicTo (x2 - cs45x, y, x2, y + cs45y, x2, y + csy);
  71055. lineTo (x2, y2 - csy);
  71056. cubicTo (x2, y2 - cs45y, x2 - cs45x, y2, x2 - csx, y2);
  71057. lineTo (x + csx, y2);
  71058. cubicTo (x + cs45x, y2, x, y2 - cs45y, x, y2 - csy);
  71059. lineTo (x, y + csy);
  71060. cubicTo (x, y + cs45y, x + cs45x, y, x + csx, y);
  71061. closeSubPath();
  71062. }
  71063. void Path::addRoundedRectangle (const float x, const float y,
  71064. const float w, const float h,
  71065. float cs)
  71066. {
  71067. addRoundedRectangle (x, y, w, h, cs, cs);
  71068. }
  71069. void Path::addTriangle (const float x1, const float y1,
  71070. const float x2, const float y2,
  71071. const float x3, const float y3)
  71072. {
  71073. startNewSubPath (x1, y1);
  71074. lineTo (x2, y2);
  71075. lineTo (x3, y3);
  71076. closeSubPath();
  71077. }
  71078. void Path::addQuadrilateral (const float x1, const float y1,
  71079. const float x2, const float y2,
  71080. const float x3, const float y3,
  71081. const float x4, const float y4)
  71082. {
  71083. startNewSubPath (x1, y1);
  71084. lineTo (x2, y2);
  71085. lineTo (x3, y3);
  71086. lineTo (x4, y4);
  71087. closeSubPath();
  71088. }
  71089. void Path::addEllipse (const float x, const float y,
  71090. const float w, const float h)
  71091. {
  71092. const float hw = w * 0.5f;
  71093. const float hw55 = hw * 0.55f;
  71094. const float hh = h * 0.5f;
  71095. const float hh45 = hh * 0.55f;
  71096. const float cx = x + hw;
  71097. const float cy = y + hh;
  71098. startNewSubPath (cx, cy - hh);
  71099. cubicTo (cx + hw55, cy - hh, cx + hw, cy - hh45, cx + hw, cy);
  71100. cubicTo (cx + hw, cy + hh45, cx + hw55, cy + hh, cx, cy + hh);
  71101. cubicTo (cx - hw55, cy + hh, cx - hw, cy + hh45, cx - hw, cy);
  71102. cubicTo (cx - hw, cy - hh45, cx - hw55, cy - hh, cx, cy - hh);
  71103. closeSubPath();
  71104. }
  71105. void Path::addArc (const float x, const float y,
  71106. const float w, const float h,
  71107. const float fromRadians,
  71108. const float toRadians,
  71109. const bool startAsNewSubPath)
  71110. {
  71111. const float radiusX = w / 2.0f;
  71112. const float radiusY = h / 2.0f;
  71113. addCentredArc (x + radiusX,
  71114. y + radiusY,
  71115. radiusX, radiusY,
  71116. 0.0f,
  71117. fromRadians, toRadians,
  71118. startAsNewSubPath);
  71119. }
  71120. void Path::addCentredArc (const float centreX, const float centreY,
  71121. const float radiusX, const float radiusY,
  71122. const float rotationOfEllipse,
  71123. const float fromRadians,
  71124. const float toRadians,
  71125. const bool startAsNewSubPath)
  71126. {
  71127. if (radiusX > 0.0f && radiusY > 0.0f)
  71128. {
  71129. const AffineTransform rotation (AffineTransform::rotation (rotationOfEllipse, centreX, centreY));
  71130. float angle = fromRadians;
  71131. if (startAsNewSubPath)
  71132. {
  71133. float x = centreX + radiusX * sinf (angle);
  71134. float y = centreY - radiusY * cosf (angle);
  71135. if (rotationOfEllipse != 0)
  71136. rotation.transformPoint (x, y);
  71137. startNewSubPath (x, y);
  71138. }
  71139. if (fromRadians < toRadians)
  71140. {
  71141. if (startAsNewSubPath)
  71142. angle += PathHelpers::ellipseAngularIncrement;
  71143. while (angle < toRadians)
  71144. {
  71145. float x = centreX + radiusX * sinf (angle);
  71146. float y = centreY - radiusY * cosf (angle);
  71147. if (rotationOfEllipse != 0)
  71148. rotation.transformPoint (x, y);
  71149. lineTo (x, y);
  71150. angle += PathHelpers::ellipseAngularIncrement;
  71151. }
  71152. }
  71153. else
  71154. {
  71155. if (startAsNewSubPath)
  71156. angle -= PathHelpers::ellipseAngularIncrement;
  71157. while (angle > toRadians)
  71158. {
  71159. float x = centreX + radiusX * sinf (angle);
  71160. float y = centreY - radiusY * cosf (angle);
  71161. if (rotationOfEllipse != 0)
  71162. rotation.transformPoint (x, y);
  71163. lineTo (x, y);
  71164. angle -= PathHelpers::ellipseAngularIncrement;
  71165. }
  71166. }
  71167. float x = centreX + radiusX * sinf (toRadians);
  71168. float y = centreY - radiusY * cosf (toRadians);
  71169. if (rotationOfEllipse != 0)
  71170. rotation.transformPoint (x, y);
  71171. lineTo (x, y);
  71172. }
  71173. }
  71174. void Path::addPieSegment (const float x, const float y,
  71175. const float width, const float height,
  71176. const float fromRadians,
  71177. const float toRadians,
  71178. const float innerCircleProportionalSize)
  71179. {
  71180. float hw = width * 0.5f;
  71181. float hh = height * 0.5f;
  71182. const float centreX = x + hw;
  71183. const float centreY = y + hh;
  71184. startNewSubPath (centreX + hw * sinf (fromRadians),
  71185. centreY - hh * cosf (fromRadians));
  71186. addArc (x, y, width, height, fromRadians, toRadians);
  71187. if (fabs (fromRadians - toRadians) > float_Pi * 1.999f)
  71188. {
  71189. closeSubPath();
  71190. if (innerCircleProportionalSize > 0)
  71191. {
  71192. hw *= innerCircleProportionalSize;
  71193. hh *= innerCircleProportionalSize;
  71194. startNewSubPath (centreX + hw * sinf (toRadians),
  71195. centreY - hh * cosf (toRadians));
  71196. addArc (centreX - hw, centreY - hh, hw * 2.0f, hh * 2.0f,
  71197. toRadians, fromRadians);
  71198. }
  71199. }
  71200. else
  71201. {
  71202. if (innerCircleProportionalSize > 0)
  71203. {
  71204. hw *= innerCircleProportionalSize;
  71205. hh *= innerCircleProportionalSize;
  71206. addArc (centreX - hw, centreY - hh, hw * 2.0f, hh * 2.0f,
  71207. toRadians, fromRadians);
  71208. }
  71209. else
  71210. {
  71211. lineTo (centreX, centreY);
  71212. }
  71213. }
  71214. closeSubPath();
  71215. }
  71216. void Path::addLineSegment (const float startX, const float startY,
  71217. const float endX, const float endY,
  71218. float lineThickness)
  71219. {
  71220. lineThickness *= 0.5f;
  71221. float x, y;
  71222. PathHelpers::perpendicularOffset (startX, startY, endX, endY,
  71223. 0, lineThickness, x, y);
  71224. startNewSubPath (x, y);
  71225. PathHelpers::perpendicularOffset (startX, startY, endX, endY,
  71226. 0, -lineThickness, x, y);
  71227. lineTo (x, y);
  71228. PathHelpers::perpendicularOffset (endX, endY, startX, startY,
  71229. 0, lineThickness, x, y);
  71230. lineTo (x, y);
  71231. PathHelpers::perpendicularOffset (endX, endY, startX, startY,
  71232. 0, -lineThickness, x, y);
  71233. lineTo (x, y);
  71234. closeSubPath();
  71235. }
  71236. void Path::addArrow (const float startX, const float startY,
  71237. const float endX, const float endY,
  71238. float lineThickness,
  71239. float arrowheadWidth,
  71240. float arrowheadLength)
  71241. {
  71242. lineThickness *= 0.5f;
  71243. arrowheadWidth *= 0.5f;
  71244. arrowheadLength = jmin (arrowheadLength, 0.8f * juce_hypotf (startX - endX,
  71245. startY - endY));
  71246. float x, y;
  71247. PathHelpers::perpendicularOffset (startX, startY, endX, endY,
  71248. 0, lineThickness, x, y);
  71249. startNewSubPath (x, y);
  71250. PathHelpers::perpendicularOffset (startX, startY, endX, endY,
  71251. 0, -lineThickness, x, y);
  71252. lineTo (x, y);
  71253. PathHelpers::perpendicularOffset (endX, endY, startX, startY,
  71254. arrowheadLength, lineThickness, x, y);
  71255. lineTo (x, y);
  71256. PathHelpers::perpendicularOffset (endX, endY, startX, startY,
  71257. arrowheadLength, arrowheadWidth, x, y);
  71258. lineTo (x, y);
  71259. PathHelpers::perpendicularOffset (endX, endY, startX, startY,
  71260. 0, 0, x, y);
  71261. lineTo (x, y);
  71262. PathHelpers::perpendicularOffset (endX, endY, startX, startY,
  71263. arrowheadLength, -arrowheadWidth, x, y);
  71264. lineTo (x, y);
  71265. PathHelpers::perpendicularOffset (endX, endY, startX, startY,
  71266. arrowheadLength, -lineThickness, x, y);
  71267. lineTo (x, y);
  71268. closeSubPath();
  71269. }
  71270. void Path::addStar (const float centreX,
  71271. const float centreY,
  71272. const int numberOfPoints,
  71273. const float innerRadius,
  71274. const float outerRadius,
  71275. const float startAngle)
  71276. {
  71277. jassert (numberOfPoints > 1); // this would be silly.
  71278. if (numberOfPoints > 1)
  71279. {
  71280. const float angleBetweenPoints = float_Pi * 2.0f / numberOfPoints;
  71281. for (int i = 0; i < numberOfPoints; ++i)
  71282. {
  71283. float angle = startAngle + i * angleBetweenPoints;
  71284. const float x = centreX + outerRadius * sinf (angle);
  71285. const float y = centreY - outerRadius * cosf (angle);
  71286. if (i == 0)
  71287. startNewSubPath (x, y);
  71288. else
  71289. lineTo (x, y);
  71290. angle += angleBetweenPoints * 0.5f;
  71291. lineTo (centreX + innerRadius * sinf (angle),
  71292. centreY - innerRadius * cosf (angle));
  71293. }
  71294. closeSubPath();
  71295. }
  71296. }
  71297. void Path::addBubble (float x, float y,
  71298. float w, float h,
  71299. float cs,
  71300. float tipX,
  71301. float tipY,
  71302. int whichSide,
  71303. float arrowPos,
  71304. float arrowWidth)
  71305. {
  71306. if (w > 1.0f && h > 1.0f)
  71307. {
  71308. cs = jmin (cs, w * 0.5f, h * 0.5f);
  71309. const float cs2 = 2.0f * cs;
  71310. startNewSubPath (x + cs, y);
  71311. if (whichSide == 0)
  71312. {
  71313. const float halfArrowW = jmin (arrowWidth, w - cs2) * 0.5f;
  71314. const float arrowX1 = x + cs + jmax (0.0f, (w - cs2) * arrowPos - halfArrowW);
  71315. lineTo (arrowX1, y);
  71316. lineTo (tipX, tipY);
  71317. lineTo (arrowX1 + halfArrowW * 2.0f, y);
  71318. }
  71319. lineTo (x + w - cs, y);
  71320. if (cs > 0.0f)
  71321. addArc (x + w - cs2, y, cs2, cs2, 0, float_Pi * 0.5f);
  71322. if (whichSide == 3)
  71323. {
  71324. const float halfArrowH = jmin (arrowWidth, h - cs2) * 0.5f;
  71325. const float arrowY1 = y + cs + jmax (0.0f, (h - cs2) * arrowPos - halfArrowH);
  71326. lineTo (x + w, arrowY1);
  71327. lineTo (tipX, tipY);
  71328. lineTo (x + w, arrowY1 + halfArrowH * 2.0f);
  71329. }
  71330. lineTo (x + w, y + h - cs);
  71331. if (cs > 0.0f)
  71332. addArc (x + w - cs2, y + h - cs2, cs2, cs2, float_Pi * 0.5f, float_Pi);
  71333. if (whichSide == 2)
  71334. {
  71335. const float halfArrowW = jmin (arrowWidth, w - cs2) * 0.5f;
  71336. const float arrowX1 = x + cs + jmax (0.0f, (w - cs2) * arrowPos - halfArrowW);
  71337. lineTo (arrowX1 + halfArrowW * 2.0f, y + h);
  71338. lineTo (tipX, tipY);
  71339. lineTo (arrowX1, y + h);
  71340. }
  71341. lineTo (x + cs, y + h);
  71342. if (cs > 0.0f)
  71343. addArc (x, y + h - cs2, cs2, cs2, float_Pi, float_Pi * 1.5f);
  71344. if (whichSide == 1)
  71345. {
  71346. const float halfArrowH = jmin (arrowWidth, h - cs2) * 0.5f;
  71347. const float arrowY1 = y + cs + jmax (0.0f, (h - cs2) * arrowPos - halfArrowH);
  71348. lineTo (x, arrowY1 + halfArrowH * 2.0f);
  71349. lineTo (tipX, tipY);
  71350. lineTo (x, arrowY1);
  71351. }
  71352. lineTo (x, y + cs);
  71353. if (cs > 0.0f)
  71354. addArc (x, y, cs2, cs2, float_Pi * 1.5f, float_Pi * 2.0f - PathHelpers::ellipseAngularIncrement);
  71355. closeSubPath();
  71356. }
  71357. }
  71358. void Path::addPath (const Path& other)
  71359. {
  71360. size_t i = 0;
  71361. while (i < other.numElements)
  71362. {
  71363. const float type = other.data.elements [i++];
  71364. if (type == moveMarker)
  71365. {
  71366. startNewSubPath (other.data.elements [i],
  71367. other.data.elements [i + 1]);
  71368. i += 2;
  71369. }
  71370. else if (type == lineMarker)
  71371. {
  71372. lineTo (other.data.elements [i],
  71373. other.data.elements [i + 1]);
  71374. i += 2;
  71375. }
  71376. else if (type == quadMarker)
  71377. {
  71378. quadraticTo (other.data.elements [i],
  71379. other.data.elements [i + 1],
  71380. other.data.elements [i + 2],
  71381. other.data.elements [i + 3]);
  71382. i += 4;
  71383. }
  71384. else if (type == cubicMarker)
  71385. {
  71386. cubicTo (other.data.elements [i],
  71387. other.data.elements [i + 1],
  71388. other.data.elements [i + 2],
  71389. other.data.elements [i + 3],
  71390. other.data.elements [i + 4],
  71391. other.data.elements [i + 5]);
  71392. i += 6;
  71393. }
  71394. else if (type == closeSubPathMarker)
  71395. {
  71396. closeSubPath();
  71397. }
  71398. else
  71399. {
  71400. // something's gone wrong with the element list!
  71401. jassertfalse
  71402. }
  71403. }
  71404. }
  71405. void Path::addPath (const Path& other,
  71406. const AffineTransform& transformToApply)
  71407. {
  71408. size_t i = 0;
  71409. while (i < other.numElements)
  71410. {
  71411. const float type = other.data.elements [i++];
  71412. if (type == closeSubPathMarker)
  71413. {
  71414. closeSubPath();
  71415. }
  71416. else
  71417. {
  71418. float x = other.data.elements [i++];
  71419. float y = other.data.elements [i++];
  71420. transformToApply.transformPoint (x, y);
  71421. if (type == moveMarker)
  71422. {
  71423. startNewSubPath (x, y);
  71424. }
  71425. else if (type == lineMarker)
  71426. {
  71427. lineTo (x, y);
  71428. }
  71429. else if (type == quadMarker)
  71430. {
  71431. float x2 = other.data.elements [i++];
  71432. float y2 = other.data.elements [i++];
  71433. transformToApply.transformPoint (x2, y2);
  71434. quadraticTo (x, y, x2, y2);
  71435. }
  71436. else if (type == cubicMarker)
  71437. {
  71438. float x2 = other.data.elements [i++];
  71439. float y2 = other.data.elements [i++];
  71440. float x3 = other.data.elements [i++];
  71441. float y3 = other.data.elements [i++];
  71442. transformToApply.transformPoint (x2, y2);
  71443. transformToApply.transformPoint (x3, y3);
  71444. cubicTo (x, y, x2, y2, x3, y3);
  71445. }
  71446. else
  71447. {
  71448. // something's gone wrong with the element list!
  71449. jassertfalse
  71450. }
  71451. }
  71452. }
  71453. }
  71454. void Path::applyTransform (const AffineTransform& transform) throw()
  71455. {
  71456. size_t i = 0;
  71457. pathYMin = pathXMin = 0;
  71458. pathYMax = pathXMax = 0;
  71459. bool setMaxMin = false;
  71460. while (i < numElements)
  71461. {
  71462. const float type = data.elements [i++];
  71463. if (type == moveMarker)
  71464. {
  71465. transform.transformPoint (data.elements [i],
  71466. data.elements [i + 1]);
  71467. if (setMaxMin)
  71468. {
  71469. pathXMin = jmin (pathXMin, data.elements [i]);
  71470. pathXMax = jmax (pathXMax, data.elements [i]);
  71471. pathYMin = jmin (pathYMin, data.elements [i + 1]);
  71472. pathYMax = jmax (pathYMax, data.elements [i + 1]);
  71473. }
  71474. else
  71475. {
  71476. pathXMin = pathXMax = data.elements [i];
  71477. pathYMin = pathYMax = data.elements [i + 1];
  71478. setMaxMin = true;
  71479. }
  71480. i += 2;
  71481. }
  71482. else if (type == lineMarker)
  71483. {
  71484. transform.transformPoint (data.elements [i],
  71485. data.elements [i + 1]);
  71486. pathXMin = jmin (pathXMin, data.elements [i]);
  71487. pathXMax = jmax (pathXMax, data.elements [i]);
  71488. pathYMin = jmin (pathYMin, data.elements [i + 1]);
  71489. pathYMax = jmax (pathYMax, data.elements [i + 1]);
  71490. i += 2;
  71491. }
  71492. else if (type == quadMarker)
  71493. {
  71494. transform.transformPoint (data.elements [i],
  71495. data.elements [i + 1]);
  71496. transform.transformPoint (data.elements [i + 2],
  71497. data.elements [i + 3]);
  71498. pathXMin = jmin (pathXMin, data.elements [i], data.elements [i + 2]);
  71499. pathXMax = jmax (pathXMax, data.elements [i], data.elements [i + 2]);
  71500. pathYMin = jmin (pathYMin, data.elements [i + 1], data.elements [i + 3]);
  71501. pathYMax = jmax (pathYMax, data.elements [i + 1], data.elements [i + 3]);
  71502. i += 4;
  71503. }
  71504. else if (type == cubicMarker)
  71505. {
  71506. transform.transformPoint (data.elements [i],
  71507. data.elements [i + 1]);
  71508. transform.transformPoint (data.elements [i + 2],
  71509. data.elements [i + 3]);
  71510. transform.transformPoint (data.elements [i + 4],
  71511. data.elements [i + 5]);
  71512. pathXMin = jmin (pathXMin, data.elements [i], data.elements [i + 2], data.elements [i + 4]);
  71513. pathXMax = jmax (pathXMax, data.elements [i], data.elements [i + 2], data.elements [i + 4]);
  71514. pathYMin = jmin (pathYMin, data.elements [i + 1], data.elements [i + 3], data.elements [i + 5]);
  71515. pathYMax = jmax (pathYMax, data.elements [i + 1], data.elements [i + 3], data.elements [i + 5]);
  71516. i += 6;
  71517. }
  71518. }
  71519. }
  71520. const AffineTransform Path::getTransformToScaleToFit (const float x, const float y,
  71521. const float w, const float h,
  71522. const bool preserveProportions,
  71523. const Justification& justification) const
  71524. {
  71525. Rectangle<float> bounds (getBounds());
  71526. if (preserveProportions)
  71527. {
  71528. if (w <= 0 || h <= 0 || bounds.isEmpty())
  71529. return AffineTransform::identity;
  71530. float newW, newH;
  71531. const float srcRatio = bounds.getHeight() / bounds.getWidth();
  71532. if (srcRatio > h / w)
  71533. {
  71534. newW = h / srcRatio;
  71535. newH = h;
  71536. }
  71537. else
  71538. {
  71539. newW = w;
  71540. newH = w * srcRatio;
  71541. }
  71542. float newXCentre = x;
  71543. float newYCentre = y;
  71544. if (justification.testFlags (Justification::left))
  71545. newXCentre += newW * 0.5f;
  71546. else if (justification.testFlags (Justification::right))
  71547. newXCentre += w - newW * 0.5f;
  71548. else
  71549. newXCentre += w * 0.5f;
  71550. if (justification.testFlags (Justification::top))
  71551. newYCentre += newH * 0.5f;
  71552. else if (justification.testFlags (Justification::bottom))
  71553. newYCentre += h - newH * 0.5f;
  71554. else
  71555. newYCentre += h * 0.5f;
  71556. return AffineTransform::translation (bounds.getWidth() * -0.5f - bounds.getX(),
  71557. bounds.getHeight() * -0.5f - bounds.getY())
  71558. .scaled (newW / bounds.getWidth(), newH / bounds.getHeight())
  71559. .translated (newXCentre, newYCentre);
  71560. }
  71561. else
  71562. {
  71563. return AffineTransform::translation (-bounds.getX(), -bounds.getY())
  71564. .scaled (w / bounds.getWidth(), h / bounds.getHeight())
  71565. .translated (x, y);
  71566. }
  71567. }
  71568. bool Path::contains (const float x, const float y, const float tolerence) const
  71569. {
  71570. if (x <= pathXMin || x >= pathXMax
  71571. || y <= pathYMin || y >= pathYMax)
  71572. return false;
  71573. PathFlatteningIterator i (*this, AffineTransform::identity, tolerence);
  71574. int positiveCrossings = 0;
  71575. int negativeCrossings = 0;
  71576. while (i.next())
  71577. {
  71578. if ((i.y1 <= y && i.y2 > y)
  71579. || (i.y2 <= y && i.y1 > y))
  71580. {
  71581. const float intersectX = i.x1 + (i.x2 - i.x1) * (y - i.y1) / (i.y2 - i.y1);
  71582. if (intersectX <= x)
  71583. {
  71584. if (i.y1 < i.y2)
  71585. ++positiveCrossings;
  71586. else
  71587. ++negativeCrossings;
  71588. }
  71589. }
  71590. }
  71591. return (useNonZeroWinding) ? (negativeCrossings != positiveCrossings)
  71592. : ((negativeCrossings + positiveCrossings) & 1) != 0;
  71593. }
  71594. bool Path::intersectsLine (const float x1, const float y1,
  71595. const float x2, const float y2,
  71596. const float tolerence)
  71597. {
  71598. PathFlatteningIterator i (*this, AffineTransform::identity, tolerence);
  71599. const Line line1 (x1, y1, x2, y2);
  71600. while (i.next())
  71601. {
  71602. const Line line2 (i.x1, i.y1, i.x2, i.y2);
  71603. float ix, iy;
  71604. if (line1.intersects (line2, ix, iy))
  71605. return true;
  71606. }
  71607. return false;
  71608. }
  71609. const Path Path::createPathWithRoundedCorners (const float cornerRadius) const
  71610. {
  71611. if (cornerRadius <= 0.01f)
  71612. return *this;
  71613. int indexOfPathStart = 0, indexOfPathStartThis = 0;
  71614. size_t n = 0;
  71615. bool lastWasLine = false, firstWasLine = false;
  71616. Path p;
  71617. while (n < numElements)
  71618. {
  71619. const float type = data.elements [n++];
  71620. if (type == moveMarker)
  71621. {
  71622. indexOfPathStart = p.numElements;
  71623. indexOfPathStartThis = n - 1;
  71624. const float x = data.elements [n++];
  71625. const float y = data.elements [n++];
  71626. p.startNewSubPath (x, y);
  71627. lastWasLine = false;
  71628. firstWasLine = (data.elements [n] == lineMarker);
  71629. }
  71630. else if (type == lineMarker || type == closeSubPathMarker)
  71631. {
  71632. float startX = 0, startY = 0, joinX = 0, joinY = 0, endX, endY;
  71633. if (type == lineMarker)
  71634. {
  71635. endX = data.elements [n++];
  71636. endY = data.elements [n++];
  71637. if (n > 8)
  71638. {
  71639. startX = data.elements [n - 8];
  71640. startY = data.elements [n - 7];
  71641. joinX = data.elements [n - 5];
  71642. joinY = data.elements [n - 4];
  71643. }
  71644. }
  71645. else
  71646. {
  71647. endX = data.elements [indexOfPathStartThis + 1];
  71648. endY = data.elements [indexOfPathStartThis + 2];
  71649. if (n > 6)
  71650. {
  71651. startX = data.elements [n - 6];
  71652. startY = data.elements [n - 5];
  71653. joinX = data.elements [n - 3];
  71654. joinY = data.elements [n - 2];
  71655. }
  71656. }
  71657. if (lastWasLine)
  71658. {
  71659. const double len1 = juce_hypot (startX - joinX,
  71660. startY - joinY);
  71661. if (len1 > 0)
  71662. {
  71663. const double propNeeded = jmin (0.5, cornerRadius / len1);
  71664. p.data.elements [p.numElements - 2] = (float) (joinX - (joinX - startX) * propNeeded);
  71665. p.data.elements [p.numElements - 1] = (float) (joinY - (joinY - startY) * propNeeded);
  71666. }
  71667. const double len2 = juce_hypot (endX - joinX,
  71668. endY - joinY);
  71669. if (len2 > 0)
  71670. {
  71671. const double propNeeded = jmin (0.5, cornerRadius / len2);
  71672. p.quadraticTo (joinX, joinY,
  71673. (float) (joinX + (endX - joinX) * propNeeded),
  71674. (float) (joinY + (endY - joinY) * propNeeded));
  71675. }
  71676. p.lineTo (endX, endY);
  71677. }
  71678. else if (type == lineMarker)
  71679. {
  71680. p.lineTo (endX, endY);
  71681. lastWasLine = true;
  71682. }
  71683. if (type == closeSubPathMarker)
  71684. {
  71685. if (firstWasLine)
  71686. {
  71687. startX = data.elements [n - 3];
  71688. startY = data.elements [n - 2];
  71689. joinX = endX;
  71690. joinY = endY;
  71691. endX = data.elements [indexOfPathStartThis + 4];
  71692. endY = data.elements [indexOfPathStartThis + 5];
  71693. const double len1 = juce_hypot (startX - joinX,
  71694. startY - joinY);
  71695. if (len1 > 0)
  71696. {
  71697. const double propNeeded = jmin (0.5, cornerRadius / len1);
  71698. p.data.elements [p.numElements - 2] = (float) (joinX - (joinX - startX) * propNeeded);
  71699. p.data.elements [p.numElements - 1] = (float) (joinY - (joinY - startY) * propNeeded);
  71700. }
  71701. const double len2 = juce_hypot (endX - joinX,
  71702. endY - joinY);
  71703. if (len2 > 0)
  71704. {
  71705. const double propNeeded = jmin (0.5, cornerRadius / len2);
  71706. endX = (float) (joinX + (endX - joinX) * propNeeded);
  71707. endY = (float) (joinY + (endY - joinY) * propNeeded);
  71708. p.quadraticTo (joinX, joinY, endX, endY);
  71709. p.data.elements [indexOfPathStart + 1] = endX;
  71710. p.data.elements [indexOfPathStart + 2] = endY;
  71711. }
  71712. }
  71713. p.closeSubPath();
  71714. }
  71715. }
  71716. else if (type == quadMarker)
  71717. {
  71718. lastWasLine = false;
  71719. const float x1 = data.elements [n++];
  71720. const float y1 = data.elements [n++];
  71721. const float x2 = data.elements [n++];
  71722. const float y2 = data.elements [n++];
  71723. p.quadraticTo (x1, y1, x2, y2);
  71724. }
  71725. else if (type == cubicMarker)
  71726. {
  71727. lastWasLine = false;
  71728. const float x1 = data.elements [n++];
  71729. const float y1 = data.elements [n++];
  71730. const float x2 = data.elements [n++];
  71731. const float y2 = data.elements [n++];
  71732. const float x3 = data.elements [n++];
  71733. const float y3 = data.elements [n++];
  71734. p.cubicTo (x1, y1, x2, y2, x3, y3);
  71735. }
  71736. }
  71737. return p;
  71738. }
  71739. void Path::loadPathFromStream (InputStream& source)
  71740. {
  71741. while (! source.isExhausted())
  71742. {
  71743. switch (source.readByte())
  71744. {
  71745. case 'm':
  71746. {
  71747. const float x = source.readFloat();
  71748. const float y = source.readFloat();
  71749. startNewSubPath (x, y);
  71750. break;
  71751. }
  71752. case 'l':
  71753. {
  71754. const float x = source.readFloat();
  71755. const float y = source.readFloat();
  71756. lineTo (x, y);
  71757. break;
  71758. }
  71759. case 'q':
  71760. {
  71761. const float x1 = source.readFloat();
  71762. const float y1 = source.readFloat();
  71763. const float x2 = source.readFloat();
  71764. const float y2 = source.readFloat();
  71765. quadraticTo (x1, y1, x2, y2);
  71766. break;
  71767. }
  71768. case 'b':
  71769. {
  71770. const float x1 = source.readFloat();
  71771. const float y1 = source.readFloat();
  71772. const float x2 = source.readFloat();
  71773. const float y2 = source.readFloat();
  71774. const float x3 = source.readFloat();
  71775. const float y3 = source.readFloat();
  71776. cubicTo (x1, y1, x2, y2, x3, y3);
  71777. break;
  71778. }
  71779. case 'c':
  71780. closeSubPath();
  71781. break;
  71782. case 'n':
  71783. useNonZeroWinding = true;
  71784. break;
  71785. case 'z':
  71786. useNonZeroWinding = false;
  71787. break;
  71788. case 'e':
  71789. return; // end of path marker
  71790. default:
  71791. jassertfalse // illegal char in the stream
  71792. break;
  71793. }
  71794. }
  71795. }
  71796. void Path::loadPathFromData (const void* const data, const int numberOfBytes)
  71797. {
  71798. MemoryInputStream in (data, numberOfBytes, false);
  71799. loadPathFromStream (in);
  71800. }
  71801. void Path::writePathToStream (OutputStream& dest) const
  71802. {
  71803. dest.writeByte (useNonZeroWinding ? 'n' : 'z');
  71804. size_t i = 0;
  71805. while (i < numElements)
  71806. {
  71807. const float type = data.elements [i++];
  71808. if (type == moveMarker)
  71809. {
  71810. dest.writeByte ('m');
  71811. dest.writeFloat (data.elements [i++]);
  71812. dest.writeFloat (data.elements [i++]);
  71813. }
  71814. else if (type == lineMarker)
  71815. {
  71816. dest.writeByte ('l');
  71817. dest.writeFloat (data.elements [i++]);
  71818. dest.writeFloat (data.elements [i++]);
  71819. }
  71820. else if (type == quadMarker)
  71821. {
  71822. dest.writeByte ('q');
  71823. dest.writeFloat (data.elements [i++]);
  71824. dest.writeFloat (data.elements [i++]);
  71825. dest.writeFloat (data.elements [i++]);
  71826. dest.writeFloat (data.elements [i++]);
  71827. }
  71828. else if (type == cubicMarker)
  71829. {
  71830. dest.writeByte ('b');
  71831. dest.writeFloat (data.elements [i++]);
  71832. dest.writeFloat (data.elements [i++]);
  71833. dest.writeFloat (data.elements [i++]);
  71834. dest.writeFloat (data.elements [i++]);
  71835. dest.writeFloat (data.elements [i++]);
  71836. dest.writeFloat (data.elements [i++]);
  71837. }
  71838. else if (type == closeSubPathMarker)
  71839. {
  71840. dest.writeByte ('c');
  71841. }
  71842. }
  71843. dest.writeByte ('e'); // marks the end-of-path
  71844. }
  71845. const String Path::toString() const
  71846. {
  71847. MemoryOutputStream s (2048, 2048);
  71848. if (! useNonZeroWinding)
  71849. s << "a ";
  71850. size_t i = 0;
  71851. float lastMarker = 0.0f;
  71852. while (i < numElements)
  71853. {
  71854. const float marker = data.elements [i++];
  71855. char markerChar = 0;
  71856. int numCoords = 0;
  71857. if (marker == moveMarker)
  71858. {
  71859. markerChar = 'm';
  71860. numCoords = 2;
  71861. }
  71862. else if (marker == lineMarker)
  71863. {
  71864. markerChar = 'l';
  71865. numCoords = 2;
  71866. }
  71867. else if (marker == quadMarker)
  71868. {
  71869. markerChar = 'q';
  71870. numCoords = 4;
  71871. }
  71872. else if (marker == cubicMarker)
  71873. {
  71874. markerChar = 'c';
  71875. numCoords = 6;
  71876. }
  71877. else
  71878. {
  71879. jassert (marker == closeSubPathMarker);
  71880. markerChar = 'z';
  71881. }
  71882. if (marker != lastMarker)
  71883. {
  71884. s << markerChar << ' ';
  71885. lastMarker = marker;
  71886. }
  71887. while (--numCoords >= 0 && i < numElements)
  71888. {
  71889. String n (data.elements [i++], 3);
  71890. if (n.endsWithChar (T('0')))
  71891. {
  71892. do
  71893. {
  71894. n = n.dropLastCharacters (1);
  71895. } while (n.endsWithChar (T('0')));
  71896. if (n.endsWithChar (T('.')))
  71897. n = n.dropLastCharacters (1);
  71898. }
  71899. s << n << ' ';
  71900. }
  71901. }
  71902. const char* const result = (const char*) s.getData();
  71903. size_t len = s.getDataSize();
  71904. while (len > 0 && CharacterFunctions::isWhitespace (result [len - 1]))
  71905. --len;
  71906. return String (result, len);
  71907. }
  71908. void Path::restoreFromString (const String& stringVersion)
  71909. {
  71910. clear();
  71911. setUsingNonZeroWinding (true);
  71912. const tchar* t = stringVersion;
  71913. tchar marker = T('m');
  71914. int numValues = 2;
  71915. float values [6];
  71916. while (*t != 0)
  71917. {
  71918. const String token (PathHelpers::nextToken (t));
  71919. const tchar firstChar = token[0];
  71920. int startNum = 0;
  71921. if (firstChar == T('m') || firstChar == T('l'))
  71922. {
  71923. marker = firstChar;
  71924. numValues = 2;
  71925. }
  71926. else if (firstChar == T('q'))
  71927. {
  71928. marker = firstChar;
  71929. numValues = 4;
  71930. }
  71931. else if (firstChar == T('c'))
  71932. {
  71933. marker = firstChar;
  71934. numValues = 6;
  71935. }
  71936. else if (firstChar == T('z'))
  71937. {
  71938. marker = firstChar;
  71939. numValues = 0;
  71940. }
  71941. else if (firstChar == T('a'))
  71942. {
  71943. setUsingNonZeroWinding (false);
  71944. continue;
  71945. }
  71946. else
  71947. {
  71948. ++startNum;
  71949. values [0] = token.getFloatValue();
  71950. }
  71951. for (int i = startNum; i < numValues; ++i)
  71952. values [i] = PathHelpers::nextToken (t).getFloatValue();
  71953. switch (marker)
  71954. {
  71955. case T('m'):
  71956. startNewSubPath (values[0], values[1]);
  71957. break;
  71958. case T('l'):
  71959. lineTo (values[0], values[1]);
  71960. break;
  71961. case T('q'):
  71962. quadraticTo (values[0], values[1],
  71963. values[2], values[3]);
  71964. break;
  71965. case T('c'):
  71966. cubicTo (values[0], values[1],
  71967. values[2], values[3],
  71968. values[4], values[5]);
  71969. break;
  71970. case T('z'):
  71971. closeSubPath();
  71972. break;
  71973. default:
  71974. jassertfalse // illegal string format?
  71975. break;
  71976. }
  71977. }
  71978. }
  71979. Path::Iterator::Iterator (const Path& path_)
  71980. : path (path_),
  71981. index (0)
  71982. {
  71983. }
  71984. Path::Iterator::~Iterator()
  71985. {
  71986. }
  71987. bool Path::Iterator::next()
  71988. {
  71989. const float* const elements = path.data.elements;
  71990. if (index < path.numElements)
  71991. {
  71992. const float type = elements [index++];
  71993. if (type == moveMarker)
  71994. {
  71995. elementType = startNewSubPath;
  71996. x1 = elements [index++];
  71997. y1 = elements [index++];
  71998. }
  71999. else if (type == lineMarker)
  72000. {
  72001. elementType = lineTo;
  72002. x1 = elements [index++];
  72003. y1 = elements [index++];
  72004. }
  72005. else if (type == quadMarker)
  72006. {
  72007. elementType = quadraticTo;
  72008. x1 = elements [index++];
  72009. y1 = elements [index++];
  72010. x2 = elements [index++];
  72011. y2 = elements [index++];
  72012. }
  72013. else if (type == cubicMarker)
  72014. {
  72015. elementType = cubicTo;
  72016. x1 = elements [index++];
  72017. y1 = elements [index++];
  72018. x2 = elements [index++];
  72019. y2 = elements [index++];
  72020. x3 = elements [index++];
  72021. y3 = elements [index++];
  72022. }
  72023. else if (type == closeSubPathMarker)
  72024. {
  72025. elementType = closePath;
  72026. }
  72027. return true;
  72028. }
  72029. return false;
  72030. }
  72031. END_JUCE_NAMESPACE
  72032. /*** End of inlined file: juce_Path.cpp ***/
  72033. /*** Start of inlined file: juce_PathIterator.cpp ***/
  72034. BEGIN_JUCE_NAMESPACE
  72035. #if JUCE_MSVC
  72036. #pragma optimize ("t", on)
  72037. #endif
  72038. PathFlatteningIterator::PathFlatteningIterator (const Path& path_,
  72039. const AffineTransform& transform_,
  72040. float tolerence_)
  72041. : x2 (0),
  72042. y2 (0),
  72043. closesSubPath (false),
  72044. subPathIndex (-1),
  72045. path (path_),
  72046. transform (transform_),
  72047. points (path_.data.elements),
  72048. tolerence (tolerence_ * tolerence_),
  72049. subPathCloseX (0),
  72050. subPathCloseY (0),
  72051. isIdentityTransform (transform_.isIdentity()),
  72052. stackBase (32),
  72053. index (0),
  72054. stackSize (32)
  72055. {
  72056. stackPos = stackBase;
  72057. }
  72058. PathFlatteningIterator::~PathFlatteningIterator()
  72059. {
  72060. }
  72061. bool PathFlatteningIterator::next()
  72062. {
  72063. x1 = x2;
  72064. y1 = y2;
  72065. float x3 = 0;
  72066. float y3 = 0;
  72067. float x4 = 0;
  72068. float y4 = 0;
  72069. float type;
  72070. for (;;)
  72071. {
  72072. if (stackPos == stackBase)
  72073. {
  72074. if (index >= path.numElements)
  72075. {
  72076. return false;
  72077. }
  72078. else
  72079. {
  72080. type = points [index++];
  72081. if (type != Path::closeSubPathMarker)
  72082. {
  72083. x2 = points [index++];
  72084. y2 = points [index++];
  72085. if (! isIdentityTransform)
  72086. transform.transformPoint (x2, y2);
  72087. if (type == Path::quadMarker)
  72088. {
  72089. x3 = points [index++];
  72090. y3 = points [index++];
  72091. if (! isIdentityTransform)
  72092. transform.transformPoint (x3, y3);
  72093. }
  72094. else if (type == Path::cubicMarker)
  72095. {
  72096. x3 = points [index++];
  72097. y3 = points [index++];
  72098. x4 = points [index++];
  72099. y4 = points [index++];
  72100. if (! isIdentityTransform)
  72101. {
  72102. transform.transformPoint (x3, y3);
  72103. transform.transformPoint (x4, y4);
  72104. }
  72105. }
  72106. }
  72107. }
  72108. }
  72109. else
  72110. {
  72111. type = *--stackPos;
  72112. if (type != Path::closeSubPathMarker)
  72113. {
  72114. x2 = *--stackPos;
  72115. y2 = *--stackPos;
  72116. if (type == Path::quadMarker)
  72117. {
  72118. x3 = *--stackPos;
  72119. y3 = *--stackPos;
  72120. }
  72121. else if (type == Path::cubicMarker)
  72122. {
  72123. x3 = *--stackPos;
  72124. y3 = *--stackPos;
  72125. x4 = *--stackPos;
  72126. y4 = *--stackPos;
  72127. }
  72128. }
  72129. }
  72130. if (type == Path::lineMarker)
  72131. {
  72132. ++subPathIndex;
  72133. closesSubPath = (stackPos == stackBase)
  72134. && (index < path.numElements)
  72135. && (points [index] == Path::closeSubPathMarker)
  72136. && x2 == subPathCloseX
  72137. && y2 == subPathCloseY;
  72138. return true;
  72139. }
  72140. else if (type == Path::quadMarker)
  72141. {
  72142. const size_t offset = (size_t) (stackPos - stackBase);
  72143. if (offset >= stackSize - 10)
  72144. {
  72145. stackSize <<= 1;
  72146. stackBase.realloc (stackSize);
  72147. stackPos = stackBase + offset;
  72148. }
  72149. const float dx1 = x1 - x2;
  72150. const float dy1 = y1 - y2;
  72151. const float dx2 = x2 - x3;
  72152. const float dy2 = y2 - y3;
  72153. const float m1x = (x1 + x2) * 0.5f;
  72154. const float m1y = (y1 + y2) * 0.5f;
  72155. const float m2x = (x2 + x3) * 0.5f;
  72156. const float m2y = (y2 + y3) * 0.5f;
  72157. const float m3x = (m1x + m2x) * 0.5f;
  72158. const float m3y = (m1y + m2y) * 0.5f;
  72159. if (dx1*dx1 + dy1*dy1 + dx2*dx2 + dy2*dy2 > tolerence)
  72160. {
  72161. *stackPos++ = y3;
  72162. *stackPos++ = x3;
  72163. *stackPos++ = m2y;
  72164. *stackPos++ = m2x;
  72165. *stackPos++ = Path::quadMarker;
  72166. *stackPos++ = m3y;
  72167. *stackPos++ = m3x;
  72168. *stackPos++ = m1y;
  72169. *stackPos++ = m1x;
  72170. *stackPos++ = Path::quadMarker;
  72171. }
  72172. else
  72173. {
  72174. *stackPos++ = y3;
  72175. *stackPos++ = x3;
  72176. *stackPos++ = Path::lineMarker;
  72177. *stackPos++ = m3y;
  72178. *stackPos++ = m3x;
  72179. *stackPos++ = Path::lineMarker;
  72180. }
  72181. jassert (stackPos < stackBase + stackSize);
  72182. }
  72183. else if (type == Path::cubicMarker)
  72184. {
  72185. const size_t offset = (size_t) (stackPos - stackBase);
  72186. if (offset >= stackSize - 16)
  72187. {
  72188. stackSize <<= 1;
  72189. stackBase.realloc (stackSize);
  72190. stackPos = stackBase + offset;
  72191. }
  72192. const float dx1 = x1 - x2;
  72193. const float dy1 = y1 - y2;
  72194. const float dx2 = x2 - x3;
  72195. const float dy2 = y2 - y3;
  72196. const float dx3 = x3 - x4;
  72197. const float dy3 = y3 - y4;
  72198. const float m1x = (x1 + x2) * 0.5f;
  72199. const float m1y = (y1 + y2) * 0.5f;
  72200. const float m2x = (x3 + x2) * 0.5f;
  72201. const float m2y = (y3 + y2) * 0.5f;
  72202. const float m3x = (x3 + x4) * 0.5f;
  72203. const float m3y = (y3 + y4) * 0.5f;
  72204. const float m4x = (m1x + m2x) * 0.5f;
  72205. const float m4y = (m1y + m2y) * 0.5f;
  72206. const float m5x = (m3x + m2x) * 0.5f;
  72207. const float m5y = (m3y + m2y) * 0.5f;
  72208. if (dx1*dx1 + dy1*dy1 + dx2*dx2
  72209. + dy2*dy2 + dx3*dx3 + dy3*dy3 > tolerence)
  72210. {
  72211. *stackPos++ = y4;
  72212. *stackPos++ = x4;
  72213. *stackPos++ = m3y;
  72214. *stackPos++ = m3x;
  72215. *stackPos++ = m5y;
  72216. *stackPos++ = m5x;
  72217. *stackPos++ = Path::cubicMarker;
  72218. *stackPos++ = (m4y + m5y) * 0.5f;
  72219. *stackPos++ = (m4x + m5x) * 0.5f;
  72220. *stackPos++ = m4y;
  72221. *stackPos++ = m4x;
  72222. *stackPos++ = m1y;
  72223. *stackPos++ = m1x;
  72224. *stackPos++ = Path::cubicMarker;
  72225. }
  72226. else
  72227. {
  72228. *stackPos++ = y4;
  72229. *stackPos++ = x4;
  72230. *stackPos++ = Path::lineMarker;
  72231. *stackPos++ = m5y;
  72232. *stackPos++ = m5x;
  72233. *stackPos++ = Path::lineMarker;
  72234. *stackPos++ = m4y;
  72235. *stackPos++ = m4x;
  72236. *stackPos++ = Path::lineMarker;
  72237. }
  72238. }
  72239. else if (type == Path::closeSubPathMarker)
  72240. {
  72241. if (x2 != subPathCloseX || y2 != subPathCloseY)
  72242. {
  72243. x1 = x2;
  72244. y1 = y2;
  72245. x2 = subPathCloseX;
  72246. y2 = subPathCloseY;
  72247. closesSubPath = true;
  72248. return true;
  72249. }
  72250. }
  72251. else
  72252. {
  72253. jassert (type == Path::moveMarker);
  72254. subPathIndex = -1;
  72255. subPathCloseX = x1 = x2;
  72256. subPathCloseY = y1 = y2;
  72257. }
  72258. }
  72259. }
  72260. END_JUCE_NAMESPACE
  72261. /*** End of inlined file: juce_PathIterator.cpp ***/
  72262. /*** Start of inlined file: juce_PathStrokeType.cpp ***/
  72263. BEGIN_JUCE_NAMESPACE
  72264. PathStrokeType::PathStrokeType (const float strokeThickness,
  72265. const JointStyle jointStyle_,
  72266. const EndCapStyle endStyle_) throw()
  72267. : thickness (strokeThickness),
  72268. jointStyle (jointStyle_),
  72269. endStyle (endStyle_)
  72270. {
  72271. }
  72272. PathStrokeType::PathStrokeType (const PathStrokeType& other) throw()
  72273. : thickness (other.thickness),
  72274. jointStyle (other.jointStyle),
  72275. endStyle (other.endStyle)
  72276. {
  72277. }
  72278. PathStrokeType& PathStrokeType::operator= (const PathStrokeType& other) throw()
  72279. {
  72280. thickness = other.thickness;
  72281. jointStyle = other.jointStyle;
  72282. endStyle = other.endStyle;
  72283. return *this;
  72284. }
  72285. PathStrokeType::~PathStrokeType() throw()
  72286. {
  72287. }
  72288. bool PathStrokeType::operator== (const PathStrokeType& other) const throw()
  72289. {
  72290. return thickness == other.thickness
  72291. && jointStyle == other.jointStyle
  72292. && endStyle == other.endStyle;
  72293. }
  72294. bool PathStrokeType::operator!= (const PathStrokeType& other) const throw()
  72295. {
  72296. return ! operator== (other);
  72297. }
  72298. static bool lineIntersection (const float x1, const float y1,
  72299. const float x2, const float y2,
  72300. const float x3, const float y3,
  72301. const float x4, const float y4,
  72302. float& intersectionX,
  72303. float& intersectionY,
  72304. float& distanceBeyondLine1EndSquared) throw()
  72305. {
  72306. if (x2 != x3 || y2 != y3)
  72307. {
  72308. const float dx1 = x2 - x1;
  72309. const float dy1 = y2 - y1;
  72310. const float dx2 = x4 - x3;
  72311. const float dy2 = y4 - y3;
  72312. const float divisor = dx1 * dy2 - dx2 * dy1;
  72313. if (divisor == 0)
  72314. {
  72315. if (! ((dx1 == 0 && dy1 == 0) || (dx2 == 0 && dy2 == 0)))
  72316. {
  72317. if (dy1 == 0 && dy2 != 0)
  72318. {
  72319. const float along = (y1 - y3) / dy2;
  72320. intersectionX = x3 + along * dx2;
  72321. intersectionY = y1;
  72322. distanceBeyondLine1EndSquared = intersectionX - x2;
  72323. distanceBeyondLine1EndSquared *= distanceBeyondLine1EndSquared;
  72324. if ((x2 > x1) == (intersectionX < x2))
  72325. distanceBeyondLine1EndSquared = -distanceBeyondLine1EndSquared;
  72326. return along >= 0 && along <= 1.0f;
  72327. }
  72328. else if (dy2 == 0 && dy1 != 0)
  72329. {
  72330. const float along = (y3 - y1) / dy1;
  72331. intersectionX = x1 + along * dx1;
  72332. intersectionY = y3;
  72333. distanceBeyondLine1EndSquared = (along - 1.0f) * dx1;
  72334. distanceBeyondLine1EndSquared *= distanceBeyondLine1EndSquared;
  72335. if (along < 1.0f)
  72336. distanceBeyondLine1EndSquared = -distanceBeyondLine1EndSquared;
  72337. return along >= 0 && along <= 1.0f;
  72338. }
  72339. else if (dx1 == 0 && dx2 != 0)
  72340. {
  72341. const float along = (x1 - x3) / dx2;
  72342. intersectionX = x1;
  72343. intersectionY = y3 + along * dy2;
  72344. distanceBeyondLine1EndSquared = intersectionY - y2;
  72345. distanceBeyondLine1EndSquared *= distanceBeyondLine1EndSquared;
  72346. if ((y2 > y1) == (intersectionY < y2))
  72347. distanceBeyondLine1EndSquared = -distanceBeyondLine1EndSquared;
  72348. return along >= 0 && along <= 1.0f;
  72349. }
  72350. else if (dx2 == 0 && dx1 != 0)
  72351. {
  72352. const float along = (x3 - x1) / dx1;
  72353. intersectionX = x3;
  72354. intersectionY = y1 + along * dy1;
  72355. distanceBeyondLine1EndSquared = (along - 1.0f) * dy1;
  72356. distanceBeyondLine1EndSquared *= distanceBeyondLine1EndSquared;
  72357. if (along < 1.0f)
  72358. distanceBeyondLine1EndSquared = -distanceBeyondLine1EndSquared;
  72359. return along >= 0 && along <= 1.0f;
  72360. }
  72361. }
  72362. intersectionX = 0.5f * (x2 + x3);
  72363. intersectionY = 0.5f * (y2 + y3);
  72364. distanceBeyondLine1EndSquared = 0.0f;
  72365. return false;
  72366. }
  72367. else
  72368. {
  72369. const float along1 = ((y1 - y3) * dx2 - (x1 - x3) * dy2) / divisor;
  72370. intersectionX = x1 + along1 * dx1;
  72371. intersectionY = y1 + along1 * dy1;
  72372. if (along1 >= 0 && along1 <= 1.0f)
  72373. {
  72374. const float along2 = ((y1 - y3) * dx1 - (x1 - x3) * dy1);
  72375. if (along2 >= 0 && along2 <= divisor)
  72376. {
  72377. distanceBeyondLine1EndSquared = 0.0f;
  72378. return true;
  72379. }
  72380. }
  72381. distanceBeyondLine1EndSquared = along1 - 1.0f;
  72382. distanceBeyondLine1EndSquared *= distanceBeyondLine1EndSquared;
  72383. distanceBeyondLine1EndSquared *= (dx1 * dx1 + dy1 * dy1);
  72384. if (along1 < 1.0f)
  72385. distanceBeyondLine1EndSquared = -distanceBeyondLine1EndSquared;
  72386. return false;
  72387. }
  72388. }
  72389. intersectionX = x2;
  72390. intersectionY = y2;
  72391. distanceBeyondLine1EndSquared = 0.0f;
  72392. return true;
  72393. }
  72394. namespace PathFunctions
  72395. {
  72396. // part of stroke drawing stuff
  72397. static void addEdgeAndJoint (Path& destPath,
  72398. const PathStrokeType::JointStyle style,
  72399. const float maxMiterExtensionSquared, const float width,
  72400. const float x1, const float y1,
  72401. const float x2, const float y2,
  72402. const float x3, const float y3,
  72403. const float x4, const float y4,
  72404. const float midX, const float midY)
  72405. {
  72406. if (style == PathStrokeType::beveled
  72407. || (x3 == x4 && y3 == y4)
  72408. || (x1 == x2 && y1 == y2))
  72409. {
  72410. destPath.lineTo (x2, y2);
  72411. destPath.lineTo (x3, y3);
  72412. }
  72413. else
  72414. {
  72415. float jx, jy, distanceBeyondLine1EndSquared;
  72416. // if they intersect, use this point..
  72417. if (lineIntersection (x1, y1, x2, y2,
  72418. x3, y3, x4, y4,
  72419. jx, jy, distanceBeyondLine1EndSquared))
  72420. {
  72421. destPath.lineTo (jx, jy);
  72422. }
  72423. else
  72424. {
  72425. if (style == PathStrokeType::mitered)
  72426. {
  72427. if (distanceBeyondLine1EndSquared < maxMiterExtensionSquared
  72428. && distanceBeyondLine1EndSquared > 0.0f)
  72429. {
  72430. destPath.lineTo (jx, jy);
  72431. }
  72432. else
  72433. {
  72434. // the end sticks out too far, so just use a blunt joint
  72435. destPath.lineTo (x2, y2);
  72436. destPath.lineTo (x3, y3);
  72437. }
  72438. }
  72439. else
  72440. {
  72441. // curved joints
  72442. float angle1 = atan2f (x2 - midX, y2 - midY);
  72443. float angle2 = atan2f (x3 - midX, y3 - midY);
  72444. const float angleIncrement = 0.1f;
  72445. destPath.lineTo (x2, y2);
  72446. if (fabs (angle1 - angle2) > angleIncrement)
  72447. {
  72448. if (angle2 > angle1 + float_Pi
  72449. || (angle2 < angle1 && angle2 >= angle1 - float_Pi))
  72450. {
  72451. if (angle2 > angle1)
  72452. angle2 -= float_Pi * 2.0f;
  72453. jassert (angle1 <= angle2 + float_Pi);
  72454. angle1 -= angleIncrement;
  72455. while (angle1 > angle2)
  72456. {
  72457. destPath.lineTo (midX + width * sinf (angle1),
  72458. midY + width * cosf (angle1));
  72459. angle1 -= angleIncrement;
  72460. }
  72461. }
  72462. else
  72463. {
  72464. if (angle1 > angle2)
  72465. angle1 -= float_Pi * 2.0f;
  72466. jassert (angle1 >= angle2 - float_Pi);
  72467. angle1 += angleIncrement;
  72468. while (angle1 < angle2)
  72469. {
  72470. destPath.lineTo (midX + width * sinf (angle1),
  72471. midY + width * cosf (angle1));
  72472. angle1 += angleIncrement;
  72473. }
  72474. }
  72475. }
  72476. destPath.lineTo (x3, y3);
  72477. }
  72478. }
  72479. }
  72480. }
  72481. static void addLineEnd (Path& destPath,
  72482. const PathStrokeType::EndCapStyle style,
  72483. const float x1, const float y1,
  72484. const float x2, const float y2,
  72485. const float width)
  72486. {
  72487. if (style == PathStrokeType::butt)
  72488. {
  72489. destPath.lineTo (x2, y2);
  72490. }
  72491. else
  72492. {
  72493. float offx1, offy1, offx2, offy2;
  72494. float dx = x2 - x1;
  72495. float dy = y2 - y1;
  72496. const float len = juce_hypotf (dx, dy);
  72497. if (len == 0)
  72498. {
  72499. offx1 = offx2 = x1;
  72500. offy1 = offy2 = y1;
  72501. }
  72502. else
  72503. {
  72504. const float offset = width / len;
  72505. dx *= offset;
  72506. dy *= offset;
  72507. offx1 = x1 + dy;
  72508. offy1 = y1 - dx;
  72509. offx2 = x2 + dy;
  72510. offy2 = y2 - dx;
  72511. }
  72512. if (style == PathStrokeType::square)
  72513. {
  72514. // sqaure ends
  72515. destPath.lineTo (offx1, offy1);
  72516. destPath.lineTo (offx2, offy2);
  72517. destPath.lineTo (x2, y2);
  72518. }
  72519. else
  72520. {
  72521. // rounded ends
  72522. const float midx = (offx1 + offx2) * 0.5f;
  72523. const float midy = (offy1 + offy2) * 0.5f;
  72524. destPath.cubicTo (x1 + (offx1 - x1) * 0.55f, y1 + (offy1 - y1) * 0.55f,
  72525. offx1 + (midx - offx1) * 0.45f, offy1 + (midy - offy1) * 0.45f,
  72526. midx, midy);
  72527. destPath.cubicTo (midx + (offx2 - midx) * 0.55f, midy + (offy2 - midy) * 0.55f,
  72528. offx2 + (x2 - offx2) * 0.45f, offy2 + (y2 - offy2) * 0.45f,
  72529. x2, y2);
  72530. }
  72531. }
  72532. }
  72533. struct LineSection
  72534. {
  72535. LineSection() {}
  72536. LineSection (int) {}
  72537. float x1, y1, x2, y2; // original line
  72538. float lx1, ly1, lx2, ly2; // the left-hand stroke
  72539. float rx1, ry1, rx2, ry2; // the right-hand stroke
  72540. };
  72541. static void addSubPath (Path& destPath, const Array <LineSection>& subPath,
  72542. const bool isClosed,
  72543. const float width, const float maxMiterExtensionSquared,
  72544. const PathStrokeType::JointStyle jointStyle, const PathStrokeType::EndCapStyle endStyle)
  72545. {
  72546. jassert (subPath.size() > 0);
  72547. const LineSection& firstLine = subPath.getReference (0);
  72548. float lastX1 = firstLine.lx1;
  72549. float lastY1 = firstLine.ly1;
  72550. float lastX2 = firstLine.lx2;
  72551. float lastY2 = firstLine.ly2;
  72552. if (isClosed)
  72553. {
  72554. destPath.startNewSubPath (lastX1, lastY1);
  72555. }
  72556. else
  72557. {
  72558. destPath.startNewSubPath (firstLine.rx2, firstLine.ry2);
  72559. addLineEnd (destPath, endStyle,
  72560. firstLine.rx2, firstLine.ry2,
  72561. lastX1, lastY1,
  72562. width);
  72563. }
  72564. int i;
  72565. for (i = 1; i < subPath.size(); ++i)
  72566. {
  72567. const LineSection& l = subPath.getReference (i);
  72568. addEdgeAndJoint (destPath, jointStyle,
  72569. maxMiterExtensionSquared, width,
  72570. lastX1, lastY1, lastX2, lastY2,
  72571. l.lx1, l.ly1, l.lx2, l.ly2,
  72572. l.x1, l.y1);
  72573. lastX1 = l.lx1;
  72574. lastY1 = l.ly1;
  72575. lastX2 = l.lx2;
  72576. lastY2 = l.ly2;
  72577. }
  72578. const LineSection& lastLine = subPath.getReference (subPath.size() - 1);
  72579. if (isClosed)
  72580. {
  72581. const LineSection& l = subPath.getReference (0);
  72582. addEdgeAndJoint (destPath, jointStyle,
  72583. maxMiterExtensionSquared, width,
  72584. lastX1, lastY1, lastX2, lastY2,
  72585. l.lx1, l.ly1, l.lx2, l.ly2,
  72586. l.x1, l.y1);
  72587. destPath.closeSubPath();
  72588. destPath.startNewSubPath (lastLine.rx1, lastLine.ry1);
  72589. }
  72590. else
  72591. {
  72592. destPath.lineTo (lastX2, lastY2);
  72593. addLineEnd (destPath, endStyle,
  72594. lastX2, lastY2,
  72595. lastLine.rx1, lastLine.ry1,
  72596. width);
  72597. }
  72598. lastX1 = lastLine.rx1;
  72599. lastY1 = lastLine.ry1;
  72600. lastX2 = lastLine.rx2;
  72601. lastY2 = lastLine.ry2;
  72602. for (i = subPath.size() - 1; --i >= 0;)
  72603. {
  72604. const LineSection& l = subPath.getReference (i);
  72605. addEdgeAndJoint (destPath, jointStyle,
  72606. maxMiterExtensionSquared, width,
  72607. lastX1, lastY1, lastX2, lastY2,
  72608. l.rx1, l.ry1, l.rx2, l.ry2,
  72609. l.x2, l.y2);
  72610. lastX1 = l.rx1;
  72611. lastY1 = l.ry1;
  72612. lastX2 = l.rx2;
  72613. lastY2 = l.ry2;
  72614. }
  72615. if (isClosed)
  72616. {
  72617. addEdgeAndJoint (destPath, jointStyle,
  72618. maxMiterExtensionSquared, width,
  72619. lastX1, lastY1, lastX2, lastY2,
  72620. lastLine.rx1, lastLine.ry1, lastLine.rx2, lastLine.ry2,
  72621. lastLine.x2, lastLine.y2);
  72622. }
  72623. else
  72624. {
  72625. // do the last line
  72626. destPath.lineTo (lastX2, lastY2);
  72627. }
  72628. destPath.closeSubPath();
  72629. }
  72630. }
  72631. void PathStrokeType::createStrokedPath (Path& destPath,
  72632. const Path& source,
  72633. const AffineTransform& transform,
  72634. const float extraAccuracy) const
  72635. {
  72636. if (thickness <= 0)
  72637. {
  72638. destPath.clear();
  72639. return;
  72640. }
  72641. const Path* sourcePath = &source;
  72642. Path temp;
  72643. if (sourcePath == &destPath)
  72644. {
  72645. destPath.swapWithPath (temp);
  72646. sourcePath = &temp;
  72647. }
  72648. else
  72649. {
  72650. destPath.clear();
  72651. }
  72652. destPath.setUsingNonZeroWinding (true);
  72653. const float maxMiterExtensionSquared = 9.0f * thickness * thickness;
  72654. const float width = 0.5f * thickness;
  72655. // Iterate the path, creating a list of the
  72656. // left/right-hand lines along either side of it...
  72657. PathFlatteningIterator it (*sourcePath, transform, 9.0f / extraAccuracy);
  72658. using namespace PathFunctions;
  72659. Array <LineSection> subPath;
  72660. LineSection l;
  72661. l.x1 = 0;
  72662. l.y1 = 0;
  72663. const float minSegmentLength = 2.0f / (extraAccuracy * extraAccuracy);
  72664. while (it.next())
  72665. {
  72666. if (it.subPathIndex == 0)
  72667. {
  72668. if (subPath.size() > 0)
  72669. {
  72670. addSubPath (destPath, subPath, false, width, maxMiterExtensionSquared, jointStyle, endStyle);
  72671. subPath.clearQuick();
  72672. }
  72673. l.x1 = it.x1;
  72674. l.y1 = it.y1;
  72675. }
  72676. l.x2 = it.x2;
  72677. l.y2 = it.y2;
  72678. float dx = l.x2 - l.x1;
  72679. float dy = l.y2 - l.y1;
  72680. const float hypotSquared = dx*dx + dy*dy;
  72681. if (it.closesSubPath || hypotSquared > minSegmentLength || it.isLastInSubpath())
  72682. {
  72683. const float len = sqrtf (hypotSquared);
  72684. if (len == 0)
  72685. {
  72686. l.rx1 = l.rx2 = l.lx1 = l.lx2 = l.x1;
  72687. l.ry1 = l.ry2 = l.ly1 = l.ly2 = l.y1;
  72688. }
  72689. else
  72690. {
  72691. const float offset = width / len;
  72692. dx *= offset;
  72693. dy *= offset;
  72694. l.rx2 = l.x1 - dy;
  72695. l.ry2 = l.y1 + dx;
  72696. l.lx1 = l.x1 + dy;
  72697. l.ly1 = l.y1 - dx;
  72698. l.lx2 = l.x2 + dy;
  72699. l.ly2 = l.y2 - dx;
  72700. l.rx1 = l.x2 - dy;
  72701. l.ry1 = l.y2 + dx;
  72702. }
  72703. subPath.add (l);
  72704. if (it.closesSubPath)
  72705. {
  72706. addSubPath (destPath, subPath, true, width, maxMiterExtensionSquared, jointStyle, endStyle);
  72707. subPath.clearQuick();
  72708. }
  72709. else
  72710. {
  72711. l.x1 = it.x2;
  72712. l.y1 = it.y2;
  72713. }
  72714. }
  72715. }
  72716. if (subPath.size() > 0)
  72717. addSubPath (destPath, subPath, false, width, maxMiterExtensionSquared, jointStyle, endStyle);
  72718. }
  72719. void PathStrokeType::createDashedStroke (Path& destPath,
  72720. const Path& sourcePath,
  72721. const float* dashLengths,
  72722. int numDashLengths,
  72723. const AffineTransform& transform,
  72724. const float extraAccuracy) const
  72725. {
  72726. if (thickness <= 0)
  72727. return;
  72728. // this should really be an even number..
  72729. jassert ((numDashLengths & 1) == 0);
  72730. Path newDestPath;
  72731. PathFlatteningIterator it (sourcePath, transform, 9.0f / extraAccuracy);
  72732. bool first = true;
  72733. int dashNum = 0;
  72734. float pos = 0.0f, lineLen = 0.0f, lineEndPos = 0.0f;
  72735. float dx = 0.0f, dy = 0.0f;
  72736. for (;;)
  72737. {
  72738. const bool isSolid = ((dashNum & 1) == 0);
  72739. const float dashLen = dashLengths [dashNum++ % numDashLengths];
  72740. jassert (dashLen > 0); // must be a positive increment!
  72741. if (dashLen <= 0)
  72742. break;
  72743. pos += dashLen;
  72744. while (pos > lineEndPos)
  72745. {
  72746. if (! it.next())
  72747. {
  72748. if (isSolid && ! first)
  72749. newDestPath.lineTo (it.x2, it.y2);
  72750. createStrokedPath (destPath, newDestPath, AffineTransform::identity, extraAccuracy);
  72751. return;
  72752. }
  72753. if (isSolid && ! first)
  72754. newDestPath.lineTo (it.x1, it.y1);
  72755. else
  72756. newDestPath.startNewSubPath (it.x1, it.y1);
  72757. dx = it.x2 - it.x1;
  72758. dy = it.y2 - it.y1;
  72759. lineLen = juce_hypotf (dx, dy);
  72760. lineEndPos += lineLen;
  72761. first = it.closesSubPath;
  72762. }
  72763. const float alpha = (pos - (lineEndPos - lineLen)) / lineLen;
  72764. if (isSolid)
  72765. newDestPath.lineTo (it.x1 + dx * alpha,
  72766. it.y1 + dy * alpha);
  72767. else
  72768. newDestPath.startNewSubPath (it.x1 + dx * alpha,
  72769. it.y1 + dy * alpha);
  72770. }
  72771. }
  72772. END_JUCE_NAMESPACE
  72773. /*** End of inlined file: juce_PathStrokeType.cpp ***/
  72774. /*** Start of inlined file: juce_PositionedRectangle.cpp ***/
  72775. BEGIN_JUCE_NAMESPACE
  72776. PositionedRectangle::PositionedRectangle() throw()
  72777. : x (0.0),
  72778. y (0.0),
  72779. w (0.0),
  72780. h (0.0),
  72781. xMode (anchorAtLeftOrTop | absoluteFromParentTopLeft),
  72782. yMode (anchorAtLeftOrTop | absoluteFromParentTopLeft),
  72783. wMode (absoluteSize),
  72784. hMode (absoluteSize)
  72785. {
  72786. }
  72787. PositionedRectangle::PositionedRectangle (const PositionedRectangle& other) throw()
  72788. : x (other.x),
  72789. y (other.y),
  72790. w (other.w),
  72791. h (other.h),
  72792. xMode (other.xMode),
  72793. yMode (other.yMode),
  72794. wMode (other.wMode),
  72795. hMode (other.hMode)
  72796. {
  72797. }
  72798. PositionedRectangle& PositionedRectangle::operator= (const PositionedRectangle& other) throw()
  72799. {
  72800. x = other.x;
  72801. y = other.y;
  72802. w = other.w;
  72803. h = other.h;
  72804. xMode = other.xMode;
  72805. yMode = other.yMode;
  72806. wMode = other.wMode;
  72807. hMode = other.hMode;
  72808. return *this;
  72809. }
  72810. PositionedRectangle::~PositionedRectangle() throw()
  72811. {
  72812. }
  72813. bool PositionedRectangle::operator== (const PositionedRectangle& other) const throw()
  72814. {
  72815. return x == other.x
  72816. && y == other.y
  72817. && w == other.w
  72818. && h == other.h
  72819. && xMode == other.xMode
  72820. && yMode == other.yMode
  72821. && wMode == other.wMode
  72822. && hMode == other.hMode;
  72823. }
  72824. bool PositionedRectangle::operator!= (const PositionedRectangle& other) const throw()
  72825. {
  72826. return ! operator== (other);
  72827. }
  72828. PositionedRectangle::PositionedRectangle (const String& stringVersion) throw()
  72829. {
  72830. StringArray tokens;
  72831. tokens.addTokens (stringVersion, false);
  72832. decodePosString (tokens [0], xMode, x);
  72833. decodePosString (tokens [1], yMode, y);
  72834. decodeSizeString (tokens [2], wMode, w);
  72835. decodeSizeString (tokens [3], hMode, h);
  72836. }
  72837. const String PositionedRectangle::toString() const throw()
  72838. {
  72839. String s;
  72840. s.preallocateStorage (12);
  72841. addPosDescription (s, xMode, x);
  72842. s << T(' ');
  72843. addPosDescription (s, yMode, y);
  72844. s << T(' ');
  72845. addSizeDescription (s, wMode, w);
  72846. s << T(' ');
  72847. addSizeDescription (s, hMode, h);
  72848. return s;
  72849. }
  72850. const Rectangle<int> PositionedRectangle::getRectangle (const Rectangle<int>& target) const throw()
  72851. {
  72852. jassert (! target.isEmpty());
  72853. double x_, y_, w_, h_;
  72854. applyPosAndSize (x_, w_, x, w, xMode, wMode, target.getX(), target.getWidth());
  72855. applyPosAndSize (y_, h_, y, h, yMode, hMode, target.getY(), target.getHeight());
  72856. return Rectangle<int> (roundToInt (x_), roundToInt (y_),
  72857. roundToInt (w_), roundToInt (h_));
  72858. }
  72859. void PositionedRectangle::getRectangleDouble (const Rectangle<int>& target,
  72860. double& x_, double& y_,
  72861. double& w_, double& h_) const throw()
  72862. {
  72863. jassert (! target.isEmpty());
  72864. applyPosAndSize (x_, w_, x, w, xMode, wMode, target.getX(), target.getWidth());
  72865. applyPosAndSize (y_, h_, y, h, yMode, hMode, target.getY(), target.getHeight());
  72866. }
  72867. void PositionedRectangle::applyToComponent (Component& comp) const throw()
  72868. {
  72869. comp.setBounds (getRectangle (Rectangle<int> (0, 0, comp.getParentWidth(), comp.getParentHeight())));
  72870. }
  72871. void PositionedRectangle::updateFrom (const Rectangle<int>& rectangle,
  72872. const Rectangle<int>& target) throw()
  72873. {
  72874. updatePosAndSize (x, w, rectangle.getX(), rectangle.getWidth(), xMode, wMode, target.getX(), target.getWidth());
  72875. updatePosAndSize (y, h, rectangle.getY(), rectangle.getHeight(), yMode, hMode, target.getY(), target.getHeight());
  72876. }
  72877. void PositionedRectangle::updateFromDouble (const double newX, const double newY,
  72878. const double newW, const double newH,
  72879. const Rectangle<int>& target) throw()
  72880. {
  72881. updatePosAndSize (x, w, newX, newW, xMode, wMode, target.getX(), target.getWidth());
  72882. updatePosAndSize (y, h, newY, newH, yMode, hMode, target.getY(), target.getHeight());
  72883. }
  72884. void PositionedRectangle::updateFromComponent (const Component& comp) throw()
  72885. {
  72886. if (comp.getParentComponent() == 0 && ! comp.isOnDesktop())
  72887. updateFrom (comp.getBounds(), Rectangle<int>());
  72888. else
  72889. updateFrom (comp.getBounds(), Rectangle<int> (0, 0, comp.getParentWidth(), comp.getParentHeight()));
  72890. }
  72891. PositionedRectangle::AnchorPoint PositionedRectangle::getAnchorPointX() const throw()
  72892. {
  72893. return (AnchorPoint) (xMode & (anchorAtLeftOrTop | anchorAtRightOrBottom | anchorAtCentre));
  72894. }
  72895. PositionedRectangle::PositionMode PositionedRectangle::getPositionModeX() const throw()
  72896. {
  72897. return (PositionMode) (xMode & (absoluteFromParentTopLeft
  72898. | absoluteFromParentBottomRight
  72899. | absoluteFromParentCentre
  72900. | proportionOfParentSize));
  72901. }
  72902. PositionedRectangle::AnchorPoint PositionedRectangle::getAnchorPointY() const throw()
  72903. {
  72904. return (AnchorPoint) (yMode & (anchorAtLeftOrTop | anchorAtRightOrBottom | anchorAtCentre));
  72905. }
  72906. PositionedRectangle::PositionMode PositionedRectangle::getPositionModeY() const throw()
  72907. {
  72908. return (PositionMode) (yMode & (absoluteFromParentTopLeft
  72909. | absoluteFromParentBottomRight
  72910. | absoluteFromParentCentre
  72911. | proportionOfParentSize));
  72912. }
  72913. PositionedRectangle::SizeMode PositionedRectangle::getWidthMode() const throw()
  72914. {
  72915. return (SizeMode) wMode;
  72916. }
  72917. PositionedRectangle::SizeMode PositionedRectangle::getHeightMode() const throw()
  72918. {
  72919. return (SizeMode) hMode;
  72920. }
  72921. void PositionedRectangle::setModes (const AnchorPoint xAnchor,
  72922. const PositionMode xMode_,
  72923. const AnchorPoint yAnchor,
  72924. const PositionMode yMode_,
  72925. const SizeMode widthMode,
  72926. const SizeMode heightMode,
  72927. const Rectangle<int>& target) throw()
  72928. {
  72929. if (xMode != (xAnchor | xMode_) || wMode != widthMode)
  72930. {
  72931. double tx, tw;
  72932. applyPosAndSize (tx, tw, x, w, xMode, wMode, target.getX(), target.getWidth());
  72933. xMode = (uint8) (xAnchor | xMode_);
  72934. wMode = (uint8) widthMode;
  72935. updatePosAndSize (x, w, tx, tw, xMode, wMode, target.getX(), target.getWidth());
  72936. }
  72937. if (yMode != (yAnchor | yMode_) || hMode != heightMode)
  72938. {
  72939. double ty, th;
  72940. applyPosAndSize (ty, th, y, h, yMode, hMode, target.getY(), target.getHeight());
  72941. yMode = (uint8) (yAnchor | yMode_);
  72942. hMode = (uint8) heightMode;
  72943. updatePosAndSize (y, h, ty, th, yMode, hMode, target.getY(), target.getHeight());
  72944. }
  72945. }
  72946. bool PositionedRectangle::isPositionAbsolute() const throw()
  72947. {
  72948. return xMode == absoluteFromParentTopLeft
  72949. && yMode == absoluteFromParentTopLeft
  72950. && wMode == absoluteSize
  72951. && hMode == absoluteSize;
  72952. }
  72953. void PositionedRectangle::addPosDescription (String& s, const uint8 mode, const double value) const throw()
  72954. {
  72955. if ((mode & proportionOfParentSize) != 0)
  72956. {
  72957. s << (roundToInt (value * 100000.0) / 1000.0) << T('%');
  72958. }
  72959. else
  72960. {
  72961. s << (roundToInt (value * 100.0) / 100.0);
  72962. if ((mode & absoluteFromParentBottomRight) != 0)
  72963. s << T('R');
  72964. else if ((mode & absoluteFromParentCentre) != 0)
  72965. s << T('C');
  72966. }
  72967. if ((mode & anchorAtRightOrBottom) != 0)
  72968. s << T('r');
  72969. else if ((mode & anchorAtCentre) != 0)
  72970. s << T('c');
  72971. }
  72972. void PositionedRectangle::addSizeDescription (String& s, const uint8 mode, const double value) const throw()
  72973. {
  72974. if (mode == proportionalSize)
  72975. s << (roundToInt (value * 100000.0) / 1000.0) << T('%');
  72976. else if (mode == parentSizeMinusAbsolute)
  72977. s << (roundToInt (value * 100.0) / 100.0) << T('M');
  72978. else
  72979. s << (roundToInt (value * 100.0) / 100.0);
  72980. }
  72981. void PositionedRectangle::decodePosString (const String& s, uint8& mode, double& value) throw()
  72982. {
  72983. if (s.containsChar (T('r')))
  72984. mode = anchorAtRightOrBottom;
  72985. else if (s.containsChar (T('c')))
  72986. mode = anchorAtCentre;
  72987. else
  72988. mode = anchorAtLeftOrTop;
  72989. if (s.containsChar (T('%')))
  72990. {
  72991. mode |= proportionOfParentSize;
  72992. value = s.removeCharacters (T("%rcRC")).getDoubleValue() / 100.0;
  72993. }
  72994. else
  72995. {
  72996. if (s.containsChar (T('R')))
  72997. mode |= absoluteFromParentBottomRight;
  72998. else if (s.containsChar (T('C')))
  72999. mode |= absoluteFromParentCentre;
  73000. else
  73001. mode |= absoluteFromParentTopLeft;
  73002. value = s.removeCharacters (T("rcRC")).getDoubleValue();
  73003. }
  73004. }
  73005. void PositionedRectangle::decodeSizeString (const String& s, uint8& mode, double& value) throw()
  73006. {
  73007. if (s.containsChar (T('%')))
  73008. {
  73009. mode = proportionalSize;
  73010. value = s.upToFirstOccurrenceOf (T("%"), false, false).getDoubleValue() / 100.0;
  73011. }
  73012. else if (s.containsChar (T('M')))
  73013. {
  73014. mode = parentSizeMinusAbsolute;
  73015. value = s.getDoubleValue();
  73016. }
  73017. else
  73018. {
  73019. mode = absoluteSize;
  73020. value = s.getDoubleValue();
  73021. }
  73022. }
  73023. void PositionedRectangle::applyPosAndSize (double& xOut, double& wOut,
  73024. const double x_, const double w_,
  73025. const uint8 xMode_, const uint8 wMode_,
  73026. const int parentPos,
  73027. const int parentSize) const throw()
  73028. {
  73029. if (wMode_ == proportionalSize)
  73030. wOut = roundToInt (w_ * parentSize);
  73031. else if (wMode_ == parentSizeMinusAbsolute)
  73032. wOut = jmax (0, parentSize - roundToInt (w_));
  73033. else
  73034. wOut = roundToInt (w_);
  73035. if ((xMode_ & proportionOfParentSize) != 0)
  73036. xOut = parentPos + x_ * parentSize;
  73037. else if ((xMode_ & absoluteFromParentBottomRight) != 0)
  73038. xOut = (parentPos + parentSize) - x_;
  73039. else if ((xMode_ & absoluteFromParentCentre) != 0)
  73040. xOut = x_ + (parentPos + parentSize / 2);
  73041. else
  73042. xOut = x_ + parentPos;
  73043. if ((xMode_ & anchorAtRightOrBottom) != 0)
  73044. xOut -= wOut;
  73045. else if ((xMode_ & anchorAtCentre) != 0)
  73046. xOut -= wOut / 2;
  73047. }
  73048. void PositionedRectangle::updatePosAndSize (double& xOut, double& wOut,
  73049. double x_, const double w_,
  73050. const uint8 xMode_, const uint8 wMode_,
  73051. const int parentPos,
  73052. const int parentSize) const throw()
  73053. {
  73054. if (wMode_ == proportionalSize)
  73055. {
  73056. if (parentSize > 0)
  73057. wOut = w_ / parentSize;
  73058. }
  73059. else if (wMode_ == parentSizeMinusAbsolute)
  73060. wOut = parentSize - w_;
  73061. else
  73062. wOut = w_;
  73063. if ((xMode_ & anchorAtRightOrBottom) != 0)
  73064. x_ += w_;
  73065. else if ((xMode_ & anchorAtCentre) != 0)
  73066. x_ += w_ / 2;
  73067. if ((xMode_ & proportionOfParentSize) != 0)
  73068. {
  73069. if (parentSize > 0)
  73070. xOut = (x_ - parentPos) / parentSize;
  73071. }
  73072. else if ((xMode_ & absoluteFromParentBottomRight) != 0)
  73073. xOut = (parentPos + parentSize) - x_;
  73074. else if ((xMode_ & absoluteFromParentCentre) != 0)
  73075. xOut = x_ - (parentPos + parentSize / 2);
  73076. else
  73077. xOut = x_ - parentPos;
  73078. }
  73079. END_JUCE_NAMESPACE
  73080. /*** End of inlined file: juce_PositionedRectangle.cpp ***/
  73081. /*** Start of inlined file: juce_RectangleList.cpp ***/
  73082. BEGIN_JUCE_NAMESPACE
  73083. RectangleList::RectangleList() throw()
  73084. {
  73085. }
  73086. RectangleList::RectangleList (const Rectangle<int>& rect) throw()
  73087. {
  73088. if (! rect.isEmpty())
  73089. rects.add (rect);
  73090. }
  73091. RectangleList::RectangleList (const RectangleList& other) throw()
  73092. : rects (other.rects)
  73093. {
  73094. }
  73095. RectangleList& RectangleList::operator= (const RectangleList& other) throw()
  73096. {
  73097. rects = other.rects;
  73098. return *this;
  73099. }
  73100. RectangleList::~RectangleList() throw()
  73101. {
  73102. }
  73103. void RectangleList::clear() throw()
  73104. {
  73105. rects.clearQuick();
  73106. }
  73107. const Rectangle<int> RectangleList::getRectangle (const int index) const throw()
  73108. {
  73109. if (((unsigned int) index) < (unsigned int) rects.size())
  73110. return rects.getReference (index);
  73111. return Rectangle<int>();
  73112. }
  73113. bool RectangleList::isEmpty() const throw()
  73114. {
  73115. return rects.size() == 0;
  73116. }
  73117. RectangleList::Iterator::Iterator (const RectangleList& list) throw()
  73118. : current (0),
  73119. owner (list),
  73120. index (list.rects.size())
  73121. {
  73122. }
  73123. RectangleList::Iterator::~Iterator() throw()
  73124. {
  73125. }
  73126. bool RectangleList::Iterator::next() throw()
  73127. {
  73128. if (--index >= 0)
  73129. {
  73130. current = & (owner.rects.getReference (index));
  73131. return true;
  73132. }
  73133. return false;
  73134. }
  73135. void RectangleList::add (const Rectangle<int>& rect) throw()
  73136. {
  73137. if (! rect.isEmpty())
  73138. {
  73139. if (rects.size() == 0)
  73140. {
  73141. rects.add (rect);
  73142. }
  73143. else
  73144. {
  73145. bool anyOverlaps = false;
  73146. int i;
  73147. for (i = rects.size(); --i >= 0;)
  73148. {
  73149. Rectangle<int>& ourRect = rects.getReference (i);
  73150. if (rect.intersects (ourRect))
  73151. {
  73152. if (rect.contains (ourRect))
  73153. rects.remove (i);
  73154. else if (! ourRect.reduceIfPartlyContainedIn (rect))
  73155. anyOverlaps = true;
  73156. }
  73157. }
  73158. if (anyOverlaps && rects.size() > 0)
  73159. {
  73160. RectangleList r (rect);
  73161. for (i = rects.size(); --i >= 0;)
  73162. {
  73163. const Rectangle<int>& ourRect = rects.getReference (i);
  73164. if (rect.intersects (ourRect))
  73165. {
  73166. r.subtract (ourRect);
  73167. if (r.rects.size() == 0)
  73168. return;
  73169. }
  73170. }
  73171. for (i = r.getNumRectangles(); --i >= 0;)
  73172. rects.add (r.rects.getReference (i));
  73173. }
  73174. else
  73175. {
  73176. rects.add (rect);
  73177. }
  73178. }
  73179. }
  73180. }
  73181. void RectangleList::addWithoutMerging (const Rectangle<int>& rect) throw()
  73182. {
  73183. rects.add (rect);
  73184. }
  73185. void RectangleList::add (const int x, const int y, const int w, const int h) throw()
  73186. {
  73187. if (rects.size() == 0)
  73188. {
  73189. if (w > 0 && h > 0)
  73190. rects.add (Rectangle<int> (x, y, w, h));
  73191. }
  73192. else
  73193. {
  73194. add (Rectangle<int> (x, y, w, h));
  73195. }
  73196. }
  73197. void RectangleList::add (const RectangleList& other) throw()
  73198. {
  73199. for (int i = 0; i < other.rects.size(); ++i)
  73200. add (other.rects.getReference (i));
  73201. }
  73202. void RectangleList::subtract (const Rectangle<int>& rect) throw()
  73203. {
  73204. const int originalNumRects = rects.size();
  73205. if (originalNumRects > 0)
  73206. {
  73207. const int x1 = rect.x;
  73208. const int y1 = rect.y;
  73209. const int x2 = x1 + rect.w;
  73210. const int y2 = y1 + rect.h;
  73211. for (int i = getNumRectangles(); --i >= 0;)
  73212. {
  73213. Rectangle<int>& r = rects.getReference (i);
  73214. const int rx1 = r.x;
  73215. const int ry1 = r.y;
  73216. const int rx2 = rx1 + r.w;
  73217. const int ry2 = ry1 + r.h;
  73218. if (! (x2 <= rx1 || x1 >= rx2 || y2 <= ry1 || y1 >= ry2))
  73219. {
  73220. if (x1 > rx1 && x1 < rx2)
  73221. {
  73222. if (y1 <= ry1 && y2 >= ry2 && x2 >= rx2)
  73223. {
  73224. r.w = x1 - rx1;
  73225. }
  73226. else
  73227. {
  73228. r.x = x1;
  73229. r.w = rx2 - x1;
  73230. rects.insert (i + 1, Rectangle<int> (rx1, ry1, x1 - rx1, ry2 - ry1));
  73231. i += 2;
  73232. }
  73233. }
  73234. else if (x2 > rx1 && x2 < rx2)
  73235. {
  73236. r.x = x2;
  73237. r.w = rx2 - x2;
  73238. if (y1 > ry1 || y2 < ry2 || x1 > rx1)
  73239. {
  73240. rects.insert (i + 1, Rectangle<int> (rx1, ry1, x2 - rx1, ry2 - ry1));
  73241. i += 2;
  73242. }
  73243. }
  73244. else if (y1 > ry1 && y1 < ry2)
  73245. {
  73246. if (x1 <= rx1 && x2 >= rx2 && y2 >= ry2)
  73247. {
  73248. r.h = y1 - ry1;
  73249. }
  73250. else
  73251. {
  73252. r.y = y1;
  73253. r.h = ry2 - y1;
  73254. rects.insert (i + 1, Rectangle<int> (rx1, ry1, rx2 - rx1, y1 - ry1));
  73255. i += 2;
  73256. }
  73257. }
  73258. else if (y2 > ry1 && y2 < ry2)
  73259. {
  73260. r.y = y2;
  73261. r.h = ry2 - y2;
  73262. if (x1 > rx1 || x2 < rx2 || y1 > ry1)
  73263. {
  73264. rects.insert (i + 1, Rectangle<int> (rx1, ry1, rx2 - rx1, y2 - ry1));
  73265. i += 2;
  73266. }
  73267. }
  73268. else
  73269. {
  73270. rects.remove (i);
  73271. }
  73272. }
  73273. }
  73274. if (rects.size() > originalNumRects + 10)
  73275. consolidate();
  73276. }
  73277. }
  73278. void RectangleList::subtract (const RectangleList& otherList) throw()
  73279. {
  73280. for (int i = otherList.rects.size(); --i >= 0;)
  73281. subtract (otherList.rects.getReference (i));
  73282. }
  73283. bool RectangleList::clipTo (const Rectangle<int>& rect) throw()
  73284. {
  73285. bool notEmpty = false;
  73286. if (rect.isEmpty())
  73287. {
  73288. clear();
  73289. }
  73290. else
  73291. {
  73292. for (int i = rects.size(); --i >= 0;)
  73293. {
  73294. Rectangle<int>& r = rects.getReference (i);
  73295. if (! rect.intersectRectangle (r.x, r.y, r.w, r.h))
  73296. rects.remove (i);
  73297. else
  73298. notEmpty = true;
  73299. }
  73300. }
  73301. return notEmpty;
  73302. }
  73303. bool RectangleList::clipTo (const RectangleList& other) throw()
  73304. {
  73305. if (rects.size() == 0)
  73306. return false;
  73307. RectangleList result;
  73308. for (int j = 0; j < rects.size(); ++j)
  73309. {
  73310. const Rectangle<int>& rect = rects.getReference (j);
  73311. for (int i = other.rects.size(); --i >= 0;)
  73312. {
  73313. Rectangle<int> r (other.rects.getReference (i));
  73314. if (rect.intersectRectangle (r.x, r.y, r.w, r.h))
  73315. result.rects.add (r);
  73316. }
  73317. }
  73318. swapWith (result);
  73319. return ! isEmpty();
  73320. }
  73321. bool RectangleList::getIntersectionWith (const Rectangle<int>& rect, RectangleList& destRegion) const throw()
  73322. {
  73323. destRegion.clear();
  73324. if (! rect.isEmpty())
  73325. {
  73326. for (int i = rects.size(); --i >= 0;)
  73327. {
  73328. Rectangle<int> r (rects.getReference (i));
  73329. if (rect.intersectRectangle (r.x, r.y, r.w, r.h))
  73330. destRegion.rects.add (r);
  73331. }
  73332. }
  73333. return destRegion.rects.size() > 0;
  73334. }
  73335. void RectangleList::swapWith (RectangleList& otherList) throw()
  73336. {
  73337. rects.swapWithArray (otherList.rects);
  73338. }
  73339. void RectangleList::consolidate() throw()
  73340. {
  73341. int i;
  73342. for (i = 0; i < getNumRectangles() - 1; ++i)
  73343. {
  73344. Rectangle<int>& r = rects.getReference (i);
  73345. const int rx1 = r.x;
  73346. const int ry1 = r.y;
  73347. const int rx2 = rx1 + r.w;
  73348. const int ry2 = ry1 + r.h;
  73349. for (int j = rects.size(); --j > i;)
  73350. {
  73351. Rectangle<int>& r2 = rects.getReference (j);
  73352. const int jrx1 = r2.x;
  73353. const int jry1 = r2.y;
  73354. const int jrx2 = jrx1 + r2.w;
  73355. const int jry2 = jry1 + r2.h;
  73356. // if the vertical edges of any blocks are touching and their horizontals don't
  73357. // line up, split them horizontally..
  73358. if (jrx1 == rx2 || jrx2 == rx1)
  73359. {
  73360. if (jry1 > ry1 && jry1 < ry2)
  73361. {
  73362. r.h = jry1 - ry1;
  73363. rects.add (Rectangle<int> (rx1, jry1, rx2 - rx1, ry2 - jry1));
  73364. i = -1;
  73365. break;
  73366. }
  73367. if (jry2 > ry1 && jry2 < ry2)
  73368. {
  73369. r.h = jry2 - ry1;
  73370. rects.add (Rectangle<int> (rx1, jry2, rx2 - rx1, ry2 - jry2));
  73371. i = -1;
  73372. break;
  73373. }
  73374. else if (ry1 > jry1 && ry1 < jry2)
  73375. {
  73376. r2.h = ry1 - jry1;
  73377. rects.add (Rectangle<int> (jrx1, ry1, jrx2 - jrx1, jry2 - ry1));
  73378. i = -1;
  73379. break;
  73380. }
  73381. else if (ry2 > jry1 && ry2 < jry2)
  73382. {
  73383. r2.h = ry2 - jry1;
  73384. rects.add (Rectangle<int> (jrx1, ry2, jrx2 - jrx1, jry2 - ry2));
  73385. i = -1;
  73386. break;
  73387. }
  73388. }
  73389. }
  73390. }
  73391. for (i = 0; i < rects.size() - 1; ++i)
  73392. {
  73393. Rectangle<int>& r = rects.getReference (i);
  73394. for (int j = rects.size(); --j > i;)
  73395. {
  73396. if (r.enlargeIfAdjacent (rects.getReference (j)))
  73397. {
  73398. rects.remove (j);
  73399. i = -1;
  73400. break;
  73401. }
  73402. }
  73403. }
  73404. }
  73405. bool RectangleList::containsPoint (const int x, const int y) const throw()
  73406. {
  73407. for (int i = getNumRectangles(); --i >= 0;)
  73408. if (rects.getReference (i).contains (x, y))
  73409. return true;
  73410. return false;
  73411. }
  73412. bool RectangleList::containsRectangle (const Rectangle<int>& rectangleToCheck) const throw()
  73413. {
  73414. if (rects.size() > 1)
  73415. {
  73416. RectangleList r (rectangleToCheck);
  73417. for (int i = rects.size(); --i >= 0;)
  73418. {
  73419. r.subtract (rects.getReference (i));
  73420. if (r.rects.size() == 0)
  73421. return true;
  73422. }
  73423. }
  73424. else if (rects.size() > 0)
  73425. {
  73426. return rects.getReference (0).contains (rectangleToCheck);
  73427. }
  73428. return false;
  73429. }
  73430. bool RectangleList::intersectsRectangle (const Rectangle<int>& rectangleToCheck) const throw()
  73431. {
  73432. for (int i = rects.size(); --i >= 0;)
  73433. if (rects.getReference (i).intersects (rectangleToCheck))
  73434. return true;
  73435. return false;
  73436. }
  73437. bool RectangleList::intersects (const RectangleList& other) const throw()
  73438. {
  73439. for (int i = rects.size(); --i >= 0;)
  73440. if (other.intersectsRectangle (rects.getReference (i)))
  73441. return true;
  73442. return false;
  73443. }
  73444. const Rectangle<int> RectangleList::getBounds() const throw()
  73445. {
  73446. if (rects.size() <= 1)
  73447. {
  73448. if (rects.size() == 0)
  73449. return Rectangle<int>();
  73450. else
  73451. return rects.getReference (0);
  73452. }
  73453. else
  73454. {
  73455. const Rectangle<int>& r = rects.getReference (0);
  73456. int minX = r.x;
  73457. int minY = r.y;
  73458. int maxX = minX + r.w;
  73459. int maxY = minY + r.h;
  73460. for (int i = rects.size(); --i > 0;)
  73461. {
  73462. const Rectangle<int>& r2 = rects.getReference (i);
  73463. minX = jmin (minX, r2.x);
  73464. minY = jmin (minY, r2.y);
  73465. maxX = jmax (maxX, r2.getRight());
  73466. maxY = jmax (maxY, r2.getBottom());
  73467. }
  73468. return Rectangle<int> (minX, minY, maxX - minX, maxY - minY);
  73469. }
  73470. }
  73471. void RectangleList::offsetAll (const int dx, const int dy) throw()
  73472. {
  73473. for (int i = rects.size(); --i >= 0;)
  73474. {
  73475. Rectangle<int>& r = rects.getReference (i);
  73476. r.x += dx;
  73477. r.y += dy;
  73478. }
  73479. }
  73480. const Path RectangleList::toPath() const throw()
  73481. {
  73482. Path p;
  73483. for (int i = rects.size(); --i >= 0;)
  73484. {
  73485. const Rectangle<int>& r = rects.getReference (i);
  73486. p.addRectangle ((float) r.x,
  73487. (float) r.y,
  73488. (float) r.w,
  73489. (float) r.h);
  73490. }
  73491. return p;
  73492. }
  73493. END_JUCE_NAMESPACE
  73494. /*** End of inlined file: juce_RectangleList.cpp ***/
  73495. /*** Start of inlined file: juce_Image.cpp ***/
  73496. BEGIN_JUCE_NAMESPACE
  73497. static const int fullAlphaThreshold = 253;
  73498. Image::Image (const PixelFormat format_,
  73499. const int imageWidth_,
  73500. const int imageHeight_)
  73501. : format (format_),
  73502. imageWidth (imageWidth_),
  73503. imageHeight (imageHeight_),
  73504. imageData (0)
  73505. {
  73506. jassert (format_ == RGB || format_ == ARGB || format_ == SingleChannel);
  73507. jassert (imageWidth_ > 0 && imageHeight_ > 0); // it's illegal to create a zero-sized image - the
  73508. // actual image will be at least 1x1.
  73509. }
  73510. Image::Image (const PixelFormat format_,
  73511. const int imageWidth_,
  73512. const int imageHeight_,
  73513. const bool clearImage)
  73514. : format (format_),
  73515. imageWidth (imageWidth_),
  73516. imageHeight (imageHeight_)
  73517. {
  73518. jassert (format_ == RGB || format_ == ARGB || format_ == SingleChannel);
  73519. jassert (imageWidth_ > 0 && imageHeight_ > 0); // it's illegal to create a zero-sized image - the
  73520. // actual image will be at least 1x1.
  73521. pixelStride = (format == RGB) ? 3 : ((format == ARGB) ? 4 : 1);
  73522. lineStride = (pixelStride * jmax (1, imageWidth_) + 3) & ~3;
  73523. imageDataAllocated.allocate (lineStride * jmax (1, imageHeight_), clearImage);
  73524. imageData = imageDataAllocated;
  73525. }
  73526. Image::Image (const Image& other)
  73527. : format (other.format),
  73528. imageWidth (other.imageWidth),
  73529. imageHeight (other.imageHeight)
  73530. {
  73531. pixelStride = (format == RGB) ? 3 : ((format == ARGB) ? 4 : 1);
  73532. lineStride = (pixelStride * jmax (1, imageWidth) + 3) & ~3;
  73533. imageDataAllocated.malloc (lineStride * jmax (1, imageHeight));
  73534. imageData = imageDataAllocated;
  73535. BitmapData srcData (other, 0, 0, imageWidth, imageHeight);
  73536. setPixelData (0, 0, imageWidth, imageHeight, srcData.data, srcData.lineStride);
  73537. }
  73538. Image::~Image()
  73539. {
  73540. }
  73541. LowLevelGraphicsContext* Image::createLowLevelContext()
  73542. {
  73543. return new LowLevelGraphicsSoftwareRenderer (*this);
  73544. }
  73545. Image::BitmapData::BitmapData (Image& image, int x, int y, int w, int h, const bool /*makeWritable*/)
  73546. : data (image.imageData + image.lineStride * y + image.pixelStride * x),
  73547. lineStride (image.lineStride),
  73548. pixelStride (image.pixelStride),
  73549. width (w),
  73550. height (h)
  73551. {
  73552. jassert (x >= 0 && y >= 0 && w > 0 && h > 0 && x + w <= image.getWidth() && y + h <= image.getHeight());
  73553. }
  73554. Image::BitmapData::BitmapData (const Image& image, int x, int y, int w, int h)
  73555. : data (image.imageData + image.lineStride * y + image.pixelStride * x),
  73556. lineStride (image.lineStride),
  73557. pixelStride (image.pixelStride),
  73558. width (w),
  73559. height (h)
  73560. {
  73561. jassert (x >= 0 && y >= 0 && w > 0 && h > 0 && x + w <= image.getWidth() && y + h <= image.getHeight());
  73562. }
  73563. Image::BitmapData::~BitmapData()
  73564. {
  73565. }
  73566. void Image::setPixelData (int x, int y, int w, int h,
  73567. const uint8* sourcePixelData, int sourceLineStride)
  73568. {
  73569. jassert (x >= 0 && y >= 0 && w > 0 && h > 0 && x + w <= imageWidth && y + h <= imageHeight);
  73570. if (Rectangle<int>::intersectRectangles (x, y, w, h, 0, 0, imageWidth, imageHeight))
  73571. {
  73572. const BitmapData dest (*this, x, y, w, h, true);
  73573. for (int i = 0; i < h; ++i)
  73574. {
  73575. memcpy (dest.getLinePointer(i),
  73576. sourcePixelData + sourceLineStride * i,
  73577. w * dest.pixelStride);
  73578. }
  73579. }
  73580. }
  73581. void Image::clear (int dx, int dy, int dw, int dh, const Colour& colourToClearTo)
  73582. {
  73583. if (Rectangle<int>::intersectRectangles (dx, dy, dw, dh, 0, 0, imageWidth, imageHeight))
  73584. {
  73585. const PixelARGB col (colourToClearTo.getPixelARGB());
  73586. const BitmapData destData (*this, dx, dy, dw, dh, true);
  73587. uint8* dest = destData.data;
  73588. while (--dh >= 0)
  73589. {
  73590. uint8* line = dest;
  73591. dest += destData.lineStride;
  73592. if (isARGB())
  73593. {
  73594. for (int x = dw; --x >= 0;)
  73595. {
  73596. ((PixelARGB*) line)->set (col);
  73597. line += destData.pixelStride;
  73598. }
  73599. }
  73600. else if (isRGB())
  73601. {
  73602. for (int x = dw; --x >= 0;)
  73603. {
  73604. ((PixelRGB*) line)->set (col);
  73605. line += destData.pixelStride;
  73606. }
  73607. }
  73608. else
  73609. {
  73610. for (int x = dw; --x >= 0;)
  73611. {
  73612. *line = col.getAlpha();
  73613. line += destData.pixelStride;
  73614. }
  73615. }
  73616. }
  73617. }
  73618. }
  73619. Image* Image::createCopy (int newWidth, int newHeight,
  73620. const Graphics::ResamplingQuality quality) const
  73621. {
  73622. if (newWidth < 0)
  73623. newWidth = imageWidth;
  73624. if (newHeight < 0)
  73625. newHeight = imageHeight;
  73626. Image* const newImage = Image::createNativeImage (format, newWidth, newHeight, true);
  73627. Graphics g (*newImage);
  73628. g.setImageResamplingQuality (quality);
  73629. g.drawImage (this,
  73630. 0, 0, newWidth, newHeight,
  73631. 0, 0, imageWidth, imageHeight,
  73632. false);
  73633. return newImage;
  73634. }
  73635. Image* Image::createCopyOfAlphaChannel() const
  73636. {
  73637. jassert (format != SingleChannel);
  73638. Image* const newImage = Image::createNativeImage (SingleChannel, imageWidth, imageHeight, false);
  73639. if (! hasAlphaChannel())
  73640. {
  73641. newImage->clear (0, 0, imageWidth, imageHeight, Colours::black);
  73642. }
  73643. else
  73644. {
  73645. const BitmapData destData (*newImage, 0, 0, imageWidth, imageHeight, true);
  73646. const BitmapData srcData (*this, 0, 0, imageWidth, imageHeight);
  73647. for (int y = 0; y < imageHeight; ++y)
  73648. {
  73649. const PixelARGB* src = (const PixelARGB*) srcData.getLinePointer(y);
  73650. uint8* dst = destData.getLinePointer (y);
  73651. for (int x = imageWidth; --x >= 0;)
  73652. {
  73653. *dst++ = src->getAlpha();
  73654. ++src;
  73655. }
  73656. }
  73657. }
  73658. return newImage;
  73659. }
  73660. const Colour Image::getPixelAt (const int x, const int y) const
  73661. {
  73662. Colour c;
  73663. if (((unsigned int) x) < (unsigned int) imageWidth
  73664. && ((unsigned int) y) < (unsigned int) imageHeight)
  73665. {
  73666. const BitmapData srcData (*this, x, y, 1, 1);
  73667. if (isARGB())
  73668. {
  73669. PixelARGB p (*(const PixelARGB*) srcData.data);
  73670. p.unpremultiply();
  73671. c = Colour (p.getARGB());
  73672. }
  73673. else if (isRGB())
  73674. c = Colour (((const PixelRGB*) srcData.data)->getARGB());
  73675. else
  73676. c = Colour ((uint8) 0, (uint8) 0, (uint8) 0, *(srcData.data));
  73677. }
  73678. return c;
  73679. }
  73680. void Image::setPixelAt (const int x, const int y,
  73681. const Colour& colour)
  73682. {
  73683. if (((unsigned int) x) < (unsigned int) imageWidth
  73684. && ((unsigned int) y) < (unsigned int) imageHeight)
  73685. {
  73686. const BitmapData destData (*this, x, y, 1, 1, true);
  73687. const PixelARGB col (colour.getPixelARGB());
  73688. if (isARGB())
  73689. ((PixelARGB*) destData.data)->set (col);
  73690. else if (isRGB())
  73691. ((PixelRGB*) destData.data)->set (col);
  73692. else
  73693. *(destData.data) = col.getAlpha();
  73694. }
  73695. }
  73696. void Image::multiplyAlphaAt (const int x, const int y,
  73697. const float multiplier)
  73698. {
  73699. if (((unsigned int) x) < (unsigned int) imageWidth
  73700. && ((unsigned int) y) < (unsigned int) imageHeight
  73701. && hasAlphaChannel())
  73702. {
  73703. const BitmapData destData (*this, x, y, 1, 1, true);
  73704. if (isARGB())
  73705. ((PixelARGB*) destData.data)->multiplyAlpha (multiplier);
  73706. else
  73707. *(destData.data) = (uint8) (*(destData.data) * multiplier);
  73708. }
  73709. }
  73710. void Image::multiplyAllAlphas (const float amountToMultiplyBy)
  73711. {
  73712. if (hasAlphaChannel())
  73713. {
  73714. const BitmapData destData (*this, 0, 0, getWidth(), getHeight(), true);
  73715. if (isARGB())
  73716. {
  73717. for (int y = 0; y < imageHeight; ++y)
  73718. {
  73719. uint8* p = destData.getLinePointer (y);
  73720. for (int x = 0; x < imageWidth; ++x)
  73721. {
  73722. ((PixelARGB*) p)->multiplyAlpha (amountToMultiplyBy);
  73723. p += destData.pixelStride;
  73724. }
  73725. }
  73726. }
  73727. else
  73728. {
  73729. for (int y = 0; y < imageHeight; ++y)
  73730. {
  73731. uint8* p = destData.getLinePointer (y);
  73732. for (int x = 0; x < imageWidth; ++x)
  73733. {
  73734. *p = (uint8) (*p * amountToMultiplyBy);
  73735. p += destData.pixelStride;
  73736. }
  73737. }
  73738. }
  73739. }
  73740. else
  73741. {
  73742. jassertfalse // can't do this without an alpha-channel!
  73743. }
  73744. }
  73745. void Image::desaturate()
  73746. {
  73747. if (isARGB() || isRGB())
  73748. {
  73749. const BitmapData destData (*this, 0, 0, getWidth(), getHeight(), true);
  73750. if (isARGB())
  73751. {
  73752. for (int y = 0; y < imageHeight; ++y)
  73753. {
  73754. uint8* p = destData.getLinePointer (y);
  73755. for (int x = 0; x < imageWidth; ++x)
  73756. {
  73757. ((PixelARGB*) p)->desaturate();
  73758. p += destData.pixelStride;
  73759. }
  73760. }
  73761. }
  73762. else
  73763. {
  73764. for (int y = 0; y < imageHeight; ++y)
  73765. {
  73766. uint8* p = destData.getLinePointer (y);
  73767. for (int x = 0; x < imageWidth; ++x)
  73768. {
  73769. ((PixelRGB*) p)->desaturate();
  73770. p += destData.pixelStride;
  73771. }
  73772. }
  73773. }
  73774. }
  73775. }
  73776. void Image::createSolidAreaMask (RectangleList& result, const float alphaThreshold) const
  73777. {
  73778. if (hasAlphaChannel())
  73779. {
  73780. const uint8 threshold = (uint8) jlimit (0, 255, roundToInt (alphaThreshold * 255.0f));
  73781. SparseSet <int> pixelsOnRow;
  73782. const BitmapData srcData (*this, 0, 0, getWidth(), getHeight());
  73783. for (int y = 0; y < imageHeight; ++y)
  73784. {
  73785. pixelsOnRow.clear();
  73786. const uint8* lineData = srcData.getLinePointer (y);
  73787. if (isARGB())
  73788. {
  73789. for (int x = 0; x < imageWidth; ++x)
  73790. {
  73791. if (((const PixelARGB*) lineData)->getAlpha() >= threshold)
  73792. pixelsOnRow.addRange (x, 1);
  73793. lineData += srcData.pixelStride;
  73794. }
  73795. }
  73796. else
  73797. {
  73798. for (int x = 0; x < imageWidth; ++x)
  73799. {
  73800. if (*lineData >= threshold)
  73801. pixelsOnRow.addRange (x, 1);
  73802. lineData += srcData.pixelStride;
  73803. }
  73804. }
  73805. for (int i = 0; i < pixelsOnRow.getNumRanges(); ++i)
  73806. {
  73807. int x, w;
  73808. if (pixelsOnRow.getRange (i, x, w))
  73809. result.add (Rectangle<int> (x, y, w, 1));
  73810. }
  73811. result.consolidate();
  73812. }
  73813. }
  73814. else
  73815. {
  73816. result.add (0, 0, imageWidth, imageHeight);
  73817. }
  73818. }
  73819. void Image::moveImageSection (int dx, int dy,
  73820. int sx, int sy,
  73821. int w, int h)
  73822. {
  73823. if (dx < 0)
  73824. {
  73825. w += dx;
  73826. sx -= dx;
  73827. dx = 0;
  73828. }
  73829. if (dy < 0)
  73830. {
  73831. h += dy;
  73832. sy -= dy;
  73833. dy = 0;
  73834. }
  73835. if (sx < 0)
  73836. {
  73837. w += sx;
  73838. dx -= sx;
  73839. sx = 0;
  73840. }
  73841. if (sy < 0)
  73842. {
  73843. h += sy;
  73844. dy -= sy;
  73845. sy = 0;
  73846. }
  73847. const int minX = jmin (dx, sx);
  73848. const int minY = jmin (dy, sy);
  73849. w = jmin (w, getWidth() - jmax (sx, dx));
  73850. h = jmin (h, getHeight() - jmax (sy, dy));
  73851. if (w > 0 && h > 0)
  73852. {
  73853. const int maxX = jmax (dx, sx) + w;
  73854. const int maxY = jmax (dy, sy) + h;
  73855. const BitmapData destData (*this, minX, minY, maxX - minX, maxY - minY, true);
  73856. uint8* dst = destData.getPixelPointer (dx - minX, dy - minY);
  73857. const uint8* src = destData.getPixelPointer (sx - minX, sy - minY);
  73858. const int lineSize = destData.pixelStride * w;
  73859. if (dy > sy)
  73860. {
  73861. while (--h >= 0)
  73862. {
  73863. const int offset = h * destData.lineStride;
  73864. memmove (dst + offset, src + offset, lineSize);
  73865. }
  73866. }
  73867. else if (dst != src)
  73868. {
  73869. while (--h >= 0)
  73870. {
  73871. memmove (dst, src, lineSize);
  73872. dst += destData.lineStride;
  73873. src += destData.lineStride;
  73874. }
  73875. }
  73876. }
  73877. }
  73878. END_JUCE_NAMESPACE
  73879. /*** End of inlined file: juce_Image.cpp ***/
  73880. /*** Start of inlined file: juce_ImageCache.cpp ***/
  73881. BEGIN_JUCE_NAMESPACE
  73882. struct ImageCache::Item
  73883. {
  73884. ScopedPointer <Image> image;
  73885. int64 hashCode;
  73886. int refCount;
  73887. uint32 releaseTime;
  73888. juce_UseDebuggingNewOperator
  73889. };
  73890. ImageCache* ImageCache::instance = 0;
  73891. int ImageCache::cacheTimeout = 5000;
  73892. ImageCache::ImageCache()
  73893. {
  73894. }
  73895. ImageCache::~ImageCache()
  73896. {
  73897. jassert (instance == this);
  73898. instance = 0;
  73899. }
  73900. Image* ImageCache::getFromHashCode (const int64 hashCode)
  73901. {
  73902. if (instance != 0)
  73903. {
  73904. const ScopedLock sl (instance->lock);
  73905. for (int i = instance->images.size(); --i >= 0;)
  73906. {
  73907. Item* const ci = instance->images.getUnchecked(i);
  73908. if (ci->hashCode == hashCode)
  73909. {
  73910. ci->refCount++;
  73911. return ci->image;
  73912. }
  73913. }
  73914. }
  73915. return 0;
  73916. }
  73917. void ImageCache::addImageToCache (Image* const image, const int64 hashCode)
  73918. {
  73919. if (image != 0)
  73920. {
  73921. if (instance == 0)
  73922. instance = new ImageCache();
  73923. Item* const newC = new Item();
  73924. newC->hashCode = hashCode;
  73925. newC->image = image;
  73926. newC->refCount = 1;
  73927. newC->releaseTime = 0;
  73928. const ScopedLock sl (instance->lock);
  73929. instance->images.add (newC);
  73930. }
  73931. }
  73932. void ImageCache::release (Image* const imageToRelease)
  73933. {
  73934. if (imageToRelease != 0 && instance != 0)
  73935. {
  73936. const ScopedLock sl (instance->lock);
  73937. for (int i = instance->images.size(); --i >= 0;)
  73938. {
  73939. Item* const ci = instance->images.getUnchecked(i);
  73940. if (static_cast <Image*> (ci->image) == imageToRelease)
  73941. {
  73942. if (--(ci->refCount) == 0)
  73943. ci->releaseTime = Time::getApproximateMillisecondCounter();
  73944. if (! instance->isTimerRunning())
  73945. instance->startTimer (999);
  73946. break;
  73947. }
  73948. }
  73949. }
  73950. }
  73951. void ImageCache::releaseOrDelete (Image* const imageToRelease)
  73952. {
  73953. if (isImageInCache (imageToRelease))
  73954. release (imageToRelease);
  73955. else
  73956. delete imageToRelease;
  73957. }
  73958. bool ImageCache::isImageInCache (Image* const imageToLookFor)
  73959. {
  73960. if (instance != 0)
  73961. {
  73962. const ScopedLock sl (instance->lock);
  73963. for (int i = instance->images.size(); --i >= 0;)
  73964. if (static_cast <Image*> (instance->images.getUnchecked(i)->image) == imageToLookFor)
  73965. return true;
  73966. }
  73967. return false;
  73968. }
  73969. void ImageCache::incReferenceCount (Image* const image)
  73970. {
  73971. if (instance != 0)
  73972. {
  73973. const ScopedLock sl (instance->lock);
  73974. for (int i = instance->images.size(); --i >= 0;)
  73975. {
  73976. Item* const ci = instance->images.getUnchecked(i);
  73977. if (static_cast <Image*> (ci->image) == image)
  73978. {
  73979. ci->refCount++;
  73980. return;
  73981. }
  73982. }
  73983. }
  73984. jassertfalse // (trying to inc the ref count of an image that's not in the cache)
  73985. }
  73986. void ImageCache::timerCallback()
  73987. {
  73988. int numberStillNeedingReleasing = 0;
  73989. const uint32 now = Time::getApproximateMillisecondCounter();
  73990. const ScopedLock sl (lock);
  73991. for (int i = images.size(); --i >= 0;)
  73992. {
  73993. Item* const ci = images.getUnchecked(i);
  73994. if (ci->refCount <= 0)
  73995. {
  73996. if (now > ci->releaseTime + cacheTimeout
  73997. || now < ci->releaseTime - 1000)
  73998. {
  73999. images.remove (i);
  74000. }
  74001. else
  74002. {
  74003. ++numberStillNeedingReleasing;
  74004. }
  74005. }
  74006. }
  74007. if (numberStillNeedingReleasing == 0)
  74008. stopTimer();
  74009. }
  74010. Image* ImageCache::getFromFile (const File& file)
  74011. {
  74012. const int64 hashCode = file.hashCode64();
  74013. Image* image = getFromHashCode (hashCode);
  74014. if (image == 0)
  74015. {
  74016. image = ImageFileFormat::loadFrom (file);
  74017. addImageToCache (image, hashCode);
  74018. }
  74019. return image;
  74020. }
  74021. Image* ImageCache::getFromMemory (const void* imageData, const int dataSize)
  74022. {
  74023. const int64 hashCode = (int64) (pointer_sized_int) imageData;
  74024. Image* image = getFromHashCode (hashCode);
  74025. if (image == 0)
  74026. {
  74027. image = ImageFileFormat::loadFrom (imageData, dataSize);
  74028. addImageToCache (image, hashCode);
  74029. }
  74030. return image;
  74031. }
  74032. void ImageCache::setCacheTimeout (const int millisecs)
  74033. {
  74034. cacheTimeout = millisecs;
  74035. }
  74036. END_JUCE_NAMESPACE
  74037. /*** End of inlined file: juce_ImageCache.cpp ***/
  74038. /*** Start of inlined file: juce_ImageConvolutionKernel.cpp ***/
  74039. BEGIN_JUCE_NAMESPACE
  74040. ImageConvolutionKernel::ImageConvolutionKernel (const int size_)
  74041. : values (size_ * size_),
  74042. size (size_)
  74043. {
  74044. clear();
  74045. }
  74046. ImageConvolutionKernel::~ImageConvolutionKernel()
  74047. {
  74048. }
  74049. float ImageConvolutionKernel::getKernelValue (const int x, const int y) const throw()
  74050. {
  74051. if (((unsigned int) x) < (unsigned int) size
  74052. && ((unsigned int) y) < (unsigned int) size)
  74053. {
  74054. return values [x + y * size];
  74055. }
  74056. else
  74057. {
  74058. jassertfalse;
  74059. return 0;
  74060. }
  74061. }
  74062. void ImageConvolutionKernel::setKernelValue (const int x, const int y, const float value) throw()
  74063. {
  74064. if (((unsigned int) x) < (unsigned int) size
  74065. && ((unsigned int) y) < (unsigned int) size)
  74066. {
  74067. values [x + y * size] = value;
  74068. }
  74069. else
  74070. {
  74071. jassertfalse;
  74072. }
  74073. }
  74074. void ImageConvolutionKernel::clear()
  74075. {
  74076. for (int i = size * size; --i >= 0;)
  74077. values[i] = 0;
  74078. }
  74079. void ImageConvolutionKernel::setOverallSum (const float desiredTotalSum)
  74080. {
  74081. double currentTotal = 0.0;
  74082. for (int i = size * size; --i >= 0;)
  74083. currentTotal += values[i];
  74084. rescaleAllValues ((float) (desiredTotalSum / currentTotal));
  74085. }
  74086. void ImageConvolutionKernel::rescaleAllValues (const float multiplier)
  74087. {
  74088. for (int i = size * size; --i >= 0;)
  74089. values[i] *= multiplier;
  74090. }
  74091. void ImageConvolutionKernel::createGaussianBlur (const float radius)
  74092. {
  74093. const double radiusFactor = -1.0 / (radius * radius * 2);
  74094. const int centre = size >> 1;
  74095. for (int y = size; --y >= 0;)
  74096. {
  74097. for (int x = size; --x >= 0;)
  74098. {
  74099. const int cx = x - centre;
  74100. const int cy = y - centre;
  74101. values [x + y * size] = (float) exp (radiusFactor * (cx * cx + cy * cy));
  74102. }
  74103. }
  74104. setOverallSum (1.0f);
  74105. }
  74106. void ImageConvolutionKernel::applyToImage (Image& destImage,
  74107. const Image* sourceImage,
  74108. int dx,
  74109. int dy,
  74110. int dw,
  74111. int dh) const
  74112. {
  74113. ScopedPointer <Image> imageCreated;
  74114. if (sourceImage == 0)
  74115. {
  74116. sourceImage = imageCreated = destImage.createCopy();
  74117. }
  74118. else
  74119. {
  74120. jassert (sourceImage->getWidth() == destImage.getWidth()
  74121. && sourceImage->getHeight() == destImage.getHeight()
  74122. && sourceImage->getFormat() == destImage.getFormat());
  74123. if (sourceImage->getWidth() != destImage.getWidth()
  74124. || sourceImage->getHeight() != destImage.getHeight()
  74125. || sourceImage->getFormat() != destImage.getFormat())
  74126. return;
  74127. }
  74128. const int imageWidth = destImage.getWidth();
  74129. const int imageHeight = destImage.getHeight();
  74130. if (dx >= imageWidth || dy >= imageHeight)
  74131. return;
  74132. if (dx + dw > imageWidth)
  74133. dw = imageWidth - dx;
  74134. if (dy + dh > imageHeight)
  74135. dh = imageHeight - dy;
  74136. const int dx2 = dx + dw;
  74137. const int dy2 = dy + dh;
  74138. const Image::BitmapData destData (destImage, dx, dy, dw, dh, true);
  74139. uint8* line = destData.data;
  74140. const Image::BitmapData srcData (*sourceImage, 0, 0, sourceImage->getWidth(), sourceImage->getHeight());
  74141. if (destData.pixelStride == 4)
  74142. {
  74143. for (int y = dy; y < dy2; ++y)
  74144. {
  74145. uint8* dest = line;
  74146. line += destData.lineStride;
  74147. for (int x = dx; x < dx2; ++x)
  74148. {
  74149. float c1 = 0;
  74150. float c2 = 0;
  74151. float c3 = 0;
  74152. float c4 = 0;
  74153. for (int yy = 0; yy < size; ++yy)
  74154. {
  74155. const int sy = y + yy - (size >> 1);
  74156. if (sy >= imageHeight)
  74157. break;
  74158. if (sy >= 0)
  74159. {
  74160. int sx = x - (size >> 1);
  74161. const uint8* src = srcData.getPixelPointer (sx, sy);
  74162. for (int xx = 0; xx < size; ++xx)
  74163. {
  74164. if (sx >= imageWidth)
  74165. break;
  74166. if (sx >= 0)
  74167. {
  74168. const float kernelMult = values [xx + yy * size];
  74169. c1 += kernelMult * *src++;
  74170. c2 += kernelMult * *src++;
  74171. c3 += kernelMult * *src++;
  74172. c4 += kernelMult * *src++;
  74173. }
  74174. else
  74175. {
  74176. src += 4;
  74177. }
  74178. ++sx;
  74179. }
  74180. }
  74181. }
  74182. *dest++ = (uint8) jmin (0xff, roundToInt (c1));
  74183. *dest++ = (uint8) jmin (0xff, roundToInt (c2));
  74184. *dest++ = (uint8) jmin (0xff, roundToInt (c3));
  74185. *dest++ = (uint8) jmin (0xff, roundToInt (c4));
  74186. }
  74187. }
  74188. }
  74189. else if (destData.pixelStride == 3)
  74190. {
  74191. for (int y = dy; y < dy2; ++y)
  74192. {
  74193. uint8* dest = line;
  74194. line += destData.lineStride;
  74195. for (int x = dx; x < dx2; ++x)
  74196. {
  74197. float c1 = 0;
  74198. float c2 = 0;
  74199. float c3 = 0;
  74200. for (int yy = 0; yy < size; ++yy)
  74201. {
  74202. const int sy = y + yy - (size >> 1);
  74203. if (sy >= imageHeight)
  74204. break;
  74205. if (sy >= 0)
  74206. {
  74207. int sx = x - (size >> 1);
  74208. const uint8* src = srcData.getPixelPointer (sx, sy);
  74209. for (int xx = 0; xx < size; ++xx)
  74210. {
  74211. if (sx >= imageWidth)
  74212. break;
  74213. if (sx >= 0)
  74214. {
  74215. const float kernelMult = values [xx + yy * size];
  74216. c1 += kernelMult * *src++;
  74217. c2 += kernelMult * *src++;
  74218. c3 += kernelMult * *src++;
  74219. }
  74220. else
  74221. {
  74222. src += 3;
  74223. }
  74224. ++sx;
  74225. }
  74226. }
  74227. }
  74228. *dest++ = (uint8) roundToInt (c1);
  74229. *dest++ = (uint8) roundToInt (c2);
  74230. *dest++ = (uint8) roundToInt (c3);
  74231. }
  74232. }
  74233. }
  74234. }
  74235. END_JUCE_NAMESPACE
  74236. /*** End of inlined file: juce_ImageConvolutionKernel.cpp ***/
  74237. /*** Start of inlined file: juce_ImageFileFormat.cpp ***/
  74238. BEGIN_JUCE_NAMESPACE
  74239. /*** Start of inlined file: juce_GIFLoader.h ***/
  74240. #ifndef __JUCE_GIFLOADER_JUCEHEADER__
  74241. #define __JUCE_GIFLOADER_JUCEHEADER__
  74242. #ifndef DOXYGEN
  74243. class GIFLoader
  74244. {
  74245. public:
  74246. GIFLoader (InputStream& in);
  74247. ~GIFLoader();
  74248. Image* getImage() const { return image; }
  74249. private:
  74250. Image* image;
  74251. InputStream& input;
  74252. uint8 buffer [300];
  74253. uint8 palette [256][4];
  74254. bool dataBlockIsZero, fresh, finished;
  74255. int currentBit, lastBit, lastByteIndex;
  74256. int codeSize, setCodeSize;
  74257. int maxCode, maxCodeSize;
  74258. int firstcode, oldcode;
  74259. int clearCode, end_code;
  74260. enum { maxGifCode = 1 << 12 };
  74261. int table [2] [maxGifCode];
  74262. int stack [2 * maxGifCode];
  74263. int *sp;
  74264. bool getSizeFromHeader (int& width, int& height);
  74265. bool readPalette (const int numCols);
  74266. int readDataBlock (unsigned char* dest);
  74267. int processExtension (int type, int& transparent);
  74268. int readLZWByte (bool initialise, int input_code_size);
  74269. int getCode (int code_size, bool initialise);
  74270. bool readImage (int width, int height, int interlace, int transparent);
  74271. static inline int makeWord (const uint8 a, const uint8 b) { return (b << 8) | a; }
  74272. GIFLoader (const GIFLoader&);
  74273. GIFLoader& operator= (const GIFLoader&);
  74274. };
  74275. #endif // DOXYGEN
  74276. #endif // __JUCE_GIFLOADER_JUCEHEADER__
  74277. /*** End of inlined file: juce_GIFLoader.h ***/
  74278. Image* juce_loadPNGImageFromStream (InputStream& inputStream);
  74279. bool juce_writePNGImageToStream (const Image& image, OutputStream& out);
  74280. PNGImageFormat::PNGImageFormat() {}
  74281. PNGImageFormat::~PNGImageFormat() {}
  74282. const String PNGImageFormat::getFormatName()
  74283. {
  74284. return T("PNG");
  74285. }
  74286. bool PNGImageFormat::canUnderstand (InputStream& in)
  74287. {
  74288. const int bytesNeeded = 4;
  74289. char header [bytesNeeded];
  74290. return in.read (header, bytesNeeded) == bytesNeeded
  74291. && header[1] == 'P'
  74292. && header[2] == 'N'
  74293. && header[3] == 'G';
  74294. }
  74295. Image* PNGImageFormat::decodeImage (InputStream& in)
  74296. {
  74297. return juce_loadPNGImageFromStream (in);
  74298. }
  74299. bool PNGImageFormat::writeImageToStream (const Image& sourceImage,
  74300. OutputStream& destStream)
  74301. {
  74302. return juce_writePNGImageToStream (sourceImage, destStream);
  74303. }
  74304. Image* juce_loadJPEGImageFromStream (InputStream& inputStream);
  74305. bool juce_writeJPEGImageToStream (const Image& image, OutputStream& out, float quality);
  74306. JPEGImageFormat::JPEGImageFormat()
  74307. : quality (-1.0f)
  74308. {
  74309. }
  74310. JPEGImageFormat::~JPEGImageFormat() {}
  74311. void JPEGImageFormat::setQuality (const float newQuality)
  74312. {
  74313. quality = newQuality;
  74314. }
  74315. const String JPEGImageFormat::getFormatName()
  74316. {
  74317. return T("JPEG");
  74318. }
  74319. bool JPEGImageFormat::canUnderstand (InputStream& in)
  74320. {
  74321. const int bytesNeeded = 10;
  74322. uint8 header [bytesNeeded];
  74323. if (in.read (header, bytesNeeded) == bytesNeeded)
  74324. {
  74325. return header[0] == 0xff
  74326. && header[1] == 0xd8
  74327. && header[2] == 0xff
  74328. && (header[3] == 0xe0 || header[3] == 0xe1);
  74329. }
  74330. return false;
  74331. }
  74332. Image* JPEGImageFormat::decodeImage (InputStream& in)
  74333. {
  74334. return juce_loadJPEGImageFromStream (in);
  74335. }
  74336. bool JPEGImageFormat::writeImageToStream (const Image& sourceImage,
  74337. OutputStream& destStream)
  74338. {
  74339. return juce_writeJPEGImageToStream (sourceImage, destStream, quality);
  74340. }
  74341. class GIFImageFormat : public ImageFileFormat
  74342. {
  74343. public:
  74344. GIFImageFormat() {}
  74345. ~GIFImageFormat() {}
  74346. const String getFormatName()
  74347. {
  74348. return T("GIF");
  74349. }
  74350. bool canUnderstand (InputStream& in)
  74351. {
  74352. const int bytesNeeded = 4;
  74353. char header [bytesNeeded];
  74354. return (in.read (header, bytesNeeded) == bytesNeeded)
  74355. && header[0] == 'G'
  74356. && header[1] == 'I'
  74357. && header[2] == 'F';
  74358. }
  74359. Image* decodeImage (InputStream& in)
  74360. {
  74361. const ScopedPointer <GIFLoader> loader (new GIFLoader (in));
  74362. return loader->getImage();
  74363. }
  74364. bool writeImageToStream (const Image& /*sourceImage*/, OutputStream& /*destStream*/)
  74365. {
  74366. return false;
  74367. }
  74368. };
  74369. ImageFileFormat* ImageFileFormat::findImageFormatForStream (InputStream& input)
  74370. {
  74371. static PNGImageFormat png;
  74372. static JPEGImageFormat jpg;
  74373. static GIFImageFormat gif;
  74374. ImageFileFormat* formats[4];
  74375. int numFormats = 0;
  74376. formats [numFormats++] = &png;
  74377. formats [numFormats++] = &jpg;
  74378. formats [numFormats++] = &gif;
  74379. const int64 streamPos = input.getPosition();
  74380. for (int i = 0; i < numFormats; ++i)
  74381. {
  74382. const bool found = formats[i]->canUnderstand (input);
  74383. input.setPosition (streamPos);
  74384. if (found)
  74385. return formats[i];
  74386. }
  74387. return 0;
  74388. }
  74389. Image* ImageFileFormat::loadFrom (InputStream& input)
  74390. {
  74391. ImageFileFormat* const format = findImageFormatForStream (input);
  74392. if (format != 0)
  74393. return format->decodeImage (input);
  74394. return 0;
  74395. }
  74396. Image* ImageFileFormat::loadFrom (const File& file)
  74397. {
  74398. InputStream* const in = file.createInputStream();
  74399. if (in != 0)
  74400. {
  74401. BufferedInputStream b (in, 8192, true);
  74402. return loadFrom (b);
  74403. }
  74404. return 0;
  74405. }
  74406. Image* ImageFileFormat::loadFrom (const void* rawData, const int numBytes)
  74407. {
  74408. if (rawData != 0 && numBytes > 4)
  74409. {
  74410. MemoryInputStream stream (rawData, numBytes, false);
  74411. return loadFrom (stream);
  74412. }
  74413. return 0;
  74414. }
  74415. END_JUCE_NAMESPACE
  74416. /*** End of inlined file: juce_ImageFileFormat.cpp ***/
  74417. /*** Start of inlined file: juce_GIFLoader.cpp ***/
  74418. BEGIN_JUCE_NAMESPACE
  74419. GIFLoader::GIFLoader (InputStream& in)
  74420. : image (0),
  74421. input (in),
  74422. dataBlockIsZero (false),
  74423. fresh (false),
  74424. finished (false)
  74425. {
  74426. currentBit = lastBit = lastByteIndex = 0;
  74427. maxCode = maxCodeSize = codeSize = setCodeSize = 0;
  74428. firstcode = oldcode = 0;
  74429. clearCode = end_code = 0;
  74430. int imageWidth, imageHeight;
  74431. int transparent = -1;
  74432. if (! getSizeFromHeader (imageWidth, imageHeight))
  74433. return;
  74434. if ((imageWidth <= 0) || (imageHeight <= 0))
  74435. return;
  74436. unsigned char buf [16];
  74437. if (in.read (buf, 3) != 3)
  74438. return;
  74439. int numColours = 2 << (buf[0] & 7);
  74440. if ((buf[0] & 0x80) != 0)
  74441. readPalette (numColours);
  74442. for (;;)
  74443. {
  74444. if (input.read (buf, 1) != 1)
  74445. break;
  74446. if (buf[0] == ';')
  74447. break;
  74448. if (buf[0] == '!')
  74449. {
  74450. if (input.read (buf, 1) != 1)
  74451. break;
  74452. if (processExtension (buf[0], transparent) < 0)
  74453. break;
  74454. continue;
  74455. }
  74456. if (buf[0] != ',')
  74457. continue;
  74458. if (input.read (buf, 9) != 9)
  74459. break;
  74460. imageWidth = makeWord (buf[4], buf[5]);
  74461. imageHeight = makeWord (buf[6], buf[7]);
  74462. numColours = 2 << (buf[8] & 7);
  74463. if ((buf[8] & 0x80) != 0)
  74464. if (! readPalette (numColours))
  74465. break;
  74466. image = Image::createNativeImage ((transparent >= 0) ? Image::ARGB : Image::RGB,
  74467. imageWidth, imageHeight, (transparent >= 0));
  74468. readImage (imageWidth, imageHeight,
  74469. (buf[8] & 0x40) != 0,
  74470. transparent);
  74471. break;
  74472. }
  74473. }
  74474. GIFLoader::~GIFLoader()
  74475. {
  74476. }
  74477. bool GIFLoader::getSizeFromHeader (int& w, int& h)
  74478. {
  74479. unsigned char b [8];
  74480. if (input.read (b, 6) == 6)
  74481. {
  74482. if ((strncmp ("GIF87a", (char*) b, 6) == 0)
  74483. || (strncmp ("GIF89a", (char*) b, 6) == 0))
  74484. {
  74485. if (input.read (b, 4) == 4)
  74486. {
  74487. w = makeWord (b[0], b[1]);
  74488. h = makeWord (b[2], b[3]);
  74489. return true;
  74490. }
  74491. }
  74492. }
  74493. return false;
  74494. }
  74495. bool GIFLoader::readPalette (const int numCols)
  74496. {
  74497. unsigned char rgb[4];
  74498. for (int i = 0; i < numCols; ++i)
  74499. {
  74500. input.read (rgb, 3);
  74501. palette [i][0] = rgb[0];
  74502. palette [i][1] = rgb[1];
  74503. palette [i][2] = rgb[2];
  74504. palette [i][3] = 0xff;
  74505. }
  74506. return true;
  74507. }
  74508. int GIFLoader::readDataBlock (unsigned char* const dest)
  74509. {
  74510. unsigned char n;
  74511. if (input.read (&n, 1) == 1)
  74512. {
  74513. dataBlockIsZero = (n == 0);
  74514. if (dataBlockIsZero || (input.read (dest, n) == n))
  74515. return n;
  74516. }
  74517. return -1;
  74518. }
  74519. int GIFLoader::processExtension (const int type, int& transparent)
  74520. {
  74521. unsigned char b [300];
  74522. int n = 0;
  74523. if (type == 0xf9)
  74524. {
  74525. n = readDataBlock (b);
  74526. if (n < 0)
  74527. return 1;
  74528. if ((b[0] & 0x1) != 0)
  74529. transparent = b[3];
  74530. }
  74531. do
  74532. {
  74533. n = readDataBlock (b);
  74534. }
  74535. while (n > 0);
  74536. return n;
  74537. }
  74538. int GIFLoader::getCode (const int codeSize_, const bool initialise)
  74539. {
  74540. if (initialise)
  74541. {
  74542. currentBit = 0;
  74543. lastBit = 0;
  74544. finished = false;
  74545. return 0;
  74546. }
  74547. if ((currentBit + codeSize_) >= lastBit)
  74548. {
  74549. if (finished)
  74550. return -1;
  74551. buffer[0] = buffer [lastByteIndex - 2];
  74552. buffer[1] = buffer [lastByteIndex - 1];
  74553. const int n = readDataBlock (&buffer[2]);
  74554. if (n == 0)
  74555. finished = true;
  74556. lastByteIndex = 2 + n;
  74557. currentBit = (currentBit - lastBit) + 16;
  74558. lastBit = (2 + n) * 8 ;
  74559. }
  74560. int result = 0;
  74561. int i = currentBit;
  74562. for (int j = 0; j < codeSize_; ++j)
  74563. {
  74564. result |= ((buffer[i >> 3] & (1 << (i & 7))) != 0) << j;
  74565. ++i;
  74566. }
  74567. currentBit += codeSize_;
  74568. return result;
  74569. }
  74570. int GIFLoader::readLZWByte (const bool initialise, const int inputCodeSize)
  74571. {
  74572. int code, incode, i;
  74573. if (initialise)
  74574. {
  74575. setCodeSize = inputCodeSize;
  74576. codeSize = setCodeSize + 1;
  74577. clearCode = 1 << setCodeSize;
  74578. end_code = clearCode + 1;
  74579. maxCodeSize = 2 * clearCode;
  74580. maxCode = clearCode + 2;
  74581. getCode (0, true);
  74582. fresh = true;
  74583. for (i = 0; i < clearCode; ++i)
  74584. {
  74585. table[0][i] = 0;
  74586. table[1][i] = i;
  74587. }
  74588. for (; i < maxGifCode; ++i)
  74589. {
  74590. table[0][i] = 0;
  74591. table[1][i] = 0;
  74592. }
  74593. sp = stack;
  74594. return 0;
  74595. }
  74596. else if (fresh)
  74597. {
  74598. fresh = false;
  74599. do
  74600. {
  74601. firstcode = oldcode
  74602. = getCode (codeSize, false);
  74603. }
  74604. while (firstcode == clearCode);
  74605. return firstcode;
  74606. }
  74607. if (sp > stack)
  74608. return *--sp;
  74609. while ((code = getCode (codeSize, false)) >= 0)
  74610. {
  74611. if (code == clearCode)
  74612. {
  74613. for (i = 0; i < clearCode; ++i)
  74614. {
  74615. table[0][i] = 0;
  74616. table[1][i] = i;
  74617. }
  74618. for (; i < maxGifCode; ++i)
  74619. {
  74620. table[0][i] = 0;
  74621. table[1][i] = 0;
  74622. }
  74623. codeSize = setCodeSize + 1;
  74624. maxCodeSize = 2 * clearCode;
  74625. maxCode = clearCode + 2;
  74626. sp = stack;
  74627. firstcode = oldcode = getCode (codeSize, false);
  74628. return firstcode;
  74629. }
  74630. else if (code == end_code)
  74631. {
  74632. if (dataBlockIsZero)
  74633. return -2;
  74634. unsigned char buf [260];
  74635. int n;
  74636. while ((n = readDataBlock (buf)) > 0)
  74637. {}
  74638. if (n != 0)
  74639. return -2;
  74640. }
  74641. incode = code;
  74642. if (code >= maxCode)
  74643. {
  74644. *sp++ = firstcode;
  74645. code = oldcode;
  74646. }
  74647. while (code >= clearCode)
  74648. {
  74649. *sp++ = table[1][code];
  74650. if (code == table[0][code])
  74651. return -2;
  74652. code = table[0][code];
  74653. }
  74654. *sp++ = firstcode = table[1][code];
  74655. if ((code = maxCode) < maxGifCode)
  74656. {
  74657. table[0][code] = oldcode;
  74658. table[1][code] = firstcode;
  74659. ++maxCode;
  74660. if ((maxCode >= maxCodeSize)
  74661. && (maxCodeSize < maxGifCode))
  74662. {
  74663. maxCodeSize <<= 1;
  74664. ++codeSize;
  74665. }
  74666. }
  74667. oldcode = incode;
  74668. if (sp > stack)
  74669. return *--sp;
  74670. }
  74671. return code;
  74672. }
  74673. bool GIFLoader::readImage (const int width, const int height,
  74674. const int interlace, const int transparent)
  74675. {
  74676. unsigned char c;
  74677. if (input.read (&c, 1) != 1
  74678. || readLZWByte (true, c) < 0)
  74679. return false;
  74680. if (transparent >= 0)
  74681. {
  74682. palette [transparent][0] = 0;
  74683. palette [transparent][1] = 0;
  74684. palette [transparent][2] = 0;
  74685. palette [transparent][3] = 0;
  74686. }
  74687. int index;
  74688. int xpos = 0, ypos = 0, pass = 0;
  74689. const Image::BitmapData destData (*image, 0, 0, width, height, true);
  74690. uint8* p = destData.data;
  74691. const bool hasAlpha = image->hasAlphaChannel();
  74692. while ((index = readLZWByte (false, c)) >= 0)
  74693. {
  74694. const uint8* const paletteEntry = palette [index];
  74695. if (hasAlpha)
  74696. {
  74697. ((PixelARGB*) p)->setARGB (paletteEntry[3],
  74698. paletteEntry[0],
  74699. paletteEntry[1],
  74700. paletteEntry[2]);
  74701. ((PixelARGB*) p)->premultiply();
  74702. }
  74703. else
  74704. {
  74705. ((PixelRGB*) p)->setARGB (0,
  74706. paletteEntry[0],
  74707. paletteEntry[1],
  74708. paletteEntry[2]);
  74709. }
  74710. p += destData.pixelStride;
  74711. ++xpos;
  74712. if (xpos == width)
  74713. {
  74714. xpos = 0;
  74715. if (interlace)
  74716. {
  74717. switch (pass)
  74718. {
  74719. case 0:
  74720. case 1:
  74721. ypos += 8;
  74722. break;
  74723. case 2:
  74724. ypos += 4;
  74725. break;
  74726. case 3:
  74727. ypos += 2;
  74728. break;
  74729. }
  74730. while (ypos >= height)
  74731. {
  74732. ++pass;
  74733. switch (pass)
  74734. {
  74735. case 1:
  74736. ypos = 4;
  74737. break;
  74738. case 2:
  74739. ypos = 2;
  74740. break;
  74741. case 3:
  74742. ypos = 1;
  74743. break;
  74744. default:
  74745. return true;
  74746. }
  74747. }
  74748. }
  74749. else
  74750. {
  74751. ++ypos;
  74752. }
  74753. p = destData.getPixelPointer (xpos, ypos);
  74754. }
  74755. if (ypos >= height)
  74756. break;
  74757. }
  74758. return true;
  74759. }
  74760. END_JUCE_NAMESPACE
  74761. /*** End of inlined file: juce_GIFLoader.cpp ***/
  74762. #endif
  74763. //==============================================================================
  74764. // some files include lots of library code, so leave them to the end to avoid cluttering
  74765. // up the build for the clean files.
  74766. #if JUCE_BUILD_CORE
  74767. /*** Start of inlined file: juce_GZIPCompressorOutputStream.cpp ***/
  74768. namespace zlibNamespace
  74769. {
  74770. #if JUCE_INCLUDE_ZLIB_CODE
  74771. #undef OS_CODE
  74772. #undef fdopen
  74773. /*** Start of inlined file: zlib.h ***/
  74774. #ifndef ZLIB_H
  74775. #define ZLIB_H
  74776. /*** Start of inlined file: zconf.h ***/
  74777. #ifndef ZCONF_H
  74778. #define ZCONF_H
  74779. // *** Just a few hacks here to make it compile nicely with Juce..
  74780. #define Z_PREFIX 1
  74781. #undef __MACTYPES__
  74782. #ifdef _MSC_VER
  74783. #pragma warning (disable : 4131 4127 4244 4267)
  74784. #endif
  74785. #ifdef Z_PREFIX
  74786. # define deflateInit_ z_deflateInit_
  74787. # define deflate z_deflate
  74788. # define deflateEnd z_deflateEnd
  74789. # define inflateInit_ z_inflateInit_
  74790. # define inflate z_inflate
  74791. # define inflateEnd z_inflateEnd
  74792. # define deflateInit2_ z_deflateInit2_
  74793. # define deflateSetDictionary z_deflateSetDictionary
  74794. # define deflateCopy z_deflateCopy
  74795. # define deflateReset z_deflateReset
  74796. # define deflateParams z_deflateParams
  74797. # define deflateBound z_deflateBound
  74798. # define deflatePrime z_deflatePrime
  74799. # define inflateInit2_ z_inflateInit2_
  74800. # define inflateSetDictionary z_inflateSetDictionary
  74801. # define inflateSync z_inflateSync
  74802. # define inflateSyncPoint z_inflateSyncPoint
  74803. # define inflateCopy z_inflateCopy
  74804. # define inflateReset z_inflateReset
  74805. # define inflateBack z_inflateBack
  74806. # define inflateBackEnd z_inflateBackEnd
  74807. # define compress z_compress
  74808. # define compress2 z_compress2
  74809. # define compressBound z_compressBound
  74810. # define uncompress z_uncompress
  74811. # define adler32 z_adler32
  74812. # define crc32 z_crc32
  74813. # define get_crc_table z_get_crc_table
  74814. # define zError z_zError
  74815. # define alloc_func z_alloc_func
  74816. # define free_func z_free_func
  74817. # define in_func z_in_func
  74818. # define out_func z_out_func
  74819. # define Byte z_Byte
  74820. # define uInt z_uInt
  74821. # define uLong z_uLong
  74822. # define Bytef z_Bytef
  74823. # define charf z_charf
  74824. # define intf z_intf
  74825. # define uIntf z_uIntf
  74826. # define uLongf z_uLongf
  74827. # define voidpf z_voidpf
  74828. # define voidp z_voidp
  74829. #endif
  74830. #if defined(__MSDOS__) && !defined(MSDOS)
  74831. # define MSDOS
  74832. #endif
  74833. #if (defined(OS_2) || defined(__OS2__)) && !defined(OS2)
  74834. # define OS2
  74835. #endif
  74836. #if defined(_WINDOWS) && !defined(WINDOWS)
  74837. # define WINDOWS
  74838. #endif
  74839. #if defined(_WIN32) || defined(_WIN32_WCE) || defined(__WIN32__)
  74840. # ifndef WIN32
  74841. # define WIN32
  74842. # endif
  74843. #endif
  74844. #if (defined(MSDOS) || defined(OS2) || defined(WINDOWS)) && !defined(WIN32)
  74845. # if !defined(__GNUC__) && !defined(__FLAT__) && !defined(__386__)
  74846. # ifndef SYS16BIT
  74847. # define SYS16BIT
  74848. # endif
  74849. # endif
  74850. #endif
  74851. #ifdef SYS16BIT
  74852. # define MAXSEG_64K
  74853. #endif
  74854. #ifdef MSDOS
  74855. # define UNALIGNED_OK
  74856. #endif
  74857. #ifdef __STDC_VERSION__
  74858. # ifndef STDC
  74859. # define STDC
  74860. # endif
  74861. # if __STDC_VERSION__ >= 199901L
  74862. # ifndef STDC99
  74863. # define STDC99
  74864. # endif
  74865. # endif
  74866. #endif
  74867. #if !defined(STDC) && (defined(__STDC__) || defined(__cplusplus))
  74868. # define STDC
  74869. #endif
  74870. #if !defined(STDC) && (defined(__GNUC__) || defined(__BORLANDC__))
  74871. # define STDC
  74872. #endif
  74873. #if !defined(STDC) && (defined(MSDOS) || defined(WINDOWS) || defined(WIN32))
  74874. # define STDC
  74875. #endif
  74876. #if !defined(STDC) && (defined(OS2) || defined(__HOS_AIX__))
  74877. # define STDC
  74878. #endif
  74879. #if defined(__OS400__) && !defined(STDC) /* iSeries (formerly AS/400). */
  74880. # define STDC
  74881. #endif
  74882. #ifndef STDC
  74883. # ifndef const /* cannot use !defined(STDC) && !defined(const) on Mac */
  74884. # define const /* note: need a more gentle solution here */
  74885. # endif
  74886. #endif
  74887. #if defined(__MWERKS__)||defined(applec)||defined(THINK_C)||defined(__SC__)
  74888. # define NO_DUMMY_DECL
  74889. #endif
  74890. #ifndef MAX_MEM_LEVEL
  74891. # ifdef MAXSEG_64K
  74892. # define MAX_MEM_LEVEL 8
  74893. # else
  74894. # define MAX_MEM_LEVEL 9
  74895. # endif
  74896. #endif
  74897. #ifndef MAX_WBITS
  74898. # define MAX_WBITS 15 /* 32K LZ77 window */
  74899. #endif
  74900. #ifndef OF /* function prototypes */
  74901. # ifdef STDC
  74902. # define OF(args) args
  74903. # else
  74904. # define OF(args) ()
  74905. # endif
  74906. #endif
  74907. #ifdef SYS16BIT
  74908. # if defined(M_I86SM) || defined(M_I86MM)
  74909. # define SMALL_MEDIUM
  74910. # ifdef _MSC_VER
  74911. # define FAR _far
  74912. # else
  74913. # define FAR far
  74914. # endif
  74915. # endif
  74916. # if (defined(__SMALL__) || defined(__MEDIUM__))
  74917. # define SMALL_MEDIUM
  74918. # ifdef __BORLANDC__
  74919. # define FAR _far
  74920. # else
  74921. # define FAR far
  74922. # endif
  74923. # endif
  74924. #endif
  74925. #if defined(WINDOWS) || defined(WIN32)
  74926. # ifdef ZLIB_DLL
  74927. # if defined(WIN32) && (!defined(__BORLANDC__) || (__BORLANDC__ >= 0x500))
  74928. # ifdef ZLIB_INTERNAL
  74929. # define ZEXTERN extern __declspec(dllexport)
  74930. # else
  74931. # define ZEXTERN extern __declspec(dllimport)
  74932. # endif
  74933. # endif
  74934. # endif /* ZLIB_DLL */
  74935. # ifdef ZLIB_WINAPI
  74936. # ifdef FAR
  74937. # undef FAR
  74938. # endif
  74939. # include <windows.h>
  74940. # define ZEXPORT WINAPI
  74941. # ifdef WIN32
  74942. # define ZEXPORTVA WINAPIV
  74943. # else
  74944. # define ZEXPORTVA FAR CDECL
  74945. # endif
  74946. # endif
  74947. #endif
  74948. #if defined (__BEOS__)
  74949. # ifdef ZLIB_DLL
  74950. # ifdef ZLIB_INTERNAL
  74951. # define ZEXPORT __declspec(dllexport)
  74952. # define ZEXPORTVA __declspec(dllexport)
  74953. # else
  74954. # define ZEXPORT __declspec(dllimport)
  74955. # define ZEXPORTVA __declspec(dllimport)
  74956. # endif
  74957. # endif
  74958. #endif
  74959. #ifndef ZEXTERN
  74960. # define ZEXTERN extern
  74961. #endif
  74962. #ifndef ZEXPORT
  74963. # define ZEXPORT
  74964. #endif
  74965. #ifndef ZEXPORTVA
  74966. # define ZEXPORTVA
  74967. #endif
  74968. #ifndef FAR
  74969. # define FAR
  74970. #endif
  74971. #if !defined(__MACTYPES__)
  74972. typedef unsigned char Byte; /* 8 bits */
  74973. #endif
  74974. typedef unsigned int uInt; /* 16 bits or more */
  74975. typedef unsigned long uLong; /* 32 bits or more */
  74976. #ifdef SMALL_MEDIUM
  74977. # define Bytef Byte FAR
  74978. #else
  74979. typedef Byte FAR Bytef;
  74980. #endif
  74981. typedef char FAR charf;
  74982. typedef int FAR intf;
  74983. typedef uInt FAR uIntf;
  74984. typedef uLong FAR uLongf;
  74985. #ifdef STDC
  74986. typedef void const *voidpc;
  74987. typedef void FAR *voidpf;
  74988. typedef void *voidp;
  74989. #else
  74990. typedef Byte const *voidpc;
  74991. typedef Byte FAR *voidpf;
  74992. typedef Byte *voidp;
  74993. #endif
  74994. #if 0 /* HAVE_UNISTD_H -- this line is updated by ./configure */
  74995. # include <sys/types.h> /* for off_t */
  74996. # include <unistd.h> /* for SEEK_* and off_t */
  74997. # ifdef VMS
  74998. # include <unixio.h> /* for off_t */
  74999. # endif
  75000. # define z_off_t off_t
  75001. #endif
  75002. #ifndef SEEK_SET
  75003. # define SEEK_SET 0 /* Seek from beginning of file. */
  75004. # define SEEK_CUR 1 /* Seek from current position. */
  75005. # define SEEK_END 2 /* Set file pointer to EOF plus "offset" */
  75006. #endif
  75007. #ifndef z_off_t
  75008. # define z_off_t long
  75009. #endif
  75010. #if defined(__OS400__)
  75011. # define NO_vsnprintf
  75012. #endif
  75013. #if defined(__MVS__)
  75014. # define NO_vsnprintf
  75015. # ifdef FAR
  75016. # undef FAR
  75017. # endif
  75018. #endif
  75019. #if defined(__MVS__)
  75020. # pragma map(deflateInit_,"DEIN")
  75021. # pragma map(deflateInit2_,"DEIN2")
  75022. # pragma map(deflateEnd,"DEEND")
  75023. # pragma map(deflateBound,"DEBND")
  75024. # pragma map(inflateInit_,"ININ")
  75025. # pragma map(inflateInit2_,"ININ2")
  75026. # pragma map(inflateEnd,"INEND")
  75027. # pragma map(inflateSync,"INSY")
  75028. # pragma map(inflateSetDictionary,"INSEDI")
  75029. # pragma map(compressBound,"CMBND")
  75030. # pragma map(inflate_table,"INTABL")
  75031. # pragma map(inflate_fast,"INFA")
  75032. # pragma map(inflate_copyright,"INCOPY")
  75033. #endif
  75034. #endif /* ZCONF_H */
  75035. /*** End of inlined file: zconf.h ***/
  75036. #ifdef __cplusplus
  75037. extern "C" {
  75038. #endif
  75039. #define ZLIB_VERSION "1.2.3"
  75040. #define ZLIB_VERNUM 0x1230
  75041. typedef voidpf (*alloc_func) OF((voidpf opaque, uInt items, uInt size));
  75042. typedef void (*free_func) OF((voidpf opaque, voidpf address));
  75043. struct internal_state;
  75044. typedef struct z_stream_s {
  75045. Bytef *next_in; /* next input byte */
  75046. uInt avail_in; /* number of bytes available at next_in */
  75047. uLong total_in; /* total nb of input bytes read so far */
  75048. Bytef *next_out; /* next output byte should be put there */
  75049. uInt avail_out; /* remaining free space at next_out */
  75050. uLong total_out; /* total nb of bytes output so far */
  75051. char *msg; /* last error message, NULL if no error */
  75052. struct internal_state FAR *state; /* not visible by applications */
  75053. alloc_func zalloc; /* used to allocate the internal state */
  75054. free_func zfree; /* used to free the internal state */
  75055. voidpf opaque; /* private data object passed to zalloc and zfree */
  75056. int data_type; /* best guess about the data type: binary or text */
  75057. uLong adler; /* adler32 value of the uncompressed data */
  75058. uLong reserved; /* reserved for future use */
  75059. } z_stream;
  75060. typedef z_stream FAR *z_streamp;
  75061. typedef struct gz_header_s {
  75062. int text; /* true if compressed data believed to be text */
  75063. uLong time; /* modification time */
  75064. int xflags; /* extra flags (not used when writing a gzip file) */
  75065. int os; /* operating system */
  75066. Bytef *extra; /* pointer to extra field or Z_NULL if none */
  75067. uInt extra_len; /* extra field length (valid if extra != Z_NULL) */
  75068. uInt extra_max; /* space at extra (only when reading header) */
  75069. Bytef *name; /* pointer to zero-terminated file name or Z_NULL */
  75070. uInt name_max; /* space at name (only when reading header) */
  75071. Bytef *comment; /* pointer to zero-terminated comment or Z_NULL */
  75072. uInt comm_max; /* space at comment (only when reading header) */
  75073. int hcrc; /* true if there was or will be a header crc */
  75074. int done; /* true when done reading gzip header (not used
  75075. when writing a gzip file) */
  75076. } gz_header;
  75077. typedef gz_header FAR *gz_headerp;
  75078. #define Z_NO_FLUSH 0
  75079. #define Z_PARTIAL_FLUSH 1 /* will be removed, use Z_SYNC_FLUSH instead */
  75080. #define Z_SYNC_FLUSH 2
  75081. #define Z_FULL_FLUSH 3
  75082. #define Z_FINISH 4
  75083. #define Z_BLOCK 5
  75084. #define Z_OK 0
  75085. #define Z_STREAM_END 1
  75086. #define Z_NEED_DICT 2
  75087. #define Z_ERRNO (-1)
  75088. #define Z_STREAM_ERROR (-2)
  75089. #define Z_DATA_ERROR (-3)
  75090. #define Z_MEM_ERROR (-4)
  75091. #define Z_BUF_ERROR (-5)
  75092. #define Z_VERSION_ERROR (-6)
  75093. #define Z_NO_COMPRESSION 0
  75094. #define Z_BEST_SPEED 1
  75095. #define Z_BEST_COMPRESSION 9
  75096. #define Z_DEFAULT_COMPRESSION (-1)
  75097. #define Z_FILTERED 1
  75098. #define Z_HUFFMAN_ONLY 2
  75099. #define Z_RLE 3
  75100. #define Z_FIXED 4
  75101. #define Z_DEFAULT_STRATEGY 0
  75102. #define Z_BINARY 0
  75103. #define Z_TEXT 1
  75104. #define Z_ASCII Z_TEXT /* for compatibility with 1.2.2 and earlier */
  75105. #define Z_UNKNOWN 2
  75106. #define Z_DEFLATED 8
  75107. #define Z_NULL 0 /* for initializing zalloc, zfree, opaque */
  75108. #define zlib_version zlibVersion()
  75109. //ZEXTERN const char * ZEXPORT zlibVersion OF((void));
  75110. ZEXTERN int ZEXPORT deflate OF((z_streamp strm, int flush));
  75111. ZEXTERN int ZEXPORT deflateEnd OF((z_streamp strm));
  75112. ZEXTERN int ZEXPORT inflate OF((z_streamp strm, int flush));
  75113. ZEXTERN int ZEXPORT inflateEnd OF((z_streamp strm));
  75114. ZEXTERN int ZEXPORT deflateSetDictionary OF((z_streamp strm,
  75115. const Bytef *dictionary,
  75116. uInt dictLength));
  75117. ZEXTERN int ZEXPORT deflateCopy OF((z_streamp dest,
  75118. z_streamp source));
  75119. ZEXTERN int ZEXPORT deflateReset OF((z_streamp strm));
  75120. ZEXTERN int ZEXPORT deflateParams OF((z_streamp strm,
  75121. int level,
  75122. int strategy));
  75123. ZEXTERN int ZEXPORT deflateTune OF((z_streamp strm,
  75124. int good_length,
  75125. int max_lazy,
  75126. int nice_length,
  75127. int max_chain));
  75128. ZEXTERN uLong ZEXPORT deflateBound OF((z_streamp strm,
  75129. uLong sourceLen));
  75130. ZEXTERN int ZEXPORT deflatePrime OF((z_streamp strm,
  75131. int bits,
  75132. int value));
  75133. ZEXTERN int ZEXPORT deflateSetHeader OF((z_streamp strm,
  75134. gz_headerp head));
  75135. ZEXTERN int ZEXPORT inflateSetDictionary OF((z_streamp strm,
  75136. const Bytef *dictionary,
  75137. uInt dictLength));
  75138. ZEXTERN int ZEXPORT inflateSync OF((z_streamp strm));
  75139. ZEXTERN int ZEXPORT inflateCopy OF((z_streamp dest,
  75140. z_streamp source));
  75141. ZEXTERN int ZEXPORT inflateReset OF((z_streamp strm));
  75142. ZEXTERN int ZEXPORT inflatePrime OF((z_streamp strm,
  75143. int bits,
  75144. int value));
  75145. ZEXTERN int ZEXPORT inflateGetHeader OF((z_streamp strm,
  75146. gz_headerp head));
  75147. typedef unsigned (*in_func) OF((void FAR *, unsigned char FAR * FAR *));
  75148. typedef int (*out_func) OF((void FAR *, unsigned char FAR *, unsigned));
  75149. ZEXTERN int ZEXPORT inflateBack OF((z_streamp strm,
  75150. in_func in, void FAR *in_desc,
  75151. out_func out, void FAR *out_desc));
  75152. ZEXTERN int ZEXPORT inflateBackEnd OF((z_streamp strm));
  75153. //ZEXTERN uLong ZEXPORT zlibCompileFlags OF((void));
  75154. ZEXTERN int ZEXPORT compress OF((Bytef *dest, uLongf *destLen,
  75155. const Bytef *source, uLong sourceLen));
  75156. ZEXTERN int ZEXPORT compress2 OF((Bytef *dest, uLongf *destLen,
  75157. const Bytef *source, uLong sourceLen,
  75158. int level));
  75159. ZEXTERN uLong ZEXPORT compressBound OF((uLong sourceLen));
  75160. ZEXTERN int ZEXPORT uncompress OF((Bytef *dest, uLongf *destLen,
  75161. const Bytef *source, uLong sourceLen));
  75162. typedef voidp gzFile;
  75163. ZEXTERN gzFile ZEXPORT gzopen OF((const char *path, const char *mode));
  75164. ZEXTERN gzFile ZEXPORT gzdopen OF((int fd, const char *mode));
  75165. ZEXTERN int ZEXPORT gzsetparams OF((gzFile file, int level, int strategy));
  75166. ZEXTERN int ZEXPORT gzread OF((gzFile file, voidp buf, unsigned len));
  75167. ZEXTERN int ZEXPORT gzwrite OF((gzFile file,
  75168. voidpc buf, unsigned len));
  75169. ZEXTERN int ZEXPORTVA gzprintf OF((gzFile file, const char *format, ...));
  75170. ZEXTERN int ZEXPORT gzputs OF((gzFile file, const char *s));
  75171. ZEXTERN char * ZEXPORT gzgets OF((gzFile file, char *buf, int len));
  75172. ZEXTERN int ZEXPORT gzputc OF((gzFile file, int c));
  75173. ZEXTERN int ZEXPORT gzgetc OF((gzFile file));
  75174. ZEXTERN int ZEXPORT gzungetc OF((int c, gzFile file));
  75175. ZEXTERN int ZEXPORT gzflush OF((gzFile file, int flush));
  75176. ZEXTERN z_off_t ZEXPORT gzseek OF((gzFile file,
  75177. z_off_t offset, int whence));
  75178. ZEXTERN int ZEXPORT gzrewind OF((gzFile file));
  75179. ZEXTERN z_off_t ZEXPORT gztell OF((gzFile file));
  75180. ZEXTERN int ZEXPORT gzeof OF((gzFile file));
  75181. ZEXTERN int ZEXPORT gzdirect OF((gzFile file));
  75182. ZEXTERN int ZEXPORT gzclose OF((gzFile file));
  75183. ZEXTERN const char * ZEXPORT gzerror OF((gzFile file, int *errnum));
  75184. ZEXTERN void ZEXPORT gzclearerr OF((gzFile file));
  75185. ZEXTERN uLong ZEXPORT adler32 OF((uLong adler, const Bytef *buf, uInt len));
  75186. ZEXTERN uLong ZEXPORT adler32_combine OF((uLong adler1, uLong adler2,
  75187. z_off_t len2));
  75188. ZEXTERN uLong ZEXPORT crc32 OF((uLong crc, const Bytef *buf, uInt len));
  75189. ZEXTERN uLong ZEXPORT crc32_combine OF((uLong crc1, uLong crc2, z_off_t len2));
  75190. ZEXTERN int ZEXPORT deflateInit_ OF((z_streamp strm, int level,
  75191. const char *version, int stream_size));
  75192. ZEXTERN int ZEXPORT inflateInit_ OF((z_streamp strm,
  75193. const char *version, int stream_size));
  75194. ZEXTERN int ZEXPORT deflateInit2_ OF((z_streamp strm, int level, int method,
  75195. int windowBits, int memLevel,
  75196. int strategy, const char *version,
  75197. int stream_size));
  75198. ZEXTERN int ZEXPORT inflateInit2_ OF((z_streamp strm, int windowBits,
  75199. const char *version, int stream_size));
  75200. ZEXTERN int ZEXPORT inflateBackInit_ OF((z_streamp strm, int windowBits,
  75201. unsigned char FAR *window,
  75202. const char *version,
  75203. int stream_size));
  75204. #define deflateInit(strm, level) \
  75205. deflateInit_((strm), (level), ZLIB_VERSION, sizeof(z_stream))
  75206. #define inflateInit(strm) \
  75207. inflateInit_((strm), ZLIB_VERSION, sizeof(z_stream))
  75208. #define deflateInit2(strm, level, method, windowBits, memLevel, strategy) \
  75209. deflateInit2_((strm),(level),(method),(windowBits),(memLevel),\
  75210. (strategy), ZLIB_VERSION, sizeof(z_stream))
  75211. #define inflateInit2(strm, windowBits) \
  75212. inflateInit2_((strm), (windowBits), ZLIB_VERSION, sizeof(z_stream))
  75213. #define inflateBackInit(strm, windowBits, window) \
  75214. inflateBackInit_((strm), (windowBits), (window), \
  75215. ZLIB_VERSION, sizeof(z_stream))
  75216. #if !defined(ZUTIL_H) && !defined(NO_DUMMY_DECL)
  75217. struct internal_state {int dummy;}; /* hack for buggy compilers */
  75218. #endif
  75219. ZEXTERN const char * ZEXPORT zError OF((int));
  75220. ZEXTERN int ZEXPORT inflateSyncPoint OF((z_streamp z));
  75221. ZEXTERN const uLongf * ZEXPORT get_crc_table OF((void));
  75222. #ifdef __cplusplus
  75223. }
  75224. #endif
  75225. #endif /* ZLIB_H */
  75226. /*** End of inlined file: zlib.h ***/
  75227. #undef OS_CODE
  75228. #else
  75229. #include <zlib.h>
  75230. #endif
  75231. }
  75232. BEGIN_JUCE_NAMESPACE
  75233. // internal helper object that holds the zlib structures so they don't have to be
  75234. // included publicly.
  75235. class GZIPCompressorHelper
  75236. {
  75237. public:
  75238. GZIPCompressorHelper (const int compressionLevel, const bool nowrap)
  75239. : data (0),
  75240. dataSize (0),
  75241. compLevel (compressionLevel),
  75242. strategy (0),
  75243. setParams (true),
  75244. streamIsValid (false),
  75245. finished (false),
  75246. shouldFinish (false)
  75247. {
  75248. using namespace zlibNamespace;
  75249. zerostruct (stream);
  75250. streamIsValid = (deflateInit2 (&stream, compLevel, Z_DEFLATED,
  75251. nowrap ? -MAX_WBITS : MAX_WBITS,
  75252. 8, strategy) == Z_OK);
  75253. }
  75254. ~GZIPCompressorHelper()
  75255. {
  75256. using namespace zlibNamespace;
  75257. if (streamIsValid)
  75258. deflateEnd (&stream);
  75259. }
  75260. bool needsInput() const throw()
  75261. {
  75262. return dataSize <= 0;
  75263. }
  75264. void setInput (uint8* const newData, const int size) throw()
  75265. {
  75266. data = newData;
  75267. dataSize = size;
  75268. }
  75269. int doNextBlock (uint8* const dest, const int destSize) throw()
  75270. {
  75271. using namespace zlibNamespace;
  75272. if (streamIsValid)
  75273. {
  75274. stream.next_in = data;
  75275. stream.next_out = dest;
  75276. stream.avail_in = dataSize;
  75277. stream.avail_out = destSize;
  75278. const int result = setParams ? deflateParams (&stream, compLevel, strategy)
  75279. : deflate (&stream, shouldFinish ? Z_FINISH : Z_NO_FLUSH);
  75280. setParams = false;
  75281. switch (result)
  75282. {
  75283. case Z_STREAM_END:
  75284. finished = true;
  75285. // Deliberate fall-through..
  75286. case Z_OK:
  75287. data += dataSize - stream.avail_in;
  75288. dataSize = stream.avail_in;
  75289. return destSize - stream.avail_out;
  75290. default:
  75291. break;
  75292. }
  75293. }
  75294. return 0;
  75295. }
  75296. private:
  75297. zlibNamespace::z_stream stream;
  75298. uint8* data;
  75299. int dataSize, compLevel, strategy;
  75300. bool setParams, streamIsValid;
  75301. public:
  75302. bool finished, shouldFinish;
  75303. };
  75304. const int gzipCompBufferSize = 32768;
  75305. GZIPCompressorOutputStream::GZIPCompressorOutputStream (OutputStream* const destStream_,
  75306. int compressionLevel,
  75307. const bool deleteDestStream,
  75308. const bool noWrap)
  75309. : destStream (destStream_),
  75310. streamToDelete (deleteDestStream ? destStream_ : 0),
  75311. buffer (gzipCompBufferSize)
  75312. {
  75313. if (compressionLevel < 1 || compressionLevel > 9)
  75314. compressionLevel = -1;
  75315. helper = new GZIPCompressorHelper (compressionLevel, noWrap);
  75316. }
  75317. GZIPCompressorOutputStream::~GZIPCompressorOutputStream()
  75318. {
  75319. flush();
  75320. }
  75321. void GZIPCompressorOutputStream::flush()
  75322. {
  75323. if (! helper->finished)
  75324. {
  75325. helper->shouldFinish = true;
  75326. while (! helper->finished)
  75327. doNextBlock();
  75328. }
  75329. destStream->flush();
  75330. }
  75331. bool GZIPCompressorOutputStream::write (const void* destBuffer, int howMany)
  75332. {
  75333. if (! helper->finished)
  75334. {
  75335. helper->setInput ((uint8*) destBuffer, howMany);
  75336. while (! helper->needsInput())
  75337. {
  75338. if (! doNextBlock())
  75339. return false;
  75340. }
  75341. }
  75342. return true;
  75343. }
  75344. bool GZIPCompressorOutputStream::doNextBlock()
  75345. {
  75346. const int len = helper->doNextBlock (buffer, gzipCompBufferSize);
  75347. if (len > 0)
  75348. return destStream->write (buffer, len);
  75349. else
  75350. return true;
  75351. }
  75352. int64 GZIPCompressorOutputStream::getPosition()
  75353. {
  75354. return destStream->getPosition();
  75355. }
  75356. bool GZIPCompressorOutputStream::setPosition (int64 /*newPosition*/)
  75357. {
  75358. jassertfalse // can't do it!
  75359. return false;
  75360. }
  75361. END_JUCE_NAMESPACE
  75362. /*** End of inlined file: juce_GZIPCompressorOutputStream.cpp ***/
  75363. /*** Start of inlined file: juce_GZIPDecompressorInputStream.cpp ***/
  75364. #if JUCE_MSVC
  75365. #pragma warning (push)
  75366. #pragma warning (disable: 4309 4305)
  75367. #endif
  75368. namespace zlibNamespace
  75369. {
  75370. #if JUCE_INCLUDE_ZLIB_CODE
  75371. extern "C"
  75372. {
  75373. #undef OS_CODE
  75374. #undef fdopen
  75375. #define ZLIB_INTERNAL
  75376. #define NO_DUMMY_DECL
  75377. /*** Start of inlined file: adler32.c ***/
  75378. #define ZLIB_INTERNAL
  75379. #define BASE 65521UL /* largest prime smaller than 65536 */
  75380. #define NMAX 5552
  75381. #define DO1(buf,i) {adler += (buf)[i]; sum2 += adler;}
  75382. #define DO2(buf,i) DO1(buf,i); DO1(buf,i+1);
  75383. #define DO4(buf,i) DO2(buf,i); DO2(buf,i+2);
  75384. #define DO8(buf,i) DO4(buf,i); DO4(buf,i+4);
  75385. #define DO16(buf) DO8(buf,0); DO8(buf,8);
  75386. #ifdef NO_DIVIDE
  75387. # define MOD(a) \
  75388. do { \
  75389. if (a >= (BASE << 16)) a -= (BASE << 16); \
  75390. if (a >= (BASE << 15)) a -= (BASE << 15); \
  75391. if (a >= (BASE << 14)) a -= (BASE << 14); \
  75392. if (a >= (BASE << 13)) a -= (BASE << 13); \
  75393. if (a >= (BASE << 12)) a -= (BASE << 12); \
  75394. if (a >= (BASE << 11)) a -= (BASE << 11); \
  75395. if (a >= (BASE << 10)) a -= (BASE << 10); \
  75396. if (a >= (BASE << 9)) a -= (BASE << 9); \
  75397. if (a >= (BASE << 8)) a -= (BASE << 8); \
  75398. if (a >= (BASE << 7)) a -= (BASE << 7); \
  75399. if (a >= (BASE << 6)) a -= (BASE << 6); \
  75400. if (a >= (BASE << 5)) a -= (BASE << 5); \
  75401. if (a >= (BASE << 4)) a -= (BASE << 4); \
  75402. if (a >= (BASE << 3)) a -= (BASE << 3); \
  75403. if (a >= (BASE << 2)) a -= (BASE << 2); \
  75404. if (a >= (BASE << 1)) a -= (BASE << 1); \
  75405. if (a >= BASE) a -= BASE; \
  75406. } while (0)
  75407. # define MOD4(a) \
  75408. do { \
  75409. if (a >= (BASE << 4)) a -= (BASE << 4); \
  75410. if (a >= (BASE << 3)) a -= (BASE << 3); \
  75411. if (a >= (BASE << 2)) a -= (BASE << 2); \
  75412. if (a >= (BASE << 1)) a -= (BASE << 1); \
  75413. if (a >= BASE) a -= BASE; \
  75414. } while (0)
  75415. #else
  75416. # define MOD(a) a %= BASE
  75417. # define MOD4(a) a %= BASE
  75418. #endif
  75419. uLong ZEXPORT adler32(uLong adler, const Bytef *buf, uInt len)
  75420. {
  75421. unsigned long sum2;
  75422. unsigned n;
  75423. sum2 = (adler >> 16) & 0xffff;
  75424. adler &= 0xffff;
  75425. if (len == 1) {
  75426. adler += buf[0];
  75427. if (adler >= BASE)
  75428. adler -= BASE;
  75429. sum2 += adler;
  75430. if (sum2 >= BASE)
  75431. sum2 -= BASE;
  75432. return adler | (sum2 << 16);
  75433. }
  75434. if (buf == Z_NULL)
  75435. return 1L;
  75436. if (len < 16) {
  75437. while (len--) {
  75438. adler += *buf++;
  75439. sum2 += adler;
  75440. }
  75441. if (adler >= BASE)
  75442. adler -= BASE;
  75443. MOD4(sum2); /* only added so many BASE's */
  75444. return adler | (sum2 << 16);
  75445. }
  75446. while (len >= NMAX) {
  75447. len -= NMAX;
  75448. n = NMAX / 16; /* NMAX is divisible by 16 */
  75449. do {
  75450. DO16(buf); /* 16 sums unrolled */
  75451. buf += 16;
  75452. } while (--n);
  75453. MOD(adler);
  75454. MOD(sum2);
  75455. }
  75456. if (len) { /* avoid modulos if none remaining */
  75457. while (len >= 16) {
  75458. len -= 16;
  75459. DO16(buf);
  75460. buf += 16;
  75461. }
  75462. while (len--) {
  75463. adler += *buf++;
  75464. sum2 += adler;
  75465. }
  75466. MOD(adler);
  75467. MOD(sum2);
  75468. }
  75469. return adler | (sum2 << 16);
  75470. }
  75471. uLong ZEXPORT adler32_combine(uLong adler1, uLong adler2, z_off_t len2)
  75472. {
  75473. unsigned long sum1;
  75474. unsigned long sum2;
  75475. unsigned rem;
  75476. rem = (unsigned)(len2 % BASE);
  75477. sum1 = adler1 & 0xffff;
  75478. sum2 = rem * sum1;
  75479. MOD(sum2);
  75480. sum1 += (adler2 & 0xffff) + BASE - 1;
  75481. sum2 += ((adler1 >> 16) & 0xffff) + ((adler2 >> 16) & 0xffff) + BASE - rem;
  75482. if (sum1 > BASE) sum1 -= BASE;
  75483. if (sum1 > BASE) sum1 -= BASE;
  75484. if (sum2 > (BASE << 1)) sum2 -= (BASE << 1);
  75485. if (sum2 > BASE) sum2 -= BASE;
  75486. return sum1 | (sum2 << 16);
  75487. }
  75488. /*** End of inlined file: adler32.c ***/
  75489. /*** Start of inlined file: compress.c ***/
  75490. #define ZLIB_INTERNAL
  75491. int ZEXPORT compress2 (Bytef *dest, uLongf *destLen, const Bytef *source,
  75492. uLong sourceLen, int level)
  75493. {
  75494. z_stream stream;
  75495. int err;
  75496. stream.next_in = (Bytef*)source;
  75497. stream.avail_in = (uInt)sourceLen;
  75498. #ifdef MAXSEG_64K
  75499. if ((uLong)stream.avail_in != sourceLen) return Z_BUF_ERROR;
  75500. #endif
  75501. stream.next_out = dest;
  75502. stream.avail_out = (uInt)*destLen;
  75503. if ((uLong)stream.avail_out != *destLen) return Z_BUF_ERROR;
  75504. stream.zalloc = (alloc_func)0;
  75505. stream.zfree = (free_func)0;
  75506. stream.opaque = (voidpf)0;
  75507. err = deflateInit(&stream, level);
  75508. if (err != Z_OK) return err;
  75509. err = deflate(&stream, Z_FINISH);
  75510. if (err != Z_STREAM_END) {
  75511. deflateEnd(&stream);
  75512. return err == Z_OK ? Z_BUF_ERROR : err;
  75513. }
  75514. *destLen = stream.total_out;
  75515. err = deflateEnd(&stream);
  75516. return err;
  75517. }
  75518. int ZEXPORT compress (Bytef *dest, uLongf *destLen, const Bytef *source, uLong sourceLen)
  75519. {
  75520. return compress2(dest, destLen, source, sourceLen, Z_DEFAULT_COMPRESSION);
  75521. }
  75522. uLong ZEXPORT compressBound (uLong sourceLen)
  75523. {
  75524. return sourceLen + (sourceLen >> 12) + (sourceLen >> 14) + 11;
  75525. }
  75526. /*** End of inlined file: compress.c ***/
  75527. #undef DO1
  75528. #undef DO8
  75529. /*** Start of inlined file: crc32.c ***/
  75530. #ifdef MAKECRCH
  75531. # include <stdio.h>
  75532. # ifndef DYNAMIC_CRC_TABLE
  75533. # define DYNAMIC_CRC_TABLE
  75534. # endif /* !DYNAMIC_CRC_TABLE */
  75535. #endif /* MAKECRCH */
  75536. /*** Start of inlined file: zutil.h ***/
  75537. #ifndef ZUTIL_H
  75538. #define ZUTIL_H
  75539. #define ZLIB_INTERNAL
  75540. #ifdef STDC
  75541. # ifndef _WIN32_WCE
  75542. # include <stddef.h>
  75543. # endif
  75544. # include <string.h>
  75545. # include <stdlib.h>
  75546. #endif
  75547. #ifdef NO_ERRNO_H
  75548. # ifdef _WIN32_WCE
  75549. # define errno z_errno
  75550. # endif
  75551. extern int errno;
  75552. #else
  75553. # ifndef _WIN32_WCE
  75554. # include <errno.h>
  75555. # endif
  75556. #endif
  75557. #ifndef local
  75558. # define local static
  75559. #endif
  75560. typedef unsigned char uch;
  75561. typedef uch FAR uchf;
  75562. typedef unsigned short ush;
  75563. typedef ush FAR ushf;
  75564. typedef unsigned long ulg;
  75565. extern const char * const z_errmsg[10]; /* indexed by 2-zlib_error */
  75566. #define ERR_MSG(err) z_errmsg[Z_NEED_DICT-(err)]
  75567. #define ERR_RETURN(strm,err) \
  75568. return (strm->msg = (char*)ERR_MSG(err), (err))
  75569. #ifndef DEF_WBITS
  75570. # define DEF_WBITS MAX_WBITS
  75571. #endif
  75572. #if MAX_MEM_LEVEL >= 8
  75573. # define DEF_MEM_LEVEL 8
  75574. #else
  75575. # define DEF_MEM_LEVEL MAX_MEM_LEVEL
  75576. #endif
  75577. #define STORED_BLOCK 0
  75578. #define STATIC_TREES 1
  75579. #define DYN_TREES 2
  75580. #define MIN_MATCH 3
  75581. #define MAX_MATCH 258
  75582. #define PRESET_DICT 0x20 /* preset dictionary flag in zlib header */
  75583. #if defined(MSDOS) || (defined(WINDOWS) && !defined(WIN32))
  75584. # define OS_CODE 0x00
  75585. # if defined(__TURBOC__) || defined(__BORLANDC__)
  75586. # if(__STDC__ == 1) && (defined(__LARGE__) || defined(__COMPACT__))
  75587. void _Cdecl farfree( void *block );
  75588. void *_Cdecl farmalloc( unsigned long nbytes );
  75589. # else
  75590. # include <alloc.h>
  75591. # endif
  75592. # else /* MSC or DJGPP */
  75593. # include <malloc.h>
  75594. # endif
  75595. #endif
  75596. #ifdef AMIGA
  75597. # define OS_CODE 0x01
  75598. #endif
  75599. #if defined(VAXC) || defined(VMS)
  75600. # define OS_CODE 0x02
  75601. # define F_OPEN(name, mode) \
  75602. fopen((name), (mode), "mbc=60", "ctx=stm", "rfm=fix", "mrs=512")
  75603. #endif
  75604. #if defined(ATARI) || defined(atarist)
  75605. # define OS_CODE 0x05
  75606. #endif
  75607. #ifdef OS2
  75608. # define OS_CODE 0x06
  75609. # ifdef M_I86
  75610. #include <malloc.h>
  75611. # endif
  75612. #endif
  75613. #if defined(MACOS) || TARGET_OS_MAC
  75614. # define OS_CODE 0x07
  75615. # if defined(__MWERKS__) && __dest_os != __be_os && __dest_os != __win32_os
  75616. # include <unix.h> /* for fdopen */
  75617. # else
  75618. # ifndef fdopen
  75619. # define fdopen(fd,mode) NULL /* No fdopen() */
  75620. # endif
  75621. # endif
  75622. #endif
  75623. #ifdef TOPS20
  75624. # define OS_CODE 0x0a
  75625. #endif
  75626. #ifdef WIN32
  75627. # ifndef __CYGWIN__ /* Cygwin is Unix, not Win32 */
  75628. # define OS_CODE 0x0b
  75629. # endif
  75630. #endif
  75631. #ifdef __50SERIES /* Prime/PRIMOS */
  75632. # define OS_CODE 0x0f
  75633. #endif
  75634. #if defined(_BEOS_) || defined(RISCOS)
  75635. # define fdopen(fd,mode) NULL /* No fdopen() */
  75636. #endif
  75637. #if (defined(_MSC_VER) && (_MSC_VER > 600))
  75638. # if defined(_WIN32_WCE)
  75639. # define fdopen(fd,mode) NULL /* No fdopen() */
  75640. # ifndef _PTRDIFF_T_DEFINED
  75641. typedef int ptrdiff_t;
  75642. # define _PTRDIFF_T_DEFINED
  75643. # endif
  75644. # else
  75645. # define fdopen(fd,type) _fdopen(fd,type)
  75646. # endif
  75647. #endif
  75648. #ifndef OS_CODE
  75649. # define OS_CODE 0x03 /* assume Unix */
  75650. #endif
  75651. #ifndef F_OPEN
  75652. # define F_OPEN(name, mode) fopen((name), (mode))
  75653. #endif
  75654. #if defined(STDC99) || (defined(__TURBOC__) && __TURBOC__ >= 0x550)
  75655. # ifndef HAVE_VSNPRINTF
  75656. # define HAVE_VSNPRINTF
  75657. # endif
  75658. #endif
  75659. #if defined(__CYGWIN__)
  75660. # ifndef HAVE_VSNPRINTF
  75661. # define HAVE_VSNPRINTF
  75662. # endif
  75663. #endif
  75664. #ifndef HAVE_VSNPRINTF
  75665. # ifdef MSDOS
  75666. # define NO_vsnprintf
  75667. # endif
  75668. # ifdef __TURBOC__
  75669. # define NO_vsnprintf
  75670. # endif
  75671. # ifdef WIN32
  75672. # if !defined(vsnprintf) && !defined(NO_vsnprintf)
  75673. # define vsnprintf _vsnprintf
  75674. # endif
  75675. # endif
  75676. # ifdef __SASC
  75677. # define NO_vsnprintf
  75678. # endif
  75679. #endif
  75680. #ifdef VMS
  75681. # define NO_vsnprintf
  75682. #endif
  75683. #if defined(pyr)
  75684. # define NO_MEMCPY
  75685. #endif
  75686. #if defined(SMALL_MEDIUM) && !defined(_MSC_VER) && !defined(__SC__)
  75687. # define NO_MEMCPY
  75688. #endif
  75689. #if defined(STDC) && !defined(HAVE_MEMCPY) && !defined(NO_MEMCPY)
  75690. # define HAVE_MEMCPY
  75691. #endif
  75692. #ifdef HAVE_MEMCPY
  75693. # ifdef SMALL_MEDIUM /* MSDOS small or medium model */
  75694. # define zmemcpy _fmemcpy
  75695. # define zmemcmp _fmemcmp
  75696. # define zmemzero(dest, len) _fmemset(dest, 0, len)
  75697. # else
  75698. # define zmemcpy memcpy
  75699. # define zmemcmp memcmp
  75700. # define zmemzero(dest, len) memset(dest, 0, len)
  75701. # endif
  75702. #else
  75703. extern void zmemcpy OF((Bytef* dest, const Bytef* source, uInt len));
  75704. extern int zmemcmp OF((const Bytef* s1, const Bytef* s2, uInt len));
  75705. extern void zmemzero OF((Bytef* dest, uInt len));
  75706. #endif
  75707. #ifdef DEBUG
  75708. # include <stdio.h>
  75709. extern int z_verbose;
  75710. extern void z_error OF((const char *m));
  75711. # define Assert(cond,msg) {if(!(cond)) z_error(msg);}
  75712. # define Trace(x) {if (z_verbose>=0) fprintf x ;}
  75713. # define Tracev(x) {if (z_verbose>0) fprintf x ;}
  75714. # define Tracevv(x) {if (z_verbose>1) fprintf x ;}
  75715. # define Tracec(c,x) {if (z_verbose>0 && (c)) fprintf x ;}
  75716. # define Tracecv(c,x) {if (z_verbose>1 && (c)) fprintf x ;}
  75717. #else
  75718. # define Assert(cond,msg)
  75719. # define Trace(x)
  75720. # define Tracev(x)
  75721. # define Tracevv(x)
  75722. # define Tracec(c,x)
  75723. # define Tracecv(c,x)
  75724. #endif
  75725. voidpf zcalloc OF((voidpf opaque, unsigned items, unsigned size));
  75726. void zcfree OF((voidpf opaque, voidpf ptr));
  75727. #define ZALLOC(strm, items, size) \
  75728. (*((strm)->zalloc))((strm)->opaque, (items), (size))
  75729. #define ZFREE(strm, addr) (*((strm)->zfree))((strm)->opaque, (voidpf)(addr))
  75730. #define TRY_FREE(s, p) {if (p) ZFREE(s, p);}
  75731. #endif /* ZUTIL_H */
  75732. /*** End of inlined file: zutil.h ***/
  75733. /* for STDC and FAR definitions */
  75734. #define local static
  75735. #ifndef NOBYFOUR
  75736. # ifdef STDC /* need ANSI C limits.h to determine sizes */
  75737. # include <limits.h>
  75738. # define BYFOUR
  75739. # if (UINT_MAX == 0xffffffffUL)
  75740. typedef unsigned int u4;
  75741. # else
  75742. # if (ULONG_MAX == 0xffffffffUL)
  75743. typedef unsigned long u4;
  75744. # else
  75745. # if (USHRT_MAX == 0xffffffffUL)
  75746. typedef unsigned short u4;
  75747. # else
  75748. # undef BYFOUR /* can't find a four-byte integer type! */
  75749. # endif
  75750. # endif
  75751. # endif
  75752. # endif /* STDC */
  75753. #endif /* !NOBYFOUR */
  75754. #ifdef BYFOUR
  75755. # define REV(w) (((w)>>24)+(((w)>>8)&0xff00)+ \
  75756. (((w)&0xff00)<<8)+(((w)&0xff)<<24))
  75757. local unsigned long crc32_little OF((unsigned long,
  75758. const unsigned char FAR *, unsigned));
  75759. local unsigned long crc32_big OF((unsigned long,
  75760. const unsigned char FAR *, unsigned));
  75761. # define TBLS 8
  75762. #else
  75763. # define TBLS 1
  75764. #endif /* BYFOUR */
  75765. local unsigned long gf2_matrix_times OF((unsigned long *mat,
  75766. unsigned long vec));
  75767. local void gf2_matrix_square OF((unsigned long *square, unsigned long *mat));
  75768. #ifdef DYNAMIC_CRC_TABLE
  75769. local volatile int crc_table_empty = 1;
  75770. local unsigned long FAR crc_table[TBLS][256];
  75771. local void make_crc_table OF((void));
  75772. #ifdef MAKECRCH
  75773. local void write_table OF((FILE *, const unsigned long FAR *));
  75774. #endif /* MAKECRCH */
  75775. local void make_crc_table()
  75776. {
  75777. unsigned long c;
  75778. int n, k;
  75779. unsigned long poly; /* polynomial exclusive-or pattern */
  75780. static volatile int first = 1; /* flag to limit concurrent making */
  75781. static const unsigned char p[] = {0,1,2,4,5,7,8,10,11,12,16,22,23,26};
  75782. if (first) {
  75783. first = 0;
  75784. poly = 0UL;
  75785. for (n = 0; n < sizeof(p)/sizeof(unsigned char); n++)
  75786. poly |= 1UL << (31 - p[n]);
  75787. for (n = 0; n < 256; n++) {
  75788. c = (unsigned long)n;
  75789. for (k = 0; k < 8; k++)
  75790. c = c & 1 ? poly ^ (c >> 1) : c >> 1;
  75791. crc_table[0][n] = c;
  75792. }
  75793. #ifdef BYFOUR
  75794. for (n = 0; n < 256; n++) {
  75795. c = crc_table[0][n];
  75796. crc_table[4][n] = REV(c);
  75797. for (k = 1; k < 4; k++) {
  75798. c = crc_table[0][c & 0xff] ^ (c >> 8);
  75799. crc_table[k][n] = c;
  75800. crc_table[k + 4][n] = REV(c);
  75801. }
  75802. }
  75803. #endif /* BYFOUR */
  75804. crc_table_empty = 0;
  75805. }
  75806. else { /* not first */
  75807. while (crc_table_empty)
  75808. ;
  75809. }
  75810. #ifdef MAKECRCH
  75811. {
  75812. FILE *out;
  75813. out = fopen("crc32.h", "w");
  75814. if (out == NULL) return;
  75815. fprintf(out, "/* crc32.h -- tables for rapid CRC calculation\n");
  75816. fprintf(out, " * Generated automatically by crc32.c\n */\n\n");
  75817. fprintf(out, "local const unsigned long FAR ");
  75818. fprintf(out, "crc_table[TBLS][256] =\n{\n {\n");
  75819. write_table(out, crc_table[0]);
  75820. # ifdef BYFOUR
  75821. fprintf(out, "#ifdef BYFOUR\n");
  75822. for (k = 1; k < 8; k++) {
  75823. fprintf(out, " },\n {\n");
  75824. write_table(out, crc_table[k]);
  75825. }
  75826. fprintf(out, "#endif\n");
  75827. # endif /* BYFOUR */
  75828. fprintf(out, " }\n};\n");
  75829. fclose(out);
  75830. }
  75831. #endif /* MAKECRCH */
  75832. }
  75833. #ifdef MAKECRCH
  75834. local void write_table(out, table)
  75835. FILE *out;
  75836. const unsigned long FAR *table;
  75837. {
  75838. int n;
  75839. for (n = 0; n < 256; n++)
  75840. fprintf(out, "%s0x%08lxUL%s", n % 5 ? "" : " ", table[n],
  75841. n == 255 ? "\n" : (n % 5 == 4 ? ",\n" : ", "));
  75842. }
  75843. #endif /* MAKECRCH */
  75844. #else /* !DYNAMIC_CRC_TABLE */
  75845. /*** Start of inlined file: crc32.h ***/
  75846. local const unsigned long FAR crc_table[TBLS][256] =
  75847. {
  75848. {
  75849. 0x00000000UL, 0x77073096UL, 0xee0e612cUL, 0x990951baUL, 0x076dc419UL,
  75850. 0x706af48fUL, 0xe963a535UL, 0x9e6495a3UL, 0x0edb8832UL, 0x79dcb8a4UL,
  75851. 0xe0d5e91eUL, 0x97d2d988UL, 0x09b64c2bUL, 0x7eb17cbdUL, 0xe7b82d07UL,
  75852. 0x90bf1d91UL, 0x1db71064UL, 0x6ab020f2UL, 0xf3b97148UL, 0x84be41deUL,
  75853. 0x1adad47dUL, 0x6ddde4ebUL, 0xf4d4b551UL, 0x83d385c7UL, 0x136c9856UL,
  75854. 0x646ba8c0UL, 0xfd62f97aUL, 0x8a65c9ecUL, 0x14015c4fUL, 0x63066cd9UL,
  75855. 0xfa0f3d63UL, 0x8d080df5UL, 0x3b6e20c8UL, 0x4c69105eUL, 0xd56041e4UL,
  75856. 0xa2677172UL, 0x3c03e4d1UL, 0x4b04d447UL, 0xd20d85fdUL, 0xa50ab56bUL,
  75857. 0x35b5a8faUL, 0x42b2986cUL, 0xdbbbc9d6UL, 0xacbcf940UL, 0x32d86ce3UL,
  75858. 0x45df5c75UL, 0xdcd60dcfUL, 0xabd13d59UL, 0x26d930acUL, 0x51de003aUL,
  75859. 0xc8d75180UL, 0xbfd06116UL, 0x21b4f4b5UL, 0x56b3c423UL, 0xcfba9599UL,
  75860. 0xb8bda50fUL, 0x2802b89eUL, 0x5f058808UL, 0xc60cd9b2UL, 0xb10be924UL,
  75861. 0x2f6f7c87UL, 0x58684c11UL, 0xc1611dabUL, 0xb6662d3dUL, 0x76dc4190UL,
  75862. 0x01db7106UL, 0x98d220bcUL, 0xefd5102aUL, 0x71b18589UL, 0x06b6b51fUL,
  75863. 0x9fbfe4a5UL, 0xe8b8d433UL, 0x7807c9a2UL, 0x0f00f934UL, 0x9609a88eUL,
  75864. 0xe10e9818UL, 0x7f6a0dbbUL, 0x086d3d2dUL, 0x91646c97UL, 0xe6635c01UL,
  75865. 0x6b6b51f4UL, 0x1c6c6162UL, 0x856530d8UL, 0xf262004eUL, 0x6c0695edUL,
  75866. 0x1b01a57bUL, 0x8208f4c1UL, 0xf50fc457UL, 0x65b0d9c6UL, 0x12b7e950UL,
  75867. 0x8bbeb8eaUL, 0xfcb9887cUL, 0x62dd1ddfUL, 0x15da2d49UL, 0x8cd37cf3UL,
  75868. 0xfbd44c65UL, 0x4db26158UL, 0x3ab551ceUL, 0xa3bc0074UL, 0xd4bb30e2UL,
  75869. 0x4adfa541UL, 0x3dd895d7UL, 0xa4d1c46dUL, 0xd3d6f4fbUL, 0x4369e96aUL,
  75870. 0x346ed9fcUL, 0xad678846UL, 0xda60b8d0UL, 0x44042d73UL, 0x33031de5UL,
  75871. 0xaa0a4c5fUL, 0xdd0d7cc9UL, 0x5005713cUL, 0x270241aaUL, 0xbe0b1010UL,
  75872. 0xc90c2086UL, 0x5768b525UL, 0x206f85b3UL, 0xb966d409UL, 0xce61e49fUL,
  75873. 0x5edef90eUL, 0x29d9c998UL, 0xb0d09822UL, 0xc7d7a8b4UL, 0x59b33d17UL,
  75874. 0x2eb40d81UL, 0xb7bd5c3bUL, 0xc0ba6cadUL, 0xedb88320UL, 0x9abfb3b6UL,
  75875. 0x03b6e20cUL, 0x74b1d29aUL, 0xead54739UL, 0x9dd277afUL, 0x04db2615UL,
  75876. 0x73dc1683UL, 0xe3630b12UL, 0x94643b84UL, 0x0d6d6a3eUL, 0x7a6a5aa8UL,
  75877. 0xe40ecf0bUL, 0x9309ff9dUL, 0x0a00ae27UL, 0x7d079eb1UL, 0xf00f9344UL,
  75878. 0x8708a3d2UL, 0x1e01f268UL, 0x6906c2feUL, 0xf762575dUL, 0x806567cbUL,
  75879. 0x196c3671UL, 0x6e6b06e7UL, 0xfed41b76UL, 0x89d32be0UL, 0x10da7a5aUL,
  75880. 0x67dd4accUL, 0xf9b9df6fUL, 0x8ebeeff9UL, 0x17b7be43UL, 0x60b08ed5UL,
  75881. 0xd6d6a3e8UL, 0xa1d1937eUL, 0x38d8c2c4UL, 0x4fdff252UL, 0xd1bb67f1UL,
  75882. 0xa6bc5767UL, 0x3fb506ddUL, 0x48b2364bUL, 0xd80d2bdaUL, 0xaf0a1b4cUL,
  75883. 0x36034af6UL, 0x41047a60UL, 0xdf60efc3UL, 0xa867df55UL, 0x316e8eefUL,
  75884. 0x4669be79UL, 0xcb61b38cUL, 0xbc66831aUL, 0x256fd2a0UL, 0x5268e236UL,
  75885. 0xcc0c7795UL, 0xbb0b4703UL, 0x220216b9UL, 0x5505262fUL, 0xc5ba3bbeUL,
  75886. 0xb2bd0b28UL, 0x2bb45a92UL, 0x5cb36a04UL, 0xc2d7ffa7UL, 0xb5d0cf31UL,
  75887. 0x2cd99e8bUL, 0x5bdeae1dUL, 0x9b64c2b0UL, 0xec63f226UL, 0x756aa39cUL,
  75888. 0x026d930aUL, 0x9c0906a9UL, 0xeb0e363fUL, 0x72076785UL, 0x05005713UL,
  75889. 0x95bf4a82UL, 0xe2b87a14UL, 0x7bb12baeUL, 0x0cb61b38UL, 0x92d28e9bUL,
  75890. 0xe5d5be0dUL, 0x7cdcefb7UL, 0x0bdbdf21UL, 0x86d3d2d4UL, 0xf1d4e242UL,
  75891. 0x68ddb3f8UL, 0x1fda836eUL, 0x81be16cdUL, 0xf6b9265bUL, 0x6fb077e1UL,
  75892. 0x18b74777UL, 0x88085ae6UL, 0xff0f6a70UL, 0x66063bcaUL, 0x11010b5cUL,
  75893. 0x8f659effUL, 0xf862ae69UL, 0x616bffd3UL, 0x166ccf45UL, 0xa00ae278UL,
  75894. 0xd70dd2eeUL, 0x4e048354UL, 0x3903b3c2UL, 0xa7672661UL, 0xd06016f7UL,
  75895. 0x4969474dUL, 0x3e6e77dbUL, 0xaed16a4aUL, 0xd9d65adcUL, 0x40df0b66UL,
  75896. 0x37d83bf0UL, 0xa9bcae53UL, 0xdebb9ec5UL, 0x47b2cf7fUL, 0x30b5ffe9UL,
  75897. 0xbdbdf21cUL, 0xcabac28aUL, 0x53b39330UL, 0x24b4a3a6UL, 0xbad03605UL,
  75898. 0xcdd70693UL, 0x54de5729UL, 0x23d967bfUL, 0xb3667a2eUL, 0xc4614ab8UL,
  75899. 0x5d681b02UL, 0x2a6f2b94UL, 0xb40bbe37UL, 0xc30c8ea1UL, 0x5a05df1bUL,
  75900. 0x2d02ef8dUL
  75901. #ifdef BYFOUR
  75902. },
  75903. {
  75904. 0x00000000UL, 0x191b3141UL, 0x32366282UL, 0x2b2d53c3UL, 0x646cc504UL,
  75905. 0x7d77f445UL, 0x565aa786UL, 0x4f4196c7UL, 0xc8d98a08UL, 0xd1c2bb49UL,
  75906. 0xfaefe88aUL, 0xe3f4d9cbUL, 0xacb54f0cUL, 0xb5ae7e4dUL, 0x9e832d8eUL,
  75907. 0x87981ccfUL, 0x4ac21251UL, 0x53d92310UL, 0x78f470d3UL, 0x61ef4192UL,
  75908. 0x2eaed755UL, 0x37b5e614UL, 0x1c98b5d7UL, 0x05838496UL, 0x821b9859UL,
  75909. 0x9b00a918UL, 0xb02dfadbUL, 0xa936cb9aUL, 0xe6775d5dUL, 0xff6c6c1cUL,
  75910. 0xd4413fdfUL, 0xcd5a0e9eUL, 0x958424a2UL, 0x8c9f15e3UL, 0xa7b24620UL,
  75911. 0xbea97761UL, 0xf1e8e1a6UL, 0xe8f3d0e7UL, 0xc3de8324UL, 0xdac5b265UL,
  75912. 0x5d5daeaaUL, 0x44469febUL, 0x6f6bcc28UL, 0x7670fd69UL, 0x39316baeUL,
  75913. 0x202a5aefUL, 0x0b07092cUL, 0x121c386dUL, 0xdf4636f3UL, 0xc65d07b2UL,
  75914. 0xed705471UL, 0xf46b6530UL, 0xbb2af3f7UL, 0xa231c2b6UL, 0x891c9175UL,
  75915. 0x9007a034UL, 0x179fbcfbUL, 0x0e848dbaUL, 0x25a9de79UL, 0x3cb2ef38UL,
  75916. 0x73f379ffUL, 0x6ae848beUL, 0x41c51b7dUL, 0x58de2a3cUL, 0xf0794f05UL,
  75917. 0xe9627e44UL, 0xc24f2d87UL, 0xdb541cc6UL, 0x94158a01UL, 0x8d0ebb40UL,
  75918. 0xa623e883UL, 0xbf38d9c2UL, 0x38a0c50dUL, 0x21bbf44cUL, 0x0a96a78fUL,
  75919. 0x138d96ceUL, 0x5ccc0009UL, 0x45d73148UL, 0x6efa628bUL, 0x77e153caUL,
  75920. 0xbabb5d54UL, 0xa3a06c15UL, 0x888d3fd6UL, 0x91960e97UL, 0xded79850UL,
  75921. 0xc7cca911UL, 0xece1fad2UL, 0xf5facb93UL, 0x7262d75cUL, 0x6b79e61dUL,
  75922. 0x4054b5deUL, 0x594f849fUL, 0x160e1258UL, 0x0f152319UL, 0x243870daUL,
  75923. 0x3d23419bUL, 0x65fd6ba7UL, 0x7ce65ae6UL, 0x57cb0925UL, 0x4ed03864UL,
  75924. 0x0191aea3UL, 0x188a9fe2UL, 0x33a7cc21UL, 0x2abcfd60UL, 0xad24e1afUL,
  75925. 0xb43fd0eeUL, 0x9f12832dUL, 0x8609b26cUL, 0xc94824abUL, 0xd05315eaUL,
  75926. 0xfb7e4629UL, 0xe2657768UL, 0x2f3f79f6UL, 0x362448b7UL, 0x1d091b74UL,
  75927. 0x04122a35UL, 0x4b53bcf2UL, 0x52488db3UL, 0x7965de70UL, 0x607eef31UL,
  75928. 0xe7e6f3feUL, 0xfefdc2bfUL, 0xd5d0917cUL, 0xcccba03dUL, 0x838a36faUL,
  75929. 0x9a9107bbUL, 0xb1bc5478UL, 0xa8a76539UL, 0x3b83984bUL, 0x2298a90aUL,
  75930. 0x09b5fac9UL, 0x10aecb88UL, 0x5fef5d4fUL, 0x46f46c0eUL, 0x6dd93fcdUL,
  75931. 0x74c20e8cUL, 0xf35a1243UL, 0xea412302UL, 0xc16c70c1UL, 0xd8774180UL,
  75932. 0x9736d747UL, 0x8e2de606UL, 0xa500b5c5UL, 0xbc1b8484UL, 0x71418a1aUL,
  75933. 0x685abb5bUL, 0x4377e898UL, 0x5a6cd9d9UL, 0x152d4f1eUL, 0x0c367e5fUL,
  75934. 0x271b2d9cUL, 0x3e001cddUL, 0xb9980012UL, 0xa0833153UL, 0x8bae6290UL,
  75935. 0x92b553d1UL, 0xddf4c516UL, 0xc4eff457UL, 0xefc2a794UL, 0xf6d996d5UL,
  75936. 0xae07bce9UL, 0xb71c8da8UL, 0x9c31de6bUL, 0x852aef2aUL, 0xca6b79edUL,
  75937. 0xd37048acUL, 0xf85d1b6fUL, 0xe1462a2eUL, 0x66de36e1UL, 0x7fc507a0UL,
  75938. 0x54e85463UL, 0x4df36522UL, 0x02b2f3e5UL, 0x1ba9c2a4UL, 0x30849167UL,
  75939. 0x299fa026UL, 0xe4c5aeb8UL, 0xfdde9ff9UL, 0xd6f3cc3aUL, 0xcfe8fd7bUL,
  75940. 0x80a96bbcUL, 0x99b25afdUL, 0xb29f093eUL, 0xab84387fUL, 0x2c1c24b0UL,
  75941. 0x350715f1UL, 0x1e2a4632UL, 0x07317773UL, 0x4870e1b4UL, 0x516bd0f5UL,
  75942. 0x7a468336UL, 0x635db277UL, 0xcbfad74eUL, 0xd2e1e60fUL, 0xf9ccb5ccUL,
  75943. 0xe0d7848dUL, 0xaf96124aUL, 0xb68d230bUL, 0x9da070c8UL, 0x84bb4189UL,
  75944. 0x03235d46UL, 0x1a386c07UL, 0x31153fc4UL, 0x280e0e85UL, 0x674f9842UL,
  75945. 0x7e54a903UL, 0x5579fac0UL, 0x4c62cb81UL, 0x8138c51fUL, 0x9823f45eUL,
  75946. 0xb30ea79dUL, 0xaa1596dcUL, 0xe554001bUL, 0xfc4f315aUL, 0xd7626299UL,
  75947. 0xce7953d8UL, 0x49e14f17UL, 0x50fa7e56UL, 0x7bd72d95UL, 0x62cc1cd4UL,
  75948. 0x2d8d8a13UL, 0x3496bb52UL, 0x1fbbe891UL, 0x06a0d9d0UL, 0x5e7ef3ecUL,
  75949. 0x4765c2adUL, 0x6c48916eUL, 0x7553a02fUL, 0x3a1236e8UL, 0x230907a9UL,
  75950. 0x0824546aUL, 0x113f652bUL, 0x96a779e4UL, 0x8fbc48a5UL, 0xa4911b66UL,
  75951. 0xbd8a2a27UL, 0xf2cbbce0UL, 0xebd08da1UL, 0xc0fdde62UL, 0xd9e6ef23UL,
  75952. 0x14bce1bdUL, 0x0da7d0fcUL, 0x268a833fUL, 0x3f91b27eUL, 0x70d024b9UL,
  75953. 0x69cb15f8UL, 0x42e6463bUL, 0x5bfd777aUL, 0xdc656bb5UL, 0xc57e5af4UL,
  75954. 0xee530937UL, 0xf7483876UL, 0xb809aeb1UL, 0xa1129ff0UL, 0x8a3fcc33UL,
  75955. 0x9324fd72UL
  75956. },
  75957. {
  75958. 0x00000000UL, 0x01c26a37UL, 0x0384d46eUL, 0x0246be59UL, 0x0709a8dcUL,
  75959. 0x06cbc2ebUL, 0x048d7cb2UL, 0x054f1685UL, 0x0e1351b8UL, 0x0fd13b8fUL,
  75960. 0x0d9785d6UL, 0x0c55efe1UL, 0x091af964UL, 0x08d89353UL, 0x0a9e2d0aUL,
  75961. 0x0b5c473dUL, 0x1c26a370UL, 0x1de4c947UL, 0x1fa2771eUL, 0x1e601d29UL,
  75962. 0x1b2f0bacUL, 0x1aed619bUL, 0x18abdfc2UL, 0x1969b5f5UL, 0x1235f2c8UL,
  75963. 0x13f798ffUL, 0x11b126a6UL, 0x10734c91UL, 0x153c5a14UL, 0x14fe3023UL,
  75964. 0x16b88e7aUL, 0x177ae44dUL, 0x384d46e0UL, 0x398f2cd7UL, 0x3bc9928eUL,
  75965. 0x3a0bf8b9UL, 0x3f44ee3cUL, 0x3e86840bUL, 0x3cc03a52UL, 0x3d025065UL,
  75966. 0x365e1758UL, 0x379c7d6fUL, 0x35dac336UL, 0x3418a901UL, 0x3157bf84UL,
  75967. 0x3095d5b3UL, 0x32d36beaUL, 0x331101ddUL, 0x246be590UL, 0x25a98fa7UL,
  75968. 0x27ef31feUL, 0x262d5bc9UL, 0x23624d4cUL, 0x22a0277bUL, 0x20e69922UL,
  75969. 0x2124f315UL, 0x2a78b428UL, 0x2bbade1fUL, 0x29fc6046UL, 0x283e0a71UL,
  75970. 0x2d711cf4UL, 0x2cb376c3UL, 0x2ef5c89aUL, 0x2f37a2adUL, 0x709a8dc0UL,
  75971. 0x7158e7f7UL, 0x731e59aeUL, 0x72dc3399UL, 0x7793251cUL, 0x76514f2bUL,
  75972. 0x7417f172UL, 0x75d59b45UL, 0x7e89dc78UL, 0x7f4bb64fUL, 0x7d0d0816UL,
  75973. 0x7ccf6221UL, 0x798074a4UL, 0x78421e93UL, 0x7a04a0caUL, 0x7bc6cafdUL,
  75974. 0x6cbc2eb0UL, 0x6d7e4487UL, 0x6f38fadeUL, 0x6efa90e9UL, 0x6bb5866cUL,
  75975. 0x6a77ec5bUL, 0x68315202UL, 0x69f33835UL, 0x62af7f08UL, 0x636d153fUL,
  75976. 0x612bab66UL, 0x60e9c151UL, 0x65a6d7d4UL, 0x6464bde3UL, 0x662203baUL,
  75977. 0x67e0698dUL, 0x48d7cb20UL, 0x4915a117UL, 0x4b531f4eUL, 0x4a917579UL,
  75978. 0x4fde63fcUL, 0x4e1c09cbUL, 0x4c5ab792UL, 0x4d98dda5UL, 0x46c49a98UL,
  75979. 0x4706f0afUL, 0x45404ef6UL, 0x448224c1UL, 0x41cd3244UL, 0x400f5873UL,
  75980. 0x4249e62aUL, 0x438b8c1dUL, 0x54f16850UL, 0x55330267UL, 0x5775bc3eUL,
  75981. 0x56b7d609UL, 0x53f8c08cUL, 0x523aaabbUL, 0x507c14e2UL, 0x51be7ed5UL,
  75982. 0x5ae239e8UL, 0x5b2053dfUL, 0x5966ed86UL, 0x58a487b1UL, 0x5deb9134UL,
  75983. 0x5c29fb03UL, 0x5e6f455aUL, 0x5fad2f6dUL, 0xe1351b80UL, 0xe0f771b7UL,
  75984. 0xe2b1cfeeUL, 0xe373a5d9UL, 0xe63cb35cUL, 0xe7fed96bUL, 0xe5b86732UL,
  75985. 0xe47a0d05UL, 0xef264a38UL, 0xeee4200fUL, 0xeca29e56UL, 0xed60f461UL,
  75986. 0xe82fe2e4UL, 0xe9ed88d3UL, 0xebab368aUL, 0xea695cbdUL, 0xfd13b8f0UL,
  75987. 0xfcd1d2c7UL, 0xfe976c9eUL, 0xff5506a9UL, 0xfa1a102cUL, 0xfbd87a1bUL,
  75988. 0xf99ec442UL, 0xf85cae75UL, 0xf300e948UL, 0xf2c2837fUL, 0xf0843d26UL,
  75989. 0xf1465711UL, 0xf4094194UL, 0xf5cb2ba3UL, 0xf78d95faUL, 0xf64fffcdUL,
  75990. 0xd9785d60UL, 0xd8ba3757UL, 0xdafc890eUL, 0xdb3ee339UL, 0xde71f5bcUL,
  75991. 0xdfb39f8bUL, 0xddf521d2UL, 0xdc374be5UL, 0xd76b0cd8UL, 0xd6a966efUL,
  75992. 0xd4efd8b6UL, 0xd52db281UL, 0xd062a404UL, 0xd1a0ce33UL, 0xd3e6706aUL,
  75993. 0xd2241a5dUL, 0xc55efe10UL, 0xc49c9427UL, 0xc6da2a7eUL, 0xc7184049UL,
  75994. 0xc25756ccUL, 0xc3953cfbUL, 0xc1d382a2UL, 0xc011e895UL, 0xcb4dafa8UL,
  75995. 0xca8fc59fUL, 0xc8c97bc6UL, 0xc90b11f1UL, 0xcc440774UL, 0xcd866d43UL,
  75996. 0xcfc0d31aUL, 0xce02b92dUL, 0x91af9640UL, 0x906dfc77UL, 0x922b422eUL,
  75997. 0x93e92819UL, 0x96a63e9cUL, 0x976454abUL, 0x9522eaf2UL, 0x94e080c5UL,
  75998. 0x9fbcc7f8UL, 0x9e7eadcfUL, 0x9c381396UL, 0x9dfa79a1UL, 0x98b56f24UL,
  75999. 0x99770513UL, 0x9b31bb4aUL, 0x9af3d17dUL, 0x8d893530UL, 0x8c4b5f07UL,
  76000. 0x8e0de15eUL, 0x8fcf8b69UL, 0x8a809decUL, 0x8b42f7dbUL, 0x89044982UL,
  76001. 0x88c623b5UL, 0x839a6488UL, 0x82580ebfUL, 0x801eb0e6UL, 0x81dcdad1UL,
  76002. 0x8493cc54UL, 0x8551a663UL, 0x8717183aUL, 0x86d5720dUL, 0xa9e2d0a0UL,
  76003. 0xa820ba97UL, 0xaa6604ceUL, 0xaba46ef9UL, 0xaeeb787cUL, 0xaf29124bUL,
  76004. 0xad6fac12UL, 0xacadc625UL, 0xa7f18118UL, 0xa633eb2fUL, 0xa4755576UL,
  76005. 0xa5b73f41UL, 0xa0f829c4UL, 0xa13a43f3UL, 0xa37cfdaaUL, 0xa2be979dUL,
  76006. 0xb5c473d0UL, 0xb40619e7UL, 0xb640a7beUL, 0xb782cd89UL, 0xb2cddb0cUL,
  76007. 0xb30fb13bUL, 0xb1490f62UL, 0xb08b6555UL, 0xbbd72268UL, 0xba15485fUL,
  76008. 0xb853f606UL, 0xb9919c31UL, 0xbcde8ab4UL, 0xbd1ce083UL, 0xbf5a5edaUL,
  76009. 0xbe9834edUL
  76010. },
  76011. {
  76012. 0x00000000UL, 0xb8bc6765UL, 0xaa09c88bUL, 0x12b5afeeUL, 0x8f629757UL,
  76013. 0x37def032UL, 0x256b5fdcUL, 0x9dd738b9UL, 0xc5b428efUL, 0x7d084f8aUL,
  76014. 0x6fbde064UL, 0xd7018701UL, 0x4ad6bfb8UL, 0xf26ad8ddUL, 0xe0df7733UL,
  76015. 0x58631056UL, 0x5019579fUL, 0xe8a530faUL, 0xfa109f14UL, 0x42acf871UL,
  76016. 0xdf7bc0c8UL, 0x67c7a7adUL, 0x75720843UL, 0xcdce6f26UL, 0x95ad7f70UL,
  76017. 0x2d111815UL, 0x3fa4b7fbUL, 0x8718d09eUL, 0x1acfe827UL, 0xa2738f42UL,
  76018. 0xb0c620acUL, 0x087a47c9UL, 0xa032af3eUL, 0x188ec85bUL, 0x0a3b67b5UL,
  76019. 0xb28700d0UL, 0x2f503869UL, 0x97ec5f0cUL, 0x8559f0e2UL, 0x3de59787UL,
  76020. 0x658687d1UL, 0xdd3ae0b4UL, 0xcf8f4f5aUL, 0x7733283fUL, 0xeae41086UL,
  76021. 0x525877e3UL, 0x40edd80dUL, 0xf851bf68UL, 0xf02bf8a1UL, 0x48979fc4UL,
  76022. 0x5a22302aUL, 0xe29e574fUL, 0x7f496ff6UL, 0xc7f50893UL, 0xd540a77dUL,
  76023. 0x6dfcc018UL, 0x359fd04eUL, 0x8d23b72bUL, 0x9f9618c5UL, 0x272a7fa0UL,
  76024. 0xbafd4719UL, 0x0241207cUL, 0x10f48f92UL, 0xa848e8f7UL, 0x9b14583dUL,
  76025. 0x23a83f58UL, 0x311d90b6UL, 0x89a1f7d3UL, 0x1476cf6aUL, 0xaccaa80fUL,
  76026. 0xbe7f07e1UL, 0x06c36084UL, 0x5ea070d2UL, 0xe61c17b7UL, 0xf4a9b859UL,
  76027. 0x4c15df3cUL, 0xd1c2e785UL, 0x697e80e0UL, 0x7bcb2f0eUL, 0xc377486bUL,
  76028. 0xcb0d0fa2UL, 0x73b168c7UL, 0x6104c729UL, 0xd9b8a04cUL, 0x446f98f5UL,
  76029. 0xfcd3ff90UL, 0xee66507eUL, 0x56da371bUL, 0x0eb9274dUL, 0xb6054028UL,
  76030. 0xa4b0efc6UL, 0x1c0c88a3UL, 0x81dbb01aUL, 0x3967d77fUL, 0x2bd27891UL,
  76031. 0x936e1ff4UL, 0x3b26f703UL, 0x839a9066UL, 0x912f3f88UL, 0x299358edUL,
  76032. 0xb4446054UL, 0x0cf80731UL, 0x1e4da8dfUL, 0xa6f1cfbaUL, 0xfe92dfecUL,
  76033. 0x462eb889UL, 0x549b1767UL, 0xec277002UL, 0x71f048bbUL, 0xc94c2fdeUL,
  76034. 0xdbf98030UL, 0x6345e755UL, 0x6b3fa09cUL, 0xd383c7f9UL, 0xc1366817UL,
  76035. 0x798a0f72UL, 0xe45d37cbUL, 0x5ce150aeUL, 0x4e54ff40UL, 0xf6e89825UL,
  76036. 0xae8b8873UL, 0x1637ef16UL, 0x048240f8UL, 0xbc3e279dUL, 0x21e91f24UL,
  76037. 0x99557841UL, 0x8be0d7afUL, 0x335cb0caUL, 0xed59b63bUL, 0x55e5d15eUL,
  76038. 0x47507eb0UL, 0xffec19d5UL, 0x623b216cUL, 0xda874609UL, 0xc832e9e7UL,
  76039. 0x708e8e82UL, 0x28ed9ed4UL, 0x9051f9b1UL, 0x82e4565fUL, 0x3a58313aUL,
  76040. 0xa78f0983UL, 0x1f336ee6UL, 0x0d86c108UL, 0xb53aa66dUL, 0xbd40e1a4UL,
  76041. 0x05fc86c1UL, 0x1749292fUL, 0xaff54e4aUL, 0x322276f3UL, 0x8a9e1196UL,
  76042. 0x982bbe78UL, 0x2097d91dUL, 0x78f4c94bUL, 0xc048ae2eUL, 0xd2fd01c0UL,
  76043. 0x6a4166a5UL, 0xf7965e1cUL, 0x4f2a3979UL, 0x5d9f9697UL, 0xe523f1f2UL,
  76044. 0x4d6b1905UL, 0xf5d77e60UL, 0xe762d18eUL, 0x5fdeb6ebUL, 0xc2098e52UL,
  76045. 0x7ab5e937UL, 0x680046d9UL, 0xd0bc21bcUL, 0x88df31eaUL, 0x3063568fUL,
  76046. 0x22d6f961UL, 0x9a6a9e04UL, 0x07bda6bdUL, 0xbf01c1d8UL, 0xadb46e36UL,
  76047. 0x15080953UL, 0x1d724e9aUL, 0xa5ce29ffUL, 0xb77b8611UL, 0x0fc7e174UL,
  76048. 0x9210d9cdUL, 0x2aacbea8UL, 0x38191146UL, 0x80a57623UL, 0xd8c66675UL,
  76049. 0x607a0110UL, 0x72cfaefeUL, 0xca73c99bUL, 0x57a4f122UL, 0xef189647UL,
  76050. 0xfdad39a9UL, 0x45115eccUL, 0x764dee06UL, 0xcef18963UL, 0xdc44268dUL,
  76051. 0x64f841e8UL, 0xf92f7951UL, 0x41931e34UL, 0x5326b1daUL, 0xeb9ad6bfUL,
  76052. 0xb3f9c6e9UL, 0x0b45a18cUL, 0x19f00e62UL, 0xa14c6907UL, 0x3c9b51beUL,
  76053. 0x842736dbUL, 0x96929935UL, 0x2e2efe50UL, 0x2654b999UL, 0x9ee8defcUL,
  76054. 0x8c5d7112UL, 0x34e11677UL, 0xa9362eceUL, 0x118a49abUL, 0x033fe645UL,
  76055. 0xbb838120UL, 0xe3e09176UL, 0x5b5cf613UL, 0x49e959fdUL, 0xf1553e98UL,
  76056. 0x6c820621UL, 0xd43e6144UL, 0xc68bceaaUL, 0x7e37a9cfUL, 0xd67f4138UL,
  76057. 0x6ec3265dUL, 0x7c7689b3UL, 0xc4caeed6UL, 0x591dd66fUL, 0xe1a1b10aUL,
  76058. 0xf3141ee4UL, 0x4ba87981UL, 0x13cb69d7UL, 0xab770eb2UL, 0xb9c2a15cUL,
  76059. 0x017ec639UL, 0x9ca9fe80UL, 0x241599e5UL, 0x36a0360bUL, 0x8e1c516eUL,
  76060. 0x866616a7UL, 0x3eda71c2UL, 0x2c6fde2cUL, 0x94d3b949UL, 0x090481f0UL,
  76061. 0xb1b8e695UL, 0xa30d497bUL, 0x1bb12e1eUL, 0x43d23e48UL, 0xfb6e592dUL,
  76062. 0xe9dbf6c3UL, 0x516791a6UL, 0xccb0a91fUL, 0x740cce7aUL, 0x66b96194UL,
  76063. 0xde0506f1UL
  76064. },
  76065. {
  76066. 0x00000000UL, 0x96300777UL, 0x2c610eeeUL, 0xba510999UL, 0x19c46d07UL,
  76067. 0x8ff46a70UL, 0x35a563e9UL, 0xa395649eUL, 0x3288db0eUL, 0xa4b8dc79UL,
  76068. 0x1ee9d5e0UL, 0x88d9d297UL, 0x2b4cb609UL, 0xbd7cb17eUL, 0x072db8e7UL,
  76069. 0x911dbf90UL, 0x6410b71dUL, 0xf220b06aUL, 0x4871b9f3UL, 0xde41be84UL,
  76070. 0x7dd4da1aUL, 0xebe4dd6dUL, 0x51b5d4f4UL, 0xc785d383UL, 0x56986c13UL,
  76071. 0xc0a86b64UL, 0x7af962fdUL, 0xecc9658aUL, 0x4f5c0114UL, 0xd96c0663UL,
  76072. 0x633d0ffaUL, 0xf50d088dUL, 0xc8206e3bUL, 0x5e10694cUL, 0xe44160d5UL,
  76073. 0x727167a2UL, 0xd1e4033cUL, 0x47d4044bUL, 0xfd850dd2UL, 0x6bb50aa5UL,
  76074. 0xfaa8b535UL, 0x6c98b242UL, 0xd6c9bbdbUL, 0x40f9bcacUL, 0xe36cd832UL,
  76075. 0x755cdf45UL, 0xcf0dd6dcUL, 0x593dd1abUL, 0xac30d926UL, 0x3a00de51UL,
  76076. 0x8051d7c8UL, 0x1661d0bfUL, 0xb5f4b421UL, 0x23c4b356UL, 0x9995bacfUL,
  76077. 0x0fa5bdb8UL, 0x9eb80228UL, 0x0888055fUL, 0xb2d90cc6UL, 0x24e90bb1UL,
  76078. 0x877c6f2fUL, 0x114c6858UL, 0xab1d61c1UL, 0x3d2d66b6UL, 0x9041dc76UL,
  76079. 0x0671db01UL, 0xbc20d298UL, 0x2a10d5efUL, 0x8985b171UL, 0x1fb5b606UL,
  76080. 0xa5e4bf9fUL, 0x33d4b8e8UL, 0xa2c90778UL, 0x34f9000fUL, 0x8ea80996UL,
  76081. 0x18980ee1UL, 0xbb0d6a7fUL, 0x2d3d6d08UL, 0x976c6491UL, 0x015c63e6UL,
  76082. 0xf4516b6bUL, 0x62616c1cUL, 0xd8306585UL, 0x4e0062f2UL, 0xed95066cUL,
  76083. 0x7ba5011bUL, 0xc1f40882UL, 0x57c40ff5UL, 0xc6d9b065UL, 0x50e9b712UL,
  76084. 0xeab8be8bUL, 0x7c88b9fcUL, 0xdf1ddd62UL, 0x492dda15UL, 0xf37cd38cUL,
  76085. 0x654cd4fbUL, 0x5861b24dUL, 0xce51b53aUL, 0x7400bca3UL, 0xe230bbd4UL,
  76086. 0x41a5df4aUL, 0xd795d83dUL, 0x6dc4d1a4UL, 0xfbf4d6d3UL, 0x6ae96943UL,
  76087. 0xfcd96e34UL, 0x468867adUL, 0xd0b860daUL, 0x732d0444UL, 0xe51d0333UL,
  76088. 0x5f4c0aaaUL, 0xc97c0dddUL, 0x3c710550UL, 0xaa410227UL, 0x10100bbeUL,
  76089. 0x86200cc9UL, 0x25b56857UL, 0xb3856f20UL, 0x09d466b9UL, 0x9fe461ceUL,
  76090. 0x0ef9de5eUL, 0x98c9d929UL, 0x2298d0b0UL, 0xb4a8d7c7UL, 0x173db359UL,
  76091. 0x810db42eUL, 0x3b5cbdb7UL, 0xad6cbac0UL, 0x2083b8edUL, 0xb6b3bf9aUL,
  76092. 0x0ce2b603UL, 0x9ad2b174UL, 0x3947d5eaUL, 0xaf77d29dUL, 0x1526db04UL,
  76093. 0x8316dc73UL, 0x120b63e3UL, 0x843b6494UL, 0x3e6a6d0dUL, 0xa85a6a7aUL,
  76094. 0x0bcf0ee4UL, 0x9dff0993UL, 0x27ae000aUL, 0xb19e077dUL, 0x44930ff0UL,
  76095. 0xd2a30887UL, 0x68f2011eUL, 0xfec20669UL, 0x5d5762f7UL, 0xcb676580UL,
  76096. 0x71366c19UL, 0xe7066b6eUL, 0x761bd4feUL, 0xe02bd389UL, 0x5a7ada10UL,
  76097. 0xcc4add67UL, 0x6fdfb9f9UL, 0xf9efbe8eUL, 0x43beb717UL, 0xd58eb060UL,
  76098. 0xe8a3d6d6UL, 0x7e93d1a1UL, 0xc4c2d838UL, 0x52f2df4fUL, 0xf167bbd1UL,
  76099. 0x6757bca6UL, 0xdd06b53fUL, 0x4b36b248UL, 0xda2b0dd8UL, 0x4c1b0aafUL,
  76100. 0xf64a0336UL, 0x607a0441UL, 0xc3ef60dfUL, 0x55df67a8UL, 0xef8e6e31UL,
  76101. 0x79be6946UL, 0x8cb361cbUL, 0x1a8366bcUL, 0xa0d26f25UL, 0x36e26852UL,
  76102. 0x95770cccUL, 0x03470bbbUL, 0xb9160222UL, 0x2f260555UL, 0xbe3bbac5UL,
  76103. 0x280bbdb2UL, 0x925ab42bUL, 0x046ab35cUL, 0xa7ffd7c2UL, 0x31cfd0b5UL,
  76104. 0x8b9ed92cUL, 0x1daede5bUL, 0xb0c2649bUL, 0x26f263ecUL, 0x9ca36a75UL,
  76105. 0x0a936d02UL, 0xa906099cUL, 0x3f360eebUL, 0x85670772UL, 0x13570005UL,
  76106. 0x824abf95UL, 0x147ab8e2UL, 0xae2bb17bUL, 0x381bb60cUL, 0x9b8ed292UL,
  76107. 0x0dbed5e5UL, 0xb7efdc7cUL, 0x21dfdb0bUL, 0xd4d2d386UL, 0x42e2d4f1UL,
  76108. 0xf8b3dd68UL, 0x6e83da1fUL, 0xcd16be81UL, 0x5b26b9f6UL, 0xe177b06fUL,
  76109. 0x7747b718UL, 0xe65a0888UL, 0x706a0fffUL, 0xca3b0666UL, 0x5c0b0111UL,
  76110. 0xff9e658fUL, 0x69ae62f8UL, 0xd3ff6b61UL, 0x45cf6c16UL, 0x78e20aa0UL,
  76111. 0xeed20dd7UL, 0x5483044eUL, 0xc2b30339UL, 0x612667a7UL, 0xf71660d0UL,
  76112. 0x4d476949UL, 0xdb776e3eUL, 0x4a6ad1aeUL, 0xdc5ad6d9UL, 0x660bdf40UL,
  76113. 0xf03bd837UL, 0x53aebca9UL, 0xc59ebbdeUL, 0x7fcfb247UL, 0xe9ffb530UL,
  76114. 0x1cf2bdbdUL, 0x8ac2bacaUL, 0x3093b353UL, 0xa6a3b424UL, 0x0536d0baUL,
  76115. 0x9306d7cdUL, 0x2957de54UL, 0xbf67d923UL, 0x2e7a66b3UL, 0xb84a61c4UL,
  76116. 0x021b685dUL, 0x942b6f2aUL, 0x37be0bb4UL, 0xa18e0cc3UL, 0x1bdf055aUL,
  76117. 0x8def022dUL
  76118. },
  76119. {
  76120. 0x00000000UL, 0x41311b19UL, 0x82623632UL, 0xc3532d2bUL, 0x04c56c64UL,
  76121. 0x45f4777dUL, 0x86a75a56UL, 0xc796414fUL, 0x088ad9c8UL, 0x49bbc2d1UL,
  76122. 0x8ae8effaUL, 0xcbd9f4e3UL, 0x0c4fb5acUL, 0x4d7eaeb5UL, 0x8e2d839eUL,
  76123. 0xcf1c9887UL, 0x5112c24aUL, 0x1023d953UL, 0xd370f478UL, 0x9241ef61UL,
  76124. 0x55d7ae2eUL, 0x14e6b537UL, 0xd7b5981cUL, 0x96848305UL, 0x59981b82UL,
  76125. 0x18a9009bUL, 0xdbfa2db0UL, 0x9acb36a9UL, 0x5d5d77e6UL, 0x1c6c6cffUL,
  76126. 0xdf3f41d4UL, 0x9e0e5acdUL, 0xa2248495UL, 0xe3159f8cUL, 0x2046b2a7UL,
  76127. 0x6177a9beUL, 0xa6e1e8f1UL, 0xe7d0f3e8UL, 0x2483dec3UL, 0x65b2c5daUL,
  76128. 0xaaae5d5dUL, 0xeb9f4644UL, 0x28cc6b6fUL, 0x69fd7076UL, 0xae6b3139UL,
  76129. 0xef5a2a20UL, 0x2c09070bUL, 0x6d381c12UL, 0xf33646dfUL, 0xb2075dc6UL,
  76130. 0x715470edUL, 0x30656bf4UL, 0xf7f32abbUL, 0xb6c231a2UL, 0x75911c89UL,
  76131. 0x34a00790UL, 0xfbbc9f17UL, 0xba8d840eUL, 0x79dea925UL, 0x38efb23cUL,
  76132. 0xff79f373UL, 0xbe48e86aUL, 0x7d1bc541UL, 0x3c2ade58UL, 0x054f79f0UL,
  76133. 0x447e62e9UL, 0x872d4fc2UL, 0xc61c54dbUL, 0x018a1594UL, 0x40bb0e8dUL,
  76134. 0x83e823a6UL, 0xc2d938bfUL, 0x0dc5a038UL, 0x4cf4bb21UL, 0x8fa7960aUL,
  76135. 0xce968d13UL, 0x0900cc5cUL, 0x4831d745UL, 0x8b62fa6eUL, 0xca53e177UL,
  76136. 0x545dbbbaUL, 0x156ca0a3UL, 0xd63f8d88UL, 0x970e9691UL, 0x5098d7deUL,
  76137. 0x11a9ccc7UL, 0xd2fae1ecUL, 0x93cbfaf5UL, 0x5cd76272UL, 0x1de6796bUL,
  76138. 0xdeb55440UL, 0x9f844f59UL, 0x58120e16UL, 0x1923150fUL, 0xda703824UL,
  76139. 0x9b41233dUL, 0xa76bfd65UL, 0xe65ae67cUL, 0x2509cb57UL, 0x6438d04eUL,
  76140. 0xa3ae9101UL, 0xe29f8a18UL, 0x21cca733UL, 0x60fdbc2aUL, 0xafe124adUL,
  76141. 0xeed03fb4UL, 0x2d83129fUL, 0x6cb20986UL, 0xab2448c9UL, 0xea1553d0UL,
  76142. 0x29467efbUL, 0x687765e2UL, 0xf6793f2fUL, 0xb7482436UL, 0x741b091dUL,
  76143. 0x352a1204UL, 0xf2bc534bUL, 0xb38d4852UL, 0x70de6579UL, 0x31ef7e60UL,
  76144. 0xfef3e6e7UL, 0xbfc2fdfeUL, 0x7c91d0d5UL, 0x3da0cbccUL, 0xfa368a83UL,
  76145. 0xbb07919aUL, 0x7854bcb1UL, 0x3965a7a8UL, 0x4b98833bUL, 0x0aa99822UL,
  76146. 0xc9fab509UL, 0x88cbae10UL, 0x4f5def5fUL, 0x0e6cf446UL, 0xcd3fd96dUL,
  76147. 0x8c0ec274UL, 0x43125af3UL, 0x022341eaUL, 0xc1706cc1UL, 0x804177d8UL,
  76148. 0x47d73697UL, 0x06e62d8eUL, 0xc5b500a5UL, 0x84841bbcUL, 0x1a8a4171UL,
  76149. 0x5bbb5a68UL, 0x98e87743UL, 0xd9d96c5aUL, 0x1e4f2d15UL, 0x5f7e360cUL,
  76150. 0x9c2d1b27UL, 0xdd1c003eUL, 0x120098b9UL, 0x533183a0UL, 0x9062ae8bUL,
  76151. 0xd153b592UL, 0x16c5f4ddUL, 0x57f4efc4UL, 0x94a7c2efUL, 0xd596d9f6UL,
  76152. 0xe9bc07aeUL, 0xa88d1cb7UL, 0x6bde319cUL, 0x2aef2a85UL, 0xed796bcaUL,
  76153. 0xac4870d3UL, 0x6f1b5df8UL, 0x2e2a46e1UL, 0xe136de66UL, 0xa007c57fUL,
  76154. 0x6354e854UL, 0x2265f34dUL, 0xe5f3b202UL, 0xa4c2a91bUL, 0x67918430UL,
  76155. 0x26a09f29UL, 0xb8aec5e4UL, 0xf99fdefdUL, 0x3accf3d6UL, 0x7bfde8cfUL,
  76156. 0xbc6ba980UL, 0xfd5ab299UL, 0x3e099fb2UL, 0x7f3884abUL, 0xb0241c2cUL,
  76157. 0xf1150735UL, 0x32462a1eUL, 0x73773107UL, 0xb4e17048UL, 0xf5d06b51UL,
  76158. 0x3683467aUL, 0x77b25d63UL, 0x4ed7facbUL, 0x0fe6e1d2UL, 0xccb5ccf9UL,
  76159. 0x8d84d7e0UL, 0x4a1296afUL, 0x0b238db6UL, 0xc870a09dUL, 0x8941bb84UL,
  76160. 0x465d2303UL, 0x076c381aUL, 0xc43f1531UL, 0x850e0e28UL, 0x42984f67UL,
  76161. 0x03a9547eUL, 0xc0fa7955UL, 0x81cb624cUL, 0x1fc53881UL, 0x5ef42398UL,
  76162. 0x9da70eb3UL, 0xdc9615aaUL, 0x1b0054e5UL, 0x5a314ffcUL, 0x996262d7UL,
  76163. 0xd85379ceUL, 0x174fe149UL, 0x567efa50UL, 0x952dd77bUL, 0xd41ccc62UL,
  76164. 0x138a8d2dUL, 0x52bb9634UL, 0x91e8bb1fUL, 0xd0d9a006UL, 0xecf37e5eUL,
  76165. 0xadc26547UL, 0x6e91486cUL, 0x2fa05375UL, 0xe836123aUL, 0xa9070923UL,
  76166. 0x6a542408UL, 0x2b653f11UL, 0xe479a796UL, 0xa548bc8fUL, 0x661b91a4UL,
  76167. 0x272a8abdUL, 0xe0bccbf2UL, 0xa18dd0ebUL, 0x62defdc0UL, 0x23efe6d9UL,
  76168. 0xbde1bc14UL, 0xfcd0a70dUL, 0x3f838a26UL, 0x7eb2913fUL, 0xb924d070UL,
  76169. 0xf815cb69UL, 0x3b46e642UL, 0x7a77fd5bUL, 0xb56b65dcUL, 0xf45a7ec5UL,
  76170. 0x370953eeUL, 0x763848f7UL, 0xb1ae09b8UL, 0xf09f12a1UL, 0x33cc3f8aUL,
  76171. 0x72fd2493UL
  76172. },
  76173. {
  76174. 0x00000000UL, 0x376ac201UL, 0x6ed48403UL, 0x59be4602UL, 0xdca80907UL,
  76175. 0xebc2cb06UL, 0xb27c8d04UL, 0x85164f05UL, 0xb851130eUL, 0x8f3bd10fUL,
  76176. 0xd685970dUL, 0xe1ef550cUL, 0x64f91a09UL, 0x5393d808UL, 0x0a2d9e0aUL,
  76177. 0x3d475c0bUL, 0x70a3261cUL, 0x47c9e41dUL, 0x1e77a21fUL, 0x291d601eUL,
  76178. 0xac0b2f1bUL, 0x9b61ed1aUL, 0xc2dfab18UL, 0xf5b56919UL, 0xc8f23512UL,
  76179. 0xff98f713UL, 0xa626b111UL, 0x914c7310UL, 0x145a3c15UL, 0x2330fe14UL,
  76180. 0x7a8eb816UL, 0x4de47a17UL, 0xe0464d38UL, 0xd72c8f39UL, 0x8e92c93bUL,
  76181. 0xb9f80b3aUL, 0x3cee443fUL, 0x0b84863eUL, 0x523ac03cUL, 0x6550023dUL,
  76182. 0x58175e36UL, 0x6f7d9c37UL, 0x36c3da35UL, 0x01a91834UL, 0x84bf5731UL,
  76183. 0xb3d59530UL, 0xea6bd332UL, 0xdd011133UL, 0x90e56b24UL, 0xa78fa925UL,
  76184. 0xfe31ef27UL, 0xc95b2d26UL, 0x4c4d6223UL, 0x7b27a022UL, 0x2299e620UL,
  76185. 0x15f32421UL, 0x28b4782aUL, 0x1fdeba2bUL, 0x4660fc29UL, 0x710a3e28UL,
  76186. 0xf41c712dUL, 0xc376b32cUL, 0x9ac8f52eUL, 0xada2372fUL, 0xc08d9a70UL,
  76187. 0xf7e75871UL, 0xae591e73UL, 0x9933dc72UL, 0x1c259377UL, 0x2b4f5176UL,
  76188. 0x72f11774UL, 0x459bd575UL, 0x78dc897eUL, 0x4fb64b7fUL, 0x16080d7dUL,
  76189. 0x2162cf7cUL, 0xa4748079UL, 0x931e4278UL, 0xcaa0047aUL, 0xfdcac67bUL,
  76190. 0xb02ebc6cUL, 0x87447e6dUL, 0xdefa386fUL, 0xe990fa6eUL, 0x6c86b56bUL,
  76191. 0x5bec776aUL, 0x02523168UL, 0x3538f369UL, 0x087faf62UL, 0x3f156d63UL,
  76192. 0x66ab2b61UL, 0x51c1e960UL, 0xd4d7a665UL, 0xe3bd6464UL, 0xba032266UL,
  76193. 0x8d69e067UL, 0x20cbd748UL, 0x17a11549UL, 0x4e1f534bUL, 0x7975914aUL,
  76194. 0xfc63de4fUL, 0xcb091c4eUL, 0x92b75a4cUL, 0xa5dd984dUL, 0x989ac446UL,
  76195. 0xaff00647UL, 0xf64e4045UL, 0xc1248244UL, 0x4432cd41UL, 0x73580f40UL,
  76196. 0x2ae64942UL, 0x1d8c8b43UL, 0x5068f154UL, 0x67023355UL, 0x3ebc7557UL,
  76197. 0x09d6b756UL, 0x8cc0f853UL, 0xbbaa3a52UL, 0xe2147c50UL, 0xd57ebe51UL,
  76198. 0xe839e25aUL, 0xdf53205bUL, 0x86ed6659UL, 0xb187a458UL, 0x3491eb5dUL,
  76199. 0x03fb295cUL, 0x5a456f5eUL, 0x6d2fad5fUL, 0x801b35e1UL, 0xb771f7e0UL,
  76200. 0xeecfb1e2UL, 0xd9a573e3UL, 0x5cb33ce6UL, 0x6bd9fee7UL, 0x3267b8e5UL,
  76201. 0x050d7ae4UL, 0x384a26efUL, 0x0f20e4eeUL, 0x569ea2ecUL, 0x61f460edUL,
  76202. 0xe4e22fe8UL, 0xd388ede9UL, 0x8a36abebUL, 0xbd5c69eaUL, 0xf0b813fdUL,
  76203. 0xc7d2d1fcUL, 0x9e6c97feUL, 0xa90655ffUL, 0x2c101afaUL, 0x1b7ad8fbUL,
  76204. 0x42c49ef9UL, 0x75ae5cf8UL, 0x48e900f3UL, 0x7f83c2f2UL, 0x263d84f0UL,
  76205. 0x115746f1UL, 0x944109f4UL, 0xa32bcbf5UL, 0xfa958df7UL, 0xcdff4ff6UL,
  76206. 0x605d78d9UL, 0x5737bad8UL, 0x0e89fcdaUL, 0x39e33edbUL, 0xbcf571deUL,
  76207. 0x8b9fb3dfUL, 0xd221f5ddUL, 0xe54b37dcUL, 0xd80c6bd7UL, 0xef66a9d6UL,
  76208. 0xb6d8efd4UL, 0x81b22dd5UL, 0x04a462d0UL, 0x33cea0d1UL, 0x6a70e6d3UL,
  76209. 0x5d1a24d2UL, 0x10fe5ec5UL, 0x27949cc4UL, 0x7e2adac6UL, 0x494018c7UL,
  76210. 0xcc5657c2UL, 0xfb3c95c3UL, 0xa282d3c1UL, 0x95e811c0UL, 0xa8af4dcbUL,
  76211. 0x9fc58fcaUL, 0xc67bc9c8UL, 0xf1110bc9UL, 0x740744ccUL, 0x436d86cdUL,
  76212. 0x1ad3c0cfUL, 0x2db902ceUL, 0x4096af91UL, 0x77fc6d90UL, 0x2e422b92UL,
  76213. 0x1928e993UL, 0x9c3ea696UL, 0xab546497UL, 0xf2ea2295UL, 0xc580e094UL,
  76214. 0xf8c7bc9fUL, 0xcfad7e9eUL, 0x9613389cUL, 0xa179fa9dUL, 0x246fb598UL,
  76215. 0x13057799UL, 0x4abb319bUL, 0x7dd1f39aUL, 0x3035898dUL, 0x075f4b8cUL,
  76216. 0x5ee10d8eUL, 0x698bcf8fUL, 0xec9d808aUL, 0xdbf7428bUL, 0x82490489UL,
  76217. 0xb523c688UL, 0x88649a83UL, 0xbf0e5882UL, 0xe6b01e80UL, 0xd1dadc81UL,
  76218. 0x54cc9384UL, 0x63a65185UL, 0x3a181787UL, 0x0d72d586UL, 0xa0d0e2a9UL,
  76219. 0x97ba20a8UL, 0xce0466aaUL, 0xf96ea4abUL, 0x7c78ebaeUL, 0x4b1229afUL,
  76220. 0x12ac6fadUL, 0x25c6adacUL, 0x1881f1a7UL, 0x2feb33a6UL, 0x765575a4UL,
  76221. 0x413fb7a5UL, 0xc429f8a0UL, 0xf3433aa1UL, 0xaafd7ca3UL, 0x9d97bea2UL,
  76222. 0xd073c4b5UL, 0xe71906b4UL, 0xbea740b6UL, 0x89cd82b7UL, 0x0cdbcdb2UL,
  76223. 0x3bb10fb3UL, 0x620f49b1UL, 0x55658bb0UL, 0x6822d7bbUL, 0x5f4815baUL,
  76224. 0x06f653b8UL, 0x319c91b9UL, 0xb48adebcUL, 0x83e01cbdUL, 0xda5e5abfUL,
  76225. 0xed3498beUL
  76226. },
  76227. {
  76228. 0x00000000UL, 0x6567bcb8UL, 0x8bc809aaUL, 0xeeafb512UL, 0x5797628fUL,
  76229. 0x32f0de37UL, 0xdc5f6b25UL, 0xb938d79dUL, 0xef28b4c5UL, 0x8a4f087dUL,
  76230. 0x64e0bd6fUL, 0x018701d7UL, 0xb8bfd64aUL, 0xddd86af2UL, 0x3377dfe0UL,
  76231. 0x56106358UL, 0x9f571950UL, 0xfa30a5e8UL, 0x149f10faUL, 0x71f8ac42UL,
  76232. 0xc8c07bdfUL, 0xada7c767UL, 0x43087275UL, 0x266fcecdUL, 0x707fad95UL,
  76233. 0x1518112dUL, 0xfbb7a43fUL, 0x9ed01887UL, 0x27e8cf1aUL, 0x428f73a2UL,
  76234. 0xac20c6b0UL, 0xc9477a08UL, 0x3eaf32a0UL, 0x5bc88e18UL, 0xb5673b0aUL,
  76235. 0xd00087b2UL, 0x6938502fUL, 0x0c5fec97UL, 0xe2f05985UL, 0x8797e53dUL,
  76236. 0xd1878665UL, 0xb4e03addUL, 0x5a4f8fcfUL, 0x3f283377UL, 0x8610e4eaUL,
  76237. 0xe3775852UL, 0x0dd8ed40UL, 0x68bf51f8UL, 0xa1f82bf0UL, 0xc49f9748UL,
  76238. 0x2a30225aUL, 0x4f579ee2UL, 0xf66f497fUL, 0x9308f5c7UL, 0x7da740d5UL,
  76239. 0x18c0fc6dUL, 0x4ed09f35UL, 0x2bb7238dUL, 0xc518969fUL, 0xa07f2a27UL,
  76240. 0x1947fdbaUL, 0x7c204102UL, 0x928ff410UL, 0xf7e848a8UL, 0x3d58149bUL,
  76241. 0x583fa823UL, 0xb6901d31UL, 0xd3f7a189UL, 0x6acf7614UL, 0x0fa8caacUL,
  76242. 0xe1077fbeUL, 0x8460c306UL, 0xd270a05eUL, 0xb7171ce6UL, 0x59b8a9f4UL,
  76243. 0x3cdf154cUL, 0x85e7c2d1UL, 0xe0807e69UL, 0x0e2fcb7bUL, 0x6b4877c3UL,
  76244. 0xa20f0dcbUL, 0xc768b173UL, 0x29c70461UL, 0x4ca0b8d9UL, 0xf5986f44UL,
  76245. 0x90ffd3fcUL, 0x7e5066eeUL, 0x1b37da56UL, 0x4d27b90eUL, 0x284005b6UL,
  76246. 0xc6efb0a4UL, 0xa3880c1cUL, 0x1ab0db81UL, 0x7fd76739UL, 0x9178d22bUL,
  76247. 0xf41f6e93UL, 0x03f7263bUL, 0x66909a83UL, 0x883f2f91UL, 0xed589329UL,
  76248. 0x546044b4UL, 0x3107f80cUL, 0xdfa84d1eUL, 0xbacff1a6UL, 0xecdf92feUL,
  76249. 0x89b82e46UL, 0x67179b54UL, 0x027027ecUL, 0xbb48f071UL, 0xde2f4cc9UL,
  76250. 0x3080f9dbUL, 0x55e74563UL, 0x9ca03f6bUL, 0xf9c783d3UL, 0x176836c1UL,
  76251. 0x720f8a79UL, 0xcb375de4UL, 0xae50e15cUL, 0x40ff544eUL, 0x2598e8f6UL,
  76252. 0x73888baeUL, 0x16ef3716UL, 0xf8408204UL, 0x9d273ebcUL, 0x241fe921UL,
  76253. 0x41785599UL, 0xafd7e08bUL, 0xcab05c33UL, 0x3bb659edUL, 0x5ed1e555UL,
  76254. 0xb07e5047UL, 0xd519ecffUL, 0x6c213b62UL, 0x094687daUL, 0xe7e932c8UL,
  76255. 0x828e8e70UL, 0xd49eed28UL, 0xb1f95190UL, 0x5f56e482UL, 0x3a31583aUL,
  76256. 0x83098fa7UL, 0xe66e331fUL, 0x08c1860dUL, 0x6da63ab5UL, 0xa4e140bdUL,
  76257. 0xc186fc05UL, 0x2f294917UL, 0x4a4ef5afUL, 0xf3762232UL, 0x96119e8aUL,
  76258. 0x78be2b98UL, 0x1dd99720UL, 0x4bc9f478UL, 0x2eae48c0UL, 0xc001fdd2UL,
  76259. 0xa566416aUL, 0x1c5e96f7UL, 0x79392a4fUL, 0x97969f5dUL, 0xf2f123e5UL,
  76260. 0x05196b4dUL, 0x607ed7f5UL, 0x8ed162e7UL, 0xebb6de5fUL, 0x528e09c2UL,
  76261. 0x37e9b57aUL, 0xd9460068UL, 0xbc21bcd0UL, 0xea31df88UL, 0x8f566330UL,
  76262. 0x61f9d622UL, 0x049e6a9aUL, 0xbda6bd07UL, 0xd8c101bfUL, 0x366eb4adUL,
  76263. 0x53090815UL, 0x9a4e721dUL, 0xff29cea5UL, 0x11867bb7UL, 0x74e1c70fUL,
  76264. 0xcdd91092UL, 0xa8beac2aUL, 0x46111938UL, 0x2376a580UL, 0x7566c6d8UL,
  76265. 0x10017a60UL, 0xfeaecf72UL, 0x9bc973caUL, 0x22f1a457UL, 0x479618efUL,
  76266. 0xa939adfdUL, 0xcc5e1145UL, 0x06ee4d76UL, 0x6389f1ceUL, 0x8d2644dcUL,
  76267. 0xe841f864UL, 0x51792ff9UL, 0x341e9341UL, 0xdab12653UL, 0xbfd69aebUL,
  76268. 0xe9c6f9b3UL, 0x8ca1450bUL, 0x620ef019UL, 0x07694ca1UL, 0xbe519b3cUL,
  76269. 0xdb362784UL, 0x35999296UL, 0x50fe2e2eUL, 0x99b95426UL, 0xfcdee89eUL,
  76270. 0x12715d8cUL, 0x7716e134UL, 0xce2e36a9UL, 0xab498a11UL, 0x45e63f03UL,
  76271. 0x208183bbUL, 0x7691e0e3UL, 0x13f65c5bUL, 0xfd59e949UL, 0x983e55f1UL,
  76272. 0x2106826cUL, 0x44613ed4UL, 0xaace8bc6UL, 0xcfa9377eUL, 0x38417fd6UL,
  76273. 0x5d26c36eUL, 0xb389767cUL, 0xd6eecac4UL, 0x6fd61d59UL, 0x0ab1a1e1UL,
  76274. 0xe41e14f3UL, 0x8179a84bUL, 0xd769cb13UL, 0xb20e77abUL, 0x5ca1c2b9UL,
  76275. 0x39c67e01UL, 0x80fea99cUL, 0xe5991524UL, 0x0b36a036UL, 0x6e511c8eUL,
  76276. 0xa7166686UL, 0xc271da3eUL, 0x2cde6f2cUL, 0x49b9d394UL, 0xf0810409UL,
  76277. 0x95e6b8b1UL, 0x7b490da3UL, 0x1e2eb11bUL, 0x483ed243UL, 0x2d596efbUL,
  76278. 0xc3f6dbe9UL, 0xa6916751UL, 0x1fa9b0ccUL, 0x7ace0c74UL, 0x9461b966UL,
  76279. 0xf10605deUL
  76280. #endif
  76281. }
  76282. };
  76283. /*** End of inlined file: crc32.h ***/
  76284. #endif /* DYNAMIC_CRC_TABLE */
  76285. const unsigned long FAR * ZEXPORT get_crc_table()
  76286. {
  76287. #ifdef DYNAMIC_CRC_TABLE
  76288. if (crc_table_empty)
  76289. make_crc_table();
  76290. #endif /* DYNAMIC_CRC_TABLE */
  76291. return (const unsigned long FAR *)crc_table;
  76292. }
  76293. #define DO1 crc = crc_table[0][((int)crc ^ (*buf++)) & 0xff] ^ (crc >> 8)
  76294. #define DO8 DO1; DO1; DO1; DO1; DO1; DO1; DO1; DO1
  76295. unsigned long ZEXPORT crc32 (unsigned long crc, const unsigned char FAR *buf, unsigned len)
  76296. {
  76297. if (buf == Z_NULL) return 0UL;
  76298. #ifdef DYNAMIC_CRC_TABLE
  76299. if (crc_table_empty)
  76300. make_crc_table();
  76301. #endif /* DYNAMIC_CRC_TABLE */
  76302. #ifdef BYFOUR
  76303. if (sizeof(void *) == sizeof(ptrdiff_t)) {
  76304. u4 endian;
  76305. endian = 1;
  76306. if (*((unsigned char *)(&endian)))
  76307. return crc32_little(crc, buf, len);
  76308. else
  76309. return crc32_big(crc, buf, len);
  76310. }
  76311. #endif /* BYFOUR */
  76312. crc = crc ^ 0xffffffffUL;
  76313. while (len >= 8) {
  76314. DO8;
  76315. len -= 8;
  76316. }
  76317. if (len) do {
  76318. DO1;
  76319. } while (--len);
  76320. return crc ^ 0xffffffffUL;
  76321. }
  76322. #ifdef BYFOUR
  76323. #define DOLIT4 c ^= *buf4++; \
  76324. c = crc_table[3][c & 0xff] ^ crc_table[2][(c >> 8) & 0xff] ^ \
  76325. crc_table[1][(c >> 16) & 0xff] ^ crc_table[0][c >> 24]
  76326. #define DOLIT32 DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4
  76327. local unsigned long crc32_little(unsigned long crc, const unsigned char FAR *buf, unsigned len)
  76328. {
  76329. register u4 c;
  76330. register const u4 FAR *buf4;
  76331. c = (u4)crc;
  76332. c = ~c;
  76333. while (len && ((ptrdiff_t)buf & 3)) {
  76334. c = crc_table[0][(c ^ *buf++) & 0xff] ^ (c >> 8);
  76335. len--;
  76336. }
  76337. buf4 = (const u4 FAR *)(const void FAR *)buf;
  76338. while (len >= 32) {
  76339. DOLIT32;
  76340. len -= 32;
  76341. }
  76342. while (len >= 4) {
  76343. DOLIT4;
  76344. len -= 4;
  76345. }
  76346. buf = (const unsigned char FAR *)buf4;
  76347. if (len) do {
  76348. c = crc_table[0][(c ^ *buf++) & 0xff] ^ (c >> 8);
  76349. } while (--len);
  76350. c = ~c;
  76351. return (unsigned long)c;
  76352. }
  76353. #define DOBIG4 c ^= *++buf4; \
  76354. c = crc_table[4][c & 0xff] ^ crc_table[5][(c >> 8) & 0xff] ^ \
  76355. crc_table[6][(c >> 16) & 0xff] ^ crc_table[7][c >> 24]
  76356. #define DOBIG32 DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4
  76357. local unsigned long crc32_big (unsigned long crc, const unsigned char FAR *buf, unsigned len)
  76358. {
  76359. register u4 c;
  76360. register const u4 FAR *buf4;
  76361. c = REV((u4)crc);
  76362. c = ~c;
  76363. while (len && ((ptrdiff_t)buf & 3)) {
  76364. c = crc_table[4][(c >> 24) ^ *buf++] ^ (c << 8);
  76365. len--;
  76366. }
  76367. buf4 = (const u4 FAR *)(const void FAR *)buf;
  76368. buf4--;
  76369. while (len >= 32) {
  76370. DOBIG32;
  76371. len -= 32;
  76372. }
  76373. while (len >= 4) {
  76374. DOBIG4;
  76375. len -= 4;
  76376. }
  76377. buf4++;
  76378. buf = (const unsigned char FAR *)buf4;
  76379. if (len) do {
  76380. c = crc_table[4][(c >> 24) ^ *buf++] ^ (c << 8);
  76381. } while (--len);
  76382. c = ~c;
  76383. return (unsigned long)(REV(c));
  76384. }
  76385. #endif /* BYFOUR */
  76386. #define GF2_DIM 32 /* dimension of GF(2) vectors (length of CRC) */
  76387. local unsigned long gf2_matrix_times (unsigned long *mat, unsigned long vec)
  76388. {
  76389. unsigned long sum;
  76390. sum = 0;
  76391. while (vec) {
  76392. if (vec & 1)
  76393. sum ^= *mat;
  76394. vec >>= 1;
  76395. mat++;
  76396. }
  76397. return sum;
  76398. }
  76399. local void gf2_matrix_square (unsigned long *square, unsigned long *mat)
  76400. {
  76401. int n;
  76402. for (n = 0; n < GF2_DIM; n++)
  76403. square[n] = gf2_matrix_times(mat, mat[n]);
  76404. }
  76405. uLong ZEXPORT crc32_combine (uLong crc1, uLong crc2, z_off_t len2)
  76406. {
  76407. int n;
  76408. unsigned long row;
  76409. unsigned long even[GF2_DIM]; /* even-power-of-two zeros operator */
  76410. unsigned long odd[GF2_DIM]; /* odd-power-of-two zeros operator */
  76411. if (len2 == 0)
  76412. return crc1;
  76413. odd[0] = 0xedb88320L; /* CRC-32 polynomial */
  76414. row = 1;
  76415. for (n = 1; n < GF2_DIM; n++) {
  76416. odd[n] = row;
  76417. row <<= 1;
  76418. }
  76419. gf2_matrix_square(even, odd);
  76420. gf2_matrix_square(odd, even);
  76421. do {
  76422. gf2_matrix_square(even, odd);
  76423. if (len2 & 1)
  76424. crc1 = gf2_matrix_times(even, crc1);
  76425. len2 >>= 1;
  76426. if (len2 == 0)
  76427. break;
  76428. gf2_matrix_square(odd, even);
  76429. if (len2 & 1)
  76430. crc1 = gf2_matrix_times(odd, crc1);
  76431. len2 >>= 1;
  76432. } while (len2 != 0);
  76433. crc1 ^= crc2;
  76434. return crc1;
  76435. }
  76436. /*** End of inlined file: crc32.c ***/
  76437. /*** Start of inlined file: deflate.c ***/
  76438. /*** Start of inlined file: deflate.h ***/
  76439. #ifndef DEFLATE_H
  76440. #define DEFLATE_H
  76441. #ifndef NO_GZIP
  76442. # define GZIP
  76443. #endif
  76444. #define NO_DUMMY_DECL
  76445. #define LENGTH_CODES 29
  76446. #define LITERALS 256
  76447. #define L_CODES (LITERALS+1+LENGTH_CODES)
  76448. #define D_CODES 30
  76449. #define BL_CODES 19
  76450. #define HEAP_SIZE (2*L_CODES+1)
  76451. #define MAX_BITS 15
  76452. #define INIT_STATE 42
  76453. #define EXTRA_STATE 69
  76454. #define NAME_STATE 73
  76455. #define COMMENT_STATE 91
  76456. #define HCRC_STATE 103
  76457. #define BUSY_STATE 113
  76458. #define FINISH_STATE 666
  76459. typedef struct ct_data_s {
  76460. union {
  76461. ush freq; /* frequency count */
  76462. ush code; /* bit string */
  76463. } fc;
  76464. union {
  76465. ush dad; /* father node in Huffman tree */
  76466. ush len; /* length of bit string */
  76467. } dl;
  76468. } FAR ct_data;
  76469. #define Freq fc.freq
  76470. #define Code fc.code
  76471. #define Dad dl.dad
  76472. #define Len dl.len
  76473. typedef struct static_tree_desc_s static_tree_desc;
  76474. typedef struct tree_desc_s {
  76475. ct_data *dyn_tree; /* the dynamic tree */
  76476. int max_code; /* largest code with non zero frequency */
  76477. static_tree_desc *stat_desc; /* the corresponding static tree */
  76478. } FAR tree_desc;
  76479. typedef ush Pos;
  76480. typedef Pos FAR Posf;
  76481. typedef unsigned IPos;
  76482. typedef struct internal_state {
  76483. z_streamp strm; /* pointer back to this zlib stream */
  76484. int status; /* as the name implies */
  76485. Bytef *pending_buf; /* output still pending */
  76486. ulg pending_buf_size; /* size of pending_buf */
  76487. Bytef *pending_out; /* next pending byte to output to the stream */
  76488. uInt pending; /* nb of bytes in the pending buffer */
  76489. int wrap; /* bit 0 true for zlib, bit 1 true for gzip */
  76490. gz_headerp gzhead; /* gzip header information to write */
  76491. uInt gzindex; /* where in extra, name, or comment */
  76492. Byte method; /* STORED (for zip only) or DEFLATED */
  76493. int last_flush; /* value of flush param for previous deflate call */
  76494. uInt w_size; /* LZ77 window size (32K by default) */
  76495. uInt w_bits; /* log2(w_size) (8..16) */
  76496. uInt w_mask; /* w_size - 1 */
  76497. Bytef *window;
  76498. ulg window_size;
  76499. Posf *prev;
  76500. Posf *head; /* Heads of the hash chains or NIL. */
  76501. uInt ins_h; /* hash index of string to be inserted */
  76502. uInt hash_size; /* number of elements in hash table */
  76503. uInt hash_bits; /* log2(hash_size) */
  76504. uInt hash_mask; /* hash_size-1 */
  76505. uInt hash_shift;
  76506. long block_start;
  76507. uInt match_length; /* length of best match */
  76508. IPos prev_match; /* previous match */
  76509. int match_available; /* set if previous match exists */
  76510. uInt strstart; /* start of string to insert */
  76511. uInt match_start; /* start of matching string */
  76512. uInt lookahead; /* number of valid bytes ahead in window */
  76513. uInt prev_length;
  76514. uInt max_chain_length;
  76515. uInt max_lazy_match;
  76516. # define max_insert_length max_lazy_match
  76517. int level; /* compression level (1..9) */
  76518. int strategy; /* favor or force Huffman coding*/
  76519. uInt good_match;
  76520. int nice_match; /* Stop searching when current match exceeds this */
  76521. struct ct_data_s dyn_ltree[HEAP_SIZE]; /* literal and length tree */
  76522. struct ct_data_s dyn_dtree[2*D_CODES+1]; /* distance tree */
  76523. struct ct_data_s bl_tree[2*BL_CODES+1]; /* Huffman tree for bit lengths */
  76524. struct tree_desc_s l_desc; /* desc. for literal tree */
  76525. struct tree_desc_s d_desc; /* desc. for distance tree */
  76526. struct tree_desc_s bl_desc; /* desc. for bit length tree */
  76527. ush bl_count[MAX_BITS+1];
  76528. int heap[2*L_CODES+1]; /* heap used to build the Huffman trees */
  76529. int heap_len; /* number of elements in the heap */
  76530. int heap_max; /* element of largest frequency */
  76531. uch depth[2*L_CODES+1];
  76532. uchf *l_buf; /* buffer for literals or lengths */
  76533. uInt lit_bufsize;
  76534. uInt last_lit; /* running index in l_buf */
  76535. ushf *d_buf;
  76536. ulg opt_len; /* bit length of current block with optimal trees */
  76537. ulg static_len; /* bit length of current block with static trees */
  76538. uInt matches; /* number of string matches in current block */
  76539. int last_eob_len; /* bit length of EOB code for last block */
  76540. #ifdef DEBUG
  76541. ulg compressed_len; /* total bit length of compressed file mod 2^32 */
  76542. ulg bits_sent; /* bit length of compressed data sent mod 2^32 */
  76543. #endif
  76544. ush bi_buf;
  76545. int bi_valid;
  76546. } FAR deflate_state;
  76547. #define put_byte(s, c) {s->pending_buf[s->pending++] = (c);}
  76548. #define MIN_LOOKAHEAD (MAX_MATCH+MIN_MATCH+1)
  76549. #define MAX_DIST(s) ((s)->w_size-MIN_LOOKAHEAD)
  76550. void _tr_init OF((deflate_state *s));
  76551. int _tr_tally OF((deflate_state *s, unsigned dist, unsigned lc));
  76552. void _tr_flush_block OF((deflate_state *s, charf *buf, ulg stored_len,
  76553. int eof));
  76554. void _tr_align OF((deflate_state *s));
  76555. void _tr_stored_block OF((deflate_state *s, charf *buf, ulg stored_len,
  76556. int eof));
  76557. #define d_code(dist) \
  76558. ((dist) < 256 ? _dist_code[dist] : _dist_code[256+((dist)>>7)])
  76559. #ifndef DEBUG
  76560. #if defined(GEN_TREES_H) || !defined(STDC)
  76561. extern uch _length_code[];
  76562. extern uch _dist_code[];
  76563. #else
  76564. extern const uch _length_code[];
  76565. extern const uch _dist_code[];
  76566. #endif
  76567. # define _tr_tally_lit(s, c, flush) \
  76568. { uch cc = (c); \
  76569. s->d_buf[s->last_lit] = 0; \
  76570. s->l_buf[s->last_lit++] = cc; \
  76571. s->dyn_ltree[cc].Freq++; \
  76572. flush = (s->last_lit == s->lit_bufsize-1); \
  76573. }
  76574. # define _tr_tally_dist(s, distance, length, flush) \
  76575. { uch len = (length); \
  76576. ush dist = (distance); \
  76577. s->d_buf[s->last_lit] = dist; \
  76578. s->l_buf[s->last_lit++] = len; \
  76579. dist--; \
  76580. s->dyn_ltree[_length_code[len]+LITERALS+1].Freq++; \
  76581. s->dyn_dtree[d_code(dist)].Freq++; \
  76582. flush = (s->last_lit == s->lit_bufsize-1); \
  76583. }
  76584. #else
  76585. # define _tr_tally_lit(s, c, flush) flush = _tr_tally(s, 0, c)
  76586. # define _tr_tally_dist(s, distance, length, flush) \
  76587. flush = _tr_tally(s, distance, length)
  76588. #endif
  76589. #endif /* DEFLATE_H */
  76590. /*** End of inlined file: deflate.h ***/
  76591. const char deflate_copyright[] =
  76592. " deflate 1.2.3 Copyright 1995-2005 Jean-loup Gailly ";
  76593. typedef enum {
  76594. need_more, /* block not completed, need more input or more output */
  76595. block_done, /* block flush performed */
  76596. finish_started, /* finish started, need only more output at next deflate */
  76597. finish_done /* finish done, accept no more input or output */
  76598. } block_state;
  76599. typedef block_state (*compress_func) OF((deflate_state *s, int flush));
  76600. local void fill_window OF((deflate_state *s));
  76601. local block_state deflate_stored OF((deflate_state *s, int flush));
  76602. local block_state deflate_fast OF((deflate_state *s, int flush));
  76603. #ifndef FASTEST
  76604. local block_state deflate_slow OF((deflate_state *s, int flush));
  76605. #endif
  76606. local void lm_init OF((deflate_state *s));
  76607. local void putShortMSB OF((deflate_state *s, uInt b));
  76608. local void flush_pending OF((z_streamp strm));
  76609. local int read_buf OF((z_streamp strm, Bytef *buf, unsigned size));
  76610. #ifndef FASTEST
  76611. #ifdef ASMV
  76612. void match_init OF((void)); /* asm code initialization */
  76613. uInt longest_match OF((deflate_state *s, IPos cur_match));
  76614. #else
  76615. local uInt longest_match OF((deflate_state *s, IPos cur_match));
  76616. #endif
  76617. #endif
  76618. local uInt longest_match_fast OF((deflate_state *s, IPos cur_match));
  76619. #ifdef DEBUG
  76620. local void check_match OF((deflate_state *s, IPos start, IPos match,
  76621. int length));
  76622. #endif
  76623. #define NIL 0
  76624. #ifndef TOO_FAR
  76625. # define TOO_FAR 4096
  76626. #endif
  76627. #define MIN_LOOKAHEAD (MAX_MATCH+MIN_MATCH+1)
  76628. typedef struct config_s {
  76629. ush good_length; /* reduce lazy search above this match length */
  76630. ush max_lazy; /* do not perform lazy search above this match length */
  76631. ush nice_length; /* quit search above this match length */
  76632. ush max_chain;
  76633. compress_func func;
  76634. } config;
  76635. #ifdef FASTEST
  76636. local const config configuration_table[2] = {
  76637. {0, 0, 0, 0, deflate_stored}, /* store only */
  76638. {4, 4, 8, 4, deflate_fast}}; /* max speed, no lazy matches */
  76639. #else
  76640. local const config configuration_table[10] = {
  76641. {0, 0, 0, 0, deflate_stored}, /* store only */
  76642. {4, 4, 8, 4, deflate_fast}, /* max speed, no lazy matches */
  76643. {4, 5, 16, 8, deflate_fast},
  76644. {4, 6, 32, 32, deflate_fast},
  76645. {4, 4, 16, 16, deflate_slow}, /* lazy matches */
  76646. {8, 16, 32, 32, deflate_slow},
  76647. {8, 16, 128, 128, deflate_slow},
  76648. {8, 32, 128, 256, deflate_slow},
  76649. {32, 128, 258, 1024, deflate_slow},
  76650. {32, 258, 258, 4096, deflate_slow}}; /* max compression */
  76651. #endif
  76652. #define EQUAL 0
  76653. #ifndef NO_DUMMY_DECL
  76654. struct static_tree_desc_s {int dummy;}; /* for buggy compilers */
  76655. #endif
  76656. #define UPDATE_HASH(s,h,c) (h = (((h)<<s->hash_shift) ^ (c)) & s->hash_mask)
  76657. #ifdef FASTEST
  76658. #define INSERT_STRING(s, str, match_head) \
  76659. (UPDATE_HASH(s, s->ins_h, s->window[(str) + (MIN_MATCH-1)]), \
  76660. match_head = s->head[s->ins_h], \
  76661. s->head[s->ins_h] = (Pos)(str))
  76662. #else
  76663. #define INSERT_STRING(s, str, match_head) \
  76664. (UPDATE_HASH(s, s->ins_h, s->window[(str) + (MIN_MATCH-1)]), \
  76665. match_head = s->prev[(str) & s->w_mask] = s->head[s->ins_h], \
  76666. s->head[s->ins_h] = (Pos)(str))
  76667. #endif
  76668. #define CLEAR_HASH(s) \
  76669. s->head[s->hash_size-1] = NIL; \
  76670. zmemzero((Bytef *)s->head, (unsigned)(s->hash_size-1)*sizeof(*s->head));
  76671. int ZEXPORT deflateInit_(z_streamp strm, int level, const char *version, int stream_size)
  76672. {
  76673. return deflateInit2_(strm, level, Z_DEFLATED, MAX_WBITS, DEF_MEM_LEVEL,
  76674. Z_DEFAULT_STRATEGY, version, stream_size);
  76675. }
  76676. int ZEXPORT deflateInit2_ (z_streamp strm, int level, int method, int windowBits, int memLevel, int strategy, const char *version, int stream_size)
  76677. {
  76678. deflate_state *s;
  76679. int wrap = 1;
  76680. static const char my_version[] = ZLIB_VERSION;
  76681. ushf *overlay;
  76682. if (version == Z_NULL || version[0] != my_version[0] ||
  76683. stream_size != sizeof(z_stream)) {
  76684. return Z_VERSION_ERROR;
  76685. }
  76686. if (strm == Z_NULL) return Z_STREAM_ERROR;
  76687. strm->msg = Z_NULL;
  76688. if (strm->zalloc == (alloc_func)0) {
  76689. strm->zalloc = zcalloc;
  76690. strm->opaque = (voidpf)0;
  76691. }
  76692. if (strm->zfree == (free_func)0) strm->zfree = zcfree;
  76693. #ifdef FASTEST
  76694. if (level != 0) level = 1;
  76695. #else
  76696. if (level == Z_DEFAULT_COMPRESSION) level = 6;
  76697. #endif
  76698. if (windowBits < 0) { /* suppress zlib wrapper */
  76699. wrap = 0;
  76700. windowBits = -windowBits;
  76701. }
  76702. #ifdef GZIP
  76703. else if (windowBits > 15) {
  76704. wrap = 2; /* write gzip wrapper instead */
  76705. windowBits -= 16;
  76706. }
  76707. #endif
  76708. if (memLevel < 1 || memLevel > MAX_MEM_LEVEL || method != Z_DEFLATED ||
  76709. windowBits < 8 || windowBits > 15 || level < 0 || level > 9 ||
  76710. strategy < 0 || strategy > Z_FIXED) {
  76711. return Z_STREAM_ERROR;
  76712. }
  76713. if (windowBits == 8) windowBits = 9; /* until 256-byte window bug fixed */
  76714. s = (deflate_state *) ZALLOC(strm, 1, sizeof(deflate_state));
  76715. if (s == Z_NULL) return Z_MEM_ERROR;
  76716. strm->state = (struct internal_state FAR *)s;
  76717. s->strm = strm;
  76718. s->wrap = wrap;
  76719. s->gzhead = Z_NULL;
  76720. s->w_bits = windowBits;
  76721. s->w_size = 1 << s->w_bits;
  76722. s->w_mask = s->w_size - 1;
  76723. s->hash_bits = memLevel + 7;
  76724. s->hash_size = 1 << s->hash_bits;
  76725. s->hash_mask = s->hash_size - 1;
  76726. s->hash_shift = ((s->hash_bits+MIN_MATCH-1)/MIN_MATCH);
  76727. s->window = (Bytef *) ZALLOC(strm, s->w_size, 2*sizeof(Byte));
  76728. s->prev = (Posf *) ZALLOC(strm, s->w_size, sizeof(Pos));
  76729. s->head = (Posf *) ZALLOC(strm, s->hash_size, sizeof(Pos));
  76730. s->lit_bufsize = 1 << (memLevel + 6); /* 16K elements by default */
  76731. overlay = (ushf *) ZALLOC(strm, s->lit_bufsize, sizeof(ush)+2);
  76732. s->pending_buf = (uchf *) overlay;
  76733. s->pending_buf_size = (ulg)s->lit_bufsize * (sizeof(ush)+2L);
  76734. if (s->window == Z_NULL || s->prev == Z_NULL || s->head == Z_NULL ||
  76735. s->pending_buf == Z_NULL) {
  76736. s->status = FINISH_STATE;
  76737. strm->msg = (char*)ERR_MSG(Z_MEM_ERROR);
  76738. deflateEnd (strm);
  76739. return Z_MEM_ERROR;
  76740. }
  76741. s->d_buf = overlay + s->lit_bufsize/sizeof(ush);
  76742. s->l_buf = s->pending_buf + (1+sizeof(ush))*s->lit_bufsize;
  76743. s->level = level;
  76744. s->strategy = strategy;
  76745. s->method = (Byte)method;
  76746. return deflateReset(strm);
  76747. }
  76748. int ZEXPORT deflateSetDictionary (z_streamp strm, const Bytef *dictionary, uInt dictLength)
  76749. {
  76750. deflate_state *s;
  76751. uInt length = dictLength;
  76752. uInt n;
  76753. IPos hash_head = 0;
  76754. if (strm == Z_NULL || strm->state == Z_NULL || dictionary == Z_NULL ||
  76755. strm->state->wrap == 2 ||
  76756. (strm->state->wrap == 1 && strm->state->status != INIT_STATE))
  76757. return Z_STREAM_ERROR;
  76758. s = strm->state;
  76759. if (s->wrap)
  76760. strm->adler = adler32(strm->adler, dictionary, dictLength);
  76761. if (length < MIN_MATCH) return Z_OK;
  76762. if (length > MAX_DIST(s)) {
  76763. length = MAX_DIST(s);
  76764. dictionary += dictLength - length; /* use the tail of the dictionary */
  76765. }
  76766. zmemcpy(s->window, dictionary, length);
  76767. s->strstart = length;
  76768. s->block_start = (long)length;
  76769. s->ins_h = s->window[0];
  76770. UPDATE_HASH(s, s->ins_h, s->window[1]);
  76771. for (n = 0; n <= length - MIN_MATCH; n++) {
  76772. INSERT_STRING(s, n, hash_head);
  76773. }
  76774. if (hash_head) hash_head = 0; /* to make compiler happy */
  76775. return Z_OK;
  76776. }
  76777. int ZEXPORT deflateReset (z_streamp strm)
  76778. {
  76779. deflate_state *s;
  76780. if (strm == Z_NULL || strm->state == Z_NULL ||
  76781. strm->zalloc == (alloc_func)0 || strm->zfree == (free_func)0) {
  76782. return Z_STREAM_ERROR;
  76783. }
  76784. strm->total_in = strm->total_out = 0;
  76785. strm->msg = Z_NULL; /* use zfree if we ever allocate msg dynamically */
  76786. strm->data_type = Z_UNKNOWN;
  76787. s = (deflate_state *)strm->state;
  76788. s->pending = 0;
  76789. s->pending_out = s->pending_buf;
  76790. if (s->wrap < 0) {
  76791. s->wrap = -s->wrap; /* was made negative by deflate(..., Z_FINISH); */
  76792. }
  76793. s->status = s->wrap ? INIT_STATE : BUSY_STATE;
  76794. strm->adler =
  76795. #ifdef GZIP
  76796. s->wrap == 2 ? crc32(0L, Z_NULL, 0) :
  76797. #endif
  76798. adler32(0L, Z_NULL, 0);
  76799. s->last_flush = Z_NO_FLUSH;
  76800. _tr_init(s);
  76801. lm_init(s);
  76802. return Z_OK;
  76803. }
  76804. int ZEXPORT deflateSetHeader (z_streamp strm, gz_headerp head)
  76805. {
  76806. if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
  76807. if (strm->state->wrap != 2) return Z_STREAM_ERROR;
  76808. strm->state->gzhead = head;
  76809. return Z_OK;
  76810. }
  76811. int ZEXPORT deflatePrime (z_streamp strm, int bits, int value)
  76812. {
  76813. if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
  76814. strm->state->bi_valid = bits;
  76815. strm->state->bi_buf = (ush)(value & ((1 << bits) - 1));
  76816. return Z_OK;
  76817. }
  76818. int ZEXPORT deflateParams (z_streamp strm, int level, int strategy)
  76819. {
  76820. deflate_state *s;
  76821. compress_func func;
  76822. int err = Z_OK;
  76823. if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
  76824. s = strm->state;
  76825. #ifdef FASTEST
  76826. if (level != 0) level = 1;
  76827. #else
  76828. if (level == Z_DEFAULT_COMPRESSION) level = 6;
  76829. #endif
  76830. if (level < 0 || level > 9 || strategy < 0 || strategy > Z_FIXED) {
  76831. return Z_STREAM_ERROR;
  76832. }
  76833. func = configuration_table[s->level].func;
  76834. if (func != configuration_table[level].func && strm->total_in != 0) {
  76835. err = deflate(strm, Z_PARTIAL_FLUSH);
  76836. }
  76837. if (s->level != level) {
  76838. s->level = level;
  76839. s->max_lazy_match = configuration_table[level].max_lazy;
  76840. s->good_match = configuration_table[level].good_length;
  76841. s->nice_match = configuration_table[level].nice_length;
  76842. s->max_chain_length = configuration_table[level].max_chain;
  76843. }
  76844. s->strategy = strategy;
  76845. return err;
  76846. }
  76847. int ZEXPORT deflateTune (z_streamp strm, int good_length, int max_lazy, int nice_length, int max_chain)
  76848. {
  76849. deflate_state *s;
  76850. if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
  76851. s = strm->state;
  76852. s->good_match = good_length;
  76853. s->max_lazy_match = max_lazy;
  76854. s->nice_match = nice_length;
  76855. s->max_chain_length = max_chain;
  76856. return Z_OK;
  76857. }
  76858. uLong ZEXPORT deflateBound (z_streamp strm, uLong sourceLen)
  76859. {
  76860. deflate_state *s;
  76861. uLong destLen;
  76862. destLen = sourceLen +
  76863. ((sourceLen + 7) >> 3) + ((sourceLen + 63) >> 6) + 11;
  76864. if (strm == Z_NULL || strm->state == Z_NULL)
  76865. return destLen;
  76866. s = strm->state;
  76867. if (s->w_bits != 15 || s->hash_bits != 8 + 7)
  76868. return destLen;
  76869. return compressBound(sourceLen);
  76870. }
  76871. local void putShortMSB (deflate_state *s, uInt b)
  76872. {
  76873. put_byte(s, (Byte)(b >> 8));
  76874. put_byte(s, (Byte)(b & 0xff));
  76875. }
  76876. local void flush_pending (z_streamp strm)
  76877. {
  76878. unsigned len = strm->state->pending;
  76879. if (len > strm->avail_out) len = strm->avail_out;
  76880. if (len == 0) return;
  76881. zmemcpy(strm->next_out, strm->state->pending_out, len);
  76882. strm->next_out += len;
  76883. strm->state->pending_out += len;
  76884. strm->total_out += len;
  76885. strm->avail_out -= len;
  76886. strm->state->pending -= len;
  76887. if (strm->state->pending == 0) {
  76888. strm->state->pending_out = strm->state->pending_buf;
  76889. }
  76890. }
  76891. int ZEXPORT deflate (z_streamp strm, int flush)
  76892. {
  76893. int old_flush; /* value of flush param for previous deflate call */
  76894. deflate_state *s;
  76895. if (strm == Z_NULL || strm->state == Z_NULL ||
  76896. flush > Z_FINISH || flush < 0) {
  76897. return Z_STREAM_ERROR;
  76898. }
  76899. s = strm->state;
  76900. if (strm->next_out == Z_NULL ||
  76901. (strm->next_in == Z_NULL && strm->avail_in != 0) ||
  76902. (s->status == FINISH_STATE && flush != Z_FINISH)) {
  76903. ERR_RETURN(strm, Z_STREAM_ERROR);
  76904. }
  76905. if (strm->avail_out == 0) ERR_RETURN(strm, Z_BUF_ERROR);
  76906. s->strm = strm; /* just in case */
  76907. old_flush = s->last_flush;
  76908. s->last_flush = flush;
  76909. if (s->status == INIT_STATE) {
  76910. #ifdef GZIP
  76911. if (s->wrap == 2) {
  76912. strm->adler = crc32(0L, Z_NULL, 0);
  76913. put_byte(s, 31);
  76914. put_byte(s, 139);
  76915. put_byte(s, 8);
  76916. if (s->gzhead == NULL) {
  76917. put_byte(s, 0);
  76918. put_byte(s, 0);
  76919. put_byte(s, 0);
  76920. put_byte(s, 0);
  76921. put_byte(s, 0);
  76922. put_byte(s, s->level == 9 ? 2 :
  76923. (s->strategy >= Z_HUFFMAN_ONLY || s->level < 2 ?
  76924. 4 : 0));
  76925. put_byte(s, OS_CODE);
  76926. s->status = BUSY_STATE;
  76927. }
  76928. else {
  76929. put_byte(s, (s->gzhead->text ? 1 : 0) +
  76930. (s->gzhead->hcrc ? 2 : 0) +
  76931. (s->gzhead->extra == Z_NULL ? 0 : 4) +
  76932. (s->gzhead->name == Z_NULL ? 0 : 8) +
  76933. (s->gzhead->comment == Z_NULL ? 0 : 16)
  76934. );
  76935. put_byte(s, (Byte)(s->gzhead->time & 0xff));
  76936. put_byte(s, (Byte)((s->gzhead->time >> 8) & 0xff));
  76937. put_byte(s, (Byte)((s->gzhead->time >> 16) & 0xff));
  76938. put_byte(s, (Byte)((s->gzhead->time >> 24) & 0xff));
  76939. put_byte(s, s->level == 9 ? 2 :
  76940. (s->strategy >= Z_HUFFMAN_ONLY || s->level < 2 ?
  76941. 4 : 0));
  76942. put_byte(s, s->gzhead->os & 0xff);
  76943. if (s->gzhead->extra != NULL) {
  76944. put_byte(s, s->gzhead->extra_len & 0xff);
  76945. put_byte(s, (s->gzhead->extra_len >> 8) & 0xff);
  76946. }
  76947. if (s->gzhead->hcrc)
  76948. strm->adler = crc32(strm->adler, s->pending_buf,
  76949. s->pending);
  76950. s->gzindex = 0;
  76951. s->status = EXTRA_STATE;
  76952. }
  76953. }
  76954. else
  76955. #endif
  76956. {
  76957. uInt header = (Z_DEFLATED + ((s->w_bits-8)<<4)) << 8;
  76958. uInt level_flags;
  76959. if (s->strategy >= Z_HUFFMAN_ONLY || s->level < 2)
  76960. level_flags = 0;
  76961. else if (s->level < 6)
  76962. level_flags = 1;
  76963. else if (s->level == 6)
  76964. level_flags = 2;
  76965. else
  76966. level_flags = 3;
  76967. header |= (level_flags << 6);
  76968. if (s->strstart != 0) header |= PRESET_DICT;
  76969. header += 31 - (header % 31);
  76970. s->status = BUSY_STATE;
  76971. putShortMSB(s, header);
  76972. if (s->strstart != 0) {
  76973. putShortMSB(s, (uInt)(strm->adler >> 16));
  76974. putShortMSB(s, (uInt)(strm->adler & 0xffff));
  76975. }
  76976. strm->adler = adler32(0L, Z_NULL, 0);
  76977. }
  76978. }
  76979. #ifdef GZIP
  76980. if (s->status == EXTRA_STATE) {
  76981. if (s->gzhead->extra != NULL) {
  76982. uInt beg = s->pending; /* start of bytes to update crc */
  76983. while (s->gzindex < (s->gzhead->extra_len & 0xffff)) {
  76984. if (s->pending == s->pending_buf_size) {
  76985. if (s->gzhead->hcrc && s->pending > beg)
  76986. strm->adler = crc32(strm->adler, s->pending_buf + beg,
  76987. s->pending - beg);
  76988. flush_pending(strm);
  76989. beg = s->pending;
  76990. if (s->pending == s->pending_buf_size)
  76991. break;
  76992. }
  76993. put_byte(s, s->gzhead->extra[s->gzindex]);
  76994. s->gzindex++;
  76995. }
  76996. if (s->gzhead->hcrc && s->pending > beg)
  76997. strm->adler = crc32(strm->adler, s->pending_buf + beg,
  76998. s->pending - beg);
  76999. if (s->gzindex == s->gzhead->extra_len) {
  77000. s->gzindex = 0;
  77001. s->status = NAME_STATE;
  77002. }
  77003. }
  77004. else
  77005. s->status = NAME_STATE;
  77006. }
  77007. if (s->status == NAME_STATE) {
  77008. if (s->gzhead->name != NULL) {
  77009. uInt beg = s->pending; /* start of bytes to update crc */
  77010. int val;
  77011. do {
  77012. if (s->pending == s->pending_buf_size) {
  77013. if (s->gzhead->hcrc && s->pending > beg)
  77014. strm->adler = crc32(strm->adler, s->pending_buf + beg,
  77015. s->pending - beg);
  77016. flush_pending(strm);
  77017. beg = s->pending;
  77018. if (s->pending == s->pending_buf_size) {
  77019. val = 1;
  77020. break;
  77021. }
  77022. }
  77023. val = s->gzhead->name[s->gzindex++];
  77024. put_byte(s, val);
  77025. } while (val != 0);
  77026. if (s->gzhead->hcrc && s->pending > beg)
  77027. strm->adler = crc32(strm->adler, s->pending_buf + beg,
  77028. s->pending - beg);
  77029. if (val == 0) {
  77030. s->gzindex = 0;
  77031. s->status = COMMENT_STATE;
  77032. }
  77033. }
  77034. else
  77035. s->status = COMMENT_STATE;
  77036. }
  77037. if (s->status == COMMENT_STATE) {
  77038. if (s->gzhead->comment != NULL) {
  77039. uInt beg = s->pending; /* start of bytes to update crc */
  77040. int val;
  77041. do {
  77042. if (s->pending == s->pending_buf_size) {
  77043. if (s->gzhead->hcrc && s->pending > beg)
  77044. strm->adler = crc32(strm->adler, s->pending_buf + beg,
  77045. s->pending - beg);
  77046. flush_pending(strm);
  77047. beg = s->pending;
  77048. if (s->pending == s->pending_buf_size) {
  77049. val = 1;
  77050. break;
  77051. }
  77052. }
  77053. val = s->gzhead->comment[s->gzindex++];
  77054. put_byte(s, val);
  77055. } while (val != 0);
  77056. if (s->gzhead->hcrc && s->pending > beg)
  77057. strm->adler = crc32(strm->adler, s->pending_buf + beg,
  77058. s->pending - beg);
  77059. if (val == 0)
  77060. s->status = HCRC_STATE;
  77061. }
  77062. else
  77063. s->status = HCRC_STATE;
  77064. }
  77065. if (s->status == HCRC_STATE) {
  77066. if (s->gzhead->hcrc) {
  77067. if (s->pending + 2 > s->pending_buf_size)
  77068. flush_pending(strm);
  77069. if (s->pending + 2 <= s->pending_buf_size) {
  77070. put_byte(s, (Byte)(strm->adler & 0xff));
  77071. put_byte(s, (Byte)((strm->adler >> 8) & 0xff));
  77072. strm->adler = crc32(0L, Z_NULL, 0);
  77073. s->status = BUSY_STATE;
  77074. }
  77075. }
  77076. else
  77077. s->status = BUSY_STATE;
  77078. }
  77079. #endif
  77080. if (s->pending != 0) {
  77081. flush_pending(strm);
  77082. if (strm->avail_out == 0) {
  77083. s->last_flush = -1;
  77084. return Z_OK;
  77085. }
  77086. } else if (strm->avail_in == 0 && flush <= old_flush &&
  77087. flush != Z_FINISH) {
  77088. ERR_RETURN(strm, Z_BUF_ERROR);
  77089. }
  77090. if (s->status == FINISH_STATE && strm->avail_in != 0) {
  77091. ERR_RETURN(strm, Z_BUF_ERROR);
  77092. }
  77093. if (strm->avail_in != 0 || s->lookahead != 0 ||
  77094. (flush != Z_NO_FLUSH && s->status != FINISH_STATE)) {
  77095. block_state bstate;
  77096. bstate = (*(configuration_table[s->level].func))(s, flush);
  77097. if (bstate == finish_started || bstate == finish_done) {
  77098. s->status = FINISH_STATE;
  77099. }
  77100. if (bstate == need_more || bstate == finish_started) {
  77101. if (strm->avail_out == 0) {
  77102. s->last_flush = -1; /* avoid BUF_ERROR next call, see above */
  77103. }
  77104. return Z_OK;
  77105. }
  77106. if (bstate == block_done) {
  77107. if (flush == Z_PARTIAL_FLUSH) {
  77108. _tr_align(s);
  77109. } else { /* FULL_FLUSH or SYNC_FLUSH */
  77110. _tr_stored_block(s, (char*)0, 0L, 0);
  77111. if (flush == Z_FULL_FLUSH) {
  77112. CLEAR_HASH(s); /* forget history */
  77113. }
  77114. }
  77115. flush_pending(strm);
  77116. if (strm->avail_out == 0) {
  77117. s->last_flush = -1; /* avoid BUF_ERROR at next call, see above */
  77118. return Z_OK;
  77119. }
  77120. }
  77121. }
  77122. Assert(strm->avail_out > 0, "bug2");
  77123. if (flush != Z_FINISH) return Z_OK;
  77124. if (s->wrap <= 0) return Z_STREAM_END;
  77125. #ifdef GZIP
  77126. if (s->wrap == 2) {
  77127. put_byte(s, (Byte)(strm->adler & 0xff));
  77128. put_byte(s, (Byte)((strm->adler >> 8) & 0xff));
  77129. put_byte(s, (Byte)((strm->adler >> 16) & 0xff));
  77130. put_byte(s, (Byte)((strm->adler >> 24) & 0xff));
  77131. put_byte(s, (Byte)(strm->total_in & 0xff));
  77132. put_byte(s, (Byte)((strm->total_in >> 8) & 0xff));
  77133. put_byte(s, (Byte)((strm->total_in >> 16) & 0xff));
  77134. put_byte(s, (Byte)((strm->total_in >> 24) & 0xff));
  77135. }
  77136. else
  77137. #endif
  77138. {
  77139. putShortMSB(s, (uInt)(strm->adler >> 16));
  77140. putShortMSB(s, (uInt)(strm->adler & 0xffff));
  77141. }
  77142. flush_pending(strm);
  77143. if (s->wrap > 0) s->wrap = -s->wrap; /* write the trailer only once! */
  77144. return s->pending != 0 ? Z_OK : Z_STREAM_END;
  77145. }
  77146. int ZEXPORT deflateEnd (z_streamp strm)
  77147. {
  77148. int status;
  77149. if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
  77150. status = strm->state->status;
  77151. if (status != INIT_STATE &&
  77152. status != EXTRA_STATE &&
  77153. status != NAME_STATE &&
  77154. status != COMMENT_STATE &&
  77155. status != HCRC_STATE &&
  77156. status != BUSY_STATE &&
  77157. status != FINISH_STATE) {
  77158. return Z_STREAM_ERROR;
  77159. }
  77160. TRY_FREE(strm, strm->state->pending_buf);
  77161. TRY_FREE(strm, strm->state->head);
  77162. TRY_FREE(strm, strm->state->prev);
  77163. TRY_FREE(strm, strm->state->window);
  77164. ZFREE(strm, strm->state);
  77165. strm->state = Z_NULL;
  77166. return status == BUSY_STATE ? Z_DATA_ERROR : Z_OK;
  77167. }
  77168. int ZEXPORT deflateCopy (z_streamp dest, z_streamp source)
  77169. {
  77170. #ifdef MAXSEG_64K
  77171. return Z_STREAM_ERROR;
  77172. #else
  77173. deflate_state *ds;
  77174. deflate_state *ss;
  77175. ushf *overlay;
  77176. if (source == Z_NULL || dest == Z_NULL || source->state == Z_NULL) {
  77177. return Z_STREAM_ERROR;
  77178. }
  77179. ss = source->state;
  77180. zmemcpy(dest, source, sizeof(z_stream));
  77181. ds = (deflate_state *) ZALLOC(dest, 1, sizeof(deflate_state));
  77182. if (ds == Z_NULL) return Z_MEM_ERROR;
  77183. dest->state = (struct internal_state FAR *) ds;
  77184. zmemcpy(ds, ss, sizeof(deflate_state));
  77185. ds->strm = dest;
  77186. ds->window = (Bytef *) ZALLOC(dest, ds->w_size, 2*sizeof(Byte));
  77187. ds->prev = (Posf *) ZALLOC(dest, ds->w_size, sizeof(Pos));
  77188. ds->head = (Posf *) ZALLOC(dest, ds->hash_size, sizeof(Pos));
  77189. overlay = (ushf *) ZALLOC(dest, ds->lit_bufsize, sizeof(ush)+2);
  77190. ds->pending_buf = (uchf *) overlay;
  77191. if (ds->window == Z_NULL || ds->prev == Z_NULL || ds->head == Z_NULL ||
  77192. ds->pending_buf == Z_NULL) {
  77193. deflateEnd (dest);
  77194. return Z_MEM_ERROR;
  77195. }
  77196. zmemcpy(ds->window, ss->window, ds->w_size * 2 * sizeof(Byte));
  77197. zmemcpy(ds->prev, ss->prev, ds->w_size * sizeof(Pos));
  77198. zmemcpy(ds->head, ss->head, ds->hash_size * sizeof(Pos));
  77199. zmemcpy(ds->pending_buf, ss->pending_buf, (uInt)ds->pending_buf_size);
  77200. ds->pending_out = ds->pending_buf + (ss->pending_out - ss->pending_buf);
  77201. ds->d_buf = overlay + ds->lit_bufsize/sizeof(ush);
  77202. ds->l_buf = ds->pending_buf + (1+sizeof(ush))*ds->lit_bufsize;
  77203. ds->l_desc.dyn_tree = ds->dyn_ltree;
  77204. ds->d_desc.dyn_tree = ds->dyn_dtree;
  77205. ds->bl_desc.dyn_tree = ds->bl_tree;
  77206. return Z_OK;
  77207. #endif /* MAXSEG_64K */
  77208. }
  77209. local int read_buf (z_streamp strm, Bytef *buf, unsigned size)
  77210. {
  77211. unsigned len = strm->avail_in;
  77212. if (len > size) len = size;
  77213. if (len == 0) return 0;
  77214. strm->avail_in -= len;
  77215. if (strm->state->wrap == 1) {
  77216. strm->adler = adler32(strm->adler, strm->next_in, len);
  77217. }
  77218. #ifdef GZIP
  77219. else if (strm->state->wrap == 2) {
  77220. strm->adler = crc32(strm->adler, strm->next_in, len);
  77221. }
  77222. #endif
  77223. zmemcpy(buf, strm->next_in, len);
  77224. strm->next_in += len;
  77225. strm->total_in += len;
  77226. return (int)len;
  77227. }
  77228. local void lm_init (deflate_state *s)
  77229. {
  77230. s->window_size = (ulg)2L*s->w_size;
  77231. CLEAR_HASH(s);
  77232. s->max_lazy_match = configuration_table[s->level].max_lazy;
  77233. s->good_match = configuration_table[s->level].good_length;
  77234. s->nice_match = configuration_table[s->level].nice_length;
  77235. s->max_chain_length = configuration_table[s->level].max_chain;
  77236. s->strstart = 0;
  77237. s->block_start = 0L;
  77238. s->lookahead = 0;
  77239. s->match_length = s->prev_length = MIN_MATCH-1;
  77240. s->match_available = 0;
  77241. s->ins_h = 0;
  77242. #ifndef FASTEST
  77243. #ifdef ASMV
  77244. match_init(); /* initialize the asm code */
  77245. #endif
  77246. #endif
  77247. }
  77248. #ifndef FASTEST
  77249. #ifndef ASMV
  77250. local uInt longest_match(deflate_state *s, IPos cur_match)
  77251. {
  77252. unsigned chain_length = s->max_chain_length;/* max hash chain length */
  77253. register Bytef *scan = s->window + s->strstart; /* current string */
  77254. register Bytef *match; /* matched string */
  77255. register int len; /* length of current match */
  77256. int best_len = s->prev_length; /* best match length so far */
  77257. int nice_match = s->nice_match; /* stop if match long enough */
  77258. IPos limit = s->strstart > (IPos)MAX_DIST(s) ?
  77259. s->strstart - (IPos)MAX_DIST(s) : NIL;
  77260. Posf *prev = s->prev;
  77261. uInt wmask = s->w_mask;
  77262. #ifdef UNALIGNED_OK
  77263. register Bytef *strend = s->window + s->strstart + MAX_MATCH - 1;
  77264. register ush scan_start = *(ushf*)scan;
  77265. register ush scan_end = *(ushf*)(scan+best_len-1);
  77266. #else
  77267. register Bytef *strend = s->window + s->strstart + MAX_MATCH;
  77268. register Byte scan_end1 = scan[best_len-1];
  77269. register Byte scan_end = scan[best_len];
  77270. #endif
  77271. Assert(s->hash_bits >= 8 && MAX_MATCH == 258, "Code too clever");
  77272. if (s->prev_length >= s->good_match) {
  77273. chain_length >>= 2;
  77274. }
  77275. if ((uInt)nice_match > s->lookahead) nice_match = s->lookahead;
  77276. Assert((ulg)s->strstart <= s->window_size-MIN_LOOKAHEAD, "need lookahead");
  77277. do {
  77278. Assert(cur_match < s->strstart, "no future");
  77279. match = s->window + cur_match;
  77280. #if (defined(UNALIGNED_OK) && MAX_MATCH == 258)
  77281. if (*(ushf*)(match+best_len-1) != scan_end ||
  77282. *(ushf*)match != scan_start) continue;
  77283. Assert(scan[2] == match[2], "scan[2]?");
  77284. scan++, match++;
  77285. do {
  77286. } while (*(ushf*)(scan+=2) == *(ushf*)(match+=2) &&
  77287. *(ushf*)(scan+=2) == *(ushf*)(match+=2) &&
  77288. *(ushf*)(scan+=2) == *(ushf*)(match+=2) &&
  77289. *(ushf*)(scan+=2) == *(ushf*)(match+=2) &&
  77290. scan < strend);
  77291. Assert(scan <= s->window+(unsigned)(s->window_size-1), "wild scan");
  77292. if (*scan == *match) scan++;
  77293. len = (MAX_MATCH - 1) - (int)(strend-scan);
  77294. scan = strend - (MAX_MATCH-1);
  77295. #else /* UNALIGNED_OK */
  77296. if (match[best_len] != scan_end ||
  77297. match[best_len-1] != scan_end1 ||
  77298. *match != *scan ||
  77299. *++match != scan[1]) continue;
  77300. scan += 2, match++;
  77301. Assert(*scan == *match, "match[2]?");
  77302. do {
  77303. } while (*++scan == *++match && *++scan == *++match &&
  77304. *++scan == *++match && *++scan == *++match &&
  77305. *++scan == *++match && *++scan == *++match &&
  77306. *++scan == *++match && *++scan == *++match &&
  77307. scan < strend);
  77308. Assert(scan <= s->window+(unsigned)(s->window_size-1), "wild scan");
  77309. len = MAX_MATCH - (int)(strend - scan);
  77310. scan = strend - MAX_MATCH;
  77311. #endif /* UNALIGNED_OK */
  77312. if (len > best_len) {
  77313. s->match_start = cur_match;
  77314. best_len = len;
  77315. if (len >= nice_match) break;
  77316. #ifdef UNALIGNED_OK
  77317. scan_end = *(ushf*)(scan+best_len-1);
  77318. #else
  77319. scan_end1 = scan[best_len-1];
  77320. scan_end = scan[best_len];
  77321. #endif
  77322. }
  77323. } while ((cur_match = prev[cur_match & wmask]) > limit
  77324. && --chain_length != 0);
  77325. if ((uInt)best_len <= s->lookahead) return (uInt)best_len;
  77326. return s->lookahead;
  77327. }
  77328. #endif /* ASMV */
  77329. #endif /* FASTEST */
  77330. local uInt longest_match_fast (deflate_state *s, IPos cur_match)
  77331. {
  77332. register Bytef *scan = s->window + s->strstart; /* current string */
  77333. register Bytef *match; /* matched string */
  77334. register int len; /* length of current match */
  77335. register Bytef *strend = s->window + s->strstart + MAX_MATCH;
  77336. Assert(s->hash_bits >= 8 && MAX_MATCH == 258, "Code too clever");
  77337. Assert((ulg)s->strstart <= s->window_size-MIN_LOOKAHEAD, "need lookahead");
  77338. Assert(cur_match < s->strstart, "no future");
  77339. match = s->window + cur_match;
  77340. if (match[0] != scan[0] || match[1] != scan[1]) return MIN_MATCH-1;
  77341. scan += 2, match += 2;
  77342. Assert(*scan == *match, "match[2]?");
  77343. do {
  77344. } while (*++scan == *++match && *++scan == *++match &&
  77345. *++scan == *++match && *++scan == *++match &&
  77346. *++scan == *++match && *++scan == *++match &&
  77347. *++scan == *++match && *++scan == *++match &&
  77348. scan < strend);
  77349. Assert(scan <= s->window+(unsigned)(s->window_size-1), "wild scan");
  77350. len = MAX_MATCH - (int)(strend - scan);
  77351. if (len < MIN_MATCH) return MIN_MATCH - 1;
  77352. s->match_start = cur_match;
  77353. return (uInt)len <= s->lookahead ? (uInt)len : s->lookahead;
  77354. }
  77355. #ifdef DEBUG
  77356. local void check_match(deflate_state *s, IPos start, IPos match, int length)
  77357. {
  77358. if (zmemcmp(s->window + match,
  77359. s->window + start, length) != EQUAL) {
  77360. fprintf(stderr, " start %u, match %u, length %d\n",
  77361. start, match, length);
  77362. do {
  77363. fprintf(stderr, "%c%c", s->window[match++], s->window[start++]);
  77364. } while (--length != 0);
  77365. z_error("invalid match");
  77366. }
  77367. if (z_verbose > 1) {
  77368. fprintf(stderr,"\\[%d,%d]", start-match, length);
  77369. do { putc(s->window[start++], stderr); } while (--length != 0);
  77370. }
  77371. }
  77372. #else
  77373. # define check_match(s, start, match, length)
  77374. #endif /* DEBUG */
  77375. local void fill_window (deflate_state *s)
  77376. {
  77377. register unsigned n, m;
  77378. register Posf *p;
  77379. unsigned more; /* Amount of free space at the end of the window. */
  77380. uInt wsize = s->w_size;
  77381. do {
  77382. more = (unsigned)(s->window_size -(ulg)s->lookahead -(ulg)s->strstart);
  77383. if (sizeof(int) <= 2) {
  77384. if (more == 0 && s->strstart == 0 && s->lookahead == 0) {
  77385. more = wsize;
  77386. } else if (more == (unsigned)(-1)) {
  77387. more--;
  77388. }
  77389. }
  77390. if (s->strstart >= wsize+MAX_DIST(s)) {
  77391. zmemcpy(s->window, s->window+wsize, (unsigned)wsize);
  77392. s->match_start -= wsize;
  77393. s->strstart -= wsize; /* we now have strstart >= MAX_DIST */
  77394. s->block_start -= (long) wsize;
  77395. n = s->hash_size;
  77396. p = &s->head[n];
  77397. do {
  77398. m = *--p;
  77399. *p = (Pos)(m >= wsize ? m-wsize : NIL);
  77400. } while (--n);
  77401. n = wsize;
  77402. #ifndef FASTEST
  77403. p = &s->prev[n];
  77404. do {
  77405. m = *--p;
  77406. *p = (Pos)(m >= wsize ? m-wsize : NIL);
  77407. } while (--n);
  77408. #endif
  77409. more += wsize;
  77410. }
  77411. if (s->strm->avail_in == 0) return;
  77412. Assert(more >= 2, "more < 2");
  77413. n = read_buf(s->strm, s->window + s->strstart + s->lookahead, more);
  77414. s->lookahead += n;
  77415. if (s->lookahead >= MIN_MATCH) {
  77416. s->ins_h = s->window[s->strstart];
  77417. UPDATE_HASH(s, s->ins_h, s->window[s->strstart+1]);
  77418. #if MIN_MATCH != 3
  77419. Call UPDATE_HASH() MIN_MATCH-3 more times
  77420. #endif
  77421. }
  77422. } while (s->lookahead < MIN_LOOKAHEAD && s->strm->avail_in != 0);
  77423. }
  77424. #define FLUSH_BLOCK_ONLY(s, eof) { \
  77425. _tr_flush_block(s, (s->block_start >= 0L ? \
  77426. (charf *)&s->window[(unsigned)s->block_start] : \
  77427. (charf *)Z_NULL), \
  77428. (ulg)((long)s->strstart - s->block_start), \
  77429. (eof)); \
  77430. s->block_start = s->strstart; \
  77431. flush_pending(s->strm); \
  77432. Tracev((stderr,"[FLUSH]")); \
  77433. }
  77434. #define FLUSH_BLOCK(s, eof) { \
  77435. FLUSH_BLOCK_ONLY(s, eof); \
  77436. if (s->strm->avail_out == 0) return (eof) ? finish_started : need_more; \
  77437. }
  77438. local block_state deflate_stored(deflate_state *s, int flush)
  77439. {
  77440. ulg max_block_size = 0xffff;
  77441. ulg max_start;
  77442. if (max_block_size > s->pending_buf_size - 5) {
  77443. max_block_size = s->pending_buf_size - 5;
  77444. }
  77445. for (;;) {
  77446. if (s->lookahead <= 1) {
  77447. Assert(s->strstart < s->w_size+MAX_DIST(s) ||
  77448. s->block_start >= (long)s->w_size, "slide too late");
  77449. fill_window(s);
  77450. if (s->lookahead == 0 && flush == Z_NO_FLUSH) return need_more;
  77451. if (s->lookahead == 0) break; /* flush the current block */
  77452. }
  77453. Assert(s->block_start >= 0L, "block gone");
  77454. s->strstart += s->lookahead;
  77455. s->lookahead = 0;
  77456. max_start = s->block_start + max_block_size;
  77457. if (s->strstart == 0 || (ulg)s->strstart >= max_start) {
  77458. s->lookahead = (uInt)(s->strstart - max_start);
  77459. s->strstart = (uInt)max_start;
  77460. FLUSH_BLOCK(s, 0);
  77461. }
  77462. if (s->strstart - (uInt)s->block_start >= MAX_DIST(s)) {
  77463. FLUSH_BLOCK(s, 0);
  77464. }
  77465. }
  77466. FLUSH_BLOCK(s, flush == Z_FINISH);
  77467. return flush == Z_FINISH ? finish_done : block_done;
  77468. }
  77469. local block_state deflate_fast(deflate_state *s, int flush)
  77470. {
  77471. IPos hash_head = NIL; /* head of the hash chain */
  77472. int bflush; /* set if current block must be flushed */
  77473. for (;;) {
  77474. if (s->lookahead < MIN_LOOKAHEAD) {
  77475. fill_window(s);
  77476. if (s->lookahead < MIN_LOOKAHEAD && flush == Z_NO_FLUSH) {
  77477. return need_more;
  77478. }
  77479. if (s->lookahead == 0) break; /* flush the current block */
  77480. }
  77481. if (s->lookahead >= MIN_MATCH) {
  77482. INSERT_STRING(s, s->strstart, hash_head);
  77483. }
  77484. if (hash_head != NIL && s->strstart - hash_head <= MAX_DIST(s)) {
  77485. #ifdef FASTEST
  77486. if ((s->strategy != Z_HUFFMAN_ONLY && s->strategy != Z_RLE) ||
  77487. (s->strategy == Z_RLE && s->strstart - hash_head == 1)) {
  77488. s->match_length = longest_match_fast (s, hash_head);
  77489. }
  77490. #else
  77491. if (s->strategy != Z_HUFFMAN_ONLY && s->strategy != Z_RLE) {
  77492. s->match_length = longest_match (s, hash_head);
  77493. } else if (s->strategy == Z_RLE && s->strstart - hash_head == 1) {
  77494. s->match_length = longest_match_fast (s, hash_head);
  77495. }
  77496. #endif
  77497. }
  77498. if (s->match_length >= MIN_MATCH) {
  77499. check_match(s, s->strstart, s->match_start, s->match_length);
  77500. _tr_tally_dist(s, s->strstart - s->match_start,
  77501. s->match_length - MIN_MATCH, bflush);
  77502. s->lookahead -= s->match_length;
  77503. #ifndef FASTEST
  77504. if (s->match_length <= s->max_insert_length &&
  77505. s->lookahead >= MIN_MATCH) {
  77506. s->match_length--; /* string at strstart already in table */
  77507. do {
  77508. s->strstart++;
  77509. INSERT_STRING(s, s->strstart, hash_head);
  77510. } while (--s->match_length != 0);
  77511. s->strstart++;
  77512. } else
  77513. #endif
  77514. {
  77515. s->strstart += s->match_length;
  77516. s->match_length = 0;
  77517. s->ins_h = s->window[s->strstart];
  77518. UPDATE_HASH(s, s->ins_h, s->window[s->strstart+1]);
  77519. #if MIN_MATCH != 3
  77520. Call UPDATE_HASH() MIN_MATCH-3 more times
  77521. #endif
  77522. }
  77523. } else {
  77524. Tracevv((stderr,"%c", s->window[s->strstart]));
  77525. _tr_tally_lit (s, s->window[s->strstart], bflush);
  77526. s->lookahead--;
  77527. s->strstart++;
  77528. }
  77529. if (bflush) FLUSH_BLOCK(s, 0);
  77530. }
  77531. FLUSH_BLOCK(s, flush == Z_FINISH);
  77532. return flush == Z_FINISH ? finish_done : block_done;
  77533. }
  77534. #ifndef FASTEST
  77535. local block_state deflate_slow(deflate_state *s, int flush)
  77536. {
  77537. IPos hash_head = NIL; /* head of hash chain */
  77538. int bflush; /* set if current block must be flushed */
  77539. for (;;) {
  77540. if (s->lookahead < MIN_LOOKAHEAD) {
  77541. fill_window(s);
  77542. if (s->lookahead < MIN_LOOKAHEAD && flush == Z_NO_FLUSH) {
  77543. return need_more;
  77544. }
  77545. if (s->lookahead == 0) break; /* flush the current block */
  77546. }
  77547. if (s->lookahead >= MIN_MATCH) {
  77548. INSERT_STRING(s, s->strstart, hash_head);
  77549. }
  77550. s->prev_length = s->match_length, s->prev_match = s->match_start;
  77551. s->match_length = MIN_MATCH-1;
  77552. if (hash_head != NIL && s->prev_length < s->max_lazy_match &&
  77553. s->strstart - hash_head <= MAX_DIST(s)) {
  77554. if (s->strategy != Z_HUFFMAN_ONLY && s->strategy != Z_RLE) {
  77555. s->match_length = longest_match (s, hash_head);
  77556. } else if (s->strategy == Z_RLE && s->strstart - hash_head == 1) {
  77557. s->match_length = longest_match_fast (s, hash_head);
  77558. }
  77559. if (s->match_length <= 5 && (s->strategy == Z_FILTERED
  77560. #if TOO_FAR <= 32767
  77561. || (s->match_length == MIN_MATCH &&
  77562. s->strstart - s->match_start > TOO_FAR)
  77563. #endif
  77564. )) {
  77565. s->match_length = MIN_MATCH-1;
  77566. }
  77567. }
  77568. if (s->prev_length >= MIN_MATCH && s->match_length <= s->prev_length) {
  77569. uInt max_insert = s->strstart + s->lookahead - MIN_MATCH;
  77570. check_match(s, s->strstart-1, s->prev_match, s->prev_length);
  77571. _tr_tally_dist(s, s->strstart -1 - s->prev_match,
  77572. s->prev_length - MIN_MATCH, bflush);
  77573. s->lookahead -= s->prev_length-1;
  77574. s->prev_length -= 2;
  77575. do {
  77576. if (++s->strstart <= max_insert) {
  77577. INSERT_STRING(s, s->strstart, hash_head);
  77578. }
  77579. } while (--s->prev_length != 0);
  77580. s->match_available = 0;
  77581. s->match_length = MIN_MATCH-1;
  77582. s->strstart++;
  77583. if (bflush) FLUSH_BLOCK(s, 0);
  77584. } else if (s->match_available) {
  77585. Tracevv((stderr,"%c", s->window[s->strstart-1]));
  77586. _tr_tally_lit(s, s->window[s->strstart-1], bflush);
  77587. if (bflush) {
  77588. FLUSH_BLOCK_ONLY(s, 0);
  77589. }
  77590. s->strstart++;
  77591. s->lookahead--;
  77592. if (s->strm->avail_out == 0) return need_more;
  77593. } else {
  77594. s->match_available = 1;
  77595. s->strstart++;
  77596. s->lookahead--;
  77597. }
  77598. }
  77599. Assert (flush != Z_NO_FLUSH, "no flush?");
  77600. if (s->match_available) {
  77601. Tracevv((stderr,"%c", s->window[s->strstart-1]));
  77602. _tr_tally_lit(s, s->window[s->strstart-1], bflush);
  77603. s->match_available = 0;
  77604. }
  77605. FLUSH_BLOCK(s, flush == Z_FINISH);
  77606. return flush == Z_FINISH ? finish_done : block_done;
  77607. }
  77608. #endif /* FASTEST */
  77609. #if 0
  77610. local block_state deflate_rle(s, flush)
  77611. deflate_state *s;
  77612. int flush;
  77613. {
  77614. int bflush; /* set if current block must be flushed */
  77615. uInt run; /* length of run */
  77616. uInt max; /* maximum length of run */
  77617. uInt prev; /* byte at distance one to match */
  77618. Bytef *scan; /* scan for end of run */
  77619. for (;;) {
  77620. if (s->lookahead < MAX_MATCH) {
  77621. fill_window(s);
  77622. if (s->lookahead < MAX_MATCH && flush == Z_NO_FLUSH) {
  77623. return need_more;
  77624. }
  77625. if (s->lookahead == 0) break; /* flush the current block */
  77626. }
  77627. run = 0;
  77628. if (s->strstart > 0) { /* if there is a previous byte, that is */
  77629. max = s->lookahead < MAX_MATCH ? s->lookahead : MAX_MATCH;
  77630. scan = s->window + s->strstart - 1;
  77631. prev = *scan++;
  77632. do {
  77633. if (*scan++ != prev)
  77634. break;
  77635. } while (++run < max);
  77636. }
  77637. if (run >= MIN_MATCH) {
  77638. check_match(s, s->strstart, s->strstart - 1, run);
  77639. _tr_tally_dist(s, 1, run - MIN_MATCH, bflush);
  77640. s->lookahead -= run;
  77641. s->strstart += run;
  77642. } else {
  77643. Tracevv((stderr,"%c", s->window[s->strstart]));
  77644. _tr_tally_lit (s, s->window[s->strstart], bflush);
  77645. s->lookahead--;
  77646. s->strstart++;
  77647. }
  77648. if (bflush) FLUSH_BLOCK(s, 0);
  77649. }
  77650. FLUSH_BLOCK(s, flush == Z_FINISH);
  77651. return flush == Z_FINISH ? finish_done : block_done;
  77652. }
  77653. #endif
  77654. /*** End of inlined file: deflate.c ***/
  77655. /*** Start of inlined file: inffast.c ***/
  77656. /*** Start of inlined file: inftrees.h ***/
  77657. #ifndef _INFTREES_H_
  77658. #define _INFTREES_H_
  77659. typedef struct {
  77660. unsigned char op; /* operation, extra bits, table bits */
  77661. unsigned char bits; /* bits in this part of the code */
  77662. unsigned short val; /* offset in table or code value */
  77663. } code;
  77664. #define ENOUGH 2048
  77665. #define MAXD 592
  77666. typedef enum {
  77667. CODES,
  77668. LENS,
  77669. DISTS
  77670. } codetype;
  77671. extern int inflate_table OF((codetype type, unsigned short FAR *lens,
  77672. unsigned codes, code FAR * FAR *table,
  77673. unsigned FAR *bits, unsigned short FAR *work));
  77674. #endif
  77675. /*** End of inlined file: inftrees.h ***/
  77676. /*** Start of inlined file: inflate.h ***/
  77677. #ifndef _INFLATE_H_
  77678. #define _INFLATE_H_
  77679. #ifndef NO_GZIP
  77680. # define GUNZIP
  77681. #endif
  77682. typedef enum {
  77683. HEAD, /* i: waiting for magic header */
  77684. FLAGS, /* i: waiting for method and flags (gzip) */
  77685. TIME, /* i: waiting for modification time (gzip) */
  77686. OS, /* i: waiting for extra flags and operating system (gzip) */
  77687. EXLEN, /* i: waiting for extra length (gzip) */
  77688. EXTRA, /* i: waiting for extra bytes (gzip) */
  77689. NAME, /* i: waiting for end of file name (gzip) */
  77690. COMMENT, /* i: waiting for end of comment (gzip) */
  77691. HCRC, /* i: waiting for header crc (gzip) */
  77692. DICTID, /* i: waiting for dictionary check value */
  77693. DICT, /* waiting for inflateSetDictionary() call */
  77694. TYPE, /* i: waiting for type bits, including last-flag bit */
  77695. TYPEDO, /* i: same, but skip check to exit inflate on new block */
  77696. STORED, /* i: waiting for stored size (length and complement) */
  77697. COPY, /* i/o: waiting for input or output to copy stored block */
  77698. TABLE, /* i: waiting for dynamic block table lengths */
  77699. LENLENS, /* i: waiting for code length code lengths */
  77700. CODELENS, /* i: waiting for length/lit and distance code lengths */
  77701. LEN, /* i: waiting for length/lit code */
  77702. LENEXT, /* i: waiting for length extra bits */
  77703. DIST, /* i: waiting for distance code */
  77704. DISTEXT, /* i: waiting for distance extra bits */
  77705. MATCH, /* o: waiting for output space to copy string */
  77706. LIT, /* o: waiting for output space to write literal */
  77707. CHECK, /* i: waiting for 32-bit check value */
  77708. LENGTH, /* i: waiting for 32-bit length (gzip) */
  77709. DONE, /* finished check, done -- remain here until reset */
  77710. BAD, /* got a data error -- remain here until reset */
  77711. MEM, /* got an inflate() memory error -- remain here until reset */
  77712. SYNC /* looking for synchronization bytes to restart inflate() */
  77713. } inflate_mode;
  77714. struct inflate_state {
  77715. inflate_mode mode; /* current inflate mode */
  77716. int last; /* true if processing last block */
  77717. int wrap; /* bit 0 true for zlib, bit 1 true for gzip */
  77718. int havedict; /* true if dictionary provided */
  77719. int flags; /* gzip header method and flags (0 if zlib) */
  77720. unsigned dmax; /* zlib header max distance (INFLATE_STRICT) */
  77721. unsigned long check; /* protected copy of check value */
  77722. unsigned long total; /* protected copy of output count */
  77723. gz_headerp head; /* where to save gzip header information */
  77724. unsigned wbits; /* log base 2 of requested window size */
  77725. unsigned wsize; /* window size or zero if not using window */
  77726. unsigned whave; /* valid bytes in the window */
  77727. unsigned write; /* window write index */
  77728. unsigned char FAR *window; /* allocated sliding window, if needed */
  77729. unsigned long hold; /* input bit accumulator */
  77730. unsigned bits; /* number of bits in "in" */
  77731. unsigned length; /* literal or length of data to copy */
  77732. unsigned offset; /* distance back to copy string from */
  77733. unsigned extra; /* extra bits needed */
  77734. code const FAR *lencode; /* starting table for length/literal codes */
  77735. code const FAR *distcode; /* starting table for distance codes */
  77736. unsigned lenbits; /* index bits for lencode */
  77737. unsigned distbits; /* index bits for distcode */
  77738. unsigned ncode; /* number of code length code lengths */
  77739. unsigned nlen; /* number of length code lengths */
  77740. unsigned ndist; /* number of distance code lengths */
  77741. unsigned have; /* number of code lengths in lens[] */
  77742. code FAR *next; /* next available space in codes[] */
  77743. unsigned short lens[320]; /* temporary storage for code lengths */
  77744. unsigned short work[288]; /* work area for code table building */
  77745. code codes[ENOUGH]; /* space for code tables */
  77746. };
  77747. #endif
  77748. /*** End of inlined file: inflate.h ***/
  77749. /*** Start of inlined file: inffast.h ***/
  77750. void inflate_fast OF((z_streamp strm, unsigned start));
  77751. /*** End of inlined file: inffast.h ***/
  77752. #ifndef ASMINF
  77753. #ifdef POSTINC
  77754. # define OFF 0
  77755. # define PUP(a) *(a)++
  77756. #else
  77757. # define OFF 1
  77758. # define PUP(a) *++(a)
  77759. #endif
  77760. void inflate_fast (z_streamp strm, unsigned start)
  77761. {
  77762. struct inflate_state FAR *state;
  77763. unsigned char FAR *in; /* local strm->next_in */
  77764. unsigned char FAR *last; /* while in < last, enough input available */
  77765. unsigned char FAR *out; /* local strm->next_out */
  77766. unsigned char FAR *beg; /* inflate()'s initial strm->next_out */
  77767. unsigned char FAR *end; /* while out < end, enough space available */
  77768. #ifdef INFLATE_STRICT
  77769. unsigned dmax; /* maximum distance from zlib header */
  77770. #endif
  77771. unsigned wsize; /* window size or zero if not using window */
  77772. unsigned whave; /* valid bytes in the window */
  77773. unsigned write; /* window write index */
  77774. unsigned char FAR *window; /* allocated sliding window, if wsize != 0 */
  77775. unsigned long hold; /* local strm->hold */
  77776. unsigned bits; /* local strm->bits */
  77777. code const FAR *lcode; /* local strm->lencode */
  77778. code const FAR *dcode; /* local strm->distcode */
  77779. unsigned lmask; /* mask for first level of length codes */
  77780. unsigned dmask; /* mask for first level of distance codes */
  77781. code thisx; /* retrieved table entry */
  77782. unsigned op; /* code bits, operation, extra bits, or */
  77783. unsigned len; /* match length, unused bytes */
  77784. unsigned dist; /* match distance */
  77785. unsigned char FAR *from; /* where to copy match from */
  77786. state = (struct inflate_state FAR *)strm->state;
  77787. in = strm->next_in - OFF;
  77788. last = in + (strm->avail_in - 5);
  77789. out = strm->next_out - OFF;
  77790. beg = out - (start - strm->avail_out);
  77791. end = out + (strm->avail_out - 257);
  77792. #ifdef INFLATE_STRICT
  77793. dmax = state->dmax;
  77794. #endif
  77795. wsize = state->wsize;
  77796. whave = state->whave;
  77797. write = state->write;
  77798. window = state->window;
  77799. hold = state->hold;
  77800. bits = state->bits;
  77801. lcode = state->lencode;
  77802. dcode = state->distcode;
  77803. lmask = (1U << state->lenbits) - 1;
  77804. dmask = (1U << state->distbits) - 1;
  77805. do {
  77806. if (bits < 15) {
  77807. hold += (unsigned long)(PUP(in)) << bits;
  77808. bits += 8;
  77809. hold += (unsigned long)(PUP(in)) << bits;
  77810. bits += 8;
  77811. }
  77812. thisx = lcode[hold & lmask];
  77813. dolen:
  77814. op = (unsigned)(thisx.bits);
  77815. hold >>= op;
  77816. bits -= op;
  77817. op = (unsigned)(thisx.op);
  77818. if (op == 0) { /* literal */
  77819. Tracevv((stderr, thisx.val >= 0x20 && thisx.val < 0x7f ?
  77820. "inflate: literal '%c'\n" :
  77821. "inflate: literal 0x%02x\n", thisx.val));
  77822. PUP(out) = (unsigned char)(thisx.val);
  77823. }
  77824. else if (op & 16) { /* length base */
  77825. len = (unsigned)(thisx.val);
  77826. op &= 15; /* number of extra bits */
  77827. if (op) {
  77828. if (bits < op) {
  77829. hold += (unsigned long)(PUP(in)) << bits;
  77830. bits += 8;
  77831. }
  77832. len += (unsigned)hold & ((1U << op) - 1);
  77833. hold >>= op;
  77834. bits -= op;
  77835. }
  77836. Tracevv((stderr, "inflate: length %u\n", len));
  77837. if (bits < 15) {
  77838. hold += (unsigned long)(PUP(in)) << bits;
  77839. bits += 8;
  77840. hold += (unsigned long)(PUP(in)) << bits;
  77841. bits += 8;
  77842. }
  77843. thisx = dcode[hold & dmask];
  77844. dodist:
  77845. op = (unsigned)(thisx.bits);
  77846. hold >>= op;
  77847. bits -= op;
  77848. op = (unsigned)(thisx.op);
  77849. if (op & 16) { /* distance base */
  77850. dist = (unsigned)(thisx.val);
  77851. op &= 15; /* number of extra bits */
  77852. if (bits < op) {
  77853. hold += (unsigned long)(PUP(in)) << bits;
  77854. bits += 8;
  77855. if (bits < op) {
  77856. hold += (unsigned long)(PUP(in)) << bits;
  77857. bits += 8;
  77858. }
  77859. }
  77860. dist += (unsigned)hold & ((1U << op) - 1);
  77861. #ifdef INFLATE_STRICT
  77862. if (dist > dmax) {
  77863. strm->msg = (char *)"invalid distance too far back";
  77864. state->mode = BAD;
  77865. break;
  77866. }
  77867. #endif
  77868. hold >>= op;
  77869. bits -= op;
  77870. Tracevv((stderr, "inflate: distance %u\n", dist));
  77871. op = (unsigned)(out - beg); /* max distance in output */
  77872. if (dist > op) { /* see if copy from window */
  77873. op = dist - op; /* distance back in window */
  77874. if (op > whave) {
  77875. strm->msg = (char *)"invalid distance too far back";
  77876. state->mode = BAD;
  77877. break;
  77878. }
  77879. from = window - OFF;
  77880. if (write == 0) { /* very common case */
  77881. from += wsize - op;
  77882. if (op < len) { /* some from window */
  77883. len -= op;
  77884. do {
  77885. PUP(out) = PUP(from);
  77886. } while (--op);
  77887. from = out - dist; /* rest from output */
  77888. }
  77889. }
  77890. else if (write < op) { /* wrap around window */
  77891. from += wsize + write - op;
  77892. op -= write;
  77893. if (op < len) { /* some from end of window */
  77894. len -= op;
  77895. do {
  77896. PUP(out) = PUP(from);
  77897. } while (--op);
  77898. from = window - OFF;
  77899. if (write < len) { /* some from start of window */
  77900. op = write;
  77901. len -= op;
  77902. do {
  77903. PUP(out) = PUP(from);
  77904. } while (--op);
  77905. from = out - dist; /* rest from output */
  77906. }
  77907. }
  77908. }
  77909. else { /* contiguous in window */
  77910. from += write - op;
  77911. if (op < len) { /* some from window */
  77912. len -= op;
  77913. do {
  77914. PUP(out) = PUP(from);
  77915. } while (--op);
  77916. from = out - dist; /* rest from output */
  77917. }
  77918. }
  77919. while (len > 2) {
  77920. PUP(out) = PUP(from);
  77921. PUP(out) = PUP(from);
  77922. PUP(out) = PUP(from);
  77923. len -= 3;
  77924. }
  77925. if (len) {
  77926. PUP(out) = PUP(from);
  77927. if (len > 1)
  77928. PUP(out) = PUP(from);
  77929. }
  77930. }
  77931. else {
  77932. from = out - dist; /* copy direct from output */
  77933. do { /* minimum length is three */
  77934. PUP(out) = PUP(from);
  77935. PUP(out) = PUP(from);
  77936. PUP(out) = PUP(from);
  77937. len -= 3;
  77938. } while (len > 2);
  77939. if (len) {
  77940. PUP(out) = PUP(from);
  77941. if (len > 1)
  77942. PUP(out) = PUP(from);
  77943. }
  77944. }
  77945. }
  77946. else if ((op & 64) == 0) { /* 2nd level distance code */
  77947. thisx = dcode[thisx.val + (hold & ((1U << op) - 1))];
  77948. goto dodist;
  77949. }
  77950. else {
  77951. strm->msg = (char *)"invalid distance code";
  77952. state->mode = BAD;
  77953. break;
  77954. }
  77955. }
  77956. else if ((op & 64) == 0) { /* 2nd level length code */
  77957. thisx = lcode[thisx.val + (hold & ((1U << op) - 1))];
  77958. goto dolen;
  77959. }
  77960. else if (op & 32) { /* end-of-block */
  77961. Tracevv((stderr, "inflate: end of block\n"));
  77962. state->mode = TYPE;
  77963. break;
  77964. }
  77965. else {
  77966. strm->msg = (char *)"invalid literal/length code";
  77967. state->mode = BAD;
  77968. break;
  77969. }
  77970. } while (in < last && out < end);
  77971. len = bits >> 3;
  77972. in -= len;
  77973. bits -= len << 3;
  77974. hold &= (1U << bits) - 1;
  77975. strm->next_in = in + OFF;
  77976. strm->next_out = out + OFF;
  77977. strm->avail_in = (unsigned)(in < last ? 5 + (last - in) : 5 - (in - last));
  77978. strm->avail_out = (unsigned)(out < end ?
  77979. 257 + (end - out) : 257 - (out - end));
  77980. state->hold = hold;
  77981. state->bits = bits;
  77982. return;
  77983. }
  77984. #endif /* !ASMINF */
  77985. /*** End of inlined file: inffast.c ***/
  77986. #undef PULLBYTE
  77987. #undef LOAD
  77988. #undef RESTORE
  77989. #undef INITBITS
  77990. #undef NEEDBITS
  77991. #undef DROPBITS
  77992. #undef BYTEBITS
  77993. /*** Start of inlined file: inflate.c ***/
  77994. /*** Start of inlined file: inffast.h ***/
  77995. void inflate_fast OF((z_streamp strm, unsigned start));
  77996. /*** End of inlined file: inffast.h ***/
  77997. #ifdef MAKEFIXED
  77998. # ifndef BUILDFIXED
  77999. # define BUILDFIXED
  78000. # endif
  78001. #endif
  78002. local void fixedtables OF((struct inflate_state FAR *state));
  78003. local int updatewindow OF((z_streamp strm, unsigned out));
  78004. #ifdef BUILDFIXED
  78005. void makefixed OF((void));
  78006. #endif
  78007. local unsigned syncsearch OF((unsigned FAR *have, unsigned char FAR *buf,
  78008. unsigned len));
  78009. int ZEXPORT inflateReset (z_streamp strm)
  78010. {
  78011. struct inflate_state FAR *state;
  78012. if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
  78013. state = (struct inflate_state FAR *)strm->state;
  78014. strm->total_in = strm->total_out = state->total = 0;
  78015. strm->msg = Z_NULL;
  78016. strm->adler = 1; /* to support ill-conceived Java test suite */
  78017. state->mode = HEAD;
  78018. state->last = 0;
  78019. state->havedict = 0;
  78020. state->dmax = 32768U;
  78021. state->head = Z_NULL;
  78022. state->wsize = 0;
  78023. state->whave = 0;
  78024. state->write = 0;
  78025. state->hold = 0;
  78026. state->bits = 0;
  78027. state->lencode = state->distcode = state->next = state->codes;
  78028. Tracev((stderr, "inflate: reset\n"));
  78029. return Z_OK;
  78030. }
  78031. int ZEXPORT inflatePrime (z_streamp strm, int bits, int value)
  78032. {
  78033. struct inflate_state FAR *state;
  78034. if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
  78035. state = (struct inflate_state FAR *)strm->state;
  78036. if (bits > 16 || state->bits + bits > 32) return Z_STREAM_ERROR;
  78037. value &= (1L << bits) - 1;
  78038. state->hold += value << state->bits;
  78039. state->bits += bits;
  78040. return Z_OK;
  78041. }
  78042. int ZEXPORT inflateInit2_(z_streamp strm, int windowBits, const char *version, int stream_size)
  78043. {
  78044. struct inflate_state FAR *state;
  78045. if (version == Z_NULL || version[0] != ZLIB_VERSION[0] ||
  78046. stream_size != (int)(sizeof(z_stream)))
  78047. return Z_VERSION_ERROR;
  78048. if (strm == Z_NULL) return Z_STREAM_ERROR;
  78049. strm->msg = Z_NULL; /* in case we return an error */
  78050. if (strm->zalloc == (alloc_func)0) {
  78051. strm->zalloc = zcalloc;
  78052. strm->opaque = (voidpf)0;
  78053. }
  78054. if (strm->zfree == (free_func)0) strm->zfree = zcfree;
  78055. state = (struct inflate_state FAR *)
  78056. ZALLOC(strm, 1, sizeof(struct inflate_state));
  78057. if (state == Z_NULL) return Z_MEM_ERROR;
  78058. Tracev((stderr, "inflate: allocated\n"));
  78059. strm->state = (struct internal_state FAR *)state;
  78060. if (windowBits < 0) {
  78061. state->wrap = 0;
  78062. windowBits = -windowBits;
  78063. }
  78064. else {
  78065. state->wrap = (windowBits >> 4) + 1;
  78066. #ifdef GUNZIP
  78067. if (windowBits < 48) windowBits &= 15;
  78068. #endif
  78069. }
  78070. if (windowBits < 8 || windowBits > 15) {
  78071. ZFREE(strm, state);
  78072. strm->state = Z_NULL;
  78073. return Z_STREAM_ERROR;
  78074. }
  78075. state->wbits = (unsigned)windowBits;
  78076. state->window = Z_NULL;
  78077. return inflateReset(strm);
  78078. }
  78079. int ZEXPORT inflateInit_ (z_streamp strm, const char *version, int stream_size)
  78080. {
  78081. return inflateInit2_(strm, DEF_WBITS, version, stream_size);
  78082. }
  78083. local void fixedtables (struct inflate_state FAR *state)
  78084. {
  78085. #ifdef BUILDFIXED
  78086. static int virgin = 1;
  78087. static code *lenfix, *distfix;
  78088. static code fixed[544];
  78089. if (virgin) {
  78090. unsigned sym, bits;
  78091. static code *next;
  78092. sym = 0;
  78093. while (sym < 144) state->lens[sym++] = 8;
  78094. while (sym < 256) state->lens[sym++] = 9;
  78095. while (sym < 280) state->lens[sym++] = 7;
  78096. while (sym < 288) state->lens[sym++] = 8;
  78097. next = fixed;
  78098. lenfix = next;
  78099. bits = 9;
  78100. inflate_table(LENS, state->lens, 288, &(next), &(bits), state->work);
  78101. sym = 0;
  78102. while (sym < 32) state->lens[sym++] = 5;
  78103. distfix = next;
  78104. bits = 5;
  78105. inflate_table(DISTS, state->lens, 32, &(next), &(bits), state->work);
  78106. virgin = 0;
  78107. }
  78108. #else /* !BUILDFIXED */
  78109. /*** Start of inlined file: inffixed.h ***/
  78110. static const code lenfix[512] = {
  78111. {96,7,0},{0,8,80},{0,8,16},{20,8,115},{18,7,31},{0,8,112},{0,8,48},
  78112. {0,9,192},{16,7,10},{0,8,96},{0,8,32},{0,9,160},{0,8,0},{0,8,128},
  78113. {0,8,64},{0,9,224},{16,7,6},{0,8,88},{0,8,24},{0,9,144},{19,7,59},
  78114. {0,8,120},{0,8,56},{0,9,208},{17,7,17},{0,8,104},{0,8,40},{0,9,176},
  78115. {0,8,8},{0,8,136},{0,8,72},{0,9,240},{16,7,4},{0,8,84},{0,8,20},
  78116. {21,8,227},{19,7,43},{0,8,116},{0,8,52},{0,9,200},{17,7,13},{0,8,100},
  78117. {0,8,36},{0,9,168},{0,8,4},{0,8,132},{0,8,68},{0,9,232},{16,7,8},
  78118. {0,8,92},{0,8,28},{0,9,152},{20,7,83},{0,8,124},{0,8,60},{0,9,216},
  78119. {18,7,23},{0,8,108},{0,8,44},{0,9,184},{0,8,12},{0,8,140},{0,8,76},
  78120. {0,9,248},{16,7,3},{0,8,82},{0,8,18},{21,8,163},{19,7,35},{0,8,114},
  78121. {0,8,50},{0,9,196},{17,7,11},{0,8,98},{0,8,34},{0,9,164},{0,8,2},
  78122. {0,8,130},{0,8,66},{0,9,228},{16,7,7},{0,8,90},{0,8,26},{0,9,148},
  78123. {20,7,67},{0,8,122},{0,8,58},{0,9,212},{18,7,19},{0,8,106},{0,8,42},
  78124. {0,9,180},{0,8,10},{0,8,138},{0,8,74},{0,9,244},{16,7,5},{0,8,86},
  78125. {0,8,22},{64,8,0},{19,7,51},{0,8,118},{0,8,54},{0,9,204},{17,7,15},
  78126. {0,8,102},{0,8,38},{0,9,172},{0,8,6},{0,8,134},{0,8,70},{0,9,236},
  78127. {16,7,9},{0,8,94},{0,8,30},{0,9,156},{20,7,99},{0,8,126},{0,8,62},
  78128. {0,9,220},{18,7,27},{0,8,110},{0,8,46},{0,9,188},{0,8,14},{0,8,142},
  78129. {0,8,78},{0,9,252},{96,7,0},{0,8,81},{0,8,17},{21,8,131},{18,7,31},
  78130. {0,8,113},{0,8,49},{0,9,194},{16,7,10},{0,8,97},{0,8,33},{0,9,162},
  78131. {0,8,1},{0,8,129},{0,8,65},{0,9,226},{16,7,6},{0,8,89},{0,8,25},
  78132. {0,9,146},{19,7,59},{0,8,121},{0,8,57},{0,9,210},{17,7,17},{0,8,105},
  78133. {0,8,41},{0,9,178},{0,8,9},{0,8,137},{0,8,73},{0,9,242},{16,7,4},
  78134. {0,8,85},{0,8,21},{16,8,258},{19,7,43},{0,8,117},{0,8,53},{0,9,202},
  78135. {17,7,13},{0,8,101},{0,8,37},{0,9,170},{0,8,5},{0,8,133},{0,8,69},
  78136. {0,9,234},{16,7,8},{0,8,93},{0,8,29},{0,9,154},{20,7,83},{0,8,125},
  78137. {0,8,61},{0,9,218},{18,7,23},{0,8,109},{0,8,45},{0,9,186},{0,8,13},
  78138. {0,8,141},{0,8,77},{0,9,250},{16,7,3},{0,8,83},{0,8,19},{21,8,195},
  78139. {19,7,35},{0,8,115},{0,8,51},{0,9,198},{17,7,11},{0,8,99},{0,8,35},
  78140. {0,9,166},{0,8,3},{0,8,131},{0,8,67},{0,9,230},{16,7,7},{0,8,91},
  78141. {0,8,27},{0,9,150},{20,7,67},{0,8,123},{0,8,59},{0,9,214},{18,7,19},
  78142. {0,8,107},{0,8,43},{0,9,182},{0,8,11},{0,8,139},{0,8,75},{0,9,246},
  78143. {16,7,5},{0,8,87},{0,8,23},{64,8,0},{19,7,51},{0,8,119},{0,8,55},
  78144. {0,9,206},{17,7,15},{0,8,103},{0,8,39},{0,9,174},{0,8,7},{0,8,135},
  78145. {0,8,71},{0,9,238},{16,7,9},{0,8,95},{0,8,31},{0,9,158},{20,7,99},
  78146. {0,8,127},{0,8,63},{0,9,222},{18,7,27},{0,8,111},{0,8,47},{0,9,190},
  78147. {0,8,15},{0,8,143},{0,8,79},{0,9,254},{96,7,0},{0,8,80},{0,8,16},
  78148. {20,8,115},{18,7,31},{0,8,112},{0,8,48},{0,9,193},{16,7,10},{0,8,96},
  78149. {0,8,32},{0,9,161},{0,8,0},{0,8,128},{0,8,64},{0,9,225},{16,7,6},
  78150. {0,8,88},{0,8,24},{0,9,145},{19,7,59},{0,8,120},{0,8,56},{0,9,209},
  78151. {17,7,17},{0,8,104},{0,8,40},{0,9,177},{0,8,8},{0,8,136},{0,8,72},
  78152. {0,9,241},{16,7,4},{0,8,84},{0,8,20},{21,8,227},{19,7,43},{0,8,116},
  78153. {0,8,52},{0,9,201},{17,7,13},{0,8,100},{0,8,36},{0,9,169},{0,8,4},
  78154. {0,8,132},{0,8,68},{0,9,233},{16,7,8},{0,8,92},{0,8,28},{0,9,153},
  78155. {20,7,83},{0,8,124},{0,8,60},{0,9,217},{18,7,23},{0,8,108},{0,8,44},
  78156. {0,9,185},{0,8,12},{0,8,140},{0,8,76},{0,9,249},{16,7,3},{0,8,82},
  78157. {0,8,18},{21,8,163},{19,7,35},{0,8,114},{0,8,50},{0,9,197},{17,7,11},
  78158. {0,8,98},{0,8,34},{0,9,165},{0,8,2},{0,8,130},{0,8,66},{0,9,229},
  78159. {16,7,7},{0,8,90},{0,8,26},{0,9,149},{20,7,67},{0,8,122},{0,8,58},
  78160. {0,9,213},{18,7,19},{0,8,106},{0,8,42},{0,9,181},{0,8,10},{0,8,138},
  78161. {0,8,74},{0,9,245},{16,7,5},{0,8,86},{0,8,22},{64,8,0},{19,7,51},
  78162. {0,8,118},{0,8,54},{0,9,205},{17,7,15},{0,8,102},{0,8,38},{0,9,173},
  78163. {0,8,6},{0,8,134},{0,8,70},{0,9,237},{16,7,9},{0,8,94},{0,8,30},
  78164. {0,9,157},{20,7,99},{0,8,126},{0,8,62},{0,9,221},{18,7,27},{0,8,110},
  78165. {0,8,46},{0,9,189},{0,8,14},{0,8,142},{0,8,78},{0,9,253},{96,7,0},
  78166. {0,8,81},{0,8,17},{21,8,131},{18,7,31},{0,8,113},{0,8,49},{0,9,195},
  78167. {16,7,10},{0,8,97},{0,8,33},{0,9,163},{0,8,1},{0,8,129},{0,8,65},
  78168. {0,9,227},{16,7,6},{0,8,89},{0,8,25},{0,9,147},{19,7,59},{0,8,121},
  78169. {0,8,57},{0,9,211},{17,7,17},{0,8,105},{0,8,41},{0,9,179},{0,8,9},
  78170. {0,8,137},{0,8,73},{0,9,243},{16,7,4},{0,8,85},{0,8,21},{16,8,258},
  78171. {19,7,43},{0,8,117},{0,8,53},{0,9,203},{17,7,13},{0,8,101},{0,8,37},
  78172. {0,9,171},{0,8,5},{0,8,133},{0,8,69},{0,9,235},{16,7,8},{0,8,93},
  78173. {0,8,29},{0,9,155},{20,7,83},{0,8,125},{0,8,61},{0,9,219},{18,7,23},
  78174. {0,8,109},{0,8,45},{0,9,187},{0,8,13},{0,8,141},{0,8,77},{0,9,251},
  78175. {16,7,3},{0,8,83},{0,8,19},{21,8,195},{19,7,35},{0,8,115},{0,8,51},
  78176. {0,9,199},{17,7,11},{0,8,99},{0,8,35},{0,9,167},{0,8,3},{0,8,131},
  78177. {0,8,67},{0,9,231},{16,7,7},{0,8,91},{0,8,27},{0,9,151},{20,7,67},
  78178. {0,8,123},{0,8,59},{0,9,215},{18,7,19},{0,8,107},{0,8,43},{0,9,183},
  78179. {0,8,11},{0,8,139},{0,8,75},{0,9,247},{16,7,5},{0,8,87},{0,8,23},
  78180. {64,8,0},{19,7,51},{0,8,119},{0,8,55},{0,9,207},{17,7,15},{0,8,103},
  78181. {0,8,39},{0,9,175},{0,8,7},{0,8,135},{0,8,71},{0,9,239},{16,7,9},
  78182. {0,8,95},{0,8,31},{0,9,159},{20,7,99},{0,8,127},{0,8,63},{0,9,223},
  78183. {18,7,27},{0,8,111},{0,8,47},{0,9,191},{0,8,15},{0,8,143},{0,8,79},
  78184. {0,9,255}
  78185. };
  78186. static const code distfix[32] = {
  78187. {16,5,1},{23,5,257},{19,5,17},{27,5,4097},{17,5,5},{25,5,1025},
  78188. {21,5,65},{29,5,16385},{16,5,3},{24,5,513},{20,5,33},{28,5,8193},
  78189. {18,5,9},{26,5,2049},{22,5,129},{64,5,0},{16,5,2},{23,5,385},
  78190. {19,5,25},{27,5,6145},{17,5,7},{25,5,1537},{21,5,97},{29,5,24577},
  78191. {16,5,4},{24,5,769},{20,5,49},{28,5,12289},{18,5,13},{26,5,3073},
  78192. {22,5,193},{64,5,0}
  78193. };
  78194. /*** End of inlined file: inffixed.h ***/
  78195. #endif /* BUILDFIXED */
  78196. state->lencode = lenfix;
  78197. state->lenbits = 9;
  78198. state->distcode = distfix;
  78199. state->distbits = 5;
  78200. }
  78201. #ifdef MAKEFIXED
  78202. #include <stdio.h>
  78203. void makefixed()
  78204. {
  78205. unsigned low, size;
  78206. struct inflate_state state;
  78207. fixedtables(&state);
  78208. puts(" /* inffixed.h -- table for decoding fixed codes");
  78209. puts(" * Generated automatically by makefixed().");
  78210. puts(" */");
  78211. puts("");
  78212. puts(" /* WARNING: this file should *not* be used by applications.");
  78213. puts(" It is part of the implementation of this library and is");
  78214. puts(" subject to change. Applications should only use zlib.h.");
  78215. puts(" */");
  78216. puts("");
  78217. size = 1U << 9;
  78218. printf(" static const code lenfix[%u] = {", size);
  78219. low = 0;
  78220. for (;;) {
  78221. if ((low % 7) == 0) printf("\n ");
  78222. printf("{%u,%u,%d}", state.lencode[low].op, state.lencode[low].bits,
  78223. state.lencode[low].val);
  78224. if (++low == size) break;
  78225. putchar(',');
  78226. }
  78227. puts("\n };");
  78228. size = 1U << 5;
  78229. printf("\n static const code distfix[%u] = {", size);
  78230. low = 0;
  78231. for (;;) {
  78232. if ((low % 6) == 0) printf("\n ");
  78233. printf("{%u,%u,%d}", state.distcode[low].op, state.distcode[low].bits,
  78234. state.distcode[low].val);
  78235. if (++low == size) break;
  78236. putchar(',');
  78237. }
  78238. puts("\n };");
  78239. }
  78240. #endif /* MAKEFIXED */
  78241. local int updatewindow (z_streamp strm, unsigned out)
  78242. {
  78243. struct inflate_state FAR *state;
  78244. unsigned copy, dist;
  78245. state = (struct inflate_state FAR *)strm->state;
  78246. if (state->window == Z_NULL) {
  78247. state->window = (unsigned char FAR *)
  78248. ZALLOC(strm, 1U << state->wbits,
  78249. sizeof(unsigned char));
  78250. if (state->window == Z_NULL) return 1;
  78251. }
  78252. if (state->wsize == 0) {
  78253. state->wsize = 1U << state->wbits;
  78254. state->write = 0;
  78255. state->whave = 0;
  78256. }
  78257. copy = out - strm->avail_out;
  78258. if (copy >= state->wsize) {
  78259. zmemcpy(state->window, strm->next_out - state->wsize, state->wsize);
  78260. state->write = 0;
  78261. state->whave = state->wsize;
  78262. }
  78263. else {
  78264. dist = state->wsize - state->write;
  78265. if (dist > copy) dist = copy;
  78266. zmemcpy(state->window + state->write, strm->next_out - copy, dist);
  78267. copy -= dist;
  78268. if (copy) {
  78269. zmemcpy(state->window, strm->next_out - copy, copy);
  78270. state->write = copy;
  78271. state->whave = state->wsize;
  78272. }
  78273. else {
  78274. state->write += dist;
  78275. if (state->write == state->wsize) state->write = 0;
  78276. if (state->whave < state->wsize) state->whave += dist;
  78277. }
  78278. }
  78279. return 0;
  78280. }
  78281. #ifdef GUNZIP
  78282. # define UPDATE(check, buf, len) \
  78283. (state->flags ? crc32(check, buf, len) : adler32(check, buf, len))
  78284. #else
  78285. # define UPDATE(check, buf, len) adler32(check, buf, len)
  78286. #endif
  78287. #ifdef GUNZIP
  78288. # define CRC2(check, word) \
  78289. do { \
  78290. hbuf[0] = (unsigned char)(word); \
  78291. hbuf[1] = (unsigned char)((word) >> 8); \
  78292. check = crc32(check, hbuf, 2); \
  78293. } while (0)
  78294. # define CRC4(check, word) \
  78295. do { \
  78296. hbuf[0] = (unsigned char)(word); \
  78297. hbuf[1] = (unsigned char)((word) >> 8); \
  78298. hbuf[2] = (unsigned char)((word) >> 16); \
  78299. hbuf[3] = (unsigned char)((word) >> 24); \
  78300. check = crc32(check, hbuf, 4); \
  78301. } while (0)
  78302. #endif
  78303. #define LOAD() \
  78304. do { \
  78305. put = strm->next_out; \
  78306. left = strm->avail_out; \
  78307. next = strm->next_in; \
  78308. have = strm->avail_in; \
  78309. hold = state->hold; \
  78310. bits = state->bits; \
  78311. } while (0)
  78312. #define RESTORE() \
  78313. do { \
  78314. strm->next_out = put; \
  78315. strm->avail_out = left; \
  78316. strm->next_in = next; \
  78317. strm->avail_in = have; \
  78318. state->hold = hold; \
  78319. state->bits = bits; \
  78320. } while (0)
  78321. #define INITBITS() \
  78322. do { \
  78323. hold = 0; \
  78324. bits = 0; \
  78325. } while (0)
  78326. #define PULLBYTE() \
  78327. do { \
  78328. if (have == 0) goto inf_leave; \
  78329. have--; \
  78330. hold += (unsigned long)(*next++) << bits; \
  78331. bits += 8; \
  78332. } while (0)
  78333. #define NEEDBITS(n) \
  78334. do { \
  78335. while (bits < (unsigned)(n)) \
  78336. PULLBYTE(); \
  78337. } while (0)
  78338. #define BITS(n) \
  78339. ((unsigned)hold & ((1U << (n)) - 1))
  78340. #define DROPBITS(n) \
  78341. do { \
  78342. hold >>= (n); \
  78343. bits -= (unsigned)(n); \
  78344. } while (0)
  78345. #define BYTEBITS() \
  78346. do { \
  78347. hold >>= bits & 7; \
  78348. bits -= bits & 7; \
  78349. } while (0)
  78350. #define REVERSE(q) \
  78351. ((((q) >> 24) & 0xff) + (((q) >> 8) & 0xff00) + \
  78352. (((q) & 0xff00) << 8) + (((q) & 0xff) << 24))
  78353. int ZEXPORT inflate (z_streamp strm, int flush)
  78354. {
  78355. struct inflate_state FAR *state;
  78356. unsigned char FAR *next; /* next input */
  78357. unsigned char FAR *put; /* next output */
  78358. unsigned have, left; /* available input and output */
  78359. unsigned long hold; /* bit buffer */
  78360. unsigned bits; /* bits in bit buffer */
  78361. unsigned in, out; /* save starting available input and output */
  78362. unsigned copy; /* number of stored or match bytes to copy */
  78363. unsigned char FAR *from; /* where to copy match bytes from */
  78364. code thisx; /* current decoding table entry */
  78365. code last; /* parent table entry */
  78366. unsigned len; /* length to copy for repeats, bits to drop */
  78367. int ret; /* return code */
  78368. #ifdef GUNZIP
  78369. unsigned char hbuf[4]; /* buffer for gzip header crc calculation */
  78370. #endif
  78371. static const unsigned short order[19] = /* permutation of code lengths */
  78372. {16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15};
  78373. if (strm == Z_NULL || strm->state == Z_NULL || strm->next_out == Z_NULL ||
  78374. (strm->next_in == Z_NULL && strm->avail_in != 0))
  78375. return Z_STREAM_ERROR;
  78376. state = (struct inflate_state FAR *)strm->state;
  78377. if (state->mode == TYPE) state->mode = TYPEDO; /* skip check */
  78378. LOAD();
  78379. in = have;
  78380. out = left;
  78381. ret = Z_OK;
  78382. for (;;)
  78383. switch (state->mode) {
  78384. case HEAD:
  78385. if (state->wrap == 0) {
  78386. state->mode = TYPEDO;
  78387. break;
  78388. }
  78389. NEEDBITS(16);
  78390. #ifdef GUNZIP
  78391. if ((state->wrap & 2) && hold == 0x8b1f) { /* gzip header */
  78392. state->check = crc32(0L, Z_NULL, 0);
  78393. CRC2(state->check, hold);
  78394. INITBITS();
  78395. state->mode = FLAGS;
  78396. break;
  78397. }
  78398. state->flags = 0; /* expect zlib header */
  78399. if (state->head != Z_NULL)
  78400. state->head->done = -1;
  78401. if (!(state->wrap & 1) || /* check if zlib header allowed */
  78402. #else
  78403. if (
  78404. #endif
  78405. ((BITS(8) << 8) + (hold >> 8)) % 31) {
  78406. strm->msg = (char *)"incorrect header check";
  78407. state->mode = BAD;
  78408. break;
  78409. }
  78410. if (BITS(4) != Z_DEFLATED) {
  78411. strm->msg = (char *)"unknown compression method";
  78412. state->mode = BAD;
  78413. break;
  78414. }
  78415. DROPBITS(4);
  78416. len = BITS(4) + 8;
  78417. if (len > state->wbits) {
  78418. strm->msg = (char *)"invalid window size";
  78419. state->mode = BAD;
  78420. break;
  78421. }
  78422. state->dmax = 1U << len;
  78423. Tracev((stderr, "inflate: zlib header ok\n"));
  78424. strm->adler = state->check = adler32(0L, Z_NULL, 0);
  78425. state->mode = hold & 0x200 ? DICTID : TYPE;
  78426. INITBITS();
  78427. break;
  78428. #ifdef GUNZIP
  78429. case FLAGS:
  78430. NEEDBITS(16);
  78431. state->flags = (int)(hold);
  78432. if ((state->flags & 0xff) != Z_DEFLATED) {
  78433. strm->msg = (char *)"unknown compression method";
  78434. state->mode = BAD;
  78435. break;
  78436. }
  78437. if (state->flags & 0xe000) {
  78438. strm->msg = (char *)"unknown header flags set";
  78439. state->mode = BAD;
  78440. break;
  78441. }
  78442. if (state->head != Z_NULL)
  78443. state->head->text = (int)((hold >> 8) & 1);
  78444. if (state->flags & 0x0200) CRC2(state->check, hold);
  78445. INITBITS();
  78446. state->mode = TIME;
  78447. case TIME:
  78448. NEEDBITS(32);
  78449. if (state->head != Z_NULL)
  78450. state->head->time = hold;
  78451. if (state->flags & 0x0200) CRC4(state->check, hold);
  78452. INITBITS();
  78453. state->mode = OS;
  78454. case OS:
  78455. NEEDBITS(16);
  78456. if (state->head != Z_NULL) {
  78457. state->head->xflags = (int)(hold & 0xff);
  78458. state->head->os = (int)(hold >> 8);
  78459. }
  78460. if (state->flags & 0x0200) CRC2(state->check, hold);
  78461. INITBITS();
  78462. state->mode = EXLEN;
  78463. case EXLEN:
  78464. if (state->flags & 0x0400) {
  78465. NEEDBITS(16);
  78466. state->length = (unsigned)(hold);
  78467. if (state->head != Z_NULL)
  78468. state->head->extra_len = (unsigned)hold;
  78469. if (state->flags & 0x0200) CRC2(state->check, hold);
  78470. INITBITS();
  78471. }
  78472. else if (state->head != Z_NULL)
  78473. state->head->extra = Z_NULL;
  78474. state->mode = EXTRA;
  78475. case EXTRA:
  78476. if (state->flags & 0x0400) {
  78477. copy = state->length;
  78478. if (copy > have) copy = have;
  78479. if (copy) {
  78480. if (state->head != Z_NULL &&
  78481. state->head->extra != Z_NULL) {
  78482. len = state->head->extra_len - state->length;
  78483. zmemcpy(state->head->extra + len, next,
  78484. len + copy > state->head->extra_max ?
  78485. state->head->extra_max - len : copy);
  78486. }
  78487. if (state->flags & 0x0200)
  78488. state->check = crc32(state->check, next, copy);
  78489. have -= copy;
  78490. next += copy;
  78491. state->length -= copy;
  78492. }
  78493. if (state->length) goto inf_leave;
  78494. }
  78495. state->length = 0;
  78496. state->mode = NAME;
  78497. case NAME:
  78498. if (state->flags & 0x0800) {
  78499. if (have == 0) goto inf_leave;
  78500. copy = 0;
  78501. do {
  78502. len = (unsigned)(next[copy++]);
  78503. if (state->head != Z_NULL &&
  78504. state->head->name != Z_NULL &&
  78505. state->length < state->head->name_max)
  78506. state->head->name[state->length++] = len;
  78507. } while (len && copy < have);
  78508. if (state->flags & 0x0200)
  78509. state->check = crc32(state->check, next, copy);
  78510. have -= copy;
  78511. next += copy;
  78512. if (len) goto inf_leave;
  78513. }
  78514. else if (state->head != Z_NULL)
  78515. state->head->name = Z_NULL;
  78516. state->length = 0;
  78517. state->mode = COMMENT;
  78518. case COMMENT:
  78519. if (state->flags & 0x1000) {
  78520. if (have == 0) goto inf_leave;
  78521. copy = 0;
  78522. do {
  78523. len = (unsigned)(next[copy++]);
  78524. if (state->head != Z_NULL &&
  78525. state->head->comment != Z_NULL &&
  78526. state->length < state->head->comm_max)
  78527. state->head->comment[state->length++] = len;
  78528. } while (len && copy < have);
  78529. if (state->flags & 0x0200)
  78530. state->check = crc32(state->check, next, copy);
  78531. have -= copy;
  78532. next += copy;
  78533. if (len) goto inf_leave;
  78534. }
  78535. else if (state->head != Z_NULL)
  78536. state->head->comment = Z_NULL;
  78537. state->mode = HCRC;
  78538. case HCRC:
  78539. if (state->flags & 0x0200) {
  78540. NEEDBITS(16);
  78541. if (hold != (state->check & 0xffff)) {
  78542. strm->msg = (char *)"header crc mismatch";
  78543. state->mode = BAD;
  78544. break;
  78545. }
  78546. INITBITS();
  78547. }
  78548. if (state->head != Z_NULL) {
  78549. state->head->hcrc = (int)((state->flags >> 9) & 1);
  78550. state->head->done = 1;
  78551. }
  78552. strm->adler = state->check = crc32(0L, Z_NULL, 0);
  78553. state->mode = TYPE;
  78554. break;
  78555. #endif
  78556. case DICTID:
  78557. NEEDBITS(32);
  78558. strm->adler = state->check = REVERSE(hold);
  78559. INITBITS();
  78560. state->mode = DICT;
  78561. case DICT:
  78562. if (state->havedict == 0) {
  78563. RESTORE();
  78564. return Z_NEED_DICT;
  78565. }
  78566. strm->adler = state->check = adler32(0L, Z_NULL, 0);
  78567. state->mode = TYPE;
  78568. case TYPE:
  78569. if (flush == Z_BLOCK) goto inf_leave;
  78570. case TYPEDO:
  78571. if (state->last) {
  78572. BYTEBITS();
  78573. state->mode = CHECK;
  78574. break;
  78575. }
  78576. NEEDBITS(3);
  78577. state->last = BITS(1);
  78578. DROPBITS(1);
  78579. switch (BITS(2)) {
  78580. case 0: /* stored block */
  78581. Tracev((stderr, "inflate: stored block%s\n",
  78582. state->last ? " (last)" : ""));
  78583. state->mode = STORED;
  78584. break;
  78585. case 1: /* fixed block */
  78586. fixedtables(state);
  78587. Tracev((stderr, "inflate: fixed codes block%s\n",
  78588. state->last ? " (last)" : ""));
  78589. state->mode = LEN; /* decode codes */
  78590. break;
  78591. case 2: /* dynamic block */
  78592. Tracev((stderr, "inflate: dynamic codes block%s\n",
  78593. state->last ? " (last)" : ""));
  78594. state->mode = TABLE;
  78595. break;
  78596. case 3:
  78597. strm->msg = (char *)"invalid block type";
  78598. state->mode = BAD;
  78599. }
  78600. DROPBITS(2);
  78601. break;
  78602. case STORED:
  78603. BYTEBITS(); /* go to byte boundary */
  78604. NEEDBITS(32);
  78605. if ((hold & 0xffff) != ((hold >> 16) ^ 0xffff)) {
  78606. strm->msg = (char *)"invalid stored block lengths";
  78607. state->mode = BAD;
  78608. break;
  78609. }
  78610. state->length = (unsigned)hold & 0xffff;
  78611. Tracev((stderr, "inflate: stored length %u\n",
  78612. state->length));
  78613. INITBITS();
  78614. state->mode = COPY;
  78615. case COPY:
  78616. copy = state->length;
  78617. if (copy) {
  78618. if (copy > have) copy = have;
  78619. if (copy > left) copy = left;
  78620. if (copy == 0) goto inf_leave;
  78621. zmemcpy(put, next, copy);
  78622. have -= copy;
  78623. next += copy;
  78624. left -= copy;
  78625. put += copy;
  78626. state->length -= copy;
  78627. break;
  78628. }
  78629. Tracev((stderr, "inflate: stored end\n"));
  78630. state->mode = TYPE;
  78631. break;
  78632. case TABLE:
  78633. NEEDBITS(14);
  78634. state->nlen = BITS(5) + 257;
  78635. DROPBITS(5);
  78636. state->ndist = BITS(5) + 1;
  78637. DROPBITS(5);
  78638. state->ncode = BITS(4) + 4;
  78639. DROPBITS(4);
  78640. #ifndef PKZIP_BUG_WORKAROUND
  78641. if (state->nlen > 286 || state->ndist > 30) {
  78642. strm->msg = (char *)"too many length or distance symbols";
  78643. state->mode = BAD;
  78644. break;
  78645. }
  78646. #endif
  78647. Tracev((stderr, "inflate: table sizes ok\n"));
  78648. state->have = 0;
  78649. state->mode = LENLENS;
  78650. case LENLENS:
  78651. while (state->have < state->ncode) {
  78652. NEEDBITS(3);
  78653. state->lens[order[state->have++]] = (unsigned short)BITS(3);
  78654. DROPBITS(3);
  78655. }
  78656. while (state->have < 19)
  78657. state->lens[order[state->have++]] = 0;
  78658. state->next = state->codes;
  78659. state->lencode = (code const FAR *)(state->next);
  78660. state->lenbits = 7;
  78661. ret = inflate_table(CODES, state->lens, 19, &(state->next),
  78662. &(state->lenbits), state->work);
  78663. if (ret) {
  78664. strm->msg = (char *)"invalid code lengths set";
  78665. state->mode = BAD;
  78666. break;
  78667. }
  78668. Tracev((stderr, "inflate: code lengths ok\n"));
  78669. state->have = 0;
  78670. state->mode = CODELENS;
  78671. case CODELENS:
  78672. while (state->have < state->nlen + state->ndist) {
  78673. for (;;) {
  78674. thisx = state->lencode[BITS(state->lenbits)];
  78675. if ((unsigned)(thisx.bits) <= bits) break;
  78676. PULLBYTE();
  78677. }
  78678. if (thisx.val < 16) {
  78679. NEEDBITS(thisx.bits);
  78680. DROPBITS(thisx.bits);
  78681. state->lens[state->have++] = thisx.val;
  78682. }
  78683. else {
  78684. if (thisx.val == 16) {
  78685. NEEDBITS(thisx.bits + 2);
  78686. DROPBITS(thisx.bits);
  78687. if (state->have == 0) {
  78688. strm->msg = (char *)"invalid bit length repeat";
  78689. state->mode = BAD;
  78690. break;
  78691. }
  78692. len = state->lens[state->have - 1];
  78693. copy = 3 + BITS(2);
  78694. DROPBITS(2);
  78695. }
  78696. else if (thisx.val == 17) {
  78697. NEEDBITS(thisx.bits + 3);
  78698. DROPBITS(thisx.bits);
  78699. len = 0;
  78700. copy = 3 + BITS(3);
  78701. DROPBITS(3);
  78702. }
  78703. else {
  78704. NEEDBITS(thisx.bits + 7);
  78705. DROPBITS(thisx.bits);
  78706. len = 0;
  78707. copy = 11 + BITS(7);
  78708. DROPBITS(7);
  78709. }
  78710. if (state->have + copy > state->nlen + state->ndist) {
  78711. strm->msg = (char *)"invalid bit length repeat";
  78712. state->mode = BAD;
  78713. break;
  78714. }
  78715. while (copy--)
  78716. state->lens[state->have++] = (unsigned short)len;
  78717. }
  78718. }
  78719. if (state->mode == BAD) break;
  78720. state->next = state->codes;
  78721. state->lencode = (code const FAR *)(state->next);
  78722. state->lenbits = 9;
  78723. ret = inflate_table(LENS, state->lens, state->nlen, &(state->next),
  78724. &(state->lenbits), state->work);
  78725. if (ret) {
  78726. strm->msg = (char *)"invalid literal/lengths set";
  78727. state->mode = BAD;
  78728. break;
  78729. }
  78730. state->distcode = (code const FAR *)(state->next);
  78731. state->distbits = 6;
  78732. ret = inflate_table(DISTS, state->lens + state->nlen, state->ndist,
  78733. &(state->next), &(state->distbits), state->work);
  78734. if (ret) {
  78735. strm->msg = (char *)"invalid distances set";
  78736. state->mode = BAD;
  78737. break;
  78738. }
  78739. Tracev((stderr, "inflate: codes ok\n"));
  78740. state->mode = LEN;
  78741. case LEN:
  78742. if (have >= 6 && left >= 258) {
  78743. RESTORE();
  78744. inflate_fast(strm, out);
  78745. LOAD();
  78746. break;
  78747. }
  78748. for (;;) {
  78749. thisx = state->lencode[BITS(state->lenbits)];
  78750. if ((unsigned)(thisx.bits) <= bits) break;
  78751. PULLBYTE();
  78752. }
  78753. if (thisx.op && (thisx.op & 0xf0) == 0) {
  78754. last = thisx;
  78755. for (;;) {
  78756. thisx = state->lencode[last.val +
  78757. (BITS(last.bits + last.op) >> last.bits)];
  78758. if ((unsigned)(last.bits + thisx.bits) <= bits) break;
  78759. PULLBYTE();
  78760. }
  78761. DROPBITS(last.bits);
  78762. }
  78763. DROPBITS(thisx.bits);
  78764. state->length = (unsigned)thisx.val;
  78765. if ((int)(thisx.op) == 0) {
  78766. Tracevv((stderr, thisx.val >= 0x20 && thisx.val < 0x7f ?
  78767. "inflate: literal '%c'\n" :
  78768. "inflate: literal 0x%02x\n", thisx.val));
  78769. state->mode = LIT;
  78770. break;
  78771. }
  78772. if (thisx.op & 32) {
  78773. Tracevv((stderr, "inflate: end of block\n"));
  78774. state->mode = TYPE;
  78775. break;
  78776. }
  78777. if (thisx.op & 64) {
  78778. strm->msg = (char *)"invalid literal/length code";
  78779. state->mode = BAD;
  78780. break;
  78781. }
  78782. state->extra = (unsigned)(thisx.op) & 15;
  78783. state->mode = LENEXT;
  78784. case LENEXT:
  78785. if (state->extra) {
  78786. NEEDBITS(state->extra);
  78787. state->length += BITS(state->extra);
  78788. DROPBITS(state->extra);
  78789. }
  78790. Tracevv((stderr, "inflate: length %u\n", state->length));
  78791. state->mode = DIST;
  78792. case DIST:
  78793. for (;;) {
  78794. thisx = state->distcode[BITS(state->distbits)];
  78795. if ((unsigned)(thisx.bits) <= bits) break;
  78796. PULLBYTE();
  78797. }
  78798. if ((thisx.op & 0xf0) == 0) {
  78799. last = thisx;
  78800. for (;;) {
  78801. thisx = state->distcode[last.val +
  78802. (BITS(last.bits + last.op) >> last.bits)];
  78803. if ((unsigned)(last.bits + thisx.bits) <= bits) break;
  78804. PULLBYTE();
  78805. }
  78806. DROPBITS(last.bits);
  78807. }
  78808. DROPBITS(thisx.bits);
  78809. if (thisx.op & 64) {
  78810. strm->msg = (char *)"invalid distance code";
  78811. state->mode = BAD;
  78812. break;
  78813. }
  78814. state->offset = (unsigned)thisx.val;
  78815. state->extra = (unsigned)(thisx.op) & 15;
  78816. state->mode = DISTEXT;
  78817. case DISTEXT:
  78818. if (state->extra) {
  78819. NEEDBITS(state->extra);
  78820. state->offset += BITS(state->extra);
  78821. DROPBITS(state->extra);
  78822. }
  78823. #ifdef INFLATE_STRICT
  78824. if (state->offset > state->dmax) {
  78825. strm->msg = (char *)"invalid distance too far back";
  78826. state->mode = BAD;
  78827. break;
  78828. }
  78829. #endif
  78830. if (state->offset > state->whave + out - left) {
  78831. strm->msg = (char *)"invalid distance too far back";
  78832. state->mode = BAD;
  78833. break;
  78834. }
  78835. Tracevv((stderr, "inflate: distance %u\n", state->offset));
  78836. state->mode = MATCH;
  78837. case MATCH:
  78838. if (left == 0) goto inf_leave;
  78839. copy = out - left;
  78840. if (state->offset > copy) { /* copy from window */
  78841. copy = state->offset - copy;
  78842. if (copy > state->write) {
  78843. copy -= state->write;
  78844. from = state->window + (state->wsize - copy);
  78845. }
  78846. else
  78847. from = state->window + (state->write - copy);
  78848. if (copy > state->length) copy = state->length;
  78849. }
  78850. else { /* copy from output */
  78851. from = put - state->offset;
  78852. copy = state->length;
  78853. }
  78854. if (copy > left) copy = left;
  78855. left -= copy;
  78856. state->length -= copy;
  78857. do {
  78858. *put++ = *from++;
  78859. } while (--copy);
  78860. if (state->length == 0) state->mode = LEN;
  78861. break;
  78862. case LIT:
  78863. if (left == 0) goto inf_leave;
  78864. *put++ = (unsigned char)(state->length);
  78865. left--;
  78866. state->mode = LEN;
  78867. break;
  78868. case CHECK:
  78869. if (state->wrap) {
  78870. NEEDBITS(32);
  78871. out -= left;
  78872. strm->total_out += out;
  78873. state->total += out;
  78874. if (out)
  78875. strm->adler = state->check =
  78876. UPDATE(state->check, put - out, out);
  78877. out = left;
  78878. if ((
  78879. #ifdef GUNZIP
  78880. state->flags ? hold :
  78881. #endif
  78882. REVERSE(hold)) != state->check) {
  78883. strm->msg = (char *)"incorrect data check";
  78884. state->mode = BAD;
  78885. break;
  78886. }
  78887. INITBITS();
  78888. Tracev((stderr, "inflate: check matches trailer\n"));
  78889. }
  78890. #ifdef GUNZIP
  78891. state->mode = LENGTH;
  78892. case LENGTH:
  78893. if (state->wrap && state->flags) {
  78894. NEEDBITS(32);
  78895. if (hold != (state->total & 0xffffffffUL)) {
  78896. strm->msg = (char *)"incorrect length check";
  78897. state->mode = BAD;
  78898. break;
  78899. }
  78900. INITBITS();
  78901. Tracev((stderr, "inflate: length matches trailer\n"));
  78902. }
  78903. #endif
  78904. state->mode = DONE;
  78905. case DONE:
  78906. ret = Z_STREAM_END;
  78907. goto inf_leave;
  78908. case BAD:
  78909. ret = Z_DATA_ERROR;
  78910. goto inf_leave;
  78911. case MEM:
  78912. return Z_MEM_ERROR;
  78913. case SYNC:
  78914. default:
  78915. return Z_STREAM_ERROR;
  78916. }
  78917. inf_leave:
  78918. RESTORE();
  78919. if (state->wsize || (state->mode < CHECK && out != strm->avail_out))
  78920. if (updatewindow(strm, out)) {
  78921. state->mode = MEM;
  78922. return Z_MEM_ERROR;
  78923. }
  78924. in -= strm->avail_in;
  78925. out -= strm->avail_out;
  78926. strm->total_in += in;
  78927. strm->total_out += out;
  78928. state->total += out;
  78929. if (state->wrap && out)
  78930. strm->adler = state->check =
  78931. UPDATE(state->check, strm->next_out - out, out);
  78932. strm->data_type = state->bits + (state->last ? 64 : 0) +
  78933. (state->mode == TYPE ? 128 : 0);
  78934. if (((in == 0 && out == 0) || flush == Z_FINISH) && ret == Z_OK)
  78935. ret = Z_BUF_ERROR;
  78936. return ret;
  78937. }
  78938. int ZEXPORT inflateEnd (z_streamp strm)
  78939. {
  78940. struct inflate_state FAR *state;
  78941. if (strm == Z_NULL || strm->state == Z_NULL || strm->zfree == (free_func)0)
  78942. return Z_STREAM_ERROR;
  78943. state = (struct inflate_state FAR *)strm->state;
  78944. if (state->window != Z_NULL) ZFREE(strm, state->window);
  78945. ZFREE(strm, strm->state);
  78946. strm->state = Z_NULL;
  78947. Tracev((stderr, "inflate: end\n"));
  78948. return Z_OK;
  78949. }
  78950. int ZEXPORT inflateSetDictionary (z_streamp strm, const Bytef *dictionary, uInt dictLength)
  78951. {
  78952. struct inflate_state FAR *state;
  78953. unsigned long id_;
  78954. if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
  78955. state = (struct inflate_state FAR *)strm->state;
  78956. if (state->wrap != 0 && state->mode != DICT)
  78957. return Z_STREAM_ERROR;
  78958. if (state->mode == DICT) {
  78959. id_ = adler32(0L, Z_NULL, 0);
  78960. id_ = adler32(id_, dictionary, dictLength);
  78961. if (id_ != state->check)
  78962. return Z_DATA_ERROR;
  78963. }
  78964. if (updatewindow(strm, strm->avail_out)) {
  78965. state->mode = MEM;
  78966. return Z_MEM_ERROR;
  78967. }
  78968. if (dictLength > state->wsize) {
  78969. zmemcpy(state->window, dictionary + dictLength - state->wsize,
  78970. state->wsize);
  78971. state->whave = state->wsize;
  78972. }
  78973. else {
  78974. zmemcpy(state->window + state->wsize - dictLength, dictionary,
  78975. dictLength);
  78976. state->whave = dictLength;
  78977. }
  78978. state->havedict = 1;
  78979. Tracev((stderr, "inflate: dictionary set\n"));
  78980. return Z_OK;
  78981. }
  78982. int ZEXPORT inflateGetHeader (z_streamp strm, gz_headerp head)
  78983. {
  78984. struct inflate_state FAR *state;
  78985. if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
  78986. state = (struct inflate_state FAR *)strm->state;
  78987. if ((state->wrap & 2) == 0) return Z_STREAM_ERROR;
  78988. state->head = head;
  78989. head->done = 0;
  78990. return Z_OK;
  78991. }
  78992. local unsigned syncsearch (unsigned FAR *have, unsigned char FAR *buf, unsigned len)
  78993. {
  78994. unsigned got;
  78995. unsigned next;
  78996. got = *have;
  78997. next = 0;
  78998. while (next < len && got < 4) {
  78999. if ((int)(buf[next]) == (got < 2 ? 0 : 0xff))
  79000. got++;
  79001. else if (buf[next])
  79002. got = 0;
  79003. else
  79004. got = 4 - got;
  79005. next++;
  79006. }
  79007. *have = got;
  79008. return next;
  79009. }
  79010. int ZEXPORT inflateSync (z_streamp strm)
  79011. {
  79012. unsigned len; /* number of bytes to look at or looked at */
  79013. unsigned long in, out; /* temporary to save total_in and total_out */
  79014. unsigned char buf[4]; /* to restore bit buffer to byte string */
  79015. struct inflate_state FAR *state;
  79016. if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
  79017. state = (struct inflate_state FAR *)strm->state;
  79018. if (strm->avail_in == 0 && state->bits < 8) return Z_BUF_ERROR;
  79019. if (state->mode != SYNC) {
  79020. state->mode = SYNC;
  79021. state->hold <<= state->bits & 7;
  79022. state->bits -= state->bits & 7;
  79023. len = 0;
  79024. while (state->bits >= 8) {
  79025. buf[len++] = (unsigned char)(state->hold);
  79026. state->hold >>= 8;
  79027. state->bits -= 8;
  79028. }
  79029. state->have = 0;
  79030. syncsearch(&(state->have), buf, len);
  79031. }
  79032. len = syncsearch(&(state->have), strm->next_in, strm->avail_in);
  79033. strm->avail_in -= len;
  79034. strm->next_in += len;
  79035. strm->total_in += len;
  79036. if (state->have != 4) return Z_DATA_ERROR;
  79037. in = strm->total_in; out = strm->total_out;
  79038. inflateReset(strm);
  79039. strm->total_in = in; strm->total_out = out;
  79040. state->mode = TYPE;
  79041. return Z_OK;
  79042. }
  79043. int ZEXPORT inflateSyncPoint (z_streamp strm)
  79044. {
  79045. struct inflate_state FAR *state;
  79046. if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
  79047. state = (struct inflate_state FAR *)strm->state;
  79048. return state->mode == STORED && state->bits == 0;
  79049. }
  79050. int ZEXPORT inflateCopy(z_streamp dest, z_streamp source)
  79051. {
  79052. struct inflate_state FAR *state;
  79053. struct inflate_state FAR *copy;
  79054. unsigned char FAR *window;
  79055. unsigned wsize;
  79056. if (dest == Z_NULL || source == Z_NULL || source->state == Z_NULL ||
  79057. source->zalloc == (alloc_func)0 || source->zfree == (free_func)0)
  79058. return Z_STREAM_ERROR;
  79059. state = (struct inflate_state FAR *)source->state;
  79060. copy = (struct inflate_state FAR *)
  79061. ZALLOC(source, 1, sizeof(struct inflate_state));
  79062. if (copy == Z_NULL) return Z_MEM_ERROR;
  79063. window = Z_NULL;
  79064. if (state->window != Z_NULL) {
  79065. window = (unsigned char FAR *)
  79066. ZALLOC(source, 1U << state->wbits, sizeof(unsigned char));
  79067. if (window == Z_NULL) {
  79068. ZFREE(source, copy);
  79069. return Z_MEM_ERROR;
  79070. }
  79071. }
  79072. zmemcpy(dest, source, sizeof(z_stream));
  79073. zmemcpy(copy, state, sizeof(struct inflate_state));
  79074. if (state->lencode >= state->codes &&
  79075. state->lencode <= state->codes + ENOUGH - 1) {
  79076. copy->lencode = copy->codes + (state->lencode - state->codes);
  79077. copy->distcode = copy->codes + (state->distcode - state->codes);
  79078. }
  79079. copy->next = copy->codes + (state->next - state->codes);
  79080. if (window != Z_NULL) {
  79081. wsize = 1U << state->wbits;
  79082. zmemcpy(window, state->window, wsize);
  79083. }
  79084. copy->window = window;
  79085. dest->state = (struct internal_state FAR *)copy;
  79086. return Z_OK;
  79087. }
  79088. /*** End of inlined file: inflate.c ***/
  79089. /*** Start of inlined file: inftrees.c ***/
  79090. #define MAXBITS 15
  79091. const char inflate_copyright[] =
  79092. " inflate 1.2.3 Copyright 1995-2005 Mark Adler ";
  79093. int inflate_table (codetype type,
  79094. unsigned short FAR *lens,
  79095. unsigned codes,
  79096. code FAR * FAR *table,
  79097. unsigned FAR *bits,
  79098. unsigned short FAR *work)
  79099. {
  79100. unsigned len; /* a code's length in bits */
  79101. unsigned sym; /* index of code symbols */
  79102. unsigned min, max; /* minimum and maximum code lengths */
  79103. unsigned root; /* number of index bits for root table */
  79104. unsigned curr; /* number of index bits for current table */
  79105. unsigned drop; /* code bits to drop for sub-table */
  79106. int left; /* number of prefix codes available */
  79107. unsigned used; /* code entries in table used */
  79108. unsigned huff; /* Huffman code */
  79109. unsigned incr; /* for incrementing code, index */
  79110. unsigned fill; /* index for replicating entries */
  79111. unsigned low; /* low bits for current root entry */
  79112. unsigned mask; /* mask for low root bits */
  79113. code thisx; /* table entry for duplication */
  79114. code FAR *next; /* next available space in table */
  79115. const unsigned short FAR *base; /* base value table to use */
  79116. const unsigned short FAR *extra; /* extra bits table to use */
  79117. int end; /* use base and extra for symbol > end */
  79118. unsigned short count[MAXBITS+1]; /* number of codes of each length */
  79119. unsigned short offs[MAXBITS+1]; /* offsets in table for each length */
  79120. static const unsigned short lbase[31] = { /* Length codes 257..285 base */
  79121. 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31,
  79122. 35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0};
  79123. static const unsigned short lext[31] = { /* Length codes 257..285 extra */
  79124. 16, 16, 16, 16, 16, 16, 16, 16, 17, 17, 17, 17, 18, 18, 18, 18,
  79125. 19, 19, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 16, 201, 196};
  79126. static const unsigned short dbase[32] = { /* Distance codes 0..29 base */
  79127. 1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193,
  79128. 257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145,
  79129. 8193, 12289, 16385, 24577, 0, 0};
  79130. static const unsigned short dext[32] = { /* Distance codes 0..29 extra */
  79131. 16, 16, 16, 16, 17, 17, 18, 18, 19, 19, 20, 20, 21, 21, 22, 22,
  79132. 23, 23, 24, 24, 25, 25, 26, 26, 27, 27,
  79133. 28, 28, 29, 29, 64, 64};
  79134. for (len = 0; len <= MAXBITS; len++)
  79135. count[len] = 0;
  79136. for (sym = 0; sym < codes; sym++)
  79137. count[lens[sym]]++;
  79138. root = *bits;
  79139. for (max = MAXBITS; max >= 1; max--)
  79140. if (count[max] != 0) break;
  79141. if (root > max) root = max;
  79142. if (max == 0) { /* no symbols to code at all */
  79143. thisx.op = (unsigned char)64; /* invalid code marker */
  79144. thisx.bits = (unsigned char)1;
  79145. thisx.val = (unsigned short)0;
  79146. *(*table)++ = thisx; /* make a table to force an error */
  79147. *(*table)++ = thisx;
  79148. *bits = 1;
  79149. return 0; /* no symbols, but wait for decoding to report error */
  79150. }
  79151. for (min = 1; min <= MAXBITS; min++)
  79152. if (count[min] != 0) break;
  79153. if (root < min) root = min;
  79154. left = 1;
  79155. for (len = 1; len <= MAXBITS; len++) {
  79156. left <<= 1;
  79157. left -= count[len];
  79158. if (left < 0) return -1; /* over-subscribed */
  79159. }
  79160. if (left > 0 && (type == CODES || max != 1))
  79161. return -1; /* incomplete set */
  79162. offs[1] = 0;
  79163. for (len = 1; len < MAXBITS; len++)
  79164. offs[len + 1] = offs[len] + count[len];
  79165. for (sym = 0; sym < codes; sym++)
  79166. if (lens[sym] != 0) work[offs[lens[sym]]++] = (unsigned short)sym;
  79167. switch (type) {
  79168. case CODES:
  79169. base = extra = work; /* dummy value--not used */
  79170. end = 19;
  79171. break;
  79172. case LENS:
  79173. base = lbase;
  79174. base -= 257;
  79175. extra = lext;
  79176. extra -= 257;
  79177. end = 256;
  79178. break;
  79179. default: /* DISTS */
  79180. base = dbase;
  79181. extra = dext;
  79182. end = -1;
  79183. }
  79184. huff = 0; /* starting code */
  79185. sym = 0; /* starting code symbol */
  79186. len = min; /* starting code length */
  79187. next = *table; /* current table to fill in */
  79188. curr = root; /* current table index bits */
  79189. drop = 0; /* current bits to drop from code for index */
  79190. low = (unsigned)(-1); /* trigger new sub-table when len > root */
  79191. used = 1U << root; /* use root table entries */
  79192. mask = used - 1; /* mask for comparing low */
  79193. if (type == LENS && used >= ENOUGH - MAXD)
  79194. return 1;
  79195. for (;;) {
  79196. thisx.bits = (unsigned char)(len - drop);
  79197. if ((int)(work[sym]) < end) {
  79198. thisx.op = (unsigned char)0;
  79199. thisx.val = work[sym];
  79200. }
  79201. else if ((int)(work[sym]) > end) {
  79202. thisx.op = (unsigned char)(extra[work[sym]]);
  79203. thisx.val = base[work[sym]];
  79204. }
  79205. else {
  79206. thisx.op = (unsigned char)(32 + 64); /* end of block */
  79207. thisx.val = 0;
  79208. }
  79209. incr = 1U << (len - drop);
  79210. fill = 1U << curr;
  79211. min = fill; /* save offset to next table */
  79212. do {
  79213. fill -= incr;
  79214. next[(huff >> drop) + fill] = thisx;
  79215. } while (fill != 0);
  79216. incr = 1U << (len - 1);
  79217. while (huff & incr)
  79218. incr >>= 1;
  79219. if (incr != 0) {
  79220. huff &= incr - 1;
  79221. huff += incr;
  79222. }
  79223. else
  79224. huff = 0;
  79225. sym++;
  79226. if (--(count[len]) == 0) {
  79227. if (len == max) break;
  79228. len = lens[work[sym]];
  79229. }
  79230. if (len > root && (huff & mask) != low) {
  79231. if (drop == 0)
  79232. drop = root;
  79233. next += min; /* here min is 1 << curr */
  79234. curr = len - drop;
  79235. left = (int)(1 << curr);
  79236. while (curr + drop < max) {
  79237. left -= count[curr + drop];
  79238. if (left <= 0) break;
  79239. curr++;
  79240. left <<= 1;
  79241. }
  79242. used += 1U << curr;
  79243. if (type == LENS && used >= ENOUGH - MAXD)
  79244. return 1;
  79245. low = huff & mask;
  79246. (*table)[low].op = (unsigned char)curr;
  79247. (*table)[low].bits = (unsigned char)root;
  79248. (*table)[low].val = (unsigned short)(next - *table);
  79249. }
  79250. }
  79251. thisx.op = (unsigned char)64; /* invalid code marker */
  79252. thisx.bits = (unsigned char)(len - drop);
  79253. thisx.val = (unsigned short)0;
  79254. while (huff != 0) {
  79255. if (drop != 0 && (huff & mask) != low) {
  79256. drop = 0;
  79257. len = root;
  79258. next = *table;
  79259. thisx.bits = (unsigned char)len;
  79260. }
  79261. next[huff >> drop] = thisx;
  79262. incr = 1U << (len - 1);
  79263. while (huff & incr)
  79264. incr >>= 1;
  79265. if (incr != 0) {
  79266. huff &= incr - 1;
  79267. huff += incr;
  79268. }
  79269. else
  79270. huff = 0;
  79271. }
  79272. *table += used;
  79273. *bits = root;
  79274. return 0;
  79275. }
  79276. /*** End of inlined file: inftrees.c ***/
  79277. /*** Start of inlined file: trees.c ***/
  79278. #ifdef DEBUG
  79279. # include <ctype.h>
  79280. #endif
  79281. #define MAX_BL_BITS 7
  79282. #define END_BLOCK 256
  79283. #define REP_3_6 16
  79284. #define REPZ_3_10 17
  79285. #define REPZ_11_138 18
  79286. local const int extra_lbits[LENGTH_CODES] /* extra bits for each length code */
  79287. = {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};
  79288. local const int extra_dbits[D_CODES] /* extra bits for each distance code */
  79289. = {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};
  79290. local const int extra_blbits[BL_CODES]/* extra bits for each bit length code */
  79291. = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,3,7};
  79292. local const uch bl_order[BL_CODES]
  79293. = {16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15};
  79294. #define Buf_size (8 * 2*sizeof(char))
  79295. #define DIST_CODE_LEN 512 /* see definition of array dist_code below */
  79296. #if defined(GEN_TREES_H) || !defined(STDC)
  79297. local ct_data static_ltree[L_CODES+2];
  79298. local ct_data static_dtree[D_CODES];
  79299. uch _dist_code[DIST_CODE_LEN];
  79300. uch _length_code[MAX_MATCH-MIN_MATCH+1];
  79301. local int base_length[LENGTH_CODES];
  79302. local int base_dist[D_CODES];
  79303. #else
  79304. /*** Start of inlined file: trees.h ***/
  79305. local const ct_data static_ltree[L_CODES+2] = {
  79306. {{ 12},{ 8}}, {{140},{ 8}}, {{ 76},{ 8}}, {{204},{ 8}}, {{ 44},{ 8}},
  79307. {{172},{ 8}}, {{108},{ 8}}, {{236},{ 8}}, {{ 28},{ 8}}, {{156},{ 8}},
  79308. {{ 92},{ 8}}, {{220},{ 8}}, {{ 60},{ 8}}, {{188},{ 8}}, {{124},{ 8}},
  79309. {{252},{ 8}}, {{ 2},{ 8}}, {{130},{ 8}}, {{ 66},{ 8}}, {{194},{ 8}},
  79310. {{ 34},{ 8}}, {{162},{ 8}}, {{ 98},{ 8}}, {{226},{ 8}}, {{ 18},{ 8}},
  79311. {{146},{ 8}}, {{ 82},{ 8}}, {{210},{ 8}}, {{ 50},{ 8}}, {{178},{ 8}},
  79312. {{114},{ 8}}, {{242},{ 8}}, {{ 10},{ 8}}, {{138},{ 8}}, {{ 74},{ 8}},
  79313. {{202},{ 8}}, {{ 42},{ 8}}, {{170},{ 8}}, {{106},{ 8}}, {{234},{ 8}},
  79314. {{ 26},{ 8}}, {{154},{ 8}}, {{ 90},{ 8}}, {{218},{ 8}}, {{ 58},{ 8}},
  79315. {{186},{ 8}}, {{122},{ 8}}, {{250},{ 8}}, {{ 6},{ 8}}, {{134},{ 8}},
  79316. {{ 70},{ 8}}, {{198},{ 8}}, {{ 38},{ 8}}, {{166},{ 8}}, {{102},{ 8}},
  79317. {{230},{ 8}}, {{ 22},{ 8}}, {{150},{ 8}}, {{ 86},{ 8}}, {{214},{ 8}},
  79318. {{ 54},{ 8}}, {{182},{ 8}}, {{118},{ 8}}, {{246},{ 8}}, {{ 14},{ 8}},
  79319. {{142},{ 8}}, {{ 78},{ 8}}, {{206},{ 8}}, {{ 46},{ 8}}, {{174},{ 8}},
  79320. {{110},{ 8}}, {{238},{ 8}}, {{ 30},{ 8}}, {{158},{ 8}}, {{ 94},{ 8}},
  79321. {{222},{ 8}}, {{ 62},{ 8}}, {{190},{ 8}}, {{126},{ 8}}, {{254},{ 8}},
  79322. {{ 1},{ 8}}, {{129},{ 8}}, {{ 65},{ 8}}, {{193},{ 8}}, {{ 33},{ 8}},
  79323. {{161},{ 8}}, {{ 97},{ 8}}, {{225},{ 8}}, {{ 17},{ 8}}, {{145},{ 8}},
  79324. {{ 81},{ 8}}, {{209},{ 8}}, {{ 49},{ 8}}, {{177},{ 8}}, {{113},{ 8}},
  79325. {{241},{ 8}}, {{ 9},{ 8}}, {{137},{ 8}}, {{ 73},{ 8}}, {{201},{ 8}},
  79326. {{ 41},{ 8}}, {{169},{ 8}}, {{105},{ 8}}, {{233},{ 8}}, {{ 25},{ 8}},
  79327. {{153},{ 8}}, {{ 89},{ 8}}, {{217},{ 8}}, {{ 57},{ 8}}, {{185},{ 8}},
  79328. {{121},{ 8}}, {{249},{ 8}}, {{ 5},{ 8}}, {{133},{ 8}}, {{ 69},{ 8}},
  79329. {{197},{ 8}}, {{ 37},{ 8}}, {{165},{ 8}}, {{101},{ 8}}, {{229},{ 8}},
  79330. {{ 21},{ 8}}, {{149},{ 8}}, {{ 85},{ 8}}, {{213},{ 8}}, {{ 53},{ 8}},
  79331. {{181},{ 8}}, {{117},{ 8}}, {{245},{ 8}}, {{ 13},{ 8}}, {{141},{ 8}},
  79332. {{ 77},{ 8}}, {{205},{ 8}}, {{ 45},{ 8}}, {{173},{ 8}}, {{109},{ 8}},
  79333. {{237},{ 8}}, {{ 29},{ 8}}, {{157},{ 8}}, {{ 93},{ 8}}, {{221},{ 8}},
  79334. {{ 61},{ 8}}, {{189},{ 8}}, {{125},{ 8}}, {{253},{ 8}}, {{ 19},{ 9}},
  79335. {{275},{ 9}}, {{147},{ 9}}, {{403},{ 9}}, {{ 83},{ 9}}, {{339},{ 9}},
  79336. {{211},{ 9}}, {{467},{ 9}}, {{ 51},{ 9}}, {{307},{ 9}}, {{179},{ 9}},
  79337. {{435},{ 9}}, {{115},{ 9}}, {{371},{ 9}}, {{243},{ 9}}, {{499},{ 9}},
  79338. {{ 11},{ 9}}, {{267},{ 9}}, {{139},{ 9}}, {{395},{ 9}}, {{ 75},{ 9}},
  79339. {{331},{ 9}}, {{203},{ 9}}, {{459},{ 9}}, {{ 43},{ 9}}, {{299},{ 9}},
  79340. {{171},{ 9}}, {{427},{ 9}}, {{107},{ 9}}, {{363},{ 9}}, {{235},{ 9}},
  79341. {{491},{ 9}}, {{ 27},{ 9}}, {{283},{ 9}}, {{155},{ 9}}, {{411},{ 9}},
  79342. {{ 91},{ 9}}, {{347},{ 9}}, {{219},{ 9}}, {{475},{ 9}}, {{ 59},{ 9}},
  79343. {{315},{ 9}}, {{187},{ 9}}, {{443},{ 9}}, {{123},{ 9}}, {{379},{ 9}},
  79344. {{251},{ 9}}, {{507},{ 9}}, {{ 7},{ 9}}, {{263},{ 9}}, {{135},{ 9}},
  79345. {{391},{ 9}}, {{ 71},{ 9}}, {{327},{ 9}}, {{199},{ 9}}, {{455},{ 9}},
  79346. {{ 39},{ 9}}, {{295},{ 9}}, {{167},{ 9}}, {{423},{ 9}}, {{103},{ 9}},
  79347. {{359},{ 9}}, {{231},{ 9}}, {{487},{ 9}}, {{ 23},{ 9}}, {{279},{ 9}},
  79348. {{151},{ 9}}, {{407},{ 9}}, {{ 87},{ 9}}, {{343},{ 9}}, {{215},{ 9}},
  79349. {{471},{ 9}}, {{ 55},{ 9}}, {{311},{ 9}}, {{183},{ 9}}, {{439},{ 9}},
  79350. {{119},{ 9}}, {{375},{ 9}}, {{247},{ 9}}, {{503},{ 9}}, {{ 15},{ 9}},
  79351. {{271},{ 9}}, {{143},{ 9}}, {{399},{ 9}}, {{ 79},{ 9}}, {{335},{ 9}},
  79352. {{207},{ 9}}, {{463},{ 9}}, {{ 47},{ 9}}, {{303},{ 9}}, {{175},{ 9}},
  79353. {{431},{ 9}}, {{111},{ 9}}, {{367},{ 9}}, {{239},{ 9}}, {{495},{ 9}},
  79354. {{ 31},{ 9}}, {{287},{ 9}}, {{159},{ 9}}, {{415},{ 9}}, {{ 95},{ 9}},
  79355. {{351},{ 9}}, {{223},{ 9}}, {{479},{ 9}}, {{ 63},{ 9}}, {{319},{ 9}},
  79356. {{191},{ 9}}, {{447},{ 9}}, {{127},{ 9}}, {{383},{ 9}}, {{255},{ 9}},
  79357. {{511},{ 9}}, {{ 0},{ 7}}, {{ 64},{ 7}}, {{ 32},{ 7}}, {{ 96},{ 7}},
  79358. {{ 16},{ 7}}, {{ 80},{ 7}}, {{ 48},{ 7}}, {{112},{ 7}}, {{ 8},{ 7}},
  79359. {{ 72},{ 7}}, {{ 40},{ 7}}, {{104},{ 7}}, {{ 24},{ 7}}, {{ 88},{ 7}},
  79360. {{ 56},{ 7}}, {{120},{ 7}}, {{ 4},{ 7}}, {{ 68},{ 7}}, {{ 36},{ 7}},
  79361. {{100},{ 7}}, {{ 20},{ 7}}, {{ 84},{ 7}}, {{ 52},{ 7}}, {{116},{ 7}},
  79362. {{ 3},{ 8}}, {{131},{ 8}}, {{ 67},{ 8}}, {{195},{ 8}}, {{ 35},{ 8}},
  79363. {{163},{ 8}}, {{ 99},{ 8}}, {{227},{ 8}}
  79364. };
  79365. local const ct_data static_dtree[D_CODES] = {
  79366. {{ 0},{ 5}}, {{16},{ 5}}, {{ 8},{ 5}}, {{24},{ 5}}, {{ 4},{ 5}},
  79367. {{20},{ 5}}, {{12},{ 5}}, {{28},{ 5}}, {{ 2},{ 5}}, {{18},{ 5}},
  79368. {{10},{ 5}}, {{26},{ 5}}, {{ 6},{ 5}}, {{22},{ 5}}, {{14},{ 5}},
  79369. {{30},{ 5}}, {{ 1},{ 5}}, {{17},{ 5}}, {{ 9},{ 5}}, {{25},{ 5}},
  79370. {{ 5},{ 5}}, {{21},{ 5}}, {{13},{ 5}}, {{29},{ 5}}, {{ 3},{ 5}},
  79371. {{19},{ 5}}, {{11},{ 5}}, {{27},{ 5}}, {{ 7},{ 5}}, {{23},{ 5}}
  79372. };
  79373. const uch _dist_code[DIST_CODE_LEN] = {
  79374. 0, 1, 2, 3, 4, 4, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8,
  79375. 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10, 10, 10, 10, 10,
  79376. 10, 10, 10, 10, 10, 10, 10, 10, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11,
  79377. 11, 11, 11, 11, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
  79378. 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 13, 13, 13, 13,
  79379. 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
  79380. 13, 13, 13, 13, 13, 13, 13, 13, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
  79381. 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
  79382. 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
  79383. 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 15, 15, 15, 15, 15, 15, 15, 15,
  79384. 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
  79385. 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
  79386. 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 0, 0, 16, 17,
  79387. 18, 18, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 22, 22, 22, 22, 22, 22, 22, 22,
  79388. 23, 23, 23, 23, 23, 23, 23, 23, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
  79389. 24, 24, 24, 24, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
  79390. 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26,
  79391. 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 27, 27, 27, 27, 27, 27, 27, 27,
  79392. 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27,
  79393. 27, 27, 27, 27, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28,
  79394. 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28,
  79395. 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28,
  79396. 28, 28, 28, 28, 28, 28, 28, 28, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29,
  79397. 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29,
  79398. 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29,
  79399. 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29
  79400. };
  79401. const uch _length_code[MAX_MATCH-MIN_MATCH+1]= {
  79402. 0, 1, 2, 3, 4, 5, 6, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 12, 12,
  79403. 13, 13, 13, 13, 14, 14, 14, 14, 15, 15, 15, 15, 16, 16, 16, 16, 16, 16, 16, 16,
  79404. 17, 17, 17, 17, 17, 17, 17, 17, 18, 18, 18, 18, 18, 18, 18, 18, 19, 19, 19, 19,
  79405. 19, 19, 19, 19, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
  79406. 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 22, 22, 22, 22,
  79407. 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 23, 23, 23, 23, 23, 23, 23, 23,
  79408. 23, 23, 23, 23, 23, 23, 23, 23, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
  79409. 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
  79410. 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
  79411. 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 26, 26, 26, 26, 26, 26, 26, 26,
  79412. 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26,
  79413. 26, 26, 26, 26, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27,
  79414. 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 28
  79415. };
  79416. local const int base_length[LENGTH_CODES] = {
  79417. 0, 1, 2, 3, 4, 5, 6, 7, 8, 10, 12, 14, 16, 20, 24, 28, 32, 40, 48, 56,
  79418. 64, 80, 96, 112, 128, 160, 192, 224, 0
  79419. };
  79420. local const int base_dist[D_CODES] = {
  79421. 0, 1, 2, 3, 4, 6, 8, 12, 16, 24,
  79422. 32, 48, 64, 96, 128, 192, 256, 384, 512, 768,
  79423. 1024, 1536, 2048, 3072, 4096, 6144, 8192, 12288, 16384, 24576
  79424. };
  79425. /*** End of inlined file: trees.h ***/
  79426. #endif /* GEN_TREES_H */
  79427. struct static_tree_desc_s {
  79428. const ct_data *static_tree; /* static tree or NULL */
  79429. const intf *extra_bits; /* extra bits for each code or NULL */
  79430. int extra_base; /* base index for extra_bits */
  79431. int elems; /* max number of elements in the tree */
  79432. int max_length; /* max bit length for the codes */
  79433. };
  79434. local static_tree_desc static_l_desc =
  79435. {static_ltree, extra_lbits, LITERALS+1, L_CODES, MAX_BITS};
  79436. local static_tree_desc static_d_desc =
  79437. {static_dtree, extra_dbits, 0, D_CODES, MAX_BITS};
  79438. local static_tree_desc static_bl_desc =
  79439. {(const ct_data *)0, extra_blbits, 0, BL_CODES, MAX_BL_BITS};
  79440. local void tr_static_init OF((void));
  79441. local void init_block OF((deflate_state *s));
  79442. local void pqdownheap OF((deflate_state *s, ct_data *tree, int k));
  79443. local void gen_bitlen OF((deflate_state *s, tree_desc *desc));
  79444. local void gen_codes OF((ct_data *tree, int max_code, ushf *bl_count));
  79445. local void build_tree OF((deflate_state *s, tree_desc *desc));
  79446. local void scan_tree OF((deflate_state *s, ct_data *tree, int max_code));
  79447. local void send_tree OF((deflate_state *s, ct_data *tree, int max_code));
  79448. local int build_bl_tree OF((deflate_state *s));
  79449. local void send_all_trees OF((deflate_state *s, int lcodes, int dcodes,
  79450. int blcodes));
  79451. local void compress_block OF((deflate_state *s, ct_data *ltree,
  79452. ct_data *dtree));
  79453. local void set_data_type OF((deflate_state *s));
  79454. local unsigned bi_reverse OF((unsigned value, int length));
  79455. local void bi_windup OF((deflate_state *s));
  79456. local void bi_flush OF((deflate_state *s));
  79457. local void copy_block OF((deflate_state *s, charf *buf, unsigned len,
  79458. int header));
  79459. #ifdef GEN_TREES_H
  79460. local void gen_trees_header OF((void));
  79461. #endif
  79462. #ifndef DEBUG
  79463. # define send_code(s, c, tree) send_bits(s, tree[c].Code, tree[c].Len)
  79464. #else /* DEBUG */
  79465. # define send_code(s, c, tree) \
  79466. { if (z_verbose>2) fprintf(stderr,"\ncd %3d ",(c)); \
  79467. send_bits(s, tree[c].Code, tree[c].Len); }
  79468. #endif
  79469. #define put_short(s, w) { \
  79470. put_byte(s, (uch)((w) & 0xff)); \
  79471. put_byte(s, (uch)((ush)(w) >> 8)); \
  79472. }
  79473. #ifdef DEBUG
  79474. local void send_bits OF((deflate_state *s, int value, int length));
  79475. local void send_bits (deflate_state *s, int value, int length)
  79476. {
  79477. Tracevv((stderr," l %2d v %4x ", length, value));
  79478. Assert(length > 0 && length <= 15, "invalid length");
  79479. s->bits_sent += (ulg)length;
  79480. if (s->bi_valid > (int)Buf_size - length) {
  79481. s->bi_buf |= (value << s->bi_valid);
  79482. put_short(s, s->bi_buf);
  79483. s->bi_buf = (ush)value >> (Buf_size - s->bi_valid);
  79484. s->bi_valid += length - Buf_size;
  79485. } else {
  79486. s->bi_buf |= value << s->bi_valid;
  79487. s->bi_valid += length;
  79488. }
  79489. }
  79490. #else /* !DEBUG */
  79491. #define send_bits(s, value, length) \
  79492. { int len = length;\
  79493. if (s->bi_valid > (int)Buf_size - len) {\
  79494. int val = value;\
  79495. s->bi_buf |= (val << s->bi_valid);\
  79496. put_short(s, s->bi_buf);\
  79497. s->bi_buf = (ush)val >> (Buf_size - s->bi_valid);\
  79498. s->bi_valid += len - Buf_size;\
  79499. } else {\
  79500. s->bi_buf |= (value) << s->bi_valid;\
  79501. s->bi_valid += len;\
  79502. }\
  79503. }
  79504. #endif /* DEBUG */
  79505. local void tr_static_init()
  79506. {
  79507. #if defined(GEN_TREES_H) || !defined(STDC)
  79508. static int static_init_done = 0;
  79509. int n; /* iterates over tree elements */
  79510. int bits; /* bit counter */
  79511. int length; /* length value */
  79512. int code; /* code value */
  79513. int dist; /* distance index */
  79514. ush bl_count[MAX_BITS+1];
  79515. if (static_init_done) return;
  79516. static_l_desc.static_tree = static_ltree;
  79517. static_l_desc.extra_bits = extra_lbits;
  79518. static_d_desc.static_tree = static_dtree;
  79519. static_d_desc.extra_bits = extra_dbits;
  79520. static_bl_desc.extra_bits = extra_blbits;
  79521. length = 0;
  79522. for (code = 0; code < LENGTH_CODES-1; code++) {
  79523. base_length[code] = length;
  79524. for (n = 0; n < (1<<extra_lbits[code]); n++) {
  79525. _length_code[length++] = (uch)code;
  79526. }
  79527. }
  79528. Assert (length == 256, "tr_static_init: length != 256");
  79529. _length_code[length-1] = (uch)code;
  79530. dist = 0;
  79531. for (code = 0 ; code < 16; code++) {
  79532. base_dist[code] = dist;
  79533. for (n = 0; n < (1<<extra_dbits[code]); n++) {
  79534. _dist_code[dist++] = (uch)code;
  79535. }
  79536. }
  79537. Assert (dist == 256, "tr_static_init: dist != 256");
  79538. dist >>= 7; /* from now on, all distances are divided by 128 */
  79539. for ( ; code < D_CODES; code++) {
  79540. base_dist[code] = dist << 7;
  79541. for (n = 0; n < (1<<(extra_dbits[code]-7)); n++) {
  79542. _dist_code[256 + dist++] = (uch)code;
  79543. }
  79544. }
  79545. Assert (dist == 256, "tr_static_init: 256+dist != 512");
  79546. for (bits = 0; bits <= MAX_BITS; bits++) bl_count[bits] = 0;
  79547. n = 0;
  79548. while (n <= 143) static_ltree[n++].Len = 8, bl_count[8]++;
  79549. while (n <= 255) static_ltree[n++].Len = 9, bl_count[9]++;
  79550. while (n <= 279) static_ltree[n++].Len = 7, bl_count[7]++;
  79551. while (n <= 287) static_ltree[n++].Len = 8, bl_count[8]++;
  79552. gen_codes((ct_data *)static_ltree, L_CODES+1, bl_count);
  79553. for (n = 0; n < D_CODES; n++) {
  79554. static_dtree[n].Len = 5;
  79555. static_dtree[n].Code = bi_reverse((unsigned)n, 5);
  79556. }
  79557. static_init_done = 1;
  79558. # ifdef GEN_TREES_H
  79559. gen_trees_header();
  79560. # endif
  79561. #endif /* defined(GEN_TREES_H) || !defined(STDC) */
  79562. }
  79563. #ifdef GEN_TREES_H
  79564. # ifndef DEBUG
  79565. # include <stdio.h>
  79566. # endif
  79567. # define SEPARATOR(i, last, width) \
  79568. ((i) == (last)? "\n};\n\n" : \
  79569. ((i) % (width) == (width)-1 ? ",\n" : ", "))
  79570. void gen_trees_header()
  79571. {
  79572. FILE *header = fopen("trees.h", "w");
  79573. int i;
  79574. Assert (header != NULL, "Can't open trees.h");
  79575. fprintf(header,
  79576. "/* header created automatically with -DGEN_TREES_H */\n\n");
  79577. fprintf(header, "local const ct_data static_ltree[L_CODES+2] = {\n");
  79578. for (i = 0; i < L_CODES+2; i++) {
  79579. fprintf(header, "{{%3u},{%3u}}%s", static_ltree[i].Code,
  79580. static_ltree[i].Len, SEPARATOR(i, L_CODES+1, 5));
  79581. }
  79582. fprintf(header, "local const ct_data static_dtree[D_CODES] = {\n");
  79583. for (i = 0; i < D_CODES; i++) {
  79584. fprintf(header, "{{%2u},{%2u}}%s", static_dtree[i].Code,
  79585. static_dtree[i].Len, SEPARATOR(i, D_CODES-1, 5));
  79586. }
  79587. fprintf(header, "const uch _dist_code[DIST_CODE_LEN] = {\n");
  79588. for (i = 0; i < DIST_CODE_LEN; i++) {
  79589. fprintf(header, "%2u%s", _dist_code[i],
  79590. SEPARATOR(i, DIST_CODE_LEN-1, 20));
  79591. }
  79592. fprintf(header, "const uch _length_code[MAX_MATCH-MIN_MATCH+1]= {\n");
  79593. for (i = 0; i < MAX_MATCH-MIN_MATCH+1; i++) {
  79594. fprintf(header, "%2u%s", _length_code[i],
  79595. SEPARATOR(i, MAX_MATCH-MIN_MATCH, 20));
  79596. }
  79597. fprintf(header, "local const int base_length[LENGTH_CODES] = {\n");
  79598. for (i = 0; i < LENGTH_CODES; i++) {
  79599. fprintf(header, "%1u%s", base_length[i],
  79600. SEPARATOR(i, LENGTH_CODES-1, 20));
  79601. }
  79602. fprintf(header, "local const int base_dist[D_CODES] = {\n");
  79603. for (i = 0; i < D_CODES; i++) {
  79604. fprintf(header, "%5u%s", base_dist[i],
  79605. SEPARATOR(i, D_CODES-1, 10));
  79606. }
  79607. fclose(header);
  79608. }
  79609. #endif /* GEN_TREES_H */
  79610. void _tr_init(deflate_state *s)
  79611. {
  79612. tr_static_init();
  79613. s->l_desc.dyn_tree = s->dyn_ltree;
  79614. s->l_desc.stat_desc = &static_l_desc;
  79615. s->d_desc.dyn_tree = s->dyn_dtree;
  79616. s->d_desc.stat_desc = &static_d_desc;
  79617. s->bl_desc.dyn_tree = s->bl_tree;
  79618. s->bl_desc.stat_desc = &static_bl_desc;
  79619. s->bi_buf = 0;
  79620. s->bi_valid = 0;
  79621. s->last_eob_len = 8; /* enough lookahead for inflate */
  79622. #ifdef DEBUG
  79623. s->compressed_len = 0L;
  79624. s->bits_sent = 0L;
  79625. #endif
  79626. init_block(s);
  79627. }
  79628. local void init_block (deflate_state *s)
  79629. {
  79630. int n; /* iterates over tree elements */
  79631. for (n = 0; n < L_CODES; n++) s->dyn_ltree[n].Freq = 0;
  79632. for (n = 0; n < D_CODES; n++) s->dyn_dtree[n].Freq = 0;
  79633. for (n = 0; n < BL_CODES; n++) s->bl_tree[n].Freq = 0;
  79634. s->dyn_ltree[END_BLOCK].Freq = 1;
  79635. s->opt_len = s->static_len = 0L;
  79636. s->last_lit = s->matches = 0;
  79637. }
  79638. #define SMALLEST 1
  79639. #define pqremove(s, tree, top) \
  79640. {\
  79641. top = s->heap[SMALLEST]; \
  79642. s->heap[SMALLEST] = s->heap[s->heap_len--]; \
  79643. pqdownheap(s, tree, SMALLEST); \
  79644. }
  79645. #define smaller(tree, n, m, depth) \
  79646. (tree[n].Freq < tree[m].Freq || \
  79647. (tree[n].Freq == tree[m].Freq && depth[n] <= depth[m]))
  79648. local void pqdownheap (deflate_state *s,
  79649. ct_data *tree, /* the tree to restore */
  79650. int k) /* node to move down */
  79651. {
  79652. int v = s->heap[k];
  79653. int j = k << 1; /* left son of k */
  79654. while (j <= s->heap_len) {
  79655. if (j < s->heap_len &&
  79656. smaller(tree, s->heap[j+1], s->heap[j], s->depth)) {
  79657. j++;
  79658. }
  79659. if (smaller(tree, v, s->heap[j], s->depth)) break;
  79660. s->heap[k] = s->heap[j]; k = j;
  79661. j <<= 1;
  79662. }
  79663. s->heap[k] = v;
  79664. }
  79665. local void gen_bitlen (deflate_state *s, tree_desc *desc)
  79666. {
  79667. ct_data *tree = desc->dyn_tree;
  79668. int max_code = desc->max_code;
  79669. const ct_data *stree = desc->stat_desc->static_tree;
  79670. const intf *extra = desc->stat_desc->extra_bits;
  79671. int base = desc->stat_desc->extra_base;
  79672. int max_length = desc->stat_desc->max_length;
  79673. int h; /* heap index */
  79674. int n, m; /* iterate over the tree elements */
  79675. int bits; /* bit length */
  79676. int xbits; /* extra bits */
  79677. ush f; /* frequency */
  79678. int overflow = 0; /* number of elements with bit length too large */
  79679. for (bits = 0; bits <= MAX_BITS; bits++) s->bl_count[bits] = 0;
  79680. tree[s->heap[s->heap_max]].Len = 0; /* root of the heap */
  79681. for (h = s->heap_max+1; h < HEAP_SIZE; h++) {
  79682. n = s->heap[h];
  79683. bits = tree[tree[n].Dad].Len + 1;
  79684. if (bits > max_length) bits = max_length, overflow++;
  79685. tree[n].Len = (ush)bits;
  79686. if (n > max_code) continue; /* not a leaf node */
  79687. s->bl_count[bits]++;
  79688. xbits = 0;
  79689. if (n >= base) xbits = extra[n-base];
  79690. f = tree[n].Freq;
  79691. s->opt_len += (ulg)f * (bits + xbits);
  79692. if (stree) s->static_len += (ulg)f * (stree[n].Len + xbits);
  79693. }
  79694. if (overflow == 0) return;
  79695. Trace((stderr,"\nbit length overflow\n"));
  79696. do {
  79697. bits = max_length-1;
  79698. while (s->bl_count[bits] == 0) bits--;
  79699. s->bl_count[bits]--; /* move one leaf down the tree */
  79700. s->bl_count[bits+1] += 2; /* move one overflow item as its brother */
  79701. s->bl_count[max_length]--;
  79702. overflow -= 2;
  79703. } while (overflow > 0);
  79704. for (bits = max_length; bits != 0; bits--) {
  79705. n = s->bl_count[bits];
  79706. while (n != 0) {
  79707. m = s->heap[--h];
  79708. if (m > max_code) continue;
  79709. if ((unsigned) tree[m].Len != (unsigned) bits) {
  79710. Trace((stderr,"code %d bits %d->%d\n", m, tree[m].Len, bits));
  79711. s->opt_len += ((long)bits - (long)tree[m].Len)
  79712. *(long)tree[m].Freq;
  79713. tree[m].Len = (ush)bits;
  79714. }
  79715. n--;
  79716. }
  79717. }
  79718. }
  79719. local void gen_codes (ct_data *tree, /* the tree to decorate */
  79720. int max_code, /* largest code with non zero frequency */
  79721. ushf *bl_count) /* number of codes at each bit length */
  79722. {
  79723. ush next_code[MAX_BITS+1]; /* next code value for each bit length */
  79724. ush code = 0; /* running code value */
  79725. int bits; /* bit index */
  79726. int n; /* code index */
  79727. for (bits = 1; bits <= MAX_BITS; bits++) {
  79728. next_code[bits] = code = (code + bl_count[bits-1]) << 1;
  79729. }
  79730. Assert (code + bl_count[MAX_BITS]-1 == (1<<MAX_BITS)-1,
  79731. "inconsistent bit counts");
  79732. Tracev((stderr,"\ngen_codes: max_code %d ", max_code));
  79733. for (n = 0; n <= max_code; n++) {
  79734. int len = tree[n].Len;
  79735. if (len == 0) continue;
  79736. tree[n].Code = bi_reverse(next_code[len]++, len);
  79737. Tracecv(tree != static_ltree, (stderr,"\nn %3d %c l %2d c %4x (%x) ",
  79738. n, (isgraph(n) ? n : ' '), len, tree[n].Code, next_code[len]-1));
  79739. }
  79740. }
  79741. local void build_tree (deflate_state *s,
  79742. tree_desc *desc) /* the tree descriptor */
  79743. {
  79744. ct_data *tree = desc->dyn_tree;
  79745. const ct_data *stree = desc->stat_desc->static_tree;
  79746. int elems = desc->stat_desc->elems;
  79747. int n, m; /* iterate over heap elements */
  79748. int max_code = -1; /* largest code with non zero frequency */
  79749. int node; /* new node being created */
  79750. s->heap_len = 0, s->heap_max = HEAP_SIZE;
  79751. for (n = 0; n < elems; n++) {
  79752. if (tree[n].Freq != 0) {
  79753. s->heap[++(s->heap_len)] = max_code = n;
  79754. s->depth[n] = 0;
  79755. } else {
  79756. tree[n].Len = 0;
  79757. }
  79758. }
  79759. while (s->heap_len < 2) {
  79760. node = s->heap[++(s->heap_len)] = (max_code < 2 ? ++max_code : 0);
  79761. tree[node].Freq = 1;
  79762. s->depth[node] = 0;
  79763. s->opt_len--; if (stree) s->static_len -= stree[node].Len;
  79764. }
  79765. desc->max_code = max_code;
  79766. for (n = s->heap_len/2; n >= 1; n--) pqdownheap(s, tree, n);
  79767. node = elems; /* next internal node of the tree */
  79768. do {
  79769. pqremove(s, tree, n); /* n = node of least frequency */
  79770. m = s->heap[SMALLEST]; /* m = node of next least frequency */
  79771. s->heap[--(s->heap_max)] = n; /* keep the nodes sorted by frequency */
  79772. s->heap[--(s->heap_max)] = m;
  79773. tree[node].Freq = tree[n].Freq + tree[m].Freq;
  79774. s->depth[node] = (uch)((s->depth[n] >= s->depth[m] ?
  79775. s->depth[n] : s->depth[m]) + 1);
  79776. tree[n].Dad = tree[m].Dad = (ush)node;
  79777. #ifdef DUMP_BL_TREE
  79778. if (tree == s->bl_tree) {
  79779. fprintf(stderr,"\nnode %d(%d), sons %d(%d) %d(%d)",
  79780. node, tree[node].Freq, n, tree[n].Freq, m, tree[m].Freq);
  79781. }
  79782. #endif
  79783. s->heap[SMALLEST] = node++;
  79784. pqdownheap(s, tree, SMALLEST);
  79785. } while (s->heap_len >= 2);
  79786. s->heap[--(s->heap_max)] = s->heap[SMALLEST];
  79787. gen_bitlen(s, (tree_desc *)desc);
  79788. gen_codes ((ct_data *)tree, max_code, s->bl_count);
  79789. }
  79790. local void scan_tree (deflate_state *s,
  79791. ct_data *tree, /* the tree to be scanned */
  79792. int max_code) /* and its largest code of non zero frequency */
  79793. {
  79794. int n; /* iterates over all tree elements */
  79795. int prevlen = -1; /* last emitted length */
  79796. int curlen; /* length of current code */
  79797. int nextlen = tree[0].Len; /* length of next code */
  79798. int count = 0; /* repeat count of the current code */
  79799. int max_count = 7; /* max repeat count */
  79800. int min_count = 4; /* min repeat count */
  79801. if (nextlen == 0) max_count = 138, min_count = 3;
  79802. tree[max_code+1].Len = (ush)0xffff; /* guard */
  79803. for (n = 0; n <= max_code; n++) {
  79804. curlen = nextlen; nextlen = tree[n+1].Len;
  79805. if (++count < max_count && curlen == nextlen) {
  79806. continue;
  79807. } else if (count < min_count) {
  79808. s->bl_tree[curlen].Freq += count;
  79809. } else if (curlen != 0) {
  79810. if (curlen != prevlen) s->bl_tree[curlen].Freq++;
  79811. s->bl_tree[REP_3_6].Freq++;
  79812. } else if (count <= 10) {
  79813. s->bl_tree[REPZ_3_10].Freq++;
  79814. } else {
  79815. s->bl_tree[REPZ_11_138].Freq++;
  79816. }
  79817. count = 0; prevlen = curlen;
  79818. if (nextlen == 0) {
  79819. max_count = 138, min_count = 3;
  79820. } else if (curlen == nextlen) {
  79821. max_count = 6, min_count = 3;
  79822. } else {
  79823. max_count = 7, min_count = 4;
  79824. }
  79825. }
  79826. }
  79827. local void send_tree (deflate_state *s,
  79828. ct_data *tree, /* the tree to be scanned */
  79829. int max_code) /* and its largest code of non zero frequency */
  79830. {
  79831. int n; /* iterates over all tree elements */
  79832. int prevlen = -1; /* last emitted length */
  79833. int curlen; /* length of current code */
  79834. int nextlen = tree[0].Len; /* length of next code */
  79835. int count = 0; /* repeat count of the current code */
  79836. int max_count = 7; /* max repeat count */
  79837. int min_count = 4; /* min repeat count */
  79838. /* guard already set */
  79839. if (nextlen == 0) max_count = 138, min_count = 3;
  79840. for (n = 0; n <= max_code; n++) {
  79841. curlen = nextlen; nextlen = tree[n+1].Len;
  79842. if (++count < max_count && curlen == nextlen) {
  79843. continue;
  79844. } else if (count < min_count) {
  79845. do { send_code(s, curlen, s->bl_tree); } while (--count != 0);
  79846. } else if (curlen != 0) {
  79847. if (curlen != prevlen) {
  79848. send_code(s, curlen, s->bl_tree); count--;
  79849. }
  79850. Assert(count >= 3 && count <= 6, " 3_6?");
  79851. send_code(s, REP_3_6, s->bl_tree); send_bits(s, count-3, 2);
  79852. } else if (count <= 10) {
  79853. send_code(s, REPZ_3_10, s->bl_tree); send_bits(s, count-3, 3);
  79854. } else {
  79855. send_code(s, REPZ_11_138, s->bl_tree); send_bits(s, count-11, 7);
  79856. }
  79857. count = 0; prevlen = curlen;
  79858. if (nextlen == 0) {
  79859. max_count = 138, min_count = 3;
  79860. } else if (curlen == nextlen) {
  79861. max_count = 6, min_count = 3;
  79862. } else {
  79863. max_count = 7, min_count = 4;
  79864. }
  79865. }
  79866. }
  79867. local int build_bl_tree (deflate_state *s)
  79868. {
  79869. int max_blindex; /* index of last bit length code of non zero freq */
  79870. scan_tree(s, (ct_data *)s->dyn_ltree, s->l_desc.max_code);
  79871. scan_tree(s, (ct_data *)s->dyn_dtree, s->d_desc.max_code);
  79872. build_tree(s, (tree_desc *)(&(s->bl_desc)));
  79873. for (max_blindex = BL_CODES-1; max_blindex >= 3; max_blindex--) {
  79874. if (s->bl_tree[bl_order[max_blindex]].Len != 0) break;
  79875. }
  79876. s->opt_len += 3*(max_blindex+1) + 5+5+4;
  79877. Tracev((stderr, "\ndyn trees: dyn %ld, stat %ld",
  79878. s->opt_len, s->static_len));
  79879. return max_blindex;
  79880. }
  79881. local void send_all_trees (deflate_state *s,
  79882. int lcodes, int dcodes, int blcodes) /* number of codes for each tree */
  79883. {
  79884. int rank; /* index in bl_order */
  79885. Assert (lcodes >= 257 && dcodes >= 1 && blcodes >= 4, "not enough codes");
  79886. Assert (lcodes <= L_CODES && dcodes <= D_CODES && blcodes <= BL_CODES,
  79887. "too many codes");
  79888. Tracev((stderr, "\nbl counts: "));
  79889. send_bits(s, lcodes-257, 5); /* not +255 as stated in appnote.txt */
  79890. send_bits(s, dcodes-1, 5);
  79891. send_bits(s, blcodes-4, 4); /* not -3 as stated in appnote.txt */
  79892. for (rank = 0; rank < blcodes; rank++) {
  79893. Tracev((stderr, "\nbl code %2d ", bl_order[rank]));
  79894. send_bits(s, s->bl_tree[bl_order[rank]].Len, 3);
  79895. }
  79896. Tracev((stderr, "\nbl tree: sent %ld", s->bits_sent));
  79897. send_tree(s, (ct_data *)s->dyn_ltree, lcodes-1); /* literal tree */
  79898. Tracev((stderr, "\nlit tree: sent %ld", s->bits_sent));
  79899. send_tree(s, (ct_data *)s->dyn_dtree, dcodes-1); /* distance tree */
  79900. Tracev((stderr, "\ndist tree: sent %ld", s->bits_sent));
  79901. }
  79902. void _tr_stored_block (deflate_state *s, charf *buf, ulg stored_len, int eof)
  79903. {
  79904. send_bits(s, (STORED_BLOCK<<1)+eof, 3); /* send block type */
  79905. #ifdef DEBUG
  79906. s->compressed_len = (s->compressed_len + 3 + 7) & (ulg)~7L;
  79907. s->compressed_len += (stored_len + 4) << 3;
  79908. #endif
  79909. copy_block(s, buf, (unsigned)stored_len, 1); /* with header */
  79910. }
  79911. void _tr_align (deflate_state *s)
  79912. {
  79913. send_bits(s, STATIC_TREES<<1, 3);
  79914. send_code(s, END_BLOCK, static_ltree);
  79915. #ifdef DEBUG
  79916. s->compressed_len += 10L; /* 3 for block type, 7 for EOB */
  79917. #endif
  79918. bi_flush(s);
  79919. if (1 + s->last_eob_len + 10 - s->bi_valid < 9) {
  79920. send_bits(s, STATIC_TREES<<1, 3);
  79921. send_code(s, END_BLOCK, static_ltree);
  79922. #ifdef DEBUG
  79923. s->compressed_len += 10L;
  79924. #endif
  79925. bi_flush(s);
  79926. }
  79927. s->last_eob_len = 7;
  79928. }
  79929. void _tr_flush_block (deflate_state *s,
  79930. charf *buf, /* input block, or NULL if too old */
  79931. ulg stored_len, /* length of input block */
  79932. int eof) /* true if this is the last block for a file */
  79933. {
  79934. ulg opt_lenb, static_lenb; /* opt_len and static_len in bytes */
  79935. int max_blindex = 0; /* index of last bit length code of non zero freq */
  79936. if (s->level > 0) {
  79937. if (stored_len > 0 && s->strm->data_type == Z_UNKNOWN)
  79938. set_data_type(s);
  79939. build_tree(s, (tree_desc *)(&(s->l_desc)));
  79940. Tracev((stderr, "\nlit data: dyn %ld, stat %ld", s->opt_len,
  79941. s->static_len));
  79942. build_tree(s, (tree_desc *)(&(s->d_desc)));
  79943. Tracev((stderr, "\ndist data: dyn %ld, stat %ld", s->opt_len,
  79944. s->static_len));
  79945. max_blindex = build_bl_tree(s);
  79946. opt_lenb = (s->opt_len+3+7)>>3;
  79947. static_lenb = (s->static_len+3+7)>>3;
  79948. Tracev((stderr, "\nopt %lu(%lu) stat %lu(%lu) stored %lu lit %u ",
  79949. opt_lenb, s->opt_len, static_lenb, s->static_len, stored_len,
  79950. s->last_lit));
  79951. if (static_lenb <= opt_lenb) opt_lenb = static_lenb;
  79952. } else {
  79953. Assert(buf != (char*)0, "lost buf");
  79954. opt_lenb = static_lenb = stored_len + 5; /* force a stored block */
  79955. }
  79956. #ifdef FORCE_STORED
  79957. if (buf != (char*)0) { /* force stored block */
  79958. #else
  79959. if (stored_len+4 <= opt_lenb && buf != (char*)0) {
  79960. #endif
  79961. _tr_stored_block(s, buf, stored_len, eof);
  79962. #ifdef FORCE_STATIC
  79963. } else if (static_lenb >= 0) { /* force static trees */
  79964. #else
  79965. } else if (s->strategy == Z_FIXED || static_lenb == opt_lenb) {
  79966. #endif
  79967. send_bits(s, (STATIC_TREES<<1)+eof, 3);
  79968. compress_block(s, (ct_data *)static_ltree, (ct_data *)static_dtree);
  79969. #ifdef DEBUG
  79970. s->compressed_len += 3 + s->static_len;
  79971. #endif
  79972. } else {
  79973. send_bits(s, (DYN_TREES<<1)+eof, 3);
  79974. send_all_trees(s, s->l_desc.max_code+1, s->d_desc.max_code+1,
  79975. max_blindex+1);
  79976. compress_block(s, (ct_data *)s->dyn_ltree, (ct_data *)s->dyn_dtree);
  79977. #ifdef DEBUG
  79978. s->compressed_len += 3 + s->opt_len;
  79979. #endif
  79980. }
  79981. Assert (s->compressed_len == s->bits_sent, "bad compressed size");
  79982. init_block(s);
  79983. if (eof) {
  79984. bi_windup(s);
  79985. #ifdef DEBUG
  79986. s->compressed_len += 7; /* align on byte boundary */
  79987. #endif
  79988. }
  79989. Tracev((stderr,"\ncomprlen %lu(%lu) ", s->compressed_len>>3,
  79990. s->compressed_len-7*eof));
  79991. }
  79992. int _tr_tally (deflate_state *s,
  79993. unsigned dist, /* distance of matched string */
  79994. unsigned lc) /* match length-MIN_MATCH or unmatched char (if dist==0) */
  79995. {
  79996. s->d_buf[s->last_lit] = (ush)dist;
  79997. s->l_buf[s->last_lit++] = (uch)lc;
  79998. if (dist == 0) {
  79999. s->dyn_ltree[lc].Freq++;
  80000. } else {
  80001. s->matches++;
  80002. dist--; /* dist = match distance - 1 */
  80003. Assert((ush)dist < (ush)MAX_DIST(s) &&
  80004. (ush)lc <= (ush)(MAX_MATCH-MIN_MATCH) &&
  80005. (ush)d_code(dist) < (ush)D_CODES, "_tr_tally: bad match");
  80006. s->dyn_ltree[_length_code[lc]+LITERALS+1].Freq++;
  80007. s->dyn_dtree[d_code(dist)].Freq++;
  80008. }
  80009. #ifdef TRUNCATE_BLOCK
  80010. if ((s->last_lit & 0x1fff) == 0 && s->level > 2) {
  80011. ulg out_length = (ulg)s->last_lit*8L;
  80012. ulg in_length = (ulg)((long)s->strstart - s->block_start);
  80013. int dcode;
  80014. for (dcode = 0; dcode < D_CODES; dcode++) {
  80015. out_length += (ulg)s->dyn_dtree[dcode].Freq *
  80016. (5L+extra_dbits[dcode]);
  80017. }
  80018. out_length >>= 3;
  80019. Tracev((stderr,"\nlast_lit %u, in %ld, out ~%ld(%ld%%) ",
  80020. s->last_lit, in_length, out_length,
  80021. 100L - out_length*100L/in_length));
  80022. if (s->matches < s->last_lit/2 && out_length < in_length/2) return 1;
  80023. }
  80024. #endif
  80025. return (s->last_lit == s->lit_bufsize-1);
  80026. }
  80027. local void compress_block (deflate_state *s,
  80028. ct_data *ltree, /* literal tree */
  80029. ct_data *dtree) /* distance tree */
  80030. {
  80031. unsigned dist; /* distance of matched string */
  80032. int lc; /* match length or unmatched char (if dist == 0) */
  80033. unsigned lx = 0; /* running index in l_buf */
  80034. unsigned code; /* the code to send */
  80035. int extra; /* number of extra bits to send */
  80036. if (s->last_lit != 0) do {
  80037. dist = s->d_buf[lx];
  80038. lc = s->l_buf[lx++];
  80039. if (dist == 0) {
  80040. send_code(s, lc, ltree); /* send a literal byte */
  80041. Tracecv(isgraph(lc), (stderr," '%c' ", lc));
  80042. } else {
  80043. code = _length_code[lc];
  80044. send_code(s, code+LITERALS+1, ltree); /* send the length code */
  80045. extra = extra_lbits[code];
  80046. if (extra != 0) {
  80047. lc -= base_length[code];
  80048. send_bits(s, lc, extra); /* send the extra length bits */
  80049. }
  80050. dist--; /* dist is now the match distance - 1 */
  80051. code = d_code(dist);
  80052. Assert (code < D_CODES, "bad d_code");
  80053. send_code(s, code, dtree); /* send the distance code */
  80054. extra = extra_dbits[code];
  80055. if (extra != 0) {
  80056. dist -= base_dist[code];
  80057. send_bits(s, dist, extra); /* send the extra distance bits */
  80058. }
  80059. } /* literal or match pair ? */
  80060. Assert((uInt)(s->pending) < s->lit_bufsize + 2*lx,
  80061. "pendingBuf overflow");
  80062. } while (lx < s->last_lit);
  80063. send_code(s, END_BLOCK, ltree);
  80064. s->last_eob_len = ltree[END_BLOCK].Len;
  80065. }
  80066. local void set_data_type (deflate_state *s)
  80067. {
  80068. int n;
  80069. for (n = 0; n < 9; n++)
  80070. if (s->dyn_ltree[n].Freq != 0)
  80071. break;
  80072. if (n == 9)
  80073. for (n = 14; n < 32; n++)
  80074. if (s->dyn_ltree[n].Freq != 0)
  80075. break;
  80076. s->strm->data_type = (n == 32) ? Z_TEXT : Z_BINARY;
  80077. }
  80078. local unsigned bi_reverse (unsigned code, int len)
  80079. {
  80080. register unsigned res = 0;
  80081. do {
  80082. res |= code & 1;
  80083. code >>= 1, res <<= 1;
  80084. } while (--len > 0);
  80085. return res >> 1;
  80086. }
  80087. local void bi_flush (deflate_state *s)
  80088. {
  80089. if (s->bi_valid == 16) {
  80090. put_short(s, s->bi_buf);
  80091. s->bi_buf = 0;
  80092. s->bi_valid = 0;
  80093. } else if (s->bi_valid >= 8) {
  80094. put_byte(s, (Byte)s->bi_buf);
  80095. s->bi_buf >>= 8;
  80096. s->bi_valid -= 8;
  80097. }
  80098. }
  80099. local void bi_windup (deflate_state *s)
  80100. {
  80101. if (s->bi_valid > 8) {
  80102. put_short(s, s->bi_buf);
  80103. } else if (s->bi_valid > 0) {
  80104. put_byte(s, (Byte)s->bi_buf);
  80105. }
  80106. s->bi_buf = 0;
  80107. s->bi_valid = 0;
  80108. #ifdef DEBUG
  80109. s->bits_sent = (s->bits_sent+7) & ~7;
  80110. #endif
  80111. }
  80112. local void copy_block(deflate_state *s,
  80113. charf *buf, /* the input data */
  80114. unsigned len, /* its length */
  80115. int header) /* true if block header must be written */
  80116. {
  80117. bi_windup(s); /* align on byte boundary */
  80118. s->last_eob_len = 8; /* enough lookahead for inflate */
  80119. if (header) {
  80120. put_short(s, (ush)len);
  80121. put_short(s, (ush)~len);
  80122. #ifdef DEBUG
  80123. s->bits_sent += 2*16;
  80124. #endif
  80125. }
  80126. #ifdef DEBUG
  80127. s->bits_sent += (ulg)len<<3;
  80128. #endif
  80129. while (len--) {
  80130. put_byte(s, *buf++);
  80131. }
  80132. }
  80133. /*** End of inlined file: trees.c ***/
  80134. /*** Start of inlined file: zutil.c ***/
  80135. #ifndef NO_DUMMY_DECL
  80136. struct internal_state {int dummy;}; /* for buggy compilers */
  80137. #endif
  80138. const char * const z_errmsg[10] = {
  80139. "need dictionary", /* Z_NEED_DICT 2 */
  80140. "stream end", /* Z_STREAM_END 1 */
  80141. "", /* Z_OK 0 */
  80142. "file error", /* Z_ERRNO (-1) */
  80143. "stream error", /* Z_STREAM_ERROR (-2) */
  80144. "data error", /* Z_DATA_ERROR (-3) */
  80145. "insufficient memory", /* Z_MEM_ERROR (-4) */
  80146. "buffer error", /* Z_BUF_ERROR (-5) */
  80147. "incompatible version",/* Z_VERSION_ERROR (-6) */
  80148. ""};
  80149. #ifdef DEBUG
  80150. # ifndef verbose
  80151. # define verbose 0
  80152. # endif
  80153. int z_verbose = verbose;
  80154. void z_error (const char *m)
  80155. {
  80156. fprintf(stderr, "%s\n", m);
  80157. exit(1);
  80158. }
  80159. #endif
  80160. const char * ZEXPORT zError(int err)
  80161. {
  80162. return ERR_MSG(err);
  80163. }
  80164. #if defined(_WIN32_WCE)
  80165. int errno = 0;
  80166. #endif
  80167. #ifndef HAVE_MEMCPY
  80168. void zmemcpy(dest, source, len)
  80169. Bytef* dest;
  80170. const Bytef* source;
  80171. uInt len;
  80172. {
  80173. if (len == 0) return;
  80174. do {
  80175. *dest++ = *source++; /* ??? to be unrolled */
  80176. } while (--len != 0);
  80177. }
  80178. int zmemcmp(s1, s2, len)
  80179. const Bytef* s1;
  80180. const Bytef* s2;
  80181. uInt len;
  80182. {
  80183. uInt j;
  80184. for (j = 0; j < len; j++) {
  80185. if (s1[j] != s2[j]) return 2*(s1[j] > s2[j])-1;
  80186. }
  80187. return 0;
  80188. }
  80189. void zmemzero(dest, len)
  80190. Bytef* dest;
  80191. uInt len;
  80192. {
  80193. if (len == 0) return;
  80194. do {
  80195. *dest++ = 0; /* ??? to be unrolled */
  80196. } while (--len != 0);
  80197. }
  80198. #endif
  80199. #ifdef SYS16BIT
  80200. #ifdef __TURBOC__
  80201. # define MY_ZCALLOC
  80202. #define MAX_PTR 10
  80203. local int next_ptr = 0;
  80204. typedef struct ptr_table_s {
  80205. voidpf org_ptr;
  80206. voidpf new_ptr;
  80207. } ptr_table;
  80208. local ptr_table table[MAX_PTR];
  80209. voidpf zcalloc (voidpf opaque, unsigned items, unsigned size)
  80210. {
  80211. voidpf buf = opaque; /* just to make some compilers happy */
  80212. ulg bsize = (ulg)items*size;
  80213. if (bsize < 65520L) {
  80214. buf = farmalloc(bsize);
  80215. if (*(ush*)&buf != 0) return buf;
  80216. } else {
  80217. buf = farmalloc(bsize + 16L);
  80218. }
  80219. if (buf == NULL || next_ptr >= MAX_PTR) return NULL;
  80220. table[next_ptr].org_ptr = buf;
  80221. *((ush*)&buf+1) += ((ush)((uch*)buf-0) + 15) >> 4;
  80222. *(ush*)&buf = 0;
  80223. table[next_ptr++].new_ptr = buf;
  80224. return buf;
  80225. }
  80226. void zcfree (voidpf opaque, voidpf ptr)
  80227. {
  80228. int n;
  80229. if (*(ush*)&ptr != 0) { /* object < 64K */
  80230. farfree(ptr);
  80231. return;
  80232. }
  80233. for (n = 0; n < next_ptr; n++) {
  80234. if (ptr != table[n].new_ptr) continue;
  80235. farfree(table[n].org_ptr);
  80236. while (++n < next_ptr) {
  80237. table[n-1] = table[n];
  80238. }
  80239. next_ptr--;
  80240. return;
  80241. }
  80242. ptr = opaque; /* just to make some compilers happy */
  80243. Assert(0, "zcfree: ptr not found");
  80244. }
  80245. #endif /* __TURBOC__ */
  80246. #ifdef M_I86
  80247. # define MY_ZCALLOC
  80248. #if (!defined(_MSC_VER) || (_MSC_VER <= 600))
  80249. # define _halloc halloc
  80250. # define _hfree hfree
  80251. #endif
  80252. voidpf zcalloc (voidpf opaque, unsigned items, unsigned size)
  80253. {
  80254. if (opaque) opaque = 0; /* to make compiler happy */
  80255. return _halloc((long)items, size);
  80256. }
  80257. void zcfree (voidpf opaque, voidpf ptr)
  80258. {
  80259. if (opaque) opaque = 0; /* to make compiler happy */
  80260. _hfree(ptr);
  80261. }
  80262. #endif /* M_I86 */
  80263. #endif /* SYS16BIT */
  80264. #ifndef MY_ZCALLOC /* Any system without a special alloc function */
  80265. #ifndef STDC
  80266. extern voidp malloc OF((uInt size));
  80267. extern voidp calloc OF((uInt items, uInt size));
  80268. extern void free OF((voidpf ptr));
  80269. #endif
  80270. voidpf zcalloc (voidpf opaque, unsigned items, unsigned size)
  80271. {
  80272. if (opaque) items += size - size; /* make compiler happy */
  80273. return sizeof(uInt) > 2 ? (voidpf)malloc(items * size) :
  80274. (voidpf)calloc(items, size);
  80275. }
  80276. void zcfree (voidpf opaque, voidpf ptr)
  80277. {
  80278. free(ptr);
  80279. if (opaque) return; /* make compiler happy */
  80280. }
  80281. #endif /* MY_ZCALLOC */
  80282. /*** End of inlined file: zutil.c ***/
  80283. #undef Byte
  80284. }
  80285. #else
  80286. #include <zlib.h>
  80287. #endif
  80288. }
  80289. #if JUCE_MSVC
  80290. #pragma warning (pop)
  80291. #endif
  80292. BEGIN_JUCE_NAMESPACE
  80293. // internal helper object that holds the zlib structures so they don't have to be
  80294. // included publicly.
  80295. class GZIPDecompressHelper
  80296. {
  80297. public:
  80298. GZIPDecompressHelper (const bool noWrap)
  80299. : finished (true),
  80300. needsDictionary (false),
  80301. error (true),
  80302. streamIsValid (false),
  80303. data (0),
  80304. dataSize (0)
  80305. {
  80306. using namespace zlibNamespace;
  80307. zerostruct (stream);
  80308. streamIsValid = (inflateInit2 (&stream, noWrap ? -MAX_WBITS : MAX_WBITS) == Z_OK);
  80309. finished = error = ! streamIsValid;
  80310. }
  80311. ~GZIPDecompressHelper()
  80312. {
  80313. using namespace zlibNamespace;
  80314. if (streamIsValid)
  80315. inflateEnd (&stream);
  80316. }
  80317. bool needsInput() const throw() { return dataSize <= 0; }
  80318. void setInput (uint8* const data_, const int size) throw()
  80319. {
  80320. data = data_;
  80321. dataSize = size;
  80322. }
  80323. int doNextBlock (uint8* const dest, const int destSize)
  80324. {
  80325. using namespace zlibNamespace;
  80326. if (streamIsValid && data != 0 && ! finished)
  80327. {
  80328. stream.next_in = data;
  80329. stream.next_out = dest;
  80330. stream.avail_in = dataSize;
  80331. stream.avail_out = destSize;
  80332. switch (inflate (&stream, Z_PARTIAL_FLUSH))
  80333. {
  80334. case Z_STREAM_END:
  80335. finished = true;
  80336. // deliberate fall-through
  80337. case Z_OK:
  80338. data += dataSize - stream.avail_in;
  80339. dataSize = stream.avail_in;
  80340. return destSize - stream.avail_out;
  80341. case Z_NEED_DICT:
  80342. needsDictionary = true;
  80343. data += dataSize - stream.avail_in;
  80344. dataSize = stream.avail_in;
  80345. break;
  80346. case Z_DATA_ERROR:
  80347. case Z_MEM_ERROR:
  80348. error = true;
  80349. default:
  80350. break;
  80351. }
  80352. }
  80353. return 0;
  80354. }
  80355. bool finished, needsDictionary, error, streamIsValid;
  80356. private:
  80357. zlibNamespace::z_stream stream;
  80358. uint8* data;
  80359. int dataSize;
  80360. GZIPDecompressHelper (const GZIPDecompressHelper&);
  80361. GZIPDecompressHelper& operator= (const GZIPDecompressHelper&);
  80362. };
  80363. const int gzipDecompBufferSize = 32768;
  80364. GZIPDecompressorInputStream::GZIPDecompressorInputStream (InputStream* const sourceStream_,
  80365. const bool deleteSourceWhenDestroyed,
  80366. const bool noWrap_,
  80367. const int64 uncompressedStreamLength_)
  80368. : sourceStream (sourceStream_),
  80369. streamToDelete (deleteSourceWhenDestroyed ? sourceStream_ : 0),
  80370. uncompressedStreamLength (uncompressedStreamLength_),
  80371. noWrap (noWrap_),
  80372. isEof (false),
  80373. activeBufferSize (0),
  80374. originalSourcePos (sourceStream_->getPosition()),
  80375. currentPos (0),
  80376. buffer (gzipDecompBufferSize),
  80377. helper (new GZIPDecompressHelper (noWrap_))
  80378. {
  80379. }
  80380. GZIPDecompressorInputStream::~GZIPDecompressorInputStream()
  80381. {
  80382. }
  80383. int64 GZIPDecompressorInputStream::getTotalLength()
  80384. {
  80385. return uncompressedStreamLength;
  80386. }
  80387. int GZIPDecompressorInputStream::read (void* destBuffer, int howMany)
  80388. {
  80389. if ((howMany > 0) && ! isEof)
  80390. {
  80391. jassert (destBuffer != 0);
  80392. if (destBuffer != 0)
  80393. {
  80394. int numRead = 0;
  80395. uint8* d = (uint8*) destBuffer;
  80396. while (! helper->error)
  80397. {
  80398. const int n = helper->doNextBlock (d, howMany);
  80399. currentPos += n;
  80400. if (n == 0)
  80401. {
  80402. if (helper->finished || helper->needsDictionary)
  80403. {
  80404. isEof = true;
  80405. return numRead;
  80406. }
  80407. if (helper->needsInput())
  80408. {
  80409. activeBufferSize = sourceStream->read (buffer, gzipDecompBufferSize);
  80410. if (activeBufferSize > 0)
  80411. {
  80412. helper->setInput ((uint8*) buffer, activeBufferSize);
  80413. }
  80414. else
  80415. {
  80416. isEof = true;
  80417. return numRead;
  80418. }
  80419. }
  80420. }
  80421. else
  80422. {
  80423. numRead += n;
  80424. howMany -= n;
  80425. d += n;
  80426. if (howMany <= 0)
  80427. return numRead;
  80428. }
  80429. }
  80430. }
  80431. }
  80432. return 0;
  80433. }
  80434. bool GZIPDecompressorInputStream::isExhausted()
  80435. {
  80436. return helper->error || isEof;
  80437. }
  80438. int64 GZIPDecompressorInputStream::getPosition()
  80439. {
  80440. return currentPos;
  80441. }
  80442. bool GZIPDecompressorInputStream::setPosition (int64 newPos)
  80443. {
  80444. if (newPos < currentPos)
  80445. {
  80446. // to go backwards, reset the stream and start again..
  80447. isEof = false;
  80448. activeBufferSize = 0;
  80449. currentPos = 0;
  80450. helper = new GZIPDecompressHelper (noWrap);
  80451. sourceStream->setPosition (originalSourcePos);
  80452. }
  80453. skipNextBytes (newPos - currentPos);
  80454. return true;
  80455. }
  80456. END_JUCE_NAMESPACE
  80457. /*** End of inlined file: juce_GZIPDecompressorInputStream.cpp ***/
  80458. #endif
  80459. #if JUCE_BUILD_NATIVE && ! JUCE_ONLY_BUILD_CORE_LIBRARY
  80460. /*** Start of inlined file: juce_FlacAudioFormat.cpp ***/
  80461. #if JUCE_USE_FLAC
  80462. #if JUCE_WINDOWS
  80463. #include <windows.h>
  80464. #endif
  80465. #ifdef _MSC_VER
  80466. #pragma warning (disable : 4505)
  80467. #pragma warning (push)
  80468. #endif
  80469. namespace FlacNamespace
  80470. {
  80471. #if JUCE_INCLUDE_FLAC_CODE
  80472. #define FLAC__NO_DLL 1
  80473. #if ! defined (SIZE_MAX)
  80474. #define SIZE_MAX 0xffffffff
  80475. #endif
  80476. #define __STDC_LIMIT_MACROS 1
  80477. /*** Start of inlined file: all.h ***/
  80478. #ifndef FLAC__ALL_H
  80479. #define FLAC__ALL_H
  80480. /*** Start of inlined file: export.h ***/
  80481. #ifndef FLAC__EXPORT_H
  80482. #define FLAC__EXPORT_H
  80483. #if defined(FLAC__NO_DLL) || !defined(_MSC_VER)
  80484. #define FLAC_API
  80485. #else
  80486. #ifdef FLAC_API_EXPORTS
  80487. #define FLAC_API _declspec(dllexport)
  80488. #else
  80489. #define FLAC_API _declspec(dllimport)
  80490. #endif
  80491. #endif
  80492. #define FLAC_API_VERSION_CURRENT 10
  80493. #define FLAC_API_VERSION_REVISION 0 /**< see above */
  80494. #define FLAC_API_VERSION_AGE 2 /**< see above */
  80495. #ifdef __cplusplus
  80496. extern "C" {
  80497. #endif
  80498. extern FLAC_API int FLAC_API_SUPPORTS_OGG_FLAC;
  80499. #ifdef __cplusplus
  80500. }
  80501. #endif
  80502. #endif
  80503. /*** End of inlined file: export.h ***/
  80504. /*** Start of inlined file: assert.h ***/
  80505. #ifndef FLAC__ASSERT_H
  80506. #define FLAC__ASSERT_H
  80507. /* we need this since some compilers (like MSVC) leave assert()s on release code (and we don't want to use their ASSERT) */
  80508. #ifdef DEBUG
  80509. #include <assert.h>
  80510. #define FLAC__ASSERT(x) assert(x)
  80511. #define FLAC__ASSERT_DECLARATION(x) x
  80512. #else
  80513. #define FLAC__ASSERT(x)
  80514. #define FLAC__ASSERT_DECLARATION(x)
  80515. #endif
  80516. #endif
  80517. /*** End of inlined file: assert.h ***/
  80518. /*** Start of inlined file: callback.h ***/
  80519. #ifndef FLAC__CALLBACK_H
  80520. #define FLAC__CALLBACK_H
  80521. /*** Start of inlined file: ordinals.h ***/
  80522. #ifndef FLAC__ORDINALS_H
  80523. #define FLAC__ORDINALS_H
  80524. #if !(defined(_MSC_VER) || defined(__BORLANDC__) || defined(__EMX__))
  80525. #include <inttypes.h>
  80526. #endif
  80527. typedef signed char FLAC__int8;
  80528. typedef unsigned char FLAC__uint8;
  80529. #if defined(_MSC_VER) || defined(__BORLANDC__)
  80530. typedef __int16 FLAC__int16;
  80531. typedef __int32 FLAC__int32;
  80532. typedef __int64 FLAC__int64;
  80533. typedef unsigned __int16 FLAC__uint16;
  80534. typedef unsigned __int32 FLAC__uint32;
  80535. typedef unsigned __int64 FLAC__uint64;
  80536. #elif defined(__EMX__)
  80537. typedef short FLAC__int16;
  80538. typedef long FLAC__int32;
  80539. typedef long long FLAC__int64;
  80540. typedef unsigned short FLAC__uint16;
  80541. typedef unsigned long FLAC__uint32;
  80542. typedef unsigned long long FLAC__uint64;
  80543. #else
  80544. typedef int16_t FLAC__int16;
  80545. typedef int32_t FLAC__int32;
  80546. typedef int64_t FLAC__int64;
  80547. typedef uint16_t FLAC__uint16;
  80548. typedef uint32_t FLAC__uint32;
  80549. typedef uint64_t FLAC__uint64;
  80550. #endif
  80551. typedef int FLAC__bool;
  80552. typedef FLAC__uint8 FLAC__byte;
  80553. #ifdef true
  80554. #undef true
  80555. #endif
  80556. #ifdef false
  80557. #undef false
  80558. #endif
  80559. #ifndef __cplusplus
  80560. #define true 1
  80561. #define false 0
  80562. #endif
  80563. #endif
  80564. /*** End of inlined file: ordinals.h ***/
  80565. #include <stdlib.h> /* for size_t */
  80566. #ifdef __cplusplus
  80567. extern "C" {
  80568. #endif
  80569. typedef void* FLAC__IOHandle;
  80570. typedef size_t (*FLAC__IOCallback_Read) (void *ptr, size_t size, size_t nmemb, FLAC__IOHandle handle);
  80571. typedef size_t (*FLAC__IOCallback_Write) (const void *ptr, size_t size, size_t nmemb, FLAC__IOHandle handle);
  80572. typedef int (*FLAC__IOCallback_Seek) (FLAC__IOHandle handle, FLAC__int64 offset, int whence);
  80573. typedef FLAC__int64 (*FLAC__IOCallback_Tell) (FLAC__IOHandle handle);
  80574. typedef int (*FLAC__IOCallback_Eof) (FLAC__IOHandle handle);
  80575. typedef int (*FLAC__IOCallback_Close) (FLAC__IOHandle handle);
  80576. typedef struct {
  80577. FLAC__IOCallback_Read read;
  80578. FLAC__IOCallback_Write write;
  80579. FLAC__IOCallback_Seek seek;
  80580. FLAC__IOCallback_Tell tell;
  80581. FLAC__IOCallback_Eof eof;
  80582. FLAC__IOCallback_Close close;
  80583. } FLAC__IOCallbacks;
  80584. #ifdef __cplusplus
  80585. }
  80586. #endif
  80587. #endif
  80588. /*** End of inlined file: callback.h ***/
  80589. /*** Start of inlined file: format.h ***/
  80590. #ifndef FLAC__FORMAT_H
  80591. #define FLAC__FORMAT_H
  80592. #ifdef __cplusplus
  80593. extern "C" {
  80594. #endif
  80595. #define FLAC__MAX_METADATA_TYPE_CODE (126u)
  80596. #define FLAC__MIN_BLOCK_SIZE (16u)
  80597. #define FLAC__MAX_BLOCK_SIZE (65535u)
  80598. #define FLAC__SUBSET_MAX_BLOCK_SIZE_48000HZ (4608u)
  80599. #define FLAC__MAX_CHANNELS (8u)
  80600. #define FLAC__MIN_BITS_PER_SAMPLE (4u)
  80601. #define FLAC__MAX_BITS_PER_SAMPLE (32u)
  80602. #define FLAC__REFERENCE_CODEC_MAX_BITS_PER_SAMPLE (24u)
  80603. #define FLAC__MAX_SAMPLE_RATE (655350u)
  80604. #define FLAC__MAX_LPC_ORDER (32u)
  80605. #define FLAC__SUBSET_MAX_LPC_ORDER_48000HZ (12u)
  80606. #define FLAC__MIN_QLP_COEFF_PRECISION (5u)
  80607. #define FLAC__MAX_QLP_COEFF_PRECISION (15u)
  80608. #define FLAC__MAX_FIXED_ORDER (4u)
  80609. #define FLAC__MAX_RICE_PARTITION_ORDER (15u)
  80610. #define FLAC__SUBSET_MAX_RICE_PARTITION_ORDER (8u)
  80611. extern FLAC_API const char *FLAC__VERSION_STRING;
  80612. extern FLAC_API const char *FLAC__VENDOR_STRING;
  80613. extern FLAC_API const FLAC__byte FLAC__STREAM_SYNC_STRING[4]; /* = "fLaC" */
  80614. extern FLAC_API const unsigned FLAC__STREAM_SYNC; /* = 0x664C6143 */
  80615. extern FLAC_API const unsigned FLAC__STREAM_SYNC_LEN; /* = 32 bits */
  80616. #define FLAC__STREAM_SYNC_LENGTH (4u)
  80617. typedef enum {
  80618. FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE = 0,
  80619. FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2 = 1
  80620. } FLAC__EntropyCodingMethodType;
  80621. extern FLAC_API const char * const FLAC__EntropyCodingMethodTypeString[];
  80622. typedef struct {
  80623. unsigned *parameters;
  80624. unsigned *raw_bits;
  80625. unsigned capacity_by_order;
  80626. } FLAC__EntropyCodingMethod_PartitionedRiceContents;
  80627. typedef struct {
  80628. unsigned order;
  80629. const FLAC__EntropyCodingMethod_PartitionedRiceContents *contents;
  80630. } FLAC__EntropyCodingMethod_PartitionedRice;
  80631. extern FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ORDER_LEN; /**< == 4 (bits) */
  80632. extern FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_PARAMETER_LEN; /**< == 4 (bits) */
  80633. extern FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_PARAMETER_LEN; /**< == 5 (bits) */
  80634. extern FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_RAW_LEN; /**< == 5 (bits) */
  80635. extern FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ESCAPE_PARAMETER;
  80636. extern FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_ESCAPE_PARAMETER;
  80637. typedef struct {
  80638. FLAC__EntropyCodingMethodType type;
  80639. union {
  80640. FLAC__EntropyCodingMethod_PartitionedRice partitioned_rice;
  80641. } data;
  80642. } FLAC__EntropyCodingMethod;
  80643. extern FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_TYPE_LEN; /**< == 2 (bits) */
  80644. typedef enum {
  80645. FLAC__SUBFRAME_TYPE_CONSTANT = 0, /**< constant signal */
  80646. FLAC__SUBFRAME_TYPE_VERBATIM = 1, /**< uncompressed signal */
  80647. FLAC__SUBFRAME_TYPE_FIXED = 2, /**< fixed polynomial prediction */
  80648. FLAC__SUBFRAME_TYPE_LPC = 3 /**< linear prediction */
  80649. } FLAC__SubframeType;
  80650. extern FLAC_API const char * const FLAC__SubframeTypeString[];
  80651. typedef struct {
  80652. FLAC__int32 value; /**< The constant signal value. */
  80653. } FLAC__Subframe_Constant;
  80654. typedef struct {
  80655. const FLAC__int32 *data; /**< A pointer to verbatim signal. */
  80656. } FLAC__Subframe_Verbatim;
  80657. typedef struct {
  80658. FLAC__EntropyCodingMethod entropy_coding_method;
  80659. unsigned order;
  80660. FLAC__int32 warmup[FLAC__MAX_FIXED_ORDER];
  80661. const FLAC__int32 *residual;
  80662. } FLAC__Subframe_Fixed;
  80663. typedef struct {
  80664. FLAC__EntropyCodingMethod entropy_coding_method;
  80665. unsigned order;
  80666. unsigned qlp_coeff_precision;
  80667. int quantization_level;
  80668. FLAC__int32 qlp_coeff[FLAC__MAX_LPC_ORDER];
  80669. FLAC__int32 warmup[FLAC__MAX_LPC_ORDER];
  80670. const FLAC__int32 *residual;
  80671. } FLAC__Subframe_LPC;
  80672. extern FLAC_API const unsigned FLAC__SUBFRAME_LPC_QLP_COEFF_PRECISION_LEN; /**< == 4 (bits) */
  80673. extern FLAC_API const unsigned FLAC__SUBFRAME_LPC_QLP_SHIFT_LEN; /**< == 5 (bits) */
  80674. typedef struct {
  80675. FLAC__SubframeType type;
  80676. union {
  80677. FLAC__Subframe_Constant constant;
  80678. FLAC__Subframe_Fixed fixed;
  80679. FLAC__Subframe_LPC lpc;
  80680. FLAC__Subframe_Verbatim verbatim;
  80681. } data;
  80682. unsigned wasted_bits;
  80683. } FLAC__Subframe;
  80684. extern FLAC_API const unsigned FLAC__SUBFRAME_ZERO_PAD_LEN;
  80685. extern FLAC_API const unsigned FLAC__SUBFRAME_TYPE_LEN; /**< == 6 (bits) */
  80686. extern FLAC_API const unsigned FLAC__SUBFRAME_WASTED_BITS_FLAG_LEN; /**< == 1 (bit) */
  80687. extern FLAC_API const unsigned FLAC__SUBFRAME_TYPE_CONSTANT_BYTE_ALIGNED_MASK; /**< = 0x00 */
  80688. extern FLAC_API const unsigned FLAC__SUBFRAME_TYPE_VERBATIM_BYTE_ALIGNED_MASK; /**< = 0x02 */
  80689. extern FLAC_API const unsigned FLAC__SUBFRAME_TYPE_FIXED_BYTE_ALIGNED_MASK; /**< = 0x10 */
  80690. extern FLAC_API const unsigned FLAC__SUBFRAME_TYPE_LPC_BYTE_ALIGNED_MASK; /**< = 0x40 */
  80691. typedef enum {
  80692. FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT = 0, /**< independent channels */
  80693. FLAC__CHANNEL_ASSIGNMENT_LEFT_SIDE = 1, /**< left+side stereo */
  80694. FLAC__CHANNEL_ASSIGNMENT_RIGHT_SIDE = 2, /**< right+side stereo */
  80695. FLAC__CHANNEL_ASSIGNMENT_MID_SIDE = 3 /**< mid+side stereo */
  80696. } FLAC__ChannelAssignment;
  80697. extern FLAC_API const char * const FLAC__ChannelAssignmentString[];
  80698. typedef enum {
  80699. FLAC__FRAME_NUMBER_TYPE_FRAME_NUMBER, /**< number contains the frame number */
  80700. FLAC__FRAME_NUMBER_TYPE_SAMPLE_NUMBER /**< number contains the sample number of first sample in frame */
  80701. } FLAC__FrameNumberType;
  80702. extern FLAC_API const char * const FLAC__FrameNumberTypeString[];
  80703. typedef struct {
  80704. unsigned blocksize;
  80705. unsigned sample_rate;
  80706. unsigned channels;
  80707. FLAC__ChannelAssignment channel_assignment;
  80708. unsigned bits_per_sample;
  80709. FLAC__FrameNumberType number_type;
  80710. union {
  80711. FLAC__uint32 frame_number;
  80712. FLAC__uint64 sample_number;
  80713. } number;
  80714. FLAC__uint8 crc;
  80715. } FLAC__FrameHeader;
  80716. extern FLAC_API const unsigned FLAC__FRAME_HEADER_SYNC; /**< == 0x3ffe; the frame header sync code */
  80717. extern FLAC_API const unsigned FLAC__FRAME_HEADER_SYNC_LEN; /**< == 14 (bits) */
  80718. extern FLAC_API const unsigned FLAC__FRAME_HEADER_RESERVED_LEN; /**< == 1 (bits) */
  80719. extern FLAC_API const unsigned FLAC__FRAME_HEADER_BLOCKING_STRATEGY_LEN; /**< == 1 (bits) */
  80720. extern FLAC_API const unsigned FLAC__FRAME_HEADER_BLOCK_SIZE_LEN; /**< == 4 (bits) */
  80721. extern FLAC_API const unsigned FLAC__FRAME_HEADER_SAMPLE_RATE_LEN; /**< == 4 (bits) */
  80722. extern FLAC_API const unsigned FLAC__FRAME_HEADER_CHANNEL_ASSIGNMENT_LEN; /**< == 4 (bits) */
  80723. extern FLAC_API const unsigned FLAC__FRAME_HEADER_BITS_PER_SAMPLE_LEN; /**< == 3 (bits) */
  80724. extern FLAC_API const unsigned FLAC__FRAME_HEADER_ZERO_PAD_LEN; /**< == 1 (bit) */
  80725. extern FLAC_API const unsigned FLAC__FRAME_HEADER_CRC_LEN; /**< == 8 (bits) */
  80726. typedef struct {
  80727. FLAC__uint16 crc;
  80728. } FLAC__FrameFooter;
  80729. extern FLAC_API const unsigned FLAC__FRAME_FOOTER_CRC_LEN; /**< == 16 (bits) */
  80730. typedef struct {
  80731. FLAC__FrameHeader header;
  80732. FLAC__Subframe subframes[FLAC__MAX_CHANNELS];
  80733. FLAC__FrameFooter footer;
  80734. } FLAC__Frame;
  80735. typedef enum {
  80736. FLAC__METADATA_TYPE_STREAMINFO = 0,
  80737. FLAC__METADATA_TYPE_PADDING = 1,
  80738. FLAC__METADATA_TYPE_APPLICATION = 2,
  80739. FLAC__METADATA_TYPE_SEEKTABLE = 3,
  80740. FLAC__METADATA_TYPE_VORBIS_COMMENT = 4,
  80741. FLAC__METADATA_TYPE_CUESHEET = 5,
  80742. FLAC__METADATA_TYPE_PICTURE = 6,
  80743. FLAC__METADATA_TYPE_UNDEFINED = 7
  80744. } FLAC__MetadataType;
  80745. extern FLAC_API const char * const FLAC__MetadataTypeString[];
  80746. typedef struct {
  80747. unsigned min_blocksize, max_blocksize;
  80748. unsigned min_framesize, max_framesize;
  80749. unsigned sample_rate;
  80750. unsigned channels;
  80751. unsigned bits_per_sample;
  80752. FLAC__uint64 total_samples;
  80753. FLAC__byte md5sum[16];
  80754. } FLAC__StreamMetadata_StreamInfo;
  80755. extern FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN; /**< == 16 (bits) */
  80756. extern FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN; /**< == 16 (bits) */
  80757. extern FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN; /**< == 24 (bits) */
  80758. extern FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN; /**< == 24 (bits) */
  80759. extern FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_SAMPLE_RATE_LEN; /**< == 20 (bits) */
  80760. extern FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN; /**< == 3 (bits) */
  80761. extern FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN; /**< == 5 (bits) */
  80762. extern FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_TOTAL_SAMPLES_LEN; /**< == 36 (bits) */
  80763. extern FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MD5SUM_LEN; /**< == 128 (bits) */
  80764. #define FLAC__STREAM_METADATA_STREAMINFO_LENGTH (34u)
  80765. typedef struct {
  80766. int dummy;
  80767. } FLAC__StreamMetadata_Padding;
  80768. typedef struct {
  80769. FLAC__byte id[4];
  80770. FLAC__byte *data;
  80771. } FLAC__StreamMetadata_Application;
  80772. extern FLAC_API const unsigned FLAC__STREAM_METADATA_APPLICATION_ID_LEN; /**< == 32 (bits) */
  80773. typedef struct {
  80774. FLAC__uint64 sample_number;
  80775. FLAC__uint64 stream_offset;
  80776. unsigned frame_samples;
  80777. } FLAC__StreamMetadata_SeekPoint;
  80778. extern FLAC_API const unsigned FLAC__STREAM_METADATA_SEEKPOINT_SAMPLE_NUMBER_LEN; /**< == 64 (bits) */
  80779. extern FLAC_API const unsigned FLAC__STREAM_METADATA_SEEKPOINT_STREAM_OFFSET_LEN; /**< == 64 (bits) */
  80780. extern FLAC_API const unsigned FLAC__STREAM_METADATA_SEEKPOINT_FRAME_SAMPLES_LEN; /**< == 16 (bits) */
  80781. #define FLAC__STREAM_METADATA_SEEKPOINT_LENGTH (18u)
  80782. extern FLAC_API const FLAC__uint64 FLAC__STREAM_METADATA_SEEKPOINT_PLACEHOLDER;
  80783. typedef struct {
  80784. unsigned num_points;
  80785. FLAC__StreamMetadata_SeekPoint *points;
  80786. } FLAC__StreamMetadata_SeekTable;
  80787. typedef struct {
  80788. FLAC__uint32 length;
  80789. FLAC__byte *entry;
  80790. } FLAC__StreamMetadata_VorbisComment_Entry;
  80791. extern FLAC_API const unsigned FLAC__STREAM_METADATA_VORBIS_COMMENT_ENTRY_LENGTH_LEN; /**< == 32 (bits) */
  80792. typedef struct {
  80793. FLAC__StreamMetadata_VorbisComment_Entry vendor_string;
  80794. FLAC__uint32 num_comments;
  80795. FLAC__StreamMetadata_VorbisComment_Entry *comments;
  80796. } FLAC__StreamMetadata_VorbisComment;
  80797. extern FLAC_API const unsigned FLAC__STREAM_METADATA_VORBIS_COMMENT_NUM_COMMENTS_LEN; /**< == 32 (bits) */
  80798. typedef struct {
  80799. FLAC__uint64 offset;
  80800. FLAC__byte number;
  80801. } FLAC__StreamMetadata_CueSheet_Index;
  80802. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_INDEX_OFFSET_LEN; /**< == 64 (bits) */
  80803. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_INDEX_NUMBER_LEN; /**< == 8 (bits) */
  80804. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_INDEX_RESERVED_LEN; /**< == 3*8 (bits) */
  80805. typedef struct {
  80806. FLAC__uint64 offset;
  80807. FLAC__byte number;
  80808. char isrc[13];
  80809. unsigned type:1;
  80810. unsigned pre_emphasis:1;
  80811. FLAC__byte num_indices;
  80812. FLAC__StreamMetadata_CueSheet_Index *indices;
  80813. } FLAC__StreamMetadata_CueSheet_Track;
  80814. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_OFFSET_LEN; /**< == 64 (bits) */
  80815. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_NUMBER_LEN; /**< == 8 (bits) */
  80816. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_ISRC_LEN; /**< == 12*8 (bits) */
  80817. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_TYPE_LEN; /**< == 1 (bit) */
  80818. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_PRE_EMPHASIS_LEN; /**< == 1 (bit) */
  80819. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_RESERVED_LEN; /**< == 6+13*8 (bits) */
  80820. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_NUM_INDICES_LEN; /**< == 8 (bits) */
  80821. typedef struct {
  80822. char media_catalog_number[129];
  80823. FLAC__uint64 lead_in;
  80824. FLAC__bool is_cd;
  80825. unsigned num_tracks;
  80826. FLAC__StreamMetadata_CueSheet_Track *tracks;
  80827. } FLAC__StreamMetadata_CueSheet;
  80828. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_MEDIA_CATALOG_NUMBER_LEN; /**< == 128*8 (bits) */
  80829. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_LEAD_IN_LEN; /**< == 64 (bits) */
  80830. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_IS_CD_LEN; /**< == 1 (bit) */
  80831. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_RESERVED_LEN; /**< == 7+258*8 (bits) */
  80832. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_NUM_TRACKS_LEN; /**< == 8 (bits) */
  80833. typedef enum {
  80834. FLAC__STREAM_METADATA_PICTURE_TYPE_OTHER = 0, /**< Other */
  80835. FLAC__STREAM_METADATA_PICTURE_TYPE_FILE_ICON_STANDARD = 1, /**< 32x32 pixels 'file icon' (PNG only) */
  80836. FLAC__STREAM_METADATA_PICTURE_TYPE_FILE_ICON = 2, /**< Other file icon */
  80837. FLAC__STREAM_METADATA_PICTURE_TYPE_FRONT_COVER = 3, /**< Cover (front) */
  80838. FLAC__STREAM_METADATA_PICTURE_TYPE_BACK_COVER = 4, /**< Cover (back) */
  80839. FLAC__STREAM_METADATA_PICTURE_TYPE_LEAFLET_PAGE = 5, /**< Leaflet page */
  80840. FLAC__STREAM_METADATA_PICTURE_TYPE_MEDIA = 6, /**< Media (e.g. label side of CD) */
  80841. FLAC__STREAM_METADATA_PICTURE_TYPE_LEAD_ARTIST = 7, /**< Lead artist/lead performer/soloist */
  80842. FLAC__STREAM_METADATA_PICTURE_TYPE_ARTIST = 8, /**< Artist/performer */
  80843. FLAC__STREAM_METADATA_PICTURE_TYPE_CONDUCTOR = 9, /**< Conductor */
  80844. FLAC__STREAM_METADATA_PICTURE_TYPE_BAND = 10, /**< Band/Orchestra */
  80845. FLAC__STREAM_METADATA_PICTURE_TYPE_COMPOSER = 11, /**< Composer */
  80846. FLAC__STREAM_METADATA_PICTURE_TYPE_LYRICIST = 12, /**< Lyricist/text writer */
  80847. FLAC__STREAM_METADATA_PICTURE_TYPE_RECORDING_LOCATION = 13, /**< Recording Location */
  80848. FLAC__STREAM_METADATA_PICTURE_TYPE_DURING_RECORDING = 14, /**< During recording */
  80849. FLAC__STREAM_METADATA_PICTURE_TYPE_DURING_PERFORMANCE = 15, /**< During performance */
  80850. FLAC__STREAM_METADATA_PICTURE_TYPE_VIDEO_SCREEN_CAPTURE = 16, /**< Movie/video screen capture */
  80851. FLAC__STREAM_METADATA_PICTURE_TYPE_FISH = 17, /**< A bright coloured fish */
  80852. FLAC__STREAM_METADATA_PICTURE_TYPE_ILLUSTRATION = 18, /**< Illustration */
  80853. FLAC__STREAM_METADATA_PICTURE_TYPE_BAND_LOGOTYPE = 19, /**< Band/artist logotype */
  80854. FLAC__STREAM_METADATA_PICTURE_TYPE_PUBLISHER_LOGOTYPE = 20, /**< Publisher/Studio logotype */
  80855. FLAC__STREAM_METADATA_PICTURE_TYPE_UNDEFINED
  80856. } FLAC__StreamMetadata_Picture_Type;
  80857. extern FLAC_API const char * const FLAC__StreamMetadata_Picture_TypeString[];
  80858. typedef struct {
  80859. FLAC__StreamMetadata_Picture_Type type;
  80860. char *mime_type;
  80861. FLAC__byte *description;
  80862. FLAC__uint32 width;
  80863. FLAC__uint32 height;
  80864. FLAC__uint32 depth;
  80865. FLAC__uint32 colors;
  80866. FLAC__uint32 data_length;
  80867. FLAC__byte *data;
  80868. } FLAC__StreamMetadata_Picture;
  80869. extern FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_TYPE_LEN; /**< == 32 (bits) */
  80870. extern FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_MIME_TYPE_LENGTH_LEN; /**< == 32 (bits) */
  80871. extern FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_DESCRIPTION_LENGTH_LEN; /**< == 32 (bits) */
  80872. extern FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_WIDTH_LEN; /**< == 32 (bits) */
  80873. extern FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_HEIGHT_LEN; /**< == 32 (bits) */
  80874. extern FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_DEPTH_LEN; /**< == 32 (bits) */
  80875. extern FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_COLORS_LEN; /**< == 32 (bits) */
  80876. extern FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_DATA_LENGTH_LEN; /**< == 32 (bits) */
  80877. typedef struct {
  80878. FLAC__byte *data;
  80879. } FLAC__StreamMetadata_Unknown;
  80880. typedef struct {
  80881. FLAC__MetadataType type;
  80882. FLAC__bool is_last;
  80883. unsigned length;
  80884. union {
  80885. FLAC__StreamMetadata_StreamInfo stream_info;
  80886. FLAC__StreamMetadata_Padding padding;
  80887. FLAC__StreamMetadata_Application application;
  80888. FLAC__StreamMetadata_SeekTable seek_table;
  80889. FLAC__StreamMetadata_VorbisComment vorbis_comment;
  80890. FLAC__StreamMetadata_CueSheet cue_sheet;
  80891. FLAC__StreamMetadata_Picture picture;
  80892. FLAC__StreamMetadata_Unknown unknown;
  80893. } data;
  80894. } FLAC__StreamMetadata;
  80895. extern FLAC_API const unsigned FLAC__STREAM_METADATA_IS_LAST_LEN; /**< == 1 (bit) */
  80896. extern FLAC_API const unsigned FLAC__STREAM_METADATA_TYPE_LEN; /**< == 7 (bits) */
  80897. extern FLAC_API const unsigned FLAC__STREAM_METADATA_LENGTH_LEN; /**< == 24 (bits) */
  80898. #define FLAC__STREAM_METADATA_HEADER_LENGTH (4u)
  80899. FLAC_API FLAC__bool FLAC__format_sample_rate_is_valid(unsigned sample_rate);
  80900. FLAC_API FLAC__bool FLAC__format_sample_rate_is_subset(unsigned sample_rate);
  80901. FLAC_API FLAC__bool FLAC__format_vorbiscomment_entry_name_is_legal(const char *name);
  80902. FLAC_API FLAC__bool FLAC__format_vorbiscomment_entry_value_is_legal(const FLAC__byte *value, unsigned length);
  80903. FLAC_API FLAC__bool FLAC__format_vorbiscomment_entry_is_legal(const FLAC__byte *entry, unsigned length);
  80904. FLAC_API FLAC__bool FLAC__format_seektable_is_legal(const FLAC__StreamMetadata_SeekTable *seek_table);
  80905. FLAC_API unsigned FLAC__format_seektable_sort(FLAC__StreamMetadata_SeekTable *seek_table);
  80906. FLAC_API FLAC__bool FLAC__format_cuesheet_is_legal(const FLAC__StreamMetadata_CueSheet *cue_sheet, FLAC__bool check_cd_da_subset, const char **violation);
  80907. FLAC_API FLAC__bool FLAC__format_picture_is_legal(const FLAC__StreamMetadata_Picture *picture, const char **violation);
  80908. #ifdef __cplusplus
  80909. }
  80910. #endif
  80911. #endif
  80912. /*** End of inlined file: format.h ***/
  80913. /*** Start of inlined file: metadata.h ***/
  80914. #ifndef FLAC__METADATA_H
  80915. #define FLAC__METADATA_H
  80916. #include <sys/types.h> /* for off_t */
  80917. #ifdef __cplusplus
  80918. extern "C" {
  80919. #endif
  80920. FLAC_API FLAC__bool FLAC__metadata_get_streaminfo(const char *filename, FLAC__StreamMetadata *streaminfo);
  80921. FLAC_API FLAC__bool FLAC__metadata_get_tags(const char *filename, FLAC__StreamMetadata **tags);
  80922. FLAC_API FLAC__bool FLAC__metadata_get_cuesheet(const char *filename, FLAC__StreamMetadata **cuesheet);
  80923. 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);
  80924. struct FLAC__Metadata_SimpleIterator;
  80925. typedef struct FLAC__Metadata_SimpleIterator FLAC__Metadata_SimpleIterator;
  80926. typedef enum {
  80927. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_OK = 0,
  80928. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_ILLEGAL_INPUT,
  80929. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_ERROR_OPENING_FILE,
  80930. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_NOT_A_FLAC_FILE,
  80931. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_NOT_WRITABLE,
  80932. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_BAD_METADATA,
  80933. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_READ_ERROR,
  80934. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_SEEK_ERROR,
  80935. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_WRITE_ERROR,
  80936. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_RENAME_ERROR,
  80937. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_UNLINK_ERROR,
  80938. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_MEMORY_ALLOCATION_ERROR,
  80939. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_INTERNAL_ERROR
  80940. } FLAC__Metadata_SimpleIteratorStatus;
  80941. extern FLAC_API const char * const FLAC__Metadata_SimpleIteratorStatusString[];
  80942. FLAC_API FLAC__Metadata_SimpleIterator *FLAC__metadata_simple_iterator_new(void);
  80943. FLAC_API void FLAC__metadata_simple_iterator_delete(FLAC__Metadata_SimpleIterator *iterator);
  80944. FLAC_API FLAC__Metadata_SimpleIteratorStatus FLAC__metadata_simple_iterator_status(FLAC__Metadata_SimpleIterator *iterator);
  80945. 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);
  80946. FLAC_API FLAC__bool FLAC__metadata_simple_iterator_is_writable(const FLAC__Metadata_SimpleIterator *iterator);
  80947. FLAC_API FLAC__bool FLAC__metadata_simple_iterator_next(FLAC__Metadata_SimpleIterator *iterator);
  80948. FLAC_API FLAC__bool FLAC__metadata_simple_iterator_prev(FLAC__Metadata_SimpleIterator *iterator);
  80949. FLAC_API FLAC__bool FLAC__metadata_simple_iterator_is_last(const FLAC__Metadata_SimpleIterator *iterator);
  80950. FLAC_API off_t FLAC__metadata_simple_iterator_get_block_offset(const FLAC__Metadata_SimpleIterator *iterator);
  80951. FLAC_API FLAC__MetadataType FLAC__metadata_simple_iterator_get_block_type(const FLAC__Metadata_SimpleIterator *iterator);
  80952. FLAC_API unsigned FLAC__metadata_simple_iterator_get_block_length(const FLAC__Metadata_SimpleIterator *iterator);
  80953. FLAC_API FLAC__bool FLAC__metadata_simple_iterator_get_application_id(FLAC__Metadata_SimpleIterator *iterator, FLAC__byte *id);
  80954. FLAC_API FLAC__StreamMetadata *FLAC__metadata_simple_iterator_get_block(FLAC__Metadata_SimpleIterator *iterator);
  80955. FLAC_API FLAC__bool FLAC__metadata_simple_iterator_set_block(FLAC__Metadata_SimpleIterator *iterator, FLAC__StreamMetadata *block, FLAC__bool use_padding);
  80956. FLAC_API FLAC__bool FLAC__metadata_simple_iterator_insert_block_after(FLAC__Metadata_SimpleIterator *iterator, FLAC__StreamMetadata *block, FLAC__bool use_padding);
  80957. FLAC_API FLAC__bool FLAC__metadata_simple_iterator_delete_block(FLAC__Metadata_SimpleIterator *iterator, FLAC__bool use_padding);
  80958. struct FLAC__Metadata_Chain;
  80959. typedef struct FLAC__Metadata_Chain FLAC__Metadata_Chain;
  80960. struct FLAC__Metadata_Iterator;
  80961. typedef struct FLAC__Metadata_Iterator FLAC__Metadata_Iterator;
  80962. typedef enum {
  80963. FLAC__METADATA_CHAIN_STATUS_OK = 0,
  80964. FLAC__METADATA_CHAIN_STATUS_ILLEGAL_INPUT,
  80965. FLAC__METADATA_CHAIN_STATUS_ERROR_OPENING_FILE,
  80966. FLAC__METADATA_CHAIN_STATUS_NOT_A_FLAC_FILE,
  80967. FLAC__METADATA_CHAIN_STATUS_NOT_WRITABLE,
  80968. FLAC__METADATA_CHAIN_STATUS_BAD_METADATA,
  80969. FLAC__METADATA_CHAIN_STATUS_READ_ERROR,
  80970. FLAC__METADATA_CHAIN_STATUS_SEEK_ERROR,
  80971. FLAC__METADATA_CHAIN_STATUS_WRITE_ERROR,
  80972. FLAC__METADATA_CHAIN_STATUS_RENAME_ERROR,
  80973. FLAC__METADATA_CHAIN_STATUS_UNLINK_ERROR,
  80974. FLAC__METADATA_CHAIN_STATUS_MEMORY_ALLOCATION_ERROR,
  80975. FLAC__METADATA_CHAIN_STATUS_INTERNAL_ERROR,
  80976. FLAC__METADATA_CHAIN_STATUS_INVALID_CALLBACKS,
  80977. FLAC__METADATA_CHAIN_STATUS_READ_WRITE_MISMATCH,
  80978. FLAC__METADATA_CHAIN_STATUS_WRONG_WRITE_CALL
  80979. } FLAC__Metadata_ChainStatus;
  80980. extern FLAC_API const char * const FLAC__Metadata_ChainStatusString[];
  80981. FLAC_API FLAC__Metadata_Chain *FLAC__metadata_chain_new(void);
  80982. FLAC_API void FLAC__metadata_chain_delete(FLAC__Metadata_Chain *chain);
  80983. FLAC_API FLAC__Metadata_ChainStatus FLAC__metadata_chain_status(FLAC__Metadata_Chain *chain);
  80984. FLAC_API FLAC__bool FLAC__metadata_chain_read(FLAC__Metadata_Chain *chain, const char *filename);
  80985. FLAC_API FLAC__bool FLAC__metadata_chain_read_ogg(FLAC__Metadata_Chain *chain, const char *filename);
  80986. FLAC_API FLAC__bool FLAC__metadata_chain_read_with_callbacks(FLAC__Metadata_Chain *chain, FLAC__IOHandle handle, FLAC__IOCallbacks callbacks);
  80987. FLAC_API FLAC__bool FLAC__metadata_chain_read_ogg_with_callbacks(FLAC__Metadata_Chain *chain, FLAC__IOHandle handle, FLAC__IOCallbacks callbacks);
  80988. FLAC_API FLAC__bool FLAC__metadata_chain_check_if_tempfile_needed(FLAC__Metadata_Chain *chain, FLAC__bool use_padding);
  80989. FLAC_API FLAC__bool FLAC__metadata_chain_write(FLAC__Metadata_Chain *chain, FLAC__bool use_padding, FLAC__bool preserve_file_stats);
  80990. FLAC_API FLAC__bool FLAC__metadata_chain_write_with_callbacks(FLAC__Metadata_Chain *chain, FLAC__bool use_padding, FLAC__IOHandle handle, FLAC__IOCallbacks callbacks);
  80991. 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);
  80992. FLAC_API void FLAC__metadata_chain_merge_padding(FLAC__Metadata_Chain *chain);
  80993. FLAC_API void FLAC__metadata_chain_sort_padding(FLAC__Metadata_Chain *chain);
  80994. FLAC_API FLAC__Metadata_Iterator *FLAC__metadata_iterator_new(void);
  80995. FLAC_API void FLAC__metadata_iterator_delete(FLAC__Metadata_Iterator *iterator);
  80996. FLAC_API void FLAC__metadata_iterator_init(FLAC__Metadata_Iterator *iterator, FLAC__Metadata_Chain *chain);
  80997. FLAC_API FLAC__bool FLAC__metadata_iterator_next(FLAC__Metadata_Iterator *iterator);
  80998. FLAC_API FLAC__bool FLAC__metadata_iterator_prev(FLAC__Metadata_Iterator *iterator);
  80999. FLAC_API FLAC__MetadataType FLAC__metadata_iterator_get_block_type(const FLAC__Metadata_Iterator *iterator);
  81000. FLAC_API FLAC__StreamMetadata *FLAC__metadata_iterator_get_block(FLAC__Metadata_Iterator *iterator);
  81001. FLAC_API FLAC__bool FLAC__metadata_iterator_set_block(FLAC__Metadata_Iterator *iterator, FLAC__StreamMetadata *block);
  81002. FLAC_API FLAC__bool FLAC__metadata_iterator_delete_block(FLAC__Metadata_Iterator *iterator, FLAC__bool replace_with_padding);
  81003. FLAC_API FLAC__bool FLAC__metadata_iterator_insert_block_before(FLAC__Metadata_Iterator *iterator, FLAC__StreamMetadata *block);
  81004. FLAC_API FLAC__bool FLAC__metadata_iterator_insert_block_after(FLAC__Metadata_Iterator *iterator, FLAC__StreamMetadata *block);
  81005. FLAC_API FLAC__StreamMetadata *FLAC__metadata_object_new(FLAC__MetadataType type);
  81006. FLAC_API FLAC__StreamMetadata *FLAC__metadata_object_clone(const FLAC__StreamMetadata *object);
  81007. FLAC_API void FLAC__metadata_object_delete(FLAC__StreamMetadata *object);
  81008. FLAC_API FLAC__bool FLAC__metadata_object_is_equal(const FLAC__StreamMetadata *block1, const FLAC__StreamMetadata *block2);
  81009. FLAC_API FLAC__bool FLAC__metadata_object_application_set_data(FLAC__StreamMetadata *object, FLAC__byte *data, unsigned length, FLAC__bool copy);
  81010. FLAC_API FLAC__bool FLAC__metadata_object_seektable_resize_points(FLAC__StreamMetadata *object, unsigned new_num_points);
  81011. FLAC_API void FLAC__metadata_object_seektable_set_point(FLAC__StreamMetadata *object, unsigned point_num, FLAC__StreamMetadata_SeekPoint point);
  81012. FLAC_API FLAC__bool FLAC__metadata_object_seektable_insert_point(FLAC__StreamMetadata *object, unsigned point_num, FLAC__StreamMetadata_SeekPoint point);
  81013. FLAC_API FLAC__bool FLAC__metadata_object_seektable_delete_point(FLAC__StreamMetadata *object, unsigned point_num);
  81014. FLAC_API FLAC__bool FLAC__metadata_object_seektable_is_legal(const FLAC__StreamMetadata *object);
  81015. FLAC_API FLAC__bool FLAC__metadata_object_seektable_template_append_placeholders(FLAC__StreamMetadata *object, unsigned num);
  81016. FLAC_API FLAC__bool FLAC__metadata_object_seektable_template_append_point(FLAC__StreamMetadata *object, FLAC__uint64 sample_number);
  81017. FLAC_API FLAC__bool FLAC__metadata_object_seektable_template_append_points(FLAC__StreamMetadata *object, FLAC__uint64 sample_numbers[], unsigned num);
  81018. FLAC_API FLAC__bool FLAC__metadata_object_seektable_template_append_spaced_points(FLAC__StreamMetadata *object, unsigned num, FLAC__uint64 total_samples);
  81019. FLAC_API FLAC__bool FLAC__metadata_object_seektable_template_append_spaced_points_by_samples(FLAC__StreamMetadata *object, unsigned samples, FLAC__uint64 total_samples);
  81020. FLAC_API FLAC__bool FLAC__metadata_object_seektable_template_sort(FLAC__StreamMetadata *object, FLAC__bool compact);
  81021. FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_set_vendor_string(FLAC__StreamMetadata *object, FLAC__StreamMetadata_VorbisComment_Entry entry, FLAC__bool copy);
  81022. FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_resize_comments(FLAC__StreamMetadata *object, unsigned new_num_comments);
  81023. FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_set_comment(FLAC__StreamMetadata *object, unsigned comment_num, FLAC__StreamMetadata_VorbisComment_Entry entry, FLAC__bool copy);
  81024. FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_insert_comment(FLAC__StreamMetadata *object, unsigned comment_num, FLAC__StreamMetadata_VorbisComment_Entry entry, FLAC__bool copy);
  81025. FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_append_comment(FLAC__StreamMetadata *object, FLAC__StreamMetadata_VorbisComment_Entry entry, FLAC__bool copy);
  81026. FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_replace_comment(FLAC__StreamMetadata *object, FLAC__StreamMetadata_VorbisComment_Entry entry, FLAC__bool all, FLAC__bool copy);
  81027. FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_delete_comment(FLAC__StreamMetadata *object, unsigned comment_num);
  81028. 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);
  81029. 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);
  81030. FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_entry_matches(const FLAC__StreamMetadata_VorbisComment_Entry entry, const char *field_name, unsigned field_name_length);
  81031. FLAC_API int FLAC__metadata_object_vorbiscomment_find_entry_from(const FLAC__StreamMetadata *object, unsigned offset, const char *field_name);
  81032. FLAC_API int FLAC__metadata_object_vorbiscomment_remove_entry_matching(FLAC__StreamMetadata *object, const char *field_name);
  81033. FLAC_API int FLAC__metadata_object_vorbiscomment_remove_entries_matching(FLAC__StreamMetadata *object, const char *field_name);
  81034. FLAC_API FLAC__StreamMetadata_CueSheet_Track *FLAC__metadata_object_cuesheet_track_new(void);
  81035. FLAC_API FLAC__StreamMetadata_CueSheet_Track *FLAC__metadata_object_cuesheet_track_clone(const FLAC__StreamMetadata_CueSheet_Track *object);
  81036. FLAC_API void FLAC__metadata_object_cuesheet_track_delete(FLAC__StreamMetadata_CueSheet_Track *object);
  81037. FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_track_resize_indices(FLAC__StreamMetadata *object, unsigned track_num, unsigned new_num_indices);
  81038. 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);
  81039. FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_track_insert_blank_index(FLAC__StreamMetadata *object, unsigned track_num, unsigned index_num);
  81040. FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_track_delete_index(FLAC__StreamMetadata *object, unsigned track_num, unsigned index_num);
  81041. FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_resize_tracks(FLAC__StreamMetadata *object, unsigned new_num_tracks);
  81042. FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_set_track(FLAC__StreamMetadata *object, unsigned track_num, FLAC__StreamMetadata_CueSheet_Track *track, FLAC__bool copy);
  81043. FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_insert_track(FLAC__StreamMetadata *object, unsigned track_num, FLAC__StreamMetadata_CueSheet_Track *track, FLAC__bool copy);
  81044. FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_insert_blank_track(FLAC__StreamMetadata *object, unsigned track_num);
  81045. FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_delete_track(FLAC__StreamMetadata *object, unsigned track_num);
  81046. FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_is_legal(const FLAC__StreamMetadata *object, FLAC__bool check_cd_da_subset, const char **violation);
  81047. FLAC_API FLAC__uint32 FLAC__metadata_object_cuesheet_calculate_cddb_id(const FLAC__StreamMetadata *object);
  81048. FLAC_API FLAC__bool FLAC__metadata_object_picture_set_mime_type(FLAC__StreamMetadata *object, char *mime_type, FLAC__bool copy);
  81049. FLAC_API FLAC__bool FLAC__metadata_object_picture_set_description(FLAC__StreamMetadata *object, FLAC__byte *description, FLAC__bool copy);
  81050. FLAC_API FLAC__bool FLAC__metadata_object_picture_set_data(FLAC__StreamMetadata *object, FLAC__byte *data, FLAC__uint32 length, FLAC__bool copy);
  81051. FLAC_API FLAC__bool FLAC__metadata_object_picture_is_legal(const FLAC__StreamMetadata *object, const char **violation);
  81052. #ifdef __cplusplus
  81053. }
  81054. #endif
  81055. #endif
  81056. /*** End of inlined file: metadata.h ***/
  81057. /*** Start of inlined file: stream_decoder.h ***/
  81058. #ifndef FLAC__STREAM_DECODER_H
  81059. #define FLAC__STREAM_DECODER_H
  81060. #include <stdio.h> /* for FILE */
  81061. #ifdef __cplusplus
  81062. extern "C" {
  81063. #endif
  81064. typedef enum {
  81065. FLAC__STREAM_DECODER_SEARCH_FOR_METADATA = 0,
  81066. FLAC__STREAM_DECODER_READ_METADATA,
  81067. FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC,
  81068. FLAC__STREAM_DECODER_READ_FRAME,
  81069. FLAC__STREAM_DECODER_END_OF_STREAM,
  81070. FLAC__STREAM_DECODER_OGG_ERROR,
  81071. FLAC__STREAM_DECODER_SEEK_ERROR,
  81072. FLAC__STREAM_DECODER_ABORTED,
  81073. FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR,
  81074. FLAC__STREAM_DECODER_UNINITIALIZED
  81075. } FLAC__StreamDecoderState;
  81076. extern FLAC_API const char * const FLAC__StreamDecoderStateString[];
  81077. typedef enum {
  81078. FLAC__STREAM_DECODER_INIT_STATUS_OK = 0,
  81079. FLAC__STREAM_DECODER_INIT_STATUS_UNSUPPORTED_CONTAINER,
  81080. FLAC__STREAM_DECODER_INIT_STATUS_INVALID_CALLBACKS,
  81081. FLAC__STREAM_DECODER_INIT_STATUS_MEMORY_ALLOCATION_ERROR,
  81082. FLAC__STREAM_DECODER_INIT_STATUS_ERROR_OPENING_FILE,
  81083. FLAC__STREAM_DECODER_INIT_STATUS_ALREADY_INITIALIZED
  81084. } FLAC__StreamDecoderInitStatus;
  81085. extern FLAC_API const char * const FLAC__StreamDecoderInitStatusString[];
  81086. typedef enum {
  81087. FLAC__STREAM_DECODER_READ_STATUS_CONTINUE,
  81088. FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM,
  81089. FLAC__STREAM_DECODER_READ_STATUS_ABORT
  81090. } FLAC__StreamDecoderReadStatus;
  81091. extern FLAC_API const char * const FLAC__StreamDecoderReadStatusString[];
  81092. typedef enum {
  81093. FLAC__STREAM_DECODER_SEEK_STATUS_OK,
  81094. FLAC__STREAM_DECODER_SEEK_STATUS_ERROR,
  81095. FLAC__STREAM_DECODER_SEEK_STATUS_UNSUPPORTED
  81096. } FLAC__StreamDecoderSeekStatus;
  81097. extern FLAC_API const char * const FLAC__StreamDecoderSeekStatusString[];
  81098. typedef enum {
  81099. FLAC__STREAM_DECODER_TELL_STATUS_OK,
  81100. FLAC__STREAM_DECODER_TELL_STATUS_ERROR,
  81101. FLAC__STREAM_DECODER_TELL_STATUS_UNSUPPORTED
  81102. } FLAC__StreamDecoderTellStatus;
  81103. extern FLAC_API const char * const FLAC__StreamDecoderTellStatusString[];
  81104. typedef enum {
  81105. FLAC__STREAM_DECODER_LENGTH_STATUS_OK,
  81106. FLAC__STREAM_DECODER_LENGTH_STATUS_ERROR,
  81107. FLAC__STREAM_DECODER_LENGTH_STATUS_UNSUPPORTED
  81108. } FLAC__StreamDecoderLengthStatus;
  81109. extern FLAC_API const char * const FLAC__StreamDecoderLengthStatusString[];
  81110. typedef enum {
  81111. FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE,
  81112. FLAC__STREAM_DECODER_WRITE_STATUS_ABORT
  81113. } FLAC__StreamDecoderWriteStatus;
  81114. extern FLAC_API const char * const FLAC__StreamDecoderWriteStatusString[];
  81115. typedef enum {
  81116. FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC,
  81117. FLAC__STREAM_DECODER_ERROR_STATUS_BAD_HEADER,
  81118. FLAC__STREAM_DECODER_ERROR_STATUS_FRAME_CRC_MISMATCH,
  81119. FLAC__STREAM_DECODER_ERROR_STATUS_UNPARSEABLE_STREAM
  81120. } FLAC__StreamDecoderErrorStatus;
  81121. extern FLAC_API const char * const FLAC__StreamDecoderErrorStatusString[];
  81122. struct FLAC__StreamDecoderProtected;
  81123. struct FLAC__StreamDecoderPrivate;
  81124. typedef struct {
  81125. struct FLAC__StreamDecoderProtected *protected_; /* avoid the C++ keyword 'protected' */
  81126. struct FLAC__StreamDecoderPrivate *private_; /* avoid the C++ keyword 'private' */
  81127. } FLAC__StreamDecoder;
  81128. typedef FLAC__StreamDecoderReadStatus (*FLAC__StreamDecoderReadCallback)(const FLAC__StreamDecoder *decoder, FLAC__byte buffer[], size_t *bytes, void *client_data);
  81129. typedef FLAC__StreamDecoderSeekStatus (*FLAC__StreamDecoderSeekCallback)(const FLAC__StreamDecoder *decoder, FLAC__uint64 absolute_byte_offset, void *client_data);
  81130. typedef FLAC__StreamDecoderTellStatus (*FLAC__StreamDecoderTellCallback)(const FLAC__StreamDecoder *decoder, FLAC__uint64 *absolute_byte_offset, void *client_data);
  81131. typedef FLAC__StreamDecoderLengthStatus (*FLAC__StreamDecoderLengthCallback)(const FLAC__StreamDecoder *decoder, FLAC__uint64 *stream_length, void *client_data);
  81132. typedef FLAC__bool (*FLAC__StreamDecoderEofCallback)(const FLAC__StreamDecoder *decoder, void *client_data);
  81133. typedef FLAC__StreamDecoderWriteStatus (*FLAC__StreamDecoderWriteCallback)(const FLAC__StreamDecoder *decoder, const FLAC__Frame *frame, const FLAC__int32 * const buffer[], void *client_data);
  81134. typedef void (*FLAC__StreamDecoderMetadataCallback)(const FLAC__StreamDecoder *decoder, const FLAC__StreamMetadata *metadata, void *client_data);
  81135. typedef void (*FLAC__StreamDecoderErrorCallback)(const FLAC__StreamDecoder *decoder, FLAC__StreamDecoderErrorStatus status, void *client_data);
  81136. FLAC_API FLAC__StreamDecoder *FLAC__stream_decoder_new(void);
  81137. FLAC_API void FLAC__stream_decoder_delete(FLAC__StreamDecoder *decoder);
  81138. FLAC_API FLAC__bool FLAC__stream_decoder_set_ogg_serial_number(FLAC__StreamDecoder *decoder, long serial_number);
  81139. FLAC_API FLAC__bool FLAC__stream_decoder_set_md5_checking(FLAC__StreamDecoder *decoder, FLAC__bool value);
  81140. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_respond(FLAC__StreamDecoder *decoder, FLAC__MetadataType type);
  81141. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_respond_application(FLAC__StreamDecoder *decoder, const FLAC__byte id[4]);
  81142. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_respond_all(FLAC__StreamDecoder *decoder);
  81143. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_ignore(FLAC__StreamDecoder *decoder, FLAC__MetadataType type);
  81144. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_ignore_application(FLAC__StreamDecoder *decoder, const FLAC__byte id[4]);
  81145. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_ignore_all(FLAC__StreamDecoder *decoder);
  81146. FLAC_API FLAC__StreamDecoderState FLAC__stream_decoder_get_state(const FLAC__StreamDecoder *decoder);
  81147. FLAC_API const char *FLAC__stream_decoder_get_resolved_state_string(const FLAC__StreamDecoder *decoder);
  81148. FLAC_API FLAC__bool FLAC__stream_decoder_get_md5_checking(const FLAC__StreamDecoder *decoder);
  81149. FLAC_API FLAC__uint64 FLAC__stream_decoder_get_total_samples(const FLAC__StreamDecoder *decoder);
  81150. FLAC_API unsigned FLAC__stream_decoder_get_channels(const FLAC__StreamDecoder *decoder);
  81151. FLAC_API FLAC__ChannelAssignment FLAC__stream_decoder_get_channel_assignment(const FLAC__StreamDecoder *decoder);
  81152. FLAC_API unsigned FLAC__stream_decoder_get_bits_per_sample(const FLAC__StreamDecoder *decoder);
  81153. FLAC_API unsigned FLAC__stream_decoder_get_sample_rate(const FLAC__StreamDecoder *decoder);
  81154. FLAC_API unsigned FLAC__stream_decoder_get_blocksize(const FLAC__StreamDecoder *decoder);
  81155. FLAC_API FLAC__bool FLAC__stream_decoder_get_decode_position(const FLAC__StreamDecoder *decoder, FLAC__uint64 *position);
  81156. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_stream(
  81157. FLAC__StreamDecoder *decoder,
  81158. FLAC__StreamDecoderReadCallback read_callback,
  81159. FLAC__StreamDecoderSeekCallback seek_callback,
  81160. FLAC__StreamDecoderTellCallback tell_callback,
  81161. FLAC__StreamDecoderLengthCallback length_callback,
  81162. FLAC__StreamDecoderEofCallback eof_callback,
  81163. FLAC__StreamDecoderWriteCallback write_callback,
  81164. FLAC__StreamDecoderMetadataCallback metadata_callback,
  81165. FLAC__StreamDecoderErrorCallback error_callback,
  81166. void *client_data
  81167. );
  81168. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_ogg_stream(
  81169. FLAC__StreamDecoder *decoder,
  81170. FLAC__StreamDecoderReadCallback read_callback,
  81171. FLAC__StreamDecoderSeekCallback seek_callback,
  81172. FLAC__StreamDecoderTellCallback tell_callback,
  81173. FLAC__StreamDecoderLengthCallback length_callback,
  81174. FLAC__StreamDecoderEofCallback eof_callback,
  81175. FLAC__StreamDecoderWriteCallback write_callback,
  81176. FLAC__StreamDecoderMetadataCallback metadata_callback,
  81177. FLAC__StreamDecoderErrorCallback error_callback,
  81178. void *client_data
  81179. );
  81180. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_FILE(
  81181. FLAC__StreamDecoder *decoder,
  81182. FILE *file,
  81183. FLAC__StreamDecoderWriteCallback write_callback,
  81184. FLAC__StreamDecoderMetadataCallback metadata_callback,
  81185. FLAC__StreamDecoderErrorCallback error_callback,
  81186. void *client_data
  81187. );
  81188. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_ogg_FILE(
  81189. FLAC__StreamDecoder *decoder,
  81190. FILE *file,
  81191. FLAC__StreamDecoderWriteCallback write_callback,
  81192. FLAC__StreamDecoderMetadataCallback metadata_callback,
  81193. FLAC__StreamDecoderErrorCallback error_callback,
  81194. void *client_data
  81195. );
  81196. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_file(
  81197. FLAC__StreamDecoder *decoder,
  81198. const char *filename,
  81199. FLAC__StreamDecoderWriteCallback write_callback,
  81200. FLAC__StreamDecoderMetadataCallback metadata_callback,
  81201. FLAC__StreamDecoderErrorCallback error_callback,
  81202. void *client_data
  81203. );
  81204. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_ogg_file(
  81205. FLAC__StreamDecoder *decoder,
  81206. const char *filename,
  81207. FLAC__StreamDecoderWriteCallback write_callback,
  81208. FLAC__StreamDecoderMetadataCallback metadata_callback,
  81209. FLAC__StreamDecoderErrorCallback error_callback,
  81210. void *client_data
  81211. );
  81212. FLAC_API FLAC__bool FLAC__stream_decoder_finish(FLAC__StreamDecoder *decoder);
  81213. FLAC_API FLAC__bool FLAC__stream_decoder_flush(FLAC__StreamDecoder *decoder);
  81214. FLAC_API FLAC__bool FLAC__stream_decoder_reset(FLAC__StreamDecoder *decoder);
  81215. FLAC_API FLAC__bool FLAC__stream_decoder_process_single(FLAC__StreamDecoder *decoder);
  81216. FLAC_API FLAC__bool FLAC__stream_decoder_process_until_end_of_metadata(FLAC__StreamDecoder *decoder);
  81217. FLAC_API FLAC__bool FLAC__stream_decoder_process_until_end_of_stream(FLAC__StreamDecoder *decoder);
  81218. FLAC_API FLAC__bool FLAC__stream_decoder_skip_single_frame(FLAC__StreamDecoder *decoder);
  81219. FLAC_API FLAC__bool FLAC__stream_decoder_seek_absolute(FLAC__StreamDecoder *decoder, FLAC__uint64 sample);
  81220. #ifdef __cplusplus
  81221. }
  81222. #endif
  81223. #endif
  81224. /*** End of inlined file: stream_decoder.h ***/
  81225. /*** Start of inlined file: stream_encoder.h ***/
  81226. #ifndef FLAC__STREAM_ENCODER_H
  81227. #define FLAC__STREAM_ENCODER_H
  81228. #include <stdio.h> /* for FILE */
  81229. #ifdef __cplusplus
  81230. extern "C" {
  81231. #endif
  81232. typedef enum {
  81233. FLAC__STREAM_ENCODER_OK = 0,
  81234. FLAC__STREAM_ENCODER_UNINITIALIZED,
  81235. FLAC__STREAM_ENCODER_OGG_ERROR,
  81236. FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR,
  81237. FLAC__STREAM_ENCODER_VERIFY_MISMATCH_IN_AUDIO_DATA,
  81238. FLAC__STREAM_ENCODER_CLIENT_ERROR,
  81239. FLAC__STREAM_ENCODER_IO_ERROR,
  81240. FLAC__STREAM_ENCODER_FRAMING_ERROR,
  81241. FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR
  81242. } FLAC__StreamEncoderState;
  81243. extern FLAC_API const char * const FLAC__StreamEncoderStateString[];
  81244. typedef enum {
  81245. FLAC__STREAM_ENCODER_INIT_STATUS_OK = 0,
  81246. FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR,
  81247. FLAC__STREAM_ENCODER_INIT_STATUS_UNSUPPORTED_CONTAINER,
  81248. FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_CALLBACKS,
  81249. FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_NUMBER_OF_CHANNELS,
  81250. FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_BITS_PER_SAMPLE,
  81251. FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_SAMPLE_RATE,
  81252. FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_BLOCK_SIZE,
  81253. FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_MAX_LPC_ORDER,
  81254. FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_QLP_COEFF_PRECISION,
  81255. FLAC__STREAM_ENCODER_INIT_STATUS_BLOCK_SIZE_TOO_SMALL_FOR_LPC_ORDER,
  81256. FLAC__STREAM_ENCODER_INIT_STATUS_NOT_STREAMABLE,
  81257. FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA,
  81258. FLAC__STREAM_ENCODER_INIT_STATUS_ALREADY_INITIALIZED
  81259. } FLAC__StreamEncoderInitStatus;
  81260. extern FLAC_API const char * const FLAC__StreamEncoderInitStatusString[];
  81261. typedef enum {
  81262. FLAC__STREAM_ENCODER_READ_STATUS_CONTINUE,
  81263. FLAC__STREAM_ENCODER_READ_STATUS_END_OF_STREAM,
  81264. FLAC__STREAM_ENCODER_READ_STATUS_ABORT,
  81265. FLAC__STREAM_ENCODER_READ_STATUS_UNSUPPORTED
  81266. } FLAC__StreamEncoderReadStatus;
  81267. extern FLAC_API const char * const FLAC__StreamEncoderReadStatusString[];
  81268. typedef enum {
  81269. FLAC__STREAM_ENCODER_WRITE_STATUS_OK = 0,
  81270. FLAC__STREAM_ENCODER_WRITE_STATUS_FATAL_ERROR
  81271. } FLAC__StreamEncoderWriteStatus;
  81272. extern FLAC_API const char * const FLAC__StreamEncoderWriteStatusString[];
  81273. typedef enum {
  81274. FLAC__STREAM_ENCODER_SEEK_STATUS_OK,
  81275. FLAC__STREAM_ENCODER_SEEK_STATUS_ERROR,
  81276. FLAC__STREAM_ENCODER_SEEK_STATUS_UNSUPPORTED
  81277. } FLAC__StreamEncoderSeekStatus;
  81278. extern FLAC_API const char * const FLAC__StreamEncoderSeekStatusString[];
  81279. typedef enum {
  81280. FLAC__STREAM_ENCODER_TELL_STATUS_OK,
  81281. FLAC__STREAM_ENCODER_TELL_STATUS_ERROR,
  81282. FLAC__STREAM_ENCODER_TELL_STATUS_UNSUPPORTED
  81283. } FLAC__StreamEncoderTellStatus;
  81284. extern FLAC_API const char * const FLAC__StreamEncoderTellStatusString[];
  81285. struct FLAC__StreamEncoderProtected;
  81286. struct FLAC__StreamEncoderPrivate;
  81287. typedef struct {
  81288. struct FLAC__StreamEncoderProtected *protected_; /* avoid the C++ keyword 'protected' */
  81289. struct FLAC__StreamEncoderPrivate *private_; /* avoid the C++ keyword 'private' */
  81290. } FLAC__StreamEncoder;
  81291. typedef FLAC__StreamEncoderReadStatus (*FLAC__StreamEncoderReadCallback)(const FLAC__StreamEncoder *encoder, FLAC__byte buffer[], size_t *bytes, void *client_data);
  81292. typedef FLAC__StreamEncoderWriteStatus (*FLAC__StreamEncoderWriteCallback)(const FLAC__StreamEncoder *encoder, const FLAC__byte buffer[], size_t bytes, unsigned samples, unsigned current_frame, void *client_data);
  81293. typedef FLAC__StreamEncoderSeekStatus (*FLAC__StreamEncoderSeekCallback)(const FLAC__StreamEncoder *encoder, FLAC__uint64 absolute_byte_offset, void *client_data);
  81294. typedef FLAC__StreamEncoderTellStatus (*FLAC__StreamEncoderTellCallback)(const FLAC__StreamEncoder *encoder, FLAC__uint64 *absolute_byte_offset, void *client_data);
  81295. typedef void (*FLAC__StreamEncoderMetadataCallback)(const FLAC__StreamEncoder *encoder, const FLAC__StreamMetadata *metadata, void *client_data);
  81296. 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);
  81297. FLAC_API FLAC__StreamEncoder *FLAC__stream_encoder_new(void);
  81298. FLAC_API void FLAC__stream_encoder_delete(FLAC__StreamEncoder *encoder);
  81299. FLAC_API FLAC__bool FLAC__stream_encoder_set_ogg_serial_number(FLAC__StreamEncoder *encoder, long serial_number);
  81300. FLAC_API FLAC__bool FLAC__stream_encoder_set_verify(FLAC__StreamEncoder *encoder, FLAC__bool value);
  81301. FLAC_API FLAC__bool FLAC__stream_encoder_set_streamable_subset(FLAC__StreamEncoder *encoder, FLAC__bool value);
  81302. FLAC_API FLAC__bool FLAC__stream_encoder_set_channels(FLAC__StreamEncoder *encoder, unsigned value);
  81303. FLAC_API FLAC__bool FLAC__stream_encoder_set_bits_per_sample(FLAC__StreamEncoder *encoder, unsigned value);
  81304. FLAC_API FLAC__bool FLAC__stream_encoder_set_sample_rate(FLAC__StreamEncoder *encoder, unsigned value);
  81305. FLAC_API FLAC__bool FLAC__stream_encoder_set_compression_level(FLAC__StreamEncoder *encoder, unsigned value);
  81306. FLAC_API FLAC__bool FLAC__stream_encoder_set_blocksize(FLAC__StreamEncoder *encoder, unsigned value);
  81307. FLAC_API FLAC__bool FLAC__stream_encoder_set_do_mid_side_stereo(FLAC__StreamEncoder *encoder, FLAC__bool value);
  81308. FLAC_API FLAC__bool FLAC__stream_encoder_set_loose_mid_side_stereo(FLAC__StreamEncoder *encoder, FLAC__bool value);
  81309. FLAC_API FLAC__bool FLAC__stream_encoder_set_apodization(FLAC__StreamEncoder *encoder, const char *specification);
  81310. FLAC_API FLAC__bool FLAC__stream_encoder_set_max_lpc_order(FLAC__StreamEncoder *encoder, unsigned value);
  81311. FLAC_API FLAC__bool FLAC__stream_encoder_set_qlp_coeff_precision(FLAC__StreamEncoder *encoder, unsigned value);
  81312. FLAC_API FLAC__bool FLAC__stream_encoder_set_do_qlp_coeff_prec_search(FLAC__StreamEncoder *encoder, FLAC__bool value);
  81313. FLAC_API FLAC__bool FLAC__stream_encoder_set_do_escape_coding(FLAC__StreamEncoder *encoder, FLAC__bool value);
  81314. FLAC_API FLAC__bool FLAC__stream_encoder_set_do_exhaustive_model_search(FLAC__StreamEncoder *encoder, FLAC__bool value);
  81315. FLAC_API FLAC__bool FLAC__stream_encoder_set_min_residual_partition_order(FLAC__StreamEncoder *encoder, unsigned value);
  81316. FLAC_API FLAC__bool FLAC__stream_encoder_set_max_residual_partition_order(FLAC__StreamEncoder *encoder, unsigned value);
  81317. FLAC_API FLAC__bool FLAC__stream_encoder_set_rice_parameter_search_dist(FLAC__StreamEncoder *encoder, unsigned value);
  81318. FLAC_API FLAC__bool FLAC__stream_encoder_set_total_samples_estimate(FLAC__StreamEncoder *encoder, FLAC__uint64 value);
  81319. FLAC_API FLAC__bool FLAC__stream_encoder_set_metadata(FLAC__StreamEncoder *encoder, FLAC__StreamMetadata **metadata, unsigned num_blocks);
  81320. FLAC_API FLAC__StreamEncoderState FLAC__stream_encoder_get_state(const FLAC__StreamEncoder *encoder);
  81321. FLAC_API FLAC__StreamDecoderState FLAC__stream_encoder_get_verify_decoder_state(const FLAC__StreamEncoder *encoder);
  81322. FLAC_API const char *FLAC__stream_encoder_get_resolved_state_string(const FLAC__StreamEncoder *encoder);
  81323. 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);
  81324. FLAC_API FLAC__bool FLAC__stream_encoder_get_verify(const FLAC__StreamEncoder *encoder);
  81325. FLAC_API FLAC__bool FLAC__stream_encoder_get_streamable_subset(const FLAC__StreamEncoder *encoder);
  81326. FLAC_API unsigned FLAC__stream_encoder_get_channels(const FLAC__StreamEncoder *encoder);
  81327. FLAC_API unsigned FLAC__stream_encoder_get_bits_per_sample(const FLAC__StreamEncoder *encoder);
  81328. FLAC_API unsigned FLAC__stream_encoder_get_sample_rate(const FLAC__StreamEncoder *encoder);
  81329. FLAC_API unsigned FLAC__stream_encoder_get_blocksize(const FLAC__StreamEncoder *encoder);
  81330. FLAC_API FLAC__bool FLAC__stream_encoder_get_do_mid_side_stereo(const FLAC__StreamEncoder *encoder);
  81331. FLAC_API FLAC__bool FLAC__stream_encoder_get_loose_mid_side_stereo(const FLAC__StreamEncoder *encoder);
  81332. FLAC_API unsigned FLAC__stream_encoder_get_max_lpc_order(const FLAC__StreamEncoder *encoder);
  81333. FLAC_API unsigned FLAC__stream_encoder_get_qlp_coeff_precision(const FLAC__StreamEncoder *encoder);
  81334. FLAC_API FLAC__bool FLAC__stream_encoder_get_do_qlp_coeff_prec_search(const FLAC__StreamEncoder *encoder);
  81335. FLAC_API FLAC__bool FLAC__stream_encoder_get_do_escape_coding(const FLAC__StreamEncoder *encoder);
  81336. FLAC_API FLAC__bool FLAC__stream_encoder_get_do_exhaustive_model_search(const FLAC__StreamEncoder *encoder);
  81337. FLAC_API unsigned FLAC__stream_encoder_get_min_residual_partition_order(const FLAC__StreamEncoder *encoder);
  81338. FLAC_API unsigned FLAC__stream_encoder_get_max_residual_partition_order(const FLAC__StreamEncoder *encoder);
  81339. FLAC_API unsigned FLAC__stream_encoder_get_rice_parameter_search_dist(const FLAC__StreamEncoder *encoder);
  81340. FLAC_API FLAC__uint64 FLAC__stream_encoder_get_total_samples_estimate(const FLAC__StreamEncoder *encoder);
  81341. 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);
  81342. 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);
  81343. FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_FILE(FLAC__StreamEncoder *encoder, FILE *file, FLAC__StreamEncoderProgressCallback progress_callback, void *client_data);
  81344. FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_ogg_FILE(FLAC__StreamEncoder *encoder, FILE *file, FLAC__StreamEncoderProgressCallback progress_callback, void *client_data);
  81345. FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_file(FLAC__StreamEncoder *encoder, const char *filename, FLAC__StreamEncoderProgressCallback progress_callback, void *client_data);
  81346. FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_ogg_file(FLAC__StreamEncoder *encoder, const char *filename, FLAC__StreamEncoderProgressCallback progress_callback, void *client_data);
  81347. FLAC_API FLAC__bool FLAC__stream_encoder_finish(FLAC__StreamEncoder *encoder);
  81348. FLAC_API FLAC__bool FLAC__stream_encoder_process(FLAC__StreamEncoder *encoder, const FLAC__int32 * const buffer[], unsigned samples);
  81349. FLAC_API FLAC__bool FLAC__stream_encoder_process_interleaved(FLAC__StreamEncoder *encoder, const FLAC__int32 buffer[], unsigned samples);
  81350. #ifdef __cplusplus
  81351. }
  81352. #endif
  81353. #endif
  81354. /*** End of inlined file: stream_encoder.h ***/
  81355. #ifdef _MSC_VER
  81356. static _inline FLAC__uint32 local_swap32_(FLAC__uint32 x)
  81357. {
  81358. x = ((x<<8)&0xFF00FF00) | ((x>>8)&0x00FF00FF);
  81359. return (x>>16) | (x<<16);
  81360. }
  81361. #endif
  81362. #if defined(_MSC_VER) && defined(_X86_)
  81363. static void local_swap32_block_(FLAC__uint32 *start, FLAC__uint32 len)
  81364. {
  81365. __asm {
  81366. mov edx, start
  81367. mov ecx, len
  81368. test ecx, ecx
  81369. loop1:
  81370. jz done1
  81371. mov eax, [edx]
  81372. bswap eax
  81373. mov [edx], eax
  81374. add edx, 4
  81375. dec ecx
  81376. jmp short loop1
  81377. done1:
  81378. }
  81379. }
  81380. #endif
  81381. #endif
  81382. /*** End of inlined file: all.h ***/
  81383. /*** Start of inlined file: bitmath.c ***/
  81384. /*** Start of inlined file: juce_FlacHeader.h ***/
  81385. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  81386. // tasks..
  81387. #define VERSION "1.2.1"
  81388. #define FLAC__NO_DLL 1
  81389. #if JUCE_MSVC
  81390. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  81391. #endif
  81392. #if JUCE_MAC
  81393. #define FLAC__SYS_DARWIN 1
  81394. #endif
  81395. /*** End of inlined file: juce_FlacHeader.h ***/
  81396. #if JUCE_USE_FLAC
  81397. #if HAVE_CONFIG_H
  81398. # include <config.h>
  81399. #endif
  81400. /*** Start of inlined file: bitmath.h ***/
  81401. #ifndef FLAC__PRIVATE__BITMATH_H
  81402. #define FLAC__PRIVATE__BITMATH_H
  81403. unsigned FLAC__bitmath_ilog2(FLAC__uint32 v);
  81404. unsigned FLAC__bitmath_ilog2_wide(FLAC__uint64 v);
  81405. unsigned FLAC__bitmath_silog2(int v);
  81406. unsigned FLAC__bitmath_silog2_wide(FLAC__int64 v);
  81407. #endif
  81408. /*** End of inlined file: bitmath.h ***/
  81409. unsigned FLAC__bitmath_ilog2(FLAC__uint32 v)
  81410. {
  81411. unsigned l = 0;
  81412. FLAC__ASSERT(v > 0);
  81413. while(v >>= 1)
  81414. l++;
  81415. return l;
  81416. }
  81417. unsigned FLAC__bitmath_ilog2_wide(FLAC__uint64 v)
  81418. {
  81419. unsigned l = 0;
  81420. FLAC__ASSERT(v > 0);
  81421. while(v >>= 1)
  81422. l++;
  81423. return l;
  81424. }
  81425. unsigned FLAC__bitmath_silog2(int v)
  81426. {
  81427. while(1) {
  81428. if(v == 0) {
  81429. return 0;
  81430. }
  81431. else if(v > 0) {
  81432. unsigned l = 0;
  81433. while(v) {
  81434. l++;
  81435. v >>= 1;
  81436. }
  81437. return l+1;
  81438. }
  81439. else if(v == -1) {
  81440. return 2;
  81441. }
  81442. else {
  81443. v++;
  81444. v = -v;
  81445. }
  81446. }
  81447. }
  81448. unsigned FLAC__bitmath_silog2_wide(FLAC__int64 v)
  81449. {
  81450. while(1) {
  81451. if(v == 0) {
  81452. return 0;
  81453. }
  81454. else if(v > 0) {
  81455. unsigned l = 0;
  81456. while(v) {
  81457. l++;
  81458. v >>= 1;
  81459. }
  81460. return l+1;
  81461. }
  81462. else if(v == -1) {
  81463. return 2;
  81464. }
  81465. else {
  81466. v++;
  81467. v = -v;
  81468. }
  81469. }
  81470. }
  81471. #endif
  81472. /*** End of inlined file: bitmath.c ***/
  81473. /*** Start of inlined file: bitreader.c ***/
  81474. /*** Start of inlined file: juce_FlacHeader.h ***/
  81475. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  81476. // tasks..
  81477. #define VERSION "1.2.1"
  81478. #define FLAC__NO_DLL 1
  81479. #if JUCE_MSVC
  81480. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  81481. #endif
  81482. #if JUCE_MAC
  81483. #define FLAC__SYS_DARWIN 1
  81484. #endif
  81485. /*** End of inlined file: juce_FlacHeader.h ***/
  81486. #if JUCE_USE_FLAC
  81487. #if HAVE_CONFIG_H
  81488. # include <config.h>
  81489. #endif
  81490. #include <stdlib.h> /* for malloc() */
  81491. #include <string.h> /* for memcpy(), memset() */
  81492. #ifdef _MSC_VER
  81493. #include <winsock.h> /* for ntohl() */
  81494. #elif defined FLAC__SYS_DARWIN
  81495. #include <machine/endian.h> /* for ntohl() */
  81496. #elif defined __MINGW32__
  81497. #include <winsock.h> /* for ntohl() */
  81498. #else
  81499. #include <netinet/in.h> /* for ntohl() */
  81500. #endif
  81501. /*** Start of inlined file: bitreader.h ***/
  81502. #ifndef FLAC__PRIVATE__BITREADER_H
  81503. #define FLAC__PRIVATE__BITREADER_H
  81504. #include <stdio.h> /* for FILE */
  81505. /*** Start of inlined file: cpu.h ***/
  81506. #ifndef FLAC__PRIVATE__CPU_H
  81507. #define FLAC__PRIVATE__CPU_H
  81508. #ifdef HAVE_CONFIG_H
  81509. #include <config.h>
  81510. #endif
  81511. typedef enum {
  81512. FLAC__CPUINFO_TYPE_IA32,
  81513. FLAC__CPUINFO_TYPE_PPC,
  81514. FLAC__CPUINFO_TYPE_UNKNOWN
  81515. } FLAC__CPUInfo_Type;
  81516. typedef struct {
  81517. FLAC__bool cpuid;
  81518. FLAC__bool bswap;
  81519. FLAC__bool cmov;
  81520. FLAC__bool mmx;
  81521. FLAC__bool fxsr;
  81522. FLAC__bool sse;
  81523. FLAC__bool sse2;
  81524. FLAC__bool sse3;
  81525. FLAC__bool ssse3;
  81526. FLAC__bool _3dnow;
  81527. FLAC__bool ext3dnow;
  81528. FLAC__bool extmmx;
  81529. } FLAC__CPUInfo_IA32;
  81530. typedef struct {
  81531. FLAC__bool altivec;
  81532. FLAC__bool ppc64;
  81533. } FLAC__CPUInfo_PPC;
  81534. typedef struct {
  81535. FLAC__bool use_asm;
  81536. FLAC__CPUInfo_Type type;
  81537. union {
  81538. FLAC__CPUInfo_IA32 ia32;
  81539. FLAC__CPUInfo_PPC ppc;
  81540. } data;
  81541. } FLAC__CPUInfo;
  81542. void FLAC__cpu_info(FLAC__CPUInfo *info);
  81543. #ifndef FLAC__NO_ASM
  81544. #ifdef FLAC__CPU_IA32
  81545. #ifdef FLAC__HAS_NASM
  81546. FLAC__uint32 FLAC__cpu_have_cpuid_asm_ia32(void);
  81547. void FLAC__cpu_info_asm_ia32(FLAC__uint32 *flags_edx, FLAC__uint32 *flags_ecx);
  81548. FLAC__uint32 FLAC__cpu_info_extended_amd_asm_ia32(void);
  81549. #endif
  81550. #endif
  81551. #endif
  81552. #endif
  81553. /*** End of inlined file: cpu.h ***/
  81554. struct FLAC__BitReader;
  81555. typedef struct FLAC__BitReader FLAC__BitReader;
  81556. typedef FLAC__bool (*FLAC__BitReaderReadCallback)(FLAC__byte buffer[], size_t *bytes, void *client_data);
  81557. FLAC__BitReader *FLAC__bitreader_new(void);
  81558. void FLAC__bitreader_delete(FLAC__BitReader *br);
  81559. FLAC__bool FLAC__bitreader_init(FLAC__BitReader *br, FLAC__CPUInfo cpu, FLAC__BitReaderReadCallback rcb, void *cd);
  81560. void FLAC__bitreader_free(FLAC__BitReader *br); /* does not 'free(br)' */
  81561. FLAC__bool FLAC__bitreader_clear(FLAC__BitReader *br);
  81562. void FLAC__bitreader_dump(const FLAC__BitReader *br, FILE *out);
  81563. void FLAC__bitreader_reset_read_crc16(FLAC__BitReader *br, FLAC__uint16 seed);
  81564. FLAC__uint16 FLAC__bitreader_get_read_crc16(FLAC__BitReader *br);
  81565. FLAC__bool FLAC__bitreader_is_consumed_byte_aligned(const FLAC__BitReader *br);
  81566. unsigned FLAC__bitreader_bits_left_for_byte_alignment(const FLAC__BitReader *br);
  81567. unsigned FLAC__bitreader_get_input_bits_unconsumed(const FLAC__BitReader *br);
  81568. FLAC__bool FLAC__bitreader_read_raw_uint32(FLAC__BitReader *br, FLAC__uint32 *val, unsigned bits);
  81569. FLAC__bool FLAC__bitreader_read_raw_int32(FLAC__BitReader *br, FLAC__int32 *val, unsigned bits);
  81570. FLAC__bool FLAC__bitreader_read_raw_uint64(FLAC__BitReader *br, FLAC__uint64 *val, unsigned bits);
  81571. FLAC__bool FLAC__bitreader_read_uint32_little_endian(FLAC__BitReader *br, FLAC__uint32 *val); /*only for bits=32*/
  81572. FLAC__bool FLAC__bitreader_skip_bits_no_crc(FLAC__BitReader *br, unsigned bits); /* WATCHOUT: does not CRC the skipped data! */ /*@@@@ add to unit tests */
  81573. FLAC__bool FLAC__bitreader_skip_byte_block_aligned_no_crc(FLAC__BitReader *br, unsigned nvals); /* WATCHOUT: does not CRC the read data! */
  81574. 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! */
  81575. FLAC__bool FLAC__bitreader_read_unary_unsigned(FLAC__BitReader *br, unsigned *val);
  81576. FLAC__bool FLAC__bitreader_read_rice_signed(FLAC__BitReader *br, int *val, unsigned parameter);
  81577. FLAC__bool FLAC__bitreader_read_rice_signed_block(FLAC__BitReader *br, int vals[], unsigned nvals, unsigned parameter);
  81578. #ifndef FLAC__NO_ASM
  81579. # ifdef FLAC__CPU_IA32
  81580. # ifdef FLAC__HAS_NASM
  81581. FLAC__bool FLAC__bitreader_read_rice_signed_block_asm_ia32_bswap(FLAC__BitReader *br, int vals[], unsigned nvals, unsigned parameter);
  81582. # endif
  81583. # endif
  81584. #endif
  81585. #if 0 /* UNUSED */
  81586. FLAC__bool FLAC__bitreader_read_golomb_signed(FLAC__BitReader *br, int *val, unsigned parameter);
  81587. FLAC__bool FLAC__bitreader_read_golomb_unsigned(FLAC__BitReader *br, unsigned *val, unsigned parameter);
  81588. #endif
  81589. FLAC__bool FLAC__bitreader_read_utf8_uint32(FLAC__BitReader *br, FLAC__uint32 *val, FLAC__byte *raw, unsigned *rawlen);
  81590. FLAC__bool FLAC__bitreader_read_utf8_uint64(FLAC__BitReader *br, FLAC__uint64 *val, FLAC__byte *raw, unsigned *rawlen);
  81591. FLAC__bool bitreader_read_from_client_(FLAC__BitReader *br);
  81592. #endif
  81593. /*** End of inlined file: bitreader.h ***/
  81594. /*** Start of inlined file: crc.h ***/
  81595. #ifndef FLAC__PRIVATE__CRC_H
  81596. #define FLAC__PRIVATE__CRC_H
  81597. extern FLAC__byte const FLAC__crc8_table[256];
  81598. #define FLAC__CRC8_UPDATE(data, crc) (crc) = FLAC__crc8_table[(crc) ^ (data)];
  81599. void FLAC__crc8_update(const FLAC__byte data, FLAC__uint8 *crc);
  81600. void FLAC__crc8_update_block(const FLAC__byte *data, unsigned len, FLAC__uint8 *crc);
  81601. FLAC__uint8 FLAC__crc8(const FLAC__byte *data, unsigned len);
  81602. extern unsigned FLAC__crc16_table[256];
  81603. #define FLAC__CRC16_UPDATE(data, crc) (((((crc)<<8) & 0xffff) ^ FLAC__crc16_table[((crc)>>8) ^ (data)]))
  81604. #if 0
  81605. #define FLAC__CRC16_UPDATE(data, crc) ((((crc)<<8) ^ FLAC__crc16_table[((crc)>>8) ^ (data)]) & 0xffff)
  81606. #endif
  81607. unsigned FLAC__crc16(const FLAC__byte *data, unsigned len);
  81608. #endif
  81609. /*** End of inlined file: crc.h ***/
  81610. typedef FLAC__uint32 brword;
  81611. #define FLAC__BYTES_PER_WORD 4
  81612. #define FLAC__BITS_PER_WORD 32
  81613. #define FLAC__WORD_ALL_ONES ((FLAC__uint32)0xffffffff)
  81614. #if WORDS_BIGENDIAN
  81615. #define SWAP_BE_WORD_TO_HOST(x) (x)
  81616. #else
  81617. #if defined (_MSC_VER) && defined (_X86_)
  81618. #define SWAP_BE_WORD_TO_HOST(x) local_swap32_(x)
  81619. #else
  81620. #define SWAP_BE_WORD_TO_HOST(x) ntohl(x)
  81621. #endif
  81622. #endif
  81623. #define COUNT_ZERO_MSBS(word) ( \
  81624. (word) <= 0xffff ? \
  81625. ( (word) <= 0xff? byte_to_unary_table[word] + 24 : byte_to_unary_table[(word) >> 8] + 16 ) : \
  81626. ( (word) <= 0xffffff? byte_to_unary_table[word >> 16] + 8 : byte_to_unary_table[(word) >> 24] ) \
  81627. )
  81628. #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])) )
  81629. static const unsigned FLAC__BITREADER_DEFAULT_CAPACITY = 65536u / FLAC__BITS_PER_WORD; /* in words */
  81630. static const unsigned char byte_to_unary_table[] = {
  81631. 8, 7, 6, 6, 5, 5, 5, 5, 4, 4, 4, 4, 4, 4, 4, 4,
  81632. 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
  81633. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  81634. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  81635. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  81636. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  81637. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  81638. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  81639. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  81640. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  81641. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  81642. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  81643. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  81644. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  81645. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  81646. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
  81647. };
  81648. #ifdef min
  81649. #undef min
  81650. #endif
  81651. #define min(x,y) ((x)<(y)?(x):(y))
  81652. #ifdef max
  81653. #undef max
  81654. #endif
  81655. #define max(x,y) ((x)>(y)?(x):(y))
  81656. #ifdef _MSC_VER
  81657. #define FLAC__U64L(x) x
  81658. #else
  81659. #define FLAC__U64L(x) x##LLU
  81660. #endif
  81661. #ifndef FLaC__INLINE
  81662. #define FLaC__INLINE
  81663. #endif
  81664. struct FLAC__BitReader {
  81665. brword *buffer;
  81666. unsigned capacity; /* in words */
  81667. unsigned words; /* # of completed words in buffer */
  81668. unsigned bytes; /* # of bytes in incomplete word at buffer[words] */
  81669. unsigned consumed_words; /* #words ... */
  81670. unsigned consumed_bits; /* ... + (#bits of head word) already consumed from the front of buffer */
  81671. unsigned read_crc16; /* the running frame CRC */
  81672. unsigned crc16_align; /* the number of bits in the current consumed word that should not be CRC'd */
  81673. FLAC__BitReaderReadCallback read_callback;
  81674. void *client_data;
  81675. FLAC__CPUInfo cpu_info;
  81676. };
  81677. static FLaC__INLINE void crc16_update_word_(FLAC__BitReader *br, brword word)
  81678. {
  81679. register unsigned crc = br->read_crc16;
  81680. #if FLAC__BYTES_PER_WORD == 4
  81681. switch(br->crc16_align) {
  81682. case 0: crc = FLAC__CRC16_UPDATE((unsigned)(word >> 24), crc);
  81683. case 8: crc = FLAC__CRC16_UPDATE((unsigned)((word >> 16) & 0xff), crc);
  81684. case 16: crc = FLAC__CRC16_UPDATE((unsigned)((word >> 8) & 0xff), crc);
  81685. case 24: br->read_crc16 = FLAC__CRC16_UPDATE((unsigned)(word & 0xff), crc);
  81686. }
  81687. #elif FLAC__BYTES_PER_WORD == 8
  81688. switch(br->crc16_align) {
  81689. case 0: crc = FLAC__CRC16_UPDATE((unsigned)(word >> 56), crc);
  81690. case 8: crc = FLAC__CRC16_UPDATE((unsigned)((word >> 48) & 0xff), crc);
  81691. case 16: crc = FLAC__CRC16_UPDATE((unsigned)((word >> 40) & 0xff), crc);
  81692. case 24: crc = FLAC__CRC16_UPDATE((unsigned)((word >> 32) & 0xff), crc);
  81693. case 32: crc = FLAC__CRC16_UPDATE((unsigned)((word >> 24) & 0xff), crc);
  81694. case 40: crc = FLAC__CRC16_UPDATE((unsigned)((word >> 16) & 0xff), crc);
  81695. case 48: crc = FLAC__CRC16_UPDATE((unsigned)((word >> 8) & 0xff), crc);
  81696. case 56: br->read_crc16 = FLAC__CRC16_UPDATE((unsigned)(word & 0xff), crc);
  81697. }
  81698. #else
  81699. for( ; br->crc16_align < FLAC__BITS_PER_WORD; br->crc16_align += 8)
  81700. crc = FLAC__CRC16_UPDATE((unsigned)((word >> (FLAC__BITS_PER_WORD-8-br->crc16_align)) & 0xff), crc);
  81701. br->read_crc16 = crc;
  81702. #endif
  81703. br->crc16_align = 0;
  81704. }
  81705. FLAC__bool bitreader_read_from_client_(FLAC__BitReader *br)
  81706. {
  81707. unsigned start, end;
  81708. size_t bytes;
  81709. FLAC__byte *target;
  81710. if(br->consumed_words > 0) {
  81711. start = br->consumed_words;
  81712. end = br->words + (br->bytes? 1:0);
  81713. memmove(br->buffer, br->buffer+start, FLAC__BYTES_PER_WORD * (end - start));
  81714. br->words -= start;
  81715. br->consumed_words = 0;
  81716. }
  81717. bytes = (br->capacity - br->words) * FLAC__BYTES_PER_WORD - br->bytes;
  81718. if(bytes == 0)
  81719. return false; /* no space left, buffer is too small; see note for FLAC__BITREADER_DEFAULT_CAPACITY */
  81720. target = ((FLAC__byte*)(br->buffer+br->words)) + br->bytes;
  81721. #if WORDS_BIGENDIAN
  81722. #else
  81723. if(br->bytes)
  81724. br->buffer[br->words] = SWAP_BE_WORD_TO_HOST(br->buffer[br->words]);
  81725. #endif
  81726. if(!br->read_callback(target, &bytes, br->client_data))
  81727. return false;
  81728. #if WORDS_BIGENDIAN
  81729. #else
  81730. end = (br->words*FLAC__BYTES_PER_WORD + br->bytes + bytes + (FLAC__BYTES_PER_WORD-1)) / FLAC__BYTES_PER_WORD;
  81731. # if defined(_MSC_VER) && defined (_X86_) && (FLAC__BYTES_PER_WORD == 4)
  81732. if(br->cpu_info.type == FLAC__CPUINFO_TYPE_IA32 && br->cpu_info.data.ia32.bswap) {
  81733. start = br->words;
  81734. local_swap32_block_(br->buffer + start, end - start);
  81735. }
  81736. else
  81737. # endif
  81738. for(start = br->words; start < end; start++)
  81739. br->buffer[start] = SWAP_BE_WORD_TO_HOST(br->buffer[start]);
  81740. #endif
  81741. end = br->words*FLAC__BYTES_PER_WORD + br->bytes + bytes;
  81742. br->words = end / FLAC__BYTES_PER_WORD;
  81743. br->bytes = end % FLAC__BYTES_PER_WORD;
  81744. return true;
  81745. }
  81746. FLAC__BitReader *FLAC__bitreader_new(void)
  81747. {
  81748. FLAC__BitReader *br = (FLAC__BitReader*)calloc(1, sizeof(FLAC__BitReader));
  81749. return br;
  81750. }
  81751. void FLAC__bitreader_delete(FLAC__BitReader *br)
  81752. {
  81753. FLAC__ASSERT(0 != br);
  81754. FLAC__bitreader_free(br);
  81755. free(br);
  81756. }
  81757. FLAC__bool FLAC__bitreader_init(FLAC__BitReader *br, FLAC__CPUInfo cpu, FLAC__BitReaderReadCallback rcb, void *cd)
  81758. {
  81759. FLAC__ASSERT(0 != br);
  81760. br->words = br->bytes = 0;
  81761. br->consumed_words = br->consumed_bits = 0;
  81762. br->capacity = FLAC__BITREADER_DEFAULT_CAPACITY;
  81763. br->buffer = (brword*)malloc(sizeof(brword) * br->capacity);
  81764. if(br->buffer == 0)
  81765. return false;
  81766. br->read_callback = rcb;
  81767. br->client_data = cd;
  81768. br->cpu_info = cpu;
  81769. return true;
  81770. }
  81771. void FLAC__bitreader_free(FLAC__BitReader *br)
  81772. {
  81773. FLAC__ASSERT(0 != br);
  81774. if(0 != br->buffer)
  81775. free(br->buffer);
  81776. br->buffer = 0;
  81777. br->capacity = 0;
  81778. br->words = br->bytes = 0;
  81779. br->consumed_words = br->consumed_bits = 0;
  81780. br->read_callback = 0;
  81781. br->client_data = 0;
  81782. }
  81783. FLAC__bool FLAC__bitreader_clear(FLAC__BitReader *br)
  81784. {
  81785. br->words = br->bytes = 0;
  81786. br->consumed_words = br->consumed_bits = 0;
  81787. return true;
  81788. }
  81789. void FLAC__bitreader_dump(const FLAC__BitReader *br, FILE *out)
  81790. {
  81791. unsigned i, j;
  81792. if(br == 0) {
  81793. fprintf(out, "bitreader is NULL\n");
  81794. }
  81795. else {
  81796. 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);
  81797. for(i = 0; i < br->words; i++) {
  81798. fprintf(out, "%08X: ", i);
  81799. for(j = 0; j < FLAC__BITS_PER_WORD; j++)
  81800. if(i < br->consumed_words || (i == br->consumed_words && j < br->consumed_bits))
  81801. fprintf(out, ".");
  81802. else
  81803. fprintf(out, "%01u", br->buffer[i] & (1 << (FLAC__BITS_PER_WORD-j-1)) ? 1:0);
  81804. fprintf(out, "\n");
  81805. }
  81806. if(br->bytes > 0) {
  81807. fprintf(out, "%08X: ", i);
  81808. for(j = 0; j < br->bytes*8; j++)
  81809. if(i < br->consumed_words || (i == br->consumed_words && j < br->consumed_bits))
  81810. fprintf(out, ".");
  81811. else
  81812. fprintf(out, "%01u", br->buffer[i] & (1 << (br->bytes*8-j-1)) ? 1:0);
  81813. fprintf(out, "\n");
  81814. }
  81815. }
  81816. }
  81817. void FLAC__bitreader_reset_read_crc16(FLAC__BitReader *br, FLAC__uint16 seed)
  81818. {
  81819. FLAC__ASSERT(0 != br);
  81820. FLAC__ASSERT(0 != br->buffer);
  81821. FLAC__ASSERT((br->consumed_bits & 7) == 0);
  81822. br->read_crc16 = (unsigned)seed;
  81823. br->crc16_align = br->consumed_bits;
  81824. }
  81825. FLAC__uint16 FLAC__bitreader_get_read_crc16(FLAC__BitReader *br)
  81826. {
  81827. FLAC__ASSERT(0 != br);
  81828. FLAC__ASSERT(0 != br->buffer);
  81829. FLAC__ASSERT((br->consumed_bits & 7) == 0);
  81830. FLAC__ASSERT(br->crc16_align <= br->consumed_bits);
  81831. if(br->consumed_bits) {
  81832. const brword tail = br->buffer[br->consumed_words];
  81833. for( ; br->crc16_align < br->consumed_bits; br->crc16_align += 8)
  81834. br->read_crc16 = FLAC__CRC16_UPDATE((unsigned)((tail >> (FLAC__BITS_PER_WORD-8-br->crc16_align)) & 0xff), br->read_crc16);
  81835. }
  81836. return br->read_crc16;
  81837. }
  81838. FLaC__INLINE FLAC__bool FLAC__bitreader_is_consumed_byte_aligned(const FLAC__BitReader *br)
  81839. {
  81840. return ((br->consumed_bits & 7) == 0);
  81841. }
  81842. FLaC__INLINE unsigned FLAC__bitreader_bits_left_for_byte_alignment(const FLAC__BitReader *br)
  81843. {
  81844. return 8 - (br->consumed_bits & 7);
  81845. }
  81846. FLaC__INLINE unsigned FLAC__bitreader_get_input_bits_unconsumed(const FLAC__BitReader *br)
  81847. {
  81848. return (br->words-br->consumed_words)*FLAC__BITS_PER_WORD + br->bytes*8 - br->consumed_bits;
  81849. }
  81850. FLaC__INLINE FLAC__bool FLAC__bitreader_read_raw_uint32(FLAC__BitReader *br, FLAC__uint32 *val, unsigned bits)
  81851. {
  81852. FLAC__ASSERT(0 != br);
  81853. FLAC__ASSERT(0 != br->buffer);
  81854. FLAC__ASSERT(bits <= 32);
  81855. FLAC__ASSERT((br->capacity*FLAC__BITS_PER_WORD) * 2 >= bits);
  81856. FLAC__ASSERT(br->consumed_words <= br->words);
  81857. FLAC__ASSERT(FLAC__BITS_PER_WORD >= 32);
  81858. if(bits == 0) { /* OPT: investigate if this can ever happen, maybe change to assertion */
  81859. *val = 0;
  81860. return true;
  81861. }
  81862. while((br->words-br->consumed_words)*FLAC__BITS_PER_WORD + br->bytes*8 - br->consumed_bits < bits) {
  81863. if(!bitreader_read_from_client_(br))
  81864. return false;
  81865. }
  81866. if(br->consumed_words < br->words) { /* if we've not consumed up to a partial tail word... */
  81867. if(br->consumed_bits) {
  81868. const unsigned n = FLAC__BITS_PER_WORD - br->consumed_bits;
  81869. const brword word = br->buffer[br->consumed_words];
  81870. if(bits < n) {
  81871. *val = (word & (FLAC__WORD_ALL_ONES >> br->consumed_bits)) >> (n-bits);
  81872. br->consumed_bits += bits;
  81873. return true;
  81874. }
  81875. *val = word & (FLAC__WORD_ALL_ONES >> br->consumed_bits);
  81876. bits -= n;
  81877. crc16_update_word_(br, word);
  81878. br->consumed_words++;
  81879. br->consumed_bits = 0;
  81880. 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 */
  81881. *val <<= bits;
  81882. *val |= (br->buffer[br->consumed_words] >> (FLAC__BITS_PER_WORD-bits));
  81883. br->consumed_bits = bits;
  81884. }
  81885. return true;
  81886. }
  81887. else {
  81888. const brword word = br->buffer[br->consumed_words];
  81889. if(bits < FLAC__BITS_PER_WORD) {
  81890. *val = word >> (FLAC__BITS_PER_WORD-bits);
  81891. br->consumed_bits = bits;
  81892. return true;
  81893. }
  81894. *val = word;
  81895. crc16_update_word_(br, word);
  81896. br->consumed_words++;
  81897. return true;
  81898. }
  81899. }
  81900. else {
  81901. if(br->consumed_bits) {
  81902. FLAC__ASSERT(br->consumed_bits + bits <= br->bytes*8);
  81903. *val = (br->buffer[br->consumed_words] & (FLAC__WORD_ALL_ONES >> br->consumed_bits)) >> (FLAC__BITS_PER_WORD-br->consumed_bits-bits);
  81904. br->consumed_bits += bits;
  81905. return true;
  81906. }
  81907. else {
  81908. *val = br->buffer[br->consumed_words] >> (FLAC__BITS_PER_WORD-bits);
  81909. br->consumed_bits += bits;
  81910. return true;
  81911. }
  81912. }
  81913. }
  81914. FLAC__bool FLAC__bitreader_read_raw_int32(FLAC__BitReader *br, FLAC__int32 *val, unsigned bits)
  81915. {
  81916. if(!FLAC__bitreader_read_raw_uint32(br, (FLAC__uint32*)val, bits))
  81917. return false;
  81918. *val <<= (32-bits);
  81919. *val >>= (32-bits);
  81920. return true;
  81921. }
  81922. FLAC__bool FLAC__bitreader_read_raw_uint64(FLAC__BitReader *br, FLAC__uint64 *val, unsigned bits)
  81923. {
  81924. FLAC__uint32 hi, lo;
  81925. if(bits > 32) {
  81926. if(!FLAC__bitreader_read_raw_uint32(br, &hi, bits-32))
  81927. return false;
  81928. if(!FLAC__bitreader_read_raw_uint32(br, &lo, 32))
  81929. return false;
  81930. *val = hi;
  81931. *val <<= 32;
  81932. *val |= lo;
  81933. }
  81934. else {
  81935. if(!FLAC__bitreader_read_raw_uint32(br, &lo, bits))
  81936. return false;
  81937. *val = lo;
  81938. }
  81939. return true;
  81940. }
  81941. FLaC__INLINE FLAC__bool FLAC__bitreader_read_uint32_little_endian(FLAC__BitReader *br, FLAC__uint32 *val)
  81942. {
  81943. FLAC__uint32 x8, x32 = 0;
  81944. if(!FLAC__bitreader_read_raw_uint32(br, &x32, 8))
  81945. return false;
  81946. if(!FLAC__bitreader_read_raw_uint32(br, &x8, 8))
  81947. return false;
  81948. x32 |= (x8 << 8);
  81949. if(!FLAC__bitreader_read_raw_uint32(br, &x8, 8))
  81950. return false;
  81951. x32 |= (x8 << 16);
  81952. if(!FLAC__bitreader_read_raw_uint32(br, &x8, 8))
  81953. return false;
  81954. x32 |= (x8 << 24);
  81955. *val = x32;
  81956. return true;
  81957. }
  81958. FLAC__bool FLAC__bitreader_skip_bits_no_crc(FLAC__BitReader *br, unsigned bits)
  81959. {
  81960. FLAC__ASSERT(0 != br);
  81961. FLAC__ASSERT(0 != br->buffer);
  81962. if(bits > 0) {
  81963. const unsigned n = br->consumed_bits & 7;
  81964. unsigned m;
  81965. FLAC__uint32 x;
  81966. if(n != 0) {
  81967. m = min(8-n, bits);
  81968. if(!FLAC__bitreader_read_raw_uint32(br, &x, m))
  81969. return false;
  81970. bits -= m;
  81971. }
  81972. m = bits / 8;
  81973. if(m > 0) {
  81974. if(!FLAC__bitreader_skip_byte_block_aligned_no_crc(br, m))
  81975. return false;
  81976. bits %= 8;
  81977. }
  81978. if(bits > 0) {
  81979. if(!FLAC__bitreader_read_raw_uint32(br, &x, bits))
  81980. return false;
  81981. }
  81982. }
  81983. return true;
  81984. }
  81985. FLAC__bool FLAC__bitreader_skip_byte_block_aligned_no_crc(FLAC__BitReader *br, unsigned nvals)
  81986. {
  81987. FLAC__uint32 x;
  81988. FLAC__ASSERT(0 != br);
  81989. FLAC__ASSERT(0 != br->buffer);
  81990. FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(br));
  81991. while(nvals && br->consumed_bits) { /* i.e. run until we read 'nvals' bytes or we hit the end of the head word */
  81992. if(!FLAC__bitreader_read_raw_uint32(br, &x, 8))
  81993. return false;
  81994. nvals--;
  81995. }
  81996. if(0 == nvals)
  81997. return true;
  81998. while(nvals >= FLAC__BYTES_PER_WORD) {
  81999. if(br->consumed_words < br->words) {
  82000. br->consumed_words++;
  82001. nvals -= FLAC__BYTES_PER_WORD;
  82002. }
  82003. else if(!bitreader_read_from_client_(br))
  82004. return false;
  82005. }
  82006. while(nvals) {
  82007. if(!FLAC__bitreader_read_raw_uint32(br, &x, 8))
  82008. return false;
  82009. nvals--;
  82010. }
  82011. return true;
  82012. }
  82013. FLAC__bool FLAC__bitreader_read_byte_block_aligned_no_crc(FLAC__BitReader *br, FLAC__byte *val, unsigned nvals)
  82014. {
  82015. FLAC__uint32 x;
  82016. FLAC__ASSERT(0 != br);
  82017. FLAC__ASSERT(0 != br->buffer);
  82018. FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(br));
  82019. while(nvals && br->consumed_bits) { /* i.e. run until we read 'nvals' bytes or we hit the end of the head word */
  82020. if(!FLAC__bitreader_read_raw_uint32(br, &x, 8))
  82021. return false;
  82022. *val++ = (FLAC__byte)x;
  82023. nvals--;
  82024. }
  82025. if(0 == nvals)
  82026. return true;
  82027. while(nvals >= FLAC__BYTES_PER_WORD) {
  82028. if(br->consumed_words < br->words) {
  82029. const brword word = br->buffer[br->consumed_words++];
  82030. #if FLAC__BYTES_PER_WORD == 4
  82031. val[0] = (FLAC__byte)(word >> 24);
  82032. val[1] = (FLAC__byte)(word >> 16);
  82033. val[2] = (FLAC__byte)(word >> 8);
  82034. val[3] = (FLAC__byte)word;
  82035. #elif FLAC__BYTES_PER_WORD == 8
  82036. val[0] = (FLAC__byte)(word >> 56);
  82037. val[1] = (FLAC__byte)(word >> 48);
  82038. val[2] = (FLAC__byte)(word >> 40);
  82039. val[3] = (FLAC__byte)(word >> 32);
  82040. val[4] = (FLAC__byte)(word >> 24);
  82041. val[5] = (FLAC__byte)(word >> 16);
  82042. val[6] = (FLAC__byte)(word >> 8);
  82043. val[7] = (FLAC__byte)word;
  82044. #else
  82045. for(x = 0; x < FLAC__BYTES_PER_WORD; x++)
  82046. val[x] = (FLAC__byte)(word >> (8*(FLAC__BYTES_PER_WORD-x-1)));
  82047. #endif
  82048. val += FLAC__BYTES_PER_WORD;
  82049. nvals -= FLAC__BYTES_PER_WORD;
  82050. }
  82051. else if(!bitreader_read_from_client_(br))
  82052. return false;
  82053. }
  82054. while(nvals) {
  82055. if(!FLAC__bitreader_read_raw_uint32(br, &x, 8))
  82056. return false;
  82057. *val++ = (FLAC__byte)x;
  82058. nvals--;
  82059. }
  82060. return true;
  82061. }
  82062. FLaC__INLINE FLAC__bool FLAC__bitreader_read_unary_unsigned(FLAC__BitReader *br, unsigned *val)
  82063. #if 0 /* slow but readable version */
  82064. {
  82065. unsigned bit;
  82066. FLAC__ASSERT(0 != br);
  82067. FLAC__ASSERT(0 != br->buffer);
  82068. *val = 0;
  82069. while(1) {
  82070. if(!FLAC__bitreader_read_bit(br, &bit))
  82071. return false;
  82072. if(bit)
  82073. break;
  82074. else
  82075. *val++;
  82076. }
  82077. return true;
  82078. }
  82079. #else
  82080. {
  82081. unsigned i;
  82082. FLAC__ASSERT(0 != br);
  82083. FLAC__ASSERT(0 != br->buffer);
  82084. *val = 0;
  82085. while(1) {
  82086. while(br->consumed_words < br->words) { /* if we've not consumed up to a partial tail word... */
  82087. brword b = br->buffer[br->consumed_words] << br->consumed_bits;
  82088. if(b) {
  82089. i = COUNT_ZERO_MSBS(b);
  82090. *val += i;
  82091. i++;
  82092. br->consumed_bits += i;
  82093. if(br->consumed_bits >= FLAC__BITS_PER_WORD) { /* faster way of testing if(br->consumed_bits == FLAC__BITS_PER_WORD) */
  82094. crc16_update_word_(br, br->buffer[br->consumed_words]);
  82095. br->consumed_words++;
  82096. br->consumed_bits = 0;
  82097. }
  82098. return true;
  82099. }
  82100. else {
  82101. *val += FLAC__BITS_PER_WORD - br->consumed_bits;
  82102. crc16_update_word_(br, br->buffer[br->consumed_words]);
  82103. br->consumed_words++;
  82104. br->consumed_bits = 0;
  82105. }
  82106. }
  82107. if(br->bytes) {
  82108. const unsigned end = br->bytes * 8;
  82109. brword b = (br->buffer[br->consumed_words] & (FLAC__WORD_ALL_ONES << (FLAC__BITS_PER_WORD-end))) << br->consumed_bits;
  82110. if(b) {
  82111. i = COUNT_ZERO_MSBS(b);
  82112. *val += i;
  82113. i++;
  82114. br->consumed_bits += i;
  82115. FLAC__ASSERT(br->consumed_bits < FLAC__BITS_PER_WORD);
  82116. return true;
  82117. }
  82118. else {
  82119. *val += end - br->consumed_bits;
  82120. br->consumed_bits += end;
  82121. FLAC__ASSERT(br->consumed_bits < FLAC__BITS_PER_WORD);
  82122. }
  82123. }
  82124. if(!bitreader_read_from_client_(br))
  82125. return false;
  82126. }
  82127. }
  82128. #endif
  82129. FLAC__bool FLAC__bitreader_read_rice_signed(FLAC__BitReader *br, int *val, unsigned parameter)
  82130. {
  82131. FLAC__uint32 lsbs = 0, msbs = 0;
  82132. unsigned uval;
  82133. FLAC__ASSERT(0 != br);
  82134. FLAC__ASSERT(0 != br->buffer);
  82135. FLAC__ASSERT(parameter <= 31);
  82136. if(!FLAC__bitreader_read_unary_unsigned(br, (unsigned int*) &msbs))
  82137. return false;
  82138. if(!FLAC__bitreader_read_raw_uint32(br, &lsbs, parameter))
  82139. return false;
  82140. uval = (msbs << parameter) | lsbs;
  82141. if(uval & 1)
  82142. *val = -((int)(uval >> 1)) - 1;
  82143. else
  82144. *val = (int)(uval >> 1);
  82145. return true;
  82146. }
  82147. FLAC__bool FLAC__bitreader_read_rice_signed_block(FLAC__BitReader *br, int vals[], unsigned nvals, unsigned parameter)
  82148. #ifdef _MSC_VER
  82149. {
  82150. unsigned i;
  82151. unsigned uval = 0;
  82152. unsigned bits; /* the # of binary LSBs left to read to finish a rice codeword */
  82153. register unsigned cwords;
  82154. register unsigned cbits;
  82155. FLAC__ASSERT(0 != br);
  82156. FLAC__ASSERT(0 != br->buffer);
  82157. FLAC__ASSERT(FLAC__BITS_PER_WORD >= 32);
  82158. FLAC__ASSERT(parameter < 32);
  82159. if(nvals == 0)
  82160. return true;
  82161. cbits = br->consumed_bits;
  82162. cwords = br->consumed_words;
  82163. while(1) {
  82164. while(1) {
  82165. while(cwords < br->words) { /* if we've not consumed up to a partial tail word... */
  82166. brword b = br->buffer[cwords] << cbits;
  82167. if(b) {
  82168. #if 0 /* slower, probably due to bad register allocation... */ && defined FLAC__CPU_IA32 && !defined FLAC__NO_ASM && FLAC__BITS_PER_WORD == 32
  82169. __asm {
  82170. bsr eax, b
  82171. not eax
  82172. and eax, 31
  82173. mov i, eax
  82174. }
  82175. #else
  82176. i = COUNT_ZERO_MSBS(b);
  82177. #endif
  82178. uval += i;
  82179. bits = parameter;
  82180. i++;
  82181. cbits += i;
  82182. if(cbits == FLAC__BITS_PER_WORD) {
  82183. crc16_update_word_(br, br->buffer[cwords]);
  82184. cwords++;
  82185. cbits = 0;
  82186. }
  82187. goto break1;
  82188. }
  82189. else {
  82190. uval += FLAC__BITS_PER_WORD - cbits;
  82191. crc16_update_word_(br, br->buffer[cwords]);
  82192. cwords++;
  82193. cbits = 0;
  82194. }
  82195. }
  82196. if(br->bytes) {
  82197. const unsigned end = br->bytes * 8;
  82198. brword b = (br->buffer[cwords] & (FLAC__WORD_ALL_ONES << (FLAC__BITS_PER_WORD-end))) << cbits;
  82199. if(b) {
  82200. i = COUNT_ZERO_MSBS(b);
  82201. uval += i;
  82202. bits = parameter;
  82203. i++;
  82204. cbits += i;
  82205. FLAC__ASSERT(cbits < FLAC__BITS_PER_WORD);
  82206. goto break1;
  82207. }
  82208. else {
  82209. uval += end - cbits;
  82210. cbits += end;
  82211. FLAC__ASSERT(cbits < FLAC__BITS_PER_WORD);
  82212. }
  82213. }
  82214. br->consumed_bits = cbits;
  82215. br->consumed_words = cwords;
  82216. if(!bitreader_read_from_client_(br))
  82217. return false;
  82218. cwords = br->consumed_words;
  82219. }
  82220. break1:
  82221. FLAC__ASSERT(cwords <= br->words);
  82222. if(bits) {
  82223. while((br->words-cwords)*FLAC__BITS_PER_WORD + br->bytes*8 - cbits < bits) {
  82224. br->consumed_bits = cbits;
  82225. br->consumed_words = cwords;
  82226. if(!bitreader_read_from_client_(br))
  82227. return false;
  82228. cwords = br->consumed_words;
  82229. }
  82230. if(cwords < br->words) { /* if we've not consumed up to a partial tail word... */
  82231. if(cbits) {
  82232. const unsigned n = FLAC__BITS_PER_WORD - cbits;
  82233. const brword word = br->buffer[cwords];
  82234. if(bits < n) {
  82235. uval <<= bits;
  82236. uval |= (word & (FLAC__WORD_ALL_ONES >> cbits)) >> (n-bits);
  82237. cbits += bits;
  82238. goto break2;
  82239. }
  82240. uval <<= n;
  82241. uval |= word & (FLAC__WORD_ALL_ONES >> cbits);
  82242. bits -= n;
  82243. crc16_update_word_(br, word);
  82244. cwords++;
  82245. cbits = 0;
  82246. 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 */
  82247. uval <<= bits;
  82248. uval |= (br->buffer[cwords] >> (FLAC__BITS_PER_WORD-bits));
  82249. cbits = bits;
  82250. }
  82251. goto break2;
  82252. }
  82253. else {
  82254. FLAC__ASSERT(bits < FLAC__BITS_PER_WORD);
  82255. uval <<= bits;
  82256. uval |= br->buffer[cwords] >> (FLAC__BITS_PER_WORD-bits);
  82257. cbits = bits;
  82258. goto break2;
  82259. }
  82260. }
  82261. else {
  82262. uval <<= bits;
  82263. if(cbits) {
  82264. FLAC__ASSERT(cbits + bits <= br->bytes*8);
  82265. uval |= (br->buffer[cwords] & (FLAC__WORD_ALL_ONES >> cbits)) >> (FLAC__BITS_PER_WORD-cbits-bits);
  82266. cbits += bits;
  82267. goto break2;
  82268. }
  82269. else {
  82270. uval |= br->buffer[cwords] >> (FLAC__BITS_PER_WORD-bits);
  82271. cbits += bits;
  82272. goto break2;
  82273. }
  82274. }
  82275. }
  82276. break2:
  82277. *vals = (int)(uval >> 1 ^ -(int)(uval & 1));
  82278. --nvals;
  82279. if(nvals == 0) {
  82280. br->consumed_bits = cbits;
  82281. br->consumed_words = cwords;
  82282. return true;
  82283. }
  82284. uval = 0;
  82285. ++vals;
  82286. }
  82287. }
  82288. #else
  82289. {
  82290. unsigned i;
  82291. unsigned uval = 0;
  82292. register unsigned cwords;
  82293. register unsigned cbits;
  82294. unsigned ucbits; /* keep track of the number of unconsumed bits in the buffer */
  82295. FLAC__ASSERT(0 != br);
  82296. FLAC__ASSERT(0 != br->buffer);
  82297. FLAC__ASSERT(FLAC__BITS_PER_WORD >= 32);
  82298. FLAC__ASSERT(parameter < 32);
  82299. if(nvals == 0)
  82300. return true;
  82301. cbits = br->consumed_bits;
  82302. cwords = br->consumed_words;
  82303. ucbits = (br->words-cwords)*FLAC__BITS_PER_WORD + br->bytes*8 - cbits;
  82304. while(1) {
  82305. while(1) {
  82306. while(cwords < br->words) { /* if we've not consumed up to a partial tail word... */
  82307. brword b = br->buffer[cwords] << cbits;
  82308. if(b) {
  82309. #if 0 /* is not discernably faster... */ && defined FLAC__CPU_IA32 && !defined FLAC__NO_ASM && FLAC__BITS_PER_WORD == 32 && defined __GNUC__
  82310. asm volatile (
  82311. "bsrl %1, %0;"
  82312. "notl %0;"
  82313. "andl $31, %0;"
  82314. : "=r"(i)
  82315. : "r"(b)
  82316. );
  82317. #else
  82318. i = COUNT_ZERO_MSBS(b);
  82319. #endif
  82320. uval += i;
  82321. cbits += i;
  82322. cbits++; /* skip over stop bit */
  82323. if(cbits >= FLAC__BITS_PER_WORD) { /* faster way of testing if(cbits == FLAC__BITS_PER_WORD) */
  82324. crc16_update_word_(br, br->buffer[cwords]);
  82325. cwords++;
  82326. cbits = 0;
  82327. }
  82328. goto break1;
  82329. }
  82330. else {
  82331. uval += FLAC__BITS_PER_WORD - cbits;
  82332. crc16_update_word_(br, br->buffer[cwords]);
  82333. cwords++;
  82334. cbits = 0;
  82335. }
  82336. }
  82337. if(br->bytes) {
  82338. const unsigned end = br->bytes * 8;
  82339. brword b = (br->buffer[cwords] & ~(FLAC__WORD_ALL_ONES >> end)) << cbits;
  82340. if(b) {
  82341. i = COUNT_ZERO_MSBS(b);
  82342. uval += i;
  82343. cbits += i;
  82344. cbits++; /* skip over stop bit */
  82345. FLAC__ASSERT(cbits < FLAC__BITS_PER_WORD);
  82346. goto break1;
  82347. }
  82348. else {
  82349. uval += end - cbits;
  82350. cbits += end;
  82351. FLAC__ASSERT(cbits < FLAC__BITS_PER_WORD);
  82352. }
  82353. }
  82354. br->consumed_bits = cbits;
  82355. br->consumed_words = cwords;
  82356. if(!bitreader_read_from_client_(br))
  82357. return false;
  82358. cwords = br->consumed_words;
  82359. ucbits = (br->words-cwords)*FLAC__BITS_PER_WORD + br->bytes*8 - cbits + uval;
  82360. }
  82361. break1:
  82362. ucbits -= uval;
  82363. ucbits--; /* account for stop bit */
  82364. FLAC__ASSERT(cwords <= br->words);
  82365. if(parameter) {
  82366. while(ucbits < parameter) {
  82367. br->consumed_bits = cbits;
  82368. br->consumed_words = cwords;
  82369. if(!bitreader_read_from_client_(br))
  82370. return false;
  82371. cwords = br->consumed_words;
  82372. ucbits = (br->words-cwords)*FLAC__BITS_PER_WORD + br->bytes*8 - cbits;
  82373. }
  82374. if(cwords < br->words) { /* if we've not consumed up to a partial tail word... */
  82375. if(cbits) {
  82376. const unsigned n = FLAC__BITS_PER_WORD - cbits;
  82377. const brword word = br->buffer[cwords];
  82378. if(parameter < n) {
  82379. uval <<= parameter;
  82380. uval |= (word & (FLAC__WORD_ALL_ONES >> cbits)) >> (n-parameter);
  82381. cbits += parameter;
  82382. }
  82383. else {
  82384. uval <<= n;
  82385. uval |= word & (FLAC__WORD_ALL_ONES >> cbits);
  82386. crc16_update_word_(br, word);
  82387. cwords++;
  82388. cbits = parameter - n;
  82389. 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 */
  82390. uval <<= cbits;
  82391. uval |= (br->buffer[cwords] >> (FLAC__BITS_PER_WORD-cbits));
  82392. }
  82393. }
  82394. }
  82395. else {
  82396. cbits = parameter;
  82397. uval <<= parameter;
  82398. uval |= br->buffer[cwords] >> (FLAC__BITS_PER_WORD-cbits);
  82399. }
  82400. }
  82401. else {
  82402. uval <<= parameter;
  82403. if(cbits) {
  82404. FLAC__ASSERT(cbits + parameter <= br->bytes*8);
  82405. uval |= (br->buffer[cwords] & (FLAC__WORD_ALL_ONES >> cbits)) >> (FLAC__BITS_PER_WORD-cbits-parameter);
  82406. cbits += parameter;
  82407. }
  82408. else {
  82409. cbits = parameter;
  82410. uval |= br->buffer[cwords] >> (FLAC__BITS_PER_WORD-cbits);
  82411. }
  82412. }
  82413. }
  82414. ucbits -= parameter;
  82415. *vals = (int)(uval >> 1 ^ -(int)(uval & 1));
  82416. --nvals;
  82417. if(nvals == 0) {
  82418. br->consumed_bits = cbits;
  82419. br->consumed_words = cwords;
  82420. return true;
  82421. }
  82422. uval = 0;
  82423. ++vals;
  82424. }
  82425. }
  82426. #endif
  82427. #if 0 /* UNUSED */
  82428. FLAC__bool FLAC__bitreader_read_golomb_signed(FLAC__BitReader *br, int *val, unsigned parameter)
  82429. {
  82430. FLAC__uint32 lsbs = 0, msbs = 0;
  82431. unsigned bit, uval, k;
  82432. FLAC__ASSERT(0 != br);
  82433. FLAC__ASSERT(0 != br->buffer);
  82434. k = FLAC__bitmath_ilog2(parameter);
  82435. if(!FLAC__bitreader_read_unary_unsigned(br, &msbs))
  82436. return false;
  82437. if(!FLAC__bitreader_read_raw_uint32(br, &lsbs, k))
  82438. return false;
  82439. if(parameter == 1u<<k) {
  82440. uval = (msbs << k) | lsbs;
  82441. }
  82442. else {
  82443. unsigned d = (1 << (k+1)) - parameter;
  82444. if(lsbs >= d) {
  82445. if(!FLAC__bitreader_read_bit(br, &bit))
  82446. return false;
  82447. lsbs <<= 1;
  82448. lsbs |= bit;
  82449. lsbs -= d;
  82450. }
  82451. uval = msbs * parameter + lsbs;
  82452. }
  82453. if(uval & 1)
  82454. *val = -((int)(uval >> 1)) - 1;
  82455. else
  82456. *val = (int)(uval >> 1);
  82457. return true;
  82458. }
  82459. FLAC__bool FLAC__bitreader_read_golomb_unsigned(FLAC__BitReader *br, unsigned *val, unsigned parameter)
  82460. {
  82461. FLAC__uint32 lsbs, msbs = 0;
  82462. unsigned bit, k;
  82463. FLAC__ASSERT(0 != br);
  82464. FLAC__ASSERT(0 != br->buffer);
  82465. k = FLAC__bitmath_ilog2(parameter);
  82466. if(!FLAC__bitreader_read_unary_unsigned(br, &msbs))
  82467. return false;
  82468. if(!FLAC__bitreader_read_raw_uint32(br, &lsbs, k))
  82469. return false;
  82470. if(parameter == 1u<<k) {
  82471. *val = (msbs << k) | lsbs;
  82472. }
  82473. else {
  82474. unsigned d = (1 << (k+1)) - parameter;
  82475. if(lsbs >= d) {
  82476. if(!FLAC__bitreader_read_bit(br, &bit))
  82477. return false;
  82478. lsbs <<= 1;
  82479. lsbs |= bit;
  82480. lsbs -= d;
  82481. }
  82482. *val = msbs * parameter + lsbs;
  82483. }
  82484. return true;
  82485. }
  82486. #endif /* UNUSED */
  82487. FLAC__bool FLAC__bitreader_read_utf8_uint32(FLAC__BitReader *br, FLAC__uint32 *val, FLAC__byte *raw, unsigned *rawlen)
  82488. {
  82489. FLAC__uint32 v = 0;
  82490. FLAC__uint32 x;
  82491. unsigned i;
  82492. if(!FLAC__bitreader_read_raw_uint32(br, &x, 8))
  82493. return false;
  82494. if(raw)
  82495. raw[(*rawlen)++] = (FLAC__byte)x;
  82496. if(!(x & 0x80)) { /* 0xxxxxxx */
  82497. v = x;
  82498. i = 0;
  82499. }
  82500. else if(x & 0xC0 && !(x & 0x20)) { /* 110xxxxx */
  82501. v = x & 0x1F;
  82502. i = 1;
  82503. }
  82504. else if(x & 0xE0 && !(x & 0x10)) { /* 1110xxxx */
  82505. v = x & 0x0F;
  82506. i = 2;
  82507. }
  82508. else if(x & 0xF0 && !(x & 0x08)) { /* 11110xxx */
  82509. v = x & 0x07;
  82510. i = 3;
  82511. }
  82512. else if(x & 0xF8 && !(x & 0x04)) { /* 111110xx */
  82513. v = x & 0x03;
  82514. i = 4;
  82515. }
  82516. else if(x & 0xFC && !(x & 0x02)) { /* 1111110x */
  82517. v = x & 0x01;
  82518. i = 5;
  82519. }
  82520. else {
  82521. *val = 0xffffffff;
  82522. return true;
  82523. }
  82524. for( ; i; i--) {
  82525. if(!FLAC__bitreader_read_raw_uint32(br, &x, 8))
  82526. return false;
  82527. if(raw)
  82528. raw[(*rawlen)++] = (FLAC__byte)x;
  82529. if(!(x & 0x80) || (x & 0x40)) { /* 10xxxxxx */
  82530. *val = 0xffffffff;
  82531. return true;
  82532. }
  82533. v <<= 6;
  82534. v |= (x & 0x3F);
  82535. }
  82536. *val = v;
  82537. return true;
  82538. }
  82539. FLAC__bool FLAC__bitreader_read_utf8_uint64(FLAC__BitReader *br, FLAC__uint64 *val, FLAC__byte *raw, unsigned *rawlen)
  82540. {
  82541. FLAC__uint64 v = 0;
  82542. FLAC__uint32 x;
  82543. unsigned i;
  82544. if(!FLAC__bitreader_read_raw_uint32(br, &x, 8))
  82545. return false;
  82546. if(raw)
  82547. raw[(*rawlen)++] = (FLAC__byte)x;
  82548. if(!(x & 0x80)) { /* 0xxxxxxx */
  82549. v = x;
  82550. i = 0;
  82551. }
  82552. else if(x & 0xC0 && !(x & 0x20)) { /* 110xxxxx */
  82553. v = x & 0x1F;
  82554. i = 1;
  82555. }
  82556. else if(x & 0xE0 && !(x & 0x10)) { /* 1110xxxx */
  82557. v = x & 0x0F;
  82558. i = 2;
  82559. }
  82560. else if(x & 0xF0 && !(x & 0x08)) { /* 11110xxx */
  82561. v = x & 0x07;
  82562. i = 3;
  82563. }
  82564. else if(x & 0xF8 && !(x & 0x04)) { /* 111110xx */
  82565. v = x & 0x03;
  82566. i = 4;
  82567. }
  82568. else if(x & 0xFC && !(x & 0x02)) { /* 1111110x */
  82569. v = x & 0x01;
  82570. i = 5;
  82571. }
  82572. else if(x & 0xFE && !(x & 0x01)) { /* 11111110 */
  82573. v = 0;
  82574. i = 6;
  82575. }
  82576. else {
  82577. *val = FLAC__U64L(0xffffffffffffffff);
  82578. return true;
  82579. }
  82580. for( ; i; i--) {
  82581. if(!FLAC__bitreader_read_raw_uint32(br, &x, 8))
  82582. return false;
  82583. if(raw)
  82584. raw[(*rawlen)++] = (FLAC__byte)x;
  82585. if(!(x & 0x80) || (x & 0x40)) { /* 10xxxxxx */
  82586. *val = FLAC__U64L(0xffffffffffffffff);
  82587. return true;
  82588. }
  82589. v <<= 6;
  82590. v |= (x & 0x3F);
  82591. }
  82592. *val = v;
  82593. return true;
  82594. }
  82595. #endif
  82596. /*** End of inlined file: bitreader.c ***/
  82597. /*** Start of inlined file: bitwriter.c ***/
  82598. /*** Start of inlined file: juce_FlacHeader.h ***/
  82599. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  82600. // tasks..
  82601. #define VERSION "1.2.1"
  82602. #define FLAC__NO_DLL 1
  82603. #if JUCE_MSVC
  82604. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  82605. #endif
  82606. #if JUCE_MAC
  82607. #define FLAC__SYS_DARWIN 1
  82608. #endif
  82609. /*** End of inlined file: juce_FlacHeader.h ***/
  82610. #if JUCE_USE_FLAC
  82611. #if HAVE_CONFIG_H
  82612. # include <config.h>
  82613. #endif
  82614. #include <stdlib.h> /* for malloc() */
  82615. #include <string.h> /* for memcpy(), memset() */
  82616. #ifdef _MSC_VER
  82617. #include <winsock.h> /* for ntohl() */
  82618. #elif defined FLAC__SYS_DARWIN
  82619. #include <machine/endian.h> /* for ntohl() */
  82620. #elif defined __MINGW32__
  82621. #include <winsock.h> /* for ntohl() */
  82622. #else
  82623. #include <netinet/in.h> /* for ntohl() */
  82624. #endif
  82625. #if 0 /* UNUSED */
  82626. #endif
  82627. /*** Start of inlined file: bitwriter.h ***/
  82628. #ifndef FLAC__PRIVATE__BITWRITER_H
  82629. #define FLAC__PRIVATE__BITWRITER_H
  82630. #include <stdio.h> /* for FILE */
  82631. struct FLAC__BitWriter;
  82632. typedef struct FLAC__BitWriter FLAC__BitWriter;
  82633. FLAC__BitWriter *FLAC__bitwriter_new(void);
  82634. void FLAC__bitwriter_delete(FLAC__BitWriter *bw);
  82635. FLAC__bool FLAC__bitwriter_init(FLAC__BitWriter *bw);
  82636. void FLAC__bitwriter_free(FLAC__BitWriter *bw); /* does not 'free(buffer)' */
  82637. void FLAC__bitwriter_clear(FLAC__BitWriter *bw);
  82638. void FLAC__bitwriter_dump(const FLAC__BitWriter *bw, FILE *out);
  82639. FLAC__bool FLAC__bitwriter_get_write_crc16(FLAC__BitWriter *bw, FLAC__uint16 *crc);
  82640. FLAC__bool FLAC__bitwriter_get_write_crc8(FLAC__BitWriter *bw, FLAC__byte *crc);
  82641. FLAC__bool FLAC__bitwriter_is_byte_aligned(const FLAC__BitWriter *bw);
  82642. unsigned FLAC__bitwriter_get_input_bits_unconsumed(const FLAC__BitWriter *bw); /* can be called anytime, returns total # of bits unconsumed */
  82643. FLAC__bool FLAC__bitwriter_get_buffer(FLAC__BitWriter *bw, const FLAC__byte **buffer, size_t *bytes);
  82644. void FLAC__bitwriter_release_buffer(FLAC__BitWriter *bw);
  82645. FLAC__bool FLAC__bitwriter_write_zeroes(FLAC__BitWriter *bw, unsigned bits);
  82646. FLAC__bool FLAC__bitwriter_write_raw_uint32(FLAC__BitWriter *bw, FLAC__uint32 val, unsigned bits);
  82647. FLAC__bool FLAC__bitwriter_write_raw_int32(FLAC__BitWriter *bw, FLAC__int32 val, unsigned bits);
  82648. FLAC__bool FLAC__bitwriter_write_raw_uint64(FLAC__BitWriter *bw, FLAC__uint64 val, unsigned bits);
  82649. FLAC__bool FLAC__bitwriter_write_raw_uint32_little_endian(FLAC__BitWriter *bw, FLAC__uint32 val); /*only for bits=32*/
  82650. FLAC__bool FLAC__bitwriter_write_byte_block(FLAC__BitWriter *bw, const FLAC__byte vals[], unsigned nvals);
  82651. FLAC__bool FLAC__bitwriter_write_unary_unsigned(FLAC__BitWriter *bw, unsigned val);
  82652. unsigned FLAC__bitwriter_rice_bits(FLAC__int32 val, unsigned parameter);
  82653. #if 0 /* UNUSED */
  82654. unsigned FLAC__bitwriter_golomb_bits_signed(int val, unsigned parameter);
  82655. unsigned FLAC__bitwriter_golomb_bits_unsigned(unsigned val, unsigned parameter);
  82656. #endif
  82657. FLAC__bool FLAC__bitwriter_write_rice_signed(FLAC__BitWriter *bw, FLAC__int32 val, unsigned parameter);
  82658. FLAC__bool FLAC__bitwriter_write_rice_signed_block(FLAC__BitWriter *bw, const FLAC__int32 *vals, unsigned nvals, unsigned parameter);
  82659. #if 0 /* UNUSED */
  82660. FLAC__bool FLAC__bitwriter_write_golomb_signed(FLAC__BitWriter *bw, int val, unsigned parameter);
  82661. FLAC__bool FLAC__bitwriter_write_golomb_unsigned(FLAC__BitWriter *bw, unsigned val, unsigned parameter);
  82662. #endif
  82663. FLAC__bool FLAC__bitwriter_write_utf8_uint32(FLAC__BitWriter *bw, FLAC__uint32 val);
  82664. FLAC__bool FLAC__bitwriter_write_utf8_uint64(FLAC__BitWriter *bw, FLAC__uint64 val);
  82665. FLAC__bool FLAC__bitwriter_zero_pad_to_byte_boundary(FLAC__BitWriter *bw);
  82666. #endif
  82667. /*** End of inlined file: bitwriter.h ***/
  82668. /*** Start of inlined file: alloc.h ***/
  82669. #ifndef FLAC__SHARE__ALLOC_H
  82670. #define FLAC__SHARE__ALLOC_H
  82671. #if HAVE_CONFIG_H
  82672. # include <config.h>
  82673. #endif
  82674. #include <limits.h> /* for SIZE_MAX */
  82675. #if !defined _MSC_VER && !defined __MINGW32__ && !defined __EMX__
  82676. #include <stdint.h> /* for SIZE_MAX in case limits.h didn't get it */
  82677. #endif
  82678. #include <stdlib.h> /* for size_t, malloc(), etc */
  82679. #ifndef SIZE_MAX
  82680. # ifndef SIZE_T_MAX
  82681. # ifdef _MSC_VER
  82682. # define SIZE_T_MAX UINT_MAX
  82683. # else
  82684. # error
  82685. # endif
  82686. # endif
  82687. # define SIZE_MAX SIZE_T_MAX
  82688. #endif
  82689. #ifndef FLaC__INLINE
  82690. #define FLaC__INLINE
  82691. #endif
  82692. static FLaC__INLINE void *safe_malloc_(size_t size)
  82693. {
  82694. if(!size)
  82695. size++;
  82696. return malloc(size);
  82697. }
  82698. static FLaC__INLINE void *safe_calloc_(size_t nmemb, size_t size)
  82699. {
  82700. if(!nmemb || !size)
  82701. return malloc(1); /* malloc(0) is undefined; FLAC src convention is to always allocate */
  82702. return calloc(nmemb, size);
  82703. }
  82704. static FLaC__INLINE void *safe_malloc_add_2op_(size_t size1, size_t size2)
  82705. {
  82706. size2 += size1;
  82707. if(size2 < size1)
  82708. return 0;
  82709. return safe_malloc_(size2);
  82710. }
  82711. static FLaC__INLINE void *safe_malloc_add_3op_(size_t size1, size_t size2, size_t size3)
  82712. {
  82713. size2 += size1;
  82714. if(size2 < size1)
  82715. return 0;
  82716. size3 += size2;
  82717. if(size3 < size2)
  82718. return 0;
  82719. return safe_malloc_(size3);
  82720. }
  82721. static FLaC__INLINE void *safe_malloc_add_4op_(size_t size1, size_t size2, size_t size3, size_t size4)
  82722. {
  82723. size2 += size1;
  82724. if(size2 < size1)
  82725. return 0;
  82726. size3 += size2;
  82727. if(size3 < size2)
  82728. return 0;
  82729. size4 += size3;
  82730. if(size4 < size3)
  82731. return 0;
  82732. return safe_malloc_(size4);
  82733. }
  82734. static FLaC__INLINE void *safe_malloc_mul_2op_(size_t size1, size_t size2)
  82735. #if 0
  82736. needs support for cases where sizeof(size_t) != 4
  82737. {
  82738. if(sizeof(size_t) == 4) {
  82739. if ((double)size1 * (double)size2 < 4294967296.0)
  82740. return malloc(size1*size2);
  82741. }
  82742. return 0;
  82743. }
  82744. #else
  82745. {
  82746. if(!size1 || !size2)
  82747. return malloc(1); /* malloc(0) is undefined; FLAC src convention is to always allocate */
  82748. if(size1 > SIZE_MAX / size2)
  82749. return 0;
  82750. return malloc(size1*size2);
  82751. }
  82752. #endif
  82753. static FLaC__INLINE void *safe_malloc_mul_3op_(size_t size1, size_t size2, size_t size3)
  82754. {
  82755. if(!size1 || !size2 || !size3)
  82756. return malloc(1); /* malloc(0) is undefined; FLAC src convention is to always allocate */
  82757. if(size1 > SIZE_MAX / size2)
  82758. return 0;
  82759. size1 *= size2;
  82760. if(size1 > SIZE_MAX / size3)
  82761. return 0;
  82762. return malloc(size1*size3);
  82763. }
  82764. static FLaC__INLINE void *safe_malloc_mul2add_(size_t size1, size_t size2, size_t size3)
  82765. {
  82766. if(!size1 || !size2)
  82767. return safe_malloc_(size3);
  82768. if(size1 > SIZE_MAX / size2)
  82769. return 0;
  82770. return safe_malloc_add_2op_(size1*size2, size3);
  82771. }
  82772. static FLaC__INLINE void *safe_malloc_muladd2_(size_t size1, size_t size2, size_t size3)
  82773. {
  82774. if(!size1 || (!size2 && !size3))
  82775. return malloc(1); /* malloc(0) is undefined; FLAC src convention is to always allocate */
  82776. size2 += size3;
  82777. if(size2 < size3)
  82778. return 0;
  82779. return safe_malloc_mul_2op_(size1, size2);
  82780. }
  82781. static FLaC__INLINE void *safe_realloc_add_2op_(void *ptr, size_t size1, size_t size2)
  82782. {
  82783. size2 += size1;
  82784. if(size2 < size1)
  82785. return 0;
  82786. return realloc(ptr, size2);
  82787. }
  82788. static FLaC__INLINE void *safe_realloc_add_3op_(void *ptr, size_t size1, size_t size2, size_t size3)
  82789. {
  82790. size2 += size1;
  82791. if(size2 < size1)
  82792. return 0;
  82793. size3 += size2;
  82794. if(size3 < size2)
  82795. return 0;
  82796. return realloc(ptr, size3);
  82797. }
  82798. static FLaC__INLINE void *safe_realloc_add_4op_(void *ptr, size_t size1, size_t size2, size_t size3, size_t size4)
  82799. {
  82800. size2 += size1;
  82801. if(size2 < size1)
  82802. return 0;
  82803. size3 += size2;
  82804. if(size3 < size2)
  82805. return 0;
  82806. size4 += size3;
  82807. if(size4 < size3)
  82808. return 0;
  82809. return realloc(ptr, size4);
  82810. }
  82811. static FLaC__INLINE void *safe_realloc_mul_2op_(void *ptr, size_t size1, size_t size2)
  82812. {
  82813. if(!size1 || !size2)
  82814. return realloc(ptr, 0); /* preserve POSIX realloc(ptr, 0) semantics */
  82815. if(size1 > SIZE_MAX / size2)
  82816. return 0;
  82817. return realloc(ptr, size1*size2);
  82818. }
  82819. static FLaC__INLINE void *safe_realloc_muladd2_(void *ptr, size_t size1, size_t size2, size_t size3)
  82820. {
  82821. if(!size1 || (!size2 && !size3))
  82822. return realloc(ptr, 0); /* preserve POSIX realloc(ptr, 0) semantics */
  82823. size2 += size3;
  82824. if(size2 < size3)
  82825. return 0;
  82826. return safe_realloc_mul_2op_(ptr, size1, size2);
  82827. }
  82828. #endif
  82829. /*** End of inlined file: alloc.h ***/
  82830. typedef FLAC__uint32 bwword;
  82831. #define FLAC__BYTES_PER_WORD 4
  82832. #define FLAC__BITS_PER_WORD 32
  82833. #define FLAC__WORD_ALL_ONES ((FLAC__uint32)0xffffffff)
  82834. #if WORDS_BIGENDIAN
  82835. #define SWAP_BE_WORD_TO_HOST(x) (x)
  82836. #else
  82837. #ifdef _MSC_VER
  82838. #define SWAP_BE_WORD_TO_HOST(x) local_swap32_(x)
  82839. #else
  82840. #define SWAP_BE_WORD_TO_HOST(x) ntohl(x)
  82841. #endif
  82842. #endif
  82843. static const unsigned FLAC__BITWRITER_DEFAULT_CAPACITY = 32768u / sizeof(bwword); /* size in words */
  82844. static const unsigned FLAC__BITWRITER_DEFAULT_INCREMENT = 4096u / sizeof(bwword); /* size in words */
  82845. #define FLAC__WORDS_TO_BITS(words) ((words) * FLAC__BITS_PER_WORD)
  82846. #define FLAC__TOTAL_BITS(bw) (FLAC__WORDS_TO_BITS((bw)->words) + (bw)->bits)
  82847. #ifdef min
  82848. #undef min
  82849. #endif
  82850. #define min(x,y) ((x)<(y)?(x):(y))
  82851. #ifdef _MSC_VER
  82852. #define FLAC__U64L(x) x
  82853. #else
  82854. #define FLAC__U64L(x) x##LLU
  82855. #endif
  82856. #ifndef FLaC__INLINE
  82857. #define FLaC__INLINE
  82858. #endif
  82859. struct FLAC__BitWriter {
  82860. bwword *buffer;
  82861. bwword accum; /* accumulator; bits are right-justified; when full, accum is appended to buffer */
  82862. unsigned capacity; /* capacity of buffer in words */
  82863. unsigned words; /* # of complete words in buffer */
  82864. unsigned bits; /* # of used bits in accum */
  82865. };
  82866. static FLAC__bool bitwriter_grow_(FLAC__BitWriter *bw, unsigned bits_to_add)
  82867. {
  82868. unsigned new_capacity;
  82869. bwword *new_buffer;
  82870. FLAC__ASSERT(0 != bw);
  82871. FLAC__ASSERT(0 != bw->buffer);
  82872. new_capacity = bw->words + ((bw->bits + bits_to_add + FLAC__BITS_PER_WORD - 1) / FLAC__BITS_PER_WORD);
  82873. if(bw->capacity >= new_capacity)
  82874. return true;
  82875. if((new_capacity - bw->capacity) % FLAC__BITWRITER_DEFAULT_INCREMENT)
  82876. new_capacity += FLAC__BITWRITER_DEFAULT_INCREMENT - ((new_capacity - bw->capacity) % FLAC__BITWRITER_DEFAULT_INCREMENT);
  82877. FLAC__ASSERT(0 == (new_capacity - bw->capacity) % FLAC__BITWRITER_DEFAULT_INCREMENT);
  82878. FLAC__ASSERT(new_capacity > bw->capacity);
  82879. FLAC__ASSERT(new_capacity >= bw->words + ((bw->bits + bits_to_add + FLAC__BITS_PER_WORD - 1) / FLAC__BITS_PER_WORD));
  82880. new_buffer = (bwword*)safe_realloc_mul_2op_(bw->buffer, sizeof(bwword), /*times*/new_capacity);
  82881. if(new_buffer == 0)
  82882. return false;
  82883. bw->buffer = new_buffer;
  82884. bw->capacity = new_capacity;
  82885. return true;
  82886. }
  82887. FLAC__BitWriter *FLAC__bitwriter_new(void)
  82888. {
  82889. FLAC__BitWriter *bw = (FLAC__BitWriter*)calloc(1, sizeof(FLAC__BitWriter));
  82890. return bw;
  82891. }
  82892. void FLAC__bitwriter_delete(FLAC__BitWriter *bw)
  82893. {
  82894. FLAC__ASSERT(0 != bw);
  82895. FLAC__bitwriter_free(bw);
  82896. free(bw);
  82897. }
  82898. FLAC__bool FLAC__bitwriter_init(FLAC__BitWriter *bw)
  82899. {
  82900. FLAC__ASSERT(0 != bw);
  82901. bw->words = bw->bits = 0;
  82902. bw->capacity = FLAC__BITWRITER_DEFAULT_CAPACITY;
  82903. bw->buffer = (bwword*)malloc(sizeof(bwword) * bw->capacity);
  82904. if(bw->buffer == 0)
  82905. return false;
  82906. return true;
  82907. }
  82908. void FLAC__bitwriter_free(FLAC__BitWriter *bw)
  82909. {
  82910. FLAC__ASSERT(0 != bw);
  82911. if(0 != bw->buffer)
  82912. free(bw->buffer);
  82913. bw->buffer = 0;
  82914. bw->capacity = 0;
  82915. bw->words = bw->bits = 0;
  82916. }
  82917. void FLAC__bitwriter_clear(FLAC__BitWriter *bw)
  82918. {
  82919. bw->words = bw->bits = 0;
  82920. }
  82921. void FLAC__bitwriter_dump(const FLAC__BitWriter *bw, FILE *out)
  82922. {
  82923. unsigned i, j;
  82924. if(bw == 0) {
  82925. fprintf(out, "bitwriter is NULL\n");
  82926. }
  82927. else {
  82928. fprintf(out, "bitwriter: capacity=%u words=%u bits=%u total_bits=%u\n", bw->capacity, bw->words, bw->bits, FLAC__TOTAL_BITS(bw));
  82929. for(i = 0; i < bw->words; i++) {
  82930. fprintf(out, "%08X: ", i);
  82931. for(j = 0; j < FLAC__BITS_PER_WORD; j++)
  82932. fprintf(out, "%01u", bw->buffer[i] & (1 << (FLAC__BITS_PER_WORD-j-1)) ? 1:0);
  82933. fprintf(out, "\n");
  82934. }
  82935. if(bw->bits > 0) {
  82936. fprintf(out, "%08X: ", i);
  82937. for(j = 0; j < bw->bits; j++)
  82938. fprintf(out, "%01u", bw->accum & (1 << (bw->bits-j-1)) ? 1:0);
  82939. fprintf(out, "\n");
  82940. }
  82941. }
  82942. }
  82943. FLAC__bool FLAC__bitwriter_get_write_crc16(FLAC__BitWriter *bw, FLAC__uint16 *crc)
  82944. {
  82945. const FLAC__byte *buffer;
  82946. size_t bytes;
  82947. FLAC__ASSERT((bw->bits & 7) == 0); /* assert that we're byte-aligned */
  82948. if(!FLAC__bitwriter_get_buffer(bw, &buffer, &bytes))
  82949. return false;
  82950. *crc = (FLAC__uint16)FLAC__crc16(buffer, bytes);
  82951. FLAC__bitwriter_release_buffer(bw);
  82952. return true;
  82953. }
  82954. FLAC__bool FLAC__bitwriter_get_write_crc8(FLAC__BitWriter *bw, FLAC__byte *crc)
  82955. {
  82956. const FLAC__byte *buffer;
  82957. size_t bytes;
  82958. FLAC__ASSERT((bw->bits & 7) == 0); /* assert that we're byte-aligned */
  82959. if(!FLAC__bitwriter_get_buffer(bw, &buffer, &bytes))
  82960. return false;
  82961. *crc = FLAC__crc8(buffer, bytes);
  82962. FLAC__bitwriter_release_buffer(bw);
  82963. return true;
  82964. }
  82965. FLAC__bool FLAC__bitwriter_is_byte_aligned(const FLAC__BitWriter *bw)
  82966. {
  82967. return ((bw->bits & 7) == 0);
  82968. }
  82969. unsigned FLAC__bitwriter_get_input_bits_unconsumed(const FLAC__BitWriter *bw)
  82970. {
  82971. return FLAC__TOTAL_BITS(bw);
  82972. }
  82973. FLAC__bool FLAC__bitwriter_get_buffer(FLAC__BitWriter *bw, const FLAC__byte **buffer, size_t *bytes)
  82974. {
  82975. FLAC__ASSERT((bw->bits & 7) == 0);
  82976. if(bw->bits & 7)
  82977. return false;
  82978. if(bw->bits) {
  82979. FLAC__ASSERT(bw->words <= bw->capacity);
  82980. if(bw->words == bw->capacity && !bitwriter_grow_(bw, FLAC__BITS_PER_WORD))
  82981. return false;
  82982. bw->buffer[bw->words] = SWAP_BE_WORD_TO_HOST(bw->accum << (FLAC__BITS_PER_WORD-bw->bits));
  82983. }
  82984. *buffer = (FLAC__byte*)bw->buffer;
  82985. *bytes = (FLAC__BYTES_PER_WORD * bw->words) + (bw->bits >> 3);
  82986. return true;
  82987. }
  82988. void FLAC__bitwriter_release_buffer(FLAC__BitWriter *bw)
  82989. {
  82990. (void)bw;
  82991. }
  82992. FLaC__INLINE FLAC__bool FLAC__bitwriter_write_zeroes(FLAC__BitWriter *bw, unsigned bits)
  82993. {
  82994. unsigned n;
  82995. FLAC__ASSERT(0 != bw);
  82996. FLAC__ASSERT(0 != bw->buffer);
  82997. if(bits == 0)
  82998. return true;
  82999. if(bw->capacity <= bw->words + bits && !bitwriter_grow_(bw, bits))
  83000. return false;
  83001. if(bw->bits) {
  83002. n = min(FLAC__BITS_PER_WORD - bw->bits, bits);
  83003. bw->accum <<= n;
  83004. bits -= n;
  83005. bw->bits += n;
  83006. if(bw->bits == FLAC__BITS_PER_WORD) {
  83007. bw->buffer[bw->words++] = SWAP_BE_WORD_TO_HOST(bw->accum);
  83008. bw->bits = 0;
  83009. }
  83010. else
  83011. return true;
  83012. }
  83013. while(bits >= FLAC__BITS_PER_WORD) {
  83014. bw->buffer[bw->words++] = 0;
  83015. bits -= FLAC__BITS_PER_WORD;
  83016. }
  83017. if(bits > 0) {
  83018. bw->accum = 0;
  83019. bw->bits = bits;
  83020. }
  83021. return true;
  83022. }
  83023. FLaC__INLINE FLAC__bool FLAC__bitwriter_write_raw_uint32(FLAC__BitWriter *bw, FLAC__uint32 val, unsigned bits)
  83024. {
  83025. register unsigned left;
  83026. FLAC__ASSERT(FLAC__BITS_PER_WORD >= 32);
  83027. FLAC__ASSERT(0 != bw);
  83028. FLAC__ASSERT(0 != bw->buffer);
  83029. FLAC__ASSERT(bits <= 32);
  83030. if(bits == 0)
  83031. return true;
  83032. if(bw->capacity <= bw->words + bits && !bitwriter_grow_(bw, bits))
  83033. return false;
  83034. left = FLAC__BITS_PER_WORD - bw->bits;
  83035. if(bits < left) {
  83036. bw->accum <<= bits;
  83037. bw->accum |= val;
  83038. bw->bits += bits;
  83039. }
  83040. 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 */
  83041. bw->accum <<= left;
  83042. bw->accum |= val >> (bw->bits = bits - left);
  83043. bw->buffer[bw->words++] = SWAP_BE_WORD_TO_HOST(bw->accum);
  83044. bw->accum = val;
  83045. }
  83046. else {
  83047. bw->accum = val;
  83048. bw->bits = 0;
  83049. bw->buffer[bw->words++] = SWAP_BE_WORD_TO_HOST(val);
  83050. }
  83051. return true;
  83052. }
  83053. FLaC__INLINE FLAC__bool FLAC__bitwriter_write_raw_int32(FLAC__BitWriter *bw, FLAC__int32 val, unsigned bits)
  83054. {
  83055. if(bits < 32)
  83056. val &= (~(0xffffffff << bits));
  83057. return FLAC__bitwriter_write_raw_uint32(bw, (FLAC__uint32)val, bits);
  83058. }
  83059. FLaC__INLINE FLAC__bool FLAC__bitwriter_write_raw_uint64(FLAC__BitWriter *bw, FLAC__uint64 val, unsigned bits)
  83060. {
  83061. if(bits > 32) {
  83062. return
  83063. FLAC__bitwriter_write_raw_uint32(bw, (FLAC__uint32)(val>>32), bits-32) &&
  83064. FLAC__bitwriter_write_raw_uint32(bw, (FLAC__uint32)val, 32);
  83065. }
  83066. else
  83067. return FLAC__bitwriter_write_raw_uint32(bw, (FLAC__uint32)val, bits);
  83068. }
  83069. FLaC__INLINE FLAC__bool FLAC__bitwriter_write_raw_uint32_little_endian(FLAC__BitWriter *bw, FLAC__uint32 val)
  83070. {
  83071. if(!FLAC__bitwriter_write_raw_uint32(bw, val & 0xff, 8))
  83072. return false;
  83073. if(!FLAC__bitwriter_write_raw_uint32(bw, (val>>8) & 0xff, 8))
  83074. return false;
  83075. if(!FLAC__bitwriter_write_raw_uint32(bw, (val>>16) & 0xff, 8))
  83076. return false;
  83077. if(!FLAC__bitwriter_write_raw_uint32(bw, val>>24, 8))
  83078. return false;
  83079. return true;
  83080. }
  83081. FLaC__INLINE FLAC__bool FLAC__bitwriter_write_byte_block(FLAC__BitWriter *bw, const FLAC__byte vals[], unsigned nvals)
  83082. {
  83083. unsigned i;
  83084. for(i = 0; i < nvals; i++) {
  83085. if(!FLAC__bitwriter_write_raw_uint32(bw, (FLAC__uint32)(vals[i]), 8))
  83086. return false;
  83087. }
  83088. return true;
  83089. }
  83090. FLAC__bool FLAC__bitwriter_write_unary_unsigned(FLAC__BitWriter *bw, unsigned val)
  83091. {
  83092. if(val < 32)
  83093. return FLAC__bitwriter_write_raw_uint32(bw, 1, ++val);
  83094. else
  83095. return
  83096. FLAC__bitwriter_write_zeroes(bw, val) &&
  83097. FLAC__bitwriter_write_raw_uint32(bw, 1, 1);
  83098. }
  83099. unsigned FLAC__bitwriter_rice_bits(FLAC__int32 val, unsigned parameter)
  83100. {
  83101. FLAC__uint32 uval;
  83102. FLAC__ASSERT(parameter < sizeof(unsigned)*8);
  83103. uval = (val<<1) ^ (val>>31);
  83104. return 1 + parameter + (uval >> parameter);
  83105. }
  83106. #if 0 /* UNUSED */
  83107. unsigned FLAC__bitwriter_golomb_bits_signed(int val, unsigned parameter)
  83108. {
  83109. unsigned bits, msbs, uval;
  83110. unsigned k;
  83111. FLAC__ASSERT(parameter > 0);
  83112. if(val < 0)
  83113. uval = (unsigned)(((-(++val)) << 1) + 1);
  83114. else
  83115. uval = (unsigned)(val << 1);
  83116. k = FLAC__bitmath_ilog2(parameter);
  83117. if(parameter == 1u<<k) {
  83118. FLAC__ASSERT(k <= 30);
  83119. msbs = uval >> k;
  83120. bits = 1 + k + msbs;
  83121. }
  83122. else {
  83123. unsigned q, r, d;
  83124. d = (1 << (k+1)) - parameter;
  83125. q = uval / parameter;
  83126. r = uval - (q * parameter);
  83127. bits = 1 + q + k;
  83128. if(r >= d)
  83129. bits++;
  83130. }
  83131. return bits;
  83132. }
  83133. unsigned FLAC__bitwriter_golomb_bits_unsigned(unsigned uval, unsigned parameter)
  83134. {
  83135. unsigned bits, msbs;
  83136. unsigned k;
  83137. FLAC__ASSERT(parameter > 0);
  83138. k = FLAC__bitmath_ilog2(parameter);
  83139. if(parameter == 1u<<k) {
  83140. FLAC__ASSERT(k <= 30);
  83141. msbs = uval >> k;
  83142. bits = 1 + k + msbs;
  83143. }
  83144. else {
  83145. unsigned q, r, d;
  83146. d = (1 << (k+1)) - parameter;
  83147. q = uval / parameter;
  83148. r = uval - (q * parameter);
  83149. bits = 1 + q + k;
  83150. if(r >= d)
  83151. bits++;
  83152. }
  83153. return bits;
  83154. }
  83155. #endif /* UNUSED */
  83156. FLAC__bool FLAC__bitwriter_write_rice_signed(FLAC__BitWriter *bw, FLAC__int32 val, unsigned parameter)
  83157. {
  83158. unsigned total_bits, interesting_bits, msbs;
  83159. FLAC__uint32 uval, pattern;
  83160. FLAC__ASSERT(0 != bw);
  83161. FLAC__ASSERT(0 != bw->buffer);
  83162. FLAC__ASSERT(parameter < 8*sizeof(uval));
  83163. uval = (val<<1) ^ (val>>31);
  83164. msbs = uval >> parameter;
  83165. interesting_bits = 1 + parameter;
  83166. total_bits = interesting_bits + msbs;
  83167. pattern = 1 << parameter; /* the unary end bit */
  83168. pattern |= (uval & ((1<<parameter)-1)); /* the binary LSBs */
  83169. if(total_bits <= 32)
  83170. return FLAC__bitwriter_write_raw_uint32(bw, pattern, total_bits);
  83171. else
  83172. return
  83173. FLAC__bitwriter_write_zeroes(bw, msbs) && /* write the unary MSBs */
  83174. FLAC__bitwriter_write_raw_uint32(bw, pattern, interesting_bits); /* write the unary end bit and binary LSBs */
  83175. }
  83176. FLAC__bool FLAC__bitwriter_write_rice_signed_block(FLAC__BitWriter *bw, const FLAC__int32 *vals, unsigned nvals, unsigned parameter)
  83177. {
  83178. const FLAC__uint32 mask1 = FLAC__WORD_ALL_ONES << parameter; /* we val|=mask1 to set the stop bit above it... */
  83179. const FLAC__uint32 mask2 = FLAC__WORD_ALL_ONES >> (31-parameter); /* ...then mask off the bits above the stop bit with val&=mask2*/
  83180. FLAC__uint32 uval;
  83181. unsigned left;
  83182. const unsigned lsbits = 1 + parameter;
  83183. unsigned msbits;
  83184. FLAC__ASSERT(0 != bw);
  83185. FLAC__ASSERT(0 != bw->buffer);
  83186. FLAC__ASSERT(parameter < 8*sizeof(bwword)-1);
  83187. FLAC__ASSERT(FLAC__BITS_PER_WORD >= 32);
  83188. while(nvals) {
  83189. uval = (*vals<<1) ^ (*vals>>31);
  83190. msbits = uval >> parameter;
  83191. #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) */
  83192. if(bw->bits && bw->bits + msbits + lsbits <= FLAC__BITS_PER_WORD) { /* i.e. if the whole thing fits in the current bwword */
  83193. bw->bits = bw->bits + msbits + lsbits;
  83194. uval |= mask1; /* set stop bit */
  83195. uval &= mask2; /* mask off unused top bits */
  83196. bw->accum <<= msbits;
  83197. bw->accum <<= lsbits;
  83198. bw->accum |= uval;
  83199. if(bw->bits == FLAC__BITS_PER_WORD) {
  83200. bw->buffer[bw->words++] = SWAP_BE_WORD_TO_HOST(bw->accum);
  83201. bw->bits = 0;
  83202. if(bw->capacity <= bw->words && nvals > 1 && !bitwriter_grow_(bw, 1)) {
  83203. FLAC__ASSERT(bw->capacity == bw->words);
  83204. return false;
  83205. }
  83206. }
  83207. }
  83208. else {
  83209. #elif 1 /*@@@@@@ OPT: try this version with MSVC6 to see if better, not much difference for gcc-4 */
  83210. if(bw->bits && bw->bits + msbits + lsbits < FLAC__BITS_PER_WORD) { /* i.e. if the whole thing fits in the current bwword */
  83211. bw->bits = bw->bits + msbits + lsbits;
  83212. uval |= mask1; /* set stop bit */
  83213. uval &= mask2; /* mask off unused top bits */
  83214. bw->accum <<= msbits + lsbits;
  83215. bw->accum |= uval;
  83216. }
  83217. else {
  83218. #endif
  83219. if(bw->capacity <= bw->words + bw->bits + msbits + 1/*lsbits always fit in 1 bwword*/ && !bitwriter_grow_(bw, msbits+lsbits))
  83220. return false;
  83221. if(msbits) {
  83222. if(bw->bits) {
  83223. left = FLAC__BITS_PER_WORD - bw->bits;
  83224. if(msbits < left) {
  83225. bw->accum <<= msbits;
  83226. bw->bits += msbits;
  83227. goto break1;
  83228. }
  83229. else {
  83230. bw->accum <<= left;
  83231. msbits -= left;
  83232. bw->buffer[bw->words++] = SWAP_BE_WORD_TO_HOST(bw->accum);
  83233. bw->bits = 0;
  83234. }
  83235. }
  83236. while(msbits >= FLAC__BITS_PER_WORD) {
  83237. bw->buffer[bw->words++] = 0;
  83238. msbits -= FLAC__BITS_PER_WORD;
  83239. }
  83240. if(msbits > 0) {
  83241. bw->accum = 0;
  83242. bw->bits = msbits;
  83243. }
  83244. }
  83245. break1:
  83246. uval |= mask1; /* set stop bit */
  83247. uval &= mask2; /* mask off unused top bits */
  83248. left = FLAC__BITS_PER_WORD - bw->bits;
  83249. if(lsbits < left) {
  83250. bw->accum <<= lsbits;
  83251. bw->accum |= uval;
  83252. bw->bits += lsbits;
  83253. }
  83254. else {
  83255. FLAC__ASSERT(bw->bits);
  83256. FLAC__ASSERT(left < FLAC__BITS_PER_WORD);
  83257. bw->accum <<= left;
  83258. bw->accum |= uval >> (bw->bits = lsbits - left);
  83259. bw->buffer[bw->words++] = SWAP_BE_WORD_TO_HOST(bw->accum);
  83260. bw->accum = uval;
  83261. }
  83262. #if 1
  83263. }
  83264. #endif
  83265. vals++;
  83266. nvals--;
  83267. }
  83268. return true;
  83269. }
  83270. #if 0 /* UNUSED */
  83271. FLAC__bool FLAC__bitwriter_write_golomb_signed(FLAC__BitWriter *bw, int val, unsigned parameter)
  83272. {
  83273. unsigned total_bits, msbs, uval;
  83274. unsigned k;
  83275. FLAC__ASSERT(0 != bw);
  83276. FLAC__ASSERT(0 != bw->buffer);
  83277. FLAC__ASSERT(parameter > 0);
  83278. if(val < 0)
  83279. uval = (unsigned)(((-(++val)) << 1) + 1);
  83280. else
  83281. uval = (unsigned)(val << 1);
  83282. k = FLAC__bitmath_ilog2(parameter);
  83283. if(parameter == 1u<<k) {
  83284. unsigned pattern;
  83285. FLAC__ASSERT(k <= 30);
  83286. msbs = uval >> k;
  83287. total_bits = 1 + k + msbs;
  83288. pattern = 1 << k; /* the unary end bit */
  83289. pattern |= (uval & ((1u<<k)-1)); /* the binary LSBs */
  83290. if(total_bits <= 32) {
  83291. if(!FLAC__bitwriter_write_raw_uint32(bw, pattern, total_bits))
  83292. return false;
  83293. }
  83294. else {
  83295. if(!FLAC__bitwriter_write_zeroes(bw, msbs))
  83296. return false;
  83297. if(!FLAC__bitwriter_write_raw_uint32(bw, pattern, k+1))
  83298. return false;
  83299. }
  83300. }
  83301. else {
  83302. unsigned q, r, d;
  83303. d = (1 << (k+1)) - parameter;
  83304. q = uval / parameter;
  83305. r = uval - (q * parameter);
  83306. if(!FLAC__bitwriter_write_zeroes(bw, q))
  83307. return false;
  83308. if(!FLAC__bitwriter_write_raw_uint32(bw, 1, 1))
  83309. return false;
  83310. if(r >= d) {
  83311. if(!FLAC__bitwriter_write_raw_uint32(bw, r+d, k+1))
  83312. return false;
  83313. }
  83314. else {
  83315. if(!FLAC__bitwriter_write_raw_uint32(bw, r, k))
  83316. return false;
  83317. }
  83318. }
  83319. return true;
  83320. }
  83321. FLAC__bool FLAC__bitwriter_write_golomb_unsigned(FLAC__BitWriter *bw, unsigned uval, unsigned parameter)
  83322. {
  83323. unsigned total_bits, msbs;
  83324. unsigned k;
  83325. FLAC__ASSERT(0 != bw);
  83326. FLAC__ASSERT(0 != bw->buffer);
  83327. FLAC__ASSERT(parameter > 0);
  83328. k = FLAC__bitmath_ilog2(parameter);
  83329. if(parameter == 1u<<k) {
  83330. unsigned pattern;
  83331. FLAC__ASSERT(k <= 30);
  83332. msbs = uval >> k;
  83333. total_bits = 1 + k + msbs;
  83334. pattern = 1 << k; /* the unary end bit */
  83335. pattern |= (uval & ((1u<<k)-1)); /* the binary LSBs */
  83336. if(total_bits <= 32) {
  83337. if(!FLAC__bitwriter_write_raw_uint32(bw, pattern, total_bits))
  83338. return false;
  83339. }
  83340. else {
  83341. if(!FLAC__bitwriter_write_zeroes(bw, msbs))
  83342. return false;
  83343. if(!FLAC__bitwriter_write_raw_uint32(bw, pattern, k+1))
  83344. return false;
  83345. }
  83346. }
  83347. else {
  83348. unsigned q, r, d;
  83349. d = (1 << (k+1)) - parameter;
  83350. q = uval / parameter;
  83351. r = uval - (q * parameter);
  83352. if(!FLAC__bitwriter_write_zeroes(bw, q))
  83353. return false;
  83354. if(!FLAC__bitwriter_write_raw_uint32(bw, 1, 1))
  83355. return false;
  83356. if(r >= d) {
  83357. if(!FLAC__bitwriter_write_raw_uint32(bw, r+d, k+1))
  83358. return false;
  83359. }
  83360. else {
  83361. if(!FLAC__bitwriter_write_raw_uint32(bw, r, k))
  83362. return false;
  83363. }
  83364. }
  83365. return true;
  83366. }
  83367. #endif /* UNUSED */
  83368. FLAC__bool FLAC__bitwriter_write_utf8_uint32(FLAC__BitWriter *bw, FLAC__uint32 val)
  83369. {
  83370. FLAC__bool ok = 1;
  83371. FLAC__ASSERT(0 != bw);
  83372. FLAC__ASSERT(0 != bw->buffer);
  83373. FLAC__ASSERT(!(val & 0x80000000)); /* this version only handles 31 bits */
  83374. if(val < 0x80) {
  83375. return FLAC__bitwriter_write_raw_uint32(bw, val, 8);
  83376. }
  83377. else if(val < 0x800) {
  83378. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xC0 | (val>>6), 8);
  83379. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (val&0x3F), 8);
  83380. }
  83381. else if(val < 0x10000) {
  83382. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xE0 | (val>>12), 8);
  83383. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | ((val>>6)&0x3F), 8);
  83384. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (val&0x3F), 8);
  83385. }
  83386. else if(val < 0x200000) {
  83387. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xF0 | (val>>18), 8);
  83388. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | ((val>>12)&0x3F), 8);
  83389. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | ((val>>6)&0x3F), 8);
  83390. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (val&0x3F), 8);
  83391. }
  83392. else if(val < 0x4000000) {
  83393. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xF8 | (val>>24), 8);
  83394. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | ((val>>18)&0x3F), 8);
  83395. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | ((val>>12)&0x3F), 8);
  83396. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | ((val>>6)&0x3F), 8);
  83397. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (val&0x3F), 8);
  83398. }
  83399. else {
  83400. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xFC | (val>>30), 8);
  83401. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | ((val>>24)&0x3F), 8);
  83402. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | ((val>>18)&0x3F), 8);
  83403. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | ((val>>12)&0x3F), 8);
  83404. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | ((val>>6)&0x3F), 8);
  83405. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (val&0x3F), 8);
  83406. }
  83407. return ok;
  83408. }
  83409. FLAC__bool FLAC__bitwriter_write_utf8_uint64(FLAC__BitWriter *bw, FLAC__uint64 val)
  83410. {
  83411. FLAC__bool ok = 1;
  83412. FLAC__ASSERT(0 != bw);
  83413. FLAC__ASSERT(0 != bw->buffer);
  83414. FLAC__ASSERT(!(val & FLAC__U64L(0xFFFFFFF000000000))); /* this version only handles 36 bits */
  83415. if(val < 0x80) {
  83416. return FLAC__bitwriter_write_raw_uint32(bw, (FLAC__uint32)val, 8);
  83417. }
  83418. else if(val < 0x800) {
  83419. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xC0 | (FLAC__uint32)(val>>6), 8);
  83420. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)(val&0x3F), 8);
  83421. }
  83422. else if(val < 0x10000) {
  83423. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xE0 | (FLAC__uint32)(val>>12), 8);
  83424. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>6)&0x3F), 8);
  83425. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)(val&0x3F), 8);
  83426. }
  83427. else if(val < 0x200000) {
  83428. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xF0 | (FLAC__uint32)(val>>18), 8);
  83429. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>12)&0x3F), 8);
  83430. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>6)&0x3F), 8);
  83431. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)(val&0x3F), 8);
  83432. }
  83433. else if(val < 0x4000000) {
  83434. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xF8 | (FLAC__uint32)(val>>24), 8);
  83435. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>18)&0x3F), 8);
  83436. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>12)&0x3F), 8);
  83437. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>6)&0x3F), 8);
  83438. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)(val&0x3F), 8);
  83439. }
  83440. else if(val < 0x80000000) {
  83441. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xFC | (FLAC__uint32)(val>>30), 8);
  83442. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>24)&0x3F), 8);
  83443. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>18)&0x3F), 8);
  83444. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>12)&0x3F), 8);
  83445. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>6)&0x3F), 8);
  83446. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)(val&0x3F), 8);
  83447. }
  83448. else {
  83449. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xFE, 8);
  83450. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>30)&0x3F), 8);
  83451. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>24)&0x3F), 8);
  83452. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>18)&0x3F), 8);
  83453. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>12)&0x3F), 8);
  83454. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>6)&0x3F), 8);
  83455. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)(val&0x3F), 8);
  83456. }
  83457. return ok;
  83458. }
  83459. FLAC__bool FLAC__bitwriter_zero_pad_to_byte_boundary(FLAC__BitWriter *bw)
  83460. {
  83461. if(bw->bits & 7u)
  83462. return FLAC__bitwriter_write_zeroes(bw, 8 - (bw->bits & 7u));
  83463. else
  83464. return true;
  83465. }
  83466. #endif
  83467. /*** End of inlined file: bitwriter.c ***/
  83468. /*** Start of inlined file: cpu.c ***/
  83469. /*** Start of inlined file: juce_FlacHeader.h ***/
  83470. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  83471. // tasks..
  83472. #define VERSION "1.2.1"
  83473. #define FLAC__NO_DLL 1
  83474. #if JUCE_MSVC
  83475. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  83476. #endif
  83477. #if JUCE_MAC
  83478. #define FLAC__SYS_DARWIN 1
  83479. #endif
  83480. /*** End of inlined file: juce_FlacHeader.h ***/
  83481. #if JUCE_USE_FLAC
  83482. #if HAVE_CONFIG_H
  83483. # include <config.h>
  83484. #endif
  83485. #include <stdlib.h>
  83486. #include <stdio.h>
  83487. #if defined FLAC__CPU_IA32
  83488. # include <signal.h>
  83489. #elif defined FLAC__CPU_PPC
  83490. # if !defined FLAC__NO_ASM
  83491. # if defined FLAC__SYS_DARWIN
  83492. # include <sys/sysctl.h>
  83493. # include <mach/mach.h>
  83494. # include <mach/mach_host.h>
  83495. # include <mach/host_info.h>
  83496. # include <mach/machine.h>
  83497. # ifndef CPU_SUBTYPE_POWERPC_970
  83498. # define CPU_SUBTYPE_POWERPC_970 ((cpu_subtype_t) 100)
  83499. # endif
  83500. # else /* FLAC__SYS_DARWIN */
  83501. # include <signal.h>
  83502. # include <setjmp.h>
  83503. static sigjmp_buf jmpbuf;
  83504. static volatile sig_atomic_t canjump = 0;
  83505. static void sigill_handler (int sig)
  83506. {
  83507. if (!canjump) {
  83508. signal (sig, SIG_DFL);
  83509. raise (sig);
  83510. }
  83511. canjump = 0;
  83512. siglongjmp (jmpbuf, 1);
  83513. }
  83514. # endif /* FLAC__SYS_DARWIN */
  83515. # endif /* FLAC__NO_ASM */
  83516. #endif /* FLAC__CPU_PPC */
  83517. #if defined (__NetBSD__) || defined(__OpenBSD__)
  83518. #include <sys/param.h>
  83519. #include <sys/sysctl.h>
  83520. #include <machine/cpu.h>
  83521. #endif
  83522. #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)
  83523. #include <sys/types.h>
  83524. #include <sys/sysctl.h>
  83525. #endif
  83526. #if defined(__APPLE__)
  83527. #endif
  83528. static const unsigned FLAC__CPUINFO_IA32_CPUID_CMOV = 0x00008000;
  83529. static const unsigned FLAC__CPUINFO_IA32_CPUID_MMX = 0x00800000;
  83530. static const unsigned FLAC__CPUINFO_IA32_CPUID_FXSR = 0x01000000;
  83531. static const unsigned FLAC__CPUINFO_IA32_CPUID_SSE = 0x02000000;
  83532. static const unsigned FLAC__CPUINFO_IA32_CPUID_SSE2 = 0x04000000;
  83533. static const unsigned FLAC__CPUINFO_IA32_CPUID_SSE3 = 0x00000001;
  83534. static const unsigned FLAC__CPUINFO_IA32_CPUID_SSSE3 = 0x00000200;
  83535. static const unsigned FLAC__CPUINFO_IA32_CPUID_EXTENDED_AMD_3DNOW = 0x80000000;
  83536. static const unsigned FLAC__CPUINFO_IA32_CPUID_EXTENDED_AMD_EXT3DNOW = 0x40000000;
  83537. static const unsigned FLAC__CPUINFO_IA32_CPUID_EXTENDED_AMD_EXTMMX = 0x00400000;
  83538. #if defined(FLAC__CPU_IA32) && !defined FLAC__NO_ASM && defined FLAC__HAS_NASM && !defined FLAC__NO_SSE_OS && !defined FLAC__SSE_OS
  83539. # if defined(__linux__)
  83540. # undef USE_OBSOLETE_SIGCONTEXT_FLAVOR /* #define this to use the older signal handler method */
  83541. # ifdef USE_OBSOLETE_SIGCONTEXT_FLAVOR
  83542. static void sigill_handler_sse_os(int signal, struct sigcontext sc)
  83543. {
  83544. (void)signal;
  83545. sc.eip += 3 + 3 + 6;
  83546. }
  83547. # else
  83548. # include <sys/ucontext.h>
  83549. static void sigill_handler_sse_os(int signal, siginfo_t *si, void *uc)
  83550. {
  83551. (void)signal, (void)si;
  83552. ((ucontext_t*)uc)->uc_mcontext.gregs[14/*REG_EIP*/] += 3 + 3 + 6;
  83553. }
  83554. # endif
  83555. # elif defined(_MSC_VER)
  83556. # include <windows.h>
  83557. # undef USE_TRY_CATCH_FLAVOR /* #define this to use the try/catch method for catching illegal opcode exception */
  83558. # ifdef USE_TRY_CATCH_FLAVOR
  83559. # else
  83560. LONG CALLBACK sigill_handler_sse_os(EXCEPTION_POINTERS *ep)
  83561. {
  83562. if(ep->ExceptionRecord->ExceptionCode == EXCEPTION_ILLEGAL_INSTRUCTION) {
  83563. ep->ContextRecord->Eip += 3 + 3 + 6;
  83564. return EXCEPTION_CONTINUE_EXECUTION;
  83565. }
  83566. return EXCEPTION_CONTINUE_SEARCH;
  83567. }
  83568. # endif
  83569. # endif
  83570. #endif
  83571. void FLAC__cpu_info(FLAC__CPUInfo *info)
  83572. {
  83573. #ifdef FLAC__CPU_IA32
  83574. info->type = FLAC__CPUINFO_TYPE_IA32;
  83575. #if !defined FLAC__NO_ASM && defined FLAC__HAS_NASM
  83576. info->use_asm = true; /* we assume a minimum of 80386 with FLAC__CPU_IA32 */
  83577. info->data.ia32.cpuid = FLAC__cpu_have_cpuid_asm_ia32()? true : false;
  83578. info->data.ia32.bswap = info->data.ia32.cpuid; /* CPUID => BSWAP since it came after */
  83579. info->data.ia32.cmov = false;
  83580. info->data.ia32.mmx = false;
  83581. info->data.ia32.fxsr = false;
  83582. info->data.ia32.sse = false;
  83583. info->data.ia32.sse2 = false;
  83584. info->data.ia32.sse3 = false;
  83585. info->data.ia32.ssse3 = false;
  83586. info->data.ia32._3dnow = false;
  83587. info->data.ia32.ext3dnow = false;
  83588. info->data.ia32.extmmx = false;
  83589. if(info->data.ia32.cpuid) {
  83590. FLAC__uint32 flags_edx, flags_ecx;
  83591. FLAC__cpu_info_asm_ia32(&flags_edx, &flags_ecx);
  83592. info->data.ia32.cmov = (flags_edx & FLAC__CPUINFO_IA32_CPUID_CMOV )? true : false;
  83593. info->data.ia32.mmx = (flags_edx & FLAC__CPUINFO_IA32_CPUID_MMX )? true : false;
  83594. info->data.ia32.fxsr = (flags_edx & FLAC__CPUINFO_IA32_CPUID_FXSR )? true : false;
  83595. info->data.ia32.sse = (flags_edx & FLAC__CPUINFO_IA32_CPUID_SSE )? true : false;
  83596. info->data.ia32.sse2 = (flags_edx & FLAC__CPUINFO_IA32_CPUID_SSE2 )? true : false;
  83597. info->data.ia32.sse3 = (flags_ecx & FLAC__CPUINFO_IA32_CPUID_SSE3 )? true : false;
  83598. info->data.ia32.ssse3 = (flags_ecx & FLAC__CPUINFO_IA32_CPUID_SSSE3)? true : false;
  83599. #ifdef FLAC__USE_3DNOW
  83600. flags_edx = FLAC__cpu_info_extended_amd_asm_ia32();
  83601. info->data.ia32._3dnow = (flags_edx & FLAC__CPUINFO_IA32_CPUID_EXTENDED_AMD_3DNOW )? true : false;
  83602. info->data.ia32.ext3dnow = (flags_edx & FLAC__CPUINFO_IA32_CPUID_EXTENDED_AMD_EXT3DNOW)? true : false;
  83603. info->data.ia32.extmmx = (flags_edx & FLAC__CPUINFO_IA32_CPUID_EXTENDED_AMD_EXTMMX )? true : false;
  83604. #else
  83605. info->data.ia32._3dnow = info->data.ia32.ext3dnow = info->data.ia32.extmmx = false;
  83606. #endif
  83607. #ifdef DEBUG
  83608. fprintf(stderr, "CPU info (IA-32):\n");
  83609. fprintf(stderr, " CPUID ...... %c\n", info->data.ia32.cpuid ? 'Y' : 'n');
  83610. fprintf(stderr, " BSWAP ...... %c\n", info->data.ia32.bswap ? 'Y' : 'n');
  83611. fprintf(stderr, " CMOV ....... %c\n", info->data.ia32.cmov ? 'Y' : 'n');
  83612. fprintf(stderr, " MMX ........ %c\n", info->data.ia32.mmx ? 'Y' : 'n');
  83613. fprintf(stderr, " FXSR ....... %c\n", info->data.ia32.fxsr ? 'Y' : 'n');
  83614. fprintf(stderr, " SSE ........ %c\n", info->data.ia32.sse ? 'Y' : 'n');
  83615. fprintf(stderr, " SSE2 ....... %c\n", info->data.ia32.sse2 ? 'Y' : 'n');
  83616. fprintf(stderr, " SSE3 ....... %c\n", info->data.ia32.sse3 ? 'Y' : 'n');
  83617. fprintf(stderr, " SSSE3 ...... %c\n", info->data.ia32.ssse3 ? 'Y' : 'n');
  83618. fprintf(stderr, " 3DNow! ..... %c\n", info->data.ia32._3dnow ? 'Y' : 'n');
  83619. fprintf(stderr, " 3DNow!-ext . %c\n", info->data.ia32.ext3dnow? 'Y' : 'n');
  83620. fprintf(stderr, " 3DNow!-MMX . %c\n", info->data.ia32.extmmx ? 'Y' : 'n');
  83621. #endif
  83622. if(info->data.ia32.fxsr || info->data.ia32.sse || info->data.ia32.sse2) {
  83623. #if defined FLAC__NO_SSE_OS
  83624. info->data.ia32.fxsr = info->data.ia32.sse = info->data.ia32.sse2 = info->data.ia32.sse3 = info->data.ia32.ssse3 = false;
  83625. #elif defined FLAC__SSE_OS
  83626. #elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__) || defined(__APPLE__)
  83627. int sse = 0;
  83628. size_t len;
  83629. len = sizeof(sse); sse = sse || (sysctlbyname("hw.instruction_sse", &sse, &len, NULL, 0) == 0 && sse);
  83630. len = sizeof(sse); sse = sse || (sysctlbyname("hw.optional.sse" , &sse, &len, NULL, 0) == 0 && sse); /* __APPLE__ ? */
  83631. if(!sse)
  83632. info->data.ia32.fxsr = info->data.ia32.sse = info->data.ia32.sse2 = info->data.ia32.sse3 = info->data.ia32.ssse3 = false;
  83633. #elif defined(__NetBSD__) || defined (__OpenBSD__)
  83634. # if __NetBSD_Version__ >= 105250000 || (defined __OpenBSD__)
  83635. int val = 0, mib[2] = { CTL_MACHDEP, CPU_SSE };
  83636. size_t len = sizeof(val);
  83637. if(sysctl(mib, 2, &val, &len, NULL, 0) < 0 || !val)
  83638. info->data.ia32.fxsr = info->data.ia32.sse = info->data.ia32.sse2 = info->data.ia32.sse3 = info->data.ia32.ssse3 = false;
  83639. else { /* double-check SSE2 */
  83640. mib[1] = CPU_SSE2;
  83641. len = sizeof(val);
  83642. if(sysctl(mib, 2, &val, &len, NULL, 0) < 0 || !val)
  83643. info->data.ia32.sse2 = info->data.ia32.sse3 = info->data.ia32.ssse3 = false;
  83644. }
  83645. # else
  83646. info->data.ia32.fxsr = info->data.ia32.sse = info->data.ia32.sse2 = info->data.ia32.sse3 = info->data.ia32.ssse3 = false;
  83647. # endif
  83648. #elif defined(__linux__)
  83649. int sse = 0;
  83650. struct sigaction sigill_save;
  83651. #ifdef USE_OBSOLETE_SIGCONTEXT_FLAVOR
  83652. if(0 == sigaction(SIGILL, NULL, &sigill_save) && signal(SIGILL, (void (*)(int))sigill_handler_sse_os) != SIG_ERR)
  83653. #else
  83654. struct sigaction sigill_sse;
  83655. sigill_sse.sa_sigaction = sigill_handler_sse_os;
  83656. __sigemptyset(&sigill_sse.sa_mask);
  83657. 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 */
  83658. if(0 == sigaction(SIGILL, &sigill_sse, &sigill_save))
  83659. #endif
  83660. {
  83661. asm volatile (
  83662. "xorl %0,%0\n\t" /* for some reason, still need to do this to clear 'sse' var */
  83663. "xorps %%xmm0,%%xmm0\n\t" /* will cause SIGILL if unsupported by OS */
  83664. "incl %0\n\t" /* SIGILL handler will jump over this */
  83665. "nop\n\t" /* SIGILL jump lands here if "inc" is 9 bytes */
  83666. "nop\n\t"
  83667. "nop\n\t"
  83668. "nop\n\t"
  83669. "nop\n\t"
  83670. "nop\n\t"
  83671. "nop\n\t" /* SIGILL jump lands here if "inc" is 3 bytes (expected) */
  83672. "nop\n\t"
  83673. "nop" /* SIGILL jump lands here if "inc" is 1 byte */
  83674. : "=r"(sse)
  83675. : "r"(sse)
  83676. );
  83677. sigaction(SIGILL, &sigill_save, NULL);
  83678. }
  83679. if(!sse)
  83680. info->data.ia32.fxsr = info->data.ia32.sse = info->data.ia32.sse2 = info->data.ia32.sse3 = info->data.ia32.ssse3 = false;
  83681. #elif defined(_MSC_VER)
  83682. # ifdef USE_TRY_CATCH_FLAVOR
  83683. _try {
  83684. __asm {
  83685. # if _MSC_VER <= 1200
  83686. _emit 0x0F
  83687. _emit 0x57
  83688. _emit 0xC0
  83689. # else
  83690. xorps xmm0,xmm0
  83691. # endif
  83692. }
  83693. }
  83694. _except(EXCEPTION_EXECUTE_HANDLER) {
  83695. if (_exception_code() == STATUS_ILLEGAL_INSTRUCTION)
  83696. info->data.ia32.fxsr = info->data.ia32.sse = info->data.ia32.sse2 = info->data.ia32.sse3 = info->data.ia32.ssse3 = false;
  83697. }
  83698. # else
  83699. int sse = 0;
  83700. LPTOP_LEVEL_EXCEPTION_FILTER save = SetUnhandledExceptionFilter(sigill_handler_sse_os);
  83701. __asm {
  83702. # if _MSC_VER <= 1200
  83703. _emit 0x0F
  83704. _emit 0x57
  83705. _emit 0xC0
  83706. # else
  83707. xorps xmm0,xmm0
  83708. # endif
  83709. inc sse
  83710. nop
  83711. nop
  83712. nop
  83713. nop
  83714. nop
  83715. nop
  83716. nop
  83717. nop
  83718. nop
  83719. }
  83720. SetUnhandledExceptionFilter(save);
  83721. if(!sse)
  83722. info->data.ia32.fxsr = info->data.ia32.sse = info->data.ia32.sse2 = info->data.ia32.sse3 = info->data.ia32.ssse3 = false;
  83723. # endif
  83724. #else
  83725. info->data.ia32.fxsr = info->data.ia32.sse = info->data.ia32.sse2 = info->data.ia32.sse3 = info->data.ia32.ssse3 = false;
  83726. #endif
  83727. #ifdef DEBUG
  83728. fprintf(stderr, " SSE OS sup . %c\n", info->data.ia32.sse ? 'Y' : 'n');
  83729. #endif
  83730. }
  83731. }
  83732. #else
  83733. info->use_asm = false;
  83734. #endif
  83735. #elif defined FLAC__CPU_PPC
  83736. info->type = FLAC__CPUINFO_TYPE_PPC;
  83737. # if !defined FLAC__NO_ASM
  83738. info->use_asm = true;
  83739. # ifdef FLAC__USE_ALTIVEC
  83740. # if defined FLAC__SYS_DARWIN
  83741. {
  83742. int val = 0, mib[2] = { CTL_HW, HW_VECTORUNIT };
  83743. size_t len = sizeof(val);
  83744. info->data.ppc.altivec = !(sysctl(mib, 2, &val, &len, NULL, 0) || !val);
  83745. }
  83746. {
  83747. host_basic_info_data_t hostInfo;
  83748. mach_msg_type_number_t infoCount;
  83749. infoCount = HOST_BASIC_INFO_COUNT;
  83750. host_info(mach_host_self(), HOST_BASIC_INFO, (host_info_t)&hostInfo, &infoCount);
  83751. info->data.ppc.ppc64 = (hostInfo.cpu_type == CPU_TYPE_POWERPC) && (hostInfo.cpu_subtype == CPU_SUBTYPE_POWERPC_970);
  83752. }
  83753. # else /* FLAC__USE_ALTIVEC && !FLAC__SYS_DARWIN */
  83754. {
  83755. info->data.ppc.altivec = 0;
  83756. info->data.ppc.ppc64 = 0;
  83757. signal (SIGILL, sigill_handler);
  83758. canjump = 0;
  83759. if (!sigsetjmp (jmpbuf, 1)) {
  83760. canjump = 1;
  83761. asm volatile (
  83762. "mtspr 256, %0\n\t"
  83763. "vand %%v0, %%v0, %%v0"
  83764. :
  83765. : "r" (-1)
  83766. );
  83767. info->data.ppc.altivec = 1;
  83768. }
  83769. canjump = 0;
  83770. if (!sigsetjmp (jmpbuf, 1)) {
  83771. int x = 0;
  83772. canjump = 1;
  83773. asm volatile ("cntlzd %0, %1" : "=r" (x) : "r" (x) );
  83774. info->data.ppc.ppc64 = 1;
  83775. }
  83776. signal (SIGILL, SIG_DFL); /*@@@@@@ should save and restore old signal */
  83777. }
  83778. # endif
  83779. # else /* !FLAC__USE_ALTIVEC */
  83780. info->data.ppc.altivec = 0;
  83781. info->data.ppc.ppc64 = 0;
  83782. # endif
  83783. # else
  83784. info->use_asm = false;
  83785. # endif
  83786. #else
  83787. info->type = FLAC__CPUINFO_TYPE_UNKNOWN;
  83788. info->use_asm = false;
  83789. #endif
  83790. }
  83791. #endif
  83792. /*** End of inlined file: cpu.c ***/
  83793. /*** Start of inlined file: crc.c ***/
  83794. /*** Start of inlined file: juce_FlacHeader.h ***/
  83795. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  83796. // tasks..
  83797. #define VERSION "1.2.1"
  83798. #define FLAC__NO_DLL 1
  83799. #if JUCE_MSVC
  83800. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  83801. #endif
  83802. #if JUCE_MAC
  83803. #define FLAC__SYS_DARWIN 1
  83804. #endif
  83805. /*** End of inlined file: juce_FlacHeader.h ***/
  83806. #if JUCE_USE_FLAC
  83807. #if HAVE_CONFIG_H
  83808. # include <config.h>
  83809. #endif
  83810. FLAC__byte const FLAC__crc8_table[256] = {
  83811. 0x00, 0x07, 0x0E, 0x09, 0x1C, 0x1B, 0x12, 0x15,
  83812. 0x38, 0x3F, 0x36, 0x31, 0x24, 0x23, 0x2A, 0x2D,
  83813. 0x70, 0x77, 0x7E, 0x79, 0x6C, 0x6B, 0x62, 0x65,
  83814. 0x48, 0x4F, 0x46, 0x41, 0x54, 0x53, 0x5A, 0x5D,
  83815. 0xE0, 0xE7, 0xEE, 0xE9, 0xFC, 0xFB, 0xF2, 0xF5,
  83816. 0xD8, 0xDF, 0xD6, 0xD1, 0xC4, 0xC3, 0xCA, 0xCD,
  83817. 0x90, 0x97, 0x9E, 0x99, 0x8C, 0x8B, 0x82, 0x85,
  83818. 0xA8, 0xAF, 0xA6, 0xA1, 0xB4, 0xB3, 0xBA, 0xBD,
  83819. 0xC7, 0xC0, 0xC9, 0xCE, 0xDB, 0xDC, 0xD5, 0xD2,
  83820. 0xFF, 0xF8, 0xF1, 0xF6, 0xE3, 0xE4, 0xED, 0xEA,
  83821. 0xB7, 0xB0, 0xB9, 0xBE, 0xAB, 0xAC, 0xA5, 0xA2,
  83822. 0x8F, 0x88, 0x81, 0x86, 0x93, 0x94, 0x9D, 0x9A,
  83823. 0x27, 0x20, 0x29, 0x2E, 0x3B, 0x3C, 0x35, 0x32,
  83824. 0x1F, 0x18, 0x11, 0x16, 0x03, 0x04, 0x0D, 0x0A,
  83825. 0x57, 0x50, 0x59, 0x5E, 0x4B, 0x4C, 0x45, 0x42,
  83826. 0x6F, 0x68, 0x61, 0x66, 0x73, 0x74, 0x7D, 0x7A,
  83827. 0x89, 0x8E, 0x87, 0x80, 0x95, 0x92, 0x9B, 0x9C,
  83828. 0xB1, 0xB6, 0xBF, 0xB8, 0xAD, 0xAA, 0xA3, 0xA4,
  83829. 0xF9, 0xFE, 0xF7, 0xF0, 0xE5, 0xE2, 0xEB, 0xEC,
  83830. 0xC1, 0xC6, 0xCF, 0xC8, 0xDD, 0xDA, 0xD3, 0xD4,
  83831. 0x69, 0x6E, 0x67, 0x60, 0x75, 0x72, 0x7B, 0x7C,
  83832. 0x51, 0x56, 0x5F, 0x58, 0x4D, 0x4A, 0x43, 0x44,
  83833. 0x19, 0x1E, 0x17, 0x10, 0x05, 0x02, 0x0B, 0x0C,
  83834. 0x21, 0x26, 0x2F, 0x28, 0x3D, 0x3A, 0x33, 0x34,
  83835. 0x4E, 0x49, 0x40, 0x47, 0x52, 0x55, 0x5C, 0x5B,
  83836. 0x76, 0x71, 0x78, 0x7F, 0x6A, 0x6D, 0x64, 0x63,
  83837. 0x3E, 0x39, 0x30, 0x37, 0x22, 0x25, 0x2C, 0x2B,
  83838. 0x06, 0x01, 0x08, 0x0F, 0x1A, 0x1D, 0x14, 0x13,
  83839. 0xAE, 0xA9, 0xA0, 0xA7, 0xB2, 0xB5, 0xBC, 0xBB,
  83840. 0x96, 0x91, 0x98, 0x9F, 0x8A, 0x8D, 0x84, 0x83,
  83841. 0xDE, 0xD9, 0xD0, 0xD7, 0xC2, 0xC5, 0xCC, 0xCB,
  83842. 0xE6, 0xE1, 0xE8, 0xEF, 0xFA, 0xFD, 0xF4, 0xF3
  83843. };
  83844. unsigned FLAC__crc16_table[256] = {
  83845. 0x0000, 0x8005, 0x800f, 0x000a, 0x801b, 0x001e, 0x0014, 0x8011,
  83846. 0x8033, 0x0036, 0x003c, 0x8039, 0x0028, 0x802d, 0x8027, 0x0022,
  83847. 0x8063, 0x0066, 0x006c, 0x8069, 0x0078, 0x807d, 0x8077, 0x0072,
  83848. 0x0050, 0x8055, 0x805f, 0x005a, 0x804b, 0x004e, 0x0044, 0x8041,
  83849. 0x80c3, 0x00c6, 0x00cc, 0x80c9, 0x00d8, 0x80dd, 0x80d7, 0x00d2,
  83850. 0x00f0, 0x80f5, 0x80ff, 0x00fa, 0x80eb, 0x00ee, 0x00e4, 0x80e1,
  83851. 0x00a0, 0x80a5, 0x80af, 0x00aa, 0x80bb, 0x00be, 0x00b4, 0x80b1,
  83852. 0x8093, 0x0096, 0x009c, 0x8099, 0x0088, 0x808d, 0x8087, 0x0082,
  83853. 0x8183, 0x0186, 0x018c, 0x8189, 0x0198, 0x819d, 0x8197, 0x0192,
  83854. 0x01b0, 0x81b5, 0x81bf, 0x01ba, 0x81ab, 0x01ae, 0x01a4, 0x81a1,
  83855. 0x01e0, 0x81e5, 0x81ef, 0x01ea, 0x81fb, 0x01fe, 0x01f4, 0x81f1,
  83856. 0x81d3, 0x01d6, 0x01dc, 0x81d9, 0x01c8, 0x81cd, 0x81c7, 0x01c2,
  83857. 0x0140, 0x8145, 0x814f, 0x014a, 0x815b, 0x015e, 0x0154, 0x8151,
  83858. 0x8173, 0x0176, 0x017c, 0x8179, 0x0168, 0x816d, 0x8167, 0x0162,
  83859. 0x8123, 0x0126, 0x012c, 0x8129, 0x0138, 0x813d, 0x8137, 0x0132,
  83860. 0x0110, 0x8115, 0x811f, 0x011a, 0x810b, 0x010e, 0x0104, 0x8101,
  83861. 0x8303, 0x0306, 0x030c, 0x8309, 0x0318, 0x831d, 0x8317, 0x0312,
  83862. 0x0330, 0x8335, 0x833f, 0x033a, 0x832b, 0x032e, 0x0324, 0x8321,
  83863. 0x0360, 0x8365, 0x836f, 0x036a, 0x837b, 0x037e, 0x0374, 0x8371,
  83864. 0x8353, 0x0356, 0x035c, 0x8359, 0x0348, 0x834d, 0x8347, 0x0342,
  83865. 0x03c0, 0x83c5, 0x83cf, 0x03ca, 0x83db, 0x03de, 0x03d4, 0x83d1,
  83866. 0x83f3, 0x03f6, 0x03fc, 0x83f9, 0x03e8, 0x83ed, 0x83e7, 0x03e2,
  83867. 0x83a3, 0x03a6, 0x03ac, 0x83a9, 0x03b8, 0x83bd, 0x83b7, 0x03b2,
  83868. 0x0390, 0x8395, 0x839f, 0x039a, 0x838b, 0x038e, 0x0384, 0x8381,
  83869. 0x0280, 0x8285, 0x828f, 0x028a, 0x829b, 0x029e, 0x0294, 0x8291,
  83870. 0x82b3, 0x02b6, 0x02bc, 0x82b9, 0x02a8, 0x82ad, 0x82a7, 0x02a2,
  83871. 0x82e3, 0x02e6, 0x02ec, 0x82e9, 0x02f8, 0x82fd, 0x82f7, 0x02f2,
  83872. 0x02d0, 0x82d5, 0x82df, 0x02da, 0x82cb, 0x02ce, 0x02c4, 0x82c1,
  83873. 0x8243, 0x0246, 0x024c, 0x8249, 0x0258, 0x825d, 0x8257, 0x0252,
  83874. 0x0270, 0x8275, 0x827f, 0x027a, 0x826b, 0x026e, 0x0264, 0x8261,
  83875. 0x0220, 0x8225, 0x822f, 0x022a, 0x823b, 0x023e, 0x0234, 0x8231,
  83876. 0x8213, 0x0216, 0x021c, 0x8219, 0x0208, 0x820d, 0x8207, 0x0202
  83877. };
  83878. void FLAC__crc8_update(const FLAC__byte data, FLAC__uint8 *crc)
  83879. {
  83880. *crc = FLAC__crc8_table[*crc ^ data];
  83881. }
  83882. void FLAC__crc8_update_block(const FLAC__byte *data, unsigned len, FLAC__uint8 *crc)
  83883. {
  83884. while(len--)
  83885. *crc = FLAC__crc8_table[*crc ^ *data++];
  83886. }
  83887. FLAC__uint8 FLAC__crc8(const FLAC__byte *data, unsigned len)
  83888. {
  83889. FLAC__uint8 crc = 0;
  83890. while(len--)
  83891. crc = FLAC__crc8_table[crc ^ *data++];
  83892. return crc;
  83893. }
  83894. unsigned FLAC__crc16(const FLAC__byte *data, unsigned len)
  83895. {
  83896. unsigned crc = 0;
  83897. while(len--)
  83898. crc = ((crc<<8) ^ FLAC__crc16_table[(crc>>8) ^ *data++]) & 0xffff;
  83899. return crc;
  83900. }
  83901. #endif
  83902. /*** End of inlined file: crc.c ***/
  83903. /*** Start of inlined file: fixed.c ***/
  83904. /*** Start of inlined file: juce_FlacHeader.h ***/
  83905. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  83906. // tasks..
  83907. #define VERSION "1.2.1"
  83908. #define FLAC__NO_DLL 1
  83909. #if JUCE_MSVC
  83910. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  83911. #endif
  83912. #if JUCE_MAC
  83913. #define FLAC__SYS_DARWIN 1
  83914. #endif
  83915. /*** End of inlined file: juce_FlacHeader.h ***/
  83916. #if JUCE_USE_FLAC
  83917. #if HAVE_CONFIG_H
  83918. # include <config.h>
  83919. #endif
  83920. #include <math.h>
  83921. #include <string.h>
  83922. /*** Start of inlined file: fixed.h ***/
  83923. #ifndef FLAC__PRIVATE__FIXED_H
  83924. #define FLAC__PRIVATE__FIXED_H
  83925. #ifdef HAVE_CONFIG_H
  83926. #include <config.h>
  83927. #endif
  83928. /*** Start of inlined file: float.h ***/
  83929. #ifndef FLAC__PRIVATE__FLOAT_H
  83930. #define FLAC__PRIVATE__FLOAT_H
  83931. #ifdef HAVE_CONFIG_H
  83932. #include <config.h>
  83933. #endif
  83934. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  83935. typedef double FLAC__double;
  83936. typedef float FLAC__float;
  83937. typedef float FLAC__real;
  83938. #else
  83939. typedef FLAC__int32 FLAC__fixedpoint;
  83940. extern const FLAC__fixedpoint FLAC__FP_ZERO;
  83941. extern const FLAC__fixedpoint FLAC__FP_ONE_HALF;
  83942. extern const FLAC__fixedpoint FLAC__FP_ONE;
  83943. extern const FLAC__fixedpoint FLAC__FP_LN2;
  83944. extern const FLAC__fixedpoint FLAC__FP_E;
  83945. #define FLAC__fixedpoint_trunc(x) ((x)>>16)
  83946. #define FLAC__fixedpoint_mul(x, y) ( (FLAC__fixedpoint) ( ((FLAC__int64)(x)*(FLAC__int64)(y)) >> 16 ) )
  83947. #define FLAC__fixedpoint_div(x, y) ( (FLAC__fixedpoint) ( ( ((FLAC__int64)(x)<<32) / (FLAC__int64)(y) ) >> 16 ) )
  83948. FLAC__uint32 FLAC__fixedpoint_log2(FLAC__uint32 x, unsigned fracbits, unsigned precision);
  83949. #endif
  83950. #endif
  83951. /*** End of inlined file: float.h ***/
  83952. /*** Start of inlined file: format.h ***/
  83953. #ifndef FLAC__PRIVATE__FORMAT_H
  83954. #define FLAC__PRIVATE__FORMAT_H
  83955. unsigned FLAC__format_get_max_rice_partition_order(unsigned blocksize, unsigned predictor_order);
  83956. unsigned FLAC__format_get_max_rice_partition_order_from_blocksize(unsigned blocksize);
  83957. unsigned FLAC__format_get_max_rice_partition_order_from_blocksize_limited_max_and_predictor_order(unsigned limit, unsigned blocksize, unsigned predictor_order);
  83958. void FLAC__format_entropy_coding_method_partitioned_rice_contents_init(FLAC__EntropyCodingMethod_PartitionedRiceContents *object);
  83959. void FLAC__format_entropy_coding_method_partitioned_rice_contents_clear(FLAC__EntropyCodingMethod_PartitionedRiceContents *object);
  83960. FLAC__bool FLAC__format_entropy_coding_method_partitioned_rice_contents_ensure_size(FLAC__EntropyCodingMethod_PartitionedRiceContents *object, unsigned max_partition_order);
  83961. #endif
  83962. /*** End of inlined file: format.h ***/
  83963. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  83964. unsigned FLAC__fixed_compute_best_predictor(const FLAC__int32 data[], unsigned data_len, FLAC__float residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1]);
  83965. # ifndef FLAC__NO_ASM
  83966. # ifdef FLAC__CPU_IA32
  83967. # ifdef FLAC__HAS_NASM
  83968. 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]);
  83969. # endif
  83970. # endif
  83971. # endif
  83972. 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]);
  83973. #else
  83974. unsigned FLAC__fixed_compute_best_predictor(const FLAC__int32 data[], unsigned data_len, FLAC__fixedpoint residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1]);
  83975. 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]);
  83976. #endif
  83977. void FLAC__fixed_compute_residual(const FLAC__int32 data[], unsigned data_len, unsigned order, FLAC__int32 residual[]);
  83978. void FLAC__fixed_restore_signal(const FLAC__int32 residual[], unsigned data_len, unsigned order, FLAC__int32 data[]);
  83979. #endif
  83980. /*** End of inlined file: fixed.h ***/
  83981. #ifndef M_LN2
  83982. #define M_LN2 0.69314718055994530942
  83983. #endif
  83984. #ifdef min
  83985. #undef min
  83986. #endif
  83987. #define min(x,y) ((x) < (y)? (x) : (y))
  83988. #ifdef local_abs
  83989. #undef local_abs
  83990. #endif
  83991. #define local_abs(x) ((unsigned)((x)<0? -(x) : (x)))
  83992. #ifdef FLAC__INTEGER_ONLY_LIBRARY
  83993. static FLAC__fixedpoint local__compute_rbps_integerized(FLAC__uint32 err, FLAC__uint32 n)
  83994. {
  83995. FLAC__uint32 rbps;
  83996. unsigned bits; /* the number of bits required to represent a number */
  83997. int fracbits; /* the number of bits of rbps that comprise the fractional part */
  83998. FLAC__ASSERT(sizeof(rbps) == sizeof(FLAC__fixedpoint));
  83999. FLAC__ASSERT(err > 0);
  84000. FLAC__ASSERT(n > 0);
  84001. FLAC__ASSERT(n <= FLAC__MAX_BLOCK_SIZE);
  84002. if(err <= n)
  84003. return 0;
  84004. fracbits = (8*sizeof(err)) - (FLAC__bitmath_ilog2(err)+1);
  84005. err <<= fracbits;
  84006. err /= n;
  84007. FLAC__ASSERT(err > 0);
  84008. bits = FLAC__bitmath_ilog2(err)+1;
  84009. if(bits > 16) {
  84010. err >>= (bits-16);
  84011. fracbits -= (bits-16);
  84012. }
  84013. rbps = (FLAC__uint32)err;
  84014. rbps *= FLAC__FP_LN2;
  84015. fracbits += 16;
  84016. FLAC__ASSERT(fracbits >= 0);
  84017. {
  84018. const int f = fracbits & 3;
  84019. if(f) {
  84020. rbps >>= f;
  84021. fracbits -= f;
  84022. }
  84023. }
  84024. rbps = FLAC__fixedpoint_log2(rbps, fracbits, (unsigned)(-1));
  84025. if(rbps == 0)
  84026. return 0;
  84027. FLAC__ASSERT((int)FLAC__bitmath_ilog2(rbps)+1 <= fracbits + 6);
  84028. FLAC__ASSERT(fracbits >= -3);
  84029. if(fracbits < 16)
  84030. return rbps << (16-fracbits);
  84031. else if(fracbits > 16)
  84032. return rbps >> (fracbits-16);
  84033. else
  84034. return rbps;
  84035. }
  84036. static FLAC__fixedpoint local__compute_rbps_wide_integerized(FLAC__uint64 err, FLAC__uint32 n)
  84037. {
  84038. FLAC__uint32 rbps;
  84039. unsigned bits; /* the number of bits required to represent a number */
  84040. int fracbits; /* the number of bits of rbps that comprise the fractional part */
  84041. FLAC__ASSERT(sizeof(rbps) == sizeof(FLAC__fixedpoint));
  84042. FLAC__ASSERT(err > 0);
  84043. FLAC__ASSERT(n > 0);
  84044. FLAC__ASSERT(n <= FLAC__MAX_BLOCK_SIZE);
  84045. if(err <= n)
  84046. return 0;
  84047. fracbits = (8*sizeof(err)) - (FLAC__bitmath_ilog2_wide(err)+1);
  84048. err <<= fracbits;
  84049. err /= n;
  84050. FLAC__ASSERT(err > 0);
  84051. bits = FLAC__bitmath_ilog2_wide(err)+1;
  84052. if(bits > 16) {
  84053. err >>= (bits-16);
  84054. fracbits -= (bits-16);
  84055. }
  84056. rbps = (FLAC__uint32)err;
  84057. rbps *= FLAC__FP_LN2;
  84058. fracbits += 16;
  84059. FLAC__ASSERT(fracbits >= 0);
  84060. {
  84061. const int f = fracbits & 3;
  84062. if(f) {
  84063. rbps >>= f;
  84064. fracbits -= f;
  84065. }
  84066. }
  84067. rbps = FLAC__fixedpoint_log2(rbps, fracbits, (unsigned)(-1));
  84068. if(rbps == 0)
  84069. return 0;
  84070. FLAC__ASSERT((int)FLAC__bitmath_ilog2(rbps)+1 <= fracbits + 6);
  84071. FLAC__ASSERT(fracbits >= -3);
  84072. if(fracbits < 16)
  84073. return rbps << (16-fracbits);
  84074. else if(fracbits > 16)
  84075. return rbps >> (fracbits-16);
  84076. else
  84077. return rbps;
  84078. }
  84079. #endif
  84080. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  84081. unsigned FLAC__fixed_compute_best_predictor(const FLAC__int32 data[], unsigned data_len, FLAC__float residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1])
  84082. #else
  84083. unsigned FLAC__fixed_compute_best_predictor(const FLAC__int32 data[], unsigned data_len, FLAC__fixedpoint residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1])
  84084. #endif
  84085. {
  84086. FLAC__int32 last_error_0 = data[-1];
  84087. FLAC__int32 last_error_1 = data[-1] - data[-2];
  84088. FLAC__int32 last_error_2 = last_error_1 - (data[-2] - data[-3]);
  84089. FLAC__int32 last_error_3 = last_error_2 - (data[-2] - 2*data[-3] + data[-4]);
  84090. FLAC__int32 error, save;
  84091. FLAC__uint32 total_error_0 = 0, total_error_1 = 0, total_error_2 = 0, total_error_3 = 0, total_error_4 = 0;
  84092. unsigned i, order;
  84093. for(i = 0; i < data_len; i++) {
  84094. error = data[i] ; total_error_0 += local_abs(error); save = error;
  84095. error -= last_error_0; total_error_1 += local_abs(error); last_error_0 = save; save = error;
  84096. error -= last_error_1; total_error_2 += local_abs(error); last_error_1 = save; save = error;
  84097. error -= last_error_2; total_error_3 += local_abs(error); last_error_2 = save; save = error;
  84098. error -= last_error_3; total_error_4 += local_abs(error); last_error_3 = save;
  84099. }
  84100. if(total_error_0 < min(min(min(total_error_1, total_error_2), total_error_3), total_error_4))
  84101. order = 0;
  84102. else if(total_error_1 < min(min(total_error_2, total_error_3), total_error_4))
  84103. order = 1;
  84104. else if(total_error_2 < min(total_error_3, total_error_4))
  84105. order = 2;
  84106. else if(total_error_3 < total_error_4)
  84107. order = 3;
  84108. else
  84109. order = 4;
  84110. FLAC__ASSERT(data_len > 0 || total_error_0 == 0);
  84111. FLAC__ASSERT(data_len > 0 || total_error_1 == 0);
  84112. FLAC__ASSERT(data_len > 0 || total_error_2 == 0);
  84113. FLAC__ASSERT(data_len > 0 || total_error_3 == 0);
  84114. FLAC__ASSERT(data_len > 0 || total_error_4 == 0);
  84115. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  84116. 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);
  84117. 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);
  84118. 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);
  84119. 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);
  84120. 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);
  84121. #else
  84122. residual_bits_per_sample[0] = (total_error_0 > 0) ? local__compute_rbps_integerized(total_error_0, data_len) : 0;
  84123. residual_bits_per_sample[1] = (total_error_1 > 0) ? local__compute_rbps_integerized(total_error_1, data_len) : 0;
  84124. residual_bits_per_sample[2] = (total_error_2 > 0) ? local__compute_rbps_integerized(total_error_2, data_len) : 0;
  84125. residual_bits_per_sample[3] = (total_error_3 > 0) ? local__compute_rbps_integerized(total_error_3, data_len) : 0;
  84126. residual_bits_per_sample[4] = (total_error_4 > 0) ? local__compute_rbps_integerized(total_error_4, data_len) : 0;
  84127. #endif
  84128. return order;
  84129. }
  84130. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  84131. 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])
  84132. #else
  84133. 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])
  84134. #endif
  84135. {
  84136. FLAC__int32 last_error_0 = data[-1];
  84137. FLAC__int32 last_error_1 = data[-1] - data[-2];
  84138. FLAC__int32 last_error_2 = last_error_1 - (data[-2] - data[-3]);
  84139. FLAC__int32 last_error_3 = last_error_2 - (data[-2] - 2*data[-3] + data[-4]);
  84140. FLAC__int32 error, save;
  84141. FLAC__uint64 total_error_0 = 0, total_error_1 = 0, total_error_2 = 0, total_error_3 = 0, total_error_4 = 0;
  84142. unsigned i, order;
  84143. for(i = 0; i < data_len; i++) {
  84144. error = data[i] ; total_error_0 += local_abs(error); save = error;
  84145. error -= last_error_0; total_error_1 += local_abs(error); last_error_0 = save; save = error;
  84146. error -= last_error_1; total_error_2 += local_abs(error); last_error_1 = save; save = error;
  84147. error -= last_error_2; total_error_3 += local_abs(error); last_error_2 = save; save = error;
  84148. error -= last_error_3; total_error_4 += local_abs(error); last_error_3 = save;
  84149. }
  84150. if(total_error_0 < min(min(min(total_error_1, total_error_2), total_error_3), total_error_4))
  84151. order = 0;
  84152. else if(total_error_1 < min(min(total_error_2, total_error_3), total_error_4))
  84153. order = 1;
  84154. else if(total_error_2 < min(total_error_3, total_error_4))
  84155. order = 2;
  84156. else if(total_error_3 < total_error_4)
  84157. order = 3;
  84158. else
  84159. order = 4;
  84160. FLAC__ASSERT(data_len > 0 || total_error_0 == 0);
  84161. FLAC__ASSERT(data_len > 0 || total_error_1 == 0);
  84162. FLAC__ASSERT(data_len > 0 || total_error_2 == 0);
  84163. FLAC__ASSERT(data_len > 0 || total_error_3 == 0);
  84164. FLAC__ASSERT(data_len > 0 || total_error_4 == 0);
  84165. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  84166. #if defined _MSC_VER || defined __MINGW32__
  84167. 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);
  84168. 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);
  84169. 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);
  84170. 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);
  84171. 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);
  84172. #else
  84173. 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);
  84174. 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);
  84175. 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);
  84176. 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);
  84177. 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);
  84178. #endif
  84179. #else
  84180. residual_bits_per_sample[0] = (total_error_0 > 0) ? local__compute_rbps_wide_integerized(total_error_0, data_len) : 0;
  84181. residual_bits_per_sample[1] = (total_error_1 > 0) ? local__compute_rbps_wide_integerized(total_error_1, data_len) : 0;
  84182. residual_bits_per_sample[2] = (total_error_2 > 0) ? local__compute_rbps_wide_integerized(total_error_2, data_len) : 0;
  84183. residual_bits_per_sample[3] = (total_error_3 > 0) ? local__compute_rbps_wide_integerized(total_error_3, data_len) : 0;
  84184. residual_bits_per_sample[4] = (total_error_4 > 0) ? local__compute_rbps_wide_integerized(total_error_4, data_len) : 0;
  84185. #endif
  84186. return order;
  84187. }
  84188. void FLAC__fixed_compute_residual(const FLAC__int32 data[], unsigned data_len, unsigned order, FLAC__int32 residual[])
  84189. {
  84190. const int idata_len = (int)data_len;
  84191. int i;
  84192. switch(order) {
  84193. case 0:
  84194. FLAC__ASSERT(sizeof(residual[0]) == sizeof(data[0]));
  84195. memcpy(residual, data, sizeof(residual[0])*data_len);
  84196. break;
  84197. case 1:
  84198. for(i = 0; i < idata_len; i++)
  84199. residual[i] = data[i] - data[i-1];
  84200. break;
  84201. case 2:
  84202. for(i = 0; i < idata_len; i++)
  84203. #if 1 /* OPT: may be faster with some compilers on some systems */
  84204. residual[i] = data[i] - (data[i-1] << 1) + data[i-2];
  84205. #else
  84206. residual[i] = data[i] - 2*data[i-1] + data[i-2];
  84207. #endif
  84208. break;
  84209. case 3:
  84210. for(i = 0; i < idata_len; i++)
  84211. #if 1 /* OPT: may be faster with some compilers on some systems */
  84212. residual[i] = data[i] - (((data[i-1]-data[i-2])<<1) + (data[i-1]-data[i-2])) - data[i-3];
  84213. #else
  84214. residual[i] = data[i] - 3*data[i-1] + 3*data[i-2] - data[i-3];
  84215. #endif
  84216. break;
  84217. case 4:
  84218. for(i = 0; i < idata_len; i++)
  84219. #if 1 /* OPT: may be faster with some compilers on some systems */
  84220. residual[i] = data[i] - ((data[i-1]+data[i-3])<<2) + ((data[i-2]<<2) + (data[i-2]<<1)) + data[i-4];
  84221. #else
  84222. residual[i] = data[i] - 4*data[i-1] + 6*data[i-2] - 4*data[i-3] + data[i-4];
  84223. #endif
  84224. break;
  84225. default:
  84226. FLAC__ASSERT(0);
  84227. }
  84228. }
  84229. void FLAC__fixed_restore_signal(const FLAC__int32 residual[], unsigned data_len, unsigned order, FLAC__int32 data[])
  84230. {
  84231. int i, idata_len = (int)data_len;
  84232. switch(order) {
  84233. case 0:
  84234. FLAC__ASSERT(sizeof(residual[0]) == sizeof(data[0]));
  84235. memcpy(data, residual, sizeof(residual[0])*data_len);
  84236. break;
  84237. case 1:
  84238. for(i = 0; i < idata_len; i++)
  84239. data[i] = residual[i] + data[i-1];
  84240. break;
  84241. case 2:
  84242. for(i = 0; i < idata_len; i++)
  84243. #if 1 /* OPT: may be faster with some compilers on some systems */
  84244. data[i] = residual[i] + (data[i-1]<<1) - data[i-2];
  84245. #else
  84246. data[i] = residual[i] + 2*data[i-1] - data[i-2];
  84247. #endif
  84248. break;
  84249. case 3:
  84250. for(i = 0; i < idata_len; i++)
  84251. #if 1 /* OPT: may be faster with some compilers on some systems */
  84252. data[i] = residual[i] + (((data[i-1]-data[i-2])<<1) + (data[i-1]-data[i-2])) + data[i-3];
  84253. #else
  84254. data[i] = residual[i] + 3*data[i-1] - 3*data[i-2] + data[i-3];
  84255. #endif
  84256. break;
  84257. case 4:
  84258. for(i = 0; i < idata_len; i++)
  84259. #if 1 /* OPT: may be faster with some compilers on some systems */
  84260. data[i] = residual[i] + ((data[i-1]+data[i-3])<<2) - ((data[i-2]<<2) + (data[i-2]<<1)) - data[i-4];
  84261. #else
  84262. data[i] = residual[i] + 4*data[i-1] - 6*data[i-2] + 4*data[i-3] - data[i-4];
  84263. #endif
  84264. break;
  84265. default:
  84266. FLAC__ASSERT(0);
  84267. }
  84268. }
  84269. #endif
  84270. /*** End of inlined file: fixed.c ***/
  84271. /*** Start of inlined file: float.c ***/
  84272. /*** Start of inlined file: juce_FlacHeader.h ***/
  84273. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  84274. // tasks..
  84275. #define VERSION "1.2.1"
  84276. #define FLAC__NO_DLL 1
  84277. #if JUCE_MSVC
  84278. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  84279. #endif
  84280. #if JUCE_MAC
  84281. #define FLAC__SYS_DARWIN 1
  84282. #endif
  84283. /*** End of inlined file: juce_FlacHeader.h ***/
  84284. #if JUCE_USE_FLAC
  84285. #if HAVE_CONFIG_H
  84286. # include <config.h>
  84287. #endif
  84288. #ifdef FLAC__INTEGER_ONLY_LIBRARY
  84289. #ifdef _MSC_VER
  84290. #define FLAC__U64L(x) x
  84291. #else
  84292. #define FLAC__U64L(x) x##LLU
  84293. #endif
  84294. const FLAC__fixedpoint FLAC__FP_ZERO = 0;
  84295. const FLAC__fixedpoint FLAC__FP_ONE_HALF = 0x00008000;
  84296. const FLAC__fixedpoint FLAC__FP_ONE = 0x00010000;
  84297. const FLAC__fixedpoint FLAC__FP_LN2 = 45426;
  84298. const FLAC__fixedpoint FLAC__FP_E = 178145;
  84299. #define LOG2_LOOKUP_PRECISION 16
  84300. static const FLAC__uint32 log2_lookup[][LOG2_LOOKUP_PRECISION] = {
  84301. {
  84302. 0x00000000,
  84303. 0x00000001,
  84304. 0x00000000,
  84305. 0x00000000,
  84306. 0x00000000,
  84307. 0x00000000,
  84308. 0x00000000,
  84309. 0x00000000,
  84310. 0x00000000,
  84311. 0x00000000,
  84312. 0x00000000,
  84313. 0x00000000,
  84314. 0x00000000,
  84315. 0x00000000,
  84316. 0x00000000,
  84317. 0x00000000
  84318. },
  84319. {
  84320. 0x00000000,
  84321. 0x00000010,
  84322. 0x00000007,
  84323. 0x00000003,
  84324. 0x00000001,
  84325. 0x00000001,
  84326. 0x00000000,
  84327. 0x00000000,
  84328. 0x00000000,
  84329. 0x00000000,
  84330. 0x00000000,
  84331. 0x00000000,
  84332. 0x00000000,
  84333. 0x00000000,
  84334. 0x00000000,
  84335. 0x00000000
  84336. },
  84337. {
  84338. 0x00000000,
  84339. 0x00000100,
  84340. 0x0000006a,
  84341. 0x00000031,
  84342. 0x00000018,
  84343. 0x0000000c,
  84344. 0x00000006,
  84345. 0x00000003,
  84346. 0x00000001,
  84347. 0x00000001,
  84348. 0x00000000,
  84349. 0x00000000,
  84350. 0x00000000,
  84351. 0x00000000,
  84352. 0x00000000,
  84353. 0x00000000
  84354. },
  84355. {
  84356. 0x00000000,
  84357. 0x00001000,
  84358. 0x000006a4,
  84359. 0x00000315,
  84360. 0x0000017d,
  84361. 0x000000bc,
  84362. 0x0000005d,
  84363. 0x0000002e,
  84364. 0x00000017,
  84365. 0x0000000c,
  84366. 0x00000006,
  84367. 0x00000003,
  84368. 0x00000001,
  84369. 0x00000001,
  84370. 0x00000000,
  84371. 0x00000000
  84372. },
  84373. {
  84374. 0x00000000,
  84375. 0x00010000,
  84376. 0x00006a40,
  84377. 0x00003151,
  84378. 0x000017d6,
  84379. 0x00000bba,
  84380. 0x000005d1,
  84381. 0x000002e6,
  84382. 0x00000172,
  84383. 0x000000b9,
  84384. 0x0000005c,
  84385. 0x0000002e,
  84386. 0x00000017,
  84387. 0x0000000c,
  84388. 0x00000006,
  84389. 0x00000003
  84390. },
  84391. {
  84392. 0x00000000,
  84393. 0x00100000,
  84394. 0x0006a3fe,
  84395. 0x00031513,
  84396. 0x00017d60,
  84397. 0x0000bb9d,
  84398. 0x00005d10,
  84399. 0x00002e59,
  84400. 0x00001721,
  84401. 0x00000b8e,
  84402. 0x000005c6,
  84403. 0x000002e3,
  84404. 0x00000171,
  84405. 0x000000b9,
  84406. 0x0000005c,
  84407. 0x0000002e
  84408. },
  84409. {
  84410. 0x00000000,
  84411. 0x01000000,
  84412. 0x006a3fe6,
  84413. 0x00315130,
  84414. 0x0017d605,
  84415. 0x000bb9ca,
  84416. 0x0005d0fc,
  84417. 0x0002e58f,
  84418. 0x0001720e,
  84419. 0x0000b8d8,
  84420. 0x00005c61,
  84421. 0x00002e2d,
  84422. 0x00001716,
  84423. 0x00000b8b,
  84424. 0x000005c5,
  84425. 0x000002e3
  84426. },
  84427. {
  84428. 0x00000000,
  84429. 0x10000000,
  84430. 0x06a3fe5c,
  84431. 0x03151301,
  84432. 0x017d6049,
  84433. 0x00bb9ca6,
  84434. 0x005d0fba,
  84435. 0x002e58f7,
  84436. 0x001720da,
  84437. 0x000b8d87,
  84438. 0x0005c60b,
  84439. 0x0002e2d7,
  84440. 0x00017160,
  84441. 0x0000b8ad,
  84442. 0x00005c56,
  84443. 0x00002e2b
  84444. }
  84445. };
  84446. #if 0
  84447. static const FLAC__uint64 log2_lookup_wide[] = {
  84448. {
  84449. 0x00000000,
  84450. FLAC__U64L(0x100000000),
  84451. FLAC__U64L(0x6a3fe5c6),
  84452. FLAC__U64L(0x31513015),
  84453. FLAC__U64L(0x17d60497),
  84454. FLAC__U64L(0x0bb9ca65),
  84455. FLAC__U64L(0x05d0fba2),
  84456. FLAC__U64L(0x02e58f74),
  84457. FLAC__U64L(0x01720d9c),
  84458. FLAC__U64L(0x00b8d875),
  84459. FLAC__U64L(0x005c60aa),
  84460. FLAC__U64L(0x002e2d72),
  84461. FLAC__U64L(0x00171600),
  84462. FLAC__U64L(0x000b8ad2),
  84463. FLAC__U64L(0x0005c55d),
  84464. FLAC__U64L(0x0002e2ac)
  84465. },
  84466. {
  84467. 0x00000000,
  84468. FLAC__U64L(0x1000000000000),
  84469. FLAC__U64L(0x6a3fe5c60429),
  84470. FLAC__U64L(0x315130157f7a),
  84471. FLAC__U64L(0x17d60496cfbb),
  84472. FLAC__U64L(0xbb9ca64ecac),
  84473. FLAC__U64L(0x5d0fba187cd),
  84474. FLAC__U64L(0x2e58f7441ee),
  84475. FLAC__U64L(0x1720d9c06a8),
  84476. FLAC__U64L(0xb8d8752173),
  84477. FLAC__U64L(0x5c60aa252e),
  84478. FLAC__U64L(0x2e2d71b0d8),
  84479. FLAC__U64L(0x1716001719),
  84480. FLAC__U64L(0xb8ad1de1b),
  84481. FLAC__U64L(0x5c55d640d),
  84482. FLAC__U64L(0x2e2abcf52)
  84483. }
  84484. };
  84485. #endif
  84486. FLAC__uint32 FLAC__fixedpoint_log2(FLAC__uint32 x, unsigned fracbits, unsigned precision)
  84487. {
  84488. const FLAC__uint32 ONE = (1u << fracbits);
  84489. const FLAC__uint32 *table = log2_lookup[fracbits >> 2];
  84490. FLAC__ASSERT(fracbits < 32);
  84491. FLAC__ASSERT((fracbits & 0x3) == 0);
  84492. if(x < ONE)
  84493. return 0;
  84494. if(precision > LOG2_LOOKUP_PRECISION)
  84495. precision = LOG2_LOOKUP_PRECISION;
  84496. {
  84497. FLAC__uint32 y = 0;
  84498. FLAC__uint32 z = x >> 1, k = 1;
  84499. while (x > ONE && k < precision) {
  84500. if (x - z >= ONE) {
  84501. x -= z;
  84502. z = x >> k;
  84503. y += table[k];
  84504. }
  84505. else {
  84506. z >>= 1;
  84507. k++;
  84508. }
  84509. }
  84510. return y;
  84511. }
  84512. }
  84513. #endif /* defined FLAC__INTEGER_ONLY_LIBRARY */
  84514. #endif
  84515. /*** End of inlined file: float.c ***/
  84516. /*** Start of inlined file: format.c ***/
  84517. /*** Start of inlined file: juce_FlacHeader.h ***/
  84518. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  84519. // tasks..
  84520. #define VERSION "1.2.1"
  84521. #define FLAC__NO_DLL 1
  84522. #if JUCE_MSVC
  84523. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  84524. #endif
  84525. #if JUCE_MAC
  84526. #define FLAC__SYS_DARWIN 1
  84527. #endif
  84528. /*** End of inlined file: juce_FlacHeader.h ***/
  84529. #if JUCE_USE_FLAC
  84530. #if HAVE_CONFIG_H
  84531. # include <config.h>
  84532. #endif
  84533. #include <stdio.h>
  84534. #include <stdlib.h> /* for qsort() */
  84535. #include <string.h> /* for memset() */
  84536. #ifndef FLaC__INLINE
  84537. #define FLaC__INLINE
  84538. #endif
  84539. #ifdef min
  84540. #undef min
  84541. #endif
  84542. #define min(a,b) ((a)<(b)?(a):(b))
  84543. #ifdef _MSC_VER
  84544. #define FLAC__U64L(x) x
  84545. #else
  84546. #define FLAC__U64L(x) x##LLU
  84547. #endif
  84548. FLAC_API const char *FLAC__VERSION_STRING = VERSION
  84549. ;
  84550. #if defined _MSC_VER || defined __BORLANDC__ || defined __MINW32__
  84551. FLAC_API const char *FLAC__VENDOR_STRING = "reference libFLAC 1.2.1 20070917";
  84552. #else
  84553. FLAC_API const char *FLAC__VENDOR_STRING = "reference libFLAC " VERSION " 20070917";
  84554. #endif
  84555. FLAC_API const FLAC__byte FLAC__STREAM_SYNC_STRING[4] = { 'f','L','a','C' };
  84556. FLAC_API const unsigned FLAC__STREAM_SYNC = 0x664C6143;
  84557. FLAC_API const unsigned FLAC__STREAM_SYNC_LEN = 32; /* bits */
  84558. FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN = 16; /* bits */
  84559. FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN = 16; /* bits */
  84560. FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN = 24; /* bits */
  84561. FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN = 24; /* bits */
  84562. FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_SAMPLE_RATE_LEN = 20; /* bits */
  84563. FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN = 3; /* bits */
  84564. FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN = 5; /* bits */
  84565. FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_TOTAL_SAMPLES_LEN = 36; /* bits */
  84566. FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MD5SUM_LEN = 128; /* bits */
  84567. FLAC_API const unsigned FLAC__STREAM_METADATA_APPLICATION_ID_LEN = 32; /* bits */
  84568. FLAC_API const unsigned FLAC__STREAM_METADATA_SEEKPOINT_SAMPLE_NUMBER_LEN = 64; /* bits */
  84569. FLAC_API const unsigned FLAC__STREAM_METADATA_SEEKPOINT_STREAM_OFFSET_LEN = 64; /* bits */
  84570. FLAC_API const unsigned FLAC__STREAM_METADATA_SEEKPOINT_FRAME_SAMPLES_LEN = 16; /* bits */
  84571. FLAC_API const FLAC__uint64 FLAC__STREAM_METADATA_SEEKPOINT_PLACEHOLDER = FLAC__U64L(0xffffffffffffffff);
  84572. FLAC_API const unsigned FLAC__STREAM_METADATA_VORBIS_COMMENT_ENTRY_LENGTH_LEN = 32; /* bits */
  84573. FLAC_API const unsigned FLAC__STREAM_METADATA_VORBIS_COMMENT_NUM_COMMENTS_LEN = 32; /* bits */
  84574. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_INDEX_OFFSET_LEN = 64; /* bits */
  84575. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_INDEX_NUMBER_LEN = 8; /* bits */
  84576. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_INDEX_RESERVED_LEN = 3*8; /* bits */
  84577. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_OFFSET_LEN = 64; /* bits */
  84578. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_NUMBER_LEN = 8; /* bits */
  84579. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_ISRC_LEN = 12*8; /* bits */
  84580. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_TYPE_LEN = 1; /* bit */
  84581. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_PRE_EMPHASIS_LEN = 1; /* bit */
  84582. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_RESERVED_LEN = 6+13*8; /* bits */
  84583. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_NUM_INDICES_LEN = 8; /* bits */
  84584. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_MEDIA_CATALOG_NUMBER_LEN = 128*8; /* bits */
  84585. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_LEAD_IN_LEN = 64; /* bits */
  84586. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_IS_CD_LEN = 1; /* bit */
  84587. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_RESERVED_LEN = 7+258*8; /* bits */
  84588. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_NUM_TRACKS_LEN = 8; /* bits */
  84589. FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_TYPE_LEN = 32; /* bits */
  84590. FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_MIME_TYPE_LENGTH_LEN = 32; /* bits */
  84591. FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_DESCRIPTION_LENGTH_LEN = 32; /* bits */
  84592. FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_WIDTH_LEN = 32; /* bits */
  84593. FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_HEIGHT_LEN = 32; /* bits */
  84594. FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_DEPTH_LEN = 32; /* bits */
  84595. FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_COLORS_LEN = 32; /* bits */
  84596. FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_DATA_LENGTH_LEN = 32; /* bits */
  84597. FLAC_API const unsigned FLAC__STREAM_METADATA_IS_LAST_LEN = 1; /* bits */
  84598. FLAC_API const unsigned FLAC__STREAM_METADATA_TYPE_LEN = 7; /* bits */
  84599. FLAC_API const unsigned FLAC__STREAM_METADATA_LENGTH_LEN = 24; /* bits */
  84600. FLAC_API const unsigned FLAC__FRAME_HEADER_SYNC = 0x3ffe;
  84601. FLAC_API const unsigned FLAC__FRAME_HEADER_SYNC_LEN = 14; /* bits */
  84602. FLAC_API const unsigned FLAC__FRAME_HEADER_RESERVED_LEN = 1; /* bits */
  84603. FLAC_API const unsigned FLAC__FRAME_HEADER_BLOCKING_STRATEGY_LEN = 1; /* bits */
  84604. FLAC_API const unsigned FLAC__FRAME_HEADER_BLOCK_SIZE_LEN = 4; /* bits */
  84605. FLAC_API const unsigned FLAC__FRAME_HEADER_SAMPLE_RATE_LEN = 4; /* bits */
  84606. FLAC_API const unsigned FLAC__FRAME_HEADER_CHANNEL_ASSIGNMENT_LEN = 4; /* bits */
  84607. FLAC_API const unsigned FLAC__FRAME_HEADER_BITS_PER_SAMPLE_LEN = 3; /* bits */
  84608. FLAC_API const unsigned FLAC__FRAME_HEADER_ZERO_PAD_LEN = 1; /* bits */
  84609. FLAC_API const unsigned FLAC__FRAME_HEADER_CRC_LEN = 8; /* bits */
  84610. FLAC_API const unsigned FLAC__FRAME_FOOTER_CRC_LEN = 16; /* bits */
  84611. FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_TYPE_LEN = 2; /* bits */
  84612. FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ORDER_LEN = 4; /* bits */
  84613. FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_PARAMETER_LEN = 4; /* bits */
  84614. FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_PARAMETER_LEN = 5; /* bits */
  84615. FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_RAW_LEN = 5; /* bits */
  84616. FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ESCAPE_PARAMETER = 15; /* == (1<<FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_PARAMETER_LEN)-1 */
  84617. FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_ESCAPE_PARAMETER = 31; /* == (1<<FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_PARAMETER_LEN)-1 */
  84618. FLAC_API const char * const FLAC__EntropyCodingMethodTypeString[] = {
  84619. "PARTITIONED_RICE",
  84620. "PARTITIONED_RICE2"
  84621. };
  84622. FLAC_API const unsigned FLAC__SUBFRAME_LPC_QLP_COEFF_PRECISION_LEN = 4; /* bits */
  84623. FLAC_API const unsigned FLAC__SUBFRAME_LPC_QLP_SHIFT_LEN = 5; /* bits */
  84624. FLAC_API const unsigned FLAC__SUBFRAME_ZERO_PAD_LEN = 1; /* bits */
  84625. FLAC_API const unsigned FLAC__SUBFRAME_TYPE_LEN = 6; /* bits */
  84626. FLAC_API const unsigned FLAC__SUBFRAME_WASTED_BITS_FLAG_LEN = 1; /* bits */
  84627. FLAC_API const unsigned FLAC__SUBFRAME_TYPE_CONSTANT_BYTE_ALIGNED_MASK = 0x00;
  84628. FLAC_API const unsigned FLAC__SUBFRAME_TYPE_VERBATIM_BYTE_ALIGNED_MASK = 0x02;
  84629. FLAC_API const unsigned FLAC__SUBFRAME_TYPE_FIXED_BYTE_ALIGNED_MASK = 0x10;
  84630. FLAC_API const unsigned FLAC__SUBFRAME_TYPE_LPC_BYTE_ALIGNED_MASK = 0x40;
  84631. FLAC_API const char * const FLAC__SubframeTypeString[] = {
  84632. "CONSTANT",
  84633. "VERBATIM",
  84634. "FIXED",
  84635. "LPC"
  84636. };
  84637. FLAC_API const char * const FLAC__ChannelAssignmentString[] = {
  84638. "INDEPENDENT",
  84639. "LEFT_SIDE",
  84640. "RIGHT_SIDE",
  84641. "MID_SIDE"
  84642. };
  84643. FLAC_API const char * const FLAC__FrameNumberTypeString[] = {
  84644. "FRAME_NUMBER_TYPE_FRAME_NUMBER",
  84645. "FRAME_NUMBER_TYPE_SAMPLE_NUMBER"
  84646. };
  84647. FLAC_API const char * const FLAC__MetadataTypeString[] = {
  84648. "STREAMINFO",
  84649. "PADDING",
  84650. "APPLICATION",
  84651. "SEEKTABLE",
  84652. "VORBIS_COMMENT",
  84653. "CUESHEET",
  84654. "PICTURE"
  84655. };
  84656. FLAC_API const char * const FLAC__StreamMetadata_Picture_TypeString[] = {
  84657. "Other",
  84658. "32x32 pixels 'file icon' (PNG only)",
  84659. "Other file icon",
  84660. "Cover (front)",
  84661. "Cover (back)",
  84662. "Leaflet page",
  84663. "Media (e.g. label side of CD)",
  84664. "Lead artist/lead performer/soloist",
  84665. "Artist/performer",
  84666. "Conductor",
  84667. "Band/Orchestra",
  84668. "Composer",
  84669. "Lyricist/text writer",
  84670. "Recording Location",
  84671. "During recording",
  84672. "During performance",
  84673. "Movie/video screen capture",
  84674. "A bright coloured fish",
  84675. "Illustration",
  84676. "Band/artist logotype",
  84677. "Publisher/Studio logotype"
  84678. };
  84679. FLAC_API FLAC__bool FLAC__format_sample_rate_is_valid(unsigned sample_rate)
  84680. {
  84681. if(sample_rate == 0 || sample_rate > FLAC__MAX_SAMPLE_RATE) {
  84682. return false;
  84683. }
  84684. else
  84685. return true;
  84686. }
  84687. FLAC_API FLAC__bool FLAC__format_sample_rate_is_subset(unsigned sample_rate)
  84688. {
  84689. if(
  84690. !FLAC__format_sample_rate_is_valid(sample_rate) ||
  84691. (
  84692. sample_rate >= (1u << 16) &&
  84693. !(sample_rate % 1000 == 0 || sample_rate % 10 == 0)
  84694. )
  84695. ) {
  84696. return false;
  84697. }
  84698. else
  84699. return true;
  84700. }
  84701. FLAC_API FLAC__bool FLAC__format_seektable_is_legal(const FLAC__StreamMetadata_SeekTable *seek_table)
  84702. {
  84703. unsigned i;
  84704. FLAC__uint64 prev_sample_number = 0;
  84705. FLAC__bool got_prev = false;
  84706. FLAC__ASSERT(0 != seek_table);
  84707. for(i = 0; i < seek_table->num_points; i++) {
  84708. if(got_prev) {
  84709. if(
  84710. seek_table->points[i].sample_number != FLAC__STREAM_METADATA_SEEKPOINT_PLACEHOLDER &&
  84711. seek_table->points[i].sample_number <= prev_sample_number
  84712. )
  84713. return false;
  84714. }
  84715. prev_sample_number = seek_table->points[i].sample_number;
  84716. got_prev = true;
  84717. }
  84718. return true;
  84719. }
  84720. static int seekpoint_compare_(const FLAC__StreamMetadata_SeekPoint *l, const FLAC__StreamMetadata_SeekPoint *r)
  84721. {
  84722. if(l->sample_number == r->sample_number)
  84723. return 0;
  84724. else if(l->sample_number < r->sample_number)
  84725. return -1;
  84726. else
  84727. return 1;
  84728. }
  84729. FLAC_API unsigned FLAC__format_seektable_sort(FLAC__StreamMetadata_SeekTable *seek_table)
  84730. {
  84731. unsigned i, j;
  84732. FLAC__bool first;
  84733. FLAC__ASSERT(0 != seek_table);
  84734. qsort(seek_table->points, seek_table->num_points, sizeof(FLAC__StreamMetadata_SeekPoint), (int (*)(const void *, const void *))seekpoint_compare_);
  84735. first = true;
  84736. for(i = j = 0; i < seek_table->num_points; i++) {
  84737. if(seek_table->points[i].sample_number != FLAC__STREAM_METADATA_SEEKPOINT_PLACEHOLDER) {
  84738. if(!first) {
  84739. if(seek_table->points[i].sample_number == seek_table->points[j-1].sample_number)
  84740. continue;
  84741. }
  84742. }
  84743. first = false;
  84744. seek_table->points[j++] = seek_table->points[i];
  84745. }
  84746. for(i = j; i < seek_table->num_points; i++) {
  84747. seek_table->points[i].sample_number = FLAC__STREAM_METADATA_SEEKPOINT_PLACEHOLDER;
  84748. seek_table->points[i].stream_offset = 0;
  84749. seek_table->points[i].frame_samples = 0;
  84750. }
  84751. return j;
  84752. }
  84753. static FLaC__INLINE unsigned utf8len_(const FLAC__byte *utf8)
  84754. {
  84755. FLAC__ASSERT(0 != utf8);
  84756. if ((utf8[0] & 0x80) == 0) {
  84757. return 1;
  84758. }
  84759. else if ((utf8[0] & 0xE0) == 0xC0 && (utf8[1] & 0xC0) == 0x80) {
  84760. if ((utf8[0] & 0xFE) == 0xC0) /* overlong sequence check */
  84761. return 0;
  84762. return 2;
  84763. }
  84764. else if ((utf8[0] & 0xF0) == 0xE0 && (utf8[1] & 0xC0) == 0x80 && (utf8[2] & 0xC0) == 0x80) {
  84765. if (utf8[0] == 0xE0 && (utf8[1] & 0xE0) == 0x80) /* overlong sequence check */
  84766. return 0;
  84767. if (utf8[0] == 0xED && (utf8[1] & 0xE0) == 0xA0) /* D800-DFFF */
  84768. return 0;
  84769. if (utf8[0] == 0xEF && utf8[1] == 0xBF && (utf8[2] & 0xFE) == 0xBE) /* FFFE-FFFF */
  84770. return 0;
  84771. return 3;
  84772. }
  84773. else if ((utf8[0] & 0xF8) == 0xF0 && (utf8[1] & 0xC0) == 0x80 && (utf8[2] & 0xC0) == 0x80 && (utf8[3] & 0xC0) == 0x80) {
  84774. if (utf8[0] == 0xF0 && (utf8[1] & 0xF0) == 0x80) /* overlong sequence check */
  84775. return 0;
  84776. return 4;
  84777. }
  84778. else if ((utf8[0] & 0xFC) == 0xF8 && (utf8[1] & 0xC0) == 0x80 && (utf8[2] & 0xC0) == 0x80 && (utf8[3] & 0xC0) == 0x80 && (utf8[4] & 0xC0) == 0x80) {
  84779. if (utf8[0] == 0xF8 && (utf8[1] & 0xF8) == 0x80) /* overlong sequence check */
  84780. return 0;
  84781. return 5;
  84782. }
  84783. 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) {
  84784. if (utf8[0] == 0xFC && (utf8[1] & 0xFC) == 0x80) /* overlong sequence check */
  84785. return 0;
  84786. return 6;
  84787. }
  84788. else {
  84789. return 0;
  84790. }
  84791. }
  84792. FLAC_API FLAC__bool FLAC__format_vorbiscomment_entry_name_is_legal(const char *name)
  84793. {
  84794. char c;
  84795. for(c = *name; c; c = *(++name))
  84796. if(c < 0x20 || c == 0x3d || c > 0x7d)
  84797. return false;
  84798. return true;
  84799. }
  84800. FLAC_API FLAC__bool FLAC__format_vorbiscomment_entry_value_is_legal(const FLAC__byte *value, unsigned length)
  84801. {
  84802. if(length == (unsigned)(-1)) {
  84803. while(*value) {
  84804. unsigned n = utf8len_(value);
  84805. if(n == 0)
  84806. return false;
  84807. value += n;
  84808. }
  84809. }
  84810. else {
  84811. const FLAC__byte *end = value + length;
  84812. while(value < end) {
  84813. unsigned n = utf8len_(value);
  84814. if(n == 0)
  84815. return false;
  84816. value += n;
  84817. }
  84818. if(value != end)
  84819. return false;
  84820. }
  84821. return true;
  84822. }
  84823. FLAC_API FLAC__bool FLAC__format_vorbiscomment_entry_is_legal(const FLAC__byte *entry, unsigned length)
  84824. {
  84825. const FLAC__byte *s, *end;
  84826. for(s = entry, end = s + length; s < end && *s != '='; s++) {
  84827. if(*s < 0x20 || *s > 0x7D)
  84828. return false;
  84829. }
  84830. if(s == end)
  84831. return false;
  84832. s++; /* skip '=' */
  84833. while(s < end) {
  84834. unsigned n = utf8len_(s);
  84835. if(n == 0)
  84836. return false;
  84837. s += n;
  84838. }
  84839. if(s != end)
  84840. return false;
  84841. return true;
  84842. }
  84843. FLAC_API FLAC__bool FLAC__format_cuesheet_is_legal(const FLAC__StreamMetadata_CueSheet *cue_sheet, FLAC__bool check_cd_da_subset, const char **violation)
  84844. {
  84845. unsigned i, j;
  84846. if(check_cd_da_subset) {
  84847. if(cue_sheet->lead_in < 2 * 44100) {
  84848. if(violation) *violation = "CD-DA cue sheet must have a lead-in length of at least 2 seconds";
  84849. return false;
  84850. }
  84851. if(cue_sheet->lead_in % 588 != 0) {
  84852. if(violation) *violation = "CD-DA cue sheet lead-in length must be evenly divisible by 588 samples";
  84853. return false;
  84854. }
  84855. }
  84856. if(cue_sheet->num_tracks == 0) {
  84857. if(violation) *violation = "cue sheet must have at least one track (the lead-out)";
  84858. return false;
  84859. }
  84860. if(check_cd_da_subset && cue_sheet->tracks[cue_sheet->num_tracks-1].number != 170) {
  84861. if(violation) *violation = "CD-DA cue sheet must have a lead-out track number 170 (0xAA)";
  84862. return false;
  84863. }
  84864. for(i = 0; i < cue_sheet->num_tracks; i++) {
  84865. if(cue_sheet->tracks[i].number == 0) {
  84866. if(violation) *violation = "cue sheet may not have a track number 0";
  84867. return false;
  84868. }
  84869. if(check_cd_da_subset) {
  84870. if(!((cue_sheet->tracks[i].number >= 1 && cue_sheet->tracks[i].number <= 99) || cue_sheet->tracks[i].number == 170)) {
  84871. if(violation) *violation = "CD-DA cue sheet track number must be 1-99 or 170";
  84872. return false;
  84873. }
  84874. }
  84875. if(check_cd_da_subset && cue_sheet->tracks[i].offset % 588 != 0) {
  84876. if(violation) {
  84877. if(i == cue_sheet->num_tracks-1) /* the lead-out track... */
  84878. *violation = "CD-DA cue sheet lead-out offset must be evenly divisible by 588 samples";
  84879. else
  84880. *violation = "CD-DA cue sheet track offset must be evenly divisible by 588 samples";
  84881. }
  84882. return false;
  84883. }
  84884. if(i < cue_sheet->num_tracks - 1) {
  84885. if(cue_sheet->tracks[i].num_indices == 0) {
  84886. if(violation) *violation = "cue sheet track must have at least one index point";
  84887. return false;
  84888. }
  84889. if(cue_sheet->tracks[i].indices[0].number > 1) {
  84890. if(violation) *violation = "cue sheet track's first index number must be 0 or 1";
  84891. return false;
  84892. }
  84893. }
  84894. for(j = 0; j < cue_sheet->tracks[i].num_indices; j++) {
  84895. if(check_cd_da_subset && cue_sheet->tracks[i].indices[j].offset % 588 != 0) {
  84896. if(violation) *violation = "CD-DA cue sheet track index offset must be evenly divisible by 588 samples";
  84897. return false;
  84898. }
  84899. if(j > 0) {
  84900. if(cue_sheet->tracks[i].indices[j].number != cue_sheet->tracks[i].indices[j-1].number + 1) {
  84901. if(violation) *violation = "cue sheet track index numbers must increase by 1";
  84902. return false;
  84903. }
  84904. }
  84905. }
  84906. }
  84907. return true;
  84908. }
  84909. FLAC_API FLAC__bool FLAC__format_picture_is_legal(const FLAC__StreamMetadata_Picture *picture, const char **violation)
  84910. {
  84911. char *p;
  84912. FLAC__byte *b;
  84913. for(p = picture->mime_type; *p; p++) {
  84914. if(*p < 0x20 || *p > 0x7e) {
  84915. if(violation) *violation = "MIME type string must contain only printable ASCII characters (0x20-0x7e)";
  84916. return false;
  84917. }
  84918. }
  84919. for(b = picture->description; *b; ) {
  84920. unsigned n = utf8len_(b);
  84921. if(n == 0) {
  84922. if(violation) *violation = "description string must be valid UTF-8";
  84923. return false;
  84924. }
  84925. b += n;
  84926. }
  84927. return true;
  84928. }
  84929. unsigned FLAC__format_get_max_rice_partition_order(unsigned blocksize, unsigned predictor_order)
  84930. {
  84931. return
  84932. FLAC__format_get_max_rice_partition_order_from_blocksize_limited_max_and_predictor_order(
  84933. FLAC__format_get_max_rice_partition_order_from_blocksize(blocksize),
  84934. blocksize,
  84935. predictor_order
  84936. );
  84937. }
  84938. unsigned FLAC__format_get_max_rice_partition_order_from_blocksize(unsigned blocksize)
  84939. {
  84940. unsigned max_rice_partition_order = 0;
  84941. while(!(blocksize & 1)) {
  84942. max_rice_partition_order++;
  84943. blocksize >>= 1;
  84944. }
  84945. return min(FLAC__MAX_RICE_PARTITION_ORDER, max_rice_partition_order);
  84946. }
  84947. unsigned FLAC__format_get_max_rice_partition_order_from_blocksize_limited_max_and_predictor_order(unsigned limit, unsigned blocksize, unsigned predictor_order)
  84948. {
  84949. unsigned max_rice_partition_order = limit;
  84950. while(max_rice_partition_order > 0 && (blocksize >> max_rice_partition_order) <= predictor_order)
  84951. max_rice_partition_order--;
  84952. FLAC__ASSERT(
  84953. (max_rice_partition_order == 0 && blocksize >= predictor_order) ||
  84954. (max_rice_partition_order > 0 && blocksize >> max_rice_partition_order > predictor_order)
  84955. );
  84956. return max_rice_partition_order;
  84957. }
  84958. void FLAC__format_entropy_coding_method_partitioned_rice_contents_init(FLAC__EntropyCodingMethod_PartitionedRiceContents *object)
  84959. {
  84960. FLAC__ASSERT(0 != object);
  84961. object->parameters = 0;
  84962. object->raw_bits = 0;
  84963. object->capacity_by_order = 0;
  84964. }
  84965. void FLAC__format_entropy_coding_method_partitioned_rice_contents_clear(FLAC__EntropyCodingMethod_PartitionedRiceContents *object)
  84966. {
  84967. FLAC__ASSERT(0 != object);
  84968. if(0 != object->parameters)
  84969. free(object->parameters);
  84970. if(0 != object->raw_bits)
  84971. free(object->raw_bits);
  84972. FLAC__format_entropy_coding_method_partitioned_rice_contents_init(object);
  84973. }
  84974. FLAC__bool FLAC__format_entropy_coding_method_partitioned_rice_contents_ensure_size(FLAC__EntropyCodingMethod_PartitionedRiceContents *object, unsigned max_partition_order)
  84975. {
  84976. FLAC__ASSERT(0 != object);
  84977. FLAC__ASSERT(object->capacity_by_order > 0 || (0 == object->parameters && 0 == object->raw_bits));
  84978. if(object->capacity_by_order < max_partition_order) {
  84979. if(0 == (object->parameters = (unsigned*)realloc(object->parameters, sizeof(unsigned)*(1 << max_partition_order))))
  84980. return false;
  84981. if(0 == (object->raw_bits = (unsigned*)realloc(object->raw_bits, sizeof(unsigned)*(1 << max_partition_order))))
  84982. return false;
  84983. memset(object->raw_bits, 0, sizeof(unsigned)*(1 << max_partition_order));
  84984. object->capacity_by_order = max_partition_order;
  84985. }
  84986. return true;
  84987. }
  84988. #endif
  84989. /*** End of inlined file: format.c ***/
  84990. /*** Start of inlined file: lpc_flac.c ***/
  84991. /*** Start of inlined file: juce_FlacHeader.h ***/
  84992. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  84993. // tasks..
  84994. #define VERSION "1.2.1"
  84995. #define FLAC__NO_DLL 1
  84996. #if JUCE_MSVC
  84997. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  84998. #endif
  84999. #if JUCE_MAC
  85000. #define FLAC__SYS_DARWIN 1
  85001. #endif
  85002. /*** End of inlined file: juce_FlacHeader.h ***/
  85003. #if JUCE_USE_FLAC
  85004. #if HAVE_CONFIG_H
  85005. # include <config.h>
  85006. #endif
  85007. #include <math.h>
  85008. /*** Start of inlined file: lpc.h ***/
  85009. #ifndef FLAC__PRIVATE__LPC_H
  85010. #define FLAC__PRIVATE__LPC_H
  85011. #ifdef HAVE_CONFIG_H
  85012. #include <config.h>
  85013. #endif
  85014. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  85015. void FLAC__lpc_window_data(const FLAC__int32 in[], const FLAC__real window[], FLAC__real out[], unsigned data_len);
  85016. void FLAC__lpc_compute_autocorrelation(const FLAC__real data[], unsigned data_len, unsigned lag, FLAC__real autoc[]);
  85017. #ifndef FLAC__NO_ASM
  85018. # ifdef FLAC__CPU_IA32
  85019. # ifdef FLAC__HAS_NASM
  85020. void FLAC__lpc_compute_autocorrelation_asm_ia32(const FLAC__real data[], unsigned data_len, unsigned lag, FLAC__real autoc[]);
  85021. void FLAC__lpc_compute_autocorrelation_asm_ia32_sse_lag_4(const FLAC__real data[], unsigned data_len, unsigned lag, FLAC__real autoc[]);
  85022. void FLAC__lpc_compute_autocorrelation_asm_ia32_sse_lag_8(const FLAC__real data[], unsigned data_len, unsigned lag, FLAC__real autoc[]);
  85023. void FLAC__lpc_compute_autocorrelation_asm_ia32_sse_lag_12(const FLAC__real data[], unsigned data_len, unsigned lag, FLAC__real autoc[]);
  85024. void FLAC__lpc_compute_autocorrelation_asm_ia32_3dnow(const FLAC__real data[], unsigned data_len, unsigned lag, FLAC__real autoc[]);
  85025. # endif
  85026. # endif
  85027. #endif
  85028. void FLAC__lpc_compute_lp_coefficients(const FLAC__real autoc[], unsigned *max_order, FLAC__real lp_coeff[][FLAC__MAX_LPC_ORDER], FLAC__double error[]);
  85029. int FLAC__lpc_quantize_coefficients(const FLAC__real lp_coeff[], unsigned order, unsigned precision, FLAC__int32 qlp_coeff[], int *shift);
  85030. 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[]);
  85031. 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[]);
  85032. #ifndef FLAC__NO_ASM
  85033. # ifdef FLAC__CPU_IA32
  85034. # ifdef FLAC__HAS_NASM
  85035. 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[]);
  85036. 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[]);
  85037. # endif
  85038. # endif
  85039. #endif
  85040. #endif /* !defined FLAC__INTEGER_ONLY_LIBRARY */
  85041. 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[]);
  85042. 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[]);
  85043. #ifndef FLAC__NO_ASM
  85044. # ifdef FLAC__CPU_IA32
  85045. # ifdef FLAC__HAS_NASM
  85046. 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[]);
  85047. 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[]);
  85048. # endif /* FLAC__HAS_NASM */
  85049. # elif defined FLAC__CPU_PPC
  85050. 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[]);
  85051. 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[]);
  85052. # endif/* FLAC__CPU_IA32 || FLAC__CPU_PPC */
  85053. #endif /* FLAC__NO_ASM */
  85054. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  85055. FLAC__double FLAC__lpc_compute_expected_bits_per_residual_sample(FLAC__double lpc_error, unsigned total_samples);
  85056. FLAC__double FLAC__lpc_compute_expected_bits_per_residual_sample_with_error_scale(FLAC__double lpc_error, FLAC__double error_scale);
  85057. unsigned FLAC__lpc_compute_best_order(const FLAC__double lpc_error[], unsigned max_order, unsigned total_samples, unsigned overhead_bits_per_order);
  85058. #endif /* !defined FLAC__INTEGER_ONLY_LIBRARY */
  85059. #endif
  85060. /*** End of inlined file: lpc.h ***/
  85061. #if defined DEBUG || defined FLAC__OVERFLOW_DETECT || defined FLAC__OVERFLOW_DETECT_VERBOSE
  85062. #include <stdio.h>
  85063. #endif
  85064. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  85065. #ifndef M_LN2
  85066. #define M_LN2 0.69314718055994530942
  85067. #endif
  85068. #define FLAC__LPC_UNROLLED_FILTER_LOOPS
  85069. void FLAC__lpc_window_data(const FLAC__int32 in[], const FLAC__real window[], FLAC__real out[], unsigned data_len)
  85070. {
  85071. unsigned i;
  85072. for(i = 0; i < data_len; i++)
  85073. out[i] = in[i] * window[i];
  85074. }
  85075. void FLAC__lpc_compute_autocorrelation(const FLAC__real data[], unsigned data_len, unsigned lag, FLAC__real autoc[])
  85076. {
  85077. #if 0
  85078. FLAC__real d;
  85079. unsigned i;
  85080. FLAC__ASSERT(lag > 0);
  85081. FLAC__ASSERT(lag <= data_len);
  85082. while(lag--) {
  85083. for(i = lag, d = 0.0; i < data_len; i++)
  85084. d += data[i] * data[i - lag];
  85085. autoc[lag] = d;
  85086. }
  85087. #endif
  85088. FLAC__real d;
  85089. unsigned sample, coeff;
  85090. const unsigned limit = data_len - lag;
  85091. FLAC__ASSERT(lag > 0);
  85092. FLAC__ASSERT(lag <= data_len);
  85093. for(coeff = 0; coeff < lag; coeff++)
  85094. autoc[coeff] = 0.0;
  85095. for(sample = 0; sample <= limit; sample++) {
  85096. d = data[sample];
  85097. for(coeff = 0; coeff < lag; coeff++)
  85098. autoc[coeff] += d * data[sample+coeff];
  85099. }
  85100. for(; sample < data_len; sample++) {
  85101. d = data[sample];
  85102. for(coeff = 0; coeff < data_len - sample; coeff++)
  85103. autoc[coeff] += d * data[sample+coeff];
  85104. }
  85105. }
  85106. void FLAC__lpc_compute_lp_coefficients(const FLAC__real autoc[], unsigned *max_order, FLAC__real lp_coeff[][FLAC__MAX_LPC_ORDER], FLAC__double error[])
  85107. {
  85108. unsigned i, j;
  85109. FLAC__double r, err, ref[FLAC__MAX_LPC_ORDER], lpc[FLAC__MAX_LPC_ORDER];
  85110. FLAC__ASSERT(0 != max_order);
  85111. FLAC__ASSERT(0 < *max_order);
  85112. FLAC__ASSERT(*max_order <= FLAC__MAX_LPC_ORDER);
  85113. FLAC__ASSERT(autoc[0] != 0.0);
  85114. err = autoc[0];
  85115. for(i = 0; i < *max_order; i++) {
  85116. r = -autoc[i+1];
  85117. for(j = 0; j < i; j++)
  85118. r -= lpc[j] * autoc[i-j];
  85119. ref[i] = (r/=err);
  85120. lpc[i]=r;
  85121. for(j = 0; j < (i>>1); j++) {
  85122. FLAC__double tmp = lpc[j];
  85123. lpc[j] += r * lpc[i-1-j];
  85124. lpc[i-1-j] += r * tmp;
  85125. }
  85126. if(i & 1)
  85127. lpc[j] += lpc[j] * r;
  85128. err *= (1.0 - r * r);
  85129. for(j = 0; j <= i; j++)
  85130. lp_coeff[i][j] = (FLAC__real)(-lpc[j]); /* negate FIR filter coeff to get predictor coeff */
  85131. error[i] = err;
  85132. if(err == 0.0) {
  85133. *max_order = i+1;
  85134. return;
  85135. }
  85136. }
  85137. }
  85138. int FLAC__lpc_quantize_coefficients(const FLAC__real lp_coeff[], unsigned order, unsigned precision, FLAC__int32 qlp_coeff[], int *shift)
  85139. {
  85140. unsigned i;
  85141. FLAC__double cmax;
  85142. FLAC__int32 qmax, qmin;
  85143. FLAC__ASSERT(precision > 0);
  85144. FLAC__ASSERT(precision >= FLAC__MIN_QLP_COEFF_PRECISION);
  85145. precision--;
  85146. qmax = 1 << precision;
  85147. qmin = -qmax;
  85148. qmax--;
  85149. cmax = 0.0;
  85150. for(i = 0; i < order; i++) {
  85151. const FLAC__double d = fabs(lp_coeff[i]);
  85152. if(d > cmax)
  85153. cmax = d;
  85154. }
  85155. if(cmax <= 0.0) {
  85156. return 2;
  85157. }
  85158. else {
  85159. const int max_shiftlimit = (1 << (FLAC__SUBFRAME_LPC_QLP_SHIFT_LEN-1)) - 1;
  85160. const int min_shiftlimit = -max_shiftlimit - 1;
  85161. int log2cmax;
  85162. (void)frexp(cmax, &log2cmax);
  85163. log2cmax--;
  85164. *shift = (int)precision - log2cmax - 1;
  85165. if(*shift > max_shiftlimit)
  85166. *shift = max_shiftlimit;
  85167. else if(*shift < min_shiftlimit)
  85168. return 1;
  85169. }
  85170. if(*shift >= 0) {
  85171. FLAC__double error = 0.0;
  85172. FLAC__int32 q;
  85173. for(i = 0; i < order; i++) {
  85174. error += lp_coeff[i] * (1 << *shift);
  85175. #if 1 /* unfortunately lround() is C99 */
  85176. if(error >= 0.0)
  85177. q = (FLAC__int32)(error + 0.5);
  85178. else
  85179. q = (FLAC__int32)(error - 0.5);
  85180. #else
  85181. q = lround(error);
  85182. #endif
  85183. #ifdef FLAC__OVERFLOW_DETECT
  85184. if(q > qmax+1) /* we expect q==qmax+1 occasionally due to rounding */
  85185. 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]);
  85186. else if(q < qmin)
  85187. 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]);
  85188. #endif
  85189. if(q > qmax)
  85190. q = qmax;
  85191. else if(q < qmin)
  85192. q = qmin;
  85193. error -= q;
  85194. qlp_coeff[i] = q;
  85195. }
  85196. }
  85197. else {
  85198. const int nshift = -(*shift);
  85199. FLAC__double error = 0.0;
  85200. FLAC__int32 q;
  85201. #ifdef DEBUG
  85202. fprintf(stderr,"FLAC__lpc_quantize_coefficients: negative shift=%d order=%u cmax=%f\n", *shift, order, cmax);
  85203. #endif
  85204. for(i = 0; i < order; i++) {
  85205. error += lp_coeff[i] / (1 << nshift);
  85206. #if 1 /* unfortunately lround() is C99 */
  85207. if(error >= 0.0)
  85208. q = (FLAC__int32)(error + 0.5);
  85209. else
  85210. q = (FLAC__int32)(error - 0.5);
  85211. #else
  85212. q = lround(error);
  85213. #endif
  85214. #ifdef FLAC__OVERFLOW_DETECT
  85215. if(q > qmax+1) /* we expect q==qmax+1 occasionally due to rounding */
  85216. 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]);
  85217. else if(q < qmin)
  85218. 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]);
  85219. #endif
  85220. if(q > qmax)
  85221. q = qmax;
  85222. else if(q < qmin)
  85223. q = qmin;
  85224. error -= q;
  85225. qlp_coeff[i] = q;
  85226. }
  85227. *shift = 0;
  85228. }
  85229. return 0;
  85230. }
  85231. 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[])
  85232. #if defined(FLAC__OVERFLOW_DETECT) || !defined(FLAC__LPC_UNROLLED_FILTER_LOOPS)
  85233. {
  85234. FLAC__int64 sumo;
  85235. unsigned i, j;
  85236. FLAC__int32 sum;
  85237. const FLAC__int32 *history;
  85238. #ifdef FLAC__OVERFLOW_DETECT_VERBOSE
  85239. fprintf(stderr,"FLAC__lpc_compute_residual_from_qlp_coefficients: data_len=%d, order=%u, lpq=%d",data_len,order,lp_quantization);
  85240. for(i=0;i<order;i++)
  85241. fprintf(stderr,", q[%u]=%d",i,qlp_coeff[i]);
  85242. fprintf(stderr,"\n");
  85243. #endif
  85244. FLAC__ASSERT(order > 0);
  85245. for(i = 0; i < data_len; i++) {
  85246. sumo = 0;
  85247. sum = 0;
  85248. history = data;
  85249. for(j = 0; j < order; j++) {
  85250. sum += qlp_coeff[j] * (*(--history));
  85251. sumo += (FLAC__int64)qlp_coeff[j] * (FLAC__int64)(*history);
  85252. #if defined _MSC_VER
  85253. if(sumo > 2147483647I64 || sumo < -2147483648I64)
  85254. 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);
  85255. #else
  85256. if(sumo > 2147483647ll || sumo < -2147483648ll)
  85257. 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);
  85258. #endif
  85259. }
  85260. *(residual++) = *(data++) - (sum >> lp_quantization);
  85261. }
  85262. }
  85263. #else /* fully unrolled version for normal use */
  85264. {
  85265. int i;
  85266. FLAC__int32 sum;
  85267. FLAC__ASSERT(order > 0);
  85268. FLAC__ASSERT(order <= 32);
  85269. if(order <= 12) {
  85270. if(order > 8) {
  85271. if(order > 10) {
  85272. if(order == 12) {
  85273. for(i = 0; i < (int)data_len; i++) {
  85274. sum = 0;
  85275. sum += qlp_coeff[11] * data[i-12];
  85276. sum += qlp_coeff[10] * data[i-11];
  85277. sum += qlp_coeff[9] * data[i-10];
  85278. sum += qlp_coeff[8] * data[i-9];
  85279. sum += qlp_coeff[7] * data[i-8];
  85280. sum += qlp_coeff[6] * data[i-7];
  85281. sum += qlp_coeff[5] * data[i-6];
  85282. sum += qlp_coeff[4] * data[i-5];
  85283. sum += qlp_coeff[3] * data[i-4];
  85284. sum += qlp_coeff[2] * data[i-3];
  85285. sum += qlp_coeff[1] * data[i-2];
  85286. sum += qlp_coeff[0] * data[i-1];
  85287. residual[i] = data[i] - (sum >> lp_quantization);
  85288. }
  85289. }
  85290. else { /* order == 11 */
  85291. for(i = 0; i < (int)data_len; i++) {
  85292. sum = 0;
  85293. sum += qlp_coeff[10] * data[i-11];
  85294. sum += qlp_coeff[9] * data[i-10];
  85295. sum += qlp_coeff[8] * data[i-9];
  85296. sum += qlp_coeff[7] * data[i-8];
  85297. sum += qlp_coeff[6] * data[i-7];
  85298. sum += qlp_coeff[5] * data[i-6];
  85299. sum += qlp_coeff[4] * data[i-5];
  85300. sum += qlp_coeff[3] * data[i-4];
  85301. sum += qlp_coeff[2] * data[i-3];
  85302. sum += qlp_coeff[1] * data[i-2];
  85303. sum += qlp_coeff[0] * data[i-1];
  85304. residual[i] = data[i] - (sum >> lp_quantization);
  85305. }
  85306. }
  85307. }
  85308. else {
  85309. if(order == 10) {
  85310. for(i = 0; i < (int)data_len; i++) {
  85311. sum = 0;
  85312. sum += qlp_coeff[9] * data[i-10];
  85313. sum += qlp_coeff[8] * data[i-9];
  85314. sum += qlp_coeff[7] * data[i-8];
  85315. sum += qlp_coeff[6] * data[i-7];
  85316. sum += qlp_coeff[5] * data[i-6];
  85317. sum += qlp_coeff[4] * data[i-5];
  85318. sum += qlp_coeff[3] * data[i-4];
  85319. sum += qlp_coeff[2] * data[i-3];
  85320. sum += qlp_coeff[1] * data[i-2];
  85321. sum += qlp_coeff[0] * data[i-1];
  85322. residual[i] = data[i] - (sum >> lp_quantization);
  85323. }
  85324. }
  85325. else { /* order == 9 */
  85326. for(i = 0; i < (int)data_len; i++) {
  85327. sum = 0;
  85328. sum += qlp_coeff[8] * data[i-9];
  85329. sum += qlp_coeff[7] * data[i-8];
  85330. sum += qlp_coeff[6] * data[i-7];
  85331. sum += qlp_coeff[5] * data[i-6];
  85332. sum += qlp_coeff[4] * data[i-5];
  85333. sum += qlp_coeff[3] * data[i-4];
  85334. sum += qlp_coeff[2] * data[i-3];
  85335. sum += qlp_coeff[1] * data[i-2];
  85336. sum += qlp_coeff[0] * data[i-1];
  85337. residual[i] = data[i] - (sum >> lp_quantization);
  85338. }
  85339. }
  85340. }
  85341. }
  85342. else if(order > 4) {
  85343. if(order > 6) {
  85344. if(order == 8) {
  85345. for(i = 0; i < (int)data_len; i++) {
  85346. sum = 0;
  85347. sum += qlp_coeff[7] * data[i-8];
  85348. sum += qlp_coeff[6] * data[i-7];
  85349. sum += qlp_coeff[5] * data[i-6];
  85350. sum += qlp_coeff[4] * data[i-5];
  85351. sum += qlp_coeff[3] * data[i-4];
  85352. sum += qlp_coeff[2] * data[i-3];
  85353. sum += qlp_coeff[1] * data[i-2];
  85354. sum += qlp_coeff[0] * data[i-1];
  85355. residual[i] = data[i] - (sum >> lp_quantization);
  85356. }
  85357. }
  85358. else { /* order == 7 */
  85359. for(i = 0; i < (int)data_len; i++) {
  85360. sum = 0;
  85361. sum += qlp_coeff[6] * data[i-7];
  85362. sum += qlp_coeff[5] * data[i-6];
  85363. sum += qlp_coeff[4] * data[i-5];
  85364. sum += qlp_coeff[3] * data[i-4];
  85365. sum += qlp_coeff[2] * data[i-3];
  85366. sum += qlp_coeff[1] * data[i-2];
  85367. sum += qlp_coeff[0] * data[i-1];
  85368. residual[i] = data[i] - (sum >> lp_quantization);
  85369. }
  85370. }
  85371. }
  85372. else {
  85373. if(order == 6) {
  85374. for(i = 0; i < (int)data_len; i++) {
  85375. sum = 0;
  85376. sum += qlp_coeff[5] * data[i-6];
  85377. sum += qlp_coeff[4] * data[i-5];
  85378. sum += qlp_coeff[3] * data[i-4];
  85379. sum += qlp_coeff[2] * data[i-3];
  85380. sum += qlp_coeff[1] * data[i-2];
  85381. sum += qlp_coeff[0] * data[i-1];
  85382. residual[i] = data[i] - (sum >> lp_quantization);
  85383. }
  85384. }
  85385. else { /* order == 5 */
  85386. for(i = 0; i < (int)data_len; i++) {
  85387. sum = 0;
  85388. sum += qlp_coeff[4] * data[i-5];
  85389. sum += qlp_coeff[3] * data[i-4];
  85390. sum += qlp_coeff[2] * data[i-3];
  85391. sum += qlp_coeff[1] * data[i-2];
  85392. sum += qlp_coeff[0] * data[i-1];
  85393. residual[i] = data[i] - (sum >> lp_quantization);
  85394. }
  85395. }
  85396. }
  85397. }
  85398. else {
  85399. if(order > 2) {
  85400. if(order == 4) {
  85401. for(i = 0; i < (int)data_len; i++) {
  85402. sum = 0;
  85403. sum += qlp_coeff[3] * data[i-4];
  85404. sum += qlp_coeff[2] * data[i-3];
  85405. sum += qlp_coeff[1] * data[i-2];
  85406. sum += qlp_coeff[0] * data[i-1];
  85407. residual[i] = data[i] - (sum >> lp_quantization);
  85408. }
  85409. }
  85410. else { /* order == 3 */
  85411. for(i = 0; i < (int)data_len; i++) {
  85412. sum = 0;
  85413. sum += qlp_coeff[2] * data[i-3];
  85414. sum += qlp_coeff[1] * data[i-2];
  85415. sum += qlp_coeff[0] * data[i-1];
  85416. residual[i] = data[i] - (sum >> lp_quantization);
  85417. }
  85418. }
  85419. }
  85420. else {
  85421. if(order == 2) {
  85422. for(i = 0; i < (int)data_len; i++) {
  85423. sum = 0;
  85424. sum += qlp_coeff[1] * data[i-2];
  85425. sum += qlp_coeff[0] * data[i-1];
  85426. residual[i] = data[i] - (sum >> lp_quantization);
  85427. }
  85428. }
  85429. else { /* order == 1 */
  85430. for(i = 0; i < (int)data_len; i++)
  85431. residual[i] = data[i] - ((qlp_coeff[0] * data[i-1]) >> lp_quantization);
  85432. }
  85433. }
  85434. }
  85435. }
  85436. else { /* order > 12 */
  85437. for(i = 0; i < (int)data_len; i++) {
  85438. sum = 0;
  85439. switch(order) {
  85440. case 32: sum += qlp_coeff[31] * data[i-32];
  85441. case 31: sum += qlp_coeff[30] * data[i-31];
  85442. case 30: sum += qlp_coeff[29] * data[i-30];
  85443. case 29: sum += qlp_coeff[28] * data[i-29];
  85444. case 28: sum += qlp_coeff[27] * data[i-28];
  85445. case 27: sum += qlp_coeff[26] * data[i-27];
  85446. case 26: sum += qlp_coeff[25] * data[i-26];
  85447. case 25: sum += qlp_coeff[24] * data[i-25];
  85448. case 24: sum += qlp_coeff[23] * data[i-24];
  85449. case 23: sum += qlp_coeff[22] * data[i-23];
  85450. case 22: sum += qlp_coeff[21] * data[i-22];
  85451. case 21: sum += qlp_coeff[20] * data[i-21];
  85452. case 20: sum += qlp_coeff[19] * data[i-20];
  85453. case 19: sum += qlp_coeff[18] * data[i-19];
  85454. case 18: sum += qlp_coeff[17] * data[i-18];
  85455. case 17: sum += qlp_coeff[16] * data[i-17];
  85456. case 16: sum += qlp_coeff[15] * data[i-16];
  85457. case 15: sum += qlp_coeff[14] * data[i-15];
  85458. case 14: sum += qlp_coeff[13] * data[i-14];
  85459. case 13: sum += qlp_coeff[12] * data[i-13];
  85460. sum += qlp_coeff[11] * data[i-12];
  85461. sum += qlp_coeff[10] * data[i-11];
  85462. sum += qlp_coeff[ 9] * data[i-10];
  85463. sum += qlp_coeff[ 8] * data[i- 9];
  85464. sum += qlp_coeff[ 7] * data[i- 8];
  85465. sum += qlp_coeff[ 6] * data[i- 7];
  85466. sum += qlp_coeff[ 5] * data[i- 6];
  85467. sum += qlp_coeff[ 4] * data[i- 5];
  85468. sum += qlp_coeff[ 3] * data[i- 4];
  85469. sum += qlp_coeff[ 2] * data[i- 3];
  85470. sum += qlp_coeff[ 1] * data[i- 2];
  85471. sum += qlp_coeff[ 0] * data[i- 1];
  85472. }
  85473. residual[i] = data[i] - (sum >> lp_quantization);
  85474. }
  85475. }
  85476. }
  85477. #endif
  85478. 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[])
  85479. #if defined(FLAC__OVERFLOW_DETECT) || !defined(FLAC__LPC_UNROLLED_FILTER_LOOPS)
  85480. {
  85481. unsigned i, j;
  85482. FLAC__int64 sum;
  85483. const FLAC__int32 *history;
  85484. #ifdef FLAC__OVERFLOW_DETECT_VERBOSE
  85485. fprintf(stderr,"FLAC__lpc_compute_residual_from_qlp_coefficients_wide: data_len=%d, order=%u, lpq=%d",data_len,order,lp_quantization);
  85486. for(i=0;i<order;i++)
  85487. fprintf(stderr,", q[%u]=%d",i,qlp_coeff[i]);
  85488. fprintf(stderr,"\n");
  85489. #endif
  85490. FLAC__ASSERT(order > 0);
  85491. for(i = 0; i < data_len; i++) {
  85492. sum = 0;
  85493. history = data;
  85494. for(j = 0; j < order; j++)
  85495. sum += (FLAC__int64)qlp_coeff[j] * (FLAC__int64)(*(--history));
  85496. if(FLAC__bitmath_silog2_wide(sum >> lp_quantization) > 32) {
  85497. #if defined _MSC_VER
  85498. fprintf(stderr,"FLAC__lpc_compute_residual_from_qlp_coefficients_wide: OVERFLOW, i=%u, sum=%I64d\n", i, sum >> lp_quantization);
  85499. #else
  85500. fprintf(stderr,"FLAC__lpc_compute_residual_from_qlp_coefficients_wide: OVERFLOW, i=%u, sum=%lld\n", i, (long long)(sum >> lp_quantization));
  85501. #endif
  85502. break;
  85503. }
  85504. if(FLAC__bitmath_silog2_wide((FLAC__int64)(*data) - (sum >> lp_quantization)) > 32) {
  85505. #if defined _MSC_VER
  85506. 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));
  85507. #else
  85508. 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)));
  85509. #endif
  85510. break;
  85511. }
  85512. *(residual++) = *(data++) - (FLAC__int32)(sum >> lp_quantization);
  85513. }
  85514. }
  85515. #else /* fully unrolled version for normal use */
  85516. {
  85517. int i;
  85518. FLAC__int64 sum;
  85519. FLAC__ASSERT(order > 0);
  85520. FLAC__ASSERT(order <= 32);
  85521. if(order <= 12) {
  85522. if(order > 8) {
  85523. if(order > 10) {
  85524. if(order == 12) {
  85525. for(i = 0; i < (int)data_len; i++) {
  85526. sum = 0;
  85527. sum += qlp_coeff[11] * (FLAC__int64)data[i-12];
  85528. sum += qlp_coeff[10] * (FLAC__int64)data[i-11];
  85529. sum += qlp_coeff[9] * (FLAC__int64)data[i-10];
  85530. sum += qlp_coeff[8] * (FLAC__int64)data[i-9];
  85531. sum += qlp_coeff[7] * (FLAC__int64)data[i-8];
  85532. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  85533. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  85534. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  85535. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  85536. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  85537. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  85538. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  85539. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  85540. }
  85541. }
  85542. else { /* order == 11 */
  85543. for(i = 0; i < (int)data_len; i++) {
  85544. sum = 0;
  85545. sum += qlp_coeff[10] * (FLAC__int64)data[i-11];
  85546. sum += qlp_coeff[9] * (FLAC__int64)data[i-10];
  85547. sum += qlp_coeff[8] * (FLAC__int64)data[i-9];
  85548. sum += qlp_coeff[7] * (FLAC__int64)data[i-8];
  85549. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  85550. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  85551. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  85552. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  85553. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  85554. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  85555. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  85556. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  85557. }
  85558. }
  85559. }
  85560. else {
  85561. if(order == 10) {
  85562. for(i = 0; i < (int)data_len; i++) {
  85563. sum = 0;
  85564. sum += qlp_coeff[9] * (FLAC__int64)data[i-10];
  85565. sum += qlp_coeff[8] * (FLAC__int64)data[i-9];
  85566. sum += qlp_coeff[7] * (FLAC__int64)data[i-8];
  85567. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  85568. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  85569. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  85570. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  85571. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  85572. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  85573. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  85574. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  85575. }
  85576. }
  85577. else { /* order == 9 */
  85578. for(i = 0; i < (int)data_len; i++) {
  85579. sum = 0;
  85580. sum += qlp_coeff[8] * (FLAC__int64)data[i-9];
  85581. sum += qlp_coeff[7] * (FLAC__int64)data[i-8];
  85582. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  85583. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  85584. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  85585. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  85586. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  85587. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  85588. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  85589. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  85590. }
  85591. }
  85592. }
  85593. }
  85594. else if(order > 4) {
  85595. if(order > 6) {
  85596. if(order == 8) {
  85597. for(i = 0; i < (int)data_len; i++) {
  85598. sum = 0;
  85599. sum += qlp_coeff[7] * (FLAC__int64)data[i-8];
  85600. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  85601. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  85602. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  85603. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  85604. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  85605. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  85606. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  85607. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  85608. }
  85609. }
  85610. else { /* order == 7 */
  85611. for(i = 0; i < (int)data_len; i++) {
  85612. sum = 0;
  85613. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  85614. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  85615. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  85616. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  85617. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  85618. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  85619. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  85620. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  85621. }
  85622. }
  85623. }
  85624. else {
  85625. if(order == 6) {
  85626. for(i = 0; i < (int)data_len; i++) {
  85627. sum = 0;
  85628. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  85629. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  85630. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  85631. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  85632. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  85633. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  85634. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  85635. }
  85636. }
  85637. else { /* order == 5 */
  85638. for(i = 0; i < (int)data_len; i++) {
  85639. sum = 0;
  85640. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  85641. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  85642. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  85643. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  85644. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  85645. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  85646. }
  85647. }
  85648. }
  85649. }
  85650. else {
  85651. if(order > 2) {
  85652. if(order == 4) {
  85653. for(i = 0; i < (int)data_len; i++) {
  85654. sum = 0;
  85655. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  85656. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  85657. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  85658. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  85659. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  85660. }
  85661. }
  85662. else { /* order == 3 */
  85663. for(i = 0; i < (int)data_len; i++) {
  85664. sum = 0;
  85665. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  85666. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  85667. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  85668. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  85669. }
  85670. }
  85671. }
  85672. else {
  85673. if(order == 2) {
  85674. for(i = 0; i < (int)data_len; i++) {
  85675. sum = 0;
  85676. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  85677. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  85678. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  85679. }
  85680. }
  85681. else { /* order == 1 */
  85682. for(i = 0; i < (int)data_len; i++)
  85683. residual[i] = data[i] - (FLAC__int32)((qlp_coeff[0] * (FLAC__int64)data[i-1]) >> lp_quantization);
  85684. }
  85685. }
  85686. }
  85687. }
  85688. else { /* order > 12 */
  85689. for(i = 0; i < (int)data_len; i++) {
  85690. sum = 0;
  85691. switch(order) {
  85692. case 32: sum += qlp_coeff[31] * (FLAC__int64)data[i-32];
  85693. case 31: sum += qlp_coeff[30] * (FLAC__int64)data[i-31];
  85694. case 30: sum += qlp_coeff[29] * (FLAC__int64)data[i-30];
  85695. case 29: sum += qlp_coeff[28] * (FLAC__int64)data[i-29];
  85696. case 28: sum += qlp_coeff[27] * (FLAC__int64)data[i-28];
  85697. case 27: sum += qlp_coeff[26] * (FLAC__int64)data[i-27];
  85698. case 26: sum += qlp_coeff[25] * (FLAC__int64)data[i-26];
  85699. case 25: sum += qlp_coeff[24] * (FLAC__int64)data[i-25];
  85700. case 24: sum += qlp_coeff[23] * (FLAC__int64)data[i-24];
  85701. case 23: sum += qlp_coeff[22] * (FLAC__int64)data[i-23];
  85702. case 22: sum += qlp_coeff[21] * (FLAC__int64)data[i-22];
  85703. case 21: sum += qlp_coeff[20] * (FLAC__int64)data[i-21];
  85704. case 20: sum += qlp_coeff[19] * (FLAC__int64)data[i-20];
  85705. case 19: sum += qlp_coeff[18] * (FLAC__int64)data[i-19];
  85706. case 18: sum += qlp_coeff[17] * (FLAC__int64)data[i-18];
  85707. case 17: sum += qlp_coeff[16] * (FLAC__int64)data[i-17];
  85708. case 16: sum += qlp_coeff[15] * (FLAC__int64)data[i-16];
  85709. case 15: sum += qlp_coeff[14] * (FLAC__int64)data[i-15];
  85710. case 14: sum += qlp_coeff[13] * (FLAC__int64)data[i-14];
  85711. case 13: sum += qlp_coeff[12] * (FLAC__int64)data[i-13];
  85712. sum += qlp_coeff[11] * (FLAC__int64)data[i-12];
  85713. sum += qlp_coeff[10] * (FLAC__int64)data[i-11];
  85714. sum += qlp_coeff[ 9] * (FLAC__int64)data[i-10];
  85715. sum += qlp_coeff[ 8] * (FLAC__int64)data[i- 9];
  85716. sum += qlp_coeff[ 7] * (FLAC__int64)data[i- 8];
  85717. sum += qlp_coeff[ 6] * (FLAC__int64)data[i- 7];
  85718. sum += qlp_coeff[ 5] * (FLAC__int64)data[i- 6];
  85719. sum += qlp_coeff[ 4] * (FLAC__int64)data[i- 5];
  85720. sum += qlp_coeff[ 3] * (FLAC__int64)data[i- 4];
  85721. sum += qlp_coeff[ 2] * (FLAC__int64)data[i- 3];
  85722. sum += qlp_coeff[ 1] * (FLAC__int64)data[i- 2];
  85723. sum += qlp_coeff[ 0] * (FLAC__int64)data[i- 1];
  85724. }
  85725. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  85726. }
  85727. }
  85728. }
  85729. #endif
  85730. #endif /* !defined FLAC__INTEGER_ONLY_LIBRARY */
  85731. 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[])
  85732. #if defined(FLAC__OVERFLOW_DETECT) || !defined(FLAC__LPC_UNROLLED_FILTER_LOOPS)
  85733. {
  85734. FLAC__int64 sumo;
  85735. unsigned i, j;
  85736. FLAC__int32 sum;
  85737. const FLAC__int32 *r = residual, *history;
  85738. #ifdef FLAC__OVERFLOW_DETECT_VERBOSE
  85739. fprintf(stderr,"FLAC__lpc_restore_signal: data_len=%d, order=%u, lpq=%d",data_len,order,lp_quantization);
  85740. for(i=0;i<order;i++)
  85741. fprintf(stderr,", q[%u]=%d",i,qlp_coeff[i]);
  85742. fprintf(stderr,"\n");
  85743. #endif
  85744. FLAC__ASSERT(order > 0);
  85745. for(i = 0; i < data_len; i++) {
  85746. sumo = 0;
  85747. sum = 0;
  85748. history = data;
  85749. for(j = 0; j < order; j++) {
  85750. sum += qlp_coeff[j] * (*(--history));
  85751. sumo += (FLAC__int64)qlp_coeff[j] * (FLAC__int64)(*history);
  85752. #if defined _MSC_VER
  85753. if(sumo > 2147483647I64 || sumo < -2147483648I64)
  85754. 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);
  85755. #else
  85756. if(sumo > 2147483647ll || sumo < -2147483648ll)
  85757. 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);
  85758. #endif
  85759. }
  85760. *(data++) = *(r++) + (sum >> lp_quantization);
  85761. }
  85762. }
  85763. #else /* fully unrolled version for normal use */
  85764. {
  85765. int i;
  85766. FLAC__int32 sum;
  85767. FLAC__ASSERT(order > 0);
  85768. FLAC__ASSERT(order <= 32);
  85769. if(order <= 12) {
  85770. if(order > 8) {
  85771. if(order > 10) {
  85772. if(order == 12) {
  85773. for(i = 0; i < (int)data_len; i++) {
  85774. sum = 0;
  85775. sum += qlp_coeff[11] * data[i-12];
  85776. sum += qlp_coeff[10] * data[i-11];
  85777. sum += qlp_coeff[9] * data[i-10];
  85778. sum += qlp_coeff[8] * data[i-9];
  85779. sum += qlp_coeff[7] * data[i-8];
  85780. sum += qlp_coeff[6] * data[i-7];
  85781. sum += qlp_coeff[5] * data[i-6];
  85782. sum += qlp_coeff[4] * data[i-5];
  85783. sum += qlp_coeff[3] * data[i-4];
  85784. sum += qlp_coeff[2] * data[i-3];
  85785. sum += qlp_coeff[1] * data[i-2];
  85786. sum += qlp_coeff[0] * data[i-1];
  85787. data[i] = residual[i] + (sum >> lp_quantization);
  85788. }
  85789. }
  85790. else { /* order == 11 */
  85791. for(i = 0; i < (int)data_len; i++) {
  85792. sum = 0;
  85793. sum += qlp_coeff[10] * data[i-11];
  85794. sum += qlp_coeff[9] * data[i-10];
  85795. sum += qlp_coeff[8] * data[i-9];
  85796. sum += qlp_coeff[7] * data[i-8];
  85797. sum += qlp_coeff[6] * data[i-7];
  85798. sum += qlp_coeff[5] * data[i-6];
  85799. sum += qlp_coeff[4] * data[i-5];
  85800. sum += qlp_coeff[3] * data[i-4];
  85801. sum += qlp_coeff[2] * data[i-3];
  85802. sum += qlp_coeff[1] * data[i-2];
  85803. sum += qlp_coeff[0] * data[i-1];
  85804. data[i] = residual[i] + (sum >> lp_quantization);
  85805. }
  85806. }
  85807. }
  85808. else {
  85809. if(order == 10) {
  85810. for(i = 0; i < (int)data_len; i++) {
  85811. sum = 0;
  85812. sum += qlp_coeff[9] * data[i-10];
  85813. sum += qlp_coeff[8] * data[i-9];
  85814. sum += qlp_coeff[7] * data[i-8];
  85815. sum += qlp_coeff[6] * data[i-7];
  85816. sum += qlp_coeff[5] * data[i-6];
  85817. sum += qlp_coeff[4] * data[i-5];
  85818. sum += qlp_coeff[3] * data[i-4];
  85819. sum += qlp_coeff[2] * data[i-3];
  85820. sum += qlp_coeff[1] * data[i-2];
  85821. sum += qlp_coeff[0] * data[i-1];
  85822. data[i] = residual[i] + (sum >> lp_quantization);
  85823. }
  85824. }
  85825. else { /* order == 9 */
  85826. for(i = 0; i < (int)data_len; i++) {
  85827. sum = 0;
  85828. sum += qlp_coeff[8] * data[i-9];
  85829. sum += qlp_coeff[7] * data[i-8];
  85830. sum += qlp_coeff[6] * data[i-7];
  85831. sum += qlp_coeff[5] * data[i-6];
  85832. sum += qlp_coeff[4] * data[i-5];
  85833. sum += qlp_coeff[3] * data[i-4];
  85834. sum += qlp_coeff[2] * data[i-3];
  85835. sum += qlp_coeff[1] * data[i-2];
  85836. sum += qlp_coeff[0] * data[i-1];
  85837. data[i] = residual[i] + (sum >> lp_quantization);
  85838. }
  85839. }
  85840. }
  85841. }
  85842. else if(order > 4) {
  85843. if(order > 6) {
  85844. if(order == 8) {
  85845. for(i = 0; i < (int)data_len; i++) {
  85846. sum = 0;
  85847. sum += qlp_coeff[7] * data[i-8];
  85848. sum += qlp_coeff[6] * data[i-7];
  85849. sum += qlp_coeff[5] * data[i-6];
  85850. sum += qlp_coeff[4] * data[i-5];
  85851. sum += qlp_coeff[3] * data[i-4];
  85852. sum += qlp_coeff[2] * data[i-3];
  85853. sum += qlp_coeff[1] * data[i-2];
  85854. sum += qlp_coeff[0] * data[i-1];
  85855. data[i] = residual[i] + (sum >> lp_quantization);
  85856. }
  85857. }
  85858. else { /* order == 7 */
  85859. for(i = 0; i < (int)data_len; i++) {
  85860. sum = 0;
  85861. sum += qlp_coeff[6] * data[i-7];
  85862. sum += qlp_coeff[5] * data[i-6];
  85863. sum += qlp_coeff[4] * data[i-5];
  85864. sum += qlp_coeff[3] * data[i-4];
  85865. sum += qlp_coeff[2] * data[i-3];
  85866. sum += qlp_coeff[1] * data[i-2];
  85867. sum += qlp_coeff[0] * data[i-1];
  85868. data[i] = residual[i] + (sum >> lp_quantization);
  85869. }
  85870. }
  85871. }
  85872. else {
  85873. if(order == 6) {
  85874. for(i = 0; i < (int)data_len; i++) {
  85875. sum = 0;
  85876. sum += qlp_coeff[5] * data[i-6];
  85877. sum += qlp_coeff[4] * data[i-5];
  85878. sum += qlp_coeff[3] * data[i-4];
  85879. sum += qlp_coeff[2] * data[i-3];
  85880. sum += qlp_coeff[1] * data[i-2];
  85881. sum += qlp_coeff[0] * data[i-1];
  85882. data[i] = residual[i] + (sum >> lp_quantization);
  85883. }
  85884. }
  85885. else { /* order == 5 */
  85886. for(i = 0; i < (int)data_len; i++) {
  85887. sum = 0;
  85888. sum += qlp_coeff[4] * data[i-5];
  85889. sum += qlp_coeff[3] * data[i-4];
  85890. sum += qlp_coeff[2] * data[i-3];
  85891. sum += qlp_coeff[1] * data[i-2];
  85892. sum += qlp_coeff[0] * data[i-1];
  85893. data[i] = residual[i] + (sum >> lp_quantization);
  85894. }
  85895. }
  85896. }
  85897. }
  85898. else {
  85899. if(order > 2) {
  85900. if(order == 4) {
  85901. for(i = 0; i < (int)data_len; i++) {
  85902. sum = 0;
  85903. sum += qlp_coeff[3] * data[i-4];
  85904. sum += qlp_coeff[2] * data[i-3];
  85905. sum += qlp_coeff[1] * data[i-2];
  85906. sum += qlp_coeff[0] * data[i-1];
  85907. data[i] = residual[i] + (sum >> lp_quantization);
  85908. }
  85909. }
  85910. else { /* order == 3 */
  85911. for(i = 0; i < (int)data_len; i++) {
  85912. sum = 0;
  85913. sum += qlp_coeff[2] * data[i-3];
  85914. sum += qlp_coeff[1] * data[i-2];
  85915. sum += qlp_coeff[0] * data[i-1];
  85916. data[i] = residual[i] + (sum >> lp_quantization);
  85917. }
  85918. }
  85919. }
  85920. else {
  85921. if(order == 2) {
  85922. for(i = 0; i < (int)data_len; i++) {
  85923. sum = 0;
  85924. sum += qlp_coeff[1] * data[i-2];
  85925. sum += qlp_coeff[0] * data[i-1];
  85926. data[i] = residual[i] + (sum >> lp_quantization);
  85927. }
  85928. }
  85929. else { /* order == 1 */
  85930. for(i = 0; i < (int)data_len; i++)
  85931. data[i] = residual[i] + ((qlp_coeff[0] * data[i-1]) >> lp_quantization);
  85932. }
  85933. }
  85934. }
  85935. }
  85936. else { /* order > 12 */
  85937. for(i = 0; i < (int)data_len; i++) {
  85938. sum = 0;
  85939. switch(order) {
  85940. case 32: sum += qlp_coeff[31] * data[i-32];
  85941. case 31: sum += qlp_coeff[30] * data[i-31];
  85942. case 30: sum += qlp_coeff[29] * data[i-30];
  85943. case 29: sum += qlp_coeff[28] * data[i-29];
  85944. case 28: sum += qlp_coeff[27] * data[i-28];
  85945. case 27: sum += qlp_coeff[26] * data[i-27];
  85946. case 26: sum += qlp_coeff[25] * data[i-26];
  85947. case 25: sum += qlp_coeff[24] * data[i-25];
  85948. case 24: sum += qlp_coeff[23] * data[i-24];
  85949. case 23: sum += qlp_coeff[22] * data[i-23];
  85950. case 22: sum += qlp_coeff[21] * data[i-22];
  85951. case 21: sum += qlp_coeff[20] * data[i-21];
  85952. case 20: sum += qlp_coeff[19] * data[i-20];
  85953. case 19: sum += qlp_coeff[18] * data[i-19];
  85954. case 18: sum += qlp_coeff[17] * data[i-18];
  85955. case 17: sum += qlp_coeff[16] * data[i-17];
  85956. case 16: sum += qlp_coeff[15] * data[i-16];
  85957. case 15: sum += qlp_coeff[14] * data[i-15];
  85958. case 14: sum += qlp_coeff[13] * data[i-14];
  85959. case 13: sum += qlp_coeff[12] * data[i-13];
  85960. sum += qlp_coeff[11] * data[i-12];
  85961. sum += qlp_coeff[10] * data[i-11];
  85962. sum += qlp_coeff[ 9] * data[i-10];
  85963. sum += qlp_coeff[ 8] * data[i- 9];
  85964. sum += qlp_coeff[ 7] * data[i- 8];
  85965. sum += qlp_coeff[ 6] * data[i- 7];
  85966. sum += qlp_coeff[ 5] * data[i- 6];
  85967. sum += qlp_coeff[ 4] * data[i- 5];
  85968. sum += qlp_coeff[ 3] * data[i- 4];
  85969. sum += qlp_coeff[ 2] * data[i- 3];
  85970. sum += qlp_coeff[ 1] * data[i- 2];
  85971. sum += qlp_coeff[ 0] * data[i- 1];
  85972. }
  85973. data[i] = residual[i] + (sum >> lp_quantization);
  85974. }
  85975. }
  85976. }
  85977. #endif
  85978. 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[])
  85979. #if defined(FLAC__OVERFLOW_DETECT) || !defined(FLAC__LPC_UNROLLED_FILTER_LOOPS)
  85980. {
  85981. unsigned i, j;
  85982. FLAC__int64 sum;
  85983. const FLAC__int32 *r = residual, *history;
  85984. #ifdef FLAC__OVERFLOW_DETECT_VERBOSE
  85985. fprintf(stderr,"FLAC__lpc_restore_signal_wide: data_len=%d, order=%u, lpq=%d",data_len,order,lp_quantization);
  85986. for(i=0;i<order;i++)
  85987. fprintf(stderr,", q[%u]=%d",i,qlp_coeff[i]);
  85988. fprintf(stderr,"\n");
  85989. #endif
  85990. FLAC__ASSERT(order > 0);
  85991. for(i = 0; i < data_len; i++) {
  85992. sum = 0;
  85993. history = data;
  85994. for(j = 0; j < order; j++)
  85995. sum += (FLAC__int64)qlp_coeff[j] * (FLAC__int64)(*(--history));
  85996. if(FLAC__bitmath_silog2_wide(sum >> lp_quantization) > 32) {
  85997. #ifdef _MSC_VER
  85998. fprintf(stderr,"FLAC__lpc_restore_signal_wide: OVERFLOW, i=%u, sum=%I64d\n", i, sum >> lp_quantization);
  85999. #else
  86000. fprintf(stderr,"FLAC__lpc_restore_signal_wide: OVERFLOW, i=%u, sum=%lld\n", i, (long long)(sum >> lp_quantization));
  86001. #endif
  86002. break;
  86003. }
  86004. if(FLAC__bitmath_silog2_wide((FLAC__int64)(*r) + (sum >> lp_quantization)) > 32) {
  86005. #ifdef _MSC_VER
  86006. 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));
  86007. #else
  86008. 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)));
  86009. #endif
  86010. break;
  86011. }
  86012. *(data++) = *(r++) + (FLAC__int32)(sum >> lp_quantization);
  86013. }
  86014. }
  86015. #else /* fully unrolled version for normal use */
  86016. {
  86017. int i;
  86018. FLAC__int64 sum;
  86019. FLAC__ASSERT(order > 0);
  86020. FLAC__ASSERT(order <= 32);
  86021. if(order <= 12) {
  86022. if(order > 8) {
  86023. if(order > 10) {
  86024. if(order == 12) {
  86025. for(i = 0; i < (int)data_len; i++) {
  86026. sum = 0;
  86027. sum += qlp_coeff[11] * (FLAC__int64)data[i-12];
  86028. sum += qlp_coeff[10] * (FLAC__int64)data[i-11];
  86029. sum += qlp_coeff[9] * (FLAC__int64)data[i-10];
  86030. sum += qlp_coeff[8] * (FLAC__int64)data[i-9];
  86031. sum += qlp_coeff[7] * (FLAC__int64)data[i-8];
  86032. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  86033. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  86034. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  86035. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  86036. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  86037. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86038. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86039. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  86040. }
  86041. }
  86042. else { /* order == 11 */
  86043. for(i = 0; i < (int)data_len; i++) {
  86044. sum = 0;
  86045. sum += qlp_coeff[10] * (FLAC__int64)data[i-11];
  86046. sum += qlp_coeff[9] * (FLAC__int64)data[i-10];
  86047. sum += qlp_coeff[8] * (FLAC__int64)data[i-9];
  86048. sum += qlp_coeff[7] * (FLAC__int64)data[i-8];
  86049. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  86050. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  86051. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  86052. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  86053. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  86054. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86055. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86056. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  86057. }
  86058. }
  86059. }
  86060. else {
  86061. if(order == 10) {
  86062. for(i = 0; i < (int)data_len; i++) {
  86063. sum = 0;
  86064. sum += qlp_coeff[9] * (FLAC__int64)data[i-10];
  86065. sum += qlp_coeff[8] * (FLAC__int64)data[i-9];
  86066. sum += qlp_coeff[7] * (FLAC__int64)data[i-8];
  86067. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  86068. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  86069. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  86070. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  86071. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  86072. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86073. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86074. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  86075. }
  86076. }
  86077. else { /* order == 9 */
  86078. for(i = 0; i < (int)data_len; i++) {
  86079. sum = 0;
  86080. sum += qlp_coeff[8] * (FLAC__int64)data[i-9];
  86081. sum += qlp_coeff[7] * (FLAC__int64)data[i-8];
  86082. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  86083. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  86084. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  86085. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  86086. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  86087. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86088. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86089. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  86090. }
  86091. }
  86092. }
  86093. }
  86094. else if(order > 4) {
  86095. if(order > 6) {
  86096. if(order == 8) {
  86097. for(i = 0; i < (int)data_len; i++) {
  86098. sum = 0;
  86099. sum += qlp_coeff[7] * (FLAC__int64)data[i-8];
  86100. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  86101. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  86102. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  86103. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  86104. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  86105. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86106. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86107. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  86108. }
  86109. }
  86110. else { /* order == 7 */
  86111. for(i = 0; i < (int)data_len; i++) {
  86112. sum = 0;
  86113. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  86114. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  86115. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  86116. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  86117. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  86118. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86119. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86120. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  86121. }
  86122. }
  86123. }
  86124. else {
  86125. if(order == 6) {
  86126. for(i = 0; i < (int)data_len; i++) {
  86127. sum = 0;
  86128. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  86129. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  86130. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  86131. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  86132. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86133. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86134. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  86135. }
  86136. }
  86137. else { /* order == 5 */
  86138. for(i = 0; i < (int)data_len; i++) {
  86139. sum = 0;
  86140. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  86141. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  86142. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  86143. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86144. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86145. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  86146. }
  86147. }
  86148. }
  86149. }
  86150. else {
  86151. if(order > 2) {
  86152. if(order == 4) {
  86153. for(i = 0; i < (int)data_len; i++) {
  86154. sum = 0;
  86155. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  86156. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  86157. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86158. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86159. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  86160. }
  86161. }
  86162. else { /* order == 3 */
  86163. for(i = 0; i < (int)data_len; i++) {
  86164. sum = 0;
  86165. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  86166. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86167. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86168. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  86169. }
  86170. }
  86171. }
  86172. else {
  86173. if(order == 2) {
  86174. for(i = 0; i < (int)data_len; i++) {
  86175. sum = 0;
  86176. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86177. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86178. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  86179. }
  86180. }
  86181. else { /* order == 1 */
  86182. for(i = 0; i < (int)data_len; i++)
  86183. data[i] = residual[i] + (FLAC__int32)((qlp_coeff[0] * (FLAC__int64)data[i-1]) >> lp_quantization);
  86184. }
  86185. }
  86186. }
  86187. }
  86188. else { /* order > 12 */
  86189. for(i = 0; i < (int)data_len; i++) {
  86190. sum = 0;
  86191. switch(order) {
  86192. case 32: sum += qlp_coeff[31] * (FLAC__int64)data[i-32];
  86193. case 31: sum += qlp_coeff[30] * (FLAC__int64)data[i-31];
  86194. case 30: sum += qlp_coeff[29] * (FLAC__int64)data[i-30];
  86195. case 29: sum += qlp_coeff[28] * (FLAC__int64)data[i-29];
  86196. case 28: sum += qlp_coeff[27] * (FLAC__int64)data[i-28];
  86197. case 27: sum += qlp_coeff[26] * (FLAC__int64)data[i-27];
  86198. case 26: sum += qlp_coeff[25] * (FLAC__int64)data[i-26];
  86199. case 25: sum += qlp_coeff[24] * (FLAC__int64)data[i-25];
  86200. case 24: sum += qlp_coeff[23] * (FLAC__int64)data[i-24];
  86201. case 23: sum += qlp_coeff[22] * (FLAC__int64)data[i-23];
  86202. case 22: sum += qlp_coeff[21] * (FLAC__int64)data[i-22];
  86203. case 21: sum += qlp_coeff[20] * (FLAC__int64)data[i-21];
  86204. case 20: sum += qlp_coeff[19] * (FLAC__int64)data[i-20];
  86205. case 19: sum += qlp_coeff[18] * (FLAC__int64)data[i-19];
  86206. case 18: sum += qlp_coeff[17] * (FLAC__int64)data[i-18];
  86207. case 17: sum += qlp_coeff[16] * (FLAC__int64)data[i-17];
  86208. case 16: sum += qlp_coeff[15] * (FLAC__int64)data[i-16];
  86209. case 15: sum += qlp_coeff[14] * (FLAC__int64)data[i-15];
  86210. case 14: sum += qlp_coeff[13] * (FLAC__int64)data[i-14];
  86211. case 13: sum += qlp_coeff[12] * (FLAC__int64)data[i-13];
  86212. sum += qlp_coeff[11] * (FLAC__int64)data[i-12];
  86213. sum += qlp_coeff[10] * (FLAC__int64)data[i-11];
  86214. sum += qlp_coeff[ 9] * (FLAC__int64)data[i-10];
  86215. sum += qlp_coeff[ 8] * (FLAC__int64)data[i- 9];
  86216. sum += qlp_coeff[ 7] * (FLAC__int64)data[i- 8];
  86217. sum += qlp_coeff[ 6] * (FLAC__int64)data[i- 7];
  86218. sum += qlp_coeff[ 5] * (FLAC__int64)data[i- 6];
  86219. sum += qlp_coeff[ 4] * (FLAC__int64)data[i- 5];
  86220. sum += qlp_coeff[ 3] * (FLAC__int64)data[i- 4];
  86221. sum += qlp_coeff[ 2] * (FLAC__int64)data[i- 3];
  86222. sum += qlp_coeff[ 1] * (FLAC__int64)data[i- 2];
  86223. sum += qlp_coeff[ 0] * (FLAC__int64)data[i- 1];
  86224. }
  86225. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  86226. }
  86227. }
  86228. }
  86229. #endif
  86230. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  86231. FLAC__double FLAC__lpc_compute_expected_bits_per_residual_sample(FLAC__double lpc_error, unsigned total_samples)
  86232. {
  86233. FLAC__double error_scale;
  86234. FLAC__ASSERT(total_samples > 0);
  86235. error_scale = 0.5 * M_LN2 * M_LN2 / (FLAC__double)total_samples;
  86236. return FLAC__lpc_compute_expected_bits_per_residual_sample_with_error_scale(lpc_error, error_scale);
  86237. }
  86238. FLAC__double FLAC__lpc_compute_expected_bits_per_residual_sample_with_error_scale(FLAC__double lpc_error, FLAC__double error_scale)
  86239. {
  86240. if(lpc_error > 0.0) {
  86241. FLAC__double bps = (FLAC__double)0.5 * log(error_scale * lpc_error) / M_LN2;
  86242. if(bps >= 0.0)
  86243. return bps;
  86244. else
  86245. return 0.0;
  86246. }
  86247. else if(lpc_error < 0.0) { /* error should not be negative but can happen due to inadequate floating-point resolution */
  86248. return 1e32;
  86249. }
  86250. else {
  86251. return 0.0;
  86252. }
  86253. }
  86254. unsigned FLAC__lpc_compute_best_order(const FLAC__double lpc_error[], unsigned max_order, unsigned total_samples, unsigned overhead_bits_per_order)
  86255. {
  86256. 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 */
  86257. FLAC__double bits, best_bits, error_scale;
  86258. FLAC__ASSERT(max_order > 0);
  86259. FLAC__ASSERT(total_samples > 0);
  86260. error_scale = 0.5 * M_LN2 * M_LN2 / (FLAC__double)total_samples;
  86261. best_index = 0;
  86262. best_bits = (unsigned)(-1);
  86263. for(index = 0, order = 1; index < max_order; index++, order++) {
  86264. 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);
  86265. if(bits < best_bits) {
  86266. best_index = index;
  86267. best_bits = bits;
  86268. }
  86269. }
  86270. return best_index+1; /* +1 since index of lpc_error[] is order-1 */
  86271. }
  86272. #endif /* !defined FLAC__INTEGER_ONLY_LIBRARY */
  86273. #endif
  86274. /*** End of inlined file: lpc_flac.c ***/
  86275. /*** Start of inlined file: md5.c ***/
  86276. /*** Start of inlined file: juce_FlacHeader.h ***/
  86277. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  86278. // tasks..
  86279. #define VERSION "1.2.1"
  86280. #define FLAC__NO_DLL 1
  86281. #if JUCE_MSVC
  86282. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  86283. #endif
  86284. #if JUCE_MAC
  86285. #define FLAC__SYS_DARWIN 1
  86286. #endif
  86287. /*** End of inlined file: juce_FlacHeader.h ***/
  86288. #if JUCE_USE_FLAC
  86289. #if HAVE_CONFIG_H
  86290. # include <config.h>
  86291. #endif
  86292. #include <stdlib.h> /* for malloc() */
  86293. #include <string.h> /* for memcpy() */
  86294. /*** Start of inlined file: md5.h ***/
  86295. #ifndef FLAC__PRIVATE__MD5_H
  86296. #define FLAC__PRIVATE__MD5_H
  86297. typedef struct {
  86298. FLAC__uint32 in[16];
  86299. FLAC__uint32 buf[4];
  86300. FLAC__uint32 bytes[2];
  86301. FLAC__byte *internal_buf;
  86302. size_t capacity;
  86303. } FLAC__MD5Context;
  86304. void FLAC__MD5Init(FLAC__MD5Context *context);
  86305. void FLAC__MD5Final(FLAC__byte digest[16], FLAC__MD5Context *context);
  86306. FLAC__bool FLAC__MD5Accumulate(FLAC__MD5Context *ctx, const FLAC__int32 * const signal[], unsigned channels, unsigned samples, unsigned bytes_per_sample);
  86307. #endif
  86308. /*** End of inlined file: md5.h ***/
  86309. #ifndef FLaC__INLINE
  86310. #define FLaC__INLINE
  86311. #endif
  86312. #define F1(x, y, z) (z ^ (x & (y ^ z)))
  86313. #define F2(x, y, z) F1(z, x, y)
  86314. #define F3(x, y, z) (x ^ y ^ z)
  86315. #define F4(x, y, z) (y ^ (x | ~z))
  86316. #define MD5STEP(f,w,x,y,z,in,s) \
  86317. (w += f(x,y,z) + in, w = (w<<s | w>>(32-s)) + x)
  86318. static void FLAC__MD5Transform(FLAC__uint32 buf[4], FLAC__uint32 const in[16])
  86319. {
  86320. register FLAC__uint32 a, b, c, d;
  86321. a = buf[0];
  86322. b = buf[1];
  86323. c = buf[2];
  86324. d = buf[3];
  86325. MD5STEP(F1, a, b, c, d, in[0] + 0xd76aa478, 7);
  86326. MD5STEP(F1, d, a, b, c, in[1] + 0xe8c7b756, 12);
  86327. MD5STEP(F1, c, d, a, b, in[2] + 0x242070db, 17);
  86328. MD5STEP(F1, b, c, d, a, in[3] + 0xc1bdceee, 22);
  86329. MD5STEP(F1, a, b, c, d, in[4] + 0xf57c0faf, 7);
  86330. MD5STEP(F1, d, a, b, c, in[5] + 0x4787c62a, 12);
  86331. MD5STEP(F1, c, d, a, b, in[6] + 0xa8304613, 17);
  86332. MD5STEP(F1, b, c, d, a, in[7] + 0xfd469501, 22);
  86333. MD5STEP(F1, a, b, c, d, in[8] + 0x698098d8, 7);
  86334. MD5STEP(F1, d, a, b, c, in[9] + 0x8b44f7af, 12);
  86335. MD5STEP(F1, c, d, a, b, in[10] + 0xffff5bb1, 17);
  86336. MD5STEP(F1, b, c, d, a, in[11] + 0x895cd7be, 22);
  86337. MD5STEP(F1, a, b, c, d, in[12] + 0x6b901122, 7);
  86338. MD5STEP(F1, d, a, b, c, in[13] + 0xfd987193, 12);
  86339. MD5STEP(F1, c, d, a, b, in[14] + 0xa679438e, 17);
  86340. MD5STEP(F1, b, c, d, a, in[15] + 0x49b40821, 22);
  86341. MD5STEP(F2, a, b, c, d, in[1] + 0xf61e2562, 5);
  86342. MD5STEP(F2, d, a, b, c, in[6] + 0xc040b340, 9);
  86343. MD5STEP(F2, c, d, a, b, in[11] + 0x265e5a51, 14);
  86344. MD5STEP(F2, b, c, d, a, in[0] + 0xe9b6c7aa, 20);
  86345. MD5STEP(F2, a, b, c, d, in[5] + 0xd62f105d, 5);
  86346. MD5STEP(F2, d, a, b, c, in[10] + 0x02441453, 9);
  86347. MD5STEP(F2, c, d, a, b, in[15] + 0xd8a1e681, 14);
  86348. MD5STEP(F2, b, c, d, a, in[4] + 0xe7d3fbc8, 20);
  86349. MD5STEP(F2, a, b, c, d, in[9] + 0x21e1cde6, 5);
  86350. MD5STEP(F2, d, a, b, c, in[14] + 0xc33707d6, 9);
  86351. MD5STEP(F2, c, d, a, b, in[3] + 0xf4d50d87, 14);
  86352. MD5STEP(F2, b, c, d, a, in[8] + 0x455a14ed, 20);
  86353. MD5STEP(F2, a, b, c, d, in[13] + 0xa9e3e905, 5);
  86354. MD5STEP(F2, d, a, b, c, in[2] + 0xfcefa3f8, 9);
  86355. MD5STEP(F2, c, d, a, b, in[7] + 0x676f02d9, 14);
  86356. MD5STEP(F2, b, c, d, a, in[12] + 0x8d2a4c8a, 20);
  86357. MD5STEP(F3, a, b, c, d, in[5] + 0xfffa3942, 4);
  86358. MD5STEP(F3, d, a, b, c, in[8] + 0x8771f681, 11);
  86359. MD5STEP(F3, c, d, a, b, in[11] + 0x6d9d6122, 16);
  86360. MD5STEP(F3, b, c, d, a, in[14] + 0xfde5380c, 23);
  86361. MD5STEP(F3, a, b, c, d, in[1] + 0xa4beea44, 4);
  86362. MD5STEP(F3, d, a, b, c, in[4] + 0x4bdecfa9, 11);
  86363. MD5STEP(F3, c, d, a, b, in[7] + 0xf6bb4b60, 16);
  86364. MD5STEP(F3, b, c, d, a, in[10] + 0xbebfbc70, 23);
  86365. MD5STEP(F3, a, b, c, d, in[13] + 0x289b7ec6, 4);
  86366. MD5STEP(F3, d, a, b, c, in[0] + 0xeaa127fa, 11);
  86367. MD5STEP(F3, c, d, a, b, in[3] + 0xd4ef3085, 16);
  86368. MD5STEP(F3, b, c, d, a, in[6] + 0x04881d05, 23);
  86369. MD5STEP(F3, a, b, c, d, in[9] + 0xd9d4d039, 4);
  86370. MD5STEP(F3, d, a, b, c, in[12] + 0xe6db99e5, 11);
  86371. MD5STEP(F3, c, d, a, b, in[15] + 0x1fa27cf8, 16);
  86372. MD5STEP(F3, b, c, d, a, in[2] + 0xc4ac5665, 23);
  86373. MD5STEP(F4, a, b, c, d, in[0] + 0xf4292244, 6);
  86374. MD5STEP(F4, d, a, b, c, in[7] + 0x432aff97, 10);
  86375. MD5STEP(F4, c, d, a, b, in[14] + 0xab9423a7, 15);
  86376. MD5STEP(F4, b, c, d, a, in[5] + 0xfc93a039, 21);
  86377. MD5STEP(F4, a, b, c, d, in[12] + 0x655b59c3, 6);
  86378. MD5STEP(F4, d, a, b, c, in[3] + 0x8f0ccc92, 10);
  86379. MD5STEP(F4, c, d, a, b, in[10] + 0xffeff47d, 15);
  86380. MD5STEP(F4, b, c, d, a, in[1] + 0x85845dd1, 21);
  86381. MD5STEP(F4, a, b, c, d, in[8] + 0x6fa87e4f, 6);
  86382. MD5STEP(F4, d, a, b, c, in[15] + 0xfe2ce6e0, 10);
  86383. MD5STEP(F4, c, d, a, b, in[6] + 0xa3014314, 15);
  86384. MD5STEP(F4, b, c, d, a, in[13] + 0x4e0811a1, 21);
  86385. MD5STEP(F4, a, b, c, d, in[4] + 0xf7537e82, 6);
  86386. MD5STEP(F4, d, a, b, c, in[11] + 0xbd3af235, 10);
  86387. MD5STEP(F4, c, d, a, b, in[2] + 0x2ad7d2bb, 15);
  86388. MD5STEP(F4, b, c, d, a, in[9] + 0xeb86d391, 21);
  86389. buf[0] += a;
  86390. buf[1] += b;
  86391. buf[2] += c;
  86392. buf[3] += d;
  86393. }
  86394. #if WORDS_BIGENDIAN
  86395. //@@@@@@ OPT: use bswap/intrinsics
  86396. static void byteSwap(FLAC__uint32 *buf, unsigned words)
  86397. {
  86398. register FLAC__uint32 x;
  86399. do {
  86400. x = *buf;
  86401. x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff);
  86402. *buf++ = (x >> 16) | (x << 16);
  86403. } while (--words);
  86404. }
  86405. static void byteSwapX16(FLAC__uint32 *buf)
  86406. {
  86407. register FLAC__uint32 x;
  86408. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86409. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86410. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86411. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86412. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86413. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86414. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86415. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86416. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86417. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86418. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86419. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86420. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86421. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86422. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86423. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf = (x >> 16) | (x << 16);
  86424. }
  86425. #else
  86426. #define byteSwap(buf, words)
  86427. #define byteSwapX16(buf)
  86428. #endif
  86429. static void FLAC__MD5Update(FLAC__MD5Context *ctx, FLAC__byte const *buf, unsigned len)
  86430. {
  86431. FLAC__uint32 t;
  86432. t = ctx->bytes[0];
  86433. if ((ctx->bytes[0] = t + len) < t)
  86434. ctx->bytes[1]++; /* Carry from low to high */
  86435. t = 64 - (t & 0x3f); /* Space available in ctx->in (at least 1) */
  86436. if (t > len) {
  86437. memcpy((FLAC__byte *)ctx->in + 64 - t, buf, len);
  86438. return;
  86439. }
  86440. memcpy((FLAC__byte *)ctx->in + 64 - t, buf, t);
  86441. byteSwapX16(ctx->in);
  86442. FLAC__MD5Transform(ctx->buf, ctx->in);
  86443. buf += t;
  86444. len -= t;
  86445. while (len >= 64) {
  86446. memcpy(ctx->in, buf, 64);
  86447. byteSwapX16(ctx->in);
  86448. FLAC__MD5Transform(ctx->buf, ctx->in);
  86449. buf += 64;
  86450. len -= 64;
  86451. }
  86452. memcpy(ctx->in, buf, len);
  86453. }
  86454. void FLAC__MD5Init(FLAC__MD5Context *ctx)
  86455. {
  86456. ctx->buf[0] = 0x67452301;
  86457. ctx->buf[1] = 0xefcdab89;
  86458. ctx->buf[2] = 0x98badcfe;
  86459. ctx->buf[3] = 0x10325476;
  86460. ctx->bytes[0] = 0;
  86461. ctx->bytes[1] = 0;
  86462. ctx->internal_buf = 0;
  86463. ctx->capacity = 0;
  86464. }
  86465. void FLAC__MD5Final(FLAC__byte digest[16], FLAC__MD5Context *ctx)
  86466. {
  86467. int count = ctx->bytes[0] & 0x3f; /* Number of bytes in ctx->in */
  86468. FLAC__byte *p = (FLAC__byte *)ctx->in + count;
  86469. *p++ = 0x80;
  86470. count = 56 - 1 - count;
  86471. if (count < 0) { /* Padding forces an extra block */
  86472. memset(p, 0, count + 8);
  86473. byteSwapX16(ctx->in);
  86474. FLAC__MD5Transform(ctx->buf, ctx->in);
  86475. p = (FLAC__byte *)ctx->in;
  86476. count = 56;
  86477. }
  86478. memset(p, 0, count);
  86479. byteSwap(ctx->in, 14);
  86480. ctx->in[14] = ctx->bytes[0] << 3;
  86481. ctx->in[15] = ctx->bytes[1] << 3 | ctx->bytes[0] >> 29;
  86482. FLAC__MD5Transform(ctx->buf, ctx->in);
  86483. byteSwap(ctx->buf, 4);
  86484. memcpy(digest, ctx->buf, 16);
  86485. memset(ctx, 0, sizeof(ctx)); /* In case it's sensitive */
  86486. if(0 != ctx->internal_buf) {
  86487. free(ctx->internal_buf);
  86488. ctx->internal_buf = 0;
  86489. ctx->capacity = 0;
  86490. }
  86491. }
  86492. static void format_input_(FLAC__byte *buf, const FLAC__int32 * const signal[], unsigned channels, unsigned samples, unsigned bytes_per_sample)
  86493. {
  86494. unsigned channel, sample;
  86495. register FLAC__int32 a_word;
  86496. register FLAC__byte *buf_ = buf;
  86497. #if WORDS_BIGENDIAN
  86498. #else
  86499. if(channels == 2 && bytes_per_sample == 2) {
  86500. FLAC__int16 *buf1_ = ((FLAC__int16*)buf_) + 1;
  86501. memcpy(buf_, signal[0], sizeof(FLAC__int32) * samples);
  86502. for(sample = 0; sample < samples; sample++, buf1_+=2)
  86503. *buf1_ = (FLAC__int16)signal[1][sample];
  86504. }
  86505. else if(channels == 1 && bytes_per_sample == 2) {
  86506. FLAC__int16 *buf1_ = (FLAC__int16*)buf_;
  86507. for(sample = 0; sample < samples; sample++)
  86508. *buf1_++ = (FLAC__int16)signal[0][sample];
  86509. }
  86510. else
  86511. #endif
  86512. if(bytes_per_sample == 2) {
  86513. if(channels == 2) {
  86514. for(sample = 0; sample < samples; sample++) {
  86515. a_word = signal[0][sample];
  86516. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  86517. *buf_++ = (FLAC__byte)a_word;
  86518. a_word = signal[1][sample];
  86519. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  86520. *buf_++ = (FLAC__byte)a_word;
  86521. }
  86522. }
  86523. else if(channels == 1) {
  86524. for(sample = 0; sample < samples; sample++) {
  86525. a_word = signal[0][sample];
  86526. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  86527. *buf_++ = (FLAC__byte)a_word;
  86528. }
  86529. }
  86530. else {
  86531. for(sample = 0; sample < samples; sample++) {
  86532. for(channel = 0; channel < channels; channel++) {
  86533. a_word = signal[channel][sample];
  86534. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  86535. *buf_++ = (FLAC__byte)a_word;
  86536. }
  86537. }
  86538. }
  86539. }
  86540. else if(bytes_per_sample == 3) {
  86541. if(channels == 2) {
  86542. for(sample = 0; sample < samples; sample++) {
  86543. a_word = signal[0][sample];
  86544. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  86545. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  86546. *buf_++ = (FLAC__byte)a_word;
  86547. a_word = signal[1][sample];
  86548. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  86549. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  86550. *buf_++ = (FLAC__byte)a_word;
  86551. }
  86552. }
  86553. else if(channels == 1) {
  86554. for(sample = 0; sample < samples; sample++) {
  86555. a_word = signal[0][sample];
  86556. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  86557. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  86558. *buf_++ = (FLAC__byte)a_word;
  86559. }
  86560. }
  86561. else {
  86562. for(sample = 0; sample < samples; sample++) {
  86563. for(channel = 0; channel < channels; channel++) {
  86564. a_word = signal[channel][sample];
  86565. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  86566. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  86567. *buf_++ = (FLAC__byte)a_word;
  86568. }
  86569. }
  86570. }
  86571. }
  86572. else if(bytes_per_sample == 1) {
  86573. if(channels == 2) {
  86574. for(sample = 0; sample < samples; sample++) {
  86575. a_word = signal[0][sample];
  86576. *buf_++ = (FLAC__byte)a_word;
  86577. a_word = signal[1][sample];
  86578. *buf_++ = (FLAC__byte)a_word;
  86579. }
  86580. }
  86581. else if(channels == 1) {
  86582. for(sample = 0; sample < samples; sample++) {
  86583. a_word = signal[0][sample];
  86584. *buf_++ = (FLAC__byte)a_word;
  86585. }
  86586. }
  86587. else {
  86588. for(sample = 0; sample < samples; sample++) {
  86589. for(channel = 0; channel < channels; channel++) {
  86590. a_word = signal[channel][sample];
  86591. *buf_++ = (FLAC__byte)a_word;
  86592. }
  86593. }
  86594. }
  86595. }
  86596. else { /* bytes_per_sample == 4, maybe optimize more later */
  86597. for(sample = 0; sample < samples; sample++) {
  86598. for(channel = 0; channel < channels; channel++) {
  86599. a_word = signal[channel][sample];
  86600. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  86601. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  86602. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  86603. *buf_++ = (FLAC__byte)a_word;
  86604. }
  86605. }
  86606. }
  86607. }
  86608. FLAC__bool FLAC__MD5Accumulate(FLAC__MD5Context *ctx, const FLAC__int32 * const signal[], unsigned channels, unsigned samples, unsigned bytes_per_sample)
  86609. {
  86610. const size_t bytes_needed = (size_t)channels * (size_t)samples * (size_t)bytes_per_sample;
  86611. if((size_t)channels > SIZE_MAX / (size_t)bytes_per_sample)
  86612. return false;
  86613. if((size_t)channels * (size_t)bytes_per_sample > SIZE_MAX / (size_t)samples)
  86614. return false;
  86615. if(ctx->capacity < bytes_needed) {
  86616. FLAC__byte *tmp = (FLAC__byte*)realloc(ctx->internal_buf, bytes_needed);
  86617. if(0 == tmp) {
  86618. free(ctx->internal_buf);
  86619. if(0 == (ctx->internal_buf = (FLAC__byte*)safe_malloc_(bytes_needed)))
  86620. return false;
  86621. }
  86622. ctx->internal_buf = tmp;
  86623. ctx->capacity = bytes_needed;
  86624. }
  86625. format_input_(ctx->internal_buf, signal, channels, samples, bytes_per_sample);
  86626. FLAC__MD5Update(ctx, ctx->internal_buf, bytes_needed);
  86627. return true;
  86628. }
  86629. #endif
  86630. /*** End of inlined file: md5.c ***/
  86631. /*** Start of inlined file: memory.c ***/
  86632. /*** Start of inlined file: juce_FlacHeader.h ***/
  86633. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  86634. // tasks..
  86635. #define VERSION "1.2.1"
  86636. #define FLAC__NO_DLL 1
  86637. #if JUCE_MSVC
  86638. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  86639. #endif
  86640. #if JUCE_MAC
  86641. #define FLAC__SYS_DARWIN 1
  86642. #endif
  86643. /*** End of inlined file: juce_FlacHeader.h ***/
  86644. #if JUCE_USE_FLAC
  86645. #if HAVE_CONFIG_H
  86646. # include <config.h>
  86647. #endif
  86648. /*** Start of inlined file: memory.h ***/
  86649. #ifndef FLAC__PRIVATE__MEMORY_H
  86650. #define FLAC__PRIVATE__MEMORY_H
  86651. #ifdef HAVE_CONFIG_H
  86652. #include <config.h>
  86653. #endif
  86654. #include <stdlib.h> /* for size_t */
  86655. void *FLAC__memory_alloc_aligned(size_t bytes, void **aligned_address);
  86656. FLAC__bool FLAC__memory_alloc_aligned_int32_array(unsigned elements, FLAC__int32 **unaligned_pointer, FLAC__int32 **aligned_pointer);
  86657. FLAC__bool FLAC__memory_alloc_aligned_uint32_array(unsigned elements, FLAC__uint32 **unaligned_pointer, FLAC__uint32 **aligned_pointer);
  86658. FLAC__bool FLAC__memory_alloc_aligned_uint64_array(unsigned elements, FLAC__uint64 **unaligned_pointer, FLAC__uint64 **aligned_pointer);
  86659. FLAC__bool FLAC__memory_alloc_aligned_unsigned_array(unsigned elements, unsigned **unaligned_pointer, unsigned **aligned_pointer);
  86660. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  86661. FLAC__bool FLAC__memory_alloc_aligned_real_array(unsigned elements, FLAC__real **unaligned_pointer, FLAC__real **aligned_pointer);
  86662. #endif
  86663. #endif
  86664. /*** End of inlined file: memory.h ***/
  86665. void *FLAC__memory_alloc_aligned(size_t bytes, void **aligned_address)
  86666. {
  86667. void *x;
  86668. FLAC__ASSERT(0 != aligned_address);
  86669. #ifdef FLAC__ALIGN_MALLOC_DATA
  86670. x = safe_malloc_add_2op_(bytes, /*+*/31);
  86671. #ifdef SIZEOF_VOIDP
  86672. #if SIZEOF_VOIDP == 4
  86673. *aligned_address = (void*)(((unsigned)x + 31) & -32);
  86674. #elif SIZEOF_VOIDP == 8
  86675. *aligned_address = (void*)(((FLAC__uint64)x + 31) & (FLAC__uint64)(-((FLAC__int64)32)));
  86676. #else
  86677. # error Unsupported sizeof(void*)
  86678. #endif
  86679. #else
  86680. if(sizeof(void*) == sizeof(unsigned))
  86681. *aligned_address = (void*)(((unsigned)x + 31) & -32);
  86682. else if(sizeof(void*) == sizeof(FLAC__uint64))
  86683. *aligned_address = (void*)(((FLAC__uint64)x + 31) & (FLAC__uint64)(-((FLAC__int64)32)));
  86684. else
  86685. return 0;
  86686. #endif
  86687. #else
  86688. x = safe_malloc_(bytes);
  86689. *aligned_address = x;
  86690. #endif
  86691. return x;
  86692. }
  86693. FLAC__bool FLAC__memory_alloc_aligned_int32_array(unsigned elements, FLAC__int32 **unaligned_pointer, FLAC__int32 **aligned_pointer)
  86694. {
  86695. FLAC__int32 *pu; /* unaligned pointer */
  86696. union { /* union needed to comply with C99 pointer aliasing rules */
  86697. FLAC__int32 *pa; /* aligned pointer */
  86698. void *pv; /* aligned pointer alias */
  86699. } u;
  86700. FLAC__ASSERT(elements > 0);
  86701. FLAC__ASSERT(0 != unaligned_pointer);
  86702. FLAC__ASSERT(0 != aligned_pointer);
  86703. FLAC__ASSERT(unaligned_pointer != aligned_pointer);
  86704. pu = (FLAC__int32*)FLAC__memory_alloc_aligned(sizeof(*pu) * (size_t)elements, &u.pv);
  86705. if(0 == pu) {
  86706. return false;
  86707. }
  86708. else {
  86709. if(*unaligned_pointer != 0)
  86710. free(*unaligned_pointer);
  86711. *unaligned_pointer = pu;
  86712. *aligned_pointer = u.pa;
  86713. return true;
  86714. }
  86715. }
  86716. FLAC__bool FLAC__memory_alloc_aligned_uint32_array(unsigned elements, FLAC__uint32 **unaligned_pointer, FLAC__uint32 **aligned_pointer)
  86717. {
  86718. FLAC__uint32 *pu; /* unaligned pointer */
  86719. union { /* union needed to comply with C99 pointer aliasing rules */
  86720. FLAC__uint32 *pa; /* aligned pointer */
  86721. void *pv; /* aligned pointer alias */
  86722. } u;
  86723. FLAC__ASSERT(elements > 0);
  86724. FLAC__ASSERT(0 != unaligned_pointer);
  86725. FLAC__ASSERT(0 != aligned_pointer);
  86726. FLAC__ASSERT(unaligned_pointer != aligned_pointer);
  86727. pu = (FLAC__uint32*)FLAC__memory_alloc_aligned(sizeof(*pu) * elements, &u.pv);
  86728. if(0 == pu) {
  86729. return false;
  86730. }
  86731. else {
  86732. if(*unaligned_pointer != 0)
  86733. free(*unaligned_pointer);
  86734. *unaligned_pointer = pu;
  86735. *aligned_pointer = u.pa;
  86736. return true;
  86737. }
  86738. }
  86739. FLAC__bool FLAC__memory_alloc_aligned_uint64_array(unsigned elements, FLAC__uint64 **unaligned_pointer, FLAC__uint64 **aligned_pointer)
  86740. {
  86741. FLAC__uint64 *pu; /* unaligned pointer */
  86742. union { /* union needed to comply with C99 pointer aliasing rules */
  86743. FLAC__uint64 *pa; /* aligned pointer */
  86744. void *pv; /* aligned pointer alias */
  86745. } u;
  86746. FLAC__ASSERT(elements > 0);
  86747. FLAC__ASSERT(0 != unaligned_pointer);
  86748. FLAC__ASSERT(0 != aligned_pointer);
  86749. FLAC__ASSERT(unaligned_pointer != aligned_pointer);
  86750. pu = (FLAC__uint64*)FLAC__memory_alloc_aligned(sizeof(*pu) * elements, &u.pv);
  86751. if(0 == pu) {
  86752. return false;
  86753. }
  86754. else {
  86755. if(*unaligned_pointer != 0)
  86756. free(*unaligned_pointer);
  86757. *unaligned_pointer = pu;
  86758. *aligned_pointer = u.pa;
  86759. return true;
  86760. }
  86761. }
  86762. FLAC__bool FLAC__memory_alloc_aligned_unsigned_array(unsigned elements, unsigned **unaligned_pointer, unsigned **aligned_pointer)
  86763. {
  86764. unsigned *pu; /* unaligned pointer */
  86765. union { /* union needed to comply with C99 pointer aliasing rules */
  86766. unsigned *pa; /* aligned pointer */
  86767. void *pv; /* aligned pointer alias */
  86768. } u;
  86769. FLAC__ASSERT(elements > 0);
  86770. FLAC__ASSERT(0 != unaligned_pointer);
  86771. FLAC__ASSERT(0 != aligned_pointer);
  86772. FLAC__ASSERT(unaligned_pointer != aligned_pointer);
  86773. pu = (unsigned*)FLAC__memory_alloc_aligned(sizeof(*pu) * elements, &u.pv);
  86774. if(0 == pu) {
  86775. return false;
  86776. }
  86777. else {
  86778. if(*unaligned_pointer != 0)
  86779. free(*unaligned_pointer);
  86780. *unaligned_pointer = pu;
  86781. *aligned_pointer = u.pa;
  86782. return true;
  86783. }
  86784. }
  86785. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  86786. FLAC__bool FLAC__memory_alloc_aligned_real_array(unsigned elements, FLAC__real **unaligned_pointer, FLAC__real **aligned_pointer)
  86787. {
  86788. FLAC__real *pu; /* unaligned pointer */
  86789. union { /* union needed to comply with C99 pointer aliasing rules */
  86790. FLAC__real *pa; /* aligned pointer */
  86791. void *pv; /* aligned pointer alias */
  86792. } u;
  86793. FLAC__ASSERT(elements > 0);
  86794. FLAC__ASSERT(0 != unaligned_pointer);
  86795. FLAC__ASSERT(0 != aligned_pointer);
  86796. FLAC__ASSERT(unaligned_pointer != aligned_pointer);
  86797. pu = (FLAC__real*)FLAC__memory_alloc_aligned(sizeof(*pu) * elements, &u.pv);
  86798. if(0 == pu) {
  86799. return false;
  86800. }
  86801. else {
  86802. if(*unaligned_pointer != 0)
  86803. free(*unaligned_pointer);
  86804. *unaligned_pointer = pu;
  86805. *aligned_pointer = u.pa;
  86806. return true;
  86807. }
  86808. }
  86809. #endif
  86810. #endif
  86811. /*** End of inlined file: memory.c ***/
  86812. /*** Start of inlined file: stream_decoder.c ***/
  86813. /*** Start of inlined file: juce_FlacHeader.h ***/
  86814. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  86815. // tasks..
  86816. #define VERSION "1.2.1"
  86817. #define FLAC__NO_DLL 1
  86818. #if JUCE_MSVC
  86819. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  86820. #endif
  86821. #if JUCE_MAC
  86822. #define FLAC__SYS_DARWIN 1
  86823. #endif
  86824. /*** End of inlined file: juce_FlacHeader.h ***/
  86825. #if JUCE_USE_FLAC
  86826. #if HAVE_CONFIG_H
  86827. # include <config.h>
  86828. #endif
  86829. #if defined _MSC_VER || defined __MINGW32__
  86830. #include <io.h> /* for _setmode() */
  86831. #include <fcntl.h> /* for _O_BINARY */
  86832. #endif
  86833. #if defined __CYGWIN__ || defined __EMX__
  86834. #include <io.h> /* for setmode(), O_BINARY */
  86835. #include <fcntl.h> /* for _O_BINARY */
  86836. #endif
  86837. #include <stdio.h>
  86838. #include <stdlib.h> /* for malloc() */
  86839. #include <string.h> /* for memset/memcpy() */
  86840. #include <sys/stat.h> /* for stat() */
  86841. #include <sys/types.h> /* for off_t */
  86842. #if defined _MSC_VER || defined __BORLANDC__ || defined __MINGW32__
  86843. #if _MSC_VER <= 1600 || defined __BORLANDC__ /* @@@ [2G limit] */
  86844. #define fseeko fseek
  86845. #define ftello ftell
  86846. #endif
  86847. #endif
  86848. /*** Start of inlined file: stream_decoder.h ***/
  86849. #ifndef FLAC__PROTECTED__STREAM_DECODER_H
  86850. #define FLAC__PROTECTED__STREAM_DECODER_H
  86851. #if FLAC__HAS_OGG
  86852. #include "include/private/ogg_decoder_aspect.h"
  86853. #endif
  86854. typedef struct FLAC__StreamDecoderProtected {
  86855. FLAC__StreamDecoderState state;
  86856. unsigned channels;
  86857. FLAC__ChannelAssignment channel_assignment;
  86858. unsigned bits_per_sample;
  86859. unsigned sample_rate; /* in Hz */
  86860. unsigned blocksize; /* in samples (per channel) */
  86861. FLAC__bool md5_checking; /* if true, generate MD5 signature of decoded data and compare against signature in the STREAMINFO metadata block */
  86862. #if FLAC__HAS_OGG
  86863. FLAC__OggDecoderAspect ogg_decoder_aspect;
  86864. #endif
  86865. } FLAC__StreamDecoderProtected;
  86866. unsigned FLAC__stream_decoder_get_input_bytes_unconsumed(const FLAC__StreamDecoder *decoder);
  86867. #endif
  86868. /*** End of inlined file: stream_decoder.h ***/
  86869. #ifdef max
  86870. #undef max
  86871. #endif
  86872. #define max(a,b) ((a)>(b)?(a):(b))
  86873. #ifdef _MSC_VER
  86874. #define FLAC__U64L(x) x
  86875. #else
  86876. #define FLAC__U64L(x) x##LLU
  86877. #endif
  86878. FLAC_API int FLAC_API_SUPPORTS_OGG_FLAC =
  86879. #if FLAC__HAS_OGG
  86880. 1
  86881. #else
  86882. 0
  86883. #endif
  86884. ;
  86885. static FLAC__byte ID3V2_TAG_[3] = { 'I', 'D', '3' };
  86886. static void set_defaults_dec(FLAC__StreamDecoder *decoder);
  86887. static FILE *get_binary_stdin_(void);
  86888. static FLAC__bool allocate_output_(FLAC__StreamDecoder *decoder, unsigned size, unsigned channels);
  86889. static FLAC__bool has_id_filtered_(FLAC__StreamDecoder *decoder, FLAC__byte *id);
  86890. static FLAC__bool find_metadata_(FLAC__StreamDecoder *decoder);
  86891. static FLAC__bool read_metadata_(FLAC__StreamDecoder *decoder);
  86892. static FLAC__bool read_metadata_streaminfo_(FLAC__StreamDecoder *decoder, FLAC__bool is_last, unsigned length);
  86893. static FLAC__bool read_metadata_seektable_(FLAC__StreamDecoder *decoder, FLAC__bool is_last, unsigned length);
  86894. static FLAC__bool read_metadata_vorbiscomment_(FLAC__StreamDecoder *decoder, FLAC__StreamMetadata_VorbisComment *obj);
  86895. static FLAC__bool read_metadata_cuesheet_(FLAC__StreamDecoder *decoder, FLAC__StreamMetadata_CueSheet *obj);
  86896. static FLAC__bool read_metadata_picture_(FLAC__StreamDecoder *decoder, FLAC__StreamMetadata_Picture *obj);
  86897. static FLAC__bool skip_id3v2_tag_(FLAC__StreamDecoder *decoder);
  86898. static FLAC__bool frame_sync_(FLAC__StreamDecoder *decoder);
  86899. static FLAC__bool read_frame_(FLAC__StreamDecoder *decoder, FLAC__bool *got_a_frame, FLAC__bool do_full_decode);
  86900. static FLAC__bool read_frame_header_(FLAC__StreamDecoder *decoder);
  86901. static FLAC__bool read_subframe_(FLAC__StreamDecoder *decoder, unsigned channel, unsigned bps, FLAC__bool do_full_decode);
  86902. static FLAC__bool read_subframe_constant_(FLAC__StreamDecoder *decoder, unsigned channel, unsigned bps, FLAC__bool do_full_decode);
  86903. static FLAC__bool read_subframe_fixed_(FLAC__StreamDecoder *decoder, unsigned channel, unsigned bps, const unsigned order, FLAC__bool do_full_decode);
  86904. static FLAC__bool read_subframe_lpc_(FLAC__StreamDecoder *decoder, unsigned channel, unsigned bps, const unsigned order, FLAC__bool do_full_decode);
  86905. static FLAC__bool read_subframe_verbatim_(FLAC__StreamDecoder *decoder, unsigned channel, unsigned bps, FLAC__bool do_full_decode);
  86906. 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);
  86907. static FLAC__bool read_zero_padding_(FLAC__StreamDecoder *decoder);
  86908. static FLAC__bool read_callback_(FLAC__byte buffer[], size_t *bytes, void *client_data);
  86909. #if FLAC__HAS_OGG
  86910. static FLAC__StreamDecoderReadStatus read_callback_ogg_aspect_(const FLAC__StreamDecoder *decoder, FLAC__byte buffer[], size_t *bytes);
  86911. static FLAC__OggDecoderAspectReadStatus read_callback_proxy_(const void *void_decoder, FLAC__byte buffer[], size_t *bytes, void *client_data);
  86912. #endif
  86913. static FLAC__StreamDecoderWriteStatus write_audio_frame_to_client_(FLAC__StreamDecoder *decoder, const FLAC__Frame *frame, const FLAC__int32 * const buffer[]);
  86914. static void send_error_to_client_(const FLAC__StreamDecoder *decoder, FLAC__StreamDecoderErrorStatus status);
  86915. static FLAC__bool seek_to_absolute_sample_(FLAC__StreamDecoder *decoder, FLAC__uint64 stream_length, FLAC__uint64 target_sample);
  86916. #if FLAC__HAS_OGG
  86917. static FLAC__bool seek_to_absolute_sample_ogg_(FLAC__StreamDecoder *decoder, FLAC__uint64 stream_length, FLAC__uint64 target_sample);
  86918. #endif
  86919. static FLAC__StreamDecoderReadStatus file_read_callback_dec (const FLAC__StreamDecoder *decoder, FLAC__byte buffer[], size_t *bytes, void *client_data);
  86920. static FLAC__StreamDecoderSeekStatus file_seek_callback_dec (const FLAC__StreamDecoder *decoder, FLAC__uint64 absolute_byte_offset, void *client_data);
  86921. static FLAC__StreamDecoderTellStatus file_tell_callback_dec (const FLAC__StreamDecoder *decoder, FLAC__uint64 *absolute_byte_offset, void *client_data);
  86922. static FLAC__StreamDecoderLengthStatus file_length_callback_(const FLAC__StreamDecoder *decoder, FLAC__uint64 *stream_length, void *client_data);
  86923. static FLAC__bool file_eof_callback_(const FLAC__StreamDecoder *decoder, void *client_data);
  86924. typedef struct FLAC__StreamDecoderPrivate {
  86925. #if FLAC__HAS_OGG
  86926. FLAC__bool is_ogg;
  86927. #endif
  86928. FLAC__StreamDecoderReadCallback read_callback;
  86929. FLAC__StreamDecoderSeekCallback seek_callback;
  86930. FLAC__StreamDecoderTellCallback tell_callback;
  86931. FLAC__StreamDecoderLengthCallback length_callback;
  86932. FLAC__StreamDecoderEofCallback eof_callback;
  86933. FLAC__StreamDecoderWriteCallback write_callback;
  86934. FLAC__StreamDecoderMetadataCallback metadata_callback;
  86935. FLAC__StreamDecoderErrorCallback error_callback;
  86936. 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[]);
  86937. 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[]);
  86938. 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[]);
  86939. 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[]);
  86940. FLAC__bool (*local_bitreader_read_rice_signed_block)(FLAC__BitReader *br, int* vals, unsigned nvals, unsigned parameter);
  86941. void *client_data;
  86942. FILE *file; /* only used if FLAC__stream_decoder_init_file()/FLAC__stream_decoder_init_file() called, else NULL */
  86943. FLAC__BitReader *input;
  86944. FLAC__int32 *output[FLAC__MAX_CHANNELS];
  86945. FLAC__int32 *residual[FLAC__MAX_CHANNELS]; /* WATCHOUT: these are the aligned pointers; the real pointers that should be free()'d are residual_unaligned[] below */
  86946. FLAC__EntropyCodingMethod_PartitionedRiceContents partitioned_rice_contents[FLAC__MAX_CHANNELS];
  86947. unsigned output_capacity, output_channels;
  86948. FLAC__uint32 fixed_block_size, next_fixed_block_size;
  86949. FLAC__uint64 samples_decoded;
  86950. FLAC__bool has_stream_info, has_seek_table;
  86951. FLAC__StreamMetadata stream_info;
  86952. FLAC__StreamMetadata seek_table;
  86953. FLAC__bool metadata_filter[128]; /* MAGIC number 128 == total number of metadata block types == 1 << 7 */
  86954. FLAC__byte *metadata_filter_ids;
  86955. size_t metadata_filter_ids_count, metadata_filter_ids_capacity; /* units for both are IDs, not bytes */
  86956. FLAC__Frame frame;
  86957. FLAC__bool cached; /* true if there is a byte in lookahead */
  86958. FLAC__CPUInfo cpuinfo;
  86959. FLAC__byte header_warmup[2]; /* contains the sync code and reserved bits */
  86960. FLAC__byte lookahead; /* temp storage when we need to look ahead one byte in the stream */
  86961. FLAC__int32 *residual_unaligned[FLAC__MAX_CHANNELS];
  86962. 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 */
  86963. FLAC__bool internal_reset_hack; /* used only during init() so we can call reset to set up the decoder without rewinding the input */
  86964. FLAC__bool is_seeking;
  86965. FLAC__MD5Context md5context;
  86966. FLAC__byte computed_md5sum[16]; /* this is the sum we computed from the decoded data */
  86967. FLAC__Frame last_frame; /* holds the info of the last frame we seeked to */
  86968. FLAC__uint64 first_frame_offset; /* hint to the seek routine of where in the stream the first audio frame starts */
  86969. FLAC__uint64 target_sample;
  86970. unsigned unparseable_frame_count; /* used to tell whether we're decoding a future version of FLAC or just got a bad sync */
  86971. #if FLAC__HAS_OGG
  86972. FLAC__bool got_a_frame; /* hack needed in Ogg FLAC seek routine to check when process_single() actually writes a frame */
  86973. #endif
  86974. } FLAC__StreamDecoderPrivate;
  86975. FLAC_API const char * const FLAC__StreamDecoderStateString[] = {
  86976. "FLAC__STREAM_DECODER_SEARCH_FOR_METADATA",
  86977. "FLAC__STREAM_DECODER_READ_METADATA",
  86978. "FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC",
  86979. "FLAC__STREAM_DECODER_READ_FRAME",
  86980. "FLAC__STREAM_DECODER_END_OF_STREAM",
  86981. "FLAC__STREAM_DECODER_OGG_ERROR",
  86982. "FLAC__STREAM_DECODER_SEEK_ERROR",
  86983. "FLAC__STREAM_DECODER_ABORTED",
  86984. "FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR",
  86985. "FLAC__STREAM_DECODER_UNINITIALIZED"
  86986. };
  86987. FLAC_API const char * const FLAC__StreamDecoderInitStatusString[] = {
  86988. "FLAC__STREAM_DECODER_INIT_STATUS_OK",
  86989. "FLAC__STREAM_DECODER_INIT_STATUS_UNSUPPORTED_CONTAINER",
  86990. "FLAC__STREAM_DECODER_INIT_STATUS_INVALID_CALLBACKS",
  86991. "FLAC__STREAM_DECODER_INIT_STATUS_MEMORY_ALLOCATION_ERROR",
  86992. "FLAC__STREAM_DECODER_INIT_STATUS_ERROR_OPENING_FILE",
  86993. "FLAC__STREAM_DECODER_INIT_STATUS_ALREADY_INITIALIZED"
  86994. };
  86995. FLAC_API const char * const FLAC__StreamDecoderReadStatusString[] = {
  86996. "FLAC__STREAM_DECODER_READ_STATUS_CONTINUE",
  86997. "FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM",
  86998. "FLAC__STREAM_DECODER_READ_STATUS_ABORT"
  86999. };
  87000. FLAC_API const char * const FLAC__StreamDecoderSeekStatusString[] = {
  87001. "FLAC__STREAM_DECODER_SEEK_STATUS_OK",
  87002. "FLAC__STREAM_DECODER_SEEK_STATUS_ERROR",
  87003. "FLAC__STREAM_DECODER_SEEK_STATUS_UNSUPPORTED"
  87004. };
  87005. FLAC_API const char * const FLAC__StreamDecoderTellStatusString[] = {
  87006. "FLAC__STREAM_DECODER_TELL_STATUS_OK",
  87007. "FLAC__STREAM_DECODER_TELL_STATUS_ERROR",
  87008. "FLAC__STREAM_DECODER_TELL_STATUS_UNSUPPORTED"
  87009. };
  87010. FLAC_API const char * const FLAC__StreamDecoderLengthStatusString[] = {
  87011. "FLAC__STREAM_DECODER_LENGTH_STATUS_OK",
  87012. "FLAC__STREAM_DECODER_LENGTH_STATUS_ERROR",
  87013. "FLAC__STREAM_DECODER_LENGTH_STATUS_UNSUPPORTED"
  87014. };
  87015. FLAC_API const char * const FLAC__StreamDecoderWriteStatusString[] = {
  87016. "FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE",
  87017. "FLAC__STREAM_DECODER_WRITE_STATUS_ABORT"
  87018. };
  87019. FLAC_API const char * const FLAC__StreamDecoderErrorStatusString[] = {
  87020. "FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC",
  87021. "FLAC__STREAM_DECODER_ERROR_STATUS_BAD_HEADER",
  87022. "FLAC__STREAM_DECODER_ERROR_STATUS_FRAME_CRC_MISMATCH",
  87023. "FLAC__STREAM_DECODER_ERROR_STATUS_UNPARSEABLE_STREAM"
  87024. };
  87025. FLAC_API FLAC__StreamDecoder *FLAC__stream_decoder_new(void)
  87026. {
  87027. FLAC__StreamDecoder *decoder;
  87028. unsigned i;
  87029. FLAC__ASSERT(sizeof(int) >= 4); /* we want to die right away if this is not true */
  87030. decoder = (FLAC__StreamDecoder*)calloc(1, sizeof(FLAC__StreamDecoder));
  87031. if(decoder == 0) {
  87032. return 0;
  87033. }
  87034. decoder->protected_ = (FLAC__StreamDecoderProtected*)calloc(1, sizeof(FLAC__StreamDecoderProtected));
  87035. if(decoder->protected_ == 0) {
  87036. free(decoder);
  87037. return 0;
  87038. }
  87039. decoder->private_ = (FLAC__StreamDecoderPrivate*)calloc(1, sizeof(FLAC__StreamDecoderPrivate));
  87040. if(decoder->private_ == 0) {
  87041. free(decoder->protected_);
  87042. free(decoder);
  87043. return 0;
  87044. }
  87045. decoder->private_->input = FLAC__bitreader_new();
  87046. if(decoder->private_->input == 0) {
  87047. free(decoder->private_);
  87048. free(decoder->protected_);
  87049. free(decoder);
  87050. return 0;
  87051. }
  87052. decoder->private_->metadata_filter_ids_capacity = 16;
  87053. if(0 == (decoder->private_->metadata_filter_ids = (FLAC__byte*)malloc((FLAC__STREAM_METADATA_APPLICATION_ID_LEN/8) * decoder->private_->metadata_filter_ids_capacity))) {
  87054. FLAC__bitreader_delete(decoder->private_->input);
  87055. free(decoder->private_);
  87056. free(decoder->protected_);
  87057. free(decoder);
  87058. return 0;
  87059. }
  87060. for(i = 0; i < FLAC__MAX_CHANNELS; i++) {
  87061. decoder->private_->output[i] = 0;
  87062. decoder->private_->residual_unaligned[i] = decoder->private_->residual[i] = 0;
  87063. }
  87064. decoder->private_->output_capacity = 0;
  87065. decoder->private_->output_channels = 0;
  87066. decoder->private_->has_seek_table = false;
  87067. for(i = 0; i < FLAC__MAX_CHANNELS; i++)
  87068. FLAC__format_entropy_coding_method_partitioned_rice_contents_init(&decoder->private_->partitioned_rice_contents[i]);
  87069. decoder->private_->file = 0;
  87070. set_defaults_dec(decoder);
  87071. decoder->protected_->state = FLAC__STREAM_DECODER_UNINITIALIZED;
  87072. return decoder;
  87073. }
  87074. FLAC_API void FLAC__stream_decoder_delete(FLAC__StreamDecoder *decoder)
  87075. {
  87076. unsigned i;
  87077. FLAC__ASSERT(0 != decoder);
  87078. FLAC__ASSERT(0 != decoder->protected_);
  87079. FLAC__ASSERT(0 != decoder->private_);
  87080. FLAC__ASSERT(0 != decoder->private_->input);
  87081. (void)FLAC__stream_decoder_finish(decoder);
  87082. if(0 != decoder->private_->metadata_filter_ids)
  87083. free(decoder->private_->metadata_filter_ids);
  87084. FLAC__bitreader_delete(decoder->private_->input);
  87085. for(i = 0; i < FLAC__MAX_CHANNELS; i++)
  87086. FLAC__format_entropy_coding_method_partitioned_rice_contents_clear(&decoder->private_->partitioned_rice_contents[i]);
  87087. free(decoder->private_);
  87088. free(decoder->protected_);
  87089. free(decoder);
  87090. }
  87091. static FLAC__StreamDecoderInitStatus init_stream_internal_dec(
  87092. FLAC__StreamDecoder *decoder,
  87093. FLAC__StreamDecoderReadCallback read_callback,
  87094. FLAC__StreamDecoderSeekCallback seek_callback,
  87095. FLAC__StreamDecoderTellCallback tell_callback,
  87096. FLAC__StreamDecoderLengthCallback length_callback,
  87097. FLAC__StreamDecoderEofCallback eof_callback,
  87098. FLAC__StreamDecoderWriteCallback write_callback,
  87099. FLAC__StreamDecoderMetadataCallback metadata_callback,
  87100. FLAC__StreamDecoderErrorCallback error_callback,
  87101. void *client_data,
  87102. FLAC__bool is_ogg
  87103. )
  87104. {
  87105. FLAC__ASSERT(0 != decoder);
  87106. if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
  87107. return FLAC__STREAM_DECODER_INIT_STATUS_ALREADY_INITIALIZED;
  87108. #if !FLAC__HAS_OGG
  87109. if(is_ogg)
  87110. return FLAC__STREAM_DECODER_INIT_STATUS_UNSUPPORTED_CONTAINER;
  87111. #endif
  87112. if(
  87113. 0 == read_callback ||
  87114. 0 == write_callback ||
  87115. 0 == error_callback ||
  87116. (seek_callback && (0 == tell_callback || 0 == length_callback || 0 == eof_callback))
  87117. )
  87118. return FLAC__STREAM_DECODER_INIT_STATUS_INVALID_CALLBACKS;
  87119. #if FLAC__HAS_OGG
  87120. decoder->private_->is_ogg = is_ogg;
  87121. if(is_ogg && !FLAC__ogg_decoder_aspect_init(&decoder->protected_->ogg_decoder_aspect))
  87122. return decoder->protected_->state = FLAC__STREAM_DECODER_OGG_ERROR;
  87123. #endif
  87124. FLAC__cpu_info(&decoder->private_->cpuinfo);
  87125. decoder->private_->local_lpc_restore_signal = FLAC__lpc_restore_signal;
  87126. decoder->private_->local_lpc_restore_signal_64bit = FLAC__lpc_restore_signal_wide;
  87127. decoder->private_->local_lpc_restore_signal_16bit = FLAC__lpc_restore_signal;
  87128. decoder->private_->local_lpc_restore_signal_16bit_order8 = FLAC__lpc_restore_signal;
  87129. decoder->private_->local_bitreader_read_rice_signed_block = FLAC__bitreader_read_rice_signed_block;
  87130. #ifndef FLAC__NO_ASM
  87131. if(decoder->private_->cpuinfo.use_asm) {
  87132. #ifdef FLAC__CPU_IA32
  87133. FLAC__ASSERT(decoder->private_->cpuinfo.type == FLAC__CPUINFO_TYPE_IA32);
  87134. #ifdef FLAC__HAS_NASM
  87135. #if 1 /*@@@@@@ OPT: not clearly faster, needs more testing */
  87136. if(decoder->private_->cpuinfo.data.ia32.bswap)
  87137. decoder->private_->local_bitreader_read_rice_signed_block = FLAC__bitreader_read_rice_signed_block_asm_ia32_bswap;
  87138. #endif
  87139. if(decoder->private_->cpuinfo.data.ia32.mmx) {
  87140. decoder->private_->local_lpc_restore_signal = FLAC__lpc_restore_signal_asm_ia32;
  87141. decoder->private_->local_lpc_restore_signal_16bit = FLAC__lpc_restore_signal_asm_ia32_mmx;
  87142. decoder->private_->local_lpc_restore_signal_16bit_order8 = FLAC__lpc_restore_signal_asm_ia32_mmx;
  87143. }
  87144. else {
  87145. decoder->private_->local_lpc_restore_signal = FLAC__lpc_restore_signal_asm_ia32;
  87146. decoder->private_->local_lpc_restore_signal_16bit = FLAC__lpc_restore_signal_asm_ia32;
  87147. decoder->private_->local_lpc_restore_signal_16bit_order8 = FLAC__lpc_restore_signal_asm_ia32;
  87148. }
  87149. #endif
  87150. #elif defined FLAC__CPU_PPC
  87151. FLAC__ASSERT(decoder->private_->cpuinfo.type == FLAC__CPUINFO_TYPE_PPC);
  87152. if(decoder->private_->cpuinfo.data.ppc.altivec) {
  87153. decoder->private_->local_lpc_restore_signal_16bit = FLAC__lpc_restore_signal_asm_ppc_altivec_16;
  87154. decoder->private_->local_lpc_restore_signal_16bit_order8 = FLAC__lpc_restore_signal_asm_ppc_altivec_16_order8;
  87155. }
  87156. #endif
  87157. }
  87158. #endif
  87159. if(!FLAC__bitreader_init(decoder->private_->input, decoder->private_->cpuinfo, read_callback_, decoder)) {
  87160. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  87161. return FLAC__STREAM_DECODER_INIT_STATUS_MEMORY_ALLOCATION_ERROR;
  87162. }
  87163. decoder->private_->read_callback = read_callback;
  87164. decoder->private_->seek_callback = seek_callback;
  87165. decoder->private_->tell_callback = tell_callback;
  87166. decoder->private_->length_callback = length_callback;
  87167. decoder->private_->eof_callback = eof_callback;
  87168. decoder->private_->write_callback = write_callback;
  87169. decoder->private_->metadata_callback = metadata_callback;
  87170. decoder->private_->error_callback = error_callback;
  87171. decoder->private_->client_data = client_data;
  87172. decoder->private_->fixed_block_size = decoder->private_->next_fixed_block_size = 0;
  87173. decoder->private_->samples_decoded = 0;
  87174. decoder->private_->has_stream_info = false;
  87175. decoder->private_->cached = false;
  87176. decoder->private_->do_md5_checking = decoder->protected_->md5_checking;
  87177. decoder->private_->is_seeking = false;
  87178. decoder->private_->internal_reset_hack = true; /* so the following reset does not try to rewind the input */
  87179. if(!FLAC__stream_decoder_reset(decoder)) {
  87180. return FLAC__STREAM_DECODER_INIT_STATUS_MEMORY_ALLOCATION_ERROR;
  87181. }
  87182. return FLAC__STREAM_DECODER_INIT_STATUS_OK;
  87183. }
  87184. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_stream(
  87185. FLAC__StreamDecoder *decoder,
  87186. FLAC__StreamDecoderReadCallback read_callback,
  87187. FLAC__StreamDecoderSeekCallback seek_callback,
  87188. FLAC__StreamDecoderTellCallback tell_callback,
  87189. FLAC__StreamDecoderLengthCallback length_callback,
  87190. FLAC__StreamDecoderEofCallback eof_callback,
  87191. FLAC__StreamDecoderWriteCallback write_callback,
  87192. FLAC__StreamDecoderMetadataCallback metadata_callback,
  87193. FLAC__StreamDecoderErrorCallback error_callback,
  87194. void *client_data
  87195. )
  87196. {
  87197. return init_stream_internal_dec(
  87198. decoder,
  87199. read_callback,
  87200. seek_callback,
  87201. tell_callback,
  87202. length_callback,
  87203. eof_callback,
  87204. write_callback,
  87205. metadata_callback,
  87206. error_callback,
  87207. client_data,
  87208. false
  87209. );
  87210. }
  87211. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_ogg_stream(
  87212. FLAC__StreamDecoder *decoder,
  87213. FLAC__StreamDecoderReadCallback read_callback,
  87214. FLAC__StreamDecoderSeekCallback seek_callback,
  87215. FLAC__StreamDecoderTellCallback tell_callback,
  87216. FLAC__StreamDecoderLengthCallback length_callback,
  87217. FLAC__StreamDecoderEofCallback eof_callback,
  87218. FLAC__StreamDecoderWriteCallback write_callback,
  87219. FLAC__StreamDecoderMetadataCallback metadata_callback,
  87220. FLAC__StreamDecoderErrorCallback error_callback,
  87221. void *client_data
  87222. )
  87223. {
  87224. return init_stream_internal_dec(
  87225. decoder,
  87226. read_callback,
  87227. seek_callback,
  87228. tell_callback,
  87229. length_callback,
  87230. eof_callback,
  87231. write_callback,
  87232. metadata_callback,
  87233. error_callback,
  87234. client_data,
  87235. true
  87236. );
  87237. }
  87238. static FLAC__StreamDecoderInitStatus init_FILE_internal_(
  87239. FLAC__StreamDecoder *decoder,
  87240. FILE *file,
  87241. FLAC__StreamDecoderWriteCallback write_callback,
  87242. FLAC__StreamDecoderMetadataCallback metadata_callback,
  87243. FLAC__StreamDecoderErrorCallback error_callback,
  87244. void *client_data,
  87245. FLAC__bool is_ogg
  87246. )
  87247. {
  87248. FLAC__ASSERT(0 != decoder);
  87249. FLAC__ASSERT(0 != file);
  87250. if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
  87251. return (FLAC__StreamDecoderInitStatus) (decoder->protected_->state = (FLAC__StreamDecoderState) FLAC__STREAM_DECODER_INIT_STATUS_ALREADY_INITIALIZED);
  87252. if(0 == write_callback || 0 == error_callback)
  87253. return (FLAC__StreamDecoderInitStatus) (decoder->protected_->state = (FLAC__StreamDecoderState) FLAC__STREAM_DECODER_INIT_STATUS_INVALID_CALLBACKS);
  87254. if(file == stdin)
  87255. file = get_binary_stdin_(); /* just to be safe */
  87256. decoder->private_->file = file;
  87257. return init_stream_internal_dec(
  87258. decoder,
  87259. file_read_callback_dec,
  87260. decoder->private_->file == stdin? 0: file_seek_callback_dec,
  87261. decoder->private_->file == stdin? 0: file_tell_callback_dec,
  87262. decoder->private_->file == stdin? 0: file_length_callback_,
  87263. file_eof_callback_,
  87264. write_callback,
  87265. metadata_callback,
  87266. error_callback,
  87267. client_data,
  87268. is_ogg
  87269. );
  87270. }
  87271. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_FILE(
  87272. FLAC__StreamDecoder *decoder,
  87273. FILE *file,
  87274. FLAC__StreamDecoderWriteCallback write_callback,
  87275. FLAC__StreamDecoderMetadataCallback metadata_callback,
  87276. FLAC__StreamDecoderErrorCallback error_callback,
  87277. void *client_data
  87278. )
  87279. {
  87280. return init_FILE_internal_(decoder, file, write_callback, metadata_callback, error_callback, client_data, /*is_ogg=*/false);
  87281. }
  87282. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_ogg_FILE(
  87283. FLAC__StreamDecoder *decoder,
  87284. FILE *file,
  87285. FLAC__StreamDecoderWriteCallback write_callback,
  87286. FLAC__StreamDecoderMetadataCallback metadata_callback,
  87287. FLAC__StreamDecoderErrorCallback error_callback,
  87288. void *client_data
  87289. )
  87290. {
  87291. return init_FILE_internal_(decoder, file, write_callback, metadata_callback, error_callback, client_data, /*is_ogg=*/true);
  87292. }
  87293. static FLAC__StreamDecoderInitStatus init_file_internal_(
  87294. FLAC__StreamDecoder *decoder,
  87295. const char *filename,
  87296. FLAC__StreamDecoderWriteCallback write_callback,
  87297. FLAC__StreamDecoderMetadataCallback metadata_callback,
  87298. FLAC__StreamDecoderErrorCallback error_callback,
  87299. void *client_data,
  87300. FLAC__bool is_ogg
  87301. )
  87302. {
  87303. FILE *file;
  87304. FLAC__ASSERT(0 != decoder);
  87305. if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
  87306. return (FLAC__StreamDecoderInitStatus) (decoder->protected_->state = (FLAC__StreamDecoderState) FLAC__STREAM_DECODER_INIT_STATUS_ALREADY_INITIALIZED);
  87307. if(0 == write_callback || 0 == error_callback)
  87308. return (FLAC__StreamDecoderInitStatus) (decoder->protected_->state = (FLAC__StreamDecoderState) FLAC__STREAM_DECODER_INIT_STATUS_INVALID_CALLBACKS);
  87309. file = filename? fopen(filename, "rb") : stdin;
  87310. if(0 == file)
  87311. return FLAC__STREAM_DECODER_INIT_STATUS_ERROR_OPENING_FILE;
  87312. return init_FILE_internal_(decoder, file, write_callback, metadata_callback, error_callback, client_data, is_ogg);
  87313. }
  87314. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_file(
  87315. FLAC__StreamDecoder *decoder,
  87316. const char *filename,
  87317. FLAC__StreamDecoderWriteCallback write_callback,
  87318. FLAC__StreamDecoderMetadataCallback metadata_callback,
  87319. FLAC__StreamDecoderErrorCallback error_callback,
  87320. void *client_data
  87321. )
  87322. {
  87323. return init_file_internal_(decoder, filename, write_callback, metadata_callback, error_callback, client_data, /*is_ogg=*/false);
  87324. }
  87325. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_ogg_file(
  87326. FLAC__StreamDecoder *decoder,
  87327. const char *filename,
  87328. FLAC__StreamDecoderWriteCallback write_callback,
  87329. FLAC__StreamDecoderMetadataCallback metadata_callback,
  87330. FLAC__StreamDecoderErrorCallback error_callback,
  87331. void *client_data
  87332. )
  87333. {
  87334. return init_file_internal_(decoder, filename, write_callback, metadata_callback, error_callback, client_data, /*is_ogg=*/true);
  87335. }
  87336. FLAC_API FLAC__bool FLAC__stream_decoder_finish(FLAC__StreamDecoder *decoder)
  87337. {
  87338. FLAC__bool md5_failed = false;
  87339. unsigned i;
  87340. FLAC__ASSERT(0 != decoder);
  87341. FLAC__ASSERT(0 != decoder->private_);
  87342. FLAC__ASSERT(0 != decoder->protected_);
  87343. if(decoder->protected_->state == FLAC__STREAM_DECODER_UNINITIALIZED)
  87344. return true;
  87345. FLAC__MD5Final(decoder->private_->computed_md5sum, &decoder->private_->md5context);
  87346. if(decoder->private_->has_seek_table && 0 != decoder->private_->seek_table.data.seek_table.points) {
  87347. free(decoder->private_->seek_table.data.seek_table.points);
  87348. decoder->private_->seek_table.data.seek_table.points = 0;
  87349. decoder->private_->has_seek_table = false;
  87350. }
  87351. FLAC__bitreader_free(decoder->private_->input);
  87352. for(i = 0; i < FLAC__MAX_CHANNELS; i++) {
  87353. if(0 != decoder->private_->output[i]) {
  87354. free(decoder->private_->output[i]-4);
  87355. decoder->private_->output[i] = 0;
  87356. }
  87357. if(0 != decoder->private_->residual_unaligned[i]) {
  87358. free(decoder->private_->residual_unaligned[i]);
  87359. decoder->private_->residual_unaligned[i] = decoder->private_->residual[i] = 0;
  87360. }
  87361. }
  87362. decoder->private_->output_capacity = 0;
  87363. decoder->private_->output_channels = 0;
  87364. #if FLAC__HAS_OGG
  87365. if(decoder->private_->is_ogg)
  87366. FLAC__ogg_decoder_aspect_finish(&decoder->protected_->ogg_decoder_aspect);
  87367. #endif
  87368. if(0 != decoder->private_->file) {
  87369. if(decoder->private_->file != stdin)
  87370. fclose(decoder->private_->file);
  87371. decoder->private_->file = 0;
  87372. }
  87373. if(decoder->private_->do_md5_checking) {
  87374. if(memcmp(decoder->private_->stream_info.data.stream_info.md5sum, decoder->private_->computed_md5sum, 16))
  87375. md5_failed = true;
  87376. }
  87377. decoder->private_->is_seeking = false;
  87378. set_defaults_dec(decoder);
  87379. decoder->protected_->state = FLAC__STREAM_DECODER_UNINITIALIZED;
  87380. return !md5_failed;
  87381. }
  87382. FLAC_API FLAC__bool FLAC__stream_decoder_set_ogg_serial_number(FLAC__StreamDecoder *decoder, long value)
  87383. {
  87384. FLAC__ASSERT(0 != decoder);
  87385. FLAC__ASSERT(0 != decoder->private_);
  87386. FLAC__ASSERT(0 != decoder->protected_);
  87387. if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
  87388. return false;
  87389. #if FLAC__HAS_OGG
  87390. FLAC__ogg_decoder_aspect_set_serial_number(&decoder->protected_->ogg_decoder_aspect, value);
  87391. return true;
  87392. #else
  87393. (void)value;
  87394. return false;
  87395. #endif
  87396. }
  87397. FLAC_API FLAC__bool FLAC__stream_decoder_set_md5_checking(FLAC__StreamDecoder *decoder, FLAC__bool value)
  87398. {
  87399. FLAC__ASSERT(0 != decoder);
  87400. FLAC__ASSERT(0 != decoder->protected_);
  87401. if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
  87402. return false;
  87403. decoder->protected_->md5_checking = value;
  87404. return true;
  87405. }
  87406. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_respond(FLAC__StreamDecoder *decoder, FLAC__MetadataType type)
  87407. {
  87408. FLAC__ASSERT(0 != decoder);
  87409. FLAC__ASSERT(0 != decoder->private_);
  87410. FLAC__ASSERT(0 != decoder->protected_);
  87411. FLAC__ASSERT((unsigned)type <= FLAC__MAX_METADATA_TYPE_CODE);
  87412. if((unsigned)type > FLAC__MAX_METADATA_TYPE_CODE)
  87413. return false;
  87414. if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
  87415. return false;
  87416. decoder->private_->metadata_filter[type] = true;
  87417. if(type == FLAC__METADATA_TYPE_APPLICATION)
  87418. decoder->private_->metadata_filter_ids_count = 0;
  87419. return true;
  87420. }
  87421. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_respond_application(FLAC__StreamDecoder *decoder, const FLAC__byte id[4])
  87422. {
  87423. FLAC__ASSERT(0 != decoder);
  87424. FLAC__ASSERT(0 != decoder->private_);
  87425. FLAC__ASSERT(0 != decoder->protected_);
  87426. FLAC__ASSERT(0 != id);
  87427. if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
  87428. return false;
  87429. if(decoder->private_->metadata_filter[FLAC__METADATA_TYPE_APPLICATION])
  87430. return true;
  87431. FLAC__ASSERT(0 != decoder->private_->metadata_filter_ids);
  87432. if(decoder->private_->metadata_filter_ids_count == decoder->private_->metadata_filter_ids_capacity) {
  87433. 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))) {
  87434. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  87435. return false;
  87436. }
  87437. decoder->private_->metadata_filter_ids_capacity *= 2;
  87438. }
  87439. 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));
  87440. decoder->private_->metadata_filter_ids_count++;
  87441. return true;
  87442. }
  87443. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_respond_all(FLAC__StreamDecoder *decoder)
  87444. {
  87445. unsigned i;
  87446. FLAC__ASSERT(0 != decoder);
  87447. FLAC__ASSERT(0 != decoder->private_);
  87448. FLAC__ASSERT(0 != decoder->protected_);
  87449. if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
  87450. return false;
  87451. for(i = 0; i < sizeof(decoder->private_->metadata_filter) / sizeof(decoder->private_->metadata_filter[0]); i++)
  87452. decoder->private_->metadata_filter[i] = true;
  87453. decoder->private_->metadata_filter_ids_count = 0;
  87454. return true;
  87455. }
  87456. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_ignore(FLAC__StreamDecoder *decoder, FLAC__MetadataType type)
  87457. {
  87458. FLAC__ASSERT(0 != decoder);
  87459. FLAC__ASSERT(0 != decoder->private_);
  87460. FLAC__ASSERT(0 != decoder->protected_);
  87461. FLAC__ASSERT((unsigned)type <= FLAC__MAX_METADATA_TYPE_CODE);
  87462. if((unsigned)type > FLAC__MAX_METADATA_TYPE_CODE)
  87463. return false;
  87464. if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
  87465. return false;
  87466. decoder->private_->metadata_filter[type] = false;
  87467. if(type == FLAC__METADATA_TYPE_APPLICATION)
  87468. decoder->private_->metadata_filter_ids_count = 0;
  87469. return true;
  87470. }
  87471. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_ignore_application(FLAC__StreamDecoder *decoder, const FLAC__byte id[4])
  87472. {
  87473. FLAC__ASSERT(0 != decoder);
  87474. FLAC__ASSERT(0 != decoder->private_);
  87475. FLAC__ASSERT(0 != decoder->protected_);
  87476. FLAC__ASSERT(0 != id);
  87477. if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
  87478. return false;
  87479. if(!decoder->private_->metadata_filter[FLAC__METADATA_TYPE_APPLICATION])
  87480. return true;
  87481. FLAC__ASSERT(0 != decoder->private_->metadata_filter_ids);
  87482. if(decoder->private_->metadata_filter_ids_count == decoder->private_->metadata_filter_ids_capacity) {
  87483. 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))) {
  87484. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  87485. return false;
  87486. }
  87487. decoder->private_->metadata_filter_ids_capacity *= 2;
  87488. }
  87489. 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));
  87490. decoder->private_->metadata_filter_ids_count++;
  87491. return true;
  87492. }
  87493. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_ignore_all(FLAC__StreamDecoder *decoder)
  87494. {
  87495. FLAC__ASSERT(0 != decoder);
  87496. FLAC__ASSERT(0 != decoder->private_);
  87497. FLAC__ASSERT(0 != decoder->protected_);
  87498. if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
  87499. return false;
  87500. memset(decoder->private_->metadata_filter, 0, sizeof(decoder->private_->metadata_filter));
  87501. decoder->private_->metadata_filter_ids_count = 0;
  87502. return true;
  87503. }
  87504. FLAC_API FLAC__StreamDecoderState FLAC__stream_decoder_get_state(const FLAC__StreamDecoder *decoder)
  87505. {
  87506. FLAC__ASSERT(0 != decoder);
  87507. FLAC__ASSERT(0 != decoder->protected_);
  87508. return decoder->protected_->state;
  87509. }
  87510. FLAC_API const char *FLAC__stream_decoder_get_resolved_state_string(const FLAC__StreamDecoder *decoder)
  87511. {
  87512. return FLAC__StreamDecoderStateString[decoder->protected_->state];
  87513. }
  87514. FLAC_API FLAC__bool FLAC__stream_decoder_get_md5_checking(const FLAC__StreamDecoder *decoder)
  87515. {
  87516. FLAC__ASSERT(0 != decoder);
  87517. FLAC__ASSERT(0 != decoder->protected_);
  87518. return decoder->protected_->md5_checking;
  87519. }
  87520. FLAC_API FLAC__uint64 FLAC__stream_decoder_get_total_samples(const FLAC__StreamDecoder *decoder)
  87521. {
  87522. FLAC__ASSERT(0 != decoder);
  87523. FLAC__ASSERT(0 != decoder->protected_);
  87524. return decoder->private_->has_stream_info? decoder->private_->stream_info.data.stream_info.total_samples : 0;
  87525. }
  87526. FLAC_API unsigned FLAC__stream_decoder_get_channels(const FLAC__StreamDecoder *decoder)
  87527. {
  87528. FLAC__ASSERT(0 != decoder);
  87529. FLAC__ASSERT(0 != decoder->protected_);
  87530. return decoder->protected_->channels;
  87531. }
  87532. FLAC_API FLAC__ChannelAssignment FLAC__stream_decoder_get_channel_assignment(const FLAC__StreamDecoder *decoder)
  87533. {
  87534. FLAC__ASSERT(0 != decoder);
  87535. FLAC__ASSERT(0 != decoder->protected_);
  87536. return decoder->protected_->channel_assignment;
  87537. }
  87538. FLAC_API unsigned FLAC__stream_decoder_get_bits_per_sample(const FLAC__StreamDecoder *decoder)
  87539. {
  87540. FLAC__ASSERT(0 != decoder);
  87541. FLAC__ASSERT(0 != decoder->protected_);
  87542. return decoder->protected_->bits_per_sample;
  87543. }
  87544. FLAC_API unsigned FLAC__stream_decoder_get_sample_rate(const FLAC__StreamDecoder *decoder)
  87545. {
  87546. FLAC__ASSERT(0 != decoder);
  87547. FLAC__ASSERT(0 != decoder->protected_);
  87548. return decoder->protected_->sample_rate;
  87549. }
  87550. FLAC_API unsigned FLAC__stream_decoder_get_blocksize(const FLAC__StreamDecoder *decoder)
  87551. {
  87552. FLAC__ASSERT(0 != decoder);
  87553. FLAC__ASSERT(0 != decoder->protected_);
  87554. return decoder->protected_->blocksize;
  87555. }
  87556. FLAC_API FLAC__bool FLAC__stream_decoder_get_decode_position(const FLAC__StreamDecoder *decoder, FLAC__uint64 *position)
  87557. {
  87558. FLAC__ASSERT(0 != decoder);
  87559. FLAC__ASSERT(0 != decoder->private_);
  87560. FLAC__ASSERT(0 != position);
  87561. #if FLAC__HAS_OGG
  87562. if(decoder->private_->is_ogg)
  87563. return false;
  87564. #endif
  87565. if(0 == decoder->private_->tell_callback)
  87566. return false;
  87567. if(decoder->private_->tell_callback(decoder, position, decoder->private_->client_data) != FLAC__STREAM_DECODER_TELL_STATUS_OK)
  87568. return false;
  87569. if(!FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input))
  87570. return false;
  87571. FLAC__ASSERT(*position >= FLAC__stream_decoder_get_input_bytes_unconsumed(decoder));
  87572. *position -= FLAC__stream_decoder_get_input_bytes_unconsumed(decoder);
  87573. return true;
  87574. }
  87575. FLAC_API FLAC__bool FLAC__stream_decoder_flush(FLAC__StreamDecoder *decoder)
  87576. {
  87577. FLAC__ASSERT(0 != decoder);
  87578. FLAC__ASSERT(0 != decoder->private_);
  87579. FLAC__ASSERT(0 != decoder->protected_);
  87580. decoder->private_->samples_decoded = 0;
  87581. decoder->private_->do_md5_checking = false;
  87582. #if FLAC__HAS_OGG
  87583. if(decoder->private_->is_ogg)
  87584. FLAC__ogg_decoder_aspect_flush(&decoder->protected_->ogg_decoder_aspect);
  87585. #endif
  87586. if(!FLAC__bitreader_clear(decoder->private_->input)) {
  87587. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  87588. return false;
  87589. }
  87590. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  87591. return true;
  87592. }
  87593. FLAC_API FLAC__bool FLAC__stream_decoder_reset(FLAC__StreamDecoder *decoder)
  87594. {
  87595. FLAC__ASSERT(0 != decoder);
  87596. FLAC__ASSERT(0 != decoder->private_);
  87597. FLAC__ASSERT(0 != decoder->protected_);
  87598. if(!FLAC__stream_decoder_flush(decoder)) {
  87599. return false;
  87600. }
  87601. #if FLAC__HAS_OGG
  87602. if(decoder->private_->is_ogg)
  87603. FLAC__ogg_decoder_aspect_reset(&decoder->protected_->ogg_decoder_aspect);
  87604. #endif
  87605. if(!decoder->private_->internal_reset_hack) {
  87606. if(decoder->private_->file == stdin)
  87607. return false; /* can't rewind stdin, reset fails */
  87608. if(decoder->private_->seek_callback && decoder->private_->seek_callback(decoder, 0, decoder->private_->client_data) == FLAC__STREAM_DECODER_SEEK_STATUS_ERROR)
  87609. return false; /* seekable and seek fails, reset fails */
  87610. }
  87611. else
  87612. decoder->private_->internal_reset_hack = false;
  87613. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_METADATA;
  87614. decoder->private_->has_stream_info = false;
  87615. if(decoder->private_->has_seek_table && 0 != decoder->private_->seek_table.data.seek_table.points) {
  87616. free(decoder->private_->seek_table.data.seek_table.points);
  87617. decoder->private_->seek_table.data.seek_table.points = 0;
  87618. decoder->private_->has_seek_table = false;
  87619. }
  87620. decoder->private_->do_md5_checking = decoder->protected_->md5_checking;
  87621. decoder->private_->fixed_block_size = decoder->private_->next_fixed_block_size = 0;
  87622. FLAC__MD5Init(&decoder->private_->md5context);
  87623. decoder->private_->first_frame_offset = 0;
  87624. decoder->private_->unparseable_frame_count = 0;
  87625. return true;
  87626. }
  87627. FLAC_API FLAC__bool FLAC__stream_decoder_process_single(FLAC__StreamDecoder *decoder)
  87628. {
  87629. FLAC__bool got_a_frame;
  87630. FLAC__ASSERT(0 != decoder);
  87631. FLAC__ASSERT(0 != decoder->protected_);
  87632. while(1) {
  87633. switch(decoder->protected_->state) {
  87634. case FLAC__STREAM_DECODER_SEARCH_FOR_METADATA:
  87635. if(!find_metadata_(decoder))
  87636. return false; /* above function sets the status for us */
  87637. break;
  87638. case FLAC__STREAM_DECODER_READ_METADATA:
  87639. if(!read_metadata_(decoder))
  87640. return false; /* above function sets the status for us */
  87641. else
  87642. return true;
  87643. case FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC:
  87644. if(!frame_sync_(decoder))
  87645. return true; /* above function sets the status for us */
  87646. break;
  87647. case FLAC__STREAM_DECODER_READ_FRAME:
  87648. if(!read_frame_(decoder, &got_a_frame, /*do_full_decode=*/true))
  87649. return false; /* above function sets the status for us */
  87650. if(got_a_frame)
  87651. return true; /* above function sets the status for us */
  87652. break;
  87653. case FLAC__STREAM_DECODER_END_OF_STREAM:
  87654. case FLAC__STREAM_DECODER_ABORTED:
  87655. return true;
  87656. default:
  87657. FLAC__ASSERT(0);
  87658. return false;
  87659. }
  87660. }
  87661. }
  87662. FLAC_API FLAC__bool FLAC__stream_decoder_process_until_end_of_metadata(FLAC__StreamDecoder *decoder)
  87663. {
  87664. FLAC__ASSERT(0 != decoder);
  87665. FLAC__ASSERT(0 != decoder->protected_);
  87666. while(1) {
  87667. switch(decoder->protected_->state) {
  87668. case FLAC__STREAM_DECODER_SEARCH_FOR_METADATA:
  87669. if(!find_metadata_(decoder))
  87670. return false; /* above function sets the status for us */
  87671. break;
  87672. case FLAC__STREAM_DECODER_READ_METADATA:
  87673. if(!read_metadata_(decoder))
  87674. return false; /* above function sets the status for us */
  87675. break;
  87676. case FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC:
  87677. case FLAC__STREAM_DECODER_READ_FRAME:
  87678. case FLAC__STREAM_DECODER_END_OF_STREAM:
  87679. case FLAC__STREAM_DECODER_ABORTED:
  87680. return true;
  87681. default:
  87682. FLAC__ASSERT(0);
  87683. return false;
  87684. }
  87685. }
  87686. }
  87687. FLAC_API FLAC__bool FLAC__stream_decoder_process_until_end_of_stream(FLAC__StreamDecoder *decoder)
  87688. {
  87689. FLAC__bool dummy;
  87690. FLAC__ASSERT(0 != decoder);
  87691. FLAC__ASSERT(0 != decoder->protected_);
  87692. while(1) {
  87693. switch(decoder->protected_->state) {
  87694. case FLAC__STREAM_DECODER_SEARCH_FOR_METADATA:
  87695. if(!find_metadata_(decoder))
  87696. return false; /* above function sets the status for us */
  87697. break;
  87698. case FLAC__STREAM_DECODER_READ_METADATA:
  87699. if(!read_metadata_(decoder))
  87700. return false; /* above function sets the status for us */
  87701. break;
  87702. case FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC:
  87703. if(!frame_sync_(decoder))
  87704. return true; /* above function sets the status for us */
  87705. break;
  87706. case FLAC__STREAM_DECODER_READ_FRAME:
  87707. if(!read_frame_(decoder, &dummy, /*do_full_decode=*/true))
  87708. return false; /* above function sets the status for us */
  87709. break;
  87710. case FLAC__STREAM_DECODER_END_OF_STREAM:
  87711. case FLAC__STREAM_DECODER_ABORTED:
  87712. return true;
  87713. default:
  87714. FLAC__ASSERT(0);
  87715. return false;
  87716. }
  87717. }
  87718. }
  87719. FLAC_API FLAC__bool FLAC__stream_decoder_skip_single_frame(FLAC__StreamDecoder *decoder)
  87720. {
  87721. FLAC__bool got_a_frame;
  87722. FLAC__ASSERT(0 != decoder);
  87723. FLAC__ASSERT(0 != decoder->protected_);
  87724. while(1) {
  87725. switch(decoder->protected_->state) {
  87726. case FLAC__STREAM_DECODER_SEARCH_FOR_METADATA:
  87727. case FLAC__STREAM_DECODER_READ_METADATA:
  87728. return false; /* above function sets the status for us */
  87729. case FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC:
  87730. if(!frame_sync_(decoder))
  87731. return true; /* above function sets the status for us */
  87732. break;
  87733. case FLAC__STREAM_DECODER_READ_FRAME:
  87734. if(!read_frame_(decoder, &got_a_frame, /*do_full_decode=*/false))
  87735. return false; /* above function sets the status for us */
  87736. if(got_a_frame)
  87737. return true; /* above function sets the status for us */
  87738. break;
  87739. case FLAC__STREAM_DECODER_END_OF_STREAM:
  87740. case FLAC__STREAM_DECODER_ABORTED:
  87741. return true;
  87742. default:
  87743. FLAC__ASSERT(0);
  87744. return false;
  87745. }
  87746. }
  87747. }
  87748. FLAC_API FLAC__bool FLAC__stream_decoder_seek_absolute(FLAC__StreamDecoder *decoder, FLAC__uint64 sample)
  87749. {
  87750. FLAC__uint64 length;
  87751. FLAC__ASSERT(0 != decoder);
  87752. if(
  87753. decoder->protected_->state != FLAC__STREAM_DECODER_SEARCH_FOR_METADATA &&
  87754. decoder->protected_->state != FLAC__STREAM_DECODER_READ_METADATA &&
  87755. decoder->protected_->state != FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC &&
  87756. decoder->protected_->state != FLAC__STREAM_DECODER_READ_FRAME &&
  87757. decoder->protected_->state != FLAC__STREAM_DECODER_END_OF_STREAM
  87758. )
  87759. return false;
  87760. if(0 == decoder->private_->seek_callback)
  87761. return false;
  87762. FLAC__ASSERT(decoder->private_->seek_callback);
  87763. FLAC__ASSERT(decoder->private_->tell_callback);
  87764. FLAC__ASSERT(decoder->private_->length_callback);
  87765. FLAC__ASSERT(decoder->private_->eof_callback);
  87766. if(FLAC__stream_decoder_get_total_samples(decoder) > 0 && sample >= FLAC__stream_decoder_get_total_samples(decoder))
  87767. return false;
  87768. decoder->private_->is_seeking = true;
  87769. decoder->private_->do_md5_checking = false;
  87770. if(decoder->private_->length_callback(decoder, &length, decoder->private_->client_data) != FLAC__STREAM_DECODER_LENGTH_STATUS_OK) {
  87771. decoder->private_->is_seeking = false;
  87772. return false;
  87773. }
  87774. if(
  87775. decoder->protected_->state == FLAC__STREAM_DECODER_SEARCH_FOR_METADATA ||
  87776. decoder->protected_->state == FLAC__STREAM_DECODER_READ_METADATA
  87777. ) {
  87778. if(!FLAC__stream_decoder_process_until_end_of_metadata(decoder)) {
  87779. decoder->private_->is_seeking = false;
  87780. return false;
  87781. }
  87782. if(FLAC__stream_decoder_get_total_samples(decoder) > 0 && sample >= FLAC__stream_decoder_get_total_samples(decoder)) {
  87783. decoder->private_->is_seeking = false;
  87784. return false;
  87785. }
  87786. }
  87787. {
  87788. const FLAC__bool ok =
  87789. #if FLAC__HAS_OGG
  87790. decoder->private_->is_ogg?
  87791. seek_to_absolute_sample_ogg_(decoder, length, sample) :
  87792. #endif
  87793. seek_to_absolute_sample_(decoder, length, sample)
  87794. ;
  87795. decoder->private_->is_seeking = false;
  87796. return ok;
  87797. }
  87798. }
  87799. unsigned FLAC__stream_decoder_get_input_bytes_unconsumed(const FLAC__StreamDecoder *decoder)
  87800. {
  87801. FLAC__ASSERT(0 != decoder);
  87802. FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input));
  87803. FLAC__ASSERT(!(FLAC__bitreader_get_input_bits_unconsumed(decoder->private_->input) & 7));
  87804. return FLAC__bitreader_get_input_bits_unconsumed(decoder->private_->input) / 8;
  87805. }
  87806. void set_defaults_dec(FLAC__StreamDecoder *decoder)
  87807. {
  87808. #if FLAC__HAS_OGG
  87809. decoder->private_->is_ogg = false;
  87810. #endif
  87811. decoder->private_->read_callback = 0;
  87812. decoder->private_->seek_callback = 0;
  87813. decoder->private_->tell_callback = 0;
  87814. decoder->private_->length_callback = 0;
  87815. decoder->private_->eof_callback = 0;
  87816. decoder->private_->write_callback = 0;
  87817. decoder->private_->metadata_callback = 0;
  87818. decoder->private_->error_callback = 0;
  87819. decoder->private_->client_data = 0;
  87820. memset(decoder->private_->metadata_filter, 0, sizeof(decoder->private_->metadata_filter));
  87821. decoder->private_->metadata_filter[FLAC__METADATA_TYPE_STREAMINFO] = true;
  87822. decoder->private_->metadata_filter_ids_count = 0;
  87823. decoder->protected_->md5_checking = false;
  87824. #if FLAC__HAS_OGG
  87825. FLAC__ogg_decoder_aspect_set_defaults(&decoder->protected_->ogg_decoder_aspect);
  87826. #endif
  87827. }
  87828. FILE *get_binary_stdin_(void)
  87829. {
  87830. #if defined _MSC_VER || defined __MINGW32__
  87831. _setmode(_fileno(stdin), _O_BINARY);
  87832. #elif defined __CYGWIN__
  87833. setmode(_fileno(stdin), _O_BINARY);
  87834. #elif defined __EMX__
  87835. setmode(fileno(stdin), O_BINARY);
  87836. #endif
  87837. return stdin;
  87838. }
  87839. FLAC__bool allocate_output_(FLAC__StreamDecoder *decoder, unsigned size, unsigned channels)
  87840. {
  87841. unsigned i;
  87842. FLAC__int32 *tmp;
  87843. if(size <= decoder->private_->output_capacity && channels <= decoder->private_->output_channels)
  87844. return true;
  87845. for(i = 0; i < FLAC__MAX_CHANNELS; i++) {
  87846. if(0 != decoder->private_->output[i]) {
  87847. free(decoder->private_->output[i]-4);
  87848. decoder->private_->output[i] = 0;
  87849. }
  87850. if(0 != decoder->private_->residual_unaligned[i]) {
  87851. free(decoder->private_->residual_unaligned[i]);
  87852. decoder->private_->residual_unaligned[i] = decoder->private_->residual[i] = 0;
  87853. }
  87854. }
  87855. for(i = 0; i < channels; i++) {
  87856. tmp = (FLAC__int32*)safe_malloc_muladd2_(sizeof(FLAC__int32), /*times (*/size, /*+*/4/*)*/);
  87857. if(tmp == 0) {
  87858. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  87859. return false;
  87860. }
  87861. memset(tmp, 0, sizeof(FLAC__int32)*4);
  87862. decoder->private_->output[i] = tmp + 4;
  87863. if(!FLAC__memory_alloc_aligned_int32_array(size, &decoder->private_->residual_unaligned[i], &decoder->private_->residual[i])) {
  87864. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  87865. return false;
  87866. }
  87867. }
  87868. decoder->private_->output_capacity = size;
  87869. decoder->private_->output_channels = channels;
  87870. return true;
  87871. }
  87872. FLAC__bool has_id_filtered_(FLAC__StreamDecoder *decoder, FLAC__byte *id)
  87873. {
  87874. size_t i;
  87875. FLAC__ASSERT(0 != decoder);
  87876. FLAC__ASSERT(0 != decoder->private_);
  87877. for(i = 0; i < decoder->private_->metadata_filter_ids_count; i++)
  87878. if(0 == memcmp(decoder->private_->metadata_filter_ids + i * (FLAC__STREAM_METADATA_APPLICATION_ID_LEN/8), id, (FLAC__STREAM_METADATA_APPLICATION_ID_LEN/8)))
  87879. return true;
  87880. return false;
  87881. }
  87882. FLAC__bool find_metadata_(FLAC__StreamDecoder *decoder)
  87883. {
  87884. FLAC__uint32 x;
  87885. unsigned i, id_;
  87886. FLAC__bool first = true;
  87887. FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input));
  87888. for(i = id_ = 0; i < 4; ) {
  87889. if(decoder->private_->cached) {
  87890. x = (FLAC__uint32)decoder->private_->lookahead;
  87891. decoder->private_->cached = false;
  87892. }
  87893. else {
  87894. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 8))
  87895. return false; /* read_callback_ sets the state for us */
  87896. }
  87897. if(x == FLAC__STREAM_SYNC_STRING[i]) {
  87898. first = true;
  87899. i++;
  87900. id_ = 0;
  87901. continue;
  87902. }
  87903. if(x == ID3V2_TAG_[id_]) {
  87904. id_++;
  87905. i = 0;
  87906. if(id_ == 3) {
  87907. if(!skip_id3v2_tag_(decoder))
  87908. return false; /* skip_id3v2_tag_ sets the state for us */
  87909. }
  87910. continue;
  87911. }
  87912. id_ = 0;
  87913. if(x == 0xff) { /* MAGIC NUMBER for the first 8 frame sync bits */
  87914. decoder->private_->header_warmup[0] = (FLAC__byte)x;
  87915. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 8))
  87916. return false; /* read_callback_ sets the state for us */
  87917. if(x == 0xff) { /* MAGIC NUMBER for the first 8 frame sync bits */
  87918. decoder->private_->lookahead = (FLAC__byte)x;
  87919. decoder->private_->cached = true;
  87920. }
  87921. else if(x >> 2 == 0x3e) { /* MAGIC NUMBER for the last 6 sync bits */
  87922. decoder->private_->header_warmup[1] = (FLAC__byte)x;
  87923. decoder->protected_->state = FLAC__STREAM_DECODER_READ_FRAME;
  87924. return true;
  87925. }
  87926. }
  87927. i = 0;
  87928. if(first) {
  87929. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC);
  87930. first = false;
  87931. }
  87932. }
  87933. decoder->protected_->state = FLAC__STREAM_DECODER_READ_METADATA;
  87934. return true;
  87935. }
  87936. FLAC__bool read_metadata_(FLAC__StreamDecoder *decoder)
  87937. {
  87938. FLAC__bool is_last;
  87939. FLAC__uint32 i, x, type, length;
  87940. FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input));
  87941. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_IS_LAST_LEN))
  87942. return false; /* read_callback_ sets the state for us */
  87943. is_last = x? true : false;
  87944. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &type, FLAC__STREAM_METADATA_TYPE_LEN))
  87945. return false; /* read_callback_ sets the state for us */
  87946. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &length, FLAC__STREAM_METADATA_LENGTH_LEN))
  87947. return false; /* read_callback_ sets the state for us */
  87948. if(type == FLAC__METADATA_TYPE_STREAMINFO) {
  87949. if(!read_metadata_streaminfo_(decoder, is_last, length))
  87950. return false;
  87951. decoder->private_->has_stream_info = true;
  87952. 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))
  87953. decoder->private_->do_md5_checking = false;
  87954. if(!decoder->private_->is_seeking && decoder->private_->metadata_filter[FLAC__METADATA_TYPE_STREAMINFO] && decoder->private_->metadata_callback)
  87955. decoder->private_->metadata_callback(decoder, &decoder->private_->stream_info, decoder->private_->client_data);
  87956. }
  87957. else if(type == FLAC__METADATA_TYPE_SEEKTABLE) {
  87958. if(!read_metadata_seektable_(decoder, is_last, length))
  87959. return false;
  87960. decoder->private_->has_seek_table = true;
  87961. if(!decoder->private_->is_seeking && decoder->private_->metadata_filter[FLAC__METADATA_TYPE_SEEKTABLE] && decoder->private_->metadata_callback)
  87962. decoder->private_->metadata_callback(decoder, &decoder->private_->seek_table, decoder->private_->client_data);
  87963. }
  87964. else {
  87965. FLAC__bool skip_it = !decoder->private_->metadata_filter[type];
  87966. unsigned real_length = length;
  87967. FLAC__StreamMetadata block;
  87968. block.is_last = is_last;
  87969. block.type = (FLAC__MetadataType)type;
  87970. block.length = length;
  87971. if(type == FLAC__METADATA_TYPE_APPLICATION) {
  87972. if(!FLAC__bitreader_read_byte_block_aligned_no_crc(decoder->private_->input, block.data.application.id, FLAC__STREAM_METADATA_APPLICATION_ID_LEN/8))
  87973. return false; /* read_callback_ sets the state for us */
  87974. if(real_length < FLAC__STREAM_METADATA_APPLICATION_ID_LEN/8) { /* underflow check */
  87975. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;/*@@@@@@ maybe wrong error? need to resync?*/
  87976. return false;
  87977. }
  87978. real_length -= FLAC__STREAM_METADATA_APPLICATION_ID_LEN/8;
  87979. if(decoder->private_->metadata_filter_ids_count > 0 && has_id_filtered_(decoder, block.data.application.id))
  87980. skip_it = !skip_it;
  87981. }
  87982. if(skip_it) {
  87983. if(!FLAC__bitreader_skip_byte_block_aligned_no_crc(decoder->private_->input, real_length))
  87984. return false; /* read_callback_ sets the state for us */
  87985. }
  87986. else {
  87987. switch(type) {
  87988. case FLAC__METADATA_TYPE_PADDING:
  87989. if(!FLAC__bitreader_skip_byte_block_aligned_no_crc(decoder->private_->input, real_length))
  87990. return false; /* read_callback_ sets the state for us */
  87991. break;
  87992. case FLAC__METADATA_TYPE_APPLICATION:
  87993. if(real_length > 0) {
  87994. if(0 == (block.data.application.data = (FLAC__byte*)malloc(real_length))) {
  87995. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  87996. return false;
  87997. }
  87998. if(!FLAC__bitreader_read_byte_block_aligned_no_crc(decoder->private_->input, block.data.application.data, real_length))
  87999. return false; /* read_callback_ sets the state for us */
  88000. }
  88001. else
  88002. block.data.application.data = 0;
  88003. break;
  88004. case FLAC__METADATA_TYPE_VORBIS_COMMENT:
  88005. if(!read_metadata_vorbiscomment_(decoder, &block.data.vorbis_comment))
  88006. return false;
  88007. break;
  88008. case FLAC__METADATA_TYPE_CUESHEET:
  88009. if(!read_metadata_cuesheet_(decoder, &block.data.cue_sheet))
  88010. return false;
  88011. break;
  88012. case FLAC__METADATA_TYPE_PICTURE:
  88013. if(!read_metadata_picture_(decoder, &block.data.picture))
  88014. return false;
  88015. break;
  88016. case FLAC__METADATA_TYPE_STREAMINFO:
  88017. case FLAC__METADATA_TYPE_SEEKTABLE:
  88018. FLAC__ASSERT(0);
  88019. break;
  88020. default:
  88021. if(real_length > 0) {
  88022. if(0 == (block.data.unknown.data = (FLAC__byte*)malloc(real_length))) {
  88023. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  88024. return false;
  88025. }
  88026. if(!FLAC__bitreader_read_byte_block_aligned_no_crc(decoder->private_->input, block.data.unknown.data, real_length))
  88027. return false; /* read_callback_ sets the state for us */
  88028. }
  88029. else
  88030. block.data.unknown.data = 0;
  88031. break;
  88032. }
  88033. if(!decoder->private_->is_seeking && decoder->private_->metadata_callback)
  88034. decoder->private_->metadata_callback(decoder, &block, decoder->private_->client_data);
  88035. switch(type) {
  88036. case FLAC__METADATA_TYPE_PADDING:
  88037. break;
  88038. case FLAC__METADATA_TYPE_APPLICATION:
  88039. if(0 != block.data.application.data)
  88040. free(block.data.application.data);
  88041. break;
  88042. case FLAC__METADATA_TYPE_VORBIS_COMMENT:
  88043. if(0 != block.data.vorbis_comment.vendor_string.entry)
  88044. free(block.data.vorbis_comment.vendor_string.entry);
  88045. if(block.data.vorbis_comment.num_comments > 0)
  88046. for(i = 0; i < block.data.vorbis_comment.num_comments; i++)
  88047. if(0 != block.data.vorbis_comment.comments[i].entry)
  88048. free(block.data.vorbis_comment.comments[i].entry);
  88049. if(0 != block.data.vorbis_comment.comments)
  88050. free(block.data.vorbis_comment.comments);
  88051. break;
  88052. case FLAC__METADATA_TYPE_CUESHEET:
  88053. if(block.data.cue_sheet.num_tracks > 0)
  88054. for(i = 0; i < block.data.cue_sheet.num_tracks; i++)
  88055. if(0 != block.data.cue_sheet.tracks[i].indices)
  88056. free(block.data.cue_sheet.tracks[i].indices);
  88057. if(0 != block.data.cue_sheet.tracks)
  88058. free(block.data.cue_sheet.tracks);
  88059. break;
  88060. case FLAC__METADATA_TYPE_PICTURE:
  88061. if(0 != block.data.picture.mime_type)
  88062. free(block.data.picture.mime_type);
  88063. if(0 != block.data.picture.description)
  88064. free(block.data.picture.description);
  88065. if(0 != block.data.picture.data)
  88066. free(block.data.picture.data);
  88067. break;
  88068. case FLAC__METADATA_TYPE_STREAMINFO:
  88069. case FLAC__METADATA_TYPE_SEEKTABLE:
  88070. FLAC__ASSERT(0);
  88071. default:
  88072. if(0 != block.data.unknown.data)
  88073. free(block.data.unknown.data);
  88074. break;
  88075. }
  88076. }
  88077. }
  88078. if(is_last) {
  88079. if(!FLAC__stream_decoder_get_decode_position(decoder, &decoder->private_->first_frame_offset))
  88080. decoder->private_->first_frame_offset = 0;
  88081. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  88082. }
  88083. return true;
  88084. }
  88085. FLAC__bool read_metadata_streaminfo_(FLAC__StreamDecoder *decoder, FLAC__bool is_last, unsigned length)
  88086. {
  88087. FLAC__uint32 x;
  88088. unsigned bits, used_bits = 0;
  88089. FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input));
  88090. decoder->private_->stream_info.type = FLAC__METADATA_TYPE_STREAMINFO;
  88091. decoder->private_->stream_info.is_last = is_last;
  88092. decoder->private_->stream_info.length = length;
  88093. bits = FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN;
  88094. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, bits))
  88095. return false; /* read_callback_ sets the state for us */
  88096. decoder->private_->stream_info.data.stream_info.min_blocksize = x;
  88097. used_bits += bits;
  88098. bits = FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN;
  88099. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN))
  88100. return false; /* read_callback_ sets the state for us */
  88101. decoder->private_->stream_info.data.stream_info.max_blocksize = x;
  88102. used_bits += bits;
  88103. bits = FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN;
  88104. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN))
  88105. return false; /* read_callback_ sets the state for us */
  88106. decoder->private_->stream_info.data.stream_info.min_framesize = x;
  88107. used_bits += bits;
  88108. bits = FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN;
  88109. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN))
  88110. return false; /* read_callback_ sets the state for us */
  88111. decoder->private_->stream_info.data.stream_info.max_framesize = x;
  88112. used_bits += bits;
  88113. bits = FLAC__STREAM_METADATA_STREAMINFO_SAMPLE_RATE_LEN;
  88114. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_STREAMINFO_SAMPLE_RATE_LEN))
  88115. return false; /* read_callback_ sets the state for us */
  88116. decoder->private_->stream_info.data.stream_info.sample_rate = x;
  88117. used_bits += bits;
  88118. bits = FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN;
  88119. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN))
  88120. return false; /* read_callback_ sets the state for us */
  88121. decoder->private_->stream_info.data.stream_info.channels = x+1;
  88122. used_bits += bits;
  88123. bits = FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN;
  88124. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN))
  88125. return false; /* read_callback_ sets the state for us */
  88126. decoder->private_->stream_info.data.stream_info.bits_per_sample = x+1;
  88127. used_bits += bits;
  88128. bits = FLAC__STREAM_METADATA_STREAMINFO_TOTAL_SAMPLES_LEN;
  88129. 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))
  88130. return false; /* read_callback_ sets the state for us */
  88131. used_bits += bits;
  88132. if(!FLAC__bitreader_read_byte_block_aligned_no_crc(decoder->private_->input, decoder->private_->stream_info.data.stream_info.md5sum, 16))
  88133. return false; /* read_callback_ sets the state for us */
  88134. used_bits += 16*8;
  88135. FLAC__ASSERT(used_bits % 8 == 0);
  88136. length -= (used_bits / 8);
  88137. if(!FLAC__bitreader_skip_byte_block_aligned_no_crc(decoder->private_->input, length))
  88138. return false; /* read_callback_ sets the state for us */
  88139. return true;
  88140. }
  88141. FLAC__bool read_metadata_seektable_(FLAC__StreamDecoder *decoder, FLAC__bool is_last, unsigned length)
  88142. {
  88143. FLAC__uint32 i, x;
  88144. FLAC__uint64 xx;
  88145. FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input));
  88146. decoder->private_->seek_table.type = FLAC__METADATA_TYPE_SEEKTABLE;
  88147. decoder->private_->seek_table.is_last = is_last;
  88148. decoder->private_->seek_table.length = length;
  88149. decoder->private_->seek_table.data.seek_table.num_points = length / FLAC__STREAM_METADATA_SEEKPOINT_LENGTH;
  88150. 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)))) {
  88151. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  88152. return false;
  88153. }
  88154. for(i = 0; i < decoder->private_->seek_table.data.seek_table.num_points; i++) {
  88155. if(!FLAC__bitreader_read_raw_uint64(decoder->private_->input, &xx, FLAC__STREAM_METADATA_SEEKPOINT_SAMPLE_NUMBER_LEN))
  88156. return false; /* read_callback_ sets the state for us */
  88157. decoder->private_->seek_table.data.seek_table.points[i].sample_number = xx;
  88158. if(!FLAC__bitreader_read_raw_uint64(decoder->private_->input, &xx, FLAC__STREAM_METADATA_SEEKPOINT_STREAM_OFFSET_LEN))
  88159. return false; /* read_callback_ sets the state for us */
  88160. decoder->private_->seek_table.data.seek_table.points[i].stream_offset = xx;
  88161. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_SEEKPOINT_FRAME_SAMPLES_LEN))
  88162. return false; /* read_callback_ sets the state for us */
  88163. decoder->private_->seek_table.data.seek_table.points[i].frame_samples = x;
  88164. }
  88165. length -= (decoder->private_->seek_table.data.seek_table.num_points * FLAC__STREAM_METADATA_SEEKPOINT_LENGTH);
  88166. if(length > 0) {
  88167. if(!FLAC__bitreader_skip_byte_block_aligned_no_crc(decoder->private_->input, length))
  88168. return false; /* read_callback_ sets the state for us */
  88169. }
  88170. return true;
  88171. }
  88172. FLAC__bool read_metadata_vorbiscomment_(FLAC__StreamDecoder *decoder, FLAC__StreamMetadata_VorbisComment *obj)
  88173. {
  88174. FLAC__uint32 i;
  88175. FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input));
  88176. FLAC__ASSERT(FLAC__STREAM_METADATA_VORBIS_COMMENT_ENTRY_LENGTH_LEN == 32);
  88177. if(!FLAC__bitreader_read_uint32_little_endian(decoder->private_->input, &obj->vendor_string.length))
  88178. return false; /* read_callback_ sets the state for us */
  88179. if(obj->vendor_string.length > 0) {
  88180. if(0 == (obj->vendor_string.entry = (FLAC__byte*)safe_malloc_add_2op_(obj->vendor_string.length, /*+*/1))) {
  88181. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  88182. return false;
  88183. }
  88184. if(!FLAC__bitreader_read_byte_block_aligned_no_crc(decoder->private_->input, obj->vendor_string.entry, obj->vendor_string.length))
  88185. return false; /* read_callback_ sets the state for us */
  88186. obj->vendor_string.entry[obj->vendor_string.length] = '\0';
  88187. }
  88188. else
  88189. obj->vendor_string.entry = 0;
  88190. FLAC__ASSERT(FLAC__STREAM_METADATA_VORBIS_COMMENT_NUM_COMMENTS_LEN == 32);
  88191. if(!FLAC__bitreader_read_uint32_little_endian(decoder->private_->input, &obj->num_comments))
  88192. return false; /* read_callback_ sets the state for us */
  88193. if(obj->num_comments > 0) {
  88194. if(0 == (obj->comments = (FLAC__StreamMetadata_VorbisComment_Entry*)safe_malloc_mul_2op_(obj->num_comments, /*times*/sizeof(FLAC__StreamMetadata_VorbisComment_Entry)))) {
  88195. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  88196. return false;
  88197. }
  88198. for(i = 0; i < obj->num_comments; i++) {
  88199. FLAC__ASSERT(FLAC__STREAM_METADATA_VORBIS_COMMENT_ENTRY_LENGTH_LEN == 32);
  88200. if(!FLAC__bitreader_read_uint32_little_endian(decoder->private_->input, &obj->comments[i].length))
  88201. return false; /* read_callback_ sets the state for us */
  88202. if(obj->comments[i].length > 0) {
  88203. if(0 == (obj->comments[i].entry = (FLAC__byte*)safe_malloc_add_2op_(obj->comments[i].length, /*+*/1))) {
  88204. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  88205. return false;
  88206. }
  88207. if(!FLAC__bitreader_read_byte_block_aligned_no_crc(decoder->private_->input, obj->comments[i].entry, obj->comments[i].length))
  88208. return false; /* read_callback_ sets the state for us */
  88209. obj->comments[i].entry[obj->comments[i].length] = '\0';
  88210. }
  88211. else
  88212. obj->comments[i].entry = 0;
  88213. }
  88214. }
  88215. else {
  88216. obj->comments = 0;
  88217. }
  88218. return true;
  88219. }
  88220. FLAC__bool read_metadata_cuesheet_(FLAC__StreamDecoder *decoder, FLAC__StreamMetadata_CueSheet *obj)
  88221. {
  88222. FLAC__uint32 i, j, x;
  88223. FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input));
  88224. memset(obj, 0, sizeof(FLAC__StreamMetadata_CueSheet));
  88225. FLAC__ASSERT(FLAC__STREAM_METADATA_CUESHEET_MEDIA_CATALOG_NUMBER_LEN % 8 == 0);
  88226. 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))
  88227. return false; /* read_callback_ sets the state for us */
  88228. if(!FLAC__bitreader_read_raw_uint64(decoder->private_->input, &obj->lead_in, FLAC__STREAM_METADATA_CUESHEET_LEAD_IN_LEN))
  88229. return false; /* read_callback_ sets the state for us */
  88230. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_CUESHEET_IS_CD_LEN))
  88231. return false; /* read_callback_ sets the state for us */
  88232. obj->is_cd = x? true : false;
  88233. if(!FLAC__bitreader_skip_bits_no_crc(decoder->private_->input, FLAC__STREAM_METADATA_CUESHEET_RESERVED_LEN))
  88234. return false; /* read_callback_ sets the state for us */
  88235. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_CUESHEET_NUM_TRACKS_LEN))
  88236. return false; /* read_callback_ sets the state for us */
  88237. obj->num_tracks = x;
  88238. if(obj->num_tracks > 0) {
  88239. if(0 == (obj->tracks = (FLAC__StreamMetadata_CueSheet_Track*)safe_calloc_(obj->num_tracks, sizeof(FLAC__StreamMetadata_CueSheet_Track)))) {
  88240. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  88241. return false;
  88242. }
  88243. for(i = 0; i < obj->num_tracks; i++) {
  88244. FLAC__StreamMetadata_CueSheet_Track *track = &obj->tracks[i];
  88245. if(!FLAC__bitreader_read_raw_uint64(decoder->private_->input, &track->offset, FLAC__STREAM_METADATA_CUESHEET_TRACK_OFFSET_LEN))
  88246. return false; /* read_callback_ sets the state for us */
  88247. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_CUESHEET_TRACK_NUMBER_LEN))
  88248. return false; /* read_callback_ sets the state for us */
  88249. track->number = (FLAC__byte)x;
  88250. FLAC__ASSERT(FLAC__STREAM_METADATA_CUESHEET_TRACK_ISRC_LEN % 8 == 0);
  88251. if(!FLAC__bitreader_read_byte_block_aligned_no_crc(decoder->private_->input, (FLAC__byte*)track->isrc, FLAC__STREAM_METADATA_CUESHEET_TRACK_ISRC_LEN/8))
  88252. return false; /* read_callback_ sets the state for us */
  88253. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_CUESHEET_TRACK_TYPE_LEN))
  88254. return false; /* read_callback_ sets the state for us */
  88255. track->type = x;
  88256. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_CUESHEET_TRACK_PRE_EMPHASIS_LEN))
  88257. return false; /* read_callback_ sets the state for us */
  88258. track->pre_emphasis = x;
  88259. if(!FLAC__bitreader_skip_bits_no_crc(decoder->private_->input, FLAC__STREAM_METADATA_CUESHEET_TRACK_RESERVED_LEN))
  88260. return false; /* read_callback_ sets the state for us */
  88261. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_CUESHEET_TRACK_NUM_INDICES_LEN))
  88262. return false; /* read_callback_ sets the state for us */
  88263. track->num_indices = (FLAC__byte)x;
  88264. if(track->num_indices > 0) {
  88265. if(0 == (track->indices = (FLAC__StreamMetadata_CueSheet_Index*)safe_calloc_(track->num_indices, sizeof(FLAC__StreamMetadata_CueSheet_Index)))) {
  88266. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  88267. return false;
  88268. }
  88269. for(j = 0; j < track->num_indices; j++) {
  88270. FLAC__StreamMetadata_CueSheet_Index *index = &track->indices[j];
  88271. if(!FLAC__bitreader_read_raw_uint64(decoder->private_->input, &index->offset, FLAC__STREAM_METADATA_CUESHEET_INDEX_OFFSET_LEN))
  88272. return false; /* read_callback_ sets the state for us */
  88273. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_CUESHEET_INDEX_NUMBER_LEN))
  88274. return false; /* read_callback_ sets the state for us */
  88275. index->number = (FLAC__byte)x;
  88276. if(!FLAC__bitreader_skip_bits_no_crc(decoder->private_->input, FLAC__STREAM_METADATA_CUESHEET_INDEX_RESERVED_LEN))
  88277. return false; /* read_callback_ sets the state for us */
  88278. }
  88279. }
  88280. }
  88281. }
  88282. return true;
  88283. }
  88284. FLAC__bool read_metadata_picture_(FLAC__StreamDecoder *decoder, FLAC__StreamMetadata_Picture *obj)
  88285. {
  88286. FLAC__uint32 x;
  88287. FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input));
  88288. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_PICTURE_TYPE_LEN))
  88289. return false; /* read_callback_ sets the state for us */
  88290. obj->type = (FLAC__StreamMetadata_Picture_Type) x;
  88291. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_PICTURE_MIME_TYPE_LENGTH_LEN))
  88292. return false; /* read_callback_ sets the state for us */
  88293. if(0 == (obj->mime_type = (char*)safe_malloc_add_2op_(x, /*+*/1))) {
  88294. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  88295. return false;
  88296. }
  88297. if(x > 0) {
  88298. if(!FLAC__bitreader_read_byte_block_aligned_no_crc(decoder->private_->input, (FLAC__byte*)obj->mime_type, x))
  88299. return false; /* read_callback_ sets the state for us */
  88300. }
  88301. obj->mime_type[x] = '\0';
  88302. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_PICTURE_DESCRIPTION_LENGTH_LEN))
  88303. return false; /* read_callback_ sets the state for us */
  88304. if(0 == (obj->description = (FLAC__byte*)safe_malloc_add_2op_(x, /*+*/1))) {
  88305. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  88306. return false;
  88307. }
  88308. if(x > 0) {
  88309. if(!FLAC__bitreader_read_byte_block_aligned_no_crc(decoder->private_->input, obj->description, x))
  88310. return false; /* read_callback_ sets the state for us */
  88311. }
  88312. obj->description[x] = '\0';
  88313. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &obj->width, FLAC__STREAM_METADATA_PICTURE_WIDTH_LEN))
  88314. return false; /* read_callback_ sets the state for us */
  88315. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &obj->height, FLAC__STREAM_METADATA_PICTURE_HEIGHT_LEN))
  88316. return false; /* read_callback_ sets the state for us */
  88317. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &obj->depth, FLAC__STREAM_METADATA_PICTURE_DEPTH_LEN))
  88318. return false; /* read_callback_ sets the state for us */
  88319. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &obj->colors, FLAC__STREAM_METADATA_PICTURE_COLORS_LEN))
  88320. return false; /* read_callback_ sets the state for us */
  88321. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &(obj->data_length), FLAC__STREAM_METADATA_PICTURE_DATA_LENGTH_LEN))
  88322. return false; /* read_callback_ sets the state for us */
  88323. if(0 == (obj->data = (FLAC__byte*)safe_malloc_(obj->data_length))) {
  88324. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  88325. return false;
  88326. }
  88327. if(obj->data_length > 0) {
  88328. if(!FLAC__bitreader_read_byte_block_aligned_no_crc(decoder->private_->input, obj->data, obj->data_length))
  88329. return false; /* read_callback_ sets the state for us */
  88330. }
  88331. return true;
  88332. }
  88333. FLAC__bool skip_id3v2_tag_(FLAC__StreamDecoder *decoder)
  88334. {
  88335. FLAC__uint32 x;
  88336. unsigned i, skip;
  88337. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 24))
  88338. return false; /* read_callback_ sets the state for us */
  88339. skip = 0;
  88340. for(i = 0; i < 4; i++) {
  88341. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 8))
  88342. return false; /* read_callback_ sets the state for us */
  88343. skip <<= 7;
  88344. skip |= (x & 0x7f);
  88345. }
  88346. if(!FLAC__bitreader_skip_byte_block_aligned_no_crc(decoder->private_->input, skip))
  88347. return false; /* read_callback_ sets the state for us */
  88348. return true;
  88349. }
  88350. FLAC__bool frame_sync_(FLAC__StreamDecoder *decoder)
  88351. {
  88352. FLAC__uint32 x;
  88353. FLAC__bool first = true;
  88354. if(FLAC__stream_decoder_get_total_samples(decoder) > 0) {
  88355. if(decoder->private_->samples_decoded >= FLAC__stream_decoder_get_total_samples(decoder)) {
  88356. decoder->protected_->state = FLAC__STREAM_DECODER_END_OF_STREAM;
  88357. return true;
  88358. }
  88359. }
  88360. if(!FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input)) {
  88361. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__bitreader_bits_left_for_byte_alignment(decoder->private_->input)))
  88362. return false; /* read_callback_ sets the state for us */
  88363. }
  88364. while(1) {
  88365. if(decoder->private_->cached) {
  88366. x = (FLAC__uint32)decoder->private_->lookahead;
  88367. decoder->private_->cached = false;
  88368. }
  88369. else {
  88370. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 8))
  88371. return false; /* read_callback_ sets the state for us */
  88372. }
  88373. if(x == 0xff) { /* MAGIC NUMBER for the first 8 frame sync bits */
  88374. decoder->private_->header_warmup[0] = (FLAC__byte)x;
  88375. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 8))
  88376. return false; /* read_callback_ sets the state for us */
  88377. if(x == 0xff) { /* MAGIC NUMBER for the first 8 frame sync bits */
  88378. decoder->private_->lookahead = (FLAC__byte)x;
  88379. decoder->private_->cached = true;
  88380. }
  88381. else if(x >> 2 == 0x3e) { /* MAGIC NUMBER for the last 6 sync bits */
  88382. decoder->private_->header_warmup[1] = (FLAC__byte)x;
  88383. decoder->protected_->state = FLAC__STREAM_DECODER_READ_FRAME;
  88384. return true;
  88385. }
  88386. }
  88387. if(first) {
  88388. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC);
  88389. first = false;
  88390. }
  88391. }
  88392. return true;
  88393. }
  88394. FLAC__bool read_frame_(FLAC__StreamDecoder *decoder, FLAC__bool *got_a_frame, FLAC__bool do_full_decode)
  88395. {
  88396. unsigned channel;
  88397. unsigned i;
  88398. FLAC__int32 mid, side;
  88399. unsigned frame_crc; /* the one we calculate from the input stream */
  88400. FLAC__uint32 x;
  88401. *got_a_frame = false;
  88402. frame_crc = 0;
  88403. frame_crc = FLAC__CRC16_UPDATE(decoder->private_->header_warmup[0], frame_crc);
  88404. frame_crc = FLAC__CRC16_UPDATE(decoder->private_->header_warmup[1], frame_crc);
  88405. FLAC__bitreader_reset_read_crc16(decoder->private_->input, (FLAC__uint16)frame_crc);
  88406. if(!read_frame_header_(decoder))
  88407. return false;
  88408. if(decoder->protected_->state == FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC) /* means we didn't sync on a valid header */
  88409. return true;
  88410. if(!allocate_output_(decoder, decoder->private_->frame.header.blocksize, decoder->private_->frame.header.channels))
  88411. return false;
  88412. for(channel = 0; channel < decoder->private_->frame.header.channels; channel++) {
  88413. unsigned bps = decoder->private_->frame.header.bits_per_sample;
  88414. switch(decoder->private_->frame.header.channel_assignment) {
  88415. case FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT:
  88416. break;
  88417. case FLAC__CHANNEL_ASSIGNMENT_LEFT_SIDE:
  88418. FLAC__ASSERT(decoder->private_->frame.header.channels == 2);
  88419. if(channel == 1)
  88420. bps++;
  88421. break;
  88422. case FLAC__CHANNEL_ASSIGNMENT_RIGHT_SIDE:
  88423. FLAC__ASSERT(decoder->private_->frame.header.channels == 2);
  88424. if(channel == 0)
  88425. bps++;
  88426. break;
  88427. case FLAC__CHANNEL_ASSIGNMENT_MID_SIDE:
  88428. FLAC__ASSERT(decoder->private_->frame.header.channels == 2);
  88429. if(channel == 1)
  88430. bps++;
  88431. break;
  88432. default:
  88433. FLAC__ASSERT(0);
  88434. }
  88435. if(!read_subframe_(decoder, channel, bps, do_full_decode))
  88436. return false;
  88437. if(decoder->protected_->state == FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC) /* means bad sync or got corruption */
  88438. return true;
  88439. }
  88440. if(!read_zero_padding_(decoder))
  88441. return false;
  88442. 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) */
  88443. return true;
  88444. frame_crc = FLAC__bitreader_get_read_crc16(decoder->private_->input);
  88445. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__FRAME_FOOTER_CRC_LEN))
  88446. return false; /* read_callback_ sets the state for us */
  88447. if(frame_crc == x) {
  88448. if(do_full_decode) {
  88449. switch(decoder->private_->frame.header.channel_assignment) {
  88450. case FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT:
  88451. break;
  88452. case FLAC__CHANNEL_ASSIGNMENT_LEFT_SIDE:
  88453. FLAC__ASSERT(decoder->private_->frame.header.channels == 2);
  88454. for(i = 0; i < decoder->private_->frame.header.blocksize; i++)
  88455. decoder->private_->output[1][i] = decoder->private_->output[0][i] - decoder->private_->output[1][i];
  88456. break;
  88457. case FLAC__CHANNEL_ASSIGNMENT_RIGHT_SIDE:
  88458. FLAC__ASSERT(decoder->private_->frame.header.channels == 2);
  88459. for(i = 0; i < decoder->private_->frame.header.blocksize; i++)
  88460. decoder->private_->output[0][i] += decoder->private_->output[1][i];
  88461. break;
  88462. case FLAC__CHANNEL_ASSIGNMENT_MID_SIDE:
  88463. FLAC__ASSERT(decoder->private_->frame.header.channels == 2);
  88464. for(i = 0; i < decoder->private_->frame.header.blocksize; i++) {
  88465. #if 1
  88466. mid = decoder->private_->output[0][i];
  88467. side = decoder->private_->output[1][i];
  88468. mid <<= 1;
  88469. mid |= (side & 1); /* i.e. if 'side' is odd... */
  88470. decoder->private_->output[0][i] = (mid + side) >> 1;
  88471. decoder->private_->output[1][i] = (mid - side) >> 1;
  88472. #else
  88473. mid = (decoder->private_->output[0][i] << 1) | (decoder->private_->output[1][i] & 1); /* i.e. if 'side' is odd... */
  88474. decoder->private_->output[0][i] = (mid + decoder->private_->output[1][i]) >> 1;
  88475. decoder->private_->output[1][i] = (mid - decoder->private_->output[1][i]) >> 1;
  88476. #endif
  88477. }
  88478. break;
  88479. default:
  88480. FLAC__ASSERT(0);
  88481. break;
  88482. }
  88483. }
  88484. }
  88485. else {
  88486. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_FRAME_CRC_MISMATCH);
  88487. if(do_full_decode) {
  88488. for(channel = 0; channel < decoder->private_->frame.header.channels; channel++) {
  88489. memset(decoder->private_->output[channel], 0, sizeof(FLAC__int32) * decoder->private_->frame.header.blocksize);
  88490. }
  88491. }
  88492. }
  88493. *got_a_frame = true;
  88494. if(decoder->private_->next_fixed_block_size)
  88495. decoder->private_->fixed_block_size = decoder->private_->next_fixed_block_size;
  88496. decoder->protected_->channels = decoder->private_->frame.header.channels;
  88497. decoder->protected_->channel_assignment = decoder->private_->frame.header.channel_assignment;
  88498. decoder->protected_->bits_per_sample = decoder->private_->frame.header.bits_per_sample;
  88499. decoder->protected_->sample_rate = decoder->private_->frame.header.sample_rate;
  88500. decoder->protected_->blocksize = decoder->private_->frame.header.blocksize;
  88501. FLAC__ASSERT(decoder->private_->frame.header.number_type == FLAC__FRAME_NUMBER_TYPE_SAMPLE_NUMBER);
  88502. decoder->private_->samples_decoded = decoder->private_->frame.header.number.sample_number + decoder->private_->frame.header.blocksize;
  88503. if(do_full_decode) {
  88504. if(write_audio_frame_to_client_(decoder, &decoder->private_->frame, (const FLAC__int32 * const *)decoder->private_->output) != FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE)
  88505. return false;
  88506. }
  88507. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  88508. return true;
  88509. }
  88510. FLAC__bool read_frame_header_(FLAC__StreamDecoder *decoder)
  88511. {
  88512. FLAC__uint32 x;
  88513. FLAC__uint64 xx;
  88514. unsigned i, blocksize_hint = 0, sample_rate_hint = 0;
  88515. FLAC__byte crc8, raw_header[16]; /* MAGIC NUMBER based on the maximum frame header size, including CRC */
  88516. unsigned raw_header_len;
  88517. FLAC__bool is_unparseable = false;
  88518. FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input));
  88519. raw_header[0] = decoder->private_->header_warmup[0];
  88520. raw_header[1] = decoder->private_->header_warmup[1];
  88521. raw_header_len = 2;
  88522. if(raw_header[1] & 0x02) /* MAGIC NUMBER */
  88523. is_unparseable = true;
  88524. for(i = 0; i < 2; i++) {
  88525. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 8))
  88526. return false; /* read_callback_ sets the state for us */
  88527. if(x == 0xff) { /* MAGIC NUMBER for the first 8 frame sync bits */
  88528. decoder->private_->lookahead = (FLAC__byte)x;
  88529. decoder->private_->cached = true;
  88530. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_BAD_HEADER);
  88531. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  88532. return true;
  88533. }
  88534. raw_header[raw_header_len++] = (FLAC__byte)x;
  88535. }
  88536. switch(x = raw_header[2] >> 4) {
  88537. case 0:
  88538. is_unparseable = true;
  88539. break;
  88540. case 1:
  88541. decoder->private_->frame.header.blocksize = 192;
  88542. break;
  88543. case 2:
  88544. case 3:
  88545. case 4:
  88546. case 5:
  88547. decoder->private_->frame.header.blocksize = 576 << (x-2);
  88548. break;
  88549. case 6:
  88550. case 7:
  88551. blocksize_hint = x;
  88552. break;
  88553. case 8:
  88554. case 9:
  88555. case 10:
  88556. case 11:
  88557. case 12:
  88558. case 13:
  88559. case 14:
  88560. case 15:
  88561. decoder->private_->frame.header.blocksize = 256 << (x-8);
  88562. break;
  88563. default:
  88564. FLAC__ASSERT(0);
  88565. break;
  88566. }
  88567. switch(x = raw_header[2] & 0x0f) {
  88568. case 0:
  88569. if(decoder->private_->has_stream_info)
  88570. decoder->private_->frame.header.sample_rate = decoder->private_->stream_info.data.stream_info.sample_rate;
  88571. else
  88572. is_unparseable = true;
  88573. break;
  88574. case 1:
  88575. decoder->private_->frame.header.sample_rate = 88200;
  88576. break;
  88577. case 2:
  88578. decoder->private_->frame.header.sample_rate = 176400;
  88579. break;
  88580. case 3:
  88581. decoder->private_->frame.header.sample_rate = 192000;
  88582. break;
  88583. case 4:
  88584. decoder->private_->frame.header.sample_rate = 8000;
  88585. break;
  88586. case 5:
  88587. decoder->private_->frame.header.sample_rate = 16000;
  88588. break;
  88589. case 6:
  88590. decoder->private_->frame.header.sample_rate = 22050;
  88591. break;
  88592. case 7:
  88593. decoder->private_->frame.header.sample_rate = 24000;
  88594. break;
  88595. case 8:
  88596. decoder->private_->frame.header.sample_rate = 32000;
  88597. break;
  88598. case 9:
  88599. decoder->private_->frame.header.sample_rate = 44100;
  88600. break;
  88601. case 10:
  88602. decoder->private_->frame.header.sample_rate = 48000;
  88603. break;
  88604. case 11:
  88605. decoder->private_->frame.header.sample_rate = 96000;
  88606. break;
  88607. case 12:
  88608. case 13:
  88609. case 14:
  88610. sample_rate_hint = x;
  88611. break;
  88612. case 15:
  88613. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_BAD_HEADER);
  88614. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  88615. return true;
  88616. default:
  88617. FLAC__ASSERT(0);
  88618. }
  88619. x = (unsigned)(raw_header[3] >> 4);
  88620. if(x & 8) {
  88621. decoder->private_->frame.header.channels = 2;
  88622. switch(x & 7) {
  88623. case 0:
  88624. decoder->private_->frame.header.channel_assignment = FLAC__CHANNEL_ASSIGNMENT_LEFT_SIDE;
  88625. break;
  88626. case 1:
  88627. decoder->private_->frame.header.channel_assignment = FLAC__CHANNEL_ASSIGNMENT_RIGHT_SIDE;
  88628. break;
  88629. case 2:
  88630. decoder->private_->frame.header.channel_assignment = FLAC__CHANNEL_ASSIGNMENT_MID_SIDE;
  88631. break;
  88632. default:
  88633. is_unparseable = true;
  88634. break;
  88635. }
  88636. }
  88637. else {
  88638. decoder->private_->frame.header.channels = (unsigned)x + 1;
  88639. decoder->private_->frame.header.channel_assignment = FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT;
  88640. }
  88641. switch(x = (unsigned)(raw_header[3] & 0x0e) >> 1) {
  88642. case 0:
  88643. if(decoder->private_->has_stream_info)
  88644. decoder->private_->frame.header.bits_per_sample = decoder->private_->stream_info.data.stream_info.bits_per_sample;
  88645. else
  88646. is_unparseable = true;
  88647. break;
  88648. case 1:
  88649. decoder->private_->frame.header.bits_per_sample = 8;
  88650. break;
  88651. case 2:
  88652. decoder->private_->frame.header.bits_per_sample = 12;
  88653. break;
  88654. case 4:
  88655. decoder->private_->frame.header.bits_per_sample = 16;
  88656. break;
  88657. case 5:
  88658. decoder->private_->frame.header.bits_per_sample = 20;
  88659. break;
  88660. case 6:
  88661. decoder->private_->frame.header.bits_per_sample = 24;
  88662. break;
  88663. case 3:
  88664. case 7:
  88665. is_unparseable = true;
  88666. break;
  88667. default:
  88668. FLAC__ASSERT(0);
  88669. break;
  88670. }
  88671. if(raw_header[3] & 0x01) /* MAGIC NUMBER */
  88672. is_unparseable = true;
  88673. if(
  88674. raw_header[1] & 0x01 ||
  88675. (decoder->private_->has_stream_info && decoder->private_->stream_info.data.stream_info.min_blocksize != decoder->private_->stream_info.data.stream_info.max_blocksize)
  88676. ) { /* variable blocksize */
  88677. if(!FLAC__bitreader_read_utf8_uint64(decoder->private_->input, &xx, raw_header, &raw_header_len))
  88678. return false; /* read_callback_ sets the state for us */
  88679. if(xx == FLAC__U64L(0xffffffffffffffff)) { /* i.e. non-UTF8 code... */
  88680. decoder->private_->lookahead = raw_header[raw_header_len-1]; /* back up as much as we can */
  88681. decoder->private_->cached = true;
  88682. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_BAD_HEADER);
  88683. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  88684. return true;
  88685. }
  88686. decoder->private_->frame.header.number_type = FLAC__FRAME_NUMBER_TYPE_SAMPLE_NUMBER;
  88687. decoder->private_->frame.header.number.sample_number = xx;
  88688. }
  88689. else { /* fixed blocksize */
  88690. if(!FLAC__bitreader_read_utf8_uint32(decoder->private_->input, &x, raw_header, &raw_header_len))
  88691. return false; /* read_callback_ sets the state for us */
  88692. if(x == 0xffffffff) { /* i.e. non-UTF8 code... */
  88693. decoder->private_->lookahead = raw_header[raw_header_len-1]; /* back up as much as we can */
  88694. decoder->private_->cached = true;
  88695. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_BAD_HEADER);
  88696. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  88697. return true;
  88698. }
  88699. decoder->private_->frame.header.number_type = FLAC__FRAME_NUMBER_TYPE_FRAME_NUMBER;
  88700. decoder->private_->frame.header.number.frame_number = x;
  88701. }
  88702. if(blocksize_hint) {
  88703. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 8))
  88704. return false; /* read_callback_ sets the state for us */
  88705. raw_header[raw_header_len++] = (FLAC__byte)x;
  88706. if(blocksize_hint == 7) {
  88707. FLAC__uint32 _x;
  88708. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &_x, 8))
  88709. return false; /* read_callback_ sets the state for us */
  88710. raw_header[raw_header_len++] = (FLAC__byte)_x;
  88711. x = (x << 8) | _x;
  88712. }
  88713. decoder->private_->frame.header.blocksize = x+1;
  88714. }
  88715. if(sample_rate_hint) {
  88716. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 8))
  88717. return false; /* read_callback_ sets the state for us */
  88718. raw_header[raw_header_len++] = (FLAC__byte)x;
  88719. if(sample_rate_hint != 12) {
  88720. FLAC__uint32 _x;
  88721. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &_x, 8))
  88722. return false; /* read_callback_ sets the state for us */
  88723. raw_header[raw_header_len++] = (FLAC__byte)_x;
  88724. x = (x << 8) | _x;
  88725. }
  88726. if(sample_rate_hint == 12)
  88727. decoder->private_->frame.header.sample_rate = x*1000;
  88728. else if(sample_rate_hint == 13)
  88729. decoder->private_->frame.header.sample_rate = x;
  88730. else
  88731. decoder->private_->frame.header.sample_rate = x*10;
  88732. }
  88733. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 8))
  88734. return false; /* read_callback_ sets the state for us */
  88735. crc8 = (FLAC__byte)x;
  88736. if(FLAC__crc8(raw_header, raw_header_len) != crc8) {
  88737. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_BAD_HEADER);
  88738. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  88739. return true;
  88740. }
  88741. decoder->private_->next_fixed_block_size = 0;
  88742. if(decoder->private_->frame.header.number_type == FLAC__FRAME_NUMBER_TYPE_FRAME_NUMBER) {
  88743. x = decoder->private_->frame.header.number.frame_number;
  88744. decoder->private_->frame.header.number_type = FLAC__FRAME_NUMBER_TYPE_SAMPLE_NUMBER;
  88745. if(decoder->private_->fixed_block_size)
  88746. decoder->private_->frame.header.number.sample_number = (FLAC__uint64)decoder->private_->fixed_block_size * (FLAC__uint64)x;
  88747. else if(decoder->private_->has_stream_info) {
  88748. if(decoder->private_->stream_info.data.stream_info.min_blocksize == decoder->private_->stream_info.data.stream_info.max_blocksize) {
  88749. decoder->private_->frame.header.number.sample_number = (FLAC__uint64)decoder->private_->stream_info.data.stream_info.min_blocksize * (FLAC__uint64)x;
  88750. decoder->private_->next_fixed_block_size = decoder->private_->stream_info.data.stream_info.max_blocksize;
  88751. }
  88752. else
  88753. is_unparseable = true;
  88754. }
  88755. else if(x == 0) {
  88756. decoder->private_->frame.header.number.sample_number = 0;
  88757. decoder->private_->next_fixed_block_size = decoder->private_->frame.header.blocksize;
  88758. }
  88759. else {
  88760. decoder->private_->frame.header.number.sample_number = (FLAC__uint64)decoder->private_->frame.header.blocksize * (FLAC__uint64)x;
  88761. }
  88762. }
  88763. if(is_unparseable) {
  88764. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_UNPARSEABLE_STREAM);
  88765. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  88766. return true;
  88767. }
  88768. return true;
  88769. }
  88770. FLAC__bool read_subframe_(FLAC__StreamDecoder *decoder, unsigned channel, unsigned bps, FLAC__bool do_full_decode)
  88771. {
  88772. FLAC__uint32 x;
  88773. FLAC__bool wasted_bits;
  88774. unsigned i;
  88775. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 8)) /* MAGIC NUMBER */
  88776. return false; /* read_callback_ sets the state for us */
  88777. wasted_bits = (x & 1);
  88778. x &= 0xfe;
  88779. if(wasted_bits) {
  88780. unsigned u;
  88781. if(!FLAC__bitreader_read_unary_unsigned(decoder->private_->input, &u))
  88782. return false; /* read_callback_ sets the state for us */
  88783. decoder->private_->frame.subframes[channel].wasted_bits = u+1;
  88784. bps -= decoder->private_->frame.subframes[channel].wasted_bits;
  88785. }
  88786. else
  88787. decoder->private_->frame.subframes[channel].wasted_bits = 0;
  88788. if(x & 0x80) {
  88789. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC);
  88790. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  88791. return true;
  88792. }
  88793. else if(x == 0) {
  88794. if(!read_subframe_constant_(decoder, channel, bps, do_full_decode))
  88795. return false;
  88796. }
  88797. else if(x == 2) {
  88798. if(!read_subframe_verbatim_(decoder, channel, bps, do_full_decode))
  88799. return false;
  88800. }
  88801. else if(x < 16) {
  88802. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_UNPARSEABLE_STREAM);
  88803. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  88804. return true;
  88805. }
  88806. else if(x <= 24) {
  88807. if(!read_subframe_fixed_(decoder, channel, bps, (x>>1)&7, do_full_decode))
  88808. return false;
  88809. if(decoder->protected_->state == FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC) /* means bad sync or got corruption */
  88810. return true;
  88811. }
  88812. else if(x < 64) {
  88813. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_UNPARSEABLE_STREAM);
  88814. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  88815. return true;
  88816. }
  88817. else {
  88818. if(!read_subframe_lpc_(decoder, channel, bps, ((x>>1)&31)+1, do_full_decode))
  88819. return false;
  88820. if(decoder->protected_->state == FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC) /* means bad sync or got corruption */
  88821. return true;
  88822. }
  88823. if(wasted_bits && do_full_decode) {
  88824. x = decoder->private_->frame.subframes[channel].wasted_bits;
  88825. for(i = 0; i < decoder->private_->frame.header.blocksize; i++)
  88826. decoder->private_->output[channel][i] <<= x;
  88827. }
  88828. return true;
  88829. }
  88830. FLAC__bool read_subframe_constant_(FLAC__StreamDecoder *decoder, unsigned channel, unsigned bps, FLAC__bool do_full_decode)
  88831. {
  88832. FLAC__Subframe_Constant *subframe = &decoder->private_->frame.subframes[channel].data.constant;
  88833. FLAC__int32 x;
  88834. unsigned i;
  88835. FLAC__int32 *output = decoder->private_->output[channel];
  88836. decoder->private_->frame.subframes[channel].type = FLAC__SUBFRAME_TYPE_CONSTANT;
  88837. if(!FLAC__bitreader_read_raw_int32(decoder->private_->input, &x, bps))
  88838. return false; /* read_callback_ sets the state for us */
  88839. subframe->value = x;
  88840. if(do_full_decode) {
  88841. for(i = 0; i < decoder->private_->frame.header.blocksize; i++)
  88842. output[i] = x;
  88843. }
  88844. return true;
  88845. }
  88846. FLAC__bool read_subframe_fixed_(FLAC__StreamDecoder *decoder, unsigned channel, unsigned bps, const unsigned order, FLAC__bool do_full_decode)
  88847. {
  88848. FLAC__Subframe_Fixed *subframe = &decoder->private_->frame.subframes[channel].data.fixed;
  88849. FLAC__int32 i32;
  88850. FLAC__uint32 u32;
  88851. unsigned u;
  88852. decoder->private_->frame.subframes[channel].type = FLAC__SUBFRAME_TYPE_FIXED;
  88853. subframe->residual = decoder->private_->residual[channel];
  88854. subframe->order = order;
  88855. for(u = 0; u < order; u++) {
  88856. if(!FLAC__bitreader_read_raw_int32(decoder->private_->input, &i32, bps))
  88857. return false; /* read_callback_ sets the state for us */
  88858. subframe->warmup[u] = i32;
  88859. }
  88860. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &u32, FLAC__ENTROPY_CODING_METHOD_TYPE_LEN))
  88861. return false; /* read_callback_ sets the state for us */
  88862. subframe->entropy_coding_method.type = (FLAC__EntropyCodingMethodType)u32;
  88863. switch(subframe->entropy_coding_method.type) {
  88864. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE:
  88865. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2:
  88866. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &u32, FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ORDER_LEN))
  88867. return false; /* read_callback_ sets the state for us */
  88868. subframe->entropy_coding_method.data.partitioned_rice.order = u32;
  88869. subframe->entropy_coding_method.data.partitioned_rice.contents = &decoder->private_->partitioned_rice_contents[channel];
  88870. break;
  88871. default:
  88872. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_UNPARSEABLE_STREAM);
  88873. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  88874. return true;
  88875. }
  88876. switch(subframe->entropy_coding_method.type) {
  88877. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE:
  88878. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2:
  88879. 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))
  88880. return false;
  88881. break;
  88882. default:
  88883. FLAC__ASSERT(0);
  88884. }
  88885. if(do_full_decode) {
  88886. memcpy(decoder->private_->output[channel], subframe->warmup, sizeof(FLAC__int32) * order);
  88887. FLAC__fixed_restore_signal(decoder->private_->residual[channel], decoder->private_->frame.header.blocksize-order, order, decoder->private_->output[channel]+order);
  88888. }
  88889. return true;
  88890. }
  88891. FLAC__bool read_subframe_lpc_(FLAC__StreamDecoder *decoder, unsigned channel, unsigned bps, const unsigned order, FLAC__bool do_full_decode)
  88892. {
  88893. FLAC__Subframe_LPC *subframe = &decoder->private_->frame.subframes[channel].data.lpc;
  88894. FLAC__int32 i32;
  88895. FLAC__uint32 u32;
  88896. unsigned u;
  88897. decoder->private_->frame.subframes[channel].type = FLAC__SUBFRAME_TYPE_LPC;
  88898. subframe->residual = decoder->private_->residual[channel];
  88899. subframe->order = order;
  88900. for(u = 0; u < order; u++) {
  88901. if(!FLAC__bitreader_read_raw_int32(decoder->private_->input, &i32, bps))
  88902. return false; /* read_callback_ sets the state for us */
  88903. subframe->warmup[u] = i32;
  88904. }
  88905. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &u32, FLAC__SUBFRAME_LPC_QLP_COEFF_PRECISION_LEN))
  88906. return false; /* read_callback_ sets the state for us */
  88907. if(u32 == (1u << FLAC__SUBFRAME_LPC_QLP_COEFF_PRECISION_LEN) - 1) {
  88908. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC);
  88909. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  88910. return true;
  88911. }
  88912. subframe->qlp_coeff_precision = u32+1;
  88913. if(!FLAC__bitreader_read_raw_int32(decoder->private_->input, &i32, FLAC__SUBFRAME_LPC_QLP_SHIFT_LEN))
  88914. return false; /* read_callback_ sets the state for us */
  88915. subframe->quantization_level = i32;
  88916. for(u = 0; u < order; u++) {
  88917. if(!FLAC__bitreader_read_raw_int32(decoder->private_->input, &i32, subframe->qlp_coeff_precision))
  88918. return false; /* read_callback_ sets the state for us */
  88919. subframe->qlp_coeff[u] = i32;
  88920. }
  88921. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &u32, FLAC__ENTROPY_CODING_METHOD_TYPE_LEN))
  88922. return false; /* read_callback_ sets the state for us */
  88923. subframe->entropy_coding_method.type = (FLAC__EntropyCodingMethodType)u32;
  88924. switch(subframe->entropy_coding_method.type) {
  88925. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE:
  88926. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2:
  88927. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &u32, FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ORDER_LEN))
  88928. return false; /* read_callback_ sets the state for us */
  88929. subframe->entropy_coding_method.data.partitioned_rice.order = u32;
  88930. subframe->entropy_coding_method.data.partitioned_rice.contents = &decoder->private_->partitioned_rice_contents[channel];
  88931. break;
  88932. default:
  88933. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_UNPARSEABLE_STREAM);
  88934. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  88935. return true;
  88936. }
  88937. switch(subframe->entropy_coding_method.type) {
  88938. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE:
  88939. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2:
  88940. 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))
  88941. return false;
  88942. break;
  88943. default:
  88944. FLAC__ASSERT(0);
  88945. }
  88946. if(do_full_decode) {
  88947. memcpy(decoder->private_->output[channel], subframe->warmup, sizeof(FLAC__int32) * order);
  88948. if(bps + subframe->qlp_coeff_precision + FLAC__bitmath_ilog2(order) <= 32)
  88949. if(bps <= 16 && subframe->qlp_coeff_precision <= 16) {
  88950. if(order <= 8)
  88951. 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);
  88952. else
  88953. 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);
  88954. }
  88955. else
  88956. 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);
  88957. else
  88958. 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);
  88959. }
  88960. return true;
  88961. }
  88962. FLAC__bool read_subframe_verbatim_(FLAC__StreamDecoder *decoder, unsigned channel, unsigned bps, FLAC__bool do_full_decode)
  88963. {
  88964. FLAC__Subframe_Verbatim *subframe = &decoder->private_->frame.subframes[channel].data.verbatim;
  88965. FLAC__int32 x, *residual = decoder->private_->residual[channel];
  88966. unsigned i;
  88967. decoder->private_->frame.subframes[channel].type = FLAC__SUBFRAME_TYPE_VERBATIM;
  88968. subframe->data = residual;
  88969. for(i = 0; i < decoder->private_->frame.header.blocksize; i++) {
  88970. if(!FLAC__bitreader_read_raw_int32(decoder->private_->input, &x, bps))
  88971. return false; /* read_callback_ sets the state for us */
  88972. residual[i] = x;
  88973. }
  88974. if(do_full_decode)
  88975. memcpy(decoder->private_->output[channel], subframe->data, sizeof(FLAC__int32) * decoder->private_->frame.header.blocksize);
  88976. return true;
  88977. }
  88978. 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)
  88979. {
  88980. FLAC__uint32 rice_parameter;
  88981. int i;
  88982. unsigned partition, sample, u;
  88983. const unsigned partitions = 1u << partition_order;
  88984. const unsigned partition_samples = partition_order > 0? decoder->private_->frame.header.blocksize >> partition_order : decoder->private_->frame.header.blocksize - predictor_order;
  88985. const unsigned plen = is_extended? FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_PARAMETER_LEN : FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_PARAMETER_LEN;
  88986. const unsigned pesc = is_extended? FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_ESCAPE_PARAMETER : FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ESCAPE_PARAMETER;
  88987. if(partition_order == 0) {
  88988. if(decoder->private_->frame.header.blocksize < predictor_order) {
  88989. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC);
  88990. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  88991. return true;
  88992. }
  88993. }
  88994. else {
  88995. if(partition_samples < predictor_order) {
  88996. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC);
  88997. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  88998. return true;
  88999. }
  89000. }
  89001. if(!FLAC__format_entropy_coding_method_partitioned_rice_contents_ensure_size(partitioned_rice_contents, max(6, partition_order))) {
  89002. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  89003. return false;
  89004. }
  89005. sample = 0;
  89006. for(partition = 0; partition < partitions; partition++) {
  89007. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &rice_parameter, plen))
  89008. return false; /* read_callback_ sets the state for us */
  89009. partitioned_rice_contents->parameters[partition] = rice_parameter;
  89010. if(rice_parameter < pesc) {
  89011. partitioned_rice_contents->raw_bits[partition] = 0;
  89012. u = (partition_order == 0 || partition > 0)? partition_samples : partition_samples - predictor_order;
  89013. if(!decoder->private_->local_bitreader_read_rice_signed_block(decoder->private_->input, (int*) residual + sample, u, rice_parameter))
  89014. return false; /* read_callback_ sets the state for us */
  89015. sample += u;
  89016. }
  89017. else {
  89018. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &rice_parameter, FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_RAW_LEN))
  89019. return false; /* read_callback_ sets the state for us */
  89020. partitioned_rice_contents->raw_bits[partition] = rice_parameter;
  89021. for(u = (partition_order == 0 || partition > 0)? 0 : predictor_order; u < partition_samples; u++, sample++) {
  89022. if(!FLAC__bitreader_read_raw_int32(decoder->private_->input, (FLAC__int32*) &i, rice_parameter))
  89023. return false; /* read_callback_ sets the state for us */
  89024. residual[sample] = i;
  89025. }
  89026. }
  89027. }
  89028. return true;
  89029. }
  89030. FLAC__bool read_zero_padding_(FLAC__StreamDecoder *decoder)
  89031. {
  89032. if(!FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input)) {
  89033. FLAC__uint32 zero = 0;
  89034. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &zero, FLAC__bitreader_bits_left_for_byte_alignment(decoder->private_->input)))
  89035. return false; /* read_callback_ sets the state for us */
  89036. if(zero != 0) {
  89037. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC);
  89038. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  89039. }
  89040. }
  89041. return true;
  89042. }
  89043. FLAC__bool read_callback_(FLAC__byte buffer[], size_t *bytes, void *client_data)
  89044. {
  89045. FLAC__StreamDecoder *decoder = (FLAC__StreamDecoder *)client_data;
  89046. if(
  89047. #if FLAC__HAS_OGG
  89048. !decoder->private_->is_ogg &&
  89049. #endif
  89050. decoder->private_->eof_callback && decoder->private_->eof_callback(decoder, decoder->private_->client_data)
  89051. ) {
  89052. *bytes = 0;
  89053. decoder->protected_->state = FLAC__STREAM_DECODER_END_OF_STREAM;
  89054. return false;
  89055. }
  89056. else if(*bytes > 0) {
  89057. if(decoder->private_->is_seeking && decoder->private_->unparseable_frame_count > 20) {
  89058. decoder->protected_->state = FLAC__STREAM_DECODER_ABORTED;
  89059. return false;
  89060. }
  89061. else {
  89062. const FLAC__StreamDecoderReadStatus status =
  89063. #if FLAC__HAS_OGG
  89064. decoder->private_->is_ogg?
  89065. read_callback_ogg_aspect_(decoder, buffer, bytes) :
  89066. #endif
  89067. decoder->private_->read_callback(decoder, buffer, bytes, decoder->private_->client_data)
  89068. ;
  89069. if(status == FLAC__STREAM_DECODER_READ_STATUS_ABORT) {
  89070. decoder->protected_->state = FLAC__STREAM_DECODER_ABORTED;
  89071. return false;
  89072. }
  89073. else if(*bytes == 0) {
  89074. if(
  89075. status == FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM ||
  89076. (
  89077. #if FLAC__HAS_OGG
  89078. !decoder->private_->is_ogg &&
  89079. #endif
  89080. decoder->private_->eof_callback && decoder->private_->eof_callback(decoder, decoder->private_->client_data)
  89081. )
  89082. ) {
  89083. decoder->protected_->state = FLAC__STREAM_DECODER_END_OF_STREAM;
  89084. return false;
  89085. }
  89086. else
  89087. return true;
  89088. }
  89089. else
  89090. return true;
  89091. }
  89092. }
  89093. else {
  89094. decoder->protected_->state = FLAC__STREAM_DECODER_ABORTED;
  89095. return false;
  89096. }
  89097. }
  89098. #if FLAC__HAS_OGG
  89099. FLAC__StreamDecoderReadStatus read_callback_ogg_aspect_(const FLAC__StreamDecoder *decoder, FLAC__byte buffer[], size_t *bytes)
  89100. {
  89101. switch(FLAC__ogg_decoder_aspect_read_callback_wrapper(&decoder->protected_->ogg_decoder_aspect, buffer, bytes, read_callback_proxy_, decoder, decoder->private_->client_data)) {
  89102. case FLAC__OGG_DECODER_ASPECT_READ_STATUS_OK:
  89103. return FLAC__STREAM_DECODER_READ_STATUS_CONTINUE;
  89104. case FLAC__OGG_DECODER_ASPECT_READ_STATUS_LOST_SYNC:
  89105. return FLAC__STREAM_DECODER_READ_STATUS_CONTINUE;
  89106. case FLAC__OGG_DECODER_ASPECT_READ_STATUS_END_OF_STREAM:
  89107. return FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM;
  89108. case FLAC__OGG_DECODER_ASPECT_READ_STATUS_NOT_FLAC:
  89109. case FLAC__OGG_DECODER_ASPECT_READ_STATUS_UNSUPPORTED_MAPPING_VERSION:
  89110. case FLAC__OGG_DECODER_ASPECT_READ_STATUS_ABORT:
  89111. case FLAC__OGG_DECODER_ASPECT_READ_STATUS_ERROR:
  89112. case FLAC__OGG_DECODER_ASPECT_READ_STATUS_MEMORY_ALLOCATION_ERROR:
  89113. return FLAC__STREAM_DECODER_READ_STATUS_ABORT;
  89114. default:
  89115. FLAC__ASSERT(0);
  89116. return FLAC__STREAM_DECODER_READ_STATUS_ABORT;
  89117. }
  89118. }
  89119. FLAC__OggDecoderAspectReadStatus read_callback_proxy_(const void *void_decoder, FLAC__byte buffer[], size_t *bytes, void *client_data)
  89120. {
  89121. FLAC__StreamDecoder *decoder = (FLAC__StreamDecoder*)void_decoder;
  89122. switch(decoder->private_->read_callback(decoder, buffer, bytes, client_data)) {
  89123. case FLAC__STREAM_DECODER_READ_STATUS_CONTINUE:
  89124. return FLAC__OGG_DECODER_ASPECT_READ_STATUS_OK;
  89125. case FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM:
  89126. return FLAC__OGG_DECODER_ASPECT_READ_STATUS_END_OF_STREAM;
  89127. case FLAC__STREAM_DECODER_READ_STATUS_ABORT:
  89128. return FLAC__OGG_DECODER_ASPECT_READ_STATUS_ABORT;
  89129. default:
  89130. FLAC__ASSERT(0);
  89131. return FLAC__OGG_DECODER_ASPECT_READ_STATUS_ABORT;
  89132. }
  89133. }
  89134. #endif
  89135. FLAC__StreamDecoderWriteStatus write_audio_frame_to_client_(FLAC__StreamDecoder *decoder, const FLAC__Frame *frame, const FLAC__int32 * const buffer[])
  89136. {
  89137. if(decoder->private_->is_seeking) {
  89138. FLAC__uint64 this_frame_sample = frame->header.number.sample_number;
  89139. FLAC__uint64 next_frame_sample = this_frame_sample + (FLAC__uint64)frame->header.blocksize;
  89140. FLAC__uint64 target_sample = decoder->private_->target_sample;
  89141. FLAC__ASSERT(frame->header.number_type == FLAC__FRAME_NUMBER_TYPE_SAMPLE_NUMBER);
  89142. #if FLAC__HAS_OGG
  89143. decoder->private_->got_a_frame = true;
  89144. #endif
  89145. decoder->private_->last_frame = *frame; /* save the frame */
  89146. if(this_frame_sample <= target_sample && target_sample < next_frame_sample) { /* we hit our target frame */
  89147. unsigned delta = (unsigned)(target_sample - this_frame_sample);
  89148. decoder->private_->is_seeking = false;
  89149. if(delta > 0) {
  89150. unsigned channel;
  89151. const FLAC__int32 *newbuffer[FLAC__MAX_CHANNELS];
  89152. for(channel = 0; channel < frame->header.channels; channel++)
  89153. newbuffer[channel] = buffer[channel] + delta;
  89154. decoder->private_->last_frame.header.blocksize -= delta;
  89155. decoder->private_->last_frame.header.number.sample_number += (FLAC__uint64)delta;
  89156. return decoder->private_->write_callback(decoder, &decoder->private_->last_frame, newbuffer, decoder->private_->client_data);
  89157. }
  89158. else {
  89159. return decoder->private_->write_callback(decoder, frame, buffer, decoder->private_->client_data);
  89160. }
  89161. }
  89162. return FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE;
  89163. }
  89164. if(!decoder->private_->has_stream_info)
  89165. decoder->private_->do_md5_checking = false;
  89166. if(decoder->private_->do_md5_checking) {
  89167. if(!FLAC__MD5Accumulate(&decoder->private_->md5context, buffer, frame->header.channels, frame->header.blocksize, (frame->header.bits_per_sample+7) / 8))
  89168. return FLAC__STREAM_DECODER_WRITE_STATUS_ABORT;
  89169. }
  89170. return decoder->private_->write_callback(decoder, frame, buffer, decoder->private_->client_data);
  89171. }
  89172. void send_error_to_client_(const FLAC__StreamDecoder *decoder, FLAC__StreamDecoderErrorStatus status)
  89173. {
  89174. if(!decoder->private_->is_seeking)
  89175. decoder->private_->error_callback(decoder, status, decoder->private_->client_data);
  89176. else if(status == FLAC__STREAM_DECODER_ERROR_STATUS_UNPARSEABLE_STREAM)
  89177. decoder->private_->unparseable_frame_count++;
  89178. }
  89179. FLAC__bool seek_to_absolute_sample_(FLAC__StreamDecoder *decoder, FLAC__uint64 stream_length, FLAC__uint64 target_sample)
  89180. {
  89181. FLAC__uint64 first_frame_offset = decoder->private_->first_frame_offset, lower_bound, upper_bound, lower_bound_sample, upper_bound_sample, this_frame_sample;
  89182. FLAC__int64 pos = -1;
  89183. int i;
  89184. unsigned approx_bytes_per_frame;
  89185. FLAC__bool first_seek = true;
  89186. const FLAC__uint64 total_samples = FLAC__stream_decoder_get_total_samples(decoder);
  89187. const unsigned min_blocksize = decoder->private_->stream_info.data.stream_info.min_blocksize;
  89188. const unsigned max_blocksize = decoder->private_->stream_info.data.stream_info.max_blocksize;
  89189. const unsigned max_framesize = decoder->private_->stream_info.data.stream_info.max_framesize;
  89190. const unsigned min_framesize = decoder->private_->stream_info.data.stream_info.min_framesize;
  89191. unsigned channels = FLAC__stream_decoder_get_channels(decoder);
  89192. unsigned bps = FLAC__stream_decoder_get_bits_per_sample(decoder);
  89193. const FLAC__StreamMetadata_SeekTable *seek_table = decoder->private_->has_seek_table? &decoder->private_->seek_table.data.seek_table : 0;
  89194. if(channels == 0)
  89195. channels = decoder->private_->stream_info.data.stream_info.channels;
  89196. if(bps == 0)
  89197. bps = decoder->private_->stream_info.data.stream_info.bits_per_sample;
  89198. if(max_framesize > 0)
  89199. approx_bytes_per_frame = (max_framesize + min_framesize) / 2 + 1;
  89200. else if(min_blocksize == max_blocksize && min_blocksize > 0) {
  89201. approx_bytes_per_frame = min_blocksize * channels * bps/8 + 64;
  89202. }
  89203. else
  89204. approx_bytes_per_frame = 4096 * channels * bps/8 + 64;
  89205. lower_bound = first_frame_offset;
  89206. lower_bound_sample = 0;
  89207. upper_bound = stream_length;
  89208. upper_bound_sample = total_samples > 0 ? total_samples : target_sample /*estimate it*/;
  89209. if(seek_table) {
  89210. FLAC__uint64 new_lower_bound = lower_bound;
  89211. FLAC__uint64 new_upper_bound = upper_bound;
  89212. FLAC__uint64 new_lower_bound_sample = lower_bound_sample;
  89213. FLAC__uint64 new_upper_bound_sample = upper_bound_sample;
  89214. for(i = (int)seek_table->num_points - 1; i >= 0; i--) {
  89215. if(
  89216. seek_table->points[i].sample_number != FLAC__STREAM_METADATA_SEEKPOINT_PLACEHOLDER &&
  89217. seek_table->points[i].frame_samples > 0 && /* defense against bad seekpoints */
  89218. (total_samples <= 0 || seek_table->points[i].sample_number < total_samples) && /* defense against bad seekpoints */
  89219. seek_table->points[i].sample_number <= target_sample
  89220. )
  89221. break;
  89222. }
  89223. if(i >= 0) { /* i.e. we found a suitable seek point... */
  89224. new_lower_bound = first_frame_offset + seek_table->points[i].stream_offset;
  89225. new_lower_bound_sample = seek_table->points[i].sample_number;
  89226. }
  89227. for(i = 0; i < (int)seek_table->num_points; i++) {
  89228. if(
  89229. seek_table->points[i].sample_number != FLAC__STREAM_METADATA_SEEKPOINT_PLACEHOLDER &&
  89230. seek_table->points[i].frame_samples > 0 && /* defense against bad seekpoints */
  89231. (total_samples <= 0 || seek_table->points[i].sample_number < total_samples) && /* defense against bad seekpoints */
  89232. seek_table->points[i].sample_number > target_sample
  89233. )
  89234. break;
  89235. }
  89236. if(i < (int)seek_table->num_points) { /* i.e. we found a suitable seek point... */
  89237. new_upper_bound = first_frame_offset + seek_table->points[i].stream_offset;
  89238. new_upper_bound_sample = seek_table->points[i].sample_number;
  89239. }
  89240. if(new_upper_bound >= new_lower_bound) {
  89241. lower_bound = new_lower_bound;
  89242. upper_bound = new_upper_bound;
  89243. lower_bound_sample = new_lower_bound_sample;
  89244. upper_bound_sample = new_upper_bound_sample;
  89245. }
  89246. }
  89247. FLAC__ASSERT(upper_bound_sample >= lower_bound_sample);
  89248. if(upper_bound_sample == lower_bound_sample)
  89249. upper_bound_sample++;
  89250. decoder->private_->target_sample = target_sample;
  89251. while(1) {
  89252. if (lower_bound_sample >= upper_bound_sample || lower_bound > upper_bound) {
  89253. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  89254. return false;
  89255. }
  89256. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  89257. #if defined _MSC_VER || defined __MINGW32__
  89258. 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;
  89259. #else
  89260. 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;
  89261. #endif
  89262. #else
  89263. if(upper_bound - lower_bound < 0xffffffff)
  89264. 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;
  89265. else /* @@@ WATCHOUT, ~2TB limit */
  89266. 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;
  89267. #endif
  89268. if(pos >= (FLAC__int64)upper_bound)
  89269. pos = (FLAC__int64)upper_bound - 1;
  89270. if(pos < (FLAC__int64)lower_bound)
  89271. pos = (FLAC__int64)lower_bound;
  89272. if(decoder->private_->seek_callback(decoder, (FLAC__uint64)pos, decoder->private_->client_data) != FLAC__STREAM_DECODER_SEEK_STATUS_OK) {
  89273. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  89274. return false;
  89275. }
  89276. if(!FLAC__stream_decoder_flush(decoder)) {
  89277. return false;
  89278. }
  89279. decoder->private_->unparseable_frame_count = 0;
  89280. if(!FLAC__stream_decoder_process_single(decoder)) {
  89281. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  89282. return false;
  89283. }
  89284. #if 0
  89285. if(decoder->protected_->state != FLAC__SEEKABLE_STREAM_DECODER_SEEKING && decoder->protected_->state != FLAC__STREAM_DECODER_END_OF_STREAM)
  89286. break;
  89287. #endif
  89288. if(!decoder->private_->is_seeking)
  89289. break;
  89290. FLAC__ASSERT(decoder->private_->last_frame.header.number_type == FLAC__FRAME_NUMBER_TYPE_SAMPLE_NUMBER);
  89291. this_frame_sample = decoder->private_->last_frame.header.number.sample_number;
  89292. if (0 == decoder->private_->samples_decoded || (this_frame_sample + decoder->private_->last_frame.header.blocksize >= upper_bound_sample && !first_seek)) {
  89293. if (pos == (FLAC__int64)lower_bound) {
  89294. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  89295. return false;
  89296. }
  89297. approx_bytes_per_frame = approx_bytes_per_frame? approx_bytes_per_frame * 2 : 16;
  89298. continue;
  89299. }
  89300. first_seek = false;
  89301. if (this_frame_sample < lower_bound_sample) {
  89302. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  89303. return false;
  89304. }
  89305. if(target_sample < this_frame_sample) {
  89306. upper_bound_sample = this_frame_sample + decoder->private_->last_frame.header.blocksize;
  89307. if(!FLAC__stream_decoder_get_decode_position(decoder, &upper_bound)) {
  89308. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  89309. return false;
  89310. }
  89311. approx_bytes_per_frame = (unsigned)(2 * (upper_bound - pos) / 3 + 16);
  89312. }
  89313. else { /* target_sample >= this_frame_sample + this frame's blocksize */
  89314. lower_bound_sample = this_frame_sample + decoder->private_->last_frame.header.blocksize;
  89315. if(!FLAC__stream_decoder_get_decode_position(decoder, &lower_bound)) {
  89316. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  89317. return false;
  89318. }
  89319. approx_bytes_per_frame = (unsigned)(2 * (lower_bound - pos) / 3 + 16);
  89320. }
  89321. }
  89322. return true;
  89323. }
  89324. #if FLAC__HAS_OGG
  89325. FLAC__bool seek_to_absolute_sample_ogg_(FLAC__StreamDecoder *decoder, FLAC__uint64 stream_length, FLAC__uint64 target_sample)
  89326. {
  89327. FLAC__uint64 left_pos = 0, right_pos = stream_length;
  89328. FLAC__uint64 left_sample = 0, right_sample = FLAC__stream_decoder_get_total_samples(decoder);
  89329. FLAC__uint64 this_frame_sample = (FLAC__uint64)0 - 1;
  89330. FLAC__uint64 pos = 0; /* only initialized to avoid compiler warning */
  89331. FLAC__bool did_a_seek;
  89332. unsigned iteration = 0;
  89333. unsigned BINARY_SEARCH_AFTER_ITERATION = 2;
  89334. static const FLAC__uint64 LINEAR_SEARCH_WITHIN_SAMPLES = FLAC__MAX_BLOCK_SIZE * 2;
  89335. if(right_sample == 0) {
  89336. right_sample = (FLAC__uint64)(-1);
  89337. BINARY_SEARCH_AFTER_ITERATION = 0;
  89338. }
  89339. decoder->private_->target_sample = target_sample;
  89340. for( ; ; iteration++) {
  89341. if (iteration == 0 || this_frame_sample > target_sample || target_sample - this_frame_sample > LINEAR_SEARCH_WITHIN_SAMPLES) {
  89342. if (iteration >= BINARY_SEARCH_AFTER_ITERATION) {
  89343. pos = (right_pos + left_pos) / 2;
  89344. }
  89345. else {
  89346. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  89347. #if defined _MSC_VER || defined __MINGW32__
  89348. 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));
  89349. #else
  89350. pos = (FLAC__uint64)((FLAC__double)(target_sample - left_sample) / (FLAC__double)(right_sample - left_sample) * (FLAC__double)(right_pos - left_pos));
  89351. #endif
  89352. #else
  89353. if ((target_sample-left_sample <= 0xffffffff) && (right_pos-left_pos <= 0xffffffff))
  89354. pos = (FLAC__int64)(((target_sample-left_sample) * (right_pos-left_pos)) / (right_sample-left_sample));
  89355. else /* @@@ WATCHOUT, ~2TB limit */
  89356. pos = (FLAC__int64)((((target_sample-left_sample)>>8) * ((right_pos-left_pos)>>8)) / ((right_sample-left_sample)>>16));
  89357. #endif
  89358. }
  89359. if(decoder->private_->seek_callback((FLAC__StreamDecoder*)decoder, (FLAC__uint64)pos, decoder->private_->client_data) != FLAC__STREAM_DECODER_SEEK_STATUS_OK) {
  89360. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  89361. return false;
  89362. }
  89363. if(!FLAC__stream_decoder_flush(decoder)) {
  89364. return false;
  89365. }
  89366. did_a_seek = true;
  89367. }
  89368. else
  89369. did_a_seek = false;
  89370. decoder->private_->got_a_frame = false;
  89371. if(!FLAC__stream_decoder_process_single(decoder)) {
  89372. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  89373. return false;
  89374. }
  89375. if(!decoder->private_->got_a_frame) {
  89376. if(did_a_seek) {
  89377. right_pos = pos;
  89378. BINARY_SEARCH_AFTER_ITERATION = 0;
  89379. }
  89380. else {
  89381. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  89382. return false;
  89383. }
  89384. }
  89385. else if(!decoder->private_->is_seeking) {
  89386. break;
  89387. }
  89388. else {
  89389. this_frame_sample = decoder->private_->last_frame.header.number.sample_number;
  89390. FLAC__ASSERT(decoder->private_->last_frame.header.number_type == FLAC__FRAME_NUMBER_TYPE_SAMPLE_NUMBER);
  89391. if (did_a_seek) {
  89392. if (this_frame_sample <= target_sample) {
  89393. FLAC__ASSERT(this_frame_sample != target_sample);
  89394. left_sample = this_frame_sample;
  89395. if (left_pos == pos) {
  89396. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  89397. return false;
  89398. }
  89399. left_pos = pos;
  89400. }
  89401. else if(this_frame_sample > target_sample) {
  89402. right_sample = this_frame_sample;
  89403. if (right_pos == pos) {
  89404. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  89405. return false;
  89406. }
  89407. right_pos = pos;
  89408. }
  89409. }
  89410. }
  89411. }
  89412. return true;
  89413. }
  89414. #endif
  89415. FLAC__StreamDecoderReadStatus file_read_callback_dec(const FLAC__StreamDecoder *decoder, FLAC__byte buffer[], size_t *bytes, void *client_data)
  89416. {
  89417. (void)client_data;
  89418. if(*bytes > 0) {
  89419. *bytes = fread(buffer, sizeof(FLAC__byte), *bytes, decoder->private_->file);
  89420. if(ferror(decoder->private_->file))
  89421. return FLAC__STREAM_DECODER_READ_STATUS_ABORT;
  89422. else if(*bytes == 0)
  89423. return FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM;
  89424. else
  89425. return FLAC__STREAM_DECODER_READ_STATUS_CONTINUE;
  89426. }
  89427. else
  89428. return FLAC__STREAM_DECODER_READ_STATUS_ABORT; /* abort to avoid a deadlock */
  89429. }
  89430. FLAC__StreamDecoderSeekStatus file_seek_callback_dec(const FLAC__StreamDecoder *decoder, FLAC__uint64 absolute_byte_offset, void *client_data)
  89431. {
  89432. (void)client_data;
  89433. if(decoder->private_->file == stdin)
  89434. return FLAC__STREAM_DECODER_SEEK_STATUS_UNSUPPORTED;
  89435. else if(fseeko(decoder->private_->file, (off_t)absolute_byte_offset, SEEK_SET) < 0)
  89436. return FLAC__STREAM_DECODER_SEEK_STATUS_ERROR;
  89437. else
  89438. return FLAC__STREAM_DECODER_SEEK_STATUS_OK;
  89439. }
  89440. FLAC__StreamDecoderTellStatus file_tell_callback_dec(const FLAC__StreamDecoder *decoder, FLAC__uint64 *absolute_byte_offset, void *client_data)
  89441. {
  89442. off_t pos;
  89443. (void)client_data;
  89444. if(decoder->private_->file == stdin)
  89445. return FLAC__STREAM_DECODER_TELL_STATUS_UNSUPPORTED;
  89446. else if((pos = ftello(decoder->private_->file)) < 0)
  89447. return FLAC__STREAM_DECODER_TELL_STATUS_ERROR;
  89448. else {
  89449. *absolute_byte_offset = (FLAC__uint64)pos;
  89450. return FLAC__STREAM_DECODER_TELL_STATUS_OK;
  89451. }
  89452. }
  89453. FLAC__StreamDecoderLengthStatus file_length_callback_(const FLAC__StreamDecoder *decoder, FLAC__uint64 *stream_length, void *client_data)
  89454. {
  89455. struct stat filestats;
  89456. (void)client_data;
  89457. if(decoder->private_->file == stdin)
  89458. return FLAC__STREAM_DECODER_LENGTH_STATUS_UNSUPPORTED;
  89459. else if(fstat(fileno(decoder->private_->file), &filestats) != 0)
  89460. return FLAC__STREAM_DECODER_LENGTH_STATUS_ERROR;
  89461. else {
  89462. *stream_length = (FLAC__uint64)filestats.st_size;
  89463. return FLAC__STREAM_DECODER_LENGTH_STATUS_OK;
  89464. }
  89465. }
  89466. FLAC__bool file_eof_callback_(const FLAC__StreamDecoder *decoder, void *client_data)
  89467. {
  89468. (void)client_data;
  89469. return feof(decoder->private_->file)? true : false;
  89470. }
  89471. #endif
  89472. /*** End of inlined file: stream_decoder.c ***/
  89473. /*** Start of inlined file: stream_encoder.c ***/
  89474. /*** Start of inlined file: juce_FlacHeader.h ***/
  89475. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  89476. // tasks..
  89477. #define VERSION "1.2.1"
  89478. #define FLAC__NO_DLL 1
  89479. #if JUCE_MSVC
  89480. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  89481. #endif
  89482. #if JUCE_MAC
  89483. #define FLAC__SYS_DARWIN 1
  89484. #endif
  89485. /*** End of inlined file: juce_FlacHeader.h ***/
  89486. #if JUCE_USE_FLAC
  89487. #if HAVE_CONFIG_H
  89488. # include <config.h>
  89489. #endif
  89490. #if defined _MSC_VER || defined __MINGW32__
  89491. #include <io.h> /* for _setmode() */
  89492. #include <fcntl.h> /* for _O_BINARY */
  89493. #endif
  89494. #if defined __CYGWIN__ || defined __EMX__
  89495. #include <io.h> /* for setmode(), O_BINARY */
  89496. #include <fcntl.h> /* for _O_BINARY */
  89497. #endif
  89498. #include <limits.h>
  89499. #include <stdio.h>
  89500. #include <stdlib.h> /* for malloc() */
  89501. #include <string.h> /* for memcpy() */
  89502. #include <sys/types.h> /* for off_t */
  89503. #if defined _MSC_VER || defined __BORLANDC__ || defined __MINGW32__
  89504. #if _MSC_VER <= 1600 || defined __BORLANDC__ /* @@@ [2G limit] */
  89505. #define fseeko fseek
  89506. #define ftello ftell
  89507. #endif
  89508. #endif
  89509. /*** Start of inlined file: stream_encoder.h ***/
  89510. #ifndef FLAC__PROTECTED__STREAM_ENCODER_H
  89511. #define FLAC__PROTECTED__STREAM_ENCODER_H
  89512. #if FLAC__HAS_OGG
  89513. #include "private/ogg_encoder_aspect.h"
  89514. #endif
  89515. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  89516. #define FLAC__MAX_APODIZATION_FUNCTIONS 32
  89517. typedef enum {
  89518. FLAC__APODIZATION_BARTLETT,
  89519. FLAC__APODIZATION_BARTLETT_HANN,
  89520. FLAC__APODIZATION_BLACKMAN,
  89521. FLAC__APODIZATION_BLACKMAN_HARRIS_4TERM_92DB_SIDELOBE,
  89522. FLAC__APODIZATION_CONNES,
  89523. FLAC__APODIZATION_FLATTOP,
  89524. FLAC__APODIZATION_GAUSS,
  89525. FLAC__APODIZATION_HAMMING,
  89526. FLAC__APODIZATION_HANN,
  89527. FLAC__APODIZATION_KAISER_BESSEL,
  89528. FLAC__APODIZATION_NUTTALL,
  89529. FLAC__APODIZATION_RECTANGLE,
  89530. FLAC__APODIZATION_TRIANGLE,
  89531. FLAC__APODIZATION_TUKEY,
  89532. FLAC__APODIZATION_WELCH
  89533. } FLAC__ApodizationFunction;
  89534. typedef struct {
  89535. FLAC__ApodizationFunction type;
  89536. union {
  89537. struct {
  89538. FLAC__real stddev;
  89539. } gauss;
  89540. struct {
  89541. FLAC__real p;
  89542. } tukey;
  89543. } parameters;
  89544. } FLAC__ApodizationSpecification;
  89545. #endif // #ifndef FLAC__INTEGER_ONLY_LIBRARY
  89546. typedef struct FLAC__StreamEncoderProtected {
  89547. FLAC__StreamEncoderState state;
  89548. FLAC__bool verify;
  89549. FLAC__bool streamable_subset;
  89550. FLAC__bool do_md5;
  89551. FLAC__bool do_mid_side_stereo;
  89552. FLAC__bool loose_mid_side_stereo;
  89553. unsigned channels;
  89554. unsigned bits_per_sample;
  89555. unsigned sample_rate;
  89556. unsigned blocksize;
  89557. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  89558. unsigned num_apodizations;
  89559. FLAC__ApodizationSpecification apodizations[FLAC__MAX_APODIZATION_FUNCTIONS];
  89560. #endif
  89561. unsigned max_lpc_order;
  89562. unsigned qlp_coeff_precision;
  89563. FLAC__bool do_qlp_coeff_prec_search;
  89564. FLAC__bool do_exhaustive_model_search;
  89565. FLAC__bool do_escape_coding;
  89566. unsigned min_residual_partition_order;
  89567. unsigned max_residual_partition_order;
  89568. unsigned rice_parameter_search_dist;
  89569. FLAC__uint64 total_samples_estimate;
  89570. FLAC__StreamMetadata **metadata;
  89571. unsigned num_metadata_blocks;
  89572. FLAC__uint64 streaminfo_offset, seektable_offset, audio_offset;
  89573. #if FLAC__HAS_OGG
  89574. FLAC__OggEncoderAspect ogg_encoder_aspect;
  89575. #endif
  89576. } FLAC__StreamEncoderProtected;
  89577. #endif
  89578. /*** End of inlined file: stream_encoder.h ***/
  89579. #if FLAC__HAS_OGG
  89580. #include "include/private/ogg_helper.h"
  89581. #include "include/private/ogg_mapping.h"
  89582. #endif
  89583. /*** Start of inlined file: stream_encoder_framing.h ***/
  89584. #ifndef FLAC__PRIVATE__STREAM_ENCODER_FRAMING_H
  89585. #define FLAC__PRIVATE__STREAM_ENCODER_FRAMING_H
  89586. FLAC__bool FLAC__add_metadata_block(const FLAC__StreamMetadata *metadata, FLAC__BitWriter *bw);
  89587. FLAC__bool FLAC__frame_add_header(const FLAC__FrameHeader *header, FLAC__BitWriter *bw);
  89588. FLAC__bool FLAC__subframe_add_constant(const FLAC__Subframe_Constant *subframe, unsigned subframe_bps, unsigned wasted_bits, FLAC__BitWriter *bw);
  89589. FLAC__bool FLAC__subframe_add_fixed(const FLAC__Subframe_Fixed *subframe, unsigned residual_samples, unsigned subframe_bps, unsigned wasted_bits, FLAC__BitWriter *bw);
  89590. FLAC__bool FLAC__subframe_add_lpc(const FLAC__Subframe_LPC *subframe, unsigned residual_samples, unsigned subframe_bps, unsigned wasted_bits, FLAC__BitWriter *bw);
  89591. FLAC__bool FLAC__subframe_add_verbatim(const FLAC__Subframe_Verbatim *subframe, unsigned samples, unsigned subframe_bps, unsigned wasted_bits, FLAC__BitWriter *bw);
  89592. #endif
  89593. /*** End of inlined file: stream_encoder_framing.h ***/
  89594. /*** Start of inlined file: window.h ***/
  89595. #ifndef FLAC__PRIVATE__WINDOW_H
  89596. #define FLAC__PRIVATE__WINDOW_H
  89597. #ifdef HAVE_CONFIG_H
  89598. #include <config.h>
  89599. #endif
  89600. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  89601. void FLAC__window_bartlett(FLAC__real *window, const FLAC__int32 L);
  89602. void FLAC__window_bartlett_hann(FLAC__real *window, const FLAC__int32 L);
  89603. void FLAC__window_blackman(FLAC__real *window, const FLAC__int32 L);
  89604. void FLAC__window_blackman_harris_4term_92db_sidelobe(FLAC__real *window, const FLAC__int32 L);
  89605. void FLAC__window_connes(FLAC__real *window, const FLAC__int32 L);
  89606. void FLAC__window_flattop(FLAC__real *window, const FLAC__int32 L);
  89607. void FLAC__window_gauss(FLAC__real *window, const FLAC__int32 L, const FLAC__real stddev); /* 0.0 < stddev <= 0.5 */
  89608. void FLAC__window_hamming(FLAC__real *window, const FLAC__int32 L);
  89609. void FLAC__window_hann(FLAC__real *window, const FLAC__int32 L);
  89610. void FLAC__window_kaiser_bessel(FLAC__real *window, const FLAC__int32 L);
  89611. void FLAC__window_nuttall(FLAC__real *window, const FLAC__int32 L);
  89612. void FLAC__window_rectangle(FLAC__real *window, const FLAC__int32 L);
  89613. void FLAC__window_triangle(FLAC__real *window, const FLAC__int32 L);
  89614. void FLAC__window_tukey(FLAC__real *window, const FLAC__int32 L, const FLAC__real p);
  89615. void FLAC__window_welch(FLAC__real *window, const FLAC__int32 L);
  89616. #endif /* !defined FLAC__INTEGER_ONLY_LIBRARY */
  89617. #endif
  89618. /*** End of inlined file: window.h ***/
  89619. #ifndef FLaC__INLINE
  89620. #define FLaC__INLINE
  89621. #endif
  89622. #ifdef min
  89623. #undef min
  89624. #endif
  89625. #define min(x,y) ((x)<(y)?(x):(y))
  89626. #ifdef max
  89627. #undef max
  89628. #endif
  89629. #define max(x,y) ((x)>(y)?(x):(y))
  89630. #undef EXACT_RICE_BITS_CALCULATION
  89631. #undef ENABLE_RICE_PARAMETER_SEARCH
  89632. typedef struct {
  89633. FLAC__int32 *data[FLAC__MAX_CHANNELS];
  89634. unsigned size; /* of each data[] in samples */
  89635. unsigned tail;
  89636. } verify_input_fifo;
  89637. typedef struct {
  89638. const FLAC__byte *data;
  89639. unsigned capacity;
  89640. unsigned bytes;
  89641. } verify_output;
  89642. typedef enum {
  89643. ENCODER_IN_MAGIC = 0,
  89644. ENCODER_IN_METADATA = 1,
  89645. ENCODER_IN_AUDIO = 2
  89646. } EncoderStateHint;
  89647. static struct CompressionLevels {
  89648. FLAC__bool do_mid_side_stereo;
  89649. FLAC__bool loose_mid_side_stereo;
  89650. unsigned max_lpc_order;
  89651. unsigned qlp_coeff_precision;
  89652. FLAC__bool do_qlp_coeff_prec_search;
  89653. FLAC__bool do_escape_coding;
  89654. FLAC__bool do_exhaustive_model_search;
  89655. unsigned min_residual_partition_order;
  89656. unsigned max_residual_partition_order;
  89657. unsigned rice_parameter_search_dist;
  89658. } compression_levels_[] = {
  89659. { false, false, 0, 0, false, false, false, 0, 3, 0 },
  89660. { true , true , 0, 0, false, false, false, 0, 3, 0 },
  89661. { true , false, 0, 0, false, false, false, 0, 3, 0 },
  89662. { false, false, 6, 0, false, false, false, 0, 4, 0 },
  89663. { true , true , 8, 0, false, false, false, 0, 4, 0 },
  89664. { true , false, 8, 0, false, false, false, 0, 5, 0 },
  89665. { true , false, 8, 0, false, false, false, 0, 6, 0 },
  89666. { true , false, 8, 0, false, false, true , 0, 6, 0 },
  89667. { true , false, 12, 0, false, false, true , 0, 6, 0 }
  89668. };
  89669. static void set_defaults_enc(FLAC__StreamEncoder *encoder);
  89670. static void free_(FLAC__StreamEncoder *encoder);
  89671. static FLAC__bool resize_buffers_(FLAC__StreamEncoder *encoder, unsigned new_blocksize);
  89672. static FLAC__bool write_bitbuffer_(FLAC__StreamEncoder *encoder, unsigned samples, FLAC__bool is_last_block);
  89673. static FLAC__StreamEncoderWriteStatus write_frame_(FLAC__StreamEncoder *encoder, const FLAC__byte buffer[], size_t bytes, unsigned samples, FLAC__bool is_last_block);
  89674. static void update_metadata_(const FLAC__StreamEncoder *encoder);
  89675. #if FLAC__HAS_OGG
  89676. static void update_ogg_metadata_(FLAC__StreamEncoder *encoder);
  89677. #endif
  89678. static FLAC__bool process_frame_(FLAC__StreamEncoder *encoder, FLAC__bool is_fractional_block, FLAC__bool is_last_block);
  89679. static FLAC__bool process_subframes_(FLAC__StreamEncoder *encoder, FLAC__bool is_fractional_block);
  89680. static FLAC__bool process_subframe_(
  89681. FLAC__StreamEncoder *encoder,
  89682. unsigned min_partition_order,
  89683. unsigned max_partition_order,
  89684. const FLAC__FrameHeader *frame_header,
  89685. unsigned subframe_bps,
  89686. const FLAC__int32 integer_signal[],
  89687. FLAC__Subframe *subframe[2],
  89688. FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents[2],
  89689. FLAC__int32 *residual[2],
  89690. unsigned *best_subframe,
  89691. unsigned *best_bits
  89692. );
  89693. static FLAC__bool add_subframe_(
  89694. FLAC__StreamEncoder *encoder,
  89695. unsigned blocksize,
  89696. unsigned subframe_bps,
  89697. const FLAC__Subframe *subframe,
  89698. FLAC__BitWriter *frame
  89699. );
  89700. static unsigned evaluate_constant_subframe_(
  89701. FLAC__StreamEncoder *encoder,
  89702. const FLAC__int32 signal,
  89703. unsigned blocksize,
  89704. unsigned subframe_bps,
  89705. FLAC__Subframe *subframe
  89706. );
  89707. static unsigned evaluate_fixed_subframe_(
  89708. FLAC__StreamEncoder *encoder,
  89709. const FLAC__int32 signal[],
  89710. FLAC__int32 residual[],
  89711. FLAC__uint64 abs_residual_partition_sums[],
  89712. unsigned raw_bits_per_partition[],
  89713. unsigned blocksize,
  89714. unsigned subframe_bps,
  89715. unsigned order,
  89716. unsigned rice_parameter,
  89717. unsigned rice_parameter_limit,
  89718. unsigned min_partition_order,
  89719. unsigned max_partition_order,
  89720. FLAC__bool do_escape_coding,
  89721. unsigned rice_parameter_search_dist,
  89722. FLAC__Subframe *subframe,
  89723. FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents
  89724. );
  89725. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  89726. static unsigned evaluate_lpc_subframe_(
  89727. FLAC__StreamEncoder *encoder,
  89728. const FLAC__int32 signal[],
  89729. FLAC__int32 residual[],
  89730. FLAC__uint64 abs_residual_partition_sums[],
  89731. unsigned raw_bits_per_partition[],
  89732. const FLAC__real lp_coeff[],
  89733. unsigned blocksize,
  89734. unsigned subframe_bps,
  89735. unsigned order,
  89736. unsigned qlp_coeff_precision,
  89737. unsigned rice_parameter,
  89738. unsigned rice_parameter_limit,
  89739. unsigned min_partition_order,
  89740. unsigned max_partition_order,
  89741. FLAC__bool do_escape_coding,
  89742. unsigned rice_parameter_search_dist,
  89743. FLAC__Subframe *subframe,
  89744. FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents
  89745. );
  89746. #endif
  89747. static unsigned evaluate_verbatim_subframe_(
  89748. FLAC__StreamEncoder *encoder,
  89749. const FLAC__int32 signal[],
  89750. unsigned blocksize,
  89751. unsigned subframe_bps,
  89752. FLAC__Subframe *subframe
  89753. );
  89754. static unsigned find_best_partition_order_(
  89755. struct FLAC__StreamEncoderPrivate *private_,
  89756. const FLAC__int32 residual[],
  89757. FLAC__uint64 abs_residual_partition_sums[],
  89758. unsigned raw_bits_per_partition[],
  89759. unsigned residual_samples,
  89760. unsigned predictor_order,
  89761. unsigned rice_parameter,
  89762. unsigned rice_parameter_limit,
  89763. unsigned min_partition_order,
  89764. unsigned max_partition_order,
  89765. unsigned bps,
  89766. FLAC__bool do_escape_coding,
  89767. unsigned rice_parameter_search_dist,
  89768. FLAC__EntropyCodingMethod *best_ecm
  89769. );
  89770. static void precompute_partition_info_sums_(
  89771. const FLAC__int32 residual[],
  89772. FLAC__uint64 abs_residual_partition_sums[],
  89773. unsigned residual_samples,
  89774. unsigned predictor_order,
  89775. unsigned min_partition_order,
  89776. unsigned max_partition_order,
  89777. unsigned bps
  89778. );
  89779. static void precompute_partition_info_escapes_(
  89780. const FLAC__int32 residual[],
  89781. unsigned raw_bits_per_partition[],
  89782. unsigned residual_samples,
  89783. unsigned predictor_order,
  89784. unsigned min_partition_order,
  89785. unsigned max_partition_order
  89786. );
  89787. static FLAC__bool set_partitioned_rice_(
  89788. #ifdef EXACT_RICE_BITS_CALCULATION
  89789. const FLAC__int32 residual[],
  89790. #endif
  89791. const FLAC__uint64 abs_residual_partition_sums[],
  89792. const unsigned raw_bits_per_partition[],
  89793. const unsigned residual_samples,
  89794. const unsigned predictor_order,
  89795. const unsigned suggested_rice_parameter,
  89796. const unsigned rice_parameter_limit,
  89797. const unsigned rice_parameter_search_dist,
  89798. const unsigned partition_order,
  89799. const FLAC__bool search_for_escapes,
  89800. FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents,
  89801. unsigned *bits
  89802. );
  89803. static unsigned get_wasted_bits_(FLAC__int32 signal[], unsigned samples);
  89804. static void append_to_verify_fifo_(
  89805. verify_input_fifo *fifo,
  89806. const FLAC__int32 * const input[],
  89807. unsigned input_offset,
  89808. unsigned channels,
  89809. unsigned wide_samples
  89810. );
  89811. static void append_to_verify_fifo_interleaved_(
  89812. verify_input_fifo *fifo,
  89813. const FLAC__int32 input[],
  89814. unsigned input_offset,
  89815. unsigned channels,
  89816. unsigned wide_samples
  89817. );
  89818. static FLAC__StreamDecoderReadStatus verify_read_callback_(const FLAC__StreamDecoder *decoder, FLAC__byte buffer[], size_t *bytes, void *client_data);
  89819. static FLAC__StreamDecoderWriteStatus verify_write_callback_(const FLAC__StreamDecoder *decoder, const FLAC__Frame *frame, const FLAC__int32 * const buffer[], void *client_data);
  89820. static void verify_metadata_callback_(const FLAC__StreamDecoder *decoder, const FLAC__StreamMetadata *metadata, void *client_data);
  89821. static void verify_error_callback_(const FLAC__StreamDecoder *decoder, FLAC__StreamDecoderErrorStatus status, void *client_data);
  89822. static FLAC__StreamEncoderReadStatus file_read_callback_enc(const FLAC__StreamEncoder *encoder, FLAC__byte buffer[], size_t *bytes, void *client_data);
  89823. static FLAC__StreamEncoderSeekStatus file_seek_callback_enc(const FLAC__StreamEncoder *encoder, FLAC__uint64 absolute_byte_offset, void *client_data);
  89824. static FLAC__StreamEncoderTellStatus file_tell_callback_enc(const FLAC__StreamEncoder *encoder, FLAC__uint64 *absolute_byte_offset, void *client_data);
  89825. 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);
  89826. static FILE *get_binary_stdout_(void);
  89827. typedef struct FLAC__StreamEncoderPrivate {
  89828. unsigned input_capacity; /* current size (in samples) of the signal and residual buffers */
  89829. FLAC__int32 *integer_signal[FLAC__MAX_CHANNELS]; /* the integer version of the input signal */
  89830. FLAC__int32 *integer_signal_mid_side[2]; /* the integer version of the mid-side input signal (stereo only) */
  89831. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  89832. FLAC__real *real_signal[FLAC__MAX_CHANNELS]; /* (@@@ currently unused) the floating-point version of the input signal */
  89833. FLAC__real *real_signal_mid_side[2]; /* (@@@ currently unused) the floating-point version of the mid-side input signal (stereo only) */
  89834. FLAC__real *window[FLAC__MAX_APODIZATION_FUNCTIONS]; /* the pre-computed floating-point window for each apodization function */
  89835. FLAC__real *windowed_signal; /* the integer_signal[] * current window[] */
  89836. #endif
  89837. unsigned subframe_bps[FLAC__MAX_CHANNELS]; /* the effective bits per sample of the input signal (stream bps - wasted bits) */
  89838. unsigned subframe_bps_mid_side[2]; /* the effective bits per sample of the mid-side input signal (stream bps - wasted bits + 0/1) */
  89839. FLAC__int32 *residual_workspace[FLAC__MAX_CHANNELS][2]; /* each channel has a candidate and best workspace where the subframe residual signals will be stored */
  89840. FLAC__int32 *residual_workspace_mid_side[2][2];
  89841. FLAC__Subframe subframe_workspace[FLAC__MAX_CHANNELS][2];
  89842. FLAC__Subframe subframe_workspace_mid_side[2][2];
  89843. FLAC__Subframe *subframe_workspace_ptr[FLAC__MAX_CHANNELS][2];
  89844. FLAC__Subframe *subframe_workspace_ptr_mid_side[2][2];
  89845. FLAC__EntropyCodingMethod_PartitionedRiceContents partitioned_rice_contents_workspace[FLAC__MAX_CHANNELS][2];
  89846. FLAC__EntropyCodingMethod_PartitionedRiceContents partitioned_rice_contents_workspace_mid_side[FLAC__MAX_CHANNELS][2];
  89847. FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents_workspace_ptr[FLAC__MAX_CHANNELS][2];
  89848. FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents_workspace_ptr_mid_side[FLAC__MAX_CHANNELS][2];
  89849. unsigned best_subframe[FLAC__MAX_CHANNELS]; /* index (0 or 1) into 2nd dimension of the above workspaces */
  89850. unsigned best_subframe_mid_side[2];
  89851. unsigned best_subframe_bits[FLAC__MAX_CHANNELS]; /* size in bits of the best subframe for each channel */
  89852. unsigned best_subframe_bits_mid_side[2];
  89853. FLAC__uint64 *abs_residual_partition_sums; /* workspace where the sum of abs(candidate residual) for each partition is stored */
  89854. unsigned *raw_bits_per_partition; /* workspace where the sum of silog2(candidate residual) for each partition is stored */
  89855. FLAC__BitWriter *frame; /* the current frame being worked on */
  89856. unsigned loose_mid_side_stereo_frames; /* rounded number of frames the encoder will use before trying both independent and mid/side frames again */
  89857. unsigned loose_mid_side_stereo_frame_count; /* number of frames using the current channel assignment */
  89858. FLAC__ChannelAssignment last_channel_assignment;
  89859. FLAC__StreamMetadata streaminfo; /* scratchpad for STREAMINFO as it is built */
  89860. FLAC__StreamMetadata_SeekTable *seek_table; /* pointer into encoder->protected_->metadata_ where the seek table is */
  89861. unsigned current_sample_number;
  89862. unsigned current_frame_number;
  89863. FLAC__MD5Context md5context;
  89864. FLAC__CPUInfo cpuinfo;
  89865. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  89866. unsigned (*local_fixed_compute_best_predictor)(const FLAC__int32 data[], unsigned data_len, FLAC__float residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1]);
  89867. #else
  89868. unsigned (*local_fixed_compute_best_predictor)(const FLAC__int32 data[], unsigned data_len, FLAC__fixedpoint residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1]);
  89869. #endif
  89870. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  89871. void (*local_lpc_compute_autocorrelation)(const FLAC__real data[], unsigned data_len, unsigned lag, FLAC__real autoc[]);
  89872. 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[]);
  89873. 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[]);
  89874. 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[]);
  89875. #endif
  89876. FLAC__bool use_wide_by_block; /* use slow 64-bit versions of some functions because of the block size */
  89877. FLAC__bool use_wide_by_partition; /* use slow 64-bit versions of some functions because of the min partition order and blocksize */
  89878. FLAC__bool use_wide_by_order; /* use slow 64-bit versions of some functions because of the lpc order */
  89879. FLAC__bool disable_constant_subframes;
  89880. FLAC__bool disable_fixed_subframes;
  89881. FLAC__bool disable_verbatim_subframes;
  89882. #if FLAC__HAS_OGG
  89883. FLAC__bool is_ogg;
  89884. #endif
  89885. FLAC__StreamEncoderReadCallback read_callback; /* currently only needed for Ogg FLAC */
  89886. FLAC__StreamEncoderSeekCallback seek_callback;
  89887. FLAC__StreamEncoderTellCallback tell_callback;
  89888. FLAC__StreamEncoderWriteCallback write_callback;
  89889. FLAC__StreamEncoderMetadataCallback metadata_callback;
  89890. FLAC__StreamEncoderProgressCallback progress_callback;
  89891. void *client_data;
  89892. unsigned first_seekpoint_to_check;
  89893. FILE *file; /* only used when encoding to a file */
  89894. FLAC__uint64 bytes_written;
  89895. FLAC__uint64 samples_written;
  89896. unsigned frames_written;
  89897. unsigned total_frames_estimate;
  89898. FLAC__int32 *integer_signal_unaligned[FLAC__MAX_CHANNELS];
  89899. FLAC__int32 *integer_signal_mid_side_unaligned[2];
  89900. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  89901. FLAC__real *real_signal_unaligned[FLAC__MAX_CHANNELS]; /* (@@@ currently unused) */
  89902. FLAC__real *real_signal_mid_side_unaligned[2]; /* (@@@ currently unused) */
  89903. FLAC__real *window_unaligned[FLAC__MAX_APODIZATION_FUNCTIONS];
  89904. FLAC__real *windowed_signal_unaligned;
  89905. #endif
  89906. FLAC__int32 *residual_workspace_unaligned[FLAC__MAX_CHANNELS][2];
  89907. FLAC__int32 *residual_workspace_mid_side_unaligned[2][2];
  89908. FLAC__uint64 *abs_residual_partition_sums_unaligned;
  89909. unsigned *raw_bits_per_partition_unaligned;
  89910. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  89911. FLAC__real lp_coeff[FLAC__MAX_LPC_ORDER][FLAC__MAX_LPC_ORDER]; /* from process_subframe_() */
  89912. #endif
  89913. FLAC__EntropyCodingMethod_PartitionedRiceContents partitioned_rice_contents_extra[2]; /* from find_best_partition_order_() */
  89914. struct {
  89915. FLAC__StreamDecoder *decoder;
  89916. EncoderStateHint state_hint;
  89917. FLAC__bool needs_magic_hack;
  89918. verify_input_fifo input_fifo;
  89919. verify_output output;
  89920. struct {
  89921. FLAC__uint64 absolute_sample;
  89922. unsigned frame_number;
  89923. unsigned channel;
  89924. unsigned sample;
  89925. FLAC__int32 expected;
  89926. FLAC__int32 got;
  89927. } error_stats;
  89928. } verify;
  89929. FLAC__bool is_being_deleted; /* if true, call to ..._finish() from ..._delete() will not call the callbacks */
  89930. } FLAC__StreamEncoderPrivate;
  89931. FLAC_API const char * const FLAC__StreamEncoderStateString[] = {
  89932. "FLAC__STREAM_ENCODER_OK",
  89933. "FLAC__STREAM_ENCODER_UNINITIALIZED",
  89934. "FLAC__STREAM_ENCODER_OGG_ERROR",
  89935. "FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR",
  89936. "FLAC__STREAM_ENCODER_VERIFY_MISMATCH_IN_AUDIO_DATA",
  89937. "FLAC__STREAM_ENCODER_CLIENT_ERROR",
  89938. "FLAC__STREAM_ENCODER_IO_ERROR",
  89939. "FLAC__STREAM_ENCODER_FRAMING_ERROR",
  89940. "FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR"
  89941. };
  89942. FLAC_API const char * const FLAC__StreamEncoderInitStatusString[] = {
  89943. "FLAC__STREAM_ENCODER_INIT_STATUS_OK",
  89944. "FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR",
  89945. "FLAC__STREAM_ENCODER_INIT_STATUS_UNSUPPORTED_CONTAINER",
  89946. "FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_CALLBACKS",
  89947. "FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_NUMBER_OF_CHANNELS",
  89948. "FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_BITS_PER_SAMPLE",
  89949. "FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_SAMPLE_RATE",
  89950. "FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_BLOCK_SIZE",
  89951. "FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_MAX_LPC_ORDER",
  89952. "FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_QLP_COEFF_PRECISION",
  89953. "FLAC__STREAM_ENCODER_INIT_STATUS_BLOCK_SIZE_TOO_SMALL_FOR_LPC_ORDER",
  89954. "FLAC__STREAM_ENCODER_INIT_STATUS_NOT_STREAMABLE",
  89955. "FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA",
  89956. "FLAC__STREAM_ENCODER_INIT_STATUS_ALREADY_INITIALIZED"
  89957. };
  89958. FLAC_API const char * const FLAC__treamEncoderReadStatusString[] = {
  89959. "FLAC__STREAM_ENCODER_READ_STATUS_CONTINUE",
  89960. "FLAC__STREAM_ENCODER_READ_STATUS_END_OF_STREAM",
  89961. "FLAC__STREAM_ENCODER_READ_STATUS_ABORT",
  89962. "FLAC__STREAM_ENCODER_READ_STATUS_UNSUPPORTED"
  89963. };
  89964. FLAC_API const char * const FLAC__StreamEncoderWriteStatusString[] = {
  89965. "FLAC__STREAM_ENCODER_WRITE_STATUS_OK",
  89966. "FLAC__STREAM_ENCODER_WRITE_STATUS_FATAL_ERROR"
  89967. };
  89968. FLAC_API const char * const FLAC__StreamEncoderSeekStatusString[] = {
  89969. "FLAC__STREAM_ENCODER_SEEK_STATUS_OK",
  89970. "FLAC__STREAM_ENCODER_SEEK_STATUS_ERROR",
  89971. "FLAC__STREAM_ENCODER_SEEK_STATUS_UNSUPPORTED"
  89972. };
  89973. FLAC_API const char * const FLAC__StreamEncoderTellStatusString[] = {
  89974. "FLAC__STREAM_ENCODER_TELL_STATUS_OK",
  89975. "FLAC__STREAM_ENCODER_TELL_STATUS_ERROR",
  89976. "FLAC__STREAM_ENCODER_TELL_STATUS_UNSUPPORTED"
  89977. };
  89978. static const unsigned OVERREAD_ = 1;
  89979. FLAC_API FLAC__StreamEncoder *FLAC__stream_encoder_new(void)
  89980. {
  89981. FLAC__StreamEncoder *encoder;
  89982. unsigned i;
  89983. FLAC__ASSERT(sizeof(int) >= 4); /* we want to die right away if this is not true */
  89984. encoder = (FLAC__StreamEncoder*)calloc(1, sizeof(FLAC__StreamEncoder));
  89985. if(encoder == 0) {
  89986. return 0;
  89987. }
  89988. encoder->protected_ = (FLAC__StreamEncoderProtected*)calloc(1, sizeof(FLAC__StreamEncoderProtected));
  89989. if(encoder->protected_ == 0) {
  89990. free(encoder);
  89991. return 0;
  89992. }
  89993. encoder->private_ = (FLAC__StreamEncoderPrivate*)calloc(1, sizeof(FLAC__StreamEncoderPrivate));
  89994. if(encoder->private_ == 0) {
  89995. free(encoder->protected_);
  89996. free(encoder);
  89997. return 0;
  89998. }
  89999. encoder->private_->frame = FLAC__bitwriter_new();
  90000. if(encoder->private_->frame == 0) {
  90001. free(encoder->private_);
  90002. free(encoder->protected_);
  90003. free(encoder);
  90004. return 0;
  90005. }
  90006. encoder->private_->file = 0;
  90007. set_defaults_enc(encoder);
  90008. encoder->private_->is_being_deleted = false;
  90009. for(i = 0; i < FLAC__MAX_CHANNELS; i++) {
  90010. encoder->private_->subframe_workspace_ptr[i][0] = &encoder->private_->subframe_workspace[i][0];
  90011. encoder->private_->subframe_workspace_ptr[i][1] = &encoder->private_->subframe_workspace[i][1];
  90012. }
  90013. for(i = 0; i < 2; i++) {
  90014. encoder->private_->subframe_workspace_ptr_mid_side[i][0] = &encoder->private_->subframe_workspace_mid_side[i][0];
  90015. encoder->private_->subframe_workspace_ptr_mid_side[i][1] = &encoder->private_->subframe_workspace_mid_side[i][1];
  90016. }
  90017. for(i = 0; i < FLAC__MAX_CHANNELS; i++) {
  90018. encoder->private_->partitioned_rice_contents_workspace_ptr[i][0] = &encoder->private_->partitioned_rice_contents_workspace[i][0];
  90019. encoder->private_->partitioned_rice_contents_workspace_ptr[i][1] = &encoder->private_->partitioned_rice_contents_workspace[i][1];
  90020. }
  90021. for(i = 0; i < 2; i++) {
  90022. encoder->private_->partitioned_rice_contents_workspace_ptr_mid_side[i][0] = &encoder->private_->partitioned_rice_contents_workspace_mid_side[i][0];
  90023. encoder->private_->partitioned_rice_contents_workspace_ptr_mid_side[i][1] = &encoder->private_->partitioned_rice_contents_workspace_mid_side[i][1];
  90024. }
  90025. for(i = 0; i < FLAC__MAX_CHANNELS; i++) {
  90026. FLAC__format_entropy_coding_method_partitioned_rice_contents_init(&encoder->private_->partitioned_rice_contents_workspace[i][0]);
  90027. FLAC__format_entropy_coding_method_partitioned_rice_contents_init(&encoder->private_->partitioned_rice_contents_workspace[i][1]);
  90028. }
  90029. for(i = 0; i < 2; i++) {
  90030. FLAC__format_entropy_coding_method_partitioned_rice_contents_init(&encoder->private_->partitioned_rice_contents_workspace_mid_side[i][0]);
  90031. FLAC__format_entropy_coding_method_partitioned_rice_contents_init(&encoder->private_->partitioned_rice_contents_workspace_mid_side[i][1]);
  90032. }
  90033. for(i = 0; i < 2; i++)
  90034. FLAC__format_entropy_coding_method_partitioned_rice_contents_init(&encoder->private_->partitioned_rice_contents_extra[i]);
  90035. encoder->protected_->state = FLAC__STREAM_ENCODER_UNINITIALIZED;
  90036. return encoder;
  90037. }
  90038. FLAC_API void FLAC__stream_encoder_delete(FLAC__StreamEncoder *encoder)
  90039. {
  90040. unsigned i;
  90041. FLAC__ASSERT(0 != encoder);
  90042. FLAC__ASSERT(0 != encoder->protected_);
  90043. FLAC__ASSERT(0 != encoder->private_);
  90044. FLAC__ASSERT(0 != encoder->private_->frame);
  90045. encoder->private_->is_being_deleted = true;
  90046. (void)FLAC__stream_encoder_finish(encoder);
  90047. if(0 != encoder->private_->verify.decoder)
  90048. FLAC__stream_decoder_delete(encoder->private_->verify.decoder);
  90049. for(i = 0; i < FLAC__MAX_CHANNELS; i++) {
  90050. FLAC__format_entropy_coding_method_partitioned_rice_contents_clear(&encoder->private_->partitioned_rice_contents_workspace[i][0]);
  90051. FLAC__format_entropy_coding_method_partitioned_rice_contents_clear(&encoder->private_->partitioned_rice_contents_workspace[i][1]);
  90052. }
  90053. for(i = 0; i < 2; i++) {
  90054. FLAC__format_entropy_coding_method_partitioned_rice_contents_clear(&encoder->private_->partitioned_rice_contents_workspace_mid_side[i][0]);
  90055. FLAC__format_entropy_coding_method_partitioned_rice_contents_clear(&encoder->private_->partitioned_rice_contents_workspace_mid_side[i][1]);
  90056. }
  90057. for(i = 0; i < 2; i++)
  90058. FLAC__format_entropy_coding_method_partitioned_rice_contents_clear(&encoder->private_->partitioned_rice_contents_extra[i]);
  90059. FLAC__bitwriter_delete(encoder->private_->frame);
  90060. free(encoder->private_);
  90061. free(encoder->protected_);
  90062. free(encoder);
  90063. }
  90064. static FLAC__StreamEncoderInitStatus init_stream_internal_enc(
  90065. FLAC__StreamEncoder *encoder,
  90066. FLAC__StreamEncoderReadCallback read_callback,
  90067. FLAC__StreamEncoderWriteCallback write_callback,
  90068. FLAC__StreamEncoderSeekCallback seek_callback,
  90069. FLAC__StreamEncoderTellCallback tell_callback,
  90070. FLAC__StreamEncoderMetadataCallback metadata_callback,
  90071. void *client_data,
  90072. FLAC__bool is_ogg
  90073. )
  90074. {
  90075. unsigned i;
  90076. FLAC__bool metadata_has_seektable, metadata_has_vorbis_comment, metadata_picture_has_type1, metadata_picture_has_type2;
  90077. FLAC__ASSERT(0 != encoder);
  90078. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90079. return FLAC__STREAM_ENCODER_INIT_STATUS_ALREADY_INITIALIZED;
  90080. #if !FLAC__HAS_OGG
  90081. if(is_ogg)
  90082. return FLAC__STREAM_ENCODER_INIT_STATUS_UNSUPPORTED_CONTAINER;
  90083. #endif
  90084. if(0 == write_callback || (seek_callback && 0 == tell_callback))
  90085. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_CALLBACKS;
  90086. if(encoder->protected_->channels == 0 || encoder->protected_->channels > FLAC__MAX_CHANNELS)
  90087. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_NUMBER_OF_CHANNELS;
  90088. if(encoder->protected_->channels != 2) {
  90089. encoder->protected_->do_mid_side_stereo = false;
  90090. encoder->protected_->loose_mid_side_stereo = false;
  90091. }
  90092. else if(!encoder->protected_->do_mid_side_stereo)
  90093. encoder->protected_->loose_mid_side_stereo = false;
  90094. if(encoder->protected_->bits_per_sample >= 32)
  90095. encoder->protected_->do_mid_side_stereo = false; /* since we currenty do 32-bit math, the side channel would have 33 bps and overflow */
  90096. if(encoder->protected_->bits_per_sample < FLAC__MIN_BITS_PER_SAMPLE || encoder->protected_->bits_per_sample > FLAC__REFERENCE_CODEC_MAX_BITS_PER_SAMPLE)
  90097. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_BITS_PER_SAMPLE;
  90098. if(!FLAC__format_sample_rate_is_valid(encoder->protected_->sample_rate))
  90099. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_SAMPLE_RATE;
  90100. if(encoder->protected_->blocksize == 0) {
  90101. if(encoder->protected_->max_lpc_order == 0)
  90102. encoder->protected_->blocksize = 1152;
  90103. else
  90104. encoder->protected_->blocksize = 4096;
  90105. }
  90106. if(encoder->protected_->blocksize < FLAC__MIN_BLOCK_SIZE || encoder->protected_->blocksize > FLAC__MAX_BLOCK_SIZE)
  90107. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_BLOCK_SIZE;
  90108. if(encoder->protected_->max_lpc_order > FLAC__MAX_LPC_ORDER)
  90109. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_MAX_LPC_ORDER;
  90110. if(encoder->protected_->blocksize < encoder->protected_->max_lpc_order)
  90111. return FLAC__STREAM_ENCODER_INIT_STATUS_BLOCK_SIZE_TOO_SMALL_FOR_LPC_ORDER;
  90112. if(encoder->protected_->qlp_coeff_precision == 0) {
  90113. if(encoder->protected_->bits_per_sample < 16) {
  90114. encoder->protected_->qlp_coeff_precision = max(FLAC__MIN_QLP_COEFF_PRECISION, 2 + encoder->protected_->bits_per_sample / 2);
  90115. }
  90116. else if(encoder->protected_->bits_per_sample == 16) {
  90117. if(encoder->protected_->blocksize <= 192)
  90118. encoder->protected_->qlp_coeff_precision = 7;
  90119. else if(encoder->protected_->blocksize <= 384)
  90120. encoder->protected_->qlp_coeff_precision = 8;
  90121. else if(encoder->protected_->blocksize <= 576)
  90122. encoder->protected_->qlp_coeff_precision = 9;
  90123. else if(encoder->protected_->blocksize <= 1152)
  90124. encoder->protected_->qlp_coeff_precision = 10;
  90125. else if(encoder->protected_->blocksize <= 2304)
  90126. encoder->protected_->qlp_coeff_precision = 11;
  90127. else if(encoder->protected_->blocksize <= 4608)
  90128. encoder->protected_->qlp_coeff_precision = 12;
  90129. else
  90130. encoder->protected_->qlp_coeff_precision = 13;
  90131. }
  90132. else {
  90133. if(encoder->protected_->blocksize <= 384)
  90134. encoder->protected_->qlp_coeff_precision = FLAC__MAX_QLP_COEFF_PRECISION-2;
  90135. else if(encoder->protected_->blocksize <= 1152)
  90136. encoder->protected_->qlp_coeff_precision = FLAC__MAX_QLP_COEFF_PRECISION-1;
  90137. else
  90138. encoder->protected_->qlp_coeff_precision = FLAC__MAX_QLP_COEFF_PRECISION;
  90139. }
  90140. FLAC__ASSERT(encoder->protected_->qlp_coeff_precision <= FLAC__MAX_QLP_COEFF_PRECISION);
  90141. }
  90142. else if(encoder->protected_->qlp_coeff_precision < FLAC__MIN_QLP_COEFF_PRECISION || encoder->protected_->qlp_coeff_precision > FLAC__MAX_QLP_COEFF_PRECISION)
  90143. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_QLP_COEFF_PRECISION;
  90144. if(encoder->protected_->streamable_subset) {
  90145. if(
  90146. encoder->protected_->blocksize != 192 &&
  90147. encoder->protected_->blocksize != 576 &&
  90148. encoder->protected_->blocksize != 1152 &&
  90149. encoder->protected_->blocksize != 2304 &&
  90150. encoder->protected_->blocksize != 4608 &&
  90151. encoder->protected_->blocksize != 256 &&
  90152. encoder->protected_->blocksize != 512 &&
  90153. encoder->protected_->blocksize != 1024 &&
  90154. encoder->protected_->blocksize != 2048 &&
  90155. encoder->protected_->blocksize != 4096 &&
  90156. encoder->protected_->blocksize != 8192 &&
  90157. encoder->protected_->blocksize != 16384
  90158. )
  90159. return FLAC__STREAM_ENCODER_INIT_STATUS_NOT_STREAMABLE;
  90160. if(!FLAC__format_sample_rate_is_subset(encoder->protected_->sample_rate))
  90161. return FLAC__STREAM_ENCODER_INIT_STATUS_NOT_STREAMABLE;
  90162. if(
  90163. encoder->protected_->bits_per_sample != 8 &&
  90164. encoder->protected_->bits_per_sample != 12 &&
  90165. encoder->protected_->bits_per_sample != 16 &&
  90166. encoder->protected_->bits_per_sample != 20 &&
  90167. encoder->protected_->bits_per_sample != 24
  90168. )
  90169. return FLAC__STREAM_ENCODER_INIT_STATUS_NOT_STREAMABLE;
  90170. if(encoder->protected_->max_residual_partition_order > FLAC__SUBSET_MAX_RICE_PARTITION_ORDER)
  90171. return FLAC__STREAM_ENCODER_INIT_STATUS_NOT_STREAMABLE;
  90172. if(
  90173. encoder->protected_->sample_rate <= 48000 &&
  90174. (
  90175. encoder->protected_->blocksize > FLAC__SUBSET_MAX_BLOCK_SIZE_48000HZ ||
  90176. encoder->protected_->max_lpc_order > FLAC__SUBSET_MAX_LPC_ORDER_48000HZ
  90177. )
  90178. ) {
  90179. return FLAC__STREAM_ENCODER_INIT_STATUS_NOT_STREAMABLE;
  90180. }
  90181. }
  90182. if(encoder->protected_->max_residual_partition_order >= (1u << FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ORDER_LEN))
  90183. encoder->protected_->max_residual_partition_order = (1u << FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ORDER_LEN) - 1;
  90184. if(encoder->protected_->min_residual_partition_order >= encoder->protected_->max_residual_partition_order)
  90185. encoder->protected_->min_residual_partition_order = encoder->protected_->max_residual_partition_order;
  90186. #if FLAC__HAS_OGG
  90187. if(is_ogg && 0 != encoder->protected_->metadata && encoder->protected_->num_metadata_blocks > 1) {
  90188. unsigned i;
  90189. for(i = 1; i < encoder->protected_->num_metadata_blocks; i++) {
  90190. if(0 != encoder->protected_->metadata[i] && encoder->protected_->metadata[i]->type == FLAC__METADATA_TYPE_VORBIS_COMMENT) {
  90191. FLAC__StreamMetadata *vc = encoder->protected_->metadata[i];
  90192. for( ; i > 0; i--)
  90193. encoder->protected_->metadata[i] = encoder->protected_->metadata[i-1];
  90194. encoder->protected_->metadata[0] = vc;
  90195. break;
  90196. }
  90197. }
  90198. }
  90199. #endif
  90200. if(0 != encoder->protected_->metadata && encoder->protected_->num_metadata_blocks > 0) {
  90201. unsigned i;
  90202. for(i = 0; i < encoder->protected_->num_metadata_blocks; i++) {
  90203. if(0 != encoder->protected_->metadata[i] && encoder->protected_->metadata[i]->type == FLAC__METADATA_TYPE_SEEKTABLE) {
  90204. encoder->private_->seek_table = &encoder->protected_->metadata[i]->data.seek_table;
  90205. break; /* take only the first one */
  90206. }
  90207. }
  90208. }
  90209. if(0 == encoder->protected_->metadata && encoder->protected_->num_metadata_blocks > 0)
  90210. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA;
  90211. metadata_has_seektable = false;
  90212. metadata_has_vorbis_comment = false;
  90213. metadata_picture_has_type1 = false;
  90214. metadata_picture_has_type2 = false;
  90215. for(i = 0; i < encoder->protected_->num_metadata_blocks; i++) {
  90216. const FLAC__StreamMetadata *m = encoder->protected_->metadata[i];
  90217. if(m->type == FLAC__METADATA_TYPE_STREAMINFO)
  90218. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA;
  90219. else if(m->type == FLAC__METADATA_TYPE_SEEKTABLE) {
  90220. if(metadata_has_seektable) /* only one is allowed */
  90221. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA;
  90222. metadata_has_seektable = true;
  90223. if(!FLAC__format_seektable_is_legal(&m->data.seek_table))
  90224. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA;
  90225. }
  90226. else if(m->type == FLAC__METADATA_TYPE_VORBIS_COMMENT) {
  90227. if(metadata_has_vorbis_comment) /* only one is allowed */
  90228. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA;
  90229. metadata_has_vorbis_comment = true;
  90230. }
  90231. else if(m->type == FLAC__METADATA_TYPE_CUESHEET) {
  90232. if(!FLAC__format_cuesheet_is_legal(&m->data.cue_sheet, m->data.cue_sheet.is_cd, /*violation=*/0))
  90233. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA;
  90234. }
  90235. else if(m->type == FLAC__METADATA_TYPE_PICTURE) {
  90236. if(!FLAC__format_picture_is_legal(&m->data.picture, /*violation=*/0))
  90237. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA;
  90238. if(m->data.picture.type == FLAC__STREAM_METADATA_PICTURE_TYPE_FILE_ICON_STANDARD) {
  90239. if(metadata_picture_has_type1) /* there should only be 1 per stream */
  90240. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA;
  90241. metadata_picture_has_type1 = true;
  90242. if(
  90243. m->data.picture.type == FLAC__STREAM_METADATA_PICTURE_TYPE_FILE_ICON_STANDARD &&
  90244. (
  90245. (strcmp(m->data.picture.mime_type, "image/png") && strcmp(m->data.picture.mime_type, "-->")) ||
  90246. m->data.picture.width != 32 ||
  90247. m->data.picture.height != 32
  90248. )
  90249. )
  90250. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA;
  90251. }
  90252. else if(m->data.picture.type == FLAC__STREAM_METADATA_PICTURE_TYPE_FILE_ICON) {
  90253. if(metadata_picture_has_type2) /* there should only be 1 per stream */
  90254. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA;
  90255. metadata_picture_has_type2 = true;
  90256. }
  90257. }
  90258. }
  90259. encoder->private_->input_capacity = 0;
  90260. for(i = 0; i < encoder->protected_->channels; i++) {
  90261. encoder->private_->integer_signal_unaligned[i] = encoder->private_->integer_signal[i] = 0;
  90262. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  90263. encoder->private_->real_signal_unaligned[i] = encoder->private_->real_signal[i] = 0;
  90264. #endif
  90265. }
  90266. for(i = 0; i < 2; i++) {
  90267. encoder->private_->integer_signal_mid_side_unaligned[i] = encoder->private_->integer_signal_mid_side[i] = 0;
  90268. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  90269. encoder->private_->real_signal_mid_side_unaligned[i] = encoder->private_->real_signal_mid_side[i] = 0;
  90270. #endif
  90271. }
  90272. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  90273. for(i = 0; i < encoder->protected_->num_apodizations; i++)
  90274. encoder->private_->window_unaligned[i] = encoder->private_->window[i] = 0;
  90275. encoder->private_->windowed_signal_unaligned = encoder->private_->windowed_signal = 0;
  90276. #endif
  90277. for(i = 0; i < encoder->protected_->channels; i++) {
  90278. encoder->private_->residual_workspace_unaligned[i][0] = encoder->private_->residual_workspace[i][0] = 0;
  90279. encoder->private_->residual_workspace_unaligned[i][1] = encoder->private_->residual_workspace[i][1] = 0;
  90280. encoder->private_->best_subframe[i] = 0;
  90281. }
  90282. for(i = 0; i < 2; i++) {
  90283. encoder->private_->residual_workspace_mid_side_unaligned[i][0] = encoder->private_->residual_workspace_mid_side[i][0] = 0;
  90284. encoder->private_->residual_workspace_mid_side_unaligned[i][1] = encoder->private_->residual_workspace_mid_side[i][1] = 0;
  90285. encoder->private_->best_subframe_mid_side[i] = 0;
  90286. }
  90287. encoder->private_->abs_residual_partition_sums_unaligned = encoder->private_->abs_residual_partition_sums = 0;
  90288. encoder->private_->raw_bits_per_partition_unaligned = encoder->private_->raw_bits_per_partition = 0;
  90289. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  90290. encoder->private_->loose_mid_side_stereo_frames = (unsigned)((FLAC__double)encoder->protected_->sample_rate * 0.4 / (FLAC__double)encoder->protected_->blocksize + 0.5);
  90291. #else
  90292. FLAC__ASSERT(FLAC__MAX_SAMPLE_RATE <= 655350);
  90293. FLAC__ASSERT(FLAC__MAX_BLOCK_SIZE <= 65535);
  90294. FLAC__ASSERT(encoder->protected_->sample_rate <= 655350);
  90295. FLAC__ASSERT(encoder->protected_->blocksize <= 65535);
  90296. 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);
  90297. #endif
  90298. if(encoder->private_->loose_mid_side_stereo_frames == 0)
  90299. encoder->private_->loose_mid_side_stereo_frames = 1;
  90300. encoder->private_->loose_mid_side_stereo_frame_count = 0;
  90301. encoder->private_->current_sample_number = 0;
  90302. encoder->private_->current_frame_number = 0;
  90303. encoder->private_->use_wide_by_block = (encoder->protected_->bits_per_sample + FLAC__bitmath_ilog2(encoder->protected_->blocksize)+1 > 30);
  90304. 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? */
  90305. encoder->private_->use_wide_by_partition = (false); /*@@@ need to set this */
  90306. FLAC__cpu_info(&encoder->private_->cpuinfo);
  90307. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  90308. encoder->private_->local_lpc_compute_autocorrelation = FLAC__lpc_compute_autocorrelation;
  90309. #endif
  90310. encoder->private_->local_fixed_compute_best_predictor = FLAC__fixed_compute_best_predictor;
  90311. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  90312. encoder->private_->local_lpc_compute_residual_from_qlp_coefficients = FLAC__lpc_compute_residual_from_qlp_coefficients;
  90313. encoder->private_->local_lpc_compute_residual_from_qlp_coefficients_64bit = FLAC__lpc_compute_residual_from_qlp_coefficients_wide;
  90314. encoder->private_->local_lpc_compute_residual_from_qlp_coefficients_16bit = FLAC__lpc_compute_residual_from_qlp_coefficients;
  90315. #endif
  90316. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  90317. # ifndef FLAC__NO_ASM
  90318. if(encoder->private_->cpuinfo.use_asm) {
  90319. # ifdef FLAC__CPU_IA32
  90320. FLAC__ASSERT(encoder->private_->cpuinfo.type == FLAC__CPUINFO_TYPE_IA32);
  90321. # ifdef FLAC__HAS_NASM
  90322. if(encoder->private_->cpuinfo.data.ia32.sse) {
  90323. if(encoder->protected_->max_lpc_order < 4)
  90324. encoder->private_->local_lpc_compute_autocorrelation = FLAC__lpc_compute_autocorrelation_asm_ia32_sse_lag_4;
  90325. else if(encoder->protected_->max_lpc_order < 8)
  90326. encoder->private_->local_lpc_compute_autocorrelation = FLAC__lpc_compute_autocorrelation_asm_ia32_sse_lag_8;
  90327. else if(encoder->protected_->max_lpc_order < 12)
  90328. encoder->private_->local_lpc_compute_autocorrelation = FLAC__lpc_compute_autocorrelation_asm_ia32_sse_lag_12;
  90329. else
  90330. encoder->private_->local_lpc_compute_autocorrelation = FLAC__lpc_compute_autocorrelation_asm_ia32;
  90331. }
  90332. else if(encoder->private_->cpuinfo.data.ia32._3dnow)
  90333. encoder->private_->local_lpc_compute_autocorrelation = FLAC__lpc_compute_autocorrelation_asm_ia32_3dnow;
  90334. else
  90335. encoder->private_->local_lpc_compute_autocorrelation = FLAC__lpc_compute_autocorrelation_asm_ia32;
  90336. if(encoder->private_->cpuinfo.data.ia32.mmx) {
  90337. encoder->private_->local_lpc_compute_residual_from_qlp_coefficients = FLAC__lpc_compute_residual_from_qlp_coefficients_asm_ia32;
  90338. encoder->private_->local_lpc_compute_residual_from_qlp_coefficients_16bit = FLAC__lpc_compute_residual_from_qlp_coefficients_asm_ia32_mmx;
  90339. }
  90340. else {
  90341. encoder->private_->local_lpc_compute_residual_from_qlp_coefficients = FLAC__lpc_compute_residual_from_qlp_coefficients_asm_ia32;
  90342. encoder->private_->local_lpc_compute_residual_from_qlp_coefficients_16bit = FLAC__lpc_compute_residual_from_qlp_coefficients_asm_ia32;
  90343. }
  90344. if(encoder->private_->cpuinfo.data.ia32.mmx && encoder->private_->cpuinfo.data.ia32.cmov)
  90345. encoder->private_->local_fixed_compute_best_predictor = FLAC__fixed_compute_best_predictor_asm_ia32_mmx_cmov;
  90346. # endif /* FLAC__HAS_NASM */
  90347. # endif /* FLAC__CPU_IA32 */
  90348. }
  90349. # endif /* !FLAC__NO_ASM */
  90350. #endif /* !FLAC__INTEGER_ONLY_LIBRARY */
  90351. if(encoder->private_->use_wide_by_block) {
  90352. encoder->private_->local_fixed_compute_best_predictor = FLAC__fixed_compute_best_predictor_wide;
  90353. }
  90354. encoder->protected_->state = FLAC__STREAM_ENCODER_OK;
  90355. #if FLAC__HAS_OGG
  90356. encoder->private_->is_ogg = is_ogg;
  90357. if(is_ogg && !FLAC__ogg_encoder_aspect_init(&encoder->protected_->ogg_encoder_aspect)) {
  90358. encoder->protected_->state = FLAC__STREAM_ENCODER_OGG_ERROR;
  90359. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90360. }
  90361. #endif
  90362. encoder->private_->read_callback = read_callback;
  90363. encoder->private_->write_callback = write_callback;
  90364. encoder->private_->seek_callback = seek_callback;
  90365. encoder->private_->tell_callback = tell_callback;
  90366. encoder->private_->metadata_callback = metadata_callback;
  90367. encoder->private_->client_data = client_data;
  90368. if(!resize_buffers_(encoder, encoder->protected_->blocksize)) {
  90369. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90370. }
  90371. if(!FLAC__bitwriter_init(encoder->private_->frame)) {
  90372. encoder->protected_->state = FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR;
  90373. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90374. }
  90375. if(encoder->protected_->verify) {
  90376. encoder->private_->verify.input_fifo.size = encoder->protected_->blocksize+OVERREAD_;
  90377. for(i = 0; i < encoder->protected_->channels; i++) {
  90378. 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))) {
  90379. encoder->protected_->state = FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR;
  90380. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90381. }
  90382. }
  90383. encoder->private_->verify.input_fifo.tail = 0;
  90384. encoder->private_->verify.decoder = FLAC__stream_decoder_new();
  90385. if(0 == encoder->private_->verify.decoder) {
  90386. encoder->protected_->state = FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR;
  90387. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90388. }
  90389. 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) {
  90390. encoder->protected_->state = FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR;
  90391. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90392. }
  90393. }
  90394. encoder->private_->verify.error_stats.absolute_sample = 0;
  90395. encoder->private_->verify.error_stats.frame_number = 0;
  90396. encoder->private_->verify.error_stats.channel = 0;
  90397. encoder->private_->verify.error_stats.sample = 0;
  90398. encoder->private_->verify.error_stats.expected = 0;
  90399. encoder->private_->verify.error_stats.got = 0;
  90400. encoder->private_->first_seekpoint_to_check = 0;
  90401. encoder->private_->samples_written = 0;
  90402. encoder->protected_->streaminfo_offset = 0;
  90403. encoder->protected_->seektable_offset = 0;
  90404. encoder->protected_->audio_offset = 0;
  90405. if(encoder->protected_->verify)
  90406. encoder->private_->verify.state_hint = ENCODER_IN_MAGIC;
  90407. if(!FLAC__bitwriter_write_raw_uint32(encoder->private_->frame, FLAC__STREAM_SYNC, FLAC__STREAM_SYNC_LEN)) {
  90408. encoder->protected_->state = FLAC__STREAM_ENCODER_FRAMING_ERROR;
  90409. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90410. }
  90411. if(!write_bitbuffer_(encoder, 0, /*is_last_block=*/false)) {
  90412. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90413. }
  90414. if(encoder->protected_->verify)
  90415. encoder->private_->verify.state_hint = ENCODER_IN_METADATA;
  90416. encoder->private_->streaminfo.type = FLAC__METADATA_TYPE_STREAMINFO;
  90417. encoder->private_->streaminfo.is_last = false; /* we will have at a minimum a VORBIS_COMMENT afterwards */
  90418. encoder->private_->streaminfo.length = FLAC__STREAM_METADATA_STREAMINFO_LENGTH;
  90419. encoder->private_->streaminfo.data.stream_info.min_blocksize = encoder->protected_->blocksize; /* this encoder uses the same blocksize for the whole stream */
  90420. encoder->private_->streaminfo.data.stream_info.max_blocksize = encoder->protected_->blocksize;
  90421. encoder->private_->streaminfo.data.stream_info.min_framesize = 0; /* we don't know this yet; have to fill it in later */
  90422. encoder->private_->streaminfo.data.stream_info.max_framesize = 0; /* we don't know this yet; have to fill it in later */
  90423. encoder->private_->streaminfo.data.stream_info.sample_rate = encoder->protected_->sample_rate;
  90424. encoder->private_->streaminfo.data.stream_info.channels = encoder->protected_->channels;
  90425. encoder->private_->streaminfo.data.stream_info.bits_per_sample = encoder->protected_->bits_per_sample;
  90426. encoder->private_->streaminfo.data.stream_info.total_samples = encoder->protected_->total_samples_estimate; /* we will replace this later with the real total */
  90427. memset(encoder->private_->streaminfo.data.stream_info.md5sum, 0, 16); /* we don't know this yet; have to fill it in later */
  90428. if(encoder->protected_->do_md5)
  90429. FLAC__MD5Init(&encoder->private_->md5context);
  90430. if(!FLAC__add_metadata_block(&encoder->private_->streaminfo, encoder->private_->frame)) {
  90431. encoder->protected_->state = FLAC__STREAM_ENCODER_FRAMING_ERROR;
  90432. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90433. }
  90434. if(!write_bitbuffer_(encoder, 0, /*is_last_block=*/false)) {
  90435. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90436. }
  90437. encoder->private_->streaminfo.data.stream_info.min_framesize = (1u << FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN) - 1;
  90438. encoder->private_->streaminfo.data.stream_info.total_samples = 0;
  90439. if(!metadata_has_vorbis_comment) {
  90440. FLAC__StreamMetadata vorbis_comment;
  90441. vorbis_comment.type = FLAC__METADATA_TYPE_VORBIS_COMMENT;
  90442. vorbis_comment.is_last = (encoder->protected_->num_metadata_blocks == 0);
  90443. vorbis_comment.length = 4 + 4; /* MAGIC NUMBER */
  90444. vorbis_comment.data.vorbis_comment.vendor_string.length = 0;
  90445. vorbis_comment.data.vorbis_comment.vendor_string.entry = 0;
  90446. vorbis_comment.data.vorbis_comment.num_comments = 0;
  90447. vorbis_comment.data.vorbis_comment.comments = 0;
  90448. if(!FLAC__add_metadata_block(&vorbis_comment, encoder->private_->frame)) {
  90449. encoder->protected_->state = FLAC__STREAM_ENCODER_FRAMING_ERROR;
  90450. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90451. }
  90452. if(!write_bitbuffer_(encoder, 0, /*is_last_block=*/false)) {
  90453. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90454. }
  90455. }
  90456. for(i = 0; i < encoder->protected_->num_metadata_blocks; i++) {
  90457. encoder->protected_->metadata[i]->is_last = (i == encoder->protected_->num_metadata_blocks - 1);
  90458. if(!FLAC__add_metadata_block(encoder->protected_->metadata[i], encoder->private_->frame)) {
  90459. encoder->protected_->state = FLAC__STREAM_ENCODER_FRAMING_ERROR;
  90460. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90461. }
  90462. if(!write_bitbuffer_(encoder, 0, /*is_last_block=*/false)) {
  90463. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90464. }
  90465. }
  90466. 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 */
  90467. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  90468. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90469. }
  90470. if(encoder->protected_->verify)
  90471. encoder->private_->verify.state_hint = ENCODER_IN_AUDIO;
  90472. return FLAC__STREAM_ENCODER_INIT_STATUS_OK;
  90473. }
  90474. FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_stream(
  90475. FLAC__StreamEncoder *encoder,
  90476. FLAC__StreamEncoderWriteCallback write_callback,
  90477. FLAC__StreamEncoderSeekCallback seek_callback,
  90478. FLAC__StreamEncoderTellCallback tell_callback,
  90479. FLAC__StreamEncoderMetadataCallback metadata_callback,
  90480. void *client_data
  90481. )
  90482. {
  90483. return init_stream_internal_enc(
  90484. encoder,
  90485. 0,
  90486. write_callback,
  90487. seek_callback,
  90488. tell_callback,
  90489. metadata_callback,
  90490. client_data,
  90491. false
  90492. );
  90493. }
  90494. FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_ogg_stream(
  90495. FLAC__StreamEncoder *encoder,
  90496. FLAC__StreamEncoderReadCallback read_callback,
  90497. FLAC__StreamEncoderWriteCallback write_callback,
  90498. FLAC__StreamEncoderSeekCallback seek_callback,
  90499. FLAC__StreamEncoderTellCallback tell_callback,
  90500. FLAC__StreamEncoderMetadataCallback metadata_callback,
  90501. void *client_data
  90502. )
  90503. {
  90504. return init_stream_internal_enc(
  90505. encoder,
  90506. read_callback,
  90507. write_callback,
  90508. seek_callback,
  90509. tell_callback,
  90510. metadata_callback,
  90511. client_data,
  90512. true
  90513. );
  90514. }
  90515. static FLAC__StreamEncoderInitStatus init_FILE_internal_enc(
  90516. FLAC__StreamEncoder *encoder,
  90517. FILE *file,
  90518. FLAC__StreamEncoderProgressCallback progress_callback,
  90519. void *client_data,
  90520. FLAC__bool is_ogg
  90521. )
  90522. {
  90523. FLAC__StreamEncoderInitStatus init_status;
  90524. FLAC__ASSERT(0 != encoder);
  90525. FLAC__ASSERT(0 != file);
  90526. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90527. return FLAC__STREAM_ENCODER_INIT_STATUS_ALREADY_INITIALIZED;
  90528. if(file == 0) {
  90529. encoder->protected_->state = FLAC__STREAM_ENCODER_IO_ERROR;
  90530. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90531. }
  90532. if(file == stdout)
  90533. file = get_binary_stdout_(); /* just to be safe */
  90534. encoder->private_->file = file;
  90535. encoder->private_->progress_callback = progress_callback;
  90536. encoder->private_->bytes_written = 0;
  90537. encoder->private_->samples_written = 0;
  90538. encoder->private_->frames_written = 0;
  90539. init_status = init_stream_internal_enc(
  90540. encoder,
  90541. encoder->private_->file == stdout? 0 : is_ogg? file_read_callback_enc : 0,
  90542. file_write_callback_,
  90543. encoder->private_->file == stdout? 0 : file_seek_callback_enc,
  90544. encoder->private_->file == stdout? 0 : file_tell_callback_enc,
  90545. 0,
  90546. client_data,
  90547. is_ogg
  90548. );
  90549. if(init_status != FLAC__STREAM_ENCODER_INIT_STATUS_OK) {
  90550. return init_status;
  90551. }
  90552. {
  90553. unsigned blocksize = FLAC__stream_encoder_get_blocksize(encoder);
  90554. FLAC__ASSERT(blocksize != 0);
  90555. encoder->private_->total_frames_estimate = (unsigned)((FLAC__stream_encoder_get_total_samples_estimate(encoder) + blocksize - 1) / blocksize);
  90556. }
  90557. return init_status;
  90558. }
  90559. FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_FILE(
  90560. FLAC__StreamEncoder *encoder,
  90561. FILE *file,
  90562. FLAC__StreamEncoderProgressCallback progress_callback,
  90563. void *client_data
  90564. )
  90565. {
  90566. return init_FILE_internal_enc(encoder, file, progress_callback, client_data, /*is_ogg=*/false);
  90567. }
  90568. FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_ogg_FILE(
  90569. FLAC__StreamEncoder *encoder,
  90570. FILE *file,
  90571. FLAC__StreamEncoderProgressCallback progress_callback,
  90572. void *client_data
  90573. )
  90574. {
  90575. return init_FILE_internal_enc(encoder, file, progress_callback, client_data, /*is_ogg=*/true);
  90576. }
  90577. static FLAC__StreamEncoderInitStatus init_file_internal_enc(
  90578. FLAC__StreamEncoder *encoder,
  90579. const char *filename,
  90580. FLAC__StreamEncoderProgressCallback progress_callback,
  90581. void *client_data,
  90582. FLAC__bool is_ogg
  90583. )
  90584. {
  90585. FILE *file;
  90586. FLAC__ASSERT(0 != encoder);
  90587. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90588. return FLAC__STREAM_ENCODER_INIT_STATUS_ALREADY_INITIALIZED;
  90589. file = filename? fopen(filename, "w+b") : stdout;
  90590. if(file == 0) {
  90591. encoder->protected_->state = FLAC__STREAM_ENCODER_IO_ERROR;
  90592. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90593. }
  90594. return init_FILE_internal_enc(encoder, file, progress_callback, client_data, is_ogg);
  90595. }
  90596. FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_file(
  90597. FLAC__StreamEncoder *encoder,
  90598. const char *filename,
  90599. FLAC__StreamEncoderProgressCallback progress_callback,
  90600. void *client_data
  90601. )
  90602. {
  90603. return init_file_internal_enc(encoder, filename, progress_callback, client_data, /*is_ogg=*/false);
  90604. }
  90605. FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_ogg_file(
  90606. FLAC__StreamEncoder *encoder,
  90607. const char *filename,
  90608. FLAC__StreamEncoderProgressCallback progress_callback,
  90609. void *client_data
  90610. )
  90611. {
  90612. return init_file_internal_enc(encoder, filename, progress_callback, client_data, /*is_ogg=*/true);
  90613. }
  90614. FLAC_API FLAC__bool FLAC__stream_encoder_finish(FLAC__StreamEncoder *encoder)
  90615. {
  90616. FLAC__bool error = false;
  90617. FLAC__ASSERT(0 != encoder);
  90618. FLAC__ASSERT(0 != encoder->private_);
  90619. FLAC__ASSERT(0 != encoder->protected_);
  90620. if(encoder->protected_->state == FLAC__STREAM_ENCODER_UNINITIALIZED)
  90621. return true;
  90622. if(encoder->protected_->state == FLAC__STREAM_ENCODER_OK && !encoder->private_->is_being_deleted) {
  90623. if(encoder->private_->current_sample_number != 0) {
  90624. const FLAC__bool is_fractional_block = encoder->protected_->blocksize != encoder->private_->current_sample_number;
  90625. encoder->protected_->blocksize = encoder->private_->current_sample_number;
  90626. if(!process_frame_(encoder, is_fractional_block, /*is_last_block=*/true))
  90627. error = true;
  90628. }
  90629. }
  90630. if(encoder->protected_->do_md5)
  90631. FLAC__MD5Final(encoder->private_->streaminfo.data.stream_info.md5sum, &encoder->private_->md5context);
  90632. if(!encoder->private_->is_being_deleted) {
  90633. if(encoder->protected_->state == FLAC__STREAM_ENCODER_OK) {
  90634. if(encoder->private_->seek_callback) {
  90635. #if FLAC__HAS_OGG
  90636. if(encoder->private_->is_ogg)
  90637. update_ogg_metadata_(encoder);
  90638. else
  90639. #endif
  90640. update_metadata_(encoder);
  90641. if(encoder->protected_->state != FLAC__STREAM_ENCODER_OK)
  90642. error = true;
  90643. }
  90644. if(encoder->private_->metadata_callback)
  90645. encoder->private_->metadata_callback(encoder, &encoder->private_->streaminfo, encoder->private_->client_data);
  90646. }
  90647. if(encoder->protected_->verify && 0 != encoder->private_->verify.decoder && !FLAC__stream_decoder_finish(encoder->private_->verify.decoder)) {
  90648. if(!error)
  90649. encoder->protected_->state = FLAC__STREAM_ENCODER_VERIFY_MISMATCH_IN_AUDIO_DATA;
  90650. error = true;
  90651. }
  90652. }
  90653. if(0 != encoder->private_->file) {
  90654. if(encoder->private_->file != stdout)
  90655. fclose(encoder->private_->file);
  90656. encoder->private_->file = 0;
  90657. }
  90658. #if FLAC__HAS_OGG
  90659. if(encoder->private_->is_ogg)
  90660. FLAC__ogg_encoder_aspect_finish(&encoder->protected_->ogg_encoder_aspect);
  90661. #endif
  90662. free_(encoder);
  90663. set_defaults_enc(encoder);
  90664. if(!error)
  90665. encoder->protected_->state = FLAC__STREAM_ENCODER_UNINITIALIZED;
  90666. return !error;
  90667. }
  90668. FLAC_API FLAC__bool FLAC__stream_encoder_set_ogg_serial_number(FLAC__StreamEncoder *encoder, long value)
  90669. {
  90670. FLAC__ASSERT(0 != encoder);
  90671. FLAC__ASSERT(0 != encoder->private_);
  90672. FLAC__ASSERT(0 != encoder->protected_);
  90673. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90674. return false;
  90675. #if FLAC__HAS_OGG
  90676. FLAC__ogg_encoder_aspect_set_serial_number(&encoder->protected_->ogg_encoder_aspect, value);
  90677. return true;
  90678. #else
  90679. (void)value;
  90680. return false;
  90681. #endif
  90682. }
  90683. FLAC_API FLAC__bool FLAC__stream_encoder_set_verify(FLAC__StreamEncoder *encoder, FLAC__bool value)
  90684. {
  90685. FLAC__ASSERT(0 != encoder);
  90686. FLAC__ASSERT(0 != encoder->private_);
  90687. FLAC__ASSERT(0 != encoder->protected_);
  90688. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90689. return false;
  90690. #ifndef FLAC__MANDATORY_VERIFY_WHILE_ENCODING
  90691. encoder->protected_->verify = value;
  90692. #endif
  90693. return true;
  90694. }
  90695. FLAC_API FLAC__bool FLAC__stream_encoder_set_streamable_subset(FLAC__StreamEncoder *encoder, FLAC__bool value)
  90696. {
  90697. FLAC__ASSERT(0 != encoder);
  90698. FLAC__ASSERT(0 != encoder->private_);
  90699. FLAC__ASSERT(0 != encoder->protected_);
  90700. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90701. return false;
  90702. encoder->protected_->streamable_subset = value;
  90703. return true;
  90704. }
  90705. FLAC_API FLAC__bool FLAC__stream_encoder_set_do_md5(FLAC__StreamEncoder *encoder, FLAC__bool value)
  90706. {
  90707. FLAC__ASSERT(0 != encoder);
  90708. FLAC__ASSERT(0 != encoder->private_);
  90709. FLAC__ASSERT(0 != encoder->protected_);
  90710. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90711. return false;
  90712. encoder->protected_->do_md5 = value;
  90713. return true;
  90714. }
  90715. FLAC_API FLAC__bool FLAC__stream_encoder_set_channels(FLAC__StreamEncoder *encoder, unsigned value)
  90716. {
  90717. FLAC__ASSERT(0 != encoder);
  90718. FLAC__ASSERT(0 != encoder->private_);
  90719. FLAC__ASSERT(0 != encoder->protected_);
  90720. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90721. return false;
  90722. encoder->protected_->channels = value;
  90723. return true;
  90724. }
  90725. FLAC_API FLAC__bool FLAC__stream_encoder_set_bits_per_sample(FLAC__StreamEncoder *encoder, unsigned value)
  90726. {
  90727. FLAC__ASSERT(0 != encoder);
  90728. FLAC__ASSERT(0 != encoder->private_);
  90729. FLAC__ASSERT(0 != encoder->protected_);
  90730. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90731. return false;
  90732. encoder->protected_->bits_per_sample = value;
  90733. return true;
  90734. }
  90735. FLAC_API FLAC__bool FLAC__stream_encoder_set_sample_rate(FLAC__StreamEncoder *encoder, unsigned value)
  90736. {
  90737. FLAC__ASSERT(0 != encoder);
  90738. FLAC__ASSERT(0 != encoder->private_);
  90739. FLAC__ASSERT(0 != encoder->protected_);
  90740. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90741. return false;
  90742. encoder->protected_->sample_rate = value;
  90743. return true;
  90744. }
  90745. FLAC_API FLAC__bool FLAC__stream_encoder_set_compression_level(FLAC__StreamEncoder *encoder, unsigned value)
  90746. {
  90747. FLAC__bool ok = true;
  90748. FLAC__ASSERT(0 != encoder);
  90749. FLAC__ASSERT(0 != encoder->private_);
  90750. FLAC__ASSERT(0 != encoder->protected_);
  90751. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90752. return false;
  90753. if(value >= sizeof(compression_levels_)/sizeof(compression_levels_[0]))
  90754. value = sizeof(compression_levels_)/sizeof(compression_levels_[0]) - 1;
  90755. ok &= FLAC__stream_encoder_set_do_mid_side_stereo (encoder, compression_levels_[value].do_mid_side_stereo);
  90756. ok &= FLAC__stream_encoder_set_loose_mid_side_stereo (encoder, compression_levels_[value].loose_mid_side_stereo);
  90757. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  90758. #if 0
  90759. ok &= FLAC__stream_encoder_set_apodization (encoder, compression_levels_[value].apodization);
  90760. #else
  90761. encoder->protected_->num_apodizations = 1;
  90762. encoder->protected_->apodizations[0].type = FLAC__APODIZATION_TUKEY;
  90763. encoder->protected_->apodizations[0].parameters.tukey.p = 0.5;
  90764. #endif
  90765. #endif
  90766. ok &= FLAC__stream_encoder_set_max_lpc_order (encoder, compression_levels_[value].max_lpc_order);
  90767. ok &= FLAC__stream_encoder_set_qlp_coeff_precision (encoder, compression_levels_[value].qlp_coeff_precision);
  90768. ok &= FLAC__stream_encoder_set_do_qlp_coeff_prec_search (encoder, compression_levels_[value].do_qlp_coeff_prec_search);
  90769. ok &= FLAC__stream_encoder_set_do_escape_coding (encoder, compression_levels_[value].do_escape_coding);
  90770. ok &= FLAC__stream_encoder_set_do_exhaustive_model_search (encoder, compression_levels_[value].do_exhaustive_model_search);
  90771. ok &= FLAC__stream_encoder_set_min_residual_partition_order(encoder, compression_levels_[value].min_residual_partition_order);
  90772. ok &= FLAC__stream_encoder_set_max_residual_partition_order(encoder, compression_levels_[value].max_residual_partition_order);
  90773. ok &= FLAC__stream_encoder_set_rice_parameter_search_dist (encoder, compression_levels_[value].rice_parameter_search_dist);
  90774. return ok;
  90775. }
  90776. FLAC_API FLAC__bool FLAC__stream_encoder_set_blocksize(FLAC__StreamEncoder *encoder, unsigned value)
  90777. {
  90778. FLAC__ASSERT(0 != encoder);
  90779. FLAC__ASSERT(0 != encoder->private_);
  90780. FLAC__ASSERT(0 != encoder->protected_);
  90781. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90782. return false;
  90783. encoder->protected_->blocksize = value;
  90784. return true;
  90785. }
  90786. FLAC_API FLAC__bool FLAC__stream_encoder_set_do_mid_side_stereo(FLAC__StreamEncoder *encoder, FLAC__bool value)
  90787. {
  90788. FLAC__ASSERT(0 != encoder);
  90789. FLAC__ASSERT(0 != encoder->private_);
  90790. FLAC__ASSERT(0 != encoder->protected_);
  90791. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90792. return false;
  90793. encoder->protected_->do_mid_side_stereo = value;
  90794. return true;
  90795. }
  90796. FLAC_API FLAC__bool FLAC__stream_encoder_set_loose_mid_side_stereo(FLAC__StreamEncoder *encoder, FLAC__bool value)
  90797. {
  90798. FLAC__ASSERT(0 != encoder);
  90799. FLAC__ASSERT(0 != encoder->private_);
  90800. FLAC__ASSERT(0 != encoder->protected_);
  90801. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90802. return false;
  90803. encoder->protected_->loose_mid_side_stereo = value;
  90804. return true;
  90805. }
  90806. FLAC_API FLAC__bool FLAC__stream_encoder_set_apodization(FLAC__StreamEncoder *encoder, const char *specification)
  90807. {
  90808. FLAC__ASSERT(0 != encoder);
  90809. FLAC__ASSERT(0 != encoder->private_);
  90810. FLAC__ASSERT(0 != encoder->protected_);
  90811. FLAC__ASSERT(0 != specification);
  90812. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90813. return false;
  90814. #ifdef FLAC__INTEGER_ONLY_LIBRARY
  90815. (void)specification; /* silently ignore since we haven't integerized; will always use a rectangular window */
  90816. #else
  90817. encoder->protected_->num_apodizations = 0;
  90818. while(1) {
  90819. const char *s = strchr(specification, ';');
  90820. const size_t n = s? (size_t)(s - specification) : strlen(specification);
  90821. if (n==8 && 0 == strncmp("bartlett" , specification, n))
  90822. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_BARTLETT;
  90823. else if(n==13 && 0 == strncmp("bartlett_hann", specification, n))
  90824. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_BARTLETT_HANN;
  90825. else if(n==8 && 0 == strncmp("blackman" , specification, n))
  90826. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_BLACKMAN;
  90827. else if(n==26 && 0 == strncmp("blackman_harris_4term_92db", specification, n))
  90828. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_BLACKMAN_HARRIS_4TERM_92DB_SIDELOBE;
  90829. else if(n==6 && 0 == strncmp("connes" , specification, n))
  90830. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_CONNES;
  90831. else if(n==7 && 0 == strncmp("flattop" , specification, n))
  90832. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_FLATTOP;
  90833. else if(n>7 && 0 == strncmp("gauss(" , specification, 6)) {
  90834. FLAC__real stddev = (FLAC__real)strtod(specification+6, 0);
  90835. if (stddev > 0.0 && stddev <= 0.5) {
  90836. encoder->protected_->apodizations[encoder->protected_->num_apodizations].parameters.gauss.stddev = stddev;
  90837. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_GAUSS;
  90838. }
  90839. }
  90840. else if(n==7 && 0 == strncmp("hamming" , specification, n))
  90841. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_HAMMING;
  90842. else if(n==4 && 0 == strncmp("hann" , specification, n))
  90843. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_HANN;
  90844. else if(n==13 && 0 == strncmp("kaiser_bessel", specification, n))
  90845. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_KAISER_BESSEL;
  90846. else if(n==7 && 0 == strncmp("nuttall" , specification, n))
  90847. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_NUTTALL;
  90848. else if(n==9 && 0 == strncmp("rectangle" , specification, n))
  90849. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_RECTANGLE;
  90850. else if(n==8 && 0 == strncmp("triangle" , specification, n))
  90851. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_TRIANGLE;
  90852. else if(n>7 && 0 == strncmp("tukey(" , specification, 6)) {
  90853. FLAC__real p = (FLAC__real)strtod(specification+6, 0);
  90854. if (p >= 0.0 && p <= 1.0) {
  90855. encoder->protected_->apodizations[encoder->protected_->num_apodizations].parameters.tukey.p = p;
  90856. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_TUKEY;
  90857. }
  90858. }
  90859. else if(n==5 && 0 == strncmp("welch" , specification, n))
  90860. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_WELCH;
  90861. if (encoder->protected_->num_apodizations == 32)
  90862. break;
  90863. if (s)
  90864. specification = s+1;
  90865. else
  90866. break;
  90867. }
  90868. if(encoder->protected_->num_apodizations == 0) {
  90869. encoder->protected_->num_apodizations = 1;
  90870. encoder->protected_->apodizations[0].type = FLAC__APODIZATION_TUKEY;
  90871. encoder->protected_->apodizations[0].parameters.tukey.p = 0.5;
  90872. }
  90873. #endif
  90874. return true;
  90875. }
  90876. FLAC_API FLAC__bool FLAC__stream_encoder_set_max_lpc_order(FLAC__StreamEncoder *encoder, unsigned value)
  90877. {
  90878. FLAC__ASSERT(0 != encoder);
  90879. FLAC__ASSERT(0 != encoder->private_);
  90880. FLAC__ASSERT(0 != encoder->protected_);
  90881. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90882. return false;
  90883. encoder->protected_->max_lpc_order = value;
  90884. return true;
  90885. }
  90886. FLAC_API FLAC__bool FLAC__stream_encoder_set_qlp_coeff_precision(FLAC__StreamEncoder *encoder, unsigned value)
  90887. {
  90888. FLAC__ASSERT(0 != encoder);
  90889. FLAC__ASSERT(0 != encoder->private_);
  90890. FLAC__ASSERT(0 != encoder->protected_);
  90891. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90892. return false;
  90893. encoder->protected_->qlp_coeff_precision = value;
  90894. return true;
  90895. }
  90896. FLAC_API FLAC__bool FLAC__stream_encoder_set_do_qlp_coeff_prec_search(FLAC__StreamEncoder *encoder, FLAC__bool value)
  90897. {
  90898. FLAC__ASSERT(0 != encoder);
  90899. FLAC__ASSERT(0 != encoder->private_);
  90900. FLAC__ASSERT(0 != encoder->protected_);
  90901. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90902. return false;
  90903. encoder->protected_->do_qlp_coeff_prec_search = value;
  90904. return true;
  90905. }
  90906. FLAC_API FLAC__bool FLAC__stream_encoder_set_do_escape_coding(FLAC__StreamEncoder *encoder, FLAC__bool value)
  90907. {
  90908. FLAC__ASSERT(0 != encoder);
  90909. FLAC__ASSERT(0 != encoder->private_);
  90910. FLAC__ASSERT(0 != encoder->protected_);
  90911. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90912. return false;
  90913. #if 0
  90914. encoder->protected_->do_escape_coding = value;
  90915. #else
  90916. (void)value;
  90917. #endif
  90918. return true;
  90919. }
  90920. FLAC_API FLAC__bool FLAC__stream_encoder_set_do_exhaustive_model_search(FLAC__StreamEncoder *encoder, FLAC__bool value)
  90921. {
  90922. FLAC__ASSERT(0 != encoder);
  90923. FLAC__ASSERT(0 != encoder->private_);
  90924. FLAC__ASSERT(0 != encoder->protected_);
  90925. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90926. return false;
  90927. encoder->protected_->do_exhaustive_model_search = value;
  90928. return true;
  90929. }
  90930. FLAC_API FLAC__bool FLAC__stream_encoder_set_min_residual_partition_order(FLAC__StreamEncoder *encoder, unsigned value)
  90931. {
  90932. FLAC__ASSERT(0 != encoder);
  90933. FLAC__ASSERT(0 != encoder->private_);
  90934. FLAC__ASSERT(0 != encoder->protected_);
  90935. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90936. return false;
  90937. encoder->protected_->min_residual_partition_order = value;
  90938. return true;
  90939. }
  90940. FLAC_API FLAC__bool FLAC__stream_encoder_set_max_residual_partition_order(FLAC__StreamEncoder *encoder, unsigned value)
  90941. {
  90942. FLAC__ASSERT(0 != encoder);
  90943. FLAC__ASSERT(0 != encoder->private_);
  90944. FLAC__ASSERT(0 != encoder->protected_);
  90945. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90946. return false;
  90947. encoder->protected_->max_residual_partition_order = value;
  90948. return true;
  90949. }
  90950. FLAC_API FLAC__bool FLAC__stream_encoder_set_rice_parameter_search_dist(FLAC__StreamEncoder *encoder, unsigned value)
  90951. {
  90952. FLAC__ASSERT(0 != encoder);
  90953. FLAC__ASSERT(0 != encoder->private_);
  90954. FLAC__ASSERT(0 != encoder->protected_);
  90955. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90956. return false;
  90957. #if 0
  90958. encoder->protected_->rice_parameter_search_dist = value;
  90959. #else
  90960. (void)value;
  90961. #endif
  90962. return true;
  90963. }
  90964. FLAC_API FLAC__bool FLAC__stream_encoder_set_total_samples_estimate(FLAC__StreamEncoder *encoder, FLAC__uint64 value)
  90965. {
  90966. FLAC__ASSERT(0 != encoder);
  90967. FLAC__ASSERT(0 != encoder->private_);
  90968. FLAC__ASSERT(0 != encoder->protected_);
  90969. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90970. return false;
  90971. encoder->protected_->total_samples_estimate = value;
  90972. return true;
  90973. }
  90974. FLAC_API FLAC__bool FLAC__stream_encoder_set_metadata(FLAC__StreamEncoder *encoder, FLAC__StreamMetadata **metadata, unsigned num_blocks)
  90975. {
  90976. FLAC__ASSERT(0 != encoder);
  90977. FLAC__ASSERT(0 != encoder->private_);
  90978. FLAC__ASSERT(0 != encoder->protected_);
  90979. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90980. return false;
  90981. if(0 == metadata)
  90982. num_blocks = 0;
  90983. if(0 == num_blocks)
  90984. metadata = 0;
  90985. if(encoder->protected_->metadata) {
  90986. free(encoder->protected_->metadata);
  90987. encoder->protected_->metadata = 0;
  90988. encoder->protected_->num_metadata_blocks = 0;
  90989. }
  90990. if(num_blocks) {
  90991. FLAC__StreamMetadata **m;
  90992. if(0 == (m = (FLAC__StreamMetadata**)safe_malloc_mul_2op_(sizeof(m[0]), /*times*/num_blocks)))
  90993. return false;
  90994. memcpy(m, metadata, sizeof(m[0]) * num_blocks);
  90995. encoder->protected_->metadata = m;
  90996. encoder->protected_->num_metadata_blocks = num_blocks;
  90997. }
  90998. #if FLAC__HAS_OGG
  90999. if(!FLAC__ogg_encoder_aspect_set_num_metadata(&encoder->protected_->ogg_encoder_aspect, num_blocks))
  91000. return false;
  91001. #endif
  91002. return true;
  91003. }
  91004. FLAC_API FLAC__bool FLAC__stream_encoder_disable_constant_subframes(FLAC__StreamEncoder *encoder, FLAC__bool value)
  91005. {
  91006. FLAC__ASSERT(0 != encoder);
  91007. FLAC__ASSERT(0 != encoder->private_);
  91008. FLAC__ASSERT(0 != encoder->protected_);
  91009. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91010. return false;
  91011. encoder->private_->disable_constant_subframes = value;
  91012. return true;
  91013. }
  91014. FLAC_API FLAC__bool FLAC__stream_encoder_disable_fixed_subframes(FLAC__StreamEncoder *encoder, FLAC__bool value)
  91015. {
  91016. FLAC__ASSERT(0 != encoder);
  91017. FLAC__ASSERT(0 != encoder->private_);
  91018. FLAC__ASSERT(0 != encoder->protected_);
  91019. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91020. return false;
  91021. encoder->private_->disable_fixed_subframes = value;
  91022. return true;
  91023. }
  91024. FLAC_API FLAC__bool FLAC__stream_encoder_disable_verbatim_subframes(FLAC__StreamEncoder *encoder, FLAC__bool value)
  91025. {
  91026. FLAC__ASSERT(0 != encoder);
  91027. FLAC__ASSERT(0 != encoder->private_);
  91028. FLAC__ASSERT(0 != encoder->protected_);
  91029. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91030. return false;
  91031. encoder->private_->disable_verbatim_subframes = value;
  91032. return true;
  91033. }
  91034. FLAC_API FLAC__StreamEncoderState FLAC__stream_encoder_get_state(const FLAC__StreamEncoder *encoder)
  91035. {
  91036. FLAC__ASSERT(0 != encoder);
  91037. FLAC__ASSERT(0 != encoder->private_);
  91038. FLAC__ASSERT(0 != encoder->protected_);
  91039. return encoder->protected_->state;
  91040. }
  91041. FLAC_API FLAC__StreamDecoderState FLAC__stream_encoder_get_verify_decoder_state(const FLAC__StreamEncoder *encoder)
  91042. {
  91043. FLAC__ASSERT(0 != encoder);
  91044. FLAC__ASSERT(0 != encoder->private_);
  91045. FLAC__ASSERT(0 != encoder->protected_);
  91046. if(encoder->protected_->verify)
  91047. return FLAC__stream_decoder_get_state(encoder->private_->verify.decoder);
  91048. else
  91049. return FLAC__STREAM_DECODER_UNINITIALIZED;
  91050. }
  91051. FLAC_API const char *FLAC__stream_encoder_get_resolved_state_string(const FLAC__StreamEncoder *encoder)
  91052. {
  91053. FLAC__ASSERT(0 != encoder);
  91054. FLAC__ASSERT(0 != encoder->private_);
  91055. FLAC__ASSERT(0 != encoder->protected_);
  91056. if(encoder->protected_->state != FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR)
  91057. return FLAC__StreamEncoderStateString[encoder->protected_->state];
  91058. else
  91059. return FLAC__stream_decoder_get_resolved_state_string(encoder->private_->verify.decoder);
  91060. }
  91061. 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)
  91062. {
  91063. FLAC__ASSERT(0 != encoder);
  91064. FLAC__ASSERT(0 != encoder->private_);
  91065. FLAC__ASSERT(0 != encoder->protected_);
  91066. if(0 != absolute_sample)
  91067. *absolute_sample = encoder->private_->verify.error_stats.absolute_sample;
  91068. if(0 != frame_number)
  91069. *frame_number = encoder->private_->verify.error_stats.frame_number;
  91070. if(0 != channel)
  91071. *channel = encoder->private_->verify.error_stats.channel;
  91072. if(0 != sample)
  91073. *sample = encoder->private_->verify.error_stats.sample;
  91074. if(0 != expected)
  91075. *expected = encoder->private_->verify.error_stats.expected;
  91076. if(0 != got)
  91077. *got = encoder->private_->verify.error_stats.got;
  91078. }
  91079. FLAC_API FLAC__bool FLAC__stream_encoder_get_verify(const FLAC__StreamEncoder *encoder)
  91080. {
  91081. FLAC__ASSERT(0 != encoder);
  91082. FLAC__ASSERT(0 != encoder->private_);
  91083. FLAC__ASSERT(0 != encoder->protected_);
  91084. return encoder->protected_->verify;
  91085. }
  91086. FLAC_API FLAC__bool FLAC__stream_encoder_get_streamable_subset(const FLAC__StreamEncoder *encoder)
  91087. {
  91088. FLAC__ASSERT(0 != encoder);
  91089. FLAC__ASSERT(0 != encoder->private_);
  91090. FLAC__ASSERT(0 != encoder->protected_);
  91091. return encoder->protected_->streamable_subset;
  91092. }
  91093. FLAC_API FLAC__bool FLAC__stream_encoder_get_do_md5(const FLAC__StreamEncoder *encoder)
  91094. {
  91095. FLAC__ASSERT(0 != encoder);
  91096. FLAC__ASSERT(0 != encoder->private_);
  91097. FLAC__ASSERT(0 != encoder->protected_);
  91098. return encoder->protected_->do_md5;
  91099. }
  91100. FLAC_API unsigned FLAC__stream_encoder_get_channels(const FLAC__StreamEncoder *encoder)
  91101. {
  91102. FLAC__ASSERT(0 != encoder);
  91103. FLAC__ASSERT(0 != encoder->private_);
  91104. FLAC__ASSERT(0 != encoder->protected_);
  91105. return encoder->protected_->channels;
  91106. }
  91107. FLAC_API unsigned FLAC__stream_encoder_get_bits_per_sample(const FLAC__StreamEncoder *encoder)
  91108. {
  91109. FLAC__ASSERT(0 != encoder);
  91110. FLAC__ASSERT(0 != encoder->private_);
  91111. FLAC__ASSERT(0 != encoder->protected_);
  91112. return encoder->protected_->bits_per_sample;
  91113. }
  91114. FLAC_API unsigned FLAC__stream_encoder_get_sample_rate(const FLAC__StreamEncoder *encoder)
  91115. {
  91116. FLAC__ASSERT(0 != encoder);
  91117. FLAC__ASSERT(0 != encoder->private_);
  91118. FLAC__ASSERT(0 != encoder->protected_);
  91119. return encoder->protected_->sample_rate;
  91120. }
  91121. FLAC_API unsigned FLAC__stream_encoder_get_blocksize(const FLAC__StreamEncoder *encoder)
  91122. {
  91123. FLAC__ASSERT(0 != encoder);
  91124. FLAC__ASSERT(0 != encoder->private_);
  91125. FLAC__ASSERT(0 != encoder->protected_);
  91126. return encoder->protected_->blocksize;
  91127. }
  91128. FLAC_API FLAC__bool FLAC__stream_encoder_get_do_mid_side_stereo(const FLAC__StreamEncoder *encoder)
  91129. {
  91130. FLAC__ASSERT(0 != encoder);
  91131. FLAC__ASSERT(0 != encoder->private_);
  91132. FLAC__ASSERT(0 != encoder->protected_);
  91133. return encoder->protected_->do_mid_side_stereo;
  91134. }
  91135. FLAC_API FLAC__bool FLAC__stream_encoder_get_loose_mid_side_stereo(const FLAC__StreamEncoder *encoder)
  91136. {
  91137. FLAC__ASSERT(0 != encoder);
  91138. FLAC__ASSERT(0 != encoder->private_);
  91139. FLAC__ASSERT(0 != encoder->protected_);
  91140. return encoder->protected_->loose_mid_side_stereo;
  91141. }
  91142. FLAC_API unsigned FLAC__stream_encoder_get_max_lpc_order(const FLAC__StreamEncoder *encoder)
  91143. {
  91144. FLAC__ASSERT(0 != encoder);
  91145. FLAC__ASSERT(0 != encoder->private_);
  91146. FLAC__ASSERT(0 != encoder->protected_);
  91147. return encoder->protected_->max_lpc_order;
  91148. }
  91149. FLAC_API unsigned FLAC__stream_encoder_get_qlp_coeff_precision(const FLAC__StreamEncoder *encoder)
  91150. {
  91151. FLAC__ASSERT(0 != encoder);
  91152. FLAC__ASSERT(0 != encoder->private_);
  91153. FLAC__ASSERT(0 != encoder->protected_);
  91154. return encoder->protected_->qlp_coeff_precision;
  91155. }
  91156. FLAC_API FLAC__bool FLAC__stream_encoder_get_do_qlp_coeff_prec_search(const FLAC__StreamEncoder *encoder)
  91157. {
  91158. FLAC__ASSERT(0 != encoder);
  91159. FLAC__ASSERT(0 != encoder->private_);
  91160. FLAC__ASSERT(0 != encoder->protected_);
  91161. return encoder->protected_->do_qlp_coeff_prec_search;
  91162. }
  91163. FLAC_API FLAC__bool FLAC__stream_encoder_get_do_escape_coding(const FLAC__StreamEncoder *encoder)
  91164. {
  91165. FLAC__ASSERT(0 != encoder);
  91166. FLAC__ASSERT(0 != encoder->private_);
  91167. FLAC__ASSERT(0 != encoder->protected_);
  91168. return encoder->protected_->do_escape_coding;
  91169. }
  91170. FLAC_API FLAC__bool FLAC__stream_encoder_get_do_exhaustive_model_search(const FLAC__StreamEncoder *encoder)
  91171. {
  91172. FLAC__ASSERT(0 != encoder);
  91173. FLAC__ASSERT(0 != encoder->private_);
  91174. FLAC__ASSERT(0 != encoder->protected_);
  91175. return encoder->protected_->do_exhaustive_model_search;
  91176. }
  91177. FLAC_API unsigned FLAC__stream_encoder_get_min_residual_partition_order(const FLAC__StreamEncoder *encoder)
  91178. {
  91179. FLAC__ASSERT(0 != encoder);
  91180. FLAC__ASSERT(0 != encoder->private_);
  91181. FLAC__ASSERT(0 != encoder->protected_);
  91182. return encoder->protected_->min_residual_partition_order;
  91183. }
  91184. FLAC_API unsigned FLAC__stream_encoder_get_max_residual_partition_order(const FLAC__StreamEncoder *encoder)
  91185. {
  91186. FLAC__ASSERT(0 != encoder);
  91187. FLAC__ASSERT(0 != encoder->private_);
  91188. FLAC__ASSERT(0 != encoder->protected_);
  91189. return encoder->protected_->max_residual_partition_order;
  91190. }
  91191. FLAC_API unsigned FLAC__stream_encoder_get_rice_parameter_search_dist(const FLAC__StreamEncoder *encoder)
  91192. {
  91193. FLAC__ASSERT(0 != encoder);
  91194. FLAC__ASSERT(0 != encoder->private_);
  91195. FLAC__ASSERT(0 != encoder->protected_);
  91196. return encoder->protected_->rice_parameter_search_dist;
  91197. }
  91198. FLAC_API FLAC__uint64 FLAC__stream_encoder_get_total_samples_estimate(const FLAC__StreamEncoder *encoder)
  91199. {
  91200. FLAC__ASSERT(0 != encoder);
  91201. FLAC__ASSERT(0 != encoder->private_);
  91202. FLAC__ASSERT(0 != encoder->protected_);
  91203. return encoder->protected_->total_samples_estimate;
  91204. }
  91205. FLAC_API FLAC__bool FLAC__stream_encoder_process(FLAC__StreamEncoder *encoder, const FLAC__int32 * const buffer[], unsigned samples)
  91206. {
  91207. unsigned i, j = 0, channel;
  91208. const unsigned channels = encoder->protected_->channels, blocksize = encoder->protected_->blocksize;
  91209. FLAC__ASSERT(0 != encoder);
  91210. FLAC__ASSERT(0 != encoder->private_);
  91211. FLAC__ASSERT(0 != encoder->protected_);
  91212. FLAC__ASSERT(encoder->protected_->state == FLAC__STREAM_ENCODER_OK);
  91213. do {
  91214. const unsigned n = min(blocksize+OVERREAD_-encoder->private_->current_sample_number, samples-j);
  91215. if(encoder->protected_->verify)
  91216. append_to_verify_fifo_(&encoder->private_->verify.input_fifo, buffer, j, channels, n);
  91217. for(channel = 0; channel < channels; channel++)
  91218. memcpy(&encoder->private_->integer_signal[channel][encoder->private_->current_sample_number], &buffer[channel][j], sizeof(buffer[channel][0]) * n);
  91219. if(encoder->protected_->do_mid_side_stereo) {
  91220. FLAC__ASSERT(channels == 2);
  91221. for(i = encoder->private_->current_sample_number; i <= blocksize && j < samples; i++, j++) {
  91222. encoder->private_->integer_signal_mid_side[1][i] = buffer[0][j] - buffer[1][j];
  91223. 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' ! */
  91224. }
  91225. }
  91226. else
  91227. j += n;
  91228. encoder->private_->current_sample_number += n;
  91229. if(encoder->private_->current_sample_number > blocksize) {
  91230. FLAC__ASSERT(encoder->private_->current_sample_number == blocksize+OVERREAD_);
  91231. FLAC__ASSERT(OVERREAD_ == 1); /* assert we only overread 1 sample which simplifies the rest of the code below */
  91232. if(!process_frame_(encoder, /*is_fractional_block=*/false, /*is_last_block=*/false))
  91233. return false;
  91234. for(channel = 0; channel < channels; channel++)
  91235. encoder->private_->integer_signal[channel][0] = encoder->private_->integer_signal[channel][blocksize];
  91236. if(encoder->protected_->do_mid_side_stereo) {
  91237. encoder->private_->integer_signal_mid_side[0][0] = encoder->private_->integer_signal_mid_side[0][blocksize];
  91238. encoder->private_->integer_signal_mid_side[1][0] = encoder->private_->integer_signal_mid_side[1][blocksize];
  91239. }
  91240. encoder->private_->current_sample_number = 1;
  91241. }
  91242. } while(j < samples);
  91243. return true;
  91244. }
  91245. FLAC_API FLAC__bool FLAC__stream_encoder_process_interleaved(FLAC__StreamEncoder *encoder, const FLAC__int32 buffer[], unsigned samples)
  91246. {
  91247. unsigned i, j, k, channel;
  91248. FLAC__int32 x, mid, side;
  91249. const unsigned channels = encoder->protected_->channels, blocksize = encoder->protected_->blocksize;
  91250. FLAC__ASSERT(0 != encoder);
  91251. FLAC__ASSERT(0 != encoder->private_);
  91252. FLAC__ASSERT(0 != encoder->protected_);
  91253. FLAC__ASSERT(encoder->protected_->state == FLAC__STREAM_ENCODER_OK);
  91254. j = k = 0;
  91255. if(encoder->protected_->do_mid_side_stereo && channels == 2) {
  91256. do {
  91257. if(encoder->protected_->verify)
  91258. append_to_verify_fifo_interleaved_(&encoder->private_->verify.input_fifo, buffer, j, channels, min(blocksize+OVERREAD_-encoder->private_->current_sample_number, samples-j));
  91259. for(i = encoder->private_->current_sample_number; i <= blocksize && j < samples; i++, j++) {
  91260. encoder->private_->integer_signal[0][i] = mid = side = buffer[k++];
  91261. x = buffer[k++];
  91262. encoder->private_->integer_signal[1][i] = x;
  91263. mid += x;
  91264. side -= x;
  91265. mid >>= 1; /* NOTE: not the same as 'mid = (left + right) / 2' ! */
  91266. encoder->private_->integer_signal_mid_side[1][i] = side;
  91267. encoder->private_->integer_signal_mid_side[0][i] = mid;
  91268. }
  91269. encoder->private_->current_sample_number = i;
  91270. if(i > blocksize) {
  91271. if(!process_frame_(encoder, /*is_fractional_block=*/false, /*is_last_block=*/false))
  91272. return false;
  91273. /* move unprocessed overread samples to beginnings of arrays */
  91274. FLAC__ASSERT(i == blocksize+OVERREAD_);
  91275. FLAC__ASSERT(OVERREAD_ == 1); /* assert we only overread 1 sample which simplifies the rest of the code below */
  91276. encoder->private_->integer_signal[0][0] = encoder->private_->integer_signal[0][blocksize];
  91277. encoder->private_->integer_signal[1][0] = encoder->private_->integer_signal[1][blocksize];
  91278. encoder->private_->integer_signal_mid_side[0][0] = encoder->private_->integer_signal_mid_side[0][blocksize];
  91279. encoder->private_->integer_signal_mid_side[1][0] = encoder->private_->integer_signal_mid_side[1][blocksize];
  91280. encoder->private_->current_sample_number = 1;
  91281. }
  91282. } while(j < samples);
  91283. }
  91284. else {
  91285. do {
  91286. if(encoder->protected_->verify)
  91287. append_to_verify_fifo_interleaved_(&encoder->private_->verify.input_fifo, buffer, j, channels, min(blocksize+OVERREAD_-encoder->private_->current_sample_number, samples-j));
  91288. for(i = encoder->private_->current_sample_number; i <= blocksize && j < samples; i++, j++) {
  91289. for(channel = 0; channel < channels; channel++)
  91290. encoder->private_->integer_signal[channel][i] = buffer[k++];
  91291. }
  91292. encoder->private_->current_sample_number = i;
  91293. if(i > blocksize) {
  91294. if(!process_frame_(encoder, /*is_fractional_block=*/false, /*is_last_block=*/false))
  91295. return false;
  91296. /* move unprocessed overread samples to beginnings of arrays */
  91297. FLAC__ASSERT(i == blocksize+OVERREAD_);
  91298. FLAC__ASSERT(OVERREAD_ == 1); /* assert we only overread 1 sample which simplifies the rest of the code below */
  91299. for(channel = 0; channel < channels; channel++)
  91300. encoder->private_->integer_signal[channel][0] = encoder->private_->integer_signal[channel][blocksize];
  91301. encoder->private_->current_sample_number = 1;
  91302. }
  91303. } while(j < samples);
  91304. }
  91305. return true;
  91306. }
  91307. void set_defaults_enc(FLAC__StreamEncoder *encoder)
  91308. {
  91309. FLAC__ASSERT(0 != encoder);
  91310. #ifdef FLAC__MANDATORY_VERIFY_WHILE_ENCODING
  91311. encoder->protected_->verify = true;
  91312. #else
  91313. encoder->protected_->verify = false;
  91314. #endif
  91315. encoder->protected_->streamable_subset = true;
  91316. encoder->protected_->do_md5 = true;
  91317. encoder->protected_->do_mid_side_stereo = false;
  91318. encoder->protected_->loose_mid_side_stereo = false;
  91319. encoder->protected_->channels = 2;
  91320. encoder->protected_->bits_per_sample = 16;
  91321. encoder->protected_->sample_rate = 44100;
  91322. encoder->protected_->blocksize = 0;
  91323. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  91324. encoder->protected_->num_apodizations = 1;
  91325. encoder->protected_->apodizations[0].type = FLAC__APODIZATION_TUKEY;
  91326. encoder->protected_->apodizations[0].parameters.tukey.p = 0.5;
  91327. #endif
  91328. encoder->protected_->max_lpc_order = 0;
  91329. encoder->protected_->qlp_coeff_precision = 0;
  91330. encoder->protected_->do_qlp_coeff_prec_search = false;
  91331. encoder->protected_->do_exhaustive_model_search = false;
  91332. encoder->protected_->do_escape_coding = false;
  91333. encoder->protected_->min_residual_partition_order = 0;
  91334. encoder->protected_->max_residual_partition_order = 0;
  91335. encoder->protected_->rice_parameter_search_dist = 0;
  91336. encoder->protected_->total_samples_estimate = 0;
  91337. encoder->protected_->metadata = 0;
  91338. encoder->protected_->num_metadata_blocks = 0;
  91339. encoder->private_->seek_table = 0;
  91340. encoder->private_->disable_constant_subframes = false;
  91341. encoder->private_->disable_fixed_subframes = false;
  91342. encoder->private_->disable_verbatim_subframes = false;
  91343. #if FLAC__HAS_OGG
  91344. encoder->private_->is_ogg = false;
  91345. #endif
  91346. encoder->private_->read_callback = 0;
  91347. encoder->private_->write_callback = 0;
  91348. encoder->private_->seek_callback = 0;
  91349. encoder->private_->tell_callback = 0;
  91350. encoder->private_->metadata_callback = 0;
  91351. encoder->private_->progress_callback = 0;
  91352. encoder->private_->client_data = 0;
  91353. #if FLAC__HAS_OGG
  91354. FLAC__ogg_encoder_aspect_set_defaults(&encoder->protected_->ogg_encoder_aspect);
  91355. #endif
  91356. }
  91357. void free_(FLAC__StreamEncoder *encoder)
  91358. {
  91359. unsigned i, channel;
  91360. FLAC__ASSERT(0 != encoder);
  91361. if(encoder->protected_->metadata) {
  91362. free(encoder->protected_->metadata);
  91363. encoder->protected_->metadata = 0;
  91364. encoder->protected_->num_metadata_blocks = 0;
  91365. }
  91366. for(i = 0; i < encoder->protected_->channels; i++) {
  91367. if(0 != encoder->private_->integer_signal_unaligned[i]) {
  91368. free(encoder->private_->integer_signal_unaligned[i]);
  91369. encoder->private_->integer_signal_unaligned[i] = 0;
  91370. }
  91371. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  91372. if(0 != encoder->private_->real_signal_unaligned[i]) {
  91373. free(encoder->private_->real_signal_unaligned[i]);
  91374. encoder->private_->real_signal_unaligned[i] = 0;
  91375. }
  91376. #endif
  91377. }
  91378. for(i = 0; i < 2; i++) {
  91379. if(0 != encoder->private_->integer_signal_mid_side_unaligned[i]) {
  91380. free(encoder->private_->integer_signal_mid_side_unaligned[i]);
  91381. encoder->private_->integer_signal_mid_side_unaligned[i] = 0;
  91382. }
  91383. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  91384. if(0 != encoder->private_->real_signal_mid_side_unaligned[i]) {
  91385. free(encoder->private_->real_signal_mid_side_unaligned[i]);
  91386. encoder->private_->real_signal_mid_side_unaligned[i] = 0;
  91387. }
  91388. #endif
  91389. }
  91390. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  91391. for(i = 0; i < encoder->protected_->num_apodizations; i++) {
  91392. if(0 != encoder->private_->window_unaligned[i]) {
  91393. free(encoder->private_->window_unaligned[i]);
  91394. encoder->private_->window_unaligned[i] = 0;
  91395. }
  91396. }
  91397. if(0 != encoder->private_->windowed_signal_unaligned) {
  91398. free(encoder->private_->windowed_signal_unaligned);
  91399. encoder->private_->windowed_signal_unaligned = 0;
  91400. }
  91401. #endif
  91402. for(channel = 0; channel < encoder->protected_->channels; channel++) {
  91403. for(i = 0; i < 2; i++) {
  91404. if(0 != encoder->private_->residual_workspace_unaligned[channel][i]) {
  91405. free(encoder->private_->residual_workspace_unaligned[channel][i]);
  91406. encoder->private_->residual_workspace_unaligned[channel][i] = 0;
  91407. }
  91408. }
  91409. }
  91410. for(channel = 0; channel < 2; channel++) {
  91411. for(i = 0; i < 2; i++) {
  91412. if(0 != encoder->private_->residual_workspace_mid_side_unaligned[channel][i]) {
  91413. free(encoder->private_->residual_workspace_mid_side_unaligned[channel][i]);
  91414. encoder->private_->residual_workspace_mid_side_unaligned[channel][i] = 0;
  91415. }
  91416. }
  91417. }
  91418. if(0 != encoder->private_->abs_residual_partition_sums_unaligned) {
  91419. free(encoder->private_->abs_residual_partition_sums_unaligned);
  91420. encoder->private_->abs_residual_partition_sums_unaligned = 0;
  91421. }
  91422. if(0 != encoder->private_->raw_bits_per_partition_unaligned) {
  91423. free(encoder->private_->raw_bits_per_partition_unaligned);
  91424. encoder->private_->raw_bits_per_partition_unaligned = 0;
  91425. }
  91426. if(encoder->protected_->verify) {
  91427. for(i = 0; i < encoder->protected_->channels; i++) {
  91428. if(0 != encoder->private_->verify.input_fifo.data[i]) {
  91429. free(encoder->private_->verify.input_fifo.data[i]);
  91430. encoder->private_->verify.input_fifo.data[i] = 0;
  91431. }
  91432. }
  91433. }
  91434. FLAC__bitwriter_free(encoder->private_->frame);
  91435. }
  91436. FLAC__bool resize_buffers_(FLAC__StreamEncoder *encoder, unsigned new_blocksize)
  91437. {
  91438. FLAC__bool ok;
  91439. unsigned i, channel;
  91440. FLAC__ASSERT(new_blocksize > 0);
  91441. FLAC__ASSERT(encoder->protected_->state == FLAC__STREAM_ENCODER_OK);
  91442. FLAC__ASSERT(encoder->private_->current_sample_number == 0);
  91443. if(new_blocksize <= encoder->private_->input_capacity)
  91444. return true;
  91445. ok = true;
  91446. for(i = 0; ok && i < encoder->protected_->channels; i++) {
  91447. ok = ok && FLAC__memory_alloc_aligned_int32_array(new_blocksize+4+OVERREAD_, &encoder->private_->integer_signal_unaligned[i], &encoder->private_->integer_signal[i]);
  91448. memset(encoder->private_->integer_signal[i], 0, sizeof(FLAC__int32)*4);
  91449. encoder->private_->integer_signal[i] += 4;
  91450. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  91451. #if 0 /* @@@ currently unused */
  91452. if(encoder->protected_->max_lpc_order > 0)
  91453. ok = ok && FLAC__memory_alloc_aligned_real_array(new_blocksize+OVERREAD_, &encoder->private_->real_signal_unaligned[i], &encoder->private_->real_signal[i]);
  91454. #endif
  91455. #endif
  91456. }
  91457. for(i = 0; ok && i < 2; i++) {
  91458. 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]);
  91459. memset(encoder->private_->integer_signal_mid_side[i], 0, sizeof(FLAC__int32)*4);
  91460. encoder->private_->integer_signal_mid_side[i] += 4;
  91461. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  91462. #if 0 /* @@@ currently unused */
  91463. if(encoder->protected_->max_lpc_order > 0)
  91464. 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]);
  91465. #endif
  91466. #endif
  91467. }
  91468. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  91469. if(ok && encoder->protected_->max_lpc_order > 0) {
  91470. for(i = 0; ok && i < encoder->protected_->num_apodizations; i++)
  91471. ok = ok && FLAC__memory_alloc_aligned_real_array(new_blocksize, &encoder->private_->window_unaligned[i], &encoder->private_->window[i]);
  91472. ok = ok && FLAC__memory_alloc_aligned_real_array(new_blocksize, &encoder->private_->windowed_signal_unaligned, &encoder->private_->windowed_signal);
  91473. }
  91474. #endif
  91475. for(channel = 0; ok && channel < encoder->protected_->channels; channel++) {
  91476. for(i = 0; ok && i < 2; i++) {
  91477. ok = ok && FLAC__memory_alloc_aligned_int32_array(new_blocksize, &encoder->private_->residual_workspace_unaligned[channel][i], &encoder->private_->residual_workspace[channel][i]);
  91478. }
  91479. }
  91480. for(channel = 0; ok && channel < 2; channel++) {
  91481. for(i = 0; ok && i < 2; i++) {
  91482. 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]);
  91483. }
  91484. }
  91485. ok = ok && FLAC__memory_alloc_aligned_uint64_array(new_blocksize * 2, &encoder->private_->abs_residual_partition_sums_unaligned, &encoder->private_->abs_residual_partition_sums);
  91486. if(encoder->protected_->do_escape_coding)
  91487. ok = ok && FLAC__memory_alloc_aligned_unsigned_array(new_blocksize * 2, &encoder->private_->raw_bits_per_partition_unaligned, &encoder->private_->raw_bits_per_partition);
  91488. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  91489. if(ok && new_blocksize != encoder->private_->input_capacity && encoder->protected_->max_lpc_order > 0) {
  91490. for(i = 0; ok && i < encoder->protected_->num_apodizations; i++) {
  91491. switch(encoder->protected_->apodizations[i].type) {
  91492. case FLAC__APODIZATION_BARTLETT:
  91493. FLAC__window_bartlett(encoder->private_->window[i], new_blocksize);
  91494. break;
  91495. case FLAC__APODIZATION_BARTLETT_HANN:
  91496. FLAC__window_bartlett_hann(encoder->private_->window[i], new_blocksize);
  91497. break;
  91498. case FLAC__APODIZATION_BLACKMAN:
  91499. FLAC__window_blackman(encoder->private_->window[i], new_blocksize);
  91500. break;
  91501. case FLAC__APODIZATION_BLACKMAN_HARRIS_4TERM_92DB_SIDELOBE:
  91502. FLAC__window_blackman_harris_4term_92db_sidelobe(encoder->private_->window[i], new_blocksize);
  91503. break;
  91504. case FLAC__APODIZATION_CONNES:
  91505. FLAC__window_connes(encoder->private_->window[i], new_blocksize);
  91506. break;
  91507. case FLAC__APODIZATION_FLATTOP:
  91508. FLAC__window_flattop(encoder->private_->window[i], new_blocksize);
  91509. break;
  91510. case FLAC__APODIZATION_GAUSS:
  91511. FLAC__window_gauss(encoder->private_->window[i], new_blocksize, encoder->protected_->apodizations[i].parameters.gauss.stddev);
  91512. break;
  91513. case FLAC__APODIZATION_HAMMING:
  91514. FLAC__window_hamming(encoder->private_->window[i], new_blocksize);
  91515. break;
  91516. case FLAC__APODIZATION_HANN:
  91517. FLAC__window_hann(encoder->private_->window[i], new_blocksize);
  91518. break;
  91519. case FLAC__APODIZATION_KAISER_BESSEL:
  91520. FLAC__window_kaiser_bessel(encoder->private_->window[i], new_blocksize);
  91521. break;
  91522. case FLAC__APODIZATION_NUTTALL:
  91523. FLAC__window_nuttall(encoder->private_->window[i], new_blocksize);
  91524. break;
  91525. case FLAC__APODIZATION_RECTANGLE:
  91526. FLAC__window_rectangle(encoder->private_->window[i], new_blocksize);
  91527. break;
  91528. case FLAC__APODIZATION_TRIANGLE:
  91529. FLAC__window_triangle(encoder->private_->window[i], new_blocksize);
  91530. break;
  91531. case FLAC__APODIZATION_TUKEY:
  91532. FLAC__window_tukey(encoder->private_->window[i], new_blocksize, encoder->protected_->apodizations[i].parameters.tukey.p);
  91533. break;
  91534. case FLAC__APODIZATION_WELCH:
  91535. FLAC__window_welch(encoder->private_->window[i], new_blocksize);
  91536. break;
  91537. default:
  91538. FLAC__ASSERT(0);
  91539. FLAC__window_hann(encoder->private_->window[i], new_blocksize);
  91540. break;
  91541. }
  91542. }
  91543. }
  91544. #endif
  91545. if(ok)
  91546. encoder->private_->input_capacity = new_blocksize;
  91547. else
  91548. encoder->protected_->state = FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR;
  91549. return ok;
  91550. }
  91551. FLAC__bool write_bitbuffer_(FLAC__StreamEncoder *encoder, unsigned samples, FLAC__bool is_last_block)
  91552. {
  91553. const FLAC__byte *buffer;
  91554. size_t bytes;
  91555. FLAC__ASSERT(FLAC__bitwriter_is_byte_aligned(encoder->private_->frame));
  91556. if(!FLAC__bitwriter_get_buffer(encoder->private_->frame, &buffer, &bytes)) {
  91557. encoder->protected_->state = FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR;
  91558. return false;
  91559. }
  91560. if(encoder->protected_->verify) {
  91561. encoder->private_->verify.output.data = buffer;
  91562. encoder->private_->verify.output.bytes = bytes;
  91563. if(encoder->private_->verify.state_hint == ENCODER_IN_MAGIC) {
  91564. encoder->private_->verify.needs_magic_hack = true;
  91565. }
  91566. else {
  91567. if(!FLAC__stream_decoder_process_single(encoder->private_->verify.decoder)) {
  91568. FLAC__bitwriter_release_buffer(encoder->private_->frame);
  91569. FLAC__bitwriter_clear(encoder->private_->frame);
  91570. if(encoder->protected_->state != FLAC__STREAM_ENCODER_VERIFY_MISMATCH_IN_AUDIO_DATA)
  91571. encoder->protected_->state = FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR;
  91572. return false;
  91573. }
  91574. }
  91575. }
  91576. if(write_frame_(encoder, buffer, bytes, samples, is_last_block) != FLAC__STREAM_ENCODER_WRITE_STATUS_OK) {
  91577. FLAC__bitwriter_release_buffer(encoder->private_->frame);
  91578. FLAC__bitwriter_clear(encoder->private_->frame);
  91579. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  91580. return false;
  91581. }
  91582. FLAC__bitwriter_release_buffer(encoder->private_->frame);
  91583. FLAC__bitwriter_clear(encoder->private_->frame);
  91584. if(samples > 0) {
  91585. encoder->private_->streaminfo.data.stream_info.min_framesize = min(bytes, encoder->private_->streaminfo.data.stream_info.min_framesize);
  91586. encoder->private_->streaminfo.data.stream_info.max_framesize = max(bytes, encoder->private_->streaminfo.data.stream_info.max_framesize);
  91587. }
  91588. return true;
  91589. }
  91590. FLAC__StreamEncoderWriteStatus write_frame_(FLAC__StreamEncoder *encoder, const FLAC__byte buffer[], size_t bytes, unsigned samples, FLAC__bool is_last_block)
  91591. {
  91592. FLAC__StreamEncoderWriteStatus status;
  91593. FLAC__uint64 output_position = 0;
  91594. if(encoder->private_->tell_callback && encoder->private_->tell_callback(encoder, &output_position, encoder->private_->client_data) == FLAC__STREAM_ENCODER_TELL_STATUS_ERROR) {
  91595. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  91596. return FLAC__STREAM_ENCODER_WRITE_STATUS_FATAL_ERROR;
  91597. }
  91598. if(samples == 0) {
  91599. FLAC__MetadataType type = (FLAC__MetadataType) (buffer[0] & 0x7f);
  91600. if(type == FLAC__METADATA_TYPE_STREAMINFO)
  91601. encoder->protected_->streaminfo_offset = output_position;
  91602. else if(type == FLAC__METADATA_TYPE_SEEKTABLE && encoder->protected_->seektable_offset == 0)
  91603. encoder->protected_->seektable_offset = output_position;
  91604. }
  91605. if(0 != encoder->private_->seek_table && encoder->protected_->audio_offset > 0 && encoder->private_->seek_table->num_points > 0) {
  91606. const unsigned blocksize = FLAC__stream_encoder_get_blocksize(encoder);
  91607. const FLAC__uint64 frame_first_sample = encoder->private_->samples_written;
  91608. const FLAC__uint64 frame_last_sample = frame_first_sample + (FLAC__uint64)blocksize - 1;
  91609. FLAC__uint64 test_sample;
  91610. unsigned i;
  91611. for(i = encoder->private_->first_seekpoint_to_check; i < encoder->private_->seek_table->num_points; i++) {
  91612. test_sample = encoder->private_->seek_table->points[i].sample_number;
  91613. if(test_sample > frame_last_sample) {
  91614. break;
  91615. }
  91616. else if(test_sample >= frame_first_sample) {
  91617. encoder->private_->seek_table->points[i].sample_number = frame_first_sample;
  91618. encoder->private_->seek_table->points[i].stream_offset = output_position - encoder->protected_->audio_offset;
  91619. encoder->private_->seek_table->points[i].frame_samples = blocksize;
  91620. encoder->private_->first_seekpoint_to_check++;
  91621. }
  91622. else {
  91623. encoder->private_->first_seekpoint_to_check++;
  91624. }
  91625. }
  91626. }
  91627. #if FLAC__HAS_OGG
  91628. if(encoder->private_->is_ogg) {
  91629. status = FLAC__ogg_encoder_aspect_write_callback_wrapper(
  91630. &encoder->protected_->ogg_encoder_aspect,
  91631. buffer,
  91632. bytes,
  91633. samples,
  91634. encoder->private_->current_frame_number,
  91635. is_last_block,
  91636. (FLAC__OggEncoderAspectWriteCallbackProxy)encoder->private_->write_callback,
  91637. encoder,
  91638. encoder->private_->client_data
  91639. );
  91640. }
  91641. else
  91642. #endif
  91643. status = encoder->private_->write_callback(encoder, buffer, bytes, samples, encoder->private_->current_frame_number, encoder->private_->client_data);
  91644. if(status == FLAC__STREAM_ENCODER_WRITE_STATUS_OK) {
  91645. encoder->private_->bytes_written += bytes;
  91646. encoder->private_->samples_written += samples;
  91647. encoder->private_->frames_written = max(encoder->private_->frames_written, encoder->private_->current_frame_number+1);
  91648. }
  91649. else
  91650. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  91651. return status;
  91652. }
  91653. void update_metadata_(const FLAC__StreamEncoder *encoder)
  91654. {
  91655. FLAC__byte b[max(6, FLAC__STREAM_METADATA_SEEKPOINT_LENGTH)];
  91656. const FLAC__StreamMetadata *metadata = &encoder->private_->streaminfo;
  91657. const FLAC__uint64 samples = metadata->data.stream_info.total_samples;
  91658. const unsigned min_framesize = metadata->data.stream_info.min_framesize;
  91659. const unsigned max_framesize = metadata->data.stream_info.max_framesize;
  91660. const unsigned bps = metadata->data.stream_info.bits_per_sample;
  91661. FLAC__StreamEncoderSeekStatus seek_status;
  91662. FLAC__ASSERT(metadata->type == FLAC__METADATA_TYPE_STREAMINFO);
  91663. {
  91664. const unsigned md5_offset =
  91665. FLAC__STREAM_METADATA_HEADER_LENGTH +
  91666. (
  91667. FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN +
  91668. FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN +
  91669. FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN +
  91670. FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN +
  91671. FLAC__STREAM_METADATA_STREAMINFO_SAMPLE_RATE_LEN +
  91672. FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN +
  91673. FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN +
  91674. FLAC__STREAM_METADATA_STREAMINFO_TOTAL_SAMPLES_LEN
  91675. ) / 8;
  91676. if((seek_status = encoder->private_->seek_callback(encoder, encoder->protected_->streaminfo_offset + md5_offset, encoder->private_->client_data)) != FLAC__STREAM_ENCODER_SEEK_STATUS_OK) {
  91677. if(seek_status == FLAC__STREAM_ENCODER_SEEK_STATUS_ERROR)
  91678. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  91679. return;
  91680. }
  91681. if(encoder->private_->write_callback(encoder, metadata->data.stream_info.md5sum, 16, 0, 0, encoder->private_->client_data) != FLAC__STREAM_ENCODER_WRITE_STATUS_OK) {
  91682. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  91683. return;
  91684. }
  91685. }
  91686. {
  91687. const unsigned total_samples_byte_offset =
  91688. FLAC__STREAM_METADATA_HEADER_LENGTH +
  91689. (
  91690. FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN +
  91691. FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN +
  91692. FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN +
  91693. FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN +
  91694. FLAC__STREAM_METADATA_STREAMINFO_SAMPLE_RATE_LEN +
  91695. FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN +
  91696. FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN
  91697. - 4
  91698. ) / 8;
  91699. b[0] = ((FLAC__byte)(bps-1) << 4) | (FLAC__byte)((samples >> 32) & 0x0F);
  91700. b[1] = (FLAC__byte)((samples >> 24) & 0xFF);
  91701. b[2] = (FLAC__byte)((samples >> 16) & 0xFF);
  91702. b[3] = (FLAC__byte)((samples >> 8) & 0xFF);
  91703. b[4] = (FLAC__byte)(samples & 0xFF);
  91704. 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) {
  91705. if(seek_status == FLAC__STREAM_ENCODER_SEEK_STATUS_ERROR)
  91706. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  91707. return;
  91708. }
  91709. if(encoder->private_->write_callback(encoder, b, 5, 0, 0, encoder->private_->client_data) != FLAC__STREAM_ENCODER_WRITE_STATUS_OK) {
  91710. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  91711. return;
  91712. }
  91713. }
  91714. {
  91715. const unsigned min_framesize_offset =
  91716. FLAC__STREAM_METADATA_HEADER_LENGTH +
  91717. (
  91718. FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN +
  91719. FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN
  91720. ) / 8;
  91721. b[0] = (FLAC__byte)((min_framesize >> 16) & 0xFF);
  91722. b[1] = (FLAC__byte)((min_framesize >> 8) & 0xFF);
  91723. b[2] = (FLAC__byte)(min_framesize & 0xFF);
  91724. b[3] = (FLAC__byte)((max_framesize >> 16) & 0xFF);
  91725. b[4] = (FLAC__byte)((max_framesize >> 8) & 0xFF);
  91726. b[5] = (FLAC__byte)(max_framesize & 0xFF);
  91727. 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) {
  91728. if(seek_status == FLAC__STREAM_ENCODER_SEEK_STATUS_ERROR)
  91729. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  91730. return;
  91731. }
  91732. if(encoder->private_->write_callback(encoder, b, 6, 0, 0, encoder->private_->client_data) != FLAC__STREAM_ENCODER_WRITE_STATUS_OK) {
  91733. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  91734. return;
  91735. }
  91736. }
  91737. if(0 != encoder->private_->seek_table && encoder->private_->seek_table->num_points > 0 && encoder->protected_->seektable_offset > 0) {
  91738. unsigned i;
  91739. FLAC__format_seektable_sort(encoder->private_->seek_table);
  91740. FLAC__ASSERT(FLAC__format_seektable_is_legal(encoder->private_->seek_table));
  91741. 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) {
  91742. if(seek_status == FLAC__STREAM_ENCODER_SEEK_STATUS_ERROR)
  91743. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  91744. return;
  91745. }
  91746. for(i = 0; i < encoder->private_->seek_table->num_points; i++) {
  91747. FLAC__uint64 xx;
  91748. unsigned x;
  91749. xx = encoder->private_->seek_table->points[i].sample_number;
  91750. b[7] = (FLAC__byte)xx; xx >>= 8;
  91751. b[6] = (FLAC__byte)xx; xx >>= 8;
  91752. b[5] = (FLAC__byte)xx; xx >>= 8;
  91753. b[4] = (FLAC__byte)xx; xx >>= 8;
  91754. b[3] = (FLAC__byte)xx; xx >>= 8;
  91755. b[2] = (FLAC__byte)xx; xx >>= 8;
  91756. b[1] = (FLAC__byte)xx; xx >>= 8;
  91757. b[0] = (FLAC__byte)xx; xx >>= 8;
  91758. xx = encoder->private_->seek_table->points[i].stream_offset;
  91759. b[15] = (FLAC__byte)xx; xx >>= 8;
  91760. b[14] = (FLAC__byte)xx; xx >>= 8;
  91761. b[13] = (FLAC__byte)xx; xx >>= 8;
  91762. b[12] = (FLAC__byte)xx; xx >>= 8;
  91763. b[11] = (FLAC__byte)xx; xx >>= 8;
  91764. b[10] = (FLAC__byte)xx; xx >>= 8;
  91765. b[9] = (FLAC__byte)xx; xx >>= 8;
  91766. b[8] = (FLAC__byte)xx; xx >>= 8;
  91767. x = encoder->private_->seek_table->points[i].frame_samples;
  91768. b[17] = (FLAC__byte)x; x >>= 8;
  91769. b[16] = (FLAC__byte)x; x >>= 8;
  91770. if(encoder->private_->write_callback(encoder, b, 18, 0, 0, encoder->private_->client_data) != FLAC__STREAM_ENCODER_WRITE_STATUS_OK) {
  91771. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  91772. return;
  91773. }
  91774. }
  91775. }
  91776. }
  91777. #if FLAC__HAS_OGG
  91778. void update_ogg_metadata_(FLAC__StreamEncoder *encoder)
  91779. {
  91780. static const unsigned FIRST_OGG_PACKET_STREAMINFO_PREFIX_LENGTH =
  91781. FLAC__OGG_MAPPING_PACKET_TYPE_LENGTH +
  91782. FLAC__OGG_MAPPING_MAGIC_LENGTH +
  91783. FLAC__OGG_MAPPING_VERSION_MAJOR_LENGTH +
  91784. FLAC__OGG_MAPPING_VERSION_MINOR_LENGTH +
  91785. FLAC__OGG_MAPPING_NUM_HEADERS_LENGTH +
  91786. FLAC__STREAM_SYNC_LENGTH
  91787. ;
  91788. FLAC__byte b[max(6, FLAC__STREAM_METADATA_SEEKPOINT_LENGTH)];
  91789. const FLAC__StreamMetadata *metadata = &encoder->private_->streaminfo;
  91790. const FLAC__uint64 samples = metadata->data.stream_info.total_samples;
  91791. const unsigned min_framesize = metadata->data.stream_info.min_framesize;
  91792. const unsigned max_framesize = metadata->data.stream_info.max_framesize;
  91793. ogg_page page;
  91794. FLAC__ASSERT(metadata->type == FLAC__METADATA_TYPE_STREAMINFO);
  91795. FLAC__ASSERT(0 != encoder->private_->seek_callback);
  91796. if(encoder->private_->seek_callback(encoder, 0, encoder->private_->client_data) == FLAC__STREAM_ENCODER_SEEK_STATUS_UNSUPPORTED)
  91797. return;
  91798. simple_ogg_page__init(&page);
  91799. if(!simple_ogg_page__get_at(encoder, encoder->protected_->streaminfo_offset, &page, encoder->private_->seek_callback, encoder->private_->read_callback, encoder->private_->client_data)) {
  91800. simple_ogg_page__clear(&page);
  91801. return; /* state already set */
  91802. }
  91803. {
  91804. const unsigned md5_offset =
  91805. FIRST_OGG_PACKET_STREAMINFO_PREFIX_LENGTH +
  91806. FLAC__STREAM_METADATA_HEADER_LENGTH +
  91807. (
  91808. FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN +
  91809. FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN +
  91810. FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN +
  91811. FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN +
  91812. FLAC__STREAM_METADATA_STREAMINFO_SAMPLE_RATE_LEN +
  91813. FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN +
  91814. FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN +
  91815. FLAC__STREAM_METADATA_STREAMINFO_TOTAL_SAMPLES_LEN
  91816. ) / 8;
  91817. if(md5_offset + 16 > (unsigned)page.body_len) {
  91818. encoder->protected_->state = FLAC__STREAM_ENCODER_OGG_ERROR;
  91819. simple_ogg_page__clear(&page);
  91820. return;
  91821. }
  91822. memcpy(page.body + md5_offset, metadata->data.stream_info.md5sum, 16);
  91823. }
  91824. {
  91825. const unsigned total_samples_byte_offset =
  91826. FIRST_OGG_PACKET_STREAMINFO_PREFIX_LENGTH +
  91827. FLAC__STREAM_METADATA_HEADER_LENGTH +
  91828. (
  91829. FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN +
  91830. FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN +
  91831. FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN +
  91832. FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN +
  91833. FLAC__STREAM_METADATA_STREAMINFO_SAMPLE_RATE_LEN +
  91834. FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN +
  91835. FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN
  91836. - 4
  91837. ) / 8;
  91838. if(total_samples_byte_offset + 5 > (unsigned)page.body_len) {
  91839. encoder->protected_->state = FLAC__STREAM_ENCODER_OGG_ERROR;
  91840. simple_ogg_page__clear(&page);
  91841. return;
  91842. }
  91843. b[0] = (FLAC__byte)page.body[total_samples_byte_offset] & 0xF0;
  91844. b[0] |= (FLAC__byte)((samples >> 32) & 0x0F);
  91845. b[1] = (FLAC__byte)((samples >> 24) & 0xFF);
  91846. b[2] = (FLAC__byte)((samples >> 16) & 0xFF);
  91847. b[3] = (FLAC__byte)((samples >> 8) & 0xFF);
  91848. b[4] = (FLAC__byte)(samples & 0xFF);
  91849. memcpy(page.body + total_samples_byte_offset, b, 5);
  91850. }
  91851. {
  91852. const unsigned min_framesize_offset =
  91853. FIRST_OGG_PACKET_STREAMINFO_PREFIX_LENGTH +
  91854. FLAC__STREAM_METADATA_HEADER_LENGTH +
  91855. (
  91856. FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN +
  91857. FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN
  91858. ) / 8;
  91859. if(min_framesize_offset + 6 > (unsigned)page.body_len) {
  91860. encoder->protected_->state = FLAC__STREAM_ENCODER_OGG_ERROR;
  91861. simple_ogg_page__clear(&page);
  91862. return;
  91863. }
  91864. b[0] = (FLAC__byte)((min_framesize >> 16) & 0xFF);
  91865. b[1] = (FLAC__byte)((min_framesize >> 8) & 0xFF);
  91866. b[2] = (FLAC__byte)(min_framesize & 0xFF);
  91867. b[3] = (FLAC__byte)((max_framesize >> 16) & 0xFF);
  91868. b[4] = (FLAC__byte)((max_framesize >> 8) & 0xFF);
  91869. b[5] = (FLAC__byte)(max_framesize & 0xFF);
  91870. memcpy(page.body + min_framesize_offset, b, 6);
  91871. }
  91872. if(!simple_ogg_page__set_at(encoder, encoder->protected_->streaminfo_offset, &page, encoder->private_->seek_callback, encoder->private_->write_callback, encoder->private_->client_data)) {
  91873. simple_ogg_page__clear(&page);
  91874. return; /* state already set */
  91875. }
  91876. simple_ogg_page__clear(&page);
  91877. if(0 != encoder->private_->seek_table && encoder->private_->seek_table->num_points > 0 && encoder->protected_->seektable_offset > 0) {
  91878. unsigned i;
  91879. FLAC__byte *p;
  91880. FLAC__format_seektable_sort(encoder->private_->seek_table);
  91881. FLAC__ASSERT(FLAC__format_seektable_is_legal(encoder->private_->seek_table));
  91882. simple_ogg_page__init(&page);
  91883. if(!simple_ogg_page__get_at(encoder, encoder->protected_->seektable_offset, &page, encoder->private_->seek_callback, encoder->private_->read_callback, encoder->private_->client_data)) {
  91884. simple_ogg_page__clear(&page);
  91885. return; /* state already set */
  91886. }
  91887. if((FLAC__STREAM_METADATA_HEADER_LENGTH + 18*encoder->private_->seek_table->num_points) != (unsigned)page.body_len) {
  91888. encoder->protected_->state = FLAC__STREAM_ENCODER_OGG_ERROR;
  91889. simple_ogg_page__clear(&page);
  91890. return;
  91891. }
  91892. for(i = 0, p = page.body + FLAC__STREAM_METADATA_HEADER_LENGTH; i < encoder->private_->seek_table->num_points; i++, p += 18) {
  91893. FLAC__uint64 xx;
  91894. unsigned x;
  91895. xx = encoder->private_->seek_table->points[i].sample_number;
  91896. b[7] = (FLAC__byte)xx; xx >>= 8;
  91897. b[6] = (FLAC__byte)xx; xx >>= 8;
  91898. b[5] = (FLAC__byte)xx; xx >>= 8;
  91899. b[4] = (FLAC__byte)xx; xx >>= 8;
  91900. b[3] = (FLAC__byte)xx; xx >>= 8;
  91901. b[2] = (FLAC__byte)xx; xx >>= 8;
  91902. b[1] = (FLAC__byte)xx; xx >>= 8;
  91903. b[0] = (FLAC__byte)xx; xx >>= 8;
  91904. xx = encoder->private_->seek_table->points[i].stream_offset;
  91905. b[15] = (FLAC__byte)xx; xx >>= 8;
  91906. b[14] = (FLAC__byte)xx; xx >>= 8;
  91907. b[13] = (FLAC__byte)xx; xx >>= 8;
  91908. b[12] = (FLAC__byte)xx; xx >>= 8;
  91909. b[11] = (FLAC__byte)xx; xx >>= 8;
  91910. b[10] = (FLAC__byte)xx; xx >>= 8;
  91911. b[9] = (FLAC__byte)xx; xx >>= 8;
  91912. b[8] = (FLAC__byte)xx; xx >>= 8;
  91913. x = encoder->private_->seek_table->points[i].frame_samples;
  91914. b[17] = (FLAC__byte)x; x >>= 8;
  91915. b[16] = (FLAC__byte)x; x >>= 8;
  91916. memcpy(p, b, 18);
  91917. }
  91918. if(!simple_ogg_page__set_at(encoder, encoder->protected_->seektable_offset, &page, encoder->private_->seek_callback, encoder->private_->write_callback, encoder->private_->client_data)) {
  91919. simple_ogg_page__clear(&page);
  91920. return; /* state already set */
  91921. }
  91922. simple_ogg_page__clear(&page);
  91923. }
  91924. }
  91925. #endif
  91926. FLAC__bool process_frame_(FLAC__StreamEncoder *encoder, FLAC__bool is_fractional_block, FLAC__bool is_last_block)
  91927. {
  91928. FLAC__uint16 crc;
  91929. FLAC__ASSERT(encoder->protected_->state == FLAC__STREAM_ENCODER_OK);
  91930. 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)) {
  91931. encoder->protected_->state = FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR;
  91932. return false;
  91933. }
  91934. if(!process_subframes_(encoder, is_fractional_block)) {
  91935. return false;
  91936. }
  91937. if(!FLAC__bitwriter_zero_pad_to_byte_boundary(encoder->private_->frame)) {
  91938. encoder->protected_->state = FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR;
  91939. return false;
  91940. }
  91941. FLAC__ASSERT(FLAC__bitwriter_is_byte_aligned(encoder->private_->frame));
  91942. if(
  91943. !FLAC__bitwriter_get_write_crc16(encoder->private_->frame, &crc) ||
  91944. !FLAC__bitwriter_write_raw_uint32(encoder->private_->frame, crc, FLAC__FRAME_FOOTER_CRC_LEN)
  91945. ) {
  91946. encoder->protected_->state = FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR;
  91947. return false;
  91948. }
  91949. if(!write_bitbuffer_(encoder, encoder->protected_->blocksize, is_last_block)) {
  91950. return false;
  91951. }
  91952. encoder->private_->current_sample_number = 0;
  91953. encoder->private_->current_frame_number++;
  91954. encoder->private_->streaminfo.data.stream_info.total_samples += (FLAC__uint64)encoder->protected_->blocksize;
  91955. return true;
  91956. }
  91957. FLAC__bool process_subframes_(FLAC__StreamEncoder *encoder, FLAC__bool is_fractional_block)
  91958. {
  91959. FLAC__FrameHeader frame_header;
  91960. unsigned channel, min_partition_order = encoder->protected_->min_residual_partition_order, max_partition_order;
  91961. FLAC__bool do_independent, do_mid_side;
  91962. if(is_fractional_block) {
  91963. max_partition_order = 0;
  91964. }
  91965. else {
  91966. max_partition_order = FLAC__format_get_max_rice_partition_order_from_blocksize(encoder->protected_->blocksize);
  91967. max_partition_order = min(max_partition_order, encoder->protected_->max_residual_partition_order);
  91968. }
  91969. min_partition_order = min(min_partition_order, max_partition_order);
  91970. frame_header.blocksize = encoder->protected_->blocksize;
  91971. frame_header.sample_rate = encoder->protected_->sample_rate;
  91972. frame_header.channels = encoder->protected_->channels;
  91973. frame_header.channel_assignment = FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT; /* the default unless the encoder determines otherwise */
  91974. frame_header.bits_per_sample = encoder->protected_->bits_per_sample;
  91975. frame_header.number_type = FLAC__FRAME_NUMBER_TYPE_FRAME_NUMBER;
  91976. frame_header.number.frame_number = encoder->private_->current_frame_number;
  91977. if(encoder->protected_->do_mid_side_stereo) {
  91978. if(encoder->protected_->loose_mid_side_stereo) {
  91979. if(encoder->private_->loose_mid_side_stereo_frame_count == 0) {
  91980. do_independent = true;
  91981. do_mid_side = true;
  91982. }
  91983. else {
  91984. do_independent = (encoder->private_->last_channel_assignment == FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT);
  91985. do_mid_side = !do_independent;
  91986. }
  91987. }
  91988. else {
  91989. do_independent = true;
  91990. do_mid_side = true;
  91991. }
  91992. }
  91993. else {
  91994. do_independent = true;
  91995. do_mid_side = false;
  91996. }
  91997. FLAC__ASSERT(do_independent || do_mid_side);
  91998. if(do_independent) {
  91999. for(channel = 0; channel < encoder->protected_->channels; channel++) {
  92000. const unsigned w = get_wasted_bits_(encoder->private_->integer_signal[channel], encoder->protected_->blocksize);
  92001. encoder->private_->subframe_workspace[channel][0].wasted_bits = encoder->private_->subframe_workspace[channel][1].wasted_bits = w;
  92002. encoder->private_->subframe_bps[channel] = encoder->protected_->bits_per_sample - w;
  92003. }
  92004. }
  92005. if(do_mid_side) {
  92006. FLAC__ASSERT(encoder->protected_->channels == 2);
  92007. for(channel = 0; channel < 2; channel++) {
  92008. const unsigned w = get_wasted_bits_(encoder->private_->integer_signal_mid_side[channel], encoder->protected_->blocksize);
  92009. encoder->private_->subframe_workspace_mid_side[channel][0].wasted_bits = encoder->private_->subframe_workspace_mid_side[channel][1].wasted_bits = w;
  92010. encoder->private_->subframe_bps_mid_side[channel] = encoder->protected_->bits_per_sample - w + (channel==0? 0:1);
  92011. }
  92012. }
  92013. if(do_independent) {
  92014. for(channel = 0; channel < encoder->protected_->channels; channel++) {
  92015. if(!
  92016. process_subframe_(
  92017. encoder,
  92018. min_partition_order,
  92019. max_partition_order,
  92020. &frame_header,
  92021. encoder->private_->subframe_bps[channel],
  92022. encoder->private_->integer_signal[channel],
  92023. encoder->private_->subframe_workspace_ptr[channel],
  92024. encoder->private_->partitioned_rice_contents_workspace_ptr[channel],
  92025. encoder->private_->residual_workspace[channel],
  92026. encoder->private_->best_subframe+channel,
  92027. encoder->private_->best_subframe_bits+channel
  92028. )
  92029. )
  92030. return false;
  92031. }
  92032. }
  92033. if(do_mid_side) {
  92034. FLAC__ASSERT(encoder->protected_->channels == 2);
  92035. for(channel = 0; channel < 2; channel++) {
  92036. if(!
  92037. process_subframe_(
  92038. encoder,
  92039. min_partition_order,
  92040. max_partition_order,
  92041. &frame_header,
  92042. encoder->private_->subframe_bps_mid_side[channel],
  92043. encoder->private_->integer_signal_mid_side[channel],
  92044. encoder->private_->subframe_workspace_ptr_mid_side[channel],
  92045. encoder->private_->partitioned_rice_contents_workspace_ptr_mid_side[channel],
  92046. encoder->private_->residual_workspace_mid_side[channel],
  92047. encoder->private_->best_subframe_mid_side+channel,
  92048. encoder->private_->best_subframe_bits_mid_side+channel
  92049. )
  92050. )
  92051. return false;
  92052. }
  92053. }
  92054. if(do_mid_side) {
  92055. unsigned left_bps = 0, right_bps = 0; /* initialized only to prevent superfluous compiler warning */
  92056. FLAC__Subframe *left_subframe = 0, *right_subframe = 0; /* initialized only to prevent superfluous compiler warning */
  92057. FLAC__ChannelAssignment channel_assignment;
  92058. FLAC__ASSERT(encoder->protected_->channels == 2);
  92059. if(encoder->protected_->loose_mid_side_stereo && encoder->private_->loose_mid_side_stereo_frame_count > 0) {
  92060. channel_assignment = (encoder->private_->last_channel_assignment == FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT? FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT : FLAC__CHANNEL_ASSIGNMENT_MID_SIDE);
  92061. }
  92062. else {
  92063. unsigned bits[4]; /* WATCHOUT - indexed by FLAC__ChannelAssignment */
  92064. unsigned min_bits;
  92065. int ca;
  92066. FLAC__ASSERT(FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT == 0);
  92067. FLAC__ASSERT(FLAC__CHANNEL_ASSIGNMENT_LEFT_SIDE == 1);
  92068. FLAC__ASSERT(FLAC__CHANNEL_ASSIGNMENT_RIGHT_SIDE == 2);
  92069. FLAC__ASSERT(FLAC__CHANNEL_ASSIGNMENT_MID_SIDE == 3);
  92070. FLAC__ASSERT(do_independent && do_mid_side);
  92071. bits[FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT] = encoder->private_->best_subframe_bits [0] + encoder->private_->best_subframe_bits [1];
  92072. bits[FLAC__CHANNEL_ASSIGNMENT_LEFT_SIDE ] = encoder->private_->best_subframe_bits [0] + encoder->private_->best_subframe_bits_mid_side[1];
  92073. bits[FLAC__CHANNEL_ASSIGNMENT_RIGHT_SIDE ] = encoder->private_->best_subframe_bits [1] + encoder->private_->best_subframe_bits_mid_side[1];
  92074. bits[FLAC__CHANNEL_ASSIGNMENT_MID_SIDE ] = encoder->private_->best_subframe_bits_mid_side[0] + encoder->private_->best_subframe_bits_mid_side[1];
  92075. channel_assignment = FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT;
  92076. min_bits = bits[channel_assignment];
  92077. for(ca = 1; ca <= 3; ca++) {
  92078. if(bits[ca] < min_bits) {
  92079. min_bits = bits[ca];
  92080. channel_assignment = (FLAC__ChannelAssignment)ca;
  92081. }
  92082. }
  92083. }
  92084. frame_header.channel_assignment = channel_assignment;
  92085. if(!FLAC__frame_add_header(&frame_header, encoder->private_->frame)) {
  92086. encoder->protected_->state = FLAC__STREAM_ENCODER_FRAMING_ERROR;
  92087. return false;
  92088. }
  92089. switch(channel_assignment) {
  92090. case FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT:
  92091. left_subframe = &encoder->private_->subframe_workspace [0][encoder->private_->best_subframe [0]];
  92092. right_subframe = &encoder->private_->subframe_workspace [1][encoder->private_->best_subframe [1]];
  92093. break;
  92094. case FLAC__CHANNEL_ASSIGNMENT_LEFT_SIDE:
  92095. left_subframe = &encoder->private_->subframe_workspace [0][encoder->private_->best_subframe [0]];
  92096. right_subframe = &encoder->private_->subframe_workspace_mid_side[1][encoder->private_->best_subframe_mid_side[1]];
  92097. break;
  92098. case FLAC__CHANNEL_ASSIGNMENT_RIGHT_SIDE:
  92099. left_subframe = &encoder->private_->subframe_workspace_mid_side[1][encoder->private_->best_subframe_mid_side[1]];
  92100. right_subframe = &encoder->private_->subframe_workspace [1][encoder->private_->best_subframe [1]];
  92101. break;
  92102. case FLAC__CHANNEL_ASSIGNMENT_MID_SIDE:
  92103. left_subframe = &encoder->private_->subframe_workspace_mid_side[0][encoder->private_->best_subframe_mid_side[0]];
  92104. right_subframe = &encoder->private_->subframe_workspace_mid_side[1][encoder->private_->best_subframe_mid_side[1]];
  92105. break;
  92106. default:
  92107. FLAC__ASSERT(0);
  92108. }
  92109. switch(channel_assignment) {
  92110. case FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT:
  92111. left_bps = encoder->private_->subframe_bps [0];
  92112. right_bps = encoder->private_->subframe_bps [1];
  92113. break;
  92114. case FLAC__CHANNEL_ASSIGNMENT_LEFT_SIDE:
  92115. left_bps = encoder->private_->subframe_bps [0];
  92116. right_bps = encoder->private_->subframe_bps_mid_side[1];
  92117. break;
  92118. case FLAC__CHANNEL_ASSIGNMENT_RIGHT_SIDE:
  92119. left_bps = encoder->private_->subframe_bps_mid_side[1];
  92120. right_bps = encoder->private_->subframe_bps [1];
  92121. break;
  92122. case FLAC__CHANNEL_ASSIGNMENT_MID_SIDE:
  92123. left_bps = encoder->private_->subframe_bps_mid_side[0];
  92124. right_bps = encoder->private_->subframe_bps_mid_side[1];
  92125. break;
  92126. default:
  92127. FLAC__ASSERT(0);
  92128. }
  92129. if(!add_subframe_(encoder, frame_header.blocksize, left_bps , left_subframe , encoder->private_->frame))
  92130. return false;
  92131. if(!add_subframe_(encoder, frame_header.blocksize, right_bps, right_subframe, encoder->private_->frame))
  92132. return false;
  92133. }
  92134. else {
  92135. if(!FLAC__frame_add_header(&frame_header, encoder->private_->frame)) {
  92136. encoder->protected_->state = FLAC__STREAM_ENCODER_FRAMING_ERROR;
  92137. return false;
  92138. }
  92139. for(channel = 0; channel < encoder->protected_->channels; channel++) {
  92140. 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)) {
  92141. return false;
  92142. }
  92143. }
  92144. }
  92145. if(encoder->protected_->loose_mid_side_stereo) {
  92146. encoder->private_->loose_mid_side_stereo_frame_count++;
  92147. if(encoder->private_->loose_mid_side_stereo_frame_count >= encoder->private_->loose_mid_side_stereo_frames)
  92148. encoder->private_->loose_mid_side_stereo_frame_count = 0;
  92149. }
  92150. encoder->private_->last_channel_assignment = frame_header.channel_assignment;
  92151. return true;
  92152. }
  92153. FLAC__bool process_subframe_(
  92154. FLAC__StreamEncoder *encoder,
  92155. unsigned min_partition_order,
  92156. unsigned max_partition_order,
  92157. const FLAC__FrameHeader *frame_header,
  92158. unsigned subframe_bps,
  92159. const FLAC__int32 integer_signal[],
  92160. FLAC__Subframe *subframe[2],
  92161. FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents[2],
  92162. FLAC__int32 *residual[2],
  92163. unsigned *best_subframe,
  92164. unsigned *best_bits
  92165. )
  92166. {
  92167. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  92168. FLAC__float fixed_residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1];
  92169. #else
  92170. FLAC__fixedpoint fixed_residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1];
  92171. #endif
  92172. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  92173. FLAC__double lpc_residual_bits_per_sample;
  92174. 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 */
  92175. FLAC__double lpc_error[FLAC__MAX_LPC_ORDER];
  92176. unsigned min_lpc_order, max_lpc_order, lpc_order;
  92177. unsigned min_qlp_coeff_precision, max_qlp_coeff_precision, qlp_coeff_precision;
  92178. #endif
  92179. unsigned min_fixed_order, max_fixed_order, guess_fixed_order, fixed_order;
  92180. unsigned rice_parameter;
  92181. unsigned _candidate_bits, _best_bits;
  92182. unsigned _best_subframe;
  92183. 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;
  92184. FLAC__ASSERT(frame_header->blocksize > 0);
  92185. _best_subframe = 0;
  92186. if(encoder->private_->disable_verbatim_subframes && frame_header->blocksize >= FLAC__MAX_FIXED_ORDER)
  92187. _best_bits = UINT_MAX;
  92188. else
  92189. _best_bits = evaluate_verbatim_subframe_(encoder, integer_signal, frame_header->blocksize, subframe_bps, subframe[_best_subframe]);
  92190. if(frame_header->blocksize >= FLAC__MAX_FIXED_ORDER) {
  92191. unsigned signal_is_constant = false;
  92192. 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);
  92193. if(
  92194. !encoder->private_->disable_constant_subframes &&
  92195. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  92196. fixed_residual_bits_per_sample[1] == 0.0
  92197. #else
  92198. fixed_residual_bits_per_sample[1] == FLAC__FP_ZERO
  92199. #endif
  92200. ) {
  92201. unsigned i;
  92202. signal_is_constant = true;
  92203. for(i = 1; i < frame_header->blocksize; i++) {
  92204. if(integer_signal[0] != integer_signal[i]) {
  92205. signal_is_constant = false;
  92206. break;
  92207. }
  92208. }
  92209. }
  92210. if(signal_is_constant) {
  92211. _candidate_bits = evaluate_constant_subframe_(encoder, integer_signal[0], frame_header->blocksize, subframe_bps, subframe[!_best_subframe]);
  92212. if(_candidate_bits < _best_bits) {
  92213. _best_subframe = !_best_subframe;
  92214. _best_bits = _candidate_bits;
  92215. }
  92216. }
  92217. else {
  92218. if(!encoder->private_->disable_fixed_subframes || (encoder->protected_->max_lpc_order == 0 && _best_bits == UINT_MAX)) {
  92219. if(encoder->protected_->do_exhaustive_model_search) {
  92220. min_fixed_order = 0;
  92221. max_fixed_order = FLAC__MAX_FIXED_ORDER;
  92222. }
  92223. else {
  92224. min_fixed_order = max_fixed_order = guess_fixed_order;
  92225. }
  92226. if(max_fixed_order >= frame_header->blocksize)
  92227. max_fixed_order = frame_header->blocksize - 1;
  92228. for(fixed_order = min_fixed_order; fixed_order <= max_fixed_order; fixed_order++) {
  92229. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  92230. if(fixed_residual_bits_per_sample[fixed_order] >= (FLAC__float)subframe_bps)
  92231. continue; /* don't even try */
  92232. 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 */
  92233. #else
  92234. if(FLAC__fixedpoint_trunc(fixed_residual_bits_per_sample[fixed_order]) >= (int)subframe_bps)
  92235. continue; /* don't even try */
  92236. 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 */
  92237. #endif
  92238. rice_parameter++; /* to account for the signed->unsigned conversion during rice coding */
  92239. if(rice_parameter >= rice_parameter_limit) {
  92240. #ifdef DEBUG_VERBOSE
  92241. fprintf(stderr, "clipping rice_parameter (%u -> %u) @0\n", rice_parameter, rice_parameter_limit - 1);
  92242. #endif
  92243. rice_parameter = rice_parameter_limit - 1;
  92244. }
  92245. _candidate_bits =
  92246. evaluate_fixed_subframe_(
  92247. encoder,
  92248. integer_signal,
  92249. residual[!_best_subframe],
  92250. encoder->private_->abs_residual_partition_sums,
  92251. encoder->private_->raw_bits_per_partition,
  92252. frame_header->blocksize,
  92253. subframe_bps,
  92254. fixed_order,
  92255. rice_parameter,
  92256. rice_parameter_limit,
  92257. min_partition_order,
  92258. max_partition_order,
  92259. encoder->protected_->do_escape_coding,
  92260. encoder->protected_->rice_parameter_search_dist,
  92261. subframe[!_best_subframe],
  92262. partitioned_rice_contents[!_best_subframe]
  92263. );
  92264. if(_candidate_bits < _best_bits) {
  92265. _best_subframe = !_best_subframe;
  92266. _best_bits = _candidate_bits;
  92267. }
  92268. }
  92269. }
  92270. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  92271. if(encoder->protected_->max_lpc_order > 0) {
  92272. if(encoder->protected_->max_lpc_order >= frame_header->blocksize)
  92273. max_lpc_order = frame_header->blocksize-1;
  92274. else
  92275. max_lpc_order = encoder->protected_->max_lpc_order;
  92276. if(max_lpc_order > 0) {
  92277. unsigned a;
  92278. for (a = 0; a < encoder->protected_->num_apodizations; a++) {
  92279. FLAC__lpc_window_data(integer_signal, encoder->private_->window[a], encoder->private_->windowed_signal, frame_header->blocksize);
  92280. encoder->private_->local_lpc_compute_autocorrelation(encoder->private_->windowed_signal, frame_header->blocksize, max_lpc_order+1, autoc);
  92281. if(autoc[0] != 0.0) {
  92282. FLAC__lpc_compute_lp_coefficients(autoc, &max_lpc_order, encoder->private_->lp_coeff, lpc_error);
  92283. if(encoder->protected_->do_exhaustive_model_search) {
  92284. min_lpc_order = 1;
  92285. }
  92286. else {
  92287. const unsigned guess_lpc_order =
  92288. FLAC__lpc_compute_best_order(
  92289. lpc_error,
  92290. max_lpc_order,
  92291. frame_header->blocksize,
  92292. subframe_bps + (
  92293. encoder->protected_->do_qlp_coeff_prec_search?
  92294. FLAC__MIN_QLP_COEFF_PRECISION : /* have to guess; use the min possible size to avoid accidentally favoring lower orders */
  92295. encoder->protected_->qlp_coeff_precision
  92296. )
  92297. );
  92298. min_lpc_order = max_lpc_order = guess_lpc_order;
  92299. }
  92300. if(max_lpc_order >= frame_header->blocksize)
  92301. max_lpc_order = frame_header->blocksize - 1;
  92302. for(lpc_order = min_lpc_order; lpc_order <= max_lpc_order; lpc_order++) {
  92303. lpc_residual_bits_per_sample = FLAC__lpc_compute_expected_bits_per_residual_sample(lpc_error[lpc_order-1], frame_header->blocksize-lpc_order);
  92304. if(lpc_residual_bits_per_sample >= (FLAC__double)subframe_bps)
  92305. continue; /* don't even try */
  92306. rice_parameter = (lpc_residual_bits_per_sample > 0.0)? (unsigned)(lpc_residual_bits_per_sample+0.5) : 0; /* 0.5 is for rounding */
  92307. rice_parameter++; /* to account for the signed->unsigned conversion during rice coding */
  92308. if(rice_parameter >= rice_parameter_limit) {
  92309. #ifdef DEBUG_VERBOSE
  92310. fprintf(stderr, "clipping rice_parameter (%u -> %u) @1\n", rice_parameter, rice_parameter_limit - 1);
  92311. #endif
  92312. rice_parameter = rice_parameter_limit - 1;
  92313. }
  92314. if(encoder->protected_->do_qlp_coeff_prec_search) {
  92315. min_qlp_coeff_precision = FLAC__MIN_QLP_COEFF_PRECISION;
  92316. if(subframe_bps <= 17) {
  92317. max_qlp_coeff_precision = min(32 - subframe_bps - lpc_order, FLAC__MAX_QLP_COEFF_PRECISION);
  92318. max_qlp_coeff_precision = max(max_qlp_coeff_precision, min_qlp_coeff_precision);
  92319. }
  92320. else
  92321. max_qlp_coeff_precision = FLAC__MAX_QLP_COEFF_PRECISION;
  92322. }
  92323. else {
  92324. min_qlp_coeff_precision = max_qlp_coeff_precision = encoder->protected_->qlp_coeff_precision;
  92325. }
  92326. for(qlp_coeff_precision = min_qlp_coeff_precision; qlp_coeff_precision <= max_qlp_coeff_precision; qlp_coeff_precision++) {
  92327. _candidate_bits =
  92328. evaluate_lpc_subframe_(
  92329. encoder,
  92330. integer_signal,
  92331. residual[!_best_subframe],
  92332. encoder->private_->abs_residual_partition_sums,
  92333. encoder->private_->raw_bits_per_partition,
  92334. encoder->private_->lp_coeff[lpc_order-1],
  92335. frame_header->blocksize,
  92336. subframe_bps,
  92337. lpc_order,
  92338. qlp_coeff_precision,
  92339. rice_parameter,
  92340. rice_parameter_limit,
  92341. min_partition_order,
  92342. max_partition_order,
  92343. encoder->protected_->do_escape_coding,
  92344. encoder->protected_->rice_parameter_search_dist,
  92345. subframe[!_best_subframe],
  92346. partitioned_rice_contents[!_best_subframe]
  92347. );
  92348. if(_candidate_bits > 0) { /* if == 0, there was a problem quantizing the lpcoeffs */
  92349. if(_candidate_bits < _best_bits) {
  92350. _best_subframe = !_best_subframe;
  92351. _best_bits = _candidate_bits;
  92352. }
  92353. }
  92354. }
  92355. }
  92356. }
  92357. }
  92358. }
  92359. }
  92360. #endif /* !defined FLAC__INTEGER_ONLY_LIBRARY */
  92361. }
  92362. }
  92363. if(_best_bits == UINT_MAX) {
  92364. FLAC__ASSERT(_best_subframe == 0);
  92365. _best_bits = evaluate_verbatim_subframe_(encoder, integer_signal, frame_header->blocksize, subframe_bps, subframe[_best_subframe]);
  92366. }
  92367. *best_subframe = _best_subframe;
  92368. *best_bits = _best_bits;
  92369. return true;
  92370. }
  92371. FLAC__bool add_subframe_(
  92372. FLAC__StreamEncoder *encoder,
  92373. unsigned blocksize,
  92374. unsigned subframe_bps,
  92375. const FLAC__Subframe *subframe,
  92376. FLAC__BitWriter *frame
  92377. )
  92378. {
  92379. switch(subframe->type) {
  92380. case FLAC__SUBFRAME_TYPE_CONSTANT:
  92381. if(!FLAC__subframe_add_constant(&(subframe->data.constant), subframe_bps, subframe->wasted_bits, frame)) {
  92382. encoder->protected_->state = FLAC__STREAM_ENCODER_FRAMING_ERROR;
  92383. return false;
  92384. }
  92385. break;
  92386. case FLAC__SUBFRAME_TYPE_FIXED:
  92387. if(!FLAC__subframe_add_fixed(&(subframe->data.fixed), blocksize - subframe->data.fixed.order, subframe_bps, subframe->wasted_bits, frame)) {
  92388. encoder->protected_->state = FLAC__STREAM_ENCODER_FRAMING_ERROR;
  92389. return false;
  92390. }
  92391. break;
  92392. case FLAC__SUBFRAME_TYPE_LPC:
  92393. if(!FLAC__subframe_add_lpc(&(subframe->data.lpc), blocksize - subframe->data.lpc.order, subframe_bps, subframe->wasted_bits, frame)) {
  92394. encoder->protected_->state = FLAC__STREAM_ENCODER_FRAMING_ERROR;
  92395. return false;
  92396. }
  92397. break;
  92398. case FLAC__SUBFRAME_TYPE_VERBATIM:
  92399. if(!FLAC__subframe_add_verbatim(&(subframe->data.verbatim), blocksize, subframe_bps, subframe->wasted_bits, frame)) {
  92400. encoder->protected_->state = FLAC__STREAM_ENCODER_FRAMING_ERROR;
  92401. return false;
  92402. }
  92403. break;
  92404. default:
  92405. FLAC__ASSERT(0);
  92406. }
  92407. return true;
  92408. }
  92409. #define SPOTCHECK_ESTIMATE 0
  92410. #if SPOTCHECK_ESTIMATE
  92411. static void spotcheck_subframe_estimate_(
  92412. FLAC__StreamEncoder *encoder,
  92413. unsigned blocksize,
  92414. unsigned subframe_bps,
  92415. const FLAC__Subframe *subframe,
  92416. unsigned estimate
  92417. )
  92418. {
  92419. FLAC__bool ret;
  92420. FLAC__BitWriter *frame = FLAC__bitwriter_new();
  92421. if(frame == 0) {
  92422. fprintf(stderr, "EST: can't allocate frame\n");
  92423. return;
  92424. }
  92425. if(!FLAC__bitwriter_init(frame)) {
  92426. fprintf(stderr, "EST: can't init frame\n");
  92427. return;
  92428. }
  92429. ret = add_subframe_(encoder, blocksize, subframe_bps, subframe, frame);
  92430. FLAC__ASSERT(ret);
  92431. {
  92432. const unsigned actual = FLAC__bitwriter_get_input_bits_unconsumed(frame);
  92433. if(estimate != actual)
  92434. 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);
  92435. }
  92436. FLAC__bitwriter_delete(frame);
  92437. }
  92438. #endif
  92439. unsigned evaluate_constant_subframe_(
  92440. FLAC__StreamEncoder *encoder,
  92441. const FLAC__int32 signal,
  92442. unsigned blocksize,
  92443. unsigned subframe_bps,
  92444. FLAC__Subframe *subframe
  92445. )
  92446. {
  92447. unsigned estimate;
  92448. subframe->type = FLAC__SUBFRAME_TYPE_CONSTANT;
  92449. subframe->data.constant.value = signal;
  92450. estimate = FLAC__SUBFRAME_ZERO_PAD_LEN + FLAC__SUBFRAME_TYPE_LEN + FLAC__SUBFRAME_WASTED_BITS_FLAG_LEN + subframe->wasted_bits + subframe_bps;
  92451. #if SPOTCHECK_ESTIMATE
  92452. spotcheck_subframe_estimate_(encoder, blocksize, subframe_bps, subframe, estimate);
  92453. #else
  92454. (void)encoder, (void)blocksize;
  92455. #endif
  92456. return estimate;
  92457. }
  92458. unsigned evaluate_fixed_subframe_(
  92459. FLAC__StreamEncoder *encoder,
  92460. const FLAC__int32 signal[],
  92461. FLAC__int32 residual[],
  92462. FLAC__uint64 abs_residual_partition_sums[],
  92463. unsigned raw_bits_per_partition[],
  92464. unsigned blocksize,
  92465. unsigned subframe_bps,
  92466. unsigned order,
  92467. unsigned rice_parameter,
  92468. unsigned rice_parameter_limit,
  92469. unsigned min_partition_order,
  92470. unsigned max_partition_order,
  92471. FLAC__bool do_escape_coding,
  92472. unsigned rice_parameter_search_dist,
  92473. FLAC__Subframe *subframe,
  92474. FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents
  92475. )
  92476. {
  92477. unsigned i, residual_bits, estimate;
  92478. const unsigned residual_samples = blocksize - order;
  92479. FLAC__fixed_compute_residual(signal+order, residual_samples, order, residual);
  92480. subframe->type = FLAC__SUBFRAME_TYPE_FIXED;
  92481. subframe->data.fixed.entropy_coding_method.type = FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE;
  92482. subframe->data.fixed.entropy_coding_method.data.partitioned_rice.contents = partitioned_rice_contents;
  92483. subframe->data.fixed.residual = residual;
  92484. residual_bits =
  92485. find_best_partition_order_(
  92486. encoder->private_,
  92487. residual,
  92488. abs_residual_partition_sums,
  92489. raw_bits_per_partition,
  92490. residual_samples,
  92491. order,
  92492. rice_parameter,
  92493. rice_parameter_limit,
  92494. min_partition_order,
  92495. max_partition_order,
  92496. subframe_bps,
  92497. do_escape_coding,
  92498. rice_parameter_search_dist,
  92499. &subframe->data.fixed.entropy_coding_method
  92500. );
  92501. subframe->data.fixed.order = order;
  92502. for(i = 0; i < order; i++)
  92503. subframe->data.fixed.warmup[i] = signal[i];
  92504. estimate = FLAC__SUBFRAME_ZERO_PAD_LEN + FLAC__SUBFRAME_TYPE_LEN + FLAC__SUBFRAME_WASTED_BITS_FLAG_LEN + subframe->wasted_bits + (order * subframe_bps) + residual_bits;
  92505. #if SPOTCHECK_ESTIMATE
  92506. spotcheck_subframe_estimate_(encoder, blocksize, subframe_bps, subframe, estimate);
  92507. #endif
  92508. return estimate;
  92509. }
  92510. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  92511. unsigned evaluate_lpc_subframe_(
  92512. FLAC__StreamEncoder *encoder,
  92513. const FLAC__int32 signal[],
  92514. FLAC__int32 residual[],
  92515. FLAC__uint64 abs_residual_partition_sums[],
  92516. unsigned raw_bits_per_partition[],
  92517. const FLAC__real lp_coeff[],
  92518. unsigned blocksize,
  92519. unsigned subframe_bps,
  92520. unsigned order,
  92521. unsigned qlp_coeff_precision,
  92522. unsigned rice_parameter,
  92523. unsigned rice_parameter_limit,
  92524. unsigned min_partition_order,
  92525. unsigned max_partition_order,
  92526. FLAC__bool do_escape_coding,
  92527. unsigned rice_parameter_search_dist,
  92528. FLAC__Subframe *subframe,
  92529. FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents
  92530. )
  92531. {
  92532. FLAC__int32 qlp_coeff[FLAC__MAX_LPC_ORDER];
  92533. unsigned i, residual_bits, estimate;
  92534. int quantization, ret;
  92535. const unsigned residual_samples = blocksize - order;
  92536. if(subframe_bps <= 16) {
  92537. FLAC__ASSERT(order > 0);
  92538. FLAC__ASSERT(order <= FLAC__MAX_LPC_ORDER);
  92539. qlp_coeff_precision = min(qlp_coeff_precision, 32 - subframe_bps - FLAC__bitmath_ilog2(order));
  92540. }
  92541. ret = FLAC__lpc_quantize_coefficients(lp_coeff, order, qlp_coeff_precision, qlp_coeff, &quantization);
  92542. if(ret != 0)
  92543. return 0; /* this is a hack to indicate to the caller that we can't do lp at this order on this subframe */
  92544. if(subframe_bps + qlp_coeff_precision + FLAC__bitmath_ilog2(order) <= 32)
  92545. if(subframe_bps <= 16 && qlp_coeff_precision <= 16)
  92546. encoder->private_->local_lpc_compute_residual_from_qlp_coefficients_16bit(signal+order, residual_samples, qlp_coeff, order, quantization, residual);
  92547. else
  92548. encoder->private_->local_lpc_compute_residual_from_qlp_coefficients(signal+order, residual_samples, qlp_coeff, order, quantization, residual);
  92549. else
  92550. encoder->private_->local_lpc_compute_residual_from_qlp_coefficients_64bit(signal+order, residual_samples, qlp_coeff, order, quantization, residual);
  92551. subframe->type = FLAC__SUBFRAME_TYPE_LPC;
  92552. subframe->data.lpc.entropy_coding_method.type = FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE;
  92553. subframe->data.lpc.entropy_coding_method.data.partitioned_rice.contents = partitioned_rice_contents;
  92554. subframe->data.lpc.residual = residual;
  92555. residual_bits =
  92556. find_best_partition_order_(
  92557. encoder->private_,
  92558. residual,
  92559. abs_residual_partition_sums,
  92560. raw_bits_per_partition,
  92561. residual_samples,
  92562. order,
  92563. rice_parameter,
  92564. rice_parameter_limit,
  92565. min_partition_order,
  92566. max_partition_order,
  92567. subframe_bps,
  92568. do_escape_coding,
  92569. rice_parameter_search_dist,
  92570. &subframe->data.lpc.entropy_coding_method
  92571. );
  92572. subframe->data.lpc.order = order;
  92573. subframe->data.lpc.qlp_coeff_precision = qlp_coeff_precision;
  92574. subframe->data.lpc.quantization_level = quantization;
  92575. memcpy(subframe->data.lpc.qlp_coeff, qlp_coeff, sizeof(FLAC__int32)*FLAC__MAX_LPC_ORDER);
  92576. for(i = 0; i < order; i++)
  92577. subframe->data.lpc.warmup[i] = signal[i];
  92578. 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;
  92579. #if SPOTCHECK_ESTIMATE
  92580. spotcheck_subframe_estimate_(encoder, blocksize, subframe_bps, subframe, estimate);
  92581. #endif
  92582. return estimate;
  92583. }
  92584. #endif
  92585. unsigned evaluate_verbatim_subframe_(
  92586. FLAC__StreamEncoder *encoder,
  92587. const FLAC__int32 signal[],
  92588. unsigned blocksize,
  92589. unsigned subframe_bps,
  92590. FLAC__Subframe *subframe
  92591. )
  92592. {
  92593. unsigned estimate;
  92594. subframe->type = FLAC__SUBFRAME_TYPE_VERBATIM;
  92595. subframe->data.verbatim.data = signal;
  92596. estimate = FLAC__SUBFRAME_ZERO_PAD_LEN + FLAC__SUBFRAME_TYPE_LEN + FLAC__SUBFRAME_WASTED_BITS_FLAG_LEN + subframe->wasted_bits + (blocksize * subframe_bps);
  92597. #if SPOTCHECK_ESTIMATE
  92598. spotcheck_subframe_estimate_(encoder, blocksize, subframe_bps, subframe, estimate);
  92599. #else
  92600. (void)encoder;
  92601. #endif
  92602. return estimate;
  92603. }
  92604. unsigned find_best_partition_order_(
  92605. FLAC__StreamEncoderPrivate *private_,
  92606. const FLAC__int32 residual[],
  92607. FLAC__uint64 abs_residual_partition_sums[],
  92608. unsigned raw_bits_per_partition[],
  92609. unsigned residual_samples,
  92610. unsigned predictor_order,
  92611. unsigned rice_parameter,
  92612. unsigned rice_parameter_limit,
  92613. unsigned min_partition_order,
  92614. unsigned max_partition_order,
  92615. unsigned bps,
  92616. FLAC__bool do_escape_coding,
  92617. unsigned rice_parameter_search_dist,
  92618. FLAC__EntropyCodingMethod *best_ecm
  92619. )
  92620. {
  92621. unsigned residual_bits, best_residual_bits = 0;
  92622. unsigned best_parameters_index = 0;
  92623. unsigned best_partition_order = 0;
  92624. const unsigned blocksize = residual_samples + predictor_order;
  92625. max_partition_order = FLAC__format_get_max_rice_partition_order_from_blocksize_limited_max_and_predictor_order(max_partition_order, blocksize, predictor_order);
  92626. min_partition_order = min(min_partition_order, max_partition_order);
  92627. precompute_partition_info_sums_(residual, abs_residual_partition_sums, residual_samples, predictor_order, min_partition_order, max_partition_order, bps);
  92628. if(do_escape_coding)
  92629. precompute_partition_info_escapes_(residual, raw_bits_per_partition, residual_samples, predictor_order, min_partition_order, max_partition_order);
  92630. {
  92631. int partition_order;
  92632. unsigned sum;
  92633. for(partition_order = (int)max_partition_order, sum = 0; partition_order >= (int)min_partition_order; partition_order--) {
  92634. if(!
  92635. set_partitioned_rice_(
  92636. #ifdef EXACT_RICE_BITS_CALCULATION
  92637. residual,
  92638. #endif
  92639. abs_residual_partition_sums+sum,
  92640. raw_bits_per_partition+sum,
  92641. residual_samples,
  92642. predictor_order,
  92643. rice_parameter,
  92644. rice_parameter_limit,
  92645. rice_parameter_search_dist,
  92646. (unsigned)partition_order,
  92647. do_escape_coding,
  92648. &private_->partitioned_rice_contents_extra[!best_parameters_index],
  92649. &residual_bits
  92650. )
  92651. )
  92652. {
  92653. FLAC__ASSERT(best_residual_bits != 0);
  92654. break;
  92655. }
  92656. sum += 1u << partition_order;
  92657. if(best_residual_bits == 0 || residual_bits < best_residual_bits) {
  92658. best_residual_bits = residual_bits;
  92659. best_parameters_index = !best_parameters_index;
  92660. best_partition_order = partition_order;
  92661. }
  92662. }
  92663. }
  92664. best_ecm->data.partitioned_rice.order = best_partition_order;
  92665. {
  92666. FLAC__EntropyCodingMethod_PartitionedRiceContents* prc = (FLAC__EntropyCodingMethod_PartitionedRiceContents*)best_ecm->data.partitioned_rice.contents;
  92667. unsigned partition;
  92668. FLAC__format_entropy_coding_method_partitioned_rice_contents_ensure_size(prc, max(6, best_partition_order));
  92669. memcpy(prc->parameters, private_->partitioned_rice_contents_extra[best_parameters_index].parameters, sizeof(unsigned)*(1<<(best_partition_order)));
  92670. if(do_escape_coding)
  92671. memcpy(prc->raw_bits, private_->partitioned_rice_contents_extra[best_parameters_index].raw_bits, sizeof(unsigned)*(1<<(best_partition_order)));
  92672. for(partition = 0; partition < (1u<<best_partition_order); partition++) {
  92673. if(prc->parameters[partition] >= FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ESCAPE_PARAMETER) {
  92674. best_ecm->type = FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2;
  92675. break;
  92676. }
  92677. }
  92678. }
  92679. return best_residual_bits;
  92680. }
  92681. #if defined(FLAC__CPU_IA32) && !defined FLAC__NO_ASM && defined FLAC__HAS_NASM
  92682. extern void precompute_partition_info_sums_32bit_asm_ia32_(
  92683. const FLAC__int32 residual[],
  92684. FLAC__uint64 abs_residual_partition_sums[],
  92685. unsigned blocksize,
  92686. unsigned predictor_order,
  92687. unsigned min_partition_order,
  92688. unsigned max_partition_order
  92689. );
  92690. #endif
  92691. void precompute_partition_info_sums_(
  92692. const FLAC__int32 residual[],
  92693. FLAC__uint64 abs_residual_partition_sums[],
  92694. unsigned residual_samples,
  92695. unsigned predictor_order,
  92696. unsigned min_partition_order,
  92697. unsigned max_partition_order,
  92698. unsigned bps
  92699. )
  92700. {
  92701. const unsigned default_partition_samples = (residual_samples + predictor_order) >> max_partition_order;
  92702. unsigned partitions = 1u << max_partition_order;
  92703. FLAC__ASSERT(default_partition_samples > predictor_order);
  92704. #if defined(FLAC__CPU_IA32) && !defined FLAC__NO_ASM && defined FLAC__HAS_NASM
  92705. if(FLAC__bitmath_ilog2(default_partition_samples) + bps < 32) {
  92706. precompute_partition_info_sums_32bit_asm_ia32_(residual, abs_residual_partition_sums, residual_samples + predictor_order, predictor_order, min_partition_order, max_partition_order);
  92707. return;
  92708. }
  92709. #endif
  92710. {
  92711. unsigned partition, residual_sample, end = (unsigned)(-(int)predictor_order);
  92712. if(FLAC__bitmath_ilog2(default_partition_samples) + bps < 32) {
  92713. FLAC__uint32 abs_residual_partition_sum;
  92714. for(partition = residual_sample = 0; partition < partitions; partition++) {
  92715. end += default_partition_samples;
  92716. abs_residual_partition_sum = 0;
  92717. for( ; residual_sample < end; residual_sample++)
  92718. abs_residual_partition_sum += abs(residual[residual_sample]); /* abs(INT_MIN) is undefined, but if the residual is INT_MIN we have bigger problems */
  92719. abs_residual_partition_sums[partition] = abs_residual_partition_sum;
  92720. }
  92721. }
  92722. else { /* have to pessimistically use 64 bits for accumulator */
  92723. FLAC__uint64 abs_residual_partition_sum;
  92724. for(partition = residual_sample = 0; partition < partitions; partition++) {
  92725. end += default_partition_samples;
  92726. abs_residual_partition_sum = 0;
  92727. for( ; residual_sample < end; residual_sample++)
  92728. abs_residual_partition_sum += abs(residual[residual_sample]); /* abs(INT_MIN) is undefined, but if the residual is INT_MIN we have bigger problems */
  92729. abs_residual_partition_sums[partition] = abs_residual_partition_sum;
  92730. }
  92731. }
  92732. }
  92733. {
  92734. unsigned from_partition = 0, to_partition = partitions;
  92735. int partition_order;
  92736. for(partition_order = (int)max_partition_order - 1; partition_order >= (int)min_partition_order; partition_order--) {
  92737. unsigned i;
  92738. partitions >>= 1;
  92739. for(i = 0; i < partitions; i++) {
  92740. abs_residual_partition_sums[to_partition++] =
  92741. abs_residual_partition_sums[from_partition ] +
  92742. abs_residual_partition_sums[from_partition+1];
  92743. from_partition += 2;
  92744. }
  92745. }
  92746. }
  92747. }
  92748. void precompute_partition_info_escapes_(
  92749. const FLAC__int32 residual[],
  92750. unsigned raw_bits_per_partition[],
  92751. unsigned residual_samples,
  92752. unsigned predictor_order,
  92753. unsigned min_partition_order,
  92754. unsigned max_partition_order
  92755. )
  92756. {
  92757. int partition_order;
  92758. unsigned from_partition, to_partition = 0;
  92759. const unsigned blocksize = residual_samples + predictor_order;
  92760. for(partition_order = (int)max_partition_order; partition_order >= 0; partition_order--) {
  92761. FLAC__int32 r;
  92762. FLAC__uint32 rmax;
  92763. unsigned partition, partition_sample, partition_samples, residual_sample;
  92764. const unsigned partitions = 1u << partition_order;
  92765. const unsigned default_partition_samples = blocksize >> partition_order;
  92766. FLAC__ASSERT(default_partition_samples > predictor_order);
  92767. for(partition = residual_sample = 0; partition < partitions; partition++) {
  92768. partition_samples = default_partition_samples;
  92769. if(partition == 0)
  92770. partition_samples -= predictor_order;
  92771. rmax = 0;
  92772. for(partition_sample = 0; partition_sample < partition_samples; partition_sample++) {
  92773. r = residual[residual_sample++];
  92774. if(r < 0)
  92775. rmax |= ~r;
  92776. else
  92777. rmax |= r;
  92778. }
  92779. raw_bits_per_partition[partition] = rmax? FLAC__bitmath_ilog2(rmax) + 2 : 1;
  92780. }
  92781. to_partition = partitions;
  92782. break; /*@@@ yuck, should remove the 'for' loop instead */
  92783. }
  92784. for(from_partition = 0, --partition_order; partition_order >= (int)min_partition_order; partition_order--) {
  92785. unsigned m;
  92786. unsigned i;
  92787. const unsigned partitions = 1u << partition_order;
  92788. for(i = 0; i < partitions; i++) {
  92789. m = raw_bits_per_partition[from_partition];
  92790. from_partition++;
  92791. raw_bits_per_partition[to_partition] = max(m, raw_bits_per_partition[from_partition]);
  92792. from_partition++;
  92793. to_partition++;
  92794. }
  92795. }
  92796. }
  92797. #ifdef EXACT_RICE_BITS_CALCULATION
  92798. static FLaC__INLINE unsigned count_rice_bits_in_partition_(
  92799. const unsigned rice_parameter,
  92800. const unsigned partition_samples,
  92801. const FLAC__int32 *residual
  92802. )
  92803. {
  92804. unsigned i, partition_bits =
  92805. 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 */
  92806. (1+rice_parameter) * partition_samples /* 1 for unary stop bit + rice_parameter for the binary portion */
  92807. ;
  92808. for(i = 0; i < partition_samples; i++)
  92809. partition_bits += ( (FLAC__uint32)((residual[i]<<1)^(residual[i]>>31)) >> rice_parameter );
  92810. return partition_bits;
  92811. }
  92812. #else
  92813. static FLaC__INLINE unsigned count_rice_bits_in_partition_(
  92814. const unsigned rice_parameter,
  92815. const unsigned partition_samples,
  92816. const FLAC__uint64 abs_residual_partition_sum
  92817. )
  92818. {
  92819. return
  92820. 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 */
  92821. (1+rice_parameter) * partition_samples + /* 1 for unary stop bit + rice_parameter for the binary portion */
  92822. (
  92823. rice_parameter?
  92824. (unsigned)(abs_residual_partition_sum >> (rice_parameter-1)) /* rice_parameter-1 because the real coder sign-folds instead of using a sign bit */
  92825. : (unsigned)(abs_residual_partition_sum << 1) /* can't shift by negative number, so reverse */
  92826. )
  92827. - (partition_samples >> 1)
  92828. ;
  92829. }
  92830. #endif
  92831. FLAC__bool set_partitioned_rice_(
  92832. #ifdef EXACT_RICE_BITS_CALCULATION
  92833. const FLAC__int32 residual[],
  92834. #endif
  92835. const FLAC__uint64 abs_residual_partition_sums[],
  92836. const unsigned raw_bits_per_partition[],
  92837. const unsigned residual_samples,
  92838. const unsigned predictor_order,
  92839. const unsigned suggested_rice_parameter,
  92840. const unsigned rice_parameter_limit,
  92841. const unsigned rice_parameter_search_dist,
  92842. const unsigned partition_order,
  92843. const FLAC__bool search_for_escapes,
  92844. FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents,
  92845. unsigned *bits
  92846. )
  92847. {
  92848. unsigned rice_parameter, partition_bits;
  92849. unsigned best_partition_bits, best_rice_parameter = 0;
  92850. unsigned bits_ = FLAC__ENTROPY_CODING_METHOD_TYPE_LEN + FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ORDER_LEN;
  92851. unsigned *parameters, *raw_bits;
  92852. #ifdef ENABLE_RICE_PARAMETER_SEARCH
  92853. unsigned min_rice_parameter, max_rice_parameter;
  92854. #else
  92855. (void)rice_parameter_search_dist;
  92856. #endif
  92857. FLAC__ASSERT(suggested_rice_parameter < FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_ESCAPE_PARAMETER);
  92858. FLAC__ASSERT(rice_parameter_limit <= FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_ESCAPE_PARAMETER);
  92859. FLAC__format_entropy_coding_method_partitioned_rice_contents_ensure_size(partitioned_rice_contents, max(6, partition_order));
  92860. parameters = partitioned_rice_contents->parameters;
  92861. raw_bits = partitioned_rice_contents->raw_bits;
  92862. if(partition_order == 0) {
  92863. best_partition_bits = (unsigned)(-1);
  92864. #ifdef ENABLE_RICE_PARAMETER_SEARCH
  92865. if(rice_parameter_search_dist) {
  92866. if(suggested_rice_parameter < rice_parameter_search_dist)
  92867. min_rice_parameter = 0;
  92868. else
  92869. min_rice_parameter = suggested_rice_parameter - rice_parameter_search_dist;
  92870. max_rice_parameter = suggested_rice_parameter + rice_parameter_search_dist;
  92871. if(max_rice_parameter >= rice_parameter_limit) {
  92872. #ifdef DEBUG_VERBOSE
  92873. fprintf(stderr, "clipping rice_parameter (%u -> %u) @5\n", max_rice_parameter, rice_parameter_limit - 1);
  92874. #endif
  92875. max_rice_parameter = rice_parameter_limit - 1;
  92876. }
  92877. }
  92878. else
  92879. min_rice_parameter = max_rice_parameter = suggested_rice_parameter;
  92880. for(rice_parameter = min_rice_parameter; rice_parameter <= max_rice_parameter; rice_parameter++) {
  92881. #else
  92882. rice_parameter = suggested_rice_parameter;
  92883. #endif
  92884. #ifdef EXACT_RICE_BITS_CALCULATION
  92885. partition_bits = count_rice_bits_in_partition_(rice_parameter, residual_samples, residual);
  92886. #else
  92887. partition_bits = count_rice_bits_in_partition_(rice_parameter, residual_samples, abs_residual_partition_sums[0]);
  92888. #endif
  92889. if(partition_bits < best_partition_bits) {
  92890. best_rice_parameter = rice_parameter;
  92891. best_partition_bits = partition_bits;
  92892. }
  92893. #ifdef ENABLE_RICE_PARAMETER_SEARCH
  92894. }
  92895. #endif
  92896. if(search_for_escapes) {
  92897. 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;
  92898. if(partition_bits <= best_partition_bits) {
  92899. raw_bits[0] = raw_bits_per_partition[0];
  92900. best_rice_parameter = 0; /* will be converted to appropriate escape parameter later */
  92901. best_partition_bits = partition_bits;
  92902. }
  92903. else
  92904. raw_bits[0] = 0;
  92905. }
  92906. parameters[0] = best_rice_parameter;
  92907. bits_ += best_partition_bits;
  92908. }
  92909. else {
  92910. unsigned partition, residual_sample;
  92911. unsigned partition_samples;
  92912. FLAC__uint64 mean, k;
  92913. const unsigned partitions = 1u << partition_order;
  92914. for(partition = residual_sample = 0; partition < partitions; partition++) {
  92915. partition_samples = (residual_samples+predictor_order) >> partition_order;
  92916. if(partition == 0) {
  92917. if(partition_samples <= predictor_order)
  92918. return false;
  92919. else
  92920. partition_samples -= predictor_order;
  92921. }
  92922. mean = abs_residual_partition_sums[partition];
  92923. for(rice_parameter = 0, k = partition_samples; k < mean; rice_parameter++, k <<= 1)
  92924. ;
  92925. if(rice_parameter >= rice_parameter_limit) {
  92926. #ifdef DEBUG_VERBOSE
  92927. fprintf(stderr, "clipping rice_parameter (%u -> %u) @6\n", rice_parameter, rice_parameter_limit - 1);
  92928. #endif
  92929. rice_parameter = rice_parameter_limit - 1;
  92930. }
  92931. best_partition_bits = (unsigned)(-1);
  92932. #ifdef ENABLE_RICE_PARAMETER_SEARCH
  92933. if(rice_parameter_search_dist) {
  92934. if(rice_parameter < rice_parameter_search_dist)
  92935. min_rice_parameter = 0;
  92936. else
  92937. min_rice_parameter = rice_parameter - rice_parameter_search_dist;
  92938. max_rice_parameter = rice_parameter + rice_parameter_search_dist;
  92939. if(max_rice_parameter >= rice_parameter_limit) {
  92940. #ifdef DEBUG_VERBOSE
  92941. fprintf(stderr, "clipping rice_parameter (%u -> %u) @7\n", max_rice_parameter, rice_parameter_limit - 1);
  92942. #endif
  92943. max_rice_parameter = rice_parameter_limit - 1;
  92944. }
  92945. }
  92946. else
  92947. min_rice_parameter = max_rice_parameter = rice_parameter;
  92948. for(rice_parameter = min_rice_parameter; rice_parameter <= max_rice_parameter; rice_parameter++) {
  92949. #endif
  92950. #ifdef EXACT_RICE_BITS_CALCULATION
  92951. partition_bits = count_rice_bits_in_partition_(rice_parameter, partition_samples, residual+residual_sample);
  92952. #else
  92953. partition_bits = count_rice_bits_in_partition_(rice_parameter, partition_samples, abs_residual_partition_sums[partition]);
  92954. #endif
  92955. if(partition_bits < best_partition_bits) {
  92956. best_rice_parameter = rice_parameter;
  92957. best_partition_bits = partition_bits;
  92958. }
  92959. #ifdef ENABLE_RICE_PARAMETER_SEARCH
  92960. }
  92961. #endif
  92962. if(search_for_escapes) {
  92963. 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;
  92964. if(partition_bits <= best_partition_bits) {
  92965. raw_bits[partition] = raw_bits_per_partition[partition];
  92966. best_rice_parameter = 0; /* will be converted to appropriate escape parameter later */
  92967. best_partition_bits = partition_bits;
  92968. }
  92969. else
  92970. raw_bits[partition] = 0;
  92971. }
  92972. parameters[partition] = best_rice_parameter;
  92973. bits_ += best_partition_bits;
  92974. residual_sample += partition_samples;
  92975. }
  92976. }
  92977. *bits = bits_;
  92978. return true;
  92979. }
  92980. unsigned get_wasted_bits_(FLAC__int32 signal[], unsigned samples)
  92981. {
  92982. unsigned i, shift;
  92983. FLAC__int32 x = 0;
  92984. for(i = 0; i < samples && !(x&1); i++)
  92985. x |= signal[i];
  92986. if(x == 0) {
  92987. shift = 0;
  92988. }
  92989. else {
  92990. for(shift = 0; !(x&1); shift++)
  92991. x >>= 1;
  92992. }
  92993. if(shift > 0) {
  92994. for(i = 0; i < samples; i++)
  92995. signal[i] >>= shift;
  92996. }
  92997. return shift;
  92998. }
  92999. void append_to_verify_fifo_(verify_input_fifo *fifo, const FLAC__int32 * const input[], unsigned input_offset, unsigned channels, unsigned wide_samples)
  93000. {
  93001. unsigned channel;
  93002. for(channel = 0; channel < channels; channel++)
  93003. memcpy(&fifo->data[channel][fifo->tail], &input[channel][input_offset], sizeof(FLAC__int32) * wide_samples);
  93004. fifo->tail += wide_samples;
  93005. FLAC__ASSERT(fifo->tail <= fifo->size);
  93006. }
  93007. void append_to_verify_fifo_interleaved_(verify_input_fifo *fifo, const FLAC__int32 input[], unsigned input_offset, unsigned channels, unsigned wide_samples)
  93008. {
  93009. unsigned channel;
  93010. unsigned sample, wide_sample;
  93011. unsigned tail = fifo->tail;
  93012. sample = input_offset * channels;
  93013. for(wide_sample = 0; wide_sample < wide_samples; wide_sample++) {
  93014. for(channel = 0; channel < channels; channel++)
  93015. fifo->data[channel][tail] = input[sample++];
  93016. tail++;
  93017. }
  93018. fifo->tail = tail;
  93019. FLAC__ASSERT(fifo->tail <= fifo->size);
  93020. }
  93021. FLAC__StreamDecoderReadStatus verify_read_callback_(const FLAC__StreamDecoder *decoder, FLAC__byte buffer[], size_t *bytes, void *client_data)
  93022. {
  93023. FLAC__StreamEncoder *encoder = (FLAC__StreamEncoder*)client_data;
  93024. const size_t encoded_bytes = encoder->private_->verify.output.bytes;
  93025. (void)decoder;
  93026. if(encoder->private_->verify.needs_magic_hack) {
  93027. FLAC__ASSERT(*bytes >= FLAC__STREAM_SYNC_LENGTH);
  93028. *bytes = FLAC__STREAM_SYNC_LENGTH;
  93029. memcpy(buffer, FLAC__STREAM_SYNC_STRING, *bytes);
  93030. encoder->private_->verify.needs_magic_hack = false;
  93031. }
  93032. else {
  93033. if(encoded_bytes == 0) {
  93034. FLAC__ASSERT(0);
  93035. return FLAC__STREAM_DECODER_READ_STATUS_ABORT;
  93036. }
  93037. else if(encoded_bytes < *bytes)
  93038. *bytes = encoded_bytes;
  93039. memcpy(buffer, encoder->private_->verify.output.data, *bytes);
  93040. encoder->private_->verify.output.data += *bytes;
  93041. encoder->private_->verify.output.bytes -= *bytes;
  93042. }
  93043. return FLAC__STREAM_DECODER_READ_STATUS_CONTINUE;
  93044. }
  93045. FLAC__StreamDecoderWriteStatus verify_write_callback_(const FLAC__StreamDecoder *decoder, const FLAC__Frame *frame, const FLAC__int32 * const buffer[], void *client_data)
  93046. {
  93047. FLAC__StreamEncoder *encoder = (FLAC__StreamEncoder *)client_data;
  93048. unsigned channel;
  93049. const unsigned channels = frame->header.channels;
  93050. const unsigned blocksize = frame->header.blocksize;
  93051. const unsigned bytes_per_block = sizeof(FLAC__int32) * blocksize;
  93052. (void)decoder;
  93053. for(channel = 0; channel < channels; channel++) {
  93054. if(0 != memcmp(buffer[channel], encoder->private_->verify.input_fifo.data[channel], bytes_per_block)) {
  93055. unsigned i, sample = 0;
  93056. FLAC__int32 expect = 0, got = 0;
  93057. for(i = 0; i < blocksize; i++) {
  93058. if(buffer[channel][i] != encoder->private_->verify.input_fifo.data[channel][i]) {
  93059. sample = i;
  93060. expect = (FLAC__int32)encoder->private_->verify.input_fifo.data[channel][i];
  93061. got = (FLAC__int32)buffer[channel][i];
  93062. break;
  93063. }
  93064. }
  93065. FLAC__ASSERT(i < blocksize);
  93066. FLAC__ASSERT(frame->header.number_type == FLAC__FRAME_NUMBER_TYPE_SAMPLE_NUMBER);
  93067. encoder->private_->verify.error_stats.absolute_sample = frame->header.number.sample_number + sample;
  93068. encoder->private_->verify.error_stats.frame_number = (unsigned)(frame->header.number.sample_number / blocksize);
  93069. encoder->private_->verify.error_stats.channel = channel;
  93070. encoder->private_->verify.error_stats.sample = sample;
  93071. encoder->private_->verify.error_stats.expected = expect;
  93072. encoder->private_->verify.error_stats.got = got;
  93073. encoder->protected_->state = FLAC__STREAM_ENCODER_VERIFY_MISMATCH_IN_AUDIO_DATA;
  93074. return FLAC__STREAM_DECODER_WRITE_STATUS_ABORT;
  93075. }
  93076. }
  93077. encoder->private_->verify.input_fifo.tail -= blocksize;
  93078. FLAC__ASSERT(encoder->private_->verify.input_fifo.tail <= OVERREAD_);
  93079. for(channel = 0; channel < channels; channel++)
  93080. 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]));
  93081. return FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE;
  93082. }
  93083. void verify_metadata_callback_(const FLAC__StreamDecoder *decoder, const FLAC__StreamMetadata *metadata, void *client_data)
  93084. {
  93085. (void)decoder, (void)metadata, (void)client_data;
  93086. }
  93087. void verify_error_callback_(const FLAC__StreamDecoder *decoder, FLAC__StreamDecoderErrorStatus status, void *client_data)
  93088. {
  93089. FLAC__StreamEncoder *encoder = (FLAC__StreamEncoder*)client_data;
  93090. (void)decoder, (void)status;
  93091. encoder->protected_->state = FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR;
  93092. }
  93093. FLAC__StreamEncoderReadStatus file_read_callback_enc(const FLAC__StreamEncoder *encoder, FLAC__byte buffer[], size_t *bytes, void *client_data)
  93094. {
  93095. (void)client_data;
  93096. *bytes = fread(buffer, 1, *bytes, encoder->private_->file);
  93097. if (*bytes == 0) {
  93098. if (feof(encoder->private_->file))
  93099. return FLAC__STREAM_ENCODER_READ_STATUS_END_OF_STREAM;
  93100. else if (ferror(encoder->private_->file))
  93101. return FLAC__STREAM_ENCODER_READ_STATUS_ABORT;
  93102. }
  93103. return FLAC__STREAM_ENCODER_READ_STATUS_CONTINUE;
  93104. }
  93105. FLAC__StreamEncoderSeekStatus file_seek_callback_enc(const FLAC__StreamEncoder *encoder, FLAC__uint64 absolute_byte_offset, void *client_data)
  93106. {
  93107. (void)client_data;
  93108. if(fseeko(encoder->private_->file, (off_t)absolute_byte_offset, SEEK_SET) < 0)
  93109. return FLAC__STREAM_ENCODER_SEEK_STATUS_ERROR;
  93110. else
  93111. return FLAC__STREAM_ENCODER_SEEK_STATUS_OK;
  93112. }
  93113. FLAC__StreamEncoderTellStatus file_tell_callback_enc(const FLAC__StreamEncoder *encoder, FLAC__uint64 *absolute_byte_offset, void *client_data)
  93114. {
  93115. off_t offset;
  93116. (void)client_data;
  93117. offset = ftello(encoder->private_->file);
  93118. if(offset < 0) {
  93119. return FLAC__STREAM_ENCODER_TELL_STATUS_ERROR;
  93120. }
  93121. else {
  93122. *absolute_byte_offset = (FLAC__uint64)offset;
  93123. return FLAC__STREAM_ENCODER_TELL_STATUS_OK;
  93124. }
  93125. }
  93126. #ifdef FLAC__VALGRIND_TESTING
  93127. static size_t local__fwrite(const void *ptr, size_t size, size_t nmemb, FILE *stream)
  93128. {
  93129. size_t ret = fwrite(ptr, size, nmemb, stream);
  93130. if(!ferror(stream))
  93131. fflush(stream);
  93132. return ret;
  93133. }
  93134. #else
  93135. #define local__fwrite fwrite
  93136. #endif
  93137. FLAC__StreamEncoderWriteStatus file_write_callback_(const FLAC__StreamEncoder *encoder, const FLAC__byte buffer[], size_t bytes, unsigned samples, unsigned current_frame, void *client_data)
  93138. {
  93139. (void)client_data, (void)current_frame;
  93140. if(local__fwrite(buffer, sizeof(FLAC__byte), bytes, encoder->private_->file) == bytes) {
  93141. FLAC__bool call_it = 0 != encoder->private_->progress_callback && (
  93142. #if FLAC__HAS_OGG
  93143. encoder->private_->is_ogg? true :
  93144. #endif
  93145. samples > 0
  93146. );
  93147. if(call_it) {
  93148. 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);
  93149. }
  93150. return FLAC__STREAM_ENCODER_WRITE_STATUS_OK;
  93151. }
  93152. else
  93153. return FLAC__STREAM_ENCODER_WRITE_STATUS_FATAL_ERROR;
  93154. }
  93155. FILE *get_binary_stdout_(void)
  93156. {
  93157. #if defined _MSC_VER || defined __MINGW32__
  93158. _setmode(_fileno(stdout), _O_BINARY);
  93159. #elif defined __CYGWIN__
  93160. setmode(_fileno(stdout), _O_BINARY);
  93161. #elif defined __EMX__
  93162. setmode(fileno(stdout), O_BINARY);
  93163. #endif
  93164. return stdout;
  93165. }
  93166. #endif
  93167. /*** End of inlined file: stream_encoder.c ***/
  93168. /*** Start of inlined file: stream_encoder_framing.c ***/
  93169. /*** Start of inlined file: juce_FlacHeader.h ***/
  93170. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  93171. // tasks..
  93172. #define VERSION "1.2.1"
  93173. #define FLAC__NO_DLL 1
  93174. #if JUCE_MSVC
  93175. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  93176. #endif
  93177. #if JUCE_MAC
  93178. #define FLAC__SYS_DARWIN 1
  93179. #endif
  93180. /*** End of inlined file: juce_FlacHeader.h ***/
  93181. #if JUCE_USE_FLAC
  93182. #if HAVE_CONFIG_H
  93183. # include <config.h>
  93184. #endif
  93185. #include <stdio.h>
  93186. #include <string.h> /* for strlen() */
  93187. #ifdef max
  93188. #undef max
  93189. #endif
  93190. #define max(x,y) ((x)>(y)?(x):(y))
  93191. static FLAC__bool add_entropy_coding_method_(FLAC__BitWriter *bw, const FLAC__EntropyCodingMethod *method);
  93192. 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);
  93193. FLAC__bool FLAC__add_metadata_block(const FLAC__StreamMetadata *metadata, FLAC__BitWriter *bw)
  93194. {
  93195. unsigned i, j;
  93196. const unsigned vendor_string_length = (unsigned)strlen(FLAC__VENDOR_STRING);
  93197. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->is_last, FLAC__STREAM_METADATA_IS_LAST_LEN))
  93198. return false;
  93199. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->type, FLAC__STREAM_METADATA_TYPE_LEN))
  93200. return false;
  93201. i = metadata->length;
  93202. if(metadata->type == FLAC__METADATA_TYPE_VORBIS_COMMENT) {
  93203. FLAC__ASSERT(metadata->data.vorbis_comment.vendor_string.length == 0 || 0 != metadata->data.vorbis_comment.vendor_string.entry);
  93204. i -= metadata->data.vorbis_comment.vendor_string.length;
  93205. i += vendor_string_length;
  93206. }
  93207. FLAC__ASSERT(i < (1u << FLAC__STREAM_METADATA_LENGTH_LEN));
  93208. if(!FLAC__bitwriter_write_raw_uint32(bw, i, FLAC__STREAM_METADATA_LENGTH_LEN))
  93209. return false;
  93210. switch(metadata->type) {
  93211. case FLAC__METADATA_TYPE_STREAMINFO:
  93212. FLAC__ASSERT(metadata->data.stream_info.min_blocksize < (1u << FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN));
  93213. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.stream_info.min_blocksize, FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN))
  93214. return false;
  93215. FLAC__ASSERT(metadata->data.stream_info.max_blocksize < (1u << FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN));
  93216. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.stream_info.max_blocksize, FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN))
  93217. return false;
  93218. FLAC__ASSERT(metadata->data.stream_info.min_framesize < (1u << FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN));
  93219. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.stream_info.min_framesize, FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN))
  93220. return false;
  93221. FLAC__ASSERT(metadata->data.stream_info.max_framesize < (1u << FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN));
  93222. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.stream_info.max_framesize, FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN))
  93223. return false;
  93224. FLAC__ASSERT(FLAC__format_sample_rate_is_valid(metadata->data.stream_info.sample_rate));
  93225. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.stream_info.sample_rate, FLAC__STREAM_METADATA_STREAMINFO_SAMPLE_RATE_LEN))
  93226. return false;
  93227. FLAC__ASSERT(metadata->data.stream_info.channels > 0);
  93228. FLAC__ASSERT(metadata->data.stream_info.channels <= (1u << FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN));
  93229. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.stream_info.channels-1, FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN))
  93230. return false;
  93231. FLAC__ASSERT(metadata->data.stream_info.bits_per_sample > 0);
  93232. FLAC__ASSERT(metadata->data.stream_info.bits_per_sample <= (1u << FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN));
  93233. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.stream_info.bits_per_sample-1, FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN))
  93234. return false;
  93235. if(!FLAC__bitwriter_write_raw_uint64(bw, metadata->data.stream_info.total_samples, FLAC__STREAM_METADATA_STREAMINFO_TOTAL_SAMPLES_LEN))
  93236. return false;
  93237. if(!FLAC__bitwriter_write_byte_block(bw, metadata->data.stream_info.md5sum, 16))
  93238. return false;
  93239. break;
  93240. case FLAC__METADATA_TYPE_PADDING:
  93241. if(!FLAC__bitwriter_write_zeroes(bw, metadata->length * 8))
  93242. return false;
  93243. break;
  93244. case FLAC__METADATA_TYPE_APPLICATION:
  93245. if(!FLAC__bitwriter_write_byte_block(bw, metadata->data.application.id, FLAC__STREAM_METADATA_APPLICATION_ID_LEN / 8))
  93246. return false;
  93247. if(!FLAC__bitwriter_write_byte_block(bw, metadata->data.application.data, metadata->length - (FLAC__STREAM_METADATA_APPLICATION_ID_LEN / 8)))
  93248. return false;
  93249. break;
  93250. case FLAC__METADATA_TYPE_SEEKTABLE:
  93251. for(i = 0; i < metadata->data.seek_table.num_points; i++) {
  93252. if(!FLAC__bitwriter_write_raw_uint64(bw, metadata->data.seek_table.points[i].sample_number, FLAC__STREAM_METADATA_SEEKPOINT_SAMPLE_NUMBER_LEN))
  93253. return false;
  93254. if(!FLAC__bitwriter_write_raw_uint64(bw, metadata->data.seek_table.points[i].stream_offset, FLAC__STREAM_METADATA_SEEKPOINT_STREAM_OFFSET_LEN))
  93255. return false;
  93256. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.seek_table.points[i].frame_samples, FLAC__STREAM_METADATA_SEEKPOINT_FRAME_SAMPLES_LEN))
  93257. return false;
  93258. }
  93259. break;
  93260. case FLAC__METADATA_TYPE_VORBIS_COMMENT:
  93261. if(!FLAC__bitwriter_write_raw_uint32_little_endian(bw, vendor_string_length))
  93262. return false;
  93263. if(!FLAC__bitwriter_write_byte_block(bw, (const FLAC__byte*)FLAC__VENDOR_STRING, vendor_string_length))
  93264. return false;
  93265. if(!FLAC__bitwriter_write_raw_uint32_little_endian(bw, metadata->data.vorbis_comment.num_comments))
  93266. return false;
  93267. for(i = 0; i < metadata->data.vorbis_comment.num_comments; i++) {
  93268. if(!FLAC__bitwriter_write_raw_uint32_little_endian(bw, metadata->data.vorbis_comment.comments[i].length))
  93269. return false;
  93270. if(!FLAC__bitwriter_write_byte_block(bw, metadata->data.vorbis_comment.comments[i].entry, metadata->data.vorbis_comment.comments[i].length))
  93271. return false;
  93272. }
  93273. break;
  93274. case FLAC__METADATA_TYPE_CUESHEET:
  93275. FLAC__ASSERT(FLAC__STREAM_METADATA_CUESHEET_MEDIA_CATALOG_NUMBER_LEN % 8 == 0);
  93276. 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))
  93277. return false;
  93278. if(!FLAC__bitwriter_write_raw_uint64(bw, metadata->data.cue_sheet.lead_in, FLAC__STREAM_METADATA_CUESHEET_LEAD_IN_LEN))
  93279. return false;
  93280. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.cue_sheet.is_cd? 1 : 0, FLAC__STREAM_METADATA_CUESHEET_IS_CD_LEN))
  93281. return false;
  93282. if(!FLAC__bitwriter_write_zeroes(bw, FLAC__STREAM_METADATA_CUESHEET_RESERVED_LEN))
  93283. return false;
  93284. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.cue_sheet.num_tracks, FLAC__STREAM_METADATA_CUESHEET_NUM_TRACKS_LEN))
  93285. return false;
  93286. for(i = 0; i < metadata->data.cue_sheet.num_tracks; i++) {
  93287. const FLAC__StreamMetadata_CueSheet_Track *track = metadata->data.cue_sheet.tracks + i;
  93288. if(!FLAC__bitwriter_write_raw_uint64(bw, track->offset, FLAC__STREAM_METADATA_CUESHEET_TRACK_OFFSET_LEN))
  93289. return false;
  93290. if(!FLAC__bitwriter_write_raw_uint32(bw, track->number, FLAC__STREAM_METADATA_CUESHEET_TRACK_NUMBER_LEN))
  93291. return false;
  93292. FLAC__ASSERT(FLAC__STREAM_METADATA_CUESHEET_TRACK_ISRC_LEN % 8 == 0);
  93293. if(!FLAC__bitwriter_write_byte_block(bw, (const FLAC__byte*)track->isrc, FLAC__STREAM_METADATA_CUESHEET_TRACK_ISRC_LEN/8))
  93294. return false;
  93295. if(!FLAC__bitwriter_write_raw_uint32(bw, track->type, FLAC__STREAM_METADATA_CUESHEET_TRACK_TYPE_LEN))
  93296. return false;
  93297. if(!FLAC__bitwriter_write_raw_uint32(bw, track->pre_emphasis, FLAC__STREAM_METADATA_CUESHEET_TRACK_PRE_EMPHASIS_LEN))
  93298. return false;
  93299. if(!FLAC__bitwriter_write_zeroes(bw, FLAC__STREAM_METADATA_CUESHEET_TRACK_RESERVED_LEN))
  93300. return false;
  93301. if(!FLAC__bitwriter_write_raw_uint32(bw, track->num_indices, FLAC__STREAM_METADATA_CUESHEET_TRACK_NUM_INDICES_LEN))
  93302. return false;
  93303. for(j = 0; j < track->num_indices; j++) {
  93304. const FLAC__StreamMetadata_CueSheet_Index *index = track->indices + j;
  93305. if(!FLAC__bitwriter_write_raw_uint64(bw, index->offset, FLAC__STREAM_METADATA_CUESHEET_INDEX_OFFSET_LEN))
  93306. return false;
  93307. if(!FLAC__bitwriter_write_raw_uint32(bw, index->number, FLAC__STREAM_METADATA_CUESHEET_INDEX_NUMBER_LEN))
  93308. return false;
  93309. if(!FLAC__bitwriter_write_zeroes(bw, FLAC__STREAM_METADATA_CUESHEET_INDEX_RESERVED_LEN))
  93310. return false;
  93311. }
  93312. }
  93313. break;
  93314. case FLAC__METADATA_TYPE_PICTURE:
  93315. {
  93316. size_t len;
  93317. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.picture.type, FLAC__STREAM_METADATA_PICTURE_TYPE_LEN))
  93318. return false;
  93319. len = strlen(metadata->data.picture.mime_type);
  93320. if(!FLAC__bitwriter_write_raw_uint32(bw, len, FLAC__STREAM_METADATA_PICTURE_MIME_TYPE_LENGTH_LEN))
  93321. return false;
  93322. if(!FLAC__bitwriter_write_byte_block(bw, (const FLAC__byte*)metadata->data.picture.mime_type, len))
  93323. return false;
  93324. len = strlen((const char *)metadata->data.picture.description);
  93325. if(!FLAC__bitwriter_write_raw_uint32(bw, len, FLAC__STREAM_METADATA_PICTURE_DESCRIPTION_LENGTH_LEN))
  93326. return false;
  93327. if(!FLAC__bitwriter_write_byte_block(bw, metadata->data.picture.description, len))
  93328. return false;
  93329. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.picture.width, FLAC__STREAM_METADATA_PICTURE_WIDTH_LEN))
  93330. return false;
  93331. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.picture.height, FLAC__STREAM_METADATA_PICTURE_HEIGHT_LEN))
  93332. return false;
  93333. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.picture.depth, FLAC__STREAM_METADATA_PICTURE_DEPTH_LEN))
  93334. return false;
  93335. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.picture.colors, FLAC__STREAM_METADATA_PICTURE_COLORS_LEN))
  93336. return false;
  93337. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.picture.data_length, FLAC__STREAM_METADATA_PICTURE_DATA_LENGTH_LEN))
  93338. return false;
  93339. if(!FLAC__bitwriter_write_byte_block(bw, metadata->data.picture.data, metadata->data.picture.data_length))
  93340. return false;
  93341. }
  93342. break;
  93343. default:
  93344. if(!FLAC__bitwriter_write_byte_block(bw, metadata->data.unknown.data, metadata->length))
  93345. return false;
  93346. break;
  93347. }
  93348. FLAC__ASSERT(FLAC__bitwriter_is_byte_aligned(bw));
  93349. return true;
  93350. }
  93351. FLAC__bool FLAC__frame_add_header(const FLAC__FrameHeader *header, FLAC__BitWriter *bw)
  93352. {
  93353. unsigned u, blocksize_hint, sample_rate_hint;
  93354. FLAC__byte crc;
  93355. FLAC__ASSERT(FLAC__bitwriter_is_byte_aligned(bw));
  93356. if(!FLAC__bitwriter_write_raw_uint32(bw, FLAC__FRAME_HEADER_SYNC, FLAC__FRAME_HEADER_SYNC_LEN))
  93357. return false;
  93358. if(!FLAC__bitwriter_write_raw_uint32(bw, 0, FLAC__FRAME_HEADER_RESERVED_LEN))
  93359. return false;
  93360. if(!FLAC__bitwriter_write_raw_uint32(bw, (header->number_type == FLAC__FRAME_NUMBER_TYPE_FRAME_NUMBER)? 0 : 1, FLAC__FRAME_HEADER_BLOCKING_STRATEGY_LEN))
  93361. return false;
  93362. FLAC__ASSERT(header->blocksize > 0 && header->blocksize <= FLAC__MAX_BLOCK_SIZE);
  93363. FLAC__ASSERT(FLAC__MAX_BLOCK_SIZE <= 65535u);
  93364. blocksize_hint = 0;
  93365. switch(header->blocksize) {
  93366. case 192: u = 1; break;
  93367. case 576: u = 2; break;
  93368. case 1152: u = 3; break;
  93369. case 2304: u = 4; break;
  93370. case 4608: u = 5; break;
  93371. case 256: u = 8; break;
  93372. case 512: u = 9; break;
  93373. case 1024: u = 10; break;
  93374. case 2048: u = 11; break;
  93375. case 4096: u = 12; break;
  93376. case 8192: u = 13; break;
  93377. case 16384: u = 14; break;
  93378. case 32768: u = 15; break;
  93379. default:
  93380. if(header->blocksize <= 0x100)
  93381. blocksize_hint = u = 6;
  93382. else
  93383. blocksize_hint = u = 7;
  93384. break;
  93385. }
  93386. if(!FLAC__bitwriter_write_raw_uint32(bw, u, FLAC__FRAME_HEADER_BLOCK_SIZE_LEN))
  93387. return false;
  93388. FLAC__ASSERT(FLAC__format_sample_rate_is_valid(header->sample_rate));
  93389. sample_rate_hint = 0;
  93390. switch(header->sample_rate) {
  93391. case 88200: u = 1; break;
  93392. case 176400: u = 2; break;
  93393. case 192000: u = 3; break;
  93394. case 8000: u = 4; break;
  93395. case 16000: u = 5; break;
  93396. case 22050: u = 6; break;
  93397. case 24000: u = 7; break;
  93398. case 32000: u = 8; break;
  93399. case 44100: u = 9; break;
  93400. case 48000: u = 10; break;
  93401. case 96000: u = 11; break;
  93402. default:
  93403. if(header->sample_rate <= 255000 && header->sample_rate % 1000 == 0)
  93404. sample_rate_hint = u = 12;
  93405. else if(header->sample_rate % 10 == 0)
  93406. sample_rate_hint = u = 14;
  93407. else if(header->sample_rate <= 0xffff)
  93408. sample_rate_hint = u = 13;
  93409. else
  93410. u = 0;
  93411. break;
  93412. }
  93413. if(!FLAC__bitwriter_write_raw_uint32(bw, u, FLAC__FRAME_HEADER_SAMPLE_RATE_LEN))
  93414. return false;
  93415. FLAC__ASSERT(header->channels > 0 && header->channels <= (1u << FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN) && header->channels <= FLAC__MAX_CHANNELS);
  93416. switch(header->channel_assignment) {
  93417. case FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT:
  93418. u = header->channels - 1;
  93419. break;
  93420. case FLAC__CHANNEL_ASSIGNMENT_LEFT_SIDE:
  93421. FLAC__ASSERT(header->channels == 2);
  93422. u = 8;
  93423. break;
  93424. case FLAC__CHANNEL_ASSIGNMENT_RIGHT_SIDE:
  93425. FLAC__ASSERT(header->channels == 2);
  93426. u = 9;
  93427. break;
  93428. case FLAC__CHANNEL_ASSIGNMENT_MID_SIDE:
  93429. FLAC__ASSERT(header->channels == 2);
  93430. u = 10;
  93431. break;
  93432. default:
  93433. FLAC__ASSERT(0);
  93434. }
  93435. if(!FLAC__bitwriter_write_raw_uint32(bw, u, FLAC__FRAME_HEADER_CHANNEL_ASSIGNMENT_LEN))
  93436. return false;
  93437. FLAC__ASSERT(header->bits_per_sample > 0 && header->bits_per_sample <= (1u << FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN));
  93438. switch(header->bits_per_sample) {
  93439. case 8 : u = 1; break;
  93440. case 12: u = 2; break;
  93441. case 16: u = 4; break;
  93442. case 20: u = 5; break;
  93443. case 24: u = 6; break;
  93444. default: u = 0; break;
  93445. }
  93446. if(!FLAC__bitwriter_write_raw_uint32(bw, u, FLAC__FRAME_HEADER_BITS_PER_SAMPLE_LEN))
  93447. return false;
  93448. if(!FLAC__bitwriter_write_raw_uint32(bw, 0, FLAC__FRAME_HEADER_ZERO_PAD_LEN))
  93449. return false;
  93450. if(header->number_type == FLAC__FRAME_NUMBER_TYPE_FRAME_NUMBER) {
  93451. if(!FLAC__bitwriter_write_utf8_uint32(bw, header->number.frame_number))
  93452. return false;
  93453. }
  93454. else {
  93455. if(!FLAC__bitwriter_write_utf8_uint64(bw, header->number.sample_number))
  93456. return false;
  93457. }
  93458. if(blocksize_hint)
  93459. if(!FLAC__bitwriter_write_raw_uint32(bw, header->blocksize-1, (blocksize_hint==6)? 8:16))
  93460. return false;
  93461. switch(sample_rate_hint) {
  93462. case 12:
  93463. if(!FLAC__bitwriter_write_raw_uint32(bw, header->sample_rate / 1000, 8))
  93464. return false;
  93465. break;
  93466. case 13:
  93467. if(!FLAC__bitwriter_write_raw_uint32(bw, header->sample_rate, 16))
  93468. return false;
  93469. break;
  93470. case 14:
  93471. if(!FLAC__bitwriter_write_raw_uint32(bw, header->sample_rate / 10, 16))
  93472. return false;
  93473. break;
  93474. }
  93475. if(!FLAC__bitwriter_get_write_crc8(bw, &crc))
  93476. return false;
  93477. if(!FLAC__bitwriter_write_raw_uint32(bw, crc, FLAC__FRAME_HEADER_CRC_LEN))
  93478. return false;
  93479. return true;
  93480. }
  93481. FLAC__bool FLAC__subframe_add_constant(const FLAC__Subframe_Constant *subframe, unsigned subframe_bps, unsigned wasted_bits, FLAC__BitWriter *bw)
  93482. {
  93483. FLAC__bool ok;
  93484. ok =
  93485. 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) &&
  93486. (wasted_bits? FLAC__bitwriter_write_unary_unsigned(bw, wasted_bits-1) : true) &&
  93487. FLAC__bitwriter_write_raw_int32(bw, subframe->value, subframe_bps)
  93488. ;
  93489. return ok;
  93490. }
  93491. FLAC__bool FLAC__subframe_add_fixed(const FLAC__Subframe_Fixed *subframe, unsigned residual_samples, unsigned subframe_bps, unsigned wasted_bits, FLAC__BitWriter *bw)
  93492. {
  93493. unsigned i;
  93494. 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))
  93495. return false;
  93496. if(wasted_bits)
  93497. if(!FLAC__bitwriter_write_unary_unsigned(bw, wasted_bits-1))
  93498. return false;
  93499. for(i = 0; i < subframe->order; i++)
  93500. if(!FLAC__bitwriter_write_raw_int32(bw, subframe->warmup[i], subframe_bps))
  93501. return false;
  93502. if(!add_entropy_coding_method_(bw, &subframe->entropy_coding_method))
  93503. return false;
  93504. switch(subframe->entropy_coding_method.type) {
  93505. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE:
  93506. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2:
  93507. if(!add_residual_partitioned_rice_(
  93508. bw,
  93509. subframe->residual,
  93510. residual_samples,
  93511. subframe->order,
  93512. subframe->entropy_coding_method.data.partitioned_rice.contents->parameters,
  93513. subframe->entropy_coding_method.data.partitioned_rice.contents->raw_bits,
  93514. subframe->entropy_coding_method.data.partitioned_rice.order,
  93515. subframe->entropy_coding_method.type == FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2
  93516. ))
  93517. return false;
  93518. break;
  93519. default:
  93520. FLAC__ASSERT(0);
  93521. }
  93522. return true;
  93523. }
  93524. FLAC__bool FLAC__subframe_add_lpc(const FLAC__Subframe_LPC *subframe, unsigned residual_samples, unsigned subframe_bps, unsigned wasted_bits, FLAC__BitWriter *bw)
  93525. {
  93526. unsigned i;
  93527. 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))
  93528. return false;
  93529. if(wasted_bits)
  93530. if(!FLAC__bitwriter_write_unary_unsigned(bw, wasted_bits-1))
  93531. return false;
  93532. for(i = 0; i < subframe->order; i++)
  93533. if(!FLAC__bitwriter_write_raw_int32(bw, subframe->warmup[i], subframe_bps))
  93534. return false;
  93535. if(!FLAC__bitwriter_write_raw_uint32(bw, subframe->qlp_coeff_precision-1, FLAC__SUBFRAME_LPC_QLP_COEFF_PRECISION_LEN))
  93536. return false;
  93537. if(!FLAC__bitwriter_write_raw_int32(bw, subframe->quantization_level, FLAC__SUBFRAME_LPC_QLP_SHIFT_LEN))
  93538. return false;
  93539. for(i = 0; i < subframe->order; i++)
  93540. if(!FLAC__bitwriter_write_raw_int32(bw, subframe->qlp_coeff[i], subframe->qlp_coeff_precision))
  93541. return false;
  93542. if(!add_entropy_coding_method_(bw, &subframe->entropy_coding_method))
  93543. return false;
  93544. switch(subframe->entropy_coding_method.type) {
  93545. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE:
  93546. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2:
  93547. if(!add_residual_partitioned_rice_(
  93548. bw,
  93549. subframe->residual,
  93550. residual_samples,
  93551. subframe->order,
  93552. subframe->entropy_coding_method.data.partitioned_rice.contents->parameters,
  93553. subframe->entropy_coding_method.data.partitioned_rice.contents->raw_bits,
  93554. subframe->entropy_coding_method.data.partitioned_rice.order,
  93555. subframe->entropy_coding_method.type == FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2
  93556. ))
  93557. return false;
  93558. break;
  93559. default:
  93560. FLAC__ASSERT(0);
  93561. }
  93562. return true;
  93563. }
  93564. FLAC__bool FLAC__subframe_add_verbatim(const FLAC__Subframe_Verbatim *subframe, unsigned samples, unsigned subframe_bps, unsigned wasted_bits, FLAC__BitWriter *bw)
  93565. {
  93566. unsigned i;
  93567. const FLAC__int32 *signal = subframe->data;
  93568. 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))
  93569. return false;
  93570. if(wasted_bits)
  93571. if(!FLAC__bitwriter_write_unary_unsigned(bw, wasted_bits-1))
  93572. return false;
  93573. for(i = 0; i < samples; i++)
  93574. if(!FLAC__bitwriter_write_raw_int32(bw, signal[i], subframe_bps))
  93575. return false;
  93576. return true;
  93577. }
  93578. FLAC__bool add_entropy_coding_method_(FLAC__BitWriter *bw, const FLAC__EntropyCodingMethod *method)
  93579. {
  93580. if(!FLAC__bitwriter_write_raw_uint32(bw, method->type, FLAC__ENTROPY_CODING_METHOD_TYPE_LEN))
  93581. return false;
  93582. switch(method->type) {
  93583. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE:
  93584. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2:
  93585. if(!FLAC__bitwriter_write_raw_uint32(bw, method->data.partitioned_rice.order, FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ORDER_LEN))
  93586. return false;
  93587. break;
  93588. default:
  93589. FLAC__ASSERT(0);
  93590. }
  93591. return true;
  93592. }
  93593. 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)
  93594. {
  93595. const unsigned plen = is_extended? FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_PARAMETER_LEN : FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_PARAMETER_LEN;
  93596. const unsigned pesc = is_extended? FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_ESCAPE_PARAMETER : FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ESCAPE_PARAMETER;
  93597. if(partition_order == 0) {
  93598. unsigned i;
  93599. if(raw_bits[0] == 0) {
  93600. if(!FLAC__bitwriter_write_raw_uint32(bw, rice_parameters[0], plen))
  93601. return false;
  93602. if(!FLAC__bitwriter_write_rice_signed_block(bw, residual, residual_samples, rice_parameters[0]))
  93603. return false;
  93604. }
  93605. else {
  93606. FLAC__ASSERT(rice_parameters[0] == 0);
  93607. if(!FLAC__bitwriter_write_raw_uint32(bw, pesc, plen))
  93608. return false;
  93609. if(!FLAC__bitwriter_write_raw_uint32(bw, raw_bits[0], FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_RAW_LEN))
  93610. return false;
  93611. for(i = 0; i < residual_samples; i++) {
  93612. if(!FLAC__bitwriter_write_raw_int32(bw, residual[i], raw_bits[0]))
  93613. return false;
  93614. }
  93615. }
  93616. return true;
  93617. }
  93618. else {
  93619. unsigned i, j, k = 0, k_last = 0;
  93620. unsigned partition_samples;
  93621. const unsigned default_partition_samples = (residual_samples+predictor_order) >> partition_order;
  93622. for(i = 0; i < (1u<<partition_order); i++) {
  93623. partition_samples = default_partition_samples;
  93624. if(i == 0)
  93625. partition_samples -= predictor_order;
  93626. k += partition_samples;
  93627. if(raw_bits[i] == 0) {
  93628. if(!FLAC__bitwriter_write_raw_uint32(bw, rice_parameters[i], plen))
  93629. return false;
  93630. if(!FLAC__bitwriter_write_rice_signed_block(bw, residual+k_last, k-k_last, rice_parameters[i]))
  93631. return false;
  93632. }
  93633. else {
  93634. if(!FLAC__bitwriter_write_raw_uint32(bw, pesc, plen))
  93635. return false;
  93636. if(!FLAC__bitwriter_write_raw_uint32(bw, raw_bits[i], FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_RAW_LEN))
  93637. return false;
  93638. for(j = k_last; j < k; j++) {
  93639. if(!FLAC__bitwriter_write_raw_int32(bw, residual[j], raw_bits[i]))
  93640. return false;
  93641. }
  93642. }
  93643. k_last = k;
  93644. }
  93645. return true;
  93646. }
  93647. }
  93648. #endif
  93649. /*** End of inlined file: stream_encoder_framing.c ***/
  93650. /*** Start of inlined file: window_flac.c ***/
  93651. /*** Start of inlined file: juce_FlacHeader.h ***/
  93652. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  93653. // tasks..
  93654. #define VERSION "1.2.1"
  93655. #define FLAC__NO_DLL 1
  93656. #if JUCE_MSVC
  93657. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  93658. #endif
  93659. #if JUCE_MAC
  93660. #define FLAC__SYS_DARWIN 1
  93661. #endif
  93662. /*** End of inlined file: juce_FlacHeader.h ***/
  93663. #if JUCE_USE_FLAC
  93664. #if HAVE_CONFIG_H
  93665. # include <config.h>
  93666. #endif
  93667. #include <math.h>
  93668. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  93669. #ifndef M_PI
  93670. #define M_PI 3.14159265358979323846
  93671. #endif
  93672. void FLAC__window_bartlett(FLAC__real *window, const FLAC__int32 L)
  93673. {
  93674. const FLAC__int32 N = L - 1;
  93675. FLAC__int32 n;
  93676. if (L & 1) {
  93677. for (n = 0; n <= N/2; n++)
  93678. window[n] = 2.0f * n / (float)N;
  93679. for (; n <= N; n++)
  93680. window[n] = 2.0f - 2.0f * n / (float)N;
  93681. }
  93682. else {
  93683. for (n = 0; n <= L/2-1; n++)
  93684. window[n] = 2.0f * n / (float)N;
  93685. for (; n <= N; n++)
  93686. window[n] = 2.0f - 2.0f * (N-n) / (float)N;
  93687. }
  93688. }
  93689. void FLAC__window_bartlett_hann(FLAC__real *window, const FLAC__int32 L)
  93690. {
  93691. const FLAC__int32 N = L - 1;
  93692. FLAC__int32 n;
  93693. for (n = 0; n < L; n++)
  93694. 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)));
  93695. }
  93696. void FLAC__window_blackman(FLAC__real *window, const FLAC__int32 L)
  93697. {
  93698. const FLAC__int32 N = L - 1;
  93699. FLAC__int32 n;
  93700. for (n = 0; n < L; n++)
  93701. window[n] = (FLAC__real)(0.42f - 0.5f * cos(2.0f * M_PI * n / N) + 0.08f * cos(4.0f * M_PI * n / N));
  93702. }
  93703. void FLAC__window_blackman_harris_4term_92db_sidelobe(FLAC__real *window, const FLAC__int32 L)
  93704. {
  93705. const FLAC__int32 N = L - 1;
  93706. FLAC__int32 n;
  93707. for (n = 0; n <= N; n++)
  93708. 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));
  93709. }
  93710. void FLAC__window_connes(FLAC__real *window, const FLAC__int32 L)
  93711. {
  93712. const FLAC__int32 N = L - 1;
  93713. const double N2 = (double)N / 2.;
  93714. FLAC__int32 n;
  93715. for (n = 0; n <= N; n++) {
  93716. double k = ((double)n - N2) / N2;
  93717. k = 1.0f - k * k;
  93718. window[n] = (FLAC__real)(k * k);
  93719. }
  93720. }
  93721. void FLAC__window_flattop(FLAC__real *window, const FLAC__int32 L)
  93722. {
  93723. const FLAC__int32 N = L - 1;
  93724. FLAC__int32 n;
  93725. for (n = 0; n < L; n++)
  93726. 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));
  93727. }
  93728. void FLAC__window_gauss(FLAC__real *window, const FLAC__int32 L, const FLAC__real stddev)
  93729. {
  93730. const FLAC__int32 N = L - 1;
  93731. const double N2 = (double)N / 2.;
  93732. FLAC__int32 n;
  93733. for (n = 0; n <= N; n++) {
  93734. const double k = ((double)n - N2) / (stddev * N2);
  93735. window[n] = (FLAC__real)exp(-0.5f * k * k);
  93736. }
  93737. }
  93738. void FLAC__window_hamming(FLAC__real *window, const FLAC__int32 L)
  93739. {
  93740. const FLAC__int32 N = L - 1;
  93741. FLAC__int32 n;
  93742. for (n = 0; n < L; n++)
  93743. window[n] = (FLAC__real)(0.54f - 0.46f * cos(2.0f * M_PI * n / N));
  93744. }
  93745. void FLAC__window_hann(FLAC__real *window, const FLAC__int32 L)
  93746. {
  93747. const FLAC__int32 N = L - 1;
  93748. FLAC__int32 n;
  93749. for (n = 0; n < L; n++)
  93750. window[n] = (FLAC__real)(0.5f - 0.5f * cos(2.0f * M_PI * n / N));
  93751. }
  93752. void FLAC__window_kaiser_bessel(FLAC__real *window, const FLAC__int32 L)
  93753. {
  93754. const FLAC__int32 N = L - 1;
  93755. FLAC__int32 n;
  93756. for (n = 0; n < L; n++)
  93757. 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));
  93758. }
  93759. void FLAC__window_nuttall(FLAC__real *window, const FLAC__int32 L)
  93760. {
  93761. const FLAC__int32 N = L - 1;
  93762. FLAC__int32 n;
  93763. for (n = 0; n < L; n++)
  93764. 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));
  93765. }
  93766. void FLAC__window_rectangle(FLAC__real *window, const FLAC__int32 L)
  93767. {
  93768. FLAC__int32 n;
  93769. for (n = 0; n < L; n++)
  93770. window[n] = 1.0f;
  93771. }
  93772. void FLAC__window_triangle(FLAC__real *window, const FLAC__int32 L)
  93773. {
  93774. FLAC__int32 n;
  93775. if (L & 1) {
  93776. for (n = 1; n <= L+1/2; n++)
  93777. window[n-1] = 2.0f * n / ((float)L + 1.0f);
  93778. for (; n <= L; n++)
  93779. window[n-1] = - (float)(2 * (L - n + 1)) / ((float)L + 1.0f);
  93780. }
  93781. else {
  93782. for (n = 1; n <= L/2; n++)
  93783. window[n-1] = 2.0f * n / (float)L;
  93784. for (; n <= L; n++)
  93785. window[n-1] = ((float)(2 * (L - n)) + 1.0f) / (float)L;
  93786. }
  93787. }
  93788. void FLAC__window_tukey(FLAC__real *window, const FLAC__int32 L, const FLAC__real p)
  93789. {
  93790. if (p <= 0.0)
  93791. FLAC__window_rectangle(window, L);
  93792. else if (p >= 1.0)
  93793. FLAC__window_hann(window, L);
  93794. else {
  93795. const FLAC__int32 Np = (FLAC__int32)(p / 2.0f * L) - 1;
  93796. FLAC__int32 n;
  93797. FLAC__window_rectangle(window, L);
  93798. if (Np > 0) {
  93799. for (n = 0; n <= Np; n++) {
  93800. window[n] = (FLAC__real)(0.5f - 0.5f * cos(M_PI * n / Np));
  93801. window[L-Np-1+n] = (FLAC__real)(0.5f - 0.5f * cos(M_PI * (n+Np) / Np));
  93802. }
  93803. }
  93804. }
  93805. }
  93806. void FLAC__window_welch(FLAC__real *window, const FLAC__int32 L)
  93807. {
  93808. const FLAC__int32 N = L - 1;
  93809. const double N2 = (double)N / 2.;
  93810. FLAC__int32 n;
  93811. for (n = 0; n <= N; n++) {
  93812. const double k = ((double)n - N2) / N2;
  93813. window[n] = (FLAC__real)(1.0f - k * k);
  93814. }
  93815. }
  93816. #endif /* !defined FLAC__INTEGER_ONLY_LIBRARY */
  93817. #endif
  93818. /*** End of inlined file: window_flac.c ***/
  93819. #else
  93820. #include <FLAC/all.h>
  93821. #endif
  93822. }
  93823. #ifdef _MSC_VER
  93824. #pragma warning (pop)
  93825. #endif
  93826. BEGIN_JUCE_NAMESPACE
  93827. static const char* const flacFormatName = "FLAC file";
  93828. static const tchar* const flacExtensions[] = { T(".flac"), 0 };
  93829. class FlacReader : public AudioFormatReader
  93830. {
  93831. public:
  93832. FlacReader (InputStream* const in)
  93833. : AudioFormatReader (in, TRANS (flacFormatName)),
  93834. reservoir (2, 0),
  93835. reservoirStart (0),
  93836. samplesInReservoir (0),
  93837. scanningForLength (false)
  93838. {
  93839. using namespace FlacNamespace;
  93840. lengthInSamples = 0;
  93841. decoder = FLAC__stream_decoder_new();
  93842. ok = FLAC__stream_decoder_init_stream (decoder,
  93843. readCallback_, seekCallback_, tellCallback_, lengthCallback_,
  93844. eofCallback_, writeCallback_, metadataCallback_, errorCallback_,
  93845. (void*) this) == FLAC__STREAM_DECODER_INIT_STATUS_OK;
  93846. if (ok)
  93847. {
  93848. FLAC__stream_decoder_process_until_end_of_metadata (decoder);
  93849. if (lengthInSamples == 0 && sampleRate > 0)
  93850. {
  93851. // the length hasn't been stored in the metadata, so we'll need to
  93852. // work it out the length the hard way, by scanning the whole file..
  93853. scanningForLength = true;
  93854. FLAC__stream_decoder_process_until_end_of_stream (decoder);
  93855. scanningForLength = false;
  93856. const int64 tempLength = lengthInSamples;
  93857. FLAC__stream_decoder_reset (decoder);
  93858. FLAC__stream_decoder_process_until_end_of_metadata (decoder);
  93859. lengthInSamples = tempLength;
  93860. }
  93861. }
  93862. }
  93863. ~FlacReader()
  93864. {
  93865. FlacNamespace::FLAC__stream_decoder_delete (decoder);
  93866. }
  93867. void useMetadata (const FlacNamespace::FLAC__StreamMetadata_StreamInfo& info)
  93868. {
  93869. sampleRate = info.sample_rate;
  93870. bitsPerSample = info.bits_per_sample;
  93871. lengthInSamples = (unsigned int) info.total_samples;
  93872. numChannels = info.channels;
  93873. reservoir.setSize (numChannels, 2 * info.max_blocksize, false, false, true);
  93874. }
  93875. // returns the number of samples read
  93876. bool readSamples (int** destSamples, int numDestChannels, int startOffsetInDestBuffer,
  93877. int64 startSampleInFile, int numSamples)
  93878. {
  93879. using namespace FlacNamespace;
  93880. if (! ok)
  93881. return false;
  93882. while (numSamples > 0)
  93883. {
  93884. if (startSampleInFile >= reservoirStart
  93885. && startSampleInFile < reservoirStart + samplesInReservoir)
  93886. {
  93887. const int num = (int) jmin ((int64) numSamples,
  93888. reservoirStart + samplesInReservoir - startSampleInFile);
  93889. jassert (num > 0);
  93890. for (int i = jmin (numDestChannels, reservoir.getNumChannels()); --i >= 0;)
  93891. if (destSamples[i] != 0)
  93892. memcpy (destSamples[i] + startOffsetInDestBuffer,
  93893. reservoir.getSampleData (i, (int) (startSampleInFile - reservoirStart)),
  93894. sizeof (int) * num);
  93895. startOffsetInDestBuffer += num;
  93896. startSampleInFile += num;
  93897. numSamples -= num;
  93898. }
  93899. else
  93900. {
  93901. if (startSampleInFile >= (int) lengthInSamples)
  93902. {
  93903. samplesInReservoir = 0;
  93904. }
  93905. else if (startSampleInFile < reservoirStart
  93906. || startSampleInFile > reservoirStart + jmax (samplesInReservoir, 511))
  93907. {
  93908. // had some problems with flac crashing if the read pos is aligned more
  93909. // accurately than this. Probably fixed in newer versions of the library, though.
  93910. reservoirStart = (int) (startSampleInFile & ~511);
  93911. samplesInReservoir = 0;
  93912. FLAC__stream_decoder_seek_absolute (decoder, (FLAC__uint64) reservoirStart);
  93913. }
  93914. else
  93915. {
  93916. reservoirStart += samplesInReservoir;
  93917. samplesInReservoir = 0;
  93918. FLAC__stream_decoder_process_single (decoder);
  93919. }
  93920. if (samplesInReservoir == 0)
  93921. break;
  93922. }
  93923. }
  93924. if (numSamples > 0)
  93925. {
  93926. for (int i = numDestChannels; --i >= 0;)
  93927. if (destSamples[i] != 0)
  93928. zeromem (destSamples[i] + startOffsetInDestBuffer,
  93929. sizeof (int) * numSamples);
  93930. }
  93931. return true;
  93932. }
  93933. void useSamples (const FlacNamespace::FLAC__int32* const buffer[], int numSamples)
  93934. {
  93935. if (scanningForLength)
  93936. {
  93937. lengthInSamples += numSamples;
  93938. }
  93939. else
  93940. {
  93941. if (numSamples > reservoir.getNumSamples())
  93942. reservoir.setSize (numChannels, numSamples, false, false, true);
  93943. const int bitsToShift = 32 - bitsPerSample;
  93944. for (int i = 0; i < (int) numChannels; ++i)
  93945. {
  93946. const FlacNamespace::FLAC__int32* src = buffer[i];
  93947. int n = i;
  93948. while (src == 0 && n > 0)
  93949. src = buffer [--n];
  93950. if (src != 0)
  93951. {
  93952. int* dest = (int*) reservoir.getSampleData(i);
  93953. for (int j = 0; j < numSamples; ++j)
  93954. dest[j] = src[j] << bitsToShift;
  93955. }
  93956. }
  93957. samplesInReservoir = numSamples;
  93958. }
  93959. }
  93960. static FlacNamespace::FLAC__StreamDecoderReadStatus readCallback_ (const FlacNamespace::FLAC__StreamDecoder*, FlacNamespace::FLAC__byte buffer[], size_t* bytes, void* client_data)
  93961. {
  93962. using namespace FlacNamespace;
  93963. *bytes = (unsigned int) ((const FlacReader*) client_data)->input->read (buffer, (int) *bytes);
  93964. return FLAC__STREAM_DECODER_READ_STATUS_CONTINUE;
  93965. }
  93966. static FlacNamespace::FLAC__StreamDecoderSeekStatus seekCallback_ (const FlacNamespace::FLAC__StreamDecoder*, FlacNamespace::FLAC__uint64 absolute_byte_offset, void* client_data)
  93967. {
  93968. using namespace FlacNamespace;
  93969. ((const FlacReader*) client_data)->input->setPosition ((int) absolute_byte_offset);
  93970. return FLAC__STREAM_DECODER_SEEK_STATUS_OK;
  93971. }
  93972. static FlacNamespace::FLAC__StreamDecoderTellStatus tellCallback_ (const FlacNamespace::FLAC__StreamDecoder*, FlacNamespace::FLAC__uint64* absolute_byte_offset, void* client_data)
  93973. {
  93974. using namespace FlacNamespace;
  93975. *absolute_byte_offset = ((const FlacReader*) client_data)->input->getPosition();
  93976. return FLAC__STREAM_DECODER_TELL_STATUS_OK;
  93977. }
  93978. static FlacNamespace::FLAC__StreamDecoderLengthStatus lengthCallback_ (const FlacNamespace::FLAC__StreamDecoder*, FlacNamespace::FLAC__uint64* stream_length, void* client_data)
  93979. {
  93980. using namespace FlacNamespace;
  93981. *stream_length = ((const FlacReader*) client_data)->input->getTotalLength();
  93982. return FLAC__STREAM_DECODER_LENGTH_STATUS_OK;
  93983. }
  93984. static FlacNamespace::FLAC__bool eofCallback_ (const FlacNamespace::FLAC__StreamDecoder*, void* client_data)
  93985. {
  93986. return ((const FlacReader*) client_data)->input->isExhausted();
  93987. }
  93988. static FlacNamespace::FLAC__StreamDecoderWriteStatus writeCallback_ (const FlacNamespace::FLAC__StreamDecoder*,
  93989. const FlacNamespace::FLAC__Frame* frame,
  93990. const FlacNamespace::FLAC__int32* const buffer[],
  93991. void* client_data)
  93992. {
  93993. using namespace FlacNamespace;
  93994. ((FlacReader*) client_data)->useSamples (buffer, frame->header.blocksize);
  93995. return FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE;
  93996. }
  93997. static void metadataCallback_ (const FlacNamespace::FLAC__StreamDecoder*,
  93998. const FlacNamespace::FLAC__StreamMetadata* metadata,
  93999. void* client_data)
  94000. {
  94001. ((FlacReader*) client_data)->useMetadata (metadata->data.stream_info);
  94002. }
  94003. static void errorCallback_ (const FlacNamespace::FLAC__StreamDecoder*, FlacNamespace::FLAC__StreamDecoderErrorStatus, void*)
  94004. {
  94005. }
  94006. juce_UseDebuggingNewOperator
  94007. private:
  94008. FlacNamespace::FLAC__StreamDecoder* decoder;
  94009. AudioSampleBuffer reservoir;
  94010. int reservoirStart, samplesInReservoir;
  94011. bool ok, scanningForLength;
  94012. FlacReader (const FlacReader&);
  94013. FlacReader& operator= (const FlacReader&);
  94014. };
  94015. class FlacWriter : public AudioFormatWriter
  94016. {
  94017. public:
  94018. FlacWriter (OutputStream* const out,
  94019. const double sampleRate_,
  94020. const int numChannels_,
  94021. const int bitsPerSample_)
  94022. : AudioFormatWriter (out, TRANS (flacFormatName),
  94023. sampleRate_,
  94024. numChannels_,
  94025. bitsPerSample_)
  94026. {
  94027. using namespace FlacNamespace;
  94028. encoder = FLAC__stream_encoder_new();
  94029. FLAC__stream_encoder_set_do_mid_side_stereo (encoder, numChannels == 2);
  94030. FLAC__stream_encoder_set_loose_mid_side_stereo (encoder, numChannels == 2);
  94031. FLAC__stream_encoder_set_channels (encoder, numChannels);
  94032. FLAC__stream_encoder_set_bits_per_sample (encoder, jmin ((unsigned int) 24, bitsPerSample));
  94033. FLAC__stream_encoder_set_sample_rate (encoder, (unsigned int) sampleRate);
  94034. FLAC__stream_encoder_set_blocksize (encoder, 2048);
  94035. FLAC__stream_encoder_set_do_escape_coding (encoder, true);
  94036. ok = FLAC__stream_encoder_init_stream (encoder,
  94037. encodeWriteCallback, encodeSeekCallback,
  94038. encodeTellCallback, encodeMetadataCallback,
  94039. (void*) this) == FLAC__STREAM_ENCODER_INIT_STATUS_OK;
  94040. }
  94041. ~FlacWriter()
  94042. {
  94043. if (ok)
  94044. {
  94045. FlacNamespace::FLAC__stream_encoder_finish (encoder);
  94046. output->flush();
  94047. }
  94048. else
  94049. {
  94050. output = 0; // to stop the base class deleting this, as it needs to be returned
  94051. // to the caller of createWriter()
  94052. }
  94053. FlacNamespace::FLAC__stream_encoder_delete (encoder);
  94054. }
  94055. bool write (const int** samplesToWrite, int numSamples)
  94056. {
  94057. using namespace FlacNamespace;
  94058. if (! ok)
  94059. return false;
  94060. int* buf[3];
  94061. const int bitsToShift = 32 - bitsPerSample;
  94062. if (bitsToShift > 0)
  94063. {
  94064. const int numChannelsToWrite = (samplesToWrite[1] == 0) ? 1 : 2;
  94065. temp.setSize (sizeof (int) * numSamples * numChannelsToWrite);
  94066. buf[0] = (int*) temp.getData();
  94067. buf[1] = buf[0] + numSamples;
  94068. buf[2] = 0;
  94069. for (int i = numChannelsToWrite; --i >= 0;)
  94070. {
  94071. if (samplesToWrite[i] != 0)
  94072. {
  94073. for (int j = 0; j < numSamples; ++j)
  94074. buf [i][j] = (samplesToWrite [i][j] >> bitsToShift);
  94075. }
  94076. }
  94077. samplesToWrite = (const int**) buf;
  94078. }
  94079. return FLAC__stream_encoder_process (encoder,
  94080. (const FLAC__int32**) samplesToWrite,
  94081. numSamples) != 0;
  94082. }
  94083. bool writeData (const void* const data, const int size) const
  94084. {
  94085. return output->write (data, size);
  94086. }
  94087. static void packUint32 (FlacNamespace::FLAC__uint32 val, FlacNamespace::FLAC__byte* b, const int bytes)
  94088. {
  94089. using namespace FlacNamespace;
  94090. b += bytes;
  94091. for (int i = 0; i < bytes; ++i)
  94092. {
  94093. *(--b) = (FLAC__byte) (val & 0xff);
  94094. val >>= 8;
  94095. }
  94096. }
  94097. void writeMetaData (const FlacNamespace::FLAC__StreamMetadata* metadata)
  94098. {
  94099. using namespace FlacNamespace;
  94100. const FLAC__StreamMetadata_StreamInfo& info = metadata->data.stream_info;
  94101. unsigned char buffer [FLAC__STREAM_METADATA_STREAMINFO_LENGTH];
  94102. const unsigned int channelsMinus1 = info.channels - 1;
  94103. const unsigned int bitsMinus1 = info.bits_per_sample - 1;
  94104. packUint32 (info.min_blocksize, buffer, 2);
  94105. packUint32 (info.max_blocksize, buffer + 2, 2);
  94106. packUint32 (info.min_framesize, buffer + 4, 3);
  94107. packUint32 (info.max_framesize, buffer + 7, 3);
  94108. buffer[10] = (uint8) ((info.sample_rate >> 12) & 0xff);
  94109. buffer[11] = (uint8) ((info.sample_rate >> 4) & 0xff);
  94110. buffer[12] = (uint8) (((info.sample_rate & 0x0f) << 4) | (channelsMinus1 << 1) | (bitsMinus1 >> 4));
  94111. buffer[13] = (FLAC__byte) (((bitsMinus1 & 0x0f) << 4) | (unsigned int) ((info.total_samples >> 32) & 0x0f));
  94112. packUint32 ((FLAC__uint32) info.total_samples, buffer + 14, 4);
  94113. memcpy (buffer + 18, info.md5sum, 16);
  94114. const bool seekOk = output->setPosition (4);
  94115. (void) seekOk;
  94116. // if this fails, you've given it an output stream that can't seek! It needs
  94117. // to be able to seek back to write the header
  94118. jassert (seekOk);
  94119. output->writeIntBigEndian (FLAC__STREAM_METADATA_STREAMINFO_LENGTH);
  94120. output->write (buffer, FLAC__STREAM_METADATA_STREAMINFO_LENGTH);
  94121. }
  94122. static FlacNamespace::FLAC__StreamEncoderWriteStatus encodeWriteCallback (const FlacNamespace::FLAC__StreamEncoder*,
  94123. const FlacNamespace::FLAC__byte buffer[],
  94124. size_t bytes,
  94125. unsigned int /*samples*/,
  94126. unsigned int /*current_frame*/,
  94127. void* client_data)
  94128. {
  94129. using namespace FlacNamespace;
  94130. return ((FlacWriter*) client_data)->writeData (buffer, (int) bytes)
  94131. ? FLAC__STREAM_ENCODER_WRITE_STATUS_OK
  94132. : FLAC__STREAM_ENCODER_WRITE_STATUS_FATAL_ERROR;
  94133. }
  94134. static FlacNamespace::FLAC__StreamEncoderSeekStatus encodeSeekCallback (const FlacNamespace::FLAC__StreamEncoder*, FlacNamespace::FLAC__uint64, void*)
  94135. {
  94136. using namespace FlacNamespace;
  94137. return FLAC__STREAM_ENCODER_SEEK_STATUS_UNSUPPORTED;
  94138. }
  94139. static FlacNamespace::FLAC__StreamEncoderTellStatus encodeTellCallback (const FlacNamespace::FLAC__StreamEncoder*, FlacNamespace::FLAC__uint64* absolute_byte_offset, void* client_data)
  94140. {
  94141. using namespace FlacNamespace;
  94142. if (client_data == 0)
  94143. return FLAC__STREAM_ENCODER_TELL_STATUS_UNSUPPORTED;
  94144. *absolute_byte_offset = (FLAC__uint64) ((FlacWriter*) client_data)->output->getPosition();
  94145. return FLAC__STREAM_ENCODER_TELL_STATUS_OK;
  94146. }
  94147. static void encodeMetadataCallback (const FlacNamespace::FLAC__StreamEncoder*,
  94148. const FlacNamespace::FLAC__StreamMetadata* metadata,
  94149. void* client_data)
  94150. {
  94151. ((FlacWriter*) client_data)->writeMetaData (metadata);
  94152. }
  94153. juce_UseDebuggingNewOperator
  94154. bool ok;
  94155. private:
  94156. FlacNamespace::FLAC__StreamEncoder* encoder;
  94157. MemoryBlock temp;
  94158. FlacWriter (const FlacWriter&);
  94159. FlacWriter& operator= (const FlacWriter&);
  94160. };
  94161. FlacAudioFormat::FlacAudioFormat()
  94162. : AudioFormat (TRANS (flacFormatName), (const tchar**) flacExtensions)
  94163. {
  94164. }
  94165. FlacAudioFormat::~FlacAudioFormat()
  94166. {
  94167. }
  94168. const Array <int> FlacAudioFormat::getPossibleSampleRates()
  94169. {
  94170. const int rates[] = { 22050, 32000, 44100, 48000, 88200, 96000, 0 };
  94171. return Array <int> (rates);
  94172. }
  94173. const Array <int> FlacAudioFormat::getPossibleBitDepths()
  94174. {
  94175. const int depths[] = { 16, 24, 0 };
  94176. return Array <int> (depths);
  94177. }
  94178. bool FlacAudioFormat::canDoStereo()
  94179. {
  94180. return true;
  94181. }
  94182. bool FlacAudioFormat::canDoMono()
  94183. {
  94184. return true;
  94185. }
  94186. bool FlacAudioFormat::isCompressed()
  94187. {
  94188. return true;
  94189. }
  94190. AudioFormatReader* FlacAudioFormat::createReaderFor (InputStream* in,
  94191. const bool deleteStreamIfOpeningFails)
  94192. {
  94193. ScopedPointer <FlacReader> r (new FlacReader (in));
  94194. if (r->sampleRate != 0)
  94195. return r.release();
  94196. if (! deleteStreamIfOpeningFails)
  94197. r->input = 0;
  94198. return 0;
  94199. }
  94200. AudioFormatWriter* FlacAudioFormat::createWriterFor (OutputStream* out,
  94201. double sampleRate,
  94202. unsigned int numberOfChannels,
  94203. int bitsPerSample,
  94204. const StringPairArray& /*metadataValues*/,
  94205. int /*qualityOptionIndex*/)
  94206. {
  94207. if (getPossibleBitDepths().contains (bitsPerSample))
  94208. {
  94209. ScopedPointer <FlacWriter> w (new FlacWriter (out,
  94210. sampleRate,
  94211. numberOfChannels,
  94212. bitsPerSample));
  94213. if (w->ok)
  94214. return w.release();
  94215. }
  94216. return 0;
  94217. }
  94218. END_JUCE_NAMESPACE
  94219. #endif
  94220. /*** End of inlined file: juce_FlacAudioFormat.cpp ***/
  94221. /*** Start of inlined file: juce_OggVorbisAudioFormat.cpp ***/
  94222. #if JUCE_USE_OGGVORBIS
  94223. #if JUCE_MAC
  94224. #define __MACOSX__ 1
  94225. #endif
  94226. namespace OggVorbisNamespace
  94227. {
  94228. #if JUCE_INCLUDE_OGGVORBIS_CODE
  94229. /*** Start of inlined file: vorbisenc.h ***/
  94230. #ifndef _OV_ENC_H_
  94231. #define _OV_ENC_H_
  94232. #ifdef __cplusplus
  94233. extern "C"
  94234. {
  94235. #endif /* __cplusplus */
  94236. /*** Start of inlined file: codec.h ***/
  94237. #ifndef _vorbis_codec_h_
  94238. #define _vorbis_codec_h_
  94239. #ifdef __cplusplus
  94240. extern "C"
  94241. {
  94242. #endif /* __cplusplus */
  94243. /*** Start of inlined file: ogg.h ***/
  94244. #ifndef _OGG_H
  94245. #define _OGG_H
  94246. #ifdef __cplusplus
  94247. extern "C" {
  94248. #endif
  94249. /*** Start of inlined file: os_types.h ***/
  94250. #ifndef _OS_TYPES_H
  94251. #define _OS_TYPES_H
  94252. #define _ogg_malloc malloc
  94253. #define _ogg_calloc calloc
  94254. #define _ogg_realloc realloc
  94255. #define _ogg_free free
  94256. #if defined(_WIN32)
  94257. # if defined(__CYGWIN__)
  94258. # include <_G_config.h>
  94259. typedef _G_int64_t ogg_int64_t;
  94260. typedef _G_int32_t ogg_int32_t;
  94261. typedef _G_uint32_t ogg_uint32_t;
  94262. typedef _G_int16_t ogg_int16_t;
  94263. typedef _G_uint16_t ogg_uint16_t;
  94264. # elif defined(__MINGW32__)
  94265. typedef short ogg_int16_t;
  94266. typedef unsigned short ogg_uint16_t;
  94267. typedef int ogg_int32_t;
  94268. typedef unsigned int ogg_uint32_t;
  94269. typedef long long ogg_int64_t;
  94270. typedef unsigned long long ogg_uint64_t;
  94271. # elif defined(__MWERKS__)
  94272. typedef long long ogg_int64_t;
  94273. typedef int ogg_int32_t;
  94274. typedef unsigned int ogg_uint32_t;
  94275. typedef short ogg_int16_t;
  94276. typedef unsigned short ogg_uint16_t;
  94277. # else
  94278. typedef __int64 ogg_int64_t;
  94279. typedef __int32 ogg_int32_t;
  94280. typedef unsigned __int32 ogg_uint32_t;
  94281. typedef __int16 ogg_int16_t;
  94282. typedef unsigned __int16 ogg_uint16_t;
  94283. # endif
  94284. #elif defined(__MACOS__)
  94285. # include <sys/types.h>
  94286. typedef SInt16 ogg_int16_t;
  94287. typedef UInt16 ogg_uint16_t;
  94288. typedef SInt32 ogg_int32_t;
  94289. typedef UInt32 ogg_uint32_t;
  94290. typedef SInt64 ogg_int64_t;
  94291. #elif defined(__MACOSX__) /* MacOS X Framework build */
  94292. # include <sys/types.h>
  94293. typedef int16_t ogg_int16_t;
  94294. typedef u_int16_t ogg_uint16_t;
  94295. typedef int32_t ogg_int32_t;
  94296. typedef u_int32_t ogg_uint32_t;
  94297. typedef int64_t ogg_int64_t;
  94298. #elif defined(__BEOS__)
  94299. # include <inttypes.h>
  94300. typedef int16_t ogg_int16_t;
  94301. typedef u_int16_t ogg_uint16_t;
  94302. typedef int32_t ogg_int32_t;
  94303. typedef u_int32_t ogg_uint32_t;
  94304. typedef int64_t ogg_int64_t;
  94305. #elif defined (__EMX__)
  94306. typedef short ogg_int16_t;
  94307. typedef unsigned short ogg_uint16_t;
  94308. typedef int ogg_int32_t;
  94309. typedef unsigned int ogg_uint32_t;
  94310. typedef long long ogg_int64_t;
  94311. #elif defined (DJGPP)
  94312. typedef short ogg_int16_t;
  94313. typedef int ogg_int32_t;
  94314. typedef unsigned int ogg_uint32_t;
  94315. typedef long long ogg_int64_t;
  94316. #elif defined(R5900)
  94317. typedef long ogg_int64_t;
  94318. typedef int ogg_int32_t;
  94319. typedef unsigned ogg_uint32_t;
  94320. typedef short ogg_int16_t;
  94321. #elif defined(__SYMBIAN32__)
  94322. typedef signed short ogg_int16_t;
  94323. typedef unsigned short ogg_uint16_t;
  94324. typedef signed int ogg_int32_t;
  94325. typedef unsigned int ogg_uint32_t;
  94326. typedef long long int ogg_int64_t;
  94327. #else
  94328. # include <sys/types.h>
  94329. /*** Start of inlined file: config_types.h ***/
  94330. #ifndef __CONFIG_TYPES_H__
  94331. #define __CONFIG_TYPES_H__
  94332. typedef int16_t ogg_int16_t;
  94333. typedef unsigned short ogg_uint16_t;
  94334. typedef int32_t ogg_int32_t;
  94335. typedef unsigned int ogg_uint32_t;
  94336. typedef int64_t ogg_int64_t;
  94337. #endif
  94338. /*** End of inlined file: config_types.h ***/
  94339. #endif
  94340. #endif /* _OS_TYPES_H */
  94341. /*** End of inlined file: os_types.h ***/
  94342. typedef struct {
  94343. long endbyte;
  94344. int endbit;
  94345. unsigned char *buffer;
  94346. unsigned char *ptr;
  94347. long storage;
  94348. } oggpack_buffer;
  94349. typedef struct {
  94350. unsigned char *header;
  94351. long header_len;
  94352. unsigned char *body;
  94353. long body_len;
  94354. } ogg_page;
  94355. ogg_uint32_t ogg_bitreverse(ogg_uint32_t x){
  94356. x= ((x>>16)&0x0000ffffUL) | ((x<<16)&0xffff0000UL);
  94357. x= ((x>> 8)&0x00ff00ffUL) | ((x<< 8)&0xff00ff00UL);
  94358. x= ((x>> 4)&0x0f0f0f0fUL) | ((x<< 4)&0xf0f0f0f0UL);
  94359. x= ((x>> 2)&0x33333333UL) | ((x<< 2)&0xccccccccUL);
  94360. return((x>> 1)&0x55555555UL) | ((x<< 1)&0xaaaaaaaaUL);
  94361. }
  94362. typedef struct {
  94363. unsigned char *body_data; /* bytes from packet bodies */
  94364. long body_storage; /* storage elements allocated */
  94365. long body_fill; /* elements stored; fill mark */
  94366. long body_returned; /* elements of fill returned */
  94367. int *lacing_vals; /* The values that will go to the segment table */
  94368. ogg_int64_t *granule_vals; /* granulepos values for headers. Not compact
  94369. this way, but it is simple coupled to the
  94370. lacing fifo */
  94371. long lacing_storage;
  94372. long lacing_fill;
  94373. long lacing_packet;
  94374. long lacing_returned;
  94375. unsigned char header[282]; /* working space for header encode */
  94376. int header_fill;
  94377. int e_o_s; /* set when we have buffered the last packet in the
  94378. logical bitstream */
  94379. int b_o_s; /* set after we've written the initial page
  94380. of a logical bitstream */
  94381. long serialno;
  94382. long pageno;
  94383. ogg_int64_t packetno; /* sequence number for decode; the framing
  94384. knows where there's a hole in the data,
  94385. but we need coupling so that the codec
  94386. (which is in a seperate abstraction
  94387. layer) also knows about the gap */
  94388. ogg_int64_t granulepos;
  94389. } ogg_stream_state;
  94390. typedef struct {
  94391. unsigned char *packet;
  94392. long bytes;
  94393. long b_o_s;
  94394. long e_o_s;
  94395. ogg_int64_t granulepos;
  94396. ogg_int64_t packetno; /* sequence number for decode; the framing
  94397. knows where there's a hole in the data,
  94398. but we need coupling so that the codec
  94399. (which is in a seperate abstraction
  94400. layer) also knows about the gap */
  94401. } ogg_packet;
  94402. typedef struct {
  94403. unsigned char *data;
  94404. int storage;
  94405. int fill;
  94406. int returned;
  94407. int unsynced;
  94408. int headerbytes;
  94409. int bodybytes;
  94410. } ogg_sync_state;
  94411. extern void oggpack_writeinit(oggpack_buffer *b);
  94412. extern void oggpack_writetrunc(oggpack_buffer *b,long bits);
  94413. extern void oggpack_writealign(oggpack_buffer *b);
  94414. extern void oggpack_writecopy(oggpack_buffer *b,void *source,long bits);
  94415. extern void oggpack_reset(oggpack_buffer *b);
  94416. extern void oggpack_writeclear(oggpack_buffer *b);
  94417. extern void oggpack_readinit(oggpack_buffer *b,unsigned char *buf,int bytes);
  94418. extern void oggpack_write(oggpack_buffer *b,unsigned long value,int bits);
  94419. extern long oggpack_look(oggpack_buffer *b,int bits);
  94420. extern long oggpack_look1(oggpack_buffer *b);
  94421. extern void oggpack_adv(oggpack_buffer *b,int bits);
  94422. extern void oggpack_adv1(oggpack_buffer *b);
  94423. extern long oggpack_read(oggpack_buffer *b,int bits);
  94424. extern long oggpack_read1(oggpack_buffer *b);
  94425. extern long oggpack_bytes(oggpack_buffer *b);
  94426. extern long oggpack_bits(oggpack_buffer *b);
  94427. extern unsigned char *oggpack_get_buffer(oggpack_buffer *b);
  94428. extern void oggpackB_writeinit(oggpack_buffer *b);
  94429. extern void oggpackB_writetrunc(oggpack_buffer *b,long bits);
  94430. extern void oggpackB_writealign(oggpack_buffer *b);
  94431. extern void oggpackB_writecopy(oggpack_buffer *b,void *source,long bits);
  94432. extern void oggpackB_reset(oggpack_buffer *b);
  94433. extern void oggpackB_writeclear(oggpack_buffer *b);
  94434. extern void oggpackB_readinit(oggpack_buffer *b,unsigned char *buf,int bytes);
  94435. extern void oggpackB_write(oggpack_buffer *b,unsigned long value,int bits);
  94436. extern long oggpackB_look(oggpack_buffer *b,int bits);
  94437. extern long oggpackB_look1(oggpack_buffer *b);
  94438. extern void oggpackB_adv(oggpack_buffer *b,int bits);
  94439. extern void oggpackB_adv1(oggpack_buffer *b);
  94440. extern long oggpackB_read(oggpack_buffer *b,int bits);
  94441. extern long oggpackB_read1(oggpack_buffer *b);
  94442. extern long oggpackB_bytes(oggpack_buffer *b);
  94443. extern long oggpackB_bits(oggpack_buffer *b);
  94444. extern unsigned char *oggpackB_get_buffer(oggpack_buffer *b);
  94445. extern int ogg_stream_packetin(ogg_stream_state *os, ogg_packet *op);
  94446. extern int ogg_stream_pageout(ogg_stream_state *os, ogg_page *og);
  94447. extern int ogg_stream_flush(ogg_stream_state *os, ogg_page *og);
  94448. extern int ogg_sync_init(ogg_sync_state *oy);
  94449. extern int ogg_sync_clear(ogg_sync_state *oy);
  94450. extern int ogg_sync_reset(ogg_sync_state *oy);
  94451. extern int ogg_sync_destroy(ogg_sync_state *oy);
  94452. extern char *ogg_sync_buffer(ogg_sync_state *oy, long size);
  94453. extern int ogg_sync_wrote(ogg_sync_state *oy, long bytes);
  94454. extern long ogg_sync_pageseek(ogg_sync_state *oy,ogg_page *og);
  94455. extern int ogg_sync_pageout(ogg_sync_state *oy, ogg_page *og);
  94456. extern int ogg_stream_pagein(ogg_stream_state *os, ogg_page *og);
  94457. extern int ogg_stream_packetout(ogg_stream_state *os,ogg_packet *op);
  94458. extern int ogg_stream_packetpeek(ogg_stream_state *os,ogg_packet *op);
  94459. extern int ogg_stream_init(ogg_stream_state *os,int serialno);
  94460. extern int ogg_stream_clear(ogg_stream_state *os);
  94461. extern int ogg_stream_reset(ogg_stream_state *os);
  94462. extern int ogg_stream_reset_serialno(ogg_stream_state *os,int serialno);
  94463. extern int ogg_stream_destroy(ogg_stream_state *os);
  94464. extern int ogg_stream_eos(ogg_stream_state *os);
  94465. extern void ogg_page_checksum_set(ogg_page *og);
  94466. extern int ogg_page_version(ogg_page *og);
  94467. extern int ogg_page_continued(ogg_page *og);
  94468. extern int ogg_page_bos(ogg_page *og);
  94469. extern int ogg_page_eos(ogg_page *og);
  94470. extern ogg_int64_t ogg_page_granulepos(ogg_page *og);
  94471. extern int ogg_page_serialno(ogg_page *og);
  94472. extern long ogg_page_pageno(ogg_page *og);
  94473. extern int ogg_page_packets(ogg_page *og);
  94474. extern void ogg_packet_clear(ogg_packet *op);
  94475. #ifdef __cplusplus
  94476. }
  94477. #endif
  94478. #endif /* _OGG_H */
  94479. /*** End of inlined file: ogg.h ***/
  94480. typedef struct vorbis_info{
  94481. int version;
  94482. int channels;
  94483. long rate;
  94484. long bitrate_upper;
  94485. long bitrate_nominal;
  94486. long bitrate_lower;
  94487. long bitrate_window;
  94488. void *codec_setup;
  94489. } vorbis_info;
  94490. typedef struct vorbis_dsp_state{
  94491. int analysisp;
  94492. vorbis_info *vi;
  94493. float **pcm;
  94494. float **pcmret;
  94495. int pcm_storage;
  94496. int pcm_current;
  94497. int pcm_returned;
  94498. int preextrapolate;
  94499. int eofflag;
  94500. long lW;
  94501. long W;
  94502. long nW;
  94503. long centerW;
  94504. ogg_int64_t granulepos;
  94505. ogg_int64_t sequence;
  94506. ogg_int64_t glue_bits;
  94507. ogg_int64_t time_bits;
  94508. ogg_int64_t floor_bits;
  94509. ogg_int64_t res_bits;
  94510. void *backend_state;
  94511. } vorbis_dsp_state;
  94512. typedef struct vorbis_block{
  94513. float **pcm; /* this is a pointer into local storage */
  94514. oggpack_buffer opb;
  94515. long lW;
  94516. long W;
  94517. long nW;
  94518. int pcmend;
  94519. int mode;
  94520. int eofflag;
  94521. ogg_int64_t granulepos;
  94522. ogg_int64_t sequence;
  94523. vorbis_dsp_state *vd; /* For read-only access of configuration */
  94524. void *localstore;
  94525. long localtop;
  94526. long localalloc;
  94527. long totaluse;
  94528. struct alloc_chain *reap;
  94529. long glue_bits;
  94530. long time_bits;
  94531. long floor_bits;
  94532. long res_bits;
  94533. void *internal;
  94534. } vorbis_block;
  94535. struct alloc_chain{
  94536. void *ptr;
  94537. struct alloc_chain *next;
  94538. };
  94539. typedef struct vorbis_comment{
  94540. char **user_comments;
  94541. int *comment_lengths;
  94542. int comments;
  94543. char *vendor;
  94544. } vorbis_comment;
  94545. extern void vorbis_info_init(vorbis_info *vi);
  94546. extern void vorbis_info_clear(vorbis_info *vi);
  94547. extern int vorbis_info_blocksize(vorbis_info *vi,int zo);
  94548. extern void vorbis_comment_init(vorbis_comment *vc);
  94549. extern void vorbis_comment_add(vorbis_comment *vc, char *comment);
  94550. extern void vorbis_comment_add_tag(vorbis_comment *vc,
  94551. const char *tag, char *contents);
  94552. extern char *vorbis_comment_query(vorbis_comment *vc, char *tag, int count);
  94553. extern int vorbis_comment_query_count(vorbis_comment *vc, char *tag);
  94554. extern void vorbis_comment_clear(vorbis_comment *vc);
  94555. extern int vorbis_block_init(vorbis_dsp_state *v, vorbis_block *vb);
  94556. extern int vorbis_block_clear(vorbis_block *vb);
  94557. extern void vorbis_dsp_clear(vorbis_dsp_state *v);
  94558. extern double vorbis_granule_time(vorbis_dsp_state *v,
  94559. ogg_int64_t granulepos);
  94560. extern int vorbis_analysis_init(vorbis_dsp_state *v,vorbis_info *vi);
  94561. extern int vorbis_commentheader_out(vorbis_comment *vc, ogg_packet *op);
  94562. extern int vorbis_analysis_headerout(vorbis_dsp_state *v,
  94563. vorbis_comment *vc,
  94564. ogg_packet *op,
  94565. ogg_packet *op_comm,
  94566. ogg_packet *op_code);
  94567. extern float **vorbis_analysis_buffer(vorbis_dsp_state *v,int vals);
  94568. extern int vorbis_analysis_wrote(vorbis_dsp_state *v,int vals);
  94569. extern int vorbis_analysis_blockout(vorbis_dsp_state *v,vorbis_block *vb);
  94570. extern int vorbis_analysis(vorbis_block *vb,ogg_packet *op);
  94571. extern int vorbis_bitrate_addblock(vorbis_block *vb);
  94572. extern int vorbis_bitrate_flushpacket(vorbis_dsp_state *vd,
  94573. ogg_packet *op);
  94574. extern int vorbis_synthesis_headerin(vorbis_info *vi,vorbis_comment *vc,
  94575. ogg_packet *op);
  94576. extern int vorbis_synthesis_init(vorbis_dsp_state *v,vorbis_info *vi);
  94577. extern int vorbis_synthesis_restart(vorbis_dsp_state *v);
  94578. extern int vorbis_synthesis(vorbis_block *vb,ogg_packet *op);
  94579. extern int vorbis_synthesis_trackonly(vorbis_block *vb,ogg_packet *op);
  94580. extern int vorbis_synthesis_blockin(vorbis_dsp_state *v,vorbis_block *vb);
  94581. extern int vorbis_synthesis_pcmout(vorbis_dsp_state *v,float ***pcm);
  94582. extern int vorbis_synthesis_lapout(vorbis_dsp_state *v,float ***pcm);
  94583. extern int vorbis_synthesis_read(vorbis_dsp_state *v,int samples);
  94584. extern long vorbis_packet_blocksize(vorbis_info *vi,ogg_packet *op);
  94585. extern int vorbis_synthesis_halfrate(vorbis_info *v,int flag);
  94586. extern int vorbis_synthesis_halfrate_p(vorbis_info *v);
  94587. #define OV_FALSE -1
  94588. #define OV_EOF -2
  94589. #define OV_HOLE -3
  94590. #define OV_EREAD -128
  94591. #define OV_EFAULT -129
  94592. #define OV_EIMPL -130
  94593. #define OV_EINVAL -131
  94594. #define OV_ENOTVORBIS -132
  94595. #define OV_EBADHEADER -133
  94596. #define OV_EVERSION -134
  94597. #define OV_ENOTAUDIO -135
  94598. #define OV_EBADPACKET -136
  94599. #define OV_EBADLINK -137
  94600. #define OV_ENOSEEK -138
  94601. #ifdef __cplusplus
  94602. }
  94603. #endif /* __cplusplus */
  94604. #endif
  94605. /*** End of inlined file: codec.h ***/
  94606. extern int vorbis_encode_init(vorbis_info *vi,
  94607. long channels,
  94608. long rate,
  94609. long max_bitrate,
  94610. long nominal_bitrate,
  94611. long min_bitrate);
  94612. extern int vorbis_encode_setup_managed(vorbis_info *vi,
  94613. long channels,
  94614. long rate,
  94615. long max_bitrate,
  94616. long nominal_bitrate,
  94617. long min_bitrate);
  94618. extern int vorbis_encode_setup_vbr(vorbis_info *vi,
  94619. long channels,
  94620. long rate,
  94621. float quality /* quality level from 0. (lo) to 1. (hi) */
  94622. );
  94623. extern int vorbis_encode_init_vbr(vorbis_info *vi,
  94624. long channels,
  94625. long rate,
  94626. float base_quality /* quality level from 0. (lo) to 1. (hi) */
  94627. );
  94628. extern int vorbis_encode_setup_init(vorbis_info *vi);
  94629. extern int vorbis_encode_ctl(vorbis_info *vi,int number,void *arg);
  94630. #define OV_ECTL_RATEMANAGE_GET 0x10
  94631. #define OV_ECTL_RATEMANAGE_SET 0x11
  94632. #define OV_ECTL_RATEMANAGE_AVG 0x12
  94633. #define OV_ECTL_RATEMANAGE_HARD 0x13
  94634. struct ovectl_ratemanage_arg {
  94635. int management_active;
  94636. long bitrate_hard_min;
  94637. long bitrate_hard_max;
  94638. double bitrate_hard_window;
  94639. long bitrate_av_lo;
  94640. long bitrate_av_hi;
  94641. double bitrate_av_window;
  94642. double bitrate_av_window_center;
  94643. };
  94644. #define OV_ECTL_RATEMANAGE2_GET 0x14
  94645. #define OV_ECTL_RATEMANAGE2_SET 0x15
  94646. struct ovectl_ratemanage2_arg {
  94647. int management_active;
  94648. long bitrate_limit_min_kbps;
  94649. long bitrate_limit_max_kbps;
  94650. long bitrate_limit_reservoir_bits;
  94651. double bitrate_limit_reservoir_bias;
  94652. long bitrate_average_kbps;
  94653. double bitrate_average_damping;
  94654. };
  94655. #define OV_ECTL_LOWPASS_GET 0x20
  94656. #define OV_ECTL_LOWPASS_SET 0x21
  94657. #define OV_ECTL_IBLOCK_GET 0x30
  94658. #define OV_ECTL_IBLOCK_SET 0x31
  94659. #ifdef __cplusplus
  94660. }
  94661. #endif /* __cplusplus */
  94662. #endif
  94663. /*** End of inlined file: vorbisenc.h ***/
  94664. /*** Start of inlined file: vorbisfile.h ***/
  94665. #ifndef _OV_FILE_H_
  94666. #define _OV_FILE_H_
  94667. #ifdef __cplusplus
  94668. extern "C"
  94669. {
  94670. #endif /* __cplusplus */
  94671. #include <stdio.h>
  94672. typedef struct {
  94673. size_t (*read_func) (void *ptr, size_t size, size_t nmemb, void *datasource);
  94674. int (*seek_func) (void *datasource, ogg_int64_t offset, int whence);
  94675. int (*close_func) (void *datasource);
  94676. long (*tell_func) (void *datasource);
  94677. } ov_callbacks;
  94678. #define NOTOPEN 0
  94679. #define PARTOPEN 1
  94680. #define OPENED 2
  94681. #define STREAMSET 3
  94682. #define INITSET 4
  94683. typedef struct OggVorbis_File {
  94684. void *datasource; /* Pointer to a FILE *, etc. */
  94685. int seekable;
  94686. ogg_int64_t offset;
  94687. ogg_int64_t end;
  94688. ogg_sync_state oy;
  94689. int links;
  94690. ogg_int64_t *offsets;
  94691. ogg_int64_t *dataoffsets;
  94692. long *serialnos;
  94693. ogg_int64_t *pcmlengths; /* overloaded to maintain binary
  94694. compatability; x2 size, stores both
  94695. beginning and end values */
  94696. vorbis_info *vi;
  94697. vorbis_comment *vc;
  94698. ogg_int64_t pcm_offset;
  94699. int ready_state;
  94700. long current_serialno;
  94701. int current_link;
  94702. double bittrack;
  94703. double samptrack;
  94704. ogg_stream_state os; /* take physical pages, weld into a logical
  94705. stream of packets */
  94706. vorbis_dsp_state vd; /* central working state for the packet->PCM decoder */
  94707. vorbis_block vb; /* local working space for packet->PCM decode */
  94708. ov_callbacks callbacks;
  94709. } OggVorbis_File;
  94710. extern int ov_clear(OggVorbis_File *vf);
  94711. extern int ov_open(FILE *f,OggVorbis_File *vf,char *initial,long ibytes);
  94712. extern int ov_open_callbacks(void *datasource, OggVorbis_File *vf,
  94713. char *initial, long ibytes, ov_callbacks callbacks);
  94714. extern int ov_test(FILE *f,OggVorbis_File *vf,char *initial,long ibytes);
  94715. extern int ov_test_callbacks(void *datasource, OggVorbis_File *vf,
  94716. char *initial, long ibytes, ov_callbacks callbacks);
  94717. extern int ov_test_open(OggVorbis_File *vf);
  94718. extern long ov_bitrate(OggVorbis_File *vf,int i);
  94719. extern long ov_bitrate_instant(OggVorbis_File *vf);
  94720. extern long ov_streams(OggVorbis_File *vf);
  94721. extern long ov_seekable(OggVorbis_File *vf);
  94722. extern long ov_serialnumber(OggVorbis_File *vf,int i);
  94723. extern ogg_int64_t ov_raw_total(OggVorbis_File *vf,int i);
  94724. extern ogg_int64_t ov_pcm_total(OggVorbis_File *vf,int i);
  94725. extern double ov_time_total(OggVorbis_File *vf,int i);
  94726. extern int ov_raw_seek(OggVorbis_File *vf,ogg_int64_t pos);
  94727. extern int ov_pcm_seek(OggVorbis_File *vf,ogg_int64_t pos);
  94728. extern int ov_pcm_seek_page(OggVorbis_File *vf,ogg_int64_t pos);
  94729. extern int ov_time_seek(OggVorbis_File *vf,double pos);
  94730. extern int ov_time_seek_page(OggVorbis_File *vf,double pos);
  94731. extern int ov_raw_seek_lap(OggVorbis_File *vf,ogg_int64_t pos);
  94732. extern int ov_pcm_seek_lap(OggVorbis_File *vf,ogg_int64_t pos);
  94733. extern int ov_pcm_seek_page_lap(OggVorbis_File *vf,ogg_int64_t pos);
  94734. extern int ov_time_seek_lap(OggVorbis_File *vf,double pos);
  94735. extern int ov_time_seek_page_lap(OggVorbis_File *vf,double pos);
  94736. extern ogg_int64_t ov_raw_tell(OggVorbis_File *vf);
  94737. extern ogg_int64_t ov_pcm_tell(OggVorbis_File *vf);
  94738. extern double ov_time_tell(OggVorbis_File *vf);
  94739. extern vorbis_info *ov_info(OggVorbis_File *vf,int link);
  94740. extern vorbis_comment *ov_comment(OggVorbis_File *vf,int link);
  94741. extern long ov_read_float(OggVorbis_File *vf,float ***pcm_channels,int samples,
  94742. int *bitstream);
  94743. extern long ov_read(OggVorbis_File *vf,char *buffer,int length,
  94744. int bigendianp,int word,int sgned,int *bitstream);
  94745. extern int ov_crosslap(OggVorbis_File *vf1,OggVorbis_File *vf2);
  94746. extern int ov_halfrate(OggVorbis_File *vf,int flag);
  94747. extern int ov_halfrate_p(OggVorbis_File *vf);
  94748. #ifdef __cplusplus
  94749. }
  94750. #endif /* __cplusplus */
  94751. #endif
  94752. /*** End of inlined file: vorbisfile.h ***/
  94753. /*** Start of inlined file: bitwise.c ***/
  94754. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  94755. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  94756. // tasks..
  94757. #if JUCE_MSVC
  94758. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  94759. #endif
  94760. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  94761. #if JUCE_USE_OGGVORBIS
  94762. #include <string.h>
  94763. #include <stdlib.h>
  94764. #define BUFFER_INCREMENT 256
  94765. static const unsigned long mask[]=
  94766. {0x00000000,0x00000001,0x00000003,0x00000007,0x0000000f,
  94767. 0x0000001f,0x0000003f,0x0000007f,0x000000ff,0x000001ff,
  94768. 0x000003ff,0x000007ff,0x00000fff,0x00001fff,0x00003fff,
  94769. 0x00007fff,0x0000ffff,0x0001ffff,0x0003ffff,0x0007ffff,
  94770. 0x000fffff,0x001fffff,0x003fffff,0x007fffff,0x00ffffff,
  94771. 0x01ffffff,0x03ffffff,0x07ffffff,0x0fffffff,0x1fffffff,
  94772. 0x3fffffff,0x7fffffff,0xffffffff };
  94773. static const unsigned int mask8B[]=
  94774. {0x00,0x80,0xc0,0xe0,0xf0,0xf8,0xfc,0xfe,0xff};
  94775. void oggpack_writeinit(oggpack_buffer *b){
  94776. memset(b,0,sizeof(*b));
  94777. b->ptr=b->buffer=(unsigned char*) _ogg_malloc(BUFFER_INCREMENT);
  94778. b->buffer[0]='\0';
  94779. b->storage=BUFFER_INCREMENT;
  94780. }
  94781. void oggpackB_writeinit(oggpack_buffer *b){
  94782. oggpack_writeinit(b);
  94783. }
  94784. void oggpack_writetrunc(oggpack_buffer *b,long bits){
  94785. long bytes=bits>>3;
  94786. bits-=bytes*8;
  94787. b->ptr=b->buffer+bytes;
  94788. b->endbit=bits;
  94789. b->endbyte=bytes;
  94790. *b->ptr&=mask[bits];
  94791. }
  94792. void oggpackB_writetrunc(oggpack_buffer *b,long bits){
  94793. long bytes=bits>>3;
  94794. bits-=bytes*8;
  94795. b->ptr=b->buffer+bytes;
  94796. b->endbit=bits;
  94797. b->endbyte=bytes;
  94798. *b->ptr&=mask8B[bits];
  94799. }
  94800. void oggpack_write(oggpack_buffer *b,unsigned long value,int bits){
  94801. if(b->endbyte+4>=b->storage){
  94802. b->buffer=(unsigned char*) _ogg_realloc(b->buffer,b->storage+BUFFER_INCREMENT);
  94803. b->storage+=BUFFER_INCREMENT;
  94804. b->ptr=b->buffer+b->endbyte;
  94805. }
  94806. value&=mask[bits];
  94807. bits+=b->endbit;
  94808. b->ptr[0]|=value<<b->endbit;
  94809. if(bits>=8){
  94810. b->ptr[1]=(unsigned char)(value>>(8-b->endbit));
  94811. if(bits>=16){
  94812. b->ptr[2]=(unsigned char)(value>>(16-b->endbit));
  94813. if(bits>=24){
  94814. b->ptr[3]=(unsigned char)(value>>(24-b->endbit));
  94815. if(bits>=32){
  94816. if(b->endbit)
  94817. b->ptr[4]=(unsigned char)(value>>(32-b->endbit));
  94818. else
  94819. b->ptr[4]=0;
  94820. }
  94821. }
  94822. }
  94823. }
  94824. b->endbyte+=bits/8;
  94825. b->ptr+=bits/8;
  94826. b->endbit=bits&7;
  94827. }
  94828. void oggpackB_write(oggpack_buffer *b,unsigned long value,int bits){
  94829. if(b->endbyte+4>=b->storage){
  94830. b->buffer=(unsigned char*) _ogg_realloc(b->buffer,b->storage+BUFFER_INCREMENT);
  94831. b->storage+=BUFFER_INCREMENT;
  94832. b->ptr=b->buffer+b->endbyte;
  94833. }
  94834. value=(value&mask[bits])<<(32-bits);
  94835. bits+=b->endbit;
  94836. b->ptr[0]|=value>>(24+b->endbit);
  94837. if(bits>=8){
  94838. b->ptr[1]=(unsigned char)(value>>(16+b->endbit));
  94839. if(bits>=16){
  94840. b->ptr[2]=(unsigned char)(value>>(8+b->endbit));
  94841. if(bits>=24){
  94842. b->ptr[3]=(unsigned char)(value>>(b->endbit));
  94843. if(bits>=32){
  94844. if(b->endbit)
  94845. b->ptr[4]=(unsigned char)(value<<(8-b->endbit));
  94846. else
  94847. b->ptr[4]=0;
  94848. }
  94849. }
  94850. }
  94851. }
  94852. b->endbyte+=bits/8;
  94853. b->ptr+=bits/8;
  94854. b->endbit=bits&7;
  94855. }
  94856. void oggpack_writealign(oggpack_buffer *b){
  94857. int bits=8-b->endbit;
  94858. if(bits<8)
  94859. oggpack_write(b,0,bits);
  94860. }
  94861. void oggpackB_writealign(oggpack_buffer *b){
  94862. int bits=8-b->endbit;
  94863. if(bits<8)
  94864. oggpackB_write(b,0,bits);
  94865. }
  94866. static void oggpack_writecopy_helper(oggpack_buffer *b,
  94867. void *source,
  94868. long bits,
  94869. void (*w)(oggpack_buffer *,
  94870. unsigned long,
  94871. int),
  94872. int msb){
  94873. unsigned char *ptr=(unsigned char *)source;
  94874. long bytes=bits/8;
  94875. bits-=bytes*8;
  94876. if(b->endbit){
  94877. int i;
  94878. for(i=0;i<bytes;i++)
  94879. w(b,(unsigned long)(ptr[i]),8);
  94880. }else{
  94881. if(b->endbyte+bytes+1>=b->storage){
  94882. b->storage=b->endbyte+bytes+BUFFER_INCREMENT;
  94883. b->buffer=(unsigned char*) _ogg_realloc(b->buffer,b->storage);
  94884. b->ptr=b->buffer+b->endbyte;
  94885. }
  94886. memmove(b->ptr,source,bytes);
  94887. b->ptr+=bytes;
  94888. b->endbyte+=bytes;
  94889. *b->ptr=0;
  94890. }
  94891. if(bits){
  94892. if(msb)
  94893. w(b,(unsigned long)(ptr[bytes]>>(8-bits)),bits);
  94894. else
  94895. w(b,(unsigned long)(ptr[bytes]),bits);
  94896. }
  94897. }
  94898. void oggpack_writecopy(oggpack_buffer *b,void *source,long bits){
  94899. oggpack_writecopy_helper(b,source,bits,oggpack_write,0);
  94900. }
  94901. void oggpackB_writecopy(oggpack_buffer *b,void *source,long bits){
  94902. oggpack_writecopy_helper(b,source,bits,oggpackB_write,1);
  94903. }
  94904. void oggpack_reset(oggpack_buffer *b){
  94905. b->ptr=b->buffer;
  94906. b->buffer[0]=0;
  94907. b->endbit=b->endbyte=0;
  94908. }
  94909. void oggpackB_reset(oggpack_buffer *b){
  94910. oggpack_reset(b);
  94911. }
  94912. void oggpack_writeclear(oggpack_buffer *b){
  94913. _ogg_free(b->buffer);
  94914. memset(b,0,sizeof(*b));
  94915. }
  94916. void oggpackB_writeclear(oggpack_buffer *b){
  94917. oggpack_writeclear(b);
  94918. }
  94919. void oggpack_readinit(oggpack_buffer *b,unsigned char *buf,int bytes){
  94920. memset(b,0,sizeof(*b));
  94921. b->buffer=b->ptr=buf;
  94922. b->storage=bytes;
  94923. }
  94924. void oggpackB_readinit(oggpack_buffer *b,unsigned char *buf,int bytes){
  94925. oggpack_readinit(b,buf,bytes);
  94926. }
  94927. long oggpack_look(oggpack_buffer *b,int bits){
  94928. unsigned long ret;
  94929. unsigned long m=mask[bits];
  94930. bits+=b->endbit;
  94931. if(b->endbyte+4>=b->storage){
  94932. if(b->endbyte*8+bits>b->storage*8)return(-1);
  94933. }
  94934. ret=b->ptr[0]>>b->endbit;
  94935. if(bits>8){
  94936. ret|=b->ptr[1]<<(8-b->endbit);
  94937. if(bits>16){
  94938. ret|=b->ptr[2]<<(16-b->endbit);
  94939. if(bits>24){
  94940. ret|=b->ptr[3]<<(24-b->endbit);
  94941. if(bits>32 && b->endbit)
  94942. ret|=b->ptr[4]<<(32-b->endbit);
  94943. }
  94944. }
  94945. }
  94946. return(m&ret);
  94947. }
  94948. long oggpackB_look(oggpack_buffer *b,int bits){
  94949. unsigned long ret;
  94950. int m=32-bits;
  94951. bits+=b->endbit;
  94952. if(b->endbyte+4>=b->storage){
  94953. if(b->endbyte*8+bits>b->storage*8)return(-1);
  94954. }
  94955. ret=b->ptr[0]<<(24+b->endbit);
  94956. if(bits>8){
  94957. ret|=b->ptr[1]<<(16+b->endbit);
  94958. if(bits>16){
  94959. ret|=b->ptr[2]<<(8+b->endbit);
  94960. if(bits>24){
  94961. ret|=b->ptr[3]<<(b->endbit);
  94962. if(bits>32 && b->endbit)
  94963. ret|=b->ptr[4]>>(8-b->endbit);
  94964. }
  94965. }
  94966. }
  94967. return ((ret&0xffffffff)>>(m>>1))>>((m+1)>>1);
  94968. }
  94969. long oggpack_look1(oggpack_buffer *b){
  94970. if(b->endbyte>=b->storage)return(-1);
  94971. return((b->ptr[0]>>b->endbit)&1);
  94972. }
  94973. long oggpackB_look1(oggpack_buffer *b){
  94974. if(b->endbyte>=b->storage)return(-1);
  94975. return((b->ptr[0]>>(7-b->endbit))&1);
  94976. }
  94977. void oggpack_adv(oggpack_buffer *b,int bits){
  94978. bits+=b->endbit;
  94979. b->ptr+=bits/8;
  94980. b->endbyte+=bits/8;
  94981. b->endbit=bits&7;
  94982. }
  94983. void oggpackB_adv(oggpack_buffer *b,int bits){
  94984. oggpack_adv(b,bits);
  94985. }
  94986. void oggpack_adv1(oggpack_buffer *b){
  94987. if(++(b->endbit)>7){
  94988. b->endbit=0;
  94989. b->ptr++;
  94990. b->endbyte++;
  94991. }
  94992. }
  94993. void oggpackB_adv1(oggpack_buffer *b){
  94994. oggpack_adv1(b);
  94995. }
  94996. long oggpack_read(oggpack_buffer *b,int bits){
  94997. long ret;
  94998. unsigned long m=mask[bits];
  94999. bits+=b->endbit;
  95000. if(b->endbyte+4>=b->storage){
  95001. ret=-1L;
  95002. if(b->endbyte*8+bits>b->storage*8)goto overflow;
  95003. }
  95004. ret=b->ptr[0]>>b->endbit;
  95005. if(bits>8){
  95006. ret|=b->ptr[1]<<(8-b->endbit);
  95007. if(bits>16){
  95008. ret|=b->ptr[2]<<(16-b->endbit);
  95009. if(bits>24){
  95010. ret|=b->ptr[3]<<(24-b->endbit);
  95011. if(bits>32 && b->endbit){
  95012. ret|=b->ptr[4]<<(32-b->endbit);
  95013. }
  95014. }
  95015. }
  95016. }
  95017. ret&=m;
  95018. overflow:
  95019. b->ptr+=bits/8;
  95020. b->endbyte+=bits/8;
  95021. b->endbit=bits&7;
  95022. return(ret);
  95023. }
  95024. long oggpackB_read(oggpack_buffer *b,int bits){
  95025. long ret;
  95026. long m=32-bits;
  95027. bits+=b->endbit;
  95028. if(b->endbyte+4>=b->storage){
  95029. ret=-1L;
  95030. if(b->endbyte*8+bits>b->storage*8)goto overflow;
  95031. }
  95032. ret=b->ptr[0]<<(24+b->endbit);
  95033. if(bits>8){
  95034. ret|=b->ptr[1]<<(16+b->endbit);
  95035. if(bits>16){
  95036. ret|=b->ptr[2]<<(8+b->endbit);
  95037. if(bits>24){
  95038. ret|=b->ptr[3]<<(b->endbit);
  95039. if(bits>32 && b->endbit)
  95040. ret|=b->ptr[4]>>(8-b->endbit);
  95041. }
  95042. }
  95043. }
  95044. ret=((ret&0xffffffffUL)>>(m>>1))>>((m+1)>>1);
  95045. overflow:
  95046. b->ptr+=bits/8;
  95047. b->endbyte+=bits/8;
  95048. b->endbit=bits&7;
  95049. return(ret);
  95050. }
  95051. long oggpack_read1(oggpack_buffer *b){
  95052. long ret;
  95053. if(b->endbyte>=b->storage){
  95054. ret=-1L;
  95055. goto overflow;
  95056. }
  95057. ret=(b->ptr[0]>>b->endbit)&1;
  95058. overflow:
  95059. b->endbit++;
  95060. if(b->endbit>7){
  95061. b->endbit=0;
  95062. b->ptr++;
  95063. b->endbyte++;
  95064. }
  95065. return(ret);
  95066. }
  95067. long oggpackB_read1(oggpack_buffer *b){
  95068. long ret;
  95069. if(b->endbyte>=b->storage){
  95070. ret=-1L;
  95071. goto overflow;
  95072. }
  95073. ret=(b->ptr[0]>>(7-b->endbit))&1;
  95074. overflow:
  95075. b->endbit++;
  95076. if(b->endbit>7){
  95077. b->endbit=0;
  95078. b->ptr++;
  95079. b->endbyte++;
  95080. }
  95081. return(ret);
  95082. }
  95083. long oggpack_bytes(oggpack_buffer *b){
  95084. return(b->endbyte+(b->endbit+7)/8);
  95085. }
  95086. long oggpack_bits(oggpack_buffer *b){
  95087. return(b->endbyte*8+b->endbit);
  95088. }
  95089. long oggpackB_bytes(oggpack_buffer *b){
  95090. return oggpack_bytes(b);
  95091. }
  95092. long oggpackB_bits(oggpack_buffer *b){
  95093. return oggpack_bits(b);
  95094. }
  95095. unsigned char *oggpack_get_buffer(oggpack_buffer *b){
  95096. return(b->buffer);
  95097. }
  95098. unsigned char *oggpackB_get_buffer(oggpack_buffer *b){
  95099. return oggpack_get_buffer(b);
  95100. }
  95101. #ifdef _V_SELFTEST
  95102. #include <stdio.h>
  95103. static int ilog(unsigned int v){
  95104. int ret=0;
  95105. while(v){
  95106. ret++;
  95107. v>>=1;
  95108. }
  95109. return(ret);
  95110. }
  95111. oggpack_buffer o;
  95112. oggpack_buffer r;
  95113. void report(char *in){
  95114. fprintf(stderr,"%s",in);
  95115. exit(1);
  95116. }
  95117. void cliptest(unsigned long *b,int vals,int bits,int *comp,int compsize){
  95118. long bytes,i;
  95119. unsigned char *buffer;
  95120. oggpack_reset(&o);
  95121. for(i=0;i<vals;i++)
  95122. oggpack_write(&o,b[i],bits?bits:ilog(b[i]));
  95123. buffer=oggpack_get_buffer(&o);
  95124. bytes=oggpack_bytes(&o);
  95125. if(bytes!=compsize)report("wrong number of bytes!\n");
  95126. for(i=0;i<bytes;i++)if(buffer[i]!=comp[i]){
  95127. for(i=0;i<bytes;i++)fprintf(stderr,"%x %x\n",(int)buffer[i],(int)comp[i]);
  95128. report("wrote incorrect value!\n");
  95129. }
  95130. oggpack_readinit(&r,buffer,bytes);
  95131. for(i=0;i<vals;i++){
  95132. int tbit=bits?bits:ilog(b[i]);
  95133. if(oggpack_look(&r,tbit)==-1)
  95134. report("out of data!\n");
  95135. if(oggpack_look(&r,tbit)!=(b[i]&mask[tbit]))
  95136. report("looked at incorrect value!\n");
  95137. if(tbit==1)
  95138. if(oggpack_look1(&r)!=(b[i]&mask[tbit]))
  95139. report("looked at single bit incorrect value!\n");
  95140. if(tbit==1){
  95141. if(oggpack_read1(&r)!=(b[i]&mask[tbit]))
  95142. report("read incorrect single bit value!\n");
  95143. }else{
  95144. if(oggpack_read(&r,tbit)!=(b[i]&mask[tbit]))
  95145. report("read incorrect value!\n");
  95146. }
  95147. }
  95148. if(oggpack_bytes(&r)!=bytes)report("leftover bytes after read!\n");
  95149. }
  95150. void cliptestB(unsigned long *b,int vals,int bits,int *comp,int compsize){
  95151. long bytes,i;
  95152. unsigned char *buffer;
  95153. oggpackB_reset(&o);
  95154. for(i=0;i<vals;i++)
  95155. oggpackB_write(&o,b[i],bits?bits:ilog(b[i]));
  95156. buffer=oggpackB_get_buffer(&o);
  95157. bytes=oggpackB_bytes(&o);
  95158. if(bytes!=compsize)report("wrong number of bytes!\n");
  95159. for(i=0;i<bytes;i++)if(buffer[i]!=comp[i]){
  95160. for(i=0;i<bytes;i++)fprintf(stderr,"%x %x\n",(int)buffer[i],(int)comp[i]);
  95161. report("wrote incorrect value!\n");
  95162. }
  95163. oggpackB_readinit(&r,buffer,bytes);
  95164. for(i=0;i<vals;i++){
  95165. int tbit=bits?bits:ilog(b[i]);
  95166. if(oggpackB_look(&r,tbit)==-1)
  95167. report("out of data!\n");
  95168. if(oggpackB_look(&r,tbit)!=(b[i]&mask[tbit]))
  95169. report("looked at incorrect value!\n");
  95170. if(tbit==1)
  95171. if(oggpackB_look1(&r)!=(b[i]&mask[tbit]))
  95172. report("looked at single bit incorrect value!\n");
  95173. if(tbit==1){
  95174. if(oggpackB_read1(&r)!=(b[i]&mask[tbit]))
  95175. report("read incorrect single bit value!\n");
  95176. }else{
  95177. if(oggpackB_read(&r,tbit)!=(b[i]&mask[tbit]))
  95178. report("read incorrect value!\n");
  95179. }
  95180. }
  95181. if(oggpackB_bytes(&r)!=bytes)report("leftover bytes after read!\n");
  95182. }
  95183. int main(void){
  95184. unsigned char *buffer;
  95185. long bytes,i;
  95186. static unsigned long testbuffer1[]=
  95187. {18,12,103948,4325,543,76,432,52,3,65,4,56,32,42,34,21,1,23,32,546,456,7,
  95188. 567,56,8,8,55,3,52,342,341,4,265,7,67,86,2199,21,7,1,5,1,4};
  95189. int test1size=43;
  95190. static unsigned long testbuffer2[]=
  95191. {216531625L,1237861823,56732452,131,3212421,12325343,34547562,12313212,
  95192. 1233432,534,5,346435231,14436467,7869299,76326614,167548585,
  95193. 85525151,0,12321,1,349528352};
  95194. int test2size=21;
  95195. static unsigned long testbuffer3[]=
  95196. {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,
  95197. 0,1,30,1,1,1,0,0,1,0,0,0,12,0,11,0,1,0,0,1};
  95198. int test3size=56;
  95199. static unsigned long large[]=
  95200. {2136531625L,2137861823,56732452,131,3212421,12325343,34547562,12313212,
  95201. 1233432,534,5,2146435231,14436467,7869299,76326614,167548585,
  95202. 85525151,0,12321,1,2146528352};
  95203. int onesize=33;
  95204. static int one[33]={146,25,44,151,195,15,153,176,233,131,196,65,85,172,47,40,
  95205. 34,242,223,136,35,222,211,86,171,50,225,135,214,75,172,
  95206. 223,4};
  95207. static int oneB[33]={150,101,131,33,203,15,204,216,105,193,156,65,84,85,222,
  95208. 8,139,145,227,126,34,55,244,171,85,100,39,195,173,18,
  95209. 245,251,128};
  95210. int twosize=6;
  95211. static int two[6]={61,255,255,251,231,29};
  95212. static int twoB[6]={247,63,255,253,249,120};
  95213. int threesize=54;
  95214. static int three[54]={169,2,232,252,91,132,156,36,89,13,123,176,144,32,254,
  95215. 142,224,85,59,121,144,79,124,23,67,90,90,216,79,23,83,
  95216. 58,135,196,61,55,129,183,54,101,100,170,37,127,126,10,
  95217. 100,52,4,14,18,86,77,1};
  95218. static int threeB[54]={206,128,42,153,57,8,183,251,13,89,36,30,32,144,183,
  95219. 130,59,240,121,59,85,223,19,228,180,134,33,107,74,98,
  95220. 233,253,196,135,63,2,110,114,50,155,90,127,37,170,104,
  95221. 200,20,254,4,58,106,176,144,0};
  95222. int foursize=38;
  95223. static int four[38]={18,6,163,252,97,194,104,131,32,1,7,82,137,42,129,11,72,
  95224. 132,60,220,112,8,196,109,64,179,86,9,137,195,208,122,169,
  95225. 28,2,133,0,1};
  95226. static int fourB[38]={36,48,102,83,243,24,52,7,4,35,132,10,145,21,2,93,2,41,
  95227. 1,219,184,16,33,184,54,149,170,132,18,30,29,98,229,67,
  95228. 129,10,4,32};
  95229. int fivesize=45;
  95230. static int five[45]={169,2,126,139,144,172,30,4,80,72,240,59,130,218,73,62,
  95231. 241,24,210,44,4,20,0,248,116,49,135,100,110,130,181,169,
  95232. 84,75,159,2,1,0,132,192,8,0,0,18,22};
  95233. static int fiveB[45]={1,84,145,111,245,100,128,8,56,36,40,71,126,78,213,226,
  95234. 124,105,12,0,133,128,0,162,233,242,67,152,77,205,77,
  95235. 172,150,169,129,79,128,0,6,4,32,0,27,9,0};
  95236. int sixsize=7;
  95237. static int six[7]={17,177,170,242,169,19,148};
  95238. static int sixB[7]={136,141,85,79,149,200,41};
  95239. oggpack_writeinit(&o);
  95240. fprintf(stderr,"\nSmall preclipped packing (LSb): ");
  95241. cliptest(testbuffer1,test1size,0,one,onesize);
  95242. fprintf(stderr,"ok.");
  95243. fprintf(stderr,"\nNull bit call (LSb): ");
  95244. cliptest(testbuffer3,test3size,0,two,twosize);
  95245. fprintf(stderr,"ok.");
  95246. fprintf(stderr,"\nLarge preclipped packing (LSb): ");
  95247. cliptest(testbuffer2,test2size,0,three,threesize);
  95248. fprintf(stderr,"ok.");
  95249. fprintf(stderr,"\n32 bit preclipped packing (LSb): ");
  95250. oggpack_reset(&o);
  95251. for(i=0;i<test2size;i++)
  95252. oggpack_write(&o,large[i],32);
  95253. buffer=oggpack_get_buffer(&o);
  95254. bytes=oggpack_bytes(&o);
  95255. oggpack_readinit(&r,buffer,bytes);
  95256. for(i=0;i<test2size;i++){
  95257. if(oggpack_look(&r,32)==-1)report("out of data. failed!");
  95258. if(oggpack_look(&r,32)!=large[i]){
  95259. fprintf(stderr,"%ld != %ld (%lx!=%lx):",oggpack_look(&r,32),large[i],
  95260. oggpack_look(&r,32),large[i]);
  95261. report("read incorrect value!\n");
  95262. }
  95263. oggpack_adv(&r,32);
  95264. }
  95265. if(oggpack_bytes(&r)!=bytes)report("leftover bytes after read!\n");
  95266. fprintf(stderr,"ok.");
  95267. fprintf(stderr,"\nSmall unclipped packing (LSb): ");
  95268. cliptest(testbuffer1,test1size,7,four,foursize);
  95269. fprintf(stderr,"ok.");
  95270. fprintf(stderr,"\nLarge unclipped packing (LSb): ");
  95271. cliptest(testbuffer2,test2size,17,five,fivesize);
  95272. fprintf(stderr,"ok.");
  95273. fprintf(stderr,"\nSingle bit unclipped packing (LSb): ");
  95274. cliptest(testbuffer3,test3size,1,six,sixsize);
  95275. fprintf(stderr,"ok.");
  95276. fprintf(stderr,"\nTesting read past end (LSb): ");
  95277. oggpack_readinit(&r,"\0\0\0\0\0\0\0\0",8);
  95278. for(i=0;i<64;i++){
  95279. if(oggpack_read(&r,1)!=0){
  95280. fprintf(stderr,"failed; got -1 prematurely.\n");
  95281. exit(1);
  95282. }
  95283. }
  95284. if(oggpack_look(&r,1)!=-1 ||
  95285. oggpack_read(&r,1)!=-1){
  95286. fprintf(stderr,"failed; read past end without -1.\n");
  95287. exit(1);
  95288. }
  95289. oggpack_readinit(&r,"\0\0\0\0\0\0\0\0",8);
  95290. if(oggpack_read(&r,30)!=0 || oggpack_read(&r,16)!=0){
  95291. fprintf(stderr,"failed 2; got -1 prematurely.\n");
  95292. exit(1);
  95293. }
  95294. if(oggpack_look(&r,18)!=0 ||
  95295. oggpack_look(&r,18)!=0){
  95296. fprintf(stderr,"failed 3; got -1 prematurely.\n");
  95297. exit(1);
  95298. }
  95299. if(oggpack_look(&r,19)!=-1 ||
  95300. oggpack_look(&r,19)!=-1){
  95301. fprintf(stderr,"failed; read past end without -1.\n");
  95302. exit(1);
  95303. }
  95304. if(oggpack_look(&r,32)!=-1 ||
  95305. oggpack_look(&r,32)!=-1){
  95306. fprintf(stderr,"failed; read past end without -1.\n");
  95307. exit(1);
  95308. }
  95309. oggpack_writeclear(&o);
  95310. fprintf(stderr,"ok.\n");
  95311. oggpackB_writeinit(&o);
  95312. fprintf(stderr,"\nSmall preclipped packing (MSb): ");
  95313. cliptestB(testbuffer1,test1size,0,oneB,onesize);
  95314. fprintf(stderr,"ok.");
  95315. fprintf(stderr,"\nNull bit call (MSb): ");
  95316. cliptestB(testbuffer3,test3size,0,twoB,twosize);
  95317. fprintf(stderr,"ok.");
  95318. fprintf(stderr,"\nLarge preclipped packing (MSb): ");
  95319. cliptestB(testbuffer2,test2size,0,threeB,threesize);
  95320. fprintf(stderr,"ok.");
  95321. fprintf(stderr,"\n32 bit preclipped packing (MSb): ");
  95322. oggpackB_reset(&o);
  95323. for(i=0;i<test2size;i++)
  95324. oggpackB_write(&o,large[i],32);
  95325. buffer=oggpackB_get_buffer(&o);
  95326. bytes=oggpackB_bytes(&o);
  95327. oggpackB_readinit(&r,buffer,bytes);
  95328. for(i=0;i<test2size;i++){
  95329. if(oggpackB_look(&r,32)==-1)report("out of data. failed!");
  95330. if(oggpackB_look(&r,32)!=large[i]){
  95331. fprintf(stderr,"%ld != %ld (%lx!=%lx):",oggpackB_look(&r,32),large[i],
  95332. oggpackB_look(&r,32),large[i]);
  95333. report("read incorrect value!\n");
  95334. }
  95335. oggpackB_adv(&r,32);
  95336. }
  95337. if(oggpackB_bytes(&r)!=bytes)report("leftover bytes after read!\n");
  95338. fprintf(stderr,"ok.");
  95339. fprintf(stderr,"\nSmall unclipped packing (MSb): ");
  95340. cliptestB(testbuffer1,test1size,7,fourB,foursize);
  95341. fprintf(stderr,"ok.");
  95342. fprintf(stderr,"\nLarge unclipped packing (MSb): ");
  95343. cliptestB(testbuffer2,test2size,17,fiveB,fivesize);
  95344. fprintf(stderr,"ok.");
  95345. fprintf(stderr,"\nSingle bit unclipped packing (MSb): ");
  95346. cliptestB(testbuffer3,test3size,1,sixB,sixsize);
  95347. fprintf(stderr,"ok.");
  95348. fprintf(stderr,"\nTesting read past end (MSb): ");
  95349. oggpackB_readinit(&r,"\0\0\0\0\0\0\0\0",8);
  95350. for(i=0;i<64;i++){
  95351. if(oggpackB_read(&r,1)!=0){
  95352. fprintf(stderr,"failed; got -1 prematurely.\n");
  95353. exit(1);
  95354. }
  95355. }
  95356. if(oggpackB_look(&r,1)!=-1 ||
  95357. oggpackB_read(&r,1)!=-1){
  95358. fprintf(stderr,"failed; read past end without -1.\n");
  95359. exit(1);
  95360. }
  95361. oggpackB_readinit(&r,"\0\0\0\0\0\0\0\0",8);
  95362. if(oggpackB_read(&r,30)!=0 || oggpackB_read(&r,16)!=0){
  95363. fprintf(stderr,"failed 2; got -1 prematurely.\n");
  95364. exit(1);
  95365. }
  95366. if(oggpackB_look(&r,18)!=0 ||
  95367. oggpackB_look(&r,18)!=0){
  95368. fprintf(stderr,"failed 3; got -1 prematurely.\n");
  95369. exit(1);
  95370. }
  95371. if(oggpackB_look(&r,19)!=-1 ||
  95372. oggpackB_look(&r,19)!=-1){
  95373. fprintf(stderr,"failed; read past end without -1.\n");
  95374. exit(1);
  95375. }
  95376. if(oggpackB_look(&r,32)!=-1 ||
  95377. oggpackB_look(&r,32)!=-1){
  95378. fprintf(stderr,"failed; read past end without -1.\n");
  95379. exit(1);
  95380. }
  95381. oggpackB_writeclear(&o);
  95382. fprintf(stderr,"ok.\n\n");
  95383. return(0);
  95384. }
  95385. #endif /* _V_SELFTEST */
  95386. #undef BUFFER_INCREMENT
  95387. #endif
  95388. /*** End of inlined file: bitwise.c ***/
  95389. /*** Start of inlined file: framing.c ***/
  95390. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  95391. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  95392. // tasks..
  95393. #if JUCE_MSVC
  95394. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  95395. #endif
  95396. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  95397. #if JUCE_USE_OGGVORBIS
  95398. #include <stdlib.h>
  95399. #include <string.h>
  95400. int ogg_page_version(ogg_page *og){
  95401. return((int)(og->header[4]));
  95402. }
  95403. int ogg_page_continued(ogg_page *og){
  95404. return((int)(og->header[5]&0x01));
  95405. }
  95406. int ogg_page_bos(ogg_page *og){
  95407. return((int)(og->header[5]&0x02));
  95408. }
  95409. int ogg_page_eos(ogg_page *og){
  95410. return((int)(og->header[5]&0x04));
  95411. }
  95412. ogg_int64_t ogg_page_granulepos(ogg_page *og){
  95413. unsigned char *page=og->header;
  95414. ogg_int64_t granulepos=page[13]&(0xff);
  95415. granulepos= (granulepos<<8)|(page[12]&0xff);
  95416. granulepos= (granulepos<<8)|(page[11]&0xff);
  95417. granulepos= (granulepos<<8)|(page[10]&0xff);
  95418. granulepos= (granulepos<<8)|(page[9]&0xff);
  95419. granulepos= (granulepos<<8)|(page[8]&0xff);
  95420. granulepos= (granulepos<<8)|(page[7]&0xff);
  95421. granulepos= (granulepos<<8)|(page[6]&0xff);
  95422. return(granulepos);
  95423. }
  95424. int ogg_page_serialno(ogg_page *og){
  95425. return(og->header[14] |
  95426. (og->header[15]<<8) |
  95427. (og->header[16]<<16) |
  95428. (og->header[17]<<24));
  95429. }
  95430. long ogg_page_pageno(ogg_page *og){
  95431. return(og->header[18] |
  95432. (og->header[19]<<8) |
  95433. (og->header[20]<<16) |
  95434. (og->header[21]<<24));
  95435. }
  95436. int ogg_page_packets(ogg_page *og){
  95437. int i,n=og->header[26],count=0;
  95438. for(i=0;i<n;i++)
  95439. if(og->header[27+i]<255)count++;
  95440. return(count);
  95441. }
  95442. #if 0
  95443. static ogg_uint32_t _ogg_crc_entry(unsigned long index){
  95444. int i;
  95445. unsigned long r;
  95446. r = index << 24;
  95447. for (i=0; i<8; i++)
  95448. if (r & 0x80000000UL)
  95449. r = (r << 1) ^ 0x04c11db7; /* The same as the ethernet generator
  95450. polynomial, although we use an
  95451. unreflected alg and an init/final
  95452. of 0, not 0xffffffff */
  95453. else
  95454. r<<=1;
  95455. return (r & 0xffffffffUL);
  95456. }
  95457. #endif
  95458. static const ogg_uint32_t crc_lookup[256]={
  95459. 0x00000000,0x04c11db7,0x09823b6e,0x0d4326d9,
  95460. 0x130476dc,0x17c56b6b,0x1a864db2,0x1e475005,
  95461. 0x2608edb8,0x22c9f00f,0x2f8ad6d6,0x2b4bcb61,
  95462. 0x350c9b64,0x31cd86d3,0x3c8ea00a,0x384fbdbd,
  95463. 0x4c11db70,0x48d0c6c7,0x4593e01e,0x4152fda9,
  95464. 0x5f15adac,0x5bd4b01b,0x569796c2,0x52568b75,
  95465. 0x6a1936c8,0x6ed82b7f,0x639b0da6,0x675a1011,
  95466. 0x791d4014,0x7ddc5da3,0x709f7b7a,0x745e66cd,
  95467. 0x9823b6e0,0x9ce2ab57,0x91a18d8e,0x95609039,
  95468. 0x8b27c03c,0x8fe6dd8b,0x82a5fb52,0x8664e6e5,
  95469. 0xbe2b5b58,0xbaea46ef,0xb7a96036,0xb3687d81,
  95470. 0xad2f2d84,0xa9ee3033,0xa4ad16ea,0xa06c0b5d,
  95471. 0xd4326d90,0xd0f37027,0xddb056fe,0xd9714b49,
  95472. 0xc7361b4c,0xc3f706fb,0xceb42022,0xca753d95,
  95473. 0xf23a8028,0xf6fb9d9f,0xfbb8bb46,0xff79a6f1,
  95474. 0xe13ef6f4,0xe5ffeb43,0xe8bccd9a,0xec7dd02d,
  95475. 0x34867077,0x30476dc0,0x3d044b19,0x39c556ae,
  95476. 0x278206ab,0x23431b1c,0x2e003dc5,0x2ac12072,
  95477. 0x128e9dcf,0x164f8078,0x1b0ca6a1,0x1fcdbb16,
  95478. 0x018aeb13,0x054bf6a4,0x0808d07d,0x0cc9cdca,
  95479. 0x7897ab07,0x7c56b6b0,0x71159069,0x75d48dde,
  95480. 0x6b93dddb,0x6f52c06c,0x6211e6b5,0x66d0fb02,
  95481. 0x5e9f46bf,0x5a5e5b08,0x571d7dd1,0x53dc6066,
  95482. 0x4d9b3063,0x495a2dd4,0x44190b0d,0x40d816ba,
  95483. 0xaca5c697,0xa864db20,0xa527fdf9,0xa1e6e04e,
  95484. 0xbfa1b04b,0xbb60adfc,0xb6238b25,0xb2e29692,
  95485. 0x8aad2b2f,0x8e6c3698,0x832f1041,0x87ee0df6,
  95486. 0x99a95df3,0x9d684044,0x902b669d,0x94ea7b2a,
  95487. 0xe0b41de7,0xe4750050,0xe9362689,0xedf73b3e,
  95488. 0xf3b06b3b,0xf771768c,0xfa325055,0xfef34de2,
  95489. 0xc6bcf05f,0xc27dede8,0xcf3ecb31,0xcbffd686,
  95490. 0xd5b88683,0xd1799b34,0xdc3abded,0xd8fba05a,
  95491. 0x690ce0ee,0x6dcdfd59,0x608edb80,0x644fc637,
  95492. 0x7a089632,0x7ec98b85,0x738aad5c,0x774bb0eb,
  95493. 0x4f040d56,0x4bc510e1,0x46863638,0x42472b8f,
  95494. 0x5c007b8a,0x58c1663d,0x558240e4,0x51435d53,
  95495. 0x251d3b9e,0x21dc2629,0x2c9f00f0,0x285e1d47,
  95496. 0x36194d42,0x32d850f5,0x3f9b762c,0x3b5a6b9b,
  95497. 0x0315d626,0x07d4cb91,0x0a97ed48,0x0e56f0ff,
  95498. 0x1011a0fa,0x14d0bd4d,0x19939b94,0x1d528623,
  95499. 0xf12f560e,0xf5ee4bb9,0xf8ad6d60,0xfc6c70d7,
  95500. 0xe22b20d2,0xe6ea3d65,0xeba91bbc,0xef68060b,
  95501. 0xd727bbb6,0xd3e6a601,0xdea580d8,0xda649d6f,
  95502. 0xc423cd6a,0xc0e2d0dd,0xcda1f604,0xc960ebb3,
  95503. 0xbd3e8d7e,0xb9ff90c9,0xb4bcb610,0xb07daba7,
  95504. 0xae3afba2,0xaafbe615,0xa7b8c0cc,0xa379dd7b,
  95505. 0x9b3660c6,0x9ff77d71,0x92b45ba8,0x9675461f,
  95506. 0x8832161a,0x8cf30bad,0x81b02d74,0x857130c3,
  95507. 0x5d8a9099,0x594b8d2e,0x5408abf7,0x50c9b640,
  95508. 0x4e8ee645,0x4a4ffbf2,0x470cdd2b,0x43cdc09c,
  95509. 0x7b827d21,0x7f436096,0x7200464f,0x76c15bf8,
  95510. 0x68860bfd,0x6c47164a,0x61043093,0x65c52d24,
  95511. 0x119b4be9,0x155a565e,0x18197087,0x1cd86d30,
  95512. 0x029f3d35,0x065e2082,0x0b1d065b,0x0fdc1bec,
  95513. 0x3793a651,0x3352bbe6,0x3e119d3f,0x3ad08088,
  95514. 0x2497d08d,0x2056cd3a,0x2d15ebe3,0x29d4f654,
  95515. 0xc5a92679,0xc1683bce,0xcc2b1d17,0xc8ea00a0,
  95516. 0xd6ad50a5,0xd26c4d12,0xdf2f6bcb,0xdbee767c,
  95517. 0xe3a1cbc1,0xe760d676,0xea23f0af,0xeee2ed18,
  95518. 0xf0a5bd1d,0xf464a0aa,0xf9278673,0xfde69bc4,
  95519. 0x89b8fd09,0x8d79e0be,0x803ac667,0x84fbdbd0,
  95520. 0x9abc8bd5,0x9e7d9662,0x933eb0bb,0x97ffad0c,
  95521. 0xafb010b1,0xab710d06,0xa6322bdf,0xa2f33668,
  95522. 0xbcb4666d,0xb8757bda,0xb5365d03,0xb1f740b4};
  95523. int ogg_stream_init(ogg_stream_state *os,int serialno){
  95524. if(os){
  95525. memset(os,0,sizeof(*os));
  95526. os->body_storage=16*1024;
  95527. os->body_data=(unsigned char*) _ogg_malloc(os->body_storage*sizeof(*os->body_data));
  95528. os->lacing_storage=1024;
  95529. os->lacing_vals=(int*) _ogg_malloc(os->lacing_storage*sizeof(*os->lacing_vals));
  95530. os->granule_vals=(ogg_int64_t*) _ogg_malloc(os->lacing_storage*sizeof(*os->granule_vals));
  95531. os->serialno=serialno;
  95532. return(0);
  95533. }
  95534. return(-1);
  95535. }
  95536. int ogg_stream_clear(ogg_stream_state *os){
  95537. if(os){
  95538. if(os->body_data)_ogg_free(os->body_data);
  95539. if(os->lacing_vals)_ogg_free(os->lacing_vals);
  95540. if(os->granule_vals)_ogg_free(os->granule_vals);
  95541. memset(os,0,sizeof(*os));
  95542. }
  95543. return(0);
  95544. }
  95545. int ogg_stream_destroy(ogg_stream_state *os){
  95546. if(os){
  95547. ogg_stream_clear(os);
  95548. _ogg_free(os);
  95549. }
  95550. return(0);
  95551. }
  95552. static void _os_body_expand(ogg_stream_state *os,int needed){
  95553. if(os->body_storage<=os->body_fill+needed){
  95554. os->body_storage+=(needed+1024);
  95555. os->body_data=(unsigned char*) _ogg_realloc(os->body_data,os->body_storage*sizeof(*os->body_data));
  95556. }
  95557. }
  95558. static void _os_lacing_expand(ogg_stream_state *os,int needed){
  95559. if(os->lacing_storage<=os->lacing_fill+needed){
  95560. os->lacing_storage+=(needed+32);
  95561. os->lacing_vals=(int*)_ogg_realloc(os->lacing_vals,os->lacing_storage*sizeof(*os->lacing_vals));
  95562. os->granule_vals=(ogg_int64_t*)_ogg_realloc(os->granule_vals,os->lacing_storage*sizeof(*os->granule_vals));
  95563. }
  95564. }
  95565. void ogg_page_checksum_set(ogg_page *og){
  95566. if(og){
  95567. ogg_uint32_t crc_reg=0;
  95568. int i;
  95569. og->header[22]=0;
  95570. og->header[23]=0;
  95571. og->header[24]=0;
  95572. og->header[25]=0;
  95573. for(i=0;i<og->header_len;i++)
  95574. crc_reg=(crc_reg<<8)^crc_lookup[((crc_reg >> 24)&0xff)^og->header[i]];
  95575. for(i=0;i<og->body_len;i++)
  95576. crc_reg=(crc_reg<<8)^crc_lookup[((crc_reg >> 24)&0xff)^og->body[i]];
  95577. og->header[22]=(unsigned char)(crc_reg&0xff);
  95578. og->header[23]=(unsigned char)((crc_reg>>8)&0xff);
  95579. og->header[24]=(unsigned char)((crc_reg>>16)&0xff);
  95580. og->header[25]=(unsigned char)((crc_reg>>24)&0xff);
  95581. }
  95582. }
  95583. int ogg_stream_packetin(ogg_stream_state *os,ogg_packet *op){
  95584. int lacing_vals=op->bytes/255+1,i;
  95585. if(os->body_returned){
  95586. os->body_fill-=os->body_returned;
  95587. if(os->body_fill)
  95588. memmove(os->body_data,os->body_data+os->body_returned,
  95589. os->body_fill);
  95590. os->body_returned=0;
  95591. }
  95592. _os_body_expand(os,op->bytes);
  95593. _os_lacing_expand(os,lacing_vals);
  95594. memcpy(os->body_data+os->body_fill,op->packet,op->bytes);
  95595. os->body_fill+=op->bytes;
  95596. for(i=0;i<lacing_vals-1;i++){
  95597. os->lacing_vals[os->lacing_fill+i]=255;
  95598. os->granule_vals[os->lacing_fill+i]=os->granulepos;
  95599. }
  95600. os->lacing_vals[os->lacing_fill+i]=(op->bytes)%255;
  95601. os->granulepos=os->granule_vals[os->lacing_fill+i]=op->granulepos;
  95602. os->lacing_vals[os->lacing_fill]|= 0x100;
  95603. os->lacing_fill+=lacing_vals;
  95604. os->packetno++;
  95605. if(op->e_o_s)os->e_o_s=1;
  95606. return(0);
  95607. }
  95608. int ogg_stream_flush(ogg_stream_state *os,ogg_page *og){
  95609. int i;
  95610. int vals=0;
  95611. int maxvals=(os->lacing_fill>255?255:os->lacing_fill);
  95612. int bytes=0;
  95613. long acc=0;
  95614. ogg_int64_t granule_pos=-1;
  95615. if(maxvals==0)return(0);
  95616. if(os->b_o_s==0){ /* 'initial header page' case */
  95617. granule_pos=0;
  95618. for(vals=0;vals<maxvals;vals++){
  95619. if((os->lacing_vals[vals]&0x0ff)<255){
  95620. vals++;
  95621. break;
  95622. }
  95623. }
  95624. }else{
  95625. for(vals=0;vals<maxvals;vals++){
  95626. if(acc>4096)break;
  95627. acc+=os->lacing_vals[vals]&0x0ff;
  95628. if((os->lacing_vals[vals]&0xff)<255)
  95629. granule_pos=os->granule_vals[vals];
  95630. }
  95631. }
  95632. memcpy(os->header,"OggS",4);
  95633. os->header[4]=0x00;
  95634. os->header[5]=0x00;
  95635. if((os->lacing_vals[0]&0x100)==0)os->header[5]|=0x01;
  95636. if(os->b_o_s==0)os->header[5]|=0x02;
  95637. if(os->e_o_s && os->lacing_fill==vals)os->header[5]|=0x04;
  95638. os->b_o_s=1;
  95639. for(i=6;i<14;i++){
  95640. os->header[i]=(unsigned char)(granule_pos&0xff);
  95641. granule_pos>>=8;
  95642. }
  95643. {
  95644. long serialno=os->serialno;
  95645. for(i=14;i<18;i++){
  95646. os->header[i]=(unsigned char)(serialno&0xff);
  95647. serialno>>=8;
  95648. }
  95649. }
  95650. if(os->pageno==-1)os->pageno=0; /* because someone called
  95651. stream_reset; this would be a
  95652. strange thing to do in an
  95653. encode stream, but it has
  95654. plausible uses */
  95655. {
  95656. long pageno=os->pageno++;
  95657. for(i=18;i<22;i++){
  95658. os->header[i]=(unsigned char)(pageno&0xff);
  95659. pageno>>=8;
  95660. }
  95661. }
  95662. os->header[22]=0;
  95663. os->header[23]=0;
  95664. os->header[24]=0;
  95665. os->header[25]=0;
  95666. os->header[26]=(unsigned char)(vals&0xff);
  95667. for(i=0;i<vals;i++)
  95668. bytes+=os->header[i+27]=(unsigned char)(os->lacing_vals[i]&0xff);
  95669. og->header=os->header;
  95670. og->header_len=os->header_fill=vals+27;
  95671. og->body=os->body_data+os->body_returned;
  95672. og->body_len=bytes;
  95673. os->lacing_fill-=vals;
  95674. memmove(os->lacing_vals,os->lacing_vals+vals,os->lacing_fill*sizeof(*os->lacing_vals));
  95675. memmove(os->granule_vals,os->granule_vals+vals,os->lacing_fill*sizeof(*os->granule_vals));
  95676. os->body_returned+=bytes;
  95677. ogg_page_checksum_set(og);
  95678. return(1);
  95679. }
  95680. int ogg_stream_pageout(ogg_stream_state *os, ogg_page *og){
  95681. if((os->e_o_s&&os->lacing_fill) || /* 'were done, now flush' case */
  95682. os->body_fill-os->body_returned > 4096 ||/* 'page nominal size' case */
  95683. os->lacing_fill>=255 || /* 'segment table full' case */
  95684. (os->lacing_fill&&!os->b_o_s)){ /* 'initial header page' case */
  95685. return(ogg_stream_flush(os,og));
  95686. }
  95687. return(0);
  95688. }
  95689. int ogg_stream_eos(ogg_stream_state *os){
  95690. return os->e_o_s;
  95691. }
  95692. int ogg_sync_init(ogg_sync_state *oy){
  95693. if(oy){
  95694. memset(oy,0,sizeof(*oy));
  95695. }
  95696. return(0);
  95697. }
  95698. int ogg_sync_clear(ogg_sync_state *oy){
  95699. if(oy){
  95700. if(oy->data)_ogg_free(oy->data);
  95701. ogg_sync_init(oy);
  95702. }
  95703. return(0);
  95704. }
  95705. int ogg_sync_destroy(ogg_sync_state *oy){
  95706. if(oy){
  95707. ogg_sync_clear(oy);
  95708. _ogg_free(oy);
  95709. }
  95710. return(0);
  95711. }
  95712. char *ogg_sync_buffer(ogg_sync_state *oy, long size){
  95713. if(oy->returned){
  95714. oy->fill-=oy->returned;
  95715. if(oy->fill>0)
  95716. memmove(oy->data,oy->data+oy->returned,oy->fill);
  95717. oy->returned=0;
  95718. }
  95719. if(size>oy->storage-oy->fill){
  95720. long newsize=size+oy->fill+4096; /* an extra page to be nice */
  95721. if(oy->data)
  95722. oy->data=(unsigned char*) _ogg_realloc(oy->data,newsize);
  95723. else
  95724. oy->data=(unsigned char*) _ogg_malloc(newsize);
  95725. oy->storage=newsize;
  95726. }
  95727. return((char *)oy->data+oy->fill);
  95728. }
  95729. int ogg_sync_wrote(ogg_sync_state *oy, long bytes){
  95730. if(oy->fill+bytes>oy->storage)return(-1);
  95731. oy->fill+=bytes;
  95732. return(0);
  95733. }
  95734. long ogg_sync_pageseek(ogg_sync_state *oy,ogg_page *og){
  95735. unsigned char *page=oy->data+oy->returned;
  95736. unsigned char *next;
  95737. long bytes=oy->fill-oy->returned;
  95738. if(oy->headerbytes==0){
  95739. int headerbytes,i;
  95740. if(bytes<27)return(0); /* not enough for a header */
  95741. if(memcmp(page,"OggS",4))goto sync_fail;
  95742. headerbytes=page[26]+27;
  95743. if(bytes<headerbytes)return(0); /* not enough for header + seg table */
  95744. for(i=0;i<page[26];i++)
  95745. oy->bodybytes+=page[27+i];
  95746. oy->headerbytes=headerbytes;
  95747. }
  95748. if(oy->bodybytes+oy->headerbytes>bytes)return(0);
  95749. {
  95750. char chksum[4];
  95751. ogg_page log;
  95752. memcpy(chksum,page+22,4);
  95753. memset(page+22,0,4);
  95754. log.header=page;
  95755. log.header_len=oy->headerbytes;
  95756. log.body=page+oy->headerbytes;
  95757. log.body_len=oy->bodybytes;
  95758. ogg_page_checksum_set(&log);
  95759. if(memcmp(chksum,page+22,4)){
  95760. memcpy(page+22,chksum,4);
  95761. goto sync_fail;
  95762. }
  95763. }
  95764. {
  95765. unsigned char *page=oy->data+oy->returned;
  95766. long bytes;
  95767. if(og){
  95768. og->header=page;
  95769. og->header_len=oy->headerbytes;
  95770. og->body=page+oy->headerbytes;
  95771. og->body_len=oy->bodybytes;
  95772. }
  95773. oy->unsynced=0;
  95774. oy->returned+=(bytes=oy->headerbytes+oy->bodybytes);
  95775. oy->headerbytes=0;
  95776. oy->bodybytes=0;
  95777. return(bytes);
  95778. }
  95779. sync_fail:
  95780. oy->headerbytes=0;
  95781. oy->bodybytes=0;
  95782. next=(unsigned char*)memchr(page+1,'O',bytes-1);
  95783. if(!next)
  95784. next=oy->data+oy->fill;
  95785. oy->returned=next-oy->data;
  95786. return(-(next-page));
  95787. }
  95788. int ogg_sync_pageout(ogg_sync_state *oy, ogg_page *og){
  95789. for(;;){
  95790. long ret=ogg_sync_pageseek(oy,og);
  95791. if(ret>0){
  95792. return(1);
  95793. }
  95794. if(ret==0){
  95795. return(0);
  95796. }
  95797. if(!oy->unsynced){
  95798. oy->unsynced=1;
  95799. return(-1);
  95800. }
  95801. }
  95802. }
  95803. int ogg_stream_pagein(ogg_stream_state *os, ogg_page *og){
  95804. unsigned char *header=og->header;
  95805. unsigned char *body=og->body;
  95806. long bodysize=og->body_len;
  95807. int segptr=0;
  95808. int version=ogg_page_version(og);
  95809. int continued=ogg_page_continued(og);
  95810. int bos=ogg_page_bos(og);
  95811. int eos=ogg_page_eos(og);
  95812. ogg_int64_t granulepos=ogg_page_granulepos(og);
  95813. int serialno=ogg_page_serialno(og);
  95814. long pageno=ogg_page_pageno(og);
  95815. int segments=header[26];
  95816. {
  95817. long lr=os->lacing_returned;
  95818. long br=os->body_returned;
  95819. if(br){
  95820. os->body_fill-=br;
  95821. if(os->body_fill)
  95822. memmove(os->body_data,os->body_data+br,os->body_fill);
  95823. os->body_returned=0;
  95824. }
  95825. if(lr){
  95826. if(os->lacing_fill-lr){
  95827. memmove(os->lacing_vals,os->lacing_vals+lr,
  95828. (os->lacing_fill-lr)*sizeof(*os->lacing_vals));
  95829. memmove(os->granule_vals,os->granule_vals+lr,
  95830. (os->lacing_fill-lr)*sizeof(*os->granule_vals));
  95831. }
  95832. os->lacing_fill-=lr;
  95833. os->lacing_packet-=lr;
  95834. os->lacing_returned=0;
  95835. }
  95836. }
  95837. if(serialno!=os->serialno)return(-1);
  95838. if(version>0)return(-1);
  95839. _os_lacing_expand(os,segments+1);
  95840. if(pageno!=os->pageno){
  95841. int i;
  95842. for(i=os->lacing_packet;i<os->lacing_fill;i++)
  95843. os->body_fill-=os->lacing_vals[i]&0xff;
  95844. os->lacing_fill=os->lacing_packet;
  95845. if(os->pageno!=-1){
  95846. os->lacing_vals[os->lacing_fill++]=0x400;
  95847. os->lacing_packet++;
  95848. }
  95849. }
  95850. if(continued){
  95851. if(os->lacing_fill<1 ||
  95852. os->lacing_vals[os->lacing_fill-1]==0x400){
  95853. bos=0;
  95854. for(;segptr<segments;segptr++){
  95855. int val=header[27+segptr];
  95856. body+=val;
  95857. bodysize-=val;
  95858. if(val<255){
  95859. segptr++;
  95860. break;
  95861. }
  95862. }
  95863. }
  95864. }
  95865. if(bodysize){
  95866. _os_body_expand(os,bodysize);
  95867. memcpy(os->body_data+os->body_fill,body,bodysize);
  95868. os->body_fill+=bodysize;
  95869. }
  95870. {
  95871. int saved=-1;
  95872. while(segptr<segments){
  95873. int val=header[27+segptr];
  95874. os->lacing_vals[os->lacing_fill]=val;
  95875. os->granule_vals[os->lacing_fill]=-1;
  95876. if(bos){
  95877. os->lacing_vals[os->lacing_fill]|=0x100;
  95878. bos=0;
  95879. }
  95880. if(val<255)saved=os->lacing_fill;
  95881. os->lacing_fill++;
  95882. segptr++;
  95883. if(val<255)os->lacing_packet=os->lacing_fill;
  95884. }
  95885. if(saved!=-1){
  95886. os->granule_vals[saved]=granulepos;
  95887. }
  95888. }
  95889. if(eos){
  95890. os->e_o_s=1;
  95891. if(os->lacing_fill>0)
  95892. os->lacing_vals[os->lacing_fill-1]|=0x200;
  95893. }
  95894. os->pageno=pageno+1;
  95895. return(0);
  95896. }
  95897. int ogg_sync_reset(ogg_sync_state *oy){
  95898. oy->fill=0;
  95899. oy->returned=0;
  95900. oy->unsynced=0;
  95901. oy->headerbytes=0;
  95902. oy->bodybytes=0;
  95903. return(0);
  95904. }
  95905. int ogg_stream_reset(ogg_stream_state *os){
  95906. os->body_fill=0;
  95907. os->body_returned=0;
  95908. os->lacing_fill=0;
  95909. os->lacing_packet=0;
  95910. os->lacing_returned=0;
  95911. os->header_fill=0;
  95912. os->e_o_s=0;
  95913. os->b_o_s=0;
  95914. os->pageno=-1;
  95915. os->packetno=0;
  95916. os->granulepos=0;
  95917. return(0);
  95918. }
  95919. int ogg_stream_reset_serialno(ogg_stream_state *os,int serialno){
  95920. ogg_stream_reset(os);
  95921. os->serialno=serialno;
  95922. return(0);
  95923. }
  95924. static int _packetout(ogg_stream_state *os,ogg_packet *op,int adv){
  95925. int ptr=os->lacing_returned;
  95926. if(os->lacing_packet<=ptr)return(0);
  95927. if(os->lacing_vals[ptr]&0x400){
  95928. os->lacing_returned++;
  95929. os->packetno++;
  95930. return(-1);
  95931. }
  95932. if(!op && !adv)return(1); /* just using peek as an inexpensive way
  95933. to ask if there's a whole packet
  95934. waiting */
  95935. {
  95936. int size=os->lacing_vals[ptr]&0xff;
  95937. int bytes=size;
  95938. int eos=os->lacing_vals[ptr]&0x200; /* last packet of the stream? */
  95939. int bos=os->lacing_vals[ptr]&0x100; /* first packet of the stream? */
  95940. while(size==255){
  95941. int val=os->lacing_vals[++ptr];
  95942. size=val&0xff;
  95943. if(val&0x200)eos=0x200;
  95944. bytes+=size;
  95945. }
  95946. if(op){
  95947. op->e_o_s=eos;
  95948. op->b_o_s=bos;
  95949. op->packet=os->body_data+os->body_returned;
  95950. op->packetno=os->packetno;
  95951. op->granulepos=os->granule_vals[ptr];
  95952. op->bytes=bytes;
  95953. }
  95954. if(adv){
  95955. os->body_returned+=bytes;
  95956. os->lacing_returned=ptr+1;
  95957. os->packetno++;
  95958. }
  95959. }
  95960. return(1);
  95961. }
  95962. int ogg_stream_packetout(ogg_stream_state *os,ogg_packet *op){
  95963. return _packetout(os,op,1);
  95964. }
  95965. int ogg_stream_packetpeek(ogg_stream_state *os,ogg_packet *op){
  95966. return _packetout(os,op,0);
  95967. }
  95968. void ogg_packet_clear(ogg_packet *op) {
  95969. _ogg_free(op->packet);
  95970. memset(op, 0, sizeof(*op));
  95971. }
  95972. #ifdef _V_SELFTEST
  95973. #include <stdio.h>
  95974. ogg_stream_state os_en, os_de;
  95975. ogg_sync_state oy;
  95976. void checkpacket(ogg_packet *op,int len, int no, int pos){
  95977. long j;
  95978. static int sequence=0;
  95979. static int lastno=0;
  95980. if(op->bytes!=len){
  95981. fprintf(stderr,"incorrect packet length!\n");
  95982. exit(1);
  95983. }
  95984. if(op->granulepos!=pos){
  95985. fprintf(stderr,"incorrect packet position!\n");
  95986. exit(1);
  95987. }
  95988. if(no==0){
  95989. sequence=0;
  95990. }else{
  95991. sequence++;
  95992. if(no>lastno+1)
  95993. sequence++;
  95994. }
  95995. lastno=no;
  95996. if(op->packetno!=sequence){
  95997. fprintf(stderr,"incorrect packet sequence %ld != %d\n",
  95998. (long)(op->packetno),sequence);
  95999. exit(1);
  96000. }
  96001. for(j=0;j<op->bytes;j++)
  96002. if(op->packet[j]!=((j+no)&0xff)){
  96003. fprintf(stderr,"body data mismatch (1) at pos %ld: %x!=%lx!\n\n",
  96004. j,op->packet[j],(j+no)&0xff);
  96005. exit(1);
  96006. }
  96007. }
  96008. void check_page(unsigned char *data,const int *header,ogg_page *og){
  96009. long j;
  96010. for(j=0;j<og->body_len;j++)
  96011. if(og->body[j]!=data[j]){
  96012. fprintf(stderr,"body data mismatch (2) at pos %ld: %x!=%x!\n\n",
  96013. j,data[j],og->body[j]);
  96014. exit(1);
  96015. }
  96016. for(j=0;j<og->header_len;j++){
  96017. if(og->header[j]!=header[j]){
  96018. fprintf(stderr,"header content mismatch at pos %ld:\n",j);
  96019. for(j=0;j<header[26]+27;j++)
  96020. fprintf(stderr," (%ld)%02x:%02x",j,header[j],og->header[j]);
  96021. fprintf(stderr,"\n");
  96022. exit(1);
  96023. }
  96024. }
  96025. if(og->header_len!=header[26]+27){
  96026. fprintf(stderr,"header length incorrect! (%ld!=%d)\n",
  96027. og->header_len,header[26]+27);
  96028. exit(1);
  96029. }
  96030. }
  96031. void print_header(ogg_page *og){
  96032. int j;
  96033. fprintf(stderr,"\nHEADER:\n");
  96034. fprintf(stderr," capture: %c %c %c %c version: %d flags: %x\n",
  96035. og->header[0],og->header[1],og->header[2],og->header[3],
  96036. (int)og->header[4],(int)og->header[5]);
  96037. fprintf(stderr," granulepos: %d serialno: %d pageno: %ld\n",
  96038. (og->header[9]<<24)|(og->header[8]<<16)|
  96039. (og->header[7]<<8)|og->header[6],
  96040. (og->header[17]<<24)|(og->header[16]<<16)|
  96041. (og->header[15]<<8)|og->header[14],
  96042. ((long)(og->header[21])<<24)|(og->header[20]<<16)|
  96043. (og->header[19]<<8)|og->header[18]);
  96044. fprintf(stderr," checksum: %02x:%02x:%02x:%02x\n segments: %d (",
  96045. (int)og->header[22],(int)og->header[23],
  96046. (int)og->header[24],(int)og->header[25],
  96047. (int)og->header[26]);
  96048. for(j=27;j<og->header_len;j++)
  96049. fprintf(stderr,"%d ",(int)og->header[j]);
  96050. fprintf(stderr,")\n\n");
  96051. }
  96052. void copy_page(ogg_page *og){
  96053. unsigned char *temp=_ogg_malloc(og->header_len);
  96054. memcpy(temp,og->header,og->header_len);
  96055. og->header=temp;
  96056. temp=_ogg_malloc(og->body_len);
  96057. memcpy(temp,og->body,og->body_len);
  96058. og->body=temp;
  96059. }
  96060. void free_page(ogg_page *og){
  96061. _ogg_free (og->header);
  96062. _ogg_free (og->body);
  96063. }
  96064. void error(void){
  96065. fprintf(stderr,"error!\n");
  96066. exit(1);
  96067. }
  96068. const int head1_0[] = {0x4f,0x67,0x67,0x53,0,0x06,
  96069. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  96070. 0x01,0x02,0x03,0x04,0,0,0,0,
  96071. 0x15,0xed,0xec,0x91,
  96072. 1,
  96073. 17};
  96074. const int head1_1[] = {0x4f,0x67,0x67,0x53,0,0x02,
  96075. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  96076. 0x01,0x02,0x03,0x04,0,0,0,0,
  96077. 0x59,0x10,0x6c,0x2c,
  96078. 1,
  96079. 17};
  96080. const int head2_1[] = {0x4f,0x67,0x67,0x53,0,0x04,
  96081. 0x07,0x18,0x00,0x00,0x00,0x00,0x00,0x00,
  96082. 0x01,0x02,0x03,0x04,1,0,0,0,
  96083. 0x89,0x33,0x85,0xce,
  96084. 13,
  96085. 254,255,0,255,1,255,245,255,255,0,
  96086. 255,255,90};
  96087. const int head1_2[] = {0x4f,0x67,0x67,0x53,0,0x02,
  96088. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  96089. 0x01,0x02,0x03,0x04,0,0,0,0,
  96090. 0xff,0x7b,0x23,0x17,
  96091. 1,
  96092. 0};
  96093. const int head2_2[] = {0x4f,0x67,0x67,0x53,0,0x04,
  96094. 0x07,0x28,0x00,0x00,0x00,0x00,0x00,0x00,
  96095. 0x01,0x02,0x03,0x04,1,0,0,0,
  96096. 0x5c,0x3f,0x66,0xcb,
  96097. 17,
  96098. 17,254,255,0,0,255,1,0,255,245,255,255,0,
  96099. 255,255,90,0};
  96100. const int head1_3[] = {0x4f,0x67,0x67,0x53,0,0x02,
  96101. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  96102. 0x01,0x02,0x03,0x04,0,0,0,0,
  96103. 0x01,0x27,0x31,0xaa,
  96104. 18,
  96105. 255,255,255,255,255,255,255,255,
  96106. 255,255,255,255,255,255,255,255,255,10};
  96107. const int head2_3[] = {0x4f,0x67,0x67,0x53,0,0x04,
  96108. 0x07,0x08,0x00,0x00,0x00,0x00,0x00,0x00,
  96109. 0x01,0x02,0x03,0x04,1,0,0,0,
  96110. 0x7f,0x4e,0x8a,0xd2,
  96111. 4,
  96112. 255,4,255,0};
  96113. const int head1_4[] = {0x4f,0x67,0x67,0x53,0,0x02,
  96114. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  96115. 0x01,0x02,0x03,0x04,0,0,0,0,
  96116. 0xff,0x7b,0x23,0x17,
  96117. 1,
  96118. 0};
  96119. const int head2_4[] = {0x4f,0x67,0x67,0x53,0,0x00,
  96120. 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
  96121. 0x01,0x02,0x03,0x04,1,0,0,0,
  96122. 0x54,0x05,0x51,0xc8,
  96123. 17,
  96124. 255,255,255,255,255,255,255,255,
  96125. 255,255,255,255,255,255,255,255,255};
  96126. const int head3_4[] = {0x4f,0x67,0x67,0x53,0,0x05,
  96127. 0x07,0x0c,0x00,0x00,0x00,0x00,0x00,0x00,
  96128. 0x01,0x02,0x03,0x04,2,0,0,0,
  96129. 0xc8,0xc3,0xcb,0xed,
  96130. 5,
  96131. 10,255,4,255,0};
  96132. const int head1_5[] = {0x4f,0x67,0x67,0x53,0,0x02,
  96133. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  96134. 0x01,0x02,0x03,0x04,0,0,0,0,
  96135. 0xff,0x7b,0x23,0x17,
  96136. 1,
  96137. 0};
  96138. const int head2_5[] = {0x4f,0x67,0x67,0x53,0,0x00,
  96139. 0x07,0xfc,0x03,0x00,0x00,0x00,0x00,0x00,
  96140. 0x01,0x02,0x03,0x04,1,0,0,0,
  96141. 0xed,0x2a,0x2e,0xa7,
  96142. 255,
  96143. 10,10,10,10,10,10,10,10,
  96144. 10,10,10,10,10,10,10,10,
  96145. 10,10,10,10,10,10,10,10,
  96146. 10,10,10,10,10,10,10,10,
  96147. 10,10,10,10,10,10,10,10,
  96148. 10,10,10,10,10,10,10,10,
  96149. 10,10,10,10,10,10,10,10,
  96150. 10,10,10,10,10,10,10,10,
  96151. 10,10,10,10,10,10,10,10,
  96152. 10,10,10,10,10,10,10,10,
  96153. 10,10,10,10,10,10,10,10,
  96154. 10,10,10,10,10,10,10,10,
  96155. 10,10,10,10,10,10,10,10,
  96156. 10,10,10,10,10,10,10,10,
  96157. 10,10,10,10,10,10,10,10,
  96158. 10,10,10,10,10,10,10,10,
  96159. 10,10,10,10,10,10,10,10,
  96160. 10,10,10,10,10,10,10,10,
  96161. 10,10,10,10,10,10,10,10,
  96162. 10,10,10,10,10,10,10,10,
  96163. 10,10,10,10,10,10,10,10,
  96164. 10,10,10,10,10,10,10,10,
  96165. 10,10,10,10,10,10,10,10,
  96166. 10,10,10,10,10,10,10,10,
  96167. 10,10,10,10,10,10,10,10,
  96168. 10,10,10,10,10,10,10,10,
  96169. 10,10,10,10,10,10,10,10,
  96170. 10,10,10,10,10,10,10,10,
  96171. 10,10,10,10,10,10,10,10,
  96172. 10,10,10,10,10,10,10,10,
  96173. 10,10,10,10,10,10,10,10,
  96174. 10,10,10,10,10,10,10};
  96175. const int head3_5[] = {0x4f,0x67,0x67,0x53,0,0x04,
  96176. 0x07,0x00,0x04,0x00,0x00,0x00,0x00,0x00,
  96177. 0x01,0x02,0x03,0x04,2,0,0,0,
  96178. 0x6c,0x3b,0x82,0x3d,
  96179. 1,
  96180. 50};
  96181. const int head1_6[] = {0x4f,0x67,0x67,0x53,0,0x02,
  96182. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  96183. 0x01,0x02,0x03,0x04,0,0,0,0,
  96184. 0xff,0x7b,0x23,0x17,
  96185. 1,
  96186. 0};
  96187. const int head2_6[] = {0x4f,0x67,0x67,0x53,0,0x00,
  96188. 0x07,0x04,0x00,0x00,0x00,0x00,0x00,0x00,
  96189. 0x01,0x02,0x03,0x04,1,0,0,0,
  96190. 0x3c,0xd9,0x4d,0x3f,
  96191. 17,
  96192. 100,255,255,255,255,255,255,255,255,
  96193. 255,255,255,255,255,255,255,255};
  96194. const int head3_6[] = {0x4f,0x67,0x67,0x53,0,0x01,
  96195. 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
  96196. 0x01,0x02,0x03,0x04,2,0,0,0,
  96197. 0x01,0xd2,0xe5,0xe5,
  96198. 17,
  96199. 255,255,255,255,255,255,255,255,
  96200. 255,255,255,255,255,255,255,255,255};
  96201. const int head4_6[] = {0x4f,0x67,0x67,0x53,0,0x05,
  96202. 0x07,0x10,0x00,0x00,0x00,0x00,0x00,0x00,
  96203. 0x01,0x02,0x03,0x04,3,0,0,0,
  96204. 0xef,0xdd,0x88,0xde,
  96205. 7,
  96206. 255,255,75,255,4,255,0};
  96207. const int head1_7[] = {0x4f,0x67,0x67,0x53,0,0x02,
  96208. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  96209. 0x01,0x02,0x03,0x04,0,0,0,0,
  96210. 0xff,0x7b,0x23,0x17,
  96211. 1,
  96212. 0};
  96213. const int head2_7[] = {0x4f,0x67,0x67,0x53,0,0x00,
  96214. 0x07,0x04,0x00,0x00,0x00,0x00,0x00,0x00,
  96215. 0x01,0x02,0x03,0x04,1,0,0,0,
  96216. 0x3c,0xd9,0x4d,0x3f,
  96217. 17,
  96218. 100,255,255,255,255,255,255,255,255,
  96219. 255,255,255,255,255,255,255,255};
  96220. const int head3_7[] = {0x4f,0x67,0x67,0x53,0,0x05,
  96221. 0x07,0x08,0x00,0x00,0x00,0x00,0x00,0x00,
  96222. 0x01,0x02,0x03,0x04,2,0,0,0,
  96223. 0xd4,0xe0,0x60,0xe5,
  96224. 1,0};
  96225. void test_pack(const int *pl, const int **headers, int byteskip,
  96226. int pageskip, int packetskip){
  96227. unsigned char *data=_ogg_malloc(1024*1024); /* for scripted test cases only */
  96228. long inptr=0;
  96229. long outptr=0;
  96230. long deptr=0;
  96231. long depacket=0;
  96232. long granule_pos=7,pageno=0;
  96233. int i,j,packets,pageout=pageskip;
  96234. int eosflag=0;
  96235. int bosflag=0;
  96236. int byteskipcount=0;
  96237. ogg_stream_reset(&os_en);
  96238. ogg_stream_reset(&os_de);
  96239. ogg_sync_reset(&oy);
  96240. for(packets=0;packets<packetskip;packets++)
  96241. depacket+=pl[packets];
  96242. for(packets=0;;packets++)if(pl[packets]==-1)break;
  96243. for(i=0;i<packets;i++){
  96244. ogg_packet op;
  96245. int len=pl[i];
  96246. op.packet=data+inptr;
  96247. op.bytes=len;
  96248. op.e_o_s=(pl[i+1]<0?1:0);
  96249. op.granulepos=granule_pos;
  96250. granule_pos+=1024;
  96251. for(j=0;j<len;j++)data[inptr++]=i+j;
  96252. ogg_stream_packetin(&os_en,&op);
  96253. {
  96254. ogg_page og;
  96255. while(ogg_stream_pageout(&os_en,&og)){
  96256. fprintf(stderr,"%ld, ",pageno);
  96257. if(headers[pageno]==NULL){
  96258. fprintf(stderr,"coded too many pages!\n");
  96259. exit(1);
  96260. }
  96261. check_page(data+outptr,headers[pageno],&og);
  96262. outptr+=og.body_len;
  96263. pageno++;
  96264. if(pageskip){
  96265. bosflag=1;
  96266. pageskip--;
  96267. deptr+=og.body_len;
  96268. }
  96269. {
  96270. ogg_page og_de;
  96271. ogg_packet op_de,op_de2;
  96272. char *buf=ogg_sync_buffer(&oy,og.header_len+og.body_len);
  96273. char *next=buf;
  96274. byteskipcount+=og.header_len;
  96275. if(byteskipcount>byteskip){
  96276. memcpy(next,og.header,byteskipcount-byteskip);
  96277. next+=byteskipcount-byteskip;
  96278. byteskipcount=byteskip;
  96279. }
  96280. byteskipcount+=og.body_len;
  96281. if(byteskipcount>byteskip){
  96282. memcpy(next,og.body,byteskipcount-byteskip);
  96283. next+=byteskipcount-byteskip;
  96284. byteskipcount=byteskip;
  96285. }
  96286. ogg_sync_wrote(&oy,next-buf);
  96287. while(1){
  96288. int ret=ogg_sync_pageout(&oy,&og_de);
  96289. if(ret==0)break;
  96290. if(ret<0)continue;
  96291. fprintf(stderr,"(%ld), ",pageout);
  96292. check_page(data+deptr,headers[pageout],&og_de);
  96293. deptr+=og_de.body_len;
  96294. pageout++;
  96295. ogg_stream_pagein(&os_de,&og_de);
  96296. while(ogg_stream_packetpeek(&os_de,&op_de2)>0){
  96297. ogg_stream_packetpeek(&os_de,NULL);
  96298. ogg_stream_packetout(&os_de,&op_de); /* just catching them all */
  96299. if(memcmp(&op_de,&op_de2,sizeof(op_de))){
  96300. fprintf(stderr,"packetout != packetpeek! pos=%ld\n",
  96301. depacket);
  96302. exit(1);
  96303. }
  96304. if(memcmp(data+depacket,op_de.packet,op_de.bytes)){
  96305. fprintf(stderr,"packet data mismatch in decode! pos=%ld\n",
  96306. depacket);
  96307. exit(1);
  96308. }
  96309. if(bosflag==0 && op_de.b_o_s==0){
  96310. fprintf(stderr,"b_o_s flag not set on packet!\n");
  96311. exit(1);
  96312. }
  96313. if(bosflag && op_de.b_o_s){
  96314. fprintf(stderr,"b_o_s flag incorrectly set on packet!\n");
  96315. exit(1);
  96316. }
  96317. bosflag=1;
  96318. depacket+=op_de.bytes;
  96319. if(eosflag){
  96320. fprintf(stderr,"Multiple decoded packets with eos flag!\n");
  96321. exit(1);
  96322. }
  96323. if(op_de.e_o_s)eosflag=1;
  96324. if(op_de.granulepos!=-1){
  96325. fprintf(stderr," granule:%ld ",(long)op_de.granulepos);
  96326. }
  96327. }
  96328. }
  96329. }
  96330. }
  96331. }
  96332. }
  96333. _ogg_free(data);
  96334. if(headers[pageno]!=NULL){
  96335. fprintf(stderr,"did not write last page!\n");
  96336. exit(1);
  96337. }
  96338. if(headers[pageout]!=NULL){
  96339. fprintf(stderr,"did not decode last page!\n");
  96340. exit(1);
  96341. }
  96342. if(inptr!=outptr){
  96343. fprintf(stderr,"encoded page data incomplete!\n");
  96344. exit(1);
  96345. }
  96346. if(inptr!=deptr){
  96347. fprintf(stderr,"decoded page data incomplete!\n");
  96348. exit(1);
  96349. }
  96350. if(inptr!=depacket){
  96351. fprintf(stderr,"decoded packet data incomplete!\n");
  96352. exit(1);
  96353. }
  96354. if(!eosflag){
  96355. fprintf(stderr,"Never got a packet with EOS set!\n");
  96356. exit(1);
  96357. }
  96358. fprintf(stderr,"ok.\n");
  96359. }
  96360. int main(void){
  96361. ogg_stream_init(&os_en,0x04030201);
  96362. ogg_stream_init(&os_de,0x04030201);
  96363. ogg_sync_init(&oy);
  96364. {
  96365. const int packets[]={17, -1};
  96366. const int *headret[]={head1_0,NULL};
  96367. fprintf(stderr,"testing single page encoding... ");
  96368. test_pack(packets,headret,0,0,0);
  96369. }
  96370. {
  96371. const int packets[]={17, 254, 255, 256, 500, 510, 600, -1};
  96372. const int *headret[]={head1_1,head2_1,NULL};
  96373. fprintf(stderr,"testing basic page encoding... ");
  96374. test_pack(packets,headret,0,0,0);
  96375. }
  96376. {
  96377. const int packets[]={0,17, 254, 255, 0, 256, 0, 500, 510, 600, 0, -1};
  96378. const int *headret[]={head1_2,head2_2,NULL};
  96379. fprintf(stderr,"testing basic nil packets... ");
  96380. test_pack(packets,headret,0,0,0);
  96381. }
  96382. {
  96383. const int packets[]={4345,259,255,-1};
  96384. const int *headret[]={head1_3,head2_3,NULL};
  96385. fprintf(stderr,"testing initial-packet lacing > 4k... ");
  96386. test_pack(packets,headret,0,0,0);
  96387. }
  96388. {
  96389. const int packets[]={0,4345,259,255,-1};
  96390. const int *headret[]={head1_4,head2_4,head3_4,NULL};
  96391. fprintf(stderr,"testing single packet page span... ");
  96392. test_pack(packets,headret,0,0,0);
  96393. }
  96394. {
  96395. const int packets[]={0,10,10,10,10,10,10,10,10,
  96396. 10,10,10,10,10,10,10,10,
  96397. 10,10,10,10,10,10,10,10,
  96398. 10,10,10,10,10,10,10,10,
  96399. 10,10,10,10,10,10,10,10,
  96400. 10,10,10,10,10,10,10,10,
  96401. 10,10,10,10,10,10,10,10,
  96402. 10,10,10,10,10,10,10,10,
  96403. 10,10,10,10,10,10,10,10,
  96404. 10,10,10,10,10,10,10,10,
  96405. 10,10,10,10,10,10,10,10,
  96406. 10,10,10,10,10,10,10,10,
  96407. 10,10,10,10,10,10,10,10,
  96408. 10,10,10,10,10,10,10,10,
  96409. 10,10,10,10,10,10,10,10,
  96410. 10,10,10,10,10,10,10,10,
  96411. 10,10,10,10,10,10,10,10,
  96412. 10,10,10,10,10,10,10,10,
  96413. 10,10,10,10,10,10,10,10,
  96414. 10,10,10,10,10,10,10,10,
  96415. 10,10,10,10,10,10,10,10,
  96416. 10,10,10,10,10,10,10,10,
  96417. 10,10,10,10,10,10,10,10,
  96418. 10,10,10,10,10,10,10,10,
  96419. 10,10,10,10,10,10,10,10,
  96420. 10,10,10,10,10,10,10,10,
  96421. 10,10,10,10,10,10,10,10,
  96422. 10,10,10,10,10,10,10,10,
  96423. 10,10,10,10,10,10,10,10,
  96424. 10,10,10,10,10,10,10,10,
  96425. 10,10,10,10,10,10,10,10,
  96426. 10,10,10,10,10,10,10,50,-1};
  96427. const int *headret[]={head1_5,head2_5,head3_5,NULL};
  96428. fprintf(stderr,"testing max packet segments... ");
  96429. test_pack(packets,headret,0,0,0);
  96430. }
  96431. {
  96432. const int packets[]={0,100,9000,259,255,-1};
  96433. const int *headret[]={head1_6,head2_6,head3_6,head4_6,NULL};
  96434. fprintf(stderr,"testing very large packets... ");
  96435. test_pack(packets,headret,0,0,0);
  96436. }
  96437. {
  96438. const int packets[]={0,100,9000,259,255,-1};
  96439. const int *headret[]={head1_6,head2_6,head3_6,head4_6,NULL};
  96440. fprintf(stderr,"testing continuation resync in very large packets... ");
  96441. test_pack(packets,headret,100,2,3);
  96442. }
  96443. {
  96444. const int packets[]={0,100,4080,-1};
  96445. const int *headret[]={head1_7,head2_7,head3_7,NULL};
  96446. fprintf(stderr,"testing zero data page (1 nil packet)... ");
  96447. test_pack(packets,headret,0,0,0);
  96448. }
  96449. {
  96450. unsigned char *data=_ogg_malloc(1024*1024);
  96451. int pl[]={0,100,4079,2956,2057,76,34,912,0,234,1000,1000,1000,300,-1};
  96452. int inptr=0,i,j;
  96453. ogg_page og[5];
  96454. ogg_stream_reset(&os_en);
  96455. for(i=0;pl[i]!=-1;i++){
  96456. ogg_packet op;
  96457. int len=pl[i];
  96458. op.packet=data+inptr;
  96459. op.bytes=len;
  96460. op.e_o_s=(pl[i+1]<0?1:0);
  96461. op.granulepos=(i+1)*1000;
  96462. for(j=0;j<len;j++)data[inptr++]=i+j;
  96463. ogg_stream_packetin(&os_en,&op);
  96464. }
  96465. _ogg_free(data);
  96466. for(i=0;i<5;i++){
  96467. if(ogg_stream_pageout(&os_en,&og[i])==0){
  96468. fprintf(stderr,"Too few pages output building sync tests!\n");
  96469. exit(1);
  96470. }
  96471. copy_page(&og[i]);
  96472. }
  96473. {
  96474. ogg_page temp;
  96475. ogg_packet test;
  96476. fprintf(stderr,"Testing loss of pages... ");
  96477. ogg_sync_reset(&oy);
  96478. ogg_stream_reset(&os_de);
  96479. for(i=0;i<5;i++){
  96480. memcpy(ogg_sync_buffer(&oy,og[i].header_len),og[i].header,
  96481. og[i].header_len);
  96482. ogg_sync_wrote(&oy,og[i].header_len);
  96483. memcpy(ogg_sync_buffer(&oy,og[i].body_len),og[i].body,og[i].body_len);
  96484. ogg_sync_wrote(&oy,og[i].body_len);
  96485. }
  96486. ogg_sync_pageout(&oy,&temp);
  96487. ogg_stream_pagein(&os_de,&temp);
  96488. ogg_sync_pageout(&oy,&temp);
  96489. ogg_stream_pagein(&os_de,&temp);
  96490. ogg_sync_pageout(&oy,&temp);
  96491. ogg_sync_pageout(&oy,&temp);
  96492. ogg_stream_pagein(&os_de,&temp);
  96493. if(ogg_stream_packetout(&os_de,&test)!=1)error();
  96494. checkpacket(&test,0,0,0);
  96495. if(ogg_stream_packetout(&os_de,&test)!=1)error();
  96496. checkpacket(&test,100,1,-1);
  96497. if(ogg_stream_packetout(&os_de,&test)!=1)error();
  96498. checkpacket(&test,4079,2,3000);
  96499. if(ogg_stream_packetout(&os_de,&test)!=-1){
  96500. fprintf(stderr,"Error: loss of page did not return error\n");
  96501. exit(1);
  96502. }
  96503. if(ogg_stream_packetout(&os_de,&test)!=1)error();
  96504. checkpacket(&test,76,5,-1);
  96505. if(ogg_stream_packetout(&os_de,&test)!=1)error();
  96506. checkpacket(&test,34,6,-1);
  96507. fprintf(stderr,"ok.\n");
  96508. }
  96509. {
  96510. ogg_page temp;
  96511. ogg_packet test;
  96512. fprintf(stderr,"Testing loss of pages (rollback required)... ");
  96513. ogg_sync_reset(&oy);
  96514. ogg_stream_reset(&os_de);
  96515. for(i=0;i<5;i++){
  96516. memcpy(ogg_sync_buffer(&oy,og[i].header_len),og[i].header,
  96517. og[i].header_len);
  96518. ogg_sync_wrote(&oy,og[i].header_len);
  96519. memcpy(ogg_sync_buffer(&oy,og[i].body_len),og[i].body,og[i].body_len);
  96520. ogg_sync_wrote(&oy,og[i].body_len);
  96521. }
  96522. ogg_sync_pageout(&oy,&temp);
  96523. ogg_stream_pagein(&os_de,&temp);
  96524. ogg_sync_pageout(&oy,&temp);
  96525. ogg_stream_pagein(&os_de,&temp);
  96526. ogg_sync_pageout(&oy,&temp);
  96527. ogg_stream_pagein(&os_de,&temp);
  96528. ogg_sync_pageout(&oy,&temp);
  96529. ogg_sync_pageout(&oy,&temp);
  96530. ogg_stream_pagein(&os_de,&temp);
  96531. if(ogg_stream_packetout(&os_de,&test)!=1)error();
  96532. checkpacket(&test,0,0,0);
  96533. if(ogg_stream_packetout(&os_de,&test)!=1)error();
  96534. checkpacket(&test,100,1,-1);
  96535. if(ogg_stream_packetout(&os_de,&test)!=1)error();
  96536. checkpacket(&test,4079,2,3000);
  96537. if(ogg_stream_packetout(&os_de,&test)!=1)error();
  96538. checkpacket(&test,2956,3,4000);
  96539. if(ogg_stream_packetout(&os_de,&test)!=-1){
  96540. fprintf(stderr,"Error: loss of page did not return error\n");
  96541. exit(1);
  96542. }
  96543. if(ogg_stream_packetout(&os_de,&test)!=1)error();
  96544. checkpacket(&test,300,13,14000);
  96545. fprintf(stderr,"ok.\n");
  96546. }
  96547. {
  96548. ogg_page og_de;
  96549. fprintf(stderr,"Testing sync on partial inputs... ");
  96550. ogg_sync_reset(&oy);
  96551. memcpy(ogg_sync_buffer(&oy,og[1].header_len),og[1].header,
  96552. 3);
  96553. ogg_sync_wrote(&oy,3);
  96554. if(ogg_sync_pageout(&oy,&og_de)>0)error();
  96555. memcpy(ogg_sync_buffer(&oy,og[1].header_len),og[1].header+3,
  96556. 20);
  96557. ogg_sync_wrote(&oy,20);
  96558. if(ogg_sync_pageout(&oy,&og_de)>0)error();
  96559. memcpy(ogg_sync_buffer(&oy,og[1].header_len),og[1].header+23,
  96560. 5);
  96561. ogg_sync_wrote(&oy,5);
  96562. if(ogg_sync_pageout(&oy,&og_de)>0)error();
  96563. memcpy(ogg_sync_buffer(&oy,og[1].header_len),og[1].header+28,
  96564. og[1].header_len-28);
  96565. ogg_sync_wrote(&oy,og[1].header_len-28);
  96566. if(ogg_sync_pageout(&oy,&og_de)>0)error();
  96567. memcpy(ogg_sync_buffer(&oy,og[1].body_len),og[1].body,1000);
  96568. ogg_sync_wrote(&oy,1000);
  96569. if(ogg_sync_pageout(&oy,&og_de)>0)error();
  96570. memcpy(ogg_sync_buffer(&oy,og[1].body_len),og[1].body+1000,
  96571. og[1].body_len-1000);
  96572. ogg_sync_wrote(&oy,og[1].body_len-1000);
  96573. if(ogg_sync_pageout(&oy,&og_de)<=0)error();
  96574. fprintf(stderr,"ok.\n");
  96575. }
  96576. {
  96577. ogg_page og_de;
  96578. fprintf(stderr,"Testing sync on 1+partial inputs... ");
  96579. ogg_sync_reset(&oy);
  96580. memcpy(ogg_sync_buffer(&oy,og[1].header_len),og[1].header,
  96581. og[1].header_len);
  96582. ogg_sync_wrote(&oy,og[1].header_len);
  96583. memcpy(ogg_sync_buffer(&oy,og[1].body_len),og[1].body,
  96584. og[1].body_len);
  96585. ogg_sync_wrote(&oy,og[1].body_len);
  96586. memcpy(ogg_sync_buffer(&oy,og[1].header_len),og[1].header,
  96587. 20);
  96588. ogg_sync_wrote(&oy,20);
  96589. if(ogg_sync_pageout(&oy,&og_de)<=0)error();
  96590. if(ogg_sync_pageout(&oy,&og_de)>0)error();
  96591. memcpy(ogg_sync_buffer(&oy,og[1].header_len),og[1].header+20,
  96592. og[1].header_len-20);
  96593. ogg_sync_wrote(&oy,og[1].header_len-20);
  96594. memcpy(ogg_sync_buffer(&oy,og[1].body_len),og[1].body,
  96595. og[1].body_len);
  96596. ogg_sync_wrote(&oy,og[1].body_len);
  96597. if(ogg_sync_pageout(&oy,&og_de)<=0)error();
  96598. fprintf(stderr,"ok.\n");
  96599. }
  96600. {
  96601. ogg_page og_de;
  96602. fprintf(stderr,"Testing search for capture... ");
  96603. ogg_sync_reset(&oy);
  96604. memcpy(ogg_sync_buffer(&oy,og[1].body_len),og[1].body,
  96605. og[1].body_len);
  96606. ogg_sync_wrote(&oy,og[1].body_len);
  96607. memcpy(ogg_sync_buffer(&oy,og[1].header_len),og[1].header,
  96608. og[1].header_len);
  96609. ogg_sync_wrote(&oy,og[1].header_len);
  96610. memcpy(ogg_sync_buffer(&oy,og[1].body_len),og[1].body,
  96611. og[1].body_len);
  96612. ogg_sync_wrote(&oy,og[1].body_len);
  96613. memcpy(ogg_sync_buffer(&oy,og[2].header_len),og[2].header,
  96614. 20);
  96615. ogg_sync_wrote(&oy,20);
  96616. if(ogg_sync_pageout(&oy,&og_de)>0)error();
  96617. if(ogg_sync_pageout(&oy,&og_de)<=0)error();
  96618. if(ogg_sync_pageout(&oy,&og_de)>0)error();
  96619. memcpy(ogg_sync_buffer(&oy,og[2].header_len),og[2].header+20,
  96620. og[2].header_len-20);
  96621. ogg_sync_wrote(&oy,og[2].header_len-20);
  96622. memcpy(ogg_sync_buffer(&oy,og[2].body_len),og[2].body,
  96623. og[2].body_len);
  96624. ogg_sync_wrote(&oy,og[2].body_len);
  96625. if(ogg_sync_pageout(&oy,&og_de)<=0)error();
  96626. fprintf(stderr,"ok.\n");
  96627. }
  96628. {
  96629. ogg_page og_de;
  96630. fprintf(stderr,"Testing recapture... ");
  96631. ogg_sync_reset(&oy);
  96632. memcpy(ogg_sync_buffer(&oy,og[1].header_len),og[1].header,
  96633. og[1].header_len);
  96634. ogg_sync_wrote(&oy,og[1].header_len);
  96635. memcpy(ogg_sync_buffer(&oy,og[1].body_len),og[1].body,
  96636. og[1].body_len);
  96637. ogg_sync_wrote(&oy,og[1].body_len);
  96638. memcpy(ogg_sync_buffer(&oy,og[2].header_len),og[2].header,
  96639. og[2].header_len);
  96640. ogg_sync_wrote(&oy,og[2].header_len);
  96641. memcpy(ogg_sync_buffer(&oy,og[2].header_len),og[2].header,
  96642. og[2].header_len);
  96643. ogg_sync_wrote(&oy,og[2].header_len);
  96644. if(ogg_sync_pageout(&oy,&og_de)<=0)error();
  96645. memcpy(ogg_sync_buffer(&oy,og[2].body_len),og[2].body,
  96646. og[2].body_len-5);
  96647. ogg_sync_wrote(&oy,og[2].body_len-5);
  96648. memcpy(ogg_sync_buffer(&oy,og[3].header_len),og[3].header,
  96649. og[3].header_len);
  96650. ogg_sync_wrote(&oy,og[3].header_len);
  96651. memcpy(ogg_sync_buffer(&oy,og[3].body_len),og[3].body,
  96652. og[3].body_len);
  96653. ogg_sync_wrote(&oy,og[3].body_len);
  96654. if(ogg_sync_pageout(&oy,&og_de)>0)error();
  96655. if(ogg_sync_pageout(&oy,&og_de)<=0)error();
  96656. fprintf(stderr,"ok.\n");
  96657. }
  96658. {
  96659. for(i=0;i<5;i++){
  96660. free_page(&og[i]);
  96661. }
  96662. }
  96663. }
  96664. return(0);
  96665. }
  96666. #endif
  96667. #endif
  96668. /*** End of inlined file: framing.c ***/
  96669. /*** Start of inlined file: analysis.c ***/
  96670. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  96671. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  96672. // tasks..
  96673. #if JUCE_MSVC
  96674. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  96675. #endif
  96676. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  96677. #if JUCE_USE_OGGVORBIS
  96678. #include <stdio.h>
  96679. #include <string.h>
  96680. #include <math.h>
  96681. /*** Start of inlined file: codec_internal.h ***/
  96682. #ifndef _V_CODECI_H_
  96683. #define _V_CODECI_H_
  96684. /*** Start of inlined file: envelope.h ***/
  96685. #ifndef _V_ENVELOPE_
  96686. #define _V_ENVELOPE_
  96687. /*** Start of inlined file: mdct.h ***/
  96688. #ifndef _OGG_mdct_H_
  96689. #define _OGG_mdct_H_
  96690. #ifdef MDCT_INTEGERIZED
  96691. #define DATA_TYPE int
  96692. #define REG_TYPE register int
  96693. #define TRIGBITS 14
  96694. #define cPI3_8 6270
  96695. #define cPI2_8 11585
  96696. #define cPI1_8 15137
  96697. #define FLOAT_CONV(x) ((int)((x)*(1<<TRIGBITS)+.5))
  96698. #define MULT_NORM(x) ((x)>>TRIGBITS)
  96699. #define HALVE(x) ((x)>>1)
  96700. #else
  96701. #define DATA_TYPE float
  96702. #define REG_TYPE float
  96703. #define cPI3_8 .38268343236508977175F
  96704. #define cPI2_8 .70710678118654752441F
  96705. #define cPI1_8 .92387953251128675613F
  96706. #define FLOAT_CONV(x) (x)
  96707. #define MULT_NORM(x) (x)
  96708. #define HALVE(x) ((x)*.5f)
  96709. #endif
  96710. typedef struct {
  96711. int n;
  96712. int log2n;
  96713. DATA_TYPE *trig;
  96714. int *bitrev;
  96715. DATA_TYPE scale;
  96716. } mdct_lookup;
  96717. extern void mdct_init(mdct_lookup *lookup,int n);
  96718. extern void mdct_clear(mdct_lookup *l);
  96719. extern void mdct_forward(mdct_lookup *init, DATA_TYPE *in, DATA_TYPE *out);
  96720. extern void mdct_backward(mdct_lookup *init, DATA_TYPE *in, DATA_TYPE *out);
  96721. #endif
  96722. /*** End of inlined file: mdct.h ***/
  96723. #define VE_PRE 16
  96724. #define VE_WIN 4
  96725. #define VE_POST 2
  96726. #define VE_AMP (VE_PRE+VE_POST-1)
  96727. #define VE_BANDS 7
  96728. #define VE_NEARDC 15
  96729. #define VE_MINSTRETCH 2 /* a bit less than short block */
  96730. #define VE_MAXSTRETCH 12 /* one-third full block */
  96731. typedef struct {
  96732. float ampbuf[VE_AMP];
  96733. int ampptr;
  96734. float nearDC[VE_NEARDC];
  96735. float nearDC_acc;
  96736. float nearDC_partialacc;
  96737. int nearptr;
  96738. } envelope_filter_state;
  96739. typedef struct {
  96740. int begin;
  96741. int end;
  96742. float *window;
  96743. float total;
  96744. } envelope_band;
  96745. typedef struct {
  96746. int ch;
  96747. int winlength;
  96748. int searchstep;
  96749. float minenergy;
  96750. mdct_lookup mdct;
  96751. float *mdct_win;
  96752. envelope_band band[VE_BANDS];
  96753. envelope_filter_state *filter;
  96754. int stretch;
  96755. int *mark;
  96756. long storage;
  96757. long current;
  96758. long curmark;
  96759. long cursor;
  96760. } envelope_lookup;
  96761. extern void _ve_envelope_init(envelope_lookup *e,vorbis_info *vi);
  96762. extern void _ve_envelope_clear(envelope_lookup *e);
  96763. extern long _ve_envelope_search(vorbis_dsp_state *v);
  96764. extern void _ve_envelope_shift(envelope_lookup *e,long shift);
  96765. extern int _ve_envelope_mark(vorbis_dsp_state *v);
  96766. #endif
  96767. /*** End of inlined file: envelope.h ***/
  96768. /*** Start of inlined file: codebook.h ***/
  96769. #ifndef _V_CODEBOOK_H_
  96770. #define _V_CODEBOOK_H_
  96771. typedef struct static_codebook{
  96772. long dim; /* codebook dimensions (elements per vector) */
  96773. long entries; /* codebook entries */
  96774. long *lengthlist; /* codeword lengths in bits */
  96775. int maptype; /* 0=none
  96776. 1=implicitly populated values from map column
  96777. 2=listed arbitrary values */
  96778. long q_min; /* packed 32 bit float; quant value 0 maps to minval */
  96779. long q_delta; /* packed 32 bit float; val 1 - val 0 == delta */
  96780. int q_quant; /* bits: 0 < quant <= 16 */
  96781. int q_sequencep; /* bitflag */
  96782. long *quantlist; /* map == 1: (int)(entries^(1/dim)) element column map
  96783. map == 2: list of dim*entries quantized entry vals
  96784. */
  96785. struct encode_aux_nearestmatch *nearest_tree;
  96786. struct encode_aux_threshmatch *thresh_tree;
  96787. struct encode_aux_pigeonhole *pigeon_tree;
  96788. int allocedp;
  96789. } static_codebook;
  96790. typedef struct encode_aux_nearestmatch{
  96791. long *ptr0;
  96792. long *ptr1;
  96793. long *p; /* decision points (each is an entry) */
  96794. long *q; /* decision points (each is an entry) */
  96795. long aux; /* number of tree entries */
  96796. long alloc;
  96797. } encode_aux_nearestmatch;
  96798. typedef struct encode_aux_threshmatch{
  96799. float *quantthresh;
  96800. long *quantmap;
  96801. int quantvals;
  96802. int threshvals;
  96803. } encode_aux_threshmatch;
  96804. typedef struct encode_aux_pigeonhole{
  96805. float min;
  96806. float del;
  96807. int mapentries;
  96808. int quantvals;
  96809. long *pigeonmap;
  96810. long fittotal;
  96811. long *fitlist;
  96812. long *fitmap;
  96813. long *fitlength;
  96814. } encode_aux_pigeonhole;
  96815. typedef struct codebook{
  96816. long dim; /* codebook dimensions (elements per vector) */
  96817. long entries; /* codebook entries */
  96818. long used_entries; /* populated codebook entries */
  96819. const static_codebook *c;
  96820. float *valuelist; /* list of dim*entries actual entry values */
  96821. ogg_uint32_t *codelist; /* list of bitstream codewords for each entry */
  96822. int *dec_index; /* only used if sparseness collapsed */
  96823. char *dec_codelengths;
  96824. ogg_uint32_t *dec_firsttable;
  96825. int dec_firsttablen;
  96826. int dec_maxlength;
  96827. } codebook;
  96828. extern void vorbis_staticbook_clear(static_codebook *b);
  96829. extern void vorbis_staticbook_destroy(static_codebook *b);
  96830. extern int vorbis_book_init_encode(codebook *dest,const static_codebook *source);
  96831. extern int vorbis_book_init_decode(codebook *dest,const static_codebook *source);
  96832. extern void vorbis_book_clear(codebook *b);
  96833. extern float *_book_unquantize(const static_codebook *b,int n,int *map);
  96834. extern float *_book_logdist(const static_codebook *b,float *vals);
  96835. extern float _float32_unpack(long val);
  96836. extern long _float32_pack(float val);
  96837. extern int _best(codebook *book, float *a, int step);
  96838. extern int _ilog(unsigned int v);
  96839. extern long _book_maptype1_quantvals(const static_codebook *b);
  96840. extern int vorbis_book_besterror(codebook *book,float *a,int step,int addmul);
  96841. extern long vorbis_book_codeword(codebook *book,int entry);
  96842. extern long vorbis_book_codelen(codebook *book,int entry);
  96843. extern int vorbis_staticbook_pack(const static_codebook *c,oggpack_buffer *b);
  96844. extern int vorbis_staticbook_unpack(oggpack_buffer *b,static_codebook *c);
  96845. extern int vorbis_book_encode(codebook *book, int a, oggpack_buffer *b);
  96846. extern int vorbis_book_errorv(codebook *book, float *a);
  96847. extern int vorbis_book_encodev(codebook *book, int best,float *a,
  96848. oggpack_buffer *b);
  96849. extern long vorbis_book_decode(codebook *book, oggpack_buffer *b);
  96850. extern long vorbis_book_decodevs_add(codebook *book, float *a,
  96851. oggpack_buffer *b,int n);
  96852. extern long vorbis_book_decodev_set(codebook *book, float *a,
  96853. oggpack_buffer *b,int n);
  96854. extern long vorbis_book_decodev_add(codebook *book, float *a,
  96855. oggpack_buffer *b,int n);
  96856. extern long vorbis_book_decodevv_add(codebook *book, float **a,
  96857. long off,int ch,
  96858. oggpack_buffer *b,int n);
  96859. #endif
  96860. /*** End of inlined file: codebook.h ***/
  96861. #define BLOCKTYPE_IMPULSE 0
  96862. #define BLOCKTYPE_PADDING 1
  96863. #define BLOCKTYPE_TRANSITION 0
  96864. #define BLOCKTYPE_LONG 1
  96865. #define PACKETBLOBS 15
  96866. typedef struct vorbis_block_internal{
  96867. float **pcmdelay; /* this is a pointer into local storage */
  96868. float ampmax;
  96869. int blocktype;
  96870. oggpack_buffer *packetblob[PACKETBLOBS]; /* initialized, must be freed;
  96871. blob [PACKETBLOBS/2] points to
  96872. the oggpack_buffer in the
  96873. main vorbis_block */
  96874. } vorbis_block_internal;
  96875. typedef void vorbis_look_floor;
  96876. typedef void vorbis_look_residue;
  96877. typedef void vorbis_look_transform;
  96878. typedef struct {
  96879. int blockflag;
  96880. int windowtype;
  96881. int transformtype;
  96882. int mapping;
  96883. } vorbis_info_mode;
  96884. typedef void vorbis_info_floor;
  96885. typedef void vorbis_info_residue;
  96886. typedef void vorbis_info_mapping;
  96887. /*** Start of inlined file: psy.h ***/
  96888. #ifndef _V_PSY_H_
  96889. #define _V_PSY_H_
  96890. /*** Start of inlined file: smallft.h ***/
  96891. #ifndef _V_SMFT_H_
  96892. #define _V_SMFT_H_
  96893. typedef struct {
  96894. int n;
  96895. float *trigcache;
  96896. int *splitcache;
  96897. } drft_lookup;
  96898. extern void drft_forward(drft_lookup *l,float *data);
  96899. extern void drft_backward(drft_lookup *l,float *data);
  96900. extern void drft_init(drft_lookup *l,int n);
  96901. extern void drft_clear(drft_lookup *l);
  96902. #endif
  96903. /*** End of inlined file: smallft.h ***/
  96904. /*** Start of inlined file: backends.h ***/
  96905. #ifndef _vorbis_backend_h_
  96906. #define _vorbis_backend_h_
  96907. typedef struct{
  96908. void (*pack) (vorbis_info_floor *,oggpack_buffer *);
  96909. vorbis_info_floor *(*unpack)(vorbis_info *,oggpack_buffer *);
  96910. vorbis_look_floor *(*look) (vorbis_dsp_state *,vorbis_info_floor *);
  96911. void (*free_info) (vorbis_info_floor *);
  96912. void (*free_look) (vorbis_look_floor *);
  96913. void *(*inverse1) (struct vorbis_block *,vorbis_look_floor *);
  96914. int (*inverse2) (struct vorbis_block *,vorbis_look_floor *,
  96915. void *buffer,float *);
  96916. } vorbis_func_floor;
  96917. typedef struct{
  96918. int order;
  96919. long rate;
  96920. long barkmap;
  96921. int ampbits;
  96922. int ampdB;
  96923. int numbooks; /* <= 16 */
  96924. int books[16];
  96925. float lessthan; /* encode-only config setting hacks for libvorbis */
  96926. float greaterthan; /* encode-only config setting hacks for libvorbis */
  96927. } vorbis_info_floor0;
  96928. #define VIF_POSIT 63
  96929. #define VIF_CLASS 16
  96930. #define VIF_PARTS 31
  96931. typedef struct{
  96932. int partitions; /* 0 to 31 */
  96933. int partitionclass[VIF_PARTS]; /* 0 to 15 */
  96934. int class_dim[VIF_CLASS]; /* 1 to 8 */
  96935. int class_subs[VIF_CLASS]; /* 0,1,2,3 (bits: 1<<n poss) */
  96936. int class_book[VIF_CLASS]; /* subs ^ dim entries */
  96937. int class_subbook[VIF_CLASS][8]; /* [VIF_CLASS][subs] */
  96938. int mult; /* 1 2 3 or 4 */
  96939. int postlist[VIF_POSIT+2]; /* first two implicit */
  96940. float maxover;
  96941. float maxunder;
  96942. float maxerr;
  96943. float twofitweight;
  96944. float twofitatten;
  96945. int n;
  96946. } vorbis_info_floor1;
  96947. typedef struct{
  96948. void (*pack) (vorbis_info_residue *,oggpack_buffer *);
  96949. vorbis_info_residue *(*unpack)(vorbis_info *,oggpack_buffer *);
  96950. vorbis_look_residue *(*look) (vorbis_dsp_state *,
  96951. vorbis_info_residue *);
  96952. void (*free_info) (vorbis_info_residue *);
  96953. void (*free_look) (vorbis_look_residue *);
  96954. long **(*classx) (struct vorbis_block *,vorbis_look_residue *,
  96955. float **,int *,int);
  96956. int (*forward) (oggpack_buffer *,struct vorbis_block *,
  96957. vorbis_look_residue *,
  96958. float **,float **,int *,int,long **);
  96959. int (*inverse) (struct vorbis_block *,vorbis_look_residue *,
  96960. float **,int *,int);
  96961. } vorbis_func_residue;
  96962. typedef struct vorbis_info_residue0{
  96963. long begin;
  96964. long end;
  96965. int grouping; /* group n vectors per partition */
  96966. int partitions; /* possible codebooks for a partition */
  96967. int groupbook; /* huffbook for partitioning */
  96968. int secondstages[64]; /* expanded out to pointers in lookup */
  96969. int booklist[256]; /* list of second stage books */
  96970. float classmetric1[64];
  96971. float classmetric2[64];
  96972. } vorbis_info_residue0;
  96973. typedef struct{
  96974. void (*pack) (vorbis_info *,vorbis_info_mapping *,
  96975. oggpack_buffer *);
  96976. vorbis_info_mapping *(*unpack)(vorbis_info *,oggpack_buffer *);
  96977. void (*free_info) (vorbis_info_mapping *);
  96978. int (*forward) (struct vorbis_block *vb);
  96979. int (*inverse) (struct vorbis_block *vb,vorbis_info_mapping *);
  96980. } vorbis_func_mapping;
  96981. typedef struct vorbis_info_mapping0{
  96982. int submaps; /* <= 16 */
  96983. int chmuxlist[256]; /* up to 256 channels in a Vorbis stream */
  96984. int floorsubmap[16]; /* [mux] submap to floors */
  96985. int residuesubmap[16]; /* [mux] submap to residue */
  96986. int coupling_steps;
  96987. int coupling_mag[256];
  96988. int coupling_ang[256];
  96989. } vorbis_info_mapping0;
  96990. #endif
  96991. /*** End of inlined file: backends.h ***/
  96992. #ifndef EHMER_MAX
  96993. #define EHMER_MAX 56
  96994. #endif
  96995. #define P_BANDS 17 /* 62Hz to 16kHz */
  96996. #define P_LEVELS 8 /* 30dB to 100dB */
  96997. #define P_LEVEL_0 30. /* 30 dB */
  96998. #define P_NOISECURVES 3
  96999. #define NOISE_COMPAND_LEVELS 40
  97000. typedef struct vorbis_info_psy{
  97001. int blockflag;
  97002. float ath_adjatt;
  97003. float ath_maxatt;
  97004. float tone_masteratt[P_NOISECURVES];
  97005. float tone_centerboost;
  97006. float tone_decay;
  97007. float tone_abs_limit;
  97008. float toneatt[P_BANDS];
  97009. int noisemaskp;
  97010. float noisemaxsupp;
  97011. float noisewindowlo;
  97012. float noisewindowhi;
  97013. int noisewindowlomin;
  97014. int noisewindowhimin;
  97015. int noisewindowfixed;
  97016. float noiseoff[P_NOISECURVES][P_BANDS];
  97017. float noisecompand[NOISE_COMPAND_LEVELS];
  97018. float max_curve_dB;
  97019. int normal_channel_p;
  97020. int normal_point_p;
  97021. int normal_start;
  97022. int normal_partition;
  97023. double normal_thresh;
  97024. } vorbis_info_psy;
  97025. typedef struct{
  97026. int eighth_octave_lines;
  97027. float preecho_thresh[VE_BANDS];
  97028. float postecho_thresh[VE_BANDS];
  97029. float stretch_penalty;
  97030. float preecho_minenergy;
  97031. float ampmax_att_per_sec;
  97032. int coupling_pkHz[PACKETBLOBS];
  97033. int coupling_pointlimit[2][PACKETBLOBS];
  97034. int coupling_prepointamp[PACKETBLOBS];
  97035. int coupling_postpointamp[PACKETBLOBS];
  97036. int sliding_lowpass[2][PACKETBLOBS];
  97037. } vorbis_info_psy_global;
  97038. typedef struct {
  97039. float ampmax;
  97040. int channels;
  97041. vorbis_info_psy_global *gi;
  97042. int coupling_pointlimit[2][P_NOISECURVES];
  97043. } vorbis_look_psy_global;
  97044. typedef struct {
  97045. int n;
  97046. struct vorbis_info_psy *vi;
  97047. float ***tonecurves;
  97048. float **noiseoffset;
  97049. float *ath;
  97050. long *octave; /* in n.ocshift format */
  97051. long *bark;
  97052. long firstoc;
  97053. long shiftoc;
  97054. int eighth_octave_lines; /* power of two, please */
  97055. int total_octave_lines;
  97056. long rate; /* cache it */
  97057. float m_val; /* Masking compensation value */
  97058. } vorbis_look_psy;
  97059. extern void _vp_psy_init(vorbis_look_psy *p,vorbis_info_psy *vi,
  97060. vorbis_info_psy_global *gi,int n,long rate);
  97061. extern void _vp_psy_clear(vorbis_look_psy *p);
  97062. extern void *_vi_psy_dup(void *source);
  97063. extern void _vi_psy_free(vorbis_info_psy *i);
  97064. extern vorbis_info_psy *_vi_psy_copy(vorbis_info_psy *i);
  97065. extern void _vp_remove_floor(vorbis_look_psy *p,
  97066. float *mdct,
  97067. int *icodedflr,
  97068. float *residue,
  97069. int sliding_lowpass);
  97070. extern void _vp_noisemask(vorbis_look_psy *p,
  97071. float *logmdct,
  97072. float *logmask);
  97073. extern void _vp_tonemask(vorbis_look_psy *p,
  97074. float *logfft,
  97075. float *logmask,
  97076. float global_specmax,
  97077. float local_specmax);
  97078. extern void _vp_offset_and_mix(vorbis_look_psy *p,
  97079. float *noise,
  97080. float *tone,
  97081. int offset_select,
  97082. float *logmask,
  97083. float *mdct,
  97084. float *logmdct);
  97085. extern float _vp_ampmax_decay(float amp,vorbis_dsp_state *vd);
  97086. extern float **_vp_quantize_couple_memo(vorbis_block *vb,
  97087. vorbis_info_psy_global *g,
  97088. vorbis_look_psy *p,
  97089. vorbis_info_mapping0 *vi,
  97090. float **mdct);
  97091. extern void _vp_couple(int blobno,
  97092. vorbis_info_psy_global *g,
  97093. vorbis_look_psy *p,
  97094. vorbis_info_mapping0 *vi,
  97095. float **res,
  97096. float **mag_memo,
  97097. int **mag_sort,
  97098. int **ifloor,
  97099. int *nonzero,
  97100. int sliding_lowpass);
  97101. extern void _vp_noise_normalize(vorbis_look_psy *p,
  97102. float *in,float *out,int *sortedindex);
  97103. extern void _vp_noise_normalize_sort(vorbis_look_psy *p,
  97104. float *magnitudes,int *sortedindex);
  97105. extern int **_vp_quantize_couple_sort(vorbis_block *vb,
  97106. vorbis_look_psy *p,
  97107. vorbis_info_mapping0 *vi,
  97108. float **mags);
  97109. extern void hf_reduction(vorbis_info_psy_global *g,
  97110. vorbis_look_psy *p,
  97111. vorbis_info_mapping0 *vi,
  97112. float **mdct);
  97113. #endif
  97114. /*** End of inlined file: psy.h ***/
  97115. /*** Start of inlined file: bitrate.h ***/
  97116. #ifndef _V_BITRATE_H_
  97117. #define _V_BITRATE_H_
  97118. /*** Start of inlined file: os.h ***/
  97119. #ifndef _OS_H
  97120. #define _OS_H
  97121. #ifdef HAVE_CONFIG_H
  97122. #include "config.h"
  97123. #endif
  97124. #include <math.h>
  97125. /*** Start of inlined file: misc.h ***/
  97126. #ifndef _V_RANDOM_H_
  97127. #define _V_RANDOM_H_
  97128. extern int analysis_noisy;
  97129. extern void *_vorbis_block_alloc(vorbis_block *vb,long bytes);
  97130. extern void _vorbis_block_ripcord(vorbis_block *vb);
  97131. extern void _analysis_output(char *base,int i,float *v,int n,int bark,int dB,
  97132. ogg_int64_t off);
  97133. #ifdef DEBUG_MALLOC
  97134. #define _VDBG_GRAPHFILE "malloc.m"
  97135. extern void *_VDBG_malloc(void *ptr,long bytes,char *file,long line);
  97136. extern void _VDBG_free(void *ptr,char *file,long line);
  97137. #ifndef MISC_C
  97138. #undef _ogg_malloc
  97139. #undef _ogg_calloc
  97140. #undef _ogg_realloc
  97141. #undef _ogg_free
  97142. #define _ogg_malloc(x) _VDBG_malloc(NULL,(x),__FILE__,__LINE__)
  97143. #define _ogg_calloc(x,y) _VDBG_malloc(NULL,(x)*(y),__FILE__,__LINE__)
  97144. #define _ogg_realloc(x,y) _VDBG_malloc((x),(y),__FILE__,__LINE__)
  97145. #define _ogg_free(x) _VDBG_free((x),__FILE__,__LINE__)
  97146. #endif
  97147. #endif
  97148. #endif
  97149. /*** End of inlined file: misc.h ***/
  97150. #ifndef _V_IFDEFJAIL_H_
  97151. # define _V_IFDEFJAIL_H_
  97152. # ifdef __GNUC__
  97153. # define STIN static __inline__
  97154. # elif _WIN32
  97155. # define STIN static __inline
  97156. # else
  97157. # define STIN static
  97158. # endif
  97159. #ifdef DJGPP
  97160. # define rint(x) (floor((x)+0.5f))
  97161. #endif
  97162. #ifndef M_PI
  97163. # define M_PI (3.1415926536f)
  97164. #endif
  97165. #if defined(_WIN32) && !defined(__SYMBIAN32__)
  97166. # include <malloc.h>
  97167. # define rint(x) (floor((x)+0.5f))
  97168. # define NO_FLOAT_MATH_LIB
  97169. # define FAST_HYPOT(a, b) sqrt((a)*(a) + (b)*(b))
  97170. #endif
  97171. #if defined(__SYMBIAN32__) && defined(__WINS__)
  97172. void *_alloca(size_t size);
  97173. # define alloca _alloca
  97174. #endif
  97175. #ifndef FAST_HYPOT
  97176. # define FAST_HYPOT hypot
  97177. #endif
  97178. #endif
  97179. #ifdef HAVE_ALLOCA_H
  97180. # include <alloca.h>
  97181. #endif
  97182. #ifdef USE_MEMORY_H
  97183. # include <memory.h>
  97184. #endif
  97185. #ifndef min
  97186. # define min(x,y) ((x)>(y)?(y):(x))
  97187. #endif
  97188. #ifndef max
  97189. # define max(x,y) ((x)<(y)?(y):(x))
  97190. #endif
  97191. #if defined(__i386__) && defined(__GNUC__) && !defined(__BEOS__)
  97192. # define VORBIS_FPU_CONTROL
  97193. typedef ogg_int16_t vorbis_fpu_control;
  97194. static inline void vorbis_fpu_setround(vorbis_fpu_control *fpu){
  97195. ogg_int16_t ret;
  97196. ogg_int16_t temp;
  97197. __asm__ __volatile__("fnstcw %0\n\t"
  97198. "movw %0,%%dx\n\t"
  97199. "orw $62463,%%dx\n\t"
  97200. "movw %%dx,%1\n\t"
  97201. "fldcw %1\n\t":"=m"(ret):"m"(temp): "dx");
  97202. *fpu=ret;
  97203. }
  97204. static inline void vorbis_fpu_restore(vorbis_fpu_control fpu){
  97205. __asm__ __volatile__("fldcw %0":: "m"(fpu));
  97206. }
  97207. static inline int vorbis_ftoi(double f){ /* yes, double! Otherwise,
  97208. we get extra fst/fld to
  97209. truncate precision */
  97210. int i;
  97211. __asm__("fistl %0": "=m"(i) : "t"(f));
  97212. return(i);
  97213. }
  97214. #endif
  97215. #if defined(_WIN32) && defined(_X86_) && !defined(__GNUC__) && !defined(__BORLANDC__)
  97216. # define VORBIS_FPU_CONTROL
  97217. typedef ogg_int16_t vorbis_fpu_control;
  97218. static __inline int vorbis_ftoi(double f){
  97219. int i;
  97220. __asm{
  97221. fld f
  97222. fistp i
  97223. }
  97224. return i;
  97225. }
  97226. static __inline void vorbis_fpu_setround(vorbis_fpu_control *fpu){
  97227. }
  97228. static __inline void vorbis_fpu_restore(vorbis_fpu_control fpu){
  97229. }
  97230. #endif
  97231. #ifndef VORBIS_FPU_CONTROL
  97232. typedef int vorbis_fpu_control;
  97233. static int vorbis_ftoi(double f){
  97234. return (int)(f+.5);
  97235. }
  97236. # define vorbis_fpu_setround(vorbis_fpu_control) {}
  97237. # define vorbis_fpu_restore(vorbis_fpu_control) {}
  97238. #endif
  97239. #endif /* _OS_H */
  97240. /*** End of inlined file: os.h ***/
  97241. typedef struct bitrate_manager_state {
  97242. int managed;
  97243. long avg_reservoir;
  97244. long minmax_reservoir;
  97245. long avg_bitsper;
  97246. long min_bitsper;
  97247. long max_bitsper;
  97248. long short_per_long;
  97249. double avgfloat;
  97250. vorbis_block *vb;
  97251. int choice;
  97252. } bitrate_manager_state;
  97253. typedef struct bitrate_manager_info{
  97254. long avg_rate;
  97255. long min_rate;
  97256. long max_rate;
  97257. long reservoir_bits;
  97258. double reservoir_bias;
  97259. double slew_damp;
  97260. } bitrate_manager_info;
  97261. extern void vorbis_bitrate_init(vorbis_info *vi,bitrate_manager_state *bs);
  97262. extern void vorbis_bitrate_clear(bitrate_manager_state *bs);
  97263. extern int vorbis_bitrate_managed(vorbis_block *vb);
  97264. extern int vorbis_bitrate_addblock(vorbis_block *vb);
  97265. extern int vorbis_bitrate_flushpacket(vorbis_dsp_state *vd, ogg_packet *op);
  97266. #endif
  97267. /*** End of inlined file: bitrate.h ***/
  97268. static int ilog(unsigned int v){
  97269. int ret=0;
  97270. while(v){
  97271. ret++;
  97272. v>>=1;
  97273. }
  97274. return(ret);
  97275. }
  97276. static int ilog2(unsigned int v){
  97277. int ret=0;
  97278. if(v)--v;
  97279. while(v){
  97280. ret++;
  97281. v>>=1;
  97282. }
  97283. return(ret);
  97284. }
  97285. typedef struct private_state {
  97286. envelope_lookup *ve; /* envelope lookup */
  97287. int window[2];
  97288. vorbis_look_transform **transform[2]; /* block, type */
  97289. drft_lookup fft_look[2];
  97290. int modebits;
  97291. vorbis_look_floor **flr;
  97292. vorbis_look_residue **residue;
  97293. vorbis_look_psy *psy;
  97294. vorbis_look_psy_global *psy_g_look;
  97295. unsigned char *header;
  97296. unsigned char *header1;
  97297. unsigned char *header2;
  97298. bitrate_manager_state bms;
  97299. ogg_int64_t sample_count;
  97300. } private_state;
  97301. /*** Start of inlined file: highlevel.h ***/
  97302. typedef struct highlevel_byblocktype {
  97303. double tone_mask_setting;
  97304. double tone_peaklimit_setting;
  97305. double noise_bias_setting;
  97306. double noise_compand_setting;
  97307. } highlevel_byblocktype;
  97308. typedef struct highlevel_encode_setup {
  97309. void *setup;
  97310. int set_in_stone;
  97311. double base_setting;
  97312. double long_setting;
  97313. double short_setting;
  97314. double impulse_noisetune;
  97315. int managed;
  97316. long bitrate_min;
  97317. long bitrate_av;
  97318. double bitrate_av_damp;
  97319. long bitrate_max;
  97320. long bitrate_reservoir;
  97321. double bitrate_reservoir_bias;
  97322. int impulse_block_p;
  97323. int noise_normalize_p;
  97324. double stereo_point_setting;
  97325. double lowpass_kHz;
  97326. double ath_floating_dB;
  97327. double ath_absolute_dB;
  97328. double amplitude_track_dBpersec;
  97329. double trigger_setting;
  97330. highlevel_byblocktype block[4]; /* padding, impulse, transition, long */
  97331. } highlevel_encode_setup;
  97332. /*** End of inlined file: highlevel.h ***/
  97333. typedef struct codec_setup_info {
  97334. long blocksizes[2];
  97335. int modes;
  97336. int maps;
  97337. int floors;
  97338. int residues;
  97339. int books;
  97340. int psys; /* encode only */
  97341. vorbis_info_mode *mode_param[64];
  97342. int map_type[64];
  97343. vorbis_info_mapping *map_param[64];
  97344. int floor_type[64];
  97345. vorbis_info_floor *floor_param[64];
  97346. int residue_type[64];
  97347. vorbis_info_residue *residue_param[64];
  97348. static_codebook *book_param[256];
  97349. codebook *fullbooks;
  97350. vorbis_info_psy *psy_param[4]; /* encode only */
  97351. vorbis_info_psy_global psy_g_param;
  97352. bitrate_manager_info bi;
  97353. highlevel_encode_setup hi; /* used only by vorbisenc.c. It's a
  97354. highly redundant structure, but
  97355. improves clarity of program flow. */
  97356. int halfrate_flag; /* painless downsample for decode */
  97357. } codec_setup_info;
  97358. extern vorbis_look_psy_global *_vp_global_look(vorbis_info *vi);
  97359. extern void _vp_global_free(vorbis_look_psy_global *look);
  97360. #endif
  97361. /*** End of inlined file: codec_internal.h ***/
  97362. /*** Start of inlined file: registry.h ***/
  97363. #ifndef _V_REG_H_
  97364. #define _V_REG_H_
  97365. #define VI_TRANSFORMB 1
  97366. #define VI_WINDOWB 1
  97367. #define VI_TIMEB 1
  97368. #define VI_FLOORB 2
  97369. #define VI_RESB 3
  97370. #define VI_MAPB 1
  97371. extern vorbis_func_floor *_floor_P[];
  97372. extern vorbis_func_residue *_residue_P[];
  97373. extern vorbis_func_mapping *_mapping_P[];
  97374. #endif
  97375. /*** End of inlined file: registry.h ***/
  97376. /*** Start of inlined file: scales.h ***/
  97377. #ifndef _V_SCALES_H_
  97378. #define _V_SCALES_H_
  97379. #include <math.h>
  97380. #define VORBIS_IEEE_FLOAT32 1
  97381. #ifdef VORBIS_IEEE_FLOAT32
  97382. static float unitnorm(float x){
  97383. union {
  97384. ogg_uint32_t i;
  97385. float f;
  97386. } ix;
  97387. ix.f = x;
  97388. ix.i = (ix.i & 0x80000000U) | (0x3f800000U);
  97389. return ix.f;
  97390. }
  97391. static float todB(const float *x){
  97392. union {
  97393. ogg_uint32_t i;
  97394. float f;
  97395. } ix;
  97396. ix.f = *x;
  97397. ix.i = ix.i&0x7fffffff;
  97398. return (float)(ix.i * 7.17711438e-7f -764.6161886f);
  97399. }
  97400. #define todB_nn(x) todB(x)
  97401. #else
  97402. static float unitnorm(float x){
  97403. if(x<0)return(-1.f);
  97404. return(1.f);
  97405. }
  97406. #define todB(x) (*(x)==0?-400.f:log(*(x)**(x))*4.34294480f)
  97407. #define todB_nn(x) (*(x)==0.f?-400.f:log(*(x))*8.6858896f)
  97408. #endif
  97409. #define fromdB(x) (exp((x)*.11512925f))
  97410. #define toBARK(n) (13.1f*atan(.00074f*(n))+2.24f*atan((n)*(n)*1.85e-8f)+1e-4f*(n))
  97411. #define fromBARK(z) (102.f*(z)-2.f*pow(z,2.f)+.4f*pow(z,3.f)+pow(1.46f,z)-1.f)
  97412. #define toMEL(n) (log(1.f+(n)*.001f)*1442.695f)
  97413. #define fromMEL(m) (1000.f*exp((m)/1442.695f)-1000.f)
  97414. #define toOC(n) (log(n)*1.442695f-5.965784f)
  97415. #define fromOC(o) (exp(((o)+5.965784f)*.693147f))
  97416. #endif
  97417. /*** End of inlined file: scales.h ***/
  97418. int analysis_noisy=1;
  97419. int vorbis_analysis(vorbis_block *vb, ogg_packet *op){
  97420. int ret,i;
  97421. vorbis_block_internal *vbi=(vorbis_block_internal *)vb->internal;
  97422. vb->glue_bits=0;
  97423. vb->time_bits=0;
  97424. vb->floor_bits=0;
  97425. vb->res_bits=0;
  97426. for(i=0;i<PACKETBLOBS;i++)
  97427. oggpack_reset(vbi->packetblob[i]);
  97428. if((ret=_mapping_P[0]->forward(vb)))
  97429. return(ret);
  97430. if(op){
  97431. if(vorbis_bitrate_managed(vb))
  97432. return(OV_EINVAL);
  97433. op->packet=oggpack_get_buffer(&vb->opb);
  97434. op->bytes=oggpack_bytes(&vb->opb);
  97435. op->b_o_s=0;
  97436. op->e_o_s=vb->eofflag;
  97437. op->granulepos=vb->granulepos;
  97438. op->packetno=vb->sequence; /* for sake of completeness */
  97439. }
  97440. return(0);
  97441. }
  97442. void _analysis_output_always(const char *base,int i,float *v,int n,int bark,int dB,ogg_int64_t off){
  97443. int j;
  97444. FILE *of;
  97445. char buffer[80];
  97446. sprintf(buffer,"%s_%d.m",base,i);
  97447. of=fopen(buffer,"w");
  97448. if(!of)perror("failed to open data dump file");
  97449. for(j=0;j<n;j++){
  97450. if(bark){
  97451. float b=toBARK((4000.f*j/n)+.25);
  97452. fprintf(of,"%f ",b);
  97453. }else
  97454. if(off!=0)
  97455. fprintf(of,"%f ",(double)(j+off)/8000.);
  97456. else
  97457. fprintf(of,"%f ",(double)j);
  97458. if(dB){
  97459. float val;
  97460. if(v[j]==0.)
  97461. val=-140.;
  97462. else
  97463. val=todB(v+j);
  97464. fprintf(of,"%f\n",val);
  97465. }else{
  97466. fprintf(of,"%f\n",v[j]);
  97467. }
  97468. }
  97469. fclose(of);
  97470. }
  97471. void _analysis_output(char *base,int i,float *v,int n,int bark,int dB,
  97472. ogg_int64_t off){
  97473. if(analysis_noisy)_analysis_output_always(base,i,v,n,bark,dB,off);
  97474. }
  97475. #endif
  97476. /*** End of inlined file: analysis.c ***/
  97477. /*** Start of inlined file: bitrate.c ***/
  97478. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  97479. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  97480. // tasks..
  97481. #if JUCE_MSVC
  97482. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  97483. #endif
  97484. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  97485. #if JUCE_USE_OGGVORBIS
  97486. #include <stdlib.h>
  97487. #include <string.h>
  97488. #include <math.h>
  97489. void vorbis_bitrate_init(vorbis_info *vi,bitrate_manager_state *bm){
  97490. codec_setup_info *ci=(codec_setup_info *)vi->codec_setup;
  97491. bitrate_manager_info *bi=&ci->bi;
  97492. memset(bm,0,sizeof(*bm));
  97493. if(bi && (bi->reservoir_bits>0)){
  97494. long ratesamples=vi->rate;
  97495. int halfsamples=ci->blocksizes[0]>>1;
  97496. bm->short_per_long=ci->blocksizes[1]/ci->blocksizes[0];
  97497. bm->managed=1;
  97498. bm->avg_bitsper= rint(1.*bi->avg_rate*halfsamples/ratesamples);
  97499. bm->min_bitsper= rint(1.*bi->min_rate*halfsamples/ratesamples);
  97500. bm->max_bitsper= rint(1.*bi->max_rate*halfsamples/ratesamples);
  97501. bm->avgfloat=PACKETBLOBS/2;
  97502. {
  97503. long desired_fill=bi->reservoir_bits*bi->reservoir_bias;
  97504. bm->minmax_reservoir=desired_fill;
  97505. bm->avg_reservoir=desired_fill;
  97506. }
  97507. }
  97508. }
  97509. void vorbis_bitrate_clear(bitrate_manager_state *bm){
  97510. memset(bm,0,sizeof(*bm));
  97511. return;
  97512. }
  97513. int vorbis_bitrate_managed(vorbis_block *vb){
  97514. vorbis_dsp_state *vd=vb->vd;
  97515. private_state *b=(private_state*)vd->backend_state;
  97516. bitrate_manager_state *bm=&b->bms;
  97517. if(bm && bm->managed)return(1);
  97518. return(0);
  97519. }
  97520. int vorbis_bitrate_addblock(vorbis_block *vb){
  97521. vorbis_block_internal *vbi=(vorbis_block_internal*)vb->internal;
  97522. vorbis_dsp_state *vd=vb->vd;
  97523. private_state *b=(private_state*)vd->backend_state;
  97524. bitrate_manager_state *bm=&b->bms;
  97525. vorbis_info *vi=vd->vi;
  97526. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  97527. bitrate_manager_info *bi=&ci->bi;
  97528. int choice=rint(bm->avgfloat);
  97529. long this_bits=oggpack_bytes(vbi->packetblob[choice])*8;
  97530. long min_target_bits=(vb->W?bm->min_bitsper*bm->short_per_long:bm->min_bitsper);
  97531. long max_target_bits=(vb->W?bm->max_bitsper*bm->short_per_long:bm->max_bitsper);
  97532. int samples=ci->blocksizes[vb->W]>>1;
  97533. long desired_fill=bi->reservoir_bits*bi->reservoir_bias;
  97534. if(!bm->managed){
  97535. if(bm->vb)return(-1); /* one has been submitted without
  97536. being claimed */
  97537. bm->vb=vb;
  97538. return(0);
  97539. }
  97540. bm->vb=vb;
  97541. if(bm->avg_bitsper>0){
  97542. double slew=0.;
  97543. long avg_target_bits=(vb->W?bm->avg_bitsper*bm->short_per_long:bm->avg_bitsper);
  97544. double slewlimit= 15./bi->slew_damp;
  97545. if(bm->avg_reservoir+(this_bits-avg_target_bits)>desired_fill){
  97546. while(choice>0 && this_bits>avg_target_bits &&
  97547. bm->avg_reservoir+(this_bits-avg_target_bits)>desired_fill){
  97548. choice--;
  97549. this_bits=oggpack_bytes(vbi->packetblob[choice])*8;
  97550. }
  97551. }else if(bm->avg_reservoir+(this_bits-avg_target_bits)<desired_fill){
  97552. while(choice+1<PACKETBLOBS && this_bits<avg_target_bits &&
  97553. bm->avg_reservoir+(this_bits-avg_target_bits)<desired_fill){
  97554. choice++;
  97555. this_bits=oggpack_bytes(vbi->packetblob[choice])*8;
  97556. }
  97557. }
  97558. slew=rint(choice-bm->avgfloat)/samples*vi->rate;
  97559. if(slew<-slewlimit)slew=-slewlimit;
  97560. if(slew>slewlimit)slew=slewlimit;
  97561. choice=rint(bm->avgfloat+= slew/vi->rate*samples);
  97562. this_bits=oggpack_bytes(vbi->packetblob[choice])*8;
  97563. }
  97564. if(bm->min_bitsper>0){
  97565. if(this_bits<min_target_bits){
  97566. while(bm->minmax_reservoir-(min_target_bits-this_bits)<0){
  97567. choice++;
  97568. if(choice>=PACKETBLOBS)break;
  97569. this_bits=oggpack_bytes(vbi->packetblob[choice])*8;
  97570. }
  97571. }
  97572. }
  97573. if(bm->max_bitsper>0){
  97574. if(this_bits>max_target_bits){
  97575. while(bm->minmax_reservoir+(this_bits-max_target_bits)>bi->reservoir_bits){
  97576. choice--;
  97577. if(choice<0)break;
  97578. this_bits=oggpack_bytes(vbi->packetblob[choice])*8;
  97579. }
  97580. }
  97581. }
  97582. if(choice<0){
  97583. long maxsize=(max_target_bits+(bi->reservoir_bits-bm->minmax_reservoir))/8;
  97584. bm->choice=choice=0;
  97585. if(oggpack_bytes(vbi->packetblob[choice])>maxsize){
  97586. oggpack_writetrunc(vbi->packetblob[choice],maxsize*8);
  97587. this_bits=oggpack_bytes(vbi->packetblob[choice])*8;
  97588. }
  97589. }else{
  97590. long minsize=(min_target_bits-bm->minmax_reservoir+7)/8;
  97591. if(choice>=PACKETBLOBS)
  97592. choice=PACKETBLOBS-1;
  97593. bm->choice=choice;
  97594. minsize-=oggpack_bytes(vbi->packetblob[choice]);
  97595. while(minsize-->0)oggpack_write(vbi->packetblob[choice],0,8);
  97596. this_bits=oggpack_bytes(vbi->packetblob[choice])*8;
  97597. }
  97598. if(bm->min_bitsper>0 || bm->max_bitsper>0){
  97599. if(max_target_bits>0 && this_bits>max_target_bits){
  97600. bm->minmax_reservoir+=(this_bits-max_target_bits);
  97601. }else if(min_target_bits>0 && this_bits<min_target_bits){
  97602. bm->minmax_reservoir+=(this_bits-min_target_bits);
  97603. }else{
  97604. if(bm->minmax_reservoir>desired_fill){
  97605. if(max_target_bits>0){ /* logical bulletproofing against initialization state */
  97606. bm->minmax_reservoir+=(this_bits-max_target_bits);
  97607. if(bm->minmax_reservoir<desired_fill)bm->minmax_reservoir=desired_fill;
  97608. }else{
  97609. bm->minmax_reservoir=desired_fill;
  97610. }
  97611. }else{
  97612. if(min_target_bits>0){ /* logical bulletproofing against initialization state */
  97613. bm->minmax_reservoir+=(this_bits-min_target_bits);
  97614. if(bm->minmax_reservoir>desired_fill)bm->minmax_reservoir=desired_fill;
  97615. }else{
  97616. bm->minmax_reservoir=desired_fill;
  97617. }
  97618. }
  97619. }
  97620. }
  97621. if(bm->avg_bitsper>0){
  97622. long avg_target_bits=(vb->W?bm->avg_bitsper*bm->short_per_long:bm->avg_bitsper);
  97623. bm->avg_reservoir+=this_bits-avg_target_bits;
  97624. }
  97625. return(0);
  97626. }
  97627. int vorbis_bitrate_flushpacket(vorbis_dsp_state *vd,ogg_packet *op){
  97628. private_state *b=(private_state*)vd->backend_state;
  97629. bitrate_manager_state *bm=&b->bms;
  97630. vorbis_block *vb=bm->vb;
  97631. int choice=PACKETBLOBS/2;
  97632. if(!vb)return 0;
  97633. if(op){
  97634. vorbis_block_internal *vbi=(vorbis_block_internal*)vb->internal;
  97635. if(vorbis_bitrate_managed(vb))
  97636. choice=bm->choice;
  97637. op->packet=oggpack_get_buffer(vbi->packetblob[choice]);
  97638. op->bytes=oggpack_bytes(vbi->packetblob[choice]);
  97639. op->b_o_s=0;
  97640. op->e_o_s=vb->eofflag;
  97641. op->granulepos=vb->granulepos;
  97642. op->packetno=vb->sequence; /* for sake of completeness */
  97643. }
  97644. bm->vb=0;
  97645. return(1);
  97646. }
  97647. #endif
  97648. /*** End of inlined file: bitrate.c ***/
  97649. /*** Start of inlined file: block.c ***/
  97650. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  97651. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  97652. // tasks..
  97653. #if JUCE_MSVC
  97654. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  97655. #endif
  97656. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  97657. #if JUCE_USE_OGGVORBIS
  97658. #include <stdio.h>
  97659. #include <stdlib.h>
  97660. #include <string.h>
  97661. /*** Start of inlined file: window.h ***/
  97662. #ifndef _V_WINDOW_
  97663. #define _V_WINDOW_
  97664. extern float *_vorbis_window_get(int n);
  97665. extern void _vorbis_apply_window(float *d,int *winno,long *blocksizes,
  97666. int lW,int W,int nW);
  97667. #endif
  97668. /*** End of inlined file: window.h ***/
  97669. /*** Start of inlined file: lpc.h ***/
  97670. #ifndef _V_LPC_H_
  97671. #define _V_LPC_H_
  97672. extern float vorbis_lpc_from_data(float *data,float *lpc,int n,int m);
  97673. extern void vorbis_lpc_predict(float *coeff,float *prime,int m,
  97674. float *data,long n);
  97675. #endif
  97676. /*** End of inlined file: lpc.h ***/
  97677. #ifndef WORD_ALIGN
  97678. #define WORD_ALIGN 8
  97679. #endif
  97680. int vorbis_block_init(vorbis_dsp_state *v, vorbis_block *vb){
  97681. int i;
  97682. memset(vb,0,sizeof(*vb));
  97683. vb->vd=v;
  97684. vb->localalloc=0;
  97685. vb->localstore=NULL;
  97686. if(v->analysisp){
  97687. vorbis_block_internal *vbi=(vorbis_block_internal*)
  97688. (vb->internal=(vorbis_block_internal*)_ogg_calloc(1,sizeof(vorbis_block_internal)));
  97689. vbi->ampmax=-9999;
  97690. for(i=0;i<PACKETBLOBS;i++){
  97691. if(i==PACKETBLOBS/2){
  97692. vbi->packetblob[i]=&vb->opb;
  97693. }else{
  97694. vbi->packetblob[i]=
  97695. (oggpack_buffer*) _ogg_calloc(1,sizeof(oggpack_buffer));
  97696. }
  97697. oggpack_writeinit(vbi->packetblob[i]);
  97698. }
  97699. }
  97700. return(0);
  97701. }
  97702. void *_vorbis_block_alloc(vorbis_block *vb,long bytes){
  97703. bytes=(bytes+(WORD_ALIGN-1)) & ~(WORD_ALIGN-1);
  97704. if(bytes+vb->localtop>vb->localalloc){
  97705. if(vb->localstore){
  97706. struct alloc_chain *link=(struct alloc_chain*)_ogg_malloc(sizeof(*link));
  97707. vb->totaluse+=vb->localtop;
  97708. link->next=vb->reap;
  97709. link->ptr=vb->localstore;
  97710. vb->reap=link;
  97711. }
  97712. vb->localalloc=bytes;
  97713. vb->localstore=_ogg_malloc(vb->localalloc);
  97714. vb->localtop=0;
  97715. }
  97716. {
  97717. void *ret=(void *)(((char *)vb->localstore)+vb->localtop);
  97718. vb->localtop+=bytes;
  97719. return ret;
  97720. }
  97721. }
  97722. void _vorbis_block_ripcord(vorbis_block *vb){
  97723. struct alloc_chain *reap=vb->reap;
  97724. while(reap){
  97725. struct alloc_chain *next=reap->next;
  97726. _ogg_free(reap->ptr);
  97727. memset(reap,0,sizeof(*reap));
  97728. _ogg_free(reap);
  97729. reap=next;
  97730. }
  97731. if(vb->totaluse){
  97732. vb->localstore=_ogg_realloc(vb->localstore,vb->totaluse+vb->localalloc);
  97733. vb->localalloc+=vb->totaluse;
  97734. vb->totaluse=0;
  97735. }
  97736. vb->localtop=0;
  97737. vb->reap=NULL;
  97738. }
  97739. int vorbis_block_clear(vorbis_block *vb){
  97740. int i;
  97741. vorbis_block_internal *vbi=(vorbis_block_internal*)vb->internal;
  97742. _vorbis_block_ripcord(vb);
  97743. if(vb->localstore)_ogg_free(vb->localstore);
  97744. if(vbi){
  97745. for(i=0;i<PACKETBLOBS;i++){
  97746. oggpack_writeclear(vbi->packetblob[i]);
  97747. if(i!=PACKETBLOBS/2)_ogg_free(vbi->packetblob[i]);
  97748. }
  97749. _ogg_free(vbi);
  97750. }
  97751. memset(vb,0,sizeof(*vb));
  97752. return(0);
  97753. }
  97754. static int _vds_shared_init(vorbis_dsp_state *v,vorbis_info *vi,int encp){
  97755. int i;
  97756. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  97757. private_state *b=NULL;
  97758. int hs;
  97759. if(ci==NULL) return 1;
  97760. hs=ci->halfrate_flag;
  97761. memset(v,0,sizeof(*v));
  97762. b=(private_state*) (v->backend_state=(private_state*)_ogg_calloc(1,sizeof(*b)));
  97763. v->vi=vi;
  97764. b->modebits=ilog2(ci->modes);
  97765. b->transform[0]=(vorbis_look_transform**)_ogg_calloc(VI_TRANSFORMB,sizeof(*b->transform[0]));
  97766. b->transform[1]=(vorbis_look_transform**)_ogg_calloc(VI_TRANSFORMB,sizeof(*b->transform[1]));
  97767. b->transform[0][0]=_ogg_calloc(1,sizeof(mdct_lookup));
  97768. b->transform[1][0]=_ogg_calloc(1,sizeof(mdct_lookup));
  97769. mdct_init((mdct_lookup*)b->transform[0][0],ci->blocksizes[0]>>hs);
  97770. mdct_init((mdct_lookup*)b->transform[1][0],ci->blocksizes[1]>>hs);
  97771. b->window[0]=ilog2(ci->blocksizes[0])-6;
  97772. b->window[1]=ilog2(ci->blocksizes[1])-6;
  97773. if(encp){ /* encode/decode differ here */
  97774. drft_init(&b->fft_look[0],ci->blocksizes[0]);
  97775. drft_init(&b->fft_look[1],ci->blocksizes[1]);
  97776. if(!ci->fullbooks){
  97777. ci->fullbooks=(codebook*) _ogg_calloc(ci->books,sizeof(*ci->fullbooks));
  97778. for(i=0;i<ci->books;i++)
  97779. vorbis_book_init_encode(ci->fullbooks+i,ci->book_param[i]);
  97780. }
  97781. b->psy=(vorbis_look_psy*)_ogg_calloc(ci->psys,sizeof(*b->psy));
  97782. for(i=0;i<ci->psys;i++){
  97783. _vp_psy_init(b->psy+i,
  97784. ci->psy_param[i],
  97785. &ci->psy_g_param,
  97786. ci->blocksizes[ci->psy_param[i]->blockflag]/2,
  97787. vi->rate);
  97788. }
  97789. v->analysisp=1;
  97790. }else{
  97791. if(!ci->fullbooks){
  97792. ci->fullbooks=(codebook*) _ogg_calloc(ci->books,sizeof(*ci->fullbooks));
  97793. for(i=0;i<ci->books;i++){
  97794. vorbis_book_init_decode(ci->fullbooks+i,ci->book_param[i]);
  97795. vorbis_staticbook_destroy(ci->book_param[i]);
  97796. ci->book_param[i]=NULL;
  97797. }
  97798. }
  97799. }
  97800. v->pcm_storage=ci->blocksizes[1];
  97801. v->pcm=(float**)_ogg_malloc(vi->channels*sizeof(*v->pcm));
  97802. v->pcmret=(float**)_ogg_malloc(vi->channels*sizeof(*v->pcmret));
  97803. {
  97804. int i;
  97805. for(i=0;i<vi->channels;i++)
  97806. v->pcm[i]=(float*)_ogg_calloc(v->pcm_storage,sizeof(*v->pcm[i]));
  97807. }
  97808. v->lW=0; /* previous window size */
  97809. v->W=0; /* current window size */
  97810. v->centerW=ci->blocksizes[1]/2;
  97811. v->pcm_current=v->centerW;
  97812. b->flr=(vorbis_look_floor**)_ogg_calloc(ci->floors,sizeof(*b->flr));
  97813. b->residue=(vorbis_look_residue**)_ogg_calloc(ci->residues,sizeof(*b->residue));
  97814. for(i=0;i<ci->floors;i++)
  97815. b->flr[i]=_floor_P[ci->floor_type[i]]->
  97816. look(v,ci->floor_param[i]);
  97817. for(i=0;i<ci->residues;i++)
  97818. b->residue[i]=_residue_P[ci->residue_type[i]]->
  97819. look(v,ci->residue_param[i]);
  97820. return 0;
  97821. }
  97822. int vorbis_analysis_init(vorbis_dsp_state *v,vorbis_info *vi){
  97823. private_state *b=NULL;
  97824. if(_vds_shared_init(v,vi,1))return 1;
  97825. b=(private_state*)v->backend_state;
  97826. b->psy_g_look=_vp_global_look(vi);
  97827. b->ve=(envelope_lookup*)_ogg_calloc(1,sizeof(*b->ve));
  97828. _ve_envelope_init(b->ve,vi);
  97829. vorbis_bitrate_init(vi,&b->bms);
  97830. v->sequence=3;
  97831. return(0);
  97832. }
  97833. void vorbis_dsp_clear(vorbis_dsp_state *v){
  97834. int i;
  97835. if(v){
  97836. vorbis_info *vi=v->vi;
  97837. codec_setup_info *ci=(codec_setup_info*)(vi?vi->codec_setup:NULL);
  97838. private_state *b=(private_state*)v->backend_state;
  97839. if(b){
  97840. if(b->ve){
  97841. _ve_envelope_clear(b->ve);
  97842. _ogg_free(b->ve);
  97843. }
  97844. if(b->transform[0]){
  97845. mdct_clear((mdct_lookup*) b->transform[0][0]);
  97846. _ogg_free(b->transform[0][0]);
  97847. _ogg_free(b->transform[0]);
  97848. }
  97849. if(b->transform[1]){
  97850. mdct_clear((mdct_lookup*) b->transform[1][0]);
  97851. _ogg_free(b->transform[1][0]);
  97852. _ogg_free(b->transform[1]);
  97853. }
  97854. if(b->flr){
  97855. for(i=0;i<ci->floors;i++)
  97856. _floor_P[ci->floor_type[i]]->
  97857. free_look(b->flr[i]);
  97858. _ogg_free(b->flr);
  97859. }
  97860. if(b->residue){
  97861. for(i=0;i<ci->residues;i++)
  97862. _residue_P[ci->residue_type[i]]->
  97863. free_look(b->residue[i]);
  97864. _ogg_free(b->residue);
  97865. }
  97866. if(b->psy){
  97867. for(i=0;i<ci->psys;i++)
  97868. _vp_psy_clear(b->psy+i);
  97869. _ogg_free(b->psy);
  97870. }
  97871. if(b->psy_g_look)_vp_global_free(b->psy_g_look);
  97872. vorbis_bitrate_clear(&b->bms);
  97873. drft_clear(&b->fft_look[0]);
  97874. drft_clear(&b->fft_look[1]);
  97875. }
  97876. if(v->pcm){
  97877. for(i=0;i<vi->channels;i++)
  97878. if(v->pcm[i])_ogg_free(v->pcm[i]);
  97879. _ogg_free(v->pcm);
  97880. if(v->pcmret)_ogg_free(v->pcmret);
  97881. }
  97882. if(b){
  97883. if(b->header)_ogg_free(b->header);
  97884. if(b->header1)_ogg_free(b->header1);
  97885. if(b->header2)_ogg_free(b->header2);
  97886. _ogg_free(b);
  97887. }
  97888. memset(v,0,sizeof(*v));
  97889. }
  97890. }
  97891. float **vorbis_analysis_buffer(vorbis_dsp_state *v, int vals){
  97892. int i;
  97893. vorbis_info *vi=v->vi;
  97894. private_state *b=(private_state*)v->backend_state;
  97895. if(b->header)_ogg_free(b->header);b->header=NULL;
  97896. if(b->header1)_ogg_free(b->header1);b->header1=NULL;
  97897. if(b->header2)_ogg_free(b->header2);b->header2=NULL;
  97898. if(v->pcm_current+vals>=v->pcm_storage){
  97899. v->pcm_storage=v->pcm_current+vals*2;
  97900. for(i=0;i<vi->channels;i++){
  97901. v->pcm[i]=(float*)_ogg_realloc(v->pcm[i],v->pcm_storage*sizeof(*v->pcm[i]));
  97902. }
  97903. }
  97904. for(i=0;i<vi->channels;i++)
  97905. v->pcmret[i]=v->pcm[i]+v->pcm_current;
  97906. return(v->pcmret);
  97907. }
  97908. static void _preextrapolate_helper(vorbis_dsp_state *v){
  97909. int i;
  97910. int order=32;
  97911. float *lpc=(float*)alloca(order*sizeof(*lpc));
  97912. float *work=(float*)alloca(v->pcm_current*sizeof(*work));
  97913. long j;
  97914. v->preextrapolate=1;
  97915. if(v->pcm_current-v->centerW>order*2){ /* safety */
  97916. for(i=0;i<v->vi->channels;i++){
  97917. for(j=0;j<v->pcm_current;j++)
  97918. work[j]=v->pcm[i][v->pcm_current-j-1];
  97919. vorbis_lpc_from_data(work,lpc,v->pcm_current-v->centerW,order);
  97920. vorbis_lpc_predict(lpc,work+v->pcm_current-v->centerW-order,
  97921. order,
  97922. work+v->pcm_current-v->centerW,
  97923. v->centerW);
  97924. for(j=0;j<v->pcm_current;j++)
  97925. v->pcm[i][v->pcm_current-j-1]=work[j];
  97926. }
  97927. }
  97928. }
  97929. int vorbis_analysis_wrote(vorbis_dsp_state *v, int vals){
  97930. vorbis_info *vi=v->vi;
  97931. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  97932. if(vals<=0){
  97933. int order=32;
  97934. int i;
  97935. float *lpc=(float*) alloca(order*sizeof(*lpc));
  97936. if(!v->preextrapolate)
  97937. _preextrapolate_helper(v);
  97938. vorbis_analysis_buffer(v,ci->blocksizes[1]*3);
  97939. v->eofflag=v->pcm_current;
  97940. v->pcm_current+=ci->blocksizes[1]*3;
  97941. for(i=0;i<vi->channels;i++){
  97942. if(v->eofflag>order*2){
  97943. long n;
  97944. n=v->eofflag;
  97945. if(n>ci->blocksizes[1])n=ci->blocksizes[1];
  97946. vorbis_lpc_from_data(v->pcm[i]+v->eofflag-n,lpc,n,order);
  97947. vorbis_lpc_predict(lpc,v->pcm[i]+v->eofflag-order,order,
  97948. v->pcm[i]+v->eofflag,v->pcm_current-v->eofflag);
  97949. }else{
  97950. memset(v->pcm[i]+v->eofflag,0,
  97951. (v->pcm_current-v->eofflag)*sizeof(*v->pcm[i]));
  97952. }
  97953. }
  97954. }else{
  97955. if(v->pcm_current+vals>v->pcm_storage)
  97956. return(OV_EINVAL);
  97957. v->pcm_current+=vals;
  97958. if(!v->preextrapolate && v->pcm_current-v->centerW>ci->blocksizes[1])
  97959. _preextrapolate_helper(v);
  97960. }
  97961. return(0);
  97962. }
  97963. int vorbis_analysis_blockout(vorbis_dsp_state *v,vorbis_block *vb){
  97964. int i;
  97965. vorbis_info *vi=v->vi;
  97966. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  97967. private_state *b=(private_state*)v->backend_state;
  97968. vorbis_look_psy_global *g=b->psy_g_look;
  97969. long beginW=v->centerW-ci->blocksizes[v->W]/2,centerNext;
  97970. vorbis_block_internal *vbi=(vorbis_block_internal *)vb->internal;
  97971. if(!v->preextrapolate)return(0);
  97972. if(v->eofflag==-1)return(0);
  97973. {
  97974. long bp=_ve_envelope_search(v);
  97975. if(bp==-1){
  97976. if(v->eofflag==0)return(0); /* not enough data currently to search for a
  97977. full long block */
  97978. v->nW=0;
  97979. }else{
  97980. if(ci->blocksizes[0]==ci->blocksizes[1])
  97981. v->nW=0;
  97982. else
  97983. v->nW=bp;
  97984. }
  97985. }
  97986. centerNext=v->centerW+ci->blocksizes[v->W]/4+ci->blocksizes[v->nW]/4;
  97987. {
  97988. long blockbound=centerNext+ci->blocksizes[v->nW]/2;
  97989. if(v->pcm_current<blockbound)return(0); /* not enough data yet;
  97990. although this check is
  97991. less strict that the
  97992. _ve_envelope_search,
  97993. the search is not run
  97994. if we only use one
  97995. block size */
  97996. }
  97997. _vorbis_block_ripcord(vb);
  97998. vb->lW=v->lW;
  97999. vb->W=v->W;
  98000. vb->nW=v->nW;
  98001. if(v->W){
  98002. if(!v->lW || !v->nW){
  98003. vbi->blocktype=BLOCKTYPE_TRANSITION;
  98004. }else{
  98005. vbi->blocktype=BLOCKTYPE_LONG;
  98006. }
  98007. }else{
  98008. if(_ve_envelope_mark(v)){
  98009. vbi->blocktype=BLOCKTYPE_IMPULSE;
  98010. }else{
  98011. vbi->blocktype=BLOCKTYPE_PADDING;
  98012. }
  98013. }
  98014. vb->vd=v;
  98015. vb->sequence=v->sequence++;
  98016. vb->granulepos=v->granulepos;
  98017. vb->pcmend=ci->blocksizes[v->W];
  98018. if(vbi->ampmax>g->ampmax)g->ampmax=vbi->ampmax;
  98019. g->ampmax=_vp_ampmax_decay(g->ampmax,v);
  98020. vbi->ampmax=g->ampmax;
  98021. vb->pcm=(float**)_vorbis_block_alloc(vb,sizeof(*vb->pcm)*vi->channels);
  98022. vbi->pcmdelay=(float**)_vorbis_block_alloc(vb,sizeof(*vbi->pcmdelay)*vi->channels);
  98023. for(i=0;i<vi->channels;i++){
  98024. vbi->pcmdelay[i]=
  98025. (float*) _vorbis_block_alloc(vb,(vb->pcmend+beginW)*sizeof(*vbi->pcmdelay[i]));
  98026. memcpy(vbi->pcmdelay[i],v->pcm[i],(vb->pcmend+beginW)*sizeof(*vbi->pcmdelay[i]));
  98027. vb->pcm[i]=vbi->pcmdelay[i]+beginW;
  98028. }
  98029. if(v->eofflag){
  98030. if(v->centerW>=v->eofflag){
  98031. v->eofflag=-1;
  98032. vb->eofflag=1;
  98033. return(1);
  98034. }
  98035. }
  98036. {
  98037. int new_centerNext=ci->blocksizes[1]/2;
  98038. int movementW=centerNext-new_centerNext;
  98039. if(movementW>0){
  98040. _ve_envelope_shift(b->ve,movementW);
  98041. v->pcm_current-=movementW;
  98042. for(i=0;i<vi->channels;i++)
  98043. memmove(v->pcm[i],v->pcm[i]+movementW,
  98044. v->pcm_current*sizeof(*v->pcm[i]));
  98045. v->lW=v->W;
  98046. v->W=v->nW;
  98047. v->centerW=new_centerNext;
  98048. if(v->eofflag){
  98049. v->eofflag-=movementW;
  98050. if(v->eofflag<=0)v->eofflag=-1;
  98051. if(v->centerW>=v->eofflag){
  98052. v->granulepos+=movementW-(v->centerW-v->eofflag);
  98053. }else{
  98054. v->granulepos+=movementW;
  98055. }
  98056. }else{
  98057. v->granulepos+=movementW;
  98058. }
  98059. }
  98060. }
  98061. return(1);
  98062. }
  98063. int vorbis_synthesis_restart(vorbis_dsp_state *v){
  98064. vorbis_info *vi=v->vi;
  98065. codec_setup_info *ci;
  98066. int hs;
  98067. if(!v->backend_state)return -1;
  98068. if(!vi)return -1;
  98069. ci=(codec_setup_info*) vi->codec_setup;
  98070. if(!ci)return -1;
  98071. hs=ci->halfrate_flag;
  98072. v->centerW=ci->blocksizes[1]>>(hs+1);
  98073. v->pcm_current=v->centerW>>hs;
  98074. v->pcm_returned=-1;
  98075. v->granulepos=-1;
  98076. v->sequence=-1;
  98077. v->eofflag=0;
  98078. ((private_state *)(v->backend_state))->sample_count=-1;
  98079. return(0);
  98080. }
  98081. int vorbis_synthesis_init(vorbis_dsp_state *v,vorbis_info *vi){
  98082. if(_vds_shared_init(v,vi,0)) return 1;
  98083. vorbis_synthesis_restart(v);
  98084. return 0;
  98085. }
  98086. int vorbis_synthesis_blockin(vorbis_dsp_state *v,vorbis_block *vb){
  98087. vorbis_info *vi=v->vi;
  98088. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  98089. private_state *b=(private_state*)v->backend_state;
  98090. int hs=ci->halfrate_flag;
  98091. int i,j;
  98092. if(!vb)return(OV_EINVAL);
  98093. if(v->pcm_current>v->pcm_returned && v->pcm_returned!=-1)return(OV_EINVAL);
  98094. v->lW=v->W;
  98095. v->W=vb->W;
  98096. v->nW=-1;
  98097. if((v->sequence==-1)||
  98098. (v->sequence+1 != vb->sequence)){
  98099. v->granulepos=-1; /* out of sequence; lose count */
  98100. b->sample_count=-1;
  98101. }
  98102. v->sequence=vb->sequence;
  98103. if(vb->pcm){ /* no pcm to process if vorbis_synthesis_trackonly
  98104. was called on block */
  98105. int n=ci->blocksizes[v->W]>>(hs+1);
  98106. int n0=ci->blocksizes[0]>>(hs+1);
  98107. int n1=ci->blocksizes[1]>>(hs+1);
  98108. int thisCenter;
  98109. int prevCenter;
  98110. v->glue_bits+=vb->glue_bits;
  98111. v->time_bits+=vb->time_bits;
  98112. v->floor_bits+=vb->floor_bits;
  98113. v->res_bits+=vb->res_bits;
  98114. if(v->centerW){
  98115. thisCenter=n1;
  98116. prevCenter=0;
  98117. }else{
  98118. thisCenter=0;
  98119. prevCenter=n1;
  98120. }
  98121. for(j=0;j<vi->channels;j++){
  98122. if(v->lW){
  98123. if(v->W){
  98124. float *w=_vorbis_window_get(b->window[1]-hs);
  98125. float *pcm=v->pcm[j]+prevCenter;
  98126. float *p=vb->pcm[j];
  98127. for(i=0;i<n1;i++)
  98128. pcm[i]=pcm[i]*w[n1-i-1] + p[i]*w[i];
  98129. }else{
  98130. float *w=_vorbis_window_get(b->window[0]-hs);
  98131. float *pcm=v->pcm[j]+prevCenter+n1/2-n0/2;
  98132. float *p=vb->pcm[j];
  98133. for(i=0;i<n0;i++)
  98134. pcm[i]=pcm[i]*w[n0-i-1] +p[i]*w[i];
  98135. }
  98136. }else{
  98137. if(v->W){
  98138. float *w=_vorbis_window_get(b->window[0]-hs);
  98139. float *pcm=v->pcm[j]+prevCenter;
  98140. float *p=vb->pcm[j]+n1/2-n0/2;
  98141. for(i=0;i<n0;i++)
  98142. pcm[i]=pcm[i]*w[n0-i-1] +p[i]*w[i];
  98143. for(;i<n1/2+n0/2;i++)
  98144. pcm[i]=p[i];
  98145. }else{
  98146. float *w=_vorbis_window_get(b->window[0]-hs);
  98147. float *pcm=v->pcm[j]+prevCenter;
  98148. float *p=vb->pcm[j];
  98149. for(i=0;i<n0;i++)
  98150. pcm[i]=pcm[i]*w[n0-i-1] +p[i]*w[i];
  98151. }
  98152. }
  98153. {
  98154. float *pcm=v->pcm[j]+thisCenter;
  98155. float *p=vb->pcm[j]+n;
  98156. for(i=0;i<n;i++)
  98157. pcm[i]=p[i];
  98158. }
  98159. }
  98160. if(v->centerW)
  98161. v->centerW=0;
  98162. else
  98163. v->centerW=n1;
  98164. if(v->pcm_returned==-1){
  98165. v->pcm_returned=thisCenter;
  98166. v->pcm_current=thisCenter;
  98167. }else{
  98168. v->pcm_returned=prevCenter;
  98169. v->pcm_current=prevCenter+
  98170. ((ci->blocksizes[v->lW]/4+
  98171. ci->blocksizes[v->W]/4)>>hs);
  98172. }
  98173. }
  98174. if(b->sample_count==-1){
  98175. b->sample_count=0;
  98176. }else{
  98177. b->sample_count+=ci->blocksizes[v->lW]/4+ci->blocksizes[v->W]/4;
  98178. }
  98179. if(v->granulepos==-1){
  98180. if(vb->granulepos!=-1){ /* only set if we have a position to set to */
  98181. v->granulepos=vb->granulepos;
  98182. if(b->sample_count>v->granulepos){
  98183. if(vb->eofflag){
  98184. v->pcm_current-=(b->sample_count-v->granulepos)>>hs;
  98185. }else{
  98186. v->pcm_returned+=(b->sample_count-v->granulepos)>>hs;
  98187. if(v->pcm_returned>v->pcm_current)
  98188. v->pcm_returned=v->pcm_current;
  98189. }
  98190. }
  98191. }
  98192. }else{
  98193. v->granulepos+=ci->blocksizes[v->lW]/4+ci->blocksizes[v->W]/4;
  98194. if(vb->granulepos!=-1 && v->granulepos!=vb->granulepos){
  98195. if(v->granulepos>vb->granulepos){
  98196. long extra=v->granulepos-vb->granulepos;
  98197. if(extra)
  98198. if(vb->eofflag){
  98199. v->pcm_current-=extra>>hs;
  98200. } /* else {Shouldn't happen *unless* the bitstream is out of
  98201. spec. Either way, believe the bitstream } */
  98202. } /* else {Shouldn't happen *unless* the bitstream is out of
  98203. spec. Either way, believe the bitstream } */
  98204. v->granulepos=vb->granulepos;
  98205. }
  98206. }
  98207. if(vb->eofflag)v->eofflag=1;
  98208. return(0);
  98209. }
  98210. int vorbis_synthesis_pcmout(vorbis_dsp_state *v,float ***pcm){
  98211. vorbis_info *vi=v->vi;
  98212. if(v->pcm_returned>-1 && v->pcm_returned<v->pcm_current){
  98213. if(pcm){
  98214. int i;
  98215. for(i=0;i<vi->channels;i++)
  98216. v->pcmret[i]=v->pcm[i]+v->pcm_returned;
  98217. *pcm=v->pcmret;
  98218. }
  98219. return(v->pcm_current-v->pcm_returned);
  98220. }
  98221. return(0);
  98222. }
  98223. int vorbis_synthesis_read(vorbis_dsp_state *v,int n){
  98224. if(n && v->pcm_returned+n>v->pcm_current)return(OV_EINVAL);
  98225. v->pcm_returned+=n;
  98226. return(0);
  98227. }
  98228. int vorbis_synthesis_lapout(vorbis_dsp_state *v,float ***pcm){
  98229. vorbis_info *vi=v->vi;
  98230. codec_setup_info *ci=(codec_setup_info *)vi->codec_setup;
  98231. int hs=ci->halfrate_flag;
  98232. int n=ci->blocksizes[v->W]>>(hs+1);
  98233. int n0=ci->blocksizes[0]>>(hs+1);
  98234. int n1=ci->blocksizes[1]>>(hs+1);
  98235. int i,j;
  98236. if(v->pcm_returned<0)return 0;
  98237. if(v->centerW==n1){
  98238. for(j=0;j<vi->channels;j++){
  98239. float *p=v->pcm[j];
  98240. for(i=0;i<n1;i++){
  98241. float temp=p[i];
  98242. p[i]=p[i+n1];
  98243. p[i+n1]=temp;
  98244. }
  98245. }
  98246. v->pcm_current-=n1;
  98247. v->pcm_returned-=n1;
  98248. v->centerW=0;
  98249. }
  98250. if((v->lW^v->W)==1){
  98251. for(j=0;j<vi->channels;j++){
  98252. float *s=v->pcm[j];
  98253. float *d=v->pcm[j]+(n1-n0)/2;
  98254. for(i=(n1+n0)/2-1;i>=0;--i)
  98255. d[i]=s[i];
  98256. }
  98257. v->pcm_returned+=(n1-n0)/2;
  98258. v->pcm_current+=(n1-n0)/2;
  98259. }else{
  98260. if(v->lW==0){
  98261. for(j=0;j<vi->channels;j++){
  98262. float *s=v->pcm[j];
  98263. float *d=v->pcm[j]+n1-n0;
  98264. for(i=n0-1;i>=0;--i)
  98265. d[i]=s[i];
  98266. }
  98267. v->pcm_returned+=n1-n0;
  98268. v->pcm_current+=n1-n0;
  98269. }
  98270. }
  98271. if(pcm){
  98272. int i;
  98273. for(i=0;i<vi->channels;i++)
  98274. v->pcmret[i]=v->pcm[i]+v->pcm_returned;
  98275. *pcm=v->pcmret;
  98276. }
  98277. return(n1+n-v->pcm_returned);
  98278. }
  98279. float *vorbis_window(vorbis_dsp_state *v,int W){
  98280. vorbis_info *vi=v->vi;
  98281. codec_setup_info *ci=(codec_setup_info*) vi->codec_setup;
  98282. int hs=ci->halfrate_flag;
  98283. private_state *b=(private_state*)v->backend_state;
  98284. if(b->window[W]-1<0)return NULL;
  98285. return _vorbis_window_get(b->window[W]-hs);
  98286. }
  98287. #endif
  98288. /*** End of inlined file: block.c ***/
  98289. /*** Start of inlined file: codebook.c ***/
  98290. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  98291. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  98292. // tasks..
  98293. #if JUCE_MSVC
  98294. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  98295. #endif
  98296. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  98297. #if JUCE_USE_OGGVORBIS
  98298. #include <stdlib.h>
  98299. #include <string.h>
  98300. #include <math.h>
  98301. int vorbis_staticbook_pack(const static_codebook *c,oggpack_buffer *opb){
  98302. long i,j;
  98303. int ordered=0;
  98304. oggpack_write(opb,0x564342,24);
  98305. oggpack_write(opb,c->dim,16);
  98306. oggpack_write(opb,c->entries,24);
  98307. for(i=1;i<c->entries;i++)
  98308. if(c->lengthlist[i-1]==0 || c->lengthlist[i]<c->lengthlist[i-1])break;
  98309. if(i==c->entries)ordered=1;
  98310. if(ordered){
  98311. long count=0;
  98312. oggpack_write(opb,1,1); /* ordered */
  98313. oggpack_write(opb,c->lengthlist[0]-1,5); /* 1 to 32 */
  98314. for(i=1;i<c->entries;i++){
  98315. long thisx=c->lengthlist[i];
  98316. long last=c->lengthlist[i-1];
  98317. if(thisx>last){
  98318. for(j=last;j<thisx;j++){
  98319. oggpack_write(opb,i-count,_ilog(c->entries-count));
  98320. count=i;
  98321. }
  98322. }
  98323. }
  98324. oggpack_write(opb,i-count,_ilog(c->entries-count));
  98325. }else{
  98326. oggpack_write(opb,0,1); /* unordered */
  98327. for(i=0;i<c->entries;i++)
  98328. if(c->lengthlist[i]==0)break;
  98329. if(i==c->entries){
  98330. oggpack_write(opb,0,1); /* no unused entries */
  98331. for(i=0;i<c->entries;i++)
  98332. oggpack_write(opb,c->lengthlist[i]-1,5);
  98333. }else{
  98334. oggpack_write(opb,1,1); /* we have unused entries; thus we tag */
  98335. for(i=0;i<c->entries;i++){
  98336. if(c->lengthlist[i]==0){
  98337. oggpack_write(opb,0,1);
  98338. }else{
  98339. oggpack_write(opb,1,1);
  98340. oggpack_write(opb,c->lengthlist[i]-1,5);
  98341. }
  98342. }
  98343. }
  98344. }
  98345. oggpack_write(opb,c->maptype,4);
  98346. switch(c->maptype){
  98347. case 0:
  98348. break;
  98349. case 1:case 2:
  98350. if(!c->quantlist){
  98351. return(-1);
  98352. }
  98353. oggpack_write(opb,c->q_min,32);
  98354. oggpack_write(opb,c->q_delta,32);
  98355. oggpack_write(opb,c->q_quant-1,4);
  98356. oggpack_write(opb,c->q_sequencep,1);
  98357. {
  98358. int quantvals;
  98359. switch(c->maptype){
  98360. case 1:
  98361. quantvals=_book_maptype1_quantvals(c);
  98362. break;
  98363. case 2:
  98364. quantvals=c->entries*c->dim;
  98365. break;
  98366. default: /* NOT_REACHABLE */
  98367. quantvals=-1;
  98368. }
  98369. for(i=0;i<quantvals;i++)
  98370. oggpack_write(opb,labs(c->quantlist[i]),c->q_quant);
  98371. }
  98372. break;
  98373. default:
  98374. return(-1);
  98375. }
  98376. return(0);
  98377. }
  98378. int vorbis_staticbook_unpack(oggpack_buffer *opb,static_codebook *s){
  98379. long i,j;
  98380. memset(s,0,sizeof(*s));
  98381. s->allocedp=1;
  98382. if(oggpack_read(opb,24)!=0x564342)goto _eofout;
  98383. s->dim=oggpack_read(opb,16);
  98384. s->entries=oggpack_read(opb,24);
  98385. if(s->entries==-1)goto _eofout;
  98386. switch((int)oggpack_read(opb,1)){
  98387. case 0:
  98388. s->lengthlist=(long*)_ogg_malloc(sizeof(*s->lengthlist)*s->entries);
  98389. if(oggpack_read(opb,1)){
  98390. for(i=0;i<s->entries;i++){
  98391. if(oggpack_read(opb,1)){
  98392. long num=oggpack_read(opb,5);
  98393. if(num==-1)goto _eofout;
  98394. s->lengthlist[i]=num+1;
  98395. }else
  98396. s->lengthlist[i]=0;
  98397. }
  98398. }else{
  98399. for(i=0;i<s->entries;i++){
  98400. long num=oggpack_read(opb,5);
  98401. if(num==-1)goto _eofout;
  98402. s->lengthlist[i]=num+1;
  98403. }
  98404. }
  98405. break;
  98406. case 1:
  98407. {
  98408. long length=oggpack_read(opb,5)+1;
  98409. s->lengthlist=(long*)_ogg_malloc(sizeof(*s->lengthlist)*s->entries);
  98410. for(i=0;i<s->entries;){
  98411. long num=oggpack_read(opb,_ilog(s->entries-i));
  98412. if(num==-1)goto _eofout;
  98413. for(j=0;j<num && i<s->entries;j++,i++)
  98414. s->lengthlist[i]=length;
  98415. length++;
  98416. }
  98417. }
  98418. break;
  98419. default:
  98420. return(-1);
  98421. }
  98422. switch((s->maptype=oggpack_read(opb,4))){
  98423. case 0:
  98424. break;
  98425. case 1: case 2:
  98426. s->q_min=oggpack_read(opb,32);
  98427. s->q_delta=oggpack_read(opb,32);
  98428. s->q_quant=oggpack_read(opb,4)+1;
  98429. s->q_sequencep=oggpack_read(opb,1);
  98430. {
  98431. int quantvals=0;
  98432. switch(s->maptype){
  98433. case 1:
  98434. quantvals=_book_maptype1_quantvals(s);
  98435. break;
  98436. case 2:
  98437. quantvals=s->entries*s->dim;
  98438. break;
  98439. }
  98440. s->quantlist=(long*)_ogg_malloc(sizeof(*s->quantlist)*quantvals);
  98441. for(i=0;i<quantvals;i++)
  98442. s->quantlist[i]=oggpack_read(opb,s->q_quant);
  98443. if(quantvals&&s->quantlist[quantvals-1]==-1)goto _eofout;
  98444. }
  98445. break;
  98446. default:
  98447. goto _errout;
  98448. }
  98449. return(0);
  98450. _errout:
  98451. _eofout:
  98452. vorbis_staticbook_clear(s);
  98453. return(-1);
  98454. }
  98455. int vorbis_book_encode(codebook *book, int a, oggpack_buffer *b){
  98456. oggpack_write(b,book->codelist[a],book->c->lengthlist[a]);
  98457. return(book->c->lengthlist[a]);
  98458. }
  98459. int vorbis_book_errorv(codebook *book,float *a){
  98460. int dim=book->dim,k;
  98461. int best=_best(book,a,1);
  98462. for(k=0;k<dim;k++)
  98463. a[k]=(book->valuelist+best*dim)[k];
  98464. return(best);
  98465. }
  98466. int vorbis_book_encodev(codebook *book,int best,float *a,oggpack_buffer *b){
  98467. int k,dim=book->dim;
  98468. for(k=0;k<dim;k++)
  98469. a[k]=(book->valuelist+best*dim)[k];
  98470. return(vorbis_book_encode(book,best,b));
  98471. }
  98472. STIN long decode_packed_entry_number(codebook *book, oggpack_buffer *b){
  98473. int read=book->dec_maxlength;
  98474. long lo,hi;
  98475. long lok = oggpack_look(b,book->dec_firsttablen);
  98476. if (lok >= 0) {
  98477. long entry = book->dec_firsttable[lok];
  98478. if(entry&0x80000000UL){
  98479. lo=(entry>>15)&0x7fff;
  98480. hi=book->used_entries-(entry&0x7fff);
  98481. }else{
  98482. oggpack_adv(b, book->dec_codelengths[entry-1]);
  98483. return(entry-1);
  98484. }
  98485. }else{
  98486. lo=0;
  98487. hi=book->used_entries;
  98488. }
  98489. lok = oggpack_look(b, read);
  98490. while(lok<0 && read>1)
  98491. lok = oggpack_look(b, --read);
  98492. if(lok<0)return -1;
  98493. {
  98494. ogg_uint32_t testword=ogg_bitreverse((ogg_uint32_t)lok);
  98495. while(hi-lo>1){
  98496. long p=(hi-lo)>>1;
  98497. long test=book->codelist[lo+p]>testword;
  98498. lo+=p&(test-1);
  98499. hi-=p&(-test);
  98500. }
  98501. if(book->dec_codelengths[lo]<=read){
  98502. oggpack_adv(b, book->dec_codelengths[lo]);
  98503. return(lo);
  98504. }
  98505. }
  98506. oggpack_adv(b, read);
  98507. return(-1);
  98508. }
  98509. long vorbis_book_decode(codebook *book, oggpack_buffer *b){
  98510. long packed_entry=decode_packed_entry_number(book,b);
  98511. if(packed_entry>=0)
  98512. return(book->dec_index[packed_entry]);
  98513. return(packed_entry);
  98514. }
  98515. long vorbis_book_decodevs_add(codebook *book,float *a,oggpack_buffer *b,int n){
  98516. int step=n/book->dim;
  98517. long *entry = (long*)alloca(sizeof(*entry)*step);
  98518. float **t = (float**)alloca(sizeof(*t)*step);
  98519. int i,j,o;
  98520. for (i = 0; i < step; i++) {
  98521. entry[i]=decode_packed_entry_number(book,b);
  98522. if(entry[i]==-1)return(-1);
  98523. t[i] = book->valuelist+entry[i]*book->dim;
  98524. }
  98525. for(i=0,o=0;i<book->dim;i++,o+=step)
  98526. for (j=0;j<step;j++)
  98527. a[o+j]+=t[j][i];
  98528. return(0);
  98529. }
  98530. long vorbis_book_decodev_add(codebook *book,float *a,oggpack_buffer *b,int n){
  98531. int i,j,entry;
  98532. float *t;
  98533. if(book->dim>8){
  98534. for(i=0;i<n;){
  98535. entry = decode_packed_entry_number(book,b);
  98536. if(entry==-1)return(-1);
  98537. t = book->valuelist+entry*book->dim;
  98538. for (j=0;j<book->dim;)
  98539. a[i++]+=t[j++];
  98540. }
  98541. }else{
  98542. for(i=0;i<n;){
  98543. entry = decode_packed_entry_number(book,b);
  98544. if(entry==-1)return(-1);
  98545. t = book->valuelist+entry*book->dim;
  98546. j=0;
  98547. switch((int)book->dim){
  98548. case 8:
  98549. a[i++]+=t[j++];
  98550. case 7:
  98551. a[i++]+=t[j++];
  98552. case 6:
  98553. a[i++]+=t[j++];
  98554. case 5:
  98555. a[i++]+=t[j++];
  98556. case 4:
  98557. a[i++]+=t[j++];
  98558. case 3:
  98559. a[i++]+=t[j++];
  98560. case 2:
  98561. a[i++]+=t[j++];
  98562. case 1:
  98563. a[i++]+=t[j++];
  98564. case 0:
  98565. break;
  98566. }
  98567. }
  98568. }
  98569. return(0);
  98570. }
  98571. long vorbis_book_decodev_set(codebook *book,float *a,oggpack_buffer *b,int n){
  98572. int i,j,entry;
  98573. float *t;
  98574. for(i=0;i<n;){
  98575. entry = decode_packed_entry_number(book,b);
  98576. if(entry==-1)return(-1);
  98577. t = book->valuelist+entry*book->dim;
  98578. for (j=0;j<book->dim;)
  98579. a[i++]=t[j++];
  98580. }
  98581. return(0);
  98582. }
  98583. long vorbis_book_decodevv_add(codebook *book,float **a,long offset,int ch,
  98584. oggpack_buffer *b,int n){
  98585. long i,j,entry;
  98586. int chptr=0;
  98587. for(i=offset/ch;i<(offset+n)/ch;){
  98588. entry = decode_packed_entry_number(book,b);
  98589. if(entry==-1)return(-1);
  98590. {
  98591. const float *t = book->valuelist+entry*book->dim;
  98592. for (j=0;j<book->dim;j++){
  98593. a[chptr++][i]+=t[j];
  98594. if(chptr==ch){
  98595. chptr=0;
  98596. i++;
  98597. }
  98598. }
  98599. }
  98600. }
  98601. return(0);
  98602. }
  98603. #ifdef _V_SELFTEST
  98604. #include <stdio.h>
  98605. #include "vorbis/book/lsp20_0.vqh"
  98606. #include "vorbis/book/res0a_13.vqh"
  98607. #define TESTSIZE 40
  98608. float test1[TESTSIZE]={
  98609. 0.105939f,
  98610. 0.215373f,
  98611. 0.429117f,
  98612. 0.587974f,
  98613. 0.181173f,
  98614. 0.296583f,
  98615. 0.515707f,
  98616. 0.715261f,
  98617. 0.162327f,
  98618. 0.263834f,
  98619. 0.342876f,
  98620. 0.406025f,
  98621. 0.103571f,
  98622. 0.223561f,
  98623. 0.368513f,
  98624. 0.540313f,
  98625. 0.136672f,
  98626. 0.395882f,
  98627. 0.587183f,
  98628. 0.652476f,
  98629. 0.114338f,
  98630. 0.417300f,
  98631. 0.525486f,
  98632. 0.698679f,
  98633. 0.147492f,
  98634. 0.324481f,
  98635. 0.643089f,
  98636. 0.757582f,
  98637. 0.139556f,
  98638. 0.215795f,
  98639. 0.324559f,
  98640. 0.399387f,
  98641. 0.120236f,
  98642. 0.267420f,
  98643. 0.446940f,
  98644. 0.608760f,
  98645. 0.115587f,
  98646. 0.287234f,
  98647. 0.571081f,
  98648. 0.708603f,
  98649. };
  98650. float test3[TESTSIZE]={
  98651. 0,1,-2,3,4,-5,6,7,8,9,
  98652. 8,-2,7,-1,4,6,8,3,1,-9,
  98653. 10,11,12,13,14,15,26,17,18,19,
  98654. 30,-25,-30,-1,-5,-32,4,3,-2,0};
  98655. static_codebook *testlist[]={&_vq_book_lsp20_0,
  98656. &_vq_book_res0a_13,NULL};
  98657. float *testvec[]={test1,test3};
  98658. int main(){
  98659. oggpack_buffer write;
  98660. oggpack_buffer read;
  98661. long ptr=0,i;
  98662. oggpack_writeinit(&write);
  98663. fprintf(stderr,"Testing codebook abstraction...:\n");
  98664. while(testlist[ptr]){
  98665. codebook c;
  98666. static_codebook s;
  98667. float *qv=alloca(sizeof(*qv)*TESTSIZE);
  98668. float *iv=alloca(sizeof(*iv)*TESTSIZE);
  98669. memcpy(qv,testvec[ptr],sizeof(*qv)*TESTSIZE);
  98670. memset(iv,0,sizeof(*iv)*TESTSIZE);
  98671. fprintf(stderr,"\tpacking/coding %ld... ",ptr);
  98672. oggpack_reset(&write);
  98673. vorbis_book_init_encode(&c,testlist[ptr]); /* get it into memory
  98674. we can write */
  98675. vorbis_staticbook_pack(testlist[ptr],&write);
  98676. fprintf(stderr,"Codebook size %ld bytes... ",oggpack_bytes(&write));
  98677. for(i=0;i<TESTSIZE;i+=c.dim){
  98678. int best=_best(&c,qv+i,1);
  98679. vorbis_book_encodev(&c,best,qv+i,&write);
  98680. }
  98681. vorbis_book_clear(&c);
  98682. fprintf(stderr,"OK.\n");
  98683. fprintf(stderr,"\tunpacking/decoding %ld... ",ptr);
  98684. oggpack_readinit(&read,oggpack_get_buffer(&write),oggpack_bytes(&write));
  98685. if(vorbis_staticbook_unpack(&read,&s)){
  98686. fprintf(stderr,"Error unpacking codebook.\n");
  98687. exit(1);
  98688. }
  98689. if(vorbis_book_init_decode(&c,&s)){
  98690. fprintf(stderr,"Error initializing codebook.\n");
  98691. exit(1);
  98692. }
  98693. for(i=0;i<TESTSIZE;i+=c.dim)
  98694. if(vorbis_book_decodev_set(&c,iv+i,&read,c.dim)==-1){
  98695. fprintf(stderr,"Error reading codebook test data (EOP).\n");
  98696. exit(1);
  98697. }
  98698. for(i=0;i<TESTSIZE;i++)
  98699. if(fabs(qv[i]-iv[i])>.000001){
  98700. fprintf(stderr,"read (%g) != written (%g) at position (%ld)\n",
  98701. iv[i],qv[i],i);
  98702. exit(1);
  98703. }
  98704. fprintf(stderr,"OK\n");
  98705. ptr++;
  98706. }
  98707. exit(0);
  98708. }
  98709. #endif
  98710. #endif
  98711. /*** End of inlined file: codebook.c ***/
  98712. /*** Start of inlined file: envelope.c ***/
  98713. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  98714. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  98715. // tasks..
  98716. #if JUCE_MSVC
  98717. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  98718. #endif
  98719. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  98720. #if JUCE_USE_OGGVORBIS
  98721. #include <stdlib.h>
  98722. #include <string.h>
  98723. #include <stdio.h>
  98724. #include <math.h>
  98725. void _ve_envelope_init(envelope_lookup *e,vorbis_info *vi){
  98726. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  98727. vorbis_info_psy_global *gi=&ci->psy_g_param;
  98728. int ch=vi->channels;
  98729. int i,j;
  98730. int n=e->winlength=128;
  98731. e->searchstep=64; /* not random */
  98732. e->minenergy=gi->preecho_minenergy;
  98733. e->ch=ch;
  98734. e->storage=128;
  98735. e->cursor=ci->blocksizes[1]/2;
  98736. e->mdct_win=(float*)_ogg_calloc(n,sizeof(*e->mdct_win));
  98737. mdct_init(&e->mdct,n);
  98738. for(i=0;i<n;i++){
  98739. e->mdct_win[i]=sin(i/(n-1.)*M_PI);
  98740. e->mdct_win[i]*=e->mdct_win[i];
  98741. }
  98742. e->band[0].begin=2; e->band[0].end=4;
  98743. e->band[1].begin=4; e->band[1].end=5;
  98744. e->band[2].begin=6; e->band[2].end=6;
  98745. e->band[3].begin=9; e->band[3].end=8;
  98746. e->band[4].begin=13; e->band[4].end=8;
  98747. e->band[5].begin=17; e->band[5].end=8;
  98748. e->band[6].begin=22; e->band[6].end=8;
  98749. for(j=0;j<VE_BANDS;j++){
  98750. n=e->band[j].end;
  98751. e->band[j].window=(float*)_ogg_malloc(n*sizeof(*e->band[0].window));
  98752. for(i=0;i<n;i++){
  98753. e->band[j].window[i]=sin((i+.5)/n*M_PI);
  98754. e->band[j].total+=e->band[j].window[i];
  98755. }
  98756. e->band[j].total=1./e->band[j].total;
  98757. }
  98758. e->filter=(envelope_filter_state*)_ogg_calloc(VE_BANDS*ch,sizeof(*e->filter));
  98759. e->mark=(int*)_ogg_calloc(e->storage,sizeof(*e->mark));
  98760. }
  98761. void _ve_envelope_clear(envelope_lookup *e){
  98762. int i;
  98763. mdct_clear(&e->mdct);
  98764. for(i=0;i<VE_BANDS;i++)
  98765. _ogg_free(e->band[i].window);
  98766. _ogg_free(e->mdct_win);
  98767. _ogg_free(e->filter);
  98768. _ogg_free(e->mark);
  98769. memset(e,0,sizeof(*e));
  98770. }
  98771. static int _ve_amp(envelope_lookup *ve,
  98772. vorbis_info_psy_global *gi,
  98773. float *data,
  98774. envelope_band *bands,
  98775. envelope_filter_state *filters,
  98776. long pos){
  98777. long n=ve->winlength;
  98778. int ret=0;
  98779. long i,j;
  98780. float decay;
  98781. float minV=ve->minenergy;
  98782. float *vec=(float*) alloca(n*sizeof(*vec));
  98783. int stretch=max(VE_MINSTRETCH,ve->stretch/2);
  98784. float penalty=gi->stretch_penalty-(ve->stretch/2-VE_MINSTRETCH);
  98785. if(penalty<0.f)penalty=0.f;
  98786. if(penalty>gi->stretch_penalty)penalty=gi->stretch_penalty;
  98787. for(i=0;i<n;i++)
  98788. vec[i]=data[i]*ve->mdct_win[i];
  98789. mdct_forward(&ve->mdct,vec,vec);
  98790. {
  98791. float temp=vec[0]*vec[0]+.7*vec[1]*vec[1]+.2*vec[2]*vec[2];
  98792. int ptr=filters->nearptr;
  98793. if(ptr==0){
  98794. decay=filters->nearDC_acc=filters->nearDC_partialacc+temp;
  98795. filters->nearDC_partialacc=temp;
  98796. }else{
  98797. decay=filters->nearDC_acc+=temp;
  98798. filters->nearDC_partialacc+=temp;
  98799. }
  98800. filters->nearDC_acc-=filters->nearDC[ptr];
  98801. filters->nearDC[ptr]=temp;
  98802. decay*=(1./(VE_NEARDC+1));
  98803. filters->nearptr++;
  98804. if(filters->nearptr>=VE_NEARDC)filters->nearptr=0;
  98805. decay=todB(&decay)*.5-15.f;
  98806. }
  98807. for(i=0;i<n/2;i+=2){
  98808. float val=vec[i]*vec[i]+vec[i+1]*vec[i+1];
  98809. val=todB(&val)*.5f;
  98810. if(val<decay)val=decay;
  98811. if(val<minV)val=minV;
  98812. vec[i>>1]=val;
  98813. decay-=8.;
  98814. }
  98815. for(j=0;j<VE_BANDS;j++){
  98816. float acc=0.;
  98817. float valmax,valmin;
  98818. for(i=0;i<bands[j].end;i++)
  98819. acc+=vec[i+bands[j].begin]*bands[j].window[i];
  98820. acc*=bands[j].total;
  98821. {
  98822. int p,thisx=filters[j].ampptr;
  98823. float postmax,postmin,premax=-99999.f,premin=99999.f;
  98824. p=thisx;
  98825. p--;
  98826. if(p<0)p+=VE_AMP;
  98827. postmax=max(acc,filters[j].ampbuf[p]);
  98828. postmin=min(acc,filters[j].ampbuf[p]);
  98829. for(i=0;i<stretch;i++){
  98830. p--;
  98831. if(p<0)p+=VE_AMP;
  98832. premax=max(premax,filters[j].ampbuf[p]);
  98833. premin=min(premin,filters[j].ampbuf[p]);
  98834. }
  98835. valmin=postmin-premin;
  98836. valmax=postmax-premax;
  98837. filters[j].ampbuf[thisx]=acc;
  98838. filters[j].ampptr++;
  98839. if(filters[j].ampptr>=VE_AMP)filters[j].ampptr=0;
  98840. }
  98841. if(valmax>gi->preecho_thresh[j]+penalty){
  98842. ret|=1;
  98843. ret|=4;
  98844. }
  98845. if(valmin<gi->postecho_thresh[j]-penalty)ret|=2;
  98846. }
  98847. return(ret);
  98848. }
  98849. #if 0
  98850. static int seq=0;
  98851. static ogg_int64_t totalshift=-1024;
  98852. #endif
  98853. long _ve_envelope_search(vorbis_dsp_state *v){
  98854. vorbis_info *vi=v->vi;
  98855. codec_setup_info *ci=(codec_setup_info *)vi->codec_setup;
  98856. vorbis_info_psy_global *gi=&ci->psy_g_param;
  98857. envelope_lookup *ve=((private_state *)(v->backend_state))->ve;
  98858. long i,j;
  98859. int first=ve->current/ve->searchstep;
  98860. int last=v->pcm_current/ve->searchstep-VE_WIN;
  98861. if(first<0)first=0;
  98862. if(last+VE_WIN+VE_POST>ve->storage){
  98863. ve->storage=last+VE_WIN+VE_POST; /* be sure */
  98864. ve->mark=(int*)_ogg_realloc(ve->mark,ve->storage*sizeof(*ve->mark));
  98865. }
  98866. for(j=first;j<last;j++){
  98867. int ret=0;
  98868. ve->stretch++;
  98869. if(ve->stretch>VE_MAXSTRETCH*2)
  98870. ve->stretch=VE_MAXSTRETCH*2;
  98871. for(i=0;i<ve->ch;i++){
  98872. float *pcm=v->pcm[i]+ve->searchstep*(j);
  98873. ret|=_ve_amp(ve,gi,pcm,ve->band,ve->filter+i*VE_BANDS,j);
  98874. }
  98875. ve->mark[j+VE_POST]=0;
  98876. if(ret&1){
  98877. ve->mark[j]=1;
  98878. ve->mark[j+1]=1;
  98879. }
  98880. if(ret&2){
  98881. ve->mark[j]=1;
  98882. if(j>0)ve->mark[j-1]=1;
  98883. }
  98884. if(ret&4)ve->stretch=-1;
  98885. }
  98886. ve->current=last*ve->searchstep;
  98887. {
  98888. long centerW=v->centerW;
  98889. long testW=
  98890. centerW+
  98891. ci->blocksizes[v->W]/4+
  98892. ci->blocksizes[1]/2+
  98893. ci->blocksizes[0]/4;
  98894. j=ve->cursor;
  98895. while(j<ve->current-(ve->searchstep)){/* account for postecho
  98896. working back one window */
  98897. if(j>=testW)return(1);
  98898. ve->cursor=j;
  98899. if(ve->mark[j/ve->searchstep]){
  98900. if(j>centerW){
  98901. #if 0
  98902. if(j>ve->curmark){
  98903. float *marker=alloca(v->pcm_current*sizeof(*marker));
  98904. int l,m;
  98905. memset(marker,0,sizeof(*marker)*v->pcm_current);
  98906. fprintf(stderr,"mark! seq=%d, cursor:%fs time:%fs\n",
  98907. seq,
  98908. (totalshift+ve->cursor)/44100.,
  98909. (totalshift+j)/44100.);
  98910. _analysis_output_always("pcmL",seq,v->pcm[0],v->pcm_current,0,0,totalshift);
  98911. _analysis_output_always("pcmR",seq,v->pcm[1],v->pcm_current,0,0,totalshift);
  98912. _analysis_output_always("markL",seq,v->pcm[0],j,0,0,totalshift);
  98913. _analysis_output_always("markR",seq,v->pcm[1],j,0,0,totalshift);
  98914. for(m=0;m<VE_BANDS;m++){
  98915. char buf[80];
  98916. sprintf(buf,"delL%d",m);
  98917. for(l=0;l<last;l++)marker[l*ve->searchstep]=ve->filter[m].markers[l]*.1;
  98918. _analysis_output_always(buf,seq,marker,v->pcm_current,0,0,totalshift);
  98919. }
  98920. for(m=0;m<VE_BANDS;m++){
  98921. char buf[80];
  98922. sprintf(buf,"delR%d",m);
  98923. for(l=0;l<last;l++)marker[l*ve->searchstep]=ve->filter[m+VE_BANDS].markers[l]*.1;
  98924. _analysis_output_always(buf,seq,marker,v->pcm_current,0,0,totalshift);
  98925. }
  98926. for(l=0;l<last;l++)marker[l*ve->searchstep]=ve->mark[l]*.4;
  98927. _analysis_output_always("mark",seq,marker,v->pcm_current,0,0,totalshift);
  98928. seq++;
  98929. }
  98930. #endif
  98931. ve->curmark=j;
  98932. if(j>=testW)return(1);
  98933. return(0);
  98934. }
  98935. }
  98936. j+=ve->searchstep;
  98937. }
  98938. }
  98939. return(-1);
  98940. }
  98941. int _ve_envelope_mark(vorbis_dsp_state *v){
  98942. envelope_lookup *ve=((private_state *)(v->backend_state))->ve;
  98943. vorbis_info *vi=v->vi;
  98944. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  98945. long centerW=v->centerW;
  98946. long beginW=centerW-ci->blocksizes[v->W]/4;
  98947. long endW=centerW+ci->blocksizes[v->W]/4;
  98948. if(v->W){
  98949. beginW-=ci->blocksizes[v->lW]/4;
  98950. endW+=ci->blocksizes[v->nW]/4;
  98951. }else{
  98952. beginW-=ci->blocksizes[0]/4;
  98953. endW+=ci->blocksizes[0]/4;
  98954. }
  98955. if(ve->curmark>=beginW && ve->curmark<endW)return(1);
  98956. {
  98957. long first=beginW/ve->searchstep;
  98958. long last=endW/ve->searchstep;
  98959. long i;
  98960. for(i=first;i<last;i++)
  98961. if(ve->mark[i])return(1);
  98962. }
  98963. return(0);
  98964. }
  98965. void _ve_envelope_shift(envelope_lookup *e,long shift){
  98966. int smallsize=e->current/e->searchstep+VE_POST; /* adjust for placing marks
  98967. ahead of ve->current */
  98968. int smallshift=shift/e->searchstep;
  98969. memmove(e->mark,e->mark+smallshift,(smallsize-smallshift)*sizeof(*e->mark));
  98970. #if 0
  98971. for(i=0;i<VE_BANDS*e->ch;i++)
  98972. memmove(e->filter[i].markers,
  98973. e->filter[i].markers+smallshift,
  98974. (1024-smallshift)*sizeof(*(*e->filter).markers));
  98975. totalshift+=shift;
  98976. #endif
  98977. e->current-=shift;
  98978. if(e->curmark>=0)
  98979. e->curmark-=shift;
  98980. e->cursor-=shift;
  98981. }
  98982. #endif
  98983. /*** End of inlined file: envelope.c ***/
  98984. /*** Start of inlined file: floor0.c ***/
  98985. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  98986. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  98987. // tasks..
  98988. #if JUCE_MSVC
  98989. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  98990. #endif
  98991. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  98992. #if JUCE_USE_OGGVORBIS
  98993. #include <stdlib.h>
  98994. #include <string.h>
  98995. #include <math.h>
  98996. /*** Start of inlined file: lsp.h ***/
  98997. #ifndef _V_LSP_H_
  98998. #define _V_LSP_H_
  98999. extern int vorbis_lpc_to_lsp(float *lpc,float *lsp,int m);
  99000. extern void vorbis_lsp_to_curve(float *curve,int *map,int n,int ln,
  99001. float *lsp,int m,
  99002. float amp,float ampoffset);
  99003. #endif
  99004. /*** End of inlined file: lsp.h ***/
  99005. #include <stdio.h>
  99006. typedef struct {
  99007. int ln;
  99008. int m;
  99009. int **linearmap;
  99010. int n[2];
  99011. vorbis_info_floor0 *vi;
  99012. long bits;
  99013. long frames;
  99014. } vorbis_look_floor0;
  99015. static void floor0_free_info(vorbis_info_floor *i){
  99016. vorbis_info_floor0 *info=(vorbis_info_floor0 *)i;
  99017. if(info){
  99018. memset(info,0,sizeof(*info));
  99019. _ogg_free(info);
  99020. }
  99021. }
  99022. static void floor0_free_look(vorbis_look_floor *i){
  99023. vorbis_look_floor0 *look=(vorbis_look_floor0 *)i;
  99024. if(look){
  99025. if(look->linearmap){
  99026. if(look->linearmap[0])_ogg_free(look->linearmap[0]);
  99027. if(look->linearmap[1])_ogg_free(look->linearmap[1]);
  99028. _ogg_free(look->linearmap);
  99029. }
  99030. memset(look,0,sizeof(*look));
  99031. _ogg_free(look);
  99032. }
  99033. }
  99034. static vorbis_info_floor *floor0_unpack (vorbis_info *vi,oggpack_buffer *opb){
  99035. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  99036. int j;
  99037. vorbis_info_floor0 *info=(vorbis_info_floor0*)_ogg_malloc(sizeof(*info));
  99038. info->order=oggpack_read(opb,8);
  99039. info->rate=oggpack_read(opb,16);
  99040. info->barkmap=oggpack_read(opb,16);
  99041. info->ampbits=oggpack_read(opb,6);
  99042. info->ampdB=oggpack_read(opb,8);
  99043. info->numbooks=oggpack_read(opb,4)+1;
  99044. if(info->order<1)goto err_out;
  99045. if(info->rate<1)goto err_out;
  99046. if(info->barkmap<1)goto err_out;
  99047. if(info->numbooks<1)goto err_out;
  99048. for(j=0;j<info->numbooks;j++){
  99049. info->books[j]=oggpack_read(opb,8);
  99050. if(info->books[j]<0 || info->books[j]>=ci->books)goto err_out;
  99051. }
  99052. return(info);
  99053. err_out:
  99054. floor0_free_info(info);
  99055. return(NULL);
  99056. }
  99057. static void floor0_map_lazy_init(vorbis_block *vb,
  99058. vorbis_info_floor *infoX,
  99059. vorbis_look_floor0 *look){
  99060. if(!look->linearmap[vb->W]){
  99061. vorbis_dsp_state *vd=vb->vd;
  99062. vorbis_info *vi=vd->vi;
  99063. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  99064. vorbis_info_floor0 *info=(vorbis_info_floor0 *)infoX;
  99065. int W=vb->W;
  99066. int n=ci->blocksizes[W]/2,j;
  99067. float scale=look->ln/toBARK(info->rate/2.f);
  99068. look->linearmap[W]=(int*)_ogg_malloc((n+1)*sizeof(**look->linearmap));
  99069. for(j=0;j<n;j++){
  99070. int val=floor( toBARK((info->rate/2.f)/n*j)
  99071. *scale); /* bark numbers represent band edges */
  99072. if(val>=look->ln)val=look->ln-1; /* guard against the approximation */
  99073. look->linearmap[W][j]=val;
  99074. }
  99075. look->linearmap[W][j]=-1;
  99076. look->n[W]=n;
  99077. }
  99078. }
  99079. static vorbis_look_floor *floor0_look(vorbis_dsp_state *vd,
  99080. vorbis_info_floor *i){
  99081. vorbis_info_floor0 *info=(vorbis_info_floor0*)i;
  99082. vorbis_look_floor0 *look=(vorbis_look_floor0*)_ogg_calloc(1,sizeof(*look));
  99083. look->m=info->order;
  99084. look->ln=info->barkmap;
  99085. look->vi=info;
  99086. look->linearmap=(int**)_ogg_calloc(2,sizeof(*look->linearmap));
  99087. return look;
  99088. }
  99089. static void *floor0_inverse1(vorbis_block *vb,vorbis_look_floor *i){
  99090. vorbis_look_floor0 *look=(vorbis_look_floor0 *)i;
  99091. vorbis_info_floor0 *info=look->vi;
  99092. int j,k;
  99093. int ampraw=oggpack_read(&vb->opb,info->ampbits);
  99094. if(ampraw>0){ /* also handles the -1 out of data case */
  99095. long maxval=(1<<info->ampbits)-1;
  99096. float amp=(float)ampraw/maxval*info->ampdB;
  99097. int booknum=oggpack_read(&vb->opb,_ilog(info->numbooks));
  99098. if(booknum!=-1 && booknum<info->numbooks){ /* be paranoid */
  99099. codec_setup_info *ci=(codec_setup_info *)vb->vd->vi->codec_setup;
  99100. codebook *b=ci->fullbooks+info->books[booknum];
  99101. float last=0.f;
  99102. float *lsp=(float*)_vorbis_block_alloc(vb,sizeof(*lsp)*(look->m+b->dim+1));
  99103. for(j=0;j<look->m;j+=b->dim)
  99104. if(vorbis_book_decodev_set(b,lsp+j,&vb->opb,b->dim)==-1)goto eop;
  99105. for(j=0;j<look->m;){
  99106. for(k=0;k<b->dim;k++,j++)lsp[j]+=last;
  99107. last=lsp[j-1];
  99108. }
  99109. lsp[look->m]=amp;
  99110. return(lsp);
  99111. }
  99112. }
  99113. eop:
  99114. return(NULL);
  99115. }
  99116. static int floor0_inverse2(vorbis_block *vb,vorbis_look_floor *i,
  99117. void *memo,float *out){
  99118. vorbis_look_floor0 *look=(vorbis_look_floor0 *)i;
  99119. vorbis_info_floor0 *info=look->vi;
  99120. floor0_map_lazy_init(vb,info,look);
  99121. if(memo){
  99122. float *lsp=(float *)memo;
  99123. float amp=lsp[look->m];
  99124. vorbis_lsp_to_curve(out,
  99125. look->linearmap[vb->W],
  99126. look->n[vb->W],
  99127. look->ln,
  99128. lsp,look->m,amp,(float)info->ampdB);
  99129. return(1);
  99130. }
  99131. memset(out,0,sizeof(*out)*look->n[vb->W]);
  99132. return(0);
  99133. }
  99134. vorbis_func_floor floor0_exportbundle={
  99135. NULL,&floor0_unpack,&floor0_look,&floor0_free_info,
  99136. &floor0_free_look,&floor0_inverse1,&floor0_inverse2
  99137. };
  99138. #endif
  99139. /*** End of inlined file: floor0.c ***/
  99140. /*** Start of inlined file: floor1.c ***/
  99141. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  99142. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  99143. // tasks..
  99144. #if JUCE_MSVC
  99145. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  99146. #endif
  99147. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  99148. #if JUCE_USE_OGGVORBIS
  99149. #include <stdlib.h>
  99150. #include <string.h>
  99151. #include <math.h>
  99152. #include <stdio.h>
  99153. #define floor1_rangedB 140 /* floor 1 fixed at -140dB to 0dB range */
  99154. typedef struct {
  99155. int sorted_index[VIF_POSIT+2];
  99156. int forward_index[VIF_POSIT+2];
  99157. int reverse_index[VIF_POSIT+2];
  99158. int hineighbor[VIF_POSIT];
  99159. int loneighbor[VIF_POSIT];
  99160. int posts;
  99161. int n;
  99162. int quant_q;
  99163. vorbis_info_floor1 *vi;
  99164. long phrasebits;
  99165. long postbits;
  99166. long frames;
  99167. } vorbis_look_floor1;
  99168. typedef struct lsfit_acc{
  99169. long x0;
  99170. long x1;
  99171. long xa;
  99172. long ya;
  99173. long x2a;
  99174. long y2a;
  99175. long xya;
  99176. long an;
  99177. } lsfit_acc;
  99178. static void floor1_free_info(vorbis_info_floor *i){
  99179. vorbis_info_floor1 *info=(vorbis_info_floor1 *)i;
  99180. if(info){
  99181. memset(info,0,sizeof(*info));
  99182. _ogg_free(info);
  99183. }
  99184. }
  99185. static void floor1_free_look(vorbis_look_floor *i){
  99186. vorbis_look_floor1 *look=(vorbis_look_floor1 *)i;
  99187. if(look){
  99188. memset(look,0,sizeof(*look));
  99189. _ogg_free(look);
  99190. }
  99191. }
  99192. static void floor1_pack (vorbis_info_floor *i,oggpack_buffer *opb){
  99193. vorbis_info_floor1 *info=(vorbis_info_floor1 *)i;
  99194. int j,k;
  99195. int count=0;
  99196. int rangebits;
  99197. int maxposit=info->postlist[1];
  99198. int maxclass=-1;
  99199. oggpack_write(opb,info->partitions,5); /* only 0 to 31 legal */
  99200. for(j=0;j<info->partitions;j++){
  99201. oggpack_write(opb,info->partitionclass[j],4); /* only 0 to 15 legal */
  99202. if(maxclass<info->partitionclass[j])maxclass=info->partitionclass[j];
  99203. }
  99204. for(j=0;j<maxclass+1;j++){
  99205. oggpack_write(opb,info->class_dim[j]-1,3); /* 1 to 8 */
  99206. oggpack_write(opb,info->class_subs[j],2); /* 0 to 3 */
  99207. if(info->class_subs[j])oggpack_write(opb,info->class_book[j],8);
  99208. for(k=0;k<(1<<info->class_subs[j]);k++)
  99209. oggpack_write(opb,info->class_subbook[j][k]+1,8);
  99210. }
  99211. oggpack_write(opb,info->mult-1,2); /* only 1,2,3,4 legal now */
  99212. oggpack_write(opb,ilog2(maxposit),4);
  99213. rangebits=ilog2(maxposit);
  99214. for(j=0,k=0;j<info->partitions;j++){
  99215. count+=info->class_dim[info->partitionclass[j]];
  99216. for(;k<count;k++)
  99217. oggpack_write(opb,info->postlist[k+2],rangebits);
  99218. }
  99219. }
  99220. static vorbis_info_floor *floor1_unpack (vorbis_info *vi,oggpack_buffer *opb){
  99221. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  99222. int j,k,count=0,maxclass=-1,rangebits;
  99223. vorbis_info_floor1 *info=(vorbis_info_floor1*)_ogg_calloc(1,sizeof(*info));
  99224. info->partitions=oggpack_read(opb,5); /* only 0 to 31 legal */
  99225. for(j=0;j<info->partitions;j++){
  99226. info->partitionclass[j]=oggpack_read(opb,4); /* only 0 to 15 legal */
  99227. if(maxclass<info->partitionclass[j])maxclass=info->partitionclass[j];
  99228. }
  99229. for(j=0;j<maxclass+1;j++){
  99230. info->class_dim[j]=oggpack_read(opb,3)+1; /* 1 to 8 */
  99231. info->class_subs[j]=oggpack_read(opb,2); /* 0,1,2,3 bits */
  99232. if(info->class_subs[j]<0)
  99233. goto err_out;
  99234. if(info->class_subs[j])info->class_book[j]=oggpack_read(opb,8);
  99235. if(info->class_book[j]<0 || info->class_book[j]>=ci->books)
  99236. goto err_out;
  99237. for(k=0;k<(1<<info->class_subs[j]);k++){
  99238. info->class_subbook[j][k]=oggpack_read(opb,8)-1;
  99239. if(info->class_subbook[j][k]<-1 || info->class_subbook[j][k]>=ci->books)
  99240. goto err_out;
  99241. }
  99242. }
  99243. info->mult=oggpack_read(opb,2)+1; /* only 1,2,3,4 legal now */
  99244. rangebits=oggpack_read(opb,4);
  99245. for(j=0,k=0;j<info->partitions;j++){
  99246. count+=info->class_dim[info->partitionclass[j]];
  99247. for(;k<count;k++){
  99248. int t=info->postlist[k+2]=oggpack_read(opb,rangebits);
  99249. if(t<0 || t>=(1<<rangebits))
  99250. goto err_out;
  99251. }
  99252. }
  99253. info->postlist[0]=0;
  99254. info->postlist[1]=1<<rangebits;
  99255. return(info);
  99256. err_out:
  99257. floor1_free_info(info);
  99258. return(NULL);
  99259. }
  99260. static int icomp(const void *a,const void *b){
  99261. return(**(int **)a-**(int **)b);
  99262. }
  99263. static vorbis_look_floor *floor1_look(vorbis_dsp_state *vd,
  99264. vorbis_info_floor *in){
  99265. int *sortpointer[VIF_POSIT+2];
  99266. vorbis_info_floor1 *info=(vorbis_info_floor1*)in;
  99267. vorbis_look_floor1 *look=(vorbis_look_floor1*)_ogg_calloc(1,sizeof(*look));
  99268. int i,j,n=0;
  99269. look->vi=info;
  99270. look->n=info->postlist[1];
  99271. for(i=0;i<info->partitions;i++)n+=info->class_dim[info->partitionclass[i]];
  99272. n+=2;
  99273. look->posts=n;
  99274. for(i=0;i<n;i++)sortpointer[i]=info->postlist+i;
  99275. qsort(sortpointer,n,sizeof(*sortpointer),icomp);
  99276. for(i=0;i<n;i++)look->forward_index[i]=sortpointer[i]-info->postlist;
  99277. for(i=0;i<n;i++)look->reverse_index[look->forward_index[i]]=i;
  99278. for(i=0;i<n;i++)look->sorted_index[i]=info->postlist[look->forward_index[i]];
  99279. switch(info->mult){
  99280. case 1: /* 1024 -> 256 */
  99281. look->quant_q=256;
  99282. break;
  99283. case 2: /* 1024 -> 128 */
  99284. look->quant_q=128;
  99285. break;
  99286. case 3: /* 1024 -> 86 */
  99287. look->quant_q=86;
  99288. break;
  99289. case 4: /* 1024 -> 64 */
  99290. look->quant_q=64;
  99291. break;
  99292. }
  99293. for(i=0;i<n-2;i++){
  99294. int lo=0;
  99295. int hi=1;
  99296. int lx=0;
  99297. int hx=look->n;
  99298. int currentx=info->postlist[i+2];
  99299. for(j=0;j<i+2;j++){
  99300. int x=info->postlist[j];
  99301. if(x>lx && x<currentx){
  99302. lo=j;
  99303. lx=x;
  99304. }
  99305. if(x<hx && x>currentx){
  99306. hi=j;
  99307. hx=x;
  99308. }
  99309. }
  99310. look->loneighbor[i]=lo;
  99311. look->hineighbor[i]=hi;
  99312. }
  99313. return(look);
  99314. }
  99315. static int render_point(int x0,int x1,int y0,int y1,int x){
  99316. y0&=0x7fff; /* mask off flag */
  99317. y1&=0x7fff;
  99318. {
  99319. int dy=y1-y0;
  99320. int adx=x1-x0;
  99321. int ady=abs(dy);
  99322. int err=ady*(x-x0);
  99323. int off=err/adx;
  99324. if(dy<0)return(y0-off);
  99325. return(y0+off);
  99326. }
  99327. }
  99328. static int vorbis_dBquant(const float *x){
  99329. int i= *x*7.3142857f+1023.5f;
  99330. if(i>1023)return(1023);
  99331. if(i<0)return(0);
  99332. return i;
  99333. }
  99334. static float FLOOR1_fromdB_LOOKUP[256]={
  99335. 1.0649863e-07F, 1.1341951e-07F, 1.2079015e-07F, 1.2863978e-07F,
  99336. 1.3699951e-07F, 1.4590251e-07F, 1.5538408e-07F, 1.6548181e-07F,
  99337. 1.7623575e-07F, 1.8768855e-07F, 1.9988561e-07F, 2.128753e-07F,
  99338. 2.2670913e-07F, 2.4144197e-07F, 2.5713223e-07F, 2.7384213e-07F,
  99339. 2.9163793e-07F, 3.1059021e-07F, 3.3077411e-07F, 3.5226968e-07F,
  99340. 3.7516214e-07F, 3.9954229e-07F, 4.2550680e-07F, 4.5315863e-07F,
  99341. 4.8260743e-07F, 5.1396998e-07F, 5.4737065e-07F, 5.8294187e-07F,
  99342. 6.2082472e-07F, 6.6116941e-07F, 7.0413592e-07F, 7.4989464e-07F,
  99343. 7.9862701e-07F, 8.5052630e-07F, 9.0579828e-07F, 9.6466216e-07F,
  99344. 1.0273513e-06F, 1.0941144e-06F, 1.1652161e-06F, 1.2409384e-06F,
  99345. 1.3215816e-06F, 1.4074654e-06F, 1.4989305e-06F, 1.5963394e-06F,
  99346. 1.7000785e-06F, 1.8105592e-06F, 1.9282195e-06F, 2.0535261e-06F,
  99347. 2.1869758e-06F, 2.3290978e-06F, 2.4804557e-06F, 2.6416497e-06F,
  99348. 2.8133190e-06F, 2.9961443e-06F, 3.1908506e-06F, 3.3982101e-06F,
  99349. 3.6190449e-06F, 3.8542308e-06F, 4.1047004e-06F, 4.3714470e-06F,
  99350. 4.6555282e-06F, 4.9580707e-06F, 5.2802740e-06F, 5.6234160e-06F,
  99351. 5.9888572e-06F, 6.3780469e-06F, 6.7925283e-06F, 7.2339451e-06F,
  99352. 7.7040476e-06F, 8.2047000e-06F, 8.7378876e-06F, 9.3057248e-06F,
  99353. 9.9104632e-06F, 1.0554501e-05F, 1.1240392e-05F, 1.1970856e-05F,
  99354. 1.2748789e-05F, 1.3577278e-05F, 1.4459606e-05F, 1.5399272e-05F,
  99355. 1.6400004e-05F, 1.7465768e-05F, 1.8600792e-05F, 1.9809576e-05F,
  99356. 2.1096914e-05F, 2.2467911e-05F, 2.3928002e-05F, 2.5482978e-05F,
  99357. 2.7139006e-05F, 2.8902651e-05F, 3.0780908e-05F, 3.2781225e-05F,
  99358. 3.4911534e-05F, 3.7180282e-05F, 3.9596466e-05F, 4.2169667e-05F,
  99359. 4.4910090e-05F, 4.7828601e-05F, 5.0936773e-05F, 5.4246931e-05F,
  99360. 5.7772202e-05F, 6.1526565e-05F, 6.5524908e-05F, 6.9783085e-05F,
  99361. 7.4317983e-05F, 7.9147585e-05F, 8.4291040e-05F, 8.9768747e-05F,
  99362. 9.5602426e-05F, 0.00010181521F, 0.00010843174F, 0.00011547824F,
  99363. 0.00012298267F, 0.00013097477F, 0.00013948625F, 0.00014855085F,
  99364. 0.00015820453F, 0.00016848555F, 0.00017943469F, 0.00019109536F,
  99365. 0.00020351382F, 0.00021673929F, 0.00023082423F, 0.00024582449F,
  99366. 0.00026179955F, 0.00027881276F, 0.00029693158F, 0.00031622787F,
  99367. 0.00033677814F, 0.00035866388F, 0.00038197188F, 0.00040679456F,
  99368. 0.00043323036F, 0.00046138411F, 0.00049136745F, 0.00052329927F,
  99369. 0.00055730621F, 0.00059352311F, 0.00063209358F, 0.00067317058F,
  99370. 0.00071691700F, 0.00076350630F, 0.00081312324F, 0.00086596457F,
  99371. 0.00092223983F, 0.00098217216F, 0.0010459992F, 0.0011139742F,
  99372. 0.0011863665F, 0.0012634633F, 0.0013455702F, 0.0014330129F,
  99373. 0.0015261382F, 0.0016253153F, 0.0017309374F, 0.0018434235F,
  99374. 0.0019632195F, 0.0020908006F, 0.0022266726F, 0.0023713743F,
  99375. 0.0025254795F, 0.0026895994F, 0.0028643847F, 0.0030505286F,
  99376. 0.0032487691F, 0.0034598925F, 0.0036847358F, 0.0039241906F,
  99377. 0.0041792066F, 0.0044507950F, 0.0047400328F, 0.0050480668F,
  99378. 0.0053761186F, 0.0057254891F, 0.0060975636F, 0.0064938176F,
  99379. 0.0069158225F, 0.0073652516F, 0.0078438871F, 0.0083536271F,
  99380. 0.0088964928F, 0.009474637F, 0.010090352F, 0.010746080F,
  99381. 0.011444421F, 0.012188144F, 0.012980198F, 0.013823725F,
  99382. 0.014722068F, 0.015678791F, 0.016697687F, 0.017782797F,
  99383. 0.018938423F, 0.020169149F, 0.021479854F, 0.022875735F,
  99384. 0.024362330F, 0.025945531F, 0.027631618F, 0.029427276F,
  99385. 0.031339626F, 0.033376252F, 0.035545228F, 0.037855157F,
  99386. 0.040315199F, 0.042935108F, 0.045725273F, 0.048696758F,
  99387. 0.051861348F, 0.055231591F, 0.058820850F, 0.062643361F,
  99388. 0.066714279F, 0.071049749F, 0.075666962F, 0.080584227F,
  99389. 0.085821044F, 0.091398179F, 0.097337747F, 0.10366330F,
  99390. 0.11039993F, 0.11757434F, 0.12521498F, 0.13335215F,
  99391. 0.14201813F, 0.15124727F, 0.16107617F, 0.17154380F,
  99392. 0.18269168F, 0.19456402F, 0.20720788F, 0.22067342F,
  99393. 0.23501402F, 0.25028656F, 0.26655159F, 0.28387361F,
  99394. 0.30232132F, 0.32196786F, 0.34289114F, 0.36517414F,
  99395. 0.38890521F, 0.41417847F, 0.44109412F, 0.46975890F,
  99396. 0.50028648F, 0.53279791F, 0.56742212F, 0.60429640F,
  99397. 0.64356699F, 0.68538959F, 0.72993007F, 0.77736504F,
  99398. 0.82788260F, 0.88168307F, 0.9389798F, 1.F,
  99399. };
  99400. static void render_line(int x0,int x1,int y0,int y1,float *d){
  99401. int dy=y1-y0;
  99402. int adx=x1-x0;
  99403. int ady=abs(dy);
  99404. int base=dy/adx;
  99405. int sy=(dy<0?base-1:base+1);
  99406. int x=x0;
  99407. int y=y0;
  99408. int err=0;
  99409. ady-=abs(base*adx);
  99410. d[x]*=FLOOR1_fromdB_LOOKUP[y];
  99411. while(++x<x1){
  99412. err=err+ady;
  99413. if(err>=adx){
  99414. err-=adx;
  99415. y+=sy;
  99416. }else{
  99417. y+=base;
  99418. }
  99419. d[x]*=FLOOR1_fromdB_LOOKUP[y];
  99420. }
  99421. }
  99422. static void render_line0(int x0,int x1,int y0,int y1,int *d){
  99423. int dy=y1-y0;
  99424. int adx=x1-x0;
  99425. int ady=abs(dy);
  99426. int base=dy/adx;
  99427. int sy=(dy<0?base-1:base+1);
  99428. int x=x0;
  99429. int y=y0;
  99430. int err=0;
  99431. ady-=abs(base*adx);
  99432. d[x]=y;
  99433. while(++x<x1){
  99434. err=err+ady;
  99435. if(err>=adx){
  99436. err-=adx;
  99437. y+=sy;
  99438. }else{
  99439. y+=base;
  99440. }
  99441. d[x]=y;
  99442. }
  99443. }
  99444. static int accumulate_fit(const float *flr,const float *mdct,
  99445. int x0, int x1,lsfit_acc *a,
  99446. int n,vorbis_info_floor1 *info){
  99447. long i;
  99448. 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;
  99449. memset(a,0,sizeof(*a));
  99450. a->x0=x0;
  99451. a->x1=x1;
  99452. if(x1>=n)x1=n-1;
  99453. for(i=x0;i<=x1;i++){
  99454. int quantized=vorbis_dBquant(flr+i);
  99455. if(quantized){
  99456. if(mdct[i]+info->twofitatten>=flr[i]){
  99457. xa += i;
  99458. ya += quantized;
  99459. x2a += i*i;
  99460. y2a += quantized*quantized;
  99461. xya += i*quantized;
  99462. na++;
  99463. }else{
  99464. xb += i;
  99465. yb += quantized;
  99466. x2b += i*i;
  99467. y2b += quantized*quantized;
  99468. xyb += i*quantized;
  99469. nb++;
  99470. }
  99471. }
  99472. }
  99473. xb+=xa;
  99474. yb+=ya;
  99475. x2b+=x2a;
  99476. y2b+=y2a;
  99477. xyb+=xya;
  99478. nb+=na;
  99479. {
  99480. int weight=nb*info->twofitweight/(na+1);
  99481. a->xa=xa*weight+xb;
  99482. a->ya=ya*weight+yb;
  99483. a->x2a=x2a*weight+x2b;
  99484. a->y2a=y2a*weight+y2b;
  99485. a->xya=xya*weight+xyb;
  99486. a->an=na*weight+nb;
  99487. }
  99488. return(na);
  99489. }
  99490. static void fit_line(lsfit_acc *a,int fits,int *y0,int *y1){
  99491. long x=0,y=0,x2=0,y2=0,xy=0,an=0,i;
  99492. long x0=a[0].x0;
  99493. long x1=a[fits-1].x1;
  99494. for(i=0;i<fits;i++){
  99495. x+=a[i].xa;
  99496. y+=a[i].ya;
  99497. x2+=a[i].x2a;
  99498. y2+=a[i].y2a;
  99499. xy+=a[i].xya;
  99500. an+=a[i].an;
  99501. }
  99502. if(*y0>=0){
  99503. x+= x0;
  99504. y+= *y0;
  99505. x2+= x0 * x0;
  99506. y2+= *y0 * *y0;
  99507. xy+= *y0 * x0;
  99508. an++;
  99509. }
  99510. if(*y1>=0){
  99511. x+= x1;
  99512. y+= *y1;
  99513. x2+= x1 * x1;
  99514. y2+= *y1 * *y1;
  99515. xy+= *y1 * x1;
  99516. an++;
  99517. }
  99518. if(an){
  99519. double fx=x;
  99520. double fy=y;
  99521. double fx2=x2;
  99522. double fxy=xy;
  99523. double denom=1./(an*fx2-fx*fx);
  99524. double a=(fy*fx2-fxy*fx)*denom;
  99525. double b=(an*fxy-fx*fy)*denom;
  99526. *y0=rint(a+b*x0);
  99527. *y1=rint(a+b*x1);
  99528. if(*y0>1023)*y0=1023;
  99529. if(*y1>1023)*y1=1023;
  99530. if(*y0<0)*y0=0;
  99531. if(*y1<0)*y1=0;
  99532. }else{
  99533. *y0=0;
  99534. *y1=0;
  99535. }
  99536. }
  99537. static int inspect_error(int x0,int x1,int y0,int y1,const float *mask,
  99538. const float *mdct,
  99539. vorbis_info_floor1 *info){
  99540. int dy=y1-y0;
  99541. int adx=x1-x0;
  99542. int ady=abs(dy);
  99543. int base=dy/adx;
  99544. int sy=(dy<0?base-1:base+1);
  99545. int x=x0;
  99546. int y=y0;
  99547. int err=0;
  99548. int val=vorbis_dBquant(mask+x);
  99549. int mse=0;
  99550. int n=0;
  99551. ady-=abs(base*adx);
  99552. mse=(y-val);
  99553. mse*=mse;
  99554. n++;
  99555. if(mdct[x]+info->twofitatten>=mask[x]){
  99556. if(y+info->maxover<val)return(1);
  99557. if(y-info->maxunder>val)return(1);
  99558. }
  99559. while(++x<x1){
  99560. err=err+ady;
  99561. if(err>=adx){
  99562. err-=adx;
  99563. y+=sy;
  99564. }else{
  99565. y+=base;
  99566. }
  99567. val=vorbis_dBquant(mask+x);
  99568. mse+=((y-val)*(y-val));
  99569. n++;
  99570. if(mdct[x]+info->twofitatten>=mask[x]){
  99571. if(val){
  99572. if(y+info->maxover<val)return(1);
  99573. if(y-info->maxunder>val)return(1);
  99574. }
  99575. }
  99576. }
  99577. if(info->maxover*info->maxover/n>info->maxerr)return(0);
  99578. if(info->maxunder*info->maxunder/n>info->maxerr)return(0);
  99579. if(mse/n>info->maxerr)return(1);
  99580. return(0);
  99581. }
  99582. static int post_Y(int *A,int *B,int pos){
  99583. if(A[pos]<0)
  99584. return B[pos];
  99585. if(B[pos]<0)
  99586. return A[pos];
  99587. return (A[pos]+B[pos])>>1;
  99588. }
  99589. int *floor1_fit(vorbis_block *vb,void *look_,
  99590. const float *logmdct, /* in */
  99591. const float *logmask){
  99592. long i,j;
  99593. vorbis_look_floor1 *look = (vorbis_look_floor1*) look_;
  99594. vorbis_info_floor1 *info=look->vi;
  99595. long n=look->n;
  99596. long posts=look->posts;
  99597. long nonzero=0;
  99598. lsfit_acc fits[VIF_POSIT+1];
  99599. int fit_valueA[VIF_POSIT+2]; /* index by range list position */
  99600. int fit_valueB[VIF_POSIT+2]; /* index by range list position */
  99601. int loneighbor[VIF_POSIT+2]; /* sorted index of range list position (+2) */
  99602. int hineighbor[VIF_POSIT+2];
  99603. int *output=NULL;
  99604. int memo[VIF_POSIT+2];
  99605. for(i=0;i<posts;i++)fit_valueA[i]=-200; /* mark all unused */
  99606. for(i=0;i<posts;i++)fit_valueB[i]=-200; /* mark all unused */
  99607. for(i=0;i<posts;i++)loneighbor[i]=0; /* 0 for the implicit 0 post */
  99608. for(i=0;i<posts;i++)hineighbor[i]=1; /* 1 for the implicit post at n */
  99609. for(i=0;i<posts;i++)memo[i]=-1; /* no neighbor yet */
  99610. if(posts==0){
  99611. nonzero+=accumulate_fit(logmask,logmdct,0,n,fits,n,info);
  99612. }else{
  99613. for(i=0;i<posts-1;i++)
  99614. nonzero+=accumulate_fit(logmask,logmdct,look->sorted_index[i],
  99615. look->sorted_index[i+1],fits+i,
  99616. n,info);
  99617. }
  99618. if(nonzero){
  99619. int y0=-200;
  99620. int y1=-200;
  99621. fit_line(fits,posts-1,&y0,&y1);
  99622. fit_valueA[0]=y0;
  99623. fit_valueB[0]=y0;
  99624. fit_valueB[1]=y1;
  99625. fit_valueA[1]=y1;
  99626. for(i=2;i<posts;i++){
  99627. int sortpos=look->reverse_index[i];
  99628. int ln=loneighbor[sortpos];
  99629. int hn=hineighbor[sortpos];
  99630. if(memo[ln]!=hn){
  99631. int lsortpos=look->reverse_index[ln];
  99632. int hsortpos=look->reverse_index[hn];
  99633. memo[ln]=hn;
  99634. {
  99635. int lx=info->postlist[ln];
  99636. int hx=info->postlist[hn];
  99637. int ly=post_Y(fit_valueA,fit_valueB,ln);
  99638. int hy=post_Y(fit_valueA,fit_valueB,hn);
  99639. if(ly==-1 || hy==-1){
  99640. exit(1);
  99641. }
  99642. if(inspect_error(lx,hx,ly,hy,logmask,logmdct,info)){
  99643. int ly0=-200;
  99644. int ly1=-200;
  99645. int hy0=-200;
  99646. int hy1=-200;
  99647. fit_line(fits+lsortpos,sortpos-lsortpos,&ly0,&ly1);
  99648. fit_line(fits+sortpos,hsortpos-sortpos,&hy0,&hy1);
  99649. fit_valueB[ln]=ly0;
  99650. if(ln==0)fit_valueA[ln]=ly0;
  99651. fit_valueA[i]=ly1;
  99652. fit_valueB[i]=hy0;
  99653. fit_valueA[hn]=hy1;
  99654. if(hn==1)fit_valueB[hn]=hy1;
  99655. if(ly1>=0 || hy0>=0){
  99656. for(j=sortpos-1;j>=0;j--)
  99657. if(hineighbor[j]==hn)
  99658. hineighbor[j]=i;
  99659. else
  99660. break;
  99661. for(j=sortpos+1;j<posts;j++)
  99662. if(loneighbor[j]==ln)
  99663. loneighbor[j]=i;
  99664. else
  99665. break;
  99666. }
  99667. }else{
  99668. fit_valueA[i]=-200;
  99669. fit_valueB[i]=-200;
  99670. }
  99671. }
  99672. }
  99673. }
  99674. output=(int*)_vorbis_block_alloc(vb,sizeof(*output)*posts);
  99675. output[0]=post_Y(fit_valueA,fit_valueB,0);
  99676. output[1]=post_Y(fit_valueA,fit_valueB,1);
  99677. for(i=2;i<posts;i++){
  99678. int ln=look->loneighbor[i-2];
  99679. int hn=look->hineighbor[i-2];
  99680. int x0=info->postlist[ln];
  99681. int x1=info->postlist[hn];
  99682. int y0=output[ln];
  99683. int y1=output[hn];
  99684. int predicted=render_point(x0,x1,y0,y1,info->postlist[i]);
  99685. int vx=post_Y(fit_valueA,fit_valueB,i);
  99686. if(vx>=0 && predicted!=vx){
  99687. output[i]=vx;
  99688. }else{
  99689. output[i]= predicted|0x8000;
  99690. }
  99691. }
  99692. }
  99693. return(output);
  99694. }
  99695. int *floor1_interpolate_fit(vorbis_block *vb,void *look_,
  99696. int *A,int *B,
  99697. int del){
  99698. long i;
  99699. vorbis_look_floor1* look = (vorbis_look_floor1*) look_;
  99700. long posts=look->posts;
  99701. int *output=NULL;
  99702. if(A && B){
  99703. output=(int*)_vorbis_block_alloc(vb,sizeof(*output)*posts);
  99704. for(i=0;i<posts;i++){
  99705. output[i]=((65536-del)*(A[i]&0x7fff)+del*(B[i]&0x7fff)+32768)>>16;
  99706. if(A[i]&0x8000 && B[i]&0x8000)output[i]|=0x8000;
  99707. }
  99708. }
  99709. return(output);
  99710. }
  99711. int floor1_encode(oggpack_buffer *opb,vorbis_block *vb,
  99712. void*look_,
  99713. int *post,int *ilogmask){
  99714. long i,j;
  99715. vorbis_look_floor1 *look = (vorbis_look_floor1 *) look_;
  99716. vorbis_info_floor1 *info=look->vi;
  99717. long posts=look->posts;
  99718. codec_setup_info *ci=(codec_setup_info*)vb->vd->vi->codec_setup;
  99719. int out[VIF_POSIT+2];
  99720. static_codebook **sbooks=ci->book_param;
  99721. codebook *books=ci->fullbooks;
  99722. static long seq=0;
  99723. if(post){
  99724. for(i=0;i<posts;i++){
  99725. int val=post[i]&0x7fff;
  99726. switch(info->mult){
  99727. case 1: /* 1024 -> 256 */
  99728. val>>=2;
  99729. break;
  99730. case 2: /* 1024 -> 128 */
  99731. val>>=3;
  99732. break;
  99733. case 3: /* 1024 -> 86 */
  99734. val/=12;
  99735. break;
  99736. case 4: /* 1024 -> 64 */
  99737. val>>=4;
  99738. break;
  99739. }
  99740. post[i]=val | (post[i]&0x8000);
  99741. }
  99742. out[0]=post[0];
  99743. out[1]=post[1];
  99744. for(i=2;i<posts;i++){
  99745. int ln=look->loneighbor[i-2];
  99746. int hn=look->hineighbor[i-2];
  99747. int x0=info->postlist[ln];
  99748. int x1=info->postlist[hn];
  99749. int y0=post[ln];
  99750. int y1=post[hn];
  99751. int predicted=render_point(x0,x1,y0,y1,info->postlist[i]);
  99752. if((post[i]&0x8000) || (predicted==post[i])){
  99753. post[i]=predicted|0x8000; /* in case there was roundoff jitter
  99754. in interpolation */
  99755. out[i]=0;
  99756. }else{
  99757. int headroom=(look->quant_q-predicted<predicted?
  99758. look->quant_q-predicted:predicted);
  99759. int val=post[i]-predicted;
  99760. if(val<0)
  99761. if(val<-headroom)
  99762. val=headroom-val-1;
  99763. else
  99764. val=-1-(val<<1);
  99765. else
  99766. if(val>=headroom)
  99767. val= val+headroom;
  99768. else
  99769. val<<=1;
  99770. out[i]=val;
  99771. post[ln]&=0x7fff;
  99772. post[hn]&=0x7fff;
  99773. }
  99774. }
  99775. oggpack_write(opb,1,1);
  99776. look->frames++;
  99777. look->postbits+=ilog(look->quant_q-1)*2;
  99778. oggpack_write(opb,out[0],ilog(look->quant_q-1));
  99779. oggpack_write(opb,out[1],ilog(look->quant_q-1));
  99780. for(i=0,j=2;i<info->partitions;i++){
  99781. int classx=info->partitionclass[i];
  99782. int cdim=info->class_dim[classx];
  99783. int csubbits=info->class_subs[classx];
  99784. int csub=1<<csubbits;
  99785. int bookas[8]={0,0,0,0,0,0,0,0};
  99786. int cval=0;
  99787. int cshift=0;
  99788. int k,l;
  99789. if(csubbits){
  99790. int maxval[8];
  99791. for(k=0;k<csub;k++){
  99792. int booknum=info->class_subbook[classx][k];
  99793. if(booknum<0){
  99794. maxval[k]=1;
  99795. }else{
  99796. maxval[k]=sbooks[info->class_subbook[classx][k]]->entries;
  99797. }
  99798. }
  99799. for(k=0;k<cdim;k++){
  99800. for(l=0;l<csub;l++){
  99801. int val=out[j+k];
  99802. if(val<maxval[l]){
  99803. bookas[k]=l;
  99804. break;
  99805. }
  99806. }
  99807. cval|= bookas[k]<<cshift;
  99808. cshift+=csubbits;
  99809. }
  99810. look->phrasebits+=
  99811. vorbis_book_encode(books+info->class_book[classx],cval,opb);
  99812. #ifdef TRAIN_FLOOR1
  99813. {
  99814. FILE *of;
  99815. char buffer[80];
  99816. sprintf(buffer,"line_%dx%ld_class%d.vqd",
  99817. vb->pcmend/2,posts-2,class);
  99818. of=fopen(buffer,"a");
  99819. fprintf(of,"%d\n",cval);
  99820. fclose(of);
  99821. }
  99822. #endif
  99823. }
  99824. for(k=0;k<cdim;k++){
  99825. int book=info->class_subbook[classx][bookas[k]];
  99826. if(book>=0){
  99827. if(out[j+k]<(books+book)->entries)
  99828. look->postbits+=vorbis_book_encode(books+book,
  99829. out[j+k],opb);
  99830. #ifdef TRAIN_FLOOR1
  99831. {
  99832. FILE *of;
  99833. char buffer[80];
  99834. sprintf(buffer,"line_%dx%ld_%dsub%d.vqd",
  99835. vb->pcmend/2,posts-2,class,bookas[k]);
  99836. of=fopen(buffer,"a");
  99837. fprintf(of,"%d\n",out[j+k]);
  99838. fclose(of);
  99839. }
  99840. #endif
  99841. }
  99842. }
  99843. j+=cdim;
  99844. }
  99845. {
  99846. int hx=0;
  99847. int lx=0;
  99848. int ly=post[0]*info->mult;
  99849. for(j=1;j<look->posts;j++){
  99850. int current=look->forward_index[j];
  99851. int hy=post[current]&0x7fff;
  99852. if(hy==post[current]){
  99853. hy*=info->mult;
  99854. hx=info->postlist[current];
  99855. render_line0(lx,hx,ly,hy,ilogmask);
  99856. lx=hx;
  99857. ly=hy;
  99858. }
  99859. }
  99860. for(j=hx;j<vb->pcmend/2;j++)ilogmask[j]=ly; /* be certain */
  99861. seq++;
  99862. return(1);
  99863. }
  99864. }else{
  99865. oggpack_write(opb,0,1);
  99866. memset(ilogmask,0,vb->pcmend/2*sizeof(*ilogmask));
  99867. seq++;
  99868. return(0);
  99869. }
  99870. }
  99871. static void *floor1_inverse1(vorbis_block *vb,vorbis_look_floor *in){
  99872. vorbis_look_floor1 *look=(vorbis_look_floor1 *)in;
  99873. vorbis_info_floor1 *info=look->vi;
  99874. codec_setup_info *ci=(codec_setup_info*)vb->vd->vi->codec_setup;
  99875. int i,j,k;
  99876. codebook *books=ci->fullbooks;
  99877. if(oggpack_read(&vb->opb,1)==1){
  99878. int *fit_value=(int*)_vorbis_block_alloc(vb,(look->posts)*sizeof(*fit_value));
  99879. fit_value[0]=oggpack_read(&vb->opb,ilog(look->quant_q-1));
  99880. fit_value[1]=oggpack_read(&vb->opb,ilog(look->quant_q-1));
  99881. for(i=0,j=2;i<info->partitions;i++){
  99882. int classx=info->partitionclass[i];
  99883. int cdim=info->class_dim[classx];
  99884. int csubbits=info->class_subs[classx];
  99885. int csub=1<<csubbits;
  99886. int cval=0;
  99887. if(csubbits){
  99888. cval=vorbis_book_decode(books+info->class_book[classx],&vb->opb);
  99889. if(cval==-1)goto eop;
  99890. }
  99891. for(k=0;k<cdim;k++){
  99892. int book=info->class_subbook[classx][cval&(csub-1)];
  99893. cval>>=csubbits;
  99894. if(book>=0){
  99895. if((fit_value[j+k]=vorbis_book_decode(books+book,&vb->opb))==-1)
  99896. goto eop;
  99897. }else{
  99898. fit_value[j+k]=0;
  99899. }
  99900. }
  99901. j+=cdim;
  99902. }
  99903. for(i=2;i<look->posts;i++){
  99904. int predicted=render_point(info->postlist[look->loneighbor[i-2]],
  99905. info->postlist[look->hineighbor[i-2]],
  99906. fit_value[look->loneighbor[i-2]],
  99907. fit_value[look->hineighbor[i-2]],
  99908. info->postlist[i]);
  99909. int hiroom=look->quant_q-predicted;
  99910. int loroom=predicted;
  99911. int room=(hiroom<loroom?hiroom:loroom)<<1;
  99912. int val=fit_value[i];
  99913. if(val){
  99914. if(val>=room){
  99915. if(hiroom>loroom){
  99916. val = val-loroom;
  99917. }else{
  99918. val = -1-(val-hiroom);
  99919. }
  99920. }else{
  99921. if(val&1){
  99922. val= -((val+1)>>1);
  99923. }else{
  99924. val>>=1;
  99925. }
  99926. }
  99927. fit_value[i]=val+predicted;
  99928. fit_value[look->loneighbor[i-2]]&=0x7fff;
  99929. fit_value[look->hineighbor[i-2]]&=0x7fff;
  99930. }else{
  99931. fit_value[i]=predicted|0x8000;
  99932. }
  99933. }
  99934. return(fit_value);
  99935. }
  99936. eop:
  99937. return(NULL);
  99938. }
  99939. static int floor1_inverse2(vorbis_block *vb,vorbis_look_floor *in,void *memo,
  99940. float *out){
  99941. vorbis_look_floor1 *look=(vorbis_look_floor1 *)in;
  99942. vorbis_info_floor1 *info=look->vi;
  99943. codec_setup_info *ci=(codec_setup_info*)vb->vd->vi->codec_setup;
  99944. int n=ci->blocksizes[vb->W]/2;
  99945. int j;
  99946. if(memo){
  99947. int *fit_value=(int *)memo;
  99948. int hx=0;
  99949. int lx=0;
  99950. int ly=fit_value[0]*info->mult;
  99951. for(j=1;j<look->posts;j++){
  99952. int current=look->forward_index[j];
  99953. int hy=fit_value[current]&0x7fff;
  99954. if(hy==fit_value[current]){
  99955. hy*=info->mult;
  99956. hx=info->postlist[current];
  99957. render_line(lx,hx,ly,hy,out);
  99958. lx=hx;
  99959. ly=hy;
  99960. }
  99961. }
  99962. for(j=hx;j<n;j++)out[j]*=FLOOR1_fromdB_LOOKUP[ly]; /* be certain */
  99963. return(1);
  99964. }
  99965. memset(out,0,sizeof(*out)*n);
  99966. return(0);
  99967. }
  99968. vorbis_func_floor floor1_exportbundle={
  99969. &floor1_pack,&floor1_unpack,&floor1_look,&floor1_free_info,
  99970. &floor1_free_look,&floor1_inverse1,&floor1_inverse2
  99971. };
  99972. #endif
  99973. /*** End of inlined file: floor1.c ***/
  99974. /*** Start of inlined file: info.c ***/
  99975. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  99976. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  99977. // tasks..
  99978. #if JUCE_MSVC
  99979. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  99980. #endif
  99981. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  99982. #if JUCE_USE_OGGVORBIS
  99983. #include <stdlib.h>
  99984. #include <string.h>
  99985. #include <ctype.h>
  99986. static void _v_writestring(oggpack_buffer *o, const char *s, int bytes){
  99987. while(bytes--){
  99988. oggpack_write(o,*s++,8);
  99989. }
  99990. }
  99991. static void _v_readstring(oggpack_buffer *o,char *buf,int bytes){
  99992. while(bytes--){
  99993. *buf++=oggpack_read(o,8);
  99994. }
  99995. }
  99996. void vorbis_comment_init(vorbis_comment *vc){
  99997. memset(vc,0,sizeof(*vc));
  99998. }
  99999. void vorbis_comment_add(vorbis_comment *vc,char *comment){
  100000. vc->user_comments=(char**)_ogg_realloc(vc->user_comments,
  100001. (vc->comments+2)*sizeof(*vc->user_comments));
  100002. vc->comment_lengths=(int*)_ogg_realloc(vc->comment_lengths,
  100003. (vc->comments+2)*sizeof(*vc->comment_lengths));
  100004. vc->comment_lengths[vc->comments]=strlen(comment);
  100005. vc->user_comments[vc->comments]=(char*)_ogg_malloc(vc->comment_lengths[vc->comments]+1);
  100006. strcpy(vc->user_comments[vc->comments], comment);
  100007. vc->comments++;
  100008. vc->user_comments[vc->comments]=NULL;
  100009. }
  100010. void vorbis_comment_add_tag(vorbis_comment *vc, const char *tag, char *contents){
  100011. char *comment=(char*)alloca(strlen(tag)+strlen(contents)+2); /* +2 for = and \0 */
  100012. strcpy(comment, tag);
  100013. strcat(comment, "=");
  100014. strcat(comment, contents);
  100015. vorbis_comment_add(vc, comment);
  100016. }
  100017. static int tagcompare(const char *s1, const char *s2, int n){
  100018. int c=0;
  100019. while(c < n){
  100020. if(toupper(s1[c]) != toupper(s2[c]))
  100021. return !0;
  100022. c++;
  100023. }
  100024. return 0;
  100025. }
  100026. char *vorbis_comment_query(vorbis_comment *vc, char *tag, int count){
  100027. long i;
  100028. int found = 0;
  100029. int taglen = strlen(tag)+1; /* +1 for the = we append */
  100030. char *fulltag = (char*)alloca(taglen+ 1);
  100031. strcpy(fulltag, tag);
  100032. strcat(fulltag, "=");
  100033. for(i=0;i<vc->comments;i++){
  100034. if(!tagcompare(vc->user_comments[i], fulltag, taglen)){
  100035. if(count == found)
  100036. return vc->user_comments[i] + taglen;
  100037. else
  100038. found++;
  100039. }
  100040. }
  100041. return NULL; /* didn't find anything */
  100042. }
  100043. int vorbis_comment_query_count(vorbis_comment *vc, char *tag){
  100044. int i,count=0;
  100045. int taglen = strlen(tag)+1; /* +1 for the = we append */
  100046. char *fulltag = (char*)alloca(taglen+1);
  100047. strcpy(fulltag,tag);
  100048. strcat(fulltag, "=");
  100049. for(i=0;i<vc->comments;i++){
  100050. if(!tagcompare(vc->user_comments[i], fulltag, taglen))
  100051. count++;
  100052. }
  100053. return count;
  100054. }
  100055. void vorbis_comment_clear(vorbis_comment *vc){
  100056. if(vc){
  100057. long i;
  100058. for(i=0;i<vc->comments;i++)
  100059. if(vc->user_comments[i])_ogg_free(vc->user_comments[i]);
  100060. if(vc->user_comments)_ogg_free(vc->user_comments);
  100061. if(vc->comment_lengths)_ogg_free(vc->comment_lengths);
  100062. if(vc->vendor)_ogg_free(vc->vendor);
  100063. }
  100064. memset(vc,0,sizeof(*vc));
  100065. }
  100066. int vorbis_info_blocksize(vorbis_info *vi,int zo){
  100067. codec_setup_info *ci = (codec_setup_info*)vi->codec_setup;
  100068. return ci ? ci->blocksizes[zo] : -1;
  100069. }
  100070. void vorbis_info_init(vorbis_info *vi){
  100071. memset(vi,0,sizeof(*vi));
  100072. vi->codec_setup=_ogg_calloc(1,sizeof(codec_setup_info));
  100073. }
  100074. void vorbis_info_clear(vorbis_info *vi){
  100075. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  100076. int i;
  100077. if(ci){
  100078. for(i=0;i<ci->modes;i++)
  100079. if(ci->mode_param[i])_ogg_free(ci->mode_param[i]);
  100080. for(i=0;i<ci->maps;i++) /* unpack does the range checking */
  100081. _mapping_P[ci->map_type[i]]->free_info(ci->map_param[i]);
  100082. for(i=0;i<ci->floors;i++) /* unpack does the range checking */
  100083. _floor_P[ci->floor_type[i]]->free_info(ci->floor_param[i]);
  100084. for(i=0;i<ci->residues;i++) /* unpack does the range checking */
  100085. _residue_P[ci->residue_type[i]]->free_info(ci->residue_param[i]);
  100086. for(i=0;i<ci->books;i++){
  100087. if(ci->book_param[i]){
  100088. vorbis_staticbook_destroy(ci->book_param[i]);
  100089. }
  100090. if(ci->fullbooks)
  100091. vorbis_book_clear(ci->fullbooks+i);
  100092. }
  100093. if(ci->fullbooks)
  100094. _ogg_free(ci->fullbooks);
  100095. for(i=0;i<ci->psys;i++)
  100096. _vi_psy_free(ci->psy_param[i]);
  100097. _ogg_free(ci);
  100098. }
  100099. memset(vi,0,sizeof(*vi));
  100100. }
  100101. static int _vorbis_unpack_info(vorbis_info *vi,oggpack_buffer *opb){
  100102. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  100103. if(!ci)return(OV_EFAULT);
  100104. vi->version=oggpack_read(opb,32);
  100105. if(vi->version!=0)return(OV_EVERSION);
  100106. vi->channels=oggpack_read(opb,8);
  100107. vi->rate=oggpack_read(opb,32);
  100108. vi->bitrate_upper=oggpack_read(opb,32);
  100109. vi->bitrate_nominal=oggpack_read(opb,32);
  100110. vi->bitrate_lower=oggpack_read(opb,32);
  100111. ci->blocksizes[0]=1<<oggpack_read(opb,4);
  100112. ci->blocksizes[1]=1<<oggpack_read(opb,4);
  100113. if(vi->rate<1)goto err_out;
  100114. if(vi->channels<1)goto err_out;
  100115. if(ci->blocksizes[0]<8)goto err_out;
  100116. if(ci->blocksizes[1]<ci->blocksizes[0])goto err_out;
  100117. if(oggpack_read(opb,1)!=1)goto err_out; /* EOP check */
  100118. return(0);
  100119. err_out:
  100120. vorbis_info_clear(vi);
  100121. return(OV_EBADHEADER);
  100122. }
  100123. static int _vorbis_unpack_comment(vorbis_comment *vc,oggpack_buffer *opb){
  100124. int i;
  100125. int vendorlen=oggpack_read(opb,32);
  100126. if(vendorlen<0)goto err_out;
  100127. vc->vendor=(char*)_ogg_calloc(vendorlen+1,1);
  100128. _v_readstring(opb,vc->vendor,vendorlen);
  100129. vc->comments=oggpack_read(opb,32);
  100130. if(vc->comments<0)goto err_out;
  100131. vc->user_comments=(char**)_ogg_calloc(vc->comments+1,sizeof(*vc->user_comments));
  100132. vc->comment_lengths=(int*)_ogg_calloc(vc->comments+1, sizeof(*vc->comment_lengths));
  100133. for(i=0;i<vc->comments;i++){
  100134. int len=oggpack_read(opb,32);
  100135. if(len<0)goto err_out;
  100136. vc->comment_lengths[i]=len;
  100137. vc->user_comments[i]=(char*)_ogg_calloc(len+1,1);
  100138. _v_readstring(opb,vc->user_comments[i],len);
  100139. }
  100140. if(oggpack_read(opb,1)!=1)goto err_out; /* EOP check */
  100141. return(0);
  100142. err_out:
  100143. vorbis_comment_clear(vc);
  100144. return(OV_EBADHEADER);
  100145. }
  100146. static int _vorbis_unpack_books(vorbis_info *vi,oggpack_buffer *opb){
  100147. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  100148. int i;
  100149. if(!ci)return(OV_EFAULT);
  100150. ci->books=oggpack_read(opb,8)+1;
  100151. for(i=0;i<ci->books;i++){
  100152. ci->book_param[i]=(static_codebook*)_ogg_calloc(1,sizeof(*ci->book_param[i]));
  100153. if(vorbis_staticbook_unpack(opb,ci->book_param[i]))goto err_out;
  100154. }
  100155. {
  100156. int times=oggpack_read(opb,6)+1;
  100157. for(i=0;i<times;i++){
  100158. int test=oggpack_read(opb,16);
  100159. if(test<0 || test>=VI_TIMEB)goto err_out;
  100160. }
  100161. }
  100162. ci->floors=oggpack_read(opb,6)+1;
  100163. for(i=0;i<ci->floors;i++){
  100164. ci->floor_type[i]=oggpack_read(opb,16);
  100165. if(ci->floor_type[i]<0 || ci->floor_type[i]>=VI_FLOORB)goto err_out;
  100166. ci->floor_param[i]=_floor_P[ci->floor_type[i]]->unpack(vi,opb);
  100167. if(!ci->floor_param[i])goto err_out;
  100168. }
  100169. ci->residues=oggpack_read(opb,6)+1;
  100170. for(i=0;i<ci->residues;i++){
  100171. ci->residue_type[i]=oggpack_read(opb,16);
  100172. if(ci->residue_type[i]<0 || ci->residue_type[i]>=VI_RESB)goto err_out;
  100173. ci->residue_param[i]=_residue_P[ci->residue_type[i]]->unpack(vi,opb);
  100174. if(!ci->residue_param[i])goto err_out;
  100175. }
  100176. ci->maps=oggpack_read(opb,6)+1;
  100177. for(i=0;i<ci->maps;i++){
  100178. ci->map_type[i]=oggpack_read(opb,16);
  100179. if(ci->map_type[i]<0 || ci->map_type[i]>=VI_MAPB)goto err_out;
  100180. ci->map_param[i]=_mapping_P[ci->map_type[i]]->unpack(vi,opb);
  100181. if(!ci->map_param[i])goto err_out;
  100182. }
  100183. ci->modes=oggpack_read(opb,6)+1;
  100184. for(i=0;i<ci->modes;i++){
  100185. ci->mode_param[i]=(vorbis_info_mode*)_ogg_calloc(1,sizeof(*ci->mode_param[i]));
  100186. ci->mode_param[i]->blockflag=oggpack_read(opb,1);
  100187. ci->mode_param[i]->windowtype=oggpack_read(opb,16);
  100188. ci->mode_param[i]->transformtype=oggpack_read(opb,16);
  100189. ci->mode_param[i]->mapping=oggpack_read(opb,8);
  100190. if(ci->mode_param[i]->windowtype>=VI_WINDOWB)goto err_out;
  100191. if(ci->mode_param[i]->transformtype>=VI_WINDOWB)goto err_out;
  100192. if(ci->mode_param[i]->mapping>=ci->maps)goto err_out;
  100193. }
  100194. if(oggpack_read(opb,1)!=1)goto err_out; /* top level EOP check */
  100195. return(0);
  100196. err_out:
  100197. vorbis_info_clear(vi);
  100198. return(OV_EBADHEADER);
  100199. }
  100200. int vorbis_synthesis_headerin(vorbis_info *vi,vorbis_comment *vc,ogg_packet *op){
  100201. oggpack_buffer opb;
  100202. if(op){
  100203. oggpack_readinit(&opb,op->packet,op->bytes);
  100204. {
  100205. char buffer[6];
  100206. int packtype=oggpack_read(&opb,8);
  100207. memset(buffer,0,6);
  100208. _v_readstring(&opb,buffer,6);
  100209. if(memcmp(buffer,"vorbis",6)){
  100210. return(OV_ENOTVORBIS);
  100211. }
  100212. switch(packtype){
  100213. case 0x01: /* least significant *bit* is read first */
  100214. if(!op->b_o_s){
  100215. return(OV_EBADHEADER);
  100216. }
  100217. if(vi->rate!=0){
  100218. return(OV_EBADHEADER);
  100219. }
  100220. return(_vorbis_unpack_info(vi,&opb));
  100221. case 0x03: /* least significant *bit* is read first */
  100222. if(vi->rate==0){
  100223. return(OV_EBADHEADER);
  100224. }
  100225. return(_vorbis_unpack_comment(vc,&opb));
  100226. case 0x05: /* least significant *bit* is read first */
  100227. if(vi->rate==0 || vc->vendor==NULL){
  100228. return(OV_EBADHEADER);
  100229. }
  100230. return(_vorbis_unpack_books(vi,&opb));
  100231. default:
  100232. return(OV_EBADHEADER);
  100233. break;
  100234. }
  100235. }
  100236. }
  100237. return(OV_EBADHEADER);
  100238. }
  100239. static int _vorbis_pack_info(oggpack_buffer *opb,vorbis_info *vi){
  100240. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  100241. if(!ci)return(OV_EFAULT);
  100242. oggpack_write(opb,0x01,8);
  100243. _v_writestring(opb,"vorbis", 6);
  100244. oggpack_write(opb,0x00,32);
  100245. oggpack_write(opb,vi->channels,8);
  100246. oggpack_write(opb,vi->rate,32);
  100247. oggpack_write(opb,vi->bitrate_upper,32);
  100248. oggpack_write(opb,vi->bitrate_nominal,32);
  100249. oggpack_write(opb,vi->bitrate_lower,32);
  100250. oggpack_write(opb,ilog2(ci->blocksizes[0]),4);
  100251. oggpack_write(opb,ilog2(ci->blocksizes[1]),4);
  100252. oggpack_write(opb,1,1);
  100253. return(0);
  100254. }
  100255. static int _vorbis_pack_comment(oggpack_buffer *opb,vorbis_comment *vc){
  100256. char temp[]="Xiph.Org libVorbis I 20050304";
  100257. int bytes = strlen(temp);
  100258. oggpack_write(opb,0x03,8);
  100259. _v_writestring(opb,"vorbis", 6);
  100260. oggpack_write(opb,bytes,32);
  100261. _v_writestring(opb,temp, bytes);
  100262. oggpack_write(opb,vc->comments,32);
  100263. if(vc->comments){
  100264. int i;
  100265. for(i=0;i<vc->comments;i++){
  100266. if(vc->user_comments[i]){
  100267. oggpack_write(opb,vc->comment_lengths[i],32);
  100268. _v_writestring(opb,vc->user_comments[i], vc->comment_lengths[i]);
  100269. }else{
  100270. oggpack_write(opb,0,32);
  100271. }
  100272. }
  100273. }
  100274. oggpack_write(opb,1,1);
  100275. return(0);
  100276. }
  100277. static int _vorbis_pack_books(oggpack_buffer *opb,vorbis_info *vi){
  100278. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  100279. int i;
  100280. if(!ci)return(OV_EFAULT);
  100281. oggpack_write(opb,0x05,8);
  100282. _v_writestring(opb,"vorbis", 6);
  100283. oggpack_write(opb,ci->books-1,8);
  100284. for(i=0;i<ci->books;i++)
  100285. if(vorbis_staticbook_pack(ci->book_param[i],opb))goto err_out;
  100286. oggpack_write(opb,0,6);
  100287. oggpack_write(opb,0,16);
  100288. oggpack_write(opb,ci->floors-1,6);
  100289. for(i=0;i<ci->floors;i++){
  100290. oggpack_write(opb,ci->floor_type[i],16);
  100291. if(_floor_P[ci->floor_type[i]]->pack)
  100292. _floor_P[ci->floor_type[i]]->pack(ci->floor_param[i],opb);
  100293. else
  100294. goto err_out;
  100295. }
  100296. oggpack_write(opb,ci->residues-1,6);
  100297. for(i=0;i<ci->residues;i++){
  100298. oggpack_write(opb,ci->residue_type[i],16);
  100299. _residue_P[ci->residue_type[i]]->pack(ci->residue_param[i],opb);
  100300. }
  100301. oggpack_write(opb,ci->maps-1,6);
  100302. for(i=0;i<ci->maps;i++){
  100303. oggpack_write(opb,ci->map_type[i],16);
  100304. _mapping_P[ci->map_type[i]]->pack(vi,ci->map_param[i],opb);
  100305. }
  100306. oggpack_write(opb,ci->modes-1,6);
  100307. for(i=0;i<ci->modes;i++){
  100308. oggpack_write(opb,ci->mode_param[i]->blockflag,1);
  100309. oggpack_write(opb,ci->mode_param[i]->windowtype,16);
  100310. oggpack_write(opb,ci->mode_param[i]->transformtype,16);
  100311. oggpack_write(opb,ci->mode_param[i]->mapping,8);
  100312. }
  100313. oggpack_write(opb,1,1);
  100314. return(0);
  100315. err_out:
  100316. return(-1);
  100317. }
  100318. int vorbis_commentheader_out(vorbis_comment *vc,
  100319. ogg_packet *op){
  100320. oggpack_buffer opb;
  100321. oggpack_writeinit(&opb);
  100322. if(_vorbis_pack_comment(&opb,vc)) return OV_EIMPL;
  100323. op->packet = (unsigned char*) _ogg_malloc(oggpack_bytes(&opb));
  100324. memcpy(op->packet, opb.buffer, oggpack_bytes(&opb));
  100325. op->bytes=oggpack_bytes(&opb);
  100326. op->b_o_s=0;
  100327. op->e_o_s=0;
  100328. op->granulepos=0;
  100329. op->packetno=1;
  100330. return 0;
  100331. }
  100332. int vorbis_analysis_headerout(vorbis_dsp_state *v,
  100333. vorbis_comment *vc,
  100334. ogg_packet *op,
  100335. ogg_packet *op_comm,
  100336. ogg_packet *op_code){
  100337. int ret=OV_EIMPL;
  100338. vorbis_info *vi=v->vi;
  100339. oggpack_buffer opb;
  100340. private_state *b=(private_state*)v->backend_state;
  100341. if(!b){
  100342. ret=OV_EFAULT;
  100343. goto err_out;
  100344. }
  100345. oggpack_writeinit(&opb);
  100346. if(_vorbis_pack_info(&opb,vi))goto err_out;
  100347. if(b->header)_ogg_free(b->header);
  100348. b->header=(unsigned char*) _ogg_malloc(oggpack_bytes(&opb));
  100349. memcpy(b->header,opb.buffer,oggpack_bytes(&opb));
  100350. op->packet=b->header;
  100351. op->bytes=oggpack_bytes(&opb);
  100352. op->b_o_s=1;
  100353. op->e_o_s=0;
  100354. op->granulepos=0;
  100355. op->packetno=0;
  100356. oggpack_reset(&opb);
  100357. if(_vorbis_pack_comment(&opb,vc))goto err_out;
  100358. if(b->header1)_ogg_free(b->header1);
  100359. b->header1=(unsigned char*) _ogg_malloc(oggpack_bytes(&opb));
  100360. memcpy(b->header1,opb.buffer,oggpack_bytes(&opb));
  100361. op_comm->packet=b->header1;
  100362. op_comm->bytes=oggpack_bytes(&opb);
  100363. op_comm->b_o_s=0;
  100364. op_comm->e_o_s=0;
  100365. op_comm->granulepos=0;
  100366. op_comm->packetno=1;
  100367. oggpack_reset(&opb);
  100368. if(_vorbis_pack_books(&opb,vi))goto err_out;
  100369. if(b->header2)_ogg_free(b->header2);
  100370. b->header2=(unsigned char*) _ogg_malloc(oggpack_bytes(&opb));
  100371. memcpy(b->header2,opb.buffer,oggpack_bytes(&opb));
  100372. op_code->packet=b->header2;
  100373. op_code->bytes=oggpack_bytes(&opb);
  100374. op_code->b_o_s=0;
  100375. op_code->e_o_s=0;
  100376. op_code->granulepos=0;
  100377. op_code->packetno=2;
  100378. oggpack_writeclear(&opb);
  100379. return(0);
  100380. err_out:
  100381. oggpack_writeclear(&opb);
  100382. memset(op,0,sizeof(*op));
  100383. memset(op_comm,0,sizeof(*op_comm));
  100384. memset(op_code,0,sizeof(*op_code));
  100385. if(b->header)_ogg_free(b->header);
  100386. if(b->header1)_ogg_free(b->header1);
  100387. if(b->header2)_ogg_free(b->header2);
  100388. b->header=NULL;
  100389. b->header1=NULL;
  100390. b->header2=NULL;
  100391. return(ret);
  100392. }
  100393. double vorbis_granule_time(vorbis_dsp_state *v,ogg_int64_t granulepos){
  100394. if(granulepos>=0)
  100395. return((double)granulepos/v->vi->rate);
  100396. return(-1);
  100397. }
  100398. #endif
  100399. /*** End of inlined file: info.c ***/
  100400. /*** Start of inlined file: lpc.c ***/
  100401. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  100402. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  100403. // tasks..
  100404. #if JUCE_MSVC
  100405. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  100406. #endif
  100407. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  100408. #if JUCE_USE_OGGVORBIS
  100409. #include <stdlib.h>
  100410. #include <string.h>
  100411. #include <math.h>
  100412. float vorbis_lpc_from_data(float *data,float *lpci,int n,int m){
  100413. double *aut=(double*)alloca(sizeof(*aut)*(m+1));
  100414. double *lpc=(double*)alloca(sizeof(*lpc)*(m));
  100415. double error;
  100416. int i,j;
  100417. j=m+1;
  100418. while(j--){
  100419. double d=0; /* double needed for accumulator depth */
  100420. for(i=j;i<n;i++)d+=(double)data[i]*data[i-j];
  100421. aut[j]=d;
  100422. }
  100423. error=aut[0];
  100424. for(i=0;i<m;i++){
  100425. double r= -aut[i+1];
  100426. if(error==0){
  100427. memset(lpci,0,m*sizeof(*lpci));
  100428. return 0;
  100429. }
  100430. for(j=0;j<i;j++)r-=lpc[j]*aut[i-j];
  100431. r/=error;
  100432. lpc[i]=r;
  100433. for(j=0;j<i/2;j++){
  100434. double tmp=lpc[j];
  100435. lpc[j]+=r*lpc[i-1-j];
  100436. lpc[i-1-j]+=r*tmp;
  100437. }
  100438. if(i%2)lpc[j]+=lpc[j]*r;
  100439. error*=1.f-r*r;
  100440. }
  100441. for(j=0;j<m;j++)lpci[j]=(float)lpc[j];
  100442. return error;
  100443. }
  100444. void vorbis_lpc_predict(float *coeff,float *prime,int m,
  100445. float *data,long n){
  100446. long i,j,o,p;
  100447. float y;
  100448. float *work=(float*)alloca(sizeof(*work)*(m+n));
  100449. if(!prime)
  100450. for(i=0;i<m;i++)
  100451. work[i]=0.f;
  100452. else
  100453. for(i=0;i<m;i++)
  100454. work[i]=prime[i];
  100455. for(i=0;i<n;i++){
  100456. y=0;
  100457. o=i;
  100458. p=m;
  100459. for(j=0;j<m;j++)
  100460. y-=work[o++]*coeff[--p];
  100461. data[i]=work[o]=y;
  100462. }
  100463. }
  100464. #endif
  100465. /*** End of inlined file: lpc.c ***/
  100466. /*** Start of inlined file: lsp.c ***/
  100467. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  100468. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  100469. // tasks..
  100470. #if JUCE_MSVC
  100471. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  100472. #endif
  100473. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  100474. #if JUCE_USE_OGGVORBIS
  100475. #include <math.h>
  100476. #include <string.h>
  100477. #include <stdlib.h>
  100478. /*** Start of inlined file: lookup.h ***/
  100479. #ifndef _V_LOOKUP_H_
  100480. #ifdef FLOAT_LOOKUP
  100481. extern float vorbis_coslook(float a);
  100482. extern float vorbis_invsqlook(float a);
  100483. extern float vorbis_invsq2explook(int a);
  100484. extern float vorbis_fromdBlook(float a);
  100485. #endif
  100486. #ifdef INT_LOOKUP
  100487. extern long vorbis_invsqlook_i(long a,long e);
  100488. extern long vorbis_coslook_i(long a);
  100489. extern float vorbis_fromdBlook_i(long a);
  100490. #endif
  100491. #endif
  100492. /*** End of inlined file: lookup.h ***/
  100493. #define FLOAT_LOOKUP
  100494. #undef INT_LOOKUP
  100495. #ifdef FLOAT_LOOKUP
  100496. /*** Start of inlined file: lookup.c ***/
  100497. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  100498. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  100499. // tasks..
  100500. #if JUCE_MSVC
  100501. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  100502. #endif
  100503. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  100504. #if JUCE_USE_OGGVORBIS
  100505. #include <math.h>
  100506. /*** Start of inlined file: lookup.h ***/
  100507. #ifndef _V_LOOKUP_H_
  100508. #ifdef FLOAT_LOOKUP
  100509. extern float vorbis_coslook(float a);
  100510. extern float vorbis_invsqlook(float a);
  100511. extern float vorbis_invsq2explook(int a);
  100512. extern float vorbis_fromdBlook(float a);
  100513. #endif
  100514. #ifdef INT_LOOKUP
  100515. extern long vorbis_invsqlook_i(long a,long e);
  100516. extern long vorbis_coslook_i(long a);
  100517. extern float vorbis_fromdBlook_i(long a);
  100518. #endif
  100519. #endif
  100520. /*** End of inlined file: lookup.h ***/
  100521. /*** Start of inlined file: lookup_data.h ***/
  100522. #ifndef _V_LOOKUP_DATA_H_
  100523. #ifdef FLOAT_LOOKUP
  100524. #define COS_LOOKUP_SZ 128
  100525. static float COS_LOOKUP[COS_LOOKUP_SZ+1]={
  100526. +1.0000000000000f,+0.9996988186962f,+0.9987954562052f,+0.9972904566787f,
  100527. +0.9951847266722f,+0.9924795345987f,+0.9891765099648f,+0.9852776423889f,
  100528. +0.9807852804032f,+0.9757021300385f,+0.9700312531945f,+0.9637760657954f,
  100529. +0.9569403357322f,+0.9495281805930f,+0.9415440651830f,+0.9329927988347f,
  100530. +0.9238795325113f,+0.9142097557035f,+0.9039892931234f,+0.8932243011955f,
  100531. +0.8819212643484f,+0.8700869911087f,+0.8577286100003f,+0.8448535652497f,
  100532. +0.8314696123025f,+0.8175848131516f,+0.8032075314806f,+0.7883464276266f,
  100533. +0.7730104533627f,+0.7572088465065f,+0.7409511253550f,+0.7242470829515f,
  100534. +0.7071067811865f,+0.6895405447371f,+0.6715589548470f,+0.6531728429538f,
  100535. +0.6343932841636f,+0.6152315905806f,+0.5956993044924f,+0.5758081914178f,
  100536. +0.5555702330196f,+0.5349976198871f,+0.5141027441932f,+0.4928981922298f,
  100537. +0.4713967368260f,+0.4496113296546f,+0.4275550934303f,+0.4052413140050f,
  100538. +0.3826834323651f,+0.3598950365350f,+0.3368898533922f,+0.3136817403989f,
  100539. +0.2902846772545f,+0.2667127574749f,+0.2429801799033f,+0.2191012401569f,
  100540. +0.1950903220161f,+0.1709618887603f,+0.1467304744554f,+0.1224106751992f,
  100541. +0.0980171403296f,+0.0735645635997f,+0.0490676743274f,+0.0245412285229f,
  100542. +0.0000000000000f,-0.0245412285229f,-0.0490676743274f,-0.0735645635997f,
  100543. -0.0980171403296f,-0.1224106751992f,-0.1467304744554f,-0.1709618887603f,
  100544. -0.1950903220161f,-0.2191012401569f,-0.2429801799033f,-0.2667127574749f,
  100545. -0.2902846772545f,-0.3136817403989f,-0.3368898533922f,-0.3598950365350f,
  100546. -0.3826834323651f,-0.4052413140050f,-0.4275550934303f,-0.4496113296546f,
  100547. -0.4713967368260f,-0.4928981922298f,-0.5141027441932f,-0.5349976198871f,
  100548. -0.5555702330196f,-0.5758081914178f,-0.5956993044924f,-0.6152315905806f,
  100549. -0.6343932841636f,-0.6531728429538f,-0.6715589548470f,-0.6895405447371f,
  100550. -0.7071067811865f,-0.7242470829515f,-0.7409511253550f,-0.7572088465065f,
  100551. -0.7730104533627f,-0.7883464276266f,-0.8032075314806f,-0.8175848131516f,
  100552. -0.8314696123025f,-0.8448535652497f,-0.8577286100003f,-0.8700869911087f,
  100553. -0.8819212643484f,-0.8932243011955f,-0.9039892931234f,-0.9142097557035f,
  100554. -0.9238795325113f,-0.9329927988347f,-0.9415440651830f,-0.9495281805930f,
  100555. -0.9569403357322f,-0.9637760657954f,-0.9700312531945f,-0.9757021300385f,
  100556. -0.9807852804032f,-0.9852776423889f,-0.9891765099648f,-0.9924795345987f,
  100557. -0.9951847266722f,-0.9972904566787f,-0.9987954562052f,-0.9996988186962f,
  100558. -1.0000000000000f,
  100559. };
  100560. #define INVSQ_LOOKUP_SZ 32
  100561. static float INVSQ_LOOKUP[INVSQ_LOOKUP_SZ+1]={
  100562. 1.414213562373f,1.392621247646f,1.371988681140f,1.352246807566f,
  100563. 1.333333333333f,1.315191898443f,1.297771369046f,1.281025230441f,
  100564. 1.264911064067f,1.249390095109f,1.234426799697f,1.219988562661f,
  100565. 1.206045378311f,1.192569588000f,1.179535649239f,1.166919931983f,
  100566. 1.154700538379f,1.142857142857f,1.131370849898f,1.120224067222f,
  100567. 1.109400392450f,1.098884511590f,1.088662107904f,1.078719779941f,
  100568. 1.069044967650f,1.059625885652f,1.050451462878f,1.041511287847f,
  100569. 1.032795558989f,1.024295039463f,1.016001016002f,1.007905261358f,
  100570. 1.000000000000f,
  100571. };
  100572. #define INVSQ2EXP_LOOKUP_MIN (-32)
  100573. #define INVSQ2EXP_LOOKUP_MAX 32
  100574. static float INVSQ2EXP_LOOKUP[INVSQ2EXP_LOOKUP_MAX-\
  100575. INVSQ2EXP_LOOKUP_MIN+1]={
  100576. 65536.f, 46340.95001f, 32768.f, 23170.47501f,
  100577. 16384.f, 11585.2375f, 8192.f, 5792.618751f,
  100578. 4096.f, 2896.309376f, 2048.f, 1448.154688f,
  100579. 1024.f, 724.0773439f, 512.f, 362.038672f,
  100580. 256.f, 181.019336f, 128.f, 90.50966799f,
  100581. 64.f, 45.254834f, 32.f, 22.627417f,
  100582. 16.f, 11.3137085f, 8.f, 5.656854249f,
  100583. 4.f, 2.828427125f, 2.f, 1.414213562f,
  100584. 1.f, 0.7071067812f, 0.5f, 0.3535533906f,
  100585. 0.25f, 0.1767766953f, 0.125f, 0.08838834765f,
  100586. 0.0625f, 0.04419417382f, 0.03125f, 0.02209708691f,
  100587. 0.015625f, 0.01104854346f, 0.0078125f, 0.005524271728f,
  100588. 0.00390625f, 0.002762135864f, 0.001953125f, 0.001381067932f,
  100589. 0.0009765625f, 0.000690533966f, 0.00048828125f, 0.000345266983f,
  100590. 0.000244140625f,0.0001726334915f,0.0001220703125f,8.631674575e-05f,
  100591. 6.103515625e-05f,4.315837288e-05f,3.051757812e-05f,2.157918644e-05f,
  100592. 1.525878906e-05f,
  100593. };
  100594. #endif
  100595. #define FROMdB_LOOKUP_SZ 35
  100596. #define FROMdB2_LOOKUP_SZ 32
  100597. #define FROMdB_SHIFT 5
  100598. #define FROMdB2_SHIFT 3
  100599. #define FROMdB2_MASK 31
  100600. static float FROMdB_LOOKUP[FROMdB_LOOKUP_SZ]={
  100601. 1.f, 0.6309573445f, 0.3981071706f, 0.2511886432f,
  100602. 0.1584893192f, 0.1f, 0.06309573445f, 0.03981071706f,
  100603. 0.02511886432f, 0.01584893192f, 0.01f, 0.006309573445f,
  100604. 0.003981071706f, 0.002511886432f, 0.001584893192f, 0.001f,
  100605. 0.0006309573445f,0.0003981071706f,0.0002511886432f,0.0001584893192f,
  100606. 0.0001f,6.309573445e-05f,3.981071706e-05f,2.511886432e-05f,
  100607. 1.584893192e-05f, 1e-05f,6.309573445e-06f,3.981071706e-06f,
  100608. 2.511886432e-06f,1.584893192e-06f, 1e-06f,6.309573445e-07f,
  100609. 3.981071706e-07f,2.511886432e-07f,1.584893192e-07f,
  100610. };
  100611. static float FROMdB2_LOOKUP[FROMdB2_LOOKUP_SZ]={
  100612. 0.9928302478f, 0.9786445908f, 0.9646616199f, 0.9508784391f,
  100613. 0.9372921937f, 0.92390007f, 0.9106992942f, 0.8976871324f,
  100614. 0.8848608897f, 0.8722179097f, 0.8597555737f, 0.8474713009f,
  100615. 0.835362547f, 0.8234268041f, 0.8116616003f, 0.8000644989f,
  100616. 0.7886330981f, 0.7773650302f, 0.7662579617f, 0.755309592f,
  100617. 0.7445176537f, 0.7338799116f, 0.7233941627f, 0.7130582353f,
  100618. 0.7028699885f, 0.6928273125f, 0.6829281272f, 0.6731703824f,
  100619. 0.6635520573f, 0.6540711597f, 0.6447257262f, 0.6355138211f,
  100620. };
  100621. #ifdef INT_LOOKUP
  100622. #define INVSQ_LOOKUP_I_SHIFT 10
  100623. #define INVSQ_LOOKUP_I_MASK 1023
  100624. static long INVSQ_LOOKUP_I[64+1]={
  100625. 92682l, 91966l, 91267l, 90583l,
  100626. 89915l, 89261l, 88621l, 87995l,
  100627. 87381l, 86781l, 86192l, 85616l,
  100628. 85051l, 84497l, 83953l, 83420l,
  100629. 82897l, 82384l, 81880l, 81385l,
  100630. 80899l, 80422l, 79953l, 79492l,
  100631. 79039l, 78594l, 78156l, 77726l,
  100632. 77302l, 76885l, 76475l, 76072l,
  100633. 75674l, 75283l, 74898l, 74519l,
  100634. 74146l, 73778l, 73415l, 73058l,
  100635. 72706l, 72359l, 72016l, 71679l,
  100636. 71347l, 71019l, 70695l, 70376l,
  100637. 70061l, 69750l, 69444l, 69141l,
  100638. 68842l, 68548l, 68256l, 67969l,
  100639. 67685l, 67405l, 67128l, 66855l,
  100640. 66585l, 66318l, 66054l, 65794l,
  100641. 65536l,
  100642. };
  100643. #define COS_LOOKUP_I_SHIFT 9
  100644. #define COS_LOOKUP_I_MASK 511
  100645. #define COS_LOOKUP_I_SZ 128
  100646. static long COS_LOOKUP_I[COS_LOOKUP_I_SZ+1]={
  100647. 16384l, 16379l, 16364l, 16340l,
  100648. 16305l, 16261l, 16207l, 16143l,
  100649. 16069l, 15986l, 15893l, 15791l,
  100650. 15679l, 15557l, 15426l, 15286l,
  100651. 15137l, 14978l, 14811l, 14635l,
  100652. 14449l, 14256l, 14053l, 13842l,
  100653. 13623l, 13395l, 13160l, 12916l,
  100654. 12665l, 12406l, 12140l, 11866l,
  100655. 11585l, 11297l, 11003l, 10702l,
  100656. 10394l, 10080l, 9760l, 9434l,
  100657. 9102l, 8765l, 8423l, 8076l,
  100658. 7723l, 7366l, 7005l, 6639l,
  100659. 6270l, 5897l, 5520l, 5139l,
  100660. 4756l, 4370l, 3981l, 3590l,
  100661. 3196l, 2801l, 2404l, 2006l,
  100662. 1606l, 1205l, 804l, 402l,
  100663. 0l, -401l, -803l, -1204l,
  100664. -1605l, -2005l, -2403l, -2800l,
  100665. -3195l, -3589l, -3980l, -4369l,
  100666. -4755l, -5138l, -5519l, -5896l,
  100667. -6269l, -6638l, -7004l, -7365l,
  100668. -7722l, -8075l, -8422l, -8764l,
  100669. -9101l, -9433l, -9759l, -10079l,
  100670. -10393l, -10701l, -11002l, -11296l,
  100671. -11584l, -11865l, -12139l, -12405l,
  100672. -12664l, -12915l, -13159l, -13394l,
  100673. -13622l, -13841l, -14052l, -14255l,
  100674. -14448l, -14634l, -14810l, -14977l,
  100675. -15136l, -15285l, -15425l, -15556l,
  100676. -15678l, -15790l, -15892l, -15985l,
  100677. -16068l, -16142l, -16206l, -16260l,
  100678. -16304l, -16339l, -16363l, -16378l,
  100679. -16383l,
  100680. };
  100681. #endif
  100682. #endif
  100683. /*** End of inlined file: lookup_data.h ***/
  100684. #ifdef FLOAT_LOOKUP
  100685. float vorbis_coslook(float a){
  100686. double d=a*(.31830989*(float)COS_LOOKUP_SZ);
  100687. int i=vorbis_ftoi(d-.5);
  100688. return COS_LOOKUP[i]+ (d-i)*(COS_LOOKUP[i+1]-COS_LOOKUP[i]);
  100689. }
  100690. float vorbis_invsqlook(float a){
  100691. double d=a*(2.f*(float)INVSQ_LOOKUP_SZ)-(float)INVSQ_LOOKUP_SZ;
  100692. int i=vorbis_ftoi(d-.5f);
  100693. return INVSQ_LOOKUP[i]+ (d-i)*(INVSQ_LOOKUP[i+1]-INVSQ_LOOKUP[i]);
  100694. }
  100695. float vorbis_invsq2explook(int a){
  100696. return INVSQ2EXP_LOOKUP[a-INVSQ2EXP_LOOKUP_MIN];
  100697. }
  100698. #include <stdio.h>
  100699. float vorbis_fromdBlook(float a){
  100700. int i=vorbis_ftoi(a*((float)(-(1<<FROMdB2_SHIFT)))-.5f);
  100701. return (i<0)?1.f:
  100702. ((i>=(FROMdB_LOOKUP_SZ<<FROMdB_SHIFT))?0.f:
  100703. FROMdB_LOOKUP[i>>FROMdB_SHIFT]*FROMdB2_LOOKUP[i&FROMdB2_MASK]);
  100704. }
  100705. #endif
  100706. #ifdef INT_LOOKUP
  100707. long vorbis_invsqlook_i(long a,long e){
  100708. long i=(a&0x7fff)>>(INVSQ_LOOKUP_I_SHIFT-1);
  100709. long d=(a&INVSQ_LOOKUP_I_MASK)<<(16-INVSQ_LOOKUP_I_SHIFT); /* 0.16 */
  100710. long val=INVSQ_LOOKUP_I[i]- /* 1.16 */
  100711. (((INVSQ_LOOKUP_I[i]-INVSQ_LOOKUP_I[i+1])* /* 0.16 */
  100712. d)>>16); /* result 1.16 */
  100713. e+=32;
  100714. if(e&1)val=(val*5792)>>13; /* multiply val by 1/sqrt(2) */
  100715. e=(e>>1)-8;
  100716. return(val>>e);
  100717. }
  100718. float vorbis_fromdBlook_i(long a){
  100719. int i=(-a)>>(12-FROMdB2_SHIFT);
  100720. return (i<0)?1.f:
  100721. ((i>=(FROMdB_LOOKUP_SZ<<FROMdB_SHIFT))?0.f:
  100722. FROMdB_LOOKUP[i>>FROMdB_SHIFT]*FROMdB2_LOOKUP[i&FROMdB2_MASK]);
  100723. }
  100724. long vorbis_coslook_i(long a){
  100725. int i=a>>COS_LOOKUP_I_SHIFT;
  100726. int d=a&COS_LOOKUP_I_MASK;
  100727. return COS_LOOKUP_I[i]- ((d*(COS_LOOKUP_I[i]-COS_LOOKUP_I[i+1]))>>
  100728. COS_LOOKUP_I_SHIFT);
  100729. }
  100730. #endif
  100731. #endif
  100732. /*** End of inlined file: lookup.c ***/
  100733. /* catch this in the build system; we #include for
  100734. compilers (like gcc) that can't inline across
  100735. modules */
  100736. void vorbis_lsp_to_curve(float *curve,int *map,int n,int ln,float *lsp,int m,
  100737. float amp,float ampoffset){
  100738. int i;
  100739. float wdel=M_PI/ln;
  100740. vorbis_fpu_control fpu;
  100741. (void) fpu; // to avoid an unused variable warning
  100742. vorbis_fpu_setround(&fpu);
  100743. for(i=0;i<m;i++)lsp[i]=vorbis_coslook(lsp[i]);
  100744. i=0;
  100745. while(i<n){
  100746. int k=map[i];
  100747. int qexp;
  100748. float p=.7071067812f;
  100749. float q=.7071067812f;
  100750. float w=vorbis_coslook(wdel*k);
  100751. float *ftmp=lsp;
  100752. int c=m>>1;
  100753. do{
  100754. q*=ftmp[0]-w;
  100755. p*=ftmp[1]-w;
  100756. ftmp+=2;
  100757. }while(--c);
  100758. if(m&1){
  100759. q*=ftmp[0]-w;
  100760. q*=q;
  100761. p*=p*(1.f-w*w);
  100762. }else{
  100763. q*=q*(1.f+w);
  100764. p*=p*(1.f-w);
  100765. }
  100766. q=frexp(p+q,&qexp);
  100767. q=vorbis_fromdBlook(amp*
  100768. vorbis_invsqlook(q)*
  100769. vorbis_invsq2explook(qexp+m)-
  100770. ampoffset);
  100771. do{
  100772. curve[i++]*=q;
  100773. }while(map[i]==k);
  100774. }
  100775. vorbis_fpu_restore(fpu);
  100776. }
  100777. #else
  100778. #ifdef INT_LOOKUP
  100779. /*** Start of inlined file: lookup.c ***/
  100780. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  100781. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  100782. // tasks..
  100783. #if JUCE_MSVC
  100784. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  100785. #endif
  100786. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  100787. #if JUCE_USE_OGGVORBIS
  100788. #include <math.h>
  100789. /*** Start of inlined file: lookup.h ***/
  100790. #ifndef _V_LOOKUP_H_
  100791. #ifdef FLOAT_LOOKUP
  100792. extern float vorbis_coslook(float a);
  100793. extern float vorbis_invsqlook(float a);
  100794. extern float vorbis_invsq2explook(int a);
  100795. extern float vorbis_fromdBlook(float a);
  100796. #endif
  100797. #ifdef INT_LOOKUP
  100798. extern long vorbis_invsqlook_i(long a,long e);
  100799. extern long vorbis_coslook_i(long a);
  100800. extern float vorbis_fromdBlook_i(long a);
  100801. #endif
  100802. #endif
  100803. /*** End of inlined file: lookup.h ***/
  100804. /*** Start of inlined file: lookup_data.h ***/
  100805. #ifndef _V_LOOKUP_DATA_H_
  100806. #ifdef FLOAT_LOOKUP
  100807. #define COS_LOOKUP_SZ 128
  100808. static float COS_LOOKUP[COS_LOOKUP_SZ+1]={
  100809. +1.0000000000000f,+0.9996988186962f,+0.9987954562052f,+0.9972904566787f,
  100810. +0.9951847266722f,+0.9924795345987f,+0.9891765099648f,+0.9852776423889f,
  100811. +0.9807852804032f,+0.9757021300385f,+0.9700312531945f,+0.9637760657954f,
  100812. +0.9569403357322f,+0.9495281805930f,+0.9415440651830f,+0.9329927988347f,
  100813. +0.9238795325113f,+0.9142097557035f,+0.9039892931234f,+0.8932243011955f,
  100814. +0.8819212643484f,+0.8700869911087f,+0.8577286100003f,+0.8448535652497f,
  100815. +0.8314696123025f,+0.8175848131516f,+0.8032075314806f,+0.7883464276266f,
  100816. +0.7730104533627f,+0.7572088465065f,+0.7409511253550f,+0.7242470829515f,
  100817. +0.7071067811865f,+0.6895405447371f,+0.6715589548470f,+0.6531728429538f,
  100818. +0.6343932841636f,+0.6152315905806f,+0.5956993044924f,+0.5758081914178f,
  100819. +0.5555702330196f,+0.5349976198871f,+0.5141027441932f,+0.4928981922298f,
  100820. +0.4713967368260f,+0.4496113296546f,+0.4275550934303f,+0.4052413140050f,
  100821. +0.3826834323651f,+0.3598950365350f,+0.3368898533922f,+0.3136817403989f,
  100822. +0.2902846772545f,+0.2667127574749f,+0.2429801799033f,+0.2191012401569f,
  100823. +0.1950903220161f,+0.1709618887603f,+0.1467304744554f,+0.1224106751992f,
  100824. +0.0980171403296f,+0.0735645635997f,+0.0490676743274f,+0.0245412285229f,
  100825. +0.0000000000000f,-0.0245412285229f,-0.0490676743274f,-0.0735645635997f,
  100826. -0.0980171403296f,-0.1224106751992f,-0.1467304744554f,-0.1709618887603f,
  100827. -0.1950903220161f,-0.2191012401569f,-0.2429801799033f,-0.2667127574749f,
  100828. -0.2902846772545f,-0.3136817403989f,-0.3368898533922f,-0.3598950365350f,
  100829. -0.3826834323651f,-0.4052413140050f,-0.4275550934303f,-0.4496113296546f,
  100830. -0.4713967368260f,-0.4928981922298f,-0.5141027441932f,-0.5349976198871f,
  100831. -0.5555702330196f,-0.5758081914178f,-0.5956993044924f,-0.6152315905806f,
  100832. -0.6343932841636f,-0.6531728429538f,-0.6715589548470f,-0.6895405447371f,
  100833. -0.7071067811865f,-0.7242470829515f,-0.7409511253550f,-0.7572088465065f,
  100834. -0.7730104533627f,-0.7883464276266f,-0.8032075314806f,-0.8175848131516f,
  100835. -0.8314696123025f,-0.8448535652497f,-0.8577286100003f,-0.8700869911087f,
  100836. -0.8819212643484f,-0.8932243011955f,-0.9039892931234f,-0.9142097557035f,
  100837. -0.9238795325113f,-0.9329927988347f,-0.9415440651830f,-0.9495281805930f,
  100838. -0.9569403357322f,-0.9637760657954f,-0.9700312531945f,-0.9757021300385f,
  100839. -0.9807852804032f,-0.9852776423889f,-0.9891765099648f,-0.9924795345987f,
  100840. -0.9951847266722f,-0.9972904566787f,-0.9987954562052f,-0.9996988186962f,
  100841. -1.0000000000000f,
  100842. };
  100843. #define INVSQ_LOOKUP_SZ 32
  100844. static float INVSQ_LOOKUP[INVSQ_LOOKUP_SZ+1]={
  100845. 1.414213562373f,1.392621247646f,1.371988681140f,1.352246807566f,
  100846. 1.333333333333f,1.315191898443f,1.297771369046f,1.281025230441f,
  100847. 1.264911064067f,1.249390095109f,1.234426799697f,1.219988562661f,
  100848. 1.206045378311f,1.192569588000f,1.179535649239f,1.166919931983f,
  100849. 1.154700538379f,1.142857142857f,1.131370849898f,1.120224067222f,
  100850. 1.109400392450f,1.098884511590f,1.088662107904f,1.078719779941f,
  100851. 1.069044967650f,1.059625885652f,1.050451462878f,1.041511287847f,
  100852. 1.032795558989f,1.024295039463f,1.016001016002f,1.007905261358f,
  100853. 1.000000000000f,
  100854. };
  100855. #define INVSQ2EXP_LOOKUP_MIN (-32)
  100856. #define INVSQ2EXP_LOOKUP_MAX 32
  100857. static float INVSQ2EXP_LOOKUP[INVSQ2EXP_LOOKUP_MAX-\
  100858. INVSQ2EXP_LOOKUP_MIN+1]={
  100859. 65536.f, 46340.95001f, 32768.f, 23170.47501f,
  100860. 16384.f, 11585.2375f, 8192.f, 5792.618751f,
  100861. 4096.f, 2896.309376f, 2048.f, 1448.154688f,
  100862. 1024.f, 724.0773439f, 512.f, 362.038672f,
  100863. 256.f, 181.019336f, 128.f, 90.50966799f,
  100864. 64.f, 45.254834f, 32.f, 22.627417f,
  100865. 16.f, 11.3137085f, 8.f, 5.656854249f,
  100866. 4.f, 2.828427125f, 2.f, 1.414213562f,
  100867. 1.f, 0.7071067812f, 0.5f, 0.3535533906f,
  100868. 0.25f, 0.1767766953f, 0.125f, 0.08838834765f,
  100869. 0.0625f, 0.04419417382f, 0.03125f, 0.02209708691f,
  100870. 0.015625f, 0.01104854346f, 0.0078125f, 0.005524271728f,
  100871. 0.00390625f, 0.002762135864f, 0.001953125f, 0.001381067932f,
  100872. 0.0009765625f, 0.000690533966f, 0.00048828125f, 0.000345266983f,
  100873. 0.000244140625f,0.0001726334915f,0.0001220703125f,8.631674575e-05f,
  100874. 6.103515625e-05f,4.315837288e-05f,3.051757812e-05f,2.157918644e-05f,
  100875. 1.525878906e-05f,
  100876. };
  100877. #endif
  100878. #define FROMdB_LOOKUP_SZ 35
  100879. #define FROMdB2_LOOKUP_SZ 32
  100880. #define FROMdB_SHIFT 5
  100881. #define FROMdB2_SHIFT 3
  100882. #define FROMdB2_MASK 31
  100883. static float FROMdB_LOOKUP[FROMdB_LOOKUP_SZ]={
  100884. 1.f, 0.6309573445f, 0.3981071706f, 0.2511886432f,
  100885. 0.1584893192f, 0.1f, 0.06309573445f, 0.03981071706f,
  100886. 0.02511886432f, 0.01584893192f, 0.01f, 0.006309573445f,
  100887. 0.003981071706f, 0.002511886432f, 0.001584893192f, 0.001f,
  100888. 0.0006309573445f,0.0003981071706f,0.0002511886432f,0.0001584893192f,
  100889. 0.0001f,6.309573445e-05f,3.981071706e-05f,2.511886432e-05f,
  100890. 1.584893192e-05f, 1e-05f,6.309573445e-06f,3.981071706e-06f,
  100891. 2.511886432e-06f,1.584893192e-06f, 1e-06f,6.309573445e-07f,
  100892. 3.981071706e-07f,2.511886432e-07f,1.584893192e-07f,
  100893. };
  100894. static float FROMdB2_LOOKUP[FROMdB2_LOOKUP_SZ]={
  100895. 0.9928302478f, 0.9786445908f, 0.9646616199f, 0.9508784391f,
  100896. 0.9372921937f, 0.92390007f, 0.9106992942f, 0.8976871324f,
  100897. 0.8848608897f, 0.8722179097f, 0.8597555737f, 0.8474713009f,
  100898. 0.835362547f, 0.8234268041f, 0.8116616003f, 0.8000644989f,
  100899. 0.7886330981f, 0.7773650302f, 0.7662579617f, 0.755309592f,
  100900. 0.7445176537f, 0.7338799116f, 0.7233941627f, 0.7130582353f,
  100901. 0.7028699885f, 0.6928273125f, 0.6829281272f, 0.6731703824f,
  100902. 0.6635520573f, 0.6540711597f, 0.6447257262f, 0.6355138211f,
  100903. };
  100904. #ifdef INT_LOOKUP
  100905. #define INVSQ_LOOKUP_I_SHIFT 10
  100906. #define INVSQ_LOOKUP_I_MASK 1023
  100907. static long INVSQ_LOOKUP_I[64+1]={
  100908. 92682l, 91966l, 91267l, 90583l,
  100909. 89915l, 89261l, 88621l, 87995l,
  100910. 87381l, 86781l, 86192l, 85616l,
  100911. 85051l, 84497l, 83953l, 83420l,
  100912. 82897l, 82384l, 81880l, 81385l,
  100913. 80899l, 80422l, 79953l, 79492l,
  100914. 79039l, 78594l, 78156l, 77726l,
  100915. 77302l, 76885l, 76475l, 76072l,
  100916. 75674l, 75283l, 74898l, 74519l,
  100917. 74146l, 73778l, 73415l, 73058l,
  100918. 72706l, 72359l, 72016l, 71679l,
  100919. 71347l, 71019l, 70695l, 70376l,
  100920. 70061l, 69750l, 69444l, 69141l,
  100921. 68842l, 68548l, 68256l, 67969l,
  100922. 67685l, 67405l, 67128l, 66855l,
  100923. 66585l, 66318l, 66054l, 65794l,
  100924. 65536l,
  100925. };
  100926. #define COS_LOOKUP_I_SHIFT 9
  100927. #define COS_LOOKUP_I_MASK 511
  100928. #define COS_LOOKUP_I_SZ 128
  100929. static long COS_LOOKUP_I[COS_LOOKUP_I_SZ+1]={
  100930. 16384l, 16379l, 16364l, 16340l,
  100931. 16305l, 16261l, 16207l, 16143l,
  100932. 16069l, 15986l, 15893l, 15791l,
  100933. 15679l, 15557l, 15426l, 15286l,
  100934. 15137l, 14978l, 14811l, 14635l,
  100935. 14449l, 14256l, 14053l, 13842l,
  100936. 13623l, 13395l, 13160l, 12916l,
  100937. 12665l, 12406l, 12140l, 11866l,
  100938. 11585l, 11297l, 11003l, 10702l,
  100939. 10394l, 10080l, 9760l, 9434l,
  100940. 9102l, 8765l, 8423l, 8076l,
  100941. 7723l, 7366l, 7005l, 6639l,
  100942. 6270l, 5897l, 5520l, 5139l,
  100943. 4756l, 4370l, 3981l, 3590l,
  100944. 3196l, 2801l, 2404l, 2006l,
  100945. 1606l, 1205l, 804l, 402l,
  100946. 0l, -401l, -803l, -1204l,
  100947. -1605l, -2005l, -2403l, -2800l,
  100948. -3195l, -3589l, -3980l, -4369l,
  100949. -4755l, -5138l, -5519l, -5896l,
  100950. -6269l, -6638l, -7004l, -7365l,
  100951. -7722l, -8075l, -8422l, -8764l,
  100952. -9101l, -9433l, -9759l, -10079l,
  100953. -10393l, -10701l, -11002l, -11296l,
  100954. -11584l, -11865l, -12139l, -12405l,
  100955. -12664l, -12915l, -13159l, -13394l,
  100956. -13622l, -13841l, -14052l, -14255l,
  100957. -14448l, -14634l, -14810l, -14977l,
  100958. -15136l, -15285l, -15425l, -15556l,
  100959. -15678l, -15790l, -15892l, -15985l,
  100960. -16068l, -16142l, -16206l, -16260l,
  100961. -16304l, -16339l, -16363l, -16378l,
  100962. -16383l,
  100963. };
  100964. #endif
  100965. #endif
  100966. /*** End of inlined file: lookup_data.h ***/
  100967. #ifdef FLOAT_LOOKUP
  100968. float vorbis_coslook(float a){
  100969. double d=a*(.31830989*(float)COS_LOOKUP_SZ);
  100970. int i=vorbis_ftoi(d-.5);
  100971. return COS_LOOKUP[i]+ (d-i)*(COS_LOOKUP[i+1]-COS_LOOKUP[i]);
  100972. }
  100973. float vorbis_invsqlook(float a){
  100974. double d=a*(2.f*(float)INVSQ_LOOKUP_SZ)-(float)INVSQ_LOOKUP_SZ;
  100975. int i=vorbis_ftoi(d-.5f);
  100976. return INVSQ_LOOKUP[i]+ (d-i)*(INVSQ_LOOKUP[i+1]-INVSQ_LOOKUP[i]);
  100977. }
  100978. float vorbis_invsq2explook(int a){
  100979. return INVSQ2EXP_LOOKUP[a-INVSQ2EXP_LOOKUP_MIN];
  100980. }
  100981. #include <stdio.h>
  100982. float vorbis_fromdBlook(float a){
  100983. int i=vorbis_ftoi(a*((float)(-(1<<FROMdB2_SHIFT)))-.5f);
  100984. return (i<0)?1.f:
  100985. ((i>=(FROMdB_LOOKUP_SZ<<FROMdB_SHIFT))?0.f:
  100986. FROMdB_LOOKUP[i>>FROMdB_SHIFT]*FROMdB2_LOOKUP[i&FROMdB2_MASK]);
  100987. }
  100988. #endif
  100989. #ifdef INT_LOOKUP
  100990. long vorbis_invsqlook_i(long a,long e){
  100991. long i=(a&0x7fff)>>(INVSQ_LOOKUP_I_SHIFT-1);
  100992. long d=(a&INVSQ_LOOKUP_I_MASK)<<(16-INVSQ_LOOKUP_I_SHIFT); /* 0.16 */
  100993. long val=INVSQ_LOOKUP_I[i]- /* 1.16 */
  100994. (((INVSQ_LOOKUP_I[i]-INVSQ_LOOKUP_I[i+1])* /* 0.16 */
  100995. d)>>16); /* result 1.16 */
  100996. e+=32;
  100997. if(e&1)val=(val*5792)>>13; /* multiply val by 1/sqrt(2) */
  100998. e=(e>>1)-8;
  100999. return(val>>e);
  101000. }
  101001. float vorbis_fromdBlook_i(long a){
  101002. int i=(-a)>>(12-FROMdB2_SHIFT);
  101003. return (i<0)?1.f:
  101004. ((i>=(FROMdB_LOOKUP_SZ<<FROMdB_SHIFT))?0.f:
  101005. FROMdB_LOOKUP[i>>FROMdB_SHIFT]*FROMdB2_LOOKUP[i&FROMdB2_MASK]);
  101006. }
  101007. long vorbis_coslook_i(long a){
  101008. int i=a>>COS_LOOKUP_I_SHIFT;
  101009. int d=a&COS_LOOKUP_I_MASK;
  101010. return COS_LOOKUP_I[i]- ((d*(COS_LOOKUP_I[i]-COS_LOOKUP_I[i+1]))>>
  101011. COS_LOOKUP_I_SHIFT);
  101012. }
  101013. #endif
  101014. #endif
  101015. /*** End of inlined file: lookup.c ***/
  101016. /* catch this in the build system; we #include for
  101017. compilers (like gcc) that can't inline across
  101018. modules */
  101019. static int MLOOP_1[64]={
  101020. 0,10,11,11, 12,12,12,12, 13,13,13,13, 13,13,13,13,
  101021. 14,14,14,14, 14,14,14,14, 14,14,14,14, 14,14,14,14,
  101022. 15,15,15,15, 15,15,15,15, 15,15,15,15, 15,15,15,15,
  101023. 15,15,15,15, 15,15,15,15, 15,15,15,15, 15,15,15,15,
  101024. };
  101025. static int MLOOP_2[64]={
  101026. 0,4,5,5, 6,6,6,6, 7,7,7,7, 7,7,7,7,
  101027. 8,8,8,8, 8,8,8,8, 8,8,8,8, 8,8,8,8,
  101028. 9,9,9,9, 9,9,9,9, 9,9,9,9, 9,9,9,9,
  101029. 9,9,9,9, 9,9,9,9, 9,9,9,9, 9,9,9,9,
  101030. };
  101031. static int MLOOP_3[8]={0,1,2,2,3,3,3,3};
  101032. void vorbis_lsp_to_curve(float *curve,int *map,int n,int ln,float *lsp,int m,
  101033. float amp,float ampoffset){
  101034. int i;
  101035. int ampoffseti=rint(ampoffset*4096.f);
  101036. int ampi=rint(amp*16.f);
  101037. long *ilsp=alloca(m*sizeof(*ilsp));
  101038. for(i=0;i<m;i++)ilsp[i]=vorbis_coslook_i(lsp[i]/M_PI*65536.f+.5f);
  101039. i=0;
  101040. while(i<n){
  101041. int j,k=map[i];
  101042. unsigned long pi=46341; /* 2**-.5 in 0.16 */
  101043. unsigned long qi=46341;
  101044. int qexp=0,shift;
  101045. long wi=vorbis_coslook_i(k*65536/ln);
  101046. qi*=labs(ilsp[0]-wi);
  101047. pi*=labs(ilsp[1]-wi);
  101048. for(j=3;j<m;j+=2){
  101049. if(!(shift=MLOOP_1[(pi|qi)>>25]))
  101050. if(!(shift=MLOOP_2[(pi|qi)>>19]))
  101051. shift=MLOOP_3[(pi|qi)>>16];
  101052. qi=(qi>>shift)*labs(ilsp[j-1]-wi);
  101053. pi=(pi>>shift)*labs(ilsp[j]-wi);
  101054. qexp+=shift;
  101055. }
  101056. if(!(shift=MLOOP_1[(pi|qi)>>25]))
  101057. if(!(shift=MLOOP_2[(pi|qi)>>19]))
  101058. shift=MLOOP_3[(pi|qi)>>16];
  101059. if(m&1){
  101060. qi=(qi>>shift)*labs(ilsp[j-1]-wi);
  101061. pi=(pi>>shift)<<14;
  101062. qexp+=shift;
  101063. if(!(shift=MLOOP_1[(pi|qi)>>25]))
  101064. if(!(shift=MLOOP_2[(pi|qi)>>19]))
  101065. shift=MLOOP_3[(pi|qi)>>16];
  101066. pi>>=shift;
  101067. qi>>=shift;
  101068. qexp+=shift-14*((m+1)>>1);
  101069. pi=((pi*pi)>>16);
  101070. qi=((qi*qi)>>16);
  101071. qexp=qexp*2+m;
  101072. pi*=(1<<14)-((wi*wi)>>14);
  101073. qi+=pi>>14;
  101074. }else{
  101075. pi>>=shift;
  101076. qi>>=shift;
  101077. qexp+=shift-7*m;
  101078. pi=((pi*pi)>>16);
  101079. qi=((qi*qi)>>16);
  101080. qexp=qexp*2+m;
  101081. pi*=(1<<14)-wi;
  101082. qi*=(1<<14)+wi;
  101083. qi=(qi+pi)>>14;
  101084. }
  101085. if(qi&0xffff0000){ /* checks for 1.xxxxxxxxxxxxxxxx */
  101086. qi>>=1; qexp++;
  101087. }else
  101088. while(qi && !(qi&0x8000)){ /* checks for 0.0xxxxxxxxxxxxxxx or less*/
  101089. qi<<=1; qexp--;
  101090. }
  101091. amp=vorbis_fromdBlook_i(ampi* /* n.4 */
  101092. vorbis_invsqlook_i(qi,qexp)-
  101093. ampoffseti); /* 8.12[0] */
  101094. curve[i]*=amp;
  101095. while(map[++i]==k)curve[i]*=amp;
  101096. }
  101097. }
  101098. #else
  101099. void vorbis_lsp_to_curve(float *curve,int *map,int n,int ln,float *lsp,int m,
  101100. float amp,float ampoffset){
  101101. int i;
  101102. float wdel=M_PI/ln;
  101103. for(i=0;i<m;i++)lsp[i]=2.f*cos(lsp[i]);
  101104. i=0;
  101105. while(i<n){
  101106. int j,k=map[i];
  101107. float p=.5f;
  101108. float q=.5f;
  101109. float w=2.f*cos(wdel*k);
  101110. for(j=1;j<m;j+=2){
  101111. q *= w-lsp[j-1];
  101112. p *= w-lsp[j];
  101113. }
  101114. if(j==m){
  101115. q*=w-lsp[j-1];
  101116. p*=p*(4.f-w*w);
  101117. q*=q;
  101118. }else{
  101119. p*=p*(2.f-w);
  101120. q*=q*(2.f+w);
  101121. }
  101122. q=fromdB(amp/sqrt(p+q)-ampoffset);
  101123. curve[i]*=q;
  101124. while(map[++i]==k)curve[i]*=q;
  101125. }
  101126. }
  101127. #endif
  101128. #endif
  101129. static void cheby(float *g, int ord) {
  101130. int i, j;
  101131. g[0] *= .5f;
  101132. for(i=2; i<= ord; i++) {
  101133. for(j=ord; j >= i; j--) {
  101134. g[j-2] -= g[j];
  101135. g[j] += g[j];
  101136. }
  101137. }
  101138. }
  101139. static int comp(const void *a,const void *b){
  101140. return (*(float *)a<*(float *)b)-(*(float *)a>*(float *)b);
  101141. }
  101142. #define EPSILON 10e-7
  101143. static int Laguerre_With_Deflation(float *a,int ord,float *r){
  101144. int i,m;
  101145. double lastdelta=0.f;
  101146. double *defl=(double*)alloca(sizeof(*defl)*(ord+1));
  101147. for(i=0;i<=ord;i++)defl[i]=a[i];
  101148. for(m=ord;m>0;m--){
  101149. double newx=0.f,delta;
  101150. while(1){
  101151. double p=defl[m],pp=0.f,ppp=0.f,denom;
  101152. for(i=m;i>0;i--){
  101153. ppp = newx*ppp + pp;
  101154. pp = newx*pp + p;
  101155. p = newx*p + defl[i-1];
  101156. }
  101157. denom=(m-1) * ((m-1)*pp*pp - m*p*ppp);
  101158. if(denom<0)
  101159. return(-1); /* complex root! The LPC generator handed us a bad filter */
  101160. if(pp>0){
  101161. denom = pp + sqrt(denom);
  101162. if(denom<EPSILON)denom=EPSILON;
  101163. }else{
  101164. denom = pp - sqrt(denom);
  101165. if(denom>-(EPSILON))denom=-(EPSILON);
  101166. }
  101167. delta = m*p/denom;
  101168. newx -= delta;
  101169. if(delta<0.f)delta*=-1;
  101170. if(fabs(delta/newx)<10e-12)break;
  101171. lastdelta=delta;
  101172. }
  101173. r[m-1]=newx;
  101174. for(i=m;i>0;i--)
  101175. defl[i-1]+=newx*defl[i];
  101176. defl++;
  101177. }
  101178. return(0);
  101179. }
  101180. static int Newton_Raphson(float *a,int ord,float *r){
  101181. int i, k, count=0;
  101182. double error=1.f;
  101183. double *root=(double*)alloca(ord*sizeof(*root));
  101184. for(i=0; i<ord;i++) root[i] = r[i];
  101185. while(error>1e-20){
  101186. error=0;
  101187. for(i=0; i<ord; i++) { /* Update each point. */
  101188. double pp=0.,delta;
  101189. double rooti=root[i];
  101190. double p=a[ord];
  101191. for(k=ord-1; k>= 0; k--) {
  101192. pp= pp* rooti + p;
  101193. p = p * rooti + a[k];
  101194. }
  101195. delta = p/pp;
  101196. root[i] -= delta;
  101197. error+= delta*delta;
  101198. }
  101199. if(count>40)return(-1);
  101200. count++;
  101201. }
  101202. for(i=0; i<ord;i++) r[i] = root[i];
  101203. return(0);
  101204. }
  101205. int vorbis_lpc_to_lsp(float *lpc,float *lsp,int m){
  101206. int order2=(m+1)>>1;
  101207. int g1_order,g2_order;
  101208. float *g1=(float*)alloca(sizeof(*g1)*(order2+1));
  101209. float *g2=(float*)alloca(sizeof(*g2)*(order2+1));
  101210. float *g1r=(float*)alloca(sizeof(*g1r)*(order2+1));
  101211. float *g2r=(float*)alloca(sizeof(*g2r)*(order2+1));
  101212. int i;
  101213. g1_order=(m+1)>>1;
  101214. g2_order=(m) >>1;
  101215. g1[g1_order] = 1.f;
  101216. for(i=1;i<=g1_order;i++) g1[g1_order-i] = lpc[i-1]+lpc[m-i];
  101217. g2[g2_order] = 1.f;
  101218. for(i=1;i<=g2_order;i++) g2[g2_order-i] = lpc[i-1]-lpc[m-i];
  101219. if(g1_order>g2_order){
  101220. for(i=2; i<=g2_order;i++) g2[g2_order-i] += g2[g2_order-i+2];
  101221. }else{
  101222. for(i=1; i<=g1_order;i++) g1[g1_order-i] -= g1[g1_order-i+1];
  101223. for(i=1; i<=g2_order;i++) g2[g2_order-i] += g2[g2_order-i+1];
  101224. }
  101225. cheby(g1,g1_order);
  101226. cheby(g2,g2_order);
  101227. if(Laguerre_With_Deflation(g1,g1_order,g1r) ||
  101228. Laguerre_With_Deflation(g2,g2_order,g2r))
  101229. return(-1);
  101230. Newton_Raphson(g1,g1_order,g1r); /* if it fails, it leaves g1r alone */
  101231. Newton_Raphson(g2,g2_order,g2r); /* if it fails, it leaves g2r alone */
  101232. qsort(g1r,g1_order,sizeof(*g1r),comp);
  101233. qsort(g2r,g2_order,sizeof(*g2r),comp);
  101234. for(i=0;i<g1_order;i++)
  101235. lsp[i*2] = acos(g1r[i]);
  101236. for(i=0;i<g2_order;i++)
  101237. lsp[i*2+1] = acos(g2r[i]);
  101238. return(0);
  101239. }
  101240. #endif
  101241. /*** End of inlined file: lsp.c ***/
  101242. /*** Start of inlined file: mapping0.c ***/
  101243. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  101244. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  101245. // tasks..
  101246. #if JUCE_MSVC
  101247. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  101248. #endif
  101249. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  101250. #if JUCE_USE_OGGVORBIS
  101251. #include <stdlib.h>
  101252. #include <stdio.h>
  101253. #include <string.h>
  101254. #include <math.h>
  101255. static void mapping0_free_info(vorbis_info_mapping *i){
  101256. vorbis_info_mapping0 *info=(vorbis_info_mapping0 *)i;
  101257. if(info){
  101258. memset(info,0,sizeof(*info));
  101259. _ogg_free(info);
  101260. }
  101261. }
  101262. static int ilog3(unsigned int v){
  101263. int ret=0;
  101264. if(v)--v;
  101265. while(v){
  101266. ret++;
  101267. v>>=1;
  101268. }
  101269. return(ret);
  101270. }
  101271. static void mapping0_pack(vorbis_info *vi,vorbis_info_mapping *vm,
  101272. oggpack_buffer *opb){
  101273. int i;
  101274. vorbis_info_mapping0 *info=(vorbis_info_mapping0 *)vm;
  101275. if(info->submaps>1){
  101276. oggpack_write(opb,1,1);
  101277. oggpack_write(opb,info->submaps-1,4);
  101278. }else
  101279. oggpack_write(opb,0,1);
  101280. if(info->coupling_steps>0){
  101281. oggpack_write(opb,1,1);
  101282. oggpack_write(opb,info->coupling_steps-1,8);
  101283. for(i=0;i<info->coupling_steps;i++){
  101284. oggpack_write(opb,info->coupling_mag[i],ilog3(vi->channels));
  101285. oggpack_write(opb,info->coupling_ang[i],ilog3(vi->channels));
  101286. }
  101287. }else
  101288. oggpack_write(opb,0,1);
  101289. oggpack_write(opb,0,2); /* 2,3:reserved */
  101290. if(info->submaps>1){
  101291. for(i=0;i<vi->channels;i++)
  101292. oggpack_write(opb,info->chmuxlist[i],4);
  101293. }
  101294. for(i=0;i<info->submaps;i++){
  101295. oggpack_write(opb,0,8); /* time submap unused */
  101296. oggpack_write(opb,info->floorsubmap[i],8);
  101297. oggpack_write(opb,info->residuesubmap[i],8);
  101298. }
  101299. }
  101300. static vorbis_info_mapping *mapping0_unpack(vorbis_info *vi,oggpack_buffer *opb){
  101301. int i;
  101302. vorbis_info_mapping0 *info=(vorbis_info_mapping0*)_ogg_calloc(1,sizeof(*info));
  101303. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  101304. memset(info,0,sizeof(*info));
  101305. if(oggpack_read(opb,1))
  101306. info->submaps=oggpack_read(opb,4)+1;
  101307. else
  101308. info->submaps=1;
  101309. if(oggpack_read(opb,1)){
  101310. info->coupling_steps=oggpack_read(opb,8)+1;
  101311. for(i=0;i<info->coupling_steps;i++){
  101312. int testM=info->coupling_mag[i]=oggpack_read(opb,ilog3(vi->channels));
  101313. int testA=info->coupling_ang[i]=oggpack_read(opb,ilog3(vi->channels));
  101314. if(testM<0 ||
  101315. testA<0 ||
  101316. testM==testA ||
  101317. testM>=vi->channels ||
  101318. testA>=vi->channels) goto err_out;
  101319. }
  101320. }
  101321. if(oggpack_read(opb,2)>0)goto err_out; /* 2,3:reserved */
  101322. if(info->submaps>1){
  101323. for(i=0;i<vi->channels;i++){
  101324. info->chmuxlist[i]=oggpack_read(opb,4);
  101325. if(info->chmuxlist[i]>=info->submaps)goto err_out;
  101326. }
  101327. }
  101328. for(i=0;i<info->submaps;i++){
  101329. oggpack_read(opb,8); /* time submap unused */
  101330. info->floorsubmap[i]=oggpack_read(opb,8);
  101331. if(info->floorsubmap[i]>=ci->floors)goto err_out;
  101332. info->residuesubmap[i]=oggpack_read(opb,8);
  101333. if(info->residuesubmap[i]>=ci->residues)goto err_out;
  101334. }
  101335. return info;
  101336. err_out:
  101337. mapping0_free_info(info);
  101338. return(NULL);
  101339. }
  101340. #if 0
  101341. static long seq=0;
  101342. static ogg_int64_t total=0;
  101343. static float FLOOR1_fromdB_LOOKUP[256]={
  101344. 1.0649863e-07F, 1.1341951e-07F, 1.2079015e-07F, 1.2863978e-07F,
  101345. 1.3699951e-07F, 1.4590251e-07F, 1.5538408e-07F, 1.6548181e-07F,
  101346. 1.7623575e-07F, 1.8768855e-07F, 1.9988561e-07F, 2.128753e-07F,
  101347. 2.2670913e-07F, 2.4144197e-07F, 2.5713223e-07F, 2.7384213e-07F,
  101348. 2.9163793e-07F, 3.1059021e-07F, 3.3077411e-07F, 3.5226968e-07F,
  101349. 3.7516214e-07F, 3.9954229e-07F, 4.2550680e-07F, 4.5315863e-07F,
  101350. 4.8260743e-07F, 5.1396998e-07F, 5.4737065e-07F, 5.8294187e-07F,
  101351. 6.2082472e-07F, 6.6116941e-07F, 7.0413592e-07F, 7.4989464e-07F,
  101352. 7.9862701e-07F, 8.5052630e-07F, 9.0579828e-07F, 9.6466216e-07F,
  101353. 1.0273513e-06F, 1.0941144e-06F, 1.1652161e-06F, 1.2409384e-06F,
  101354. 1.3215816e-06F, 1.4074654e-06F, 1.4989305e-06F, 1.5963394e-06F,
  101355. 1.7000785e-06F, 1.8105592e-06F, 1.9282195e-06F, 2.0535261e-06F,
  101356. 2.1869758e-06F, 2.3290978e-06F, 2.4804557e-06F, 2.6416497e-06F,
  101357. 2.8133190e-06F, 2.9961443e-06F, 3.1908506e-06F, 3.3982101e-06F,
  101358. 3.6190449e-06F, 3.8542308e-06F, 4.1047004e-06F, 4.3714470e-06F,
  101359. 4.6555282e-06F, 4.9580707e-06F, 5.2802740e-06F, 5.6234160e-06F,
  101360. 5.9888572e-06F, 6.3780469e-06F, 6.7925283e-06F, 7.2339451e-06F,
  101361. 7.7040476e-06F, 8.2047000e-06F, 8.7378876e-06F, 9.3057248e-06F,
  101362. 9.9104632e-06F, 1.0554501e-05F, 1.1240392e-05F, 1.1970856e-05F,
  101363. 1.2748789e-05F, 1.3577278e-05F, 1.4459606e-05F, 1.5399272e-05F,
  101364. 1.6400004e-05F, 1.7465768e-05F, 1.8600792e-05F, 1.9809576e-05F,
  101365. 2.1096914e-05F, 2.2467911e-05F, 2.3928002e-05F, 2.5482978e-05F,
  101366. 2.7139006e-05F, 2.8902651e-05F, 3.0780908e-05F, 3.2781225e-05F,
  101367. 3.4911534e-05F, 3.7180282e-05F, 3.9596466e-05F, 4.2169667e-05F,
  101368. 4.4910090e-05F, 4.7828601e-05F, 5.0936773e-05F, 5.4246931e-05F,
  101369. 5.7772202e-05F, 6.1526565e-05F, 6.5524908e-05F, 6.9783085e-05F,
  101370. 7.4317983e-05F, 7.9147585e-05F, 8.4291040e-05F, 8.9768747e-05F,
  101371. 9.5602426e-05F, 0.00010181521F, 0.00010843174F, 0.00011547824F,
  101372. 0.00012298267F, 0.00013097477F, 0.00013948625F, 0.00014855085F,
  101373. 0.00015820453F, 0.00016848555F, 0.00017943469F, 0.00019109536F,
  101374. 0.00020351382F, 0.00021673929F, 0.00023082423F, 0.00024582449F,
  101375. 0.00026179955F, 0.00027881276F, 0.00029693158F, 0.00031622787F,
  101376. 0.00033677814F, 0.00035866388F, 0.00038197188F, 0.00040679456F,
  101377. 0.00043323036F, 0.00046138411F, 0.00049136745F, 0.00052329927F,
  101378. 0.00055730621F, 0.00059352311F, 0.00063209358F, 0.00067317058F,
  101379. 0.00071691700F, 0.00076350630F, 0.00081312324F, 0.00086596457F,
  101380. 0.00092223983F, 0.00098217216F, 0.0010459992F, 0.0011139742F,
  101381. 0.0011863665F, 0.0012634633F, 0.0013455702F, 0.0014330129F,
  101382. 0.0015261382F, 0.0016253153F, 0.0017309374F, 0.0018434235F,
  101383. 0.0019632195F, 0.0020908006F, 0.0022266726F, 0.0023713743F,
  101384. 0.0025254795F, 0.0026895994F, 0.0028643847F, 0.0030505286F,
  101385. 0.0032487691F, 0.0034598925F, 0.0036847358F, 0.0039241906F,
  101386. 0.0041792066F, 0.0044507950F, 0.0047400328F, 0.0050480668F,
  101387. 0.0053761186F, 0.0057254891F, 0.0060975636F, 0.0064938176F,
  101388. 0.0069158225F, 0.0073652516F, 0.0078438871F, 0.0083536271F,
  101389. 0.0088964928F, 0.009474637F, 0.010090352F, 0.010746080F,
  101390. 0.011444421F, 0.012188144F, 0.012980198F, 0.013823725F,
  101391. 0.014722068F, 0.015678791F, 0.016697687F, 0.017782797F,
  101392. 0.018938423F, 0.020169149F, 0.021479854F, 0.022875735F,
  101393. 0.024362330F, 0.025945531F, 0.027631618F, 0.029427276F,
  101394. 0.031339626F, 0.033376252F, 0.035545228F, 0.037855157F,
  101395. 0.040315199F, 0.042935108F, 0.045725273F, 0.048696758F,
  101396. 0.051861348F, 0.055231591F, 0.058820850F, 0.062643361F,
  101397. 0.066714279F, 0.071049749F, 0.075666962F, 0.080584227F,
  101398. 0.085821044F, 0.091398179F, 0.097337747F, 0.10366330F,
  101399. 0.11039993F, 0.11757434F, 0.12521498F, 0.13335215F,
  101400. 0.14201813F, 0.15124727F, 0.16107617F, 0.17154380F,
  101401. 0.18269168F, 0.19456402F, 0.20720788F, 0.22067342F,
  101402. 0.23501402F, 0.25028656F, 0.26655159F, 0.28387361F,
  101403. 0.30232132F, 0.32196786F, 0.34289114F, 0.36517414F,
  101404. 0.38890521F, 0.41417847F, 0.44109412F, 0.46975890F,
  101405. 0.50028648F, 0.53279791F, 0.56742212F, 0.60429640F,
  101406. 0.64356699F, 0.68538959F, 0.72993007F, 0.77736504F,
  101407. 0.82788260F, 0.88168307F, 0.9389798F, 1.F,
  101408. };
  101409. #endif
  101410. extern int *floor1_fit(vorbis_block *vb,void *look,
  101411. const float *logmdct, /* in */
  101412. const float *logmask);
  101413. extern int *floor1_interpolate_fit(vorbis_block *vb,void *look,
  101414. int *A,int *B,
  101415. int del);
  101416. extern int floor1_encode(oggpack_buffer *opb,vorbis_block *vb,
  101417. void*look,
  101418. int *post,int *ilogmask);
  101419. static int mapping0_forward(vorbis_block *vb){
  101420. vorbis_dsp_state *vd=vb->vd;
  101421. vorbis_info *vi=vd->vi;
  101422. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  101423. private_state *b=(private_state*)vb->vd->backend_state;
  101424. vorbis_block_internal *vbi=(vorbis_block_internal *)vb->internal;
  101425. int n=vb->pcmend;
  101426. int i,j,k;
  101427. int *nonzero = (int*) alloca(sizeof(*nonzero)*vi->channels);
  101428. float **gmdct = (float**) _vorbis_block_alloc(vb,vi->channels*sizeof(*gmdct));
  101429. int **ilogmaskch= (int**) _vorbis_block_alloc(vb,vi->channels*sizeof(*ilogmaskch));
  101430. int ***floor_posts = (int***) _vorbis_block_alloc(vb,vi->channels*sizeof(*floor_posts));
  101431. float global_ampmax=vbi->ampmax;
  101432. float *local_ampmax=(float*)alloca(sizeof(*local_ampmax)*vi->channels);
  101433. int blocktype=vbi->blocktype;
  101434. int modenumber=vb->W;
  101435. vorbis_info_mapping0 *info=(vorbis_info_mapping0*)ci->map_param[modenumber];
  101436. vorbis_look_psy *psy_look=
  101437. b->psy+blocktype+(vb->W?2:0);
  101438. vb->mode=modenumber;
  101439. for(i=0;i<vi->channels;i++){
  101440. float scale=4.f/n;
  101441. float scale_dB;
  101442. float *pcm =vb->pcm[i];
  101443. float *logfft =pcm;
  101444. gmdct[i]=(float*)_vorbis_block_alloc(vb,n/2*sizeof(**gmdct));
  101445. scale_dB=todB(&scale) + .345; /* + .345 is a hack; the original
  101446. todB estimation used on IEEE 754
  101447. compliant machines had a bug that
  101448. returned dB values about a third
  101449. of a decibel too high. The bug
  101450. was harmless because tunings
  101451. implicitly took that into
  101452. account. However, fixing the bug
  101453. in the estimator requires
  101454. changing all the tunings as well.
  101455. For now, it's easier to sync
  101456. things back up here, and
  101457. recalibrate the tunings in the
  101458. next major model upgrade. */
  101459. #if 0
  101460. if(vi->channels==2)
  101461. if(i==0)
  101462. _analysis_output("pcmL",seq,pcm,n,0,0,total-n/2);
  101463. else
  101464. _analysis_output("pcmR",seq,pcm,n,0,0,total-n/2);
  101465. #endif
  101466. _vorbis_apply_window(pcm,b->window,ci->blocksizes,vb->lW,vb->W,vb->nW);
  101467. #if 0
  101468. if(vi->channels==2)
  101469. if(i==0)
  101470. _analysis_output("windowedL",seq,pcm,n,0,0,total-n/2);
  101471. else
  101472. _analysis_output("windowedR",seq,pcm,n,0,0,total-n/2);
  101473. #endif
  101474. mdct_forward((mdct_lookup*) b->transform[vb->W][0],pcm,gmdct[i]);
  101475. drft_forward(&b->fft_look[vb->W],pcm);
  101476. logfft[0]=scale_dB+todB(pcm) + .345; /* + .345 is a hack; the
  101477. original todB estimation used on
  101478. IEEE 754 compliant machines had a
  101479. bug that returned dB values about
  101480. a third of a decibel too high.
  101481. The bug was harmless because
  101482. tunings implicitly took that into
  101483. account. However, fixing the bug
  101484. in the estimator requires
  101485. changing all the tunings as well.
  101486. For now, it's easier to sync
  101487. things back up here, and
  101488. recalibrate the tunings in the
  101489. next major model upgrade. */
  101490. local_ampmax[i]=logfft[0];
  101491. for(j=1;j<n-1;j+=2){
  101492. float temp=pcm[j]*pcm[j]+pcm[j+1]*pcm[j+1];
  101493. temp=logfft[(j+1)>>1]=scale_dB+.5f*todB(&temp) + .345; /* +
  101494. .345 is a hack; the original todB
  101495. estimation used on IEEE 754
  101496. compliant machines had a bug that
  101497. returned dB values about a third
  101498. of a decibel too high. The bug
  101499. was harmless because tunings
  101500. implicitly took that into
  101501. account. However, fixing the bug
  101502. in the estimator requires
  101503. changing all the tunings as well.
  101504. For now, it's easier to sync
  101505. things back up here, and
  101506. recalibrate the tunings in the
  101507. next major model upgrade. */
  101508. if(temp>local_ampmax[i])local_ampmax[i]=temp;
  101509. }
  101510. if(local_ampmax[i]>0.f)local_ampmax[i]=0.f;
  101511. if(local_ampmax[i]>global_ampmax)global_ampmax=local_ampmax[i];
  101512. #if 0
  101513. if(vi->channels==2){
  101514. if(i==0){
  101515. _analysis_output("fftL",seq,logfft,n/2,1,0,0);
  101516. }else{
  101517. _analysis_output("fftR",seq,logfft,n/2,1,0,0);
  101518. }
  101519. }
  101520. #endif
  101521. }
  101522. {
  101523. float *noise = (float*) _vorbis_block_alloc(vb,n/2*sizeof(*noise));
  101524. float *tone = (float*) _vorbis_block_alloc(vb,n/2*sizeof(*tone));
  101525. for(i=0;i<vi->channels;i++){
  101526. int submap=info->chmuxlist[i];
  101527. float *mdct =gmdct[i];
  101528. float *logfft =vb->pcm[i];
  101529. float *logmdct =logfft+n/2;
  101530. float *logmask =logfft;
  101531. vb->mode=modenumber;
  101532. floor_posts[i]=(int**) _vorbis_block_alloc(vb,PACKETBLOBS*sizeof(**floor_posts));
  101533. memset(floor_posts[i],0,sizeof(**floor_posts)*PACKETBLOBS);
  101534. for(j=0;j<n/2;j++)
  101535. logmdct[j]=todB(mdct+j) + .345; /* + .345 is a hack; the original
  101536. todB estimation used on IEEE 754
  101537. compliant machines had a bug that
  101538. returned dB values about a third
  101539. of a decibel too high. The bug
  101540. was harmless because tunings
  101541. implicitly took that into
  101542. account. However, fixing the bug
  101543. in the estimator requires
  101544. changing all the tunings as well.
  101545. For now, it's easier to sync
  101546. things back up here, and
  101547. recalibrate the tunings in the
  101548. next major model upgrade. */
  101549. #if 0
  101550. if(vi->channels==2){
  101551. if(i==0)
  101552. _analysis_output("mdctL",seq,logmdct,n/2,1,0,0);
  101553. else
  101554. _analysis_output("mdctR",seq,logmdct,n/2,1,0,0);
  101555. }else{
  101556. _analysis_output("mdct",seq,logmdct,n/2,1,0,0);
  101557. }
  101558. #endif
  101559. _vp_noisemask(psy_look,
  101560. logmdct,
  101561. noise); /* noise does not have by-frequency offset
  101562. bias applied yet */
  101563. #if 0
  101564. if(vi->channels==2){
  101565. if(i==0)
  101566. _analysis_output("noiseL",seq,noise,n/2,1,0,0);
  101567. else
  101568. _analysis_output("noiseR",seq,noise,n/2,1,0,0);
  101569. }
  101570. #endif
  101571. _vp_tonemask(psy_look,
  101572. logfft,
  101573. tone,
  101574. global_ampmax,
  101575. local_ampmax[i]);
  101576. #if 0
  101577. if(vi->channels==2){
  101578. if(i==0)
  101579. _analysis_output("toneL",seq,tone,n/2,1,0,0);
  101580. else
  101581. _analysis_output("toneR",seq,tone,n/2,1,0,0);
  101582. }
  101583. #endif
  101584. #if 0
  101585. {
  101586. float aotuv[psy_look->n];
  101587. #endif
  101588. _vp_offset_and_mix(psy_look,
  101589. noise,
  101590. tone,
  101591. 1,
  101592. logmask,
  101593. mdct,
  101594. logmdct);
  101595. #if 0
  101596. if(vi->channels==2){
  101597. if(i==0)
  101598. _analysis_output("aotuvM1_L",seq,aotuv,psy_look->n,1,1,0);
  101599. else
  101600. _analysis_output("aotuvM1_R",seq,aotuv,psy_look->n,1,1,0);
  101601. }
  101602. }
  101603. #endif
  101604. #if 0
  101605. if(vi->channels==2){
  101606. if(i==0)
  101607. _analysis_output("mask1L",seq,logmask,n/2,1,0,0);
  101608. else
  101609. _analysis_output("mask1R",seq,logmask,n/2,1,0,0);
  101610. }
  101611. #endif
  101612. if(ci->floor_type[info->floorsubmap[submap]]!=1)return(-1);
  101613. floor_posts[i][PACKETBLOBS/2]=
  101614. floor1_fit(vb,b->flr[info->floorsubmap[submap]],
  101615. logmdct,
  101616. logmask);
  101617. if(vorbis_bitrate_managed(vb) && floor_posts[i][PACKETBLOBS/2]){
  101618. _vp_offset_and_mix(psy_look,
  101619. noise,
  101620. tone,
  101621. 2,
  101622. logmask,
  101623. mdct,
  101624. logmdct);
  101625. #if 0
  101626. if(vi->channels==2){
  101627. if(i==0)
  101628. _analysis_output("mask2L",seq,logmask,n/2,1,0,0);
  101629. else
  101630. _analysis_output("mask2R",seq,logmask,n/2,1,0,0);
  101631. }
  101632. #endif
  101633. floor_posts[i][PACKETBLOBS-1]=
  101634. floor1_fit(vb,b->flr[info->floorsubmap[submap]],
  101635. logmdct,
  101636. logmask);
  101637. _vp_offset_and_mix(psy_look,
  101638. noise,
  101639. tone,
  101640. 0,
  101641. logmask,
  101642. mdct,
  101643. logmdct);
  101644. #if 0
  101645. if(vi->channels==2)
  101646. if(i==0)
  101647. _analysis_output("mask0L",seq,logmask,n/2,1,0,0);
  101648. else
  101649. _analysis_output("mask0R",seq,logmask,n/2,1,0,0);
  101650. #endif
  101651. floor_posts[i][0]=
  101652. floor1_fit(vb,b->flr[info->floorsubmap[submap]],
  101653. logmdct,
  101654. logmask);
  101655. for(k=1;k<PACKETBLOBS/2;k++)
  101656. floor_posts[i][k]=
  101657. floor1_interpolate_fit(vb,b->flr[info->floorsubmap[submap]],
  101658. floor_posts[i][0],
  101659. floor_posts[i][PACKETBLOBS/2],
  101660. k*65536/(PACKETBLOBS/2));
  101661. for(k=PACKETBLOBS/2+1;k<PACKETBLOBS-1;k++)
  101662. floor_posts[i][k]=
  101663. floor1_interpolate_fit(vb,b->flr[info->floorsubmap[submap]],
  101664. floor_posts[i][PACKETBLOBS/2],
  101665. floor_posts[i][PACKETBLOBS-1],
  101666. (k-PACKETBLOBS/2)*65536/(PACKETBLOBS/2));
  101667. }
  101668. }
  101669. }
  101670. vbi->ampmax=global_ampmax;
  101671. {
  101672. float **res_bundle=(float**) alloca(sizeof(*res_bundle)*vi->channels);
  101673. float **couple_bundle=(float**) alloca(sizeof(*couple_bundle)*vi->channels);
  101674. int *zerobundle=(int*) alloca(sizeof(*zerobundle)*vi->channels);
  101675. int **sortindex=(int**) alloca(sizeof(*sortindex)*vi->channels);
  101676. float **mag_memo;
  101677. int **mag_sort;
  101678. if(info->coupling_steps){
  101679. mag_memo=_vp_quantize_couple_memo(vb,
  101680. &ci->psy_g_param,
  101681. psy_look,
  101682. info,
  101683. gmdct);
  101684. mag_sort=_vp_quantize_couple_sort(vb,
  101685. psy_look,
  101686. info,
  101687. mag_memo);
  101688. hf_reduction(&ci->psy_g_param,
  101689. psy_look,
  101690. info,
  101691. mag_memo);
  101692. }
  101693. memset(sortindex,0,sizeof(*sortindex)*vi->channels);
  101694. if(psy_look->vi->normal_channel_p){
  101695. for(i=0;i<vi->channels;i++){
  101696. float *mdct =gmdct[i];
  101697. sortindex[i]=(int*) alloca(sizeof(**sortindex)*n/2);
  101698. _vp_noise_normalize_sort(psy_look,mdct,sortindex[i]);
  101699. }
  101700. }
  101701. for(k=(vorbis_bitrate_managed(vb)?0:PACKETBLOBS/2);
  101702. k<=(vorbis_bitrate_managed(vb)?PACKETBLOBS-1:PACKETBLOBS/2);
  101703. k++){
  101704. oggpack_buffer *opb=vbi->packetblob[k];
  101705. oggpack_write(opb,0,1);
  101706. oggpack_write(opb,modenumber,b->modebits);
  101707. if(vb->W){
  101708. oggpack_write(opb,vb->lW,1);
  101709. oggpack_write(opb,vb->nW,1);
  101710. }
  101711. for(i=0;i<vi->channels;i++){
  101712. int submap=info->chmuxlist[i];
  101713. float *mdct =gmdct[i];
  101714. float *res =vb->pcm[i];
  101715. int *ilogmask=ilogmaskch[i]=
  101716. (int*) _vorbis_block_alloc(vb,n/2*sizeof(**gmdct));
  101717. nonzero[i]=floor1_encode(opb,vb,b->flr[info->floorsubmap[submap]],
  101718. floor_posts[i][k],
  101719. ilogmask);
  101720. #if 0
  101721. {
  101722. char buf[80];
  101723. sprintf(buf,"maskI%c%d",i?'R':'L',k);
  101724. float work[n/2];
  101725. for(j=0;j<n/2;j++)
  101726. work[j]=FLOOR1_fromdB_LOOKUP[ilogmask[j]];
  101727. _analysis_output(buf,seq,work,n/2,1,1,0);
  101728. }
  101729. #endif
  101730. _vp_remove_floor(psy_look,
  101731. mdct,
  101732. ilogmask,
  101733. res,
  101734. ci->psy_g_param.sliding_lowpass[vb->W][k]);
  101735. _vp_noise_normalize(psy_look,res,res+n/2,sortindex[i]);
  101736. #if 0
  101737. {
  101738. char buf[80];
  101739. float work[n/2];
  101740. for(j=0;j<n/2;j++)
  101741. work[j]=FLOOR1_fromdB_LOOKUP[ilogmask[j]]*(res+n/2)[j];
  101742. sprintf(buf,"resI%c%d",i?'R':'L',k);
  101743. _analysis_output(buf,seq,work,n/2,1,1,0);
  101744. }
  101745. #endif
  101746. }
  101747. if(info->coupling_steps){
  101748. _vp_couple(k,
  101749. &ci->psy_g_param,
  101750. psy_look,
  101751. info,
  101752. vb->pcm,
  101753. mag_memo,
  101754. mag_sort,
  101755. ilogmaskch,
  101756. nonzero,
  101757. ci->psy_g_param.sliding_lowpass[vb->W][k]);
  101758. }
  101759. for(i=0;i<info->submaps;i++){
  101760. int ch_in_bundle=0;
  101761. long **classifications;
  101762. int resnum=info->residuesubmap[i];
  101763. for(j=0;j<vi->channels;j++){
  101764. if(info->chmuxlist[j]==i){
  101765. zerobundle[ch_in_bundle]=0;
  101766. if(nonzero[j])zerobundle[ch_in_bundle]=1;
  101767. res_bundle[ch_in_bundle]=vb->pcm[j];
  101768. couple_bundle[ch_in_bundle++]=vb->pcm[j]+n/2;
  101769. }
  101770. }
  101771. classifications=_residue_P[ci->residue_type[resnum]]->
  101772. classx(vb,b->residue[resnum],couple_bundle,zerobundle,ch_in_bundle);
  101773. _residue_P[ci->residue_type[resnum]]->
  101774. forward(opb,vb,b->residue[resnum],
  101775. couple_bundle,NULL,zerobundle,ch_in_bundle,classifications);
  101776. }
  101777. }
  101778. }
  101779. #if 0
  101780. seq++;
  101781. total+=ci->blocksizes[vb->W]/4+ci->blocksizes[vb->nW]/4;
  101782. #endif
  101783. return(0);
  101784. }
  101785. static int mapping0_inverse(vorbis_block *vb,vorbis_info_mapping *l){
  101786. vorbis_dsp_state *vd=vb->vd;
  101787. vorbis_info *vi=vd->vi;
  101788. codec_setup_info *ci=(codec_setup_info*) vi->codec_setup;
  101789. private_state *b=(private_state*)vd->backend_state;
  101790. vorbis_info_mapping0 *info=(vorbis_info_mapping0 *)l;
  101791. int i,j;
  101792. long n=vb->pcmend=ci->blocksizes[vb->W];
  101793. float **pcmbundle=(float**) alloca(sizeof(*pcmbundle)*vi->channels);
  101794. int *zerobundle=(int*) alloca(sizeof(*zerobundle)*vi->channels);
  101795. int *nonzero =(int*) alloca(sizeof(*nonzero)*vi->channels);
  101796. void **floormemo=(void**) alloca(sizeof(*floormemo)*vi->channels);
  101797. for(i=0;i<vi->channels;i++){
  101798. int submap=info->chmuxlist[i];
  101799. floormemo[i]=_floor_P[ci->floor_type[info->floorsubmap[submap]]]->
  101800. inverse1(vb,b->flr[info->floorsubmap[submap]]);
  101801. if(floormemo[i])
  101802. nonzero[i]=1;
  101803. else
  101804. nonzero[i]=0;
  101805. memset(vb->pcm[i],0,sizeof(*vb->pcm[i])*n/2);
  101806. }
  101807. for(i=0;i<info->coupling_steps;i++){
  101808. if(nonzero[info->coupling_mag[i]] ||
  101809. nonzero[info->coupling_ang[i]]){
  101810. nonzero[info->coupling_mag[i]]=1;
  101811. nonzero[info->coupling_ang[i]]=1;
  101812. }
  101813. }
  101814. for(i=0;i<info->submaps;i++){
  101815. int ch_in_bundle=0;
  101816. for(j=0;j<vi->channels;j++){
  101817. if(info->chmuxlist[j]==i){
  101818. if(nonzero[j])
  101819. zerobundle[ch_in_bundle]=1;
  101820. else
  101821. zerobundle[ch_in_bundle]=0;
  101822. pcmbundle[ch_in_bundle++]=vb->pcm[j];
  101823. }
  101824. }
  101825. _residue_P[ci->residue_type[info->residuesubmap[i]]]->
  101826. inverse(vb,b->residue[info->residuesubmap[i]],
  101827. pcmbundle,zerobundle,ch_in_bundle);
  101828. }
  101829. for(i=info->coupling_steps-1;i>=0;i--){
  101830. float *pcmM=vb->pcm[info->coupling_mag[i]];
  101831. float *pcmA=vb->pcm[info->coupling_ang[i]];
  101832. for(j=0;j<n/2;j++){
  101833. float mag=pcmM[j];
  101834. float ang=pcmA[j];
  101835. if(mag>0)
  101836. if(ang>0){
  101837. pcmM[j]=mag;
  101838. pcmA[j]=mag-ang;
  101839. }else{
  101840. pcmA[j]=mag;
  101841. pcmM[j]=mag+ang;
  101842. }
  101843. else
  101844. if(ang>0){
  101845. pcmM[j]=mag;
  101846. pcmA[j]=mag+ang;
  101847. }else{
  101848. pcmA[j]=mag;
  101849. pcmM[j]=mag-ang;
  101850. }
  101851. }
  101852. }
  101853. for(i=0;i<vi->channels;i++){
  101854. float *pcm=vb->pcm[i];
  101855. int submap=info->chmuxlist[i];
  101856. _floor_P[ci->floor_type[info->floorsubmap[submap]]]->
  101857. inverse2(vb,b->flr[info->floorsubmap[submap]],
  101858. floormemo[i],pcm);
  101859. }
  101860. for(i=0;i<vi->channels;i++){
  101861. float *pcm=vb->pcm[i];
  101862. mdct_backward((mdct_lookup*) b->transform[vb->W][0],pcm,pcm);
  101863. }
  101864. return(0);
  101865. }
  101866. vorbis_func_mapping mapping0_exportbundle={
  101867. &mapping0_pack,
  101868. &mapping0_unpack,
  101869. &mapping0_free_info,
  101870. &mapping0_forward,
  101871. &mapping0_inverse
  101872. };
  101873. #endif
  101874. /*** End of inlined file: mapping0.c ***/
  101875. /*** Start of inlined file: mdct.c ***/
  101876. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  101877. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  101878. // tasks..
  101879. #if JUCE_MSVC
  101880. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  101881. #endif
  101882. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  101883. #if JUCE_USE_OGGVORBIS
  101884. #include <stdio.h>
  101885. #include <stdlib.h>
  101886. #include <string.h>
  101887. #include <math.h>
  101888. void mdct_init(mdct_lookup *lookup,int n){
  101889. int *bitrev=(int*) _ogg_malloc(sizeof(*bitrev)*(n/4));
  101890. DATA_TYPE *T=(DATA_TYPE*) _ogg_malloc(sizeof(*T)*(n+n/4));
  101891. int i;
  101892. int n2=n>>1;
  101893. int log2n=lookup->log2n=rint(log((float)n)/log(2.f));
  101894. lookup->n=n;
  101895. lookup->trig=T;
  101896. lookup->bitrev=bitrev;
  101897. for(i=0;i<n/4;i++){
  101898. T[i*2]=FLOAT_CONV(cos((M_PI/n)*(4*i)));
  101899. T[i*2+1]=FLOAT_CONV(-sin((M_PI/n)*(4*i)));
  101900. T[n2+i*2]=FLOAT_CONV(cos((M_PI/(2*n))*(2*i+1)));
  101901. T[n2+i*2+1]=FLOAT_CONV(sin((M_PI/(2*n))*(2*i+1)));
  101902. }
  101903. for(i=0;i<n/8;i++){
  101904. T[n+i*2]=FLOAT_CONV(cos((M_PI/n)*(4*i+2))*.5);
  101905. T[n+i*2+1]=FLOAT_CONV(-sin((M_PI/n)*(4*i+2))*.5);
  101906. }
  101907. {
  101908. int mask=(1<<(log2n-1))-1,i,j;
  101909. int msb=1<<(log2n-2);
  101910. for(i=0;i<n/8;i++){
  101911. int acc=0;
  101912. for(j=0;msb>>j;j++)
  101913. if((msb>>j)&i)acc|=1<<j;
  101914. bitrev[i*2]=((~acc)&mask)-1;
  101915. bitrev[i*2+1]=acc;
  101916. }
  101917. }
  101918. lookup->scale=FLOAT_CONV(4.f/n);
  101919. }
  101920. STIN void mdct_butterfly_8(DATA_TYPE *x){
  101921. REG_TYPE r0 = x[6] + x[2];
  101922. REG_TYPE r1 = x[6] - x[2];
  101923. REG_TYPE r2 = x[4] + x[0];
  101924. REG_TYPE r3 = x[4] - x[0];
  101925. x[6] = r0 + r2;
  101926. x[4] = r0 - r2;
  101927. r0 = x[5] - x[1];
  101928. r2 = x[7] - x[3];
  101929. x[0] = r1 + r0;
  101930. x[2] = r1 - r0;
  101931. r0 = x[5] + x[1];
  101932. r1 = x[7] + x[3];
  101933. x[3] = r2 + r3;
  101934. x[1] = r2 - r3;
  101935. x[7] = r1 + r0;
  101936. x[5] = r1 - r0;
  101937. }
  101938. STIN void mdct_butterfly_16(DATA_TYPE *x){
  101939. REG_TYPE r0 = x[1] - x[9];
  101940. REG_TYPE r1 = x[0] - x[8];
  101941. x[8] += x[0];
  101942. x[9] += x[1];
  101943. x[0] = MULT_NORM((r0 + r1) * cPI2_8);
  101944. x[1] = MULT_NORM((r0 - r1) * cPI2_8);
  101945. r0 = x[3] - x[11];
  101946. r1 = x[10] - x[2];
  101947. x[10] += x[2];
  101948. x[11] += x[3];
  101949. x[2] = r0;
  101950. x[3] = r1;
  101951. r0 = x[12] - x[4];
  101952. r1 = x[13] - x[5];
  101953. x[12] += x[4];
  101954. x[13] += x[5];
  101955. x[4] = MULT_NORM((r0 - r1) * cPI2_8);
  101956. x[5] = MULT_NORM((r0 + r1) * cPI2_8);
  101957. r0 = x[14] - x[6];
  101958. r1 = x[15] - x[7];
  101959. x[14] += x[6];
  101960. x[15] += x[7];
  101961. x[6] = r0;
  101962. x[7] = r1;
  101963. mdct_butterfly_8(x);
  101964. mdct_butterfly_8(x+8);
  101965. }
  101966. STIN void mdct_butterfly_32(DATA_TYPE *x){
  101967. REG_TYPE r0 = x[30] - x[14];
  101968. REG_TYPE r1 = x[31] - x[15];
  101969. x[30] += x[14];
  101970. x[31] += x[15];
  101971. x[14] = r0;
  101972. x[15] = r1;
  101973. r0 = x[28] - x[12];
  101974. r1 = x[29] - x[13];
  101975. x[28] += x[12];
  101976. x[29] += x[13];
  101977. x[12] = MULT_NORM( r0 * cPI1_8 - r1 * cPI3_8 );
  101978. x[13] = MULT_NORM( r0 * cPI3_8 + r1 * cPI1_8 );
  101979. r0 = x[26] - x[10];
  101980. r1 = x[27] - x[11];
  101981. x[26] += x[10];
  101982. x[27] += x[11];
  101983. x[10] = MULT_NORM(( r0 - r1 ) * cPI2_8);
  101984. x[11] = MULT_NORM(( r0 + r1 ) * cPI2_8);
  101985. r0 = x[24] - x[8];
  101986. r1 = x[25] - x[9];
  101987. x[24] += x[8];
  101988. x[25] += x[9];
  101989. x[8] = MULT_NORM( r0 * cPI3_8 - r1 * cPI1_8 );
  101990. x[9] = MULT_NORM( r1 * cPI3_8 + r0 * cPI1_8 );
  101991. r0 = x[22] - x[6];
  101992. r1 = x[7] - x[23];
  101993. x[22] += x[6];
  101994. x[23] += x[7];
  101995. x[6] = r1;
  101996. x[7] = r0;
  101997. r0 = x[4] - x[20];
  101998. r1 = x[5] - x[21];
  101999. x[20] += x[4];
  102000. x[21] += x[5];
  102001. x[4] = MULT_NORM( r1 * cPI1_8 + r0 * cPI3_8 );
  102002. x[5] = MULT_NORM( r1 * cPI3_8 - r0 * cPI1_8 );
  102003. r0 = x[2] - x[18];
  102004. r1 = x[3] - x[19];
  102005. x[18] += x[2];
  102006. x[19] += x[3];
  102007. x[2] = MULT_NORM(( r1 + r0 ) * cPI2_8);
  102008. x[3] = MULT_NORM(( r1 - r0 ) * cPI2_8);
  102009. r0 = x[0] - x[16];
  102010. r1 = x[1] - x[17];
  102011. x[16] += x[0];
  102012. x[17] += x[1];
  102013. x[0] = MULT_NORM( r1 * cPI3_8 + r0 * cPI1_8 );
  102014. x[1] = MULT_NORM( r1 * cPI1_8 - r0 * cPI3_8 );
  102015. mdct_butterfly_16(x);
  102016. mdct_butterfly_16(x+16);
  102017. }
  102018. STIN void mdct_butterfly_first(DATA_TYPE *T,
  102019. DATA_TYPE *x,
  102020. int points){
  102021. DATA_TYPE *x1 = x + points - 8;
  102022. DATA_TYPE *x2 = x + (points>>1) - 8;
  102023. REG_TYPE r0;
  102024. REG_TYPE r1;
  102025. do{
  102026. r0 = x1[6] - x2[6];
  102027. r1 = x1[7] - x2[7];
  102028. x1[6] += x2[6];
  102029. x1[7] += x2[7];
  102030. x2[6] = MULT_NORM(r1 * T[1] + r0 * T[0]);
  102031. x2[7] = MULT_NORM(r1 * T[0] - r0 * T[1]);
  102032. r0 = x1[4] - x2[4];
  102033. r1 = x1[5] - x2[5];
  102034. x1[4] += x2[4];
  102035. x1[5] += x2[5];
  102036. x2[4] = MULT_NORM(r1 * T[5] + r0 * T[4]);
  102037. x2[5] = MULT_NORM(r1 * T[4] - r0 * T[5]);
  102038. r0 = x1[2] - x2[2];
  102039. r1 = x1[3] - x2[3];
  102040. x1[2] += x2[2];
  102041. x1[3] += x2[3];
  102042. x2[2] = MULT_NORM(r1 * T[9] + r0 * T[8]);
  102043. x2[3] = MULT_NORM(r1 * T[8] - r0 * T[9]);
  102044. r0 = x1[0] - x2[0];
  102045. r1 = x1[1] - x2[1];
  102046. x1[0] += x2[0];
  102047. x1[1] += x2[1];
  102048. x2[0] = MULT_NORM(r1 * T[13] + r0 * T[12]);
  102049. x2[1] = MULT_NORM(r1 * T[12] - r0 * T[13]);
  102050. x1-=8;
  102051. x2-=8;
  102052. T+=16;
  102053. }while(x2>=x);
  102054. }
  102055. STIN void mdct_butterfly_generic(DATA_TYPE *T,
  102056. DATA_TYPE *x,
  102057. int points,
  102058. int trigint){
  102059. DATA_TYPE *x1 = x + points - 8;
  102060. DATA_TYPE *x2 = x + (points>>1) - 8;
  102061. REG_TYPE r0;
  102062. REG_TYPE r1;
  102063. do{
  102064. r0 = x1[6] - x2[6];
  102065. r1 = x1[7] - x2[7];
  102066. x1[6] += x2[6];
  102067. x1[7] += x2[7];
  102068. x2[6] = MULT_NORM(r1 * T[1] + r0 * T[0]);
  102069. x2[7] = MULT_NORM(r1 * T[0] - r0 * T[1]);
  102070. T+=trigint;
  102071. r0 = x1[4] - x2[4];
  102072. r1 = x1[5] - x2[5];
  102073. x1[4] += x2[4];
  102074. x1[5] += x2[5];
  102075. x2[4] = MULT_NORM(r1 * T[1] + r0 * T[0]);
  102076. x2[5] = MULT_NORM(r1 * T[0] - r0 * T[1]);
  102077. T+=trigint;
  102078. r0 = x1[2] - x2[2];
  102079. r1 = x1[3] - x2[3];
  102080. x1[2] += x2[2];
  102081. x1[3] += x2[3];
  102082. x2[2] = MULT_NORM(r1 * T[1] + r0 * T[0]);
  102083. x2[3] = MULT_NORM(r1 * T[0] - r0 * T[1]);
  102084. T+=trigint;
  102085. r0 = x1[0] - x2[0];
  102086. r1 = x1[1] - x2[1];
  102087. x1[0] += x2[0];
  102088. x1[1] += x2[1];
  102089. x2[0] = MULT_NORM(r1 * T[1] + r0 * T[0]);
  102090. x2[1] = MULT_NORM(r1 * T[0] - r0 * T[1]);
  102091. T+=trigint;
  102092. x1-=8;
  102093. x2-=8;
  102094. }while(x2>=x);
  102095. }
  102096. STIN void mdct_butterflies(mdct_lookup *init,
  102097. DATA_TYPE *x,
  102098. int points){
  102099. DATA_TYPE *T=init->trig;
  102100. int stages=init->log2n-5;
  102101. int i,j;
  102102. if(--stages>0){
  102103. mdct_butterfly_first(T,x,points);
  102104. }
  102105. for(i=1;--stages>0;i++){
  102106. for(j=0;j<(1<<i);j++)
  102107. mdct_butterfly_generic(T,x+(points>>i)*j,points>>i,4<<i);
  102108. }
  102109. for(j=0;j<points;j+=32)
  102110. mdct_butterfly_32(x+j);
  102111. }
  102112. void mdct_clear(mdct_lookup *l){
  102113. if(l){
  102114. if(l->trig)_ogg_free(l->trig);
  102115. if(l->bitrev)_ogg_free(l->bitrev);
  102116. memset(l,0,sizeof(*l));
  102117. }
  102118. }
  102119. STIN void mdct_bitreverse(mdct_lookup *init,
  102120. DATA_TYPE *x){
  102121. int n = init->n;
  102122. int *bit = init->bitrev;
  102123. DATA_TYPE *w0 = x;
  102124. DATA_TYPE *w1 = x = w0+(n>>1);
  102125. DATA_TYPE *T = init->trig+n;
  102126. do{
  102127. DATA_TYPE *x0 = x+bit[0];
  102128. DATA_TYPE *x1 = x+bit[1];
  102129. REG_TYPE r0 = x0[1] - x1[1];
  102130. REG_TYPE r1 = x0[0] + x1[0];
  102131. REG_TYPE r2 = MULT_NORM(r1 * T[0] + r0 * T[1]);
  102132. REG_TYPE r3 = MULT_NORM(r1 * T[1] - r0 * T[0]);
  102133. w1 -= 4;
  102134. r0 = HALVE(x0[1] + x1[1]);
  102135. r1 = HALVE(x0[0] - x1[0]);
  102136. w0[0] = r0 + r2;
  102137. w1[2] = r0 - r2;
  102138. w0[1] = r1 + r3;
  102139. w1[3] = r3 - r1;
  102140. x0 = x+bit[2];
  102141. x1 = x+bit[3];
  102142. r0 = x0[1] - x1[1];
  102143. r1 = x0[0] + x1[0];
  102144. r2 = MULT_NORM(r1 * T[2] + r0 * T[3]);
  102145. r3 = MULT_NORM(r1 * T[3] - r0 * T[2]);
  102146. r0 = HALVE(x0[1] + x1[1]);
  102147. r1 = HALVE(x0[0] - x1[0]);
  102148. w0[2] = r0 + r2;
  102149. w1[0] = r0 - r2;
  102150. w0[3] = r1 + r3;
  102151. w1[1] = r3 - r1;
  102152. T += 4;
  102153. bit += 4;
  102154. w0 += 4;
  102155. }while(w0<w1);
  102156. }
  102157. void mdct_backward(mdct_lookup *init, DATA_TYPE *in, DATA_TYPE *out){
  102158. int n=init->n;
  102159. int n2=n>>1;
  102160. int n4=n>>2;
  102161. DATA_TYPE *iX = in+n2-7;
  102162. DATA_TYPE *oX = out+n2+n4;
  102163. DATA_TYPE *T = init->trig+n4;
  102164. do{
  102165. oX -= 4;
  102166. oX[0] = MULT_NORM(-iX[2] * T[3] - iX[0] * T[2]);
  102167. oX[1] = MULT_NORM (iX[0] * T[3] - iX[2] * T[2]);
  102168. oX[2] = MULT_NORM(-iX[6] * T[1] - iX[4] * T[0]);
  102169. oX[3] = MULT_NORM (iX[4] * T[1] - iX[6] * T[0]);
  102170. iX -= 8;
  102171. T += 4;
  102172. }while(iX>=in);
  102173. iX = in+n2-8;
  102174. oX = out+n2+n4;
  102175. T = init->trig+n4;
  102176. do{
  102177. T -= 4;
  102178. oX[0] = MULT_NORM (iX[4] * T[3] + iX[6] * T[2]);
  102179. oX[1] = MULT_NORM (iX[4] * T[2] - iX[6] * T[3]);
  102180. oX[2] = MULT_NORM (iX[0] * T[1] + iX[2] * T[0]);
  102181. oX[3] = MULT_NORM (iX[0] * T[0] - iX[2] * T[1]);
  102182. iX -= 8;
  102183. oX += 4;
  102184. }while(iX>=in);
  102185. mdct_butterflies(init,out+n2,n2);
  102186. mdct_bitreverse(init,out);
  102187. {
  102188. DATA_TYPE *oX1=out+n2+n4;
  102189. DATA_TYPE *oX2=out+n2+n4;
  102190. DATA_TYPE *iX =out;
  102191. T =init->trig+n2;
  102192. do{
  102193. oX1-=4;
  102194. oX1[3] = MULT_NORM (iX[0] * T[1] - iX[1] * T[0]);
  102195. oX2[0] = -MULT_NORM (iX[0] * T[0] + iX[1] * T[1]);
  102196. oX1[2] = MULT_NORM (iX[2] * T[3] - iX[3] * T[2]);
  102197. oX2[1] = -MULT_NORM (iX[2] * T[2] + iX[3] * T[3]);
  102198. oX1[1] = MULT_NORM (iX[4] * T[5] - iX[5] * T[4]);
  102199. oX2[2] = -MULT_NORM (iX[4] * T[4] + iX[5] * T[5]);
  102200. oX1[0] = MULT_NORM (iX[6] * T[7] - iX[7] * T[6]);
  102201. oX2[3] = -MULT_NORM (iX[6] * T[6] + iX[7] * T[7]);
  102202. oX2+=4;
  102203. iX += 8;
  102204. T += 8;
  102205. }while(iX<oX1);
  102206. iX=out+n2+n4;
  102207. oX1=out+n4;
  102208. oX2=oX1;
  102209. do{
  102210. oX1-=4;
  102211. iX-=4;
  102212. oX2[0] = -(oX1[3] = iX[3]);
  102213. oX2[1] = -(oX1[2] = iX[2]);
  102214. oX2[2] = -(oX1[1] = iX[1]);
  102215. oX2[3] = -(oX1[0] = iX[0]);
  102216. oX2+=4;
  102217. }while(oX2<iX);
  102218. iX=out+n2+n4;
  102219. oX1=out+n2+n4;
  102220. oX2=out+n2;
  102221. do{
  102222. oX1-=4;
  102223. oX1[0]= iX[3];
  102224. oX1[1]= iX[2];
  102225. oX1[2]= iX[1];
  102226. oX1[3]= iX[0];
  102227. iX+=4;
  102228. }while(oX1>oX2);
  102229. }
  102230. }
  102231. void mdct_forward(mdct_lookup *init, DATA_TYPE *in, DATA_TYPE *out){
  102232. int n=init->n;
  102233. int n2=n>>1;
  102234. int n4=n>>2;
  102235. int n8=n>>3;
  102236. DATA_TYPE *w=(DATA_TYPE*) alloca(n*sizeof(*w)); /* forward needs working space */
  102237. DATA_TYPE *w2=w+n2;
  102238. REG_TYPE r0;
  102239. REG_TYPE r1;
  102240. DATA_TYPE *x0=in+n2+n4;
  102241. DATA_TYPE *x1=x0+1;
  102242. DATA_TYPE *T=init->trig+n2;
  102243. int i=0;
  102244. for(i=0;i<n8;i+=2){
  102245. x0 -=4;
  102246. T-=2;
  102247. r0= x0[2] + x1[0];
  102248. r1= x0[0] + x1[2];
  102249. w2[i]= MULT_NORM(r1*T[1] + r0*T[0]);
  102250. w2[i+1]= MULT_NORM(r1*T[0] - r0*T[1]);
  102251. x1 +=4;
  102252. }
  102253. x1=in+1;
  102254. for(;i<n2-n8;i+=2){
  102255. T-=2;
  102256. x0 -=4;
  102257. r0= x0[2] - x1[0];
  102258. r1= x0[0] - x1[2];
  102259. w2[i]= MULT_NORM(r1*T[1] + r0*T[0]);
  102260. w2[i+1]= MULT_NORM(r1*T[0] - r0*T[1]);
  102261. x1 +=4;
  102262. }
  102263. x0=in+n;
  102264. for(;i<n2;i+=2){
  102265. T-=2;
  102266. x0 -=4;
  102267. r0= -x0[2] - x1[0];
  102268. r1= -x0[0] - x1[2];
  102269. w2[i]= MULT_NORM(r1*T[1] + r0*T[0]);
  102270. w2[i+1]= MULT_NORM(r1*T[0] - r0*T[1]);
  102271. x1 +=4;
  102272. }
  102273. mdct_butterflies(init,w+n2,n2);
  102274. mdct_bitreverse(init,w);
  102275. T=init->trig+n2;
  102276. x0=out+n2;
  102277. for(i=0;i<n4;i++){
  102278. x0--;
  102279. out[i] =MULT_NORM((w[0]*T[0]+w[1]*T[1])*init->scale);
  102280. x0[0] =MULT_NORM((w[0]*T[1]-w[1]*T[0])*init->scale);
  102281. w+=2;
  102282. T+=2;
  102283. }
  102284. }
  102285. #endif
  102286. /*** End of inlined file: mdct.c ***/
  102287. /*** Start of inlined file: psy.c ***/
  102288. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  102289. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  102290. // tasks..
  102291. #if JUCE_MSVC
  102292. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  102293. #endif
  102294. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  102295. #if JUCE_USE_OGGVORBIS
  102296. #include <stdlib.h>
  102297. #include <math.h>
  102298. #include <string.h>
  102299. /*** Start of inlined file: masking.h ***/
  102300. #ifndef _V_MASKING_H_
  102301. #define _V_MASKING_H_
  102302. #define MAX_ATH 88
  102303. static float ATH[]={
  102304. -51, -52, -53, -54, -55, -56, -57, -58,
  102305. -59, -60, -61, -62, -63, -64, -65, -66,
  102306. -67, -68, -69, -70, -71, -72, -73, -74,
  102307. -75, -76, -77, -78, -80, -81, -82, -83,
  102308. -84, -85, -86, -87, -88, -88, -89, -89,
  102309. -90, -91, -91, -92, -93, -94, -95, -96,
  102310. -96, -97, -98, -98, -99, -99,-100,-100,
  102311. -101,-102,-103,-104,-106,-107,-107,-107,
  102312. -107,-105,-103,-102,-101, -99, -98, -96,
  102313. -95, -95, -96, -97, -96, -95, -93, -90,
  102314. -80, -70, -50, -40, -30, -30, -30, -30
  102315. };
  102316. #define EHMER_OFFSET 16
  102317. #define EHMER_MAX 56
  102318. static float tonemasks[P_BANDS][6][EHMER_MAX]={
  102319. {{ -60, -60, -60, -60, -60, -60, -60, -60,
  102320. -60, -60, -60, -60, -62, -62, -65, -73,
  102321. -69, -68, -68, -67, -70, -70, -72, -74,
  102322. -75, -79, -79, -80, -83, -88, -93, -100,
  102323. -110, -999, -999, -999, -999, -999, -999, -999,
  102324. -999, -999, -999, -999, -999, -999, -999, -999,
  102325. -999, -999, -999, -999, -999, -999, -999, -999},
  102326. { -48, -48, -48, -48, -48, -48, -48, -48,
  102327. -48, -48, -48, -48, -48, -53, -61, -66,
  102328. -66, -68, -67, -70, -76, -76, -72, -73,
  102329. -75, -76, -78, -79, -83, -88, -93, -100,
  102330. -110, -999, -999, -999, -999, -999, -999, -999,
  102331. -999, -999, -999, -999, -999, -999, -999, -999,
  102332. -999, -999, -999, -999, -999, -999, -999, -999},
  102333. { -37, -37, -37, -37, -37, -37, -37, -37,
  102334. -38, -40, -42, -46, -48, -53, -55, -62,
  102335. -65, -58, -56, -56, -61, -60, -65, -67,
  102336. -69, -71, -77, -77, -78, -80, -82, -84,
  102337. -88, -93, -98, -106, -112, -999, -999, -999,
  102338. -999, -999, -999, -999, -999, -999, -999, -999,
  102339. -999, -999, -999, -999, -999, -999, -999, -999},
  102340. { -25, -25, -25, -25, -25, -25, -25, -25,
  102341. -25, -26, -27, -29, -32, -38, -48, -52,
  102342. -52, -50, -48, -48, -51, -52, -54, -60,
  102343. -67, -67, -66, -68, -69, -73, -73, -76,
  102344. -80, -81, -81, -85, -85, -86, -88, -93,
  102345. -100, -110, -999, -999, -999, -999, -999, -999,
  102346. -999, -999, -999, -999, -999, -999, -999, -999},
  102347. { -16, -16, -16, -16, -16, -16, -16, -16,
  102348. -17, -19, -20, -22, -26, -28, -31, -40,
  102349. -47, -39, -39, -40, -42, -43, -47, -51,
  102350. -57, -52, -55, -55, -60, -58, -62, -63,
  102351. -70, -67, -69, -72, -73, -77, -80, -82,
  102352. -83, -87, -90, -94, -98, -104, -115, -999,
  102353. -999, -999, -999, -999, -999, -999, -999, -999},
  102354. { -8, -8, -8, -8, -8, -8, -8, -8,
  102355. -8, -8, -10, -11, -15, -19, -25, -30,
  102356. -34, -31, -30, -31, -29, -32, -35, -42,
  102357. -48, -42, -44, -46, -50, -50, -51, -52,
  102358. -59, -54, -55, -55, -58, -62, -63, -66,
  102359. -72, -73, -76, -75, -78, -80, -80, -81,
  102360. -84, -88, -90, -94, -98, -101, -106, -110}},
  102361. {{ -66, -66, -66, -66, -66, -66, -66, -66,
  102362. -66, -66, -66, -66, -66, -67, -67, -67,
  102363. -76, -72, -71, -74, -76, -76, -75, -78,
  102364. -79, -79, -81, -83, -86, -89, -93, -97,
  102365. -100, -105, -110, -999, -999, -999, -999, -999,
  102366. -999, -999, -999, -999, -999, -999, -999, -999,
  102367. -999, -999, -999, -999, -999, -999, -999, -999},
  102368. { -47, -47, -47, -47, -47, -47, -47, -47,
  102369. -47, -47, -47, -48, -51, -55, -59, -66,
  102370. -66, -66, -67, -66, -68, -69, -70, -74,
  102371. -79, -77, -77, -78, -80, -81, -82, -84,
  102372. -86, -88, -91, -95, -100, -108, -116, -999,
  102373. -999, -999, -999, -999, -999, -999, -999, -999,
  102374. -999, -999, -999, -999, -999, -999, -999, -999},
  102375. { -36, -36, -36, -36, -36, -36, -36, -36,
  102376. -36, -37, -37, -41, -44, -48, -51, -58,
  102377. -62, -60, -57, -59, -59, -60, -63, -65,
  102378. -72, -71, -70, -72, -74, -77, -76, -78,
  102379. -81, -81, -80, -83, -86, -91, -96, -100,
  102380. -105, -110, -999, -999, -999, -999, -999, -999,
  102381. -999, -999, -999, -999, -999, -999, -999, -999},
  102382. { -28, -28, -28, -28, -28, -28, -28, -28,
  102383. -28, -30, -32, -32, -33, -35, -41, -49,
  102384. -50, -49, -47, -48, -48, -52, -51, -57,
  102385. -65, -61, -59, -61, -64, -69, -70, -74,
  102386. -77, -77, -78, -81, -84, -85, -87, -90,
  102387. -92, -96, -100, -107, -112, -999, -999, -999,
  102388. -999, -999, -999, -999, -999, -999, -999, -999},
  102389. { -19, -19, -19, -19, -19, -19, -19, -19,
  102390. -20, -21, -23, -27, -30, -35, -36, -41,
  102391. -46, -44, -42, -40, -41, -41, -43, -48,
  102392. -55, -53, -52, -53, -56, -59, -58, -60,
  102393. -67, -66, -69, -71, -72, -75, -79, -81,
  102394. -84, -87, -90, -93, -97, -101, -107, -114,
  102395. -999, -999, -999, -999, -999, -999, -999, -999},
  102396. { -9, -9, -9, -9, -9, -9, -9, -9,
  102397. -11, -12, -12, -15, -16, -20, -23, -30,
  102398. -37, -34, -33, -34, -31, -32, -32, -38,
  102399. -47, -44, -41, -40, -47, -49, -46, -46,
  102400. -58, -50, -50, -54, -58, -62, -64, -67,
  102401. -67, -70, -72, -76, -79, -83, -87, -91,
  102402. -96, -100, -104, -110, -999, -999, -999, -999}},
  102403. {{ -62, -62, -62, -62, -62, -62, -62, -62,
  102404. -62, -62, -63, -64, -66, -67, -66, -68,
  102405. -75, -72, -76, -75, -76, -78, -79, -82,
  102406. -84, -85, -90, -94, -101, -110, -999, -999,
  102407. -999, -999, -999, -999, -999, -999, -999, -999,
  102408. -999, -999, -999, -999, -999, -999, -999, -999,
  102409. -999, -999, -999, -999, -999, -999, -999, -999},
  102410. { -59, -59, -59, -59, -59, -59, -59, -59,
  102411. -59, -59, -59, -60, -60, -61, -63, -66,
  102412. -71, -68, -70, -70, -71, -72, -72, -75,
  102413. -81, -78, -79, -82, -83, -86, -90, -97,
  102414. -103, -113, -999, -999, -999, -999, -999, -999,
  102415. -999, -999, -999, -999, -999, -999, -999, -999,
  102416. -999, -999, -999, -999, -999, -999, -999, -999},
  102417. { -53, -53, -53, -53, -53, -53, -53, -53,
  102418. -53, -54, -55, -57, -56, -57, -55, -61,
  102419. -65, -60, -60, -62, -63, -63, -66, -68,
  102420. -74, -73, -75, -75, -78, -80, -80, -82,
  102421. -85, -90, -96, -101, -108, -999, -999, -999,
  102422. -999, -999, -999, -999, -999, -999, -999, -999,
  102423. -999, -999, -999, -999, -999, -999, -999, -999},
  102424. { -46, -46, -46, -46, -46, -46, -46, -46,
  102425. -46, -46, -47, -47, -47, -47, -48, -51,
  102426. -57, -51, -49, -50, -51, -53, -54, -59,
  102427. -66, -60, -62, -67, -67, -70, -72, -75,
  102428. -76, -78, -81, -85, -88, -94, -97, -104,
  102429. -112, -999, -999, -999, -999, -999, -999, -999,
  102430. -999, -999, -999, -999, -999, -999, -999, -999},
  102431. { -36, -36, -36, -36, -36, -36, -36, -36,
  102432. -39, -41, -42, -42, -39, -38, -41, -43,
  102433. -52, -44, -40, -39, -37, -37, -40, -47,
  102434. -54, -50, -48, -50, -55, -61, -59, -62,
  102435. -66, -66, -66, -69, -69, -73, -74, -74,
  102436. -75, -77, -79, -82, -87, -91, -95, -100,
  102437. -108, -115, -999, -999, -999, -999, -999, -999},
  102438. { -28, -26, -24, -22, -20, -20, -23, -29,
  102439. -30, -31, -28, -27, -28, -28, -28, -35,
  102440. -40, -33, -32, -29, -30, -30, -30, -37,
  102441. -45, -41, -37, -38, -45, -47, -47, -48,
  102442. -53, -49, -48, -50, -49, -49, -51, -52,
  102443. -58, -56, -57, -56, -60, -61, -62, -70,
  102444. -72, -74, -78, -83, -88, -93, -100, -106}},
  102445. {{-999, -999, -999, -999, -999, -999, -999, -999,
  102446. -999, -110, -105, -100, -95, -91, -87, -83,
  102447. -80, -78, -76, -78, -78, -81, -83, -85,
  102448. -86, -85, -86, -87, -90, -97, -107, -999,
  102449. -999, -999, -999, -999, -999, -999, -999, -999,
  102450. -999, -999, -999, -999, -999, -999, -999, -999,
  102451. -999, -999, -999, -999, -999, -999, -999, -999},
  102452. {-999, -999, -999, -110, -105, -100, -95, -90,
  102453. -85, -81, -77, -73, -70, -67, -67, -68,
  102454. -75, -73, -70, -69, -70, -72, -75, -79,
  102455. -84, -83, -84, -86, -88, -89, -89, -93,
  102456. -98, -105, -112, -999, -999, -999, -999, -999,
  102457. -999, -999, -999, -999, -999, -999, -999, -999,
  102458. -999, -999, -999, -999, -999, -999, -999, -999},
  102459. {-105, -100, -95, -90, -85, -80, -76, -71,
  102460. -68, -68, -65, -63, -63, -62, -62, -64,
  102461. -65, -64, -61, -62, -63, -64, -66, -68,
  102462. -73, -73, -74, -75, -76, -81, -83, -85,
  102463. -88, -89, -92, -95, -100, -108, -999, -999,
  102464. -999, -999, -999, -999, -999, -999, -999, -999,
  102465. -999, -999, -999, -999, -999, -999, -999, -999},
  102466. { -80, -75, -71, -68, -65, -63, -62, -61,
  102467. -61, -61, -61, -59, -56, -57, -53, -50,
  102468. -58, -52, -50, -50, -52, -53, -54, -58,
  102469. -67, -63, -67, -68, -72, -75, -78, -80,
  102470. -81, -81, -82, -85, -89, -90, -93, -97,
  102471. -101, -107, -114, -999, -999, -999, -999, -999,
  102472. -999, -999, -999, -999, -999, -999, -999, -999},
  102473. { -65, -61, -59, -57, -56, -55, -55, -56,
  102474. -56, -57, -55, -53, -52, -47, -44, -44,
  102475. -50, -44, -41, -39, -39, -42, -40, -46,
  102476. -51, -49, -50, -53, -54, -63, -60, -61,
  102477. -62, -66, -66, -66, -70, -73, -74, -75,
  102478. -76, -75, -79, -85, -89, -91, -96, -102,
  102479. -110, -999, -999, -999, -999, -999, -999, -999},
  102480. { -52, -50, -49, -49, -48, -48, -48, -49,
  102481. -50, -50, -49, -46, -43, -39, -35, -33,
  102482. -38, -36, -32, -29, -32, -32, -32, -35,
  102483. -44, -39, -38, -38, -46, -50, -45, -46,
  102484. -53, -50, -50, -50, -54, -54, -53, -53,
  102485. -56, -57, -59, -66, -70, -72, -74, -79,
  102486. -83, -85, -90, -97, -114, -999, -999, -999}},
  102487. {{-999, -999, -999, -999, -999, -999, -110, -105,
  102488. -100, -95, -90, -86, -80, -75, -75, -79,
  102489. -80, -79, -80, -81, -82, -88, -95, -103,
  102490. -110, -999, -999, -999, -999, -999, -999, -999,
  102491. -999, -999, -999, -999, -999, -999, -999, -999,
  102492. -999, -999, -999, -999, -999, -999, -999, -999,
  102493. -999, -999, -999, -999, -999, -999, -999, -999},
  102494. {-999, -999, -999, -999, -108, -103, -98, -93,
  102495. -88, -83, -79, -78, -75, -71, -67, -68,
  102496. -73, -73, -72, -73, -75, -77, -80, -82,
  102497. -88, -93, -100, -107, -114, -999, -999, -999,
  102498. -999, -999, -999, -999, -999, -999, -999, -999,
  102499. -999, -999, -999, -999, -999, -999, -999, -999,
  102500. -999, -999, -999, -999, -999, -999, -999, -999},
  102501. {-999, -999, -999, -110, -105, -101, -96, -90,
  102502. -86, -81, -77, -73, -69, -66, -61, -62,
  102503. -66, -64, -62, -65, -66, -70, -72, -76,
  102504. -81, -80, -84, -90, -95, -102, -110, -999,
  102505. -999, -999, -999, -999, -999, -999, -999, -999,
  102506. -999, -999, -999, -999, -999, -999, -999, -999,
  102507. -999, -999, -999, -999, -999, -999, -999, -999},
  102508. {-999, -999, -999, -107, -103, -97, -92, -88,
  102509. -83, -79, -74, -70, -66, -59, -53, -58,
  102510. -62, -55, -54, -54, -54, -58, -61, -62,
  102511. -72, -70, -72, -75, -78, -80, -81, -80,
  102512. -83, -83, -88, -93, -100, -107, -115, -999,
  102513. -999, -999, -999, -999, -999, -999, -999, -999,
  102514. -999, -999, -999, -999, -999, -999, -999, -999},
  102515. {-999, -999, -999, -105, -100, -95, -90, -85,
  102516. -80, -75, -70, -66, -62, -56, -48, -44,
  102517. -48, -46, -46, -43, -46, -48, -48, -51,
  102518. -58, -58, -59, -60, -62, -62, -61, -61,
  102519. -65, -64, -65, -68, -70, -74, -75, -78,
  102520. -81, -86, -95, -110, -999, -999, -999, -999,
  102521. -999, -999, -999, -999, -999, -999, -999, -999},
  102522. {-999, -999, -105, -100, -95, -90, -85, -80,
  102523. -75, -70, -65, -61, -55, -49, -39, -33,
  102524. -40, -35, -32, -38, -40, -33, -35, -37,
  102525. -46, -41, -45, -44, -46, -42, -45, -46,
  102526. -52, -50, -50, -50, -54, -54, -55, -57,
  102527. -62, -64, -66, -68, -70, -76, -81, -90,
  102528. -100, -110, -999, -999, -999, -999, -999, -999}},
  102529. {{-999, -999, -999, -999, -999, -999, -999, -999,
  102530. -105, -98, -90, -85, -82, -83, -80, -78,
  102531. -84, -79, -80, -83, -87, -89, -91, -93,
  102532. -99, -106, -117, -999, -999, -999, -999, -999,
  102533. -999, -999, -999, -999, -999, -999, -999, -999,
  102534. -999, -999, -999, -999, -999, -999, -999, -999,
  102535. -999, -999, -999, -999, -999, -999, -999, -999},
  102536. {-999, -999, -999, -999, -999, -999, -999, -999,
  102537. -105, -98, -90, -85, -80, -75, -70, -68,
  102538. -74, -72, -74, -77, -80, -82, -85, -87,
  102539. -92, -89, -91, -95, -100, -106, -112, -999,
  102540. -999, -999, -999, -999, -999, -999, -999, -999,
  102541. -999, -999, -999, -999, -999, -999, -999, -999,
  102542. -999, -999, -999, -999, -999, -999, -999, -999},
  102543. {-999, -999, -999, -999, -999, -999, -999, -999,
  102544. -105, -98, -90, -83, -75, -71, -63, -64,
  102545. -67, -62, -64, -67, -70, -73, -77, -81,
  102546. -84, -83, -85, -89, -90, -93, -98, -104,
  102547. -109, -114, -999, -999, -999, -999, -999, -999,
  102548. -999, -999, -999, -999, -999, -999, -999, -999,
  102549. -999, -999, -999, -999, -999, -999, -999, -999},
  102550. {-999, -999, -999, -999, -999, -999, -999, -999,
  102551. -103, -96, -88, -81, -75, -68, -58, -54,
  102552. -56, -54, -56, -56, -58, -60, -63, -66,
  102553. -74, -69, -72, -72, -75, -74, -77, -81,
  102554. -81, -82, -84, -87, -93, -96, -99, -104,
  102555. -110, -999, -999, -999, -999, -999, -999, -999,
  102556. -999, -999, -999, -999, -999, -999, -999, -999},
  102557. {-999, -999, -999, -999, -999, -108, -102, -96,
  102558. -91, -85, -80, -74, -68, -60, -51, -46,
  102559. -48, -46, -43, -45, -47, -47, -49, -48,
  102560. -56, -53, -55, -58, -57, -63, -58, -60,
  102561. -66, -64, -67, -70, -70, -74, -77, -84,
  102562. -86, -89, -91, -93, -94, -101, -109, -118,
  102563. -999, -999, -999, -999, -999, -999, -999, -999},
  102564. {-999, -999, -999, -108, -103, -98, -93, -88,
  102565. -83, -78, -73, -68, -60, -53, -44, -35,
  102566. -38, -38, -34, -34, -36, -40, -41, -44,
  102567. -51, -45, -46, -47, -46, -54, -50, -49,
  102568. -50, -50, -50, -51, -54, -57, -58, -60,
  102569. -66, -66, -66, -64, -65, -68, -77, -82,
  102570. -87, -95, -110, -999, -999, -999, -999, -999}},
  102571. {{-999, -999, -999, -999, -999, -999, -999, -999,
  102572. -107, -102, -97, -92, -87, -83, -78, -75,
  102573. -82, -79, -83, -85, -89, -92, -95, -98,
  102574. -101, -105, -109, -113, -999, -999, -999, -999,
  102575. -999, -999, -999, -999, -999, -999, -999, -999,
  102576. -999, -999, -999, -999, -999, -999, -999, -999,
  102577. -999, -999, -999, -999, -999, -999, -999, -999},
  102578. {-999, -999, -999, -999, -999, -999, -999, -106,
  102579. -100, -95, -90, -86, -81, -78, -74, -69,
  102580. -74, -74, -76, -79, -83, -84, -86, -89,
  102581. -92, -97, -93, -100, -103, -107, -110, -999,
  102582. -999, -999, -999, -999, -999, -999, -999, -999,
  102583. -999, -999, -999, -999, -999, -999, -999, -999,
  102584. -999, -999, -999, -999, -999, -999, -999, -999},
  102585. {-999, -999, -999, -999, -999, -999, -106, -100,
  102586. -95, -90, -87, -83, -80, -75, -69, -60,
  102587. -66, -66, -68, -70, -74, -78, -79, -81,
  102588. -81, -83, -84, -87, -93, -96, -99, -103,
  102589. -107, -110, -999, -999, -999, -999, -999, -999,
  102590. -999, -999, -999, -999, -999, -999, -999, -999,
  102591. -999, -999, -999, -999, -999, -999, -999, -999},
  102592. {-999, -999, -999, -999, -999, -108, -103, -98,
  102593. -93, -89, -85, -82, -78, -71, -62, -55,
  102594. -58, -58, -54, -54, -55, -59, -61, -62,
  102595. -70, -66, -66, -67, -70, -72, -75, -78,
  102596. -84, -84, -84, -88, -91, -90, -95, -98,
  102597. -102, -103, -106, -110, -999, -999, -999, -999,
  102598. -999, -999, -999, -999, -999, -999, -999, -999},
  102599. {-999, -999, -999, -999, -108, -103, -98, -94,
  102600. -90, -87, -82, -79, -73, -67, -58, -47,
  102601. -50, -45, -41, -45, -48, -44, -44, -49,
  102602. -54, -51, -48, -47, -49, -50, -51, -57,
  102603. -58, -60, -63, -69, -70, -69, -71, -74,
  102604. -78, -82, -90, -95, -101, -105, -110, -999,
  102605. -999, -999, -999, -999, -999, -999, -999, -999},
  102606. {-999, -999, -999, -105, -101, -97, -93, -90,
  102607. -85, -80, -77, -72, -65, -56, -48, -37,
  102608. -40, -36, -34, -40, -50, -47, -38, -41,
  102609. -47, -38, -35, -39, -38, -43, -40, -45,
  102610. -50, -45, -44, -47, -50, -55, -48, -48,
  102611. -52, -66, -70, -76, -82, -90, -97, -105,
  102612. -110, -999, -999, -999, -999, -999, -999, -999}},
  102613. {{-999, -999, -999, -999, -999, -999, -999, -999,
  102614. -999, -108, -103, -98, -93, -86, -79, -76,
  102615. -83, -81, -85, -87, -89, -93, -98, -102,
  102616. -107, -112, -999, -999, -999, -999, -999, -999,
  102617. -999, -999, -999, -999, -999, -999, -999, -999,
  102618. -999, -999, -999, -999, -999, -999, -999, -999,
  102619. -999, -999, -999, -999, -999, -999, -999, -999},
  102620. {-999, -999, -999, -999, -999, -999, -999, -999,
  102621. -999, -108, -103, -98, -93, -86, -79, -71,
  102622. -77, -74, -77, -79, -81, -84, -85, -90,
  102623. -92, -93, -92, -98, -101, -108, -112, -999,
  102624. -999, -999, -999, -999, -999, -999, -999, -999,
  102625. -999, -999, -999, -999, -999, -999, -999, -999,
  102626. -999, -999, -999, -999, -999, -999, -999, -999},
  102627. {-999, -999, -999, -999, -999, -999, -999, -999,
  102628. -108, -103, -98, -93, -87, -78, -68, -65,
  102629. -66, -62, -65, -67, -70, -73, -75, -78,
  102630. -82, -82, -83, -84, -91, -93, -98, -102,
  102631. -106, -110, -999, -999, -999, -999, -999, -999,
  102632. -999, -999, -999, -999, -999, -999, -999, -999,
  102633. -999, -999, -999, -999, -999, -999, -999, -999},
  102634. {-999, -999, -999, -999, -999, -999, -999, -999,
  102635. -105, -100, -95, -90, -82, -74, -62, -57,
  102636. -58, -56, -51, -52, -52, -54, -54, -58,
  102637. -66, -59, -60, -63, -66, -69, -73, -79,
  102638. -83, -84, -80, -81, -81, -82, -88, -92,
  102639. -98, -105, -113, -999, -999, -999, -999, -999,
  102640. -999, -999, -999, -999, -999, -999, -999, -999},
  102641. {-999, -999, -999, -999, -999, -999, -999, -107,
  102642. -102, -97, -92, -84, -79, -69, -57, -47,
  102643. -52, -47, -44, -45, -50, -52, -42, -42,
  102644. -53, -43, -43, -48, -51, -56, -55, -52,
  102645. -57, -59, -61, -62, -67, -71, -78, -83,
  102646. -86, -94, -98, -103, -110, -999, -999, -999,
  102647. -999, -999, -999, -999, -999, -999, -999, -999},
  102648. {-999, -999, -999, -999, -999, -999, -105, -100,
  102649. -95, -90, -84, -78, -70, -61, -51, -41,
  102650. -40, -38, -40, -46, -52, -51, -41, -40,
  102651. -46, -40, -38, -38, -41, -46, -41, -46,
  102652. -47, -43, -43, -45, -41, -45, -56, -67,
  102653. -68, -83, -87, -90, -95, -102, -107, -113,
  102654. -999, -999, -999, -999, -999, -999, -999, -999}},
  102655. {{-999, -999, -999, -999, -999, -999, -999, -999,
  102656. -999, -109, -105, -101, -96, -91, -84, -77,
  102657. -82, -82, -85, -89, -94, -100, -106, -110,
  102658. -999, -999, -999, -999, -999, -999, -999, -999,
  102659. -999, -999, -999, -999, -999, -999, -999, -999,
  102660. -999, -999, -999, -999, -999, -999, -999, -999,
  102661. -999, -999, -999, -999, -999, -999, -999, -999},
  102662. {-999, -999, -999, -999, -999, -999, -999, -999,
  102663. -999, -106, -103, -98, -92, -85, -80, -71,
  102664. -75, -72, -76, -80, -84, -86, -89, -93,
  102665. -100, -107, -113, -999, -999, -999, -999, -999,
  102666. -999, -999, -999, -999, -999, -999, -999, -999,
  102667. -999, -999, -999, -999, -999, -999, -999, -999,
  102668. -999, -999, -999, -999, -999, -999, -999, -999},
  102669. {-999, -999, -999, -999, -999, -999, -999, -107,
  102670. -104, -101, -97, -92, -88, -84, -80, -64,
  102671. -66, -63, -64, -66, -69, -73, -77, -83,
  102672. -83, -86, -91, -98, -104, -111, -999, -999,
  102673. -999, -999, -999, -999, -999, -999, -999, -999,
  102674. -999, -999, -999, -999, -999, -999, -999, -999,
  102675. -999, -999, -999, -999, -999, -999, -999, -999},
  102676. {-999, -999, -999, -999, -999, -999, -999, -107,
  102677. -104, -101, -97, -92, -90, -84, -74, -57,
  102678. -58, -52, -55, -54, -50, -52, -50, -52,
  102679. -63, -62, -69, -76, -77, -78, -78, -79,
  102680. -82, -88, -94, -100, -106, -111, -999, -999,
  102681. -999, -999, -999, -999, -999, -999, -999, -999,
  102682. -999, -999, -999, -999, -999, -999, -999, -999},
  102683. {-999, -999, -999, -999, -999, -999, -106, -102,
  102684. -98, -95, -90, -85, -83, -78, -70, -50,
  102685. -50, -41, -44, -49, -47, -50, -50, -44,
  102686. -55, -46, -47, -48, -48, -54, -49, -49,
  102687. -58, -62, -71, -81, -87, -92, -97, -102,
  102688. -108, -114, -999, -999, -999, -999, -999, -999,
  102689. -999, -999, -999, -999, -999, -999, -999, -999},
  102690. {-999, -999, -999, -999, -999, -999, -106, -102,
  102691. -98, -95, -90, -85, -83, -78, -70, -45,
  102692. -43, -41, -47, -50, -51, -50, -49, -45,
  102693. -47, -41, -44, -41, -39, -43, -38, -37,
  102694. -40, -41, -44, -50, -58, -65, -73, -79,
  102695. -85, -92, -97, -101, -105, -109, -113, -999,
  102696. -999, -999, -999, -999, -999, -999, -999, -999}},
  102697. {{-999, -999, -999, -999, -999, -999, -999, -999,
  102698. -999, -999, -999, -107, -100, -95, -87, -81,
  102699. -85, -83, -88, -93, -100, -107, -114, -999,
  102700. -999, -999, -999, -999, -999, -999, -999, -999,
  102701. -999, -999, -999, -999, -999, -999, -999, -999,
  102702. -999, -999, -999, -999, -999, -999, -999, -999,
  102703. -999, -999, -999, -999, -999, -999, -999, -999},
  102704. {-999, -999, -999, -999, -999, -999, -999, -999,
  102705. -999, -999, -107, -101, -95, -88, -83, -76,
  102706. -73, -72, -79, -84, -90, -95, -100, -105,
  102707. -110, -115, -999, -999, -999, -999, -999, -999,
  102708. -999, -999, -999, -999, -999, -999, -999, -999,
  102709. -999, -999, -999, -999, -999, -999, -999, -999,
  102710. -999, -999, -999, -999, -999, -999, -999, -999},
  102711. {-999, -999, -999, -999, -999, -999, -999, -999,
  102712. -999, -999, -104, -98, -92, -87, -81, -70,
  102713. -65, -62, -67, -71, -74, -80, -85, -91,
  102714. -95, -99, -103, -108, -111, -114, -999, -999,
  102715. -999, -999, -999, -999, -999, -999, -999, -999,
  102716. -999, -999, -999, -999, -999, -999, -999, -999,
  102717. -999, -999, -999, -999, -999, -999, -999, -999},
  102718. {-999, -999, -999, -999, -999, -999, -999, -999,
  102719. -999, -999, -103, -97, -90, -85, -76, -60,
  102720. -56, -54, -60, -62, -61, -56, -63, -65,
  102721. -73, -74, -77, -75, -78, -81, -86, -87,
  102722. -88, -91, -94, -98, -103, -110, -999, -999,
  102723. -999, -999, -999, -999, -999, -999, -999, -999,
  102724. -999, -999, -999, -999, -999, -999, -999, -999},
  102725. {-999, -999, -999, -999, -999, -999, -999, -105,
  102726. -100, -97, -92, -86, -81, -79, -70, -57,
  102727. -51, -47, -51, -58, -60, -56, -53, -50,
  102728. -58, -52, -50, -50, -53, -55, -64, -69,
  102729. -71, -85, -82, -78, -81, -85, -95, -102,
  102730. -112, -999, -999, -999, -999, -999, -999, -999,
  102731. -999, -999, -999, -999, -999, -999, -999, -999},
  102732. {-999, -999, -999, -999, -999, -999, -999, -105,
  102733. -100, -97, -92, -85, -83, -79, -72, -49,
  102734. -40, -43, -43, -54, -56, -51, -50, -40,
  102735. -43, -38, -36, -35, -37, -38, -37, -44,
  102736. -54, -60, -57, -60, -70, -75, -84, -92,
  102737. -103, -112, -999, -999, -999, -999, -999, -999,
  102738. -999, -999, -999, -999, -999, -999, -999, -999}},
  102739. {{-999, -999, -999, -999, -999, -999, -999, -999,
  102740. -999, -999, -999, -110, -102, -95, -89, -82,
  102741. -83, -84, -90, -92, -99, -107, -113, -999,
  102742. -999, -999, -999, -999, -999, -999, -999, -999,
  102743. -999, -999, -999, -999, -999, -999, -999, -999,
  102744. -999, -999, -999, -999, -999, -999, -999, -999,
  102745. -999, -999, -999, -999, -999, -999, -999, -999},
  102746. {-999, -999, -999, -999, -999, -999, -999, -999,
  102747. -999, -999, -107, -101, -95, -89, -83, -72,
  102748. -74, -78, -85, -88, -88, -90, -92, -98,
  102749. -105, -111, -999, -999, -999, -999, -999, -999,
  102750. -999, -999, -999, -999, -999, -999, -999, -999,
  102751. -999, -999, -999, -999, -999, -999, -999, -999,
  102752. -999, -999, -999, -999, -999, -999, -999, -999},
  102753. {-999, -999, -999, -999, -999, -999, -999, -999,
  102754. -999, -109, -103, -97, -93, -87, -81, -70,
  102755. -70, -67, -75, -73, -76, -79, -81, -83,
  102756. -88, -89, -97, -103, -110, -999, -999, -999,
  102757. -999, -999, -999, -999, -999, -999, -999, -999,
  102758. -999, -999, -999, -999, -999, -999, -999, -999,
  102759. -999, -999, -999, -999, -999, -999, -999, -999},
  102760. {-999, -999, -999, -999, -999, -999, -999, -999,
  102761. -999, -107, -100, -94, -88, -83, -75, -63,
  102762. -59, -59, -63, -66, -60, -62, -67, -67,
  102763. -77, -76, -81, -88, -86, -92, -96, -102,
  102764. -109, -116, -999, -999, -999, -999, -999, -999,
  102765. -999, -999, -999, -999, -999, -999, -999, -999,
  102766. -999, -999, -999, -999, -999, -999, -999, -999},
  102767. {-999, -999, -999, -999, -999, -999, -999, -999,
  102768. -999, -105, -98, -92, -86, -81, -73, -56,
  102769. -52, -47, -55, -60, -58, -52, -51, -45,
  102770. -49, -50, -53, -54, -61, -71, -70, -69,
  102771. -78, -79, -87, -90, -96, -104, -112, -999,
  102772. -999, -999, -999, -999, -999, -999, -999, -999,
  102773. -999, -999, -999, -999, -999, -999, -999, -999},
  102774. {-999, -999, -999, -999, -999, -999, -999, -999,
  102775. -999, -103, -96, -90, -86, -78, -70, -51,
  102776. -42, -47, -48, -55, -54, -54, -53, -42,
  102777. -35, -28, -33, -38, -37, -44, -47, -49,
  102778. -54, -63, -68, -78, -82, -89, -94, -99,
  102779. -104, -109, -114, -999, -999, -999, -999, -999,
  102780. -999, -999, -999, -999, -999, -999, -999, -999}},
  102781. {{-999, -999, -999, -999, -999, -999, -999, -999,
  102782. -999, -999, -999, -999, -110, -100, -90, -79,
  102783. -85, -81, -82, -82, -89, -94, -99, -103,
  102784. -109, -115, -999, -999, -999, -999, -999, -999,
  102785. -999, -999, -999, -999, -999, -999, -999, -999,
  102786. -999, -999, -999, -999, -999, -999, -999, -999,
  102787. -999, -999, -999, -999, -999, -999, -999, -999},
  102788. {-999, -999, -999, -999, -999, -999, -999, -999,
  102789. -999, -999, -999, -999, -105, -97, -85, -72,
  102790. -74, -70, -70, -70, -76, -85, -91, -93,
  102791. -97, -103, -109, -115, -999, -999, -999, -999,
  102792. -999, -999, -999, -999, -999, -999, -999, -999,
  102793. -999, -999, -999, -999, -999, -999, -999, -999,
  102794. -999, -999, -999, -999, -999, -999, -999, -999},
  102795. {-999, -999, -999, -999, -999, -999, -999, -999,
  102796. -999, -999, -999, -999, -112, -93, -81, -68,
  102797. -62, -60, -60, -57, -63, -70, -77, -82,
  102798. -90, -93, -98, -104, -109, -113, -999, -999,
  102799. -999, -999, -999, -999, -999, -999, -999, -999,
  102800. -999, -999, -999, -999, -999, -999, -999, -999,
  102801. -999, -999, -999, -999, -999, -999, -999, -999},
  102802. {-999, -999, -999, -999, -999, -999, -999, -999,
  102803. -999, -999, -999, -113, -100, -93, -84, -63,
  102804. -58, -48, -53, -54, -52, -52, -57, -64,
  102805. -66, -76, -83, -81, -85, -85, -90, -95,
  102806. -98, -101, -103, -106, -108, -111, -999, -999,
  102807. -999, -999, -999, -999, -999, -999, -999, -999,
  102808. -999, -999, -999, -999, -999, -999, -999, -999},
  102809. {-999, -999, -999, -999, -999, -999, -999, -999,
  102810. -999, -999, -999, -105, -95, -86, -74, -53,
  102811. -50, -38, -43, -49, -43, -42, -39, -39,
  102812. -46, -52, -57, -56, -72, -69, -74, -81,
  102813. -87, -92, -94, -97, -99, -102, -105, -108,
  102814. -999, -999, -999, -999, -999, -999, -999, -999,
  102815. -999, -999, -999, -999, -999, -999, -999, -999},
  102816. {-999, -999, -999, -999, -999, -999, -999, -999,
  102817. -999, -999, -108, -99, -90, -76, -66, -45,
  102818. -43, -41, -44, -47, -43, -47, -40, -30,
  102819. -31, -31, -39, -33, -40, -41, -43, -53,
  102820. -59, -70, -73, -77, -79, -82, -84, -87,
  102821. -999, -999, -999, -999, -999, -999, -999, -999,
  102822. -999, -999, -999, -999, -999, -999, -999, -999}},
  102823. {{-999, -999, -999, -999, -999, -999, -999, -999,
  102824. -999, -999, -999, -999, -999, -110, -91, -76,
  102825. -75, -85, -93, -98, -104, -110, -999, -999,
  102826. -999, -999, -999, -999, -999, -999, -999, -999,
  102827. -999, -999, -999, -999, -999, -999, -999, -999,
  102828. -999, -999, -999, -999, -999, -999, -999, -999,
  102829. -999, -999, -999, -999, -999, -999, -999, -999},
  102830. {-999, -999, -999, -999, -999, -999, -999, -999,
  102831. -999, -999, -999, -999, -999, -110, -91, -70,
  102832. -70, -75, -86, -89, -94, -98, -101, -106,
  102833. -110, -999, -999, -999, -999, -999, -999, -999,
  102834. -999, -999, -999, -999, -999, -999, -999, -999,
  102835. -999, -999, -999, -999, -999, -999, -999, -999,
  102836. -999, -999, -999, -999, -999, -999, -999, -999},
  102837. {-999, -999, -999, -999, -999, -999, -999, -999,
  102838. -999, -999, -999, -999, -110, -95, -80, -60,
  102839. -65, -64, -74, -83, -88, -91, -95, -99,
  102840. -103, -107, -110, -999, -999, -999, -999, -999,
  102841. -999, -999, -999, -999, -999, -999, -999, -999,
  102842. -999, -999, -999, -999, -999, -999, -999, -999,
  102843. -999, -999, -999, -999, -999, -999, -999, -999},
  102844. {-999, -999, -999, -999, -999, -999, -999, -999,
  102845. -999, -999, -999, -999, -110, -95, -80, -58,
  102846. -55, -49, -66, -68, -71, -78, -78, -80,
  102847. -88, -85, -89, -97, -100, -105, -110, -999,
  102848. -999, -999, -999, -999, -999, -999, -999, -999,
  102849. -999, -999, -999, -999, -999, -999, -999, -999,
  102850. -999, -999, -999, -999, -999, -999, -999, -999},
  102851. {-999, -999, -999, -999, -999, -999, -999, -999,
  102852. -999, -999, -999, -999, -110, -95, -80, -53,
  102853. -52, -41, -59, -59, -49, -58, -56, -63,
  102854. -86, -79, -90, -93, -98, -103, -107, -112,
  102855. -999, -999, -999, -999, -999, -999, -999, -999,
  102856. -999, -999, -999, -999, -999, -999, -999, -999,
  102857. -999, -999, -999, -999, -999, -999, -999, -999},
  102858. {-999, -999, -999, -999, -999, -999, -999, -999,
  102859. -999, -999, -999, -110, -97, -91, -73, -45,
  102860. -40, -33, -53, -61, -49, -54, -50, -50,
  102861. -60, -52, -67, -74, -81, -92, -96, -100,
  102862. -105, -110, -999, -999, -999, -999, -999, -999,
  102863. -999, -999, -999, -999, -999, -999, -999, -999,
  102864. -999, -999, -999, -999, -999, -999, -999, -999}},
  102865. {{-999, -999, -999, -999, -999, -999, -999, -999,
  102866. -999, -999, -999, -113, -106, -99, -92, -77,
  102867. -80, -88, -97, -106, -115, -999, -999, -999,
  102868. -999, -999, -999, -999, -999, -999, -999, -999,
  102869. -999, -999, -999, -999, -999, -999, -999, -999,
  102870. -999, -999, -999, -999, -999, -999, -999, -999,
  102871. -999, -999, -999, -999, -999, -999, -999, -999},
  102872. {-999, -999, -999, -999, -999, -999, -999, -999,
  102873. -999, -999, -116, -109, -102, -95, -89, -74,
  102874. -72, -88, -87, -95, -102, -109, -116, -999,
  102875. -999, -999, -999, -999, -999, -999, -999, -999,
  102876. -999, -999, -999, -999, -999, -999, -999, -999,
  102877. -999, -999, -999, -999, -999, -999, -999, -999,
  102878. -999, -999, -999, -999, -999, -999, -999, -999},
  102879. {-999, -999, -999, -999, -999, -999, -999, -999,
  102880. -999, -999, -116, -109, -102, -95, -89, -75,
  102881. -66, -74, -77, -78, -86, -87, -90, -96,
  102882. -105, -115, -999, -999, -999, -999, -999, -999,
  102883. -999, -999, -999, -999, -999, -999, -999, -999,
  102884. -999, -999, -999, -999, -999, -999, -999, -999,
  102885. -999, -999, -999, -999, -999, -999, -999, -999},
  102886. {-999, -999, -999, -999, -999, -999, -999, -999,
  102887. -999, -999, -115, -108, -101, -94, -88, -66,
  102888. -56, -61, -70, -65, -78, -72, -83, -84,
  102889. -93, -98, -105, -110, -999, -999, -999, -999,
  102890. -999, -999, -999, -999, -999, -999, -999, -999,
  102891. -999, -999, -999, -999, -999, -999, -999, -999,
  102892. -999, -999, -999, -999, -999, -999, -999, -999},
  102893. {-999, -999, -999, -999, -999, -999, -999, -999,
  102894. -999, -999, -110, -105, -95, -89, -82, -57,
  102895. -52, -52, -59, -56, -59, -58, -69, -67,
  102896. -88, -82, -82, -89, -94, -100, -108, -999,
  102897. -999, -999, -999, -999, -999, -999, -999, -999,
  102898. -999, -999, -999, -999, -999, -999, -999, -999,
  102899. -999, -999, -999, -999, -999, -999, -999, -999},
  102900. {-999, -999, -999, -999, -999, -999, -999, -999,
  102901. -999, -110, -101, -96, -90, -83, -77, -54,
  102902. -43, -38, -50, -48, -52, -48, -42, -42,
  102903. -51, -52, -53, -59, -65, -71, -78, -85,
  102904. -95, -999, -999, -999, -999, -999, -999, -999,
  102905. -999, -999, -999, -999, -999, -999, -999, -999,
  102906. -999, -999, -999, -999, -999, -999, -999, -999}},
  102907. {{-999, -999, -999, -999, -999, -999, -999, -999,
  102908. -999, -999, -999, -999, -120, -105, -86, -68,
  102909. -78, -79, -90, -100, -110, -999, -999, -999,
  102910. -999, -999, -999, -999, -999, -999, -999, -999,
  102911. -999, -999, -999, -999, -999, -999, -999, -999,
  102912. -999, -999, -999, -999, -999, -999, -999, -999,
  102913. -999, -999, -999, -999, -999, -999, -999, -999},
  102914. {-999, -999, -999, -999, -999, -999, -999, -999,
  102915. -999, -999, -999, -999, -120, -105, -86, -66,
  102916. -73, -77, -88, -96, -105, -115, -999, -999,
  102917. -999, -999, -999, -999, -999, -999, -999, -999,
  102918. -999, -999, -999, -999, -999, -999, -999, -999,
  102919. -999, -999, -999, -999, -999, -999, -999, -999,
  102920. -999, -999, -999, -999, -999, -999, -999, -999},
  102921. {-999, -999, -999, -999, -999, -999, -999, -999,
  102922. -999, -999, -999, -120, -105, -92, -80, -61,
  102923. -64, -68, -80, -87, -92, -100, -110, -999,
  102924. -999, -999, -999, -999, -999, -999, -999, -999,
  102925. -999, -999, -999, -999, -999, -999, -999, -999,
  102926. -999, -999, -999, -999, -999, -999, -999, -999,
  102927. -999, -999, -999, -999, -999, -999, -999, -999},
  102928. {-999, -999, -999, -999, -999, -999, -999, -999,
  102929. -999, -999, -999, -120, -104, -91, -79, -52,
  102930. -60, -54, -64, -69, -77, -80, -82, -84,
  102931. -85, -87, -88, -90, -999, -999, -999, -999,
  102932. -999, -999, -999, -999, -999, -999, -999, -999,
  102933. -999, -999, -999, -999, -999, -999, -999, -999,
  102934. -999, -999, -999, -999, -999, -999, -999, -999},
  102935. {-999, -999, -999, -999, -999, -999, -999, -999,
  102936. -999, -999, -999, -118, -100, -87, -77, -49,
  102937. -50, -44, -58, -61, -61, -67, -65, -62,
  102938. -62, -62, -65, -68, -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, -999, -999, -999, -999,
  102943. -999, -999, -999, -115, -98, -84, -62, -49,
  102944. -44, -38, -46, -49, -49, -46, -39, -37,
  102945. -39, -40, -42, -43, -999, -999, -999, -999,
  102946. -999, -999, -999, -999, -999, -999, -999, -999,
  102947. -999, -999, -999, -999, -999, -999, -999, -999,
  102948. -999, -999, -999, -999, -999, -999, -999, -999}},
  102949. {{-999, -999, -999, -999, -999, -999, -999, -999,
  102950. -999, -999, -999, -999, -999, -110, -88, -74,
  102951. -77, -82, -82, -85, -90, -94, -99, -104,
  102952. -999, -999, -999, -999, -999, -999, -999, -999,
  102953. -999, -999, -999, -999, -999, -999, -999, -999,
  102954. -999, -999, -999, -999, -999, -999, -999, -999,
  102955. -999, -999, -999, -999, -999, -999, -999, -999},
  102956. {-999, -999, -999, -999, -999, -999, -999, -999,
  102957. -999, -999, -999, -999, -999, -110, -88, -66,
  102958. -70, -81, -80, -81, -84, -88, -91, -93,
  102959. -999, -999, -999, -999, -999, -999, -999, -999,
  102960. -999, -999, -999, -999, -999, -999, -999, -999,
  102961. -999, -999, -999, -999, -999, -999, -999, -999,
  102962. -999, -999, -999, -999, -999, -999, -999, -999},
  102963. {-999, -999, -999, -999, -999, -999, -999, -999,
  102964. -999, -999, -999, -999, -999, -110, -88, -61,
  102965. -63, -70, -71, -74, -77, -80, -83, -85,
  102966. -999, -999, -999, -999, -999, -999, -999, -999,
  102967. -999, -999, -999, -999, -999, -999, -999, -999,
  102968. -999, -999, -999, -999, -999, -999, -999, -999,
  102969. -999, -999, -999, -999, -999, -999, -999, -999},
  102970. {-999, -999, -999, -999, -999, -999, -999, -999,
  102971. -999, -999, -999, -999, -999, -110, -86, -62,
  102972. -63, -62, -62, -58, -52, -50, -50, -52,
  102973. -54, -999, -999, -999, -999, -999, -999, -999,
  102974. -999, -999, -999, -999, -999, -999, -999, -999,
  102975. -999, -999, -999, -999, -999, -999, -999, -999,
  102976. -999, -999, -999, -999, -999, -999, -999, -999},
  102977. {-999, -999, -999, -999, -999, -999, -999, -999,
  102978. -999, -999, -999, -999, -118, -108, -84, -53,
  102979. -50, -50, -50, -55, -47, -45, -40, -40,
  102980. -40, -999, -999, -999, -999, -999, -999, -999,
  102981. -999, -999, -999, -999, -999, -999, -999, -999,
  102982. -999, -999, -999, -999, -999, -999, -999, -999,
  102983. -999, -999, -999, -999, -999, -999, -999, -999},
  102984. {-999, -999, -999, -999, -999, -999, -999, -999,
  102985. -999, -999, -999, -999, -118, -100, -73, -43,
  102986. -37, -42, -43, -53, -38, -37, -35, -35,
  102987. -38, -999, -999, -999, -999, -999, -999, -999,
  102988. -999, -999, -999, -999, -999, -999, -999, -999,
  102989. -999, -999, -999, -999, -999, -999, -999, -999,
  102990. -999, -999, -999, -999, -999, -999, -999, -999}},
  102991. {{-999, -999, -999, -999, -999, -999, -999, -999,
  102992. -999, -999, -999, -110, -100, -91, -84, -74,
  102993. -80, -80, -80, -80, -80, -999, -999, -999,
  102994. -999, -999, -999, -999, -999, -999, -999, -999,
  102995. -999, -999, -999, -999, -999, -999, -999, -999,
  102996. -999, -999, -999, -999, -999, -999, -999, -999,
  102997. -999, -999, -999, -999, -999, -999, -999, -999},
  102998. {-999, -999, -999, -999, -999, -999, -999, -999,
  102999. -999, -999, -999, -110, -100, -91, -84, -74,
  103000. -68, -68, -68, -68, -68, -999, -999, -999,
  103001. -999, -999, -999, -999, -999, -999, -999, -999,
  103002. -999, -999, -999, -999, -999, -999, -999, -999,
  103003. -999, -999, -999, -999, -999, -999, -999, -999,
  103004. -999, -999, -999, -999, -999, -999, -999, -999},
  103005. {-999, -999, -999, -999, -999, -999, -999, -999,
  103006. -999, -999, -999, -110, -100, -86, -78, -70,
  103007. -60, -45, -30, -21, -999, -999, -999, -999,
  103008. -999, -999, -999, -999, -999, -999, -999, -999,
  103009. -999, -999, -999, -999, -999, -999, -999, -999,
  103010. -999, -999, -999, -999, -999, -999, -999, -999,
  103011. -999, -999, -999, -999, -999, -999, -999, -999},
  103012. {-999, -999, -999, -999, -999, -999, -999, -999,
  103013. -999, -999, -999, -110, -100, -87, -78, -67,
  103014. -48, -38, -29, -21, -999, -999, -999, -999,
  103015. -999, -999, -999, -999, -999, -999, -999, -999,
  103016. -999, -999, -999, -999, -999, -999, -999, -999,
  103017. -999, -999, -999, -999, -999, -999, -999, -999,
  103018. -999, -999, -999, -999, -999, -999, -999, -999},
  103019. {-999, -999, -999, -999, -999, -999, -999, -999,
  103020. -999, -999, -999, -110, -100, -86, -69, -56,
  103021. -45, -35, -33, -29, -999, -999, -999, -999,
  103022. -999, -999, -999, -999, -999, -999, -999, -999,
  103023. -999, -999, -999, -999, -999, -999, -999, -999,
  103024. -999, -999, -999, -999, -999, -999, -999, -999,
  103025. -999, -999, -999, -999, -999, -999, -999, -999},
  103026. {-999, -999, -999, -999, -999, -999, -999, -999,
  103027. -999, -999, -999, -110, -100, -83, -71, -48,
  103028. -27, -38, -37, -34, -999, -999, -999, -999,
  103029. -999, -999, -999, -999, -999, -999, -999, -999,
  103030. -999, -999, -999, -999, -999, -999, -999, -999,
  103031. -999, -999, -999, -999, -999, -999, -999, -999,
  103032. -999, -999, -999, -999, -999, -999, -999, -999}}
  103033. };
  103034. #endif
  103035. /*** End of inlined file: masking.h ***/
  103036. #define NEGINF -9999.f
  103037. static double stereo_threshholds[]={0.0, .5, 1.0, 1.5, 2.5, 4.5, 8.5, 16.5, 9e10};
  103038. static double stereo_threshholds_limited[]={0.0, .5, 1.0, 1.5, 2.0, 2.5, 4.5, 8.5, 9e10};
  103039. vorbis_look_psy_global *_vp_global_look(vorbis_info *vi){
  103040. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  103041. vorbis_info_psy_global *gi=&ci->psy_g_param;
  103042. vorbis_look_psy_global *look=(vorbis_look_psy_global*)_ogg_calloc(1,sizeof(*look));
  103043. look->channels=vi->channels;
  103044. look->ampmax=-9999.;
  103045. look->gi=gi;
  103046. return(look);
  103047. }
  103048. void _vp_global_free(vorbis_look_psy_global *look){
  103049. if(look){
  103050. memset(look,0,sizeof(*look));
  103051. _ogg_free(look);
  103052. }
  103053. }
  103054. void _vi_gpsy_free(vorbis_info_psy_global *i){
  103055. if(i){
  103056. memset(i,0,sizeof(*i));
  103057. _ogg_free(i);
  103058. }
  103059. }
  103060. void _vi_psy_free(vorbis_info_psy *i){
  103061. if(i){
  103062. memset(i,0,sizeof(*i));
  103063. _ogg_free(i);
  103064. }
  103065. }
  103066. static void min_curve(float *c,
  103067. float *c2){
  103068. int i;
  103069. for(i=0;i<EHMER_MAX;i++)if(c2[i]<c[i])c[i]=c2[i];
  103070. }
  103071. static void max_curve(float *c,
  103072. float *c2){
  103073. int i;
  103074. for(i=0;i<EHMER_MAX;i++)if(c2[i]>c[i])c[i]=c2[i];
  103075. }
  103076. static void attenuate_curve(float *c,float att){
  103077. int i;
  103078. for(i=0;i<EHMER_MAX;i++)
  103079. c[i]+=att;
  103080. }
  103081. static float ***setup_tone_curves(float curveatt_dB[P_BANDS],float binHz,int n,
  103082. float center_boost, float center_decay_rate){
  103083. int i,j,k,m;
  103084. float ath[EHMER_MAX];
  103085. float workc[P_BANDS][P_LEVELS][EHMER_MAX];
  103086. float athc[P_LEVELS][EHMER_MAX];
  103087. float *brute_buffer=(float*) alloca(n*sizeof(*brute_buffer));
  103088. float ***ret=(float***) _ogg_malloc(sizeof(*ret)*P_BANDS);
  103089. memset(workc,0,sizeof(workc));
  103090. for(i=0;i<P_BANDS;i++){
  103091. int ath_offset=i*4;
  103092. for(j=0;j<EHMER_MAX;j++){
  103093. float min=999.;
  103094. for(k=0;k<4;k++)
  103095. if(j+k+ath_offset<MAX_ATH){
  103096. if(min>ATH[j+k+ath_offset])min=ATH[j+k+ath_offset];
  103097. }else{
  103098. if(min>ATH[MAX_ATH-1])min=ATH[MAX_ATH-1];
  103099. }
  103100. ath[j]=min;
  103101. }
  103102. for(j=0;j<6;j++)
  103103. memcpy(workc[i][j+2],tonemasks[i][j],EHMER_MAX*sizeof(*tonemasks[i][j]));
  103104. memcpy(workc[i][0],tonemasks[i][0],EHMER_MAX*sizeof(*tonemasks[i][0]));
  103105. memcpy(workc[i][1],tonemasks[i][0],EHMER_MAX*sizeof(*tonemasks[i][0]));
  103106. for(j=0;j<P_LEVELS;j++){
  103107. for(k=0;k<EHMER_MAX;k++){
  103108. float adj=center_boost+abs(EHMER_OFFSET-k)*center_decay_rate;
  103109. if(adj<0. && center_boost>0)adj=0.;
  103110. if(adj>0. && center_boost<0)adj=0.;
  103111. workc[i][j][k]+=adj;
  103112. }
  103113. }
  103114. for(j=0;j<P_LEVELS;j++){
  103115. attenuate_curve(workc[i][j],curveatt_dB[i]+100.-(j<2?2:j)*10.-P_LEVEL_0);
  103116. memcpy(athc[j],ath,EHMER_MAX*sizeof(**athc));
  103117. attenuate_curve(athc[j],+100.-j*10.f-P_LEVEL_0);
  103118. max_curve(athc[j],workc[i][j]);
  103119. }
  103120. for(j=1;j<P_LEVELS;j++){
  103121. min_curve(athc[j],athc[j-1]);
  103122. min_curve(workc[i][j],athc[j]);
  103123. }
  103124. }
  103125. for(i=0;i<P_BANDS;i++){
  103126. int hi_curve,lo_curve,bin;
  103127. ret[i]=(float**)_ogg_malloc(sizeof(**ret)*P_LEVELS);
  103128. bin=floor(fromOC(i*.5)/binHz);
  103129. lo_curve= ceil(toOC(bin*binHz+1)*2);
  103130. hi_curve= floor(toOC((bin+1)*binHz)*2);
  103131. if(lo_curve>i)lo_curve=i;
  103132. if(lo_curve<0)lo_curve=0;
  103133. if(hi_curve>=P_BANDS)hi_curve=P_BANDS-1;
  103134. for(m=0;m<P_LEVELS;m++){
  103135. ret[i][m]=(float*)_ogg_malloc(sizeof(***ret)*(EHMER_MAX+2));
  103136. for(j=0;j<n;j++)brute_buffer[j]=999.;
  103137. for(k=lo_curve;k<=hi_curve;k++){
  103138. int l=0;
  103139. for(j=0;j<EHMER_MAX;j++){
  103140. int lo_bin= fromOC(j*.125+k*.5-2.0625)/binHz;
  103141. int hi_bin= fromOC(j*.125+k*.5-1.9375)/binHz+1;
  103142. if(lo_bin<0)lo_bin=0;
  103143. if(lo_bin>n)lo_bin=n;
  103144. if(lo_bin<l)l=lo_bin;
  103145. if(hi_bin<0)hi_bin=0;
  103146. if(hi_bin>n)hi_bin=n;
  103147. for(;l<hi_bin && l<n;l++)
  103148. if(brute_buffer[l]>workc[k][m][j])
  103149. brute_buffer[l]=workc[k][m][j];
  103150. }
  103151. for(;l<n;l++)
  103152. if(brute_buffer[l]>workc[k][m][EHMER_MAX-1])
  103153. brute_buffer[l]=workc[k][m][EHMER_MAX-1];
  103154. }
  103155. if(i+1<P_BANDS){
  103156. int l=0;
  103157. k=i+1;
  103158. for(j=0;j<EHMER_MAX;j++){
  103159. int lo_bin= fromOC(j*.125+i*.5-2.0625)/binHz;
  103160. int hi_bin= fromOC(j*.125+i*.5-1.9375)/binHz+1;
  103161. if(lo_bin<0)lo_bin=0;
  103162. if(lo_bin>n)lo_bin=n;
  103163. if(lo_bin<l)l=lo_bin;
  103164. if(hi_bin<0)hi_bin=0;
  103165. if(hi_bin>n)hi_bin=n;
  103166. for(;l<hi_bin && l<n;l++)
  103167. if(brute_buffer[l]>workc[k][m][j])
  103168. brute_buffer[l]=workc[k][m][j];
  103169. }
  103170. for(;l<n;l++)
  103171. if(brute_buffer[l]>workc[k][m][EHMER_MAX-1])
  103172. brute_buffer[l]=workc[k][m][EHMER_MAX-1];
  103173. }
  103174. for(j=0;j<EHMER_MAX;j++){
  103175. int bin=fromOC(j*.125+i*.5-2.)/binHz;
  103176. if(bin<0){
  103177. ret[i][m][j+2]=-999.;
  103178. }else{
  103179. if(bin>=n){
  103180. ret[i][m][j+2]=-999.;
  103181. }else{
  103182. ret[i][m][j+2]=brute_buffer[bin];
  103183. }
  103184. }
  103185. }
  103186. for(j=0;j<EHMER_OFFSET;j++)
  103187. if(ret[i][m][j+2]>-200.f)break;
  103188. ret[i][m][0]=j;
  103189. for(j=EHMER_MAX-1;j>EHMER_OFFSET+1;j--)
  103190. if(ret[i][m][j+2]>-200.f)
  103191. break;
  103192. ret[i][m][1]=j;
  103193. }
  103194. }
  103195. return(ret);
  103196. }
  103197. void _vp_psy_init(vorbis_look_psy *p,vorbis_info_psy *vi,
  103198. vorbis_info_psy_global *gi,int n,long rate){
  103199. long i,j,lo=-99,hi=1;
  103200. long maxoc;
  103201. memset(p,0,sizeof(*p));
  103202. p->eighth_octave_lines=gi->eighth_octave_lines;
  103203. p->shiftoc=rint(log(gi->eighth_octave_lines*8.f)/log(2.f))-1;
  103204. p->firstoc=toOC(.25f*rate*.5/n)*(1<<(p->shiftoc+1))-gi->eighth_octave_lines;
  103205. maxoc=toOC((n+.25f)*rate*.5/n)*(1<<(p->shiftoc+1))+.5f;
  103206. p->total_octave_lines=maxoc-p->firstoc+1;
  103207. p->ath=(float*)_ogg_malloc(n*sizeof(*p->ath));
  103208. p->octave=(long*)_ogg_malloc(n*sizeof(*p->octave));
  103209. p->bark=(long*)_ogg_malloc(n*sizeof(*p->bark));
  103210. p->vi=vi;
  103211. p->n=n;
  103212. p->rate=rate;
  103213. p->m_val = 1.;
  103214. if(rate < 26000) p->m_val = 0;
  103215. else if(rate < 38000) p->m_val = .94; /* 32kHz */
  103216. else if(rate > 46000) p->m_val = 1.275; /* 48kHz */
  103217. for(i=0,j=0;i<MAX_ATH-1;i++){
  103218. int endpos=rint(fromOC((i+1)*.125-2.)*2*n/rate);
  103219. float base=ATH[i];
  103220. if(j<endpos){
  103221. float delta=(ATH[i+1]-base)/(endpos-j);
  103222. for(;j<endpos && j<n;j++){
  103223. p->ath[j]=base+100.;
  103224. base+=delta;
  103225. }
  103226. }
  103227. }
  103228. for(i=0;i<n;i++){
  103229. float bark=toBARK(rate/(2*n)*i);
  103230. for(;lo+vi->noisewindowlomin<i &&
  103231. toBARK(rate/(2*n)*lo)<(bark-vi->noisewindowlo);lo++);
  103232. for(;hi<=n && (hi<i+vi->noisewindowhimin ||
  103233. toBARK(rate/(2*n)*hi)<(bark+vi->noisewindowhi));hi++);
  103234. p->bark[i]=((lo-1)<<16)+(hi-1);
  103235. }
  103236. for(i=0;i<n;i++)
  103237. p->octave[i]=toOC((i+.25f)*.5*rate/n)*(1<<(p->shiftoc+1))+.5f;
  103238. p->tonecurves=setup_tone_curves(vi->toneatt,rate*.5/n,n,
  103239. vi->tone_centerboost,vi->tone_decay);
  103240. p->noiseoffset=(float**)_ogg_malloc(P_NOISECURVES*sizeof(*p->noiseoffset));
  103241. for(i=0;i<P_NOISECURVES;i++)
  103242. p->noiseoffset[i]=(float*)_ogg_malloc(n*sizeof(**p->noiseoffset));
  103243. for(i=0;i<n;i++){
  103244. float halfoc=toOC((i+.5)*rate/(2.*n))*2.;
  103245. int inthalfoc;
  103246. float del;
  103247. if(halfoc<0)halfoc=0;
  103248. if(halfoc>=P_BANDS-1)halfoc=P_BANDS-1;
  103249. inthalfoc=(int)halfoc;
  103250. del=halfoc-inthalfoc;
  103251. for(j=0;j<P_NOISECURVES;j++)
  103252. p->noiseoffset[j][i]=
  103253. p->vi->noiseoff[j][inthalfoc]*(1.-del) +
  103254. p->vi->noiseoff[j][inthalfoc+1]*del;
  103255. }
  103256. #if 0
  103257. {
  103258. static int ls=0;
  103259. _analysis_output_always("noiseoff0",ls,p->noiseoffset[0],n,1,0,0);
  103260. _analysis_output_always("noiseoff1",ls,p->noiseoffset[1],n,1,0,0);
  103261. _analysis_output_always("noiseoff2",ls++,p->noiseoffset[2],n,1,0,0);
  103262. }
  103263. #endif
  103264. }
  103265. void _vp_psy_clear(vorbis_look_psy *p){
  103266. int i,j;
  103267. if(p){
  103268. if(p->ath)_ogg_free(p->ath);
  103269. if(p->octave)_ogg_free(p->octave);
  103270. if(p->bark)_ogg_free(p->bark);
  103271. if(p->tonecurves){
  103272. for(i=0;i<P_BANDS;i++){
  103273. for(j=0;j<P_LEVELS;j++){
  103274. _ogg_free(p->tonecurves[i][j]);
  103275. }
  103276. _ogg_free(p->tonecurves[i]);
  103277. }
  103278. _ogg_free(p->tonecurves);
  103279. }
  103280. if(p->noiseoffset){
  103281. for(i=0;i<P_NOISECURVES;i++){
  103282. _ogg_free(p->noiseoffset[i]);
  103283. }
  103284. _ogg_free(p->noiseoffset);
  103285. }
  103286. memset(p,0,sizeof(*p));
  103287. }
  103288. }
  103289. static void seed_curve(float *seed,
  103290. const float **curves,
  103291. float amp,
  103292. int oc, int n,
  103293. int linesper,float dBoffset){
  103294. int i,post1;
  103295. int seedptr;
  103296. const float *posts,*curve;
  103297. int choice=(int)((amp+dBoffset-P_LEVEL_0)*.1f);
  103298. choice=max(choice,0);
  103299. choice=min(choice,P_LEVELS-1);
  103300. posts=curves[choice];
  103301. curve=posts+2;
  103302. post1=(int)posts[1];
  103303. seedptr=oc+(posts[0]-EHMER_OFFSET)*linesper-(linesper>>1);
  103304. for(i=posts[0];i<post1;i++){
  103305. if(seedptr>0){
  103306. float lin=amp+curve[i];
  103307. if(seed[seedptr]<lin)seed[seedptr]=lin;
  103308. }
  103309. seedptr+=linesper;
  103310. if(seedptr>=n)break;
  103311. }
  103312. }
  103313. static void seed_loop(vorbis_look_psy *p,
  103314. const float ***curves,
  103315. const float *f,
  103316. const float *flr,
  103317. float *seed,
  103318. float specmax){
  103319. vorbis_info_psy *vi=p->vi;
  103320. long n=p->n,i;
  103321. float dBoffset=vi->max_curve_dB-specmax;
  103322. for(i=0;i<n;i++){
  103323. float max=f[i];
  103324. long oc=p->octave[i];
  103325. while(i+1<n && p->octave[i+1]==oc){
  103326. i++;
  103327. if(f[i]>max)max=f[i];
  103328. }
  103329. if(max+6.f>flr[i]){
  103330. oc=oc>>p->shiftoc;
  103331. if(oc>=P_BANDS)oc=P_BANDS-1;
  103332. if(oc<0)oc=0;
  103333. seed_curve(seed,
  103334. curves[oc],
  103335. max,
  103336. p->octave[i]-p->firstoc,
  103337. p->total_octave_lines,
  103338. p->eighth_octave_lines,
  103339. dBoffset);
  103340. }
  103341. }
  103342. }
  103343. static void seed_chase(float *seeds, int linesper, long n){
  103344. long *posstack=(long*)alloca(n*sizeof(*posstack));
  103345. float *ampstack=(float*)alloca(n*sizeof(*ampstack));
  103346. long stack=0;
  103347. long pos=0;
  103348. long i;
  103349. for(i=0;i<n;i++){
  103350. if(stack<2){
  103351. posstack[stack]=i;
  103352. ampstack[stack++]=seeds[i];
  103353. }else{
  103354. while(1){
  103355. if(seeds[i]<ampstack[stack-1]){
  103356. posstack[stack]=i;
  103357. ampstack[stack++]=seeds[i];
  103358. break;
  103359. }else{
  103360. if(i<posstack[stack-1]+linesper){
  103361. if(stack>1 && ampstack[stack-1]<=ampstack[stack-2] &&
  103362. i<posstack[stack-2]+linesper){
  103363. stack--;
  103364. continue;
  103365. }
  103366. }
  103367. posstack[stack]=i;
  103368. ampstack[stack++]=seeds[i];
  103369. break;
  103370. }
  103371. }
  103372. }
  103373. }
  103374. for(i=0;i<stack;i++){
  103375. long endpos;
  103376. if(i<stack-1 && ampstack[i+1]>ampstack[i]){
  103377. endpos=posstack[i+1];
  103378. }else{
  103379. endpos=posstack[i]+linesper+1; /* +1 is important, else bin 0 is
  103380. discarded in short frames */
  103381. }
  103382. if(endpos>n)endpos=n;
  103383. for(;pos<endpos;pos++)
  103384. seeds[pos]=ampstack[i];
  103385. }
  103386. }
  103387. #include<stdio.h>
  103388. static void max_seeds(vorbis_look_psy *p,
  103389. float *seed,
  103390. float *flr){
  103391. long n=p->total_octave_lines;
  103392. int linesper=p->eighth_octave_lines;
  103393. long linpos=0;
  103394. long pos;
  103395. seed_chase(seed,linesper,n); /* for masking */
  103396. pos=p->octave[0]-p->firstoc-(linesper>>1);
  103397. while(linpos+1<p->n){
  103398. float minV=seed[pos];
  103399. long end=((p->octave[linpos]+p->octave[linpos+1])>>1)-p->firstoc;
  103400. if(minV>p->vi->tone_abs_limit)minV=p->vi->tone_abs_limit;
  103401. while(pos+1<=end){
  103402. pos++;
  103403. if((seed[pos]>NEGINF && seed[pos]<minV) || minV==NEGINF)
  103404. minV=seed[pos];
  103405. }
  103406. end=pos+p->firstoc;
  103407. for(;linpos<p->n && p->octave[linpos]<=end;linpos++)
  103408. if(flr[linpos]<minV)flr[linpos]=minV;
  103409. }
  103410. {
  103411. float minV=seed[p->total_octave_lines-1];
  103412. for(;linpos<p->n;linpos++)
  103413. if(flr[linpos]<minV)flr[linpos]=minV;
  103414. }
  103415. }
  103416. static void bark_noise_hybridmp(int n,const long *b,
  103417. const float *f,
  103418. float *noise,
  103419. const float offset,
  103420. const int fixed){
  103421. float *N=(float*) alloca(n*sizeof(*N));
  103422. float *X=(float*) alloca(n*sizeof(*N));
  103423. float *XX=(float*) alloca(n*sizeof(*N));
  103424. float *Y=(float*) alloca(n*sizeof(*N));
  103425. float *XY=(float*) alloca(n*sizeof(*N));
  103426. float tN, tX, tXX, tY, tXY;
  103427. int i;
  103428. int lo, hi;
  103429. float R, A, B, D;
  103430. float w, x, y;
  103431. tN = tX = tXX = tY = tXY = 0.f;
  103432. y = f[0] + offset;
  103433. if (y < 1.f) y = 1.f;
  103434. w = y * y * .5;
  103435. tN += w;
  103436. tX += w;
  103437. tY += w * y;
  103438. N[0] = tN;
  103439. X[0] = tX;
  103440. XX[0] = tXX;
  103441. Y[0] = tY;
  103442. XY[0] = tXY;
  103443. for (i = 1, x = 1.f; i < n; i++, x += 1.f) {
  103444. y = f[i] + offset;
  103445. if (y < 1.f) y = 1.f;
  103446. w = y * y;
  103447. tN += w;
  103448. tX += w * x;
  103449. tXX += w * x * x;
  103450. tY += w * y;
  103451. tXY += w * x * y;
  103452. N[i] = tN;
  103453. X[i] = tX;
  103454. XX[i] = tXX;
  103455. Y[i] = tY;
  103456. XY[i] = tXY;
  103457. }
  103458. for (i = 0, x = 0.f;; i++, x += 1.f) {
  103459. lo = b[i] >> 16;
  103460. if( lo>=0 ) break;
  103461. hi = b[i] & 0xffff;
  103462. tN = N[hi] + N[-lo];
  103463. tX = X[hi] - X[-lo];
  103464. tXX = XX[hi] + XX[-lo];
  103465. tY = Y[hi] + Y[-lo];
  103466. tXY = XY[hi] - XY[-lo];
  103467. A = tY * tXX - tX * tXY;
  103468. B = tN * tXY - tX * tY;
  103469. D = tN * tXX - tX * tX;
  103470. R = (A + x * B) / D;
  103471. if (R < 0.f)
  103472. R = 0.f;
  103473. noise[i] = R - offset;
  103474. }
  103475. for ( ;; i++, x += 1.f) {
  103476. lo = b[i] >> 16;
  103477. hi = b[i] & 0xffff;
  103478. if(hi>=n)break;
  103479. tN = N[hi] - N[lo];
  103480. tX = X[hi] - X[lo];
  103481. tXX = XX[hi] - XX[lo];
  103482. tY = Y[hi] - Y[lo];
  103483. tXY = XY[hi] - XY[lo];
  103484. A = tY * tXX - tX * tXY;
  103485. B = tN * tXY - tX * tY;
  103486. D = tN * tXX - tX * tX;
  103487. R = (A + x * B) / D;
  103488. if (R < 0.f) R = 0.f;
  103489. noise[i] = R - offset;
  103490. }
  103491. for ( ; i < n; i++, x += 1.f) {
  103492. R = (A + x * B) / D;
  103493. if (R < 0.f) R = 0.f;
  103494. noise[i] = R - offset;
  103495. }
  103496. if (fixed <= 0) return;
  103497. for (i = 0, x = 0.f;; i++, x += 1.f) {
  103498. hi = i + fixed / 2;
  103499. lo = hi - fixed;
  103500. if(lo>=0)break;
  103501. tN = N[hi] + N[-lo];
  103502. tX = X[hi] - X[-lo];
  103503. tXX = XX[hi] + XX[-lo];
  103504. tY = Y[hi] + Y[-lo];
  103505. tXY = XY[hi] - XY[-lo];
  103506. A = tY * tXX - tX * tXY;
  103507. B = tN * tXY - tX * tY;
  103508. D = tN * tXX - tX * tX;
  103509. R = (A + x * B) / D;
  103510. if (R - offset < noise[i]) noise[i] = R - offset;
  103511. }
  103512. for ( ;; i++, x += 1.f) {
  103513. hi = i + fixed / 2;
  103514. lo = hi - fixed;
  103515. if(hi>=n)break;
  103516. tN = N[hi] - N[lo];
  103517. tX = X[hi] - X[lo];
  103518. tXX = XX[hi] - XX[lo];
  103519. tY = Y[hi] - Y[lo];
  103520. tXY = XY[hi] - XY[lo];
  103521. A = tY * tXX - tX * tXY;
  103522. B = tN * tXY - tX * tY;
  103523. D = tN * tXX - tX * tX;
  103524. R = (A + x * B) / D;
  103525. if (R - offset < noise[i]) noise[i] = R - offset;
  103526. }
  103527. for ( ; i < n; i++, x += 1.f) {
  103528. R = (A + x * B) / D;
  103529. if (R - offset < noise[i]) noise[i] = R - offset;
  103530. }
  103531. }
  103532. static float FLOOR1_fromdB_INV_LOOKUP[256]={
  103533. 0.F, 8.81683e+06F, 8.27882e+06F, 7.77365e+06F,
  103534. 7.29930e+06F, 6.85389e+06F, 6.43567e+06F, 6.04296e+06F,
  103535. 5.67422e+06F, 5.32798e+06F, 5.00286e+06F, 4.69759e+06F,
  103536. 4.41094e+06F, 4.14178e+06F, 3.88905e+06F, 3.65174e+06F,
  103537. 3.42891e+06F, 3.21968e+06F, 3.02321e+06F, 2.83873e+06F,
  103538. 2.66551e+06F, 2.50286e+06F, 2.35014e+06F, 2.20673e+06F,
  103539. 2.07208e+06F, 1.94564e+06F, 1.82692e+06F, 1.71544e+06F,
  103540. 1.61076e+06F, 1.51247e+06F, 1.42018e+06F, 1.33352e+06F,
  103541. 1.25215e+06F, 1.17574e+06F, 1.10400e+06F, 1.03663e+06F,
  103542. 973377.F, 913981.F, 858210.F, 805842.F,
  103543. 756669.F, 710497.F, 667142.F, 626433.F,
  103544. 588208.F, 552316.F, 518613.F, 486967.F,
  103545. 457252.F, 429351.F, 403152.F, 378551.F,
  103546. 355452.F, 333762.F, 313396.F, 294273.F,
  103547. 276316.F, 259455.F, 243623.F, 228757.F,
  103548. 214798.F, 201691.F, 189384.F, 177828.F,
  103549. 166977.F, 156788.F, 147221.F, 138237.F,
  103550. 129802.F, 121881.F, 114444.F, 107461.F,
  103551. 100903.F, 94746.3F, 88964.9F, 83536.2F,
  103552. 78438.8F, 73652.5F, 69158.2F, 64938.1F,
  103553. 60975.6F, 57254.9F, 53761.2F, 50480.6F,
  103554. 47400.3F, 44507.9F, 41792.0F, 39241.9F,
  103555. 36847.3F, 34598.9F, 32487.7F, 30505.3F,
  103556. 28643.8F, 26896.0F, 25254.8F, 23713.7F,
  103557. 22266.7F, 20908.0F, 19632.2F, 18434.2F,
  103558. 17309.4F, 16253.1F, 15261.4F, 14330.1F,
  103559. 13455.7F, 12634.6F, 11863.7F, 11139.7F,
  103560. 10460.0F, 9821.72F, 9222.39F, 8659.64F,
  103561. 8131.23F, 7635.06F, 7169.17F, 6731.70F,
  103562. 6320.93F, 5935.23F, 5573.06F, 5232.99F,
  103563. 4913.67F, 4613.84F, 4332.30F, 4067.94F,
  103564. 3819.72F, 3586.64F, 3367.78F, 3162.28F,
  103565. 2969.31F, 2788.13F, 2617.99F, 2458.24F,
  103566. 2308.24F, 2167.39F, 2035.14F, 1910.95F,
  103567. 1794.35F, 1684.85F, 1582.04F, 1485.51F,
  103568. 1394.86F, 1309.75F, 1229.83F, 1154.78F,
  103569. 1084.32F, 1018.15F, 956.024F, 897.687F,
  103570. 842.910F, 791.475F, 743.179F, 697.830F,
  103571. 655.249F, 615.265F, 577.722F, 542.469F,
  103572. 509.367F, 478.286F, 449.101F, 421.696F,
  103573. 395.964F, 371.803F, 349.115F, 327.812F,
  103574. 307.809F, 289.026F, 271.390F, 254.830F,
  103575. 239.280F, 224.679F, 210.969F, 198.096F,
  103576. 186.008F, 174.658F, 164.000F, 153.993F,
  103577. 144.596F, 135.773F, 127.488F, 119.708F,
  103578. 112.404F, 105.545F, 99.1046F, 93.0572F,
  103579. 87.3788F, 82.0469F, 77.0404F, 72.3394F,
  103580. 67.9252F, 63.7804F, 59.8885F, 56.2341F,
  103581. 52.8027F, 49.5807F, 46.5553F, 43.7144F,
  103582. 41.0470F, 38.5423F, 36.1904F, 33.9821F,
  103583. 31.9085F, 29.9614F, 28.1332F, 26.4165F,
  103584. 24.8045F, 23.2910F, 21.8697F, 20.5352F,
  103585. 19.2822F, 18.1056F, 17.0008F, 15.9634F,
  103586. 14.9893F, 14.0746F, 13.2158F, 12.4094F,
  103587. 11.6522F, 10.9411F, 10.2735F, 9.64662F,
  103588. 9.05798F, 8.50526F, 7.98626F, 7.49894F,
  103589. 7.04135F, 6.61169F, 6.20824F, 5.82941F,
  103590. 5.47370F, 5.13970F, 4.82607F, 4.53158F,
  103591. 4.25507F, 3.99542F, 3.75162F, 3.52269F,
  103592. 3.30774F, 3.10590F, 2.91638F, 2.73842F,
  103593. 2.57132F, 2.41442F, 2.26709F, 2.12875F,
  103594. 1.99885F, 1.87688F, 1.76236F, 1.65482F,
  103595. 1.55384F, 1.45902F, 1.36999F, 1.28640F,
  103596. 1.20790F, 1.13419F, 1.06499F, 1.F
  103597. };
  103598. void _vp_remove_floor(vorbis_look_psy *p,
  103599. float *mdct,
  103600. int *codedflr,
  103601. float *residue,
  103602. int sliding_lowpass){
  103603. int i,n=p->n;
  103604. if(sliding_lowpass>n)sliding_lowpass=n;
  103605. for(i=0;i<sliding_lowpass;i++){
  103606. residue[i]=
  103607. mdct[i]*FLOOR1_fromdB_INV_LOOKUP[codedflr[i]];
  103608. }
  103609. for(;i<n;i++)
  103610. residue[i]=0.;
  103611. }
  103612. void _vp_noisemask(vorbis_look_psy *p,
  103613. float *logmdct,
  103614. float *logmask){
  103615. int i,n=p->n;
  103616. float *work=(float*) alloca(n*sizeof(*work));
  103617. bark_noise_hybridmp(n,p->bark,logmdct,logmask,
  103618. 140.,-1);
  103619. for(i=0;i<n;i++)work[i]=logmdct[i]-logmask[i];
  103620. bark_noise_hybridmp(n,p->bark,work,logmask,0.,
  103621. p->vi->noisewindowfixed);
  103622. for(i=0;i<n;i++)work[i]=logmdct[i]-work[i];
  103623. #if 0
  103624. {
  103625. static int seq=0;
  103626. float work2[n];
  103627. for(i=0;i<n;i++){
  103628. work2[i]=logmask[i]+work[i];
  103629. }
  103630. if(seq&1)
  103631. _analysis_output("median2R",seq/2,work,n,1,0,0);
  103632. else
  103633. _analysis_output("median2L",seq/2,work,n,1,0,0);
  103634. if(seq&1)
  103635. _analysis_output("envelope2R",seq/2,work2,n,1,0,0);
  103636. else
  103637. _analysis_output("envelope2L",seq/2,work2,n,1,0,0);
  103638. seq++;
  103639. }
  103640. #endif
  103641. for(i=0;i<n;i++){
  103642. int dB=logmask[i]+.5;
  103643. if(dB>=NOISE_COMPAND_LEVELS)dB=NOISE_COMPAND_LEVELS-1;
  103644. if(dB<0)dB=0;
  103645. logmask[i]= work[i]+p->vi->noisecompand[dB];
  103646. }
  103647. }
  103648. void _vp_tonemask(vorbis_look_psy *p,
  103649. float *logfft,
  103650. float *logmask,
  103651. float global_specmax,
  103652. float local_specmax){
  103653. int i,n=p->n;
  103654. float *seed=(float*) alloca(sizeof(*seed)*p->total_octave_lines);
  103655. float att=local_specmax+p->vi->ath_adjatt;
  103656. for(i=0;i<p->total_octave_lines;i++)seed[i]=NEGINF;
  103657. if(att<p->vi->ath_maxatt)att=p->vi->ath_maxatt;
  103658. for(i=0;i<n;i++)
  103659. logmask[i]=p->ath[i]+att;
  103660. seed_loop(p,(const float ***)p->tonecurves,logfft,logmask,seed,global_specmax);
  103661. max_seeds(p,seed,logmask);
  103662. }
  103663. void _vp_offset_and_mix(vorbis_look_psy *p,
  103664. float *noise,
  103665. float *tone,
  103666. int offset_select,
  103667. float *logmask,
  103668. float *mdct,
  103669. float *logmdct){
  103670. int i,n=p->n;
  103671. float de, coeffi, cx;/* AoTuV */
  103672. float toneatt=p->vi->tone_masteratt[offset_select];
  103673. cx = p->m_val;
  103674. for(i=0;i<n;i++){
  103675. float val= noise[i]+p->noiseoffset[offset_select][i];
  103676. if(val>p->vi->noisemaxsupp)val=p->vi->noisemaxsupp;
  103677. logmask[i]=max(val,tone[i]+toneatt);
  103678. if(offset_select == 1) {
  103679. coeffi = -17.2; /* coeffi is a -17.2dB threshold */
  103680. val = val - logmdct[i]; /* val == mdct line value relative to floor in dB */
  103681. if(val > coeffi){
  103682. de = 1.0-((val-coeffi)*0.005*cx);
  103683. if(de < 0) de = 0.0001;
  103684. }else
  103685. de = 1.0-((val-coeffi)*0.0003*cx);
  103686. mdct[i] *= de;
  103687. }
  103688. }
  103689. }
  103690. float _vp_ampmax_decay(float amp,vorbis_dsp_state *vd){
  103691. vorbis_info *vi=vd->vi;
  103692. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  103693. vorbis_info_psy_global *gi=&ci->psy_g_param;
  103694. int n=ci->blocksizes[vd->W]/2;
  103695. float secs=(float)n/vi->rate;
  103696. amp+=secs*gi->ampmax_att_per_sec;
  103697. if(amp<-9999)amp=-9999;
  103698. return(amp);
  103699. }
  103700. static void couple_lossless(float A, float B,
  103701. float *qA, float *qB){
  103702. int test1=fabs(*qA)>fabs(*qB);
  103703. test1-= fabs(*qA)<fabs(*qB);
  103704. if(!test1)test1=((fabs(A)>fabs(B))<<1)-1;
  103705. if(test1==1){
  103706. *qB=(*qA>0.f?*qA-*qB:*qB-*qA);
  103707. }else{
  103708. float temp=*qB;
  103709. *qB=(*qB>0.f?*qA-*qB:*qB-*qA);
  103710. *qA=temp;
  103711. }
  103712. if(*qB>fabs(*qA)*1.9999f){
  103713. *qB= -fabs(*qA)*2.f;
  103714. *qA= -*qA;
  103715. }
  103716. }
  103717. static float hypot_lookup[32]={
  103718. -0.009935, -0.011245, -0.012726, -0.014397,
  103719. -0.016282, -0.018407, -0.020800, -0.023494,
  103720. -0.026522, -0.029923, -0.033737, -0.038010,
  103721. -0.042787, -0.048121, -0.054064, -0.060671,
  103722. -0.068000, -0.076109, -0.085054, -0.094892,
  103723. -0.105675, -0.117451, -0.130260, -0.144134,
  103724. -0.159093, -0.175146, -0.192286, -0.210490,
  103725. -0.229718, -0.249913, -0.271001, -0.292893};
  103726. static void precomputed_couple_point(float premag,
  103727. int floorA,int floorB,
  103728. float *mag, float *ang){
  103729. int test=(floorA>floorB)-1;
  103730. int offset=31-abs(floorA-floorB);
  103731. float floormag=hypot_lookup[((offset<0)-1)&offset]+1.f;
  103732. floormag*=FLOOR1_fromdB_INV_LOOKUP[(floorB&test)|(floorA&(~test))];
  103733. *mag=premag*floormag;
  103734. *ang=0.f;
  103735. }
  103736. static float dipole_hypot(float a, float b){
  103737. if(a>0.){
  103738. if(b>0.)return sqrt(a*a+b*b);
  103739. if(a>-b)return sqrt(a*a-b*b);
  103740. return -sqrt(b*b-a*a);
  103741. }
  103742. if(b<0.)return -sqrt(a*a+b*b);
  103743. if(-a>b)return -sqrt(a*a-b*b);
  103744. return sqrt(b*b-a*a);
  103745. }
  103746. static float round_hypot(float a, float b){
  103747. if(a>0.){
  103748. if(b>0.)return sqrt(a*a+b*b);
  103749. if(a>-b)return sqrt(a*a+b*b);
  103750. return -sqrt(b*b+a*a);
  103751. }
  103752. if(b<0.)return -sqrt(a*a+b*b);
  103753. if(-a>b)return -sqrt(a*a+b*b);
  103754. return sqrt(b*b+a*a);
  103755. }
  103756. float **_vp_quantize_couple_memo(vorbis_block *vb,
  103757. vorbis_info_psy_global *g,
  103758. vorbis_look_psy *p,
  103759. vorbis_info_mapping0 *vi,
  103760. float **mdct){
  103761. int i,j,n=p->n;
  103762. float **ret=(float**) _vorbis_block_alloc(vb,vi->coupling_steps*sizeof(*ret));
  103763. int limit=g->coupling_pointlimit[p->vi->blockflag][PACKETBLOBS/2];
  103764. for(i=0;i<vi->coupling_steps;i++){
  103765. float *mdctM=mdct[vi->coupling_mag[i]];
  103766. float *mdctA=mdct[vi->coupling_ang[i]];
  103767. ret[i]=(float*) _vorbis_block_alloc(vb,n*sizeof(**ret));
  103768. for(j=0;j<limit;j++)
  103769. ret[i][j]=dipole_hypot(mdctM[j],mdctA[j]);
  103770. for(;j<n;j++)
  103771. ret[i][j]=round_hypot(mdctM[j],mdctA[j]);
  103772. }
  103773. return(ret);
  103774. }
  103775. static int apsort(const void *a, const void *b){
  103776. float f1=fabs(**(float**)a);
  103777. float f2=fabs(**(float**)b);
  103778. return (f1<f2)-(f1>f2);
  103779. }
  103780. int **_vp_quantize_couple_sort(vorbis_block *vb,
  103781. vorbis_look_psy *p,
  103782. vorbis_info_mapping0 *vi,
  103783. float **mags){
  103784. if(p->vi->normal_point_p){
  103785. int i,j,k,n=p->n;
  103786. int **ret=(int**) _vorbis_block_alloc(vb,vi->coupling_steps*sizeof(*ret));
  103787. int partition=p->vi->normal_partition;
  103788. float **work=(float**) alloca(sizeof(*work)*partition);
  103789. for(i=0;i<vi->coupling_steps;i++){
  103790. ret[i]=(int*) _vorbis_block_alloc(vb,n*sizeof(**ret));
  103791. for(j=0;j<n;j+=partition){
  103792. for(k=0;k<partition;k++)work[k]=mags[i]+k+j;
  103793. qsort(work,partition,sizeof(*work),apsort);
  103794. for(k=0;k<partition;k++)ret[i][k+j]=work[k]-mags[i];
  103795. }
  103796. }
  103797. return(ret);
  103798. }
  103799. return(NULL);
  103800. }
  103801. void _vp_noise_normalize_sort(vorbis_look_psy *p,
  103802. float *magnitudes,int *sortedindex){
  103803. int i,j,n=p->n;
  103804. vorbis_info_psy *vi=p->vi;
  103805. int partition=vi->normal_partition;
  103806. float **work=(float**) alloca(sizeof(*work)*partition);
  103807. int start=vi->normal_start;
  103808. for(j=start;j<n;j+=partition){
  103809. if(j+partition>n)partition=n-j;
  103810. for(i=0;i<partition;i++)work[i]=magnitudes+i+j;
  103811. qsort(work,partition,sizeof(*work),apsort);
  103812. for(i=0;i<partition;i++){
  103813. sortedindex[i+j-start]=work[i]-magnitudes;
  103814. }
  103815. }
  103816. }
  103817. void _vp_noise_normalize(vorbis_look_psy *p,
  103818. float *in,float *out,int *sortedindex){
  103819. int flag=0,i,j=0,n=p->n;
  103820. vorbis_info_psy *vi=p->vi;
  103821. int partition=vi->normal_partition;
  103822. int start=vi->normal_start;
  103823. if(start>n)start=n;
  103824. if(vi->normal_channel_p){
  103825. for(;j<start;j++)
  103826. out[j]=rint(in[j]);
  103827. for(;j+partition<=n;j+=partition){
  103828. float acc=0.;
  103829. int k;
  103830. for(i=j;i<j+partition;i++)
  103831. acc+=in[i]*in[i];
  103832. for(i=0;i<partition;i++){
  103833. k=sortedindex[i+j-start];
  103834. if(in[k]*in[k]>=.25f){
  103835. out[k]=rint(in[k]);
  103836. acc-=in[k]*in[k];
  103837. flag=1;
  103838. }else{
  103839. if(acc<vi->normal_thresh)break;
  103840. out[k]=unitnorm(in[k]);
  103841. acc-=1.;
  103842. }
  103843. }
  103844. for(;i<partition;i++){
  103845. k=sortedindex[i+j-start];
  103846. out[k]=0.;
  103847. }
  103848. }
  103849. }
  103850. for(;j<n;j++)
  103851. out[j]=rint(in[j]);
  103852. }
  103853. void _vp_couple(int blobno,
  103854. vorbis_info_psy_global *g,
  103855. vorbis_look_psy *p,
  103856. vorbis_info_mapping0 *vi,
  103857. float **res,
  103858. float **mag_memo,
  103859. int **mag_sort,
  103860. int **ifloor,
  103861. int *nonzero,
  103862. int sliding_lowpass){
  103863. int i,j,k,n=p->n;
  103864. for(i=0;i<vi->coupling_steps;i++){
  103865. if(nonzero[vi->coupling_mag[i]] ||
  103866. nonzero[vi->coupling_ang[i]]){
  103867. float *rM=res[vi->coupling_mag[i]];
  103868. float *rA=res[vi->coupling_ang[i]];
  103869. float *qM=rM+n;
  103870. float *qA=rA+n;
  103871. int *floorM=ifloor[vi->coupling_mag[i]];
  103872. int *floorA=ifloor[vi->coupling_ang[i]];
  103873. float prepoint=stereo_threshholds[g->coupling_prepointamp[blobno]];
  103874. float postpoint=stereo_threshholds[g->coupling_postpointamp[blobno]];
  103875. int partition=(p->vi->normal_point_p?p->vi->normal_partition:p->n);
  103876. int limit=g->coupling_pointlimit[p->vi->blockflag][blobno];
  103877. int pointlimit=limit;
  103878. nonzero[vi->coupling_mag[i]]=1;
  103879. nonzero[vi->coupling_ang[i]]=1;
  103880. if(n > 1000)
  103881. postpoint=stereo_threshholds_limited[g->coupling_postpointamp[blobno]];
  103882. for(j=0;j<p->n;j+=partition){
  103883. float acc=0.f;
  103884. for(k=0;k<partition;k++){
  103885. int l=k+j;
  103886. if(l<sliding_lowpass){
  103887. if((l>=limit && fabs(rM[l])<postpoint && fabs(rA[l])<postpoint) ||
  103888. (fabs(rM[l])<prepoint && fabs(rA[l])<prepoint)){
  103889. precomputed_couple_point(mag_memo[i][l],
  103890. floorM[l],floorA[l],
  103891. qM+l,qA+l);
  103892. if(rint(qM[l])==0.f)acc+=qM[l]*qM[l];
  103893. }else{
  103894. couple_lossless(rM[l],rA[l],qM+l,qA+l);
  103895. }
  103896. }else{
  103897. qM[l]=0.;
  103898. qA[l]=0.;
  103899. }
  103900. }
  103901. if(p->vi->normal_point_p){
  103902. for(k=0;k<partition && acc>=p->vi->normal_thresh;k++){
  103903. int l=mag_sort[i][j+k];
  103904. if(l<sliding_lowpass && l>=pointlimit && rint(qM[l])==0.f){
  103905. qM[l]=unitnorm(qM[l]);
  103906. acc-=1.f;
  103907. }
  103908. }
  103909. }
  103910. }
  103911. }
  103912. }
  103913. }
  103914. void hf_reduction(vorbis_info_psy_global *g,
  103915. vorbis_look_psy *p,
  103916. vorbis_info_mapping0 *vi,
  103917. float **mdct){
  103918. int i,j,n=p->n, de=0.3*p->m_val;
  103919. int limit=g->coupling_pointlimit[p->vi->blockflag][PACKETBLOBS/2];
  103920. for(i=0; i<vi->coupling_steps; i++){
  103921. for(j=limit; j<n; j++)
  103922. mdct[i][j] *= (1.0 - de*((float)(j-limit) / (float)(n-limit)));
  103923. }
  103924. }
  103925. #endif
  103926. /*** End of inlined file: psy.c ***/
  103927. /*** Start of inlined file: registry.c ***/
  103928. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  103929. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  103930. // tasks..
  103931. #if JUCE_MSVC
  103932. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  103933. #endif
  103934. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  103935. #if JUCE_USE_OGGVORBIS
  103936. extern vorbis_func_floor floor0_exportbundle;
  103937. extern vorbis_func_floor floor1_exportbundle;
  103938. extern vorbis_func_residue residue0_exportbundle;
  103939. extern vorbis_func_residue residue1_exportbundle;
  103940. extern vorbis_func_residue residue2_exportbundle;
  103941. extern vorbis_func_mapping mapping0_exportbundle;
  103942. vorbis_func_floor *_floor_P[]={
  103943. &floor0_exportbundle,
  103944. &floor1_exportbundle,
  103945. };
  103946. vorbis_func_residue *_residue_P[]={
  103947. &residue0_exportbundle,
  103948. &residue1_exportbundle,
  103949. &residue2_exportbundle,
  103950. };
  103951. vorbis_func_mapping *_mapping_P[]={
  103952. &mapping0_exportbundle,
  103953. };
  103954. #endif
  103955. /*** End of inlined file: registry.c ***/
  103956. /*** Start of inlined file: res0.c ***/
  103957. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  103958. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  103959. // tasks..
  103960. #if JUCE_MSVC
  103961. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  103962. #endif
  103963. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  103964. #if JUCE_USE_OGGVORBIS
  103965. #include <stdlib.h>
  103966. #include <string.h>
  103967. #include <math.h>
  103968. #if defined(TRAIN_RES) || defined (TRAIN_RESAUX)
  103969. #include <stdio.h>
  103970. #endif
  103971. typedef struct {
  103972. vorbis_info_residue0 *info;
  103973. int parts;
  103974. int stages;
  103975. codebook *fullbooks;
  103976. codebook *phrasebook;
  103977. codebook ***partbooks;
  103978. int partvals;
  103979. int **decodemap;
  103980. long postbits;
  103981. long phrasebits;
  103982. long frames;
  103983. #if defined(TRAIN_RES) || defined(TRAIN_RESAUX)
  103984. int train_seq;
  103985. long *training_data[8][64];
  103986. float training_max[8][64];
  103987. float training_min[8][64];
  103988. float tmin;
  103989. float tmax;
  103990. #endif
  103991. } vorbis_look_residue0;
  103992. void res0_free_info(vorbis_info_residue *i){
  103993. vorbis_info_residue0 *info=(vorbis_info_residue0 *)i;
  103994. if(info){
  103995. memset(info,0,sizeof(*info));
  103996. _ogg_free(info);
  103997. }
  103998. }
  103999. void res0_free_look(vorbis_look_residue *i){
  104000. int j;
  104001. if(i){
  104002. vorbis_look_residue0 *look=(vorbis_look_residue0 *)i;
  104003. #ifdef TRAIN_RES
  104004. {
  104005. int j,k,l;
  104006. for(j=0;j<look->parts;j++){
  104007. for(k=0;k<8;k++)
  104008. if(look->training_data[k][j]){
  104009. char buffer[80];
  104010. FILE *of;
  104011. codebook *statebook=look->partbooks[j][k];
  104012. sprintf(buffer,"res_part%d_pass%d.vqd",j,k);
  104013. of=fopen(buffer,"a");
  104014. for(l=0;l<statebook->entries;l++)
  104015. fprintf(of,"%d:%ld\n",l,look->training_data[k][j][l]);
  104016. fclose(of);
  104017. _ogg_free(look->training_data[k][j]);
  104018. look->training_data[k][j]=NULL;
  104019. }
  104020. }
  104021. }
  104022. fprintf(stderr,"min/max residue: %g::%g\n",look->tmin,look->tmax);
  104023. #endif
  104024. for(j=0;j<look->parts;j++)
  104025. if(look->partbooks[j])_ogg_free(look->partbooks[j]);
  104026. _ogg_free(look->partbooks);
  104027. for(j=0;j<look->partvals;j++)
  104028. _ogg_free(look->decodemap[j]);
  104029. _ogg_free(look->decodemap);
  104030. memset(look,0,sizeof(*look));
  104031. _ogg_free(look);
  104032. }
  104033. }
  104034. static int icount(unsigned int v){
  104035. int ret=0;
  104036. while(v){
  104037. ret+=v&1;
  104038. v>>=1;
  104039. }
  104040. return(ret);
  104041. }
  104042. void res0_pack(vorbis_info_residue *vr,oggpack_buffer *opb){
  104043. vorbis_info_residue0 *info=(vorbis_info_residue0 *)vr;
  104044. int j,acc=0;
  104045. oggpack_write(opb,info->begin,24);
  104046. oggpack_write(opb,info->end,24);
  104047. oggpack_write(opb,info->grouping-1,24); /* residue vectors to group and
  104048. code with a partitioned book */
  104049. oggpack_write(opb,info->partitions-1,6); /* possible partition choices */
  104050. oggpack_write(opb,info->groupbook,8); /* group huffman book */
  104051. for(j=0;j<info->partitions;j++){
  104052. if(ilog(info->secondstages[j])>3){
  104053. oggpack_write(opb,info->secondstages[j],3);
  104054. oggpack_write(opb,1,1);
  104055. oggpack_write(opb,info->secondstages[j]>>3,5);
  104056. }else
  104057. oggpack_write(opb,info->secondstages[j],4); /* trailing zero */
  104058. acc+=icount(info->secondstages[j]);
  104059. }
  104060. for(j=0;j<acc;j++)
  104061. oggpack_write(opb,info->booklist[j],8);
  104062. }
  104063. vorbis_info_residue *res0_unpack(vorbis_info *vi,oggpack_buffer *opb){
  104064. int j,acc=0;
  104065. vorbis_info_residue0 *info=(vorbis_info_residue0*) _ogg_calloc(1,sizeof(*info));
  104066. codec_setup_info *ci=(codec_setup_info*) vi->codec_setup;
  104067. info->begin=oggpack_read(opb,24);
  104068. info->end=oggpack_read(opb,24);
  104069. info->grouping=oggpack_read(opb,24)+1;
  104070. info->partitions=oggpack_read(opb,6)+1;
  104071. info->groupbook=oggpack_read(opb,8);
  104072. for(j=0;j<info->partitions;j++){
  104073. int cascade=oggpack_read(opb,3);
  104074. if(oggpack_read(opb,1))
  104075. cascade|=(oggpack_read(opb,5)<<3);
  104076. info->secondstages[j]=cascade;
  104077. acc+=icount(cascade);
  104078. }
  104079. for(j=0;j<acc;j++)
  104080. info->booklist[j]=oggpack_read(opb,8);
  104081. if(info->groupbook>=ci->books)goto errout;
  104082. for(j=0;j<acc;j++)
  104083. if(info->booklist[j]>=ci->books)goto errout;
  104084. return(info);
  104085. errout:
  104086. res0_free_info(info);
  104087. return(NULL);
  104088. }
  104089. vorbis_look_residue *res0_look(vorbis_dsp_state *vd,
  104090. vorbis_info_residue *vr){
  104091. vorbis_info_residue0 *info=(vorbis_info_residue0 *)vr;
  104092. vorbis_look_residue0 *look=(vorbis_look_residue0 *)_ogg_calloc(1,sizeof(*look));
  104093. codec_setup_info *ci=(codec_setup_info*)vd->vi->codec_setup;
  104094. int j,k,acc=0;
  104095. int dim;
  104096. int maxstage=0;
  104097. look->info=info;
  104098. look->parts=info->partitions;
  104099. look->fullbooks=ci->fullbooks;
  104100. look->phrasebook=ci->fullbooks+info->groupbook;
  104101. dim=look->phrasebook->dim;
  104102. look->partbooks=(codebook***)_ogg_calloc(look->parts,sizeof(*look->partbooks));
  104103. for(j=0;j<look->parts;j++){
  104104. int stages=ilog(info->secondstages[j]);
  104105. if(stages){
  104106. if(stages>maxstage)maxstage=stages;
  104107. look->partbooks[j]=(codebook**) _ogg_calloc(stages,sizeof(*look->partbooks[j]));
  104108. for(k=0;k<stages;k++)
  104109. if(info->secondstages[j]&(1<<k)){
  104110. look->partbooks[j][k]=ci->fullbooks+info->booklist[acc++];
  104111. #ifdef TRAIN_RES
  104112. look->training_data[k][j]=_ogg_calloc(look->partbooks[j][k]->entries,
  104113. sizeof(***look->training_data));
  104114. #endif
  104115. }
  104116. }
  104117. }
  104118. look->partvals=rint(pow((float)look->parts,(float)dim));
  104119. look->stages=maxstage;
  104120. look->decodemap=(int**)_ogg_malloc(look->partvals*sizeof(*look->decodemap));
  104121. for(j=0;j<look->partvals;j++){
  104122. long val=j;
  104123. long mult=look->partvals/look->parts;
  104124. look->decodemap[j]=(int*)_ogg_malloc(dim*sizeof(*look->decodemap[j]));
  104125. for(k=0;k<dim;k++){
  104126. long deco=val/mult;
  104127. val-=deco*mult;
  104128. mult/=look->parts;
  104129. look->decodemap[j][k]=deco;
  104130. }
  104131. }
  104132. #if defined(TRAIN_RES) || defined (TRAIN_RESAUX)
  104133. {
  104134. static int train_seq=0;
  104135. look->train_seq=train_seq++;
  104136. }
  104137. #endif
  104138. return(look);
  104139. }
  104140. static int local_book_besterror(codebook *book,float *a){
  104141. int dim=book->dim,i,k,o;
  104142. int best=0;
  104143. encode_aux_threshmatch *tt=book->c->thresh_tree;
  104144. for(k=0,o=dim;k<dim;++k){
  104145. float val=a[--o];
  104146. i=tt->threshvals>>1;
  104147. if(val<tt->quantthresh[i]){
  104148. if(val<tt->quantthresh[i-1]){
  104149. for(--i;i>0;--i)
  104150. if(val>=tt->quantthresh[i-1])
  104151. break;
  104152. }
  104153. }else{
  104154. for(++i;i<tt->threshvals-1;++i)
  104155. if(val<tt->quantthresh[i])break;
  104156. }
  104157. best=(best*tt->quantvals)+tt->quantmap[i];
  104158. }
  104159. if(book->c->lengthlist[best]<=0){
  104160. const static_codebook *c=book->c;
  104161. int i,j;
  104162. float bestf=0.f;
  104163. float *e=book->valuelist;
  104164. best=-1;
  104165. for(i=0;i<book->entries;i++){
  104166. if(c->lengthlist[i]>0){
  104167. float thisx=0.f;
  104168. for(j=0;j<dim;j++){
  104169. float val=(e[j]-a[j]);
  104170. thisx+=val*val;
  104171. }
  104172. if(best==-1 || thisx<bestf){
  104173. bestf=thisx;
  104174. best=i;
  104175. }
  104176. }
  104177. e+=dim;
  104178. }
  104179. }
  104180. {
  104181. float *ptr=book->valuelist+best*dim;
  104182. for(i=0;i<dim;i++)
  104183. *a++ -= *ptr++;
  104184. }
  104185. return(best);
  104186. }
  104187. static int _encodepart(oggpack_buffer *opb,float *vec, int n,
  104188. codebook *book,long *acc){
  104189. int i,bits=0;
  104190. int dim=book->dim;
  104191. int step=n/dim;
  104192. for(i=0;i<step;i++){
  104193. int entry=local_book_besterror(book,vec+i*dim);
  104194. #ifdef TRAIN_RES
  104195. acc[entry]++;
  104196. #endif
  104197. bits+=vorbis_book_encode(book,entry,opb);
  104198. }
  104199. return(bits);
  104200. }
  104201. static long **_01class(vorbis_block *vb,vorbis_look_residue *vl,
  104202. float **in,int ch){
  104203. long i,j,k;
  104204. vorbis_look_residue0 *look=(vorbis_look_residue0 *)vl;
  104205. vorbis_info_residue0 *info=look->info;
  104206. int samples_per_partition=info->grouping;
  104207. int possible_partitions=info->partitions;
  104208. int n=info->end-info->begin;
  104209. int partvals=n/samples_per_partition;
  104210. long **partword=(long**)_vorbis_block_alloc(vb,ch*sizeof(*partword));
  104211. float scale=100./samples_per_partition;
  104212. for(i=0;i<ch;i++){
  104213. partword[i]=(long*)_vorbis_block_alloc(vb,n/samples_per_partition*sizeof(*partword[i]));
  104214. memset(partword[i],0,n/samples_per_partition*sizeof(*partword[i]));
  104215. }
  104216. for(i=0;i<partvals;i++){
  104217. int offset=i*samples_per_partition+info->begin;
  104218. for(j=0;j<ch;j++){
  104219. float max=0.;
  104220. float ent=0.;
  104221. for(k=0;k<samples_per_partition;k++){
  104222. if(fabs(in[j][offset+k])>max)max=fabs(in[j][offset+k]);
  104223. ent+=fabs(rint(in[j][offset+k]));
  104224. }
  104225. ent*=scale;
  104226. for(k=0;k<possible_partitions-1;k++)
  104227. if(max<=info->classmetric1[k] &&
  104228. (info->classmetric2[k]<0 || (int)ent<info->classmetric2[k]))
  104229. break;
  104230. partword[j][i]=k;
  104231. }
  104232. }
  104233. #ifdef TRAIN_RESAUX
  104234. {
  104235. FILE *of;
  104236. char buffer[80];
  104237. for(i=0;i<ch;i++){
  104238. sprintf(buffer,"resaux_%d.vqd",look->train_seq);
  104239. of=fopen(buffer,"a");
  104240. for(j=0;j<partvals;j++)
  104241. fprintf(of,"%ld, ",partword[i][j]);
  104242. fprintf(of,"\n");
  104243. fclose(of);
  104244. }
  104245. }
  104246. #endif
  104247. look->frames++;
  104248. return(partword);
  104249. }
  104250. static long **_2class(vorbis_block *vb,vorbis_look_residue *vl,float **in,
  104251. int ch){
  104252. long i,j,k,l;
  104253. vorbis_look_residue0 *look=(vorbis_look_residue0 *)vl;
  104254. vorbis_info_residue0 *info=look->info;
  104255. int samples_per_partition=info->grouping;
  104256. int possible_partitions=info->partitions;
  104257. int n=info->end-info->begin;
  104258. int partvals=n/samples_per_partition;
  104259. long **partword=(long**)_vorbis_block_alloc(vb,sizeof(*partword));
  104260. #if defined(TRAIN_RES) || defined (TRAIN_RESAUX)
  104261. FILE *of;
  104262. char buffer[80];
  104263. #endif
  104264. partword[0]=(long*)_vorbis_block_alloc(vb,n*ch/samples_per_partition*sizeof(*partword[0]));
  104265. memset(partword[0],0,n*ch/samples_per_partition*sizeof(*partword[0]));
  104266. for(i=0,l=info->begin/ch;i<partvals;i++){
  104267. float magmax=0.f;
  104268. float angmax=0.f;
  104269. for(j=0;j<samples_per_partition;j+=ch){
  104270. if(fabs(in[0][l])>magmax)magmax=fabs(in[0][l]);
  104271. for(k=1;k<ch;k++)
  104272. if(fabs(in[k][l])>angmax)angmax=fabs(in[k][l]);
  104273. l++;
  104274. }
  104275. for(j=0;j<possible_partitions-1;j++)
  104276. if(magmax<=info->classmetric1[j] &&
  104277. angmax<=info->classmetric2[j])
  104278. break;
  104279. partword[0][i]=j;
  104280. }
  104281. #ifdef TRAIN_RESAUX
  104282. sprintf(buffer,"resaux_%d.vqd",look->train_seq);
  104283. of=fopen(buffer,"a");
  104284. for(i=0;i<partvals;i++)
  104285. fprintf(of,"%ld, ",partword[0][i]);
  104286. fprintf(of,"\n");
  104287. fclose(of);
  104288. #endif
  104289. look->frames++;
  104290. return(partword);
  104291. }
  104292. static int _01forward(oggpack_buffer *opb,
  104293. vorbis_block *vb,vorbis_look_residue *vl,
  104294. float **in,int ch,
  104295. long **partword,
  104296. int (*encode)(oggpack_buffer *,float *,int,
  104297. codebook *,long *)){
  104298. long i,j,k,s;
  104299. vorbis_look_residue0 *look=(vorbis_look_residue0 *)vl;
  104300. vorbis_info_residue0 *info=look->info;
  104301. int samples_per_partition=info->grouping;
  104302. int possible_partitions=info->partitions;
  104303. int partitions_per_word=look->phrasebook->dim;
  104304. int n=info->end-info->begin;
  104305. int partvals=n/samples_per_partition;
  104306. long resbits[128];
  104307. long resvals[128];
  104308. #ifdef TRAIN_RES
  104309. for(i=0;i<ch;i++)
  104310. for(j=info->begin;j<info->end;j++){
  104311. if(in[i][j]>look->tmax)look->tmax=in[i][j];
  104312. if(in[i][j]<look->tmin)look->tmin=in[i][j];
  104313. }
  104314. #endif
  104315. memset(resbits,0,sizeof(resbits));
  104316. memset(resvals,0,sizeof(resvals));
  104317. for(s=0;s<look->stages;s++){
  104318. for(i=0;i<partvals;){
  104319. if(s==0){
  104320. for(j=0;j<ch;j++){
  104321. long val=partword[j][i];
  104322. for(k=1;k<partitions_per_word;k++){
  104323. val*=possible_partitions;
  104324. if(i+k<partvals)
  104325. val+=partword[j][i+k];
  104326. }
  104327. if(val<look->phrasebook->entries)
  104328. look->phrasebits+=vorbis_book_encode(look->phrasebook,val,opb);
  104329. #if 0 /*def TRAIN_RES*/
  104330. else
  104331. fprintf(stderr,"!");
  104332. #endif
  104333. }
  104334. }
  104335. for(k=0;k<partitions_per_word && i<partvals;k++,i++){
  104336. long offset=i*samples_per_partition+info->begin;
  104337. for(j=0;j<ch;j++){
  104338. if(s==0)resvals[partword[j][i]]+=samples_per_partition;
  104339. if(info->secondstages[partword[j][i]]&(1<<s)){
  104340. codebook *statebook=look->partbooks[partword[j][i]][s];
  104341. if(statebook){
  104342. int ret;
  104343. long *accumulator=NULL;
  104344. #ifdef TRAIN_RES
  104345. accumulator=look->training_data[s][partword[j][i]];
  104346. {
  104347. int l;
  104348. float *samples=in[j]+offset;
  104349. for(l=0;l<samples_per_partition;l++){
  104350. if(samples[l]<look->training_min[s][partword[j][i]])
  104351. look->training_min[s][partword[j][i]]=samples[l];
  104352. if(samples[l]>look->training_max[s][partword[j][i]])
  104353. look->training_max[s][partword[j][i]]=samples[l];
  104354. }
  104355. }
  104356. #endif
  104357. ret=encode(opb,in[j]+offset,samples_per_partition,
  104358. statebook,accumulator);
  104359. look->postbits+=ret;
  104360. resbits[partword[j][i]]+=ret;
  104361. }
  104362. }
  104363. }
  104364. }
  104365. }
  104366. }
  104367. return(0);
  104368. }
  104369. static int _01inverse(vorbis_block *vb,vorbis_look_residue *vl,
  104370. float **in,int ch,
  104371. long (*decodepart)(codebook *, float *,
  104372. oggpack_buffer *,int)){
  104373. long i,j,k,l,s;
  104374. vorbis_look_residue0 *look=(vorbis_look_residue0 *)vl;
  104375. vorbis_info_residue0 *info=look->info;
  104376. int samples_per_partition=info->grouping;
  104377. int partitions_per_word=look->phrasebook->dim;
  104378. int n=info->end-info->begin;
  104379. int partvals=n/samples_per_partition;
  104380. int partwords=(partvals+partitions_per_word-1)/partitions_per_word;
  104381. int ***partword=(int***)alloca(ch*sizeof(*partword));
  104382. for(j=0;j<ch;j++)
  104383. partword[j]=(int**)_vorbis_block_alloc(vb,partwords*sizeof(*partword[j]));
  104384. for(s=0;s<look->stages;s++){
  104385. for(i=0,l=0;i<partvals;l++){
  104386. if(s==0){
  104387. for(j=0;j<ch;j++){
  104388. int temp=vorbis_book_decode(look->phrasebook,&vb->opb);
  104389. if(temp==-1)goto eopbreak;
  104390. partword[j][l]=look->decodemap[temp];
  104391. if(partword[j][l]==NULL)goto errout;
  104392. }
  104393. }
  104394. for(k=0;k<partitions_per_word && i<partvals;k++,i++)
  104395. for(j=0;j<ch;j++){
  104396. long offset=info->begin+i*samples_per_partition;
  104397. if(info->secondstages[partword[j][l][k]]&(1<<s)){
  104398. codebook *stagebook=look->partbooks[partword[j][l][k]][s];
  104399. if(stagebook){
  104400. if(decodepart(stagebook,in[j]+offset,&vb->opb,
  104401. samples_per_partition)==-1)goto eopbreak;
  104402. }
  104403. }
  104404. }
  104405. }
  104406. }
  104407. errout:
  104408. eopbreak:
  104409. return(0);
  104410. }
  104411. #if 0
  104412. long **res0_class(vorbis_block *vb,vorbis_look_residue *vl,
  104413. float **in,int *nonzero,int ch){
  104414. int i,used=0;
  104415. for(i=0;i<ch;i++)
  104416. if(nonzero[i])
  104417. in[used++]=in[i];
  104418. if(used)
  104419. return(_01class(vb,vl,in,used));
  104420. else
  104421. return(0);
  104422. }
  104423. int res0_forward(vorbis_block *vb,vorbis_look_residue *vl,
  104424. float **in,float **out,int *nonzero,int ch,
  104425. long **partword){
  104426. int i,j,used=0,n=vb->pcmend/2;
  104427. for(i=0;i<ch;i++)
  104428. if(nonzero[i]){
  104429. if(out)
  104430. for(j=0;j<n;j++)
  104431. out[i][j]+=in[i][j];
  104432. in[used++]=in[i];
  104433. }
  104434. if(used){
  104435. int ret=_01forward(vb,vl,in,used,partword,
  104436. _interleaved_encodepart);
  104437. if(out){
  104438. used=0;
  104439. for(i=0;i<ch;i++)
  104440. if(nonzero[i]){
  104441. for(j=0;j<n;j++)
  104442. out[i][j]-=in[used][j];
  104443. used++;
  104444. }
  104445. }
  104446. return(ret);
  104447. }else{
  104448. return(0);
  104449. }
  104450. }
  104451. #endif
  104452. int res0_inverse(vorbis_block *vb,vorbis_look_residue *vl,
  104453. float **in,int *nonzero,int ch){
  104454. int i,used=0;
  104455. for(i=0;i<ch;i++)
  104456. if(nonzero[i])
  104457. in[used++]=in[i];
  104458. if(used)
  104459. return(_01inverse(vb,vl,in,used,vorbis_book_decodevs_add));
  104460. else
  104461. return(0);
  104462. }
  104463. int res1_forward(oggpack_buffer *opb,vorbis_block *vb,vorbis_look_residue *vl,
  104464. float **in,float **out,int *nonzero,int ch,
  104465. long **partword){
  104466. int i,j,used=0,n=vb->pcmend/2;
  104467. for(i=0;i<ch;i++)
  104468. if(nonzero[i]){
  104469. if(out)
  104470. for(j=0;j<n;j++)
  104471. out[i][j]+=in[i][j];
  104472. in[used++]=in[i];
  104473. }
  104474. if(used){
  104475. int ret=_01forward(opb,vb,vl,in,used,partword,_encodepart);
  104476. if(out){
  104477. used=0;
  104478. for(i=0;i<ch;i++)
  104479. if(nonzero[i]){
  104480. for(j=0;j<n;j++)
  104481. out[i][j]-=in[used][j];
  104482. used++;
  104483. }
  104484. }
  104485. return(ret);
  104486. }else{
  104487. return(0);
  104488. }
  104489. }
  104490. long **res1_class(vorbis_block *vb,vorbis_look_residue *vl,
  104491. float **in,int *nonzero,int ch){
  104492. int i,used=0;
  104493. for(i=0;i<ch;i++)
  104494. if(nonzero[i])
  104495. in[used++]=in[i];
  104496. if(used)
  104497. return(_01class(vb,vl,in,used));
  104498. else
  104499. return(0);
  104500. }
  104501. int res1_inverse(vorbis_block *vb,vorbis_look_residue *vl,
  104502. float **in,int *nonzero,int ch){
  104503. int i,used=0;
  104504. for(i=0;i<ch;i++)
  104505. if(nonzero[i])
  104506. in[used++]=in[i];
  104507. if(used)
  104508. return(_01inverse(vb,vl,in,used,vorbis_book_decodev_add));
  104509. else
  104510. return(0);
  104511. }
  104512. long **res2_class(vorbis_block *vb,vorbis_look_residue *vl,
  104513. float **in,int *nonzero,int ch){
  104514. int i,used=0;
  104515. for(i=0;i<ch;i++)
  104516. if(nonzero[i])used++;
  104517. if(used)
  104518. return(_2class(vb,vl,in,ch));
  104519. else
  104520. return(0);
  104521. }
  104522. int res2_forward(oggpack_buffer *opb,
  104523. vorbis_block *vb,vorbis_look_residue *vl,
  104524. float **in,float **out,int *nonzero,int ch,
  104525. long **partword){
  104526. long i,j,k,n=vb->pcmend/2,used=0;
  104527. float *work=(float*)_vorbis_block_alloc(vb,ch*n*sizeof(*work));
  104528. for(i=0;i<ch;i++){
  104529. float *pcm=in[i];
  104530. if(nonzero[i])used++;
  104531. for(j=0,k=i;j<n;j++,k+=ch)
  104532. work[k]=pcm[j];
  104533. }
  104534. if(used){
  104535. int ret=_01forward(opb,vb,vl,&work,1,partword,_encodepart);
  104536. if(out){
  104537. for(i=0;i<ch;i++){
  104538. float *pcm=in[i];
  104539. float *sofar=out[i];
  104540. for(j=0,k=i;j<n;j++,k+=ch)
  104541. sofar[j]+=pcm[j]-work[k];
  104542. }
  104543. }
  104544. return(ret);
  104545. }else{
  104546. return(0);
  104547. }
  104548. }
  104549. int res2_inverse(vorbis_block *vb,vorbis_look_residue *vl,
  104550. float **in,int *nonzero,int ch){
  104551. long i,k,l,s;
  104552. vorbis_look_residue0 *look=(vorbis_look_residue0 *)vl;
  104553. vorbis_info_residue0 *info=look->info;
  104554. int samples_per_partition=info->grouping;
  104555. int partitions_per_word=look->phrasebook->dim;
  104556. int n=info->end-info->begin;
  104557. int partvals=n/samples_per_partition;
  104558. int partwords=(partvals+partitions_per_word-1)/partitions_per_word;
  104559. int **partword=(int**)_vorbis_block_alloc(vb,partwords*sizeof(*partword));
  104560. for(i=0;i<ch;i++)if(nonzero[i])break;
  104561. if(i==ch)return(0); /* no nonzero vectors */
  104562. for(s=0;s<look->stages;s++){
  104563. for(i=0,l=0;i<partvals;l++){
  104564. if(s==0){
  104565. int temp=vorbis_book_decode(look->phrasebook,&vb->opb);
  104566. if(temp==-1)goto eopbreak;
  104567. partword[l]=look->decodemap[temp];
  104568. if(partword[l]==NULL)goto errout;
  104569. }
  104570. for(k=0;k<partitions_per_word && i<partvals;k++,i++)
  104571. if(info->secondstages[partword[l][k]]&(1<<s)){
  104572. codebook *stagebook=look->partbooks[partword[l][k]][s];
  104573. if(stagebook){
  104574. if(vorbis_book_decodevv_add(stagebook,in,
  104575. i*samples_per_partition+info->begin,ch,
  104576. &vb->opb,samples_per_partition)==-1)
  104577. goto eopbreak;
  104578. }
  104579. }
  104580. }
  104581. }
  104582. errout:
  104583. eopbreak:
  104584. return(0);
  104585. }
  104586. vorbis_func_residue residue0_exportbundle={
  104587. NULL,
  104588. &res0_unpack,
  104589. &res0_look,
  104590. &res0_free_info,
  104591. &res0_free_look,
  104592. NULL,
  104593. NULL,
  104594. &res0_inverse
  104595. };
  104596. vorbis_func_residue residue1_exportbundle={
  104597. &res0_pack,
  104598. &res0_unpack,
  104599. &res0_look,
  104600. &res0_free_info,
  104601. &res0_free_look,
  104602. &res1_class,
  104603. &res1_forward,
  104604. &res1_inverse
  104605. };
  104606. vorbis_func_residue residue2_exportbundle={
  104607. &res0_pack,
  104608. &res0_unpack,
  104609. &res0_look,
  104610. &res0_free_info,
  104611. &res0_free_look,
  104612. &res2_class,
  104613. &res2_forward,
  104614. &res2_inverse
  104615. };
  104616. #endif
  104617. /*** End of inlined file: res0.c ***/
  104618. /*** Start of inlined file: sharedbook.c ***/
  104619. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  104620. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  104621. // tasks..
  104622. #if JUCE_MSVC
  104623. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  104624. #endif
  104625. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  104626. #if JUCE_USE_OGGVORBIS
  104627. #include <stdlib.h>
  104628. #include <math.h>
  104629. #include <string.h>
  104630. int _ilog(unsigned int v){
  104631. int ret=0;
  104632. while(v){
  104633. ret++;
  104634. v>>=1;
  104635. }
  104636. return(ret);
  104637. }
  104638. #define VQ_FEXP 10
  104639. #define VQ_FMAN 21
  104640. #define VQ_FEXP_BIAS 768 /* bias toward values smaller than 1. */
  104641. long _float32_pack(float val){
  104642. int sign=0;
  104643. long exp;
  104644. long mant;
  104645. if(val<0){
  104646. sign=0x80000000;
  104647. val= -val;
  104648. }
  104649. exp= floor(log(val)/log(2.f));
  104650. mant=rint(ldexp(val,(VQ_FMAN-1)-exp));
  104651. exp=(exp+VQ_FEXP_BIAS)<<VQ_FMAN;
  104652. return(sign|exp|mant);
  104653. }
  104654. float _float32_unpack(long val){
  104655. double mant=val&0x1fffff;
  104656. int sign=val&0x80000000;
  104657. long exp =(val&0x7fe00000L)>>VQ_FMAN;
  104658. if(sign)mant= -mant;
  104659. return(ldexp(mant,exp-(VQ_FMAN-1)-VQ_FEXP_BIAS));
  104660. }
  104661. ogg_uint32_t *_make_words(long *l,long n,long sparsecount){
  104662. long i,j,count=0;
  104663. ogg_uint32_t marker[33];
  104664. ogg_uint32_t *r=(ogg_uint32_t*)_ogg_malloc((sparsecount?sparsecount:n)*sizeof(*r));
  104665. memset(marker,0,sizeof(marker));
  104666. for(i=0;i<n;i++){
  104667. long length=l[i];
  104668. if(length>0){
  104669. ogg_uint32_t entry=marker[length];
  104670. if(length<32 && (entry>>length)){
  104671. _ogg_free(r);
  104672. return(NULL);
  104673. }
  104674. r[count++]=entry;
  104675. {
  104676. for(j=length;j>0;j--){
  104677. if(marker[j]&1){
  104678. if(j==1)
  104679. marker[1]++;
  104680. else
  104681. marker[j]=marker[j-1]<<1;
  104682. break; /* invariant says next upper marker would already
  104683. have been moved if it was on the same path */
  104684. }
  104685. marker[j]++;
  104686. }
  104687. }
  104688. for(j=length+1;j<33;j++)
  104689. if((marker[j]>>1) == entry){
  104690. entry=marker[j];
  104691. marker[j]=marker[j-1]<<1;
  104692. }else
  104693. break;
  104694. }else
  104695. if(sparsecount==0)count++;
  104696. }
  104697. for(i=0,count=0;i<n;i++){
  104698. ogg_uint32_t temp=0;
  104699. for(j=0;j<l[i];j++){
  104700. temp<<=1;
  104701. temp|=(r[count]>>j)&1;
  104702. }
  104703. if(sparsecount){
  104704. if(l[i])
  104705. r[count++]=temp;
  104706. }else
  104707. r[count++]=temp;
  104708. }
  104709. return(r);
  104710. }
  104711. long _book_maptype1_quantvals(const static_codebook *b){
  104712. long vals=floor(pow((float)b->entries,1.f/b->dim));
  104713. while(1){
  104714. long acc=1;
  104715. long acc1=1;
  104716. int i;
  104717. for(i=0;i<b->dim;i++){
  104718. acc*=vals;
  104719. acc1*=vals+1;
  104720. }
  104721. if(acc<=b->entries && acc1>b->entries){
  104722. return(vals);
  104723. }else{
  104724. if(acc>b->entries){
  104725. vals--;
  104726. }else{
  104727. vals++;
  104728. }
  104729. }
  104730. }
  104731. }
  104732. float *_book_unquantize(const static_codebook *b,int n,int *sparsemap){
  104733. long j,k,count=0;
  104734. if(b->maptype==1 || b->maptype==2){
  104735. int quantvals;
  104736. float mindel=_float32_unpack(b->q_min);
  104737. float delta=_float32_unpack(b->q_delta);
  104738. float *r=(float*)_ogg_calloc(n*b->dim,sizeof(*r));
  104739. switch(b->maptype){
  104740. case 1:
  104741. quantvals=_book_maptype1_quantvals(b);
  104742. for(j=0;j<b->entries;j++){
  104743. if((sparsemap && b->lengthlist[j]) || !sparsemap){
  104744. float last=0.f;
  104745. int indexdiv=1;
  104746. for(k=0;k<b->dim;k++){
  104747. int index= (j/indexdiv)%quantvals;
  104748. float val=b->quantlist[index];
  104749. val=fabs(val)*delta+mindel+last;
  104750. if(b->q_sequencep)last=val;
  104751. if(sparsemap)
  104752. r[sparsemap[count]*b->dim+k]=val;
  104753. else
  104754. r[count*b->dim+k]=val;
  104755. indexdiv*=quantvals;
  104756. }
  104757. count++;
  104758. }
  104759. }
  104760. break;
  104761. case 2:
  104762. for(j=0;j<b->entries;j++){
  104763. if((sparsemap && b->lengthlist[j]) || !sparsemap){
  104764. float last=0.f;
  104765. for(k=0;k<b->dim;k++){
  104766. float val=b->quantlist[j*b->dim+k];
  104767. val=fabs(val)*delta+mindel+last;
  104768. if(b->q_sequencep)last=val;
  104769. if(sparsemap)
  104770. r[sparsemap[count]*b->dim+k]=val;
  104771. else
  104772. r[count*b->dim+k]=val;
  104773. }
  104774. count++;
  104775. }
  104776. }
  104777. break;
  104778. }
  104779. return(r);
  104780. }
  104781. return(NULL);
  104782. }
  104783. void vorbis_staticbook_clear(static_codebook *b){
  104784. if(b->allocedp){
  104785. if(b->quantlist)_ogg_free(b->quantlist);
  104786. if(b->lengthlist)_ogg_free(b->lengthlist);
  104787. if(b->nearest_tree){
  104788. _ogg_free(b->nearest_tree->ptr0);
  104789. _ogg_free(b->nearest_tree->ptr1);
  104790. _ogg_free(b->nearest_tree->p);
  104791. _ogg_free(b->nearest_tree->q);
  104792. memset(b->nearest_tree,0,sizeof(*b->nearest_tree));
  104793. _ogg_free(b->nearest_tree);
  104794. }
  104795. if(b->thresh_tree){
  104796. _ogg_free(b->thresh_tree->quantthresh);
  104797. _ogg_free(b->thresh_tree->quantmap);
  104798. memset(b->thresh_tree,0,sizeof(*b->thresh_tree));
  104799. _ogg_free(b->thresh_tree);
  104800. }
  104801. memset(b,0,sizeof(*b));
  104802. }
  104803. }
  104804. void vorbis_staticbook_destroy(static_codebook *b){
  104805. if(b->allocedp){
  104806. vorbis_staticbook_clear(b);
  104807. _ogg_free(b);
  104808. }
  104809. }
  104810. void vorbis_book_clear(codebook *b){
  104811. if(b->valuelist)_ogg_free(b->valuelist);
  104812. if(b->codelist)_ogg_free(b->codelist);
  104813. if(b->dec_index)_ogg_free(b->dec_index);
  104814. if(b->dec_codelengths)_ogg_free(b->dec_codelengths);
  104815. if(b->dec_firsttable)_ogg_free(b->dec_firsttable);
  104816. memset(b,0,sizeof(*b));
  104817. }
  104818. int vorbis_book_init_encode(codebook *c,const static_codebook *s){
  104819. memset(c,0,sizeof(*c));
  104820. c->c=s;
  104821. c->entries=s->entries;
  104822. c->used_entries=s->entries;
  104823. c->dim=s->dim;
  104824. c->codelist=_make_words(s->lengthlist,s->entries,0);
  104825. c->valuelist=_book_unquantize(s,s->entries,NULL);
  104826. return(0);
  104827. }
  104828. static int sort32a(const void *a,const void *b){
  104829. return ( **(ogg_uint32_t **)a>**(ogg_uint32_t **)b)-
  104830. ( **(ogg_uint32_t **)a<**(ogg_uint32_t **)b);
  104831. }
  104832. int vorbis_book_init_decode(codebook *c,const static_codebook *s){
  104833. int i,j,n=0,tabn;
  104834. int *sortindex;
  104835. memset(c,0,sizeof(*c));
  104836. for(i=0;i<s->entries;i++)
  104837. if(s->lengthlist[i]>0)
  104838. n++;
  104839. c->entries=s->entries;
  104840. c->used_entries=n;
  104841. c->dim=s->dim;
  104842. {
  104843. ogg_uint32_t *codes=_make_words(s->lengthlist,s->entries,c->used_entries);
  104844. ogg_uint32_t **codep=(ogg_uint32_t**)alloca(sizeof(*codep)*n);
  104845. if(codes==NULL)goto err_out;
  104846. for(i=0;i<n;i++){
  104847. codes[i]=ogg_bitreverse(codes[i]);
  104848. codep[i]=codes+i;
  104849. }
  104850. qsort(codep,n,sizeof(*codep),sort32a);
  104851. sortindex=(int*)alloca(n*sizeof(*sortindex));
  104852. c->codelist=(ogg_uint32_t*)_ogg_malloc(n*sizeof(*c->codelist));
  104853. for(i=0;i<n;i++){
  104854. int position=codep[i]-codes;
  104855. sortindex[position]=i;
  104856. }
  104857. for(i=0;i<n;i++)
  104858. c->codelist[sortindex[i]]=codes[i];
  104859. _ogg_free(codes);
  104860. }
  104861. c->valuelist=_book_unquantize(s,n,sortindex);
  104862. c->dec_index=(int*)_ogg_malloc(n*sizeof(*c->dec_index));
  104863. for(n=0,i=0;i<s->entries;i++)
  104864. if(s->lengthlist[i]>0)
  104865. c->dec_index[sortindex[n++]]=i;
  104866. c->dec_codelengths=(char*)_ogg_malloc(n*sizeof(*c->dec_codelengths));
  104867. for(n=0,i=0;i<s->entries;i++)
  104868. if(s->lengthlist[i]>0)
  104869. c->dec_codelengths[sortindex[n++]]=s->lengthlist[i];
  104870. c->dec_firsttablen=_ilog(c->used_entries)-4; /* this is magic */
  104871. if(c->dec_firsttablen<5)c->dec_firsttablen=5;
  104872. if(c->dec_firsttablen>8)c->dec_firsttablen=8;
  104873. tabn=1<<c->dec_firsttablen;
  104874. c->dec_firsttable=(ogg_uint32_t*)_ogg_calloc(tabn,sizeof(*c->dec_firsttable));
  104875. c->dec_maxlength=0;
  104876. for(i=0;i<n;i++){
  104877. if(c->dec_maxlength<c->dec_codelengths[i])
  104878. c->dec_maxlength=c->dec_codelengths[i];
  104879. if(c->dec_codelengths[i]<=c->dec_firsttablen){
  104880. ogg_uint32_t orig=ogg_bitreverse(c->codelist[i]);
  104881. for(j=0;j<(1<<(c->dec_firsttablen-c->dec_codelengths[i]));j++)
  104882. c->dec_firsttable[orig|(j<<c->dec_codelengths[i])]=i+1;
  104883. }
  104884. }
  104885. {
  104886. ogg_uint32_t mask=0xfffffffeUL<<(31-c->dec_firsttablen);
  104887. long lo=0,hi=0;
  104888. for(i=0;i<tabn;i++){
  104889. ogg_uint32_t word=i<<(32-c->dec_firsttablen);
  104890. if(c->dec_firsttable[ogg_bitreverse(word)]==0){
  104891. while((lo+1)<n && c->codelist[lo+1]<=word)lo++;
  104892. while( hi<n && word>=(c->codelist[hi]&mask))hi++;
  104893. {
  104894. unsigned long loval=lo;
  104895. unsigned long hival=n-hi;
  104896. if(loval>0x7fff)loval=0x7fff;
  104897. if(hival>0x7fff)hival=0x7fff;
  104898. c->dec_firsttable[ogg_bitreverse(word)]=
  104899. 0x80000000UL | (loval<<15) | hival;
  104900. }
  104901. }
  104902. }
  104903. }
  104904. return(0);
  104905. err_out:
  104906. vorbis_book_clear(c);
  104907. return(-1);
  104908. }
  104909. static float _dist(int el,float *ref, float *b,int step){
  104910. int i;
  104911. float acc=0.f;
  104912. for(i=0;i<el;i++){
  104913. float val=(ref[i]-b[i*step]);
  104914. acc+=val*val;
  104915. }
  104916. return(acc);
  104917. }
  104918. int _best(codebook *book, float *a, int step){
  104919. encode_aux_threshmatch *tt=book->c->thresh_tree;
  104920. #if 0
  104921. encode_aux_nearestmatch *nt=book->c->nearest_tree;
  104922. encode_aux_pigeonhole *pt=book->c->pigeon_tree;
  104923. #endif
  104924. int dim=book->dim;
  104925. int k,o;
  104926. if(tt){
  104927. int index=0,i;
  104928. for(k=0,o=step*(dim-1);k<dim;k++,o-=step){
  104929. i=tt->threshvals>>1;
  104930. if(a[o]<tt->quantthresh[i]){
  104931. for(;i>0;i--)
  104932. if(a[o]>=tt->quantthresh[i-1])
  104933. break;
  104934. }else{
  104935. for(i++;i<tt->threshvals-1;i++)
  104936. if(a[o]<tt->quantthresh[i])break;
  104937. }
  104938. index=(index*tt->quantvals)+tt->quantmap[i];
  104939. }
  104940. if(book->c->lengthlist[index]>0) /* is this unused? If so, we'll
  104941. use a decision tree after all
  104942. and fall through*/
  104943. return(index);
  104944. }
  104945. #if 0
  104946. if(pt){
  104947. const static_codebook *c=book->c;
  104948. int i,besti=-1;
  104949. float best=0.f;
  104950. int entry=0;
  104951. if(c->q_sequencep){
  104952. int pv;
  104953. long mul=1;
  104954. float qlast=0;
  104955. for(k=0,o=0;k<dim;k++,o+=step){
  104956. pv=(int)((a[o]-qlast-pt->min)/pt->del);
  104957. if(pv<0 || pv>=pt->mapentries)break;
  104958. entry+=pt->pigeonmap[pv]*mul;
  104959. mul*=pt->quantvals;
  104960. qlast+=pv*pt->del+pt->min;
  104961. }
  104962. }else{
  104963. for(k=0,o=step*(dim-1);k<dim;k++,o-=step){
  104964. int pv=(int)((a[o]-pt->min)/pt->del);
  104965. if(pv<0 || pv>=pt->mapentries)break;
  104966. entry=entry*pt->quantvals+pt->pigeonmap[pv];
  104967. }
  104968. }
  104969. if(k==dim && pt->fitlength[entry]){
  104970. long *list=pt->fitlist+pt->fitmap[entry];
  104971. for(i=0;i<pt->fitlength[entry];i++){
  104972. float this=_dist(dim,book->valuelist+list[i]*dim,a,step);
  104973. if(besti==-1 || this<best){
  104974. best=this;
  104975. besti=list[i];
  104976. }
  104977. }
  104978. return(besti);
  104979. }
  104980. }
  104981. if(nt){
  104982. while(1){
  104983. float c=0.f;
  104984. float *p=book->valuelist+nt->p[ptr];
  104985. float *q=book->valuelist+nt->q[ptr];
  104986. for(k=0,o=0;k<dim;k++,o+=step)
  104987. c+=(p[k]-q[k])*(a[o]-(p[k]+q[k])*.5);
  104988. if(c>0.f) /* in A */
  104989. ptr= -nt->ptr0[ptr];
  104990. else /* in B */
  104991. ptr= -nt->ptr1[ptr];
  104992. if(ptr<=0)break;
  104993. }
  104994. return(-ptr);
  104995. }
  104996. #endif
  104997. {
  104998. const static_codebook *c=book->c;
  104999. int i,besti=-1;
  105000. float best=0.f;
  105001. float *e=book->valuelist;
  105002. for(i=0;i<book->entries;i++){
  105003. if(c->lengthlist[i]>0){
  105004. float thisx=_dist(dim,e,a,step);
  105005. if(besti==-1 || thisx<best){
  105006. best=thisx;
  105007. besti=i;
  105008. }
  105009. }
  105010. e+=dim;
  105011. }
  105012. return(besti);
  105013. }
  105014. }
  105015. long vorbis_book_codeword(codebook *book,int entry){
  105016. if(book->c) /* only use with encode; decode optimizations are
  105017. allowed to break this */
  105018. return book->codelist[entry];
  105019. return -1;
  105020. }
  105021. long vorbis_book_codelen(codebook *book,int entry){
  105022. if(book->c) /* only use with encode; decode optimizations are
  105023. allowed to break this */
  105024. return book->c->lengthlist[entry];
  105025. return -1;
  105026. }
  105027. #ifdef _V_SELFTEST
  105028. #include <stdio.h>
  105029. static long full_quantlist1[]={0,1,2,3, 4,5,6,7, 8,3,6,1};
  105030. static long partial_quantlist1[]={0,7,2};
  105031. static_codebook test1={
  105032. 4,16,
  105033. NULL,
  105034. 0,
  105035. 0,0,0,0,
  105036. NULL,
  105037. NULL,NULL
  105038. };
  105039. static float *test1_result=NULL;
  105040. static_codebook test2={
  105041. 4,3,
  105042. NULL,
  105043. 2,
  105044. -533200896,1611661312,4,0,
  105045. full_quantlist1,
  105046. NULL,NULL
  105047. };
  105048. static float test2_result[]={-3,-2,-1,0, 1,2,3,4, 5,0,3,-2};
  105049. static_codebook test3={
  105050. 4,3,
  105051. NULL,
  105052. 2,
  105053. -533200896,1611661312,4,1,
  105054. full_quantlist1,
  105055. NULL,NULL
  105056. };
  105057. static float test3_result[]={-3,-5,-6,-6, 1,3,6,10, 5,5,8,6};
  105058. static_codebook test4={
  105059. 3,27,
  105060. NULL,
  105061. 1,
  105062. -533200896,1611661312,4,0,
  105063. partial_quantlist1,
  105064. NULL,NULL
  105065. };
  105066. static float test4_result[]={-3,-3,-3, 4,-3,-3, -1,-3,-3,
  105067. -3, 4,-3, 4, 4,-3, -1, 4,-3,
  105068. -3,-1,-3, 4,-1,-3, -1,-1,-3,
  105069. -3,-3, 4, 4,-3, 4, -1,-3, 4,
  105070. -3, 4, 4, 4, 4, 4, -1, 4, 4,
  105071. -3,-1, 4, 4,-1, 4, -1,-1, 4,
  105072. -3,-3,-1, 4,-3,-1, -1,-3,-1,
  105073. -3, 4,-1, 4, 4,-1, -1, 4,-1,
  105074. -3,-1,-1, 4,-1,-1, -1,-1,-1};
  105075. static_codebook test5={
  105076. 3,27,
  105077. NULL,
  105078. 1,
  105079. -533200896,1611661312,4,1,
  105080. partial_quantlist1,
  105081. NULL,NULL
  105082. };
  105083. static float test5_result[]={-3,-6,-9, 4, 1,-2, -1,-4,-7,
  105084. -3, 1,-2, 4, 8, 5, -1, 3, 0,
  105085. -3,-4,-7, 4, 3, 0, -1,-2,-5,
  105086. -3,-6,-2, 4, 1, 5, -1,-4, 0,
  105087. -3, 1, 5, 4, 8,12, -1, 3, 7,
  105088. -3,-4, 0, 4, 3, 7, -1,-2, 2,
  105089. -3,-6,-7, 4, 1, 0, -1,-4,-5,
  105090. -3, 1, 0, 4, 8, 7, -1, 3, 2,
  105091. -3,-4,-5, 4, 3, 2, -1,-2,-3};
  105092. void run_test(static_codebook *b,float *comp){
  105093. float *out=_book_unquantize(b,b->entries,NULL);
  105094. int i;
  105095. if(comp){
  105096. if(!out){
  105097. fprintf(stderr,"_book_unquantize incorrectly returned NULL\n");
  105098. exit(1);
  105099. }
  105100. for(i=0;i<b->entries*b->dim;i++)
  105101. if(fabs(out[i]-comp[i])>.0001){
  105102. fprintf(stderr,"disagreement in unquantized and reference data:\n"
  105103. "position %d, %g != %g\n",i,out[i],comp[i]);
  105104. exit(1);
  105105. }
  105106. }else{
  105107. if(out){
  105108. fprintf(stderr,"_book_unquantize returned a value array: \n"
  105109. " correct result should have been NULL\n");
  105110. exit(1);
  105111. }
  105112. }
  105113. }
  105114. int main(){
  105115. fprintf(stderr,"Dequant test 1... ");
  105116. run_test(&test1,test1_result);
  105117. fprintf(stderr,"OK\nDequant test 2... ");
  105118. run_test(&test2,test2_result);
  105119. fprintf(stderr,"OK\nDequant test 3... ");
  105120. run_test(&test3,test3_result);
  105121. fprintf(stderr,"OK\nDequant test 4... ");
  105122. run_test(&test4,test4_result);
  105123. fprintf(stderr,"OK\nDequant test 5... ");
  105124. run_test(&test5,test5_result);
  105125. fprintf(stderr,"OK\n\n");
  105126. return(0);
  105127. }
  105128. #endif
  105129. #endif
  105130. /*** End of inlined file: sharedbook.c ***/
  105131. /*** Start of inlined file: smallft.c ***/
  105132. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  105133. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  105134. // tasks..
  105135. #if JUCE_MSVC
  105136. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  105137. #endif
  105138. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  105139. #if JUCE_USE_OGGVORBIS
  105140. #include <stdlib.h>
  105141. #include <string.h>
  105142. #include <math.h>
  105143. static void drfti1(int n, float *wa, int *ifac){
  105144. static int ntryh[4] = { 4,2,3,5 };
  105145. static float tpi = 6.28318530717958648f;
  105146. float arg,argh,argld,fi;
  105147. int ntry=0,i,j=-1;
  105148. int k1, l1, l2, ib;
  105149. int ld, ii, ip, is, nq, nr;
  105150. int ido, ipm, nfm1;
  105151. int nl=n;
  105152. int nf=0;
  105153. L101:
  105154. j++;
  105155. if (j < 4)
  105156. ntry=ntryh[j];
  105157. else
  105158. ntry+=2;
  105159. L104:
  105160. nq=nl/ntry;
  105161. nr=nl-ntry*nq;
  105162. if (nr!=0) goto L101;
  105163. nf++;
  105164. ifac[nf+1]=ntry;
  105165. nl=nq;
  105166. if(ntry!=2)goto L107;
  105167. if(nf==1)goto L107;
  105168. for (i=1;i<nf;i++){
  105169. ib=nf-i+1;
  105170. ifac[ib+1]=ifac[ib];
  105171. }
  105172. ifac[2] = 2;
  105173. L107:
  105174. if(nl!=1)goto L104;
  105175. ifac[0]=n;
  105176. ifac[1]=nf;
  105177. argh=tpi/n;
  105178. is=0;
  105179. nfm1=nf-1;
  105180. l1=1;
  105181. if(nfm1==0)return;
  105182. for (k1=0;k1<nfm1;k1++){
  105183. ip=ifac[k1+2];
  105184. ld=0;
  105185. l2=l1*ip;
  105186. ido=n/l2;
  105187. ipm=ip-1;
  105188. for (j=0;j<ipm;j++){
  105189. ld+=l1;
  105190. i=is;
  105191. argld=(float)ld*argh;
  105192. fi=0.f;
  105193. for (ii=2;ii<ido;ii+=2){
  105194. fi+=1.f;
  105195. arg=fi*argld;
  105196. wa[i++]=cos(arg);
  105197. wa[i++]=sin(arg);
  105198. }
  105199. is+=ido;
  105200. }
  105201. l1=l2;
  105202. }
  105203. }
  105204. static void fdrffti(int n, float *wsave, int *ifac){
  105205. if (n == 1) return;
  105206. drfti1(n, wsave+n, ifac);
  105207. }
  105208. static void dradf2(int ido,int l1,float *cc,float *ch,float *wa1){
  105209. int i,k;
  105210. float ti2,tr2;
  105211. int t0,t1,t2,t3,t4,t5,t6;
  105212. t1=0;
  105213. t0=(t2=l1*ido);
  105214. t3=ido<<1;
  105215. for(k=0;k<l1;k++){
  105216. ch[t1<<1]=cc[t1]+cc[t2];
  105217. ch[(t1<<1)+t3-1]=cc[t1]-cc[t2];
  105218. t1+=ido;
  105219. t2+=ido;
  105220. }
  105221. if(ido<2)return;
  105222. if(ido==2)goto L105;
  105223. t1=0;
  105224. t2=t0;
  105225. for(k=0;k<l1;k++){
  105226. t3=t2;
  105227. t4=(t1<<1)+(ido<<1);
  105228. t5=t1;
  105229. t6=t1+t1;
  105230. for(i=2;i<ido;i+=2){
  105231. t3+=2;
  105232. t4-=2;
  105233. t5+=2;
  105234. t6+=2;
  105235. tr2=wa1[i-2]*cc[t3-1]+wa1[i-1]*cc[t3];
  105236. ti2=wa1[i-2]*cc[t3]-wa1[i-1]*cc[t3-1];
  105237. ch[t6]=cc[t5]+ti2;
  105238. ch[t4]=ti2-cc[t5];
  105239. ch[t6-1]=cc[t5-1]+tr2;
  105240. ch[t4-1]=cc[t5-1]-tr2;
  105241. }
  105242. t1+=ido;
  105243. t2+=ido;
  105244. }
  105245. if(ido%2==1)return;
  105246. L105:
  105247. t3=(t2=(t1=ido)-1);
  105248. t2+=t0;
  105249. for(k=0;k<l1;k++){
  105250. ch[t1]=-cc[t2];
  105251. ch[t1-1]=cc[t3];
  105252. t1+=ido<<1;
  105253. t2+=ido;
  105254. t3+=ido;
  105255. }
  105256. }
  105257. static void dradf4(int ido,int l1,float *cc,float *ch,float *wa1,
  105258. float *wa2,float *wa3){
  105259. static float hsqt2 = .70710678118654752f;
  105260. int i,k,t0,t1,t2,t3,t4,t5,t6;
  105261. float ci2,ci3,ci4,cr2,cr3,cr4,ti1,ti2,ti3,ti4,tr1,tr2,tr3,tr4;
  105262. t0=l1*ido;
  105263. t1=t0;
  105264. t4=t1<<1;
  105265. t2=t1+(t1<<1);
  105266. t3=0;
  105267. for(k=0;k<l1;k++){
  105268. tr1=cc[t1]+cc[t2];
  105269. tr2=cc[t3]+cc[t4];
  105270. ch[t5=t3<<2]=tr1+tr2;
  105271. ch[(ido<<2)+t5-1]=tr2-tr1;
  105272. ch[(t5+=(ido<<1))-1]=cc[t3]-cc[t4];
  105273. ch[t5]=cc[t2]-cc[t1];
  105274. t1+=ido;
  105275. t2+=ido;
  105276. t3+=ido;
  105277. t4+=ido;
  105278. }
  105279. if(ido<2)return;
  105280. if(ido==2)goto L105;
  105281. t1=0;
  105282. for(k=0;k<l1;k++){
  105283. t2=t1;
  105284. t4=t1<<2;
  105285. t5=(t6=ido<<1)+t4;
  105286. for(i=2;i<ido;i+=2){
  105287. t3=(t2+=2);
  105288. t4+=2;
  105289. t5-=2;
  105290. t3+=t0;
  105291. cr2=wa1[i-2]*cc[t3-1]+wa1[i-1]*cc[t3];
  105292. ci2=wa1[i-2]*cc[t3]-wa1[i-1]*cc[t3-1];
  105293. t3+=t0;
  105294. cr3=wa2[i-2]*cc[t3-1]+wa2[i-1]*cc[t3];
  105295. ci3=wa2[i-2]*cc[t3]-wa2[i-1]*cc[t3-1];
  105296. t3+=t0;
  105297. cr4=wa3[i-2]*cc[t3-1]+wa3[i-1]*cc[t3];
  105298. ci4=wa3[i-2]*cc[t3]-wa3[i-1]*cc[t3-1];
  105299. tr1=cr2+cr4;
  105300. tr4=cr4-cr2;
  105301. ti1=ci2+ci4;
  105302. ti4=ci2-ci4;
  105303. ti2=cc[t2]+ci3;
  105304. ti3=cc[t2]-ci3;
  105305. tr2=cc[t2-1]+cr3;
  105306. tr3=cc[t2-1]-cr3;
  105307. ch[t4-1]=tr1+tr2;
  105308. ch[t4]=ti1+ti2;
  105309. ch[t5-1]=tr3-ti4;
  105310. ch[t5]=tr4-ti3;
  105311. ch[t4+t6-1]=ti4+tr3;
  105312. ch[t4+t6]=tr4+ti3;
  105313. ch[t5+t6-1]=tr2-tr1;
  105314. ch[t5+t6]=ti1-ti2;
  105315. }
  105316. t1+=ido;
  105317. }
  105318. if(ido&1)return;
  105319. L105:
  105320. t2=(t1=t0+ido-1)+(t0<<1);
  105321. t3=ido<<2;
  105322. t4=ido;
  105323. t5=ido<<1;
  105324. t6=ido;
  105325. for(k=0;k<l1;k++){
  105326. ti1=-hsqt2*(cc[t1]+cc[t2]);
  105327. tr1=hsqt2*(cc[t1]-cc[t2]);
  105328. ch[t4-1]=tr1+cc[t6-1];
  105329. ch[t4+t5-1]=cc[t6-1]-tr1;
  105330. ch[t4]=ti1-cc[t1+t0];
  105331. ch[t4+t5]=ti1+cc[t1+t0];
  105332. t1+=ido;
  105333. t2+=ido;
  105334. t4+=t3;
  105335. t6+=ido;
  105336. }
  105337. }
  105338. static void dradfg(int ido,int ip,int l1,int idl1,float *cc,float *c1,
  105339. float *c2,float *ch,float *ch2,float *wa){
  105340. static float tpi=6.283185307179586f;
  105341. int idij,ipph,i,j,k,l,ic,ik,is;
  105342. int t0,t1,t2,t3,t4,t5,t6,t7,t8,t9,t10;
  105343. float dc2,ai1,ai2,ar1,ar2,ds2;
  105344. int nbd;
  105345. float dcp,arg,dsp,ar1h,ar2h;
  105346. int idp2,ipp2;
  105347. arg=tpi/(float)ip;
  105348. dcp=cos(arg);
  105349. dsp=sin(arg);
  105350. ipph=(ip+1)>>1;
  105351. ipp2=ip;
  105352. idp2=ido;
  105353. nbd=(ido-1)>>1;
  105354. t0=l1*ido;
  105355. t10=ip*ido;
  105356. if(ido==1)goto L119;
  105357. for(ik=0;ik<idl1;ik++)ch2[ik]=c2[ik];
  105358. t1=0;
  105359. for(j=1;j<ip;j++){
  105360. t1+=t0;
  105361. t2=t1;
  105362. for(k=0;k<l1;k++){
  105363. ch[t2]=c1[t2];
  105364. t2+=ido;
  105365. }
  105366. }
  105367. is=-ido;
  105368. t1=0;
  105369. if(nbd>l1){
  105370. for(j=1;j<ip;j++){
  105371. t1+=t0;
  105372. is+=ido;
  105373. t2= -ido+t1;
  105374. for(k=0;k<l1;k++){
  105375. idij=is-1;
  105376. t2+=ido;
  105377. t3=t2;
  105378. for(i=2;i<ido;i+=2){
  105379. idij+=2;
  105380. t3+=2;
  105381. ch[t3-1]=wa[idij-1]*c1[t3-1]+wa[idij]*c1[t3];
  105382. ch[t3]=wa[idij-1]*c1[t3]-wa[idij]*c1[t3-1];
  105383. }
  105384. }
  105385. }
  105386. }else{
  105387. for(j=1;j<ip;j++){
  105388. is+=ido;
  105389. idij=is-1;
  105390. t1+=t0;
  105391. t2=t1;
  105392. for(i=2;i<ido;i+=2){
  105393. idij+=2;
  105394. t2+=2;
  105395. t3=t2;
  105396. for(k=0;k<l1;k++){
  105397. ch[t3-1]=wa[idij-1]*c1[t3-1]+wa[idij]*c1[t3];
  105398. ch[t3]=wa[idij-1]*c1[t3]-wa[idij]*c1[t3-1];
  105399. t3+=ido;
  105400. }
  105401. }
  105402. }
  105403. }
  105404. t1=0;
  105405. t2=ipp2*t0;
  105406. if(nbd<l1){
  105407. for(j=1;j<ipph;j++){
  105408. t1+=t0;
  105409. t2-=t0;
  105410. t3=t1;
  105411. t4=t2;
  105412. for(i=2;i<ido;i+=2){
  105413. t3+=2;
  105414. t4+=2;
  105415. t5=t3-ido;
  105416. t6=t4-ido;
  105417. for(k=0;k<l1;k++){
  105418. t5+=ido;
  105419. t6+=ido;
  105420. c1[t5-1]=ch[t5-1]+ch[t6-1];
  105421. c1[t6-1]=ch[t5]-ch[t6];
  105422. c1[t5]=ch[t5]+ch[t6];
  105423. c1[t6]=ch[t6-1]-ch[t5-1];
  105424. }
  105425. }
  105426. }
  105427. }else{
  105428. for(j=1;j<ipph;j++){
  105429. t1+=t0;
  105430. t2-=t0;
  105431. t3=t1;
  105432. t4=t2;
  105433. for(k=0;k<l1;k++){
  105434. t5=t3;
  105435. t6=t4;
  105436. for(i=2;i<ido;i+=2){
  105437. t5+=2;
  105438. t6+=2;
  105439. c1[t5-1]=ch[t5-1]+ch[t6-1];
  105440. c1[t6-1]=ch[t5]-ch[t6];
  105441. c1[t5]=ch[t5]+ch[t6];
  105442. c1[t6]=ch[t6-1]-ch[t5-1];
  105443. }
  105444. t3+=ido;
  105445. t4+=ido;
  105446. }
  105447. }
  105448. }
  105449. L119:
  105450. for(ik=0;ik<idl1;ik++)c2[ik]=ch2[ik];
  105451. t1=0;
  105452. t2=ipp2*idl1;
  105453. for(j=1;j<ipph;j++){
  105454. t1+=t0;
  105455. t2-=t0;
  105456. t3=t1-ido;
  105457. t4=t2-ido;
  105458. for(k=0;k<l1;k++){
  105459. t3+=ido;
  105460. t4+=ido;
  105461. c1[t3]=ch[t3]+ch[t4];
  105462. c1[t4]=ch[t4]-ch[t3];
  105463. }
  105464. }
  105465. ar1=1.f;
  105466. ai1=0.f;
  105467. t1=0;
  105468. t2=ipp2*idl1;
  105469. t3=(ip-1)*idl1;
  105470. for(l=1;l<ipph;l++){
  105471. t1+=idl1;
  105472. t2-=idl1;
  105473. ar1h=dcp*ar1-dsp*ai1;
  105474. ai1=dcp*ai1+dsp*ar1;
  105475. ar1=ar1h;
  105476. t4=t1;
  105477. t5=t2;
  105478. t6=t3;
  105479. t7=idl1;
  105480. for(ik=0;ik<idl1;ik++){
  105481. ch2[t4++]=c2[ik]+ar1*c2[t7++];
  105482. ch2[t5++]=ai1*c2[t6++];
  105483. }
  105484. dc2=ar1;
  105485. ds2=ai1;
  105486. ar2=ar1;
  105487. ai2=ai1;
  105488. t4=idl1;
  105489. t5=(ipp2-1)*idl1;
  105490. for(j=2;j<ipph;j++){
  105491. t4+=idl1;
  105492. t5-=idl1;
  105493. ar2h=dc2*ar2-ds2*ai2;
  105494. ai2=dc2*ai2+ds2*ar2;
  105495. ar2=ar2h;
  105496. t6=t1;
  105497. t7=t2;
  105498. t8=t4;
  105499. t9=t5;
  105500. for(ik=0;ik<idl1;ik++){
  105501. ch2[t6++]+=ar2*c2[t8++];
  105502. ch2[t7++]+=ai2*c2[t9++];
  105503. }
  105504. }
  105505. }
  105506. t1=0;
  105507. for(j=1;j<ipph;j++){
  105508. t1+=idl1;
  105509. t2=t1;
  105510. for(ik=0;ik<idl1;ik++)ch2[ik]+=c2[t2++];
  105511. }
  105512. if(ido<l1)goto L132;
  105513. t1=0;
  105514. t2=0;
  105515. for(k=0;k<l1;k++){
  105516. t3=t1;
  105517. t4=t2;
  105518. for(i=0;i<ido;i++)cc[t4++]=ch[t3++];
  105519. t1+=ido;
  105520. t2+=t10;
  105521. }
  105522. goto L135;
  105523. L132:
  105524. for(i=0;i<ido;i++){
  105525. t1=i;
  105526. t2=i;
  105527. for(k=0;k<l1;k++){
  105528. cc[t2]=ch[t1];
  105529. t1+=ido;
  105530. t2+=t10;
  105531. }
  105532. }
  105533. L135:
  105534. t1=0;
  105535. t2=ido<<1;
  105536. t3=0;
  105537. t4=ipp2*t0;
  105538. for(j=1;j<ipph;j++){
  105539. t1+=t2;
  105540. t3+=t0;
  105541. t4-=t0;
  105542. t5=t1;
  105543. t6=t3;
  105544. t7=t4;
  105545. for(k=0;k<l1;k++){
  105546. cc[t5-1]=ch[t6];
  105547. cc[t5]=ch[t7];
  105548. t5+=t10;
  105549. t6+=ido;
  105550. t7+=ido;
  105551. }
  105552. }
  105553. if(ido==1)return;
  105554. if(nbd<l1)goto L141;
  105555. t1=-ido;
  105556. t3=0;
  105557. t4=0;
  105558. t5=ipp2*t0;
  105559. for(j=1;j<ipph;j++){
  105560. t1+=t2;
  105561. t3+=t2;
  105562. t4+=t0;
  105563. t5-=t0;
  105564. t6=t1;
  105565. t7=t3;
  105566. t8=t4;
  105567. t9=t5;
  105568. for(k=0;k<l1;k++){
  105569. for(i=2;i<ido;i+=2){
  105570. ic=idp2-i;
  105571. cc[i+t7-1]=ch[i+t8-1]+ch[i+t9-1];
  105572. cc[ic+t6-1]=ch[i+t8-1]-ch[i+t9-1];
  105573. cc[i+t7]=ch[i+t8]+ch[i+t9];
  105574. cc[ic+t6]=ch[i+t9]-ch[i+t8];
  105575. }
  105576. t6+=t10;
  105577. t7+=t10;
  105578. t8+=ido;
  105579. t9+=ido;
  105580. }
  105581. }
  105582. return;
  105583. L141:
  105584. t1=-ido;
  105585. t3=0;
  105586. t4=0;
  105587. t5=ipp2*t0;
  105588. for(j=1;j<ipph;j++){
  105589. t1+=t2;
  105590. t3+=t2;
  105591. t4+=t0;
  105592. t5-=t0;
  105593. for(i=2;i<ido;i+=2){
  105594. t6=idp2+t1-i;
  105595. t7=i+t3;
  105596. t8=i+t4;
  105597. t9=i+t5;
  105598. for(k=0;k<l1;k++){
  105599. cc[t7-1]=ch[t8-1]+ch[t9-1];
  105600. cc[t6-1]=ch[t8-1]-ch[t9-1];
  105601. cc[t7]=ch[t8]+ch[t9];
  105602. cc[t6]=ch[t9]-ch[t8];
  105603. t6+=t10;
  105604. t7+=t10;
  105605. t8+=ido;
  105606. t9+=ido;
  105607. }
  105608. }
  105609. }
  105610. }
  105611. static void drftf1(int n,float *c,float *ch,float *wa,int *ifac){
  105612. int i,k1,l1,l2;
  105613. int na,kh,nf;
  105614. int ip,iw,ido,idl1,ix2,ix3;
  105615. nf=ifac[1];
  105616. na=1;
  105617. l2=n;
  105618. iw=n;
  105619. for(k1=0;k1<nf;k1++){
  105620. kh=nf-k1;
  105621. ip=ifac[kh+1];
  105622. l1=l2/ip;
  105623. ido=n/l2;
  105624. idl1=ido*l1;
  105625. iw-=(ip-1)*ido;
  105626. na=1-na;
  105627. if(ip!=4)goto L102;
  105628. ix2=iw+ido;
  105629. ix3=ix2+ido;
  105630. if(na!=0)
  105631. dradf4(ido,l1,ch,c,wa+iw-1,wa+ix2-1,wa+ix3-1);
  105632. else
  105633. dradf4(ido,l1,c,ch,wa+iw-1,wa+ix2-1,wa+ix3-1);
  105634. goto L110;
  105635. L102:
  105636. if(ip!=2)goto L104;
  105637. if(na!=0)goto L103;
  105638. dradf2(ido,l1,c,ch,wa+iw-1);
  105639. goto L110;
  105640. L103:
  105641. dradf2(ido,l1,ch,c,wa+iw-1);
  105642. goto L110;
  105643. L104:
  105644. if(ido==1)na=1-na;
  105645. if(na!=0)goto L109;
  105646. dradfg(ido,ip,l1,idl1,c,c,c,ch,ch,wa+iw-1);
  105647. na=1;
  105648. goto L110;
  105649. L109:
  105650. dradfg(ido,ip,l1,idl1,ch,ch,ch,c,c,wa+iw-1);
  105651. na=0;
  105652. L110:
  105653. l2=l1;
  105654. }
  105655. if(na==1)return;
  105656. for(i=0;i<n;i++)c[i]=ch[i];
  105657. }
  105658. static void dradb2(int ido,int l1,float *cc,float *ch,float *wa1){
  105659. int i,k,t0,t1,t2,t3,t4,t5,t6;
  105660. float ti2,tr2;
  105661. t0=l1*ido;
  105662. t1=0;
  105663. t2=0;
  105664. t3=(ido<<1)-1;
  105665. for(k=0;k<l1;k++){
  105666. ch[t1]=cc[t2]+cc[t3+t2];
  105667. ch[t1+t0]=cc[t2]-cc[t3+t2];
  105668. t2=(t1+=ido)<<1;
  105669. }
  105670. if(ido<2)return;
  105671. if(ido==2)goto L105;
  105672. t1=0;
  105673. t2=0;
  105674. for(k=0;k<l1;k++){
  105675. t3=t1;
  105676. t5=(t4=t2)+(ido<<1);
  105677. t6=t0+t1;
  105678. for(i=2;i<ido;i+=2){
  105679. t3+=2;
  105680. t4+=2;
  105681. t5-=2;
  105682. t6+=2;
  105683. ch[t3-1]=cc[t4-1]+cc[t5-1];
  105684. tr2=cc[t4-1]-cc[t5-1];
  105685. ch[t3]=cc[t4]-cc[t5];
  105686. ti2=cc[t4]+cc[t5];
  105687. ch[t6-1]=wa1[i-2]*tr2-wa1[i-1]*ti2;
  105688. ch[t6]=wa1[i-2]*ti2+wa1[i-1]*tr2;
  105689. }
  105690. t2=(t1+=ido)<<1;
  105691. }
  105692. if(ido%2==1)return;
  105693. L105:
  105694. t1=ido-1;
  105695. t2=ido-1;
  105696. for(k=0;k<l1;k++){
  105697. ch[t1]=cc[t2]+cc[t2];
  105698. ch[t1+t0]=-(cc[t2+1]+cc[t2+1]);
  105699. t1+=ido;
  105700. t2+=ido<<1;
  105701. }
  105702. }
  105703. static void dradb3(int ido,int l1,float *cc,float *ch,float *wa1,
  105704. float *wa2){
  105705. static float taur = -.5f;
  105706. static float taui = .8660254037844386f;
  105707. int i,k,t0,t1,t2,t3,t4,t5,t6,t7,t8,t9,t10;
  105708. float ci2,ci3,di2,di3,cr2,cr3,dr2,dr3,ti2,tr2;
  105709. t0=l1*ido;
  105710. t1=0;
  105711. t2=t0<<1;
  105712. t3=ido<<1;
  105713. t4=ido+(ido<<1);
  105714. t5=0;
  105715. for(k=0;k<l1;k++){
  105716. tr2=cc[t3-1]+cc[t3-1];
  105717. cr2=cc[t5]+(taur*tr2);
  105718. ch[t1]=cc[t5]+tr2;
  105719. ci3=taui*(cc[t3]+cc[t3]);
  105720. ch[t1+t0]=cr2-ci3;
  105721. ch[t1+t2]=cr2+ci3;
  105722. t1+=ido;
  105723. t3+=t4;
  105724. t5+=t4;
  105725. }
  105726. if(ido==1)return;
  105727. t1=0;
  105728. t3=ido<<1;
  105729. for(k=0;k<l1;k++){
  105730. t7=t1+(t1<<1);
  105731. t6=(t5=t7+t3);
  105732. t8=t1;
  105733. t10=(t9=t1+t0)+t0;
  105734. for(i=2;i<ido;i+=2){
  105735. t5+=2;
  105736. t6-=2;
  105737. t7+=2;
  105738. t8+=2;
  105739. t9+=2;
  105740. t10+=2;
  105741. tr2=cc[t5-1]+cc[t6-1];
  105742. cr2=cc[t7-1]+(taur*tr2);
  105743. ch[t8-1]=cc[t7-1]+tr2;
  105744. ti2=cc[t5]-cc[t6];
  105745. ci2=cc[t7]+(taur*ti2);
  105746. ch[t8]=cc[t7]+ti2;
  105747. cr3=taui*(cc[t5-1]-cc[t6-1]);
  105748. ci3=taui*(cc[t5]+cc[t6]);
  105749. dr2=cr2-ci3;
  105750. dr3=cr2+ci3;
  105751. di2=ci2+cr3;
  105752. di3=ci2-cr3;
  105753. ch[t9-1]=wa1[i-2]*dr2-wa1[i-1]*di2;
  105754. ch[t9]=wa1[i-2]*di2+wa1[i-1]*dr2;
  105755. ch[t10-1]=wa2[i-2]*dr3-wa2[i-1]*di3;
  105756. ch[t10]=wa2[i-2]*di3+wa2[i-1]*dr3;
  105757. }
  105758. t1+=ido;
  105759. }
  105760. }
  105761. static void dradb4(int ido,int l1,float *cc,float *ch,float *wa1,
  105762. float *wa2,float *wa3){
  105763. static float sqrt2=1.414213562373095f;
  105764. int i,k,t0,t1,t2,t3,t4,t5,t6,t7,t8;
  105765. float ci2,ci3,ci4,cr2,cr3,cr4,ti1,ti2,ti3,ti4,tr1,tr2,tr3,tr4;
  105766. t0=l1*ido;
  105767. t1=0;
  105768. t2=ido<<2;
  105769. t3=0;
  105770. t6=ido<<1;
  105771. for(k=0;k<l1;k++){
  105772. t4=t3+t6;
  105773. t5=t1;
  105774. tr3=cc[t4-1]+cc[t4-1];
  105775. tr4=cc[t4]+cc[t4];
  105776. tr1=cc[t3]-cc[(t4+=t6)-1];
  105777. tr2=cc[t3]+cc[t4-1];
  105778. ch[t5]=tr2+tr3;
  105779. ch[t5+=t0]=tr1-tr4;
  105780. ch[t5+=t0]=tr2-tr3;
  105781. ch[t5+=t0]=tr1+tr4;
  105782. t1+=ido;
  105783. t3+=t2;
  105784. }
  105785. if(ido<2)return;
  105786. if(ido==2)goto L105;
  105787. t1=0;
  105788. for(k=0;k<l1;k++){
  105789. t5=(t4=(t3=(t2=t1<<2)+t6))+t6;
  105790. t7=t1;
  105791. for(i=2;i<ido;i+=2){
  105792. t2+=2;
  105793. t3+=2;
  105794. t4-=2;
  105795. t5-=2;
  105796. t7+=2;
  105797. ti1=cc[t2]+cc[t5];
  105798. ti2=cc[t2]-cc[t5];
  105799. ti3=cc[t3]-cc[t4];
  105800. tr4=cc[t3]+cc[t4];
  105801. tr1=cc[t2-1]-cc[t5-1];
  105802. tr2=cc[t2-1]+cc[t5-1];
  105803. ti4=cc[t3-1]-cc[t4-1];
  105804. tr3=cc[t3-1]+cc[t4-1];
  105805. ch[t7-1]=tr2+tr3;
  105806. cr3=tr2-tr3;
  105807. ch[t7]=ti2+ti3;
  105808. ci3=ti2-ti3;
  105809. cr2=tr1-tr4;
  105810. cr4=tr1+tr4;
  105811. ci2=ti1+ti4;
  105812. ci4=ti1-ti4;
  105813. ch[(t8=t7+t0)-1]=wa1[i-2]*cr2-wa1[i-1]*ci2;
  105814. ch[t8]=wa1[i-2]*ci2+wa1[i-1]*cr2;
  105815. ch[(t8+=t0)-1]=wa2[i-2]*cr3-wa2[i-1]*ci3;
  105816. ch[t8]=wa2[i-2]*ci3+wa2[i-1]*cr3;
  105817. ch[(t8+=t0)-1]=wa3[i-2]*cr4-wa3[i-1]*ci4;
  105818. ch[t8]=wa3[i-2]*ci4+wa3[i-1]*cr4;
  105819. }
  105820. t1+=ido;
  105821. }
  105822. if(ido%2 == 1)return;
  105823. L105:
  105824. t1=ido;
  105825. t2=ido<<2;
  105826. t3=ido-1;
  105827. t4=ido+(ido<<1);
  105828. for(k=0;k<l1;k++){
  105829. t5=t3;
  105830. ti1=cc[t1]+cc[t4];
  105831. ti2=cc[t4]-cc[t1];
  105832. tr1=cc[t1-1]-cc[t4-1];
  105833. tr2=cc[t1-1]+cc[t4-1];
  105834. ch[t5]=tr2+tr2;
  105835. ch[t5+=t0]=sqrt2*(tr1-ti1);
  105836. ch[t5+=t0]=ti2+ti2;
  105837. ch[t5+=t0]=-sqrt2*(tr1+ti1);
  105838. t3+=ido;
  105839. t1+=t2;
  105840. t4+=t2;
  105841. }
  105842. }
  105843. static void dradbg(int ido,int ip,int l1,int idl1,float *cc,float *c1,
  105844. float *c2,float *ch,float *ch2,float *wa){
  105845. static float tpi=6.283185307179586f;
  105846. int idij,ipph,i,j,k,l,ik,is,t0,t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,
  105847. t11,t12;
  105848. float dc2,ai1,ai2,ar1,ar2,ds2;
  105849. int nbd;
  105850. float dcp,arg,dsp,ar1h,ar2h;
  105851. int ipp2;
  105852. t10=ip*ido;
  105853. t0=l1*ido;
  105854. arg=tpi/(float)ip;
  105855. dcp=cos(arg);
  105856. dsp=sin(arg);
  105857. nbd=(ido-1)>>1;
  105858. ipp2=ip;
  105859. ipph=(ip+1)>>1;
  105860. if(ido<l1)goto L103;
  105861. t1=0;
  105862. t2=0;
  105863. for(k=0;k<l1;k++){
  105864. t3=t1;
  105865. t4=t2;
  105866. for(i=0;i<ido;i++){
  105867. ch[t3]=cc[t4];
  105868. t3++;
  105869. t4++;
  105870. }
  105871. t1+=ido;
  105872. t2+=t10;
  105873. }
  105874. goto L106;
  105875. L103:
  105876. t1=0;
  105877. for(i=0;i<ido;i++){
  105878. t2=t1;
  105879. t3=t1;
  105880. for(k=0;k<l1;k++){
  105881. ch[t2]=cc[t3];
  105882. t2+=ido;
  105883. t3+=t10;
  105884. }
  105885. t1++;
  105886. }
  105887. L106:
  105888. t1=0;
  105889. t2=ipp2*t0;
  105890. t7=(t5=ido<<1);
  105891. for(j=1;j<ipph;j++){
  105892. t1+=t0;
  105893. t2-=t0;
  105894. t3=t1;
  105895. t4=t2;
  105896. t6=t5;
  105897. for(k=0;k<l1;k++){
  105898. ch[t3]=cc[t6-1]+cc[t6-1];
  105899. ch[t4]=cc[t6]+cc[t6];
  105900. t3+=ido;
  105901. t4+=ido;
  105902. t6+=t10;
  105903. }
  105904. t5+=t7;
  105905. }
  105906. if (ido == 1)goto L116;
  105907. if(nbd<l1)goto L112;
  105908. t1=0;
  105909. t2=ipp2*t0;
  105910. t7=0;
  105911. for(j=1;j<ipph;j++){
  105912. t1+=t0;
  105913. t2-=t0;
  105914. t3=t1;
  105915. t4=t2;
  105916. t7+=(ido<<1);
  105917. t8=t7;
  105918. for(k=0;k<l1;k++){
  105919. t5=t3;
  105920. t6=t4;
  105921. t9=t8;
  105922. t11=t8;
  105923. for(i=2;i<ido;i+=2){
  105924. t5+=2;
  105925. t6+=2;
  105926. t9+=2;
  105927. t11-=2;
  105928. ch[t5-1]=cc[t9-1]+cc[t11-1];
  105929. ch[t6-1]=cc[t9-1]-cc[t11-1];
  105930. ch[t5]=cc[t9]-cc[t11];
  105931. ch[t6]=cc[t9]+cc[t11];
  105932. }
  105933. t3+=ido;
  105934. t4+=ido;
  105935. t8+=t10;
  105936. }
  105937. }
  105938. goto L116;
  105939. L112:
  105940. t1=0;
  105941. t2=ipp2*t0;
  105942. t7=0;
  105943. for(j=1;j<ipph;j++){
  105944. t1+=t0;
  105945. t2-=t0;
  105946. t3=t1;
  105947. t4=t2;
  105948. t7+=(ido<<1);
  105949. t8=t7;
  105950. t9=t7;
  105951. for(i=2;i<ido;i+=2){
  105952. t3+=2;
  105953. t4+=2;
  105954. t8+=2;
  105955. t9-=2;
  105956. t5=t3;
  105957. t6=t4;
  105958. t11=t8;
  105959. t12=t9;
  105960. for(k=0;k<l1;k++){
  105961. ch[t5-1]=cc[t11-1]+cc[t12-1];
  105962. ch[t6-1]=cc[t11-1]-cc[t12-1];
  105963. ch[t5]=cc[t11]-cc[t12];
  105964. ch[t6]=cc[t11]+cc[t12];
  105965. t5+=ido;
  105966. t6+=ido;
  105967. t11+=t10;
  105968. t12+=t10;
  105969. }
  105970. }
  105971. }
  105972. L116:
  105973. ar1=1.f;
  105974. ai1=0.f;
  105975. t1=0;
  105976. t9=(t2=ipp2*idl1);
  105977. t3=(ip-1)*idl1;
  105978. for(l=1;l<ipph;l++){
  105979. t1+=idl1;
  105980. t2-=idl1;
  105981. ar1h=dcp*ar1-dsp*ai1;
  105982. ai1=dcp*ai1+dsp*ar1;
  105983. ar1=ar1h;
  105984. t4=t1;
  105985. t5=t2;
  105986. t6=0;
  105987. t7=idl1;
  105988. t8=t3;
  105989. for(ik=0;ik<idl1;ik++){
  105990. c2[t4++]=ch2[t6++]+ar1*ch2[t7++];
  105991. c2[t5++]=ai1*ch2[t8++];
  105992. }
  105993. dc2=ar1;
  105994. ds2=ai1;
  105995. ar2=ar1;
  105996. ai2=ai1;
  105997. t6=idl1;
  105998. t7=t9-idl1;
  105999. for(j=2;j<ipph;j++){
  106000. t6+=idl1;
  106001. t7-=idl1;
  106002. ar2h=dc2*ar2-ds2*ai2;
  106003. ai2=dc2*ai2+ds2*ar2;
  106004. ar2=ar2h;
  106005. t4=t1;
  106006. t5=t2;
  106007. t11=t6;
  106008. t12=t7;
  106009. for(ik=0;ik<idl1;ik++){
  106010. c2[t4++]+=ar2*ch2[t11++];
  106011. c2[t5++]+=ai2*ch2[t12++];
  106012. }
  106013. }
  106014. }
  106015. t1=0;
  106016. for(j=1;j<ipph;j++){
  106017. t1+=idl1;
  106018. t2=t1;
  106019. for(ik=0;ik<idl1;ik++)ch2[ik]+=ch2[t2++];
  106020. }
  106021. t1=0;
  106022. t2=ipp2*t0;
  106023. for(j=1;j<ipph;j++){
  106024. t1+=t0;
  106025. t2-=t0;
  106026. t3=t1;
  106027. t4=t2;
  106028. for(k=0;k<l1;k++){
  106029. ch[t3]=c1[t3]-c1[t4];
  106030. ch[t4]=c1[t3]+c1[t4];
  106031. t3+=ido;
  106032. t4+=ido;
  106033. }
  106034. }
  106035. if(ido==1)goto L132;
  106036. if(nbd<l1)goto L128;
  106037. t1=0;
  106038. t2=ipp2*t0;
  106039. for(j=1;j<ipph;j++){
  106040. t1+=t0;
  106041. t2-=t0;
  106042. t3=t1;
  106043. t4=t2;
  106044. for(k=0;k<l1;k++){
  106045. t5=t3;
  106046. t6=t4;
  106047. for(i=2;i<ido;i+=2){
  106048. t5+=2;
  106049. t6+=2;
  106050. ch[t5-1]=c1[t5-1]-c1[t6];
  106051. ch[t6-1]=c1[t5-1]+c1[t6];
  106052. ch[t5]=c1[t5]+c1[t6-1];
  106053. ch[t6]=c1[t5]-c1[t6-1];
  106054. }
  106055. t3+=ido;
  106056. t4+=ido;
  106057. }
  106058. }
  106059. goto L132;
  106060. L128:
  106061. t1=0;
  106062. t2=ipp2*t0;
  106063. for(j=1;j<ipph;j++){
  106064. t1+=t0;
  106065. t2-=t0;
  106066. t3=t1;
  106067. t4=t2;
  106068. for(i=2;i<ido;i+=2){
  106069. t3+=2;
  106070. t4+=2;
  106071. t5=t3;
  106072. t6=t4;
  106073. for(k=0;k<l1;k++){
  106074. ch[t5-1]=c1[t5-1]-c1[t6];
  106075. ch[t6-1]=c1[t5-1]+c1[t6];
  106076. ch[t5]=c1[t5]+c1[t6-1];
  106077. ch[t6]=c1[t5]-c1[t6-1];
  106078. t5+=ido;
  106079. t6+=ido;
  106080. }
  106081. }
  106082. }
  106083. L132:
  106084. if(ido==1)return;
  106085. for(ik=0;ik<idl1;ik++)c2[ik]=ch2[ik];
  106086. t1=0;
  106087. for(j=1;j<ip;j++){
  106088. t2=(t1+=t0);
  106089. for(k=0;k<l1;k++){
  106090. c1[t2]=ch[t2];
  106091. t2+=ido;
  106092. }
  106093. }
  106094. if(nbd>l1)goto L139;
  106095. is= -ido-1;
  106096. t1=0;
  106097. for(j=1;j<ip;j++){
  106098. is+=ido;
  106099. t1+=t0;
  106100. idij=is;
  106101. t2=t1;
  106102. for(i=2;i<ido;i+=2){
  106103. t2+=2;
  106104. idij+=2;
  106105. t3=t2;
  106106. for(k=0;k<l1;k++){
  106107. c1[t3-1]=wa[idij-1]*ch[t3-1]-wa[idij]*ch[t3];
  106108. c1[t3]=wa[idij-1]*ch[t3]+wa[idij]*ch[t3-1];
  106109. t3+=ido;
  106110. }
  106111. }
  106112. }
  106113. return;
  106114. L139:
  106115. is= -ido-1;
  106116. t1=0;
  106117. for(j=1;j<ip;j++){
  106118. is+=ido;
  106119. t1+=t0;
  106120. t2=t1;
  106121. for(k=0;k<l1;k++){
  106122. idij=is;
  106123. t3=t2;
  106124. for(i=2;i<ido;i+=2){
  106125. idij+=2;
  106126. t3+=2;
  106127. c1[t3-1]=wa[idij-1]*ch[t3-1]-wa[idij]*ch[t3];
  106128. c1[t3]=wa[idij-1]*ch[t3]+wa[idij]*ch[t3-1];
  106129. }
  106130. t2+=ido;
  106131. }
  106132. }
  106133. }
  106134. static void drftb1(int n, float *c, float *ch, float *wa, int *ifac){
  106135. int i,k1,l1,l2;
  106136. int na;
  106137. int nf,ip,iw,ix2,ix3,ido,idl1;
  106138. nf=ifac[1];
  106139. na=0;
  106140. l1=1;
  106141. iw=1;
  106142. for(k1=0;k1<nf;k1++){
  106143. ip=ifac[k1 + 2];
  106144. l2=ip*l1;
  106145. ido=n/l2;
  106146. idl1=ido*l1;
  106147. if(ip!=4)goto L103;
  106148. ix2=iw+ido;
  106149. ix3=ix2+ido;
  106150. if(na!=0)
  106151. dradb4(ido,l1,ch,c,wa+iw-1,wa+ix2-1,wa+ix3-1);
  106152. else
  106153. dradb4(ido,l1,c,ch,wa+iw-1,wa+ix2-1,wa+ix3-1);
  106154. na=1-na;
  106155. goto L115;
  106156. L103:
  106157. if(ip!=2)goto L106;
  106158. if(na!=0)
  106159. dradb2(ido,l1,ch,c,wa+iw-1);
  106160. else
  106161. dradb2(ido,l1,c,ch,wa+iw-1);
  106162. na=1-na;
  106163. goto L115;
  106164. L106:
  106165. if(ip!=3)goto L109;
  106166. ix2=iw+ido;
  106167. if(na!=0)
  106168. dradb3(ido,l1,ch,c,wa+iw-1,wa+ix2-1);
  106169. else
  106170. dradb3(ido,l1,c,ch,wa+iw-1,wa+ix2-1);
  106171. na=1-na;
  106172. goto L115;
  106173. L109:
  106174. if(na!=0)
  106175. dradbg(ido,ip,l1,idl1,ch,ch,ch,c,c,wa+iw-1);
  106176. else
  106177. dradbg(ido,ip,l1,idl1,c,c,c,ch,ch,wa+iw-1);
  106178. if(ido==1)na=1-na;
  106179. L115:
  106180. l1=l2;
  106181. iw+=(ip-1)*ido;
  106182. }
  106183. if(na==0)return;
  106184. for(i=0;i<n;i++)c[i]=ch[i];
  106185. }
  106186. void drft_forward(drft_lookup *l,float *data){
  106187. if(l->n==1)return;
  106188. drftf1(l->n,data,l->trigcache,l->trigcache+l->n,l->splitcache);
  106189. }
  106190. void drft_backward(drft_lookup *l,float *data){
  106191. if (l->n==1)return;
  106192. drftb1(l->n,data,l->trigcache,l->trigcache+l->n,l->splitcache);
  106193. }
  106194. void drft_init(drft_lookup *l,int n){
  106195. l->n=n;
  106196. l->trigcache=(float*)_ogg_calloc(3*n,sizeof(*l->trigcache));
  106197. l->splitcache=(int*)_ogg_calloc(32,sizeof(*l->splitcache));
  106198. fdrffti(n, l->trigcache, l->splitcache);
  106199. }
  106200. void drft_clear(drft_lookup *l){
  106201. if(l){
  106202. if(l->trigcache)_ogg_free(l->trigcache);
  106203. if(l->splitcache)_ogg_free(l->splitcache);
  106204. memset(l,0,sizeof(*l));
  106205. }
  106206. }
  106207. #endif
  106208. /*** End of inlined file: smallft.c ***/
  106209. /*** Start of inlined file: synthesis.c ***/
  106210. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  106211. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  106212. // tasks..
  106213. #if JUCE_MSVC
  106214. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  106215. #endif
  106216. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  106217. #if JUCE_USE_OGGVORBIS
  106218. #include <stdio.h>
  106219. int vorbis_synthesis(vorbis_block *vb,ogg_packet *op){
  106220. vorbis_dsp_state *vd=vb->vd;
  106221. private_state *b=(private_state*)vd->backend_state;
  106222. vorbis_info *vi=vd->vi;
  106223. codec_setup_info *ci=(codec_setup_info*) vi->codec_setup;
  106224. oggpack_buffer *opb=&vb->opb;
  106225. int type,mode,i;
  106226. _vorbis_block_ripcord(vb);
  106227. oggpack_readinit(opb,op->packet,op->bytes);
  106228. if(oggpack_read(opb,1)!=0){
  106229. return(OV_ENOTAUDIO);
  106230. }
  106231. mode=oggpack_read(opb,b->modebits);
  106232. if(mode==-1)return(OV_EBADPACKET);
  106233. vb->mode=mode;
  106234. vb->W=ci->mode_param[mode]->blockflag;
  106235. if(vb->W){
  106236. vb->lW=oggpack_read(opb,1);
  106237. vb->nW=oggpack_read(opb,1);
  106238. if(vb->nW==-1) return(OV_EBADPACKET);
  106239. }else{
  106240. vb->lW=0;
  106241. vb->nW=0;
  106242. }
  106243. vb->granulepos=op->granulepos;
  106244. vb->sequence=op->packetno;
  106245. vb->eofflag=op->e_o_s;
  106246. vb->pcmend=ci->blocksizes[vb->W];
  106247. vb->pcm=(float**)_vorbis_block_alloc(vb,sizeof(*vb->pcm)*vi->channels);
  106248. for(i=0;i<vi->channels;i++)
  106249. vb->pcm[i]=(float*)_vorbis_block_alloc(vb,vb->pcmend*sizeof(*vb->pcm[i]));
  106250. type=ci->map_type[ci->mode_param[mode]->mapping];
  106251. return(_mapping_P[type]->inverse(vb,ci->map_param[ci->mode_param[mode]->
  106252. mapping]));
  106253. }
  106254. int vorbis_synthesis_trackonly(vorbis_block *vb,ogg_packet *op){
  106255. vorbis_dsp_state *vd=vb->vd;
  106256. private_state *b=(private_state*)vd->backend_state;
  106257. vorbis_info *vi=vd->vi;
  106258. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  106259. oggpack_buffer *opb=&vb->opb;
  106260. int mode;
  106261. _vorbis_block_ripcord(vb);
  106262. oggpack_readinit(opb,op->packet,op->bytes);
  106263. if(oggpack_read(opb,1)!=0){
  106264. return(OV_ENOTAUDIO);
  106265. }
  106266. mode=oggpack_read(opb,b->modebits);
  106267. if(mode==-1)return(OV_EBADPACKET);
  106268. vb->mode=mode;
  106269. vb->W=ci->mode_param[mode]->blockflag;
  106270. if(vb->W){
  106271. vb->lW=oggpack_read(opb,1);
  106272. vb->nW=oggpack_read(opb,1);
  106273. if(vb->nW==-1) return(OV_EBADPACKET);
  106274. }else{
  106275. vb->lW=0;
  106276. vb->nW=0;
  106277. }
  106278. vb->granulepos=op->granulepos;
  106279. vb->sequence=op->packetno;
  106280. vb->eofflag=op->e_o_s;
  106281. vb->pcmend=0;
  106282. vb->pcm=NULL;
  106283. return(0);
  106284. }
  106285. long vorbis_packet_blocksize(vorbis_info *vi,ogg_packet *op){
  106286. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  106287. oggpack_buffer opb;
  106288. int mode;
  106289. oggpack_readinit(&opb,op->packet,op->bytes);
  106290. if(oggpack_read(&opb,1)!=0){
  106291. return(OV_ENOTAUDIO);
  106292. }
  106293. {
  106294. int modebits=0;
  106295. int v=ci->modes;
  106296. while(v>1){
  106297. modebits++;
  106298. v>>=1;
  106299. }
  106300. mode=oggpack_read(&opb,modebits);
  106301. }
  106302. if(mode==-1)return(OV_EBADPACKET);
  106303. return(ci->blocksizes[ci->mode_param[mode]->blockflag]);
  106304. }
  106305. int vorbis_synthesis_halfrate(vorbis_info *vi,int flag){
  106306. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  106307. if(ci->blocksizes[0]<=64 && flag)return -1;
  106308. ci->halfrate_flag=(flag?1:0);
  106309. return 0;
  106310. }
  106311. int vorbis_synthesis_halfrate_p(vorbis_info *vi){
  106312. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  106313. return ci->halfrate_flag;
  106314. }
  106315. #endif
  106316. /*** End of inlined file: synthesis.c ***/
  106317. /*** Start of inlined file: vorbisenc.c ***/
  106318. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  106319. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  106320. // tasks..
  106321. #if JUCE_MSVC
  106322. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  106323. #endif
  106324. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  106325. #if JUCE_USE_OGGVORBIS
  106326. #include <stdlib.h>
  106327. #include <string.h>
  106328. #include <math.h>
  106329. typedef struct {
  106330. static_codebook *books[12][3];
  106331. } static_bookblock;
  106332. typedef struct {
  106333. int res_type;
  106334. int limit_type; /* 0 lowpass limited, 1 point stereo limited */
  106335. vorbis_info_residue0 *res;
  106336. static_codebook *book_aux;
  106337. static_codebook *book_aux_managed;
  106338. static_bookblock *books_base;
  106339. static_bookblock *books_base_managed;
  106340. } vorbis_residue_template;
  106341. typedef struct {
  106342. vorbis_info_mapping0 *map;
  106343. vorbis_residue_template *res;
  106344. } vorbis_mapping_template;
  106345. typedef struct vp_adjblock{
  106346. int block[P_BANDS];
  106347. } vp_adjblock;
  106348. typedef struct {
  106349. int data[NOISE_COMPAND_LEVELS];
  106350. } compandblock;
  106351. typedef struct {
  106352. int att[P_NOISECURVES];
  106353. float boost;
  106354. float decay;
  106355. } att3;
  106356. typedef struct { int data[P_NOISECURVES]; } adj3;
  106357. typedef struct {
  106358. int pre[PACKETBLOBS];
  106359. int post[PACKETBLOBS];
  106360. float kHz[PACKETBLOBS];
  106361. float lowpasskHz[PACKETBLOBS];
  106362. } adj_stereo;
  106363. typedef struct {
  106364. int lo;
  106365. int hi;
  106366. int fixed;
  106367. } noiseguard;
  106368. typedef struct {
  106369. int data[P_NOISECURVES][17];
  106370. } noise3;
  106371. typedef struct {
  106372. int mappings;
  106373. double *rate_mapping;
  106374. double *quality_mapping;
  106375. int coupling_restriction;
  106376. long samplerate_min_restriction;
  106377. long samplerate_max_restriction;
  106378. int *blocksize_short;
  106379. int *blocksize_long;
  106380. att3 *psy_tone_masteratt;
  106381. int *psy_tone_0dB;
  106382. int *psy_tone_dBsuppress;
  106383. vp_adjblock *psy_tone_adj_impulse;
  106384. vp_adjblock *psy_tone_adj_long;
  106385. vp_adjblock *psy_tone_adj_other;
  106386. noiseguard *psy_noiseguards;
  106387. noise3 *psy_noise_bias_impulse;
  106388. noise3 *psy_noise_bias_padding;
  106389. noise3 *psy_noise_bias_trans;
  106390. noise3 *psy_noise_bias_long;
  106391. int *psy_noise_dBsuppress;
  106392. compandblock *psy_noise_compand;
  106393. double *psy_noise_compand_short_mapping;
  106394. double *psy_noise_compand_long_mapping;
  106395. int *psy_noise_normal_start[2];
  106396. int *psy_noise_normal_partition[2];
  106397. double *psy_noise_normal_thresh;
  106398. int *psy_ath_float;
  106399. int *psy_ath_abs;
  106400. double *psy_lowpass;
  106401. vorbis_info_psy_global *global_params;
  106402. double *global_mapping;
  106403. adj_stereo *stereo_modes;
  106404. static_codebook ***floor_books;
  106405. vorbis_info_floor1 *floor_params;
  106406. int *floor_short_mapping;
  106407. int *floor_long_mapping;
  106408. vorbis_mapping_template *maps;
  106409. } ve_setup_data_template;
  106410. static vorbis_info_mode _mode_template[2]={
  106411. {0,0,0,0},
  106412. {1,0,0,1}
  106413. };
  106414. static vorbis_info_mapping0 _map_nominal[2]={
  106415. {1, {0,0}, {0}, {0}, 1,{0},{1}},
  106416. {1, {0,0}, {1}, {1}, 1,{0},{1}}
  106417. };
  106418. /*** Start of inlined file: setup_44.h ***/
  106419. /*** Start of inlined file: floor_all.h ***/
  106420. /*** Start of inlined file: floor_books.h ***/
  106421. static long _huff_lengthlist_line_256x7_0sub1[] = {
  106422. 0, 2, 3, 3, 3, 3, 4, 3, 4,
  106423. };
  106424. static static_codebook _huff_book_line_256x7_0sub1 = {
  106425. 1, 9,
  106426. _huff_lengthlist_line_256x7_0sub1,
  106427. 0, 0, 0, 0, 0,
  106428. NULL,
  106429. NULL,
  106430. NULL,
  106431. NULL,
  106432. 0
  106433. };
  106434. static long _huff_lengthlist_line_256x7_0sub2[] = {
  106435. 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 4, 3, 4, 3, 5, 3,
  106436. 6, 3, 6, 4, 6, 4, 7, 5, 7,
  106437. };
  106438. static static_codebook _huff_book_line_256x7_0sub2 = {
  106439. 1, 25,
  106440. _huff_lengthlist_line_256x7_0sub2,
  106441. 0, 0, 0, 0, 0,
  106442. NULL,
  106443. NULL,
  106444. NULL,
  106445. NULL,
  106446. 0
  106447. };
  106448. static long _huff_lengthlist_line_256x7_0sub3[] = {
  106449. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  106450. 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 5, 2, 5, 3, 5, 3,
  106451. 6, 3, 6, 4, 7, 6, 7, 8, 7, 9, 8, 9, 9, 9,10, 9,
  106452. 11,13,11,13,10,10,13,13,13,13,13,13,12,12,12,12,
  106453. };
  106454. static static_codebook _huff_book_line_256x7_0sub3 = {
  106455. 1, 64,
  106456. _huff_lengthlist_line_256x7_0sub3,
  106457. 0, 0, 0, 0, 0,
  106458. NULL,
  106459. NULL,
  106460. NULL,
  106461. NULL,
  106462. 0
  106463. };
  106464. static long _huff_lengthlist_line_256x7_1sub1[] = {
  106465. 0, 3, 3, 3, 3, 2, 4, 3, 4,
  106466. };
  106467. static static_codebook _huff_book_line_256x7_1sub1 = {
  106468. 1, 9,
  106469. _huff_lengthlist_line_256x7_1sub1,
  106470. 0, 0, 0, 0, 0,
  106471. NULL,
  106472. NULL,
  106473. NULL,
  106474. NULL,
  106475. 0
  106476. };
  106477. static long _huff_lengthlist_line_256x7_1sub2[] = {
  106478. 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 3, 3, 4, 3, 4, 4,
  106479. 5, 4, 6, 5, 6, 7, 6, 8, 8,
  106480. };
  106481. static static_codebook _huff_book_line_256x7_1sub2 = {
  106482. 1, 25,
  106483. _huff_lengthlist_line_256x7_1sub2,
  106484. 0, 0, 0, 0, 0,
  106485. NULL,
  106486. NULL,
  106487. NULL,
  106488. NULL,
  106489. 0
  106490. };
  106491. static long _huff_lengthlist_line_256x7_1sub3[] = {
  106492. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  106493. 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 2, 4, 3, 6, 3, 7,
  106494. 3, 8, 5, 8, 6, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  106495. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 7,
  106496. };
  106497. static static_codebook _huff_book_line_256x7_1sub3 = {
  106498. 1, 64,
  106499. _huff_lengthlist_line_256x7_1sub3,
  106500. 0, 0, 0, 0, 0,
  106501. NULL,
  106502. NULL,
  106503. NULL,
  106504. NULL,
  106505. 0
  106506. };
  106507. static long _huff_lengthlist_line_256x7_class0[] = {
  106508. 7, 5, 5, 9, 9, 6, 6, 9,12, 8, 7, 8,11, 8, 9,15,
  106509. 6, 3, 3, 7, 7, 4, 3, 6, 9, 6, 5, 6, 8, 6, 8,15,
  106510. 8, 5, 5, 9, 8, 5, 4, 6,10, 7, 5, 5,11, 8, 7,15,
  106511. 14,15,13,13,13,13, 8,11,15,10, 7, 6,11, 9,10,15,
  106512. };
  106513. static static_codebook _huff_book_line_256x7_class0 = {
  106514. 1, 64,
  106515. _huff_lengthlist_line_256x7_class0,
  106516. 0, 0, 0, 0, 0,
  106517. NULL,
  106518. NULL,
  106519. NULL,
  106520. NULL,
  106521. 0
  106522. };
  106523. static long _huff_lengthlist_line_256x7_class1[] = {
  106524. 5, 6, 8,15, 6, 9,10,15,10,11,12,15,15,15,15,15,
  106525. 4, 6, 7,15, 6, 7, 8,15, 9, 8, 9,15,15,15,15,15,
  106526. 6, 8, 9,15, 7, 7, 8,15,10, 9,10,15,15,15,15,15,
  106527. 15,13,15,15,15,10,11,15,15,13,13,15,15,15,15,15,
  106528. 4, 6, 7,15, 6, 8, 9,15,10,10,12,15,15,15,15,15,
  106529. 2, 5, 6,15, 5, 6, 7,15, 8, 6, 7,15,15,15,15,15,
  106530. 5, 6, 8,15, 5, 6, 7,15, 9, 6, 7,15,15,15,15,15,
  106531. 14,12,13,15,12,10,11,15,15,15,15,15,15,15,15,15,
  106532. 7, 8, 9,15, 9,10,10,15,15,14,14,15,15,15,15,15,
  106533. 5, 6, 7,15, 7, 8, 9,15,12, 9,10,15,15,15,15,15,
  106534. 7, 7, 9,15, 7, 7, 8,15,12, 8, 9,15,15,15,15,15,
  106535. 13,13,14,15,12,11,12,15,15,15,15,15,15,15,15,15,
  106536. 15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,
  106537. 13,13,13,15,15,15,15,15,15,15,15,15,15,15,15,15,
  106538. 15,12,13,15,15,12,13,15,15,14,15,15,15,15,15,15,
  106539. 15,15,15,15,15,15,13,15,15,15,15,15,15,15,15,15,
  106540. };
  106541. static static_codebook _huff_book_line_256x7_class1 = {
  106542. 1, 256,
  106543. _huff_lengthlist_line_256x7_class1,
  106544. 0, 0, 0, 0, 0,
  106545. NULL,
  106546. NULL,
  106547. NULL,
  106548. NULL,
  106549. 0
  106550. };
  106551. static long _huff_lengthlist_line_512x17_0sub0[] = {
  106552. 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
  106553. 5, 6, 5, 6, 6, 6, 6, 5, 6, 6, 7, 6, 7, 6, 7, 6,
  106554. 7, 6, 8, 7, 8, 7, 8, 7, 8, 7, 8, 7, 9, 7, 9, 7,
  106555. 9, 7, 9, 8, 9, 8,10, 8,10, 8,10, 7,10, 6,10, 8,
  106556. 10, 8,11, 7,10, 7,11, 8,11,11,12,12,11,11,12,11,
  106557. 13,11,13,11,13,12,15,12,13,13,14,14,14,14,14,15,
  106558. 15,15,16,14,17,19,19,18,18,18,18,18,18,18,18,18,
  106559. 18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,
  106560. };
  106561. static static_codebook _huff_book_line_512x17_0sub0 = {
  106562. 1, 128,
  106563. _huff_lengthlist_line_512x17_0sub0,
  106564. 0, 0, 0, 0, 0,
  106565. NULL,
  106566. NULL,
  106567. NULL,
  106568. NULL,
  106569. 0
  106570. };
  106571. static long _huff_lengthlist_line_512x17_1sub0[] = {
  106572. 2, 4, 5, 4, 5, 4, 5, 4, 5, 5, 5, 5, 5, 5, 6, 5,
  106573. 6, 5, 6, 6, 7, 6, 7, 6, 8, 7, 8, 7, 8, 7, 8, 7,
  106574. };
  106575. static static_codebook _huff_book_line_512x17_1sub0 = {
  106576. 1, 32,
  106577. _huff_lengthlist_line_512x17_1sub0,
  106578. 0, 0, 0, 0, 0,
  106579. NULL,
  106580. NULL,
  106581. NULL,
  106582. NULL,
  106583. 0
  106584. };
  106585. static long _huff_lengthlist_line_512x17_1sub1[] = {
  106586. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  106587. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  106588. 4, 3, 5, 3, 5, 4, 5, 4, 5, 4, 5, 5, 5, 5, 6, 5,
  106589. 6, 5, 7, 5, 8, 6, 8, 6, 8, 6, 8, 6, 8, 7, 9, 7,
  106590. 9, 7,11, 9,11,11,12,11,14,12,14,16,14,16,13,16,
  106591. 14,16,12,15,13,16,14,16,13,14,12,15,13,15,13,13,
  106592. 13,15,12,14,14,15,13,15,12,15,15,15,15,15,15,15,
  106593. 15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,
  106594. };
  106595. static static_codebook _huff_book_line_512x17_1sub1 = {
  106596. 1, 128,
  106597. _huff_lengthlist_line_512x17_1sub1,
  106598. 0, 0, 0, 0, 0,
  106599. NULL,
  106600. NULL,
  106601. NULL,
  106602. NULL,
  106603. 0
  106604. };
  106605. static long _huff_lengthlist_line_512x17_2sub1[] = {
  106606. 0, 4, 5, 4, 4, 4, 5, 4, 4, 4, 5, 4, 5, 4, 5, 3,
  106607. 5, 3,
  106608. };
  106609. static static_codebook _huff_book_line_512x17_2sub1 = {
  106610. 1, 18,
  106611. _huff_lengthlist_line_512x17_2sub1,
  106612. 0, 0, 0, 0, 0,
  106613. NULL,
  106614. NULL,
  106615. NULL,
  106616. NULL,
  106617. 0
  106618. };
  106619. static long _huff_lengthlist_line_512x17_2sub2[] = {
  106620. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  106621. 0, 0, 4, 3, 4, 3, 4, 4, 5, 4, 5, 4, 6, 4, 6, 5,
  106622. 6, 5, 7, 5, 7, 6, 8, 6, 8, 6, 8, 7, 8, 7, 9, 7,
  106623. 9, 8,
  106624. };
  106625. static static_codebook _huff_book_line_512x17_2sub2 = {
  106626. 1, 50,
  106627. _huff_lengthlist_line_512x17_2sub2,
  106628. 0, 0, 0, 0, 0,
  106629. NULL,
  106630. NULL,
  106631. NULL,
  106632. NULL,
  106633. 0
  106634. };
  106635. static long _huff_lengthlist_line_512x17_2sub3[] = {
  106636. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  106637. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  106638. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  106639. 0, 0, 3, 3, 3, 3, 4, 3, 4, 4, 5, 5, 6, 6, 7, 7,
  106640. 7, 8, 8,11, 8, 9, 9, 9,10,11,11,11, 9,10,10,11,
  106641. 11,11,11,10,10,10,10,10,10,10,10,10,10,10,10,10,
  106642. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  106643. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  106644. };
  106645. static static_codebook _huff_book_line_512x17_2sub3 = {
  106646. 1, 128,
  106647. _huff_lengthlist_line_512x17_2sub3,
  106648. 0, 0, 0, 0, 0,
  106649. NULL,
  106650. NULL,
  106651. NULL,
  106652. NULL,
  106653. 0
  106654. };
  106655. static long _huff_lengthlist_line_512x17_3sub1[] = {
  106656. 0, 4, 4, 4, 4, 4, 4, 3, 4, 4, 4, 4, 4, 5, 4, 5,
  106657. 5, 5,
  106658. };
  106659. static static_codebook _huff_book_line_512x17_3sub1 = {
  106660. 1, 18,
  106661. _huff_lengthlist_line_512x17_3sub1,
  106662. 0, 0, 0, 0, 0,
  106663. NULL,
  106664. NULL,
  106665. NULL,
  106666. NULL,
  106667. 0
  106668. };
  106669. static long _huff_lengthlist_line_512x17_3sub2[] = {
  106670. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  106671. 0, 0, 2, 3, 3, 4, 3, 5, 4, 6, 4, 6, 5, 7, 6, 7,
  106672. 6, 8, 6, 8, 7, 9, 8,10, 8,12, 9,13,10,15,10,15,
  106673. 11,14,
  106674. };
  106675. static static_codebook _huff_book_line_512x17_3sub2 = {
  106676. 1, 50,
  106677. _huff_lengthlist_line_512x17_3sub2,
  106678. 0, 0, 0, 0, 0,
  106679. NULL,
  106680. NULL,
  106681. NULL,
  106682. NULL,
  106683. 0
  106684. };
  106685. static long _huff_lengthlist_line_512x17_3sub3[] = {
  106686. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  106687. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  106688. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  106689. 0, 0, 4, 8, 4, 8, 4, 8, 4, 8, 5, 8, 5, 8, 6, 8,
  106690. 4, 8, 4, 8, 5, 8, 5, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  106691. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  106692. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  106693. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  106694. };
  106695. static static_codebook _huff_book_line_512x17_3sub3 = {
  106696. 1, 128,
  106697. _huff_lengthlist_line_512x17_3sub3,
  106698. 0, 0, 0, 0, 0,
  106699. NULL,
  106700. NULL,
  106701. NULL,
  106702. NULL,
  106703. 0
  106704. };
  106705. static long _huff_lengthlist_line_512x17_class1[] = {
  106706. 1, 2, 3, 6, 5, 4, 7, 7,
  106707. };
  106708. static static_codebook _huff_book_line_512x17_class1 = {
  106709. 1, 8,
  106710. _huff_lengthlist_line_512x17_class1,
  106711. 0, 0, 0, 0, 0,
  106712. NULL,
  106713. NULL,
  106714. NULL,
  106715. NULL,
  106716. 0
  106717. };
  106718. static long _huff_lengthlist_line_512x17_class2[] = {
  106719. 3, 3, 3,14, 5, 4, 4,11, 8, 6, 6,10,17,12,11,17,
  106720. 6, 5, 5,15, 5, 3, 4,11, 8, 5, 5, 8,16, 9,10,14,
  106721. 10, 8, 9,17, 8, 6, 6,13,10, 7, 7,10,16,11,13,14,
  106722. 17,17,17,17,17,16,16,16,16,15,16,16,16,16,16,16,
  106723. };
  106724. static static_codebook _huff_book_line_512x17_class2 = {
  106725. 1, 64,
  106726. _huff_lengthlist_line_512x17_class2,
  106727. 0, 0, 0, 0, 0,
  106728. NULL,
  106729. NULL,
  106730. NULL,
  106731. NULL,
  106732. 0
  106733. };
  106734. static long _huff_lengthlist_line_512x17_class3[] = {
  106735. 2, 4, 6,17, 4, 5, 7,17, 8, 7,10,17,17,17,17,17,
  106736. 3, 4, 6,15, 3, 3, 6,15, 7, 6, 9,17,17,17,17,17,
  106737. 6, 8,10,17, 6, 6, 8,16, 9, 8,10,17,17,15,16,17,
  106738. 17,17,17,17,12,15,15,16,12,15,15,16,16,16,16,16,
  106739. };
  106740. static static_codebook _huff_book_line_512x17_class3 = {
  106741. 1, 64,
  106742. _huff_lengthlist_line_512x17_class3,
  106743. 0, 0, 0, 0, 0,
  106744. NULL,
  106745. NULL,
  106746. NULL,
  106747. NULL,
  106748. 0
  106749. };
  106750. static long _huff_lengthlist_line_128x4_class0[] = {
  106751. 7, 7, 7,11, 6, 6, 7,11, 7, 6, 6,10,12,10,10,13,
  106752. 7, 7, 8,11, 7, 7, 7,11, 7, 6, 7,10,11,10,10,13,
  106753. 10,10, 9,12, 9, 9, 9,11, 8, 8, 8,11,13,11,10,14,
  106754. 15,15,14,15,15,14,13,14,15,12,12,17,17,17,17,17,
  106755. 7, 7, 6, 9, 6, 6, 6, 9, 7, 6, 6, 8,11,11,10,12,
  106756. 7, 7, 7, 9, 7, 6, 6, 9, 7, 6, 6, 9,13,10,10,11,
  106757. 10, 9, 8,10, 9, 8, 8,10, 8, 8, 7, 9,13,12,10,11,
  106758. 17,14,14,13,15,14,12,13,17,13,12,15,17,17,14,17,
  106759. 7, 6, 6, 7, 6, 6, 5, 7, 6, 6, 6, 6,11, 9, 9, 9,
  106760. 7, 7, 6, 7, 7, 6, 6, 7, 6, 6, 6, 6,10, 9, 8, 9,
  106761. 10, 9, 8, 8, 9, 8, 7, 8, 8, 7, 6, 8,11,10, 9,10,
  106762. 17,17,12,15,15,15,12,14,14,14,10,12,15,13,12,13,
  106763. 11,10, 8,10,11,10, 8, 8,10, 9, 7, 7,10, 9, 9,11,
  106764. 11,11, 9,10,11,10, 8, 9,10, 8, 6, 8,10, 9, 9,11,
  106765. 14,13,10,12,12,11,10,10, 8, 7, 8,10,10,11,11,12,
  106766. 17,17,15,17,17,17,17,17,17,13,12,17,17,17,14,17,
  106767. };
  106768. static static_codebook _huff_book_line_128x4_class0 = {
  106769. 1, 256,
  106770. _huff_lengthlist_line_128x4_class0,
  106771. 0, 0, 0, 0, 0,
  106772. NULL,
  106773. NULL,
  106774. NULL,
  106775. NULL,
  106776. 0
  106777. };
  106778. static long _huff_lengthlist_line_128x4_0sub0[] = {
  106779. 2, 2, 2, 2,
  106780. };
  106781. static static_codebook _huff_book_line_128x4_0sub0 = {
  106782. 1, 4,
  106783. _huff_lengthlist_line_128x4_0sub0,
  106784. 0, 0, 0, 0, 0,
  106785. NULL,
  106786. NULL,
  106787. NULL,
  106788. NULL,
  106789. 0
  106790. };
  106791. static long _huff_lengthlist_line_128x4_0sub1[] = {
  106792. 0, 0, 0, 0, 3, 2, 3, 2, 3, 3,
  106793. };
  106794. static static_codebook _huff_book_line_128x4_0sub1 = {
  106795. 1, 10,
  106796. _huff_lengthlist_line_128x4_0sub1,
  106797. 0, 0, 0, 0, 0,
  106798. NULL,
  106799. NULL,
  106800. NULL,
  106801. NULL,
  106802. 0
  106803. };
  106804. static long _huff_lengthlist_line_128x4_0sub2[] = {
  106805. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 3, 4, 3, 4, 3,
  106806. 4, 4, 5, 4, 5, 4, 6, 5, 6,
  106807. };
  106808. static static_codebook _huff_book_line_128x4_0sub2 = {
  106809. 1, 25,
  106810. _huff_lengthlist_line_128x4_0sub2,
  106811. 0, 0, 0, 0, 0,
  106812. NULL,
  106813. NULL,
  106814. NULL,
  106815. NULL,
  106816. 0
  106817. };
  106818. static long _huff_lengthlist_line_128x4_0sub3[] = {
  106819. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  106820. 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 4, 3, 5, 3, 5, 3,
  106821. 5, 4, 6, 5, 6, 5, 7, 6, 6, 7, 7, 9, 9,11,11,16,
  106822. 11,14,10,11,11,13,16,15,15,15,15,15,15,15,15,15,
  106823. };
  106824. static static_codebook _huff_book_line_128x4_0sub3 = {
  106825. 1, 64,
  106826. _huff_lengthlist_line_128x4_0sub3,
  106827. 0, 0, 0, 0, 0,
  106828. NULL,
  106829. NULL,
  106830. NULL,
  106831. NULL,
  106832. 0
  106833. };
  106834. static long _huff_lengthlist_line_256x4_class0[] = {
  106835. 6, 7, 7,12, 6, 6, 7,12, 7, 6, 6,10,15,12,11,13,
  106836. 7, 7, 8,13, 7, 7, 8,12, 7, 7, 7,11,12,12,11,13,
  106837. 10, 9, 9,11, 9, 9, 9,10,10, 8, 8,12,14,12,12,14,
  106838. 11,11,12,14,11,12,11,15,15,12,13,15,15,15,15,15,
  106839. 6, 6, 7,10, 6, 6, 6,11, 7, 6, 6, 9,14,12,11,13,
  106840. 7, 7, 7,10, 6, 6, 7, 9, 7, 7, 6,10,13,12,10,12,
  106841. 9, 9, 9,11, 9, 9, 8, 9, 9, 8, 8,10,13,12,10,12,
  106842. 12,12,11,13,12,12,11,12,15,13,12,15,15,15,14,14,
  106843. 6, 6, 6, 8, 6, 6, 5, 6, 7, 7, 6, 5,11,10, 9, 8,
  106844. 7, 6, 6, 7, 6, 6, 5, 6, 7, 7, 6, 6,11,10, 9, 8,
  106845. 8, 8, 8, 9, 8, 8, 7, 8, 8, 8, 6, 7,11,10, 9, 9,
  106846. 14,11,10,14,14,11,10,15,13,11, 9,11,15,12,12,11,
  106847. 11, 9, 8, 8,10, 9, 8, 9,11,10, 9, 8,12,11,12,11,
  106848. 13,10, 8, 9,11,10, 8, 9,10, 9, 8, 9,10, 8,12,12,
  106849. 15,11,10,10,13,11,10,10, 8, 8, 7,12,10, 9,11,12,
  106850. 15,12,11,15,13,11,11,15,12,14,11,13,15,15,13,13,
  106851. };
  106852. static static_codebook _huff_book_line_256x4_class0 = {
  106853. 1, 256,
  106854. _huff_lengthlist_line_256x4_class0,
  106855. 0, 0, 0, 0, 0,
  106856. NULL,
  106857. NULL,
  106858. NULL,
  106859. NULL,
  106860. 0
  106861. };
  106862. static long _huff_lengthlist_line_256x4_0sub0[] = {
  106863. 2, 2, 2, 2,
  106864. };
  106865. static static_codebook _huff_book_line_256x4_0sub0 = {
  106866. 1, 4,
  106867. _huff_lengthlist_line_256x4_0sub0,
  106868. 0, 0, 0, 0, 0,
  106869. NULL,
  106870. NULL,
  106871. NULL,
  106872. NULL,
  106873. 0
  106874. };
  106875. static long _huff_lengthlist_line_256x4_0sub1[] = {
  106876. 0, 0, 0, 0, 2, 2, 3, 3, 3, 3,
  106877. };
  106878. static static_codebook _huff_book_line_256x4_0sub1 = {
  106879. 1, 10,
  106880. _huff_lengthlist_line_256x4_0sub1,
  106881. 0, 0, 0, 0, 0,
  106882. NULL,
  106883. NULL,
  106884. NULL,
  106885. NULL,
  106886. 0
  106887. };
  106888. static long _huff_lengthlist_line_256x4_0sub2[] = {
  106889. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 3, 4, 3, 4, 3,
  106890. 5, 3, 5, 4, 5, 4, 6, 4, 6,
  106891. };
  106892. static static_codebook _huff_book_line_256x4_0sub2 = {
  106893. 1, 25,
  106894. _huff_lengthlist_line_256x4_0sub2,
  106895. 0, 0, 0, 0, 0,
  106896. NULL,
  106897. NULL,
  106898. NULL,
  106899. NULL,
  106900. 0
  106901. };
  106902. static long _huff_lengthlist_line_256x4_0sub3[] = {
  106903. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  106904. 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 4, 3, 5, 3, 5, 3,
  106905. 6, 4, 7, 4, 7, 5, 7, 6, 7, 6, 7, 8,10,13,13,13,
  106906. 13,13,13,13,13,13,13,13,13,13,13,12,12,12,12,12,
  106907. };
  106908. static static_codebook _huff_book_line_256x4_0sub3 = {
  106909. 1, 64,
  106910. _huff_lengthlist_line_256x4_0sub3,
  106911. 0, 0, 0, 0, 0,
  106912. NULL,
  106913. NULL,
  106914. NULL,
  106915. NULL,
  106916. 0
  106917. };
  106918. static long _huff_lengthlist_line_128x7_class0[] = {
  106919. 10, 7, 8,13, 9, 6, 7,11,10, 8, 8,12,17,17,17,17,
  106920. 7, 5, 5, 9, 6, 4, 4, 8, 8, 5, 5, 8,16,14,13,16,
  106921. 7, 5, 5, 7, 6, 3, 3, 5, 8, 5, 4, 7,14,12,12,15,
  106922. 10, 7, 8, 9, 7, 5, 5, 6, 9, 6, 5, 5,15,12, 9,10,
  106923. };
  106924. static static_codebook _huff_book_line_128x7_class0 = {
  106925. 1, 64,
  106926. _huff_lengthlist_line_128x7_class0,
  106927. 0, 0, 0, 0, 0,
  106928. NULL,
  106929. NULL,
  106930. NULL,
  106931. NULL,
  106932. 0
  106933. };
  106934. static long _huff_lengthlist_line_128x7_class1[] = {
  106935. 8,13,17,17, 8,11,17,17,11,13,17,17,17,17,17,17,
  106936. 6,10,16,17, 6,10,15,17, 8,10,16,17,17,17,17,17,
  106937. 9,13,15,17, 8,11,17,17,10,12,17,17,17,17,17,17,
  106938. 17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,
  106939. 6,11,15,17, 7,10,15,17, 8,10,17,17,17,15,17,17,
  106940. 4, 8,13,17, 4, 7,13,17, 6, 8,15,17,16,15,17,17,
  106941. 6,11,15,17, 6, 9,13,17, 8,10,17,17,15,17,17,17,
  106942. 16,17,17,17,12,14,15,17,13,14,15,17,17,17,17,17,
  106943. 5,10,14,17, 5, 9,14,17, 7, 9,15,17,15,15,17,17,
  106944. 3, 7,12,17, 3, 6,11,17, 5, 7,13,17,12,12,17,17,
  106945. 5, 9,14,17, 3, 7,11,17, 5, 8,13,17,13,11,16,17,
  106946. 12,17,17,17, 9,14,15,17,10,11,14,17,16,14,17,17,
  106947. 8,12,17,17, 8,12,17,17,10,12,17,17,17,17,17,17,
  106948. 5,10,17,17, 5, 9,15,17, 7, 9,17,17,13,13,17,17,
  106949. 7,11,17,17, 6,10,15,17, 7, 9,15,17,12,11,17,17,
  106950. 12,15,17,17,11,14,17,17,11,10,15,17,17,16,17,17,
  106951. };
  106952. static static_codebook _huff_book_line_128x7_class1 = {
  106953. 1, 256,
  106954. _huff_lengthlist_line_128x7_class1,
  106955. 0, 0, 0, 0, 0,
  106956. NULL,
  106957. NULL,
  106958. NULL,
  106959. NULL,
  106960. 0
  106961. };
  106962. static long _huff_lengthlist_line_128x7_0sub1[] = {
  106963. 0, 3, 3, 3, 3, 3, 3, 3, 3,
  106964. };
  106965. static static_codebook _huff_book_line_128x7_0sub1 = {
  106966. 1, 9,
  106967. _huff_lengthlist_line_128x7_0sub1,
  106968. 0, 0, 0, 0, 0,
  106969. NULL,
  106970. NULL,
  106971. NULL,
  106972. NULL,
  106973. 0
  106974. };
  106975. static long _huff_lengthlist_line_128x7_0sub2[] = {
  106976. 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 3, 3, 4, 4, 4, 4,
  106977. 5, 4, 5, 4, 5, 4, 6, 4, 6,
  106978. };
  106979. static static_codebook _huff_book_line_128x7_0sub2 = {
  106980. 1, 25,
  106981. _huff_lengthlist_line_128x7_0sub2,
  106982. 0, 0, 0, 0, 0,
  106983. NULL,
  106984. NULL,
  106985. NULL,
  106986. NULL,
  106987. 0
  106988. };
  106989. static long _huff_lengthlist_line_128x7_0sub3[] = {
  106990. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  106991. 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 5, 3, 5, 3, 5, 4,
  106992. 5, 4, 5, 5, 5, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 5,
  106993. 7, 8, 9,11,13,13,13,13,13,13,13,13,13,13,13,13,
  106994. };
  106995. static static_codebook _huff_book_line_128x7_0sub3 = {
  106996. 1, 64,
  106997. _huff_lengthlist_line_128x7_0sub3,
  106998. 0, 0, 0, 0, 0,
  106999. NULL,
  107000. NULL,
  107001. NULL,
  107002. NULL,
  107003. 0
  107004. };
  107005. static long _huff_lengthlist_line_128x7_1sub1[] = {
  107006. 0, 3, 3, 2, 3, 3, 4, 3, 4,
  107007. };
  107008. static static_codebook _huff_book_line_128x7_1sub1 = {
  107009. 1, 9,
  107010. _huff_lengthlist_line_128x7_1sub1,
  107011. 0, 0, 0, 0, 0,
  107012. NULL,
  107013. NULL,
  107014. NULL,
  107015. NULL,
  107016. 0
  107017. };
  107018. static long _huff_lengthlist_line_128x7_1sub2[] = {
  107019. 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 4, 3, 6, 3, 6, 3,
  107020. 6, 3, 7, 3, 8, 4, 9, 4, 9,
  107021. };
  107022. static static_codebook _huff_book_line_128x7_1sub2 = {
  107023. 1, 25,
  107024. _huff_lengthlist_line_128x7_1sub2,
  107025. 0, 0, 0, 0, 0,
  107026. NULL,
  107027. NULL,
  107028. NULL,
  107029. NULL,
  107030. 0
  107031. };
  107032. static long _huff_lengthlist_line_128x7_1sub3[] = {
  107033. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107034. 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 7, 2, 7, 3, 8, 4,
  107035. 9, 5, 9, 8,10,11,11,12,14,14,14,14,14,14,14,14,
  107036. 14,14,14,14,14,14,14,14,14,14,14,14,13,13,13,13,
  107037. };
  107038. static static_codebook _huff_book_line_128x7_1sub3 = {
  107039. 1, 64,
  107040. _huff_lengthlist_line_128x7_1sub3,
  107041. 0, 0, 0, 0, 0,
  107042. NULL,
  107043. NULL,
  107044. NULL,
  107045. NULL,
  107046. 0
  107047. };
  107048. static long _huff_lengthlist_line_128x11_class1[] = {
  107049. 1, 6, 3, 7, 2, 4, 5, 7,
  107050. };
  107051. static static_codebook _huff_book_line_128x11_class1 = {
  107052. 1, 8,
  107053. _huff_lengthlist_line_128x11_class1,
  107054. 0, 0, 0, 0, 0,
  107055. NULL,
  107056. NULL,
  107057. NULL,
  107058. NULL,
  107059. 0
  107060. };
  107061. static long _huff_lengthlist_line_128x11_class2[] = {
  107062. 1, 6,12,16, 4,12,15,16, 9,15,16,16,16,16,16,16,
  107063. 2, 5,11,16, 5,11,13,16, 9,13,16,16,16,16,16,16,
  107064. 4, 8,12,16, 5, 9,12,16, 9,13,15,16,16,16,16,16,
  107065. 15,16,16,16,11,14,13,16,12,15,16,16,16,16,16,15,
  107066. };
  107067. static static_codebook _huff_book_line_128x11_class2 = {
  107068. 1, 64,
  107069. _huff_lengthlist_line_128x11_class2,
  107070. 0, 0, 0, 0, 0,
  107071. NULL,
  107072. NULL,
  107073. NULL,
  107074. NULL,
  107075. 0
  107076. };
  107077. static long _huff_lengthlist_line_128x11_class3[] = {
  107078. 7, 6, 9,17, 7, 6, 8,17,12, 9,11,16,16,16,16,16,
  107079. 5, 4, 7,16, 5, 3, 6,14, 9, 6, 8,15,16,16,16,16,
  107080. 5, 4, 6,13, 3, 2, 4,11, 7, 4, 6,13,16,11,10,14,
  107081. 12,12,12,16, 9, 7,10,15,12, 9,11,16,16,15,15,16,
  107082. };
  107083. static static_codebook _huff_book_line_128x11_class3 = {
  107084. 1, 64,
  107085. _huff_lengthlist_line_128x11_class3,
  107086. 0, 0, 0, 0, 0,
  107087. NULL,
  107088. NULL,
  107089. NULL,
  107090. NULL,
  107091. 0
  107092. };
  107093. static long _huff_lengthlist_line_128x11_0sub0[] = {
  107094. 5, 5, 5, 5, 5, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 5,
  107095. 6, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 6, 6, 6, 7, 6,
  107096. 7, 6, 7, 6, 7, 6, 7, 6, 7, 6, 8, 6, 8, 6, 8, 7,
  107097. 8, 7, 8, 7, 8, 7, 9, 7, 9, 8, 9, 8, 9, 8,10, 8,
  107098. 10, 9,10, 9,10, 9,11, 9,11, 9,10,10,11,10,11,10,
  107099. 11,11,11,11,11,11,12,13,14,14,14,15,15,16,16,16,
  107100. 17,15,16,15,16,16,17,17,16,17,17,17,17,17,17,17,
  107101. 17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,
  107102. };
  107103. static static_codebook _huff_book_line_128x11_0sub0 = {
  107104. 1, 128,
  107105. _huff_lengthlist_line_128x11_0sub0,
  107106. 0, 0, 0, 0, 0,
  107107. NULL,
  107108. NULL,
  107109. NULL,
  107110. NULL,
  107111. 0
  107112. };
  107113. static long _huff_lengthlist_line_128x11_1sub0[] = {
  107114. 2, 5, 5, 5, 5, 5, 5, 4, 5, 5, 5, 5, 5, 5, 5, 5,
  107115. 6, 5, 6, 5, 6, 5, 7, 6, 7, 6, 7, 6, 8, 6, 8, 6,
  107116. };
  107117. static static_codebook _huff_book_line_128x11_1sub0 = {
  107118. 1, 32,
  107119. _huff_lengthlist_line_128x11_1sub0,
  107120. 0, 0, 0, 0, 0,
  107121. NULL,
  107122. NULL,
  107123. NULL,
  107124. NULL,
  107125. 0
  107126. };
  107127. static long _huff_lengthlist_line_128x11_1sub1[] = {
  107128. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107129. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107130. 5, 3, 5, 3, 6, 4, 6, 4, 7, 4, 7, 4, 7, 4, 8, 4,
  107131. 8, 4, 9, 5, 9, 5, 9, 5, 9, 6,10, 6,10, 6,11, 7,
  107132. 10, 7,10, 8,11, 9,11, 9,11,10,11,11,12,11,11,12,
  107133. 15,15,12,14,11,14,12,14,11,14,13,14,12,14,11,14,
  107134. 11,14,12,14,11,14,11,14,13,13,14,14,14,14,14,14,
  107135. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  107136. };
  107137. static static_codebook _huff_book_line_128x11_1sub1 = {
  107138. 1, 128,
  107139. _huff_lengthlist_line_128x11_1sub1,
  107140. 0, 0, 0, 0, 0,
  107141. NULL,
  107142. NULL,
  107143. NULL,
  107144. NULL,
  107145. 0
  107146. };
  107147. static long _huff_lengthlist_line_128x11_2sub1[] = {
  107148. 0, 4, 5, 4, 5, 4, 5, 3, 5, 3, 5, 3, 5, 4, 4, 4,
  107149. 5, 5,
  107150. };
  107151. static static_codebook _huff_book_line_128x11_2sub1 = {
  107152. 1, 18,
  107153. _huff_lengthlist_line_128x11_2sub1,
  107154. 0, 0, 0, 0, 0,
  107155. NULL,
  107156. NULL,
  107157. NULL,
  107158. NULL,
  107159. 0
  107160. };
  107161. static long _huff_lengthlist_line_128x11_2sub2[] = {
  107162. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107163. 0, 0, 3, 3, 3, 4, 4, 4, 4, 5, 4, 5, 4, 6, 5, 7,
  107164. 5, 7, 6, 8, 6, 8, 6, 9, 7, 9, 7,10, 7, 9, 8,11,
  107165. 8,11,
  107166. };
  107167. static static_codebook _huff_book_line_128x11_2sub2 = {
  107168. 1, 50,
  107169. _huff_lengthlist_line_128x11_2sub2,
  107170. 0, 0, 0, 0, 0,
  107171. NULL,
  107172. NULL,
  107173. NULL,
  107174. NULL,
  107175. 0
  107176. };
  107177. static long _huff_lengthlist_line_128x11_2sub3[] = {
  107178. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107179. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107180. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107181. 0, 0, 4, 8, 3, 8, 4, 8, 4, 8, 6, 8, 5, 8, 4, 8,
  107182. 4, 8, 6, 8, 7, 8, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  107183. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  107184. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  107185. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  107186. };
  107187. static static_codebook _huff_book_line_128x11_2sub3 = {
  107188. 1, 128,
  107189. _huff_lengthlist_line_128x11_2sub3,
  107190. 0, 0, 0, 0, 0,
  107191. NULL,
  107192. NULL,
  107193. NULL,
  107194. NULL,
  107195. 0
  107196. };
  107197. static long _huff_lengthlist_line_128x11_3sub1[] = {
  107198. 0, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 5, 4,
  107199. 5, 4,
  107200. };
  107201. static static_codebook _huff_book_line_128x11_3sub1 = {
  107202. 1, 18,
  107203. _huff_lengthlist_line_128x11_3sub1,
  107204. 0, 0, 0, 0, 0,
  107205. NULL,
  107206. NULL,
  107207. NULL,
  107208. NULL,
  107209. 0
  107210. };
  107211. static long _huff_lengthlist_line_128x11_3sub2[] = {
  107212. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107213. 0, 0, 5, 3, 5, 4, 6, 4, 6, 4, 7, 4, 7, 4, 8, 4,
  107214. 8, 4, 9, 4, 9, 4,10, 4,10, 5,10, 5,11, 5,12, 6,
  107215. 12, 6,
  107216. };
  107217. static static_codebook _huff_book_line_128x11_3sub2 = {
  107218. 1, 50,
  107219. _huff_lengthlist_line_128x11_3sub2,
  107220. 0, 0, 0, 0, 0,
  107221. NULL,
  107222. NULL,
  107223. NULL,
  107224. NULL,
  107225. 0
  107226. };
  107227. static long _huff_lengthlist_line_128x11_3sub3[] = {
  107228. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107229. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107230. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107231. 0, 0, 7, 1, 6, 3, 7, 3, 8, 4, 8, 5, 8, 8, 8, 9,
  107232. 7, 8, 8, 7, 7, 7, 8, 9,10, 9, 9,10,10,10,10,10,
  107233. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  107234. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  107235. 10,10,10,10,10,10,10,10,10,10,10,10,10,10, 9, 9,
  107236. };
  107237. static static_codebook _huff_book_line_128x11_3sub3 = {
  107238. 1, 128,
  107239. _huff_lengthlist_line_128x11_3sub3,
  107240. 0, 0, 0, 0, 0,
  107241. NULL,
  107242. NULL,
  107243. NULL,
  107244. NULL,
  107245. 0
  107246. };
  107247. static long _huff_lengthlist_line_128x17_class1[] = {
  107248. 1, 3, 4, 7, 2, 5, 6, 7,
  107249. };
  107250. static static_codebook _huff_book_line_128x17_class1 = {
  107251. 1, 8,
  107252. _huff_lengthlist_line_128x17_class1,
  107253. 0, 0, 0, 0, 0,
  107254. NULL,
  107255. NULL,
  107256. NULL,
  107257. NULL,
  107258. 0
  107259. };
  107260. static long _huff_lengthlist_line_128x17_class2[] = {
  107261. 1, 4,10,19, 3, 8,13,19, 7,12,19,19,19,19,19,19,
  107262. 2, 6,11,19, 8,13,19,19, 9,11,19,19,19,19,19,19,
  107263. 6, 7,13,19, 9,13,19,19,10,13,18,18,18,18,18,18,
  107264. 18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,
  107265. };
  107266. static static_codebook _huff_book_line_128x17_class2 = {
  107267. 1, 64,
  107268. _huff_lengthlist_line_128x17_class2,
  107269. 0, 0, 0, 0, 0,
  107270. NULL,
  107271. NULL,
  107272. NULL,
  107273. NULL,
  107274. 0
  107275. };
  107276. static long _huff_lengthlist_line_128x17_class3[] = {
  107277. 3, 6,10,17, 4, 8,11,20, 8,10,11,20,20,20,20,20,
  107278. 2, 4, 8,18, 4, 6, 8,17, 7, 8,10,20,20,17,20,20,
  107279. 3, 5, 8,17, 3, 4, 6,17, 8, 8,10,17,17,12,16,20,
  107280. 13,13,15,20,10,10,12,20,15,14,15,20,20,20,19,19,
  107281. };
  107282. static static_codebook _huff_book_line_128x17_class3 = {
  107283. 1, 64,
  107284. _huff_lengthlist_line_128x17_class3,
  107285. 0, 0, 0, 0, 0,
  107286. NULL,
  107287. NULL,
  107288. NULL,
  107289. NULL,
  107290. 0
  107291. };
  107292. static long _huff_lengthlist_line_128x17_0sub0[] = {
  107293. 5, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 5,
  107294. 7, 5, 7, 5, 7, 5, 7, 5, 7, 5, 7, 5, 8, 5, 8, 5,
  107295. 8, 5, 8, 5, 8, 6, 8, 6, 8, 6, 9, 6, 9, 6, 9, 6,
  107296. 9, 6, 9, 7, 9, 7, 9, 7, 9, 7,10, 7,10, 8,10, 8,
  107297. 10, 8,10, 8,10, 8,11, 8,11, 8,11, 8,11, 8,11, 9,
  107298. 12, 9,12, 9,12, 9,12, 9,12,10,12,10,13,11,13,11,
  107299. 14,12,14,13,15,14,16,14,17,15,18,16,20,20,20,20,
  107300. 20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,
  107301. };
  107302. static static_codebook _huff_book_line_128x17_0sub0 = {
  107303. 1, 128,
  107304. _huff_lengthlist_line_128x17_0sub0,
  107305. 0, 0, 0, 0, 0,
  107306. NULL,
  107307. NULL,
  107308. NULL,
  107309. NULL,
  107310. 0
  107311. };
  107312. static long _huff_lengthlist_line_128x17_1sub0[] = {
  107313. 2, 5, 5, 4, 5, 4, 5, 4, 5, 5, 5, 5, 5, 5, 6, 5,
  107314. 6, 5, 6, 5, 7, 6, 7, 6, 7, 6, 8, 6, 9, 7, 9, 7,
  107315. };
  107316. static static_codebook _huff_book_line_128x17_1sub0 = {
  107317. 1, 32,
  107318. _huff_lengthlist_line_128x17_1sub0,
  107319. 0, 0, 0, 0, 0,
  107320. NULL,
  107321. NULL,
  107322. NULL,
  107323. NULL,
  107324. 0
  107325. };
  107326. static long _huff_lengthlist_line_128x17_1sub1[] = {
  107327. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107328. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107329. 4, 3, 5, 3, 5, 3, 6, 3, 6, 4, 6, 4, 7, 4, 7, 5,
  107330. 8, 5, 8, 6, 9, 7, 9, 7, 9, 8,10, 9,10, 9,11,10,
  107331. 11,11,11,11,11,11,12,12,12,13,12,13,12,14,12,15,
  107332. 12,14,12,16,13,17,13,17,14,17,14,16,13,17,14,17,
  107333. 14,17,15,17,15,15,16,17,17,17,17,17,17,17,17,17,
  107334. 17,17,17,17,17,17,16,16,16,16,16,16,16,16,16,16,
  107335. };
  107336. static static_codebook _huff_book_line_128x17_1sub1 = {
  107337. 1, 128,
  107338. _huff_lengthlist_line_128x17_1sub1,
  107339. 0, 0, 0, 0, 0,
  107340. NULL,
  107341. NULL,
  107342. NULL,
  107343. NULL,
  107344. 0
  107345. };
  107346. static long _huff_lengthlist_line_128x17_2sub1[] = {
  107347. 0, 4, 5, 4, 6, 4, 8, 3, 9, 3, 9, 2, 9, 3, 8, 4,
  107348. 9, 4,
  107349. };
  107350. static static_codebook _huff_book_line_128x17_2sub1 = {
  107351. 1, 18,
  107352. _huff_lengthlist_line_128x17_2sub1,
  107353. 0, 0, 0, 0, 0,
  107354. NULL,
  107355. NULL,
  107356. NULL,
  107357. NULL,
  107358. 0
  107359. };
  107360. static long _huff_lengthlist_line_128x17_2sub2[] = {
  107361. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107362. 0, 0, 5, 1, 5, 3, 5, 3, 5, 4, 7, 5,10, 7,10, 7,
  107363. 12,10,14,10,14, 9,14,11,14,14,14,13,13,13,13,13,
  107364. 13,13,
  107365. };
  107366. static static_codebook _huff_book_line_128x17_2sub2 = {
  107367. 1, 50,
  107368. _huff_lengthlist_line_128x17_2sub2,
  107369. 0, 0, 0, 0, 0,
  107370. NULL,
  107371. NULL,
  107372. NULL,
  107373. NULL,
  107374. 0
  107375. };
  107376. static long _huff_lengthlist_line_128x17_2sub3[] = {
  107377. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107378. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107379. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107380. 0, 0, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  107381. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 6, 6,
  107382. 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
  107383. 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
  107384. 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
  107385. };
  107386. static static_codebook _huff_book_line_128x17_2sub3 = {
  107387. 1, 128,
  107388. _huff_lengthlist_line_128x17_2sub3,
  107389. 0, 0, 0, 0, 0,
  107390. NULL,
  107391. NULL,
  107392. NULL,
  107393. NULL,
  107394. 0
  107395. };
  107396. static long _huff_lengthlist_line_128x17_3sub1[] = {
  107397. 0, 4, 4, 4, 4, 4, 4, 4, 5, 3, 5, 3, 5, 4, 6, 4,
  107398. 6, 4,
  107399. };
  107400. static static_codebook _huff_book_line_128x17_3sub1 = {
  107401. 1, 18,
  107402. _huff_lengthlist_line_128x17_3sub1,
  107403. 0, 0, 0, 0, 0,
  107404. NULL,
  107405. NULL,
  107406. NULL,
  107407. NULL,
  107408. 0
  107409. };
  107410. static long _huff_lengthlist_line_128x17_3sub2[] = {
  107411. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107412. 0, 0, 5, 3, 6, 3, 6, 4, 7, 4, 7, 4, 7, 4, 8, 4,
  107413. 8, 4, 8, 4, 8, 4, 9, 4, 9, 5,10, 5,10, 7,10, 8,
  107414. 10, 8,
  107415. };
  107416. static static_codebook _huff_book_line_128x17_3sub2 = {
  107417. 1, 50,
  107418. _huff_lengthlist_line_128x17_3sub2,
  107419. 0, 0, 0, 0, 0,
  107420. NULL,
  107421. NULL,
  107422. NULL,
  107423. NULL,
  107424. 0
  107425. };
  107426. static long _huff_lengthlist_line_128x17_3sub3[] = {
  107427. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107428. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107429. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107430. 0, 0, 3, 2, 4, 3, 4, 4, 4, 5, 4, 7, 5, 8, 5,11,
  107431. 6,10, 6,12, 7,12, 7,12, 8,12, 8,12,10,12,12,12,
  107432. 12,12,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  107433. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  107434. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  107435. };
  107436. static static_codebook _huff_book_line_128x17_3sub3 = {
  107437. 1, 128,
  107438. _huff_lengthlist_line_128x17_3sub3,
  107439. 0, 0, 0, 0, 0,
  107440. NULL,
  107441. NULL,
  107442. NULL,
  107443. NULL,
  107444. 0
  107445. };
  107446. static long _huff_lengthlist_line_1024x27_class1[] = {
  107447. 2,10, 8,14, 7,12,11,14, 1, 5, 3, 7, 4, 9, 7,13,
  107448. };
  107449. static static_codebook _huff_book_line_1024x27_class1 = {
  107450. 1, 16,
  107451. _huff_lengthlist_line_1024x27_class1,
  107452. 0, 0, 0, 0, 0,
  107453. NULL,
  107454. NULL,
  107455. NULL,
  107456. NULL,
  107457. 0
  107458. };
  107459. static long _huff_lengthlist_line_1024x27_class2[] = {
  107460. 1, 4, 2, 6, 3, 7, 5, 7,
  107461. };
  107462. static static_codebook _huff_book_line_1024x27_class2 = {
  107463. 1, 8,
  107464. _huff_lengthlist_line_1024x27_class2,
  107465. 0, 0, 0, 0, 0,
  107466. NULL,
  107467. NULL,
  107468. NULL,
  107469. NULL,
  107470. 0
  107471. };
  107472. static long _huff_lengthlist_line_1024x27_class3[] = {
  107473. 1, 5, 7,21, 5, 8, 9,21,10, 9,12,20,20,16,20,20,
  107474. 4, 8, 9,20, 6, 8, 9,20,11,11,13,20,20,15,17,20,
  107475. 9,11,14,20, 8,10,15,20,11,13,15,20,20,20,20,20,
  107476. 20,20,20,20,13,20,20,20,18,18,20,20,20,20,20,20,
  107477. 3, 6, 8,20, 6, 7, 9,20,10, 9,12,20,20,20,20,20,
  107478. 5, 7, 9,20, 6, 6, 9,20,10, 9,12,20,20,20,20,20,
  107479. 8,10,13,20, 8, 9,12,20,11,10,12,20,20,20,20,20,
  107480. 18,20,20,20,15,17,18,20,18,17,18,20,20,20,20,20,
  107481. 7,10,12,20, 8, 9,11,20,14,13,14,20,20,20,20,20,
  107482. 6, 9,12,20, 7, 8,11,20,12,11,13,20,20,20,20,20,
  107483. 9,11,15,20, 8,10,14,20,12,11,14,20,20,20,20,20,
  107484. 20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,
  107485. 11,16,18,20,15,15,17,20,20,17,20,20,20,20,20,20,
  107486. 9,14,16,20,12,12,15,20,17,15,18,20,20,20,20,20,
  107487. 16,19,18,20,15,16,20,20,17,17,20,20,20,20,20,20,
  107488. 20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,
  107489. };
  107490. static static_codebook _huff_book_line_1024x27_class3 = {
  107491. 1, 256,
  107492. _huff_lengthlist_line_1024x27_class3,
  107493. 0, 0, 0, 0, 0,
  107494. NULL,
  107495. NULL,
  107496. NULL,
  107497. NULL,
  107498. 0
  107499. };
  107500. static long _huff_lengthlist_line_1024x27_class4[] = {
  107501. 2, 3, 7,13, 4, 4, 7,15, 8, 6, 9,17,21,16,15,21,
  107502. 2, 5, 7,11, 5, 5, 7,14, 9, 7,10,16,17,15,16,21,
  107503. 4, 7,10,17, 7, 7, 9,15,11, 9,11,16,21,18,15,21,
  107504. 18,21,21,21,15,17,17,19,21,19,18,20,21,21,21,20,
  107505. };
  107506. static static_codebook _huff_book_line_1024x27_class4 = {
  107507. 1, 64,
  107508. _huff_lengthlist_line_1024x27_class4,
  107509. 0, 0, 0, 0, 0,
  107510. NULL,
  107511. NULL,
  107512. NULL,
  107513. NULL,
  107514. 0
  107515. };
  107516. static long _huff_lengthlist_line_1024x27_0sub0[] = {
  107517. 5, 5, 5, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 5,
  107518. 6, 5, 6, 5, 6, 5, 6, 5, 7, 5, 7, 5, 7, 5, 7, 5,
  107519. 8, 6, 8, 6, 8, 6, 9, 6, 9, 6,10, 6,10, 6,11, 6,
  107520. 11, 7,11, 7,12, 7,12, 7,12, 7,12, 7,12, 7,12, 7,
  107521. 12, 7,12, 8,13, 8,12, 8,12, 8,13, 8,13, 9,13, 9,
  107522. 13, 9,13, 9,12,10,12,10,13,10,14,11,14,12,14,13,
  107523. 14,13,14,14,15,16,15,15,15,14,15,17,21,22,22,21,
  107524. 22,22,22,22,22,22,21,21,21,21,21,21,21,21,21,21,
  107525. };
  107526. static static_codebook _huff_book_line_1024x27_0sub0 = {
  107527. 1, 128,
  107528. _huff_lengthlist_line_1024x27_0sub0,
  107529. 0, 0, 0, 0, 0,
  107530. NULL,
  107531. NULL,
  107532. NULL,
  107533. NULL,
  107534. 0
  107535. };
  107536. static long _huff_lengthlist_line_1024x27_1sub0[] = {
  107537. 2, 5, 5, 4, 5, 4, 5, 4, 5, 4, 6, 5, 6, 5, 6, 5,
  107538. 6, 5, 7, 5, 7, 6, 8, 6, 8, 6, 8, 6, 9, 6, 9, 6,
  107539. };
  107540. static static_codebook _huff_book_line_1024x27_1sub0 = {
  107541. 1, 32,
  107542. _huff_lengthlist_line_1024x27_1sub0,
  107543. 0, 0, 0, 0, 0,
  107544. NULL,
  107545. NULL,
  107546. NULL,
  107547. NULL,
  107548. 0
  107549. };
  107550. static long _huff_lengthlist_line_1024x27_1sub1[] = {
  107551. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107552. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107553. 8, 5, 8, 4, 9, 4, 9, 4, 9, 4, 9, 4, 9, 4, 9, 4,
  107554. 9, 4, 9, 4, 9, 4, 8, 4, 8, 4, 9, 5, 9, 5, 9, 5,
  107555. 9, 5, 9, 6,10, 6,10, 7,10, 8,11, 9,11,11,12,13,
  107556. 12,14,13,15,13,15,14,16,14,17,15,17,15,15,16,16,
  107557. 15,16,16,16,15,18,16,15,17,17,19,19,19,19,19,19,
  107558. 19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,
  107559. };
  107560. static static_codebook _huff_book_line_1024x27_1sub1 = {
  107561. 1, 128,
  107562. _huff_lengthlist_line_1024x27_1sub1,
  107563. 0, 0, 0, 0, 0,
  107564. NULL,
  107565. NULL,
  107566. NULL,
  107567. NULL,
  107568. 0
  107569. };
  107570. static long _huff_lengthlist_line_1024x27_2sub0[] = {
  107571. 1, 5, 5, 5, 5, 5, 5, 5, 6, 5, 6, 5, 6, 5, 6, 5,
  107572. 6, 6, 7, 7, 7, 7, 8, 7, 8, 8, 9, 8,10, 9,10, 9,
  107573. };
  107574. static static_codebook _huff_book_line_1024x27_2sub0 = {
  107575. 1, 32,
  107576. _huff_lengthlist_line_1024x27_2sub0,
  107577. 0, 0, 0, 0, 0,
  107578. NULL,
  107579. NULL,
  107580. NULL,
  107581. NULL,
  107582. 0
  107583. };
  107584. static long _huff_lengthlist_line_1024x27_2sub1[] = {
  107585. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107586. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107587. 4, 3, 4, 3, 4, 4, 5, 4, 5, 4, 5, 5, 6, 5, 6, 5,
  107588. 7, 5, 7, 6, 7, 6, 8, 7, 8, 7, 8, 7, 9, 8, 9, 9,
  107589. 9, 9,10,10,10,11, 9,12, 9,12, 9,15,10,14, 9,13,
  107590. 10,13,10,12,10,12,10,13,10,12,11,13,11,14,12,13,
  107591. 13,14,14,13,14,15,14,16,13,13,14,16,16,16,16,16,
  107592. 16,16,16,16,16,16,16,16,16,16,16,16,16,16,15,15,
  107593. };
  107594. static static_codebook _huff_book_line_1024x27_2sub1 = {
  107595. 1, 128,
  107596. _huff_lengthlist_line_1024x27_2sub1,
  107597. 0, 0, 0, 0, 0,
  107598. NULL,
  107599. NULL,
  107600. NULL,
  107601. NULL,
  107602. 0
  107603. };
  107604. static long _huff_lengthlist_line_1024x27_3sub1[] = {
  107605. 0, 4, 5, 4, 5, 3, 5, 3, 5, 3, 5, 4, 4, 4, 4, 5,
  107606. 5, 5,
  107607. };
  107608. static static_codebook _huff_book_line_1024x27_3sub1 = {
  107609. 1, 18,
  107610. _huff_lengthlist_line_1024x27_3sub1,
  107611. 0, 0, 0, 0, 0,
  107612. NULL,
  107613. NULL,
  107614. NULL,
  107615. NULL,
  107616. 0
  107617. };
  107618. static long _huff_lengthlist_line_1024x27_3sub2[] = {
  107619. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107620. 0, 0, 3, 3, 4, 3, 4, 4, 4, 4, 5, 5, 5, 5, 5, 6,
  107621. 5, 7, 5, 8, 6, 8, 6, 9, 7,10, 7,10, 8,10, 8,11,
  107622. 9,11,
  107623. };
  107624. static static_codebook _huff_book_line_1024x27_3sub2 = {
  107625. 1, 50,
  107626. _huff_lengthlist_line_1024x27_3sub2,
  107627. 0, 0, 0, 0, 0,
  107628. NULL,
  107629. NULL,
  107630. NULL,
  107631. NULL,
  107632. 0
  107633. };
  107634. static long _huff_lengthlist_line_1024x27_3sub3[] = {
  107635. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107636. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107637. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107638. 0, 0, 3, 7, 3, 8, 3,10, 3, 8, 3, 9, 3, 8, 4, 9,
  107639. 4, 9, 5, 9, 6,10, 6, 9, 7,11, 7,12, 9,13,10,13,
  107640. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  107641. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  107642. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  107643. };
  107644. static static_codebook _huff_book_line_1024x27_3sub3 = {
  107645. 1, 128,
  107646. _huff_lengthlist_line_1024x27_3sub3,
  107647. 0, 0, 0, 0, 0,
  107648. NULL,
  107649. NULL,
  107650. NULL,
  107651. NULL,
  107652. 0
  107653. };
  107654. static long _huff_lengthlist_line_1024x27_4sub1[] = {
  107655. 0, 4, 5, 4, 5, 4, 5, 4, 5, 3, 5, 3, 5, 3, 5, 4,
  107656. 5, 4,
  107657. };
  107658. static static_codebook _huff_book_line_1024x27_4sub1 = {
  107659. 1, 18,
  107660. _huff_lengthlist_line_1024x27_4sub1,
  107661. 0, 0, 0, 0, 0,
  107662. NULL,
  107663. NULL,
  107664. NULL,
  107665. NULL,
  107666. 0
  107667. };
  107668. static long _huff_lengthlist_line_1024x27_4sub2[] = {
  107669. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107670. 0, 0, 4, 2, 4, 2, 5, 3, 5, 4, 6, 6, 6, 7, 7, 8,
  107671. 7, 8, 7, 8, 7, 9, 8, 9, 8, 9, 8,10, 8,11, 9,12,
  107672. 9,12,
  107673. };
  107674. static static_codebook _huff_book_line_1024x27_4sub2 = {
  107675. 1, 50,
  107676. _huff_lengthlist_line_1024x27_4sub2,
  107677. 0, 0, 0, 0, 0,
  107678. NULL,
  107679. NULL,
  107680. NULL,
  107681. NULL,
  107682. 0
  107683. };
  107684. static long _huff_lengthlist_line_1024x27_4sub3[] = {
  107685. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107686. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107687. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107688. 0, 0, 2, 5, 2, 6, 3, 6, 4, 7, 4, 7, 5, 9, 5,11,
  107689. 6,11, 6,11, 7,11, 6,11, 6,11, 9,11, 8,11,11,11,
  107690. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  107691. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  107692. 11,11,11,11,11,11,11,11,11,11,10,10,10,10,10,10,
  107693. };
  107694. static static_codebook _huff_book_line_1024x27_4sub3 = {
  107695. 1, 128,
  107696. _huff_lengthlist_line_1024x27_4sub3,
  107697. 0, 0, 0, 0, 0,
  107698. NULL,
  107699. NULL,
  107700. NULL,
  107701. NULL,
  107702. 0
  107703. };
  107704. static long _huff_lengthlist_line_2048x27_class1[] = {
  107705. 2, 6, 8, 9, 7,11,13,13, 1, 3, 5, 5, 6, 6,12,10,
  107706. };
  107707. static static_codebook _huff_book_line_2048x27_class1 = {
  107708. 1, 16,
  107709. _huff_lengthlist_line_2048x27_class1,
  107710. 0, 0, 0, 0, 0,
  107711. NULL,
  107712. NULL,
  107713. NULL,
  107714. NULL,
  107715. 0
  107716. };
  107717. static long _huff_lengthlist_line_2048x27_class2[] = {
  107718. 1, 2, 3, 6, 4, 7, 5, 7,
  107719. };
  107720. static static_codebook _huff_book_line_2048x27_class2 = {
  107721. 1, 8,
  107722. _huff_lengthlist_line_2048x27_class2,
  107723. 0, 0, 0, 0, 0,
  107724. NULL,
  107725. NULL,
  107726. NULL,
  107727. NULL,
  107728. 0
  107729. };
  107730. static long _huff_lengthlist_line_2048x27_class3[] = {
  107731. 3, 3, 6,16, 5, 5, 7,16, 9, 8,11,16,16,16,16,16,
  107732. 5, 5, 8,16, 5, 5, 7,16, 8, 7, 9,16,16,16,16,16,
  107733. 9, 9,12,16, 6, 8,11,16, 9,10,11,16,16,16,16,16,
  107734. 16,16,16,16,13,16,16,16,15,16,16,16,16,16,16,16,
  107735. 5, 4, 7,16, 6, 5, 8,16, 9, 8,10,16,16,16,16,16,
  107736. 5, 5, 7,15, 5, 4, 6,15, 7, 6, 8,16,16,16,16,16,
  107737. 9, 9,11,15, 7, 7, 9,16, 8, 8, 9,16,16,16,16,16,
  107738. 16,16,16,16,15,15,15,16,15,15,14,16,16,16,16,16,
  107739. 8, 8,11,16, 8, 9,10,16,11,10,14,16,16,16,16,16,
  107740. 6, 8,10,16, 6, 7,10,16, 8, 8,11,16,14,16,16,16,
  107741. 10,11,14,16, 9, 9,11,16,10,10,11,16,16,16,16,16,
  107742. 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,
  107743. 16,16,16,16,15,16,16,16,16,16,16,16,16,16,16,16,
  107744. 12,16,15,16,12,14,16,16,16,16,16,16,16,16,16,16,
  107745. 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,
  107746. 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,
  107747. };
  107748. static static_codebook _huff_book_line_2048x27_class3 = {
  107749. 1, 256,
  107750. _huff_lengthlist_line_2048x27_class3,
  107751. 0, 0, 0, 0, 0,
  107752. NULL,
  107753. NULL,
  107754. NULL,
  107755. NULL,
  107756. 0
  107757. };
  107758. static long _huff_lengthlist_line_2048x27_class4[] = {
  107759. 2, 4, 7,13, 4, 5, 7,15, 8, 7,10,16,16,14,16,16,
  107760. 2, 4, 7,16, 3, 4, 7,14, 8, 8,10,16,16,16,15,16,
  107761. 6, 8,11,16, 7, 7, 9,16,11, 9,13,16,16,16,15,16,
  107762. 16,16,16,16,14,16,16,16,16,16,16,16,16,16,16,16,
  107763. };
  107764. static static_codebook _huff_book_line_2048x27_class4 = {
  107765. 1, 64,
  107766. _huff_lengthlist_line_2048x27_class4,
  107767. 0, 0, 0, 0, 0,
  107768. NULL,
  107769. NULL,
  107770. NULL,
  107771. NULL,
  107772. 0
  107773. };
  107774. static long _huff_lengthlist_line_2048x27_0sub0[] = {
  107775. 5, 5, 5, 5, 5, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 5,
  107776. 6, 5, 7, 5, 7, 5, 7, 5, 8, 5, 8, 5, 8, 5, 9, 5,
  107777. 9, 6,10, 6,10, 6,11, 6,11, 6,11, 6,11, 6,11, 6,
  107778. 11, 6,11, 6,12, 7,11, 7,11, 7,11, 7,11, 7,10, 7,
  107779. 11, 7,11, 7,12, 7,11, 8,11, 8,11, 8,11, 8,13, 8,
  107780. 12, 9,11, 9,11, 9,11,10,12,10,12, 9,12,10,12,11,
  107781. 14,12,16,12,12,11,14,16,17,17,17,17,17,17,17,17,
  107782. 17,17,17,17,17,17,17,17,17,17,17,17,16,16,16,16,
  107783. };
  107784. static static_codebook _huff_book_line_2048x27_0sub0 = {
  107785. 1, 128,
  107786. _huff_lengthlist_line_2048x27_0sub0,
  107787. 0, 0, 0, 0, 0,
  107788. NULL,
  107789. NULL,
  107790. NULL,
  107791. NULL,
  107792. 0
  107793. };
  107794. static long _huff_lengthlist_line_2048x27_1sub0[] = {
  107795. 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5,
  107796. 5, 5, 6, 6, 6, 6, 6, 6, 7, 6, 7, 6, 7, 6, 7, 6,
  107797. };
  107798. static static_codebook _huff_book_line_2048x27_1sub0 = {
  107799. 1, 32,
  107800. _huff_lengthlist_line_2048x27_1sub0,
  107801. 0, 0, 0, 0, 0,
  107802. NULL,
  107803. NULL,
  107804. NULL,
  107805. NULL,
  107806. 0
  107807. };
  107808. static long _huff_lengthlist_line_2048x27_1sub1[] = {
  107809. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107810. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107811. 6, 5, 7, 5, 7, 4, 7, 4, 8, 4, 8, 4, 8, 4, 8, 3,
  107812. 8, 4, 9, 4, 9, 4, 9, 4, 9, 4, 9, 5, 9, 5, 9, 6,
  107813. 9, 7, 9, 8, 9, 9, 9,10, 9,11, 9,14, 9,15,10,15,
  107814. 10,15,10,15,10,15,11,15,10,14,12,14,11,14,13,14,
  107815. 13,15,15,15,12,15,15,15,13,15,13,15,13,15,15,15,
  107816. 15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,14,
  107817. };
  107818. static static_codebook _huff_book_line_2048x27_1sub1 = {
  107819. 1, 128,
  107820. _huff_lengthlist_line_2048x27_1sub1,
  107821. 0, 0, 0, 0, 0,
  107822. NULL,
  107823. NULL,
  107824. NULL,
  107825. NULL,
  107826. 0
  107827. };
  107828. static long _huff_lengthlist_line_2048x27_2sub0[] = {
  107829. 2, 4, 5, 4, 5, 4, 5, 4, 5, 5, 5, 5, 5, 5, 6, 5,
  107830. 6, 5, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8,
  107831. };
  107832. static static_codebook _huff_book_line_2048x27_2sub0 = {
  107833. 1, 32,
  107834. _huff_lengthlist_line_2048x27_2sub0,
  107835. 0, 0, 0, 0, 0,
  107836. NULL,
  107837. NULL,
  107838. NULL,
  107839. NULL,
  107840. 0
  107841. };
  107842. static long _huff_lengthlist_line_2048x27_2sub1[] = {
  107843. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107844. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107845. 3, 4, 3, 4, 3, 4, 4, 5, 4, 5, 5, 5, 6, 6, 6, 7,
  107846. 6, 8, 6, 8, 6, 9, 7,10, 7,10, 7,10, 7,12, 7,12,
  107847. 7,12, 9,12,11,12,10,12,10,12,11,12,12,12,10,12,
  107848. 10,12,10,12, 9,12,11,12,12,12,12,12,11,12,11,12,
  107849. 12,12,12,12,12,12,12,12,10,10,12,12,12,12,12,10,
  107850. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  107851. };
  107852. static static_codebook _huff_book_line_2048x27_2sub1 = {
  107853. 1, 128,
  107854. _huff_lengthlist_line_2048x27_2sub1,
  107855. 0, 0, 0, 0, 0,
  107856. NULL,
  107857. NULL,
  107858. NULL,
  107859. NULL,
  107860. 0
  107861. };
  107862. static long _huff_lengthlist_line_2048x27_3sub1[] = {
  107863. 0, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
  107864. 5, 5,
  107865. };
  107866. static static_codebook _huff_book_line_2048x27_3sub1 = {
  107867. 1, 18,
  107868. _huff_lengthlist_line_2048x27_3sub1,
  107869. 0, 0, 0, 0, 0,
  107870. NULL,
  107871. NULL,
  107872. NULL,
  107873. NULL,
  107874. 0
  107875. };
  107876. static long _huff_lengthlist_line_2048x27_3sub2[] = {
  107877. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107878. 0, 0, 3, 3, 3, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 6,
  107879. 6, 7, 6, 7, 6, 8, 6, 9, 7, 9, 7, 9, 9,11, 9,12,
  107880. 10,12,
  107881. };
  107882. static static_codebook _huff_book_line_2048x27_3sub2 = {
  107883. 1, 50,
  107884. _huff_lengthlist_line_2048x27_3sub2,
  107885. 0, 0, 0, 0, 0,
  107886. NULL,
  107887. NULL,
  107888. NULL,
  107889. NULL,
  107890. 0
  107891. };
  107892. static long _huff_lengthlist_line_2048x27_3sub3[] = {
  107893. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107894. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107895. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107896. 0, 0, 3, 6, 3, 7, 3, 7, 5, 7, 7, 7, 7, 7, 6, 7,
  107897. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  107898. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  107899. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  107900. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  107901. };
  107902. static static_codebook _huff_book_line_2048x27_3sub3 = {
  107903. 1, 128,
  107904. _huff_lengthlist_line_2048x27_3sub3,
  107905. 0, 0, 0, 0, 0,
  107906. NULL,
  107907. NULL,
  107908. NULL,
  107909. NULL,
  107910. 0
  107911. };
  107912. static long _huff_lengthlist_line_2048x27_4sub1[] = {
  107913. 0, 3, 4, 4, 4, 4, 4, 4, 4, 4, 5, 4, 5, 4, 5, 4,
  107914. 4, 5,
  107915. };
  107916. static static_codebook _huff_book_line_2048x27_4sub1 = {
  107917. 1, 18,
  107918. _huff_lengthlist_line_2048x27_4sub1,
  107919. 0, 0, 0, 0, 0,
  107920. NULL,
  107921. NULL,
  107922. NULL,
  107923. NULL,
  107924. 0
  107925. };
  107926. static long _huff_lengthlist_line_2048x27_4sub2[] = {
  107927. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107928. 0, 0, 3, 2, 4, 3, 4, 4, 4, 5, 5, 6, 5, 6, 5, 7,
  107929. 6, 6, 6, 7, 7, 7, 8, 9, 9, 9,12,10,11,10,10,12,
  107930. 10,10,
  107931. };
  107932. static static_codebook _huff_book_line_2048x27_4sub2 = {
  107933. 1, 50,
  107934. _huff_lengthlist_line_2048x27_4sub2,
  107935. 0, 0, 0, 0, 0,
  107936. NULL,
  107937. NULL,
  107938. NULL,
  107939. NULL,
  107940. 0
  107941. };
  107942. static long _huff_lengthlist_line_2048x27_4sub3[] = {
  107943. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107944. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107945. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107946. 0, 0, 3, 6, 5, 7, 5, 7, 7, 7, 7, 7, 5, 7, 5, 7,
  107947. 5, 7, 5, 7, 7, 7, 7, 7, 4, 7, 7, 7, 7, 7, 7, 7,
  107948. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  107949. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  107950. 7, 7, 7, 7, 7, 7, 7, 6, 6, 6, 6, 6, 6, 6, 6, 6,
  107951. };
  107952. static static_codebook _huff_book_line_2048x27_4sub3 = {
  107953. 1, 128,
  107954. _huff_lengthlist_line_2048x27_4sub3,
  107955. 0, 0, 0, 0, 0,
  107956. NULL,
  107957. NULL,
  107958. NULL,
  107959. NULL,
  107960. 0
  107961. };
  107962. static long _huff_lengthlist_line_256x4low_class0[] = {
  107963. 4, 5, 6,11, 5, 5, 6,10, 7, 7, 6, 6,14,13, 9, 9,
  107964. 6, 6, 6,10, 6, 6, 6, 9, 8, 7, 7, 9,14,12, 8,11,
  107965. 8, 7, 7,11, 8, 8, 7,11, 9, 9, 7, 9,13,11, 9,13,
  107966. 19,19,18,19,15,16,16,19,11,11,10,13,10,10, 9,15,
  107967. 5, 5, 6,13, 6, 6, 6,11, 8, 7, 6, 7,14,11,10,11,
  107968. 6, 6, 6,12, 7, 6, 6,11, 8, 7, 7,11,13,11, 9,11,
  107969. 9, 7, 6,12, 8, 7, 6,12, 9, 8, 8,11,13,10, 7,13,
  107970. 19,19,17,19,17,14,14,19,12,10, 8,12,13,10, 9,16,
  107971. 7, 8, 7,12, 7, 7, 7,11, 8, 7, 7, 8,12,12,11,11,
  107972. 8, 8, 7,12, 8, 7, 6,11, 8, 7, 7,10,10,11,10,11,
  107973. 9, 8, 8,13, 9, 8, 7,12,10, 9, 7,11, 9, 8, 7,11,
  107974. 18,18,15,18,18,16,17,18,15,11,10,18,11, 9, 9,18,
  107975. 16,16,13,16,12,11,10,16,12,11, 9, 6,15,12,11,13,
  107976. 16,16,14,14,13,11,12,16,12, 9, 9,13,13,10,10,12,
  107977. 17,18,17,17,14,15,14,16,14,12,14,15,12,10,11,12,
  107978. 18,18,18,18,18,18,18,18,18,12,13,18,16,11, 9,18,
  107979. };
  107980. static static_codebook _huff_book_line_256x4low_class0 = {
  107981. 1, 256,
  107982. _huff_lengthlist_line_256x4low_class0,
  107983. 0, 0, 0, 0, 0,
  107984. NULL,
  107985. NULL,
  107986. NULL,
  107987. NULL,
  107988. 0
  107989. };
  107990. static long _huff_lengthlist_line_256x4low_0sub0[] = {
  107991. 1, 3, 2, 3,
  107992. };
  107993. static static_codebook _huff_book_line_256x4low_0sub0 = {
  107994. 1, 4,
  107995. _huff_lengthlist_line_256x4low_0sub0,
  107996. 0, 0, 0, 0, 0,
  107997. NULL,
  107998. NULL,
  107999. NULL,
  108000. NULL,
  108001. 0
  108002. };
  108003. static long _huff_lengthlist_line_256x4low_0sub1[] = {
  108004. 0, 0, 0, 0, 2, 3, 2, 3, 3, 3,
  108005. };
  108006. static static_codebook _huff_book_line_256x4low_0sub1 = {
  108007. 1, 10,
  108008. _huff_lengthlist_line_256x4low_0sub1,
  108009. 0, 0, 0, 0, 0,
  108010. NULL,
  108011. NULL,
  108012. NULL,
  108013. NULL,
  108014. 0
  108015. };
  108016. static long _huff_lengthlist_line_256x4low_0sub2[] = {
  108017. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 3, 3, 4, 3, 4,
  108018. 4, 4, 4, 4, 5, 5, 5, 6, 6,
  108019. };
  108020. static static_codebook _huff_book_line_256x4low_0sub2 = {
  108021. 1, 25,
  108022. _huff_lengthlist_line_256x4low_0sub2,
  108023. 0, 0, 0, 0, 0,
  108024. NULL,
  108025. NULL,
  108026. NULL,
  108027. NULL,
  108028. 0
  108029. };
  108030. static long _huff_lengthlist_line_256x4low_0sub3[] = {
  108031. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108032. 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 4, 2, 4, 3, 5, 4,
  108033. 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 7, 7, 8, 6, 9,
  108034. 7,12,11,16,13,16,12,15,13,15,12,14,12,15,15,15,
  108035. };
  108036. static static_codebook _huff_book_line_256x4low_0sub3 = {
  108037. 1, 64,
  108038. _huff_lengthlist_line_256x4low_0sub3,
  108039. 0, 0, 0, 0, 0,
  108040. NULL,
  108041. NULL,
  108042. NULL,
  108043. NULL,
  108044. 0
  108045. };
  108046. /*** End of inlined file: floor_books.h ***/
  108047. static static_codebook *_floor_128x4_books[]={
  108048. &_huff_book_line_128x4_class0,
  108049. &_huff_book_line_128x4_0sub0,
  108050. &_huff_book_line_128x4_0sub1,
  108051. &_huff_book_line_128x4_0sub2,
  108052. &_huff_book_line_128x4_0sub3,
  108053. };
  108054. static static_codebook *_floor_256x4_books[]={
  108055. &_huff_book_line_256x4_class0,
  108056. &_huff_book_line_256x4_0sub0,
  108057. &_huff_book_line_256x4_0sub1,
  108058. &_huff_book_line_256x4_0sub2,
  108059. &_huff_book_line_256x4_0sub3,
  108060. };
  108061. static static_codebook *_floor_128x7_books[]={
  108062. &_huff_book_line_128x7_class0,
  108063. &_huff_book_line_128x7_class1,
  108064. &_huff_book_line_128x7_0sub1,
  108065. &_huff_book_line_128x7_0sub2,
  108066. &_huff_book_line_128x7_0sub3,
  108067. &_huff_book_line_128x7_1sub1,
  108068. &_huff_book_line_128x7_1sub2,
  108069. &_huff_book_line_128x7_1sub3,
  108070. };
  108071. static static_codebook *_floor_256x7_books[]={
  108072. &_huff_book_line_256x7_class0,
  108073. &_huff_book_line_256x7_class1,
  108074. &_huff_book_line_256x7_0sub1,
  108075. &_huff_book_line_256x7_0sub2,
  108076. &_huff_book_line_256x7_0sub3,
  108077. &_huff_book_line_256x7_1sub1,
  108078. &_huff_book_line_256x7_1sub2,
  108079. &_huff_book_line_256x7_1sub3,
  108080. };
  108081. static static_codebook *_floor_128x11_books[]={
  108082. &_huff_book_line_128x11_class1,
  108083. &_huff_book_line_128x11_class2,
  108084. &_huff_book_line_128x11_class3,
  108085. &_huff_book_line_128x11_0sub0,
  108086. &_huff_book_line_128x11_1sub0,
  108087. &_huff_book_line_128x11_1sub1,
  108088. &_huff_book_line_128x11_2sub1,
  108089. &_huff_book_line_128x11_2sub2,
  108090. &_huff_book_line_128x11_2sub3,
  108091. &_huff_book_line_128x11_3sub1,
  108092. &_huff_book_line_128x11_3sub2,
  108093. &_huff_book_line_128x11_3sub3,
  108094. };
  108095. static static_codebook *_floor_128x17_books[]={
  108096. &_huff_book_line_128x17_class1,
  108097. &_huff_book_line_128x17_class2,
  108098. &_huff_book_line_128x17_class3,
  108099. &_huff_book_line_128x17_0sub0,
  108100. &_huff_book_line_128x17_1sub0,
  108101. &_huff_book_line_128x17_1sub1,
  108102. &_huff_book_line_128x17_2sub1,
  108103. &_huff_book_line_128x17_2sub2,
  108104. &_huff_book_line_128x17_2sub3,
  108105. &_huff_book_line_128x17_3sub1,
  108106. &_huff_book_line_128x17_3sub2,
  108107. &_huff_book_line_128x17_3sub3,
  108108. };
  108109. static static_codebook *_floor_256x4low_books[]={
  108110. &_huff_book_line_256x4low_class0,
  108111. &_huff_book_line_256x4low_0sub0,
  108112. &_huff_book_line_256x4low_0sub1,
  108113. &_huff_book_line_256x4low_0sub2,
  108114. &_huff_book_line_256x4low_0sub3,
  108115. };
  108116. static static_codebook *_floor_1024x27_books[]={
  108117. &_huff_book_line_1024x27_class1,
  108118. &_huff_book_line_1024x27_class2,
  108119. &_huff_book_line_1024x27_class3,
  108120. &_huff_book_line_1024x27_class4,
  108121. &_huff_book_line_1024x27_0sub0,
  108122. &_huff_book_line_1024x27_1sub0,
  108123. &_huff_book_line_1024x27_1sub1,
  108124. &_huff_book_line_1024x27_2sub0,
  108125. &_huff_book_line_1024x27_2sub1,
  108126. &_huff_book_line_1024x27_3sub1,
  108127. &_huff_book_line_1024x27_3sub2,
  108128. &_huff_book_line_1024x27_3sub3,
  108129. &_huff_book_line_1024x27_4sub1,
  108130. &_huff_book_line_1024x27_4sub2,
  108131. &_huff_book_line_1024x27_4sub3,
  108132. };
  108133. static static_codebook *_floor_2048x27_books[]={
  108134. &_huff_book_line_2048x27_class1,
  108135. &_huff_book_line_2048x27_class2,
  108136. &_huff_book_line_2048x27_class3,
  108137. &_huff_book_line_2048x27_class4,
  108138. &_huff_book_line_2048x27_0sub0,
  108139. &_huff_book_line_2048x27_1sub0,
  108140. &_huff_book_line_2048x27_1sub1,
  108141. &_huff_book_line_2048x27_2sub0,
  108142. &_huff_book_line_2048x27_2sub1,
  108143. &_huff_book_line_2048x27_3sub1,
  108144. &_huff_book_line_2048x27_3sub2,
  108145. &_huff_book_line_2048x27_3sub3,
  108146. &_huff_book_line_2048x27_4sub1,
  108147. &_huff_book_line_2048x27_4sub2,
  108148. &_huff_book_line_2048x27_4sub3,
  108149. };
  108150. static static_codebook *_floor_512x17_books[]={
  108151. &_huff_book_line_512x17_class1,
  108152. &_huff_book_line_512x17_class2,
  108153. &_huff_book_line_512x17_class3,
  108154. &_huff_book_line_512x17_0sub0,
  108155. &_huff_book_line_512x17_1sub0,
  108156. &_huff_book_line_512x17_1sub1,
  108157. &_huff_book_line_512x17_2sub1,
  108158. &_huff_book_line_512x17_2sub2,
  108159. &_huff_book_line_512x17_2sub3,
  108160. &_huff_book_line_512x17_3sub1,
  108161. &_huff_book_line_512x17_3sub2,
  108162. &_huff_book_line_512x17_3sub3,
  108163. };
  108164. static static_codebook **_floor_books[10]={
  108165. _floor_128x4_books,
  108166. _floor_256x4_books,
  108167. _floor_128x7_books,
  108168. _floor_256x7_books,
  108169. _floor_128x11_books,
  108170. _floor_128x17_books,
  108171. _floor_256x4low_books,
  108172. _floor_1024x27_books,
  108173. _floor_2048x27_books,
  108174. _floor_512x17_books,
  108175. };
  108176. static vorbis_info_floor1 _floor[10]={
  108177. {
  108178. 1,{0},{4},{2},{0},
  108179. {{1,2,3,4}},
  108180. 4,{0,128, 33,8,16,70},
  108181. 60,30,500, 1.,18., -1
  108182. },
  108183. {
  108184. 1,{0},{4},{2},{0},
  108185. {{1,2,3,4}},
  108186. 4,{0,256, 66,16,32,140},
  108187. 60,30,500, 1.,18., -1
  108188. },
  108189. {
  108190. 2,{0,1},{3,4},{2,2},{0,1},
  108191. {{-1,2,3,4},{-1,5,6,7}},
  108192. 4,{0,128, 14,4,58, 2,8,28,90},
  108193. 60,30,500, 1.,18., -1
  108194. },
  108195. {
  108196. 2,{0,1},{3,4},{2,2},{0,1},
  108197. {{-1,2,3,4},{-1,5,6,7}},
  108198. 4,{0,256, 28,8,116, 4,16,56,180},
  108199. 60,30,500, 1.,18., -1
  108200. },
  108201. {
  108202. 4,{0,1,2,3},{2,3,3,3},{0,1,2,2},{-1,0,1,2},
  108203. {{3},{4,5},{-1,6,7,8},{-1,9,10,11}},
  108204. 2,{0,128, 8,33, 4,16,70, 2,6,12, 23,46,90},
  108205. 60,30,500, 1,18., -1
  108206. },
  108207. {
  108208. 6,{0,1,1,2,3,3},{2,3,3,3},{0,1,2,2},{-1,0,1,2},
  108209. {{3},{4,5},{-1,6,7,8},{-1,9,10,11}},
  108210. 2,{0,128, 12,46, 4,8,16, 23,33,70, 2,6,10, 14,19,28, 39,58,90},
  108211. 60,30,500, 1,18., -1
  108212. },
  108213. {
  108214. 1,{0},{4},{2},{0},
  108215. {{1,2,3,4}},
  108216. 4,{0,256, 66,16,32,140},
  108217. 60,30,500, 1.,18., -1
  108218. },
  108219. {
  108220. 8,{0,1,2,2,3,3,4,4},{3,4,3,4,3},{0,1,1,2,2},{-1,0,1,2,3},
  108221. {{4},{5,6},{7,8},{-1,9,10,11},{-1,12,13,14}},
  108222. 2,{0,1024, 93,23,372, 6,46,186,750, 14,33,65, 130,260,556,
  108223. 3,10,18,28, 39,55,79,111, 158,220,312, 464,650,850},
  108224. 60,30,500, 3,18., -1 /* lowpass */
  108225. },
  108226. {
  108227. 8,{0,1,2,2,3,3,4,4},{3,4,3,4,3},{0,1,1,2,2},{-1,0,1,2,3},
  108228. {{4},{5,6},{7,8},{-1,9,10,11},{-1,12,13,14}},
  108229. 2,{0,2048, 186,46,744, 12,92,372,1500, 28,66,130, 260,520,1112,
  108230. 6,20,36,56, 78,110,158,222, 316,440,624, 928,1300,1700},
  108231. 60,30,500, 3,18., -1 /* lowpass */
  108232. },
  108233. {
  108234. 6,{0,1,1,2,3,3},{2,3,3,3},{0,1,2,2},{-1,0,1,2},
  108235. {{3},{4,5},{-1,6,7,8},{-1,9,10,11}},
  108236. 2,{0,512, 46,186, 16,33,65, 93,130,278,
  108237. 7,23,39, 55,79,110, 156,232,360},
  108238. 60,30,500, 1,18., -1 /* lowpass! */
  108239. },
  108240. };
  108241. /*** End of inlined file: floor_all.h ***/
  108242. /*** Start of inlined file: residue_44.h ***/
  108243. /*** Start of inlined file: res_books_stereo.h ***/
  108244. static long _vq_quantlist__16c0_s_p1_0[] = {
  108245. 1,
  108246. 0,
  108247. 2,
  108248. };
  108249. static long _vq_lengthlist__16c0_s_p1_0[] = {
  108250. 1, 4, 4, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0,
  108251. 0, 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108252. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108253. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108254. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108255. 0, 5, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9,10, 0, 0, 0,
  108256. 0, 0, 0, 7, 9,10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  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. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108260. 0, 0, 5, 8, 8, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  108261. 0, 0, 0, 0, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108262. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108263. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108264. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108265. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108266. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108267. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108268. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108269. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108270. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108271. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108272. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108273. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108274. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108275. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108276. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108277. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108278. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108279. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108280. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108281. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108282. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108283. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108284. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108285. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108286. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108287. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108288. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108289. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108290. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108291. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108292. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108293. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108294. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108295. 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 8, 8, 0, 0, 0, 0,
  108296. 0, 0, 8,10,10, 0, 0, 0, 0, 0, 0, 8,10,10, 0, 0,
  108297. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108298. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108299. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108300. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7,10,10, 0, 0, 0,
  108301. 0, 0, 0, 9, 9,12, 0, 0, 0, 0, 0, 0,10,12,11, 0,
  108302. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108303. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108304. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108305. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7,10,10, 0, 0,
  108306. 0, 0, 0, 0, 9,12,10, 0, 0, 0, 0, 0, 0,10,11,12,
  108307. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108308. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108309. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108310. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108311. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108312. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108313. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108314. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108315. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108316. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108317. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108318. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108319. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108320. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108321. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108322. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108323. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108324. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108325. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108326. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108327. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108328. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108329. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108330. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108331. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108332. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108333. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108334. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108335. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108336. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108337. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108338. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108339. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108340. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108341. 0, 0, 5, 8, 8, 0, 0, 0, 0, 0, 0, 8,10,10, 0, 0,
  108342. 0, 0, 0, 0, 8,10,10, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108343. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108344. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108345. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108346. 0, 0, 0, 7,10,10, 0, 0, 0, 0, 0, 0,10,12,11, 0,
  108347. 0, 0, 0, 0, 0, 9,10,12, 0, 0, 0, 0, 0, 0, 0, 0,
  108348. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108349. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108350. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108351. 0, 0, 0, 0, 7,10,10, 0, 0, 0, 0, 0, 0,10,11,12,
  108352. 0, 0, 0, 0, 0, 0, 9,12, 9, 0, 0, 0, 0, 0, 0, 0,
  108353. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108354. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108355. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108356. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108357. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108358. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108359. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108360. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108361. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108362. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108363. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108364. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108365. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108366. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108367. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108368. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108369. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108370. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108371. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108372. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108373. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108374. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108375. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108376. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108377. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108378. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108379. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108380. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108381. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108382. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108383. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108384. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108385. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108386. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108387. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108388. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108389. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108390. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108391. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108392. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108393. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108394. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108395. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108396. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108397. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108398. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108399. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108400. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108401. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108402. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108403. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108404. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108405. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108406. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108407. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108408. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108409. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108410. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108411. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108412. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108413. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108414. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108415. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108416. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108417. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108418. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108419. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108420. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108421. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108422. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108423. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108424. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108425. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108426. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108427. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108428. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108429. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108430. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108431. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108432. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108433. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108434. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108435. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108436. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108437. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108438. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108439. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108440. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108441. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108442. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108443. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108444. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108445. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108446. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108447. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108448. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108449. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108450. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108451. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108452. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108453. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108454. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108455. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108456. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108457. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108458. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108459. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108460. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108461. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108462. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108463. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108464. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108465. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108466. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108467. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108468. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108469. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108470. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108471. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108472. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108473. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108474. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108475. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108476. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108477. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108478. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108479. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108480. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108481. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108482. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108483. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108484. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108485. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108486. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108487. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108488. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108489. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108490. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108491. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108492. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108493. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108494. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108495. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108496. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108497. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108498. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108499. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108500. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108501. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108502. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108503. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108504. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108505. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108506. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108507. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108508. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108509. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108510. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108511. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108512. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108513. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108514. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108515. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108516. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108517. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108518. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108519. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108520. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108521. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108522. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108523. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108524. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108525. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108526. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108527. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108528. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108529. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108530. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108531. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108532. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108533. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108534. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108535. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108536. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108537. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108538. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108539. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108540. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108541. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108542. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108543. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108544. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108545. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108546. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108547. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108548. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108549. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108550. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108551. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108552. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108553. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108554. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108555. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108556. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108557. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108558. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108559. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108560. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108561. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108562. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108563. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108564. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108565. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108566. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108567. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108568. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108569. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108570. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108571. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108572. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108573. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108574. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108575. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108576. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108577. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108578. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108579. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108580. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108581. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108582. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108583. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108584. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108585. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108586. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108587. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108588. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108589. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108590. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108591. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108592. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108593. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108594. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108595. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108596. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108597. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108598. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108599. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108600. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108601. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108602. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108603. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108604. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108605. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108606. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108607. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108608. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108609. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108610. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108611. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108612. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108613. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108614. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108615. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108616. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108617. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108618. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108619. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108620. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108621. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108622. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108623. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108624. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108625. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108626. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108627. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108628. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108629. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108630. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108631. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108632. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108633. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108634. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108635. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108636. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108637. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108638. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108639. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108640. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108641. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108642. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108643. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108644. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108645. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108646. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108647. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108648. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108649. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108650. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108651. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108652. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108653. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108654. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108655. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108656. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108657. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108658. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108659. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108660. 0,
  108661. };
  108662. static float _vq_quantthresh__16c0_s_p1_0[] = {
  108663. -0.5, 0.5,
  108664. };
  108665. static long _vq_quantmap__16c0_s_p1_0[] = {
  108666. 1, 0, 2,
  108667. };
  108668. static encode_aux_threshmatch _vq_auxt__16c0_s_p1_0 = {
  108669. _vq_quantthresh__16c0_s_p1_0,
  108670. _vq_quantmap__16c0_s_p1_0,
  108671. 3,
  108672. 3
  108673. };
  108674. static static_codebook _16c0_s_p1_0 = {
  108675. 8, 6561,
  108676. _vq_lengthlist__16c0_s_p1_0,
  108677. 1, -535822336, 1611661312, 2, 0,
  108678. _vq_quantlist__16c0_s_p1_0,
  108679. NULL,
  108680. &_vq_auxt__16c0_s_p1_0,
  108681. NULL,
  108682. 0
  108683. };
  108684. static long _vq_quantlist__16c0_s_p2_0[] = {
  108685. 2,
  108686. 1,
  108687. 3,
  108688. 0,
  108689. 4,
  108690. };
  108691. static long _vq_lengthlist__16c0_s_p2_0[] = {
  108692. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108693. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108694. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108695. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108696. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108697. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108698. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108699. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108700. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108701. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108702. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108703. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108704. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108705. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108706. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108707. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108708. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108709. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108710. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108711. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108712. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108713. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108714. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108715. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108716. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108717. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108718. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108719. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108720. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108721. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108722. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108723. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108724. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108725. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108726. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108727. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108728. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108729. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108730. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108731. 0,
  108732. };
  108733. static float _vq_quantthresh__16c0_s_p2_0[] = {
  108734. -1.5, -0.5, 0.5, 1.5,
  108735. };
  108736. static long _vq_quantmap__16c0_s_p2_0[] = {
  108737. 3, 1, 0, 2, 4,
  108738. };
  108739. static encode_aux_threshmatch _vq_auxt__16c0_s_p2_0 = {
  108740. _vq_quantthresh__16c0_s_p2_0,
  108741. _vq_quantmap__16c0_s_p2_0,
  108742. 5,
  108743. 5
  108744. };
  108745. static static_codebook _16c0_s_p2_0 = {
  108746. 4, 625,
  108747. _vq_lengthlist__16c0_s_p2_0,
  108748. 1, -533725184, 1611661312, 3, 0,
  108749. _vq_quantlist__16c0_s_p2_0,
  108750. NULL,
  108751. &_vq_auxt__16c0_s_p2_0,
  108752. NULL,
  108753. 0
  108754. };
  108755. static long _vq_quantlist__16c0_s_p3_0[] = {
  108756. 2,
  108757. 1,
  108758. 3,
  108759. 0,
  108760. 4,
  108761. };
  108762. static long _vq_lengthlist__16c0_s_p3_0[] = {
  108763. 1, 4, 4, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108764. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 6, 6, 7, 6, 0, 0,
  108765. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108766. 0, 0, 4, 6, 6, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108767. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 6, 6, 9, 9,
  108768. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108769. 0, 0, 0, 0, 6, 6, 6, 9, 9, 0, 0, 0, 0, 0, 0, 0,
  108770. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108771. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108772. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108773. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108774. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108775. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108776. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108777. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108778. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108779. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108780. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108781. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108782. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108783. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108784. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108785. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108786. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108787. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108788. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108789. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108790. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108791. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108792. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108793. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108794. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108795. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108796. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108797. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108798. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108799. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108800. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108801. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108802. 0,
  108803. };
  108804. static float _vq_quantthresh__16c0_s_p3_0[] = {
  108805. -1.5, -0.5, 0.5, 1.5,
  108806. };
  108807. static long _vq_quantmap__16c0_s_p3_0[] = {
  108808. 3, 1, 0, 2, 4,
  108809. };
  108810. static encode_aux_threshmatch _vq_auxt__16c0_s_p3_0 = {
  108811. _vq_quantthresh__16c0_s_p3_0,
  108812. _vq_quantmap__16c0_s_p3_0,
  108813. 5,
  108814. 5
  108815. };
  108816. static static_codebook _16c0_s_p3_0 = {
  108817. 4, 625,
  108818. _vq_lengthlist__16c0_s_p3_0,
  108819. 1, -533725184, 1611661312, 3, 0,
  108820. _vq_quantlist__16c0_s_p3_0,
  108821. NULL,
  108822. &_vq_auxt__16c0_s_p3_0,
  108823. NULL,
  108824. 0
  108825. };
  108826. static long _vq_quantlist__16c0_s_p4_0[] = {
  108827. 4,
  108828. 3,
  108829. 5,
  108830. 2,
  108831. 6,
  108832. 1,
  108833. 7,
  108834. 0,
  108835. 8,
  108836. };
  108837. static long _vq_lengthlist__16c0_s_p4_0[] = {
  108838. 1, 3, 2, 7, 8, 0, 0, 0, 0, 0, 0, 0, 6, 6, 0, 0,
  108839. 0, 0, 0, 0, 0, 6, 6, 0, 0, 0, 0, 0, 0, 0, 7, 7,
  108840. 0, 0, 0, 0, 0, 0, 0, 7, 7, 0, 0, 0, 0, 0, 0, 0,
  108841. 8, 8, 0, 0, 0, 0, 0, 0, 0, 8, 8, 0, 0, 0, 0, 0,
  108842. 0, 0, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108843. 0,
  108844. };
  108845. static float _vq_quantthresh__16c0_s_p4_0[] = {
  108846. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  108847. };
  108848. static long _vq_quantmap__16c0_s_p4_0[] = {
  108849. 7, 5, 3, 1, 0, 2, 4, 6,
  108850. 8,
  108851. };
  108852. static encode_aux_threshmatch _vq_auxt__16c0_s_p4_0 = {
  108853. _vq_quantthresh__16c0_s_p4_0,
  108854. _vq_quantmap__16c0_s_p4_0,
  108855. 9,
  108856. 9
  108857. };
  108858. static static_codebook _16c0_s_p4_0 = {
  108859. 2, 81,
  108860. _vq_lengthlist__16c0_s_p4_0,
  108861. 1, -531628032, 1611661312, 4, 0,
  108862. _vq_quantlist__16c0_s_p4_0,
  108863. NULL,
  108864. &_vq_auxt__16c0_s_p4_0,
  108865. NULL,
  108866. 0
  108867. };
  108868. static long _vq_quantlist__16c0_s_p5_0[] = {
  108869. 4,
  108870. 3,
  108871. 5,
  108872. 2,
  108873. 6,
  108874. 1,
  108875. 7,
  108876. 0,
  108877. 8,
  108878. };
  108879. static long _vq_lengthlist__16c0_s_p5_0[] = {
  108880. 1, 3, 3, 6, 6, 6, 6, 8, 8, 0, 0, 0, 7, 7, 7, 7,
  108881. 8, 8, 0, 0, 0, 7, 7, 7, 7, 8, 8, 0, 0, 0, 7, 7,
  108882. 8, 8, 9, 9, 0, 0, 0, 7, 7, 8, 8, 9, 9, 0, 0, 0,
  108883. 8, 9, 8, 8,10,10, 0, 0, 0, 8, 8, 8, 8,10,10, 0,
  108884. 0, 0,10,10, 9, 9,10,10, 0, 0, 0, 0, 0, 9, 9,10,
  108885. 10,
  108886. };
  108887. static float _vq_quantthresh__16c0_s_p5_0[] = {
  108888. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  108889. };
  108890. static long _vq_quantmap__16c0_s_p5_0[] = {
  108891. 7, 5, 3, 1, 0, 2, 4, 6,
  108892. 8,
  108893. };
  108894. static encode_aux_threshmatch _vq_auxt__16c0_s_p5_0 = {
  108895. _vq_quantthresh__16c0_s_p5_0,
  108896. _vq_quantmap__16c0_s_p5_0,
  108897. 9,
  108898. 9
  108899. };
  108900. static static_codebook _16c0_s_p5_0 = {
  108901. 2, 81,
  108902. _vq_lengthlist__16c0_s_p5_0,
  108903. 1, -531628032, 1611661312, 4, 0,
  108904. _vq_quantlist__16c0_s_p5_0,
  108905. NULL,
  108906. &_vq_auxt__16c0_s_p5_0,
  108907. NULL,
  108908. 0
  108909. };
  108910. static long _vq_quantlist__16c0_s_p6_0[] = {
  108911. 8,
  108912. 7,
  108913. 9,
  108914. 6,
  108915. 10,
  108916. 5,
  108917. 11,
  108918. 4,
  108919. 12,
  108920. 3,
  108921. 13,
  108922. 2,
  108923. 14,
  108924. 1,
  108925. 15,
  108926. 0,
  108927. 16,
  108928. };
  108929. static long _vq_lengthlist__16c0_s_p6_0[] = {
  108930. 1, 3, 4, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,10,11,
  108931. 11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,10,11,
  108932. 11,11, 0, 0, 0, 6, 6, 8, 8, 9, 9, 9, 9,10,10,11,
  108933. 11,11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  108934. 11,11,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,
  108935. 10,11,11,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,10,10,
  108936. 11,11,12,12,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,10,
  108937. 10,11,11,12,12,12,13, 0, 0, 0, 9, 9, 9, 9,10,10,
  108938. 10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0,10,10,10,
  108939. 10,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9, 9,
  108940. 10,10,11,11,12,12,13,13,13,13, 0, 0, 0, 0, 0, 9,
  108941. 9,10,10,11,11,12,12,13,13,13,14, 0, 0, 0, 0, 0,
  108942. 10,10,10,11,11,11,12,12,13,13,13,14, 0, 0, 0, 0,
  108943. 0, 0, 0,10,10,11,11,12,12,13,13,14,14, 0, 0, 0,
  108944. 0, 0, 0, 0,11,11,12,12,13,13,13,13,14,14, 0, 0,
  108945. 0, 0, 0, 0, 0,11,11,12,12,12,13,13,14,15,14, 0,
  108946. 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,13,14,14,15,
  108947. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,13,13,14,13,14,
  108948. 14,
  108949. };
  108950. static float _vq_quantthresh__16c0_s_p6_0[] = {
  108951. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  108952. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  108953. };
  108954. static long _vq_quantmap__16c0_s_p6_0[] = {
  108955. 15, 13, 11, 9, 7, 5, 3, 1,
  108956. 0, 2, 4, 6, 8, 10, 12, 14,
  108957. 16,
  108958. };
  108959. static encode_aux_threshmatch _vq_auxt__16c0_s_p6_0 = {
  108960. _vq_quantthresh__16c0_s_p6_0,
  108961. _vq_quantmap__16c0_s_p6_0,
  108962. 17,
  108963. 17
  108964. };
  108965. static static_codebook _16c0_s_p6_0 = {
  108966. 2, 289,
  108967. _vq_lengthlist__16c0_s_p6_0,
  108968. 1, -529530880, 1611661312, 5, 0,
  108969. _vq_quantlist__16c0_s_p6_0,
  108970. NULL,
  108971. &_vq_auxt__16c0_s_p6_0,
  108972. NULL,
  108973. 0
  108974. };
  108975. static long _vq_quantlist__16c0_s_p7_0[] = {
  108976. 1,
  108977. 0,
  108978. 2,
  108979. };
  108980. static long _vq_lengthlist__16c0_s_p7_0[] = {
  108981. 1, 4, 4, 6, 6, 6, 7, 6, 6, 4, 7, 7,11,10,10,11,
  108982. 11,10, 4, 7, 7,10,10,10,11,10,10, 6,10,10,11,11,
  108983. 11,11,11,10, 6, 9, 9,11,12,12,11, 9, 9, 6, 9,10,
  108984. 11,12,12,11, 9,10, 7,11,11,11,11,11,12,13,12, 6,
  108985. 9,10,11,10,10,12,13,13, 6,10, 9,11,10,10,11,12,
  108986. 13,
  108987. };
  108988. static float _vq_quantthresh__16c0_s_p7_0[] = {
  108989. -5.5, 5.5,
  108990. };
  108991. static long _vq_quantmap__16c0_s_p7_0[] = {
  108992. 1, 0, 2,
  108993. };
  108994. static encode_aux_threshmatch _vq_auxt__16c0_s_p7_0 = {
  108995. _vq_quantthresh__16c0_s_p7_0,
  108996. _vq_quantmap__16c0_s_p7_0,
  108997. 3,
  108998. 3
  108999. };
  109000. static static_codebook _16c0_s_p7_0 = {
  109001. 4, 81,
  109002. _vq_lengthlist__16c0_s_p7_0,
  109003. 1, -529137664, 1618345984, 2, 0,
  109004. _vq_quantlist__16c0_s_p7_0,
  109005. NULL,
  109006. &_vq_auxt__16c0_s_p7_0,
  109007. NULL,
  109008. 0
  109009. };
  109010. static long _vq_quantlist__16c0_s_p7_1[] = {
  109011. 5,
  109012. 4,
  109013. 6,
  109014. 3,
  109015. 7,
  109016. 2,
  109017. 8,
  109018. 1,
  109019. 9,
  109020. 0,
  109021. 10,
  109022. };
  109023. static long _vq_lengthlist__16c0_s_p7_1[] = {
  109024. 1, 3, 4, 6, 6, 7, 7, 8, 8, 8, 8,10,10,10, 7, 7,
  109025. 8, 8, 8, 9, 9, 9,10,10,10, 6, 7, 8, 8, 8, 8, 9,
  109026. 8,10,10,10, 7, 7, 8, 8, 9, 9, 9, 9,10,10,10, 7,
  109027. 7, 8, 8, 9, 9, 8, 9,10,10,10, 8, 8, 9, 9, 9, 9,
  109028. 9, 9,11,11,11, 8, 8, 9, 9, 9, 9, 9,10,10,11,11,
  109029. 9, 9, 9, 9, 9, 9, 9,10,11,11,11,10,11, 9, 9, 9,
  109030. 9,10, 9,11,11,11,10,11,10,10, 9, 9,10,10,11,11,
  109031. 11,11,11, 9, 9, 9, 9,10,10,
  109032. };
  109033. static float _vq_quantthresh__16c0_s_p7_1[] = {
  109034. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  109035. 3.5, 4.5,
  109036. };
  109037. static long _vq_quantmap__16c0_s_p7_1[] = {
  109038. 9, 7, 5, 3, 1, 0, 2, 4,
  109039. 6, 8, 10,
  109040. };
  109041. static encode_aux_threshmatch _vq_auxt__16c0_s_p7_1 = {
  109042. _vq_quantthresh__16c0_s_p7_1,
  109043. _vq_quantmap__16c0_s_p7_1,
  109044. 11,
  109045. 11
  109046. };
  109047. static static_codebook _16c0_s_p7_1 = {
  109048. 2, 121,
  109049. _vq_lengthlist__16c0_s_p7_1,
  109050. 1, -531365888, 1611661312, 4, 0,
  109051. _vq_quantlist__16c0_s_p7_1,
  109052. NULL,
  109053. &_vq_auxt__16c0_s_p7_1,
  109054. NULL,
  109055. 0
  109056. };
  109057. static long _vq_quantlist__16c0_s_p8_0[] = {
  109058. 6,
  109059. 5,
  109060. 7,
  109061. 4,
  109062. 8,
  109063. 3,
  109064. 9,
  109065. 2,
  109066. 10,
  109067. 1,
  109068. 11,
  109069. 0,
  109070. 12,
  109071. };
  109072. static long _vq_lengthlist__16c0_s_p8_0[] = {
  109073. 1, 4, 4, 7, 7, 7, 7, 7, 6, 8, 8,10,10, 6, 5, 6,
  109074. 8, 8, 8, 8, 8, 8, 8, 9,10,10, 7, 6, 6, 8, 8, 8,
  109075. 8, 8, 8, 8, 8,10,10, 0, 8, 8, 8, 8, 9, 8, 9, 9,
  109076. 9,10,10,10, 0, 9, 8, 8, 8, 9, 9, 8, 8, 9, 9,10,
  109077. 10, 0,12,11, 8, 8, 9, 9, 9, 9,10,10,11,10, 0,12,
  109078. 13, 8, 8, 9,10, 9, 9,11,11,11,12, 0, 0, 0, 8, 8,
  109079. 8, 8,10, 9,12,13,12,14, 0, 0, 0, 8, 8, 8, 9,10,
  109080. 10,12,12,13,14, 0, 0, 0,13,13, 9, 9,11,11, 0, 0,
  109081. 14, 0, 0, 0, 0,14,14,10,10,12,11,12,14,14,14, 0,
  109082. 0, 0, 0, 0,11,11,13,13,14,13,14,14, 0, 0, 0, 0,
  109083. 0,12,13,13,12,13,14,14,14,
  109084. };
  109085. static float _vq_quantthresh__16c0_s_p8_0[] = {
  109086. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  109087. 12.5, 17.5, 22.5, 27.5,
  109088. };
  109089. static long _vq_quantmap__16c0_s_p8_0[] = {
  109090. 11, 9, 7, 5, 3, 1, 0, 2,
  109091. 4, 6, 8, 10, 12,
  109092. };
  109093. static encode_aux_threshmatch _vq_auxt__16c0_s_p8_0 = {
  109094. _vq_quantthresh__16c0_s_p8_0,
  109095. _vq_quantmap__16c0_s_p8_0,
  109096. 13,
  109097. 13
  109098. };
  109099. static static_codebook _16c0_s_p8_0 = {
  109100. 2, 169,
  109101. _vq_lengthlist__16c0_s_p8_0,
  109102. 1, -526516224, 1616117760, 4, 0,
  109103. _vq_quantlist__16c0_s_p8_0,
  109104. NULL,
  109105. &_vq_auxt__16c0_s_p8_0,
  109106. NULL,
  109107. 0
  109108. };
  109109. static long _vq_quantlist__16c0_s_p8_1[] = {
  109110. 2,
  109111. 1,
  109112. 3,
  109113. 0,
  109114. 4,
  109115. };
  109116. static long _vq_lengthlist__16c0_s_p8_1[] = {
  109117. 1, 4, 3, 5, 5, 7, 7, 7, 6, 6, 7, 7, 7, 5, 5, 7,
  109118. 7, 7, 6, 6, 7, 7, 7, 6, 6,
  109119. };
  109120. static float _vq_quantthresh__16c0_s_p8_1[] = {
  109121. -1.5, -0.5, 0.5, 1.5,
  109122. };
  109123. static long _vq_quantmap__16c0_s_p8_1[] = {
  109124. 3, 1, 0, 2, 4,
  109125. };
  109126. static encode_aux_threshmatch _vq_auxt__16c0_s_p8_1 = {
  109127. _vq_quantthresh__16c0_s_p8_1,
  109128. _vq_quantmap__16c0_s_p8_1,
  109129. 5,
  109130. 5
  109131. };
  109132. static static_codebook _16c0_s_p8_1 = {
  109133. 2, 25,
  109134. _vq_lengthlist__16c0_s_p8_1,
  109135. 1, -533725184, 1611661312, 3, 0,
  109136. _vq_quantlist__16c0_s_p8_1,
  109137. NULL,
  109138. &_vq_auxt__16c0_s_p8_1,
  109139. NULL,
  109140. 0
  109141. };
  109142. static long _vq_quantlist__16c0_s_p9_0[] = {
  109143. 1,
  109144. 0,
  109145. 2,
  109146. };
  109147. static long _vq_lengthlist__16c0_s_p9_0[] = {
  109148. 1, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  109149. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  109150. 8, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  109151. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  109152. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  109153. 7,
  109154. };
  109155. static float _vq_quantthresh__16c0_s_p9_0[] = {
  109156. -157.5, 157.5,
  109157. };
  109158. static long _vq_quantmap__16c0_s_p9_0[] = {
  109159. 1, 0, 2,
  109160. };
  109161. static encode_aux_threshmatch _vq_auxt__16c0_s_p9_0 = {
  109162. _vq_quantthresh__16c0_s_p9_0,
  109163. _vq_quantmap__16c0_s_p9_0,
  109164. 3,
  109165. 3
  109166. };
  109167. static static_codebook _16c0_s_p9_0 = {
  109168. 4, 81,
  109169. _vq_lengthlist__16c0_s_p9_0,
  109170. 1, -518803456, 1628680192, 2, 0,
  109171. _vq_quantlist__16c0_s_p9_0,
  109172. NULL,
  109173. &_vq_auxt__16c0_s_p9_0,
  109174. NULL,
  109175. 0
  109176. };
  109177. static long _vq_quantlist__16c0_s_p9_1[] = {
  109178. 7,
  109179. 6,
  109180. 8,
  109181. 5,
  109182. 9,
  109183. 4,
  109184. 10,
  109185. 3,
  109186. 11,
  109187. 2,
  109188. 12,
  109189. 1,
  109190. 13,
  109191. 0,
  109192. 14,
  109193. };
  109194. static long _vq_lengthlist__16c0_s_p9_1[] = {
  109195. 1, 5, 5, 5, 5, 9,11,11,10,10,10,10,10,10,10, 7,
  109196. 6, 6, 6, 6,10,10,10,10,10,10,10,10,10,10, 7, 6,
  109197. 6, 6, 6,10, 9,10,10,10,10,10,10,10,10,10, 7, 7,
  109198. 8, 9,10,10,10,10,10,10,10,10,10,10,10, 8, 7,10,
  109199. 10,10, 9,10,10,10,10,10,10,10,10,10,10,10,10,10,
  109200. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  109201. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  109202. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  109203. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  109204. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  109205. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  109206. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  109207. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  109208. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  109209. 10,
  109210. };
  109211. static float _vq_quantthresh__16c0_s_p9_1[] = {
  109212. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  109213. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  109214. };
  109215. static long _vq_quantmap__16c0_s_p9_1[] = {
  109216. 13, 11, 9, 7, 5, 3, 1, 0,
  109217. 2, 4, 6, 8, 10, 12, 14,
  109218. };
  109219. static encode_aux_threshmatch _vq_auxt__16c0_s_p9_1 = {
  109220. _vq_quantthresh__16c0_s_p9_1,
  109221. _vq_quantmap__16c0_s_p9_1,
  109222. 15,
  109223. 15
  109224. };
  109225. static static_codebook _16c0_s_p9_1 = {
  109226. 2, 225,
  109227. _vq_lengthlist__16c0_s_p9_1,
  109228. 1, -520986624, 1620377600, 4, 0,
  109229. _vq_quantlist__16c0_s_p9_1,
  109230. NULL,
  109231. &_vq_auxt__16c0_s_p9_1,
  109232. NULL,
  109233. 0
  109234. };
  109235. static long _vq_quantlist__16c0_s_p9_2[] = {
  109236. 10,
  109237. 9,
  109238. 11,
  109239. 8,
  109240. 12,
  109241. 7,
  109242. 13,
  109243. 6,
  109244. 14,
  109245. 5,
  109246. 15,
  109247. 4,
  109248. 16,
  109249. 3,
  109250. 17,
  109251. 2,
  109252. 18,
  109253. 1,
  109254. 19,
  109255. 0,
  109256. 20,
  109257. };
  109258. static long _vq_lengthlist__16c0_s_p9_2[] = {
  109259. 1, 5, 5, 7, 8, 8, 7, 9, 9, 9,12,12,11,12,12,10,
  109260. 10,11,12,12,12,11,12,12, 8, 9, 8, 7, 9,10,10,11,
  109261. 11,10,11,12,10,12,10,12,12,12,11,12,11, 9, 8, 8,
  109262. 9,10, 9, 8, 9,10,12,12,11,11,12,11,10,11,12,11,
  109263. 12,12, 8, 9, 9, 9,10,11,12,11,12,11,11,11,11,12,
  109264. 12,11,11,12,12,11,11, 9, 9, 8, 9, 9,11, 9, 9,10,
  109265. 9,11,11,11,11,12,11,11,10,12,12,12, 9,12,11,10,
  109266. 11,11,11,11,12,12,12,11,11,11,12,10,12,12,12,10,
  109267. 10, 9,10, 9,10,10, 9, 9, 9,10,10,12,10,11,11, 9,
  109268. 11,11,10,11,11,11,10,10,10, 9, 9,10,10, 9, 9,10,
  109269. 11,11,10,11,10,11,10,11,11,10,11,11,11,10, 9,10,
  109270. 10, 9,10, 9, 9,11, 9, 9,11,10,10,11,11,10,10,11,
  109271. 10,11, 8, 9,11,11,10, 9,10,11,11,10,11,11,10,10,
  109272. 10,11,10, 9,10,10,11, 9,10,10, 9,11,10,10,10,10,
  109273. 11,10,11,11, 9,11,10,11,10,10,11,11,10,10,10, 9,
  109274. 10,10,11,11,11, 9,10,10,10,10,10,11,10,10,10, 9,
  109275. 10,10,11,10,10,10,10,10, 9,10,11,10,10,10,10,11,
  109276. 11,11,10,10,10,10,10,11,10,11,10,11,10,10,10, 9,
  109277. 11,11,10,10,10,11,11,10,10,10,10,10,10,10,10,11,
  109278. 11, 9,10,10,10,11,10,11,10,10,10,11, 9,10,11,10,
  109279. 11,10,10, 9,10,10,10,11,10,11,10,10,10,10,10,11,
  109280. 11,10,11,11,10,10,11,11,10, 9, 9,10,10,10,10,10,
  109281. 9,11, 9,10,10,10,11,11,10,10,10,10,11,11,11,10,
  109282. 9, 9,10,10,11,10,10,10,10,10,11,11,11,10,10,10,
  109283. 11,11,11, 9,10,10,10,10, 9,10, 9,10,11,10,11,10,
  109284. 10,11,11,10,11,11,11,11,11,10,11,10,10,10, 9,11,
  109285. 11,10,11,11,11,11,11,11,11,11,11,10,11,10,10,10,
  109286. 10,11,10,10,11, 9,10,10,10,
  109287. };
  109288. static float _vq_quantthresh__16c0_s_p9_2[] = {
  109289. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  109290. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  109291. 6.5, 7.5, 8.5, 9.5,
  109292. };
  109293. static long _vq_quantmap__16c0_s_p9_2[] = {
  109294. 19, 17, 15, 13, 11, 9, 7, 5,
  109295. 3, 1, 0, 2, 4, 6, 8, 10,
  109296. 12, 14, 16, 18, 20,
  109297. };
  109298. static encode_aux_threshmatch _vq_auxt__16c0_s_p9_2 = {
  109299. _vq_quantthresh__16c0_s_p9_2,
  109300. _vq_quantmap__16c0_s_p9_2,
  109301. 21,
  109302. 21
  109303. };
  109304. static static_codebook _16c0_s_p9_2 = {
  109305. 2, 441,
  109306. _vq_lengthlist__16c0_s_p9_2,
  109307. 1, -529268736, 1611661312, 5, 0,
  109308. _vq_quantlist__16c0_s_p9_2,
  109309. NULL,
  109310. &_vq_auxt__16c0_s_p9_2,
  109311. NULL,
  109312. 0
  109313. };
  109314. static long _huff_lengthlist__16c0_s_single[] = {
  109315. 3, 4,19, 7, 9, 7, 8,11, 9,12, 4, 1,19, 6, 7, 7,
  109316. 8,10,11,13,18,18,18,18,18,18,18,18,18,18, 8, 6,
  109317. 18, 8, 9, 9,11,12,14,18, 9, 6,18, 9, 7, 8, 9,11,
  109318. 12,18, 7, 6,18, 8, 7, 7, 7, 9,11,17, 8, 8,18, 9,
  109319. 7, 6, 6, 8,11,17,10,10,18,12, 9, 8, 7, 9,12,18,
  109320. 13,15,18,15,13,11,10,11,15,18,14,18,18,18,18,18,
  109321. 16,16,18,18,
  109322. };
  109323. static static_codebook _huff_book__16c0_s_single = {
  109324. 2, 100,
  109325. _huff_lengthlist__16c0_s_single,
  109326. 0, 0, 0, 0, 0,
  109327. NULL,
  109328. NULL,
  109329. NULL,
  109330. NULL,
  109331. 0
  109332. };
  109333. static long _huff_lengthlist__16c1_s_long[] = {
  109334. 2, 5,20, 7,10, 7, 8,10,11,11, 4, 2,20, 5, 8, 6,
  109335. 7, 9,10,10,20,20,20,20,19,19,19,19,19,19, 7, 5,
  109336. 19, 6,10, 7, 9,11,13,17,11, 8,19,10, 7, 7, 8,10,
  109337. 11,15, 7, 5,19, 7, 7, 5, 6, 9,11,16, 7, 6,19, 8,
  109338. 7, 6, 6, 7, 9,13, 9, 9,19,11, 9, 8, 6, 7, 8,13,
  109339. 12,14,19,16,13,10, 9, 8, 9,13,14,17,19,18,18,17,
  109340. 12,11,11,13,
  109341. };
  109342. static static_codebook _huff_book__16c1_s_long = {
  109343. 2, 100,
  109344. _huff_lengthlist__16c1_s_long,
  109345. 0, 0, 0, 0, 0,
  109346. NULL,
  109347. NULL,
  109348. NULL,
  109349. NULL,
  109350. 0
  109351. };
  109352. static long _vq_quantlist__16c1_s_p1_0[] = {
  109353. 1,
  109354. 0,
  109355. 2,
  109356. };
  109357. static long _vq_lengthlist__16c1_s_p1_0[] = {
  109358. 1, 5, 5, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0,
  109359. 0, 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109360. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109361. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109362. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109363. 0, 5, 8, 7, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0, 0,
  109364. 0, 0, 0, 7, 8, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109365. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109366. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109367. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109368. 0, 0, 5, 7, 8, 0, 0, 0, 0, 0, 0, 7, 9, 8, 0, 0,
  109369. 0, 0, 0, 0, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109370. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109371. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109372. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109373. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109374. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109375. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109376. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109377. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109378. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109379. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109380. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109381. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109382. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109383. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109384. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109385. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109386. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109387. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109388. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109389. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109390. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109391. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109392. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109393. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109394. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109395. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109396. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109397. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109398. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109399. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109400. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109401. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109402. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109403. 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 8, 7, 0, 0, 0, 0,
  109404. 0, 0, 8, 9, 9, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  109405. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109406. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109407. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109408. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0, 0,
  109409. 0, 0, 0, 9, 9,11, 0, 0, 0, 0, 0, 0, 9,11,10, 0,
  109410. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109411. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109412. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109413. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  109414. 0, 0, 0, 0, 8,11, 9, 0, 0, 0, 0, 0, 0, 9,10,11,
  109415. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109416. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109417. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109418. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109419. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109420. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109421. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109422. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109423. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109424. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109425. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109426. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109427. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109428. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109429. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109430. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109431. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109432. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109433. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109434. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109435. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109436. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109437. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109438. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109439. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109440. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109441. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109442. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109443. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109444. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109445. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109446. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109447. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109448. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109449. 0, 0, 5, 7, 8, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  109450. 0, 0, 0, 0, 8, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109451. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109452. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109453. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109454. 0, 0, 0, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,11,10, 0,
  109455. 0, 0, 0, 0, 0, 8, 9,11, 0, 0, 0, 0, 0, 0, 0, 0,
  109456. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109457. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109458. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109459. 0, 0, 0, 0, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,10,11,
  109460. 0, 0, 0, 0, 0, 0, 9,11, 9, 0, 0, 0, 0, 0, 0, 0,
  109461. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109462. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109463. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109464. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109465. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109466. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109467. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109468. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109469. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109470. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109471. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109472. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109473. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109474. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109475. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109476. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109477. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109478. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109479. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109480. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109481. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109482. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109483. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109484. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109485. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109486. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109487. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109488. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109489. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109490. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109491. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109492. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109493. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109494. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109495. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109496. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109497. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109498. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109499. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109500. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109501. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109502. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109503. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109504. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109505. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109506. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109507. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109508. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109509. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109510. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109511. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109512. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109513. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109514. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109515. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109516. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109517. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109518. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109519. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109520. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109521. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109522. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109523. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109524. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109525. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109526. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109527. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109528. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109529. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109530. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109531. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109532. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109533. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109534. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109535. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109536. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109537. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109538. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109539. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109540. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109541. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109542. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109543. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109544. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109545. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109546. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109547. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109548. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109549. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109550. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109551. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109552. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109553. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109554. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109555. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109556. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109557. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109558. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109559. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109560. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109561. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109562. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109563. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109564. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109565. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109566. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109567. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109568. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109569. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109570. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109571. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109572. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109573. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109574. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109575. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109576. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109577. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109578. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109579. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109580. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109581. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109582. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109583. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109584. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109585. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109586. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109587. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109588. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109589. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109590. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109591. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109592. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109593. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109594. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109595. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109596. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109597. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109598. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109599. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109600. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109601. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109602. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109603. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109604. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109605. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109606. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109607. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109608. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109609. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109610. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109611. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109612. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109613. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109614. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109615. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109616. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109617. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109618. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109619. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109620. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109621. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109622. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109623. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109624. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109625. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109626. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109627. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109628. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109629. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109630. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109631. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109632. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109633. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109634. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109635. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109636. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109637. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109638. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109639. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109640. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109641. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109642. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109643. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109644. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109645. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109646. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109647. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109648. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109649. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109650. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109651. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109652. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109653. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109654. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109655. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109656. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109657. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109658. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109659. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109660. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109661. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109662. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109663. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109664. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109665. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109666. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109667. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109668. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109669. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109670. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109671. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109672. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109673. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109674. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109675. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109676. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109677. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109678. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109679. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109680. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109681. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109682. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109683. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109684. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109685. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109686. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109687. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109688. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109689. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109690. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109691. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109692. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109693. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109694. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109695. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109696. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109697. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109698. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109699. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109700. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109701. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109702. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109703. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109704. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109705. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109706. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109707. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109708. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109709. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109710. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109711. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109712. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109713. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109714. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109715. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109716. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109717. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109718. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109719. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109720. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109721. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109722. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109723. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109724. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109725. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109726. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109727. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109728. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109729. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109730. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109731. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109732. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109733. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109734. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109735. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109736. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109737. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109738. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109739. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109740. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109741. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109742. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109743. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109744. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109745. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109746. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109747. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109748. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109749. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109750. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109751. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109752. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109753. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109754. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109755. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109756. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109757. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109758. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109759. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109760. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109761. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109762. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109763. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109764. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109765. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109766. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109767. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109768. 0,
  109769. };
  109770. static float _vq_quantthresh__16c1_s_p1_0[] = {
  109771. -0.5, 0.5,
  109772. };
  109773. static long _vq_quantmap__16c1_s_p1_0[] = {
  109774. 1, 0, 2,
  109775. };
  109776. static encode_aux_threshmatch _vq_auxt__16c1_s_p1_0 = {
  109777. _vq_quantthresh__16c1_s_p1_0,
  109778. _vq_quantmap__16c1_s_p1_0,
  109779. 3,
  109780. 3
  109781. };
  109782. static static_codebook _16c1_s_p1_0 = {
  109783. 8, 6561,
  109784. _vq_lengthlist__16c1_s_p1_0,
  109785. 1, -535822336, 1611661312, 2, 0,
  109786. _vq_quantlist__16c1_s_p1_0,
  109787. NULL,
  109788. &_vq_auxt__16c1_s_p1_0,
  109789. NULL,
  109790. 0
  109791. };
  109792. static long _vq_quantlist__16c1_s_p2_0[] = {
  109793. 2,
  109794. 1,
  109795. 3,
  109796. 0,
  109797. 4,
  109798. };
  109799. static long _vq_lengthlist__16c1_s_p2_0[] = {
  109800. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109801. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109802. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109803. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109804. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109805. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109806. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109807. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109808. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109809. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109810. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109811. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109812. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109813. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109814. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109815. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109816. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109817. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109818. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109819. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109820. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109821. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109822. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109823. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109824. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109825. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109826. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109827. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109828. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109829. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109830. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109831. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109832. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109833. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109834. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109835. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109836. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109837. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109838. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109839. 0,
  109840. };
  109841. static float _vq_quantthresh__16c1_s_p2_0[] = {
  109842. -1.5, -0.5, 0.5, 1.5,
  109843. };
  109844. static long _vq_quantmap__16c1_s_p2_0[] = {
  109845. 3, 1, 0, 2, 4,
  109846. };
  109847. static encode_aux_threshmatch _vq_auxt__16c1_s_p2_0 = {
  109848. _vq_quantthresh__16c1_s_p2_0,
  109849. _vq_quantmap__16c1_s_p2_0,
  109850. 5,
  109851. 5
  109852. };
  109853. static static_codebook _16c1_s_p2_0 = {
  109854. 4, 625,
  109855. _vq_lengthlist__16c1_s_p2_0,
  109856. 1, -533725184, 1611661312, 3, 0,
  109857. _vq_quantlist__16c1_s_p2_0,
  109858. NULL,
  109859. &_vq_auxt__16c1_s_p2_0,
  109860. NULL,
  109861. 0
  109862. };
  109863. static long _vq_quantlist__16c1_s_p3_0[] = {
  109864. 2,
  109865. 1,
  109866. 3,
  109867. 0,
  109868. 4,
  109869. };
  109870. static long _vq_lengthlist__16c1_s_p3_0[] = {
  109871. 1, 4, 4, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109872. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 5, 5, 7, 7, 0, 0,
  109873. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109874. 0, 0, 4, 5, 5, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109875. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 7, 7, 9, 9,
  109876. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109877. 0, 0, 0, 0, 6, 7, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0,
  109878. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109879. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109880. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109881. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109882. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109883. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109884. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109885. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109886. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109887. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109888. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109889. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109890. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109891. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109892. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109893. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109894. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109895. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109896. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109897. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109898. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109899. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109900. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109901. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109902. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109903. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109904. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109905. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109906. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109907. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109908. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109909. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109910. 0,
  109911. };
  109912. static float _vq_quantthresh__16c1_s_p3_0[] = {
  109913. -1.5, -0.5, 0.5, 1.5,
  109914. };
  109915. static long _vq_quantmap__16c1_s_p3_0[] = {
  109916. 3, 1, 0, 2, 4,
  109917. };
  109918. static encode_aux_threshmatch _vq_auxt__16c1_s_p3_0 = {
  109919. _vq_quantthresh__16c1_s_p3_0,
  109920. _vq_quantmap__16c1_s_p3_0,
  109921. 5,
  109922. 5
  109923. };
  109924. static static_codebook _16c1_s_p3_0 = {
  109925. 4, 625,
  109926. _vq_lengthlist__16c1_s_p3_0,
  109927. 1, -533725184, 1611661312, 3, 0,
  109928. _vq_quantlist__16c1_s_p3_0,
  109929. NULL,
  109930. &_vq_auxt__16c1_s_p3_0,
  109931. NULL,
  109932. 0
  109933. };
  109934. static long _vq_quantlist__16c1_s_p4_0[] = {
  109935. 4,
  109936. 3,
  109937. 5,
  109938. 2,
  109939. 6,
  109940. 1,
  109941. 7,
  109942. 0,
  109943. 8,
  109944. };
  109945. static long _vq_lengthlist__16c1_s_p4_0[] = {
  109946. 1, 2, 3, 7, 7, 0, 0, 0, 0, 0, 0, 0, 6, 6, 0, 0,
  109947. 0, 0, 0, 0, 0, 6, 6, 0, 0, 0, 0, 0, 0, 0, 7, 7,
  109948. 0, 0, 0, 0, 0, 0, 0, 7, 7, 0, 0, 0, 0, 0, 0, 0,
  109949. 8, 8, 0, 0, 0, 0, 0, 0, 0, 8, 9, 0, 0, 0, 0, 0,
  109950. 0, 0,10,10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109951. 0,
  109952. };
  109953. static float _vq_quantthresh__16c1_s_p4_0[] = {
  109954. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  109955. };
  109956. static long _vq_quantmap__16c1_s_p4_0[] = {
  109957. 7, 5, 3, 1, 0, 2, 4, 6,
  109958. 8,
  109959. };
  109960. static encode_aux_threshmatch _vq_auxt__16c1_s_p4_0 = {
  109961. _vq_quantthresh__16c1_s_p4_0,
  109962. _vq_quantmap__16c1_s_p4_0,
  109963. 9,
  109964. 9
  109965. };
  109966. static static_codebook _16c1_s_p4_0 = {
  109967. 2, 81,
  109968. _vq_lengthlist__16c1_s_p4_0,
  109969. 1, -531628032, 1611661312, 4, 0,
  109970. _vq_quantlist__16c1_s_p4_0,
  109971. NULL,
  109972. &_vq_auxt__16c1_s_p4_0,
  109973. NULL,
  109974. 0
  109975. };
  109976. static long _vq_quantlist__16c1_s_p5_0[] = {
  109977. 4,
  109978. 3,
  109979. 5,
  109980. 2,
  109981. 6,
  109982. 1,
  109983. 7,
  109984. 0,
  109985. 8,
  109986. };
  109987. static long _vq_lengthlist__16c1_s_p5_0[] = {
  109988. 1, 3, 3, 5, 5, 6, 6, 8, 8, 0, 0, 0, 7, 7, 7, 7,
  109989. 9, 9, 0, 0, 0, 7, 7, 7, 7, 9, 9, 0, 0, 0, 8, 8,
  109990. 8, 8, 9, 9, 0, 0, 0, 8, 8, 8, 8,10,10, 0, 0, 0,
  109991. 9, 9, 8, 8,10,10, 0, 0, 0, 9, 9, 8, 8,10,10, 0,
  109992. 0, 0,10,10, 9, 9,10,10, 0, 0, 0, 0, 0, 9, 9,10,
  109993. 10,
  109994. };
  109995. static float _vq_quantthresh__16c1_s_p5_0[] = {
  109996. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  109997. };
  109998. static long _vq_quantmap__16c1_s_p5_0[] = {
  109999. 7, 5, 3, 1, 0, 2, 4, 6,
  110000. 8,
  110001. };
  110002. static encode_aux_threshmatch _vq_auxt__16c1_s_p5_0 = {
  110003. _vq_quantthresh__16c1_s_p5_0,
  110004. _vq_quantmap__16c1_s_p5_0,
  110005. 9,
  110006. 9
  110007. };
  110008. static static_codebook _16c1_s_p5_0 = {
  110009. 2, 81,
  110010. _vq_lengthlist__16c1_s_p5_0,
  110011. 1, -531628032, 1611661312, 4, 0,
  110012. _vq_quantlist__16c1_s_p5_0,
  110013. NULL,
  110014. &_vq_auxt__16c1_s_p5_0,
  110015. NULL,
  110016. 0
  110017. };
  110018. static long _vq_quantlist__16c1_s_p6_0[] = {
  110019. 8,
  110020. 7,
  110021. 9,
  110022. 6,
  110023. 10,
  110024. 5,
  110025. 11,
  110026. 4,
  110027. 12,
  110028. 3,
  110029. 13,
  110030. 2,
  110031. 14,
  110032. 1,
  110033. 15,
  110034. 0,
  110035. 16,
  110036. };
  110037. static long _vq_lengthlist__16c1_s_p6_0[] = {
  110038. 1, 3, 3, 6, 6, 8, 8, 9, 9, 9, 9,10,10,11,11,12,
  110039. 12, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,11,11,
  110040. 12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,11,
  110041. 11,12,12, 0, 0, 0, 8, 8, 8, 9,10, 9,10,10,10,10,
  110042. 11,11,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,10,10,11,
  110043. 11,11,12,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,10,10,
  110044. 11,11,12,12,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,10,
  110045. 10,11,11,12,12,13,13, 0, 0, 0, 9, 9, 9, 9,10,10,
  110046. 10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9, 9,10,
  110047. 10,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9, 9,
  110048. 10,10,11,11,12,12,12,12,13,13, 0, 0, 0, 0, 0, 9,
  110049. 9,10,10,11,11,12,12,12,12,13,13, 0, 0, 0, 0, 0,
  110050. 10,10,11,10,11,11,12,12,13,13,13,13, 0, 0, 0, 0,
  110051. 0, 0, 0,10,10,11,11,12,12,13,13,13,13, 0, 0, 0,
  110052. 0, 0, 0, 0,11,11,12,12,12,12,13,13,14,14, 0, 0,
  110053. 0, 0, 0, 0, 0,11,11,12,12,12,12,13,13,14,14, 0,
  110054. 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,13,13,14,14,
  110055. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,13,13,13,13,14,
  110056. 14,
  110057. };
  110058. static float _vq_quantthresh__16c1_s_p6_0[] = {
  110059. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  110060. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  110061. };
  110062. static long _vq_quantmap__16c1_s_p6_0[] = {
  110063. 15, 13, 11, 9, 7, 5, 3, 1,
  110064. 0, 2, 4, 6, 8, 10, 12, 14,
  110065. 16,
  110066. };
  110067. static encode_aux_threshmatch _vq_auxt__16c1_s_p6_0 = {
  110068. _vq_quantthresh__16c1_s_p6_0,
  110069. _vq_quantmap__16c1_s_p6_0,
  110070. 17,
  110071. 17
  110072. };
  110073. static static_codebook _16c1_s_p6_0 = {
  110074. 2, 289,
  110075. _vq_lengthlist__16c1_s_p6_0,
  110076. 1, -529530880, 1611661312, 5, 0,
  110077. _vq_quantlist__16c1_s_p6_0,
  110078. NULL,
  110079. &_vq_auxt__16c1_s_p6_0,
  110080. NULL,
  110081. 0
  110082. };
  110083. static long _vq_quantlist__16c1_s_p7_0[] = {
  110084. 1,
  110085. 0,
  110086. 2,
  110087. };
  110088. static long _vq_lengthlist__16c1_s_p7_0[] = {
  110089. 1, 4, 4, 6, 6, 6, 7, 6, 6, 4, 7, 7,10, 9,10,10,
  110090. 10, 9, 4, 7, 7,10,10,10,11,10,10, 6,10,10,11,11,
  110091. 11,11,10,10, 6,10, 9,11,11,11,11,10,10, 6,10,10,
  110092. 11,11,11,11,10,10, 7,11,11,11,11,11,12,12,11, 6,
  110093. 10,10,11,10,10,11,11,11, 6,10,10,10,11,10,11,11,
  110094. 11,
  110095. };
  110096. static float _vq_quantthresh__16c1_s_p7_0[] = {
  110097. -5.5, 5.5,
  110098. };
  110099. static long _vq_quantmap__16c1_s_p7_0[] = {
  110100. 1, 0, 2,
  110101. };
  110102. static encode_aux_threshmatch _vq_auxt__16c1_s_p7_0 = {
  110103. _vq_quantthresh__16c1_s_p7_0,
  110104. _vq_quantmap__16c1_s_p7_0,
  110105. 3,
  110106. 3
  110107. };
  110108. static static_codebook _16c1_s_p7_0 = {
  110109. 4, 81,
  110110. _vq_lengthlist__16c1_s_p7_0,
  110111. 1, -529137664, 1618345984, 2, 0,
  110112. _vq_quantlist__16c1_s_p7_0,
  110113. NULL,
  110114. &_vq_auxt__16c1_s_p7_0,
  110115. NULL,
  110116. 0
  110117. };
  110118. static long _vq_quantlist__16c1_s_p7_1[] = {
  110119. 5,
  110120. 4,
  110121. 6,
  110122. 3,
  110123. 7,
  110124. 2,
  110125. 8,
  110126. 1,
  110127. 9,
  110128. 0,
  110129. 10,
  110130. };
  110131. static long _vq_lengthlist__16c1_s_p7_1[] = {
  110132. 2, 3, 3, 5, 6, 7, 7, 7, 7, 8, 8,10,10,10, 6, 6,
  110133. 7, 7, 8, 8, 8, 8,10,10,10, 6, 6, 7, 7, 8, 8, 8,
  110134. 8,10,10,10, 7, 7, 7, 7, 8, 8, 8, 8,10,10,10, 7,
  110135. 7, 7, 7, 8, 8, 8, 8,10,10,10, 7, 7, 8, 8, 8, 8,
  110136. 8, 8,10,10,10, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10,
  110137. 8, 8, 8, 8, 8, 8, 9, 9,10,10,10,10,10, 8, 8, 8,
  110138. 8, 9, 9,10,10,10,10,10, 9, 9, 8, 8, 9, 9,10,10,
  110139. 10,10,10, 8, 8, 8, 8, 9, 9,
  110140. };
  110141. static float _vq_quantthresh__16c1_s_p7_1[] = {
  110142. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  110143. 3.5, 4.5,
  110144. };
  110145. static long _vq_quantmap__16c1_s_p7_1[] = {
  110146. 9, 7, 5, 3, 1, 0, 2, 4,
  110147. 6, 8, 10,
  110148. };
  110149. static encode_aux_threshmatch _vq_auxt__16c1_s_p7_1 = {
  110150. _vq_quantthresh__16c1_s_p7_1,
  110151. _vq_quantmap__16c1_s_p7_1,
  110152. 11,
  110153. 11
  110154. };
  110155. static static_codebook _16c1_s_p7_1 = {
  110156. 2, 121,
  110157. _vq_lengthlist__16c1_s_p7_1,
  110158. 1, -531365888, 1611661312, 4, 0,
  110159. _vq_quantlist__16c1_s_p7_1,
  110160. NULL,
  110161. &_vq_auxt__16c1_s_p7_1,
  110162. NULL,
  110163. 0
  110164. };
  110165. static long _vq_quantlist__16c1_s_p8_0[] = {
  110166. 6,
  110167. 5,
  110168. 7,
  110169. 4,
  110170. 8,
  110171. 3,
  110172. 9,
  110173. 2,
  110174. 10,
  110175. 1,
  110176. 11,
  110177. 0,
  110178. 12,
  110179. };
  110180. static long _vq_lengthlist__16c1_s_p8_0[] = {
  110181. 1, 4, 4, 6, 6, 7, 7, 7, 7, 8, 8, 9, 9, 6, 5, 5,
  110182. 7, 8, 8, 9, 8, 8, 9, 9,10,11, 6, 5, 5, 8, 8, 9,
  110183. 9, 8, 8, 9,10,10,11, 0, 8, 8, 8, 9, 9, 9, 9, 9,
  110184. 10,10,11,11, 0, 9, 9, 9, 8, 9, 9, 9, 9,10,10,11,
  110185. 11, 0,13,13, 9, 9,10,10,10,10,11,11,12,12, 0,14,
  110186. 13, 9, 9,10,10,10,10,11,11,12,12, 0, 0, 0,10,10,
  110187. 9, 9,11,11,12,12,13,12, 0, 0, 0,10,10, 9, 9,10,
  110188. 10,12,12,13,13, 0, 0, 0,13,14,11,10,11,11,12,12,
  110189. 13,14, 0, 0, 0,14,14,10,10,11,11,12,12,13,13, 0,
  110190. 0, 0, 0, 0,12,12,12,12,13,13,14,15, 0, 0, 0, 0,
  110191. 0,12,12,12,12,13,13,14,15,
  110192. };
  110193. static float _vq_quantthresh__16c1_s_p8_0[] = {
  110194. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  110195. 12.5, 17.5, 22.5, 27.5,
  110196. };
  110197. static long _vq_quantmap__16c1_s_p8_0[] = {
  110198. 11, 9, 7, 5, 3, 1, 0, 2,
  110199. 4, 6, 8, 10, 12,
  110200. };
  110201. static encode_aux_threshmatch _vq_auxt__16c1_s_p8_0 = {
  110202. _vq_quantthresh__16c1_s_p8_0,
  110203. _vq_quantmap__16c1_s_p8_0,
  110204. 13,
  110205. 13
  110206. };
  110207. static static_codebook _16c1_s_p8_0 = {
  110208. 2, 169,
  110209. _vq_lengthlist__16c1_s_p8_0,
  110210. 1, -526516224, 1616117760, 4, 0,
  110211. _vq_quantlist__16c1_s_p8_0,
  110212. NULL,
  110213. &_vq_auxt__16c1_s_p8_0,
  110214. NULL,
  110215. 0
  110216. };
  110217. static long _vq_quantlist__16c1_s_p8_1[] = {
  110218. 2,
  110219. 1,
  110220. 3,
  110221. 0,
  110222. 4,
  110223. };
  110224. static long _vq_lengthlist__16c1_s_p8_1[] = {
  110225. 2, 3, 3, 5, 5, 6, 6, 6, 5, 5, 6, 6, 6, 5, 5, 6,
  110226. 6, 6, 5, 5, 6, 6, 6, 5, 5,
  110227. };
  110228. static float _vq_quantthresh__16c1_s_p8_1[] = {
  110229. -1.5, -0.5, 0.5, 1.5,
  110230. };
  110231. static long _vq_quantmap__16c1_s_p8_1[] = {
  110232. 3, 1, 0, 2, 4,
  110233. };
  110234. static encode_aux_threshmatch _vq_auxt__16c1_s_p8_1 = {
  110235. _vq_quantthresh__16c1_s_p8_1,
  110236. _vq_quantmap__16c1_s_p8_1,
  110237. 5,
  110238. 5
  110239. };
  110240. static static_codebook _16c1_s_p8_1 = {
  110241. 2, 25,
  110242. _vq_lengthlist__16c1_s_p8_1,
  110243. 1, -533725184, 1611661312, 3, 0,
  110244. _vq_quantlist__16c1_s_p8_1,
  110245. NULL,
  110246. &_vq_auxt__16c1_s_p8_1,
  110247. NULL,
  110248. 0
  110249. };
  110250. static long _vq_quantlist__16c1_s_p9_0[] = {
  110251. 6,
  110252. 5,
  110253. 7,
  110254. 4,
  110255. 8,
  110256. 3,
  110257. 9,
  110258. 2,
  110259. 10,
  110260. 1,
  110261. 11,
  110262. 0,
  110263. 12,
  110264. };
  110265. static long _vq_lengthlist__16c1_s_p9_0[] = {
  110266. 1, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  110267. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  110268. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  110269. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  110270. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  110271. 9, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  110272. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  110273. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  110274. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  110275. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  110276. 8, 8, 8, 8, 8, 8, 8, 8, 8,
  110277. };
  110278. static float _vq_quantthresh__16c1_s_p9_0[] = {
  110279. -1732.5, -1417.5, -1102.5, -787.5, -472.5, -157.5, 157.5, 472.5,
  110280. 787.5, 1102.5, 1417.5, 1732.5,
  110281. };
  110282. static long _vq_quantmap__16c1_s_p9_0[] = {
  110283. 11, 9, 7, 5, 3, 1, 0, 2,
  110284. 4, 6, 8, 10, 12,
  110285. };
  110286. static encode_aux_threshmatch _vq_auxt__16c1_s_p9_0 = {
  110287. _vq_quantthresh__16c1_s_p9_0,
  110288. _vq_quantmap__16c1_s_p9_0,
  110289. 13,
  110290. 13
  110291. };
  110292. static static_codebook _16c1_s_p9_0 = {
  110293. 2, 169,
  110294. _vq_lengthlist__16c1_s_p9_0,
  110295. 1, -513964032, 1628680192, 4, 0,
  110296. _vq_quantlist__16c1_s_p9_0,
  110297. NULL,
  110298. &_vq_auxt__16c1_s_p9_0,
  110299. NULL,
  110300. 0
  110301. };
  110302. static long _vq_quantlist__16c1_s_p9_1[] = {
  110303. 7,
  110304. 6,
  110305. 8,
  110306. 5,
  110307. 9,
  110308. 4,
  110309. 10,
  110310. 3,
  110311. 11,
  110312. 2,
  110313. 12,
  110314. 1,
  110315. 13,
  110316. 0,
  110317. 14,
  110318. };
  110319. static long _vq_lengthlist__16c1_s_p9_1[] = {
  110320. 1, 4, 4, 4, 4, 8, 8,12,13,14,14,14,14,14,14, 6,
  110321. 6, 6, 6, 6,10, 9,14,14,14,14,14,14,14,14, 7, 6,
  110322. 5, 6, 6,10, 9,12,13,13,13,13,13,13,13,13, 7, 7,
  110323. 9, 9,11,11,12,13,13,13,13,13,13,13,13, 7, 7, 8,
  110324. 8,11,12,13,13,13,13,13,13,13,13,13,12,12,10,10,
  110325. 13,12,13,13,13,13,13,13,13,13,13,12,12,10,10,13,
  110326. 13,13,13,13,13,13,13,13,13,13,13,13,13,12,13,12,
  110327. 13,13,13,13,13,13,13,13,13,13,13,13,12,13,13,13,
  110328. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  110329. 13,13,13,13,13,13,13,13,13,13,13,13,12,13,13,13,
  110330. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  110331. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  110332. 13,13,13,13,13,13,13,13,13,12,13,13,13,13,13,13,
  110333. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  110334. 13,
  110335. };
  110336. static float _vq_quantthresh__16c1_s_p9_1[] = {
  110337. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  110338. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  110339. };
  110340. static long _vq_quantmap__16c1_s_p9_1[] = {
  110341. 13, 11, 9, 7, 5, 3, 1, 0,
  110342. 2, 4, 6, 8, 10, 12, 14,
  110343. };
  110344. static encode_aux_threshmatch _vq_auxt__16c1_s_p9_1 = {
  110345. _vq_quantthresh__16c1_s_p9_1,
  110346. _vq_quantmap__16c1_s_p9_1,
  110347. 15,
  110348. 15
  110349. };
  110350. static static_codebook _16c1_s_p9_1 = {
  110351. 2, 225,
  110352. _vq_lengthlist__16c1_s_p9_1,
  110353. 1, -520986624, 1620377600, 4, 0,
  110354. _vq_quantlist__16c1_s_p9_1,
  110355. NULL,
  110356. &_vq_auxt__16c1_s_p9_1,
  110357. NULL,
  110358. 0
  110359. };
  110360. static long _vq_quantlist__16c1_s_p9_2[] = {
  110361. 10,
  110362. 9,
  110363. 11,
  110364. 8,
  110365. 12,
  110366. 7,
  110367. 13,
  110368. 6,
  110369. 14,
  110370. 5,
  110371. 15,
  110372. 4,
  110373. 16,
  110374. 3,
  110375. 17,
  110376. 2,
  110377. 18,
  110378. 1,
  110379. 19,
  110380. 0,
  110381. 20,
  110382. };
  110383. static long _vq_lengthlist__16c1_s_p9_2[] = {
  110384. 1, 4, 4, 6, 6, 7, 7, 8, 7, 8, 8, 9, 9, 9, 9,10,
  110385. 10,10, 9,10,10,11,12,12, 8, 8, 8, 8, 9, 9, 9, 9,
  110386. 10,10,10,10,10,11,11,10,12,11,11,13,11, 7, 7, 8,
  110387. 8, 8, 8, 9, 9, 9,10,10,10,10, 9,10,10,11,11,12,
  110388. 11,11, 8, 8, 8, 8, 9, 9,10,10,10,10,11,11,11,11,
  110389. 11,11,11,12,11,12,12, 8, 8, 9, 9, 9, 9, 9,10,10,
  110390. 10,10,10,10,11,11,11,11,11,11,12,11, 9, 9, 9, 9,
  110391. 10,10,10,10,11,10,11,11,11,11,11,11,12,12,12,12,
  110392. 11, 9, 9, 9, 9,10,10,10,10,11,11,11,11,11,11,11,
  110393. 11,11,12,12,12,13, 9,10,10, 9,11,10,10,10,10,11,
  110394. 11,11,11,11,10,11,12,11,12,12,11,12,11,10, 9,10,
  110395. 10,11,10,11,11,11,11,11,11,11,11,11,12,12,11,12,
  110396. 12,12,10,10,10,11,10,11,11,11,11,11,11,11,11,11,
  110397. 11,11,12,13,12,12,11, 9,10,10,11,11,10,11,11,11,
  110398. 12,11,11,11,11,11,12,12,13,13,12,13,10,10,12,10,
  110399. 11,11,11,11,11,11,11,11,11,12,12,11,13,12,12,12,
  110400. 12,13,12,11,11,11,11,11,11,12,11,12,11,11,11,11,
  110401. 12,12,13,12,11,12,12,11,11,11,11,11,12,11,11,11,
  110402. 11,12,11,11,12,11,12,13,13,12,12,12,12,11,11,11,
  110403. 11,11,12,11,11,12,11,12,11,11,11,11,13,12,12,12,
  110404. 12,13,11,11,11,12,12,11,11,11,12,11,12,12,12,11,
  110405. 12,13,12,11,11,12,12,11,12,11,11,11,12,12,11,12,
  110406. 11,11,11,12,12,12,12,13,12,13,12,12,12,12,11,11,
  110407. 12,11,11,11,11,11,11,12,12,12,13,12,11,13,13,12,
  110408. 12,11,12,10,11,11,11,11,12,11,12,12,11,12,12,13,
  110409. 12,12,13,12,12,12,12,12,11,12,12,12,11,12,11,11,
  110410. 11,12,13,12,13,13,13,13,13,12,13,13,12,12,13,11,
  110411. 11,11,11,11,12,11,11,12,11,
  110412. };
  110413. static float _vq_quantthresh__16c1_s_p9_2[] = {
  110414. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  110415. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  110416. 6.5, 7.5, 8.5, 9.5,
  110417. };
  110418. static long _vq_quantmap__16c1_s_p9_2[] = {
  110419. 19, 17, 15, 13, 11, 9, 7, 5,
  110420. 3, 1, 0, 2, 4, 6, 8, 10,
  110421. 12, 14, 16, 18, 20,
  110422. };
  110423. static encode_aux_threshmatch _vq_auxt__16c1_s_p9_2 = {
  110424. _vq_quantthresh__16c1_s_p9_2,
  110425. _vq_quantmap__16c1_s_p9_2,
  110426. 21,
  110427. 21
  110428. };
  110429. static static_codebook _16c1_s_p9_2 = {
  110430. 2, 441,
  110431. _vq_lengthlist__16c1_s_p9_2,
  110432. 1, -529268736, 1611661312, 5, 0,
  110433. _vq_quantlist__16c1_s_p9_2,
  110434. NULL,
  110435. &_vq_auxt__16c1_s_p9_2,
  110436. NULL,
  110437. 0
  110438. };
  110439. static long _huff_lengthlist__16c1_s_short[] = {
  110440. 5, 6,17, 8,12, 9,10,10,12,13, 5, 2,17, 4, 9, 5,
  110441. 7, 8,11,13,16,16,16,16,16,16,16,16,16,16, 6, 4,
  110442. 16, 5,10, 5, 7,10,14,16,13, 9,16,11, 8, 7, 8, 9,
  110443. 13,16, 7, 4,16, 5, 7, 4, 6, 8,11,13, 8, 6,16, 7,
  110444. 8, 5, 5, 7, 9,13, 9, 8,16, 9, 8, 6, 6, 7, 9,13,
  110445. 11,11,16,10,10, 7, 7, 7, 9,13,13,13,16,13,13, 9,
  110446. 9, 9,10,13,
  110447. };
  110448. static static_codebook _huff_book__16c1_s_short = {
  110449. 2, 100,
  110450. _huff_lengthlist__16c1_s_short,
  110451. 0, 0, 0, 0, 0,
  110452. NULL,
  110453. NULL,
  110454. NULL,
  110455. NULL,
  110456. 0
  110457. };
  110458. static long _huff_lengthlist__16c2_s_long[] = {
  110459. 4, 7, 9, 9, 9, 8, 9,10,15,19, 5, 4, 5, 6, 7, 7,
  110460. 8, 9,14,16, 6, 5, 4, 5, 6, 7, 8,10,12,19, 7, 6,
  110461. 5, 4, 5, 6, 7, 9,11,18, 8, 7, 6, 5, 5, 5, 7, 9,
  110462. 10,17, 8, 7, 7, 5, 5, 5, 6, 7,12,18, 8, 8, 8, 7,
  110463. 7, 5, 5, 7,12,18, 8, 9,10, 9, 9, 7, 6, 7,12,17,
  110464. 14,18,16,16,15,12,11,10,12,18,15,17,18,18,18,15,
  110465. 14,14,16,18,
  110466. };
  110467. static static_codebook _huff_book__16c2_s_long = {
  110468. 2, 100,
  110469. _huff_lengthlist__16c2_s_long,
  110470. 0, 0, 0, 0, 0,
  110471. NULL,
  110472. NULL,
  110473. NULL,
  110474. NULL,
  110475. 0
  110476. };
  110477. static long _vq_quantlist__16c2_s_p1_0[] = {
  110478. 1,
  110479. 0,
  110480. 2,
  110481. };
  110482. static long _vq_lengthlist__16c2_s_p1_0[] = {
  110483. 1, 3, 3, 0, 0, 0, 0, 0, 0, 4, 5, 5, 0, 0, 0, 0,
  110484. 0, 0, 4, 5, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110485. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110486. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110487. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110488. 0,
  110489. };
  110490. static float _vq_quantthresh__16c2_s_p1_0[] = {
  110491. -0.5, 0.5,
  110492. };
  110493. static long _vq_quantmap__16c2_s_p1_0[] = {
  110494. 1, 0, 2,
  110495. };
  110496. static encode_aux_threshmatch _vq_auxt__16c2_s_p1_0 = {
  110497. _vq_quantthresh__16c2_s_p1_0,
  110498. _vq_quantmap__16c2_s_p1_0,
  110499. 3,
  110500. 3
  110501. };
  110502. static static_codebook _16c2_s_p1_0 = {
  110503. 4, 81,
  110504. _vq_lengthlist__16c2_s_p1_0,
  110505. 1, -535822336, 1611661312, 2, 0,
  110506. _vq_quantlist__16c2_s_p1_0,
  110507. NULL,
  110508. &_vq_auxt__16c2_s_p1_0,
  110509. NULL,
  110510. 0
  110511. };
  110512. static long _vq_quantlist__16c2_s_p2_0[] = {
  110513. 2,
  110514. 1,
  110515. 3,
  110516. 0,
  110517. 4,
  110518. };
  110519. static long _vq_lengthlist__16c2_s_p2_0[] = {
  110520. 2, 4, 3, 7, 7, 0, 0, 0, 7, 8, 0, 0, 0, 8, 8, 0,
  110521. 0, 0, 8, 8, 0, 0, 0, 8, 8, 4, 5, 4, 8, 8, 0, 0,
  110522. 0, 8, 8, 0, 0, 0, 8, 8, 0, 0, 0, 9, 9, 0, 0, 0,
  110523. 9, 9, 4, 4, 5, 8, 8, 0, 0, 0, 8, 8, 0, 0, 0, 8,
  110524. 8, 0, 0, 0, 9, 9, 0, 0, 0, 9, 9, 7, 8, 8,10,10,
  110525. 0, 0, 0,12,11, 0, 0, 0,11,11, 0, 0, 0,14,13, 0,
  110526. 0, 0,14,13, 7, 8, 8, 9,10, 0, 0, 0,11,12, 0, 0,
  110527. 0,11,11, 0, 0, 0,14,14, 0, 0, 0,13,14, 0, 0, 0,
  110528. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110529. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110530. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110531. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110532. 0, 0, 0, 0, 0, 0, 0, 0, 8, 8, 8,11,11, 0, 0, 0,
  110533. 11,11, 0, 0, 0,12,11, 0, 0, 0,12,12, 0, 0, 0,13,
  110534. 13, 8, 8, 8,11,11, 0, 0, 0,11,11, 0, 0, 0,11,12,
  110535. 0, 0, 0,12,13, 0, 0, 0,13,13, 0, 0, 0, 0, 0, 0,
  110536. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110537. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110538. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110539. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110540. 0, 0, 0, 0, 0, 8, 8, 8,12,11, 0, 0, 0,12,11, 0,
  110541. 0, 0,11,11, 0, 0, 0,13,13, 0, 0, 0,13,12, 8, 8,
  110542. 8,11,12, 0, 0, 0,11,12, 0, 0, 0,11,11, 0, 0, 0,
  110543. 13,13, 0, 0, 0,12,13, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110544. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110545. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110546. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110547. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110548. 0, 0, 8, 9, 9,14,13, 0, 0, 0,13,12, 0, 0, 0,13,
  110549. 13, 0, 0, 0,13,12, 0, 0, 0,13,13, 8, 9, 9,13,14,
  110550. 0, 0, 0,12,13, 0, 0, 0,13,13, 0, 0, 0,12,13, 0,
  110551. 0, 0,13,13, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110552. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110553. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110554. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110555. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8,
  110556. 9, 9,14,13, 0, 0, 0,13,13, 0, 0, 0,13,12, 0, 0,
  110557. 0,13,13, 0, 0, 0,13,12, 8, 9, 9,14,14, 0, 0, 0,
  110558. 13,13, 0, 0, 0,12,13, 0, 0, 0,13,13, 0, 0, 0,12,
  110559. 13,
  110560. };
  110561. static float _vq_quantthresh__16c2_s_p2_0[] = {
  110562. -1.5, -0.5, 0.5, 1.5,
  110563. };
  110564. static long _vq_quantmap__16c2_s_p2_0[] = {
  110565. 3, 1, 0, 2, 4,
  110566. };
  110567. static encode_aux_threshmatch _vq_auxt__16c2_s_p2_0 = {
  110568. _vq_quantthresh__16c2_s_p2_0,
  110569. _vq_quantmap__16c2_s_p2_0,
  110570. 5,
  110571. 5
  110572. };
  110573. static static_codebook _16c2_s_p2_0 = {
  110574. 4, 625,
  110575. _vq_lengthlist__16c2_s_p2_0,
  110576. 1, -533725184, 1611661312, 3, 0,
  110577. _vq_quantlist__16c2_s_p2_0,
  110578. NULL,
  110579. &_vq_auxt__16c2_s_p2_0,
  110580. NULL,
  110581. 0
  110582. };
  110583. static long _vq_quantlist__16c2_s_p3_0[] = {
  110584. 4,
  110585. 3,
  110586. 5,
  110587. 2,
  110588. 6,
  110589. 1,
  110590. 7,
  110591. 0,
  110592. 8,
  110593. };
  110594. static long _vq_lengthlist__16c2_s_p3_0[] = {
  110595. 1, 3, 3, 6, 6, 7, 7, 8, 8, 0, 0, 0, 6, 6, 7, 7,
  110596. 9, 9, 0, 0, 0, 6, 6, 7, 7, 9, 9, 0, 0, 0, 7, 7,
  110597. 8, 8,10,10, 0, 0, 0, 7, 7, 8, 8,10,10, 0, 0, 0,
  110598. 7, 7, 9, 9,10,10, 0, 0, 0, 7, 7, 9, 9,10,10, 0,
  110599. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110600. 0,
  110601. };
  110602. static float _vq_quantthresh__16c2_s_p3_0[] = {
  110603. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  110604. };
  110605. static long _vq_quantmap__16c2_s_p3_0[] = {
  110606. 7, 5, 3, 1, 0, 2, 4, 6,
  110607. 8,
  110608. };
  110609. static encode_aux_threshmatch _vq_auxt__16c2_s_p3_0 = {
  110610. _vq_quantthresh__16c2_s_p3_0,
  110611. _vq_quantmap__16c2_s_p3_0,
  110612. 9,
  110613. 9
  110614. };
  110615. static static_codebook _16c2_s_p3_0 = {
  110616. 2, 81,
  110617. _vq_lengthlist__16c2_s_p3_0,
  110618. 1, -531628032, 1611661312, 4, 0,
  110619. _vq_quantlist__16c2_s_p3_0,
  110620. NULL,
  110621. &_vq_auxt__16c2_s_p3_0,
  110622. NULL,
  110623. 0
  110624. };
  110625. static long _vq_quantlist__16c2_s_p4_0[] = {
  110626. 8,
  110627. 7,
  110628. 9,
  110629. 6,
  110630. 10,
  110631. 5,
  110632. 11,
  110633. 4,
  110634. 12,
  110635. 3,
  110636. 13,
  110637. 2,
  110638. 14,
  110639. 1,
  110640. 15,
  110641. 0,
  110642. 16,
  110643. };
  110644. static long _vq_lengthlist__16c2_s_p4_0[] = {
  110645. 2, 3, 3, 5, 5, 6, 6, 7, 7, 7, 7, 8, 8, 9, 9,10,
  110646. 10, 0, 0, 0, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,10,
  110647. 11,11, 0, 0, 0, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,
  110648. 10,10,11, 0, 0, 0, 6, 6, 8, 8, 8, 8, 9, 9,10,10,
  110649. 10,11,11,11, 0, 0, 0, 6, 6, 8, 8, 9, 9, 9, 9,10,
  110650. 10,11,11,11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,
  110651. 10,10,11,11,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9,
  110652. 9,10,10,11,11,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9,
  110653. 10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 8, 8, 9,
  110654. 9,10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 0, 0,
  110655. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110656. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110657. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110658. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110659. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110660. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110661. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110662. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110663. 0,
  110664. };
  110665. static float _vq_quantthresh__16c2_s_p4_0[] = {
  110666. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  110667. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  110668. };
  110669. static long _vq_quantmap__16c2_s_p4_0[] = {
  110670. 15, 13, 11, 9, 7, 5, 3, 1,
  110671. 0, 2, 4, 6, 8, 10, 12, 14,
  110672. 16,
  110673. };
  110674. static encode_aux_threshmatch _vq_auxt__16c2_s_p4_0 = {
  110675. _vq_quantthresh__16c2_s_p4_0,
  110676. _vq_quantmap__16c2_s_p4_0,
  110677. 17,
  110678. 17
  110679. };
  110680. static static_codebook _16c2_s_p4_0 = {
  110681. 2, 289,
  110682. _vq_lengthlist__16c2_s_p4_0,
  110683. 1, -529530880, 1611661312, 5, 0,
  110684. _vq_quantlist__16c2_s_p4_0,
  110685. NULL,
  110686. &_vq_auxt__16c2_s_p4_0,
  110687. NULL,
  110688. 0
  110689. };
  110690. static long _vq_quantlist__16c2_s_p5_0[] = {
  110691. 1,
  110692. 0,
  110693. 2,
  110694. };
  110695. static long _vq_lengthlist__16c2_s_p5_0[] = {
  110696. 1, 4, 4, 5, 7, 7, 6, 7, 7, 4, 6, 6,10,10,10,10,
  110697. 10,10, 4, 7, 6,10,10,10,10,10,10, 5, 9, 9, 9,12,
  110698. 11,10,11,12, 7,10,10,12,12,12,12,12,12, 7,10,10,
  110699. 11,12,12,12,12,13, 6,10,10,10,12,12,10,12,12, 7,
  110700. 10,10,11,13,12,12,12,12, 7,10,10,11,12,12,12,12,
  110701. 12,
  110702. };
  110703. static float _vq_quantthresh__16c2_s_p5_0[] = {
  110704. -5.5, 5.5,
  110705. };
  110706. static long _vq_quantmap__16c2_s_p5_0[] = {
  110707. 1, 0, 2,
  110708. };
  110709. static encode_aux_threshmatch _vq_auxt__16c2_s_p5_0 = {
  110710. _vq_quantthresh__16c2_s_p5_0,
  110711. _vq_quantmap__16c2_s_p5_0,
  110712. 3,
  110713. 3
  110714. };
  110715. static static_codebook _16c2_s_p5_0 = {
  110716. 4, 81,
  110717. _vq_lengthlist__16c2_s_p5_0,
  110718. 1, -529137664, 1618345984, 2, 0,
  110719. _vq_quantlist__16c2_s_p5_0,
  110720. NULL,
  110721. &_vq_auxt__16c2_s_p5_0,
  110722. NULL,
  110723. 0
  110724. };
  110725. static long _vq_quantlist__16c2_s_p5_1[] = {
  110726. 5,
  110727. 4,
  110728. 6,
  110729. 3,
  110730. 7,
  110731. 2,
  110732. 8,
  110733. 1,
  110734. 9,
  110735. 0,
  110736. 10,
  110737. };
  110738. static long _vq_lengthlist__16c2_s_p5_1[] = {
  110739. 2, 3, 3, 6, 6, 7, 7, 7, 7, 8, 8,11,11,11, 6, 6,
  110740. 7, 7, 8, 8, 8, 8,11,11,11, 6, 6, 7, 7, 8, 8, 8,
  110741. 8,11,11,11, 6, 6, 8, 8, 8, 8, 9, 9,11,11,11, 6,
  110742. 6, 8, 8, 8, 8, 9, 9,11,11,11, 7, 7, 8, 8, 8, 8,
  110743. 8, 8,11,11,11, 7, 7, 8, 8, 8, 8, 8, 9,11,11,11,
  110744. 8, 8, 8, 8, 8, 8, 8, 8,11,11,11,11,11, 8, 8, 8,
  110745. 8, 8, 8,11,11,11,11,11, 8, 8, 8, 8, 8, 8,11,11,
  110746. 11,11,11, 7, 7, 8, 8, 8, 8,
  110747. };
  110748. static float _vq_quantthresh__16c2_s_p5_1[] = {
  110749. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  110750. 3.5, 4.5,
  110751. };
  110752. static long _vq_quantmap__16c2_s_p5_1[] = {
  110753. 9, 7, 5, 3, 1, 0, 2, 4,
  110754. 6, 8, 10,
  110755. };
  110756. static encode_aux_threshmatch _vq_auxt__16c2_s_p5_1 = {
  110757. _vq_quantthresh__16c2_s_p5_1,
  110758. _vq_quantmap__16c2_s_p5_1,
  110759. 11,
  110760. 11
  110761. };
  110762. static static_codebook _16c2_s_p5_1 = {
  110763. 2, 121,
  110764. _vq_lengthlist__16c2_s_p5_1,
  110765. 1, -531365888, 1611661312, 4, 0,
  110766. _vq_quantlist__16c2_s_p5_1,
  110767. NULL,
  110768. &_vq_auxt__16c2_s_p5_1,
  110769. NULL,
  110770. 0
  110771. };
  110772. static long _vq_quantlist__16c2_s_p6_0[] = {
  110773. 6,
  110774. 5,
  110775. 7,
  110776. 4,
  110777. 8,
  110778. 3,
  110779. 9,
  110780. 2,
  110781. 10,
  110782. 1,
  110783. 11,
  110784. 0,
  110785. 12,
  110786. };
  110787. static long _vq_lengthlist__16c2_s_p6_0[] = {
  110788. 1, 4, 4, 7, 6, 8, 8, 9, 9,10,10,11,11, 5, 5, 5,
  110789. 7, 7, 9, 9, 9, 9,11,11,12,12, 6, 5, 5, 7, 7, 9,
  110790. 9,10,10,11,11,12,12, 0, 6, 6, 7, 7, 9, 9,10,10,
  110791. 11,11,12,12, 0, 7, 7, 7, 7, 9, 9,10,10,11,12,12,
  110792. 12, 0,11,11, 8, 8,10,10,11,11,12,12,13,13, 0,11,
  110793. 12, 8, 8,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0,
  110794. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110795. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110796. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110797. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110798. 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110799. };
  110800. static float _vq_quantthresh__16c2_s_p6_0[] = {
  110801. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  110802. 12.5, 17.5, 22.5, 27.5,
  110803. };
  110804. static long _vq_quantmap__16c2_s_p6_0[] = {
  110805. 11, 9, 7, 5, 3, 1, 0, 2,
  110806. 4, 6, 8, 10, 12,
  110807. };
  110808. static encode_aux_threshmatch _vq_auxt__16c2_s_p6_0 = {
  110809. _vq_quantthresh__16c2_s_p6_0,
  110810. _vq_quantmap__16c2_s_p6_0,
  110811. 13,
  110812. 13
  110813. };
  110814. static static_codebook _16c2_s_p6_0 = {
  110815. 2, 169,
  110816. _vq_lengthlist__16c2_s_p6_0,
  110817. 1, -526516224, 1616117760, 4, 0,
  110818. _vq_quantlist__16c2_s_p6_0,
  110819. NULL,
  110820. &_vq_auxt__16c2_s_p6_0,
  110821. NULL,
  110822. 0
  110823. };
  110824. static long _vq_quantlist__16c2_s_p6_1[] = {
  110825. 2,
  110826. 1,
  110827. 3,
  110828. 0,
  110829. 4,
  110830. };
  110831. static long _vq_lengthlist__16c2_s_p6_1[] = {
  110832. 2, 3, 3, 5, 5, 6, 6, 6, 5, 5, 6, 6, 6, 5, 5, 6,
  110833. 6, 6, 5, 5, 6, 6, 6, 5, 5,
  110834. };
  110835. static float _vq_quantthresh__16c2_s_p6_1[] = {
  110836. -1.5, -0.5, 0.5, 1.5,
  110837. };
  110838. static long _vq_quantmap__16c2_s_p6_1[] = {
  110839. 3, 1, 0, 2, 4,
  110840. };
  110841. static encode_aux_threshmatch _vq_auxt__16c2_s_p6_1 = {
  110842. _vq_quantthresh__16c2_s_p6_1,
  110843. _vq_quantmap__16c2_s_p6_1,
  110844. 5,
  110845. 5
  110846. };
  110847. static static_codebook _16c2_s_p6_1 = {
  110848. 2, 25,
  110849. _vq_lengthlist__16c2_s_p6_1,
  110850. 1, -533725184, 1611661312, 3, 0,
  110851. _vq_quantlist__16c2_s_p6_1,
  110852. NULL,
  110853. &_vq_auxt__16c2_s_p6_1,
  110854. NULL,
  110855. 0
  110856. };
  110857. static long _vq_quantlist__16c2_s_p7_0[] = {
  110858. 6,
  110859. 5,
  110860. 7,
  110861. 4,
  110862. 8,
  110863. 3,
  110864. 9,
  110865. 2,
  110866. 10,
  110867. 1,
  110868. 11,
  110869. 0,
  110870. 12,
  110871. };
  110872. static long _vq_lengthlist__16c2_s_p7_0[] = {
  110873. 1, 4, 4, 7, 7, 8, 8, 9, 9,10,10,11,11, 5, 5, 5,
  110874. 8, 8, 9, 9,10,10,11,11,12,12, 6, 5, 5, 8, 8, 9,
  110875. 9,10,10,11,11,12,13,18, 6, 6, 7, 7, 9, 9,10,10,
  110876. 12,12,13,13,18, 6, 6, 7, 7, 9, 9,10,10,12,12,13,
  110877. 13,18,11,10, 8, 8,10,10,11,11,12,12,13,13,18,11,
  110878. 11, 8, 8,10,10,11,11,12,13,13,13,18,18,18,10,11,
  110879. 11,11,12,12,13,13,14,14,18,18,18,11,11,11,11,12,
  110880. 12,13,13,14,14,18,18,18,14,14,12,12,12,12,14,14,
  110881. 15,14,18,18,18,15,15,11,12,12,12,13,13,15,15,18,
  110882. 18,18,18,18,13,13,13,13,13,14,17,16,18,18,18,18,
  110883. 18,13,14,13,13,14,13,15,14,
  110884. };
  110885. static float _vq_quantthresh__16c2_s_p7_0[] = {
  110886. -60.5, -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5,
  110887. 27.5, 38.5, 49.5, 60.5,
  110888. };
  110889. static long _vq_quantmap__16c2_s_p7_0[] = {
  110890. 11, 9, 7, 5, 3, 1, 0, 2,
  110891. 4, 6, 8, 10, 12,
  110892. };
  110893. static encode_aux_threshmatch _vq_auxt__16c2_s_p7_0 = {
  110894. _vq_quantthresh__16c2_s_p7_0,
  110895. _vq_quantmap__16c2_s_p7_0,
  110896. 13,
  110897. 13
  110898. };
  110899. static static_codebook _16c2_s_p7_0 = {
  110900. 2, 169,
  110901. _vq_lengthlist__16c2_s_p7_0,
  110902. 1, -523206656, 1618345984, 4, 0,
  110903. _vq_quantlist__16c2_s_p7_0,
  110904. NULL,
  110905. &_vq_auxt__16c2_s_p7_0,
  110906. NULL,
  110907. 0
  110908. };
  110909. static long _vq_quantlist__16c2_s_p7_1[] = {
  110910. 5,
  110911. 4,
  110912. 6,
  110913. 3,
  110914. 7,
  110915. 2,
  110916. 8,
  110917. 1,
  110918. 9,
  110919. 0,
  110920. 10,
  110921. };
  110922. static long _vq_lengthlist__16c2_s_p7_1[] = {
  110923. 2, 4, 4, 6, 6, 7, 7, 7, 7, 7, 7, 9, 9, 9, 6, 6,
  110924. 7, 7, 8, 8, 8, 8, 9, 9, 9, 6, 6, 7, 7, 8, 8, 8,
  110925. 8, 9, 9, 9, 7, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 7,
  110926. 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 7, 7, 7, 7, 8, 8,
  110927. 8, 8, 9, 9, 9, 7, 7, 7, 7, 7, 7, 8, 8, 9, 9, 9,
  110928. 7, 7, 8, 8, 7, 7, 8, 8, 9, 9, 9, 9, 9, 7, 7, 7,
  110929. 7, 8, 8, 9, 9, 9, 9, 9, 8, 8, 7, 7, 8, 8, 9, 9,
  110930. 9, 9, 9, 7, 7, 7, 7, 8, 8,
  110931. };
  110932. static float _vq_quantthresh__16c2_s_p7_1[] = {
  110933. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  110934. 3.5, 4.5,
  110935. };
  110936. static long _vq_quantmap__16c2_s_p7_1[] = {
  110937. 9, 7, 5, 3, 1, 0, 2, 4,
  110938. 6, 8, 10,
  110939. };
  110940. static encode_aux_threshmatch _vq_auxt__16c2_s_p7_1 = {
  110941. _vq_quantthresh__16c2_s_p7_1,
  110942. _vq_quantmap__16c2_s_p7_1,
  110943. 11,
  110944. 11
  110945. };
  110946. static static_codebook _16c2_s_p7_1 = {
  110947. 2, 121,
  110948. _vq_lengthlist__16c2_s_p7_1,
  110949. 1, -531365888, 1611661312, 4, 0,
  110950. _vq_quantlist__16c2_s_p7_1,
  110951. NULL,
  110952. &_vq_auxt__16c2_s_p7_1,
  110953. NULL,
  110954. 0
  110955. };
  110956. static long _vq_quantlist__16c2_s_p8_0[] = {
  110957. 7,
  110958. 6,
  110959. 8,
  110960. 5,
  110961. 9,
  110962. 4,
  110963. 10,
  110964. 3,
  110965. 11,
  110966. 2,
  110967. 12,
  110968. 1,
  110969. 13,
  110970. 0,
  110971. 14,
  110972. };
  110973. static long _vq_lengthlist__16c2_s_p8_0[] = {
  110974. 1, 4, 4, 7, 6, 7, 7, 6, 6, 8, 8, 9, 9,10,10, 6,
  110975. 6, 6, 8, 8, 9, 8, 8, 8, 9, 9,11,10,11,11, 7, 6,
  110976. 6, 8, 8, 9, 8, 7, 7, 9, 9,10,10,12,11,14, 8, 8,
  110977. 8, 9, 9, 9, 9, 9,10, 9,10,10,11,13,14, 8, 8, 8,
  110978. 8, 9, 9, 8, 8, 9, 9,10,10,11,12,14,13,11, 9, 9,
  110979. 9, 9, 9, 9, 9,10,11,10,13,12,14,11,13, 8, 9, 9,
  110980. 9, 9, 9,10,10,11,10,13,12,14,14,14, 8, 9, 9, 9,
  110981. 11,11,11,11,11,12,13,13,14,14,14, 9, 8, 9, 9,10,
  110982. 10,12,10,11,12,12,14,14,14,14,11,12,10,10,12,12,
  110983. 12,12,13,14,12,12,14,14,14,12,12, 9,10,11,11,12,
  110984. 14,12,14,14,14,14,14,14,14,14,11,11,12,11,12,14,
  110985. 14,14,14,14,14,14,14,14,14,12,11,11,11,11,14,14,
  110986. 14,14,14,14,14,14,14,14,14,14,13,12,14,14,14,14,
  110987. 14,14,14,14,14,14,14,14,14,12,12,12,13,14,14,13,
  110988. 13,
  110989. };
  110990. static float _vq_quantthresh__16c2_s_p8_0[] = {
  110991. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  110992. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  110993. };
  110994. static long _vq_quantmap__16c2_s_p8_0[] = {
  110995. 13, 11, 9, 7, 5, 3, 1, 0,
  110996. 2, 4, 6, 8, 10, 12, 14,
  110997. };
  110998. static encode_aux_threshmatch _vq_auxt__16c2_s_p8_0 = {
  110999. _vq_quantthresh__16c2_s_p8_0,
  111000. _vq_quantmap__16c2_s_p8_0,
  111001. 15,
  111002. 15
  111003. };
  111004. static static_codebook _16c2_s_p8_0 = {
  111005. 2, 225,
  111006. _vq_lengthlist__16c2_s_p8_0,
  111007. 1, -520986624, 1620377600, 4, 0,
  111008. _vq_quantlist__16c2_s_p8_0,
  111009. NULL,
  111010. &_vq_auxt__16c2_s_p8_0,
  111011. NULL,
  111012. 0
  111013. };
  111014. static long _vq_quantlist__16c2_s_p8_1[] = {
  111015. 10,
  111016. 9,
  111017. 11,
  111018. 8,
  111019. 12,
  111020. 7,
  111021. 13,
  111022. 6,
  111023. 14,
  111024. 5,
  111025. 15,
  111026. 4,
  111027. 16,
  111028. 3,
  111029. 17,
  111030. 2,
  111031. 18,
  111032. 1,
  111033. 19,
  111034. 0,
  111035. 20,
  111036. };
  111037. static long _vq_lengthlist__16c2_s_p8_1[] = {
  111038. 2, 4, 4, 6, 6, 7, 7, 7, 7, 8, 7, 8, 8, 8, 8, 8,
  111039. 8, 8, 8, 8, 8,11,12,11, 7, 7, 8, 8, 8, 8, 9, 9,
  111040. 9, 9, 9, 9, 9, 9, 9,10, 9, 9,11,11,10, 7, 7, 8,
  111041. 8, 8, 8, 9, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,11,
  111042. 11,11, 8, 7, 8, 8, 9, 9, 9, 9, 9, 9,10,10, 9,10,
  111043. 10, 9,10,10,11,11,12, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  111044. 9, 9, 9,10, 9,10,10,10,10,11,11,11, 8, 8, 9, 9,
  111045. 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,11,11,
  111046. 11, 8, 8, 9, 8, 9, 9, 9, 9,10, 9, 9, 9,10,10,10,
  111047. 10, 9,10,11,11,11, 9, 9, 9, 9,10, 9, 9, 9,10,10,
  111048. 9,10, 9,10,10,10,10,10,11,12,11,11,11, 9, 9, 9,
  111049. 9, 9,10,10, 9,10,10,10,10,10,10,10,10,12,11,13,
  111050. 13,11, 9, 9, 9, 9,10,10, 9,10,10,10,10,11,10,10,
  111051. 10,10,11,12,11,12,11, 9, 9, 9,10,10, 9,10,10,10,
  111052. 10,10,10,10,10,10,10,11,11,11,12,11, 9,10,10,10,
  111053. 10,10,10,10,10,10,10,10,10,10,10,10,11,12,12,12,
  111054. 11,11,11,10, 9,10,10,10,10,10,10,10,10,11,10,10,
  111055. 10,11,11,11,11,11,11,11,10,10,10,11,10,10,10,10,
  111056. 10,10,10,10,10,10,11,11,11,11,12,12,11,10,10,10,
  111057. 10,10,10,10,10,11,10,10,10,11,10,12,11,11,12,11,
  111058. 11,11,10,10,10,10,10,11,10,10,10,10,10,11,10,10,
  111059. 11,11,11,12,11,12,11,11,12,10,10,10,10,10,10,10,
  111060. 11,10,10,11,10,12,11,11,11,12,11,11,11,11,10,10,
  111061. 10,10,10,10,10,11,11,11,10,11,12,11,11,11,12,11,
  111062. 12,11,12,10,11,10,10,10,10,11,10,10,10,10,10,10,
  111063. 12,11,11,11,11,11,12,12,10,10,10,10,10,11,10,10,
  111064. 11,10,11,11,11,11,11,11,11,11,11,11,11,11,12,11,
  111065. 10,11,10,10,10,10,10,10,10,
  111066. };
  111067. static float _vq_quantthresh__16c2_s_p8_1[] = {
  111068. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  111069. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  111070. 6.5, 7.5, 8.5, 9.5,
  111071. };
  111072. static long _vq_quantmap__16c2_s_p8_1[] = {
  111073. 19, 17, 15, 13, 11, 9, 7, 5,
  111074. 3, 1, 0, 2, 4, 6, 8, 10,
  111075. 12, 14, 16, 18, 20,
  111076. };
  111077. static encode_aux_threshmatch _vq_auxt__16c2_s_p8_1 = {
  111078. _vq_quantthresh__16c2_s_p8_1,
  111079. _vq_quantmap__16c2_s_p8_1,
  111080. 21,
  111081. 21
  111082. };
  111083. static static_codebook _16c2_s_p8_1 = {
  111084. 2, 441,
  111085. _vq_lengthlist__16c2_s_p8_1,
  111086. 1, -529268736, 1611661312, 5, 0,
  111087. _vq_quantlist__16c2_s_p8_1,
  111088. NULL,
  111089. &_vq_auxt__16c2_s_p8_1,
  111090. NULL,
  111091. 0
  111092. };
  111093. static long _vq_quantlist__16c2_s_p9_0[] = {
  111094. 6,
  111095. 5,
  111096. 7,
  111097. 4,
  111098. 8,
  111099. 3,
  111100. 9,
  111101. 2,
  111102. 10,
  111103. 1,
  111104. 11,
  111105. 0,
  111106. 12,
  111107. };
  111108. static long _vq_lengthlist__16c2_s_p9_0[] = {
  111109. 1, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  111110. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  111111. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  111112. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  111113. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  111114. 9, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  111115. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  111116. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  111117. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  111118. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  111119. 8, 8, 8, 8, 8, 8, 8, 8, 8,
  111120. };
  111121. static float _vq_quantthresh__16c2_s_p9_0[] = {
  111122. -5120.5, -4189.5, -3258.5, -2327.5, -1396.5, -465.5, 465.5, 1396.5,
  111123. 2327.5, 3258.5, 4189.5, 5120.5,
  111124. };
  111125. static long _vq_quantmap__16c2_s_p9_0[] = {
  111126. 11, 9, 7, 5, 3, 1, 0, 2,
  111127. 4, 6, 8, 10, 12,
  111128. };
  111129. static encode_aux_threshmatch _vq_auxt__16c2_s_p9_0 = {
  111130. _vq_quantthresh__16c2_s_p9_0,
  111131. _vq_quantmap__16c2_s_p9_0,
  111132. 13,
  111133. 13
  111134. };
  111135. static static_codebook _16c2_s_p9_0 = {
  111136. 2, 169,
  111137. _vq_lengthlist__16c2_s_p9_0,
  111138. 1, -510275072, 1631393792, 4, 0,
  111139. _vq_quantlist__16c2_s_p9_0,
  111140. NULL,
  111141. &_vq_auxt__16c2_s_p9_0,
  111142. NULL,
  111143. 0
  111144. };
  111145. static long _vq_quantlist__16c2_s_p9_1[] = {
  111146. 8,
  111147. 7,
  111148. 9,
  111149. 6,
  111150. 10,
  111151. 5,
  111152. 11,
  111153. 4,
  111154. 12,
  111155. 3,
  111156. 13,
  111157. 2,
  111158. 14,
  111159. 1,
  111160. 15,
  111161. 0,
  111162. 16,
  111163. };
  111164. static long _vq_lengthlist__16c2_s_p9_1[] = {
  111165. 1, 5, 5, 9, 8, 7, 7, 7, 6,10,11,11,11,11,11,11,
  111166. 11, 8, 7, 6, 8, 8,10, 9,10,10,10, 9,11,10,10,10,
  111167. 10,10, 8, 6, 6, 8, 8, 9, 8, 9, 8, 9,10,10,10,10,
  111168. 10,10,10,10, 8,10, 9, 9, 9, 9,10,10,10,10,10,10,
  111169. 10,10,10,10,10, 8, 9, 9, 9,10,10, 9,10,10,10,10,
  111170. 10,10,10,10,10,10,10,10, 9, 8, 9, 9,10,10,10,10,
  111171. 10,10,10,10,10,10,10,10, 9, 8, 8, 9, 9,10,10,10,
  111172. 10,10,10,10,10,10,10,10,10,10, 9,10, 9, 9,10,10,
  111173. 10,10,10,10,10,10,10,10,10,10,10, 9, 8, 9, 9,10,
  111174. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10, 9,
  111175. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  111176. 8,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  111177. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  111178. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  111179. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  111180. 10,10,10,10, 9,10, 9,10,10,10,10,10,10,10,10,10,
  111181. 10,10,10,10,10,10,10,10,10, 9,10,10,10,10,10,10,
  111182. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  111183. 10,
  111184. };
  111185. static float _vq_quantthresh__16c2_s_p9_1[] = {
  111186. -367.5, -318.5, -269.5, -220.5, -171.5, -122.5, -73.5, -24.5,
  111187. 24.5, 73.5, 122.5, 171.5, 220.5, 269.5, 318.5, 367.5,
  111188. };
  111189. static long _vq_quantmap__16c2_s_p9_1[] = {
  111190. 15, 13, 11, 9, 7, 5, 3, 1,
  111191. 0, 2, 4, 6, 8, 10, 12, 14,
  111192. 16,
  111193. };
  111194. static encode_aux_threshmatch _vq_auxt__16c2_s_p9_1 = {
  111195. _vq_quantthresh__16c2_s_p9_1,
  111196. _vq_quantmap__16c2_s_p9_1,
  111197. 17,
  111198. 17
  111199. };
  111200. static static_codebook _16c2_s_p9_1 = {
  111201. 2, 289,
  111202. _vq_lengthlist__16c2_s_p9_1,
  111203. 1, -518488064, 1622704128, 5, 0,
  111204. _vq_quantlist__16c2_s_p9_1,
  111205. NULL,
  111206. &_vq_auxt__16c2_s_p9_1,
  111207. NULL,
  111208. 0
  111209. };
  111210. static long _vq_quantlist__16c2_s_p9_2[] = {
  111211. 13,
  111212. 12,
  111213. 14,
  111214. 11,
  111215. 15,
  111216. 10,
  111217. 16,
  111218. 9,
  111219. 17,
  111220. 8,
  111221. 18,
  111222. 7,
  111223. 19,
  111224. 6,
  111225. 20,
  111226. 5,
  111227. 21,
  111228. 4,
  111229. 22,
  111230. 3,
  111231. 23,
  111232. 2,
  111233. 24,
  111234. 1,
  111235. 25,
  111236. 0,
  111237. 26,
  111238. };
  111239. static long _vq_lengthlist__16c2_s_p9_2[] = {
  111240. 1, 4, 4, 5, 5, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7,
  111241. 7, 7, 7, 7, 8, 7, 8, 7, 7, 4, 4,
  111242. };
  111243. static float _vq_quantthresh__16c2_s_p9_2[] = {
  111244. -12.5, -11.5, -10.5, -9.5, -8.5, -7.5, -6.5, -5.5,
  111245. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  111246. 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5, 10.5,
  111247. 11.5, 12.5,
  111248. };
  111249. static long _vq_quantmap__16c2_s_p9_2[] = {
  111250. 25, 23, 21, 19, 17, 15, 13, 11,
  111251. 9, 7, 5, 3, 1, 0, 2, 4,
  111252. 6, 8, 10, 12, 14, 16, 18, 20,
  111253. 22, 24, 26,
  111254. };
  111255. static encode_aux_threshmatch _vq_auxt__16c2_s_p9_2 = {
  111256. _vq_quantthresh__16c2_s_p9_2,
  111257. _vq_quantmap__16c2_s_p9_2,
  111258. 27,
  111259. 27
  111260. };
  111261. static static_codebook _16c2_s_p9_2 = {
  111262. 1, 27,
  111263. _vq_lengthlist__16c2_s_p9_2,
  111264. 1, -528875520, 1611661312, 5, 0,
  111265. _vq_quantlist__16c2_s_p9_2,
  111266. NULL,
  111267. &_vq_auxt__16c2_s_p9_2,
  111268. NULL,
  111269. 0
  111270. };
  111271. static long _huff_lengthlist__16c2_s_short[] = {
  111272. 7,10,11,11,11,14,15,15,17,14, 8, 6, 7, 7, 8, 9,
  111273. 11,11,14,17, 9, 6, 6, 6, 7, 7,10,11,15,16, 9, 6,
  111274. 6, 4, 4, 5, 8, 9,12,16,10, 6, 6, 4, 4, 4, 6, 9,
  111275. 13,16,10, 7, 6, 5, 4, 3, 5, 7,13,16,11, 9, 8, 7,
  111276. 6, 5, 5, 6,12,15,10,10,10, 9, 7, 6, 6, 7,11,15,
  111277. 13,13,13,13,11,10,10, 9,12,16,16,16,16,14,16,15,
  111278. 15,12,14,14,
  111279. };
  111280. static static_codebook _huff_book__16c2_s_short = {
  111281. 2, 100,
  111282. _huff_lengthlist__16c2_s_short,
  111283. 0, 0, 0, 0, 0,
  111284. NULL,
  111285. NULL,
  111286. NULL,
  111287. NULL,
  111288. 0
  111289. };
  111290. static long _vq_quantlist__8c0_s_p1_0[] = {
  111291. 1,
  111292. 0,
  111293. 2,
  111294. };
  111295. static long _vq_lengthlist__8c0_s_p1_0[] = {
  111296. 1, 5, 4, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0,
  111297. 0, 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111298. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111299. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111300. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111301. 0, 5, 8, 8, 0, 0, 0, 0, 0, 0, 7, 8, 9, 0, 0, 0,
  111302. 0, 0, 0, 7, 8, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111303. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111304. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111305. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111306. 0, 0, 5, 8, 8, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  111307. 0, 0, 0, 0, 7, 9, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111308. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111309. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111310. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111311. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111312. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111313. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111314. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111315. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111316. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111317. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111318. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111319. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111320. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111321. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111322. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111323. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111324. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111325. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111326. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111327. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111328. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111329. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111330. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111331. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111332. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111333. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111334. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111335. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111336. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111337. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111338. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111339. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111340. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111341. 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 8, 8, 0, 0, 0, 0,
  111342. 0, 0, 8,10,10, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0, 0,
  111343. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111344. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111345. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111346. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7,10, 9, 0, 0, 0,
  111347. 0, 0, 0, 8, 9,11, 0, 0, 0, 0, 0, 0, 9,11,11, 0,
  111348. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111349. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111350. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111351. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 9,10, 0, 0,
  111352. 0, 0, 0, 0, 9,11,10, 0, 0, 0, 0, 0, 0, 9,11,11,
  111353. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111354. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111355. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111356. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111357. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111358. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111359. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111360. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111361. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111362. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111363. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111364. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111365. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111366. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111367. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111368. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111369. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111370. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111371. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111372. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111373. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111374. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111375. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111376. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111377. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111378. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111379. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111380. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111381. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111382. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111383. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111384. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111385. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111386. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111387. 0, 0, 5, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0, 0,
  111388. 0, 0, 0, 0, 8, 9,10, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111389. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111390. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111391. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111392. 0, 0, 0, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,11,11, 0,
  111393. 0, 0, 0, 0, 0, 9,10,11, 0, 0, 0, 0, 0, 0, 0, 0,
  111394. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111395. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111396. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111397. 0, 0, 0, 0, 7, 9,10, 0, 0, 0, 0, 0, 0, 9,11,11,
  111398. 0, 0, 0, 0, 0, 0, 8,11, 9, 0, 0, 0, 0, 0, 0, 0,
  111399. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111400. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111401. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111402. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111403. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111404. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111405. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111406. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111407. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111408. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111409. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111410. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111411. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111412. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111413. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111414. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111415. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111416. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111417. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111418. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111419. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111420. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111421. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111422. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111423. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111424. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111425. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111426. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111427. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111428. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111429. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111430. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111431. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111432. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111433. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111434. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111435. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111436. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111437. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111438. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111439. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111440. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111441. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111442. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111443. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111444. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111445. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111446. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111447. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111448. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111449. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111450. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111451. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111452. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111453. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111454. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111455. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111456. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111457. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111458. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111459. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111460. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111461. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111462. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111463. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111464. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111465. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111466. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111467. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111468. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111469. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111470. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111471. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111472. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111473. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111474. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111475. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111476. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111477. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111478. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111479. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111480. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111481. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111482. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111483. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111484. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111485. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111486. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111487. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111488. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111489. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111490. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111491. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111492. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111493. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111494. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111495. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111496. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111497. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111498. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111499. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111500. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111501. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111502. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111503. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111504. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111505. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111506. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111507. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111508. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111509. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111510. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111511. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111512. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111513. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111514. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111515. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111516. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111517. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111518. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111519. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111520. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111521. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111522. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111523. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111524. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111525. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111526. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111527. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111528. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111529. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111530. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111531. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111532. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111533. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111534. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111535. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111536. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111537. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111538. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111539. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111540. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111541. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111542. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111543. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111544. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111545. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111546. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111547. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111548. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111549. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111550. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111551. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111552. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111553. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111554. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111555. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111556. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111557. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111558. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111559. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111560. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111561. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111562. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111563. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111564. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111565. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111566. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111567. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111568. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111569. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111570. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111571. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111572. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111573. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111574. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111575. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111576. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111577. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111578. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111579. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111580. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111581. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111582. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111583. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111584. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111585. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111586. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111587. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111588. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111589. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111590. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111591. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111592. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111593. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111594. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111595. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111596. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111597. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111598. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111599. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111600. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111601. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111602. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111603. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111604. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111605. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111606. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111607. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111608. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111609. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111610. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111611. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111612. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111613. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111614. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111615. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111616. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111617. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111618. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111619. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111620. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111621. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111622. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111623. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111624. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111625. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111626. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111627. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111628. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111629. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111630. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111631. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111632. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111633. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111634. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111635. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111636. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111637. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111638. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111639. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111640. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111641. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111642. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111643. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111644. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111645. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111646. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111647. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111648. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111649. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111650. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111651. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111652. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111653. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111654. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111655. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111656. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111657. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111658. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111659. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111660. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111661. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111662. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111663. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111664. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111665. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111666. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111667. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111668. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111669. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111670. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111671. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111672. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111673. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111674. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111675. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111676. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111677. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111678. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111679. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111680. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111681. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111682. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111683. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111684. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111685. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111686. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111687. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111688. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111689. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111690. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111691. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111692. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111693. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111694. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111695. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111696. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111697. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111698. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111699. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111700. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111701. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111702. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111703. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111704. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111705. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111706. 0,
  111707. };
  111708. static float _vq_quantthresh__8c0_s_p1_0[] = {
  111709. -0.5, 0.5,
  111710. };
  111711. static long _vq_quantmap__8c0_s_p1_0[] = {
  111712. 1, 0, 2,
  111713. };
  111714. static encode_aux_threshmatch _vq_auxt__8c0_s_p1_0 = {
  111715. _vq_quantthresh__8c0_s_p1_0,
  111716. _vq_quantmap__8c0_s_p1_0,
  111717. 3,
  111718. 3
  111719. };
  111720. static static_codebook _8c0_s_p1_0 = {
  111721. 8, 6561,
  111722. _vq_lengthlist__8c0_s_p1_0,
  111723. 1, -535822336, 1611661312, 2, 0,
  111724. _vq_quantlist__8c0_s_p1_0,
  111725. NULL,
  111726. &_vq_auxt__8c0_s_p1_0,
  111727. NULL,
  111728. 0
  111729. };
  111730. static long _vq_quantlist__8c0_s_p2_0[] = {
  111731. 2,
  111732. 1,
  111733. 3,
  111734. 0,
  111735. 4,
  111736. };
  111737. static long _vq_lengthlist__8c0_s_p2_0[] = {
  111738. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111739. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111740. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111741. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111742. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111743. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111744. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111745. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111746. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111747. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111748. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111749. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111750. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111751. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111752. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111753. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111754. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111755. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111756. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111757. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111758. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111759. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111760. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111761. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111762. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111763. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111764. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111765. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111766. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111767. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111768. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111769. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111770. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111771. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111772. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111773. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111774. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111775. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111776. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111777. 0,
  111778. };
  111779. static float _vq_quantthresh__8c0_s_p2_0[] = {
  111780. -1.5, -0.5, 0.5, 1.5,
  111781. };
  111782. static long _vq_quantmap__8c0_s_p2_0[] = {
  111783. 3, 1, 0, 2, 4,
  111784. };
  111785. static encode_aux_threshmatch _vq_auxt__8c0_s_p2_0 = {
  111786. _vq_quantthresh__8c0_s_p2_0,
  111787. _vq_quantmap__8c0_s_p2_0,
  111788. 5,
  111789. 5
  111790. };
  111791. static static_codebook _8c0_s_p2_0 = {
  111792. 4, 625,
  111793. _vq_lengthlist__8c0_s_p2_0,
  111794. 1, -533725184, 1611661312, 3, 0,
  111795. _vq_quantlist__8c0_s_p2_0,
  111796. NULL,
  111797. &_vq_auxt__8c0_s_p2_0,
  111798. NULL,
  111799. 0
  111800. };
  111801. static long _vq_quantlist__8c0_s_p3_0[] = {
  111802. 2,
  111803. 1,
  111804. 3,
  111805. 0,
  111806. 4,
  111807. };
  111808. static long _vq_lengthlist__8c0_s_p3_0[] = {
  111809. 1, 4, 4, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111810. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 5, 6, 7, 7, 0, 0,
  111811. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111812. 0, 0, 4, 5, 5, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111813. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 7, 7, 8, 8,
  111814. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111815. 0, 0, 0, 0, 6, 7, 7, 8, 8, 0, 0, 0, 0, 0, 0, 0,
  111816. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111817. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111818. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111819. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111820. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111821. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111822. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111823. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111824. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111825. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111826. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111827. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111828. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111829. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111830. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111831. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111832. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111833. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111834. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111835. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111836. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111837. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111838. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111839. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111840. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111841. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111842. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111843. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111844. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111845. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111846. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111847. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111848. 0,
  111849. };
  111850. static float _vq_quantthresh__8c0_s_p3_0[] = {
  111851. -1.5, -0.5, 0.5, 1.5,
  111852. };
  111853. static long _vq_quantmap__8c0_s_p3_0[] = {
  111854. 3, 1, 0, 2, 4,
  111855. };
  111856. static encode_aux_threshmatch _vq_auxt__8c0_s_p3_0 = {
  111857. _vq_quantthresh__8c0_s_p3_0,
  111858. _vq_quantmap__8c0_s_p3_0,
  111859. 5,
  111860. 5
  111861. };
  111862. static static_codebook _8c0_s_p3_0 = {
  111863. 4, 625,
  111864. _vq_lengthlist__8c0_s_p3_0,
  111865. 1, -533725184, 1611661312, 3, 0,
  111866. _vq_quantlist__8c0_s_p3_0,
  111867. NULL,
  111868. &_vq_auxt__8c0_s_p3_0,
  111869. NULL,
  111870. 0
  111871. };
  111872. static long _vq_quantlist__8c0_s_p4_0[] = {
  111873. 4,
  111874. 3,
  111875. 5,
  111876. 2,
  111877. 6,
  111878. 1,
  111879. 7,
  111880. 0,
  111881. 8,
  111882. };
  111883. static long _vq_lengthlist__8c0_s_p4_0[] = {
  111884. 1, 2, 3, 7, 7, 0, 0, 0, 0, 0, 0, 0, 6, 6, 0, 0,
  111885. 0, 0, 0, 0, 0, 6, 6, 0, 0, 0, 0, 0, 0, 0, 7, 7,
  111886. 0, 0, 0, 0, 0, 0, 0, 7, 7, 0, 0, 0, 0, 0, 0, 0,
  111887. 8, 8, 0, 0, 0, 0, 0, 0, 0, 9, 8, 0, 0, 0, 0, 0,
  111888. 0, 0,10,10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111889. 0,
  111890. };
  111891. static float _vq_quantthresh__8c0_s_p4_0[] = {
  111892. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  111893. };
  111894. static long _vq_quantmap__8c0_s_p4_0[] = {
  111895. 7, 5, 3, 1, 0, 2, 4, 6,
  111896. 8,
  111897. };
  111898. static encode_aux_threshmatch _vq_auxt__8c0_s_p4_0 = {
  111899. _vq_quantthresh__8c0_s_p4_0,
  111900. _vq_quantmap__8c0_s_p4_0,
  111901. 9,
  111902. 9
  111903. };
  111904. static static_codebook _8c0_s_p4_0 = {
  111905. 2, 81,
  111906. _vq_lengthlist__8c0_s_p4_0,
  111907. 1, -531628032, 1611661312, 4, 0,
  111908. _vq_quantlist__8c0_s_p4_0,
  111909. NULL,
  111910. &_vq_auxt__8c0_s_p4_0,
  111911. NULL,
  111912. 0
  111913. };
  111914. static long _vq_quantlist__8c0_s_p5_0[] = {
  111915. 4,
  111916. 3,
  111917. 5,
  111918. 2,
  111919. 6,
  111920. 1,
  111921. 7,
  111922. 0,
  111923. 8,
  111924. };
  111925. static long _vq_lengthlist__8c0_s_p5_0[] = {
  111926. 1, 3, 3, 5, 5, 7, 6, 8, 8, 0, 0, 0, 7, 7, 7, 7,
  111927. 8, 8, 0, 0, 0, 7, 7, 7, 7, 8, 9, 0, 0, 0, 8, 8,
  111928. 8, 8, 9, 9, 0, 0, 0, 8, 8, 8, 8, 9, 9, 0, 0, 0,
  111929. 9, 9, 8, 8,10,10, 0, 0, 0, 9, 9, 8, 8,10,10, 0,
  111930. 0, 0,10,10, 9, 9,10,10, 0, 0, 0, 0, 0, 9, 9,10,
  111931. 10,
  111932. };
  111933. static float _vq_quantthresh__8c0_s_p5_0[] = {
  111934. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  111935. };
  111936. static long _vq_quantmap__8c0_s_p5_0[] = {
  111937. 7, 5, 3, 1, 0, 2, 4, 6,
  111938. 8,
  111939. };
  111940. static encode_aux_threshmatch _vq_auxt__8c0_s_p5_0 = {
  111941. _vq_quantthresh__8c0_s_p5_0,
  111942. _vq_quantmap__8c0_s_p5_0,
  111943. 9,
  111944. 9
  111945. };
  111946. static static_codebook _8c0_s_p5_0 = {
  111947. 2, 81,
  111948. _vq_lengthlist__8c0_s_p5_0,
  111949. 1, -531628032, 1611661312, 4, 0,
  111950. _vq_quantlist__8c0_s_p5_0,
  111951. NULL,
  111952. &_vq_auxt__8c0_s_p5_0,
  111953. NULL,
  111954. 0
  111955. };
  111956. static long _vq_quantlist__8c0_s_p6_0[] = {
  111957. 8,
  111958. 7,
  111959. 9,
  111960. 6,
  111961. 10,
  111962. 5,
  111963. 11,
  111964. 4,
  111965. 12,
  111966. 3,
  111967. 13,
  111968. 2,
  111969. 14,
  111970. 1,
  111971. 15,
  111972. 0,
  111973. 16,
  111974. };
  111975. static long _vq_lengthlist__8c0_s_p6_0[] = {
  111976. 1, 3, 3, 6, 6, 8, 8, 9, 9, 8, 8,10, 9,10,10,11,
  111977. 11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,11,11,
  111978. 11,12, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,11,
  111979. 11,12,11, 0, 0, 0, 8, 8, 9, 9,10,10, 9, 9,10,10,
  111980. 11,11,12,12, 0, 0, 0, 8, 8, 9, 9,10,10, 9, 9,11,
  111981. 10,11,11,12,12, 0, 0, 0, 9, 9, 9, 9,10,10,10,10,
  111982. 11,11,11,12,12,12, 0, 0, 0, 9, 9, 9, 9,10,10,10,
  111983. 10,11,11,12,12,13,13, 0, 0, 0,10,10,10,10,11,11,
  111984. 10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0,10, 9,10,
  111985. 11,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9, 9,
  111986. 10, 9,10,11,12,12,13,13,14,13, 0, 0, 0, 0, 0, 9,
  111987. 9, 9,10,10,10,11,11,13,12,13,13, 0, 0, 0, 0, 0,
  111988. 10,10,10,10,11,11,12,12,13,13,14,14, 0, 0, 0, 0,
  111989. 0, 0, 0,10,10,11,11,12,12,13,13,13,14, 0, 0, 0,
  111990. 0, 0, 0, 0,11,11,11,11,12,12,13,14,14,14, 0, 0,
  111991. 0, 0, 0, 0, 0,11,11,11,11,12,12,13,13,14,13, 0,
  111992. 0, 0, 0, 0, 0, 0,11,11,12,12,13,13,14,14,14,14,
  111993. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,14,
  111994. 14,
  111995. };
  111996. static float _vq_quantthresh__8c0_s_p6_0[] = {
  111997. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  111998. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  111999. };
  112000. static long _vq_quantmap__8c0_s_p6_0[] = {
  112001. 15, 13, 11, 9, 7, 5, 3, 1,
  112002. 0, 2, 4, 6, 8, 10, 12, 14,
  112003. 16,
  112004. };
  112005. static encode_aux_threshmatch _vq_auxt__8c0_s_p6_0 = {
  112006. _vq_quantthresh__8c0_s_p6_0,
  112007. _vq_quantmap__8c0_s_p6_0,
  112008. 17,
  112009. 17
  112010. };
  112011. static static_codebook _8c0_s_p6_0 = {
  112012. 2, 289,
  112013. _vq_lengthlist__8c0_s_p6_0,
  112014. 1, -529530880, 1611661312, 5, 0,
  112015. _vq_quantlist__8c0_s_p6_0,
  112016. NULL,
  112017. &_vq_auxt__8c0_s_p6_0,
  112018. NULL,
  112019. 0
  112020. };
  112021. static long _vq_quantlist__8c0_s_p7_0[] = {
  112022. 1,
  112023. 0,
  112024. 2,
  112025. };
  112026. static long _vq_lengthlist__8c0_s_p7_0[] = {
  112027. 1, 4, 4, 7, 6, 6, 7, 6, 6, 4, 7, 7,11, 9,10,12,
  112028. 9,10, 4, 7, 7,10,10,10,11, 9, 9, 6,11,10,11,11,
  112029. 12,11,11,11, 6,10,10,11,11,12,11,10,10, 6, 9,10,
  112030. 11,11,11,11,10,10, 7,10,11,12,11,11,12,11,12, 6,
  112031. 9, 9,10, 9, 9,11,10,10, 6, 9, 9,10,10,10,11,10,
  112032. 10,
  112033. };
  112034. static float _vq_quantthresh__8c0_s_p7_0[] = {
  112035. -5.5, 5.5,
  112036. };
  112037. static long _vq_quantmap__8c0_s_p7_0[] = {
  112038. 1, 0, 2,
  112039. };
  112040. static encode_aux_threshmatch _vq_auxt__8c0_s_p7_0 = {
  112041. _vq_quantthresh__8c0_s_p7_0,
  112042. _vq_quantmap__8c0_s_p7_0,
  112043. 3,
  112044. 3
  112045. };
  112046. static static_codebook _8c0_s_p7_0 = {
  112047. 4, 81,
  112048. _vq_lengthlist__8c0_s_p7_0,
  112049. 1, -529137664, 1618345984, 2, 0,
  112050. _vq_quantlist__8c0_s_p7_0,
  112051. NULL,
  112052. &_vq_auxt__8c0_s_p7_0,
  112053. NULL,
  112054. 0
  112055. };
  112056. static long _vq_quantlist__8c0_s_p7_1[] = {
  112057. 5,
  112058. 4,
  112059. 6,
  112060. 3,
  112061. 7,
  112062. 2,
  112063. 8,
  112064. 1,
  112065. 9,
  112066. 0,
  112067. 10,
  112068. };
  112069. static long _vq_lengthlist__8c0_s_p7_1[] = {
  112070. 1, 3, 3, 6, 6, 8, 8, 9, 9, 9, 9,10,10,10, 7, 7,
  112071. 8, 8, 9, 9, 9, 9,10,10, 9, 7, 7, 8, 8, 9, 9, 9,
  112072. 9,10,10,10, 8, 8, 9, 9, 9, 9, 9, 9,10,10,10, 8,
  112073. 8, 9, 9, 9, 9, 8, 9,10,10,10, 8, 8, 9, 9, 9,10,
  112074. 10,10,10,10,10, 9, 9, 9, 9, 9, 9,10,10,11,10,11,
  112075. 9, 9, 9, 9,10,10,10,10,11,11,11,10,10, 9, 9,10,
  112076. 10,10, 9,11,10,10,10,10,10,10, 9, 9,10,10,11,11,
  112077. 10,10,10, 9, 9, 9,10,10,10,
  112078. };
  112079. static float _vq_quantthresh__8c0_s_p7_1[] = {
  112080. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  112081. 3.5, 4.5,
  112082. };
  112083. static long _vq_quantmap__8c0_s_p7_1[] = {
  112084. 9, 7, 5, 3, 1, 0, 2, 4,
  112085. 6, 8, 10,
  112086. };
  112087. static encode_aux_threshmatch _vq_auxt__8c0_s_p7_1 = {
  112088. _vq_quantthresh__8c0_s_p7_1,
  112089. _vq_quantmap__8c0_s_p7_1,
  112090. 11,
  112091. 11
  112092. };
  112093. static static_codebook _8c0_s_p7_1 = {
  112094. 2, 121,
  112095. _vq_lengthlist__8c0_s_p7_1,
  112096. 1, -531365888, 1611661312, 4, 0,
  112097. _vq_quantlist__8c0_s_p7_1,
  112098. NULL,
  112099. &_vq_auxt__8c0_s_p7_1,
  112100. NULL,
  112101. 0
  112102. };
  112103. static long _vq_quantlist__8c0_s_p8_0[] = {
  112104. 6,
  112105. 5,
  112106. 7,
  112107. 4,
  112108. 8,
  112109. 3,
  112110. 9,
  112111. 2,
  112112. 10,
  112113. 1,
  112114. 11,
  112115. 0,
  112116. 12,
  112117. };
  112118. static long _vq_lengthlist__8c0_s_p8_0[] = {
  112119. 1, 4, 4, 7, 6, 7, 7, 7, 7, 8, 8, 9, 9, 7, 6, 6,
  112120. 7, 7, 8, 8, 7, 7, 8, 9,10,10, 7, 6, 6, 7, 7, 8,
  112121. 7, 7, 7, 9, 9,10,12, 0, 8, 8, 8, 8, 8, 9, 8, 8,
  112122. 9, 9,10,10, 0, 8, 8, 8, 8, 8, 9, 8, 9, 9, 9,11,
  112123. 10, 0, 0,13, 9, 8, 9, 9, 9, 9,10,10,11,11, 0,13,
  112124. 0, 9, 9, 9, 9, 9, 9,11,10,11,11, 0, 0, 0, 8, 9,
  112125. 10, 9,10,10,13,11,12,12, 0, 0, 0, 8, 9, 9, 9,10,
  112126. 10,13,12,12,13, 0, 0, 0,12, 0,10,10,12,11,10,11,
  112127. 12,12, 0, 0, 0,13,13,10,10,10,11,12, 0,13, 0, 0,
  112128. 0, 0, 0, 0,13,11, 0,12,12,12,13,12, 0, 0, 0, 0,
  112129. 0, 0,13,13,11,13,13,11,12,
  112130. };
  112131. static float _vq_quantthresh__8c0_s_p8_0[] = {
  112132. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  112133. 12.5, 17.5, 22.5, 27.5,
  112134. };
  112135. static long _vq_quantmap__8c0_s_p8_0[] = {
  112136. 11, 9, 7, 5, 3, 1, 0, 2,
  112137. 4, 6, 8, 10, 12,
  112138. };
  112139. static encode_aux_threshmatch _vq_auxt__8c0_s_p8_0 = {
  112140. _vq_quantthresh__8c0_s_p8_0,
  112141. _vq_quantmap__8c0_s_p8_0,
  112142. 13,
  112143. 13
  112144. };
  112145. static static_codebook _8c0_s_p8_0 = {
  112146. 2, 169,
  112147. _vq_lengthlist__8c0_s_p8_0,
  112148. 1, -526516224, 1616117760, 4, 0,
  112149. _vq_quantlist__8c0_s_p8_0,
  112150. NULL,
  112151. &_vq_auxt__8c0_s_p8_0,
  112152. NULL,
  112153. 0
  112154. };
  112155. static long _vq_quantlist__8c0_s_p8_1[] = {
  112156. 2,
  112157. 1,
  112158. 3,
  112159. 0,
  112160. 4,
  112161. };
  112162. static long _vq_lengthlist__8c0_s_p8_1[] = {
  112163. 1, 3, 4, 5, 5, 7, 6, 6, 6, 5, 7, 7, 7, 6, 6, 7,
  112164. 7, 7, 6, 6, 7, 7, 7, 6, 6,
  112165. };
  112166. static float _vq_quantthresh__8c0_s_p8_1[] = {
  112167. -1.5, -0.5, 0.5, 1.5,
  112168. };
  112169. static long _vq_quantmap__8c0_s_p8_1[] = {
  112170. 3, 1, 0, 2, 4,
  112171. };
  112172. static encode_aux_threshmatch _vq_auxt__8c0_s_p8_1 = {
  112173. _vq_quantthresh__8c0_s_p8_1,
  112174. _vq_quantmap__8c0_s_p8_1,
  112175. 5,
  112176. 5
  112177. };
  112178. static static_codebook _8c0_s_p8_1 = {
  112179. 2, 25,
  112180. _vq_lengthlist__8c0_s_p8_1,
  112181. 1, -533725184, 1611661312, 3, 0,
  112182. _vq_quantlist__8c0_s_p8_1,
  112183. NULL,
  112184. &_vq_auxt__8c0_s_p8_1,
  112185. NULL,
  112186. 0
  112187. };
  112188. static long _vq_quantlist__8c0_s_p9_0[] = {
  112189. 1,
  112190. 0,
  112191. 2,
  112192. };
  112193. static long _vq_lengthlist__8c0_s_p9_0[] = {
  112194. 1, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  112195. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  112196. 8, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  112197. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  112198. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  112199. 7,
  112200. };
  112201. static float _vq_quantthresh__8c0_s_p9_0[] = {
  112202. -157.5, 157.5,
  112203. };
  112204. static long _vq_quantmap__8c0_s_p9_0[] = {
  112205. 1, 0, 2,
  112206. };
  112207. static encode_aux_threshmatch _vq_auxt__8c0_s_p9_0 = {
  112208. _vq_quantthresh__8c0_s_p9_0,
  112209. _vq_quantmap__8c0_s_p9_0,
  112210. 3,
  112211. 3
  112212. };
  112213. static static_codebook _8c0_s_p9_0 = {
  112214. 4, 81,
  112215. _vq_lengthlist__8c0_s_p9_0,
  112216. 1, -518803456, 1628680192, 2, 0,
  112217. _vq_quantlist__8c0_s_p9_0,
  112218. NULL,
  112219. &_vq_auxt__8c0_s_p9_0,
  112220. NULL,
  112221. 0
  112222. };
  112223. static long _vq_quantlist__8c0_s_p9_1[] = {
  112224. 7,
  112225. 6,
  112226. 8,
  112227. 5,
  112228. 9,
  112229. 4,
  112230. 10,
  112231. 3,
  112232. 11,
  112233. 2,
  112234. 12,
  112235. 1,
  112236. 13,
  112237. 0,
  112238. 14,
  112239. };
  112240. static long _vq_lengthlist__8c0_s_p9_1[] = {
  112241. 1, 4, 4, 5, 5,10, 8,11,11,11,11,11,11,11,11, 6,
  112242. 6, 6, 7, 6,11,10,11,11,11,11,11,11,11,11, 7, 5,
  112243. 6, 6, 6, 8, 7,11,11,11,11,11,11,11,11,11, 7, 8,
  112244. 8, 8, 9, 9,11,11,11,11,11,11,11,11,11, 9, 8, 7,
  112245. 8, 9,11,11,11,11,11,11,11,11,11,11,11,10,11,11,
  112246. 11,11,11,11,11,11,11,11,11,11,11,11,11,10,11,11,
  112247. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  112248. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  112249. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  112250. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  112251. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  112252. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  112253. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  112254. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  112255. 11,
  112256. };
  112257. static float _vq_quantthresh__8c0_s_p9_1[] = {
  112258. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  112259. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  112260. };
  112261. static long _vq_quantmap__8c0_s_p9_1[] = {
  112262. 13, 11, 9, 7, 5, 3, 1, 0,
  112263. 2, 4, 6, 8, 10, 12, 14,
  112264. };
  112265. static encode_aux_threshmatch _vq_auxt__8c0_s_p9_1 = {
  112266. _vq_quantthresh__8c0_s_p9_1,
  112267. _vq_quantmap__8c0_s_p9_1,
  112268. 15,
  112269. 15
  112270. };
  112271. static static_codebook _8c0_s_p9_1 = {
  112272. 2, 225,
  112273. _vq_lengthlist__8c0_s_p9_1,
  112274. 1, -520986624, 1620377600, 4, 0,
  112275. _vq_quantlist__8c0_s_p9_1,
  112276. NULL,
  112277. &_vq_auxt__8c0_s_p9_1,
  112278. NULL,
  112279. 0
  112280. };
  112281. static long _vq_quantlist__8c0_s_p9_2[] = {
  112282. 10,
  112283. 9,
  112284. 11,
  112285. 8,
  112286. 12,
  112287. 7,
  112288. 13,
  112289. 6,
  112290. 14,
  112291. 5,
  112292. 15,
  112293. 4,
  112294. 16,
  112295. 3,
  112296. 17,
  112297. 2,
  112298. 18,
  112299. 1,
  112300. 19,
  112301. 0,
  112302. 20,
  112303. };
  112304. static long _vq_lengthlist__8c0_s_p9_2[] = {
  112305. 1, 5, 5, 7, 7, 8, 7, 8, 8,10,10, 9, 9,10,10,10,
  112306. 11,11,10,12,11,12,12,12, 9, 8, 8, 8, 8, 8, 9,10,
  112307. 10,10,10,11,11,11,10,11,11,12,12,11,12, 8, 8, 7,
  112308. 7, 8, 9,10,10,10, 9,10,10, 9,10,10,11,11,11,11,
  112309. 11,11, 9, 9, 9, 9, 8, 9,10,10,11,10,10,11,11,12,
  112310. 10,10,12,12,11,11,10, 9, 9,10, 8, 9,10,10,10, 9,
  112311. 10,10,11,11,10,11,10,10,10,12,12,12, 9,10, 9,10,
  112312. 9, 9,10,10,11,11,11,11,10,10,10,11,12,11,12,11,
  112313. 12,10,11,10,11, 9,10, 9,10, 9,10,10, 9,10,10,11,
  112314. 10,11,11,11,11,12,11, 9,10,10,10,10,11,11,11,11,
  112315. 11,10,11,11,11,11,10,12,10,12,12,11,12,10,10,11,
  112316. 10, 9,11,10,11, 9,10,11,10,10,10,11,11,11,11,12,
  112317. 12,10, 9, 9,11,10, 9,12,11,10,12,12,11,11,11,11,
  112318. 10,11,11,12,11,10,12, 9,11,10,11,10,10,11,10,11,
  112319. 9,10,10,10,11,12,11,11,12,11,10,10,11,11, 9,10,
  112320. 10,12,10,11,10,10,10, 9,10,10,10,10, 9,10,10,11,
  112321. 11,11,11,12,11,10,10,10,10,11,11,10,11,11, 9,11,
  112322. 10,12,10,12,11,10,11,10,10,10,11,10,10,11,11,10,
  112323. 11,10,10,10,10,11,11,12,10,10,10,11,10,11,12,11,
  112324. 10,11,10,10,11,11,10,12,10, 9,10,10,11,11,11,10,
  112325. 12,10,10,11,11,11,10,10,11,10,10,10,11,10,11,10,
  112326. 12,11,11,10,10,10,12,10,10,11, 9,10,11,11,11,10,
  112327. 10,11,10,10, 9,11,11,12,12,11,12,11,11,11,11,11,
  112328. 11, 9,10,11,10,12,10,10,10,10,11,10,10,11,10,10,
  112329. 12,10,10,10,10,10, 9,12,10,10,10,10,12, 9,11,10,
  112330. 10,11,10,12,12,10,12,12,12,10,10,10,10, 9,10,11,
  112331. 10,10,12,10,10,12,11,10,11,10,10,12,11,10,12,10,
  112332. 10,11, 9,11,10, 9,10, 9,10,
  112333. };
  112334. static float _vq_quantthresh__8c0_s_p9_2[] = {
  112335. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  112336. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  112337. 6.5, 7.5, 8.5, 9.5,
  112338. };
  112339. static long _vq_quantmap__8c0_s_p9_2[] = {
  112340. 19, 17, 15, 13, 11, 9, 7, 5,
  112341. 3, 1, 0, 2, 4, 6, 8, 10,
  112342. 12, 14, 16, 18, 20,
  112343. };
  112344. static encode_aux_threshmatch _vq_auxt__8c0_s_p9_2 = {
  112345. _vq_quantthresh__8c0_s_p9_2,
  112346. _vq_quantmap__8c0_s_p9_2,
  112347. 21,
  112348. 21
  112349. };
  112350. static static_codebook _8c0_s_p9_2 = {
  112351. 2, 441,
  112352. _vq_lengthlist__8c0_s_p9_2,
  112353. 1, -529268736, 1611661312, 5, 0,
  112354. _vq_quantlist__8c0_s_p9_2,
  112355. NULL,
  112356. &_vq_auxt__8c0_s_p9_2,
  112357. NULL,
  112358. 0
  112359. };
  112360. static long _huff_lengthlist__8c0_s_single[] = {
  112361. 4, 5,18, 7,10, 6, 7, 8, 9,10, 5, 2,18, 5, 7, 5,
  112362. 6, 7, 8,11,17,17,17,17,17,17,17,17,17,17, 7, 4,
  112363. 17, 6, 9, 6, 8,10,12,15,11, 7,17, 9, 6, 6, 7, 9,
  112364. 11,15, 6, 4,17, 6, 6, 4, 5, 8,11,16, 6, 6,17, 8,
  112365. 6, 5, 6, 9,13,16, 8, 9,17,11, 9, 8, 8,11,13,17,
  112366. 9,12,17,15,14,13,12,13,14,17,12,15,17,17,17,17,
  112367. 17,16,17,17,
  112368. };
  112369. static static_codebook _huff_book__8c0_s_single = {
  112370. 2, 100,
  112371. _huff_lengthlist__8c0_s_single,
  112372. 0, 0, 0, 0, 0,
  112373. NULL,
  112374. NULL,
  112375. NULL,
  112376. NULL,
  112377. 0
  112378. };
  112379. static long _vq_quantlist__8c1_s_p1_0[] = {
  112380. 1,
  112381. 0,
  112382. 2,
  112383. };
  112384. static long _vq_lengthlist__8c1_s_p1_0[] = {
  112385. 1, 5, 5, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0,
  112386. 0, 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112387. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112388. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112389. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112390. 0, 5, 8, 7, 0, 0, 0, 0, 0, 0, 7, 8, 9, 0, 0, 0,
  112391. 0, 0, 0, 7, 8, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112392. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112393. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112394. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112395. 0, 0, 5, 7, 8, 0, 0, 0, 0, 0, 0, 7, 9, 8, 0, 0,
  112396. 0, 0, 0, 0, 7, 9, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112397. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112398. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112399. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112400. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112401. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112402. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112403. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112404. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112405. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112406. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112407. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112408. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112409. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112410. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112411. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112412. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112413. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112414. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112415. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112416. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112417. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112418. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112419. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112420. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112421. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112422. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112423. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112424. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112425. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112426. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112427. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112428. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112429. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112430. 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 8, 8, 0, 0, 0, 0,
  112431. 0, 0, 8, 9, 9, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0, 0,
  112432. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112433. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112434. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112435. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0, 0,
  112436. 0, 0, 0, 8, 8,10, 0, 0, 0, 0, 0, 0, 9,10,10, 0,
  112437. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112438. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112439. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112440. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  112441. 0, 0, 0, 0, 8,10, 9, 0, 0, 0, 0, 0, 0, 9,10,10,
  112442. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112443. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112444. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112445. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112446. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112447. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112448. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112449. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112450. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112451. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112452. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112453. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112454. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112455. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112456. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112457. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112458. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112459. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112460. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112461. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112462. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112463. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112464. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112465. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112466. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112467. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112468. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112469. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112470. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112471. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112472. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112473. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112474. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112475. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112476. 0, 0, 5, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0, 0,
  112477. 0, 0, 0, 0, 8, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112478. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112479. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112480. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112481. 0, 0, 0, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,10,10, 0,
  112482. 0, 0, 0, 0, 0, 8, 9,10, 0, 0, 0, 0, 0, 0, 0, 0,
  112483. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112484. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112485. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112486. 0, 0, 0, 0, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,10,10,
  112487. 0, 0, 0, 0, 0, 0, 8,10, 8, 0, 0, 0, 0, 0, 0, 0,
  112488. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112489. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112490. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112491. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112492. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112493. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112494. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112495. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112496. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112497. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112498. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112499. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112500. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112501. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112502. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112503. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112504. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112505. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112506. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112507. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112508. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112509. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112510. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112511. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112512. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112513. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112514. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112515. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112516. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112517. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112518. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112519. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112520. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112521. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112522. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112523. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112524. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112525. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112526. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112527. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112528. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112529. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112530. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112531. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112532. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112533. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112534. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112535. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112536. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112537. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112538. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112539. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112540. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112541. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112542. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112543. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112544. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112545. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112546. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112547. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112548. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112549. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112550. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112551. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112552. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112553. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112554. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112555. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112556. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112557. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112558. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112559. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112560. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112561. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112562. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112563. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112564. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112565. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112566. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112567. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112568. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112569. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112570. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112571. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112572. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112573. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112574. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112575. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112576. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112577. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112578. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112579. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112580. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112581. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112582. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112583. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112584. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112585. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112586. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112587. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112588. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112589. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112590. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112591. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112592. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112593. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112594. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112595. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112596. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112597. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112598. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112599. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112600. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112601. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112602. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112603. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112604. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112605. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112606. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112607. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112608. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112609. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112610. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112611. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112612. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112613. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112614. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112615. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112616. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112617. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112618. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112619. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112620. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112621. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112622. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112623. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112624. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112625. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112626. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112627. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112628. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112629. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112630. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112631. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112632. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112633. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112634. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112635. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112636. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112637. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112638. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112639. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112640. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112641. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112642. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112643. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112644. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112645. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112646. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112647. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112648. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112649. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112650. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112651. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112652. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112653. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112654. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112655. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112656. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112657. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112658. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112659. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112660. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112661. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112662. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112663. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112664. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112665. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112666. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112667. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112668. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112669. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112670. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112671. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112672. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112673. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112674. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112675. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112676. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112677. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112678. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112679. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112680. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112681. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112682. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112683. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112684. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112685. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112686. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112687. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112688. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112689. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112690. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112691. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112692. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112693. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112694. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112695. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112696. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112697. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112698. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112699. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112700. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112701. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112702. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112703. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112704. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112705. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112706. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112707. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112708. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112709. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112710. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112711. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112712. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112713. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112714. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112715. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112716. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112717. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112718. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112719. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112720. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112721. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112722. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112723. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112724. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112725. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112726. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112727. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112728. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112729. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112730. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112731. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112732. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112733. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112734. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112735. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112736. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112737. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112738. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112739. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112740. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112741. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112742. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112743. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112744. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112745. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112746. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112747. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112748. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112749. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112750. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112751. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112752. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112753. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112754. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112755. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112756. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112757. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112758. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112759. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112760. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112761. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112762. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112763. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112764. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112765. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112766. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112767. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112768. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112769. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112770. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112771. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112772. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112773. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112774. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112775. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112776. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112777. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112778. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112779. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112780. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112781. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112782. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112783. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112784. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112785. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112786. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112787. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112788. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112789. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112790. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112791. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112792. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112793. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112794. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112795. 0,
  112796. };
  112797. static float _vq_quantthresh__8c1_s_p1_0[] = {
  112798. -0.5, 0.5,
  112799. };
  112800. static long _vq_quantmap__8c1_s_p1_0[] = {
  112801. 1, 0, 2,
  112802. };
  112803. static encode_aux_threshmatch _vq_auxt__8c1_s_p1_0 = {
  112804. _vq_quantthresh__8c1_s_p1_0,
  112805. _vq_quantmap__8c1_s_p1_0,
  112806. 3,
  112807. 3
  112808. };
  112809. static static_codebook _8c1_s_p1_0 = {
  112810. 8, 6561,
  112811. _vq_lengthlist__8c1_s_p1_0,
  112812. 1, -535822336, 1611661312, 2, 0,
  112813. _vq_quantlist__8c1_s_p1_0,
  112814. NULL,
  112815. &_vq_auxt__8c1_s_p1_0,
  112816. NULL,
  112817. 0
  112818. };
  112819. static long _vq_quantlist__8c1_s_p2_0[] = {
  112820. 2,
  112821. 1,
  112822. 3,
  112823. 0,
  112824. 4,
  112825. };
  112826. static long _vq_lengthlist__8c1_s_p2_0[] = {
  112827. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112828. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112829. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112830. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112831. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112832. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112833. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112834. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112835. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112836. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112837. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112838. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112839. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112840. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112841. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112842. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112843. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112844. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112845. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112846. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112847. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112848. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112849. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112850. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112851. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112852. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112853. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112854. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112855. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112856. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112857. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112858. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112859. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112860. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112861. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112862. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112863. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112864. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112865. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112866. 0,
  112867. };
  112868. static float _vq_quantthresh__8c1_s_p2_0[] = {
  112869. -1.5, -0.5, 0.5, 1.5,
  112870. };
  112871. static long _vq_quantmap__8c1_s_p2_0[] = {
  112872. 3, 1, 0, 2, 4,
  112873. };
  112874. static encode_aux_threshmatch _vq_auxt__8c1_s_p2_0 = {
  112875. _vq_quantthresh__8c1_s_p2_0,
  112876. _vq_quantmap__8c1_s_p2_0,
  112877. 5,
  112878. 5
  112879. };
  112880. static static_codebook _8c1_s_p2_0 = {
  112881. 4, 625,
  112882. _vq_lengthlist__8c1_s_p2_0,
  112883. 1, -533725184, 1611661312, 3, 0,
  112884. _vq_quantlist__8c1_s_p2_0,
  112885. NULL,
  112886. &_vq_auxt__8c1_s_p2_0,
  112887. NULL,
  112888. 0
  112889. };
  112890. static long _vq_quantlist__8c1_s_p3_0[] = {
  112891. 2,
  112892. 1,
  112893. 3,
  112894. 0,
  112895. 4,
  112896. };
  112897. static long _vq_lengthlist__8c1_s_p3_0[] = {
  112898. 2, 4, 4, 5, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112899. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 4, 4, 6, 6, 0, 0,
  112900. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112901. 0, 0, 4, 4, 4, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112902. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 6, 6, 7, 7,
  112903. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112904. 0, 0, 0, 0, 6, 6, 6, 7, 7, 0, 0, 0, 0, 0, 0, 0,
  112905. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112906. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112907. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112908. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112909. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112910. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112911. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112912. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112913. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112914. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112915. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112916. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112917. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112918. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112919. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112920. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112921. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112922. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112923. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112924. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112925. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112926. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112927. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112928. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112929. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112930. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112931. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112932. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112933. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112934. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112935. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112936. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112937. 0,
  112938. };
  112939. static float _vq_quantthresh__8c1_s_p3_0[] = {
  112940. -1.5, -0.5, 0.5, 1.5,
  112941. };
  112942. static long _vq_quantmap__8c1_s_p3_0[] = {
  112943. 3, 1, 0, 2, 4,
  112944. };
  112945. static encode_aux_threshmatch _vq_auxt__8c1_s_p3_0 = {
  112946. _vq_quantthresh__8c1_s_p3_0,
  112947. _vq_quantmap__8c1_s_p3_0,
  112948. 5,
  112949. 5
  112950. };
  112951. static static_codebook _8c1_s_p3_0 = {
  112952. 4, 625,
  112953. _vq_lengthlist__8c1_s_p3_0,
  112954. 1, -533725184, 1611661312, 3, 0,
  112955. _vq_quantlist__8c1_s_p3_0,
  112956. NULL,
  112957. &_vq_auxt__8c1_s_p3_0,
  112958. NULL,
  112959. 0
  112960. };
  112961. static long _vq_quantlist__8c1_s_p4_0[] = {
  112962. 4,
  112963. 3,
  112964. 5,
  112965. 2,
  112966. 6,
  112967. 1,
  112968. 7,
  112969. 0,
  112970. 8,
  112971. };
  112972. static long _vq_lengthlist__8c1_s_p4_0[] = {
  112973. 1, 2, 3, 7, 7, 0, 0, 0, 0, 0, 0, 0, 6, 6, 0, 0,
  112974. 0, 0, 0, 0, 0, 6, 6, 0, 0, 0, 0, 0, 0, 0, 7, 7,
  112975. 0, 0, 0, 0, 0, 0, 0, 7, 7, 0, 0, 0, 0, 0, 0, 0,
  112976. 8, 8, 0, 0, 0, 0, 0, 0, 0, 9, 8, 0, 0, 0, 0, 0,
  112977. 0, 0,10,10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112978. 0,
  112979. };
  112980. static float _vq_quantthresh__8c1_s_p4_0[] = {
  112981. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  112982. };
  112983. static long _vq_quantmap__8c1_s_p4_0[] = {
  112984. 7, 5, 3, 1, 0, 2, 4, 6,
  112985. 8,
  112986. };
  112987. static encode_aux_threshmatch _vq_auxt__8c1_s_p4_0 = {
  112988. _vq_quantthresh__8c1_s_p4_0,
  112989. _vq_quantmap__8c1_s_p4_0,
  112990. 9,
  112991. 9
  112992. };
  112993. static static_codebook _8c1_s_p4_0 = {
  112994. 2, 81,
  112995. _vq_lengthlist__8c1_s_p4_0,
  112996. 1, -531628032, 1611661312, 4, 0,
  112997. _vq_quantlist__8c1_s_p4_0,
  112998. NULL,
  112999. &_vq_auxt__8c1_s_p4_0,
  113000. NULL,
  113001. 0
  113002. };
  113003. static long _vq_quantlist__8c1_s_p5_0[] = {
  113004. 4,
  113005. 3,
  113006. 5,
  113007. 2,
  113008. 6,
  113009. 1,
  113010. 7,
  113011. 0,
  113012. 8,
  113013. };
  113014. static long _vq_lengthlist__8c1_s_p5_0[] = {
  113015. 1, 3, 3, 4, 5, 6, 6, 8, 8, 0, 0, 0, 8, 8, 7, 7,
  113016. 9, 9, 0, 0, 0, 8, 8, 7, 7, 9, 9, 0, 0, 0, 9,10,
  113017. 8, 8, 9, 9, 0, 0, 0,10,10, 8, 8, 9, 9, 0, 0, 0,
  113018. 11,10, 8, 8,10,10, 0, 0, 0,11,11, 8, 8,10,10, 0,
  113019. 0, 0,12,12, 9, 9,10,10, 0, 0, 0, 0, 0, 9, 9,10,
  113020. 10,
  113021. };
  113022. static float _vq_quantthresh__8c1_s_p5_0[] = {
  113023. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  113024. };
  113025. static long _vq_quantmap__8c1_s_p5_0[] = {
  113026. 7, 5, 3, 1, 0, 2, 4, 6,
  113027. 8,
  113028. };
  113029. static encode_aux_threshmatch _vq_auxt__8c1_s_p5_0 = {
  113030. _vq_quantthresh__8c1_s_p5_0,
  113031. _vq_quantmap__8c1_s_p5_0,
  113032. 9,
  113033. 9
  113034. };
  113035. static static_codebook _8c1_s_p5_0 = {
  113036. 2, 81,
  113037. _vq_lengthlist__8c1_s_p5_0,
  113038. 1, -531628032, 1611661312, 4, 0,
  113039. _vq_quantlist__8c1_s_p5_0,
  113040. NULL,
  113041. &_vq_auxt__8c1_s_p5_0,
  113042. NULL,
  113043. 0
  113044. };
  113045. static long _vq_quantlist__8c1_s_p6_0[] = {
  113046. 8,
  113047. 7,
  113048. 9,
  113049. 6,
  113050. 10,
  113051. 5,
  113052. 11,
  113053. 4,
  113054. 12,
  113055. 3,
  113056. 13,
  113057. 2,
  113058. 14,
  113059. 1,
  113060. 15,
  113061. 0,
  113062. 16,
  113063. };
  113064. static long _vq_lengthlist__8c1_s_p6_0[] = {
  113065. 1, 3, 3, 5, 5, 8, 8, 8, 8, 9, 9,10,10,11,11,11,
  113066. 11, 0, 0, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,11,
  113067. 12,12, 0, 0, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  113068. 11,12,12, 0, 0, 0, 9, 9, 8, 8,10,10,10,10,11,11,
  113069. 12,12,12,12, 0, 0, 0, 9, 9, 8, 8,10,10,10,10,11,
  113070. 11,12,12,12,12, 0, 0, 0,10,10, 9, 9,10,10,10,10,
  113071. 11,11,12,12,13,13, 0, 0, 0,10,10, 9, 9,10,10,10,
  113072. 10,11,11,12,12,13,13, 0, 0, 0,11,11, 9, 9,10,10,
  113073. 10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9, 9,10,
  113074. 10,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9, 9,
  113075. 10,10,11,11,12,12,12,12,13,13, 0, 0, 0, 0, 0, 9,
  113076. 9,10,10,11,11,12,11,12,12,13,13, 0, 0, 0, 0, 0,
  113077. 10,10,11,11,11,11,12,12,13,12,13,13, 0, 0, 0, 0,
  113078. 0, 0, 0,11,10,11,11,12,12,13,13,13,13, 0, 0, 0,
  113079. 0, 0, 0, 0,11,11,12,12,12,12,13,13,13,14, 0, 0,
  113080. 0, 0, 0, 0, 0,11,11,12,12,12,12,13,13,14,13, 0,
  113081. 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,13,13,14,14,
  113082. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,13,13,13,13,14,
  113083. 14,
  113084. };
  113085. static float _vq_quantthresh__8c1_s_p6_0[] = {
  113086. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  113087. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  113088. };
  113089. static long _vq_quantmap__8c1_s_p6_0[] = {
  113090. 15, 13, 11, 9, 7, 5, 3, 1,
  113091. 0, 2, 4, 6, 8, 10, 12, 14,
  113092. 16,
  113093. };
  113094. static encode_aux_threshmatch _vq_auxt__8c1_s_p6_0 = {
  113095. _vq_quantthresh__8c1_s_p6_0,
  113096. _vq_quantmap__8c1_s_p6_0,
  113097. 17,
  113098. 17
  113099. };
  113100. static static_codebook _8c1_s_p6_0 = {
  113101. 2, 289,
  113102. _vq_lengthlist__8c1_s_p6_0,
  113103. 1, -529530880, 1611661312, 5, 0,
  113104. _vq_quantlist__8c1_s_p6_0,
  113105. NULL,
  113106. &_vq_auxt__8c1_s_p6_0,
  113107. NULL,
  113108. 0
  113109. };
  113110. static long _vq_quantlist__8c1_s_p7_0[] = {
  113111. 1,
  113112. 0,
  113113. 2,
  113114. };
  113115. static long _vq_lengthlist__8c1_s_p7_0[] = {
  113116. 1, 4, 4, 6, 6, 6, 7, 6, 6, 4, 7, 7,10, 9, 9,10,
  113117. 9, 9, 5, 7, 7,10, 9, 9,10, 9, 9, 6,10,10,10,10,
  113118. 10,11,10,10, 6, 9, 9,10, 9,10,11,10,10, 6, 9, 9,
  113119. 10, 9, 9,11, 9,10, 7,10,10,11,11,11,11,10,10, 6,
  113120. 9, 9,10,10,10,11, 9, 9, 6, 9, 9,10,10,10,10, 9,
  113121. 9,
  113122. };
  113123. static float _vq_quantthresh__8c1_s_p7_0[] = {
  113124. -5.5, 5.5,
  113125. };
  113126. static long _vq_quantmap__8c1_s_p7_0[] = {
  113127. 1, 0, 2,
  113128. };
  113129. static encode_aux_threshmatch _vq_auxt__8c1_s_p7_0 = {
  113130. _vq_quantthresh__8c1_s_p7_0,
  113131. _vq_quantmap__8c1_s_p7_0,
  113132. 3,
  113133. 3
  113134. };
  113135. static static_codebook _8c1_s_p7_0 = {
  113136. 4, 81,
  113137. _vq_lengthlist__8c1_s_p7_0,
  113138. 1, -529137664, 1618345984, 2, 0,
  113139. _vq_quantlist__8c1_s_p7_0,
  113140. NULL,
  113141. &_vq_auxt__8c1_s_p7_0,
  113142. NULL,
  113143. 0
  113144. };
  113145. static long _vq_quantlist__8c1_s_p7_1[] = {
  113146. 5,
  113147. 4,
  113148. 6,
  113149. 3,
  113150. 7,
  113151. 2,
  113152. 8,
  113153. 1,
  113154. 9,
  113155. 0,
  113156. 10,
  113157. };
  113158. static long _vq_lengthlist__8c1_s_p7_1[] = {
  113159. 2, 3, 3, 5, 5, 7, 7, 7, 7, 7, 7,10,10, 9, 7, 7,
  113160. 7, 7, 8, 8, 8, 8, 9, 9, 9, 7, 7, 7, 7, 8, 8, 8,
  113161. 8,10,10,10, 7, 7, 7, 7, 8, 8, 8, 8,10,10,10, 7,
  113162. 7, 7, 7, 8, 8, 8, 8,10,10,10, 8, 8, 8, 8, 8, 8,
  113163. 8, 8,10,10,10, 8, 8, 8, 8, 8, 8, 8, 8,10,10,10,
  113164. 8, 8, 8, 8, 8, 8, 8, 8,10,10,10,10,10, 8, 8, 8,
  113165. 8, 8, 8,10,10,10,10,10, 8, 8, 8, 8, 8, 8,10,10,
  113166. 10,10,10, 8, 8, 8, 8, 8, 8,
  113167. };
  113168. static float _vq_quantthresh__8c1_s_p7_1[] = {
  113169. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  113170. 3.5, 4.5,
  113171. };
  113172. static long _vq_quantmap__8c1_s_p7_1[] = {
  113173. 9, 7, 5, 3, 1, 0, 2, 4,
  113174. 6, 8, 10,
  113175. };
  113176. static encode_aux_threshmatch _vq_auxt__8c1_s_p7_1 = {
  113177. _vq_quantthresh__8c1_s_p7_1,
  113178. _vq_quantmap__8c1_s_p7_1,
  113179. 11,
  113180. 11
  113181. };
  113182. static static_codebook _8c1_s_p7_1 = {
  113183. 2, 121,
  113184. _vq_lengthlist__8c1_s_p7_1,
  113185. 1, -531365888, 1611661312, 4, 0,
  113186. _vq_quantlist__8c1_s_p7_1,
  113187. NULL,
  113188. &_vq_auxt__8c1_s_p7_1,
  113189. NULL,
  113190. 0
  113191. };
  113192. static long _vq_quantlist__8c1_s_p8_0[] = {
  113193. 6,
  113194. 5,
  113195. 7,
  113196. 4,
  113197. 8,
  113198. 3,
  113199. 9,
  113200. 2,
  113201. 10,
  113202. 1,
  113203. 11,
  113204. 0,
  113205. 12,
  113206. };
  113207. static long _vq_lengthlist__8c1_s_p8_0[] = {
  113208. 1, 4, 4, 6, 6, 8, 8, 8, 8, 9, 9,10,10, 7, 5, 5,
  113209. 7, 7, 8, 8, 8, 8, 9,10,11,11, 7, 5, 5, 7, 7, 8,
  113210. 8, 9, 9,10,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  113211. 9,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  113212. 11, 0,12,12, 9, 9, 9, 9,10, 9,10,11,11,11, 0,13,
  113213. 12, 9, 8, 9, 9,10,10,11,11,12,11, 0, 0, 0, 9, 9,
  113214. 9, 9,10,10,11,11,12,12, 0, 0, 0,10,10, 9, 9,10,
  113215. 10,11,11,12,12, 0, 0, 0,13,13,10,10,11,11,12,11,
  113216. 13,12, 0, 0, 0,14,14,10,10,11,10,11,11,12,12, 0,
  113217. 0, 0, 0, 0,12,12,11,11,12,12,13,13, 0, 0, 0, 0,
  113218. 0,12,12,11,10,12,11,13,12,
  113219. };
  113220. static float _vq_quantthresh__8c1_s_p8_0[] = {
  113221. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  113222. 12.5, 17.5, 22.5, 27.5,
  113223. };
  113224. static long _vq_quantmap__8c1_s_p8_0[] = {
  113225. 11, 9, 7, 5, 3, 1, 0, 2,
  113226. 4, 6, 8, 10, 12,
  113227. };
  113228. static encode_aux_threshmatch _vq_auxt__8c1_s_p8_0 = {
  113229. _vq_quantthresh__8c1_s_p8_0,
  113230. _vq_quantmap__8c1_s_p8_0,
  113231. 13,
  113232. 13
  113233. };
  113234. static static_codebook _8c1_s_p8_0 = {
  113235. 2, 169,
  113236. _vq_lengthlist__8c1_s_p8_0,
  113237. 1, -526516224, 1616117760, 4, 0,
  113238. _vq_quantlist__8c1_s_p8_0,
  113239. NULL,
  113240. &_vq_auxt__8c1_s_p8_0,
  113241. NULL,
  113242. 0
  113243. };
  113244. static long _vq_quantlist__8c1_s_p8_1[] = {
  113245. 2,
  113246. 1,
  113247. 3,
  113248. 0,
  113249. 4,
  113250. };
  113251. static long _vq_lengthlist__8c1_s_p8_1[] = {
  113252. 2, 3, 3, 5, 5, 6, 6, 6, 5, 5, 6, 6, 6, 5, 5, 6,
  113253. 6, 6, 5, 5, 6, 6, 6, 5, 5,
  113254. };
  113255. static float _vq_quantthresh__8c1_s_p8_1[] = {
  113256. -1.5, -0.5, 0.5, 1.5,
  113257. };
  113258. static long _vq_quantmap__8c1_s_p8_1[] = {
  113259. 3, 1, 0, 2, 4,
  113260. };
  113261. static encode_aux_threshmatch _vq_auxt__8c1_s_p8_1 = {
  113262. _vq_quantthresh__8c1_s_p8_1,
  113263. _vq_quantmap__8c1_s_p8_1,
  113264. 5,
  113265. 5
  113266. };
  113267. static static_codebook _8c1_s_p8_1 = {
  113268. 2, 25,
  113269. _vq_lengthlist__8c1_s_p8_1,
  113270. 1, -533725184, 1611661312, 3, 0,
  113271. _vq_quantlist__8c1_s_p8_1,
  113272. NULL,
  113273. &_vq_auxt__8c1_s_p8_1,
  113274. NULL,
  113275. 0
  113276. };
  113277. static long _vq_quantlist__8c1_s_p9_0[] = {
  113278. 6,
  113279. 5,
  113280. 7,
  113281. 4,
  113282. 8,
  113283. 3,
  113284. 9,
  113285. 2,
  113286. 10,
  113287. 1,
  113288. 11,
  113289. 0,
  113290. 12,
  113291. };
  113292. static long _vq_lengthlist__8c1_s_p9_0[] = {
  113293. 1, 3, 3,10,10,10,10,10,10,10,10,10,10, 5, 6, 6,
  113294. 10,10,10,10,10,10,10,10,10,10, 6, 7, 8,10,10,10,
  113295. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  113296. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  113297. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  113298. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  113299. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  113300. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  113301. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  113302. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  113303. 10,10,10,10,10, 9, 9, 9, 9,
  113304. };
  113305. static float _vq_quantthresh__8c1_s_p9_0[] = {
  113306. -1732.5, -1417.5, -1102.5, -787.5, -472.5, -157.5, 157.5, 472.5,
  113307. 787.5, 1102.5, 1417.5, 1732.5,
  113308. };
  113309. static long _vq_quantmap__8c1_s_p9_0[] = {
  113310. 11, 9, 7, 5, 3, 1, 0, 2,
  113311. 4, 6, 8, 10, 12,
  113312. };
  113313. static encode_aux_threshmatch _vq_auxt__8c1_s_p9_0 = {
  113314. _vq_quantthresh__8c1_s_p9_0,
  113315. _vq_quantmap__8c1_s_p9_0,
  113316. 13,
  113317. 13
  113318. };
  113319. static static_codebook _8c1_s_p9_0 = {
  113320. 2, 169,
  113321. _vq_lengthlist__8c1_s_p9_0,
  113322. 1, -513964032, 1628680192, 4, 0,
  113323. _vq_quantlist__8c1_s_p9_0,
  113324. NULL,
  113325. &_vq_auxt__8c1_s_p9_0,
  113326. NULL,
  113327. 0
  113328. };
  113329. static long _vq_quantlist__8c1_s_p9_1[] = {
  113330. 7,
  113331. 6,
  113332. 8,
  113333. 5,
  113334. 9,
  113335. 4,
  113336. 10,
  113337. 3,
  113338. 11,
  113339. 2,
  113340. 12,
  113341. 1,
  113342. 13,
  113343. 0,
  113344. 14,
  113345. };
  113346. static long _vq_lengthlist__8c1_s_p9_1[] = {
  113347. 1, 4, 4, 5, 5, 7, 7, 9, 9,11,11,12,12,13,13, 6,
  113348. 5, 5, 6, 6, 9, 9,10,10,12,12,12,13,15,14, 6, 5,
  113349. 5, 7, 7, 9, 9,10,10,12,12,12,13,14,13,17, 7, 7,
  113350. 8, 8,10,10,11,11,12,13,13,13,13,13,17, 7, 7, 8,
  113351. 8,10,10,11,11,13,13,13,13,14,14,17,11,11, 9, 9,
  113352. 11,11,12,12,12,13,13,14,15,13,17,12,12, 9, 9,11,
  113353. 11,12,12,13,13,13,13,14,16,17,17,17,11,12,12,12,
  113354. 13,13,13,14,15,14,15,15,17,17,17,12,12,11,11,13,
  113355. 13,14,14,15,14,15,15,17,17,17,15,15,13,13,14,14,
  113356. 15,14,15,15,16,15,17,17,17,15,15,13,13,13,14,14,
  113357. 15,15,15,15,16,17,17,17,17,16,14,15,14,14,15,14,
  113358. 14,15,15,15,17,17,17,17,17,14,14,16,14,15,15,15,
  113359. 15,15,15,17,17,17,17,17,17,16,16,15,17,15,15,14,
  113360. 17,15,17,16,17,17,17,17,16,15,14,15,15,15,15,15,
  113361. 15,
  113362. };
  113363. static float _vq_quantthresh__8c1_s_p9_1[] = {
  113364. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  113365. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  113366. };
  113367. static long _vq_quantmap__8c1_s_p9_1[] = {
  113368. 13, 11, 9, 7, 5, 3, 1, 0,
  113369. 2, 4, 6, 8, 10, 12, 14,
  113370. };
  113371. static encode_aux_threshmatch _vq_auxt__8c1_s_p9_1 = {
  113372. _vq_quantthresh__8c1_s_p9_1,
  113373. _vq_quantmap__8c1_s_p9_1,
  113374. 15,
  113375. 15
  113376. };
  113377. static static_codebook _8c1_s_p9_1 = {
  113378. 2, 225,
  113379. _vq_lengthlist__8c1_s_p9_1,
  113380. 1, -520986624, 1620377600, 4, 0,
  113381. _vq_quantlist__8c1_s_p9_1,
  113382. NULL,
  113383. &_vq_auxt__8c1_s_p9_1,
  113384. NULL,
  113385. 0
  113386. };
  113387. static long _vq_quantlist__8c1_s_p9_2[] = {
  113388. 10,
  113389. 9,
  113390. 11,
  113391. 8,
  113392. 12,
  113393. 7,
  113394. 13,
  113395. 6,
  113396. 14,
  113397. 5,
  113398. 15,
  113399. 4,
  113400. 16,
  113401. 3,
  113402. 17,
  113403. 2,
  113404. 18,
  113405. 1,
  113406. 19,
  113407. 0,
  113408. 20,
  113409. };
  113410. static long _vq_lengthlist__8c1_s_p9_2[] = {
  113411. 2, 4, 4, 6, 6, 7, 7, 8, 8, 8, 8, 9, 8, 9, 9, 9,
  113412. 9, 9, 9, 9, 9,11,11,12, 7, 7, 7, 7, 8, 8, 9, 9,
  113413. 9, 9,10,10,10,10,10,10,10,10,11,11,11, 7, 7, 7,
  113414. 7, 8, 8, 9, 8, 9, 9, 9, 9, 9, 9,10,10,10,10,11,
  113415. 11,12, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9,10,10,10,10,
  113416. 10,10,10,10,11,11,11, 7, 7, 8, 8, 8, 8, 9, 9, 9,
  113417. 9,10,10,10,10,10,10,10,10,11,11,11, 8, 8, 8, 8,
  113418. 9, 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10,11,11,
  113419. 11, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9,10,10,10,10,10,
  113420. 10,10,10,11,12,11, 9, 9, 8, 9, 9, 9, 9, 9,10,10,
  113421. 10,10,10,10,10,10,10,10,11,11,11,11,11, 8, 8, 9,
  113422. 9, 9, 9,10,10,10,10,10,10,10,10,10,10,11,12,11,
  113423. 12,11, 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,
  113424. 10,10,11,11,11,11,11, 9, 9, 9, 9,10,10,10,10,10,
  113425. 10,10,10,10,10,10,10,12,11,12,11,11, 9, 9, 9,10,
  113426. 10,10,10,10,10,10,10,10,10,10,10,10,12,11,11,11,
  113427. 11,11,11,10,10,10,10,10,10,10,10,10,10,10,10,10,
  113428. 11,11,11,12,11,11,12,11,10,10,10,10,10,10,10,10,
  113429. 10,10,10,10,11,10,11,11,11,11,11,11,11,10,10,10,
  113430. 10,10,10,10,10,10,10,10,10,10,10,11,11,12,11,12,
  113431. 11,11,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  113432. 11,11,12,11,12,11,11,11,11,10,10,10,10,10,10,10,
  113433. 10,10,10,10,10,11,11,12,11,11,12,11,11,12,10,10,
  113434. 11,10,10,10,10,10,10,10,10,10,11,11,11,11,11,11,
  113435. 11,11,11,10,10,10,10,10,10,10,10,10,10,10,10,12,
  113436. 12,11,12,11,11,12,12,12,11,11,10,10,10,10,10,10,
  113437. 10,10,10,11,12,12,11,12,12,11,12,11,11,11,11,10,
  113438. 10,10,10,10,10,10,10,10,10,
  113439. };
  113440. static float _vq_quantthresh__8c1_s_p9_2[] = {
  113441. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  113442. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  113443. 6.5, 7.5, 8.5, 9.5,
  113444. };
  113445. static long _vq_quantmap__8c1_s_p9_2[] = {
  113446. 19, 17, 15, 13, 11, 9, 7, 5,
  113447. 3, 1, 0, 2, 4, 6, 8, 10,
  113448. 12, 14, 16, 18, 20,
  113449. };
  113450. static encode_aux_threshmatch _vq_auxt__8c1_s_p9_2 = {
  113451. _vq_quantthresh__8c1_s_p9_2,
  113452. _vq_quantmap__8c1_s_p9_2,
  113453. 21,
  113454. 21
  113455. };
  113456. static static_codebook _8c1_s_p9_2 = {
  113457. 2, 441,
  113458. _vq_lengthlist__8c1_s_p9_2,
  113459. 1, -529268736, 1611661312, 5, 0,
  113460. _vq_quantlist__8c1_s_p9_2,
  113461. NULL,
  113462. &_vq_auxt__8c1_s_p9_2,
  113463. NULL,
  113464. 0
  113465. };
  113466. static long _huff_lengthlist__8c1_s_single[] = {
  113467. 4, 6,18, 8,11, 8, 8, 9, 9,10, 4, 4,18, 5, 9, 5,
  113468. 6, 7, 8,10,18,18,18,18,17,17,17,17,17,17, 7, 5,
  113469. 17, 6,11, 6, 7, 8, 9,12,12, 9,17,12, 8, 8, 9,10,
  113470. 10,13, 7, 5,17, 6, 8, 4, 5, 6, 8,10, 6, 5,17, 6,
  113471. 8, 5, 4, 5, 7, 9, 7, 7,17, 8, 9, 6, 5, 5, 6, 8,
  113472. 8, 8,17, 9,11, 8, 6, 6, 6, 7, 9,10,17,12,12,10,
  113473. 9, 7, 7, 8,
  113474. };
  113475. static static_codebook _huff_book__8c1_s_single = {
  113476. 2, 100,
  113477. _huff_lengthlist__8c1_s_single,
  113478. 0, 0, 0, 0, 0,
  113479. NULL,
  113480. NULL,
  113481. NULL,
  113482. NULL,
  113483. 0
  113484. };
  113485. static long _huff_lengthlist__44c2_s_long[] = {
  113486. 6, 6,12,10,10,10, 9,10,12,12, 6, 1,10, 5, 6, 6,
  113487. 7, 9,11,14,12, 9, 8,11, 7, 8, 9,11,13,15,10, 5,
  113488. 12, 7, 8, 7, 9,12,14,15,10, 6, 7, 8, 5, 6, 7, 9,
  113489. 12,14, 9, 6, 8, 7, 6, 6, 7, 9,12,12, 9, 7, 9, 9,
  113490. 7, 6, 6, 7,10,10,10, 9,10,11, 8, 7, 6, 6, 8,10,
  113491. 12,11,13,13,11,10, 8, 8, 8,10,11,13,15,15,14,13,
  113492. 10, 8, 8, 9,
  113493. };
  113494. static static_codebook _huff_book__44c2_s_long = {
  113495. 2, 100,
  113496. _huff_lengthlist__44c2_s_long,
  113497. 0, 0, 0, 0, 0,
  113498. NULL,
  113499. NULL,
  113500. NULL,
  113501. NULL,
  113502. 0
  113503. };
  113504. static long _vq_quantlist__44c2_s_p1_0[] = {
  113505. 1,
  113506. 0,
  113507. 2,
  113508. };
  113509. static long _vq_lengthlist__44c2_s_p1_0[] = {
  113510. 2, 4, 4, 0, 0, 0, 0, 0, 0, 5, 6, 6, 0, 0, 0, 0,
  113511. 0, 0, 5, 6, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113512. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113513. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113514. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113515. 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0, 0,
  113516. 0, 0, 0, 6, 8, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113517. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113518. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113519. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113520. 0, 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 6, 8, 7, 0, 0,
  113521. 0, 0, 0, 0, 7, 8, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113522. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113523. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113524. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113525. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113526. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113527. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113528. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113529. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113530. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113531. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113532. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113533. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113534. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113535. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113536. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113537. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113538. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113539. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113540. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113541. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113542. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113543. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113544. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113545. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113546. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113547. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113548. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113549. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113550. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113551. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113552. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113553. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113554. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113555. 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0,
  113556. 0, 0, 7, 8, 8, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0,
  113557. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113558. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113559. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113560. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0, 0,
  113561. 0, 0, 0, 8, 9, 9, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0,
  113562. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113563. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113564. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113565. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 8, 8, 0, 0,
  113566. 0, 0, 0, 0, 8, 9, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9,
  113567. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113568. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113569. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113570. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113571. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113572. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113573. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113574. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113575. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113576. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113577. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113578. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113579. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113580. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113581. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113582. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113583. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113584. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113585. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113586. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113587. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113588. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113589. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113590. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113591. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113592. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113593. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113594. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113595. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113596. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113597. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113598. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113599. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113600. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113601. 0, 0, 4, 7, 7, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0,
  113602. 0, 0, 0, 0, 7, 8, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113603. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113604. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113605. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113606. 0, 0, 0, 6, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0,
  113607. 0, 0, 0, 0, 0, 8, 8, 9, 0, 0, 0, 0, 0, 0, 0, 0,
  113608. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113609. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113610. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113611. 0, 0, 0, 0, 7, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9,
  113612. 0, 0, 0, 0, 0, 0, 8, 9, 9, 0, 0, 0, 0, 0, 0, 0,
  113613. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113614. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113615. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113616. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113617. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113618. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113619. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113620. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113621. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113622. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113623. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113624. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113625. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113626. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113627. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113628. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113629. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113630. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113631. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113632. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113633. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113634. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113635. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113636. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113637. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113638. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113639. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113640. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113641. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113642. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113643. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113644. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113645. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113646. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113647. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113648. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113649. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113650. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113651. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113652. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113653. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113654. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113655. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113656. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113657. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113658. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113659. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113660. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113661. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113662. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113663. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113664. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113665. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113666. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113667. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113668. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113669. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113670. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113671. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113672. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113673. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113674. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113675. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113676. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113677. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113678. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113679. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113680. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113681. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113682. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113683. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113684. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113685. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113686. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113687. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113688. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113689. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113690. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113691. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113692. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113693. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113694. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113695. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113696. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113697. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113698. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113699. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113700. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113701. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113702. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113703. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113704. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113705. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113706. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113707. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113708. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113709. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113710. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113711. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113712. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113713. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113714. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113715. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113716. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113717. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113718. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113719. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113720. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113721. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113722. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113723. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113724. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113725. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113726. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113727. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113728. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113729. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113730. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113731. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113732. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113733. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113734. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113735. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113736. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113737. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113738. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113739. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113740. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113741. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113742. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113743. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113744. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113745. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113746. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113747. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113748. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113749. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113750. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113751. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113752. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113753. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113754. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113755. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113756. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113757. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113758. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113759. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113760. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113761. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113762. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113763. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113764. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113765. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113766. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113767. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113768. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113769. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113770. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113771. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113772. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113773. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113774. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113775. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113776. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113777. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113778. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113779. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113780. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113781. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113782. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113783. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113784. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113785. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113786. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113787. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113788. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113789. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113790. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113791. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113792. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113793. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113794. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113795. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113796. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113797. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113798. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113799. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113800. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113801. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113802. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113803. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113804. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113805. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113806. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113807. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113808. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113809. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113810. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113811. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113812. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113813. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113814. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113815. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113816. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113817. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113818. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113819. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113820. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113821. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113822. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113823. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113824. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113825. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113826. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113827. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113828. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113829. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113830. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113831. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113832. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113833. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113834. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113835. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113836. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113837. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113838. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113839. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113840. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113841. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113842. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113843. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113844. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113845. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113846. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113847. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113848. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113849. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113850. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113851. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113852. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113853. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113854. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113855. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113856. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113857. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113858. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113859. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113860. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113861. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113862. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113863. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113864. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113865. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113866. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113867. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113868. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113869. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113870. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113871. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113872. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113873. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113874. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113875. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113876. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113877. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113878. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113879. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113880. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113881. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113882. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113883. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113884. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113885. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113886. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113887. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113888. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113889. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113890. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113891. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113892. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113893. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113894. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113895. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113896. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113897. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113898. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113899. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113900. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113901. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113902. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113903. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113904. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113905. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113906. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113907. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113908. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113909. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113910. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113911. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113912. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113913. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113914. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113915. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113916. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113917. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113918. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113919. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113920. 0,
  113921. };
  113922. static float _vq_quantthresh__44c2_s_p1_0[] = {
  113923. -0.5, 0.5,
  113924. };
  113925. static long _vq_quantmap__44c2_s_p1_0[] = {
  113926. 1, 0, 2,
  113927. };
  113928. static encode_aux_threshmatch _vq_auxt__44c2_s_p1_0 = {
  113929. _vq_quantthresh__44c2_s_p1_0,
  113930. _vq_quantmap__44c2_s_p1_0,
  113931. 3,
  113932. 3
  113933. };
  113934. static static_codebook _44c2_s_p1_0 = {
  113935. 8, 6561,
  113936. _vq_lengthlist__44c2_s_p1_0,
  113937. 1, -535822336, 1611661312, 2, 0,
  113938. _vq_quantlist__44c2_s_p1_0,
  113939. NULL,
  113940. &_vq_auxt__44c2_s_p1_0,
  113941. NULL,
  113942. 0
  113943. };
  113944. static long _vq_quantlist__44c2_s_p2_0[] = {
  113945. 2,
  113946. 1,
  113947. 3,
  113948. 0,
  113949. 4,
  113950. };
  113951. static long _vq_lengthlist__44c2_s_p2_0[] = {
  113952. 1, 4, 4, 0, 0, 0, 7, 7, 0, 0, 0, 7, 7, 0, 0, 0,
  113953. 8, 8, 0, 0, 0, 0, 0, 0, 0, 4, 6, 6, 0, 0, 0, 8,
  113954. 8, 0, 0, 0, 8, 8, 0, 0, 0, 9, 9, 0, 0, 0, 0, 0,
  113955. 0, 0, 4, 6, 6, 0, 0, 0, 8, 8, 0, 0, 0, 8, 8, 0,
  113956. 0, 0, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113957. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113958. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113959. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113960. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113961. 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0, 0,11,11, 0, 0,
  113962. 0,11,11, 0, 0, 0,12,11, 0, 0, 0, 0, 0, 0, 0, 7,
  113963. 8, 8, 0, 0, 0,10,11, 0, 0, 0,11,11, 0, 0, 0,11,
  113964. 12, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113965. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113966. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113967. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113968. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113969. 0, 0, 0, 6, 8, 8, 0, 0, 0,11,11, 0, 0, 0,11,11,
  113970. 0, 0, 0,12,12, 0, 0, 0, 0, 0, 0, 0, 6, 8, 8, 0,
  113971. 0, 0,10,11, 0, 0, 0,10,11, 0, 0, 0,11,11, 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. 8, 9, 9, 0, 0, 0,11,12, 0, 0, 0,11,12, 0, 0, 0,
  113978. 12,11, 0, 0, 0, 0, 0, 0, 0, 8,10, 9, 0, 0, 0,12,
  113979. 11, 0, 0, 0,12,11, 0, 0, 0,11,12, 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,
  113992. };
  113993. static float _vq_quantthresh__44c2_s_p2_0[] = {
  113994. -1.5, -0.5, 0.5, 1.5,
  113995. };
  113996. static long _vq_quantmap__44c2_s_p2_0[] = {
  113997. 3, 1, 0, 2, 4,
  113998. };
  113999. static encode_aux_threshmatch _vq_auxt__44c2_s_p2_0 = {
  114000. _vq_quantthresh__44c2_s_p2_0,
  114001. _vq_quantmap__44c2_s_p2_0,
  114002. 5,
  114003. 5
  114004. };
  114005. static static_codebook _44c2_s_p2_0 = {
  114006. 4, 625,
  114007. _vq_lengthlist__44c2_s_p2_0,
  114008. 1, -533725184, 1611661312, 3, 0,
  114009. _vq_quantlist__44c2_s_p2_0,
  114010. NULL,
  114011. &_vq_auxt__44c2_s_p2_0,
  114012. NULL,
  114013. 0
  114014. };
  114015. static long _vq_quantlist__44c2_s_p3_0[] = {
  114016. 2,
  114017. 1,
  114018. 3,
  114019. 0,
  114020. 4,
  114021. };
  114022. static long _vq_lengthlist__44c2_s_p3_0[] = {
  114023. 2, 4, 3, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114024. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 4, 4, 6, 6, 0, 0,
  114025. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114026. 0, 0, 4, 4, 4, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114027. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 6, 6, 9, 9,
  114028. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114029. 0, 0, 0, 0, 6, 6, 7, 9, 9, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114050. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114051. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114052. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114053. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114054. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114055. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114056. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114057. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114058. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114059. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114060. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114061. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114062. 0,
  114063. };
  114064. static float _vq_quantthresh__44c2_s_p3_0[] = {
  114065. -1.5, -0.5, 0.5, 1.5,
  114066. };
  114067. static long _vq_quantmap__44c2_s_p3_0[] = {
  114068. 3, 1, 0, 2, 4,
  114069. };
  114070. static encode_aux_threshmatch _vq_auxt__44c2_s_p3_0 = {
  114071. _vq_quantthresh__44c2_s_p3_0,
  114072. _vq_quantmap__44c2_s_p3_0,
  114073. 5,
  114074. 5
  114075. };
  114076. static static_codebook _44c2_s_p3_0 = {
  114077. 4, 625,
  114078. _vq_lengthlist__44c2_s_p3_0,
  114079. 1, -533725184, 1611661312, 3, 0,
  114080. _vq_quantlist__44c2_s_p3_0,
  114081. NULL,
  114082. &_vq_auxt__44c2_s_p3_0,
  114083. NULL,
  114084. 0
  114085. };
  114086. static long _vq_quantlist__44c2_s_p4_0[] = {
  114087. 4,
  114088. 3,
  114089. 5,
  114090. 2,
  114091. 6,
  114092. 1,
  114093. 7,
  114094. 0,
  114095. 8,
  114096. };
  114097. static long _vq_lengthlist__44c2_s_p4_0[] = {
  114098. 1, 3, 3, 6, 6, 0, 0, 0, 0, 0, 6, 6, 6, 6, 0, 0,
  114099. 0, 0, 0, 6, 6, 6, 6, 0, 0, 0, 0, 0, 7, 7, 6, 6,
  114100. 0, 0, 0, 0, 0, 0, 0, 6, 7, 0, 0, 0, 0, 0, 0, 0,
  114101. 7, 8, 0, 0, 0, 0, 0, 0, 0, 8, 8, 0, 0, 0, 0, 0,
  114102. 0, 0, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114103. 0,
  114104. };
  114105. static float _vq_quantthresh__44c2_s_p4_0[] = {
  114106. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  114107. };
  114108. static long _vq_quantmap__44c2_s_p4_0[] = {
  114109. 7, 5, 3, 1, 0, 2, 4, 6,
  114110. 8,
  114111. };
  114112. static encode_aux_threshmatch _vq_auxt__44c2_s_p4_0 = {
  114113. _vq_quantthresh__44c2_s_p4_0,
  114114. _vq_quantmap__44c2_s_p4_0,
  114115. 9,
  114116. 9
  114117. };
  114118. static static_codebook _44c2_s_p4_0 = {
  114119. 2, 81,
  114120. _vq_lengthlist__44c2_s_p4_0,
  114121. 1, -531628032, 1611661312, 4, 0,
  114122. _vq_quantlist__44c2_s_p4_0,
  114123. NULL,
  114124. &_vq_auxt__44c2_s_p4_0,
  114125. NULL,
  114126. 0
  114127. };
  114128. static long _vq_quantlist__44c2_s_p5_0[] = {
  114129. 4,
  114130. 3,
  114131. 5,
  114132. 2,
  114133. 6,
  114134. 1,
  114135. 7,
  114136. 0,
  114137. 8,
  114138. };
  114139. static long _vq_lengthlist__44c2_s_p5_0[] = {
  114140. 1, 3, 3, 6, 6, 7, 7, 9, 9, 0, 7, 7, 7, 7, 7, 7,
  114141. 9, 9, 0, 7, 7, 7, 7, 7, 7, 9, 9, 0, 8, 8, 7, 7,
  114142. 8, 8,10,10, 0, 0, 0, 7, 7, 8, 8,10,10, 0, 0, 0,
  114143. 9, 9, 8, 8,10,10, 0, 0, 0, 9, 9, 8, 8,10,10, 0,
  114144. 0, 0,10,10, 9, 9,11,11, 0, 0, 0, 0, 0, 9, 9,11,
  114145. 11,
  114146. };
  114147. static float _vq_quantthresh__44c2_s_p5_0[] = {
  114148. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  114149. };
  114150. static long _vq_quantmap__44c2_s_p5_0[] = {
  114151. 7, 5, 3, 1, 0, 2, 4, 6,
  114152. 8,
  114153. };
  114154. static encode_aux_threshmatch _vq_auxt__44c2_s_p5_0 = {
  114155. _vq_quantthresh__44c2_s_p5_0,
  114156. _vq_quantmap__44c2_s_p5_0,
  114157. 9,
  114158. 9
  114159. };
  114160. static static_codebook _44c2_s_p5_0 = {
  114161. 2, 81,
  114162. _vq_lengthlist__44c2_s_p5_0,
  114163. 1, -531628032, 1611661312, 4, 0,
  114164. _vq_quantlist__44c2_s_p5_0,
  114165. NULL,
  114166. &_vq_auxt__44c2_s_p5_0,
  114167. NULL,
  114168. 0
  114169. };
  114170. static long _vq_quantlist__44c2_s_p6_0[] = {
  114171. 8,
  114172. 7,
  114173. 9,
  114174. 6,
  114175. 10,
  114176. 5,
  114177. 11,
  114178. 4,
  114179. 12,
  114180. 3,
  114181. 13,
  114182. 2,
  114183. 14,
  114184. 1,
  114185. 15,
  114186. 0,
  114187. 16,
  114188. };
  114189. static long _vq_lengthlist__44c2_s_p6_0[] = {
  114190. 1, 4, 3, 6, 6, 8, 8, 9, 9, 9, 9, 9, 9,10,10,11,
  114191. 11, 0, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9,10,10,11,11,
  114192. 12,11, 0, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9,10,10,11,
  114193. 11,11,12, 0, 8, 8, 7, 7, 9, 9,10,10, 9, 9,10,10,
  114194. 11,11,12,12, 0, 0, 0, 7, 7, 9, 9,10,10,10, 9,10,
  114195. 10,11,11,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,10,10,
  114196. 11,11,11,11,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,10,
  114197. 10,11,11,12,12,12,12, 0, 0, 0, 9, 9, 9, 9,10,10,
  114198. 10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 9, 9,10,
  114199. 10,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9, 9,
  114200. 10,10,11,11,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9,
  114201. 9,10,10,11,11,11,11,12,12,13,13, 0, 0, 0, 0, 0,
  114202. 10,10,10,10,11,11,12,12,13,12,13,13, 0, 0, 0, 0,
  114203. 0, 0, 0,10,10,11,11,12,12,13,13,13,13, 0, 0, 0,
  114204. 0, 0, 0, 0,11,11,12,12,12,12,13,13,13,14, 0, 0,
  114205. 0, 0, 0, 0, 0,11,11,12,12,12,12,13,13,13,14, 0,
  114206. 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,13,13,14,14,
  114207. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,13,13,13,13,14,
  114208. 14,
  114209. };
  114210. static float _vq_quantthresh__44c2_s_p6_0[] = {
  114211. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  114212. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  114213. };
  114214. static long _vq_quantmap__44c2_s_p6_0[] = {
  114215. 15, 13, 11, 9, 7, 5, 3, 1,
  114216. 0, 2, 4, 6, 8, 10, 12, 14,
  114217. 16,
  114218. };
  114219. static encode_aux_threshmatch _vq_auxt__44c2_s_p6_0 = {
  114220. _vq_quantthresh__44c2_s_p6_0,
  114221. _vq_quantmap__44c2_s_p6_0,
  114222. 17,
  114223. 17
  114224. };
  114225. static static_codebook _44c2_s_p6_0 = {
  114226. 2, 289,
  114227. _vq_lengthlist__44c2_s_p6_0,
  114228. 1, -529530880, 1611661312, 5, 0,
  114229. _vq_quantlist__44c2_s_p6_0,
  114230. NULL,
  114231. &_vq_auxt__44c2_s_p6_0,
  114232. NULL,
  114233. 0
  114234. };
  114235. static long _vq_quantlist__44c2_s_p7_0[] = {
  114236. 1,
  114237. 0,
  114238. 2,
  114239. };
  114240. static long _vq_lengthlist__44c2_s_p7_0[] = {
  114241. 1, 4, 4, 7, 6, 6, 7, 6, 6, 4, 7, 7,10, 9, 9,11,
  114242. 9, 9, 4, 7, 7,10, 9, 9,10, 9, 9, 7,10,10,11,10,
  114243. 11,11,10,11, 6, 9, 9,11,10,10,11,10,10, 6, 9, 9,
  114244. 11,10,11,11,10,10, 7,11,10,11,11,11,12,11,11, 6,
  114245. 9, 9,11,10,10,11,11,10, 6, 9, 9,11,10,10,12,10,
  114246. 11,
  114247. };
  114248. static float _vq_quantthresh__44c2_s_p7_0[] = {
  114249. -5.5, 5.5,
  114250. };
  114251. static long _vq_quantmap__44c2_s_p7_0[] = {
  114252. 1, 0, 2,
  114253. };
  114254. static encode_aux_threshmatch _vq_auxt__44c2_s_p7_0 = {
  114255. _vq_quantthresh__44c2_s_p7_0,
  114256. _vq_quantmap__44c2_s_p7_0,
  114257. 3,
  114258. 3
  114259. };
  114260. static static_codebook _44c2_s_p7_0 = {
  114261. 4, 81,
  114262. _vq_lengthlist__44c2_s_p7_0,
  114263. 1, -529137664, 1618345984, 2, 0,
  114264. _vq_quantlist__44c2_s_p7_0,
  114265. NULL,
  114266. &_vq_auxt__44c2_s_p7_0,
  114267. NULL,
  114268. 0
  114269. };
  114270. static long _vq_quantlist__44c2_s_p7_1[] = {
  114271. 5,
  114272. 4,
  114273. 6,
  114274. 3,
  114275. 7,
  114276. 2,
  114277. 8,
  114278. 1,
  114279. 9,
  114280. 0,
  114281. 10,
  114282. };
  114283. static long _vq_lengthlist__44c2_s_p7_1[] = {
  114284. 2, 3, 4, 6, 6, 7, 7, 7, 7, 7, 7, 9, 7, 7, 6, 6,
  114285. 7, 7, 8, 8, 8, 8, 9, 6, 6, 6, 6, 7, 7, 8, 8, 8,
  114286. 8,10, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8,10,10,10, 7,
  114287. 7, 7, 7, 8, 8, 8, 8,10,10,10, 7, 7, 8, 8, 8, 8,
  114288. 8, 8,10,10,10, 7, 8, 8, 8, 8, 8, 8, 8,10,10,10,
  114289. 8, 8, 8, 8, 8, 8, 8, 8,10,10,10,10,10, 8, 8, 8,
  114290. 8, 8, 8,10,10,10,10,10, 9, 9, 8, 8, 8, 8,10,10,
  114291. 10,10,10, 8, 8, 8, 8, 8, 8,
  114292. };
  114293. static float _vq_quantthresh__44c2_s_p7_1[] = {
  114294. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  114295. 3.5, 4.5,
  114296. };
  114297. static long _vq_quantmap__44c2_s_p7_1[] = {
  114298. 9, 7, 5, 3, 1, 0, 2, 4,
  114299. 6, 8, 10,
  114300. };
  114301. static encode_aux_threshmatch _vq_auxt__44c2_s_p7_1 = {
  114302. _vq_quantthresh__44c2_s_p7_1,
  114303. _vq_quantmap__44c2_s_p7_1,
  114304. 11,
  114305. 11
  114306. };
  114307. static static_codebook _44c2_s_p7_1 = {
  114308. 2, 121,
  114309. _vq_lengthlist__44c2_s_p7_1,
  114310. 1, -531365888, 1611661312, 4, 0,
  114311. _vq_quantlist__44c2_s_p7_1,
  114312. NULL,
  114313. &_vq_auxt__44c2_s_p7_1,
  114314. NULL,
  114315. 0
  114316. };
  114317. static long _vq_quantlist__44c2_s_p8_0[] = {
  114318. 6,
  114319. 5,
  114320. 7,
  114321. 4,
  114322. 8,
  114323. 3,
  114324. 9,
  114325. 2,
  114326. 10,
  114327. 1,
  114328. 11,
  114329. 0,
  114330. 12,
  114331. };
  114332. static long _vq_lengthlist__44c2_s_p8_0[] = {
  114333. 1, 4, 4, 6, 6, 7, 7, 7, 7, 8, 8, 9, 9, 6, 5, 5,
  114334. 7, 7, 8, 8, 8, 8, 9, 9,10,10, 7, 6, 5, 7, 7, 8,
  114335. 8, 8, 8, 9, 9,10,10, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  114336. 10,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  114337. 11, 0,12,12, 9, 9,10,10,10,10,11,11,11,11, 0,13,
  114338. 13, 9, 9,10,10,10,10,11,11,12,12, 0, 0, 0,10,10,
  114339. 10,10,11,11,12,12,12,13, 0, 0, 0,10,10,10,10,11,
  114340. 11,12,12,12,12, 0, 0, 0,14,14,10,11,11,11,12,12,
  114341. 13,13, 0, 0, 0,14,14,11,10,11,11,13,12,13,13, 0,
  114342. 0, 0, 0, 0,12,12,11,12,13,12,14,14, 0, 0, 0, 0,
  114343. 0,12,12,12,12,13,12,14,14,
  114344. };
  114345. static float _vq_quantthresh__44c2_s_p8_0[] = {
  114346. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  114347. 12.5, 17.5, 22.5, 27.5,
  114348. };
  114349. static long _vq_quantmap__44c2_s_p8_0[] = {
  114350. 11, 9, 7, 5, 3, 1, 0, 2,
  114351. 4, 6, 8, 10, 12,
  114352. };
  114353. static encode_aux_threshmatch _vq_auxt__44c2_s_p8_0 = {
  114354. _vq_quantthresh__44c2_s_p8_0,
  114355. _vq_quantmap__44c2_s_p8_0,
  114356. 13,
  114357. 13
  114358. };
  114359. static static_codebook _44c2_s_p8_0 = {
  114360. 2, 169,
  114361. _vq_lengthlist__44c2_s_p8_0,
  114362. 1, -526516224, 1616117760, 4, 0,
  114363. _vq_quantlist__44c2_s_p8_0,
  114364. NULL,
  114365. &_vq_auxt__44c2_s_p8_0,
  114366. NULL,
  114367. 0
  114368. };
  114369. static long _vq_quantlist__44c2_s_p8_1[] = {
  114370. 2,
  114371. 1,
  114372. 3,
  114373. 0,
  114374. 4,
  114375. };
  114376. static long _vq_lengthlist__44c2_s_p8_1[] = {
  114377. 2, 4, 4, 5, 4, 6, 5, 5, 5, 5, 6, 5, 5, 5, 5, 6,
  114378. 5, 5, 5, 5, 6, 6, 6, 5, 5,
  114379. };
  114380. static float _vq_quantthresh__44c2_s_p8_1[] = {
  114381. -1.5, -0.5, 0.5, 1.5,
  114382. };
  114383. static long _vq_quantmap__44c2_s_p8_1[] = {
  114384. 3, 1, 0, 2, 4,
  114385. };
  114386. static encode_aux_threshmatch _vq_auxt__44c2_s_p8_1 = {
  114387. _vq_quantthresh__44c2_s_p8_1,
  114388. _vq_quantmap__44c2_s_p8_1,
  114389. 5,
  114390. 5
  114391. };
  114392. static static_codebook _44c2_s_p8_1 = {
  114393. 2, 25,
  114394. _vq_lengthlist__44c2_s_p8_1,
  114395. 1, -533725184, 1611661312, 3, 0,
  114396. _vq_quantlist__44c2_s_p8_1,
  114397. NULL,
  114398. &_vq_auxt__44c2_s_p8_1,
  114399. NULL,
  114400. 0
  114401. };
  114402. static long _vq_quantlist__44c2_s_p9_0[] = {
  114403. 6,
  114404. 5,
  114405. 7,
  114406. 4,
  114407. 8,
  114408. 3,
  114409. 9,
  114410. 2,
  114411. 10,
  114412. 1,
  114413. 11,
  114414. 0,
  114415. 12,
  114416. };
  114417. static long _vq_lengthlist__44c2_s_p9_0[] = {
  114418. 1, 5, 4,12,12,12,12,12,12,12,12,12,12, 4, 9, 8,
  114419. 11,11,11,11,11,11,11,11,11,11, 2, 8, 7,11,11,11,
  114420. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  114421. 11,11,11,11,11,11,10,11,11,11,11,11,11,11,11,11,
  114422. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  114423. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  114424. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  114425. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  114426. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  114427. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  114428. 11,11,11,11,11,11,11,11,11,
  114429. };
  114430. static float _vq_quantthresh__44c2_s_p9_0[] = {
  114431. -1215.5, -994.5, -773.5, -552.5, -331.5, -110.5, 110.5, 331.5,
  114432. 552.5, 773.5, 994.5, 1215.5,
  114433. };
  114434. static long _vq_quantmap__44c2_s_p9_0[] = {
  114435. 11, 9, 7, 5, 3, 1, 0, 2,
  114436. 4, 6, 8, 10, 12,
  114437. };
  114438. static encode_aux_threshmatch _vq_auxt__44c2_s_p9_0 = {
  114439. _vq_quantthresh__44c2_s_p9_0,
  114440. _vq_quantmap__44c2_s_p9_0,
  114441. 13,
  114442. 13
  114443. };
  114444. static static_codebook _44c2_s_p9_0 = {
  114445. 2, 169,
  114446. _vq_lengthlist__44c2_s_p9_0,
  114447. 1, -514541568, 1627103232, 4, 0,
  114448. _vq_quantlist__44c2_s_p9_0,
  114449. NULL,
  114450. &_vq_auxt__44c2_s_p9_0,
  114451. NULL,
  114452. 0
  114453. };
  114454. static long _vq_quantlist__44c2_s_p9_1[] = {
  114455. 6,
  114456. 5,
  114457. 7,
  114458. 4,
  114459. 8,
  114460. 3,
  114461. 9,
  114462. 2,
  114463. 10,
  114464. 1,
  114465. 11,
  114466. 0,
  114467. 12,
  114468. };
  114469. static long _vq_lengthlist__44c2_s_p9_1[] = {
  114470. 1, 4, 4, 6, 6, 7, 6, 8, 8,10, 9,10,10, 6, 5, 5,
  114471. 7, 7, 8, 7,10, 9,11,11,12,13, 6, 5, 5, 7, 7, 8,
  114472. 8,10,10,11,11,13,13,18, 8, 8, 8, 8, 9, 9,10,10,
  114473. 12,12,12,13,18, 8, 8, 8, 8, 9, 9,10,10,12,12,13,
  114474. 13,18,11,11, 8, 8,10,10,11,11,12,11,13,12,18,11,
  114475. 11, 9, 7,10,10,11,11,11,12,12,13,17,17,17,10,10,
  114476. 11,11,12,12,12,10,12,12,17,17,17,11,10,11,10,13,
  114477. 12,11,12,12,12,17,17,17,15,14,11,11,12,11,13,10,
  114478. 13,12,17,17,17,14,14,12,10,11,11,13,13,13,13,17,
  114479. 17,16,17,16,13,13,12,10,13,10,14,13,17,16,17,16,
  114480. 17,13,12,12,10,13,11,14,14,
  114481. };
  114482. static float _vq_quantthresh__44c2_s_p9_1[] = {
  114483. -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5, 25.5,
  114484. 42.5, 59.5, 76.5, 93.5,
  114485. };
  114486. static long _vq_quantmap__44c2_s_p9_1[] = {
  114487. 11, 9, 7, 5, 3, 1, 0, 2,
  114488. 4, 6, 8, 10, 12,
  114489. };
  114490. static encode_aux_threshmatch _vq_auxt__44c2_s_p9_1 = {
  114491. _vq_quantthresh__44c2_s_p9_1,
  114492. _vq_quantmap__44c2_s_p9_1,
  114493. 13,
  114494. 13
  114495. };
  114496. static static_codebook _44c2_s_p9_1 = {
  114497. 2, 169,
  114498. _vq_lengthlist__44c2_s_p9_1,
  114499. 1, -522616832, 1620115456, 4, 0,
  114500. _vq_quantlist__44c2_s_p9_1,
  114501. NULL,
  114502. &_vq_auxt__44c2_s_p9_1,
  114503. NULL,
  114504. 0
  114505. };
  114506. static long _vq_quantlist__44c2_s_p9_2[] = {
  114507. 8,
  114508. 7,
  114509. 9,
  114510. 6,
  114511. 10,
  114512. 5,
  114513. 11,
  114514. 4,
  114515. 12,
  114516. 3,
  114517. 13,
  114518. 2,
  114519. 14,
  114520. 1,
  114521. 15,
  114522. 0,
  114523. 16,
  114524. };
  114525. static long _vq_lengthlist__44c2_s_p9_2[] = {
  114526. 2, 4, 4, 6, 6, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8,
  114527. 8,10, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9,
  114528. 9, 9,10, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 9, 9, 9,
  114529. 9, 9, 9,10, 8, 8, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9,
  114530. 9, 9, 9, 9,10,10,10, 8, 7, 8, 8, 8, 8, 9, 9, 9,
  114531. 9, 9, 9, 9, 9,10,11,11, 8, 8, 8, 8, 9, 9, 9, 9,
  114532. 9, 9,10, 9, 9, 9,10,11,10, 8, 8, 8, 8, 9, 9, 9,
  114533. 9, 9, 9, 9,10,10,10,10,11,10, 8, 8, 9, 9, 9, 9,
  114534. 9, 9,10, 9, 9,10, 9,10,11,10,11,11,11, 8, 8, 9,
  114535. 9, 9, 9, 9, 9, 9, 9,10,10,11,11,11,11,11, 9, 9,
  114536. 9, 9, 9, 9,10, 9, 9, 9,10,10,11,11,11,11,11, 9,
  114537. 9, 9, 9, 9, 9, 9, 9, 9,10, 9,10,11,11,11,11,11,
  114538. 9, 9, 9, 9,10,10, 9, 9, 9,10,10,10,11,11,11,11,
  114539. 11,11,11, 9, 9, 9,10, 9, 9,10,10,10,10,11,11,10,
  114540. 11,11,11,11,10, 9,10,10, 9, 9, 9, 9,10,10,11,10,
  114541. 11,11,11,11,11, 9, 9, 9, 9,10, 9,10,10,10,10,11,
  114542. 10,11,11,11,11,11,10,10, 9, 9,10, 9,10,10,10,10,
  114543. 10,10,10,11,11,11,11,11,11, 9, 9,10, 9,10, 9,10,
  114544. 10,
  114545. };
  114546. static float _vq_quantthresh__44c2_s_p9_2[] = {
  114547. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  114548. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  114549. };
  114550. static long _vq_quantmap__44c2_s_p9_2[] = {
  114551. 15, 13, 11, 9, 7, 5, 3, 1,
  114552. 0, 2, 4, 6, 8, 10, 12, 14,
  114553. 16,
  114554. };
  114555. static encode_aux_threshmatch _vq_auxt__44c2_s_p9_2 = {
  114556. _vq_quantthresh__44c2_s_p9_2,
  114557. _vq_quantmap__44c2_s_p9_2,
  114558. 17,
  114559. 17
  114560. };
  114561. static static_codebook _44c2_s_p9_2 = {
  114562. 2, 289,
  114563. _vq_lengthlist__44c2_s_p9_2,
  114564. 1, -529530880, 1611661312, 5, 0,
  114565. _vq_quantlist__44c2_s_p9_2,
  114566. NULL,
  114567. &_vq_auxt__44c2_s_p9_2,
  114568. NULL,
  114569. 0
  114570. };
  114571. static long _huff_lengthlist__44c2_s_short[] = {
  114572. 11, 9,13,12,12,11,12,12,13,15, 8, 2,11, 4, 8, 5,
  114573. 7,10,12,15,13, 7,10, 9, 8, 8,10,13,17,17,11, 4,
  114574. 12, 5, 9, 5, 8,11,14,16,12, 6, 8, 7, 6, 6, 8,11,
  114575. 13,16,11, 4, 9, 5, 6, 4, 6,10,13,16,11, 6,11, 7,
  114576. 7, 6, 7,10,13,15,13, 9,12, 9, 8, 6, 8,10,12,14,
  114577. 14,10,10, 8, 6, 5, 6, 9,11,13,15,11,11, 9, 6, 5,
  114578. 6, 8, 9,12,
  114579. };
  114580. static static_codebook _huff_book__44c2_s_short = {
  114581. 2, 100,
  114582. _huff_lengthlist__44c2_s_short,
  114583. 0, 0, 0, 0, 0,
  114584. NULL,
  114585. NULL,
  114586. NULL,
  114587. NULL,
  114588. 0
  114589. };
  114590. static long _huff_lengthlist__44c3_s_long[] = {
  114591. 5, 6,11,11,11,11,10,10,12,11, 5, 2,11, 5, 6, 6,
  114592. 7, 9,11,13,13,10, 7,11, 6, 7, 8, 9,10,12,11, 5,
  114593. 11, 6, 8, 7, 9,11,14,15,11, 6, 6, 8, 4, 5, 7, 8,
  114594. 10,13,10, 5, 7, 7, 5, 5, 6, 8,10,11,10, 7, 7, 8,
  114595. 6, 5, 5, 7, 9, 9,11, 8, 8,11, 8, 7, 6, 6, 7, 9,
  114596. 12,11,10,13, 9, 9, 7, 7, 7, 9,11,13,12,15,12,11,
  114597. 9, 8, 8, 8,
  114598. };
  114599. static static_codebook _huff_book__44c3_s_long = {
  114600. 2, 100,
  114601. _huff_lengthlist__44c3_s_long,
  114602. 0, 0, 0, 0, 0,
  114603. NULL,
  114604. NULL,
  114605. NULL,
  114606. NULL,
  114607. 0
  114608. };
  114609. static long _vq_quantlist__44c3_s_p1_0[] = {
  114610. 1,
  114611. 0,
  114612. 2,
  114613. };
  114614. static long _vq_lengthlist__44c3_s_p1_0[] = {
  114615. 2, 4, 4, 0, 0, 0, 0, 0, 0, 5, 6, 6, 0, 0, 0, 0,
  114616. 0, 0, 5, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114617. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114618. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114619. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114620. 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0, 0,
  114621. 0, 0, 0, 6, 7, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114622. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114623. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114624. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114625. 0, 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 6, 8, 7, 0, 0,
  114626. 0, 0, 0, 0, 7, 8, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114627. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114628. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114629. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114630. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114631. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114632. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114633. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114634. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114635. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114636. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114637. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114638. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114639. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114640. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114641. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114642. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114643. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114644. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114645. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114646. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114647. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114648. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114649. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114650. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114651. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114652. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114653. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114654. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114655. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114656. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114657. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114658. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114659. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114660. 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0,
  114661. 0, 0, 7, 8, 8, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0,
  114662. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114663. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114664. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114665. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0, 0,
  114666. 0, 0, 0, 8, 8, 9, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0,
  114667. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114668. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114669. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114670. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 8, 8, 0, 0,
  114671. 0, 0, 0, 0, 7, 9, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9,
  114672. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114673. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114674. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114675. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114676. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114677. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114678. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114679. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114680. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114681. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114682. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114683. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114684. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114685. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114686. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114687. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114688. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114689. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114690. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114691. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114692. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114693. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114694. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114695. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114696. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114697. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114698. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114699. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114700. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114701. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114702. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114703. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114704. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114705. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114706. 0, 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0,
  114707. 0, 0, 0, 0, 7, 8, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114708. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114709. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114710. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114711. 0, 0, 0, 6, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0,
  114712. 0, 0, 0, 0, 0, 7, 8, 9, 0, 0, 0, 0, 0, 0, 0, 0,
  114713. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114714. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114715. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114716. 0, 0, 0, 0, 6, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9,
  114717. 0, 0, 0, 0, 0, 0, 8, 9, 8, 0, 0, 0, 0, 0, 0, 0,
  114718. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114719. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114720. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114721. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114722. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114723. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114724. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114725. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114726. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114727. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114728. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114729. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114730. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114731. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114732. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114733. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114734. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114735. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114736. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114737. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114738. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114739. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114740. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114741. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114742. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114743. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114744. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114745. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114746. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114747. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114748. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114749. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114750. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114751. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114752. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114753. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114754. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114755. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114756. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114757. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114758. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114759. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114760. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114761. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114762. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114763. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114764. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114765. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114766. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114767. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114768. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114769. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114770. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114771. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114772. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114773. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114774. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114775. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114776. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114777. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114778. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114779. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114780. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114781. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114782. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114783. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114784. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114785. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114786. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114787. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114788. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114789. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114790. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114791. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114792. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114793. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114794. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114795. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114796. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114797. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114798. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114799. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114800. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114801. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114802. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114803. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114804. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114805. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114806. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114807. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114808. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114809. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114810. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114811. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114812. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114813. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114814. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114815. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114816. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114817. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114818. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114819. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114820. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114821. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114822. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114823. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114824. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114825. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114826. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114827. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114828. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114829. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114830. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114831. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114832. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114833. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114834. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114835. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114836. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114837. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114838. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114839. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114840. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114841. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114842. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114843. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114844. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114845. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114846. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114847. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114848. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114849. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114850. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114851. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114852. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114853. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114854. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114855. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114856. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114857. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114858. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114859. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114860. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114861. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114862. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114863. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114864. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114865. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114866. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114867. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114868. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114869. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114870. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114871. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114872. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114873. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114874. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114875. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114876. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114877. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114878. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114879. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114880. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114881. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114882. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114883. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114884. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114885. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114886. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114887. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114888. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114889. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114890. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114891. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114892. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114893. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114894. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114895. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114896. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114897. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114898. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114899. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114900. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114901. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114902. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114903. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114904. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114905. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114906. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114907. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114908. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114909. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114910. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114911. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114912. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114913. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114914. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114915. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114916. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114917. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114918. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114919. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114920. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114921. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114922. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114923. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114924. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114925. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114926. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114927. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114928. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114929. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114930. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114931. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114932. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114933. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114934. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114935. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114936. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114937. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114938. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114939. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114940. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114941. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114942. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114943. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114944. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114945. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114946. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114947. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114948. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114949. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114950. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114951. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114952. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114953. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114954. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114955. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114956. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114957. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114958. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114959. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114960. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114961. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114962. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114963. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114964. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114965. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114966. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114967. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114968. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114969. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114970. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114971. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114972. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114973. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114974. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114975. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114976. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114977. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114978. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114979. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114980. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114981. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114982. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114983. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114984. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114985. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114986. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114987. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114988. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114989. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114990. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114991. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114992. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114993. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114994. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114995. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114996. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114997. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114998. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114999. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115000. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115001. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115002. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115003. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115004. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115005. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115006. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115007. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115008. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115009. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115010. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115011. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115012. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115013. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115014. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115015. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115016. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115017. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115018. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115019. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115020. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115021. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115022. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115023. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115024. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115025. 0,
  115026. };
  115027. static float _vq_quantthresh__44c3_s_p1_0[] = {
  115028. -0.5, 0.5,
  115029. };
  115030. static long _vq_quantmap__44c3_s_p1_0[] = {
  115031. 1, 0, 2,
  115032. };
  115033. static encode_aux_threshmatch _vq_auxt__44c3_s_p1_0 = {
  115034. _vq_quantthresh__44c3_s_p1_0,
  115035. _vq_quantmap__44c3_s_p1_0,
  115036. 3,
  115037. 3
  115038. };
  115039. static static_codebook _44c3_s_p1_0 = {
  115040. 8, 6561,
  115041. _vq_lengthlist__44c3_s_p1_0,
  115042. 1, -535822336, 1611661312, 2, 0,
  115043. _vq_quantlist__44c3_s_p1_0,
  115044. NULL,
  115045. &_vq_auxt__44c3_s_p1_0,
  115046. NULL,
  115047. 0
  115048. };
  115049. static long _vq_quantlist__44c3_s_p2_0[] = {
  115050. 2,
  115051. 1,
  115052. 3,
  115053. 0,
  115054. 4,
  115055. };
  115056. static long _vq_lengthlist__44c3_s_p2_0[] = {
  115057. 2, 5, 5, 0, 0, 0, 5, 5, 0, 0, 0, 5, 5, 0, 0, 0,
  115058. 7, 8, 0, 0, 0, 0, 0, 0, 0, 5, 6, 6, 0, 0, 0, 7,
  115059. 7, 0, 0, 0, 7, 7, 0, 0, 0,10,10, 0, 0, 0, 0, 0,
  115060. 0, 0, 5, 6, 6, 0, 0, 0, 7, 7, 0, 0, 0, 7, 7, 0,
  115061. 0, 0,10,10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115062. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115063. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115064. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115065. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115066. 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 7, 7, 0, 0,
  115067. 0, 7, 7, 0, 0, 0, 9, 9, 0, 0, 0, 0, 0, 0, 0, 5,
  115068. 7, 7, 0, 0, 0, 7, 7, 0, 0, 0, 7, 7, 0, 0, 0, 9,
  115069. 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115070. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115071. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115072. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115073. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115074. 0, 0, 0, 5, 7, 7, 0, 0, 0, 7, 7, 0, 0, 0, 7, 7,
  115075. 0, 0, 0, 9, 9, 0, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0,
  115076. 0, 0, 7, 7, 0, 0, 0, 7, 7, 0, 0, 0, 9, 9, 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. 8,10,10, 0, 0, 0, 9, 9, 0, 0, 0, 9, 9, 0, 0, 0,
  115083. 10,10, 0, 0, 0, 0, 0, 0, 0, 8,10,10, 0, 0, 0, 9,
  115084. 9, 0, 0, 0, 9, 9, 0, 0, 0,10,10, 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,
  115097. };
  115098. static float _vq_quantthresh__44c3_s_p2_0[] = {
  115099. -1.5, -0.5, 0.5, 1.5,
  115100. };
  115101. static long _vq_quantmap__44c3_s_p2_0[] = {
  115102. 3, 1, 0, 2, 4,
  115103. };
  115104. static encode_aux_threshmatch _vq_auxt__44c3_s_p2_0 = {
  115105. _vq_quantthresh__44c3_s_p2_0,
  115106. _vq_quantmap__44c3_s_p2_0,
  115107. 5,
  115108. 5
  115109. };
  115110. static static_codebook _44c3_s_p2_0 = {
  115111. 4, 625,
  115112. _vq_lengthlist__44c3_s_p2_0,
  115113. 1, -533725184, 1611661312, 3, 0,
  115114. _vq_quantlist__44c3_s_p2_0,
  115115. NULL,
  115116. &_vq_auxt__44c3_s_p2_0,
  115117. NULL,
  115118. 0
  115119. };
  115120. static long _vq_quantlist__44c3_s_p3_0[] = {
  115121. 2,
  115122. 1,
  115123. 3,
  115124. 0,
  115125. 4,
  115126. };
  115127. static long _vq_lengthlist__44c3_s_p3_0[] = {
  115128. 2, 4, 3, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115129. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 4, 4, 6, 6, 0, 0,
  115130. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115131. 0, 0, 4, 4, 4, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115132. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 6, 6, 9, 9,
  115133. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115134. 0, 0, 0, 0, 6, 6, 7, 9, 9, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115155. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115156. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115157. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115158. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115159. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115160. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115161. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115162. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115163. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115164. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115165. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115166. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115167. 0,
  115168. };
  115169. static float _vq_quantthresh__44c3_s_p3_0[] = {
  115170. -1.5, -0.5, 0.5, 1.5,
  115171. };
  115172. static long _vq_quantmap__44c3_s_p3_0[] = {
  115173. 3, 1, 0, 2, 4,
  115174. };
  115175. static encode_aux_threshmatch _vq_auxt__44c3_s_p3_0 = {
  115176. _vq_quantthresh__44c3_s_p3_0,
  115177. _vq_quantmap__44c3_s_p3_0,
  115178. 5,
  115179. 5
  115180. };
  115181. static static_codebook _44c3_s_p3_0 = {
  115182. 4, 625,
  115183. _vq_lengthlist__44c3_s_p3_0,
  115184. 1, -533725184, 1611661312, 3, 0,
  115185. _vq_quantlist__44c3_s_p3_0,
  115186. NULL,
  115187. &_vq_auxt__44c3_s_p3_0,
  115188. NULL,
  115189. 0
  115190. };
  115191. static long _vq_quantlist__44c3_s_p4_0[] = {
  115192. 4,
  115193. 3,
  115194. 5,
  115195. 2,
  115196. 6,
  115197. 1,
  115198. 7,
  115199. 0,
  115200. 8,
  115201. };
  115202. static long _vq_lengthlist__44c3_s_p4_0[] = {
  115203. 2, 3, 3, 6, 6, 0, 0, 0, 0, 0, 4, 4, 6, 6, 0, 0,
  115204. 0, 0, 0, 4, 4, 6, 6, 0, 0, 0, 0, 0, 5, 5, 6, 6,
  115205. 0, 0, 0, 0, 0, 0, 0, 6, 6, 0, 0, 0, 0, 0, 0, 0,
  115206. 7, 8, 0, 0, 0, 0, 0, 0, 0, 7, 7, 0, 0, 0, 0, 0,
  115207. 0, 0, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115208. 0,
  115209. };
  115210. static float _vq_quantthresh__44c3_s_p4_0[] = {
  115211. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  115212. };
  115213. static long _vq_quantmap__44c3_s_p4_0[] = {
  115214. 7, 5, 3, 1, 0, 2, 4, 6,
  115215. 8,
  115216. };
  115217. static encode_aux_threshmatch _vq_auxt__44c3_s_p4_0 = {
  115218. _vq_quantthresh__44c3_s_p4_0,
  115219. _vq_quantmap__44c3_s_p4_0,
  115220. 9,
  115221. 9
  115222. };
  115223. static static_codebook _44c3_s_p4_0 = {
  115224. 2, 81,
  115225. _vq_lengthlist__44c3_s_p4_0,
  115226. 1, -531628032, 1611661312, 4, 0,
  115227. _vq_quantlist__44c3_s_p4_0,
  115228. NULL,
  115229. &_vq_auxt__44c3_s_p4_0,
  115230. NULL,
  115231. 0
  115232. };
  115233. static long _vq_quantlist__44c3_s_p5_0[] = {
  115234. 4,
  115235. 3,
  115236. 5,
  115237. 2,
  115238. 6,
  115239. 1,
  115240. 7,
  115241. 0,
  115242. 8,
  115243. };
  115244. static long _vq_lengthlist__44c3_s_p5_0[] = {
  115245. 1, 3, 4, 6, 6, 7, 7, 9, 9, 0, 5, 5, 7, 7, 7, 8,
  115246. 9, 9, 0, 5, 5, 7, 7, 8, 8, 9, 9, 0, 7, 7, 8, 8,
  115247. 8, 8,10,10, 0, 0, 0, 8, 8, 8, 8,10,10, 0, 0, 0,
  115248. 9, 9, 9, 9,10,10, 0, 0, 0, 9, 9, 9, 9,10,10, 0,
  115249. 0, 0,10,10,10,10,11,11, 0, 0, 0, 0, 0,10,10,11,
  115250. 11,
  115251. };
  115252. static float _vq_quantthresh__44c3_s_p5_0[] = {
  115253. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  115254. };
  115255. static long _vq_quantmap__44c3_s_p5_0[] = {
  115256. 7, 5, 3, 1, 0, 2, 4, 6,
  115257. 8,
  115258. };
  115259. static encode_aux_threshmatch _vq_auxt__44c3_s_p5_0 = {
  115260. _vq_quantthresh__44c3_s_p5_0,
  115261. _vq_quantmap__44c3_s_p5_0,
  115262. 9,
  115263. 9
  115264. };
  115265. static static_codebook _44c3_s_p5_0 = {
  115266. 2, 81,
  115267. _vq_lengthlist__44c3_s_p5_0,
  115268. 1, -531628032, 1611661312, 4, 0,
  115269. _vq_quantlist__44c3_s_p5_0,
  115270. NULL,
  115271. &_vq_auxt__44c3_s_p5_0,
  115272. NULL,
  115273. 0
  115274. };
  115275. static long _vq_quantlist__44c3_s_p6_0[] = {
  115276. 8,
  115277. 7,
  115278. 9,
  115279. 6,
  115280. 10,
  115281. 5,
  115282. 11,
  115283. 4,
  115284. 12,
  115285. 3,
  115286. 13,
  115287. 2,
  115288. 14,
  115289. 1,
  115290. 15,
  115291. 0,
  115292. 16,
  115293. };
  115294. static long _vq_lengthlist__44c3_s_p6_0[] = {
  115295. 2, 3, 3, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,10,11,
  115296. 10, 0, 5, 5, 7, 7, 8, 8, 9, 9, 9, 9,10,10,10,10,
  115297. 11,11, 0, 5, 5, 7, 7, 8, 8, 9, 9, 9, 9,10,10,10,
  115298. 10,11,11, 0, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  115299. 11,11,11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,
  115300. 10,11,11,11,12, 0, 0, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  115301. 10,10,11,11,12,12, 0, 0, 0, 8, 8, 8, 8, 9, 9, 9,
  115302. 9,10,10,11,11,12,12, 0, 0, 0, 9, 9, 9, 9,10,10,
  115303. 10,10,11,10,11,11,12,12, 0, 0, 0, 0, 0, 9, 9,10,
  115304. 10,10,10,11,11,11,11,12,12, 0, 0, 0, 0, 0, 9, 8,
  115305. 9, 9,10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 8,
  115306. 8, 9, 9,10,10,11,11,12,11,12,12, 0, 0, 0, 0, 0,
  115307. 9,10,10,10,11,11,11,11,12,12,13,13, 0, 0, 0, 0,
  115308. 0, 0, 0,10,10,10,10,11,11,12,12,13,13, 0, 0, 0,
  115309. 0, 0, 0, 0,11,11,11,11,12,12,12,12,13,13, 0, 0,
  115310. 0, 0, 0, 0, 0,11,11,11,11,12,12,12,12,13,13, 0,
  115311. 0, 0, 0, 0, 0, 0,11,11,12,12,12,12,13,13,13,13,
  115312. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,13,
  115313. 13,
  115314. };
  115315. static float _vq_quantthresh__44c3_s_p6_0[] = {
  115316. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  115317. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  115318. };
  115319. static long _vq_quantmap__44c3_s_p6_0[] = {
  115320. 15, 13, 11, 9, 7, 5, 3, 1,
  115321. 0, 2, 4, 6, 8, 10, 12, 14,
  115322. 16,
  115323. };
  115324. static encode_aux_threshmatch _vq_auxt__44c3_s_p6_0 = {
  115325. _vq_quantthresh__44c3_s_p6_0,
  115326. _vq_quantmap__44c3_s_p6_0,
  115327. 17,
  115328. 17
  115329. };
  115330. static static_codebook _44c3_s_p6_0 = {
  115331. 2, 289,
  115332. _vq_lengthlist__44c3_s_p6_0,
  115333. 1, -529530880, 1611661312, 5, 0,
  115334. _vq_quantlist__44c3_s_p6_0,
  115335. NULL,
  115336. &_vq_auxt__44c3_s_p6_0,
  115337. NULL,
  115338. 0
  115339. };
  115340. static long _vq_quantlist__44c3_s_p7_0[] = {
  115341. 1,
  115342. 0,
  115343. 2,
  115344. };
  115345. static long _vq_lengthlist__44c3_s_p7_0[] = {
  115346. 1, 4, 4, 7, 6, 6, 7, 6, 6, 4, 7, 7,10, 9, 9,11,
  115347. 9, 9, 4, 7, 7,10, 9, 9,11, 9, 9, 7,10,10,11,11,
  115348. 10,12,11,11, 6, 9, 9,11,10,10,11,10,10, 6, 9, 9,
  115349. 11,10,10,11,10,10, 7,11,11,11,11,11,12,11,11, 6,
  115350. 9, 9,11,10,10,11,10,10, 6, 9, 9,11,10,10,11,10,
  115351. 10,
  115352. };
  115353. static float _vq_quantthresh__44c3_s_p7_0[] = {
  115354. -5.5, 5.5,
  115355. };
  115356. static long _vq_quantmap__44c3_s_p7_0[] = {
  115357. 1, 0, 2,
  115358. };
  115359. static encode_aux_threshmatch _vq_auxt__44c3_s_p7_0 = {
  115360. _vq_quantthresh__44c3_s_p7_0,
  115361. _vq_quantmap__44c3_s_p7_0,
  115362. 3,
  115363. 3
  115364. };
  115365. static static_codebook _44c3_s_p7_0 = {
  115366. 4, 81,
  115367. _vq_lengthlist__44c3_s_p7_0,
  115368. 1, -529137664, 1618345984, 2, 0,
  115369. _vq_quantlist__44c3_s_p7_0,
  115370. NULL,
  115371. &_vq_auxt__44c3_s_p7_0,
  115372. NULL,
  115373. 0
  115374. };
  115375. static long _vq_quantlist__44c3_s_p7_1[] = {
  115376. 5,
  115377. 4,
  115378. 6,
  115379. 3,
  115380. 7,
  115381. 2,
  115382. 8,
  115383. 1,
  115384. 9,
  115385. 0,
  115386. 10,
  115387. };
  115388. static long _vq_lengthlist__44c3_s_p7_1[] = {
  115389. 2, 4, 4, 6, 6, 7, 7, 7, 7, 8, 8,10, 5, 5, 6, 6,
  115390. 7, 7, 8, 8, 8, 8,10, 5, 5, 6, 6, 7, 7, 8, 8, 8,
  115391. 8,10, 6, 6, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10, 7,
  115392. 7, 8, 7, 8, 8, 8, 8,10,10,10, 8, 8, 8, 8, 8, 8,
  115393. 8, 8,10,10,10, 7, 8, 8, 8, 8, 8, 8, 8,10,10,10,
  115394. 8, 8, 8, 8, 8, 8, 8, 8,10,10,10,10,10, 8, 8, 8,
  115395. 8, 8, 8,10,10,10,10,10, 9, 9, 8, 8, 9, 8,10,10,
  115396. 10,10,10, 8, 8, 8, 8, 8, 8,
  115397. };
  115398. static float _vq_quantthresh__44c3_s_p7_1[] = {
  115399. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  115400. 3.5, 4.5,
  115401. };
  115402. static long _vq_quantmap__44c3_s_p7_1[] = {
  115403. 9, 7, 5, 3, 1, 0, 2, 4,
  115404. 6, 8, 10,
  115405. };
  115406. static encode_aux_threshmatch _vq_auxt__44c3_s_p7_1 = {
  115407. _vq_quantthresh__44c3_s_p7_1,
  115408. _vq_quantmap__44c3_s_p7_1,
  115409. 11,
  115410. 11
  115411. };
  115412. static static_codebook _44c3_s_p7_1 = {
  115413. 2, 121,
  115414. _vq_lengthlist__44c3_s_p7_1,
  115415. 1, -531365888, 1611661312, 4, 0,
  115416. _vq_quantlist__44c3_s_p7_1,
  115417. NULL,
  115418. &_vq_auxt__44c3_s_p7_1,
  115419. NULL,
  115420. 0
  115421. };
  115422. static long _vq_quantlist__44c3_s_p8_0[] = {
  115423. 6,
  115424. 5,
  115425. 7,
  115426. 4,
  115427. 8,
  115428. 3,
  115429. 9,
  115430. 2,
  115431. 10,
  115432. 1,
  115433. 11,
  115434. 0,
  115435. 12,
  115436. };
  115437. static long _vq_lengthlist__44c3_s_p8_0[] = {
  115438. 1, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9,10,10, 6, 5, 5,
  115439. 7, 7, 8, 8, 8, 8, 9, 9,10,10, 7, 5, 5, 7, 7, 8,
  115440. 8, 8, 8, 9, 9,11,10, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  115441. 10,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  115442. 11, 0,12,12, 9, 9,10,10,10,10,11,11,11,12, 0,13,
  115443. 13, 9, 9,10,10,10,10,11,11,12,12, 0, 0, 0,10,10,
  115444. 10,10,11,11,12,12,12,12, 0, 0, 0,10,10,10,10,11,
  115445. 11,12,12,12,12, 0, 0, 0,14,14,11,11,11,11,12,12,
  115446. 13,13, 0, 0, 0,14,14,11,11,11,11,12,12,13,13, 0,
  115447. 0, 0, 0, 0,12,12,12,12,13,13,14,13, 0, 0, 0, 0,
  115448. 0,13,13,12,12,13,12,14,13,
  115449. };
  115450. static float _vq_quantthresh__44c3_s_p8_0[] = {
  115451. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  115452. 12.5, 17.5, 22.5, 27.5,
  115453. };
  115454. static long _vq_quantmap__44c3_s_p8_0[] = {
  115455. 11, 9, 7, 5, 3, 1, 0, 2,
  115456. 4, 6, 8, 10, 12,
  115457. };
  115458. static encode_aux_threshmatch _vq_auxt__44c3_s_p8_0 = {
  115459. _vq_quantthresh__44c3_s_p8_0,
  115460. _vq_quantmap__44c3_s_p8_0,
  115461. 13,
  115462. 13
  115463. };
  115464. static static_codebook _44c3_s_p8_0 = {
  115465. 2, 169,
  115466. _vq_lengthlist__44c3_s_p8_0,
  115467. 1, -526516224, 1616117760, 4, 0,
  115468. _vq_quantlist__44c3_s_p8_0,
  115469. NULL,
  115470. &_vq_auxt__44c3_s_p8_0,
  115471. NULL,
  115472. 0
  115473. };
  115474. static long _vq_quantlist__44c3_s_p8_1[] = {
  115475. 2,
  115476. 1,
  115477. 3,
  115478. 0,
  115479. 4,
  115480. };
  115481. static long _vq_lengthlist__44c3_s_p8_1[] = {
  115482. 2, 4, 4, 5, 5, 6, 5, 5, 5, 5, 6, 4, 5, 5, 5, 6,
  115483. 5, 5, 5, 5, 6, 6, 6, 5, 5,
  115484. };
  115485. static float _vq_quantthresh__44c3_s_p8_1[] = {
  115486. -1.5, -0.5, 0.5, 1.5,
  115487. };
  115488. static long _vq_quantmap__44c3_s_p8_1[] = {
  115489. 3, 1, 0, 2, 4,
  115490. };
  115491. static encode_aux_threshmatch _vq_auxt__44c3_s_p8_1 = {
  115492. _vq_quantthresh__44c3_s_p8_1,
  115493. _vq_quantmap__44c3_s_p8_1,
  115494. 5,
  115495. 5
  115496. };
  115497. static static_codebook _44c3_s_p8_1 = {
  115498. 2, 25,
  115499. _vq_lengthlist__44c3_s_p8_1,
  115500. 1, -533725184, 1611661312, 3, 0,
  115501. _vq_quantlist__44c3_s_p8_1,
  115502. NULL,
  115503. &_vq_auxt__44c3_s_p8_1,
  115504. NULL,
  115505. 0
  115506. };
  115507. static long _vq_quantlist__44c3_s_p9_0[] = {
  115508. 6,
  115509. 5,
  115510. 7,
  115511. 4,
  115512. 8,
  115513. 3,
  115514. 9,
  115515. 2,
  115516. 10,
  115517. 1,
  115518. 11,
  115519. 0,
  115520. 12,
  115521. };
  115522. static long _vq_lengthlist__44c3_s_p9_0[] = {
  115523. 1, 4, 4,12,12,12,12,12,12,12,12,12,12, 4, 9, 8,
  115524. 12,12,12,12,12,12,12,12,12,12, 2, 9, 7,12,12,12,
  115525. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  115526. 12,12,12,12,12,12,11,12,12,12,12,12,12,12,12,12,
  115527. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  115528. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  115529. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  115530. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  115531. 12,12,12,12,12,12,12,12,12,12,11,11,11,11,11,11,
  115532. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  115533. 11,11,11,11,11,11,11,11,11,
  115534. };
  115535. static float _vq_quantthresh__44c3_s_p9_0[] = {
  115536. -1402.5, -1147.5, -892.5, -637.5, -382.5, -127.5, 127.5, 382.5,
  115537. 637.5, 892.5, 1147.5, 1402.5,
  115538. };
  115539. static long _vq_quantmap__44c3_s_p9_0[] = {
  115540. 11, 9, 7, 5, 3, 1, 0, 2,
  115541. 4, 6, 8, 10, 12,
  115542. };
  115543. static encode_aux_threshmatch _vq_auxt__44c3_s_p9_0 = {
  115544. _vq_quantthresh__44c3_s_p9_0,
  115545. _vq_quantmap__44c3_s_p9_0,
  115546. 13,
  115547. 13
  115548. };
  115549. static static_codebook _44c3_s_p9_0 = {
  115550. 2, 169,
  115551. _vq_lengthlist__44c3_s_p9_0,
  115552. 1, -514332672, 1627381760, 4, 0,
  115553. _vq_quantlist__44c3_s_p9_0,
  115554. NULL,
  115555. &_vq_auxt__44c3_s_p9_0,
  115556. NULL,
  115557. 0
  115558. };
  115559. static long _vq_quantlist__44c3_s_p9_1[] = {
  115560. 7,
  115561. 6,
  115562. 8,
  115563. 5,
  115564. 9,
  115565. 4,
  115566. 10,
  115567. 3,
  115568. 11,
  115569. 2,
  115570. 12,
  115571. 1,
  115572. 13,
  115573. 0,
  115574. 14,
  115575. };
  115576. static long _vq_lengthlist__44c3_s_p9_1[] = {
  115577. 1, 4, 4, 6, 6, 7, 7, 8, 7, 9, 9,10,10,10,10, 6,
  115578. 5, 5, 7, 7, 8, 8,10, 8,11,10,12,12,13,13, 6, 5,
  115579. 5, 7, 7, 8, 8,10, 9,11,11,12,12,13,12,18, 8, 8,
  115580. 8, 8, 9, 9,10, 9,11,10,12,12,13,13,18, 8, 8, 8,
  115581. 8, 9, 9,10,10,11,11,13,12,14,13,18,11,11, 9, 9,
  115582. 10,10,11,11,11,12,13,12,13,14,18,11,11, 9, 8,11,
  115583. 10,11,11,11,11,12,12,14,13,18,18,18,10,11,10,11,
  115584. 12,12,12,12,13,12,14,13,18,18,18,10,11,11, 9,12,
  115585. 11,12,12,12,13,13,13,18,18,17,14,14,11,11,12,12,
  115586. 13,12,14,12,14,13,18,18,18,14,14,11,10,12, 9,12,
  115587. 13,13,13,13,13,18,18,17,16,18,13,13,12,12,13,11,
  115588. 14,12,14,14,17,18,18,17,18,13,12,13,10,12,11,14,
  115589. 14,14,14,17,18,18,18,18,15,16,12,12,13,10,14,12,
  115590. 14,15,18,18,18,16,17,16,14,12,11,13,10,13,13,14,
  115591. 15,
  115592. };
  115593. static float _vq_quantthresh__44c3_s_p9_1[] = {
  115594. -110.5, -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5,
  115595. 25.5, 42.5, 59.5, 76.5, 93.5, 110.5,
  115596. };
  115597. static long _vq_quantmap__44c3_s_p9_1[] = {
  115598. 13, 11, 9, 7, 5, 3, 1, 0,
  115599. 2, 4, 6, 8, 10, 12, 14,
  115600. };
  115601. static encode_aux_threshmatch _vq_auxt__44c3_s_p9_1 = {
  115602. _vq_quantthresh__44c3_s_p9_1,
  115603. _vq_quantmap__44c3_s_p9_1,
  115604. 15,
  115605. 15
  115606. };
  115607. static static_codebook _44c3_s_p9_1 = {
  115608. 2, 225,
  115609. _vq_lengthlist__44c3_s_p9_1,
  115610. 1, -522338304, 1620115456, 4, 0,
  115611. _vq_quantlist__44c3_s_p9_1,
  115612. NULL,
  115613. &_vq_auxt__44c3_s_p9_1,
  115614. NULL,
  115615. 0
  115616. };
  115617. static long _vq_quantlist__44c3_s_p9_2[] = {
  115618. 8,
  115619. 7,
  115620. 9,
  115621. 6,
  115622. 10,
  115623. 5,
  115624. 11,
  115625. 4,
  115626. 12,
  115627. 3,
  115628. 13,
  115629. 2,
  115630. 14,
  115631. 1,
  115632. 15,
  115633. 0,
  115634. 16,
  115635. };
  115636. static long _vq_lengthlist__44c3_s_p9_2[] = {
  115637. 2, 5, 5, 6, 6, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8,
  115638. 8,10, 6, 6, 7, 7, 8, 7, 8, 8, 8, 8, 8, 9, 9, 9,
  115639. 9, 9,10, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9,
  115640. 9, 9, 9,10, 7, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9,
  115641. 9, 9, 9, 9,10,10,10, 7, 7, 8, 8, 8, 9, 9, 9, 9,
  115642. 9, 9, 9, 9, 9,11,11,11, 8, 8, 8, 8, 9, 9, 9, 9,
  115643. 9, 9, 9, 9, 9, 9,10,10,10, 8, 8, 8, 8, 9, 9, 9,
  115644. 9, 9, 9, 9, 9, 9, 9,10,10,10, 8, 9, 9, 9, 9, 9,
  115645. 9, 9, 9, 9, 9, 9,10, 9,10,10,10,11,11, 9, 9, 9,
  115646. 9, 9, 9, 9, 9, 9, 9, 9, 9,11,10,11,11,11, 9, 9,
  115647. 9, 9, 9, 9,10,10, 9, 9,10, 9,11,10,11,11,11, 9,
  115648. 9, 9, 9, 9, 9, 9, 9,10,10,10, 9,11,11,11,11,11,
  115649. 9, 9, 9, 9,10,10, 9, 9, 9, 9,10, 9,11,11,11,11,
  115650. 11,11,11, 9, 9, 9, 9, 9, 9,10,10,10,10,11,11,11,
  115651. 11,11,11,11,10, 9,10,10, 9,10, 9, 9,10, 9,11,10,
  115652. 10,11,11,11,11, 9,10, 9, 9, 9, 9,10,10,10,10,11,
  115653. 11,11,11,11,11,10,10,10, 9, 9,10, 9,10, 9,10,10,
  115654. 10,10,11,11,11,11,11,11,11, 9, 9, 9, 9, 9,10,10,
  115655. 10,
  115656. };
  115657. static float _vq_quantthresh__44c3_s_p9_2[] = {
  115658. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  115659. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  115660. };
  115661. static long _vq_quantmap__44c3_s_p9_2[] = {
  115662. 15, 13, 11, 9, 7, 5, 3, 1,
  115663. 0, 2, 4, 6, 8, 10, 12, 14,
  115664. 16,
  115665. };
  115666. static encode_aux_threshmatch _vq_auxt__44c3_s_p9_2 = {
  115667. _vq_quantthresh__44c3_s_p9_2,
  115668. _vq_quantmap__44c3_s_p9_2,
  115669. 17,
  115670. 17
  115671. };
  115672. static static_codebook _44c3_s_p9_2 = {
  115673. 2, 289,
  115674. _vq_lengthlist__44c3_s_p9_2,
  115675. 1, -529530880, 1611661312, 5, 0,
  115676. _vq_quantlist__44c3_s_p9_2,
  115677. NULL,
  115678. &_vq_auxt__44c3_s_p9_2,
  115679. NULL,
  115680. 0
  115681. };
  115682. static long _huff_lengthlist__44c3_s_short[] = {
  115683. 10, 9,13,11,14,10,12,13,13,14, 7, 2,12, 5,10, 5,
  115684. 7,10,12,14,12, 6, 9, 8, 7, 7, 9,11,13,16,10, 4,
  115685. 12, 5,10, 6, 8,12,14,16,12, 6, 8, 7, 6, 5, 7,11,
  115686. 12,16,10, 4, 8, 5, 6, 4, 6, 9,13,16,10, 6,10, 7,
  115687. 7, 6, 7, 9,13,15,12, 9,11, 9, 8, 6, 7,10,12,14,
  115688. 14,11,10, 9, 6, 5, 6, 9,11,13,15,13,11,10, 6, 5,
  115689. 6, 8, 9,11,
  115690. };
  115691. static static_codebook _huff_book__44c3_s_short = {
  115692. 2, 100,
  115693. _huff_lengthlist__44c3_s_short,
  115694. 0, 0, 0, 0, 0,
  115695. NULL,
  115696. NULL,
  115697. NULL,
  115698. NULL,
  115699. 0
  115700. };
  115701. static long _huff_lengthlist__44c4_s_long[] = {
  115702. 4, 7,11,11,11,11,10,11,12,11, 5, 2,11, 5, 6, 6,
  115703. 7, 9,11,12,11, 9, 6,10, 6, 7, 8, 9,10,11,11, 5,
  115704. 11, 7, 8, 8, 9,11,13,14,11, 6, 5, 8, 4, 5, 7, 8,
  115705. 10,11,10, 6, 7, 7, 5, 5, 6, 8, 9,11,10, 7, 8, 9,
  115706. 6, 6, 6, 7, 8, 9,11, 9, 9,11, 7, 7, 6, 6, 7, 9,
  115707. 12,12,10,13, 9, 8, 7, 7, 7, 8,11,13,11,14,11,10,
  115708. 9, 8, 7, 7,
  115709. };
  115710. static static_codebook _huff_book__44c4_s_long = {
  115711. 2, 100,
  115712. _huff_lengthlist__44c4_s_long,
  115713. 0, 0, 0, 0, 0,
  115714. NULL,
  115715. NULL,
  115716. NULL,
  115717. NULL,
  115718. 0
  115719. };
  115720. static long _vq_quantlist__44c4_s_p1_0[] = {
  115721. 1,
  115722. 0,
  115723. 2,
  115724. };
  115725. static long _vq_lengthlist__44c4_s_p1_0[] = {
  115726. 2, 4, 4, 0, 0, 0, 0, 0, 0, 5, 6, 6, 0, 0, 0, 0,
  115727. 0, 0, 5, 6, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115728. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115729. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115730. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115731. 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0, 0,
  115732. 0, 0, 0, 6, 8, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115733. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115734. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115735. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115736. 0, 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 6, 8, 7, 0, 0,
  115737. 0, 0, 0, 0, 7, 8, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115738. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115739. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115740. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115741. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115742. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115743. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115744. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115745. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115746. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115747. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115748. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115749. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115750. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115751. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115752. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115753. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115754. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115755. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115756. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115757. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115758. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115759. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115760. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115761. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115762. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115763. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115764. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115765. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115766. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115767. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115768. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115769. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115770. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115771. 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0,
  115772. 0, 0, 7, 8, 8, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0,
  115773. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115774. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115775. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115776. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0, 0,
  115777. 0, 0, 0, 8, 9, 9, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0,
  115778. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115779. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115780. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115781. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 8, 8, 0, 0,
  115782. 0, 0, 0, 0, 8, 9, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9,
  115783. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115784. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115785. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115786. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115787. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115788. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115789. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115790. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115791. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115792. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115793. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115794. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115795. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115796. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115797. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115798. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115799. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115800. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115801. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115802. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115803. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115804. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115805. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115806. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115807. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115808. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115809. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115810. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115811. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115812. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115813. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115814. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115815. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115816. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115817. 0, 0, 4, 7, 7, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0,
  115818. 0, 0, 0, 0, 7, 8, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115819. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115820. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115821. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115822. 0, 0, 0, 6, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0,
  115823. 0, 0, 0, 0, 0, 8, 8, 9, 0, 0, 0, 0, 0, 0, 0, 0,
  115824. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115825. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115826. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115827. 0, 0, 0, 0, 7, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9,
  115828. 0, 0, 0, 0, 0, 0, 8, 9, 9, 0, 0, 0, 0, 0, 0, 0,
  115829. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115830. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115831. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115832. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115833. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115834. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115835. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115836. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115837. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115838. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115839. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115840. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115841. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115842. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115843. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115844. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115845. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115846. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115847. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115848. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115849. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115850. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115851. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115852. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115853. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115854. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115855. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115856. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115857. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115858. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115859. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115860. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115861. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115862. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115863. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115864. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115865. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115866. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115867. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115868. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115869. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115870. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115871. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115872. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115873. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115874. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115875. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115876. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115877. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115878. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115879. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115880. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115881. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115882. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115883. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115884. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115885. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115886. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115887. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115888. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115889. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115890. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115891. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115892. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115893. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115894. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115895. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115896. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115897. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115898. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115899. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115900. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115901. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115902. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115903. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115904. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115905. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115906. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115907. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115908. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115909. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115910. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115911. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115912. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115913. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115914. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115915. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115916. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115917. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115918. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115919. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115920. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115921. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115922. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115923. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115924. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115925. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115926. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115927. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115928. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115929. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115930. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115931. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115932. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115933. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115934. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115935. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115936. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115937. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115938. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115939. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115940. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115941. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115942. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115943. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115944. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115945. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115946. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115947. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115948. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115949. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115950. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115951. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115952. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115953. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115954. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115955. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115956. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115957. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115958. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115959. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115960. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115961. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115962. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115963. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115964. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115965. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115966. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115967. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115968. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115969. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115970. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115971. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115972. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115973. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115974. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115975. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115976. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115977. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115978. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115979. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115980. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115981. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115982. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115983. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115984. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115985. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115986. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115987. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115988. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115989. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115990. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115991. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115992. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115993. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115994. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115995. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115996. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115997. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115998. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115999. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116000. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116001. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116002. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116003. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116004. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116005. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116006. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116007. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116008. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116009. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116010. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116011. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116012. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116013. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116014. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116015. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116016. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116017. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116018. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116019. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116020. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116021. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116022. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116023. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116024. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116025. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116026. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116027. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116028. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116029. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116030. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116031. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116032. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116033. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116034. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116035. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116036. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116037. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116038. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116039. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116040. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116041. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116042. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116043. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116044. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116045. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116046. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116047. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116048. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116049. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116050. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116051. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116052. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116053. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116054. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116055. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116056. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116057. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116058. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116059. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116060. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116061. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116062. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116063. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116064. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116065. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116066. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116067. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116068. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116069. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116070. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116071. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116072. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116073. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116074. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116075. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116076. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116077. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116078. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116079. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116080. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116081. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116082. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116083. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116084. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116085. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116086. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116087. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116088. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116089. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116090. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116091. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116092. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116093. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116094. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116095. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116096. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116097. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116098. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116099. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116100. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116101. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116102. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116103. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116104. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116105. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116106. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116107. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116108. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116109. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116110. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116111. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116112. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116113. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116114. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116115. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116116. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116117. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116118. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116119. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116120. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116121. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116122. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116123. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116124. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116125. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116126. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116127. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116128. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116129. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116130. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116131. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116132. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116133. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116134. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116135. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116136. 0,
  116137. };
  116138. static float _vq_quantthresh__44c4_s_p1_0[] = {
  116139. -0.5, 0.5,
  116140. };
  116141. static long _vq_quantmap__44c4_s_p1_0[] = {
  116142. 1, 0, 2,
  116143. };
  116144. static encode_aux_threshmatch _vq_auxt__44c4_s_p1_0 = {
  116145. _vq_quantthresh__44c4_s_p1_0,
  116146. _vq_quantmap__44c4_s_p1_0,
  116147. 3,
  116148. 3
  116149. };
  116150. static static_codebook _44c4_s_p1_0 = {
  116151. 8, 6561,
  116152. _vq_lengthlist__44c4_s_p1_0,
  116153. 1, -535822336, 1611661312, 2, 0,
  116154. _vq_quantlist__44c4_s_p1_0,
  116155. NULL,
  116156. &_vq_auxt__44c4_s_p1_0,
  116157. NULL,
  116158. 0
  116159. };
  116160. static long _vq_quantlist__44c4_s_p2_0[] = {
  116161. 2,
  116162. 1,
  116163. 3,
  116164. 0,
  116165. 4,
  116166. };
  116167. static long _vq_lengthlist__44c4_s_p2_0[] = {
  116168. 2, 5, 5, 0, 0, 0, 5, 5, 0, 0, 0, 5, 5, 0, 0, 0,
  116169. 7, 7, 0, 0, 0, 0, 0, 0, 0, 5, 6, 6, 0, 0, 0, 7,
  116170. 7, 0, 0, 0, 7, 7, 0, 0, 0,10,10, 0, 0, 0, 0, 0,
  116171. 0, 0, 5, 6, 6, 0, 0, 0, 7, 7, 0, 0, 0, 7, 7, 0,
  116172. 0, 0,10,10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116173. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116174. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116175. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116176. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116177. 0, 0, 0, 0, 0, 0, 5, 8, 7, 0, 0, 0, 7, 7, 0, 0,
  116178. 0, 7, 7, 0, 0, 0, 9, 9, 0, 0, 0, 0, 0, 0, 0, 5,
  116179. 7, 8, 0, 0, 0, 7, 7, 0, 0, 0, 7, 7, 0, 0, 0, 9,
  116180. 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116181. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116182. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116183. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116184. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116185. 0, 0, 0, 5, 7, 7, 0, 0, 0, 7, 7, 0, 0, 0, 7, 7,
  116186. 0, 0, 0, 9, 9, 0, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0,
  116187. 0, 0, 7, 7, 0, 0, 0, 7, 7, 0, 0, 0, 9, 9, 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. 7,10,10, 0, 0, 0, 9, 9, 0, 0, 0, 9, 9, 0, 0, 0,
  116194. 10,10, 0, 0, 0, 0, 0, 0, 0, 8,10,10, 0, 0, 0, 9,
  116195. 9, 0, 0, 0, 9, 9, 0, 0, 0,10,10, 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,
  116208. };
  116209. static float _vq_quantthresh__44c4_s_p2_0[] = {
  116210. -1.5, -0.5, 0.5, 1.5,
  116211. };
  116212. static long _vq_quantmap__44c4_s_p2_0[] = {
  116213. 3, 1, 0, 2, 4,
  116214. };
  116215. static encode_aux_threshmatch _vq_auxt__44c4_s_p2_0 = {
  116216. _vq_quantthresh__44c4_s_p2_0,
  116217. _vq_quantmap__44c4_s_p2_0,
  116218. 5,
  116219. 5
  116220. };
  116221. static static_codebook _44c4_s_p2_0 = {
  116222. 4, 625,
  116223. _vq_lengthlist__44c4_s_p2_0,
  116224. 1, -533725184, 1611661312, 3, 0,
  116225. _vq_quantlist__44c4_s_p2_0,
  116226. NULL,
  116227. &_vq_auxt__44c4_s_p2_0,
  116228. NULL,
  116229. 0
  116230. };
  116231. static long _vq_quantlist__44c4_s_p3_0[] = {
  116232. 2,
  116233. 1,
  116234. 3,
  116235. 0,
  116236. 4,
  116237. };
  116238. static long _vq_lengthlist__44c4_s_p3_0[] = {
  116239. 2, 3, 3, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116240. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 5, 4, 6, 6, 0, 0,
  116241. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116242. 0, 0, 4, 4, 5, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116243. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 6, 6, 9, 9,
  116244. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116245. 0, 0, 0, 0, 6, 6, 7, 9, 9, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116266. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116267. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116268. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116269. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116270. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116271. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116272. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116273. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116274. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116275. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116276. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116277. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116278. 0,
  116279. };
  116280. static float _vq_quantthresh__44c4_s_p3_0[] = {
  116281. -1.5, -0.5, 0.5, 1.5,
  116282. };
  116283. static long _vq_quantmap__44c4_s_p3_0[] = {
  116284. 3, 1, 0, 2, 4,
  116285. };
  116286. static encode_aux_threshmatch _vq_auxt__44c4_s_p3_0 = {
  116287. _vq_quantthresh__44c4_s_p3_0,
  116288. _vq_quantmap__44c4_s_p3_0,
  116289. 5,
  116290. 5
  116291. };
  116292. static static_codebook _44c4_s_p3_0 = {
  116293. 4, 625,
  116294. _vq_lengthlist__44c4_s_p3_0,
  116295. 1, -533725184, 1611661312, 3, 0,
  116296. _vq_quantlist__44c4_s_p3_0,
  116297. NULL,
  116298. &_vq_auxt__44c4_s_p3_0,
  116299. NULL,
  116300. 0
  116301. };
  116302. static long _vq_quantlist__44c4_s_p4_0[] = {
  116303. 4,
  116304. 3,
  116305. 5,
  116306. 2,
  116307. 6,
  116308. 1,
  116309. 7,
  116310. 0,
  116311. 8,
  116312. };
  116313. static long _vq_lengthlist__44c4_s_p4_0[] = {
  116314. 2, 3, 3, 6, 6, 0, 0, 0, 0, 0, 4, 4, 6, 6, 0, 0,
  116315. 0, 0, 0, 4, 4, 6, 6, 0, 0, 0, 0, 0, 5, 5, 6, 6,
  116316. 0, 0, 0, 0, 0, 0, 0, 6, 6, 0, 0, 0, 0, 0, 0, 0,
  116317. 7, 8, 0, 0, 0, 0, 0, 0, 0, 7, 7, 0, 0, 0, 0, 0,
  116318. 0, 0, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116319. 0,
  116320. };
  116321. static float _vq_quantthresh__44c4_s_p4_0[] = {
  116322. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  116323. };
  116324. static long _vq_quantmap__44c4_s_p4_0[] = {
  116325. 7, 5, 3, 1, 0, 2, 4, 6,
  116326. 8,
  116327. };
  116328. static encode_aux_threshmatch _vq_auxt__44c4_s_p4_0 = {
  116329. _vq_quantthresh__44c4_s_p4_0,
  116330. _vq_quantmap__44c4_s_p4_0,
  116331. 9,
  116332. 9
  116333. };
  116334. static static_codebook _44c4_s_p4_0 = {
  116335. 2, 81,
  116336. _vq_lengthlist__44c4_s_p4_0,
  116337. 1, -531628032, 1611661312, 4, 0,
  116338. _vq_quantlist__44c4_s_p4_0,
  116339. NULL,
  116340. &_vq_auxt__44c4_s_p4_0,
  116341. NULL,
  116342. 0
  116343. };
  116344. static long _vq_quantlist__44c4_s_p5_0[] = {
  116345. 4,
  116346. 3,
  116347. 5,
  116348. 2,
  116349. 6,
  116350. 1,
  116351. 7,
  116352. 0,
  116353. 8,
  116354. };
  116355. static long _vq_lengthlist__44c4_s_p5_0[] = {
  116356. 2, 3, 3, 6, 6, 7, 7, 9, 9, 0, 4, 4, 6, 6, 7, 7,
  116357. 9, 9, 0, 4, 5, 6, 6, 7, 7, 9, 9, 0, 6, 6, 7, 7,
  116358. 8, 8,10,10, 0, 0, 0, 7, 7, 8, 8,10, 9, 0, 0, 0,
  116359. 9, 8, 8, 8,10,10, 0, 0, 0, 8, 8, 8, 8,10,10, 0,
  116360. 0, 0,10,10, 9, 9,11,11, 0, 0, 0, 0, 0, 9, 9,10,
  116361. 10,
  116362. };
  116363. static float _vq_quantthresh__44c4_s_p5_0[] = {
  116364. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  116365. };
  116366. static long _vq_quantmap__44c4_s_p5_0[] = {
  116367. 7, 5, 3, 1, 0, 2, 4, 6,
  116368. 8,
  116369. };
  116370. static encode_aux_threshmatch _vq_auxt__44c4_s_p5_0 = {
  116371. _vq_quantthresh__44c4_s_p5_0,
  116372. _vq_quantmap__44c4_s_p5_0,
  116373. 9,
  116374. 9
  116375. };
  116376. static static_codebook _44c4_s_p5_0 = {
  116377. 2, 81,
  116378. _vq_lengthlist__44c4_s_p5_0,
  116379. 1, -531628032, 1611661312, 4, 0,
  116380. _vq_quantlist__44c4_s_p5_0,
  116381. NULL,
  116382. &_vq_auxt__44c4_s_p5_0,
  116383. NULL,
  116384. 0
  116385. };
  116386. static long _vq_quantlist__44c4_s_p6_0[] = {
  116387. 8,
  116388. 7,
  116389. 9,
  116390. 6,
  116391. 10,
  116392. 5,
  116393. 11,
  116394. 4,
  116395. 12,
  116396. 3,
  116397. 13,
  116398. 2,
  116399. 14,
  116400. 1,
  116401. 15,
  116402. 0,
  116403. 16,
  116404. };
  116405. static long _vq_lengthlist__44c4_s_p6_0[] = {
  116406. 2, 4, 4, 6, 6, 8, 8, 9, 9, 8, 8, 9, 9,10,10,11,
  116407. 11, 0, 4, 4, 6, 6, 8, 8, 9, 9, 9, 9,10,10,11,11,
  116408. 11,11, 0, 4, 4, 7, 6, 8, 8, 9, 9, 9, 9,10,10,11,
  116409. 11,11,11, 0, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  116410. 11,11,11,12, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,
  116411. 10,11,11,12,12, 0, 0, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  116412. 10,10,11,11,12,12, 0, 0, 0, 8, 8, 8, 8, 9, 9, 9,
  116413. 9,10,10,11,11,12,12, 0, 0, 0, 9, 9, 9, 9,10,10,
  116414. 10,10,11,11,11,11,12,12, 0, 0, 0, 0, 0, 9, 9,10,
  116415. 10,10,10,11,11,11,11,12,12, 0, 0, 0, 0, 0, 9, 9,
  116416. 9,10,10,10,11,11,11,11,12,12, 0, 0, 0, 0, 0, 9,
  116417. 9, 9, 9,10,10,11,11,11,12,12,12, 0, 0, 0, 0, 0,
  116418. 10,10,10,10,11,11,11,11,12,12,13,12, 0, 0, 0, 0,
  116419. 0, 0, 0,10,10,11,11,11,11,12,12,12,12, 0, 0, 0,
  116420. 0, 0, 0, 0,11,11,11,11,12,12,12,12,13,13, 0, 0,
  116421. 0, 0, 0, 0, 0,11,11,11,11,12,12,12,12,13,13, 0,
  116422. 0, 0, 0, 0, 0, 0,12,12,12,12,12,12,13,13,13,13,
  116423. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,12,12,12,13,13,
  116424. 13,
  116425. };
  116426. static float _vq_quantthresh__44c4_s_p6_0[] = {
  116427. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  116428. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  116429. };
  116430. static long _vq_quantmap__44c4_s_p6_0[] = {
  116431. 15, 13, 11, 9, 7, 5, 3, 1,
  116432. 0, 2, 4, 6, 8, 10, 12, 14,
  116433. 16,
  116434. };
  116435. static encode_aux_threshmatch _vq_auxt__44c4_s_p6_0 = {
  116436. _vq_quantthresh__44c4_s_p6_0,
  116437. _vq_quantmap__44c4_s_p6_0,
  116438. 17,
  116439. 17
  116440. };
  116441. static static_codebook _44c4_s_p6_0 = {
  116442. 2, 289,
  116443. _vq_lengthlist__44c4_s_p6_0,
  116444. 1, -529530880, 1611661312, 5, 0,
  116445. _vq_quantlist__44c4_s_p6_0,
  116446. NULL,
  116447. &_vq_auxt__44c4_s_p6_0,
  116448. NULL,
  116449. 0
  116450. };
  116451. static long _vq_quantlist__44c4_s_p7_0[] = {
  116452. 1,
  116453. 0,
  116454. 2,
  116455. };
  116456. static long _vq_lengthlist__44c4_s_p7_0[] = {
  116457. 1, 4, 4, 7, 6, 6, 7, 6, 6, 4, 7, 7,10, 9, 9,11,
  116458. 9, 9, 4, 7, 7,10, 9, 9,11, 9, 9, 7,10,10,11,11,
  116459. 10,11,11,11, 6, 9, 9,11,10,10,11,10,10, 6, 9, 9,
  116460. 11,10,10,11,10,10, 7,11,11,12,11,11,12,11,11, 6,
  116461. 9, 9,11,10,10,11,10,10, 6, 9, 9,11,10,10,11,10,
  116462. 10,
  116463. };
  116464. static float _vq_quantthresh__44c4_s_p7_0[] = {
  116465. -5.5, 5.5,
  116466. };
  116467. static long _vq_quantmap__44c4_s_p7_0[] = {
  116468. 1, 0, 2,
  116469. };
  116470. static encode_aux_threshmatch _vq_auxt__44c4_s_p7_0 = {
  116471. _vq_quantthresh__44c4_s_p7_0,
  116472. _vq_quantmap__44c4_s_p7_0,
  116473. 3,
  116474. 3
  116475. };
  116476. static static_codebook _44c4_s_p7_0 = {
  116477. 4, 81,
  116478. _vq_lengthlist__44c4_s_p7_0,
  116479. 1, -529137664, 1618345984, 2, 0,
  116480. _vq_quantlist__44c4_s_p7_0,
  116481. NULL,
  116482. &_vq_auxt__44c4_s_p7_0,
  116483. NULL,
  116484. 0
  116485. };
  116486. static long _vq_quantlist__44c4_s_p7_1[] = {
  116487. 5,
  116488. 4,
  116489. 6,
  116490. 3,
  116491. 7,
  116492. 2,
  116493. 8,
  116494. 1,
  116495. 9,
  116496. 0,
  116497. 10,
  116498. };
  116499. static long _vq_lengthlist__44c4_s_p7_1[] = {
  116500. 2, 4, 4, 6, 6, 7, 7, 7, 7, 8, 8,10, 5, 5, 6, 6,
  116501. 7, 7, 8, 8, 8, 8,10, 5, 5, 6, 6, 7, 7, 8, 8, 8,
  116502. 8,10, 6, 6, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10, 7,
  116503. 7, 8, 8, 8, 8, 8, 8,10,10,10, 8, 7, 8, 8, 8, 8,
  116504. 8, 8,10,10,10, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10,
  116505. 8, 8, 8, 8, 8, 8, 8, 8,10,10,10,10,10, 8, 8, 8,
  116506. 8, 8, 8,10,10,10,10,10, 9, 9, 8, 8, 9, 8,10,10,
  116507. 10,10,10, 8, 8, 8, 8, 9, 9,
  116508. };
  116509. static float _vq_quantthresh__44c4_s_p7_1[] = {
  116510. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  116511. 3.5, 4.5,
  116512. };
  116513. static long _vq_quantmap__44c4_s_p7_1[] = {
  116514. 9, 7, 5, 3, 1, 0, 2, 4,
  116515. 6, 8, 10,
  116516. };
  116517. static encode_aux_threshmatch _vq_auxt__44c4_s_p7_1 = {
  116518. _vq_quantthresh__44c4_s_p7_1,
  116519. _vq_quantmap__44c4_s_p7_1,
  116520. 11,
  116521. 11
  116522. };
  116523. static static_codebook _44c4_s_p7_1 = {
  116524. 2, 121,
  116525. _vq_lengthlist__44c4_s_p7_1,
  116526. 1, -531365888, 1611661312, 4, 0,
  116527. _vq_quantlist__44c4_s_p7_1,
  116528. NULL,
  116529. &_vq_auxt__44c4_s_p7_1,
  116530. NULL,
  116531. 0
  116532. };
  116533. static long _vq_quantlist__44c4_s_p8_0[] = {
  116534. 6,
  116535. 5,
  116536. 7,
  116537. 4,
  116538. 8,
  116539. 3,
  116540. 9,
  116541. 2,
  116542. 10,
  116543. 1,
  116544. 11,
  116545. 0,
  116546. 12,
  116547. };
  116548. static long _vq_lengthlist__44c4_s_p8_0[] = {
  116549. 1, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9,10,10, 6, 5, 5,
  116550. 7, 7, 8, 8, 8, 8, 9,10,11,11, 7, 5, 5, 7, 7, 8,
  116551. 8, 9, 9,10,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  116552. 10,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  116553. 11, 0,12,12, 9, 9, 9, 9,10,10,10,10,11,11, 0,13,
  116554. 13, 9, 9,10, 9,10,10,11,11,11,12, 0, 0, 0,10,10,
  116555. 10,10,10,10,11,11,12,12, 0, 0, 0,10,10,10,10,10,
  116556. 10,11,11,12,12, 0, 0, 0,14,14,11,11,11,11,12,12,
  116557. 12,12, 0, 0, 0,14,14,11,11,11,11,12,12,12,13, 0,
  116558. 0, 0, 0, 0,12,12,12,12,12,12,13,13, 0, 0, 0, 0,
  116559. 0,13,12,12,12,12,12,13,13,
  116560. };
  116561. static float _vq_quantthresh__44c4_s_p8_0[] = {
  116562. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  116563. 12.5, 17.5, 22.5, 27.5,
  116564. };
  116565. static long _vq_quantmap__44c4_s_p8_0[] = {
  116566. 11, 9, 7, 5, 3, 1, 0, 2,
  116567. 4, 6, 8, 10, 12,
  116568. };
  116569. static encode_aux_threshmatch _vq_auxt__44c4_s_p8_0 = {
  116570. _vq_quantthresh__44c4_s_p8_0,
  116571. _vq_quantmap__44c4_s_p8_0,
  116572. 13,
  116573. 13
  116574. };
  116575. static static_codebook _44c4_s_p8_0 = {
  116576. 2, 169,
  116577. _vq_lengthlist__44c4_s_p8_0,
  116578. 1, -526516224, 1616117760, 4, 0,
  116579. _vq_quantlist__44c4_s_p8_0,
  116580. NULL,
  116581. &_vq_auxt__44c4_s_p8_0,
  116582. NULL,
  116583. 0
  116584. };
  116585. static long _vq_quantlist__44c4_s_p8_1[] = {
  116586. 2,
  116587. 1,
  116588. 3,
  116589. 0,
  116590. 4,
  116591. };
  116592. static long _vq_lengthlist__44c4_s_p8_1[] = {
  116593. 2, 4, 4, 5, 5, 6, 5, 5, 5, 5, 6, 5, 4, 5, 5, 6,
  116594. 5, 5, 5, 5, 6, 6, 6, 5, 5,
  116595. };
  116596. static float _vq_quantthresh__44c4_s_p8_1[] = {
  116597. -1.5, -0.5, 0.5, 1.5,
  116598. };
  116599. static long _vq_quantmap__44c4_s_p8_1[] = {
  116600. 3, 1, 0, 2, 4,
  116601. };
  116602. static encode_aux_threshmatch _vq_auxt__44c4_s_p8_1 = {
  116603. _vq_quantthresh__44c4_s_p8_1,
  116604. _vq_quantmap__44c4_s_p8_1,
  116605. 5,
  116606. 5
  116607. };
  116608. static static_codebook _44c4_s_p8_1 = {
  116609. 2, 25,
  116610. _vq_lengthlist__44c4_s_p8_1,
  116611. 1, -533725184, 1611661312, 3, 0,
  116612. _vq_quantlist__44c4_s_p8_1,
  116613. NULL,
  116614. &_vq_auxt__44c4_s_p8_1,
  116615. NULL,
  116616. 0
  116617. };
  116618. static long _vq_quantlist__44c4_s_p9_0[] = {
  116619. 6,
  116620. 5,
  116621. 7,
  116622. 4,
  116623. 8,
  116624. 3,
  116625. 9,
  116626. 2,
  116627. 10,
  116628. 1,
  116629. 11,
  116630. 0,
  116631. 12,
  116632. };
  116633. static long _vq_lengthlist__44c4_s_p9_0[] = {
  116634. 1, 3, 3,12,12,12,12,12,12,12,12,12,12, 4, 7, 7,
  116635. 12,12,12,12,12,12,12,12,12,12, 3, 8, 8,12,12,12,
  116636. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  116637. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  116638. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  116639. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  116640. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  116641. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  116642. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  116643. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  116644. 12,12,12,12,12,12,12,12,12,
  116645. };
  116646. static float _vq_quantthresh__44c4_s_p9_0[] = {
  116647. -1732.5, -1417.5, -1102.5, -787.5, -472.5, -157.5, 157.5, 472.5,
  116648. 787.5, 1102.5, 1417.5, 1732.5,
  116649. };
  116650. static long _vq_quantmap__44c4_s_p9_0[] = {
  116651. 11, 9, 7, 5, 3, 1, 0, 2,
  116652. 4, 6, 8, 10, 12,
  116653. };
  116654. static encode_aux_threshmatch _vq_auxt__44c4_s_p9_0 = {
  116655. _vq_quantthresh__44c4_s_p9_0,
  116656. _vq_quantmap__44c4_s_p9_0,
  116657. 13,
  116658. 13
  116659. };
  116660. static static_codebook _44c4_s_p9_0 = {
  116661. 2, 169,
  116662. _vq_lengthlist__44c4_s_p9_0,
  116663. 1, -513964032, 1628680192, 4, 0,
  116664. _vq_quantlist__44c4_s_p9_0,
  116665. NULL,
  116666. &_vq_auxt__44c4_s_p9_0,
  116667. NULL,
  116668. 0
  116669. };
  116670. static long _vq_quantlist__44c4_s_p9_1[] = {
  116671. 7,
  116672. 6,
  116673. 8,
  116674. 5,
  116675. 9,
  116676. 4,
  116677. 10,
  116678. 3,
  116679. 11,
  116680. 2,
  116681. 12,
  116682. 1,
  116683. 13,
  116684. 0,
  116685. 14,
  116686. };
  116687. static long _vq_lengthlist__44c4_s_p9_1[] = {
  116688. 1, 4, 4, 5, 5, 7, 7, 9, 8,10, 9,10,10,10,10, 6,
  116689. 5, 5, 7, 7, 9, 8,10, 9,11,10,12,12,13,13, 6, 5,
  116690. 5, 7, 7, 9, 9,10,10,11,11,12,12,12,13,19, 8, 8,
  116691. 8, 8, 9, 9,10,10,12,11,12,12,13,13,19, 8, 8, 8,
  116692. 8, 9, 9,11,11,12,12,13,13,13,13,19,12,12, 9, 9,
  116693. 11,11,11,11,12,11,13,12,13,13,18,12,12, 9, 9,11,
  116694. 10,11,11,12,12,12,13,13,14,19,18,18,11,11,11,11,
  116695. 12,12,13,12,13,13,14,14,16,18,18,11,11,11,10,12,
  116696. 11,13,13,13,13,13,14,17,18,18,14,15,11,12,12,13,
  116697. 13,13,13,14,14,14,18,18,18,15,15,12,10,13,10,13,
  116698. 13,13,13,13,14,18,17,18,17,18,12,13,12,13,13,13,
  116699. 14,14,16,14,18,17,18,18,17,13,12,13,10,12,12,14,
  116700. 14,14,14,17,18,18,18,18,14,15,12,12,13,12,14,14,
  116701. 15,15,18,18,18,17,18,15,14,12,11,12,12,14,14,14,
  116702. 15,
  116703. };
  116704. static float _vq_quantthresh__44c4_s_p9_1[] = {
  116705. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  116706. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  116707. };
  116708. static long _vq_quantmap__44c4_s_p9_1[] = {
  116709. 13, 11, 9, 7, 5, 3, 1, 0,
  116710. 2, 4, 6, 8, 10, 12, 14,
  116711. };
  116712. static encode_aux_threshmatch _vq_auxt__44c4_s_p9_1 = {
  116713. _vq_quantthresh__44c4_s_p9_1,
  116714. _vq_quantmap__44c4_s_p9_1,
  116715. 15,
  116716. 15
  116717. };
  116718. static static_codebook _44c4_s_p9_1 = {
  116719. 2, 225,
  116720. _vq_lengthlist__44c4_s_p9_1,
  116721. 1, -520986624, 1620377600, 4, 0,
  116722. _vq_quantlist__44c4_s_p9_1,
  116723. NULL,
  116724. &_vq_auxt__44c4_s_p9_1,
  116725. NULL,
  116726. 0
  116727. };
  116728. static long _vq_quantlist__44c4_s_p9_2[] = {
  116729. 10,
  116730. 9,
  116731. 11,
  116732. 8,
  116733. 12,
  116734. 7,
  116735. 13,
  116736. 6,
  116737. 14,
  116738. 5,
  116739. 15,
  116740. 4,
  116741. 16,
  116742. 3,
  116743. 17,
  116744. 2,
  116745. 18,
  116746. 1,
  116747. 19,
  116748. 0,
  116749. 20,
  116750. };
  116751. static long _vq_lengthlist__44c4_s_p9_2[] = {
  116752. 2, 5, 5, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8,
  116753. 8, 9, 9, 9, 9,11, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,
  116754. 9, 9, 9, 9, 9, 9,10,10,10,10,11, 6, 6, 7, 7, 8,
  116755. 8, 8, 8, 9, 9, 9, 9, 9, 9,10, 9,10,10,10,10,11,
  116756. 7, 7, 7, 7, 8, 8, 9, 9, 9, 9, 9, 9, 9,10,10,10,
  116757. 10,10,10,10,12,11,11, 7, 7, 8, 8, 9, 9, 9, 9, 9,
  116758. 9,10,10,10,10,10,10,10,10,12,11,12, 8, 8, 8, 8,
  116759. 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,11,11,
  116760. 11, 8, 8, 8, 8, 9, 9, 9, 9,10,10,10,10,10,10,10,
  116761. 10,10,10,11,11,12, 9, 9, 9, 9, 9, 9,10, 9,10,10,
  116762. 10,10,10,10,10,10,10,10,11,11,11,11,11, 9, 9, 9,
  116763. 9,10,10,10,10,10,10,10,10,10,10,10,10,11,12,11,
  116764. 11,11, 9, 9, 9,10,10,10,10,10,10,10,10,10,10,10,
  116765. 10,10,11,11,11,11,11, 9, 9, 9, 9,10,10,10,10,10,
  116766. 10,10,10,10,10,10,10,11,11,11,12,12,10,10,10,10,
  116767. 10,10,10,10,10,10,10,10,10,10,10,10,11,12,11,12,
  116768. 11,11,11, 9,10,10,10,10,10,10,10,10,10,10,10,10,
  116769. 10,11,12,11,11,11,11,11,10,10,10,10,10,10,10,10,
  116770. 10,10,10,10,10,10,11,11,11,12,11,11,11,10,10,10,
  116771. 10,10,10,10,10,10,10,10,10,10,10,12,11,11,12,11,
  116772. 11,11,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  116773. 11,11,11,11,11,11,11,11,11,10,10,10,10,10,10,10,
  116774. 10,10,10,10,10,11,11,11,11,12,12,11,11,11,11,11,
  116775. 11,11,10,10,10,10,10,10,10,10,12,12,12,11,11,11,
  116776. 12,11,11,11,10,10,10,10,10,10,10,10,10,10,10,12,
  116777. 11,12,12,12,12,12,11,12,11,11,10,10,10,10,10,10,
  116778. 10,10,10,10,12,12,12,12,11,11,11,11,11,11,11,10,
  116779. 10,10,10,10,10,10,10,10,10,
  116780. };
  116781. static float _vq_quantthresh__44c4_s_p9_2[] = {
  116782. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  116783. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  116784. 6.5, 7.5, 8.5, 9.5,
  116785. };
  116786. static long _vq_quantmap__44c4_s_p9_2[] = {
  116787. 19, 17, 15, 13, 11, 9, 7, 5,
  116788. 3, 1, 0, 2, 4, 6, 8, 10,
  116789. 12, 14, 16, 18, 20,
  116790. };
  116791. static encode_aux_threshmatch _vq_auxt__44c4_s_p9_2 = {
  116792. _vq_quantthresh__44c4_s_p9_2,
  116793. _vq_quantmap__44c4_s_p9_2,
  116794. 21,
  116795. 21
  116796. };
  116797. static static_codebook _44c4_s_p9_2 = {
  116798. 2, 441,
  116799. _vq_lengthlist__44c4_s_p9_2,
  116800. 1, -529268736, 1611661312, 5, 0,
  116801. _vq_quantlist__44c4_s_p9_2,
  116802. NULL,
  116803. &_vq_auxt__44c4_s_p9_2,
  116804. NULL,
  116805. 0
  116806. };
  116807. static long _huff_lengthlist__44c4_s_short[] = {
  116808. 4, 7,14,10,15,10,12,15,16,15, 4, 2,11, 5,10, 6,
  116809. 8,11,14,14,14,10, 7,11, 6, 8,10,11,13,15, 9, 4,
  116810. 11, 5, 9, 6, 9,12,14,15,14, 9, 6, 9, 4, 5, 7,10,
  116811. 12,13, 9, 5, 7, 6, 5, 5, 7,10,13,13,10, 8, 9, 8,
  116812. 7, 6, 8,10,14,14,13,11,10,10, 7, 7, 8,11,14,15,
  116813. 13,12, 9, 9, 6, 5, 7,10,14,17,15,13,11,10, 6, 6,
  116814. 7, 9,12,17,
  116815. };
  116816. static static_codebook _huff_book__44c4_s_short = {
  116817. 2, 100,
  116818. _huff_lengthlist__44c4_s_short,
  116819. 0, 0, 0, 0, 0,
  116820. NULL,
  116821. NULL,
  116822. NULL,
  116823. NULL,
  116824. 0
  116825. };
  116826. static long _huff_lengthlist__44c5_s_long[] = {
  116827. 3, 8, 9,13,10,12,12,12,12,12, 6, 4, 6, 8, 6, 8,
  116828. 10,10,11,12, 8, 5, 4,10, 4, 7, 8, 9,10,11,13, 8,
  116829. 10, 8, 9, 9,11,12,13,14,10, 6, 4, 9, 3, 5, 6, 8,
  116830. 10,11,11, 8, 6, 9, 5, 5, 6, 7, 9,11,12, 9, 7,11,
  116831. 6, 6, 6, 7, 8,10,12,11, 9,12, 7, 7, 6, 6, 7, 9,
  116832. 13,12,10,13, 9, 8, 7, 7, 7, 8,11,15,11,15,11,10,
  116833. 9, 8, 7, 7,
  116834. };
  116835. static static_codebook _huff_book__44c5_s_long = {
  116836. 2, 100,
  116837. _huff_lengthlist__44c5_s_long,
  116838. 0, 0, 0, 0, 0,
  116839. NULL,
  116840. NULL,
  116841. NULL,
  116842. NULL,
  116843. 0
  116844. };
  116845. static long _vq_quantlist__44c5_s_p1_0[] = {
  116846. 1,
  116847. 0,
  116848. 2,
  116849. };
  116850. static long _vq_lengthlist__44c5_s_p1_0[] = {
  116851. 2, 4, 4, 0, 0, 0, 0, 0, 0, 4, 7, 7, 0, 0, 0, 0,
  116852. 0, 0, 4, 6, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116853. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116854. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116855. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116856. 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0, 0,
  116857. 0, 0, 0, 7, 8, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116858. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116859. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116860. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116861. 0, 0, 4, 7, 7, 0, 0, 0, 0, 0, 0, 7, 9, 8, 0, 0,
  116862. 0, 0, 0, 0, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116863. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116864. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116865. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116866. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116867. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116868. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116869. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116870. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116871. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116872. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116873. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116874. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116875. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116876. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116877. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116878. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116879. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116880. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116881. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116882. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116883. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116884. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116885. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116886. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116887. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116888. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116889. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116890. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116891. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116892. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116893. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116894. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116895. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116896. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 7, 7, 0, 0, 0, 0,
  116897. 0, 0, 7, 9, 9, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  116898. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116899. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116900. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116901. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0, 0,
  116902. 0, 0, 0, 9,10,11, 0, 0, 0, 0, 0, 0, 9,10,10, 0,
  116903. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116904. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116905. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116906. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  116907. 0, 0, 0, 0, 8,10, 9, 0, 0, 0, 0, 0, 0, 9,10,11,
  116908. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116909. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116910. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116911. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116912. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116913. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116914. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116915. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116916. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116917. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116918. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116919. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116920. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116921. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116922. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116923. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116924. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116925. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116926. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116927. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116928. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116929. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116930. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116931. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116932. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116933. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116934. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116935. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116936. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116937. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116938. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116939. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116940. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116941. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116942. 0, 0, 4, 7, 7, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  116943. 0, 0, 0, 0, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116944. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116945. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116946. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116947. 0, 0, 0, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,11,10, 0,
  116948. 0, 0, 0, 0, 0, 8, 9,10, 0, 0, 0, 0, 0, 0, 0, 0,
  116949. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116950. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116951. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116952. 0, 0, 0, 0, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,10,10,
  116953. 0, 0, 0, 0, 0, 0, 9,11,10, 0, 0, 0, 0, 0, 0, 0,
  116954. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116955. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116956. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116957. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116958. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116959. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116960. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116961. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116962. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116963. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116964. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116965. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116966. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116967. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116968. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116969. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116970. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116971. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116972. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116973. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116974. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116975. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116976. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116977. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116978. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116979. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116980. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116981. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116982. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116983. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116984. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116985. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116986. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116987. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116988. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116989. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116990. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116991. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116992. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116993. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116994. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116995. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116996. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116997. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116998. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116999. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117000. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117001. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117002. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117003. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117004. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117005. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117006. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117007. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117008. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117009. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117010. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117011. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117012. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117013. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117014. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117015. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117016. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117017. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117018. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117019. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117020. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117021. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117022. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117023. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117024. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117025. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117026. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117027. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117028. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117029. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117030. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117031. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117032. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117033. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117034. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117035. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117036. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117037. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117038. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117039. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117040. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117041. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117042. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117043. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117044. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117045. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117046. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117047. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117048. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117049. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117050. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117051. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117052. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117053. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117054. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117055. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117056. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117057. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117058. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117059. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117060. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117061. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117062. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117063. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117064. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117065. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117066. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117067. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117068. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117069. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117070. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117071. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117072. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117073. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117074. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117075. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117076. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117077. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117078. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117079. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117080. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117081. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117082. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117083. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117084. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117085. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117086. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117087. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117088. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117089. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117090. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117091. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117092. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117093. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117094. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117095. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117096. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117097. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117098. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117099. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117100. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117101. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117102. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117103. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117104. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117105. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117106. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117107. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117108. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117109. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117110. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117111. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117112. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117113. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117114. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117115. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117116. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117117. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117118. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117119. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117120. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117121. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117122. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117123. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117124. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117125. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117126. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117127. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117128. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117129. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117130. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117131. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117132. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117133. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117134. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117135. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117136. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117137. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117138. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117139. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117140. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117141. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117142. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117143. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117144. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117145. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117146. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117147. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117148. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117149. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117150. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117151. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117152. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117153. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117154. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117155. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117156. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117157. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117158. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117159. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117160. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117161. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117162. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117163. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117164. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117165. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117166. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117167. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117168. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117169. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117170. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117171. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117172. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117173. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117174. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117175. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117176. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117177. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117178. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117179. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117180. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117181. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117182. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117183. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117184. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117185. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117186. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117187. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117188. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117189. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117190. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117191. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117192. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117193. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117194. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117195. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117196. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117197. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117198. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117199. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117200. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117201. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117202. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117203. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117204. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117205. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117206. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117207. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117208. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117209. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117210. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117211. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117212. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117213. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117214. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117215. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117216. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117217. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117218. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117219. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117220. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117221. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117222. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117223. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117224. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117225. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117226. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117227. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117228. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117229. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117230. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117231. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117232. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117233. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117234. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117235. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117236. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117237. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117238. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117239. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117240. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117241. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117242. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117243. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117244. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117245. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117246. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117247. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117248. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117249. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117250. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117251. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117252. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117253. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117254. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117255. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117256. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117257. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117258. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117259. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117260. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117261. 0,
  117262. };
  117263. static float _vq_quantthresh__44c5_s_p1_0[] = {
  117264. -0.5, 0.5,
  117265. };
  117266. static long _vq_quantmap__44c5_s_p1_0[] = {
  117267. 1, 0, 2,
  117268. };
  117269. static encode_aux_threshmatch _vq_auxt__44c5_s_p1_0 = {
  117270. _vq_quantthresh__44c5_s_p1_0,
  117271. _vq_quantmap__44c5_s_p1_0,
  117272. 3,
  117273. 3
  117274. };
  117275. static static_codebook _44c5_s_p1_0 = {
  117276. 8, 6561,
  117277. _vq_lengthlist__44c5_s_p1_0,
  117278. 1, -535822336, 1611661312, 2, 0,
  117279. _vq_quantlist__44c5_s_p1_0,
  117280. NULL,
  117281. &_vq_auxt__44c5_s_p1_0,
  117282. NULL,
  117283. 0
  117284. };
  117285. static long _vq_quantlist__44c5_s_p2_0[] = {
  117286. 2,
  117287. 1,
  117288. 3,
  117289. 0,
  117290. 4,
  117291. };
  117292. static long _vq_lengthlist__44c5_s_p2_0[] = {
  117293. 2, 4, 4, 0, 0, 0, 5, 5, 0, 0, 0, 5, 5, 0, 0, 0,
  117294. 8, 7, 0, 0, 0, 0, 0, 0, 0, 4, 6, 6, 0, 0, 0, 8,
  117295. 8, 0, 0, 0, 8, 7, 0, 0, 0,10,10, 0, 0, 0, 0, 0,
  117296. 0, 0, 4, 6, 6, 0, 0, 0, 8, 8, 0, 0, 0, 7, 8, 0,
  117297. 0, 0,10,10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117298. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117299. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117300. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117301. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117302. 0, 0, 0, 0, 0, 0, 5, 8, 7, 0, 0, 0, 8, 8, 0, 0,
  117303. 0, 8, 8, 0, 0, 0,10,10, 0, 0, 0, 0, 0, 0, 0, 5,
  117304. 7, 8, 0, 0, 0, 8, 8, 0, 0, 0, 8, 8, 0, 0, 0,10,
  117305. 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117306. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117307. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117308. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117309. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117310. 0, 0, 0, 5, 8, 8, 0, 0, 0, 8, 8, 0, 0, 0, 8, 8,
  117311. 0, 0, 0,10,10, 0, 0, 0, 0, 0, 0, 0, 5, 8, 8, 0,
  117312. 0, 0, 8, 8, 0, 0, 0, 8, 8, 0, 0, 0,10,10, 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. 8,10,10, 0, 0, 0,10,10, 0, 0, 0, 9,10, 0, 0, 0,
  117319. 11,10, 0, 0, 0, 0, 0, 0, 0, 8,10,10, 0, 0, 0,10,
  117320. 10, 0, 0, 0,10,10, 0, 0, 0,10,11, 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,
  117333. };
  117334. static float _vq_quantthresh__44c5_s_p2_0[] = {
  117335. -1.5, -0.5, 0.5, 1.5,
  117336. };
  117337. static long _vq_quantmap__44c5_s_p2_0[] = {
  117338. 3, 1, 0, 2, 4,
  117339. };
  117340. static encode_aux_threshmatch _vq_auxt__44c5_s_p2_0 = {
  117341. _vq_quantthresh__44c5_s_p2_0,
  117342. _vq_quantmap__44c5_s_p2_0,
  117343. 5,
  117344. 5
  117345. };
  117346. static static_codebook _44c5_s_p2_0 = {
  117347. 4, 625,
  117348. _vq_lengthlist__44c5_s_p2_0,
  117349. 1, -533725184, 1611661312, 3, 0,
  117350. _vq_quantlist__44c5_s_p2_0,
  117351. NULL,
  117352. &_vq_auxt__44c5_s_p2_0,
  117353. NULL,
  117354. 0
  117355. };
  117356. static long _vq_quantlist__44c5_s_p3_0[] = {
  117357. 2,
  117358. 1,
  117359. 3,
  117360. 0,
  117361. 4,
  117362. };
  117363. static long _vq_lengthlist__44c5_s_p3_0[] = {
  117364. 2, 4, 3, 5, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117365. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 5, 5, 6, 6, 0, 0,
  117366. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117367. 0, 0, 3, 5, 5, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117368. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 6, 6, 8, 8,
  117369. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117370. 0, 0, 0, 0, 5, 6, 6, 8, 8, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117391. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117392. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117393. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117394. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117395. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117396. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117397. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117398. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117399. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117400. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117401. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117402. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117403. 0,
  117404. };
  117405. static float _vq_quantthresh__44c5_s_p3_0[] = {
  117406. -1.5, -0.5, 0.5, 1.5,
  117407. };
  117408. static long _vq_quantmap__44c5_s_p3_0[] = {
  117409. 3, 1, 0, 2, 4,
  117410. };
  117411. static encode_aux_threshmatch _vq_auxt__44c5_s_p3_0 = {
  117412. _vq_quantthresh__44c5_s_p3_0,
  117413. _vq_quantmap__44c5_s_p3_0,
  117414. 5,
  117415. 5
  117416. };
  117417. static static_codebook _44c5_s_p3_0 = {
  117418. 4, 625,
  117419. _vq_lengthlist__44c5_s_p3_0,
  117420. 1, -533725184, 1611661312, 3, 0,
  117421. _vq_quantlist__44c5_s_p3_0,
  117422. NULL,
  117423. &_vq_auxt__44c5_s_p3_0,
  117424. NULL,
  117425. 0
  117426. };
  117427. static long _vq_quantlist__44c5_s_p4_0[] = {
  117428. 4,
  117429. 3,
  117430. 5,
  117431. 2,
  117432. 6,
  117433. 1,
  117434. 7,
  117435. 0,
  117436. 8,
  117437. };
  117438. static long _vq_lengthlist__44c5_s_p4_0[] = {
  117439. 2, 3, 3, 6, 6, 0, 0, 0, 0, 0, 4, 4, 6, 6, 0, 0,
  117440. 0, 0, 0, 4, 4, 6, 6, 0, 0, 0, 0, 0, 5, 5, 6, 6,
  117441. 0, 0, 0, 0, 0, 0, 0, 6, 6, 0, 0, 0, 0, 0, 0, 0,
  117442. 7, 7, 0, 0, 0, 0, 0, 0, 0, 8, 7, 0, 0, 0, 0, 0,
  117443. 0, 0, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117444. 0,
  117445. };
  117446. static float _vq_quantthresh__44c5_s_p4_0[] = {
  117447. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  117448. };
  117449. static long _vq_quantmap__44c5_s_p4_0[] = {
  117450. 7, 5, 3, 1, 0, 2, 4, 6,
  117451. 8,
  117452. };
  117453. static encode_aux_threshmatch _vq_auxt__44c5_s_p4_0 = {
  117454. _vq_quantthresh__44c5_s_p4_0,
  117455. _vq_quantmap__44c5_s_p4_0,
  117456. 9,
  117457. 9
  117458. };
  117459. static static_codebook _44c5_s_p4_0 = {
  117460. 2, 81,
  117461. _vq_lengthlist__44c5_s_p4_0,
  117462. 1, -531628032, 1611661312, 4, 0,
  117463. _vq_quantlist__44c5_s_p4_0,
  117464. NULL,
  117465. &_vq_auxt__44c5_s_p4_0,
  117466. NULL,
  117467. 0
  117468. };
  117469. static long _vq_quantlist__44c5_s_p5_0[] = {
  117470. 4,
  117471. 3,
  117472. 5,
  117473. 2,
  117474. 6,
  117475. 1,
  117476. 7,
  117477. 0,
  117478. 8,
  117479. };
  117480. static long _vq_lengthlist__44c5_s_p5_0[] = {
  117481. 2, 4, 3, 6, 6, 7, 7, 9, 9, 0, 4, 4, 6, 6, 7, 7,
  117482. 9, 9, 0, 4, 4, 6, 6, 7, 7, 9, 9, 0, 6, 6, 7, 7,
  117483. 7, 7, 9, 9, 0, 0, 0, 7, 6, 7, 7, 9, 9, 0, 0, 0,
  117484. 8, 8, 8, 8,10,10, 0, 0, 0, 8, 8, 8, 8,10,10, 0,
  117485. 0, 0, 9, 9, 9, 9,10,10, 0, 0, 0, 0, 0, 9, 9,10,
  117486. 10,
  117487. };
  117488. static float _vq_quantthresh__44c5_s_p5_0[] = {
  117489. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  117490. };
  117491. static long _vq_quantmap__44c5_s_p5_0[] = {
  117492. 7, 5, 3, 1, 0, 2, 4, 6,
  117493. 8,
  117494. };
  117495. static encode_aux_threshmatch _vq_auxt__44c5_s_p5_0 = {
  117496. _vq_quantthresh__44c5_s_p5_0,
  117497. _vq_quantmap__44c5_s_p5_0,
  117498. 9,
  117499. 9
  117500. };
  117501. static static_codebook _44c5_s_p5_0 = {
  117502. 2, 81,
  117503. _vq_lengthlist__44c5_s_p5_0,
  117504. 1, -531628032, 1611661312, 4, 0,
  117505. _vq_quantlist__44c5_s_p5_0,
  117506. NULL,
  117507. &_vq_auxt__44c5_s_p5_0,
  117508. NULL,
  117509. 0
  117510. };
  117511. static long _vq_quantlist__44c5_s_p6_0[] = {
  117512. 8,
  117513. 7,
  117514. 9,
  117515. 6,
  117516. 10,
  117517. 5,
  117518. 11,
  117519. 4,
  117520. 12,
  117521. 3,
  117522. 13,
  117523. 2,
  117524. 14,
  117525. 1,
  117526. 15,
  117527. 0,
  117528. 16,
  117529. };
  117530. static long _vq_lengthlist__44c5_s_p6_0[] = {
  117531. 2, 4, 4, 6, 6, 8, 8, 9, 9, 9, 9,10,10,10,10,11,
  117532. 11, 0, 4, 4, 6, 6, 8, 8, 9, 9, 9, 9,10,10,11,11,
  117533. 12,12, 0, 4, 4, 6, 6, 8, 8, 9, 9, 9, 9,10,10,11,
  117534. 11,12,12, 0, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  117535. 11,11,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,
  117536. 10,11,11,12,12, 0, 0, 0, 7, 7, 9, 9,10,10,10,10,
  117537. 11,11,11,11,12,12, 0, 0, 0, 7, 7, 8, 9,10,10,10,
  117538. 10,11,11,11,11,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,
  117539. 10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 9, 9,10,
  117540. 10,10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 9, 9,
  117541. 10,10,10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 9,
  117542. 9, 9,10,10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0,
  117543. 10,10,10,10,11,11,11,12,12,12,13,13, 0, 0, 0, 0,
  117544. 0, 0, 0,10,10,11,11,11,11,12,12,13,13, 0, 0, 0,
  117545. 0, 0, 0, 0,11,11,11,11,12,12,12,13,13,13, 0, 0,
  117546. 0, 0, 0, 0, 0,11,11,11,11,12,12,12,12,13,13, 0,
  117547. 0, 0, 0, 0, 0, 0,12,12,12,12,13,12,13,13,13,13,
  117548. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,13,
  117549. 13,
  117550. };
  117551. static float _vq_quantthresh__44c5_s_p6_0[] = {
  117552. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  117553. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  117554. };
  117555. static long _vq_quantmap__44c5_s_p6_0[] = {
  117556. 15, 13, 11, 9, 7, 5, 3, 1,
  117557. 0, 2, 4, 6, 8, 10, 12, 14,
  117558. 16,
  117559. };
  117560. static encode_aux_threshmatch _vq_auxt__44c5_s_p6_0 = {
  117561. _vq_quantthresh__44c5_s_p6_0,
  117562. _vq_quantmap__44c5_s_p6_0,
  117563. 17,
  117564. 17
  117565. };
  117566. static static_codebook _44c5_s_p6_0 = {
  117567. 2, 289,
  117568. _vq_lengthlist__44c5_s_p6_0,
  117569. 1, -529530880, 1611661312, 5, 0,
  117570. _vq_quantlist__44c5_s_p6_0,
  117571. NULL,
  117572. &_vq_auxt__44c5_s_p6_0,
  117573. NULL,
  117574. 0
  117575. };
  117576. static long _vq_quantlist__44c5_s_p7_0[] = {
  117577. 1,
  117578. 0,
  117579. 2,
  117580. };
  117581. static long _vq_lengthlist__44c5_s_p7_0[] = {
  117582. 1, 4, 4, 7, 6, 6, 7, 6, 6, 4, 7, 7,10, 9, 9,11,
  117583. 9, 9, 4, 7, 7,10, 9, 9,11, 9, 9, 7,10,10,11,11,
  117584. 10,11,11,11, 6, 9, 9,11,10,10,11,10,10, 6, 9, 9,
  117585. 11,10,10,11,10,10, 7,11,11,12,11,11,12,11,11, 6,
  117586. 9, 9,11,10,10,11,10,10, 6, 9, 9,11,10,10,11,10,
  117587. 10,
  117588. };
  117589. static float _vq_quantthresh__44c5_s_p7_0[] = {
  117590. -5.5, 5.5,
  117591. };
  117592. static long _vq_quantmap__44c5_s_p7_0[] = {
  117593. 1, 0, 2,
  117594. };
  117595. static encode_aux_threshmatch _vq_auxt__44c5_s_p7_0 = {
  117596. _vq_quantthresh__44c5_s_p7_0,
  117597. _vq_quantmap__44c5_s_p7_0,
  117598. 3,
  117599. 3
  117600. };
  117601. static static_codebook _44c5_s_p7_0 = {
  117602. 4, 81,
  117603. _vq_lengthlist__44c5_s_p7_0,
  117604. 1, -529137664, 1618345984, 2, 0,
  117605. _vq_quantlist__44c5_s_p7_0,
  117606. NULL,
  117607. &_vq_auxt__44c5_s_p7_0,
  117608. NULL,
  117609. 0
  117610. };
  117611. static long _vq_quantlist__44c5_s_p7_1[] = {
  117612. 5,
  117613. 4,
  117614. 6,
  117615. 3,
  117616. 7,
  117617. 2,
  117618. 8,
  117619. 1,
  117620. 9,
  117621. 0,
  117622. 10,
  117623. };
  117624. static long _vq_lengthlist__44c5_s_p7_1[] = {
  117625. 2, 4, 4, 6, 6, 7, 7, 8, 8, 8, 8,10, 5, 5, 6, 6,
  117626. 7, 7, 8, 8, 8, 8,10, 5, 5, 6, 6, 7, 7, 8, 8, 8,
  117627. 8,10, 6, 6, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10, 7,
  117628. 7, 8, 8, 8, 8, 8, 8,10,10,10, 7, 7, 8, 8, 8, 8,
  117629. 8, 8,10,10,10, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10,
  117630. 8, 8, 8, 8, 8, 8, 8, 9,10,10,10,10,10, 8, 8, 8,
  117631. 8, 8, 8,10,10,10,10,10, 9, 9, 8, 8, 8, 8,10,10,
  117632. 10,10,10, 8, 8, 8, 8, 8, 8,
  117633. };
  117634. static float _vq_quantthresh__44c5_s_p7_1[] = {
  117635. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  117636. 3.5, 4.5,
  117637. };
  117638. static long _vq_quantmap__44c5_s_p7_1[] = {
  117639. 9, 7, 5, 3, 1, 0, 2, 4,
  117640. 6, 8, 10,
  117641. };
  117642. static encode_aux_threshmatch _vq_auxt__44c5_s_p7_1 = {
  117643. _vq_quantthresh__44c5_s_p7_1,
  117644. _vq_quantmap__44c5_s_p7_1,
  117645. 11,
  117646. 11
  117647. };
  117648. static static_codebook _44c5_s_p7_1 = {
  117649. 2, 121,
  117650. _vq_lengthlist__44c5_s_p7_1,
  117651. 1, -531365888, 1611661312, 4, 0,
  117652. _vq_quantlist__44c5_s_p7_1,
  117653. NULL,
  117654. &_vq_auxt__44c5_s_p7_1,
  117655. NULL,
  117656. 0
  117657. };
  117658. static long _vq_quantlist__44c5_s_p8_0[] = {
  117659. 6,
  117660. 5,
  117661. 7,
  117662. 4,
  117663. 8,
  117664. 3,
  117665. 9,
  117666. 2,
  117667. 10,
  117668. 1,
  117669. 11,
  117670. 0,
  117671. 12,
  117672. };
  117673. static long _vq_lengthlist__44c5_s_p8_0[] = {
  117674. 1, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9,10,10, 6, 5, 5,
  117675. 7, 7, 8, 8, 8, 9,10,10,10,10, 7, 5, 5, 7, 7, 8,
  117676. 8, 9, 9,10,10,10,10, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  117677. 10,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  117678. 11, 0,12,12, 9, 9, 9,10,10,10,10,10,11,11, 0,13,
  117679. 13, 9, 9, 9, 9,10,10,11,11,11,11, 0, 0, 0,10,10,
  117680. 10,10,10,10,11,11,11,11, 0, 0, 0,10,10,10,10,10,
  117681. 10,11,11,12,12, 0, 0, 0,14,14,11,11,11,11,12,12,
  117682. 12,12, 0, 0, 0,14,14,11,11,11,11,12,12,12,12, 0,
  117683. 0, 0, 0, 0,12,12,12,12,12,12,13,13, 0, 0, 0, 0,
  117684. 0,12,12,12,12,12,12,13,13,
  117685. };
  117686. static float _vq_quantthresh__44c5_s_p8_0[] = {
  117687. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  117688. 12.5, 17.5, 22.5, 27.5,
  117689. };
  117690. static long _vq_quantmap__44c5_s_p8_0[] = {
  117691. 11, 9, 7, 5, 3, 1, 0, 2,
  117692. 4, 6, 8, 10, 12,
  117693. };
  117694. static encode_aux_threshmatch _vq_auxt__44c5_s_p8_0 = {
  117695. _vq_quantthresh__44c5_s_p8_0,
  117696. _vq_quantmap__44c5_s_p8_0,
  117697. 13,
  117698. 13
  117699. };
  117700. static static_codebook _44c5_s_p8_0 = {
  117701. 2, 169,
  117702. _vq_lengthlist__44c5_s_p8_0,
  117703. 1, -526516224, 1616117760, 4, 0,
  117704. _vq_quantlist__44c5_s_p8_0,
  117705. NULL,
  117706. &_vq_auxt__44c5_s_p8_0,
  117707. NULL,
  117708. 0
  117709. };
  117710. static long _vq_quantlist__44c5_s_p8_1[] = {
  117711. 2,
  117712. 1,
  117713. 3,
  117714. 0,
  117715. 4,
  117716. };
  117717. static long _vq_lengthlist__44c5_s_p8_1[] = {
  117718. 2, 4, 4, 5, 5, 6, 5, 5, 5, 5, 6, 4, 5, 5, 5, 6,
  117719. 5, 5, 5, 5, 6, 6, 6, 5, 5,
  117720. };
  117721. static float _vq_quantthresh__44c5_s_p8_1[] = {
  117722. -1.5, -0.5, 0.5, 1.5,
  117723. };
  117724. static long _vq_quantmap__44c5_s_p8_1[] = {
  117725. 3, 1, 0, 2, 4,
  117726. };
  117727. static encode_aux_threshmatch _vq_auxt__44c5_s_p8_1 = {
  117728. _vq_quantthresh__44c5_s_p8_1,
  117729. _vq_quantmap__44c5_s_p8_1,
  117730. 5,
  117731. 5
  117732. };
  117733. static static_codebook _44c5_s_p8_1 = {
  117734. 2, 25,
  117735. _vq_lengthlist__44c5_s_p8_1,
  117736. 1, -533725184, 1611661312, 3, 0,
  117737. _vq_quantlist__44c5_s_p8_1,
  117738. NULL,
  117739. &_vq_auxt__44c5_s_p8_1,
  117740. NULL,
  117741. 0
  117742. };
  117743. static long _vq_quantlist__44c5_s_p9_0[] = {
  117744. 7,
  117745. 6,
  117746. 8,
  117747. 5,
  117748. 9,
  117749. 4,
  117750. 10,
  117751. 3,
  117752. 11,
  117753. 2,
  117754. 12,
  117755. 1,
  117756. 13,
  117757. 0,
  117758. 14,
  117759. };
  117760. static long _vq_lengthlist__44c5_s_p9_0[] = {
  117761. 1, 3, 3,13,13,13,13,13,13,13,13,13,13,13,13, 4,
  117762. 7, 7,13,13,13,13,13,13,13,13,13,13,13,13, 3, 8,
  117763. 6,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  117764. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  117765. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  117766. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  117767. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  117768. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  117769. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  117770. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  117771. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  117772. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  117773. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  117774. 13,13,13,13,13,13,13,13,13,12,12,12,12,12,12,12,
  117775. 12,
  117776. };
  117777. static float _vq_quantthresh__44c5_s_p9_0[] = {
  117778. -2320.5, -1963.5, -1606.5, -1249.5, -892.5, -535.5, -178.5, 178.5,
  117779. 535.5, 892.5, 1249.5, 1606.5, 1963.5, 2320.5,
  117780. };
  117781. static long _vq_quantmap__44c5_s_p9_0[] = {
  117782. 13, 11, 9, 7, 5, 3, 1, 0,
  117783. 2, 4, 6, 8, 10, 12, 14,
  117784. };
  117785. static encode_aux_threshmatch _vq_auxt__44c5_s_p9_0 = {
  117786. _vq_quantthresh__44c5_s_p9_0,
  117787. _vq_quantmap__44c5_s_p9_0,
  117788. 15,
  117789. 15
  117790. };
  117791. static static_codebook _44c5_s_p9_0 = {
  117792. 2, 225,
  117793. _vq_lengthlist__44c5_s_p9_0,
  117794. 1, -512522752, 1628852224, 4, 0,
  117795. _vq_quantlist__44c5_s_p9_0,
  117796. NULL,
  117797. &_vq_auxt__44c5_s_p9_0,
  117798. NULL,
  117799. 0
  117800. };
  117801. static long _vq_quantlist__44c5_s_p9_1[] = {
  117802. 8,
  117803. 7,
  117804. 9,
  117805. 6,
  117806. 10,
  117807. 5,
  117808. 11,
  117809. 4,
  117810. 12,
  117811. 3,
  117812. 13,
  117813. 2,
  117814. 14,
  117815. 1,
  117816. 15,
  117817. 0,
  117818. 16,
  117819. };
  117820. static long _vq_lengthlist__44c5_s_p9_1[] = {
  117821. 1, 4, 4, 5, 5, 7, 7, 9, 8,10, 9,10,10,11,10,11,
  117822. 11, 6, 5, 5, 7, 7, 8, 9,10,10,11,10,12,11,12,11,
  117823. 13,12, 6, 5, 5, 7, 7, 9, 9,10,10,11,11,12,12,13,
  117824. 12,13,13,18, 8, 8, 8, 8, 9, 9,10,11,11,11,12,11,
  117825. 13,11,13,12,18, 8, 8, 8, 8,10,10,11,11,12,12,13,
  117826. 13,13,13,13,14,18,12,12, 9, 9,11,11,11,11,12,12,
  117827. 13,12,13,12,13,13,20,13,12, 9, 9,11,11,11,11,12,
  117828. 12,13,13,13,14,14,13,20,18,19,11,12,11,11,12,12,
  117829. 13,13,13,13,13,13,14,13,18,19,19,12,11,11,11,12,
  117830. 12,13,12,13,13,13,14,14,13,18,17,19,14,15,12,12,
  117831. 12,13,13,13,14,14,14,14,14,14,19,19,19,16,15,12,
  117832. 11,13,12,14,14,14,13,13,14,14,14,19,18,19,18,19,
  117833. 13,13,13,13,14,14,14,13,14,14,14,14,18,17,19,19,
  117834. 19,13,13,13,11,13,11,13,14,14,14,14,14,19,17,17,
  117835. 18,18,16,16,13,13,13,13,14,13,15,15,14,14,19,19,
  117836. 17,17,18,16,16,13,11,14,10,13,12,14,14,14,14,19,
  117837. 19,19,19,19,18,17,13,14,13,11,14,13,14,14,15,15,
  117838. 19,19,19,17,19,18,18,14,13,12,11,14,11,15,15,15,
  117839. 15,
  117840. };
  117841. static float _vq_quantthresh__44c5_s_p9_1[] = {
  117842. -157.5, -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5,
  117843. 10.5, 31.5, 52.5, 73.5, 94.5, 115.5, 136.5, 157.5,
  117844. };
  117845. static long _vq_quantmap__44c5_s_p9_1[] = {
  117846. 15, 13, 11, 9, 7, 5, 3, 1,
  117847. 0, 2, 4, 6, 8, 10, 12, 14,
  117848. 16,
  117849. };
  117850. static encode_aux_threshmatch _vq_auxt__44c5_s_p9_1 = {
  117851. _vq_quantthresh__44c5_s_p9_1,
  117852. _vq_quantmap__44c5_s_p9_1,
  117853. 17,
  117854. 17
  117855. };
  117856. static static_codebook _44c5_s_p9_1 = {
  117857. 2, 289,
  117858. _vq_lengthlist__44c5_s_p9_1,
  117859. 1, -520814592, 1620377600, 5, 0,
  117860. _vq_quantlist__44c5_s_p9_1,
  117861. NULL,
  117862. &_vq_auxt__44c5_s_p9_1,
  117863. NULL,
  117864. 0
  117865. };
  117866. static long _vq_quantlist__44c5_s_p9_2[] = {
  117867. 10,
  117868. 9,
  117869. 11,
  117870. 8,
  117871. 12,
  117872. 7,
  117873. 13,
  117874. 6,
  117875. 14,
  117876. 5,
  117877. 15,
  117878. 4,
  117879. 16,
  117880. 3,
  117881. 17,
  117882. 2,
  117883. 18,
  117884. 1,
  117885. 19,
  117886. 0,
  117887. 20,
  117888. };
  117889. static long _vq_lengthlist__44c5_s_p9_2[] = {
  117890. 3, 5, 5, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8,
  117891. 8, 8, 8, 8, 9,11, 5, 6, 7, 7, 8, 7, 8, 8, 8, 8,
  117892. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,11, 5, 5, 7, 7, 7,
  117893. 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,11,
  117894. 7, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9,
  117895. 9,10, 9,10,11,11,11, 7, 7, 8, 8, 8, 8, 9, 9, 9,
  117896. 9, 9, 9,10,10,10,10,10,10,11,11,11, 8, 8, 8, 8,
  117897. 9, 9, 9, 9, 9, 9, 9,10,10,10,10,10,10,10,11,11,
  117898. 11, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9,10,10,10,10,10,
  117899. 10,10,10,11,11,11, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  117900. 10,10,10,10,10,10,10,10,11,11,11,11,11, 9, 9, 9,
  117901. 9, 9, 9,10, 9,10,10,10,10,10,10,10,10,11,11,11,
  117902. 11,11, 9, 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10,
  117903. 10,10,11,11,11,11,11, 9, 9, 9, 9, 9, 9,10,10,10,
  117904. 10,10,10,10,10,10,10,11,11,11,11,11, 9, 9,10, 9,
  117905. 10,10,10,10,10,10,10,10,10,10,10,10,11,11,11,11,
  117906. 11,11,11, 9, 9,10,10,10,10,10,10,10,10,10,10,10,
  117907. 10,11,11,11,11,11,11,11,10,10,10,10,10,10,10,10,
  117908. 10,10,10,10,10,10,11,11,11,11,11,11,11,10,10,10,
  117909. 10,10,10,10,10,10,10,10,10,10,10,11,11,11,11,11,
  117910. 11,11,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  117911. 11,11,11,11,11,11,11,11,11,10,10,10,10,10,10,10,
  117912. 10,10,10,10,10,11,11,11,11,11,11,11,11,11,10,10,
  117913. 10,10,10,10,10,10,10,10,10,10,11,11,11,11,11,11,
  117914. 11,11,11,10,10,10,10,10,10,10,10,10,10,10,10,11,
  117915. 11,11,11,11,11,11,11,11,10,10,10,10,10,10,10,10,
  117916. 10,10,10,10,11,11,11,11,11,11,11,11,11,11,11,10,
  117917. 10,10,10,10,10,10,10,10,10,
  117918. };
  117919. static float _vq_quantthresh__44c5_s_p9_2[] = {
  117920. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  117921. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  117922. 6.5, 7.5, 8.5, 9.5,
  117923. };
  117924. static long _vq_quantmap__44c5_s_p9_2[] = {
  117925. 19, 17, 15, 13, 11, 9, 7, 5,
  117926. 3, 1, 0, 2, 4, 6, 8, 10,
  117927. 12, 14, 16, 18, 20,
  117928. };
  117929. static encode_aux_threshmatch _vq_auxt__44c5_s_p9_2 = {
  117930. _vq_quantthresh__44c5_s_p9_2,
  117931. _vq_quantmap__44c5_s_p9_2,
  117932. 21,
  117933. 21
  117934. };
  117935. static static_codebook _44c5_s_p9_2 = {
  117936. 2, 441,
  117937. _vq_lengthlist__44c5_s_p9_2,
  117938. 1, -529268736, 1611661312, 5, 0,
  117939. _vq_quantlist__44c5_s_p9_2,
  117940. NULL,
  117941. &_vq_auxt__44c5_s_p9_2,
  117942. NULL,
  117943. 0
  117944. };
  117945. static long _huff_lengthlist__44c5_s_short[] = {
  117946. 5, 8,10,14,11,11,12,16,15,17, 5, 5, 7, 9, 7, 8,
  117947. 10,13,17,17, 7, 5, 5,10, 5, 7, 8,11,13,15,10, 8,
  117948. 10, 8, 8, 8,11,15,18,18, 8, 5, 5, 8, 3, 4, 6,10,
  117949. 14,16, 9, 7, 6, 7, 4, 3, 5, 9,14,18,10, 9, 8,10,
  117950. 6, 5, 6, 9,14,18,12,12,11,12, 8, 7, 8,11,14,18,
  117951. 14,13,12,10, 7, 5, 6, 9,14,18,14,14,13,10, 6, 5,
  117952. 6, 8,11,16,
  117953. };
  117954. static static_codebook _huff_book__44c5_s_short = {
  117955. 2, 100,
  117956. _huff_lengthlist__44c5_s_short,
  117957. 0, 0, 0, 0, 0,
  117958. NULL,
  117959. NULL,
  117960. NULL,
  117961. NULL,
  117962. 0
  117963. };
  117964. static long _huff_lengthlist__44c6_s_long[] = {
  117965. 3, 8,11,13,14,14,13,13,16,14, 6, 3, 4, 7, 9, 9,
  117966. 10,11,14,13,10, 4, 3, 5, 7, 7, 9,10,13,15,12, 7,
  117967. 4, 4, 6, 6, 8,10,13,15,12, 8, 6, 6, 6, 6, 8,10,
  117968. 13,14,11, 9, 7, 6, 6, 6, 7, 8,12,11,13,10, 9, 8,
  117969. 7, 6, 6, 7,11,11,13,11,10, 9, 9, 7, 7, 6,10,11,
  117970. 13,13,13,13,13,11, 9, 8,10,12,12,15,15,16,15,12,
  117971. 11,10,10,12,
  117972. };
  117973. static static_codebook _huff_book__44c6_s_long = {
  117974. 2, 100,
  117975. _huff_lengthlist__44c6_s_long,
  117976. 0, 0, 0, 0, 0,
  117977. NULL,
  117978. NULL,
  117979. NULL,
  117980. NULL,
  117981. 0
  117982. };
  117983. static long _vq_quantlist__44c6_s_p1_0[] = {
  117984. 1,
  117985. 0,
  117986. 2,
  117987. };
  117988. static long _vq_lengthlist__44c6_s_p1_0[] = {
  117989. 1, 5, 5, 0, 5, 5, 0, 5, 5, 5, 8, 7, 0, 9, 9, 0,
  117990. 9, 8, 5, 7, 8, 0, 9, 9, 0, 8, 9, 0, 0, 0, 0, 0,
  117991. 0, 0, 0, 0, 5, 9, 8, 0, 8, 8, 0, 8, 8, 5, 8, 9,
  117992. 0, 8, 8, 0, 8, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5,
  117993. 9, 9, 0, 8, 8, 0, 8, 8, 5, 9, 9, 0, 8, 8, 0, 8,
  117994. 8,
  117995. };
  117996. static float _vq_quantthresh__44c6_s_p1_0[] = {
  117997. -0.5, 0.5,
  117998. };
  117999. static long _vq_quantmap__44c6_s_p1_0[] = {
  118000. 1, 0, 2,
  118001. };
  118002. static encode_aux_threshmatch _vq_auxt__44c6_s_p1_0 = {
  118003. _vq_quantthresh__44c6_s_p1_0,
  118004. _vq_quantmap__44c6_s_p1_0,
  118005. 3,
  118006. 3
  118007. };
  118008. static static_codebook _44c6_s_p1_0 = {
  118009. 4, 81,
  118010. _vq_lengthlist__44c6_s_p1_0,
  118011. 1, -535822336, 1611661312, 2, 0,
  118012. _vq_quantlist__44c6_s_p1_0,
  118013. NULL,
  118014. &_vq_auxt__44c6_s_p1_0,
  118015. NULL,
  118016. 0
  118017. };
  118018. static long _vq_quantlist__44c6_s_p2_0[] = {
  118019. 2,
  118020. 1,
  118021. 3,
  118022. 0,
  118023. 4,
  118024. };
  118025. static long _vq_lengthlist__44c6_s_p2_0[] = {
  118026. 3, 5, 5, 8, 8, 0, 5, 5, 8, 8, 0, 5, 5, 8, 8, 0,
  118027. 7, 7, 9, 9, 0, 0, 0, 9, 9, 5, 7, 7, 9, 9, 0, 8,
  118028. 8,10,10, 0, 8, 7,10, 9, 0,10,10,11,11, 0, 0, 0,
  118029. 11,11, 5, 7, 7, 9, 9, 0, 8, 8,10,10, 0, 7, 8, 9,
  118030. 10, 0,10,10,11,11, 0, 0, 0,11,11, 8, 9, 9,11,11,
  118031. 0,11,11,12,12, 0,11,10,12,12, 0,13,14,14,14, 0,
  118032. 0, 0,14,13, 8, 9, 9,11,11, 0,11,11,12,12, 0,10,
  118033. 11,12,12, 0,14,13,14,14, 0, 0, 0,13,14, 0, 0, 0,
  118034. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118035. 0, 0, 0, 0, 0, 0, 5, 8, 7,11,10, 0, 7, 7,10,10,
  118036. 0, 7, 7,10,10, 0, 9, 9,11,10, 0, 0, 0,11,11, 5,
  118037. 7, 8,10,11, 0, 7, 7,10,10, 0, 7, 7,10,10, 0, 9,
  118038. 9,10,11, 0, 0, 0,11,11, 8,10, 9,12,12, 0,10,10,
  118039. 12,12, 0,10,10,12,12, 0,12,12,13,13, 0, 0, 0,13,
  118040. 13, 8, 9,10,12,12, 0,10,10,11,12, 0,10,10,12,12,
  118041. 0,12,12,13,13, 0, 0, 0,13,13, 0, 0, 0, 0, 0, 0,
  118042. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118043. 0, 0, 0, 5, 8, 8,11,11, 0, 7, 7,10,10, 0, 7, 7,
  118044. 10,10, 0, 9, 9,10,11, 0, 0, 0,11,10, 5, 8, 8,11,
  118045. 11, 0, 7, 7,10,10, 0, 7, 7,10,10, 0, 9, 9,11,11,
  118046. 0, 0, 0,10,11, 8,10,10,12,12, 0,10,10,12,12, 0,
  118047. 10,10,12,12, 0,12,13,13,13, 0, 0, 0,14,13, 8,10,
  118048. 10,12,12, 0,10,10,12,12, 0,10,10,12,12, 0,13,12,
  118049. 13,13, 0, 0, 0,13,13, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118050. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118051. 7,10,10,14,13, 0, 9, 9,13,12, 0, 9, 9,12,12, 0,
  118052. 10,10,12,12, 0, 0, 0,12,12, 7,10,10,13,14, 0, 9,
  118053. 9,12,13, 0, 9, 9,12,12, 0,10,10,12,12, 0, 0, 0,
  118054. 12,12, 9,11,11,14,13, 0,11,10,14,13, 0,11,11,13,
  118055. 13, 0,12,12,13,13, 0, 0, 0,13,13, 9,11,11,13,14,
  118056. 0,10,11,13,14, 0,11,11,13,13, 0,12,12,13,13, 0,
  118057. 0, 0,13,13, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118058. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118059. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118060. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118061. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9,
  118062. 11,11,14,14, 0,11,11,13,13, 0,11,10,13,13, 0,12,
  118063. 12,13,13, 0, 0, 0,13,13, 9,11,11,14,14, 0,11,11,
  118064. 13,13, 0,10,11,13,13, 0,12,12,14,13, 0, 0, 0,13,
  118065. 13,
  118066. };
  118067. static float _vq_quantthresh__44c6_s_p2_0[] = {
  118068. -1.5, -0.5, 0.5, 1.5,
  118069. };
  118070. static long _vq_quantmap__44c6_s_p2_0[] = {
  118071. 3, 1, 0, 2, 4,
  118072. };
  118073. static encode_aux_threshmatch _vq_auxt__44c6_s_p2_0 = {
  118074. _vq_quantthresh__44c6_s_p2_0,
  118075. _vq_quantmap__44c6_s_p2_0,
  118076. 5,
  118077. 5
  118078. };
  118079. static static_codebook _44c6_s_p2_0 = {
  118080. 4, 625,
  118081. _vq_lengthlist__44c6_s_p2_0,
  118082. 1, -533725184, 1611661312, 3, 0,
  118083. _vq_quantlist__44c6_s_p2_0,
  118084. NULL,
  118085. &_vq_auxt__44c6_s_p2_0,
  118086. NULL,
  118087. 0
  118088. };
  118089. static long _vq_quantlist__44c6_s_p3_0[] = {
  118090. 4,
  118091. 3,
  118092. 5,
  118093. 2,
  118094. 6,
  118095. 1,
  118096. 7,
  118097. 0,
  118098. 8,
  118099. };
  118100. static long _vq_lengthlist__44c6_s_p3_0[] = {
  118101. 2, 3, 4, 6, 6, 7, 7, 9, 9, 0, 4, 4, 6, 6, 7, 7,
  118102. 9,10, 0, 4, 4, 6, 6, 7, 7,10, 9, 0, 5, 5, 7, 7,
  118103. 8, 8,10,10, 0, 0, 0, 7, 6, 8, 8,10,10, 0, 0, 0,
  118104. 7, 7, 9, 9,11,11, 0, 0, 0, 7, 7, 9, 9,11,11, 0,
  118105. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118106. 0,
  118107. };
  118108. static float _vq_quantthresh__44c6_s_p3_0[] = {
  118109. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  118110. };
  118111. static long _vq_quantmap__44c6_s_p3_0[] = {
  118112. 7, 5, 3, 1, 0, 2, 4, 6,
  118113. 8,
  118114. };
  118115. static encode_aux_threshmatch _vq_auxt__44c6_s_p3_0 = {
  118116. _vq_quantthresh__44c6_s_p3_0,
  118117. _vq_quantmap__44c6_s_p3_0,
  118118. 9,
  118119. 9
  118120. };
  118121. static static_codebook _44c6_s_p3_0 = {
  118122. 2, 81,
  118123. _vq_lengthlist__44c6_s_p3_0,
  118124. 1, -531628032, 1611661312, 4, 0,
  118125. _vq_quantlist__44c6_s_p3_0,
  118126. NULL,
  118127. &_vq_auxt__44c6_s_p3_0,
  118128. NULL,
  118129. 0
  118130. };
  118131. static long _vq_quantlist__44c6_s_p4_0[] = {
  118132. 8,
  118133. 7,
  118134. 9,
  118135. 6,
  118136. 10,
  118137. 5,
  118138. 11,
  118139. 4,
  118140. 12,
  118141. 3,
  118142. 13,
  118143. 2,
  118144. 14,
  118145. 1,
  118146. 15,
  118147. 0,
  118148. 16,
  118149. };
  118150. static long _vq_lengthlist__44c6_s_p4_0[] = {
  118151. 2, 4, 4, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9,10,10,
  118152. 10, 0, 4, 4, 6, 6, 8, 8, 9, 9, 9, 9,10,10,10,10,
  118153. 11,11, 0, 4, 4, 6, 6, 8, 8, 9, 9, 9, 9,10,10,10,
  118154. 10,11,11, 0, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  118155. 11,11,11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,
  118156. 10,11,11,11,11, 0, 0, 0, 7, 7, 9, 9,10,10,10,10,
  118157. 11,11,11,11,12,12, 0, 0, 0, 7, 7, 9, 9,10,10,10,
  118158. 10,11,11,11,11,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9,
  118159. 10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 8, 8, 9,
  118160. 9,10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 0, 0,
  118161. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118162. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118163. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118164. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118165. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118166. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118167. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118168. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118169. 0,
  118170. };
  118171. static float _vq_quantthresh__44c6_s_p4_0[] = {
  118172. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  118173. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  118174. };
  118175. static long _vq_quantmap__44c6_s_p4_0[] = {
  118176. 15, 13, 11, 9, 7, 5, 3, 1,
  118177. 0, 2, 4, 6, 8, 10, 12, 14,
  118178. 16,
  118179. };
  118180. static encode_aux_threshmatch _vq_auxt__44c6_s_p4_0 = {
  118181. _vq_quantthresh__44c6_s_p4_0,
  118182. _vq_quantmap__44c6_s_p4_0,
  118183. 17,
  118184. 17
  118185. };
  118186. static static_codebook _44c6_s_p4_0 = {
  118187. 2, 289,
  118188. _vq_lengthlist__44c6_s_p4_0,
  118189. 1, -529530880, 1611661312, 5, 0,
  118190. _vq_quantlist__44c6_s_p4_0,
  118191. NULL,
  118192. &_vq_auxt__44c6_s_p4_0,
  118193. NULL,
  118194. 0
  118195. };
  118196. static long _vq_quantlist__44c6_s_p5_0[] = {
  118197. 1,
  118198. 0,
  118199. 2,
  118200. };
  118201. static long _vq_lengthlist__44c6_s_p5_0[] = {
  118202. 1, 4, 4, 5, 7, 7, 6, 7, 7, 4, 6, 6, 9, 9,10,10,
  118203. 10, 9, 4, 6, 6, 9,10, 9,10, 9,10, 6, 9, 9,10,12,
  118204. 11,10,11,11, 7,10, 9,11,12,12,12,12,12, 7,10,10,
  118205. 11,12,12,12,12,12, 6,10,10,10,12,12,11,12,12, 7,
  118206. 9,10,11,12,12,12,12,12, 7,10, 9,12,12,12,12,12,
  118207. 12,
  118208. };
  118209. static float _vq_quantthresh__44c6_s_p5_0[] = {
  118210. -5.5, 5.5,
  118211. };
  118212. static long _vq_quantmap__44c6_s_p5_0[] = {
  118213. 1, 0, 2,
  118214. };
  118215. static encode_aux_threshmatch _vq_auxt__44c6_s_p5_0 = {
  118216. _vq_quantthresh__44c6_s_p5_0,
  118217. _vq_quantmap__44c6_s_p5_0,
  118218. 3,
  118219. 3
  118220. };
  118221. static static_codebook _44c6_s_p5_0 = {
  118222. 4, 81,
  118223. _vq_lengthlist__44c6_s_p5_0,
  118224. 1, -529137664, 1618345984, 2, 0,
  118225. _vq_quantlist__44c6_s_p5_0,
  118226. NULL,
  118227. &_vq_auxt__44c6_s_p5_0,
  118228. NULL,
  118229. 0
  118230. };
  118231. static long _vq_quantlist__44c6_s_p5_1[] = {
  118232. 5,
  118233. 4,
  118234. 6,
  118235. 3,
  118236. 7,
  118237. 2,
  118238. 8,
  118239. 1,
  118240. 9,
  118241. 0,
  118242. 10,
  118243. };
  118244. static long _vq_lengthlist__44c6_s_p5_1[] = {
  118245. 3, 5, 4, 6, 6, 7, 7, 8, 8, 8, 8,11, 4, 4, 6, 6,
  118246. 7, 7, 8, 8, 8, 8,11, 4, 4, 6, 6, 7, 7, 8, 8, 8,
  118247. 8,11, 6, 6, 6, 6, 8, 8, 8, 8, 9, 9,11,11,11, 6,
  118248. 6, 7, 8, 8, 8, 8, 9,11,11,11, 7, 7, 8, 8, 8, 8,
  118249. 8, 8,11,11,11, 7, 7, 8, 8, 8, 8, 8, 8,11,11,11,
  118250. 8, 8, 8, 8, 8, 8, 8, 8,11,11,11,10,10, 8, 8, 8,
  118251. 8, 8, 8,11,11,11,10,10, 8, 8, 8, 8, 8, 8,11,11,
  118252. 11,10,10, 7, 7, 8, 8, 8, 8,
  118253. };
  118254. static float _vq_quantthresh__44c6_s_p5_1[] = {
  118255. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  118256. 3.5, 4.5,
  118257. };
  118258. static long _vq_quantmap__44c6_s_p5_1[] = {
  118259. 9, 7, 5, 3, 1, 0, 2, 4,
  118260. 6, 8, 10,
  118261. };
  118262. static encode_aux_threshmatch _vq_auxt__44c6_s_p5_1 = {
  118263. _vq_quantthresh__44c6_s_p5_1,
  118264. _vq_quantmap__44c6_s_p5_1,
  118265. 11,
  118266. 11
  118267. };
  118268. static static_codebook _44c6_s_p5_1 = {
  118269. 2, 121,
  118270. _vq_lengthlist__44c6_s_p5_1,
  118271. 1, -531365888, 1611661312, 4, 0,
  118272. _vq_quantlist__44c6_s_p5_1,
  118273. NULL,
  118274. &_vq_auxt__44c6_s_p5_1,
  118275. NULL,
  118276. 0
  118277. };
  118278. static long _vq_quantlist__44c6_s_p6_0[] = {
  118279. 6,
  118280. 5,
  118281. 7,
  118282. 4,
  118283. 8,
  118284. 3,
  118285. 9,
  118286. 2,
  118287. 10,
  118288. 1,
  118289. 11,
  118290. 0,
  118291. 12,
  118292. };
  118293. static long _vq_lengthlist__44c6_s_p6_0[] = {
  118294. 1, 4, 4, 6, 6, 8, 8, 8, 8,10, 9,10,10, 6, 5, 5,
  118295. 7, 7, 9, 9, 9, 9,10,10,11,11, 6, 5, 5, 7, 7, 9,
  118296. 9,10, 9,11,10,11,11, 0, 6, 6, 7, 7, 9, 9,10,10,
  118297. 11,11,12,12, 0, 7, 7, 7, 7, 9, 9,10,10,11,11,12,
  118298. 12, 0,11,11, 8, 8,10,10,11,11,12,12,12,12, 0,11,
  118299. 12, 9, 8,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0,
  118300. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118301. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118302. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118303. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118304. 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118305. };
  118306. static float _vq_quantthresh__44c6_s_p6_0[] = {
  118307. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  118308. 12.5, 17.5, 22.5, 27.5,
  118309. };
  118310. static long _vq_quantmap__44c6_s_p6_0[] = {
  118311. 11, 9, 7, 5, 3, 1, 0, 2,
  118312. 4, 6, 8, 10, 12,
  118313. };
  118314. static encode_aux_threshmatch _vq_auxt__44c6_s_p6_0 = {
  118315. _vq_quantthresh__44c6_s_p6_0,
  118316. _vq_quantmap__44c6_s_p6_0,
  118317. 13,
  118318. 13
  118319. };
  118320. static static_codebook _44c6_s_p6_0 = {
  118321. 2, 169,
  118322. _vq_lengthlist__44c6_s_p6_0,
  118323. 1, -526516224, 1616117760, 4, 0,
  118324. _vq_quantlist__44c6_s_p6_0,
  118325. NULL,
  118326. &_vq_auxt__44c6_s_p6_0,
  118327. NULL,
  118328. 0
  118329. };
  118330. static long _vq_quantlist__44c6_s_p6_1[] = {
  118331. 2,
  118332. 1,
  118333. 3,
  118334. 0,
  118335. 4,
  118336. };
  118337. static long _vq_lengthlist__44c6_s_p6_1[] = {
  118338. 3, 4, 4, 5, 5, 5, 4, 4, 5, 5, 5, 4, 4, 5, 5, 6,
  118339. 5, 5, 5, 5, 6, 6, 6, 5, 5,
  118340. };
  118341. static float _vq_quantthresh__44c6_s_p6_1[] = {
  118342. -1.5, -0.5, 0.5, 1.5,
  118343. };
  118344. static long _vq_quantmap__44c6_s_p6_1[] = {
  118345. 3, 1, 0, 2, 4,
  118346. };
  118347. static encode_aux_threshmatch _vq_auxt__44c6_s_p6_1 = {
  118348. _vq_quantthresh__44c6_s_p6_1,
  118349. _vq_quantmap__44c6_s_p6_1,
  118350. 5,
  118351. 5
  118352. };
  118353. static static_codebook _44c6_s_p6_1 = {
  118354. 2, 25,
  118355. _vq_lengthlist__44c6_s_p6_1,
  118356. 1, -533725184, 1611661312, 3, 0,
  118357. _vq_quantlist__44c6_s_p6_1,
  118358. NULL,
  118359. &_vq_auxt__44c6_s_p6_1,
  118360. NULL,
  118361. 0
  118362. };
  118363. static long _vq_quantlist__44c6_s_p7_0[] = {
  118364. 6,
  118365. 5,
  118366. 7,
  118367. 4,
  118368. 8,
  118369. 3,
  118370. 9,
  118371. 2,
  118372. 10,
  118373. 1,
  118374. 11,
  118375. 0,
  118376. 12,
  118377. };
  118378. static long _vq_lengthlist__44c6_s_p7_0[] = {
  118379. 1, 4, 4, 6, 6, 8, 8, 8, 8,10,10,11,10, 6, 5, 5,
  118380. 7, 7, 8, 8, 9, 9,10,10,12,11, 6, 5, 5, 7, 7, 8,
  118381. 8, 9, 9,10,10,12,11,21, 7, 7, 7, 7, 9, 9,10,10,
  118382. 11,11,12,12,21, 7, 7, 7, 7, 9, 9,10,10,11,11,12,
  118383. 12,21,12,12, 9, 9,10,10,11,11,11,11,12,12,21,12,
  118384. 12, 9, 9,10,10,11,11,12,12,12,12,21,21,21,11,11,
  118385. 10,10,11,12,12,12,13,13,21,21,21,11,11,10,10,12,
  118386. 12,12,12,13,13,21,21,21,15,15,11,11,12,12,13,13,
  118387. 13,13,21,21,21,15,16,11,11,12,12,13,13,14,14,21,
  118388. 21,21,21,20,13,13,13,13,13,13,14,14,20,20,20,20,
  118389. 20,13,13,13,13,13,13,14,14,
  118390. };
  118391. static float _vq_quantthresh__44c6_s_p7_0[] = {
  118392. -60.5, -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5,
  118393. 27.5, 38.5, 49.5, 60.5,
  118394. };
  118395. static long _vq_quantmap__44c6_s_p7_0[] = {
  118396. 11, 9, 7, 5, 3, 1, 0, 2,
  118397. 4, 6, 8, 10, 12,
  118398. };
  118399. static encode_aux_threshmatch _vq_auxt__44c6_s_p7_0 = {
  118400. _vq_quantthresh__44c6_s_p7_0,
  118401. _vq_quantmap__44c6_s_p7_0,
  118402. 13,
  118403. 13
  118404. };
  118405. static static_codebook _44c6_s_p7_0 = {
  118406. 2, 169,
  118407. _vq_lengthlist__44c6_s_p7_0,
  118408. 1, -523206656, 1618345984, 4, 0,
  118409. _vq_quantlist__44c6_s_p7_0,
  118410. NULL,
  118411. &_vq_auxt__44c6_s_p7_0,
  118412. NULL,
  118413. 0
  118414. };
  118415. static long _vq_quantlist__44c6_s_p7_1[] = {
  118416. 5,
  118417. 4,
  118418. 6,
  118419. 3,
  118420. 7,
  118421. 2,
  118422. 8,
  118423. 1,
  118424. 9,
  118425. 0,
  118426. 10,
  118427. };
  118428. static long _vq_lengthlist__44c6_s_p7_1[] = {
  118429. 3, 5, 5, 6, 6, 7, 7, 7, 7, 7, 7, 9, 5, 5, 6, 6,
  118430. 7, 7, 7, 7, 8, 7, 8, 5, 5, 6, 6, 7, 7, 7, 7, 7,
  118431. 7, 9, 6, 6, 7, 7, 7, 7, 8, 7, 7, 8, 9, 9, 9, 7,
  118432. 7, 7, 7, 7, 7, 7, 8, 9, 9, 9, 7, 7, 7, 7, 8, 8,
  118433. 8, 8, 9, 9, 9, 7, 7, 7, 7, 7, 7, 8, 8, 9, 9, 9,
  118434. 8, 8, 8, 8, 7, 7, 8, 8, 9, 9, 9, 9, 8, 8, 8, 7,
  118435. 7, 8, 8, 9, 9, 9, 8, 8, 8, 8, 7, 7, 8, 8, 9, 9,
  118436. 9, 8, 8, 7, 7, 7, 7, 8, 8,
  118437. };
  118438. static float _vq_quantthresh__44c6_s_p7_1[] = {
  118439. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  118440. 3.5, 4.5,
  118441. };
  118442. static long _vq_quantmap__44c6_s_p7_1[] = {
  118443. 9, 7, 5, 3, 1, 0, 2, 4,
  118444. 6, 8, 10,
  118445. };
  118446. static encode_aux_threshmatch _vq_auxt__44c6_s_p7_1 = {
  118447. _vq_quantthresh__44c6_s_p7_1,
  118448. _vq_quantmap__44c6_s_p7_1,
  118449. 11,
  118450. 11
  118451. };
  118452. static static_codebook _44c6_s_p7_1 = {
  118453. 2, 121,
  118454. _vq_lengthlist__44c6_s_p7_1,
  118455. 1, -531365888, 1611661312, 4, 0,
  118456. _vq_quantlist__44c6_s_p7_1,
  118457. NULL,
  118458. &_vq_auxt__44c6_s_p7_1,
  118459. NULL,
  118460. 0
  118461. };
  118462. static long _vq_quantlist__44c6_s_p8_0[] = {
  118463. 7,
  118464. 6,
  118465. 8,
  118466. 5,
  118467. 9,
  118468. 4,
  118469. 10,
  118470. 3,
  118471. 11,
  118472. 2,
  118473. 12,
  118474. 1,
  118475. 13,
  118476. 0,
  118477. 14,
  118478. };
  118479. static long _vq_lengthlist__44c6_s_p8_0[] = {
  118480. 1, 4, 4, 7, 7, 8, 8, 7, 7, 8, 7, 9, 8,10, 9, 6,
  118481. 5, 5, 8, 8, 9, 9, 8, 8, 9, 9,11,10,11,10, 6, 5,
  118482. 5, 8, 8, 9, 9, 8, 8, 9, 9,10,10,11,11,18, 8, 8,
  118483. 9, 8,10,10, 9, 9,10,10,10,10,11,10,18, 8, 8, 9,
  118484. 9,10,10, 9, 9,10,10,11,11,12,12,18,12,13, 9,10,
  118485. 10,10, 9,10,10,10,11,11,12,11,18,13,13, 9, 9,10,
  118486. 10,10,10,10,10,11,11,12,12,18,18,18,10,10, 9, 9,
  118487. 11,11,11,11,11,12,12,12,18,18,18,10, 9,10, 9,11,
  118488. 10,11,11,11,11,13,12,18,18,18,14,13,10,10,11,11,
  118489. 12,12,12,12,12,12,18,18,18,14,13,10,10,11,10,12,
  118490. 12,12,12,12,12,18,18,18,18,18,12,12,11,11,12,12,
  118491. 13,13,13,14,18,18,18,18,18,12,12,11,11,12,11,13,
  118492. 13,14,13,18,18,18,18,18,16,16,11,12,12,13,13,13,
  118493. 14,13,18,18,18,18,18,16,15,12,11,12,11,13,11,15,
  118494. 14,
  118495. };
  118496. static float _vq_quantthresh__44c6_s_p8_0[] = {
  118497. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  118498. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  118499. };
  118500. static long _vq_quantmap__44c6_s_p8_0[] = {
  118501. 13, 11, 9, 7, 5, 3, 1, 0,
  118502. 2, 4, 6, 8, 10, 12, 14,
  118503. };
  118504. static encode_aux_threshmatch _vq_auxt__44c6_s_p8_0 = {
  118505. _vq_quantthresh__44c6_s_p8_0,
  118506. _vq_quantmap__44c6_s_p8_0,
  118507. 15,
  118508. 15
  118509. };
  118510. static static_codebook _44c6_s_p8_0 = {
  118511. 2, 225,
  118512. _vq_lengthlist__44c6_s_p8_0,
  118513. 1, -520986624, 1620377600, 4, 0,
  118514. _vq_quantlist__44c6_s_p8_0,
  118515. NULL,
  118516. &_vq_auxt__44c6_s_p8_0,
  118517. NULL,
  118518. 0
  118519. };
  118520. static long _vq_quantlist__44c6_s_p8_1[] = {
  118521. 10,
  118522. 9,
  118523. 11,
  118524. 8,
  118525. 12,
  118526. 7,
  118527. 13,
  118528. 6,
  118529. 14,
  118530. 5,
  118531. 15,
  118532. 4,
  118533. 16,
  118534. 3,
  118535. 17,
  118536. 2,
  118537. 18,
  118538. 1,
  118539. 19,
  118540. 0,
  118541. 20,
  118542. };
  118543. static long _vq_lengthlist__44c6_s_p8_1[] = {
  118544. 3, 5, 5, 6, 6, 7, 7, 7, 7, 8, 7, 8, 8, 8, 8, 8,
  118545. 8, 8, 8, 8, 8,10, 6, 6, 7, 7, 8, 8, 8, 8, 8, 8,
  118546. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 6, 6, 7, 7, 8,
  118547. 8, 8, 8, 8, 8, 9, 8, 9, 9, 9, 9, 9, 9, 9, 9,10,
  118548. 7, 7, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  118549. 9, 9, 9, 9,10,11,11, 8, 7, 8, 8, 8, 9, 9, 9, 9,
  118550. 9, 9, 9, 9, 9, 9, 9, 9, 9,11,11,11, 8, 8, 8, 8,
  118551. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,11,11,
  118552. 11, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  118553. 9, 9, 9,11,11,11, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  118554. 9, 9, 9, 9, 9, 9, 9, 9,11,11,11,11,11, 9, 9, 9,
  118555. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10, 9,11,11,11,
  118556. 11,11, 9, 9, 9, 9, 9, 9,10, 9, 9,10, 9,10, 9, 9,
  118557. 10, 9,11,11,11,11,11, 9, 9, 9, 9, 9, 9, 9,10,10,
  118558. 10,10, 9,10,10, 9,10,11,11,11,11,11, 9, 9, 9, 9,
  118559. 10,10,10, 9,10,10,10,10, 9,10,10, 9,11,11,11,11,
  118560. 11,11,11, 9, 9, 9, 9,10,10,10,10, 9,10,10,10,10,
  118561. 10,11,11,11,11,11,11,11,10, 9,10,10,10,10,10,10,
  118562. 10, 9,10, 9,10,10,11,11,11,11,11,11,11,10, 9,10,
  118563. 9,10,10, 9,10,10,10,10,10,10,10,11,11,11,11,11,
  118564. 11,11,10,10,10,10,10,10,10, 9,10,10,10,10,10, 9,
  118565. 11,11,11,11,11,11,11,11,11,10,10,10,10,10,10,10,
  118566. 10,10,10,10,10,11,11,11,11,11,11,11,11,11,10,10,
  118567. 10,10,10,10,10,10,10,10,10,10,11,11,11,11,11,11,
  118568. 11,11,11,10,10,10,10,10,10,10,10,10, 9,10,10,11,
  118569. 11,11,11,11,11,11,11,11,10,10,10, 9,10,10,10,10,
  118570. 10,10,10,10,10,11,11,11,11,11,11,11,11,10,11, 9,
  118571. 10,10,10,10,10,10,10,10,10,
  118572. };
  118573. static float _vq_quantthresh__44c6_s_p8_1[] = {
  118574. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  118575. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  118576. 6.5, 7.5, 8.5, 9.5,
  118577. };
  118578. static long _vq_quantmap__44c6_s_p8_1[] = {
  118579. 19, 17, 15, 13, 11, 9, 7, 5,
  118580. 3, 1, 0, 2, 4, 6, 8, 10,
  118581. 12, 14, 16, 18, 20,
  118582. };
  118583. static encode_aux_threshmatch _vq_auxt__44c6_s_p8_1 = {
  118584. _vq_quantthresh__44c6_s_p8_1,
  118585. _vq_quantmap__44c6_s_p8_1,
  118586. 21,
  118587. 21
  118588. };
  118589. static static_codebook _44c6_s_p8_1 = {
  118590. 2, 441,
  118591. _vq_lengthlist__44c6_s_p8_1,
  118592. 1, -529268736, 1611661312, 5, 0,
  118593. _vq_quantlist__44c6_s_p8_1,
  118594. NULL,
  118595. &_vq_auxt__44c6_s_p8_1,
  118596. NULL,
  118597. 0
  118598. };
  118599. static long _vq_quantlist__44c6_s_p9_0[] = {
  118600. 6,
  118601. 5,
  118602. 7,
  118603. 4,
  118604. 8,
  118605. 3,
  118606. 9,
  118607. 2,
  118608. 10,
  118609. 1,
  118610. 11,
  118611. 0,
  118612. 12,
  118613. };
  118614. static long _vq_lengthlist__44c6_s_p9_0[] = {
  118615. 1, 3, 3,11,11,11,11,11,11,11,11,11,11, 4, 7, 7,
  118616. 11,11,11,11,11,11,11,11,11,11, 5, 8, 9,11,11,11,
  118617. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  118618. 11,11,11,11,11,10,10,10,10,10,10,10,10,10,10,10,
  118619. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  118620. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  118621. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  118622. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  118623. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  118624. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  118625. 10,10,10,10,10,10,10,10,10,
  118626. };
  118627. static float _vq_quantthresh__44c6_s_p9_0[] = {
  118628. -3503.5, -2866.5, -2229.5, -1592.5, -955.5, -318.5, 318.5, 955.5,
  118629. 1592.5, 2229.5, 2866.5, 3503.5,
  118630. };
  118631. static long _vq_quantmap__44c6_s_p9_0[] = {
  118632. 11, 9, 7, 5, 3, 1, 0, 2,
  118633. 4, 6, 8, 10, 12,
  118634. };
  118635. static encode_aux_threshmatch _vq_auxt__44c6_s_p9_0 = {
  118636. _vq_quantthresh__44c6_s_p9_0,
  118637. _vq_quantmap__44c6_s_p9_0,
  118638. 13,
  118639. 13
  118640. };
  118641. static static_codebook _44c6_s_p9_0 = {
  118642. 2, 169,
  118643. _vq_lengthlist__44c6_s_p9_0,
  118644. 1, -511845376, 1630791680, 4, 0,
  118645. _vq_quantlist__44c6_s_p9_0,
  118646. NULL,
  118647. &_vq_auxt__44c6_s_p9_0,
  118648. NULL,
  118649. 0
  118650. };
  118651. static long _vq_quantlist__44c6_s_p9_1[] = {
  118652. 6,
  118653. 5,
  118654. 7,
  118655. 4,
  118656. 8,
  118657. 3,
  118658. 9,
  118659. 2,
  118660. 10,
  118661. 1,
  118662. 11,
  118663. 0,
  118664. 12,
  118665. };
  118666. static long _vq_lengthlist__44c6_s_p9_1[] = {
  118667. 1, 4, 4, 7, 7, 7, 7, 7, 6, 8, 8, 8, 8, 6, 6, 6,
  118668. 8, 8, 8, 8, 8, 7, 9, 8,10,10, 5, 6, 6, 8, 8, 9,
  118669. 9, 8, 8,10,10,10,10,16, 9, 9, 9, 9, 9, 9, 9, 8,
  118670. 10, 9,11,11,16, 8, 9, 9, 9, 9, 9, 9, 9,10,10,11,
  118671. 11,16,13,13, 9, 9,10, 9, 9,10,11,11,11,12,16,13,
  118672. 14, 9, 8,10, 8, 9, 9,10,10,12,11,16,14,16, 9, 9,
  118673. 9, 9,11,11,12,11,12,11,16,16,16, 9, 7, 9, 6,11,
  118674. 11,11,10,11,11,16,16,16,11,12, 9,10,11,11,12,11,
  118675. 13,13,16,16,16,12,11,10, 7,12,10,12,12,12,12,16,
  118676. 16,15,16,16,10,11,10,11,13,13,14,12,16,16,16,15,
  118677. 15,12,10,11,11,13,11,12,13,
  118678. };
  118679. static float _vq_quantthresh__44c6_s_p9_1[] = {
  118680. -269.5, -220.5, -171.5, -122.5, -73.5, -24.5, 24.5, 73.5,
  118681. 122.5, 171.5, 220.5, 269.5,
  118682. };
  118683. static long _vq_quantmap__44c6_s_p9_1[] = {
  118684. 11, 9, 7, 5, 3, 1, 0, 2,
  118685. 4, 6, 8, 10, 12,
  118686. };
  118687. static encode_aux_threshmatch _vq_auxt__44c6_s_p9_1 = {
  118688. _vq_quantthresh__44c6_s_p9_1,
  118689. _vq_quantmap__44c6_s_p9_1,
  118690. 13,
  118691. 13
  118692. };
  118693. static static_codebook _44c6_s_p9_1 = {
  118694. 2, 169,
  118695. _vq_lengthlist__44c6_s_p9_1,
  118696. 1, -518889472, 1622704128, 4, 0,
  118697. _vq_quantlist__44c6_s_p9_1,
  118698. NULL,
  118699. &_vq_auxt__44c6_s_p9_1,
  118700. NULL,
  118701. 0
  118702. };
  118703. static long _vq_quantlist__44c6_s_p9_2[] = {
  118704. 24,
  118705. 23,
  118706. 25,
  118707. 22,
  118708. 26,
  118709. 21,
  118710. 27,
  118711. 20,
  118712. 28,
  118713. 19,
  118714. 29,
  118715. 18,
  118716. 30,
  118717. 17,
  118718. 31,
  118719. 16,
  118720. 32,
  118721. 15,
  118722. 33,
  118723. 14,
  118724. 34,
  118725. 13,
  118726. 35,
  118727. 12,
  118728. 36,
  118729. 11,
  118730. 37,
  118731. 10,
  118732. 38,
  118733. 9,
  118734. 39,
  118735. 8,
  118736. 40,
  118737. 7,
  118738. 41,
  118739. 6,
  118740. 42,
  118741. 5,
  118742. 43,
  118743. 4,
  118744. 44,
  118745. 3,
  118746. 45,
  118747. 2,
  118748. 46,
  118749. 1,
  118750. 47,
  118751. 0,
  118752. 48,
  118753. };
  118754. static long _vq_lengthlist__44c6_s_p9_2[] = {
  118755. 2, 4, 3, 4, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6, 6,
  118756. 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  118757. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  118758. 7,
  118759. };
  118760. static float _vq_quantthresh__44c6_s_p9_2[] = {
  118761. -23.5, -22.5, -21.5, -20.5, -19.5, -18.5, -17.5, -16.5,
  118762. -15.5, -14.5, -13.5, -12.5, -11.5, -10.5, -9.5, -8.5,
  118763. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  118764. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  118765. 8.5, 9.5, 10.5, 11.5, 12.5, 13.5, 14.5, 15.5,
  118766. 16.5, 17.5, 18.5, 19.5, 20.5, 21.5, 22.5, 23.5,
  118767. };
  118768. static long _vq_quantmap__44c6_s_p9_2[] = {
  118769. 47, 45, 43, 41, 39, 37, 35, 33,
  118770. 31, 29, 27, 25, 23, 21, 19, 17,
  118771. 15, 13, 11, 9, 7, 5, 3, 1,
  118772. 0, 2, 4, 6, 8, 10, 12, 14,
  118773. 16, 18, 20, 22, 24, 26, 28, 30,
  118774. 32, 34, 36, 38, 40, 42, 44, 46,
  118775. 48,
  118776. };
  118777. static encode_aux_threshmatch _vq_auxt__44c6_s_p9_2 = {
  118778. _vq_quantthresh__44c6_s_p9_2,
  118779. _vq_quantmap__44c6_s_p9_2,
  118780. 49,
  118781. 49
  118782. };
  118783. static static_codebook _44c6_s_p9_2 = {
  118784. 1, 49,
  118785. _vq_lengthlist__44c6_s_p9_2,
  118786. 1, -526909440, 1611661312, 6, 0,
  118787. _vq_quantlist__44c6_s_p9_2,
  118788. NULL,
  118789. &_vq_auxt__44c6_s_p9_2,
  118790. NULL,
  118791. 0
  118792. };
  118793. static long _huff_lengthlist__44c6_s_short[] = {
  118794. 3, 9,11,11,13,14,19,17,17,19, 5, 4, 5, 8,10,10,
  118795. 13,16,18,19, 7, 4, 4, 5, 8, 9,12,14,17,19, 8, 6,
  118796. 5, 5, 7, 7,10,13,16,18,10, 8, 7, 6, 5, 5, 8,11,
  118797. 17,19,11, 9, 7, 7, 5, 4, 5, 8,17,19,13,11, 8, 7,
  118798. 7, 5, 5, 7,16,18,14,13, 8, 6, 6, 5, 5, 7,16,18,
  118799. 18,16,10, 8, 8, 7, 7, 9,16,18,18,18,12,10,10, 9,
  118800. 9,10,17,18,
  118801. };
  118802. static static_codebook _huff_book__44c6_s_short = {
  118803. 2, 100,
  118804. _huff_lengthlist__44c6_s_short,
  118805. 0, 0, 0, 0, 0,
  118806. NULL,
  118807. NULL,
  118808. NULL,
  118809. NULL,
  118810. 0
  118811. };
  118812. static long _huff_lengthlist__44c7_s_long[] = {
  118813. 3, 8,11,13,15,14,14,13,15,14, 6, 4, 5, 7, 9,10,
  118814. 11,11,14,13,10, 4, 3, 5, 7, 8, 9,10,13,13,12, 7,
  118815. 4, 4, 5, 6, 8, 9,12,14,13, 9, 6, 5, 5, 6, 8, 9,
  118816. 12,14,12, 9, 7, 6, 5, 5, 6, 8,11,11,12,11, 9, 8,
  118817. 7, 6, 6, 7,10,11,13,11,10, 9, 8, 7, 6, 6, 9,11,
  118818. 13,13,12,12,12,10, 9, 8, 9,11,12,14,15,15,14,12,
  118819. 11,10,10,12,
  118820. };
  118821. static static_codebook _huff_book__44c7_s_long = {
  118822. 2, 100,
  118823. _huff_lengthlist__44c7_s_long,
  118824. 0, 0, 0, 0, 0,
  118825. NULL,
  118826. NULL,
  118827. NULL,
  118828. NULL,
  118829. 0
  118830. };
  118831. static long _vq_quantlist__44c7_s_p1_0[] = {
  118832. 1,
  118833. 0,
  118834. 2,
  118835. };
  118836. static long _vq_lengthlist__44c7_s_p1_0[] = {
  118837. 1, 5, 5, 0, 5, 5, 0, 5, 5, 5, 8, 7, 0, 9, 9, 0,
  118838. 9, 8, 5, 7, 8, 0, 9, 9, 0, 8, 9, 0, 0, 0, 0, 0,
  118839. 0, 0, 0, 0, 5, 9, 9, 0, 8, 8, 0, 8, 8, 5, 8, 9,
  118840. 0, 8, 8, 0, 8, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5,
  118841. 9, 9, 0, 8, 8, 0, 8, 8, 5, 8, 9, 0, 8, 8, 0, 8,
  118842. 8,
  118843. };
  118844. static float _vq_quantthresh__44c7_s_p1_0[] = {
  118845. -0.5, 0.5,
  118846. };
  118847. static long _vq_quantmap__44c7_s_p1_0[] = {
  118848. 1, 0, 2,
  118849. };
  118850. static encode_aux_threshmatch _vq_auxt__44c7_s_p1_0 = {
  118851. _vq_quantthresh__44c7_s_p1_0,
  118852. _vq_quantmap__44c7_s_p1_0,
  118853. 3,
  118854. 3
  118855. };
  118856. static static_codebook _44c7_s_p1_0 = {
  118857. 4, 81,
  118858. _vq_lengthlist__44c7_s_p1_0,
  118859. 1, -535822336, 1611661312, 2, 0,
  118860. _vq_quantlist__44c7_s_p1_0,
  118861. NULL,
  118862. &_vq_auxt__44c7_s_p1_0,
  118863. NULL,
  118864. 0
  118865. };
  118866. static long _vq_quantlist__44c7_s_p2_0[] = {
  118867. 2,
  118868. 1,
  118869. 3,
  118870. 0,
  118871. 4,
  118872. };
  118873. static long _vq_lengthlist__44c7_s_p2_0[] = {
  118874. 3, 5, 5, 8, 8, 0, 5, 5, 8, 8, 0, 5, 5, 8, 8, 0,
  118875. 7, 7, 9, 9, 0, 0, 0, 9, 9, 5, 7, 7, 9, 9, 0, 8,
  118876. 8,10,10, 0, 8, 7,10, 9, 0,10,10,11,11, 0, 0, 0,
  118877. 11,11, 5, 7, 7, 9, 9, 0, 8, 8,10,10, 0, 7, 8, 9,
  118878. 10, 0,10,10,11,11, 0, 0, 0,11,11, 8, 9, 9,11,10,
  118879. 0,11,11,12,12, 0,11,10,12,12, 0,13,14,14,14, 0,
  118880. 0, 0,14,13, 8, 9, 9,10,11, 0,11,11,12,12, 0,10,
  118881. 11,12,12, 0,13,13,14,14, 0, 0, 0,13,14, 0, 0, 0,
  118882. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118883. 0, 0, 0, 0, 0, 0, 5, 8, 7,11,10, 0, 7, 7,10,10,
  118884. 0, 7, 7,10,10, 0, 9, 9,11,10, 0, 0, 0,11,11, 5,
  118885. 7, 8,10,11, 0, 7, 7,10,10, 0, 7, 7,10,10, 0, 9,
  118886. 9,10,11, 0, 0, 0,11,11, 8,10, 9,12,12, 0,10,10,
  118887. 12,12, 0,10,10,12,12, 0,12,12,13,13, 0, 0, 0,13,
  118888. 13, 8, 9,10,12,12, 0,10,10,12,12, 0,10,10,11,12,
  118889. 0,12,12,13,13, 0, 0, 0,13,13, 0, 0, 0, 0, 0, 0,
  118890. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118891. 0, 0, 0, 5, 8, 8,11,11, 0, 7, 7,10,10, 0, 7, 7,
  118892. 10,10, 0, 9, 9,10,11, 0, 0, 0,11,10, 5, 8, 8,10,
  118893. 11, 0, 7, 7,10,10, 0, 7, 7,10,10, 0, 9, 9,11,10,
  118894. 0, 0, 0,10,11, 9,10,10,12,12, 0,10,10,12,12, 0,
  118895. 10,10,12,12, 0,12,13,13,13, 0, 0, 0,13,12, 9,10,
  118896. 10,12,12, 0,10,10,12,12, 0,10,10,12,12, 0,13,12,
  118897. 13,13, 0, 0, 0,12,13, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118898. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118899. 7,10,10,14,13, 0, 9, 9,12,12, 0, 9, 9,12,12, 0,
  118900. 10,10,12,12, 0, 0, 0,12,12, 7,10,10,13,14, 0, 9,
  118901. 9,12,13, 0, 9, 9,12,12, 0,10,10,12,12, 0, 0, 0,
  118902. 12,12, 9,11,11,14,13, 0,11,10,13,12, 0,11,11,13,
  118903. 13, 0,12,12,13,13, 0, 0, 0,13,13, 9,11,11,13,14,
  118904. 0,10,11,12,13, 0,11,11,13,13, 0,12,12,13,13, 0,
  118905. 0, 0,13,13, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118906. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118907. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118908. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118909. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9,
  118910. 11,11,14,14, 0,10,11,13,13, 0,11,10,13,13, 0,12,
  118911. 12,13,13, 0, 0, 0,13,12, 9,11,11,14,14, 0,11,10,
  118912. 13,13, 0,10,11,13,13, 0,12,12,14,13, 0, 0, 0,13,
  118913. 13,
  118914. };
  118915. static float _vq_quantthresh__44c7_s_p2_0[] = {
  118916. -1.5, -0.5, 0.5, 1.5,
  118917. };
  118918. static long _vq_quantmap__44c7_s_p2_0[] = {
  118919. 3, 1, 0, 2, 4,
  118920. };
  118921. static encode_aux_threshmatch _vq_auxt__44c7_s_p2_0 = {
  118922. _vq_quantthresh__44c7_s_p2_0,
  118923. _vq_quantmap__44c7_s_p2_0,
  118924. 5,
  118925. 5
  118926. };
  118927. static static_codebook _44c7_s_p2_0 = {
  118928. 4, 625,
  118929. _vq_lengthlist__44c7_s_p2_0,
  118930. 1, -533725184, 1611661312, 3, 0,
  118931. _vq_quantlist__44c7_s_p2_0,
  118932. NULL,
  118933. &_vq_auxt__44c7_s_p2_0,
  118934. NULL,
  118935. 0
  118936. };
  118937. static long _vq_quantlist__44c7_s_p3_0[] = {
  118938. 4,
  118939. 3,
  118940. 5,
  118941. 2,
  118942. 6,
  118943. 1,
  118944. 7,
  118945. 0,
  118946. 8,
  118947. };
  118948. static long _vq_lengthlist__44c7_s_p3_0[] = {
  118949. 2, 4, 4, 5, 5, 7, 7, 9, 9, 0, 4, 4, 6, 6, 7, 7,
  118950. 9, 9, 0, 4, 4, 6, 6, 7, 7, 9, 9, 0, 5, 5, 6, 6,
  118951. 8, 8,10,10, 0, 0, 0, 6, 6, 8, 8,10,10, 0, 0, 0,
  118952. 7, 7, 9, 9,10,10, 0, 0, 0, 7, 7, 8, 8,10,10, 0,
  118953. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118954. 0,
  118955. };
  118956. static float _vq_quantthresh__44c7_s_p3_0[] = {
  118957. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  118958. };
  118959. static long _vq_quantmap__44c7_s_p3_0[] = {
  118960. 7, 5, 3, 1, 0, 2, 4, 6,
  118961. 8,
  118962. };
  118963. static encode_aux_threshmatch _vq_auxt__44c7_s_p3_0 = {
  118964. _vq_quantthresh__44c7_s_p3_0,
  118965. _vq_quantmap__44c7_s_p3_0,
  118966. 9,
  118967. 9
  118968. };
  118969. static static_codebook _44c7_s_p3_0 = {
  118970. 2, 81,
  118971. _vq_lengthlist__44c7_s_p3_0,
  118972. 1, -531628032, 1611661312, 4, 0,
  118973. _vq_quantlist__44c7_s_p3_0,
  118974. NULL,
  118975. &_vq_auxt__44c7_s_p3_0,
  118976. NULL,
  118977. 0
  118978. };
  118979. static long _vq_quantlist__44c7_s_p4_0[] = {
  118980. 8,
  118981. 7,
  118982. 9,
  118983. 6,
  118984. 10,
  118985. 5,
  118986. 11,
  118987. 4,
  118988. 12,
  118989. 3,
  118990. 13,
  118991. 2,
  118992. 14,
  118993. 1,
  118994. 15,
  118995. 0,
  118996. 16,
  118997. };
  118998. static long _vq_lengthlist__44c7_s_p4_0[] = {
  118999. 3, 4, 4, 5, 5, 7, 7, 8, 8, 8, 8, 9, 9,10,10,11,
  119000. 11, 0, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9,10,10,11,11,
  119001. 12,12, 0, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9,10,10,11,
  119002. 11,12,12, 0, 5, 5, 6, 6, 8, 8, 9, 9, 9, 9,10,10,
  119003. 11,12,12,12, 0, 0, 0, 6, 6, 8, 7, 9, 9, 9, 9,10,
  119004. 10,11,11,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9,10,10,
  119005. 11,11,12,12,13,12, 0, 0, 0, 7, 7, 8, 8, 9, 9,10,
  119006. 10,11,11,12,12,12,13, 0, 0, 0, 7, 7, 8, 8, 9, 9,
  119007. 10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 8, 8, 9,
  119008. 9,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 0, 0,
  119009. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119010. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119011. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119012. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119013. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119014. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119015. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119016. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119017. 0,
  119018. };
  119019. static float _vq_quantthresh__44c7_s_p4_0[] = {
  119020. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  119021. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  119022. };
  119023. static long _vq_quantmap__44c7_s_p4_0[] = {
  119024. 15, 13, 11, 9, 7, 5, 3, 1,
  119025. 0, 2, 4, 6, 8, 10, 12, 14,
  119026. 16,
  119027. };
  119028. static encode_aux_threshmatch _vq_auxt__44c7_s_p4_0 = {
  119029. _vq_quantthresh__44c7_s_p4_0,
  119030. _vq_quantmap__44c7_s_p4_0,
  119031. 17,
  119032. 17
  119033. };
  119034. static static_codebook _44c7_s_p4_0 = {
  119035. 2, 289,
  119036. _vq_lengthlist__44c7_s_p4_0,
  119037. 1, -529530880, 1611661312, 5, 0,
  119038. _vq_quantlist__44c7_s_p4_0,
  119039. NULL,
  119040. &_vq_auxt__44c7_s_p4_0,
  119041. NULL,
  119042. 0
  119043. };
  119044. static long _vq_quantlist__44c7_s_p5_0[] = {
  119045. 1,
  119046. 0,
  119047. 2,
  119048. };
  119049. static long _vq_lengthlist__44c7_s_p5_0[] = {
  119050. 1, 4, 4, 5, 7, 7, 6, 7, 7, 4, 6, 7,10,10,10,10,
  119051. 10, 9, 4, 6, 6,10,10,10,10, 9,10, 5,10,10, 9,11,
  119052. 12,10,11,12, 7,10,10,11,12,12,12,12,12, 7,10,10,
  119053. 11,12,12,12,12,12, 6,10,10,10,12,12,11,12,12, 7,
  119054. 10,10,12,12,12,12,11,12, 7,10,10,11,12,12,12,12,
  119055. 12,
  119056. };
  119057. static float _vq_quantthresh__44c7_s_p5_0[] = {
  119058. -5.5, 5.5,
  119059. };
  119060. static long _vq_quantmap__44c7_s_p5_0[] = {
  119061. 1, 0, 2,
  119062. };
  119063. static encode_aux_threshmatch _vq_auxt__44c7_s_p5_0 = {
  119064. _vq_quantthresh__44c7_s_p5_0,
  119065. _vq_quantmap__44c7_s_p5_0,
  119066. 3,
  119067. 3
  119068. };
  119069. static static_codebook _44c7_s_p5_0 = {
  119070. 4, 81,
  119071. _vq_lengthlist__44c7_s_p5_0,
  119072. 1, -529137664, 1618345984, 2, 0,
  119073. _vq_quantlist__44c7_s_p5_0,
  119074. NULL,
  119075. &_vq_auxt__44c7_s_p5_0,
  119076. NULL,
  119077. 0
  119078. };
  119079. static long _vq_quantlist__44c7_s_p5_1[] = {
  119080. 5,
  119081. 4,
  119082. 6,
  119083. 3,
  119084. 7,
  119085. 2,
  119086. 8,
  119087. 1,
  119088. 9,
  119089. 0,
  119090. 10,
  119091. };
  119092. static long _vq_lengthlist__44c7_s_p5_1[] = {
  119093. 3, 5, 5, 6, 6, 7, 7, 8, 8, 8, 8,11, 4, 4, 6, 6,
  119094. 7, 7, 8, 8, 9, 9,11, 4, 4, 6, 6, 7, 7, 8, 8, 9,
  119095. 9,12, 5, 5, 6, 6, 7, 7, 9, 9, 9, 9,12,12,12, 6,
  119096. 6, 7, 7, 9, 9, 9, 9,11,11,11, 7, 7, 7, 7, 8, 8,
  119097. 9, 9,11,11,11, 7, 7, 7, 7, 8, 8, 9, 9,11,11,11,
  119098. 7, 7, 8, 8, 8, 8, 9, 9,11,11,11,11,11, 8, 8, 8,
  119099. 8, 8, 9,11,11,11,11,11, 8, 8, 8, 8, 8, 8,11,11,
  119100. 11,11,11, 7, 7, 8, 8, 8, 8,
  119101. };
  119102. static float _vq_quantthresh__44c7_s_p5_1[] = {
  119103. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  119104. 3.5, 4.5,
  119105. };
  119106. static long _vq_quantmap__44c7_s_p5_1[] = {
  119107. 9, 7, 5, 3, 1, 0, 2, 4,
  119108. 6, 8, 10,
  119109. };
  119110. static encode_aux_threshmatch _vq_auxt__44c7_s_p5_1 = {
  119111. _vq_quantthresh__44c7_s_p5_1,
  119112. _vq_quantmap__44c7_s_p5_1,
  119113. 11,
  119114. 11
  119115. };
  119116. static static_codebook _44c7_s_p5_1 = {
  119117. 2, 121,
  119118. _vq_lengthlist__44c7_s_p5_1,
  119119. 1, -531365888, 1611661312, 4, 0,
  119120. _vq_quantlist__44c7_s_p5_1,
  119121. NULL,
  119122. &_vq_auxt__44c7_s_p5_1,
  119123. NULL,
  119124. 0
  119125. };
  119126. static long _vq_quantlist__44c7_s_p6_0[] = {
  119127. 6,
  119128. 5,
  119129. 7,
  119130. 4,
  119131. 8,
  119132. 3,
  119133. 9,
  119134. 2,
  119135. 10,
  119136. 1,
  119137. 11,
  119138. 0,
  119139. 12,
  119140. };
  119141. static long _vq_lengthlist__44c7_s_p6_0[] = {
  119142. 1, 4, 4, 6, 6, 7, 7, 8, 7, 9, 8,10,10, 6, 5, 5,
  119143. 7, 7, 8, 8, 9, 9, 9,10,11,11, 7, 5, 5, 7, 7, 8,
  119144. 8, 9, 9,10,10,11,11, 0, 7, 7, 7, 7, 9, 8, 9, 9,
  119145. 10,10,11,11, 0, 8, 8, 7, 7, 8, 9, 9, 9,10,10,11,
  119146. 11, 0,11,11, 9, 9,10,10,11,10,11,11,12,12, 0,12,
  119147. 12, 9, 9,10,10,11,11,11,11,12,12, 0, 0, 0, 0, 0,
  119148. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119149. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119150. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119151. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119152. 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119153. };
  119154. static float _vq_quantthresh__44c7_s_p6_0[] = {
  119155. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  119156. 12.5, 17.5, 22.5, 27.5,
  119157. };
  119158. static long _vq_quantmap__44c7_s_p6_0[] = {
  119159. 11, 9, 7, 5, 3, 1, 0, 2,
  119160. 4, 6, 8, 10, 12,
  119161. };
  119162. static encode_aux_threshmatch _vq_auxt__44c7_s_p6_0 = {
  119163. _vq_quantthresh__44c7_s_p6_0,
  119164. _vq_quantmap__44c7_s_p6_0,
  119165. 13,
  119166. 13
  119167. };
  119168. static static_codebook _44c7_s_p6_0 = {
  119169. 2, 169,
  119170. _vq_lengthlist__44c7_s_p6_0,
  119171. 1, -526516224, 1616117760, 4, 0,
  119172. _vq_quantlist__44c7_s_p6_0,
  119173. NULL,
  119174. &_vq_auxt__44c7_s_p6_0,
  119175. NULL,
  119176. 0
  119177. };
  119178. static long _vq_quantlist__44c7_s_p6_1[] = {
  119179. 2,
  119180. 1,
  119181. 3,
  119182. 0,
  119183. 4,
  119184. };
  119185. static long _vq_lengthlist__44c7_s_p6_1[] = {
  119186. 3, 4, 4, 5, 5, 5, 4, 4, 5, 5, 5, 4, 4, 5, 5, 6,
  119187. 5, 5, 5, 5, 6, 6, 6, 5, 5,
  119188. };
  119189. static float _vq_quantthresh__44c7_s_p6_1[] = {
  119190. -1.5, -0.5, 0.5, 1.5,
  119191. };
  119192. static long _vq_quantmap__44c7_s_p6_1[] = {
  119193. 3, 1, 0, 2, 4,
  119194. };
  119195. static encode_aux_threshmatch _vq_auxt__44c7_s_p6_1 = {
  119196. _vq_quantthresh__44c7_s_p6_1,
  119197. _vq_quantmap__44c7_s_p6_1,
  119198. 5,
  119199. 5
  119200. };
  119201. static static_codebook _44c7_s_p6_1 = {
  119202. 2, 25,
  119203. _vq_lengthlist__44c7_s_p6_1,
  119204. 1, -533725184, 1611661312, 3, 0,
  119205. _vq_quantlist__44c7_s_p6_1,
  119206. NULL,
  119207. &_vq_auxt__44c7_s_p6_1,
  119208. NULL,
  119209. 0
  119210. };
  119211. static long _vq_quantlist__44c7_s_p7_0[] = {
  119212. 6,
  119213. 5,
  119214. 7,
  119215. 4,
  119216. 8,
  119217. 3,
  119218. 9,
  119219. 2,
  119220. 10,
  119221. 1,
  119222. 11,
  119223. 0,
  119224. 12,
  119225. };
  119226. static long _vq_lengthlist__44c7_s_p7_0[] = {
  119227. 1, 4, 4, 6, 6, 7, 8, 9, 9,10,10,12,11, 6, 5, 5,
  119228. 7, 7, 8, 8, 9,10,11,11,12,12, 7, 5, 5, 7, 7, 8,
  119229. 8,10,10,11,11,12,12,20, 7, 7, 7, 7, 8, 9,10,10,
  119230. 11,11,12,13,20, 7, 7, 7, 7, 9, 9,10,10,11,12,13,
  119231. 13,20,11,11, 8, 8, 9, 9,11,11,12,12,13,13,20,11,
  119232. 11, 8, 8, 9, 9,11,11,12,12,13,13,20,20,20,10,10,
  119233. 10,10,12,12,13,13,13,13,20,20,20,10,10,10,10,12,
  119234. 12,13,13,13,14,20,20,20,14,14,11,11,12,12,13,13,
  119235. 14,14,20,20,20,14,14,11,11,12,12,13,13,14,14,20,
  119236. 20,20,20,19,13,13,13,13,14,14,15,14,19,19,19,19,
  119237. 19,13,13,13,13,14,14,15,15,
  119238. };
  119239. static float _vq_quantthresh__44c7_s_p7_0[] = {
  119240. -60.5, -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5,
  119241. 27.5, 38.5, 49.5, 60.5,
  119242. };
  119243. static long _vq_quantmap__44c7_s_p7_0[] = {
  119244. 11, 9, 7, 5, 3, 1, 0, 2,
  119245. 4, 6, 8, 10, 12,
  119246. };
  119247. static encode_aux_threshmatch _vq_auxt__44c7_s_p7_0 = {
  119248. _vq_quantthresh__44c7_s_p7_0,
  119249. _vq_quantmap__44c7_s_p7_0,
  119250. 13,
  119251. 13
  119252. };
  119253. static static_codebook _44c7_s_p7_0 = {
  119254. 2, 169,
  119255. _vq_lengthlist__44c7_s_p7_0,
  119256. 1, -523206656, 1618345984, 4, 0,
  119257. _vq_quantlist__44c7_s_p7_0,
  119258. NULL,
  119259. &_vq_auxt__44c7_s_p7_0,
  119260. NULL,
  119261. 0
  119262. };
  119263. static long _vq_quantlist__44c7_s_p7_1[] = {
  119264. 5,
  119265. 4,
  119266. 6,
  119267. 3,
  119268. 7,
  119269. 2,
  119270. 8,
  119271. 1,
  119272. 9,
  119273. 0,
  119274. 10,
  119275. };
  119276. static long _vq_lengthlist__44c7_s_p7_1[] = {
  119277. 4, 5, 5, 6, 6, 7, 7, 7, 7, 7, 7, 8, 6, 6, 7, 7,
  119278. 7, 7, 7, 7, 7, 7, 8, 6, 6, 6, 7, 7, 7, 7, 7, 7,
  119279. 7, 8, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 7,
  119280. 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 7, 7, 7, 7, 7, 7,
  119281. 7, 7, 8, 8, 8, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8,
  119282. 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 7, 7, 7,
  119283. 7, 7, 7, 8, 8, 8, 8, 8, 7, 7, 7, 7, 7, 7, 8, 8,
  119284. 8, 8, 8, 7, 7, 7, 7, 7, 7,
  119285. };
  119286. static float _vq_quantthresh__44c7_s_p7_1[] = {
  119287. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  119288. 3.5, 4.5,
  119289. };
  119290. static long _vq_quantmap__44c7_s_p7_1[] = {
  119291. 9, 7, 5, 3, 1, 0, 2, 4,
  119292. 6, 8, 10,
  119293. };
  119294. static encode_aux_threshmatch _vq_auxt__44c7_s_p7_1 = {
  119295. _vq_quantthresh__44c7_s_p7_1,
  119296. _vq_quantmap__44c7_s_p7_1,
  119297. 11,
  119298. 11
  119299. };
  119300. static static_codebook _44c7_s_p7_1 = {
  119301. 2, 121,
  119302. _vq_lengthlist__44c7_s_p7_1,
  119303. 1, -531365888, 1611661312, 4, 0,
  119304. _vq_quantlist__44c7_s_p7_1,
  119305. NULL,
  119306. &_vq_auxt__44c7_s_p7_1,
  119307. NULL,
  119308. 0
  119309. };
  119310. static long _vq_quantlist__44c7_s_p8_0[] = {
  119311. 7,
  119312. 6,
  119313. 8,
  119314. 5,
  119315. 9,
  119316. 4,
  119317. 10,
  119318. 3,
  119319. 11,
  119320. 2,
  119321. 12,
  119322. 1,
  119323. 13,
  119324. 0,
  119325. 14,
  119326. };
  119327. static long _vq_lengthlist__44c7_s_p8_0[] = {
  119328. 1, 4, 4, 7, 7, 8, 8, 8, 7, 9, 8, 9, 9,10,10, 6,
  119329. 5, 5, 7, 7, 9, 9, 8, 8,10, 9,11,10,12,11, 6, 5,
  119330. 5, 8, 7, 9, 9, 8, 8,10,10,11,11,12,11,19, 8, 8,
  119331. 8, 8,10,10, 9, 9,10,10,11,11,12,11,19, 8, 8, 8,
  119332. 8,10,10, 9, 9,10,10,11,11,12,12,19,12,12, 9, 9,
  119333. 10,10, 9,10,10,10,11,11,12,12,19,12,12, 9, 9,10,
  119334. 10,10,10,10,10,12,12,12,12,19,19,19, 9, 9, 9, 9,
  119335. 11,10,11,11,12,11,13,13,19,19,19, 9, 9, 9, 9,11,
  119336. 10,11,11,11,12,13,13,19,19,19,13,13,10,10,11,11,
  119337. 12,12,12,12,13,12,19,19,19,14,13,10,10,11,11,12,
  119338. 12,12,13,13,13,19,19,19,19,19,12,12,12,11,12,13,
  119339. 14,13,13,13,19,19,19,19,19,12,12,12,11,12,12,13,
  119340. 14,13,14,19,19,19,19,19,16,16,12,13,12,13,13,14,
  119341. 15,14,19,18,18,18,18,16,15,12,11,12,11,14,12,14,
  119342. 14,
  119343. };
  119344. static float _vq_quantthresh__44c7_s_p8_0[] = {
  119345. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  119346. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  119347. };
  119348. static long _vq_quantmap__44c7_s_p8_0[] = {
  119349. 13, 11, 9, 7, 5, 3, 1, 0,
  119350. 2, 4, 6, 8, 10, 12, 14,
  119351. };
  119352. static encode_aux_threshmatch _vq_auxt__44c7_s_p8_0 = {
  119353. _vq_quantthresh__44c7_s_p8_0,
  119354. _vq_quantmap__44c7_s_p8_0,
  119355. 15,
  119356. 15
  119357. };
  119358. static static_codebook _44c7_s_p8_0 = {
  119359. 2, 225,
  119360. _vq_lengthlist__44c7_s_p8_0,
  119361. 1, -520986624, 1620377600, 4, 0,
  119362. _vq_quantlist__44c7_s_p8_0,
  119363. NULL,
  119364. &_vq_auxt__44c7_s_p8_0,
  119365. NULL,
  119366. 0
  119367. };
  119368. static long _vq_quantlist__44c7_s_p8_1[] = {
  119369. 10,
  119370. 9,
  119371. 11,
  119372. 8,
  119373. 12,
  119374. 7,
  119375. 13,
  119376. 6,
  119377. 14,
  119378. 5,
  119379. 15,
  119380. 4,
  119381. 16,
  119382. 3,
  119383. 17,
  119384. 2,
  119385. 18,
  119386. 1,
  119387. 19,
  119388. 0,
  119389. 20,
  119390. };
  119391. static long _vq_lengthlist__44c7_s_p8_1[] = {
  119392. 3, 5, 5, 7, 6, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  119393. 8, 8, 8, 8, 8,10, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,
  119394. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 6, 6, 7, 7, 8,
  119395. 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,
  119396. 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  119397. 9, 9, 9, 9,10,10,10, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  119398. 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10,10, 8, 8, 8, 9,
  119399. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10,
  119400. 10, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  119401. 9, 9, 9,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  119402. 9, 9, 9, 9, 9, 9, 9, 9,10,11,10,10,10, 9, 9, 9,
  119403. 9, 9, 9, 9, 9, 9, 9,10, 9, 9,10, 9, 9,10,11,10,
  119404. 11,10, 9, 9, 9, 9, 9, 9, 9,10,10,10, 9,10, 9, 9,
  119405. 9, 9,11,10,11,10,10, 9, 9, 9, 9, 9, 9,10, 9, 9,
  119406. 10, 9, 9,10, 9, 9,10,11,10,10,11,10, 9, 9, 9, 9,
  119407. 9,10,10, 9,10,10,10,10, 9,10,10,10,10,10,10,11,
  119408. 11,11,10, 9, 9, 9,10,10,10,10,10,10,10,10,10,10,
  119409. 10,10,10,11,11,10,10,10,10,10,10,10,10,10,10,10,
  119410. 10, 9,10,10, 9,10,11,11,10,11,10,11,10, 9,10,10,
  119411. 9,10,10,10,10,10,10,10,10,10,10,11,11,11,11,10,
  119412. 11,11,10,10,10,10,10,10, 9,10, 9,10,10, 9,10, 9,
  119413. 10,10,10,11,10,11,10,11,11,10,10,10,10,10,10, 9,
  119414. 10,10,10,10,10,10,10,11,10,10,10,10,10,10,10,10,
  119415. 10,10,10,10,10,10,10,10,10,10,10,10,10,11,10,11,
  119416. 11,10,10,10,10, 9, 9,10,10, 9, 9,10, 9,10,10,10,
  119417. 10,11,11,10,10,10,10,10,10,10, 9, 9,10,10,10, 9,
  119418. 9,10,10,10,10,10,11,10,11,10,10,10,10,10,10, 9,
  119419. 10,10,10,10,10,10,10,10,10,
  119420. };
  119421. static float _vq_quantthresh__44c7_s_p8_1[] = {
  119422. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  119423. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  119424. 6.5, 7.5, 8.5, 9.5,
  119425. };
  119426. static long _vq_quantmap__44c7_s_p8_1[] = {
  119427. 19, 17, 15, 13, 11, 9, 7, 5,
  119428. 3, 1, 0, 2, 4, 6, 8, 10,
  119429. 12, 14, 16, 18, 20,
  119430. };
  119431. static encode_aux_threshmatch _vq_auxt__44c7_s_p8_1 = {
  119432. _vq_quantthresh__44c7_s_p8_1,
  119433. _vq_quantmap__44c7_s_p8_1,
  119434. 21,
  119435. 21
  119436. };
  119437. static static_codebook _44c7_s_p8_1 = {
  119438. 2, 441,
  119439. _vq_lengthlist__44c7_s_p8_1,
  119440. 1, -529268736, 1611661312, 5, 0,
  119441. _vq_quantlist__44c7_s_p8_1,
  119442. NULL,
  119443. &_vq_auxt__44c7_s_p8_1,
  119444. NULL,
  119445. 0
  119446. };
  119447. static long _vq_quantlist__44c7_s_p9_0[] = {
  119448. 6,
  119449. 5,
  119450. 7,
  119451. 4,
  119452. 8,
  119453. 3,
  119454. 9,
  119455. 2,
  119456. 10,
  119457. 1,
  119458. 11,
  119459. 0,
  119460. 12,
  119461. };
  119462. static long _vq_lengthlist__44c7_s_p9_0[] = {
  119463. 1, 3, 3,11,11,11,11,11,11,11,11,11,11, 4, 6, 6,
  119464. 11,11,11,11,11,11,11,11,11,11, 4, 7, 7,11,11,11,
  119465. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  119466. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  119467. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  119468. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  119469. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  119470. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  119471. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  119472. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  119473. 11,11,11,11,11,11,11,11,11,
  119474. };
  119475. static float _vq_quantthresh__44c7_s_p9_0[] = {
  119476. -3503.5, -2866.5, -2229.5, -1592.5, -955.5, -318.5, 318.5, 955.5,
  119477. 1592.5, 2229.5, 2866.5, 3503.5,
  119478. };
  119479. static long _vq_quantmap__44c7_s_p9_0[] = {
  119480. 11, 9, 7, 5, 3, 1, 0, 2,
  119481. 4, 6, 8, 10, 12,
  119482. };
  119483. static encode_aux_threshmatch _vq_auxt__44c7_s_p9_0 = {
  119484. _vq_quantthresh__44c7_s_p9_0,
  119485. _vq_quantmap__44c7_s_p9_0,
  119486. 13,
  119487. 13
  119488. };
  119489. static static_codebook _44c7_s_p9_0 = {
  119490. 2, 169,
  119491. _vq_lengthlist__44c7_s_p9_0,
  119492. 1, -511845376, 1630791680, 4, 0,
  119493. _vq_quantlist__44c7_s_p9_0,
  119494. NULL,
  119495. &_vq_auxt__44c7_s_p9_0,
  119496. NULL,
  119497. 0
  119498. };
  119499. static long _vq_quantlist__44c7_s_p9_1[] = {
  119500. 6,
  119501. 5,
  119502. 7,
  119503. 4,
  119504. 8,
  119505. 3,
  119506. 9,
  119507. 2,
  119508. 10,
  119509. 1,
  119510. 11,
  119511. 0,
  119512. 12,
  119513. };
  119514. static long _vq_lengthlist__44c7_s_p9_1[] = {
  119515. 1, 4, 4, 7, 7, 7, 7, 7, 6, 8, 8, 8, 8, 6, 6, 6,
  119516. 8, 8, 9, 8, 8, 7, 9, 8,11,10, 5, 6, 6, 8, 8, 9,
  119517. 8, 8, 8,10, 9,11,11,16, 8, 8, 9, 8, 9, 9, 9, 8,
  119518. 10, 9,11,10,16, 8, 8, 9, 9,10,10, 9, 9,10,10,11,
  119519. 11,16,13,13, 9, 9,10,10, 9,10,11,11,12,11,16,13,
  119520. 13, 9, 8,10, 9,10,10,10,10,11,11,16,14,16, 8, 9,
  119521. 9, 9,11,10,11,11,12,11,16,16,16, 9, 7,10, 7,11,
  119522. 10,11,11,12,11,16,16,16,12,12, 9,10,11,11,12,11,
  119523. 12,12,16,16,16,12,10,10, 7,11, 8,12,11,12,12,16,
  119524. 16,15,16,16,11,12,10,10,12,11,12,12,16,16,16,15,
  119525. 15,11,11,10,10,12,12,12,12,
  119526. };
  119527. static float _vq_quantthresh__44c7_s_p9_1[] = {
  119528. -269.5, -220.5, -171.5, -122.5, -73.5, -24.5, 24.5, 73.5,
  119529. 122.5, 171.5, 220.5, 269.5,
  119530. };
  119531. static long _vq_quantmap__44c7_s_p9_1[] = {
  119532. 11, 9, 7, 5, 3, 1, 0, 2,
  119533. 4, 6, 8, 10, 12,
  119534. };
  119535. static encode_aux_threshmatch _vq_auxt__44c7_s_p9_1 = {
  119536. _vq_quantthresh__44c7_s_p9_1,
  119537. _vq_quantmap__44c7_s_p9_1,
  119538. 13,
  119539. 13
  119540. };
  119541. static static_codebook _44c7_s_p9_1 = {
  119542. 2, 169,
  119543. _vq_lengthlist__44c7_s_p9_1,
  119544. 1, -518889472, 1622704128, 4, 0,
  119545. _vq_quantlist__44c7_s_p9_1,
  119546. NULL,
  119547. &_vq_auxt__44c7_s_p9_1,
  119548. NULL,
  119549. 0
  119550. };
  119551. static long _vq_quantlist__44c7_s_p9_2[] = {
  119552. 24,
  119553. 23,
  119554. 25,
  119555. 22,
  119556. 26,
  119557. 21,
  119558. 27,
  119559. 20,
  119560. 28,
  119561. 19,
  119562. 29,
  119563. 18,
  119564. 30,
  119565. 17,
  119566. 31,
  119567. 16,
  119568. 32,
  119569. 15,
  119570. 33,
  119571. 14,
  119572. 34,
  119573. 13,
  119574. 35,
  119575. 12,
  119576. 36,
  119577. 11,
  119578. 37,
  119579. 10,
  119580. 38,
  119581. 9,
  119582. 39,
  119583. 8,
  119584. 40,
  119585. 7,
  119586. 41,
  119587. 6,
  119588. 42,
  119589. 5,
  119590. 43,
  119591. 4,
  119592. 44,
  119593. 3,
  119594. 45,
  119595. 2,
  119596. 46,
  119597. 1,
  119598. 47,
  119599. 0,
  119600. 48,
  119601. };
  119602. static long _vq_lengthlist__44c7_s_p9_2[] = {
  119603. 2, 4, 3, 4, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6, 6,
  119604. 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  119605. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  119606. 7,
  119607. };
  119608. static float _vq_quantthresh__44c7_s_p9_2[] = {
  119609. -23.5, -22.5, -21.5, -20.5, -19.5, -18.5, -17.5, -16.5,
  119610. -15.5, -14.5, -13.5, -12.5, -11.5, -10.5, -9.5, -8.5,
  119611. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  119612. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  119613. 8.5, 9.5, 10.5, 11.5, 12.5, 13.5, 14.5, 15.5,
  119614. 16.5, 17.5, 18.5, 19.5, 20.5, 21.5, 22.5, 23.5,
  119615. };
  119616. static long _vq_quantmap__44c7_s_p9_2[] = {
  119617. 47, 45, 43, 41, 39, 37, 35, 33,
  119618. 31, 29, 27, 25, 23, 21, 19, 17,
  119619. 15, 13, 11, 9, 7, 5, 3, 1,
  119620. 0, 2, 4, 6, 8, 10, 12, 14,
  119621. 16, 18, 20, 22, 24, 26, 28, 30,
  119622. 32, 34, 36, 38, 40, 42, 44, 46,
  119623. 48,
  119624. };
  119625. static encode_aux_threshmatch _vq_auxt__44c7_s_p9_2 = {
  119626. _vq_quantthresh__44c7_s_p9_2,
  119627. _vq_quantmap__44c7_s_p9_2,
  119628. 49,
  119629. 49
  119630. };
  119631. static static_codebook _44c7_s_p9_2 = {
  119632. 1, 49,
  119633. _vq_lengthlist__44c7_s_p9_2,
  119634. 1, -526909440, 1611661312, 6, 0,
  119635. _vq_quantlist__44c7_s_p9_2,
  119636. NULL,
  119637. &_vq_auxt__44c7_s_p9_2,
  119638. NULL,
  119639. 0
  119640. };
  119641. static long _huff_lengthlist__44c7_s_short[] = {
  119642. 4,11,12,14,15,15,17,17,18,18, 5, 6, 6, 8, 9,10,
  119643. 13,17,18,19, 7, 5, 4, 6, 8, 9,11,15,19,19, 8, 6,
  119644. 5, 5, 6, 7,11,14,16,17, 9, 7, 7, 6, 7, 7,10,13,
  119645. 15,19,10, 8, 7, 6, 7, 6, 7, 9,14,16,12,10, 9, 7,
  119646. 7, 6, 4, 5,10,15,14,13,11, 7, 6, 6, 4, 2, 7,13,
  119647. 16,16,15, 9, 8, 8, 8, 6, 9,13,19,19,17,12,11,10,
  119648. 10, 9,11,14,
  119649. };
  119650. static static_codebook _huff_book__44c7_s_short = {
  119651. 2, 100,
  119652. _huff_lengthlist__44c7_s_short,
  119653. 0, 0, 0, 0, 0,
  119654. NULL,
  119655. NULL,
  119656. NULL,
  119657. NULL,
  119658. 0
  119659. };
  119660. static long _huff_lengthlist__44c8_s_long[] = {
  119661. 3, 8,12,13,14,14,14,13,14,14, 6, 4, 5, 8,10,10,
  119662. 11,11,14,13, 9, 5, 4, 5, 7, 8, 9,10,13,13,12, 7,
  119663. 5, 4, 5, 6, 8, 9,12,13,13, 9, 6, 5, 5, 5, 7, 9,
  119664. 11,14,12,10, 7, 6, 5, 4, 6, 7,10,11,12,11, 9, 8,
  119665. 7, 5, 5, 6,10,10,13,12,10, 9, 8, 6, 6, 5, 8,10,
  119666. 14,13,12,12,11,10, 9, 7, 8,10,12,13,14,14,13,12,
  119667. 11, 9, 9,10,
  119668. };
  119669. static static_codebook _huff_book__44c8_s_long = {
  119670. 2, 100,
  119671. _huff_lengthlist__44c8_s_long,
  119672. 0, 0, 0, 0, 0,
  119673. NULL,
  119674. NULL,
  119675. NULL,
  119676. NULL,
  119677. 0
  119678. };
  119679. static long _vq_quantlist__44c8_s_p1_0[] = {
  119680. 1,
  119681. 0,
  119682. 2,
  119683. };
  119684. static long _vq_lengthlist__44c8_s_p1_0[] = {
  119685. 1, 5, 5, 0, 5, 5, 0, 5, 5, 5, 7, 7, 0, 9, 8, 0,
  119686. 9, 8, 6, 7, 7, 0, 8, 9, 0, 8, 9, 0, 0, 0, 0, 0,
  119687. 0, 0, 0, 0, 5, 9, 8, 0, 8, 8, 0, 8, 8, 5, 8, 9,
  119688. 0, 8, 8, 0, 8, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5,
  119689. 9, 8, 0, 8, 8, 0, 8, 8, 5, 8, 9, 0, 8, 8, 0, 8,
  119690. 8,
  119691. };
  119692. static float _vq_quantthresh__44c8_s_p1_0[] = {
  119693. -0.5, 0.5,
  119694. };
  119695. static long _vq_quantmap__44c8_s_p1_0[] = {
  119696. 1, 0, 2,
  119697. };
  119698. static encode_aux_threshmatch _vq_auxt__44c8_s_p1_0 = {
  119699. _vq_quantthresh__44c8_s_p1_0,
  119700. _vq_quantmap__44c8_s_p1_0,
  119701. 3,
  119702. 3
  119703. };
  119704. static static_codebook _44c8_s_p1_0 = {
  119705. 4, 81,
  119706. _vq_lengthlist__44c8_s_p1_0,
  119707. 1, -535822336, 1611661312, 2, 0,
  119708. _vq_quantlist__44c8_s_p1_0,
  119709. NULL,
  119710. &_vq_auxt__44c8_s_p1_0,
  119711. NULL,
  119712. 0
  119713. };
  119714. static long _vq_quantlist__44c8_s_p2_0[] = {
  119715. 2,
  119716. 1,
  119717. 3,
  119718. 0,
  119719. 4,
  119720. };
  119721. static long _vq_lengthlist__44c8_s_p2_0[] = {
  119722. 3, 5, 5, 8, 8, 0, 5, 5, 8, 8, 0, 5, 5, 8, 8, 0,
  119723. 7, 7, 9, 9, 0, 0, 0, 9, 9, 5, 7, 7, 9, 9, 0, 8,
  119724. 7,10, 9, 0, 8, 7,10, 9, 0,10,10,11,11, 0, 0, 0,
  119725. 11,11, 5, 7, 7, 9, 9, 0, 7, 8, 9,10, 0, 7, 8, 9,
  119726. 10, 0,10,10,11,11, 0, 0, 0,11,11, 8, 9, 9,11,10,
  119727. 0,11,10,12,11, 0,11,10,12,12, 0,13,13,14,14, 0,
  119728. 0, 0,14,13, 8, 9, 9,10,11, 0,10,11,12,12, 0,10,
  119729. 11,12,12, 0,13,13,14,14, 0, 0, 0,13,14, 0, 0, 0,
  119730. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119731. 0, 0, 0, 0, 0, 0, 5, 8, 7,11,10, 0, 7, 7,10,10,
  119732. 0, 7, 7,10,10, 0, 9, 9,10,10, 0, 0, 0,11,10, 5,
  119733. 7, 8,10,11, 0, 7, 7,10,10, 0, 7, 7,10,10, 0, 9,
  119734. 9,10,10, 0, 0, 0,10,10, 8,10, 9,12,12, 0,10,10,
  119735. 12,11, 0,10,10,12,12, 0,12,12,13,12, 0, 0, 0,13,
  119736. 12, 8, 9,10,12,12, 0,10,10,11,12, 0,10,10,11,12,
  119737. 0,12,12,13,13, 0, 0, 0,12,13, 0, 0, 0, 0, 0, 0,
  119738. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119739. 0, 0, 0, 6, 8, 7,11,10, 0, 7, 7,10,10, 0, 7, 7,
  119740. 10,10, 0, 9, 9,10,11, 0, 0, 0,10,10, 6, 7, 8,10,
  119741. 11, 0, 7, 7,10,10, 0, 7, 7,10,10, 0, 9, 9,10,10,
  119742. 0, 0, 0,10,10, 9,10, 9,12,12, 0,10,10,12,12, 0,
  119743. 10,10,12,11, 0,12,12,13,13, 0, 0, 0,13,12, 8, 9,
  119744. 10,12,12, 0,10,10,12,12, 0,10,10,11,12, 0,12,12,
  119745. 13,13, 0, 0, 0,12,13, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119746. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119747. 7,10,10,13,13, 0, 9, 9,12,12, 0, 9, 9,12,12, 0,
  119748. 10,10,12,12, 0, 0, 0,12,12, 7,10,10,13,13, 0, 9,
  119749. 9,12,12, 0, 9, 9,12,12, 0,10,10,12,12, 0, 0, 0,
  119750. 12,12, 9,11,11,14,13, 0,10,10,13,12, 0,11,10,13,
  119751. 12, 0,12,12,13,12, 0, 0, 0,13,13, 9,11,11,13,14,
  119752. 0,10,11,12,13, 0,10,11,13,13, 0,12,12,12,13, 0,
  119753. 0, 0,13,13, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119754. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119755. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119756. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119757. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9,
  119758. 11,11,14,14, 0,10,11,13,13, 0,11,10,13,13, 0,11,
  119759. 12,13,13, 0, 0, 0,13,12, 9,11,11,14,14, 0,11,10,
  119760. 13,13, 0,10,11,13,13, 0,12,12,13,13, 0, 0, 0,12,
  119761. 13,
  119762. };
  119763. static float _vq_quantthresh__44c8_s_p2_0[] = {
  119764. -1.5, -0.5, 0.5, 1.5,
  119765. };
  119766. static long _vq_quantmap__44c8_s_p2_0[] = {
  119767. 3, 1, 0, 2, 4,
  119768. };
  119769. static encode_aux_threshmatch _vq_auxt__44c8_s_p2_0 = {
  119770. _vq_quantthresh__44c8_s_p2_0,
  119771. _vq_quantmap__44c8_s_p2_0,
  119772. 5,
  119773. 5
  119774. };
  119775. static static_codebook _44c8_s_p2_0 = {
  119776. 4, 625,
  119777. _vq_lengthlist__44c8_s_p2_0,
  119778. 1, -533725184, 1611661312, 3, 0,
  119779. _vq_quantlist__44c8_s_p2_0,
  119780. NULL,
  119781. &_vq_auxt__44c8_s_p2_0,
  119782. NULL,
  119783. 0
  119784. };
  119785. static long _vq_quantlist__44c8_s_p3_0[] = {
  119786. 4,
  119787. 3,
  119788. 5,
  119789. 2,
  119790. 6,
  119791. 1,
  119792. 7,
  119793. 0,
  119794. 8,
  119795. };
  119796. static long _vq_lengthlist__44c8_s_p3_0[] = {
  119797. 2, 4, 4, 5, 5, 7, 7, 9, 9, 0, 4, 4, 6, 6, 7, 7,
  119798. 9, 9, 0, 4, 4, 6, 6, 7, 7, 9, 9, 0, 5, 5, 6, 6,
  119799. 8, 8,10,10, 0, 0, 0, 6, 6, 8, 8,10,10, 0, 0, 0,
  119800. 7, 7, 9, 9,10,10, 0, 0, 0, 7, 7, 8, 8,10,10, 0,
  119801. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119802. 0,
  119803. };
  119804. static float _vq_quantthresh__44c8_s_p3_0[] = {
  119805. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  119806. };
  119807. static long _vq_quantmap__44c8_s_p3_0[] = {
  119808. 7, 5, 3, 1, 0, 2, 4, 6,
  119809. 8,
  119810. };
  119811. static encode_aux_threshmatch _vq_auxt__44c8_s_p3_0 = {
  119812. _vq_quantthresh__44c8_s_p3_0,
  119813. _vq_quantmap__44c8_s_p3_0,
  119814. 9,
  119815. 9
  119816. };
  119817. static static_codebook _44c8_s_p3_0 = {
  119818. 2, 81,
  119819. _vq_lengthlist__44c8_s_p3_0,
  119820. 1, -531628032, 1611661312, 4, 0,
  119821. _vq_quantlist__44c8_s_p3_0,
  119822. NULL,
  119823. &_vq_auxt__44c8_s_p3_0,
  119824. NULL,
  119825. 0
  119826. };
  119827. static long _vq_quantlist__44c8_s_p4_0[] = {
  119828. 8,
  119829. 7,
  119830. 9,
  119831. 6,
  119832. 10,
  119833. 5,
  119834. 11,
  119835. 4,
  119836. 12,
  119837. 3,
  119838. 13,
  119839. 2,
  119840. 14,
  119841. 1,
  119842. 15,
  119843. 0,
  119844. 16,
  119845. };
  119846. static long _vq_lengthlist__44c8_s_p4_0[] = {
  119847. 3, 4, 4, 5, 5, 7, 7, 8, 8, 8, 8, 9, 9,10,10,11,
  119848. 11, 0, 4, 4, 6, 6, 7, 7, 8, 8, 9, 8,10,10,11,11,
  119849. 11,11, 0, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9,10,10,11,
  119850. 11,11,11, 0, 6, 5, 6, 6, 7, 7, 9, 9, 9, 9,10,10,
  119851. 11,11,12,12, 0, 0, 0, 6, 6, 7, 7, 9, 9, 9, 9,10,
  119852. 10,11,11,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9,10,10,
  119853. 11,11,11,12,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9,10,
  119854. 10,11,11,11,12,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9,
  119855. 10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 8, 8, 9,
  119856. 9,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 0, 0,
  119857. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119858. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119859. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119860. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119861. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119862. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119863. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119864. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119865. 0,
  119866. };
  119867. static float _vq_quantthresh__44c8_s_p4_0[] = {
  119868. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  119869. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  119870. };
  119871. static long _vq_quantmap__44c8_s_p4_0[] = {
  119872. 15, 13, 11, 9, 7, 5, 3, 1,
  119873. 0, 2, 4, 6, 8, 10, 12, 14,
  119874. 16,
  119875. };
  119876. static encode_aux_threshmatch _vq_auxt__44c8_s_p4_0 = {
  119877. _vq_quantthresh__44c8_s_p4_0,
  119878. _vq_quantmap__44c8_s_p4_0,
  119879. 17,
  119880. 17
  119881. };
  119882. static static_codebook _44c8_s_p4_0 = {
  119883. 2, 289,
  119884. _vq_lengthlist__44c8_s_p4_0,
  119885. 1, -529530880, 1611661312, 5, 0,
  119886. _vq_quantlist__44c8_s_p4_0,
  119887. NULL,
  119888. &_vq_auxt__44c8_s_p4_0,
  119889. NULL,
  119890. 0
  119891. };
  119892. static long _vq_quantlist__44c8_s_p5_0[] = {
  119893. 1,
  119894. 0,
  119895. 2,
  119896. };
  119897. static long _vq_lengthlist__44c8_s_p5_0[] = {
  119898. 1, 4, 4, 5, 7, 7, 6, 7, 7, 4, 7, 6,10,10,10,10,
  119899. 10,10, 4, 6, 6,10,10,10,10, 9,10, 5,10,10, 9,11,
  119900. 11,10,11,11, 7,10,10,11,12,12,12,12,12, 7,10,10,
  119901. 11,12,12,12,12,12, 6,10,10,10,12,12,10,12,12, 7,
  119902. 10,10,11,12,12,12,12,12, 7,10,10,11,12,12,12,12,
  119903. 12,
  119904. };
  119905. static float _vq_quantthresh__44c8_s_p5_0[] = {
  119906. -5.5, 5.5,
  119907. };
  119908. static long _vq_quantmap__44c8_s_p5_0[] = {
  119909. 1, 0, 2,
  119910. };
  119911. static encode_aux_threshmatch _vq_auxt__44c8_s_p5_0 = {
  119912. _vq_quantthresh__44c8_s_p5_0,
  119913. _vq_quantmap__44c8_s_p5_0,
  119914. 3,
  119915. 3
  119916. };
  119917. static static_codebook _44c8_s_p5_0 = {
  119918. 4, 81,
  119919. _vq_lengthlist__44c8_s_p5_0,
  119920. 1, -529137664, 1618345984, 2, 0,
  119921. _vq_quantlist__44c8_s_p5_0,
  119922. NULL,
  119923. &_vq_auxt__44c8_s_p5_0,
  119924. NULL,
  119925. 0
  119926. };
  119927. static long _vq_quantlist__44c8_s_p5_1[] = {
  119928. 5,
  119929. 4,
  119930. 6,
  119931. 3,
  119932. 7,
  119933. 2,
  119934. 8,
  119935. 1,
  119936. 9,
  119937. 0,
  119938. 10,
  119939. };
  119940. static long _vq_lengthlist__44c8_s_p5_1[] = {
  119941. 3, 5, 5, 6, 6, 7, 7, 8, 8, 8, 8,11, 4, 5, 6, 6,
  119942. 7, 7, 8, 8, 8, 8,11, 5, 5, 6, 6, 7, 7, 8, 8, 8,
  119943. 9,12, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9,12,12,12, 6,
  119944. 6, 7, 7, 8, 8, 9, 9,11,11,11, 6, 6, 7, 7, 8, 8,
  119945. 8, 8,11,11,11, 6, 6, 7, 7, 8, 8, 8, 8,11,11,11,
  119946. 7, 7, 7, 8, 8, 8, 8, 8,11,11,11,11,11, 7, 7, 8,
  119947. 8, 8, 8,11,11,11,11,11, 7, 7, 7, 7, 8, 8,11,11,
  119948. 11,11,11, 7, 7, 7, 7, 8, 8,
  119949. };
  119950. static float _vq_quantthresh__44c8_s_p5_1[] = {
  119951. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  119952. 3.5, 4.5,
  119953. };
  119954. static long _vq_quantmap__44c8_s_p5_1[] = {
  119955. 9, 7, 5, 3, 1, 0, 2, 4,
  119956. 6, 8, 10,
  119957. };
  119958. static encode_aux_threshmatch _vq_auxt__44c8_s_p5_1 = {
  119959. _vq_quantthresh__44c8_s_p5_1,
  119960. _vq_quantmap__44c8_s_p5_1,
  119961. 11,
  119962. 11
  119963. };
  119964. static static_codebook _44c8_s_p5_1 = {
  119965. 2, 121,
  119966. _vq_lengthlist__44c8_s_p5_1,
  119967. 1, -531365888, 1611661312, 4, 0,
  119968. _vq_quantlist__44c8_s_p5_1,
  119969. NULL,
  119970. &_vq_auxt__44c8_s_p5_1,
  119971. NULL,
  119972. 0
  119973. };
  119974. static long _vq_quantlist__44c8_s_p6_0[] = {
  119975. 6,
  119976. 5,
  119977. 7,
  119978. 4,
  119979. 8,
  119980. 3,
  119981. 9,
  119982. 2,
  119983. 10,
  119984. 1,
  119985. 11,
  119986. 0,
  119987. 12,
  119988. };
  119989. static long _vq_lengthlist__44c8_s_p6_0[] = {
  119990. 1, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9,10,10, 6, 5, 5,
  119991. 7, 7, 8, 8, 9, 9,10,10,11,11, 6, 5, 5, 7, 7, 8,
  119992. 8, 9, 9,10,10,11,11, 0, 7, 7, 7, 7, 9, 9,10,10,
  119993. 10,10,11,11, 0, 7, 7, 7, 7, 9, 9,10,10,10,10,11,
  119994. 11, 0,11,11, 9, 9,10,10,11,11,11,11,12,12, 0,12,
  119995. 12, 9, 9,10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0,
  119996. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119997. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119998. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119999. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120000. 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120001. };
  120002. static float _vq_quantthresh__44c8_s_p6_0[] = {
  120003. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  120004. 12.5, 17.5, 22.5, 27.5,
  120005. };
  120006. static long _vq_quantmap__44c8_s_p6_0[] = {
  120007. 11, 9, 7, 5, 3, 1, 0, 2,
  120008. 4, 6, 8, 10, 12,
  120009. };
  120010. static encode_aux_threshmatch _vq_auxt__44c8_s_p6_0 = {
  120011. _vq_quantthresh__44c8_s_p6_0,
  120012. _vq_quantmap__44c8_s_p6_0,
  120013. 13,
  120014. 13
  120015. };
  120016. static static_codebook _44c8_s_p6_0 = {
  120017. 2, 169,
  120018. _vq_lengthlist__44c8_s_p6_0,
  120019. 1, -526516224, 1616117760, 4, 0,
  120020. _vq_quantlist__44c8_s_p6_0,
  120021. NULL,
  120022. &_vq_auxt__44c8_s_p6_0,
  120023. NULL,
  120024. 0
  120025. };
  120026. static long _vq_quantlist__44c8_s_p6_1[] = {
  120027. 2,
  120028. 1,
  120029. 3,
  120030. 0,
  120031. 4,
  120032. };
  120033. static long _vq_lengthlist__44c8_s_p6_1[] = {
  120034. 3, 4, 4, 5, 5, 5, 4, 4, 5, 5, 5, 4, 4, 5, 5, 6,
  120035. 5, 5, 5, 5, 6, 6, 6, 5, 5,
  120036. };
  120037. static float _vq_quantthresh__44c8_s_p6_1[] = {
  120038. -1.5, -0.5, 0.5, 1.5,
  120039. };
  120040. static long _vq_quantmap__44c8_s_p6_1[] = {
  120041. 3, 1, 0, 2, 4,
  120042. };
  120043. static encode_aux_threshmatch _vq_auxt__44c8_s_p6_1 = {
  120044. _vq_quantthresh__44c8_s_p6_1,
  120045. _vq_quantmap__44c8_s_p6_1,
  120046. 5,
  120047. 5
  120048. };
  120049. static static_codebook _44c8_s_p6_1 = {
  120050. 2, 25,
  120051. _vq_lengthlist__44c8_s_p6_1,
  120052. 1, -533725184, 1611661312, 3, 0,
  120053. _vq_quantlist__44c8_s_p6_1,
  120054. NULL,
  120055. &_vq_auxt__44c8_s_p6_1,
  120056. NULL,
  120057. 0
  120058. };
  120059. static long _vq_quantlist__44c8_s_p7_0[] = {
  120060. 6,
  120061. 5,
  120062. 7,
  120063. 4,
  120064. 8,
  120065. 3,
  120066. 9,
  120067. 2,
  120068. 10,
  120069. 1,
  120070. 11,
  120071. 0,
  120072. 12,
  120073. };
  120074. static long _vq_lengthlist__44c8_s_p7_0[] = {
  120075. 1, 4, 4, 6, 6, 8, 7, 9, 9,10,10,12,12, 6, 5, 5,
  120076. 7, 7, 8, 8,10,10,11,11,12,12, 7, 5, 5, 7, 7, 8,
  120077. 8,10,10,11,11,12,12,21, 7, 7, 7, 7, 8, 9,10,10,
  120078. 11,11,12,12,21, 7, 7, 7, 7, 9, 9,10,10,12,12,13,
  120079. 13,21,11,11, 8, 8, 9, 9,11,11,12,12,13,13,21,11,
  120080. 11, 8, 8, 9, 9,11,11,12,12,13,13,21,21,21,10,10,
  120081. 10,10,11,11,12,13,13,13,21,21,21,10,10,10,10,11,
  120082. 11,13,13,14,13,21,21,21,13,13,11,11,12,12,13,13,
  120083. 14,14,21,21,21,14,14,11,11,12,12,13,13,14,14,21,
  120084. 21,21,21,20,13,13,13,12,14,14,16,15,20,20,20,20,
  120085. 20,13,13,13,13,14,13,15,15,
  120086. };
  120087. static float _vq_quantthresh__44c8_s_p7_0[] = {
  120088. -60.5, -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5,
  120089. 27.5, 38.5, 49.5, 60.5,
  120090. };
  120091. static long _vq_quantmap__44c8_s_p7_0[] = {
  120092. 11, 9, 7, 5, 3, 1, 0, 2,
  120093. 4, 6, 8, 10, 12,
  120094. };
  120095. static encode_aux_threshmatch _vq_auxt__44c8_s_p7_0 = {
  120096. _vq_quantthresh__44c8_s_p7_0,
  120097. _vq_quantmap__44c8_s_p7_0,
  120098. 13,
  120099. 13
  120100. };
  120101. static static_codebook _44c8_s_p7_0 = {
  120102. 2, 169,
  120103. _vq_lengthlist__44c8_s_p7_0,
  120104. 1, -523206656, 1618345984, 4, 0,
  120105. _vq_quantlist__44c8_s_p7_0,
  120106. NULL,
  120107. &_vq_auxt__44c8_s_p7_0,
  120108. NULL,
  120109. 0
  120110. };
  120111. static long _vq_quantlist__44c8_s_p7_1[] = {
  120112. 5,
  120113. 4,
  120114. 6,
  120115. 3,
  120116. 7,
  120117. 2,
  120118. 8,
  120119. 1,
  120120. 9,
  120121. 0,
  120122. 10,
  120123. };
  120124. static long _vq_lengthlist__44c8_s_p7_1[] = {
  120125. 4, 5, 6, 6, 6, 7, 7, 7, 7, 7, 7, 8, 6, 6, 6, 7,
  120126. 7, 7, 7, 7, 7, 7, 8, 6, 6, 6, 6, 7, 7, 7, 7, 7,
  120127. 7, 8, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 7,
  120128. 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 7, 7, 7, 7, 7, 7,
  120129. 7, 7, 8, 8, 8, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8,
  120130. 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 7, 7, 7,
  120131. 7, 7, 7, 8, 8, 8, 8, 8, 7, 7, 7, 7, 7, 7, 8, 8,
  120132. 8, 8, 8, 7, 7, 7, 7, 7, 7,
  120133. };
  120134. static float _vq_quantthresh__44c8_s_p7_1[] = {
  120135. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  120136. 3.5, 4.5,
  120137. };
  120138. static long _vq_quantmap__44c8_s_p7_1[] = {
  120139. 9, 7, 5, 3, 1, 0, 2, 4,
  120140. 6, 8, 10,
  120141. };
  120142. static encode_aux_threshmatch _vq_auxt__44c8_s_p7_1 = {
  120143. _vq_quantthresh__44c8_s_p7_1,
  120144. _vq_quantmap__44c8_s_p7_1,
  120145. 11,
  120146. 11
  120147. };
  120148. static static_codebook _44c8_s_p7_1 = {
  120149. 2, 121,
  120150. _vq_lengthlist__44c8_s_p7_1,
  120151. 1, -531365888, 1611661312, 4, 0,
  120152. _vq_quantlist__44c8_s_p7_1,
  120153. NULL,
  120154. &_vq_auxt__44c8_s_p7_1,
  120155. NULL,
  120156. 0
  120157. };
  120158. static long _vq_quantlist__44c8_s_p8_0[] = {
  120159. 7,
  120160. 6,
  120161. 8,
  120162. 5,
  120163. 9,
  120164. 4,
  120165. 10,
  120166. 3,
  120167. 11,
  120168. 2,
  120169. 12,
  120170. 1,
  120171. 13,
  120172. 0,
  120173. 14,
  120174. };
  120175. static long _vq_lengthlist__44c8_s_p8_0[] = {
  120176. 1, 4, 4, 7, 6, 8, 8, 8, 7, 9, 8,10,10,11,10, 6,
  120177. 5, 5, 7, 7, 9, 9, 8, 8,10,10,11,11,12,11, 6, 5,
  120178. 5, 7, 7, 9, 9, 9, 9,10,10,11,11,12,12,20, 8, 8,
  120179. 8, 8, 9, 9, 9, 9,10,10,11,11,12,12,20, 8, 8, 8,
  120180. 8,10, 9, 9, 9,10,10,11,11,12,12,20,12,12, 9, 9,
  120181. 10,10,10,10,10,11,12,12,12,12,20,12,12, 9, 9,10,
  120182. 10,10,10,11,11,12,12,13,13,20,20,20, 9, 9, 9, 9,
  120183. 11,10,11,11,12,12,12,13,20,19,19, 9, 9, 9, 9,11,
  120184. 11,11,12,12,12,13,13,19,19,19,13,13,10,10,11,11,
  120185. 12,12,13,13,13,13,19,19,19,14,13,11,10,11,11,12,
  120186. 12,12,13,13,13,19,19,19,19,19,12,12,12,12,13,13,
  120187. 13,13,14,13,19,19,19,19,19,12,12,12,11,12,12,13,
  120188. 14,14,14,19,19,19,19,19,16,15,13,12,13,13,13,14,
  120189. 14,14,19,19,19,19,19,17,17,13,12,13,11,14,13,15,
  120190. 15,
  120191. };
  120192. static float _vq_quantthresh__44c8_s_p8_0[] = {
  120193. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  120194. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  120195. };
  120196. static long _vq_quantmap__44c8_s_p8_0[] = {
  120197. 13, 11, 9, 7, 5, 3, 1, 0,
  120198. 2, 4, 6, 8, 10, 12, 14,
  120199. };
  120200. static encode_aux_threshmatch _vq_auxt__44c8_s_p8_0 = {
  120201. _vq_quantthresh__44c8_s_p8_0,
  120202. _vq_quantmap__44c8_s_p8_0,
  120203. 15,
  120204. 15
  120205. };
  120206. static static_codebook _44c8_s_p8_0 = {
  120207. 2, 225,
  120208. _vq_lengthlist__44c8_s_p8_0,
  120209. 1, -520986624, 1620377600, 4, 0,
  120210. _vq_quantlist__44c8_s_p8_0,
  120211. NULL,
  120212. &_vq_auxt__44c8_s_p8_0,
  120213. NULL,
  120214. 0
  120215. };
  120216. static long _vq_quantlist__44c8_s_p8_1[] = {
  120217. 10,
  120218. 9,
  120219. 11,
  120220. 8,
  120221. 12,
  120222. 7,
  120223. 13,
  120224. 6,
  120225. 14,
  120226. 5,
  120227. 15,
  120228. 4,
  120229. 16,
  120230. 3,
  120231. 17,
  120232. 2,
  120233. 18,
  120234. 1,
  120235. 19,
  120236. 0,
  120237. 20,
  120238. };
  120239. static long _vq_lengthlist__44c8_s_p8_1[] = {
  120240. 4, 5, 5, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  120241. 8, 8, 8, 8, 8,10, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,
  120242. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 6, 6, 7, 7, 8,
  120243. 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,
  120244. 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  120245. 9, 9, 9, 9,10,10,10, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  120246. 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10,10, 8, 8, 8, 9,
  120247. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10,
  120248. 10, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  120249. 9, 9, 9,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  120250. 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,10,10, 9, 9, 9,
  120251. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,
  120252. 10,10, 9, 9, 9, 9, 9, 9, 9, 9,10, 9, 9, 9, 9, 9,
  120253. 9, 9,10,10,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  120254. 9, 9, 9, 9, 9, 9, 9,10,10,10,10,10, 9, 9, 9, 9,
  120255. 9, 9, 9, 9,10,10,10, 9, 9, 9, 9, 9,10,10,10,10,
  120256. 10,10,10, 9, 9, 9, 9, 9,10,10,10, 9, 9, 9, 9, 9,
  120257. 9,10,10,10,10,10,10,10, 9,10,10, 9,10,10,10,10,
  120258. 9,10, 9,10,10, 9,10,10,10,10,10,10,10, 9,10,10,
  120259. 10,10,10,10, 9, 9,10,10, 9,10,10,10,10,10,10,10,
  120260. 10,10,10,10,10,10,10,10, 9, 9, 9,10, 9, 9, 9, 9,
  120261. 10,10,10,10,10,10,10,10,10,10,10,10,10,10, 9, 9,
  120262. 10, 9,10, 9,10,10,10,10,10,10,10,10,10,10,10,10,
  120263. 10,10,10,10, 9, 9,10, 9, 9, 9,10,10,10,10,10,10,
  120264. 10,10,10,10,10, 9, 9, 9, 9, 9, 9,10, 9, 9,10,10,
  120265. 10,10,10,10,10,10,10,10,10,10,10,10,10, 9,10, 9,
  120266. 9,10, 9, 9,10,10,10,10,10,10,10,10,10,10,10,10,
  120267. 10, 9, 9,10,10, 9,10, 9, 9,
  120268. };
  120269. static float _vq_quantthresh__44c8_s_p8_1[] = {
  120270. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  120271. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  120272. 6.5, 7.5, 8.5, 9.5,
  120273. };
  120274. static long _vq_quantmap__44c8_s_p8_1[] = {
  120275. 19, 17, 15, 13, 11, 9, 7, 5,
  120276. 3, 1, 0, 2, 4, 6, 8, 10,
  120277. 12, 14, 16, 18, 20,
  120278. };
  120279. static encode_aux_threshmatch _vq_auxt__44c8_s_p8_1 = {
  120280. _vq_quantthresh__44c8_s_p8_1,
  120281. _vq_quantmap__44c8_s_p8_1,
  120282. 21,
  120283. 21
  120284. };
  120285. static static_codebook _44c8_s_p8_1 = {
  120286. 2, 441,
  120287. _vq_lengthlist__44c8_s_p8_1,
  120288. 1, -529268736, 1611661312, 5, 0,
  120289. _vq_quantlist__44c8_s_p8_1,
  120290. NULL,
  120291. &_vq_auxt__44c8_s_p8_1,
  120292. NULL,
  120293. 0
  120294. };
  120295. static long _vq_quantlist__44c8_s_p9_0[] = {
  120296. 8,
  120297. 7,
  120298. 9,
  120299. 6,
  120300. 10,
  120301. 5,
  120302. 11,
  120303. 4,
  120304. 12,
  120305. 3,
  120306. 13,
  120307. 2,
  120308. 14,
  120309. 1,
  120310. 15,
  120311. 0,
  120312. 16,
  120313. };
  120314. static long _vq_lengthlist__44c8_s_p9_0[] = {
  120315. 1, 4, 3,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120316. 11, 4, 7, 7,11,11,11,11,11,11,11,11,11,11,11,11,
  120317. 11,11, 4, 8,11,11,11,11,11,11,11,11,11,11,11,11,
  120318. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120319. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120320. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120321. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120322. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120323. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120324. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120325. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120326. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120327. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120328. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120329. 11,11,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  120330. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  120331. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  120332. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  120333. 10,
  120334. };
  120335. static float _vq_quantthresh__44c8_s_p9_0[] = {
  120336. -6982.5, -6051.5, -5120.5, -4189.5, -3258.5, -2327.5, -1396.5, -465.5,
  120337. 465.5, 1396.5, 2327.5, 3258.5, 4189.5, 5120.5, 6051.5, 6982.5,
  120338. };
  120339. static long _vq_quantmap__44c8_s_p9_0[] = {
  120340. 15, 13, 11, 9, 7, 5, 3, 1,
  120341. 0, 2, 4, 6, 8, 10, 12, 14,
  120342. 16,
  120343. };
  120344. static encode_aux_threshmatch _vq_auxt__44c8_s_p9_0 = {
  120345. _vq_quantthresh__44c8_s_p9_0,
  120346. _vq_quantmap__44c8_s_p9_0,
  120347. 17,
  120348. 17
  120349. };
  120350. static static_codebook _44c8_s_p9_0 = {
  120351. 2, 289,
  120352. _vq_lengthlist__44c8_s_p9_0,
  120353. 1, -509798400, 1631393792, 5, 0,
  120354. _vq_quantlist__44c8_s_p9_0,
  120355. NULL,
  120356. &_vq_auxt__44c8_s_p9_0,
  120357. NULL,
  120358. 0
  120359. };
  120360. static long _vq_quantlist__44c8_s_p9_1[] = {
  120361. 9,
  120362. 8,
  120363. 10,
  120364. 7,
  120365. 11,
  120366. 6,
  120367. 12,
  120368. 5,
  120369. 13,
  120370. 4,
  120371. 14,
  120372. 3,
  120373. 15,
  120374. 2,
  120375. 16,
  120376. 1,
  120377. 17,
  120378. 0,
  120379. 18,
  120380. };
  120381. static long _vq_lengthlist__44c8_s_p9_1[] = {
  120382. 1, 4, 4, 7, 6, 7, 7, 7, 7, 8, 8, 9, 9,10,10,10,
  120383. 10,11,11, 6, 6, 6, 8, 8, 9, 8, 8, 7,10, 8,11,10,
  120384. 12,11,12,12,13,13, 5, 5, 6, 8, 8, 9, 9, 8, 8,10,
  120385. 9,11,11,12,12,13,13,13,13,17, 8, 8, 9, 9, 9, 9,
  120386. 9, 9,10, 9,12,10,12,12,13,12,13,13,17, 9, 8, 9,
  120387. 9, 9, 9, 9, 9,10,10,12,12,12,12,13,13,13,13,17,
  120388. 13,13, 9, 9,10,10,10,10,11,11,12,11,13,12,13,13,
  120389. 14,15,17,13,13, 9, 8,10, 9,10,10,11,11,12,12,14,
  120390. 13,15,13,14,15,17,17,17, 9,10, 9,10,11,11,12,12,
  120391. 12,12,13,13,14,14,15,15,17,17,17, 9, 8, 9, 8,11,
  120392. 11,12,12,12,12,14,13,14,14,14,15,17,17,17,12,14,
  120393. 9,10,11,11,12,12,14,13,13,14,15,13,15,15,17,17,
  120394. 17,13,11,10, 8,11, 9,13,12,13,13,13,13,13,14,14,
  120395. 14,17,17,17,17,17,11,12,11,11,13,13,14,13,15,14,
  120396. 13,15,16,15,17,17,17,17,17,11,11,12, 8,13,12,14,
  120397. 13,17,14,15,14,15,14,17,17,17,17,17,15,15,12,12,
  120398. 12,12,13,14,14,14,15,14,17,14,17,17,17,17,17,16,
  120399. 17,12,12,13,12,13,13,14,14,14,14,14,14,17,17,17,
  120400. 17,17,17,17,14,14,13,12,13,13,15,15,14,13,15,17,
  120401. 17,17,17,17,17,17,17,13,14,13,13,13,13,14,15,15,
  120402. 15,14,15,17,17,17,17,17,17,17,16,15,13,14,13,13,
  120403. 14,14,15,14,14,16,17,17,17,17,17,17,17,16,16,13,
  120404. 14,13,13,14,14,15,14,15,14,
  120405. };
  120406. static float _vq_quantthresh__44c8_s_p9_1[] = {
  120407. -416.5, -367.5, -318.5, -269.5, -220.5, -171.5, -122.5, -73.5,
  120408. -24.5, 24.5, 73.5, 122.5, 171.5, 220.5, 269.5, 318.5,
  120409. 367.5, 416.5,
  120410. };
  120411. static long _vq_quantmap__44c8_s_p9_1[] = {
  120412. 17, 15, 13, 11, 9, 7, 5, 3,
  120413. 1, 0, 2, 4, 6, 8, 10, 12,
  120414. 14, 16, 18,
  120415. };
  120416. static encode_aux_threshmatch _vq_auxt__44c8_s_p9_1 = {
  120417. _vq_quantthresh__44c8_s_p9_1,
  120418. _vq_quantmap__44c8_s_p9_1,
  120419. 19,
  120420. 19
  120421. };
  120422. static static_codebook _44c8_s_p9_1 = {
  120423. 2, 361,
  120424. _vq_lengthlist__44c8_s_p9_1,
  120425. 1, -518287360, 1622704128, 5, 0,
  120426. _vq_quantlist__44c8_s_p9_1,
  120427. NULL,
  120428. &_vq_auxt__44c8_s_p9_1,
  120429. NULL,
  120430. 0
  120431. };
  120432. static long _vq_quantlist__44c8_s_p9_2[] = {
  120433. 24,
  120434. 23,
  120435. 25,
  120436. 22,
  120437. 26,
  120438. 21,
  120439. 27,
  120440. 20,
  120441. 28,
  120442. 19,
  120443. 29,
  120444. 18,
  120445. 30,
  120446. 17,
  120447. 31,
  120448. 16,
  120449. 32,
  120450. 15,
  120451. 33,
  120452. 14,
  120453. 34,
  120454. 13,
  120455. 35,
  120456. 12,
  120457. 36,
  120458. 11,
  120459. 37,
  120460. 10,
  120461. 38,
  120462. 9,
  120463. 39,
  120464. 8,
  120465. 40,
  120466. 7,
  120467. 41,
  120468. 6,
  120469. 42,
  120470. 5,
  120471. 43,
  120472. 4,
  120473. 44,
  120474. 3,
  120475. 45,
  120476. 2,
  120477. 46,
  120478. 1,
  120479. 47,
  120480. 0,
  120481. 48,
  120482. };
  120483. static long _vq_lengthlist__44c8_s_p9_2[] = {
  120484. 2, 4, 4, 4, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6,
  120485. 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  120486. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  120487. 7,
  120488. };
  120489. static float _vq_quantthresh__44c8_s_p9_2[] = {
  120490. -23.5, -22.5, -21.5, -20.5, -19.5, -18.5, -17.5, -16.5,
  120491. -15.5, -14.5, -13.5, -12.5, -11.5, -10.5, -9.5, -8.5,
  120492. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  120493. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  120494. 8.5, 9.5, 10.5, 11.5, 12.5, 13.5, 14.5, 15.5,
  120495. 16.5, 17.5, 18.5, 19.5, 20.5, 21.5, 22.5, 23.5,
  120496. };
  120497. static long _vq_quantmap__44c8_s_p9_2[] = {
  120498. 47, 45, 43, 41, 39, 37, 35, 33,
  120499. 31, 29, 27, 25, 23, 21, 19, 17,
  120500. 15, 13, 11, 9, 7, 5, 3, 1,
  120501. 0, 2, 4, 6, 8, 10, 12, 14,
  120502. 16, 18, 20, 22, 24, 26, 28, 30,
  120503. 32, 34, 36, 38, 40, 42, 44, 46,
  120504. 48,
  120505. };
  120506. static encode_aux_threshmatch _vq_auxt__44c8_s_p9_2 = {
  120507. _vq_quantthresh__44c8_s_p9_2,
  120508. _vq_quantmap__44c8_s_p9_2,
  120509. 49,
  120510. 49
  120511. };
  120512. static static_codebook _44c8_s_p9_2 = {
  120513. 1, 49,
  120514. _vq_lengthlist__44c8_s_p9_2,
  120515. 1, -526909440, 1611661312, 6, 0,
  120516. _vq_quantlist__44c8_s_p9_2,
  120517. NULL,
  120518. &_vq_auxt__44c8_s_p9_2,
  120519. NULL,
  120520. 0
  120521. };
  120522. static long _huff_lengthlist__44c8_s_short[] = {
  120523. 4,11,13,14,15,15,18,17,19,17, 5, 6, 8, 9,10,10,
  120524. 12,15,19,19, 6, 6, 6, 6, 8, 8,11,14,18,19, 8, 6,
  120525. 5, 4, 6, 7,10,13,16,17, 9, 7, 6, 5, 6, 7, 9,12,
  120526. 15,19,10, 8, 7, 6, 6, 6, 7, 9,13,15,12,10, 9, 8,
  120527. 7, 6, 4, 5,10,15,13,13,11, 8, 6, 6, 4, 2, 7,12,
  120528. 17,15,16,10, 8, 8, 7, 6, 9,12,19,18,17,13,11,10,
  120529. 10, 9,11,14,
  120530. };
  120531. static static_codebook _huff_book__44c8_s_short = {
  120532. 2, 100,
  120533. _huff_lengthlist__44c8_s_short,
  120534. 0, 0, 0, 0, 0,
  120535. NULL,
  120536. NULL,
  120537. NULL,
  120538. NULL,
  120539. 0
  120540. };
  120541. static long _huff_lengthlist__44c9_s_long[] = {
  120542. 3, 8,12,14,15,15,15,13,15,15, 6, 5, 8,10,12,12,
  120543. 13,12,14,13,10, 6, 5, 6, 8, 9,11,11,13,13,13, 8,
  120544. 5, 4, 5, 6, 8,10,11,13,14,10, 7, 5, 4, 5, 7, 9,
  120545. 11,12,13,11, 8, 6, 5, 4, 5, 7, 9,11,12,11,10, 8,
  120546. 7, 5, 4, 5, 9,10,13,13,11,10, 8, 6, 5, 4, 7, 9,
  120547. 15,14,13,12,10, 9, 8, 7, 8, 9,12,12,14,13,12,11,
  120548. 10, 9, 8, 9,
  120549. };
  120550. static static_codebook _huff_book__44c9_s_long = {
  120551. 2, 100,
  120552. _huff_lengthlist__44c9_s_long,
  120553. 0, 0, 0, 0, 0,
  120554. NULL,
  120555. NULL,
  120556. NULL,
  120557. NULL,
  120558. 0
  120559. };
  120560. static long _vq_quantlist__44c9_s_p1_0[] = {
  120561. 1,
  120562. 0,
  120563. 2,
  120564. };
  120565. static long _vq_lengthlist__44c9_s_p1_0[] = {
  120566. 1, 5, 5, 0, 5, 5, 0, 5, 5, 6, 8, 8, 0, 9, 8, 0,
  120567. 9, 8, 6, 8, 8, 0, 8, 9, 0, 8, 9, 0, 0, 0, 0, 0,
  120568. 0, 0, 0, 0, 5, 8, 8, 0, 7, 7, 0, 8, 8, 5, 8, 8,
  120569. 0, 7, 8, 0, 8, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5,
  120570. 9, 8, 0, 8, 8, 0, 7, 7, 5, 8, 9, 0, 8, 8, 0, 7,
  120571. 7,
  120572. };
  120573. static float _vq_quantthresh__44c9_s_p1_0[] = {
  120574. -0.5, 0.5,
  120575. };
  120576. static long _vq_quantmap__44c9_s_p1_0[] = {
  120577. 1, 0, 2,
  120578. };
  120579. static encode_aux_threshmatch _vq_auxt__44c9_s_p1_0 = {
  120580. _vq_quantthresh__44c9_s_p1_0,
  120581. _vq_quantmap__44c9_s_p1_0,
  120582. 3,
  120583. 3
  120584. };
  120585. static static_codebook _44c9_s_p1_0 = {
  120586. 4, 81,
  120587. _vq_lengthlist__44c9_s_p1_0,
  120588. 1, -535822336, 1611661312, 2, 0,
  120589. _vq_quantlist__44c9_s_p1_0,
  120590. NULL,
  120591. &_vq_auxt__44c9_s_p1_0,
  120592. NULL,
  120593. 0
  120594. };
  120595. static long _vq_quantlist__44c9_s_p2_0[] = {
  120596. 2,
  120597. 1,
  120598. 3,
  120599. 0,
  120600. 4,
  120601. };
  120602. static long _vq_lengthlist__44c9_s_p2_0[] = {
  120603. 3, 5, 5, 8, 8, 0, 5, 5, 8, 8, 0, 5, 5, 8, 8, 0,
  120604. 7, 7, 9, 9, 0, 0, 0, 9, 9, 6, 7, 7, 9, 8, 0, 8,
  120605. 8, 9, 9, 0, 8, 7, 9, 9, 0, 9,10,10,10, 0, 0, 0,
  120606. 11,10, 6, 7, 7, 8, 9, 0, 8, 8, 9, 9, 0, 7, 8, 9,
  120607. 9, 0,10, 9,11,10, 0, 0, 0,10,10, 8, 9, 8,10,10,
  120608. 0,10,10,12,11, 0,10,10,11,11, 0,12,13,13,13, 0,
  120609. 0, 0,13,12, 8, 8, 9,10,10, 0,10,10,11,12, 0,10,
  120610. 10,11,11, 0,13,12,13,13, 0, 0, 0,13,13, 0, 0, 0,
  120611. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120612. 0, 0, 0, 0, 0, 0, 6, 8, 7,10,10, 0, 7, 7,10, 9,
  120613. 0, 7, 7,10,10, 0, 9, 9,10,10, 0, 0, 0,10,10, 6,
  120614. 7, 8,10,10, 0, 7, 7, 9,10, 0, 7, 7,10,10, 0, 9,
  120615. 9,10,10, 0, 0, 0,10,10, 8, 9, 9,11,11, 0,10,10,
  120616. 11,11, 0,10,10,11,11, 0,12,12,12,12, 0, 0, 0,12,
  120617. 12, 8, 9,10,11,11, 0, 9,10,11,11, 0,10,10,11,11,
  120618. 0,12,12,12,12, 0, 0, 0,12,12, 0, 0, 0, 0, 0, 0,
  120619. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120620. 0, 0, 0, 5, 8, 7,10,10, 0, 7, 7,10,10, 0, 7, 7,
  120621. 10, 9, 0, 9, 9,10,10, 0, 0, 0,10,10, 6, 7, 8,10,
  120622. 10, 0, 7, 7,10,10, 0, 7, 7, 9,10, 0, 9, 9,10,10,
  120623. 0, 0, 0,10,10, 8,10, 9,12,11, 0,10,10,12,11, 0,
  120624. 10, 9,11,11, 0,11,12,12,12, 0, 0, 0,12,12, 8, 9,
  120625. 10,11,12, 0,10,10,11,11, 0, 9,10,11,11, 0,12,11,
  120626. 12,12, 0, 0, 0,12,12, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120627. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120628. 7,10, 9,12,12, 0, 9, 9,12,11, 0, 9, 9,11,11, 0,
  120629. 10,10,12,11, 0, 0, 0,11,12, 7, 9,10,12,12, 0, 9,
  120630. 9,11,12, 0, 9, 9,11,11, 0,10,10,11,12, 0, 0, 0,
  120631. 11,11, 9,11,10,13,12, 0,10,10,12,12, 0,10,10,12,
  120632. 12, 0,11,11,12,12, 0, 0, 0,13,12, 9,10,11,12,13,
  120633. 0,10,10,12,12, 0,10,10,12,12, 0,11,12,12,12, 0,
  120634. 0, 0,12,13, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120635. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120636. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120637. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120638. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9,
  120639. 11,10,13,13, 0,10,10,12,12, 0,10,10,12,12, 0,11,
  120640. 12,12,12, 0, 0, 0,12,12, 9,10,11,13,13, 0,10,10,
  120641. 12,12, 0,10,10,12,12, 0,12,11,13,12, 0, 0, 0,12,
  120642. 12,
  120643. };
  120644. static float _vq_quantthresh__44c9_s_p2_0[] = {
  120645. -1.5, -0.5, 0.5, 1.5,
  120646. };
  120647. static long _vq_quantmap__44c9_s_p2_0[] = {
  120648. 3, 1, 0, 2, 4,
  120649. };
  120650. static encode_aux_threshmatch _vq_auxt__44c9_s_p2_0 = {
  120651. _vq_quantthresh__44c9_s_p2_0,
  120652. _vq_quantmap__44c9_s_p2_0,
  120653. 5,
  120654. 5
  120655. };
  120656. static static_codebook _44c9_s_p2_0 = {
  120657. 4, 625,
  120658. _vq_lengthlist__44c9_s_p2_0,
  120659. 1, -533725184, 1611661312, 3, 0,
  120660. _vq_quantlist__44c9_s_p2_0,
  120661. NULL,
  120662. &_vq_auxt__44c9_s_p2_0,
  120663. NULL,
  120664. 0
  120665. };
  120666. static long _vq_quantlist__44c9_s_p3_0[] = {
  120667. 4,
  120668. 3,
  120669. 5,
  120670. 2,
  120671. 6,
  120672. 1,
  120673. 7,
  120674. 0,
  120675. 8,
  120676. };
  120677. static long _vq_lengthlist__44c9_s_p3_0[] = {
  120678. 3, 4, 4, 5, 5, 6, 6, 8, 8, 0, 4, 4, 5, 5, 6, 7,
  120679. 8, 8, 0, 4, 4, 5, 5, 7, 7, 8, 8, 0, 5, 5, 6, 6,
  120680. 7, 7, 9, 9, 0, 0, 0, 6, 6, 7, 7, 9, 9, 0, 0, 0,
  120681. 7, 7, 8, 8, 9, 9, 0, 0, 0, 7, 7, 8, 8, 9, 9, 0,
  120682. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120683. 0,
  120684. };
  120685. static float _vq_quantthresh__44c9_s_p3_0[] = {
  120686. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  120687. };
  120688. static long _vq_quantmap__44c9_s_p3_0[] = {
  120689. 7, 5, 3, 1, 0, 2, 4, 6,
  120690. 8,
  120691. };
  120692. static encode_aux_threshmatch _vq_auxt__44c9_s_p3_0 = {
  120693. _vq_quantthresh__44c9_s_p3_0,
  120694. _vq_quantmap__44c9_s_p3_0,
  120695. 9,
  120696. 9
  120697. };
  120698. static static_codebook _44c9_s_p3_0 = {
  120699. 2, 81,
  120700. _vq_lengthlist__44c9_s_p3_0,
  120701. 1, -531628032, 1611661312, 4, 0,
  120702. _vq_quantlist__44c9_s_p3_0,
  120703. NULL,
  120704. &_vq_auxt__44c9_s_p3_0,
  120705. NULL,
  120706. 0
  120707. };
  120708. static long _vq_quantlist__44c9_s_p4_0[] = {
  120709. 8,
  120710. 7,
  120711. 9,
  120712. 6,
  120713. 10,
  120714. 5,
  120715. 11,
  120716. 4,
  120717. 12,
  120718. 3,
  120719. 13,
  120720. 2,
  120721. 14,
  120722. 1,
  120723. 15,
  120724. 0,
  120725. 16,
  120726. };
  120727. static long _vq_lengthlist__44c9_s_p4_0[] = {
  120728. 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9,10,10,10,
  120729. 10, 0, 5, 4, 5, 5, 7, 7, 8, 8, 8, 8, 9, 9,10,10,
  120730. 11,11, 0, 5, 5, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,
  120731. 10,11,11, 0, 6, 5, 6, 6, 7, 7, 8, 8, 9, 9,10,10,
  120732. 11,11,11,12, 0, 0, 0, 6, 6, 7, 7, 8, 8, 9, 9,10,
  120733. 10,11,11,12,12, 0, 0, 0, 7, 7, 7, 7, 9, 9, 9, 9,
  120734. 10,10,11,11,12,12, 0, 0, 0, 7, 7, 7, 8, 9, 9, 9,
  120735. 9,10,10,11,11,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9,
  120736. 10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 8, 8, 9,
  120737. 9,10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 0, 0,
  120738. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120739. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120740. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120741. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120742. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120743. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120744. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120745. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120746. 0,
  120747. };
  120748. static float _vq_quantthresh__44c9_s_p4_0[] = {
  120749. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  120750. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  120751. };
  120752. static long _vq_quantmap__44c9_s_p4_0[] = {
  120753. 15, 13, 11, 9, 7, 5, 3, 1,
  120754. 0, 2, 4, 6, 8, 10, 12, 14,
  120755. 16,
  120756. };
  120757. static encode_aux_threshmatch _vq_auxt__44c9_s_p4_0 = {
  120758. _vq_quantthresh__44c9_s_p4_0,
  120759. _vq_quantmap__44c9_s_p4_0,
  120760. 17,
  120761. 17
  120762. };
  120763. static static_codebook _44c9_s_p4_0 = {
  120764. 2, 289,
  120765. _vq_lengthlist__44c9_s_p4_0,
  120766. 1, -529530880, 1611661312, 5, 0,
  120767. _vq_quantlist__44c9_s_p4_0,
  120768. NULL,
  120769. &_vq_auxt__44c9_s_p4_0,
  120770. NULL,
  120771. 0
  120772. };
  120773. static long _vq_quantlist__44c9_s_p5_0[] = {
  120774. 1,
  120775. 0,
  120776. 2,
  120777. };
  120778. static long _vq_lengthlist__44c9_s_p5_0[] = {
  120779. 1, 4, 4, 5, 7, 7, 6, 7, 7, 4, 7, 6, 9,10,10,10,
  120780. 10, 9, 4, 6, 7, 9,10,10,10, 9,10, 5, 9, 9, 9,11,
  120781. 11,10,11,11, 7,10, 9,11,12,11,12,12,12, 7, 9,10,
  120782. 11,11,12,12,12,12, 6,10,10,10,12,12,10,12,11, 7,
  120783. 10,10,11,12,12,11,12,12, 7,10,10,11,12,12,12,12,
  120784. 12,
  120785. };
  120786. static float _vq_quantthresh__44c9_s_p5_0[] = {
  120787. -5.5, 5.5,
  120788. };
  120789. static long _vq_quantmap__44c9_s_p5_0[] = {
  120790. 1, 0, 2,
  120791. };
  120792. static encode_aux_threshmatch _vq_auxt__44c9_s_p5_0 = {
  120793. _vq_quantthresh__44c9_s_p5_0,
  120794. _vq_quantmap__44c9_s_p5_0,
  120795. 3,
  120796. 3
  120797. };
  120798. static static_codebook _44c9_s_p5_0 = {
  120799. 4, 81,
  120800. _vq_lengthlist__44c9_s_p5_0,
  120801. 1, -529137664, 1618345984, 2, 0,
  120802. _vq_quantlist__44c9_s_p5_0,
  120803. NULL,
  120804. &_vq_auxt__44c9_s_p5_0,
  120805. NULL,
  120806. 0
  120807. };
  120808. static long _vq_quantlist__44c9_s_p5_1[] = {
  120809. 5,
  120810. 4,
  120811. 6,
  120812. 3,
  120813. 7,
  120814. 2,
  120815. 8,
  120816. 1,
  120817. 9,
  120818. 0,
  120819. 10,
  120820. };
  120821. static long _vq_lengthlist__44c9_s_p5_1[] = {
  120822. 4, 5, 5, 6, 6, 7, 7, 7, 7, 7, 7,11, 5, 5, 6, 6,
  120823. 7, 7, 7, 7, 8, 8,11, 5, 5, 6, 6, 7, 7, 7, 7, 8,
  120824. 8,11, 5, 5, 6, 6, 7, 7, 8, 8, 8, 8,11,11,11, 6,
  120825. 6, 7, 7, 7, 8, 8, 8,11,11,11, 6, 6, 7, 7, 7, 8,
  120826. 8, 8,11,11,11, 6, 6, 7, 7, 7, 7, 8, 8,11,11,11,
  120827. 7, 7, 7, 7, 7, 7, 8, 8,11,11,11,10,10, 7, 7, 7,
  120828. 7, 8, 8,11,11,11,11,11, 7, 7, 7, 7, 7, 7,11,11,
  120829. 11,11,11, 7, 7, 7, 7, 7, 7,
  120830. };
  120831. static float _vq_quantthresh__44c9_s_p5_1[] = {
  120832. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  120833. 3.5, 4.5,
  120834. };
  120835. static long _vq_quantmap__44c9_s_p5_1[] = {
  120836. 9, 7, 5, 3, 1, 0, 2, 4,
  120837. 6, 8, 10,
  120838. };
  120839. static encode_aux_threshmatch _vq_auxt__44c9_s_p5_1 = {
  120840. _vq_quantthresh__44c9_s_p5_1,
  120841. _vq_quantmap__44c9_s_p5_1,
  120842. 11,
  120843. 11
  120844. };
  120845. static static_codebook _44c9_s_p5_1 = {
  120846. 2, 121,
  120847. _vq_lengthlist__44c9_s_p5_1,
  120848. 1, -531365888, 1611661312, 4, 0,
  120849. _vq_quantlist__44c9_s_p5_1,
  120850. NULL,
  120851. &_vq_auxt__44c9_s_p5_1,
  120852. NULL,
  120853. 0
  120854. };
  120855. static long _vq_quantlist__44c9_s_p6_0[] = {
  120856. 6,
  120857. 5,
  120858. 7,
  120859. 4,
  120860. 8,
  120861. 3,
  120862. 9,
  120863. 2,
  120864. 10,
  120865. 1,
  120866. 11,
  120867. 0,
  120868. 12,
  120869. };
  120870. static long _vq_lengthlist__44c9_s_p6_0[] = {
  120871. 2, 4, 4, 6, 6, 7, 7, 7, 7, 8, 8, 9, 9, 5, 4, 4,
  120872. 6, 6, 8, 8, 9, 9, 9, 9,10,10, 6, 4, 4, 6, 6, 8,
  120873. 8, 9, 9, 9, 9,10,10, 0, 6, 6, 7, 7, 8, 8, 9, 9,
  120874. 10,10,11,11, 0, 6, 6, 7, 7, 8, 8, 9, 9,10,10,11,
  120875. 11, 0,10,10, 8, 8, 9, 9,10,10,11,11,12,12, 0,11,
  120876. 11, 8, 8, 9, 9,10,10,11,11,12,12, 0, 0, 0, 0, 0,
  120877. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120878. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120879. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120880. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120881. 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120882. };
  120883. static float _vq_quantthresh__44c9_s_p6_0[] = {
  120884. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  120885. 12.5, 17.5, 22.5, 27.5,
  120886. };
  120887. static long _vq_quantmap__44c9_s_p6_0[] = {
  120888. 11, 9, 7, 5, 3, 1, 0, 2,
  120889. 4, 6, 8, 10, 12,
  120890. };
  120891. static encode_aux_threshmatch _vq_auxt__44c9_s_p6_0 = {
  120892. _vq_quantthresh__44c9_s_p6_0,
  120893. _vq_quantmap__44c9_s_p6_0,
  120894. 13,
  120895. 13
  120896. };
  120897. static static_codebook _44c9_s_p6_0 = {
  120898. 2, 169,
  120899. _vq_lengthlist__44c9_s_p6_0,
  120900. 1, -526516224, 1616117760, 4, 0,
  120901. _vq_quantlist__44c9_s_p6_0,
  120902. NULL,
  120903. &_vq_auxt__44c9_s_p6_0,
  120904. NULL,
  120905. 0
  120906. };
  120907. static long _vq_quantlist__44c9_s_p6_1[] = {
  120908. 2,
  120909. 1,
  120910. 3,
  120911. 0,
  120912. 4,
  120913. };
  120914. static long _vq_lengthlist__44c9_s_p6_1[] = {
  120915. 4, 4, 4, 5, 5, 5, 4, 4, 5, 5, 5, 4, 4, 5, 5, 5,
  120916. 5, 5, 5, 5, 5, 5, 5, 5, 5,
  120917. };
  120918. static float _vq_quantthresh__44c9_s_p6_1[] = {
  120919. -1.5, -0.5, 0.5, 1.5,
  120920. };
  120921. static long _vq_quantmap__44c9_s_p6_1[] = {
  120922. 3, 1, 0, 2, 4,
  120923. };
  120924. static encode_aux_threshmatch _vq_auxt__44c9_s_p6_1 = {
  120925. _vq_quantthresh__44c9_s_p6_1,
  120926. _vq_quantmap__44c9_s_p6_1,
  120927. 5,
  120928. 5
  120929. };
  120930. static static_codebook _44c9_s_p6_1 = {
  120931. 2, 25,
  120932. _vq_lengthlist__44c9_s_p6_1,
  120933. 1, -533725184, 1611661312, 3, 0,
  120934. _vq_quantlist__44c9_s_p6_1,
  120935. NULL,
  120936. &_vq_auxt__44c9_s_p6_1,
  120937. NULL,
  120938. 0
  120939. };
  120940. static long _vq_quantlist__44c9_s_p7_0[] = {
  120941. 6,
  120942. 5,
  120943. 7,
  120944. 4,
  120945. 8,
  120946. 3,
  120947. 9,
  120948. 2,
  120949. 10,
  120950. 1,
  120951. 11,
  120952. 0,
  120953. 12,
  120954. };
  120955. static long _vq_lengthlist__44c9_s_p7_0[] = {
  120956. 2, 4, 4, 6, 6, 7, 7, 8, 8,10,10,11,11, 6, 4, 4,
  120957. 6, 6, 8, 8, 9, 9,10,10,12,12, 6, 4, 5, 6, 6, 8,
  120958. 8, 9, 9,10,10,12,12,20, 6, 6, 6, 6, 8, 8, 9,10,
  120959. 11,11,12,12,20, 6, 6, 6, 6, 8, 8,10,10,11,11,12,
  120960. 12,20,10,10, 7, 7, 9, 9,10,10,11,11,12,12,20,11,
  120961. 11, 7, 7, 9, 9,10,10,11,11,12,12,20,20,20, 9, 9,
  120962. 9, 9,11,11,12,12,13,13,20,20,20, 9, 9, 9, 9,11,
  120963. 11,12,12,13,13,20,20,20,13,13,10,10,11,11,12,13,
  120964. 13,13,20,20,20,13,13,10,10,11,11,12,13,13,13,20,
  120965. 20,20,20,19,12,12,12,12,13,13,14,15,19,19,19,19,
  120966. 19,12,12,12,12,13,13,14,14,
  120967. };
  120968. static float _vq_quantthresh__44c9_s_p7_0[] = {
  120969. -60.5, -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5,
  120970. 27.5, 38.5, 49.5, 60.5,
  120971. };
  120972. static long _vq_quantmap__44c9_s_p7_0[] = {
  120973. 11, 9, 7, 5, 3, 1, 0, 2,
  120974. 4, 6, 8, 10, 12,
  120975. };
  120976. static encode_aux_threshmatch _vq_auxt__44c9_s_p7_0 = {
  120977. _vq_quantthresh__44c9_s_p7_0,
  120978. _vq_quantmap__44c9_s_p7_0,
  120979. 13,
  120980. 13
  120981. };
  120982. static static_codebook _44c9_s_p7_0 = {
  120983. 2, 169,
  120984. _vq_lengthlist__44c9_s_p7_0,
  120985. 1, -523206656, 1618345984, 4, 0,
  120986. _vq_quantlist__44c9_s_p7_0,
  120987. NULL,
  120988. &_vq_auxt__44c9_s_p7_0,
  120989. NULL,
  120990. 0
  120991. };
  120992. static long _vq_quantlist__44c9_s_p7_1[] = {
  120993. 5,
  120994. 4,
  120995. 6,
  120996. 3,
  120997. 7,
  120998. 2,
  120999. 8,
  121000. 1,
  121001. 9,
  121002. 0,
  121003. 10,
  121004. };
  121005. static long _vq_lengthlist__44c9_s_p7_1[] = {
  121006. 5, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 6, 6, 6, 6,
  121007. 7, 7, 7, 7, 7, 7, 7, 6, 6, 6, 6, 7, 7, 7, 7, 7,
  121008. 7, 8, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 8, 8, 8, 6,
  121009. 6, 7, 7, 7, 7, 7, 7, 8, 8, 8, 7, 7, 7, 7, 7, 7,
  121010. 7, 7, 8, 8, 8, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8,
  121011. 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 7, 7, 7,
  121012. 7, 7, 7, 8, 8, 8, 8, 8, 7, 7, 7, 7, 7, 7, 8, 8,
  121013. 8, 8, 8, 7, 7, 7, 7, 7, 7,
  121014. };
  121015. static float _vq_quantthresh__44c9_s_p7_1[] = {
  121016. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  121017. 3.5, 4.5,
  121018. };
  121019. static long _vq_quantmap__44c9_s_p7_1[] = {
  121020. 9, 7, 5, 3, 1, 0, 2, 4,
  121021. 6, 8, 10,
  121022. };
  121023. static encode_aux_threshmatch _vq_auxt__44c9_s_p7_1 = {
  121024. _vq_quantthresh__44c9_s_p7_1,
  121025. _vq_quantmap__44c9_s_p7_1,
  121026. 11,
  121027. 11
  121028. };
  121029. static static_codebook _44c9_s_p7_1 = {
  121030. 2, 121,
  121031. _vq_lengthlist__44c9_s_p7_1,
  121032. 1, -531365888, 1611661312, 4, 0,
  121033. _vq_quantlist__44c9_s_p7_1,
  121034. NULL,
  121035. &_vq_auxt__44c9_s_p7_1,
  121036. NULL,
  121037. 0
  121038. };
  121039. static long _vq_quantlist__44c9_s_p8_0[] = {
  121040. 7,
  121041. 6,
  121042. 8,
  121043. 5,
  121044. 9,
  121045. 4,
  121046. 10,
  121047. 3,
  121048. 11,
  121049. 2,
  121050. 12,
  121051. 1,
  121052. 13,
  121053. 0,
  121054. 14,
  121055. };
  121056. static long _vq_lengthlist__44c9_s_p8_0[] = {
  121057. 1, 4, 4, 7, 6, 8, 8, 8, 8, 9, 9,10,10,11,10, 6,
  121058. 5, 5, 7, 7, 9, 9, 8, 9,10,10,11,11,12,12, 6, 5,
  121059. 5, 7, 7, 9, 9, 9, 9,10,10,11,11,12,12,21, 7, 8,
  121060. 8, 8, 9, 9, 9, 9,10,10,11,11,12,12,21, 8, 8, 8,
  121061. 8, 9, 9, 9, 9,10,10,11,11,12,12,21,11,12, 9, 9,
  121062. 10,10,10,10,10,11,11,12,12,12,21,12,12, 9, 8,10,
  121063. 10,10,10,11,11,12,12,13,13,21,21,21, 9, 9, 9, 9,
  121064. 11,11,11,11,12,12,12,13,21,20,20, 9, 9, 9, 9,10,
  121065. 11,11,11,12,12,13,13,20,20,20,13,13,10,10,11,11,
  121066. 12,12,13,13,13,13,20,20,20,13,13,10,10,11,11,12,
  121067. 12,13,13,13,13,20,20,20,20,20,12,12,12,12,12,12,
  121068. 13,13,14,14,20,20,20,20,20,12,12,12,11,13,12,13,
  121069. 13,14,14,20,20,20,20,20,15,16,13,12,13,13,14,13,
  121070. 14,14,20,20,20,20,20,16,15,12,12,13,12,14,13,14,
  121071. 14,
  121072. };
  121073. static float _vq_quantthresh__44c9_s_p8_0[] = {
  121074. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  121075. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  121076. };
  121077. static long _vq_quantmap__44c9_s_p8_0[] = {
  121078. 13, 11, 9, 7, 5, 3, 1, 0,
  121079. 2, 4, 6, 8, 10, 12, 14,
  121080. };
  121081. static encode_aux_threshmatch _vq_auxt__44c9_s_p8_0 = {
  121082. _vq_quantthresh__44c9_s_p8_0,
  121083. _vq_quantmap__44c9_s_p8_0,
  121084. 15,
  121085. 15
  121086. };
  121087. static static_codebook _44c9_s_p8_0 = {
  121088. 2, 225,
  121089. _vq_lengthlist__44c9_s_p8_0,
  121090. 1, -520986624, 1620377600, 4, 0,
  121091. _vq_quantlist__44c9_s_p8_0,
  121092. NULL,
  121093. &_vq_auxt__44c9_s_p8_0,
  121094. NULL,
  121095. 0
  121096. };
  121097. static long _vq_quantlist__44c9_s_p8_1[] = {
  121098. 10,
  121099. 9,
  121100. 11,
  121101. 8,
  121102. 12,
  121103. 7,
  121104. 13,
  121105. 6,
  121106. 14,
  121107. 5,
  121108. 15,
  121109. 4,
  121110. 16,
  121111. 3,
  121112. 17,
  121113. 2,
  121114. 18,
  121115. 1,
  121116. 19,
  121117. 0,
  121118. 20,
  121119. };
  121120. static long _vq_lengthlist__44c9_s_p8_1[] = {
  121121. 4, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  121122. 8, 8, 8, 8, 8,10, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,
  121123. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 6, 6, 7, 7, 8,
  121124. 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,
  121125. 7, 7, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  121126. 9, 9, 9, 9,10,10,10, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  121127. 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10,10, 8, 8, 8, 8,
  121128. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10,
  121129. 10, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  121130. 9, 9, 9,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  121131. 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,10,10, 9, 9, 9,
  121132. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,
  121133. 10,10, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  121134. 9, 9,10,10,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  121135. 9, 9, 9, 9, 9, 9, 9,10,10,10,10,10, 9, 9, 9, 9,
  121136. 9, 9, 9, 9, 9, 9, 9, 9,10, 9, 9, 9,10,10,10,10,
  121137. 10,10,10, 9, 9, 9, 9, 9, 9,10, 9, 9, 9, 9, 9, 9,
  121138. 9,10,10,10,10,10,10,10, 9, 9, 9,10,10,10,10,10,
  121139. 9, 9, 9, 9, 9, 9,10,10,10,10,10,10,10, 9, 9,10,
  121140. 9,10, 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,10,10,10,
  121141. 10,10,10,10, 9, 9,10,10, 9, 9, 9, 9, 9, 9, 9, 9,
  121142. 10,10,10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9,
  121143. 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,10,10,
  121144. 10,10, 9, 9,10, 9, 9, 9, 9, 9,10,10,10,10,10,10,
  121145. 10,10,10,10,10, 9, 9,10,10, 9, 9,10, 9, 9, 9,10,
  121146. 10,10,10,10,10,10,10,10,10,10, 9, 9,10, 9, 9, 9,
  121147. 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,10,10, 9,
  121148. 9, 9, 9,10, 9, 9, 9, 9, 9,
  121149. };
  121150. static float _vq_quantthresh__44c9_s_p8_1[] = {
  121151. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  121152. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  121153. 6.5, 7.5, 8.5, 9.5,
  121154. };
  121155. static long _vq_quantmap__44c9_s_p8_1[] = {
  121156. 19, 17, 15, 13, 11, 9, 7, 5,
  121157. 3, 1, 0, 2, 4, 6, 8, 10,
  121158. 12, 14, 16, 18, 20,
  121159. };
  121160. static encode_aux_threshmatch _vq_auxt__44c9_s_p8_1 = {
  121161. _vq_quantthresh__44c9_s_p8_1,
  121162. _vq_quantmap__44c9_s_p8_1,
  121163. 21,
  121164. 21
  121165. };
  121166. static static_codebook _44c9_s_p8_1 = {
  121167. 2, 441,
  121168. _vq_lengthlist__44c9_s_p8_1,
  121169. 1, -529268736, 1611661312, 5, 0,
  121170. _vq_quantlist__44c9_s_p8_1,
  121171. NULL,
  121172. &_vq_auxt__44c9_s_p8_1,
  121173. NULL,
  121174. 0
  121175. };
  121176. static long _vq_quantlist__44c9_s_p9_0[] = {
  121177. 9,
  121178. 8,
  121179. 10,
  121180. 7,
  121181. 11,
  121182. 6,
  121183. 12,
  121184. 5,
  121185. 13,
  121186. 4,
  121187. 14,
  121188. 3,
  121189. 15,
  121190. 2,
  121191. 16,
  121192. 1,
  121193. 17,
  121194. 0,
  121195. 18,
  121196. };
  121197. static long _vq_lengthlist__44c9_s_p9_0[] = {
  121198. 1, 4, 3,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121199. 12,12,12, 4, 5, 6,12,12,12,12,12,12,12,12,12,12,
  121200. 12,12,12,12,12,12, 4, 6, 6,12,12,12,12,12,12,12,
  121201. 12,12,12,12,12,12,12,12,12,12,12,11,12,12,12,12,
  121202. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121203. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121204. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121205. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121206. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121207. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121208. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121209. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121210. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121211. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121212. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121213. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121214. 12,12,12,12,12,12,12,12,12,12,11,11,11,11,11,11,
  121215. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  121216. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  121217. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  121218. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  121219. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  121220. 11,11,11,11,11,11,11,11,11,
  121221. };
  121222. static float _vq_quantthresh__44c9_s_p9_0[] = {
  121223. -7913.5, -6982.5, -6051.5, -5120.5, -4189.5, -3258.5, -2327.5, -1396.5,
  121224. -465.5, 465.5, 1396.5, 2327.5, 3258.5, 4189.5, 5120.5, 6051.5,
  121225. 6982.5, 7913.5,
  121226. };
  121227. static long _vq_quantmap__44c9_s_p9_0[] = {
  121228. 17, 15, 13, 11, 9, 7, 5, 3,
  121229. 1, 0, 2, 4, 6, 8, 10, 12,
  121230. 14, 16, 18,
  121231. };
  121232. static encode_aux_threshmatch _vq_auxt__44c9_s_p9_0 = {
  121233. _vq_quantthresh__44c9_s_p9_0,
  121234. _vq_quantmap__44c9_s_p9_0,
  121235. 19,
  121236. 19
  121237. };
  121238. static static_codebook _44c9_s_p9_0 = {
  121239. 2, 361,
  121240. _vq_lengthlist__44c9_s_p9_0,
  121241. 1, -508535424, 1631393792, 5, 0,
  121242. _vq_quantlist__44c9_s_p9_0,
  121243. NULL,
  121244. &_vq_auxt__44c9_s_p9_0,
  121245. NULL,
  121246. 0
  121247. };
  121248. static long _vq_quantlist__44c9_s_p9_1[] = {
  121249. 9,
  121250. 8,
  121251. 10,
  121252. 7,
  121253. 11,
  121254. 6,
  121255. 12,
  121256. 5,
  121257. 13,
  121258. 4,
  121259. 14,
  121260. 3,
  121261. 15,
  121262. 2,
  121263. 16,
  121264. 1,
  121265. 17,
  121266. 0,
  121267. 18,
  121268. };
  121269. static long _vq_lengthlist__44c9_s_p9_1[] = {
  121270. 1, 4, 4, 7, 7, 7, 7, 8, 7, 9, 8, 9, 9,10,10,11,
  121271. 11,11,11, 6, 5, 5, 8, 8, 9, 9, 9, 8,10, 9,11,10,
  121272. 12,12,13,12,13,13, 5, 5, 5, 8, 8, 9, 9, 9, 9,10,
  121273. 10,11,11,12,12,13,12,13,13,17, 8, 8, 9, 9, 9, 9,
  121274. 9, 9,10,10,12,11,13,12,13,13,13,13,18, 8, 8, 9,
  121275. 9, 9, 9, 9, 9,11,11,12,12,13,13,13,13,13,13,17,
  121276. 13,12, 9, 9,10,10,10,10,11,11,12,12,12,13,13,13,
  121277. 14,14,18,13,12, 9, 9,10,10,10,10,11,11,12,12,13,
  121278. 13,13,14,14,14,17,18,18,10,10,10,10,11,11,11,12,
  121279. 12,12,14,13,14,13,13,14,18,18,18,10, 9,10, 9,11,
  121280. 11,12,12,12,12,13,13,15,14,14,14,18,18,16,13,14,
  121281. 10,11,11,11,12,13,13,13,13,14,13,13,14,14,18,18,
  121282. 18,14,12,11, 9,11,10,13,12,13,13,13,14,14,14,13,
  121283. 14,18,18,17,18,18,11,12,12,12,13,13,14,13,14,14,
  121284. 13,14,14,14,18,18,18,18,17,12,10,12, 9,13,11,13,
  121285. 14,14,14,14,14,15,14,18,18,17,17,18,14,15,12,13,
  121286. 13,13,14,13,14,14,15,14,15,14,18,17,18,18,18,15,
  121287. 15,12,10,14,10,14,14,13,13,14,14,14,14,18,16,18,
  121288. 18,18,18,17,14,14,13,14,14,13,13,14,14,14,15,15,
  121289. 18,18,18,18,17,17,17,14,14,14,12,14,13,14,14,15,
  121290. 14,15,14,18,18,18,18,18,18,18,17,16,13,13,13,14,
  121291. 14,14,14,15,16,15,18,18,18,18,18,18,18,17,17,13,
  121292. 13,13,13,14,13,14,15,15,15,
  121293. };
  121294. static float _vq_quantthresh__44c9_s_p9_1[] = {
  121295. -416.5, -367.5, -318.5, -269.5, -220.5, -171.5, -122.5, -73.5,
  121296. -24.5, 24.5, 73.5, 122.5, 171.5, 220.5, 269.5, 318.5,
  121297. 367.5, 416.5,
  121298. };
  121299. static long _vq_quantmap__44c9_s_p9_1[] = {
  121300. 17, 15, 13, 11, 9, 7, 5, 3,
  121301. 1, 0, 2, 4, 6, 8, 10, 12,
  121302. 14, 16, 18,
  121303. };
  121304. static encode_aux_threshmatch _vq_auxt__44c9_s_p9_1 = {
  121305. _vq_quantthresh__44c9_s_p9_1,
  121306. _vq_quantmap__44c9_s_p9_1,
  121307. 19,
  121308. 19
  121309. };
  121310. static static_codebook _44c9_s_p9_1 = {
  121311. 2, 361,
  121312. _vq_lengthlist__44c9_s_p9_1,
  121313. 1, -518287360, 1622704128, 5, 0,
  121314. _vq_quantlist__44c9_s_p9_1,
  121315. NULL,
  121316. &_vq_auxt__44c9_s_p9_1,
  121317. NULL,
  121318. 0
  121319. };
  121320. static long _vq_quantlist__44c9_s_p9_2[] = {
  121321. 24,
  121322. 23,
  121323. 25,
  121324. 22,
  121325. 26,
  121326. 21,
  121327. 27,
  121328. 20,
  121329. 28,
  121330. 19,
  121331. 29,
  121332. 18,
  121333. 30,
  121334. 17,
  121335. 31,
  121336. 16,
  121337. 32,
  121338. 15,
  121339. 33,
  121340. 14,
  121341. 34,
  121342. 13,
  121343. 35,
  121344. 12,
  121345. 36,
  121346. 11,
  121347. 37,
  121348. 10,
  121349. 38,
  121350. 9,
  121351. 39,
  121352. 8,
  121353. 40,
  121354. 7,
  121355. 41,
  121356. 6,
  121357. 42,
  121358. 5,
  121359. 43,
  121360. 4,
  121361. 44,
  121362. 3,
  121363. 45,
  121364. 2,
  121365. 46,
  121366. 1,
  121367. 47,
  121368. 0,
  121369. 48,
  121370. };
  121371. static long _vq_lengthlist__44c9_s_p9_2[] = {
  121372. 2, 4, 4, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6,
  121373. 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7,
  121374. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  121375. 7,
  121376. };
  121377. static float _vq_quantthresh__44c9_s_p9_2[] = {
  121378. -23.5, -22.5, -21.5, -20.5, -19.5, -18.5, -17.5, -16.5,
  121379. -15.5, -14.5, -13.5, -12.5, -11.5, -10.5, -9.5, -8.5,
  121380. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  121381. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  121382. 8.5, 9.5, 10.5, 11.5, 12.5, 13.5, 14.5, 15.5,
  121383. 16.5, 17.5, 18.5, 19.5, 20.5, 21.5, 22.5, 23.5,
  121384. };
  121385. static long _vq_quantmap__44c9_s_p9_2[] = {
  121386. 47, 45, 43, 41, 39, 37, 35, 33,
  121387. 31, 29, 27, 25, 23, 21, 19, 17,
  121388. 15, 13, 11, 9, 7, 5, 3, 1,
  121389. 0, 2, 4, 6, 8, 10, 12, 14,
  121390. 16, 18, 20, 22, 24, 26, 28, 30,
  121391. 32, 34, 36, 38, 40, 42, 44, 46,
  121392. 48,
  121393. };
  121394. static encode_aux_threshmatch _vq_auxt__44c9_s_p9_2 = {
  121395. _vq_quantthresh__44c9_s_p9_2,
  121396. _vq_quantmap__44c9_s_p9_2,
  121397. 49,
  121398. 49
  121399. };
  121400. static static_codebook _44c9_s_p9_2 = {
  121401. 1, 49,
  121402. _vq_lengthlist__44c9_s_p9_2,
  121403. 1, -526909440, 1611661312, 6, 0,
  121404. _vq_quantlist__44c9_s_p9_2,
  121405. NULL,
  121406. &_vq_auxt__44c9_s_p9_2,
  121407. NULL,
  121408. 0
  121409. };
  121410. static long _huff_lengthlist__44c9_s_short[] = {
  121411. 5,13,18,16,17,17,19,18,19,19, 5, 7,10,11,12,12,
  121412. 13,16,17,18, 6, 6, 7, 7, 9, 9,10,14,17,19, 8, 7,
  121413. 6, 5, 6, 7, 9,12,19,17, 8, 7, 7, 6, 5, 6, 8,11,
  121414. 15,19, 9, 8, 7, 6, 5, 5, 6, 8,13,15,11,10, 8, 8,
  121415. 7, 5, 4, 4,10,14,12,13,11, 9, 7, 6, 4, 2, 6,12,
  121416. 18,16,16,13, 8, 7, 7, 5, 8,13,16,17,18,15,11, 9,
  121417. 9, 8,10,13,
  121418. };
  121419. static static_codebook _huff_book__44c9_s_short = {
  121420. 2, 100,
  121421. _huff_lengthlist__44c9_s_short,
  121422. 0, 0, 0, 0, 0,
  121423. NULL,
  121424. NULL,
  121425. NULL,
  121426. NULL,
  121427. 0
  121428. };
  121429. static long _huff_lengthlist__44c0_s_long[] = {
  121430. 5, 4, 8, 9, 8, 9,10,12,15, 4, 1, 5, 5, 6, 8,11,
  121431. 12,12, 8, 5, 8, 9, 9,11,13,12,12, 9, 5, 8, 5, 7,
  121432. 9,12,13,13, 8, 6, 8, 7, 7, 9,11,11,11, 9, 7, 9,
  121433. 7, 7, 7, 7,10,12,10,10,11, 9, 8, 7, 7, 9,11,11,
  121434. 12,13,12,11, 9, 8, 9,11,13,16,16,15,15,12,10,11,
  121435. 12,
  121436. };
  121437. static static_codebook _huff_book__44c0_s_long = {
  121438. 2, 81,
  121439. _huff_lengthlist__44c0_s_long,
  121440. 0, 0, 0, 0, 0,
  121441. NULL,
  121442. NULL,
  121443. NULL,
  121444. NULL,
  121445. 0
  121446. };
  121447. static long _vq_quantlist__44c0_s_p1_0[] = {
  121448. 1,
  121449. 0,
  121450. 2,
  121451. };
  121452. static long _vq_lengthlist__44c0_s_p1_0[] = {
  121453. 1, 5, 5, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0,
  121454. 0, 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121455. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121456. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121457. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121458. 0, 5, 8, 7, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0, 0,
  121459. 0, 0, 0, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121460. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121461. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121462. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121463. 0, 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  121464. 0, 0, 0, 0, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121465. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121466. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121467. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121468. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121469. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121470. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121471. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121472. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121473. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121474. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121475. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121476. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121477. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121478. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121479. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121480. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121481. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121482. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121483. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121484. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121485. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121486. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121487. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121488. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121489. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121490. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121491. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121492. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121493. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121494. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121495. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121496. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121497. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121498. 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0,
  121499. 0, 0, 8,10, 9, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  121500. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121501. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121502. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121503. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0, 0,
  121504. 0, 0, 0, 9,10,11, 0, 0, 0, 0, 0, 0, 9,11,10, 0,
  121505. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121506. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121507. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121508. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  121509. 0, 0, 0, 0, 9,11, 9, 0, 0, 0, 0, 0, 0, 9,10,11,
  121510. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121511. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121512. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121513. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121514. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121515. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121516. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121517. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121518. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121519. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121520. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121521. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121522. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121523. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121524. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121525. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121526. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121527. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121528. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121529. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121530. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121531. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121532. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121533. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121534. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121535. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121536. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121537. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121538. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121539. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121540. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121541. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121542. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121543. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121544. 0, 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  121545. 0, 0, 0, 0, 8, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121546. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121547. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121548. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121549. 0, 0, 0, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,11,10, 0,
  121550. 0, 0, 0, 0, 0, 9, 9,11, 0, 0, 0, 0, 0, 0, 0, 0,
  121551. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121552. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121553. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121554. 0, 0, 0, 0, 7, 9,10, 0, 0, 0, 0, 0, 0, 9,10,11,
  121555. 0, 0, 0, 0, 0, 0, 9,11,10, 0, 0, 0, 0, 0, 0, 0,
  121556. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121557. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121558. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121559. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121560. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121561. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121562. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121563. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121564. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121565. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121566. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121567. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121568. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121569. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121570. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121571. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121572. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121573. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121574. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121575. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121576. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121577. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121578. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121579. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121580. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121581. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121582. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121583. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121584. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121585. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121586. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121587. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121588. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121589. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121590. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121591. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121592. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121593. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121594. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121595. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121596. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121597. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121598. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121599. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121600. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121601. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121602. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121603. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121604. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121605. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121606. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121607. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121608. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121609. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121610. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121611. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121612. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121613. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121614. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121615. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121616. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121617. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121618. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121619. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121620. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121621. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121622. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121623. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121624. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121625. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121626. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121627. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121628. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121629. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121630. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121631. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121632. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121633. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121634. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121635. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121636. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121637. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121638. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121639. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121640. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121641. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121642. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121643. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121644. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121645. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121646. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121647. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121648. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121649. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121650. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121651. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121652. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121653. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121654. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121655. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121656. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121657. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121658. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121659. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121660. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121661. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121662. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121663. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121664. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121665. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121666. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121667. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121668. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121669. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121670. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121671. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121672. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121673. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121674. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121675. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121676. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121677. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121678. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121679. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121680. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121681. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121682. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121683. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121684. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121685. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121686. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121687. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121688. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121689. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121690. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121691. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121692. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121693. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121694. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121695. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121696. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121697. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121698. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121699. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121700. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121701. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121702. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121703. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121704. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121705. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121706. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121707. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121708. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121709. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121710. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121711. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121712. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121713. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121714. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121715. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121716. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121717. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121718. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121719. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121720. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121721. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121722. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121723. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121724. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121725. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121726. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121727. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121728. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121729. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121730. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121731. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121732. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121733. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121734. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121735. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121736. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121737. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121738. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121739. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121740. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121741. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121742. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121743. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121744. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121745. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121746. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121747. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121748. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121749. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121750. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121751. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121752. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121753. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121754. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121755. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121756. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121757. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121758. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121759. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121760. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121761. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121762. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121763. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121764. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121765. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121766. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121767. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121768. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121769. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121770. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121771. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121772. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121773. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121774. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121775. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121776. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121777. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121778. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121779. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121780. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121781. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121782. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121783. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121784. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121785. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121786. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121787. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121788. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121789. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121790. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121791. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121792. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121793. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121794. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121795. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121796. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121797. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121798. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121799. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121800. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121801. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121802. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121803. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121804. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121805. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121806. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121807. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121808. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121809. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121810. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121811. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121812. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121813. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121814. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121815. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121816. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121817. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121818. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121819. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121820. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121821. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121822. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121823. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121824. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121825. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121826. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121827. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121828. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121829. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121830. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121831. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121832. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121833. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121834. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121835. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121836. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121837. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121838. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121839. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121840. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121841. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121842. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121843. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121844. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121845. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121846. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121847. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121848. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121849. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121850. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121851. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121852. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121853. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121854. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121855. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121856. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121857. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121858. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121859. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121860. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121861. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121862. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121863. 0,
  121864. };
  121865. static float _vq_quantthresh__44c0_s_p1_0[] = {
  121866. -0.5, 0.5,
  121867. };
  121868. static long _vq_quantmap__44c0_s_p1_0[] = {
  121869. 1, 0, 2,
  121870. };
  121871. static encode_aux_threshmatch _vq_auxt__44c0_s_p1_0 = {
  121872. _vq_quantthresh__44c0_s_p1_0,
  121873. _vq_quantmap__44c0_s_p1_0,
  121874. 3,
  121875. 3
  121876. };
  121877. static static_codebook _44c0_s_p1_0 = {
  121878. 8, 6561,
  121879. _vq_lengthlist__44c0_s_p1_0,
  121880. 1, -535822336, 1611661312, 2, 0,
  121881. _vq_quantlist__44c0_s_p1_0,
  121882. NULL,
  121883. &_vq_auxt__44c0_s_p1_0,
  121884. NULL,
  121885. 0
  121886. };
  121887. static long _vq_quantlist__44c0_s_p2_0[] = {
  121888. 2,
  121889. 1,
  121890. 3,
  121891. 0,
  121892. 4,
  121893. };
  121894. static long _vq_lengthlist__44c0_s_p2_0[] = {
  121895. 1, 4, 4, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121896. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 5, 5, 7, 6, 0, 0,
  121897. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121898. 0, 0, 4, 5, 6, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121899. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 7, 7, 9, 9,
  121900. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121901. 0, 0, 0, 0, 6, 7, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0,
  121902. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121903. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121904. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121905. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121906. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121907. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121908. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121909. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121910. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121911. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121912. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121913. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121914. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121915. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121916. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121917. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121918. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121919. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121920. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121921. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121922. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121923. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121924. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121925. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121926. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121927. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121928. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121929. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121930. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121931. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121932. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121933. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121934. 0,
  121935. };
  121936. static float _vq_quantthresh__44c0_s_p2_0[] = {
  121937. -1.5, -0.5, 0.5, 1.5,
  121938. };
  121939. static long _vq_quantmap__44c0_s_p2_0[] = {
  121940. 3, 1, 0, 2, 4,
  121941. };
  121942. static encode_aux_threshmatch _vq_auxt__44c0_s_p2_0 = {
  121943. _vq_quantthresh__44c0_s_p2_0,
  121944. _vq_quantmap__44c0_s_p2_0,
  121945. 5,
  121946. 5
  121947. };
  121948. static static_codebook _44c0_s_p2_0 = {
  121949. 4, 625,
  121950. _vq_lengthlist__44c0_s_p2_0,
  121951. 1, -533725184, 1611661312, 3, 0,
  121952. _vq_quantlist__44c0_s_p2_0,
  121953. NULL,
  121954. &_vq_auxt__44c0_s_p2_0,
  121955. NULL,
  121956. 0
  121957. };
  121958. static long _vq_quantlist__44c0_s_p3_0[] = {
  121959. 4,
  121960. 3,
  121961. 5,
  121962. 2,
  121963. 6,
  121964. 1,
  121965. 7,
  121966. 0,
  121967. 8,
  121968. };
  121969. static long _vq_lengthlist__44c0_s_p3_0[] = {
  121970. 1, 3, 2, 8, 7, 0, 0, 0, 0, 0, 0, 0, 6, 6, 0, 0,
  121971. 0, 0, 0, 0, 0, 6, 6, 0, 0, 0, 0, 0, 0, 0, 7, 7,
  121972. 0, 0, 0, 0, 0, 0, 0, 7, 7, 0, 0, 0, 0, 0, 0, 0,
  121973. 8, 8, 0, 0, 0, 0, 0, 0, 0, 8, 8, 0, 0, 0, 0, 0,
  121974. 0, 0, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121975. 0,
  121976. };
  121977. static float _vq_quantthresh__44c0_s_p3_0[] = {
  121978. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  121979. };
  121980. static long _vq_quantmap__44c0_s_p3_0[] = {
  121981. 7, 5, 3, 1, 0, 2, 4, 6,
  121982. 8,
  121983. };
  121984. static encode_aux_threshmatch _vq_auxt__44c0_s_p3_0 = {
  121985. _vq_quantthresh__44c0_s_p3_0,
  121986. _vq_quantmap__44c0_s_p3_0,
  121987. 9,
  121988. 9
  121989. };
  121990. static static_codebook _44c0_s_p3_0 = {
  121991. 2, 81,
  121992. _vq_lengthlist__44c0_s_p3_0,
  121993. 1, -531628032, 1611661312, 4, 0,
  121994. _vq_quantlist__44c0_s_p3_0,
  121995. NULL,
  121996. &_vq_auxt__44c0_s_p3_0,
  121997. NULL,
  121998. 0
  121999. };
  122000. static long _vq_quantlist__44c0_s_p4_0[] = {
  122001. 4,
  122002. 3,
  122003. 5,
  122004. 2,
  122005. 6,
  122006. 1,
  122007. 7,
  122008. 0,
  122009. 8,
  122010. };
  122011. static long _vq_lengthlist__44c0_s_p4_0[] = {
  122012. 1, 3, 3, 6, 6, 6, 6, 8, 8, 0, 0, 0, 7, 7, 7, 7,
  122013. 9, 9, 0, 0, 0, 7, 7, 7, 7, 9, 9, 0, 0, 0, 7, 7,
  122014. 7, 8, 9, 9, 0, 0, 0, 7, 7, 7, 7, 9, 9, 0, 0, 0,
  122015. 9, 9, 8, 8,10,10, 0, 0, 0, 8, 9, 8, 8,10,10, 0,
  122016. 0, 0,10,10, 9, 9,10,10, 0, 0, 0, 0, 0, 9, 9,10,
  122017. 10,
  122018. };
  122019. static float _vq_quantthresh__44c0_s_p4_0[] = {
  122020. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  122021. };
  122022. static long _vq_quantmap__44c0_s_p4_0[] = {
  122023. 7, 5, 3, 1, 0, 2, 4, 6,
  122024. 8,
  122025. };
  122026. static encode_aux_threshmatch _vq_auxt__44c0_s_p4_0 = {
  122027. _vq_quantthresh__44c0_s_p4_0,
  122028. _vq_quantmap__44c0_s_p4_0,
  122029. 9,
  122030. 9
  122031. };
  122032. static static_codebook _44c0_s_p4_0 = {
  122033. 2, 81,
  122034. _vq_lengthlist__44c0_s_p4_0,
  122035. 1, -531628032, 1611661312, 4, 0,
  122036. _vq_quantlist__44c0_s_p4_0,
  122037. NULL,
  122038. &_vq_auxt__44c0_s_p4_0,
  122039. NULL,
  122040. 0
  122041. };
  122042. static long _vq_quantlist__44c0_s_p5_0[] = {
  122043. 8,
  122044. 7,
  122045. 9,
  122046. 6,
  122047. 10,
  122048. 5,
  122049. 11,
  122050. 4,
  122051. 12,
  122052. 3,
  122053. 13,
  122054. 2,
  122055. 14,
  122056. 1,
  122057. 15,
  122058. 0,
  122059. 16,
  122060. };
  122061. static long _vq_lengthlist__44c0_s_p5_0[] = {
  122062. 1, 4, 3, 6, 6, 8, 7, 8, 8, 8, 8, 9, 9,10,10,11,
  122063. 11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9, 9,10,10,10,
  122064. 11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,10,
  122065. 10,11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  122066. 11,11,11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,
  122067. 10,11,11,11,11, 0, 0, 0, 8, 8, 9, 9, 9, 9,10,10,
  122068. 10,10,11,11,12,12, 0, 0, 0, 8, 8, 9, 9, 9, 9,10,
  122069. 10,10,10,11,11,12,12, 0, 0, 0, 9, 9, 9, 9,10,10,
  122070. 10,10,11,11,11,12,12,12, 0, 0, 0, 0, 0, 9, 9,10,
  122071. 10,10,10,11,11,11,11,12,12, 0, 0, 0, 0, 0, 9, 9,
  122072. 10,10,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9,
  122073. 9,10,10,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0,
  122074. 10,10,11,11,11,11,11,12,12,12,13,13, 0, 0, 0, 0,
  122075. 0, 0, 0,11,10,11,11,11,11,12,12,13,13, 0, 0, 0,
  122076. 0, 0, 0, 0,11,11,12,11,12,12,12,12,13,13, 0, 0,
  122077. 0, 0, 0, 0, 0,11,11,11,12,12,12,12,13,13,13, 0,
  122078. 0, 0, 0, 0, 0, 0,12,12,12,12,12,13,13,13,14,14,
  122079. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,14,
  122080. 14,
  122081. };
  122082. static float _vq_quantthresh__44c0_s_p5_0[] = {
  122083. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  122084. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  122085. };
  122086. static long _vq_quantmap__44c0_s_p5_0[] = {
  122087. 15, 13, 11, 9, 7, 5, 3, 1,
  122088. 0, 2, 4, 6, 8, 10, 12, 14,
  122089. 16,
  122090. };
  122091. static encode_aux_threshmatch _vq_auxt__44c0_s_p5_0 = {
  122092. _vq_quantthresh__44c0_s_p5_0,
  122093. _vq_quantmap__44c0_s_p5_0,
  122094. 17,
  122095. 17
  122096. };
  122097. static static_codebook _44c0_s_p5_0 = {
  122098. 2, 289,
  122099. _vq_lengthlist__44c0_s_p5_0,
  122100. 1, -529530880, 1611661312, 5, 0,
  122101. _vq_quantlist__44c0_s_p5_0,
  122102. NULL,
  122103. &_vq_auxt__44c0_s_p5_0,
  122104. NULL,
  122105. 0
  122106. };
  122107. static long _vq_quantlist__44c0_s_p6_0[] = {
  122108. 1,
  122109. 0,
  122110. 2,
  122111. };
  122112. static long _vq_lengthlist__44c0_s_p6_0[] = {
  122113. 1, 4, 4, 7, 6, 6, 7, 6, 6, 4, 7, 7,10, 9, 9,10,
  122114. 9, 9, 4, 6, 7,10, 9, 9,11, 9, 9, 7,10,10,11,11,
  122115. 11,12,10,11, 6, 9, 9,11,10,11,11,10,10, 6, 9, 9,
  122116. 11,10,11,11,10,10, 7,11,10,12,11,11,11,11,11, 7,
  122117. 9, 9,10,10,10,11,11,10, 6, 9, 9,11,10,10,11,10,
  122118. 10,
  122119. };
  122120. static float _vq_quantthresh__44c0_s_p6_0[] = {
  122121. -5.5, 5.5,
  122122. };
  122123. static long _vq_quantmap__44c0_s_p6_0[] = {
  122124. 1, 0, 2,
  122125. };
  122126. static encode_aux_threshmatch _vq_auxt__44c0_s_p6_0 = {
  122127. _vq_quantthresh__44c0_s_p6_0,
  122128. _vq_quantmap__44c0_s_p6_0,
  122129. 3,
  122130. 3
  122131. };
  122132. static static_codebook _44c0_s_p6_0 = {
  122133. 4, 81,
  122134. _vq_lengthlist__44c0_s_p6_0,
  122135. 1, -529137664, 1618345984, 2, 0,
  122136. _vq_quantlist__44c0_s_p6_0,
  122137. NULL,
  122138. &_vq_auxt__44c0_s_p6_0,
  122139. NULL,
  122140. 0
  122141. };
  122142. static long _vq_quantlist__44c0_s_p6_1[] = {
  122143. 5,
  122144. 4,
  122145. 6,
  122146. 3,
  122147. 7,
  122148. 2,
  122149. 8,
  122150. 1,
  122151. 9,
  122152. 0,
  122153. 10,
  122154. };
  122155. static long _vq_lengthlist__44c0_s_p6_1[] = {
  122156. 2, 3, 3, 6, 6, 7, 7, 7, 7, 7, 8,10,10,10, 6, 6,
  122157. 7, 7, 8, 8, 8, 8,10,10,10, 6, 6, 7, 7, 8, 8, 8,
  122158. 8,10,10,10, 7, 7, 7, 7, 8, 8, 8, 8,10,10,10, 7,
  122159. 7, 7, 7, 8, 8, 8, 8,10,10,10, 8, 7, 8, 8, 8, 8,
  122160. 8, 8,10,10,10, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10,
  122161. 8, 8, 8, 8, 8, 8, 8, 8,10,10,10,10,10, 8, 8, 8,
  122162. 8, 8, 8,10,10,10,10,10, 9, 9, 8, 8, 8, 8,10,10,
  122163. 10,10,10, 8, 8, 8, 8, 8, 8,
  122164. };
  122165. static float _vq_quantthresh__44c0_s_p6_1[] = {
  122166. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  122167. 3.5, 4.5,
  122168. };
  122169. static long _vq_quantmap__44c0_s_p6_1[] = {
  122170. 9, 7, 5, 3, 1, 0, 2, 4,
  122171. 6, 8, 10,
  122172. };
  122173. static encode_aux_threshmatch _vq_auxt__44c0_s_p6_1 = {
  122174. _vq_quantthresh__44c0_s_p6_1,
  122175. _vq_quantmap__44c0_s_p6_1,
  122176. 11,
  122177. 11
  122178. };
  122179. static static_codebook _44c0_s_p6_1 = {
  122180. 2, 121,
  122181. _vq_lengthlist__44c0_s_p6_1,
  122182. 1, -531365888, 1611661312, 4, 0,
  122183. _vq_quantlist__44c0_s_p6_1,
  122184. NULL,
  122185. &_vq_auxt__44c0_s_p6_1,
  122186. NULL,
  122187. 0
  122188. };
  122189. static long _vq_quantlist__44c0_s_p7_0[] = {
  122190. 6,
  122191. 5,
  122192. 7,
  122193. 4,
  122194. 8,
  122195. 3,
  122196. 9,
  122197. 2,
  122198. 10,
  122199. 1,
  122200. 11,
  122201. 0,
  122202. 12,
  122203. };
  122204. static long _vq_lengthlist__44c0_s_p7_0[] = {
  122205. 1, 4, 4, 6, 6, 7, 7, 7, 7, 8, 8, 9, 9, 7, 5, 5,
  122206. 7, 7, 8, 8, 8, 8, 9, 9,10,10, 7, 5, 6, 7, 7, 8,
  122207. 8, 8, 8, 9, 9,10,10, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  122208. 10,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  122209. 11, 0,12,12, 9, 9,10,10,10,10,11,11,11,11, 0,13,
  122210. 13, 9, 9, 9, 9,10,10,11,11,11,12, 0, 0, 0,10,10,
  122211. 10,10,11,11,11,11,12,12, 0, 0, 0,10,10, 9, 9,11,
  122212. 11,11,12,12,12, 0, 0, 0,13,13,10,10,11,11,12,12,
  122213. 13,13, 0, 0, 0,14,14,10,10,11,11,12,12,13,13, 0,
  122214. 0, 0, 0, 0,11,11,11,11,13,12,13,13, 0, 0, 0, 0,
  122215. 0,12,12,11,11,12,12,13,13,
  122216. };
  122217. static float _vq_quantthresh__44c0_s_p7_0[] = {
  122218. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  122219. 12.5, 17.5, 22.5, 27.5,
  122220. };
  122221. static long _vq_quantmap__44c0_s_p7_0[] = {
  122222. 11, 9, 7, 5, 3, 1, 0, 2,
  122223. 4, 6, 8, 10, 12,
  122224. };
  122225. static encode_aux_threshmatch _vq_auxt__44c0_s_p7_0 = {
  122226. _vq_quantthresh__44c0_s_p7_0,
  122227. _vq_quantmap__44c0_s_p7_0,
  122228. 13,
  122229. 13
  122230. };
  122231. static static_codebook _44c0_s_p7_0 = {
  122232. 2, 169,
  122233. _vq_lengthlist__44c0_s_p7_0,
  122234. 1, -526516224, 1616117760, 4, 0,
  122235. _vq_quantlist__44c0_s_p7_0,
  122236. NULL,
  122237. &_vq_auxt__44c0_s_p7_0,
  122238. NULL,
  122239. 0
  122240. };
  122241. static long _vq_quantlist__44c0_s_p7_1[] = {
  122242. 2,
  122243. 1,
  122244. 3,
  122245. 0,
  122246. 4,
  122247. };
  122248. static long _vq_lengthlist__44c0_s_p7_1[] = {
  122249. 2, 3, 3, 5, 5, 6, 6, 6, 5, 5, 6, 6, 6, 5, 5, 6,
  122250. 6, 6, 5, 5, 6, 6, 6, 5, 5,
  122251. };
  122252. static float _vq_quantthresh__44c0_s_p7_1[] = {
  122253. -1.5, -0.5, 0.5, 1.5,
  122254. };
  122255. static long _vq_quantmap__44c0_s_p7_1[] = {
  122256. 3, 1, 0, 2, 4,
  122257. };
  122258. static encode_aux_threshmatch _vq_auxt__44c0_s_p7_1 = {
  122259. _vq_quantthresh__44c0_s_p7_1,
  122260. _vq_quantmap__44c0_s_p7_1,
  122261. 5,
  122262. 5
  122263. };
  122264. static static_codebook _44c0_s_p7_1 = {
  122265. 2, 25,
  122266. _vq_lengthlist__44c0_s_p7_1,
  122267. 1, -533725184, 1611661312, 3, 0,
  122268. _vq_quantlist__44c0_s_p7_1,
  122269. NULL,
  122270. &_vq_auxt__44c0_s_p7_1,
  122271. NULL,
  122272. 0
  122273. };
  122274. static long _vq_quantlist__44c0_s_p8_0[] = {
  122275. 2,
  122276. 1,
  122277. 3,
  122278. 0,
  122279. 4,
  122280. };
  122281. static long _vq_lengthlist__44c0_s_p8_0[] = {
  122282. 1, 5, 5,10,10, 6, 9, 8,10,10, 6,10, 9,10,10,10,
  122283. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  122284. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  122285. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  122286. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  122287. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  122288. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  122289. 10,10,10,10,10,10,10,10,10,10,10,10,10, 8,10,10,
  122290. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  122291. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  122292. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  122293. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  122294. 10,10,10,10,10,10,10,10,11,11,11,11,11,11,11,11,
  122295. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122296. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122297. 11,11,11,11,11,11,11,11,11,11,10,11,11,11,11,11,
  122298. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122299. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122300. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122301. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122302. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122303. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122304. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122305. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122306. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122307. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122308. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122309. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122310. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122311. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122312. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122313. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122314. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122315. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122316. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122317. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122318. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122319. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122320. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122321. 11,
  122322. };
  122323. static float _vq_quantthresh__44c0_s_p8_0[] = {
  122324. -331.5, -110.5, 110.5, 331.5,
  122325. };
  122326. static long _vq_quantmap__44c0_s_p8_0[] = {
  122327. 3, 1, 0, 2, 4,
  122328. };
  122329. static encode_aux_threshmatch _vq_auxt__44c0_s_p8_0 = {
  122330. _vq_quantthresh__44c0_s_p8_0,
  122331. _vq_quantmap__44c0_s_p8_0,
  122332. 5,
  122333. 5
  122334. };
  122335. static static_codebook _44c0_s_p8_0 = {
  122336. 4, 625,
  122337. _vq_lengthlist__44c0_s_p8_0,
  122338. 1, -518283264, 1627103232, 3, 0,
  122339. _vq_quantlist__44c0_s_p8_0,
  122340. NULL,
  122341. &_vq_auxt__44c0_s_p8_0,
  122342. NULL,
  122343. 0
  122344. };
  122345. static long _vq_quantlist__44c0_s_p8_1[] = {
  122346. 6,
  122347. 5,
  122348. 7,
  122349. 4,
  122350. 8,
  122351. 3,
  122352. 9,
  122353. 2,
  122354. 10,
  122355. 1,
  122356. 11,
  122357. 0,
  122358. 12,
  122359. };
  122360. static long _vq_lengthlist__44c0_s_p8_1[] = {
  122361. 1, 4, 4, 6, 6, 7, 7, 9, 9,11,12,13,12, 6, 5, 5,
  122362. 7, 7, 8, 8,10, 9,12,12,12,12, 6, 5, 5, 7, 7, 8,
  122363. 8,10, 9,12,11,11,13,16, 7, 7, 8, 8, 9, 9,10,10,
  122364. 12,12,13,12,16, 7, 7, 8, 7, 9, 9,10,10,11,12,12,
  122365. 13,16,10,10, 8, 8,10,10,11,12,12,12,13,13,16,11,
  122366. 10, 8, 7,11,10,11,11,12,11,13,13,16,16,16,10,10,
  122367. 10,10,11,11,13,12,13,13,16,16,16,11, 9,11, 9,15,
  122368. 13,12,13,13,13,16,16,16,15,13,11,11,12,13,12,12,
  122369. 14,13,16,16,16,14,13,11,11,13,12,14,13,13,13,16,
  122370. 16,16,16,16,13,13,13,12,14,13,14,14,16,16,16,16,
  122371. 16,13,13,12,12,14,14,15,13,
  122372. };
  122373. static float _vq_quantthresh__44c0_s_p8_1[] = {
  122374. -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5, 25.5,
  122375. 42.5, 59.5, 76.5, 93.5,
  122376. };
  122377. static long _vq_quantmap__44c0_s_p8_1[] = {
  122378. 11, 9, 7, 5, 3, 1, 0, 2,
  122379. 4, 6, 8, 10, 12,
  122380. };
  122381. static encode_aux_threshmatch _vq_auxt__44c0_s_p8_1 = {
  122382. _vq_quantthresh__44c0_s_p8_1,
  122383. _vq_quantmap__44c0_s_p8_1,
  122384. 13,
  122385. 13
  122386. };
  122387. static static_codebook _44c0_s_p8_1 = {
  122388. 2, 169,
  122389. _vq_lengthlist__44c0_s_p8_1,
  122390. 1, -522616832, 1620115456, 4, 0,
  122391. _vq_quantlist__44c0_s_p8_1,
  122392. NULL,
  122393. &_vq_auxt__44c0_s_p8_1,
  122394. NULL,
  122395. 0
  122396. };
  122397. static long _vq_quantlist__44c0_s_p8_2[] = {
  122398. 8,
  122399. 7,
  122400. 9,
  122401. 6,
  122402. 10,
  122403. 5,
  122404. 11,
  122405. 4,
  122406. 12,
  122407. 3,
  122408. 13,
  122409. 2,
  122410. 14,
  122411. 1,
  122412. 15,
  122413. 0,
  122414. 16,
  122415. };
  122416. static long _vq_lengthlist__44c0_s_p8_2[] = {
  122417. 2, 4, 4, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8,
  122418. 8,10,10,10, 7, 7, 7, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  122419. 9, 9,10,10,10, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9, 9,
  122420. 9, 9, 9,10,10,10, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9,
  122421. 9,10, 9, 9,10,10,10, 7, 7, 8, 8, 9, 8, 9, 9, 9,
  122422. 9,10, 9, 9,10,10,10,10, 8, 8, 8, 8, 9, 8, 9, 9,
  122423. 9, 9, 9,10, 9,10,10,10,10, 7, 7, 8, 8, 9, 9, 9,
  122424. 9, 9, 9,10, 9,10,10,10,10,10, 8, 8, 8, 9, 9, 9,
  122425. 9, 9, 9, 9,10,10,10, 9,11,10,10,10,10, 8, 8, 9,
  122426. 9, 9, 9, 9,10, 9, 9, 9,10,10,10,10,11,11, 9, 9,
  122427. 9, 9, 9, 9, 9, 9,10, 9, 9,10,11,10,10,11,11, 9,
  122428. 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 9,11,11,10,11,11,
  122429. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 9,11,10,10,11,
  122430. 11,11,11, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,
  122431. 11,11,11,11, 9,10, 9,10, 9, 9, 9, 9,10, 9,10,11,
  122432. 10,11,10,10,10,10,10, 9, 9, 9,10, 9, 9, 9,10,11,
  122433. 11,10,11,11,10,11,10,10,10, 9, 9, 9, 9,10, 9, 9,
  122434. 10,11,10,11,11,11,11,10,11,10,10, 9,10, 9, 9, 9,
  122435. 10,
  122436. };
  122437. static float _vq_quantthresh__44c0_s_p8_2[] = {
  122438. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  122439. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  122440. };
  122441. static long _vq_quantmap__44c0_s_p8_2[] = {
  122442. 15, 13, 11, 9, 7, 5, 3, 1,
  122443. 0, 2, 4, 6, 8, 10, 12, 14,
  122444. 16,
  122445. };
  122446. static encode_aux_threshmatch _vq_auxt__44c0_s_p8_2 = {
  122447. _vq_quantthresh__44c0_s_p8_2,
  122448. _vq_quantmap__44c0_s_p8_2,
  122449. 17,
  122450. 17
  122451. };
  122452. static static_codebook _44c0_s_p8_2 = {
  122453. 2, 289,
  122454. _vq_lengthlist__44c0_s_p8_2,
  122455. 1, -529530880, 1611661312, 5, 0,
  122456. _vq_quantlist__44c0_s_p8_2,
  122457. NULL,
  122458. &_vq_auxt__44c0_s_p8_2,
  122459. NULL,
  122460. 0
  122461. };
  122462. static long _huff_lengthlist__44c0_s_short[] = {
  122463. 9, 8,12,11,12,13,14,14,16, 6, 1, 5, 6, 6, 9,12,
  122464. 14,17, 9, 4, 5, 9, 7, 9,13,15,16, 8, 5, 8, 6, 8,
  122465. 10,13,17,17, 9, 6, 7, 7, 8, 9,13,15,17,11, 8, 9,
  122466. 9, 9,10,12,16,16,13, 7, 8, 7, 7, 9,12,14,15,13,
  122467. 6, 7, 5, 5, 7,10,13,13,14, 7, 8, 5, 6, 7, 9,10,
  122468. 12,
  122469. };
  122470. static static_codebook _huff_book__44c0_s_short = {
  122471. 2, 81,
  122472. _huff_lengthlist__44c0_s_short,
  122473. 0, 0, 0, 0, 0,
  122474. NULL,
  122475. NULL,
  122476. NULL,
  122477. NULL,
  122478. 0
  122479. };
  122480. static long _huff_lengthlist__44c0_sm_long[] = {
  122481. 5, 4, 9,10, 9,10,11,12,13, 4, 1, 5, 7, 7, 9,11,
  122482. 12,14, 8, 5, 7, 9, 8,10,13,13,13,10, 7, 9, 4, 6,
  122483. 7,10,12,14, 9, 6, 7, 6, 6, 7,10,12,12, 9, 8, 9,
  122484. 7, 6, 7, 8,11,12,11,11,11, 9, 8, 7, 8,10,12,12,
  122485. 13,14,12,11, 9, 9, 9,12,12,17,17,15,16,12,10,11,
  122486. 13,
  122487. };
  122488. static static_codebook _huff_book__44c0_sm_long = {
  122489. 2, 81,
  122490. _huff_lengthlist__44c0_sm_long,
  122491. 0, 0, 0, 0, 0,
  122492. NULL,
  122493. NULL,
  122494. NULL,
  122495. NULL,
  122496. 0
  122497. };
  122498. static long _vq_quantlist__44c0_sm_p1_0[] = {
  122499. 1,
  122500. 0,
  122501. 2,
  122502. };
  122503. static long _vq_lengthlist__44c0_sm_p1_0[] = {
  122504. 1, 5, 5, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0,
  122505. 0, 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122506. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122507. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122508. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122509. 0, 5, 8, 7, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0, 0,
  122510. 0, 0, 0, 7, 8, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122511. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122512. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122513. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122514. 0, 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 7, 9, 8, 0, 0,
  122515. 0, 0, 0, 0, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122516. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122517. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122518. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122519. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122520. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122521. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122522. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122523. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122524. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122525. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122526. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122527. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122528. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122529. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122530. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122531. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122532. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122533. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122534. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122535. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122536. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122537. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122538. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122539. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122540. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122541. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122542. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122543. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122544. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122545. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122546. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122547. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122548. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122549. 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 8, 7, 0, 0, 0, 0,
  122550. 0, 0, 8, 9, 9, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0, 0,
  122551. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122552. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122553. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122554. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0, 0,
  122555. 0, 0, 0, 9,10,10, 0, 0, 0, 0, 0, 0, 9,10,10, 0,
  122556. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122557. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122558. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122559. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  122560. 0, 0, 0, 0, 8,10, 9, 0, 0, 0, 0, 0, 0, 9,10,10,
  122561. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122562. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122563. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122564. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122565. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122566. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122567. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122568. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122569. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122570. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122571. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122572. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122573. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122574. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122575. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122576. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122577. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122578. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122579. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122580. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122581. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122582. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122583. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122584. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122585. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122586. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122587. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122588. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122589. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122590. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122591. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122592. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122593. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122594. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122595. 0, 0, 5, 7, 8, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  122596. 0, 0, 0, 0, 8, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122597. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122598. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122599. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122600. 0, 0, 0, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,10,10, 0,
  122601. 0, 0, 0, 0, 0, 9, 9,10, 0, 0, 0, 0, 0, 0, 0, 0,
  122602. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122603. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122604. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122605. 0, 0, 0, 0, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,10,10,
  122606. 0, 0, 0, 0, 0, 0, 9,10,10, 0, 0, 0, 0, 0, 0, 0,
  122607. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122608. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122609. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122610. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122611. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122612. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122613. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122614. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122615. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122616. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122617. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122618. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122619. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122620. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122621. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122622. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122623. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122624. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122625. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122626. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122627. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122628. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122629. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122630. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122631. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122632. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122633. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122634. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122635. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122636. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122637. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122638. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122639. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122640. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122641. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122642. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122643. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122644. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122645. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122646. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122647. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122648. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122649. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122650. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122651. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122652. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122653. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122654. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122655. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122656. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122657. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122658. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122659. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122660. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122661. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122662. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122663. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122664. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122665. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122666. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122667. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122668. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122669. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122670. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122671. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122672. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122673. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122674. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122675. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122676. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122677. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122678. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122679. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122680. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122681. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122682. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122683. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122684. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122685. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122686. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122687. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122688. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122689. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122690. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122691. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122692. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122693. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122694. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122695. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122696. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122697. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122698. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122699. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122700. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122701. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122702. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122703. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122704. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122705. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122706. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122707. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122708. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122709. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122710. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122711. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122712. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122713. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122714. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122715. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122716. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122717. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122718. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122719. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122720. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122721. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122722. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122723. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122724. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122725. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122726. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122727. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122728. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122729. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122730. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122731. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122732. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122733. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122734. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122735. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122736. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122737. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122738. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122739. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122740. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122741. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122742. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122743. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122744. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122745. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122746. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122747. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122748. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122749. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122750. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122751. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122752. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122753. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122754. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122755. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122756. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122757. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122758. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122759. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122760. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122761. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122762. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122763. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122764. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122765. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122766. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122767. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122768. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122769. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122770. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122771. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122772. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122773. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122774. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122775. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122776. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122777. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122778. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122779. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122780. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122781. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122782. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122783. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122784. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122785. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122786. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122787. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122788. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122789. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122790. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122791. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122792. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122793. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122794. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122795. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122796. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122797. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122798. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122799. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122800. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122801. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122802. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122803. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122804. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122805. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122806. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122807. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122808. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122809. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122810. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122811. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122812. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122813. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122814. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122815. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122816. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122817. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122818. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122819. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122820. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122821. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122822. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122823. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122824. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122825. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122826. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122827. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122828. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122829. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122830. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122831. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122832. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122833. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122834. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122835. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122836. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122837. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122838. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122839. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122840. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122841. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122842. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122843. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122844. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122845. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122846. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122847. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122848. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122849. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122850. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122851. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122852. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122853. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122854. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122855. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122856. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122857. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122858. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122859. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122860. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122861. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122862. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122863. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122864. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122865. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122866. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122867. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122868. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122869. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122870. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122871. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122872. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122873. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122874. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122875. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122876. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122877. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122878. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122879. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122880. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122881. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122882. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122883. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122884. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122885. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122886. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122887. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122888. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122889. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122890. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122891. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122892. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122893. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122894. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122895. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122896. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122897. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122898. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122899. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122900. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122901. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122902. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122903. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122904. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122905. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122906. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122907. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122908. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122909. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122910. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122911. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122912. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122913. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122914. 0,
  122915. };
  122916. static float _vq_quantthresh__44c0_sm_p1_0[] = {
  122917. -0.5, 0.5,
  122918. };
  122919. static long _vq_quantmap__44c0_sm_p1_0[] = {
  122920. 1, 0, 2,
  122921. };
  122922. static encode_aux_threshmatch _vq_auxt__44c0_sm_p1_0 = {
  122923. _vq_quantthresh__44c0_sm_p1_0,
  122924. _vq_quantmap__44c0_sm_p1_0,
  122925. 3,
  122926. 3
  122927. };
  122928. static static_codebook _44c0_sm_p1_0 = {
  122929. 8, 6561,
  122930. _vq_lengthlist__44c0_sm_p1_0,
  122931. 1, -535822336, 1611661312, 2, 0,
  122932. _vq_quantlist__44c0_sm_p1_0,
  122933. NULL,
  122934. &_vq_auxt__44c0_sm_p1_0,
  122935. NULL,
  122936. 0
  122937. };
  122938. static long _vq_quantlist__44c0_sm_p2_0[] = {
  122939. 2,
  122940. 1,
  122941. 3,
  122942. 0,
  122943. 4,
  122944. };
  122945. static long _vq_lengthlist__44c0_sm_p2_0[] = {
  122946. 1, 4, 4, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122947. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 5, 5, 7, 7, 0, 0,
  122948. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122949. 0, 0, 4, 5, 5, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122950. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 7, 7, 9, 9,
  122951. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122952. 0, 0, 0, 0, 7, 7, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0,
  122953. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122954. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122955. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122956. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122957. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122958. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122959. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122960. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122961. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122962. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122963. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122964. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122965. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122966. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122967. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122968. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122969. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122970. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122971. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122972. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122973. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122974. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122975. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122976. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122977. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122978. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122979. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122980. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122981. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122982. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122983. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122984. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122985. 0,
  122986. };
  122987. static float _vq_quantthresh__44c0_sm_p2_0[] = {
  122988. -1.5, -0.5, 0.5, 1.5,
  122989. };
  122990. static long _vq_quantmap__44c0_sm_p2_0[] = {
  122991. 3, 1, 0, 2, 4,
  122992. };
  122993. static encode_aux_threshmatch _vq_auxt__44c0_sm_p2_0 = {
  122994. _vq_quantthresh__44c0_sm_p2_0,
  122995. _vq_quantmap__44c0_sm_p2_0,
  122996. 5,
  122997. 5
  122998. };
  122999. static static_codebook _44c0_sm_p2_0 = {
  123000. 4, 625,
  123001. _vq_lengthlist__44c0_sm_p2_0,
  123002. 1, -533725184, 1611661312, 3, 0,
  123003. _vq_quantlist__44c0_sm_p2_0,
  123004. NULL,
  123005. &_vq_auxt__44c0_sm_p2_0,
  123006. NULL,
  123007. 0
  123008. };
  123009. static long _vq_quantlist__44c0_sm_p3_0[] = {
  123010. 4,
  123011. 3,
  123012. 5,
  123013. 2,
  123014. 6,
  123015. 1,
  123016. 7,
  123017. 0,
  123018. 8,
  123019. };
  123020. static long _vq_lengthlist__44c0_sm_p3_0[] = {
  123021. 1, 3, 3, 7, 7, 0, 0, 0, 0, 0, 5, 4, 7, 7, 0, 0,
  123022. 0, 0, 0, 5, 5, 7, 7, 0, 0, 0, 0, 0, 6, 7, 8, 8,
  123023. 0, 0, 0, 0, 0, 0, 0, 8, 8, 0, 0, 0, 0, 0, 0, 0,
  123024. 9,10, 0, 0, 0, 0, 0, 0, 0, 9, 9, 0, 0, 0, 0, 0,
  123025. 0, 0,11,11, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123026. 0,
  123027. };
  123028. static float _vq_quantthresh__44c0_sm_p3_0[] = {
  123029. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  123030. };
  123031. static long _vq_quantmap__44c0_sm_p3_0[] = {
  123032. 7, 5, 3, 1, 0, 2, 4, 6,
  123033. 8,
  123034. };
  123035. static encode_aux_threshmatch _vq_auxt__44c0_sm_p3_0 = {
  123036. _vq_quantthresh__44c0_sm_p3_0,
  123037. _vq_quantmap__44c0_sm_p3_0,
  123038. 9,
  123039. 9
  123040. };
  123041. static static_codebook _44c0_sm_p3_0 = {
  123042. 2, 81,
  123043. _vq_lengthlist__44c0_sm_p3_0,
  123044. 1, -531628032, 1611661312, 4, 0,
  123045. _vq_quantlist__44c0_sm_p3_0,
  123046. NULL,
  123047. &_vq_auxt__44c0_sm_p3_0,
  123048. NULL,
  123049. 0
  123050. };
  123051. static long _vq_quantlist__44c0_sm_p4_0[] = {
  123052. 4,
  123053. 3,
  123054. 5,
  123055. 2,
  123056. 6,
  123057. 1,
  123058. 7,
  123059. 0,
  123060. 8,
  123061. };
  123062. static long _vq_lengthlist__44c0_sm_p4_0[] = {
  123063. 1, 4, 3, 6, 6, 7, 7, 9, 9, 0, 5, 5, 7, 7, 8, 7,
  123064. 9, 9, 0, 5, 5, 7, 7, 8, 8, 9, 9, 0, 7, 7, 8, 8,
  123065. 8, 8,10,10, 0, 0, 0, 8, 8, 8, 8,10,10, 0, 0, 0,
  123066. 9, 9, 9, 9,11,11, 0, 0, 0, 9, 9, 9, 9,11,11, 0,
  123067. 0, 0,10,10,10,10,11,11, 0, 0, 0, 0, 0, 9, 9,11,
  123068. 11,
  123069. };
  123070. static float _vq_quantthresh__44c0_sm_p4_0[] = {
  123071. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  123072. };
  123073. static long _vq_quantmap__44c0_sm_p4_0[] = {
  123074. 7, 5, 3, 1, 0, 2, 4, 6,
  123075. 8,
  123076. };
  123077. static encode_aux_threshmatch _vq_auxt__44c0_sm_p4_0 = {
  123078. _vq_quantthresh__44c0_sm_p4_0,
  123079. _vq_quantmap__44c0_sm_p4_0,
  123080. 9,
  123081. 9
  123082. };
  123083. static static_codebook _44c0_sm_p4_0 = {
  123084. 2, 81,
  123085. _vq_lengthlist__44c0_sm_p4_0,
  123086. 1, -531628032, 1611661312, 4, 0,
  123087. _vq_quantlist__44c0_sm_p4_0,
  123088. NULL,
  123089. &_vq_auxt__44c0_sm_p4_0,
  123090. NULL,
  123091. 0
  123092. };
  123093. static long _vq_quantlist__44c0_sm_p5_0[] = {
  123094. 8,
  123095. 7,
  123096. 9,
  123097. 6,
  123098. 10,
  123099. 5,
  123100. 11,
  123101. 4,
  123102. 12,
  123103. 3,
  123104. 13,
  123105. 2,
  123106. 14,
  123107. 1,
  123108. 15,
  123109. 0,
  123110. 16,
  123111. };
  123112. static long _vq_lengthlist__44c0_sm_p5_0[] = {
  123113. 1, 4, 4, 6, 6, 8, 8, 8, 8, 8, 8, 9, 9,10,10,11,
  123114. 11, 0, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9,10,10,10,11,
  123115. 11,11, 0, 5, 6, 7, 7, 8, 8, 9, 9, 9, 9,10,10,10,
  123116. 11,11,11, 0, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9,10,10,
  123117. 11,11,12,12, 0, 0, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,
  123118. 10,11,11,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,10,10,
  123119. 11,11,11,11,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,10,
  123120. 10,11,11,11,11,12,12, 0, 0, 0, 9, 9, 9, 9,10,10,
  123121. 10,10,11,11,12,12,12,13, 0, 0, 0, 0, 0, 9, 9,10,
  123122. 10,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9, 9,
  123123. 10,10,11,11,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9,
  123124. 9,10,10,11,10,11,11,12,12,13,13, 0, 0, 0, 0, 0,
  123125. 10,10,10,10,11,11,12,12,12,13,13,13, 0, 0, 0, 0,
  123126. 0, 0, 0,10,10,11,11,12,12,12,13,13,13, 0, 0, 0,
  123127. 0, 0, 0, 0,11,11,12,12,12,12,13,13,14,14, 0, 0,
  123128. 0, 0, 0, 0, 0,11,11,12,11,12,12,13,13,13,13, 0,
  123129. 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,13,13,14,14,
  123130. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,14,
  123131. 14,
  123132. };
  123133. static float _vq_quantthresh__44c0_sm_p5_0[] = {
  123134. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  123135. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  123136. };
  123137. static long _vq_quantmap__44c0_sm_p5_0[] = {
  123138. 15, 13, 11, 9, 7, 5, 3, 1,
  123139. 0, 2, 4, 6, 8, 10, 12, 14,
  123140. 16,
  123141. };
  123142. static encode_aux_threshmatch _vq_auxt__44c0_sm_p5_0 = {
  123143. _vq_quantthresh__44c0_sm_p5_0,
  123144. _vq_quantmap__44c0_sm_p5_0,
  123145. 17,
  123146. 17
  123147. };
  123148. static static_codebook _44c0_sm_p5_0 = {
  123149. 2, 289,
  123150. _vq_lengthlist__44c0_sm_p5_0,
  123151. 1, -529530880, 1611661312, 5, 0,
  123152. _vq_quantlist__44c0_sm_p5_0,
  123153. NULL,
  123154. &_vq_auxt__44c0_sm_p5_0,
  123155. NULL,
  123156. 0
  123157. };
  123158. static long _vq_quantlist__44c0_sm_p6_0[] = {
  123159. 1,
  123160. 0,
  123161. 2,
  123162. };
  123163. static long _vq_lengthlist__44c0_sm_p6_0[] = {
  123164. 1, 4, 4, 7, 6, 6, 7, 6, 6, 4, 7, 7,10, 9, 9,11,
  123165. 9, 9, 4, 7, 7,10, 9, 9,11, 9, 9, 7,10,10,10,11,
  123166. 11,11,10,10, 6, 9, 9,11,11,10,11,10,10, 6, 9, 9,
  123167. 11,10,11,11,10,10, 7,11,10,11,11,11,11,11,11, 6,
  123168. 9, 9,11,10,10,11,11,10, 6, 9, 9,11,10,10,11,10,
  123169. 11,
  123170. };
  123171. static float _vq_quantthresh__44c0_sm_p6_0[] = {
  123172. -5.5, 5.5,
  123173. };
  123174. static long _vq_quantmap__44c0_sm_p6_0[] = {
  123175. 1, 0, 2,
  123176. };
  123177. static encode_aux_threshmatch _vq_auxt__44c0_sm_p6_0 = {
  123178. _vq_quantthresh__44c0_sm_p6_0,
  123179. _vq_quantmap__44c0_sm_p6_0,
  123180. 3,
  123181. 3
  123182. };
  123183. static static_codebook _44c0_sm_p6_0 = {
  123184. 4, 81,
  123185. _vq_lengthlist__44c0_sm_p6_0,
  123186. 1, -529137664, 1618345984, 2, 0,
  123187. _vq_quantlist__44c0_sm_p6_0,
  123188. NULL,
  123189. &_vq_auxt__44c0_sm_p6_0,
  123190. NULL,
  123191. 0
  123192. };
  123193. static long _vq_quantlist__44c0_sm_p6_1[] = {
  123194. 5,
  123195. 4,
  123196. 6,
  123197. 3,
  123198. 7,
  123199. 2,
  123200. 8,
  123201. 1,
  123202. 9,
  123203. 0,
  123204. 10,
  123205. };
  123206. static long _vq_lengthlist__44c0_sm_p6_1[] = {
  123207. 2, 4, 4, 6, 6, 7, 7, 7, 7, 7, 8, 9, 5, 5, 6, 6,
  123208. 7, 7, 8, 8, 8, 8, 9, 5, 5, 6, 6, 7, 7, 8, 8, 8,
  123209. 8,10, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8,10,10,10, 7,
  123210. 7, 7, 7, 8, 8, 8, 8,10,10,10, 8, 8, 8, 8, 8, 8,
  123211. 8, 8,10,10,10, 8, 8, 8, 8, 8, 8, 8, 8,10,10,10,
  123212. 8, 8, 8, 8, 8, 8, 8, 8,10,10,10,10,10, 8, 8, 8,
  123213. 8, 8, 8,10,10,10,10,10, 9, 9, 8, 8, 8, 8,10,10,
  123214. 10,10,10, 8, 8, 8, 8, 8, 8,
  123215. };
  123216. static float _vq_quantthresh__44c0_sm_p6_1[] = {
  123217. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  123218. 3.5, 4.5,
  123219. };
  123220. static long _vq_quantmap__44c0_sm_p6_1[] = {
  123221. 9, 7, 5, 3, 1, 0, 2, 4,
  123222. 6, 8, 10,
  123223. };
  123224. static encode_aux_threshmatch _vq_auxt__44c0_sm_p6_1 = {
  123225. _vq_quantthresh__44c0_sm_p6_1,
  123226. _vq_quantmap__44c0_sm_p6_1,
  123227. 11,
  123228. 11
  123229. };
  123230. static static_codebook _44c0_sm_p6_1 = {
  123231. 2, 121,
  123232. _vq_lengthlist__44c0_sm_p6_1,
  123233. 1, -531365888, 1611661312, 4, 0,
  123234. _vq_quantlist__44c0_sm_p6_1,
  123235. NULL,
  123236. &_vq_auxt__44c0_sm_p6_1,
  123237. NULL,
  123238. 0
  123239. };
  123240. static long _vq_quantlist__44c0_sm_p7_0[] = {
  123241. 6,
  123242. 5,
  123243. 7,
  123244. 4,
  123245. 8,
  123246. 3,
  123247. 9,
  123248. 2,
  123249. 10,
  123250. 1,
  123251. 11,
  123252. 0,
  123253. 12,
  123254. };
  123255. static long _vq_lengthlist__44c0_sm_p7_0[] = {
  123256. 1, 4, 4, 6, 6, 7, 7, 7, 7, 8, 8, 9, 9, 7, 5, 5,
  123257. 7, 7, 8, 8, 8, 8, 9, 9,10,10, 7, 6, 5, 7, 7, 8,
  123258. 8, 8, 8, 9, 9,10,10, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  123259. 10,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  123260. 11, 0,12,12, 9, 9,10,10,10,10,11,11,11,11, 0,13,
  123261. 13, 9, 9, 9, 9,10,10,11,11,11,12, 0, 0, 0, 9,10,
  123262. 10,10,11,11,12,11,12,12, 0, 0, 0,10,10, 9, 9,11,
  123263. 11,12,12,12,12, 0, 0, 0,13,13,10,10,11,11,12,12,
  123264. 13,13, 0, 0, 0,14,14,10,10,11,11,12,12,13,13, 0,
  123265. 0, 0, 0, 0,11,12,11,11,13,12,13,13, 0, 0, 0, 0,
  123266. 0,12,12,11,11,13,12,14,14,
  123267. };
  123268. static float _vq_quantthresh__44c0_sm_p7_0[] = {
  123269. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  123270. 12.5, 17.5, 22.5, 27.5,
  123271. };
  123272. static long _vq_quantmap__44c0_sm_p7_0[] = {
  123273. 11, 9, 7, 5, 3, 1, 0, 2,
  123274. 4, 6, 8, 10, 12,
  123275. };
  123276. static encode_aux_threshmatch _vq_auxt__44c0_sm_p7_0 = {
  123277. _vq_quantthresh__44c0_sm_p7_0,
  123278. _vq_quantmap__44c0_sm_p7_0,
  123279. 13,
  123280. 13
  123281. };
  123282. static static_codebook _44c0_sm_p7_0 = {
  123283. 2, 169,
  123284. _vq_lengthlist__44c0_sm_p7_0,
  123285. 1, -526516224, 1616117760, 4, 0,
  123286. _vq_quantlist__44c0_sm_p7_0,
  123287. NULL,
  123288. &_vq_auxt__44c0_sm_p7_0,
  123289. NULL,
  123290. 0
  123291. };
  123292. static long _vq_quantlist__44c0_sm_p7_1[] = {
  123293. 2,
  123294. 1,
  123295. 3,
  123296. 0,
  123297. 4,
  123298. };
  123299. static long _vq_lengthlist__44c0_sm_p7_1[] = {
  123300. 2, 4, 4, 4, 4, 6, 5, 5, 5, 5, 6, 5, 5, 5, 5, 6,
  123301. 6, 6, 5, 5, 6, 6, 6, 5, 5,
  123302. };
  123303. static float _vq_quantthresh__44c0_sm_p7_1[] = {
  123304. -1.5, -0.5, 0.5, 1.5,
  123305. };
  123306. static long _vq_quantmap__44c0_sm_p7_1[] = {
  123307. 3, 1, 0, 2, 4,
  123308. };
  123309. static encode_aux_threshmatch _vq_auxt__44c0_sm_p7_1 = {
  123310. _vq_quantthresh__44c0_sm_p7_1,
  123311. _vq_quantmap__44c0_sm_p7_1,
  123312. 5,
  123313. 5
  123314. };
  123315. static static_codebook _44c0_sm_p7_1 = {
  123316. 2, 25,
  123317. _vq_lengthlist__44c0_sm_p7_1,
  123318. 1, -533725184, 1611661312, 3, 0,
  123319. _vq_quantlist__44c0_sm_p7_1,
  123320. NULL,
  123321. &_vq_auxt__44c0_sm_p7_1,
  123322. NULL,
  123323. 0
  123324. };
  123325. static long _vq_quantlist__44c0_sm_p8_0[] = {
  123326. 4,
  123327. 3,
  123328. 5,
  123329. 2,
  123330. 6,
  123331. 1,
  123332. 7,
  123333. 0,
  123334. 8,
  123335. };
  123336. static long _vq_lengthlist__44c0_sm_p8_0[] = {
  123337. 1, 3, 3,11,11,11,11,11,11, 3, 7, 6,11,11,11,11,
  123338. 11,11, 4, 8, 7,11,11,11,11,11,11,11,11,11,11,11,
  123339. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  123340. 11,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  123341. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  123342. 12,
  123343. };
  123344. static float _vq_quantthresh__44c0_sm_p8_0[] = {
  123345. -773.5, -552.5, -331.5, -110.5, 110.5, 331.5, 552.5, 773.5,
  123346. };
  123347. static long _vq_quantmap__44c0_sm_p8_0[] = {
  123348. 7, 5, 3, 1, 0, 2, 4, 6,
  123349. 8,
  123350. };
  123351. static encode_aux_threshmatch _vq_auxt__44c0_sm_p8_0 = {
  123352. _vq_quantthresh__44c0_sm_p8_0,
  123353. _vq_quantmap__44c0_sm_p8_0,
  123354. 9,
  123355. 9
  123356. };
  123357. static static_codebook _44c0_sm_p8_0 = {
  123358. 2, 81,
  123359. _vq_lengthlist__44c0_sm_p8_0,
  123360. 1, -516186112, 1627103232, 4, 0,
  123361. _vq_quantlist__44c0_sm_p8_0,
  123362. NULL,
  123363. &_vq_auxt__44c0_sm_p8_0,
  123364. NULL,
  123365. 0
  123366. };
  123367. static long _vq_quantlist__44c0_sm_p8_1[] = {
  123368. 6,
  123369. 5,
  123370. 7,
  123371. 4,
  123372. 8,
  123373. 3,
  123374. 9,
  123375. 2,
  123376. 10,
  123377. 1,
  123378. 11,
  123379. 0,
  123380. 12,
  123381. };
  123382. static long _vq_lengthlist__44c0_sm_p8_1[] = {
  123383. 1, 4, 4, 6, 6, 7, 7, 9, 9,10,11,12,12, 6, 5, 5,
  123384. 7, 7, 8, 8,10,10,12,11,12,12, 6, 5, 5, 7, 7, 8,
  123385. 8,10,10,12,11,12,12,17, 7, 7, 8, 8, 9, 9,10,10,
  123386. 12,12,13,13,18, 7, 7, 8, 7, 9, 9,10,10,12,12,12,
  123387. 13,19,10,10, 8, 8,10,10,11,11,12,12,13,14,19,11,
  123388. 10, 8, 7,10,10,11,11,12,12,13,12,19,19,19,10,10,
  123389. 10,10,11,11,12,12,13,13,19,19,19,11, 9,11, 9,14,
  123390. 12,13,12,13,13,19,20,18,13,14,11,11,12,12,13,13,
  123391. 14,13,20,20,20,15,13,11,10,13,11,13,13,14,13,20,
  123392. 20,20,20,20,13,14,12,12,13,13,13,13,20,20,20,20,
  123393. 20,13,13,12,12,16,13,15,13,
  123394. };
  123395. static float _vq_quantthresh__44c0_sm_p8_1[] = {
  123396. -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5, 25.5,
  123397. 42.5, 59.5, 76.5, 93.5,
  123398. };
  123399. static long _vq_quantmap__44c0_sm_p8_1[] = {
  123400. 11, 9, 7, 5, 3, 1, 0, 2,
  123401. 4, 6, 8, 10, 12,
  123402. };
  123403. static encode_aux_threshmatch _vq_auxt__44c0_sm_p8_1 = {
  123404. _vq_quantthresh__44c0_sm_p8_1,
  123405. _vq_quantmap__44c0_sm_p8_1,
  123406. 13,
  123407. 13
  123408. };
  123409. static static_codebook _44c0_sm_p8_1 = {
  123410. 2, 169,
  123411. _vq_lengthlist__44c0_sm_p8_1,
  123412. 1, -522616832, 1620115456, 4, 0,
  123413. _vq_quantlist__44c0_sm_p8_1,
  123414. NULL,
  123415. &_vq_auxt__44c0_sm_p8_1,
  123416. NULL,
  123417. 0
  123418. };
  123419. static long _vq_quantlist__44c0_sm_p8_2[] = {
  123420. 8,
  123421. 7,
  123422. 9,
  123423. 6,
  123424. 10,
  123425. 5,
  123426. 11,
  123427. 4,
  123428. 12,
  123429. 3,
  123430. 13,
  123431. 2,
  123432. 14,
  123433. 1,
  123434. 15,
  123435. 0,
  123436. 16,
  123437. };
  123438. static long _vq_lengthlist__44c0_sm_p8_2[] = {
  123439. 2, 5, 5, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8,
  123440. 8,10, 6, 6, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9, 9, 9,
  123441. 9, 9,10, 6, 6, 7, 7, 8, 7, 8, 8, 9, 9, 9, 9, 9,
  123442. 9, 9, 9,10, 7, 7, 7, 7, 8, 8, 8, 9, 9, 9, 9, 9,
  123443. 9, 9, 9, 9,10,10,10, 7, 7, 8, 8, 9, 8, 9, 9, 9,
  123444. 9,10, 9, 9,10,10,10,11, 8, 8, 8, 8, 9, 9, 9, 9,
  123445. 9, 9, 9,10, 9,10,10,10,10, 8, 8, 8, 8, 9, 9, 9,
  123446. 9, 9, 9, 9, 9,10,10,11,10,10, 8, 8, 9, 9, 9, 9,
  123447. 9, 9, 9, 9, 9, 9,10,10,10,10,10,11,11, 8, 8, 9,
  123448. 9, 9, 9, 9, 9, 9, 9, 9,10,11,11,11,11,11, 9, 9,
  123449. 9, 9, 9, 9, 9, 9,10, 9,10, 9,11,11,10,11,11, 9,
  123450. 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 9,11,11,10,11,11,
  123451. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 9,11,10,11,11,
  123452. 11,11,11, 9, 9,10, 9, 9, 9, 9, 9, 9, 9,10,11,10,
  123453. 11,11,11,11,10,10,10,10, 9, 9, 9, 9, 9, 9,10,11,
  123454. 11,11,11,11,11, 9,10, 9, 9, 9, 9, 9, 9, 9, 9,11,
  123455. 11,10,11,11,11,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9,
  123456. 10,11,10,11,11,11,11,11,11, 9, 9, 9, 9, 9, 9, 9,
  123457. 9,
  123458. };
  123459. static float _vq_quantthresh__44c0_sm_p8_2[] = {
  123460. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  123461. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  123462. };
  123463. static long _vq_quantmap__44c0_sm_p8_2[] = {
  123464. 15, 13, 11, 9, 7, 5, 3, 1,
  123465. 0, 2, 4, 6, 8, 10, 12, 14,
  123466. 16,
  123467. };
  123468. static encode_aux_threshmatch _vq_auxt__44c0_sm_p8_2 = {
  123469. _vq_quantthresh__44c0_sm_p8_2,
  123470. _vq_quantmap__44c0_sm_p8_2,
  123471. 17,
  123472. 17
  123473. };
  123474. static static_codebook _44c0_sm_p8_2 = {
  123475. 2, 289,
  123476. _vq_lengthlist__44c0_sm_p8_2,
  123477. 1, -529530880, 1611661312, 5, 0,
  123478. _vq_quantlist__44c0_sm_p8_2,
  123479. NULL,
  123480. &_vq_auxt__44c0_sm_p8_2,
  123481. NULL,
  123482. 0
  123483. };
  123484. static long _huff_lengthlist__44c0_sm_short[] = {
  123485. 6, 6,12,13,13,14,16,17,17, 4, 2, 5, 8, 7, 9,12,
  123486. 15,15, 9, 4, 5, 9, 7, 9,12,16,18,11, 6, 7, 4, 6,
  123487. 8,11,14,18,10, 5, 6, 5, 5, 7,10,14,17,10, 5, 7,
  123488. 7, 6, 7,10,13,16,11, 5, 7, 7, 7, 8,10,12,15,13,
  123489. 6, 7, 5, 5, 7, 9,12,13,16, 8, 9, 6, 6, 7, 9,10,
  123490. 12,
  123491. };
  123492. static static_codebook _huff_book__44c0_sm_short = {
  123493. 2, 81,
  123494. _huff_lengthlist__44c0_sm_short,
  123495. 0, 0, 0, 0, 0,
  123496. NULL,
  123497. NULL,
  123498. NULL,
  123499. NULL,
  123500. 0
  123501. };
  123502. static long _huff_lengthlist__44c1_s_long[] = {
  123503. 5, 5, 9,10, 9, 9,10,11,12, 5, 1, 5, 6, 6, 7,10,
  123504. 12,14, 9, 5, 6, 8, 8,10,12,14,14,10, 5, 8, 5, 6,
  123505. 8,11,13,14, 9, 5, 7, 6, 6, 8,10,12,11, 9, 7, 9,
  123506. 7, 6, 6, 7,10,10,10, 9,12, 9, 8, 7, 7,10,12,11,
  123507. 11,13,12,10, 9, 8, 9,11,11,14,15,15,13,11, 9, 9,
  123508. 11,
  123509. };
  123510. static static_codebook _huff_book__44c1_s_long = {
  123511. 2, 81,
  123512. _huff_lengthlist__44c1_s_long,
  123513. 0, 0, 0, 0, 0,
  123514. NULL,
  123515. NULL,
  123516. NULL,
  123517. NULL,
  123518. 0
  123519. };
  123520. static long _vq_quantlist__44c1_s_p1_0[] = {
  123521. 1,
  123522. 0,
  123523. 2,
  123524. };
  123525. static long _vq_lengthlist__44c1_s_p1_0[] = {
  123526. 2, 4, 4, 0, 0, 0, 0, 0, 0, 5, 7, 6, 0, 0, 0, 0,
  123527. 0, 0, 5, 6, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123528. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123529. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123530. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123531. 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0, 0,
  123532. 0, 0, 0, 7, 8, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123533. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123534. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123535. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123536. 0, 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0,
  123537. 0, 0, 0, 0, 7, 8, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123538. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123539. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123540. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123541. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123542. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123543. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123544. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123545. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123546. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123547. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123548. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123549. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123550. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123551. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123552. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123553. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123554. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123555. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123556. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123557. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123558. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123559. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123560. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123561. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123562. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123563. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123564. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123565. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123566. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123567. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123568. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123569. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123570. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123571. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 7, 7, 0, 0, 0, 0,
  123572. 0, 0, 7, 8, 8, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0,
  123573. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123574. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123575. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123576. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0, 0,
  123577. 0, 0, 0, 8, 9,10, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0,
  123578. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123579. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123580. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123581. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 8, 8, 0, 0,
  123582. 0, 0, 0, 0, 8, 9, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9,
  123583. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123584. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123585. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123586. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123587. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123588. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123589. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123590. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123591. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123592. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123593. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123594. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123595. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123596. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123597. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123598. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123599. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123600. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123601. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123602. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123603. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123604. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123605. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123606. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123607. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123608. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123609. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123610. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123611. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123612. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123613. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123614. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123615. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123616. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123617. 0, 0, 4, 7, 7, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0,
  123618. 0, 0, 0, 0, 7, 8, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123619. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123620. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123621. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123622. 0, 0, 0, 6, 8, 8, 0, 0, 0, 0, 0, 0, 8,10, 9, 0,
  123623. 0, 0, 0, 0, 0, 8, 8, 9, 0, 0, 0, 0, 0, 0, 0, 0,
  123624. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123625. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123626. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123627. 0, 0, 0, 0, 7, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9,
  123628. 0, 0, 0, 0, 0, 0, 8, 9, 9, 0, 0, 0, 0, 0, 0, 0,
  123629. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123630. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123631. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123632. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123633. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123634. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123635. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123636. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123637. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123638. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123639. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123640. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123641. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123642. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123643. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123644. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123645. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123646. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123647. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123648. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123649. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123650. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123651. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123652. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123653. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123654. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123655. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123656. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123657. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123658. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123659. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123660. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123661. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123662. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123663. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123664. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123665. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123666. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123667. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123668. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123669. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123670. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123671. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123672. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123673. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123674. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123675. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123676. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123677. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123678. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123679. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123680. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123681. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123682. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123683. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123684. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123685. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123686. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123687. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123688. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123689. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123690. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123691. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123692. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123693. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123694. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123695. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123696. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123697. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123698. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123699. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123700. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123701. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123702. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123703. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123704. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123705. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123706. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123707. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123708. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123709. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123710. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123711. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123712. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123713. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123714. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123715. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123716. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123717. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123718. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123719. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123720. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123721. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123722. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123723. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123724. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123725. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123726. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123727. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123728. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123729. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123730. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123731. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123732. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123733. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123734. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123735. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123736. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123737. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123738. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123739. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123740. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123741. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123742. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123743. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123744. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123745. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123746. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123747. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123748. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123749. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123750. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123751. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123752. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123753. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123754. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123755. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123756. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123757. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123758. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123759. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123760. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123761. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123762. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123763. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123764. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123765. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123766. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123767. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123768. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123769. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123770. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123771. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123772. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123773. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123774. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123775. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123776. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123777. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123778. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123779. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123780. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123781. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123782. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123783. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123784. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123785. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123786. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123787. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123788. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123789. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123790. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123791. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123792. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123793. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123794. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123795. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123796. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123797. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123798. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123799. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123800. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123801. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123802. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123803. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123804. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123805. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123806. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123807. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123808. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123809. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123810. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123811. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123812. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123813. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123814. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123815. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123816. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123817. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123818. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123819. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123820. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123821. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123822. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123823. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123824. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123825. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123826. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123827. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123828. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123829. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123830. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123831. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123832. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123833. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123834. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123835. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123836. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123837. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123838. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123839. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123840. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123841. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123842. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123843. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123844. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123845. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123846. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123847. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123848. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123849. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123850. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123851. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123852. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123853. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123854. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123855. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123856. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123857. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123858. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123859. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123860. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123861. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123862. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123863. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123864. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123865. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123866. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123867. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123868. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123869. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123870. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123871. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123872. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123873. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123874. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123875. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123876. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123877. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123878. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123879. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123880. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123881. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123882. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123883. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123884. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123885. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123886. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123887. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123888. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123889. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123890. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123891. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123892. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123893. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123894. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123895. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123896. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123897. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123898. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123899. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123900. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123901. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123902. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123903. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123904. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123905. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123906. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123907. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123908. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123909. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123910. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123911. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123912. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123913. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123914. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123915. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123916. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123917. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123918. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123919. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123920. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123921. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123922. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123923. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123924. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123925. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123926. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123927. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123928. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123929. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123930. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123931. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123932. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123933. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123934. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123935. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123936. 0,
  123937. };
  123938. static float _vq_quantthresh__44c1_s_p1_0[] = {
  123939. -0.5, 0.5,
  123940. };
  123941. static long _vq_quantmap__44c1_s_p1_0[] = {
  123942. 1, 0, 2,
  123943. };
  123944. static encode_aux_threshmatch _vq_auxt__44c1_s_p1_0 = {
  123945. _vq_quantthresh__44c1_s_p1_0,
  123946. _vq_quantmap__44c1_s_p1_0,
  123947. 3,
  123948. 3
  123949. };
  123950. static static_codebook _44c1_s_p1_0 = {
  123951. 8, 6561,
  123952. _vq_lengthlist__44c1_s_p1_0,
  123953. 1, -535822336, 1611661312, 2, 0,
  123954. _vq_quantlist__44c1_s_p1_0,
  123955. NULL,
  123956. &_vq_auxt__44c1_s_p1_0,
  123957. NULL,
  123958. 0
  123959. };
  123960. static long _vq_quantlist__44c1_s_p2_0[] = {
  123961. 2,
  123962. 1,
  123963. 3,
  123964. 0,
  123965. 4,
  123966. };
  123967. static long _vq_lengthlist__44c1_s_p2_0[] = {
  123968. 2, 3, 4, 6, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123969. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 4, 4, 6, 6, 0, 0,
  123970. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123971. 0, 0, 4, 4, 5, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123972. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 6, 6, 8, 8,
  123973. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123974. 0, 0, 0, 0, 6, 6, 6, 8, 8, 0, 0, 0, 0, 0, 0, 0,
  123975. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123976. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123977. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123978. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123979. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123980. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123981. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123982. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123983. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123984. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123985. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123986. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123987. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123988. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123989. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123990. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123991. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123992. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123993. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123994. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123995. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123996. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123997. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123998. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123999. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124000. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124001. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124002. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124003. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124004. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124005. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124006. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124007. 0,
  124008. };
  124009. static float _vq_quantthresh__44c1_s_p2_0[] = {
  124010. -1.5, -0.5, 0.5, 1.5,
  124011. };
  124012. static long _vq_quantmap__44c1_s_p2_0[] = {
  124013. 3, 1, 0, 2, 4,
  124014. };
  124015. static encode_aux_threshmatch _vq_auxt__44c1_s_p2_0 = {
  124016. _vq_quantthresh__44c1_s_p2_0,
  124017. _vq_quantmap__44c1_s_p2_0,
  124018. 5,
  124019. 5
  124020. };
  124021. static static_codebook _44c1_s_p2_0 = {
  124022. 4, 625,
  124023. _vq_lengthlist__44c1_s_p2_0,
  124024. 1, -533725184, 1611661312, 3, 0,
  124025. _vq_quantlist__44c1_s_p2_0,
  124026. NULL,
  124027. &_vq_auxt__44c1_s_p2_0,
  124028. NULL,
  124029. 0
  124030. };
  124031. static long _vq_quantlist__44c1_s_p3_0[] = {
  124032. 4,
  124033. 3,
  124034. 5,
  124035. 2,
  124036. 6,
  124037. 1,
  124038. 7,
  124039. 0,
  124040. 8,
  124041. };
  124042. static long _vq_lengthlist__44c1_s_p3_0[] = {
  124043. 1, 3, 2, 7, 7, 0, 0, 0, 0, 0,13,13, 6, 6, 0, 0,
  124044. 0, 0, 0,12, 0, 6, 6, 0, 0, 0, 0, 0, 0, 0, 7, 7,
  124045. 0, 0, 0, 0, 0, 0, 0, 7, 7, 0, 0, 0, 0, 0, 0, 0,
  124046. 8, 9, 0, 0, 0, 0, 0, 0, 0, 8, 8, 0, 0, 0, 0, 0,
  124047. 0, 0,11,10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124048. 0,
  124049. };
  124050. static float _vq_quantthresh__44c1_s_p3_0[] = {
  124051. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  124052. };
  124053. static long _vq_quantmap__44c1_s_p3_0[] = {
  124054. 7, 5, 3, 1, 0, 2, 4, 6,
  124055. 8,
  124056. };
  124057. static encode_aux_threshmatch _vq_auxt__44c1_s_p3_0 = {
  124058. _vq_quantthresh__44c1_s_p3_0,
  124059. _vq_quantmap__44c1_s_p3_0,
  124060. 9,
  124061. 9
  124062. };
  124063. static static_codebook _44c1_s_p3_0 = {
  124064. 2, 81,
  124065. _vq_lengthlist__44c1_s_p3_0,
  124066. 1, -531628032, 1611661312, 4, 0,
  124067. _vq_quantlist__44c1_s_p3_0,
  124068. NULL,
  124069. &_vq_auxt__44c1_s_p3_0,
  124070. NULL,
  124071. 0
  124072. };
  124073. static long _vq_quantlist__44c1_s_p4_0[] = {
  124074. 4,
  124075. 3,
  124076. 5,
  124077. 2,
  124078. 6,
  124079. 1,
  124080. 7,
  124081. 0,
  124082. 8,
  124083. };
  124084. static long _vq_lengthlist__44c1_s_p4_0[] = {
  124085. 1, 3, 3, 6, 5, 6, 6, 8, 8, 0, 0, 0, 7, 7, 7, 7,
  124086. 9, 9, 0, 0, 0, 7, 7, 7, 7, 9, 9, 0, 0, 0, 7, 7,
  124087. 8, 8,10,10, 0, 0, 0, 7, 7, 8, 8,10,10, 0, 0, 0,
  124088. 9, 9, 8, 8,10,10, 0, 0, 0, 8, 8, 8, 8,10,10, 0,
  124089. 0, 0,10,10, 9, 9,11,11, 0, 0, 0, 0, 0, 9, 9,11,
  124090. 11,
  124091. };
  124092. static float _vq_quantthresh__44c1_s_p4_0[] = {
  124093. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  124094. };
  124095. static long _vq_quantmap__44c1_s_p4_0[] = {
  124096. 7, 5, 3, 1, 0, 2, 4, 6,
  124097. 8,
  124098. };
  124099. static encode_aux_threshmatch _vq_auxt__44c1_s_p4_0 = {
  124100. _vq_quantthresh__44c1_s_p4_0,
  124101. _vq_quantmap__44c1_s_p4_0,
  124102. 9,
  124103. 9
  124104. };
  124105. static static_codebook _44c1_s_p4_0 = {
  124106. 2, 81,
  124107. _vq_lengthlist__44c1_s_p4_0,
  124108. 1, -531628032, 1611661312, 4, 0,
  124109. _vq_quantlist__44c1_s_p4_0,
  124110. NULL,
  124111. &_vq_auxt__44c1_s_p4_0,
  124112. NULL,
  124113. 0
  124114. };
  124115. static long _vq_quantlist__44c1_s_p5_0[] = {
  124116. 8,
  124117. 7,
  124118. 9,
  124119. 6,
  124120. 10,
  124121. 5,
  124122. 11,
  124123. 4,
  124124. 12,
  124125. 3,
  124126. 13,
  124127. 2,
  124128. 14,
  124129. 1,
  124130. 15,
  124131. 0,
  124132. 16,
  124133. };
  124134. static long _vq_lengthlist__44c1_s_p5_0[] = {
  124135. 1, 4, 3, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,10,11,
  124136. 11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,10,10,
  124137. 11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,10,
  124138. 10,11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  124139. 11,11,11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,
  124140. 10,11,11,12,11, 0, 0, 0, 8, 8, 9, 9, 9,10,10,10,
  124141. 10,10,11,11,12,12, 0, 0, 0, 8, 8, 9, 9,10, 9,10,
  124142. 10,10,10,11,11,12,12, 0, 0, 0, 9, 9, 9, 9,10,10,
  124143. 10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 9, 9,10,
  124144. 10,10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 9, 9,
  124145. 10,10,10,11,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9,
  124146. 9,10,10,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0,
  124147. 10,10,10,10,11,11,12,12,12,12,13,13, 0, 0, 0, 0,
  124148. 0, 0, 0,10,10,11,11,12,12,12,12,13,13, 0, 0, 0,
  124149. 0, 0, 0, 0,11,11,12,12,12,12,13,13,13,13, 0, 0,
  124150. 0, 0, 0, 0, 0,11,11,11,11,12,12,13,13,13,13, 0,
  124151. 0, 0, 0, 0, 0, 0,12,12,12,12,12,12,13,13,14,14,
  124152. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,14,
  124153. 14,
  124154. };
  124155. static float _vq_quantthresh__44c1_s_p5_0[] = {
  124156. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  124157. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  124158. };
  124159. static long _vq_quantmap__44c1_s_p5_0[] = {
  124160. 15, 13, 11, 9, 7, 5, 3, 1,
  124161. 0, 2, 4, 6, 8, 10, 12, 14,
  124162. 16,
  124163. };
  124164. static encode_aux_threshmatch _vq_auxt__44c1_s_p5_0 = {
  124165. _vq_quantthresh__44c1_s_p5_0,
  124166. _vq_quantmap__44c1_s_p5_0,
  124167. 17,
  124168. 17
  124169. };
  124170. static static_codebook _44c1_s_p5_0 = {
  124171. 2, 289,
  124172. _vq_lengthlist__44c1_s_p5_0,
  124173. 1, -529530880, 1611661312, 5, 0,
  124174. _vq_quantlist__44c1_s_p5_0,
  124175. NULL,
  124176. &_vq_auxt__44c1_s_p5_0,
  124177. NULL,
  124178. 0
  124179. };
  124180. static long _vq_quantlist__44c1_s_p6_0[] = {
  124181. 1,
  124182. 0,
  124183. 2,
  124184. };
  124185. static long _vq_lengthlist__44c1_s_p6_0[] = {
  124186. 1, 4, 4, 7, 6, 6, 7, 6, 6, 4, 7, 7,10, 9, 9,11,
  124187. 9, 9, 4, 7, 7,10, 9, 9,11, 9, 9, 6,10,10,11,11,
  124188. 11,11,10,10, 6, 9, 9,11,10,10,11,10,10, 6, 9, 9,
  124189. 11,10,11,11,10,10, 7,11,10,11,11,11,12,11,11, 7,
  124190. 9, 9,11,10,10,11,11,10, 6, 9, 9,10,10,10,12,10,
  124191. 11,
  124192. };
  124193. static float _vq_quantthresh__44c1_s_p6_0[] = {
  124194. -5.5, 5.5,
  124195. };
  124196. static long _vq_quantmap__44c1_s_p6_0[] = {
  124197. 1, 0, 2,
  124198. };
  124199. static encode_aux_threshmatch _vq_auxt__44c1_s_p6_0 = {
  124200. _vq_quantthresh__44c1_s_p6_0,
  124201. _vq_quantmap__44c1_s_p6_0,
  124202. 3,
  124203. 3
  124204. };
  124205. static static_codebook _44c1_s_p6_0 = {
  124206. 4, 81,
  124207. _vq_lengthlist__44c1_s_p6_0,
  124208. 1, -529137664, 1618345984, 2, 0,
  124209. _vq_quantlist__44c1_s_p6_0,
  124210. NULL,
  124211. &_vq_auxt__44c1_s_p6_0,
  124212. NULL,
  124213. 0
  124214. };
  124215. static long _vq_quantlist__44c1_s_p6_1[] = {
  124216. 5,
  124217. 4,
  124218. 6,
  124219. 3,
  124220. 7,
  124221. 2,
  124222. 8,
  124223. 1,
  124224. 9,
  124225. 0,
  124226. 10,
  124227. };
  124228. static long _vq_lengthlist__44c1_s_p6_1[] = {
  124229. 2, 3, 3, 6, 6, 7, 7, 7, 7, 8, 8,10,10,10, 6, 6,
  124230. 7, 7, 8, 8, 8, 8,10,10,10, 6, 6, 7, 7, 8, 8, 8,
  124231. 8,10,10,10, 7, 7, 7, 7, 8, 8, 8, 8,10,10,10, 7,
  124232. 7, 7, 7, 8, 8, 8, 8,10,10,10, 7, 7, 8, 8, 8, 8,
  124233. 8, 8,10,10,10, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10,
  124234. 8, 8, 8, 8, 8, 8, 8, 8,10,10,10,10,10, 8, 8, 8,
  124235. 8, 8, 8,10,10,10,10,10, 9, 9, 8, 8, 8, 8,10,10,
  124236. 10,10,10, 8, 8, 8, 8, 8, 8,
  124237. };
  124238. static float _vq_quantthresh__44c1_s_p6_1[] = {
  124239. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  124240. 3.5, 4.5,
  124241. };
  124242. static long _vq_quantmap__44c1_s_p6_1[] = {
  124243. 9, 7, 5, 3, 1, 0, 2, 4,
  124244. 6, 8, 10,
  124245. };
  124246. static encode_aux_threshmatch _vq_auxt__44c1_s_p6_1 = {
  124247. _vq_quantthresh__44c1_s_p6_1,
  124248. _vq_quantmap__44c1_s_p6_1,
  124249. 11,
  124250. 11
  124251. };
  124252. static static_codebook _44c1_s_p6_1 = {
  124253. 2, 121,
  124254. _vq_lengthlist__44c1_s_p6_1,
  124255. 1, -531365888, 1611661312, 4, 0,
  124256. _vq_quantlist__44c1_s_p6_1,
  124257. NULL,
  124258. &_vq_auxt__44c1_s_p6_1,
  124259. NULL,
  124260. 0
  124261. };
  124262. static long _vq_quantlist__44c1_s_p7_0[] = {
  124263. 6,
  124264. 5,
  124265. 7,
  124266. 4,
  124267. 8,
  124268. 3,
  124269. 9,
  124270. 2,
  124271. 10,
  124272. 1,
  124273. 11,
  124274. 0,
  124275. 12,
  124276. };
  124277. static long _vq_lengthlist__44c1_s_p7_0[] = {
  124278. 1, 4, 4, 6, 6, 7, 7, 7, 7, 8, 8,10, 9, 7, 5, 6,
  124279. 7, 7, 8, 8, 8, 8, 9, 9,10,10, 7, 5, 5, 7, 7, 8,
  124280. 8, 8, 8, 9, 9,10,10, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  124281. 10,10,11,10, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  124282. 11, 0,12,12, 9, 9, 9,10,10,10,11,11,11,11, 0,13,
  124283. 13, 9, 9, 9, 9,10,10,11,11,11,11, 0, 0, 0,10,10,
  124284. 10,10,11,11,12,11,12,12, 0, 0, 0,10,10,10, 9,11,
  124285. 11,12,11,13,12, 0, 0, 0,13,13,10,10,11,11,12,12,
  124286. 13,13, 0, 0, 0,14,14,10,10,11,11,12,12,13,13, 0,
  124287. 0, 0, 0, 0,11,12,11,11,12,12,14,13, 0, 0, 0, 0,
  124288. 0,12,11,11,11,13,10,14,13,
  124289. };
  124290. static float _vq_quantthresh__44c1_s_p7_0[] = {
  124291. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  124292. 12.5, 17.5, 22.5, 27.5,
  124293. };
  124294. static long _vq_quantmap__44c1_s_p7_0[] = {
  124295. 11, 9, 7, 5, 3, 1, 0, 2,
  124296. 4, 6, 8, 10, 12,
  124297. };
  124298. static encode_aux_threshmatch _vq_auxt__44c1_s_p7_0 = {
  124299. _vq_quantthresh__44c1_s_p7_0,
  124300. _vq_quantmap__44c1_s_p7_0,
  124301. 13,
  124302. 13
  124303. };
  124304. static static_codebook _44c1_s_p7_0 = {
  124305. 2, 169,
  124306. _vq_lengthlist__44c1_s_p7_0,
  124307. 1, -526516224, 1616117760, 4, 0,
  124308. _vq_quantlist__44c1_s_p7_0,
  124309. NULL,
  124310. &_vq_auxt__44c1_s_p7_0,
  124311. NULL,
  124312. 0
  124313. };
  124314. static long _vq_quantlist__44c1_s_p7_1[] = {
  124315. 2,
  124316. 1,
  124317. 3,
  124318. 0,
  124319. 4,
  124320. };
  124321. static long _vq_lengthlist__44c1_s_p7_1[] = {
  124322. 2, 3, 3, 5, 5, 6, 6, 6, 5, 5, 6, 6, 6, 5, 5, 6,
  124323. 6, 6, 5, 5, 6, 6, 6, 5, 5,
  124324. };
  124325. static float _vq_quantthresh__44c1_s_p7_1[] = {
  124326. -1.5, -0.5, 0.5, 1.5,
  124327. };
  124328. static long _vq_quantmap__44c1_s_p7_1[] = {
  124329. 3, 1, 0, 2, 4,
  124330. };
  124331. static encode_aux_threshmatch _vq_auxt__44c1_s_p7_1 = {
  124332. _vq_quantthresh__44c1_s_p7_1,
  124333. _vq_quantmap__44c1_s_p7_1,
  124334. 5,
  124335. 5
  124336. };
  124337. static static_codebook _44c1_s_p7_1 = {
  124338. 2, 25,
  124339. _vq_lengthlist__44c1_s_p7_1,
  124340. 1, -533725184, 1611661312, 3, 0,
  124341. _vq_quantlist__44c1_s_p7_1,
  124342. NULL,
  124343. &_vq_auxt__44c1_s_p7_1,
  124344. NULL,
  124345. 0
  124346. };
  124347. static long _vq_quantlist__44c1_s_p8_0[] = {
  124348. 6,
  124349. 5,
  124350. 7,
  124351. 4,
  124352. 8,
  124353. 3,
  124354. 9,
  124355. 2,
  124356. 10,
  124357. 1,
  124358. 11,
  124359. 0,
  124360. 12,
  124361. };
  124362. static long _vq_lengthlist__44c1_s_p8_0[] = {
  124363. 1, 4, 3,10,10,10,10,10,10,10,10,10,10, 4, 8, 6,
  124364. 10,10,10,10,10,10,10,10,10,10, 4, 8, 7,10,10,10,
  124365. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  124366. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  124367. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  124368. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  124369. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  124370. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  124371. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  124372. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  124373. 10,10,10,10,10,10,10,10,10,
  124374. };
  124375. static float _vq_quantthresh__44c1_s_p8_0[] = {
  124376. -1215.5, -994.5, -773.5, -552.5, -331.5, -110.5, 110.5, 331.5,
  124377. 552.5, 773.5, 994.5, 1215.5,
  124378. };
  124379. static long _vq_quantmap__44c1_s_p8_0[] = {
  124380. 11, 9, 7, 5, 3, 1, 0, 2,
  124381. 4, 6, 8, 10, 12,
  124382. };
  124383. static encode_aux_threshmatch _vq_auxt__44c1_s_p8_0 = {
  124384. _vq_quantthresh__44c1_s_p8_0,
  124385. _vq_quantmap__44c1_s_p8_0,
  124386. 13,
  124387. 13
  124388. };
  124389. static static_codebook _44c1_s_p8_0 = {
  124390. 2, 169,
  124391. _vq_lengthlist__44c1_s_p8_0,
  124392. 1, -514541568, 1627103232, 4, 0,
  124393. _vq_quantlist__44c1_s_p8_0,
  124394. NULL,
  124395. &_vq_auxt__44c1_s_p8_0,
  124396. NULL,
  124397. 0
  124398. };
  124399. static long _vq_quantlist__44c1_s_p8_1[] = {
  124400. 6,
  124401. 5,
  124402. 7,
  124403. 4,
  124404. 8,
  124405. 3,
  124406. 9,
  124407. 2,
  124408. 10,
  124409. 1,
  124410. 11,
  124411. 0,
  124412. 12,
  124413. };
  124414. static long _vq_lengthlist__44c1_s_p8_1[] = {
  124415. 1, 4, 4, 6, 5, 7, 7, 9, 9,10,10,12,12, 6, 5, 5,
  124416. 7, 7, 8, 8,10,10,12,11,12,12, 6, 5, 5, 7, 7, 8,
  124417. 8,10,10,11,11,12,12,15, 7, 7, 8, 8, 9, 9,11,11,
  124418. 12,12,13,12,15, 8, 8, 8, 7, 9, 9,10,10,12,12,13,
  124419. 13,16,11,10, 8, 8,10,10,11,11,12,12,13,13,16,11,
  124420. 11, 9, 8,11,10,11,11,12,12,13,12,16,16,16,10,11,
  124421. 10,11,12,12,12,12,13,13,16,16,16,11, 9,11, 9,14,
  124422. 12,12,12,13,13,16,16,16,12,14,11,12,12,12,13,13,
  124423. 14,13,16,16,16,15,13,12,10,13,10,13,14,13,13,16,
  124424. 16,16,16,16,13,14,12,13,13,12,13,13,16,16,16,16,
  124425. 16,13,12,12,11,14,12,15,13,
  124426. };
  124427. static float _vq_quantthresh__44c1_s_p8_1[] = {
  124428. -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5, 25.5,
  124429. 42.5, 59.5, 76.5, 93.5,
  124430. };
  124431. static long _vq_quantmap__44c1_s_p8_1[] = {
  124432. 11, 9, 7, 5, 3, 1, 0, 2,
  124433. 4, 6, 8, 10, 12,
  124434. };
  124435. static encode_aux_threshmatch _vq_auxt__44c1_s_p8_1 = {
  124436. _vq_quantthresh__44c1_s_p8_1,
  124437. _vq_quantmap__44c1_s_p8_1,
  124438. 13,
  124439. 13
  124440. };
  124441. static static_codebook _44c1_s_p8_1 = {
  124442. 2, 169,
  124443. _vq_lengthlist__44c1_s_p8_1,
  124444. 1, -522616832, 1620115456, 4, 0,
  124445. _vq_quantlist__44c1_s_p8_1,
  124446. NULL,
  124447. &_vq_auxt__44c1_s_p8_1,
  124448. NULL,
  124449. 0
  124450. };
  124451. static long _vq_quantlist__44c1_s_p8_2[] = {
  124452. 8,
  124453. 7,
  124454. 9,
  124455. 6,
  124456. 10,
  124457. 5,
  124458. 11,
  124459. 4,
  124460. 12,
  124461. 3,
  124462. 13,
  124463. 2,
  124464. 14,
  124465. 1,
  124466. 15,
  124467. 0,
  124468. 16,
  124469. };
  124470. static long _vq_lengthlist__44c1_s_p8_2[] = {
  124471. 2, 4, 4, 6, 6, 6, 6, 7, 7, 8, 8, 8, 8, 8, 8, 8,
  124472. 8,10,10,10, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9, 9, 9,
  124473. 9, 9,10,10,10, 7, 7, 8, 7, 8, 8, 9, 9, 9, 9, 9,
  124474. 9, 9, 9,10,10,10, 7, 7, 8, 8, 8, 9, 9, 9, 9, 9,
  124475. 9,10, 9, 9,10,10,10, 7, 7, 8, 8, 9, 8, 9, 9, 9,
  124476. 9,10, 9, 9,10,10,11,11, 8, 8, 8, 8, 9, 9, 9, 9,
  124477. 9, 9,10, 9, 9,10,10,10,10, 8, 8, 8, 8, 9, 9, 9,
  124478. 9, 9, 9, 9, 9,10,10,11,11,11, 8, 8, 9, 9, 9, 9,
  124479. 9, 9, 9, 9, 9, 9,10,10,10,10,11,11,11, 8, 8, 9,
  124480. 9, 9, 9,10, 9, 9, 9, 9, 9,11,11,11,11,11, 9, 9,
  124481. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,11,10,10,11,11, 9,
  124482. 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,10,11,10,11,11,
  124483. 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10, 9,10,10,11,11,
  124484. 11,11,11, 9, 9, 9,10, 9, 9, 9, 9, 9, 9,10,11,11,
  124485. 11,11,11,11,10,10,10,10, 9, 9, 9, 9, 9, 9,10,11,
  124486. 11,11,11,11,11, 9,10, 9, 9, 9, 9,10, 9, 9, 9,11,
  124487. 11,11,11,11,11,11,10,10, 9, 9, 9, 9, 9, 9,10, 9,
  124488. 11,11,10,11,11,11,11,10,11, 9, 9, 9, 9, 9, 9, 9,
  124489. 9,
  124490. };
  124491. static float _vq_quantthresh__44c1_s_p8_2[] = {
  124492. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  124493. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  124494. };
  124495. static long _vq_quantmap__44c1_s_p8_2[] = {
  124496. 15, 13, 11, 9, 7, 5, 3, 1,
  124497. 0, 2, 4, 6, 8, 10, 12, 14,
  124498. 16,
  124499. };
  124500. static encode_aux_threshmatch _vq_auxt__44c1_s_p8_2 = {
  124501. _vq_quantthresh__44c1_s_p8_2,
  124502. _vq_quantmap__44c1_s_p8_2,
  124503. 17,
  124504. 17
  124505. };
  124506. static static_codebook _44c1_s_p8_2 = {
  124507. 2, 289,
  124508. _vq_lengthlist__44c1_s_p8_2,
  124509. 1, -529530880, 1611661312, 5, 0,
  124510. _vq_quantlist__44c1_s_p8_2,
  124511. NULL,
  124512. &_vq_auxt__44c1_s_p8_2,
  124513. NULL,
  124514. 0
  124515. };
  124516. static long _huff_lengthlist__44c1_s_short[] = {
  124517. 6, 8,13,12,13,14,15,16,16, 4, 2, 4, 7, 6, 8,11,
  124518. 13,15,10, 4, 4, 8, 6, 8,11,14,17,11, 5, 6, 5, 6,
  124519. 8,12,14,17,11, 5, 5, 6, 5, 7,10,13,16,12, 6, 7,
  124520. 8, 7, 8,10,13,15,13, 8, 8, 7, 7, 8,10,12,15,15,
  124521. 7, 7, 5, 5, 7, 9,12,14,15, 8, 8, 6, 6, 7, 8,10,
  124522. 11,
  124523. };
  124524. static static_codebook _huff_book__44c1_s_short = {
  124525. 2, 81,
  124526. _huff_lengthlist__44c1_s_short,
  124527. 0, 0, 0, 0, 0,
  124528. NULL,
  124529. NULL,
  124530. NULL,
  124531. NULL,
  124532. 0
  124533. };
  124534. static long _huff_lengthlist__44c1_sm_long[] = {
  124535. 5, 4, 8,10, 9, 9,10,11,12, 4, 2, 5, 6, 6, 8,10,
  124536. 11,13, 8, 4, 6, 8, 7, 9,12,12,14,10, 6, 8, 4, 5,
  124537. 6, 9,11,12, 9, 5, 6, 5, 5, 6, 9,11,11, 9, 7, 9,
  124538. 6, 5, 5, 7,10,10,10, 9,11, 8, 7, 6, 7, 9,11,11,
  124539. 12,13,10,10, 9, 8, 9,11,11,15,15,12,13,11, 9,10,
  124540. 11,
  124541. };
  124542. static static_codebook _huff_book__44c1_sm_long = {
  124543. 2, 81,
  124544. _huff_lengthlist__44c1_sm_long,
  124545. 0, 0, 0, 0, 0,
  124546. NULL,
  124547. NULL,
  124548. NULL,
  124549. NULL,
  124550. 0
  124551. };
  124552. static long _vq_quantlist__44c1_sm_p1_0[] = {
  124553. 1,
  124554. 0,
  124555. 2,
  124556. };
  124557. static long _vq_lengthlist__44c1_sm_p1_0[] = {
  124558. 1, 5, 5, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0,
  124559. 0, 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124560. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124561. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124562. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124563. 0, 5, 8, 7, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0, 0,
  124564. 0, 0, 0, 7, 8, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124565. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124566. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124567. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124568. 0, 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 7, 9, 8, 0, 0,
  124569. 0, 0, 0, 0, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124570. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124571. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124572. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124573. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124574. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124575. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124576. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124577. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124578. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124579. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124580. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124581. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124582. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124583. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124584. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124585. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124586. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124587. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124588. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124589. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124590. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124591. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124592. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124593. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124594. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124595. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124596. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124597. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124598. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124599. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124600. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124601. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124602. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124603. 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 8, 7, 0, 0, 0, 0,
  124604. 0, 0, 8, 9, 9, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0, 0,
  124605. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124606. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124607. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124608. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0, 0,
  124609. 0, 0, 0, 9, 9,10, 0, 0, 0, 0, 0, 0, 9,10,10, 0,
  124610. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124611. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124612. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124613. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  124614. 0, 0, 0, 0, 8,10, 9, 0, 0, 0, 0, 0, 0, 9,10,10,
  124615. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124616. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124617. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124618. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124619. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124620. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124621. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124622. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124623. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124624. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124625. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124626. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124627. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124628. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124629. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124630. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124631. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124632. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124633. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124634. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124635. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124636. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124637. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124638. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124639. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124640. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124641. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124642. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124643. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124644. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124645. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124646. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124647. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124648. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124649. 0, 0, 5, 7, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0, 0,
  124650. 0, 0, 0, 0, 8, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124651. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124652. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124653. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124654. 0, 0, 0, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,10,10, 0,
  124655. 0, 0, 0, 0, 0, 8, 9,10, 0, 0, 0, 0, 0, 0, 0, 0,
  124656. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124657. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124658. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124659. 0, 0, 0, 0, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,10,10,
  124660. 0, 0, 0, 0, 0, 0, 9,10, 9, 0, 0, 0, 0, 0, 0, 0,
  124661. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124662. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124663. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124664. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124665. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124666. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124667. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124668. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124669. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124670. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124671. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124672. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124673. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124674. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124675. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124676. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124677. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124678. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124679. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124680. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124681. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124682. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124683. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124684. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124685. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124686. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124687. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124688. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124689. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124690. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124691. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124692. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124693. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124694. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124695. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124696. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124697. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124698. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124699. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124700. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124701. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124702. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124703. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124704. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124705. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124706. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124707. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124708. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124709. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124710. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124711. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124712. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124713. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124714. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124715. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124716. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124717. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124718. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124719. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124720. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124721. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124722. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124723. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124724. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124725. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124726. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124727. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124728. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124729. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124730. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124731. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124732. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124733. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124734. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124735. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124736. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124737. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124738. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124739. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124740. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124741. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124742. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124743. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124744. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124745. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124746. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124747. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124748. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124749. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124750. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124751. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124752. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124753. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124754. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124755. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124756. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124757. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124758. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124759. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124760. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124761. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124762. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124763. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124764. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124765. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124766. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124767. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124768. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124769. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124770. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124771. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124772. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124773. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124774. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124775. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124776. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124777. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124778. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124779. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124780. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124781. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124782. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124783. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124784. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124785. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124786. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124787. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124788. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124789. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124790. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124791. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124792. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124793. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124794. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124795. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124796. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124797. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124798. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124799. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124800. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124801. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124802. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124803. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124804. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124805. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124806. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124807. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124808. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124809. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124810. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124811. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124812. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124813. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124814. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124815. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124816. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124817. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124818. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124819. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124820. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124821. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124822. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124823. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124824. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124825. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124826. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124827. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124828. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124829. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124830. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124831. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124832. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124833. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124834. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124835. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124836. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124837. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124838. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124839. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124840. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124841. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124842. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124843. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124844. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124845. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124846. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124847. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124848. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124849. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124850. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124851. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124852. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124853. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124854. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124855. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124856. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124857. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124858. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124859. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124860. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124861. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124862. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124863. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124864. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124865. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124866. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124867. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124868. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124869. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124870. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124871. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124872. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124873. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124874. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124875. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124876. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124877. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124878. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124879. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124880. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124881. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124882. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124883. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124884. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124885. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124886. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124887. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124888. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124889. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124890. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124891. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124892. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124893. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124894. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124895. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124896. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124897. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124898. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124899. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124900. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124901. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124902. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124903. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124904. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124905. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124906. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124907. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124908. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124909. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124910. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124911. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124912. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124913. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124914. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124915. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124916. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124917. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124918. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124919. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124920. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124921. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124922. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124923. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124924. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124925. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124926. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124927. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124928. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124929. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124930. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124931. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124932. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124933. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124934. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124935. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124936. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124937. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124938. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124939. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124940. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124941. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124942. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124943. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124944. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124945. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124946. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124947. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124948. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124949. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124950. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124951. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124952. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124953. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124954. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124955. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124956. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124957. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124958. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124959. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124960. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124961. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124962. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124963. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124964. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124965. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124966. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124967. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124968. 0,
  124969. };
  124970. static float _vq_quantthresh__44c1_sm_p1_0[] = {
  124971. -0.5, 0.5,
  124972. };
  124973. static long _vq_quantmap__44c1_sm_p1_0[] = {
  124974. 1, 0, 2,
  124975. };
  124976. static encode_aux_threshmatch _vq_auxt__44c1_sm_p1_0 = {
  124977. _vq_quantthresh__44c1_sm_p1_0,
  124978. _vq_quantmap__44c1_sm_p1_0,
  124979. 3,
  124980. 3
  124981. };
  124982. static static_codebook _44c1_sm_p1_0 = {
  124983. 8, 6561,
  124984. _vq_lengthlist__44c1_sm_p1_0,
  124985. 1, -535822336, 1611661312, 2, 0,
  124986. _vq_quantlist__44c1_sm_p1_0,
  124987. NULL,
  124988. &_vq_auxt__44c1_sm_p1_0,
  124989. NULL,
  124990. 0
  124991. };
  124992. static long _vq_quantlist__44c1_sm_p2_0[] = {
  124993. 2,
  124994. 1,
  124995. 3,
  124996. 0,
  124997. 4,
  124998. };
  124999. static long _vq_lengthlist__44c1_sm_p2_0[] = {
  125000. 2, 3, 4, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125001. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 4, 4, 6, 6, 0, 0,
  125002. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125003. 0, 0, 4, 4, 4, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125004. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 6, 6, 9, 9,
  125005. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125006. 0, 0, 0, 0, 6, 6, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0,
  125007. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125008. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125009. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125010. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125011. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125012. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125013. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125014. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125015. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125016. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125017. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125018. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125019. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125020. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125021. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125022. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125023. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125024. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125025. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125026. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125027. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125028. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125029. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125030. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125031. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125032. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125033. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125034. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125035. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125036. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125037. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125038. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125039. 0,
  125040. };
  125041. static float _vq_quantthresh__44c1_sm_p2_0[] = {
  125042. -1.5, -0.5, 0.5, 1.5,
  125043. };
  125044. static long _vq_quantmap__44c1_sm_p2_0[] = {
  125045. 3, 1, 0, 2, 4,
  125046. };
  125047. static encode_aux_threshmatch _vq_auxt__44c1_sm_p2_0 = {
  125048. _vq_quantthresh__44c1_sm_p2_0,
  125049. _vq_quantmap__44c1_sm_p2_0,
  125050. 5,
  125051. 5
  125052. };
  125053. static static_codebook _44c1_sm_p2_0 = {
  125054. 4, 625,
  125055. _vq_lengthlist__44c1_sm_p2_0,
  125056. 1, -533725184, 1611661312, 3, 0,
  125057. _vq_quantlist__44c1_sm_p2_0,
  125058. NULL,
  125059. &_vq_auxt__44c1_sm_p2_0,
  125060. NULL,
  125061. 0
  125062. };
  125063. static long _vq_quantlist__44c1_sm_p3_0[] = {
  125064. 4,
  125065. 3,
  125066. 5,
  125067. 2,
  125068. 6,
  125069. 1,
  125070. 7,
  125071. 0,
  125072. 8,
  125073. };
  125074. static long _vq_lengthlist__44c1_sm_p3_0[] = {
  125075. 1, 3, 3, 7, 7, 0, 0, 0, 0, 0, 5, 5, 6, 6, 0, 0,
  125076. 0, 0, 0, 5, 5, 7, 7, 0, 0, 0, 0, 0, 7, 7, 7, 7,
  125077. 0, 0, 0, 0, 0, 0, 0, 7, 7, 0, 0, 0, 0, 0, 0, 0,
  125078. 8, 9, 0, 0, 0, 0, 0, 0, 0, 8, 8, 0, 0, 0, 0, 0,
  125079. 0, 0,10,10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125080. 0,
  125081. };
  125082. static float _vq_quantthresh__44c1_sm_p3_0[] = {
  125083. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  125084. };
  125085. static long _vq_quantmap__44c1_sm_p3_0[] = {
  125086. 7, 5, 3, 1, 0, 2, 4, 6,
  125087. 8,
  125088. };
  125089. static encode_aux_threshmatch _vq_auxt__44c1_sm_p3_0 = {
  125090. _vq_quantthresh__44c1_sm_p3_0,
  125091. _vq_quantmap__44c1_sm_p3_0,
  125092. 9,
  125093. 9
  125094. };
  125095. static static_codebook _44c1_sm_p3_0 = {
  125096. 2, 81,
  125097. _vq_lengthlist__44c1_sm_p3_0,
  125098. 1, -531628032, 1611661312, 4, 0,
  125099. _vq_quantlist__44c1_sm_p3_0,
  125100. NULL,
  125101. &_vq_auxt__44c1_sm_p3_0,
  125102. NULL,
  125103. 0
  125104. };
  125105. static long _vq_quantlist__44c1_sm_p4_0[] = {
  125106. 4,
  125107. 3,
  125108. 5,
  125109. 2,
  125110. 6,
  125111. 1,
  125112. 7,
  125113. 0,
  125114. 8,
  125115. };
  125116. static long _vq_lengthlist__44c1_sm_p4_0[] = {
  125117. 1, 3, 3, 6, 6, 7, 7, 9, 9, 0, 6, 6, 7, 7, 8, 8,
  125118. 9, 9, 0, 6, 6, 7, 7, 8, 8, 9, 9, 0, 7, 7, 8, 8,
  125119. 8, 8,10,10, 0, 0, 0, 8, 8, 8, 8,10,10, 0, 0, 0,
  125120. 8, 8, 9, 9,11,11, 0, 0, 0, 9, 9, 9, 9,11,11, 0,
  125121. 0, 0,10,10,10,10,11,11, 0, 0, 0, 0, 0, 9, 9,11,
  125122. 11,
  125123. };
  125124. static float _vq_quantthresh__44c1_sm_p4_0[] = {
  125125. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  125126. };
  125127. static long _vq_quantmap__44c1_sm_p4_0[] = {
  125128. 7, 5, 3, 1, 0, 2, 4, 6,
  125129. 8,
  125130. };
  125131. static encode_aux_threshmatch _vq_auxt__44c1_sm_p4_0 = {
  125132. _vq_quantthresh__44c1_sm_p4_0,
  125133. _vq_quantmap__44c1_sm_p4_0,
  125134. 9,
  125135. 9
  125136. };
  125137. static static_codebook _44c1_sm_p4_0 = {
  125138. 2, 81,
  125139. _vq_lengthlist__44c1_sm_p4_0,
  125140. 1, -531628032, 1611661312, 4, 0,
  125141. _vq_quantlist__44c1_sm_p4_0,
  125142. NULL,
  125143. &_vq_auxt__44c1_sm_p4_0,
  125144. NULL,
  125145. 0
  125146. };
  125147. static long _vq_quantlist__44c1_sm_p5_0[] = {
  125148. 8,
  125149. 7,
  125150. 9,
  125151. 6,
  125152. 10,
  125153. 5,
  125154. 11,
  125155. 4,
  125156. 12,
  125157. 3,
  125158. 13,
  125159. 2,
  125160. 14,
  125161. 1,
  125162. 15,
  125163. 0,
  125164. 16,
  125165. };
  125166. static long _vq_lengthlist__44c1_sm_p5_0[] = {
  125167. 2, 3, 3, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,10,11,
  125168. 11, 0, 5, 5, 6, 6, 8, 8, 9, 9, 9, 9,10,10,10,10,
  125169. 11,11, 0, 5, 5, 6, 6, 8, 8, 9, 9, 9, 9,10,10,10,
  125170. 10,11,11, 0, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  125171. 11,11,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,
  125172. 10,11,11,12,12, 0, 0, 0, 8, 8, 8, 8, 9, 9,10,10,
  125173. 10,11,11,11,12,12, 0, 0, 0, 8, 8, 8, 8, 9, 9,10,
  125174. 10,10,10,11,11,12,12, 0, 0, 0, 9, 9, 9, 9,10,10,
  125175. 10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 9, 9,10,
  125176. 10,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9, 9,
  125177. 9, 9,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9,
  125178. 9, 9, 9,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0,
  125179. 9, 9,10,10,11,11,12,12,12,12,13,13, 0, 0, 0, 0,
  125180. 0, 0, 0,10,10,11,11,12,12,12,12,13,13, 0, 0, 0,
  125181. 0, 0, 0, 0,11,11,11,11,12,12,13,13,13,13, 0, 0,
  125182. 0, 0, 0, 0, 0,11,11,11,11,12,12,13,13,13,13, 0,
  125183. 0, 0, 0, 0, 0, 0,11,11,12,12,12,12,13,13,14,14,
  125184. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,14,
  125185. 14,
  125186. };
  125187. static float _vq_quantthresh__44c1_sm_p5_0[] = {
  125188. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  125189. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  125190. };
  125191. static long _vq_quantmap__44c1_sm_p5_0[] = {
  125192. 15, 13, 11, 9, 7, 5, 3, 1,
  125193. 0, 2, 4, 6, 8, 10, 12, 14,
  125194. 16,
  125195. };
  125196. static encode_aux_threshmatch _vq_auxt__44c1_sm_p5_0 = {
  125197. _vq_quantthresh__44c1_sm_p5_0,
  125198. _vq_quantmap__44c1_sm_p5_0,
  125199. 17,
  125200. 17
  125201. };
  125202. static static_codebook _44c1_sm_p5_0 = {
  125203. 2, 289,
  125204. _vq_lengthlist__44c1_sm_p5_0,
  125205. 1, -529530880, 1611661312, 5, 0,
  125206. _vq_quantlist__44c1_sm_p5_0,
  125207. NULL,
  125208. &_vq_auxt__44c1_sm_p5_0,
  125209. NULL,
  125210. 0
  125211. };
  125212. static long _vq_quantlist__44c1_sm_p6_0[] = {
  125213. 1,
  125214. 0,
  125215. 2,
  125216. };
  125217. static long _vq_lengthlist__44c1_sm_p6_0[] = {
  125218. 1, 4, 4, 7, 6, 6, 7, 6, 6, 4, 7, 7,10, 9, 9,11,
  125219. 9, 9, 4, 7, 7,10, 9, 9,11, 9, 9, 7,10,10,10,11,
  125220. 11,11,10,10, 6, 9, 9,11,11,10,11,10,10, 6, 9, 9,
  125221. 11,10,11,11,10,10, 7,11,11,11,11,11,11,11,11, 6,
  125222. 9, 9,11,10,10,11,11,10, 6, 9, 9,10,10,10,11,10,
  125223. 11,
  125224. };
  125225. static float _vq_quantthresh__44c1_sm_p6_0[] = {
  125226. -5.5, 5.5,
  125227. };
  125228. static long _vq_quantmap__44c1_sm_p6_0[] = {
  125229. 1, 0, 2,
  125230. };
  125231. static encode_aux_threshmatch _vq_auxt__44c1_sm_p6_0 = {
  125232. _vq_quantthresh__44c1_sm_p6_0,
  125233. _vq_quantmap__44c1_sm_p6_0,
  125234. 3,
  125235. 3
  125236. };
  125237. static static_codebook _44c1_sm_p6_0 = {
  125238. 4, 81,
  125239. _vq_lengthlist__44c1_sm_p6_0,
  125240. 1, -529137664, 1618345984, 2, 0,
  125241. _vq_quantlist__44c1_sm_p6_0,
  125242. NULL,
  125243. &_vq_auxt__44c1_sm_p6_0,
  125244. NULL,
  125245. 0
  125246. };
  125247. static long _vq_quantlist__44c1_sm_p6_1[] = {
  125248. 5,
  125249. 4,
  125250. 6,
  125251. 3,
  125252. 7,
  125253. 2,
  125254. 8,
  125255. 1,
  125256. 9,
  125257. 0,
  125258. 10,
  125259. };
  125260. static long _vq_lengthlist__44c1_sm_p6_1[] = {
  125261. 2, 4, 4, 6, 6, 7, 7, 7, 7, 8, 8,10, 5, 5, 6, 6,
  125262. 7, 7, 8, 8, 8, 8,10, 5, 5, 6, 6, 7, 7, 8, 8, 8,
  125263. 8,10, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10, 7,
  125264. 7, 7, 7, 8, 8, 8, 8,10,10,10, 7, 7, 8, 8, 8, 8,
  125265. 8, 8,10,10,10, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10,
  125266. 8, 8, 8, 8, 8, 8, 9, 8,10,10,10,10,10, 8, 8, 8,
  125267. 8, 8, 8,10,10,10,10,10, 9, 9, 8, 8, 8, 8,10,10,
  125268. 10,10,10, 8, 8, 8, 8, 8, 8,
  125269. };
  125270. static float _vq_quantthresh__44c1_sm_p6_1[] = {
  125271. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  125272. 3.5, 4.5,
  125273. };
  125274. static long _vq_quantmap__44c1_sm_p6_1[] = {
  125275. 9, 7, 5, 3, 1, 0, 2, 4,
  125276. 6, 8, 10,
  125277. };
  125278. static encode_aux_threshmatch _vq_auxt__44c1_sm_p6_1 = {
  125279. _vq_quantthresh__44c1_sm_p6_1,
  125280. _vq_quantmap__44c1_sm_p6_1,
  125281. 11,
  125282. 11
  125283. };
  125284. static static_codebook _44c1_sm_p6_1 = {
  125285. 2, 121,
  125286. _vq_lengthlist__44c1_sm_p6_1,
  125287. 1, -531365888, 1611661312, 4, 0,
  125288. _vq_quantlist__44c1_sm_p6_1,
  125289. NULL,
  125290. &_vq_auxt__44c1_sm_p6_1,
  125291. NULL,
  125292. 0
  125293. };
  125294. static long _vq_quantlist__44c1_sm_p7_0[] = {
  125295. 6,
  125296. 5,
  125297. 7,
  125298. 4,
  125299. 8,
  125300. 3,
  125301. 9,
  125302. 2,
  125303. 10,
  125304. 1,
  125305. 11,
  125306. 0,
  125307. 12,
  125308. };
  125309. static long _vq_lengthlist__44c1_sm_p7_0[] = {
  125310. 1, 4, 4, 6, 6, 7, 7, 7, 7, 8, 8, 9, 9, 7, 5, 5,
  125311. 7, 7, 8, 8, 8, 8, 9, 9,10,10, 7, 5, 6, 7, 7, 8,
  125312. 8, 8, 8, 9, 9,11,10, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  125313. 10,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  125314. 11, 0,12,12, 9, 9,10,10,10,10,11,11,11,11, 0,13,
  125315. 13, 9, 9, 9, 9,10,10,11,11,12,12, 0, 0, 0, 9,10,
  125316. 9,10,11,11,12,11,13,12, 0, 0, 0,10,10, 9, 9,11,
  125317. 11,12,12,13,12, 0, 0, 0,13,13,10,10,11,11,12,12,
  125318. 13,13, 0, 0, 0,14,14,10,10,11,11,12,12,13,13, 0,
  125319. 0, 0, 0, 0,11,12,11,11,12,13,14,13, 0, 0, 0, 0,
  125320. 0,12,12,11,11,13,12,14,13,
  125321. };
  125322. static float _vq_quantthresh__44c1_sm_p7_0[] = {
  125323. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  125324. 12.5, 17.5, 22.5, 27.5,
  125325. };
  125326. static long _vq_quantmap__44c1_sm_p7_0[] = {
  125327. 11, 9, 7, 5, 3, 1, 0, 2,
  125328. 4, 6, 8, 10, 12,
  125329. };
  125330. static encode_aux_threshmatch _vq_auxt__44c1_sm_p7_0 = {
  125331. _vq_quantthresh__44c1_sm_p7_0,
  125332. _vq_quantmap__44c1_sm_p7_0,
  125333. 13,
  125334. 13
  125335. };
  125336. static static_codebook _44c1_sm_p7_0 = {
  125337. 2, 169,
  125338. _vq_lengthlist__44c1_sm_p7_0,
  125339. 1, -526516224, 1616117760, 4, 0,
  125340. _vq_quantlist__44c1_sm_p7_0,
  125341. NULL,
  125342. &_vq_auxt__44c1_sm_p7_0,
  125343. NULL,
  125344. 0
  125345. };
  125346. static long _vq_quantlist__44c1_sm_p7_1[] = {
  125347. 2,
  125348. 1,
  125349. 3,
  125350. 0,
  125351. 4,
  125352. };
  125353. static long _vq_lengthlist__44c1_sm_p7_1[] = {
  125354. 2, 4, 4, 4, 5, 6, 5, 5, 5, 5, 6, 5, 5, 5, 5, 6,
  125355. 5, 5, 5, 5, 6, 6, 6, 5, 5,
  125356. };
  125357. static float _vq_quantthresh__44c1_sm_p7_1[] = {
  125358. -1.5, -0.5, 0.5, 1.5,
  125359. };
  125360. static long _vq_quantmap__44c1_sm_p7_1[] = {
  125361. 3, 1, 0, 2, 4,
  125362. };
  125363. static encode_aux_threshmatch _vq_auxt__44c1_sm_p7_1 = {
  125364. _vq_quantthresh__44c1_sm_p7_1,
  125365. _vq_quantmap__44c1_sm_p7_1,
  125366. 5,
  125367. 5
  125368. };
  125369. static static_codebook _44c1_sm_p7_1 = {
  125370. 2, 25,
  125371. _vq_lengthlist__44c1_sm_p7_1,
  125372. 1, -533725184, 1611661312, 3, 0,
  125373. _vq_quantlist__44c1_sm_p7_1,
  125374. NULL,
  125375. &_vq_auxt__44c1_sm_p7_1,
  125376. NULL,
  125377. 0
  125378. };
  125379. static long _vq_quantlist__44c1_sm_p8_0[] = {
  125380. 6,
  125381. 5,
  125382. 7,
  125383. 4,
  125384. 8,
  125385. 3,
  125386. 9,
  125387. 2,
  125388. 10,
  125389. 1,
  125390. 11,
  125391. 0,
  125392. 12,
  125393. };
  125394. static long _vq_lengthlist__44c1_sm_p8_0[] = {
  125395. 1, 3, 3,13,13,13,13,13,13,13,13,13,13, 3, 6, 6,
  125396. 13,13,13,13,13,13,13,13,13,13, 4, 8, 7,13,13,13,
  125397. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  125398. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  125399. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  125400. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  125401. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  125402. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  125403. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  125404. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  125405. 13,13,13,13,13,13,13,13,13,
  125406. };
  125407. static float _vq_quantthresh__44c1_sm_p8_0[] = {
  125408. -1215.5, -994.5, -773.5, -552.5, -331.5, -110.5, 110.5, 331.5,
  125409. 552.5, 773.5, 994.5, 1215.5,
  125410. };
  125411. static long _vq_quantmap__44c1_sm_p8_0[] = {
  125412. 11, 9, 7, 5, 3, 1, 0, 2,
  125413. 4, 6, 8, 10, 12,
  125414. };
  125415. static encode_aux_threshmatch _vq_auxt__44c1_sm_p8_0 = {
  125416. _vq_quantthresh__44c1_sm_p8_0,
  125417. _vq_quantmap__44c1_sm_p8_0,
  125418. 13,
  125419. 13
  125420. };
  125421. static static_codebook _44c1_sm_p8_0 = {
  125422. 2, 169,
  125423. _vq_lengthlist__44c1_sm_p8_0,
  125424. 1, -514541568, 1627103232, 4, 0,
  125425. _vq_quantlist__44c1_sm_p8_0,
  125426. NULL,
  125427. &_vq_auxt__44c1_sm_p8_0,
  125428. NULL,
  125429. 0
  125430. };
  125431. static long _vq_quantlist__44c1_sm_p8_1[] = {
  125432. 6,
  125433. 5,
  125434. 7,
  125435. 4,
  125436. 8,
  125437. 3,
  125438. 9,
  125439. 2,
  125440. 10,
  125441. 1,
  125442. 11,
  125443. 0,
  125444. 12,
  125445. };
  125446. static long _vq_lengthlist__44c1_sm_p8_1[] = {
  125447. 1, 4, 4, 6, 6, 7, 7, 9, 9,10,11,12,12, 6, 5, 5,
  125448. 7, 7, 8, 7,10,10,11,11,12,12, 6, 5, 5, 7, 7, 8,
  125449. 8,10,10,11,11,12,12,16, 7, 7, 8, 8, 9, 9,11,11,
  125450. 12,12,13,13,17, 7, 7, 8, 7, 9, 9,11,10,12,12,13,
  125451. 13,19,11,10, 8, 8,10,10,11,11,12,12,13,13,19,11,
  125452. 11, 9, 7,11,10,11,11,12,12,13,12,19,19,19,10,10,
  125453. 10,10,11,12,12,12,13,14,18,19,19,11, 9,11, 9,13,
  125454. 12,12,12,13,13,19,20,19,13,15,11,11,12,12,13,13,
  125455. 14,13,18,19,20,15,13,12,10,13,10,13,13,13,14,20,
  125456. 20,20,20,20,13,14,12,12,13,12,13,13,20,20,20,20,
  125457. 20,13,12,12,12,14,12,14,13,
  125458. };
  125459. static float _vq_quantthresh__44c1_sm_p8_1[] = {
  125460. -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5, 25.5,
  125461. 42.5, 59.5, 76.5, 93.5,
  125462. };
  125463. static long _vq_quantmap__44c1_sm_p8_1[] = {
  125464. 11, 9, 7, 5, 3, 1, 0, 2,
  125465. 4, 6, 8, 10, 12,
  125466. };
  125467. static encode_aux_threshmatch _vq_auxt__44c1_sm_p8_1 = {
  125468. _vq_quantthresh__44c1_sm_p8_1,
  125469. _vq_quantmap__44c1_sm_p8_1,
  125470. 13,
  125471. 13
  125472. };
  125473. static static_codebook _44c1_sm_p8_1 = {
  125474. 2, 169,
  125475. _vq_lengthlist__44c1_sm_p8_1,
  125476. 1, -522616832, 1620115456, 4, 0,
  125477. _vq_quantlist__44c1_sm_p8_1,
  125478. NULL,
  125479. &_vq_auxt__44c1_sm_p8_1,
  125480. NULL,
  125481. 0
  125482. };
  125483. static long _vq_quantlist__44c1_sm_p8_2[] = {
  125484. 8,
  125485. 7,
  125486. 9,
  125487. 6,
  125488. 10,
  125489. 5,
  125490. 11,
  125491. 4,
  125492. 12,
  125493. 3,
  125494. 13,
  125495. 2,
  125496. 14,
  125497. 1,
  125498. 15,
  125499. 0,
  125500. 16,
  125501. };
  125502. static long _vq_lengthlist__44c1_sm_p8_2[] = {
  125503. 2, 5, 5, 6, 6, 7, 6, 7, 7, 8, 8, 8, 8, 8, 8, 8,
  125504. 8,10, 6, 6, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9, 9, 9,
  125505. 9, 9,10, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  125506. 9, 9, 9,10, 7, 7, 7, 7, 8, 8, 8, 9, 9, 9, 9, 9,
  125507. 9, 9, 9, 9,10,10,10, 7, 7, 8, 8, 9, 9, 9, 9, 9,
  125508. 9, 9, 9, 9, 9,10,11,11, 8, 8, 8, 8, 9, 9, 9, 9,
  125509. 9, 9,10,10, 9,10,10,10,10, 8, 8, 8, 8, 9, 9, 9,
  125510. 9, 9, 9, 9, 9,10,10,11,10,10, 8, 8, 9, 9, 9, 9,
  125511. 9, 9, 9, 9, 9, 9,10, 9,10,10,10,11,11, 8, 8, 9,
  125512. 9, 9, 9, 9, 9, 9, 9, 9, 9,11,11,11,11,11, 9, 9,
  125513. 9, 9, 9, 9, 9, 9,10, 9,10, 9,11,11,11,11,11, 9,
  125514. 8, 9, 9, 9, 9, 9, 9, 9,10,10, 9,11,11,10,11,11,
  125515. 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10, 9,11,11,11,11,
  125516. 11,11,11, 9, 9,10, 9, 9, 9, 9,10, 9,10,10,11,10,
  125517. 11,11,11,11, 9,10,10,10, 9, 9, 9, 9, 9, 9,10,11,
  125518. 11,11,11,11,11, 9, 9, 9, 9, 9, 9, 9, 9,10, 9,11,
  125519. 11,10,11,11,11,11,10,10, 9, 9, 9, 9, 9, 9,10, 9,
  125520. 10,11,10,11,11,11,11,11,11, 9, 9,10, 9, 9, 9, 9,
  125521. 9,
  125522. };
  125523. static float _vq_quantthresh__44c1_sm_p8_2[] = {
  125524. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  125525. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  125526. };
  125527. static long _vq_quantmap__44c1_sm_p8_2[] = {
  125528. 15, 13, 11, 9, 7, 5, 3, 1,
  125529. 0, 2, 4, 6, 8, 10, 12, 14,
  125530. 16,
  125531. };
  125532. static encode_aux_threshmatch _vq_auxt__44c1_sm_p8_2 = {
  125533. _vq_quantthresh__44c1_sm_p8_2,
  125534. _vq_quantmap__44c1_sm_p8_2,
  125535. 17,
  125536. 17
  125537. };
  125538. static static_codebook _44c1_sm_p8_2 = {
  125539. 2, 289,
  125540. _vq_lengthlist__44c1_sm_p8_2,
  125541. 1, -529530880, 1611661312, 5, 0,
  125542. _vq_quantlist__44c1_sm_p8_2,
  125543. NULL,
  125544. &_vq_auxt__44c1_sm_p8_2,
  125545. NULL,
  125546. 0
  125547. };
  125548. static long _huff_lengthlist__44c1_sm_short[] = {
  125549. 4, 7,13,14,14,15,16,18,18, 4, 2, 5, 8, 7, 9,12,
  125550. 15,15,10, 4, 5,10, 6, 8,11,15,17,12, 5, 7, 5, 6,
  125551. 8,11,14,17,11, 5, 6, 6, 5, 6, 9,13,17,12, 6, 7,
  125552. 6, 5, 6, 8,12,14,14, 7, 8, 6, 6, 7, 9,11,14,14,
  125553. 8, 9, 6, 5, 6, 9,11,13,16,10,10, 7, 6, 7, 8,10,
  125554. 11,
  125555. };
  125556. static static_codebook _huff_book__44c1_sm_short = {
  125557. 2, 81,
  125558. _huff_lengthlist__44c1_sm_short,
  125559. 0, 0, 0, 0, 0,
  125560. NULL,
  125561. NULL,
  125562. NULL,
  125563. NULL,
  125564. 0
  125565. };
  125566. static long _huff_lengthlist__44cn1_s_long[] = {
  125567. 4, 4, 7, 8, 7, 8,10,12,17, 3, 1, 6, 6, 7, 8,10,
  125568. 12,15, 7, 6, 9, 9, 9,11,12,14,17, 8, 6, 9, 6, 7,
  125569. 9,11,13,17, 7, 6, 9, 7, 7, 8, 9,12,15, 8, 8,10,
  125570. 8, 7, 7, 7,10,14, 9,10,12,10, 8, 8, 8,10,14,11,
  125571. 13,15,13,12,11,11,12,16,17,18,18,19,20,18,16,16,
  125572. 20,
  125573. };
  125574. static static_codebook _huff_book__44cn1_s_long = {
  125575. 2, 81,
  125576. _huff_lengthlist__44cn1_s_long,
  125577. 0, 0, 0, 0, 0,
  125578. NULL,
  125579. NULL,
  125580. NULL,
  125581. NULL,
  125582. 0
  125583. };
  125584. static long _vq_quantlist__44cn1_s_p1_0[] = {
  125585. 1,
  125586. 0,
  125587. 2,
  125588. };
  125589. static long _vq_lengthlist__44cn1_s_p1_0[] = {
  125590. 1, 4, 4, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0,
  125591. 0, 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125592. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125593. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125594. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125595. 0, 5, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0, 0, 0,
  125596. 0, 0, 0, 7, 9,10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125597. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125598. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125599. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125600. 0, 0, 5, 8, 8, 0, 0, 0, 0, 0, 0, 7,10, 9, 0, 0,
  125601. 0, 0, 0, 0, 8,10, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125602. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125603. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125604. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125605. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125606. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125607. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125608. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125609. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125610. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125611. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125612. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125613. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125614. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125615. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125616. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125617. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125618. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125619. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125620. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125621. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125622. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125623. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125624. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125625. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125626. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125627. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125628. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125629. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125630. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125631. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125632. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125633. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125634. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125635. 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 8, 8, 0, 0, 0, 0,
  125636. 0, 0, 8,10,10, 0, 0, 0, 0, 0, 0, 8, 9,10, 0, 0,
  125637. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125638. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125639. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125640. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7,10,10, 0, 0, 0,
  125641. 0, 0, 0, 9, 9,11, 0, 0, 0, 0, 0, 0,10,11,11, 0,
  125642. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125643. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125644. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125645. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7,10,10, 0, 0,
  125646. 0, 0, 0, 0, 9,11, 9, 0, 0, 0, 0, 0, 0,10,11,11,
  125647. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125648. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125649. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125650. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125651. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125652. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125653. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125654. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125655. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125656. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125657. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125658. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125659. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125660. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125661. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125662. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125663. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125664. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125665. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125666. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125667. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125668. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125669. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125670. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125671. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125672. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125673. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125674. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125675. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125676. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125677. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125678. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125679. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125680. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125681. 0, 0, 5, 8, 8, 0, 0, 0, 0, 0, 0, 8,10,10, 0, 0,
  125682. 0, 0, 0, 0, 8,10,10, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125683. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125684. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125685. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125686. 0, 0, 0, 7,10,10, 0, 0, 0, 0, 0, 0,10,11,11, 0,
  125687. 0, 0, 0, 0, 0, 9, 9,11, 0, 0, 0, 0, 0, 0, 0, 0,
  125688. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125689. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125690. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125691. 0, 0, 0, 0, 7,10,10, 0, 0, 0, 0, 0, 0,10,11,11,
  125692. 0, 0, 0, 0, 0, 0, 9,11, 9, 0, 0, 0, 0, 0, 0, 0,
  125693. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125694. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125695. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125696. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125697. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125698. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125699. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125700. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125701. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125702. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125703. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125704. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125705. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125706. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125707. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125708. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125709. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125710. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125711. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125712. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125713. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125714. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125715. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125716. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125717. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125718. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125719. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125720. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125721. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125722. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125723. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125724. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125725. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125726. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125727. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125728. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125729. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125730. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125731. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125732. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125733. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125734. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125735. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125736. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125737. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125738. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125739. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125740. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125741. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125742. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125743. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125744. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125745. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125746. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125747. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125748. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125749. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125750. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125751. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125752. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125753. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125754. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125755. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125756. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125757. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125758. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125759. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125760. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125761. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125762. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125763. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125764. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125765. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125766. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125767. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125768. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125769. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125770. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125771. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125772. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125773. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125774. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125775. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125776. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125777. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125778. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125779. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125780. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125781. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125782. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125783. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125784. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125785. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125786. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125787. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125788. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125789. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125790. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125791. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125792. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125793. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125794. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125795. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125796. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125797. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125798. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125799. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125800. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125801. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125802. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125803. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125804. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125805. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125806. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125807. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125808. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125809. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125810. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125811. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125812. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125813. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125814. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125815. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125816. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125817. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125818. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125819. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125820. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125821. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125822. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125823. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125824. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125825. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125826. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125827. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125828. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125829. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125830. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125831. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125832. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125833. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125834. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125835. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125836. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125837. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125838. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125839. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125840. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125841. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125842. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125843. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125844. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125845. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125846. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125847. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125848. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125849. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125850. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125851. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125852. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125853. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125854. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125855. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125856. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125857. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125858. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125859. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125860. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125861. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125862. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125863. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125864. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125865. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125866. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125867. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125868. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125869. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125870. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125871. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125872. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125873. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125874. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125875. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125876. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125877. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125878. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125879. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125880. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125881. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125882. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125883. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125884. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125885. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125886. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125887. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125888. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125889. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125890. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125891. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125892. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125893. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125894. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125895. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125896. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125897. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125898. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125899. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125900. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125901. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125902. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125903. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125904. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125905. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125906. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125907. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125908. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125909. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125910. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125911. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125912. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125913. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125914. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125915. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125916. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125917. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125918. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125919. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125920. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125921. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125922. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125923. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125924. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125925. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125926. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125927. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125928. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125929. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125930. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125931. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125932. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125933. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125934. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125935. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125936. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125937. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125938. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125939. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125940. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125941. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125942. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125943. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125944. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125945. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125946. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125947. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125948. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125949. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125950. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125951. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125952. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125953. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125954. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125955. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125956. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125957. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125958. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125959. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125960. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125961. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125962. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125963. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125964. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125965. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125966. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125967. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125968. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125969. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125970. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125971. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125972. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125973. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125974. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125975. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125976. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125977. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125978. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125979. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125980. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125981. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125982. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125983. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125984. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125985. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125986. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125987. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125988. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125989. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125990. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125991. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125992. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125993. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125994. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125995. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125996. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125997. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125998. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125999. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126000. 0,
  126001. };
  126002. static float _vq_quantthresh__44cn1_s_p1_0[] = {
  126003. -0.5, 0.5,
  126004. };
  126005. static long _vq_quantmap__44cn1_s_p1_0[] = {
  126006. 1, 0, 2,
  126007. };
  126008. static encode_aux_threshmatch _vq_auxt__44cn1_s_p1_0 = {
  126009. _vq_quantthresh__44cn1_s_p1_0,
  126010. _vq_quantmap__44cn1_s_p1_0,
  126011. 3,
  126012. 3
  126013. };
  126014. static static_codebook _44cn1_s_p1_0 = {
  126015. 8, 6561,
  126016. _vq_lengthlist__44cn1_s_p1_0,
  126017. 1, -535822336, 1611661312, 2, 0,
  126018. _vq_quantlist__44cn1_s_p1_0,
  126019. NULL,
  126020. &_vq_auxt__44cn1_s_p1_0,
  126021. NULL,
  126022. 0
  126023. };
  126024. static long _vq_quantlist__44cn1_s_p2_0[] = {
  126025. 2,
  126026. 1,
  126027. 3,
  126028. 0,
  126029. 4,
  126030. };
  126031. static long _vq_lengthlist__44cn1_s_p2_0[] = {
  126032. 1, 4, 4, 7, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126033. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 5, 5, 7, 7, 0, 0,
  126034. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126035. 0, 0, 4, 5, 5, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126036. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 7, 7, 9, 9,
  126037. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126038. 0, 0, 0, 0, 6, 7, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0,
  126039. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126040. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126041. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126042. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126043. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126044. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126045. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126046. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126047. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126048. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126049. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126050. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126051. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126052. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126053. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126054. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126055. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126056. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126057. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126058. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126059. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126060. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126061. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126062. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126063. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126064. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126065. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126066. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126067. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126068. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126069. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126070. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126071. 0,
  126072. };
  126073. static float _vq_quantthresh__44cn1_s_p2_0[] = {
  126074. -1.5, -0.5, 0.5, 1.5,
  126075. };
  126076. static long _vq_quantmap__44cn1_s_p2_0[] = {
  126077. 3, 1, 0, 2, 4,
  126078. };
  126079. static encode_aux_threshmatch _vq_auxt__44cn1_s_p2_0 = {
  126080. _vq_quantthresh__44cn1_s_p2_0,
  126081. _vq_quantmap__44cn1_s_p2_0,
  126082. 5,
  126083. 5
  126084. };
  126085. static static_codebook _44cn1_s_p2_0 = {
  126086. 4, 625,
  126087. _vq_lengthlist__44cn1_s_p2_0,
  126088. 1, -533725184, 1611661312, 3, 0,
  126089. _vq_quantlist__44cn1_s_p2_0,
  126090. NULL,
  126091. &_vq_auxt__44cn1_s_p2_0,
  126092. NULL,
  126093. 0
  126094. };
  126095. static long _vq_quantlist__44cn1_s_p3_0[] = {
  126096. 4,
  126097. 3,
  126098. 5,
  126099. 2,
  126100. 6,
  126101. 1,
  126102. 7,
  126103. 0,
  126104. 8,
  126105. };
  126106. static long _vq_lengthlist__44cn1_s_p3_0[] = {
  126107. 1, 2, 3, 7, 7, 0, 0, 0, 0, 0, 0, 0, 6, 6, 0, 0,
  126108. 0, 0, 0, 0, 0, 6, 6, 0, 0, 0, 0, 0, 0, 0, 7, 7,
  126109. 0, 0, 0, 0, 0, 0, 0, 7, 7, 0, 0, 0, 0, 0, 0, 0,
  126110. 9, 8, 0, 0, 0, 0, 0, 0, 0, 8, 8, 0, 0, 0, 0, 0,
  126111. 0, 0,10,10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126112. 0,
  126113. };
  126114. static float _vq_quantthresh__44cn1_s_p3_0[] = {
  126115. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  126116. };
  126117. static long _vq_quantmap__44cn1_s_p3_0[] = {
  126118. 7, 5, 3, 1, 0, 2, 4, 6,
  126119. 8,
  126120. };
  126121. static encode_aux_threshmatch _vq_auxt__44cn1_s_p3_0 = {
  126122. _vq_quantthresh__44cn1_s_p3_0,
  126123. _vq_quantmap__44cn1_s_p3_0,
  126124. 9,
  126125. 9
  126126. };
  126127. static static_codebook _44cn1_s_p3_0 = {
  126128. 2, 81,
  126129. _vq_lengthlist__44cn1_s_p3_0,
  126130. 1, -531628032, 1611661312, 4, 0,
  126131. _vq_quantlist__44cn1_s_p3_0,
  126132. NULL,
  126133. &_vq_auxt__44cn1_s_p3_0,
  126134. NULL,
  126135. 0
  126136. };
  126137. static long _vq_quantlist__44cn1_s_p4_0[] = {
  126138. 4,
  126139. 3,
  126140. 5,
  126141. 2,
  126142. 6,
  126143. 1,
  126144. 7,
  126145. 0,
  126146. 8,
  126147. };
  126148. static long _vq_lengthlist__44cn1_s_p4_0[] = {
  126149. 1, 3, 3, 6, 6, 6, 6, 8, 8, 0, 0, 0, 6, 6, 7, 7,
  126150. 9, 9, 0, 0, 0, 6, 6, 7, 7, 9, 9, 0, 0, 0, 7, 7,
  126151. 8, 8,10,10, 0, 0, 0, 7, 7, 8, 8,10,10, 0, 0, 0,
  126152. 9, 9, 9, 9,10,10, 0, 0, 0, 9, 9, 9, 9,10,10, 0,
  126153. 0, 0,10,10,10,10,11,11, 0, 0, 0, 0, 0,10,10,11,
  126154. 11,
  126155. };
  126156. static float _vq_quantthresh__44cn1_s_p4_0[] = {
  126157. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  126158. };
  126159. static long _vq_quantmap__44cn1_s_p4_0[] = {
  126160. 7, 5, 3, 1, 0, 2, 4, 6,
  126161. 8,
  126162. };
  126163. static encode_aux_threshmatch _vq_auxt__44cn1_s_p4_0 = {
  126164. _vq_quantthresh__44cn1_s_p4_0,
  126165. _vq_quantmap__44cn1_s_p4_0,
  126166. 9,
  126167. 9
  126168. };
  126169. static static_codebook _44cn1_s_p4_0 = {
  126170. 2, 81,
  126171. _vq_lengthlist__44cn1_s_p4_0,
  126172. 1, -531628032, 1611661312, 4, 0,
  126173. _vq_quantlist__44cn1_s_p4_0,
  126174. NULL,
  126175. &_vq_auxt__44cn1_s_p4_0,
  126176. NULL,
  126177. 0
  126178. };
  126179. static long _vq_quantlist__44cn1_s_p5_0[] = {
  126180. 8,
  126181. 7,
  126182. 9,
  126183. 6,
  126184. 10,
  126185. 5,
  126186. 11,
  126187. 4,
  126188. 12,
  126189. 3,
  126190. 13,
  126191. 2,
  126192. 14,
  126193. 1,
  126194. 15,
  126195. 0,
  126196. 16,
  126197. };
  126198. static long _vq_lengthlist__44cn1_s_p5_0[] = {
  126199. 1, 4, 3, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,10,10,
  126200. 10, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,10,10,
  126201. 11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,10,
  126202. 10,11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  126203. 11,11,11,12, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,
  126204. 10,11,11,11,11, 0, 0, 0, 8, 8, 9, 9, 9, 9,10,10,
  126205. 10,10,11,11,12,12, 0, 0, 0, 8, 8, 9, 9, 9, 9,10,
  126206. 10,10,11,11,11,12,12, 0, 0, 0, 9, 9,10, 9,10,10,
  126207. 10,10,11,11,11,11,12,12, 0, 0, 0, 0, 0, 9, 9,10,
  126208. 10,10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 9, 9,
  126209. 10,10,10,11,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9,
  126210. 9,10,10,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0,
  126211. 10,10,11,10,11,11,11,12,13,12,13,13, 0, 0, 0, 0,
  126212. 0, 0, 0,11,10,11,11,12,12,12,12,13,13, 0, 0, 0,
  126213. 0, 0, 0, 0,11,11,12,12,12,12,13,13,13,14, 0, 0,
  126214. 0, 0, 0, 0, 0,11,11,12,12,12,12,13,13,13,14, 0,
  126215. 0, 0, 0, 0, 0, 0,12,12,12,13,13,13,13,13,14,14,
  126216. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,13,12,13,13,14,
  126217. 14,
  126218. };
  126219. static float _vq_quantthresh__44cn1_s_p5_0[] = {
  126220. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  126221. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  126222. };
  126223. static long _vq_quantmap__44cn1_s_p5_0[] = {
  126224. 15, 13, 11, 9, 7, 5, 3, 1,
  126225. 0, 2, 4, 6, 8, 10, 12, 14,
  126226. 16,
  126227. };
  126228. static encode_aux_threshmatch _vq_auxt__44cn1_s_p5_0 = {
  126229. _vq_quantthresh__44cn1_s_p5_0,
  126230. _vq_quantmap__44cn1_s_p5_0,
  126231. 17,
  126232. 17
  126233. };
  126234. static static_codebook _44cn1_s_p5_0 = {
  126235. 2, 289,
  126236. _vq_lengthlist__44cn1_s_p5_0,
  126237. 1, -529530880, 1611661312, 5, 0,
  126238. _vq_quantlist__44cn1_s_p5_0,
  126239. NULL,
  126240. &_vq_auxt__44cn1_s_p5_0,
  126241. NULL,
  126242. 0
  126243. };
  126244. static long _vq_quantlist__44cn1_s_p6_0[] = {
  126245. 1,
  126246. 0,
  126247. 2,
  126248. };
  126249. static long _vq_lengthlist__44cn1_s_p6_0[] = {
  126250. 1, 4, 4, 7, 6, 6, 7, 6, 6, 4, 6, 6,10, 9, 9,11,
  126251. 9, 9, 4, 6, 6,10, 9, 9,10, 9, 9, 7,10,10,11,11,
  126252. 11,12,11,11, 7, 9, 9,11,11,10,11,10,10, 7, 9, 9,
  126253. 11,10,11,11,10,10, 7,10,10,11,11,11,12,11,11, 7,
  126254. 9, 9,11,10,10,11,10,10, 7, 9, 9,11,10,10,11,10,
  126255. 10,
  126256. };
  126257. static float _vq_quantthresh__44cn1_s_p6_0[] = {
  126258. -5.5, 5.5,
  126259. };
  126260. static long _vq_quantmap__44cn1_s_p6_0[] = {
  126261. 1, 0, 2,
  126262. };
  126263. static encode_aux_threshmatch _vq_auxt__44cn1_s_p6_0 = {
  126264. _vq_quantthresh__44cn1_s_p6_0,
  126265. _vq_quantmap__44cn1_s_p6_0,
  126266. 3,
  126267. 3
  126268. };
  126269. static static_codebook _44cn1_s_p6_0 = {
  126270. 4, 81,
  126271. _vq_lengthlist__44cn1_s_p6_0,
  126272. 1, -529137664, 1618345984, 2, 0,
  126273. _vq_quantlist__44cn1_s_p6_0,
  126274. NULL,
  126275. &_vq_auxt__44cn1_s_p6_0,
  126276. NULL,
  126277. 0
  126278. };
  126279. static long _vq_quantlist__44cn1_s_p6_1[] = {
  126280. 5,
  126281. 4,
  126282. 6,
  126283. 3,
  126284. 7,
  126285. 2,
  126286. 8,
  126287. 1,
  126288. 9,
  126289. 0,
  126290. 10,
  126291. };
  126292. static long _vq_lengthlist__44cn1_s_p6_1[] = {
  126293. 1, 4, 4, 6, 6, 7, 7, 8, 8, 8, 8,10,10,10, 7, 6,
  126294. 8, 8, 8, 8, 8, 8,10,10,10, 7, 6, 7, 7, 8, 8, 8,
  126295. 8,10,10,10, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10, 7,
  126296. 7, 8, 8, 8, 8, 8, 8,10,10,10, 8, 8, 8, 8, 9, 9,
  126297. 9, 9,10,10,10, 8, 8, 8, 8, 9, 9, 9, 9,10,10,10,
  126298. 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,10,10, 9, 9, 9,
  126299. 9, 9, 9,10,10,10,10,10, 9, 9, 9, 9, 9, 9,10,10,
  126300. 10,10,10, 9, 9, 9, 9, 9, 9,
  126301. };
  126302. static float _vq_quantthresh__44cn1_s_p6_1[] = {
  126303. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  126304. 3.5, 4.5,
  126305. };
  126306. static long _vq_quantmap__44cn1_s_p6_1[] = {
  126307. 9, 7, 5, 3, 1, 0, 2, 4,
  126308. 6, 8, 10,
  126309. };
  126310. static encode_aux_threshmatch _vq_auxt__44cn1_s_p6_1 = {
  126311. _vq_quantthresh__44cn1_s_p6_1,
  126312. _vq_quantmap__44cn1_s_p6_1,
  126313. 11,
  126314. 11
  126315. };
  126316. static static_codebook _44cn1_s_p6_1 = {
  126317. 2, 121,
  126318. _vq_lengthlist__44cn1_s_p6_1,
  126319. 1, -531365888, 1611661312, 4, 0,
  126320. _vq_quantlist__44cn1_s_p6_1,
  126321. NULL,
  126322. &_vq_auxt__44cn1_s_p6_1,
  126323. NULL,
  126324. 0
  126325. };
  126326. static long _vq_quantlist__44cn1_s_p7_0[] = {
  126327. 6,
  126328. 5,
  126329. 7,
  126330. 4,
  126331. 8,
  126332. 3,
  126333. 9,
  126334. 2,
  126335. 10,
  126336. 1,
  126337. 11,
  126338. 0,
  126339. 12,
  126340. };
  126341. static long _vq_lengthlist__44cn1_s_p7_0[] = {
  126342. 1, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9,10,10, 6, 5, 5,
  126343. 7, 7, 8, 8, 8, 8, 9, 9,11,11, 7, 5, 5, 7, 7, 8,
  126344. 8, 8, 8, 9,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  126345. 10,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  126346. 11, 0,12,12, 9, 9, 9,10,10,10,11,11,11,12, 0,13,
  126347. 13, 9, 9, 9, 9,10,10,11,11,11,12, 0, 0, 0,10,10,
  126348. 10,10,11,11,12,12,12,13, 0, 0, 0,10,10,10,10,11,
  126349. 11,12,12,13,12, 0, 0, 0,14,14,11,10,11,12,12,13,
  126350. 13,14, 0, 0, 0,15,15,11,11,12,11,12,12,14,13, 0,
  126351. 0, 0, 0, 0,12,12,12,12,13,13,14,14, 0, 0, 0, 0,
  126352. 0,13,13,12,12,13,13,13,14,
  126353. };
  126354. static float _vq_quantthresh__44cn1_s_p7_0[] = {
  126355. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  126356. 12.5, 17.5, 22.5, 27.5,
  126357. };
  126358. static long _vq_quantmap__44cn1_s_p7_0[] = {
  126359. 11, 9, 7, 5, 3, 1, 0, 2,
  126360. 4, 6, 8, 10, 12,
  126361. };
  126362. static encode_aux_threshmatch _vq_auxt__44cn1_s_p7_0 = {
  126363. _vq_quantthresh__44cn1_s_p7_0,
  126364. _vq_quantmap__44cn1_s_p7_0,
  126365. 13,
  126366. 13
  126367. };
  126368. static static_codebook _44cn1_s_p7_0 = {
  126369. 2, 169,
  126370. _vq_lengthlist__44cn1_s_p7_0,
  126371. 1, -526516224, 1616117760, 4, 0,
  126372. _vq_quantlist__44cn1_s_p7_0,
  126373. NULL,
  126374. &_vq_auxt__44cn1_s_p7_0,
  126375. NULL,
  126376. 0
  126377. };
  126378. static long _vq_quantlist__44cn1_s_p7_1[] = {
  126379. 2,
  126380. 1,
  126381. 3,
  126382. 0,
  126383. 4,
  126384. };
  126385. static long _vq_lengthlist__44cn1_s_p7_1[] = {
  126386. 2, 3, 3, 5, 5, 6, 6, 6, 5, 5, 6, 6, 6, 5, 5, 6,
  126387. 6, 6, 5, 5, 6, 6, 6, 5, 5,
  126388. };
  126389. static float _vq_quantthresh__44cn1_s_p7_1[] = {
  126390. -1.5, -0.5, 0.5, 1.5,
  126391. };
  126392. static long _vq_quantmap__44cn1_s_p7_1[] = {
  126393. 3, 1, 0, 2, 4,
  126394. };
  126395. static encode_aux_threshmatch _vq_auxt__44cn1_s_p7_1 = {
  126396. _vq_quantthresh__44cn1_s_p7_1,
  126397. _vq_quantmap__44cn1_s_p7_1,
  126398. 5,
  126399. 5
  126400. };
  126401. static static_codebook _44cn1_s_p7_1 = {
  126402. 2, 25,
  126403. _vq_lengthlist__44cn1_s_p7_1,
  126404. 1, -533725184, 1611661312, 3, 0,
  126405. _vq_quantlist__44cn1_s_p7_1,
  126406. NULL,
  126407. &_vq_auxt__44cn1_s_p7_1,
  126408. NULL,
  126409. 0
  126410. };
  126411. static long _vq_quantlist__44cn1_s_p8_0[] = {
  126412. 2,
  126413. 1,
  126414. 3,
  126415. 0,
  126416. 4,
  126417. };
  126418. static long _vq_lengthlist__44cn1_s_p8_0[] = {
  126419. 1, 7, 7,11,11, 8,11,11,11,11, 4,11, 3,11,11,11,
  126420. 11,11,11,11,11,11,11,11,11,11,11,10,11,11,11,11,
  126421. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126422. 11,11,11,10,11,11,11,11,11,11,11,11,11,11,11,11,
  126423. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126424. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126425. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126426. 11,11,11,11,11,11,11,11,11,11,11,11,11, 7,11,11,
  126427. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126428. 11,11,11,11,11,11,10,11,11,11,11,11,11,11,11,11,
  126429. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,10,
  126430. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126431. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126432. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126433. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126434. 11,11,11,11,11,11,11,11,11,11, 8,11,11,11,11,11,
  126435. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126436. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126437. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126438. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126439. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126440. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126441. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126442. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126443. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126444. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126445. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126446. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126447. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126448. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126449. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126450. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126451. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126452. 11,11,11,11,11,11,11,12,12,12,12,12,12,12,12,12,
  126453. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  126454. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  126455. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  126456. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  126457. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  126458. 12,
  126459. };
  126460. static float _vq_quantthresh__44cn1_s_p8_0[] = {
  126461. -331.5, -110.5, 110.5, 331.5,
  126462. };
  126463. static long _vq_quantmap__44cn1_s_p8_0[] = {
  126464. 3, 1, 0, 2, 4,
  126465. };
  126466. static encode_aux_threshmatch _vq_auxt__44cn1_s_p8_0 = {
  126467. _vq_quantthresh__44cn1_s_p8_0,
  126468. _vq_quantmap__44cn1_s_p8_0,
  126469. 5,
  126470. 5
  126471. };
  126472. static static_codebook _44cn1_s_p8_0 = {
  126473. 4, 625,
  126474. _vq_lengthlist__44cn1_s_p8_0,
  126475. 1, -518283264, 1627103232, 3, 0,
  126476. _vq_quantlist__44cn1_s_p8_0,
  126477. NULL,
  126478. &_vq_auxt__44cn1_s_p8_0,
  126479. NULL,
  126480. 0
  126481. };
  126482. static long _vq_quantlist__44cn1_s_p8_1[] = {
  126483. 6,
  126484. 5,
  126485. 7,
  126486. 4,
  126487. 8,
  126488. 3,
  126489. 9,
  126490. 2,
  126491. 10,
  126492. 1,
  126493. 11,
  126494. 0,
  126495. 12,
  126496. };
  126497. static long _vq_lengthlist__44cn1_s_p8_1[] = {
  126498. 1, 4, 4, 6, 6, 8, 8, 9,10,10,11,11,11, 6, 5, 5,
  126499. 7, 7, 8, 8, 9,10, 9,11,11,12, 5, 5, 5, 7, 7, 8,
  126500. 9,10,10,12,12,14,13,15, 7, 7, 8, 8, 9,10,11,11,
  126501. 10,12,10,11,15, 7, 8, 8, 8, 9, 9,11,11,13,12,12,
  126502. 13,15,10,10, 8, 8,10,10,12,12,11,14,10,10,15,11,
  126503. 11, 8, 8,10,10,12,13,13,14,15,13,15,15,15,10,10,
  126504. 10,10,12,12,13,12,13,10,15,15,15,10,10,11,10,13,
  126505. 11,13,13,15,13,15,15,15,13,13,10,11,11,11,12,10,
  126506. 14,11,15,15,14,14,13,10,10,12,11,13,13,14,14,15,
  126507. 15,15,15,15,11,11,11,11,12,11,15,12,15,15,15,15,
  126508. 15,12,12,11,11,14,12,13,14,
  126509. };
  126510. static float _vq_quantthresh__44cn1_s_p8_1[] = {
  126511. -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5, 25.5,
  126512. 42.5, 59.5, 76.5, 93.5,
  126513. };
  126514. static long _vq_quantmap__44cn1_s_p8_1[] = {
  126515. 11, 9, 7, 5, 3, 1, 0, 2,
  126516. 4, 6, 8, 10, 12,
  126517. };
  126518. static encode_aux_threshmatch _vq_auxt__44cn1_s_p8_1 = {
  126519. _vq_quantthresh__44cn1_s_p8_1,
  126520. _vq_quantmap__44cn1_s_p8_1,
  126521. 13,
  126522. 13
  126523. };
  126524. static static_codebook _44cn1_s_p8_1 = {
  126525. 2, 169,
  126526. _vq_lengthlist__44cn1_s_p8_1,
  126527. 1, -522616832, 1620115456, 4, 0,
  126528. _vq_quantlist__44cn1_s_p8_1,
  126529. NULL,
  126530. &_vq_auxt__44cn1_s_p8_1,
  126531. NULL,
  126532. 0
  126533. };
  126534. static long _vq_quantlist__44cn1_s_p8_2[] = {
  126535. 8,
  126536. 7,
  126537. 9,
  126538. 6,
  126539. 10,
  126540. 5,
  126541. 11,
  126542. 4,
  126543. 12,
  126544. 3,
  126545. 13,
  126546. 2,
  126547. 14,
  126548. 1,
  126549. 15,
  126550. 0,
  126551. 16,
  126552. };
  126553. static long _vq_lengthlist__44cn1_s_p8_2[] = {
  126554. 3, 4, 3, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9, 9, 9, 9,
  126555. 9,10,11,11, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9, 9, 9,
  126556. 9, 9,10,10,10, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9, 9,
  126557. 9, 9, 9,10,10,10, 7, 7, 7, 8, 8, 8, 9, 9, 9, 9,
  126558. 9, 9,10, 9,10,11,10, 7, 6, 7, 7, 8, 8, 9, 9, 9,
  126559. 9, 9, 9, 9,10,10,10,11, 7, 7, 8, 8, 8, 8, 9, 9,
  126560. 9, 9, 9, 9, 9, 9,10,10,10, 7, 7, 8, 8, 8, 8, 9,
  126561. 9, 9, 9, 9, 9, 9,10,11,11,11, 8, 8, 8, 8, 8, 8,
  126562. 9, 9, 9, 9, 9, 9, 9, 9,11,10,10,11,11, 8, 8, 8,
  126563. 9, 9, 9, 9, 9, 9,10, 9,10,10,10,10,11,11, 9, 9,
  126564. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,11,11,10,11,11, 9,
  126565. 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,10,11,10,11,11,
  126566. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,11,10,10,11,
  126567. 11,11,11, 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,11,11,
  126568. 10,11,11,11, 9,10,10, 9, 9, 9, 9, 9, 9, 9,10,11,
  126569. 11,11,11,11,11, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,11,
  126570. 11,11,11,11,11,11,10,10, 9, 9, 9, 9, 9, 9, 9, 9,
  126571. 11,11,11,10,11,11,11,11,11, 9, 9, 9,10, 9, 9, 9,
  126572. 9,
  126573. };
  126574. static float _vq_quantthresh__44cn1_s_p8_2[] = {
  126575. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  126576. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  126577. };
  126578. static long _vq_quantmap__44cn1_s_p8_2[] = {
  126579. 15, 13, 11, 9, 7, 5, 3, 1,
  126580. 0, 2, 4, 6, 8, 10, 12, 14,
  126581. 16,
  126582. };
  126583. static encode_aux_threshmatch _vq_auxt__44cn1_s_p8_2 = {
  126584. _vq_quantthresh__44cn1_s_p8_2,
  126585. _vq_quantmap__44cn1_s_p8_2,
  126586. 17,
  126587. 17
  126588. };
  126589. static static_codebook _44cn1_s_p8_2 = {
  126590. 2, 289,
  126591. _vq_lengthlist__44cn1_s_p8_2,
  126592. 1, -529530880, 1611661312, 5, 0,
  126593. _vq_quantlist__44cn1_s_p8_2,
  126594. NULL,
  126595. &_vq_auxt__44cn1_s_p8_2,
  126596. NULL,
  126597. 0
  126598. };
  126599. static long _huff_lengthlist__44cn1_s_short[] = {
  126600. 10, 9,12,15,12,13,16,14,16, 7, 1, 5,14, 7,10,13,
  126601. 16,16, 9, 4, 6,16, 8,11,16,16,16,14, 4, 7,16, 9,
  126602. 12,14,16,16,10, 5, 7,14, 9,12,14,15,15,13, 8, 9,
  126603. 14,10,12,13,14,15,13, 9, 9, 7, 6, 8,11,12,12,14,
  126604. 8, 8, 5, 4, 5, 8,11,12,16,10,10, 6, 5, 6, 8, 9,
  126605. 10,
  126606. };
  126607. static static_codebook _huff_book__44cn1_s_short = {
  126608. 2, 81,
  126609. _huff_lengthlist__44cn1_s_short,
  126610. 0, 0, 0, 0, 0,
  126611. NULL,
  126612. NULL,
  126613. NULL,
  126614. NULL,
  126615. 0
  126616. };
  126617. static long _huff_lengthlist__44cn1_sm_long[] = {
  126618. 3, 3, 8, 8, 8, 8,10,12,14, 3, 2, 6, 7, 7, 8,10,
  126619. 12,16, 7, 6, 7, 9, 8,10,12,14,16, 8, 6, 8, 4, 5,
  126620. 7, 9,11,13, 7, 6, 8, 5, 6, 7, 9,11,14, 8, 8,10,
  126621. 7, 7, 6, 8,10,13, 9,11,12, 9, 9, 7, 8,10,12,10,
  126622. 13,15,11,11,10, 9,10,13,13,16,17,14,15,14,13,14,
  126623. 17,
  126624. };
  126625. static static_codebook _huff_book__44cn1_sm_long = {
  126626. 2, 81,
  126627. _huff_lengthlist__44cn1_sm_long,
  126628. 0, 0, 0, 0, 0,
  126629. NULL,
  126630. NULL,
  126631. NULL,
  126632. NULL,
  126633. 0
  126634. };
  126635. static long _vq_quantlist__44cn1_sm_p1_0[] = {
  126636. 1,
  126637. 0,
  126638. 2,
  126639. };
  126640. static long _vq_lengthlist__44cn1_sm_p1_0[] = {
  126641. 1, 4, 5, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0,
  126642. 0, 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126643. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126644. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126645. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126646. 0, 5, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0, 0, 0,
  126647. 0, 0, 0, 7, 8, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126648. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126649. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126650. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126651. 0, 0, 5, 8, 8, 0, 0, 0, 0, 0, 0, 7, 9, 8, 0, 0,
  126652. 0, 0, 0, 0, 8, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126653. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126654. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126655. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126656. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126657. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126658. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126659. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126660. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126661. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126662. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126663. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126664. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126665. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126666. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126667. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126668. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126669. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126670. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126671. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126672. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126673. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126674. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126675. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126676. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126677. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126678. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126679. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126680. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126681. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126682. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126683. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126684. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126685. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126686. 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 8, 8, 0, 0, 0, 0,
  126687. 0, 0, 8,10, 9, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0, 0,
  126688. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126689. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126690. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126691. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7,10, 9, 0, 0, 0,
  126692. 0, 0, 0, 9, 9,10, 0, 0, 0, 0, 0, 0, 9,10,10, 0,
  126693. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126694. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126695. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126696. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  126697. 0, 0, 0, 0, 8,10, 9, 0, 0, 0, 0, 0, 0, 9,10,10,
  126698. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126699. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126700. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126701. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126702. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126703. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126704. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126705. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126706. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126707. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126708. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126709. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126710. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126711. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126712. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126713. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126714. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126715. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126716. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126717. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126718. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126719. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126720. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126721. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126722. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126723. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126724. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126725. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126726. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126727. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126728. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126729. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126730. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126731. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126732. 0, 0, 5, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0, 0,
  126733. 0, 0, 0, 0, 8, 9,10, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126734. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126735. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126736. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126737. 0, 0, 0, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,10,10, 0,
  126738. 0, 0, 0, 0, 0, 8, 9,10, 0, 0, 0, 0, 0, 0, 0, 0,
  126739. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126740. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126741. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126742. 0, 0, 0, 0, 7, 9,10, 0, 0, 0, 0, 0, 0, 9,10,10,
  126743. 0, 0, 0, 0, 0, 0, 9,10, 9, 0, 0, 0, 0, 0, 0, 0,
  126744. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126745. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126746. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126747. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126748. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126749. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126750. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126751. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126752. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126753. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126754. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126755. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126756. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126757. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126758. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126759. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126760. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126761. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126762. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126763. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126764. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126765. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126766. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126767. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126768. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126769. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126770. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126771. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126772. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126773. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126774. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126775. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126776. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126777. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126778. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126779. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126780. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126781. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126782. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126783. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126784. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126785. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126786. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126787. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126788. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126789. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126790. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126791. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126792. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126793. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126794. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126795. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126796. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126797. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126798. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126799. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126800. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126801. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126802. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126803. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126804. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126805. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126806. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126807. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126808. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126809. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126810. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126811. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126812. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126813. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126814. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126815. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126816. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126817. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126818. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126819. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126820. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126821. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126822. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126823. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126824. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126825. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126826. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126827. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126828. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126829. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126830. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126831. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126832. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126833. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126834. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126835. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126836. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126837. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126838. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126839. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126840. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126841. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126842. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126843. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126844. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126845. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126846. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126847. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126848. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126849. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126850. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126851. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126852. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126853. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126854. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126855. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126856. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126857. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126858. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126859. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126860. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126861. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126862. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126863. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126864. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126865. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126866. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126867. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126868. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126869. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126870. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126871. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126872. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126873. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126874. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126875. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126876. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126877. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126878. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126879. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126880. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126881. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126882. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126883. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126884. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126885. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126886. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126887. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126888. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126889. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126890. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126891. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126892. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126893. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126894. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126895. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126896. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126897. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126898. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126899. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126900. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126901. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126902. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126903. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126904. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126905. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126906. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126907. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126908. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126909. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126910. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126911. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126912. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126913. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126914. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126915. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126916. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126917. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126918. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126919. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126920. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126921. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126922. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126923. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126924. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126925. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126926. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126927. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126928. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126929. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126930. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126931. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126932. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126933. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126934. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126935. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126936. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126937. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126938. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126939. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126940. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126941. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126942. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126943. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126944. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126945. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126946. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126947. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126948. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126949. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126950. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126951. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126952. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126953. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126954. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126955. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126956. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126957. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126958. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126959. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126960. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126961. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126962. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126963. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126964. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126965. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126966. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126967. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126968. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126969. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126970. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126971. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126972. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126973. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126974. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126975. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126976. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126977. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126978. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126979. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126980. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126981. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126982. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126983. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126984. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126985. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126986. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126987. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126988. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126989. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126990. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126991. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126992. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126993. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126994. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126995. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126996. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126997. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126998. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126999. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127000. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127001. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127002. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127003. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127004. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127005. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127006. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127007. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127008. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127009. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127010. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127011. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127012. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127013. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127014. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127015. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127016. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127017. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127018. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127019. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127020. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127021. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127022. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127023. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127024. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127025. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127026. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127027. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127028. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127029. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127030. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127031. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127032. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127033. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127034. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127035. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127036. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127037. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127038. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127039. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127040. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127041. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127042. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127043. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127044. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127045. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127046. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127047. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127048. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127049. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127050. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127051. 0,
  127052. };
  127053. static float _vq_quantthresh__44cn1_sm_p1_0[] = {
  127054. -0.5, 0.5,
  127055. };
  127056. static long _vq_quantmap__44cn1_sm_p1_0[] = {
  127057. 1, 0, 2,
  127058. };
  127059. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p1_0 = {
  127060. _vq_quantthresh__44cn1_sm_p1_0,
  127061. _vq_quantmap__44cn1_sm_p1_0,
  127062. 3,
  127063. 3
  127064. };
  127065. static static_codebook _44cn1_sm_p1_0 = {
  127066. 8, 6561,
  127067. _vq_lengthlist__44cn1_sm_p1_0,
  127068. 1, -535822336, 1611661312, 2, 0,
  127069. _vq_quantlist__44cn1_sm_p1_0,
  127070. NULL,
  127071. &_vq_auxt__44cn1_sm_p1_0,
  127072. NULL,
  127073. 0
  127074. };
  127075. static long _vq_quantlist__44cn1_sm_p2_0[] = {
  127076. 2,
  127077. 1,
  127078. 3,
  127079. 0,
  127080. 4,
  127081. };
  127082. static long _vq_lengthlist__44cn1_sm_p2_0[] = {
  127083. 1, 4, 4, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127084. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 5, 5, 7, 7, 0, 0,
  127085. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127086. 0, 0, 4, 5, 5, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127087. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 7, 7, 9, 9,
  127088. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127089. 0, 0, 0, 0, 7, 7, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0,
  127090. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127091. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127092. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127093. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127094. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127095. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127096. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127097. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127098. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127099. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127100. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127101. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127102. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127103. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127104. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127105. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127106. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127107. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127108. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127109. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127110. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127111. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127112. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127113. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127114. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127115. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127116. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127117. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127118. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127119. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127120. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127121. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127122. 0,
  127123. };
  127124. static float _vq_quantthresh__44cn1_sm_p2_0[] = {
  127125. -1.5, -0.5, 0.5, 1.5,
  127126. };
  127127. static long _vq_quantmap__44cn1_sm_p2_0[] = {
  127128. 3, 1, 0, 2, 4,
  127129. };
  127130. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p2_0 = {
  127131. _vq_quantthresh__44cn1_sm_p2_0,
  127132. _vq_quantmap__44cn1_sm_p2_0,
  127133. 5,
  127134. 5
  127135. };
  127136. static static_codebook _44cn1_sm_p2_0 = {
  127137. 4, 625,
  127138. _vq_lengthlist__44cn1_sm_p2_0,
  127139. 1, -533725184, 1611661312, 3, 0,
  127140. _vq_quantlist__44cn1_sm_p2_0,
  127141. NULL,
  127142. &_vq_auxt__44cn1_sm_p2_0,
  127143. NULL,
  127144. 0
  127145. };
  127146. static long _vq_quantlist__44cn1_sm_p3_0[] = {
  127147. 4,
  127148. 3,
  127149. 5,
  127150. 2,
  127151. 6,
  127152. 1,
  127153. 7,
  127154. 0,
  127155. 8,
  127156. };
  127157. static long _vq_lengthlist__44cn1_sm_p3_0[] = {
  127158. 1, 3, 4, 7, 7, 0, 0, 0, 0, 0, 4, 4, 7, 7, 0, 0,
  127159. 0, 0, 0, 4, 5, 7, 7, 0, 0, 0, 0, 0, 6, 7, 8, 8,
  127160. 0, 0, 0, 0, 0, 0, 0, 8, 8, 0, 0, 0, 0, 0, 0, 0,
  127161. 9, 9, 0, 0, 0, 0, 0, 0, 0,10, 9, 0, 0, 0, 0, 0,
  127162. 0, 0,11,11, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127163. 0,
  127164. };
  127165. static float _vq_quantthresh__44cn1_sm_p3_0[] = {
  127166. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  127167. };
  127168. static long _vq_quantmap__44cn1_sm_p3_0[] = {
  127169. 7, 5, 3, 1, 0, 2, 4, 6,
  127170. 8,
  127171. };
  127172. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p3_0 = {
  127173. _vq_quantthresh__44cn1_sm_p3_0,
  127174. _vq_quantmap__44cn1_sm_p3_0,
  127175. 9,
  127176. 9
  127177. };
  127178. static static_codebook _44cn1_sm_p3_0 = {
  127179. 2, 81,
  127180. _vq_lengthlist__44cn1_sm_p3_0,
  127181. 1, -531628032, 1611661312, 4, 0,
  127182. _vq_quantlist__44cn1_sm_p3_0,
  127183. NULL,
  127184. &_vq_auxt__44cn1_sm_p3_0,
  127185. NULL,
  127186. 0
  127187. };
  127188. static long _vq_quantlist__44cn1_sm_p4_0[] = {
  127189. 4,
  127190. 3,
  127191. 5,
  127192. 2,
  127193. 6,
  127194. 1,
  127195. 7,
  127196. 0,
  127197. 8,
  127198. };
  127199. static long _vq_lengthlist__44cn1_sm_p4_0[] = {
  127200. 1, 4, 3, 6, 6, 7, 7, 9, 9, 0, 5, 5, 7, 7, 8, 7,
  127201. 9, 9, 0, 5, 5, 7, 7, 8, 8, 9, 9, 0, 7, 7, 8, 8,
  127202. 8, 8,10,10, 0, 0, 0, 8, 8, 8, 8,10,10, 0, 0, 0,
  127203. 9, 9, 9, 9,10,10, 0, 0, 0, 9, 9, 9, 9,10,10, 0,
  127204. 0, 0,10,10,10,10,11,11, 0, 0, 0, 0, 0,10,10,11,
  127205. 11,
  127206. };
  127207. static float _vq_quantthresh__44cn1_sm_p4_0[] = {
  127208. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  127209. };
  127210. static long _vq_quantmap__44cn1_sm_p4_0[] = {
  127211. 7, 5, 3, 1, 0, 2, 4, 6,
  127212. 8,
  127213. };
  127214. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p4_0 = {
  127215. _vq_quantthresh__44cn1_sm_p4_0,
  127216. _vq_quantmap__44cn1_sm_p4_0,
  127217. 9,
  127218. 9
  127219. };
  127220. static static_codebook _44cn1_sm_p4_0 = {
  127221. 2, 81,
  127222. _vq_lengthlist__44cn1_sm_p4_0,
  127223. 1, -531628032, 1611661312, 4, 0,
  127224. _vq_quantlist__44cn1_sm_p4_0,
  127225. NULL,
  127226. &_vq_auxt__44cn1_sm_p4_0,
  127227. NULL,
  127228. 0
  127229. };
  127230. static long _vq_quantlist__44cn1_sm_p5_0[] = {
  127231. 8,
  127232. 7,
  127233. 9,
  127234. 6,
  127235. 10,
  127236. 5,
  127237. 11,
  127238. 4,
  127239. 12,
  127240. 3,
  127241. 13,
  127242. 2,
  127243. 14,
  127244. 1,
  127245. 15,
  127246. 0,
  127247. 16,
  127248. };
  127249. static long _vq_lengthlist__44cn1_sm_p5_0[] = {
  127250. 1, 4, 4, 6, 6, 8, 8, 9, 9, 8, 8, 9, 9,10,10,11,
  127251. 11, 0, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9,10,10,11,11,
  127252. 12,12, 0, 6, 5, 7, 7, 8, 8, 9, 9, 9, 9,10,10,11,
  127253. 11,12,12, 0, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  127254. 11,11,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9,10,10,11,
  127255. 11,11,11,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,10,10,
  127256. 11,11,12,12,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,10,
  127257. 10,11,11,12,12,12,12, 0, 0, 0, 9, 9, 9, 9,10,10,
  127258. 10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9, 9,10,
  127259. 10,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9, 9,
  127260. 10,10,11,11,12,12,13,13,13,13, 0, 0, 0, 0, 0, 9,
  127261. 9,10,10,11,11,12,12,12,13,13,13, 0, 0, 0, 0, 0,
  127262. 10,10,11,11,11,11,12,12,13,13,14,14, 0, 0, 0, 0,
  127263. 0, 0, 0,11,11,11,11,12,12,13,13,14,14, 0, 0, 0,
  127264. 0, 0, 0, 0,11,11,12,12,13,13,13,13,14,14, 0, 0,
  127265. 0, 0, 0, 0, 0,11,11,12,12,13,13,13,13,14,14, 0,
  127266. 0, 0, 0, 0, 0, 0,12,12,12,13,13,13,14,14,14,14,
  127267. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,13,13,14,14,14,
  127268. 14,
  127269. };
  127270. static float _vq_quantthresh__44cn1_sm_p5_0[] = {
  127271. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  127272. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  127273. };
  127274. static long _vq_quantmap__44cn1_sm_p5_0[] = {
  127275. 15, 13, 11, 9, 7, 5, 3, 1,
  127276. 0, 2, 4, 6, 8, 10, 12, 14,
  127277. 16,
  127278. };
  127279. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p5_0 = {
  127280. _vq_quantthresh__44cn1_sm_p5_0,
  127281. _vq_quantmap__44cn1_sm_p5_0,
  127282. 17,
  127283. 17
  127284. };
  127285. static static_codebook _44cn1_sm_p5_0 = {
  127286. 2, 289,
  127287. _vq_lengthlist__44cn1_sm_p5_0,
  127288. 1, -529530880, 1611661312, 5, 0,
  127289. _vq_quantlist__44cn1_sm_p5_0,
  127290. NULL,
  127291. &_vq_auxt__44cn1_sm_p5_0,
  127292. NULL,
  127293. 0
  127294. };
  127295. static long _vq_quantlist__44cn1_sm_p6_0[] = {
  127296. 1,
  127297. 0,
  127298. 2,
  127299. };
  127300. static long _vq_lengthlist__44cn1_sm_p6_0[] = {
  127301. 1, 4, 4, 7, 6, 6, 7, 6, 6, 4, 7, 6,10, 9, 9,11,
  127302. 9, 9, 4, 6, 7,10, 9, 9,11, 9, 9, 7,10,10,10,11,
  127303. 11,11,11,10, 6, 9, 9,11,10,10,11,10,10, 6, 9, 9,
  127304. 11,10,11,11,10,10, 7,11,11,11,11,11,12,11,11, 7,
  127305. 9, 9,11,10,10,12,10,10, 7, 9, 9,11,10,10,11,10,
  127306. 10,
  127307. };
  127308. static float _vq_quantthresh__44cn1_sm_p6_0[] = {
  127309. -5.5, 5.5,
  127310. };
  127311. static long _vq_quantmap__44cn1_sm_p6_0[] = {
  127312. 1, 0, 2,
  127313. };
  127314. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p6_0 = {
  127315. _vq_quantthresh__44cn1_sm_p6_0,
  127316. _vq_quantmap__44cn1_sm_p6_0,
  127317. 3,
  127318. 3
  127319. };
  127320. static static_codebook _44cn1_sm_p6_0 = {
  127321. 4, 81,
  127322. _vq_lengthlist__44cn1_sm_p6_0,
  127323. 1, -529137664, 1618345984, 2, 0,
  127324. _vq_quantlist__44cn1_sm_p6_0,
  127325. NULL,
  127326. &_vq_auxt__44cn1_sm_p6_0,
  127327. NULL,
  127328. 0
  127329. };
  127330. static long _vq_quantlist__44cn1_sm_p6_1[] = {
  127331. 5,
  127332. 4,
  127333. 6,
  127334. 3,
  127335. 7,
  127336. 2,
  127337. 8,
  127338. 1,
  127339. 9,
  127340. 0,
  127341. 10,
  127342. };
  127343. static long _vq_lengthlist__44cn1_sm_p6_1[] = {
  127344. 2, 4, 4, 5, 5, 7, 7, 7, 7, 8, 8,10, 5, 5, 6, 6,
  127345. 7, 7, 8, 8, 8, 8,10, 5, 5, 6, 6, 7, 7, 8, 8, 8,
  127346. 8,10, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10, 7,
  127347. 7, 7, 7, 8, 8, 8, 8,10,10,10, 8, 8, 8, 8, 8, 8,
  127348. 8, 8,10,10,10, 8, 8, 8, 8, 8, 8, 8, 8,10,10,10,
  127349. 8, 8, 8, 8, 8, 8, 9, 9,10,10,10,10,10, 8, 8, 8,
  127350. 8, 9, 9,10,10,10,10,10, 9, 9, 9, 9, 8, 9,10,10,
  127351. 10,10,10, 8, 9, 8, 8, 9, 8,
  127352. };
  127353. static float _vq_quantthresh__44cn1_sm_p6_1[] = {
  127354. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  127355. 3.5, 4.5,
  127356. };
  127357. static long _vq_quantmap__44cn1_sm_p6_1[] = {
  127358. 9, 7, 5, 3, 1, 0, 2, 4,
  127359. 6, 8, 10,
  127360. };
  127361. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p6_1 = {
  127362. _vq_quantthresh__44cn1_sm_p6_1,
  127363. _vq_quantmap__44cn1_sm_p6_1,
  127364. 11,
  127365. 11
  127366. };
  127367. static static_codebook _44cn1_sm_p6_1 = {
  127368. 2, 121,
  127369. _vq_lengthlist__44cn1_sm_p6_1,
  127370. 1, -531365888, 1611661312, 4, 0,
  127371. _vq_quantlist__44cn1_sm_p6_1,
  127372. NULL,
  127373. &_vq_auxt__44cn1_sm_p6_1,
  127374. NULL,
  127375. 0
  127376. };
  127377. static long _vq_quantlist__44cn1_sm_p7_0[] = {
  127378. 6,
  127379. 5,
  127380. 7,
  127381. 4,
  127382. 8,
  127383. 3,
  127384. 9,
  127385. 2,
  127386. 10,
  127387. 1,
  127388. 11,
  127389. 0,
  127390. 12,
  127391. };
  127392. static long _vq_lengthlist__44cn1_sm_p7_0[] = {
  127393. 1, 4, 4, 6, 6, 7, 7, 7, 7, 9, 9,10,10, 7, 5, 5,
  127394. 7, 7, 8, 8, 8, 8,10, 9,11,10, 7, 5, 5, 7, 7, 8,
  127395. 8, 8, 8, 9,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  127396. 10,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  127397. 11, 0,12,12, 9, 9, 9,10,10,10,11,11,12,12, 0,13,
  127398. 13, 9, 9, 9, 9,10,10,11,11,12,12, 0, 0, 0,10,10,
  127399. 10,10,11,11,12,12,12,13, 0, 0, 0,10,10,10,10,11,
  127400. 11,12,12,12,12, 0, 0, 0,14,14,11,11,11,11,12,13,
  127401. 13,13, 0, 0, 0,14,14,11,10,11,11,12,12,13,13, 0,
  127402. 0, 0, 0, 0,12,12,12,12,13,13,13,14, 0, 0, 0, 0,
  127403. 0,13,12,12,12,13,13,13,14,
  127404. };
  127405. static float _vq_quantthresh__44cn1_sm_p7_0[] = {
  127406. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  127407. 12.5, 17.5, 22.5, 27.5,
  127408. };
  127409. static long _vq_quantmap__44cn1_sm_p7_0[] = {
  127410. 11, 9, 7, 5, 3, 1, 0, 2,
  127411. 4, 6, 8, 10, 12,
  127412. };
  127413. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p7_0 = {
  127414. _vq_quantthresh__44cn1_sm_p7_0,
  127415. _vq_quantmap__44cn1_sm_p7_0,
  127416. 13,
  127417. 13
  127418. };
  127419. static static_codebook _44cn1_sm_p7_0 = {
  127420. 2, 169,
  127421. _vq_lengthlist__44cn1_sm_p7_0,
  127422. 1, -526516224, 1616117760, 4, 0,
  127423. _vq_quantlist__44cn1_sm_p7_0,
  127424. NULL,
  127425. &_vq_auxt__44cn1_sm_p7_0,
  127426. NULL,
  127427. 0
  127428. };
  127429. static long _vq_quantlist__44cn1_sm_p7_1[] = {
  127430. 2,
  127431. 1,
  127432. 3,
  127433. 0,
  127434. 4,
  127435. };
  127436. static long _vq_lengthlist__44cn1_sm_p7_1[] = {
  127437. 2, 4, 4, 4, 5, 6, 5, 5, 5, 5, 6, 5, 5, 5, 5, 6,
  127438. 5, 5, 5, 5, 6, 6, 6, 5, 5,
  127439. };
  127440. static float _vq_quantthresh__44cn1_sm_p7_1[] = {
  127441. -1.5, -0.5, 0.5, 1.5,
  127442. };
  127443. static long _vq_quantmap__44cn1_sm_p7_1[] = {
  127444. 3, 1, 0, 2, 4,
  127445. };
  127446. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p7_1 = {
  127447. _vq_quantthresh__44cn1_sm_p7_1,
  127448. _vq_quantmap__44cn1_sm_p7_1,
  127449. 5,
  127450. 5
  127451. };
  127452. static static_codebook _44cn1_sm_p7_1 = {
  127453. 2, 25,
  127454. _vq_lengthlist__44cn1_sm_p7_1,
  127455. 1, -533725184, 1611661312, 3, 0,
  127456. _vq_quantlist__44cn1_sm_p7_1,
  127457. NULL,
  127458. &_vq_auxt__44cn1_sm_p7_1,
  127459. NULL,
  127460. 0
  127461. };
  127462. static long _vq_quantlist__44cn1_sm_p8_0[] = {
  127463. 4,
  127464. 3,
  127465. 5,
  127466. 2,
  127467. 6,
  127468. 1,
  127469. 7,
  127470. 0,
  127471. 8,
  127472. };
  127473. static long _vq_lengthlist__44cn1_sm_p8_0[] = {
  127474. 1, 4, 4,12,11,13,13,14,14, 4, 7, 7,11,13,14,14,
  127475. 14,14, 3, 8, 3,14,14,14,14,14,14,14,10,12,14,14,
  127476. 14,14,14,14,14,14, 5,14, 8,14,14,14,14,14,12,14,
  127477. 13,14,14,14,14,14,14,14,13,14,10,14,14,14,14,14,
  127478. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  127479. 14,
  127480. };
  127481. static float _vq_quantthresh__44cn1_sm_p8_0[] = {
  127482. -773.5, -552.5, -331.5, -110.5, 110.5, 331.5, 552.5, 773.5,
  127483. };
  127484. static long _vq_quantmap__44cn1_sm_p8_0[] = {
  127485. 7, 5, 3, 1, 0, 2, 4, 6,
  127486. 8,
  127487. };
  127488. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p8_0 = {
  127489. _vq_quantthresh__44cn1_sm_p8_0,
  127490. _vq_quantmap__44cn1_sm_p8_0,
  127491. 9,
  127492. 9
  127493. };
  127494. static static_codebook _44cn1_sm_p8_0 = {
  127495. 2, 81,
  127496. _vq_lengthlist__44cn1_sm_p8_0,
  127497. 1, -516186112, 1627103232, 4, 0,
  127498. _vq_quantlist__44cn1_sm_p8_0,
  127499. NULL,
  127500. &_vq_auxt__44cn1_sm_p8_0,
  127501. NULL,
  127502. 0
  127503. };
  127504. static long _vq_quantlist__44cn1_sm_p8_1[] = {
  127505. 6,
  127506. 5,
  127507. 7,
  127508. 4,
  127509. 8,
  127510. 3,
  127511. 9,
  127512. 2,
  127513. 10,
  127514. 1,
  127515. 11,
  127516. 0,
  127517. 12,
  127518. };
  127519. static long _vq_lengthlist__44cn1_sm_p8_1[] = {
  127520. 1, 4, 4, 6, 6, 8, 8, 9, 9,10,11,11,11, 6, 5, 5,
  127521. 7, 7, 8, 8,10,10,10,11,11,11, 6, 5, 5, 7, 7, 8,
  127522. 8,10,10,11,12,12,12,14, 7, 7, 7, 8, 9, 9,11,11,
  127523. 11,12,11,12,17, 7, 7, 8, 7, 9, 9,11,11,12,12,12,
  127524. 12,14,11,11, 8, 8,10,10,11,12,12,13,11,12,14,11,
  127525. 11, 8, 8,10,10,11,12,12,13,13,12,14,15,14,10,10,
  127526. 10,10,11,12,12,12,12,11,14,13,16,10,10,10, 9,12,
  127527. 11,12,12,13,14,14,15,14,14,13,10,10,11,11,12,11,
  127528. 13,11,14,12,15,13,14,11,10,12,10,12,12,13,13,13,
  127529. 13,14,15,15,12,12,11,11,12,11,13,12,14,14,14,14,
  127530. 17,12,12,11,10,13,11,13,13,
  127531. };
  127532. static float _vq_quantthresh__44cn1_sm_p8_1[] = {
  127533. -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5, 25.5,
  127534. 42.5, 59.5, 76.5, 93.5,
  127535. };
  127536. static long _vq_quantmap__44cn1_sm_p8_1[] = {
  127537. 11, 9, 7, 5, 3, 1, 0, 2,
  127538. 4, 6, 8, 10, 12,
  127539. };
  127540. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p8_1 = {
  127541. _vq_quantthresh__44cn1_sm_p8_1,
  127542. _vq_quantmap__44cn1_sm_p8_1,
  127543. 13,
  127544. 13
  127545. };
  127546. static static_codebook _44cn1_sm_p8_1 = {
  127547. 2, 169,
  127548. _vq_lengthlist__44cn1_sm_p8_1,
  127549. 1, -522616832, 1620115456, 4, 0,
  127550. _vq_quantlist__44cn1_sm_p8_1,
  127551. NULL,
  127552. &_vq_auxt__44cn1_sm_p8_1,
  127553. NULL,
  127554. 0
  127555. };
  127556. static long _vq_quantlist__44cn1_sm_p8_2[] = {
  127557. 8,
  127558. 7,
  127559. 9,
  127560. 6,
  127561. 10,
  127562. 5,
  127563. 11,
  127564. 4,
  127565. 12,
  127566. 3,
  127567. 13,
  127568. 2,
  127569. 14,
  127570. 1,
  127571. 15,
  127572. 0,
  127573. 16,
  127574. };
  127575. static long _vq_lengthlist__44cn1_sm_p8_2[] = {
  127576. 3, 4, 4, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  127577. 9,10, 6, 6, 6, 6, 7, 7, 8, 8, 8, 9, 9, 9, 9, 9,
  127578. 9, 9,10, 6, 6, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9,
  127579. 9, 9, 9,10, 7, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9,
  127580. 9, 9, 9, 9,10,10,10, 7, 7, 7, 8, 8, 8, 9, 9, 9,
  127581. 9, 9, 9, 9, 9,10,10,10, 8, 8, 8, 8, 8, 8, 9, 9,
  127582. 9, 9, 9, 9, 9, 9,10,10,10, 8, 8, 8, 8, 8, 8, 9,
  127583. 9, 9, 9, 9, 9, 9, 9,11,10,11, 8, 8, 8, 8, 8, 8,
  127584. 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,11,11, 8, 8, 8,
  127585. 8, 9, 9, 9, 9, 9, 9, 9, 9,11,10,11,11,11, 9, 9,
  127586. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,11,10,11,11, 9,
  127587. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,11,11,10,11,11,
  127588. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,11,10,11,11,
  127589. 11,11,11, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,11,11,
  127590. 11,11,11,11, 9,10,10,10, 9, 9, 9, 9, 9, 9,11,10,
  127591. 11,11,11,11,11, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,11,
  127592. 11,11,11,11,11,11,10,10, 9, 9, 9, 9, 9, 9, 9, 9,
  127593. 10,11,11,11,11,11,11,11,11, 9, 9, 9, 9, 9, 9, 9,
  127594. 9,
  127595. };
  127596. static float _vq_quantthresh__44cn1_sm_p8_2[] = {
  127597. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  127598. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  127599. };
  127600. static long _vq_quantmap__44cn1_sm_p8_2[] = {
  127601. 15, 13, 11, 9, 7, 5, 3, 1,
  127602. 0, 2, 4, 6, 8, 10, 12, 14,
  127603. 16,
  127604. };
  127605. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p8_2 = {
  127606. _vq_quantthresh__44cn1_sm_p8_2,
  127607. _vq_quantmap__44cn1_sm_p8_2,
  127608. 17,
  127609. 17
  127610. };
  127611. static static_codebook _44cn1_sm_p8_2 = {
  127612. 2, 289,
  127613. _vq_lengthlist__44cn1_sm_p8_2,
  127614. 1, -529530880, 1611661312, 5, 0,
  127615. _vq_quantlist__44cn1_sm_p8_2,
  127616. NULL,
  127617. &_vq_auxt__44cn1_sm_p8_2,
  127618. NULL,
  127619. 0
  127620. };
  127621. static long _huff_lengthlist__44cn1_sm_short[] = {
  127622. 5, 6,12,14,12,14,16,17,18, 4, 2, 5,11, 7,10,12,
  127623. 14,15, 9, 4, 5,11, 7,10,13,15,18,15, 6, 7, 5, 6,
  127624. 8,11,13,16,11, 5, 6, 5, 5, 6, 9,13,15,12, 5, 7,
  127625. 6, 5, 6, 9,12,14,12, 6, 7, 8, 6, 7, 9,12,13,14,
  127626. 8, 8, 7, 5, 5, 8,10,12,16, 9, 9, 8, 6, 6, 7, 9,
  127627. 9,
  127628. };
  127629. static static_codebook _huff_book__44cn1_sm_short = {
  127630. 2, 81,
  127631. _huff_lengthlist__44cn1_sm_short,
  127632. 0, 0, 0, 0, 0,
  127633. NULL,
  127634. NULL,
  127635. NULL,
  127636. NULL,
  127637. 0
  127638. };
  127639. /*** End of inlined file: res_books_stereo.h ***/
  127640. static vorbis_info_residue0 _residue_44_low={
  127641. 0,-1, -1, 9,-1,
  127642. {0},
  127643. {-1},
  127644. { .5, 1.5, 2.5, 2.5, 4.5, 8.5, 16.5, 32.5},
  127645. { .5, .5, .5, 999., 4.5, 8.5, 16.5, 32.5},
  127646. };
  127647. static vorbis_info_residue0 _residue_44_mid={
  127648. 0,-1, -1, 10,-1,
  127649. {0},
  127650. {-1},
  127651. { .5, 1.5, 1.5, 2.5, 2.5, 4.5, 8.5, 16.5, 32.5},
  127652. { .5, .5, 999., .5, 999., 4.5, 8.5, 16.5, 32.5},
  127653. };
  127654. static vorbis_info_residue0 _residue_44_high={
  127655. 0,-1, -1, 10,-1,
  127656. {0},
  127657. {-1},
  127658. { .5, 1.5, 2.5, 4.5, 8.5, 16.5, 32.5, 71.5,157.5},
  127659. { .5, 1.5, 2.5, 3.5, 4.5, 8.5, 16.5, 71.5,157.5},
  127660. };
  127661. static static_bookblock _resbook_44s_n1={
  127662. {
  127663. {0},{0,0,&_44cn1_s_p1_0},{0,0,&_44cn1_s_p2_0},
  127664. {0,0,&_44cn1_s_p3_0},{0,0,&_44cn1_s_p4_0},{0,0,&_44cn1_s_p5_0},
  127665. {&_44cn1_s_p6_0,&_44cn1_s_p6_1},{&_44cn1_s_p7_0,&_44cn1_s_p7_1},
  127666. {&_44cn1_s_p8_0,&_44cn1_s_p8_1,&_44cn1_s_p8_2}
  127667. }
  127668. };
  127669. static static_bookblock _resbook_44sm_n1={
  127670. {
  127671. {0},{0,0,&_44cn1_sm_p1_0},{0,0,&_44cn1_sm_p2_0},
  127672. {0,0,&_44cn1_sm_p3_0},{0,0,&_44cn1_sm_p4_0},{0,0,&_44cn1_sm_p5_0},
  127673. {&_44cn1_sm_p6_0,&_44cn1_sm_p6_1},{&_44cn1_sm_p7_0,&_44cn1_sm_p7_1},
  127674. {&_44cn1_sm_p8_0,&_44cn1_sm_p8_1,&_44cn1_sm_p8_2}
  127675. }
  127676. };
  127677. static static_bookblock _resbook_44s_0={
  127678. {
  127679. {0},{0,0,&_44c0_s_p1_0},{0,0,&_44c0_s_p2_0},
  127680. {0,0,&_44c0_s_p3_0},{0,0,&_44c0_s_p4_0},{0,0,&_44c0_s_p5_0},
  127681. {&_44c0_s_p6_0,&_44c0_s_p6_1},{&_44c0_s_p7_0,&_44c0_s_p7_1},
  127682. {&_44c0_s_p8_0,&_44c0_s_p8_1,&_44c0_s_p8_2}
  127683. }
  127684. };
  127685. static static_bookblock _resbook_44sm_0={
  127686. {
  127687. {0},{0,0,&_44c0_sm_p1_0},{0,0,&_44c0_sm_p2_0},
  127688. {0,0,&_44c0_sm_p3_0},{0,0,&_44c0_sm_p4_0},{0,0,&_44c0_sm_p5_0},
  127689. {&_44c0_sm_p6_0,&_44c0_sm_p6_1},{&_44c0_sm_p7_0,&_44c0_sm_p7_1},
  127690. {&_44c0_sm_p8_0,&_44c0_sm_p8_1,&_44c0_sm_p8_2}
  127691. }
  127692. };
  127693. static static_bookblock _resbook_44s_1={
  127694. {
  127695. {0},{0,0,&_44c1_s_p1_0},{0,0,&_44c1_s_p2_0},
  127696. {0,0,&_44c1_s_p3_0},{0,0,&_44c1_s_p4_0},{0,0,&_44c1_s_p5_0},
  127697. {&_44c1_s_p6_0,&_44c1_s_p6_1},{&_44c1_s_p7_0,&_44c1_s_p7_1},
  127698. {&_44c1_s_p8_0,&_44c1_s_p8_1,&_44c1_s_p8_2}
  127699. }
  127700. };
  127701. static static_bookblock _resbook_44sm_1={
  127702. {
  127703. {0},{0,0,&_44c1_sm_p1_0},{0,0,&_44c1_sm_p2_0},
  127704. {0,0,&_44c1_sm_p3_0},{0,0,&_44c1_sm_p4_0},{0,0,&_44c1_sm_p5_0},
  127705. {&_44c1_sm_p6_0,&_44c1_sm_p6_1},{&_44c1_sm_p7_0,&_44c1_sm_p7_1},
  127706. {&_44c1_sm_p8_0,&_44c1_sm_p8_1,&_44c1_sm_p8_2}
  127707. }
  127708. };
  127709. static static_bookblock _resbook_44s_2={
  127710. {
  127711. {0},{0,0,&_44c2_s_p1_0},{0,0,&_44c2_s_p2_0},{0,0,&_44c2_s_p3_0},
  127712. {0,0,&_44c2_s_p4_0},{0,0,&_44c2_s_p5_0},{0,0,&_44c2_s_p6_0},
  127713. {&_44c2_s_p7_0,&_44c2_s_p7_1},{&_44c2_s_p8_0,&_44c2_s_p8_1},
  127714. {&_44c2_s_p9_0,&_44c2_s_p9_1,&_44c2_s_p9_2}
  127715. }
  127716. };
  127717. static static_bookblock _resbook_44s_3={
  127718. {
  127719. {0},{0,0,&_44c3_s_p1_0},{0,0,&_44c3_s_p2_0},{0,0,&_44c3_s_p3_0},
  127720. {0,0,&_44c3_s_p4_0},{0,0,&_44c3_s_p5_0},{0,0,&_44c3_s_p6_0},
  127721. {&_44c3_s_p7_0,&_44c3_s_p7_1},{&_44c3_s_p8_0,&_44c3_s_p8_1},
  127722. {&_44c3_s_p9_0,&_44c3_s_p9_1,&_44c3_s_p9_2}
  127723. }
  127724. };
  127725. static static_bookblock _resbook_44s_4={
  127726. {
  127727. {0},{0,0,&_44c4_s_p1_0},{0,0,&_44c4_s_p2_0},{0,0,&_44c4_s_p3_0},
  127728. {0,0,&_44c4_s_p4_0},{0,0,&_44c4_s_p5_0},{0,0,&_44c4_s_p6_0},
  127729. {&_44c4_s_p7_0,&_44c4_s_p7_1},{&_44c4_s_p8_0,&_44c4_s_p8_1},
  127730. {&_44c4_s_p9_0,&_44c4_s_p9_1,&_44c4_s_p9_2}
  127731. }
  127732. };
  127733. static static_bookblock _resbook_44s_5={
  127734. {
  127735. {0},{0,0,&_44c5_s_p1_0},{0,0,&_44c5_s_p2_0},{0,0,&_44c5_s_p3_0},
  127736. {0,0,&_44c5_s_p4_0},{0,0,&_44c5_s_p5_0},{0,0,&_44c5_s_p6_0},
  127737. {&_44c5_s_p7_0,&_44c5_s_p7_1},{&_44c5_s_p8_0,&_44c5_s_p8_1},
  127738. {&_44c5_s_p9_0,&_44c5_s_p9_1,&_44c5_s_p9_2}
  127739. }
  127740. };
  127741. static static_bookblock _resbook_44s_6={
  127742. {
  127743. {0},{0,0,&_44c6_s_p1_0},{0,0,&_44c6_s_p2_0},{0,0,&_44c6_s_p3_0},
  127744. {0,0,&_44c6_s_p4_0},
  127745. {&_44c6_s_p5_0,&_44c6_s_p5_1},
  127746. {&_44c6_s_p6_0,&_44c6_s_p6_1},
  127747. {&_44c6_s_p7_0,&_44c6_s_p7_1},
  127748. {&_44c6_s_p8_0,&_44c6_s_p8_1},
  127749. {&_44c6_s_p9_0,&_44c6_s_p9_1,&_44c6_s_p9_2}
  127750. }
  127751. };
  127752. static static_bookblock _resbook_44s_7={
  127753. {
  127754. {0},{0,0,&_44c7_s_p1_0},{0,0,&_44c7_s_p2_0},{0,0,&_44c7_s_p3_0},
  127755. {0,0,&_44c7_s_p4_0},
  127756. {&_44c7_s_p5_0,&_44c7_s_p5_1},
  127757. {&_44c7_s_p6_0,&_44c7_s_p6_1},
  127758. {&_44c7_s_p7_0,&_44c7_s_p7_1},
  127759. {&_44c7_s_p8_0,&_44c7_s_p8_1},
  127760. {&_44c7_s_p9_0,&_44c7_s_p9_1,&_44c7_s_p9_2}
  127761. }
  127762. };
  127763. static static_bookblock _resbook_44s_8={
  127764. {
  127765. {0},{0,0,&_44c8_s_p1_0},{0,0,&_44c8_s_p2_0},{0,0,&_44c8_s_p3_0},
  127766. {0,0,&_44c8_s_p4_0},
  127767. {&_44c8_s_p5_0,&_44c8_s_p5_1},
  127768. {&_44c8_s_p6_0,&_44c8_s_p6_1},
  127769. {&_44c8_s_p7_0,&_44c8_s_p7_1},
  127770. {&_44c8_s_p8_0,&_44c8_s_p8_1},
  127771. {&_44c8_s_p9_0,&_44c8_s_p9_1,&_44c8_s_p9_2}
  127772. }
  127773. };
  127774. static static_bookblock _resbook_44s_9={
  127775. {
  127776. {0},{0,0,&_44c9_s_p1_0},{0,0,&_44c9_s_p2_0},{0,0,&_44c9_s_p3_0},
  127777. {0,0,&_44c9_s_p4_0},
  127778. {&_44c9_s_p5_0,&_44c9_s_p5_1},
  127779. {&_44c9_s_p6_0,&_44c9_s_p6_1},
  127780. {&_44c9_s_p7_0,&_44c9_s_p7_1},
  127781. {&_44c9_s_p8_0,&_44c9_s_p8_1},
  127782. {&_44c9_s_p9_0,&_44c9_s_p9_1,&_44c9_s_p9_2}
  127783. }
  127784. };
  127785. static vorbis_residue_template _res_44s_n1[]={
  127786. {2,0, &_residue_44_low,
  127787. &_huff_book__44cn1_s_short,&_huff_book__44cn1_sm_short,
  127788. &_resbook_44s_n1,&_resbook_44sm_n1},
  127789. {2,0, &_residue_44_low,
  127790. &_huff_book__44cn1_s_long,&_huff_book__44cn1_sm_long,
  127791. &_resbook_44s_n1,&_resbook_44sm_n1}
  127792. };
  127793. static vorbis_residue_template _res_44s_0[]={
  127794. {2,0, &_residue_44_low,
  127795. &_huff_book__44c0_s_short,&_huff_book__44c0_sm_short,
  127796. &_resbook_44s_0,&_resbook_44sm_0},
  127797. {2,0, &_residue_44_low,
  127798. &_huff_book__44c0_s_long,&_huff_book__44c0_sm_long,
  127799. &_resbook_44s_0,&_resbook_44sm_0}
  127800. };
  127801. static vorbis_residue_template _res_44s_1[]={
  127802. {2,0, &_residue_44_low,
  127803. &_huff_book__44c1_s_short,&_huff_book__44c1_sm_short,
  127804. &_resbook_44s_1,&_resbook_44sm_1},
  127805. {2,0, &_residue_44_low,
  127806. &_huff_book__44c1_s_long,&_huff_book__44c1_sm_long,
  127807. &_resbook_44s_1,&_resbook_44sm_1}
  127808. };
  127809. static vorbis_residue_template _res_44s_2[]={
  127810. {2,0, &_residue_44_mid,
  127811. &_huff_book__44c2_s_short,&_huff_book__44c2_s_short,
  127812. &_resbook_44s_2,&_resbook_44s_2},
  127813. {2,0, &_residue_44_mid,
  127814. &_huff_book__44c2_s_long,&_huff_book__44c2_s_long,
  127815. &_resbook_44s_2,&_resbook_44s_2}
  127816. };
  127817. static vorbis_residue_template _res_44s_3[]={
  127818. {2,0, &_residue_44_mid,
  127819. &_huff_book__44c3_s_short,&_huff_book__44c3_s_short,
  127820. &_resbook_44s_3,&_resbook_44s_3},
  127821. {2,0, &_residue_44_mid,
  127822. &_huff_book__44c3_s_long,&_huff_book__44c3_s_long,
  127823. &_resbook_44s_3,&_resbook_44s_3}
  127824. };
  127825. static vorbis_residue_template _res_44s_4[]={
  127826. {2,0, &_residue_44_mid,
  127827. &_huff_book__44c4_s_short,&_huff_book__44c4_s_short,
  127828. &_resbook_44s_4,&_resbook_44s_4},
  127829. {2,0, &_residue_44_mid,
  127830. &_huff_book__44c4_s_long,&_huff_book__44c4_s_long,
  127831. &_resbook_44s_4,&_resbook_44s_4}
  127832. };
  127833. static vorbis_residue_template _res_44s_5[]={
  127834. {2,0, &_residue_44_mid,
  127835. &_huff_book__44c5_s_short,&_huff_book__44c5_s_short,
  127836. &_resbook_44s_5,&_resbook_44s_5},
  127837. {2,0, &_residue_44_mid,
  127838. &_huff_book__44c5_s_long,&_huff_book__44c5_s_long,
  127839. &_resbook_44s_5,&_resbook_44s_5}
  127840. };
  127841. static vorbis_residue_template _res_44s_6[]={
  127842. {2,0, &_residue_44_high,
  127843. &_huff_book__44c6_s_short,&_huff_book__44c6_s_short,
  127844. &_resbook_44s_6,&_resbook_44s_6},
  127845. {2,0, &_residue_44_high,
  127846. &_huff_book__44c6_s_long,&_huff_book__44c6_s_long,
  127847. &_resbook_44s_6,&_resbook_44s_6}
  127848. };
  127849. static vorbis_residue_template _res_44s_7[]={
  127850. {2,0, &_residue_44_high,
  127851. &_huff_book__44c7_s_short,&_huff_book__44c7_s_short,
  127852. &_resbook_44s_7,&_resbook_44s_7},
  127853. {2,0, &_residue_44_high,
  127854. &_huff_book__44c7_s_long,&_huff_book__44c7_s_long,
  127855. &_resbook_44s_7,&_resbook_44s_7}
  127856. };
  127857. static vorbis_residue_template _res_44s_8[]={
  127858. {2,0, &_residue_44_high,
  127859. &_huff_book__44c8_s_short,&_huff_book__44c8_s_short,
  127860. &_resbook_44s_8,&_resbook_44s_8},
  127861. {2,0, &_residue_44_high,
  127862. &_huff_book__44c8_s_long,&_huff_book__44c8_s_long,
  127863. &_resbook_44s_8,&_resbook_44s_8}
  127864. };
  127865. static vorbis_residue_template _res_44s_9[]={
  127866. {2,0, &_residue_44_high,
  127867. &_huff_book__44c9_s_short,&_huff_book__44c9_s_short,
  127868. &_resbook_44s_9,&_resbook_44s_9},
  127869. {2,0, &_residue_44_high,
  127870. &_huff_book__44c9_s_long,&_huff_book__44c9_s_long,
  127871. &_resbook_44s_9,&_resbook_44s_9}
  127872. };
  127873. static vorbis_mapping_template _mapres_template_44_stereo[]={
  127874. { _map_nominal, _res_44s_n1 }, /* -1 */
  127875. { _map_nominal, _res_44s_0 }, /* 0 */
  127876. { _map_nominal, _res_44s_1 }, /* 1 */
  127877. { _map_nominal, _res_44s_2 }, /* 2 */
  127878. { _map_nominal, _res_44s_3 }, /* 3 */
  127879. { _map_nominal, _res_44s_4 }, /* 4 */
  127880. { _map_nominal, _res_44s_5 }, /* 5 */
  127881. { _map_nominal, _res_44s_6 }, /* 6 */
  127882. { _map_nominal, _res_44s_7 }, /* 7 */
  127883. { _map_nominal, _res_44s_8 }, /* 8 */
  127884. { _map_nominal, _res_44s_9 }, /* 9 */
  127885. };
  127886. /*** End of inlined file: residue_44.h ***/
  127887. /*** Start of inlined file: psych_44.h ***/
  127888. static vorbis_info_psy_global _psy_global_44[5]={
  127889. {8, /* lines per eighth octave */
  127890. {20.f,14.f,12.f,12.f,12.f,12.f,12.f},
  127891. {-60.f,-30.f,-40.f,-40.f,-40.f,-40.f,-40.f}, 2,-75.f,
  127892. -6.f,
  127893. {99.},{{99.},{99.}},{0},{0},{{0.},{0.}}
  127894. },
  127895. {8, /* lines per eighth octave */
  127896. {14.f,10.f,10.f,10.f,10.f,10.f,10.f},
  127897. {-40.f,-30.f,-25.f,-25.f,-25.f,-25.f,-25.f}, 2,-80.f,
  127898. -6.f,
  127899. {99.},{{99.},{99.}},{0},{0},{{0.},{0.}}
  127900. },
  127901. {8, /* lines per eighth octave */
  127902. {12.f,10.f,10.f,10.f,10.f,10.f,10.f},
  127903. {-20.f,-20.f,-15.f,-15.f,-15.f,-15.f,-15.f}, 0,-80.f,
  127904. -6.f,
  127905. {99.},{{99.},{99.}},{0},{0},{{0.},{0.}}
  127906. },
  127907. {8, /* lines per eighth octave */
  127908. {10.f,8.f,8.f,8.f,8.f,8.f,8.f},
  127909. {-20.f,-15.f,-12.f,-12.f,-12.f,-12.f,-12.f}, 0,-80.f,
  127910. -6.f,
  127911. {99.},{{99.},{99.}},{0},{0},{{0.},{0.}}
  127912. },
  127913. {8, /* lines per eighth octave */
  127914. {10.f,6.f,6.f,6.f,6.f,6.f,6.f},
  127915. {-15.f,-15.f,-12.f,-12.f,-12.f,-12.f,-12.f}, 0,-85.f,
  127916. -6.f,
  127917. {99.},{{99.},{99.}},{0},{0},{{0.},{0.}}
  127918. },
  127919. };
  127920. static compandblock _psy_compand_44[6]={
  127921. {{
  127922. 0, 1, 2, 3, 4, 5, 6, 7, /* 7dB */
  127923. 8, 9,10,11,12,13,14, 15, /* 15dB */
  127924. 16,17,18,19,20,21,22, 23, /* 23dB */
  127925. 24,25,26,27,28,29,30, 31, /* 31dB */
  127926. 32,33,34,35,36,37,38, 39, /* 39dB */
  127927. }},
  127928. {{
  127929. 0, 1, 2, 3, 4, 5, 6, 6, /* 7dB */
  127930. 7, 7, 7, 7, 6, 6, 6, 7, /* 15dB */
  127931. 7, 8, 9,10,11,12,13, 14, /* 23dB */
  127932. 15,16,17,17,17,18,18, 19, /* 31dB */
  127933. 19,19,20,21,22,23,24, 25, /* 39dB */
  127934. }},
  127935. {{
  127936. 0, 1, 2, 3, 4, 5, 5, 5, /* 7dB */
  127937. 6, 6, 6, 5, 4, 4, 4, 4, /* 15dB */
  127938. 4, 4, 5, 5, 5, 6, 6, 6, /* 23dB */
  127939. 7, 7, 7, 8, 8, 8, 9, 10, /* 31dB */
  127940. 11,12,13,14,15,16,17, 18, /* 39dB */
  127941. }},
  127942. {{
  127943. 0, 1, 2, 3, 4, 5, 6, 7, /* 7dB */
  127944. 8, 9,10,11,12,13,14, 15, /* 15dB */
  127945. 16,17,18,19,20,21,22, 23, /* 23dB */
  127946. 24,25,26,27,28,29,30, 31, /* 31dB */
  127947. 32,33,34,35,36,37,38, 39, /* 39dB */
  127948. }},
  127949. {{
  127950. 0, 1, 2, 3, 4, 5, 6, 7, /* 7dB */
  127951. 8, 9,10,11,12,12,13, 13, /* 15dB */
  127952. 13,14,14,14,15,15,15, 15, /* 23dB */
  127953. 16,16,17,17,17,18,18, 19, /* 31dB */
  127954. 19,19,20,21,22,23,24, 25, /* 39dB */
  127955. }},
  127956. {{
  127957. 0, 1, 2, 3, 4, 5, 6, 7, /* 7dB */
  127958. 8, 8, 7, 6, 5, 4, 4, 4, /* 15dB */
  127959. 4, 4, 5, 5, 5, 6, 6, 6, /* 23dB */
  127960. 7, 7, 7, 8, 8, 8, 9, 10, /* 31dB */
  127961. 11,12,13,14,15,16,17, 18, /* 39dB */
  127962. }}
  127963. };
  127964. static vp_adjblock _vp_tonemask_adj_longblock[12]={
  127965. {{ -3, -8,-13,-15,-10,-10,-10,-10,-10,-10,-10, 0, 0, 0, 0, 0, 0}}, /* -1 */
  127966. {{ -4,-10,-14,-16,-15,-14,-13,-12,-12,-12,-11, -1, -1, -1, -1, -1, 0}}, /* 0 */
  127967. {{ -6,-12,-14,-16,-15,-15,-14,-13,-13,-12,-12, -2, -2, -1, -1, -1, 0}}, /* 1 */
  127968. {{-12,-13,-14,-16,-16,-16,-15,-14,-13,-12,-12, -6, -3, -1, -1, -1, 0}}, /* 2 */
  127969. {{-15,-15,-15,-16,-16,-16,-16,-14,-13,-13,-13,-10, -4, -2, -1, -1, 0}}, /* 3 */
  127970. /* 4 */
  127971. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-13,-11, -7 -3, -1, -1 , 0}}, /* 4 */
  127972. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-13,-11, -7 -3, -1, -1 , 0}}, /* 5 */
  127973. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-14,-12, -8, -4, -2, -2, 0}}, /* 6 */
  127974. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-14,-12, -9, -4, -2, -2, 0}}, /* 7 */
  127975. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-14,-12, -9, -4, -2, -2, 0}}, /* 8 */
  127976. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-14,-12, -9, -4, -2, -2, 0}}, /* 9 */
  127977. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-14,-12, -9, -4, -2, -2, 0}}, /* 10 */
  127978. };
  127979. static vp_adjblock _vp_tonemask_adj_otherblock[12]={
  127980. {{ -3, -8,-13,-15,-10,-10, -9, -9, -9, -9, -9, 1, 1, 1, 1, 1, 1}}, /* -1 */
  127981. {{ -4,-10,-14,-16,-14,-13,-12,-12,-11,-11,-10, 0, 0, 0, 0, 0, 0}}, /* 0 */
  127982. {{ -6,-12,-14,-16,-15,-15,-14,-13,-13,-12,-12, -2, -2, -1, 0, 0, 0}}, /* 1 */
  127983. {{-12,-13,-14,-16,-16,-16,-15,-14,-13,-12,-12, -5, -2, -1, 0, 0, 0}}, /* 2 */
  127984. {{-15,-15,-15,-16,-16,-16,-16,-14,-13,-13,-13,-10, -4, -2, 0, 0, 0}}, /* 3 */
  127985. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-13,-11, -7 -3, -1, -1 , 0}}, /* 4 */
  127986. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-13,-11, -7 -3, -1, -1 , 0}}, /* 5 */
  127987. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-14,-12, -8, -4, -2, -2, 0}}, /* 6 */
  127988. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-14,-12, -9, -4, -2, -2, 0}}, /* 7 */
  127989. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-14,-12, -9, -4, -2, -2, 0}}, /* 8 */
  127990. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-14,-12, -9, -4, -2, -2, 0}}, /* 9 */
  127991. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-14,-12, -9, -4, -2, -2, 0}}, /* 10 */
  127992. };
  127993. static noise3 _psy_noisebias_trans[12]={
  127994. {{{-10,-10,-10,-10,-10, -4, 0, 0, 4, 8, 8, 8, 8, 10, 12, 14, 20},
  127995. {-30,-30,-30,-30,-26,-20,-16, -8, -6, -6, -2, 2, 2, 3, 6, 6, 15},
  127996. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, -6, -4, -2}}},
  127997. {{{-15,-15,-15,-15,-15,-12, -6, -4, 0, 2, 4, 4, 5, 5, 5, 8, 10},
  127998. {-30,-30,-30,-30,-26,-22,-20,-14, -8, -4, 0, 0, 0, 0, 2, 3, 6},
  127999. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -6, -6, -6, -6, -4, -4, -4, -2}}},
  128000. {{{-15,-15,-15,-15,-15,-12,-10, -8, 0, 2, 4, 4, 5, 5, 5, 8, 10},
  128001. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -4, -2, -2, -2, -2, 0, 1, 4},
  128002. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -8, -8, -8, -8, -6, -6, -6, -4}}},
  128003. {{{-15,-15,-15,-15,-15,-12,-10, -8, 0, 2, 2, 2, 4, 4, 5, 6, 10},
  128004. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -4, -3, -3, -3, -2, -1, 0, 3},
  128005. {-30,-30,-30,-30,-26,-22,-20,-14,-10,-10,-10,-10,-10, -8, -8, -7, -4}}},
  128006. {{{-15,-15,-15,-15,-15,-12,-10, -8, 0, 2, 2, 2, 4, 4, 4, 5, 8},
  128007. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -4, -3, -3, -3, -3, -2, 0, 2},
  128008. {-30,-30,-30,-30,-26,-22,-20,-14,-10,-10,-10,-10,-10, -8, -8, -8, -4}}},
  128009. {{{-20,-20,-20,-20,-20,-18,-14, -8, -1, 1, 1, 1, 2, 3, 3, 4, 7},
  128010. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -4, -3, -3, -3, -3, -2, -1, 1},
  128011. {-30,-30,-30,-30,-26,-22,-20,-14,-10,-10,-10,-10,-10, -8, -8, -8, -4}}},
  128012. {{{-24,-24,-24,-24,-20,-18,-14, -8, -1, 1, 1, 1, 2, 3, 3, 4, 7},
  128013. {-32,-32,-32,-32,-28,-24,-22,-16,-12, -6, -4, -4, -4, -4, -3, -1, 0},
  128014. {-34,-34,-34,-34,-30,-24,-24,-18,-14,-12,-12,-12,-12,-10,-10, -9, -5}}},
  128015. {{{-24,-24,-24,-24,-20,-18,-14, -8, -1, 1, 1, 1, 2, 3, 3, 4, 7},
  128016. {-32,-32,-32,-32,-28,-24,-24,-18,-14, -8, -6, -6, -6, -6, -5, -2, 0},
  128017. {-34,-34,-34,-34,-30,-26,-26,-24,-22,-19,-19,-19,-19,-18,-17,-16,-12}}},
  128018. {{{-24,-24,-24,-24,-20,-18,-14, -8, -1, 1, 1, 1, 2, 3, 3, 4, 7},
  128019. {-32,-32,-32,-32,-28,-24,-24,-24,-18,-14,-12,-10,-10,-10, -8, -6, -2},
  128020. {-34,-34,-34,-34,-30,-26,-26,-26,-24,-24,-24,-24,-24,-24,-24,-20,-16}}},
  128021. {{{-24,-24,-24,-24,-22,-20,-15,-10, -8, -2, 0, 0, 0, 1, 2, 3, 7},
  128022. {-36,-36,-36,-36,-30,-30,-30,-24,-20,-16,-16,-16,-16,-14,-12,-10, -7},
  128023. {-36,-36,-36,-36,-34,-30,-28,-26,-24,-30,-30,-30,-30,-30,-30,-24,-20}}},
  128024. {{{-28,-28,-28,-28,-28,-28,-28,-20,-14, -8, -4, -4, -4, -4, -4, -2, 2},
  128025. {-38,-38,-38,-38,-36,-34,-34,-30,-24,-20,-20,-20,-20,-18,-16,-12,-10},
  128026. {-40,-40,-40,-40,-40,-40,-40,-38,-35,-35,-35,-35,-35,-35,-35,-35,-30}}},
  128027. {{{-30,-30,-30,-30,-30,-30,-30,-28,-20,-14,-14,-14,-14,-14,-14,-12,-10},
  128028. {-40,-40,-40,-40,-40,-40,-40,-40,-35,-30,-30,-30,-30,-30,-30,-30,-20},
  128029. {-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40}}},
  128030. };
  128031. static noise3 _psy_noisebias_long[12]={
  128032. {{{-10,-10,-10,-10,-10, -4, 0, 0, 0, 6, 6, 6, 6, 10, 10, 12, 20},
  128033. {-20,-20,-20,-20,-20,-20,-10, -2, 0, 0, 0, 0, 0, 2, 4, 6, 15},
  128034. {-20,-20,-20,-20,-20,-20,-20,-10, -6, -6, -6, -6, -6, -4, -4, -4, -2}}},
  128035. {{{-10,-10,-10,-10,-10,-10, -8, 2, 2, 2, 4, 4, 5, 5, 5, 8, 10},
  128036. {-20,-20,-20,-20,-20,-20,-20,-14, -6, 0, 0, 0, 0, 0, 2, 3, 6},
  128037. {-20,-20,-20,-20,-20,-20,-20,-14, -8, -6, -6, -6, -6, -4, -4, -4, -2}}},
  128038. {{{-10,-10,-10,-10,-10,-10, -8, -4, 0, 2, 4, 4, 5, 5, 5, 8, 10},
  128039. {-20,-20,-20,-20,-20,-20,-20,-14,-10, -4, -2, -2, -2, -2, 0, 1, 4},
  128040. {-20,-20,-20,-20,-20,-20,-20,-14,-10, -8, -8, -8, -8, -6, -6, -6, -4}}},
  128041. {{{-10,-10,-10,-10,-10,-10,-10, -8, 0, 2, 2, 2, 4, 4, 5, 6, 10},
  128042. {-20,-20,-20,-20,-20,-20,-20,-14,-10, -4, -3, -3, -3, -2, -1, 0, 3},
  128043. {-20,-20,-20,-20,-20,-20,-20,-14,-10,-10,-10,-10,-10, -8, -8, -8, -4}}},
  128044. {{{-10,-10,-10,-10,-10,-10,-10, -8, 0, 2, 2, 2, 4, 4, 4, 5, 8},
  128045. {-20,-20,-20,-20,-20,-20,-20,-14,-10, -4, -3, -3, -3, -3, -2, 0, 2},
  128046. {-20,-20,-20,-20,-20,-20,-20,-14,-10,-10,-10,-10,-10, -8, -8, -8, -5}}},
  128047. {{{-15,-15,-15,-15,-15,-15,-15,-10, -4, 1, 1, 1, 2, 3, 3, 4, 7},
  128048. {-20,-20,-20,-20,-20,-20,-20,-14,-10, -4, -3, -3, -3, -3, -2, -1, 1},
  128049. {-20,-20,-20,-20,-20,-20,-20,-14,-10,-10,-10,-10,-10, -8, -8, -8, -7}}},
  128050. {{{-15,-15,-15,-15,-15,-15,-15,-10, -4, 1, 1, 1, 2, 3, 3, 4, 7},
  128051. {-22,-22,-22,-22,-22,-22,-22,-16,-12, -6, -4, -4, -4, -4, -3, -1, 0},
  128052. {-24,-24,-24,-24,-24,-24,-24,-18,-14,-12,-12,-12,-12,-10,-10, -9, -8}}},
  128053. {{{-15,-15,-15,-15,-15,-15,-15,-10, -4, 1, 1, 1, 2, 3, 3, 4, 7},
  128054. {-24,-24,-24,-24,-24,-24,-24,-18,-14, -8, -6, -6, -6, -6, -5, -2, 0},
  128055. {-26,-26,-26,-26,-26,-26,-26,-18,-16,-15,-15,-15,-15,-13,-13,-12,-10}}},
  128056. {{{-15,-15,-15,-15,-15,-15,-15,-10, -4, 1, 1, 1, 2, 3, 3, 4, 7},
  128057. {-24,-24,-24,-24,-24,-24,-24,-18,-14,-10, -8, -8, -8, -8, -6, -4, 0},
  128058. {-26,-26,-26,-26,-26,-26,-26,-22,-20,-19,-19,-19,-19,-18,-17,-16,-12}}},
  128059. {{{-15,-15,-15,-15,-15,-15,-15,-10, -4, 0, 0, 0, 0, 1, 2, 3, 7},
  128060. {-26,-26,-26,-26,-26,-26,-26,-20,-16,-12,-10,-10,-10,-10, -8, -6, -2},
  128061. {-28,-28,-28,-28,-28,-28,-28,-26,-24,-24,-24,-24,-24,-24,-24,-20,-16}}},
  128062. {{{-22,-22,-22,-22,-22,-22,-22,-18,-14, -8, -4, -4, -4, -4, -4, -2, 2},
  128063. {-26,-26,-26,-26,-26,-26,-26,-22,-18,-16,-16,-16,-16,-14,-12,-10, -7},
  128064. {-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-24,-20}}},
  128065. {{{-24,-24,-24,-24,-24,-24,-24,-24,-24,-18,-14,-14,-14,-14,-14,-12,-10},
  128066. {-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-20},
  128067. {-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40}}},
  128068. };
  128069. static noise3 _psy_noisebias_impulse[12]={
  128070. {{{-10,-10,-10,-10,-10, -4, 0, 0, 4, 8, 8, 8, 8, 10, 12, 14, 20},
  128071. {-30,-30,-30,-30,-26,-20,-16, -8, -6, -6, -2, 2, 2, 3, 6, 6, 15},
  128072. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, -6, -4, -2}}},
  128073. {{{-10,-10,-10,-10,-10, -4, 0, 0, 4, 4, 8, 8, 8, 10, 12, 14, 20},
  128074. {-30,-30,-30,-30,-26,-22,-20,-14, -6, -2, 0, 0, 0, 0, 2, 3, 6},
  128075. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, -6, -4, -2}}},
  128076. {{{-12,-12,-12,-12,-12, -8, -6, -4, 0, 4, 4, 4, 4, 10, 12, 14, 20},
  128077. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -6, -4, -4, -2, -2, -2, -2, 2},
  128078. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -8,-10,-10, -8, -8, -8, -6, -4}}},
  128079. {{{-14,-14,-14,-14,-14,-10, -8, -6, -2, 2, 2, 2, 2, 8, 10, 10, 16},
  128080. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -6, -6, -6, -4, -4, -4, -2, 0},
  128081. {-30,-30,-30,-30,-26,-22,-20,-14,-10,-10,-10,-10,-10,-10,-10, -8, -4}}},
  128082. {{{-14,-14,-14,-14,-14,-10, -8, -6, -2, 2, 2, 2, 2, 6, 8, 8, 14},
  128083. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -6, -6, -6, -4, -4, -4, -2, 0},
  128084. {-30,-30,-30,-30,-26,-22,-20,-14,-10,-10,-10,-10,-10,-10,-10, -8, -4}}},
  128085. {{{-16,-16,-16,-16,-16,-12,-10, -6, -2, 0, 0, 0, 0, 4, 6, 6, 12},
  128086. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -6, -6, -6, -4, -4, -4, -2, 0},
  128087. {-30,-30,-30,-30,-26,-22,-20,-14,-10,-10,-10,-10,-10,-10,-10, -8, -4}}},
  128088. {{{-20,-20,-20,-20,-20,-18,-14,-10, -4, 0, 0, 0, 0, 4, 4, 6, 11},
  128089. {-32,-32,-32,-32,-28,-24,-22,-16,-10, -6, -8, -8, -6, -6, -6, -4, -2},
  128090. {-34,-34,-34,-34,-30,-26,-24,-18,-14,-12,-12,-12,-12,-12,-10, -9, -5}}},
  128091. {{{-20,-20,-20,-20,-20,-18,-14,-10, -4, 0, 0, 0, 0, 4, 4, 6, 11},
  128092. {-34,-34,-34,-34,-30,-30,-30,-24,-16,-16,-16,-16,-16,-16,-14,-14,-12},
  128093. {-36,-36,-36,-36,-36,-34,-28,-24,-20,-20,-20,-20,-20,-20,-20,-18,-16}}},
  128094. {{{-22,-22,-22,-22,-22,-20,-14,-10, -6, 0, 0, 0, 0, 4, 4, 6, 11},
  128095. {-34,-34,-34,-34,-30,-30,-30,-30,-26,-26,-26,-26,-26,-26,-26,-24,-22},
  128096. {-40,-40,-40,-40,-40,-40,-40,-32,-30,-30,-30,-30,-30,-30,-30,-30,-24}}},
  128097. {{{-24,-24,-24,-24,-24,-22,-14,-10, -6, -1, -1, -1, -1, 3, 3, 5, 10},
  128098. {-34,-34,-34,-34,-34,-32,-32,-30,-26,-26,-26,-26,-26,-26,-26,-26,-24},
  128099. {-40,-40,-40,-40,-40,-40,-40,-32,-30,-30,-30,-30,-30,-30,-30,-30,-24}}},
  128100. {{{-28,-28,-28,-28,-28,-28,-28,-20,-14, -8, -4, -4, -4, -4, -4, -2, 2},
  128101. {-36,-36,-36,-36,-34,-32,-32,-30,-26,-26,-26,-26,-26,-26,-26,-26,-26},
  128102. {-40,-40,-40,-40,-40,-40,-40,-32,-30,-30,-30,-30,-30,-30,-30,-24,-20}}},
  128103. {{{-30,-30,-30,-30,-30,-26,-24,-24,-24,-20,-16,-16,-16,-16,-16,-14,-12},
  128104. {-40,-40,-40,-40,-40,-40,-40,-40,-35,-30,-30,-30,-30,-30,-30,-30,-26},
  128105. {-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40}}},
  128106. };
  128107. static noise3 _psy_noisebias_padding[12]={
  128108. {{{-10,-10,-10,-10,-10, -4, 0, 0, 4, 8, 8, 8, 8, 10, 12, 14, 20},
  128109. {-30,-30,-30,-30,-26,-20,-16, -8, -6, -6, -2, 2, 2, 3, 6, 6, 15},
  128110. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, -6, -4, -2}}},
  128111. {{{-10,-10,-10,-10,-10, -4, 0, 0, 4, 8, 8, 8, 8, 10, 12, 14, 20},
  128112. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -4, -2, 2, 3, 6, 6, 8, 10},
  128113. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -4, -4, -4, -4, -4, -2, 0, 2}}},
  128114. {{{-12,-12,-12,-12,-12, -8, -6, -4, 0, 4, 4, 4, 4, 10, 12, 14, 20},
  128115. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -4, 0, 0, 0, 2, 2, 4, 8},
  128116. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -6, -6, -6, -6, -6, -4, -2, 0}}},
  128117. {{{-14,-14,-14,-14,-14,-10, -8, -6, -2, 2, 2, 2, 2, 8, 10, 10, 16},
  128118. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -6, -1, -1, -1, 0, 0, 2, 6},
  128119. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -8, -8, -8, -8, -8, -6, -4, -2}}},
  128120. {{{-14,-14,-14,-14,-14,-10, -8, -6, -2, 2, 2, 2, 2, 6, 8, 8, 14},
  128121. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -6, -1, -1, -1, 0, 0, 2, 6},
  128122. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -8, -8, -8, -8, -8, -6, -4, -2}}},
  128123. {{{-16,-16,-16,-16,-16,-12,-10, -6, -2, 0, 0, 0, 0, 4, 6, 6, 12},
  128124. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -6, -1, -1, -1, -1, 0, 2, 6},
  128125. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -8, -8, -8, -8, -8, -6, -4, -2}}},
  128126. {{{-20,-20,-20,-20,-20,-18,-14,-10, -4, 0, 0, 0, 0, 4, 6, 6, 12},
  128127. {-32,-32,-32,-32,-28,-24,-22,-16,-12, -6, -3, -3, -3, -3, -2, 0, 4},
  128128. {-34,-34,-34,-34,-30,-26,-24,-18,-14,-10,-10,-10,-10,-10, -8, -5, -3}}},
  128129. {{{-20,-20,-20,-20,-20,-18,-14,-10, -4, 0, 0, 0, 0, 4, 6, 6, 12},
  128130. {-34,-34,-34,-34,-30,-30,-24,-20,-14, -8, -4, -4, -4, -4, -3, -1, 4},
  128131. {-34,-34,-34,-34,-34,-30,-26,-20,-16,-13,-13,-13,-13,-13,-11, -8, -6}}},
  128132. {{{-20,-20,-20,-20,-20,-18,-14,-10, -4, 0, 0, 0, 0, 4, 6, 6, 12},
  128133. {-34,-34,-34,-34,-30,-30,-30,-24,-16,-10, -8, -6, -6, -6, -5, -3, 1},
  128134. {-34,-34,-34,-34,-32,-32,-28,-22,-18,-16,-16,-16,-16,-16,-14,-12,-10}}},
  128135. {{{-22,-22,-22,-22,-22,-20,-14,-10, -4, 0, 0, 0, 0, 3, 5, 5, 11},
  128136. {-34,-34,-34,-34,-30,-30,-30,-24,-16,-12,-10, -8, -8, -8, -7, -5, -2},
  128137. {-36,-36,-36,-36,-36,-34,-28,-22,-20,-20,-20,-20,-20,-20,-20,-16,-14}}},
  128138. {{{-28,-28,-28,-28,-28,-28,-28,-20,-14, -8, -2, -2, -2, -2, 0, 2, 6},
  128139. {-36,-36,-36,-36,-34,-32,-32,-24,-16,-12,-12,-12,-12,-12,-10, -8, -5},
  128140. {-40,-40,-40,-40,-40,-40,-40,-32,-26,-24,-24,-24,-24,-24,-24,-20,-18}}},
  128141. {{{-30,-30,-30,-30,-30,-26,-24,-24,-24,-20,-12,-12,-12,-12,-12,-10, -8},
  128142. {-40,-40,-40,-40,-40,-40,-40,-40,-35,-30,-25,-25,-25,-25,-25,-25,-15},
  128143. {-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40}}},
  128144. };
  128145. static noiseguard _psy_noiseguards_44[4]={
  128146. {3,3,15},
  128147. {3,3,15},
  128148. {10,10,100},
  128149. {10,10,100},
  128150. };
  128151. static int _psy_tone_suppress[12]={
  128152. -20,-20,-20,-20,-20,-24,-30,-40,-40,-45,-45,-45,
  128153. };
  128154. static int _psy_tone_0dB[12]={
  128155. 90,90,95,95,95,95,105,105,105,105,105,105,
  128156. };
  128157. static int _psy_noise_suppress[12]={
  128158. -20,-20,-24,-24,-24,-24,-30,-40,-40,-45,-45,-45,
  128159. };
  128160. static vorbis_info_psy _psy_info_template={
  128161. -1,
  128162. -140.,-140.,
  128163. {0.f,0.f,0.f}, 0.,0., -40.f, {0.},
  128164. 1, -0.f, .5f, .5f, 0,0,0,
  128165. {{-1},{-1},{-1}},{-1},105.f,
  128166. 0,0,-1,-1,0.,
  128167. };
  128168. static int _psy_ath_floater[12]={
  128169. -100,-100,-100,-100,-100,-100,-105,-105,-105,-105,-110,-120,
  128170. };
  128171. static int _psy_ath_abs[12]={
  128172. -130,-130,-130,-130,-140,-140,-140,-140,-140,-140,-140,-150,
  128173. };
  128174. static adj_stereo _psy_stereo_modes_44[12]={
  128175. {{ 4, 4, 4, 4, 4, 4, 4, 3, 2, 2, 1, 0, 0, 0, 0},
  128176. { 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 5, 4, 3},
  128177. { 1, 2, 3, 4, 4, 4, 4, 4, 4, 5, 6, 7, 8, 8, 8},
  128178. { 12,12.5, 13,13.5, 14,14.5, 15, 99, 99, 99, 99, 99, 99, 99, 99}},
  128179. {{ 4, 4, 4, 4, 4, 4, 4, 3, 2, 1, 0, 0, 0, 0, 0},
  128180. { 8, 8, 8, 8, 6, 6, 5, 5, 5, 5, 5, 5, 5, 4, 3},
  128181. { 1, 2, 3, 4, 4, 5, 6, 6, 6, 6, 6, 8, 8, 8, 8},
  128182. { 12,12.5, 13,13.5, 14,14.5, 15, 99, 99, 99, 99, 99, 99, 99, 99}},
  128183. {{ 3, 3, 3, 3, 3, 3, 3, 3, 2, 1, 0, 0, 0, 0, 0},
  128184. { 8, 8, 8, 8, 6, 6, 5, 5, 5, 5, 5, 5, 5, 4, 3},
  128185. { 1, 2, 3, 4, 4, 5, 6, 6, 6, 6, 6, 8, 8, 8, 8},
  128186. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  128187. {{ 3, 3, 3, 3, 3, 3, 3, 2, 1, 1, 0, 0, 0, 0, 0},
  128188. { 8, 8, 6, 6, 5, 5, 4, 4, 4, 4, 4, 4, 3, 2, 1},
  128189. { 3, 4, 4, 5, 5, 6, 6, 6, 6, 6, 6, 8, 8, 8, 8},
  128190. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  128191. {{ 2, 2, 2, 2, 2, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0},
  128192. { 5, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 3, 2, 1},
  128193. { 4, 4, 5, 6, 6, 6, 6, 6, 8, 8, 10, 10, 10, 10, 10},
  128194. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  128195. {{ 2, 2, 2, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  128196. { 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 3, 3, 2, 1, 0},
  128197. { 6, 6, 6, 8, 8, 8, 8, 8, 8, 8, 10, 10, 10, 10, 10},
  128198. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  128199. {{ 2, 2, 2, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  128200. { 3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2, 0, 0, 0, 0},
  128201. { 6, 7, 8, 8, 8, 10, 10, 12, 12, 12, 12, 12, 12, 12, 12},
  128202. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  128203. {{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  128204. { 3, 3, 3, 2, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  128205. { 8, 8, 8, 10, 10, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12},
  128206. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  128207. {{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  128208. { 3, 3, 3, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  128209. { 8, 8, 10, 10, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12},
  128210. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  128211. {{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  128212. { 2, 2, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  128213. { 8, 10, 10, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12},
  128214. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  128215. {{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  128216. { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  128217. { 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4},
  128218. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  128219. {{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  128220. { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  128221. { 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4},
  128222. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  128223. };
  128224. static att3 _psy_tone_masteratt_44[12]={
  128225. {{ 35, 21, 9}, 0, 0}, /* -1 */
  128226. {{ 30, 20, 8}, -2, 1.25}, /* 0 */
  128227. /* 1 */
  128228. {{ 25, 12, 2}, 0, 0}, /* 1 */
  128229. /* 2 */
  128230. {{ 20, 9, -3}, 0, 0}, /* 2 */
  128231. {{ 20, 9, -4}, 0, 0}, /* 3 */
  128232. {{ 20, 9, -4}, 0, 0}, /* 4 */
  128233. {{ 20, 6, -6}, 0, 0}, /* 5 */
  128234. {{ 20, 3, -10}, 0, 0}, /* 6 */
  128235. {{ 18, 1, -14}, 0, 0}, /* 7 */
  128236. {{ 18, 0, -16}, 0, 0}, /* 8 */
  128237. {{ 18, -2, -16}, 0, 0}, /* 9 */
  128238. {{ 12, -2, -20}, 0, 0}, /* 10 */
  128239. };
  128240. static double _psy_lowpass_44[12]={
  128241. 13.9,15.1,15.8,16.5,17.2,18.9,20.1,48.,999.,999.,999.,999.
  128242. };
  128243. static int _noise_start_short_44[11]={
  128244. 32,16,16,16,32,9999,9999,9999,9999,9999,9999
  128245. };
  128246. static int _noise_start_long_44[11]={
  128247. 256,128,128,256,512,9999,9999,9999,9999,9999,9999
  128248. };
  128249. static int _noise_part_short_44[11]={
  128250. 8,8,8,8,8,8,8,8,8,8,8
  128251. };
  128252. static int _noise_part_long_44[11]={
  128253. 32,32,32,32,32,32,32,32,32,32,32
  128254. };
  128255. static double _noise_thresh_44[11]={
  128256. .2,.2,.2,.4,.6,9999.,9999.,9999.,9999.,9999.,9999.,
  128257. };
  128258. static double _noise_thresh_5only[2]={
  128259. .5,.5,
  128260. };
  128261. /*** End of inlined file: psych_44.h ***/
  128262. static double rate_mapping_44_stereo[12]={
  128263. 22500.,32000.,40000.,48000.,56000.,64000.,
  128264. 80000.,96000.,112000.,128000.,160000.,250001.
  128265. };
  128266. static double quality_mapping_44[12]={
  128267. -.1,.0,.1,.2,.3,.4,.5,.6,.7,.8,.9,1.0
  128268. };
  128269. static int blocksize_short_44[11]={
  128270. 512,256,256,256,256,256,256,256,256,256,256
  128271. };
  128272. static int blocksize_long_44[11]={
  128273. 4096,2048,2048,2048,2048,2048,2048,2048,2048,2048,2048
  128274. };
  128275. static double _psy_compand_short_mapping[12]={
  128276. 0.5, 1., 1., 1.3, 1.6, 2., 2., 2., 2., 2., 2., 2.
  128277. };
  128278. static double _psy_compand_long_mapping[12]={
  128279. 3.5, 4., 4., 4.3, 4.6, 5., 5., 5., 5., 5., 5., 5.
  128280. };
  128281. static double _global_mapping_44[12]={
  128282. 0., 1., 1., 1.5, 2., 2., 2.5, 2.7, 3.0, 3.7, 4., 4.
  128283. };
  128284. static int _floor_short_mapping_44[11]={
  128285. 1,0,0,2,2,4,5,5,5,5,5
  128286. };
  128287. static int _floor_long_mapping_44[11]={
  128288. 8,7,7,7,7,7,7,7,7,7,7
  128289. };
  128290. ve_setup_data_template ve_setup_44_stereo={
  128291. 11,
  128292. rate_mapping_44_stereo,
  128293. quality_mapping_44,
  128294. 2,
  128295. 40000,
  128296. 50000,
  128297. blocksize_short_44,
  128298. blocksize_long_44,
  128299. _psy_tone_masteratt_44,
  128300. _psy_tone_0dB,
  128301. _psy_tone_suppress,
  128302. _vp_tonemask_adj_otherblock,
  128303. _vp_tonemask_adj_longblock,
  128304. _vp_tonemask_adj_otherblock,
  128305. _psy_noiseguards_44,
  128306. _psy_noisebias_impulse,
  128307. _psy_noisebias_padding,
  128308. _psy_noisebias_trans,
  128309. _psy_noisebias_long,
  128310. _psy_noise_suppress,
  128311. _psy_compand_44,
  128312. _psy_compand_short_mapping,
  128313. _psy_compand_long_mapping,
  128314. {_noise_start_short_44,_noise_start_long_44},
  128315. {_noise_part_short_44,_noise_part_long_44},
  128316. _noise_thresh_44,
  128317. _psy_ath_floater,
  128318. _psy_ath_abs,
  128319. _psy_lowpass_44,
  128320. _psy_global_44,
  128321. _global_mapping_44,
  128322. _psy_stereo_modes_44,
  128323. _floor_books,
  128324. _floor,
  128325. _floor_short_mapping_44,
  128326. _floor_long_mapping_44,
  128327. _mapres_template_44_stereo
  128328. };
  128329. /*** End of inlined file: setup_44.h ***/
  128330. /*** Start of inlined file: setup_44u.h ***/
  128331. /*** Start of inlined file: residue_44u.h ***/
  128332. /*** Start of inlined file: res_books_uncoupled.h ***/
  128333. static long _vq_quantlist__16u0__p1_0[] = {
  128334. 1,
  128335. 0,
  128336. 2,
  128337. };
  128338. static long _vq_lengthlist__16u0__p1_0[] = {
  128339. 1, 4, 4, 5, 7, 7, 5, 7, 8, 5, 8, 8, 8,10,10, 8,
  128340. 10,11, 5, 8, 8, 8,10,10, 8,10,10, 4, 9, 9, 9,12,
  128341. 11, 8,11,11, 8,12,11,10,12,14,10,13,13, 7,11,11,
  128342. 10,14,12,11,14,14, 4, 9, 9, 8,11,11, 9,11,12, 7,
  128343. 11,11,10,13,14,10,12,14, 8,11,12,10,14,14,10,13,
  128344. 12,
  128345. };
  128346. static float _vq_quantthresh__16u0__p1_0[] = {
  128347. -0.5, 0.5,
  128348. };
  128349. static long _vq_quantmap__16u0__p1_0[] = {
  128350. 1, 0, 2,
  128351. };
  128352. static encode_aux_threshmatch _vq_auxt__16u0__p1_0 = {
  128353. _vq_quantthresh__16u0__p1_0,
  128354. _vq_quantmap__16u0__p1_0,
  128355. 3,
  128356. 3
  128357. };
  128358. static static_codebook _16u0__p1_0 = {
  128359. 4, 81,
  128360. _vq_lengthlist__16u0__p1_0,
  128361. 1, -535822336, 1611661312, 2, 0,
  128362. _vq_quantlist__16u0__p1_0,
  128363. NULL,
  128364. &_vq_auxt__16u0__p1_0,
  128365. NULL,
  128366. 0
  128367. };
  128368. static long _vq_quantlist__16u0__p2_0[] = {
  128369. 1,
  128370. 0,
  128371. 2,
  128372. };
  128373. static long _vq_lengthlist__16u0__p2_0[] = {
  128374. 2, 4, 4, 5, 6, 6, 5, 6, 6, 5, 7, 7, 7, 8, 9, 7,
  128375. 8, 9, 5, 7, 7, 7, 9, 8, 7, 9, 7, 4, 7, 7, 7, 9,
  128376. 9, 7, 8, 8, 6, 9, 8, 7, 8,11, 9,11,10, 6, 8, 9,
  128377. 8,11, 8, 9,10,11, 4, 7, 7, 7, 8, 8, 7, 9, 9, 6,
  128378. 9, 8, 9,11,10, 8, 8,11, 6, 8, 9, 9,10,11, 8,11,
  128379. 8,
  128380. };
  128381. static float _vq_quantthresh__16u0__p2_0[] = {
  128382. -0.5, 0.5,
  128383. };
  128384. static long _vq_quantmap__16u0__p2_0[] = {
  128385. 1, 0, 2,
  128386. };
  128387. static encode_aux_threshmatch _vq_auxt__16u0__p2_0 = {
  128388. _vq_quantthresh__16u0__p2_0,
  128389. _vq_quantmap__16u0__p2_0,
  128390. 3,
  128391. 3
  128392. };
  128393. static static_codebook _16u0__p2_0 = {
  128394. 4, 81,
  128395. _vq_lengthlist__16u0__p2_0,
  128396. 1, -535822336, 1611661312, 2, 0,
  128397. _vq_quantlist__16u0__p2_0,
  128398. NULL,
  128399. &_vq_auxt__16u0__p2_0,
  128400. NULL,
  128401. 0
  128402. };
  128403. static long _vq_quantlist__16u0__p3_0[] = {
  128404. 2,
  128405. 1,
  128406. 3,
  128407. 0,
  128408. 4,
  128409. };
  128410. static long _vq_lengthlist__16u0__p3_0[] = {
  128411. 1, 5, 5, 7, 7, 6, 7, 7, 8, 8, 6, 7, 8, 8, 8, 8,
  128412. 9, 9,11,11, 8, 9, 9,11,11, 6, 9, 8,10,10, 8,10,
  128413. 10,11,11, 8,10,10,11,11,10,11,10,13,12, 9,11,10,
  128414. 13,13, 6, 8, 9,10,10, 8,10,10,11,11, 8,10,10,11,
  128415. 11, 9,10,11,13,12,10,10,11,12,12, 8,11,11,14,13,
  128416. 10,12,11,15,13, 9,12,11,15,14,12,14,13,16,14,12,
  128417. 13,13,17,14, 8,11,11,13,14, 9,11,12,14,15,10,11,
  128418. 12,13,15,11,13,13,14,16,12,13,14,14,16, 5, 9, 9,
  128419. 11,11, 9,11,11,12,12, 8,11,11,12,12,11,12,12,15,
  128420. 14,10,12,12,15,15, 8,11,11,13,12,10,12,12,13,13,
  128421. 10,12,12,14,13,12,12,13,14,15,11,13,13,17,16, 7,
  128422. 11,11,13,13,10,12,12,14,13,10,12,12,13,14,12,13,
  128423. 12,15,14,11,13,13,15,14, 9,12,12,16,15,11,13,13,
  128424. 17,16,10,13,13,16,16,13,14,15,15,16,13,15,14,19,
  128425. 17, 9,12,12,14,16,11,13,13,15,16,10,13,13,17,16,
  128426. 13,14,13,17,15,12,15,15,16,17, 5, 9, 9,11,11, 8,
  128427. 11,11,13,12, 9,11,11,12,12,10,12,12,14,15,11,12,
  128428. 12,14,14, 7,11,10,13,12,10,12,12,14,13,10,11,12,
  128429. 13,13,11,13,13,15,16,12,12,13,15,15, 7,11,11,13,
  128430. 13,10,13,13,14,14,10,12,12,13,13,11,13,13,16,15,
  128431. 12,13,13,15,14, 9,12,12,15,15,10,13,13,17,16,11,
  128432. 12,13,15,15,12,15,14,18,18,13,14,14,16,17, 9,12,
  128433. 12,15,16,10,13,13,15,16,11,13,13,15,16,13,15,15,
  128434. 17,17,13,15,14,16,15, 7,11,11,15,16,10,13,12,16,
  128435. 17,10,12,13,15,17,15,16,16,18,17,13,15,15,17,18,
  128436. 8,12,12,16,16,11,13,14,17,18,11,13,13,18,16,15,
  128437. 17,16,17,19,14,15,15,17,16, 8,12,12,16,15,11,14,
  128438. 13,18,17,11,13,14,18,17,15,16,16,18,17,13,16,16,
  128439. 18,18,11,15,14,18,17,13,14,15,18, 0,12,15,15, 0,
  128440. 17,17,16,17,17,18,14,16,18,18, 0,11,14,14,17, 0,
  128441. 12,15,14,17,19,12,15,14,18, 0,15,18,16, 0,17,14,
  128442. 18,16,18, 0, 7,11,11,16,15,10,12,12,18,16,10,13,
  128443. 13,16,15,13,15,14,17,17,14,16,16,19,18, 8,12,12,
  128444. 16,16,11,13,13,18,16,11,13,14,17,16,14,15,15,19,
  128445. 18,15,16,16, 0,19, 8,12,12,16,17,11,13,13,17,17,
  128446. 11,14,13,17,17,13,15,15,17,19,15,17,17,19, 0,11,
  128447. 14,15,19,17,12,15,16,18,18,12,14,15,19,17,14,16,
  128448. 17, 0,18,16,16,19,17, 0,11,14,14,18,19,12,15,14,
  128449. 17,17,13,16,14,17,16,14,17,16,18,18,15,18,15, 0,
  128450. 18,
  128451. };
  128452. static float _vq_quantthresh__16u0__p3_0[] = {
  128453. -1.5, -0.5, 0.5, 1.5,
  128454. };
  128455. static long _vq_quantmap__16u0__p3_0[] = {
  128456. 3, 1, 0, 2, 4,
  128457. };
  128458. static encode_aux_threshmatch _vq_auxt__16u0__p3_0 = {
  128459. _vq_quantthresh__16u0__p3_0,
  128460. _vq_quantmap__16u0__p3_0,
  128461. 5,
  128462. 5
  128463. };
  128464. static static_codebook _16u0__p3_0 = {
  128465. 4, 625,
  128466. _vq_lengthlist__16u0__p3_0,
  128467. 1, -533725184, 1611661312, 3, 0,
  128468. _vq_quantlist__16u0__p3_0,
  128469. NULL,
  128470. &_vq_auxt__16u0__p3_0,
  128471. NULL,
  128472. 0
  128473. };
  128474. static long _vq_quantlist__16u0__p4_0[] = {
  128475. 2,
  128476. 1,
  128477. 3,
  128478. 0,
  128479. 4,
  128480. };
  128481. static long _vq_lengthlist__16u0__p4_0[] = {
  128482. 3, 5, 5, 8, 8, 6, 6, 6, 9, 9, 6, 6, 6, 9, 9, 9,
  128483. 10, 9,11,11, 9, 9, 9,11,11, 6, 7, 7,10,10, 7, 7,
  128484. 8,10,10, 7, 7, 8,10,10,10,10,10,11,12, 9,10,10,
  128485. 11,12, 6, 7, 7,10,10, 7, 8, 7,10,10, 7, 8, 7,10,
  128486. 10,10,11,10,12,11,10,10,10,13,10, 9,10,10,12,12,
  128487. 10,11,10,14,12, 9,11,11,13,13,11,12,13,13,13,11,
  128488. 12,12,15,13, 9,10,10,12,13, 9,11,10,12,13,10,10,
  128489. 11,12,13,11,12,12,12,13,11,12,12,13,13, 5, 7, 7,
  128490. 10,10, 7, 8, 8,10,10, 7, 8, 8,10,10,10,11,10,12,
  128491. 13,10,10,11,12,12, 6, 8, 8,11,10, 7, 8, 9,10,12,
  128492. 8, 9, 9,11,11,11,10,11,11,12,10,11,11,13,12, 7,
  128493. 8, 8,10,11, 8, 9, 8,11,10, 8, 9, 9,11,11,10,12,
  128494. 10,13,11,10,11,11,13,13,10,11,10,14,13,10,10,11,
  128495. 13,13,10,12,11,14,13,12,11,13,12,13,13,12,13,14,
  128496. 14,10,11,11,13,13,10,11,10,12,13,10,12,12,12,14,
  128497. 12,12,12,14,12,12,13,12,17,15, 5, 7, 7,10,10, 7,
  128498. 8, 8,10,10, 7, 8, 8,11,10,10,10,11,12,12,10,11,
  128499. 11,12,13, 6, 8, 8,11,10, 8, 9, 9,11,11, 7, 8, 9,
  128500. 10,11,11,11,11,12,12,10,10,11,12,13, 6, 8, 8,10,
  128501. 11, 8, 9, 9,11,11, 7, 9, 7,11,10,10,12,12,13,13,
  128502. 11,11,10,13,11, 9,11,10,14,13,11,11,11,15,13,10,
  128503. 10,11,13,13,12,13,13,14,14,12,11,12,12,13,10,11,
  128504. 11,12,13,10,11,12,13,13,10,11,10,13,12,12,12,13,
  128505. 14, 0,12,13,11,13,11, 8,10,10,13,13,10,11,11,14,
  128506. 13,10,11,11,13,12,13,14,14,14,15,12,12,12,15,14,
  128507. 9,11,10,13,12,10,10,11,13,14,11,11,11,15,12,13,
  128508. 12,14,15,16,13,13,13,14,13, 9,11,11,12,12,10,12,
  128509. 11,13,13,10,11,11,13,14,13,13,13,15,15,13,13,14,
  128510. 17,15,11,12,12,14,14,10,11,12,13,15,12,13,13, 0,
  128511. 15,13,11,14,12,16,14,16,14, 0,15,11,12,12,14,16,
  128512. 11,13,12,16,15,12,13,13,14,15,12,14,12,15,13,15,
  128513. 14,14,16,16, 8,10,10,13,13,10,11,10,13,14,10,11,
  128514. 11,13,13,13,13,12,14,14,14,13,13,16,17, 9,10,10,
  128515. 12,14,10,12,11,14,13,10,11,12,13,14,12,12,12,15,
  128516. 15,13,13,13,14,14, 9,10,10,13,13,10,11,12,12,14,
  128517. 10,11,10,13,13,13,13,13,14,16,13,13,13,14,14,11,
  128518. 12,13,15,13,12,14,13,14,16,12,12,13,13,14,13,14,
  128519. 14,17,15,13,12,17,13,16,11,12,13,14,15,12,13,14,
  128520. 14,17,11,12,11,14,14,13,16,14,16, 0,14,15,11,15,
  128521. 11,
  128522. };
  128523. static float _vq_quantthresh__16u0__p4_0[] = {
  128524. -1.5, -0.5, 0.5, 1.5,
  128525. };
  128526. static long _vq_quantmap__16u0__p4_0[] = {
  128527. 3, 1, 0, 2, 4,
  128528. };
  128529. static encode_aux_threshmatch _vq_auxt__16u0__p4_0 = {
  128530. _vq_quantthresh__16u0__p4_0,
  128531. _vq_quantmap__16u0__p4_0,
  128532. 5,
  128533. 5
  128534. };
  128535. static static_codebook _16u0__p4_0 = {
  128536. 4, 625,
  128537. _vq_lengthlist__16u0__p4_0,
  128538. 1, -533725184, 1611661312, 3, 0,
  128539. _vq_quantlist__16u0__p4_0,
  128540. NULL,
  128541. &_vq_auxt__16u0__p4_0,
  128542. NULL,
  128543. 0
  128544. };
  128545. static long _vq_quantlist__16u0__p5_0[] = {
  128546. 4,
  128547. 3,
  128548. 5,
  128549. 2,
  128550. 6,
  128551. 1,
  128552. 7,
  128553. 0,
  128554. 8,
  128555. };
  128556. static long _vq_lengthlist__16u0__p5_0[] = {
  128557. 1, 4, 4, 7, 7, 7, 7, 9, 9, 4, 6, 6, 8, 8, 8, 8,
  128558. 9, 9, 4, 6, 6, 8, 8, 8, 8, 9, 9, 7, 8, 8, 9, 9,
  128559. 9, 9,11,10, 7, 8, 8, 9, 9, 9, 9,10,11, 7, 8, 8,
  128560. 9, 9,10,10,11,11, 7, 8, 8, 9, 9,10,10,11,11, 9,
  128561. 9, 9,10,10,11,11,12,12, 9, 9, 9,10,10,11,11,12,
  128562. 12,
  128563. };
  128564. static float _vq_quantthresh__16u0__p5_0[] = {
  128565. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  128566. };
  128567. static long _vq_quantmap__16u0__p5_0[] = {
  128568. 7, 5, 3, 1, 0, 2, 4, 6,
  128569. 8,
  128570. };
  128571. static encode_aux_threshmatch _vq_auxt__16u0__p5_0 = {
  128572. _vq_quantthresh__16u0__p5_0,
  128573. _vq_quantmap__16u0__p5_0,
  128574. 9,
  128575. 9
  128576. };
  128577. static static_codebook _16u0__p5_0 = {
  128578. 2, 81,
  128579. _vq_lengthlist__16u0__p5_0,
  128580. 1, -531628032, 1611661312, 4, 0,
  128581. _vq_quantlist__16u0__p5_0,
  128582. NULL,
  128583. &_vq_auxt__16u0__p5_0,
  128584. NULL,
  128585. 0
  128586. };
  128587. static long _vq_quantlist__16u0__p6_0[] = {
  128588. 6,
  128589. 5,
  128590. 7,
  128591. 4,
  128592. 8,
  128593. 3,
  128594. 9,
  128595. 2,
  128596. 10,
  128597. 1,
  128598. 11,
  128599. 0,
  128600. 12,
  128601. };
  128602. static long _vq_lengthlist__16u0__p6_0[] = {
  128603. 1, 4, 4, 7, 7,10,10,12,12,13,13,18,17, 3, 6, 6,
  128604. 9, 9,11,11,13,13,14,14,18,17, 3, 6, 6, 9, 9,11,
  128605. 11,13,13,14,14,17,18, 7, 9, 9,11,11,13,13,14,14,
  128606. 15,15, 0, 0, 7, 9, 9,11,11,13,13,14,14,15,16,19,
  128607. 18,10,11,11,13,13,14,14,16,15,17,18, 0, 0,10,11,
  128608. 11,13,13,14,14,15,15,16,18, 0, 0,11,13,13,14,14,
  128609. 15,15,17,17, 0,19, 0, 0,11,13,13,14,14,14,15,16,
  128610. 18, 0,19, 0, 0,13,14,14,15,15,18,17,18,18, 0,19,
  128611. 0, 0,13,14,14,15,16,16,16,18,18,19, 0, 0, 0,16,
  128612. 17,17, 0,17,19,19, 0,19, 0, 0, 0, 0,16,19,16,17,
  128613. 18, 0,19, 0, 0, 0, 0, 0, 0,
  128614. };
  128615. static float _vq_quantthresh__16u0__p6_0[] = {
  128616. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  128617. 12.5, 17.5, 22.5, 27.5,
  128618. };
  128619. static long _vq_quantmap__16u0__p6_0[] = {
  128620. 11, 9, 7, 5, 3, 1, 0, 2,
  128621. 4, 6, 8, 10, 12,
  128622. };
  128623. static encode_aux_threshmatch _vq_auxt__16u0__p6_0 = {
  128624. _vq_quantthresh__16u0__p6_0,
  128625. _vq_quantmap__16u0__p6_0,
  128626. 13,
  128627. 13
  128628. };
  128629. static static_codebook _16u0__p6_0 = {
  128630. 2, 169,
  128631. _vq_lengthlist__16u0__p6_0,
  128632. 1, -526516224, 1616117760, 4, 0,
  128633. _vq_quantlist__16u0__p6_0,
  128634. NULL,
  128635. &_vq_auxt__16u0__p6_0,
  128636. NULL,
  128637. 0
  128638. };
  128639. static long _vq_quantlist__16u0__p6_1[] = {
  128640. 2,
  128641. 1,
  128642. 3,
  128643. 0,
  128644. 4,
  128645. };
  128646. static long _vq_lengthlist__16u0__p6_1[] = {
  128647. 1, 4, 5, 6, 6, 4, 6, 6, 6, 6, 4, 6, 6, 6, 6, 6,
  128648. 6, 6, 7, 7, 6, 6, 6, 7, 7,
  128649. };
  128650. static float _vq_quantthresh__16u0__p6_1[] = {
  128651. -1.5, -0.5, 0.5, 1.5,
  128652. };
  128653. static long _vq_quantmap__16u0__p6_1[] = {
  128654. 3, 1, 0, 2, 4,
  128655. };
  128656. static encode_aux_threshmatch _vq_auxt__16u0__p6_1 = {
  128657. _vq_quantthresh__16u0__p6_1,
  128658. _vq_quantmap__16u0__p6_1,
  128659. 5,
  128660. 5
  128661. };
  128662. static static_codebook _16u0__p6_1 = {
  128663. 2, 25,
  128664. _vq_lengthlist__16u0__p6_1,
  128665. 1, -533725184, 1611661312, 3, 0,
  128666. _vq_quantlist__16u0__p6_1,
  128667. NULL,
  128668. &_vq_auxt__16u0__p6_1,
  128669. NULL,
  128670. 0
  128671. };
  128672. static long _vq_quantlist__16u0__p7_0[] = {
  128673. 1,
  128674. 0,
  128675. 2,
  128676. };
  128677. static long _vq_lengthlist__16u0__p7_0[] = {
  128678. 1, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  128679. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  128680. 8, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  128681. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  128682. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  128683. 7,
  128684. };
  128685. static float _vq_quantthresh__16u0__p7_0[] = {
  128686. -157.5, 157.5,
  128687. };
  128688. static long _vq_quantmap__16u0__p7_0[] = {
  128689. 1, 0, 2,
  128690. };
  128691. static encode_aux_threshmatch _vq_auxt__16u0__p7_0 = {
  128692. _vq_quantthresh__16u0__p7_0,
  128693. _vq_quantmap__16u0__p7_0,
  128694. 3,
  128695. 3
  128696. };
  128697. static static_codebook _16u0__p7_0 = {
  128698. 4, 81,
  128699. _vq_lengthlist__16u0__p7_0,
  128700. 1, -518803456, 1628680192, 2, 0,
  128701. _vq_quantlist__16u0__p7_0,
  128702. NULL,
  128703. &_vq_auxt__16u0__p7_0,
  128704. NULL,
  128705. 0
  128706. };
  128707. static long _vq_quantlist__16u0__p7_1[] = {
  128708. 7,
  128709. 6,
  128710. 8,
  128711. 5,
  128712. 9,
  128713. 4,
  128714. 10,
  128715. 3,
  128716. 11,
  128717. 2,
  128718. 12,
  128719. 1,
  128720. 13,
  128721. 0,
  128722. 14,
  128723. };
  128724. static long _vq_lengthlist__16u0__p7_1[] = {
  128725. 1, 5, 5, 6, 5, 9,10,11,11,10,10,10,10,10,10, 5,
  128726. 8, 8, 8,10,10,10,10,10,10,10,10,10,10,10, 5, 8,
  128727. 9, 9, 9,10,10,10,10,10,10,10,10,10,10, 5,10, 8,
  128728. 10,10,10,10,10,10,10,10,10,10,10,10, 4, 8, 9,10,
  128729. 10,10,10,10,10,10,10,10,10,10,10, 9,10,10,10,10,
  128730. 10,10,10,10,10,10,10,10,10,10, 9,10,10,10,10,10,
  128731. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  128732. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  128733. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  128734. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  128735. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  128736. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  128737. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  128738. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  128739. 10,
  128740. };
  128741. static float _vq_quantthresh__16u0__p7_1[] = {
  128742. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  128743. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  128744. };
  128745. static long _vq_quantmap__16u0__p7_1[] = {
  128746. 13, 11, 9, 7, 5, 3, 1, 0,
  128747. 2, 4, 6, 8, 10, 12, 14,
  128748. };
  128749. static encode_aux_threshmatch _vq_auxt__16u0__p7_1 = {
  128750. _vq_quantthresh__16u0__p7_1,
  128751. _vq_quantmap__16u0__p7_1,
  128752. 15,
  128753. 15
  128754. };
  128755. static static_codebook _16u0__p7_1 = {
  128756. 2, 225,
  128757. _vq_lengthlist__16u0__p7_1,
  128758. 1, -520986624, 1620377600, 4, 0,
  128759. _vq_quantlist__16u0__p7_1,
  128760. NULL,
  128761. &_vq_auxt__16u0__p7_1,
  128762. NULL,
  128763. 0
  128764. };
  128765. static long _vq_quantlist__16u0__p7_2[] = {
  128766. 10,
  128767. 9,
  128768. 11,
  128769. 8,
  128770. 12,
  128771. 7,
  128772. 13,
  128773. 6,
  128774. 14,
  128775. 5,
  128776. 15,
  128777. 4,
  128778. 16,
  128779. 3,
  128780. 17,
  128781. 2,
  128782. 18,
  128783. 1,
  128784. 19,
  128785. 0,
  128786. 20,
  128787. };
  128788. static long _vq_lengthlist__16u0__p7_2[] = {
  128789. 1, 6, 6, 7, 8, 7, 7,10, 9,10, 9,11,10, 9,11,10,
  128790. 9, 9, 9, 9,10, 6, 8, 7, 9, 9, 8, 8,10,10, 9,11,
  128791. 11,12,12,10, 9,11, 9,12,10, 9, 6, 9, 8, 9,12, 8,
  128792. 8,11, 9,11,11,12,11,12,12,10,11,11,10,10,11, 7,
  128793. 10, 9, 9, 9, 9, 9,10, 9,10, 9,10,10,12,10,10,10,
  128794. 11,12,10,10, 7, 9, 9, 9,10, 9, 9,10,10, 9, 9, 9,
  128795. 11,11,10,10,10,10, 9, 9,12, 7, 9,10, 9,11, 9,10,
  128796. 9,10,11,11,11,10,11,12, 9,12,11,10,10,10, 7, 9,
  128797. 9, 9, 9,10,12,10, 9,11,12,10,11,12,12,11, 9,10,
  128798. 11,10,11, 7, 9,10,10,11,10, 9,10,11,11,11,10,12,
  128799. 12,12,11,11,10,11,11,12, 8, 9,10,12,11,10,10,12,
  128800. 12,12,12,12,10,11,11, 9,11,10,12,11,11, 8, 9,10,
  128801. 10,11,12,11,11,10,10,10,12,12,12, 9,10,12,12,12,
  128802. 12,12, 8,10,11,10,10,12, 9,11,12,12,11,12,12,12,
  128803. 12,10,12,10,10,10,10, 8,12,11,11,11,10,10,11,12,
  128804. 12,12,12,11,12,12,12,11,11,11,12,10, 9,10,10,12,
  128805. 10,12,10,12,12,10,10,10,11,12,12,12,11,12,12,12,
  128806. 11,10,11,12,12,12,11,12,12,11,12,12,11,12,12,12,
  128807. 12,11,12,12,10,10,10,10,11,11,12,11,12,12,12,12,
  128808. 12,12,12,11,12,11,10,11,11,12,11,11, 9,10,10,10,
  128809. 12,10,10,11, 9,11,12,11,12,11,12,12,10,11,10,12,
  128810. 9, 9, 9,12,11,10,11,10,12,10,12,10,12,12,12,11,
  128811. 11,11,11,11,10, 9,10,10,11,10,11,11,12,11,10,11,
  128812. 12,12,12,11,11, 9,12,10,12, 9,10,12,10,10,11,10,
  128813. 11,11,12,11,10,11,10,11,11,11,11,12,11,11,10, 9,
  128814. 10,10,10, 9,11,11,10, 9,12,10,11,12,11,12,12,11,
  128815. 12,11,12,11,10,11,10,12,11,12,11,12,11,12,10,11,
  128816. 10,10,12,11,10,11,11,11,10,
  128817. };
  128818. static float _vq_quantthresh__16u0__p7_2[] = {
  128819. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  128820. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  128821. 6.5, 7.5, 8.5, 9.5,
  128822. };
  128823. static long _vq_quantmap__16u0__p7_2[] = {
  128824. 19, 17, 15, 13, 11, 9, 7, 5,
  128825. 3, 1, 0, 2, 4, 6, 8, 10,
  128826. 12, 14, 16, 18, 20,
  128827. };
  128828. static encode_aux_threshmatch _vq_auxt__16u0__p7_2 = {
  128829. _vq_quantthresh__16u0__p7_2,
  128830. _vq_quantmap__16u0__p7_2,
  128831. 21,
  128832. 21
  128833. };
  128834. static static_codebook _16u0__p7_2 = {
  128835. 2, 441,
  128836. _vq_lengthlist__16u0__p7_2,
  128837. 1, -529268736, 1611661312, 5, 0,
  128838. _vq_quantlist__16u0__p7_2,
  128839. NULL,
  128840. &_vq_auxt__16u0__p7_2,
  128841. NULL,
  128842. 0
  128843. };
  128844. static long _huff_lengthlist__16u0__single[] = {
  128845. 3, 5, 8, 7,14, 8, 9,19, 5, 2, 5, 5, 9, 6, 9,19,
  128846. 8, 4, 5, 7, 8, 9,13,19, 7, 4, 6, 5, 9, 6, 9,19,
  128847. 12, 8, 7, 9,10,11,13,19, 8, 5, 8, 6, 9, 6, 7,19,
  128848. 8, 8,10, 7, 7, 4, 5,19,12,17,19,15,18,13,11,18,
  128849. };
  128850. static static_codebook _huff_book__16u0__single = {
  128851. 2, 64,
  128852. _huff_lengthlist__16u0__single,
  128853. 0, 0, 0, 0, 0,
  128854. NULL,
  128855. NULL,
  128856. NULL,
  128857. NULL,
  128858. 0
  128859. };
  128860. static long _huff_lengthlist__16u1__long[] = {
  128861. 3, 6,10, 8,12, 8,14, 8,14,19, 5, 3, 5, 5, 7, 6,
  128862. 11, 7,16,19, 7, 5, 6, 7, 7, 9,11,12,19,19, 6, 4,
  128863. 7, 5, 7, 6,10, 7,18,18, 8, 6, 7, 7, 7, 7, 8, 9,
  128864. 18,18, 7, 5, 8, 5, 7, 5, 8, 6,18,18,12, 9,10, 9,
  128865. 9, 9, 8, 9,18,18, 8, 7,10, 6, 8, 5, 6, 4,11,18,
  128866. 11,15,16,12,11, 8, 8, 6, 9,18,14,18,18,18,16,16,
  128867. 16,13,16,18,
  128868. };
  128869. static static_codebook _huff_book__16u1__long = {
  128870. 2, 100,
  128871. _huff_lengthlist__16u1__long,
  128872. 0, 0, 0, 0, 0,
  128873. NULL,
  128874. NULL,
  128875. NULL,
  128876. NULL,
  128877. 0
  128878. };
  128879. static long _vq_quantlist__16u1__p1_0[] = {
  128880. 1,
  128881. 0,
  128882. 2,
  128883. };
  128884. static long _vq_lengthlist__16u1__p1_0[] = {
  128885. 1, 4, 4, 5, 7, 7, 5, 7, 7, 5, 8, 7, 7,10,10, 7,
  128886. 9,10, 5, 7, 8, 7,10, 9, 7,10,10, 5, 8, 8, 8,10,
  128887. 10, 8,10,10, 7,10,10,10,11,12,10,12,13, 7,10,10,
  128888. 9,13,11,10,12,13, 5, 8, 8, 8,10,10, 8,10,10, 7,
  128889. 10,10,10,12,12, 9,11,12, 7,10,11,10,12,12,10,13,
  128890. 11,
  128891. };
  128892. static float _vq_quantthresh__16u1__p1_0[] = {
  128893. -0.5, 0.5,
  128894. };
  128895. static long _vq_quantmap__16u1__p1_0[] = {
  128896. 1, 0, 2,
  128897. };
  128898. static encode_aux_threshmatch _vq_auxt__16u1__p1_0 = {
  128899. _vq_quantthresh__16u1__p1_0,
  128900. _vq_quantmap__16u1__p1_0,
  128901. 3,
  128902. 3
  128903. };
  128904. static static_codebook _16u1__p1_0 = {
  128905. 4, 81,
  128906. _vq_lengthlist__16u1__p1_0,
  128907. 1, -535822336, 1611661312, 2, 0,
  128908. _vq_quantlist__16u1__p1_0,
  128909. NULL,
  128910. &_vq_auxt__16u1__p1_0,
  128911. NULL,
  128912. 0
  128913. };
  128914. static long _vq_quantlist__16u1__p2_0[] = {
  128915. 1,
  128916. 0,
  128917. 2,
  128918. };
  128919. static long _vq_lengthlist__16u1__p2_0[] = {
  128920. 3, 4, 4, 5, 6, 6, 5, 6, 6, 5, 6, 6, 6, 7, 8, 6,
  128921. 7, 8, 5, 6, 6, 6, 8, 7, 6, 8, 7, 5, 6, 6, 6, 8,
  128922. 8, 6, 8, 8, 6, 8, 8, 7, 7,10, 8, 9, 9, 6, 8, 8,
  128923. 7, 9, 8, 8, 9,10, 5, 6, 6, 6, 8, 8, 7, 8, 8, 6,
  128924. 8, 8, 8,10, 9, 7, 8, 9, 6, 8, 8, 8, 9, 9, 7,10,
  128925. 8,
  128926. };
  128927. static float _vq_quantthresh__16u1__p2_0[] = {
  128928. -0.5, 0.5,
  128929. };
  128930. static long _vq_quantmap__16u1__p2_0[] = {
  128931. 1, 0, 2,
  128932. };
  128933. static encode_aux_threshmatch _vq_auxt__16u1__p2_0 = {
  128934. _vq_quantthresh__16u1__p2_0,
  128935. _vq_quantmap__16u1__p2_0,
  128936. 3,
  128937. 3
  128938. };
  128939. static static_codebook _16u1__p2_0 = {
  128940. 4, 81,
  128941. _vq_lengthlist__16u1__p2_0,
  128942. 1, -535822336, 1611661312, 2, 0,
  128943. _vq_quantlist__16u1__p2_0,
  128944. NULL,
  128945. &_vq_auxt__16u1__p2_0,
  128946. NULL,
  128947. 0
  128948. };
  128949. static long _vq_quantlist__16u1__p3_0[] = {
  128950. 2,
  128951. 1,
  128952. 3,
  128953. 0,
  128954. 4,
  128955. };
  128956. static long _vq_lengthlist__16u1__p3_0[] = {
  128957. 1, 5, 5, 8, 8, 6, 7, 7, 9, 9, 5, 7, 7, 9, 9, 9,
  128958. 10, 9,11,11, 9, 9,10,11,11, 6, 8, 8,10,10, 8, 9,
  128959. 10,11,11, 8, 9,10,11,11,10,11,11,12,13,10,11,11,
  128960. 13,13, 6, 8, 8,10,10, 8,10, 9,11,11, 8,10, 9,11,
  128961. 11,10,11,11,13,13,10,11,11,13,12, 9,11,11,14,13,
  128962. 10,12,12,15,14,10,12,11,14,13,12,13,13,15,15,12,
  128963. 13,13,16,14, 9,11,11,13,14,10,11,12,14,14,10,12,
  128964. 12,14,15,12,13,13,14,15,12,13,14,15,16, 5, 8, 8,
  128965. 11,11, 8,10,10,12,12, 8,10,10,12,12,11,12,12,14,
  128966. 14,11,12,12,14,14, 8,10,10,12,12, 9,11,12,12,13,
  128967. 10,12,12,13,13,12,12,13,14,15,11,13,13,15,15, 7,
  128968. 10,10,12,12, 9,12,11,13,12,10,11,12,13,13,12,13,
  128969. 12,15,14,11,12,13,15,15,10,12,12,15,14,11,13,13,
  128970. 16,15,11,13,13,16,15,14,13,14,15,16,13,15,15,17,
  128971. 17,10,12,12,14,15,11,12,12,15,15,11,13,13,15,16,
  128972. 13,15,13,16,15,13,15,15,16,17, 5, 8, 8,11,11, 8,
  128973. 10,10,12,12, 8,10,10,12,12,11,12,12,14,14,11,12,
  128974. 12,14,14, 7,10,10,12,12,10,12,12,14,13, 9,11,12,
  128975. 12,13,12,13,13,15,15,12,12,13,13,15, 7,10,10,12,
  128976. 13,10,11,12,13,13,10,12,11,13,13,11,13,13,15,15,
  128977. 12,13,12,15,14, 9,12,12,15,14,11,13,13,15,15,11,
  128978. 12,13,15,15,13,14,14,17,19,13,13,14,16,16,10,12,
  128979. 12,14,15,11,13,13,15,16,11,13,12,16,15,13,15,15,
  128980. 17,18,14,15,13,16,15, 8,11,11,15,14,10,12,12,16,
  128981. 15,10,12,12,16,16,14,15,15,18,17,13,14,15,16,18,
  128982. 9,12,12,15,15,11,12,14,16,17,11,13,13,16,15,15,
  128983. 15,15,17,18,14,15,16,17,17, 9,12,12,15,15,11,14,
  128984. 13,16,16,11,13,13,16,16,15,16,15,17,18,14,16,15,
  128985. 17,16,12,14,14,17,16,12,14,15,18,17,13,15,15,17,
  128986. 17,15,15,18,16,20,15,16,17,18,18,11,14,14,16,17,
  128987. 13,15,14,18,17,13,15,15,17,17,15,17,15,18,17,15,
  128988. 17,16,19,18, 8,11,11,14,15,10,12,12,15,15,10,12,
  128989. 12,16,16,13,14,14,17,16,14,15,15,17,17, 9,12,12,
  128990. 15,16,11,13,13,16,16,11,12,13,16,16,14,16,15,20,
  128991. 17,14,16,16,17,17, 9,12,12,15,16,11,13,13,16,17,
  128992. 11,13,13,17,16,14,15,15,17,18,15,15,15,18,18,11,
  128993. 14,14,17,16,13,15,15,17,17,13,14,14,18,17,15,16,
  128994. 16,18,19,15,15,17,17,19,11,14,14,16,17,13,15,14,
  128995. 17,19,13,15,14,18,17,15,17,16,18,18,15,17,15,18,
  128996. 16,
  128997. };
  128998. static float _vq_quantthresh__16u1__p3_0[] = {
  128999. -1.5, -0.5, 0.5, 1.5,
  129000. };
  129001. static long _vq_quantmap__16u1__p3_0[] = {
  129002. 3, 1, 0, 2, 4,
  129003. };
  129004. static encode_aux_threshmatch _vq_auxt__16u1__p3_0 = {
  129005. _vq_quantthresh__16u1__p3_0,
  129006. _vq_quantmap__16u1__p3_0,
  129007. 5,
  129008. 5
  129009. };
  129010. static static_codebook _16u1__p3_0 = {
  129011. 4, 625,
  129012. _vq_lengthlist__16u1__p3_0,
  129013. 1, -533725184, 1611661312, 3, 0,
  129014. _vq_quantlist__16u1__p3_0,
  129015. NULL,
  129016. &_vq_auxt__16u1__p3_0,
  129017. NULL,
  129018. 0
  129019. };
  129020. static long _vq_quantlist__16u1__p4_0[] = {
  129021. 2,
  129022. 1,
  129023. 3,
  129024. 0,
  129025. 4,
  129026. };
  129027. static long _vq_lengthlist__16u1__p4_0[] = {
  129028. 4, 5, 5, 8, 8, 6, 6, 7, 9, 9, 6, 6, 6, 9, 9, 9,
  129029. 10, 9,11,11, 9, 9,10,11,11, 6, 7, 7,10, 9, 7, 7,
  129030. 8, 9,10, 7, 7, 8,10,10,10,10,10,10,12, 9, 9,10,
  129031. 11,12, 6, 7, 7, 9, 9, 7, 8, 7,10,10, 7, 8, 7,10,
  129032. 10, 9,10, 9,12,11,10,10, 9,12,10, 9,10,10,12,11,
  129033. 10,10,10,12,12, 9,10,10,12,12,12,11,12,13,13,11,
  129034. 11,12,12,13, 9,10,10,11,12, 9,10,10,12,12,10,10,
  129035. 10,12,12,11,12,11,14,13,11,12,12,14,13, 5, 7, 7,
  129036. 10,10, 7, 8, 8,10,10, 7, 8, 7,10,10,10,10,10,12,
  129037. 12,10,10,10,12,12, 6, 8, 7,10,10, 7, 7, 9,10,11,
  129038. 8, 9, 9,11,10,10,10,11,11,13,10,10,11,12,13, 6,
  129039. 8, 8,10,10, 7, 9, 8,11,10, 8, 9, 9,10,11,10,11,
  129040. 10,13,11,10,11,10,12,12,10,11,10,12,11,10,10,10,
  129041. 12,13,10,11,11,13,12,11,11,13,11,14,12,12,13,14,
  129042. 14, 9,10,10,12,13,10,11,10,13,12,10,11,11,12,13,
  129043. 11,12,11,14,12,12,13,13,15,14, 5, 7, 7,10,10, 7,
  129044. 7, 8,10,10, 7, 8, 8,10,10,10,10,10,11,12,10,10,
  129045. 10,12,12, 7, 8, 8,10,10, 8, 9, 8,11,10, 7, 8, 9,
  129046. 10,11,10,11,11,12,12,10,10,11,11,13, 7, 7, 8,10,
  129047. 10, 8, 8, 9,10,11, 7, 9, 7,11,10,10,11,11,13,12,
  129048. 11,11,10,13,11, 9,10,10,12,12,10,11,11,13,12,10,
  129049. 10,11,12,12,12,13,13,14,14,11,11,12,12,14,10,10,
  129050. 11,12,12,10,11,11,12,13,10,10,10,13,12,12,13,13,
  129051. 15,14,12,13,10,14,11, 8,10,10,12,12,10,11,10,13,
  129052. 13, 9,10,10,12,12,12,13,13,15,14,11,12,12,13,13,
  129053. 9,10,10,13,12,10,10,11,13,13,10,11,10,13,12,12,
  129054. 12,13,14,15,12,13,12,15,13, 9,10,10,12,13,10,11,
  129055. 10,13,12,10,10,11,12,13,12,14,12,15,13,12,12,13,
  129056. 14,15,11,12,11,14,13,11,11,12,14,15,12,13,12,15,
  129057. 14,13,11,15,11,16,13,14,14,16,15,11,12,12,14,14,
  129058. 11,12,11,14,13,12,12,13,14,15,13,14,12,16,12,14,
  129059. 14,14,15,15, 8,10,10,12,12, 9,10,10,12,12,10,10,
  129060. 11,13,13,11,12,12,13,13,12,13,13,14,15, 9,10,10,
  129061. 13,12,10,11,11,13,12,10,10,11,13,13,12,13,12,15,
  129062. 14,12,12,13,13,16, 9, 9,10,12,13,10,10,11,12,13,
  129063. 10,11,10,13,13,12,12,13,13,15,13,13,12,15,13,11,
  129064. 12,12,14,14,12,13,12,15,14,11,11,12,13,14,14,14,
  129065. 14,16,15,13,12,15,12,16,11,11,12,13,14,12,13,13,
  129066. 14,15,10,12,11,14,13,14,15,14,16,16,13,14,11,15,
  129067. 11,
  129068. };
  129069. static float _vq_quantthresh__16u1__p4_0[] = {
  129070. -1.5, -0.5, 0.5, 1.5,
  129071. };
  129072. static long _vq_quantmap__16u1__p4_0[] = {
  129073. 3, 1, 0, 2, 4,
  129074. };
  129075. static encode_aux_threshmatch _vq_auxt__16u1__p4_0 = {
  129076. _vq_quantthresh__16u1__p4_0,
  129077. _vq_quantmap__16u1__p4_0,
  129078. 5,
  129079. 5
  129080. };
  129081. static static_codebook _16u1__p4_0 = {
  129082. 4, 625,
  129083. _vq_lengthlist__16u1__p4_0,
  129084. 1, -533725184, 1611661312, 3, 0,
  129085. _vq_quantlist__16u1__p4_0,
  129086. NULL,
  129087. &_vq_auxt__16u1__p4_0,
  129088. NULL,
  129089. 0
  129090. };
  129091. static long _vq_quantlist__16u1__p5_0[] = {
  129092. 4,
  129093. 3,
  129094. 5,
  129095. 2,
  129096. 6,
  129097. 1,
  129098. 7,
  129099. 0,
  129100. 8,
  129101. };
  129102. static long _vq_lengthlist__16u1__p5_0[] = {
  129103. 1, 4, 4, 7, 7, 7, 7, 9, 9, 4, 6, 6, 8, 8, 8, 8,
  129104. 10,10, 4, 5, 6, 8, 8, 8, 8,10,10, 7, 8, 8, 9, 9,
  129105. 9, 9,11,11, 7, 8, 8, 9, 9, 9, 9,11,11, 7, 8, 8,
  129106. 10, 9,11,11,12,11, 7, 8, 8, 9, 9,11,11,12,12, 9,
  129107. 10,10,11,11,12,12,13,12, 9,10,10,11,11,12,12,12,
  129108. 13,
  129109. };
  129110. static float _vq_quantthresh__16u1__p5_0[] = {
  129111. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  129112. };
  129113. static long _vq_quantmap__16u1__p5_0[] = {
  129114. 7, 5, 3, 1, 0, 2, 4, 6,
  129115. 8,
  129116. };
  129117. static encode_aux_threshmatch _vq_auxt__16u1__p5_0 = {
  129118. _vq_quantthresh__16u1__p5_0,
  129119. _vq_quantmap__16u1__p5_0,
  129120. 9,
  129121. 9
  129122. };
  129123. static static_codebook _16u1__p5_0 = {
  129124. 2, 81,
  129125. _vq_lengthlist__16u1__p5_0,
  129126. 1, -531628032, 1611661312, 4, 0,
  129127. _vq_quantlist__16u1__p5_0,
  129128. NULL,
  129129. &_vq_auxt__16u1__p5_0,
  129130. NULL,
  129131. 0
  129132. };
  129133. static long _vq_quantlist__16u1__p6_0[] = {
  129134. 4,
  129135. 3,
  129136. 5,
  129137. 2,
  129138. 6,
  129139. 1,
  129140. 7,
  129141. 0,
  129142. 8,
  129143. };
  129144. static long _vq_lengthlist__16u1__p6_0[] = {
  129145. 3, 4, 4, 6, 6, 7, 7, 9, 9, 4, 4, 4, 6, 6, 8, 8,
  129146. 9, 9, 4, 4, 4, 6, 6, 7, 7, 9, 9, 6, 6, 6, 7, 7,
  129147. 8, 8,10, 9, 6, 6, 6, 7, 7, 8, 8, 9,10, 7, 8, 7,
  129148. 8, 8, 9, 9,10,10, 7, 8, 8, 8, 8, 9, 9,10,10, 9,
  129149. 9, 9,10,10,10,10,11,11, 9, 9, 9,10,10,10,10,11,
  129150. 11,
  129151. };
  129152. static float _vq_quantthresh__16u1__p6_0[] = {
  129153. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  129154. };
  129155. static long _vq_quantmap__16u1__p6_0[] = {
  129156. 7, 5, 3, 1, 0, 2, 4, 6,
  129157. 8,
  129158. };
  129159. static encode_aux_threshmatch _vq_auxt__16u1__p6_0 = {
  129160. _vq_quantthresh__16u1__p6_0,
  129161. _vq_quantmap__16u1__p6_0,
  129162. 9,
  129163. 9
  129164. };
  129165. static static_codebook _16u1__p6_0 = {
  129166. 2, 81,
  129167. _vq_lengthlist__16u1__p6_0,
  129168. 1, -531628032, 1611661312, 4, 0,
  129169. _vq_quantlist__16u1__p6_0,
  129170. NULL,
  129171. &_vq_auxt__16u1__p6_0,
  129172. NULL,
  129173. 0
  129174. };
  129175. static long _vq_quantlist__16u1__p7_0[] = {
  129176. 1,
  129177. 0,
  129178. 2,
  129179. };
  129180. static long _vq_lengthlist__16u1__p7_0[] = {
  129181. 1, 4, 4, 4, 8, 8, 4, 8, 8, 5,11, 9, 8,12,11, 8,
  129182. 12,11, 5,10,11, 8,11,12, 8,11,12, 4,11,11,11,14,
  129183. 13,10,13,13, 8,14,13,12,14,16,12,16,15, 8,14,14,
  129184. 13,16,14,12,15,16, 4,11,11,10,14,13,11,14,14, 8,
  129185. 15,14,12,15,15,12,14,16, 8,14,14,11,16,15,12,15,
  129186. 13,
  129187. };
  129188. static float _vq_quantthresh__16u1__p7_0[] = {
  129189. -5.5, 5.5,
  129190. };
  129191. static long _vq_quantmap__16u1__p7_0[] = {
  129192. 1, 0, 2,
  129193. };
  129194. static encode_aux_threshmatch _vq_auxt__16u1__p7_0 = {
  129195. _vq_quantthresh__16u1__p7_0,
  129196. _vq_quantmap__16u1__p7_0,
  129197. 3,
  129198. 3
  129199. };
  129200. static static_codebook _16u1__p7_0 = {
  129201. 4, 81,
  129202. _vq_lengthlist__16u1__p7_0,
  129203. 1, -529137664, 1618345984, 2, 0,
  129204. _vq_quantlist__16u1__p7_0,
  129205. NULL,
  129206. &_vq_auxt__16u1__p7_0,
  129207. NULL,
  129208. 0
  129209. };
  129210. static long _vq_quantlist__16u1__p7_1[] = {
  129211. 5,
  129212. 4,
  129213. 6,
  129214. 3,
  129215. 7,
  129216. 2,
  129217. 8,
  129218. 1,
  129219. 9,
  129220. 0,
  129221. 10,
  129222. };
  129223. static long _vq_lengthlist__16u1__p7_1[] = {
  129224. 2, 4, 4, 6, 6, 7, 7, 8, 8, 8, 8, 4, 6, 5, 7, 7,
  129225. 8, 8, 8, 8, 8, 8, 4, 5, 6, 7, 7, 8, 8, 8, 8, 8,
  129226. 8, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 6, 7, 7, 8,
  129227. 8, 8, 8, 9, 9, 9, 9, 7, 8, 8, 8, 8, 9, 9, 9,10,
  129228. 9,10, 7, 8, 8, 8, 8, 9, 9, 9, 9,10, 9, 8, 8, 8,
  129229. 9, 9,10,10,10,10,10,10, 8, 8, 8, 9, 9, 9, 9,10,
  129230. 10,10,10, 8, 8, 8, 9, 9, 9,10,10,10,10,10, 8, 8,
  129231. 8, 9, 9,10,10,10,10,10,10,
  129232. };
  129233. static float _vq_quantthresh__16u1__p7_1[] = {
  129234. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  129235. 3.5, 4.5,
  129236. };
  129237. static long _vq_quantmap__16u1__p7_1[] = {
  129238. 9, 7, 5, 3, 1, 0, 2, 4,
  129239. 6, 8, 10,
  129240. };
  129241. static encode_aux_threshmatch _vq_auxt__16u1__p7_1 = {
  129242. _vq_quantthresh__16u1__p7_1,
  129243. _vq_quantmap__16u1__p7_1,
  129244. 11,
  129245. 11
  129246. };
  129247. static static_codebook _16u1__p7_1 = {
  129248. 2, 121,
  129249. _vq_lengthlist__16u1__p7_1,
  129250. 1, -531365888, 1611661312, 4, 0,
  129251. _vq_quantlist__16u1__p7_1,
  129252. NULL,
  129253. &_vq_auxt__16u1__p7_1,
  129254. NULL,
  129255. 0
  129256. };
  129257. static long _vq_quantlist__16u1__p8_0[] = {
  129258. 5,
  129259. 4,
  129260. 6,
  129261. 3,
  129262. 7,
  129263. 2,
  129264. 8,
  129265. 1,
  129266. 9,
  129267. 0,
  129268. 10,
  129269. };
  129270. static long _vq_lengthlist__16u1__p8_0[] = {
  129271. 1, 4, 4, 5, 5, 8, 8,10,10,12,12, 4, 7, 7, 8, 8,
  129272. 9, 9,12,11,14,13, 4, 7, 7, 7, 8, 9,10,11,11,13,
  129273. 12, 5, 8, 8, 9, 9,11,11,12,13,15,14, 5, 7, 8, 9,
  129274. 9,11,11,13,13,17,15, 8, 9,10,11,11,12,13,17,14,
  129275. 17,16, 8,10, 9,11,11,12,12,13,15,15,17,10,11,11,
  129276. 12,13,14,15,15,16,16,17, 9,11,11,12,12,14,15,17,
  129277. 15,15,16,11,14,12,14,15,16,15,16,16,16,15,11,13,
  129278. 13,14,14,15,15,16,16,15,16,
  129279. };
  129280. static float _vq_quantthresh__16u1__p8_0[] = {
  129281. -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5, 27.5,
  129282. 38.5, 49.5,
  129283. };
  129284. static long _vq_quantmap__16u1__p8_0[] = {
  129285. 9, 7, 5, 3, 1, 0, 2, 4,
  129286. 6, 8, 10,
  129287. };
  129288. static encode_aux_threshmatch _vq_auxt__16u1__p8_0 = {
  129289. _vq_quantthresh__16u1__p8_0,
  129290. _vq_quantmap__16u1__p8_0,
  129291. 11,
  129292. 11
  129293. };
  129294. static static_codebook _16u1__p8_0 = {
  129295. 2, 121,
  129296. _vq_lengthlist__16u1__p8_0,
  129297. 1, -524582912, 1618345984, 4, 0,
  129298. _vq_quantlist__16u1__p8_0,
  129299. NULL,
  129300. &_vq_auxt__16u1__p8_0,
  129301. NULL,
  129302. 0
  129303. };
  129304. static long _vq_quantlist__16u1__p8_1[] = {
  129305. 5,
  129306. 4,
  129307. 6,
  129308. 3,
  129309. 7,
  129310. 2,
  129311. 8,
  129312. 1,
  129313. 9,
  129314. 0,
  129315. 10,
  129316. };
  129317. static long _vq_lengthlist__16u1__p8_1[] = {
  129318. 2, 5, 5, 6, 6, 7, 7, 8, 8, 8, 8, 4, 6, 6, 7, 7,
  129319. 8, 7, 8, 8, 8, 8, 4, 6, 6, 7, 7, 7, 7, 8, 8, 8,
  129320. 8, 6, 7, 7, 7, 7, 8, 8, 8, 8, 8, 9, 6, 7, 7, 7,
  129321. 7, 8, 8, 8, 8, 9, 9, 7, 7, 7, 8, 8, 8, 8, 9, 9,
  129322. 9, 9, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 8, 8, 8,
  129323. 8, 8, 9, 9, 9, 9, 9, 9, 8, 8, 8, 8, 8, 9, 9, 9,
  129324. 9, 9, 9, 8, 8, 8, 9, 8, 9, 9, 9, 9, 9, 9, 8, 8,
  129325. 8, 9, 9, 9, 9, 9, 9, 9, 9,
  129326. };
  129327. static float _vq_quantthresh__16u1__p8_1[] = {
  129328. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  129329. 3.5, 4.5,
  129330. };
  129331. static long _vq_quantmap__16u1__p8_1[] = {
  129332. 9, 7, 5, 3, 1, 0, 2, 4,
  129333. 6, 8, 10,
  129334. };
  129335. static encode_aux_threshmatch _vq_auxt__16u1__p8_1 = {
  129336. _vq_quantthresh__16u1__p8_1,
  129337. _vq_quantmap__16u1__p8_1,
  129338. 11,
  129339. 11
  129340. };
  129341. static static_codebook _16u1__p8_1 = {
  129342. 2, 121,
  129343. _vq_lengthlist__16u1__p8_1,
  129344. 1, -531365888, 1611661312, 4, 0,
  129345. _vq_quantlist__16u1__p8_1,
  129346. NULL,
  129347. &_vq_auxt__16u1__p8_1,
  129348. NULL,
  129349. 0
  129350. };
  129351. static long _vq_quantlist__16u1__p9_0[] = {
  129352. 7,
  129353. 6,
  129354. 8,
  129355. 5,
  129356. 9,
  129357. 4,
  129358. 10,
  129359. 3,
  129360. 11,
  129361. 2,
  129362. 12,
  129363. 1,
  129364. 13,
  129365. 0,
  129366. 14,
  129367. };
  129368. static long _vq_lengthlist__16u1__p9_0[] = {
  129369. 1, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129370. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129371. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129372. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129373. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129374. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129375. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129376. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129377. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129378. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129379. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129380. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129381. 9, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  129382. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  129383. 8,
  129384. };
  129385. static float _vq_quantthresh__16u1__p9_0[] = {
  129386. -1657.5, -1402.5, -1147.5, -892.5, -637.5, -382.5, -127.5, 127.5,
  129387. 382.5, 637.5, 892.5, 1147.5, 1402.5, 1657.5,
  129388. };
  129389. static long _vq_quantmap__16u1__p9_0[] = {
  129390. 13, 11, 9, 7, 5, 3, 1, 0,
  129391. 2, 4, 6, 8, 10, 12, 14,
  129392. };
  129393. static encode_aux_threshmatch _vq_auxt__16u1__p9_0 = {
  129394. _vq_quantthresh__16u1__p9_0,
  129395. _vq_quantmap__16u1__p9_0,
  129396. 15,
  129397. 15
  129398. };
  129399. static static_codebook _16u1__p9_0 = {
  129400. 2, 225,
  129401. _vq_lengthlist__16u1__p9_0,
  129402. 1, -514071552, 1627381760, 4, 0,
  129403. _vq_quantlist__16u1__p9_0,
  129404. NULL,
  129405. &_vq_auxt__16u1__p9_0,
  129406. NULL,
  129407. 0
  129408. };
  129409. static long _vq_quantlist__16u1__p9_1[] = {
  129410. 7,
  129411. 6,
  129412. 8,
  129413. 5,
  129414. 9,
  129415. 4,
  129416. 10,
  129417. 3,
  129418. 11,
  129419. 2,
  129420. 12,
  129421. 1,
  129422. 13,
  129423. 0,
  129424. 14,
  129425. };
  129426. static long _vq_lengthlist__16u1__p9_1[] = {
  129427. 1, 6, 5, 9, 9,10,10, 6, 7, 9, 9,10,10,10,10, 5,
  129428. 10, 8,10, 8,10,10, 8, 8,10, 9,10,10,10,10, 5, 8,
  129429. 9,10,10,10,10, 8,10,10,10,10,10,10,10, 9,10,10,
  129430. 10,10,10,10, 9, 9,10,10,10,10,10,10, 9, 9, 8, 9,
  129431. 10,10,10, 9,10,10,10,10,10,10,10,10,10,10,10,10,
  129432. 10,10,10,10,10,10,10,10,10,10,10, 8,10,10,10,10,
  129433. 10,10,10,10,10,10,10,10,10, 6, 8, 8,10,10,10, 8,
  129434. 10,10,10,10,10,10,10,10, 5, 8, 8,10,10,10, 9, 9,
  129435. 10,10,10,10,10,10,10,10, 9,10,10,10,10,10,10,10,
  129436. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  129437. 10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9,
  129438. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129439. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129440. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129441. 9,
  129442. };
  129443. static float _vq_quantthresh__16u1__p9_1[] = {
  129444. -110.5, -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5,
  129445. 25.5, 42.5, 59.5, 76.5, 93.5, 110.5,
  129446. };
  129447. static long _vq_quantmap__16u1__p9_1[] = {
  129448. 13, 11, 9, 7, 5, 3, 1, 0,
  129449. 2, 4, 6, 8, 10, 12, 14,
  129450. };
  129451. static encode_aux_threshmatch _vq_auxt__16u1__p9_1 = {
  129452. _vq_quantthresh__16u1__p9_1,
  129453. _vq_quantmap__16u1__p9_1,
  129454. 15,
  129455. 15
  129456. };
  129457. static static_codebook _16u1__p9_1 = {
  129458. 2, 225,
  129459. _vq_lengthlist__16u1__p9_1,
  129460. 1, -522338304, 1620115456, 4, 0,
  129461. _vq_quantlist__16u1__p9_1,
  129462. NULL,
  129463. &_vq_auxt__16u1__p9_1,
  129464. NULL,
  129465. 0
  129466. };
  129467. static long _vq_quantlist__16u1__p9_2[] = {
  129468. 8,
  129469. 7,
  129470. 9,
  129471. 6,
  129472. 10,
  129473. 5,
  129474. 11,
  129475. 4,
  129476. 12,
  129477. 3,
  129478. 13,
  129479. 2,
  129480. 14,
  129481. 1,
  129482. 15,
  129483. 0,
  129484. 16,
  129485. };
  129486. static long _vq_lengthlist__16u1__p9_2[] = {
  129487. 1, 6, 6, 7, 8, 8,11,10, 9, 9,11, 9,10, 9,11,11,
  129488. 9, 6, 7, 6,11, 8,11, 9,10,10,11, 9,11,10,10,10,
  129489. 11, 9, 5, 7, 7, 8, 8,10,11, 8, 8,11, 9, 9,10,11,
  129490. 9,10,11, 8, 9, 6, 8, 8, 9, 9,10,10,11,11,11, 9,
  129491. 11,10, 9,11, 8, 8, 8, 9, 8, 9,10,11, 9, 9,11,11,
  129492. 10, 9, 9,11,10, 8,11, 8, 9, 8,11, 9,10, 9,10,11,
  129493. 11,10,10, 9,10,10, 8, 8, 9,10,10,10, 9,11, 9,10,
  129494. 11,11,11,11,10, 9,11, 9, 9,11,11,10, 8,11,11,11,
  129495. 9,10,10,11,10,11,11, 9,11,10, 9,11,10,10,10,10,
  129496. 9,11,10,11,10, 9, 9,10,11, 9, 8,10,11,11,10,10,
  129497. 11, 9,11,10,11,11,10,11, 9, 9, 8,10, 8, 9,11, 9,
  129498. 8,10,10, 9,11,10,11,10,11, 9,11, 8,10,11,11,11,
  129499. 11,10,10,11,11,11,11,10,11,11,10, 9, 8,10,10, 9,
  129500. 11,10,11,11,11, 9, 9, 9,11,11,11,10,10, 9, 9,10,
  129501. 9,11,11,11,11, 8,10,11,10,11,11,10,11,11, 9, 9,
  129502. 9,10, 9,11, 9,11,11,11,11,11,10,11,11,10,11,10,
  129503. 11,11, 9,11,10,11,10, 9,10, 9,10,10,11,11,11,11,
  129504. 9,10, 9,10,11,11,10,11,11,11,11,11,11,10,11,11,
  129505. 10,
  129506. };
  129507. static float _vq_quantthresh__16u1__p9_2[] = {
  129508. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  129509. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  129510. };
  129511. static long _vq_quantmap__16u1__p9_2[] = {
  129512. 15, 13, 11, 9, 7, 5, 3, 1,
  129513. 0, 2, 4, 6, 8, 10, 12, 14,
  129514. 16,
  129515. };
  129516. static encode_aux_threshmatch _vq_auxt__16u1__p9_2 = {
  129517. _vq_quantthresh__16u1__p9_2,
  129518. _vq_quantmap__16u1__p9_2,
  129519. 17,
  129520. 17
  129521. };
  129522. static static_codebook _16u1__p9_2 = {
  129523. 2, 289,
  129524. _vq_lengthlist__16u1__p9_2,
  129525. 1, -529530880, 1611661312, 5, 0,
  129526. _vq_quantlist__16u1__p9_2,
  129527. NULL,
  129528. &_vq_auxt__16u1__p9_2,
  129529. NULL,
  129530. 0
  129531. };
  129532. static long _huff_lengthlist__16u1__short[] = {
  129533. 5, 7,10, 9,11,10,15,11,13,16, 6, 4, 6, 6, 7, 7,
  129534. 10, 9,12,16,10, 6, 5, 6, 6, 7,10,11,16,16, 9, 6,
  129535. 7, 6, 7, 7,10, 8,14,16,11, 6, 5, 4, 5, 6, 8, 9,
  129536. 15,16, 9, 6, 6, 5, 6, 6, 9, 8,14,16,12, 7, 6, 6,
  129537. 5, 6, 6, 7,13,16, 8, 6, 7, 6, 5, 5, 4, 4,11,16,
  129538. 9, 8, 9, 9, 7, 7, 6, 5,13,16,14,14,16,15,16,15,
  129539. 16,16,16,16,
  129540. };
  129541. static static_codebook _huff_book__16u1__short = {
  129542. 2, 100,
  129543. _huff_lengthlist__16u1__short,
  129544. 0, 0, 0, 0, 0,
  129545. NULL,
  129546. NULL,
  129547. NULL,
  129548. NULL,
  129549. 0
  129550. };
  129551. static long _huff_lengthlist__16u2__long[] = {
  129552. 5, 7,10,10,10,11,11,13,18,19, 6, 5, 5, 6, 7, 8,
  129553. 9,12,19,19, 8, 5, 4, 4, 6, 7, 9,13,19,19, 8, 5,
  129554. 4, 4, 5, 6, 8,12,17,19, 7, 5, 5, 4, 4, 5, 7,12,
  129555. 18,18, 8, 7, 7, 6, 5, 5, 6,10,18,18, 9, 9, 9, 8,
  129556. 6, 5, 6, 9,18,18,11,13,13,13, 8, 7, 7, 9,16,18,
  129557. 13,17,18,16,11, 9, 9, 9,17,18,15,18,18,18,15,13,
  129558. 13,14,18,18,
  129559. };
  129560. static static_codebook _huff_book__16u2__long = {
  129561. 2, 100,
  129562. _huff_lengthlist__16u2__long,
  129563. 0, 0, 0, 0, 0,
  129564. NULL,
  129565. NULL,
  129566. NULL,
  129567. NULL,
  129568. 0
  129569. };
  129570. static long _huff_lengthlist__16u2__short[] = {
  129571. 8,11,12,12,14,15,16,16,16,16, 9, 7, 7, 8, 9,11,
  129572. 13,14,16,16,13, 7, 6, 6, 7, 9,12,13,15,16,15, 7,
  129573. 6, 5, 4, 6,10,11,14,16,12, 8, 7, 4, 2, 4, 7,10,
  129574. 14,16,11, 9, 7, 5, 3, 4, 6, 9,14,16,11,10, 9, 7,
  129575. 5, 5, 6, 9,16,16,10,10, 9, 8, 6, 6, 7,10,16,16,
  129576. 11,11,11,10,10,10,11,14,16,16,16,14,14,13,14,16,
  129577. 16,16,16,16,
  129578. };
  129579. static static_codebook _huff_book__16u2__short = {
  129580. 2, 100,
  129581. _huff_lengthlist__16u2__short,
  129582. 0, 0, 0, 0, 0,
  129583. NULL,
  129584. NULL,
  129585. NULL,
  129586. NULL,
  129587. 0
  129588. };
  129589. static long _vq_quantlist__16u2_p1_0[] = {
  129590. 1,
  129591. 0,
  129592. 2,
  129593. };
  129594. static long _vq_lengthlist__16u2_p1_0[] = {
  129595. 1, 5, 5, 5, 7, 7, 5, 7, 7, 5, 7, 7, 7, 9, 9, 7,
  129596. 9, 9, 5, 7, 7, 7, 9, 9, 7, 9, 9, 5, 7, 7, 8, 9,
  129597. 9, 7, 9, 9, 7, 9, 9, 9,10,10, 9,10,10, 7, 9, 9,
  129598. 9,10,10, 9,10,11, 5, 7, 8, 8, 9, 9, 8, 9, 9, 7,
  129599. 9, 9, 9,10,10, 9, 9,10, 7, 9, 9, 9,10,10, 9,11,
  129600. 10,
  129601. };
  129602. static float _vq_quantthresh__16u2_p1_0[] = {
  129603. -0.5, 0.5,
  129604. };
  129605. static long _vq_quantmap__16u2_p1_0[] = {
  129606. 1, 0, 2,
  129607. };
  129608. static encode_aux_threshmatch _vq_auxt__16u2_p1_0 = {
  129609. _vq_quantthresh__16u2_p1_0,
  129610. _vq_quantmap__16u2_p1_0,
  129611. 3,
  129612. 3
  129613. };
  129614. static static_codebook _16u2_p1_0 = {
  129615. 4, 81,
  129616. _vq_lengthlist__16u2_p1_0,
  129617. 1, -535822336, 1611661312, 2, 0,
  129618. _vq_quantlist__16u2_p1_0,
  129619. NULL,
  129620. &_vq_auxt__16u2_p1_0,
  129621. NULL,
  129622. 0
  129623. };
  129624. static long _vq_quantlist__16u2_p2_0[] = {
  129625. 2,
  129626. 1,
  129627. 3,
  129628. 0,
  129629. 4,
  129630. };
  129631. static long _vq_lengthlist__16u2_p2_0[] = {
  129632. 3, 5, 5, 8, 8, 5, 7, 7, 9, 9, 5, 7, 7, 9, 9, 9,
  129633. 10, 9,11,11, 9, 9, 9,11,11, 5, 7, 7, 9, 9, 7, 8,
  129634. 8,10,10, 7, 8, 8,10,10,10,10,10,12,12, 9,10,10,
  129635. 11,12, 5, 7, 7, 9, 9, 7, 8, 8,10,10, 7, 8, 8,10,
  129636. 10, 9,10,10,12,11,10,10,10,12,12, 9,10,10,12,12,
  129637. 10,11,10,13,12, 9,10,10,12,12,12,12,12,14,14,11,
  129638. 12,12,13,14, 9,10,10,12,12, 9,10,10,12,12,10,10,
  129639. 10,12,12,11,12,12,14,13,12,13,12,14,14, 5, 7, 7,
  129640. 9, 9, 7, 8, 8,10,10, 7, 8, 8,10,10,10,11,10,12,
  129641. 12,10,10,11,12,12, 7, 8, 8,10,10, 8, 9, 9,11,11,
  129642. 8, 9, 9,11,11,11,11,11,12,13,10,11,11,12,13, 7,
  129643. 8, 8,10,10, 8, 9, 8,11,10, 8, 9, 9,11,11,10,11,
  129644. 10,13,12,10,11,11,13,13, 9,11,10,13,13,10,11,11,
  129645. 13,13,10,11,11,13,13,12,12,13,13,15,12,12,13,14,
  129646. 15, 9,10,10,12,12,10,11,10,13,12,10,11,11,13,13,
  129647. 11,13,11,14,13,12,13,13,15,15, 5, 7, 7, 9, 9, 7,
  129648. 8, 8,10,10, 7, 8, 8,10,10,10,10,10,12,12,10,10,
  129649. 11,12,12, 7, 8, 8,10,10, 8, 9, 9,11,11, 8, 8, 9,
  129650. 10,11,10,11,11,13,13,10,10,11,12,13, 7, 8, 8,10,
  129651. 11, 8, 9, 9,11,11, 8, 9, 9,11,11,10,11,11,13,12,
  129652. 11,11,11,13,12, 9,10,10,12,12,10,11,11,13,13,10,
  129653. 10,11,12,13,12,13,13,15,14,11,11,13,12,14,10,10,
  129654. 11,13,13,10,11,11,13,13,10,11,11,13,13,12,13,13,
  129655. 14,14,12,13,12,14,13, 8,10, 9,12,12, 9,11,10,13,
  129656. 13, 9,10,10,12,13,12,13,13,14,14,12,12,13,14,14,
  129657. 9,11,10,13,13,10,11,11,13,13,10,11,11,13,13,12,
  129658. 13,13,15,15,13,13,13,14,15, 9,10,10,12,13,10,11,
  129659. 10,13,12,10,11,11,13,13,12,13,12,15,14,13,13,13,
  129660. 14,15,11,12,12,15,14,12,12,13,15,15,12,13,13,15,
  129661. 14,14,13,15,14,16,13,14,15,16,16,11,12,12,14,14,
  129662. 11,12,12,15,14,12,13,13,15,15,13,14,13,16,14,14,
  129663. 14,14,16,16, 8, 9, 9,12,12, 9,10,10,13,12, 9,10,
  129664. 10,13,13,12,12,12,14,14,12,12,13,15,15, 9,10,10,
  129665. 13,12,10,11,11,13,13,10,10,11,13,14,12,13,13,15,
  129666. 15,12,12,13,14,15, 9,10,10,13,13,10,11,11,13,13,
  129667. 10,11,11,13,13,12,13,13,14,14,13,14,13,15,14,11,
  129668. 12,12,14,14,12,13,13,15,14,11,12,12,14,15,14,14,
  129669. 14,16,15,13,12,14,14,16,11,12,13,14,15,12,13,13,
  129670. 14,16,12,13,12,15,14,13,15,14,16,16,14,15,13,16,
  129671. 13,
  129672. };
  129673. static float _vq_quantthresh__16u2_p2_0[] = {
  129674. -1.5, -0.5, 0.5, 1.5,
  129675. };
  129676. static long _vq_quantmap__16u2_p2_0[] = {
  129677. 3, 1, 0, 2, 4,
  129678. };
  129679. static encode_aux_threshmatch _vq_auxt__16u2_p2_0 = {
  129680. _vq_quantthresh__16u2_p2_0,
  129681. _vq_quantmap__16u2_p2_0,
  129682. 5,
  129683. 5
  129684. };
  129685. static static_codebook _16u2_p2_0 = {
  129686. 4, 625,
  129687. _vq_lengthlist__16u2_p2_0,
  129688. 1, -533725184, 1611661312, 3, 0,
  129689. _vq_quantlist__16u2_p2_0,
  129690. NULL,
  129691. &_vq_auxt__16u2_p2_0,
  129692. NULL,
  129693. 0
  129694. };
  129695. static long _vq_quantlist__16u2_p3_0[] = {
  129696. 4,
  129697. 3,
  129698. 5,
  129699. 2,
  129700. 6,
  129701. 1,
  129702. 7,
  129703. 0,
  129704. 8,
  129705. };
  129706. static long _vq_lengthlist__16u2_p3_0[] = {
  129707. 2, 4, 4, 6, 6, 7, 7, 9, 9, 4, 5, 5, 6, 6, 8, 7,
  129708. 9, 9, 4, 5, 5, 6, 6, 7, 8, 9, 9, 6, 6, 6, 7, 7,
  129709. 8, 8,10,10, 6, 6, 6, 7, 7, 8, 8, 9,10, 7, 8, 7,
  129710. 8, 8, 9, 9,10,10, 7, 8, 8, 8, 8, 9, 9,10,10, 9,
  129711. 9, 9,10, 9,10,10,11,11, 9, 9, 9,10,10,10,10,11,
  129712. 11,
  129713. };
  129714. static float _vq_quantthresh__16u2_p3_0[] = {
  129715. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  129716. };
  129717. static long _vq_quantmap__16u2_p3_0[] = {
  129718. 7, 5, 3, 1, 0, 2, 4, 6,
  129719. 8,
  129720. };
  129721. static encode_aux_threshmatch _vq_auxt__16u2_p3_0 = {
  129722. _vq_quantthresh__16u2_p3_0,
  129723. _vq_quantmap__16u2_p3_0,
  129724. 9,
  129725. 9
  129726. };
  129727. static static_codebook _16u2_p3_0 = {
  129728. 2, 81,
  129729. _vq_lengthlist__16u2_p3_0,
  129730. 1, -531628032, 1611661312, 4, 0,
  129731. _vq_quantlist__16u2_p3_0,
  129732. NULL,
  129733. &_vq_auxt__16u2_p3_0,
  129734. NULL,
  129735. 0
  129736. };
  129737. static long _vq_quantlist__16u2_p4_0[] = {
  129738. 8,
  129739. 7,
  129740. 9,
  129741. 6,
  129742. 10,
  129743. 5,
  129744. 11,
  129745. 4,
  129746. 12,
  129747. 3,
  129748. 13,
  129749. 2,
  129750. 14,
  129751. 1,
  129752. 15,
  129753. 0,
  129754. 16,
  129755. };
  129756. static long _vq_lengthlist__16u2_p4_0[] = {
  129757. 2, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9,10,10,11,11,11,
  129758. 11, 5, 5, 5, 7, 7, 8, 8, 9, 9, 9, 9,10,10,11,11,
  129759. 12,11, 5, 5, 5, 7, 7, 8, 8, 9, 9, 9, 9,10,10,11,
  129760. 11,12,12, 6, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  129761. 11,11,12,12, 6, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9,10,
  129762. 10,11,11,12,12, 7, 8, 8, 8, 8, 9, 9, 9, 9,10,10,
  129763. 11,11,12,12,12,12, 7, 8, 8, 8, 8, 9, 9, 9, 9,10,
  129764. 10,11,11,11,12,12,12, 9, 9, 9, 9, 9, 9,10,10,10,
  129765. 10,10,11,11,12,12,13,13, 8, 9, 9, 9, 9,10, 9,10,
  129766. 10,10,10,11,11,12,12,13,13, 9, 9, 9, 9, 9,10,10,
  129767. 10,10,11,11,11,12,12,12,13,13, 9, 9, 9, 9, 9,10,
  129768. 10,10,10,11,11,12,11,12,12,13,13,10,10,10,10,10,
  129769. 11,11,11,11,11,12,12,12,12,13,13,14,10,10,10,10,
  129770. 10,11,11,11,11,12,11,12,12,13,12,13,13,11,11,11,
  129771. 11,11,12,12,12,12,12,12,13,13,13,13,14,14,11,11,
  129772. 11,11,11,12,12,12,12,12,12,13,12,13,13,14,14,11,
  129773. 12,12,12,12,12,12,13,13,13,13,13,13,14,14,14,14,
  129774. 11,12,12,12,12,12,12,13,13,13,13,14,13,14,14,14,
  129775. 14,
  129776. };
  129777. static float _vq_quantthresh__16u2_p4_0[] = {
  129778. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  129779. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  129780. };
  129781. static long _vq_quantmap__16u2_p4_0[] = {
  129782. 15, 13, 11, 9, 7, 5, 3, 1,
  129783. 0, 2, 4, 6, 8, 10, 12, 14,
  129784. 16,
  129785. };
  129786. static encode_aux_threshmatch _vq_auxt__16u2_p4_0 = {
  129787. _vq_quantthresh__16u2_p4_0,
  129788. _vq_quantmap__16u2_p4_0,
  129789. 17,
  129790. 17
  129791. };
  129792. static static_codebook _16u2_p4_0 = {
  129793. 2, 289,
  129794. _vq_lengthlist__16u2_p4_0,
  129795. 1, -529530880, 1611661312, 5, 0,
  129796. _vq_quantlist__16u2_p4_0,
  129797. NULL,
  129798. &_vq_auxt__16u2_p4_0,
  129799. NULL,
  129800. 0
  129801. };
  129802. static long _vq_quantlist__16u2_p5_0[] = {
  129803. 1,
  129804. 0,
  129805. 2,
  129806. };
  129807. static long _vq_lengthlist__16u2_p5_0[] = {
  129808. 1, 4, 4, 5, 7, 7, 5, 7, 7, 5, 9, 8, 7,10, 9, 7,
  129809. 10, 9, 5, 8, 9, 7, 9,10, 7, 9,10, 4, 9, 9, 9,11,
  129810. 11, 8,11,11, 7,11,11,10,10,13,10,14,13, 7,11,11,
  129811. 10,13,11,10,13,14, 5, 9, 9, 8,11,11, 9,11,11, 7,
  129812. 11,11,10,14,13,10,12,14, 7,11,11,10,13,13,10,13,
  129813. 10,
  129814. };
  129815. static float _vq_quantthresh__16u2_p5_0[] = {
  129816. -5.5, 5.5,
  129817. };
  129818. static long _vq_quantmap__16u2_p5_0[] = {
  129819. 1, 0, 2,
  129820. };
  129821. static encode_aux_threshmatch _vq_auxt__16u2_p5_0 = {
  129822. _vq_quantthresh__16u2_p5_0,
  129823. _vq_quantmap__16u2_p5_0,
  129824. 3,
  129825. 3
  129826. };
  129827. static static_codebook _16u2_p5_0 = {
  129828. 4, 81,
  129829. _vq_lengthlist__16u2_p5_0,
  129830. 1, -529137664, 1618345984, 2, 0,
  129831. _vq_quantlist__16u2_p5_0,
  129832. NULL,
  129833. &_vq_auxt__16u2_p5_0,
  129834. NULL,
  129835. 0
  129836. };
  129837. static long _vq_quantlist__16u2_p5_1[] = {
  129838. 5,
  129839. 4,
  129840. 6,
  129841. 3,
  129842. 7,
  129843. 2,
  129844. 8,
  129845. 1,
  129846. 9,
  129847. 0,
  129848. 10,
  129849. };
  129850. static long _vq_lengthlist__16u2_p5_1[] = {
  129851. 2, 5, 5, 6, 6, 7, 7, 8, 8, 8, 8, 5, 5, 5, 7, 7,
  129852. 7, 7, 8, 8, 8, 8, 5, 5, 6, 7, 7, 7, 7, 8, 8, 8,
  129853. 8, 6, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 6, 7, 7, 7,
  129854. 7, 8, 8, 8, 8, 8, 8, 7, 7, 7, 8, 8, 8, 8, 9, 9,
  129855. 9, 9, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 8, 8, 8,
  129856. 8, 8, 9, 9, 9, 9, 9, 9, 8, 8, 8, 8, 8, 9, 9, 9,
  129857. 9, 9, 9, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 8, 8,
  129858. 8, 8, 8, 9, 9, 9, 9, 9, 9,
  129859. };
  129860. static float _vq_quantthresh__16u2_p5_1[] = {
  129861. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  129862. 3.5, 4.5,
  129863. };
  129864. static long _vq_quantmap__16u2_p5_1[] = {
  129865. 9, 7, 5, 3, 1, 0, 2, 4,
  129866. 6, 8, 10,
  129867. };
  129868. static encode_aux_threshmatch _vq_auxt__16u2_p5_1 = {
  129869. _vq_quantthresh__16u2_p5_1,
  129870. _vq_quantmap__16u2_p5_1,
  129871. 11,
  129872. 11
  129873. };
  129874. static static_codebook _16u2_p5_1 = {
  129875. 2, 121,
  129876. _vq_lengthlist__16u2_p5_1,
  129877. 1, -531365888, 1611661312, 4, 0,
  129878. _vq_quantlist__16u2_p5_1,
  129879. NULL,
  129880. &_vq_auxt__16u2_p5_1,
  129881. NULL,
  129882. 0
  129883. };
  129884. static long _vq_quantlist__16u2_p6_0[] = {
  129885. 6,
  129886. 5,
  129887. 7,
  129888. 4,
  129889. 8,
  129890. 3,
  129891. 9,
  129892. 2,
  129893. 10,
  129894. 1,
  129895. 11,
  129896. 0,
  129897. 12,
  129898. };
  129899. static long _vq_lengthlist__16u2_p6_0[] = {
  129900. 1, 4, 4, 7, 7, 8, 8, 8, 8, 9, 9,10,10, 4, 6, 6,
  129901. 8, 8, 9, 9, 9, 9,10,10,12,11, 4, 6, 6, 8, 8, 9,
  129902. 9, 9, 9,10,10,11,12, 7, 8, 8, 9, 9,10,10,10,10,
  129903. 12,12,13,12, 7, 8, 8, 9, 9,10,10,10,10,11,12,12,
  129904. 12, 8, 9, 9,10,10,11,11,11,11,12,12,13,13, 8, 9,
  129905. 9,10,10,11,11,11,11,12,13,13,13, 8, 9, 9,10,10,
  129906. 11,11,12,12,13,13,14,14, 8, 9, 9,10,10,11,11,12,
  129907. 12,13,13,14,14, 9,10,10,11,12,13,12,13,14,14,14,
  129908. 14,14, 9,10,10,11,12,12,13,13,13,14,14,14,14,10,
  129909. 11,11,12,12,13,13,14,14,15,15,15,15,10,11,11,12,
  129910. 12,13,13,14,14,14,14,15,15,
  129911. };
  129912. static float _vq_quantthresh__16u2_p6_0[] = {
  129913. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  129914. 12.5, 17.5, 22.5, 27.5,
  129915. };
  129916. static long _vq_quantmap__16u2_p6_0[] = {
  129917. 11, 9, 7, 5, 3, 1, 0, 2,
  129918. 4, 6, 8, 10, 12,
  129919. };
  129920. static encode_aux_threshmatch _vq_auxt__16u2_p6_0 = {
  129921. _vq_quantthresh__16u2_p6_0,
  129922. _vq_quantmap__16u2_p6_0,
  129923. 13,
  129924. 13
  129925. };
  129926. static static_codebook _16u2_p6_0 = {
  129927. 2, 169,
  129928. _vq_lengthlist__16u2_p6_0,
  129929. 1, -526516224, 1616117760, 4, 0,
  129930. _vq_quantlist__16u2_p6_0,
  129931. NULL,
  129932. &_vq_auxt__16u2_p6_0,
  129933. NULL,
  129934. 0
  129935. };
  129936. static long _vq_quantlist__16u2_p6_1[] = {
  129937. 2,
  129938. 1,
  129939. 3,
  129940. 0,
  129941. 4,
  129942. };
  129943. static long _vq_lengthlist__16u2_p6_1[] = {
  129944. 2, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
  129945. 5, 5, 6, 6, 5, 5, 5, 6, 6,
  129946. };
  129947. static float _vq_quantthresh__16u2_p6_1[] = {
  129948. -1.5, -0.5, 0.5, 1.5,
  129949. };
  129950. static long _vq_quantmap__16u2_p6_1[] = {
  129951. 3, 1, 0, 2, 4,
  129952. };
  129953. static encode_aux_threshmatch _vq_auxt__16u2_p6_1 = {
  129954. _vq_quantthresh__16u2_p6_1,
  129955. _vq_quantmap__16u2_p6_1,
  129956. 5,
  129957. 5
  129958. };
  129959. static static_codebook _16u2_p6_1 = {
  129960. 2, 25,
  129961. _vq_lengthlist__16u2_p6_1,
  129962. 1, -533725184, 1611661312, 3, 0,
  129963. _vq_quantlist__16u2_p6_1,
  129964. NULL,
  129965. &_vq_auxt__16u2_p6_1,
  129966. NULL,
  129967. 0
  129968. };
  129969. static long _vq_quantlist__16u2_p7_0[] = {
  129970. 6,
  129971. 5,
  129972. 7,
  129973. 4,
  129974. 8,
  129975. 3,
  129976. 9,
  129977. 2,
  129978. 10,
  129979. 1,
  129980. 11,
  129981. 0,
  129982. 12,
  129983. };
  129984. static long _vq_lengthlist__16u2_p7_0[] = {
  129985. 1, 4, 4, 7, 7, 7, 7, 8, 8, 9, 9,10,10, 4, 6, 6,
  129986. 9, 9, 9, 9, 9, 9,10,10,11,11, 4, 6, 6, 8, 9, 9,
  129987. 9, 9, 9,10,11,12,11, 7, 8, 9,10,10,10,10,11,10,
  129988. 11,12,12,13, 7, 9, 9,10,10,10,10,10,10,11,12,13,
  129989. 13, 7, 9, 8,10,10,11,11,11,12,12,13,13,14, 7, 9,
  129990. 9,10,10,11,11,11,12,13,13,13,13, 8, 9, 9,10,11,
  129991. 11,12,12,12,13,13,13,13, 8, 9, 9,10,11,11,11,12,
  129992. 12,13,13,14,14, 9,10,10,12,11,12,13,13,13,14,13,
  129993. 13,13, 9,10,10,11,11,12,12,13,14,13,13,14,13,10,
  129994. 11,11,12,13,14,14,14,15,14,14,14,14,10,11,11,12,
  129995. 12,13,13,13,14,14,14,15,14,
  129996. };
  129997. static float _vq_quantthresh__16u2_p7_0[] = {
  129998. -60.5, -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5,
  129999. 27.5, 38.5, 49.5, 60.5,
  130000. };
  130001. static long _vq_quantmap__16u2_p7_0[] = {
  130002. 11, 9, 7, 5, 3, 1, 0, 2,
  130003. 4, 6, 8, 10, 12,
  130004. };
  130005. static encode_aux_threshmatch _vq_auxt__16u2_p7_0 = {
  130006. _vq_quantthresh__16u2_p7_0,
  130007. _vq_quantmap__16u2_p7_0,
  130008. 13,
  130009. 13
  130010. };
  130011. static static_codebook _16u2_p7_0 = {
  130012. 2, 169,
  130013. _vq_lengthlist__16u2_p7_0,
  130014. 1, -523206656, 1618345984, 4, 0,
  130015. _vq_quantlist__16u2_p7_0,
  130016. NULL,
  130017. &_vq_auxt__16u2_p7_0,
  130018. NULL,
  130019. 0
  130020. };
  130021. static long _vq_quantlist__16u2_p7_1[] = {
  130022. 5,
  130023. 4,
  130024. 6,
  130025. 3,
  130026. 7,
  130027. 2,
  130028. 8,
  130029. 1,
  130030. 9,
  130031. 0,
  130032. 10,
  130033. };
  130034. static long _vq_lengthlist__16u2_p7_1[] = {
  130035. 3, 5, 5, 6, 6, 7, 7, 7, 7, 7, 7, 5, 6, 6, 7, 7,
  130036. 7, 7, 7, 7, 8, 8, 5, 6, 6, 6, 6, 7, 7, 7, 7, 8,
  130037. 8, 6, 6, 7, 7, 7, 8, 7, 8, 8, 8, 8, 6, 7, 7, 7,
  130038. 7, 7, 7, 8, 8, 8, 8, 7, 7, 7, 7, 7, 8, 8, 8, 8,
  130039. 8, 8, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 7, 7, 7,
  130040. 8, 8, 8, 8, 8, 8, 8, 8, 7, 7, 7, 8, 8, 8, 8, 8,
  130041. 8, 8, 8, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 7, 8,
  130042. 8, 8, 8, 8, 8, 8, 8, 8, 8,
  130043. };
  130044. static float _vq_quantthresh__16u2_p7_1[] = {
  130045. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  130046. 3.5, 4.5,
  130047. };
  130048. static long _vq_quantmap__16u2_p7_1[] = {
  130049. 9, 7, 5, 3, 1, 0, 2, 4,
  130050. 6, 8, 10,
  130051. };
  130052. static encode_aux_threshmatch _vq_auxt__16u2_p7_1 = {
  130053. _vq_quantthresh__16u2_p7_1,
  130054. _vq_quantmap__16u2_p7_1,
  130055. 11,
  130056. 11
  130057. };
  130058. static static_codebook _16u2_p7_1 = {
  130059. 2, 121,
  130060. _vq_lengthlist__16u2_p7_1,
  130061. 1, -531365888, 1611661312, 4, 0,
  130062. _vq_quantlist__16u2_p7_1,
  130063. NULL,
  130064. &_vq_auxt__16u2_p7_1,
  130065. NULL,
  130066. 0
  130067. };
  130068. static long _vq_quantlist__16u2_p8_0[] = {
  130069. 7,
  130070. 6,
  130071. 8,
  130072. 5,
  130073. 9,
  130074. 4,
  130075. 10,
  130076. 3,
  130077. 11,
  130078. 2,
  130079. 12,
  130080. 1,
  130081. 13,
  130082. 0,
  130083. 14,
  130084. };
  130085. static long _vq_lengthlist__16u2_p8_0[] = {
  130086. 1, 5, 5, 7, 7, 8, 8, 7, 7, 8, 8,10, 9,11,11, 4,
  130087. 6, 6, 8, 8,10, 9, 9, 8, 9, 9,10,10,12,14, 4, 6,
  130088. 7, 8, 9, 9,10, 9, 8, 9, 9,10,12,12,11, 7, 8, 8,
  130089. 10,10,10,10, 9, 9,10,10,11,13,13,12, 7, 8, 8, 9,
  130090. 11,11,10, 9, 9,11,10,12,11,11,14, 8, 9, 9,11,10,
  130091. 11,11,10,10,11,11,13,12,14,12, 8, 9, 9,11,12,11,
  130092. 11,10,10,12,11,12,12,12,14, 7, 8, 8, 9, 9,10,10,
  130093. 10,11,12,11,13,13,14,12, 7, 8, 9, 9, 9,10,10,11,
  130094. 11,11,12,12,14,14,14, 8,10, 9,10,11,11,11,11,14,
  130095. 12,12,13,14,14,13, 9, 9, 9,10,11,11,11,12,12,12,
  130096. 14,12,14,13,14,10,10,10,12,11,12,11,14,13,14,13,
  130097. 14,14,13,14, 9,10,10,11,12,11,13,12,13,13,14,14,
  130098. 14,13,14,10,13,13,12,12,11,12,14,13,14,13,14,12,
  130099. 14,13,10,11,11,12,11,12,12,14,14,14,13,14,14,14,
  130100. 14,
  130101. };
  130102. static float _vq_quantthresh__16u2_p8_0[] = {
  130103. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  130104. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  130105. };
  130106. static long _vq_quantmap__16u2_p8_0[] = {
  130107. 13, 11, 9, 7, 5, 3, 1, 0,
  130108. 2, 4, 6, 8, 10, 12, 14,
  130109. };
  130110. static encode_aux_threshmatch _vq_auxt__16u2_p8_0 = {
  130111. _vq_quantthresh__16u2_p8_0,
  130112. _vq_quantmap__16u2_p8_0,
  130113. 15,
  130114. 15
  130115. };
  130116. static static_codebook _16u2_p8_0 = {
  130117. 2, 225,
  130118. _vq_lengthlist__16u2_p8_0,
  130119. 1, -520986624, 1620377600, 4, 0,
  130120. _vq_quantlist__16u2_p8_0,
  130121. NULL,
  130122. &_vq_auxt__16u2_p8_0,
  130123. NULL,
  130124. 0
  130125. };
  130126. static long _vq_quantlist__16u2_p8_1[] = {
  130127. 10,
  130128. 9,
  130129. 11,
  130130. 8,
  130131. 12,
  130132. 7,
  130133. 13,
  130134. 6,
  130135. 14,
  130136. 5,
  130137. 15,
  130138. 4,
  130139. 16,
  130140. 3,
  130141. 17,
  130142. 2,
  130143. 18,
  130144. 1,
  130145. 19,
  130146. 0,
  130147. 20,
  130148. };
  130149. static long _vq_lengthlist__16u2_p8_1[] = {
  130150. 2, 5, 5, 7, 7, 8, 8, 8, 8, 9, 9,10, 9,10, 9, 9,
  130151. 9,10,10,10,10, 5, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9,
  130152. 10, 9,10,10,10,10,10,10,11,10, 5, 6, 6, 7, 7, 8,
  130153. 8, 8, 9, 9,10,10,10,10,10,10,10,10,10,10,10, 7,
  130154. 7, 7, 8, 8, 9, 8, 9, 9,10, 9,10,10,10,10,10,10,
  130155. 11,10,11,10, 7, 7, 7, 8, 8, 8, 9, 9, 9,10, 9,10,
  130156. 10,10,10,10,10,10,10,10,10, 8, 8, 8, 9, 9, 9, 9,
  130157. 10, 9,10,10,10,10,10,10,10,11,10,10,11,10, 8, 8,
  130158. 8, 8, 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,11,
  130159. 11,10,10, 8, 9, 9, 9, 9, 9, 9,10,10,10,10,10,10,
  130160. 11,10,11,10,11,10,11,10, 8, 9, 9, 9, 9, 9,10,10,
  130161. 10,10,10,10,10,10,10,10,11,11,10,10,10, 9,10, 9,
  130162. 9,10,10,10,11,10,10,10,10,10,10,10,10,11,11,11,
  130163. 11,11, 9, 9, 9,10, 9,10,10,10,10,10,10,11,10,11,
  130164. 10,11,11,11,11,10,10, 9,10, 9,10,10,10,10,11,10,
  130165. 10,10,10,10,11,10,11,10,11,10,10,11, 9,10,10,10,
  130166. 10,10,10,10,10,10,11,10,10,11,11,10,11,11,11,11,
  130167. 11, 9, 9,10,10,10,10,10,11,10,10,11,10,10,11,10,
  130168. 10,11,11,11,11,11, 9,10,10,10,10,10,10,10,11,10,
  130169. 11,10,11,10,11,11,11,11,11,10,11,10,10,10,10,10,
  130170. 10,10,10,10,11,11,11,11,11,11,11,11,11,10,11,11,
  130171. 10,10,10,10,10,11,10,10,10,11,10,11,11,11,11,10,
  130172. 12,11,11,11,10,10,10,10,10,10,11,10,10,10,11,11,
  130173. 12,11,11,11,11,11,11,11,11,11,10,10,10,11,10,11,
  130174. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,10,
  130175. 10,10,11,10,11,10,10,11,11,11,11,11,11,11,11,11,
  130176. 11,11,11,10,10,10,10,10,10,10,11,11,10,11,11,10,
  130177. 11,11,10,11,11,11,10,11,11,
  130178. };
  130179. static float _vq_quantthresh__16u2_p8_1[] = {
  130180. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  130181. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  130182. 6.5, 7.5, 8.5, 9.5,
  130183. };
  130184. static long _vq_quantmap__16u2_p8_1[] = {
  130185. 19, 17, 15, 13, 11, 9, 7, 5,
  130186. 3, 1, 0, 2, 4, 6, 8, 10,
  130187. 12, 14, 16, 18, 20,
  130188. };
  130189. static encode_aux_threshmatch _vq_auxt__16u2_p8_1 = {
  130190. _vq_quantthresh__16u2_p8_1,
  130191. _vq_quantmap__16u2_p8_1,
  130192. 21,
  130193. 21
  130194. };
  130195. static static_codebook _16u2_p8_1 = {
  130196. 2, 441,
  130197. _vq_lengthlist__16u2_p8_1,
  130198. 1, -529268736, 1611661312, 5, 0,
  130199. _vq_quantlist__16u2_p8_1,
  130200. NULL,
  130201. &_vq_auxt__16u2_p8_1,
  130202. NULL,
  130203. 0
  130204. };
  130205. static long _vq_quantlist__16u2_p9_0[] = {
  130206. 5586,
  130207. 4655,
  130208. 6517,
  130209. 3724,
  130210. 7448,
  130211. 2793,
  130212. 8379,
  130213. 1862,
  130214. 9310,
  130215. 931,
  130216. 10241,
  130217. 0,
  130218. 11172,
  130219. 5521,
  130220. 5651,
  130221. };
  130222. static long _vq_lengthlist__16u2_p9_0[] = {
  130223. 1,10,10,10,10,10,10,10,10,10,10,10,10, 5, 4,10,
  130224. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  130225. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  130226. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  130227. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  130228. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  130229. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  130230. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  130231. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  130232. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  130233. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  130234. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  130235. 10,10,10, 4,10,10,10,10,10,10,10,10,10,10,10,10,
  130236. 6, 6, 5,10,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9, 5,
  130237. 5,
  130238. };
  130239. static float _vq_quantthresh__16u2_p9_0[] = {
  130240. -5120.5, -4189.5, -3258.5, -2327.5, -1396.5, -498, -32.5, 32.5,
  130241. 498, 1396.5, 2327.5, 3258.5, 4189.5, 5120.5,
  130242. };
  130243. static long _vq_quantmap__16u2_p9_0[] = {
  130244. 11, 9, 7, 5, 3, 1, 13, 0,
  130245. 14, 2, 4, 6, 8, 10, 12,
  130246. };
  130247. static encode_aux_threshmatch _vq_auxt__16u2_p9_0 = {
  130248. _vq_quantthresh__16u2_p9_0,
  130249. _vq_quantmap__16u2_p9_0,
  130250. 15,
  130251. 15
  130252. };
  130253. static static_codebook _16u2_p9_0 = {
  130254. 2, 225,
  130255. _vq_lengthlist__16u2_p9_0,
  130256. 1, -510275072, 1611661312, 14, 0,
  130257. _vq_quantlist__16u2_p9_0,
  130258. NULL,
  130259. &_vq_auxt__16u2_p9_0,
  130260. NULL,
  130261. 0
  130262. };
  130263. static long _vq_quantlist__16u2_p9_1[] = {
  130264. 392,
  130265. 343,
  130266. 441,
  130267. 294,
  130268. 490,
  130269. 245,
  130270. 539,
  130271. 196,
  130272. 588,
  130273. 147,
  130274. 637,
  130275. 98,
  130276. 686,
  130277. 49,
  130278. 735,
  130279. 0,
  130280. 784,
  130281. 388,
  130282. 396,
  130283. };
  130284. static long _vq_lengthlist__16u2_p9_1[] = {
  130285. 1,12,10,12,10,12,10,12,11,12,12,12,12,12,12,12,
  130286. 12, 5, 5, 9,10,12,11,11,12,12,12,12,12,12,12,12,
  130287. 12,12,12,12,10, 9, 9,11, 9,11,11,12,11,12,12,12,
  130288. 12,12,12,12,12,12,12, 8, 8,10,11, 9,12,11,12,12,
  130289. 12,12,12,12,12,12,12,12,12,12, 9, 8,10,11,12,11,
  130290. 12,11,12,12,12,12,12,12,12,12,12,12,12, 8, 9,11,
  130291. 11,10,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  130292. 9,10,11,12,11,12,11,12,12,12,12,12,12,12,12,12,
  130293. 12,12,12, 9, 9,11,12,12,12,12,12,12,12,12,12,12,
  130294. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  130295. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  130296. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  130297. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  130298. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  130299. 12,12,12,12,11,11,11,11,11,11,11,11,11,11,11,11,
  130300. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  130301. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  130302. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  130303. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  130304. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  130305. 11,11,11, 5, 8, 9, 9, 8,11, 9,11,11,11,11,11,11,
  130306. 11,11,11,11, 5, 5, 4, 8, 8, 8, 8,10, 9,10,10,11,
  130307. 11,11,11,11,11,11,11, 5, 4,
  130308. };
  130309. static float _vq_quantthresh__16u2_p9_1[] = {
  130310. -367.5, -318.5, -269.5, -220.5, -171.5, -122.5, -73.5, -26.5,
  130311. -2, 2, 26.5, 73.5, 122.5, 171.5, 220.5, 269.5,
  130312. 318.5, 367.5,
  130313. };
  130314. static long _vq_quantmap__16u2_p9_1[] = {
  130315. 15, 13, 11, 9, 7, 5, 3, 1,
  130316. 17, 0, 18, 2, 4, 6, 8, 10,
  130317. 12, 14, 16,
  130318. };
  130319. static encode_aux_threshmatch _vq_auxt__16u2_p9_1 = {
  130320. _vq_quantthresh__16u2_p9_1,
  130321. _vq_quantmap__16u2_p9_1,
  130322. 19,
  130323. 19
  130324. };
  130325. static static_codebook _16u2_p9_1 = {
  130326. 2, 361,
  130327. _vq_lengthlist__16u2_p9_1,
  130328. 1, -518488064, 1611661312, 10, 0,
  130329. _vq_quantlist__16u2_p9_1,
  130330. NULL,
  130331. &_vq_auxt__16u2_p9_1,
  130332. NULL,
  130333. 0
  130334. };
  130335. static long _vq_quantlist__16u2_p9_2[] = {
  130336. 24,
  130337. 23,
  130338. 25,
  130339. 22,
  130340. 26,
  130341. 21,
  130342. 27,
  130343. 20,
  130344. 28,
  130345. 19,
  130346. 29,
  130347. 18,
  130348. 30,
  130349. 17,
  130350. 31,
  130351. 16,
  130352. 32,
  130353. 15,
  130354. 33,
  130355. 14,
  130356. 34,
  130357. 13,
  130358. 35,
  130359. 12,
  130360. 36,
  130361. 11,
  130362. 37,
  130363. 10,
  130364. 38,
  130365. 9,
  130366. 39,
  130367. 8,
  130368. 40,
  130369. 7,
  130370. 41,
  130371. 6,
  130372. 42,
  130373. 5,
  130374. 43,
  130375. 4,
  130376. 44,
  130377. 3,
  130378. 45,
  130379. 2,
  130380. 46,
  130381. 1,
  130382. 47,
  130383. 0,
  130384. 48,
  130385. };
  130386. static long _vq_lengthlist__16u2_p9_2[] = {
  130387. 1, 3, 3, 4, 7, 7, 7, 8, 7, 7, 7, 7, 8, 8, 8, 8,
  130388. 7, 8, 8, 8, 8, 8, 8, 8, 8, 8, 7, 9, 9, 8, 9, 9,
  130389. 9, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,12,12,10,
  130390. 11,
  130391. };
  130392. static float _vq_quantthresh__16u2_p9_2[] = {
  130393. -23.5, -22.5, -21.5, -20.5, -19.5, -18.5, -17.5, -16.5,
  130394. -15.5, -14.5, -13.5, -12.5, -11.5, -10.5, -9.5, -8.5,
  130395. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  130396. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  130397. 8.5, 9.5, 10.5, 11.5, 12.5, 13.5, 14.5, 15.5,
  130398. 16.5, 17.5, 18.5, 19.5, 20.5, 21.5, 22.5, 23.5,
  130399. };
  130400. static long _vq_quantmap__16u2_p9_2[] = {
  130401. 47, 45, 43, 41, 39, 37, 35, 33,
  130402. 31, 29, 27, 25, 23, 21, 19, 17,
  130403. 15, 13, 11, 9, 7, 5, 3, 1,
  130404. 0, 2, 4, 6, 8, 10, 12, 14,
  130405. 16, 18, 20, 22, 24, 26, 28, 30,
  130406. 32, 34, 36, 38, 40, 42, 44, 46,
  130407. 48,
  130408. };
  130409. static encode_aux_threshmatch _vq_auxt__16u2_p9_2 = {
  130410. _vq_quantthresh__16u2_p9_2,
  130411. _vq_quantmap__16u2_p9_2,
  130412. 49,
  130413. 49
  130414. };
  130415. static static_codebook _16u2_p9_2 = {
  130416. 1, 49,
  130417. _vq_lengthlist__16u2_p9_2,
  130418. 1, -526909440, 1611661312, 6, 0,
  130419. _vq_quantlist__16u2_p9_2,
  130420. NULL,
  130421. &_vq_auxt__16u2_p9_2,
  130422. NULL,
  130423. 0
  130424. };
  130425. static long _vq_quantlist__8u0__p1_0[] = {
  130426. 1,
  130427. 0,
  130428. 2,
  130429. };
  130430. static long _vq_lengthlist__8u0__p1_0[] = {
  130431. 1, 4, 4, 5, 7, 7, 5, 7, 7, 5, 8, 8, 8,10,10, 7,
  130432. 10,10, 5, 8, 8, 7,10,10, 8,10,10, 4, 9, 8, 8,11,
  130433. 11, 8,11,11, 7,11,11,10,11,13,10,13,13, 7,11,11,
  130434. 10,13,12,10,13,13, 5, 9, 8, 8,11,11, 8,11,11, 7,
  130435. 11,11, 9,13,13,10,12,13, 7,11,11,10,13,13,10,13,
  130436. 11,
  130437. };
  130438. static float _vq_quantthresh__8u0__p1_0[] = {
  130439. -0.5, 0.5,
  130440. };
  130441. static long _vq_quantmap__8u0__p1_0[] = {
  130442. 1, 0, 2,
  130443. };
  130444. static encode_aux_threshmatch _vq_auxt__8u0__p1_0 = {
  130445. _vq_quantthresh__8u0__p1_0,
  130446. _vq_quantmap__8u0__p1_0,
  130447. 3,
  130448. 3
  130449. };
  130450. static static_codebook _8u0__p1_0 = {
  130451. 4, 81,
  130452. _vq_lengthlist__8u0__p1_0,
  130453. 1, -535822336, 1611661312, 2, 0,
  130454. _vq_quantlist__8u0__p1_0,
  130455. NULL,
  130456. &_vq_auxt__8u0__p1_0,
  130457. NULL,
  130458. 0
  130459. };
  130460. static long _vq_quantlist__8u0__p2_0[] = {
  130461. 1,
  130462. 0,
  130463. 2,
  130464. };
  130465. static long _vq_lengthlist__8u0__p2_0[] = {
  130466. 2, 4, 4, 5, 6, 6, 5, 6, 6, 5, 7, 7, 6, 7, 8, 6,
  130467. 7, 8, 5, 7, 7, 6, 8, 8, 7, 9, 7, 5, 7, 7, 7, 9,
  130468. 9, 7, 8, 8, 6, 9, 8, 7, 7,10, 8,10,10, 6, 8, 8,
  130469. 8,10, 8, 8,10,10, 5, 7, 7, 7, 8, 8, 7, 8, 9, 6,
  130470. 8, 8, 8,10,10, 8, 8,10, 6, 8, 9, 8,10,10, 7,10,
  130471. 8,
  130472. };
  130473. static float _vq_quantthresh__8u0__p2_0[] = {
  130474. -0.5, 0.5,
  130475. };
  130476. static long _vq_quantmap__8u0__p2_0[] = {
  130477. 1, 0, 2,
  130478. };
  130479. static encode_aux_threshmatch _vq_auxt__8u0__p2_0 = {
  130480. _vq_quantthresh__8u0__p2_0,
  130481. _vq_quantmap__8u0__p2_0,
  130482. 3,
  130483. 3
  130484. };
  130485. static static_codebook _8u0__p2_0 = {
  130486. 4, 81,
  130487. _vq_lengthlist__8u0__p2_0,
  130488. 1, -535822336, 1611661312, 2, 0,
  130489. _vq_quantlist__8u0__p2_0,
  130490. NULL,
  130491. &_vq_auxt__8u0__p2_0,
  130492. NULL,
  130493. 0
  130494. };
  130495. static long _vq_quantlist__8u0__p3_0[] = {
  130496. 2,
  130497. 1,
  130498. 3,
  130499. 0,
  130500. 4,
  130501. };
  130502. static long _vq_lengthlist__8u0__p3_0[] = {
  130503. 1, 5, 5, 7, 7, 6, 7, 7, 9, 9, 6, 7, 7, 9, 9, 8,
  130504. 10, 9,11,11, 8, 9, 9,11,11, 6, 8, 8,10,10, 8,10,
  130505. 10,11,11, 8,10,10,11,11,10,11,11,12,12,10,11,11,
  130506. 12,13, 6, 8, 8,10,10, 8,10,10,11,11, 8,10,10,11,
  130507. 11, 9,10,11,12,12,10,11,11,12,12, 8,11,11,14,13,
  130508. 10,12,11,15,13,10,12,11,14,14,12,13,12,16,14,12,
  130509. 14,12,16,15, 8,11,11,13,14,10,11,12,13,15,10,11,
  130510. 12,13,15,11,12,13,14,15,12,12,14,14,16, 5, 8, 8,
  130511. 11,11, 9,11,11,12,12, 8,10,11,12,12,11,12,12,15,
  130512. 14,11,12,12,14,14, 7,11,10,13,12,10,11,12,13,14,
  130513. 10,12,12,14,13,12,13,13,14,15,12,13,13,15,15, 7,
  130514. 10,11,12,13,10,12,11,14,13,10,12,13,13,15,12,13,
  130515. 12,14,14,11,13,13,15,16, 9,12,12,15,14,11,13,13,
  130516. 15,16,11,13,13,16,16,13,14,15,15,15,12,14,15,17,
  130517. 16, 9,12,12,14,15,11,13,13,15,16,11,13,13,16,18,
  130518. 13,14,14,17,16,13,15,15,17,18, 5, 8, 9,11,11, 8,
  130519. 11,11,12,12, 8,10,11,12,12,11,12,12,14,14,11,12,
  130520. 12,14,15, 7,11,10,12,13,10,12,12,14,13,10,11,12,
  130521. 13,14,11,13,13,15,14,12,13,13,14,15, 7,10,11,13,
  130522. 13,10,12,12,13,14,10,12,12,13,13,11,13,13,16,16,
  130523. 12,13,13,15,14, 9,12,12,16,15,10,13,13,15,15,11,
  130524. 13,13,17,15,12,15,15,18,17,13,14,14,15,16, 9,12,
  130525. 12,15,15,11,13,13,15,16,11,13,13,15,15,12,15,15,
  130526. 16,16,13,15,14,17,15, 7,11,11,15,15,10,13,13,16,
  130527. 15,10,13,13,15,16,14,15,15,17,19,13,15,14,15,18,
  130528. 9,12,12,16,16,11,13,14,17,16,11,13,13,17,16,15,
  130529. 15,16,17,19,13,15,16, 0,18, 9,12,12,16,15,11,14,
  130530. 13,17,17,11,13,14,16,16,15,16,16,19,18,13,15,15,
  130531. 17,19,11,14,14,19,16,12,14,15, 0,18,12,16,15,18,
  130532. 17,15,15,18,16,19,14,15,17,19,19,11,14,14,18,19,
  130533. 13,15,14,19,19,12,16,15,18,17,15,17,15, 0,16,14,
  130534. 17,16,19, 0, 7,11,11,14,14,10,12,12,15,15,10,13,
  130535. 13,16,15,13,15,15,17, 0,14,15,15,16,19, 9,12,12,
  130536. 16,16,11,14,14,16,16,11,13,13,16,16,14,17,16,19,
  130537. 0,14,18,17,17,19, 9,12,12,15,16,11,13,13,15,17,
  130538. 12,14,13,19,16,13,15,15,17,19,15,17,16,17,19,11,
  130539. 14,14,19,16,12,15,15,19,17,13,14,15,17,19,14,16,
  130540. 17,19,19,16,15,16,17,19,11,15,14,16,16,12,15,15,
  130541. 19, 0,12,14,15,19,19,14,16,16, 0,18,15,19,14,18,
  130542. 16,
  130543. };
  130544. static float _vq_quantthresh__8u0__p3_0[] = {
  130545. -1.5, -0.5, 0.5, 1.5,
  130546. };
  130547. static long _vq_quantmap__8u0__p3_0[] = {
  130548. 3, 1, 0, 2, 4,
  130549. };
  130550. static encode_aux_threshmatch _vq_auxt__8u0__p3_0 = {
  130551. _vq_quantthresh__8u0__p3_0,
  130552. _vq_quantmap__8u0__p3_0,
  130553. 5,
  130554. 5
  130555. };
  130556. static static_codebook _8u0__p3_0 = {
  130557. 4, 625,
  130558. _vq_lengthlist__8u0__p3_0,
  130559. 1, -533725184, 1611661312, 3, 0,
  130560. _vq_quantlist__8u0__p3_0,
  130561. NULL,
  130562. &_vq_auxt__8u0__p3_0,
  130563. NULL,
  130564. 0
  130565. };
  130566. static long _vq_quantlist__8u0__p4_0[] = {
  130567. 2,
  130568. 1,
  130569. 3,
  130570. 0,
  130571. 4,
  130572. };
  130573. static long _vq_lengthlist__8u0__p4_0[] = {
  130574. 3, 5, 5, 8, 8, 5, 6, 7, 9, 9, 6, 7, 6, 9, 9, 9,
  130575. 9, 9,10,11, 9, 9, 9,11,10, 6, 7, 7,10,10, 7, 7,
  130576. 8,10,10, 7, 8, 8,10,10,10,10,10,10,11, 9,10,10,
  130577. 11,12, 6, 7, 7,10,10, 7, 8, 8,10,10, 7, 8, 7,10,
  130578. 10, 9,10,10,12,11,10,10,10,11,10, 9,10,10,12,11,
  130579. 10,10,10,13,11, 9,10,10,12,12,11,11,12,12,13,11,
  130580. 11,11,12,13, 9,10,10,12,12,10,10,11,12,12,10,10,
  130581. 11,12,12,11,11,11,13,13,11,12,12,13,13, 5, 7, 7,
  130582. 10,10, 7, 8, 8,10,10, 7, 8, 8,10,10,10,11,11,12,
  130583. 12,10,11,10,12,12, 7, 8, 8,11,11, 7, 8, 9,10,11,
  130584. 8, 9, 9,11,11,11,10,11,10,12,10,11,11,12,13, 7,
  130585. 8, 8,10,11, 8, 9, 8,12,10, 8, 9, 9,11,12,10,11,
  130586. 10,13,11,10,11,11,13,12, 9,11,10,13,12,10,10,11,
  130587. 12,12,10,11,11,13,13,12,10,13,11,14,11,12,12,15,
  130588. 13, 9,11,11,13,13,10,11,11,13,12,10,11,11,12,14,
  130589. 12,13,11,14,12,12,12,12,14,14, 5, 7, 7,10,10, 7,
  130590. 8, 8,10,10, 7, 8, 8,11,10,10,11,11,12,12,10,11,
  130591. 10,12,12, 7, 8, 8,10,11, 8, 9, 9,12,11, 8, 8, 9,
  130592. 10,11,10,11,11,12,13,11,10,11,11,13, 6, 8, 8,10,
  130593. 11, 8, 9, 9,11,11, 7, 9, 7,11,10,10,11,11,12,12,
  130594. 10,11,10,13,10, 9,11,10,13,12,10,12,11,13,13,10,
  130595. 10,11,12,13,11,12,13,15,14,11,11,13,12,13, 9,10,
  130596. 11,12,13,10,11,11,12,13,10,11,10,13,12,12,13,13,
  130597. 13,14,12,12,11,14,11, 8,10,10,12,13,10,11,11,13,
  130598. 13,10,11,10,13,13,12,13,14,15,14,12,12,12,14,13,
  130599. 9,10,10,13,12,10,10,12,13,13,10,11,11,15,12,12,
  130600. 12,13,15,14,12,13,13,15,13, 9,10,11,12,13,10,12,
  130601. 10,13,12,10,11,11,12,13,12,14,12,15,13,12,12,12,
  130602. 15,14,11,12,11,14,13,11,11,12,14,14,12,13,13,14,
  130603. 13,13,11,15,11,15,14,14,14,16,15,11,12,12,13,14,
  130604. 11,13,11,14,14,12,12,13,14,15,12,14,12,15,12,13,
  130605. 15,14,16,15, 8,10,10,12,12,10,10,10,12,13,10,11,
  130606. 11,13,13,12,12,12,13,14,13,13,13,15,15, 9,10,10,
  130607. 12,12,10,11,11,13,12,10,10,11,13,13,12,12,12,14,
  130608. 14,12,12,13,15,14, 9,10,10,13,12,10,10,12,12,13,
  130609. 10,11,10,13,13,12,13,13,14,14,12,13,12,14,13,11,
  130610. 12,12,14,13,12,13,12,14,14,10,12,12,14,14,14,14,
  130611. 14,16,14,13,12,14,12,15,10,12,12,14,15,12,13,13,
  130612. 14,16,11,12,11,15,14,13,14,14,14,15,13,14,11,14,
  130613. 12,
  130614. };
  130615. static float _vq_quantthresh__8u0__p4_0[] = {
  130616. -1.5, -0.5, 0.5, 1.5,
  130617. };
  130618. static long _vq_quantmap__8u0__p4_0[] = {
  130619. 3, 1, 0, 2, 4,
  130620. };
  130621. static encode_aux_threshmatch _vq_auxt__8u0__p4_0 = {
  130622. _vq_quantthresh__8u0__p4_0,
  130623. _vq_quantmap__8u0__p4_0,
  130624. 5,
  130625. 5
  130626. };
  130627. static static_codebook _8u0__p4_0 = {
  130628. 4, 625,
  130629. _vq_lengthlist__8u0__p4_0,
  130630. 1, -533725184, 1611661312, 3, 0,
  130631. _vq_quantlist__8u0__p4_0,
  130632. NULL,
  130633. &_vq_auxt__8u0__p4_0,
  130634. NULL,
  130635. 0
  130636. };
  130637. static long _vq_quantlist__8u0__p5_0[] = {
  130638. 4,
  130639. 3,
  130640. 5,
  130641. 2,
  130642. 6,
  130643. 1,
  130644. 7,
  130645. 0,
  130646. 8,
  130647. };
  130648. static long _vq_lengthlist__8u0__p5_0[] = {
  130649. 1, 4, 4, 7, 7, 7, 7, 9, 9, 4, 6, 6, 8, 7, 8, 8,
  130650. 10,10, 4, 6, 6, 8, 8, 8, 8,10,10, 6, 8, 8, 9, 9,
  130651. 9, 9,11,11, 7, 8, 8, 9, 9, 9, 9,11,11, 7, 8, 8,
  130652. 9, 9,10,10,12,11, 7, 8, 8, 9, 9,10,10,11,11, 9,
  130653. 10,10,11,11,11,12,12,12, 9,10,10,11,11,12,12,12,
  130654. 12,
  130655. };
  130656. static float _vq_quantthresh__8u0__p5_0[] = {
  130657. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  130658. };
  130659. static long _vq_quantmap__8u0__p5_0[] = {
  130660. 7, 5, 3, 1, 0, 2, 4, 6,
  130661. 8,
  130662. };
  130663. static encode_aux_threshmatch _vq_auxt__8u0__p5_0 = {
  130664. _vq_quantthresh__8u0__p5_0,
  130665. _vq_quantmap__8u0__p5_0,
  130666. 9,
  130667. 9
  130668. };
  130669. static static_codebook _8u0__p5_0 = {
  130670. 2, 81,
  130671. _vq_lengthlist__8u0__p5_0,
  130672. 1, -531628032, 1611661312, 4, 0,
  130673. _vq_quantlist__8u0__p5_0,
  130674. NULL,
  130675. &_vq_auxt__8u0__p5_0,
  130676. NULL,
  130677. 0
  130678. };
  130679. static long _vq_quantlist__8u0__p6_0[] = {
  130680. 6,
  130681. 5,
  130682. 7,
  130683. 4,
  130684. 8,
  130685. 3,
  130686. 9,
  130687. 2,
  130688. 10,
  130689. 1,
  130690. 11,
  130691. 0,
  130692. 12,
  130693. };
  130694. static long _vq_lengthlist__8u0__p6_0[] = {
  130695. 1, 4, 4, 7, 7, 9, 9,11,11,12,12,16,16, 3, 6, 6,
  130696. 9, 9,11,11,12,12,13,14,18,16, 3, 6, 7, 9, 9,11,
  130697. 11,13,12,14,14,17,16, 7, 9, 9,11,11,12,12,14,14,
  130698. 14,14,17,16, 7, 9, 9,11,11,13,12,13,13,14,14,17,
  130699. 0, 9,11,11,12,13,14,14,14,13,15,14,17,17, 9,11,
  130700. 11,12,12,14,14,13,14,14,15, 0, 0,11,12,12,15,14,
  130701. 15,14,15,14,15,16,17, 0,11,12,13,13,13,14,14,15,
  130702. 14,15,15, 0, 0,12,14,14,15,15,14,16,15,15,17,16,
  130703. 0,18,13,14,14,15,14,15,14,15,16,17,16, 0, 0,17,
  130704. 17,18, 0,16,18,16, 0, 0, 0,17, 0, 0,16, 0, 0,16,
  130705. 16, 0,15, 0,17, 0, 0, 0, 0,
  130706. };
  130707. static float _vq_quantthresh__8u0__p6_0[] = {
  130708. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  130709. 12.5, 17.5, 22.5, 27.5,
  130710. };
  130711. static long _vq_quantmap__8u0__p6_0[] = {
  130712. 11, 9, 7, 5, 3, 1, 0, 2,
  130713. 4, 6, 8, 10, 12,
  130714. };
  130715. static encode_aux_threshmatch _vq_auxt__8u0__p6_0 = {
  130716. _vq_quantthresh__8u0__p6_0,
  130717. _vq_quantmap__8u0__p6_0,
  130718. 13,
  130719. 13
  130720. };
  130721. static static_codebook _8u0__p6_0 = {
  130722. 2, 169,
  130723. _vq_lengthlist__8u0__p6_0,
  130724. 1, -526516224, 1616117760, 4, 0,
  130725. _vq_quantlist__8u0__p6_0,
  130726. NULL,
  130727. &_vq_auxt__8u0__p6_0,
  130728. NULL,
  130729. 0
  130730. };
  130731. static long _vq_quantlist__8u0__p6_1[] = {
  130732. 2,
  130733. 1,
  130734. 3,
  130735. 0,
  130736. 4,
  130737. };
  130738. static long _vq_lengthlist__8u0__p6_1[] = {
  130739. 1, 4, 4, 6, 6, 4, 6, 5, 7, 7, 4, 5, 6, 7, 7, 6,
  130740. 7, 7, 7, 7, 6, 7, 7, 7, 7,
  130741. };
  130742. static float _vq_quantthresh__8u0__p6_1[] = {
  130743. -1.5, -0.5, 0.5, 1.5,
  130744. };
  130745. static long _vq_quantmap__8u0__p6_1[] = {
  130746. 3, 1, 0, 2, 4,
  130747. };
  130748. static encode_aux_threshmatch _vq_auxt__8u0__p6_1 = {
  130749. _vq_quantthresh__8u0__p6_1,
  130750. _vq_quantmap__8u0__p6_1,
  130751. 5,
  130752. 5
  130753. };
  130754. static static_codebook _8u0__p6_1 = {
  130755. 2, 25,
  130756. _vq_lengthlist__8u0__p6_1,
  130757. 1, -533725184, 1611661312, 3, 0,
  130758. _vq_quantlist__8u0__p6_1,
  130759. NULL,
  130760. &_vq_auxt__8u0__p6_1,
  130761. NULL,
  130762. 0
  130763. };
  130764. static long _vq_quantlist__8u0__p7_0[] = {
  130765. 1,
  130766. 0,
  130767. 2,
  130768. };
  130769. static long _vq_lengthlist__8u0__p7_0[] = {
  130770. 1, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  130771. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  130772. 8, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  130773. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  130774. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  130775. 7,
  130776. };
  130777. static float _vq_quantthresh__8u0__p7_0[] = {
  130778. -157.5, 157.5,
  130779. };
  130780. static long _vq_quantmap__8u0__p7_0[] = {
  130781. 1, 0, 2,
  130782. };
  130783. static encode_aux_threshmatch _vq_auxt__8u0__p7_0 = {
  130784. _vq_quantthresh__8u0__p7_0,
  130785. _vq_quantmap__8u0__p7_0,
  130786. 3,
  130787. 3
  130788. };
  130789. static static_codebook _8u0__p7_0 = {
  130790. 4, 81,
  130791. _vq_lengthlist__8u0__p7_0,
  130792. 1, -518803456, 1628680192, 2, 0,
  130793. _vq_quantlist__8u0__p7_0,
  130794. NULL,
  130795. &_vq_auxt__8u0__p7_0,
  130796. NULL,
  130797. 0
  130798. };
  130799. static long _vq_quantlist__8u0__p7_1[] = {
  130800. 7,
  130801. 6,
  130802. 8,
  130803. 5,
  130804. 9,
  130805. 4,
  130806. 10,
  130807. 3,
  130808. 11,
  130809. 2,
  130810. 12,
  130811. 1,
  130812. 13,
  130813. 0,
  130814. 14,
  130815. };
  130816. static long _vq_lengthlist__8u0__p7_1[] = {
  130817. 1, 5, 5, 5, 5,10,10,11,11,11,11,11,11,11,11, 5,
  130818. 7, 6, 8, 8, 9,10,11,11,11,11,11,11,11,11, 6, 6,
  130819. 7, 9, 7,11,10,11,11,11,11,11,11,11,11, 5, 6, 6,
  130820. 11, 8,11,11,11,11,11,11,11,11,11,11, 5, 6, 6, 9,
  130821. 10,11,10,11,11,11,11,11,11,11,11, 7,10,10,11,11,
  130822. 11,11,11,11,11,11,11,11,11,11, 7,11, 8,11,11,11,
  130823. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  130824. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  130825. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  130826. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  130827. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  130828. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  130829. 11,11,11,11,11,11,11,11,11,11,11,10,10,10,10,10,
  130830. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  130831. 10,
  130832. };
  130833. static float _vq_quantthresh__8u0__p7_1[] = {
  130834. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  130835. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  130836. };
  130837. static long _vq_quantmap__8u0__p7_1[] = {
  130838. 13, 11, 9, 7, 5, 3, 1, 0,
  130839. 2, 4, 6, 8, 10, 12, 14,
  130840. };
  130841. static encode_aux_threshmatch _vq_auxt__8u0__p7_1 = {
  130842. _vq_quantthresh__8u0__p7_1,
  130843. _vq_quantmap__8u0__p7_1,
  130844. 15,
  130845. 15
  130846. };
  130847. static static_codebook _8u0__p7_1 = {
  130848. 2, 225,
  130849. _vq_lengthlist__8u0__p7_1,
  130850. 1, -520986624, 1620377600, 4, 0,
  130851. _vq_quantlist__8u0__p7_1,
  130852. NULL,
  130853. &_vq_auxt__8u0__p7_1,
  130854. NULL,
  130855. 0
  130856. };
  130857. static long _vq_quantlist__8u0__p7_2[] = {
  130858. 10,
  130859. 9,
  130860. 11,
  130861. 8,
  130862. 12,
  130863. 7,
  130864. 13,
  130865. 6,
  130866. 14,
  130867. 5,
  130868. 15,
  130869. 4,
  130870. 16,
  130871. 3,
  130872. 17,
  130873. 2,
  130874. 18,
  130875. 1,
  130876. 19,
  130877. 0,
  130878. 20,
  130879. };
  130880. static long _vq_lengthlist__8u0__p7_2[] = {
  130881. 1, 6, 5, 7, 7, 9, 9, 9, 9,10,12,12,10,11,11,10,
  130882. 11,11,11,10,11, 6, 8, 8, 9, 9,10,10, 9,10,11,11,
  130883. 10,11,11,11,11,10,11,11,11,11, 6, 7, 8, 9, 9, 9,
  130884. 10,11,10,11,12,11,10,11,11,11,11,11,11,12,10, 8,
  130885. 9, 9,10, 9,10,10, 9,10,10,10,10,10, 9,10,10,10,
  130886. 10, 9,10,10, 9, 9, 9, 9,10,10, 9, 9,10,10,11,10,
  130887. 9,12,10,11,10, 9,10,10,10, 8, 9, 9,10, 9,10, 9,
  130888. 9,10,10, 9,10, 9,11,10,10,10,10,10, 9,10, 8, 8,
  130889. 9, 9,10, 9,11, 9, 8, 9, 9,10,11,10,10,10,11,12,
  130890. 9, 9,11, 8, 9, 8,11,10,11,10,10, 9,11,10,10,10,
  130891. 10,10,10,10,11,11,11,11, 8, 9, 9, 9,10,10,10,11,
  130892. 11,12,11,12,11,10,10,10,12,11,11,11,10, 8,10, 9,
  130893. 11,10,10,11,12,10,11,12,11,11,12,11,12,12,10,11,
  130894. 11,10, 9, 9,10,11,12,10,10,10,11,10,11,11,10,12,
  130895. 12,10,11,10,11,12,10, 9,10,10,11,10,11,11,11,11,
  130896. 11,12,11,11,11, 9,11,10,11,10,11,10, 9, 9,10,11,
  130897. 11,11,10,10,11,12,12,11,12,11,11,11,12,12,12,12,
  130898. 11, 9,11,11,12,10,11,11,11,11,11,11,12,11,11,12,
  130899. 11,11,11,10,11,11, 9,11,10,11,11,11,10,10,10,11,
  130900. 11,11,12,10,11,10,11,11,11,11,12, 9,11,10,11,11,
  130901. 10,10,11,11, 9,11,11,12,10,10,10,10,10,11,11,10,
  130902. 9,10,11,11,12,11,10,10,12,11,11,12,11,12,11,11,
  130903. 10,10,11,11,10,12,11,10,11,10,11,10,10,10,11,11,
  130904. 10,10,11,11,11,11,10,10,10,12,11,11,11,11,10, 9,
  130905. 10,11,11,11,12,11,11,11,12,10,11,11,11, 9,10,11,
  130906. 11,11,11,11,11,10,10,11,11,12,11,10,11,12,11,10,
  130907. 10,11, 9,10,11,11,11,11,11,10,11,11,10,12,11,11,
  130908. 11,12,11,11,11,10,10,11,11,
  130909. };
  130910. static float _vq_quantthresh__8u0__p7_2[] = {
  130911. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  130912. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  130913. 6.5, 7.5, 8.5, 9.5,
  130914. };
  130915. static long _vq_quantmap__8u0__p7_2[] = {
  130916. 19, 17, 15, 13, 11, 9, 7, 5,
  130917. 3, 1, 0, 2, 4, 6, 8, 10,
  130918. 12, 14, 16, 18, 20,
  130919. };
  130920. static encode_aux_threshmatch _vq_auxt__8u0__p7_2 = {
  130921. _vq_quantthresh__8u0__p7_2,
  130922. _vq_quantmap__8u0__p7_2,
  130923. 21,
  130924. 21
  130925. };
  130926. static static_codebook _8u0__p7_2 = {
  130927. 2, 441,
  130928. _vq_lengthlist__8u0__p7_2,
  130929. 1, -529268736, 1611661312, 5, 0,
  130930. _vq_quantlist__8u0__p7_2,
  130931. NULL,
  130932. &_vq_auxt__8u0__p7_2,
  130933. NULL,
  130934. 0
  130935. };
  130936. static long _huff_lengthlist__8u0__single[] = {
  130937. 4, 7,11, 9,12, 8, 7,10, 6, 4, 5, 5, 7, 5, 6,16,
  130938. 9, 5, 5, 6, 7, 7, 9,16, 7, 4, 6, 5, 7, 5, 7,17,
  130939. 10, 7, 7, 8, 7, 7, 8,18, 7, 5, 6, 4, 5, 4, 5,15,
  130940. 7, 6, 7, 5, 6, 4, 5,15,12,13,18,12,17,11, 9,17,
  130941. };
  130942. static static_codebook _huff_book__8u0__single = {
  130943. 2, 64,
  130944. _huff_lengthlist__8u0__single,
  130945. 0, 0, 0, 0, 0,
  130946. NULL,
  130947. NULL,
  130948. NULL,
  130949. NULL,
  130950. 0
  130951. };
  130952. static long _vq_quantlist__8u1__p1_0[] = {
  130953. 1,
  130954. 0,
  130955. 2,
  130956. };
  130957. static long _vq_lengthlist__8u1__p1_0[] = {
  130958. 1, 4, 4, 5, 7, 7, 5, 7, 7, 5, 8, 8, 7, 9,10, 7,
  130959. 9, 9, 5, 8, 8, 7,10, 9, 7, 9, 9, 5, 8, 8, 8,10,
  130960. 10, 8,10,10, 7,10,10, 9,10,12,10,12,12, 7,10,10,
  130961. 9,12,11,10,12,12, 5, 8, 8, 8,10,10, 8,10,10, 7,
  130962. 10,10,10,12,12, 9,11,12, 7,10,10,10,12,12, 9,12,
  130963. 10,
  130964. };
  130965. static float _vq_quantthresh__8u1__p1_0[] = {
  130966. -0.5, 0.5,
  130967. };
  130968. static long _vq_quantmap__8u1__p1_0[] = {
  130969. 1, 0, 2,
  130970. };
  130971. static encode_aux_threshmatch _vq_auxt__8u1__p1_0 = {
  130972. _vq_quantthresh__8u1__p1_0,
  130973. _vq_quantmap__8u1__p1_0,
  130974. 3,
  130975. 3
  130976. };
  130977. static static_codebook _8u1__p1_0 = {
  130978. 4, 81,
  130979. _vq_lengthlist__8u1__p1_0,
  130980. 1, -535822336, 1611661312, 2, 0,
  130981. _vq_quantlist__8u1__p1_0,
  130982. NULL,
  130983. &_vq_auxt__8u1__p1_0,
  130984. NULL,
  130985. 0
  130986. };
  130987. static long _vq_quantlist__8u1__p2_0[] = {
  130988. 1,
  130989. 0,
  130990. 2,
  130991. };
  130992. static long _vq_lengthlist__8u1__p2_0[] = {
  130993. 3, 4, 5, 5, 6, 6, 5, 6, 6, 5, 7, 6, 6, 7, 8, 6,
  130994. 7, 8, 5, 6, 6, 6, 8, 7, 6, 8, 7, 5, 6, 6, 7, 8,
  130995. 8, 6, 7, 7, 6, 8, 7, 7, 7, 9, 8, 9, 9, 6, 7, 8,
  130996. 7, 9, 7, 8, 9, 9, 5, 6, 6, 6, 7, 7, 7, 8, 8, 6,
  130997. 8, 7, 8, 9, 9, 7, 7, 9, 6, 7, 8, 8, 9, 9, 7, 9,
  130998. 7,
  130999. };
  131000. static float _vq_quantthresh__8u1__p2_0[] = {
  131001. -0.5, 0.5,
  131002. };
  131003. static long _vq_quantmap__8u1__p2_0[] = {
  131004. 1, 0, 2,
  131005. };
  131006. static encode_aux_threshmatch _vq_auxt__8u1__p2_0 = {
  131007. _vq_quantthresh__8u1__p2_0,
  131008. _vq_quantmap__8u1__p2_0,
  131009. 3,
  131010. 3
  131011. };
  131012. static static_codebook _8u1__p2_0 = {
  131013. 4, 81,
  131014. _vq_lengthlist__8u1__p2_0,
  131015. 1, -535822336, 1611661312, 2, 0,
  131016. _vq_quantlist__8u1__p2_0,
  131017. NULL,
  131018. &_vq_auxt__8u1__p2_0,
  131019. NULL,
  131020. 0
  131021. };
  131022. static long _vq_quantlist__8u1__p3_0[] = {
  131023. 2,
  131024. 1,
  131025. 3,
  131026. 0,
  131027. 4,
  131028. };
  131029. static long _vq_lengthlist__8u1__p3_0[] = {
  131030. 1, 5, 5, 7, 7, 6, 7, 7, 9, 9, 6, 7, 7, 9, 9, 8,
  131031. 10, 9,11,11, 9, 9, 9,11,11, 6, 8, 8,10,10, 8,10,
  131032. 10,11,11, 8, 9,10,11,11,10,11,11,12,12,10,11,11,
  131033. 12,13, 6, 8, 8,10,10, 8,10, 9,11,11, 8,10, 9,11,
  131034. 11,10,11,11,12,12,10,11,11,12,12, 9,11,11,14,13,
  131035. 10,12,11,14,14,10,12,11,14,13,12,13,13,15,14,12,
  131036. 13,13,15,14, 8,11,11,13,14,10,11,12,13,15,10,11,
  131037. 12,14,14,12,13,13,14,15,12,13,13,14,15, 5, 8, 8,
  131038. 11,11, 8,10,10,12,12, 8,10,10,12,12,11,12,12,14,
  131039. 13,11,12,12,13,14, 8,10,10,12,12, 9,11,12,13,14,
  131040. 10,12,12,13,13,12,12,13,14,14,11,13,13,15,15, 7,
  131041. 10,10,12,12, 9,12,11,14,12,10,11,12,13,14,12,13,
  131042. 12,14,14,12,13,13,15,16,10,12,12,15,14,11,12,13,
  131043. 15,15,11,13,13,15,16,14,14,15,15,16,13,14,15,17,
  131044. 15, 9,12,12,14,15,11,13,12,15,15,11,13,13,15,15,
  131045. 13,14,13,15,14,13,14,14,17, 0, 5, 8, 8,11,11, 8,
  131046. 10,10,12,12, 8,10,10,12,12,11,12,12,14,14,11,12,
  131047. 12,14,14, 7,10,10,12,12,10,12,12,13,13, 9,11,12,
  131048. 12,13,11,12,13,15,15,11,12,13,14,15, 8,10,10,12,
  131049. 12,10,12,11,13,13,10,12,11,13,13,11,13,13,15,14,
  131050. 12,13,12,15,13, 9,12,12,14,14,11,13,13,16,15,11,
  131051. 12,13,16,15,13,14,15,16,16,13,13,15,15,16,10,12,
  131052. 12,15,14,11,13,13,14,16,11,13,13,15,16,13,15,15,
  131053. 16,17,13,15,14,16,15, 8,11,11,14,15,10,12,12,15,
  131054. 15,10,12,12,15,16,14,15,15,16,17,13,14,14,16,16,
  131055. 9,12,12,15,15,11,13,14,15,17,11,13,13,15,16,14,
  131056. 15,16,19,17,13,15,15, 0,17, 9,12,12,15,15,11,14,
  131057. 13,16,15,11,13,13,15,16,15,15,15,18,17,13,15,15,
  131058. 17,17,11,15,14,18,16,12,14,15,17,17,12,15,15,18,
  131059. 18,15,15,16,15,19,14,16,16, 0, 0,11,14,14,16,17,
  131060. 12,15,14,18,17,12,15,15,18,18,15,17,15,18,16,14,
  131061. 16,16,18,18, 7,11,11,14,14,10,12,12,15,15,10,12,
  131062. 13,15,15,13,14,15,16,16,14,15,15,18,18, 9,12,12,
  131063. 15,15,11,13,13,16,15,11,12,13,16,16,14,15,15,17,
  131064. 16,15,16,16,17,17, 9,12,12,15,15,11,13,13,15,17,
  131065. 11,14,13,16,15,13,15,15,17,17,15,15,15,18,17,11,
  131066. 14,14,17,15,12,14,15,17,18,13,13,15,17,17,14,16,
  131067. 16,19,18,16,15,17,17, 0,11,14,14,17,17,12,15,15,
  131068. 18, 0,12,15,14,18,16,14,17,17,19, 0,16,18,15, 0,
  131069. 16,
  131070. };
  131071. static float _vq_quantthresh__8u1__p3_0[] = {
  131072. -1.5, -0.5, 0.5, 1.5,
  131073. };
  131074. static long _vq_quantmap__8u1__p3_0[] = {
  131075. 3, 1, 0, 2, 4,
  131076. };
  131077. static encode_aux_threshmatch _vq_auxt__8u1__p3_0 = {
  131078. _vq_quantthresh__8u1__p3_0,
  131079. _vq_quantmap__8u1__p3_0,
  131080. 5,
  131081. 5
  131082. };
  131083. static static_codebook _8u1__p3_0 = {
  131084. 4, 625,
  131085. _vq_lengthlist__8u1__p3_0,
  131086. 1, -533725184, 1611661312, 3, 0,
  131087. _vq_quantlist__8u1__p3_0,
  131088. NULL,
  131089. &_vq_auxt__8u1__p3_0,
  131090. NULL,
  131091. 0
  131092. };
  131093. static long _vq_quantlist__8u1__p4_0[] = {
  131094. 2,
  131095. 1,
  131096. 3,
  131097. 0,
  131098. 4,
  131099. };
  131100. static long _vq_lengthlist__8u1__p4_0[] = {
  131101. 4, 5, 5, 9, 9, 6, 7, 7, 9, 9, 6, 7, 7, 9, 9, 9,
  131102. 9, 9,11,11, 9, 9, 9,11,11, 6, 7, 7, 9, 9, 7, 7,
  131103. 8, 9,10, 7, 7, 8, 9,10, 9, 9,10,10,11, 9, 9,10,
  131104. 10,12, 6, 7, 7, 9, 9, 7, 8, 7,10, 9, 7, 8, 7,10,
  131105. 9, 9,10, 9,12,11,10,10, 9,12,10, 9,10,10,12,11,
  131106. 9,10,10,12,11, 9,10,10,12,12,11,11,12,12,13,11,
  131107. 11,12,12,13, 9, 9,10,12,11, 9,10,10,12,12,10,10,
  131108. 10,12,12,11,12,11,13,12,11,12,11,13,12, 6, 7, 7,
  131109. 9, 9, 7, 8, 8,10,10, 7, 8, 7,10, 9,10,10,10,12,
  131110. 12,10,10,10,12,11, 7, 8, 7,10,10, 7, 7, 9,10,11,
  131111. 8, 9, 9,11,10,10,10,11,10,12,10,10,11,12,12, 7,
  131112. 8, 8,10,10, 7, 9, 8,11,10, 8, 8, 9,11,11,10,11,
  131113. 10,12,11,10,11,11,12,12, 9,10,10,12,12, 9,10,10,
  131114. 12,12,10,11,11,13,12,11,10,12,10,14,12,12,12,13,
  131115. 14, 9,10,10,12,12, 9,11,10,12,12,10,11,11,12,12,
  131116. 11,12,11,14,12,12,12,12,14,14, 5, 7, 7, 9, 9, 7,
  131117. 7, 7, 9,10, 7, 8, 8,10,10,10,10,10,11,11,10,10,
  131118. 10,12,12, 7, 8, 8,10,10, 8, 9, 8,11,10, 7, 8, 9,
  131119. 10,11,10,10,10,11,12,10,10,11,11,13, 6, 7, 8,10,
  131120. 10, 8, 9, 9,10,10, 7, 9, 7,11,10,10,11,10,12,12,
  131121. 10,11,10,12,10, 9,10,10,12,12,10,11,11,13,12, 9,
  131122. 10,10,12,12,12,12,12,14,13,11,11,12,11,14, 9,10,
  131123. 10,11,12,10,11,11,12,13, 9,10,10,12,12,12,12,12,
  131124. 14,13,11,12,10,14,11, 9, 9,10,11,12, 9,10,10,12,
  131125. 12, 9,10,10,12,12,12,12,12,14,14,11,12,12,13,12,
  131126. 9,10, 9,12,12, 9,10,11,12,13,10,11,10,13,11,12,
  131127. 12,13,13,14,12,12,12,13,13, 9,10,10,12,12,10,11,
  131128. 10,13,12,10,10,11,12,13,12,13,12,14,13,12,12,12,
  131129. 13,14,11,12,11,14,13,10,10,11,13,13,12,12,12,14,
  131130. 13,12,10,14,10,15,13,14,14,14,14,11,11,12,13,14,
  131131. 10,12,11,13,13,12,12,12,13,15,12,13,11,15,12,13,
  131132. 13,14,14,14, 9,10, 9,12,12, 9,10,10,12,12,10,10,
  131133. 10,12,12,11,11,12,12,13,12,12,12,14,14, 9,10,10,
  131134. 12,12,10,11,10,13,12,10,10,11,12,13,12,12,12,14,
  131135. 13,12,12,13,13,14, 9,10,10,12,13,10,10,11,11,12,
  131136. 9,11,10,13,12,12,12,12,13,14,12,13,12,14,13,11,
  131137. 12,11,13,13,12,13,12,14,13,10,11,12,13,13,13,13,
  131138. 13,14,15,12,11,14,12,14,11,11,12,12,13,12,12,12,
  131139. 13,14,10,12,10,14,13,13,13,13,14,15,12,14,11,15,
  131140. 10,
  131141. };
  131142. static float _vq_quantthresh__8u1__p4_0[] = {
  131143. -1.5, -0.5, 0.5, 1.5,
  131144. };
  131145. static long _vq_quantmap__8u1__p4_0[] = {
  131146. 3, 1, 0, 2, 4,
  131147. };
  131148. static encode_aux_threshmatch _vq_auxt__8u1__p4_0 = {
  131149. _vq_quantthresh__8u1__p4_0,
  131150. _vq_quantmap__8u1__p4_0,
  131151. 5,
  131152. 5
  131153. };
  131154. static static_codebook _8u1__p4_0 = {
  131155. 4, 625,
  131156. _vq_lengthlist__8u1__p4_0,
  131157. 1, -533725184, 1611661312, 3, 0,
  131158. _vq_quantlist__8u1__p4_0,
  131159. NULL,
  131160. &_vq_auxt__8u1__p4_0,
  131161. NULL,
  131162. 0
  131163. };
  131164. static long _vq_quantlist__8u1__p5_0[] = {
  131165. 4,
  131166. 3,
  131167. 5,
  131168. 2,
  131169. 6,
  131170. 1,
  131171. 7,
  131172. 0,
  131173. 8,
  131174. };
  131175. static long _vq_lengthlist__8u1__p5_0[] = {
  131176. 1, 4, 4, 7, 7, 7, 7, 9, 9, 4, 6, 5, 8, 7, 8, 8,
  131177. 10,10, 4, 6, 6, 8, 8, 8, 8,10,10, 7, 8, 8, 9, 9,
  131178. 9, 9,11,11, 7, 8, 8, 9, 9, 9, 9,11,11, 8, 8, 8,
  131179. 9, 9,10,10,12,11, 8, 8, 8, 9, 9,10,10,11,11, 9,
  131180. 10,10,11,11,11,11,13,12, 9,10,10,11,11,12,12,12,
  131181. 13,
  131182. };
  131183. static float _vq_quantthresh__8u1__p5_0[] = {
  131184. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  131185. };
  131186. static long _vq_quantmap__8u1__p5_0[] = {
  131187. 7, 5, 3, 1, 0, 2, 4, 6,
  131188. 8,
  131189. };
  131190. static encode_aux_threshmatch _vq_auxt__8u1__p5_0 = {
  131191. _vq_quantthresh__8u1__p5_0,
  131192. _vq_quantmap__8u1__p5_0,
  131193. 9,
  131194. 9
  131195. };
  131196. static static_codebook _8u1__p5_0 = {
  131197. 2, 81,
  131198. _vq_lengthlist__8u1__p5_0,
  131199. 1, -531628032, 1611661312, 4, 0,
  131200. _vq_quantlist__8u1__p5_0,
  131201. NULL,
  131202. &_vq_auxt__8u1__p5_0,
  131203. NULL,
  131204. 0
  131205. };
  131206. static long _vq_quantlist__8u1__p6_0[] = {
  131207. 4,
  131208. 3,
  131209. 5,
  131210. 2,
  131211. 6,
  131212. 1,
  131213. 7,
  131214. 0,
  131215. 8,
  131216. };
  131217. static long _vq_lengthlist__8u1__p6_0[] = {
  131218. 3, 4, 4, 6, 6, 7, 7, 9, 9, 4, 4, 5, 6, 6, 7, 7,
  131219. 9, 9, 4, 4, 4, 6, 6, 7, 7, 9, 9, 6, 6, 6, 7, 7,
  131220. 8, 8, 9, 9, 6, 6, 6, 7, 7, 8, 8, 9, 9, 7, 7, 7,
  131221. 8, 8, 8, 9,10,10, 7, 7, 7, 8, 8, 9, 8,10,10, 9,
  131222. 9, 9, 9, 9,10,10,10,10, 9, 9, 9, 9, 9,10,10,10,
  131223. 10,
  131224. };
  131225. static float _vq_quantthresh__8u1__p6_0[] = {
  131226. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  131227. };
  131228. static long _vq_quantmap__8u1__p6_0[] = {
  131229. 7, 5, 3, 1, 0, 2, 4, 6,
  131230. 8,
  131231. };
  131232. static encode_aux_threshmatch _vq_auxt__8u1__p6_0 = {
  131233. _vq_quantthresh__8u1__p6_0,
  131234. _vq_quantmap__8u1__p6_0,
  131235. 9,
  131236. 9
  131237. };
  131238. static static_codebook _8u1__p6_0 = {
  131239. 2, 81,
  131240. _vq_lengthlist__8u1__p6_0,
  131241. 1, -531628032, 1611661312, 4, 0,
  131242. _vq_quantlist__8u1__p6_0,
  131243. NULL,
  131244. &_vq_auxt__8u1__p6_0,
  131245. NULL,
  131246. 0
  131247. };
  131248. static long _vq_quantlist__8u1__p7_0[] = {
  131249. 1,
  131250. 0,
  131251. 2,
  131252. };
  131253. static long _vq_lengthlist__8u1__p7_0[] = {
  131254. 1, 4, 4, 5, 7, 7, 5, 7, 7, 5, 9, 9, 8,10,10, 8,
  131255. 10,10, 5, 9, 9, 7,10,10, 8,10,10, 4,10,10, 9,12,
  131256. 12, 9,11,11, 7,12,11,10,11,13,10,13,13, 7,12,12,
  131257. 10,13,12,10,13,13, 4,10,10, 9,12,12, 9,12,12, 7,
  131258. 12,12,10,13,13,10,12,13, 7,11,12,10,13,13,10,13,
  131259. 11,
  131260. };
  131261. static float _vq_quantthresh__8u1__p7_0[] = {
  131262. -5.5, 5.5,
  131263. };
  131264. static long _vq_quantmap__8u1__p7_0[] = {
  131265. 1, 0, 2,
  131266. };
  131267. static encode_aux_threshmatch _vq_auxt__8u1__p7_0 = {
  131268. _vq_quantthresh__8u1__p7_0,
  131269. _vq_quantmap__8u1__p7_0,
  131270. 3,
  131271. 3
  131272. };
  131273. static static_codebook _8u1__p7_0 = {
  131274. 4, 81,
  131275. _vq_lengthlist__8u1__p7_0,
  131276. 1, -529137664, 1618345984, 2, 0,
  131277. _vq_quantlist__8u1__p7_0,
  131278. NULL,
  131279. &_vq_auxt__8u1__p7_0,
  131280. NULL,
  131281. 0
  131282. };
  131283. static long _vq_quantlist__8u1__p7_1[] = {
  131284. 5,
  131285. 4,
  131286. 6,
  131287. 3,
  131288. 7,
  131289. 2,
  131290. 8,
  131291. 1,
  131292. 9,
  131293. 0,
  131294. 10,
  131295. };
  131296. static long _vq_lengthlist__8u1__p7_1[] = {
  131297. 2, 4, 4, 6, 6, 7, 7, 8, 8, 8, 8, 4, 5, 5, 7, 7,
  131298. 8, 8, 9, 9, 9, 9, 4, 5, 5, 7, 7, 8, 8, 9, 9, 9,
  131299. 9, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 6, 7, 7, 8,
  131300. 8, 8, 8, 9, 9, 9, 9, 8, 8, 8, 8, 8, 9, 9, 9, 9,
  131301. 9, 9, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 8, 9, 9,
  131302. 9, 9, 9, 9,10,10,10,10, 8, 9, 9, 9, 9, 9, 9,10,
  131303. 10,10,10, 8, 9, 9, 9, 9, 9, 9,10,10,10,10, 8, 9,
  131304. 9, 9, 9, 9, 9,10,10,10,10,
  131305. };
  131306. static float _vq_quantthresh__8u1__p7_1[] = {
  131307. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  131308. 3.5, 4.5,
  131309. };
  131310. static long _vq_quantmap__8u1__p7_1[] = {
  131311. 9, 7, 5, 3, 1, 0, 2, 4,
  131312. 6, 8, 10,
  131313. };
  131314. static encode_aux_threshmatch _vq_auxt__8u1__p7_1 = {
  131315. _vq_quantthresh__8u1__p7_1,
  131316. _vq_quantmap__8u1__p7_1,
  131317. 11,
  131318. 11
  131319. };
  131320. static static_codebook _8u1__p7_1 = {
  131321. 2, 121,
  131322. _vq_lengthlist__8u1__p7_1,
  131323. 1, -531365888, 1611661312, 4, 0,
  131324. _vq_quantlist__8u1__p7_1,
  131325. NULL,
  131326. &_vq_auxt__8u1__p7_1,
  131327. NULL,
  131328. 0
  131329. };
  131330. static long _vq_quantlist__8u1__p8_0[] = {
  131331. 5,
  131332. 4,
  131333. 6,
  131334. 3,
  131335. 7,
  131336. 2,
  131337. 8,
  131338. 1,
  131339. 9,
  131340. 0,
  131341. 10,
  131342. };
  131343. static long _vq_lengthlist__8u1__p8_0[] = {
  131344. 1, 4, 4, 6, 6, 8, 8,10,10,11,11, 4, 6, 6, 7, 7,
  131345. 9, 9,11,11,13,12, 4, 6, 6, 7, 7, 9, 9,11,11,12,
  131346. 12, 6, 7, 7, 9, 9,11,11,12,12,13,13, 6, 7, 7, 9,
  131347. 9,11,11,12,12,13,13, 8, 9, 9,11,11,12,12,13,13,
  131348. 14,14, 8, 9, 9,11,11,12,12,13,13,14,14, 9,11,11,
  131349. 12,12,13,13,14,14,15,15, 9,11,11,12,12,13,13,14,
  131350. 14,15,14,11,12,12,13,13,14,14,15,15,16,16,11,12,
  131351. 12,13,13,14,14,15,15,15,15,
  131352. };
  131353. static float _vq_quantthresh__8u1__p8_0[] = {
  131354. -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5, 27.5,
  131355. 38.5, 49.5,
  131356. };
  131357. static long _vq_quantmap__8u1__p8_0[] = {
  131358. 9, 7, 5, 3, 1, 0, 2, 4,
  131359. 6, 8, 10,
  131360. };
  131361. static encode_aux_threshmatch _vq_auxt__8u1__p8_0 = {
  131362. _vq_quantthresh__8u1__p8_0,
  131363. _vq_quantmap__8u1__p8_0,
  131364. 11,
  131365. 11
  131366. };
  131367. static static_codebook _8u1__p8_0 = {
  131368. 2, 121,
  131369. _vq_lengthlist__8u1__p8_0,
  131370. 1, -524582912, 1618345984, 4, 0,
  131371. _vq_quantlist__8u1__p8_0,
  131372. NULL,
  131373. &_vq_auxt__8u1__p8_0,
  131374. NULL,
  131375. 0
  131376. };
  131377. static long _vq_quantlist__8u1__p8_1[] = {
  131378. 5,
  131379. 4,
  131380. 6,
  131381. 3,
  131382. 7,
  131383. 2,
  131384. 8,
  131385. 1,
  131386. 9,
  131387. 0,
  131388. 10,
  131389. };
  131390. static long _vq_lengthlist__8u1__p8_1[] = {
  131391. 2, 5, 5, 6, 6, 7, 7, 7, 7, 8, 8, 5, 6, 6, 7, 7,
  131392. 7, 7, 8, 8, 8, 8, 5, 6, 6, 7, 7, 7, 7, 8, 8, 8,
  131393. 8, 6, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 6, 7, 7, 7,
  131394. 7, 8, 8, 8, 8, 8, 8, 7, 7, 7, 8, 8, 8, 8, 8, 8,
  131395. 8, 8, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  131396. 8, 8, 8, 8, 9, 8, 9, 9, 7, 8, 8, 8, 8, 8, 8, 9,
  131397. 8, 9, 9, 8, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 8, 8,
  131398. 8, 8, 8, 8, 8, 9, 9, 9, 9,
  131399. };
  131400. static float _vq_quantthresh__8u1__p8_1[] = {
  131401. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  131402. 3.5, 4.5,
  131403. };
  131404. static long _vq_quantmap__8u1__p8_1[] = {
  131405. 9, 7, 5, 3, 1, 0, 2, 4,
  131406. 6, 8, 10,
  131407. };
  131408. static encode_aux_threshmatch _vq_auxt__8u1__p8_1 = {
  131409. _vq_quantthresh__8u1__p8_1,
  131410. _vq_quantmap__8u1__p8_1,
  131411. 11,
  131412. 11
  131413. };
  131414. static static_codebook _8u1__p8_1 = {
  131415. 2, 121,
  131416. _vq_lengthlist__8u1__p8_1,
  131417. 1, -531365888, 1611661312, 4, 0,
  131418. _vq_quantlist__8u1__p8_1,
  131419. NULL,
  131420. &_vq_auxt__8u1__p8_1,
  131421. NULL,
  131422. 0
  131423. };
  131424. static long _vq_quantlist__8u1__p9_0[] = {
  131425. 7,
  131426. 6,
  131427. 8,
  131428. 5,
  131429. 9,
  131430. 4,
  131431. 10,
  131432. 3,
  131433. 11,
  131434. 2,
  131435. 12,
  131436. 1,
  131437. 13,
  131438. 0,
  131439. 14,
  131440. };
  131441. static long _vq_lengthlist__8u1__p9_0[] = {
  131442. 1, 4, 4,11,11,11,11,11,11,11,11,11,11,11,11, 3,
  131443. 11, 8,11,11,11,11,11,11,11,11,11,11,11,11, 3, 9,
  131444. 9,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131445. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131446. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131447. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131448. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131449. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131450. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131451. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131452. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131453. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131454. 11,11,11,11,11,11,11,11,11,11,10,10,10,10,10,10,
  131455. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  131456. 10,
  131457. };
  131458. static float _vq_quantthresh__8u1__p9_0[] = {
  131459. -1657.5, -1402.5, -1147.5, -892.5, -637.5, -382.5, -127.5, 127.5,
  131460. 382.5, 637.5, 892.5, 1147.5, 1402.5, 1657.5,
  131461. };
  131462. static long _vq_quantmap__8u1__p9_0[] = {
  131463. 13, 11, 9, 7, 5, 3, 1, 0,
  131464. 2, 4, 6, 8, 10, 12, 14,
  131465. };
  131466. static encode_aux_threshmatch _vq_auxt__8u1__p9_0 = {
  131467. _vq_quantthresh__8u1__p9_0,
  131468. _vq_quantmap__8u1__p9_0,
  131469. 15,
  131470. 15
  131471. };
  131472. static static_codebook _8u1__p9_0 = {
  131473. 2, 225,
  131474. _vq_lengthlist__8u1__p9_0,
  131475. 1, -514071552, 1627381760, 4, 0,
  131476. _vq_quantlist__8u1__p9_0,
  131477. NULL,
  131478. &_vq_auxt__8u1__p9_0,
  131479. NULL,
  131480. 0
  131481. };
  131482. static long _vq_quantlist__8u1__p9_1[] = {
  131483. 7,
  131484. 6,
  131485. 8,
  131486. 5,
  131487. 9,
  131488. 4,
  131489. 10,
  131490. 3,
  131491. 11,
  131492. 2,
  131493. 12,
  131494. 1,
  131495. 13,
  131496. 0,
  131497. 14,
  131498. };
  131499. static long _vq_lengthlist__8u1__p9_1[] = {
  131500. 1, 4, 4, 7, 7, 9, 9, 7, 7, 8, 8,10,10,11,11, 4,
  131501. 7, 7, 9, 9,10,10, 8, 8,10,10,10,11,10,11, 4, 7,
  131502. 7, 9, 9,10,10, 8, 8,10, 9,11,11,11,11, 7, 9, 9,
  131503. 12,12,11,12,10,10,11,10,12,11,11,11, 7, 9, 9,11,
  131504. 11,13,12, 9, 9,11,10,11,11,12,11, 9,10,10,12,12,
  131505. 14,14,10,10,11,12,12,11,11,11, 9,10,11,11,13,14,
  131506. 13,10,11,11,11,12,11,12,12, 7, 8, 8,10, 9,11,10,
  131507. 11,12,12,11,12,14,12,13, 7, 8, 8, 9,10,10,11,12,
  131508. 12,12,11,12,12,12,13, 9, 9, 9,11,11,13,12,12,12,
  131509. 12,11,12,12,13,12, 8,10,10,11,10,11,12,12,12,12,
  131510. 12,12,14,12,12, 9,11,11,11,12,12,12,12,13,13,12,
  131511. 12,13,13,12,10,11,11,12,11,12,12,12,11,12,13,12,
  131512. 12,12,13,11,11,12,12,12,13,12,12,11,12,13,13,12,
  131513. 12,13,12,11,12,12,13,13,12,13,12,13,13,13,13,14,
  131514. 13,
  131515. };
  131516. static float _vq_quantthresh__8u1__p9_1[] = {
  131517. -110.5, -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5,
  131518. 25.5, 42.5, 59.5, 76.5, 93.5, 110.5,
  131519. };
  131520. static long _vq_quantmap__8u1__p9_1[] = {
  131521. 13, 11, 9, 7, 5, 3, 1, 0,
  131522. 2, 4, 6, 8, 10, 12, 14,
  131523. };
  131524. static encode_aux_threshmatch _vq_auxt__8u1__p9_1 = {
  131525. _vq_quantthresh__8u1__p9_1,
  131526. _vq_quantmap__8u1__p9_1,
  131527. 15,
  131528. 15
  131529. };
  131530. static static_codebook _8u1__p9_1 = {
  131531. 2, 225,
  131532. _vq_lengthlist__8u1__p9_1,
  131533. 1, -522338304, 1620115456, 4, 0,
  131534. _vq_quantlist__8u1__p9_1,
  131535. NULL,
  131536. &_vq_auxt__8u1__p9_1,
  131537. NULL,
  131538. 0
  131539. };
  131540. static long _vq_quantlist__8u1__p9_2[] = {
  131541. 8,
  131542. 7,
  131543. 9,
  131544. 6,
  131545. 10,
  131546. 5,
  131547. 11,
  131548. 4,
  131549. 12,
  131550. 3,
  131551. 13,
  131552. 2,
  131553. 14,
  131554. 1,
  131555. 15,
  131556. 0,
  131557. 16,
  131558. };
  131559. static long _vq_lengthlist__8u1__p9_2[] = {
  131560. 2, 5, 4, 6, 6, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  131561. 9, 5, 6, 6, 7, 7, 8, 8, 9, 8, 9, 9, 9, 9, 9, 9,
  131562. 9, 9, 5, 6, 6, 7, 7, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  131563. 9, 9, 9, 7, 7, 7, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9,
  131564. 9,10,10, 9, 7, 7, 7, 8, 8, 9, 9, 9, 9, 9, 9, 9,
  131565. 9, 9, 9,10,10, 8, 8, 8, 9, 9, 9, 9,10,10,10, 9,
  131566. 10,10,10,10,10,10, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9,
  131567. 10,10,10,10,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9,10,
  131568. 10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9,10,10,10,
  131569. 10,10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9, 9,10,
  131570. 10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9,10,
  131571. 10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9,10,
  131572. 10,10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9,
  131573. 9,10,10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9,
  131574. 10,10,10,10,10,10,10,10,10,10,10,10,10,10, 9,10,
  131575. 9, 9, 9,10,10,10,10,10,10,10,10,10,10,10,10, 9,
  131576. 10, 9,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  131577. 9, 9,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  131578. 10,
  131579. };
  131580. static float _vq_quantthresh__8u1__p9_2[] = {
  131581. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  131582. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  131583. };
  131584. static long _vq_quantmap__8u1__p9_2[] = {
  131585. 15, 13, 11, 9, 7, 5, 3, 1,
  131586. 0, 2, 4, 6, 8, 10, 12, 14,
  131587. 16,
  131588. };
  131589. static encode_aux_threshmatch _vq_auxt__8u1__p9_2 = {
  131590. _vq_quantthresh__8u1__p9_2,
  131591. _vq_quantmap__8u1__p9_2,
  131592. 17,
  131593. 17
  131594. };
  131595. static static_codebook _8u1__p9_2 = {
  131596. 2, 289,
  131597. _vq_lengthlist__8u1__p9_2,
  131598. 1, -529530880, 1611661312, 5, 0,
  131599. _vq_quantlist__8u1__p9_2,
  131600. NULL,
  131601. &_vq_auxt__8u1__p9_2,
  131602. NULL,
  131603. 0
  131604. };
  131605. static long _huff_lengthlist__8u1__single[] = {
  131606. 4, 7,13, 9,15, 9,16, 8,10,13, 7, 5, 8, 6, 9, 7,
  131607. 10, 7,10,11,11, 6, 7, 8, 8, 9, 9, 9,12,16, 8, 5,
  131608. 8, 6, 8, 6, 9, 7,10,12,11, 7, 7, 7, 6, 7, 7, 7,
  131609. 11,15, 7, 5, 8, 6, 7, 5, 7, 6, 9,13,13, 9, 9, 8,
  131610. 6, 6, 5, 5, 9,14, 8, 6, 8, 6, 6, 4, 5, 3, 5,13,
  131611. 9, 9,11, 8,10, 7, 8, 4, 5,12,11,16,17,15,17,12,
  131612. 13, 8, 8,15,
  131613. };
  131614. static static_codebook _huff_book__8u1__single = {
  131615. 2, 100,
  131616. _huff_lengthlist__8u1__single,
  131617. 0, 0, 0, 0, 0,
  131618. NULL,
  131619. NULL,
  131620. NULL,
  131621. NULL,
  131622. 0
  131623. };
  131624. static long _huff_lengthlist__44u0__long[] = {
  131625. 5, 8,13,10,17,11,11,15, 7, 2, 4, 5, 8, 7, 9,16,
  131626. 13, 4, 3, 5, 6, 8,11,20,10, 4, 5, 5, 7, 6, 8,18,
  131627. 15, 7, 6, 7, 8,10,14,20,10, 6, 7, 6, 9, 7, 8,17,
  131628. 9, 8,10, 8,10, 5, 4,11,12,17,19,14,16,10, 7,12,
  131629. };
  131630. static static_codebook _huff_book__44u0__long = {
  131631. 2, 64,
  131632. _huff_lengthlist__44u0__long,
  131633. 0, 0, 0, 0, 0,
  131634. NULL,
  131635. NULL,
  131636. NULL,
  131637. NULL,
  131638. 0
  131639. };
  131640. static long _vq_quantlist__44u0__p1_0[] = {
  131641. 1,
  131642. 0,
  131643. 2,
  131644. };
  131645. static long _vq_lengthlist__44u0__p1_0[] = {
  131646. 1, 4, 4, 5, 8, 7, 5, 7, 8, 5, 8, 8, 8,11,11, 8,
  131647. 10,10, 5, 8, 8, 8,11,10, 8,11,11, 4, 8, 8, 8,11,
  131648. 11, 8,11,11, 8,12,11,11,13,13,11,13,14, 7,11,11,
  131649. 10,13,12,11,13,14, 4, 8, 8, 8,11,11, 8,11,12, 8,
  131650. 11,11,11,13,13,10,12,13, 8,11,11,11,14,13,11,14,
  131651. 13,
  131652. };
  131653. static float _vq_quantthresh__44u0__p1_0[] = {
  131654. -0.5, 0.5,
  131655. };
  131656. static long _vq_quantmap__44u0__p1_0[] = {
  131657. 1, 0, 2,
  131658. };
  131659. static encode_aux_threshmatch _vq_auxt__44u0__p1_0 = {
  131660. _vq_quantthresh__44u0__p1_0,
  131661. _vq_quantmap__44u0__p1_0,
  131662. 3,
  131663. 3
  131664. };
  131665. static static_codebook _44u0__p1_0 = {
  131666. 4, 81,
  131667. _vq_lengthlist__44u0__p1_0,
  131668. 1, -535822336, 1611661312, 2, 0,
  131669. _vq_quantlist__44u0__p1_0,
  131670. NULL,
  131671. &_vq_auxt__44u0__p1_0,
  131672. NULL,
  131673. 0
  131674. };
  131675. static long _vq_quantlist__44u0__p2_0[] = {
  131676. 1,
  131677. 0,
  131678. 2,
  131679. };
  131680. static long _vq_lengthlist__44u0__p2_0[] = {
  131681. 2, 4, 4, 5, 6, 6, 5, 6, 6, 5, 7, 7, 7, 8, 8, 6,
  131682. 8, 8, 5, 7, 7, 6, 8, 8, 7, 8, 8, 4, 7, 7, 7, 8,
  131683. 8, 7, 8, 8, 7, 8, 8, 8, 9,10, 8,10,10, 6, 8, 8,
  131684. 8,10, 8, 8,10,10, 5, 7, 7, 7, 8, 8, 7, 8, 8, 6,
  131685. 8, 8, 8,10,10, 8, 8,10, 6, 8, 8, 8,10,10, 8,10,
  131686. 9,
  131687. };
  131688. static float _vq_quantthresh__44u0__p2_0[] = {
  131689. -0.5, 0.5,
  131690. };
  131691. static long _vq_quantmap__44u0__p2_0[] = {
  131692. 1, 0, 2,
  131693. };
  131694. static encode_aux_threshmatch _vq_auxt__44u0__p2_0 = {
  131695. _vq_quantthresh__44u0__p2_0,
  131696. _vq_quantmap__44u0__p2_0,
  131697. 3,
  131698. 3
  131699. };
  131700. static static_codebook _44u0__p2_0 = {
  131701. 4, 81,
  131702. _vq_lengthlist__44u0__p2_0,
  131703. 1, -535822336, 1611661312, 2, 0,
  131704. _vq_quantlist__44u0__p2_0,
  131705. NULL,
  131706. &_vq_auxt__44u0__p2_0,
  131707. NULL,
  131708. 0
  131709. };
  131710. static long _vq_quantlist__44u0__p3_0[] = {
  131711. 2,
  131712. 1,
  131713. 3,
  131714. 0,
  131715. 4,
  131716. };
  131717. static long _vq_lengthlist__44u0__p3_0[] = {
  131718. 1, 5, 5, 8, 8, 5, 8, 7, 9, 9, 5, 7, 8, 9, 9, 9,
  131719. 10, 9,12,12, 9, 9,10,12,12, 6, 8, 8,11,10, 8,10,
  131720. 10,11,11, 8, 9,10,11,11,10,11,11,14,13,10,11,11,
  131721. 13,13, 5, 8, 8,10,10, 8,10,10,11,11, 8,10,10,11,
  131722. 11,10,11,11,13,13,10,11,11,13,13, 9,11,11,15,14,
  131723. 10,12,12,15,14,10,12,11,15,14,13,14,14,16,16,12,
  131724. 14,13,17,15, 9,11,11,14,15,10,11,12,14,16,10,11,
  131725. 12,14,16,12,13,14,16,16,13,13,15,15,18, 5, 8, 8,
  131726. 11,11, 8,10,10,12,12, 8,10,10,12,13,11,12,12,14,
  131727. 14,11,12,12,15,15, 8,10,10,13,13,10,12,12,13,13,
  131728. 10,12,12,14,14,12,13,13,15,15,12,13,13,16,16, 7,
  131729. 10,10,12,12,10,12,11,13,13,10,12,12,13,14,12,13,
  131730. 12,15,14,12,13,13,16,16,10,12,12,17,16,12,13,13,
  131731. 16,15,11,13,13,17,17,15,15,15,16,17,14,15,15,19,
  131732. 19,10,12,12,15,16,11,13,12,15,18,11,13,13,16,16,
  131733. 14,15,15,17,17,14,15,15,17,19, 5, 8, 8,11,11, 8,
  131734. 10,10,12,12, 8,10,10,12,12,11,12,12,16,15,11,12,
  131735. 12,14,15, 7,10,10,13,13,10,12,12,14,13,10,11,12,
  131736. 13,13,12,13,13,16,16,12,12,13,15,15, 8,10,10,13,
  131737. 13,10,12,12,14,14,10,12,12,13,13,12,13,13,16,16,
  131738. 12,13,13,15,15,10,12,12,16,15,11,13,13,17,16,11,
  131739. 12,13,16,15,13,15,15,19,17,14,15,14,17,16,10,12,
  131740. 12,16,16,11,13,13,16,17,12,13,13,15,17,14,15,15,
  131741. 17,19,14,15,15,17,17, 8,11,11,16,16,10,13,12,17,
  131742. 17,10,12,13,16,16,15,17,16,20,19,14,15,17,18,19,
  131743. 9,12,12,16,17,11,13,14,17,18,11,13,13,19,18,16,
  131744. 17,18,19,19,15,16,16,19,19, 9,12,12,16,17,11,14,
  131745. 13,18,17,11,13,13,17,17,16,17,16,20,19,14,16,16,
  131746. 18,18,12,15,15,19,17,14,15,16, 0,20,13,15,16,20,
  131747. 17,18,16,20, 0, 0,15,16,19,20, 0,12,15,14,18,19,
  131748. 13,16,15,20,19,13,16,15,20,18,17,18,17, 0,20,16,
  131749. 17,16, 0, 0, 8,11,11,16,15,10,12,12,17,17,10,13,
  131750. 13,17,16,14,16,15,18,20,15,16,16,19,19, 9,12,12,
  131751. 16,16,11,13,13,17,16,11,13,14,17,18,15,15,16,20,
  131752. 20,16,16,17,19,19, 9,13,12,16,17,11,14,13,17,17,
  131753. 11,14,14,18,17,14,16,15,18,19,16,17,18,18,19,12,
  131754. 14,15,19,18,13,15,16,18, 0,13,14,15, 0, 0,16,16,
  131755. 17,20, 0,17,17,20,20, 0,12,15,15,19,20,13,15,15,
  131756. 0, 0,14,16,15, 0, 0,15,18,16, 0, 0,17,18,16, 0,
  131757. 19,
  131758. };
  131759. static float _vq_quantthresh__44u0__p3_0[] = {
  131760. -1.5, -0.5, 0.5, 1.5,
  131761. };
  131762. static long _vq_quantmap__44u0__p3_0[] = {
  131763. 3, 1, 0, 2, 4,
  131764. };
  131765. static encode_aux_threshmatch _vq_auxt__44u0__p3_0 = {
  131766. _vq_quantthresh__44u0__p3_0,
  131767. _vq_quantmap__44u0__p3_0,
  131768. 5,
  131769. 5
  131770. };
  131771. static static_codebook _44u0__p3_0 = {
  131772. 4, 625,
  131773. _vq_lengthlist__44u0__p3_0,
  131774. 1, -533725184, 1611661312, 3, 0,
  131775. _vq_quantlist__44u0__p3_0,
  131776. NULL,
  131777. &_vq_auxt__44u0__p3_0,
  131778. NULL,
  131779. 0
  131780. };
  131781. static long _vq_quantlist__44u0__p4_0[] = {
  131782. 2,
  131783. 1,
  131784. 3,
  131785. 0,
  131786. 4,
  131787. };
  131788. static long _vq_lengthlist__44u0__p4_0[] = {
  131789. 4, 5, 5, 9, 9, 5, 6, 6, 9, 9, 5, 6, 6, 9, 9, 9,
  131790. 10, 9,12,12, 9, 9,10,12,12, 5, 7, 7,10,10, 7, 7,
  131791. 8,10,10, 6, 7, 8,10,10,10,10,10,11,13,10, 9,10,
  131792. 12,13, 5, 7, 7,10,10, 6, 8, 7,10,10, 7, 8, 7,10,
  131793. 10, 9,10,10,12,12,10,10,10,13,11, 9,10,10,13,13,
  131794. 10,11,10,13,13,10,10,10,13,13,12,12,13,14,14,12,
  131795. 12,13,14,14, 9,10,10,13,13,10,10,10,13,13,10,10,
  131796. 10,13,13,12,13,12,15,14,12,13,12,15,15, 5, 7, 6,
  131797. 10,10, 7, 8, 8,10,10, 7, 8, 8,10,10,10,11,10,13,
  131798. 13,10,10,10,12,12, 7, 8, 8,11,10, 8, 8, 9,10,11,
  131799. 8, 9, 9,11,11,11,10,11,11,14,11,11,11,13,13, 6,
  131800. 8, 8,10,10, 7, 9, 8,11,10, 8, 9, 9,11,11,10,11,
  131801. 10,14,11,10,11,11,13,13,10,11,11,14,13,10,10,11,
  131802. 14,13,10,11,11,14,14,12,11,13,12,16,13,14,14,15,
  131803. 15,10,10,11,13,14,10,11,10,14,13,10,11,11,14,14,
  131804. 12,13,12,15,13,13,13,14,15,16, 5, 7, 7,10,10, 7,
  131805. 8, 8,10,10, 7, 8, 8,10,10,10,10,10,13,13,10,10,
  131806. 11,12,13, 6, 8, 8,11,10, 8, 9, 9,11,11, 7, 8, 9,
  131807. 10,11,10,11,11,13,13,10,10,11,11,13, 6, 8, 8,10,
  131808. 11, 8, 9, 9,11,11, 8, 9, 8,12,10,10,11,11,13,13,
  131809. 10,11,10,14,11,10,10,10,14,13,10,11,11,14,13,10,
  131810. 10,11,13,13,12,14,14,16,16,12,12,13,13,15,10,11,
  131811. 11,13,14,10,11,11,14,15,10,11,10,13,13,13,14,13,
  131812. 16,16,12,13,11,15,12, 9,10,10,13,13,10,11,11,14,
  131813. 13,10,10,11,13,14,13,14,13,16,16,13,13,13,15,16,
  131814. 9,10,10,13,13,10,10,11,13,14,10,11,11,15,13,13,
  131815. 13,14,14,18,13,13,14,16,15, 9,10,10,13,14,10,11,
  131816. 10,14,13,10,11,11,13,14,13,14,13,16,15,13,13,14,
  131817. 15,16,12,13,12,16,14,11,11,13,15,15,13,14,13,16,
  131818. 15,15,12,16,12,17,14,15,15,17,17,12,13,13,14,16,
  131819. 11,13,11,16,15,12,13,14,15,16,14,15,13, 0,14,14,
  131820. 16,16, 0, 0, 9,10,10,13,13,10,11,10,14,14,10,11,
  131821. 11,13,13,12,13,13,14,16,13,14,14,16,16, 9,10,10,
  131822. 14,14,11,11,11,14,13,10,10,11,14,14,13,13,13,16,
  131823. 16,13,13,14,14,17, 9,10,10,13,14,10,11,11,13,15,
  131824. 10,11,10,14,14,13,13,13,14,17,13,14,13,17,14,12,
  131825. 13,13,16,14,13,14,13,16,15,12,12,13,15,16,15,15,
  131826. 16,18,16,15,13,15,14, 0,12,12,13,14,16,13,13,14,
  131827. 15,16,11,12,11,16,14,15,16,16,17,17,14,15,12,17,
  131828. 12,
  131829. };
  131830. static float _vq_quantthresh__44u0__p4_0[] = {
  131831. -1.5, -0.5, 0.5, 1.5,
  131832. };
  131833. static long _vq_quantmap__44u0__p4_0[] = {
  131834. 3, 1, 0, 2, 4,
  131835. };
  131836. static encode_aux_threshmatch _vq_auxt__44u0__p4_0 = {
  131837. _vq_quantthresh__44u0__p4_0,
  131838. _vq_quantmap__44u0__p4_0,
  131839. 5,
  131840. 5
  131841. };
  131842. static static_codebook _44u0__p4_0 = {
  131843. 4, 625,
  131844. _vq_lengthlist__44u0__p4_0,
  131845. 1, -533725184, 1611661312, 3, 0,
  131846. _vq_quantlist__44u0__p4_0,
  131847. NULL,
  131848. &_vq_auxt__44u0__p4_0,
  131849. NULL,
  131850. 0
  131851. };
  131852. static long _vq_quantlist__44u0__p5_0[] = {
  131853. 4,
  131854. 3,
  131855. 5,
  131856. 2,
  131857. 6,
  131858. 1,
  131859. 7,
  131860. 0,
  131861. 8,
  131862. };
  131863. static long _vq_lengthlist__44u0__p5_0[] = {
  131864. 1, 4, 4, 7, 7, 7, 7, 9, 9, 4, 6, 6, 8, 8, 8, 8,
  131865. 9, 9, 4, 6, 6, 8, 8, 8, 8, 9, 9, 7, 8, 8, 9, 9,
  131866. 9, 9,11,10, 7, 8, 8, 9, 9, 9, 9,10,10, 7, 8, 8,
  131867. 9, 9,10,10,11,11, 7, 8, 8, 9, 9,10,10,11,11, 9,
  131868. 9, 9,10,10,11,11,12,12, 9, 9, 9,10,11,11,11,12,
  131869. 12,
  131870. };
  131871. static float _vq_quantthresh__44u0__p5_0[] = {
  131872. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  131873. };
  131874. static long _vq_quantmap__44u0__p5_0[] = {
  131875. 7, 5, 3, 1, 0, 2, 4, 6,
  131876. 8,
  131877. };
  131878. static encode_aux_threshmatch _vq_auxt__44u0__p5_0 = {
  131879. _vq_quantthresh__44u0__p5_0,
  131880. _vq_quantmap__44u0__p5_0,
  131881. 9,
  131882. 9
  131883. };
  131884. static static_codebook _44u0__p5_0 = {
  131885. 2, 81,
  131886. _vq_lengthlist__44u0__p5_0,
  131887. 1, -531628032, 1611661312, 4, 0,
  131888. _vq_quantlist__44u0__p5_0,
  131889. NULL,
  131890. &_vq_auxt__44u0__p5_0,
  131891. NULL,
  131892. 0
  131893. };
  131894. static long _vq_quantlist__44u0__p6_0[] = {
  131895. 6,
  131896. 5,
  131897. 7,
  131898. 4,
  131899. 8,
  131900. 3,
  131901. 9,
  131902. 2,
  131903. 10,
  131904. 1,
  131905. 11,
  131906. 0,
  131907. 12,
  131908. };
  131909. static long _vq_lengthlist__44u0__p6_0[] = {
  131910. 1, 4, 4, 6, 6, 8, 8,10, 9,11,10,14,13, 4, 6, 5,
  131911. 8, 8, 9, 9,11,10,11,11,14,14, 4, 5, 6, 8, 8, 9,
  131912. 9,10,10,11,11,14,14, 6, 8, 8, 9, 9,10,10,11,11,
  131913. 12,12,16,15, 7, 8, 8, 9, 9,10,10,11,11,12,12,15,
  131914. 15, 9,10,10,10,10,11,11,12,12,12,12,15,15, 9,10,
  131915. 9,10,11,11,11,12,12,12,13,15,15,10,10,11,11,11,
  131916. 12,12,13,12,13,13,16,15,10,11,11,11,11,12,12,13,
  131917. 12,13,13,16,17,11,11,12,12,12,13,13,13,14,14,15,
  131918. 17,17,11,11,12,12,12,13,13,13,14,14,14,16,18,14,
  131919. 15,15,15,15,16,16,16,16,17,18, 0, 0,14,15,15,15,
  131920. 15,17,16,17,18,17,17,18, 0,
  131921. };
  131922. static float _vq_quantthresh__44u0__p6_0[] = {
  131923. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  131924. 12.5, 17.5, 22.5, 27.5,
  131925. };
  131926. static long _vq_quantmap__44u0__p6_0[] = {
  131927. 11, 9, 7, 5, 3, 1, 0, 2,
  131928. 4, 6, 8, 10, 12,
  131929. };
  131930. static encode_aux_threshmatch _vq_auxt__44u0__p6_0 = {
  131931. _vq_quantthresh__44u0__p6_0,
  131932. _vq_quantmap__44u0__p6_0,
  131933. 13,
  131934. 13
  131935. };
  131936. static static_codebook _44u0__p6_0 = {
  131937. 2, 169,
  131938. _vq_lengthlist__44u0__p6_0,
  131939. 1, -526516224, 1616117760, 4, 0,
  131940. _vq_quantlist__44u0__p6_0,
  131941. NULL,
  131942. &_vq_auxt__44u0__p6_0,
  131943. NULL,
  131944. 0
  131945. };
  131946. static long _vq_quantlist__44u0__p6_1[] = {
  131947. 2,
  131948. 1,
  131949. 3,
  131950. 0,
  131951. 4,
  131952. };
  131953. static long _vq_lengthlist__44u0__p6_1[] = {
  131954. 2, 4, 4, 5, 5, 4, 5, 5, 5, 5, 4, 5, 5, 5, 5, 5,
  131955. 6, 6, 6, 6, 5, 6, 6, 6, 6,
  131956. };
  131957. static float _vq_quantthresh__44u0__p6_1[] = {
  131958. -1.5, -0.5, 0.5, 1.5,
  131959. };
  131960. static long _vq_quantmap__44u0__p6_1[] = {
  131961. 3, 1, 0, 2, 4,
  131962. };
  131963. static encode_aux_threshmatch _vq_auxt__44u0__p6_1 = {
  131964. _vq_quantthresh__44u0__p6_1,
  131965. _vq_quantmap__44u0__p6_1,
  131966. 5,
  131967. 5
  131968. };
  131969. static static_codebook _44u0__p6_1 = {
  131970. 2, 25,
  131971. _vq_lengthlist__44u0__p6_1,
  131972. 1, -533725184, 1611661312, 3, 0,
  131973. _vq_quantlist__44u0__p6_1,
  131974. NULL,
  131975. &_vq_auxt__44u0__p6_1,
  131976. NULL,
  131977. 0
  131978. };
  131979. static long _vq_quantlist__44u0__p7_0[] = {
  131980. 2,
  131981. 1,
  131982. 3,
  131983. 0,
  131984. 4,
  131985. };
  131986. static long _vq_lengthlist__44u0__p7_0[] = {
  131987. 1, 4, 4,11,11, 9,11,11,11,11,11,11,11,11,11,11,
  131988. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131989. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131990. 11,11, 9,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131991. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131992. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131993. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131994. 11,11,11,11,11,11,11,11,11,11,11,11,11,10,11,11,
  131995. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131996. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131997. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131998. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131999. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132000. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132001. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132002. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132003. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132004. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132005. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132006. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132007. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132008. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132009. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132010. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132011. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132012. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132013. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132014. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132015. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132016. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132017. 11,11,11,11,11,11,10,10,10,10,10,10,10,10,10,10,
  132018. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  132019. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  132020. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  132021. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  132022. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  132023. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  132024. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  132025. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  132026. 10,
  132027. };
  132028. static float _vq_quantthresh__44u0__p7_0[] = {
  132029. -253.5, -84.5, 84.5, 253.5,
  132030. };
  132031. static long _vq_quantmap__44u0__p7_0[] = {
  132032. 3, 1, 0, 2, 4,
  132033. };
  132034. static encode_aux_threshmatch _vq_auxt__44u0__p7_0 = {
  132035. _vq_quantthresh__44u0__p7_0,
  132036. _vq_quantmap__44u0__p7_0,
  132037. 5,
  132038. 5
  132039. };
  132040. static static_codebook _44u0__p7_0 = {
  132041. 4, 625,
  132042. _vq_lengthlist__44u0__p7_0,
  132043. 1, -518709248, 1626677248, 3, 0,
  132044. _vq_quantlist__44u0__p7_0,
  132045. NULL,
  132046. &_vq_auxt__44u0__p7_0,
  132047. NULL,
  132048. 0
  132049. };
  132050. static long _vq_quantlist__44u0__p7_1[] = {
  132051. 6,
  132052. 5,
  132053. 7,
  132054. 4,
  132055. 8,
  132056. 3,
  132057. 9,
  132058. 2,
  132059. 10,
  132060. 1,
  132061. 11,
  132062. 0,
  132063. 12,
  132064. };
  132065. static long _vq_lengthlist__44u0__p7_1[] = {
  132066. 1, 4, 4, 6, 6, 6, 6, 7, 7, 8, 8, 9, 9, 5, 7, 7,
  132067. 8, 7, 7, 7, 9, 8,10, 9,10,11, 5, 7, 7, 8, 8, 7,
  132068. 7, 8, 9,10,10,11,11, 6, 8, 8, 9, 9, 9, 9,11,10,
  132069. 12,12,15,12, 6, 8, 8, 9, 9, 9, 9,11,11,12,11,14,
  132070. 12, 7, 8, 8,10,10,12,12,13,13,13,15,13,13, 7, 8,
  132071. 8,10,10,11,11,13,12,14,15,15,15, 9,10,10,11,12,
  132072. 13,13,14,15,14,15,14,15, 8,10,10,12,12,14,14,15,
  132073. 14,14,15,15,14,10,12,12,14,14,15,14,15,15,15,14,
  132074. 15,15,10,12,12,13,14,15,14,15,15,14,15,15,15,12,
  132075. 15,13,15,14,15,15,15,15,15,15,15,15,13,13,15,15,
  132076. 15,15,15,15,15,15,15,15,15,
  132077. };
  132078. static float _vq_quantthresh__44u0__p7_1[] = {
  132079. -71.5, -58.5, -45.5, -32.5, -19.5, -6.5, 6.5, 19.5,
  132080. 32.5, 45.5, 58.5, 71.5,
  132081. };
  132082. static long _vq_quantmap__44u0__p7_1[] = {
  132083. 11, 9, 7, 5, 3, 1, 0, 2,
  132084. 4, 6, 8, 10, 12,
  132085. };
  132086. static encode_aux_threshmatch _vq_auxt__44u0__p7_1 = {
  132087. _vq_quantthresh__44u0__p7_1,
  132088. _vq_quantmap__44u0__p7_1,
  132089. 13,
  132090. 13
  132091. };
  132092. static static_codebook _44u0__p7_1 = {
  132093. 2, 169,
  132094. _vq_lengthlist__44u0__p7_1,
  132095. 1, -523010048, 1618608128, 4, 0,
  132096. _vq_quantlist__44u0__p7_1,
  132097. NULL,
  132098. &_vq_auxt__44u0__p7_1,
  132099. NULL,
  132100. 0
  132101. };
  132102. static long _vq_quantlist__44u0__p7_2[] = {
  132103. 6,
  132104. 5,
  132105. 7,
  132106. 4,
  132107. 8,
  132108. 3,
  132109. 9,
  132110. 2,
  132111. 10,
  132112. 1,
  132113. 11,
  132114. 0,
  132115. 12,
  132116. };
  132117. static long _vq_lengthlist__44u0__p7_2[] = {
  132118. 2, 5, 4, 6, 6, 7, 7, 8, 8, 8, 8, 9, 8, 5, 5, 6,
  132119. 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 5, 6, 5, 7, 7, 8,
  132120. 8, 8, 8, 9, 9, 9, 9, 6, 7, 7, 8, 8, 8, 8, 9, 8,
  132121. 9, 9, 9, 9, 6, 7, 7, 8, 7, 8, 8, 9, 9, 9, 9, 9,
  132122. 9, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 7, 8,
  132123. 8, 9, 8, 9, 8, 9, 9, 9, 9, 9, 9, 8, 9, 8, 9, 9,
  132124. 9, 9, 9, 9, 9, 9,10,10, 8, 8, 9, 9, 9, 9, 9, 9,
  132125. 9, 9,10, 9,10, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  132126. 9, 9, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  132127. 9, 9, 9, 9, 9, 9, 9, 9,10,10,10, 9, 9, 9, 9, 9,
  132128. 9, 9, 9,10, 9, 9,10,10, 9,
  132129. };
  132130. static float _vq_quantthresh__44u0__p7_2[] = {
  132131. -5.5, -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5,
  132132. 2.5, 3.5, 4.5, 5.5,
  132133. };
  132134. static long _vq_quantmap__44u0__p7_2[] = {
  132135. 11, 9, 7, 5, 3, 1, 0, 2,
  132136. 4, 6, 8, 10, 12,
  132137. };
  132138. static encode_aux_threshmatch _vq_auxt__44u0__p7_2 = {
  132139. _vq_quantthresh__44u0__p7_2,
  132140. _vq_quantmap__44u0__p7_2,
  132141. 13,
  132142. 13
  132143. };
  132144. static static_codebook _44u0__p7_2 = {
  132145. 2, 169,
  132146. _vq_lengthlist__44u0__p7_2,
  132147. 1, -531103744, 1611661312, 4, 0,
  132148. _vq_quantlist__44u0__p7_2,
  132149. NULL,
  132150. &_vq_auxt__44u0__p7_2,
  132151. NULL,
  132152. 0
  132153. };
  132154. static long _huff_lengthlist__44u0__short[] = {
  132155. 12,13,14,13,17,12,15,17, 5, 5, 6,10,10,11,15,16,
  132156. 4, 3, 3, 7, 5, 7,10,16, 7, 7, 7,10, 9,11,12,16,
  132157. 6, 5, 5, 9, 5, 6,10,16, 8, 7, 7, 9, 6, 7, 9,16,
  132158. 11, 7, 3, 6, 4, 5, 8,16,12, 9, 4, 8, 5, 7, 9,16,
  132159. };
  132160. static static_codebook _huff_book__44u0__short = {
  132161. 2, 64,
  132162. _huff_lengthlist__44u0__short,
  132163. 0, 0, 0, 0, 0,
  132164. NULL,
  132165. NULL,
  132166. NULL,
  132167. NULL,
  132168. 0
  132169. };
  132170. static long _huff_lengthlist__44u1__long[] = {
  132171. 5, 8,13,10,17,11,11,15, 7, 2, 4, 5, 8, 7, 9,16,
  132172. 13, 4, 3, 5, 6, 8,11,20,10, 4, 5, 5, 7, 6, 8,18,
  132173. 15, 7, 6, 7, 8,10,14,20,10, 6, 7, 6, 9, 7, 8,17,
  132174. 9, 8,10, 8,10, 5, 4,11,12,17,19,14,16,10, 7,12,
  132175. };
  132176. static static_codebook _huff_book__44u1__long = {
  132177. 2, 64,
  132178. _huff_lengthlist__44u1__long,
  132179. 0, 0, 0, 0, 0,
  132180. NULL,
  132181. NULL,
  132182. NULL,
  132183. NULL,
  132184. 0
  132185. };
  132186. static long _vq_quantlist__44u1__p1_0[] = {
  132187. 1,
  132188. 0,
  132189. 2,
  132190. };
  132191. static long _vq_lengthlist__44u1__p1_0[] = {
  132192. 1, 4, 4, 5, 8, 7, 5, 7, 8, 5, 8, 8, 8,11,11, 8,
  132193. 10,10, 5, 8, 8, 8,11,10, 8,11,11, 4, 8, 8, 8,11,
  132194. 11, 8,11,11, 8,12,11,11,13,13,11,13,14, 7,11,11,
  132195. 10,13,12,11,13,14, 4, 8, 8, 8,11,11, 8,11,12, 8,
  132196. 11,11,11,13,13,10,12,13, 8,11,11,11,14,13,11,14,
  132197. 13,
  132198. };
  132199. static float _vq_quantthresh__44u1__p1_0[] = {
  132200. -0.5, 0.5,
  132201. };
  132202. static long _vq_quantmap__44u1__p1_0[] = {
  132203. 1, 0, 2,
  132204. };
  132205. static encode_aux_threshmatch _vq_auxt__44u1__p1_0 = {
  132206. _vq_quantthresh__44u1__p1_0,
  132207. _vq_quantmap__44u1__p1_0,
  132208. 3,
  132209. 3
  132210. };
  132211. static static_codebook _44u1__p1_0 = {
  132212. 4, 81,
  132213. _vq_lengthlist__44u1__p1_0,
  132214. 1, -535822336, 1611661312, 2, 0,
  132215. _vq_quantlist__44u1__p1_0,
  132216. NULL,
  132217. &_vq_auxt__44u1__p1_0,
  132218. NULL,
  132219. 0
  132220. };
  132221. static long _vq_quantlist__44u1__p2_0[] = {
  132222. 1,
  132223. 0,
  132224. 2,
  132225. };
  132226. static long _vq_lengthlist__44u1__p2_0[] = {
  132227. 2, 4, 4, 5, 6, 6, 5, 6, 6, 5, 7, 7, 7, 8, 8, 6,
  132228. 8, 8, 5, 7, 7, 6, 8, 8, 7, 8, 8, 4, 7, 7, 7, 8,
  132229. 8, 7, 8, 8, 7, 8, 8, 8, 9,10, 8,10,10, 6, 8, 8,
  132230. 8,10, 8, 8,10,10, 5, 7, 7, 7, 8, 8, 7, 8, 8, 6,
  132231. 8, 8, 8,10,10, 8, 8,10, 6, 8, 8, 8,10,10, 8,10,
  132232. 9,
  132233. };
  132234. static float _vq_quantthresh__44u1__p2_0[] = {
  132235. -0.5, 0.5,
  132236. };
  132237. static long _vq_quantmap__44u1__p2_0[] = {
  132238. 1, 0, 2,
  132239. };
  132240. static encode_aux_threshmatch _vq_auxt__44u1__p2_0 = {
  132241. _vq_quantthresh__44u1__p2_0,
  132242. _vq_quantmap__44u1__p2_0,
  132243. 3,
  132244. 3
  132245. };
  132246. static static_codebook _44u1__p2_0 = {
  132247. 4, 81,
  132248. _vq_lengthlist__44u1__p2_0,
  132249. 1, -535822336, 1611661312, 2, 0,
  132250. _vq_quantlist__44u1__p2_0,
  132251. NULL,
  132252. &_vq_auxt__44u1__p2_0,
  132253. NULL,
  132254. 0
  132255. };
  132256. static long _vq_quantlist__44u1__p3_0[] = {
  132257. 2,
  132258. 1,
  132259. 3,
  132260. 0,
  132261. 4,
  132262. };
  132263. static long _vq_lengthlist__44u1__p3_0[] = {
  132264. 1, 5, 5, 8, 8, 5, 8, 7, 9, 9, 5, 7, 8, 9, 9, 9,
  132265. 10, 9,12,12, 9, 9,10,12,12, 6, 8, 8,11,10, 8,10,
  132266. 10,11,11, 8, 9,10,11,11,10,11,11,14,13,10,11,11,
  132267. 13,13, 5, 8, 8,10,10, 8,10,10,11,11, 8,10,10,11,
  132268. 11,10,11,11,13,13,10,11,11,13,13, 9,11,11,15,14,
  132269. 10,12,12,15,14,10,12,11,15,14,13,14,14,16,16,12,
  132270. 14,13,17,15, 9,11,11,14,15,10,11,12,14,16,10,11,
  132271. 12,14,16,12,13,14,16,16,13,13,15,15,18, 5, 8, 8,
  132272. 11,11, 8,10,10,12,12, 8,10,10,12,13,11,12,12,14,
  132273. 14,11,12,12,15,15, 8,10,10,13,13,10,12,12,13,13,
  132274. 10,12,12,14,14,12,13,13,15,15,12,13,13,16,16, 7,
  132275. 10,10,12,12,10,12,11,13,13,10,12,12,13,14,12,13,
  132276. 12,15,14,12,13,13,16,16,10,12,12,17,16,12,13,13,
  132277. 16,15,11,13,13,17,17,15,15,15,16,17,14,15,15,19,
  132278. 19,10,12,12,15,16,11,13,12,15,18,11,13,13,16,16,
  132279. 14,15,15,17,17,14,15,15,17,19, 5, 8, 8,11,11, 8,
  132280. 10,10,12,12, 8,10,10,12,12,11,12,12,16,15,11,12,
  132281. 12,14,15, 7,10,10,13,13,10,12,12,14,13,10,11,12,
  132282. 13,13,12,13,13,16,16,12,12,13,15,15, 8,10,10,13,
  132283. 13,10,12,12,14,14,10,12,12,13,13,12,13,13,16,16,
  132284. 12,13,13,15,15,10,12,12,16,15,11,13,13,17,16,11,
  132285. 12,13,16,15,13,15,15,19,17,14,15,14,17,16,10,12,
  132286. 12,16,16,11,13,13,16,17,12,13,13,15,17,14,15,15,
  132287. 17,19,14,15,15,17,17, 8,11,11,16,16,10,13,12,17,
  132288. 17,10,12,13,16,16,15,17,16,20,19,14,15,17,18,19,
  132289. 9,12,12,16,17,11,13,14,17,18,11,13,13,19,18,16,
  132290. 17,18,19,19,15,16,16,19,19, 9,12,12,16,17,11,14,
  132291. 13,18,17,11,13,13,17,17,16,17,16,20,19,14,16,16,
  132292. 18,18,12,15,15,19,17,14,15,16, 0,20,13,15,16,20,
  132293. 17,18,16,20, 0, 0,15,16,19,20, 0,12,15,14,18,19,
  132294. 13,16,15,20,19,13,16,15,20,18,17,18,17, 0,20,16,
  132295. 17,16, 0, 0, 8,11,11,16,15,10,12,12,17,17,10,13,
  132296. 13,17,16,14,16,15,18,20,15,16,16,19,19, 9,12,12,
  132297. 16,16,11,13,13,17,16,11,13,14,17,18,15,15,16,20,
  132298. 20,16,16,17,19,19, 9,13,12,16,17,11,14,13,17,17,
  132299. 11,14,14,18,17,14,16,15,18,19,16,17,18,18,19,12,
  132300. 14,15,19,18,13,15,16,18, 0,13,14,15, 0, 0,16,16,
  132301. 17,20, 0,17,17,20,20, 0,12,15,15,19,20,13,15,15,
  132302. 0, 0,14,16,15, 0, 0,15,18,16, 0, 0,17,18,16, 0,
  132303. 19,
  132304. };
  132305. static float _vq_quantthresh__44u1__p3_0[] = {
  132306. -1.5, -0.5, 0.5, 1.5,
  132307. };
  132308. static long _vq_quantmap__44u1__p3_0[] = {
  132309. 3, 1, 0, 2, 4,
  132310. };
  132311. static encode_aux_threshmatch _vq_auxt__44u1__p3_0 = {
  132312. _vq_quantthresh__44u1__p3_0,
  132313. _vq_quantmap__44u1__p3_0,
  132314. 5,
  132315. 5
  132316. };
  132317. static static_codebook _44u1__p3_0 = {
  132318. 4, 625,
  132319. _vq_lengthlist__44u1__p3_0,
  132320. 1, -533725184, 1611661312, 3, 0,
  132321. _vq_quantlist__44u1__p3_0,
  132322. NULL,
  132323. &_vq_auxt__44u1__p3_0,
  132324. NULL,
  132325. 0
  132326. };
  132327. static long _vq_quantlist__44u1__p4_0[] = {
  132328. 2,
  132329. 1,
  132330. 3,
  132331. 0,
  132332. 4,
  132333. };
  132334. static long _vq_lengthlist__44u1__p4_0[] = {
  132335. 4, 5, 5, 9, 9, 5, 6, 6, 9, 9, 5, 6, 6, 9, 9, 9,
  132336. 10, 9,12,12, 9, 9,10,12,12, 5, 7, 7,10,10, 7, 7,
  132337. 8,10,10, 6, 7, 8,10,10,10,10,10,11,13,10, 9,10,
  132338. 12,13, 5, 7, 7,10,10, 6, 8, 7,10,10, 7, 8, 7,10,
  132339. 10, 9,10,10,12,12,10,10,10,13,11, 9,10,10,13,13,
  132340. 10,11,10,13,13,10,10,10,13,13,12,12,13,14,14,12,
  132341. 12,13,14,14, 9,10,10,13,13,10,10,10,13,13,10,10,
  132342. 10,13,13,12,13,12,15,14,12,13,12,15,15, 5, 7, 6,
  132343. 10,10, 7, 8, 8,10,10, 7, 8, 8,10,10,10,11,10,13,
  132344. 13,10,10,10,12,12, 7, 8, 8,11,10, 8, 8, 9,10,11,
  132345. 8, 9, 9,11,11,11,10,11,11,14,11,11,11,13,13, 6,
  132346. 8, 8,10,10, 7, 9, 8,11,10, 8, 9, 9,11,11,10,11,
  132347. 10,14,11,10,11,11,13,13,10,11,11,14,13,10,10,11,
  132348. 14,13,10,11,11,14,14,12,11,13,12,16,13,14,14,15,
  132349. 15,10,10,11,13,14,10,11,10,14,13,10,11,11,14,14,
  132350. 12,13,12,15,13,13,13,14,15,16, 5, 7, 7,10,10, 7,
  132351. 8, 8,10,10, 7, 8, 8,10,10,10,10,10,13,13,10,10,
  132352. 11,12,13, 6, 8, 8,11,10, 8, 9, 9,11,11, 7, 8, 9,
  132353. 10,11,10,11,11,13,13,10,10,11,11,13, 6, 8, 8,10,
  132354. 11, 8, 9, 9,11,11, 8, 9, 8,12,10,10,11,11,13,13,
  132355. 10,11,10,14,11,10,10,10,14,13,10,11,11,14,13,10,
  132356. 10,11,13,13,12,14,14,16,16,12,12,13,13,15,10,11,
  132357. 11,13,14,10,11,11,14,15,10,11,10,13,13,13,14,13,
  132358. 16,16,12,13,11,15,12, 9,10,10,13,13,10,11,11,14,
  132359. 13,10,10,11,13,14,13,14,13,16,16,13,13,13,15,16,
  132360. 9,10,10,13,13,10,10,11,13,14,10,11,11,15,13,13,
  132361. 13,14,14,18,13,13,14,16,15, 9,10,10,13,14,10,11,
  132362. 10,14,13,10,11,11,13,14,13,14,13,16,15,13,13,14,
  132363. 15,16,12,13,12,16,14,11,11,13,15,15,13,14,13,16,
  132364. 15,15,12,16,12,17,14,15,15,17,17,12,13,13,14,16,
  132365. 11,13,11,16,15,12,13,14,15,16,14,15,13, 0,14,14,
  132366. 16,16, 0, 0, 9,10,10,13,13,10,11,10,14,14,10,11,
  132367. 11,13,13,12,13,13,14,16,13,14,14,16,16, 9,10,10,
  132368. 14,14,11,11,11,14,13,10,10,11,14,14,13,13,13,16,
  132369. 16,13,13,14,14,17, 9,10,10,13,14,10,11,11,13,15,
  132370. 10,11,10,14,14,13,13,13,14,17,13,14,13,17,14,12,
  132371. 13,13,16,14,13,14,13,16,15,12,12,13,15,16,15,15,
  132372. 16,18,16,15,13,15,14, 0,12,12,13,14,16,13,13,14,
  132373. 15,16,11,12,11,16,14,15,16,16,17,17,14,15,12,17,
  132374. 12,
  132375. };
  132376. static float _vq_quantthresh__44u1__p4_0[] = {
  132377. -1.5, -0.5, 0.5, 1.5,
  132378. };
  132379. static long _vq_quantmap__44u1__p4_0[] = {
  132380. 3, 1, 0, 2, 4,
  132381. };
  132382. static encode_aux_threshmatch _vq_auxt__44u1__p4_0 = {
  132383. _vq_quantthresh__44u1__p4_0,
  132384. _vq_quantmap__44u1__p4_0,
  132385. 5,
  132386. 5
  132387. };
  132388. static static_codebook _44u1__p4_0 = {
  132389. 4, 625,
  132390. _vq_lengthlist__44u1__p4_0,
  132391. 1, -533725184, 1611661312, 3, 0,
  132392. _vq_quantlist__44u1__p4_0,
  132393. NULL,
  132394. &_vq_auxt__44u1__p4_0,
  132395. NULL,
  132396. 0
  132397. };
  132398. static long _vq_quantlist__44u1__p5_0[] = {
  132399. 4,
  132400. 3,
  132401. 5,
  132402. 2,
  132403. 6,
  132404. 1,
  132405. 7,
  132406. 0,
  132407. 8,
  132408. };
  132409. static long _vq_lengthlist__44u1__p5_0[] = {
  132410. 1, 4, 4, 7, 7, 7, 7, 9, 9, 4, 6, 6, 8, 8, 8, 8,
  132411. 9, 9, 4, 6, 6, 8, 8, 8, 8, 9, 9, 7, 8, 8, 9, 9,
  132412. 9, 9,11,10, 7, 8, 8, 9, 9, 9, 9,10,10, 7, 8, 8,
  132413. 9, 9,10,10,11,11, 7, 8, 8, 9, 9,10,10,11,11, 9,
  132414. 9, 9,10,10,11,11,12,12, 9, 9, 9,10,11,11,11,12,
  132415. 12,
  132416. };
  132417. static float _vq_quantthresh__44u1__p5_0[] = {
  132418. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  132419. };
  132420. static long _vq_quantmap__44u1__p5_0[] = {
  132421. 7, 5, 3, 1, 0, 2, 4, 6,
  132422. 8,
  132423. };
  132424. static encode_aux_threshmatch _vq_auxt__44u1__p5_0 = {
  132425. _vq_quantthresh__44u1__p5_0,
  132426. _vq_quantmap__44u1__p5_0,
  132427. 9,
  132428. 9
  132429. };
  132430. static static_codebook _44u1__p5_0 = {
  132431. 2, 81,
  132432. _vq_lengthlist__44u1__p5_0,
  132433. 1, -531628032, 1611661312, 4, 0,
  132434. _vq_quantlist__44u1__p5_0,
  132435. NULL,
  132436. &_vq_auxt__44u1__p5_0,
  132437. NULL,
  132438. 0
  132439. };
  132440. static long _vq_quantlist__44u1__p6_0[] = {
  132441. 6,
  132442. 5,
  132443. 7,
  132444. 4,
  132445. 8,
  132446. 3,
  132447. 9,
  132448. 2,
  132449. 10,
  132450. 1,
  132451. 11,
  132452. 0,
  132453. 12,
  132454. };
  132455. static long _vq_lengthlist__44u1__p6_0[] = {
  132456. 1, 4, 4, 6, 6, 8, 8,10, 9,11,10,14,13, 4, 6, 5,
  132457. 8, 8, 9, 9,11,10,11,11,14,14, 4, 5, 6, 8, 8, 9,
  132458. 9,10,10,11,11,14,14, 6, 8, 8, 9, 9,10,10,11,11,
  132459. 12,12,16,15, 7, 8, 8, 9, 9,10,10,11,11,12,12,15,
  132460. 15, 9,10,10,10,10,11,11,12,12,12,12,15,15, 9,10,
  132461. 9,10,11,11,11,12,12,12,13,15,15,10,10,11,11,11,
  132462. 12,12,13,12,13,13,16,15,10,11,11,11,11,12,12,13,
  132463. 12,13,13,16,17,11,11,12,12,12,13,13,13,14,14,15,
  132464. 17,17,11,11,12,12,12,13,13,13,14,14,14,16,18,14,
  132465. 15,15,15,15,16,16,16,16,17,18, 0, 0,14,15,15,15,
  132466. 15,17,16,17,18,17,17,18, 0,
  132467. };
  132468. static float _vq_quantthresh__44u1__p6_0[] = {
  132469. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  132470. 12.5, 17.5, 22.5, 27.5,
  132471. };
  132472. static long _vq_quantmap__44u1__p6_0[] = {
  132473. 11, 9, 7, 5, 3, 1, 0, 2,
  132474. 4, 6, 8, 10, 12,
  132475. };
  132476. static encode_aux_threshmatch _vq_auxt__44u1__p6_0 = {
  132477. _vq_quantthresh__44u1__p6_0,
  132478. _vq_quantmap__44u1__p6_0,
  132479. 13,
  132480. 13
  132481. };
  132482. static static_codebook _44u1__p6_0 = {
  132483. 2, 169,
  132484. _vq_lengthlist__44u1__p6_0,
  132485. 1, -526516224, 1616117760, 4, 0,
  132486. _vq_quantlist__44u1__p6_0,
  132487. NULL,
  132488. &_vq_auxt__44u1__p6_0,
  132489. NULL,
  132490. 0
  132491. };
  132492. static long _vq_quantlist__44u1__p6_1[] = {
  132493. 2,
  132494. 1,
  132495. 3,
  132496. 0,
  132497. 4,
  132498. };
  132499. static long _vq_lengthlist__44u1__p6_1[] = {
  132500. 2, 4, 4, 5, 5, 4, 5, 5, 5, 5, 4, 5, 5, 5, 5, 5,
  132501. 6, 6, 6, 6, 5, 6, 6, 6, 6,
  132502. };
  132503. static float _vq_quantthresh__44u1__p6_1[] = {
  132504. -1.5, -0.5, 0.5, 1.5,
  132505. };
  132506. static long _vq_quantmap__44u1__p6_1[] = {
  132507. 3, 1, 0, 2, 4,
  132508. };
  132509. static encode_aux_threshmatch _vq_auxt__44u1__p6_1 = {
  132510. _vq_quantthresh__44u1__p6_1,
  132511. _vq_quantmap__44u1__p6_1,
  132512. 5,
  132513. 5
  132514. };
  132515. static static_codebook _44u1__p6_1 = {
  132516. 2, 25,
  132517. _vq_lengthlist__44u1__p6_1,
  132518. 1, -533725184, 1611661312, 3, 0,
  132519. _vq_quantlist__44u1__p6_1,
  132520. NULL,
  132521. &_vq_auxt__44u1__p6_1,
  132522. NULL,
  132523. 0
  132524. };
  132525. static long _vq_quantlist__44u1__p7_0[] = {
  132526. 3,
  132527. 2,
  132528. 4,
  132529. 1,
  132530. 5,
  132531. 0,
  132532. 6,
  132533. };
  132534. static long _vq_lengthlist__44u1__p7_0[] = {
  132535. 1, 3, 2, 9, 9, 7, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  132536. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  132537. 9, 9, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  132538. 8,
  132539. };
  132540. static float _vq_quantthresh__44u1__p7_0[] = {
  132541. -422.5, -253.5, -84.5, 84.5, 253.5, 422.5,
  132542. };
  132543. static long _vq_quantmap__44u1__p7_0[] = {
  132544. 5, 3, 1, 0, 2, 4, 6,
  132545. };
  132546. static encode_aux_threshmatch _vq_auxt__44u1__p7_0 = {
  132547. _vq_quantthresh__44u1__p7_0,
  132548. _vq_quantmap__44u1__p7_0,
  132549. 7,
  132550. 7
  132551. };
  132552. static static_codebook _44u1__p7_0 = {
  132553. 2, 49,
  132554. _vq_lengthlist__44u1__p7_0,
  132555. 1, -518017024, 1626677248, 3, 0,
  132556. _vq_quantlist__44u1__p7_0,
  132557. NULL,
  132558. &_vq_auxt__44u1__p7_0,
  132559. NULL,
  132560. 0
  132561. };
  132562. static long _vq_quantlist__44u1__p7_1[] = {
  132563. 6,
  132564. 5,
  132565. 7,
  132566. 4,
  132567. 8,
  132568. 3,
  132569. 9,
  132570. 2,
  132571. 10,
  132572. 1,
  132573. 11,
  132574. 0,
  132575. 12,
  132576. };
  132577. static long _vq_lengthlist__44u1__p7_1[] = {
  132578. 1, 4, 4, 6, 6, 6, 6, 7, 7, 8, 8, 9, 9, 5, 7, 7,
  132579. 8, 7, 7, 7, 9, 8,10, 9,10,11, 5, 7, 7, 8, 8, 7,
  132580. 7, 8, 9,10,10,11,11, 6, 8, 8, 9, 9, 9, 9,11,10,
  132581. 12,12,15,12, 6, 8, 8, 9, 9, 9, 9,11,11,12,11,14,
  132582. 12, 7, 8, 8,10,10,12,12,13,13,13,15,13,13, 7, 8,
  132583. 8,10,10,11,11,13,12,14,15,15,15, 9,10,10,11,12,
  132584. 13,13,14,15,14,15,14,15, 8,10,10,12,12,14,14,15,
  132585. 14,14,15,15,14,10,12,12,14,14,15,14,15,15,15,14,
  132586. 15,15,10,12,12,13,14,15,14,15,15,14,15,15,15,12,
  132587. 15,13,15,14,15,15,15,15,15,15,15,15,13,13,15,15,
  132588. 15,15,15,15,15,15,15,15,15,
  132589. };
  132590. static float _vq_quantthresh__44u1__p7_1[] = {
  132591. -71.5, -58.5, -45.5, -32.5, -19.5, -6.5, 6.5, 19.5,
  132592. 32.5, 45.5, 58.5, 71.5,
  132593. };
  132594. static long _vq_quantmap__44u1__p7_1[] = {
  132595. 11, 9, 7, 5, 3, 1, 0, 2,
  132596. 4, 6, 8, 10, 12,
  132597. };
  132598. static encode_aux_threshmatch _vq_auxt__44u1__p7_1 = {
  132599. _vq_quantthresh__44u1__p7_1,
  132600. _vq_quantmap__44u1__p7_1,
  132601. 13,
  132602. 13
  132603. };
  132604. static static_codebook _44u1__p7_1 = {
  132605. 2, 169,
  132606. _vq_lengthlist__44u1__p7_1,
  132607. 1, -523010048, 1618608128, 4, 0,
  132608. _vq_quantlist__44u1__p7_1,
  132609. NULL,
  132610. &_vq_auxt__44u1__p7_1,
  132611. NULL,
  132612. 0
  132613. };
  132614. static long _vq_quantlist__44u1__p7_2[] = {
  132615. 6,
  132616. 5,
  132617. 7,
  132618. 4,
  132619. 8,
  132620. 3,
  132621. 9,
  132622. 2,
  132623. 10,
  132624. 1,
  132625. 11,
  132626. 0,
  132627. 12,
  132628. };
  132629. static long _vq_lengthlist__44u1__p7_2[] = {
  132630. 2, 5, 4, 6, 6, 7, 7, 8, 8, 8, 8, 9, 8, 5, 5, 6,
  132631. 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 5, 6, 5, 7, 7, 8,
  132632. 8, 8, 8, 9, 9, 9, 9, 6, 7, 7, 8, 8, 8, 8, 9, 8,
  132633. 9, 9, 9, 9, 6, 7, 7, 8, 7, 8, 8, 9, 9, 9, 9, 9,
  132634. 9, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 7, 8,
  132635. 8, 9, 8, 9, 8, 9, 9, 9, 9, 9, 9, 8, 9, 8, 9, 9,
  132636. 9, 9, 9, 9, 9, 9,10,10, 8, 8, 9, 9, 9, 9, 9, 9,
  132637. 9, 9,10, 9,10, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  132638. 9, 9, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  132639. 9, 9, 9, 9, 9, 9, 9, 9,10,10,10, 9, 9, 9, 9, 9,
  132640. 9, 9, 9,10, 9, 9,10,10, 9,
  132641. };
  132642. static float _vq_quantthresh__44u1__p7_2[] = {
  132643. -5.5, -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5,
  132644. 2.5, 3.5, 4.5, 5.5,
  132645. };
  132646. static long _vq_quantmap__44u1__p7_2[] = {
  132647. 11, 9, 7, 5, 3, 1, 0, 2,
  132648. 4, 6, 8, 10, 12,
  132649. };
  132650. static encode_aux_threshmatch _vq_auxt__44u1__p7_2 = {
  132651. _vq_quantthresh__44u1__p7_2,
  132652. _vq_quantmap__44u1__p7_2,
  132653. 13,
  132654. 13
  132655. };
  132656. static static_codebook _44u1__p7_2 = {
  132657. 2, 169,
  132658. _vq_lengthlist__44u1__p7_2,
  132659. 1, -531103744, 1611661312, 4, 0,
  132660. _vq_quantlist__44u1__p7_2,
  132661. NULL,
  132662. &_vq_auxt__44u1__p7_2,
  132663. NULL,
  132664. 0
  132665. };
  132666. static long _huff_lengthlist__44u1__short[] = {
  132667. 12,13,14,13,17,12,15,17, 5, 5, 6,10,10,11,15,16,
  132668. 4, 3, 3, 7, 5, 7,10,16, 7, 7, 7,10, 9,11,12,16,
  132669. 6, 5, 5, 9, 5, 6,10,16, 8, 7, 7, 9, 6, 7, 9,16,
  132670. 11, 7, 3, 6, 4, 5, 8,16,12, 9, 4, 8, 5, 7, 9,16,
  132671. };
  132672. static static_codebook _huff_book__44u1__short = {
  132673. 2, 64,
  132674. _huff_lengthlist__44u1__short,
  132675. 0, 0, 0, 0, 0,
  132676. NULL,
  132677. NULL,
  132678. NULL,
  132679. NULL,
  132680. 0
  132681. };
  132682. static long _huff_lengthlist__44u2__long[] = {
  132683. 5, 9,14,12,15,13,10,13, 7, 4, 5, 6, 8, 7, 8,12,
  132684. 13, 4, 3, 5, 5, 6, 9,15,12, 6, 5, 6, 6, 6, 7,14,
  132685. 14, 7, 4, 6, 4, 6, 8,15,12, 6, 6, 5, 5, 5, 6,14,
  132686. 9, 7, 8, 6, 7, 5, 4,10,10,13,14,14,15,10, 6, 8,
  132687. };
  132688. static static_codebook _huff_book__44u2__long = {
  132689. 2, 64,
  132690. _huff_lengthlist__44u2__long,
  132691. 0, 0, 0, 0, 0,
  132692. NULL,
  132693. NULL,
  132694. NULL,
  132695. NULL,
  132696. 0
  132697. };
  132698. static long _vq_quantlist__44u2__p1_0[] = {
  132699. 1,
  132700. 0,
  132701. 2,
  132702. };
  132703. static long _vq_lengthlist__44u2__p1_0[] = {
  132704. 1, 4, 4, 5, 8, 7, 5, 7, 8, 5, 8, 8, 8,11,11, 8,
  132705. 10,11, 5, 8, 8, 8,11,10, 8,11,11, 4, 8, 8, 8,11,
  132706. 11, 8,11,11, 8,11,11,11,13,14,11,13,13, 7,11,11,
  132707. 10,13,12,11,14,14, 4, 8, 8, 8,11,11, 8,11,11, 8,
  132708. 11,11,11,14,13,10,12,13, 8,11,11,11,13,13,11,13,
  132709. 13,
  132710. };
  132711. static float _vq_quantthresh__44u2__p1_0[] = {
  132712. -0.5, 0.5,
  132713. };
  132714. static long _vq_quantmap__44u2__p1_0[] = {
  132715. 1, 0, 2,
  132716. };
  132717. static encode_aux_threshmatch _vq_auxt__44u2__p1_0 = {
  132718. _vq_quantthresh__44u2__p1_0,
  132719. _vq_quantmap__44u2__p1_0,
  132720. 3,
  132721. 3
  132722. };
  132723. static static_codebook _44u2__p1_0 = {
  132724. 4, 81,
  132725. _vq_lengthlist__44u2__p1_0,
  132726. 1, -535822336, 1611661312, 2, 0,
  132727. _vq_quantlist__44u2__p1_0,
  132728. NULL,
  132729. &_vq_auxt__44u2__p1_0,
  132730. NULL,
  132731. 0
  132732. };
  132733. static long _vq_quantlist__44u2__p2_0[] = {
  132734. 1,
  132735. 0,
  132736. 2,
  132737. };
  132738. static long _vq_lengthlist__44u2__p2_0[] = {
  132739. 2, 5, 5, 5, 6, 6, 5, 6, 6, 5, 6, 6, 7, 8, 8, 6,
  132740. 8, 8, 5, 6, 6, 6, 8, 7, 7, 8, 8, 5, 6, 6, 7, 8,
  132741. 8, 6, 8, 8, 6, 8, 8, 8, 9,10, 8,10,10, 6, 8, 8,
  132742. 7,10, 8, 8,10,10, 5, 6, 6, 6, 8, 8, 7, 8, 8, 6,
  132743. 8, 8, 8,10,10, 8, 8,10, 6, 8, 8, 8,10,10, 8,10,
  132744. 9,
  132745. };
  132746. static float _vq_quantthresh__44u2__p2_0[] = {
  132747. -0.5, 0.5,
  132748. };
  132749. static long _vq_quantmap__44u2__p2_0[] = {
  132750. 1, 0, 2,
  132751. };
  132752. static encode_aux_threshmatch _vq_auxt__44u2__p2_0 = {
  132753. _vq_quantthresh__44u2__p2_0,
  132754. _vq_quantmap__44u2__p2_0,
  132755. 3,
  132756. 3
  132757. };
  132758. static static_codebook _44u2__p2_0 = {
  132759. 4, 81,
  132760. _vq_lengthlist__44u2__p2_0,
  132761. 1, -535822336, 1611661312, 2, 0,
  132762. _vq_quantlist__44u2__p2_0,
  132763. NULL,
  132764. &_vq_auxt__44u2__p2_0,
  132765. NULL,
  132766. 0
  132767. };
  132768. static long _vq_quantlist__44u2__p3_0[] = {
  132769. 2,
  132770. 1,
  132771. 3,
  132772. 0,
  132773. 4,
  132774. };
  132775. static long _vq_lengthlist__44u2__p3_0[] = {
  132776. 2, 4, 4, 7, 8, 5, 7, 7, 9, 9, 5, 7, 7, 9, 9, 8,
  132777. 9, 9,12,11, 8, 9, 9,11,12, 5, 7, 7,10,10, 7, 9,
  132778. 9,11,11, 7, 9, 9,10,11,10,11,11,13,13, 9,10,11,
  132779. 12,13, 5, 7, 7,10,10, 7, 9, 9,11,10, 7, 9, 9,11,
  132780. 11, 9,11,10,13,13,10,11,11,13,13, 8,10,10,14,13,
  132781. 10,11,11,15,14, 9,11,11,15,14,13,14,13,16,14,12,
  132782. 13,13,15,16, 8,10,10,13,14, 9,11,11,14,15,10,11,
  132783. 11,14,15,12,13,13,15,15,12,13,14,15,16, 5, 7, 7,
  132784. 10,10, 7, 9, 9,11,11, 7, 9, 9,11,12,10,11,11,14,
  132785. 13,10,11,11,14,14, 7, 9, 9,12,12, 9,11,11,13,13,
  132786. 9,11,11,13,13,12,13,12,14,14,11,12,13,15,15, 7,
  132787. 9, 9,12,12, 8,11,10,13,12, 9,11,11,13,13,11,13,
  132788. 12,15,13,11,13,13,15,16, 9,12,11,15,15,11,12,12,
  132789. 16,15,11,12,13,16,16,13,14,15,16,15,13,15,15,17,
  132790. 17, 9,11,11,14,15,10,12,12,15,15,11,13,12,15,16,
  132791. 13,15,14,16,16,13,15,15,17,19, 5, 7, 7,10,10, 7,
  132792. 9, 9,12,11, 7, 9, 9,11,11,10,11,11,14,14,10,11,
  132793. 11,13,14, 7, 9, 9,12,12, 9,11,11,13,13, 9,10,11,
  132794. 12,13,11,13,12,16,15,11,12,12,14,15, 7, 9, 9,12,
  132795. 12, 9,11,11,13,13, 9,11,11,13,12,11,13,12,15,16,
  132796. 12,13,13,15,14, 9,11,11,15,14,11,13,12,16,15,10,
  132797. 11,12,15,15,13,14,14,18,17,13,14,14,15,17,10,11,
  132798. 11,14,15,11,13,12,15,17,11,13,12,15,16,13,15,14,
  132799. 18,17,14,15,15,16,18, 7,10,10,14,14,10,12,12,15,
  132800. 15,10,12,12,15,15,14,15,15,18,17,13,15,15,16,16,
  132801. 9,11,11,16,15,11,13,13,16,18,11,13,13,16,16,15,
  132802. 16,16, 0, 0,14,15,16,18,17, 9,11,11,15,15,10,13,
  132803. 12,17,16,11,12,13,16,17,14,15,16,19,19,14,15,15,
  132804. 0,20,12,14,14, 0, 0,13,14,16,19,18,13,15,16,20,
  132805. 17,16,18, 0, 0, 0,15,16,17,18,19,11,14,14, 0,19,
  132806. 12,15,14,17,17,13,15,15, 0, 0,16,17,15,20,19,15,
  132807. 17,16,19, 0, 8,10,10,14,15,10,12,11,15,15,10,11,
  132808. 12,16,15,13,14,14,19,17,14,15,15, 0, 0, 9,11,11,
  132809. 16,15,11,13,13,17,16,10,12,13,16,17,14,15,15,18,
  132810. 18,14,15,16,20,19, 9,12,12, 0,15,11,13,13,16,17,
  132811. 11,13,13,19,17,14,16,16,18,17,15,16,16,17,19,11,
  132812. 14,14,18,18,13,14,15, 0, 0,12,14,15,19,18,15,16,
  132813. 19, 0,19,15,16,19,19,17,12,14,14,16,19,13,15,15,
  132814. 0,17,13,15,14,18,18,15,16,15, 0,18,16,17,17, 0,
  132815. 0,
  132816. };
  132817. static float _vq_quantthresh__44u2__p3_0[] = {
  132818. -1.5, -0.5, 0.5, 1.5,
  132819. };
  132820. static long _vq_quantmap__44u2__p3_0[] = {
  132821. 3, 1, 0, 2, 4,
  132822. };
  132823. static encode_aux_threshmatch _vq_auxt__44u2__p3_0 = {
  132824. _vq_quantthresh__44u2__p3_0,
  132825. _vq_quantmap__44u2__p3_0,
  132826. 5,
  132827. 5
  132828. };
  132829. static static_codebook _44u2__p3_0 = {
  132830. 4, 625,
  132831. _vq_lengthlist__44u2__p3_0,
  132832. 1, -533725184, 1611661312, 3, 0,
  132833. _vq_quantlist__44u2__p3_0,
  132834. NULL,
  132835. &_vq_auxt__44u2__p3_0,
  132836. NULL,
  132837. 0
  132838. };
  132839. static long _vq_quantlist__44u2__p4_0[] = {
  132840. 2,
  132841. 1,
  132842. 3,
  132843. 0,
  132844. 4,
  132845. };
  132846. static long _vq_lengthlist__44u2__p4_0[] = {
  132847. 4, 5, 5, 8, 8, 5, 7, 6, 9, 9, 5, 6, 7, 9, 9, 9,
  132848. 9, 9,11,11, 9, 9, 9,11,11, 5, 7, 7, 9, 9, 7, 8,
  132849. 8,10,10, 7, 7, 8,10,10,10,10,10,11,12, 9,10,10,
  132850. 11,12, 5, 7, 7, 9, 9, 6, 8, 7,10,10, 7, 8, 8,10,
  132851. 10, 9,10,10,12,11, 9,10,10,12,11, 9,10,10,12,12,
  132852. 10,10,10,13,12, 9,10,10,12,13,12,12,12,14,14,11,
  132853. 12,12,13,14, 9,10,10,12,12, 9,10,10,12,13,10,10,
  132854. 10,12,13,11,12,12,14,13,12,12,12,14,13, 5, 7, 7,
  132855. 10, 9, 7, 8, 8,10,10, 7, 8, 8,10,10,10,10,10,12,
  132856. 12,10,10,10,12,12, 7, 8, 8,11,10, 8, 8, 9,11,11,
  132857. 8, 9, 9,11,11,10,11,11,12,13,10,11,11,13,13, 6,
  132858. 8, 8,10,10, 7, 9, 8,11,10, 8, 9, 9,11,11,10,11,
  132859. 10,13,11,10,11,11,13,13, 9,10,10,13,13,10,11,11,
  132860. 13,13,10,11,11,14,13,12,11,13,12,15,12,13,13,15,
  132861. 15, 9,10,10,12,13,10,11,10,13,13,10,11,11,13,13,
  132862. 12,13,11,15,13,12,13,13,15,15, 5, 7, 7, 9,10, 7,
  132863. 8, 8,10,10, 7, 8, 8,10,10,10,10,10,12,12,10,10,
  132864. 11,12,12, 6, 8, 8,10,10, 8, 9, 9,11,11, 7, 8, 9,
  132865. 10,11,10,11,11,13,13,10,10,11,11,13, 7, 8, 8,10,
  132866. 11, 8, 9, 9,11,11, 8, 9, 8,11,11,10,11,11,13,13,
  132867. 10,11,11,13,12, 9,10,10,13,12,10,11,11,14,13,10,
  132868. 10,11,13,13,12,13,13,15,15,12,11,13,12,14, 9,10,
  132869. 10,12,13,10,11,11,13,14,10,11,11,13,13,12,13,13,
  132870. 15,15,12,13,12,15,12, 8, 9, 9,12,12, 9,11,10,13,
  132871. 13, 9,10,10,13,13,12,13,13,15,15,12,12,12,14,14,
  132872. 9,10,10,13,13,10,11,11,13,14,10,11,11,14,12,13,
  132873. 13,14,14,16,12,13,13,15,14, 9,10,10,13,13,10,11,
  132874. 10,14,13,10,11,11,13,14,12,14,13,16,14,13,13,13,
  132875. 14,15,11,13,12,15,14,11,12,13,14,15,12,13,13,16,
  132876. 15,14,12,15,12,16,14,15,15,17,16,11,12,12,14,15,
  132877. 11,13,11,15,14,12,13,13,15,16,13,15,12,17,13,14,
  132878. 15,15,16,16, 8, 9, 9,12,12, 9,10,10,13,13, 9,10,
  132879. 10,13,13,12,13,12,14,14,12,13,13,15,15, 9,10,10,
  132880. 13,13,10,11,11,14,13,10,10,11,13,14,12,13,13,15,
  132881. 14,12,12,14,14,16, 9,10,10,13,13,10,11,11,13,14,
  132882. 10,11,11,14,13,13,13,13,15,15,13,14,13,16,14,11,
  132883. 12,12,14,14,12,13,13,16,15,11,12,13,14,15,14,15,
  132884. 15,16,16,14,13,15,13,17,11,12,12,14,15,12,13,13,
  132885. 15,16,11,13,12,15,15,14,15,14,16,16,14,15,12,17,
  132886. 13,
  132887. };
  132888. static float _vq_quantthresh__44u2__p4_0[] = {
  132889. -1.5, -0.5, 0.5, 1.5,
  132890. };
  132891. static long _vq_quantmap__44u2__p4_0[] = {
  132892. 3, 1, 0, 2, 4,
  132893. };
  132894. static encode_aux_threshmatch _vq_auxt__44u2__p4_0 = {
  132895. _vq_quantthresh__44u2__p4_0,
  132896. _vq_quantmap__44u2__p4_0,
  132897. 5,
  132898. 5
  132899. };
  132900. static static_codebook _44u2__p4_0 = {
  132901. 4, 625,
  132902. _vq_lengthlist__44u2__p4_0,
  132903. 1, -533725184, 1611661312, 3, 0,
  132904. _vq_quantlist__44u2__p4_0,
  132905. NULL,
  132906. &_vq_auxt__44u2__p4_0,
  132907. NULL,
  132908. 0
  132909. };
  132910. static long _vq_quantlist__44u2__p5_0[] = {
  132911. 4,
  132912. 3,
  132913. 5,
  132914. 2,
  132915. 6,
  132916. 1,
  132917. 7,
  132918. 0,
  132919. 8,
  132920. };
  132921. static long _vq_lengthlist__44u2__p5_0[] = {
  132922. 1, 4, 4, 7, 7, 8, 8, 9, 9, 4, 6, 5, 8, 8, 8, 8,
  132923. 10,10, 4, 5, 6, 8, 8, 8, 8,10,10, 7, 8, 8, 9, 9,
  132924. 9, 9,11,11, 7, 8, 8, 9, 9, 9, 9,11,11, 8, 8, 8,
  132925. 9, 9,10,11,12,12, 8, 8, 8, 9, 9,10,10,12,12,10,
  132926. 10,10,11,11,12,12,13,13,10,10,10,11,11,12,12,13,
  132927. 13,
  132928. };
  132929. static float _vq_quantthresh__44u2__p5_0[] = {
  132930. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  132931. };
  132932. static long _vq_quantmap__44u2__p5_0[] = {
  132933. 7, 5, 3, 1, 0, 2, 4, 6,
  132934. 8,
  132935. };
  132936. static encode_aux_threshmatch _vq_auxt__44u2__p5_0 = {
  132937. _vq_quantthresh__44u2__p5_0,
  132938. _vq_quantmap__44u2__p5_0,
  132939. 9,
  132940. 9
  132941. };
  132942. static static_codebook _44u2__p5_0 = {
  132943. 2, 81,
  132944. _vq_lengthlist__44u2__p5_0,
  132945. 1, -531628032, 1611661312, 4, 0,
  132946. _vq_quantlist__44u2__p5_0,
  132947. NULL,
  132948. &_vq_auxt__44u2__p5_0,
  132949. NULL,
  132950. 0
  132951. };
  132952. static long _vq_quantlist__44u2__p6_0[] = {
  132953. 6,
  132954. 5,
  132955. 7,
  132956. 4,
  132957. 8,
  132958. 3,
  132959. 9,
  132960. 2,
  132961. 10,
  132962. 1,
  132963. 11,
  132964. 0,
  132965. 12,
  132966. };
  132967. static long _vq_lengthlist__44u2__p6_0[] = {
  132968. 1, 4, 4, 6, 6, 8, 8,10,10,11,11,14,13, 4, 6, 5,
  132969. 8, 8, 9, 9,11,10,12,11,15,14, 4, 5, 6, 8, 8, 9,
  132970. 9,11,11,11,11,14,14, 6, 8, 8,10, 9,11,11,11,11,
  132971. 12,12,15,15, 6, 8, 8, 9, 9,11,11,11,12,12,12,15,
  132972. 15, 8,10,10,11,11,11,11,12,12,13,13,15,16, 8,10,
  132973. 10,11,11,11,11,12,12,13,13,16,16,10,11,11,12,12,
  132974. 12,12,13,13,13,13,17,16,10,11,11,12,12,12,12,13,
  132975. 13,13,14,16,17,11,12,12,13,13,13,13,14,14,15,14,
  132976. 18,17,11,12,12,13,13,13,13,14,14,14,15,19,18,14,
  132977. 15,15,15,15,16,16,18,19,18,18, 0, 0,14,15,15,16,
  132978. 15,17,17,16,18,17,18, 0, 0,
  132979. };
  132980. static float _vq_quantthresh__44u2__p6_0[] = {
  132981. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  132982. 12.5, 17.5, 22.5, 27.5,
  132983. };
  132984. static long _vq_quantmap__44u2__p6_0[] = {
  132985. 11, 9, 7, 5, 3, 1, 0, 2,
  132986. 4, 6, 8, 10, 12,
  132987. };
  132988. static encode_aux_threshmatch _vq_auxt__44u2__p6_0 = {
  132989. _vq_quantthresh__44u2__p6_0,
  132990. _vq_quantmap__44u2__p6_0,
  132991. 13,
  132992. 13
  132993. };
  132994. static static_codebook _44u2__p6_0 = {
  132995. 2, 169,
  132996. _vq_lengthlist__44u2__p6_0,
  132997. 1, -526516224, 1616117760, 4, 0,
  132998. _vq_quantlist__44u2__p6_0,
  132999. NULL,
  133000. &_vq_auxt__44u2__p6_0,
  133001. NULL,
  133002. 0
  133003. };
  133004. static long _vq_quantlist__44u2__p6_1[] = {
  133005. 2,
  133006. 1,
  133007. 3,
  133008. 0,
  133009. 4,
  133010. };
  133011. static long _vq_lengthlist__44u2__p6_1[] = {
  133012. 2, 4, 4, 5, 5, 4, 5, 5, 6, 5, 4, 5, 5, 5, 6, 5,
  133013. 6, 5, 6, 6, 5, 5, 6, 6, 6,
  133014. };
  133015. static float _vq_quantthresh__44u2__p6_1[] = {
  133016. -1.5, -0.5, 0.5, 1.5,
  133017. };
  133018. static long _vq_quantmap__44u2__p6_1[] = {
  133019. 3, 1, 0, 2, 4,
  133020. };
  133021. static encode_aux_threshmatch _vq_auxt__44u2__p6_1 = {
  133022. _vq_quantthresh__44u2__p6_1,
  133023. _vq_quantmap__44u2__p6_1,
  133024. 5,
  133025. 5
  133026. };
  133027. static static_codebook _44u2__p6_1 = {
  133028. 2, 25,
  133029. _vq_lengthlist__44u2__p6_1,
  133030. 1, -533725184, 1611661312, 3, 0,
  133031. _vq_quantlist__44u2__p6_1,
  133032. NULL,
  133033. &_vq_auxt__44u2__p6_1,
  133034. NULL,
  133035. 0
  133036. };
  133037. static long _vq_quantlist__44u2__p7_0[] = {
  133038. 4,
  133039. 3,
  133040. 5,
  133041. 2,
  133042. 6,
  133043. 1,
  133044. 7,
  133045. 0,
  133046. 8,
  133047. };
  133048. static long _vq_lengthlist__44u2__p7_0[] = {
  133049. 1, 3, 2,12,12,12,12,12,12, 4,12,12,12,12,12,12,
  133050. 12,12, 5,12,12,12,12,12,12,12,12,12,12,11,11,11,
  133051. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  133052. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  133053. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  133054. 11,
  133055. };
  133056. static float _vq_quantthresh__44u2__p7_0[] = {
  133057. -591.5, -422.5, -253.5, -84.5, 84.5, 253.5, 422.5, 591.5,
  133058. };
  133059. static long _vq_quantmap__44u2__p7_0[] = {
  133060. 7, 5, 3, 1, 0, 2, 4, 6,
  133061. 8,
  133062. };
  133063. static encode_aux_threshmatch _vq_auxt__44u2__p7_0 = {
  133064. _vq_quantthresh__44u2__p7_0,
  133065. _vq_quantmap__44u2__p7_0,
  133066. 9,
  133067. 9
  133068. };
  133069. static static_codebook _44u2__p7_0 = {
  133070. 2, 81,
  133071. _vq_lengthlist__44u2__p7_0,
  133072. 1, -516612096, 1626677248, 4, 0,
  133073. _vq_quantlist__44u2__p7_0,
  133074. NULL,
  133075. &_vq_auxt__44u2__p7_0,
  133076. NULL,
  133077. 0
  133078. };
  133079. static long _vq_quantlist__44u2__p7_1[] = {
  133080. 6,
  133081. 5,
  133082. 7,
  133083. 4,
  133084. 8,
  133085. 3,
  133086. 9,
  133087. 2,
  133088. 10,
  133089. 1,
  133090. 11,
  133091. 0,
  133092. 12,
  133093. };
  133094. static long _vq_lengthlist__44u2__p7_1[] = {
  133095. 1, 4, 4, 7, 6, 7, 6, 8, 7, 9, 7, 9, 8, 4, 7, 6,
  133096. 8, 8, 9, 8,10, 9,10,10,11,11, 4, 7, 7, 8, 8, 8,
  133097. 8, 9,10,11,11,11,11, 6, 8, 8,10,10,10,10,11,11,
  133098. 12,12,12,12, 7, 8, 8,10,10,10,10,11,11,12,12,13,
  133099. 13, 7, 9, 9,11,10,12,12,13,13,14,13,14,14, 7, 9,
  133100. 9,10,11,11,12,13,13,13,13,16,14, 9,10,10,12,12,
  133101. 13,13,14,14,15,16,15,16, 9,10,10,12,12,12,13,14,
  133102. 14,14,15,16,15,10,12,12,13,13,15,13,16,16,15,17,
  133103. 17,17,10,11,11,12,14,14,14,15,15,17,17,15,17,11,
  133104. 12,12,14,14,14,15,15,15,17,16,17,17,10,12,12,13,
  133105. 14,14,14,17,15,17,17,17,17,
  133106. };
  133107. static float _vq_quantthresh__44u2__p7_1[] = {
  133108. -71.5, -58.5, -45.5, -32.5, -19.5, -6.5, 6.5, 19.5,
  133109. 32.5, 45.5, 58.5, 71.5,
  133110. };
  133111. static long _vq_quantmap__44u2__p7_1[] = {
  133112. 11, 9, 7, 5, 3, 1, 0, 2,
  133113. 4, 6, 8, 10, 12,
  133114. };
  133115. static encode_aux_threshmatch _vq_auxt__44u2__p7_1 = {
  133116. _vq_quantthresh__44u2__p7_1,
  133117. _vq_quantmap__44u2__p7_1,
  133118. 13,
  133119. 13
  133120. };
  133121. static static_codebook _44u2__p7_1 = {
  133122. 2, 169,
  133123. _vq_lengthlist__44u2__p7_1,
  133124. 1, -523010048, 1618608128, 4, 0,
  133125. _vq_quantlist__44u2__p7_1,
  133126. NULL,
  133127. &_vq_auxt__44u2__p7_1,
  133128. NULL,
  133129. 0
  133130. };
  133131. static long _vq_quantlist__44u2__p7_2[] = {
  133132. 6,
  133133. 5,
  133134. 7,
  133135. 4,
  133136. 8,
  133137. 3,
  133138. 9,
  133139. 2,
  133140. 10,
  133141. 1,
  133142. 11,
  133143. 0,
  133144. 12,
  133145. };
  133146. static long _vq_lengthlist__44u2__p7_2[] = {
  133147. 2, 5, 5, 6, 6, 7, 7, 8, 7, 8, 8, 8, 8, 5, 6, 6,
  133148. 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 5, 6, 6, 7, 7, 8,
  133149. 7, 8, 8, 8, 8, 8, 8, 6, 7, 7, 7, 8, 8, 8, 8, 8,
  133150. 9, 9, 9, 9, 6, 7, 7, 8, 7, 8, 8, 9, 9, 9, 9, 9,
  133151. 9, 7, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 7, 8,
  133152. 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 8, 8, 8, 8, 9,
  133153. 9, 9, 9, 9, 9, 9, 9, 9, 8, 8, 8, 9, 9, 9, 9, 9,
  133154. 9, 9, 9, 9, 9, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  133155. 9, 9, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 8,
  133156. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 8, 9, 9, 9,
  133157. 9, 9, 9, 9, 9, 9, 9, 9, 9,
  133158. };
  133159. static float _vq_quantthresh__44u2__p7_2[] = {
  133160. -5.5, -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5,
  133161. 2.5, 3.5, 4.5, 5.5,
  133162. };
  133163. static long _vq_quantmap__44u2__p7_2[] = {
  133164. 11, 9, 7, 5, 3, 1, 0, 2,
  133165. 4, 6, 8, 10, 12,
  133166. };
  133167. static encode_aux_threshmatch _vq_auxt__44u2__p7_2 = {
  133168. _vq_quantthresh__44u2__p7_2,
  133169. _vq_quantmap__44u2__p7_2,
  133170. 13,
  133171. 13
  133172. };
  133173. static static_codebook _44u2__p7_2 = {
  133174. 2, 169,
  133175. _vq_lengthlist__44u2__p7_2,
  133176. 1, -531103744, 1611661312, 4, 0,
  133177. _vq_quantlist__44u2__p7_2,
  133178. NULL,
  133179. &_vq_auxt__44u2__p7_2,
  133180. NULL,
  133181. 0
  133182. };
  133183. static long _huff_lengthlist__44u2__short[] = {
  133184. 13,15,17,17,15,15,12,17,11, 9, 7,10,10, 9,12,17,
  133185. 10, 6, 3, 6, 5, 7,10,17,15,10, 6, 9, 8, 9,11,17,
  133186. 15, 8, 4, 7, 3, 5, 9,16,16,10, 5, 8, 4, 5, 8,16,
  133187. 13,11, 5, 8, 3, 3, 5,14,13,12, 7,10, 5, 5, 7,14,
  133188. };
  133189. static static_codebook _huff_book__44u2__short = {
  133190. 2, 64,
  133191. _huff_lengthlist__44u2__short,
  133192. 0, 0, 0, 0, 0,
  133193. NULL,
  133194. NULL,
  133195. NULL,
  133196. NULL,
  133197. 0
  133198. };
  133199. static long _huff_lengthlist__44u3__long[] = {
  133200. 6, 9,13,12,14,11,10,13, 8, 4, 5, 7, 8, 7, 8,12,
  133201. 11, 4, 3, 5, 5, 7, 9,14,11, 6, 5, 6, 6, 6, 7,13,
  133202. 13, 7, 5, 6, 4, 5, 7,14,11, 7, 6, 6, 5, 5, 6,13,
  133203. 9, 7, 8, 6, 7, 5, 3, 9, 9,12,13,12,14,10, 6, 7,
  133204. };
  133205. static static_codebook _huff_book__44u3__long = {
  133206. 2, 64,
  133207. _huff_lengthlist__44u3__long,
  133208. 0, 0, 0, 0, 0,
  133209. NULL,
  133210. NULL,
  133211. NULL,
  133212. NULL,
  133213. 0
  133214. };
  133215. static long _vq_quantlist__44u3__p1_0[] = {
  133216. 1,
  133217. 0,
  133218. 2,
  133219. };
  133220. static long _vq_lengthlist__44u3__p1_0[] = {
  133221. 1, 4, 4, 5, 8, 7, 5, 7, 8, 5, 8, 8, 8,10,11, 8,
  133222. 10,11, 5, 8, 8, 8,11,10, 8,11,11, 4, 8, 8, 8,11,
  133223. 11, 8,11,11, 8,11,11,11,13,14,11,14,14, 8,11,11,
  133224. 10,14,12,11,14,14, 4, 8, 8, 8,11,11, 8,11,11, 7,
  133225. 11,11,11,14,14,10,12,14, 8,11,11,11,14,14,11,14,
  133226. 13,
  133227. };
  133228. static float _vq_quantthresh__44u3__p1_0[] = {
  133229. -0.5, 0.5,
  133230. };
  133231. static long _vq_quantmap__44u3__p1_0[] = {
  133232. 1, 0, 2,
  133233. };
  133234. static encode_aux_threshmatch _vq_auxt__44u3__p1_0 = {
  133235. _vq_quantthresh__44u3__p1_0,
  133236. _vq_quantmap__44u3__p1_0,
  133237. 3,
  133238. 3
  133239. };
  133240. static static_codebook _44u3__p1_0 = {
  133241. 4, 81,
  133242. _vq_lengthlist__44u3__p1_0,
  133243. 1, -535822336, 1611661312, 2, 0,
  133244. _vq_quantlist__44u3__p1_0,
  133245. NULL,
  133246. &_vq_auxt__44u3__p1_0,
  133247. NULL,
  133248. 0
  133249. };
  133250. static long _vq_quantlist__44u3__p2_0[] = {
  133251. 1,
  133252. 0,
  133253. 2,
  133254. };
  133255. static long _vq_lengthlist__44u3__p2_0[] = {
  133256. 2, 5, 4, 5, 6, 6, 5, 6, 6, 5, 6, 6, 7, 8, 8, 6,
  133257. 8, 8, 5, 6, 6, 6, 8, 8, 7, 8, 8, 5, 7, 6, 7, 8,
  133258. 8, 6, 8, 8, 7, 8, 8, 8, 9,10, 8,10,10, 6, 8, 8,
  133259. 8,10, 8, 8,10,10, 5, 6, 6, 6, 8, 8, 7, 8, 8, 6,
  133260. 8, 8, 8,10,10, 8, 8,10, 7, 8, 8, 8,10,10, 8,10,
  133261. 9,
  133262. };
  133263. static float _vq_quantthresh__44u3__p2_0[] = {
  133264. -0.5, 0.5,
  133265. };
  133266. static long _vq_quantmap__44u3__p2_0[] = {
  133267. 1, 0, 2,
  133268. };
  133269. static encode_aux_threshmatch _vq_auxt__44u3__p2_0 = {
  133270. _vq_quantthresh__44u3__p2_0,
  133271. _vq_quantmap__44u3__p2_0,
  133272. 3,
  133273. 3
  133274. };
  133275. static static_codebook _44u3__p2_0 = {
  133276. 4, 81,
  133277. _vq_lengthlist__44u3__p2_0,
  133278. 1, -535822336, 1611661312, 2, 0,
  133279. _vq_quantlist__44u3__p2_0,
  133280. NULL,
  133281. &_vq_auxt__44u3__p2_0,
  133282. NULL,
  133283. 0
  133284. };
  133285. static long _vq_quantlist__44u3__p3_0[] = {
  133286. 2,
  133287. 1,
  133288. 3,
  133289. 0,
  133290. 4,
  133291. };
  133292. static long _vq_lengthlist__44u3__p3_0[] = {
  133293. 2, 4, 4, 7, 7, 5, 7, 7, 9, 9, 5, 7, 7, 9, 9, 8,
  133294. 9, 9,12,12, 8, 9, 9,11,12, 5, 7, 7,10,10, 7, 9,
  133295. 9,11,11, 7, 9, 9,10,11,10,11,11,13,13, 9,10,11,
  133296. 13,13, 5, 7, 7,10,10, 7, 9, 9,11,10, 7, 9, 9,11,
  133297. 11, 9,11,10,13,13,10,11,11,14,13, 8,10,10,14,13,
  133298. 10,11,11,15,14, 9,11,11,14,14,13,14,13,16,16,12,
  133299. 13,13,15,15, 8,10,10,13,14, 9,11,11,14,14,10,11,
  133300. 11,14,15,12,13,13,15,15,13,14,14,15,16, 5, 7, 7,
  133301. 10,10, 7, 9, 9,11,11, 7, 9, 9,11,12,10,11,11,14,
  133302. 14,10,11,11,14,14, 7, 9, 9,12,12, 9,11,11,13,13,
  133303. 9,11,11,13,13,12,12,13,15,15,11,12,13,15,16, 7,
  133304. 9, 9,11,11, 8,11,10,13,12, 9,11,11,13,13,11,13,
  133305. 12,15,13,11,13,13,15,16, 9,12,11,15,14,11,12,13,
  133306. 16,15,11,13,13,15,16,14,14,15,17,16,13,15,16, 0,
  133307. 17, 9,11,11,15,15,10,13,12,15,15,11,13,13,15,16,
  133308. 13,15,13,16,15,14,16,15, 0,19, 5, 7, 7,10,10, 7,
  133309. 9, 9,11,11, 7, 9, 9,11,11,10,12,11,14,14,10,11,
  133310. 12,14,14, 7, 9, 9,12,12, 9,11,11,14,13, 9,10,11,
  133311. 12,13,11,13,13,16,16,11,12,13,13,16, 7, 9, 9,12,
  133312. 12, 9,11,11,13,13, 9,11,11,13,13,11,13,13,15,15,
  133313. 12,13,12,15,14, 9,11,11,15,14,11,13,12,16,16,10,
  133314. 12,12,15,15,13,15,15,17,19,13,14,15,16,17,10,12,
  133315. 12,15,15,11,13,13,16,16,11,13,13,15,16,13,15,15,
  133316. 0, 0,14,15,15,16,16, 8,10,10,14,14,10,12,12,15,
  133317. 15,10,12,11,15,16,14,15,15,19,20,13,14,14,18,16,
  133318. 9,11,11,15,15,11,13,13,17,16,11,13,13,16,16,15,
  133319. 17,17,20,20,14,15,16,17,20, 9,11,11,15,15,10,13,
  133320. 12,16,15,11,13,13,15,17,14,16,15,18, 0,14,16,15,
  133321. 18,20,12,14,14, 0, 0,14,14,16, 0, 0,13,16,15, 0,
  133322. 0,17,17,18, 0, 0,16,17,19,19, 0,12,14,14,18, 0,
  133323. 12,16,14, 0,17,13,15,15,18, 0,16,18,17, 0,17,16,
  133324. 18,17, 0, 0, 7,10,10,14,14,10,12,11,15,15,10,12,
  133325. 12,16,15,13,15,15,18, 0,14,15,15,17, 0, 9,11,11,
  133326. 15,15,11,13,13,16,16,11,12,13,16,16,14,15,16,17,
  133327. 17,14,16,16,16,18, 9,11,12,16,16,11,13,13,17,17,
  133328. 11,14,13,20,17,15,16,16,19, 0,15,16,17, 0,19,11,
  133329. 13,14,17,16,14,15,15,20,18,13,14,15,17,19,16,18,
  133330. 18, 0,20,16,16,19,17, 0,12,15,14,17, 0,14,15,15,
  133331. 18,19,13,16,15,19,20,15,18,18, 0,20,17, 0,16, 0,
  133332. 0,
  133333. };
  133334. static float _vq_quantthresh__44u3__p3_0[] = {
  133335. -1.5, -0.5, 0.5, 1.5,
  133336. };
  133337. static long _vq_quantmap__44u3__p3_0[] = {
  133338. 3, 1, 0, 2, 4,
  133339. };
  133340. static encode_aux_threshmatch _vq_auxt__44u3__p3_0 = {
  133341. _vq_quantthresh__44u3__p3_0,
  133342. _vq_quantmap__44u3__p3_0,
  133343. 5,
  133344. 5
  133345. };
  133346. static static_codebook _44u3__p3_0 = {
  133347. 4, 625,
  133348. _vq_lengthlist__44u3__p3_0,
  133349. 1, -533725184, 1611661312, 3, 0,
  133350. _vq_quantlist__44u3__p3_0,
  133351. NULL,
  133352. &_vq_auxt__44u3__p3_0,
  133353. NULL,
  133354. 0
  133355. };
  133356. static long _vq_quantlist__44u3__p4_0[] = {
  133357. 2,
  133358. 1,
  133359. 3,
  133360. 0,
  133361. 4,
  133362. };
  133363. static long _vq_lengthlist__44u3__p4_0[] = {
  133364. 4, 5, 5, 8, 8, 5, 7, 6, 9, 9, 5, 6, 7, 9, 9, 9,
  133365. 9, 9,11,11, 9, 9, 9,11,11, 5, 7, 7, 9, 9, 7, 8,
  133366. 8,10,10, 7, 7, 8,10,10, 9,10,10,11,12, 9,10,10,
  133367. 11,12, 5, 7, 7, 9, 9, 7, 8, 7,10,10, 7, 8, 8,10,
  133368. 10, 9,10, 9,12,11, 9,10,10,12,11, 9,10, 9,12,12,
  133369. 9,10,10,13,12, 9,10,10,12,13,12,12,12,14,14,11,
  133370. 12,12,13,14, 9, 9,10,12,12, 9,10,10,12,12, 9,10,
  133371. 10,12,13,11,12,11,14,13,12,12,12,14,13, 5, 7, 7,
  133372. 9, 9, 7, 8, 8,10,10, 7, 8, 8,10,10,10,10,10,12,
  133373. 12, 9,10,10,12,12, 7, 8, 8,11,10, 8, 8, 9,11,11,
  133374. 8, 9, 9,11,11,11,11,11,12,13,10,11,11,13,13, 6,
  133375. 8, 8,10,10, 7, 9, 8,11,10, 8, 9, 9,11,11,10,11,
  133376. 10,13,11,10,11,11,13,13, 9,11,10,13,12,10,11,11,
  133377. 13,13,10,11,11,13,13,12,12,13,12,15,12,13,13,15,
  133378. 15, 9,10,10,12,13,10,11,10,13,12,10,11,11,13,14,
  133379. 12,13,11,15,13,12,13,13,15,15, 5, 7, 7, 9, 9, 7,
  133380. 8, 8,10,10, 7, 8, 8,10,10, 9,10,10,12,12,10,10,
  133381. 11,12,12, 6, 8, 8,10,10, 8, 9, 9,11,11, 7, 8, 9,
  133382. 10,11,10,11,11,13,13,10,10,11,11,13, 7, 8, 8,10,
  133383. 10, 8, 9, 9,11,11, 8, 9, 9,11,11,10,11,11,13,13,
  133384. 11,11,11,13,12, 9,10,10,13,12,10,11,11,14,13,10,
  133385. 10,11,12,13,12,13,13,15,15,12,11,13,13,14, 9,10,
  133386. 11,12,13,10,11,11,13,13,10,11,11,13,13,12,13,13,
  133387. 15,15,12,13,12,15,12, 8, 9, 9,12,12, 9,11,10,13,
  133388. 13, 9,10,10,13,13,12,13,13,15,14,12,12,12,14,13,
  133389. 9,10,10,13,12,10,11,11,13,13,10,11,11,14,12,13,
  133390. 13,14,14,16,12,13,13,15,15, 9,10,10,13,13,10,11,
  133391. 10,14,13,10,11,11,13,14,12,14,13,15,14,13,13,13,
  133392. 15,15,11,13,12,15,14,11,12,13,14,15,12,13,13,16,
  133393. 14,14,12,15,12,16,14,15,15,17,15,11,12,12,14,14,
  133394. 11,13,11,15,14,12,13,13,15,15,13,15,12,17,13,14,
  133395. 15,15,16,16, 8, 9, 9,12,12, 9,10,10,12,13, 9,10,
  133396. 10,13,13,12,12,12,14,14,12,13,13,15,15, 9,10,10,
  133397. 13,12,10,11,11,14,13,10,10,11,13,14,12,13,13,15,
  133398. 15,12,12,13,14,16, 9,10,10,13,13,10,11,11,13,14,
  133399. 10,11,11,14,13,12,13,13,14,15,13,14,13,16,14,11,
  133400. 12,12,14,14,12,13,13,15,14,11,12,13,14,15,14,15,
  133401. 15,16,16,13,13,15,13,16,11,12,12,14,15,12,13,13,
  133402. 14,15,11,13,12,15,14,14,15,15,16,16,14,15,12,16,
  133403. 13,
  133404. };
  133405. static float _vq_quantthresh__44u3__p4_0[] = {
  133406. -1.5, -0.5, 0.5, 1.5,
  133407. };
  133408. static long _vq_quantmap__44u3__p4_0[] = {
  133409. 3, 1, 0, 2, 4,
  133410. };
  133411. static encode_aux_threshmatch _vq_auxt__44u3__p4_0 = {
  133412. _vq_quantthresh__44u3__p4_0,
  133413. _vq_quantmap__44u3__p4_0,
  133414. 5,
  133415. 5
  133416. };
  133417. static static_codebook _44u3__p4_0 = {
  133418. 4, 625,
  133419. _vq_lengthlist__44u3__p4_0,
  133420. 1, -533725184, 1611661312, 3, 0,
  133421. _vq_quantlist__44u3__p4_0,
  133422. NULL,
  133423. &_vq_auxt__44u3__p4_0,
  133424. NULL,
  133425. 0
  133426. };
  133427. static long _vq_quantlist__44u3__p5_0[] = {
  133428. 4,
  133429. 3,
  133430. 5,
  133431. 2,
  133432. 6,
  133433. 1,
  133434. 7,
  133435. 0,
  133436. 8,
  133437. };
  133438. static long _vq_lengthlist__44u3__p5_0[] = {
  133439. 2, 3, 3, 6, 6, 7, 7, 9, 9, 4, 5, 5, 7, 7, 8, 8,
  133440. 10,10, 4, 5, 5, 7, 7, 8, 8,10,10, 6, 7, 7, 8, 8,
  133441. 9, 9,11,10, 6, 7, 7, 8, 8, 9, 9,10,10, 7, 8, 8,
  133442. 9, 9,10,10,11,11, 7, 8, 8, 9, 9,10,10,11,11, 9,
  133443. 10,10,11,10,11,11,12,12, 9,10,10,10,10,11,11,12,
  133444. 12,
  133445. };
  133446. static float _vq_quantthresh__44u3__p5_0[] = {
  133447. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  133448. };
  133449. static long _vq_quantmap__44u3__p5_0[] = {
  133450. 7, 5, 3, 1, 0, 2, 4, 6,
  133451. 8,
  133452. };
  133453. static encode_aux_threshmatch _vq_auxt__44u3__p5_0 = {
  133454. _vq_quantthresh__44u3__p5_0,
  133455. _vq_quantmap__44u3__p5_0,
  133456. 9,
  133457. 9
  133458. };
  133459. static static_codebook _44u3__p5_0 = {
  133460. 2, 81,
  133461. _vq_lengthlist__44u3__p5_0,
  133462. 1, -531628032, 1611661312, 4, 0,
  133463. _vq_quantlist__44u3__p5_0,
  133464. NULL,
  133465. &_vq_auxt__44u3__p5_0,
  133466. NULL,
  133467. 0
  133468. };
  133469. static long _vq_quantlist__44u3__p6_0[] = {
  133470. 6,
  133471. 5,
  133472. 7,
  133473. 4,
  133474. 8,
  133475. 3,
  133476. 9,
  133477. 2,
  133478. 10,
  133479. 1,
  133480. 11,
  133481. 0,
  133482. 12,
  133483. };
  133484. static long _vq_lengthlist__44u3__p6_0[] = {
  133485. 1, 4, 4, 6, 6, 8, 8, 9, 9,10,11,13,14, 4, 6, 5,
  133486. 8, 8, 9, 9,10,10,11,11,14,14, 4, 6, 6, 8, 8, 9,
  133487. 9,10,10,11,11,14,14, 6, 8, 8, 9, 9,10,10,11,11,
  133488. 12,12,15,15, 6, 8, 8, 9, 9,10,11,11,11,12,12,15,
  133489. 15, 8, 9, 9,11,10,11,11,12,12,13,13,15,16, 8, 9,
  133490. 9,10,11,11,11,12,12,13,13,16,16,10,10,11,11,11,
  133491. 12,12,13,13,13,14,17,16, 9,10,11,12,11,12,12,13,
  133492. 13,13,13,16,18,11,12,11,12,12,13,13,13,14,15,14,
  133493. 17,17,11,11,12,12,12,13,13,13,14,14,15,18,17,14,
  133494. 15,15,15,15,16,16,17,17,19,18, 0,20,14,15,14,15,
  133495. 15,16,16,16,17,18,16,20,18,
  133496. };
  133497. static float _vq_quantthresh__44u3__p6_0[] = {
  133498. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  133499. 12.5, 17.5, 22.5, 27.5,
  133500. };
  133501. static long _vq_quantmap__44u3__p6_0[] = {
  133502. 11, 9, 7, 5, 3, 1, 0, 2,
  133503. 4, 6, 8, 10, 12,
  133504. };
  133505. static encode_aux_threshmatch _vq_auxt__44u3__p6_0 = {
  133506. _vq_quantthresh__44u3__p6_0,
  133507. _vq_quantmap__44u3__p6_0,
  133508. 13,
  133509. 13
  133510. };
  133511. static static_codebook _44u3__p6_0 = {
  133512. 2, 169,
  133513. _vq_lengthlist__44u3__p6_0,
  133514. 1, -526516224, 1616117760, 4, 0,
  133515. _vq_quantlist__44u3__p6_0,
  133516. NULL,
  133517. &_vq_auxt__44u3__p6_0,
  133518. NULL,
  133519. 0
  133520. };
  133521. static long _vq_quantlist__44u3__p6_1[] = {
  133522. 2,
  133523. 1,
  133524. 3,
  133525. 0,
  133526. 4,
  133527. };
  133528. static long _vq_lengthlist__44u3__p6_1[] = {
  133529. 2, 4, 4, 5, 5, 4, 5, 5, 6, 5, 4, 5, 5, 5, 6, 5,
  133530. 6, 5, 6, 6, 5, 5, 6, 6, 6,
  133531. };
  133532. static float _vq_quantthresh__44u3__p6_1[] = {
  133533. -1.5, -0.5, 0.5, 1.5,
  133534. };
  133535. static long _vq_quantmap__44u3__p6_1[] = {
  133536. 3, 1, 0, 2, 4,
  133537. };
  133538. static encode_aux_threshmatch _vq_auxt__44u3__p6_1 = {
  133539. _vq_quantthresh__44u3__p6_1,
  133540. _vq_quantmap__44u3__p6_1,
  133541. 5,
  133542. 5
  133543. };
  133544. static static_codebook _44u3__p6_1 = {
  133545. 2, 25,
  133546. _vq_lengthlist__44u3__p6_1,
  133547. 1, -533725184, 1611661312, 3, 0,
  133548. _vq_quantlist__44u3__p6_1,
  133549. NULL,
  133550. &_vq_auxt__44u3__p6_1,
  133551. NULL,
  133552. 0
  133553. };
  133554. static long _vq_quantlist__44u3__p7_0[] = {
  133555. 4,
  133556. 3,
  133557. 5,
  133558. 2,
  133559. 6,
  133560. 1,
  133561. 7,
  133562. 0,
  133563. 8,
  133564. };
  133565. static long _vq_lengthlist__44u3__p7_0[] = {
  133566. 1, 3, 3,10,10,10,10,10,10, 4,10,10,10,10,10,10,
  133567. 10,10, 4,10,10,10,10,10,10,10,10,10,10, 9, 9, 9,
  133568. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  133569. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  133570. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  133571. 9,
  133572. };
  133573. static float _vq_quantthresh__44u3__p7_0[] = {
  133574. -892.5, -637.5, -382.5, -127.5, 127.5, 382.5, 637.5, 892.5,
  133575. };
  133576. static long _vq_quantmap__44u3__p7_0[] = {
  133577. 7, 5, 3, 1, 0, 2, 4, 6,
  133578. 8,
  133579. };
  133580. static encode_aux_threshmatch _vq_auxt__44u3__p7_0 = {
  133581. _vq_quantthresh__44u3__p7_0,
  133582. _vq_quantmap__44u3__p7_0,
  133583. 9,
  133584. 9
  133585. };
  133586. static static_codebook _44u3__p7_0 = {
  133587. 2, 81,
  133588. _vq_lengthlist__44u3__p7_0,
  133589. 1, -515907584, 1627381760, 4, 0,
  133590. _vq_quantlist__44u3__p7_0,
  133591. NULL,
  133592. &_vq_auxt__44u3__p7_0,
  133593. NULL,
  133594. 0
  133595. };
  133596. static long _vq_quantlist__44u3__p7_1[] = {
  133597. 7,
  133598. 6,
  133599. 8,
  133600. 5,
  133601. 9,
  133602. 4,
  133603. 10,
  133604. 3,
  133605. 11,
  133606. 2,
  133607. 12,
  133608. 1,
  133609. 13,
  133610. 0,
  133611. 14,
  133612. };
  133613. static long _vq_lengthlist__44u3__p7_1[] = {
  133614. 1, 4, 4, 6, 6, 7, 6, 8, 7, 9, 8,10, 9,11,11, 4,
  133615. 7, 7, 8, 7, 9, 9,10,10,11,11,11,11,12,12, 4, 7,
  133616. 7, 7, 7, 9, 9,10,10,11,11,12,12,12,11, 6, 8, 8,
  133617. 9, 9,10,10,11,11,12,12,13,12,13,13, 6, 8, 8, 9,
  133618. 9,10,11,11,11,12,12,13,14,13,13, 8, 9, 9,11,11,
  133619. 12,12,12,13,14,13,14,14,14,15, 8, 9, 9,11,11,11,
  133620. 12,13,14,13,14,15,17,14,15, 9,10,10,12,12,13,13,
  133621. 13,14,15,15,15,16,16,16, 9,11,11,12,12,13,13,14,
  133622. 14,14,15,16,16,16,16,10,12,12,13,13,14,14,15,15,
  133623. 15,16,17,17,17,17,10,12,11,13,13,15,14,15,14,16,
  133624. 17,16,16,16,16,11,13,12,14,14,14,14,15,16,17,16,
  133625. 17,17,17,17,11,13,12,14,14,14,15,17,16,17,17,17,
  133626. 17,17,17,12,13,13,15,16,15,16,17,17,16,16,17,17,
  133627. 17,17,12,13,13,15,15,15,16,17,17,17,16,17,16,17,
  133628. 17,
  133629. };
  133630. static float _vq_quantthresh__44u3__p7_1[] = {
  133631. -110.5, -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5,
  133632. 25.5, 42.5, 59.5, 76.5, 93.5, 110.5,
  133633. };
  133634. static long _vq_quantmap__44u3__p7_1[] = {
  133635. 13, 11, 9, 7, 5, 3, 1, 0,
  133636. 2, 4, 6, 8, 10, 12, 14,
  133637. };
  133638. static encode_aux_threshmatch _vq_auxt__44u3__p7_1 = {
  133639. _vq_quantthresh__44u3__p7_1,
  133640. _vq_quantmap__44u3__p7_1,
  133641. 15,
  133642. 15
  133643. };
  133644. static static_codebook _44u3__p7_1 = {
  133645. 2, 225,
  133646. _vq_lengthlist__44u3__p7_1,
  133647. 1, -522338304, 1620115456, 4, 0,
  133648. _vq_quantlist__44u3__p7_1,
  133649. NULL,
  133650. &_vq_auxt__44u3__p7_1,
  133651. NULL,
  133652. 0
  133653. };
  133654. static long _vq_quantlist__44u3__p7_2[] = {
  133655. 8,
  133656. 7,
  133657. 9,
  133658. 6,
  133659. 10,
  133660. 5,
  133661. 11,
  133662. 4,
  133663. 12,
  133664. 3,
  133665. 13,
  133666. 2,
  133667. 14,
  133668. 1,
  133669. 15,
  133670. 0,
  133671. 16,
  133672. };
  133673. static long _vq_lengthlist__44u3__p7_2[] = {
  133674. 2, 5, 5, 7, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  133675. 9, 5, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  133676. 10,10, 5, 6, 6, 7, 7, 8, 8, 8, 8, 9, 8, 9, 9, 9,
  133677. 9,10, 9, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  133678. 10,10,10,10, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9,10,
  133679. 9,10,10,10,10, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  133680. 10,10,10,10,10,10, 7, 8, 8, 9, 8, 9, 9, 9, 9,10,
  133681. 9,10,10,10,10,10,10, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  133682. 9,10,10,10,10,10,10,10, 8, 9, 8, 9, 9, 9, 9,10,
  133683. 9,10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9, 9,10,
  133684. 9,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9,10,
  133685. 9,10,10,10,10,10,10,10,10,10,10, 9, 9, 9,10, 9,
  133686. 10,10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9,10,
  133687. 10,10,10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9,
  133688. 10,10,10,10,10,10,10,10,10,10,10,10,10,11, 9,10,
  133689. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,11, 9,
  133690. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  133691. 9,10,10,10,10,10,10,10,10,10,10,10,11,11,11,10,
  133692. 11,
  133693. };
  133694. static float _vq_quantthresh__44u3__p7_2[] = {
  133695. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  133696. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  133697. };
  133698. static long _vq_quantmap__44u3__p7_2[] = {
  133699. 15, 13, 11, 9, 7, 5, 3, 1,
  133700. 0, 2, 4, 6, 8, 10, 12, 14,
  133701. 16,
  133702. };
  133703. static encode_aux_threshmatch _vq_auxt__44u3__p7_2 = {
  133704. _vq_quantthresh__44u3__p7_2,
  133705. _vq_quantmap__44u3__p7_2,
  133706. 17,
  133707. 17
  133708. };
  133709. static static_codebook _44u3__p7_2 = {
  133710. 2, 289,
  133711. _vq_lengthlist__44u3__p7_2,
  133712. 1, -529530880, 1611661312, 5, 0,
  133713. _vq_quantlist__44u3__p7_2,
  133714. NULL,
  133715. &_vq_auxt__44u3__p7_2,
  133716. NULL,
  133717. 0
  133718. };
  133719. static long _huff_lengthlist__44u3__short[] = {
  133720. 14,14,14,15,13,15,12,16,10, 8, 7, 9, 9, 8,12,16,
  133721. 10, 5, 4, 6, 5, 6, 9,16,14, 8, 6, 8, 7, 8,10,16,
  133722. 14, 7, 4, 6, 3, 5, 8,16,15, 9, 5, 7, 4, 4, 7,16,
  133723. 13,10, 6, 7, 4, 3, 4,13,13,12, 7, 9, 5, 5, 6,12,
  133724. };
  133725. static static_codebook _huff_book__44u3__short = {
  133726. 2, 64,
  133727. _huff_lengthlist__44u3__short,
  133728. 0, 0, 0, 0, 0,
  133729. NULL,
  133730. NULL,
  133731. NULL,
  133732. NULL,
  133733. 0
  133734. };
  133735. static long _huff_lengthlist__44u4__long[] = {
  133736. 3, 8,12,12,13,12,11,13, 5, 4, 6, 7, 8, 8, 9,13,
  133737. 9, 5, 4, 5, 5, 7, 9,13, 9, 6, 5, 6, 6, 7, 8,12,
  133738. 12, 7, 5, 6, 4, 5, 8,13,11, 7, 6, 6, 5, 5, 6,12,
  133739. 10, 8, 8, 7, 7, 5, 3, 8,10,12,13,12,12, 9, 6, 7,
  133740. };
  133741. static static_codebook _huff_book__44u4__long = {
  133742. 2, 64,
  133743. _huff_lengthlist__44u4__long,
  133744. 0, 0, 0, 0, 0,
  133745. NULL,
  133746. NULL,
  133747. NULL,
  133748. NULL,
  133749. 0
  133750. };
  133751. static long _vq_quantlist__44u4__p1_0[] = {
  133752. 1,
  133753. 0,
  133754. 2,
  133755. };
  133756. static long _vq_lengthlist__44u4__p1_0[] = {
  133757. 1, 4, 4, 5, 8, 7, 5, 7, 8, 5, 8, 8, 8,10,11, 8,
  133758. 10,11, 5, 8, 8, 8,11,10, 8,11,11, 4, 8, 8, 8,11,
  133759. 11, 8,11,11, 8,11,11,11,13,14,11,15,14, 8,11,11,
  133760. 10,13,12,11,14,14, 4, 8, 8, 8,11,11, 8,11,11, 7,
  133761. 11,11,11,15,14,10,12,14, 8,11,11,11,14,14,11,14,
  133762. 13,
  133763. };
  133764. static float _vq_quantthresh__44u4__p1_0[] = {
  133765. -0.5, 0.5,
  133766. };
  133767. static long _vq_quantmap__44u4__p1_0[] = {
  133768. 1, 0, 2,
  133769. };
  133770. static encode_aux_threshmatch _vq_auxt__44u4__p1_0 = {
  133771. _vq_quantthresh__44u4__p1_0,
  133772. _vq_quantmap__44u4__p1_0,
  133773. 3,
  133774. 3
  133775. };
  133776. static static_codebook _44u4__p1_0 = {
  133777. 4, 81,
  133778. _vq_lengthlist__44u4__p1_0,
  133779. 1, -535822336, 1611661312, 2, 0,
  133780. _vq_quantlist__44u4__p1_0,
  133781. NULL,
  133782. &_vq_auxt__44u4__p1_0,
  133783. NULL,
  133784. 0
  133785. };
  133786. static long _vq_quantlist__44u4__p2_0[] = {
  133787. 1,
  133788. 0,
  133789. 2,
  133790. };
  133791. static long _vq_lengthlist__44u4__p2_0[] = {
  133792. 2, 5, 5, 5, 6, 6, 5, 6, 6, 5, 6, 6, 7, 8, 8, 6,
  133793. 8, 8, 5, 6, 6, 6, 8, 8, 7, 8, 8, 5, 7, 6, 6, 8,
  133794. 8, 6, 8, 8, 6, 8, 8, 8, 9,10, 8,10,10, 6, 8, 8,
  133795. 8,10, 8, 8,10,10, 5, 6, 6, 6, 8, 8, 6, 8, 8, 6,
  133796. 8, 8, 8,10,10, 8, 8,10, 6, 8, 8, 8,10,10, 8,10,
  133797. 9,
  133798. };
  133799. static float _vq_quantthresh__44u4__p2_0[] = {
  133800. -0.5, 0.5,
  133801. };
  133802. static long _vq_quantmap__44u4__p2_0[] = {
  133803. 1, 0, 2,
  133804. };
  133805. static encode_aux_threshmatch _vq_auxt__44u4__p2_0 = {
  133806. _vq_quantthresh__44u4__p2_0,
  133807. _vq_quantmap__44u4__p2_0,
  133808. 3,
  133809. 3
  133810. };
  133811. static static_codebook _44u4__p2_0 = {
  133812. 4, 81,
  133813. _vq_lengthlist__44u4__p2_0,
  133814. 1, -535822336, 1611661312, 2, 0,
  133815. _vq_quantlist__44u4__p2_0,
  133816. NULL,
  133817. &_vq_auxt__44u4__p2_0,
  133818. NULL,
  133819. 0
  133820. };
  133821. static long _vq_quantlist__44u4__p3_0[] = {
  133822. 2,
  133823. 1,
  133824. 3,
  133825. 0,
  133826. 4,
  133827. };
  133828. static long _vq_lengthlist__44u4__p3_0[] = {
  133829. 2, 4, 4, 8, 8, 5, 7, 7, 9, 9, 5, 7, 7, 9, 9, 8,
  133830. 10, 9,12,12, 8, 9,10,12,12, 5, 7, 7,10,10, 7, 9,
  133831. 9,11,11, 7, 9, 9,11,11,10,12,11,14,14, 9,10,11,
  133832. 13,14, 5, 7, 7,10,10, 7, 9, 9,11,11, 7, 9, 9,11,
  133833. 11, 9,11,10,14,13,10,11,11,14,14, 8,10,10,14,13,
  133834. 10,12,12,15,14, 9,11,11,15,14,13,14,14,17,17,12,
  133835. 14,14,16,16, 8,10,10,14,14, 9,11,11,14,15,10,12,
  133836. 12,14,15,12,14,13,16,16,13,14,15,15,18, 4, 7, 7,
  133837. 10,10, 7, 9, 9,12,11, 7, 9, 9,11,12,10,12,11,15,
  133838. 14,10,11,12,14,15, 7, 9, 9,12,12, 9,11,12,13,13,
  133839. 9,11,12,13,13,12,13,13,15,16,11,13,13,15,16, 7,
  133840. 9, 9,12,12, 9,11,10,13,12, 9,11,12,13,14,11,13,
  133841. 12,16,14,12,13,13,15,16,10,12,12,16,15,11,13,13,
  133842. 17,16,11,13,13,17,16,14,15,15,17,17,14,16,16,18,
  133843. 20, 9,11,11,15,16,11,13,12,16,16,11,13,13,16,17,
  133844. 14,15,14,18,16,14,16,16,17,20, 5, 7, 7,10,10, 7,
  133845. 9, 9,12,11, 7, 9,10,11,12,10,12,11,15,15,10,12,
  133846. 12,14,14, 7, 9, 9,12,12, 9,12,11,14,13, 9,10,11,
  133847. 12,13,12,13,14,16,16,11,12,13,14,16, 7, 9, 9,12,
  133848. 12, 9,12,11,13,13, 9,12,11,13,13,11,13,13,16,16,
  133849. 12,13,13,16,15, 9,11,11,16,14,11,13,13,16,16,11,
  133850. 12,13,16,16,14,16,16,17,17,13,14,15,16,17,10,12,
  133851. 12,15,15,11,13,13,16,17,11,13,13,16,16,14,16,15,
  133852. 19,19,14,15,15,17,18, 8,10,10,14,14,10,12,12,15,
  133853. 15,10,12,12,16,16,14,16,15,20,19,13,15,15,17,16,
  133854. 9,12,12,16,16,11,13,13,16,18,11,14,13,16,17,16,
  133855. 17,16,20, 0,15,16,18,18,20, 9,11,11,15,15,11,14,
  133856. 12,17,16,11,13,13,17,17,15,17,15,20,20,14,16,16,
  133857. 17, 0,13,15,14,18,16,14,15,16, 0,18,14,16,16, 0,
  133858. 0,18,16, 0, 0,20,16,18,18, 0, 0,12,14,14,17,18,
  133859. 13,15,14,20,18,14,16,15,19,19,16,20,16, 0,18,16,
  133860. 19,17,19, 0, 8,10,10,14,14,10,12,12,16,15,10,12,
  133861. 12,16,16,13,15,15,18,17,14,16,16,19, 0, 9,11,11,
  133862. 16,15,11,14,13,18,17,11,12,13,17,18,14,17,16,18,
  133863. 18,15,16,17,18,18, 9,12,12,16,16,11,13,13,16,18,
  133864. 11,14,13,17,17,15,16,16,18,20,16,17,17,20,20,12,
  133865. 14,14,18,17,14,16,16, 0,19,13,14,15,18, 0,16, 0,
  133866. 0, 0, 0,16,16, 0,19,20,13,15,14, 0, 0,14,16,16,
  133867. 18,19,14,16,15, 0,20,16,20,18, 0,20,17,20,17, 0,
  133868. 0,
  133869. };
  133870. static float _vq_quantthresh__44u4__p3_0[] = {
  133871. -1.5, -0.5, 0.5, 1.5,
  133872. };
  133873. static long _vq_quantmap__44u4__p3_0[] = {
  133874. 3, 1, 0, 2, 4,
  133875. };
  133876. static encode_aux_threshmatch _vq_auxt__44u4__p3_0 = {
  133877. _vq_quantthresh__44u4__p3_0,
  133878. _vq_quantmap__44u4__p3_0,
  133879. 5,
  133880. 5
  133881. };
  133882. static static_codebook _44u4__p3_0 = {
  133883. 4, 625,
  133884. _vq_lengthlist__44u4__p3_0,
  133885. 1, -533725184, 1611661312, 3, 0,
  133886. _vq_quantlist__44u4__p3_0,
  133887. NULL,
  133888. &_vq_auxt__44u4__p3_0,
  133889. NULL,
  133890. 0
  133891. };
  133892. static long _vq_quantlist__44u4__p4_0[] = {
  133893. 2,
  133894. 1,
  133895. 3,
  133896. 0,
  133897. 4,
  133898. };
  133899. static long _vq_lengthlist__44u4__p4_0[] = {
  133900. 4, 5, 5, 8, 8, 5, 7, 6, 9, 9, 5, 6, 7, 9, 9, 9,
  133901. 9, 9,11,11, 8, 9, 9,11,11, 5, 7, 7, 9, 9, 7, 8,
  133902. 8,10,10, 7, 7, 8,10,10, 9,10,10,11,12, 9,10,10,
  133903. 11,12, 5, 7, 7, 9, 9, 7, 8, 7,10,10, 7, 8, 8,10,
  133904. 10, 9,10,10,12,11, 9,10,10,12,11, 9,10, 9,12,12,
  133905. 9,10,10,13,12, 9,10,10,12,12,12,12,12,14,14,11,
  133906. 12,12,13,14, 9, 9,10,12,12, 9,10,10,13,13, 9,10,
  133907. 10,12,13,11,12,12,14,13,11,12,12,14,14, 5, 7, 7,
  133908. 9, 9, 7, 8, 8,10,10, 7, 8, 8,10,10,10,10,10,12,
  133909. 12, 9,10,10,12,12, 7, 8, 8,11,10, 8, 8, 9,11,11,
  133910. 8, 9, 9,11,11,11,11,11,12,13,10,11,11,13,13, 6,
  133911. 8, 8,10,10, 7, 9, 8,11,10, 8, 9, 9,11,11,10,11,
  133912. 10,13,11,10,11,11,13,13, 9,11,10,13,12,10,11,11,
  133913. 13,14,10,11,11,14,13,12,12,13,12,15,12,13,13,15,
  133914. 15, 9,10,10,12,13,10,11,10,13,12,10,11,11,13,14,
  133915. 12,13,11,15,13,13,13,13,15,15, 5, 7, 7, 9, 9, 7,
  133916. 8, 8,10,10, 7, 8, 8,10,10, 9,10,10,12,12,10,10,
  133917. 11,12,13, 6, 8, 8,10,10, 8, 9, 9,11,11, 7, 8, 9,
  133918. 10,11,10,11,11,13,13,10,10,11,11,13, 7, 8, 8,10,
  133919. 11, 8, 9, 9,11,11, 8, 9, 8,11,11,10,11,11,13,13,
  133920. 11,12,11,13,12, 9,10,10,13,12,10,11,11,14,13,10,
  133921. 10,11,12,13,12,13,13,15,15,12,11,13,13,14, 9,10,
  133922. 11,12,13,10,11,11,13,14,10,11,11,13,13,12,13,13,
  133923. 15,15,12,13,12,15,12, 8, 9, 9,12,12, 9,11,10,13,
  133924. 13, 9,10,10,13,13,12,13,13,15,15,12,12,12,14,14,
  133925. 9,10,10,13,13,10,11,11,13,14,10,11,11,14,13,13,
  133926. 13,14,14,16,13,13,13,15,15, 9,10,10,13,13,10,11,
  133927. 10,14,13,10,11,11,13,14,12,14,13,16,14,12,13,13,
  133928. 14,15,11,12,12,15,14,11,12,13,14,15,12,13,13,16,
  133929. 15,14,12,15,12,16,14,15,15,16,16,11,12,12,14,14,
  133930. 11,13,12,15,14,12,13,13,15,16,13,15,13,17,13,14,
  133931. 15,15,16,17, 8, 9, 9,12,12, 9,10,10,12,13, 9,10,
  133932. 10,13,13,12,12,12,14,14,12,13,13,15,15, 9,10,10,
  133933. 13,12,10,11,11,14,13,10,10,11,13,14,13,13,13,15,
  133934. 15,12,13,14,14,16, 9,10,10,13,13,10,11,11,13,14,
  133935. 10,11,11,14,14,13,13,13,15,15,13,14,13,16,14,11,
  133936. 12,12,15,14,12,13,13,16,15,11,12,13,14,15,14,15,
  133937. 15,17,16,13,13,15,13,16,11,12,13,14,15,13,13,13,
  133938. 15,16,11,13,12,15,14,14,15,15,16,16,14,15,12,17,
  133939. 13,
  133940. };
  133941. static float _vq_quantthresh__44u4__p4_0[] = {
  133942. -1.5, -0.5, 0.5, 1.5,
  133943. };
  133944. static long _vq_quantmap__44u4__p4_0[] = {
  133945. 3, 1, 0, 2, 4,
  133946. };
  133947. static encode_aux_threshmatch _vq_auxt__44u4__p4_0 = {
  133948. _vq_quantthresh__44u4__p4_0,
  133949. _vq_quantmap__44u4__p4_0,
  133950. 5,
  133951. 5
  133952. };
  133953. static static_codebook _44u4__p4_0 = {
  133954. 4, 625,
  133955. _vq_lengthlist__44u4__p4_0,
  133956. 1, -533725184, 1611661312, 3, 0,
  133957. _vq_quantlist__44u4__p4_0,
  133958. NULL,
  133959. &_vq_auxt__44u4__p4_0,
  133960. NULL,
  133961. 0
  133962. };
  133963. static long _vq_quantlist__44u4__p5_0[] = {
  133964. 4,
  133965. 3,
  133966. 5,
  133967. 2,
  133968. 6,
  133969. 1,
  133970. 7,
  133971. 0,
  133972. 8,
  133973. };
  133974. static long _vq_lengthlist__44u4__p5_0[] = {
  133975. 2, 3, 3, 6, 6, 7, 7, 9, 9, 4, 5, 5, 7, 7, 8, 8,
  133976. 10, 9, 4, 5, 5, 7, 7, 8, 8,10,10, 6, 7, 7, 8, 8,
  133977. 9, 9,11,10, 6, 7, 7, 8, 8, 9, 9,10,11, 7, 8, 8,
  133978. 9, 9,10,10,11,11, 7, 8, 8, 9, 9,10,10,11,11, 9,
  133979. 10,10,11,10,11,11,12,12, 9,10,10,10,11,11,11,12,
  133980. 12,
  133981. };
  133982. static float _vq_quantthresh__44u4__p5_0[] = {
  133983. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  133984. };
  133985. static long _vq_quantmap__44u4__p5_0[] = {
  133986. 7, 5, 3, 1, 0, 2, 4, 6,
  133987. 8,
  133988. };
  133989. static encode_aux_threshmatch _vq_auxt__44u4__p5_0 = {
  133990. _vq_quantthresh__44u4__p5_0,
  133991. _vq_quantmap__44u4__p5_0,
  133992. 9,
  133993. 9
  133994. };
  133995. static static_codebook _44u4__p5_0 = {
  133996. 2, 81,
  133997. _vq_lengthlist__44u4__p5_0,
  133998. 1, -531628032, 1611661312, 4, 0,
  133999. _vq_quantlist__44u4__p5_0,
  134000. NULL,
  134001. &_vq_auxt__44u4__p5_0,
  134002. NULL,
  134003. 0
  134004. };
  134005. static long _vq_quantlist__44u4__p6_0[] = {
  134006. 6,
  134007. 5,
  134008. 7,
  134009. 4,
  134010. 8,
  134011. 3,
  134012. 9,
  134013. 2,
  134014. 10,
  134015. 1,
  134016. 11,
  134017. 0,
  134018. 12,
  134019. };
  134020. static long _vq_lengthlist__44u4__p6_0[] = {
  134021. 1, 4, 4, 6, 6, 8, 8, 9, 9,11,10,13,13, 4, 6, 5,
  134022. 8, 8, 9, 9,10,10,11,11,14,14, 4, 6, 6, 8, 8, 9,
  134023. 9,10,10,11,11,14,14, 6, 8, 8, 9, 9,10,10,11,11,
  134024. 12,12,15,15, 6, 8, 8, 9, 9,10,11,11,11,12,12,15,
  134025. 15, 8, 9, 9,11,10,11,11,12,12,13,13,16,16, 8, 9,
  134026. 9,10,10,11,11,12,12,13,13,16,16,10,10,10,12,11,
  134027. 12,12,13,13,14,14,16,16,10,10,10,11,12,12,12,13,
  134028. 13,13,14,16,17,11,12,11,12,12,13,13,14,14,15,14,
  134029. 18,17,11,11,12,12,12,13,13,14,14,14,15,19,18,14,
  134030. 15,14,15,15,17,16,17,17,17,17,21, 0,14,15,15,16,
  134031. 16,16,16,17,17,18,17,20,21,
  134032. };
  134033. static float _vq_quantthresh__44u4__p6_0[] = {
  134034. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  134035. 12.5, 17.5, 22.5, 27.5,
  134036. };
  134037. static long _vq_quantmap__44u4__p6_0[] = {
  134038. 11, 9, 7, 5, 3, 1, 0, 2,
  134039. 4, 6, 8, 10, 12,
  134040. };
  134041. static encode_aux_threshmatch _vq_auxt__44u4__p6_0 = {
  134042. _vq_quantthresh__44u4__p6_0,
  134043. _vq_quantmap__44u4__p6_0,
  134044. 13,
  134045. 13
  134046. };
  134047. static static_codebook _44u4__p6_0 = {
  134048. 2, 169,
  134049. _vq_lengthlist__44u4__p6_0,
  134050. 1, -526516224, 1616117760, 4, 0,
  134051. _vq_quantlist__44u4__p6_0,
  134052. NULL,
  134053. &_vq_auxt__44u4__p6_0,
  134054. NULL,
  134055. 0
  134056. };
  134057. static long _vq_quantlist__44u4__p6_1[] = {
  134058. 2,
  134059. 1,
  134060. 3,
  134061. 0,
  134062. 4,
  134063. };
  134064. static long _vq_lengthlist__44u4__p6_1[] = {
  134065. 2, 4, 4, 5, 5, 4, 5, 5, 6, 5, 4, 5, 5, 5, 6, 5,
  134066. 6, 5, 6, 6, 5, 5, 6, 6, 6,
  134067. };
  134068. static float _vq_quantthresh__44u4__p6_1[] = {
  134069. -1.5, -0.5, 0.5, 1.5,
  134070. };
  134071. static long _vq_quantmap__44u4__p6_1[] = {
  134072. 3, 1, 0, 2, 4,
  134073. };
  134074. static encode_aux_threshmatch _vq_auxt__44u4__p6_1 = {
  134075. _vq_quantthresh__44u4__p6_1,
  134076. _vq_quantmap__44u4__p6_1,
  134077. 5,
  134078. 5
  134079. };
  134080. static static_codebook _44u4__p6_1 = {
  134081. 2, 25,
  134082. _vq_lengthlist__44u4__p6_1,
  134083. 1, -533725184, 1611661312, 3, 0,
  134084. _vq_quantlist__44u4__p6_1,
  134085. NULL,
  134086. &_vq_auxt__44u4__p6_1,
  134087. NULL,
  134088. 0
  134089. };
  134090. static long _vq_quantlist__44u4__p7_0[] = {
  134091. 6,
  134092. 5,
  134093. 7,
  134094. 4,
  134095. 8,
  134096. 3,
  134097. 9,
  134098. 2,
  134099. 10,
  134100. 1,
  134101. 11,
  134102. 0,
  134103. 12,
  134104. };
  134105. static long _vq_lengthlist__44u4__p7_0[] = {
  134106. 1, 3, 3,12,12,12,12,12,12,12,12,12,12, 3,12,11,
  134107. 12,12,12,12,12,12,12,12,12,12, 4,11,10,12,12,12,
  134108. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  134109. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  134110. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  134111. 12,12,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  134112. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  134113. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  134114. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  134115. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  134116. 11,11,11,11,11,11,11,11,11,
  134117. };
  134118. static float _vq_quantthresh__44u4__p7_0[] = {
  134119. -1402.5, -1147.5, -892.5, -637.5, -382.5, -127.5, 127.5, 382.5,
  134120. 637.5, 892.5, 1147.5, 1402.5,
  134121. };
  134122. static long _vq_quantmap__44u4__p7_0[] = {
  134123. 11, 9, 7, 5, 3, 1, 0, 2,
  134124. 4, 6, 8, 10, 12,
  134125. };
  134126. static encode_aux_threshmatch _vq_auxt__44u4__p7_0 = {
  134127. _vq_quantthresh__44u4__p7_0,
  134128. _vq_quantmap__44u4__p7_0,
  134129. 13,
  134130. 13
  134131. };
  134132. static static_codebook _44u4__p7_0 = {
  134133. 2, 169,
  134134. _vq_lengthlist__44u4__p7_0,
  134135. 1, -514332672, 1627381760, 4, 0,
  134136. _vq_quantlist__44u4__p7_0,
  134137. NULL,
  134138. &_vq_auxt__44u4__p7_0,
  134139. NULL,
  134140. 0
  134141. };
  134142. static long _vq_quantlist__44u4__p7_1[] = {
  134143. 7,
  134144. 6,
  134145. 8,
  134146. 5,
  134147. 9,
  134148. 4,
  134149. 10,
  134150. 3,
  134151. 11,
  134152. 2,
  134153. 12,
  134154. 1,
  134155. 13,
  134156. 0,
  134157. 14,
  134158. };
  134159. static long _vq_lengthlist__44u4__p7_1[] = {
  134160. 1, 4, 4, 6, 6, 7, 7, 9, 8,10, 8,10, 9,11,11, 4,
  134161. 7, 6, 8, 7, 9, 9,10,10,11,10,11,10,12,10, 4, 6,
  134162. 7, 8, 8, 9, 9,10,10,11,11,11,11,12,12, 6, 8, 8,
  134163. 10, 9,11,10,12,11,12,12,12,12,13,13, 6, 8, 8,10,
  134164. 10,10,11,11,11,12,12,13,12,13,13, 8, 9, 9,11,11,
  134165. 12,11,12,12,13,13,13,13,13,13, 8, 9, 9,11,11,11,
  134166. 12,12,12,13,13,13,13,13,13, 9,10,10,12,11,13,13,
  134167. 13,13,14,13,13,14,14,14, 9,10,11,11,12,12,13,13,
  134168. 13,13,13,14,15,14,14,10,11,11,12,12,13,13,14,14,
  134169. 14,14,14,15,16,16,10,11,11,12,13,13,13,13,15,14,
  134170. 14,15,16,15,16,10,12,12,13,13,14,14,14,15,15,15,
  134171. 15,15,15,16,11,12,12,13,13,14,14,14,15,15,15,16,
  134172. 15,17,16,11,12,12,13,13,13,15,15,14,16,16,16,16,
  134173. 16,17,11,12,12,13,13,14,14,15,14,15,15,17,17,16,
  134174. 16,
  134175. };
  134176. static float _vq_quantthresh__44u4__p7_1[] = {
  134177. -110.5, -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5,
  134178. 25.5, 42.5, 59.5, 76.5, 93.5, 110.5,
  134179. };
  134180. static long _vq_quantmap__44u4__p7_1[] = {
  134181. 13, 11, 9, 7, 5, 3, 1, 0,
  134182. 2, 4, 6, 8, 10, 12, 14,
  134183. };
  134184. static encode_aux_threshmatch _vq_auxt__44u4__p7_1 = {
  134185. _vq_quantthresh__44u4__p7_1,
  134186. _vq_quantmap__44u4__p7_1,
  134187. 15,
  134188. 15
  134189. };
  134190. static static_codebook _44u4__p7_1 = {
  134191. 2, 225,
  134192. _vq_lengthlist__44u4__p7_1,
  134193. 1, -522338304, 1620115456, 4, 0,
  134194. _vq_quantlist__44u4__p7_1,
  134195. NULL,
  134196. &_vq_auxt__44u4__p7_1,
  134197. NULL,
  134198. 0
  134199. };
  134200. static long _vq_quantlist__44u4__p7_2[] = {
  134201. 8,
  134202. 7,
  134203. 9,
  134204. 6,
  134205. 10,
  134206. 5,
  134207. 11,
  134208. 4,
  134209. 12,
  134210. 3,
  134211. 13,
  134212. 2,
  134213. 14,
  134214. 1,
  134215. 15,
  134216. 0,
  134217. 16,
  134218. };
  134219. static long _vq_lengthlist__44u4__p7_2[] = {
  134220. 2, 5, 5, 7, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  134221. 9, 5, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  134222. 9, 9, 5, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  134223. 9, 9, 9, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  134224. 10,10,10,10, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9,10,
  134225. 9,10, 9,10,10, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  134226. 10,10,10,10,10,10, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  134227. 9,10,10,10,10,10,10, 8, 9, 8, 9, 9, 9, 9, 9, 9,
  134228. 10,10,10,10,10,10,10,10, 8, 8, 8, 9, 9, 9, 9, 9,
  134229. 10,10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9,10,10,
  134230. 10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9,10,
  134231. 10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9,10,
  134232. 10,10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9,
  134233. 10,10,10,10,10,10,10,10,10,11,10,10,10, 9, 9, 9,
  134234. 10,10,10,10,10,10,10,10,10,10,10,10,10,10, 9, 9,
  134235. 9,10,10,10,10,10,10,10,10,10,10,10,10,10,10, 9,
  134236. 10, 9,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  134237. 9,10, 9,10,10,10,10,10,10,10,10,10,10,11,10,10,
  134238. 10,
  134239. };
  134240. static float _vq_quantthresh__44u4__p7_2[] = {
  134241. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  134242. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  134243. };
  134244. static long _vq_quantmap__44u4__p7_2[] = {
  134245. 15, 13, 11, 9, 7, 5, 3, 1,
  134246. 0, 2, 4, 6, 8, 10, 12, 14,
  134247. 16,
  134248. };
  134249. static encode_aux_threshmatch _vq_auxt__44u4__p7_2 = {
  134250. _vq_quantthresh__44u4__p7_2,
  134251. _vq_quantmap__44u4__p7_2,
  134252. 17,
  134253. 17
  134254. };
  134255. static static_codebook _44u4__p7_2 = {
  134256. 2, 289,
  134257. _vq_lengthlist__44u4__p7_2,
  134258. 1, -529530880, 1611661312, 5, 0,
  134259. _vq_quantlist__44u4__p7_2,
  134260. NULL,
  134261. &_vq_auxt__44u4__p7_2,
  134262. NULL,
  134263. 0
  134264. };
  134265. static long _huff_lengthlist__44u4__short[] = {
  134266. 14,17,15,17,16,14,13,16,10, 7, 7,10,13,10,15,16,
  134267. 9, 4, 4, 6, 5, 7, 9,16,12, 8, 7, 8, 8, 8,11,16,
  134268. 14, 7, 4, 6, 3, 5, 8,15,13, 8, 5, 7, 4, 5, 7,16,
  134269. 12, 9, 6, 8, 3, 3, 5,16,14,13, 7,10, 5, 5, 7,15,
  134270. };
  134271. static static_codebook _huff_book__44u4__short = {
  134272. 2, 64,
  134273. _huff_lengthlist__44u4__short,
  134274. 0, 0, 0, 0, 0,
  134275. NULL,
  134276. NULL,
  134277. NULL,
  134278. NULL,
  134279. 0
  134280. };
  134281. static long _huff_lengthlist__44u5__long[] = {
  134282. 3, 8,13,12,14,12,16,11,13,14, 5, 4, 5, 6, 7, 8,
  134283. 10, 9,12,15,10, 5, 5, 5, 6, 8, 9, 9,13,15,10, 5,
  134284. 5, 6, 6, 7, 8, 8,11,13,12, 7, 5, 6, 4, 6, 7, 7,
  134285. 11,14,11, 7, 7, 6, 6, 6, 7, 6,10,14,14, 9, 8, 8,
  134286. 6, 7, 7, 7,11,16,11, 8, 8, 7, 6, 6, 7, 4, 7,12,
  134287. 10,10,12,10,10, 9,10, 5, 6, 9,10,12,15,13,14,14,
  134288. 14, 8, 7, 8,
  134289. };
  134290. static static_codebook _huff_book__44u5__long = {
  134291. 2, 100,
  134292. _huff_lengthlist__44u5__long,
  134293. 0, 0, 0, 0, 0,
  134294. NULL,
  134295. NULL,
  134296. NULL,
  134297. NULL,
  134298. 0
  134299. };
  134300. static long _vq_quantlist__44u5__p1_0[] = {
  134301. 1,
  134302. 0,
  134303. 2,
  134304. };
  134305. static long _vq_lengthlist__44u5__p1_0[] = {
  134306. 1, 4, 4, 5, 8, 7, 5, 7, 7, 5, 8, 8, 8,10,10, 7,
  134307. 9,10, 5, 8, 8, 7,10, 9, 8,10,10, 5, 8, 8, 8,10,
  134308. 10, 8,10,10, 8,10,10,10,12,13,10,13,13, 7,10,10,
  134309. 10,13,11,10,13,13, 4, 8, 8, 8,11,10, 8,10,10, 7,
  134310. 10,10,10,13,13,10,11,13, 8,10,11,10,13,13,10,13,
  134311. 12,
  134312. };
  134313. static float _vq_quantthresh__44u5__p1_0[] = {
  134314. -0.5, 0.5,
  134315. };
  134316. static long _vq_quantmap__44u5__p1_0[] = {
  134317. 1, 0, 2,
  134318. };
  134319. static encode_aux_threshmatch _vq_auxt__44u5__p1_0 = {
  134320. _vq_quantthresh__44u5__p1_0,
  134321. _vq_quantmap__44u5__p1_0,
  134322. 3,
  134323. 3
  134324. };
  134325. static static_codebook _44u5__p1_0 = {
  134326. 4, 81,
  134327. _vq_lengthlist__44u5__p1_0,
  134328. 1, -535822336, 1611661312, 2, 0,
  134329. _vq_quantlist__44u5__p1_0,
  134330. NULL,
  134331. &_vq_auxt__44u5__p1_0,
  134332. NULL,
  134333. 0
  134334. };
  134335. static long _vq_quantlist__44u5__p2_0[] = {
  134336. 1,
  134337. 0,
  134338. 2,
  134339. };
  134340. static long _vq_lengthlist__44u5__p2_0[] = {
  134341. 3, 4, 4, 5, 6, 6, 5, 6, 6, 5, 6, 6, 6, 8, 8, 6,
  134342. 7, 8, 5, 6, 6, 6, 8, 7, 6, 8, 8, 5, 6, 6, 6, 8,
  134343. 8, 6, 8, 8, 6, 8, 8, 8, 9, 9, 8, 9, 9, 6, 8, 7,
  134344. 7, 9, 8, 8, 9, 9, 5, 6, 6, 6, 8, 7, 6, 8, 8, 6,
  134345. 8, 7, 8, 9, 9, 7, 8, 9, 6, 8, 8, 8, 9, 9, 8, 9,
  134346. 9,
  134347. };
  134348. static float _vq_quantthresh__44u5__p2_0[] = {
  134349. -0.5, 0.5,
  134350. };
  134351. static long _vq_quantmap__44u5__p2_0[] = {
  134352. 1, 0, 2,
  134353. };
  134354. static encode_aux_threshmatch _vq_auxt__44u5__p2_0 = {
  134355. _vq_quantthresh__44u5__p2_0,
  134356. _vq_quantmap__44u5__p2_0,
  134357. 3,
  134358. 3
  134359. };
  134360. static static_codebook _44u5__p2_0 = {
  134361. 4, 81,
  134362. _vq_lengthlist__44u5__p2_0,
  134363. 1, -535822336, 1611661312, 2, 0,
  134364. _vq_quantlist__44u5__p2_0,
  134365. NULL,
  134366. &_vq_auxt__44u5__p2_0,
  134367. NULL,
  134368. 0
  134369. };
  134370. static long _vq_quantlist__44u5__p3_0[] = {
  134371. 2,
  134372. 1,
  134373. 3,
  134374. 0,
  134375. 4,
  134376. };
  134377. static long _vq_lengthlist__44u5__p3_0[] = {
  134378. 2, 4, 5, 8, 8, 5, 7, 6, 9, 9, 5, 6, 7, 9, 9, 8,
  134379. 10, 9,13,12, 8, 9,10,12,12, 5, 7, 7,10,10, 7, 9,
  134380. 9,11,11, 6, 8, 9,11,11,10,11,11,14,14, 9,10,11,
  134381. 13,14, 5, 7, 7, 9,10, 7, 9, 8,11,11, 7, 9, 9,11,
  134382. 11, 9,11,10,14,13,10,11,11,14,14, 8,10,10,13,13,
  134383. 10,11,11,15,14, 9,11,11,14,14,13,14,14,17,16,12,
  134384. 13,13,15,16, 8,10,10,13,13, 9,11,11,14,15,10,11,
  134385. 11,14,15,12,14,13,16,16,13,15,14,15,17, 5, 7, 7,
  134386. 10,10, 7, 9, 9,11,11, 7, 9, 9,11,11,10,11,11,14,
  134387. 14,10,11,12,14,14, 7, 9, 9,12,11, 9,11,11,13,13,
  134388. 9,11,11,13,13,12,13,13,15,16,11,12,13,15,16, 6,
  134389. 9, 9,11,11, 8,11,10,13,12, 9,11,11,13,14,11,13,
  134390. 12,16,14,11,13,13,16,17,10,12,11,15,15,11,13,13,
  134391. 16,16,11,13,13,17,16,14,15,15,17,17,14,16,16,17,
  134392. 18, 9,11,11,14,15,10,12,12,15,15,11,13,13,16,17,
  134393. 13,15,13,17,15,14,15,16,18, 0, 5, 7, 7,10,10, 7,
  134394. 9, 9,11,11, 7, 9, 9,11,11,10,11,11,14,14,10,11,
  134395. 12,14,15, 6, 9, 9,12,11, 9,11,11,13,13, 8,10,11,
  134396. 12,13,11,13,13,16,15,11,12,13,14,15, 7, 9, 9,11,
  134397. 12, 9,11,11,13,13, 9,11,11,13,13,11,13,13,15,16,
  134398. 11,13,13,15,14, 9,11,11,15,14,11,13,13,17,15,10,
  134399. 12,12,15,15,14,16,16,17,17,13,13,15,15,17,10,11,
  134400. 12,15,15,11,13,13,16,16,11,13,13,15,15,14,15,15,
  134401. 18,18,14,15,15,17,17, 8,10,10,13,13,10,12,11,15,
  134402. 15,10,11,12,15,15,14,15,15,18,18,13,14,14,18,18,
  134403. 9,11,11,15,16,11,13,13,17,17,11,13,13,16,16,15,
  134404. 15,16,17, 0,14,15,17, 0, 0, 9,11,11,15,15,10,13,
  134405. 12,18,16,11,13,13,15,16,14,16,15,20,20,14,15,16,
  134406. 17, 0,13,14,14,20,16,14,15,16,19,18,14,15,15,19,
  134407. 0,18,16, 0,20,20,16,18,18, 0, 0,12,14,14,18,18,
  134408. 13,15,14,18,16,14,15,16,18,20,16,19,16, 0,17,17,
  134409. 18,18,19, 0, 8,10,10,14,14,10,11,11,14,15,10,11,
  134410. 12,15,15,13,15,14,19,17,13,15,15,17, 0, 9,11,11,
  134411. 16,15,11,13,13,16,16,10,12,13,15,17,14,16,16,18,
  134412. 18,14,15,15,18, 0, 9,11,11,15,15,11,13,13,16,17,
  134413. 11,13,13,18,17,14,18,16,18,18,15,17,17,18, 0,12,
  134414. 14,14,18,18,14,15,15,20, 0,13,14,15,17, 0,16,18,
  134415. 17, 0, 0,16,16, 0,17,20,12,14,14,18,18,14,16,15,
  134416. 0,18,14,16,15,18, 0,16,19,17, 0, 0,17,18,16, 0,
  134417. 0,
  134418. };
  134419. static float _vq_quantthresh__44u5__p3_0[] = {
  134420. -1.5, -0.5, 0.5, 1.5,
  134421. };
  134422. static long _vq_quantmap__44u5__p3_0[] = {
  134423. 3, 1, 0, 2, 4,
  134424. };
  134425. static encode_aux_threshmatch _vq_auxt__44u5__p3_0 = {
  134426. _vq_quantthresh__44u5__p3_0,
  134427. _vq_quantmap__44u5__p3_0,
  134428. 5,
  134429. 5
  134430. };
  134431. static static_codebook _44u5__p3_0 = {
  134432. 4, 625,
  134433. _vq_lengthlist__44u5__p3_0,
  134434. 1, -533725184, 1611661312, 3, 0,
  134435. _vq_quantlist__44u5__p3_0,
  134436. NULL,
  134437. &_vq_auxt__44u5__p3_0,
  134438. NULL,
  134439. 0
  134440. };
  134441. static long _vq_quantlist__44u5__p4_0[] = {
  134442. 2,
  134443. 1,
  134444. 3,
  134445. 0,
  134446. 4,
  134447. };
  134448. static long _vq_lengthlist__44u5__p4_0[] = {
  134449. 4, 5, 5, 8, 8, 6, 7, 6, 9, 9, 6, 6, 7, 9, 9, 8,
  134450. 9, 9,11,11, 8, 9, 9,11,11, 6, 7, 7, 9, 9, 7, 8,
  134451. 8,10,10, 6, 7, 8, 9,10, 9,10,10,11,12, 9, 9,10,
  134452. 11,12, 6, 7, 7, 9, 9, 6, 8, 7,10, 9, 7, 8, 8,10,
  134453. 10, 9,10, 9,12,11, 9,10,10,12,11, 8, 9, 9,12,11,
  134454. 9,10,10,12,12, 9,10,10,12,12,11,12,12,13,14,11,
  134455. 11,12,13,14, 8, 9, 9,11,12, 9,10,10,12,12, 9,10,
  134456. 10,12,12,11,12,11,14,13,11,12,12,13,13, 5, 7, 7,
  134457. 9, 9, 7, 8, 8,10,10, 7, 8, 8,10,10, 9,10,10,12,
  134458. 12, 9,10,10,12,12, 7, 8, 8,10,10, 8, 8, 9,10,11,
  134459. 8, 9, 9,11,11,10,10,11,11,13,10,11,11,12,13, 6,
  134460. 7, 8,10,10, 7, 9, 8,11,10, 8, 9, 9,11,11,10,11,
  134461. 10,13,11,10,11,11,12,12, 9,10,10,12,12,10,10,11,
  134462. 12,13,10,11,11,13,13,12,11,13,12,15,12,13,13,14,
  134463. 15, 9,10,10,12,12, 9,11,10,13,12,10,11,11,13,13,
  134464. 11,13,11,14,12,12,13,13,14,15, 5, 7, 7, 9, 9, 7,
  134465. 8, 8,10,10, 7, 8, 8,10,10, 9,10,10,12,12, 9,10,
  134466. 10,12,12, 6, 8, 7,10,10, 8, 9, 9,11,11, 7, 8, 9,
  134467. 10,11,10,11,11,12,12,10,10,11,11,13, 7, 8, 8,10,
  134468. 10, 8, 9, 9,11,11, 8, 9, 8,11,10,10,11,11,13,12,
  134469. 10,11,10,13,11, 9,10,10,12,12,10,11,11,13,12, 9,
  134470. 10,10,12,13,12,13,13,14,15,11,11,13,12,14, 9,10,
  134471. 10,12,12,10,11,11,13,13,10,11,10,13,12,12,13,13,
  134472. 14,14,12,13,11,14,12, 8, 9, 9,12,12, 9,10,10,12,
  134473. 12, 9,10,10,12,12,12,12,12,14,14,11,12,12,14,13,
  134474. 9,10,10,12,12,10,11,11,13,13,10,11,11,13,12,12,
  134475. 12,13,14,15,12,13,13,15,14, 9,10,10,12,12,10,11,
  134476. 10,13,12,10,11,11,12,13,12,13,12,15,13,12,13,13,
  134477. 14,15,11,12,12,14,13,11,12,12,14,15,12,13,13,15,
  134478. 14,13,12,14,12,16,13,14,14,15,15,11,11,12,14,14,
  134479. 11,12,11,14,13,12,13,13,14,15,13,14,12,16,12,14,
  134480. 14,15,16,16, 8, 9, 9,11,12, 9,10,10,12,12, 9,10,
  134481. 10,12,13,11,12,12,13,13,12,12,13,14,14, 9,10,10,
  134482. 12,12,10,11,10,13,12,10,10,11,12,13,12,13,13,15,
  134483. 14,12,12,13,13,15, 9,10,10,12,13,10,11,11,12,13,
  134484. 10,11,11,13,13,12,13,13,14,15,12,13,12,15,14,11,
  134485. 12,11,14,13,12,13,13,15,14,11,11,12,13,14,14,15,
  134486. 14,16,15,13,12,14,13,16,11,12,12,13,14,12,13,13,
  134487. 14,15,11,12,11,14,14,14,14,14,15,16,13,15,12,16,
  134488. 12,
  134489. };
  134490. static float _vq_quantthresh__44u5__p4_0[] = {
  134491. -1.5, -0.5, 0.5, 1.5,
  134492. };
  134493. static long _vq_quantmap__44u5__p4_0[] = {
  134494. 3, 1, 0, 2, 4,
  134495. };
  134496. static encode_aux_threshmatch _vq_auxt__44u5__p4_0 = {
  134497. _vq_quantthresh__44u5__p4_0,
  134498. _vq_quantmap__44u5__p4_0,
  134499. 5,
  134500. 5
  134501. };
  134502. static static_codebook _44u5__p4_0 = {
  134503. 4, 625,
  134504. _vq_lengthlist__44u5__p4_0,
  134505. 1, -533725184, 1611661312, 3, 0,
  134506. _vq_quantlist__44u5__p4_0,
  134507. NULL,
  134508. &_vq_auxt__44u5__p4_0,
  134509. NULL,
  134510. 0
  134511. };
  134512. static long _vq_quantlist__44u5__p5_0[] = {
  134513. 4,
  134514. 3,
  134515. 5,
  134516. 2,
  134517. 6,
  134518. 1,
  134519. 7,
  134520. 0,
  134521. 8,
  134522. };
  134523. static long _vq_lengthlist__44u5__p5_0[] = {
  134524. 2, 3, 3, 6, 6, 8, 8,10,10, 4, 5, 5, 8, 7, 8, 8,
  134525. 11,10, 3, 5, 5, 7, 8, 8, 8,10,11, 6, 8, 7,10, 9,
  134526. 10,10,11,11, 6, 7, 8, 9, 9, 9,10,11,12, 8, 8, 8,
  134527. 10,10,11,11,13,12, 8, 8, 9, 9,10,11,11,12,13,10,
  134528. 11,10,12,11,13,12,14,14,10,10,11,11,12,12,13,14,
  134529. 14,
  134530. };
  134531. static float _vq_quantthresh__44u5__p5_0[] = {
  134532. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  134533. };
  134534. static long _vq_quantmap__44u5__p5_0[] = {
  134535. 7, 5, 3, 1, 0, 2, 4, 6,
  134536. 8,
  134537. };
  134538. static encode_aux_threshmatch _vq_auxt__44u5__p5_0 = {
  134539. _vq_quantthresh__44u5__p5_0,
  134540. _vq_quantmap__44u5__p5_0,
  134541. 9,
  134542. 9
  134543. };
  134544. static static_codebook _44u5__p5_0 = {
  134545. 2, 81,
  134546. _vq_lengthlist__44u5__p5_0,
  134547. 1, -531628032, 1611661312, 4, 0,
  134548. _vq_quantlist__44u5__p5_0,
  134549. NULL,
  134550. &_vq_auxt__44u5__p5_0,
  134551. NULL,
  134552. 0
  134553. };
  134554. static long _vq_quantlist__44u5__p6_0[] = {
  134555. 4,
  134556. 3,
  134557. 5,
  134558. 2,
  134559. 6,
  134560. 1,
  134561. 7,
  134562. 0,
  134563. 8,
  134564. };
  134565. static long _vq_lengthlist__44u5__p6_0[] = {
  134566. 3, 4, 4, 5, 5, 7, 7, 9, 9, 4, 5, 4, 6, 6, 7, 7,
  134567. 9, 9, 4, 4, 5, 6, 6, 7, 7, 9, 9, 5, 6, 6, 7, 7,
  134568. 8, 8,10,10, 6, 6, 6, 7, 7, 8, 8,10,10, 7, 7, 7,
  134569. 8, 8, 9, 9,11,10, 7, 7, 7, 8, 8, 9, 9,10,11, 9,
  134570. 9, 9,10,10,11,10,11,11, 9, 9, 9,10,10,11,10,11,
  134571. 11,
  134572. };
  134573. static float _vq_quantthresh__44u5__p6_0[] = {
  134574. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  134575. };
  134576. static long _vq_quantmap__44u5__p6_0[] = {
  134577. 7, 5, 3, 1, 0, 2, 4, 6,
  134578. 8,
  134579. };
  134580. static encode_aux_threshmatch _vq_auxt__44u5__p6_0 = {
  134581. _vq_quantthresh__44u5__p6_0,
  134582. _vq_quantmap__44u5__p6_0,
  134583. 9,
  134584. 9
  134585. };
  134586. static static_codebook _44u5__p6_0 = {
  134587. 2, 81,
  134588. _vq_lengthlist__44u5__p6_0,
  134589. 1, -531628032, 1611661312, 4, 0,
  134590. _vq_quantlist__44u5__p6_0,
  134591. NULL,
  134592. &_vq_auxt__44u5__p6_0,
  134593. NULL,
  134594. 0
  134595. };
  134596. static long _vq_quantlist__44u5__p7_0[] = {
  134597. 1,
  134598. 0,
  134599. 2,
  134600. };
  134601. static long _vq_lengthlist__44u5__p7_0[] = {
  134602. 1, 4, 4, 5, 7, 7, 5, 7, 7, 5, 9, 9, 8,11,10, 7,
  134603. 11,10, 5, 9, 9, 7,10,10, 8,10,11, 4, 9, 9, 9,12,
  134604. 12, 9,12,12, 8,12,12,11,12,12,10,12,13, 7,12,12,
  134605. 11,12,12,10,12,13, 4, 9, 9, 9,12,12, 9,12,12, 7,
  134606. 12,11,10,13,13,11,12,12, 7,12,12,10,13,13,11,12,
  134607. 12,
  134608. };
  134609. static float _vq_quantthresh__44u5__p7_0[] = {
  134610. -5.5, 5.5,
  134611. };
  134612. static long _vq_quantmap__44u5__p7_0[] = {
  134613. 1, 0, 2,
  134614. };
  134615. static encode_aux_threshmatch _vq_auxt__44u5__p7_0 = {
  134616. _vq_quantthresh__44u5__p7_0,
  134617. _vq_quantmap__44u5__p7_0,
  134618. 3,
  134619. 3
  134620. };
  134621. static static_codebook _44u5__p7_0 = {
  134622. 4, 81,
  134623. _vq_lengthlist__44u5__p7_0,
  134624. 1, -529137664, 1618345984, 2, 0,
  134625. _vq_quantlist__44u5__p7_0,
  134626. NULL,
  134627. &_vq_auxt__44u5__p7_0,
  134628. NULL,
  134629. 0
  134630. };
  134631. static long _vq_quantlist__44u5__p7_1[] = {
  134632. 5,
  134633. 4,
  134634. 6,
  134635. 3,
  134636. 7,
  134637. 2,
  134638. 8,
  134639. 1,
  134640. 9,
  134641. 0,
  134642. 10,
  134643. };
  134644. static long _vq_lengthlist__44u5__p7_1[] = {
  134645. 2, 4, 4, 6, 6, 7, 7, 8, 8, 8, 8, 4, 5, 5, 7, 7,
  134646. 8, 8, 9, 8, 8, 9, 4, 5, 5, 7, 7, 8, 8, 9, 9, 8,
  134647. 9, 6, 7, 7, 8, 8, 9, 8, 9, 9, 9, 9, 6, 7, 7, 8,
  134648. 8, 9, 9, 9, 9, 9, 9, 7, 8, 8, 9, 9, 9, 9, 9, 9,
  134649. 9, 9, 7, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 8, 9, 9,
  134650. 9, 9, 9, 9,10,10,10,10, 8, 9, 9, 9, 9, 9, 9,10,
  134651. 10,10,10, 8, 9, 9, 9, 9, 9, 9,10,10,10,10, 8, 9,
  134652. 9, 9, 9, 9, 9,10,10,10,10,
  134653. };
  134654. static float _vq_quantthresh__44u5__p7_1[] = {
  134655. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  134656. 3.5, 4.5,
  134657. };
  134658. static long _vq_quantmap__44u5__p7_1[] = {
  134659. 9, 7, 5, 3, 1, 0, 2, 4,
  134660. 6, 8, 10,
  134661. };
  134662. static encode_aux_threshmatch _vq_auxt__44u5__p7_1 = {
  134663. _vq_quantthresh__44u5__p7_1,
  134664. _vq_quantmap__44u5__p7_1,
  134665. 11,
  134666. 11
  134667. };
  134668. static static_codebook _44u5__p7_1 = {
  134669. 2, 121,
  134670. _vq_lengthlist__44u5__p7_1,
  134671. 1, -531365888, 1611661312, 4, 0,
  134672. _vq_quantlist__44u5__p7_1,
  134673. NULL,
  134674. &_vq_auxt__44u5__p7_1,
  134675. NULL,
  134676. 0
  134677. };
  134678. static long _vq_quantlist__44u5__p8_0[] = {
  134679. 5,
  134680. 4,
  134681. 6,
  134682. 3,
  134683. 7,
  134684. 2,
  134685. 8,
  134686. 1,
  134687. 9,
  134688. 0,
  134689. 10,
  134690. };
  134691. static long _vq_lengthlist__44u5__p8_0[] = {
  134692. 1, 4, 4, 6, 6, 8, 8, 9, 9,10,10, 4, 6, 6, 7, 7,
  134693. 9, 9,10,10,11,11, 4, 6, 6, 7, 7, 9, 9,10,10,11,
  134694. 11, 6, 8, 7, 9, 9,10,10,11,11,13,12, 6, 8, 8, 9,
  134695. 9,10,10,11,11,12,13, 8, 9, 9,10,10,12,12,13,12,
  134696. 14,13, 8, 9, 9,10,10,12,12,13,13,14,14, 9,11,11,
  134697. 12,12,13,13,14,14,15,14, 9,11,11,12,12,13,13,14,
  134698. 14,15,14,11,12,12,13,13,14,14,15,14,15,14,11,11,
  134699. 12,13,13,14,14,14,14,15,15,
  134700. };
  134701. static float _vq_quantthresh__44u5__p8_0[] = {
  134702. -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5, 27.5,
  134703. 38.5, 49.5,
  134704. };
  134705. static long _vq_quantmap__44u5__p8_0[] = {
  134706. 9, 7, 5, 3, 1, 0, 2, 4,
  134707. 6, 8, 10,
  134708. };
  134709. static encode_aux_threshmatch _vq_auxt__44u5__p8_0 = {
  134710. _vq_quantthresh__44u5__p8_0,
  134711. _vq_quantmap__44u5__p8_0,
  134712. 11,
  134713. 11
  134714. };
  134715. static static_codebook _44u5__p8_0 = {
  134716. 2, 121,
  134717. _vq_lengthlist__44u5__p8_0,
  134718. 1, -524582912, 1618345984, 4, 0,
  134719. _vq_quantlist__44u5__p8_0,
  134720. NULL,
  134721. &_vq_auxt__44u5__p8_0,
  134722. NULL,
  134723. 0
  134724. };
  134725. static long _vq_quantlist__44u5__p8_1[] = {
  134726. 5,
  134727. 4,
  134728. 6,
  134729. 3,
  134730. 7,
  134731. 2,
  134732. 8,
  134733. 1,
  134734. 9,
  134735. 0,
  134736. 10,
  134737. };
  134738. static long _vq_lengthlist__44u5__p8_1[] = {
  134739. 3, 5, 5, 6, 6, 7, 7, 7, 7, 7, 7, 5, 6, 5, 7, 6,
  134740. 7, 7, 8, 8, 8, 8, 5, 5, 5, 6, 6, 7, 7, 8, 8, 8,
  134741. 8, 6, 7, 6, 7, 7, 8, 8, 8, 8, 8, 8, 6, 6, 7, 7,
  134742. 7, 8, 8, 8, 8, 8, 8, 7, 7, 7, 8, 8, 8, 8, 8, 8,
  134743. 8, 8, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 7, 8, 8,
  134744. 8, 8, 8, 8, 8, 8, 8, 8, 7, 8, 8, 8, 8, 8, 8, 8,
  134745. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  134746. 8, 8, 8, 8, 8, 8, 8, 8, 8,
  134747. };
  134748. static float _vq_quantthresh__44u5__p8_1[] = {
  134749. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  134750. 3.5, 4.5,
  134751. };
  134752. static long _vq_quantmap__44u5__p8_1[] = {
  134753. 9, 7, 5, 3, 1, 0, 2, 4,
  134754. 6, 8, 10,
  134755. };
  134756. static encode_aux_threshmatch _vq_auxt__44u5__p8_1 = {
  134757. _vq_quantthresh__44u5__p8_1,
  134758. _vq_quantmap__44u5__p8_1,
  134759. 11,
  134760. 11
  134761. };
  134762. static static_codebook _44u5__p8_1 = {
  134763. 2, 121,
  134764. _vq_lengthlist__44u5__p8_1,
  134765. 1, -531365888, 1611661312, 4, 0,
  134766. _vq_quantlist__44u5__p8_1,
  134767. NULL,
  134768. &_vq_auxt__44u5__p8_1,
  134769. NULL,
  134770. 0
  134771. };
  134772. static long _vq_quantlist__44u5__p9_0[] = {
  134773. 6,
  134774. 5,
  134775. 7,
  134776. 4,
  134777. 8,
  134778. 3,
  134779. 9,
  134780. 2,
  134781. 10,
  134782. 1,
  134783. 11,
  134784. 0,
  134785. 12,
  134786. };
  134787. static long _vq_lengthlist__44u5__p9_0[] = {
  134788. 1, 3, 2,12,10,13,13,13,13,13,13,13,13, 4, 9, 9,
  134789. 13,13,13,13,13,13,13,13,13,13, 5,10, 9,13,13,13,
  134790. 13,13,13,13,13,13,13,12,13,13,13,13,13,13,13,13,
  134791. 13,13,13,13,11,13,13,13,13,13,13,13,13,13,13,13,
  134792. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  134793. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  134794. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  134795. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  134796. 13,13,13,13,13,13,13,13,13,13,13,13,13,12,12,12,
  134797. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  134798. 12,12,12,12,12,12,12,12,12,
  134799. };
  134800. static float _vq_quantthresh__44u5__p9_0[] = {
  134801. -1402.5, -1147.5, -892.5, -637.5, -382.5, -127.5, 127.5, 382.5,
  134802. 637.5, 892.5, 1147.5, 1402.5,
  134803. };
  134804. static long _vq_quantmap__44u5__p9_0[] = {
  134805. 11, 9, 7, 5, 3, 1, 0, 2,
  134806. 4, 6, 8, 10, 12,
  134807. };
  134808. static encode_aux_threshmatch _vq_auxt__44u5__p9_0 = {
  134809. _vq_quantthresh__44u5__p9_0,
  134810. _vq_quantmap__44u5__p9_0,
  134811. 13,
  134812. 13
  134813. };
  134814. static static_codebook _44u5__p9_0 = {
  134815. 2, 169,
  134816. _vq_lengthlist__44u5__p9_0,
  134817. 1, -514332672, 1627381760, 4, 0,
  134818. _vq_quantlist__44u5__p9_0,
  134819. NULL,
  134820. &_vq_auxt__44u5__p9_0,
  134821. NULL,
  134822. 0
  134823. };
  134824. static long _vq_quantlist__44u5__p9_1[] = {
  134825. 7,
  134826. 6,
  134827. 8,
  134828. 5,
  134829. 9,
  134830. 4,
  134831. 10,
  134832. 3,
  134833. 11,
  134834. 2,
  134835. 12,
  134836. 1,
  134837. 13,
  134838. 0,
  134839. 14,
  134840. };
  134841. static long _vq_lengthlist__44u5__p9_1[] = {
  134842. 1, 4, 4, 7, 7, 8, 8, 8, 7, 8, 7, 9, 8, 9, 9, 4,
  134843. 7, 6, 9, 8,10,10, 9, 8, 9, 9, 9, 9, 9, 8, 5, 6,
  134844. 6, 8, 9,10,10, 9, 9, 9,10,10,10,10,11, 7, 8, 8,
  134845. 10,10,11,11,10,10,11,11,11,12,11,11, 7, 8, 8,10,
  134846. 10,11,11,10,10,11,11,12,11,11,11, 8, 9, 9,11,11,
  134847. 12,12,11,11,12,11,12,12,12,12, 8, 9,10,11,11,12,
  134848. 12,11,11,12,12,12,12,12,12, 8, 9, 9,10,10,12,11,
  134849. 12,12,12,12,12,12,12,13, 8, 9, 9,11,11,11,11,12,
  134850. 12,12,12,13,12,13,13, 9,10,10,11,11,12,12,12,13,
  134851. 12,13,13,13,14,13, 9,10,10,11,11,12,12,12,13,13,
  134852. 12,13,13,14,13, 9,11,10,12,11,13,12,12,13,13,13,
  134853. 13,13,13,14, 9,10,10,12,12,12,12,12,13,13,13,13,
  134854. 13,14,14,10,11,11,12,12,12,13,13,13,14,14,13,14,
  134855. 14,14,10,11,11,12,12,12,12,13,12,13,14,13,14,14,
  134856. 14,
  134857. };
  134858. static float _vq_quantthresh__44u5__p9_1[] = {
  134859. -110.5, -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5,
  134860. 25.5, 42.5, 59.5, 76.5, 93.5, 110.5,
  134861. };
  134862. static long _vq_quantmap__44u5__p9_1[] = {
  134863. 13, 11, 9, 7, 5, 3, 1, 0,
  134864. 2, 4, 6, 8, 10, 12, 14,
  134865. };
  134866. static encode_aux_threshmatch _vq_auxt__44u5__p9_1 = {
  134867. _vq_quantthresh__44u5__p9_1,
  134868. _vq_quantmap__44u5__p9_1,
  134869. 15,
  134870. 15
  134871. };
  134872. static static_codebook _44u5__p9_1 = {
  134873. 2, 225,
  134874. _vq_lengthlist__44u5__p9_1,
  134875. 1, -522338304, 1620115456, 4, 0,
  134876. _vq_quantlist__44u5__p9_1,
  134877. NULL,
  134878. &_vq_auxt__44u5__p9_1,
  134879. NULL,
  134880. 0
  134881. };
  134882. static long _vq_quantlist__44u5__p9_2[] = {
  134883. 8,
  134884. 7,
  134885. 9,
  134886. 6,
  134887. 10,
  134888. 5,
  134889. 11,
  134890. 4,
  134891. 12,
  134892. 3,
  134893. 13,
  134894. 2,
  134895. 14,
  134896. 1,
  134897. 15,
  134898. 0,
  134899. 16,
  134900. };
  134901. static long _vq_lengthlist__44u5__p9_2[] = {
  134902. 2, 5, 5, 7, 7, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  134903. 9, 5, 6, 6, 7, 7, 8, 8, 9, 8, 9, 9, 9, 9, 9, 9,
  134904. 9, 9, 5, 6, 6, 7, 7, 8, 8, 9, 8, 9, 9, 9, 9, 9,
  134905. 9, 9, 9, 7, 7, 7, 8, 8, 9, 8, 9, 9, 9, 9, 9, 9,
  134906. 9, 9, 9, 9, 7, 7, 7, 8, 8, 9, 8, 9, 9, 9, 9, 9,
  134907. 9, 9, 9, 9, 9, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9,
  134908. 9,10, 9,10,10,10, 8, 8, 8, 9, 8, 9, 9, 9, 9, 9,
  134909. 9, 9,10, 9,10, 9,10, 8, 9, 9, 9, 9, 9, 9, 9, 9,
  134910. 9,10, 9,10,10,10,10,10, 8, 9, 9, 9, 9, 9, 9,10,
  134911. 9,10, 9,10,10,10,10,10,10, 9, 9, 9, 9, 9,10, 9,
  134912. 10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9, 9,
  134913. 9,10, 9,10, 9,10,10,10,10,10,10, 9, 9, 9, 9, 9,
  134914. 10,10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9,
  134915. 9, 9,10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9,
  134916. 9,10,10, 9,10,10,10,10,10,10,10,10,10,10, 9, 9,
  134917. 9, 9, 9,10,10,10,10,10,10,10,10,10,10,10,10, 9,
  134918. 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,10,10,10,
  134919. 9, 9, 9,10, 9,10,10,10,10,10,10,10,10,10,10,10,
  134920. 10,
  134921. };
  134922. static float _vq_quantthresh__44u5__p9_2[] = {
  134923. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  134924. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  134925. };
  134926. static long _vq_quantmap__44u5__p9_2[] = {
  134927. 15, 13, 11, 9, 7, 5, 3, 1,
  134928. 0, 2, 4, 6, 8, 10, 12, 14,
  134929. 16,
  134930. };
  134931. static encode_aux_threshmatch _vq_auxt__44u5__p9_2 = {
  134932. _vq_quantthresh__44u5__p9_2,
  134933. _vq_quantmap__44u5__p9_2,
  134934. 17,
  134935. 17
  134936. };
  134937. static static_codebook _44u5__p9_2 = {
  134938. 2, 289,
  134939. _vq_lengthlist__44u5__p9_2,
  134940. 1, -529530880, 1611661312, 5, 0,
  134941. _vq_quantlist__44u5__p9_2,
  134942. NULL,
  134943. &_vq_auxt__44u5__p9_2,
  134944. NULL,
  134945. 0
  134946. };
  134947. static long _huff_lengthlist__44u5__short[] = {
  134948. 4,10,17,13,17,13,17,17,17,17, 3, 6, 8, 9,11, 9,
  134949. 15,12,16,17, 6, 5, 5, 7, 7, 8,10,11,17,17, 7, 8,
  134950. 7, 9, 9,10,13,13,17,17, 8, 6, 5, 7, 4, 7, 5, 8,
  134951. 14,17, 9, 9, 8, 9, 7, 9, 8,10,16,17,12,10, 7, 8,
  134952. 4, 7, 4, 7,16,17,12,11, 9,10, 6, 9, 5, 7,14,17,
  134953. 14,13,10,15, 4, 8, 3, 5,14,17,17,14,11,15, 6,10,
  134954. 6, 8,15,17,
  134955. };
  134956. static static_codebook _huff_book__44u5__short = {
  134957. 2, 100,
  134958. _huff_lengthlist__44u5__short,
  134959. 0, 0, 0, 0, 0,
  134960. NULL,
  134961. NULL,
  134962. NULL,
  134963. NULL,
  134964. 0
  134965. };
  134966. static long _huff_lengthlist__44u6__long[] = {
  134967. 3, 9,14,13,14,13,16,12,13,14, 5, 4, 6, 6, 8, 9,
  134968. 11,10,12,15,10, 5, 5, 6, 6, 8,10,10,13,16,10, 6,
  134969. 6, 6, 6, 8, 9, 9,12,14,13, 7, 6, 6, 4, 6, 6, 7,
  134970. 11,14,10, 7, 7, 7, 6, 6, 6, 7,10,13,15,10, 9, 8,
  134971. 5, 6, 5, 6,10,14,10, 9, 8, 8, 6, 6, 5, 4, 6,11,
  134972. 11,11,12,11,10, 9, 9, 5, 5, 9,10,12,15,13,13,13,
  134973. 13, 8, 7, 7,
  134974. };
  134975. static static_codebook _huff_book__44u6__long = {
  134976. 2, 100,
  134977. _huff_lengthlist__44u6__long,
  134978. 0, 0, 0, 0, 0,
  134979. NULL,
  134980. NULL,
  134981. NULL,
  134982. NULL,
  134983. 0
  134984. };
  134985. static long _vq_quantlist__44u6__p1_0[] = {
  134986. 1,
  134987. 0,
  134988. 2,
  134989. };
  134990. static long _vq_lengthlist__44u6__p1_0[] = {
  134991. 1, 4, 4, 4, 8, 7, 5, 7, 7, 5, 8, 8, 8,10,10, 7,
  134992. 9,10, 5, 8, 8, 7,10, 9, 8,10,10, 5, 8, 8, 8,10,
  134993. 10, 8,10,10, 8,10,10,10,12,13,10,13,13, 7,10,10,
  134994. 10,13,11,10,13,13, 5, 8, 8, 8,11,10, 8,10,10, 7,
  134995. 10,10,10,13,13,10,11,13, 8,10,11,10,13,13,10,13,
  134996. 12,
  134997. };
  134998. static float _vq_quantthresh__44u6__p1_0[] = {
  134999. -0.5, 0.5,
  135000. };
  135001. static long _vq_quantmap__44u6__p1_0[] = {
  135002. 1, 0, 2,
  135003. };
  135004. static encode_aux_threshmatch _vq_auxt__44u6__p1_0 = {
  135005. _vq_quantthresh__44u6__p1_0,
  135006. _vq_quantmap__44u6__p1_0,
  135007. 3,
  135008. 3
  135009. };
  135010. static static_codebook _44u6__p1_0 = {
  135011. 4, 81,
  135012. _vq_lengthlist__44u6__p1_0,
  135013. 1, -535822336, 1611661312, 2, 0,
  135014. _vq_quantlist__44u6__p1_0,
  135015. NULL,
  135016. &_vq_auxt__44u6__p1_0,
  135017. NULL,
  135018. 0
  135019. };
  135020. static long _vq_quantlist__44u6__p2_0[] = {
  135021. 1,
  135022. 0,
  135023. 2,
  135024. };
  135025. static long _vq_lengthlist__44u6__p2_0[] = {
  135026. 3, 4, 4, 5, 6, 6, 5, 6, 6, 5, 6, 6, 6, 8, 8, 6,
  135027. 7, 8, 5, 6, 6, 6, 8, 7, 6, 8, 8, 5, 6, 6, 6, 8,
  135028. 8, 6, 8, 8, 6, 8, 8, 8, 9, 9, 8, 9, 9, 6, 7, 7,
  135029. 7, 9, 8, 8, 9, 9, 5, 6, 6, 6, 8, 7, 6, 8, 8, 6,
  135030. 8, 8, 8, 9, 9, 7, 8, 9, 6, 8, 8, 8, 9, 9, 8, 9,
  135031. 9,
  135032. };
  135033. static float _vq_quantthresh__44u6__p2_0[] = {
  135034. -0.5, 0.5,
  135035. };
  135036. static long _vq_quantmap__44u6__p2_0[] = {
  135037. 1, 0, 2,
  135038. };
  135039. static encode_aux_threshmatch _vq_auxt__44u6__p2_0 = {
  135040. _vq_quantthresh__44u6__p2_0,
  135041. _vq_quantmap__44u6__p2_0,
  135042. 3,
  135043. 3
  135044. };
  135045. static static_codebook _44u6__p2_0 = {
  135046. 4, 81,
  135047. _vq_lengthlist__44u6__p2_0,
  135048. 1, -535822336, 1611661312, 2, 0,
  135049. _vq_quantlist__44u6__p2_0,
  135050. NULL,
  135051. &_vq_auxt__44u6__p2_0,
  135052. NULL,
  135053. 0
  135054. };
  135055. static long _vq_quantlist__44u6__p3_0[] = {
  135056. 2,
  135057. 1,
  135058. 3,
  135059. 0,
  135060. 4,
  135061. };
  135062. static long _vq_lengthlist__44u6__p3_0[] = {
  135063. 2, 5, 4, 8, 8, 5, 7, 6, 9, 9, 5, 6, 7, 9, 9, 8,
  135064. 9, 9,13,12, 8, 9,10,12,13, 5, 7, 7,10, 9, 7, 9,
  135065. 9,11,11, 7, 8, 9,11,11,10,11,11,14,14, 9,10,11,
  135066. 13,14, 5, 7, 7, 9,10, 6, 9, 8,11,11, 7, 9, 9,11,
  135067. 11, 9,11,10,14,13,10,11,11,14,13, 8,10,10,13,13,
  135068. 10,11,11,15,15, 9,11,11,14,14,13,14,14,17,16,12,
  135069. 13,14,16,16, 8,10,10,13,14, 9,11,11,14,15,10,11,
  135070. 12,14,15,12,14,13,16,15,13,14,14,15,17, 5, 7, 7,
  135071. 10,10, 7, 9, 9,11,11, 7, 9, 9,11,11,10,12,11,14,
  135072. 14,10,11,11,14,14, 7, 9, 9,12,11, 9,11,11,13,13,
  135073. 9,11,11,13,13,11,13,13,14,15,11,12,13,15,16, 6,
  135074. 9, 9,11,12, 8,11,10,13,12, 9,11,11,13,14,11,13,
  135075. 12,16,14,11,13,13,15,16,10,12,11,14,15,11,13,13,
  135076. 15,17,11,13,13,17,16,15,15,16,17,16,14,15,16,18,
  135077. 0, 9,11,11,14,15,10,12,12,16,15,11,13,13,16,16,
  135078. 13,15,14,18,15,14,16,16, 0, 0, 5, 7, 7,10,10, 7,
  135079. 9, 9,11,11, 7, 9, 9,11,11,10,11,11,14,14,10,11,
  135080. 12,14,14, 6, 9, 9,11,11, 9,11,11,13,13, 8,10,11,
  135081. 12,13,11,13,13,16,15,11,12,13,14,16, 7, 9, 9,11,
  135082. 12, 9,11,11,13,13, 9,11,11,13,13,11,13,13,16,15,
  135083. 11,13,12,15,15, 9,11,11,15,14,11,13,13,17,16,10,
  135084. 12,13,15,16,14,16,16, 0,18,14,14,15,15,17,10,11,
  135085. 12,15,15,11,13,13,16,16,11,13,13,16,16,14,16,16,
  135086. 19,17,14,15,15,17,17, 8,10,10,14,14,10,12,11,15,
  135087. 15,10,11,12,16,15,14,15,15,18,20,13,14,16,17,18,
  135088. 9,11,11,15,16,11,13,13,17,17,11,13,13,17,16,15,
  135089. 16,16, 0, 0,15,16,16, 0, 0, 9,11,11,15,15,10,13,
  135090. 12,17,15,11,13,13,17,16,15,17,15,20,19,15,16,16,
  135091. 19, 0,13,15,14, 0,17,14,15,16, 0,20,15,16,16, 0,
  135092. 19,17,18, 0, 0, 0,16,17,18, 0, 0,12,14,14,19,18,
  135093. 13,15,14, 0,17,14,15,16,19,19,16,18,16, 0,19,19,
  135094. 20,17,20, 0, 8,10,10,13,14,10,11,11,15,15,10,12,
  135095. 12,15,16,14,15,14,19,16,14,15,15, 0,18, 9,11,11,
  135096. 16,15,11,13,13, 0,16,11,12,13,16,17,14,16,17, 0,
  135097. 19,15,16,16,18, 0, 9,11,11,15,16,11,13,13,16,16,
  135098. 11,14,13,18,17,15,16,16,18,20,15,17,19, 0, 0,12,
  135099. 14,14,17,17,14,16,15, 0, 0,13,14,15,19, 0,16,18,
  135100. 20, 0, 0,16,16,18,18, 0,12,14,14,17,20,14,16,16,
  135101. 19, 0,14,16,14, 0,20,16,20,17, 0, 0,17, 0,15, 0,
  135102. 19,
  135103. };
  135104. static float _vq_quantthresh__44u6__p3_0[] = {
  135105. -1.5, -0.5, 0.5, 1.5,
  135106. };
  135107. static long _vq_quantmap__44u6__p3_0[] = {
  135108. 3, 1, 0, 2, 4,
  135109. };
  135110. static encode_aux_threshmatch _vq_auxt__44u6__p3_0 = {
  135111. _vq_quantthresh__44u6__p3_0,
  135112. _vq_quantmap__44u6__p3_0,
  135113. 5,
  135114. 5
  135115. };
  135116. static static_codebook _44u6__p3_0 = {
  135117. 4, 625,
  135118. _vq_lengthlist__44u6__p3_0,
  135119. 1, -533725184, 1611661312, 3, 0,
  135120. _vq_quantlist__44u6__p3_0,
  135121. NULL,
  135122. &_vq_auxt__44u6__p3_0,
  135123. NULL,
  135124. 0
  135125. };
  135126. static long _vq_quantlist__44u6__p4_0[] = {
  135127. 2,
  135128. 1,
  135129. 3,
  135130. 0,
  135131. 4,
  135132. };
  135133. static long _vq_lengthlist__44u6__p4_0[] = {
  135134. 4, 5, 5, 8, 8, 6, 7, 6, 9, 9, 6, 6, 7, 9, 9, 8,
  135135. 9, 9,11,11, 8, 9, 9,11,11, 6, 7, 7, 9, 9, 7, 8,
  135136. 8,10,10, 7, 7, 8, 9,10, 9,10,10,11,11, 9, 9,10,
  135137. 11,12, 6, 7, 7, 9, 9, 7, 8, 7,10, 9, 7, 8, 8,10,
  135138. 10, 9,10, 9,12,11, 9,10,10,12,11, 8, 9, 9,11,11,
  135139. 9,10,10,12,12, 9,10,10,12,12,11,12,12,14,13,11,
  135140. 11,12,13,13, 8, 9, 9,11,11, 9,10,10,12,12, 9,10,
  135141. 10,12,12,11,12,11,13,12,11,12,12,13,13, 5, 7, 7,
  135142. 9, 9, 7, 8, 7,10,10, 7, 7, 8,10,10, 9,10,10,12,
  135143. 11, 9,10,10,11,12, 7, 8, 8,10,10, 8, 8, 9,11,11,
  135144. 8, 9, 9,11,11,10,10,11,12,13,10,10,11,12,12, 6,
  135145. 7, 7,10,10, 7, 9, 8,11,10, 8, 8, 9,10,11,10,11,
  135146. 10,13,11,10,11,11,12,12, 9,10,10,12,12,10,10,11,
  135147. 13,13,10,11,11,12,13,12,12,12,13,14,12,12,13,14,
  135148. 14, 9,10,10,12,12, 9,10,10,13,12,10,11,11,13,13,
  135149. 11,12,11,14,12,12,13,13,14,14, 6, 7, 7, 9, 9, 7,
  135150. 8, 7,10,10, 7, 8, 8,10,10, 9,10,10,12,11, 9,10,
  135151. 10,11,12, 6, 7, 7,10,10, 8, 9, 8,11,10, 7, 8, 9,
  135152. 10,11,10,11,11,12,12,10,10,11,11,13, 7, 8, 8,10,
  135153. 10, 8, 9, 9,11,11, 8, 9, 8,11,11,10,11,10,13,12,
  135154. 10,11,11,13,12, 9,10,10,12,12,10,11,11,13,12, 9,
  135155. 10,10,12,13,12,13,12,14,14,11,11,12,12,14, 9,10,
  135156. 10,12,12,10,11,11,13,13,10,11,10,13,12,12,12,12,
  135157. 14,14,12,13,12,14,13, 8, 9, 9,11,11, 9,10,10,12,
  135158. 12, 9,10,10,12,12,11,12,12,14,13,11,12,12,13,14,
  135159. 9,10,10,12,12,10,11,11,13,13,10,11,11,13,13,12,
  135160. 12,13,14,15,12,12,13,14,14, 9,10,10,12,12, 9,11,
  135161. 10,13,12,10,10,11,12,13,12,13,12,14,13,12,12,13,
  135162. 14,15,11,12,12,14,13,11,12,12,14,14,12,13,13,14,
  135163. 14,13,13,14,14,16,13,14,14,15,15,11,12,11,13,13,
  135164. 11,12,11,14,13,12,12,13,14,15,12,14,12,15,12,13,
  135165. 14,15,15,16, 8, 9, 9,11,11, 9,10,10,12,12, 9,10,
  135166. 10,12,12,11,12,12,14,13,11,12,12,13,13, 9,10,10,
  135167. 12,12,10,11,10,13,12, 9,10,11,12,13,12,13,12,14,
  135168. 14,12,12,13,13,14, 9,10,10,12,12,10,11,11,13,13,
  135169. 10,11,11,13,13,12,13,12,14,14,12,13,13,14,14,11,
  135170. 11,11,13,13,12,13,12,14,14,11,11,12,13,14,14,14,
  135171. 14,16,15,12,12,14,12,15,11,12,12,13,14,12,13,13,
  135172. 14,15,11,12,12,14,14,13,14,14,16,16,13,14,13,16,
  135173. 13,
  135174. };
  135175. static float _vq_quantthresh__44u6__p4_0[] = {
  135176. -1.5, -0.5, 0.5, 1.5,
  135177. };
  135178. static long _vq_quantmap__44u6__p4_0[] = {
  135179. 3, 1, 0, 2, 4,
  135180. };
  135181. static encode_aux_threshmatch _vq_auxt__44u6__p4_0 = {
  135182. _vq_quantthresh__44u6__p4_0,
  135183. _vq_quantmap__44u6__p4_0,
  135184. 5,
  135185. 5
  135186. };
  135187. static static_codebook _44u6__p4_0 = {
  135188. 4, 625,
  135189. _vq_lengthlist__44u6__p4_0,
  135190. 1, -533725184, 1611661312, 3, 0,
  135191. _vq_quantlist__44u6__p4_0,
  135192. NULL,
  135193. &_vq_auxt__44u6__p4_0,
  135194. NULL,
  135195. 0
  135196. };
  135197. static long _vq_quantlist__44u6__p5_0[] = {
  135198. 4,
  135199. 3,
  135200. 5,
  135201. 2,
  135202. 6,
  135203. 1,
  135204. 7,
  135205. 0,
  135206. 8,
  135207. };
  135208. static long _vq_lengthlist__44u6__p5_0[] = {
  135209. 2, 3, 3, 6, 6, 8, 8,10,10, 4, 5, 5, 8, 7, 8, 8,
  135210. 11,11, 3, 5, 5, 7, 8, 8, 8,11,11, 6, 8, 7, 9, 9,
  135211. 10, 9,12,11, 6, 7, 8, 9, 9, 9,10,11,12, 8, 8, 8,
  135212. 10, 9,12,11,13,13, 8, 8, 9, 9,10,11,12,13,13,10,
  135213. 11,11,12,12,13,13,14,14,10,10,11,11,12,13,13,14,
  135214. 14,
  135215. };
  135216. static float _vq_quantthresh__44u6__p5_0[] = {
  135217. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  135218. };
  135219. static long _vq_quantmap__44u6__p5_0[] = {
  135220. 7, 5, 3, 1, 0, 2, 4, 6,
  135221. 8,
  135222. };
  135223. static encode_aux_threshmatch _vq_auxt__44u6__p5_0 = {
  135224. _vq_quantthresh__44u6__p5_0,
  135225. _vq_quantmap__44u6__p5_0,
  135226. 9,
  135227. 9
  135228. };
  135229. static static_codebook _44u6__p5_0 = {
  135230. 2, 81,
  135231. _vq_lengthlist__44u6__p5_0,
  135232. 1, -531628032, 1611661312, 4, 0,
  135233. _vq_quantlist__44u6__p5_0,
  135234. NULL,
  135235. &_vq_auxt__44u6__p5_0,
  135236. NULL,
  135237. 0
  135238. };
  135239. static long _vq_quantlist__44u6__p6_0[] = {
  135240. 4,
  135241. 3,
  135242. 5,
  135243. 2,
  135244. 6,
  135245. 1,
  135246. 7,
  135247. 0,
  135248. 8,
  135249. };
  135250. static long _vq_lengthlist__44u6__p6_0[] = {
  135251. 3, 4, 4, 5, 5, 7, 7, 9, 9, 4, 5, 4, 6, 6, 7, 7,
  135252. 9, 9, 4, 4, 5, 6, 6, 7, 8, 9, 9, 5, 6, 6, 7, 7,
  135253. 8, 8,10,10, 5, 6, 6, 7, 7, 8, 8,10,10, 7, 8, 7,
  135254. 8, 8,10, 9,11,11, 7, 7, 8, 8, 8, 9,10,10,11, 9,
  135255. 9, 9,10,10,11,11,12,11, 9, 9, 9,10,10,11,11,11,
  135256. 12,
  135257. };
  135258. static float _vq_quantthresh__44u6__p6_0[] = {
  135259. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  135260. };
  135261. static long _vq_quantmap__44u6__p6_0[] = {
  135262. 7, 5, 3, 1, 0, 2, 4, 6,
  135263. 8,
  135264. };
  135265. static encode_aux_threshmatch _vq_auxt__44u6__p6_0 = {
  135266. _vq_quantthresh__44u6__p6_0,
  135267. _vq_quantmap__44u6__p6_0,
  135268. 9,
  135269. 9
  135270. };
  135271. static static_codebook _44u6__p6_0 = {
  135272. 2, 81,
  135273. _vq_lengthlist__44u6__p6_0,
  135274. 1, -531628032, 1611661312, 4, 0,
  135275. _vq_quantlist__44u6__p6_0,
  135276. NULL,
  135277. &_vq_auxt__44u6__p6_0,
  135278. NULL,
  135279. 0
  135280. };
  135281. static long _vq_quantlist__44u6__p7_0[] = {
  135282. 1,
  135283. 0,
  135284. 2,
  135285. };
  135286. static long _vq_lengthlist__44u6__p7_0[] = {
  135287. 1, 4, 4, 5, 7, 7, 5, 7, 7, 5, 9, 8, 7,10,10, 8,
  135288. 10,10, 5, 8, 9, 7,10,10, 7,10, 9, 4, 8, 8, 9,11,
  135289. 11, 8,11,11, 7,11,11,10,10,13,10,13,13, 7,11,11,
  135290. 10,13,12,10,13,13, 5, 9, 8, 8,11,11, 9,11,11, 7,
  135291. 11,11,10,13,13,10,12,13, 7,11,11,10,13,13, 9,13,
  135292. 10,
  135293. };
  135294. static float _vq_quantthresh__44u6__p7_0[] = {
  135295. -5.5, 5.5,
  135296. };
  135297. static long _vq_quantmap__44u6__p7_0[] = {
  135298. 1, 0, 2,
  135299. };
  135300. static encode_aux_threshmatch _vq_auxt__44u6__p7_0 = {
  135301. _vq_quantthresh__44u6__p7_0,
  135302. _vq_quantmap__44u6__p7_0,
  135303. 3,
  135304. 3
  135305. };
  135306. static static_codebook _44u6__p7_0 = {
  135307. 4, 81,
  135308. _vq_lengthlist__44u6__p7_0,
  135309. 1, -529137664, 1618345984, 2, 0,
  135310. _vq_quantlist__44u6__p7_0,
  135311. NULL,
  135312. &_vq_auxt__44u6__p7_0,
  135313. NULL,
  135314. 0
  135315. };
  135316. static long _vq_quantlist__44u6__p7_1[] = {
  135317. 5,
  135318. 4,
  135319. 6,
  135320. 3,
  135321. 7,
  135322. 2,
  135323. 8,
  135324. 1,
  135325. 9,
  135326. 0,
  135327. 10,
  135328. };
  135329. static long _vq_lengthlist__44u6__p7_1[] = {
  135330. 3, 4, 4, 6, 6, 7, 7, 8, 8, 8, 8, 4, 5, 5, 7, 6,
  135331. 8, 8, 8, 8, 8, 8, 4, 5, 5, 6, 7, 8, 8, 8, 8, 8,
  135332. 8, 6, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 6, 7, 7, 7,
  135333. 7, 8, 8, 8, 8, 8, 8, 7, 8, 8, 8, 8, 8, 8, 9, 9,
  135334. 9, 9, 7, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 8, 8, 8,
  135335. 8, 8, 9, 9, 9, 9, 9, 9, 8, 8, 8, 8, 8, 9, 9, 9,
  135336. 9, 9, 9, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 8, 8,
  135337. 8, 8, 8, 9, 9, 9, 9, 9, 9,
  135338. };
  135339. static float _vq_quantthresh__44u6__p7_1[] = {
  135340. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  135341. 3.5, 4.5,
  135342. };
  135343. static long _vq_quantmap__44u6__p7_1[] = {
  135344. 9, 7, 5, 3, 1, 0, 2, 4,
  135345. 6, 8, 10,
  135346. };
  135347. static encode_aux_threshmatch _vq_auxt__44u6__p7_1 = {
  135348. _vq_quantthresh__44u6__p7_1,
  135349. _vq_quantmap__44u6__p7_1,
  135350. 11,
  135351. 11
  135352. };
  135353. static static_codebook _44u6__p7_1 = {
  135354. 2, 121,
  135355. _vq_lengthlist__44u6__p7_1,
  135356. 1, -531365888, 1611661312, 4, 0,
  135357. _vq_quantlist__44u6__p7_1,
  135358. NULL,
  135359. &_vq_auxt__44u6__p7_1,
  135360. NULL,
  135361. 0
  135362. };
  135363. static long _vq_quantlist__44u6__p8_0[] = {
  135364. 5,
  135365. 4,
  135366. 6,
  135367. 3,
  135368. 7,
  135369. 2,
  135370. 8,
  135371. 1,
  135372. 9,
  135373. 0,
  135374. 10,
  135375. };
  135376. static long _vq_lengthlist__44u6__p8_0[] = {
  135377. 1, 4, 4, 6, 6, 8, 8, 9, 9,10,10, 4, 6, 6, 7, 7,
  135378. 9, 9,10,10,11,11, 4, 6, 6, 7, 7, 9, 9,10,10,11,
  135379. 11, 6, 8, 8, 9, 9,10,10,11,11,12,12, 6, 8, 8, 9,
  135380. 9,10,10,11,11,12,12, 8, 9, 9,10,10,11,11,12,12,
  135381. 13,13, 8, 9, 9,10,10,11,11,12,12,13,13,10,10,10,
  135382. 11,11,13,13,13,13,15,14, 9,10,10,12,11,12,13,13,
  135383. 13,14,15,11,12,12,13,13,13,13,15,14,15,15,11,11,
  135384. 12,13,13,14,14,14,15,15,15,
  135385. };
  135386. static float _vq_quantthresh__44u6__p8_0[] = {
  135387. -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5, 27.5,
  135388. 38.5, 49.5,
  135389. };
  135390. static long _vq_quantmap__44u6__p8_0[] = {
  135391. 9, 7, 5, 3, 1, 0, 2, 4,
  135392. 6, 8, 10,
  135393. };
  135394. static encode_aux_threshmatch _vq_auxt__44u6__p8_0 = {
  135395. _vq_quantthresh__44u6__p8_0,
  135396. _vq_quantmap__44u6__p8_0,
  135397. 11,
  135398. 11
  135399. };
  135400. static static_codebook _44u6__p8_0 = {
  135401. 2, 121,
  135402. _vq_lengthlist__44u6__p8_0,
  135403. 1, -524582912, 1618345984, 4, 0,
  135404. _vq_quantlist__44u6__p8_0,
  135405. NULL,
  135406. &_vq_auxt__44u6__p8_0,
  135407. NULL,
  135408. 0
  135409. };
  135410. static long _vq_quantlist__44u6__p8_1[] = {
  135411. 5,
  135412. 4,
  135413. 6,
  135414. 3,
  135415. 7,
  135416. 2,
  135417. 8,
  135418. 1,
  135419. 9,
  135420. 0,
  135421. 10,
  135422. };
  135423. static long _vq_lengthlist__44u6__p8_1[] = {
  135424. 3, 5, 5, 6, 6, 7, 7, 7, 7, 7, 7, 5, 6, 5, 7, 7,
  135425. 7, 7, 8, 7, 8, 8, 5, 5, 6, 6, 7, 7, 7, 7, 7, 8,
  135426. 8, 6, 7, 7, 7, 7, 8, 7, 8, 8, 8, 8, 6, 6, 7, 7,
  135427. 7, 7, 8, 8, 8, 8, 8, 7, 7, 7, 8, 8, 8, 8, 8, 8,
  135428. 8, 8, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 7, 7, 7,
  135429. 8, 8, 8, 8, 8, 8, 8, 8, 7, 8, 8, 8, 8, 8, 8, 8,
  135430. 8, 8, 8, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 7, 8,
  135431. 8, 8, 8, 8, 8, 8, 8, 8, 8,
  135432. };
  135433. static float _vq_quantthresh__44u6__p8_1[] = {
  135434. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  135435. 3.5, 4.5,
  135436. };
  135437. static long _vq_quantmap__44u6__p8_1[] = {
  135438. 9, 7, 5, 3, 1, 0, 2, 4,
  135439. 6, 8, 10,
  135440. };
  135441. static encode_aux_threshmatch _vq_auxt__44u6__p8_1 = {
  135442. _vq_quantthresh__44u6__p8_1,
  135443. _vq_quantmap__44u6__p8_1,
  135444. 11,
  135445. 11
  135446. };
  135447. static static_codebook _44u6__p8_1 = {
  135448. 2, 121,
  135449. _vq_lengthlist__44u6__p8_1,
  135450. 1, -531365888, 1611661312, 4, 0,
  135451. _vq_quantlist__44u6__p8_1,
  135452. NULL,
  135453. &_vq_auxt__44u6__p8_1,
  135454. NULL,
  135455. 0
  135456. };
  135457. static long _vq_quantlist__44u6__p9_0[] = {
  135458. 7,
  135459. 6,
  135460. 8,
  135461. 5,
  135462. 9,
  135463. 4,
  135464. 10,
  135465. 3,
  135466. 11,
  135467. 2,
  135468. 12,
  135469. 1,
  135470. 13,
  135471. 0,
  135472. 14,
  135473. };
  135474. static long _vq_lengthlist__44u6__p9_0[] = {
  135475. 1, 3, 2, 9, 8,15,15,15,15,15,15,15,15,15,15, 4,
  135476. 8, 9,13,14,14,14,14,14,14,14,14,14,14,14, 5, 8,
  135477. 9,14,14,14,14,14,14,14,14,14,14,14,14,11,14,14,
  135478. 14,14,14,14,14,14,14,14,14,14,14,14,11,14,14,14,
  135479. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  135480. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  135481. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  135482. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  135483. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  135484. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  135485. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  135486. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  135487. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  135488. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  135489. 14,
  135490. };
  135491. static float _vq_quantthresh__44u6__p9_0[] = {
  135492. -1657.5, -1402.5, -1147.5, -892.5, -637.5, -382.5, -127.5, 127.5,
  135493. 382.5, 637.5, 892.5, 1147.5, 1402.5, 1657.5,
  135494. };
  135495. static long _vq_quantmap__44u6__p9_0[] = {
  135496. 13, 11, 9, 7, 5, 3, 1, 0,
  135497. 2, 4, 6, 8, 10, 12, 14,
  135498. };
  135499. static encode_aux_threshmatch _vq_auxt__44u6__p9_0 = {
  135500. _vq_quantthresh__44u6__p9_0,
  135501. _vq_quantmap__44u6__p9_0,
  135502. 15,
  135503. 15
  135504. };
  135505. static static_codebook _44u6__p9_0 = {
  135506. 2, 225,
  135507. _vq_lengthlist__44u6__p9_0,
  135508. 1, -514071552, 1627381760, 4, 0,
  135509. _vq_quantlist__44u6__p9_0,
  135510. NULL,
  135511. &_vq_auxt__44u6__p9_0,
  135512. NULL,
  135513. 0
  135514. };
  135515. static long _vq_quantlist__44u6__p9_1[] = {
  135516. 7,
  135517. 6,
  135518. 8,
  135519. 5,
  135520. 9,
  135521. 4,
  135522. 10,
  135523. 3,
  135524. 11,
  135525. 2,
  135526. 12,
  135527. 1,
  135528. 13,
  135529. 0,
  135530. 14,
  135531. };
  135532. static long _vq_lengthlist__44u6__p9_1[] = {
  135533. 1, 4, 4, 7, 7, 8, 9, 8, 8, 9, 8, 9, 8, 9, 9, 4,
  135534. 7, 6, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 4, 7,
  135535. 6, 9, 9,10,10, 9, 9,10,10,10,10,11,11, 7, 9, 8,
  135536. 10,10,11,11,10,10,11,11,11,11,11,11, 7, 8, 9,10,
  135537. 10,11,11,10,10,11,11,11,11,11,12, 8,10,10,11,11,
  135538. 12,12,11,11,12,12,12,12,13,12, 8,10,10,11,11,12,
  135539. 11,11,11,11,12,12,12,12,13, 8, 9, 9,11,10,11,11,
  135540. 12,12,12,12,13,12,13,12, 8, 9, 9,11,11,11,11,12,
  135541. 12,12,12,12,13,13,13, 9,10,10,11,12,12,12,12,12,
  135542. 13,13,13,13,13,13, 9,10,10,11,11,12,12,12,12,13,
  135543. 13,13,13,14,13,10,10,10,12,11,12,12,13,13,13,13,
  135544. 13,13,13,13,10,10,11,11,11,12,12,13,13,13,13,13,
  135545. 13,13,13,10,11,11,12,12,13,12,12,13,13,13,13,13,
  135546. 13,14,10,11,11,12,12,13,12,13,13,13,14,13,13,14,
  135547. 13,
  135548. };
  135549. static float _vq_quantthresh__44u6__p9_1[] = {
  135550. -110.5, -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5,
  135551. 25.5, 42.5, 59.5, 76.5, 93.5, 110.5,
  135552. };
  135553. static long _vq_quantmap__44u6__p9_1[] = {
  135554. 13, 11, 9, 7, 5, 3, 1, 0,
  135555. 2, 4, 6, 8, 10, 12, 14,
  135556. };
  135557. static encode_aux_threshmatch _vq_auxt__44u6__p9_1 = {
  135558. _vq_quantthresh__44u6__p9_1,
  135559. _vq_quantmap__44u6__p9_1,
  135560. 15,
  135561. 15
  135562. };
  135563. static static_codebook _44u6__p9_1 = {
  135564. 2, 225,
  135565. _vq_lengthlist__44u6__p9_1,
  135566. 1, -522338304, 1620115456, 4, 0,
  135567. _vq_quantlist__44u6__p9_1,
  135568. NULL,
  135569. &_vq_auxt__44u6__p9_1,
  135570. NULL,
  135571. 0
  135572. };
  135573. static long _vq_quantlist__44u6__p9_2[] = {
  135574. 8,
  135575. 7,
  135576. 9,
  135577. 6,
  135578. 10,
  135579. 5,
  135580. 11,
  135581. 4,
  135582. 12,
  135583. 3,
  135584. 13,
  135585. 2,
  135586. 14,
  135587. 1,
  135588. 15,
  135589. 0,
  135590. 16,
  135591. };
  135592. static long _vq_lengthlist__44u6__p9_2[] = {
  135593. 3, 5, 5, 7, 7, 8, 8, 8, 8, 8, 8, 9, 8, 8, 9, 9,
  135594. 9, 5, 6, 6, 7, 7, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9,
  135595. 9, 9, 5, 6, 6, 7, 7, 8, 8, 8, 8, 8, 8, 9, 9, 9,
  135596. 9, 9, 9, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  135597. 9, 9, 9, 9, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  135598. 9, 9, 9, 9, 9, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  135599. 9, 9, 9, 9, 9, 9, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  135600. 9, 9, 9, 9, 9, 9, 9, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  135601. 9, 9, 9, 9, 9, 9, 9, 9, 8, 8, 8, 9, 9, 9, 9, 9,
  135602. 9, 9, 9, 9, 9, 9, 9, 9, 9, 8, 9, 9, 9, 9, 9, 9,
  135603. 9, 9, 9, 9, 9, 9, 9, 9,10, 9, 8, 9, 9, 9, 9, 9,
  135604. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  135605. 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10, 9, 9, 9, 9, 9,
  135606. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 9, 9, 9,
  135607. 9, 9, 9, 9, 9, 9, 9, 9,10, 9, 9, 9,10, 9, 9, 9,
  135608. 9, 9, 9, 9, 9, 9, 9,10, 9, 9, 9,10, 9, 9,10, 9,
  135609. 9, 9, 9, 9, 9, 9, 9, 9,10,10,10, 9,10, 9,10,10,
  135610. 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10, 9,10,10, 9, 9,
  135611. 10,
  135612. };
  135613. static float _vq_quantthresh__44u6__p9_2[] = {
  135614. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  135615. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  135616. };
  135617. static long _vq_quantmap__44u6__p9_2[] = {
  135618. 15, 13, 11, 9, 7, 5, 3, 1,
  135619. 0, 2, 4, 6, 8, 10, 12, 14,
  135620. 16,
  135621. };
  135622. static encode_aux_threshmatch _vq_auxt__44u6__p9_2 = {
  135623. _vq_quantthresh__44u6__p9_2,
  135624. _vq_quantmap__44u6__p9_2,
  135625. 17,
  135626. 17
  135627. };
  135628. static static_codebook _44u6__p9_2 = {
  135629. 2, 289,
  135630. _vq_lengthlist__44u6__p9_2,
  135631. 1, -529530880, 1611661312, 5, 0,
  135632. _vq_quantlist__44u6__p9_2,
  135633. NULL,
  135634. &_vq_auxt__44u6__p9_2,
  135635. NULL,
  135636. 0
  135637. };
  135638. static long _huff_lengthlist__44u6__short[] = {
  135639. 4,11,16,13,17,13,17,16,17,17, 4, 7, 9, 9,13,10,
  135640. 16,12,16,17, 7, 6, 5, 7, 8, 9,12,12,16,17, 6, 9,
  135641. 7, 9,10,10,15,15,17,17, 6, 7, 5, 7, 5, 7, 7,10,
  135642. 16,17, 7, 9, 8, 9, 8,10,11,11,15,17, 7, 7, 7, 8,
  135643. 5, 8, 8, 9,15,17, 8, 7, 9, 9, 7, 8, 7, 2, 7,15,
  135644. 14,13,13,15, 5,10, 4, 3, 6,17,17,15,13,17, 7,11,
  135645. 7, 6, 9,16,
  135646. };
  135647. static static_codebook _huff_book__44u6__short = {
  135648. 2, 100,
  135649. _huff_lengthlist__44u6__short,
  135650. 0, 0, 0, 0, 0,
  135651. NULL,
  135652. NULL,
  135653. NULL,
  135654. NULL,
  135655. 0
  135656. };
  135657. static long _huff_lengthlist__44u7__long[] = {
  135658. 3, 9,14,13,15,14,16,13,13,14, 5, 5, 7, 7, 8, 9,
  135659. 11,10,12,15,10, 6, 5, 6, 6, 9,10,10,13,16,10, 6,
  135660. 6, 6, 6, 8, 9, 9,12,15,14, 7, 6, 6, 5, 6, 6, 8,
  135661. 12,15,10, 8, 7, 7, 6, 7, 7, 7,11,13,14,10, 9, 8,
  135662. 5, 6, 4, 5, 9,12,10, 9, 9, 8, 6, 6, 5, 3, 6,11,
  135663. 12,11,12,12,10, 9, 8, 5, 5, 8,10,11,15,13,13,13,
  135664. 12, 8, 6, 7,
  135665. };
  135666. static static_codebook _huff_book__44u7__long = {
  135667. 2, 100,
  135668. _huff_lengthlist__44u7__long,
  135669. 0, 0, 0, 0, 0,
  135670. NULL,
  135671. NULL,
  135672. NULL,
  135673. NULL,
  135674. 0
  135675. };
  135676. static long _vq_quantlist__44u7__p1_0[] = {
  135677. 1,
  135678. 0,
  135679. 2,
  135680. };
  135681. static long _vq_lengthlist__44u7__p1_0[] = {
  135682. 1, 4, 4, 4, 7, 7, 5, 7, 7, 5, 8, 8, 8,10,10, 7,
  135683. 10,10, 5, 8, 8, 7,10,10, 8,10,10, 5, 8, 8, 8,11,
  135684. 10, 8,10,10, 8,10,10,10,12,13,10,13,13, 7,10,10,
  135685. 10,13,12,10,13,13, 5, 8, 8, 8,11,10, 8,10,11, 7,
  135686. 10,10,10,13,13,10,12,13, 8,11,11,10,13,13,10,13,
  135687. 12,
  135688. };
  135689. static float _vq_quantthresh__44u7__p1_0[] = {
  135690. -0.5, 0.5,
  135691. };
  135692. static long _vq_quantmap__44u7__p1_0[] = {
  135693. 1, 0, 2,
  135694. };
  135695. static encode_aux_threshmatch _vq_auxt__44u7__p1_0 = {
  135696. _vq_quantthresh__44u7__p1_0,
  135697. _vq_quantmap__44u7__p1_0,
  135698. 3,
  135699. 3
  135700. };
  135701. static static_codebook _44u7__p1_0 = {
  135702. 4, 81,
  135703. _vq_lengthlist__44u7__p1_0,
  135704. 1, -535822336, 1611661312, 2, 0,
  135705. _vq_quantlist__44u7__p1_0,
  135706. NULL,
  135707. &_vq_auxt__44u7__p1_0,
  135708. NULL,
  135709. 0
  135710. };
  135711. static long _vq_quantlist__44u7__p2_0[] = {
  135712. 1,
  135713. 0,
  135714. 2,
  135715. };
  135716. static long _vq_lengthlist__44u7__p2_0[] = {
  135717. 3, 4, 4, 5, 6, 6, 5, 6, 6, 5, 6, 6, 6, 8, 8, 6,
  135718. 7, 8, 5, 6, 6, 6, 8, 7, 6, 8, 8, 5, 6, 6, 6, 8,
  135719. 7, 6, 8, 8, 6, 8, 8, 8, 9, 9, 8, 9, 9, 6, 8, 7,
  135720. 7, 9, 8, 8, 9, 9, 5, 6, 6, 6, 8, 7, 6, 8, 8, 6,
  135721. 8, 8, 8, 9, 9, 7, 8, 9, 6, 8, 8, 8, 9, 9, 8, 9,
  135722. 9,
  135723. };
  135724. static float _vq_quantthresh__44u7__p2_0[] = {
  135725. -0.5, 0.5,
  135726. };
  135727. static long _vq_quantmap__44u7__p2_0[] = {
  135728. 1, 0, 2,
  135729. };
  135730. static encode_aux_threshmatch _vq_auxt__44u7__p2_0 = {
  135731. _vq_quantthresh__44u7__p2_0,
  135732. _vq_quantmap__44u7__p2_0,
  135733. 3,
  135734. 3
  135735. };
  135736. static static_codebook _44u7__p2_0 = {
  135737. 4, 81,
  135738. _vq_lengthlist__44u7__p2_0,
  135739. 1, -535822336, 1611661312, 2, 0,
  135740. _vq_quantlist__44u7__p2_0,
  135741. NULL,
  135742. &_vq_auxt__44u7__p2_0,
  135743. NULL,
  135744. 0
  135745. };
  135746. static long _vq_quantlist__44u7__p3_0[] = {
  135747. 2,
  135748. 1,
  135749. 3,
  135750. 0,
  135751. 4,
  135752. };
  135753. static long _vq_lengthlist__44u7__p3_0[] = {
  135754. 2, 5, 4, 8, 8, 5, 7, 6, 9, 9, 5, 6, 7, 9, 9, 8,
  135755. 9, 9,13,12, 8, 9,10,12,13, 5, 7, 7,10, 9, 7, 9,
  135756. 9,11,11, 6, 8, 9,11,11,10,11,11,14,14, 9,10,11,
  135757. 13,14, 5, 7, 7, 9, 9, 7, 9, 8,11,11, 7, 9, 9,11,
  135758. 11, 9,11,10,14,13,10,11,11,14,14, 8,10,10,14,13,
  135759. 10,11,12,15,14, 9,11,11,15,14,13,14,14,16,16,12,
  135760. 13,14,17,16, 8,10,10,13,13, 9,11,11,14,15,10,11,
  135761. 12,14,15,12,14,13,16,16,13,14,15,15,17, 5, 7, 7,
  135762. 10,10, 7, 9, 9,11,11, 7, 9, 9,11,11,10,12,11,15,
  135763. 14,10,11,12,14,14, 7, 9, 9,12,12, 9,11,11,13,13,
  135764. 9,11,11,13,13,11,13,13,14,17,11,13,13,15,16, 6,
  135765. 9, 9,11,11, 8,11,10,13,12, 9,11,11,13,13,11,13,
  135766. 12,16,14,11,13,13,16,16,10,12,12,15,15,11,13,13,
  135767. 16,16,11,13,13,16,15,14,16,17,17,19,14,16,16,18,
  135768. 0, 9,11,11,14,15,10,13,12,16,15,11,13,13,16,16,
  135769. 14,15,14, 0,16,14,16,16,18, 0, 5, 7, 7,10,10, 7,
  135770. 9, 9,12,11, 7, 9, 9,11,12,10,11,11,15,14,10,11,
  135771. 12,14,14, 6, 9, 9,11,11, 9,11,11,13,13, 8,10,11,
  135772. 12,13,11,13,13,17,15,11,12,13,14,15, 7, 9, 9,11,
  135773. 12, 9,11,11,13,13, 9,11,11,13,13,11,13,12,16,16,
  135774. 11,13,13,15,14, 9,11,11,14,15,11,13,13,16,15,10,
  135775. 12,13,16,16,15,16,16, 0, 0,14,13,15,16,18,10,11,
  135776. 11,15,15,11,13,14,16,18,11,13,13,16,15,15,16,16,
  135777. 19, 0,14,15,15,16,16, 8,10,10,13,13,10,12,11,16,
  135778. 15,10,11,11,16,15,13,15,16,18, 0,13,14,15,17,17,
  135779. 9,11,11,15,15,11,13,13,16,18,11,13,13,16,17,15,
  135780. 16,16, 0, 0,15,18,16, 0,17, 9,11,11,15,15,11,13,
  135781. 12,17,15,11,13,14,16,17,15,18,15, 0,17,15,16,16,
  135782. 18,19,13,15,14, 0,18,14,16,16,19,18,14,16,15,19,
  135783. 19,16,18,19, 0, 0,16,17, 0, 0, 0,12,14,14,17,17,
  135784. 13,16,14, 0,18,14,16,15,18, 0,16,18,16,19,17,18,
  135785. 19,17, 0, 0, 8,10,10,14,14, 9,12,11,15,15,10,11,
  135786. 12,15,17,13,15,15,18,16,14,16,15,18,17, 9,11,11,
  135787. 16,15,11,13,13, 0,16,11,12,13,16,15,15,16,16, 0,
  135788. 17,15,15,16,18,17, 9,12,11,15,17,11,13,13,16,16,
  135789. 11,14,13,16,16,15,15,16,18,19,16,18,16, 0, 0,12,
  135790. 14,14, 0,16,14,16,16, 0,18,13,14,15,16, 0,17,16,
  135791. 18, 0, 0,16,16,17,19, 0,13,14,14,17, 0,14,17,16,
  135792. 0,19,14,15,15,18,19,17,16,18, 0, 0,15,19,16, 0,
  135793. 0,
  135794. };
  135795. static float _vq_quantthresh__44u7__p3_0[] = {
  135796. -1.5, -0.5, 0.5, 1.5,
  135797. };
  135798. static long _vq_quantmap__44u7__p3_0[] = {
  135799. 3, 1, 0, 2, 4,
  135800. };
  135801. static encode_aux_threshmatch _vq_auxt__44u7__p3_0 = {
  135802. _vq_quantthresh__44u7__p3_0,
  135803. _vq_quantmap__44u7__p3_0,
  135804. 5,
  135805. 5
  135806. };
  135807. static static_codebook _44u7__p3_0 = {
  135808. 4, 625,
  135809. _vq_lengthlist__44u7__p3_0,
  135810. 1, -533725184, 1611661312, 3, 0,
  135811. _vq_quantlist__44u7__p3_0,
  135812. NULL,
  135813. &_vq_auxt__44u7__p3_0,
  135814. NULL,
  135815. 0
  135816. };
  135817. static long _vq_quantlist__44u7__p4_0[] = {
  135818. 2,
  135819. 1,
  135820. 3,
  135821. 0,
  135822. 4,
  135823. };
  135824. static long _vq_lengthlist__44u7__p4_0[] = {
  135825. 4, 5, 5, 8, 8, 6, 7, 6, 9, 9, 6, 6, 7, 9, 9, 8,
  135826. 9, 9,11,11, 8, 9, 9,10,11, 6, 7, 7, 9, 9, 7, 8,
  135827. 8,10,10, 6, 7, 8, 9,10, 9,10,10,12,12, 9, 9,10,
  135828. 11,12, 6, 7, 7, 9, 9, 6, 8, 7,10, 9, 7, 8, 8,10,
  135829. 10, 9,10, 9,12,11, 9,10,10,12,11, 8, 9, 9,11,11,
  135830. 9,10,10,12,12, 9,10,10,12,12,11,12,12,13,14,11,
  135831. 11,12,13,13, 8, 9, 9,11,11, 9,10,10,12,11, 9,10,
  135832. 10,12,12,11,12,11,13,13,11,12,12,13,13, 6, 7, 7,
  135833. 9, 9, 7, 8, 7,10,10, 7, 7, 8,10,10, 9,10,10,12,
  135834. 11, 9,10,10,12,12, 7, 8, 8,10,10, 8, 8, 9,11,11,
  135835. 8, 9, 9,11,11,10,11,11,12,12,10,10,11,12,13, 6,
  135836. 7, 7,10,10, 7, 9, 8,11,10, 8, 8, 9,10,11,10,11,
  135837. 10,13,11,10,11,11,12,12, 9,10,10,12,12,10,10,11,
  135838. 13,13,10,11,11,13,12,12,12,13,13,14,12,12,13,14,
  135839. 14, 9,10,10,12,12, 9,10,10,12,12,10,11,11,13,13,
  135840. 11,12,11,14,12,12,13,13,14,14, 6, 7, 7, 9, 9, 7,
  135841. 8, 7,10,10, 7, 7, 8,10,10, 9,10,10,12,11, 9,10,
  135842. 10,11,12, 6, 7, 7,10,10, 8, 9, 8,11,10, 7, 8, 9,
  135843. 10,11,10,11,11,13,12,10,10,11,11,13, 7, 8, 8,10,
  135844. 10, 8, 9, 9,11,11, 8, 9, 9,11,11,10,11,10,13,12,
  135845. 10,11,11,12,12, 9,10,10,12,12,10,11,11,13,12, 9,
  135846. 10,10,12,13,12,13,12,14,14,11,11,12,12,14, 9,10,
  135847. 10,12,12,10,11,11,13,13,10,11,11,13,13,12,13,12,
  135848. 14,14,12,13,12,14,13, 8, 9, 9,11,11, 9,10,10,12,
  135849. 12, 9,10,10,12,12,11,12,12,14,13,11,12,12,13,13,
  135850. 9,10,10,12,12,10,11,11,13,13,10,11,11,13,12,12,
  135851. 13,13,14,14,12,12,13,14,14, 9,10,10,12,12, 9,11,
  135852. 10,13,12,10,10,11,12,13,11,13,12,14,13,12,12,13,
  135853. 14,14,11,12,12,13,13,11,12,13,14,14,12,13,13,14,
  135854. 14,13,13,14,14,16,13,14,14,16,16,11,11,11,13,13,
  135855. 11,12,11,14,13,12,12,13,14,15,13,14,12,16,13,14,
  135856. 14,14,15,16, 8, 9, 9,11,11, 9,10,10,12,12, 9,10,
  135857. 10,12,12,11,12,12,14,13,11,12,12,13,14, 9,10,10,
  135858. 12,12,10,11,10,13,12, 9,10,11,12,13,12,13,12,14,
  135859. 14,12,12,13,13,14, 9,10,10,12,12,10,11,11,12,13,
  135860. 10,11,11,13,13,12,13,12,14,14,12,13,13,14,14,11,
  135861. 12,12,13,13,12,13,12,14,14,11,11,12,13,14,13,15,
  135862. 14,16,15,13,12,14,13,16,11,12,12,13,13,12,13,13,
  135863. 14,14,12,12,12,14,14,13,14,14,15,15,13,14,13,16,
  135864. 14,
  135865. };
  135866. static float _vq_quantthresh__44u7__p4_0[] = {
  135867. -1.5, -0.5, 0.5, 1.5,
  135868. };
  135869. static long _vq_quantmap__44u7__p4_0[] = {
  135870. 3, 1, 0, 2, 4,
  135871. };
  135872. static encode_aux_threshmatch _vq_auxt__44u7__p4_0 = {
  135873. _vq_quantthresh__44u7__p4_0,
  135874. _vq_quantmap__44u7__p4_0,
  135875. 5,
  135876. 5
  135877. };
  135878. static static_codebook _44u7__p4_0 = {
  135879. 4, 625,
  135880. _vq_lengthlist__44u7__p4_0,
  135881. 1, -533725184, 1611661312, 3, 0,
  135882. _vq_quantlist__44u7__p4_0,
  135883. NULL,
  135884. &_vq_auxt__44u7__p4_0,
  135885. NULL,
  135886. 0
  135887. };
  135888. static long _vq_quantlist__44u7__p5_0[] = {
  135889. 4,
  135890. 3,
  135891. 5,
  135892. 2,
  135893. 6,
  135894. 1,
  135895. 7,
  135896. 0,
  135897. 8,
  135898. };
  135899. static long _vq_lengthlist__44u7__p5_0[] = {
  135900. 2, 3, 3, 6, 6, 7, 8,10,10, 4, 5, 5, 8, 7, 8, 8,
  135901. 11,11, 3, 5, 5, 7, 7, 8, 9,11,11, 6, 8, 7, 9, 9,
  135902. 10,10,12,12, 6, 7, 8, 9,10,10,10,12,12, 8, 8, 8,
  135903. 10,10,12,11,13,13, 8, 8, 9,10,10,11,11,13,13,10,
  135904. 11,11,12,12,13,13,14,14,10,11,11,12,12,13,13,14,
  135905. 14,
  135906. };
  135907. static float _vq_quantthresh__44u7__p5_0[] = {
  135908. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  135909. };
  135910. static long _vq_quantmap__44u7__p5_0[] = {
  135911. 7, 5, 3, 1, 0, 2, 4, 6,
  135912. 8,
  135913. };
  135914. static encode_aux_threshmatch _vq_auxt__44u7__p5_0 = {
  135915. _vq_quantthresh__44u7__p5_0,
  135916. _vq_quantmap__44u7__p5_0,
  135917. 9,
  135918. 9
  135919. };
  135920. static static_codebook _44u7__p5_0 = {
  135921. 2, 81,
  135922. _vq_lengthlist__44u7__p5_0,
  135923. 1, -531628032, 1611661312, 4, 0,
  135924. _vq_quantlist__44u7__p5_0,
  135925. NULL,
  135926. &_vq_auxt__44u7__p5_0,
  135927. NULL,
  135928. 0
  135929. };
  135930. static long _vq_quantlist__44u7__p6_0[] = {
  135931. 4,
  135932. 3,
  135933. 5,
  135934. 2,
  135935. 6,
  135936. 1,
  135937. 7,
  135938. 0,
  135939. 8,
  135940. };
  135941. static long _vq_lengthlist__44u7__p6_0[] = {
  135942. 3, 4, 4, 5, 5, 7, 7, 9, 9, 4, 5, 4, 6, 6, 8, 7,
  135943. 9, 9, 4, 4, 5, 6, 6, 7, 7, 9, 9, 5, 6, 6, 7, 7,
  135944. 8, 8,10,10, 5, 6, 6, 7, 7, 8, 8,10,10, 7, 8, 7,
  135945. 8, 8,10, 9,11,11, 7, 7, 8, 8, 8, 9,10,11,11, 9,
  135946. 9, 9,10,10,11,10,12,11, 9, 9, 9,10,10,11,11,11,
  135947. 12,
  135948. };
  135949. static float _vq_quantthresh__44u7__p6_0[] = {
  135950. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  135951. };
  135952. static long _vq_quantmap__44u7__p6_0[] = {
  135953. 7, 5, 3, 1, 0, 2, 4, 6,
  135954. 8,
  135955. };
  135956. static encode_aux_threshmatch _vq_auxt__44u7__p6_0 = {
  135957. _vq_quantthresh__44u7__p6_0,
  135958. _vq_quantmap__44u7__p6_0,
  135959. 9,
  135960. 9
  135961. };
  135962. static static_codebook _44u7__p6_0 = {
  135963. 2, 81,
  135964. _vq_lengthlist__44u7__p6_0,
  135965. 1, -531628032, 1611661312, 4, 0,
  135966. _vq_quantlist__44u7__p6_0,
  135967. NULL,
  135968. &_vq_auxt__44u7__p6_0,
  135969. NULL,
  135970. 0
  135971. };
  135972. static long _vq_quantlist__44u7__p7_0[] = {
  135973. 1,
  135974. 0,
  135975. 2,
  135976. };
  135977. static long _vq_lengthlist__44u7__p7_0[] = {
  135978. 1, 4, 4, 5, 7, 7, 5, 7, 7, 5, 9, 8, 8, 9, 9, 7,
  135979. 10,10, 5, 8, 9, 7, 9,10, 8, 9, 9, 4, 9, 9, 9,11,
  135980. 10, 8,10,10, 7,11,10,10,10,12,10,12,12, 7,10,10,
  135981. 10,12,11,10,12,12, 5, 9, 9, 8,10,10, 9,11,11, 7,
  135982. 11,10,10,12,12,10,11,12, 7,10,11,10,12,12,10,12,
  135983. 10,
  135984. };
  135985. static float _vq_quantthresh__44u7__p7_0[] = {
  135986. -5.5, 5.5,
  135987. };
  135988. static long _vq_quantmap__44u7__p7_0[] = {
  135989. 1, 0, 2,
  135990. };
  135991. static encode_aux_threshmatch _vq_auxt__44u7__p7_0 = {
  135992. _vq_quantthresh__44u7__p7_0,
  135993. _vq_quantmap__44u7__p7_0,
  135994. 3,
  135995. 3
  135996. };
  135997. static static_codebook _44u7__p7_0 = {
  135998. 4, 81,
  135999. _vq_lengthlist__44u7__p7_0,
  136000. 1, -529137664, 1618345984, 2, 0,
  136001. _vq_quantlist__44u7__p7_0,
  136002. NULL,
  136003. &_vq_auxt__44u7__p7_0,
  136004. NULL,
  136005. 0
  136006. };
  136007. static long _vq_quantlist__44u7__p7_1[] = {
  136008. 5,
  136009. 4,
  136010. 6,
  136011. 3,
  136012. 7,
  136013. 2,
  136014. 8,
  136015. 1,
  136016. 9,
  136017. 0,
  136018. 10,
  136019. };
  136020. static long _vq_lengthlist__44u7__p7_1[] = {
  136021. 3, 4, 4, 6, 6, 7, 7, 8, 8, 8, 8, 4, 5, 5, 6, 6,
  136022. 8, 7, 8, 8, 8, 8, 4, 5, 5, 6, 6, 7, 8, 8, 8, 8,
  136023. 8, 6, 7, 6, 7, 7, 8, 8, 9, 9, 9, 9, 6, 6, 7, 7,
  136024. 7, 8, 8, 9, 9, 9, 9, 7, 8, 7, 8, 8, 9, 9, 9, 9,
  136025. 9, 9, 7, 7, 8, 8, 8, 9, 9, 9, 9, 9, 9, 8, 8, 8,
  136026. 9, 9, 9, 9,10, 9, 9, 9, 8, 8, 8, 9, 9, 9, 9, 9,
  136027. 9, 9,10, 8, 8, 8, 9, 9, 9, 9,10, 9,10,10, 8, 8,
  136028. 8, 9, 9, 9, 9, 9,10,10,10,
  136029. };
  136030. static float _vq_quantthresh__44u7__p7_1[] = {
  136031. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  136032. 3.5, 4.5,
  136033. };
  136034. static long _vq_quantmap__44u7__p7_1[] = {
  136035. 9, 7, 5, 3, 1, 0, 2, 4,
  136036. 6, 8, 10,
  136037. };
  136038. static encode_aux_threshmatch _vq_auxt__44u7__p7_1 = {
  136039. _vq_quantthresh__44u7__p7_1,
  136040. _vq_quantmap__44u7__p7_1,
  136041. 11,
  136042. 11
  136043. };
  136044. static static_codebook _44u7__p7_1 = {
  136045. 2, 121,
  136046. _vq_lengthlist__44u7__p7_1,
  136047. 1, -531365888, 1611661312, 4, 0,
  136048. _vq_quantlist__44u7__p7_1,
  136049. NULL,
  136050. &_vq_auxt__44u7__p7_1,
  136051. NULL,
  136052. 0
  136053. };
  136054. static long _vq_quantlist__44u7__p8_0[] = {
  136055. 5,
  136056. 4,
  136057. 6,
  136058. 3,
  136059. 7,
  136060. 2,
  136061. 8,
  136062. 1,
  136063. 9,
  136064. 0,
  136065. 10,
  136066. };
  136067. static long _vq_lengthlist__44u7__p8_0[] = {
  136068. 1, 4, 4, 6, 6, 8, 8,10,10,11,11, 4, 6, 6, 7, 7,
  136069. 9, 9,11,10,12,12, 5, 6, 5, 7, 7, 9, 9,10,11,12,
  136070. 12, 6, 7, 7, 8, 8,10,10,11,11,13,13, 6, 7, 7, 8,
  136071. 8,10,10,11,12,13,13, 8, 9, 9,10,10,11,11,12,12,
  136072. 14,14, 8, 9, 9,10,10,11,11,12,12,14,14,10,10,10,
  136073. 11,11,13,12,14,14,15,15,10,10,10,12,12,13,13,14,
  136074. 14,15,15,11,12,12,13,13,14,14,15,14,16,15,11,12,
  136075. 12,13,13,14,14,15,15,15,16,
  136076. };
  136077. static float _vq_quantthresh__44u7__p8_0[] = {
  136078. -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5, 27.5,
  136079. 38.5, 49.5,
  136080. };
  136081. static long _vq_quantmap__44u7__p8_0[] = {
  136082. 9, 7, 5, 3, 1, 0, 2, 4,
  136083. 6, 8, 10,
  136084. };
  136085. static encode_aux_threshmatch _vq_auxt__44u7__p8_0 = {
  136086. _vq_quantthresh__44u7__p8_0,
  136087. _vq_quantmap__44u7__p8_0,
  136088. 11,
  136089. 11
  136090. };
  136091. static static_codebook _44u7__p8_0 = {
  136092. 2, 121,
  136093. _vq_lengthlist__44u7__p8_0,
  136094. 1, -524582912, 1618345984, 4, 0,
  136095. _vq_quantlist__44u7__p8_0,
  136096. NULL,
  136097. &_vq_auxt__44u7__p8_0,
  136098. NULL,
  136099. 0
  136100. };
  136101. static long _vq_quantlist__44u7__p8_1[] = {
  136102. 5,
  136103. 4,
  136104. 6,
  136105. 3,
  136106. 7,
  136107. 2,
  136108. 8,
  136109. 1,
  136110. 9,
  136111. 0,
  136112. 10,
  136113. };
  136114. static long _vq_lengthlist__44u7__p8_1[] = {
  136115. 4, 5, 5, 6, 6, 7, 7, 7, 7, 7, 7, 5, 6, 6, 7, 7,
  136116. 7, 7, 7, 7, 7, 7, 5, 6, 6, 6, 7, 7, 7, 7, 7, 7,
  136117. 7, 6, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 6, 7, 7, 7,
  136118. 7, 7, 7, 7, 7, 8, 8, 7, 7, 7, 7, 7, 8, 7, 8, 8,
  136119. 8, 8, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 7, 7, 7,
  136120. 7, 7, 8, 8, 8, 8, 8, 8, 7, 7, 7, 7, 7, 8, 8, 8,
  136121. 8, 8, 8, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 7, 7,
  136122. 7, 8, 8, 8, 8, 8, 8, 8, 8,
  136123. };
  136124. static float _vq_quantthresh__44u7__p8_1[] = {
  136125. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  136126. 3.5, 4.5,
  136127. };
  136128. static long _vq_quantmap__44u7__p8_1[] = {
  136129. 9, 7, 5, 3, 1, 0, 2, 4,
  136130. 6, 8, 10,
  136131. };
  136132. static encode_aux_threshmatch _vq_auxt__44u7__p8_1 = {
  136133. _vq_quantthresh__44u7__p8_1,
  136134. _vq_quantmap__44u7__p8_1,
  136135. 11,
  136136. 11
  136137. };
  136138. static static_codebook _44u7__p8_1 = {
  136139. 2, 121,
  136140. _vq_lengthlist__44u7__p8_1,
  136141. 1, -531365888, 1611661312, 4, 0,
  136142. _vq_quantlist__44u7__p8_1,
  136143. NULL,
  136144. &_vq_auxt__44u7__p8_1,
  136145. NULL,
  136146. 0
  136147. };
  136148. static long _vq_quantlist__44u7__p9_0[] = {
  136149. 5,
  136150. 4,
  136151. 6,
  136152. 3,
  136153. 7,
  136154. 2,
  136155. 8,
  136156. 1,
  136157. 9,
  136158. 0,
  136159. 10,
  136160. };
  136161. static long _vq_lengthlist__44u7__p9_0[] = {
  136162. 1, 3, 3,10,10,10,10,10,10,10,10, 4,10,10,10,10,
  136163. 10,10,10,10,10,10, 4,10,10,10,10,10,10,10,10,10,
  136164. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  136165. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  136166. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  136167. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  136168. 10,10,10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9,
  136169. 9, 9, 9, 9, 9, 9, 9, 9, 9,
  136170. };
  136171. static float _vq_quantthresh__44u7__p9_0[] = {
  136172. -2866.5, -2229.5, -1592.5, -955.5, -318.5, 318.5, 955.5, 1592.5,
  136173. 2229.5, 2866.5,
  136174. };
  136175. static long _vq_quantmap__44u7__p9_0[] = {
  136176. 9, 7, 5, 3, 1, 0, 2, 4,
  136177. 6, 8, 10,
  136178. };
  136179. static encode_aux_threshmatch _vq_auxt__44u7__p9_0 = {
  136180. _vq_quantthresh__44u7__p9_0,
  136181. _vq_quantmap__44u7__p9_0,
  136182. 11,
  136183. 11
  136184. };
  136185. static static_codebook _44u7__p9_0 = {
  136186. 2, 121,
  136187. _vq_lengthlist__44u7__p9_0,
  136188. 1, -512171520, 1630791680, 4, 0,
  136189. _vq_quantlist__44u7__p9_0,
  136190. NULL,
  136191. &_vq_auxt__44u7__p9_0,
  136192. NULL,
  136193. 0
  136194. };
  136195. static long _vq_quantlist__44u7__p9_1[] = {
  136196. 6,
  136197. 5,
  136198. 7,
  136199. 4,
  136200. 8,
  136201. 3,
  136202. 9,
  136203. 2,
  136204. 10,
  136205. 1,
  136206. 11,
  136207. 0,
  136208. 12,
  136209. };
  136210. static long _vq_lengthlist__44u7__p9_1[] = {
  136211. 1, 4, 4, 6, 5, 8, 6, 9, 8,10, 9,11,10, 4, 6, 6,
  136212. 8, 8, 9, 9,11,10,11,11,11,11, 4, 6, 6, 8, 8,10,
  136213. 9,11,11,11,11,11,12, 6, 8, 8,10,10,11,11,12,12,
  136214. 13,12,13,13, 6, 8, 8,10,10,11,11,12,12,12,13,14,
  136215. 13, 8,10,10,11,11,12,13,14,14,14,14,15,15, 8,10,
  136216. 10,11,12,12,13,13,14,14,14,14,15, 9,11,11,13,13,
  136217. 14,14,15,14,16,15,17,15, 9,11,11,12,13,14,14,15,
  136218. 14,15,15,15,16,10,12,12,13,14,15,15,15,15,16,17,
  136219. 16,17,10,13,12,13,14,14,16,16,16,16,15,16,17,11,
  136220. 13,13,14,15,14,17,15,16,17,17,17,17,11,13,13,14,
  136221. 15,15,15,15,17,17,16,17,16,
  136222. };
  136223. static float _vq_quantthresh__44u7__p9_1[] = {
  136224. -269.5, -220.5, -171.5, -122.5, -73.5, -24.5, 24.5, 73.5,
  136225. 122.5, 171.5, 220.5, 269.5,
  136226. };
  136227. static long _vq_quantmap__44u7__p9_1[] = {
  136228. 11, 9, 7, 5, 3, 1, 0, 2,
  136229. 4, 6, 8, 10, 12,
  136230. };
  136231. static encode_aux_threshmatch _vq_auxt__44u7__p9_1 = {
  136232. _vq_quantthresh__44u7__p9_1,
  136233. _vq_quantmap__44u7__p9_1,
  136234. 13,
  136235. 13
  136236. };
  136237. static static_codebook _44u7__p9_1 = {
  136238. 2, 169,
  136239. _vq_lengthlist__44u7__p9_1,
  136240. 1, -518889472, 1622704128, 4, 0,
  136241. _vq_quantlist__44u7__p9_1,
  136242. NULL,
  136243. &_vq_auxt__44u7__p9_1,
  136244. NULL,
  136245. 0
  136246. };
  136247. static long _vq_quantlist__44u7__p9_2[] = {
  136248. 24,
  136249. 23,
  136250. 25,
  136251. 22,
  136252. 26,
  136253. 21,
  136254. 27,
  136255. 20,
  136256. 28,
  136257. 19,
  136258. 29,
  136259. 18,
  136260. 30,
  136261. 17,
  136262. 31,
  136263. 16,
  136264. 32,
  136265. 15,
  136266. 33,
  136267. 14,
  136268. 34,
  136269. 13,
  136270. 35,
  136271. 12,
  136272. 36,
  136273. 11,
  136274. 37,
  136275. 10,
  136276. 38,
  136277. 9,
  136278. 39,
  136279. 8,
  136280. 40,
  136281. 7,
  136282. 41,
  136283. 6,
  136284. 42,
  136285. 5,
  136286. 43,
  136287. 4,
  136288. 44,
  136289. 3,
  136290. 45,
  136291. 2,
  136292. 46,
  136293. 1,
  136294. 47,
  136295. 0,
  136296. 48,
  136297. };
  136298. static long _vq_lengthlist__44u7__p9_2[] = {
  136299. 2, 4, 4, 4, 4, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6,
  136300. 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  136301. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8,
  136302. 8,
  136303. };
  136304. static float _vq_quantthresh__44u7__p9_2[] = {
  136305. -23.5, -22.5, -21.5, -20.5, -19.5, -18.5, -17.5, -16.5,
  136306. -15.5, -14.5, -13.5, -12.5, -11.5, -10.5, -9.5, -8.5,
  136307. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  136308. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  136309. 8.5, 9.5, 10.5, 11.5, 12.5, 13.5, 14.5, 15.5,
  136310. 16.5, 17.5, 18.5, 19.5, 20.5, 21.5, 22.5, 23.5,
  136311. };
  136312. static long _vq_quantmap__44u7__p9_2[] = {
  136313. 47, 45, 43, 41, 39, 37, 35, 33,
  136314. 31, 29, 27, 25, 23, 21, 19, 17,
  136315. 15, 13, 11, 9, 7, 5, 3, 1,
  136316. 0, 2, 4, 6, 8, 10, 12, 14,
  136317. 16, 18, 20, 22, 24, 26, 28, 30,
  136318. 32, 34, 36, 38, 40, 42, 44, 46,
  136319. 48,
  136320. };
  136321. static encode_aux_threshmatch _vq_auxt__44u7__p9_2 = {
  136322. _vq_quantthresh__44u7__p9_2,
  136323. _vq_quantmap__44u7__p9_2,
  136324. 49,
  136325. 49
  136326. };
  136327. static static_codebook _44u7__p9_2 = {
  136328. 1, 49,
  136329. _vq_lengthlist__44u7__p9_2,
  136330. 1, -526909440, 1611661312, 6, 0,
  136331. _vq_quantlist__44u7__p9_2,
  136332. NULL,
  136333. &_vq_auxt__44u7__p9_2,
  136334. NULL,
  136335. 0
  136336. };
  136337. static long _huff_lengthlist__44u7__short[] = {
  136338. 5,12,17,16,16,17,17,17,17,17, 4, 7,11,11,12, 9,
  136339. 17,10,17,17, 7, 7, 8, 9, 7, 9,11,10,15,17, 7, 9,
  136340. 10,11,10,12,14,12,16,17, 7, 8, 5, 7, 4, 7, 7, 8,
  136341. 16,16, 6,10, 9,10, 7,10,11,11,16,17, 6, 8, 8, 9,
  136342. 5, 7, 5, 8,16,17, 5, 5, 8, 7, 6, 7, 7, 6, 6,14,
  136343. 12,10,12,11, 7,11, 4, 4, 2, 7,17,15,15,15, 8,15,
  136344. 6, 8, 5, 9,
  136345. };
  136346. static static_codebook _huff_book__44u7__short = {
  136347. 2, 100,
  136348. _huff_lengthlist__44u7__short,
  136349. 0, 0, 0, 0, 0,
  136350. NULL,
  136351. NULL,
  136352. NULL,
  136353. NULL,
  136354. 0
  136355. };
  136356. static long _huff_lengthlist__44u8__long[] = {
  136357. 3, 9,13,14,14,15,14,14,15,15, 5, 4, 6, 8,10,12,
  136358. 12,14,15,15, 9, 5, 4, 5, 8,10,11,13,16,16,10, 7,
  136359. 4, 3, 5, 7, 9,11,13,13,10, 9, 7, 4, 4, 6, 8,10,
  136360. 12,14,13,11, 9, 6, 5, 5, 6, 8,12,14,13,11,10, 8,
  136361. 7, 6, 6, 7,10,14,13,11,12,10, 8, 7, 6, 6, 9,13,
  136362. 12,11,14,12,11, 9, 8, 7, 9,11,11,12,14,13,14,11,
  136363. 10, 8, 8, 9,
  136364. };
  136365. static static_codebook _huff_book__44u8__long = {
  136366. 2, 100,
  136367. _huff_lengthlist__44u8__long,
  136368. 0, 0, 0, 0, 0,
  136369. NULL,
  136370. NULL,
  136371. NULL,
  136372. NULL,
  136373. 0
  136374. };
  136375. static long _huff_lengthlist__44u8__short[] = {
  136376. 6,14,18,18,17,17,17,17,17,17, 4, 7, 9, 9,10,13,
  136377. 15,17,17,17, 6, 7, 5, 6, 8,11,16,17,16,17, 5, 7,
  136378. 5, 4, 6,10,14,17,17,17, 6, 6, 6, 5, 7,10,13,16,
  136379. 17,17, 7, 6, 7, 7, 7, 8, 7,10,15,16,12, 9, 9, 6,
  136380. 6, 5, 3, 5,11,15,14,14,13, 5, 5, 7, 3, 4, 8,15,
  136381. 17,17,13, 7, 7,10, 6, 6,10,15,17,17,16,10,11,14,
  136382. 10,10,15,17,
  136383. };
  136384. static static_codebook _huff_book__44u8__short = {
  136385. 2, 100,
  136386. _huff_lengthlist__44u8__short,
  136387. 0, 0, 0, 0, 0,
  136388. NULL,
  136389. NULL,
  136390. NULL,
  136391. NULL,
  136392. 0
  136393. };
  136394. static long _vq_quantlist__44u8_p1_0[] = {
  136395. 1,
  136396. 0,
  136397. 2,
  136398. };
  136399. static long _vq_lengthlist__44u8_p1_0[] = {
  136400. 1, 5, 5, 5, 7, 7, 5, 7, 7, 5, 7, 7, 8, 9, 9, 7,
  136401. 9, 9, 5, 7, 7, 7, 9, 9, 8, 9, 9, 5, 7, 7, 7, 9,
  136402. 9, 7, 9, 9, 7, 9, 9, 9,10,11, 9,11,10, 7, 9, 9,
  136403. 9,11,10, 9,10,11, 5, 7, 7, 7, 9, 9, 7, 9, 9, 7,
  136404. 9, 9, 9,11,10, 9,10,10, 8, 9, 9, 9,11,11, 9,11,
  136405. 10,
  136406. };
  136407. static float _vq_quantthresh__44u8_p1_0[] = {
  136408. -0.5, 0.5,
  136409. };
  136410. static long _vq_quantmap__44u8_p1_0[] = {
  136411. 1, 0, 2,
  136412. };
  136413. static encode_aux_threshmatch _vq_auxt__44u8_p1_0 = {
  136414. _vq_quantthresh__44u8_p1_0,
  136415. _vq_quantmap__44u8_p1_0,
  136416. 3,
  136417. 3
  136418. };
  136419. static static_codebook _44u8_p1_0 = {
  136420. 4, 81,
  136421. _vq_lengthlist__44u8_p1_0,
  136422. 1, -535822336, 1611661312, 2, 0,
  136423. _vq_quantlist__44u8_p1_0,
  136424. NULL,
  136425. &_vq_auxt__44u8_p1_0,
  136426. NULL,
  136427. 0
  136428. };
  136429. static long _vq_quantlist__44u8_p2_0[] = {
  136430. 2,
  136431. 1,
  136432. 3,
  136433. 0,
  136434. 4,
  136435. };
  136436. static long _vq_lengthlist__44u8_p2_0[] = {
  136437. 4, 5, 5, 8, 8, 5, 7, 6, 9, 9, 5, 6, 7, 9, 9, 8,
  136438. 9, 9,11,11, 8, 9, 9,11,11, 5, 7, 7, 9, 9, 7, 8,
  136439. 8,10,10, 7, 8, 8,10,10, 9,10,10,12,12, 9,10,10,
  136440. 11,12, 5, 7, 7, 9, 9, 7, 8, 7,10,10, 7, 8, 8,10,
  136441. 10, 9,10, 9,12,11, 9,10,10,12,12, 8, 9, 9,12,11,
  136442. 9,10,10,12,12, 9,10,10,12,12,11,12,12,14,14,11,
  136443. 11,12,13,14, 8, 9, 9,11,11, 9,10,10,12,12, 9,10,
  136444. 10,12,12,11,12,11,13,13,11,12,12,14,14, 5, 7, 7,
  136445. 9, 9, 7, 8, 8,10,10, 7, 8, 8,10,10, 9,10,10,12,
  136446. 12, 9,10,10,11,12, 7, 8, 8,10,10, 8, 9, 9,11,11,
  136447. 8, 9, 9,11,11,10,11,11,12,13,10,11,11,12,13, 6,
  136448. 8, 8,10,10, 8, 9, 8,11,10, 8, 9, 9,11,11,10,11,
  136449. 10,13,12,10,11,11,13,13, 9,10,10,12,12,10,11,11,
  136450. 13,13,10,11,11,13,13,12,12,13,13,14,12,13,13,14,
  136451. 14, 9,10,10,12,12,10,11,10,13,12,10,11,11,13,13,
  136452. 11,13,12,14,13,12,13,13,14,14, 5, 7, 7, 9, 9, 7,
  136453. 8, 8,10,10, 7, 8, 8,10,10, 9,10,10,12,12, 9,10,
  136454. 10,12,12, 7, 8, 8,10,10, 8, 9, 9,11,11, 8, 8, 9,
  136455. 10,11,10,11,11,13,13,10,10,11,12,13, 7, 8, 8,10,
  136456. 10, 8, 9, 9,11,11, 8, 9, 9,11,11,10,11,11,13,13,
  136457. 10,11,11,13,12, 9,10,10,12,12,10,11,11,13,13,10,
  136458. 10,11,12,13,12,13,13,14,14,12,12,13,13,14, 9,10,
  136459. 10,12,12,10,11,11,13,13,10,11,11,13,13,12,13,13,
  136460. 15,14,12,13,13,14,13, 8, 9, 9,11,11, 9,10,10,12,
  136461. 12, 9,10,10,12,12,12,12,12,14,13,11,12,12,14,14,
  136462. 9,10,10,12,12,10,11,11,13,13,10,11,11,13,13,12,
  136463. 13,13,14,15,12,13,13,14,15, 9,10,10,12,12,10,11,
  136464. 10,13,12,10,11,11,13,13,12,13,12,15,14,12,13,13,
  136465. 14,15,11,12,12,14,14,12,13,13,14,14,12,13,13,15,
  136466. 14,14,14,14,14,16,14,14,15,16,16,11,12,12,14,14,
  136467. 11,12,12,14,14,12,13,13,14,15,13,14,13,16,14,14,
  136468. 14,14,16,16, 8, 9, 9,11,11, 9,10,10,12,12, 9,10,
  136469. 10,12,12,11,12,12,14,13,11,12,12,14,14, 9,10,10,
  136470. 12,12,10,11,11,13,13,10,10,11,12,13,12,13,13,15,
  136471. 14,12,12,13,13,14, 9,10,10,12,12,10,11,11,13,13,
  136472. 10,11,11,13,13,12,13,13,14,14,12,13,13,15,14,11,
  136473. 12,12,14,13,12,13,13,15,14,11,12,12,13,14,14,15,
  136474. 14,16,15,13,13,14,13,16,11,12,12,14,14,12,13,13,
  136475. 14,15,12,13,12,15,14,14,14,14,16,15,14,15,13,16,
  136476. 14,
  136477. };
  136478. static float _vq_quantthresh__44u8_p2_0[] = {
  136479. -1.5, -0.5, 0.5, 1.5,
  136480. };
  136481. static long _vq_quantmap__44u8_p2_0[] = {
  136482. 3, 1, 0, 2, 4,
  136483. };
  136484. static encode_aux_threshmatch _vq_auxt__44u8_p2_0 = {
  136485. _vq_quantthresh__44u8_p2_0,
  136486. _vq_quantmap__44u8_p2_0,
  136487. 5,
  136488. 5
  136489. };
  136490. static static_codebook _44u8_p2_0 = {
  136491. 4, 625,
  136492. _vq_lengthlist__44u8_p2_0,
  136493. 1, -533725184, 1611661312, 3, 0,
  136494. _vq_quantlist__44u8_p2_0,
  136495. NULL,
  136496. &_vq_auxt__44u8_p2_0,
  136497. NULL,
  136498. 0
  136499. };
  136500. static long _vq_quantlist__44u8_p3_0[] = {
  136501. 4,
  136502. 3,
  136503. 5,
  136504. 2,
  136505. 6,
  136506. 1,
  136507. 7,
  136508. 0,
  136509. 8,
  136510. };
  136511. static long _vq_lengthlist__44u8_p3_0[] = {
  136512. 3, 4, 4, 5, 5, 7, 7, 9, 9, 4, 5, 4, 6, 6, 7, 7,
  136513. 9, 9, 4, 4, 5, 6, 6, 7, 7, 9, 9, 5, 6, 6, 7, 7,
  136514. 8, 8,10,10, 6, 6, 6, 7, 7, 8, 8,10,10, 7, 7, 7,
  136515. 8, 8, 9, 9,11,10, 7, 7, 7, 8, 8, 9, 9,10,11, 9,
  136516. 9, 9,10,10,11,10,12,11, 9, 9, 9, 9,10,11,11,11,
  136517. 12,
  136518. };
  136519. static float _vq_quantthresh__44u8_p3_0[] = {
  136520. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  136521. };
  136522. static long _vq_quantmap__44u8_p3_0[] = {
  136523. 7, 5, 3, 1, 0, 2, 4, 6,
  136524. 8,
  136525. };
  136526. static encode_aux_threshmatch _vq_auxt__44u8_p3_0 = {
  136527. _vq_quantthresh__44u8_p3_0,
  136528. _vq_quantmap__44u8_p3_0,
  136529. 9,
  136530. 9
  136531. };
  136532. static static_codebook _44u8_p3_0 = {
  136533. 2, 81,
  136534. _vq_lengthlist__44u8_p3_0,
  136535. 1, -531628032, 1611661312, 4, 0,
  136536. _vq_quantlist__44u8_p3_0,
  136537. NULL,
  136538. &_vq_auxt__44u8_p3_0,
  136539. NULL,
  136540. 0
  136541. };
  136542. static long _vq_quantlist__44u8_p4_0[] = {
  136543. 8,
  136544. 7,
  136545. 9,
  136546. 6,
  136547. 10,
  136548. 5,
  136549. 11,
  136550. 4,
  136551. 12,
  136552. 3,
  136553. 13,
  136554. 2,
  136555. 14,
  136556. 1,
  136557. 15,
  136558. 0,
  136559. 16,
  136560. };
  136561. static long _vq_lengthlist__44u8_p4_0[] = {
  136562. 4, 4, 4, 6, 6, 7, 7, 8, 8, 8, 8,10,10,11,11,11,
  136563. 11, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9,10,10,11,11,
  136564. 12,12, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9,10,10,11,
  136565. 11,12,12, 6, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  136566. 11,11,12,12, 6, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9,10,
  136567. 10,11,11,12,12, 7, 7, 7, 8, 8, 9, 8,10, 9,10, 9,
  136568. 11,10,12,11,13,12, 7, 7, 7, 8, 8, 8, 9, 9,10, 9,
  136569. 10,10,11,11,12,12,13, 8, 8, 8, 9, 9, 9, 9,10,10,
  136570. 11,10,11,11,12,12,13,13, 8, 8, 8, 9, 9, 9,10,10,
  136571. 10,10,11,11,11,12,12,12,13, 8, 9, 9, 9, 9,10, 9,
  136572. 11,10,11,11,12,11,13,12,13,13, 8, 9, 9, 9, 9, 9,
  136573. 10,10,11,11,11,11,12,12,13,13,13,10,10,10,10,10,
  136574. 11,10,11,11,12,11,13,12,13,13,14,13,10,10,10,10,
  136575. 10,10,11,11,11,11,12,12,13,13,13,13,14,11,11,11,
  136576. 11,11,12,11,12,12,13,12,13,13,14,13,14,14,11,11,
  136577. 11,11,11,11,12,12,12,12,13,13,13,13,14,14,14,11,
  136578. 12,12,12,12,13,12,13,12,13,13,14,13,14,14,14,14,
  136579. 11,12,12,12,12,12,12,13,13,13,13,13,14,14,14,14,
  136580. 14,
  136581. };
  136582. static float _vq_quantthresh__44u8_p4_0[] = {
  136583. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  136584. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  136585. };
  136586. static long _vq_quantmap__44u8_p4_0[] = {
  136587. 15, 13, 11, 9, 7, 5, 3, 1,
  136588. 0, 2, 4, 6, 8, 10, 12, 14,
  136589. 16,
  136590. };
  136591. static encode_aux_threshmatch _vq_auxt__44u8_p4_0 = {
  136592. _vq_quantthresh__44u8_p4_0,
  136593. _vq_quantmap__44u8_p4_0,
  136594. 17,
  136595. 17
  136596. };
  136597. static static_codebook _44u8_p4_0 = {
  136598. 2, 289,
  136599. _vq_lengthlist__44u8_p4_0,
  136600. 1, -529530880, 1611661312, 5, 0,
  136601. _vq_quantlist__44u8_p4_0,
  136602. NULL,
  136603. &_vq_auxt__44u8_p4_0,
  136604. NULL,
  136605. 0
  136606. };
  136607. static long _vq_quantlist__44u8_p5_0[] = {
  136608. 1,
  136609. 0,
  136610. 2,
  136611. };
  136612. static long _vq_lengthlist__44u8_p5_0[] = {
  136613. 1, 4, 4, 5, 7, 7, 5, 7, 7, 5, 8, 8, 8, 9, 9, 7,
  136614. 9, 9, 5, 8, 8, 7, 9, 9, 8, 9, 9, 5, 8, 8, 8,10,
  136615. 10, 8,10,10, 7,10,10, 9,10,12, 9,12,11, 7,10,10,
  136616. 9,11,10, 9,11,12, 5, 8, 8, 8,10,10, 8,10,10, 7,
  136617. 10,10, 9,11,11, 9,10,11, 7,10,10, 9,11,11,10,12,
  136618. 10,
  136619. };
  136620. static float _vq_quantthresh__44u8_p5_0[] = {
  136621. -5.5, 5.5,
  136622. };
  136623. static long _vq_quantmap__44u8_p5_0[] = {
  136624. 1, 0, 2,
  136625. };
  136626. static encode_aux_threshmatch _vq_auxt__44u8_p5_0 = {
  136627. _vq_quantthresh__44u8_p5_0,
  136628. _vq_quantmap__44u8_p5_0,
  136629. 3,
  136630. 3
  136631. };
  136632. static static_codebook _44u8_p5_0 = {
  136633. 4, 81,
  136634. _vq_lengthlist__44u8_p5_0,
  136635. 1, -529137664, 1618345984, 2, 0,
  136636. _vq_quantlist__44u8_p5_0,
  136637. NULL,
  136638. &_vq_auxt__44u8_p5_0,
  136639. NULL,
  136640. 0
  136641. };
  136642. static long _vq_quantlist__44u8_p5_1[] = {
  136643. 5,
  136644. 4,
  136645. 6,
  136646. 3,
  136647. 7,
  136648. 2,
  136649. 8,
  136650. 1,
  136651. 9,
  136652. 0,
  136653. 10,
  136654. };
  136655. static long _vq_lengthlist__44u8_p5_1[] = {
  136656. 4, 5, 5, 6, 6, 7, 7, 7, 7, 8, 8, 5, 5, 5, 6, 6,
  136657. 7, 7, 8, 8, 8, 8, 5, 5, 5, 6, 6, 7, 7, 7, 8, 8,
  136658. 8, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 6, 6, 6, 7,
  136659. 7, 7, 7, 8, 8, 8, 8, 7, 7, 7, 7, 7, 8, 8, 8, 8,
  136660. 8, 8, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 7, 8, 7,
  136661. 8, 8, 8, 8, 8, 8, 8, 8, 7, 8, 8, 8, 8, 8, 8, 8,
  136662. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 9, 9, 8, 8,
  136663. 8, 8, 8, 8, 8, 8, 8, 9, 9,
  136664. };
  136665. static float _vq_quantthresh__44u8_p5_1[] = {
  136666. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  136667. 3.5, 4.5,
  136668. };
  136669. static long _vq_quantmap__44u8_p5_1[] = {
  136670. 9, 7, 5, 3, 1, 0, 2, 4,
  136671. 6, 8, 10,
  136672. };
  136673. static encode_aux_threshmatch _vq_auxt__44u8_p5_1 = {
  136674. _vq_quantthresh__44u8_p5_1,
  136675. _vq_quantmap__44u8_p5_1,
  136676. 11,
  136677. 11
  136678. };
  136679. static static_codebook _44u8_p5_1 = {
  136680. 2, 121,
  136681. _vq_lengthlist__44u8_p5_1,
  136682. 1, -531365888, 1611661312, 4, 0,
  136683. _vq_quantlist__44u8_p5_1,
  136684. NULL,
  136685. &_vq_auxt__44u8_p5_1,
  136686. NULL,
  136687. 0
  136688. };
  136689. static long _vq_quantlist__44u8_p6_0[] = {
  136690. 6,
  136691. 5,
  136692. 7,
  136693. 4,
  136694. 8,
  136695. 3,
  136696. 9,
  136697. 2,
  136698. 10,
  136699. 1,
  136700. 11,
  136701. 0,
  136702. 12,
  136703. };
  136704. static long _vq_lengthlist__44u8_p6_0[] = {
  136705. 2, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9,10,10, 4, 6, 5,
  136706. 7, 7, 8, 8, 8, 8, 9, 9,10,10, 4, 6, 6, 7, 7, 8,
  136707. 8, 8, 8, 9, 9,10,10, 6, 7, 7, 7, 8, 8, 8, 8, 9,
  136708. 9,10,10,10, 6, 7, 7, 8, 8, 8, 8, 9, 8,10, 9,11,
  136709. 10, 7, 8, 8, 8, 8, 8, 9, 9, 9,10,10,11,11, 7, 8,
  136710. 8, 8, 8, 9, 8, 9, 9,10,10,11,11, 8, 8, 8, 9, 9,
  136711. 9, 9, 9,10,10,10,11,11, 8, 8, 8, 9, 9, 9, 9,10,
  136712. 9,10,10,11,11, 9, 9, 9, 9,10,10,10,10,10,10,11,
  136713. 11,12, 9, 9, 9,10, 9,10,10,10,10,11,10,12,11,10,
  136714. 10,10,10,10,11,11,11,11,11,12,12,12,10,10,10,10,
  136715. 11,11,11,11,11,12,11,12,12,
  136716. };
  136717. static float _vq_quantthresh__44u8_p6_0[] = {
  136718. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  136719. 12.5, 17.5, 22.5, 27.5,
  136720. };
  136721. static long _vq_quantmap__44u8_p6_0[] = {
  136722. 11, 9, 7, 5, 3, 1, 0, 2,
  136723. 4, 6, 8, 10, 12,
  136724. };
  136725. static encode_aux_threshmatch _vq_auxt__44u8_p6_0 = {
  136726. _vq_quantthresh__44u8_p6_0,
  136727. _vq_quantmap__44u8_p6_0,
  136728. 13,
  136729. 13
  136730. };
  136731. static static_codebook _44u8_p6_0 = {
  136732. 2, 169,
  136733. _vq_lengthlist__44u8_p6_0,
  136734. 1, -526516224, 1616117760, 4, 0,
  136735. _vq_quantlist__44u8_p6_0,
  136736. NULL,
  136737. &_vq_auxt__44u8_p6_0,
  136738. NULL,
  136739. 0
  136740. };
  136741. static long _vq_quantlist__44u8_p6_1[] = {
  136742. 2,
  136743. 1,
  136744. 3,
  136745. 0,
  136746. 4,
  136747. };
  136748. static long _vq_lengthlist__44u8_p6_1[] = {
  136749. 3, 4, 4, 5, 5, 4, 5, 5, 5, 5, 4, 5, 5, 5, 5, 5,
  136750. 5, 5, 5, 5, 5, 5, 5, 5, 5,
  136751. };
  136752. static float _vq_quantthresh__44u8_p6_1[] = {
  136753. -1.5, -0.5, 0.5, 1.5,
  136754. };
  136755. static long _vq_quantmap__44u8_p6_1[] = {
  136756. 3, 1, 0, 2, 4,
  136757. };
  136758. static encode_aux_threshmatch _vq_auxt__44u8_p6_1 = {
  136759. _vq_quantthresh__44u8_p6_1,
  136760. _vq_quantmap__44u8_p6_1,
  136761. 5,
  136762. 5
  136763. };
  136764. static static_codebook _44u8_p6_1 = {
  136765. 2, 25,
  136766. _vq_lengthlist__44u8_p6_1,
  136767. 1, -533725184, 1611661312, 3, 0,
  136768. _vq_quantlist__44u8_p6_1,
  136769. NULL,
  136770. &_vq_auxt__44u8_p6_1,
  136771. NULL,
  136772. 0
  136773. };
  136774. static long _vq_quantlist__44u8_p7_0[] = {
  136775. 6,
  136776. 5,
  136777. 7,
  136778. 4,
  136779. 8,
  136780. 3,
  136781. 9,
  136782. 2,
  136783. 10,
  136784. 1,
  136785. 11,
  136786. 0,
  136787. 12,
  136788. };
  136789. static long _vq_lengthlist__44u8_p7_0[] = {
  136790. 1, 4, 5, 6, 6, 7, 7, 8, 8,10,10,11,11, 5, 6, 6,
  136791. 7, 7, 8, 8, 9, 9,11,10,12,11, 5, 6, 6, 7, 7, 8,
  136792. 8, 9, 9,10,11,11,12, 6, 7, 7, 8, 8, 9, 9,10,10,
  136793. 11,11,12,12, 6, 7, 7, 8, 8, 9, 9,10,10,11,12,13,
  136794. 12, 7, 8, 8, 9, 9,10,10,11,11,12,12,13,13, 8, 8,
  136795. 8, 9, 9,10,10,11,11,12,12,13,13, 9, 9, 9,10,10,
  136796. 11,11,12,12,13,13,14,14, 9, 9, 9,10,10,11,11,12,
  136797. 12,13,13,14,14,10,11,11,12,11,13,12,13,13,14,14,
  136798. 15,15,10,11,11,11,12,12,13,13,14,14,14,15,15,11,
  136799. 12,12,13,13,14,13,15,14,15,15,16,15,11,11,12,13,
  136800. 13,13,14,14,14,15,15,15,16,
  136801. };
  136802. static float _vq_quantthresh__44u8_p7_0[] = {
  136803. -60.5, -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5,
  136804. 27.5, 38.5, 49.5, 60.5,
  136805. };
  136806. static long _vq_quantmap__44u8_p7_0[] = {
  136807. 11, 9, 7, 5, 3, 1, 0, 2,
  136808. 4, 6, 8, 10, 12,
  136809. };
  136810. static encode_aux_threshmatch _vq_auxt__44u8_p7_0 = {
  136811. _vq_quantthresh__44u8_p7_0,
  136812. _vq_quantmap__44u8_p7_0,
  136813. 13,
  136814. 13
  136815. };
  136816. static static_codebook _44u8_p7_0 = {
  136817. 2, 169,
  136818. _vq_lengthlist__44u8_p7_0,
  136819. 1, -523206656, 1618345984, 4, 0,
  136820. _vq_quantlist__44u8_p7_0,
  136821. NULL,
  136822. &_vq_auxt__44u8_p7_0,
  136823. NULL,
  136824. 0
  136825. };
  136826. static long _vq_quantlist__44u8_p7_1[] = {
  136827. 5,
  136828. 4,
  136829. 6,
  136830. 3,
  136831. 7,
  136832. 2,
  136833. 8,
  136834. 1,
  136835. 9,
  136836. 0,
  136837. 10,
  136838. };
  136839. static long _vq_lengthlist__44u8_p7_1[] = {
  136840. 4, 5, 5, 6, 6, 7, 7, 7, 7, 7, 7, 5, 6, 6, 7, 7,
  136841. 7, 7, 7, 7, 7, 7, 5, 6, 6, 7, 7, 7, 7, 7, 7, 7,
  136842. 7, 6, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 6, 7, 7, 7,
  136843. 7, 7, 7, 7, 7, 7, 8, 7, 7, 7, 7, 7, 7, 7, 8, 8,
  136844. 8, 8, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 7, 7, 7,
  136845. 8, 7, 8, 8, 8, 8, 8, 8, 7, 7, 7, 7, 7, 8, 8, 8,
  136846. 8, 8, 8, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 7, 7,
  136847. 7, 8, 8, 8, 8, 8, 8, 8, 8,
  136848. };
  136849. static float _vq_quantthresh__44u8_p7_1[] = {
  136850. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  136851. 3.5, 4.5,
  136852. };
  136853. static long _vq_quantmap__44u8_p7_1[] = {
  136854. 9, 7, 5, 3, 1, 0, 2, 4,
  136855. 6, 8, 10,
  136856. };
  136857. static encode_aux_threshmatch _vq_auxt__44u8_p7_1 = {
  136858. _vq_quantthresh__44u8_p7_1,
  136859. _vq_quantmap__44u8_p7_1,
  136860. 11,
  136861. 11
  136862. };
  136863. static static_codebook _44u8_p7_1 = {
  136864. 2, 121,
  136865. _vq_lengthlist__44u8_p7_1,
  136866. 1, -531365888, 1611661312, 4, 0,
  136867. _vq_quantlist__44u8_p7_1,
  136868. NULL,
  136869. &_vq_auxt__44u8_p7_1,
  136870. NULL,
  136871. 0
  136872. };
  136873. static long _vq_quantlist__44u8_p8_0[] = {
  136874. 7,
  136875. 6,
  136876. 8,
  136877. 5,
  136878. 9,
  136879. 4,
  136880. 10,
  136881. 3,
  136882. 11,
  136883. 2,
  136884. 12,
  136885. 1,
  136886. 13,
  136887. 0,
  136888. 14,
  136889. };
  136890. static long _vq_lengthlist__44u8_p8_0[] = {
  136891. 1, 4, 4, 7, 7, 8, 8, 8, 7, 9, 8,10, 9,11,10, 4,
  136892. 6, 6, 8, 8,10, 9, 9, 9,10,10,11,10,12,10, 4, 6,
  136893. 6, 8, 8,10,10, 9, 9,10,10,11,11,11,12, 7, 8, 8,
  136894. 10,10,11,11,11,10,12,11,12,12,13,11, 7, 8, 8,10,
  136895. 10,11,11,10,10,11,11,12,12,13,13, 8,10,10,11,11,
  136896. 12,11,12,11,13,12,13,12,14,13, 8,10, 9,11,11,12,
  136897. 12,12,12,12,12,13,13,14,13, 8, 9, 9,11,10,12,11,
  136898. 13,12,13,13,14,13,14,13, 8, 9, 9,10,11,12,12,12,
  136899. 12,13,13,14,15,14,14, 9,10,10,12,11,13,12,13,13,
  136900. 14,13,14,14,14,14, 9,10,10,12,12,12,12,13,13,14,
  136901. 14,14,15,14,14,10,11,11,13,12,13,12,14,14,14,14,
  136902. 14,14,15,15,10,11,11,12,12,13,13,14,14,14,15,15,
  136903. 14,16,15,11,12,12,13,12,14,14,14,13,15,14,15,15,
  136904. 15,17,11,12,12,13,13,14,14,14,15,15,14,15,15,14,
  136905. 17,
  136906. };
  136907. static float _vq_quantthresh__44u8_p8_0[] = {
  136908. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  136909. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  136910. };
  136911. static long _vq_quantmap__44u8_p8_0[] = {
  136912. 13, 11, 9, 7, 5, 3, 1, 0,
  136913. 2, 4, 6, 8, 10, 12, 14,
  136914. };
  136915. static encode_aux_threshmatch _vq_auxt__44u8_p8_0 = {
  136916. _vq_quantthresh__44u8_p8_0,
  136917. _vq_quantmap__44u8_p8_0,
  136918. 15,
  136919. 15
  136920. };
  136921. static static_codebook _44u8_p8_0 = {
  136922. 2, 225,
  136923. _vq_lengthlist__44u8_p8_0,
  136924. 1, -520986624, 1620377600, 4, 0,
  136925. _vq_quantlist__44u8_p8_0,
  136926. NULL,
  136927. &_vq_auxt__44u8_p8_0,
  136928. NULL,
  136929. 0
  136930. };
  136931. static long _vq_quantlist__44u8_p8_1[] = {
  136932. 10,
  136933. 9,
  136934. 11,
  136935. 8,
  136936. 12,
  136937. 7,
  136938. 13,
  136939. 6,
  136940. 14,
  136941. 5,
  136942. 15,
  136943. 4,
  136944. 16,
  136945. 3,
  136946. 17,
  136947. 2,
  136948. 18,
  136949. 1,
  136950. 19,
  136951. 0,
  136952. 20,
  136953. };
  136954. static long _vq_lengthlist__44u8_p8_1[] = {
  136955. 4, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9,
  136956. 9, 9, 9, 9, 9, 6, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,
  136957. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 5, 6, 6, 7, 7, 8,
  136958. 8, 9, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 7,
  136959. 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  136960. 9, 9, 9, 9, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  136961. 9, 9, 9, 9, 9, 9, 9, 9, 9, 8, 8, 8, 8, 8, 9, 9,
  136962. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10, 9,10, 8, 8,
  136963. 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 9,10,
  136964. 10, 9,10, 8, 9, 8, 9, 9, 9, 9, 9, 9, 9, 9,10, 9,
  136965. 10,10,10,10,10,10,10,10, 8, 9, 8, 9, 9, 9, 9, 9,
  136966. 9, 9, 9, 9, 9, 9,10,10,10,10, 9,10,10, 9, 9, 9,
  136967. 9, 9, 9, 9, 9, 9, 9, 9,10, 9,10,10,10,10,10,10,
  136968. 10,10, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 9,10,
  136969. 10,10,10,10,10,10,10, 9, 9, 9, 9, 9, 9, 9,10, 9,
  136970. 10,10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9,
  136971. 9, 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,10,
  136972. 10, 9, 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,
  136973. 10,10,10,10,10,10, 9, 9, 9, 9, 9, 9, 9,10,10,10,
  136974. 10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9,
  136975. 9, 9,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  136976. 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,10,10,
  136977. 10,10,10,10,10, 9, 9, 9,10, 9,10,10,10,10,10,10,
  136978. 10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9,10,
  136979. 9,10,10,10,10,10,10,10,10,10,10,10,10,10,10, 9,
  136980. 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,10,10,
  136981. 10,10,10,10, 9, 9, 9,10, 9,10, 9,10,10,10,10,10,
  136982. 10,10,10,10,10,10,10,10,10,
  136983. };
  136984. static float _vq_quantthresh__44u8_p8_1[] = {
  136985. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  136986. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  136987. 6.5, 7.5, 8.5, 9.5,
  136988. };
  136989. static long _vq_quantmap__44u8_p8_1[] = {
  136990. 19, 17, 15, 13, 11, 9, 7, 5,
  136991. 3, 1, 0, 2, 4, 6, 8, 10,
  136992. 12, 14, 16, 18, 20,
  136993. };
  136994. static encode_aux_threshmatch _vq_auxt__44u8_p8_1 = {
  136995. _vq_quantthresh__44u8_p8_1,
  136996. _vq_quantmap__44u8_p8_1,
  136997. 21,
  136998. 21
  136999. };
  137000. static static_codebook _44u8_p8_1 = {
  137001. 2, 441,
  137002. _vq_lengthlist__44u8_p8_1,
  137003. 1, -529268736, 1611661312, 5, 0,
  137004. _vq_quantlist__44u8_p8_1,
  137005. NULL,
  137006. &_vq_auxt__44u8_p8_1,
  137007. NULL,
  137008. 0
  137009. };
  137010. static long _vq_quantlist__44u8_p9_0[] = {
  137011. 4,
  137012. 3,
  137013. 5,
  137014. 2,
  137015. 6,
  137016. 1,
  137017. 7,
  137018. 0,
  137019. 8,
  137020. };
  137021. static long _vq_lengthlist__44u8_p9_0[] = {
  137022. 1, 3, 3, 9, 9, 9, 9, 9, 9, 4, 9, 9, 9, 9, 9, 9,
  137023. 9, 9, 5, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  137024. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  137025. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  137026. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 8, 8, 8,
  137027. 8,
  137028. };
  137029. static float _vq_quantthresh__44u8_p9_0[] = {
  137030. -3258.5, -2327.5, -1396.5, -465.5, 465.5, 1396.5, 2327.5, 3258.5,
  137031. };
  137032. static long _vq_quantmap__44u8_p9_0[] = {
  137033. 7, 5, 3, 1, 0, 2, 4, 6,
  137034. 8,
  137035. };
  137036. static encode_aux_threshmatch _vq_auxt__44u8_p9_0 = {
  137037. _vq_quantthresh__44u8_p9_0,
  137038. _vq_quantmap__44u8_p9_0,
  137039. 9,
  137040. 9
  137041. };
  137042. static static_codebook _44u8_p9_0 = {
  137043. 2, 81,
  137044. _vq_lengthlist__44u8_p9_0,
  137045. 1, -511895552, 1631393792, 4, 0,
  137046. _vq_quantlist__44u8_p9_0,
  137047. NULL,
  137048. &_vq_auxt__44u8_p9_0,
  137049. NULL,
  137050. 0
  137051. };
  137052. static long _vq_quantlist__44u8_p9_1[] = {
  137053. 9,
  137054. 8,
  137055. 10,
  137056. 7,
  137057. 11,
  137058. 6,
  137059. 12,
  137060. 5,
  137061. 13,
  137062. 4,
  137063. 14,
  137064. 3,
  137065. 15,
  137066. 2,
  137067. 16,
  137068. 1,
  137069. 17,
  137070. 0,
  137071. 18,
  137072. };
  137073. static long _vq_lengthlist__44u8_p9_1[] = {
  137074. 1, 4, 4, 7, 7, 8, 7, 8, 6, 9, 7,10, 8,11,10,11,
  137075. 11,11,11, 4, 7, 6, 9, 9,10, 9, 9, 9,10,10,11,10,
  137076. 11,10,11,11,13,11, 4, 7, 7, 9, 9, 9, 9, 9, 9,10,
  137077. 10,11,10,11,11,11,12,11,12, 7, 9, 8,11,11,11,11,
  137078. 10,10,11,11,12,12,12,12,12,12,14,13, 7, 8, 9,10,
  137079. 11,11,11,10,10,11,11,11,11,12,12,14,12,13,14, 8,
  137080. 9, 9,11,11,11,11,11,11,12,12,14,12,15,14,14,14,
  137081. 15,14, 8, 9, 9,11,11,11,11,12,11,12,12,13,13,13,
  137082. 13,13,13,14,14, 8, 9, 9,11,10,12,11,12,12,13,13,
  137083. 13,13,15,14,14,14,16,16, 8, 9, 9,10,11,11,12,12,
  137084. 12,13,13,13,14,14,14,15,16,15,15, 9,10,10,11,12,
  137085. 12,13,13,13,14,14,16,14,14,16,16,16,16,15, 9,10,
  137086. 10,11,11,12,13,13,14,15,14,16,14,15,16,16,16,16,
  137087. 15,10,11,11,12,13,13,14,15,15,15,15,15,16,15,16,
  137088. 15,16,15,15,10,11,11,13,13,14,13,13,15,14,15,15,
  137089. 16,15,15,15,16,15,16,10,12,12,14,14,14,14,14,16,
  137090. 16,15,15,15,16,16,16,16,16,16,11,12,12,14,14,14,
  137091. 14,15,15,16,15,16,15,16,15,16,16,16,16,12,12,13,
  137092. 14,14,15,16,16,16,16,16,16,15,16,16,16,16,16,16,
  137093. 12,13,13,14,14,14,14,15,16,15,16,16,16,16,16,16,
  137094. 16,16,16,12,13,14,14,14,16,15,16,15,16,16,16,16,
  137095. 16,16,16,16,16,16,12,14,13,14,15,15,15,16,15,16,
  137096. 16,15,16,16,16,16,16,16,16,
  137097. };
  137098. static float _vq_quantthresh__44u8_p9_1[] = {
  137099. -416.5, -367.5, -318.5, -269.5, -220.5, -171.5, -122.5, -73.5,
  137100. -24.5, 24.5, 73.5, 122.5, 171.5, 220.5, 269.5, 318.5,
  137101. 367.5, 416.5,
  137102. };
  137103. static long _vq_quantmap__44u8_p9_1[] = {
  137104. 17, 15, 13, 11, 9, 7, 5, 3,
  137105. 1, 0, 2, 4, 6, 8, 10, 12,
  137106. 14, 16, 18,
  137107. };
  137108. static encode_aux_threshmatch _vq_auxt__44u8_p9_1 = {
  137109. _vq_quantthresh__44u8_p9_1,
  137110. _vq_quantmap__44u8_p9_1,
  137111. 19,
  137112. 19
  137113. };
  137114. static static_codebook _44u8_p9_1 = {
  137115. 2, 361,
  137116. _vq_lengthlist__44u8_p9_1,
  137117. 1, -518287360, 1622704128, 5, 0,
  137118. _vq_quantlist__44u8_p9_1,
  137119. NULL,
  137120. &_vq_auxt__44u8_p9_1,
  137121. NULL,
  137122. 0
  137123. };
  137124. static long _vq_quantlist__44u8_p9_2[] = {
  137125. 24,
  137126. 23,
  137127. 25,
  137128. 22,
  137129. 26,
  137130. 21,
  137131. 27,
  137132. 20,
  137133. 28,
  137134. 19,
  137135. 29,
  137136. 18,
  137137. 30,
  137138. 17,
  137139. 31,
  137140. 16,
  137141. 32,
  137142. 15,
  137143. 33,
  137144. 14,
  137145. 34,
  137146. 13,
  137147. 35,
  137148. 12,
  137149. 36,
  137150. 11,
  137151. 37,
  137152. 10,
  137153. 38,
  137154. 9,
  137155. 39,
  137156. 8,
  137157. 40,
  137158. 7,
  137159. 41,
  137160. 6,
  137161. 42,
  137162. 5,
  137163. 43,
  137164. 4,
  137165. 44,
  137166. 3,
  137167. 45,
  137168. 2,
  137169. 46,
  137170. 1,
  137171. 47,
  137172. 0,
  137173. 48,
  137174. };
  137175. static long _vq_lengthlist__44u8_p9_2[] = {
  137176. 2, 3, 4, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6,
  137177. 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  137178. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  137179. 7,
  137180. };
  137181. static float _vq_quantthresh__44u8_p9_2[] = {
  137182. -23.5, -22.5, -21.5, -20.5, -19.5, -18.5, -17.5, -16.5,
  137183. -15.5, -14.5, -13.5, -12.5, -11.5, -10.5, -9.5, -8.5,
  137184. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  137185. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  137186. 8.5, 9.5, 10.5, 11.5, 12.5, 13.5, 14.5, 15.5,
  137187. 16.5, 17.5, 18.5, 19.5, 20.5, 21.5, 22.5, 23.5,
  137188. };
  137189. static long _vq_quantmap__44u8_p9_2[] = {
  137190. 47, 45, 43, 41, 39, 37, 35, 33,
  137191. 31, 29, 27, 25, 23, 21, 19, 17,
  137192. 15, 13, 11, 9, 7, 5, 3, 1,
  137193. 0, 2, 4, 6, 8, 10, 12, 14,
  137194. 16, 18, 20, 22, 24, 26, 28, 30,
  137195. 32, 34, 36, 38, 40, 42, 44, 46,
  137196. 48,
  137197. };
  137198. static encode_aux_threshmatch _vq_auxt__44u8_p9_2 = {
  137199. _vq_quantthresh__44u8_p9_2,
  137200. _vq_quantmap__44u8_p9_2,
  137201. 49,
  137202. 49
  137203. };
  137204. static static_codebook _44u8_p9_2 = {
  137205. 1, 49,
  137206. _vq_lengthlist__44u8_p9_2,
  137207. 1, -526909440, 1611661312, 6, 0,
  137208. _vq_quantlist__44u8_p9_2,
  137209. NULL,
  137210. &_vq_auxt__44u8_p9_2,
  137211. NULL,
  137212. 0
  137213. };
  137214. static long _huff_lengthlist__44u9__long[] = {
  137215. 3, 9,13,13,14,15,14,14,15,15, 5, 5, 9,10,12,12,
  137216. 13,14,16,15,10, 6, 6, 6, 8,11,12,13,16,15,11, 7,
  137217. 5, 3, 5, 8,10,12,15,15,10,10, 7, 4, 3, 5, 8,10,
  137218. 12,12,12,12, 9, 7, 5, 4, 6, 8,10,13,13,12,11, 9,
  137219. 7, 5, 5, 6, 9,12,14,12,12,10, 8, 6, 6, 6, 7,11,
  137220. 13,12,14,13,10, 8, 7, 7, 7,10,11,11,12,13,12,11,
  137221. 10, 8, 8, 9,
  137222. };
  137223. static static_codebook _huff_book__44u9__long = {
  137224. 2, 100,
  137225. _huff_lengthlist__44u9__long,
  137226. 0, 0, 0, 0, 0,
  137227. NULL,
  137228. NULL,
  137229. NULL,
  137230. NULL,
  137231. 0
  137232. };
  137233. static long _huff_lengthlist__44u9__short[] = {
  137234. 9,16,18,18,17,17,17,17,17,17, 5, 8,11,12,11,12,
  137235. 17,17,16,16, 6, 6, 8, 8, 9,10,14,15,16,16, 6, 7,
  137236. 7, 4, 6, 9,13,16,16,16, 6, 6, 7, 4, 5, 8,11,15,
  137237. 17,16, 7, 6, 7, 6, 6, 8, 9,10,14,16,11, 8, 8, 7,
  137238. 6, 6, 3, 4,10,15,14,12,12,10, 5, 6, 3, 3, 8,13,
  137239. 15,17,15,11, 6, 8, 6, 6, 9,14,17,15,15,12, 8,10,
  137240. 9, 9,12,15,
  137241. };
  137242. static static_codebook _huff_book__44u9__short = {
  137243. 2, 100,
  137244. _huff_lengthlist__44u9__short,
  137245. 0, 0, 0, 0, 0,
  137246. NULL,
  137247. NULL,
  137248. NULL,
  137249. NULL,
  137250. 0
  137251. };
  137252. static long _vq_quantlist__44u9_p1_0[] = {
  137253. 1,
  137254. 0,
  137255. 2,
  137256. };
  137257. static long _vq_lengthlist__44u9_p1_0[] = {
  137258. 1, 5, 5, 5, 7, 7, 5, 7, 7, 5, 7, 7, 7, 9, 9, 7,
  137259. 9, 9, 5, 7, 7, 7, 9, 9, 7, 9, 9, 5, 7, 7, 7, 9,
  137260. 9, 7, 9, 9, 8, 9, 9, 9,10,11, 9,11,11, 7, 9, 9,
  137261. 9,11,10, 9,11,11, 5, 7, 7, 7, 9, 9, 8, 9,10, 7,
  137262. 9, 9, 9,11,11, 9,10,11, 7, 9,10, 9,11,11, 9,11,
  137263. 10,
  137264. };
  137265. static float _vq_quantthresh__44u9_p1_0[] = {
  137266. -0.5, 0.5,
  137267. };
  137268. static long _vq_quantmap__44u9_p1_0[] = {
  137269. 1, 0, 2,
  137270. };
  137271. static encode_aux_threshmatch _vq_auxt__44u9_p1_0 = {
  137272. _vq_quantthresh__44u9_p1_0,
  137273. _vq_quantmap__44u9_p1_0,
  137274. 3,
  137275. 3
  137276. };
  137277. static static_codebook _44u9_p1_0 = {
  137278. 4, 81,
  137279. _vq_lengthlist__44u9_p1_0,
  137280. 1, -535822336, 1611661312, 2, 0,
  137281. _vq_quantlist__44u9_p1_0,
  137282. NULL,
  137283. &_vq_auxt__44u9_p1_0,
  137284. NULL,
  137285. 0
  137286. };
  137287. static long _vq_quantlist__44u9_p2_0[] = {
  137288. 2,
  137289. 1,
  137290. 3,
  137291. 0,
  137292. 4,
  137293. };
  137294. static long _vq_lengthlist__44u9_p2_0[] = {
  137295. 3, 5, 5, 8, 8, 5, 7, 7, 9, 9, 6, 7, 7, 9, 9, 8,
  137296. 9, 9,11,10, 8, 9, 9,11,11, 6, 7, 7, 9, 9, 7, 8,
  137297. 8,10,10, 7, 8, 8, 9,10, 9,10,10,11,11, 9, 9,10,
  137298. 11,11, 6, 7, 7, 9, 9, 7, 8, 8,10, 9, 7, 8, 8,10,
  137299. 10, 9,10, 9,11,11, 9,10,10,11,11, 8, 9, 9,11,11,
  137300. 9,10,10,12,11, 9,10,10,11,12,11,11,11,13,13,11,
  137301. 11,11,12,13, 8, 9, 9,11,11, 9,10,10,11,11, 9,10,
  137302. 10,12,11,11,12,11,13,12,11,11,12,13,13, 6, 7, 7,
  137303. 9, 9, 7, 8, 8,10,10, 7, 8, 8,10,10, 9,10,10,12,
  137304. 11, 9,10,10,11,12, 7, 8, 8,10,10, 8, 9, 9,11,11,
  137305. 8, 9, 9,10,10,10,11,11,12,12,10,10,11,12,12, 7,
  137306. 8, 8,10,10, 8, 9, 8,10,10, 8, 9, 9,10,10,10,11,
  137307. 10,12,11,10,10,11,12,12, 9,10,10,11,12,10,11,11,
  137308. 12,12,10,11,10,12,12,12,12,12,13,13,11,12,12,13,
  137309. 13, 9,10,10,11,11, 9,10,10,12,12,10,11,11,12,13,
  137310. 11,12,11,13,12,12,12,12,13,14, 6, 7, 7, 9, 9, 7,
  137311. 8, 8,10,10, 7, 8, 8,10,10, 9,10,10,11,11, 9,10,
  137312. 10,11,12, 7, 8, 8,10,10, 8, 9, 9,11,10, 8, 8, 9,
  137313. 10,10,10,11,10,12,12,10,10,11,11,12, 7, 8, 8,10,
  137314. 10, 8, 9, 9,10,10, 8, 9, 9,10,10,10,11,10,12,12,
  137315. 10,11,10,12,12, 9,10,10,12,11,10,11,11,12,12, 9,
  137316. 10,10,12,12,12,12,12,13,13,11,11,12,12,14, 9,10,
  137317. 10,11,12,10,11,11,12,12,10,11,11,12,12,11,12,12,
  137318. 14,14,12,12,12,13,13, 8, 9, 9,11,11, 9,10,10,12,
  137319. 11, 9,10,10,12,12,11,12,11,13,13,11,11,12,13,13,
  137320. 9,10,10,12,12,10,11,11,12,12,10,11,11,12,12,12,
  137321. 12,12,14,14,12,12,12,13,13, 9,10,10,12,11,10,11,
  137322. 10,12,12,10,11,11,12,12,11,12,12,14,13,12,12,12,
  137323. 13,14,11,12,11,13,13,11,12,12,13,13,12,12,12,14,
  137324. 14,13,13,13,13,15,13,13,14,15,15,11,11,11,13,13,
  137325. 11,12,11,13,13,11,12,12,13,13,12,13,12,15,13,13,
  137326. 13,14,14,15, 8, 9, 9,11,11, 9,10,10,11,12, 9,10,
  137327. 10,11,12,11,12,11,13,13,11,12,12,13,13, 9,10,10,
  137328. 11,12,10,11,10,12,12,10,10,11,12,13,12,12,12,14,
  137329. 13,11,12,12,13,14, 9,10,10,12,12,10,11,11,12,12,
  137330. 10,11,11,12,12,12,12,12,14,13,12,12,12,14,13,11,
  137331. 11,11,13,13,11,12,12,14,13,11,11,12,13,13,13,13,
  137332. 13,15,14,12,12,13,13,15,11,12,12,13,13,12,12,12,
  137333. 13,14,11,12,12,13,13,13,13,14,14,15,13,13,13,14,
  137334. 14,
  137335. };
  137336. static float _vq_quantthresh__44u9_p2_0[] = {
  137337. -1.5, -0.5, 0.5, 1.5,
  137338. };
  137339. static long _vq_quantmap__44u9_p2_0[] = {
  137340. 3, 1, 0, 2, 4,
  137341. };
  137342. static encode_aux_threshmatch _vq_auxt__44u9_p2_0 = {
  137343. _vq_quantthresh__44u9_p2_0,
  137344. _vq_quantmap__44u9_p2_0,
  137345. 5,
  137346. 5
  137347. };
  137348. static static_codebook _44u9_p2_0 = {
  137349. 4, 625,
  137350. _vq_lengthlist__44u9_p2_0,
  137351. 1, -533725184, 1611661312, 3, 0,
  137352. _vq_quantlist__44u9_p2_0,
  137353. NULL,
  137354. &_vq_auxt__44u9_p2_0,
  137355. NULL,
  137356. 0
  137357. };
  137358. static long _vq_quantlist__44u9_p3_0[] = {
  137359. 4,
  137360. 3,
  137361. 5,
  137362. 2,
  137363. 6,
  137364. 1,
  137365. 7,
  137366. 0,
  137367. 8,
  137368. };
  137369. static long _vq_lengthlist__44u9_p3_0[] = {
  137370. 3, 4, 4, 5, 5, 7, 7, 8, 8, 4, 5, 5, 6, 6, 7, 7,
  137371. 9, 9, 4, 4, 5, 6, 6, 7, 7, 9, 9, 5, 6, 6, 7, 7,
  137372. 8, 8, 9, 9, 5, 6, 6, 7, 7, 8, 8, 9, 9, 7, 7, 7,
  137373. 8, 8, 9, 9,10,10, 7, 7, 7, 8, 8, 9, 9,10,10, 8,
  137374. 9, 9,10, 9,10,10,11,11, 8, 9, 9, 9,10,10,10,11,
  137375. 11,
  137376. };
  137377. static float _vq_quantthresh__44u9_p3_0[] = {
  137378. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  137379. };
  137380. static long _vq_quantmap__44u9_p3_0[] = {
  137381. 7, 5, 3, 1, 0, 2, 4, 6,
  137382. 8,
  137383. };
  137384. static encode_aux_threshmatch _vq_auxt__44u9_p3_0 = {
  137385. _vq_quantthresh__44u9_p3_0,
  137386. _vq_quantmap__44u9_p3_0,
  137387. 9,
  137388. 9
  137389. };
  137390. static static_codebook _44u9_p3_0 = {
  137391. 2, 81,
  137392. _vq_lengthlist__44u9_p3_0,
  137393. 1, -531628032, 1611661312, 4, 0,
  137394. _vq_quantlist__44u9_p3_0,
  137395. NULL,
  137396. &_vq_auxt__44u9_p3_0,
  137397. NULL,
  137398. 0
  137399. };
  137400. static long _vq_quantlist__44u9_p4_0[] = {
  137401. 8,
  137402. 7,
  137403. 9,
  137404. 6,
  137405. 10,
  137406. 5,
  137407. 11,
  137408. 4,
  137409. 12,
  137410. 3,
  137411. 13,
  137412. 2,
  137413. 14,
  137414. 1,
  137415. 15,
  137416. 0,
  137417. 16,
  137418. };
  137419. static long _vq_lengthlist__44u9_p4_0[] = {
  137420. 4, 5, 5, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,10,11,
  137421. 11, 5, 5, 5, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,10,
  137422. 11,11, 5, 5, 5, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,
  137423. 10,11,11, 6, 6, 6, 7, 6, 7, 7, 8, 8, 9, 9,10,10,
  137424. 11,11,12,11, 6, 6, 6, 6, 7, 7, 7, 8, 8, 9, 9,10,
  137425. 10,11,11,11,12, 7, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9,
  137426. 10,10,11,11,12,12, 7, 7, 7, 7, 7, 8, 8, 9, 9, 9,
  137427. 9,10,10,11,11,12,12, 8, 8, 8, 8, 8, 9, 8,10, 9,
  137428. 10,10,11,10,12,11,13,12, 8, 8, 8, 8, 8, 9, 9, 9,
  137429. 10,10,10,10,11,11,12,12,12, 8, 8, 8, 9, 9, 9, 9,
  137430. 10,10,11,10,12,11,12,12,13,12, 8, 8, 8, 9, 9, 9,
  137431. 9,10,10,10,11,11,11,12,12,12,13, 9, 9, 9,10,10,
  137432. 10,10,11,10,11,11,12,11,13,12,13,13, 9, 9,10,10,
  137433. 10,10,10,10,11,11,11,11,12,12,13,13,13,10,11,10,
  137434. 11,11,11,11,12,11,12,12,13,12,13,13,14,13,10,10,
  137435. 10,11,11,11,11,11,12,12,12,12,13,13,13,13,14,11,
  137436. 11,11,12,11,12,12,12,12,13,13,13,13,14,13,14,14,
  137437. 11,11,11,11,12,12,12,12,12,12,13,13,13,13,14,14,
  137438. 14,
  137439. };
  137440. static float _vq_quantthresh__44u9_p4_0[] = {
  137441. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  137442. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  137443. };
  137444. static long _vq_quantmap__44u9_p4_0[] = {
  137445. 15, 13, 11, 9, 7, 5, 3, 1,
  137446. 0, 2, 4, 6, 8, 10, 12, 14,
  137447. 16,
  137448. };
  137449. static encode_aux_threshmatch _vq_auxt__44u9_p4_0 = {
  137450. _vq_quantthresh__44u9_p4_0,
  137451. _vq_quantmap__44u9_p4_0,
  137452. 17,
  137453. 17
  137454. };
  137455. static static_codebook _44u9_p4_0 = {
  137456. 2, 289,
  137457. _vq_lengthlist__44u9_p4_0,
  137458. 1, -529530880, 1611661312, 5, 0,
  137459. _vq_quantlist__44u9_p4_0,
  137460. NULL,
  137461. &_vq_auxt__44u9_p4_0,
  137462. NULL,
  137463. 0
  137464. };
  137465. static long _vq_quantlist__44u9_p5_0[] = {
  137466. 1,
  137467. 0,
  137468. 2,
  137469. };
  137470. static long _vq_lengthlist__44u9_p5_0[] = {
  137471. 1, 4, 4, 5, 7, 7, 5, 7, 7, 5, 8, 8, 8, 9, 9, 7,
  137472. 9, 9, 5, 8, 8, 7, 9, 9, 8, 9, 9, 5, 8, 8, 8,10,
  137473. 10, 8,10,10, 7,10,10, 9,10,12, 9,11,11, 7,10,10,
  137474. 9,11,10, 9,11,12, 5, 8, 8, 8,10,10, 8,10,10, 7,
  137475. 10,10, 9,12,11, 9,10,11, 7,10,10, 9,11,11,10,12,
  137476. 10,
  137477. };
  137478. static float _vq_quantthresh__44u9_p5_0[] = {
  137479. -5.5, 5.5,
  137480. };
  137481. static long _vq_quantmap__44u9_p5_0[] = {
  137482. 1, 0, 2,
  137483. };
  137484. static encode_aux_threshmatch _vq_auxt__44u9_p5_0 = {
  137485. _vq_quantthresh__44u9_p5_0,
  137486. _vq_quantmap__44u9_p5_0,
  137487. 3,
  137488. 3
  137489. };
  137490. static static_codebook _44u9_p5_0 = {
  137491. 4, 81,
  137492. _vq_lengthlist__44u9_p5_0,
  137493. 1, -529137664, 1618345984, 2, 0,
  137494. _vq_quantlist__44u9_p5_0,
  137495. NULL,
  137496. &_vq_auxt__44u9_p5_0,
  137497. NULL,
  137498. 0
  137499. };
  137500. static long _vq_quantlist__44u9_p5_1[] = {
  137501. 5,
  137502. 4,
  137503. 6,
  137504. 3,
  137505. 7,
  137506. 2,
  137507. 8,
  137508. 1,
  137509. 9,
  137510. 0,
  137511. 10,
  137512. };
  137513. static long _vq_lengthlist__44u9_p5_1[] = {
  137514. 5, 5, 5, 6, 6, 7, 7, 7, 7, 7, 7, 5, 6, 6, 6, 6,
  137515. 7, 7, 7, 7, 8, 7, 5, 6, 6, 6, 6, 7, 7, 7, 7, 7,
  137516. 7, 6, 6, 6, 7, 7, 7, 7, 7, 7, 8, 8, 6, 6, 6, 7,
  137517. 7, 7, 7, 7, 7, 8, 8, 7, 7, 7, 7, 7, 8, 7, 8, 8,
  137518. 8, 8, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 7, 7, 7,
  137519. 8, 7, 8, 8, 8, 8, 8, 8, 7, 7, 7, 7, 8, 8, 8, 8,
  137520. 8, 8, 8, 7, 8, 7, 8, 8, 8, 8, 8, 8, 8, 8, 7, 8,
  137521. 8, 8, 8, 8, 8, 8, 8, 8, 8,
  137522. };
  137523. static float _vq_quantthresh__44u9_p5_1[] = {
  137524. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  137525. 3.5, 4.5,
  137526. };
  137527. static long _vq_quantmap__44u9_p5_1[] = {
  137528. 9, 7, 5, 3, 1, 0, 2, 4,
  137529. 6, 8, 10,
  137530. };
  137531. static encode_aux_threshmatch _vq_auxt__44u9_p5_1 = {
  137532. _vq_quantthresh__44u9_p5_1,
  137533. _vq_quantmap__44u9_p5_1,
  137534. 11,
  137535. 11
  137536. };
  137537. static static_codebook _44u9_p5_1 = {
  137538. 2, 121,
  137539. _vq_lengthlist__44u9_p5_1,
  137540. 1, -531365888, 1611661312, 4, 0,
  137541. _vq_quantlist__44u9_p5_1,
  137542. NULL,
  137543. &_vq_auxt__44u9_p5_1,
  137544. NULL,
  137545. 0
  137546. };
  137547. static long _vq_quantlist__44u9_p6_0[] = {
  137548. 6,
  137549. 5,
  137550. 7,
  137551. 4,
  137552. 8,
  137553. 3,
  137554. 9,
  137555. 2,
  137556. 10,
  137557. 1,
  137558. 11,
  137559. 0,
  137560. 12,
  137561. };
  137562. static long _vq_lengthlist__44u9_p6_0[] = {
  137563. 2, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9,10,10, 4, 6, 5,
  137564. 7, 7, 8, 8, 8, 8, 9, 9,10,10, 4, 5, 6, 7, 7, 8,
  137565. 8, 8, 8, 9, 9,10,10, 6, 7, 7, 8, 8, 8, 8, 9, 9,
  137566. 10,10,10,10, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,10,10,
  137567. 10, 7, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,11, 7, 8,
  137568. 8, 8, 8, 9, 9, 9, 9,10,10,11,11, 8, 8, 8, 9, 9,
  137569. 9, 9, 9,10,10,10,11,11, 8, 8, 8, 9, 9, 9, 9,10,
  137570. 9,10,10,11,11, 9, 9, 9,10,10,10,10,10,11,11,11,
  137571. 11,12, 9, 9, 9,10,10,10,10,10,10,11,10,12,11,10,
  137572. 10,10,10,10,11,11,11,11,11,12,12,12,10,10,10,10,
  137573. 10,11,11,11,11,12,11,12,12,
  137574. };
  137575. static float _vq_quantthresh__44u9_p6_0[] = {
  137576. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  137577. 12.5, 17.5, 22.5, 27.5,
  137578. };
  137579. static long _vq_quantmap__44u9_p6_0[] = {
  137580. 11, 9, 7, 5, 3, 1, 0, 2,
  137581. 4, 6, 8, 10, 12,
  137582. };
  137583. static encode_aux_threshmatch _vq_auxt__44u9_p6_0 = {
  137584. _vq_quantthresh__44u9_p6_0,
  137585. _vq_quantmap__44u9_p6_0,
  137586. 13,
  137587. 13
  137588. };
  137589. static static_codebook _44u9_p6_0 = {
  137590. 2, 169,
  137591. _vq_lengthlist__44u9_p6_0,
  137592. 1, -526516224, 1616117760, 4, 0,
  137593. _vq_quantlist__44u9_p6_0,
  137594. NULL,
  137595. &_vq_auxt__44u9_p6_0,
  137596. NULL,
  137597. 0
  137598. };
  137599. static long _vq_quantlist__44u9_p6_1[] = {
  137600. 2,
  137601. 1,
  137602. 3,
  137603. 0,
  137604. 4,
  137605. };
  137606. static long _vq_lengthlist__44u9_p6_1[] = {
  137607. 4, 4, 4, 5, 5, 4, 5, 4, 5, 5, 4, 4, 5, 5, 5, 5,
  137608. 5, 5, 5, 5, 5, 5, 5, 5, 5,
  137609. };
  137610. static float _vq_quantthresh__44u9_p6_1[] = {
  137611. -1.5, -0.5, 0.5, 1.5,
  137612. };
  137613. static long _vq_quantmap__44u9_p6_1[] = {
  137614. 3, 1, 0, 2, 4,
  137615. };
  137616. static encode_aux_threshmatch _vq_auxt__44u9_p6_1 = {
  137617. _vq_quantthresh__44u9_p6_1,
  137618. _vq_quantmap__44u9_p6_1,
  137619. 5,
  137620. 5
  137621. };
  137622. static static_codebook _44u9_p6_1 = {
  137623. 2, 25,
  137624. _vq_lengthlist__44u9_p6_1,
  137625. 1, -533725184, 1611661312, 3, 0,
  137626. _vq_quantlist__44u9_p6_1,
  137627. NULL,
  137628. &_vq_auxt__44u9_p6_1,
  137629. NULL,
  137630. 0
  137631. };
  137632. static long _vq_quantlist__44u9_p7_0[] = {
  137633. 6,
  137634. 5,
  137635. 7,
  137636. 4,
  137637. 8,
  137638. 3,
  137639. 9,
  137640. 2,
  137641. 10,
  137642. 1,
  137643. 11,
  137644. 0,
  137645. 12,
  137646. };
  137647. static long _vq_lengthlist__44u9_p7_0[] = {
  137648. 1, 4, 5, 6, 6, 7, 7, 8, 9,10,10,11,11, 5, 6, 6,
  137649. 7, 7, 8, 8, 9, 9,10,10,11,11, 5, 6, 6, 7, 7, 8,
  137650. 8, 9, 9,10,10,11,11, 6, 7, 7, 8, 8, 9, 9,10,10,
  137651. 11,11,12,12, 6, 7, 7, 8, 8, 9, 9,10,10,11,11,12,
  137652. 12, 8, 8, 8, 9, 9,10,10,11,11,12,12,13,13, 8, 8,
  137653. 8, 9, 9,10,10,11,11,12,12,13,13, 9, 9, 9,10,10,
  137654. 11,11,12,12,13,13,13,13, 9, 9, 9,10,10,11,11,12,
  137655. 12,13,13,14,14,10,10,10,11,11,12,12,13,13,14,13,
  137656. 15,14,10,10,10,11,11,12,12,13,13,14,14,14,14,11,
  137657. 11,12,12,12,13,13,14,14,14,14,15,15,11,11,12,12,
  137658. 12,13,13,14,14,14,15,15,15,
  137659. };
  137660. static float _vq_quantthresh__44u9_p7_0[] = {
  137661. -60.5, -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5,
  137662. 27.5, 38.5, 49.5, 60.5,
  137663. };
  137664. static long _vq_quantmap__44u9_p7_0[] = {
  137665. 11, 9, 7, 5, 3, 1, 0, 2,
  137666. 4, 6, 8, 10, 12,
  137667. };
  137668. static encode_aux_threshmatch _vq_auxt__44u9_p7_0 = {
  137669. _vq_quantthresh__44u9_p7_0,
  137670. _vq_quantmap__44u9_p7_0,
  137671. 13,
  137672. 13
  137673. };
  137674. static static_codebook _44u9_p7_0 = {
  137675. 2, 169,
  137676. _vq_lengthlist__44u9_p7_0,
  137677. 1, -523206656, 1618345984, 4, 0,
  137678. _vq_quantlist__44u9_p7_0,
  137679. NULL,
  137680. &_vq_auxt__44u9_p7_0,
  137681. NULL,
  137682. 0
  137683. };
  137684. static long _vq_quantlist__44u9_p7_1[] = {
  137685. 5,
  137686. 4,
  137687. 6,
  137688. 3,
  137689. 7,
  137690. 2,
  137691. 8,
  137692. 1,
  137693. 9,
  137694. 0,
  137695. 10,
  137696. };
  137697. static long _vq_lengthlist__44u9_p7_1[] = {
  137698. 5, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 6, 6, 6, 7, 7,
  137699. 7, 7, 7, 7, 7, 7, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7,
  137700. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 6, 7, 7, 7,
  137701. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  137702. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  137703. 7, 7, 7, 7, 8, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  137704. 7, 8, 8, 7, 7, 7, 7, 7, 7, 7, 8, 7, 8, 8, 7, 7,
  137705. 7, 7, 7, 7, 7, 8, 8, 8, 8,
  137706. };
  137707. static float _vq_quantthresh__44u9_p7_1[] = {
  137708. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  137709. 3.5, 4.5,
  137710. };
  137711. static long _vq_quantmap__44u9_p7_1[] = {
  137712. 9, 7, 5, 3, 1, 0, 2, 4,
  137713. 6, 8, 10,
  137714. };
  137715. static encode_aux_threshmatch _vq_auxt__44u9_p7_1 = {
  137716. _vq_quantthresh__44u9_p7_1,
  137717. _vq_quantmap__44u9_p7_1,
  137718. 11,
  137719. 11
  137720. };
  137721. static static_codebook _44u9_p7_1 = {
  137722. 2, 121,
  137723. _vq_lengthlist__44u9_p7_1,
  137724. 1, -531365888, 1611661312, 4, 0,
  137725. _vq_quantlist__44u9_p7_1,
  137726. NULL,
  137727. &_vq_auxt__44u9_p7_1,
  137728. NULL,
  137729. 0
  137730. };
  137731. static long _vq_quantlist__44u9_p8_0[] = {
  137732. 7,
  137733. 6,
  137734. 8,
  137735. 5,
  137736. 9,
  137737. 4,
  137738. 10,
  137739. 3,
  137740. 11,
  137741. 2,
  137742. 12,
  137743. 1,
  137744. 13,
  137745. 0,
  137746. 14,
  137747. };
  137748. static long _vq_lengthlist__44u9_p8_0[] = {
  137749. 1, 4, 4, 7, 7, 8, 8, 8, 8, 9, 9,10, 9,11,10, 4,
  137750. 6, 6, 8, 8, 9, 9, 9, 9,10,10,11,10,12,10, 4, 6,
  137751. 6, 8, 8, 9,10, 9, 9,10,10,11,11,12,12, 7, 8, 8,
  137752. 10,10,11,11,10,10,11,11,12,12,13,12, 7, 8, 8,10,
  137753. 10,11,11,10,10,11,11,12,12,12,13, 8,10, 9,11,11,
  137754. 12,12,11,11,12,12,13,13,14,13, 8, 9, 9,11,11,12,
  137755. 12,11,12,12,12,13,13,14,13, 8, 9, 9,10,10,12,11,
  137756. 13,12,13,13,14,13,15,14, 8, 9, 9,10,10,11,12,12,
  137757. 12,13,13,13,14,14,14, 9,10,10,12,11,13,12,13,13,
  137758. 14,13,14,14,14,15, 9,10,10,11,12,12,12,13,13,14,
  137759. 14,14,15,15,15,10,11,11,12,12,13,13,14,14,14,14,
  137760. 15,14,16,15,10,11,11,12,12,13,13,13,14,14,14,14,
  137761. 14,15,16,11,12,12,13,13,14,13,14,14,15,14,15,16,
  137762. 16,16,11,12,12,13,13,14,13,14,14,15,15,15,16,15,
  137763. 15,
  137764. };
  137765. static float _vq_quantthresh__44u9_p8_0[] = {
  137766. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  137767. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  137768. };
  137769. static long _vq_quantmap__44u9_p8_0[] = {
  137770. 13, 11, 9, 7, 5, 3, 1, 0,
  137771. 2, 4, 6, 8, 10, 12, 14,
  137772. };
  137773. static encode_aux_threshmatch _vq_auxt__44u9_p8_0 = {
  137774. _vq_quantthresh__44u9_p8_0,
  137775. _vq_quantmap__44u9_p8_0,
  137776. 15,
  137777. 15
  137778. };
  137779. static static_codebook _44u9_p8_0 = {
  137780. 2, 225,
  137781. _vq_lengthlist__44u9_p8_0,
  137782. 1, -520986624, 1620377600, 4, 0,
  137783. _vq_quantlist__44u9_p8_0,
  137784. NULL,
  137785. &_vq_auxt__44u9_p8_0,
  137786. NULL,
  137787. 0
  137788. };
  137789. static long _vq_quantlist__44u9_p8_1[] = {
  137790. 10,
  137791. 9,
  137792. 11,
  137793. 8,
  137794. 12,
  137795. 7,
  137796. 13,
  137797. 6,
  137798. 14,
  137799. 5,
  137800. 15,
  137801. 4,
  137802. 16,
  137803. 3,
  137804. 17,
  137805. 2,
  137806. 18,
  137807. 1,
  137808. 19,
  137809. 0,
  137810. 20,
  137811. };
  137812. static long _vq_lengthlist__44u9_p8_1[] = {
  137813. 4, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9,
  137814. 9, 9, 9, 9, 9, 6, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,
  137815. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 6, 6, 6, 7, 7, 8,
  137816. 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 7,
  137817. 7, 7, 8, 8, 8, 8, 9, 8, 9, 9, 9, 9, 9, 9, 9, 9,
  137818. 9, 9, 9, 9, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  137819. 9, 9, 9, 9, 9, 9, 9, 9, 9, 8, 8, 8, 8, 8, 9, 9,
  137820. 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 9,10,10,10, 8, 8,
  137821. 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  137822. 9,10,10, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  137823. 10, 9,10, 9,10,10,10,10, 8, 8, 8, 9, 9, 9, 9, 9,
  137824. 9, 9, 9, 9, 9,10,10, 9,10,10,10,10,10, 9, 9, 9,
  137825. 9, 9, 9, 9, 9, 9, 9, 9,10, 9,10,10,10,10,10,10,
  137826. 10,10, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,
  137827. 10,10,10,10,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  137828. 9, 9,10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9,
  137829. 9, 9, 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,
  137830. 10, 9, 9, 9, 9, 9, 9, 9,10, 9,10,10,10,10,10,10,
  137831. 10,10,10,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9,10,10,
  137832. 10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9,
  137833. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  137834. 9, 9, 9, 9,10, 9, 9,10,10,10,10,10,10,10,10,10,
  137835. 10,10,10,10,10, 9, 9, 9,10, 9,10, 9,10,10,10,10,
  137836. 10,10,10,10,10,10,10,10,10,10, 9, 9, 9,10, 9,10,
  137837. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10, 9,
  137838. 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,10,10,10,
  137839. 10,10,10,10, 9, 9, 9,10,10,10,10,10,10,10,10,10,
  137840. 10,10,10,10,10,10,10,10,10,
  137841. };
  137842. static float _vq_quantthresh__44u9_p8_1[] = {
  137843. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  137844. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  137845. 6.5, 7.5, 8.5, 9.5,
  137846. };
  137847. static long _vq_quantmap__44u9_p8_1[] = {
  137848. 19, 17, 15, 13, 11, 9, 7, 5,
  137849. 3, 1, 0, 2, 4, 6, 8, 10,
  137850. 12, 14, 16, 18, 20,
  137851. };
  137852. static encode_aux_threshmatch _vq_auxt__44u9_p8_1 = {
  137853. _vq_quantthresh__44u9_p8_1,
  137854. _vq_quantmap__44u9_p8_1,
  137855. 21,
  137856. 21
  137857. };
  137858. static static_codebook _44u9_p8_1 = {
  137859. 2, 441,
  137860. _vq_lengthlist__44u9_p8_1,
  137861. 1, -529268736, 1611661312, 5, 0,
  137862. _vq_quantlist__44u9_p8_1,
  137863. NULL,
  137864. &_vq_auxt__44u9_p8_1,
  137865. NULL,
  137866. 0
  137867. };
  137868. static long _vq_quantlist__44u9_p9_0[] = {
  137869. 7,
  137870. 6,
  137871. 8,
  137872. 5,
  137873. 9,
  137874. 4,
  137875. 10,
  137876. 3,
  137877. 11,
  137878. 2,
  137879. 12,
  137880. 1,
  137881. 13,
  137882. 0,
  137883. 14,
  137884. };
  137885. static long _vq_lengthlist__44u9_p9_0[] = {
  137886. 1, 3, 3,11,11,11,11,11,11,11,11,11,11,11,11, 4,
  137887. 10,11,11,11,11,11,11,11,11,11,11,11,11,11, 4,10,
  137888. 10,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  137889. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  137890. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  137891. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  137892. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  137893. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  137894. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  137895. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  137896. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  137897. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  137898. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  137899. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  137900. 10,
  137901. };
  137902. static float _vq_quantthresh__44u9_p9_0[] = {
  137903. -6051.5, -5120.5, -4189.5, -3258.5, -2327.5, -1396.5, -465.5, 465.5,
  137904. 1396.5, 2327.5, 3258.5, 4189.5, 5120.5, 6051.5,
  137905. };
  137906. static long _vq_quantmap__44u9_p9_0[] = {
  137907. 13, 11, 9, 7, 5, 3, 1, 0,
  137908. 2, 4, 6, 8, 10, 12, 14,
  137909. };
  137910. static encode_aux_threshmatch _vq_auxt__44u9_p9_0 = {
  137911. _vq_quantthresh__44u9_p9_0,
  137912. _vq_quantmap__44u9_p9_0,
  137913. 15,
  137914. 15
  137915. };
  137916. static static_codebook _44u9_p9_0 = {
  137917. 2, 225,
  137918. _vq_lengthlist__44u9_p9_0,
  137919. 1, -510036736, 1631393792, 4, 0,
  137920. _vq_quantlist__44u9_p9_0,
  137921. NULL,
  137922. &_vq_auxt__44u9_p9_0,
  137923. NULL,
  137924. 0
  137925. };
  137926. static long _vq_quantlist__44u9_p9_1[] = {
  137927. 9,
  137928. 8,
  137929. 10,
  137930. 7,
  137931. 11,
  137932. 6,
  137933. 12,
  137934. 5,
  137935. 13,
  137936. 4,
  137937. 14,
  137938. 3,
  137939. 15,
  137940. 2,
  137941. 16,
  137942. 1,
  137943. 17,
  137944. 0,
  137945. 18,
  137946. };
  137947. static long _vq_lengthlist__44u9_p9_1[] = {
  137948. 1, 4, 4, 7, 7, 8, 7, 8, 7, 9, 8,10, 9,10,10,11,
  137949. 11,12,12, 4, 7, 6, 9, 9,10, 9, 9, 8,10,10,11,10,
  137950. 12,10,13,12,13,12, 4, 6, 6, 9, 9, 9, 9, 9, 9,10,
  137951. 10,11,11,11,12,12,12,12,12, 7, 9, 8,11,10,10,10,
  137952. 11,10,11,11,12,12,13,12,13,13,13,13, 7, 8, 9,10,
  137953. 10,11,11,10,10,11,11,11,12,13,13,13,13,14,14, 8,
  137954. 9, 9,11,11,12,11,12,12,13,12,12,13,13,14,15,14,
  137955. 14,14, 8, 9, 9,10,11,11,11,12,12,13,12,13,13,14,
  137956. 14,14,15,14,16, 8, 9, 9,11,10,12,12,12,12,15,13,
  137957. 13,13,17,14,15,15,15,14, 8, 9, 9,10,11,11,12,13,
  137958. 12,13,13,13,14,15,14,14,14,16,15, 9,11,10,12,12,
  137959. 13,13,13,13,14,14,16,15,14,14,14,15,15,17, 9,10,
  137960. 10,11,11,13,13,13,14,14,13,15,14,15,14,15,16,15,
  137961. 16,10,11,11,12,12,13,14,15,14,15,14,14,15,17,16,
  137962. 15,15,17,17,10,12,11,13,12,14,14,13,14,15,15,15,
  137963. 15,16,17,17,15,17,16,11,12,12,14,13,15,14,15,16,
  137964. 17,15,17,15,17,15,15,16,17,15,11,11,12,14,14,14,
  137965. 14,14,15,15,16,15,17,17,17,16,17,16,15,12,12,13,
  137966. 14,14,14,15,14,15,15,16,16,17,16,17,15,17,17,16,
  137967. 12,14,12,14,14,15,15,15,14,14,16,16,16,15,16,16,
  137968. 15,17,15,12,13,13,14,15,14,15,17,15,17,16,17,17,
  137969. 17,16,17,16,17,17,12,13,13,14,16,15,15,15,16,15,
  137970. 17,17,15,17,15,17,16,16,17,
  137971. };
  137972. static float _vq_quantthresh__44u9_p9_1[] = {
  137973. -416.5, -367.5, -318.5, -269.5, -220.5, -171.5, -122.5, -73.5,
  137974. -24.5, 24.5, 73.5, 122.5, 171.5, 220.5, 269.5, 318.5,
  137975. 367.5, 416.5,
  137976. };
  137977. static long _vq_quantmap__44u9_p9_1[] = {
  137978. 17, 15, 13, 11, 9, 7, 5, 3,
  137979. 1, 0, 2, 4, 6, 8, 10, 12,
  137980. 14, 16, 18,
  137981. };
  137982. static encode_aux_threshmatch _vq_auxt__44u9_p9_1 = {
  137983. _vq_quantthresh__44u9_p9_1,
  137984. _vq_quantmap__44u9_p9_1,
  137985. 19,
  137986. 19
  137987. };
  137988. static static_codebook _44u9_p9_1 = {
  137989. 2, 361,
  137990. _vq_lengthlist__44u9_p9_1,
  137991. 1, -518287360, 1622704128, 5, 0,
  137992. _vq_quantlist__44u9_p9_1,
  137993. NULL,
  137994. &_vq_auxt__44u9_p9_1,
  137995. NULL,
  137996. 0
  137997. };
  137998. static long _vq_quantlist__44u9_p9_2[] = {
  137999. 24,
  138000. 23,
  138001. 25,
  138002. 22,
  138003. 26,
  138004. 21,
  138005. 27,
  138006. 20,
  138007. 28,
  138008. 19,
  138009. 29,
  138010. 18,
  138011. 30,
  138012. 17,
  138013. 31,
  138014. 16,
  138015. 32,
  138016. 15,
  138017. 33,
  138018. 14,
  138019. 34,
  138020. 13,
  138021. 35,
  138022. 12,
  138023. 36,
  138024. 11,
  138025. 37,
  138026. 10,
  138027. 38,
  138028. 9,
  138029. 39,
  138030. 8,
  138031. 40,
  138032. 7,
  138033. 41,
  138034. 6,
  138035. 42,
  138036. 5,
  138037. 43,
  138038. 4,
  138039. 44,
  138040. 3,
  138041. 45,
  138042. 2,
  138043. 46,
  138044. 1,
  138045. 47,
  138046. 0,
  138047. 48,
  138048. };
  138049. static long _vq_lengthlist__44u9_p9_2[] = {
  138050. 2, 4, 4, 5, 4, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6,
  138051. 6, 6, 6, 7, 6, 7, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  138052. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  138053. 7,
  138054. };
  138055. static float _vq_quantthresh__44u9_p9_2[] = {
  138056. -23.5, -22.5, -21.5, -20.5, -19.5, -18.5, -17.5, -16.5,
  138057. -15.5, -14.5, -13.5, -12.5, -11.5, -10.5, -9.5, -8.5,
  138058. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  138059. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  138060. 8.5, 9.5, 10.5, 11.5, 12.5, 13.5, 14.5, 15.5,
  138061. 16.5, 17.5, 18.5, 19.5, 20.5, 21.5, 22.5, 23.5,
  138062. };
  138063. static long _vq_quantmap__44u9_p9_2[] = {
  138064. 47, 45, 43, 41, 39, 37, 35, 33,
  138065. 31, 29, 27, 25, 23, 21, 19, 17,
  138066. 15, 13, 11, 9, 7, 5, 3, 1,
  138067. 0, 2, 4, 6, 8, 10, 12, 14,
  138068. 16, 18, 20, 22, 24, 26, 28, 30,
  138069. 32, 34, 36, 38, 40, 42, 44, 46,
  138070. 48,
  138071. };
  138072. static encode_aux_threshmatch _vq_auxt__44u9_p9_2 = {
  138073. _vq_quantthresh__44u9_p9_2,
  138074. _vq_quantmap__44u9_p9_2,
  138075. 49,
  138076. 49
  138077. };
  138078. static static_codebook _44u9_p9_2 = {
  138079. 1, 49,
  138080. _vq_lengthlist__44u9_p9_2,
  138081. 1, -526909440, 1611661312, 6, 0,
  138082. _vq_quantlist__44u9_p9_2,
  138083. NULL,
  138084. &_vq_auxt__44u9_p9_2,
  138085. NULL,
  138086. 0
  138087. };
  138088. static long _huff_lengthlist__44un1__long[] = {
  138089. 5, 6,12, 9,14, 9, 9,19, 6, 1, 5, 5, 8, 7, 9,19,
  138090. 12, 4, 4, 7, 7, 9,11,18, 9, 5, 6, 6, 8, 7, 8,17,
  138091. 14, 8, 7, 8, 8,10,12,18, 9, 6, 8, 6, 8, 6, 8,18,
  138092. 9, 8,11, 8,11, 7, 5,15,16,18,18,18,17,15,11,18,
  138093. };
  138094. static static_codebook _huff_book__44un1__long = {
  138095. 2, 64,
  138096. _huff_lengthlist__44un1__long,
  138097. 0, 0, 0, 0, 0,
  138098. NULL,
  138099. NULL,
  138100. NULL,
  138101. NULL,
  138102. 0
  138103. };
  138104. static long _vq_quantlist__44un1__p1_0[] = {
  138105. 1,
  138106. 0,
  138107. 2,
  138108. };
  138109. static long _vq_lengthlist__44un1__p1_0[] = {
  138110. 1, 4, 4, 5, 8, 7, 5, 7, 8, 5, 8, 8, 8,10,11, 8,
  138111. 10,11, 5, 8, 8, 8,11,10, 8,11,10, 4, 9, 9, 8,11,
  138112. 11, 8,11,11, 8,12,11,10,12,14,11,13,13, 7,11,11,
  138113. 10,13,11,11,13,14, 4, 8, 9, 8,11,11, 8,11,12, 7,
  138114. 11,11,11,14,13,10,11,13, 8,11,12,11,13,13,10,14,
  138115. 12,
  138116. };
  138117. static float _vq_quantthresh__44un1__p1_0[] = {
  138118. -0.5, 0.5,
  138119. };
  138120. static long _vq_quantmap__44un1__p1_0[] = {
  138121. 1, 0, 2,
  138122. };
  138123. static encode_aux_threshmatch _vq_auxt__44un1__p1_0 = {
  138124. _vq_quantthresh__44un1__p1_0,
  138125. _vq_quantmap__44un1__p1_0,
  138126. 3,
  138127. 3
  138128. };
  138129. static static_codebook _44un1__p1_0 = {
  138130. 4, 81,
  138131. _vq_lengthlist__44un1__p1_0,
  138132. 1, -535822336, 1611661312, 2, 0,
  138133. _vq_quantlist__44un1__p1_0,
  138134. NULL,
  138135. &_vq_auxt__44un1__p1_0,
  138136. NULL,
  138137. 0
  138138. };
  138139. static long _vq_quantlist__44un1__p2_0[] = {
  138140. 1,
  138141. 0,
  138142. 2,
  138143. };
  138144. static long _vq_lengthlist__44un1__p2_0[] = {
  138145. 2, 4, 4, 5, 6, 6, 5, 6, 6, 5, 7, 7, 7, 8, 8, 6,
  138146. 7, 9, 5, 7, 7, 6, 8, 7, 7, 9, 8, 4, 7, 7, 7, 9,
  138147. 8, 7, 8, 8, 7, 9, 8, 8, 8,10, 9,10,10, 6, 8, 8,
  138148. 7,10, 8, 9,10,10, 5, 7, 7, 7, 8, 8, 7, 8, 9, 6,
  138149. 8, 8, 9,10,10, 7, 8,10, 6, 8, 9, 9,10,10, 8,10,
  138150. 8,
  138151. };
  138152. static float _vq_quantthresh__44un1__p2_0[] = {
  138153. -0.5, 0.5,
  138154. };
  138155. static long _vq_quantmap__44un1__p2_0[] = {
  138156. 1, 0, 2,
  138157. };
  138158. static encode_aux_threshmatch _vq_auxt__44un1__p2_0 = {
  138159. _vq_quantthresh__44un1__p2_0,
  138160. _vq_quantmap__44un1__p2_0,
  138161. 3,
  138162. 3
  138163. };
  138164. static static_codebook _44un1__p2_0 = {
  138165. 4, 81,
  138166. _vq_lengthlist__44un1__p2_0,
  138167. 1, -535822336, 1611661312, 2, 0,
  138168. _vq_quantlist__44un1__p2_0,
  138169. NULL,
  138170. &_vq_auxt__44un1__p2_0,
  138171. NULL,
  138172. 0
  138173. };
  138174. static long _vq_quantlist__44un1__p3_0[] = {
  138175. 2,
  138176. 1,
  138177. 3,
  138178. 0,
  138179. 4,
  138180. };
  138181. static long _vq_lengthlist__44un1__p3_0[] = {
  138182. 1, 5, 5, 8, 8, 5, 8, 7, 9, 9, 5, 7, 8, 9, 9, 9,
  138183. 10, 9,12,12, 9, 9,10,11,12, 6, 8, 8,10,10, 8,10,
  138184. 10,11,11, 8, 9,10,11,11,10,11,11,13,13,10,11,11,
  138185. 12,13, 6, 8, 8,10,10, 8,10, 9,11,11, 8,10,10,11,
  138186. 11,10,11,11,13,12,10,11,11,13,12, 9,11,11,15,13,
  138187. 10,12,11,15,13,10,11,11,15,14,12,14,13,16,15,12,
  138188. 13,13,17,16, 9,11,11,13,15,10,11,12,14,15,10,11,
  138189. 12,14,15,12,13,13,15,16,12,13,13,16,16, 5, 8, 8,
  138190. 11,11, 8,10,10,12,12, 8,10,10,12,12,11,12,12,14,
  138191. 14,11,12,12,14,14, 8,11,10,13,12,10,11,12,12,13,
  138192. 10,12,12,13,13,12,12,13,13,15,11,12,13,15,14, 7,
  138193. 10,10,12,12, 9,12,11,13,12,10,12,12,13,14,12,13,
  138194. 12,15,13,11,13,12,14,15,10,12,12,16,14,11,12,12,
  138195. 16,15,11,13,12,17,16,13,13,15,15,17,13,15,15,20,
  138196. 17,10,12,12,14,16,11,12,12,15,15,11,13,13,15,18,
  138197. 13,14,13,15,15,13,15,14,16,16, 5, 8, 8,11,11, 8,
  138198. 10,10,12,12, 8,10,10,12,12,11,12,12,14,14,11,12,
  138199. 12,14,15, 7,10,10,13,12,10,12,12,14,13, 9,10,12,
  138200. 12,13,11,13,13,15,15,11,12,13,13,15, 8,10,10,12,
  138201. 13,10,12,12,13,13,10,12,11,13,13,11,13,12,15,15,
  138202. 12,13,12,15,13,10,12,12,16,14,11,12,12,16,15,10,
  138203. 12,12,16,14,14,15,14,18,16,13,13,14,15,16,10,12,
  138204. 12,14,16,11,13,13,16,16,11,13,12,14,16,13,15,15,
  138205. 18,18,13,15,13,16,14, 8,11,11,16,16,10,13,13,17,
  138206. 16,10,12,12,16,15,14,16,15,20,17,13,14,14,17,17,
  138207. 9,12,12,16,16,11,13,14,16,17,11,13,13,16,16,15,
  138208. 15,19,18, 0,14,15,15,18,18, 9,12,12,17,16,11,13,
  138209. 12,17,16,11,12,13,15,17,15,16,15, 0,19,14,15,14,
  138210. 19,18,12,14,14, 0,16,13,14,14,19,18,13,15,16,17,
  138211. 16,15,15,17,18, 0,14,16,16,19, 0,12,14,14,16,18,
  138212. 13,15,13,17,18,13,15,14,17,18,15,18,14,18,18,16,
  138213. 17,16, 0,17, 8,11,11,15,15,10,12,12,16,16,10,13,
  138214. 13,16,16,13,15,14,17,17,14,15,17,17,18, 9,12,12,
  138215. 16,15,11,13,13,16,16,11,12,13,17,17,14,14,15,17,
  138216. 17,14,15,16, 0,18, 9,12,12,16,17,11,13,13,16,17,
  138217. 11,14,13,18,17,14,16,14,17,17,15,17,17,18,18,12,
  138218. 14,14, 0,16,13,15,15,19, 0,12,13,15, 0, 0,14,17,
  138219. 16,19, 0,16,15,18,18, 0,12,14,14,17, 0,13,14,14,
  138220. 17, 0,13,15,14, 0,18,15,16,16, 0,18,15,18,15, 0,
  138221. 17,
  138222. };
  138223. static float _vq_quantthresh__44un1__p3_0[] = {
  138224. -1.5, -0.5, 0.5, 1.5,
  138225. };
  138226. static long _vq_quantmap__44un1__p3_0[] = {
  138227. 3, 1, 0, 2, 4,
  138228. };
  138229. static encode_aux_threshmatch _vq_auxt__44un1__p3_0 = {
  138230. _vq_quantthresh__44un1__p3_0,
  138231. _vq_quantmap__44un1__p3_0,
  138232. 5,
  138233. 5
  138234. };
  138235. static static_codebook _44un1__p3_0 = {
  138236. 4, 625,
  138237. _vq_lengthlist__44un1__p3_0,
  138238. 1, -533725184, 1611661312, 3, 0,
  138239. _vq_quantlist__44un1__p3_0,
  138240. NULL,
  138241. &_vq_auxt__44un1__p3_0,
  138242. NULL,
  138243. 0
  138244. };
  138245. static long _vq_quantlist__44un1__p4_0[] = {
  138246. 2,
  138247. 1,
  138248. 3,
  138249. 0,
  138250. 4,
  138251. };
  138252. static long _vq_lengthlist__44un1__p4_0[] = {
  138253. 3, 5, 5, 9, 9, 5, 6, 6,10, 9, 5, 6, 6, 9,10,10,
  138254. 10,10,12,11, 9,10,10,12,12, 5, 7, 7,10,10, 7, 7,
  138255. 8,10,11, 7, 7, 8,10,11,10,10,11,11,13,10,10,11,
  138256. 11,13, 6, 7, 7,10,10, 7, 8, 7,11,10, 7, 8, 7,10,
  138257. 10,10,11, 9,13,11,10,11,10,13,11,10,10,10,14,13,
  138258. 10,11,11,14,13,10,10,11,13,14,12,12,13,15,15,12,
  138259. 12,13,13,14,10,10,10,12,13,10,11,10,13,13,10,11,
  138260. 11,13,13,12,13,12,14,13,12,13,13,14,13, 5, 7, 7,
  138261. 10,10, 7, 8, 8,11,10, 7, 8, 8,10,10,11,11,11,13,
  138262. 13,10,11,11,12,12, 7, 8, 8,11,11, 7, 8, 9,10,12,
  138263. 8, 9, 9,11,11,11,10,12,11,14,11,11,12,13,13, 6,
  138264. 8, 8,10,11, 7, 9, 7,12,10, 8, 9,10,11,12,10,12,
  138265. 10,14,11,11,12,11,13,13,10,11,11,14,14,10,10,11,
  138266. 13,14,11,12,12,15,13,12,11,14,12,16,12,13,14,15,
  138267. 16,10,10,11,13,14,10,11,10,14,12,11,12,12,13,14,
  138268. 12,13,11,15,12,14,14,14,15,15, 5, 7, 7,10,10, 7,
  138269. 8, 8,10,10, 7, 8, 8,10,11,10,11,10,12,12,10,11,
  138270. 11,12,13, 6, 8, 8,11,11, 8, 9, 9,12,11, 7, 7, 9,
  138271. 10,12,11,11,11,12,13,11,10,12,11,15, 7, 8, 8,11,
  138272. 11, 8, 9, 9,11,11, 7, 9, 8,12,10,11,12,11,13,12,
  138273. 11,12,10,15,11,10,11,10,14,12,11,12,11,14,13,10,
  138274. 10,11,13,14,13,13,13,17,15,12,11,14,12,15,10,10,
  138275. 11,13,14,11,12,12,14,14,10,11,10,14,13,13,14,13,
  138276. 16,17,12,14,11,16,12, 9,10,10,14,13,10,11,10,14,
  138277. 14,10,11,11,13,13,13,14,14,16,15,12,13,13,14,14,
  138278. 9,11,10,14,13,10,10,12,13,14,11,12,11,14,13,13,
  138279. 14,14,14,15,13,14,14,15,15, 9,10,11,13,14,10,11,
  138280. 10,15,13,11,11,12,12,15,13,14,12,15,14,13,13,14,
  138281. 14,15,12,13,12,16,14,11,11,12,15,14,13,15,13,16,
  138282. 14,13,12,15,12,17,15,16,15,16,16,12,12,13,13,15,
  138283. 11,13,11,15,14,13,13,14,15,17,13,14,12, 0,13,14,
  138284. 15,14,15, 0, 9,10,10,13,13,10,11,11,13,13,10,11,
  138285. 11,13,13,12,13,12,14,14,13,14,14,15,17, 9,10,10,
  138286. 13,13,11,12,11,15,12,10,10,11,13,16,13,14,13,15,
  138287. 14,13,13,14,15,16,10,10,11,13,14,11,11,12,13,14,
  138288. 10,12,11,14,14,13,13,13,14,15,13,15,13,16,15,12,
  138289. 13,12,15,13,12,15,13,15,15,11,11,13,14,15,15,15,
  138290. 15,15,17,13,12,14,13,17,12,12,14,14,15,13,13,14,
  138291. 14,16,11,13,11,16,15,14,16,16,17, 0,14,13,11,16,
  138292. 12,
  138293. };
  138294. static float _vq_quantthresh__44un1__p4_0[] = {
  138295. -1.5, -0.5, 0.5, 1.5,
  138296. };
  138297. static long _vq_quantmap__44un1__p4_0[] = {
  138298. 3, 1, 0, 2, 4,
  138299. };
  138300. static encode_aux_threshmatch _vq_auxt__44un1__p4_0 = {
  138301. _vq_quantthresh__44un1__p4_0,
  138302. _vq_quantmap__44un1__p4_0,
  138303. 5,
  138304. 5
  138305. };
  138306. static static_codebook _44un1__p4_0 = {
  138307. 4, 625,
  138308. _vq_lengthlist__44un1__p4_0,
  138309. 1, -533725184, 1611661312, 3, 0,
  138310. _vq_quantlist__44un1__p4_0,
  138311. NULL,
  138312. &_vq_auxt__44un1__p4_0,
  138313. NULL,
  138314. 0
  138315. };
  138316. static long _vq_quantlist__44un1__p5_0[] = {
  138317. 4,
  138318. 3,
  138319. 5,
  138320. 2,
  138321. 6,
  138322. 1,
  138323. 7,
  138324. 0,
  138325. 8,
  138326. };
  138327. static long _vq_lengthlist__44un1__p5_0[] = {
  138328. 1, 4, 4, 7, 7, 8, 8, 9, 9, 4, 6, 5, 8, 7, 8, 8,
  138329. 10, 9, 4, 6, 6, 8, 8, 8, 8,10,10, 7, 8, 7, 9, 9,
  138330. 9, 9,11,10, 7, 8, 8, 9, 9, 9, 9,10,11, 8, 8, 8,
  138331. 9, 9,10,10,11,11, 8, 8, 8, 9, 9,10,10,11,11, 9,
  138332. 10,10,11,10,11,11,12,12, 9,10,10,10,11,11,11,12,
  138333. 12,
  138334. };
  138335. static float _vq_quantthresh__44un1__p5_0[] = {
  138336. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  138337. };
  138338. static long _vq_quantmap__44un1__p5_0[] = {
  138339. 7, 5, 3, 1, 0, 2, 4, 6,
  138340. 8,
  138341. };
  138342. static encode_aux_threshmatch _vq_auxt__44un1__p5_0 = {
  138343. _vq_quantthresh__44un1__p5_0,
  138344. _vq_quantmap__44un1__p5_0,
  138345. 9,
  138346. 9
  138347. };
  138348. static static_codebook _44un1__p5_0 = {
  138349. 2, 81,
  138350. _vq_lengthlist__44un1__p5_0,
  138351. 1, -531628032, 1611661312, 4, 0,
  138352. _vq_quantlist__44un1__p5_0,
  138353. NULL,
  138354. &_vq_auxt__44un1__p5_0,
  138355. NULL,
  138356. 0
  138357. };
  138358. static long _vq_quantlist__44un1__p6_0[] = {
  138359. 6,
  138360. 5,
  138361. 7,
  138362. 4,
  138363. 8,
  138364. 3,
  138365. 9,
  138366. 2,
  138367. 10,
  138368. 1,
  138369. 11,
  138370. 0,
  138371. 12,
  138372. };
  138373. static long _vq_lengthlist__44un1__p6_0[] = {
  138374. 1, 4, 4, 6, 6, 8, 8,10,10,11,11,15,15, 4, 5, 5,
  138375. 8, 8, 9, 9,11,11,12,12,16,16, 4, 5, 6, 8, 8, 9,
  138376. 9,11,11,12,12,14,14, 7, 8, 8, 9, 9,10,10,11,12,
  138377. 13,13,16,17, 7, 8, 8, 9, 9,10,10,12,12,12,13,15,
  138378. 15, 9,10,10,10,10,11,11,12,12,13,13,15,16, 9, 9,
  138379. 9,10,10,11,11,13,12,13,13,17,17,10,11,11,11,12,
  138380. 12,12,13,13,14,15, 0,18,10,11,11,12,12,12,13,14,
  138381. 13,14,14,17,16,11,12,12,13,13,14,14,14,14,15,16,
  138382. 17,16,11,12,12,13,13,14,14,14,14,15,15,17,17,14,
  138383. 15,15,16,16,16,17,17,16, 0,17, 0,18,14,15,15,16,
  138384. 16, 0,15,18,18, 0,16, 0, 0,
  138385. };
  138386. static float _vq_quantthresh__44un1__p6_0[] = {
  138387. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  138388. 12.5, 17.5, 22.5, 27.5,
  138389. };
  138390. static long _vq_quantmap__44un1__p6_0[] = {
  138391. 11, 9, 7, 5, 3, 1, 0, 2,
  138392. 4, 6, 8, 10, 12,
  138393. };
  138394. static encode_aux_threshmatch _vq_auxt__44un1__p6_0 = {
  138395. _vq_quantthresh__44un1__p6_0,
  138396. _vq_quantmap__44un1__p6_0,
  138397. 13,
  138398. 13
  138399. };
  138400. static static_codebook _44un1__p6_0 = {
  138401. 2, 169,
  138402. _vq_lengthlist__44un1__p6_0,
  138403. 1, -526516224, 1616117760, 4, 0,
  138404. _vq_quantlist__44un1__p6_0,
  138405. NULL,
  138406. &_vq_auxt__44un1__p6_0,
  138407. NULL,
  138408. 0
  138409. };
  138410. static long _vq_quantlist__44un1__p6_1[] = {
  138411. 2,
  138412. 1,
  138413. 3,
  138414. 0,
  138415. 4,
  138416. };
  138417. static long _vq_lengthlist__44un1__p6_1[] = {
  138418. 2, 4, 4, 5, 5, 4, 5, 5, 5, 5, 4, 5, 5, 6, 5, 5,
  138419. 6, 5, 6, 6, 5, 6, 6, 6, 6,
  138420. };
  138421. static float _vq_quantthresh__44un1__p6_1[] = {
  138422. -1.5, -0.5, 0.5, 1.5,
  138423. };
  138424. static long _vq_quantmap__44un1__p6_1[] = {
  138425. 3, 1, 0, 2, 4,
  138426. };
  138427. static encode_aux_threshmatch _vq_auxt__44un1__p6_1 = {
  138428. _vq_quantthresh__44un1__p6_1,
  138429. _vq_quantmap__44un1__p6_1,
  138430. 5,
  138431. 5
  138432. };
  138433. static static_codebook _44un1__p6_1 = {
  138434. 2, 25,
  138435. _vq_lengthlist__44un1__p6_1,
  138436. 1, -533725184, 1611661312, 3, 0,
  138437. _vq_quantlist__44un1__p6_1,
  138438. NULL,
  138439. &_vq_auxt__44un1__p6_1,
  138440. NULL,
  138441. 0
  138442. };
  138443. static long _vq_quantlist__44un1__p7_0[] = {
  138444. 2,
  138445. 1,
  138446. 3,
  138447. 0,
  138448. 4,
  138449. };
  138450. static long _vq_lengthlist__44un1__p7_0[] = {
  138451. 1, 5, 3,11,11,11,11,11,11,11, 8,11,11,11,11,11,
  138452. 11,11,11,11,11,11,11,11,11,10,11,11,11,11,11,11,
  138453. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138454. 11,11,10,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138455. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138456. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138457. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138458. 11,11,11,11,11,11,11,11,11,11,11,11,11, 8,11,11,
  138459. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138460. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138461. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,10,
  138462. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138463. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138464. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138465. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138466. 11,11,11,11,11,11,11,11,11,11, 7,11,11,11,11,11,
  138467. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138468. 11,11,11,10,11,11,11,11,11,11,11,11,11,11,11,11,
  138469. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138470. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138471. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138472. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138473. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138474. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138475. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138476. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138477. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138478. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138479. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138480. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138481. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138482. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138483. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138484. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138485. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138486. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138487. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  138488. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  138489. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  138490. 10,
  138491. };
  138492. static float _vq_quantthresh__44un1__p7_0[] = {
  138493. -253.5, -84.5, 84.5, 253.5,
  138494. };
  138495. static long _vq_quantmap__44un1__p7_0[] = {
  138496. 3, 1, 0, 2, 4,
  138497. };
  138498. static encode_aux_threshmatch _vq_auxt__44un1__p7_0 = {
  138499. _vq_quantthresh__44un1__p7_0,
  138500. _vq_quantmap__44un1__p7_0,
  138501. 5,
  138502. 5
  138503. };
  138504. static static_codebook _44un1__p7_0 = {
  138505. 4, 625,
  138506. _vq_lengthlist__44un1__p7_0,
  138507. 1, -518709248, 1626677248, 3, 0,
  138508. _vq_quantlist__44un1__p7_0,
  138509. NULL,
  138510. &_vq_auxt__44un1__p7_0,
  138511. NULL,
  138512. 0
  138513. };
  138514. static long _vq_quantlist__44un1__p7_1[] = {
  138515. 6,
  138516. 5,
  138517. 7,
  138518. 4,
  138519. 8,
  138520. 3,
  138521. 9,
  138522. 2,
  138523. 10,
  138524. 1,
  138525. 11,
  138526. 0,
  138527. 12,
  138528. };
  138529. static long _vq_lengthlist__44un1__p7_1[] = {
  138530. 1, 4, 4, 6, 6, 6, 6, 9, 8, 9, 8, 8, 8, 5, 7, 7,
  138531. 7, 7, 8, 8, 8,10, 8,10, 8, 9, 5, 7, 7, 8, 7, 7,
  138532. 8,10,10,11,10,12,11, 7, 8, 8, 9, 9, 9,10,11,11,
  138533. 11,11,11,11, 7, 8, 8, 8, 9, 9, 9,10,10,10,11,11,
  138534. 12, 7, 8, 8, 9, 9,10,11,11,12,11,12,11,11, 7, 8,
  138535. 8, 9, 9,10,10,11,11,11,12,12,11, 8,10,10,10,10,
  138536. 11,11,14,11,12,12,12,13, 9,10,10,10,10,12,11,14,
  138537. 11,14,11,12,13,10,11,11,11,11,13,11,14,14,13,13,
  138538. 13,14,11,11,11,12,11,12,12,12,13,14,14,13,14,12,
  138539. 11,12,12,12,12,13,13,13,14,13,14,14,11,12,12,14,
  138540. 12,13,13,12,13,13,14,14,14,
  138541. };
  138542. static float _vq_quantthresh__44un1__p7_1[] = {
  138543. -71.5, -58.5, -45.5, -32.5, -19.5, -6.5, 6.5, 19.5,
  138544. 32.5, 45.5, 58.5, 71.5,
  138545. };
  138546. static long _vq_quantmap__44un1__p7_1[] = {
  138547. 11, 9, 7, 5, 3, 1, 0, 2,
  138548. 4, 6, 8, 10, 12,
  138549. };
  138550. static encode_aux_threshmatch _vq_auxt__44un1__p7_1 = {
  138551. _vq_quantthresh__44un1__p7_1,
  138552. _vq_quantmap__44un1__p7_1,
  138553. 13,
  138554. 13
  138555. };
  138556. static static_codebook _44un1__p7_1 = {
  138557. 2, 169,
  138558. _vq_lengthlist__44un1__p7_1,
  138559. 1, -523010048, 1618608128, 4, 0,
  138560. _vq_quantlist__44un1__p7_1,
  138561. NULL,
  138562. &_vq_auxt__44un1__p7_1,
  138563. NULL,
  138564. 0
  138565. };
  138566. static long _vq_quantlist__44un1__p7_2[] = {
  138567. 6,
  138568. 5,
  138569. 7,
  138570. 4,
  138571. 8,
  138572. 3,
  138573. 9,
  138574. 2,
  138575. 10,
  138576. 1,
  138577. 11,
  138578. 0,
  138579. 12,
  138580. };
  138581. static long _vq_lengthlist__44un1__p7_2[] = {
  138582. 3, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9, 9, 8, 4, 5, 5,
  138583. 6, 6, 8, 8, 9, 8, 9, 9, 9, 9, 4, 5, 5, 7, 6, 8,
  138584. 8, 8, 8, 9, 8, 9, 8, 6, 7, 7, 7, 8, 8, 8, 9, 9,
  138585. 9, 9, 9, 9, 6, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9, 9,
  138586. 9, 7, 8, 8, 8, 8, 9, 8, 9, 9,10, 9, 9,10, 7, 8,
  138587. 8, 8, 8, 9, 9, 9, 9, 9, 9,10,10, 8, 9, 9, 9, 9,
  138588. 9, 9, 9, 9,10,10, 9,10, 8, 9, 9, 9, 9, 9, 9, 9,
  138589. 9, 9, 9,10,10, 9, 9, 9,10, 9, 9,10, 9, 9,10,10,
  138590. 10,10, 9, 9, 9, 9, 9, 9, 9,10, 9,10,10,10,10, 9,
  138591. 9, 9,10, 9, 9,10,10, 9,10,10,10,10, 9, 9, 9,10,
  138592. 9, 9, 9,10,10,10,10,10,10,
  138593. };
  138594. static float _vq_quantthresh__44un1__p7_2[] = {
  138595. -5.5, -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5,
  138596. 2.5, 3.5, 4.5, 5.5,
  138597. };
  138598. static long _vq_quantmap__44un1__p7_2[] = {
  138599. 11, 9, 7, 5, 3, 1, 0, 2,
  138600. 4, 6, 8, 10, 12,
  138601. };
  138602. static encode_aux_threshmatch _vq_auxt__44un1__p7_2 = {
  138603. _vq_quantthresh__44un1__p7_2,
  138604. _vq_quantmap__44un1__p7_2,
  138605. 13,
  138606. 13
  138607. };
  138608. static static_codebook _44un1__p7_2 = {
  138609. 2, 169,
  138610. _vq_lengthlist__44un1__p7_2,
  138611. 1, -531103744, 1611661312, 4, 0,
  138612. _vq_quantlist__44un1__p7_2,
  138613. NULL,
  138614. &_vq_auxt__44un1__p7_2,
  138615. NULL,
  138616. 0
  138617. };
  138618. static long _huff_lengthlist__44un1__short[] = {
  138619. 12,12,14,12,14,14,14,14,12, 6, 6, 8, 9, 9,11,14,
  138620. 12, 4, 2, 6, 6, 7,11,14,13, 6, 5, 7, 8, 9,11,14,
  138621. 13, 8, 5, 8, 6, 8,12,14,12, 7, 7, 8, 8, 8,10,14,
  138622. 12, 6, 3, 4, 4, 4, 7,14,11, 7, 4, 6, 6, 6, 8,14,
  138623. };
  138624. static static_codebook _huff_book__44un1__short = {
  138625. 2, 64,
  138626. _huff_lengthlist__44un1__short,
  138627. 0, 0, 0, 0, 0,
  138628. NULL,
  138629. NULL,
  138630. NULL,
  138631. NULL,
  138632. 0
  138633. };
  138634. /*** End of inlined file: res_books_uncoupled.h ***/
  138635. static vorbis_info_residue0 _residue_44_low_un={
  138636. 0,-1, -1, 8,-1,
  138637. {0},
  138638. {-1},
  138639. { .5, 1.5, 1.5, 2.5, 2.5, 4.5, 28.5},
  138640. { -1, 25, -1, 45, -1, -1, -1}
  138641. };
  138642. static vorbis_info_residue0 _residue_44_mid_un={
  138643. 0,-1, -1, 10,-1,
  138644. {0},
  138645. {-1},
  138646. { .5, 1.5, 1.5, 2.5, 2.5, 4.5, 4.5, 16.5, 60.5},
  138647. { -1, 30, -1, 50, -1, 80, -1, -1, -1}
  138648. };
  138649. static vorbis_info_residue0 _residue_44_hi_un={
  138650. 0,-1, -1, 10,-1,
  138651. {0},
  138652. {-1},
  138653. { .5, 1.5, 2.5, 4.5, 8.5, 16.5, 32.5, 71.5,157.5},
  138654. { -1, -1, -1, -1, -1, -1, -1, -1, -1}
  138655. };
  138656. static vorbis_info_mapping0 _map_nominal_u[2]={
  138657. {1, {0,0}, {0}, {0}, 0,{0},{0}},
  138658. {1, {0,0}, {1}, {1}, 0,{0},{0}}
  138659. };
  138660. static static_bookblock _resbook_44u_n1={
  138661. {
  138662. {0},
  138663. {0,0,&_44un1__p1_0},
  138664. {0,0,&_44un1__p2_0},
  138665. {0,0,&_44un1__p3_0},
  138666. {0,0,&_44un1__p4_0},
  138667. {0,0,&_44un1__p5_0},
  138668. {&_44un1__p6_0,&_44un1__p6_1},
  138669. {&_44un1__p7_0,&_44un1__p7_1,&_44un1__p7_2}
  138670. }
  138671. };
  138672. static static_bookblock _resbook_44u_0={
  138673. {
  138674. {0},
  138675. {0,0,&_44u0__p1_0},
  138676. {0,0,&_44u0__p2_0},
  138677. {0,0,&_44u0__p3_0},
  138678. {0,0,&_44u0__p4_0},
  138679. {0,0,&_44u0__p5_0},
  138680. {&_44u0__p6_0,&_44u0__p6_1},
  138681. {&_44u0__p7_0,&_44u0__p7_1,&_44u0__p7_2}
  138682. }
  138683. };
  138684. static static_bookblock _resbook_44u_1={
  138685. {
  138686. {0},
  138687. {0,0,&_44u1__p1_0},
  138688. {0,0,&_44u1__p2_0},
  138689. {0,0,&_44u1__p3_0},
  138690. {0,0,&_44u1__p4_0},
  138691. {0,0,&_44u1__p5_0},
  138692. {&_44u1__p6_0,&_44u1__p6_1},
  138693. {&_44u1__p7_0,&_44u1__p7_1,&_44u1__p7_2}
  138694. }
  138695. };
  138696. static static_bookblock _resbook_44u_2={
  138697. {
  138698. {0},
  138699. {0,0,&_44u2__p1_0},
  138700. {0,0,&_44u2__p2_0},
  138701. {0,0,&_44u2__p3_0},
  138702. {0,0,&_44u2__p4_0},
  138703. {0,0,&_44u2__p5_0},
  138704. {&_44u2__p6_0,&_44u2__p6_1},
  138705. {&_44u2__p7_0,&_44u2__p7_1,&_44u2__p7_2}
  138706. }
  138707. };
  138708. static static_bookblock _resbook_44u_3={
  138709. {
  138710. {0},
  138711. {0,0,&_44u3__p1_0},
  138712. {0,0,&_44u3__p2_0},
  138713. {0,0,&_44u3__p3_0},
  138714. {0,0,&_44u3__p4_0},
  138715. {0,0,&_44u3__p5_0},
  138716. {&_44u3__p6_0,&_44u3__p6_1},
  138717. {&_44u3__p7_0,&_44u3__p7_1,&_44u3__p7_2}
  138718. }
  138719. };
  138720. static static_bookblock _resbook_44u_4={
  138721. {
  138722. {0},
  138723. {0,0,&_44u4__p1_0},
  138724. {0,0,&_44u4__p2_0},
  138725. {0,0,&_44u4__p3_0},
  138726. {0,0,&_44u4__p4_0},
  138727. {0,0,&_44u4__p5_0},
  138728. {&_44u4__p6_0,&_44u4__p6_1},
  138729. {&_44u4__p7_0,&_44u4__p7_1,&_44u4__p7_2}
  138730. }
  138731. };
  138732. static static_bookblock _resbook_44u_5={
  138733. {
  138734. {0},
  138735. {0,0,&_44u5__p1_0},
  138736. {0,0,&_44u5__p2_0},
  138737. {0,0,&_44u5__p3_0},
  138738. {0,0,&_44u5__p4_0},
  138739. {0,0,&_44u5__p5_0},
  138740. {0,0,&_44u5__p6_0},
  138741. {&_44u5__p7_0,&_44u5__p7_1},
  138742. {&_44u5__p8_0,&_44u5__p8_1},
  138743. {&_44u5__p9_0,&_44u5__p9_1,&_44u5__p9_2}
  138744. }
  138745. };
  138746. static static_bookblock _resbook_44u_6={
  138747. {
  138748. {0},
  138749. {0,0,&_44u6__p1_0},
  138750. {0,0,&_44u6__p2_0},
  138751. {0,0,&_44u6__p3_0},
  138752. {0,0,&_44u6__p4_0},
  138753. {0,0,&_44u6__p5_0},
  138754. {0,0,&_44u6__p6_0},
  138755. {&_44u6__p7_0,&_44u6__p7_1},
  138756. {&_44u6__p8_0,&_44u6__p8_1},
  138757. {&_44u6__p9_0,&_44u6__p9_1,&_44u6__p9_2}
  138758. }
  138759. };
  138760. static static_bookblock _resbook_44u_7={
  138761. {
  138762. {0},
  138763. {0,0,&_44u7__p1_0},
  138764. {0,0,&_44u7__p2_0},
  138765. {0,0,&_44u7__p3_0},
  138766. {0,0,&_44u7__p4_0},
  138767. {0,0,&_44u7__p5_0},
  138768. {0,0,&_44u7__p6_0},
  138769. {&_44u7__p7_0,&_44u7__p7_1},
  138770. {&_44u7__p8_0,&_44u7__p8_1},
  138771. {&_44u7__p9_0,&_44u7__p9_1,&_44u7__p9_2}
  138772. }
  138773. };
  138774. static static_bookblock _resbook_44u_8={
  138775. {
  138776. {0},
  138777. {0,0,&_44u8_p1_0},
  138778. {0,0,&_44u8_p2_0},
  138779. {0,0,&_44u8_p3_0},
  138780. {0,0,&_44u8_p4_0},
  138781. {&_44u8_p5_0,&_44u8_p5_1},
  138782. {&_44u8_p6_0,&_44u8_p6_1},
  138783. {&_44u8_p7_0,&_44u8_p7_1},
  138784. {&_44u8_p8_0,&_44u8_p8_1},
  138785. {&_44u8_p9_0,&_44u8_p9_1,&_44u8_p9_2}
  138786. }
  138787. };
  138788. static static_bookblock _resbook_44u_9={
  138789. {
  138790. {0},
  138791. {0,0,&_44u9_p1_0},
  138792. {0,0,&_44u9_p2_0},
  138793. {0,0,&_44u9_p3_0},
  138794. {0,0,&_44u9_p4_0},
  138795. {&_44u9_p5_0,&_44u9_p5_1},
  138796. {&_44u9_p6_0,&_44u9_p6_1},
  138797. {&_44u9_p7_0,&_44u9_p7_1},
  138798. {&_44u9_p8_0,&_44u9_p8_1},
  138799. {&_44u9_p9_0,&_44u9_p9_1,&_44u9_p9_2}
  138800. }
  138801. };
  138802. static vorbis_residue_template _res_44u_n1[]={
  138803. {1,0, &_residue_44_low_un,
  138804. &_huff_book__44un1__short,&_huff_book__44un1__short,
  138805. &_resbook_44u_n1,&_resbook_44u_n1},
  138806. {1,0, &_residue_44_low_un,
  138807. &_huff_book__44un1__long,&_huff_book__44un1__long,
  138808. &_resbook_44u_n1,&_resbook_44u_n1}
  138809. };
  138810. static vorbis_residue_template _res_44u_0[]={
  138811. {1,0, &_residue_44_low_un,
  138812. &_huff_book__44u0__short,&_huff_book__44u0__short,
  138813. &_resbook_44u_0,&_resbook_44u_0},
  138814. {1,0, &_residue_44_low_un,
  138815. &_huff_book__44u0__long,&_huff_book__44u0__long,
  138816. &_resbook_44u_0,&_resbook_44u_0}
  138817. };
  138818. static vorbis_residue_template _res_44u_1[]={
  138819. {1,0, &_residue_44_low_un,
  138820. &_huff_book__44u1__short,&_huff_book__44u1__short,
  138821. &_resbook_44u_1,&_resbook_44u_1},
  138822. {1,0, &_residue_44_low_un,
  138823. &_huff_book__44u1__long,&_huff_book__44u1__long,
  138824. &_resbook_44u_1,&_resbook_44u_1}
  138825. };
  138826. static vorbis_residue_template _res_44u_2[]={
  138827. {1,0, &_residue_44_low_un,
  138828. &_huff_book__44u2__short,&_huff_book__44u2__short,
  138829. &_resbook_44u_2,&_resbook_44u_2},
  138830. {1,0, &_residue_44_low_un,
  138831. &_huff_book__44u2__long,&_huff_book__44u2__long,
  138832. &_resbook_44u_2,&_resbook_44u_2}
  138833. };
  138834. static vorbis_residue_template _res_44u_3[]={
  138835. {1,0, &_residue_44_low_un,
  138836. &_huff_book__44u3__short,&_huff_book__44u3__short,
  138837. &_resbook_44u_3,&_resbook_44u_3},
  138838. {1,0, &_residue_44_low_un,
  138839. &_huff_book__44u3__long,&_huff_book__44u3__long,
  138840. &_resbook_44u_3,&_resbook_44u_3}
  138841. };
  138842. static vorbis_residue_template _res_44u_4[]={
  138843. {1,0, &_residue_44_low_un,
  138844. &_huff_book__44u4__short,&_huff_book__44u4__short,
  138845. &_resbook_44u_4,&_resbook_44u_4},
  138846. {1,0, &_residue_44_low_un,
  138847. &_huff_book__44u4__long,&_huff_book__44u4__long,
  138848. &_resbook_44u_4,&_resbook_44u_4}
  138849. };
  138850. static vorbis_residue_template _res_44u_5[]={
  138851. {1,0, &_residue_44_mid_un,
  138852. &_huff_book__44u5__short,&_huff_book__44u5__short,
  138853. &_resbook_44u_5,&_resbook_44u_5},
  138854. {1,0, &_residue_44_mid_un,
  138855. &_huff_book__44u5__long,&_huff_book__44u5__long,
  138856. &_resbook_44u_5,&_resbook_44u_5}
  138857. };
  138858. static vorbis_residue_template _res_44u_6[]={
  138859. {1,0, &_residue_44_mid_un,
  138860. &_huff_book__44u6__short,&_huff_book__44u6__short,
  138861. &_resbook_44u_6,&_resbook_44u_6},
  138862. {1,0, &_residue_44_mid_un,
  138863. &_huff_book__44u6__long,&_huff_book__44u6__long,
  138864. &_resbook_44u_6,&_resbook_44u_6}
  138865. };
  138866. static vorbis_residue_template _res_44u_7[]={
  138867. {1,0, &_residue_44_mid_un,
  138868. &_huff_book__44u7__short,&_huff_book__44u7__short,
  138869. &_resbook_44u_7,&_resbook_44u_7},
  138870. {1,0, &_residue_44_mid_un,
  138871. &_huff_book__44u7__long,&_huff_book__44u7__long,
  138872. &_resbook_44u_7,&_resbook_44u_7}
  138873. };
  138874. static vorbis_residue_template _res_44u_8[]={
  138875. {1,0, &_residue_44_hi_un,
  138876. &_huff_book__44u8__short,&_huff_book__44u8__short,
  138877. &_resbook_44u_8,&_resbook_44u_8},
  138878. {1,0, &_residue_44_hi_un,
  138879. &_huff_book__44u8__long,&_huff_book__44u8__long,
  138880. &_resbook_44u_8,&_resbook_44u_8}
  138881. };
  138882. static vorbis_residue_template _res_44u_9[]={
  138883. {1,0, &_residue_44_hi_un,
  138884. &_huff_book__44u9__short,&_huff_book__44u9__short,
  138885. &_resbook_44u_9,&_resbook_44u_9},
  138886. {1,0, &_residue_44_hi_un,
  138887. &_huff_book__44u9__long,&_huff_book__44u9__long,
  138888. &_resbook_44u_9,&_resbook_44u_9}
  138889. };
  138890. static vorbis_mapping_template _mapres_template_44_uncoupled[]={
  138891. { _map_nominal_u, _res_44u_n1 }, /* -1 */
  138892. { _map_nominal_u, _res_44u_0 }, /* 0 */
  138893. { _map_nominal_u, _res_44u_1 }, /* 1 */
  138894. { _map_nominal_u, _res_44u_2 }, /* 2 */
  138895. { _map_nominal_u, _res_44u_3 }, /* 3 */
  138896. { _map_nominal_u, _res_44u_4 }, /* 4 */
  138897. { _map_nominal_u, _res_44u_5 }, /* 5 */
  138898. { _map_nominal_u, _res_44u_6 }, /* 6 */
  138899. { _map_nominal_u, _res_44u_7 }, /* 7 */
  138900. { _map_nominal_u, _res_44u_8 }, /* 8 */
  138901. { _map_nominal_u, _res_44u_9 }, /* 9 */
  138902. };
  138903. /*** End of inlined file: residue_44u.h ***/
  138904. static double rate_mapping_44_un[12]={
  138905. 32000.,48000.,60000.,70000.,80000.,86000.,
  138906. 96000.,110000.,120000.,140000.,160000.,240001.
  138907. };
  138908. ve_setup_data_template ve_setup_44_uncoupled={
  138909. 11,
  138910. rate_mapping_44_un,
  138911. quality_mapping_44,
  138912. -1,
  138913. 40000,
  138914. 50000,
  138915. blocksize_short_44,
  138916. blocksize_long_44,
  138917. _psy_tone_masteratt_44,
  138918. _psy_tone_0dB,
  138919. _psy_tone_suppress,
  138920. _vp_tonemask_adj_otherblock,
  138921. _vp_tonemask_adj_longblock,
  138922. _vp_tonemask_adj_otherblock,
  138923. _psy_noiseguards_44,
  138924. _psy_noisebias_impulse,
  138925. _psy_noisebias_padding,
  138926. _psy_noisebias_trans,
  138927. _psy_noisebias_long,
  138928. _psy_noise_suppress,
  138929. _psy_compand_44,
  138930. _psy_compand_short_mapping,
  138931. _psy_compand_long_mapping,
  138932. {_noise_start_short_44,_noise_start_long_44},
  138933. {_noise_part_short_44,_noise_part_long_44},
  138934. _noise_thresh_44,
  138935. _psy_ath_floater,
  138936. _psy_ath_abs,
  138937. _psy_lowpass_44,
  138938. _psy_global_44,
  138939. _global_mapping_44,
  138940. NULL,
  138941. _floor_books,
  138942. _floor,
  138943. _floor_short_mapping_44,
  138944. _floor_long_mapping_44,
  138945. _mapres_template_44_uncoupled
  138946. };
  138947. /*** End of inlined file: setup_44u.h ***/
  138948. /*** Start of inlined file: setup_32.h ***/
  138949. static double rate_mapping_32[12]={
  138950. 18000.,28000.,35000.,45000.,56000.,60000.,
  138951. 75000.,90000.,100000.,115000.,150000.,190000.,
  138952. };
  138953. static double rate_mapping_32_un[12]={
  138954. 30000.,42000.,52000.,64000.,72000.,78000.,
  138955. 86000.,92000.,110000.,120000.,140000.,190000.,
  138956. };
  138957. static double _psy_lowpass_32[12]={
  138958. 12.3,13.,13.,14.,15.,99.,99.,99.,99.,99.,99.,99.
  138959. };
  138960. ve_setup_data_template ve_setup_32_stereo={
  138961. 11,
  138962. rate_mapping_32,
  138963. quality_mapping_44,
  138964. 2,
  138965. 26000,
  138966. 40000,
  138967. blocksize_short_44,
  138968. blocksize_long_44,
  138969. _psy_tone_masteratt_44,
  138970. _psy_tone_0dB,
  138971. _psy_tone_suppress,
  138972. _vp_tonemask_adj_otherblock,
  138973. _vp_tonemask_adj_longblock,
  138974. _vp_tonemask_adj_otherblock,
  138975. _psy_noiseguards_44,
  138976. _psy_noisebias_impulse,
  138977. _psy_noisebias_padding,
  138978. _psy_noisebias_trans,
  138979. _psy_noisebias_long,
  138980. _psy_noise_suppress,
  138981. _psy_compand_44,
  138982. _psy_compand_short_mapping,
  138983. _psy_compand_long_mapping,
  138984. {_noise_start_short_44,_noise_start_long_44},
  138985. {_noise_part_short_44,_noise_part_long_44},
  138986. _noise_thresh_44,
  138987. _psy_ath_floater,
  138988. _psy_ath_abs,
  138989. _psy_lowpass_32,
  138990. _psy_global_44,
  138991. _global_mapping_44,
  138992. _psy_stereo_modes_44,
  138993. _floor_books,
  138994. _floor,
  138995. _floor_short_mapping_44,
  138996. _floor_long_mapping_44,
  138997. _mapres_template_44_stereo
  138998. };
  138999. ve_setup_data_template ve_setup_32_uncoupled={
  139000. 11,
  139001. rate_mapping_32_un,
  139002. quality_mapping_44,
  139003. -1,
  139004. 26000,
  139005. 40000,
  139006. blocksize_short_44,
  139007. blocksize_long_44,
  139008. _psy_tone_masteratt_44,
  139009. _psy_tone_0dB,
  139010. _psy_tone_suppress,
  139011. _vp_tonemask_adj_otherblock,
  139012. _vp_tonemask_adj_longblock,
  139013. _vp_tonemask_adj_otherblock,
  139014. _psy_noiseguards_44,
  139015. _psy_noisebias_impulse,
  139016. _psy_noisebias_padding,
  139017. _psy_noisebias_trans,
  139018. _psy_noisebias_long,
  139019. _psy_noise_suppress,
  139020. _psy_compand_44,
  139021. _psy_compand_short_mapping,
  139022. _psy_compand_long_mapping,
  139023. {_noise_start_short_44,_noise_start_long_44},
  139024. {_noise_part_short_44,_noise_part_long_44},
  139025. _noise_thresh_44,
  139026. _psy_ath_floater,
  139027. _psy_ath_abs,
  139028. _psy_lowpass_32,
  139029. _psy_global_44,
  139030. _global_mapping_44,
  139031. NULL,
  139032. _floor_books,
  139033. _floor,
  139034. _floor_short_mapping_44,
  139035. _floor_long_mapping_44,
  139036. _mapres_template_44_uncoupled
  139037. };
  139038. /*** End of inlined file: setup_32.h ***/
  139039. /*** Start of inlined file: setup_8.h ***/
  139040. /*** Start of inlined file: psych_8.h ***/
  139041. static att3 _psy_tone_masteratt_8[3]={
  139042. {{ 32, 25, 12}, 0, 0}, /* 0 */
  139043. {{ 30, 25, 12}, 0, 0}, /* 0 */
  139044. {{ 20, 0, -14}, 0, 0}, /* 0 */
  139045. };
  139046. static vp_adjblock _vp_tonemask_adj_8[3]={
  139047. {{-15,-15,-15,-15,-10,-10, -6, 0, 0, 0, 0,10, 0, 0,99,99,99}}, /* 1 */
  139048. {{-15,-15,-15,-15,-10,-10, -6, 0, 0, 0, 0,10, 0, 0,99,99,99}}, /* 1 */
  139049. {{-15,-15,-15,-15,-10,-10, -6, 0, 0, 0, 0, 0, 0, 0,99,99,99}}, /* 1 */
  139050. };
  139051. static noise3 _psy_noisebias_8[3]={
  139052. {{{-10,-10,-10,-10, -5, -5, -5, 0, 4, 8, 8, 8, 10, 10, 99, 99, 99},
  139053. {-10,-10,-10,-10, -5, -5, -5, 0, 0, 4, 4, 4, 4, 4, 99, 99, 99},
  139054. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, 99, 99, 99}}},
  139055. {{{-10,-10,-10,-10, -5, -5, -5, 0, 4, 8, 8, 8, 10, 10, 99, 99, 99},
  139056. {-10,-10,-10,-10,-10,-10, -5, -5, -5, 0, 0, 0, 0, 0, 99, 99, 99},
  139057. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, 99, 99, 99}}},
  139058. {{{-15,-15,-15,-15,-15,-12,-10, -8, 0, 2, 4, 4, 5, 5, 99, 99, 99},
  139059. {-30,-30,-30,-30,-26,-22,-20,-14,-12,-12,-10,-10,-10,-10, 99, 99, 99},
  139060. {-30,-30,-30,-30,-26,-26,-26,-26,-26,-26,-26,-26,-26,-24, 99, 99, 99}}},
  139061. };
  139062. static adj_stereo _psy_stereo_modes_8[3]={
  139063. {{ 4, 4, 4, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3},
  139064. { 6, 5, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4},
  139065. { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
  139066. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  139067. {{ 4, 4, 4, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3},
  139068. { 6, 5, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4},
  139069. { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
  139070. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  139071. {{ 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3},
  139072. { 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4},
  139073. { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
  139074. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  139075. };
  139076. static noiseguard _psy_noiseguards_8[2]={
  139077. {10,10,-1},
  139078. {10,10,-1},
  139079. };
  139080. static compandblock _psy_compand_8[2]={
  139081. {{
  139082. 0, 1, 2, 3, 4, 5, 6, 7, /* 7dB */
  139083. 8, 8, 9, 9,10,10,11, 11, /* 15dB */
  139084. 12,12,13,13,14,14,15, 15, /* 23dB */
  139085. 16,16,17,17,17,18,18, 19, /* 31dB */
  139086. 19,19,20,21,22,23,24, 25, /* 39dB */
  139087. }},
  139088. {{
  139089. 0, 1, 2, 3, 4, 5, 6, 6, /* 7dB */
  139090. 7, 7, 6, 6, 5, 5, 4, 4, /* 15dB */
  139091. 3, 3, 3, 4, 5, 6, 7, 8, /* 23dB */
  139092. 9,10,11,12,13,14,15, 16, /* 31dB */
  139093. 17,18,19,20,21,22,23, 24, /* 39dB */
  139094. }},
  139095. };
  139096. static double _psy_lowpass_8[3]={3.,4.,4.};
  139097. static int _noise_start_8[2]={
  139098. 64,64,
  139099. };
  139100. static int _noise_part_8[2]={
  139101. 8,8,
  139102. };
  139103. static int _psy_ath_floater_8[3]={
  139104. -100,-100,-105,
  139105. };
  139106. static int _psy_ath_abs_8[3]={
  139107. -130,-130,-140,
  139108. };
  139109. /*** End of inlined file: psych_8.h ***/
  139110. /*** Start of inlined file: residue_8.h ***/
  139111. static static_bookblock _resbook_8s_0={
  139112. {
  139113. {0},{0,0,&_8c0_s_p1_0},{0,0,&_8c0_s_p2_0},{0,0,&_8c0_s_p3_0},
  139114. {0,0,&_8c0_s_p4_0},{0,0,&_8c0_s_p5_0},{0,0,&_8c0_s_p6_0},
  139115. {&_8c0_s_p7_0,&_8c0_s_p7_1},{&_8c0_s_p8_0,&_8c0_s_p8_1},
  139116. {&_8c0_s_p9_0,&_8c0_s_p9_1,&_8c0_s_p9_2}
  139117. }
  139118. };
  139119. static static_bookblock _resbook_8s_1={
  139120. {
  139121. {0},{0,0,&_8c1_s_p1_0},{0,0,&_8c1_s_p2_0},{0,0,&_8c1_s_p3_0},
  139122. {0,0,&_8c1_s_p4_0},{0,0,&_8c1_s_p5_0},{0,0,&_8c1_s_p6_0},
  139123. {&_8c1_s_p7_0,&_8c1_s_p7_1},{&_8c1_s_p8_0,&_8c1_s_p8_1},
  139124. {&_8c1_s_p9_0,&_8c1_s_p9_1,&_8c1_s_p9_2}
  139125. }
  139126. };
  139127. static vorbis_residue_template _res_8s_0[]={
  139128. {2,0, &_residue_44_mid,
  139129. &_huff_book__8c0_s_single,&_huff_book__8c0_s_single,
  139130. &_resbook_8s_0,&_resbook_8s_0},
  139131. };
  139132. static vorbis_residue_template _res_8s_1[]={
  139133. {2,0, &_residue_44_mid,
  139134. &_huff_book__8c1_s_single,&_huff_book__8c1_s_single,
  139135. &_resbook_8s_1,&_resbook_8s_1},
  139136. };
  139137. static vorbis_mapping_template _mapres_template_8_stereo[2]={
  139138. { _map_nominal, _res_8s_0 }, /* 0 */
  139139. { _map_nominal, _res_8s_1 }, /* 1 */
  139140. };
  139141. static static_bookblock _resbook_8u_0={
  139142. {
  139143. {0},
  139144. {0,0,&_8u0__p1_0},
  139145. {0,0,&_8u0__p2_0},
  139146. {0,0,&_8u0__p3_0},
  139147. {0,0,&_8u0__p4_0},
  139148. {0,0,&_8u0__p5_0},
  139149. {&_8u0__p6_0,&_8u0__p6_1},
  139150. {&_8u0__p7_0,&_8u0__p7_1,&_8u0__p7_2}
  139151. }
  139152. };
  139153. static static_bookblock _resbook_8u_1={
  139154. {
  139155. {0},
  139156. {0,0,&_8u1__p1_0},
  139157. {0,0,&_8u1__p2_0},
  139158. {0,0,&_8u1__p3_0},
  139159. {0,0,&_8u1__p4_0},
  139160. {0,0,&_8u1__p5_0},
  139161. {0,0,&_8u1__p6_0},
  139162. {&_8u1__p7_0,&_8u1__p7_1},
  139163. {&_8u1__p8_0,&_8u1__p8_1},
  139164. {&_8u1__p9_0,&_8u1__p9_1,&_8u1__p9_2}
  139165. }
  139166. };
  139167. static vorbis_residue_template _res_8u_0[]={
  139168. {1,0, &_residue_44_low_un,
  139169. &_huff_book__8u0__single,&_huff_book__8u0__single,
  139170. &_resbook_8u_0,&_resbook_8u_0},
  139171. };
  139172. static vorbis_residue_template _res_8u_1[]={
  139173. {1,0, &_residue_44_mid_un,
  139174. &_huff_book__8u1__single,&_huff_book__8u1__single,
  139175. &_resbook_8u_1,&_resbook_8u_1},
  139176. };
  139177. static vorbis_mapping_template _mapres_template_8_uncoupled[2]={
  139178. { _map_nominal_u, _res_8u_0 }, /* 0 */
  139179. { _map_nominal_u, _res_8u_1 }, /* 1 */
  139180. };
  139181. /*** End of inlined file: residue_8.h ***/
  139182. static int blocksize_8[2]={
  139183. 512,512
  139184. };
  139185. static int _floor_mapping_8[2]={
  139186. 6,6,
  139187. };
  139188. static double rate_mapping_8[3]={
  139189. 6000.,9000.,32000.,
  139190. };
  139191. static double rate_mapping_8_uncoupled[3]={
  139192. 8000.,14000.,42000.,
  139193. };
  139194. static double quality_mapping_8[3]={
  139195. -.1,.0,1.
  139196. };
  139197. static double _psy_compand_8_mapping[3]={ 0., 1., 1.};
  139198. static double _global_mapping_8[3]={ 1., 2., 3. };
  139199. ve_setup_data_template ve_setup_8_stereo={
  139200. 2,
  139201. rate_mapping_8,
  139202. quality_mapping_8,
  139203. 2,
  139204. 8000,
  139205. 9000,
  139206. blocksize_8,
  139207. blocksize_8,
  139208. _psy_tone_masteratt_8,
  139209. _psy_tone_0dB,
  139210. _psy_tone_suppress,
  139211. _vp_tonemask_adj_8,
  139212. NULL,
  139213. _vp_tonemask_adj_8,
  139214. _psy_noiseguards_8,
  139215. _psy_noisebias_8,
  139216. _psy_noisebias_8,
  139217. NULL,
  139218. NULL,
  139219. _psy_noise_suppress,
  139220. _psy_compand_8,
  139221. _psy_compand_8_mapping,
  139222. NULL,
  139223. {_noise_start_8,_noise_start_8},
  139224. {_noise_part_8,_noise_part_8},
  139225. _noise_thresh_5only,
  139226. _psy_ath_floater_8,
  139227. _psy_ath_abs_8,
  139228. _psy_lowpass_8,
  139229. _psy_global_44,
  139230. _global_mapping_8,
  139231. _psy_stereo_modes_8,
  139232. _floor_books,
  139233. _floor,
  139234. _floor_mapping_8,
  139235. NULL,
  139236. _mapres_template_8_stereo
  139237. };
  139238. ve_setup_data_template ve_setup_8_uncoupled={
  139239. 2,
  139240. rate_mapping_8_uncoupled,
  139241. quality_mapping_8,
  139242. -1,
  139243. 8000,
  139244. 9000,
  139245. blocksize_8,
  139246. blocksize_8,
  139247. _psy_tone_masteratt_8,
  139248. _psy_tone_0dB,
  139249. _psy_tone_suppress,
  139250. _vp_tonemask_adj_8,
  139251. NULL,
  139252. _vp_tonemask_adj_8,
  139253. _psy_noiseguards_8,
  139254. _psy_noisebias_8,
  139255. _psy_noisebias_8,
  139256. NULL,
  139257. NULL,
  139258. _psy_noise_suppress,
  139259. _psy_compand_8,
  139260. _psy_compand_8_mapping,
  139261. NULL,
  139262. {_noise_start_8,_noise_start_8},
  139263. {_noise_part_8,_noise_part_8},
  139264. _noise_thresh_5only,
  139265. _psy_ath_floater_8,
  139266. _psy_ath_abs_8,
  139267. _psy_lowpass_8,
  139268. _psy_global_44,
  139269. _global_mapping_8,
  139270. _psy_stereo_modes_8,
  139271. _floor_books,
  139272. _floor,
  139273. _floor_mapping_8,
  139274. NULL,
  139275. _mapres_template_8_uncoupled
  139276. };
  139277. /*** End of inlined file: setup_8.h ***/
  139278. /*** Start of inlined file: setup_11.h ***/
  139279. /*** Start of inlined file: psych_11.h ***/
  139280. static double _psy_lowpass_11[3]={4.5,5.5,30.,};
  139281. static att3 _psy_tone_masteratt_11[3]={
  139282. {{ 30, 25, 12}, 0, 0}, /* 0 */
  139283. {{ 30, 25, 12}, 0, 0}, /* 0 */
  139284. {{ 20, 0, -14}, 0, 0}, /* 0 */
  139285. };
  139286. static vp_adjblock _vp_tonemask_adj_11[3]={
  139287. {{-20,-20,-20,-20,-20,-16,-10, 0, 0, 0, 0,10, 2, 0,99,99,99}}, /* 0 */
  139288. {{-20,-20,-20,-20,-20,-16,-10, 0, 0, 0, 0, 5, 0, 0,99,99,99}}, /* 1 */
  139289. {{-20,-20,-20,-20,-20,-16,-10, 0, 0, 0, 0, 0, 0, 0,99,99,99}}, /* 2 */
  139290. };
  139291. static noise3 _psy_noisebias_11[3]={
  139292. {{{-10,-10,-10,-10, -5, -5, -5, 0, 4, 10, 10, 12, 12, 12, 99, 99, 99},
  139293. {-15,-15,-15,-15,-10,-10, -5, 0, 0, 4, 4, 5, 5, 10, 99, 99, 99},
  139294. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, 99, 99, 99}}},
  139295. {{{-10,-10,-10,-10, -5, -5, -5, 0, 4, 10, 10, 12, 12, 12, 99, 99, 99},
  139296. {-15,-15,-15,-15,-10,-10, -5, -5, -5, 0, 0, 0, 0, 0, 99, 99, 99},
  139297. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, 99, 99, 99}}},
  139298. {{{-15,-15,-15,-15,-15,-12,-10, -8, 0, 2, 4, 4, 5, 5, 99, 99, 99},
  139299. {-30,-30,-30,-30,-26,-22,-20,-14,-12,-12,-10,-10,-10,-10, 99, 99, 99},
  139300. {-30,-30,-30,-30,-26,-26,-26,-26,-26,-26,-26,-26,-26,-24, 99, 99, 99}}},
  139301. };
  139302. static double _noise_thresh_11[3]={ .3,.5,.5 };
  139303. /*** End of inlined file: psych_11.h ***/
  139304. static int blocksize_11[2]={
  139305. 512,512
  139306. };
  139307. static int _floor_mapping_11[2]={
  139308. 6,6,
  139309. };
  139310. static double rate_mapping_11[3]={
  139311. 8000.,13000.,44000.,
  139312. };
  139313. static double rate_mapping_11_uncoupled[3]={
  139314. 12000.,20000.,50000.,
  139315. };
  139316. static double quality_mapping_11[3]={
  139317. -.1,.0,1.
  139318. };
  139319. ve_setup_data_template ve_setup_11_stereo={
  139320. 2,
  139321. rate_mapping_11,
  139322. quality_mapping_11,
  139323. 2,
  139324. 9000,
  139325. 15000,
  139326. blocksize_11,
  139327. blocksize_11,
  139328. _psy_tone_masteratt_11,
  139329. _psy_tone_0dB,
  139330. _psy_tone_suppress,
  139331. _vp_tonemask_adj_11,
  139332. NULL,
  139333. _vp_tonemask_adj_11,
  139334. _psy_noiseguards_8,
  139335. _psy_noisebias_11,
  139336. _psy_noisebias_11,
  139337. NULL,
  139338. NULL,
  139339. _psy_noise_suppress,
  139340. _psy_compand_8,
  139341. _psy_compand_8_mapping,
  139342. NULL,
  139343. {_noise_start_8,_noise_start_8},
  139344. {_noise_part_8,_noise_part_8},
  139345. _noise_thresh_11,
  139346. _psy_ath_floater_8,
  139347. _psy_ath_abs_8,
  139348. _psy_lowpass_11,
  139349. _psy_global_44,
  139350. _global_mapping_8,
  139351. _psy_stereo_modes_8,
  139352. _floor_books,
  139353. _floor,
  139354. _floor_mapping_11,
  139355. NULL,
  139356. _mapres_template_8_stereo
  139357. };
  139358. ve_setup_data_template ve_setup_11_uncoupled={
  139359. 2,
  139360. rate_mapping_11_uncoupled,
  139361. quality_mapping_11,
  139362. -1,
  139363. 9000,
  139364. 15000,
  139365. blocksize_11,
  139366. blocksize_11,
  139367. _psy_tone_masteratt_11,
  139368. _psy_tone_0dB,
  139369. _psy_tone_suppress,
  139370. _vp_tonemask_adj_11,
  139371. NULL,
  139372. _vp_tonemask_adj_11,
  139373. _psy_noiseguards_8,
  139374. _psy_noisebias_11,
  139375. _psy_noisebias_11,
  139376. NULL,
  139377. NULL,
  139378. _psy_noise_suppress,
  139379. _psy_compand_8,
  139380. _psy_compand_8_mapping,
  139381. NULL,
  139382. {_noise_start_8,_noise_start_8},
  139383. {_noise_part_8,_noise_part_8},
  139384. _noise_thresh_11,
  139385. _psy_ath_floater_8,
  139386. _psy_ath_abs_8,
  139387. _psy_lowpass_11,
  139388. _psy_global_44,
  139389. _global_mapping_8,
  139390. _psy_stereo_modes_8,
  139391. _floor_books,
  139392. _floor,
  139393. _floor_mapping_11,
  139394. NULL,
  139395. _mapres_template_8_uncoupled
  139396. };
  139397. /*** End of inlined file: setup_11.h ***/
  139398. /*** Start of inlined file: setup_16.h ***/
  139399. /*** Start of inlined file: psych_16.h ***/
  139400. static adj_stereo _psy_stereo_modes_16[4]={
  139401. {{ 4, 4, 4, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3},
  139402. { 6, 5, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4},
  139403. { 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 4, 4},
  139404. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  139405. {{ 4, 4, 4, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3},
  139406. { 6, 5, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4},
  139407. { 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 4, 4, 4, 4, 4},
  139408. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  139409. {{ 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3},
  139410. { 5, 4, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3},
  139411. { 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4},
  139412. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  139413. {{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  139414. { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  139415. { 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8},
  139416. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  139417. };
  139418. static double _psy_lowpass_16[4]={6.5,8,30.,99.};
  139419. static att3 _psy_tone_masteratt_16[4]={
  139420. {{ 30, 25, 12}, 0, 0}, /* 0 */
  139421. {{ 25, 22, 12}, 0, 0}, /* 0 */
  139422. {{ 20, 12, 0}, 0, 0}, /* 0 */
  139423. {{ 15, 0, -14}, 0, 0}, /* 0 */
  139424. };
  139425. static vp_adjblock _vp_tonemask_adj_16[4]={
  139426. {{-20,-20,-20,-20,-20,-16,-10, 0, 0, 0, 0,10, 0, 0, 0, 0, 0}}, /* 0 */
  139427. {{-20,-20,-20,-20,-20,-16,-10, 0, 0, 0, 0,10, 0, 0, 0, 0, 0}}, /* 1 */
  139428. {{-20,-20,-20,-20,-20,-16,-10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}}, /* 2 */
  139429. {{-30,-30,-30,-30,-30,-26,-20,-10, -5, 0, 0, 0, 0, 0, 0, 0, 0}}, /* 2 */
  139430. };
  139431. static noise3 _psy_noisebias_16_short[4]={
  139432. {{{-15,-15,-15,-15,-15,-10,-10,-5, 4, 10, 10, 10, 10, 12, 12, 14, 20},
  139433. {-15,-15,-15,-15,-15,-10,-10, -5, 0, 0, 4, 5, 5, 6, 8, 8, 15},
  139434. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, -6, -6, -6}}},
  139435. {{{-15,-15,-15,-15,-15,-10,-10,-5, 4, 6, 6, 6, 6, 8, 10, 12, 20},
  139436. {-15,-15,-15,-15,-15,-15,-15,-10, -5, -5, -5, 4, 5, 6, 8, 8, 15},
  139437. {-30,-30,-30,-30,-30,-24,-20,-14,-10,-10,-10,-10,-10,-10,-10,-10,-10}}},
  139438. {{{-15,-15,-15,-15,-15,-12,-10, -8, 0, 2, 4, 4, 5, 5, 5, 8, 12},
  139439. {-20,-20,-20,-20,-16,-12,-20,-14,-10,-10, -8, 0, 0, 0, 0, 2, 5},
  139440. {-30,-30,-30,-30,-26,-26,-26,-26,-26,-26,-26,-26,-26,-24,-20,-20,-20}}},
  139441. {{{-15,-15,-15,-15,-15,-12,-10, -8, -5, -5, -5, -5, -5, 0, 0, 0, 6},
  139442. {-30,-30,-30,-30,-26,-22,-20,-14,-12,-12,-10,-10,-10,-10,-10,-10, -6},
  139443. {-30,-30,-30,-30,-26,-26,-26,-26,-26,-26,-26,-26,-26,-24,-20,-20,-20}}},
  139444. };
  139445. static noise3 _psy_noisebias_16_impulse[4]={
  139446. {{{-15,-15,-15,-15,-15,-10,-10,-5, 4, 10, 10, 10, 10, 12, 12, 14, 20},
  139447. {-15,-15,-15,-15,-15,-10,-10, -5, 0, 0, 4, 5, 5, 6, 8, 8, 15},
  139448. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, -6, -6, -6}}},
  139449. {{{-15,-15,-15,-15,-15,-10,-10,-5, 4, 4, 4, 4, 5, 5, 6, 8, 15},
  139450. {-15,-15,-15,-15,-15,-15,-15,-10, -5, -5, -5, 0, 0, 0, 0, 4, 10},
  139451. {-30,-30,-30,-30,-30,-24,-20,-14,-10,-10,-10,-10,-10,-10,-10,-10,-10}}},
  139452. {{{-15,-15,-15,-15,-15,-12,-10, -8, 0, 0, 0, 0, 0, 0, 0, 4, 10},
  139453. {-20,-20,-20,-20,-16,-12,-20,-14,-10,-10,-10,-10,-10,-10,-10, -7, -5},
  139454. {-30,-30,-30,-30,-26,-26,-26,-26,-26,-26,-26,-26,-26,-24,-20,-20,-20}}},
  139455. {{{-15,-15,-15,-15,-15,-12,-10, -8, -5, -5, -5, -5, -5, 0, 0, 0, 6},
  139456. {-30,-30,-30,-30,-26,-22,-20,-18,-18,-18,-20,-20,-20,-20,-20,-20,-16},
  139457. {-30,-30,-30,-30,-26,-26,-26,-26,-26,-26,-26,-26,-26,-24,-20,-20,-20}}},
  139458. };
  139459. static noise3 _psy_noisebias_16[4]={
  139460. {{{-10,-10,-10,-10, -5, -5, -5, 0, 4, 6, 8, 8, 10, 10, 10, 14, 20},
  139461. {-10,-10,-10,-10,-10, -5, -2, -2, 0, 0, 0, 4, 5, 6, 8, 8, 15},
  139462. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, -6, -6, -6}}},
  139463. {{{-10,-10,-10,-10, -5, -5, -5, 0, 4, 6, 6, 6, 6, 8, 10, 12, 20},
  139464. {-15,-15,-15,-15,-15,-10, -5, -5, 0, 0, 0, 4, 5, 6, 8, 8, 15},
  139465. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, -6, -6, -6}}},
  139466. {{{-15,-15,-15,-15,-15,-12,-10, -8, 0, 2, 4, 4, 5, 5, 5, 8, 12},
  139467. {-20,-20,-20,-20,-16,-12,-20,-10, -5, -5, 0, 0, 0, 0, 0, 2, 5},
  139468. {-30,-30,-30,-30,-26,-26,-26,-26,-26,-26,-26,-26,-26,-24,-20,-20,-20}}},
  139469. {{{-15,-15,-15,-15,-15,-12,-10, -8, -5, -5, -5, -5, -5, 0, 0, 0, 6},
  139470. {-30,-30,-30,-30,-26,-22,-20,-14,-12,-12,-10,-10,-10,-10,-10,-10, -6},
  139471. {-30,-30,-30,-30,-26,-26,-26,-26,-26,-26,-26,-26,-26,-24,-20,-20,-20}}},
  139472. };
  139473. static double _noise_thresh_16[4]={ .3,.5,.5,.5 };
  139474. static int _noise_start_16[3]={ 256,256,9999 };
  139475. static int _noise_part_16[4]={ 8,8,8,8 };
  139476. static int _psy_ath_floater_16[4]={
  139477. -100,-100,-100,-105,
  139478. };
  139479. static int _psy_ath_abs_16[4]={
  139480. -130,-130,-130,-140,
  139481. };
  139482. /*** End of inlined file: psych_16.h ***/
  139483. /*** Start of inlined file: residue_16.h ***/
  139484. static static_bookblock _resbook_16s_0={
  139485. {
  139486. {0},
  139487. {0,0,&_16c0_s_p1_0},
  139488. {0,0,&_16c0_s_p2_0},
  139489. {0,0,&_16c0_s_p3_0},
  139490. {0,0,&_16c0_s_p4_0},
  139491. {0,0,&_16c0_s_p5_0},
  139492. {0,0,&_16c0_s_p6_0},
  139493. {&_16c0_s_p7_0,&_16c0_s_p7_1},
  139494. {&_16c0_s_p8_0,&_16c0_s_p8_1},
  139495. {&_16c0_s_p9_0,&_16c0_s_p9_1,&_16c0_s_p9_2}
  139496. }
  139497. };
  139498. static static_bookblock _resbook_16s_1={
  139499. {
  139500. {0},
  139501. {0,0,&_16c1_s_p1_0},
  139502. {0,0,&_16c1_s_p2_0},
  139503. {0,0,&_16c1_s_p3_0},
  139504. {0,0,&_16c1_s_p4_0},
  139505. {0,0,&_16c1_s_p5_0},
  139506. {0,0,&_16c1_s_p6_0},
  139507. {&_16c1_s_p7_0,&_16c1_s_p7_1},
  139508. {&_16c1_s_p8_0,&_16c1_s_p8_1},
  139509. {&_16c1_s_p9_0,&_16c1_s_p9_1,&_16c1_s_p9_2}
  139510. }
  139511. };
  139512. static static_bookblock _resbook_16s_2={
  139513. {
  139514. {0},
  139515. {0,0,&_16c2_s_p1_0},
  139516. {0,0,&_16c2_s_p2_0},
  139517. {0,0,&_16c2_s_p3_0},
  139518. {0,0,&_16c2_s_p4_0},
  139519. {&_16c2_s_p5_0,&_16c2_s_p5_1},
  139520. {&_16c2_s_p6_0,&_16c2_s_p6_1},
  139521. {&_16c2_s_p7_0,&_16c2_s_p7_1},
  139522. {&_16c2_s_p8_0,&_16c2_s_p8_1},
  139523. {&_16c2_s_p9_0,&_16c2_s_p9_1,&_16c2_s_p9_2}
  139524. }
  139525. };
  139526. static vorbis_residue_template _res_16s_0[]={
  139527. {2,0, &_residue_44_mid,
  139528. &_huff_book__16c0_s_single,&_huff_book__16c0_s_single,
  139529. &_resbook_16s_0,&_resbook_16s_0},
  139530. };
  139531. static vorbis_residue_template _res_16s_1[]={
  139532. {2,0, &_residue_44_mid,
  139533. &_huff_book__16c1_s_short,&_huff_book__16c1_s_short,
  139534. &_resbook_16s_1,&_resbook_16s_1},
  139535. {2,0, &_residue_44_mid,
  139536. &_huff_book__16c1_s_long,&_huff_book__16c1_s_long,
  139537. &_resbook_16s_1,&_resbook_16s_1}
  139538. };
  139539. static vorbis_residue_template _res_16s_2[]={
  139540. {2,0, &_residue_44_high,
  139541. &_huff_book__16c2_s_short,&_huff_book__16c2_s_short,
  139542. &_resbook_16s_2,&_resbook_16s_2},
  139543. {2,0, &_residue_44_high,
  139544. &_huff_book__16c2_s_long,&_huff_book__16c2_s_long,
  139545. &_resbook_16s_2,&_resbook_16s_2}
  139546. };
  139547. static vorbis_mapping_template _mapres_template_16_stereo[3]={
  139548. { _map_nominal, _res_16s_0 }, /* 0 */
  139549. { _map_nominal, _res_16s_1 }, /* 1 */
  139550. { _map_nominal, _res_16s_2 }, /* 2 */
  139551. };
  139552. static static_bookblock _resbook_16u_0={
  139553. {
  139554. {0},
  139555. {0,0,&_16u0__p1_0},
  139556. {0,0,&_16u0__p2_0},
  139557. {0,0,&_16u0__p3_0},
  139558. {0,0,&_16u0__p4_0},
  139559. {0,0,&_16u0__p5_0},
  139560. {&_16u0__p6_0,&_16u0__p6_1},
  139561. {&_16u0__p7_0,&_16u0__p7_1,&_16u0__p7_2}
  139562. }
  139563. };
  139564. static static_bookblock _resbook_16u_1={
  139565. {
  139566. {0},
  139567. {0,0,&_16u1__p1_0},
  139568. {0,0,&_16u1__p2_0},
  139569. {0,0,&_16u1__p3_0},
  139570. {0,0,&_16u1__p4_0},
  139571. {0,0,&_16u1__p5_0},
  139572. {0,0,&_16u1__p6_0},
  139573. {&_16u1__p7_0,&_16u1__p7_1},
  139574. {&_16u1__p8_0,&_16u1__p8_1},
  139575. {&_16u1__p9_0,&_16u1__p9_1,&_16u1__p9_2}
  139576. }
  139577. };
  139578. static static_bookblock _resbook_16u_2={
  139579. {
  139580. {0},
  139581. {0,0,&_16u2_p1_0},
  139582. {0,0,&_16u2_p2_0},
  139583. {0,0,&_16u2_p3_0},
  139584. {0,0,&_16u2_p4_0},
  139585. {&_16u2_p5_0,&_16u2_p5_1},
  139586. {&_16u2_p6_0,&_16u2_p6_1},
  139587. {&_16u2_p7_0,&_16u2_p7_1},
  139588. {&_16u2_p8_0,&_16u2_p8_1},
  139589. {&_16u2_p9_0,&_16u2_p9_1,&_16u2_p9_2}
  139590. }
  139591. };
  139592. static vorbis_residue_template _res_16u_0[]={
  139593. {1,0, &_residue_44_low_un,
  139594. &_huff_book__16u0__single,&_huff_book__16u0__single,
  139595. &_resbook_16u_0,&_resbook_16u_0},
  139596. };
  139597. static vorbis_residue_template _res_16u_1[]={
  139598. {1,0, &_residue_44_mid_un,
  139599. &_huff_book__16u1__short,&_huff_book__16u1__short,
  139600. &_resbook_16u_1,&_resbook_16u_1},
  139601. {1,0, &_residue_44_mid_un,
  139602. &_huff_book__16u1__long,&_huff_book__16u1__long,
  139603. &_resbook_16u_1,&_resbook_16u_1}
  139604. };
  139605. static vorbis_residue_template _res_16u_2[]={
  139606. {1,0, &_residue_44_hi_un,
  139607. &_huff_book__16u2__short,&_huff_book__16u2__short,
  139608. &_resbook_16u_2,&_resbook_16u_2},
  139609. {1,0, &_residue_44_hi_un,
  139610. &_huff_book__16u2__long,&_huff_book__16u2__long,
  139611. &_resbook_16u_2,&_resbook_16u_2}
  139612. };
  139613. static vorbis_mapping_template _mapres_template_16_uncoupled[3]={
  139614. { _map_nominal_u, _res_16u_0 }, /* 0 */
  139615. { _map_nominal_u, _res_16u_1 }, /* 1 */
  139616. { _map_nominal_u, _res_16u_2 }, /* 2 */
  139617. };
  139618. /*** End of inlined file: residue_16.h ***/
  139619. static int blocksize_16_short[3]={
  139620. 1024,512,512
  139621. };
  139622. static int blocksize_16_long[3]={
  139623. 1024,1024,1024
  139624. };
  139625. static int _floor_mapping_16_short[3]={
  139626. 9,3,3
  139627. };
  139628. static int _floor_mapping_16[3]={
  139629. 9,9,9
  139630. };
  139631. static double rate_mapping_16[4]={
  139632. 12000.,20000.,44000.,86000.
  139633. };
  139634. static double rate_mapping_16_uncoupled[4]={
  139635. 16000.,28000.,64000.,100000.
  139636. };
  139637. static double _global_mapping_16[4]={ 1., 2., 3., 4. };
  139638. static double quality_mapping_16[4]={ -.1,.05,.5,1. };
  139639. static double _psy_compand_16_mapping[4]={ 0., .8, 1., 1.};
  139640. ve_setup_data_template ve_setup_16_stereo={
  139641. 3,
  139642. rate_mapping_16,
  139643. quality_mapping_16,
  139644. 2,
  139645. 15000,
  139646. 19000,
  139647. blocksize_16_short,
  139648. blocksize_16_long,
  139649. _psy_tone_masteratt_16,
  139650. _psy_tone_0dB,
  139651. _psy_tone_suppress,
  139652. _vp_tonemask_adj_16,
  139653. _vp_tonemask_adj_16,
  139654. _vp_tonemask_adj_16,
  139655. _psy_noiseguards_8,
  139656. _psy_noisebias_16_impulse,
  139657. _psy_noisebias_16_short,
  139658. _psy_noisebias_16_short,
  139659. _psy_noisebias_16,
  139660. _psy_noise_suppress,
  139661. _psy_compand_8,
  139662. _psy_compand_16_mapping,
  139663. _psy_compand_16_mapping,
  139664. {_noise_start_16,_noise_start_16},
  139665. { _noise_part_16, _noise_part_16},
  139666. _noise_thresh_16,
  139667. _psy_ath_floater_16,
  139668. _psy_ath_abs_16,
  139669. _psy_lowpass_16,
  139670. _psy_global_44,
  139671. _global_mapping_16,
  139672. _psy_stereo_modes_16,
  139673. _floor_books,
  139674. _floor,
  139675. _floor_mapping_16_short,
  139676. _floor_mapping_16,
  139677. _mapres_template_16_stereo
  139678. };
  139679. ve_setup_data_template ve_setup_16_uncoupled={
  139680. 3,
  139681. rate_mapping_16_uncoupled,
  139682. quality_mapping_16,
  139683. -1,
  139684. 15000,
  139685. 19000,
  139686. blocksize_16_short,
  139687. blocksize_16_long,
  139688. _psy_tone_masteratt_16,
  139689. _psy_tone_0dB,
  139690. _psy_tone_suppress,
  139691. _vp_tonemask_adj_16,
  139692. _vp_tonemask_adj_16,
  139693. _vp_tonemask_adj_16,
  139694. _psy_noiseguards_8,
  139695. _psy_noisebias_16_impulse,
  139696. _psy_noisebias_16_short,
  139697. _psy_noisebias_16_short,
  139698. _psy_noisebias_16,
  139699. _psy_noise_suppress,
  139700. _psy_compand_8,
  139701. _psy_compand_16_mapping,
  139702. _psy_compand_16_mapping,
  139703. {_noise_start_16,_noise_start_16},
  139704. { _noise_part_16, _noise_part_16},
  139705. _noise_thresh_16,
  139706. _psy_ath_floater_16,
  139707. _psy_ath_abs_16,
  139708. _psy_lowpass_16,
  139709. _psy_global_44,
  139710. _global_mapping_16,
  139711. _psy_stereo_modes_16,
  139712. _floor_books,
  139713. _floor,
  139714. _floor_mapping_16_short,
  139715. _floor_mapping_16,
  139716. _mapres_template_16_uncoupled
  139717. };
  139718. /*** End of inlined file: setup_16.h ***/
  139719. /*** Start of inlined file: setup_22.h ***/
  139720. static double rate_mapping_22[4]={
  139721. 15000.,20000.,44000.,86000.
  139722. };
  139723. static double rate_mapping_22_uncoupled[4]={
  139724. 16000.,28000.,50000.,90000.
  139725. };
  139726. static double _psy_lowpass_22[4]={9.5,11.,30.,99.};
  139727. ve_setup_data_template ve_setup_22_stereo={
  139728. 3,
  139729. rate_mapping_22,
  139730. quality_mapping_16,
  139731. 2,
  139732. 19000,
  139733. 26000,
  139734. blocksize_16_short,
  139735. blocksize_16_long,
  139736. _psy_tone_masteratt_16,
  139737. _psy_tone_0dB,
  139738. _psy_tone_suppress,
  139739. _vp_tonemask_adj_16,
  139740. _vp_tonemask_adj_16,
  139741. _vp_tonemask_adj_16,
  139742. _psy_noiseguards_8,
  139743. _psy_noisebias_16_impulse,
  139744. _psy_noisebias_16_short,
  139745. _psy_noisebias_16_short,
  139746. _psy_noisebias_16,
  139747. _psy_noise_suppress,
  139748. _psy_compand_8,
  139749. _psy_compand_8_mapping,
  139750. _psy_compand_8_mapping,
  139751. {_noise_start_16,_noise_start_16},
  139752. { _noise_part_16, _noise_part_16},
  139753. _noise_thresh_16,
  139754. _psy_ath_floater_16,
  139755. _psy_ath_abs_16,
  139756. _psy_lowpass_22,
  139757. _psy_global_44,
  139758. _global_mapping_16,
  139759. _psy_stereo_modes_16,
  139760. _floor_books,
  139761. _floor,
  139762. _floor_mapping_16_short,
  139763. _floor_mapping_16,
  139764. _mapres_template_16_stereo
  139765. };
  139766. ve_setup_data_template ve_setup_22_uncoupled={
  139767. 3,
  139768. rate_mapping_22_uncoupled,
  139769. quality_mapping_16,
  139770. -1,
  139771. 19000,
  139772. 26000,
  139773. blocksize_16_short,
  139774. blocksize_16_long,
  139775. _psy_tone_masteratt_16,
  139776. _psy_tone_0dB,
  139777. _psy_tone_suppress,
  139778. _vp_tonemask_adj_16,
  139779. _vp_tonemask_adj_16,
  139780. _vp_tonemask_adj_16,
  139781. _psy_noiseguards_8,
  139782. _psy_noisebias_16_impulse,
  139783. _psy_noisebias_16_short,
  139784. _psy_noisebias_16_short,
  139785. _psy_noisebias_16,
  139786. _psy_noise_suppress,
  139787. _psy_compand_8,
  139788. _psy_compand_8_mapping,
  139789. _psy_compand_8_mapping,
  139790. {_noise_start_16,_noise_start_16},
  139791. { _noise_part_16, _noise_part_16},
  139792. _noise_thresh_16,
  139793. _psy_ath_floater_16,
  139794. _psy_ath_abs_16,
  139795. _psy_lowpass_22,
  139796. _psy_global_44,
  139797. _global_mapping_16,
  139798. _psy_stereo_modes_16,
  139799. _floor_books,
  139800. _floor,
  139801. _floor_mapping_16_short,
  139802. _floor_mapping_16,
  139803. _mapres_template_16_uncoupled
  139804. };
  139805. /*** End of inlined file: setup_22.h ***/
  139806. /*** Start of inlined file: setup_X.h ***/
  139807. static double rate_mapping_X[12]={
  139808. -1.,-1.,-1.,-1.,-1.,-1.,
  139809. -1.,-1.,-1.,-1.,-1.,-1.
  139810. };
  139811. ve_setup_data_template ve_setup_X_stereo={
  139812. 11,
  139813. rate_mapping_X,
  139814. quality_mapping_44,
  139815. 2,
  139816. 50000,
  139817. 200000,
  139818. blocksize_short_44,
  139819. blocksize_long_44,
  139820. _psy_tone_masteratt_44,
  139821. _psy_tone_0dB,
  139822. _psy_tone_suppress,
  139823. _vp_tonemask_adj_otherblock,
  139824. _vp_tonemask_adj_longblock,
  139825. _vp_tonemask_adj_otherblock,
  139826. _psy_noiseguards_44,
  139827. _psy_noisebias_impulse,
  139828. _psy_noisebias_padding,
  139829. _psy_noisebias_trans,
  139830. _psy_noisebias_long,
  139831. _psy_noise_suppress,
  139832. _psy_compand_44,
  139833. _psy_compand_short_mapping,
  139834. _psy_compand_long_mapping,
  139835. {_noise_start_short_44,_noise_start_long_44},
  139836. {_noise_part_short_44,_noise_part_long_44},
  139837. _noise_thresh_44,
  139838. _psy_ath_floater,
  139839. _psy_ath_abs,
  139840. _psy_lowpass_44,
  139841. _psy_global_44,
  139842. _global_mapping_44,
  139843. _psy_stereo_modes_44,
  139844. _floor_books,
  139845. _floor,
  139846. _floor_short_mapping_44,
  139847. _floor_long_mapping_44,
  139848. _mapres_template_44_stereo
  139849. };
  139850. ve_setup_data_template ve_setup_X_uncoupled={
  139851. 11,
  139852. rate_mapping_X,
  139853. quality_mapping_44,
  139854. -1,
  139855. 50000,
  139856. 200000,
  139857. blocksize_short_44,
  139858. blocksize_long_44,
  139859. _psy_tone_masteratt_44,
  139860. _psy_tone_0dB,
  139861. _psy_tone_suppress,
  139862. _vp_tonemask_adj_otherblock,
  139863. _vp_tonemask_adj_longblock,
  139864. _vp_tonemask_adj_otherblock,
  139865. _psy_noiseguards_44,
  139866. _psy_noisebias_impulse,
  139867. _psy_noisebias_padding,
  139868. _psy_noisebias_trans,
  139869. _psy_noisebias_long,
  139870. _psy_noise_suppress,
  139871. _psy_compand_44,
  139872. _psy_compand_short_mapping,
  139873. _psy_compand_long_mapping,
  139874. {_noise_start_short_44,_noise_start_long_44},
  139875. {_noise_part_short_44,_noise_part_long_44},
  139876. _noise_thresh_44,
  139877. _psy_ath_floater,
  139878. _psy_ath_abs,
  139879. _psy_lowpass_44,
  139880. _psy_global_44,
  139881. _global_mapping_44,
  139882. NULL,
  139883. _floor_books,
  139884. _floor,
  139885. _floor_short_mapping_44,
  139886. _floor_long_mapping_44,
  139887. _mapres_template_44_uncoupled
  139888. };
  139889. ve_setup_data_template ve_setup_XX_stereo={
  139890. 2,
  139891. rate_mapping_X,
  139892. quality_mapping_8,
  139893. 2,
  139894. 0,
  139895. 8000,
  139896. blocksize_8,
  139897. blocksize_8,
  139898. _psy_tone_masteratt_8,
  139899. _psy_tone_0dB,
  139900. _psy_tone_suppress,
  139901. _vp_tonemask_adj_8,
  139902. NULL,
  139903. _vp_tonemask_adj_8,
  139904. _psy_noiseguards_8,
  139905. _psy_noisebias_8,
  139906. _psy_noisebias_8,
  139907. NULL,
  139908. NULL,
  139909. _psy_noise_suppress,
  139910. _psy_compand_8,
  139911. _psy_compand_8_mapping,
  139912. NULL,
  139913. {_noise_start_8,_noise_start_8},
  139914. {_noise_part_8,_noise_part_8},
  139915. _noise_thresh_5only,
  139916. _psy_ath_floater_8,
  139917. _psy_ath_abs_8,
  139918. _psy_lowpass_8,
  139919. _psy_global_44,
  139920. _global_mapping_8,
  139921. _psy_stereo_modes_8,
  139922. _floor_books,
  139923. _floor,
  139924. _floor_mapping_8,
  139925. NULL,
  139926. _mapres_template_8_stereo
  139927. };
  139928. ve_setup_data_template ve_setup_XX_uncoupled={
  139929. 2,
  139930. rate_mapping_X,
  139931. quality_mapping_8,
  139932. -1,
  139933. 0,
  139934. 8000,
  139935. blocksize_8,
  139936. blocksize_8,
  139937. _psy_tone_masteratt_8,
  139938. _psy_tone_0dB,
  139939. _psy_tone_suppress,
  139940. _vp_tonemask_adj_8,
  139941. NULL,
  139942. _vp_tonemask_adj_8,
  139943. _psy_noiseguards_8,
  139944. _psy_noisebias_8,
  139945. _psy_noisebias_8,
  139946. NULL,
  139947. NULL,
  139948. _psy_noise_suppress,
  139949. _psy_compand_8,
  139950. _psy_compand_8_mapping,
  139951. NULL,
  139952. {_noise_start_8,_noise_start_8},
  139953. {_noise_part_8,_noise_part_8},
  139954. _noise_thresh_5only,
  139955. _psy_ath_floater_8,
  139956. _psy_ath_abs_8,
  139957. _psy_lowpass_8,
  139958. _psy_global_44,
  139959. _global_mapping_8,
  139960. _psy_stereo_modes_8,
  139961. _floor_books,
  139962. _floor,
  139963. _floor_mapping_8,
  139964. NULL,
  139965. _mapres_template_8_uncoupled
  139966. };
  139967. /*** End of inlined file: setup_X.h ***/
  139968. static ve_setup_data_template *setup_list[]={
  139969. &ve_setup_44_stereo,
  139970. &ve_setup_44_uncoupled,
  139971. &ve_setup_32_stereo,
  139972. &ve_setup_32_uncoupled,
  139973. &ve_setup_22_stereo,
  139974. &ve_setup_22_uncoupled,
  139975. &ve_setup_16_stereo,
  139976. &ve_setup_16_uncoupled,
  139977. &ve_setup_11_stereo,
  139978. &ve_setup_11_uncoupled,
  139979. &ve_setup_8_stereo,
  139980. &ve_setup_8_uncoupled,
  139981. &ve_setup_X_stereo,
  139982. &ve_setup_X_uncoupled,
  139983. &ve_setup_XX_stereo,
  139984. &ve_setup_XX_uncoupled,
  139985. 0
  139986. };
  139987. static int vorbis_encode_toplevel_setup(vorbis_info *vi,int ch,long rate){
  139988. if(vi && vi->codec_setup){
  139989. vi->version=0;
  139990. vi->channels=ch;
  139991. vi->rate=rate;
  139992. return(0);
  139993. }
  139994. return(OV_EINVAL);
  139995. }
  139996. static void vorbis_encode_floor_setup(vorbis_info *vi,double s,int block,
  139997. static_codebook ***books,
  139998. vorbis_info_floor1 *in,
  139999. int *x){
  140000. int i,k,is=s;
  140001. vorbis_info_floor1 *f=(vorbis_info_floor1*) _ogg_calloc(1,sizeof(*f));
  140002. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  140003. memcpy(f,in+x[is],sizeof(*f));
  140004. f->n=ci->blocksizes[block]>>1;
  140005. {
  140006. int partitions=f->partitions;
  140007. int maxclass=-1;
  140008. int maxbook=-1;
  140009. for(i=0;i<partitions;i++)
  140010. if(f->partitionclass[i]>maxclass)maxclass=f->partitionclass[i];
  140011. for(i=0;i<=maxclass;i++){
  140012. if(f->class_book[i]>maxbook)maxbook=f->class_book[i];
  140013. f->class_book[i]+=ci->books;
  140014. for(k=0;k<(1<<f->class_subs[i]);k++){
  140015. if(f->class_subbook[i][k]>maxbook)maxbook=f->class_subbook[i][k];
  140016. if(f->class_subbook[i][k]>=0)f->class_subbook[i][k]+=ci->books;
  140017. }
  140018. }
  140019. for(i=0;i<=maxbook;i++)
  140020. ci->book_param[ci->books++]=books[x[is]][i];
  140021. }
  140022. ci->floor_type[ci->floors]=1;
  140023. ci->floor_param[ci->floors]=f;
  140024. ci->floors++;
  140025. return;
  140026. }
  140027. static void vorbis_encode_global_psych_setup(vorbis_info *vi,double s,
  140028. vorbis_info_psy_global *in,
  140029. double *x){
  140030. int i,is=s;
  140031. double ds=s-is;
  140032. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  140033. vorbis_info_psy_global *g=&ci->psy_g_param;
  140034. memcpy(g,in+(int)x[is],sizeof(*g));
  140035. ds=x[is]*(1.-ds)+x[is+1]*ds;
  140036. is=(int)ds;
  140037. ds-=is;
  140038. if(ds==0 && is>0){
  140039. is--;
  140040. ds=1.;
  140041. }
  140042. for(i=0;i<4;i++){
  140043. g->preecho_thresh[i]=in[is].preecho_thresh[i]*(1.-ds)+in[is+1].preecho_thresh[i]*ds;
  140044. g->postecho_thresh[i]=in[is].postecho_thresh[i]*(1.-ds)+in[is+1].postecho_thresh[i]*ds;
  140045. }
  140046. g->ampmax_att_per_sec=ci->hi.amplitude_track_dBpersec;
  140047. return;
  140048. }
  140049. static void vorbis_encode_global_stereo(vorbis_info *vi,
  140050. highlevel_encode_setup *hi,
  140051. adj_stereo *p){
  140052. float s=hi->stereo_point_setting;
  140053. int i,is=s;
  140054. double ds=s-is;
  140055. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  140056. vorbis_info_psy_global *g=&ci->psy_g_param;
  140057. if(p){
  140058. memcpy(g->coupling_prepointamp,p[is].pre,sizeof(*p[is].pre)*PACKETBLOBS);
  140059. memcpy(g->coupling_postpointamp,p[is].post,sizeof(*p[is].post)*PACKETBLOBS);
  140060. if(hi->managed){
  140061. for(i=0;i<PACKETBLOBS;i++){
  140062. float kHz=p[is].kHz[i]*(1.-ds)+p[is+1].kHz[i]*ds;
  140063. g->coupling_pointlimit[0][i]=kHz*1000./vi->rate*ci->blocksizes[0];
  140064. g->coupling_pointlimit[1][i]=kHz*1000./vi->rate*ci->blocksizes[1];
  140065. g->coupling_pkHz[i]=kHz;
  140066. kHz=p[is].lowpasskHz[i]*(1.-ds)+p[is+1].lowpasskHz[i]*ds;
  140067. g->sliding_lowpass[0][i]=kHz*1000./vi->rate*ci->blocksizes[0];
  140068. g->sliding_lowpass[1][i]=kHz*1000./vi->rate*ci->blocksizes[1];
  140069. }
  140070. }else{
  140071. float kHz=p[is].kHz[PACKETBLOBS/2]*(1.-ds)+p[is+1].kHz[PACKETBLOBS/2]*ds;
  140072. for(i=0;i<PACKETBLOBS;i++){
  140073. g->coupling_pointlimit[0][i]=kHz*1000./vi->rate*ci->blocksizes[0];
  140074. g->coupling_pointlimit[1][i]=kHz*1000./vi->rate*ci->blocksizes[1];
  140075. g->coupling_pkHz[i]=kHz;
  140076. }
  140077. kHz=p[is].lowpasskHz[PACKETBLOBS/2]*(1.-ds)+p[is+1].lowpasskHz[PACKETBLOBS/2]*ds;
  140078. for(i=0;i<PACKETBLOBS;i++){
  140079. g->sliding_lowpass[0][i]=kHz*1000./vi->rate*ci->blocksizes[0];
  140080. g->sliding_lowpass[1][i]=kHz*1000./vi->rate*ci->blocksizes[1];
  140081. }
  140082. }
  140083. }else{
  140084. for(i=0;i<PACKETBLOBS;i++){
  140085. g->sliding_lowpass[0][i]=ci->blocksizes[0];
  140086. g->sliding_lowpass[1][i]=ci->blocksizes[1];
  140087. }
  140088. }
  140089. return;
  140090. }
  140091. static void vorbis_encode_psyset_setup(vorbis_info *vi,double s,
  140092. int *nn_start,
  140093. int *nn_partition,
  140094. double *nn_thresh,
  140095. int block){
  140096. codec_setup_info *ci=(codec_setup_info*) vi->codec_setup;
  140097. vorbis_info_psy *p=ci->psy_param[block];
  140098. highlevel_encode_setup *hi=&ci->hi;
  140099. int is=s;
  140100. if(block>=ci->psys)
  140101. ci->psys=block+1;
  140102. if(!p){
  140103. p=(vorbis_info_psy*)_ogg_calloc(1,sizeof(*p));
  140104. ci->psy_param[block]=p;
  140105. }
  140106. memcpy(p,&_psy_info_template,sizeof(*p));
  140107. p->blockflag=block>>1;
  140108. if(hi->noise_normalize_p){
  140109. p->normal_channel_p=1;
  140110. p->normal_point_p=1;
  140111. p->normal_start=nn_start[is];
  140112. p->normal_partition=nn_partition[is];
  140113. p->normal_thresh=nn_thresh[is];
  140114. }
  140115. return;
  140116. }
  140117. static void vorbis_encode_tonemask_setup(vorbis_info *vi,double s,int block,
  140118. att3 *att,
  140119. int *max,
  140120. vp_adjblock *in){
  140121. int i,is=s;
  140122. double ds=s-is;
  140123. codec_setup_info *ci=(codec_setup_info*) vi->codec_setup;
  140124. vorbis_info_psy *p=ci->psy_param[block];
  140125. p->tone_masteratt[0]=att[is].att[0]*(1.-ds)+att[is+1].att[0]*ds;
  140126. p->tone_masteratt[1]=att[is].att[1]*(1.-ds)+att[is+1].att[1]*ds;
  140127. p->tone_masteratt[2]=att[is].att[2]*(1.-ds)+att[is+1].att[2]*ds;
  140128. p->tone_centerboost=att[is].boost*(1.-ds)+att[is+1].boost*ds;
  140129. p->tone_decay=att[is].decay*(1.-ds)+att[is+1].decay*ds;
  140130. p->max_curve_dB=max[is]*(1.-ds)+max[is+1]*ds;
  140131. for(i=0;i<P_BANDS;i++)
  140132. p->toneatt[i]=in[is].block[i]*(1.-ds)+in[is+1].block[i]*ds;
  140133. return;
  140134. }
  140135. static void vorbis_encode_compand_setup(vorbis_info *vi,double s,int block,
  140136. compandblock *in, double *x){
  140137. int i,is=s;
  140138. double ds=s-is;
  140139. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  140140. vorbis_info_psy *p=ci->psy_param[block];
  140141. ds=x[is]*(1.-ds)+x[is+1]*ds;
  140142. is=(int)ds;
  140143. ds-=is;
  140144. if(ds==0 && is>0){
  140145. is--;
  140146. ds=1.;
  140147. }
  140148. for(i=0;i<NOISE_COMPAND_LEVELS;i++)
  140149. p->noisecompand[i]=in[is].data[i]*(1.-ds)+in[is+1].data[i]*ds;
  140150. return;
  140151. }
  140152. static void vorbis_encode_peak_setup(vorbis_info *vi,double s,int block,
  140153. int *suppress){
  140154. int is=s;
  140155. double ds=s-is;
  140156. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  140157. vorbis_info_psy *p=ci->psy_param[block];
  140158. p->tone_abs_limit=suppress[is]*(1.-ds)+suppress[is+1]*ds;
  140159. return;
  140160. }
  140161. static void vorbis_encode_noisebias_setup(vorbis_info *vi,double s,int block,
  140162. int *suppress,
  140163. noise3 *in,
  140164. noiseguard *guard,
  140165. double userbias){
  140166. int i,is=s,j;
  140167. double ds=s-is;
  140168. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  140169. vorbis_info_psy *p=ci->psy_param[block];
  140170. p->noisemaxsupp=suppress[is]*(1.-ds)+suppress[is+1]*ds;
  140171. p->noisewindowlomin=guard[block].lo;
  140172. p->noisewindowhimin=guard[block].hi;
  140173. p->noisewindowfixed=guard[block].fixed;
  140174. for(j=0;j<P_NOISECURVES;j++)
  140175. for(i=0;i<P_BANDS;i++)
  140176. p->noiseoff[j][i]=in[is].data[j][i]*(1.-ds)+in[is+1].data[j][i]*ds;
  140177. for(j=0;j<P_NOISECURVES;j++){
  140178. float min=p->noiseoff[j][0]+6; /* the lowest it can go */
  140179. for(i=0;i<P_BANDS;i++){
  140180. p->noiseoff[j][i]+=userbias;
  140181. if(p->noiseoff[j][i]<min)p->noiseoff[j][i]=min;
  140182. }
  140183. }
  140184. return;
  140185. }
  140186. static void vorbis_encode_ath_setup(vorbis_info *vi,int block){
  140187. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  140188. vorbis_info_psy *p=ci->psy_param[block];
  140189. p->ath_adjatt=ci->hi.ath_floating_dB;
  140190. p->ath_maxatt=ci->hi.ath_absolute_dB;
  140191. return;
  140192. }
  140193. static int book_dup_or_new(codec_setup_info *ci,static_codebook *book){
  140194. int i;
  140195. for(i=0;i<ci->books;i++)
  140196. if(ci->book_param[i]==book)return(i);
  140197. return(ci->books++);
  140198. }
  140199. static void vorbis_encode_blocksize_setup(vorbis_info *vi,double s,
  140200. int *shortb,int *longb){
  140201. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  140202. int is=s;
  140203. int blockshort=shortb[is];
  140204. int blocklong=longb[is];
  140205. ci->blocksizes[0]=blockshort;
  140206. ci->blocksizes[1]=blocklong;
  140207. }
  140208. static void vorbis_encode_residue_setup(vorbis_info *vi,
  140209. int number, int block,
  140210. vorbis_residue_template *res){
  140211. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  140212. int i,n;
  140213. vorbis_info_residue0 *r=(vorbis_info_residue0*)(ci->residue_param[number]=
  140214. (vorbis_info_residue0*)_ogg_malloc(sizeof(*r)));
  140215. memcpy(r,res->res,sizeof(*r));
  140216. if(ci->residues<=number)ci->residues=number+1;
  140217. switch(ci->blocksizes[block]){
  140218. case 64:case 128:case 256:
  140219. r->grouping=16;
  140220. break;
  140221. default:
  140222. r->grouping=32;
  140223. break;
  140224. }
  140225. ci->residue_type[number]=res->res_type;
  140226. n=r->end=ci->blocksizes[block]>>1;
  140227. if(res->res_type==2)
  140228. n=r->end*=vi->channels;
  140229. {
  140230. int booklist=0,k;
  140231. if(ci->hi.managed){
  140232. for(i=0;i<r->partitions;i++)
  140233. for(k=0;k<3;k++)
  140234. if(res->books_base_managed->books[i][k])
  140235. r->secondstages[i]|=(1<<k);
  140236. r->groupbook=book_dup_or_new(ci,res->book_aux_managed);
  140237. ci->book_param[r->groupbook]=res->book_aux_managed;
  140238. for(i=0;i<r->partitions;i++){
  140239. for(k=0;k<3;k++){
  140240. if(res->books_base_managed->books[i][k]){
  140241. int bookid=book_dup_or_new(ci,res->books_base_managed->books[i][k]);
  140242. r->booklist[booklist++]=bookid;
  140243. ci->book_param[bookid]=res->books_base_managed->books[i][k];
  140244. }
  140245. }
  140246. }
  140247. }else{
  140248. for(i=0;i<r->partitions;i++)
  140249. for(k=0;k<3;k++)
  140250. if(res->books_base->books[i][k])
  140251. r->secondstages[i]|=(1<<k);
  140252. r->groupbook=book_dup_or_new(ci,res->book_aux);
  140253. ci->book_param[r->groupbook]=res->book_aux;
  140254. for(i=0;i<r->partitions;i++){
  140255. for(k=0;k<3;k++){
  140256. if(res->books_base->books[i][k]){
  140257. int bookid=book_dup_or_new(ci,res->books_base->books[i][k]);
  140258. r->booklist[booklist++]=bookid;
  140259. ci->book_param[bookid]=res->books_base->books[i][k];
  140260. }
  140261. }
  140262. }
  140263. }
  140264. }
  140265. {
  140266. double freq=ci->hi.lowpass_kHz*1000.;
  140267. vorbis_info_floor1 *f=(vorbis_info_floor1*)ci->floor_param[block]; /* by convention */
  140268. double nyq=vi->rate/2.;
  140269. long blocksize=ci->blocksizes[block]>>1;
  140270. if(freq>nyq)freq=nyq;
  140271. f->n=freq/nyq*blocksize;
  140272. if(res->limit_type){
  140273. if(ci->hi.managed)
  140274. freq=ci->psy_g_param.coupling_pkHz[PACKETBLOBS-1]*1000.;
  140275. else
  140276. freq=ci->psy_g_param.coupling_pkHz[PACKETBLOBS/2]*1000.;
  140277. if(freq>nyq)freq=nyq;
  140278. }
  140279. if(ci->residue_type[block]==2)
  140280. r->end=(int)((freq/nyq*blocksize*2)/r->grouping+.9)* /* round up only if we're well past */
  140281. r->grouping;
  140282. else
  140283. r->end=(int)((freq/nyq*blocksize)/r->grouping+.9)* /* round up only if we're well past */
  140284. r->grouping;
  140285. }
  140286. }
  140287. static void vorbis_encode_map_n_res_setup(vorbis_info *vi,double s,
  140288. vorbis_mapping_template *maps){
  140289. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  140290. int i,j,is=s,modes=2;
  140291. vorbis_info_mapping0 *map=maps[is].map;
  140292. vorbis_info_mode *mode=_mode_template;
  140293. vorbis_residue_template *res=maps[is].res;
  140294. if(ci->blocksizes[0]==ci->blocksizes[1])modes=1;
  140295. for(i=0;i<modes;i++){
  140296. ci->map_param[i]=_ogg_calloc(1,sizeof(*map));
  140297. ci->mode_param[i]=(vorbis_info_mode*)_ogg_calloc(1,sizeof(*mode));
  140298. memcpy(ci->mode_param[i],mode+i,sizeof(*_mode_template));
  140299. if(i>=ci->modes)ci->modes=i+1;
  140300. ci->map_type[i]=0;
  140301. memcpy(ci->map_param[i],map+i,sizeof(*map));
  140302. if(i>=ci->maps)ci->maps=i+1;
  140303. for(j=0;j<map[i].submaps;j++)
  140304. vorbis_encode_residue_setup(vi,map[i].residuesubmap[j],i
  140305. ,res+map[i].residuesubmap[j]);
  140306. }
  140307. }
  140308. static double setting_to_approx_bitrate(vorbis_info *vi){
  140309. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  140310. highlevel_encode_setup *hi=&ci->hi;
  140311. ve_setup_data_template *setup=(ve_setup_data_template *)hi->setup;
  140312. int is=hi->base_setting;
  140313. double ds=hi->base_setting-is;
  140314. int ch=vi->channels;
  140315. double *r=setup->rate_mapping;
  140316. if(r==NULL)
  140317. return(-1);
  140318. return((r[is]*(1.-ds)+r[is+1]*ds)*ch);
  140319. }
  140320. static void get_setup_template(vorbis_info *vi,
  140321. long ch,long srate,
  140322. double req,int q_or_bitrate){
  140323. int i=0,j;
  140324. codec_setup_info *ci=(codec_setup_info*) vi->codec_setup;
  140325. highlevel_encode_setup *hi=&ci->hi;
  140326. if(q_or_bitrate)req/=ch;
  140327. while(setup_list[i]){
  140328. if(setup_list[i]->coupling_restriction==-1 ||
  140329. setup_list[i]->coupling_restriction==ch){
  140330. if(srate>=setup_list[i]->samplerate_min_restriction &&
  140331. srate<=setup_list[i]->samplerate_max_restriction){
  140332. int mappings=setup_list[i]->mappings;
  140333. double *map=(q_or_bitrate?
  140334. setup_list[i]->rate_mapping:
  140335. setup_list[i]->quality_mapping);
  140336. if(req<map[0]){++i;continue;}
  140337. if(req>map[setup_list[i]->mappings]){++i;continue;}
  140338. for(j=0;j<mappings;j++)
  140339. if(req>=map[j] && req<map[j+1])break;
  140340. hi->setup=setup_list[i];
  140341. if(j==mappings)
  140342. hi->base_setting=j-.001;
  140343. else{
  140344. float low=map[j];
  140345. float high=map[j+1];
  140346. float del=(req-low)/(high-low);
  140347. hi->base_setting=j+del;
  140348. }
  140349. return;
  140350. }
  140351. }
  140352. i++;
  140353. }
  140354. hi->setup=NULL;
  140355. }
  140356. int vorbis_encode_setup_init(vorbis_info *vi){
  140357. int i0=0,singleblock=0;
  140358. codec_setup_info *ci=(codec_setup_info*) vi->codec_setup;
  140359. ve_setup_data_template *setup=NULL;
  140360. highlevel_encode_setup *hi=&ci->hi;
  140361. if(ci==NULL)return(OV_EINVAL);
  140362. if(!hi->impulse_block_p)i0=1;
  140363. if(hi->ath_floating_dB>-80)hi->ath_floating_dB=-80;
  140364. if(hi->ath_floating_dB<-200)hi->ath_floating_dB=-200;
  140365. if(hi->amplitude_track_dBpersec>0.)hi->amplitude_track_dBpersec=0.;
  140366. if(hi->amplitude_track_dBpersec<-99999.)hi->amplitude_track_dBpersec=-99999.;
  140367. setup=(ve_setup_data_template *)hi->setup;
  140368. if(setup==NULL)return(OV_EINVAL);
  140369. hi->set_in_stone=1;
  140370. vorbis_encode_blocksize_setup(vi,hi->base_setting,
  140371. setup->blocksize_short,
  140372. setup->blocksize_long);
  140373. if(ci->blocksizes[0]==ci->blocksizes[1])singleblock=1;
  140374. vorbis_encode_floor_setup(vi,hi->short_setting,0,
  140375. setup->floor_books,
  140376. setup->floor_params,
  140377. setup->floor_short_mapping);
  140378. if(!singleblock)
  140379. vorbis_encode_floor_setup(vi,hi->long_setting,1,
  140380. setup->floor_books,
  140381. setup->floor_params,
  140382. setup->floor_long_mapping);
  140383. vorbis_encode_global_psych_setup(vi,hi->trigger_setting,
  140384. setup->global_params,
  140385. setup->global_mapping);
  140386. vorbis_encode_global_stereo(vi,hi,setup->stereo_modes);
  140387. vorbis_encode_psyset_setup(vi,hi->short_setting,
  140388. setup->psy_noise_normal_start[0],
  140389. setup->psy_noise_normal_partition[0],
  140390. setup->psy_noise_normal_thresh,
  140391. 0);
  140392. vorbis_encode_psyset_setup(vi,hi->short_setting,
  140393. setup->psy_noise_normal_start[0],
  140394. setup->psy_noise_normal_partition[0],
  140395. setup->psy_noise_normal_thresh,
  140396. 1);
  140397. if(!singleblock){
  140398. vorbis_encode_psyset_setup(vi,hi->long_setting,
  140399. setup->psy_noise_normal_start[1],
  140400. setup->psy_noise_normal_partition[1],
  140401. setup->psy_noise_normal_thresh,
  140402. 2);
  140403. vorbis_encode_psyset_setup(vi,hi->long_setting,
  140404. setup->psy_noise_normal_start[1],
  140405. setup->psy_noise_normal_partition[1],
  140406. setup->psy_noise_normal_thresh,
  140407. 3);
  140408. }
  140409. vorbis_encode_tonemask_setup(vi,hi->block[i0].tone_mask_setting,0,
  140410. setup->psy_tone_masteratt,
  140411. setup->psy_tone_0dB,
  140412. setup->psy_tone_adj_impulse);
  140413. vorbis_encode_tonemask_setup(vi,hi->block[1].tone_mask_setting,1,
  140414. setup->psy_tone_masteratt,
  140415. setup->psy_tone_0dB,
  140416. setup->psy_tone_adj_other);
  140417. if(!singleblock){
  140418. vorbis_encode_tonemask_setup(vi,hi->block[2].tone_mask_setting,2,
  140419. setup->psy_tone_masteratt,
  140420. setup->psy_tone_0dB,
  140421. setup->psy_tone_adj_other);
  140422. vorbis_encode_tonemask_setup(vi,hi->block[3].tone_mask_setting,3,
  140423. setup->psy_tone_masteratt,
  140424. setup->psy_tone_0dB,
  140425. setup->psy_tone_adj_long);
  140426. }
  140427. vorbis_encode_compand_setup(vi,hi->block[i0].noise_compand_setting,0,
  140428. setup->psy_noise_compand,
  140429. setup->psy_noise_compand_short_mapping);
  140430. vorbis_encode_compand_setup(vi,hi->block[1].noise_compand_setting,1,
  140431. setup->psy_noise_compand,
  140432. setup->psy_noise_compand_short_mapping);
  140433. if(!singleblock){
  140434. vorbis_encode_compand_setup(vi,hi->block[2].noise_compand_setting,2,
  140435. setup->psy_noise_compand,
  140436. setup->psy_noise_compand_long_mapping);
  140437. vorbis_encode_compand_setup(vi,hi->block[3].noise_compand_setting,3,
  140438. setup->psy_noise_compand,
  140439. setup->psy_noise_compand_long_mapping);
  140440. }
  140441. vorbis_encode_peak_setup(vi,hi->block[i0].tone_peaklimit_setting,0,
  140442. setup->psy_tone_dBsuppress);
  140443. vorbis_encode_peak_setup(vi,hi->block[1].tone_peaklimit_setting,1,
  140444. setup->psy_tone_dBsuppress);
  140445. if(!singleblock){
  140446. vorbis_encode_peak_setup(vi,hi->block[2].tone_peaklimit_setting,2,
  140447. setup->psy_tone_dBsuppress);
  140448. vorbis_encode_peak_setup(vi,hi->block[3].tone_peaklimit_setting,3,
  140449. setup->psy_tone_dBsuppress);
  140450. }
  140451. vorbis_encode_noisebias_setup(vi,hi->block[i0].noise_bias_setting,0,
  140452. setup->psy_noise_dBsuppress,
  140453. setup->psy_noise_bias_impulse,
  140454. setup->psy_noiseguards,
  140455. (i0==0?hi->impulse_noisetune:0.));
  140456. vorbis_encode_noisebias_setup(vi,hi->block[1].noise_bias_setting,1,
  140457. setup->psy_noise_dBsuppress,
  140458. setup->psy_noise_bias_padding,
  140459. setup->psy_noiseguards,0.);
  140460. if(!singleblock){
  140461. vorbis_encode_noisebias_setup(vi,hi->block[2].noise_bias_setting,2,
  140462. setup->psy_noise_dBsuppress,
  140463. setup->psy_noise_bias_trans,
  140464. setup->psy_noiseguards,0.);
  140465. vorbis_encode_noisebias_setup(vi,hi->block[3].noise_bias_setting,3,
  140466. setup->psy_noise_dBsuppress,
  140467. setup->psy_noise_bias_long,
  140468. setup->psy_noiseguards,0.);
  140469. }
  140470. vorbis_encode_ath_setup(vi,0);
  140471. vorbis_encode_ath_setup(vi,1);
  140472. if(!singleblock){
  140473. vorbis_encode_ath_setup(vi,2);
  140474. vorbis_encode_ath_setup(vi,3);
  140475. }
  140476. vorbis_encode_map_n_res_setup(vi,hi->base_setting,setup->maps);
  140477. if(hi->bitrate_av>0)
  140478. vi->bitrate_nominal=hi->bitrate_av;
  140479. else{
  140480. vi->bitrate_nominal=setting_to_approx_bitrate(vi);
  140481. }
  140482. vi->bitrate_lower=hi->bitrate_min;
  140483. vi->bitrate_upper=hi->bitrate_max;
  140484. if(hi->bitrate_av)
  140485. vi->bitrate_window=(double)hi->bitrate_reservoir/hi->bitrate_av;
  140486. else
  140487. vi->bitrate_window=0.;
  140488. if(hi->managed){
  140489. ci->bi.avg_rate=hi->bitrate_av;
  140490. ci->bi.min_rate=hi->bitrate_min;
  140491. ci->bi.max_rate=hi->bitrate_max;
  140492. ci->bi.reservoir_bits=hi->bitrate_reservoir;
  140493. ci->bi.reservoir_bias=
  140494. hi->bitrate_reservoir_bias;
  140495. ci->bi.slew_damp=hi->bitrate_av_damp;
  140496. }
  140497. return(0);
  140498. }
  140499. static int vorbis_encode_setup_setting(vorbis_info *vi,
  140500. long channels,
  140501. long rate){
  140502. int ret=0,i,is;
  140503. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  140504. highlevel_encode_setup *hi=&ci->hi;
  140505. ve_setup_data_template *setup=(ve_setup_data_template*) hi->setup;
  140506. double ds;
  140507. ret=vorbis_encode_toplevel_setup(vi,channels,rate);
  140508. if(ret)return(ret);
  140509. is=hi->base_setting;
  140510. ds=hi->base_setting-is;
  140511. hi->short_setting=hi->base_setting;
  140512. hi->long_setting=hi->base_setting;
  140513. hi->managed=0;
  140514. hi->impulse_block_p=1;
  140515. hi->noise_normalize_p=1;
  140516. hi->stereo_point_setting=hi->base_setting;
  140517. hi->lowpass_kHz=
  140518. setup->psy_lowpass[is]*(1.-ds)+setup->psy_lowpass[is+1]*ds;
  140519. hi->ath_floating_dB=setup->psy_ath_float[is]*(1.-ds)+
  140520. setup->psy_ath_float[is+1]*ds;
  140521. hi->ath_absolute_dB=setup->psy_ath_abs[is]*(1.-ds)+
  140522. setup->psy_ath_abs[is+1]*ds;
  140523. hi->amplitude_track_dBpersec=-6.;
  140524. hi->trigger_setting=hi->base_setting;
  140525. for(i=0;i<4;i++){
  140526. hi->block[i].tone_mask_setting=hi->base_setting;
  140527. hi->block[i].tone_peaklimit_setting=hi->base_setting;
  140528. hi->block[i].noise_bias_setting=hi->base_setting;
  140529. hi->block[i].noise_compand_setting=hi->base_setting;
  140530. }
  140531. return(ret);
  140532. }
  140533. int vorbis_encode_setup_vbr(vorbis_info *vi,
  140534. long channels,
  140535. long rate,
  140536. float quality){
  140537. codec_setup_info *ci=(codec_setup_info*) vi->codec_setup;
  140538. highlevel_encode_setup *hi=&ci->hi;
  140539. quality+=.0000001;
  140540. if(quality>=1.)quality=.9999;
  140541. get_setup_template(vi,channels,rate,quality,0);
  140542. if(!hi->setup)return OV_EIMPL;
  140543. return vorbis_encode_setup_setting(vi,channels,rate);
  140544. }
  140545. int vorbis_encode_init_vbr(vorbis_info *vi,
  140546. long channels,
  140547. long rate,
  140548. float base_quality /* 0. to 1. */
  140549. ){
  140550. int ret=0;
  140551. ret=vorbis_encode_setup_vbr(vi,channels,rate,base_quality);
  140552. if(ret){
  140553. vorbis_info_clear(vi);
  140554. return ret;
  140555. }
  140556. ret=vorbis_encode_setup_init(vi);
  140557. if(ret)
  140558. vorbis_info_clear(vi);
  140559. return(ret);
  140560. }
  140561. int vorbis_encode_setup_managed(vorbis_info *vi,
  140562. long channels,
  140563. long rate,
  140564. long max_bitrate,
  140565. long nominal_bitrate,
  140566. long min_bitrate){
  140567. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  140568. highlevel_encode_setup *hi=&ci->hi;
  140569. double tnominal=nominal_bitrate;
  140570. int ret=0;
  140571. if(nominal_bitrate<=0.){
  140572. if(max_bitrate>0.){
  140573. if(min_bitrate>0.)
  140574. nominal_bitrate=(max_bitrate+min_bitrate)*.5;
  140575. else
  140576. nominal_bitrate=max_bitrate*.875;
  140577. }else{
  140578. if(min_bitrate>0.){
  140579. nominal_bitrate=min_bitrate;
  140580. }else{
  140581. return(OV_EINVAL);
  140582. }
  140583. }
  140584. }
  140585. get_setup_template(vi,channels,rate,nominal_bitrate,1);
  140586. if(!hi->setup)return OV_EIMPL;
  140587. ret=vorbis_encode_setup_setting(vi,channels,rate);
  140588. if(ret){
  140589. vorbis_info_clear(vi);
  140590. return ret;
  140591. }
  140592. hi->managed=1;
  140593. hi->bitrate_min=min_bitrate;
  140594. hi->bitrate_max=max_bitrate;
  140595. hi->bitrate_av=tnominal;
  140596. hi->bitrate_av_damp=1.5f; /* full range in no less than 1.5 second */
  140597. hi->bitrate_reservoir=nominal_bitrate*2;
  140598. hi->bitrate_reservoir_bias=.1; /* bias toward hoarding bits */
  140599. return(ret);
  140600. }
  140601. int vorbis_encode_init(vorbis_info *vi,
  140602. long channels,
  140603. long rate,
  140604. long max_bitrate,
  140605. long nominal_bitrate,
  140606. long min_bitrate){
  140607. int ret=vorbis_encode_setup_managed(vi,channels,rate,
  140608. max_bitrate,
  140609. nominal_bitrate,
  140610. min_bitrate);
  140611. if(ret){
  140612. vorbis_info_clear(vi);
  140613. return(ret);
  140614. }
  140615. ret=vorbis_encode_setup_init(vi);
  140616. if(ret)
  140617. vorbis_info_clear(vi);
  140618. return(ret);
  140619. }
  140620. int vorbis_encode_ctl(vorbis_info *vi,int number,void *arg){
  140621. if(vi){
  140622. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  140623. highlevel_encode_setup *hi=&ci->hi;
  140624. int setp=(number&0xf); /* a read request has a low nibble of 0 */
  140625. if(setp && hi->set_in_stone)return(OV_EINVAL);
  140626. switch(number){
  140627. case OV_ECTL_RATEMANAGE_GET:
  140628. {
  140629. struct ovectl_ratemanage_arg *ai=
  140630. (struct ovectl_ratemanage_arg *)arg;
  140631. ai->management_active=hi->managed;
  140632. ai->bitrate_hard_window=ai->bitrate_av_window=
  140633. (double)hi->bitrate_reservoir/vi->rate;
  140634. ai->bitrate_av_window_center=1.;
  140635. ai->bitrate_hard_min=hi->bitrate_min;
  140636. ai->bitrate_hard_max=hi->bitrate_max;
  140637. ai->bitrate_av_lo=hi->bitrate_av;
  140638. ai->bitrate_av_hi=hi->bitrate_av;
  140639. }
  140640. return(0);
  140641. case OV_ECTL_RATEMANAGE_SET:
  140642. {
  140643. struct ovectl_ratemanage_arg *ai=
  140644. (struct ovectl_ratemanage_arg *)arg;
  140645. if(ai==NULL){
  140646. hi->managed=0;
  140647. }else{
  140648. hi->managed=ai->management_active;
  140649. vorbis_encode_ctl(vi,OV_ECTL_RATEMANAGE_AVG,arg);
  140650. vorbis_encode_ctl(vi,OV_ECTL_RATEMANAGE_HARD,arg);
  140651. }
  140652. }
  140653. return 0;
  140654. case OV_ECTL_RATEMANAGE_AVG:
  140655. {
  140656. struct ovectl_ratemanage_arg *ai=
  140657. (struct ovectl_ratemanage_arg *)arg;
  140658. if(ai==NULL){
  140659. hi->bitrate_av=0;
  140660. }else{
  140661. hi->bitrate_av=(ai->bitrate_av_lo+ai->bitrate_av_hi)*.5;
  140662. }
  140663. }
  140664. return(0);
  140665. case OV_ECTL_RATEMANAGE_HARD:
  140666. {
  140667. struct ovectl_ratemanage_arg *ai=
  140668. (struct ovectl_ratemanage_arg *)arg;
  140669. if(ai==NULL){
  140670. hi->bitrate_min=0;
  140671. hi->bitrate_max=0;
  140672. }else{
  140673. hi->bitrate_min=ai->bitrate_hard_min;
  140674. hi->bitrate_max=ai->bitrate_hard_max;
  140675. hi->bitrate_reservoir=ai->bitrate_hard_window*
  140676. (hi->bitrate_max+hi->bitrate_min)*.5;
  140677. }
  140678. if(hi->bitrate_reservoir<128.)
  140679. hi->bitrate_reservoir=128.;
  140680. }
  140681. return(0);
  140682. case OV_ECTL_RATEMANAGE2_GET:
  140683. {
  140684. struct ovectl_ratemanage2_arg *ai=
  140685. (struct ovectl_ratemanage2_arg *)arg;
  140686. if(ai==NULL)return OV_EINVAL;
  140687. ai->management_active=hi->managed;
  140688. ai->bitrate_limit_min_kbps=hi->bitrate_min/1000;
  140689. ai->bitrate_limit_max_kbps=hi->bitrate_max/1000;
  140690. ai->bitrate_average_kbps=hi->bitrate_av/1000;
  140691. ai->bitrate_average_damping=hi->bitrate_av_damp;
  140692. ai->bitrate_limit_reservoir_bits=hi->bitrate_reservoir;
  140693. ai->bitrate_limit_reservoir_bias=hi->bitrate_reservoir_bias;
  140694. }
  140695. return (0);
  140696. case OV_ECTL_RATEMANAGE2_SET:
  140697. {
  140698. struct ovectl_ratemanage2_arg *ai=
  140699. (struct ovectl_ratemanage2_arg *)arg;
  140700. if(ai==NULL){
  140701. hi->managed=0;
  140702. }else{
  140703. if(ai->bitrate_limit_min_kbps>0 &&
  140704. ai->bitrate_average_kbps>0 &&
  140705. ai->bitrate_limit_min_kbps>ai->bitrate_average_kbps)
  140706. return OV_EINVAL;
  140707. if(ai->bitrate_limit_max_kbps>0 &&
  140708. ai->bitrate_average_kbps>0 &&
  140709. ai->bitrate_limit_max_kbps<ai->bitrate_average_kbps)
  140710. return OV_EINVAL;
  140711. if(ai->bitrate_limit_min_kbps>0 &&
  140712. ai->bitrate_limit_max_kbps>0 &&
  140713. ai->bitrate_limit_min_kbps>ai->bitrate_limit_max_kbps)
  140714. return OV_EINVAL;
  140715. if(ai->bitrate_average_damping <= 0.)
  140716. return OV_EINVAL;
  140717. if(ai->bitrate_limit_reservoir_bits < 0)
  140718. return OV_EINVAL;
  140719. if(ai->bitrate_limit_reservoir_bias < 0.)
  140720. return OV_EINVAL;
  140721. if(ai->bitrate_limit_reservoir_bias > 1.)
  140722. return OV_EINVAL;
  140723. hi->managed=ai->management_active;
  140724. hi->bitrate_min=ai->bitrate_limit_min_kbps * 1000;
  140725. hi->bitrate_max=ai->bitrate_limit_max_kbps * 1000;
  140726. hi->bitrate_av=ai->bitrate_average_kbps * 1000;
  140727. hi->bitrate_av_damp=ai->bitrate_average_damping;
  140728. hi->bitrate_reservoir=ai->bitrate_limit_reservoir_bits;
  140729. hi->bitrate_reservoir_bias=ai->bitrate_limit_reservoir_bias;
  140730. }
  140731. }
  140732. return 0;
  140733. case OV_ECTL_LOWPASS_GET:
  140734. {
  140735. double *farg=(double *)arg;
  140736. *farg=hi->lowpass_kHz;
  140737. }
  140738. return(0);
  140739. case OV_ECTL_LOWPASS_SET:
  140740. {
  140741. double *farg=(double *)arg;
  140742. hi->lowpass_kHz=*farg;
  140743. if(hi->lowpass_kHz<2.)hi->lowpass_kHz=2.;
  140744. if(hi->lowpass_kHz>99.)hi->lowpass_kHz=99.;
  140745. }
  140746. return(0);
  140747. case OV_ECTL_IBLOCK_GET:
  140748. {
  140749. double *farg=(double *)arg;
  140750. *farg=hi->impulse_noisetune;
  140751. }
  140752. return(0);
  140753. case OV_ECTL_IBLOCK_SET:
  140754. {
  140755. double *farg=(double *)arg;
  140756. hi->impulse_noisetune=*farg;
  140757. if(hi->impulse_noisetune>0.)hi->impulse_noisetune=0.;
  140758. if(hi->impulse_noisetune<-15.)hi->impulse_noisetune=-15.;
  140759. }
  140760. return(0);
  140761. }
  140762. return(OV_EIMPL);
  140763. }
  140764. return(OV_EINVAL);
  140765. }
  140766. #endif
  140767. /*** End of inlined file: vorbisenc.c ***/
  140768. /*** Start of inlined file: vorbisfile.c ***/
  140769. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  140770. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  140771. // tasks..
  140772. #if JUCE_MSVC
  140773. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  140774. #endif
  140775. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  140776. #if JUCE_USE_OGGVORBIS
  140777. #include <stdlib.h>
  140778. #include <stdio.h>
  140779. #include <errno.h>
  140780. #include <string.h>
  140781. #include <math.h>
  140782. #define CHUNKSIZE 8500 /* a shade over 8k; anyone using pages well
  140783. over 8k gets what they deserve */
  140784. static long _get_data(OggVorbis_File *vf){
  140785. errno=0;
  140786. if(vf->datasource){
  140787. char *buffer=ogg_sync_buffer(&vf->oy,CHUNKSIZE);
  140788. long bytes=(vf->callbacks.read_func)(buffer,1,CHUNKSIZE,vf->datasource);
  140789. if(bytes>0)ogg_sync_wrote(&vf->oy,bytes);
  140790. if(bytes==0 && errno)return(-1);
  140791. return(bytes);
  140792. }else
  140793. return(0);
  140794. }
  140795. static void _seek_helper(OggVorbis_File *vf,ogg_int64_t offset){
  140796. if(vf->datasource){
  140797. (vf->callbacks.seek_func)(vf->datasource, offset, SEEK_SET);
  140798. vf->offset=offset;
  140799. ogg_sync_reset(&vf->oy);
  140800. }else{
  140801. return;
  140802. }
  140803. }
  140804. static ogg_int64_t _get_next_page(OggVorbis_File *vf,ogg_page *og,
  140805. ogg_int64_t boundary){
  140806. if(boundary>0)boundary+=vf->offset;
  140807. while(1){
  140808. long more;
  140809. if(boundary>0 && vf->offset>=boundary)return(OV_FALSE);
  140810. more=ogg_sync_pageseek(&vf->oy,og);
  140811. if(more<0){
  140812. vf->offset-=more;
  140813. }else{
  140814. if(more==0){
  140815. if(!boundary)return(OV_FALSE);
  140816. {
  140817. long ret=_get_data(vf);
  140818. if(ret==0)return(OV_EOF);
  140819. if(ret<0)return(OV_EREAD);
  140820. }
  140821. }else{
  140822. ogg_int64_t ret=vf->offset;
  140823. vf->offset+=more;
  140824. return(ret);
  140825. }
  140826. }
  140827. }
  140828. }
  140829. static ogg_int64_t _get_prev_page(OggVorbis_File *vf,ogg_page *og){
  140830. ogg_int64_t begin=vf->offset;
  140831. ogg_int64_t end=begin;
  140832. ogg_int64_t ret;
  140833. ogg_int64_t offset=-1;
  140834. while(offset==-1){
  140835. begin-=CHUNKSIZE;
  140836. if(begin<0)
  140837. begin=0;
  140838. _seek_helper(vf,begin);
  140839. while(vf->offset<end){
  140840. ret=_get_next_page(vf,og,end-vf->offset);
  140841. if(ret==OV_EREAD)return(OV_EREAD);
  140842. if(ret<0){
  140843. break;
  140844. }else{
  140845. offset=ret;
  140846. }
  140847. }
  140848. }
  140849. _seek_helper(vf,offset);
  140850. ret=_get_next_page(vf,og,CHUNKSIZE);
  140851. if(ret<0)
  140852. return(OV_EFAULT);
  140853. return(offset);
  140854. }
  140855. static int _bisect_forward_serialno(OggVorbis_File *vf,
  140856. ogg_int64_t begin,
  140857. ogg_int64_t searched,
  140858. ogg_int64_t end,
  140859. long currentno,
  140860. long m){
  140861. ogg_int64_t endsearched=end;
  140862. ogg_int64_t next=end;
  140863. ogg_page og;
  140864. ogg_int64_t ret;
  140865. while(searched<endsearched){
  140866. ogg_int64_t bisect;
  140867. if(endsearched-searched<CHUNKSIZE){
  140868. bisect=searched;
  140869. }else{
  140870. bisect=(searched+endsearched)/2;
  140871. }
  140872. _seek_helper(vf,bisect);
  140873. ret=_get_next_page(vf,&og,-1);
  140874. if(ret==OV_EREAD)return(OV_EREAD);
  140875. if(ret<0 || ogg_page_serialno(&og)!=currentno){
  140876. endsearched=bisect;
  140877. if(ret>=0)next=ret;
  140878. }else{
  140879. searched=ret+og.header_len+og.body_len;
  140880. }
  140881. }
  140882. _seek_helper(vf,next);
  140883. ret=_get_next_page(vf,&og,-1);
  140884. if(ret==OV_EREAD)return(OV_EREAD);
  140885. if(searched>=end || ret<0){
  140886. vf->links=m+1;
  140887. vf->offsets=(ogg_int64_t*)_ogg_malloc((vf->links+1)*sizeof(*vf->offsets));
  140888. vf->serialnos=(long*)_ogg_malloc(vf->links*sizeof(*vf->serialnos));
  140889. vf->offsets[m+1]=searched;
  140890. }else{
  140891. ret=_bisect_forward_serialno(vf,next,vf->offset,
  140892. end,ogg_page_serialno(&og),m+1);
  140893. if(ret==OV_EREAD)return(OV_EREAD);
  140894. }
  140895. vf->offsets[m]=begin;
  140896. vf->serialnos[m]=currentno;
  140897. return(0);
  140898. }
  140899. static int _fetch_headers(OggVorbis_File *vf,vorbis_info *vi,vorbis_comment *vc,
  140900. long *serialno,ogg_page *og_ptr){
  140901. ogg_page og;
  140902. ogg_packet op;
  140903. int i,ret;
  140904. if(!og_ptr){
  140905. ogg_int64_t llret=_get_next_page(vf,&og,CHUNKSIZE);
  140906. if(llret==OV_EREAD)return(OV_EREAD);
  140907. if(llret<0)return OV_ENOTVORBIS;
  140908. og_ptr=&og;
  140909. }
  140910. ogg_stream_reset_serialno(&vf->os,ogg_page_serialno(og_ptr));
  140911. if(serialno)*serialno=vf->os.serialno;
  140912. vf->ready_state=STREAMSET;
  140913. vorbis_info_init(vi);
  140914. vorbis_comment_init(vc);
  140915. i=0;
  140916. while(i<3){
  140917. ogg_stream_pagein(&vf->os,og_ptr);
  140918. while(i<3){
  140919. int result=ogg_stream_packetout(&vf->os,&op);
  140920. if(result==0)break;
  140921. if(result==-1){
  140922. ret=OV_EBADHEADER;
  140923. goto bail_header;
  140924. }
  140925. if((ret=vorbis_synthesis_headerin(vi,vc,&op))){
  140926. goto bail_header;
  140927. }
  140928. i++;
  140929. }
  140930. if(i<3)
  140931. if(_get_next_page(vf,og_ptr,CHUNKSIZE)<0){
  140932. ret=OV_EBADHEADER;
  140933. goto bail_header;
  140934. }
  140935. }
  140936. return 0;
  140937. bail_header:
  140938. vorbis_info_clear(vi);
  140939. vorbis_comment_clear(vc);
  140940. vf->ready_state=OPENED;
  140941. return ret;
  140942. }
  140943. static void _prefetch_all_headers(OggVorbis_File *vf, ogg_int64_t dataoffset){
  140944. ogg_page og;
  140945. int i;
  140946. ogg_int64_t ret;
  140947. vf->vi=(vorbis_info*) _ogg_realloc(vf->vi,vf->links*sizeof(*vf->vi));
  140948. vf->vc=(vorbis_comment*) _ogg_realloc(vf->vc,vf->links*sizeof(*vf->vc));
  140949. vf->dataoffsets=(ogg_int64_t*) _ogg_malloc(vf->links*sizeof(*vf->dataoffsets));
  140950. vf->pcmlengths=(ogg_int64_t*) _ogg_malloc(vf->links*2*sizeof(*vf->pcmlengths));
  140951. for(i=0;i<vf->links;i++){
  140952. if(i==0){
  140953. vf->dataoffsets[i]=dataoffset;
  140954. _seek_helper(vf,dataoffset);
  140955. }else{
  140956. _seek_helper(vf,vf->offsets[i]);
  140957. if(_fetch_headers(vf,vf->vi+i,vf->vc+i,NULL,NULL)<0){
  140958. vf->dataoffsets[i]=-1;
  140959. }else{
  140960. vf->dataoffsets[i]=vf->offset;
  140961. }
  140962. }
  140963. if(vf->dataoffsets[i]!=-1){
  140964. ogg_int64_t accumulated=0;
  140965. long lastblock=-1;
  140966. int result;
  140967. ogg_stream_reset_serialno(&vf->os,vf->serialnos[i]);
  140968. while(1){
  140969. ogg_packet op;
  140970. ret=_get_next_page(vf,&og,-1);
  140971. if(ret<0)
  140972. break;
  140973. if(ogg_page_serialno(&og)!=vf->serialnos[i])
  140974. break;
  140975. ogg_stream_pagein(&vf->os,&og);
  140976. while((result=ogg_stream_packetout(&vf->os,&op))){
  140977. if(result>0){ /* ignore holes */
  140978. long thisblock=vorbis_packet_blocksize(vf->vi+i,&op);
  140979. if(lastblock!=-1)
  140980. accumulated+=(lastblock+thisblock)>>2;
  140981. lastblock=thisblock;
  140982. }
  140983. }
  140984. if(ogg_page_granulepos(&og)!=-1){
  140985. accumulated= ogg_page_granulepos(&og)-accumulated;
  140986. break;
  140987. }
  140988. }
  140989. if(accumulated<0)accumulated=0;
  140990. vf->pcmlengths[i*2]=accumulated;
  140991. }
  140992. {
  140993. ogg_int64_t end=vf->offsets[i+1];
  140994. _seek_helper(vf,end);
  140995. while(1){
  140996. ret=_get_prev_page(vf,&og);
  140997. if(ret<0){
  140998. vorbis_info_clear(vf->vi+i);
  140999. vorbis_comment_clear(vf->vc+i);
  141000. break;
  141001. }
  141002. if(ogg_page_granulepos(&og)!=-1){
  141003. vf->pcmlengths[i*2+1]=ogg_page_granulepos(&og)-vf->pcmlengths[i*2];
  141004. break;
  141005. }
  141006. vf->offset=ret;
  141007. }
  141008. }
  141009. }
  141010. }
  141011. static int _make_decode_ready(OggVorbis_File *vf){
  141012. if(vf->ready_state>STREAMSET)return 0;
  141013. if(vf->ready_state<STREAMSET)return OV_EFAULT;
  141014. if(vf->seekable){
  141015. if(vorbis_synthesis_init(&vf->vd,vf->vi+vf->current_link))
  141016. return OV_EBADLINK;
  141017. }else{
  141018. if(vorbis_synthesis_init(&vf->vd,vf->vi))
  141019. return OV_EBADLINK;
  141020. }
  141021. vorbis_block_init(&vf->vd,&vf->vb);
  141022. vf->ready_state=INITSET;
  141023. vf->bittrack=0.f;
  141024. vf->samptrack=0.f;
  141025. return 0;
  141026. }
  141027. static int _open_seekable2(OggVorbis_File *vf){
  141028. long serialno=vf->current_serialno;
  141029. ogg_int64_t dataoffset=vf->offset, end;
  141030. ogg_page og;
  141031. (vf->callbacks.seek_func)(vf->datasource,0,SEEK_END);
  141032. vf->offset=vf->end=(vf->callbacks.tell_func)(vf->datasource);
  141033. end=_get_prev_page(vf,&og);
  141034. if(end<0)return(end);
  141035. if(ogg_page_serialno(&og)!=serialno){
  141036. if(_bisect_forward_serialno(vf,0,0,end+1,serialno,0)<0)return(OV_EREAD);
  141037. }else{
  141038. if(_bisect_forward_serialno(vf,0,end,end+1,serialno,0))return(OV_EREAD);
  141039. }
  141040. _prefetch_all_headers(vf,dataoffset);
  141041. return(ov_raw_seek(vf,0));
  141042. }
  141043. static void _decode_clear(OggVorbis_File *vf){
  141044. vorbis_dsp_clear(&vf->vd);
  141045. vorbis_block_clear(&vf->vb);
  141046. vf->ready_state=OPENED;
  141047. }
  141048. static int _fetch_and_process_packet(OggVorbis_File *vf,
  141049. ogg_packet *op_in,
  141050. int readp,
  141051. int spanp){
  141052. ogg_page og;
  141053. while(1){
  141054. if(vf->ready_state==INITSET){
  141055. while(1) {
  141056. ogg_packet op;
  141057. ogg_packet *op_ptr=(op_in?op_in:&op);
  141058. int result=ogg_stream_packetout(&vf->os,op_ptr);
  141059. ogg_int64_t granulepos;
  141060. op_in=NULL;
  141061. if(result==-1)return(OV_HOLE); /* hole in the data. */
  141062. if(result>0){
  141063. granulepos=op_ptr->granulepos;
  141064. if(!vorbis_synthesis(&vf->vb,op_ptr)){ /* lazy check for lazy
  141065. header handling. The
  141066. header packets aren't
  141067. audio, so if/when we
  141068. submit them,
  141069. vorbis_synthesis will
  141070. reject them */
  141071. {
  141072. int oldsamples=vorbis_synthesis_pcmout(&vf->vd,NULL);
  141073. if(oldsamples)return(OV_EFAULT);
  141074. vorbis_synthesis_blockin(&vf->vd,&vf->vb);
  141075. vf->samptrack+=vorbis_synthesis_pcmout(&vf->vd,NULL)-oldsamples;
  141076. vf->bittrack+=op_ptr->bytes*8;
  141077. }
  141078. if(granulepos!=-1 && !op_ptr->e_o_s){
  141079. int link=(vf->seekable?vf->current_link:0);
  141080. int i,samples;
  141081. if(vf->seekable && link>0)
  141082. granulepos-=vf->pcmlengths[link*2];
  141083. if(granulepos<0)granulepos=0; /* actually, this
  141084. shouldn't be possible
  141085. here unless the stream
  141086. is very broken */
  141087. samples=vorbis_synthesis_pcmout(&vf->vd,NULL);
  141088. granulepos-=samples;
  141089. for(i=0;i<link;i++)
  141090. granulepos+=vf->pcmlengths[i*2+1];
  141091. vf->pcm_offset=granulepos;
  141092. }
  141093. return(1);
  141094. }
  141095. }
  141096. else
  141097. break;
  141098. }
  141099. }
  141100. if(vf->ready_state>=OPENED){
  141101. ogg_int64_t ret;
  141102. if(!readp)return(0);
  141103. if((ret=_get_next_page(vf,&og,-1))<0){
  141104. return(OV_EOF); /* eof.
  141105. leave unitialized */
  141106. }
  141107. vf->bittrack+=og.header_len*8;
  141108. if(vf->ready_state==INITSET){
  141109. if(vf->current_serialno!=ogg_page_serialno(&og)){
  141110. if(!spanp)
  141111. return(OV_EOF);
  141112. _decode_clear(vf);
  141113. if(!vf->seekable){
  141114. vorbis_info_clear(vf->vi);
  141115. vorbis_comment_clear(vf->vc);
  141116. }
  141117. }
  141118. }
  141119. }
  141120. if(vf->ready_state!=INITSET){
  141121. int link;
  141122. if(vf->ready_state<STREAMSET){
  141123. if(vf->seekable){
  141124. vf->current_serialno=ogg_page_serialno(&og);
  141125. for(link=0;link<vf->links;link++)
  141126. if(vf->serialnos[link]==vf->current_serialno)break;
  141127. if(link==vf->links)return(OV_EBADLINK); /* sign of a bogus
  141128. stream. error out,
  141129. leave machine
  141130. uninitialized */
  141131. vf->current_link=link;
  141132. ogg_stream_reset_serialno(&vf->os,vf->current_serialno);
  141133. vf->ready_state=STREAMSET;
  141134. }else{
  141135. int ret=_fetch_headers(vf,vf->vi,vf->vc,&vf->current_serialno,&og);
  141136. if(ret)return(ret);
  141137. vf->current_link++;
  141138. link=0;
  141139. }
  141140. }
  141141. {
  141142. int ret=_make_decode_ready(vf);
  141143. if(ret<0)return ret;
  141144. }
  141145. }
  141146. ogg_stream_pagein(&vf->os,&og);
  141147. }
  141148. }
  141149. static int _fseek64_wrap(FILE *f,ogg_int64_t off,int whence){
  141150. if(f==NULL)return(-1);
  141151. return fseek(f,off,whence);
  141152. }
  141153. static int _ov_open1(void *f,OggVorbis_File *vf,char *initial,
  141154. long ibytes, ov_callbacks callbacks){
  141155. int offsettest=(f?callbacks.seek_func(f,0,SEEK_CUR):-1);
  141156. int ret;
  141157. memset(vf,0,sizeof(*vf));
  141158. vf->datasource=f;
  141159. vf->callbacks = callbacks;
  141160. ogg_sync_init(&vf->oy);
  141161. if(initial){
  141162. char *buffer=ogg_sync_buffer(&vf->oy,ibytes);
  141163. memcpy(buffer,initial,ibytes);
  141164. ogg_sync_wrote(&vf->oy,ibytes);
  141165. }
  141166. if(offsettest!=-1)vf->seekable=1;
  141167. vf->links=1;
  141168. vf->vi=(vorbis_info*) _ogg_calloc(vf->links,sizeof(*vf->vi));
  141169. vf->vc=(vorbis_comment*) _ogg_calloc(vf->links,sizeof(*vf->vc));
  141170. ogg_stream_init(&vf->os,-1); /* fill in the serialno later */
  141171. if((ret=_fetch_headers(vf,vf->vi,vf->vc,&vf->current_serialno,NULL))<0){
  141172. vf->datasource=NULL;
  141173. ov_clear(vf);
  141174. }else
  141175. vf->ready_state=PARTOPEN;
  141176. return(ret);
  141177. }
  141178. static int _ov_open2(OggVorbis_File *vf){
  141179. if(vf->ready_state != PARTOPEN) return OV_EINVAL;
  141180. vf->ready_state=OPENED;
  141181. if(vf->seekable){
  141182. int ret=_open_seekable2(vf);
  141183. if(ret){
  141184. vf->datasource=NULL;
  141185. ov_clear(vf);
  141186. }
  141187. return(ret);
  141188. }else
  141189. vf->ready_state=STREAMSET;
  141190. return 0;
  141191. }
  141192. int ov_clear(OggVorbis_File *vf){
  141193. if(vf){
  141194. vorbis_block_clear(&vf->vb);
  141195. vorbis_dsp_clear(&vf->vd);
  141196. ogg_stream_clear(&vf->os);
  141197. if(vf->vi && vf->links){
  141198. int i;
  141199. for(i=0;i<vf->links;i++){
  141200. vorbis_info_clear(vf->vi+i);
  141201. vorbis_comment_clear(vf->vc+i);
  141202. }
  141203. _ogg_free(vf->vi);
  141204. _ogg_free(vf->vc);
  141205. }
  141206. if(vf->dataoffsets)_ogg_free(vf->dataoffsets);
  141207. if(vf->pcmlengths)_ogg_free(vf->pcmlengths);
  141208. if(vf->serialnos)_ogg_free(vf->serialnos);
  141209. if(vf->offsets)_ogg_free(vf->offsets);
  141210. ogg_sync_clear(&vf->oy);
  141211. if(vf->datasource)(vf->callbacks.close_func)(vf->datasource);
  141212. memset(vf,0,sizeof(*vf));
  141213. }
  141214. #ifdef DEBUG_LEAKS
  141215. _VDBG_dump();
  141216. #endif
  141217. return(0);
  141218. }
  141219. int ov_open_callbacks(void *f,OggVorbis_File *vf,char *initial,long ibytes,
  141220. ov_callbacks callbacks){
  141221. int ret=_ov_open1(f,vf,initial,ibytes,callbacks);
  141222. if(ret)return ret;
  141223. return _ov_open2(vf);
  141224. }
  141225. int ov_open(FILE *f,OggVorbis_File *vf,char *initial,long ibytes){
  141226. ov_callbacks callbacks = {
  141227. (size_t (*)(void *, size_t, size_t, void *)) fread,
  141228. (int (*)(void *, ogg_int64_t, int)) _fseek64_wrap,
  141229. (int (*)(void *)) fclose,
  141230. (long (*)(void *)) ftell
  141231. };
  141232. return ov_open_callbacks((void *)f, vf, initial, ibytes, callbacks);
  141233. }
  141234. int ov_halfrate(OggVorbis_File *vf,int flag){
  141235. int i;
  141236. if(vf->vi==NULL)return OV_EINVAL;
  141237. if(!vf->seekable)return OV_EINVAL;
  141238. if(vf->ready_state>=STREAMSET)
  141239. _decode_clear(vf); /* clear out stream state; later on libvorbis
  141240. will be able to swap this on the fly, but
  141241. for now dumping the decode machine is needed
  141242. to reinit the MDCT lookups. 1.1 libvorbis
  141243. is planned to be able to switch on the fly */
  141244. for(i=0;i<vf->links;i++){
  141245. if(vorbis_synthesis_halfrate(vf->vi+i,flag)){
  141246. ov_halfrate(vf,0);
  141247. return OV_EINVAL;
  141248. }
  141249. }
  141250. return 0;
  141251. }
  141252. int ov_halfrate_p(OggVorbis_File *vf){
  141253. if(vf->vi==NULL)return OV_EINVAL;
  141254. return vorbis_synthesis_halfrate_p(vf->vi);
  141255. }
  141256. int ov_test_callbacks(void *f,OggVorbis_File *vf,char *initial,long ibytes,
  141257. ov_callbacks callbacks)
  141258. {
  141259. return _ov_open1(f,vf,initial,ibytes,callbacks);
  141260. }
  141261. int ov_test(FILE *f,OggVorbis_File *vf,char *initial,long ibytes){
  141262. ov_callbacks callbacks = {
  141263. (size_t (*)(void *, size_t, size_t, void *)) fread,
  141264. (int (*)(void *, ogg_int64_t, int)) _fseek64_wrap,
  141265. (int (*)(void *)) fclose,
  141266. (long (*)(void *)) ftell
  141267. };
  141268. return ov_test_callbacks((void *)f, vf, initial, ibytes, callbacks);
  141269. }
  141270. int ov_test_open(OggVorbis_File *vf){
  141271. if(vf->ready_state!=PARTOPEN)return(OV_EINVAL);
  141272. return _ov_open2(vf);
  141273. }
  141274. long ov_streams(OggVorbis_File *vf){
  141275. return vf->links;
  141276. }
  141277. long ov_seekable(OggVorbis_File *vf){
  141278. return vf->seekable;
  141279. }
  141280. long ov_bitrate(OggVorbis_File *vf,int i){
  141281. if(vf->ready_state<OPENED)return(OV_EINVAL);
  141282. if(i>=vf->links)return(OV_EINVAL);
  141283. if(!vf->seekable && i!=0)return(ov_bitrate(vf,0));
  141284. if(i<0){
  141285. ogg_int64_t bits=0;
  141286. int i;
  141287. float br;
  141288. for(i=0;i<vf->links;i++)
  141289. bits+=(vf->offsets[i+1]-vf->dataoffsets[i])*8;
  141290. br = bits/ov_time_total(vf,-1);
  141291. return(rint(br));
  141292. }else{
  141293. if(vf->seekable){
  141294. return(rint((vf->offsets[i+1]-vf->dataoffsets[i])*8/ov_time_total(vf,i)));
  141295. }else{
  141296. if(vf->vi[i].bitrate_nominal>0){
  141297. return vf->vi[i].bitrate_nominal;
  141298. }else{
  141299. if(vf->vi[i].bitrate_upper>0){
  141300. if(vf->vi[i].bitrate_lower>0){
  141301. return (vf->vi[i].bitrate_upper+vf->vi[i].bitrate_lower)/2;
  141302. }else{
  141303. return vf->vi[i].bitrate_upper;
  141304. }
  141305. }
  141306. return(OV_FALSE);
  141307. }
  141308. }
  141309. }
  141310. }
  141311. long ov_bitrate_instant(OggVorbis_File *vf){
  141312. int link=(vf->seekable?vf->current_link:0);
  141313. long ret;
  141314. if(vf->ready_state<OPENED)return(OV_EINVAL);
  141315. if(vf->samptrack==0)return(OV_FALSE);
  141316. ret=vf->bittrack/vf->samptrack*vf->vi[link].rate+.5;
  141317. vf->bittrack=0.f;
  141318. vf->samptrack=0.f;
  141319. return(ret);
  141320. }
  141321. long ov_serialnumber(OggVorbis_File *vf,int i){
  141322. if(i>=vf->links)return(ov_serialnumber(vf,vf->links-1));
  141323. if(!vf->seekable && i>=0)return(ov_serialnumber(vf,-1));
  141324. if(i<0){
  141325. return(vf->current_serialno);
  141326. }else{
  141327. return(vf->serialnos[i]);
  141328. }
  141329. }
  141330. ogg_int64_t ov_raw_total(OggVorbis_File *vf,int i){
  141331. if(vf->ready_state<OPENED)return(OV_EINVAL);
  141332. if(!vf->seekable || i>=vf->links)return(OV_EINVAL);
  141333. if(i<0){
  141334. ogg_int64_t acc=0;
  141335. int i;
  141336. for(i=0;i<vf->links;i++)
  141337. acc+=ov_raw_total(vf,i);
  141338. return(acc);
  141339. }else{
  141340. return(vf->offsets[i+1]-vf->offsets[i]);
  141341. }
  141342. }
  141343. ogg_int64_t ov_pcm_total(OggVorbis_File *vf,int i){
  141344. if(vf->ready_state<OPENED)return(OV_EINVAL);
  141345. if(!vf->seekable || i>=vf->links)return(OV_EINVAL);
  141346. if(i<0){
  141347. ogg_int64_t acc=0;
  141348. int i;
  141349. for(i=0;i<vf->links;i++)
  141350. acc+=ov_pcm_total(vf,i);
  141351. return(acc);
  141352. }else{
  141353. return(vf->pcmlengths[i*2+1]);
  141354. }
  141355. }
  141356. double ov_time_total(OggVorbis_File *vf,int i){
  141357. if(vf->ready_state<OPENED)return(OV_EINVAL);
  141358. if(!vf->seekable || i>=vf->links)return(OV_EINVAL);
  141359. if(i<0){
  141360. double acc=0;
  141361. int i;
  141362. for(i=0;i<vf->links;i++)
  141363. acc+=ov_time_total(vf,i);
  141364. return(acc);
  141365. }else{
  141366. return((double)(vf->pcmlengths[i*2+1])/vf->vi[i].rate);
  141367. }
  141368. }
  141369. int ov_raw_seek(OggVorbis_File *vf,ogg_int64_t pos){
  141370. ogg_stream_state work_os;
  141371. if(vf->ready_state<OPENED)return(OV_EINVAL);
  141372. if(!vf->seekable)
  141373. return(OV_ENOSEEK); /* don't dump machine if we can't seek */
  141374. if(pos<0 || pos>vf->end)return(OV_EINVAL);
  141375. vf->pcm_offset=-1;
  141376. ogg_stream_reset_serialno(&vf->os,
  141377. vf->current_serialno); /* must set serialno */
  141378. vorbis_synthesis_restart(&vf->vd);
  141379. _seek_helper(vf,pos);
  141380. {
  141381. ogg_page og;
  141382. ogg_packet op;
  141383. int lastblock=0;
  141384. int accblock=0;
  141385. int thisblock;
  141386. int eosflag;
  141387. ogg_stream_init(&work_os,vf->current_serialno); /* get the memory ready */
  141388. ogg_stream_reset(&work_os); /* eliminate the spurious OV_HOLE
  141389. return from not necessarily
  141390. starting from the beginning */
  141391. while(1){
  141392. if(vf->ready_state>=STREAMSET){
  141393. int result=ogg_stream_packetout(&work_os,&op);
  141394. if(result>0){
  141395. if(vf->vi[vf->current_link].codec_setup){
  141396. thisblock=vorbis_packet_blocksize(vf->vi+vf->current_link,&op);
  141397. if(thisblock<0){
  141398. ogg_stream_packetout(&vf->os,NULL);
  141399. thisblock=0;
  141400. }else{
  141401. if(eosflag)
  141402. ogg_stream_packetout(&vf->os,NULL);
  141403. else
  141404. if(lastblock)accblock+=(lastblock+thisblock)>>2;
  141405. }
  141406. if(op.granulepos!=-1){
  141407. int i,link=vf->current_link;
  141408. ogg_int64_t granulepos=op.granulepos-vf->pcmlengths[link*2];
  141409. if(granulepos<0)granulepos=0;
  141410. for(i=0;i<link;i++)
  141411. granulepos+=vf->pcmlengths[i*2+1];
  141412. vf->pcm_offset=granulepos-accblock;
  141413. break;
  141414. }
  141415. lastblock=thisblock;
  141416. continue;
  141417. }else
  141418. ogg_stream_packetout(&vf->os,NULL);
  141419. }
  141420. }
  141421. if(!lastblock){
  141422. if(_get_next_page(vf,&og,-1)<0){
  141423. vf->pcm_offset=ov_pcm_total(vf,-1);
  141424. break;
  141425. }
  141426. }else{
  141427. vf->pcm_offset=-1;
  141428. break;
  141429. }
  141430. if(vf->ready_state>=STREAMSET)
  141431. if(vf->current_serialno!=ogg_page_serialno(&og)){
  141432. _decode_clear(vf); /* clear out stream state */
  141433. ogg_stream_clear(&work_os);
  141434. }
  141435. if(vf->ready_state<STREAMSET){
  141436. int link;
  141437. vf->current_serialno=ogg_page_serialno(&og);
  141438. for(link=0;link<vf->links;link++)
  141439. if(vf->serialnos[link]==vf->current_serialno)break;
  141440. if(link==vf->links)goto seek_error; /* sign of a bogus stream.
  141441. error out, leave
  141442. machine uninitialized */
  141443. vf->current_link=link;
  141444. ogg_stream_reset_serialno(&vf->os,vf->current_serialno);
  141445. ogg_stream_reset_serialno(&work_os,vf->current_serialno);
  141446. vf->ready_state=STREAMSET;
  141447. }
  141448. ogg_stream_pagein(&vf->os,&og);
  141449. ogg_stream_pagein(&work_os,&og);
  141450. eosflag=ogg_page_eos(&og);
  141451. }
  141452. }
  141453. ogg_stream_clear(&work_os);
  141454. vf->bittrack=0.f;
  141455. vf->samptrack=0.f;
  141456. return(0);
  141457. seek_error:
  141458. vf->pcm_offset=-1;
  141459. ogg_stream_clear(&work_os);
  141460. _decode_clear(vf);
  141461. return OV_EBADLINK;
  141462. }
  141463. int ov_pcm_seek_page(OggVorbis_File *vf,ogg_int64_t pos){
  141464. int link=-1;
  141465. ogg_int64_t result=0;
  141466. ogg_int64_t total=ov_pcm_total(vf,-1);
  141467. if(vf->ready_state<OPENED)return(OV_EINVAL);
  141468. if(!vf->seekable)return(OV_ENOSEEK);
  141469. if(pos<0 || pos>total)return(OV_EINVAL);
  141470. for(link=vf->links-1;link>=0;link--){
  141471. total-=vf->pcmlengths[link*2+1];
  141472. if(pos>=total)break;
  141473. }
  141474. {
  141475. ogg_int64_t end=vf->offsets[link+1];
  141476. ogg_int64_t begin=vf->offsets[link];
  141477. ogg_int64_t begintime = vf->pcmlengths[link*2];
  141478. ogg_int64_t endtime = vf->pcmlengths[link*2+1]+begintime;
  141479. ogg_int64_t target=pos-total+begintime;
  141480. ogg_int64_t best=begin;
  141481. ogg_page og;
  141482. while(begin<end){
  141483. ogg_int64_t bisect;
  141484. if(end-begin<CHUNKSIZE){
  141485. bisect=begin;
  141486. }else{
  141487. bisect=begin +
  141488. (target-begintime)*(end-begin)/(endtime-begintime) - CHUNKSIZE;
  141489. if(bisect<=begin)
  141490. bisect=begin+1;
  141491. }
  141492. _seek_helper(vf,bisect);
  141493. while(begin<end){
  141494. result=_get_next_page(vf,&og,end-vf->offset);
  141495. if(result==OV_EREAD) goto seek_error;
  141496. if(result<0){
  141497. if(bisect<=begin+1)
  141498. end=begin; /* found it */
  141499. else{
  141500. if(bisect==0) goto seek_error;
  141501. bisect-=CHUNKSIZE;
  141502. if(bisect<=begin)bisect=begin+1;
  141503. _seek_helper(vf,bisect);
  141504. }
  141505. }else{
  141506. ogg_int64_t granulepos=ogg_page_granulepos(&og);
  141507. if(granulepos==-1)continue;
  141508. if(granulepos<target){
  141509. best=result; /* raw offset of packet with granulepos */
  141510. begin=vf->offset; /* raw offset of next page */
  141511. begintime=granulepos;
  141512. if(target-begintime>44100)break;
  141513. bisect=begin; /* *not* begin + 1 */
  141514. }else{
  141515. if(bisect<=begin+1)
  141516. end=begin; /* found it */
  141517. else{
  141518. if(end==vf->offset){ /* we're pretty close - we'd be stuck in */
  141519. end=result;
  141520. bisect-=CHUNKSIZE; /* an endless loop otherwise. */
  141521. if(bisect<=begin)bisect=begin+1;
  141522. _seek_helper(vf,bisect);
  141523. }else{
  141524. end=result;
  141525. endtime=granulepos;
  141526. break;
  141527. }
  141528. }
  141529. }
  141530. }
  141531. }
  141532. }
  141533. {
  141534. ogg_page og;
  141535. ogg_packet op;
  141536. _seek_helper(vf,best);
  141537. vf->pcm_offset=-1;
  141538. if(_get_next_page(vf,&og,-1)<0)return(OV_EOF); /* shouldn't happen */
  141539. if(link!=vf->current_link){
  141540. _decode_clear(vf);
  141541. vf->current_link=link;
  141542. vf->current_serialno=ogg_page_serialno(&og);
  141543. vf->ready_state=STREAMSET;
  141544. }else{
  141545. vorbis_synthesis_restart(&vf->vd);
  141546. }
  141547. ogg_stream_reset_serialno(&vf->os,vf->current_serialno);
  141548. ogg_stream_pagein(&vf->os,&og);
  141549. while(1){
  141550. result=ogg_stream_packetpeek(&vf->os,&op);
  141551. if(result==0){
  141552. _seek_helper(vf,best);
  141553. while(1){
  141554. result=_get_prev_page(vf,&og);
  141555. if(result<0) goto seek_error;
  141556. if(ogg_page_granulepos(&og)>-1 ||
  141557. !ogg_page_continued(&og)){
  141558. return ov_raw_seek(vf,result);
  141559. }
  141560. vf->offset=result;
  141561. }
  141562. }
  141563. if(result<0){
  141564. result = OV_EBADPACKET;
  141565. goto seek_error;
  141566. }
  141567. if(op.granulepos!=-1){
  141568. vf->pcm_offset=op.granulepos-vf->pcmlengths[vf->current_link*2];
  141569. if(vf->pcm_offset<0)vf->pcm_offset=0;
  141570. vf->pcm_offset+=total;
  141571. break;
  141572. }else
  141573. result=ogg_stream_packetout(&vf->os,NULL);
  141574. }
  141575. }
  141576. }
  141577. if(vf->pcm_offset>pos || pos>ov_pcm_total(vf,-1)){
  141578. result=OV_EFAULT;
  141579. goto seek_error;
  141580. }
  141581. vf->bittrack=0.f;
  141582. vf->samptrack=0.f;
  141583. return(0);
  141584. seek_error:
  141585. vf->pcm_offset=-1;
  141586. _decode_clear(vf);
  141587. return (int)result;
  141588. }
  141589. int ov_pcm_seek(OggVorbis_File *vf,ogg_int64_t pos){
  141590. int thisblock,lastblock=0;
  141591. int ret=ov_pcm_seek_page(vf,pos);
  141592. if(ret<0)return(ret);
  141593. if((ret=_make_decode_ready(vf)))return ret;
  141594. while(1){
  141595. ogg_packet op;
  141596. ogg_page og;
  141597. int ret=ogg_stream_packetpeek(&vf->os,&op);
  141598. if(ret>0){
  141599. thisblock=vorbis_packet_blocksize(vf->vi+vf->current_link,&op);
  141600. if(thisblock<0){
  141601. ogg_stream_packetout(&vf->os,NULL);
  141602. continue; /* non audio packet */
  141603. }
  141604. if(lastblock)vf->pcm_offset+=(lastblock+thisblock)>>2;
  141605. if(vf->pcm_offset+((thisblock+
  141606. vorbis_info_blocksize(vf->vi,1))>>2)>=pos)break;
  141607. ogg_stream_packetout(&vf->os,NULL);
  141608. vorbis_synthesis_trackonly(&vf->vb,&op); /* set up a vb with
  141609. only tracking, no
  141610. pcm_decode */
  141611. vorbis_synthesis_blockin(&vf->vd,&vf->vb);
  141612. if(op.granulepos>-1){
  141613. int i;
  141614. vf->pcm_offset=op.granulepos-vf->pcmlengths[vf->current_link*2];
  141615. if(vf->pcm_offset<0)vf->pcm_offset=0;
  141616. for(i=0;i<vf->current_link;i++)
  141617. vf->pcm_offset+=vf->pcmlengths[i*2+1];
  141618. }
  141619. lastblock=thisblock;
  141620. }else{
  141621. if(ret<0 && ret!=OV_HOLE)break;
  141622. if(_get_next_page(vf,&og,-1)<0)break;
  141623. if(vf->current_serialno!=ogg_page_serialno(&og))_decode_clear(vf);
  141624. if(vf->ready_state<STREAMSET){
  141625. int link;
  141626. vf->current_serialno=ogg_page_serialno(&og);
  141627. for(link=0;link<vf->links;link++)
  141628. if(vf->serialnos[link]==vf->current_serialno)break;
  141629. if(link==vf->links)return(OV_EBADLINK);
  141630. vf->current_link=link;
  141631. ogg_stream_reset_serialno(&vf->os,vf->current_serialno);
  141632. vf->ready_state=STREAMSET;
  141633. ret=_make_decode_ready(vf);
  141634. if(ret)return ret;
  141635. lastblock=0;
  141636. }
  141637. ogg_stream_pagein(&vf->os,&og);
  141638. }
  141639. }
  141640. vf->bittrack=0.f;
  141641. vf->samptrack=0.f;
  141642. while(vf->pcm_offset<pos){
  141643. ogg_int64_t target=pos-vf->pcm_offset;
  141644. long samples=vorbis_synthesis_pcmout(&vf->vd,NULL);
  141645. if(samples>target)samples=target;
  141646. vorbis_synthesis_read(&vf->vd,samples);
  141647. vf->pcm_offset+=samples;
  141648. if(samples<target)
  141649. if(_fetch_and_process_packet(vf,NULL,1,1)<=0)
  141650. vf->pcm_offset=ov_pcm_total(vf,-1); /* eof */
  141651. }
  141652. return 0;
  141653. }
  141654. int ov_time_seek(OggVorbis_File *vf,double seconds){
  141655. int link=-1;
  141656. ogg_int64_t pcm_total=ov_pcm_total(vf,-1);
  141657. double time_total=ov_time_total(vf,-1);
  141658. if(vf->ready_state<OPENED)return(OV_EINVAL);
  141659. if(!vf->seekable)return(OV_ENOSEEK);
  141660. if(seconds<0 || seconds>time_total)return(OV_EINVAL);
  141661. for(link=vf->links-1;link>=0;link--){
  141662. pcm_total-=vf->pcmlengths[link*2+1];
  141663. time_total-=ov_time_total(vf,link);
  141664. if(seconds>=time_total)break;
  141665. }
  141666. {
  141667. ogg_int64_t target=pcm_total+(seconds-time_total)*vf->vi[link].rate;
  141668. return(ov_pcm_seek(vf,target));
  141669. }
  141670. }
  141671. int ov_time_seek_page(OggVorbis_File *vf,double seconds){
  141672. int link=-1;
  141673. ogg_int64_t pcm_total=ov_pcm_total(vf,-1);
  141674. double time_total=ov_time_total(vf,-1);
  141675. if(vf->ready_state<OPENED)return(OV_EINVAL);
  141676. if(!vf->seekable)return(OV_ENOSEEK);
  141677. if(seconds<0 || seconds>time_total)return(OV_EINVAL);
  141678. for(link=vf->links-1;link>=0;link--){
  141679. pcm_total-=vf->pcmlengths[link*2+1];
  141680. time_total-=ov_time_total(vf,link);
  141681. if(seconds>=time_total)break;
  141682. }
  141683. {
  141684. ogg_int64_t target=pcm_total+(seconds-time_total)*vf->vi[link].rate;
  141685. return(ov_pcm_seek_page(vf,target));
  141686. }
  141687. }
  141688. ogg_int64_t ov_raw_tell(OggVorbis_File *vf){
  141689. if(vf->ready_state<OPENED)return(OV_EINVAL);
  141690. return(vf->offset);
  141691. }
  141692. ogg_int64_t ov_pcm_tell(OggVorbis_File *vf){
  141693. if(vf->ready_state<OPENED)return(OV_EINVAL);
  141694. return(vf->pcm_offset);
  141695. }
  141696. double ov_time_tell(OggVorbis_File *vf){
  141697. int link=0;
  141698. ogg_int64_t pcm_total=0;
  141699. double time_total=0.f;
  141700. if(vf->ready_state<OPENED)return(OV_EINVAL);
  141701. if(vf->seekable){
  141702. pcm_total=ov_pcm_total(vf,-1);
  141703. time_total=ov_time_total(vf,-1);
  141704. for(link=vf->links-1;link>=0;link--){
  141705. pcm_total-=vf->pcmlengths[link*2+1];
  141706. time_total-=ov_time_total(vf,link);
  141707. if(vf->pcm_offset>=pcm_total)break;
  141708. }
  141709. }
  141710. return((double)time_total+(double)(vf->pcm_offset-pcm_total)/vf->vi[link].rate);
  141711. }
  141712. vorbis_info *ov_info(OggVorbis_File *vf,int link){
  141713. if(vf->seekable){
  141714. if(link<0)
  141715. if(vf->ready_state>=STREAMSET)
  141716. return vf->vi+vf->current_link;
  141717. else
  141718. return vf->vi;
  141719. else
  141720. if(link>=vf->links)
  141721. return NULL;
  141722. else
  141723. return vf->vi+link;
  141724. }else{
  141725. return vf->vi;
  141726. }
  141727. }
  141728. vorbis_comment *ov_comment(OggVorbis_File *vf,int link){
  141729. if(vf->seekable){
  141730. if(link<0)
  141731. if(vf->ready_state>=STREAMSET)
  141732. return vf->vc+vf->current_link;
  141733. else
  141734. return vf->vc;
  141735. else
  141736. if(link>=vf->links)
  141737. return NULL;
  141738. else
  141739. return vf->vc+link;
  141740. }else{
  141741. return vf->vc;
  141742. }
  141743. }
  141744. static int host_is_big_endian() {
  141745. ogg_int32_t pattern = 0xfeedface; /* deadbeef */
  141746. unsigned char *bytewise = (unsigned char *)&pattern;
  141747. if (bytewise[0] == 0xfe) return 1;
  141748. return 0;
  141749. }
  141750. long ov_read(OggVorbis_File *vf,char *buffer,int length,
  141751. int bigendianp,int word,int sgned,int *bitstream){
  141752. int i,j;
  141753. int host_endian = host_is_big_endian();
  141754. float **pcm;
  141755. long samples;
  141756. if(vf->ready_state<OPENED)return(OV_EINVAL);
  141757. while(1){
  141758. if(vf->ready_state==INITSET){
  141759. samples=vorbis_synthesis_pcmout(&vf->vd,&pcm);
  141760. if(samples)break;
  141761. }
  141762. {
  141763. int ret=_fetch_and_process_packet(vf,NULL,1,1);
  141764. if(ret==OV_EOF)
  141765. return(0);
  141766. if(ret<=0)
  141767. return(ret);
  141768. }
  141769. }
  141770. if(samples>0){
  141771. long channels=ov_info(vf,-1)->channels;
  141772. long bytespersample=word * channels;
  141773. vorbis_fpu_control fpu;
  141774. (void) fpu; // (to avoid a warning about it being unused)
  141775. if(samples>length/bytespersample)samples=length/bytespersample;
  141776. if(samples <= 0)
  141777. return OV_EINVAL;
  141778. {
  141779. int val;
  141780. if(word==1){
  141781. int off=(sgned?0:128);
  141782. vorbis_fpu_setround(&fpu);
  141783. for(j=0;j<samples;j++)
  141784. for(i=0;i<channels;i++){
  141785. val=vorbis_ftoi(pcm[i][j]*128.f);
  141786. if(val>127)val=127;
  141787. else if(val<-128)val=-128;
  141788. *buffer++=val+off;
  141789. }
  141790. vorbis_fpu_restore(fpu);
  141791. }else{
  141792. int off=(sgned?0:32768);
  141793. if(host_endian==bigendianp){
  141794. if(sgned){
  141795. vorbis_fpu_setround(&fpu);
  141796. for(i=0;i<channels;i++) { /* It's faster in this order */
  141797. float *src=pcm[i];
  141798. short *dest=((short *)buffer)+i;
  141799. for(j=0;j<samples;j++) {
  141800. val=vorbis_ftoi(src[j]*32768.f);
  141801. if(val>32767)val=32767;
  141802. else if(val<-32768)val=-32768;
  141803. *dest=val;
  141804. dest+=channels;
  141805. }
  141806. }
  141807. vorbis_fpu_restore(fpu);
  141808. }else{
  141809. vorbis_fpu_setround(&fpu);
  141810. for(i=0;i<channels;i++) {
  141811. float *src=pcm[i];
  141812. short *dest=((short *)buffer)+i;
  141813. for(j=0;j<samples;j++) {
  141814. val=vorbis_ftoi(src[j]*32768.f);
  141815. if(val>32767)val=32767;
  141816. else if(val<-32768)val=-32768;
  141817. *dest=val+off;
  141818. dest+=channels;
  141819. }
  141820. }
  141821. vorbis_fpu_restore(fpu);
  141822. }
  141823. }else if(bigendianp){
  141824. vorbis_fpu_setround(&fpu);
  141825. for(j=0;j<samples;j++)
  141826. for(i=0;i<channels;i++){
  141827. val=vorbis_ftoi(pcm[i][j]*32768.f);
  141828. if(val>32767)val=32767;
  141829. else if(val<-32768)val=-32768;
  141830. val+=off;
  141831. *buffer++=(val>>8);
  141832. *buffer++=(val&0xff);
  141833. }
  141834. vorbis_fpu_restore(fpu);
  141835. }else{
  141836. int val;
  141837. vorbis_fpu_setround(&fpu);
  141838. for(j=0;j<samples;j++)
  141839. for(i=0;i<channels;i++){
  141840. val=vorbis_ftoi(pcm[i][j]*32768.f);
  141841. if(val>32767)val=32767;
  141842. else if(val<-32768)val=-32768;
  141843. val+=off;
  141844. *buffer++=(val&0xff);
  141845. *buffer++=(val>>8);
  141846. }
  141847. vorbis_fpu_restore(fpu);
  141848. }
  141849. }
  141850. }
  141851. vorbis_synthesis_read(&vf->vd,samples);
  141852. vf->pcm_offset+=samples;
  141853. if(bitstream)*bitstream=vf->current_link;
  141854. return(samples*bytespersample);
  141855. }else{
  141856. return(samples);
  141857. }
  141858. }
  141859. long ov_read_float(OggVorbis_File *vf,float ***pcm_channels,int length,
  141860. int *bitstream){
  141861. if(vf->ready_state<OPENED)return(OV_EINVAL);
  141862. while(1){
  141863. if(vf->ready_state==INITSET){
  141864. float **pcm;
  141865. long samples=vorbis_synthesis_pcmout(&vf->vd,&pcm);
  141866. if(samples){
  141867. if(pcm_channels)*pcm_channels=pcm;
  141868. if(samples>length)samples=length;
  141869. vorbis_synthesis_read(&vf->vd,samples);
  141870. vf->pcm_offset+=samples;
  141871. if(bitstream)*bitstream=vf->current_link;
  141872. return samples;
  141873. }
  141874. }
  141875. {
  141876. int ret=_fetch_and_process_packet(vf,NULL,1,1);
  141877. if(ret==OV_EOF)return(0);
  141878. if(ret<=0)return(ret);
  141879. }
  141880. }
  141881. }
  141882. extern float *vorbis_window(vorbis_dsp_state *v,int W);
  141883. extern void _analysis_output_always(const char *base,int i,float *v,int n,int bark,int dB,
  141884. ogg_int64_t off);
  141885. static void _ov_splice(float **pcm,float **lappcm,
  141886. int n1, int n2,
  141887. int ch1, int ch2,
  141888. float *w1, float *w2){
  141889. int i,j;
  141890. float *w=w1;
  141891. int n=n1;
  141892. if(n1>n2){
  141893. n=n2;
  141894. w=w2;
  141895. }
  141896. for(j=0;j<ch1 && j<ch2;j++){
  141897. float *s=lappcm[j];
  141898. float *d=pcm[j];
  141899. for(i=0;i<n;i++){
  141900. float wd=w[i]*w[i];
  141901. float ws=1.-wd;
  141902. d[i]=d[i]*wd + s[i]*ws;
  141903. }
  141904. }
  141905. for(;j<ch2;j++){
  141906. float *d=pcm[j];
  141907. for(i=0;i<n;i++){
  141908. float wd=w[i]*w[i];
  141909. d[i]=d[i]*wd;
  141910. }
  141911. }
  141912. }
  141913. static int _ov_initset(OggVorbis_File *vf){
  141914. while(1){
  141915. if(vf->ready_state==INITSET)break;
  141916. {
  141917. int ret=_fetch_and_process_packet(vf,NULL,1,0);
  141918. if(ret<0 && ret!=OV_HOLE)return(ret);
  141919. }
  141920. }
  141921. return 0;
  141922. }
  141923. static int _ov_initprime(OggVorbis_File *vf){
  141924. vorbis_dsp_state *vd=&vf->vd;
  141925. while(1){
  141926. if(vf->ready_state==INITSET)
  141927. if(vorbis_synthesis_pcmout(vd,NULL))break;
  141928. {
  141929. int ret=_fetch_and_process_packet(vf,NULL,1,0);
  141930. if(ret<0 && ret!=OV_HOLE)return(ret);
  141931. }
  141932. }
  141933. return 0;
  141934. }
  141935. static void _ov_getlap(OggVorbis_File *vf,vorbis_info *vi,vorbis_dsp_state *vd,
  141936. float **lappcm,int lapsize){
  141937. int lapcount=0,i;
  141938. float **pcm;
  141939. while(lapcount<lapsize){
  141940. int samples=vorbis_synthesis_pcmout(vd,&pcm);
  141941. if(samples){
  141942. if(samples>lapsize-lapcount)samples=lapsize-lapcount;
  141943. for(i=0;i<vi->channels;i++)
  141944. memcpy(lappcm[i]+lapcount,pcm[i],sizeof(**pcm)*samples);
  141945. lapcount+=samples;
  141946. vorbis_synthesis_read(vd,samples);
  141947. }else{
  141948. int ret=_fetch_and_process_packet(vf,NULL,1,0); /* do *not* span */
  141949. if(ret==OV_EOF)break;
  141950. }
  141951. }
  141952. if(lapcount<lapsize){
  141953. int samples=vorbis_synthesis_lapout(&vf->vd,&pcm);
  141954. if(samples==0){
  141955. for(i=0;i<vi->channels;i++)
  141956. memset(lappcm[i]+lapcount,0,sizeof(**pcm)*lapsize-lapcount);
  141957. lapcount=lapsize;
  141958. }else{
  141959. if(samples>lapsize-lapcount)samples=lapsize-lapcount;
  141960. for(i=0;i<vi->channels;i++)
  141961. memcpy(lappcm[i]+lapcount,pcm[i],sizeof(**pcm)*samples);
  141962. lapcount+=samples;
  141963. }
  141964. }
  141965. }
  141966. int ov_crosslap(OggVorbis_File *vf1, OggVorbis_File *vf2){
  141967. vorbis_info *vi1,*vi2;
  141968. float **lappcm;
  141969. float **pcm;
  141970. float *w1,*w2;
  141971. int n1,n2,i,ret,hs1,hs2;
  141972. if(vf1==vf2)return(0); /* degenerate case */
  141973. if(vf1->ready_state<OPENED)return(OV_EINVAL);
  141974. if(vf2->ready_state<OPENED)return(OV_EINVAL);
  141975. ret=_ov_initset(vf1);
  141976. if(ret)return(ret);
  141977. ret=_ov_initprime(vf2);
  141978. if(ret)return(ret);
  141979. vi1=ov_info(vf1,-1);
  141980. vi2=ov_info(vf2,-1);
  141981. hs1=ov_halfrate_p(vf1);
  141982. hs2=ov_halfrate_p(vf2);
  141983. lappcm=(float**) alloca(sizeof(*lappcm)*vi1->channels);
  141984. n1=vorbis_info_blocksize(vi1,0)>>(1+hs1);
  141985. n2=vorbis_info_blocksize(vi2,0)>>(1+hs2);
  141986. w1=vorbis_window(&vf1->vd,0);
  141987. w2=vorbis_window(&vf2->vd,0);
  141988. for(i=0;i<vi1->channels;i++)
  141989. lappcm[i]=(float*) alloca(sizeof(**lappcm)*n1);
  141990. _ov_getlap(vf1,vi1,&vf1->vd,lappcm,n1);
  141991. vorbis_synthesis_lapout(&vf2->vd,&pcm);
  141992. _analysis_output_always("pcmL",0,pcm[0],n1*2,0,0,0);
  141993. _analysis_output_always("pcmR",0,pcm[1],n1*2,0,0,0);
  141994. _ov_splice(pcm,lappcm,n1,n2,vi1->channels,vi2->channels,w1,w2);
  141995. return(0);
  141996. }
  141997. static int _ov_64_seek_lap(OggVorbis_File *vf,ogg_int64_t pos,
  141998. int (*localseek)(OggVorbis_File *,ogg_int64_t)){
  141999. vorbis_info *vi;
  142000. float **lappcm;
  142001. float **pcm;
  142002. float *w1,*w2;
  142003. int n1,n2,ch1,ch2,hs;
  142004. int i,ret;
  142005. if(vf->ready_state<OPENED)return(OV_EINVAL);
  142006. ret=_ov_initset(vf);
  142007. if(ret)return(ret);
  142008. vi=ov_info(vf,-1);
  142009. hs=ov_halfrate_p(vf);
  142010. ch1=vi->channels;
  142011. n1=vorbis_info_blocksize(vi,0)>>(1+hs);
  142012. w1=vorbis_window(&vf->vd,0); /* window arrays from libvorbis are
  142013. persistent; even if the decode state
  142014. from this link gets dumped, this
  142015. window array continues to exist */
  142016. lappcm=(float**) alloca(sizeof(*lappcm)*ch1);
  142017. for(i=0;i<ch1;i++)
  142018. lappcm[i]=(float*) alloca(sizeof(**lappcm)*n1);
  142019. _ov_getlap(vf,vi,&vf->vd,lappcm,n1);
  142020. ret=localseek(vf,pos);
  142021. if(ret)return ret;
  142022. ret=_ov_initprime(vf);
  142023. if(ret)return(ret);
  142024. vi=ov_info(vf,-1);
  142025. ch2=vi->channels;
  142026. n2=vorbis_info_blocksize(vi,0)>>(1+hs);
  142027. w2=vorbis_window(&vf->vd,0);
  142028. vorbis_synthesis_lapout(&vf->vd,&pcm);
  142029. _ov_splice(pcm,lappcm,n1,n2,ch1,ch2,w1,w2);
  142030. return(0);
  142031. }
  142032. int ov_raw_seek_lap(OggVorbis_File *vf,ogg_int64_t pos){
  142033. return _ov_64_seek_lap(vf,pos,ov_raw_seek);
  142034. }
  142035. int ov_pcm_seek_lap(OggVorbis_File *vf,ogg_int64_t pos){
  142036. return _ov_64_seek_lap(vf,pos,ov_pcm_seek);
  142037. }
  142038. int ov_pcm_seek_page_lap(OggVorbis_File *vf,ogg_int64_t pos){
  142039. return _ov_64_seek_lap(vf,pos,ov_pcm_seek_page);
  142040. }
  142041. static int _ov_d_seek_lap(OggVorbis_File *vf,double pos,
  142042. int (*localseek)(OggVorbis_File *,double)){
  142043. vorbis_info *vi;
  142044. float **lappcm;
  142045. float **pcm;
  142046. float *w1,*w2;
  142047. int n1,n2,ch1,ch2,hs;
  142048. int i,ret;
  142049. if(vf->ready_state<OPENED)return(OV_EINVAL);
  142050. ret=_ov_initset(vf);
  142051. if(ret)return(ret);
  142052. vi=ov_info(vf,-1);
  142053. hs=ov_halfrate_p(vf);
  142054. ch1=vi->channels;
  142055. n1=vorbis_info_blocksize(vi,0)>>(1+hs);
  142056. w1=vorbis_window(&vf->vd,0); /* window arrays from libvorbis are
  142057. persistent; even if the decode state
  142058. from this link gets dumped, this
  142059. window array continues to exist */
  142060. lappcm=(float**) alloca(sizeof(*lappcm)*ch1);
  142061. for(i=0;i<ch1;i++)
  142062. lappcm[i]=(float*) alloca(sizeof(**lappcm)*n1);
  142063. _ov_getlap(vf,vi,&vf->vd,lappcm,n1);
  142064. ret=localseek(vf,pos);
  142065. if(ret)return ret;
  142066. ret=_ov_initprime(vf);
  142067. if(ret)return(ret);
  142068. vi=ov_info(vf,-1);
  142069. ch2=vi->channels;
  142070. n2=vorbis_info_blocksize(vi,0)>>(1+hs);
  142071. w2=vorbis_window(&vf->vd,0);
  142072. vorbis_synthesis_lapout(&vf->vd,&pcm);
  142073. _ov_splice(pcm,lappcm,n1,n2,ch1,ch2,w1,w2);
  142074. return(0);
  142075. }
  142076. int ov_time_seek_lap(OggVorbis_File *vf,double pos){
  142077. return _ov_d_seek_lap(vf,pos,ov_time_seek);
  142078. }
  142079. int ov_time_seek_page_lap(OggVorbis_File *vf,double pos){
  142080. return _ov_d_seek_lap(vf,pos,ov_time_seek_page);
  142081. }
  142082. #endif
  142083. /*** End of inlined file: vorbisfile.c ***/
  142084. /*** Start of inlined file: window.c ***/
  142085. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  142086. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  142087. // tasks..
  142088. #if JUCE_MSVC
  142089. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  142090. #endif
  142091. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  142092. #if JUCE_USE_OGGVORBIS
  142093. #include <stdlib.h>
  142094. #include <math.h>
  142095. static float vwin64[32] = {
  142096. 0.0009460463F, 0.0085006468F, 0.0235352254F, 0.0458950567F,
  142097. 0.0753351908F, 0.1115073077F, 0.1539457973F, 0.2020557475F,
  142098. 0.2551056759F, 0.3122276645F, 0.3724270287F, 0.4346027792F,
  142099. 0.4975789974F, 0.5601459521F, 0.6211085051F, 0.6793382689F,
  142100. 0.7338252629F, 0.7837245849F, 0.8283939355F, 0.8674186656F,
  142101. 0.9006222429F, 0.9280614787F, 0.9500073081F, 0.9669131782F,
  142102. 0.9793740220F, 0.9880792941F, 0.9937636139F, 0.9971582668F,
  142103. 0.9989462667F, 0.9997230082F, 0.9999638688F, 0.9999995525F,
  142104. };
  142105. static float vwin128[64] = {
  142106. 0.0002365472F, 0.0021280687F, 0.0059065254F, 0.0115626550F,
  142107. 0.0190823442F, 0.0284463735F, 0.0396300935F, 0.0526030430F,
  142108. 0.0673285281F, 0.0837631763F, 0.1018564887F, 0.1215504095F,
  142109. 0.1427789367F, 0.1654677960F, 0.1895342001F, 0.2148867160F,
  142110. 0.2414252576F, 0.2690412240F, 0.2976177952F, 0.3270303960F,
  142111. 0.3571473350F, 0.3878306189F, 0.4189369387F, 0.4503188188F,
  142112. 0.4818259135F, 0.5133064334F, 0.5446086751F, 0.5755826278F,
  142113. 0.6060816248F, 0.6359640047F, 0.6650947483F, 0.6933470543F,
  142114. 0.7206038179F, 0.7467589810F, 0.7717187213F, 0.7954024542F,
  142115. 0.8177436264F, 0.8386902831F, 0.8582053981F, 0.8762669622F,
  142116. 0.8928678298F, 0.9080153310F, 0.9217306608F, 0.9340480615F,
  142117. 0.9450138200F, 0.9546851041F, 0.9631286621F, 0.9704194171F,
  142118. 0.9766389810F, 0.9818741197F, 0.9862151938F, 0.9897546035F,
  142119. 0.9925852598F, 0.9947991032F, 0.9964856900F, 0.9977308602F,
  142120. 0.9986155015F, 0.9992144193F, 0.9995953200F, 0.9998179155F,
  142121. 0.9999331503F, 0.9999825563F, 0.9999977357F, 0.9999999720F,
  142122. };
  142123. static float vwin256[128] = {
  142124. 0.0000591390F, 0.0005321979F, 0.0014780301F, 0.0028960636F,
  142125. 0.0047854363F, 0.0071449926F, 0.0099732775F, 0.0132685298F,
  142126. 0.0170286741F, 0.0212513119F, 0.0259337111F, 0.0310727950F,
  142127. 0.0366651302F, 0.0427069140F, 0.0491939614F, 0.0561216907F,
  142128. 0.0634851102F, 0.0712788035F, 0.0794969160F, 0.0881331402F,
  142129. 0.0971807028F, 0.1066323515F, 0.1164803426F, 0.1267164297F,
  142130. 0.1373318534F, 0.1483173323F, 0.1596630553F, 0.1713586755F,
  142131. 0.1833933062F, 0.1957555184F, 0.2084333404F, 0.2214142599F,
  142132. 0.2346852280F, 0.2482326664F, 0.2620424757F, 0.2761000481F,
  142133. 0.2903902813F, 0.3048975959F, 0.3196059553F, 0.3344988887F,
  142134. 0.3495595160F, 0.3647705766F, 0.3801144597F, 0.3955732382F,
  142135. 0.4111287047F, 0.4267624093F, 0.4424557009F, 0.4581897696F,
  142136. 0.4739456913F, 0.4897044744F, 0.5054471075F, 0.5211546088F,
  142137. 0.5368080763F, 0.5523887395F, 0.5678780103F, 0.5832575361F,
  142138. 0.5985092508F, 0.6136154277F, 0.6285587300F, 0.6433222619F,
  142139. 0.6578896175F, 0.6722449294F, 0.6863729144F, 0.7002589187F,
  142140. 0.7138889597F, 0.7272497662F, 0.7403288154F, 0.7531143679F,
  142141. 0.7655954985F, 0.7777621249F, 0.7896050322F, 0.8011158947F,
  142142. 0.8122872932F, 0.8231127294F, 0.8335866365F, 0.8437043850F,
  142143. 0.8534622861F, 0.8628575905F, 0.8718884835F, 0.8805540765F,
  142144. 0.8888543947F, 0.8967903616F, 0.9043637797F, 0.9115773078F,
  142145. 0.9184344360F, 0.9249394562F, 0.9310974312F, 0.9369141608F,
  142146. 0.9423961446F, 0.9475505439F, 0.9523851406F, 0.9569082947F,
  142147. 0.9611289005F, 0.9650563408F, 0.9687004405F, 0.9720714191F,
  142148. 0.9751798427F, 0.9780365753F, 0.9806527301F, 0.9830396204F,
  142149. 0.9852087111F, 0.9871715701F, 0.9889398207F, 0.9905250941F,
  142150. 0.9919389832F, 0.9931929973F, 0.9942985174F, 0.9952667537F,
  142151. 0.9961087037F, 0.9968351119F, 0.9974564312F, 0.9979827858F,
  142152. 0.9984239359F, 0.9987892441F, 0.9990876435F, 0.9993276081F,
  142153. 0.9995171241F, 0.9996636648F, 0.9997741654F, 0.9998550016F,
  142154. 0.9999119692F, 0.9999502656F, 0.9999744742F, 0.9999885497F,
  142155. 0.9999958064F, 0.9999989077F, 0.9999998584F, 0.9999999983F,
  142156. };
  142157. static float vwin512[256] = {
  142158. 0.0000147849F, 0.0001330607F, 0.0003695946F, 0.0007243509F,
  142159. 0.0011972759F, 0.0017882983F, 0.0024973285F, 0.0033242588F,
  142160. 0.0042689632F, 0.0053312973F, 0.0065110982F, 0.0078081841F,
  142161. 0.0092223540F, 0.0107533880F, 0.0124010466F, 0.0141650703F,
  142162. 0.0160451800F, 0.0180410758F, 0.0201524373F, 0.0223789233F,
  142163. 0.0247201710F, 0.0271757958F, 0.0297453914F, 0.0324285286F,
  142164. 0.0352247556F, 0.0381335972F, 0.0411545545F, 0.0442871045F,
  142165. 0.0475306997F, 0.0508847676F, 0.0543487103F, 0.0579219038F,
  142166. 0.0616036982F, 0.0653934164F, 0.0692903546F, 0.0732937809F,
  142167. 0.0774029356F, 0.0816170305F, 0.0859352485F, 0.0903567428F,
  142168. 0.0948806375F, 0.0995060259F, 0.1042319712F, 0.1090575056F,
  142169. 0.1139816300F, 0.1190033137F, 0.1241214941F, 0.1293350764F,
  142170. 0.1346429333F, 0.1400439046F, 0.1455367974F, 0.1511203852F,
  142171. 0.1567934083F, 0.1625545735F, 0.1684025537F, 0.1743359881F,
  142172. 0.1803534820F, 0.1864536069F, 0.1926349000F, 0.1988958650F,
  142173. 0.2052349715F, 0.2116506555F, 0.2181413191F, 0.2247053313F,
  142174. 0.2313410275F, 0.2380467105F, 0.2448206500F, 0.2516610835F,
  142175. 0.2585662164F, 0.2655342226F, 0.2725632448F, 0.2796513950F,
  142176. 0.2867967551F, 0.2939973773F, 0.3012512852F, 0.3085564739F,
  142177. 0.3159109111F, 0.3233125375F, 0.3307592680F, 0.3382489922F,
  142178. 0.3457795756F, 0.3533488602F, 0.3609546657F, 0.3685947904F,
  142179. 0.3762670121F, 0.3839690896F, 0.3916987634F, 0.3994537572F,
  142180. 0.4072317788F, 0.4150305215F, 0.4228476653F, 0.4306808783F,
  142181. 0.4385278181F, 0.4463861329F, 0.4542534630F, 0.4621274424F,
  142182. 0.4700057001F, 0.4778858615F, 0.4857655502F, 0.4936423891F,
  142183. 0.5015140023F, 0.5093780165F, 0.5172320626F, 0.5250737772F,
  142184. 0.5329008043F, 0.5407107971F, 0.5485014192F, 0.5562703465F,
  142185. 0.5640152688F, 0.5717338914F, 0.5794239366F, 0.5870831457F,
  142186. 0.5947092801F, 0.6023001235F, 0.6098534829F, 0.6173671907F,
  142187. 0.6248391059F, 0.6322671161F, 0.6396491384F, 0.6469831217F,
  142188. 0.6542670475F, 0.6614989319F, 0.6686768267F, 0.6757988210F,
  142189. 0.6828630426F, 0.6898676592F, 0.6968108799F, 0.7036909564F,
  142190. 0.7105061843F, 0.7172549043F, 0.7239355032F, 0.7305464154F,
  142191. 0.7370861235F, 0.7435531598F, 0.7499461068F, 0.7562635986F,
  142192. 0.7625043214F, 0.7686670148F, 0.7747504721F, 0.7807535410F,
  142193. 0.7866751247F, 0.7925141825F, 0.7982697296F, 0.8039408387F,
  142194. 0.8095266395F, 0.8150263196F, 0.8204391248F, 0.8257643590F,
  142195. 0.8310013848F, 0.8361496236F, 0.8412085555F, 0.8461777194F,
  142196. 0.8510567129F, 0.8558451924F, 0.8605428730F, 0.8651495278F,
  142197. 0.8696649882F, 0.8740891432F, 0.8784219392F, 0.8826633797F,
  142198. 0.8868135244F, 0.8908724888F, 0.8948404441F, 0.8987176157F,
  142199. 0.9025042831F, 0.9062007791F, 0.9098074886F, 0.9133248482F,
  142200. 0.9167533451F, 0.9200935163F, 0.9233459472F, 0.9265112712F,
  142201. 0.9295901680F, 0.9325833632F, 0.9354916263F, 0.9383157705F,
  142202. 0.9410566504F, 0.9437151618F, 0.9462922398F, 0.9487888576F,
  142203. 0.9512060252F, 0.9535447882F, 0.9558062262F, 0.9579914516F,
  142204. 0.9601016078F, 0.9621378683F, 0.9641014348F, 0.9659935361F,
  142205. 0.9678154261F, 0.9695683830F, 0.9712537071F, 0.9728727198F,
  142206. 0.9744267618F, 0.9759171916F, 0.9773453842F, 0.9787127293F,
  142207. 0.9800206298F, 0.9812705006F, 0.9824637665F, 0.9836018613F,
  142208. 0.9846862258F, 0.9857183066F, 0.9866995544F, 0.9876314227F,
  142209. 0.9885153662F, 0.9893528393F, 0.9901452948F, 0.9908941823F,
  142210. 0.9916009470F, 0.9922670279F, 0.9928938570F, 0.9934828574F,
  142211. 0.9940354423F, 0.9945530133F, 0.9950369595F, 0.9954886562F,
  142212. 0.9959094633F, 0.9963007242F, 0.9966637649F, 0.9969998925F,
  142213. 0.9973103939F, 0.9975965351F, 0.9978595598F, 0.9981006885F,
  142214. 0.9983211172F, 0.9985220166F, 0.9987045311F, 0.9988697776F,
  142215. 0.9990188449F, 0.9991527924F, 0.9992726499F, 0.9993794157F,
  142216. 0.9994740570F, 0.9995575079F, 0.9996306699F, 0.9996944099F,
  142217. 0.9997495605F, 0.9997969190F, 0.9998372465F, 0.9998712678F,
  142218. 0.9998996704F, 0.9999231041F, 0.9999421807F, 0.9999574732F,
  142219. 0.9999695157F, 0.9999788026F, 0.9999857885F, 0.9999908879F,
  142220. 0.9999944746F, 0.9999968817F, 0.9999984010F, 0.9999992833F,
  142221. 0.9999997377F, 0.9999999317F, 0.9999999911F, 0.9999999999F,
  142222. };
  142223. static float vwin1024[512] = {
  142224. 0.0000036962F, 0.0000332659F, 0.0000924041F, 0.0001811086F,
  142225. 0.0002993761F, 0.0004472021F, 0.0006245811F, 0.0008315063F,
  142226. 0.0010679699F, 0.0013339631F, 0.0016294757F, 0.0019544965F,
  142227. 0.0023090133F, 0.0026930125F, 0.0031064797F, 0.0035493989F,
  142228. 0.0040217533F, 0.0045235250F, 0.0050546946F, 0.0056152418F,
  142229. 0.0062051451F, 0.0068243817F, 0.0074729278F, 0.0081507582F,
  142230. 0.0088578466F, 0.0095941655F, 0.0103596863F, 0.0111543789F,
  142231. 0.0119782122F, 0.0128311538F, 0.0137131701F, 0.0146242260F,
  142232. 0.0155642855F, 0.0165333111F, 0.0175312640F, 0.0185581042F,
  142233. 0.0196137903F, 0.0206982797F, 0.0218115284F, 0.0229534910F,
  142234. 0.0241241208F, 0.0253233698F, 0.0265511886F, 0.0278075263F,
  142235. 0.0290923308F, 0.0304055484F, 0.0317471241F, 0.0331170013F,
  142236. 0.0345151222F, 0.0359414274F, 0.0373958560F, 0.0388783456F,
  142237. 0.0403888325F, 0.0419272511F, 0.0434935347F, 0.0450876148F,
  142238. 0.0467094213F, 0.0483588828F, 0.0500359261F, 0.0517404765F,
  142239. 0.0534724575F, 0.0552317913F, 0.0570183983F, 0.0588321971F,
  142240. 0.0606731048F, 0.0625410369F, 0.0644359070F, 0.0663576272F,
  142241. 0.0683061077F, 0.0702812571F, 0.0722829821F, 0.0743111878F,
  142242. 0.0763657775F, 0.0784466526F, 0.0805537129F, 0.0826868561F,
  142243. 0.0848459782F, 0.0870309736F, 0.0892417345F, 0.0914781514F,
  142244. 0.0937401128F, 0.0960275056F, 0.0983402145F, 0.1006781223F,
  142245. 0.1030411101F, 0.1054290568F, 0.1078418397F, 0.1102793336F,
  142246. 0.1127414119F, 0.1152279457F, 0.1177388042F, 0.1202738544F,
  142247. 0.1228329618F, 0.1254159892F, 0.1280227980F, 0.1306532471F,
  142248. 0.1333071937F, 0.1359844927F, 0.1386849970F, 0.1414085575F,
  142249. 0.1441550230F, 0.1469242403F, 0.1497160539F, 0.1525303063F,
  142250. 0.1553668381F, 0.1582254875F, 0.1611060909F, 0.1640084822F,
  142251. 0.1669324936F, 0.1698779549F, 0.1728446939F, 0.1758325362F,
  142252. 0.1788413055F, 0.1818708232F, 0.1849209084F, 0.1879913785F,
  142253. 0.1910820485F, 0.1941927312F, 0.1973232376F, 0.2004733764F,
  142254. 0.2036429541F, 0.2068317752F, 0.2100396421F, 0.2132663552F,
  142255. 0.2165117125F, 0.2197755102F, 0.2230575422F, 0.2263576007F,
  142256. 0.2296754753F, 0.2330109540F, 0.2363638225F, 0.2397338646F,
  142257. 0.2431208619F, 0.2465245941F, 0.2499448389F, 0.2533813719F,
  142258. 0.2568339669F, 0.2603023956F, 0.2637864277F, 0.2672858312F,
  142259. 0.2708003718F, 0.2743298135F, 0.2778739186F, 0.2814324472F,
  142260. 0.2850051576F, 0.2885918065F, 0.2921921485F, 0.2958059366F,
  142261. 0.2994329219F, 0.3030728538F, 0.3067254799F, 0.3103905462F,
  142262. 0.3140677969F, 0.3177569747F, 0.3214578205F, 0.3251700736F,
  142263. 0.3288934718F, 0.3326277513F, 0.3363726468F, 0.3401278914F,
  142264. 0.3438932168F, 0.3476683533F, 0.3514530297F, 0.3552469734F,
  142265. 0.3590499106F, 0.3628615659F, 0.3666816630F, 0.3705099239F,
  142266. 0.3743460698F, 0.3781898204F, 0.3820408945F, 0.3858990095F,
  142267. 0.3897638820F, 0.3936352274F, 0.3975127601F, 0.4013961936F,
  142268. 0.4052852405F, 0.4091796123F, 0.4130790198F, 0.4169831732F,
  142269. 0.4208917815F, 0.4248045534F, 0.4287211965F, 0.4326414181F,
  142270. 0.4365649248F, 0.4404914225F, 0.4444206167F, 0.4483522125F,
  142271. 0.4522859146F, 0.4562214270F, 0.4601584538F, 0.4640966984F,
  142272. 0.4680358644F, 0.4719756548F, 0.4759157726F, 0.4798559209F,
  142273. 0.4837958024F, 0.4877351199F, 0.4916735765F, 0.4956108751F,
  142274. 0.4995467188F, 0.5034808109F, 0.5074128550F, 0.5113425550F,
  142275. 0.5152696149F, 0.5191937395F, 0.5231146336F, 0.5270320028F,
  142276. 0.5309455530F, 0.5348549910F, 0.5387600239F, 0.5426603597F,
  142277. 0.5465557070F, 0.5504457754F, 0.5543302752F, 0.5582089175F,
  142278. 0.5620814145F, 0.5659474793F, 0.5698068262F, 0.5736591704F,
  142279. 0.5775042283F, 0.5813417176F, 0.5851713571F, 0.5889928670F,
  142280. 0.5928059689F, 0.5966103856F, 0.6004058415F, 0.6041920626F,
  142281. 0.6079687761F, 0.6117357113F, 0.6154925986F, 0.6192391705F,
  142282. 0.6229751612F, 0.6267003064F, 0.6304143441F, 0.6341170137F,
  142283. 0.6378080569F, 0.6414872173F, 0.6451542405F, 0.6488088741F,
  142284. 0.6524508681F, 0.6560799742F, 0.6596959469F, 0.6632985424F,
  142285. 0.6668875197F, 0.6704626398F, 0.6740236662F, 0.6775703649F,
  142286. 0.6811025043F, 0.6846198554F, 0.6881221916F, 0.6916092892F,
  142287. 0.6950809269F, 0.6985368861F, 0.7019769510F, 0.7054009085F,
  142288. 0.7088085484F, 0.7121996632F, 0.7155740484F, 0.7189315023F,
  142289. 0.7222718263F, 0.7255948245F, 0.7289003043F, 0.7321880760F,
  142290. 0.7354579530F, 0.7387097518F, 0.7419432921F, 0.7451583966F,
  142291. 0.7483548915F, 0.7515326059F, 0.7546913723F, 0.7578310265F,
  142292. 0.7609514077F, 0.7640523581F, 0.7671337237F, 0.7701953535F,
  142293. 0.7732371001F, 0.7762588195F, 0.7792603711F, 0.7822416178F,
  142294. 0.7852024259F, 0.7881426654F, 0.7910622097F, 0.7939609356F,
  142295. 0.7968387237F, 0.7996954579F, 0.8025310261F, 0.8053453193F,
  142296. 0.8081382324F, 0.8109096638F, 0.8136595156F, 0.8163876936F,
  142297. 0.8190941071F, 0.8217786690F, 0.8244412960F, 0.8270819086F,
  142298. 0.8297004305F, 0.8322967896F, 0.8348709171F, 0.8374227481F,
  142299. 0.8399522213F, 0.8424592789F, 0.8449438672F, 0.8474059356F,
  142300. 0.8498454378F, 0.8522623306F, 0.8546565748F, 0.8570281348F,
  142301. 0.8593769787F, 0.8617030779F, 0.8640064080F, 0.8662869477F,
  142302. 0.8685446796F, 0.8707795899F, 0.8729916682F, 0.8751809079F,
  142303. 0.8773473059F, 0.8794908626F, 0.8816115819F, 0.8837094713F,
  142304. 0.8857845418F, 0.8878368079F, 0.8898662874F, 0.8918730019F,
  142305. 0.8938569760F, 0.8958182380F, 0.8977568194F, 0.8996727552F,
  142306. 0.9015660837F, 0.9034368465F, 0.9052850885F, 0.9071108577F,
  142307. 0.9089142057F, 0.9106951869F, 0.9124538591F, 0.9141902832F,
  142308. 0.9159045233F, 0.9175966464F, 0.9192667228F, 0.9209148257F,
  142309. 0.9225410313F, 0.9241454187F, 0.9257280701F, 0.9272890704F,
  142310. 0.9288285075F, 0.9303464720F, 0.9318430576F, 0.9333183603F,
  142311. 0.9347724792F, 0.9362055158F, 0.9376175745F, 0.9390087622F,
  142312. 0.9403791881F, 0.9417289644F, 0.9430582055F, 0.9443670283F,
  142313. 0.9456555521F, 0.9469238986F, 0.9481721917F, 0.9494005577F,
  142314. 0.9506091252F, 0.9517980248F, 0.9529673894F, 0.9541173540F,
  142315. 0.9552480557F, 0.9563596334F, 0.9574522282F, 0.9585259830F,
  142316. 0.9595810428F, 0.9606175542F, 0.9616356656F, 0.9626355274F,
  142317. 0.9636172915F, 0.9645811114F, 0.9655271425F, 0.9664555414F,
  142318. 0.9673664664F, 0.9682600774F, 0.9691365355F, 0.9699960034F,
  142319. 0.9708386448F, 0.9716646250F, 0.9724741103F, 0.9732672685F,
  142320. 0.9740442683F, 0.9748052795F, 0.9755504729F, 0.9762800205F,
  142321. 0.9769940950F, 0.9776928703F, 0.9783765210F, 0.9790452223F,
  142322. 0.9796991504F, 0.9803384823F, 0.9809633954F, 0.9815740679F,
  142323. 0.9821706784F, 0.9827534063F, 0.9833224312F, 0.9838779332F,
  142324. 0.9844200928F, 0.9849490910F, 0.9854651087F, 0.9859683274F,
  142325. 0.9864589286F, 0.9869370940F, 0.9874030054F, 0.9878568447F,
  142326. 0.9882987937F, 0.9887290343F, 0.9891477481F, 0.9895551169F,
  142327. 0.9899513220F, 0.9903365446F, 0.9907109658F, 0.9910747662F,
  142328. 0.9914281260F, 0.9917712252F, 0.9921042433F, 0.9924273593F,
  142329. 0.9927407516F, 0.9930445982F, 0.9933390763F, 0.9936243626F,
  142330. 0.9939006331F, 0.9941680631F, 0.9944268269F, 0.9946770982F,
  142331. 0.9949190498F, 0.9951528537F, 0.9953786808F, 0.9955967011F,
  142332. 0.9958070836F, 0.9960099963F, 0.9962056061F, 0.9963940787F,
  142333. 0.9965755786F, 0.9967502693F, 0.9969183129F, 0.9970798704F,
  142334. 0.9972351013F, 0.9973841640F, 0.9975272151F, 0.9976644103F,
  142335. 0.9977959036F, 0.9979218476F, 0.9980423932F, 0.9981576901F,
  142336. 0.9982678862F, 0.9983731278F, 0.9984735596F, 0.9985693247F,
  142337. 0.9986605645F, 0.9987474186F, 0.9988300248F, 0.9989085193F,
  142338. 0.9989830364F, 0.9990537085F, 0.9991206662F, 0.9991840382F,
  142339. 0.9992439513F, 0.9993005303F, 0.9993538982F, 0.9994041757F,
  142340. 0.9994514817F, 0.9994959330F, 0.9995376444F, 0.9995767286F,
  142341. 0.9996132960F, 0.9996474550F, 0.9996793121F, 0.9997089710F,
  142342. 0.9997365339F, 0.9997621003F, 0.9997857677F, 0.9998076311F,
  142343. 0.9998277836F, 0.9998463156F, 0.9998633155F, 0.9998788692F,
  142344. 0.9998930603F, 0.9999059701F, 0.9999176774F, 0.9999282586F,
  142345. 0.9999377880F, 0.9999463370F, 0.9999539749F, 0.9999607685F,
  142346. 0.9999667820F, 0.9999720773F, 0.9999767136F, 0.9999807479F,
  142347. 0.9999842344F, 0.9999872249F, 0.9999897688F, 0.9999919127F,
  142348. 0.9999937009F, 0.9999951749F, 0.9999963738F, 0.9999973342F,
  142349. 0.9999980900F, 0.9999986724F, 0.9999991103F, 0.9999994297F,
  142350. 0.9999996543F, 0.9999998049F, 0.9999999000F, 0.9999999552F,
  142351. 0.9999999836F, 0.9999999957F, 0.9999999994F, 1.0000000000F,
  142352. };
  142353. static float vwin2048[1024] = {
  142354. 0.0000009241F, 0.0000083165F, 0.0000231014F, 0.0000452785F,
  142355. 0.0000748476F, 0.0001118085F, 0.0001561608F, 0.0002079041F,
  142356. 0.0002670379F, 0.0003335617F, 0.0004074748F, 0.0004887765F,
  142357. 0.0005774661F, 0.0006735427F, 0.0007770054F, 0.0008878533F,
  142358. 0.0010060853F, 0.0011317002F, 0.0012646969F, 0.0014050742F,
  142359. 0.0015528307F, 0.0017079650F, 0.0018704756F, 0.0020403610F,
  142360. 0.0022176196F, 0.0024022497F, 0.0025942495F, 0.0027936173F,
  142361. 0.0030003511F, 0.0032144490F, 0.0034359088F, 0.0036647286F,
  142362. 0.0039009061F, 0.0041444391F, 0.0043953253F, 0.0046535621F,
  142363. 0.0049191472F, 0.0051920781F, 0.0054723520F, 0.0057599664F,
  142364. 0.0060549184F, 0.0063572052F, 0.0066668239F, 0.0069837715F,
  142365. 0.0073080449F, 0.0076396410F, 0.0079785566F, 0.0083247884F,
  142366. 0.0086783330F, 0.0090391871F, 0.0094073470F, 0.0097828092F,
  142367. 0.0101655700F, 0.0105556258F, 0.0109529726F, 0.0113576065F,
  142368. 0.0117695237F, 0.0121887200F, 0.0126151913F, 0.0130489335F,
  142369. 0.0134899422F, 0.0139382130F, 0.0143937415F, 0.0148565233F,
  142370. 0.0153265536F, 0.0158038279F, 0.0162883413F, 0.0167800889F,
  142371. 0.0172790660F, 0.0177852675F, 0.0182986882F, 0.0188193231F,
  142372. 0.0193471668F, 0.0198822141F, 0.0204244594F, 0.0209738974F,
  142373. 0.0215305225F, 0.0220943289F, 0.0226653109F, 0.0232434627F,
  142374. 0.0238287784F, 0.0244212519F, 0.0250208772F, 0.0256276481F,
  142375. 0.0262415582F, 0.0268626014F, 0.0274907711F, 0.0281260608F,
  142376. 0.0287684638F, 0.0294179736F, 0.0300745833F, 0.0307382859F,
  142377. 0.0314090747F, 0.0320869424F, 0.0327718819F, 0.0334638860F,
  142378. 0.0341629474F, 0.0348690586F, 0.0355822122F, 0.0363024004F,
  142379. 0.0370296157F, 0.0377638502F, 0.0385050960F, 0.0392533451F,
  142380. 0.0400085896F, 0.0407708211F, 0.0415400315F, 0.0423162123F,
  142381. 0.0430993552F, 0.0438894515F, 0.0446864926F, 0.0454904698F,
  142382. 0.0463013742F, 0.0471191969F, 0.0479439288F, 0.0487755607F,
  142383. 0.0496140836F, 0.0504594879F, 0.0513117642F, 0.0521709031F,
  142384. 0.0530368949F, 0.0539097297F, 0.0547893979F, 0.0556758894F,
  142385. 0.0565691941F, 0.0574693019F, 0.0583762026F, 0.0592898858F,
  142386. 0.0602103410F, 0.0611375576F, 0.0620715250F, 0.0630122324F,
  142387. 0.0639596688F, 0.0649138234F, 0.0658746848F, 0.0668422421F,
  142388. 0.0678164838F, 0.0687973985F, 0.0697849746F, 0.0707792005F,
  142389. 0.0717800645F, 0.0727875547F, 0.0738016591F, 0.0748223656F,
  142390. 0.0758496620F, 0.0768835359F, 0.0779239751F, 0.0789709668F,
  142391. 0.0800244985F, 0.0810845574F, 0.0821511306F, 0.0832242052F,
  142392. 0.0843037679F, 0.0853898056F, 0.0864823050F, 0.0875812525F,
  142393. 0.0886866347F, 0.0897984378F, 0.0909166480F, 0.0920412513F,
  142394. 0.0931722338F, 0.0943095813F, 0.0954532795F, 0.0966033140F,
  142395. 0.0977596702F, 0.0989223336F, 0.1000912894F, 0.1012665227F,
  142396. 0.1024480185F, 0.1036357616F, 0.1048297369F, 0.1060299290F,
  142397. 0.1072363224F, 0.1084489014F, 0.1096676504F, 0.1108925534F,
  142398. 0.1121235946F, 0.1133607577F, 0.1146040267F, 0.1158533850F,
  142399. 0.1171088163F, 0.1183703040F, 0.1196378312F, 0.1209113812F,
  142400. 0.1221909370F, 0.1234764815F, 0.1247679974F, 0.1260654674F,
  142401. 0.1273688740F, 0.1286781995F, 0.1299934263F, 0.1313145365F,
  142402. 0.1326415121F, 0.1339743349F, 0.1353129866F, 0.1366574490F,
  142403. 0.1380077035F, 0.1393637315F, 0.1407255141F, 0.1420930325F,
  142404. 0.1434662677F, 0.1448452004F, 0.1462298115F, 0.1476200814F,
  142405. 0.1490159906F, 0.1504175195F, 0.1518246482F, 0.1532373569F,
  142406. 0.1546556253F, 0.1560794333F, 0.1575087606F, 0.1589435866F,
  142407. 0.1603838909F, 0.1618296526F, 0.1632808509F, 0.1647374648F,
  142408. 0.1661994731F, 0.1676668546F, 0.1691395880F, 0.1706176516F,
  142409. 0.1721010238F, 0.1735896829F, 0.1750836068F, 0.1765827736F,
  142410. 0.1780871610F, 0.1795967468F, 0.1811115084F, 0.1826314234F,
  142411. 0.1841564689F, 0.1856866221F, 0.1872218600F, 0.1887621595F,
  142412. 0.1903074974F, 0.1918578503F, 0.1934131947F, 0.1949735068F,
  142413. 0.1965387630F, 0.1981089393F, 0.1996840117F, 0.2012639560F,
  142414. 0.2028487479F, 0.2044383630F, 0.2060327766F, 0.2076319642F,
  142415. 0.2092359007F, 0.2108445614F, 0.2124579211F, 0.2140759545F,
  142416. 0.2156986364F, 0.2173259411F, 0.2189578432F, 0.2205943168F,
  142417. 0.2222353361F, 0.2238808751F, 0.2255309076F, 0.2271854073F,
  142418. 0.2288443480F, 0.2305077030F, 0.2321754457F, 0.2338475493F,
  142419. 0.2355239869F, 0.2372047315F, 0.2388897560F, 0.2405790329F,
  142420. 0.2422725350F, 0.2439702347F, 0.2456721043F, 0.2473781159F,
  142421. 0.2490882418F, 0.2508024539F, 0.2525207240F, 0.2542430237F,
  142422. 0.2559693248F, 0.2576995986F, 0.2594338166F, 0.2611719498F,
  142423. 0.2629139695F, 0.2646598466F, 0.2664095520F, 0.2681630564F,
  142424. 0.2699203304F, 0.2716813445F, 0.2734460691F, 0.2752144744F,
  142425. 0.2769865307F, 0.2787622079F, 0.2805414760F, 0.2823243047F,
  142426. 0.2841106637F, 0.2859005227F, 0.2876938509F, 0.2894906179F,
  142427. 0.2912907928F, 0.2930943447F, 0.2949012426F, 0.2967114554F,
  142428. 0.2985249520F, 0.3003417009F, 0.3021616708F, 0.3039848301F,
  142429. 0.3058111471F, 0.3076405901F, 0.3094731273F, 0.3113087266F,
  142430. 0.3131473560F, 0.3149889833F, 0.3168335762F, 0.3186811024F,
  142431. 0.3205315294F, 0.3223848245F, 0.3242409552F, 0.3260998886F,
  142432. 0.3279615918F, 0.3298260319F, 0.3316931758F, 0.3335629903F,
  142433. 0.3354354423F, 0.3373104982F, 0.3391881247F, 0.3410682882F,
  142434. 0.3429509551F, 0.3448360917F, 0.3467236642F, 0.3486136387F,
  142435. 0.3505059811F, 0.3524006575F, 0.3542976336F, 0.3561968753F,
  142436. 0.3580983482F, 0.3600020179F, 0.3619078499F, 0.3638158096F,
  142437. 0.3657258625F, 0.3676379737F, 0.3695521086F, 0.3714682321F,
  142438. 0.3733863094F, 0.3753063055F, 0.3772281852F, 0.3791519134F,
  142439. 0.3810774548F, 0.3830047742F, 0.3849338362F, 0.3868646053F,
  142440. 0.3887970459F, 0.3907311227F, 0.3926667998F, 0.3946040417F,
  142441. 0.3965428125F, 0.3984830765F, 0.4004247978F, 0.4023679403F,
  142442. 0.4043124683F, 0.4062583455F, 0.4082055359F, 0.4101540034F,
  142443. 0.4121037117F, 0.4140546246F, 0.4160067058F, 0.4179599190F,
  142444. 0.4199142277F, 0.4218695956F, 0.4238259861F, 0.4257833627F,
  142445. 0.4277416888F, 0.4297009279F, 0.4316610433F, 0.4336219983F,
  142446. 0.4355837562F, 0.4375462803F, 0.4395095337F, 0.4414734797F,
  142447. 0.4434380815F, 0.4454033021F, 0.4473691046F, 0.4493354521F,
  142448. 0.4513023078F, 0.4532696345F, 0.4552373954F, 0.4572055533F,
  142449. 0.4591740713F, 0.4611429123F, 0.4631120393F, 0.4650814151F,
  142450. 0.4670510028F, 0.4690207650F, 0.4709906649F, 0.4729606651F,
  142451. 0.4749307287F, 0.4769008185F, 0.4788708972F, 0.4808409279F,
  142452. 0.4828108732F, 0.4847806962F, 0.4867503597F, 0.4887198264F,
  142453. 0.4906890593F, 0.4926580213F, 0.4946266753F, 0.4965949840F,
  142454. 0.4985629105F, 0.5005304176F, 0.5024974683F, 0.5044640255F,
  142455. 0.5064300522F, 0.5083955114F, 0.5103603659F, 0.5123245790F,
  142456. 0.5142881136F, 0.5162509328F, 0.5182129997F, 0.5201742774F,
  142457. 0.5221347290F, 0.5240943178F, 0.5260530070F, 0.5280107598F,
  142458. 0.5299675395F, 0.5319233095F, 0.5338780330F, 0.5358316736F,
  142459. 0.5377841946F, 0.5397355596F, 0.5416857320F, 0.5436346755F,
  142460. 0.5455823538F, 0.5475287304F, 0.5494737691F, 0.5514174337F,
  142461. 0.5533596881F, 0.5553004962F, 0.5572398218F, 0.5591776291F,
  142462. 0.5611138821F, 0.5630485449F, 0.5649815818F, 0.5669129570F,
  142463. 0.5688426349F, 0.5707705799F, 0.5726967564F, 0.5746211290F,
  142464. 0.5765436624F, 0.5784643212F, 0.5803830702F, 0.5822998743F,
  142465. 0.5842146984F, 0.5861275076F, 0.5880382669F, 0.5899469416F,
  142466. 0.5918534968F, 0.5937578981F, 0.5956601107F, 0.5975601004F,
  142467. 0.5994578326F, 0.6013532732F, 0.6032463880F, 0.6051371429F,
  142468. 0.6070255039F, 0.6089114372F, 0.6107949090F, 0.6126758856F,
  142469. 0.6145543334F, 0.6164302191F, 0.6183035092F, 0.6201741706F,
  142470. 0.6220421700F, 0.6239074745F, 0.6257700513F, 0.6276298674F,
  142471. 0.6294868903F, 0.6313410873F, 0.6331924262F, 0.6350408745F,
  142472. 0.6368864001F, 0.6387289710F, 0.6405685552F, 0.6424051209F,
  142473. 0.6442386364F, 0.6460690702F, 0.6478963910F, 0.6497205673F,
  142474. 0.6515415682F, 0.6533593625F, 0.6551739194F, 0.6569852082F,
  142475. 0.6587931984F, 0.6605978593F, 0.6623991609F, 0.6641970728F,
  142476. 0.6659915652F, 0.6677826081F, 0.6695701718F, 0.6713542268F,
  142477. 0.6731347437F, 0.6749116932F, 0.6766850461F, 0.6784547736F,
  142478. 0.6802208469F, 0.6819832374F, 0.6837419164F, 0.6854968559F,
  142479. 0.6872480275F, 0.6889954034F, 0.6907389556F, 0.6924786566F,
  142480. 0.6942144788F, 0.6959463950F, 0.6976743780F, 0.6993984008F,
  142481. 0.7011184365F, 0.7028344587F, 0.7045464407F, 0.7062543564F,
  142482. 0.7079581796F, 0.7096578844F, 0.7113534450F, 0.7130448359F,
  142483. 0.7147320316F, 0.7164150070F, 0.7180937371F, 0.7197681970F,
  142484. 0.7214383620F, 0.7231042077F, 0.7247657098F, 0.7264228443F,
  142485. 0.7280755871F, 0.7297239147F, 0.7313678035F, 0.7330072301F,
  142486. 0.7346421715F, 0.7362726046F, 0.7378985069F, 0.7395198556F,
  142487. 0.7411366285F, 0.7427488034F, 0.7443563584F, 0.7459592717F,
  142488. 0.7475575218F, 0.7491510873F, 0.7507399471F, 0.7523240803F,
  142489. 0.7539034661F, 0.7554780839F, 0.7570479136F, 0.7586129349F,
  142490. 0.7601731279F, 0.7617284730F, 0.7632789506F, 0.7648245416F,
  142491. 0.7663652267F, 0.7679009872F, 0.7694318044F, 0.7709576599F,
  142492. 0.7724785354F, 0.7739944130F, 0.7755052749F, 0.7770111035F,
  142493. 0.7785118815F, 0.7800075916F, 0.7814982170F, 0.7829837410F,
  142494. 0.7844641472F, 0.7859394191F, 0.7874095408F, 0.7888744965F,
  142495. 0.7903342706F, 0.7917888476F, 0.7932382124F, 0.7946823501F,
  142496. 0.7961212460F, 0.7975548855F, 0.7989832544F, 0.8004063386F,
  142497. 0.8018241244F, 0.8032365981F, 0.8046437463F, 0.8060455560F,
  142498. 0.8074420141F, 0.8088331080F, 0.8102188253F, 0.8115991536F,
  142499. 0.8129740810F, 0.8143435957F, 0.8157076861F, 0.8170663409F,
  142500. 0.8184195489F, 0.8197672994F, 0.8211095817F, 0.8224463853F,
  142501. 0.8237777001F, 0.8251035161F, 0.8264238235F, 0.8277386129F,
  142502. 0.8290478750F, 0.8303516008F, 0.8316497814F, 0.8329424083F,
  142503. 0.8342294731F, 0.8355109677F, 0.8367868841F, 0.8380572148F,
  142504. 0.8393219523F, 0.8405810893F, 0.8418346190F, 0.8430825345F,
  142505. 0.8443248294F, 0.8455614974F, 0.8467925323F, 0.8480179285F,
  142506. 0.8492376802F, 0.8504517822F, 0.8516602292F, 0.8528630164F,
  142507. 0.8540601391F, 0.8552515928F, 0.8564373733F, 0.8576174766F,
  142508. 0.8587918990F, 0.8599606368F, 0.8611236868F, 0.8622810460F,
  142509. 0.8634327113F, 0.8645786802F, 0.8657189504F, 0.8668535195F,
  142510. 0.8679823857F, 0.8691055472F, 0.8702230025F, 0.8713347503F,
  142511. 0.8724407896F, 0.8735411194F, 0.8746357394F, 0.8757246489F,
  142512. 0.8768078479F, 0.8778853364F, 0.8789571146F, 0.8800231832F,
  142513. 0.8810835427F, 0.8821381942F, 0.8831871387F, 0.8842303777F,
  142514. 0.8852679127F, 0.8862997456F, 0.8873258784F, 0.8883463132F,
  142515. 0.8893610527F, 0.8903700994F, 0.8913734562F, 0.8923711263F,
  142516. 0.8933631129F, 0.8943494196F, 0.8953300500F, 0.8963050083F,
  142517. 0.8972742985F, 0.8982379249F, 0.8991958922F, 0.9001482052F,
  142518. 0.9010948688F, 0.9020358883F, 0.9029712690F, 0.9039010165F,
  142519. 0.9048251367F, 0.9057436357F, 0.9066565195F, 0.9075637946F,
  142520. 0.9084654678F, 0.9093615456F, 0.9102520353F, 0.9111369440F,
  142521. 0.9120162792F, 0.9128900484F, 0.9137582595F, 0.9146209204F,
  142522. 0.9154780394F, 0.9163296248F, 0.9171756853F, 0.9180162296F,
  142523. 0.9188512667F, 0.9196808057F, 0.9205048559F, 0.9213234270F,
  142524. 0.9221365285F, 0.9229441704F, 0.9237463629F, 0.9245431160F,
  142525. 0.9253344404F, 0.9261203465F, 0.9269008453F, 0.9276759477F,
  142526. 0.9284456648F, 0.9292100080F, 0.9299689889F, 0.9307226190F,
  142527. 0.9314709103F, 0.9322138747F, 0.9329515245F, 0.9336838721F,
  142528. 0.9344109300F, 0.9351327108F, 0.9358492275F, 0.9365604931F,
  142529. 0.9372665208F, 0.9379673239F, 0.9386629160F, 0.9393533107F,
  142530. 0.9400385220F, 0.9407185637F, 0.9413934501F, 0.9420631954F,
  142531. 0.9427278141F, 0.9433873208F, 0.9440417304F, 0.9446910576F,
  142532. 0.9453353176F, 0.9459745255F, 0.9466086968F, 0.9472378469F,
  142533. 0.9478619915F, 0.9484811463F, 0.9490953274F, 0.9497045506F,
  142534. 0.9503088323F, 0.9509081888F, 0.9515026365F, 0.9520921921F,
  142535. 0.9526768723F, 0.9532566940F, 0.9538316742F, 0.9544018300F,
  142536. 0.9549671786F, 0.9555277375F, 0.9560835241F, 0.9566345562F,
  142537. 0.9571808513F, 0.9577224275F, 0.9582593027F, 0.9587914949F,
  142538. 0.9593190225F, 0.9598419038F, 0.9603601571F, 0.9608738012F,
  142539. 0.9613828546F, 0.9618873361F, 0.9623872646F, 0.9628826591F,
  142540. 0.9633735388F, 0.9638599227F, 0.9643418303F, 0.9648192808F,
  142541. 0.9652922939F, 0.9657608890F, 0.9662250860F, 0.9666849046F,
  142542. 0.9671403646F, 0.9675914861F, 0.9680382891F, 0.9684807937F,
  142543. 0.9689190202F, 0.9693529890F, 0.9697827203F, 0.9702082347F,
  142544. 0.9706295529F, 0.9710466953F, 0.9714596828F, 0.9718685362F,
  142545. 0.9722732762F, 0.9726739240F, 0.9730705005F, 0.9734630267F,
  142546. 0.9738515239F, 0.9742360134F, 0.9746165163F, 0.9749930540F,
  142547. 0.9753656481F, 0.9757343198F, 0.9760990909F, 0.9764599829F,
  142548. 0.9768170175F, 0.9771702164F, 0.9775196013F, 0.9778651941F,
  142549. 0.9782070167F, 0.9785450909F, 0.9788794388F, 0.9792100824F,
  142550. 0.9795370437F, 0.9798603449F, 0.9801800080F, 0.9804960554F,
  142551. 0.9808085092F, 0.9811173916F, 0.9814227251F, 0.9817245318F,
  142552. 0.9820228343F, 0.9823176549F, 0.9826090160F, 0.9828969402F,
  142553. 0.9831814498F, 0.9834625674F, 0.9837403156F, 0.9840147169F,
  142554. 0.9842857939F, 0.9845535692F, 0.9848180654F, 0.9850793052F,
  142555. 0.9853373113F, 0.9855921062F, 0.9858437127F, 0.9860921535F,
  142556. 0.9863374512F, 0.9865796287F, 0.9868187085F, 0.9870547136F,
  142557. 0.9872876664F, 0.9875175899F, 0.9877445067F, 0.9879684396F,
  142558. 0.9881894112F, 0.9884074444F, 0.9886225619F, 0.9888347863F,
  142559. 0.9890441404F, 0.9892506468F, 0.9894543284F, 0.9896552077F,
  142560. 0.9898533074F, 0.9900486502F, 0.9902412587F, 0.9904311555F,
  142561. 0.9906183633F, 0.9908029045F, 0.9909848019F, 0.9911640779F,
  142562. 0.9913407550F, 0.9915148557F, 0.9916864025F, 0.9918554179F,
  142563. 0.9920219241F, 0.9921859437F, 0.9923474989F, 0.9925066120F,
  142564. 0.9926633054F, 0.9928176012F, 0.9929695218F, 0.9931190891F,
  142565. 0.9932663254F, 0.9934112527F, 0.9935538932F, 0.9936942686F,
  142566. 0.9938324012F, 0.9939683126F, 0.9941020248F, 0.9942335597F,
  142567. 0.9943629388F, 0.9944901841F, 0.9946153170F, 0.9947383593F,
  142568. 0.9948593325F, 0.9949782579F, 0.9950951572F, 0.9952100516F,
  142569. 0.9953229625F, 0.9954339111F, 0.9955429186F, 0.9956500062F,
  142570. 0.9957551948F, 0.9958585056F, 0.9959599593F, 0.9960595769F,
  142571. 0.9961573792F, 0.9962533869F, 0.9963476206F, 0.9964401009F,
  142572. 0.9965308483F, 0.9966198833F, 0.9967072261F, 0.9967928971F,
  142573. 0.9968769164F, 0.9969593041F, 0.9970400804F, 0.9971192651F,
  142574. 0.9971968781F, 0.9972729391F, 0.9973474680F, 0.9974204842F,
  142575. 0.9974920074F, 0.9975620569F, 0.9976306521F, 0.9976978122F,
  142576. 0.9977635565F, 0.9978279039F, 0.9978908736F, 0.9979524842F,
  142577. 0.9980127547F, 0.9980717037F, 0.9981293499F, 0.9981857116F,
  142578. 0.9982408073F, 0.9982946554F, 0.9983472739F, 0.9983986810F,
  142579. 0.9984488947F, 0.9984979328F, 0.9985458132F, 0.9985925534F,
  142580. 0.9986381711F, 0.9986826838F, 0.9987261086F, 0.9987684630F,
  142581. 0.9988097640F, 0.9988500286F, 0.9988892738F, 0.9989275163F,
  142582. 0.9989647727F, 0.9990010597F, 0.9990363938F, 0.9990707911F,
  142583. 0.9991042679F, 0.9991368404F, 0.9991685244F, 0.9991993358F,
  142584. 0.9992292905F, 0.9992584038F, 0.9992866914F, 0.9993141686F,
  142585. 0.9993408506F, 0.9993667526F, 0.9993918895F, 0.9994162761F,
  142586. 0.9994399273F, 0.9994628576F, 0.9994850815F, 0.9995066133F,
  142587. 0.9995274672F, 0.9995476574F, 0.9995671978F, 0.9995861021F,
  142588. 0.9996043841F, 0.9996220573F, 0.9996391352F, 0.9996556310F,
  142589. 0.9996715579F, 0.9996869288F, 0.9997017568F, 0.9997160543F,
  142590. 0.9997298342F, 0.9997431088F, 0.9997558905F, 0.9997681914F,
  142591. 0.9997800236F, 0.9997913990F, 0.9998023292F, 0.9998128261F,
  142592. 0.9998229009F, 0.9998325650F, 0.9998418296F, 0.9998507058F,
  142593. 0.9998592044F, 0.9998673362F, 0.9998751117F, 0.9998825415F,
  142594. 0.9998896358F, 0.9998964047F, 0.9999028584F, 0.9999090066F,
  142595. 0.9999148590F, 0.9999204253F, 0.9999257148F, 0.9999307368F,
  142596. 0.9999355003F, 0.9999400144F, 0.9999442878F, 0.9999483293F,
  142597. 0.9999521472F, 0.9999557499F, 0.9999591457F, 0.9999623426F,
  142598. 0.9999653483F, 0.9999681708F, 0.9999708175F, 0.9999732959F,
  142599. 0.9999756132F, 0.9999777765F, 0.9999797928F, 0.9999816688F,
  142600. 0.9999834113F, 0.9999850266F, 0.9999865211F, 0.9999879009F,
  142601. 0.9999891721F, 0.9999903405F, 0.9999914118F, 0.9999923914F,
  142602. 0.9999932849F, 0.9999940972F, 0.9999948336F, 0.9999954989F,
  142603. 0.9999960978F, 0.9999966349F, 0.9999971146F, 0.9999975411F,
  142604. 0.9999979185F, 0.9999982507F, 0.9999985414F, 0.9999987944F,
  142605. 0.9999990129F, 0.9999992003F, 0.9999993596F, 0.9999994939F,
  142606. 0.9999996059F, 0.9999996981F, 0.9999997732F, 0.9999998333F,
  142607. 0.9999998805F, 0.9999999170F, 0.9999999444F, 0.9999999643F,
  142608. 0.9999999784F, 0.9999999878F, 0.9999999937F, 0.9999999972F,
  142609. 0.9999999990F, 0.9999999997F, 1.0000000000F, 1.0000000000F,
  142610. };
  142611. static float vwin4096[2048] = {
  142612. 0.0000002310F, 0.0000020791F, 0.0000057754F, 0.0000113197F,
  142613. 0.0000187121F, 0.0000279526F, 0.0000390412F, 0.0000519777F,
  142614. 0.0000667623F, 0.0000833949F, 0.0001018753F, 0.0001222036F,
  142615. 0.0001443798F, 0.0001684037F, 0.0001942754F, 0.0002219947F,
  142616. 0.0002515616F, 0.0002829761F, 0.0003162380F, 0.0003513472F,
  142617. 0.0003883038F, 0.0004271076F, 0.0004677584F, 0.0005102563F,
  142618. 0.0005546011F, 0.0006007928F, 0.0006488311F, 0.0006987160F,
  142619. 0.0007504474F, 0.0008040251F, 0.0008594490F, 0.0009167191F,
  142620. 0.0009758351F, 0.0010367969F, 0.0010996044F, 0.0011642574F,
  142621. 0.0012307558F, 0.0012990994F, 0.0013692880F, 0.0014413216F,
  142622. 0.0015151998F, 0.0015909226F, 0.0016684898F, 0.0017479011F,
  142623. 0.0018291565F, 0.0019122556F, 0.0019971983F, 0.0020839845F,
  142624. 0.0021726138F, 0.0022630861F, 0.0023554012F, 0.0024495588F,
  142625. 0.0025455588F, 0.0026434008F, 0.0027430847F, 0.0028446103F,
  142626. 0.0029479772F, 0.0030531853F, 0.0031602342F, 0.0032691238F,
  142627. 0.0033798538F, 0.0034924239F, 0.0036068338F, 0.0037230833F,
  142628. 0.0038411721F, 0.0039610999F, 0.0040828664F, 0.0042064714F,
  142629. 0.0043319145F, 0.0044591954F, 0.0045883139F, 0.0047192696F,
  142630. 0.0048520622F, 0.0049866914F, 0.0051231569F, 0.0052614583F,
  142631. 0.0054015953F, 0.0055435676F, 0.0056873748F, 0.0058330166F,
  142632. 0.0059804926F, 0.0061298026F, 0.0062809460F, 0.0064339226F,
  142633. 0.0065887320F, 0.0067453738F, 0.0069038476F, 0.0070641531F,
  142634. 0.0072262899F, 0.0073902575F, 0.0075560556F, 0.0077236838F,
  142635. 0.0078931417F, 0.0080644288F, 0.0082375447F, 0.0084124891F,
  142636. 0.0085892615F, 0.0087678614F, 0.0089482885F, 0.0091305422F,
  142637. 0.0093146223F, 0.0095005281F, 0.0096882592F, 0.0098778153F,
  142638. 0.0100691958F, 0.0102624002F, 0.0104574281F, 0.0106542791F,
  142639. 0.0108529525F, 0.0110534480F, 0.0112557651F, 0.0114599032F,
  142640. 0.0116658618F, 0.0118736405F, 0.0120832387F, 0.0122946560F,
  142641. 0.0125078917F, 0.0127229454F, 0.0129398166F, 0.0131585046F,
  142642. 0.0133790090F, 0.0136013292F, 0.0138254647F, 0.0140514149F,
  142643. 0.0142791792F, 0.0145087572F, 0.0147401481F, 0.0149733515F,
  142644. 0.0152083667F, 0.0154451932F, 0.0156838304F, 0.0159242777F,
  142645. 0.0161665345F, 0.0164106001F, 0.0166564741F, 0.0169041557F,
  142646. 0.0171536443F, 0.0174049393F, 0.0176580401F, 0.0179129461F,
  142647. 0.0181696565F, 0.0184281708F, 0.0186884883F, 0.0189506084F,
  142648. 0.0192145303F, 0.0194802535F, 0.0197477772F, 0.0200171008F,
  142649. 0.0202882236F, 0.0205611449F, 0.0208358639F, 0.0211123801F,
  142650. 0.0213906927F, 0.0216708011F, 0.0219527043F, 0.0222364019F,
  142651. 0.0225218930F, 0.0228091769F, 0.0230982529F, 0.0233891203F,
  142652. 0.0236817782F, 0.0239762259F, 0.0242724628F, 0.0245704880F,
  142653. 0.0248703007F, 0.0251719002F, 0.0254752858F, 0.0257804565F,
  142654. 0.0260874117F, 0.0263961506F, 0.0267066722F, 0.0270189760F,
  142655. 0.0273330609F, 0.0276489263F, 0.0279665712F, 0.0282859949F,
  142656. 0.0286071966F, 0.0289301753F, 0.0292549303F, 0.0295814607F,
  142657. 0.0299097656F, 0.0302398442F, 0.0305716957F, 0.0309053191F,
  142658. 0.0312407135F, 0.0315778782F, 0.0319168122F, 0.0322575145F,
  142659. 0.0325999844F, 0.0329442209F, 0.0332902231F, 0.0336379900F,
  142660. 0.0339875208F, 0.0343388146F, 0.0346918703F, 0.0350466871F,
  142661. 0.0354032640F, 0.0357616000F, 0.0361216943F, 0.0364835458F,
  142662. 0.0368471535F, 0.0372125166F, 0.0375796339F, 0.0379485046F,
  142663. 0.0383191276F, 0.0386915020F, 0.0390656267F, 0.0394415008F,
  142664. 0.0398191231F, 0.0401984927F, 0.0405796086F, 0.0409624698F,
  142665. 0.0413470751F, 0.0417334235F, 0.0421215141F, 0.0425113457F,
  142666. 0.0429029172F, 0.0432962277F, 0.0436912760F, 0.0440880610F,
  142667. 0.0444865817F, 0.0448868370F, 0.0452888257F, 0.0456925468F,
  142668. 0.0460979992F, 0.0465051816F, 0.0469140931F, 0.0473247325F,
  142669. 0.0477370986F, 0.0481511902F, 0.0485670064F, 0.0489845458F,
  142670. 0.0494038074F, 0.0498247899F, 0.0502474922F, 0.0506719131F,
  142671. 0.0510980514F, 0.0515259060F, 0.0519554756F, 0.0523867590F,
  142672. 0.0528197550F, 0.0532544624F, 0.0536908800F, 0.0541290066F,
  142673. 0.0545688408F, 0.0550103815F, 0.0554536274F, 0.0558985772F,
  142674. 0.0563452297F, 0.0567935837F, 0.0572436377F, 0.0576953907F,
  142675. 0.0581488412F, 0.0586039880F, 0.0590608297F, 0.0595193651F,
  142676. 0.0599795929F, 0.0604415117F, 0.0609051202F, 0.0613704170F,
  142677. 0.0618374009F, 0.0623060704F, 0.0627764243F, 0.0632484611F,
  142678. 0.0637221795F, 0.0641975781F, 0.0646746555F, 0.0651534104F,
  142679. 0.0656338413F, 0.0661159469F, 0.0665997257F, 0.0670851763F,
  142680. 0.0675722973F, 0.0680610873F, 0.0685515448F, 0.0690436684F,
  142681. 0.0695374567F, 0.0700329081F, 0.0705300213F, 0.0710287947F,
  142682. 0.0715292269F, 0.0720313163F, 0.0725350616F, 0.0730404612F,
  142683. 0.0735475136F, 0.0740562172F, 0.0745665707F, 0.0750785723F,
  142684. 0.0755922207F, 0.0761075143F, 0.0766244515F, 0.0771430307F,
  142685. 0.0776632505F, 0.0781851092F, 0.0787086052F, 0.0792337371F,
  142686. 0.0797605032F, 0.0802889018F, 0.0808189315F, 0.0813505905F,
  142687. 0.0818838773F, 0.0824187903F, 0.0829553277F, 0.0834934881F,
  142688. 0.0840332697F, 0.0845746708F, 0.0851176899F, 0.0856623252F,
  142689. 0.0862085751F, 0.0867564379F, 0.0873059119F, 0.0878569954F,
  142690. 0.0884096867F, 0.0889639840F, 0.0895198858F, 0.0900773902F,
  142691. 0.0906364955F, 0.0911972000F, 0.0917595019F, 0.0923233995F,
  142692. 0.0928888909F, 0.0934559745F, 0.0940246485F, 0.0945949110F,
  142693. 0.0951667604F, 0.0957401946F, 0.0963152121F, 0.0968918109F,
  142694. 0.0974699893F, 0.0980497454F, 0.0986310773F, 0.0992139832F,
  142695. 0.0997984614F, 0.1003845098F, 0.1009721267F, 0.1015613101F,
  142696. 0.1021520582F, 0.1027443692F, 0.1033382410F, 0.1039336718F,
  142697. 0.1045306597F, 0.1051292027F, 0.1057292990F, 0.1063309466F,
  142698. 0.1069341435F, 0.1075388878F, 0.1081451776F, 0.1087530108F,
  142699. 0.1093623856F, 0.1099732998F, 0.1105857516F, 0.1111997389F,
  142700. 0.1118152597F, 0.1124323121F, 0.1130508939F, 0.1136710032F,
  142701. 0.1142926379F, 0.1149157960F, 0.1155404755F, 0.1161666742F,
  142702. 0.1167943901F, 0.1174236211F, 0.1180543652F, 0.1186866202F,
  142703. 0.1193203841F, 0.1199556548F, 0.1205924300F, 0.1212307078F,
  142704. 0.1218704860F, 0.1225117624F, 0.1231545349F, 0.1237988013F,
  142705. 0.1244445596F, 0.1250918074F, 0.1257405427F, 0.1263907632F,
  142706. 0.1270424667F, 0.1276956512F, 0.1283503142F, 0.1290064537F,
  142707. 0.1296640674F, 0.1303231530F, 0.1309837084F, 0.1316457312F,
  142708. 0.1323092193F, 0.1329741703F, 0.1336405820F, 0.1343084520F,
  142709. 0.1349777782F, 0.1356485582F, 0.1363207897F, 0.1369944704F,
  142710. 0.1376695979F, 0.1383461700F, 0.1390241842F, 0.1397036384F,
  142711. 0.1403845300F, 0.1410668567F, 0.1417506162F, 0.1424358061F,
  142712. 0.1431224240F, 0.1438104674F, 0.1444999341F, 0.1451908216F,
  142713. 0.1458831274F, 0.1465768492F, 0.1472719844F, 0.1479685308F,
  142714. 0.1486664857F, 0.1493658468F, 0.1500666115F, 0.1507687775F,
  142715. 0.1514723422F, 0.1521773031F, 0.1528836577F, 0.1535914035F,
  142716. 0.1543005380F, 0.1550110587F, 0.1557229631F, 0.1564362485F,
  142717. 0.1571509124F, 0.1578669524F, 0.1585843657F, 0.1593031499F,
  142718. 0.1600233024F, 0.1607448205F, 0.1614677017F, 0.1621919433F,
  142719. 0.1629175428F, 0.1636444975F, 0.1643728047F, 0.1651024619F,
  142720. 0.1658334665F, 0.1665658156F, 0.1672995067F, 0.1680345371F,
  142721. 0.1687709041F, 0.1695086050F, 0.1702476372F, 0.1709879978F,
  142722. 0.1717296843F, 0.1724726938F, 0.1732170237F, 0.1739626711F,
  142723. 0.1747096335F, 0.1754579079F, 0.1762074916F, 0.1769583819F,
  142724. 0.1777105760F, 0.1784640710F, 0.1792188642F, 0.1799749529F,
  142725. 0.1807323340F, 0.1814910049F, 0.1822509628F, 0.1830122046F,
  142726. 0.1837747277F, 0.1845385292F, 0.1853036062F, 0.1860699558F,
  142727. 0.1868375751F, 0.1876064613F, 0.1883766114F, 0.1891480226F,
  142728. 0.1899206919F, 0.1906946164F, 0.1914697932F, 0.1922462194F,
  142729. 0.1930238919F, 0.1938028079F, 0.1945829643F, 0.1953643583F,
  142730. 0.1961469868F, 0.1969308468F, 0.1977159353F, 0.1985022494F,
  142731. 0.1992897859F, 0.2000785420F, 0.2008685145F, 0.2016597005F,
  142732. 0.2024520968F, 0.2032457005F, 0.2040405084F, 0.2048365175F,
  142733. 0.2056337247F, 0.2064321269F, 0.2072317211F, 0.2080325041F,
  142734. 0.2088344727F, 0.2096376240F, 0.2104419547F, 0.2112474618F,
  142735. 0.2120541420F, 0.2128619923F, 0.2136710094F, 0.2144811902F,
  142736. 0.2152925315F, 0.2161050301F, 0.2169186829F, 0.2177334866F,
  142737. 0.2185494381F, 0.2193665340F, 0.2201847712F, 0.2210041465F,
  142738. 0.2218246565F, 0.2226462981F, 0.2234690680F, 0.2242929629F,
  142739. 0.2251179796F, 0.2259441147F, 0.2267713650F, 0.2275997272F,
  142740. 0.2284291979F, 0.2292597739F, 0.2300914518F, 0.2309242283F,
  142741. 0.2317581001F, 0.2325930638F, 0.2334291160F, 0.2342662534F,
  142742. 0.2351044727F, 0.2359437703F, 0.2367841431F, 0.2376255875F,
  142743. 0.2384681001F, 0.2393116776F, 0.2401563165F, 0.2410020134F,
  142744. 0.2418487649F, 0.2426965675F, 0.2435454178F, 0.2443953122F,
  142745. 0.2452462474F, 0.2460982199F, 0.2469512262F, 0.2478052628F,
  142746. 0.2486603262F, 0.2495164129F, 0.2503735194F, 0.2512316421F,
  142747. 0.2520907776F, 0.2529509222F, 0.2538120726F, 0.2546742250F,
  142748. 0.2555373760F, 0.2564015219F, 0.2572666593F, 0.2581327845F,
  142749. 0.2589998939F, 0.2598679840F, 0.2607370510F, 0.2616070916F,
  142750. 0.2624781019F, 0.2633500783F, 0.2642230173F, 0.2650969152F,
  142751. 0.2659717684F, 0.2668475731F, 0.2677243257F, 0.2686020226F,
  142752. 0.2694806601F, 0.2703602344F, 0.2712407419F, 0.2721221789F,
  142753. 0.2730045417F, 0.2738878265F, 0.2747720297F, 0.2756571474F,
  142754. 0.2765431760F, 0.2774301117F, 0.2783179508F, 0.2792066895F,
  142755. 0.2800963240F, 0.2809868505F, 0.2818782654F, 0.2827705647F,
  142756. 0.2836637447F, 0.2845578016F, 0.2854527315F, 0.2863485307F,
  142757. 0.2872451953F, 0.2881427215F, 0.2890411055F, 0.2899403433F,
  142758. 0.2908404312F, 0.2917413654F, 0.2926431418F, 0.2935457567F,
  142759. 0.2944492061F, 0.2953534863F, 0.2962585932F, 0.2971645230F,
  142760. 0.2980712717F, 0.2989788356F, 0.2998872105F, 0.3007963927F,
  142761. 0.3017063781F, 0.3026171629F, 0.3035287430F, 0.3044411145F,
  142762. 0.3053542736F, 0.3062682161F, 0.3071829381F, 0.3080984356F,
  142763. 0.3090147047F, 0.3099317413F, 0.3108495414F, 0.3117681011F,
  142764. 0.3126874163F, 0.3136074830F, 0.3145282972F, 0.3154498548F,
  142765. 0.3163721517F, 0.3172951841F, 0.3182189477F, 0.3191434385F,
  142766. 0.3200686525F, 0.3209945856F, 0.3219212336F, 0.3228485927F,
  142767. 0.3237766585F, 0.3247054271F, 0.3256348943F, 0.3265650560F,
  142768. 0.3274959081F, 0.3284274465F, 0.3293596671F, 0.3302925657F,
  142769. 0.3312261382F, 0.3321603804F, 0.3330952882F, 0.3340308574F,
  142770. 0.3349670838F, 0.3359039634F, 0.3368414919F, 0.3377796651F,
  142771. 0.3387184789F, 0.3396579290F, 0.3405980113F, 0.3415387216F,
  142772. 0.3424800556F, 0.3434220091F, 0.3443645779F, 0.3453077578F,
  142773. 0.3462515446F, 0.3471959340F, 0.3481409217F, 0.3490865036F,
  142774. 0.3500326754F, 0.3509794328F, 0.3519267715F, 0.3528746873F,
  142775. 0.3538231759F, 0.3547722330F, 0.3557218544F, 0.3566720357F,
  142776. 0.3576227727F, 0.3585740610F, 0.3595258964F, 0.3604782745F,
  142777. 0.3614311910F, 0.3623846417F, 0.3633386221F, 0.3642931280F,
  142778. 0.3652481549F, 0.3662036987F, 0.3671597548F, 0.3681163191F,
  142779. 0.3690733870F, 0.3700309544F, 0.3709890167F, 0.3719475696F,
  142780. 0.3729066089F, 0.3738661299F, 0.3748261285F, 0.3757866002F,
  142781. 0.3767475406F, 0.3777089453F, 0.3786708100F, 0.3796331302F,
  142782. 0.3805959014F, 0.3815591194F, 0.3825227796F, 0.3834868777F,
  142783. 0.3844514093F, 0.3854163698F, 0.3863817549F, 0.3873475601F,
  142784. 0.3883137810F, 0.3892804131F, 0.3902474521F, 0.3912148933F,
  142785. 0.3921827325F, 0.3931509650F, 0.3941195865F, 0.3950885925F,
  142786. 0.3960579785F, 0.3970277400F, 0.3979978725F, 0.3989683716F,
  142787. 0.3999392328F, 0.4009104516F, 0.4018820234F, 0.4028539438F,
  142788. 0.4038262084F, 0.4047988125F, 0.4057717516F, 0.4067450214F,
  142789. 0.4077186172F, 0.4086925345F, 0.4096667688F, 0.4106413155F,
  142790. 0.4116161703F, 0.4125913284F, 0.4135667854F, 0.4145425368F,
  142791. 0.4155185780F, 0.4164949044F, 0.4174715116F, 0.4184483949F,
  142792. 0.4194255498F, 0.4204029718F, 0.4213806563F, 0.4223585987F,
  142793. 0.4233367946F, 0.4243152392F, 0.4252939281F, 0.4262728566F,
  142794. 0.4272520202F, 0.4282314144F, 0.4292110345F, 0.4301908760F,
  142795. 0.4311709343F, 0.4321512047F, 0.4331316828F, 0.4341123639F,
  142796. 0.4350932435F, 0.4360743168F, 0.4370555794F, 0.4380370267F,
  142797. 0.4390186540F, 0.4400004567F, 0.4409824303F, 0.4419645701F,
  142798. 0.4429468716F, 0.4439293300F, 0.4449119409F, 0.4458946996F,
  142799. 0.4468776014F, 0.4478606418F, 0.4488438162F, 0.4498271199F,
  142800. 0.4508105483F, 0.4517940967F, 0.4527777607F, 0.4537615355F,
  142801. 0.4547454165F, 0.4557293991F, 0.4567134786F, 0.4576976505F,
  142802. 0.4586819101F, 0.4596662527F, 0.4606506738F, 0.4616351687F,
  142803. 0.4626197328F, 0.4636043614F, 0.4645890499F, 0.4655737936F,
  142804. 0.4665585880F, 0.4675434284F, 0.4685283101F, 0.4695132286F,
  142805. 0.4704981791F, 0.4714831570F, 0.4724681577F, 0.4734531766F,
  142806. 0.4744382089F, 0.4754232501F, 0.4764082956F, 0.4773933406F,
  142807. 0.4783783806F, 0.4793634108F, 0.4803484267F, 0.4813334237F,
  142808. 0.4823183969F, 0.4833033419F, 0.4842882540F, 0.4852731285F,
  142809. 0.4862579608F, 0.4872427462F, 0.4882274802F, 0.4892121580F,
  142810. 0.4901967751F, 0.4911813267F, 0.4921658083F, 0.4931502151F,
  142811. 0.4941345427F, 0.4951187863F, 0.4961029412F, 0.4970870029F,
  142812. 0.4980709667F, 0.4990548280F, 0.5000385822F, 0.5010222245F,
  142813. 0.5020057505F, 0.5029891553F, 0.5039724345F, 0.5049555834F,
  142814. 0.5059385973F, 0.5069214716F, 0.5079042018F, 0.5088867831F,
  142815. 0.5098692110F, 0.5108514808F, 0.5118335879F, 0.5128155277F,
  142816. 0.5137972956F, 0.5147788869F, 0.5157602971F, 0.5167415215F,
  142817. 0.5177225555F, 0.5187033945F, 0.5196840339F, 0.5206644692F,
  142818. 0.5216446956F, 0.5226247086F, 0.5236045035F, 0.5245840759F,
  142819. 0.5255634211F, 0.5265425344F, 0.5275214114F, 0.5285000474F,
  142820. 0.5294784378F, 0.5304565781F, 0.5314344637F, 0.5324120899F,
  142821. 0.5333894522F, 0.5343665461F, 0.5353433670F, 0.5363199102F,
  142822. 0.5372961713F, 0.5382721457F, 0.5392478287F, 0.5402232159F,
  142823. 0.5411983027F, 0.5421730845F, 0.5431475569F, 0.5441217151F,
  142824. 0.5450955548F, 0.5460690714F, 0.5470422602F, 0.5480151169F,
  142825. 0.5489876368F, 0.5499598155F, 0.5509316484F, 0.5519031310F,
  142826. 0.5528742587F, 0.5538450271F, 0.5548154317F, 0.5557854680F,
  142827. 0.5567551314F, 0.5577244174F, 0.5586933216F, 0.5596618395F,
  142828. 0.5606299665F, 0.5615976983F, 0.5625650302F, 0.5635319580F,
  142829. 0.5644984770F, 0.5654645828F, 0.5664302709F, 0.5673955370F,
  142830. 0.5683603765F, 0.5693247850F, 0.5702887580F, 0.5712522912F,
  142831. 0.5722153800F, 0.5731780200F, 0.5741402069F, 0.5751019362F,
  142832. 0.5760632034F, 0.5770240042F, 0.5779843341F, 0.5789441889F,
  142833. 0.5799035639F, 0.5808624549F, 0.5818208575F, 0.5827787673F,
  142834. 0.5837361800F, 0.5846930910F, 0.5856494961F, 0.5866053910F,
  142835. 0.5875607712F, 0.5885156324F, 0.5894699703F, 0.5904237804F,
  142836. 0.5913770586F, 0.5923298004F, 0.5932820016F, 0.5942336578F,
  142837. 0.5951847646F, 0.5961353179F, 0.5970853132F, 0.5980347464F,
  142838. 0.5989836131F, 0.5999319090F, 0.6008796298F, 0.6018267713F,
  142839. 0.6027733292F, 0.6037192993F, 0.6046646773F, 0.6056094589F,
  142840. 0.6065536400F, 0.6074972162F, 0.6084401833F, 0.6093825372F,
  142841. 0.6103242736F, 0.6112653884F, 0.6122058772F, 0.6131457359F,
  142842. 0.6140849604F, 0.6150235464F, 0.6159614897F, 0.6168987862F,
  142843. 0.6178354318F, 0.6187714223F, 0.6197067535F, 0.6206414213F,
  142844. 0.6215754215F, 0.6225087501F, 0.6234414028F, 0.6243733757F,
  142845. 0.6253046646F, 0.6262352654F, 0.6271651739F, 0.6280943862F,
  142846. 0.6290228982F, 0.6299507057F, 0.6308778048F, 0.6318041913F,
  142847. 0.6327298612F, 0.6336548105F, 0.6345790352F, 0.6355025312F,
  142848. 0.6364252945F, 0.6373473211F, 0.6382686070F, 0.6391891483F,
  142849. 0.6401089409F, 0.6410279808F, 0.6419462642F, 0.6428637869F,
  142850. 0.6437805452F, 0.6446965350F, 0.6456117524F, 0.6465261935F,
  142851. 0.6474398544F, 0.6483527311F, 0.6492648197F, 0.6501761165F,
  142852. 0.6510866174F, 0.6519963186F, 0.6529052162F, 0.6538133064F,
  142853. 0.6547205854F, 0.6556270492F, 0.6565326941F, 0.6574375162F,
  142854. 0.6583415117F, 0.6592446769F, 0.6601470079F, 0.6610485009F,
  142855. 0.6619491521F, 0.6628489578F, 0.6637479143F, 0.6646460177F,
  142856. 0.6655432643F, 0.6664396505F, 0.6673351724F, 0.6682298264F,
  142857. 0.6691236087F, 0.6700165157F, 0.6709085436F, 0.6717996889F,
  142858. 0.6726899478F, 0.6735793167F, 0.6744677918F, 0.6753553697F,
  142859. 0.6762420466F, 0.6771278190F, 0.6780126832F, 0.6788966357F,
  142860. 0.6797796728F, 0.6806617909F, 0.6815429866F, 0.6824232562F,
  142861. 0.6833025961F, 0.6841810030F, 0.6850584731F, 0.6859350031F,
  142862. 0.6868105894F, 0.6876852284F, 0.6885589168F, 0.6894316510F,
  142863. 0.6903034275F, 0.6911742430F, 0.6920440939F, 0.6929129769F,
  142864. 0.6937808884F, 0.6946478251F, 0.6955137837F, 0.6963787606F,
  142865. 0.6972427525F, 0.6981057560F, 0.6989677678F, 0.6998287845F,
  142866. 0.7006888028F, 0.7015478194F, 0.7024058309F, 0.7032628340F,
  142867. 0.7041188254F, 0.7049738019F, 0.7058277601F, 0.7066806969F,
  142868. 0.7075326089F, 0.7083834929F, 0.7092333457F, 0.7100821640F,
  142869. 0.7109299447F, 0.7117766846F, 0.7126223804F, 0.7134670291F,
  142870. 0.7143106273F, 0.7151531721F, 0.7159946602F, 0.7168350885F,
  142871. 0.7176744539F, 0.7185127534F, 0.7193499837F, 0.7201861418F,
  142872. 0.7210212247F, 0.7218552293F, 0.7226881526F, 0.7235199914F,
  142873. 0.7243507428F, 0.7251804039F, 0.7260089715F, 0.7268364426F,
  142874. 0.7276628144F, 0.7284880839F, 0.7293122481F, 0.7301353040F,
  142875. 0.7309572487F, 0.7317780794F, 0.7325977930F, 0.7334163868F,
  142876. 0.7342338579F, 0.7350502033F, 0.7358654202F, 0.7366795059F,
  142877. 0.7374924573F, 0.7383042718F, 0.7391149465F, 0.7399244787F,
  142878. 0.7407328655F, 0.7415401041F, 0.7423461920F, 0.7431511261F,
  142879. 0.7439549040F, 0.7447575227F, 0.7455589797F, 0.7463592723F,
  142880. 0.7471583976F, 0.7479563532F, 0.7487531363F, 0.7495487443F,
  142881. 0.7503431745F, 0.7511364244F, 0.7519284913F, 0.7527193726F,
  142882. 0.7535090658F, 0.7542975683F, 0.7550848776F, 0.7558709910F,
  142883. 0.7566559062F, 0.7574396205F, 0.7582221314F, 0.7590034366F,
  142884. 0.7597835334F, 0.7605624194F, 0.7613400923F, 0.7621165495F,
  142885. 0.7628917886F, 0.7636658072F, 0.7644386030F, 0.7652101735F,
  142886. 0.7659805164F, 0.7667496292F, 0.7675175098F, 0.7682841556F,
  142887. 0.7690495645F, 0.7698137341F, 0.7705766622F, 0.7713383463F,
  142888. 0.7720987844F, 0.7728579741F, 0.7736159132F, 0.7743725994F,
  142889. 0.7751280306F, 0.7758822046F, 0.7766351192F, 0.7773867722F,
  142890. 0.7781371614F, 0.7788862848F, 0.7796341401F, 0.7803807253F,
  142891. 0.7811260383F, 0.7818700769F, 0.7826128392F, 0.7833543230F,
  142892. 0.7840945263F, 0.7848334471F, 0.7855710833F, 0.7863074330F,
  142893. 0.7870424941F, 0.7877762647F, 0.7885087428F, 0.7892399264F,
  142894. 0.7899698137F, 0.7906984026F, 0.7914256914F, 0.7921516780F,
  142895. 0.7928763607F, 0.7935997375F, 0.7943218065F, 0.7950425661F,
  142896. 0.7957620142F, 0.7964801492F, 0.7971969692F, 0.7979124724F,
  142897. 0.7986266570F, 0.7993395214F, 0.8000510638F, 0.8007612823F,
  142898. 0.8014701754F, 0.8021777413F, 0.8028839784F, 0.8035888849F,
  142899. 0.8042924592F, 0.8049946997F, 0.8056956048F, 0.8063951727F,
  142900. 0.8070934020F, 0.8077902910F, 0.8084858381F, 0.8091800419F,
  142901. 0.8098729007F, 0.8105644130F, 0.8112545774F, 0.8119433922F,
  142902. 0.8126308561F, 0.8133169676F, 0.8140017251F, 0.8146851272F,
  142903. 0.8153671726F, 0.8160478598F, 0.8167271874F, 0.8174051539F,
  142904. 0.8180817582F, 0.8187569986F, 0.8194308741F, 0.8201033831F,
  142905. 0.8207745244F, 0.8214442966F, 0.8221126986F, 0.8227797290F,
  142906. 0.8234453865F, 0.8241096700F, 0.8247725781F, 0.8254341097F,
  142907. 0.8260942636F, 0.8267530385F, 0.8274104334F, 0.8280664470F,
  142908. 0.8287210782F, 0.8293743259F, 0.8300261889F, 0.8306766662F,
  142909. 0.8313257566F, 0.8319734591F, 0.8326197727F, 0.8332646963F,
  142910. 0.8339082288F, 0.8345503692F, 0.8351911167F, 0.8358304700F,
  142911. 0.8364684284F, 0.8371049907F, 0.8377401562F, 0.8383739238F,
  142912. 0.8390062927F, 0.8396372618F, 0.8402668305F, 0.8408949977F,
  142913. 0.8415217626F, 0.8421471245F, 0.8427710823F, 0.8433936354F,
  142914. 0.8440147830F, 0.8446345242F, 0.8452528582F, 0.8458697844F,
  142915. 0.8464853020F, 0.8470994102F, 0.8477121084F, 0.8483233958F,
  142916. 0.8489332718F, 0.8495417356F, 0.8501487866F, 0.8507544243F,
  142917. 0.8513586479F, 0.8519614568F, 0.8525628505F, 0.8531628283F,
  142918. 0.8537613897F, 0.8543585341F, 0.8549542611F, 0.8555485699F,
  142919. 0.8561414603F, 0.8567329315F, 0.8573229832F, 0.8579116149F,
  142920. 0.8584988262F, 0.8590846165F, 0.8596689855F, 0.8602519327F,
  142921. 0.8608334577F, 0.8614135603F, 0.8619922399F, 0.8625694962F,
  142922. 0.8631453289F, 0.8637197377F, 0.8642927222F, 0.8648642821F,
  142923. 0.8654344172F, 0.8660031272F, 0.8665704118F, 0.8671362708F,
  142924. 0.8677007039F, 0.8682637109F, 0.8688252917F, 0.8693854460F,
  142925. 0.8699441737F, 0.8705014745F, 0.8710573485F, 0.8716117953F,
  142926. 0.8721648150F, 0.8727164073F, 0.8732665723F, 0.8738153098F,
  142927. 0.8743626197F, 0.8749085021F, 0.8754529569F, 0.8759959840F,
  142928. 0.8765375835F, 0.8770777553F, 0.8776164996F, 0.8781538162F,
  142929. 0.8786897054F, 0.8792241670F, 0.8797572013F, 0.8802888082F,
  142930. 0.8808189880F, 0.8813477407F, 0.8818750664F, 0.8824009653F,
  142931. 0.8829254375F, 0.8834484833F, 0.8839701028F, 0.8844902961F,
  142932. 0.8850090636F, 0.8855264054F, 0.8860423218F, 0.8865568131F,
  142933. 0.8870698794F, 0.8875815212F, 0.8880917386F, 0.8886005319F,
  142934. 0.8891079016F, 0.8896138479F, 0.8901183712F, 0.8906214719F,
  142935. 0.8911231503F, 0.8916234067F, 0.8921222417F, 0.8926196556F,
  142936. 0.8931156489F, 0.8936102219F, 0.8941033752F, 0.8945951092F,
  142937. 0.8950854244F, 0.8955743212F, 0.8960618003F, 0.8965478621F,
  142938. 0.8970325071F, 0.8975157359F, 0.8979975490F, 0.8984779471F,
  142939. 0.8989569307F, 0.8994345004F, 0.8999106568F, 0.9003854005F,
  142940. 0.9008587323F, 0.9013306526F, 0.9018011623F, 0.9022702619F,
  142941. 0.9027379521F, 0.9032042337F, 0.9036691074F, 0.9041325739F,
  142942. 0.9045946339F, 0.9050552882F, 0.9055145376F, 0.9059723828F,
  142943. 0.9064288246F, 0.9068838638F, 0.9073375013F, 0.9077897379F,
  142944. 0.9082405743F, 0.9086900115F, 0.9091380503F, 0.9095846917F,
  142945. 0.9100299364F, 0.9104737854F, 0.9109162397F, 0.9113573001F,
  142946. 0.9117969675F, 0.9122352430F, 0.9126721275F, 0.9131076219F,
  142947. 0.9135417273F, 0.9139744447F, 0.9144057750F, 0.9148357194F,
  142948. 0.9152642787F, 0.9156914542F, 0.9161172468F, 0.9165416576F,
  142949. 0.9169646877F, 0.9173863382F, 0.9178066102F, 0.9182255048F,
  142950. 0.9186430232F, 0.9190591665F, 0.9194739359F, 0.9198873324F,
  142951. 0.9202993574F, 0.9207100120F, 0.9211192973F, 0.9215272147F,
  142952. 0.9219337653F, 0.9223389504F, 0.9227427713F, 0.9231452290F,
  142953. 0.9235463251F, 0.9239460607F, 0.9243444371F, 0.9247414557F,
  142954. 0.9251371177F, 0.9255314245F, 0.9259243774F, 0.9263159778F,
  142955. 0.9267062270F, 0.9270951264F, 0.9274826774F, 0.9278688814F,
  142956. 0.9282537398F, 0.9286372540F, 0.9290194254F, 0.9294002555F,
  142957. 0.9297797458F, 0.9301578976F, 0.9305347125F, 0.9309101919F,
  142958. 0.9312843373F, 0.9316571503F, 0.9320286323F, 0.9323987849F,
  142959. 0.9327676097F, 0.9331351080F, 0.9335012816F, 0.9338661320F,
  142960. 0.9342296607F, 0.9345918694F, 0.9349527596F, 0.9353123330F,
  142961. 0.9356705911F, 0.9360275357F, 0.9363831683F, 0.9367374905F,
  142962. 0.9370905042F, 0.9374422108F, 0.9377926122F, 0.9381417099F,
  142963. 0.9384895057F, 0.9388360014F, 0.9391811985F, 0.9395250989F,
  142964. 0.9398677043F, 0.9402090165F, 0.9405490371F, 0.9408877680F,
  142965. 0.9412252110F, 0.9415613678F, 0.9418962402F, 0.9422298301F,
  142966. 0.9425621392F, 0.9428931695F, 0.9432229226F, 0.9435514005F,
  142967. 0.9438786050F, 0.9442045381F, 0.9445292014F, 0.9448525971F,
  142968. 0.9451747268F, 0.9454955926F, 0.9458151963F, 0.9461335399F,
  142969. 0.9464506253F, 0.9467664545F, 0.9470810293F, 0.9473943517F,
  142970. 0.9477064238F, 0.9480172474F, 0.9483268246F, 0.9486351573F,
  142971. 0.9489422475F, 0.9492480973F, 0.9495527087F, 0.9498560837F,
  142972. 0.9501582243F, 0.9504591325F, 0.9507588105F, 0.9510572603F,
  142973. 0.9513544839F, 0.9516504834F, 0.9519452609F, 0.9522388186F,
  142974. 0.9525311584F, 0.9528222826F, 0.9531121932F, 0.9534008923F,
  142975. 0.9536883821F, 0.9539746647F, 0.9542597424F, 0.9545436171F,
  142976. 0.9548262912F, 0.9551077667F, 0.9553880459F, 0.9556671309F,
  142977. 0.9559450239F, 0.9562217272F, 0.9564972429F, 0.9567715733F,
  142978. 0.9570447206F, 0.9573166871F, 0.9575874749F, 0.9578570863F,
  142979. 0.9581255236F, 0.9583927890F, 0.9586588849F, 0.9589238134F,
  142980. 0.9591875769F, 0.9594501777F, 0.9597116180F, 0.9599719003F,
  142981. 0.9602310267F, 0.9604889995F, 0.9607458213F, 0.9610014942F,
  142982. 0.9612560206F, 0.9615094028F, 0.9617616433F, 0.9620127443F,
  142983. 0.9622627083F, 0.9625115376F, 0.9627592345F, 0.9630058016F,
  142984. 0.9632512411F, 0.9634955555F, 0.9637387471F, 0.9639808185F,
  142985. 0.9642217720F, 0.9644616100F, 0.9647003349F, 0.9649379493F,
  142986. 0.9651744556F, 0.9654098561F, 0.9656441534F, 0.9658773499F,
  142987. 0.9661094480F, 0.9663404504F, 0.9665703593F, 0.9667991774F,
  142988. 0.9670269071F, 0.9672535509F, 0.9674791114F, 0.9677035909F,
  142989. 0.9679269921F, 0.9681493174F, 0.9683705694F, 0.9685907506F,
  142990. 0.9688098636F, 0.9690279108F, 0.9692448948F, 0.9694608182F,
  142991. 0.9696756836F, 0.9698894934F, 0.9701022503F, 0.9703139569F,
  142992. 0.9705246156F, 0.9707342291F, 0.9709428000F, 0.9711503309F,
  142993. 0.9713568243F, 0.9715622829F, 0.9717667093F, 0.9719701060F,
  142994. 0.9721724757F, 0.9723738210F, 0.9725741446F, 0.9727734490F,
  142995. 0.9729717369F, 0.9731690109F, 0.9733652737F, 0.9735605279F,
  142996. 0.9737547762F, 0.9739480212F, 0.9741402656F, 0.9743315120F,
  142997. 0.9745217631F, 0.9747110216F, 0.9748992901F, 0.9750865714F,
  142998. 0.9752728681F, 0.9754581829F, 0.9756425184F, 0.9758258775F,
  142999. 0.9760082627F, 0.9761896768F, 0.9763701224F, 0.9765496024F,
  143000. 0.9767281193F, 0.9769056760F, 0.9770822751F, 0.9772579193F,
  143001. 0.9774326114F, 0.9776063542F, 0.9777791502F, 0.9779510023F,
  143002. 0.9781219133F, 0.9782918858F, 0.9784609226F, 0.9786290264F,
  143003. 0.9787962000F, 0.9789624461F, 0.9791277676F, 0.9792921671F,
  143004. 0.9794556474F, 0.9796182113F, 0.9797798615F, 0.9799406009F,
  143005. 0.9801004321F, 0.9802593580F, 0.9804173813F, 0.9805745049F,
  143006. 0.9807307314F, 0.9808860637F, 0.9810405046F, 0.9811940568F,
  143007. 0.9813467232F, 0.9814985065F, 0.9816494095F, 0.9817994351F,
  143008. 0.9819485860F, 0.9820968650F, 0.9822442750F, 0.9823908186F,
  143009. 0.9825364988F, 0.9826813184F, 0.9828252801F, 0.9829683868F,
  143010. 0.9831106413F, 0.9832520463F, 0.9833926048F, 0.9835323195F,
  143011. 0.9836711932F, 0.9838092288F, 0.9839464291F, 0.9840827969F,
  143012. 0.9842183351F, 0.9843530464F, 0.9844869337F, 0.9846199998F,
  143013. 0.9847522475F, 0.9848836798F, 0.9850142993F, 0.9851441090F,
  143014. 0.9852731117F, 0.9854013101F, 0.9855287073F, 0.9856553058F,
  143015. 0.9857811087F, 0.9859061188F, 0.9860303388F, 0.9861537717F,
  143016. 0.9862764202F, 0.9863982872F, 0.9865193756F, 0.9866396882F,
  143017. 0.9867592277F, 0.9868779972F, 0.9869959993F, 0.9871132370F,
  143018. 0.9872297131F, 0.9873454304F, 0.9874603918F, 0.9875746001F,
  143019. 0.9876880581F, 0.9878007688F, 0.9879127348F, 0.9880239592F,
  143020. 0.9881344447F, 0.9882441941F, 0.9883532104F, 0.9884614962F,
  143021. 0.9885690546F, 0.9886758883F, 0.9887820001F, 0.9888873930F,
  143022. 0.9889920697F, 0.9890960331F, 0.9891992859F, 0.9893018312F,
  143023. 0.9894036716F, 0.9895048100F, 0.9896052493F, 0.9897049923F,
  143024. 0.9898040418F, 0.9899024006F, 0.9900000717F, 0.9900970577F,
  143025. 0.9901933616F, 0.9902889862F, 0.9903839343F, 0.9904782087F,
  143026. 0.9905718122F, 0.9906647477F, 0.9907570180F, 0.9908486259F,
  143027. 0.9909395742F, 0.9910298658F, 0.9911195034F, 0.9912084899F,
  143028. 0.9912968281F, 0.9913845208F, 0.9914715708F, 0.9915579810F,
  143029. 0.9916437540F, 0.9917288928F, 0.9918134001F, 0.9918972788F,
  143030. 0.9919805316F, 0.9920631613F, 0.9921451707F, 0.9922265626F,
  143031. 0.9923073399F, 0.9923875052F, 0.9924670615F, 0.9925460114F,
  143032. 0.9926243577F, 0.9927021033F, 0.9927792508F, 0.9928558032F,
  143033. 0.9929317631F, 0.9930071333F, 0.9930819167F, 0.9931561158F,
  143034. 0.9932297337F, 0.9933027728F, 0.9933752362F, 0.9934471264F,
  143035. 0.9935184462F, 0.9935891985F, 0.9936593859F, 0.9937290112F,
  143036. 0.9937980771F, 0.9938665864F, 0.9939345418F, 0.9940019460F,
  143037. 0.9940688018F, 0.9941351118F, 0.9942008789F, 0.9942661057F,
  143038. 0.9943307950F, 0.9943949494F, 0.9944585717F, 0.9945216645F,
  143039. 0.9945842307F, 0.9946462728F, 0.9947077936F, 0.9947687957F,
  143040. 0.9948292820F, 0.9948892550F, 0.9949487174F, 0.9950076719F,
  143041. 0.9950661212F, 0.9951240679F, 0.9951815148F, 0.9952384645F,
  143042. 0.9952949196F, 0.9953508828F, 0.9954063568F, 0.9954613442F,
  143043. 0.9955158476F, 0.9955698697F, 0.9956234132F, 0.9956764806F,
  143044. 0.9957290746F, 0.9957811978F, 0.9958328528F, 0.9958840423F,
  143045. 0.9959347688F, 0.9959850351F, 0.9960348435F, 0.9960841969F,
  143046. 0.9961330977F, 0.9961815486F, 0.9962295521F, 0.9962771108F,
  143047. 0.9963242274F, 0.9963709043F, 0.9964171441F, 0.9964629494F,
  143048. 0.9965083228F, 0.9965532668F, 0.9965977840F, 0.9966418768F,
  143049. 0.9966855479F, 0.9967287998F, 0.9967716350F, 0.9968140559F,
  143050. 0.9968560653F, 0.9968976655F, 0.9969388591F, 0.9969796485F,
  143051. 0.9970200363F, 0.9970600250F, 0.9970996170F, 0.9971388149F,
  143052. 0.9971776211F, 0.9972160380F, 0.9972540683F, 0.9972917142F,
  143053. 0.9973289783F, 0.9973658631F, 0.9974023709F, 0.9974385042F,
  143054. 0.9974742655F, 0.9975096571F, 0.9975446816F, 0.9975793413F,
  143055. 0.9976136386F, 0.9976475759F, 0.9976811557F, 0.9977143803F,
  143056. 0.9977472521F, 0.9977797736F, 0.9978119470F, 0.9978437748F,
  143057. 0.9978752593F, 0.9979064029F, 0.9979372079F, 0.9979676768F,
  143058. 0.9979978117F, 0.9980276151F, 0.9980570893F, 0.9980862367F,
  143059. 0.9981150595F, 0.9981435600F, 0.9981717406F, 0.9981996035F,
  143060. 0.9982271511F, 0.9982543856F, 0.9982813093F, 0.9983079246F,
  143061. 0.9983342336F, 0.9983602386F, 0.9983859418F, 0.9984113456F,
  143062. 0.9984364522F, 0.9984612638F, 0.9984857825F, 0.9985100108F,
  143063. 0.9985339507F, 0.9985576044F, 0.9985809743F, 0.9986040624F,
  143064. 0.9986268710F, 0.9986494022F, 0.9986716583F, 0.9986936413F,
  143065. 0.9987153535F, 0.9987367969F, 0.9987579738F, 0.9987788864F,
  143066. 0.9987995366F, 0.9988199267F, 0.9988400587F, 0.9988599348F,
  143067. 0.9988795572F, 0.9988989278F, 0.9989180487F, 0.9989369222F,
  143068. 0.9989555501F, 0.9989739347F, 0.9989920780F, 0.9990099820F,
  143069. 0.9990276487F, 0.9990450803F, 0.9990622787F, 0.9990792460F,
  143070. 0.9990959841F, 0.9991124952F, 0.9991287812F, 0.9991448440F,
  143071. 0.9991606858F, 0.9991763084F, 0.9991917139F, 0.9992069042F,
  143072. 0.9992218813F, 0.9992366471F, 0.9992512035F, 0.9992655525F,
  143073. 0.9992796961F, 0.9992936361F, 0.9993073744F, 0.9993209131F,
  143074. 0.9993342538F, 0.9993473987F, 0.9993603494F, 0.9993731080F,
  143075. 0.9993856762F, 0.9993980559F, 0.9994102490F, 0.9994222573F,
  143076. 0.9994340827F, 0.9994457269F, 0.9994571918F, 0.9994684793F,
  143077. 0.9994795910F, 0.9994905288F, 0.9995012945F, 0.9995118898F,
  143078. 0.9995223165F, 0.9995325765F, 0.9995426713F, 0.9995526029F,
  143079. 0.9995623728F, 0.9995719829F, 0.9995814349F, 0.9995907304F,
  143080. 0.9995998712F, 0.9996088590F, 0.9996176954F, 0.9996263821F,
  143081. 0.9996349208F, 0.9996433132F, 0.9996515609F, 0.9996596656F,
  143082. 0.9996676288F, 0.9996754522F, 0.9996831375F, 0.9996906862F,
  143083. 0.9996981000F, 0.9997053804F, 0.9997125290F, 0.9997195474F,
  143084. 0.9997264371F, 0.9997331998F, 0.9997398369F, 0.9997463500F,
  143085. 0.9997527406F, 0.9997590103F, 0.9997651606F, 0.9997711930F,
  143086. 0.9997771089F, 0.9997829098F, 0.9997885973F, 0.9997941728F,
  143087. 0.9997996378F, 0.9998049936F, 0.9998102419F, 0.9998153839F,
  143088. 0.9998204211F, 0.9998253550F, 0.9998301868F, 0.9998349182F,
  143089. 0.9998395503F, 0.9998440847F, 0.9998485226F, 0.9998528654F,
  143090. 0.9998571146F, 0.9998612713F, 0.9998653370F, 0.9998693130F,
  143091. 0.9998732007F, 0.9998770012F, 0.9998807159F, 0.9998843461F,
  143092. 0.9998878931F, 0.9998913581F, 0.9998947424F, 0.9998980473F,
  143093. 0.9999012740F, 0.9999044237F, 0.9999074976F, 0.9999104971F,
  143094. 0.9999134231F, 0.9999162771F, 0.9999190601F, 0.9999217733F,
  143095. 0.9999244179F, 0.9999269950F, 0.9999295058F, 0.9999319515F,
  143096. 0.9999343332F, 0.9999366519F, 0.9999389088F, 0.9999411050F,
  143097. 0.9999432416F, 0.9999453196F, 0.9999473402F, 0.9999493044F,
  143098. 0.9999512132F, 0.9999530677F, 0.9999548690F, 0.9999566180F,
  143099. 0.9999583157F, 0.9999599633F, 0.9999615616F, 0.9999631116F,
  143100. 0.9999646144F, 0.9999660709F, 0.9999674820F, 0.9999688487F,
  143101. 0.9999701719F, 0.9999714526F, 0.9999726917F, 0.9999738900F,
  143102. 0.9999750486F, 0.9999761682F, 0.9999772497F, 0.9999782941F,
  143103. 0.9999793021F, 0.9999802747F, 0.9999812126F, 0.9999821167F,
  143104. 0.9999829878F, 0.9999838268F, 0.9999846343F, 0.9999854113F,
  143105. 0.9999861584F, 0.9999868765F, 0.9999875664F, 0.9999882287F,
  143106. 0.9999888642F, 0.9999894736F, 0.9999900577F, 0.9999906172F,
  143107. 0.9999911528F, 0.9999916651F, 0.9999921548F, 0.9999926227F,
  143108. 0.9999930693F, 0.9999934954F, 0.9999939015F, 0.9999942883F,
  143109. 0.9999946564F, 0.9999950064F, 0.9999953390F, 0.9999956547F,
  143110. 0.9999959541F, 0.9999962377F, 0.9999965062F, 0.9999967601F,
  143111. 0.9999969998F, 0.9999972260F, 0.9999974392F, 0.9999976399F,
  143112. 0.9999978285F, 0.9999980056F, 0.9999981716F, 0.9999983271F,
  143113. 0.9999984724F, 0.9999986081F, 0.9999987345F, 0.9999988521F,
  143114. 0.9999989613F, 0.9999990625F, 0.9999991562F, 0.9999992426F,
  143115. 0.9999993223F, 0.9999993954F, 0.9999994625F, 0.9999995239F,
  143116. 0.9999995798F, 0.9999996307F, 0.9999996768F, 0.9999997184F,
  143117. 0.9999997559F, 0.9999997895F, 0.9999998195F, 0.9999998462F,
  143118. 0.9999998698F, 0.9999998906F, 0.9999999088F, 0.9999999246F,
  143119. 0.9999999383F, 0.9999999500F, 0.9999999600F, 0.9999999684F,
  143120. 0.9999999754F, 0.9999999811F, 0.9999999858F, 0.9999999896F,
  143121. 0.9999999925F, 0.9999999948F, 0.9999999965F, 0.9999999978F,
  143122. 0.9999999986F, 0.9999999992F, 0.9999999996F, 0.9999999998F,
  143123. 0.9999999999F, 1.0000000000F, 1.0000000000F, 1.0000000000F,
  143124. };
  143125. static float vwin8192[4096] = {
  143126. 0.0000000578F, 0.0000005198F, 0.0000014438F, 0.0000028299F,
  143127. 0.0000046780F, 0.0000069882F, 0.0000097604F, 0.0000129945F,
  143128. 0.0000166908F, 0.0000208490F, 0.0000254692F, 0.0000305515F,
  143129. 0.0000360958F, 0.0000421021F, 0.0000485704F, 0.0000555006F,
  143130. 0.0000628929F, 0.0000707472F, 0.0000790635F, 0.0000878417F,
  143131. 0.0000970820F, 0.0001067842F, 0.0001169483F, 0.0001275744F,
  143132. 0.0001386625F, 0.0001502126F, 0.0001622245F, 0.0001746984F,
  143133. 0.0001876343F, 0.0002010320F, 0.0002148917F, 0.0002292132F,
  143134. 0.0002439967F, 0.0002592421F, 0.0002749493F, 0.0002911184F,
  143135. 0.0003077493F, 0.0003248421F, 0.0003423967F, 0.0003604132F,
  143136. 0.0003788915F, 0.0003978316F, 0.0004172335F, 0.0004370971F,
  143137. 0.0004574226F, 0.0004782098F, 0.0004994587F, 0.0005211694F,
  143138. 0.0005433418F, 0.0005659759F, 0.0005890717F, 0.0006126292F,
  143139. 0.0006366484F, 0.0006611292F, 0.0006860716F, 0.0007114757F,
  143140. 0.0007373414F, 0.0007636687F, 0.0007904576F, 0.0008177080F,
  143141. 0.0008454200F, 0.0008735935F, 0.0009022285F, 0.0009313250F,
  143142. 0.0009608830F, 0.0009909025F, 0.0010213834F, 0.0010523257F,
  143143. 0.0010837295F, 0.0011155946F, 0.0011479211F, 0.0011807090F,
  143144. 0.0012139582F, 0.0012476687F, 0.0012818405F, 0.0013164736F,
  143145. 0.0013515679F, 0.0013871235F, 0.0014231402F, 0.0014596182F,
  143146. 0.0014965573F, 0.0015339576F, 0.0015718190F, 0.0016101415F,
  143147. 0.0016489251F, 0.0016881698F, 0.0017278754F, 0.0017680421F,
  143148. 0.0018086698F, 0.0018497584F, 0.0018913080F, 0.0019333185F,
  143149. 0.0019757898F, 0.0020187221F, 0.0020621151F, 0.0021059690F,
  143150. 0.0021502837F, 0.0021950591F, 0.0022402953F, 0.0022859921F,
  143151. 0.0023321497F, 0.0023787679F, 0.0024258467F, 0.0024733861F,
  143152. 0.0025213861F, 0.0025698466F, 0.0026187676F, 0.0026681491F,
  143153. 0.0027179911F, 0.0027682935F, 0.0028190562F, 0.0028702794F,
  143154. 0.0029219628F, 0.0029741066F, 0.0030267107F, 0.0030797749F,
  143155. 0.0031332994F, 0.0031872841F, 0.0032417289F, 0.0032966338F,
  143156. 0.0033519988F, 0.0034078238F, 0.0034641089F, 0.0035208539F,
  143157. 0.0035780589F, 0.0036357237F, 0.0036938485F, 0.0037524331F,
  143158. 0.0038114775F, 0.0038709817F, 0.0039309456F, 0.0039913692F,
  143159. 0.0040522524F, 0.0041135953F, 0.0041753978F, 0.0042376599F,
  143160. 0.0043003814F, 0.0043635624F, 0.0044272029F, 0.0044913028F,
  143161. 0.0045558620F, 0.0046208806F, 0.0046863585F, 0.0047522955F,
  143162. 0.0048186919F, 0.0048855473F, 0.0049528619F, 0.0050206356F,
  143163. 0.0050888684F, 0.0051575601F, 0.0052267108F, 0.0052963204F,
  143164. 0.0053663890F, 0.0054369163F, 0.0055079025F, 0.0055793474F,
  143165. 0.0056512510F, 0.0057236133F, 0.0057964342F, 0.0058697137F,
  143166. 0.0059434517F, 0.0060176482F, 0.0060923032F, 0.0061674166F,
  143167. 0.0062429883F, 0.0063190183F, 0.0063955066F, 0.0064724532F,
  143168. 0.0065498579F, 0.0066277207F, 0.0067060416F, 0.0067848205F,
  143169. 0.0068640575F, 0.0069437523F, 0.0070239051F, 0.0071045157F,
  143170. 0.0071855840F, 0.0072671102F, 0.0073490940F, 0.0074315355F,
  143171. 0.0075144345F, 0.0075977911F, 0.0076816052F, 0.0077658768F,
  143172. 0.0078506057F, 0.0079357920F, 0.0080214355F, 0.0081075363F,
  143173. 0.0081940943F, 0.0082811094F, 0.0083685816F, 0.0084565108F,
  143174. 0.0085448970F, 0.0086337401F, 0.0087230401F, 0.0088127969F,
  143175. 0.0089030104F, 0.0089936807F, 0.0090848076F, 0.0091763911F,
  143176. 0.0092684311F, 0.0093609276F, 0.0094538805F, 0.0095472898F,
  143177. 0.0096411554F, 0.0097354772F, 0.0098302552F, 0.0099254894F,
  143178. 0.0100211796F, 0.0101173259F, 0.0102139281F, 0.0103109863F,
  143179. 0.0104085002F, 0.0105064700F, 0.0106048955F, 0.0107037766F,
  143180. 0.0108031133F, 0.0109029056F, 0.0110031534F, 0.0111038565F,
  143181. 0.0112050151F, 0.0113066289F, 0.0114086980F, 0.0115112222F,
  143182. 0.0116142015F, 0.0117176359F, 0.0118215252F, 0.0119258695F,
  143183. 0.0120306686F, 0.0121359225F, 0.0122416312F, 0.0123477944F,
  143184. 0.0124544123F, 0.0125614847F, 0.0126690116F, 0.0127769928F,
  143185. 0.0128854284F, 0.0129943182F, 0.0131036623F, 0.0132134604F,
  143186. 0.0133237126F, 0.0134344188F, 0.0135455790F, 0.0136571929F,
  143187. 0.0137692607F, 0.0138817821F, 0.0139947572F, 0.0141081859F,
  143188. 0.0142220681F, 0.0143364037F, 0.0144511927F, 0.0145664350F,
  143189. 0.0146821304F, 0.0147982791F, 0.0149148808F, 0.0150319355F,
  143190. 0.0151494431F, 0.0152674036F, 0.0153858168F, 0.0155046828F,
  143191. 0.0156240014F, 0.0157437726F, 0.0158639962F, 0.0159846723F,
  143192. 0.0161058007F, 0.0162273814F, 0.0163494142F, 0.0164718991F,
  143193. 0.0165948361F, 0.0167182250F, 0.0168420658F, 0.0169663584F,
  143194. 0.0170911027F, 0.0172162987F, 0.0173419462F, 0.0174680452F,
  143195. 0.0175945956F, 0.0177215974F, 0.0178490504F, 0.0179769545F,
  143196. 0.0181053098F, 0.0182341160F, 0.0183633732F, 0.0184930812F,
  143197. 0.0186232399F, 0.0187538494F, 0.0188849094F, 0.0190164200F,
  143198. 0.0191483809F, 0.0192807923F, 0.0194136539F, 0.0195469656F,
  143199. 0.0196807275F, 0.0198149394F, 0.0199496012F, 0.0200847128F,
  143200. 0.0202202742F, 0.0203562853F, 0.0204927460F, 0.0206296561F,
  143201. 0.0207670157F, 0.0209048245F, 0.0210430826F, 0.0211817899F,
  143202. 0.0213209462F, 0.0214605515F, 0.0216006057F, 0.0217411086F,
  143203. 0.0218820603F, 0.0220234605F, 0.0221653093F, 0.0223076066F,
  143204. 0.0224503521F, 0.0225935459F, 0.0227371879F, 0.0228812779F,
  143205. 0.0230258160F, 0.0231708018F, 0.0233162355F, 0.0234621169F,
  143206. 0.0236084459F, 0.0237552224F, 0.0239024462F, 0.0240501175F,
  143207. 0.0241982359F, 0.0243468015F, 0.0244958141F, 0.0246452736F,
  143208. 0.0247951800F, 0.0249455331F, 0.0250963329F, 0.0252475792F,
  143209. 0.0253992720F, 0.0255514111F, 0.0257039965F, 0.0258570281F,
  143210. 0.0260105057F, 0.0261644293F, 0.0263187987F, 0.0264736139F,
  143211. 0.0266288747F, 0.0267845811F, 0.0269407330F, 0.0270973302F,
  143212. 0.0272543727F, 0.0274118604F, 0.0275697930F, 0.0277281707F,
  143213. 0.0278869932F, 0.0280462604F, 0.0282059723F, 0.0283661287F,
  143214. 0.0285267295F, 0.0286877747F, 0.0288492641F, 0.0290111976F,
  143215. 0.0291735751F, 0.0293363965F, 0.0294996617F, 0.0296633706F,
  143216. 0.0298275231F, 0.0299921190F, 0.0301571583F, 0.0303226409F,
  143217. 0.0304885667F, 0.0306549354F, 0.0308217472F, 0.0309890017F,
  143218. 0.0311566989F, 0.0313248388F, 0.0314934211F, 0.0316624459F,
  143219. 0.0318319128F, 0.0320018220F, 0.0321721732F, 0.0323429663F,
  143220. 0.0325142013F, 0.0326858779F, 0.0328579962F, 0.0330305559F,
  143221. 0.0332035570F, 0.0333769994F, 0.0335508829F, 0.0337252074F,
  143222. 0.0338999728F, 0.0340751790F, 0.0342508259F, 0.0344269134F,
  143223. 0.0346034412F, 0.0347804094F, 0.0349578178F, 0.0351356663F,
  143224. 0.0353139548F, 0.0354926831F, 0.0356718511F, 0.0358514588F,
  143225. 0.0360315059F, 0.0362119924F, 0.0363929182F, 0.0365742831F,
  143226. 0.0367560870F, 0.0369383297F, 0.0371210113F, 0.0373041315F,
  143227. 0.0374876902F, 0.0376716873F, 0.0378561226F, 0.0380409961F,
  143228. 0.0382263077F, 0.0384120571F, 0.0385982443F, 0.0387848691F,
  143229. 0.0389719315F, 0.0391594313F, 0.0393473683F, 0.0395357425F,
  143230. 0.0397245537F, 0.0399138017F, 0.0401034866F, 0.0402936080F,
  143231. 0.0404841660F, 0.0406751603F, 0.0408665909F, 0.0410584576F,
  143232. 0.0412507603F, 0.0414434988F, 0.0416366731F, 0.0418302829F,
  143233. 0.0420243282F, 0.0422188088F, 0.0424137246F, 0.0426090755F,
  143234. 0.0428048613F, 0.0430010819F, 0.0431977371F, 0.0433948269F,
  143235. 0.0435923511F, 0.0437903095F, 0.0439887020F, 0.0441875285F,
  143236. 0.0443867889F, 0.0445864830F, 0.0447866106F, 0.0449871717F,
  143237. 0.0451881661F, 0.0453895936F, 0.0455914542F, 0.0457937477F,
  143238. 0.0459964738F, 0.0461996326F, 0.0464032239F, 0.0466072475F,
  143239. 0.0468117032F, 0.0470165910F, 0.0472219107F, 0.0474276622F,
  143240. 0.0476338452F, 0.0478404597F, 0.0480475056F, 0.0482549827F,
  143241. 0.0484628907F, 0.0486712297F, 0.0488799994F, 0.0490891998F,
  143242. 0.0492988306F, 0.0495088917F, 0.0497193830F, 0.0499303043F,
  143243. 0.0501416554F, 0.0503534363F, 0.0505656468F, 0.0507782867F,
  143244. 0.0509913559F, 0.0512048542F, 0.0514187815F, 0.0516331376F,
  143245. 0.0518479225F, 0.0520631358F, 0.0522787775F, 0.0524948475F,
  143246. 0.0527113455F, 0.0529282715F, 0.0531456252F, 0.0533634066F,
  143247. 0.0535816154F, 0.0538002515F, 0.0540193148F, 0.0542388051F,
  143248. 0.0544587222F, 0.0546790660F, 0.0548998364F, 0.0551210331F,
  143249. 0.0553426561F, 0.0555647051F, 0.0557871801F, 0.0560100807F,
  143250. 0.0562334070F, 0.0564571587F, 0.0566813357F, 0.0569059378F,
  143251. 0.0571309649F, 0.0573564168F, 0.0575822933F, 0.0578085942F,
  143252. 0.0580353195F, 0.0582624689F, 0.0584900423F, 0.0587180396F,
  143253. 0.0589464605F, 0.0591753049F, 0.0594045726F, 0.0596342635F,
  143254. 0.0598643774F, 0.0600949141F, 0.0603258735F, 0.0605572555F,
  143255. 0.0607890597F, 0.0610212862F, 0.0612539346F, 0.0614870049F,
  143256. 0.0617204968F, 0.0619544103F, 0.0621887451F, 0.0624235010F,
  143257. 0.0626586780F, 0.0628942758F, 0.0631302942F, 0.0633667331F,
  143258. 0.0636035923F, 0.0638408717F, 0.0640785710F, 0.0643166901F,
  143259. 0.0645552288F, 0.0647941870F, 0.0650335645F, 0.0652733610F,
  143260. 0.0655135765F, 0.0657542108F, 0.0659952636F, 0.0662367348F,
  143261. 0.0664786242F, 0.0667209316F, 0.0669636570F, 0.0672068000F,
  143262. 0.0674503605F, 0.0676943384F, 0.0679387334F, 0.0681835454F,
  143263. 0.0684287742F, 0.0686744196F, 0.0689204814F, 0.0691669595F,
  143264. 0.0694138536F, 0.0696611637F, 0.0699088894F, 0.0701570307F,
  143265. 0.0704055873F, 0.0706545590F, 0.0709039458F, 0.0711537473F,
  143266. 0.0714039634F, 0.0716545939F, 0.0719056387F, 0.0721570975F,
  143267. 0.0724089702F, 0.0726612565F, 0.0729139563F, 0.0731670694F,
  143268. 0.0734205956F, 0.0736745347F, 0.0739288866F, 0.0741836510F,
  143269. 0.0744388277F, 0.0746944166F, 0.0749504175F, 0.0752068301F,
  143270. 0.0754636543F, 0.0757208899F, 0.0759785367F, 0.0762365946F,
  143271. 0.0764950632F, 0.0767539424F, 0.0770132320F, 0.0772729319F,
  143272. 0.0775330418F, 0.0777935616F, 0.0780544909F, 0.0783158298F,
  143273. 0.0785775778F, 0.0788397349F, 0.0791023009F, 0.0793652755F,
  143274. 0.0796286585F, 0.0798924498F, 0.0801566492F, 0.0804212564F,
  143275. 0.0806862712F, 0.0809516935F, 0.0812175231F, 0.0814837597F,
  143276. 0.0817504031F, 0.0820174532F, 0.0822849097F, 0.0825527724F,
  143277. 0.0828210412F, 0.0830897158F, 0.0833587960F, 0.0836282816F,
  143278. 0.0838981724F, 0.0841684682F, 0.0844391688F, 0.0847102740F,
  143279. 0.0849817835F, 0.0852536973F, 0.0855260150F, 0.0857987364F,
  143280. 0.0860718614F, 0.0863453897F, 0.0866193211F, 0.0868936554F,
  143281. 0.0871683924F, 0.0874435319F, 0.0877190737F, 0.0879950175F,
  143282. 0.0882713632F, 0.0885481105F, 0.0888252592F, 0.0891028091F,
  143283. 0.0893807600F, 0.0896591117F, 0.0899378639F, 0.0902170165F,
  143284. 0.0904965692F, 0.0907765218F, 0.0910568740F, 0.0913376258F,
  143285. 0.0916187767F, 0.0919003268F, 0.0921822756F, 0.0924646230F,
  143286. 0.0927473687F, 0.0930305126F, 0.0933140545F, 0.0935979940F,
  143287. 0.0938823310F, 0.0941670653F, 0.0944521966F, 0.0947377247F,
  143288. 0.0950236494F, 0.0953099704F, 0.0955966876F, 0.0958838007F,
  143289. 0.0961713094F, 0.0964592136F, 0.0967475131F, 0.0970362075F,
  143290. 0.0973252967F, 0.0976147805F, 0.0979046585F, 0.0981949307F,
  143291. 0.0984855967F, 0.0987766563F, 0.0990681093F, 0.0993599555F,
  143292. 0.0996521945F, 0.0999448263F, 0.1002378506F, 0.1005312671F,
  143293. 0.1008250755F, 0.1011192757F, 0.1014138675F, 0.1017088505F,
  143294. 0.1020042246F, 0.1022999895F, 0.1025961450F, 0.1028926909F,
  143295. 0.1031896268F, 0.1034869526F, 0.1037846680F, 0.1040827729F,
  143296. 0.1043812668F, 0.1046801497F, 0.1049794213F, 0.1052790813F,
  143297. 0.1055791294F, 0.1058795656F, 0.1061803894F, 0.1064816006F,
  143298. 0.1067831991F, 0.1070851846F, 0.1073875568F, 0.1076903155F,
  143299. 0.1079934604F, 0.1082969913F, 0.1086009079F, 0.1089052101F,
  143300. 0.1092098975F, 0.1095149699F, 0.1098204270F, 0.1101262687F,
  143301. 0.1104324946F, 0.1107391045F, 0.1110460982F, 0.1113534754F,
  143302. 0.1116612359F, 0.1119693793F, 0.1122779055F, 0.1125868142F,
  143303. 0.1128961052F, 0.1132057781F, 0.1135158328F, 0.1138262690F,
  143304. 0.1141370863F, 0.1144482847F, 0.1147598638F, 0.1150718233F,
  143305. 0.1153841631F, 0.1156968828F, 0.1160099822F, 0.1163234610F,
  143306. 0.1166373190F, 0.1169515559F, 0.1172661714F, 0.1175811654F,
  143307. 0.1178965374F, 0.1182122874F, 0.1185284149F, 0.1188449198F,
  143308. 0.1191618018F, 0.1194790606F, 0.1197966960F, 0.1201147076F,
  143309. 0.1204330953F, 0.1207518587F, 0.1210709976F, 0.1213905118F,
  143310. 0.1217104009F, 0.1220306647F, 0.1223513029F, 0.1226723153F,
  143311. 0.1229937016F, 0.1233154615F, 0.1236375948F, 0.1239601011F,
  143312. 0.1242829803F, 0.1246062319F, 0.1249298559F, 0.1252538518F,
  143313. 0.1255782195F, 0.1259029586F, 0.1262280689F, 0.1265535501F,
  143314. 0.1268794019F, 0.1272056241F, 0.1275322163F, 0.1278591784F,
  143315. 0.1281865099F, 0.1285142108F, 0.1288422805F, 0.1291707190F,
  143316. 0.1294995259F, 0.1298287009F, 0.1301582437F, 0.1304881542F,
  143317. 0.1308184319F, 0.1311490766F, 0.1314800881F, 0.1318114660F,
  143318. 0.1321432100F, 0.1324753200F, 0.1328077955F, 0.1331406364F,
  143319. 0.1334738422F, 0.1338074129F, 0.1341413479F, 0.1344756472F,
  143320. 0.1348103103F, 0.1351453370F, 0.1354807270F, 0.1358164801F,
  143321. 0.1361525959F, 0.1364890741F, 0.1368259145F, 0.1371631167F,
  143322. 0.1375006805F, 0.1378386056F, 0.1381768917F, 0.1385155384F,
  143323. 0.1388545456F, 0.1391939129F, 0.1395336400F, 0.1398737266F,
  143324. 0.1402141724F, 0.1405549772F, 0.1408961406F, 0.1412376623F,
  143325. 0.1415795421F, 0.1419217797F, 0.1422643746F, 0.1426073268F,
  143326. 0.1429506358F, 0.1432943013F, 0.1436383231F, 0.1439827008F,
  143327. 0.1443274342F, 0.1446725229F, 0.1450179667F, 0.1453637652F,
  143328. 0.1457099181F, 0.1460564252F, 0.1464032861F, 0.1467505006F,
  143329. 0.1470980682F, 0.1474459888F, 0.1477942620F, 0.1481428875F,
  143330. 0.1484918651F, 0.1488411942F, 0.1491908748F, 0.1495409065F,
  143331. 0.1498912889F, 0.1502420218F, 0.1505931048F, 0.1509445376F,
  143332. 0.1512963200F, 0.1516484516F, 0.1520009321F, 0.1523537612F,
  143333. 0.1527069385F, 0.1530604638F, 0.1534143368F, 0.1537685571F,
  143334. 0.1541231244F, 0.1544780384F, 0.1548332987F, 0.1551889052F,
  143335. 0.1555448574F, 0.1559011550F, 0.1562577978F, 0.1566147853F,
  143336. 0.1569721173F, 0.1573297935F, 0.1576878135F, 0.1580461771F,
  143337. 0.1584048838F, 0.1587639334F, 0.1591233255F, 0.1594830599F,
  143338. 0.1598431361F, 0.1602035540F, 0.1605643131F, 0.1609254131F,
  143339. 0.1612868537F, 0.1616486346F, 0.1620107555F, 0.1623732160F,
  143340. 0.1627360158F, 0.1630991545F, 0.1634626319F, 0.1638264476F,
  143341. 0.1641906013F, 0.1645550926F, 0.1649199212F, 0.1652850869F,
  143342. 0.1656505892F, 0.1660164278F, 0.1663826024F, 0.1667491127F,
  143343. 0.1671159583F, 0.1674831388F, 0.1678506541F, 0.1682185036F,
  143344. 0.1685866872F, 0.1689552044F, 0.1693240549F, 0.1696932384F,
  143345. 0.1700627545F, 0.1704326029F, 0.1708027833F, 0.1711732952F,
  143346. 0.1715441385F, 0.1719153127F, 0.1722868175F, 0.1726586526F,
  143347. 0.1730308176F, 0.1734033121F, 0.1737761359F, 0.1741492886F,
  143348. 0.1745227698F, 0.1748965792F, 0.1752707164F, 0.1756451812F,
  143349. 0.1760199731F, 0.1763950918F, 0.1767705370F, 0.1771463083F,
  143350. 0.1775224054F, 0.1778988279F, 0.1782755754F, 0.1786526477F,
  143351. 0.1790300444F, 0.1794077651F, 0.1797858094F, 0.1801641771F,
  143352. 0.1805428677F, 0.1809218810F, 0.1813012165F, 0.1816808739F,
  143353. 0.1820608528F, 0.1824411530F, 0.1828217739F, 0.1832027154F,
  143354. 0.1835839770F, 0.1839655584F, 0.1843474592F, 0.1847296790F,
  143355. 0.1851122175F, 0.1854950744F, 0.1858782492F, 0.1862617417F,
  143356. 0.1866455514F, 0.1870296780F, 0.1874141211F, 0.1877988804F,
  143357. 0.1881839555F, 0.1885693461F, 0.1889550517F, 0.1893410721F,
  143358. 0.1897274068F, 0.1901140555F, 0.1905010178F, 0.1908882933F,
  143359. 0.1912758818F, 0.1916637828F, 0.1920519959F, 0.1924405208F,
  143360. 0.1928293571F, 0.1932185044F, 0.1936079625F, 0.1939977308F,
  143361. 0.1943878091F, 0.1947781969F, 0.1951688939F, 0.1955598998F,
  143362. 0.1959512141F, 0.1963428364F, 0.1967347665F, 0.1971270038F,
  143363. 0.1975195482F, 0.1979123990F, 0.1983055561F, 0.1986990190F,
  143364. 0.1990927873F, 0.1994868607F, 0.1998812388F, 0.2002759212F,
  143365. 0.2006709075F, 0.2010661974F, 0.2014617904F, 0.2018576862F,
  143366. 0.2022538844F, 0.2026503847F, 0.2030471865F, 0.2034442897F,
  143367. 0.2038416937F, 0.2042393982F, 0.2046374028F, 0.2050357071F,
  143368. 0.2054343107F, 0.2058332133F, 0.2062324145F, 0.2066319138F,
  143369. 0.2070317110F, 0.2074318055F, 0.2078321970F, 0.2082328852F,
  143370. 0.2086338696F, 0.2090351498F, 0.2094367255F, 0.2098385962F,
  143371. 0.2102407617F, 0.2106432213F, 0.2110459749F, 0.2114490220F,
  143372. 0.2118523621F, 0.2122559950F, 0.2126599202F, 0.2130641373F,
  143373. 0.2134686459F, 0.2138734456F, 0.2142785361F, 0.2146839168F,
  143374. 0.2150895875F, 0.2154955478F, 0.2159017972F, 0.2163083353F,
  143375. 0.2167151617F, 0.2171222761F, 0.2175296780F, 0.2179373670F,
  143376. 0.2183453428F, 0.2187536049F, 0.2191621529F, 0.2195709864F,
  143377. 0.2199801051F, 0.2203895085F, 0.2207991961F, 0.2212091677F,
  143378. 0.2216194228F, 0.2220299610F, 0.2224407818F, 0.2228518850F,
  143379. 0.2232632699F, 0.2236749364F, 0.2240868839F, 0.2244991121F,
  143380. 0.2249116204F, 0.2253244086F, 0.2257374763F, 0.2261508229F,
  143381. 0.2265644481F, 0.2269783514F, 0.2273925326F, 0.2278069911F,
  143382. 0.2282217265F, 0.2286367384F, 0.2290520265F, 0.2294675902F,
  143383. 0.2298834292F, 0.2302995431F, 0.2307159314F, 0.2311325937F,
  143384. 0.2315495297F, 0.2319667388F, 0.2323842207F, 0.2328019749F,
  143385. 0.2332200011F, 0.2336382988F, 0.2340568675F, 0.2344757070F,
  143386. 0.2348948166F, 0.2353141961F, 0.2357338450F, 0.2361537629F,
  143387. 0.2365739493F, 0.2369944038F, 0.2374151261F, 0.2378361156F,
  143388. 0.2382573720F, 0.2386788948F, 0.2391006836F, 0.2395227380F,
  143389. 0.2399450575F, 0.2403676417F, 0.2407904902F, 0.2412136026F,
  143390. 0.2416369783F, 0.2420606171F, 0.2424845185F, 0.2429086820F,
  143391. 0.2433331072F, 0.2437577936F, 0.2441827409F, 0.2446079486F,
  143392. 0.2450334163F, 0.2454591435F, 0.2458851298F, 0.2463113747F,
  143393. 0.2467378779F, 0.2471646389F, 0.2475916573F, 0.2480189325F,
  143394. 0.2484464643F, 0.2488742521F, 0.2493022955F, 0.2497305940F,
  143395. 0.2501591473F, 0.2505879549F, 0.2510170163F, 0.2514463311F,
  143396. 0.2518758989F, 0.2523057193F, 0.2527357916F, 0.2531661157F,
  143397. 0.2535966909F, 0.2540275169F, 0.2544585931F, 0.2548899193F,
  143398. 0.2553214948F, 0.2557533193F, 0.2561853924F, 0.2566177135F,
  143399. 0.2570502822F, 0.2574830981F, 0.2579161608F, 0.2583494697F,
  143400. 0.2587830245F, 0.2592168246F, 0.2596508697F, 0.2600851593F,
  143401. 0.2605196929F, 0.2609544701F, 0.2613894904F, 0.2618247534F,
  143402. 0.2622602586F, 0.2626960055F, 0.2631319938F, 0.2635682230F,
  143403. 0.2640046925F, 0.2644414021F, 0.2648783511F, 0.2653155391F,
  143404. 0.2657529657F, 0.2661906305F, 0.2666285329F, 0.2670666725F,
  143405. 0.2675050489F, 0.2679436616F, 0.2683825101F, 0.2688215940F,
  143406. 0.2692609127F, 0.2697004660F, 0.2701402532F, 0.2705802739F,
  143407. 0.2710205278F, 0.2714610142F, 0.2719017327F, 0.2723426830F,
  143408. 0.2727838644F, 0.2732252766F, 0.2736669191F, 0.2741087914F,
  143409. 0.2745508930F, 0.2749932235F, 0.2754357824F, 0.2758785693F,
  143410. 0.2763215837F, 0.2767648251F, 0.2772082930F, 0.2776519870F,
  143411. 0.2780959066F, 0.2785400513F, 0.2789844207F, 0.2794290143F,
  143412. 0.2798738316F, 0.2803188722F, 0.2807641355F, 0.2812096211F,
  143413. 0.2816553286F, 0.2821012574F, 0.2825474071F, 0.2829937773F,
  143414. 0.2834403673F, 0.2838871768F, 0.2843342053F, 0.2847814523F,
  143415. 0.2852289174F, 0.2856765999F, 0.2861244996F, 0.2865726159F,
  143416. 0.2870209482F, 0.2874694962F, 0.2879182594F, 0.2883672372F,
  143417. 0.2888164293F, 0.2892658350F, 0.2897154540F, 0.2901652858F,
  143418. 0.2906153298F, 0.2910655856F, 0.2915160527F, 0.2919667306F,
  143419. 0.2924176189F, 0.2928687171F, 0.2933200246F, 0.2937715409F,
  143420. 0.2942232657F, 0.2946751984F, 0.2951273386F, 0.2955796856F,
  143421. 0.2960322391F, 0.2964849986F, 0.2969379636F, 0.2973911335F,
  143422. 0.2978445080F, 0.2982980864F, 0.2987518684F, 0.2992058534F,
  143423. 0.2996600409F, 0.3001144305F, 0.3005690217F, 0.3010238139F,
  143424. 0.3014788067F, 0.3019339995F, 0.3023893920F, 0.3028449835F,
  143425. 0.3033007736F, 0.3037567618F, 0.3042129477F, 0.3046693306F,
  143426. 0.3051259102F, 0.3055826859F, 0.3060396572F, 0.3064968236F,
  143427. 0.3069541847F, 0.3074117399F, 0.3078694887F, 0.3083274307F,
  143428. 0.3087855653F, 0.3092438920F, 0.3097024104F, 0.3101611199F,
  143429. 0.3106200200F, 0.3110791103F, 0.3115383902F, 0.3119978592F,
  143430. 0.3124575169F, 0.3129173627F, 0.3133773961F, 0.3138376166F,
  143431. 0.3142980238F, 0.3147586170F, 0.3152193959F, 0.3156803598F,
  143432. 0.3161415084F, 0.3166028410F, 0.3170643573F, 0.3175260566F,
  143433. 0.3179879384F, 0.3184500023F, 0.3189122478F, 0.3193746743F,
  143434. 0.3198372814F, 0.3203000685F, 0.3207630351F, 0.3212261807F,
  143435. 0.3216895048F, 0.3221530069F, 0.3226166865F, 0.3230805430F,
  143436. 0.3235445760F, 0.3240087849F, 0.3244731693F, 0.3249377285F,
  143437. 0.3254024622F, 0.3258673698F, 0.3263324507F, 0.3267977045F,
  143438. 0.3272631306F, 0.3277287286F, 0.3281944978F, 0.3286604379F,
  143439. 0.3291265482F, 0.3295928284F, 0.3300592777F, 0.3305258958F,
  143440. 0.3309926821F, 0.3314596361F, 0.3319267573F, 0.3323940451F,
  143441. 0.3328614990F, 0.3333291186F, 0.3337969033F, 0.3342648525F,
  143442. 0.3347329658F, 0.3352012427F, 0.3356696825F, 0.3361382849F,
  143443. 0.3366070492F, 0.3370759749F, 0.3375450616F, 0.3380143087F,
  143444. 0.3384837156F, 0.3389532819F, 0.3394230071F, 0.3398928905F,
  143445. 0.3403629317F, 0.3408331302F, 0.3413034854F, 0.3417739967F,
  143446. 0.3422446638F, 0.3427154860F, 0.3431864628F, 0.3436575938F,
  143447. 0.3441288782F, 0.3446003158F, 0.3450719058F, 0.3455436478F,
  143448. 0.3460155412F, 0.3464875856F, 0.3469597804F, 0.3474321250F,
  143449. 0.3479046189F, 0.3483772617F, 0.3488500527F, 0.3493229914F,
  143450. 0.3497960774F, 0.3502693100F, 0.3507426887F, 0.3512162131F,
  143451. 0.3516898825F, 0.3521636965F, 0.3526376545F, 0.3531117559F,
  143452. 0.3535860003F, 0.3540603870F, 0.3545349157F, 0.3550095856F,
  143453. 0.3554843964F, 0.3559593474F, 0.3564344381F, 0.3569096680F,
  143454. 0.3573850366F, 0.3578605432F, 0.3583361875F, 0.3588119687F,
  143455. 0.3592878865F, 0.3597639402F, 0.3602401293F, 0.3607164533F,
  143456. 0.3611929117F, 0.3616695038F, 0.3621462292F, 0.3626230873F,
  143457. 0.3631000776F, 0.3635771995F, 0.3640544525F, 0.3645318360F,
  143458. 0.3650093496F, 0.3654869926F, 0.3659647645F, 0.3664426648F,
  143459. 0.3669206930F, 0.3673988484F, 0.3678771306F, 0.3683555390F,
  143460. 0.3688340731F, 0.3693127322F, 0.3697915160F, 0.3702704237F,
  143461. 0.3707494549F, 0.3712286091F, 0.3717078857F, 0.3721872840F,
  143462. 0.3726668037F, 0.3731464441F, 0.3736262047F, 0.3741060850F,
  143463. 0.3745860843F, 0.3750662023F, 0.3755464382F, 0.3760267915F,
  143464. 0.3765072618F, 0.3769878484F, 0.3774685509F, 0.3779493686F,
  143465. 0.3784303010F, 0.3789113475F, 0.3793925076F, 0.3798737809F,
  143466. 0.3803551666F, 0.3808366642F, 0.3813182733F, 0.3817999932F,
  143467. 0.3822818234F, 0.3827637633F, 0.3832458124F, 0.3837279702F,
  143468. 0.3842102360F, 0.3846926093F, 0.3851750897F, 0.3856576764F,
  143469. 0.3861403690F, 0.3866231670F, 0.3871060696F, 0.3875890765F,
  143470. 0.3880721870F, 0.3885554007F, 0.3890387168F, 0.3895221349F,
  143471. 0.3900056544F, 0.3904892748F, 0.3909729955F, 0.3914568160F,
  143472. 0.3919407356F, 0.3924247539F, 0.3929088702F, 0.3933930841F,
  143473. 0.3938773949F, 0.3943618021F, 0.3948463052F, 0.3953309035F,
  143474. 0.3958155966F, 0.3963003838F, 0.3967852646F, 0.3972702385F,
  143475. 0.3977553048F, 0.3982404631F, 0.3987257127F, 0.3992110531F,
  143476. 0.3996964838F, 0.4001820041F, 0.4006676136F, 0.4011533116F,
  143477. 0.4016390976F, 0.4021249710F, 0.4026109313F, 0.4030969779F,
  143478. 0.4035831102F, 0.4040693277F, 0.4045556299F, 0.4050420160F,
  143479. 0.4055284857F, 0.4060150383F, 0.4065016732F, 0.4069883899F,
  143480. 0.4074751879F, 0.4079620665F, 0.4084490252F, 0.4089360635F,
  143481. 0.4094231807F, 0.4099103763F, 0.4103976498F, 0.4108850005F,
  143482. 0.4113724280F, 0.4118599315F, 0.4123475107F, 0.4128351648F,
  143483. 0.4133228934F, 0.4138106959F, 0.4142985716F, 0.4147865201F,
  143484. 0.4152745408F, 0.4157626330F, 0.4162507963F, 0.4167390301F,
  143485. 0.4172273337F, 0.4177157067F, 0.4182041484F, 0.4186926583F,
  143486. 0.4191812359F, 0.4196698805F, 0.4201585915F, 0.4206473685F,
  143487. 0.4211362108F, 0.4216251179F, 0.4221140892F, 0.4226031241F,
  143488. 0.4230922221F, 0.4235813826F, 0.4240706050F, 0.4245598887F,
  143489. 0.4250492332F, 0.4255386379F, 0.4260281022F, 0.4265176256F,
  143490. 0.4270072075F, 0.4274968473F, 0.4279865445F, 0.4284762984F,
  143491. 0.4289661086F, 0.4294559743F, 0.4299458951F, 0.4304358704F,
  143492. 0.4309258996F, 0.4314159822F, 0.4319061175F, 0.4323963050F,
  143493. 0.4328865441F, 0.4333768342F, 0.4338671749F, 0.4343575654F,
  143494. 0.4348480052F, 0.4353384938F, 0.4358290306F, 0.4363196149F,
  143495. 0.4368102463F, 0.4373009241F, 0.4377916478F, 0.4382824168F,
  143496. 0.4387732305F, 0.4392640884F, 0.4397549899F, 0.4402459343F,
  143497. 0.4407369212F, 0.4412279499F, 0.4417190198F, 0.4422101305F,
  143498. 0.4427012813F, 0.4431924717F, 0.4436837010F, 0.4441749686F,
  143499. 0.4446662742F, 0.4451576169F, 0.4456489963F, 0.4461404118F,
  143500. 0.4466318628F, 0.4471233487F, 0.4476148690F, 0.4481064230F,
  143501. 0.4485980103F, 0.4490896302F, 0.4495812821F, 0.4500729654F,
  143502. 0.4505646797F, 0.4510564243F, 0.4515481986F, 0.4520400021F,
  143503. 0.4525318341F, 0.4530236942F, 0.4535155816F, 0.4540074959F,
  143504. 0.4544994365F, 0.4549914028F, 0.4554833941F, 0.4559754100F,
  143505. 0.4564674499F, 0.4569595131F, 0.4574515991F, 0.4579437074F,
  143506. 0.4584358372F, 0.4589279881F, 0.4594201595F, 0.4599123508F,
  143507. 0.4604045615F, 0.4608967908F, 0.4613890383F, 0.4618813034F,
  143508. 0.4623735855F, 0.4628658841F, 0.4633581984F, 0.4638505281F,
  143509. 0.4643428724F, 0.4648352308F, 0.4653276028F, 0.4658199877F,
  143510. 0.4663123849F, 0.4668047940F, 0.4672972143F, 0.4677896451F,
  143511. 0.4682820861F, 0.4687745365F, 0.4692669958F, 0.4697594634F,
  143512. 0.4702519387F, 0.4707444211F, 0.4712369102F, 0.4717294052F,
  143513. 0.4722219056F, 0.4727144109F, 0.4732069204F, 0.4736994336F,
  143514. 0.4741919498F, 0.4746844686F, 0.4751769893F, 0.4756695113F,
  143515. 0.4761620341F, 0.4766545571F, 0.4771470797F, 0.4776396013F,
  143516. 0.4781321213F, 0.4786246392F, 0.4791171544F, 0.4796096663F,
  143517. 0.4801021744F, 0.4805946779F, 0.4810871765F, 0.4815796694F,
  143518. 0.4820721561F, 0.4825646360F, 0.4830571086F, 0.4835495732F,
  143519. 0.4840420293F, 0.4845344763F, 0.4850269136F, 0.4855193407F,
  143520. 0.4860117569F, 0.4865041617F, 0.4869965545F, 0.4874889347F,
  143521. 0.4879813018F, 0.4884736551F, 0.4889659941F, 0.4894583182F,
  143522. 0.4899506268F, 0.4904429193F, 0.4909351952F, 0.4914274538F,
  143523. 0.4919196947F, 0.4924119172F, 0.4929041207F, 0.4933963046F,
  143524. 0.4938884685F, 0.4943806116F, 0.4948727335F, 0.4953648335F,
  143525. 0.4958569110F, 0.4963489656F, 0.4968409965F, 0.4973330032F,
  143526. 0.4978249852F, 0.4983169419F, 0.4988088726F, 0.4993007768F,
  143527. 0.4997926539F, 0.5002845034F, 0.5007763247F, 0.5012681171F,
  143528. 0.5017598801F, 0.5022516132F, 0.5027433157F, 0.5032349871F,
  143529. 0.5037266268F, 0.5042182341F, 0.5047098086F, 0.5052013497F,
  143530. 0.5056928567F, 0.5061843292F, 0.5066757664F, 0.5071671679F,
  143531. 0.5076585330F, 0.5081498613F, 0.5086411520F, 0.5091324047F,
  143532. 0.5096236187F, 0.5101147934F, 0.5106059284F, 0.5110970230F,
  143533. 0.5115880766F, 0.5120790887F, 0.5125700587F, 0.5130609860F,
  143534. 0.5135518700F, 0.5140427102F, 0.5145335059F, 0.5150242566F,
  143535. 0.5155149618F, 0.5160056208F, 0.5164962331F, 0.5169867980F,
  143536. 0.5174773151F, 0.5179677837F, 0.5184582033F, 0.5189485733F,
  143537. 0.5194388931F, 0.5199291621F, 0.5204193798F, 0.5209095455F,
  143538. 0.5213996588F, 0.5218897190F, 0.5223797256F, 0.5228696779F,
  143539. 0.5233595755F, 0.5238494177F, 0.5243392039F, 0.5248289337F,
  143540. 0.5253186063F, 0.5258082213F, 0.5262977781F, 0.5267872760F,
  143541. 0.5272767146F, 0.5277660932F, 0.5282554112F, 0.5287446682F,
  143542. 0.5292338635F, 0.5297229965F, 0.5302120667F, 0.5307010736F,
  143543. 0.5311900164F, 0.5316788947F, 0.5321677079F, 0.5326564554F,
  143544. 0.5331451366F, 0.5336337511F, 0.5341222981F, 0.5346107771F,
  143545. 0.5350991876F, 0.5355875290F, 0.5360758007F, 0.5365640021F,
  143546. 0.5370521327F, 0.5375401920F, 0.5380281792F, 0.5385160939F,
  143547. 0.5390039355F, 0.5394917034F, 0.5399793971F, 0.5404670159F,
  143548. 0.5409545594F, 0.5414420269F, 0.5419294179F, 0.5424167318F,
  143549. 0.5429039680F, 0.5433911261F, 0.5438782053F, 0.5443652051F,
  143550. 0.5448521250F, 0.5453389644F, 0.5458257228F, 0.5463123995F,
  143551. 0.5467989940F, 0.5472855057F, 0.5477719341F, 0.5482582786F,
  143552. 0.5487445387F, 0.5492307137F, 0.5497168031F, 0.5502028063F,
  143553. 0.5506887228F, 0.5511745520F, 0.5516602934F, 0.5521459463F,
  143554. 0.5526315103F, 0.5531169847F, 0.5536023690F, 0.5540876626F,
  143555. 0.5545728649F, 0.5550579755F, 0.5555429937F, 0.5560279189F,
  143556. 0.5565127507F, 0.5569974884F, 0.5574821315F, 0.5579666794F,
  143557. 0.5584511316F, 0.5589354875F, 0.5594197465F, 0.5599039080F,
  143558. 0.5603879716F, 0.5608719367F, 0.5613558026F, 0.5618395689F,
  143559. 0.5623232350F, 0.5628068002F, 0.5632902642F, 0.5637736262F,
  143560. 0.5642568858F, 0.5647400423F, 0.5652230953F, 0.5657060442F,
  143561. 0.5661888883F, 0.5666716272F, 0.5671542603F, 0.5676367870F,
  143562. 0.5681192069F, 0.5686015192F, 0.5690837235F, 0.5695658192F,
  143563. 0.5700478058F, 0.5705296827F, 0.5710114494F, 0.5714931052F,
  143564. 0.5719746497F, 0.5724560822F, 0.5729374023F, 0.5734186094F,
  143565. 0.5738997029F, 0.5743806823F, 0.5748615470F, 0.5753422965F,
  143566. 0.5758229301F, 0.5763034475F, 0.5767838480F, 0.5772641310F,
  143567. 0.5777442960F, 0.5782243426F, 0.5787042700F, 0.5791840778F,
  143568. 0.5796637654F, 0.5801433322F, 0.5806227778F, 0.5811021016F,
  143569. 0.5815813029F, 0.5820603814F, 0.5825393363F, 0.5830181673F,
  143570. 0.5834968737F, 0.5839754549F, 0.5844539105F, 0.5849322399F,
  143571. 0.5854104425F, 0.5858885179F, 0.5863664653F, 0.5868442844F,
  143572. 0.5873219746F, 0.5877995353F, 0.5882769660F, 0.5887542661F,
  143573. 0.5892314351F, 0.5897084724F, 0.5901853776F, 0.5906621500F,
  143574. 0.5911387892F, 0.5916152945F, 0.5920916655F, 0.5925679016F,
  143575. 0.5930440022F, 0.5935199669F, 0.5939957950F, 0.5944714861F,
  143576. 0.5949470396F, 0.5954224550F, 0.5958977317F, 0.5963728692F,
  143577. 0.5968478669F, 0.5973227244F, 0.5977974411F, 0.5982720163F,
  143578. 0.5987464497F, 0.5992207407F, 0.5996948887F, 0.6001688932F,
  143579. 0.6006427537F, 0.6011164696F, 0.6015900405F, 0.6020634657F,
  143580. 0.6025367447F, 0.6030098770F, 0.6034828621F, 0.6039556995F,
  143581. 0.6044283885F, 0.6049009288F, 0.6053733196F, 0.6058455606F,
  143582. 0.6063176512F, 0.6067895909F, 0.6072613790F, 0.6077330152F,
  143583. 0.6082044989F, 0.6086758295F, 0.6091470065F, 0.6096180294F,
  143584. 0.6100888977F, 0.6105596108F, 0.6110301682F, 0.6115005694F,
  143585. 0.6119708139F, 0.6124409011F, 0.6129108305F, 0.6133806017F,
  143586. 0.6138502139F, 0.6143196669F, 0.6147889599F, 0.6152580926F,
  143587. 0.6157270643F, 0.6161958746F, 0.6166645230F, 0.6171330088F,
  143588. 0.6176013317F, 0.6180694910F, 0.6185374863F, 0.6190053171F,
  143589. 0.6194729827F, 0.6199404828F, 0.6204078167F, 0.6208749841F,
  143590. 0.6213419842F, 0.6218088168F, 0.6222754811F, 0.6227419768F,
  143591. 0.6232083032F, 0.6236744600F, 0.6241404465F, 0.6246062622F,
  143592. 0.6250719067F, 0.6255373795F, 0.6260026799F, 0.6264678076F,
  143593. 0.6269327619F, 0.6273975425F, 0.6278621487F, 0.6283265800F,
  143594. 0.6287908361F, 0.6292549163F, 0.6297188201F, 0.6301825471F,
  143595. 0.6306460966F, 0.6311094683F, 0.6315726617F, 0.6320356761F,
  143596. 0.6324985111F, 0.6329611662F, 0.6334236410F, 0.6338859348F,
  143597. 0.6343480472F, 0.6348099777F, 0.6352717257F, 0.6357332909F,
  143598. 0.6361946726F, 0.6366558704F, 0.6371168837F, 0.6375777122F,
  143599. 0.6380383552F, 0.6384988123F, 0.6389590830F, 0.6394191668F,
  143600. 0.6398790631F, 0.6403387716F, 0.6407982916F, 0.6412576228F,
  143601. 0.6417167645F, 0.6421757163F, 0.6426344778F, 0.6430930483F,
  143602. 0.6435514275F, 0.6440096149F, 0.6444676098F, 0.6449254119F,
  143603. 0.6453830207F, 0.6458404356F, 0.6462976562F, 0.6467546820F,
  143604. 0.6472115125F, 0.6476681472F, 0.6481245856F, 0.6485808273F,
  143605. 0.6490368717F, 0.6494927183F, 0.6499483667F, 0.6504038164F,
  143606. 0.6508590670F, 0.6513141178F, 0.6517689684F, 0.6522236185F,
  143607. 0.6526780673F, 0.6531323146F, 0.6535863598F, 0.6540402024F,
  143608. 0.6544938419F, 0.6549472779F, 0.6554005099F, 0.6558535373F,
  143609. 0.6563063598F, 0.6567589769F, 0.6572113880F, 0.6576635927F,
  143610. 0.6581155906F, 0.6585673810F, 0.6590189637F, 0.6594703380F,
  143611. 0.6599215035F, 0.6603724598F, 0.6608232064F, 0.6612737427F,
  143612. 0.6617240684F, 0.6621741829F, 0.6626240859F, 0.6630737767F,
  143613. 0.6635232550F, 0.6639725202F, 0.6644215720F, 0.6648704098F,
  143614. 0.6653190332F, 0.6657674417F, 0.6662156348F, 0.6666636121F,
  143615. 0.6671113731F, 0.6675589174F, 0.6680062445F, 0.6684533538F,
  143616. 0.6689002450F, 0.6693469177F, 0.6697933712F, 0.6702396052F,
  143617. 0.6706856193F, 0.6711314129F, 0.6715769855F, 0.6720223369F,
  143618. 0.6724674664F, 0.6729123736F, 0.6733570581F, 0.6738015194F,
  143619. 0.6742457570F, 0.6746897706F, 0.6751335596F, 0.6755771236F,
  143620. 0.6760204621F, 0.6764635747F, 0.6769064609F, 0.6773491204F,
  143621. 0.6777915525F, 0.6782337570F, 0.6786757332F, 0.6791174809F,
  143622. 0.6795589995F, 0.6800002886F, 0.6804413477F, 0.6808821765F,
  143623. 0.6813227743F, 0.6817631409F, 0.6822032758F, 0.6826431785F,
  143624. 0.6830828485F, 0.6835222855F, 0.6839614890F, 0.6844004585F,
  143625. 0.6848391936F, 0.6852776939F, 0.6857159589F, 0.6861539883F,
  143626. 0.6865917815F, 0.6870293381F, 0.6874666576F, 0.6879037398F,
  143627. 0.6883405840F, 0.6887771899F, 0.6892135571F, 0.6896496850F,
  143628. 0.6900855733F, 0.6905212216F, 0.6909566294F, 0.6913917963F,
  143629. 0.6918267218F, 0.6922614055F, 0.6926958471F, 0.6931300459F,
  143630. 0.6935640018F, 0.6939977141F, 0.6944311825F, 0.6948644066F,
  143631. 0.6952973859F, 0.6957301200F, 0.6961626085F, 0.6965948510F,
  143632. 0.6970268470F, 0.6974585961F, 0.6978900980F, 0.6983213521F,
  143633. 0.6987523580F, 0.6991831154F, 0.6996136238F, 0.7000438828F,
  143634. 0.7004738921F, 0.7009036510F, 0.7013331594F, 0.7017624166F,
  143635. 0.7021914224F, 0.7026201763F, 0.7030486779F, 0.7034769268F,
  143636. 0.7039049226F, 0.7043326648F, 0.7047601531F, 0.7051873870F,
  143637. 0.7056143662F, 0.7060410902F, 0.7064675586F, 0.7068937711F,
  143638. 0.7073197271F, 0.7077454264F, 0.7081708684F, 0.7085960529F,
  143639. 0.7090209793F, 0.7094456474F, 0.7098700566F, 0.7102942066F,
  143640. 0.7107180970F, 0.7111417274F, 0.7115650974F, 0.7119882066F,
  143641. 0.7124110545F, 0.7128336409F, 0.7132559653F, 0.7136780272F,
  143642. 0.7140998264F, 0.7145213624F, 0.7149426348F, 0.7153636433F,
  143643. 0.7157843874F, 0.7162048668F, 0.7166250810F, 0.7170450296F,
  143644. 0.7174647124F, 0.7178841289F, 0.7183032786F, 0.7187221613F,
  143645. 0.7191407765F, 0.7195591239F, 0.7199772030F, 0.7203950135F,
  143646. 0.7208125550F, 0.7212298271F, 0.7216468294F, 0.7220635616F,
  143647. 0.7224800233F, 0.7228962140F, 0.7233121335F, 0.7237277813F,
  143648. 0.7241431571F, 0.7245582604F, 0.7249730910F, 0.7253876484F,
  143649. 0.7258019322F, 0.7262159422F, 0.7266296778F, 0.7270431388F,
  143650. 0.7274563247F, 0.7278692353F, 0.7282818700F, 0.7286942287F,
  143651. 0.7291063108F, 0.7295181160F, 0.7299296440F, 0.7303408944F,
  143652. 0.7307518669F, 0.7311625609F, 0.7315729763F, 0.7319831126F,
  143653. 0.7323929695F, 0.7328025466F, 0.7332118435F, 0.7336208600F,
  143654. 0.7340295955F, 0.7344380499F, 0.7348462226F, 0.7352541134F,
  143655. 0.7356617220F, 0.7360690478F, 0.7364760907F, 0.7368828502F,
  143656. 0.7372893259F, 0.7376955176F, 0.7381014249F, 0.7385070475F,
  143657. 0.7389123849F, 0.7393174368F, 0.7397222029F, 0.7401266829F,
  143658. 0.7405308763F, 0.7409347829F, 0.7413384023F, 0.7417417341F,
  143659. 0.7421447780F, 0.7425475338F, 0.7429500009F, 0.7433521791F,
  143660. 0.7437540681F, 0.7441556674F, 0.7445569769F, 0.7449579960F,
  143661. 0.7453587245F, 0.7457591621F, 0.7461593084F, 0.7465591631F,
  143662. 0.7469587259F, 0.7473579963F, 0.7477569741F, 0.7481556590F,
  143663. 0.7485540506F, 0.7489521486F, 0.7493499526F, 0.7497474623F,
  143664. 0.7501446775F, 0.7505415977F, 0.7509382227F, 0.7513345521F,
  143665. 0.7517305856F, 0.7521263229F, 0.7525217636F, 0.7529169074F,
  143666. 0.7533117541F, 0.7537063032F, 0.7541005545F, 0.7544945076F,
  143667. 0.7548881623F, 0.7552815182F, 0.7556745749F, 0.7560673323F,
  143668. 0.7564597899F, 0.7568519474F, 0.7572438046F, 0.7576353611F,
  143669. 0.7580266166F, 0.7584175708F, 0.7588082235F, 0.7591985741F,
  143670. 0.7595886226F, 0.7599783685F, 0.7603678116F, 0.7607569515F,
  143671. 0.7611457879F, 0.7615343206F, 0.7619225493F, 0.7623104735F,
  143672. 0.7626980931F, 0.7630854078F, 0.7634724171F, 0.7638591209F,
  143673. 0.7642455188F, 0.7646316106F, 0.7650173959F, 0.7654028744F,
  143674. 0.7657880459F, 0.7661729100F, 0.7665574664F, 0.7669417150F,
  143675. 0.7673256553F, 0.7677092871F, 0.7680926100F, 0.7684756239F,
  143676. 0.7688583284F, 0.7692407232F, 0.7696228080F, 0.7700045826F,
  143677. 0.7703860467F, 0.7707671999F, 0.7711480420F, 0.7715285728F,
  143678. 0.7719087918F, 0.7722886989F, 0.7726682938F, 0.7730475762F,
  143679. 0.7734265458F, 0.7738052023F, 0.7741835454F, 0.7745615750F,
  143680. 0.7749392906F, 0.7753166921F, 0.7756937791F, 0.7760705514F,
  143681. 0.7764470087F, 0.7768231508F, 0.7771989773F, 0.7775744880F,
  143682. 0.7779496827F, 0.7783245610F, 0.7786991227F, 0.7790733676F,
  143683. 0.7794472953F, 0.7798209056F, 0.7801941982F, 0.7805671729F,
  143684. 0.7809398294F, 0.7813121675F, 0.7816841869F, 0.7820558873F,
  143685. 0.7824272684F, 0.7827983301F, 0.7831690720F, 0.7835394940F,
  143686. 0.7839095957F, 0.7842793768F, 0.7846488373F, 0.7850179767F,
  143687. 0.7853867948F, 0.7857552914F, 0.7861234663F, 0.7864913191F,
  143688. 0.7868588497F, 0.7872260578F, 0.7875929431F, 0.7879595055F,
  143689. 0.7883257445F, 0.7886916601F, 0.7890572520F, 0.7894225198F,
  143690. 0.7897874635F, 0.7901520827F, 0.7905163772F, 0.7908803468F,
  143691. 0.7912439912F, 0.7916073102F, 0.7919703035F, 0.7923329710F,
  143692. 0.7926953124F, 0.7930573274F, 0.7934190158F, 0.7937803774F,
  143693. 0.7941414120F, 0.7945021193F, 0.7948624991F, 0.7952225511F,
  143694. 0.7955822752F, 0.7959416711F, 0.7963007387F, 0.7966594775F,
  143695. 0.7970178875F, 0.7973759685F, 0.7977337201F, 0.7980911422F,
  143696. 0.7984482346F, 0.7988049970F, 0.7991614292F, 0.7995175310F,
  143697. 0.7998733022F, 0.8002287426F, 0.8005838519F, 0.8009386299F,
  143698. 0.8012930765F, 0.8016471914F, 0.8020009744F, 0.8023544253F,
  143699. 0.8027075438F, 0.8030603298F, 0.8034127831F, 0.8037649035F,
  143700. 0.8041166906F, 0.8044681445F, 0.8048192647F, 0.8051700512F,
  143701. 0.8055205038F, 0.8058706222F, 0.8062204062F, 0.8065698556F,
  143702. 0.8069189702F, 0.8072677499F, 0.8076161944F, 0.8079643036F,
  143703. 0.8083120772F, 0.8086595151F, 0.8090066170F, 0.8093533827F,
  143704. 0.8096998122F, 0.8100459051F, 0.8103916613F, 0.8107370806F,
  143705. 0.8110821628F, 0.8114269077F, 0.8117713151F, 0.8121153849F,
  143706. 0.8124591169F, 0.8128025108F, 0.8131455666F, 0.8134882839F,
  143707. 0.8138306627F, 0.8141727027F, 0.8145144038F, 0.8148557658F,
  143708. 0.8151967886F, 0.8155374718F, 0.8158778154F, 0.8162178192F,
  143709. 0.8165574830F, 0.8168968067F, 0.8172357900F, 0.8175744328F,
  143710. 0.8179127349F, 0.8182506962F, 0.8185883164F, 0.8189255955F,
  143711. 0.8192625332F, 0.8195991295F, 0.8199353840F, 0.8202712967F,
  143712. 0.8206068673F, 0.8209420958F, 0.8212769820F, 0.8216115256F,
  143713. 0.8219457266F, 0.8222795848F, 0.8226131000F, 0.8229462721F,
  143714. 0.8232791009F, 0.8236115863F, 0.8239437280F, 0.8242755260F,
  143715. 0.8246069801F, 0.8249380901F, 0.8252688559F, 0.8255992774F,
  143716. 0.8259293544F, 0.8262590867F, 0.8265884741F, 0.8269175167F,
  143717. 0.8272462141F, 0.8275745663F, 0.8279025732F, 0.8282302344F,
  143718. 0.8285575501F, 0.8288845199F, 0.8292111437F, 0.8295374215F,
  143719. 0.8298633530F, 0.8301889382F, 0.8305141768F, 0.8308390688F,
  143720. 0.8311636141F, 0.8314878124F, 0.8318116637F, 0.8321351678F,
  143721. 0.8324583246F, 0.8327811340F, 0.8331035957F, 0.8334257098F,
  143722. 0.8337474761F, 0.8340688944F, 0.8343899647F, 0.8347106867F,
  143723. 0.8350310605F, 0.8353510857F, 0.8356707624F, 0.8359900904F,
  143724. 0.8363090696F, 0.8366276999F, 0.8369459811F, 0.8372639131F,
  143725. 0.8375814958F, 0.8378987292F, 0.8382156130F, 0.8385321472F,
  143726. 0.8388483316F, 0.8391641662F, 0.8394796508F, 0.8397947853F,
  143727. 0.8401095697F, 0.8404240037F, 0.8407380873F, 0.8410518204F,
  143728. 0.8413652029F, 0.8416782347F, 0.8419909156F, 0.8423032456F,
  143729. 0.8426152245F, 0.8429268523F, 0.8432381289F, 0.8435490541F,
  143730. 0.8438596279F, 0.8441698502F, 0.8444797208F, 0.8447892396F,
  143731. 0.8450984067F, 0.8454072218F, 0.8457156849F, 0.8460237959F,
  143732. 0.8463315547F, 0.8466389612F, 0.8469460154F, 0.8472527170F,
  143733. 0.8475590661F, 0.8478650625F, 0.8481707063F, 0.8484759971F,
  143734. 0.8487809351F, 0.8490855201F, 0.8493897521F, 0.8496936308F,
  143735. 0.8499971564F, 0.8503003286F, 0.8506031474F, 0.8509056128F,
  143736. 0.8512077246F, 0.8515094828F, 0.8518108872F, 0.8521119379F,
  143737. 0.8524126348F, 0.8527129777F, 0.8530129666F, 0.8533126015F,
  143738. 0.8536118822F, 0.8539108087F, 0.8542093809F, 0.8545075988F,
  143739. 0.8548054623F, 0.8551029712F, 0.8554001257F, 0.8556969255F,
  143740. 0.8559933707F, 0.8562894611F, 0.8565851968F, 0.8568805775F,
  143741. 0.8571756034F, 0.8574702743F, 0.8577645902F, 0.8580585509F,
  143742. 0.8583521566F, 0.8586454070F, 0.8589383021F, 0.8592308420F,
  143743. 0.8595230265F, 0.8598148556F, 0.8601063292F, 0.8603974473F,
  143744. 0.8606882098F, 0.8609786167F, 0.8612686680F, 0.8615583636F,
  143745. 0.8618477034F, 0.8621366874F, 0.8624253156F, 0.8627135878F,
  143746. 0.8630015042F, 0.8632890646F, 0.8635762690F, 0.8638631173F,
  143747. 0.8641496096F, 0.8644357457F, 0.8647215257F, 0.8650069495F,
  143748. 0.8652920171F, 0.8655767283F, 0.8658610833F, 0.8661450820F,
  143749. 0.8664287243F, 0.8667120102F, 0.8669949397F, 0.8672775127F,
  143750. 0.8675597293F, 0.8678415894F, 0.8681230929F, 0.8684042398F,
  143751. 0.8686850302F, 0.8689654640F, 0.8692455412F, 0.8695252617F,
  143752. 0.8698046255F, 0.8700836327F, 0.8703622831F, 0.8706405768F,
  143753. 0.8709185138F, 0.8711960940F, 0.8714733174F, 0.8717501840F,
  143754. 0.8720266939F, 0.8723028469F, 0.8725786430F, 0.8728540824F,
  143755. 0.8731291648F, 0.8734038905F, 0.8736782592F, 0.8739522711F,
  143756. 0.8742259261F, 0.8744992242F, 0.8747721653F, 0.8750447496F,
  143757. 0.8753169770F, 0.8755888475F, 0.8758603611F, 0.8761315177F,
  143758. 0.8764023175F, 0.8766727603F, 0.8769428462F, 0.8772125752F,
  143759. 0.8774819474F, 0.8777509626F, 0.8780196209F, 0.8782879224F,
  143760. 0.8785558669F, 0.8788234546F, 0.8790906854F, 0.8793575594F,
  143761. 0.8796240765F, 0.8798902368F, 0.8801560403F, 0.8804214870F,
  143762. 0.8806865768F, 0.8809513099F, 0.8812156863F, 0.8814797059F,
  143763. 0.8817433687F, 0.8820066749F, 0.8822696243F, 0.8825322171F,
  143764. 0.8827944532F, 0.8830563327F, 0.8833178556F, 0.8835790219F,
  143765. 0.8838398316F, 0.8841002848F, 0.8843603815F, 0.8846201217F,
  143766. 0.8848795054F, 0.8851385327F, 0.8853972036F, 0.8856555182F,
  143767. 0.8859134764F, 0.8861710783F, 0.8864283239F, 0.8866852133F,
  143768. 0.8869417464F, 0.8871979234F, 0.8874537443F, 0.8877092090F,
  143769. 0.8879643177F, 0.8882190704F, 0.8884734671F, 0.8887275078F,
  143770. 0.8889811927F, 0.8892345216F, 0.8894874948F, 0.8897401122F,
  143771. 0.8899923738F, 0.8902442798F, 0.8904958301F, 0.8907470248F,
  143772. 0.8909978640F, 0.8912483477F, 0.8914984759F, 0.8917482487F,
  143773. 0.8919976662F, 0.8922467284F, 0.8924954353F, 0.8927437871F,
  143774. 0.8929917837F, 0.8932394252F, 0.8934867118F, 0.8937336433F,
  143775. 0.8939802199F, 0.8942264417F, 0.8944723087F, 0.8947178210F,
  143776. 0.8949629785F, 0.8952077815F, 0.8954522299F, 0.8956963239F,
  143777. 0.8959400634F, 0.8961834486F, 0.8964264795F, 0.8966691561F,
  143778. 0.8969114786F, 0.8971534470F, 0.8973950614F, 0.8976363219F,
  143779. 0.8978772284F, 0.8981177812F, 0.8983579802F, 0.8985978256F,
  143780. 0.8988373174F, 0.8990764556F, 0.8993152405F, 0.8995536720F,
  143781. 0.8997917502F, 0.9000294751F, 0.9002668470F, 0.9005038658F,
  143782. 0.9007405317F, 0.9009768446F, 0.9012128048F, 0.9014484123F,
  143783. 0.9016836671F, 0.9019185693F, 0.9021531191F, 0.9023873165F,
  143784. 0.9026211616F, 0.9028546546F, 0.9030877954F, 0.9033205841F,
  143785. 0.9035530210F, 0.9037851059F, 0.9040168392F, 0.9042482207F,
  143786. 0.9044792507F, 0.9047099293F, 0.9049402564F, 0.9051702323F,
  143787. 0.9053998569F, 0.9056291305F, 0.9058580531F, 0.9060866248F,
  143788. 0.9063148457F, 0.9065427159F, 0.9067702355F, 0.9069974046F,
  143789. 0.9072242233F, 0.9074506917F, 0.9076768100F, 0.9079025782F,
  143790. 0.9081279964F, 0.9083530647F, 0.9085777833F, 0.9088021523F,
  143791. 0.9090261717F, 0.9092498417F, 0.9094731623F, 0.9096961338F,
  143792. 0.9099187561F, 0.9101410295F, 0.9103629540F, 0.9105845297F,
  143793. 0.9108057568F, 0.9110266354F, 0.9112471656F, 0.9114673475F,
  143794. 0.9116871812F, 0.9119066668F, 0.9121258046F, 0.9123445945F,
  143795. 0.9125630367F, 0.9127811314F, 0.9129988786F, 0.9132162785F,
  143796. 0.9134333312F, 0.9136500368F, 0.9138663954F, 0.9140824073F,
  143797. 0.9142980724F, 0.9145133910F, 0.9147283632F, 0.9149429890F,
  143798. 0.9151572687F, 0.9153712023F, 0.9155847900F, 0.9157980319F,
  143799. 0.9160109282F, 0.9162234790F, 0.9164356844F, 0.9166475445F,
  143800. 0.9168590595F, 0.9170702296F, 0.9172810548F, 0.9174915354F,
  143801. 0.9177016714F, 0.9179114629F, 0.9181209102F, 0.9183300134F,
  143802. 0.9185387726F, 0.9187471879F, 0.9189552595F, 0.9191629876F,
  143803. 0.9193703723F, 0.9195774136F, 0.9197841119F, 0.9199904672F,
  143804. 0.9201964797F, 0.9204021495F, 0.9206074767F, 0.9208124616F,
  143805. 0.9210171043F, 0.9212214049F, 0.9214253636F, 0.9216289805F,
  143806. 0.9218322558F, 0.9220351896F, 0.9222377821F, 0.9224400335F,
  143807. 0.9226419439F, 0.9228435134F, 0.9230447423F, 0.9232456307F,
  143808. 0.9234461787F, 0.9236463865F, 0.9238462543F, 0.9240457822F,
  143809. 0.9242449704F, 0.9244438190F, 0.9246423282F, 0.9248404983F,
  143810. 0.9250383293F, 0.9252358214F, 0.9254329747F, 0.9256297896F,
  143811. 0.9258262660F, 0.9260224042F, 0.9262182044F, 0.9264136667F,
  143812. 0.9266087913F, 0.9268035783F, 0.9269980280F, 0.9271921405F,
  143813. 0.9273859160F, 0.9275793546F, 0.9277724566F, 0.9279652221F,
  143814. 0.9281576513F, 0.9283497443F, 0.9285415014F, 0.9287329227F,
  143815. 0.9289240084F, 0.9291147586F, 0.9293051737F, 0.9294952536F,
  143816. 0.9296849987F, 0.9298744091F, 0.9300634850F, 0.9302522266F,
  143817. 0.9304406340F, 0.9306287074F, 0.9308164471F, 0.9310038532F,
  143818. 0.9311909259F, 0.9313776654F, 0.9315640719F, 0.9317501455F,
  143819. 0.9319358865F, 0.9321212951F, 0.9323063713F, 0.9324911155F,
  143820. 0.9326755279F, 0.9328596085F, 0.9330433577F, 0.9332267756F,
  143821. 0.9334098623F, 0.9335926182F, 0.9337750434F, 0.9339571380F,
  143822. 0.9341389023F, 0.9343203366F, 0.9345014409F, 0.9346822155F,
  143823. 0.9348626606F, 0.9350427763F, 0.9352225630F, 0.9354020207F,
  143824. 0.9355811498F, 0.9357599503F, 0.9359384226F, 0.9361165667F,
  143825. 0.9362943830F, 0.9364718716F, 0.9366490327F, 0.9368258666F,
  143826. 0.9370023733F, 0.9371785533F, 0.9373544066F, 0.9375299335F,
  143827. 0.9377051341F, 0.9378800087F, 0.9380545576F, 0.9382287809F,
  143828. 0.9384026787F, 0.9385762515F, 0.9387494993F, 0.9389224223F,
  143829. 0.9390950209F, 0.9392672951F, 0.9394392453F, 0.9396108716F,
  143830. 0.9397821743F, 0.9399531536F, 0.9401238096F, 0.9402941427F,
  143831. 0.9404641530F, 0.9406338407F, 0.9408032061F, 0.9409722495F,
  143832. 0.9411409709F, 0.9413093707F, 0.9414774491F, 0.9416452062F,
  143833. 0.9418126424F, 0.9419797579F, 0.9421465528F, 0.9423130274F,
  143834. 0.9424791819F, 0.9426450166F, 0.9428105317F, 0.9429757274F,
  143835. 0.9431406039F, 0.9433051616F, 0.9434694005F, 0.9436333209F,
  143836. 0.9437969232F, 0.9439602074F, 0.9441231739F, 0.9442858229F,
  143837. 0.9444481545F, 0.9446101691F, 0.9447718669F, 0.9449332481F,
  143838. 0.9450943129F, 0.9452550617F, 0.9454154945F, 0.9455756118F,
  143839. 0.9457354136F, 0.9458949003F, 0.9460540721F, 0.9462129292F,
  143840. 0.9463714719F, 0.9465297003F, 0.9466876149F, 0.9468452157F,
  143841. 0.9470025031F, 0.9471594772F, 0.9473161384F, 0.9474724869F,
  143842. 0.9476285229F, 0.9477842466F, 0.9479396584F, 0.9480947585F,
  143843. 0.9482495470F, 0.9484040243F, 0.9485581906F, 0.9487120462F,
  143844. 0.9488655913F, 0.9490188262F, 0.9491717511F, 0.9493243662F,
  143845. 0.9494766718F, 0.9496286683F, 0.9497803557F, 0.9499317345F,
  143846. 0.9500828047F, 0.9502335668F, 0.9503840209F, 0.9505341673F,
  143847. 0.9506840062F, 0.9508335380F, 0.9509827629F, 0.9511316810F,
  143848. 0.9512802928F, 0.9514285984F, 0.9515765982F, 0.9517242923F,
  143849. 0.9518716810F, 0.9520187646F, 0.9521655434F, 0.9523120176F,
  143850. 0.9524581875F, 0.9526040534F, 0.9527496154F, 0.9528948739F,
  143851. 0.9530398292F, 0.9531844814F, 0.9533288310F, 0.9534728780F,
  143852. 0.9536166229F, 0.9537600659F, 0.9539032071F, 0.9540460470F,
  143853. 0.9541885858F, 0.9543308237F, 0.9544727611F, 0.9546143981F,
  143854. 0.9547557351F, 0.9548967723F, 0.9550375100F, 0.9551779485F,
  143855. 0.9553180881F, 0.9554579290F, 0.9555974714F, 0.9557367158F,
  143856. 0.9558756623F, 0.9560143112F, 0.9561526628F, 0.9562907174F,
  143857. 0.9564284752F, 0.9565659366F, 0.9567031017F, 0.9568399710F,
  143858. 0.9569765446F, 0.9571128229F, 0.9572488061F, 0.9573844944F,
  143859. 0.9575198883F, 0.9576549879F, 0.9577897936F, 0.9579243056F,
  143860. 0.9580585242F, 0.9581924497F, 0.9583260824F, 0.9584594226F,
  143861. 0.9585924705F, 0.9587252264F, 0.9588576906F, 0.9589898634F,
  143862. 0.9591217452F, 0.9592533360F, 0.9593846364F, 0.9595156465F,
  143863. 0.9596463666F, 0.9597767971F, 0.9599069382F, 0.9600367901F,
  143864. 0.9601663533F, 0.9602956279F, 0.9604246143F, 0.9605533128F,
  143865. 0.9606817236F, 0.9608098471F, 0.9609376835F, 0.9610652332F,
  143866. 0.9611924963F, 0.9613194733F, 0.9614461644F, 0.9615725699F,
  143867. 0.9616986901F, 0.9618245253F, 0.9619500757F, 0.9620753418F,
  143868. 0.9622003238F, 0.9623250219F, 0.9624494365F, 0.9625735679F,
  143869. 0.9626974163F, 0.9628209821F, 0.9629442656F, 0.9630672671F,
  143870. 0.9631899868F, 0.9633124251F, 0.9634345822F, 0.9635564585F,
  143871. 0.9636780543F, 0.9637993699F, 0.9639204056F, 0.9640411616F,
  143872. 0.9641616383F, 0.9642818359F, 0.9644017549F, 0.9645213955F,
  143873. 0.9646407579F, 0.9647598426F, 0.9648786497F, 0.9649971797F,
  143874. 0.9651154328F, 0.9652334092F, 0.9653511095F, 0.9654685337F,
  143875. 0.9655856823F, 0.9657025556F, 0.9658191538F, 0.9659354773F,
  143876. 0.9660515263F, 0.9661673013F, 0.9662828024F, 0.9663980300F,
  143877. 0.9665129845F, 0.9666276660F, 0.9667420750F, 0.9668562118F,
  143878. 0.9669700766F, 0.9670836698F, 0.9671969917F, 0.9673100425F,
  143879. 0.9674228227F, 0.9675353325F, 0.9676475722F, 0.9677595422F,
  143880. 0.9678712428F, 0.9679826742F, 0.9680938368F, 0.9682047309F,
  143881. 0.9683153569F, 0.9684257150F, 0.9685358056F, 0.9686456289F,
  143882. 0.9687551853F, 0.9688644752F, 0.9689734987F, 0.9690822564F,
  143883. 0.9691907483F, 0.9692989750F, 0.9694069367F, 0.9695146337F,
  143884. 0.9696220663F, 0.9697292349F, 0.9698361398F, 0.9699427813F,
  143885. 0.9700491597F, 0.9701552754F, 0.9702611286F, 0.9703667197F,
  143886. 0.9704720490F, 0.9705771169F, 0.9706819236F, 0.9707864695F,
  143887. 0.9708907549F, 0.9709947802F, 0.9710985456F, 0.9712020514F,
  143888. 0.9713052981F, 0.9714082859F, 0.9715110151F, 0.9716134862F,
  143889. 0.9717156993F, 0.9718176549F, 0.9719193532F, 0.9720207946F,
  143890. 0.9721219794F, 0.9722229080F, 0.9723235806F, 0.9724239976F,
  143891. 0.9725241593F, 0.9726240661F, 0.9727237183F, 0.9728231161F,
  143892. 0.9729222601F, 0.9730211503F, 0.9731197873F, 0.9732181713F,
  143893. 0.9733163027F, 0.9734141817F, 0.9735118088F, 0.9736091842F,
  143894. 0.9737063083F, 0.9738031814F, 0.9738998039F, 0.9739961760F,
  143895. 0.9740922981F, 0.9741881706F, 0.9742837938F, 0.9743791680F,
  143896. 0.9744742935F, 0.9745691707F, 0.9746637999F, 0.9747581814F,
  143897. 0.9748523157F, 0.9749462029F, 0.9750398435F, 0.9751332378F,
  143898. 0.9752263861F, 0.9753192887F, 0.9754119461F, 0.9755043585F,
  143899. 0.9755965262F, 0.9756884496F, 0.9757801291F, 0.9758715650F,
  143900. 0.9759627575F, 0.9760537071F, 0.9761444141F, 0.9762348789F,
  143901. 0.9763251016F, 0.9764150828F, 0.9765048228F, 0.9765943218F,
  143902. 0.9766835802F, 0.9767725984F, 0.9768613767F, 0.9769499154F,
  143903. 0.9770382149F, 0.9771262755F, 0.9772140976F, 0.9773016815F,
  143904. 0.9773890275F, 0.9774761360F, 0.9775630073F, 0.9776496418F,
  143905. 0.9777360398F, 0.9778222016F, 0.9779081277F, 0.9779938182F,
  143906. 0.9780792736F, 0.9781644943F, 0.9782494805F, 0.9783342326F,
  143907. 0.9784187509F, 0.9785030359F, 0.9785870877F, 0.9786709069F,
  143908. 0.9787544936F, 0.9788378484F, 0.9789209714F, 0.9790038631F,
  143909. 0.9790865238F, 0.9791689538F, 0.9792511535F, 0.9793331232F,
  143910. 0.9794148633F, 0.9794963742F, 0.9795776561F, 0.9796587094F,
  143911. 0.9797395345F, 0.9798201316F, 0.9799005013F, 0.9799806437F,
  143912. 0.9800605593F, 0.9801402483F, 0.9802197112F, 0.9802989483F,
  143913. 0.9803779600F, 0.9804567465F, 0.9805353082F, 0.9806136455F,
  143914. 0.9806917587F, 0.9807696482F, 0.9808473143F, 0.9809247574F,
  143915. 0.9810019778F, 0.9810789759F, 0.9811557519F, 0.9812323064F,
  143916. 0.9813086395F, 0.9813847517F, 0.9814606433F, 0.9815363147F,
  143917. 0.9816117662F, 0.9816869981F, 0.9817620108F, 0.9818368047F,
  143918. 0.9819113801F, 0.9819857374F, 0.9820598769F, 0.9821337989F,
  143919. 0.9822075038F, 0.9822809920F, 0.9823542638F, 0.9824273195F,
  143920. 0.9825001596F, 0.9825727843F, 0.9826451940F, 0.9827173891F,
  143921. 0.9827893700F, 0.9828611368F, 0.9829326901F, 0.9830040302F,
  143922. 0.9830751574F, 0.9831460720F, 0.9832167745F, 0.9832872652F,
  143923. 0.9833575444F, 0.9834276124F, 0.9834974697F, 0.9835671166F,
  143924. 0.9836365535F, 0.9837057806F, 0.9837747983F, 0.9838436071F,
  143925. 0.9839122072F, 0.9839805990F, 0.9840487829F, 0.9841167591F,
  143926. 0.9841845282F, 0.9842520903F, 0.9843194459F, 0.9843865953F,
  143927. 0.9844535389F, 0.9845202771F, 0.9845868101F, 0.9846531383F,
  143928. 0.9847192622F, 0.9847851820F, 0.9848508980F, 0.9849164108F,
  143929. 0.9849817205F, 0.9850468276F, 0.9851117324F, 0.9851764352F,
  143930. 0.9852409365F, 0.9853052366F, 0.9853693358F, 0.9854332344F,
  143931. 0.9854969330F, 0.9855604317F, 0.9856237309F, 0.9856868310F,
  143932. 0.9857497325F, 0.9858124355F, 0.9858749404F, 0.9859372477F,
  143933. 0.9859993577F, 0.9860612707F, 0.9861229871F, 0.9861845072F,
  143934. 0.9862458315F, 0.9863069601F, 0.9863678936F, 0.9864286322F,
  143935. 0.9864891764F, 0.9865495264F, 0.9866096826F, 0.9866696454F,
  143936. 0.9867294152F, 0.9867889922F, 0.9868483769F, 0.9869075695F,
  143937. 0.9869665706F, 0.9870253803F, 0.9870839991F, 0.9871424273F,
  143938. 0.9872006653F, 0.9872587135F, 0.9873165721F, 0.9873742415F,
  143939. 0.9874317222F, 0.9874890144F, 0.9875461185F, 0.9876030348F,
  143940. 0.9876597638F, 0.9877163057F, 0.9877726610F, 0.9878288300F,
  143941. 0.9878848130F, 0.9879406104F, 0.9879962225F, 0.9880516497F,
  143942. 0.9881068924F, 0.9881619509F, 0.9882168256F, 0.9882715168F,
  143943. 0.9883260249F, 0.9883803502F, 0.9884344931F, 0.9884884539F,
  143944. 0.9885422331F, 0.9885958309F, 0.9886492477F, 0.9887024838F,
  143945. 0.9887555397F, 0.9888084157F, 0.9888611120F, 0.9889136292F,
  143946. 0.9889659675F, 0.9890181273F, 0.9890701089F, 0.9891219128F,
  143947. 0.9891735392F, 0.9892249885F, 0.9892762610F, 0.9893273572F,
  143948. 0.9893782774F, 0.9894290219F, 0.9894795911F, 0.9895299853F,
  143949. 0.9895802049F, 0.9896302502F, 0.9896801217F, 0.9897298196F,
  143950. 0.9897793443F, 0.9898286961F, 0.9898778755F, 0.9899268828F,
  143951. 0.9899757183F, 0.9900243823F, 0.9900728753F, 0.9901211976F,
  143952. 0.9901693495F, 0.9902173314F, 0.9902651436F, 0.9903127865F,
  143953. 0.9903602605F, 0.9904075659F, 0.9904547031F, 0.9905016723F,
  143954. 0.9905484740F, 0.9905951086F, 0.9906415763F, 0.9906878775F,
  143955. 0.9907340126F, 0.9907799819F, 0.9908257858F, 0.9908714247F,
  143956. 0.9909168988F, 0.9909622086F, 0.9910073543F, 0.9910523364F,
  143957. 0.9910971552F, 0.9911418110F, 0.9911863042F, 0.9912306351F,
  143958. 0.9912748042F, 0.9913188117F, 0.9913626580F, 0.9914063435F,
  143959. 0.9914498684F, 0.9914932333F, 0.9915364383F, 0.9915794839F,
  143960. 0.9916223703F, 0.9916650981F, 0.9917076674F, 0.9917500787F,
  143961. 0.9917923323F, 0.9918344286F, 0.9918763679F, 0.9919181505F,
  143962. 0.9919597769F, 0.9920012473F, 0.9920425621F, 0.9920837217F,
  143963. 0.9921247263F, 0.9921655765F, 0.9922062724F, 0.9922468145F,
  143964. 0.9922872030F, 0.9923274385F, 0.9923675211F, 0.9924074513F,
  143965. 0.9924472294F, 0.9924868557F, 0.9925263306F, 0.9925656544F,
  143966. 0.9926048275F, 0.9926438503F, 0.9926827230F, 0.9927214461F,
  143967. 0.9927600199F, 0.9927984446F, 0.9928367208F, 0.9928748486F,
  143968. 0.9929128285F, 0.9929506608F, 0.9929883459F, 0.9930258841F,
  143969. 0.9930632757F, 0.9931005211F, 0.9931376207F, 0.9931745747F,
  143970. 0.9932113836F, 0.9932480476F, 0.9932845671F, 0.9933209425F,
  143971. 0.9933571742F, 0.9933932623F, 0.9934292074F, 0.9934650097F,
  143972. 0.9935006696F, 0.9935361874F, 0.9935715635F, 0.9936067982F,
  143973. 0.9936418919F, 0.9936768448F, 0.9937116574F, 0.9937463300F,
  143974. 0.9937808629F, 0.9938152565F, 0.9938495111F, 0.9938836271F,
  143975. 0.9939176047F, 0.9939514444F, 0.9939851465F, 0.9940187112F,
  143976. 0.9940521391F, 0.9940854303F, 0.9941185853F, 0.9941516044F,
  143977. 0.9941844879F, 0.9942172361F, 0.9942498495F, 0.9942823283F,
  143978. 0.9943146729F, 0.9943468836F, 0.9943789608F, 0.9944109047F,
  143979. 0.9944427158F, 0.9944743944F, 0.9945059408F, 0.9945373553F,
  143980. 0.9945686384F, 0.9945997902F, 0.9946308112F, 0.9946617017F,
  143981. 0.9946924621F, 0.9947230926F, 0.9947535937F, 0.9947839656F,
  143982. 0.9948142086F, 0.9948443232F, 0.9948743097F, 0.9949041683F,
  143983. 0.9949338995F, 0.9949635035F, 0.9949929807F, 0.9950223315F,
  143984. 0.9950515561F, 0.9950806549F, 0.9951096282F, 0.9951384764F,
  143985. 0.9951671998F, 0.9951957987F, 0.9952242735F, 0.9952526245F,
  143986. 0.9952808520F, 0.9953089564F, 0.9953369380F, 0.9953647971F,
  143987. 0.9953925340F, 0.9954201491F, 0.9954476428F, 0.9954750153F,
  143988. 0.9955022670F, 0.9955293981F, 0.9955564092F, 0.9955833003F,
  143989. 0.9956100720F, 0.9956367245F, 0.9956632582F, 0.9956896733F,
  143990. 0.9957159703F, 0.9957421494F, 0.9957682110F, 0.9957941553F,
  143991. 0.9958199828F, 0.9958456937F, 0.9958712884F, 0.9958967672F,
  143992. 0.9959221305F, 0.9959473784F, 0.9959725115F, 0.9959975300F,
  143993. 0.9960224342F, 0.9960472244F, 0.9960719011F, 0.9960964644F,
  143994. 0.9961209148F, 0.9961452525F, 0.9961694779F, 0.9961935913F,
  143995. 0.9962175930F, 0.9962414834F, 0.9962652627F, 0.9962889313F,
  143996. 0.9963124895F, 0.9963359377F, 0.9963592761F, 0.9963825051F,
  143997. 0.9964056250F, 0.9964286361F, 0.9964515387F, 0.9964743332F,
  143998. 0.9964970198F, 0.9965195990F, 0.9965420709F, 0.9965644360F,
  143999. 0.9965866946F, 0.9966088469F, 0.9966308932F, 0.9966528340F,
  144000. 0.9966746695F, 0.9966964001F, 0.9967180260F, 0.9967395475F,
  144001. 0.9967609651F, 0.9967822789F, 0.9968034894F, 0.9968245968F,
  144002. 0.9968456014F, 0.9968665036F, 0.9968873037F, 0.9969080019F,
  144003. 0.9969285987F, 0.9969490942F, 0.9969694889F, 0.9969897830F,
  144004. 0.9970099769F, 0.9970300708F, 0.9970500651F, 0.9970699601F,
  144005. 0.9970897561F, 0.9971094533F, 0.9971290522F, 0.9971485531F,
  144006. 0.9971679561F, 0.9971872617F, 0.9972064702F, 0.9972255818F,
  144007. 0.9972445968F, 0.9972635157F, 0.9972823386F, 0.9973010659F,
  144008. 0.9973196980F, 0.9973382350F, 0.9973566773F, 0.9973750253F,
  144009. 0.9973932791F, 0.9974114392F, 0.9974295059F, 0.9974474793F,
  144010. 0.9974653599F, 0.9974831480F, 0.9975008438F, 0.9975184476F,
  144011. 0.9975359598F, 0.9975533806F, 0.9975707104F, 0.9975879495F,
  144012. 0.9976050981F, 0.9976221566F, 0.9976391252F, 0.9976560043F,
  144013. 0.9976727941F, 0.9976894950F, 0.9977061073F, 0.9977226312F,
  144014. 0.9977390671F, 0.9977554152F, 0.9977716759F, 0.9977878495F,
  144015. 0.9978039361F, 0.9978199363F, 0.9978358501F, 0.9978516780F,
  144016. 0.9978674202F, 0.9978830771F, 0.9978986488F, 0.9979141358F,
  144017. 0.9979295383F, 0.9979448566F, 0.9979600909F, 0.9979752417F,
  144018. 0.9979903091F, 0.9980052936F, 0.9980201952F, 0.9980350145F,
  144019. 0.9980497515F, 0.9980644067F, 0.9980789804F, 0.9980934727F,
  144020. 0.9981078841F, 0.9981222147F, 0.9981364649F, 0.9981506350F,
  144021. 0.9981647253F, 0.9981787360F, 0.9981926674F, 0.9982065199F,
  144022. 0.9982202936F, 0.9982339890F, 0.9982476062F, 0.9982611456F,
  144023. 0.9982746074F, 0.9982879920F, 0.9983012996F, 0.9983145304F,
  144024. 0.9983276849F, 0.9983407632F, 0.9983537657F, 0.9983666926F,
  144025. 0.9983795442F, 0.9983923208F, 0.9984050226F, 0.9984176501F,
  144026. 0.9984302033F, 0.9984426827F, 0.9984550884F, 0.9984674208F,
  144027. 0.9984796802F, 0.9984918667F, 0.9985039808F, 0.9985160227F,
  144028. 0.9985279926F, 0.9985398909F, 0.9985517177F, 0.9985634734F,
  144029. 0.9985751583F, 0.9985867727F, 0.9985983167F, 0.9986097907F,
  144030. 0.9986211949F, 0.9986325297F, 0.9986437953F, 0.9986549919F,
  144031. 0.9986661199F, 0.9986771795F, 0.9986881710F, 0.9986990946F,
  144032. 0.9987099507F, 0.9987207394F, 0.9987314611F, 0.9987421161F,
  144033. 0.9987527045F, 0.9987632267F, 0.9987736829F, 0.9987840734F,
  144034. 0.9987943985F, 0.9988046584F, 0.9988148534F, 0.9988249838F,
  144035. 0.9988350498F, 0.9988450516F, 0.9988549897F, 0.9988648641F,
  144036. 0.9988746753F, 0.9988844233F, 0.9988941086F, 0.9989037313F,
  144037. 0.9989132918F, 0.9989227902F, 0.9989322269F, 0.9989416021F,
  144038. 0.9989509160F, 0.9989601690F, 0.9989693613F, 0.9989784931F,
  144039. 0.9989875647F, 0.9989965763F, 0.9990055283F, 0.9990144208F,
  144040. 0.9990232541F, 0.9990320286F, 0.9990407443F, 0.9990494016F,
  144041. 0.9990580008F, 0.9990665421F, 0.9990750257F, 0.9990834519F,
  144042. 0.9990918209F, 0.9991001331F, 0.9991083886F, 0.9991165877F,
  144043. 0.9991247307F, 0.9991328177F, 0.9991408491F, 0.9991488251F,
  144044. 0.9991567460F, 0.9991646119F, 0.9991724232F, 0.9991801801F,
  144045. 0.9991878828F, 0.9991955316F, 0.9992031267F, 0.9992106684F,
  144046. 0.9992181569F, 0.9992255925F, 0.9992329753F, 0.9992403057F,
  144047. 0.9992475839F, 0.9992548101F, 0.9992619846F, 0.9992691076F,
  144048. 0.9992761793F, 0.9992832001F, 0.9992901701F, 0.9992970895F,
  144049. 0.9993039587F, 0.9993107777F, 0.9993175470F, 0.9993242667F,
  144050. 0.9993309371F, 0.9993375583F, 0.9993441307F, 0.9993506545F,
  144051. 0.9993571298F, 0.9993635570F, 0.9993699362F, 0.9993762678F,
  144052. 0.9993825519F, 0.9993887887F, 0.9993949785F, 0.9994011216F,
  144053. 0.9994072181F, 0.9994132683F, 0.9994192725F, 0.9994252307F,
  144054. 0.9994311434F, 0.9994370107F, 0.9994428327F, 0.9994486099F,
  144055. 0.9994543423F, 0.9994600303F, 0.9994656739F, 0.9994712736F,
  144056. 0.9994768294F, 0.9994823417F, 0.9994878105F, 0.9994932363F,
  144057. 0.9994986191F, 0.9995039592F, 0.9995092568F, 0.9995145122F,
  144058. 0.9995197256F, 0.9995248971F, 0.9995300270F, 0.9995351156F,
  144059. 0.9995401630F, 0.9995451695F, 0.9995501352F, 0.9995550604F,
  144060. 0.9995599454F, 0.9995647903F, 0.9995695953F, 0.9995743607F,
  144061. 0.9995790866F, 0.9995837734F, 0.9995884211F, 0.9995930300F,
  144062. 0.9995976004F, 0.9996021324F, 0.9996066263F, 0.9996110822F,
  144063. 0.9996155004F, 0.9996198810F, 0.9996242244F, 0.9996285306F,
  144064. 0.9996327999F, 0.9996370326F, 0.9996412287F, 0.9996453886F,
  144065. 0.9996495125F, 0.9996536004F, 0.9996576527F, 0.9996616696F,
  144066. 0.9996656512F, 0.9996695977F, 0.9996735094F, 0.9996773865F,
  144067. 0.9996812291F, 0.9996850374F, 0.9996888118F, 0.9996925523F,
  144068. 0.9996962591F, 0.9996999325F, 0.9997035727F, 0.9997071798F,
  144069. 0.9997107541F, 0.9997142957F, 0.9997178049F, 0.9997212818F,
  144070. 0.9997247266F, 0.9997281396F, 0.9997315209F, 0.9997348708F,
  144071. 0.9997381893F, 0.9997414767F, 0.9997447333F, 0.9997479591F,
  144072. 0.9997511544F, 0.9997543194F, 0.9997574542F, 0.9997605591F,
  144073. 0.9997636342F, 0.9997666797F, 0.9997696958F, 0.9997726828F,
  144074. 0.9997756407F, 0.9997785698F, 0.9997814703F, 0.9997843423F,
  144075. 0.9997871860F, 0.9997900016F, 0.9997927894F, 0.9997955494F,
  144076. 0.9997982818F, 0.9998009869F, 0.9998036648F, 0.9998063157F,
  144077. 0.9998089398F, 0.9998115373F, 0.9998141082F, 0.9998166529F,
  144078. 0.9998191715F, 0.9998216642F, 0.9998241311F, 0.9998265724F,
  144079. 0.9998289884F, 0.9998313790F, 0.9998337447F, 0.9998360854F,
  144080. 0.9998384015F, 0.9998406930F, 0.9998429602F, 0.9998452031F,
  144081. 0.9998474221F, 0.9998496171F, 0.9998517885F, 0.9998539364F,
  144082. 0.9998560610F, 0.9998581624F, 0.9998602407F, 0.9998622962F,
  144083. 0.9998643291F, 0.9998663394F, 0.9998683274F, 0.9998702932F,
  144084. 0.9998722370F, 0.9998741589F, 0.9998760591F, 0.9998779378F,
  144085. 0.9998797952F, 0.9998816313F, 0.9998834464F, 0.9998852406F,
  144086. 0.9998870141F, 0.9998887670F, 0.9998904995F, 0.9998922117F,
  144087. 0.9998939039F, 0.9998955761F, 0.9998972285F, 0.9998988613F,
  144088. 0.9999004746F, 0.9999020686F, 0.9999036434F, 0.9999051992F,
  144089. 0.9999067362F, 0.9999082544F, 0.9999097541F, 0.9999112354F,
  144090. 0.9999126984F, 0.9999141433F, 0.9999155703F, 0.9999169794F,
  144091. 0.9999183709F, 0.9999197449F, 0.9999211014F, 0.9999224408F,
  144092. 0.9999237631F, 0.9999250684F, 0.9999263570F, 0.9999276289F,
  144093. 0.9999288843F, 0.9999301233F, 0.9999313461F, 0.9999325529F,
  144094. 0.9999337437F, 0.9999349187F, 0.9999360780F, 0.9999372218F,
  144095. 0.9999383503F, 0.9999394635F, 0.9999405616F, 0.9999416447F,
  144096. 0.9999427129F, 0.9999437665F, 0.9999448055F, 0.9999458301F,
  144097. 0.9999468404F, 0.9999478365F, 0.9999488185F, 0.9999497867F,
  144098. 0.9999507411F, 0.9999516819F, 0.9999526091F, 0.9999535230F,
  144099. 0.9999544236F, 0.9999553111F, 0.9999561856F, 0.9999570472F,
  144100. 0.9999578960F, 0.9999587323F, 0.9999595560F, 0.9999603674F,
  144101. 0.9999611666F, 0.9999619536F, 0.9999627286F, 0.9999634917F,
  144102. 0.9999642431F, 0.9999649828F, 0.9999657110F, 0.9999664278F,
  144103. 0.9999671334F, 0.9999678278F, 0.9999685111F, 0.9999691835F,
  144104. 0.9999698451F, 0.9999704960F, 0.9999711364F, 0.9999717662F,
  144105. 0.9999723858F, 0.9999729950F, 0.9999735942F, 0.9999741834F,
  144106. 0.9999747626F, 0.9999753321F, 0.9999758919F, 0.9999764421F,
  144107. 0.9999769828F, 0.9999775143F, 0.9999780364F, 0.9999785495F,
  144108. 0.9999790535F, 0.9999795485F, 0.9999800348F, 0.9999805124F,
  144109. 0.9999809813F, 0.9999814417F, 0.9999818938F, 0.9999823375F,
  144110. 0.9999827731F, 0.9999832005F, 0.9999836200F, 0.9999840316F,
  144111. 0.9999844353F, 0.9999848314F, 0.9999852199F, 0.9999856008F,
  144112. 0.9999859744F, 0.9999863407F, 0.9999866997F, 0.9999870516F,
  144113. 0.9999873965F, 0.9999877345F, 0.9999880656F, 0.9999883900F,
  144114. 0.9999887078F, 0.9999890190F, 0.9999893237F, 0.9999896220F,
  144115. 0.9999899140F, 0.9999901999F, 0.9999904796F, 0.9999907533F,
  144116. 0.9999910211F, 0.9999912830F, 0.9999915391F, 0.9999917896F,
  144117. 0.9999920345F, 0.9999922738F, 0.9999925077F, 0.9999927363F,
  144118. 0.9999929596F, 0.9999931777F, 0.9999933907F, 0.9999935987F,
  144119. 0.9999938018F, 0.9999940000F, 0.9999941934F, 0.9999943820F,
  144120. 0.9999945661F, 0.9999947456F, 0.9999949206F, 0.9999950912F,
  144121. 0.9999952575F, 0.9999954195F, 0.9999955773F, 0.9999957311F,
  144122. 0.9999958807F, 0.9999960265F, 0.9999961683F, 0.9999963063F,
  144123. 0.9999964405F, 0.9999965710F, 0.9999966979F, 0.9999968213F,
  144124. 0.9999969412F, 0.9999970576F, 0.9999971707F, 0.9999972805F,
  144125. 0.9999973871F, 0.9999974905F, 0.9999975909F, 0.9999976881F,
  144126. 0.9999977824F, 0.9999978738F, 0.9999979624F, 0.9999980481F,
  144127. 0.9999981311F, 0.9999982115F, 0.9999982892F, 0.9999983644F,
  144128. 0.9999984370F, 0.9999985072F, 0.9999985750F, 0.9999986405F,
  144129. 0.9999987037F, 0.9999987647F, 0.9999988235F, 0.9999988802F,
  144130. 0.9999989348F, 0.9999989873F, 0.9999990379F, 0.9999990866F,
  144131. 0.9999991334F, 0.9999991784F, 0.9999992217F, 0.9999992632F,
  144132. 0.9999993030F, 0.9999993411F, 0.9999993777F, 0.9999994128F,
  144133. 0.9999994463F, 0.9999994784F, 0.9999995091F, 0.9999995384F,
  144134. 0.9999995663F, 0.9999995930F, 0.9999996184F, 0.9999996426F,
  144135. 0.9999996657F, 0.9999996876F, 0.9999997084F, 0.9999997282F,
  144136. 0.9999997469F, 0.9999997647F, 0.9999997815F, 0.9999997973F,
  144137. 0.9999998123F, 0.9999998265F, 0.9999998398F, 0.9999998524F,
  144138. 0.9999998642F, 0.9999998753F, 0.9999998857F, 0.9999998954F,
  144139. 0.9999999045F, 0.9999999130F, 0.9999999209F, 0.9999999282F,
  144140. 0.9999999351F, 0.9999999414F, 0.9999999472F, 0.9999999526F,
  144141. 0.9999999576F, 0.9999999622F, 0.9999999664F, 0.9999999702F,
  144142. 0.9999999737F, 0.9999999769F, 0.9999999798F, 0.9999999824F,
  144143. 0.9999999847F, 0.9999999868F, 0.9999999887F, 0.9999999904F,
  144144. 0.9999999919F, 0.9999999932F, 0.9999999943F, 0.9999999953F,
  144145. 0.9999999961F, 0.9999999969F, 0.9999999975F, 0.9999999980F,
  144146. 0.9999999985F, 0.9999999988F, 0.9999999991F, 0.9999999993F,
  144147. 0.9999999995F, 0.9999999997F, 0.9999999998F, 0.9999999999F,
  144148. 0.9999999999F, 1.0000000000F, 1.0000000000F, 1.0000000000F,
  144149. 1.0000000000F, 1.0000000000F, 1.0000000000F, 1.0000000000F,
  144150. };
  144151. static float *vwin[8] = {
  144152. vwin64,
  144153. vwin128,
  144154. vwin256,
  144155. vwin512,
  144156. vwin1024,
  144157. vwin2048,
  144158. vwin4096,
  144159. vwin8192,
  144160. };
  144161. float *_vorbis_window_get(int n){
  144162. return vwin[n];
  144163. }
  144164. void _vorbis_apply_window(float *d,int *winno,long *blocksizes,
  144165. int lW,int W,int nW){
  144166. lW=(W?lW:0);
  144167. nW=(W?nW:0);
  144168. {
  144169. float *windowLW=vwin[winno[lW]];
  144170. float *windowNW=vwin[winno[nW]];
  144171. long n=blocksizes[W];
  144172. long ln=blocksizes[lW];
  144173. long rn=blocksizes[nW];
  144174. long leftbegin=n/4-ln/4;
  144175. long leftend=leftbegin+ln/2;
  144176. long rightbegin=n/2+n/4-rn/4;
  144177. long rightend=rightbegin+rn/2;
  144178. int i,p;
  144179. for(i=0;i<leftbegin;i++)
  144180. d[i]=0.f;
  144181. for(p=0;i<leftend;i++,p++)
  144182. d[i]*=windowLW[p];
  144183. for(i=rightbegin,p=rn/2-1;i<rightend;i++,p--)
  144184. d[i]*=windowNW[p];
  144185. for(;i<n;i++)
  144186. d[i]=0.f;
  144187. }
  144188. }
  144189. #endif
  144190. /*** End of inlined file: window.c ***/
  144191. #else
  144192. #include <vorbis/vorbisenc.h>
  144193. #include <vorbis/codec.h>
  144194. #include <vorbis/vorbisfile.h>
  144195. #endif
  144196. }
  144197. BEGIN_JUCE_NAMESPACE
  144198. static const char* const oggFormatName = "Ogg-Vorbis file";
  144199. static const tchar* const oggExtensions[] = { T(".ogg"), 0 };
  144200. class OggReader : public AudioFormatReader
  144201. {
  144202. OggVorbisNamespace::OggVorbis_File ovFile;
  144203. OggVorbisNamespace::ov_callbacks callbacks;
  144204. AudioSampleBuffer reservoir;
  144205. int reservoirStart, samplesInReservoir;
  144206. public:
  144207. OggReader (InputStream* const inp)
  144208. : AudioFormatReader (inp, TRANS (oggFormatName)),
  144209. reservoir (2, 4096),
  144210. reservoirStart (0),
  144211. samplesInReservoir (0)
  144212. {
  144213. using namespace OggVorbisNamespace;
  144214. sampleRate = 0;
  144215. usesFloatingPointData = true;
  144216. callbacks.read_func = &oggReadCallback;
  144217. callbacks.seek_func = &oggSeekCallback;
  144218. callbacks.close_func = &oggCloseCallback;
  144219. callbacks.tell_func = &oggTellCallback;
  144220. const int err = ov_open_callbacks (input, &ovFile, 0, 0, callbacks);
  144221. if (err == 0)
  144222. {
  144223. vorbis_info* info = ov_info (&ovFile, -1);
  144224. lengthInSamples = (uint32) ov_pcm_total (&ovFile, -1);
  144225. numChannels = info->channels;
  144226. bitsPerSample = 16;
  144227. sampleRate = info->rate;
  144228. reservoir.setSize (numChannels,
  144229. (int) jmin (lengthInSamples, (int64) reservoir.getNumSamples()));
  144230. }
  144231. }
  144232. ~OggReader()
  144233. {
  144234. OggVorbisNamespace::ov_clear (&ovFile);
  144235. }
  144236. bool readSamples (int** destSamples, int numDestChannels, int startOffsetInDestBuffer,
  144237. int64 startSampleInFile, int numSamples)
  144238. {
  144239. while (numSamples > 0)
  144240. {
  144241. const int numAvailable = reservoirStart + samplesInReservoir - startSampleInFile;
  144242. if (startSampleInFile >= reservoirStart && numAvailable > 0)
  144243. {
  144244. // got a few samples overlapping, so use them before seeking..
  144245. const int numToUse = jmin (numSamples, numAvailable);
  144246. for (int i = jmin (numDestChannels, reservoir.getNumChannels()); --i >= 0;)
  144247. if (destSamples[i] != 0)
  144248. memcpy (destSamples[i] + startOffsetInDestBuffer,
  144249. reservoir.getSampleData (i, (int) (startSampleInFile - reservoirStart)),
  144250. sizeof (float) * numToUse);
  144251. startSampleInFile += numToUse;
  144252. numSamples -= numToUse;
  144253. startOffsetInDestBuffer += numToUse;
  144254. if (numSamples == 0)
  144255. break;
  144256. }
  144257. if (startSampleInFile < reservoirStart
  144258. || startSampleInFile + numSamples > reservoirStart + samplesInReservoir)
  144259. {
  144260. // buffer miss, so refill the reservoir
  144261. int bitStream = 0;
  144262. reservoirStart = jmax (0, (int) startSampleInFile);
  144263. samplesInReservoir = reservoir.getNumSamples();
  144264. if (reservoirStart != (int) OggVorbisNamespace::ov_pcm_tell (&ovFile))
  144265. OggVorbisNamespace::ov_pcm_seek (&ovFile, reservoirStart);
  144266. int offset = 0;
  144267. int numToRead = samplesInReservoir;
  144268. while (numToRead > 0)
  144269. {
  144270. float** dataIn = 0;
  144271. const int samps = OggVorbisNamespace::ov_read_float (&ovFile, &dataIn, numToRead, &bitStream);
  144272. if (samps <= 0)
  144273. break;
  144274. jassert (samps <= numToRead);
  144275. for (int i = jmin ((int) numChannels, reservoir.getNumChannels()); --i >= 0;)
  144276. {
  144277. memcpy (reservoir.getSampleData (i, offset),
  144278. dataIn[i],
  144279. sizeof (float) * samps);
  144280. }
  144281. numToRead -= samps;
  144282. offset += samps;
  144283. }
  144284. if (numToRead > 0)
  144285. reservoir.clear (offset, numToRead);
  144286. }
  144287. }
  144288. if (numSamples > 0)
  144289. {
  144290. for (int i = numDestChannels; --i >= 0;)
  144291. if (destSamples[i] != 0)
  144292. zeromem (destSamples[i] + startOffsetInDestBuffer,
  144293. sizeof (int) * numSamples);
  144294. }
  144295. return true;
  144296. }
  144297. static size_t oggReadCallback (void* ptr, size_t size, size_t nmemb, void* datasource)
  144298. {
  144299. return (size_t) (((InputStream*) datasource)->read (ptr, (int) (size * nmemb)) / size);
  144300. }
  144301. static int oggSeekCallback (void* datasource, OggVorbisNamespace::ogg_int64_t offset, int whence)
  144302. {
  144303. InputStream* const in = (InputStream*) datasource;
  144304. if (whence == SEEK_CUR)
  144305. offset += in->getPosition();
  144306. else if (whence == SEEK_END)
  144307. offset += in->getTotalLength();
  144308. in->setPosition (offset);
  144309. return 0;
  144310. }
  144311. static int oggCloseCallback (void*)
  144312. {
  144313. return 0;
  144314. }
  144315. static long oggTellCallback (void* datasource)
  144316. {
  144317. return (long) ((InputStream*) datasource)->getPosition();
  144318. }
  144319. juce_UseDebuggingNewOperator
  144320. };
  144321. class OggWriter : public AudioFormatWriter
  144322. {
  144323. OggVorbisNamespace::ogg_stream_state os;
  144324. OggVorbisNamespace::ogg_page og;
  144325. OggVorbisNamespace::ogg_packet op;
  144326. OggVorbisNamespace::vorbis_info vi;
  144327. OggVorbisNamespace::vorbis_comment vc;
  144328. OggVorbisNamespace::vorbis_dsp_state vd;
  144329. OggVorbisNamespace::vorbis_block vb;
  144330. public:
  144331. bool ok;
  144332. OggWriter (OutputStream* const out,
  144333. const double sampleRate,
  144334. const int numChannels,
  144335. const int bitsPerSample,
  144336. const int qualityIndex)
  144337. : AudioFormatWriter (out, TRANS (oggFormatName),
  144338. sampleRate,
  144339. numChannels,
  144340. bitsPerSample)
  144341. {
  144342. using namespace OggVorbisNamespace;
  144343. ok = false;
  144344. vorbis_info_init (&vi);
  144345. if (vorbis_encode_init_vbr (&vi,
  144346. numChannels,
  144347. (int) sampleRate,
  144348. jlimit (0.0f, 1.0f, qualityIndex * 0.5f)) == 0)
  144349. {
  144350. vorbis_comment_init (&vc);
  144351. if (JUCEApplication::getInstance() != 0)
  144352. vorbis_comment_add_tag (&vc, "ENCODER", const_cast <char*> (JUCEApplication::getInstance()->getApplicationName().toUTF8()));
  144353. vorbis_analysis_init (&vd, &vi);
  144354. vorbis_block_init (&vd, &vb);
  144355. ogg_stream_init (&os, Random::getSystemRandom().nextInt());
  144356. ogg_packet header;
  144357. ogg_packet header_comm;
  144358. ogg_packet header_code;
  144359. vorbis_analysis_headerout (&vd, &vc, &header, &header_comm, &header_code);
  144360. ogg_stream_packetin (&os, &header);
  144361. ogg_stream_packetin (&os, &header_comm);
  144362. ogg_stream_packetin (&os, &header_code);
  144363. for (;;)
  144364. {
  144365. if (ogg_stream_flush (&os, &og) == 0)
  144366. break;
  144367. output->write (og.header, og.header_len);
  144368. output->write (og.body, og.body_len);
  144369. }
  144370. ok = true;
  144371. }
  144372. }
  144373. ~OggWriter()
  144374. {
  144375. using namespace OggVorbisNamespace;
  144376. if (ok)
  144377. {
  144378. // write a zero-length packet to show ogg that we're finished..
  144379. write (0, 0);
  144380. ogg_stream_clear (&os);
  144381. vorbis_block_clear (&vb);
  144382. vorbis_dsp_clear (&vd);
  144383. vorbis_comment_clear (&vc);
  144384. vorbis_info_clear (&vi);
  144385. output->flush();
  144386. }
  144387. else
  144388. {
  144389. vorbis_info_clear (&vi);
  144390. output = 0; // to stop the base class deleting this, as it needs to be returned
  144391. // to the caller of createWriter()
  144392. }
  144393. }
  144394. bool write (const int** samplesToWrite, int numSamples)
  144395. {
  144396. using namespace OggVorbisNamespace;
  144397. if (! ok)
  144398. return false;
  144399. if (numSamples > 0)
  144400. {
  144401. const double gain = 1.0 / 0x80000000u;
  144402. float** const vorbisBuffer = vorbis_analysis_buffer (&vd, numSamples);
  144403. for (int i = numChannels; --i >= 0;)
  144404. {
  144405. float* const dst = vorbisBuffer[i];
  144406. const int* const src = samplesToWrite [i];
  144407. if (src != 0 && dst != 0)
  144408. {
  144409. for (int j = 0; j < numSamples; ++j)
  144410. dst[j] = (float) (src[j] * gain);
  144411. }
  144412. }
  144413. }
  144414. vorbis_analysis_wrote (&vd, numSamples);
  144415. while (vorbis_analysis_blockout (&vd, &vb) == 1)
  144416. {
  144417. vorbis_analysis (&vb, 0);
  144418. vorbis_bitrate_addblock (&vb);
  144419. while (vorbis_bitrate_flushpacket (&vd, &op))
  144420. {
  144421. ogg_stream_packetin (&os, &op);
  144422. for (;;)
  144423. {
  144424. if (ogg_stream_pageout (&os, &og) == 0)
  144425. break;
  144426. output->write (og.header, og.header_len);
  144427. output->write (og.body, og.body_len);
  144428. if (ogg_page_eos (&og))
  144429. break;
  144430. }
  144431. }
  144432. }
  144433. return true;
  144434. }
  144435. juce_UseDebuggingNewOperator
  144436. };
  144437. OggVorbisAudioFormat::OggVorbisAudioFormat()
  144438. : AudioFormat (TRANS (oggFormatName), (const tchar**) oggExtensions)
  144439. {
  144440. }
  144441. OggVorbisAudioFormat::~OggVorbisAudioFormat()
  144442. {
  144443. }
  144444. const Array <int> OggVorbisAudioFormat::getPossibleSampleRates()
  144445. {
  144446. const int rates[] = { 22050, 32000, 44100, 48000, 0 };
  144447. return Array <int> (rates);
  144448. }
  144449. const Array <int> OggVorbisAudioFormat::getPossibleBitDepths()
  144450. {
  144451. Array <int> depths;
  144452. depths.add (32);
  144453. return depths;
  144454. }
  144455. bool OggVorbisAudioFormat::canDoStereo()
  144456. {
  144457. return true;
  144458. }
  144459. bool OggVorbisAudioFormat::canDoMono()
  144460. {
  144461. return true;
  144462. }
  144463. AudioFormatReader* OggVorbisAudioFormat::createReaderFor (InputStream* in,
  144464. const bool deleteStreamIfOpeningFails)
  144465. {
  144466. ScopedPointer <OggReader> r (new OggReader (in));
  144467. if (r->sampleRate != 0)
  144468. return r.release();
  144469. if (! deleteStreamIfOpeningFails)
  144470. r->input = 0;
  144471. return 0;
  144472. }
  144473. AudioFormatWriter* OggVorbisAudioFormat::createWriterFor (OutputStream* out,
  144474. double sampleRate,
  144475. unsigned int numChannels,
  144476. int bitsPerSample,
  144477. const StringPairArray& /*metadataValues*/,
  144478. int qualityOptionIndex)
  144479. {
  144480. ScopedPointer <OggWriter> w (new OggWriter (out,
  144481. sampleRate,
  144482. numChannels,
  144483. bitsPerSample,
  144484. qualityOptionIndex));
  144485. return w->ok ? w.release() : 0;
  144486. }
  144487. bool OggVorbisAudioFormat::isCompressed()
  144488. {
  144489. return true;
  144490. }
  144491. const StringArray OggVorbisAudioFormat::getQualityOptions()
  144492. {
  144493. StringArray s;
  144494. s.add ("Low Quality");
  144495. s.add ("Medium Quality");
  144496. s.add ("High Quality");
  144497. return s;
  144498. }
  144499. int OggVorbisAudioFormat::estimateOggFileQuality (const File& source)
  144500. {
  144501. FileInputStream* const in = source.createInputStream();
  144502. if (in != 0)
  144503. {
  144504. ScopedPointer <AudioFormatReader> r (createReaderFor (in, true));
  144505. if (r != 0)
  144506. {
  144507. const int64 numSamps = r->lengthInSamples;
  144508. r = 0;
  144509. const int64 fileNumSamps = source.getSize() / 4;
  144510. const double ratio = numSamps / (double) fileNumSamps;
  144511. if (ratio > 12.0)
  144512. return 0;
  144513. else if (ratio > 6.0)
  144514. return 1;
  144515. else
  144516. return 2;
  144517. }
  144518. }
  144519. return 1;
  144520. }
  144521. END_JUCE_NAMESPACE
  144522. #endif
  144523. /*** End of inlined file: juce_OggVorbisAudioFormat.cpp ***/
  144524. #endif
  144525. #if JUCE_BUILD_CORE && ! JUCE_ONLY_BUILD_CORE_LIBRARY // do these in the core section to help balance the sizes
  144526. /*** Start of inlined file: juce_JPEGLoader.cpp ***/
  144527. #if JUCE_MSVC
  144528. #pragma warning (push)
  144529. #endif
  144530. namespace jpeglibNamespace
  144531. {
  144532. #if JUCE_INCLUDE_JPEGLIB_CODE
  144533. #if JUCE_MINGW
  144534. typedef unsigned char boolean;
  144535. #endif
  144536. extern "C"
  144537. {
  144538. #define JPEG_INTERNALS
  144539. #undef FAR
  144540. /*** Start of inlined file: jpeglib.h ***/
  144541. #ifndef JPEGLIB_H
  144542. #define JPEGLIB_H
  144543. #ifndef JCONFIG_INCLUDED /* in case jinclude.h already did */
  144544. /*** Start of inlined file: jconfig.h ***/
  144545. // disable all the warnings under MSVC
  144546. #ifdef _MSC_VER
  144547. #pragma warning (disable: 4996 4267 4100 4127 4702 4244)
  144548. #endif
  144549. #ifdef __BORLANDC__
  144550. #pragma warn -8057
  144551. #pragma warn -8019
  144552. #pragma warn -8004
  144553. #pragma warn -8008
  144554. #endif
  144555. #define HAVE_PROTOTYPES
  144556. #define HAVE_UNSIGNED_CHAR
  144557. #define HAVE_UNSIGNED_SHORT
  144558. #undef CHAR_IS_UNSIGNED
  144559. #define HAVE_STDDEF_H
  144560. #define HAVE_STDLIB_H
  144561. #undef NEED_BSD_STRINGS
  144562. #undef NEED_SYS_TYPES_H
  144563. #undef NEED_FAR_POINTERS /* we presume a 32-bit flat memory model */
  144564. #undef NEED_SHORT_EXTERNAL_NAMES
  144565. #undef INCOMPLETE_TYPES_BROKEN
  144566. #ifndef __RPCNDR_H__ /* don't conflict if rpcndr.h already read */
  144567. typedef unsigned char boolean;
  144568. #endif
  144569. #define HAVE_BOOLEAN /* prevent jmorecfg.h from redefining it */
  144570. #ifdef JPEG_INTERNALS
  144571. #undef RIGHT_SHIFT_IS_UNSIGNED
  144572. #endif /* JPEG_INTERNALS */
  144573. #ifdef JPEG_CJPEG_DJPEG
  144574. #define BMP_SUPPORTED /* BMP image file format */
  144575. #define GIF_SUPPORTED /* GIF image file format */
  144576. #define PPM_SUPPORTED /* PBMPLUS PPM/PGM image file format */
  144577. #undef RLE_SUPPORTED /* Utah RLE image file format */
  144578. #define TARGA_SUPPORTED /* Targa image file format */
  144579. #define TWO_FILE_COMMANDLINE /* optional */
  144580. #define USE_SETMODE /* Microsoft has setmode() */
  144581. #undef NEED_SIGNAL_CATCHER
  144582. #undef DONT_USE_B_MODE
  144583. #undef PROGRESS_REPORT /* optional */
  144584. #endif /* JPEG_CJPEG_DJPEG */
  144585. /*** End of inlined file: jconfig.h ***/
  144586. /* widely used configuration options */
  144587. #endif
  144588. /*** Start of inlined file: jmorecfg.h ***/
  144589. #define BITS_IN_JSAMPLE 8 /* use 8 or 12 */
  144590. #define MAX_COMPONENTS 10 /* maximum number of image components */
  144591. #if BITS_IN_JSAMPLE == 8
  144592. #ifdef HAVE_UNSIGNED_CHAR
  144593. typedef unsigned char JSAMPLE;
  144594. #define GETJSAMPLE(value) ((int) (value))
  144595. #else /* not HAVE_UNSIGNED_CHAR */
  144596. typedef char JSAMPLE;
  144597. #ifdef CHAR_IS_UNSIGNED
  144598. #define GETJSAMPLE(value) ((int) (value))
  144599. #else
  144600. #define GETJSAMPLE(value) ((int) (value) & 0xFF)
  144601. #endif /* CHAR_IS_UNSIGNED */
  144602. #endif /* HAVE_UNSIGNED_CHAR */
  144603. #define MAXJSAMPLE 255
  144604. #define CENTERJSAMPLE 128
  144605. #endif /* BITS_IN_JSAMPLE == 8 */
  144606. #if BITS_IN_JSAMPLE == 12
  144607. typedef short JSAMPLE;
  144608. #define GETJSAMPLE(value) ((int) (value))
  144609. #define MAXJSAMPLE 4095
  144610. #define CENTERJSAMPLE 2048
  144611. #endif /* BITS_IN_JSAMPLE == 12 */
  144612. typedef short JCOEF;
  144613. #ifdef HAVE_UNSIGNED_CHAR
  144614. typedef unsigned char JOCTET;
  144615. #define GETJOCTET(value) (value)
  144616. #else /* not HAVE_UNSIGNED_CHAR */
  144617. typedef char JOCTET;
  144618. #ifdef CHAR_IS_UNSIGNED
  144619. #define GETJOCTET(value) (value)
  144620. #else
  144621. #define GETJOCTET(value) ((value) & 0xFF)
  144622. #endif /* CHAR_IS_UNSIGNED */
  144623. #endif /* HAVE_UNSIGNED_CHAR */
  144624. #ifdef HAVE_UNSIGNED_CHAR
  144625. typedef unsigned char UINT8;
  144626. #else /* not HAVE_UNSIGNED_CHAR */
  144627. #ifdef CHAR_IS_UNSIGNED
  144628. typedef char UINT8;
  144629. #else /* not CHAR_IS_UNSIGNED */
  144630. typedef short UINT8;
  144631. #endif /* CHAR_IS_UNSIGNED */
  144632. #endif /* HAVE_UNSIGNED_CHAR */
  144633. #ifdef HAVE_UNSIGNED_SHORT
  144634. typedef unsigned short UINT16;
  144635. #else /* not HAVE_UNSIGNED_SHORT */
  144636. typedef unsigned int UINT16;
  144637. #endif /* HAVE_UNSIGNED_SHORT */
  144638. #ifndef XMD_H /* X11/xmd.h correctly defines INT16 */
  144639. typedef short INT16;
  144640. #endif
  144641. #ifndef XMD_H /* X11/xmd.h correctly defines INT32 */
  144642. typedef long INT32;
  144643. #endif
  144644. typedef unsigned int JDIMENSION;
  144645. #define JPEG_MAX_DIMENSION 65500L /* a tad under 64K to prevent overflows */
  144646. #define METHODDEF(type) static type
  144647. #define LOCAL(type) static type
  144648. #define GLOBAL(type) type
  144649. #define EXTERN(type) extern type
  144650. #ifdef HAVE_PROTOTYPES
  144651. #define JMETHOD(type,methodname,arglist) type (*methodname) arglist
  144652. #else
  144653. #define JMETHOD(type,methodname,arglist) type (*methodname) ()
  144654. #endif
  144655. #ifdef NEED_FAR_POINTERS
  144656. #define FAR far
  144657. #else
  144658. #define FAR
  144659. #endif
  144660. #ifndef HAVE_BOOLEAN
  144661. typedef int boolean;
  144662. #endif
  144663. #ifndef FALSE /* in case these macros already exist */
  144664. #define FALSE 0 /* values of boolean */
  144665. #endif
  144666. #ifndef TRUE
  144667. #define TRUE 1
  144668. #endif
  144669. #ifdef JPEG_INTERNALS
  144670. #define JPEG_INTERNAL_OPTIONS
  144671. #endif
  144672. #ifdef JPEG_INTERNAL_OPTIONS
  144673. #define DCT_ISLOW_SUPPORTED /* slow but accurate integer algorithm */
  144674. #define DCT_IFAST_SUPPORTED /* faster, less accurate integer method */
  144675. #define DCT_FLOAT_SUPPORTED /* floating-point: accurate, fast on fast HW */
  144676. #undef C_ARITH_CODING_SUPPORTED /* Arithmetic coding back end? */
  144677. #define C_MULTISCAN_FILES_SUPPORTED /* Multiple-scan JPEG files? */
  144678. #define C_PROGRESSIVE_SUPPORTED /* Progressive JPEG? (Requires MULTISCAN)*/
  144679. #define ENTROPY_OPT_SUPPORTED /* Optimization of entropy coding parms? */
  144680. #define INPUT_SMOOTHING_SUPPORTED /* Input image smoothing option? */
  144681. #undef D_ARITH_CODING_SUPPORTED /* Arithmetic coding back end? */
  144682. #define D_MULTISCAN_FILES_SUPPORTED /* Multiple-scan JPEG files? */
  144683. #define D_PROGRESSIVE_SUPPORTED /* Progressive JPEG? (Requires MULTISCAN)*/
  144684. #define SAVE_MARKERS_SUPPORTED /* jpeg_save_markers() needed? */
  144685. #define BLOCK_SMOOTHING_SUPPORTED /* Block smoothing? (Progressive only) */
  144686. #define IDCT_SCALING_SUPPORTED /* Output rescaling via IDCT? */
  144687. #undef UPSAMPLE_SCALING_SUPPORTED /* Output rescaling at upsample stage? */
  144688. #define UPSAMPLE_MERGING_SUPPORTED /* Fast path for sloppy upsampling? */
  144689. #define QUANT_1PASS_SUPPORTED /* 1-pass color quantization? */
  144690. #define QUANT_2PASS_SUPPORTED /* 2-pass color quantization? */
  144691. #define RGB_RED 0 /* Offset of Red in an RGB scanline element */
  144692. #define RGB_GREEN 1 /* Offset of Green */
  144693. #define RGB_BLUE 2 /* Offset of Blue */
  144694. #define RGB_PIXELSIZE 3 /* JSAMPLEs per RGB scanline element */
  144695. #ifndef INLINE
  144696. #ifdef __GNUC__ /* for instance, GNU C knows about inline */
  144697. #define INLINE __inline__
  144698. #endif
  144699. #ifndef INLINE
  144700. #define INLINE /* default is to define it as empty */
  144701. #endif
  144702. #endif
  144703. #ifndef MULTIPLIER
  144704. #define MULTIPLIER int /* type for fastest integer multiply */
  144705. #endif
  144706. #ifndef FAST_FLOAT
  144707. #ifdef HAVE_PROTOTYPES
  144708. #define FAST_FLOAT float
  144709. #else
  144710. #define FAST_FLOAT double
  144711. #endif
  144712. #endif
  144713. #endif /* JPEG_INTERNAL_OPTIONS */
  144714. /*** End of inlined file: jmorecfg.h ***/
  144715. /* seldom changed options */
  144716. #define JPEG_LIB_VERSION 62 /* Version 6b */
  144717. #define DCTSIZE 8 /* The basic DCT block is 8x8 samples */
  144718. #define DCTSIZE2 64 /* DCTSIZE squared; # of elements in a block */
  144719. #define NUM_QUANT_TBLS 4 /* Quantization tables are numbered 0..3 */
  144720. #define NUM_HUFF_TBLS 4 /* Huffman tables are numbered 0..3 */
  144721. #define NUM_ARITH_TBLS 16 /* Arith-coding tables are numbered 0..15 */
  144722. #define MAX_COMPS_IN_SCAN 4 /* JPEG limit on # of components in one scan */
  144723. #define MAX_SAMP_FACTOR 4 /* JPEG limit on sampling factors */
  144724. #define C_MAX_BLOCKS_IN_MCU 10 /* compressor's limit on blocks per MCU */
  144725. #ifndef D_MAX_BLOCKS_IN_MCU
  144726. #define D_MAX_BLOCKS_IN_MCU 10 /* decompressor's limit on blocks per MCU */
  144727. #endif
  144728. typedef JSAMPLE FAR *JSAMPROW; /* ptr to one image row of pixel samples. */
  144729. typedef JSAMPROW *JSAMPARRAY; /* ptr to some rows (a 2-D sample array) */
  144730. typedef JSAMPARRAY *JSAMPIMAGE; /* a 3-D sample array: top index is color */
  144731. typedef JCOEF JBLOCK[DCTSIZE2]; /* one block of coefficients */
  144732. typedef JBLOCK FAR *JBLOCKROW; /* pointer to one row of coefficient blocks */
  144733. typedef JBLOCKROW *JBLOCKARRAY; /* a 2-D array of coefficient blocks */
  144734. typedef JBLOCKARRAY *JBLOCKIMAGE; /* a 3-D array of coefficient blocks */
  144735. typedef JCOEF FAR *JCOEFPTR; /* useful in a couple of places */
  144736. typedef struct {
  144737. UINT16 quantval[DCTSIZE2]; /* quantization step for each coefficient */
  144738. boolean sent_table; /* TRUE when table has been output */
  144739. } JQUANT_TBL;
  144740. typedef struct {
  144741. UINT8 bits[17]; /* bits[k] = # of symbols with codes of */
  144742. UINT8 huffval[256]; /* The symbols, in order of incr code length */
  144743. boolean sent_table; /* TRUE when table has been output */
  144744. } JHUFF_TBL;
  144745. typedef struct {
  144746. int component_id; /* identifier for this component (0..255) */
  144747. int component_index; /* its index in SOF or cinfo->comp_info[] */
  144748. int h_samp_factor; /* horizontal sampling factor (1..4) */
  144749. int v_samp_factor; /* vertical sampling factor (1..4) */
  144750. int quant_tbl_no; /* quantization table selector (0..3) */
  144751. int dc_tbl_no; /* DC entropy table selector (0..3) */
  144752. int ac_tbl_no; /* AC entropy table selector (0..3) */
  144753. JDIMENSION width_in_blocks;
  144754. JDIMENSION height_in_blocks;
  144755. int DCT_scaled_size;
  144756. JDIMENSION downsampled_width; /* actual width in samples */
  144757. JDIMENSION downsampled_height; /* actual height in samples */
  144758. boolean component_needed; /* do we need the value of this component? */
  144759. int MCU_width; /* number of blocks per MCU, horizontally */
  144760. int MCU_height; /* number of blocks per MCU, vertically */
  144761. int MCU_blocks; /* MCU_width * MCU_height */
  144762. int MCU_sample_width; /* MCU width in samples, MCU_width*DCT_scaled_size */
  144763. int last_col_width; /* # of non-dummy blocks across in last MCU */
  144764. int last_row_height; /* # of non-dummy blocks down in last MCU */
  144765. JQUANT_TBL * quant_table;
  144766. void * dct_table;
  144767. } jpeg_component_info;
  144768. typedef struct {
  144769. int comps_in_scan; /* number of components encoded in this scan */
  144770. int component_index[MAX_COMPS_IN_SCAN]; /* their SOF/comp_info[] indexes */
  144771. int Ss, Se; /* progressive JPEG spectral selection parms */
  144772. int Ah, Al; /* progressive JPEG successive approx. parms */
  144773. } jpeg_scan_info;
  144774. typedef struct jpeg_marker_struct FAR * jpeg_saved_marker_ptr;
  144775. struct jpeg_marker_struct {
  144776. jpeg_saved_marker_ptr next; /* next in list, or NULL */
  144777. UINT8 marker; /* marker code: JPEG_COM, or JPEG_APP0+n */
  144778. unsigned int original_length; /* # bytes of data in the file */
  144779. unsigned int data_length; /* # bytes of data saved at data[] */
  144780. JOCTET FAR * data; /* the data contained in the marker */
  144781. };
  144782. typedef enum {
  144783. JCS_UNKNOWN, /* error/unspecified */
  144784. JCS_GRAYSCALE, /* monochrome */
  144785. JCS_RGB, /* red/green/blue */
  144786. JCS_YCbCr, /* Y/Cb/Cr (also known as YUV) */
  144787. JCS_CMYK, /* C/M/Y/K */
  144788. JCS_YCCK /* Y/Cb/Cr/K */
  144789. } J_COLOR_SPACE;
  144790. typedef enum {
  144791. JDCT_ISLOW, /* slow but accurate integer algorithm */
  144792. JDCT_IFAST, /* faster, less accurate integer method */
  144793. JDCT_FLOAT /* floating-point: accurate, fast on fast HW */
  144794. } J_DCT_METHOD;
  144795. #ifndef JDCT_DEFAULT /* may be overridden in jconfig.h */
  144796. #define JDCT_DEFAULT JDCT_ISLOW
  144797. #endif
  144798. #ifndef JDCT_FASTEST /* may be overridden in jconfig.h */
  144799. #define JDCT_FASTEST JDCT_IFAST
  144800. #endif
  144801. typedef enum {
  144802. JDITHER_NONE, /* no dithering */
  144803. JDITHER_ORDERED, /* simple ordered dither */
  144804. JDITHER_FS /* Floyd-Steinberg error diffusion dither */
  144805. } J_DITHER_MODE;
  144806. #define jpeg_common_fields \
  144807. struct jpeg_error_mgr * err; /* Error handler module */\
  144808. struct jpeg_memory_mgr * mem; /* Memory manager module */\
  144809. struct jpeg_progress_mgr * progress; /* Progress monitor, or NULL if none */\
  144810. void * client_data; /* Available for use by application */\
  144811. boolean is_decompressor; /* So common code can tell which is which */\
  144812. int global_state /* For checking call sequence validity */
  144813. struct jpeg_common_struct {
  144814. jpeg_common_fields; /* Fields common to both master struct types */
  144815. };
  144816. typedef struct jpeg_common_struct * j_common_ptr;
  144817. typedef struct jpeg_compress_struct * j_compress_ptr;
  144818. typedef struct jpeg_decompress_struct * j_decompress_ptr;
  144819. struct jpeg_compress_struct {
  144820. jpeg_common_fields; /* Fields shared with jpeg_decompress_struct */
  144821. struct jpeg_destination_mgr * dest;
  144822. JDIMENSION image_width; /* input image width */
  144823. JDIMENSION image_height; /* input image height */
  144824. int input_components; /* # of color components in input image */
  144825. J_COLOR_SPACE in_color_space; /* colorspace of input image */
  144826. double input_gamma; /* image gamma of input image */
  144827. int data_precision; /* bits of precision in image data */
  144828. int num_components; /* # of color components in JPEG image */
  144829. J_COLOR_SPACE jpeg_color_space; /* colorspace of JPEG image */
  144830. jpeg_component_info * comp_info;
  144831. JQUANT_TBL * quant_tbl_ptrs[NUM_QUANT_TBLS];
  144832. JHUFF_TBL * dc_huff_tbl_ptrs[NUM_HUFF_TBLS];
  144833. JHUFF_TBL * ac_huff_tbl_ptrs[NUM_HUFF_TBLS];
  144834. UINT8 arith_dc_L[NUM_ARITH_TBLS]; /* L values for DC arith-coding tables */
  144835. UINT8 arith_dc_U[NUM_ARITH_TBLS]; /* U values for DC arith-coding tables */
  144836. UINT8 arith_ac_K[NUM_ARITH_TBLS]; /* Kx values for AC arith-coding tables */
  144837. int num_scans; /* # of entries in scan_info array */
  144838. const jpeg_scan_info * scan_info; /* script for multi-scan file, or NULL */
  144839. boolean raw_data_in; /* TRUE=caller supplies downsampled data */
  144840. boolean arith_code; /* TRUE=arithmetic coding, FALSE=Huffman */
  144841. boolean optimize_coding; /* TRUE=optimize entropy encoding parms */
  144842. boolean CCIR601_sampling; /* TRUE=first samples are cosited */
  144843. int smoothing_factor; /* 1..100, or 0 for no input smoothing */
  144844. J_DCT_METHOD dct_method; /* DCT algorithm selector */
  144845. unsigned int restart_interval; /* MCUs per restart, or 0 for no restart */
  144846. int restart_in_rows; /* if > 0, MCU rows per restart interval */
  144847. boolean write_JFIF_header; /* should a JFIF marker be written? */
  144848. UINT8 JFIF_major_version; /* What to write for the JFIF version number */
  144849. UINT8 JFIF_minor_version;
  144850. UINT8 density_unit; /* JFIF code for pixel size units */
  144851. UINT16 X_density; /* Horizontal pixel density */
  144852. UINT16 Y_density; /* Vertical pixel density */
  144853. boolean write_Adobe_marker; /* should an Adobe marker be written? */
  144854. JDIMENSION next_scanline; /* 0 .. image_height-1 */
  144855. boolean progressive_mode; /* TRUE if scan script uses progressive mode */
  144856. int max_h_samp_factor; /* largest h_samp_factor */
  144857. int max_v_samp_factor; /* largest v_samp_factor */
  144858. JDIMENSION total_iMCU_rows; /* # of iMCU rows to be input to coef ctlr */
  144859. int comps_in_scan; /* # of JPEG components in this scan */
  144860. jpeg_component_info * cur_comp_info[MAX_COMPS_IN_SCAN];
  144861. JDIMENSION MCUs_per_row; /* # of MCUs across the image */
  144862. JDIMENSION MCU_rows_in_scan; /* # of MCU rows in the image */
  144863. int blocks_in_MCU; /* # of DCT blocks per MCU */
  144864. int MCU_membership[C_MAX_BLOCKS_IN_MCU];
  144865. int Ss, Se, Ah, Al; /* progressive JPEG parameters for scan */
  144866. struct jpeg_comp_master * master;
  144867. struct jpeg_c_main_controller * main;
  144868. struct jpeg_c_prep_controller * prep;
  144869. struct jpeg_c_coef_controller * coef;
  144870. struct jpeg_marker_writer * marker;
  144871. struct jpeg_color_converter * cconvert;
  144872. struct jpeg_downsampler * downsample;
  144873. struct jpeg_forward_dct * fdct;
  144874. struct jpeg_entropy_encoder * entropy;
  144875. jpeg_scan_info * script_space; /* workspace for jpeg_simple_progression */
  144876. int script_space_size;
  144877. };
  144878. struct jpeg_decompress_struct {
  144879. jpeg_common_fields; /* Fields shared with jpeg_compress_struct */
  144880. struct jpeg_source_mgr * src;
  144881. JDIMENSION image_width; /* nominal image width (from SOF marker) */
  144882. JDIMENSION image_height; /* nominal image height */
  144883. int num_components; /* # of color components in JPEG image */
  144884. J_COLOR_SPACE jpeg_color_space; /* colorspace of JPEG image */
  144885. J_COLOR_SPACE out_color_space; /* colorspace for output */
  144886. unsigned int scale_num, scale_denom; /* fraction by which to scale image */
  144887. double output_gamma; /* image gamma wanted in output */
  144888. boolean buffered_image; /* TRUE=multiple output passes */
  144889. boolean raw_data_out; /* TRUE=downsampled data wanted */
  144890. J_DCT_METHOD dct_method; /* IDCT algorithm selector */
  144891. boolean do_fancy_upsampling; /* TRUE=apply fancy upsampling */
  144892. boolean do_block_smoothing; /* TRUE=apply interblock smoothing */
  144893. boolean quantize_colors; /* TRUE=colormapped output wanted */
  144894. J_DITHER_MODE dither_mode; /* type of color dithering to use */
  144895. boolean two_pass_quantize; /* TRUE=use two-pass color quantization */
  144896. int desired_number_of_colors; /* max # colors to use in created colormap */
  144897. boolean enable_1pass_quant; /* enable future use of 1-pass quantizer */
  144898. boolean enable_external_quant;/* enable future use of external colormap */
  144899. boolean enable_2pass_quant; /* enable future use of 2-pass quantizer */
  144900. JDIMENSION output_width; /* scaled image width */
  144901. JDIMENSION output_height; /* scaled image height */
  144902. int out_color_components; /* # of color components in out_color_space */
  144903. int output_components; /* # of color components returned */
  144904. int rec_outbuf_height; /* min recommended height of scanline buffer */
  144905. int actual_number_of_colors; /* number of entries in use */
  144906. JSAMPARRAY colormap; /* The color map as a 2-D pixel array */
  144907. JDIMENSION output_scanline; /* 0 .. output_height-1 */
  144908. int input_scan_number; /* Number of SOS markers seen so far */
  144909. JDIMENSION input_iMCU_row; /* Number of iMCU rows completed */
  144910. int output_scan_number; /* Nominal scan number being displayed */
  144911. JDIMENSION output_iMCU_row; /* Number of iMCU rows read */
  144912. int (*coef_bits)[DCTSIZE2]; /* -1 or current Al value for each coef */
  144913. JQUANT_TBL * quant_tbl_ptrs[NUM_QUANT_TBLS];
  144914. JHUFF_TBL * dc_huff_tbl_ptrs[NUM_HUFF_TBLS];
  144915. JHUFF_TBL * ac_huff_tbl_ptrs[NUM_HUFF_TBLS];
  144916. int data_precision; /* bits of precision in image data */
  144917. jpeg_component_info * comp_info;
  144918. boolean progressive_mode; /* TRUE if SOFn specifies progressive mode */
  144919. boolean arith_code; /* TRUE=arithmetic coding, FALSE=Huffman */
  144920. UINT8 arith_dc_L[NUM_ARITH_TBLS]; /* L values for DC arith-coding tables */
  144921. UINT8 arith_dc_U[NUM_ARITH_TBLS]; /* U values for DC arith-coding tables */
  144922. UINT8 arith_ac_K[NUM_ARITH_TBLS]; /* Kx values for AC arith-coding tables */
  144923. unsigned int restart_interval; /* MCUs per restart interval, or 0 for no restart */
  144924. boolean saw_JFIF_marker; /* TRUE iff a JFIF APP0 marker was found */
  144925. UINT8 JFIF_major_version; /* JFIF version number */
  144926. UINT8 JFIF_minor_version;
  144927. UINT8 density_unit; /* JFIF code for pixel size units */
  144928. UINT16 X_density; /* Horizontal pixel density */
  144929. UINT16 Y_density; /* Vertical pixel density */
  144930. boolean saw_Adobe_marker; /* TRUE iff an Adobe APP14 marker was found */
  144931. UINT8 Adobe_transform; /* Color transform code from Adobe marker */
  144932. boolean CCIR601_sampling; /* TRUE=first samples are cosited */
  144933. jpeg_saved_marker_ptr marker_list; /* Head of list of saved markers */
  144934. int max_h_samp_factor; /* largest h_samp_factor */
  144935. int max_v_samp_factor; /* largest v_samp_factor */
  144936. int min_DCT_scaled_size; /* smallest DCT_scaled_size of any component */
  144937. JDIMENSION total_iMCU_rows; /* # of iMCU rows in image */
  144938. JSAMPLE * sample_range_limit; /* table for fast range-limiting */
  144939. int comps_in_scan; /* # of JPEG components in this scan */
  144940. jpeg_component_info * cur_comp_info[MAX_COMPS_IN_SCAN];
  144941. JDIMENSION MCUs_per_row; /* # of MCUs across the image */
  144942. JDIMENSION MCU_rows_in_scan; /* # of MCU rows in the image */
  144943. int blocks_in_MCU; /* # of DCT blocks per MCU */
  144944. int MCU_membership[D_MAX_BLOCKS_IN_MCU];
  144945. int Ss, Se, Ah, Al; /* progressive JPEG parameters for scan */
  144946. int unread_marker;
  144947. struct jpeg_decomp_master * master;
  144948. struct jpeg_d_main_controller * main;
  144949. struct jpeg_d_coef_controller * coef;
  144950. struct jpeg_d_post_controller * post;
  144951. struct jpeg_input_controller * inputctl;
  144952. struct jpeg_marker_reader * marker;
  144953. struct jpeg_entropy_decoder * entropy;
  144954. struct jpeg_inverse_dct * idct;
  144955. struct jpeg_upsampler * upsample;
  144956. struct jpeg_color_deconverter * cconvert;
  144957. struct jpeg_color_quantizer * cquantize;
  144958. };
  144959. struct jpeg_error_mgr {
  144960. JMETHOD(void, error_exit, (j_common_ptr cinfo));
  144961. JMETHOD(void, emit_message, (j_common_ptr cinfo, int msg_level));
  144962. JMETHOD(void, output_message, (j_common_ptr cinfo));
  144963. JMETHOD(void, format_message, (j_common_ptr cinfo, char * buffer));
  144964. #define JMSG_LENGTH_MAX 200 /* recommended size of format_message buffer */
  144965. JMETHOD(void, reset_error_mgr, (j_common_ptr cinfo));
  144966. int msg_code;
  144967. #define JMSG_STR_PARM_MAX 80
  144968. union {
  144969. int i[8];
  144970. char s[JMSG_STR_PARM_MAX];
  144971. } msg_parm;
  144972. int trace_level; /* max msg_level that will be displayed */
  144973. long num_warnings; /* number of corrupt-data warnings */
  144974. const char * const * jpeg_message_table; /* Library errors */
  144975. int last_jpeg_message; /* Table contains strings 0..last_jpeg_message */
  144976. const char * const * addon_message_table; /* Non-library errors */
  144977. int first_addon_message; /* code for first string in addon table */
  144978. int last_addon_message; /* code for last string in addon table */
  144979. };
  144980. struct jpeg_progress_mgr {
  144981. JMETHOD(void, progress_monitor, (j_common_ptr cinfo));
  144982. long pass_counter; /* work units completed in this pass */
  144983. long pass_limit; /* total number of work units in this pass */
  144984. int completed_passes; /* passes completed so far */
  144985. int total_passes; /* total number of passes expected */
  144986. };
  144987. struct jpeg_destination_mgr {
  144988. JOCTET * next_output_byte; /* => next byte to write in buffer */
  144989. size_t free_in_buffer; /* # of byte spaces remaining in buffer */
  144990. JMETHOD(void, init_destination, (j_compress_ptr cinfo));
  144991. JMETHOD(boolean, empty_output_buffer, (j_compress_ptr cinfo));
  144992. JMETHOD(void, term_destination, (j_compress_ptr cinfo));
  144993. };
  144994. struct jpeg_source_mgr {
  144995. const JOCTET * next_input_byte; /* => next byte to read from buffer */
  144996. size_t bytes_in_buffer; /* # of bytes remaining in buffer */
  144997. JMETHOD(void, init_source, (j_decompress_ptr cinfo));
  144998. JMETHOD(boolean, fill_input_buffer, (j_decompress_ptr cinfo));
  144999. JMETHOD(void, skip_input_data, (j_decompress_ptr cinfo, long num_bytes));
  145000. JMETHOD(boolean, resync_to_restart, (j_decompress_ptr cinfo, int desired));
  145001. JMETHOD(void, term_source, (j_decompress_ptr cinfo));
  145002. };
  145003. #define JPOOL_PERMANENT 0 /* lasts until master record is destroyed */
  145004. #define JPOOL_IMAGE 1 /* lasts until done with image/datastream */
  145005. #define JPOOL_NUMPOOLS 2
  145006. typedef struct jvirt_sarray_control * jvirt_sarray_ptr;
  145007. typedef struct jvirt_barray_control * jvirt_barray_ptr;
  145008. struct jpeg_memory_mgr {
  145009. JMETHOD(void *, alloc_small, (j_common_ptr cinfo, int pool_id,
  145010. size_t sizeofobject));
  145011. JMETHOD(void FAR *, alloc_large, (j_common_ptr cinfo, int pool_id,
  145012. size_t sizeofobject));
  145013. JMETHOD(JSAMPARRAY, alloc_sarray, (j_common_ptr cinfo, int pool_id,
  145014. JDIMENSION samplesperrow,
  145015. JDIMENSION numrows));
  145016. JMETHOD(JBLOCKARRAY, alloc_barray, (j_common_ptr cinfo, int pool_id,
  145017. JDIMENSION blocksperrow,
  145018. JDIMENSION numrows));
  145019. JMETHOD(jvirt_sarray_ptr, request_virt_sarray, (j_common_ptr cinfo,
  145020. int pool_id,
  145021. boolean pre_zero,
  145022. JDIMENSION samplesperrow,
  145023. JDIMENSION numrows,
  145024. JDIMENSION maxaccess));
  145025. JMETHOD(jvirt_barray_ptr, request_virt_barray, (j_common_ptr cinfo,
  145026. int pool_id,
  145027. boolean pre_zero,
  145028. JDIMENSION blocksperrow,
  145029. JDIMENSION numrows,
  145030. JDIMENSION maxaccess));
  145031. JMETHOD(void, realize_virt_arrays, (j_common_ptr cinfo));
  145032. JMETHOD(JSAMPARRAY, access_virt_sarray, (j_common_ptr cinfo,
  145033. jvirt_sarray_ptr ptr,
  145034. JDIMENSION start_row,
  145035. JDIMENSION num_rows,
  145036. boolean writable));
  145037. JMETHOD(JBLOCKARRAY, access_virt_barray, (j_common_ptr cinfo,
  145038. jvirt_barray_ptr ptr,
  145039. JDIMENSION start_row,
  145040. JDIMENSION num_rows,
  145041. boolean writable));
  145042. JMETHOD(void, free_pool, (j_common_ptr cinfo, int pool_id));
  145043. JMETHOD(void, self_destruct, (j_common_ptr cinfo));
  145044. long max_memory_to_use;
  145045. long max_alloc_chunk;
  145046. };
  145047. typedef JMETHOD(boolean, jpeg_marker_parser_method, (j_decompress_ptr cinfo));
  145048. #ifdef HAVE_PROTOTYPES
  145049. #define JPP(arglist) arglist
  145050. #else
  145051. #define JPP(arglist) ()
  145052. #endif
  145053. #ifdef NEED_SHORT_EXTERNAL_NAMES
  145054. #define jpeg_std_error jStdError
  145055. #define jpeg_CreateCompress jCreaCompress
  145056. #define jpeg_CreateDecompress jCreaDecompress
  145057. #define jpeg_destroy_compress jDestCompress
  145058. #define jpeg_destroy_decompress jDestDecompress
  145059. #define jpeg_stdio_dest jStdDest
  145060. #define jpeg_stdio_src jStdSrc
  145061. #define jpeg_set_defaults jSetDefaults
  145062. #define jpeg_set_colorspace jSetColorspace
  145063. #define jpeg_default_colorspace jDefColorspace
  145064. #define jpeg_set_quality jSetQuality
  145065. #define jpeg_set_linear_quality jSetLQuality
  145066. #define jpeg_add_quant_table jAddQuantTable
  145067. #define jpeg_quality_scaling jQualityScaling
  145068. #define jpeg_simple_progression jSimProgress
  145069. #define jpeg_suppress_tables jSuppressTables
  145070. #define jpeg_alloc_quant_table jAlcQTable
  145071. #define jpeg_alloc_huff_table jAlcHTable
  145072. #define jpeg_start_compress jStrtCompress
  145073. #define jpeg_write_scanlines jWrtScanlines
  145074. #define jpeg_finish_compress jFinCompress
  145075. #define jpeg_write_raw_data jWrtRawData
  145076. #define jpeg_write_marker jWrtMarker
  145077. #define jpeg_write_m_header jWrtMHeader
  145078. #define jpeg_write_m_byte jWrtMByte
  145079. #define jpeg_write_tables jWrtTables
  145080. #define jpeg_read_header jReadHeader
  145081. #define jpeg_start_decompress jStrtDecompress
  145082. #define jpeg_read_scanlines jReadScanlines
  145083. #define jpeg_finish_decompress jFinDecompress
  145084. #define jpeg_read_raw_data jReadRawData
  145085. #define jpeg_has_multiple_scans jHasMultScn
  145086. #define jpeg_start_output jStrtOutput
  145087. #define jpeg_finish_output jFinOutput
  145088. #define jpeg_input_complete jInComplete
  145089. #define jpeg_new_colormap jNewCMap
  145090. #define jpeg_consume_input jConsumeInput
  145091. #define jpeg_calc_output_dimensions jCalcDimensions
  145092. #define jpeg_save_markers jSaveMarkers
  145093. #define jpeg_set_marker_processor jSetMarker
  145094. #define jpeg_read_coefficients jReadCoefs
  145095. #define jpeg_write_coefficients jWrtCoefs
  145096. #define jpeg_copy_critical_parameters jCopyCrit
  145097. #define jpeg_abort_compress jAbrtCompress
  145098. #define jpeg_abort_decompress jAbrtDecompress
  145099. #define jpeg_abort jAbort
  145100. #define jpeg_destroy jDestroy
  145101. #define jpeg_resync_to_restart jResyncRestart
  145102. #endif /* NEED_SHORT_EXTERNAL_NAMES */
  145103. EXTERN(struct jpeg_error_mgr *) jpeg_std_error
  145104. JPP((struct jpeg_error_mgr * err));
  145105. #define jpeg_create_compress(cinfo) \
  145106. jpeg_CreateCompress((cinfo), JPEG_LIB_VERSION, \
  145107. (size_t) sizeof(struct jpeg_compress_struct))
  145108. #define jpeg_create_decompress(cinfo) \
  145109. jpeg_CreateDecompress((cinfo), JPEG_LIB_VERSION, \
  145110. (size_t) sizeof(struct jpeg_decompress_struct))
  145111. EXTERN(void) jpeg_CreateCompress JPP((j_compress_ptr cinfo,
  145112. int version, size_t structsize));
  145113. EXTERN(void) jpeg_CreateDecompress JPP((j_decompress_ptr cinfo,
  145114. int version, size_t structsize));
  145115. EXTERN(void) jpeg_destroy_compress JPP((j_compress_ptr cinfo));
  145116. EXTERN(void) jpeg_destroy_decompress JPP((j_decompress_ptr cinfo));
  145117. EXTERN(void) jpeg_stdio_dest JPP((j_compress_ptr cinfo, FILE * outfile));
  145118. EXTERN(void) jpeg_stdio_src JPP((j_decompress_ptr cinfo, FILE * infile));
  145119. EXTERN(void) jpeg_set_defaults JPP((j_compress_ptr cinfo));
  145120. EXTERN(void) jpeg_set_colorspace JPP((j_compress_ptr cinfo,
  145121. J_COLOR_SPACE colorspace));
  145122. EXTERN(void) jpeg_default_colorspace JPP((j_compress_ptr cinfo));
  145123. EXTERN(void) jpeg_set_quality JPP((j_compress_ptr cinfo, int quality,
  145124. boolean force_baseline));
  145125. EXTERN(void) jpeg_set_linear_quality JPP((j_compress_ptr cinfo,
  145126. int scale_factor,
  145127. boolean force_baseline));
  145128. EXTERN(void) jpeg_add_quant_table JPP((j_compress_ptr cinfo, int which_tbl,
  145129. const unsigned int *basic_table,
  145130. int scale_factor,
  145131. boolean force_baseline));
  145132. EXTERN(int) jpeg_quality_scaling JPP((int quality));
  145133. EXTERN(void) jpeg_simple_progression JPP((j_compress_ptr cinfo));
  145134. EXTERN(void) jpeg_suppress_tables JPP((j_compress_ptr cinfo,
  145135. boolean suppress));
  145136. EXTERN(JQUANT_TBL *) jpeg_alloc_quant_table JPP((j_common_ptr cinfo));
  145137. EXTERN(JHUFF_TBL *) jpeg_alloc_huff_table JPP((j_common_ptr cinfo));
  145138. EXTERN(void) jpeg_start_compress JPP((j_compress_ptr cinfo,
  145139. boolean write_all_tables));
  145140. EXTERN(JDIMENSION) jpeg_write_scanlines JPP((j_compress_ptr cinfo,
  145141. JSAMPARRAY scanlines,
  145142. JDIMENSION num_lines));
  145143. EXTERN(void) jpeg_finish_compress JPP((j_compress_ptr cinfo));
  145144. EXTERN(JDIMENSION) jpeg_write_raw_data JPP((j_compress_ptr cinfo,
  145145. JSAMPIMAGE data,
  145146. JDIMENSION num_lines));
  145147. EXTERN(void) jpeg_write_marker
  145148. JPP((j_compress_ptr cinfo, int marker,
  145149. const JOCTET * dataptr, unsigned int datalen));
  145150. EXTERN(void) jpeg_write_m_header
  145151. JPP((j_compress_ptr cinfo, int marker, unsigned int datalen));
  145152. EXTERN(void) jpeg_write_m_byte
  145153. JPP((j_compress_ptr cinfo, int val));
  145154. EXTERN(void) jpeg_write_tables JPP((j_compress_ptr cinfo));
  145155. EXTERN(int) jpeg_read_header JPP((j_decompress_ptr cinfo,
  145156. boolean require_image));
  145157. #define JPEG_SUSPENDED 0 /* Suspended due to lack of input data */
  145158. #define JPEG_HEADER_OK 1 /* Found valid image datastream */
  145159. #define JPEG_HEADER_TABLES_ONLY 2 /* Found valid table-specs-only datastream */
  145160. EXTERN(boolean) jpeg_start_decompress JPP((j_decompress_ptr cinfo));
  145161. EXTERN(JDIMENSION) jpeg_read_scanlines JPP((j_decompress_ptr cinfo,
  145162. JSAMPARRAY scanlines,
  145163. JDIMENSION max_lines));
  145164. EXTERN(boolean) jpeg_finish_decompress JPP((j_decompress_ptr cinfo));
  145165. EXTERN(JDIMENSION) jpeg_read_raw_data JPP((j_decompress_ptr cinfo,
  145166. JSAMPIMAGE data,
  145167. JDIMENSION max_lines));
  145168. EXTERN(boolean) jpeg_has_multiple_scans JPP((j_decompress_ptr cinfo));
  145169. EXTERN(boolean) jpeg_start_output JPP((j_decompress_ptr cinfo,
  145170. int scan_number));
  145171. EXTERN(boolean) jpeg_finish_output JPP((j_decompress_ptr cinfo));
  145172. EXTERN(boolean) jpeg_input_complete JPP((j_decompress_ptr cinfo));
  145173. EXTERN(void) jpeg_new_colormap JPP((j_decompress_ptr cinfo));
  145174. EXTERN(int) jpeg_consume_input JPP((j_decompress_ptr cinfo));
  145175. #define JPEG_REACHED_SOS 1 /* Reached start of new scan */
  145176. #define JPEG_REACHED_EOI 2 /* Reached end of image */
  145177. #define JPEG_ROW_COMPLETED 3 /* Completed one iMCU row */
  145178. #define JPEG_SCAN_COMPLETED 4 /* Completed last iMCU row of a scan */
  145179. EXTERN(void) jpeg_calc_output_dimensions JPP((j_decompress_ptr cinfo));
  145180. EXTERN(void) jpeg_save_markers
  145181. JPP((j_decompress_ptr cinfo, int marker_code,
  145182. unsigned int length_limit));
  145183. EXTERN(void) jpeg_set_marker_processor
  145184. JPP((j_decompress_ptr cinfo, int marker_code,
  145185. jpeg_marker_parser_method routine));
  145186. EXTERN(jvirt_barray_ptr *) jpeg_read_coefficients JPP((j_decompress_ptr cinfo));
  145187. EXTERN(void) jpeg_write_coefficients JPP((j_compress_ptr cinfo,
  145188. jvirt_barray_ptr * coef_arrays));
  145189. EXTERN(void) jpeg_copy_critical_parameters JPP((j_decompress_ptr srcinfo,
  145190. j_compress_ptr dstinfo));
  145191. EXTERN(void) jpeg_abort_compress JPP((j_compress_ptr cinfo));
  145192. EXTERN(void) jpeg_abort_decompress JPP((j_decompress_ptr cinfo));
  145193. EXTERN(void) jpeg_abort JPP((j_common_ptr cinfo));
  145194. EXTERN(void) jpeg_destroy JPP((j_common_ptr cinfo));
  145195. EXTERN(boolean) jpeg_resync_to_restart JPP((j_decompress_ptr cinfo,
  145196. int desired));
  145197. #define JPEG_RST0 0xD0 /* RST0 marker code */
  145198. #define JPEG_EOI 0xD9 /* EOI marker code */
  145199. #define JPEG_APP0 0xE0 /* APP0 marker code */
  145200. #define JPEG_COM 0xFE /* COM marker code */
  145201. #ifdef INCOMPLETE_TYPES_BROKEN
  145202. #ifndef JPEG_INTERNALS /* will be defined in jpegint.h */
  145203. struct jvirt_sarray_control { long dummy; };
  145204. struct jvirt_barray_control { long dummy; };
  145205. struct jpeg_comp_master { long dummy; };
  145206. struct jpeg_c_main_controller { long dummy; };
  145207. struct jpeg_c_prep_controller { long dummy; };
  145208. struct jpeg_c_coef_controller { long dummy; };
  145209. struct jpeg_marker_writer { long dummy; };
  145210. struct jpeg_color_converter { long dummy; };
  145211. struct jpeg_downsampler { long dummy; };
  145212. struct jpeg_forward_dct { long dummy; };
  145213. struct jpeg_entropy_encoder { long dummy; };
  145214. struct jpeg_decomp_master { long dummy; };
  145215. struct jpeg_d_main_controller { long dummy; };
  145216. struct jpeg_d_coef_controller { long dummy; };
  145217. struct jpeg_d_post_controller { long dummy; };
  145218. struct jpeg_input_controller { long dummy; };
  145219. struct jpeg_marker_reader { long dummy; };
  145220. struct jpeg_entropy_decoder { long dummy; };
  145221. struct jpeg_inverse_dct { long dummy; };
  145222. struct jpeg_upsampler { long dummy; };
  145223. struct jpeg_color_deconverter { long dummy; };
  145224. struct jpeg_color_quantizer { long dummy; };
  145225. #endif /* JPEG_INTERNALS */
  145226. #endif /* INCOMPLETE_TYPES_BROKEN */
  145227. #ifdef JPEG_INTERNALS
  145228. /*** Start of inlined file: jpegint.h ***/
  145229. typedef enum { /* Operating modes for buffer controllers */
  145230. JBUF_PASS_THRU, /* Plain stripwise operation */
  145231. JBUF_SAVE_SOURCE, /* Run source subobject only, save output */
  145232. JBUF_CRANK_DEST, /* Run dest subobject only, using saved data */
  145233. JBUF_SAVE_AND_PASS /* Run both subobjects, save output */
  145234. } J_BUF_MODE;
  145235. #define CSTATE_START 100 /* after create_compress */
  145236. #define CSTATE_SCANNING 101 /* start_compress done, write_scanlines OK */
  145237. #define CSTATE_RAW_OK 102 /* start_compress done, write_raw_data OK */
  145238. #define CSTATE_WRCOEFS 103 /* jpeg_write_coefficients done */
  145239. #define DSTATE_START 200 /* after create_decompress */
  145240. #define DSTATE_INHEADER 201 /* reading header markers, no SOS yet */
  145241. #define DSTATE_READY 202 /* found SOS, ready for start_decompress */
  145242. #define DSTATE_PRELOAD 203 /* reading multiscan file in start_decompress*/
  145243. #define DSTATE_PRESCAN 204 /* performing dummy pass for 2-pass quant */
  145244. #define DSTATE_SCANNING 205 /* start_decompress done, read_scanlines OK */
  145245. #define DSTATE_RAW_OK 206 /* start_decompress done, read_raw_data OK */
  145246. #define DSTATE_BUFIMAGE 207 /* expecting jpeg_start_output */
  145247. #define DSTATE_BUFPOST 208 /* looking for SOS/EOI in jpeg_finish_output */
  145248. #define DSTATE_RDCOEFS 209 /* reading file in jpeg_read_coefficients */
  145249. #define DSTATE_STOPPING 210 /* looking for EOI in jpeg_finish_decompress */
  145250. struct jpeg_comp_master {
  145251. JMETHOD(void, prepare_for_pass, (j_compress_ptr cinfo));
  145252. JMETHOD(void, pass_startup, (j_compress_ptr cinfo));
  145253. JMETHOD(void, finish_pass, (j_compress_ptr cinfo));
  145254. boolean call_pass_startup; /* True if pass_startup must be called */
  145255. boolean is_last_pass; /* True during last pass */
  145256. };
  145257. struct jpeg_c_main_controller {
  145258. JMETHOD(void, start_pass, (j_compress_ptr cinfo, J_BUF_MODE pass_mode));
  145259. JMETHOD(void, process_data, (j_compress_ptr cinfo,
  145260. JSAMPARRAY input_buf, JDIMENSION *in_row_ctr,
  145261. JDIMENSION in_rows_avail));
  145262. };
  145263. struct jpeg_c_prep_controller {
  145264. JMETHOD(void, start_pass, (j_compress_ptr cinfo, J_BUF_MODE pass_mode));
  145265. JMETHOD(void, pre_process_data, (j_compress_ptr cinfo,
  145266. JSAMPARRAY input_buf,
  145267. JDIMENSION *in_row_ctr,
  145268. JDIMENSION in_rows_avail,
  145269. JSAMPIMAGE output_buf,
  145270. JDIMENSION *out_row_group_ctr,
  145271. JDIMENSION out_row_groups_avail));
  145272. };
  145273. struct jpeg_c_coef_controller {
  145274. JMETHOD(void, start_pass, (j_compress_ptr cinfo, J_BUF_MODE pass_mode));
  145275. JMETHOD(boolean, compress_data, (j_compress_ptr cinfo,
  145276. JSAMPIMAGE input_buf));
  145277. };
  145278. struct jpeg_color_converter {
  145279. JMETHOD(void, start_pass, (j_compress_ptr cinfo));
  145280. JMETHOD(void, color_convert, (j_compress_ptr cinfo,
  145281. JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
  145282. JDIMENSION output_row, int num_rows));
  145283. };
  145284. struct jpeg_downsampler {
  145285. JMETHOD(void, start_pass, (j_compress_ptr cinfo));
  145286. JMETHOD(void, downsample, (j_compress_ptr cinfo,
  145287. JSAMPIMAGE input_buf, JDIMENSION in_row_index,
  145288. JSAMPIMAGE output_buf,
  145289. JDIMENSION out_row_group_index));
  145290. boolean need_context_rows; /* TRUE if need rows above & below */
  145291. };
  145292. struct jpeg_forward_dct {
  145293. JMETHOD(void, start_pass, (j_compress_ptr cinfo));
  145294. JMETHOD(void, forward_DCT, (j_compress_ptr cinfo,
  145295. jpeg_component_info * compptr,
  145296. JSAMPARRAY sample_data, JBLOCKROW coef_blocks,
  145297. JDIMENSION start_row, JDIMENSION start_col,
  145298. JDIMENSION num_blocks));
  145299. };
  145300. struct jpeg_entropy_encoder {
  145301. JMETHOD(void, start_pass, (j_compress_ptr cinfo, boolean gather_statistics));
  145302. JMETHOD(boolean, encode_mcu, (j_compress_ptr cinfo, JBLOCKROW *MCU_data));
  145303. JMETHOD(void, finish_pass, (j_compress_ptr cinfo));
  145304. };
  145305. struct jpeg_marker_writer {
  145306. JMETHOD(void, write_file_header, (j_compress_ptr cinfo));
  145307. JMETHOD(void, write_frame_header, (j_compress_ptr cinfo));
  145308. JMETHOD(void, write_scan_header, (j_compress_ptr cinfo));
  145309. JMETHOD(void, write_file_trailer, (j_compress_ptr cinfo));
  145310. JMETHOD(void, write_tables_only, (j_compress_ptr cinfo));
  145311. JMETHOD(void, write_marker_header, (j_compress_ptr cinfo, int marker,
  145312. unsigned int datalen));
  145313. JMETHOD(void, write_marker_byte, (j_compress_ptr cinfo, int val));
  145314. };
  145315. struct jpeg_decomp_master {
  145316. JMETHOD(void, prepare_for_output_pass, (j_decompress_ptr cinfo));
  145317. JMETHOD(void, finish_output_pass, (j_decompress_ptr cinfo));
  145318. boolean is_dummy_pass; /* True during 1st pass for 2-pass quant */
  145319. };
  145320. struct jpeg_input_controller {
  145321. JMETHOD(int, consume_input, (j_decompress_ptr cinfo));
  145322. JMETHOD(void, reset_input_controller, (j_decompress_ptr cinfo));
  145323. JMETHOD(void, start_input_pass, (j_decompress_ptr cinfo));
  145324. JMETHOD(void, finish_input_pass, (j_decompress_ptr cinfo));
  145325. boolean has_multiple_scans; /* True if file has multiple scans */
  145326. boolean eoi_reached; /* True when EOI has been consumed */
  145327. };
  145328. struct jpeg_d_main_controller {
  145329. JMETHOD(void, start_pass, (j_decompress_ptr cinfo, J_BUF_MODE pass_mode));
  145330. JMETHOD(void, process_data, (j_decompress_ptr cinfo,
  145331. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  145332. JDIMENSION out_rows_avail));
  145333. };
  145334. struct jpeg_d_coef_controller {
  145335. JMETHOD(void, start_input_pass, (j_decompress_ptr cinfo));
  145336. JMETHOD(int, consume_data, (j_decompress_ptr cinfo));
  145337. JMETHOD(void, start_output_pass, (j_decompress_ptr cinfo));
  145338. JMETHOD(int, decompress_data, (j_decompress_ptr cinfo,
  145339. JSAMPIMAGE output_buf));
  145340. jvirt_barray_ptr *coef_arrays;
  145341. };
  145342. struct jpeg_d_post_controller {
  145343. JMETHOD(void, start_pass, (j_decompress_ptr cinfo, J_BUF_MODE pass_mode));
  145344. JMETHOD(void, post_process_data, (j_decompress_ptr cinfo,
  145345. JSAMPIMAGE input_buf,
  145346. JDIMENSION *in_row_group_ctr,
  145347. JDIMENSION in_row_groups_avail,
  145348. JSAMPARRAY output_buf,
  145349. JDIMENSION *out_row_ctr,
  145350. JDIMENSION out_rows_avail));
  145351. };
  145352. struct jpeg_marker_reader {
  145353. JMETHOD(void, reset_marker_reader, (j_decompress_ptr cinfo));
  145354. JMETHOD(int, read_markers, (j_decompress_ptr cinfo));
  145355. jpeg_marker_parser_method read_restart_marker;
  145356. boolean saw_SOI; /* found SOI? */
  145357. boolean saw_SOF; /* found SOF? */
  145358. int next_restart_num; /* next restart number expected (0-7) */
  145359. unsigned int discarded_bytes; /* # of bytes skipped looking for a marker */
  145360. };
  145361. struct jpeg_entropy_decoder {
  145362. JMETHOD(void, start_pass, (j_decompress_ptr cinfo));
  145363. JMETHOD(boolean, decode_mcu, (j_decompress_ptr cinfo,
  145364. JBLOCKROW *MCU_data));
  145365. boolean insufficient_data; /* set TRUE after emitting warning */
  145366. };
  145367. typedef JMETHOD(void, inverse_DCT_method_ptr,
  145368. (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  145369. JCOEFPTR coef_block,
  145370. JSAMPARRAY output_buf, JDIMENSION output_col));
  145371. struct jpeg_inverse_dct {
  145372. JMETHOD(void, start_pass, (j_decompress_ptr cinfo));
  145373. inverse_DCT_method_ptr inverse_DCT[MAX_COMPONENTS];
  145374. };
  145375. struct jpeg_upsampler {
  145376. JMETHOD(void, start_pass, (j_decompress_ptr cinfo));
  145377. JMETHOD(void, upsample, (j_decompress_ptr cinfo,
  145378. JSAMPIMAGE input_buf,
  145379. JDIMENSION *in_row_group_ctr,
  145380. JDIMENSION in_row_groups_avail,
  145381. JSAMPARRAY output_buf,
  145382. JDIMENSION *out_row_ctr,
  145383. JDIMENSION out_rows_avail));
  145384. boolean need_context_rows; /* TRUE if need rows above & below */
  145385. };
  145386. struct jpeg_color_deconverter {
  145387. JMETHOD(void, start_pass, (j_decompress_ptr cinfo));
  145388. JMETHOD(void, color_convert, (j_decompress_ptr cinfo,
  145389. JSAMPIMAGE input_buf, JDIMENSION input_row,
  145390. JSAMPARRAY output_buf, int num_rows));
  145391. };
  145392. struct jpeg_color_quantizer {
  145393. JMETHOD(void, start_pass, (j_decompress_ptr cinfo, boolean is_pre_scan));
  145394. JMETHOD(void, color_quantize, (j_decompress_ptr cinfo,
  145395. JSAMPARRAY input_buf, JSAMPARRAY output_buf,
  145396. int num_rows));
  145397. JMETHOD(void, finish_pass, (j_decompress_ptr cinfo));
  145398. JMETHOD(void, new_color_map, (j_decompress_ptr cinfo));
  145399. };
  145400. #undef MAX
  145401. #define MAX(a,b) ((a) > (b) ? (a) : (b))
  145402. #undef MIN
  145403. #define MIN(a,b) ((a) < (b) ? (a) : (b))
  145404. #ifdef RIGHT_SHIFT_IS_UNSIGNED
  145405. #define SHIFT_TEMPS INT32 shift_temp;
  145406. #define RIGHT_SHIFT(x,shft) \
  145407. ((shift_temp = (x)) < 0 ? \
  145408. (shift_temp >> (shft)) | ((~((INT32) 0)) << (32-(shft))) : \
  145409. (shift_temp >> (shft)))
  145410. #else
  145411. #define SHIFT_TEMPS
  145412. #define RIGHT_SHIFT(x,shft) ((x) >> (shft))
  145413. #endif
  145414. #ifdef NEED_SHORT_EXTERNAL_NAMES
  145415. #define jinit_compress_master jICompress
  145416. #define jinit_c_master_control jICMaster
  145417. #define jinit_c_main_controller jICMainC
  145418. #define jinit_c_prep_controller jICPrepC
  145419. #define jinit_c_coef_controller jICCoefC
  145420. #define jinit_color_converter jICColor
  145421. #define jinit_downsampler jIDownsampler
  145422. #define jinit_forward_dct jIFDCT
  145423. #define jinit_huff_encoder jIHEncoder
  145424. #define jinit_phuff_encoder jIPHEncoder
  145425. #define jinit_marker_writer jIMWriter
  145426. #define jinit_master_decompress jIDMaster
  145427. #define jinit_d_main_controller jIDMainC
  145428. #define jinit_d_coef_controller jIDCoefC
  145429. #define jinit_d_post_controller jIDPostC
  145430. #define jinit_input_controller jIInCtlr
  145431. #define jinit_marker_reader jIMReader
  145432. #define jinit_huff_decoder jIHDecoder
  145433. #define jinit_phuff_decoder jIPHDecoder
  145434. #define jinit_inverse_dct jIIDCT
  145435. #define jinit_upsampler jIUpsampler
  145436. #define jinit_color_deconverter jIDColor
  145437. #define jinit_1pass_quantizer jI1Quant
  145438. #define jinit_2pass_quantizer jI2Quant
  145439. #define jinit_merged_upsampler jIMUpsampler
  145440. #define jinit_memory_mgr jIMemMgr
  145441. #define jdiv_round_up jDivRound
  145442. #define jround_up jRound
  145443. #define jcopy_sample_rows jCopySamples
  145444. #define jcopy_block_row jCopyBlocks
  145445. #define jzero_far jZeroFar
  145446. #define jpeg_zigzag_order jZIGTable
  145447. #define jpeg_natural_order jZAGTable
  145448. #endif /* NEED_SHORT_EXTERNAL_NAMES */
  145449. EXTERN(void) jinit_compress_master JPP((j_compress_ptr cinfo));
  145450. EXTERN(void) jinit_c_master_control JPP((j_compress_ptr cinfo,
  145451. boolean transcode_only));
  145452. EXTERN(void) jinit_c_main_controller JPP((j_compress_ptr cinfo,
  145453. boolean need_full_buffer));
  145454. EXTERN(void) jinit_c_prep_controller JPP((j_compress_ptr cinfo,
  145455. boolean need_full_buffer));
  145456. EXTERN(void) jinit_c_coef_controller JPP((j_compress_ptr cinfo,
  145457. boolean need_full_buffer));
  145458. EXTERN(void) jinit_color_converter JPP((j_compress_ptr cinfo));
  145459. EXTERN(void) jinit_downsampler JPP((j_compress_ptr cinfo));
  145460. EXTERN(void) jinit_forward_dct JPP((j_compress_ptr cinfo));
  145461. EXTERN(void) jinit_huff_encoder JPP((j_compress_ptr cinfo));
  145462. EXTERN(void) jinit_phuff_encoder JPP((j_compress_ptr cinfo));
  145463. EXTERN(void) jinit_marker_writer JPP((j_compress_ptr cinfo));
  145464. EXTERN(void) jinit_master_decompress JPP((j_decompress_ptr cinfo));
  145465. EXTERN(void) jinit_d_main_controller JPP((j_decompress_ptr cinfo,
  145466. boolean need_full_buffer));
  145467. EXTERN(void) jinit_d_coef_controller JPP((j_decompress_ptr cinfo,
  145468. boolean need_full_buffer));
  145469. EXTERN(void) jinit_d_post_controller JPP((j_decompress_ptr cinfo,
  145470. boolean need_full_buffer));
  145471. EXTERN(void) jinit_input_controller JPP((j_decompress_ptr cinfo));
  145472. EXTERN(void) jinit_marker_reader JPP((j_decompress_ptr cinfo));
  145473. EXTERN(void) jinit_huff_decoder JPP((j_decompress_ptr cinfo));
  145474. EXTERN(void) jinit_phuff_decoder JPP((j_decompress_ptr cinfo));
  145475. EXTERN(void) jinit_inverse_dct JPP((j_decompress_ptr cinfo));
  145476. EXTERN(void) jinit_upsampler JPP((j_decompress_ptr cinfo));
  145477. EXTERN(void) jinit_color_deconverter JPP((j_decompress_ptr cinfo));
  145478. EXTERN(void) jinit_1pass_quantizer JPP((j_decompress_ptr cinfo));
  145479. EXTERN(void) jinit_2pass_quantizer JPP((j_decompress_ptr cinfo));
  145480. EXTERN(void) jinit_merged_upsampler JPP((j_decompress_ptr cinfo));
  145481. EXTERN(void) jinit_memory_mgr JPP((j_common_ptr cinfo));
  145482. EXTERN(long) jdiv_round_up JPP((long a, long b));
  145483. EXTERN(long) jround_up JPP((long a, long b));
  145484. EXTERN(void) jcopy_sample_rows JPP((JSAMPARRAY input_array, int source_row,
  145485. JSAMPARRAY output_array, int dest_row,
  145486. int num_rows, JDIMENSION num_cols));
  145487. EXTERN(void) jcopy_block_row JPP((JBLOCKROW input_row, JBLOCKROW output_row,
  145488. JDIMENSION num_blocks));
  145489. EXTERN(void) jzero_far JPP((void FAR * target, size_t bytestozero));
  145490. #if 0 /* This table is not actually needed in v6a */
  145491. extern const int jpeg_zigzag_order[]; /* natural coef order to zigzag order */
  145492. #endif
  145493. extern const int jpeg_natural_order[]; /* zigzag coef order to natural order */
  145494. #ifdef INCOMPLETE_TYPES_BROKEN
  145495. #ifndef AM_MEMORY_MANAGER /* only jmemmgr.c defines these */
  145496. struct jvirt_sarray_control { long dummy; };
  145497. struct jvirt_barray_control { long dummy; };
  145498. #endif
  145499. #endif /* INCOMPLETE_TYPES_BROKEN */
  145500. /*** End of inlined file: jpegint.h ***/
  145501. /* fetch private declarations */
  145502. /*** Start of inlined file: jerror.h ***/
  145503. #ifndef JMESSAGE
  145504. #ifndef JERROR_H
  145505. #define JMAKE_ENUM_LIST
  145506. #else
  145507. #define JMESSAGE(code,string)
  145508. #endif /* JERROR_H */
  145509. #endif /* JMESSAGE */
  145510. #ifdef JMAKE_ENUM_LIST
  145511. typedef enum {
  145512. #define JMESSAGE(code,string) code ,
  145513. #endif /* JMAKE_ENUM_LIST */
  145514. JMESSAGE(JMSG_NOMESSAGE, "Bogus message code %d") /* Must be first entry! */
  145515. JMESSAGE(JERR_ARITH_NOTIMPL,
  145516. "Sorry, there are legal restrictions on arithmetic coding")
  145517. JMESSAGE(JERR_BAD_ALIGN_TYPE, "ALIGN_TYPE is wrong, please fix")
  145518. JMESSAGE(JERR_BAD_ALLOC_CHUNK, "MAX_ALLOC_CHUNK is wrong, please fix")
  145519. JMESSAGE(JERR_BAD_BUFFER_MODE, "Bogus buffer control mode")
  145520. JMESSAGE(JERR_BAD_COMPONENT_ID, "Invalid component ID %d in SOS")
  145521. JMESSAGE(JERR_BAD_DCT_COEF, "DCT coefficient out of range")
  145522. JMESSAGE(JERR_BAD_DCTSIZE, "IDCT output block size %d not supported")
  145523. JMESSAGE(JERR_BAD_HUFF_TABLE, "Bogus Huffman table definition")
  145524. JMESSAGE(JERR_BAD_IN_COLORSPACE, "Bogus input colorspace")
  145525. JMESSAGE(JERR_BAD_J_COLORSPACE, "Bogus JPEG colorspace")
  145526. JMESSAGE(JERR_BAD_LENGTH, "Bogus marker length")
  145527. JMESSAGE(JERR_BAD_LIB_VERSION,
  145528. "Wrong JPEG library version: library is %d, caller expects %d")
  145529. JMESSAGE(JERR_BAD_MCU_SIZE, "Sampling factors too large for interleaved scan")
  145530. JMESSAGE(JERR_BAD_POOL_ID, "Invalid memory pool code %d")
  145531. JMESSAGE(JERR_BAD_PRECISION, "Unsupported JPEG data precision %d")
  145532. JMESSAGE(JERR_BAD_PROGRESSION,
  145533. "Invalid progressive parameters Ss=%d Se=%d Ah=%d Al=%d")
  145534. JMESSAGE(JERR_BAD_PROG_SCRIPT,
  145535. "Invalid progressive parameters at scan script entry %d")
  145536. JMESSAGE(JERR_BAD_SAMPLING, "Bogus sampling factors")
  145537. JMESSAGE(JERR_BAD_SCAN_SCRIPT, "Invalid scan script at entry %d")
  145538. JMESSAGE(JERR_BAD_STATE, "Improper call to JPEG library in state %d")
  145539. JMESSAGE(JERR_BAD_STRUCT_SIZE,
  145540. "JPEG parameter struct mismatch: library thinks size is %u, caller expects %u")
  145541. JMESSAGE(JERR_BAD_VIRTUAL_ACCESS, "Bogus virtual array access")
  145542. JMESSAGE(JERR_BUFFER_SIZE, "Buffer passed to JPEG library is too small")
  145543. JMESSAGE(JERR_CANT_SUSPEND, "Suspension not allowed here")
  145544. JMESSAGE(JERR_CCIR601_NOTIMPL, "CCIR601 sampling not implemented yet")
  145545. JMESSAGE(JERR_COMPONENT_COUNT, "Too many color components: %d, max %d")
  145546. JMESSAGE(JERR_CONVERSION_NOTIMPL, "Unsupported color conversion request")
  145547. JMESSAGE(JERR_DAC_INDEX, "Bogus DAC index %d")
  145548. JMESSAGE(JERR_DAC_VALUE, "Bogus DAC value 0x%x")
  145549. JMESSAGE(JERR_DHT_INDEX, "Bogus DHT index %d")
  145550. JMESSAGE(JERR_DQT_INDEX, "Bogus DQT index %d")
  145551. JMESSAGE(JERR_EMPTY_IMAGE, "Empty JPEG image (DNL not supported)")
  145552. JMESSAGE(JERR_EMS_READ, "Read from EMS failed")
  145553. JMESSAGE(JERR_EMS_WRITE, "Write to EMS failed")
  145554. JMESSAGE(JERR_EOI_EXPECTED, "Didn't expect more than one scan")
  145555. JMESSAGE(JERR_FILE_READ, "Input file read error")
  145556. JMESSAGE(JERR_FILE_WRITE, "Output file write error --- out of disk space?")
  145557. JMESSAGE(JERR_FRACT_SAMPLE_NOTIMPL, "Fractional sampling not implemented yet")
  145558. JMESSAGE(JERR_HUFF_CLEN_OVERFLOW, "Huffman code size table overflow")
  145559. JMESSAGE(JERR_HUFF_MISSING_CODE, "Missing Huffman code table entry")
  145560. JMESSAGE(JERR_IMAGE_TOO_BIG, "Maximum supported image dimension is %u pixels")
  145561. JMESSAGE(JERR_INPUT_EMPTY, "Empty input file")
  145562. JMESSAGE(JERR_INPUT_EOF, "Premature end of input file")
  145563. JMESSAGE(JERR_MISMATCHED_QUANT_TABLE,
  145564. "Cannot transcode due to multiple use of quantization table %d")
  145565. JMESSAGE(JERR_MISSING_DATA, "Scan script does not transmit all data")
  145566. JMESSAGE(JERR_MODE_CHANGE, "Invalid color quantization mode change")
  145567. JMESSAGE(JERR_NOTIMPL, "Not implemented yet")
  145568. JMESSAGE(JERR_NOT_COMPILED, "Requested feature was omitted at compile time")
  145569. JMESSAGE(JERR_NO_BACKING_STORE, "Backing store not supported")
  145570. JMESSAGE(JERR_NO_HUFF_TABLE, "Huffman table 0x%02x was not defined")
  145571. JMESSAGE(JERR_NO_IMAGE, "JPEG datastream contains no image")
  145572. JMESSAGE(JERR_NO_QUANT_TABLE, "Quantization table 0x%02x was not defined")
  145573. JMESSAGE(JERR_NO_SOI, "Not a JPEG file: starts with 0x%02x 0x%02x")
  145574. JMESSAGE(JERR_OUT_OF_MEMORY, "Insufficient memory (case %d)")
  145575. JMESSAGE(JERR_QUANT_COMPONENTS,
  145576. "Cannot quantize more than %d color components")
  145577. JMESSAGE(JERR_QUANT_FEW_COLORS, "Cannot quantize to fewer than %d colors")
  145578. JMESSAGE(JERR_QUANT_MANY_COLORS, "Cannot quantize to more than %d colors")
  145579. JMESSAGE(JERR_SOF_DUPLICATE, "Invalid JPEG file structure: two SOF markers")
  145580. JMESSAGE(JERR_SOF_NO_SOS, "Invalid JPEG file structure: missing SOS marker")
  145581. JMESSAGE(JERR_SOF_UNSUPPORTED, "Unsupported JPEG process: SOF type 0x%02x")
  145582. JMESSAGE(JERR_SOI_DUPLICATE, "Invalid JPEG file structure: two SOI markers")
  145583. JMESSAGE(JERR_SOS_NO_SOF, "Invalid JPEG file structure: SOS before SOF")
  145584. JMESSAGE(JERR_TFILE_CREATE, "Failed to create temporary file %s")
  145585. JMESSAGE(JERR_TFILE_READ, "Read failed on temporary file")
  145586. JMESSAGE(JERR_TFILE_SEEK, "Seek failed on temporary file")
  145587. JMESSAGE(JERR_TFILE_WRITE,
  145588. "Write failed on temporary file --- out of disk space?")
  145589. JMESSAGE(JERR_TOO_LITTLE_DATA, "Application transferred too few scanlines")
  145590. JMESSAGE(JERR_UNKNOWN_MARKER, "Unsupported marker type 0x%02x")
  145591. JMESSAGE(JERR_VIRTUAL_BUG, "Virtual array controller messed up")
  145592. JMESSAGE(JERR_WIDTH_OVERFLOW, "Image too wide for this implementation")
  145593. JMESSAGE(JERR_XMS_READ, "Read from XMS failed")
  145594. JMESSAGE(JERR_XMS_WRITE, "Write to XMS failed")
  145595. JMESSAGE(JMSG_COPYRIGHT, JCOPYRIGHT)
  145596. JMESSAGE(JMSG_VERSION, JVERSION)
  145597. JMESSAGE(JTRC_16BIT_TABLES,
  145598. "Caution: quantization tables are too coarse for baseline JPEG")
  145599. JMESSAGE(JTRC_ADOBE,
  145600. "Adobe APP14 marker: version %d, flags 0x%04x 0x%04x, transform %d")
  145601. JMESSAGE(JTRC_APP0, "Unknown APP0 marker (not JFIF), length %u")
  145602. JMESSAGE(JTRC_APP14, "Unknown APP14 marker (not Adobe), length %u")
  145603. JMESSAGE(JTRC_DAC, "Define Arithmetic Table 0x%02x: 0x%02x")
  145604. JMESSAGE(JTRC_DHT, "Define Huffman Table 0x%02x")
  145605. JMESSAGE(JTRC_DQT, "Define Quantization Table %d precision %d")
  145606. JMESSAGE(JTRC_DRI, "Define Restart Interval %u")
  145607. JMESSAGE(JTRC_EMS_CLOSE, "Freed EMS handle %u")
  145608. JMESSAGE(JTRC_EMS_OPEN, "Obtained EMS handle %u")
  145609. JMESSAGE(JTRC_EOI, "End Of Image")
  145610. JMESSAGE(JTRC_HUFFBITS, " %3d %3d %3d %3d %3d %3d %3d %3d")
  145611. JMESSAGE(JTRC_JFIF, "JFIF APP0 marker: version %d.%02d, density %dx%d %d")
  145612. JMESSAGE(JTRC_JFIF_BADTHUMBNAILSIZE,
  145613. "Warning: thumbnail image size does not match data length %u")
  145614. JMESSAGE(JTRC_JFIF_EXTENSION,
  145615. "JFIF extension marker: type 0x%02x, length %u")
  145616. JMESSAGE(JTRC_JFIF_THUMBNAIL, " with %d x %d thumbnail image")
  145617. JMESSAGE(JTRC_MISC_MARKER, "Miscellaneous marker 0x%02x, length %u")
  145618. JMESSAGE(JTRC_PARMLESS_MARKER, "Unexpected marker 0x%02x")
  145619. JMESSAGE(JTRC_QUANTVALS, " %4u %4u %4u %4u %4u %4u %4u %4u")
  145620. JMESSAGE(JTRC_QUANT_3_NCOLORS, "Quantizing to %d = %d*%d*%d colors")
  145621. JMESSAGE(JTRC_QUANT_NCOLORS, "Quantizing to %d colors")
  145622. JMESSAGE(JTRC_QUANT_SELECTED, "Selected %d colors for quantization")
  145623. JMESSAGE(JTRC_RECOVERY_ACTION, "At marker 0x%02x, recovery action %d")
  145624. JMESSAGE(JTRC_RST, "RST%d")
  145625. JMESSAGE(JTRC_SMOOTH_NOTIMPL,
  145626. "Smoothing not supported with nonstandard sampling ratios")
  145627. JMESSAGE(JTRC_SOF, "Start Of Frame 0x%02x: width=%u, height=%u, components=%d")
  145628. JMESSAGE(JTRC_SOF_COMPONENT, " Component %d: %dhx%dv q=%d")
  145629. JMESSAGE(JTRC_SOI, "Start of Image")
  145630. JMESSAGE(JTRC_SOS, "Start Of Scan: %d components")
  145631. JMESSAGE(JTRC_SOS_COMPONENT, " Component %d: dc=%d ac=%d")
  145632. JMESSAGE(JTRC_SOS_PARAMS, " Ss=%d, Se=%d, Ah=%d, Al=%d")
  145633. JMESSAGE(JTRC_TFILE_CLOSE, "Closed temporary file %s")
  145634. JMESSAGE(JTRC_TFILE_OPEN, "Opened temporary file %s")
  145635. JMESSAGE(JTRC_THUMB_JPEG,
  145636. "JFIF extension marker: JPEG-compressed thumbnail image, length %u")
  145637. JMESSAGE(JTRC_THUMB_PALETTE,
  145638. "JFIF extension marker: palette thumbnail image, length %u")
  145639. JMESSAGE(JTRC_THUMB_RGB,
  145640. "JFIF extension marker: RGB thumbnail image, length %u")
  145641. JMESSAGE(JTRC_UNKNOWN_IDS,
  145642. "Unrecognized component IDs %d %d %d, assuming YCbCr")
  145643. JMESSAGE(JTRC_XMS_CLOSE, "Freed XMS handle %u")
  145644. JMESSAGE(JTRC_XMS_OPEN, "Obtained XMS handle %u")
  145645. JMESSAGE(JWRN_ADOBE_XFORM, "Unknown Adobe color transform code %d")
  145646. JMESSAGE(JWRN_BOGUS_PROGRESSION,
  145647. "Inconsistent progression sequence for component %d coefficient %d")
  145648. JMESSAGE(JWRN_EXTRANEOUS_DATA,
  145649. "Corrupt JPEG data: %u extraneous bytes before marker 0x%02x")
  145650. JMESSAGE(JWRN_HIT_MARKER, "Corrupt JPEG data: premature end of data segment")
  145651. JMESSAGE(JWRN_HUFF_BAD_CODE, "Corrupt JPEG data: bad Huffman code")
  145652. JMESSAGE(JWRN_JFIF_MAJOR, "Warning: unknown JFIF revision number %d.%02d")
  145653. JMESSAGE(JWRN_JPEG_EOF, "Premature end of JPEG file")
  145654. JMESSAGE(JWRN_MUST_RESYNC,
  145655. "Corrupt JPEG data: found marker 0x%02x instead of RST%d")
  145656. JMESSAGE(JWRN_NOT_SEQUENTIAL, "Invalid SOS parameters for sequential JPEG")
  145657. JMESSAGE(JWRN_TOO_MUCH_DATA, "Application transferred too many scanlines")
  145658. #ifdef JMAKE_ENUM_LIST
  145659. JMSG_LASTMSGCODE
  145660. } J_MESSAGE_CODE;
  145661. #undef JMAKE_ENUM_LIST
  145662. #endif /* JMAKE_ENUM_LIST */
  145663. #undef JMESSAGE
  145664. #ifndef JERROR_H
  145665. #define JERROR_H
  145666. #define ERREXIT(cinfo,code) \
  145667. ((cinfo)->err->msg_code = (code), \
  145668. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  145669. #define ERREXIT1(cinfo,code,p1) \
  145670. ((cinfo)->err->msg_code = (code), \
  145671. (cinfo)->err->msg_parm.i[0] = (p1), \
  145672. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  145673. #define ERREXIT2(cinfo,code,p1,p2) \
  145674. ((cinfo)->err->msg_code = (code), \
  145675. (cinfo)->err->msg_parm.i[0] = (p1), \
  145676. (cinfo)->err->msg_parm.i[1] = (p2), \
  145677. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  145678. #define ERREXIT3(cinfo,code,p1,p2,p3) \
  145679. ((cinfo)->err->msg_code = (code), \
  145680. (cinfo)->err->msg_parm.i[0] = (p1), \
  145681. (cinfo)->err->msg_parm.i[1] = (p2), \
  145682. (cinfo)->err->msg_parm.i[2] = (p3), \
  145683. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  145684. #define ERREXIT4(cinfo,code,p1,p2,p3,p4) \
  145685. ((cinfo)->err->msg_code = (code), \
  145686. (cinfo)->err->msg_parm.i[0] = (p1), \
  145687. (cinfo)->err->msg_parm.i[1] = (p2), \
  145688. (cinfo)->err->msg_parm.i[2] = (p3), \
  145689. (cinfo)->err->msg_parm.i[3] = (p4), \
  145690. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  145691. #define ERREXITS(cinfo,code,str) \
  145692. ((cinfo)->err->msg_code = (code), \
  145693. strncpy((cinfo)->err->msg_parm.s, (str), JMSG_STR_PARM_MAX), \
  145694. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  145695. #define MAKESTMT(stuff) do { stuff } while (0)
  145696. #define WARNMS(cinfo,code) \
  145697. ((cinfo)->err->msg_code = (code), \
  145698. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), -1))
  145699. #define WARNMS1(cinfo,code,p1) \
  145700. ((cinfo)->err->msg_code = (code), \
  145701. (cinfo)->err->msg_parm.i[0] = (p1), \
  145702. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), -1))
  145703. #define WARNMS2(cinfo,code,p1,p2) \
  145704. ((cinfo)->err->msg_code = (code), \
  145705. (cinfo)->err->msg_parm.i[0] = (p1), \
  145706. (cinfo)->err->msg_parm.i[1] = (p2), \
  145707. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), -1))
  145708. #define TRACEMS(cinfo,lvl,code) \
  145709. ((cinfo)->err->msg_code = (code), \
  145710. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)))
  145711. #define TRACEMS1(cinfo,lvl,code,p1) \
  145712. ((cinfo)->err->msg_code = (code), \
  145713. (cinfo)->err->msg_parm.i[0] = (p1), \
  145714. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)))
  145715. #define TRACEMS2(cinfo,lvl,code,p1,p2) \
  145716. ((cinfo)->err->msg_code = (code), \
  145717. (cinfo)->err->msg_parm.i[0] = (p1), \
  145718. (cinfo)->err->msg_parm.i[1] = (p2), \
  145719. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)))
  145720. #define TRACEMS3(cinfo,lvl,code,p1,p2,p3) \
  145721. MAKESTMT(int * _mp = (cinfo)->err->msg_parm.i; \
  145722. _mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); \
  145723. (cinfo)->err->msg_code = (code); \
  145724. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)); )
  145725. #define TRACEMS4(cinfo,lvl,code,p1,p2,p3,p4) \
  145726. MAKESTMT(int * _mp = (cinfo)->err->msg_parm.i; \
  145727. _mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); _mp[3] = (p4); \
  145728. (cinfo)->err->msg_code = (code); \
  145729. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)); )
  145730. #define TRACEMS5(cinfo,lvl,code,p1,p2,p3,p4,p5) \
  145731. MAKESTMT(int * _mp = (cinfo)->err->msg_parm.i; \
  145732. _mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); _mp[3] = (p4); \
  145733. _mp[4] = (p5); \
  145734. (cinfo)->err->msg_code = (code); \
  145735. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)); )
  145736. #define TRACEMS8(cinfo,lvl,code,p1,p2,p3,p4,p5,p6,p7,p8) \
  145737. MAKESTMT(int * _mp = (cinfo)->err->msg_parm.i; \
  145738. _mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); _mp[3] = (p4); \
  145739. _mp[4] = (p5); _mp[5] = (p6); _mp[6] = (p7); _mp[7] = (p8); \
  145740. (cinfo)->err->msg_code = (code); \
  145741. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)); )
  145742. #define TRACEMSS(cinfo,lvl,code,str) \
  145743. ((cinfo)->err->msg_code = (code), \
  145744. strncpy((cinfo)->err->msg_parm.s, (str), JMSG_STR_PARM_MAX), \
  145745. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)))
  145746. #endif /* JERROR_H */
  145747. /*** End of inlined file: jerror.h ***/
  145748. /* fetch error codes too */
  145749. #endif
  145750. #endif /* JPEGLIB_H */
  145751. /*** End of inlined file: jpeglib.h ***/
  145752. /*** Start of inlined file: jcapimin.c ***/
  145753. #define JPEG_INTERNALS
  145754. /*** Start of inlined file: jinclude.h ***/
  145755. #ifndef __jinclude_h__
  145756. #define __jinclude_h__
  145757. /*** Start of inlined file: jconfig.h ***/
  145758. // disable all the warnings under MSVC
  145759. #ifdef _MSC_VER
  145760. #pragma warning (disable: 4996 4267 4100 4127 4702 4244)
  145761. #endif
  145762. #ifdef __BORLANDC__
  145763. #pragma warn -8057
  145764. #pragma warn -8019
  145765. #pragma warn -8004
  145766. #pragma warn -8008
  145767. #endif
  145768. #define HAVE_PROTOTYPES
  145769. #define HAVE_UNSIGNED_CHAR
  145770. #define HAVE_UNSIGNED_SHORT
  145771. #undef CHAR_IS_UNSIGNED
  145772. #define HAVE_STDDEF_H
  145773. #define HAVE_STDLIB_H
  145774. #undef NEED_BSD_STRINGS
  145775. #undef NEED_SYS_TYPES_H
  145776. #undef NEED_FAR_POINTERS /* we presume a 32-bit flat memory model */
  145777. #undef NEED_SHORT_EXTERNAL_NAMES
  145778. #undef INCOMPLETE_TYPES_BROKEN
  145779. #ifndef __RPCNDR_H__ /* don't conflict if rpcndr.h already read */
  145780. typedef unsigned char boolean;
  145781. #endif
  145782. #define HAVE_BOOLEAN /* prevent jmorecfg.h from redefining it */
  145783. #ifdef JPEG_INTERNALS
  145784. #undef RIGHT_SHIFT_IS_UNSIGNED
  145785. #endif /* JPEG_INTERNALS */
  145786. #ifdef JPEG_CJPEG_DJPEG
  145787. #define BMP_SUPPORTED /* BMP image file format */
  145788. #define GIF_SUPPORTED /* GIF image file format */
  145789. #define PPM_SUPPORTED /* PBMPLUS PPM/PGM image file format */
  145790. #undef RLE_SUPPORTED /* Utah RLE image file format */
  145791. #define TARGA_SUPPORTED /* Targa image file format */
  145792. #define TWO_FILE_COMMANDLINE /* optional */
  145793. #define USE_SETMODE /* Microsoft has setmode() */
  145794. #undef NEED_SIGNAL_CATCHER
  145795. #undef DONT_USE_B_MODE
  145796. #undef PROGRESS_REPORT /* optional */
  145797. #endif /* JPEG_CJPEG_DJPEG */
  145798. /*** End of inlined file: jconfig.h ***/
  145799. /* auto configuration options */
  145800. #define JCONFIG_INCLUDED /* so that jpeglib.h doesn't do it again */
  145801. #ifdef HAVE_STDDEF_H
  145802. #include <stddef.h>
  145803. #endif
  145804. #ifdef HAVE_STDLIB_H
  145805. #include <stdlib.h>
  145806. #endif
  145807. #ifdef NEED_SYS_TYPES_H
  145808. #include <sys/types.h>
  145809. #endif
  145810. #include <stdio.h>
  145811. #ifdef NEED_BSD_STRINGS
  145812. #include <strings.h>
  145813. #define MEMZERO(target,size) bzero((void *)(target), (size_t)(size))
  145814. #define MEMCOPY(dest,src,size) bcopy((const void *)(src), (void *)(dest), (size_t)(size))
  145815. #else /* not BSD, assume ANSI/SysV string lib */
  145816. #include <string.h>
  145817. #define MEMZERO(target,size) memset((void *)(target), 0, (size_t)(size))
  145818. #define MEMCOPY(dest,src,size) memcpy((void *)(dest), (const void *)(src), (size_t)(size))
  145819. #endif
  145820. #define SIZEOF(object) ((size_t) sizeof(object))
  145821. #define JFREAD(file,buf,sizeofbuf) \
  145822. ((size_t) fread((void *) (buf), (size_t) 1, (size_t) (sizeofbuf), (file)))
  145823. #define JFWRITE(file,buf,sizeofbuf) \
  145824. ((size_t) fwrite((const void *) (buf), (size_t) 1, (size_t) (sizeofbuf), (file)))
  145825. typedef enum { /* JPEG marker codes */
  145826. M_SOF0 = 0xc0,
  145827. M_SOF1 = 0xc1,
  145828. M_SOF2 = 0xc2,
  145829. M_SOF3 = 0xc3,
  145830. M_SOF5 = 0xc5,
  145831. M_SOF6 = 0xc6,
  145832. M_SOF7 = 0xc7,
  145833. M_JPG = 0xc8,
  145834. M_SOF9 = 0xc9,
  145835. M_SOF10 = 0xca,
  145836. M_SOF11 = 0xcb,
  145837. M_SOF13 = 0xcd,
  145838. M_SOF14 = 0xce,
  145839. M_SOF15 = 0xcf,
  145840. M_DHT = 0xc4,
  145841. M_DAC = 0xcc,
  145842. M_RST0 = 0xd0,
  145843. M_RST1 = 0xd1,
  145844. M_RST2 = 0xd2,
  145845. M_RST3 = 0xd3,
  145846. M_RST4 = 0xd4,
  145847. M_RST5 = 0xd5,
  145848. M_RST6 = 0xd6,
  145849. M_RST7 = 0xd7,
  145850. M_SOI = 0xd8,
  145851. M_EOI = 0xd9,
  145852. M_SOS = 0xda,
  145853. M_DQT = 0xdb,
  145854. M_DNL = 0xdc,
  145855. M_DRI = 0xdd,
  145856. M_DHP = 0xde,
  145857. M_EXP = 0xdf,
  145858. M_APP0 = 0xe0,
  145859. M_APP1 = 0xe1,
  145860. M_APP2 = 0xe2,
  145861. M_APP3 = 0xe3,
  145862. M_APP4 = 0xe4,
  145863. M_APP5 = 0xe5,
  145864. M_APP6 = 0xe6,
  145865. M_APP7 = 0xe7,
  145866. M_APP8 = 0xe8,
  145867. M_APP9 = 0xe9,
  145868. M_APP10 = 0xea,
  145869. M_APP11 = 0xeb,
  145870. M_APP12 = 0xec,
  145871. M_APP13 = 0xed,
  145872. M_APP14 = 0xee,
  145873. M_APP15 = 0xef,
  145874. M_JPG0 = 0xf0,
  145875. M_JPG13 = 0xfd,
  145876. M_COM = 0xfe,
  145877. M_TEM = 0x01,
  145878. M_ERROR = 0x100
  145879. } JPEG_MARKER;
  145880. #ifdef AVOID_TABLES
  145881. #define HUFF_EXTEND(x,s) ((x) < (1<<((s)-1)) ? (x) + (((-1)<<(s)) + 1) : (x))
  145882. #else
  145883. #define HUFF_EXTEND(x,s) ((x) < extend_test[s] ? (x) + extend_offset[s] : (x))
  145884. static const int extend_test[16] = /* entry n is 2**(n-1) */
  145885. { 0, 0x0001, 0x0002, 0x0004, 0x0008, 0x0010, 0x0020, 0x0040, 0x0080,
  145886. 0x0100, 0x0200, 0x0400, 0x0800, 0x1000, 0x2000, 0x4000 };
  145887. static const int extend_offset[16] = /* entry n is (-1 << n) + 1 */
  145888. { 0, ((-1)<<1) + 1, ((-1)<<2) + 1, ((-1)<<3) + 1, ((-1)<<4) + 1,
  145889. ((-1)<<5) + 1, ((-1)<<6) + 1, ((-1)<<7) + 1, ((-1)<<8) + 1,
  145890. ((-1)<<9) + 1, ((-1)<<10) + 1, ((-1)<<11) + 1, ((-1)<<12) + 1,
  145891. ((-1)<<13) + 1, ((-1)<<14) + 1, ((-1)<<15) + 1 };
  145892. #endif /* AVOID_TABLES */
  145893. #endif
  145894. /*** End of inlined file: jinclude.h ***/
  145895. GLOBAL(void)
  145896. jpeg_CreateCompress (j_compress_ptr cinfo, int version, size_t structsize)
  145897. {
  145898. int i;
  145899. cinfo->mem = NULL; /* so jpeg_destroy knows mem mgr not called */
  145900. if (version != JPEG_LIB_VERSION)
  145901. ERREXIT2(cinfo, JERR_BAD_LIB_VERSION, JPEG_LIB_VERSION, version);
  145902. if (structsize != SIZEOF(struct jpeg_compress_struct))
  145903. ERREXIT2(cinfo, JERR_BAD_STRUCT_SIZE,
  145904. (int) SIZEOF(struct jpeg_compress_struct), (int) structsize);
  145905. {
  145906. struct jpeg_error_mgr * err = cinfo->err;
  145907. void * client_data = cinfo->client_data; /* ignore Purify complaint here */
  145908. MEMZERO(cinfo, SIZEOF(struct jpeg_compress_struct));
  145909. cinfo->err = err;
  145910. cinfo->client_data = client_data;
  145911. }
  145912. cinfo->is_decompressor = FALSE;
  145913. jinit_memory_mgr((j_common_ptr) cinfo);
  145914. cinfo->progress = NULL;
  145915. cinfo->dest = NULL;
  145916. cinfo->comp_info = NULL;
  145917. for (i = 0; i < NUM_QUANT_TBLS; i++)
  145918. cinfo->quant_tbl_ptrs[i] = NULL;
  145919. for (i = 0; i < NUM_HUFF_TBLS; i++) {
  145920. cinfo->dc_huff_tbl_ptrs[i] = NULL;
  145921. cinfo->ac_huff_tbl_ptrs[i] = NULL;
  145922. }
  145923. cinfo->script_space = NULL;
  145924. cinfo->input_gamma = 1.0; /* in case application forgets */
  145925. cinfo->global_state = CSTATE_START;
  145926. }
  145927. GLOBAL(void)
  145928. jpeg_destroy_compress (j_compress_ptr cinfo)
  145929. {
  145930. jpeg_destroy((j_common_ptr) cinfo); /* use common routine */
  145931. }
  145932. GLOBAL(void)
  145933. jpeg_abort_compress (j_compress_ptr cinfo)
  145934. {
  145935. jpeg_abort((j_common_ptr) cinfo); /* use common routine */
  145936. }
  145937. GLOBAL(void)
  145938. jpeg_suppress_tables (j_compress_ptr cinfo, boolean suppress)
  145939. {
  145940. int i;
  145941. JQUANT_TBL * qtbl;
  145942. JHUFF_TBL * htbl;
  145943. for (i = 0; i < NUM_QUANT_TBLS; i++) {
  145944. if ((qtbl = cinfo->quant_tbl_ptrs[i]) != NULL)
  145945. qtbl->sent_table = suppress;
  145946. }
  145947. for (i = 0; i < NUM_HUFF_TBLS; i++) {
  145948. if ((htbl = cinfo->dc_huff_tbl_ptrs[i]) != NULL)
  145949. htbl->sent_table = suppress;
  145950. if ((htbl = cinfo->ac_huff_tbl_ptrs[i]) != NULL)
  145951. htbl->sent_table = suppress;
  145952. }
  145953. }
  145954. GLOBAL(void)
  145955. jpeg_finish_compress (j_compress_ptr cinfo)
  145956. {
  145957. JDIMENSION iMCU_row;
  145958. if (cinfo->global_state == CSTATE_SCANNING ||
  145959. cinfo->global_state == CSTATE_RAW_OK) {
  145960. if (cinfo->next_scanline < cinfo->image_height)
  145961. ERREXIT(cinfo, JERR_TOO_LITTLE_DATA);
  145962. (*cinfo->master->finish_pass) (cinfo);
  145963. } else if (cinfo->global_state != CSTATE_WRCOEFS)
  145964. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  145965. while (! cinfo->master->is_last_pass) {
  145966. (*cinfo->master->prepare_for_pass) (cinfo);
  145967. for (iMCU_row = 0; iMCU_row < cinfo->total_iMCU_rows; iMCU_row++) {
  145968. if (cinfo->progress != NULL) {
  145969. cinfo->progress->pass_counter = (long) iMCU_row;
  145970. cinfo->progress->pass_limit = (long) cinfo->total_iMCU_rows;
  145971. (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
  145972. }
  145973. if (! (*cinfo->coef->compress_data) (cinfo, (JSAMPIMAGE) NULL))
  145974. ERREXIT(cinfo, JERR_CANT_SUSPEND);
  145975. }
  145976. (*cinfo->master->finish_pass) (cinfo);
  145977. }
  145978. (*cinfo->marker->write_file_trailer) (cinfo);
  145979. (*cinfo->dest->term_destination) (cinfo);
  145980. jpeg_abort((j_common_ptr) cinfo);
  145981. }
  145982. GLOBAL(void)
  145983. jpeg_write_marker (j_compress_ptr cinfo, int marker,
  145984. const JOCTET *dataptr, unsigned int datalen)
  145985. {
  145986. JMETHOD(void, write_marker_byte, (j_compress_ptr info, int val));
  145987. if (cinfo->next_scanline != 0 ||
  145988. (cinfo->global_state != CSTATE_SCANNING &&
  145989. cinfo->global_state != CSTATE_RAW_OK &&
  145990. cinfo->global_state != CSTATE_WRCOEFS))
  145991. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  145992. (*cinfo->marker->write_marker_header) (cinfo, marker, datalen);
  145993. write_marker_byte = cinfo->marker->write_marker_byte; /* copy for speed */
  145994. while (datalen--) {
  145995. (*write_marker_byte) (cinfo, *dataptr);
  145996. dataptr++;
  145997. }
  145998. }
  145999. GLOBAL(void)
  146000. jpeg_write_m_header (j_compress_ptr cinfo, int marker, unsigned int datalen)
  146001. {
  146002. if (cinfo->next_scanline != 0 ||
  146003. (cinfo->global_state != CSTATE_SCANNING &&
  146004. cinfo->global_state != CSTATE_RAW_OK &&
  146005. cinfo->global_state != CSTATE_WRCOEFS))
  146006. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  146007. (*cinfo->marker->write_marker_header) (cinfo, marker, datalen);
  146008. }
  146009. GLOBAL(void)
  146010. jpeg_write_m_byte (j_compress_ptr cinfo, int val)
  146011. {
  146012. (*cinfo->marker->write_marker_byte) (cinfo, val);
  146013. }
  146014. GLOBAL(void)
  146015. jpeg_write_tables (j_compress_ptr cinfo)
  146016. {
  146017. if (cinfo->global_state != CSTATE_START)
  146018. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  146019. (*cinfo->err->reset_error_mgr) ((j_common_ptr) cinfo);
  146020. (*cinfo->dest->init_destination) (cinfo);
  146021. jinit_marker_writer(cinfo);
  146022. (*cinfo->marker->write_tables_only) (cinfo);
  146023. (*cinfo->dest->term_destination) (cinfo);
  146024. }
  146025. /*** End of inlined file: jcapimin.c ***/
  146026. /*** Start of inlined file: jcapistd.c ***/
  146027. #define JPEG_INTERNALS
  146028. GLOBAL(void)
  146029. jpeg_start_compress (j_compress_ptr cinfo, boolean write_all_tables)
  146030. {
  146031. if (cinfo->global_state != CSTATE_START)
  146032. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  146033. if (write_all_tables)
  146034. jpeg_suppress_tables(cinfo, FALSE); /* mark all tables to be written */
  146035. (*cinfo->err->reset_error_mgr) ((j_common_ptr) cinfo);
  146036. (*cinfo->dest->init_destination) (cinfo);
  146037. jinit_compress_master(cinfo);
  146038. (*cinfo->master->prepare_for_pass) (cinfo);
  146039. cinfo->next_scanline = 0;
  146040. cinfo->global_state = (cinfo->raw_data_in ? CSTATE_RAW_OK : CSTATE_SCANNING);
  146041. }
  146042. GLOBAL(JDIMENSION)
  146043. jpeg_write_scanlines (j_compress_ptr cinfo, JSAMPARRAY scanlines,
  146044. JDIMENSION num_lines)
  146045. {
  146046. JDIMENSION row_ctr, rows_left;
  146047. if (cinfo->global_state != CSTATE_SCANNING)
  146048. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  146049. if (cinfo->next_scanline >= cinfo->image_height)
  146050. WARNMS(cinfo, JWRN_TOO_MUCH_DATA);
  146051. if (cinfo->progress != NULL) {
  146052. cinfo->progress->pass_counter = (long) cinfo->next_scanline;
  146053. cinfo->progress->pass_limit = (long) cinfo->image_height;
  146054. (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
  146055. }
  146056. if (cinfo->master->call_pass_startup)
  146057. (*cinfo->master->pass_startup) (cinfo);
  146058. rows_left = cinfo->image_height - cinfo->next_scanline;
  146059. if (num_lines > rows_left)
  146060. num_lines = rows_left;
  146061. row_ctr = 0;
  146062. (*cinfo->main->process_data) (cinfo, scanlines, &row_ctr, num_lines);
  146063. cinfo->next_scanline += row_ctr;
  146064. return row_ctr;
  146065. }
  146066. GLOBAL(JDIMENSION)
  146067. jpeg_write_raw_data (j_compress_ptr cinfo, JSAMPIMAGE data,
  146068. JDIMENSION num_lines)
  146069. {
  146070. JDIMENSION lines_per_iMCU_row;
  146071. if (cinfo->global_state != CSTATE_RAW_OK)
  146072. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  146073. if (cinfo->next_scanline >= cinfo->image_height) {
  146074. WARNMS(cinfo, JWRN_TOO_MUCH_DATA);
  146075. return 0;
  146076. }
  146077. if (cinfo->progress != NULL) {
  146078. cinfo->progress->pass_counter = (long) cinfo->next_scanline;
  146079. cinfo->progress->pass_limit = (long) cinfo->image_height;
  146080. (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
  146081. }
  146082. if (cinfo->master->call_pass_startup)
  146083. (*cinfo->master->pass_startup) (cinfo);
  146084. lines_per_iMCU_row = cinfo->max_v_samp_factor * DCTSIZE;
  146085. if (num_lines < lines_per_iMCU_row)
  146086. ERREXIT(cinfo, JERR_BUFFER_SIZE);
  146087. if (! (*cinfo->coef->compress_data) (cinfo, data)) {
  146088. return 0;
  146089. }
  146090. cinfo->next_scanline += lines_per_iMCU_row;
  146091. return lines_per_iMCU_row;
  146092. }
  146093. /*** End of inlined file: jcapistd.c ***/
  146094. /*** Start of inlined file: jccoefct.c ***/
  146095. #define JPEG_INTERNALS
  146096. #ifdef ENTROPY_OPT_SUPPORTED
  146097. #define FULL_COEF_BUFFER_SUPPORTED
  146098. #else
  146099. #ifdef C_MULTISCAN_FILES_SUPPORTED
  146100. #define FULL_COEF_BUFFER_SUPPORTED
  146101. #endif
  146102. #endif
  146103. typedef struct {
  146104. struct jpeg_c_coef_controller pub; /* public fields */
  146105. JDIMENSION iMCU_row_num; /* iMCU row # within image */
  146106. JDIMENSION mcu_ctr; /* counts MCUs processed in current row */
  146107. int MCU_vert_offset; /* counts MCU rows within iMCU row */
  146108. int MCU_rows_per_iMCU_row; /* number of such rows needed */
  146109. JBLOCKROW MCU_buffer[C_MAX_BLOCKS_IN_MCU];
  146110. jvirt_barray_ptr whole_image[MAX_COMPONENTS];
  146111. } my_coef_controller;
  146112. typedef my_coef_controller * my_coef_ptr;
  146113. METHODDEF(boolean) compress_data
  146114. JPP((j_compress_ptr cinfo, JSAMPIMAGE input_buf));
  146115. #ifdef FULL_COEF_BUFFER_SUPPORTED
  146116. METHODDEF(boolean) compress_first_pass
  146117. JPP((j_compress_ptr cinfo, JSAMPIMAGE input_buf));
  146118. METHODDEF(boolean) compress_output
  146119. JPP((j_compress_ptr cinfo, JSAMPIMAGE input_buf));
  146120. #endif
  146121. LOCAL(void)
  146122. start_iMCU_row (j_compress_ptr cinfo)
  146123. {
  146124. my_coef_ptr coef = (my_coef_ptr) cinfo->coef;
  146125. if (cinfo->comps_in_scan > 1) {
  146126. coef->MCU_rows_per_iMCU_row = 1;
  146127. } else {
  146128. if (coef->iMCU_row_num < (cinfo->total_iMCU_rows-1))
  146129. coef->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
  146130. else
  146131. coef->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
  146132. }
  146133. coef->mcu_ctr = 0;
  146134. coef->MCU_vert_offset = 0;
  146135. }
  146136. METHODDEF(void)
  146137. start_pass_coef (j_compress_ptr cinfo, J_BUF_MODE pass_mode)
  146138. {
  146139. my_coef_ptr coef = (my_coef_ptr) cinfo->coef;
  146140. coef->iMCU_row_num = 0;
  146141. start_iMCU_row(cinfo);
  146142. switch (pass_mode) {
  146143. case JBUF_PASS_THRU:
  146144. if (coef->whole_image[0] != NULL)
  146145. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  146146. coef->pub.compress_data = compress_data;
  146147. break;
  146148. #ifdef FULL_COEF_BUFFER_SUPPORTED
  146149. case JBUF_SAVE_AND_PASS:
  146150. if (coef->whole_image[0] == NULL)
  146151. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  146152. coef->pub.compress_data = compress_first_pass;
  146153. break;
  146154. case JBUF_CRANK_DEST:
  146155. if (coef->whole_image[0] == NULL)
  146156. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  146157. coef->pub.compress_data = compress_output;
  146158. break;
  146159. #endif
  146160. default:
  146161. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  146162. break;
  146163. }
  146164. }
  146165. METHODDEF(boolean)
  146166. compress_data (j_compress_ptr cinfo, JSAMPIMAGE input_buf)
  146167. {
  146168. my_coef_ptr coef = (my_coef_ptr) cinfo->coef;
  146169. JDIMENSION MCU_col_num; /* index of current MCU within row */
  146170. JDIMENSION last_MCU_col = cinfo->MCUs_per_row - 1;
  146171. JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
  146172. int blkn, bi, ci, yindex, yoffset, blockcnt;
  146173. JDIMENSION ypos, xpos;
  146174. jpeg_component_info *compptr;
  146175. for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
  146176. yoffset++) {
  146177. for (MCU_col_num = coef->mcu_ctr; MCU_col_num <= last_MCU_col;
  146178. MCU_col_num++) {
  146179. blkn = 0;
  146180. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  146181. compptr = cinfo->cur_comp_info[ci];
  146182. blockcnt = (MCU_col_num < last_MCU_col) ? compptr->MCU_width
  146183. : compptr->last_col_width;
  146184. xpos = MCU_col_num * compptr->MCU_sample_width;
  146185. ypos = yoffset * DCTSIZE; /* ypos == (yoffset+yindex) * DCTSIZE */
  146186. for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
  146187. if (coef->iMCU_row_num < last_iMCU_row ||
  146188. yoffset+yindex < compptr->last_row_height) {
  146189. (*cinfo->fdct->forward_DCT) (cinfo, compptr,
  146190. input_buf[compptr->component_index],
  146191. coef->MCU_buffer[blkn],
  146192. ypos, xpos, (JDIMENSION) blockcnt);
  146193. if (blockcnt < compptr->MCU_width) {
  146194. jzero_far((void FAR *) coef->MCU_buffer[blkn + blockcnt],
  146195. (compptr->MCU_width - blockcnt) * SIZEOF(JBLOCK));
  146196. for (bi = blockcnt; bi < compptr->MCU_width; bi++) {
  146197. coef->MCU_buffer[blkn+bi][0][0] = coef->MCU_buffer[blkn+bi-1][0][0];
  146198. }
  146199. }
  146200. } else {
  146201. jzero_far((void FAR *) coef->MCU_buffer[blkn],
  146202. compptr->MCU_width * SIZEOF(JBLOCK));
  146203. for (bi = 0; bi < compptr->MCU_width; bi++) {
  146204. coef->MCU_buffer[blkn+bi][0][0] = coef->MCU_buffer[blkn-1][0][0];
  146205. }
  146206. }
  146207. blkn += compptr->MCU_width;
  146208. ypos += DCTSIZE;
  146209. }
  146210. }
  146211. if (! (*cinfo->entropy->encode_mcu) (cinfo, coef->MCU_buffer)) {
  146212. coef->MCU_vert_offset = yoffset;
  146213. coef->mcu_ctr = MCU_col_num;
  146214. return FALSE;
  146215. }
  146216. }
  146217. coef->mcu_ctr = 0;
  146218. }
  146219. coef->iMCU_row_num++;
  146220. start_iMCU_row(cinfo);
  146221. return TRUE;
  146222. }
  146223. #ifdef FULL_COEF_BUFFER_SUPPORTED
  146224. METHODDEF(boolean)
  146225. compress_first_pass (j_compress_ptr cinfo, JSAMPIMAGE input_buf)
  146226. {
  146227. my_coef_ptr coef = (my_coef_ptr) cinfo->coef;
  146228. JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
  146229. JDIMENSION blocks_across, MCUs_across, MCUindex;
  146230. int bi, ci, h_samp_factor, block_row, block_rows, ndummy;
  146231. JCOEF lastDC;
  146232. jpeg_component_info *compptr;
  146233. JBLOCKARRAY buffer;
  146234. JBLOCKROW thisblockrow, lastblockrow;
  146235. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  146236. ci++, compptr++) {
  146237. buffer = (*cinfo->mem->access_virt_barray)
  146238. ((j_common_ptr) cinfo, coef->whole_image[ci],
  146239. coef->iMCU_row_num * compptr->v_samp_factor,
  146240. (JDIMENSION) compptr->v_samp_factor, TRUE);
  146241. if (coef->iMCU_row_num < last_iMCU_row)
  146242. block_rows = compptr->v_samp_factor;
  146243. else {
  146244. block_rows = (int) (compptr->height_in_blocks % compptr->v_samp_factor);
  146245. if (block_rows == 0) block_rows = compptr->v_samp_factor;
  146246. }
  146247. blocks_across = compptr->width_in_blocks;
  146248. h_samp_factor = compptr->h_samp_factor;
  146249. ndummy = (int) (blocks_across % h_samp_factor);
  146250. if (ndummy > 0)
  146251. ndummy = h_samp_factor - ndummy;
  146252. for (block_row = 0; block_row < block_rows; block_row++) {
  146253. thisblockrow = buffer[block_row];
  146254. (*cinfo->fdct->forward_DCT) (cinfo, compptr,
  146255. input_buf[ci], thisblockrow,
  146256. (JDIMENSION) (block_row * DCTSIZE),
  146257. (JDIMENSION) 0, blocks_across);
  146258. if (ndummy > 0) {
  146259. thisblockrow += blocks_across; /* => first dummy block */
  146260. jzero_far((void FAR *) thisblockrow, ndummy * SIZEOF(JBLOCK));
  146261. lastDC = thisblockrow[-1][0];
  146262. for (bi = 0; bi < ndummy; bi++) {
  146263. thisblockrow[bi][0] = lastDC;
  146264. }
  146265. }
  146266. }
  146267. if (coef->iMCU_row_num == last_iMCU_row) {
  146268. blocks_across += ndummy; /* include lower right corner */
  146269. MCUs_across = blocks_across / h_samp_factor;
  146270. for (block_row = block_rows; block_row < compptr->v_samp_factor;
  146271. block_row++) {
  146272. thisblockrow = buffer[block_row];
  146273. lastblockrow = buffer[block_row-1];
  146274. jzero_far((void FAR *) thisblockrow,
  146275. (size_t) (blocks_across * SIZEOF(JBLOCK)));
  146276. for (MCUindex = 0; MCUindex < MCUs_across; MCUindex++) {
  146277. lastDC = lastblockrow[h_samp_factor-1][0];
  146278. for (bi = 0; bi < h_samp_factor; bi++) {
  146279. thisblockrow[bi][0] = lastDC;
  146280. }
  146281. thisblockrow += h_samp_factor; /* advance to next MCU in row */
  146282. lastblockrow += h_samp_factor;
  146283. }
  146284. }
  146285. }
  146286. }
  146287. return compress_output(cinfo, input_buf);
  146288. }
  146289. METHODDEF(boolean)
  146290. compress_output (j_compress_ptr cinfo, JSAMPIMAGE input_buf)
  146291. {
  146292. my_coef_ptr coef = (my_coef_ptr) cinfo->coef;
  146293. JDIMENSION MCU_col_num; /* index of current MCU within row */
  146294. int blkn, ci, xindex, yindex, yoffset;
  146295. JDIMENSION start_col;
  146296. JBLOCKARRAY buffer[MAX_COMPS_IN_SCAN];
  146297. JBLOCKROW buffer_ptr;
  146298. jpeg_component_info *compptr;
  146299. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  146300. compptr = cinfo->cur_comp_info[ci];
  146301. buffer[ci] = (*cinfo->mem->access_virt_barray)
  146302. ((j_common_ptr) cinfo, coef->whole_image[compptr->component_index],
  146303. coef->iMCU_row_num * compptr->v_samp_factor,
  146304. (JDIMENSION) compptr->v_samp_factor, FALSE);
  146305. }
  146306. for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
  146307. yoffset++) {
  146308. for (MCU_col_num = coef->mcu_ctr; MCU_col_num < cinfo->MCUs_per_row;
  146309. MCU_col_num++) {
  146310. blkn = 0; /* index of current DCT block within MCU */
  146311. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  146312. compptr = cinfo->cur_comp_info[ci];
  146313. start_col = MCU_col_num * compptr->MCU_width;
  146314. for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
  146315. buffer_ptr = buffer[ci][yindex+yoffset] + start_col;
  146316. for (xindex = 0; xindex < compptr->MCU_width; xindex++) {
  146317. coef->MCU_buffer[blkn++] = buffer_ptr++;
  146318. }
  146319. }
  146320. }
  146321. if (! (*cinfo->entropy->encode_mcu) (cinfo, coef->MCU_buffer)) {
  146322. coef->MCU_vert_offset = yoffset;
  146323. coef->mcu_ctr = MCU_col_num;
  146324. return FALSE;
  146325. }
  146326. }
  146327. coef->mcu_ctr = 0;
  146328. }
  146329. coef->iMCU_row_num++;
  146330. start_iMCU_row(cinfo);
  146331. return TRUE;
  146332. }
  146333. #endif /* FULL_COEF_BUFFER_SUPPORTED */
  146334. GLOBAL(void)
  146335. jinit_c_coef_controller (j_compress_ptr cinfo, boolean need_full_buffer)
  146336. {
  146337. my_coef_ptr coef;
  146338. coef = (my_coef_ptr)
  146339. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  146340. SIZEOF(my_coef_controller));
  146341. cinfo->coef = (struct jpeg_c_coef_controller *) coef;
  146342. coef->pub.start_pass = start_pass_coef;
  146343. if (need_full_buffer) {
  146344. #ifdef FULL_COEF_BUFFER_SUPPORTED
  146345. int ci;
  146346. jpeg_component_info *compptr;
  146347. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  146348. ci++, compptr++) {
  146349. coef->whole_image[ci] = (*cinfo->mem->request_virt_barray)
  146350. ((j_common_ptr) cinfo, JPOOL_IMAGE, FALSE,
  146351. (JDIMENSION) jround_up((long) compptr->width_in_blocks,
  146352. (long) compptr->h_samp_factor),
  146353. (JDIMENSION) jround_up((long) compptr->height_in_blocks,
  146354. (long) compptr->v_samp_factor),
  146355. (JDIMENSION) compptr->v_samp_factor);
  146356. }
  146357. #else
  146358. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  146359. #endif
  146360. } else {
  146361. JBLOCKROW buffer;
  146362. int i;
  146363. buffer = (JBLOCKROW)
  146364. (*cinfo->mem->alloc_large) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  146365. C_MAX_BLOCKS_IN_MCU * SIZEOF(JBLOCK));
  146366. for (i = 0; i < C_MAX_BLOCKS_IN_MCU; i++) {
  146367. coef->MCU_buffer[i] = buffer + i;
  146368. }
  146369. coef->whole_image[0] = NULL; /* flag for no virtual arrays */
  146370. }
  146371. }
  146372. /*** End of inlined file: jccoefct.c ***/
  146373. /*** Start of inlined file: jccolor.c ***/
  146374. #define JPEG_INTERNALS
  146375. typedef struct {
  146376. struct jpeg_color_converter pub; /* public fields */
  146377. INT32 * rgb_ycc_tab; /* => table for RGB to YCbCr conversion */
  146378. } my_color_converter;
  146379. typedef my_color_converter * my_cconvert_ptr;
  146380. #define SCALEBITS 16 /* speediest right-shift on some machines */
  146381. #define CBCR_OFFSET ((INT32) CENTERJSAMPLE << SCALEBITS)
  146382. #define ONE_HALF ((INT32) 1 << (SCALEBITS-1))
  146383. #define FIX(x) ((INT32) ((x) * (1L<<SCALEBITS) + 0.5))
  146384. #define R_Y_OFF 0 /* offset to R => Y section */
  146385. #define G_Y_OFF (1*(MAXJSAMPLE+1)) /* offset to G => Y section */
  146386. #define B_Y_OFF (2*(MAXJSAMPLE+1)) /* etc. */
  146387. #define R_CB_OFF (3*(MAXJSAMPLE+1))
  146388. #define G_CB_OFF (4*(MAXJSAMPLE+1))
  146389. #define B_CB_OFF (5*(MAXJSAMPLE+1))
  146390. #define R_CR_OFF B_CB_OFF /* B=>Cb, R=>Cr are the same */
  146391. #define G_CR_OFF (6*(MAXJSAMPLE+1))
  146392. #define B_CR_OFF (7*(MAXJSAMPLE+1))
  146393. #define TABLE_SIZE (8*(MAXJSAMPLE+1))
  146394. METHODDEF(void)
  146395. rgb_ycc_start (j_compress_ptr cinfo)
  146396. {
  146397. my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert;
  146398. INT32 * rgb_ycc_tab;
  146399. INT32 i;
  146400. cconvert->rgb_ycc_tab = rgb_ycc_tab = (INT32 *)
  146401. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  146402. (TABLE_SIZE * SIZEOF(INT32)));
  146403. for (i = 0; i <= MAXJSAMPLE; i++) {
  146404. rgb_ycc_tab[i+R_Y_OFF] = FIX(0.29900) * i;
  146405. rgb_ycc_tab[i+G_Y_OFF] = FIX(0.58700) * i;
  146406. rgb_ycc_tab[i+B_Y_OFF] = FIX(0.11400) * i + ONE_HALF;
  146407. rgb_ycc_tab[i+R_CB_OFF] = (-FIX(0.16874)) * i;
  146408. rgb_ycc_tab[i+G_CB_OFF] = (-FIX(0.33126)) * i;
  146409. rgb_ycc_tab[i+B_CB_OFF] = FIX(0.50000) * i + CBCR_OFFSET + ONE_HALF-1;
  146410. rgb_ycc_tab[i+G_CR_OFF] = (-FIX(0.41869)) * i;
  146411. rgb_ycc_tab[i+B_CR_OFF] = (-FIX(0.08131)) * i;
  146412. }
  146413. }
  146414. METHODDEF(void)
  146415. rgb_ycc_convert (j_compress_ptr cinfo,
  146416. JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
  146417. JDIMENSION output_row, int num_rows)
  146418. {
  146419. my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert;
  146420. register int r, g, b;
  146421. register INT32 * ctab = cconvert->rgb_ycc_tab;
  146422. register JSAMPROW inptr;
  146423. register JSAMPROW outptr0, outptr1, outptr2;
  146424. register JDIMENSION col;
  146425. JDIMENSION num_cols = cinfo->image_width;
  146426. while (--num_rows >= 0) {
  146427. inptr = *input_buf++;
  146428. outptr0 = output_buf[0][output_row];
  146429. outptr1 = output_buf[1][output_row];
  146430. outptr2 = output_buf[2][output_row];
  146431. output_row++;
  146432. for (col = 0; col < num_cols; col++) {
  146433. r = GETJSAMPLE(inptr[RGB_RED]);
  146434. g = GETJSAMPLE(inptr[RGB_GREEN]);
  146435. b = GETJSAMPLE(inptr[RGB_BLUE]);
  146436. inptr += RGB_PIXELSIZE;
  146437. outptr0[col] = (JSAMPLE)
  146438. ((ctab[r+R_Y_OFF] + ctab[g+G_Y_OFF] + ctab[b+B_Y_OFF])
  146439. >> SCALEBITS);
  146440. outptr1[col] = (JSAMPLE)
  146441. ((ctab[r+R_CB_OFF] + ctab[g+G_CB_OFF] + ctab[b+B_CB_OFF])
  146442. >> SCALEBITS);
  146443. outptr2[col] = (JSAMPLE)
  146444. ((ctab[r+R_CR_OFF] + ctab[g+G_CR_OFF] + ctab[b+B_CR_OFF])
  146445. >> SCALEBITS);
  146446. }
  146447. }
  146448. }
  146449. METHODDEF(void)
  146450. rgb_gray_convert (j_compress_ptr cinfo,
  146451. JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
  146452. JDIMENSION output_row, int num_rows)
  146453. {
  146454. my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert;
  146455. register int r, g, b;
  146456. register INT32 * ctab = cconvert->rgb_ycc_tab;
  146457. register JSAMPROW inptr;
  146458. register JSAMPROW outptr;
  146459. register JDIMENSION col;
  146460. JDIMENSION num_cols = cinfo->image_width;
  146461. while (--num_rows >= 0) {
  146462. inptr = *input_buf++;
  146463. outptr = output_buf[0][output_row];
  146464. output_row++;
  146465. for (col = 0; col < num_cols; col++) {
  146466. r = GETJSAMPLE(inptr[RGB_RED]);
  146467. g = GETJSAMPLE(inptr[RGB_GREEN]);
  146468. b = GETJSAMPLE(inptr[RGB_BLUE]);
  146469. inptr += RGB_PIXELSIZE;
  146470. outptr[col] = (JSAMPLE)
  146471. ((ctab[r+R_Y_OFF] + ctab[g+G_Y_OFF] + ctab[b+B_Y_OFF])
  146472. >> SCALEBITS);
  146473. }
  146474. }
  146475. }
  146476. METHODDEF(void)
  146477. cmyk_ycck_convert (j_compress_ptr cinfo,
  146478. JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
  146479. JDIMENSION output_row, int num_rows)
  146480. {
  146481. my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert;
  146482. register int r, g, b;
  146483. register INT32 * ctab = cconvert->rgb_ycc_tab;
  146484. register JSAMPROW inptr;
  146485. register JSAMPROW outptr0, outptr1, outptr2, outptr3;
  146486. register JDIMENSION col;
  146487. JDIMENSION num_cols = cinfo->image_width;
  146488. while (--num_rows >= 0) {
  146489. inptr = *input_buf++;
  146490. outptr0 = output_buf[0][output_row];
  146491. outptr1 = output_buf[1][output_row];
  146492. outptr2 = output_buf[2][output_row];
  146493. outptr3 = output_buf[3][output_row];
  146494. output_row++;
  146495. for (col = 0; col < num_cols; col++) {
  146496. r = MAXJSAMPLE - GETJSAMPLE(inptr[0]);
  146497. g = MAXJSAMPLE - GETJSAMPLE(inptr[1]);
  146498. b = MAXJSAMPLE - GETJSAMPLE(inptr[2]);
  146499. outptr3[col] = inptr[3]; /* don't need GETJSAMPLE here */
  146500. inptr += 4;
  146501. outptr0[col] = (JSAMPLE)
  146502. ((ctab[r+R_Y_OFF] + ctab[g+G_Y_OFF] + ctab[b+B_Y_OFF])
  146503. >> SCALEBITS);
  146504. outptr1[col] = (JSAMPLE)
  146505. ((ctab[r+R_CB_OFF] + ctab[g+G_CB_OFF] + ctab[b+B_CB_OFF])
  146506. >> SCALEBITS);
  146507. outptr2[col] = (JSAMPLE)
  146508. ((ctab[r+R_CR_OFF] + ctab[g+G_CR_OFF] + ctab[b+B_CR_OFF])
  146509. >> SCALEBITS);
  146510. }
  146511. }
  146512. }
  146513. METHODDEF(void)
  146514. grayscale_convert (j_compress_ptr cinfo,
  146515. JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
  146516. JDIMENSION output_row, int num_rows)
  146517. {
  146518. register JSAMPROW inptr;
  146519. register JSAMPROW outptr;
  146520. register JDIMENSION col;
  146521. JDIMENSION num_cols = cinfo->image_width;
  146522. int instride = cinfo->input_components;
  146523. while (--num_rows >= 0) {
  146524. inptr = *input_buf++;
  146525. outptr = output_buf[0][output_row];
  146526. output_row++;
  146527. for (col = 0; col < num_cols; col++) {
  146528. outptr[col] = inptr[0]; /* don't need GETJSAMPLE() here */
  146529. inptr += instride;
  146530. }
  146531. }
  146532. }
  146533. METHODDEF(void)
  146534. null_convert (j_compress_ptr cinfo,
  146535. JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
  146536. JDIMENSION output_row, int num_rows)
  146537. {
  146538. register JSAMPROW inptr;
  146539. register JSAMPROW outptr;
  146540. register JDIMENSION col;
  146541. register int ci;
  146542. int nc = cinfo->num_components;
  146543. JDIMENSION num_cols = cinfo->image_width;
  146544. while (--num_rows >= 0) {
  146545. for (ci = 0; ci < nc; ci++) {
  146546. inptr = *input_buf;
  146547. outptr = output_buf[ci][output_row];
  146548. for (col = 0; col < num_cols; col++) {
  146549. outptr[col] = inptr[ci]; /* don't need GETJSAMPLE() here */
  146550. inptr += nc;
  146551. }
  146552. }
  146553. input_buf++;
  146554. output_row++;
  146555. }
  146556. }
  146557. METHODDEF(void)
  146558. null_method (j_compress_ptr cinfo)
  146559. {
  146560. }
  146561. GLOBAL(void)
  146562. jinit_color_converter (j_compress_ptr cinfo)
  146563. {
  146564. my_cconvert_ptr cconvert;
  146565. cconvert = (my_cconvert_ptr)
  146566. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  146567. SIZEOF(my_color_converter));
  146568. cinfo->cconvert = (struct jpeg_color_converter *) cconvert;
  146569. cconvert->pub.start_pass = null_method;
  146570. switch (cinfo->in_color_space) {
  146571. case JCS_GRAYSCALE:
  146572. if (cinfo->input_components != 1)
  146573. ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
  146574. break;
  146575. case JCS_RGB:
  146576. #if RGB_PIXELSIZE != 3
  146577. if (cinfo->input_components != RGB_PIXELSIZE)
  146578. ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
  146579. break;
  146580. #endif /* else share code with YCbCr */
  146581. case JCS_YCbCr:
  146582. if (cinfo->input_components != 3)
  146583. ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
  146584. break;
  146585. case JCS_CMYK:
  146586. case JCS_YCCK:
  146587. if (cinfo->input_components != 4)
  146588. ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
  146589. break;
  146590. default: /* JCS_UNKNOWN can be anything */
  146591. if (cinfo->input_components < 1)
  146592. ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
  146593. break;
  146594. }
  146595. switch (cinfo->jpeg_color_space) {
  146596. case JCS_GRAYSCALE:
  146597. if (cinfo->num_components != 1)
  146598. ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
  146599. if (cinfo->in_color_space == JCS_GRAYSCALE)
  146600. cconvert->pub.color_convert = grayscale_convert;
  146601. else if (cinfo->in_color_space == JCS_RGB) {
  146602. cconvert->pub.start_pass = rgb_ycc_start;
  146603. cconvert->pub.color_convert = rgb_gray_convert;
  146604. } else if (cinfo->in_color_space == JCS_YCbCr)
  146605. cconvert->pub.color_convert = grayscale_convert;
  146606. else
  146607. ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
  146608. break;
  146609. case JCS_RGB:
  146610. if (cinfo->num_components != 3)
  146611. ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
  146612. if (cinfo->in_color_space == JCS_RGB && RGB_PIXELSIZE == 3)
  146613. cconvert->pub.color_convert = null_convert;
  146614. else
  146615. ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
  146616. break;
  146617. case JCS_YCbCr:
  146618. if (cinfo->num_components != 3)
  146619. ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
  146620. if (cinfo->in_color_space == JCS_RGB) {
  146621. cconvert->pub.start_pass = rgb_ycc_start;
  146622. cconvert->pub.color_convert = rgb_ycc_convert;
  146623. } else if (cinfo->in_color_space == JCS_YCbCr)
  146624. cconvert->pub.color_convert = null_convert;
  146625. else
  146626. ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
  146627. break;
  146628. case JCS_CMYK:
  146629. if (cinfo->num_components != 4)
  146630. ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
  146631. if (cinfo->in_color_space == JCS_CMYK)
  146632. cconvert->pub.color_convert = null_convert;
  146633. else
  146634. ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
  146635. break;
  146636. case JCS_YCCK:
  146637. if (cinfo->num_components != 4)
  146638. ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
  146639. if (cinfo->in_color_space == JCS_CMYK) {
  146640. cconvert->pub.start_pass = rgb_ycc_start;
  146641. cconvert->pub.color_convert = cmyk_ycck_convert;
  146642. } else if (cinfo->in_color_space == JCS_YCCK)
  146643. cconvert->pub.color_convert = null_convert;
  146644. else
  146645. ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
  146646. break;
  146647. default: /* allow null conversion of JCS_UNKNOWN */
  146648. if (cinfo->jpeg_color_space != cinfo->in_color_space ||
  146649. cinfo->num_components != cinfo->input_components)
  146650. ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
  146651. cconvert->pub.color_convert = null_convert;
  146652. break;
  146653. }
  146654. }
  146655. /*** End of inlined file: jccolor.c ***/
  146656. #undef FIX
  146657. /*** Start of inlined file: jcdctmgr.c ***/
  146658. #define JPEG_INTERNALS
  146659. /*** Start of inlined file: jdct.h ***/
  146660. #ifndef __jdct_h__
  146661. #define __jdct_h__
  146662. #if BITS_IN_JSAMPLE == 8
  146663. typedef int DCTELEM; /* 16 or 32 bits is fine */
  146664. #else
  146665. typedef INT32 DCTELEM; /* must have 32 bits */
  146666. #endif
  146667. typedef JMETHOD(void, forward_DCT_method_ptr, (DCTELEM * data));
  146668. typedef JMETHOD(void, float_DCT_method_ptr, (FAST_FLOAT * data));
  146669. typedef MULTIPLIER ISLOW_MULT_TYPE; /* short or int, whichever is faster */
  146670. #if BITS_IN_JSAMPLE == 8
  146671. typedef MULTIPLIER IFAST_MULT_TYPE; /* 16 bits is OK, use short if faster */
  146672. #define IFAST_SCALE_BITS 2 /* fractional bits in scale factors */
  146673. #else
  146674. typedef INT32 IFAST_MULT_TYPE; /* need 32 bits for scaled quantizers */
  146675. #define IFAST_SCALE_BITS 13 /* fractional bits in scale factors */
  146676. #endif
  146677. typedef FAST_FLOAT FLOAT_MULT_TYPE; /* preferred floating type */
  146678. #define IDCT_range_limit(cinfo) ((cinfo)->sample_range_limit + CENTERJSAMPLE)
  146679. #define RANGE_MASK (MAXJSAMPLE * 4 + 3) /* 2 bits wider than legal samples */
  146680. #ifdef NEED_SHORT_EXTERNAL_NAMES
  146681. #define jpeg_fdct_islow jFDislow
  146682. #define jpeg_fdct_ifast jFDifast
  146683. #define jpeg_fdct_float jFDfloat
  146684. #define jpeg_idct_islow jRDislow
  146685. #define jpeg_idct_ifast jRDifast
  146686. #define jpeg_idct_float jRDfloat
  146687. #define jpeg_idct_4x4 jRD4x4
  146688. #define jpeg_idct_2x2 jRD2x2
  146689. #define jpeg_idct_1x1 jRD1x1
  146690. #endif /* NEED_SHORT_EXTERNAL_NAMES */
  146691. EXTERN(void) jpeg_fdct_islow JPP((DCTELEM * data));
  146692. EXTERN(void) jpeg_fdct_ifast JPP((DCTELEM * data));
  146693. EXTERN(void) jpeg_fdct_float JPP((FAST_FLOAT * data));
  146694. EXTERN(void) jpeg_idct_islow
  146695. JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
  146696. JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
  146697. EXTERN(void) jpeg_idct_ifast
  146698. JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
  146699. JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
  146700. EXTERN(void) jpeg_idct_float
  146701. JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
  146702. JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
  146703. EXTERN(void) jpeg_idct_4x4
  146704. JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
  146705. JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
  146706. EXTERN(void) jpeg_idct_2x2
  146707. JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
  146708. JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
  146709. EXTERN(void) jpeg_idct_1x1
  146710. JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
  146711. JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
  146712. #define ONE ((INT32) 1)
  146713. #define CONST_SCALE (ONE << CONST_BITS)
  146714. #define FIX(x) ((INT32) ((x) * CONST_SCALE + 0.5))
  146715. #define DESCALE(x,n) RIGHT_SHIFT((x) + (ONE << ((n)-1)), n)
  146716. #ifdef SHORTxSHORT_32 /* may work if 'int' is 32 bits */
  146717. #define MULTIPLY16C16(var,const) (((INT16) (var)) * ((INT16) (const)))
  146718. #endif
  146719. #ifdef SHORTxLCONST_32 /* known to work with Microsoft C 6.0 */
  146720. #define MULTIPLY16C16(var,const) (((INT16) (var)) * ((INT32) (const)))
  146721. #endif
  146722. #ifndef MULTIPLY16C16 /* default definition */
  146723. #define MULTIPLY16C16(var,const) ((var) * (const))
  146724. #endif
  146725. #ifdef SHORTxSHORT_32 /* may work if 'int' is 32 bits */
  146726. #define MULTIPLY16V16(var1,var2) (((INT16) (var1)) * ((INT16) (var2)))
  146727. #endif
  146728. #ifndef MULTIPLY16V16 /* default definition */
  146729. #define MULTIPLY16V16(var1,var2) ((var1) * (var2))
  146730. #endif
  146731. #endif
  146732. /*** End of inlined file: jdct.h ***/
  146733. /* Private declarations for DCT subsystem */
  146734. typedef struct {
  146735. struct jpeg_forward_dct pub; /* public fields */
  146736. forward_DCT_method_ptr do_dct;
  146737. DCTELEM * divisors[NUM_QUANT_TBLS];
  146738. #ifdef DCT_FLOAT_SUPPORTED
  146739. float_DCT_method_ptr do_float_dct;
  146740. FAST_FLOAT * float_divisors[NUM_QUANT_TBLS];
  146741. #endif
  146742. } my_fdct_controller;
  146743. typedef my_fdct_controller * my_fdct_ptr;
  146744. METHODDEF(void)
  146745. start_pass_fdctmgr (j_compress_ptr cinfo)
  146746. {
  146747. my_fdct_ptr fdct = (my_fdct_ptr) cinfo->fdct;
  146748. int ci, qtblno, i;
  146749. jpeg_component_info *compptr;
  146750. JQUANT_TBL * qtbl;
  146751. DCTELEM * dtbl;
  146752. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  146753. ci++, compptr++) {
  146754. qtblno = compptr->quant_tbl_no;
  146755. if (qtblno < 0 || qtblno >= NUM_QUANT_TBLS ||
  146756. cinfo->quant_tbl_ptrs[qtblno] == NULL)
  146757. ERREXIT1(cinfo, JERR_NO_QUANT_TABLE, qtblno);
  146758. qtbl = cinfo->quant_tbl_ptrs[qtblno];
  146759. switch (cinfo->dct_method) {
  146760. #ifdef DCT_ISLOW_SUPPORTED
  146761. case JDCT_ISLOW:
  146762. if (fdct->divisors[qtblno] == NULL) {
  146763. fdct->divisors[qtblno] = (DCTELEM *)
  146764. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  146765. DCTSIZE2 * SIZEOF(DCTELEM));
  146766. }
  146767. dtbl = fdct->divisors[qtblno];
  146768. for (i = 0; i < DCTSIZE2; i++) {
  146769. dtbl[i] = ((DCTELEM) qtbl->quantval[i]) << 3;
  146770. }
  146771. break;
  146772. #endif
  146773. #ifdef DCT_IFAST_SUPPORTED
  146774. case JDCT_IFAST:
  146775. {
  146776. #define CONST_BITS 14
  146777. static const INT16 aanscales[DCTSIZE2] = {
  146778. 16384, 22725, 21407, 19266, 16384, 12873, 8867, 4520,
  146779. 22725, 31521, 29692, 26722, 22725, 17855, 12299, 6270,
  146780. 21407, 29692, 27969, 25172, 21407, 16819, 11585, 5906,
  146781. 19266, 26722, 25172, 22654, 19266, 15137, 10426, 5315,
  146782. 16384, 22725, 21407, 19266, 16384, 12873, 8867, 4520,
  146783. 12873, 17855, 16819, 15137, 12873, 10114, 6967, 3552,
  146784. 8867, 12299, 11585, 10426, 8867, 6967, 4799, 2446,
  146785. 4520, 6270, 5906, 5315, 4520, 3552, 2446, 1247
  146786. };
  146787. SHIFT_TEMPS
  146788. if (fdct->divisors[qtblno] == NULL) {
  146789. fdct->divisors[qtblno] = (DCTELEM *)
  146790. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  146791. DCTSIZE2 * SIZEOF(DCTELEM));
  146792. }
  146793. dtbl = fdct->divisors[qtblno];
  146794. for (i = 0; i < DCTSIZE2; i++) {
  146795. dtbl[i] = (DCTELEM)
  146796. DESCALE(MULTIPLY16V16((INT32) qtbl->quantval[i],
  146797. (INT32) aanscales[i]),
  146798. CONST_BITS-3);
  146799. }
  146800. }
  146801. break;
  146802. #endif
  146803. #ifdef DCT_FLOAT_SUPPORTED
  146804. case JDCT_FLOAT:
  146805. {
  146806. FAST_FLOAT * fdtbl;
  146807. int row, col;
  146808. static const double aanscalefactor[DCTSIZE] = {
  146809. 1.0, 1.387039845, 1.306562965, 1.175875602,
  146810. 1.0, 0.785694958, 0.541196100, 0.275899379
  146811. };
  146812. if (fdct->float_divisors[qtblno] == NULL) {
  146813. fdct->float_divisors[qtblno] = (FAST_FLOAT *)
  146814. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  146815. DCTSIZE2 * SIZEOF(FAST_FLOAT));
  146816. }
  146817. fdtbl = fdct->float_divisors[qtblno];
  146818. i = 0;
  146819. for (row = 0; row < DCTSIZE; row++) {
  146820. for (col = 0; col < DCTSIZE; col++) {
  146821. fdtbl[i] = (FAST_FLOAT)
  146822. (1.0 / (((double) qtbl->quantval[i] *
  146823. aanscalefactor[row] * aanscalefactor[col] * 8.0)));
  146824. i++;
  146825. }
  146826. }
  146827. }
  146828. break;
  146829. #endif
  146830. default:
  146831. ERREXIT(cinfo, JERR_NOT_COMPILED);
  146832. break;
  146833. }
  146834. }
  146835. }
  146836. METHODDEF(void)
  146837. forward_DCT (j_compress_ptr cinfo, jpeg_component_info * compptr,
  146838. JSAMPARRAY sample_data, JBLOCKROW coef_blocks,
  146839. JDIMENSION start_row, JDIMENSION start_col,
  146840. JDIMENSION num_blocks)
  146841. {
  146842. my_fdct_ptr fdct = (my_fdct_ptr) cinfo->fdct;
  146843. forward_DCT_method_ptr do_dct = fdct->do_dct;
  146844. DCTELEM * divisors = fdct->divisors[compptr->quant_tbl_no];
  146845. DCTELEM workspace[DCTSIZE2]; /* work area for FDCT subroutine */
  146846. JDIMENSION bi;
  146847. sample_data += start_row; /* fold in the vertical offset once */
  146848. for (bi = 0; bi < num_blocks; bi++, start_col += DCTSIZE) {
  146849. { register DCTELEM *workspaceptr;
  146850. register JSAMPROW elemptr;
  146851. register int elemr;
  146852. workspaceptr = workspace;
  146853. for (elemr = 0; elemr < DCTSIZE; elemr++) {
  146854. elemptr = sample_data[elemr] + start_col;
  146855. #if DCTSIZE == 8 /* unroll the inner loop */
  146856. *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
  146857. *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
  146858. *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
  146859. *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
  146860. *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
  146861. *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
  146862. *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
  146863. *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
  146864. #else
  146865. { register int elemc;
  146866. for (elemc = DCTSIZE; elemc > 0; elemc--) {
  146867. *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
  146868. }
  146869. }
  146870. #endif
  146871. }
  146872. }
  146873. (*do_dct) (workspace);
  146874. { register DCTELEM temp, qval;
  146875. register int i;
  146876. register JCOEFPTR output_ptr = coef_blocks[bi];
  146877. for (i = 0; i < DCTSIZE2; i++) {
  146878. qval = divisors[i];
  146879. temp = workspace[i];
  146880. #ifdef FAST_DIVIDE
  146881. #define DIVIDE_BY(a,b) a /= b
  146882. #else
  146883. #define DIVIDE_BY(a,b) if (a >= b) a /= b; else a = 0
  146884. #endif
  146885. if (temp < 0) {
  146886. temp = -temp;
  146887. temp += qval>>1; /* for rounding */
  146888. DIVIDE_BY(temp, qval);
  146889. temp = -temp;
  146890. } else {
  146891. temp += qval>>1; /* for rounding */
  146892. DIVIDE_BY(temp, qval);
  146893. }
  146894. output_ptr[i] = (JCOEF) temp;
  146895. }
  146896. }
  146897. }
  146898. }
  146899. #ifdef DCT_FLOAT_SUPPORTED
  146900. METHODDEF(void)
  146901. forward_DCT_float (j_compress_ptr cinfo, jpeg_component_info * compptr,
  146902. JSAMPARRAY sample_data, JBLOCKROW coef_blocks,
  146903. JDIMENSION start_row, JDIMENSION start_col,
  146904. JDIMENSION num_blocks)
  146905. {
  146906. my_fdct_ptr fdct = (my_fdct_ptr) cinfo->fdct;
  146907. float_DCT_method_ptr do_dct = fdct->do_float_dct;
  146908. FAST_FLOAT * divisors = fdct->float_divisors[compptr->quant_tbl_no];
  146909. FAST_FLOAT workspace[DCTSIZE2]; /* work area for FDCT subroutine */
  146910. JDIMENSION bi;
  146911. sample_data += start_row; /* fold in the vertical offset once */
  146912. for (bi = 0; bi < num_blocks; bi++, start_col += DCTSIZE) {
  146913. { register FAST_FLOAT *workspaceptr;
  146914. register JSAMPROW elemptr;
  146915. register int elemr;
  146916. workspaceptr = workspace;
  146917. for (elemr = 0; elemr < DCTSIZE; elemr++) {
  146918. elemptr = sample_data[elemr] + start_col;
  146919. #if DCTSIZE == 8 /* unroll the inner loop */
  146920. *workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
  146921. *workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
  146922. *workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
  146923. *workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
  146924. *workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
  146925. *workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
  146926. *workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
  146927. *workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
  146928. #else
  146929. { register int elemc;
  146930. for (elemc = DCTSIZE; elemc > 0; elemc--) {
  146931. *workspaceptr++ = (FAST_FLOAT)
  146932. (GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
  146933. }
  146934. }
  146935. #endif
  146936. }
  146937. }
  146938. (*do_dct) (workspace);
  146939. { register FAST_FLOAT temp;
  146940. register int i;
  146941. register JCOEFPTR output_ptr = coef_blocks[bi];
  146942. for (i = 0; i < DCTSIZE2; i++) {
  146943. temp = workspace[i] * divisors[i];
  146944. output_ptr[i] = (JCOEF) ((int) (temp + (FAST_FLOAT) 16384.5) - 16384);
  146945. }
  146946. }
  146947. }
  146948. }
  146949. #endif /* DCT_FLOAT_SUPPORTED */
  146950. GLOBAL(void)
  146951. jinit_forward_dct (j_compress_ptr cinfo)
  146952. {
  146953. my_fdct_ptr fdct;
  146954. int i;
  146955. fdct = (my_fdct_ptr)
  146956. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  146957. SIZEOF(my_fdct_controller));
  146958. cinfo->fdct = (struct jpeg_forward_dct *) fdct;
  146959. fdct->pub.start_pass = start_pass_fdctmgr;
  146960. switch (cinfo->dct_method) {
  146961. #ifdef DCT_ISLOW_SUPPORTED
  146962. case JDCT_ISLOW:
  146963. fdct->pub.forward_DCT = forward_DCT;
  146964. fdct->do_dct = jpeg_fdct_islow;
  146965. break;
  146966. #endif
  146967. #ifdef DCT_IFAST_SUPPORTED
  146968. case JDCT_IFAST:
  146969. fdct->pub.forward_DCT = forward_DCT;
  146970. fdct->do_dct = jpeg_fdct_ifast;
  146971. break;
  146972. #endif
  146973. #ifdef DCT_FLOAT_SUPPORTED
  146974. case JDCT_FLOAT:
  146975. fdct->pub.forward_DCT = forward_DCT_float;
  146976. fdct->do_float_dct = jpeg_fdct_float;
  146977. break;
  146978. #endif
  146979. default:
  146980. ERREXIT(cinfo, JERR_NOT_COMPILED);
  146981. break;
  146982. }
  146983. for (i = 0; i < NUM_QUANT_TBLS; i++) {
  146984. fdct->divisors[i] = NULL;
  146985. #ifdef DCT_FLOAT_SUPPORTED
  146986. fdct->float_divisors[i] = NULL;
  146987. #endif
  146988. }
  146989. }
  146990. /*** End of inlined file: jcdctmgr.c ***/
  146991. #undef CONST_BITS
  146992. /*** Start of inlined file: jchuff.c ***/
  146993. #define JPEG_INTERNALS
  146994. /*** Start of inlined file: jchuff.h ***/
  146995. #ifndef _jchuff_h_
  146996. #define _jchuff_h_
  146997. #if BITS_IN_JSAMPLE == 8
  146998. #define MAX_COEF_BITS 10
  146999. #else
  147000. #define MAX_COEF_BITS 14
  147001. #endif
  147002. typedef struct {
  147003. unsigned int ehufco[256]; /* code for each symbol */
  147004. char ehufsi[256]; /* length of code for each symbol */
  147005. } c_derived_tbl;
  147006. #ifdef NEED_SHORT_EXTERNAL_NAMES
  147007. #define jpeg_make_c_derived_tbl jMkCDerived
  147008. #define jpeg_gen_optimal_table jGenOptTbl
  147009. #endif /* NEED_SHORT_EXTERNAL_NAMES */
  147010. EXTERN(void) jpeg_make_c_derived_tbl
  147011. JPP((j_compress_ptr cinfo, boolean isDC, int tblno,
  147012. c_derived_tbl ** pdtbl));
  147013. EXTERN(void) jpeg_gen_optimal_table
  147014. JPP((j_compress_ptr cinfo, JHUFF_TBL * htbl, long freq[]));
  147015. #endif
  147016. /*** End of inlined file: jchuff.h ***/
  147017. /* Declarations shared with jcphuff.c */
  147018. typedef struct {
  147019. INT32 put_buffer; /* current bit-accumulation buffer */
  147020. int put_bits; /* # of bits now in it */
  147021. int last_dc_val[MAX_COMPS_IN_SCAN]; /* last DC coef for each component */
  147022. } savable_state;
  147023. #ifndef NO_STRUCT_ASSIGN
  147024. #define ASSIGN_STATE(dest,src) ((dest) = (src))
  147025. #else
  147026. #if MAX_COMPS_IN_SCAN == 4
  147027. #define ASSIGN_STATE(dest,src) \
  147028. ((dest).put_buffer = (src).put_buffer, \
  147029. (dest).put_bits = (src).put_bits, \
  147030. (dest).last_dc_val[0] = (src).last_dc_val[0], \
  147031. (dest).last_dc_val[1] = (src).last_dc_val[1], \
  147032. (dest).last_dc_val[2] = (src).last_dc_val[2], \
  147033. (dest).last_dc_val[3] = (src).last_dc_val[3])
  147034. #endif
  147035. #endif
  147036. typedef struct {
  147037. struct jpeg_entropy_encoder pub; /* public fields */
  147038. savable_state saved; /* Bit buffer & DC state at start of MCU */
  147039. unsigned int restarts_to_go; /* MCUs left in this restart interval */
  147040. int next_restart_num; /* next restart number to write (0-7) */
  147041. c_derived_tbl * dc_derived_tbls[NUM_HUFF_TBLS];
  147042. c_derived_tbl * ac_derived_tbls[NUM_HUFF_TBLS];
  147043. #ifdef ENTROPY_OPT_SUPPORTED /* Statistics tables for optimization */
  147044. long * dc_count_ptrs[NUM_HUFF_TBLS];
  147045. long * ac_count_ptrs[NUM_HUFF_TBLS];
  147046. #endif
  147047. } huff_entropy_encoder;
  147048. typedef huff_entropy_encoder * huff_entropy_ptr;
  147049. typedef struct {
  147050. JOCTET * next_output_byte; /* => next byte to write in buffer */
  147051. size_t free_in_buffer; /* # of byte spaces remaining in buffer */
  147052. savable_state cur; /* Current bit buffer & DC state */
  147053. j_compress_ptr cinfo; /* dump_buffer needs access to this */
  147054. } working_state;
  147055. METHODDEF(boolean) encode_mcu_huff JPP((j_compress_ptr cinfo,
  147056. JBLOCKROW *MCU_data));
  147057. METHODDEF(void) finish_pass_huff JPP((j_compress_ptr cinfo));
  147058. #ifdef ENTROPY_OPT_SUPPORTED
  147059. METHODDEF(boolean) encode_mcu_gather JPP((j_compress_ptr cinfo,
  147060. JBLOCKROW *MCU_data));
  147061. METHODDEF(void) finish_pass_gather JPP((j_compress_ptr cinfo));
  147062. #endif
  147063. METHODDEF(void)
  147064. start_pass_huff (j_compress_ptr cinfo, boolean gather_statistics)
  147065. {
  147066. huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy;
  147067. int ci, dctbl, actbl;
  147068. jpeg_component_info * compptr;
  147069. if (gather_statistics) {
  147070. #ifdef ENTROPY_OPT_SUPPORTED
  147071. entropy->pub.encode_mcu = encode_mcu_gather;
  147072. entropy->pub.finish_pass = finish_pass_gather;
  147073. #else
  147074. ERREXIT(cinfo, JERR_NOT_COMPILED);
  147075. #endif
  147076. } else {
  147077. entropy->pub.encode_mcu = encode_mcu_huff;
  147078. entropy->pub.finish_pass = finish_pass_huff;
  147079. }
  147080. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  147081. compptr = cinfo->cur_comp_info[ci];
  147082. dctbl = compptr->dc_tbl_no;
  147083. actbl = compptr->ac_tbl_no;
  147084. if (gather_statistics) {
  147085. #ifdef ENTROPY_OPT_SUPPORTED
  147086. if (dctbl < 0 || dctbl >= NUM_HUFF_TBLS)
  147087. ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, dctbl);
  147088. if (actbl < 0 || actbl >= NUM_HUFF_TBLS)
  147089. ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, actbl);
  147090. if (entropy->dc_count_ptrs[dctbl] == NULL)
  147091. entropy->dc_count_ptrs[dctbl] = (long *)
  147092. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  147093. 257 * SIZEOF(long));
  147094. MEMZERO(entropy->dc_count_ptrs[dctbl], 257 * SIZEOF(long));
  147095. if (entropy->ac_count_ptrs[actbl] == NULL)
  147096. entropy->ac_count_ptrs[actbl] = (long *)
  147097. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  147098. 257 * SIZEOF(long));
  147099. MEMZERO(entropy->ac_count_ptrs[actbl], 257 * SIZEOF(long));
  147100. #endif
  147101. } else {
  147102. jpeg_make_c_derived_tbl(cinfo, TRUE, dctbl,
  147103. & entropy->dc_derived_tbls[dctbl]);
  147104. jpeg_make_c_derived_tbl(cinfo, FALSE, actbl,
  147105. & entropy->ac_derived_tbls[actbl]);
  147106. }
  147107. entropy->saved.last_dc_val[ci] = 0;
  147108. }
  147109. entropy->saved.put_buffer = 0;
  147110. entropy->saved.put_bits = 0;
  147111. entropy->restarts_to_go = cinfo->restart_interval;
  147112. entropy->next_restart_num = 0;
  147113. }
  147114. GLOBAL(void)
  147115. jpeg_make_c_derived_tbl (j_compress_ptr cinfo, boolean isDC, int tblno,
  147116. c_derived_tbl ** pdtbl)
  147117. {
  147118. JHUFF_TBL *htbl;
  147119. c_derived_tbl *dtbl;
  147120. int p, i, l, lastp, si, maxsymbol;
  147121. char huffsize[257];
  147122. unsigned int huffcode[257];
  147123. unsigned int code;
  147124. if (tblno < 0 || tblno >= NUM_HUFF_TBLS)
  147125. ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, tblno);
  147126. htbl =
  147127. isDC ? cinfo->dc_huff_tbl_ptrs[tblno] : cinfo->ac_huff_tbl_ptrs[tblno];
  147128. if (htbl == NULL)
  147129. ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, tblno);
  147130. if (*pdtbl == NULL)
  147131. *pdtbl = (c_derived_tbl *)
  147132. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  147133. SIZEOF(c_derived_tbl));
  147134. dtbl = *pdtbl;
  147135. p = 0;
  147136. for (l = 1; l <= 16; l++) {
  147137. i = (int) htbl->bits[l];
  147138. if (i < 0 || p + i > 256) /* protect against table overrun */
  147139. ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
  147140. while (i--)
  147141. huffsize[p++] = (char) l;
  147142. }
  147143. huffsize[p] = 0;
  147144. lastp = p;
  147145. code = 0;
  147146. si = huffsize[0];
  147147. p = 0;
  147148. while (huffsize[p]) {
  147149. while (((int) huffsize[p]) == si) {
  147150. huffcode[p++] = code;
  147151. code++;
  147152. }
  147153. if (((INT32) code) >= (((INT32) 1) << si))
  147154. ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
  147155. code <<= 1;
  147156. si++;
  147157. }
  147158. MEMZERO(dtbl->ehufsi, SIZEOF(dtbl->ehufsi));
  147159. maxsymbol = isDC ? 15 : 255;
  147160. for (p = 0; p < lastp; p++) {
  147161. i = htbl->huffval[p];
  147162. if (i < 0 || i > maxsymbol || dtbl->ehufsi[i])
  147163. ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
  147164. dtbl->ehufco[i] = huffcode[p];
  147165. dtbl->ehufsi[i] = huffsize[p];
  147166. }
  147167. }
  147168. #define emit_byte(state,val,action) \
  147169. { *(state)->next_output_byte++ = (JOCTET) (val); \
  147170. if (--(state)->free_in_buffer == 0) \
  147171. if (! dump_buffer(state)) \
  147172. { action; } }
  147173. LOCAL(boolean)
  147174. dump_buffer (working_state * state)
  147175. {
  147176. struct jpeg_destination_mgr * dest = state->cinfo->dest;
  147177. if (! (*dest->empty_output_buffer) (state->cinfo))
  147178. return FALSE;
  147179. state->next_output_byte = dest->next_output_byte;
  147180. state->free_in_buffer = dest->free_in_buffer;
  147181. return TRUE;
  147182. }
  147183. INLINE
  147184. LOCAL(boolean)
  147185. emit_bits (working_state * state, unsigned int code, int size)
  147186. {
  147187. register INT32 put_buffer = (INT32) code;
  147188. register int put_bits = state->cur.put_bits;
  147189. if (size == 0)
  147190. ERREXIT(state->cinfo, JERR_HUFF_MISSING_CODE);
  147191. put_buffer &= (((INT32) 1)<<size) - 1; /* mask off any extra bits in code */
  147192. put_bits += size; /* new number of bits in buffer */
  147193. put_buffer <<= 24 - put_bits; /* align incoming bits */
  147194. put_buffer |= state->cur.put_buffer; /* and merge with old buffer contents */
  147195. while (put_bits >= 8) {
  147196. int c = (int) ((put_buffer >> 16) & 0xFF);
  147197. emit_byte(state, c, return FALSE);
  147198. if (c == 0xFF) { /* need to stuff a zero byte? */
  147199. emit_byte(state, 0, return FALSE);
  147200. }
  147201. put_buffer <<= 8;
  147202. put_bits -= 8;
  147203. }
  147204. state->cur.put_buffer = put_buffer; /* update state variables */
  147205. state->cur.put_bits = put_bits;
  147206. return TRUE;
  147207. }
  147208. LOCAL(boolean)
  147209. flush_bits (working_state * state)
  147210. {
  147211. if (! emit_bits(state, 0x7F, 7)) /* fill any partial byte with ones */
  147212. return FALSE;
  147213. state->cur.put_buffer = 0; /* and reset bit-buffer to empty */
  147214. state->cur.put_bits = 0;
  147215. return TRUE;
  147216. }
  147217. LOCAL(boolean)
  147218. encode_one_block (working_state * state, JCOEFPTR block, int last_dc_val,
  147219. c_derived_tbl *dctbl, c_derived_tbl *actbl)
  147220. {
  147221. register int temp, temp2;
  147222. register int nbits;
  147223. register int k, r, i;
  147224. temp = temp2 = block[0] - last_dc_val;
  147225. if (temp < 0) {
  147226. temp = -temp; /* temp is abs value of input */
  147227. temp2--;
  147228. }
  147229. nbits = 0;
  147230. while (temp) {
  147231. nbits++;
  147232. temp >>= 1;
  147233. }
  147234. if (nbits > MAX_COEF_BITS+1)
  147235. ERREXIT(state->cinfo, JERR_BAD_DCT_COEF);
  147236. if (! emit_bits(state, dctbl->ehufco[nbits], dctbl->ehufsi[nbits]))
  147237. return FALSE;
  147238. if (nbits) /* emit_bits rejects calls with size 0 */
  147239. if (! emit_bits(state, (unsigned int) temp2, nbits))
  147240. return FALSE;
  147241. r = 0; /* r = run length of zeros */
  147242. for (k = 1; k < DCTSIZE2; k++) {
  147243. if ((temp = block[jpeg_natural_order[k]]) == 0) {
  147244. r++;
  147245. } else {
  147246. while (r > 15) {
  147247. if (! emit_bits(state, actbl->ehufco[0xF0], actbl->ehufsi[0xF0]))
  147248. return FALSE;
  147249. r -= 16;
  147250. }
  147251. temp2 = temp;
  147252. if (temp < 0) {
  147253. temp = -temp; /* temp is abs value of input */
  147254. temp2--;
  147255. }
  147256. nbits = 1; /* there must be at least one 1 bit */
  147257. while ((temp >>= 1))
  147258. nbits++;
  147259. if (nbits > MAX_COEF_BITS)
  147260. ERREXIT(state->cinfo, JERR_BAD_DCT_COEF);
  147261. i = (r << 4) + nbits;
  147262. if (! emit_bits(state, actbl->ehufco[i], actbl->ehufsi[i]))
  147263. return FALSE;
  147264. if (! emit_bits(state, (unsigned int) temp2, nbits))
  147265. return FALSE;
  147266. r = 0;
  147267. }
  147268. }
  147269. if (r > 0)
  147270. if (! emit_bits(state, actbl->ehufco[0], actbl->ehufsi[0]))
  147271. return FALSE;
  147272. return TRUE;
  147273. }
  147274. LOCAL(boolean)
  147275. emit_restart (working_state * state, int restart_num)
  147276. {
  147277. int ci;
  147278. if (! flush_bits(state))
  147279. return FALSE;
  147280. emit_byte(state, 0xFF, return FALSE);
  147281. emit_byte(state, JPEG_RST0 + restart_num, return FALSE);
  147282. for (ci = 0; ci < state->cinfo->comps_in_scan; ci++)
  147283. state->cur.last_dc_val[ci] = 0;
  147284. return TRUE;
  147285. }
  147286. METHODDEF(boolean)
  147287. encode_mcu_huff (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
  147288. {
  147289. huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy;
  147290. working_state state;
  147291. int blkn, ci;
  147292. jpeg_component_info * compptr;
  147293. state.next_output_byte = cinfo->dest->next_output_byte;
  147294. state.free_in_buffer = cinfo->dest->free_in_buffer;
  147295. ASSIGN_STATE(state.cur, entropy->saved);
  147296. state.cinfo = cinfo;
  147297. if (cinfo->restart_interval) {
  147298. if (entropy->restarts_to_go == 0)
  147299. if (! emit_restart(&state, entropy->next_restart_num))
  147300. return FALSE;
  147301. }
  147302. for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
  147303. ci = cinfo->MCU_membership[blkn];
  147304. compptr = cinfo->cur_comp_info[ci];
  147305. if (! encode_one_block(&state,
  147306. MCU_data[blkn][0], state.cur.last_dc_val[ci],
  147307. entropy->dc_derived_tbls[compptr->dc_tbl_no],
  147308. entropy->ac_derived_tbls[compptr->ac_tbl_no]))
  147309. return FALSE;
  147310. state.cur.last_dc_val[ci] = MCU_data[blkn][0][0];
  147311. }
  147312. cinfo->dest->next_output_byte = state.next_output_byte;
  147313. cinfo->dest->free_in_buffer = state.free_in_buffer;
  147314. ASSIGN_STATE(entropy->saved, state.cur);
  147315. if (cinfo->restart_interval) {
  147316. if (entropy->restarts_to_go == 0) {
  147317. entropy->restarts_to_go = cinfo->restart_interval;
  147318. entropy->next_restart_num++;
  147319. entropy->next_restart_num &= 7;
  147320. }
  147321. entropy->restarts_to_go--;
  147322. }
  147323. return TRUE;
  147324. }
  147325. METHODDEF(void)
  147326. finish_pass_huff (j_compress_ptr cinfo)
  147327. {
  147328. huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy;
  147329. working_state state;
  147330. state.next_output_byte = cinfo->dest->next_output_byte;
  147331. state.free_in_buffer = cinfo->dest->free_in_buffer;
  147332. ASSIGN_STATE(state.cur, entropy->saved);
  147333. state.cinfo = cinfo;
  147334. if (! flush_bits(&state))
  147335. ERREXIT(cinfo, JERR_CANT_SUSPEND);
  147336. cinfo->dest->next_output_byte = state.next_output_byte;
  147337. cinfo->dest->free_in_buffer = state.free_in_buffer;
  147338. ASSIGN_STATE(entropy->saved, state.cur);
  147339. }
  147340. #ifdef ENTROPY_OPT_SUPPORTED
  147341. LOCAL(void)
  147342. htest_one_block (j_compress_ptr cinfo, JCOEFPTR block, int last_dc_val,
  147343. long dc_counts[], long ac_counts[])
  147344. {
  147345. register int temp;
  147346. register int nbits;
  147347. register int k, r;
  147348. temp = block[0] - last_dc_val;
  147349. if (temp < 0)
  147350. temp = -temp;
  147351. nbits = 0;
  147352. while (temp) {
  147353. nbits++;
  147354. temp >>= 1;
  147355. }
  147356. if (nbits > MAX_COEF_BITS+1)
  147357. ERREXIT(cinfo, JERR_BAD_DCT_COEF);
  147358. dc_counts[nbits]++;
  147359. r = 0; /* r = run length of zeros */
  147360. for (k = 1; k < DCTSIZE2; k++) {
  147361. if ((temp = block[jpeg_natural_order[k]]) == 0) {
  147362. r++;
  147363. } else {
  147364. while (r > 15) {
  147365. ac_counts[0xF0]++;
  147366. r -= 16;
  147367. }
  147368. if (temp < 0)
  147369. temp = -temp;
  147370. nbits = 1; /* there must be at least one 1 bit */
  147371. while ((temp >>= 1))
  147372. nbits++;
  147373. if (nbits > MAX_COEF_BITS)
  147374. ERREXIT(cinfo, JERR_BAD_DCT_COEF);
  147375. ac_counts[(r << 4) + nbits]++;
  147376. r = 0;
  147377. }
  147378. }
  147379. if (r > 0)
  147380. ac_counts[0]++;
  147381. }
  147382. METHODDEF(boolean)
  147383. encode_mcu_gather (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
  147384. {
  147385. huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy;
  147386. int blkn, ci;
  147387. jpeg_component_info * compptr;
  147388. if (cinfo->restart_interval) {
  147389. if (entropy->restarts_to_go == 0) {
  147390. for (ci = 0; ci < cinfo->comps_in_scan; ci++)
  147391. entropy->saved.last_dc_val[ci] = 0;
  147392. entropy->restarts_to_go = cinfo->restart_interval;
  147393. }
  147394. entropy->restarts_to_go--;
  147395. }
  147396. for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
  147397. ci = cinfo->MCU_membership[blkn];
  147398. compptr = cinfo->cur_comp_info[ci];
  147399. htest_one_block(cinfo, MCU_data[blkn][0], entropy->saved.last_dc_val[ci],
  147400. entropy->dc_count_ptrs[compptr->dc_tbl_no],
  147401. entropy->ac_count_ptrs[compptr->ac_tbl_no]);
  147402. entropy->saved.last_dc_val[ci] = MCU_data[blkn][0][0];
  147403. }
  147404. return TRUE;
  147405. }
  147406. GLOBAL(void)
  147407. jpeg_gen_optimal_table (j_compress_ptr cinfo, JHUFF_TBL * htbl, long freq[])
  147408. {
  147409. #define MAX_CLEN 32 /* assumed maximum initial code length */
  147410. UINT8 bits[MAX_CLEN+1]; /* bits[k] = # of symbols with code length k */
  147411. int codesize[257]; /* codesize[k] = code length of symbol k */
  147412. int others[257]; /* next symbol in current branch of tree */
  147413. int c1, c2;
  147414. int p, i, j;
  147415. long v;
  147416. MEMZERO(bits, SIZEOF(bits));
  147417. MEMZERO(codesize, SIZEOF(codesize));
  147418. for (i = 0; i < 257; i++)
  147419. others[i] = -1; /* init links to empty */
  147420. freq[256] = 1; /* make sure 256 has a nonzero count */
  147421. for (;;) {
  147422. c1 = -1;
  147423. v = 1000000000L;
  147424. for (i = 0; i <= 256; i++) {
  147425. if (freq[i] && freq[i] <= v) {
  147426. v = freq[i];
  147427. c1 = i;
  147428. }
  147429. }
  147430. c2 = -1;
  147431. v = 1000000000L;
  147432. for (i = 0; i <= 256; i++) {
  147433. if (freq[i] && freq[i] <= v && i != c1) {
  147434. v = freq[i];
  147435. c2 = i;
  147436. }
  147437. }
  147438. if (c2 < 0)
  147439. break;
  147440. freq[c1] += freq[c2];
  147441. freq[c2] = 0;
  147442. codesize[c1]++;
  147443. while (others[c1] >= 0) {
  147444. c1 = others[c1];
  147445. codesize[c1]++;
  147446. }
  147447. others[c1] = c2; /* chain c2 onto c1's tree branch */
  147448. codesize[c2]++;
  147449. while (others[c2] >= 0) {
  147450. c2 = others[c2];
  147451. codesize[c2]++;
  147452. }
  147453. }
  147454. for (i = 0; i <= 256; i++) {
  147455. if (codesize[i]) {
  147456. if (codesize[i] > MAX_CLEN)
  147457. ERREXIT(cinfo, JERR_HUFF_CLEN_OVERFLOW);
  147458. bits[codesize[i]]++;
  147459. }
  147460. }
  147461. for (i = MAX_CLEN; i > 16; i--) {
  147462. while (bits[i] > 0) {
  147463. j = i - 2; /* find length of new prefix to be used */
  147464. while (bits[j] == 0)
  147465. j--;
  147466. bits[i] -= 2; /* remove two symbols */
  147467. bits[i-1]++; /* one goes in this length */
  147468. bits[j+1] += 2; /* two new symbols in this length */
  147469. bits[j]--; /* symbol of this length is now a prefix */
  147470. }
  147471. }
  147472. while (bits[i] == 0) /* find largest codelength still in use */
  147473. i--;
  147474. bits[i]--;
  147475. MEMCOPY(htbl->bits, bits, SIZEOF(htbl->bits));
  147476. p = 0;
  147477. for (i = 1; i <= MAX_CLEN; i++) {
  147478. for (j = 0; j <= 255; j++) {
  147479. if (codesize[j] == i) {
  147480. htbl->huffval[p] = (UINT8) j;
  147481. p++;
  147482. }
  147483. }
  147484. }
  147485. htbl->sent_table = FALSE;
  147486. }
  147487. METHODDEF(void)
  147488. finish_pass_gather (j_compress_ptr cinfo)
  147489. {
  147490. huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy;
  147491. int ci, dctbl, actbl;
  147492. jpeg_component_info * compptr;
  147493. JHUFF_TBL **htblptr;
  147494. boolean did_dc[NUM_HUFF_TBLS];
  147495. boolean did_ac[NUM_HUFF_TBLS];
  147496. MEMZERO(did_dc, SIZEOF(did_dc));
  147497. MEMZERO(did_ac, SIZEOF(did_ac));
  147498. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  147499. compptr = cinfo->cur_comp_info[ci];
  147500. dctbl = compptr->dc_tbl_no;
  147501. actbl = compptr->ac_tbl_no;
  147502. if (! did_dc[dctbl]) {
  147503. htblptr = & cinfo->dc_huff_tbl_ptrs[dctbl];
  147504. if (*htblptr == NULL)
  147505. *htblptr = jpeg_alloc_huff_table((j_common_ptr) cinfo);
  147506. jpeg_gen_optimal_table(cinfo, *htblptr, entropy->dc_count_ptrs[dctbl]);
  147507. did_dc[dctbl] = TRUE;
  147508. }
  147509. if (! did_ac[actbl]) {
  147510. htblptr = & cinfo->ac_huff_tbl_ptrs[actbl];
  147511. if (*htblptr == NULL)
  147512. *htblptr = jpeg_alloc_huff_table((j_common_ptr) cinfo);
  147513. jpeg_gen_optimal_table(cinfo, *htblptr, entropy->ac_count_ptrs[actbl]);
  147514. did_ac[actbl] = TRUE;
  147515. }
  147516. }
  147517. }
  147518. #endif /* ENTROPY_OPT_SUPPORTED */
  147519. GLOBAL(void)
  147520. jinit_huff_encoder (j_compress_ptr cinfo)
  147521. {
  147522. huff_entropy_ptr entropy;
  147523. int i;
  147524. entropy = (huff_entropy_ptr)
  147525. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  147526. SIZEOF(huff_entropy_encoder));
  147527. cinfo->entropy = (struct jpeg_entropy_encoder *) entropy;
  147528. entropy->pub.start_pass = start_pass_huff;
  147529. for (i = 0; i < NUM_HUFF_TBLS; i++) {
  147530. entropy->dc_derived_tbls[i] = entropy->ac_derived_tbls[i] = NULL;
  147531. #ifdef ENTROPY_OPT_SUPPORTED
  147532. entropy->dc_count_ptrs[i] = entropy->ac_count_ptrs[i] = NULL;
  147533. #endif
  147534. }
  147535. }
  147536. /*** End of inlined file: jchuff.c ***/
  147537. #undef emit_byte
  147538. /*** Start of inlined file: jcinit.c ***/
  147539. #define JPEG_INTERNALS
  147540. GLOBAL(void)
  147541. jinit_compress_master (j_compress_ptr cinfo)
  147542. {
  147543. jinit_c_master_control(cinfo, FALSE /* full compression */);
  147544. if (! cinfo->raw_data_in) {
  147545. jinit_color_converter(cinfo);
  147546. jinit_downsampler(cinfo);
  147547. jinit_c_prep_controller(cinfo, FALSE /* never need full buffer here */);
  147548. }
  147549. jinit_forward_dct(cinfo);
  147550. if (cinfo->arith_code) {
  147551. ERREXIT(cinfo, JERR_ARITH_NOTIMPL);
  147552. } else {
  147553. if (cinfo->progressive_mode) {
  147554. #ifdef C_PROGRESSIVE_SUPPORTED
  147555. jinit_phuff_encoder(cinfo);
  147556. #else
  147557. ERREXIT(cinfo, JERR_NOT_COMPILED);
  147558. #endif
  147559. } else
  147560. jinit_huff_encoder(cinfo);
  147561. }
  147562. jinit_c_coef_controller(cinfo,
  147563. (boolean) (cinfo->num_scans > 1 || cinfo->optimize_coding));
  147564. jinit_c_main_controller(cinfo, FALSE /* never need full buffer here */);
  147565. jinit_marker_writer(cinfo);
  147566. (*cinfo->mem->realize_virt_arrays) ((j_common_ptr) cinfo);
  147567. (*cinfo->marker->write_file_header) (cinfo);
  147568. }
  147569. /*** End of inlined file: jcinit.c ***/
  147570. /*** Start of inlined file: jcmainct.c ***/
  147571. #define JPEG_INTERNALS
  147572. #undef FULL_MAIN_BUFFER_SUPPORTED
  147573. typedef struct {
  147574. struct jpeg_c_main_controller pub; /* public fields */
  147575. JDIMENSION cur_iMCU_row; /* number of current iMCU row */
  147576. JDIMENSION rowgroup_ctr; /* counts row groups received in iMCU row */
  147577. boolean suspended; /* remember if we suspended output */
  147578. J_BUF_MODE pass_mode; /* current operating mode */
  147579. JSAMPARRAY buffer[MAX_COMPONENTS];
  147580. #ifdef FULL_MAIN_BUFFER_SUPPORTED
  147581. jvirt_sarray_ptr whole_image[MAX_COMPONENTS];
  147582. #endif
  147583. } my_main_controller;
  147584. typedef my_main_controller * my_main_ptr;
  147585. METHODDEF(void) process_data_simple_main
  147586. JPP((j_compress_ptr cinfo, JSAMPARRAY input_buf,
  147587. JDIMENSION *in_row_ctr, JDIMENSION in_rows_avail));
  147588. #ifdef FULL_MAIN_BUFFER_SUPPORTED
  147589. METHODDEF(void) process_data_buffer_main
  147590. JPP((j_compress_ptr cinfo, JSAMPARRAY input_buf,
  147591. JDIMENSION *in_row_ctr, JDIMENSION in_rows_avail));
  147592. #endif
  147593. METHODDEF(void)
  147594. start_pass_main (j_compress_ptr cinfo, J_BUF_MODE pass_mode)
  147595. {
  147596. my_main_ptr main_ = (my_main_ptr) cinfo->main;
  147597. if (cinfo->raw_data_in)
  147598. return;
  147599. main_->cur_iMCU_row = 0; /* initialize counters */
  147600. main_->rowgroup_ctr = 0;
  147601. main_->suspended = FALSE;
  147602. main_->pass_mode = pass_mode; /* save mode for use by process_data */
  147603. switch (pass_mode) {
  147604. case JBUF_PASS_THRU:
  147605. #ifdef FULL_MAIN_BUFFER_SUPPORTED
  147606. if (main_->whole_image[0] != NULL)
  147607. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  147608. #endif
  147609. main_->pub.process_data = process_data_simple_main;
  147610. break;
  147611. #ifdef FULL_MAIN_BUFFER_SUPPORTED
  147612. case JBUF_SAVE_SOURCE:
  147613. case JBUF_CRANK_DEST:
  147614. case JBUF_SAVE_AND_PASS:
  147615. if (main_->whole_image[0] == NULL)
  147616. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  147617. main_->pub.process_data = process_data_buffer_main;
  147618. break;
  147619. #endif
  147620. default:
  147621. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  147622. break;
  147623. }
  147624. }
  147625. METHODDEF(void)
  147626. process_data_simple_main (j_compress_ptr cinfo,
  147627. JSAMPARRAY input_buf, JDIMENSION *in_row_ctr,
  147628. JDIMENSION in_rows_avail)
  147629. {
  147630. my_main_ptr main_ = (my_main_ptr) cinfo->main;
  147631. while (main_->cur_iMCU_row < cinfo->total_iMCU_rows) {
  147632. if (main_->rowgroup_ctr < DCTSIZE)
  147633. (*cinfo->prep->pre_process_data) (cinfo,
  147634. input_buf, in_row_ctr, in_rows_avail,
  147635. main_->buffer, &main_->rowgroup_ctr,
  147636. (JDIMENSION) DCTSIZE);
  147637. if (main_->rowgroup_ctr != DCTSIZE)
  147638. return;
  147639. if (! (*cinfo->coef->compress_data) (cinfo, main_->buffer)) {
  147640. if (! main_->suspended) {
  147641. (*in_row_ctr)--;
  147642. main_->suspended = TRUE;
  147643. }
  147644. return;
  147645. }
  147646. if (main_->suspended) {
  147647. (*in_row_ctr)++;
  147648. main_->suspended = FALSE;
  147649. }
  147650. main_->rowgroup_ctr = 0;
  147651. main_->cur_iMCU_row++;
  147652. }
  147653. }
  147654. #ifdef FULL_MAIN_BUFFER_SUPPORTED
  147655. METHODDEF(void)
  147656. process_data_buffer_main (j_compress_ptr cinfo,
  147657. JSAMPARRAY input_buf, JDIMENSION *in_row_ctr,
  147658. JDIMENSION in_rows_avail)
  147659. {
  147660. my_main_ptr main = (my_main_ptr) cinfo->main;
  147661. int ci;
  147662. jpeg_component_info *compptr;
  147663. boolean writing = (main->pass_mode != JBUF_CRANK_DEST);
  147664. while (main->cur_iMCU_row < cinfo->total_iMCU_rows) {
  147665. if (main->rowgroup_ctr == 0) {
  147666. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  147667. ci++, compptr++) {
  147668. main->buffer[ci] = (*cinfo->mem->access_virt_sarray)
  147669. ((j_common_ptr) cinfo, main->whole_image[ci],
  147670. main->cur_iMCU_row * (compptr->v_samp_factor * DCTSIZE),
  147671. (JDIMENSION) (compptr->v_samp_factor * DCTSIZE), writing);
  147672. }
  147673. if (! writing) {
  147674. *in_row_ctr += cinfo->max_v_samp_factor * DCTSIZE;
  147675. main->rowgroup_ctr = DCTSIZE;
  147676. }
  147677. }
  147678. if (writing) {
  147679. (*cinfo->prep->pre_process_data) (cinfo,
  147680. input_buf, in_row_ctr, in_rows_avail,
  147681. main->buffer, &main->rowgroup_ctr,
  147682. (JDIMENSION) DCTSIZE);
  147683. if (main->rowgroup_ctr < DCTSIZE)
  147684. return;
  147685. }
  147686. if (main->pass_mode != JBUF_SAVE_SOURCE) {
  147687. if (! (*cinfo->coef->compress_data) (cinfo, main->buffer)) {
  147688. if (! main->suspended) {
  147689. (*in_row_ctr)--;
  147690. main->suspended = TRUE;
  147691. }
  147692. return;
  147693. }
  147694. if (main->suspended) {
  147695. (*in_row_ctr)++;
  147696. main->suspended = FALSE;
  147697. }
  147698. }
  147699. main->rowgroup_ctr = 0;
  147700. main->cur_iMCU_row++;
  147701. }
  147702. }
  147703. #endif /* FULL_MAIN_BUFFER_SUPPORTED */
  147704. GLOBAL(void)
  147705. jinit_c_main_controller (j_compress_ptr cinfo, boolean need_full_buffer)
  147706. {
  147707. my_main_ptr main_;
  147708. int ci;
  147709. jpeg_component_info *compptr;
  147710. main_ = (my_main_ptr)
  147711. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  147712. SIZEOF(my_main_controller));
  147713. cinfo->main = (struct jpeg_c_main_controller *) main_;
  147714. main_->pub.start_pass = start_pass_main;
  147715. if (cinfo->raw_data_in)
  147716. return;
  147717. if (need_full_buffer) {
  147718. #ifdef FULL_MAIN_BUFFER_SUPPORTED
  147719. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  147720. ci++, compptr++) {
  147721. main->whole_image[ci] = (*cinfo->mem->request_virt_sarray)
  147722. ((j_common_ptr) cinfo, JPOOL_IMAGE, FALSE,
  147723. compptr->width_in_blocks * DCTSIZE,
  147724. (JDIMENSION) jround_up((long) compptr->height_in_blocks,
  147725. (long) compptr->v_samp_factor) * DCTSIZE,
  147726. (JDIMENSION) (compptr->v_samp_factor * DCTSIZE));
  147727. }
  147728. #else
  147729. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  147730. #endif
  147731. } else {
  147732. #ifdef FULL_MAIN_BUFFER_SUPPORTED
  147733. main_->whole_image[0] = NULL; /* flag for no virtual arrays */
  147734. #endif
  147735. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  147736. ci++, compptr++) {
  147737. main_->buffer[ci] = (*cinfo->mem->alloc_sarray)
  147738. ((j_common_ptr) cinfo, JPOOL_IMAGE,
  147739. compptr->width_in_blocks * DCTSIZE,
  147740. (JDIMENSION) (compptr->v_samp_factor * DCTSIZE));
  147741. }
  147742. }
  147743. }
  147744. /*** End of inlined file: jcmainct.c ***/
  147745. /*** Start of inlined file: jcmarker.c ***/
  147746. #define JPEG_INTERNALS
  147747. typedef struct {
  147748. struct jpeg_marker_writer pub; /* public fields */
  147749. unsigned int last_restart_interval; /* last DRI value emitted; 0 after SOI */
  147750. } my_marker_writer;
  147751. typedef my_marker_writer * my_marker_ptr;
  147752. LOCAL(void)
  147753. emit_byte (j_compress_ptr cinfo, int val)
  147754. {
  147755. struct jpeg_destination_mgr * dest = cinfo->dest;
  147756. *(dest->next_output_byte)++ = (JOCTET) val;
  147757. if (--dest->free_in_buffer == 0) {
  147758. if (! (*dest->empty_output_buffer) (cinfo))
  147759. ERREXIT(cinfo, JERR_CANT_SUSPEND);
  147760. }
  147761. }
  147762. LOCAL(void)
  147763. emit_marker (j_compress_ptr cinfo, JPEG_MARKER mark)
  147764. {
  147765. emit_byte(cinfo, 0xFF);
  147766. emit_byte(cinfo, (int) mark);
  147767. }
  147768. LOCAL(void)
  147769. emit_2bytes (j_compress_ptr cinfo, int value)
  147770. {
  147771. emit_byte(cinfo, (value >> 8) & 0xFF);
  147772. emit_byte(cinfo, value & 0xFF);
  147773. }
  147774. LOCAL(int)
  147775. emit_dqt (j_compress_ptr cinfo, int index)
  147776. {
  147777. JQUANT_TBL * qtbl = cinfo->quant_tbl_ptrs[index];
  147778. int prec;
  147779. int i;
  147780. if (qtbl == NULL)
  147781. ERREXIT1(cinfo, JERR_NO_QUANT_TABLE, index);
  147782. prec = 0;
  147783. for (i = 0; i < DCTSIZE2; i++) {
  147784. if (qtbl->quantval[i] > 255)
  147785. prec = 1;
  147786. }
  147787. if (! qtbl->sent_table) {
  147788. emit_marker(cinfo, M_DQT);
  147789. emit_2bytes(cinfo, prec ? DCTSIZE2*2 + 1 + 2 : DCTSIZE2 + 1 + 2);
  147790. emit_byte(cinfo, index + (prec<<4));
  147791. for (i = 0; i < DCTSIZE2; i++) {
  147792. unsigned int qval = qtbl->quantval[jpeg_natural_order[i]];
  147793. if (prec)
  147794. emit_byte(cinfo, (int) (qval >> 8));
  147795. emit_byte(cinfo, (int) (qval & 0xFF));
  147796. }
  147797. qtbl->sent_table = TRUE;
  147798. }
  147799. return prec;
  147800. }
  147801. LOCAL(void)
  147802. emit_dht (j_compress_ptr cinfo, int index, boolean is_ac)
  147803. {
  147804. JHUFF_TBL * htbl;
  147805. int length, i;
  147806. if (is_ac) {
  147807. htbl = cinfo->ac_huff_tbl_ptrs[index];
  147808. index += 0x10; /* output index has AC bit set */
  147809. } else {
  147810. htbl = cinfo->dc_huff_tbl_ptrs[index];
  147811. }
  147812. if (htbl == NULL)
  147813. ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, index);
  147814. if (! htbl->sent_table) {
  147815. emit_marker(cinfo, M_DHT);
  147816. length = 0;
  147817. for (i = 1; i <= 16; i++)
  147818. length += htbl->bits[i];
  147819. emit_2bytes(cinfo, length + 2 + 1 + 16);
  147820. emit_byte(cinfo, index);
  147821. for (i = 1; i <= 16; i++)
  147822. emit_byte(cinfo, htbl->bits[i]);
  147823. for (i = 0; i < length; i++)
  147824. emit_byte(cinfo, htbl->huffval[i]);
  147825. htbl->sent_table = TRUE;
  147826. }
  147827. }
  147828. LOCAL(void)
  147829. emit_dac (j_compress_ptr cinfo)
  147830. {
  147831. #ifdef C_ARITH_CODING_SUPPORTED
  147832. char dc_in_use[NUM_ARITH_TBLS];
  147833. char ac_in_use[NUM_ARITH_TBLS];
  147834. int length, i;
  147835. jpeg_component_info *compptr;
  147836. for (i = 0; i < NUM_ARITH_TBLS; i++)
  147837. dc_in_use[i] = ac_in_use[i] = 0;
  147838. for (i = 0; i < cinfo->comps_in_scan; i++) {
  147839. compptr = cinfo->cur_comp_info[i];
  147840. dc_in_use[compptr->dc_tbl_no] = 1;
  147841. ac_in_use[compptr->ac_tbl_no] = 1;
  147842. }
  147843. length = 0;
  147844. for (i = 0; i < NUM_ARITH_TBLS; i++)
  147845. length += dc_in_use[i] + ac_in_use[i];
  147846. emit_marker(cinfo, M_DAC);
  147847. emit_2bytes(cinfo, length*2 + 2);
  147848. for (i = 0; i < NUM_ARITH_TBLS; i++) {
  147849. if (dc_in_use[i]) {
  147850. emit_byte(cinfo, i);
  147851. emit_byte(cinfo, cinfo->arith_dc_L[i] + (cinfo->arith_dc_U[i]<<4));
  147852. }
  147853. if (ac_in_use[i]) {
  147854. emit_byte(cinfo, i + 0x10);
  147855. emit_byte(cinfo, cinfo->arith_ac_K[i]);
  147856. }
  147857. }
  147858. #endif /* C_ARITH_CODING_SUPPORTED */
  147859. }
  147860. LOCAL(void)
  147861. emit_dri (j_compress_ptr cinfo)
  147862. {
  147863. emit_marker(cinfo, M_DRI);
  147864. emit_2bytes(cinfo, 4); /* fixed length */
  147865. emit_2bytes(cinfo, (int) cinfo->restart_interval);
  147866. }
  147867. LOCAL(void)
  147868. emit_sof (j_compress_ptr cinfo, JPEG_MARKER code)
  147869. {
  147870. int ci;
  147871. jpeg_component_info *compptr;
  147872. emit_marker(cinfo, code);
  147873. emit_2bytes(cinfo, 3 * cinfo->num_components + 2 + 5 + 1); /* length */
  147874. if ((long) cinfo->image_height > 65535L ||
  147875. (long) cinfo->image_width > 65535L)
  147876. ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, (unsigned int) 65535);
  147877. emit_byte(cinfo, cinfo->data_precision);
  147878. emit_2bytes(cinfo, (int) cinfo->image_height);
  147879. emit_2bytes(cinfo, (int) cinfo->image_width);
  147880. emit_byte(cinfo, cinfo->num_components);
  147881. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  147882. ci++, compptr++) {
  147883. emit_byte(cinfo, compptr->component_id);
  147884. emit_byte(cinfo, (compptr->h_samp_factor << 4) + compptr->v_samp_factor);
  147885. emit_byte(cinfo, compptr->quant_tbl_no);
  147886. }
  147887. }
  147888. LOCAL(void)
  147889. emit_sos (j_compress_ptr cinfo)
  147890. {
  147891. int i, td, ta;
  147892. jpeg_component_info *compptr;
  147893. emit_marker(cinfo, M_SOS);
  147894. emit_2bytes(cinfo, 2 * cinfo->comps_in_scan + 2 + 1 + 3); /* length */
  147895. emit_byte(cinfo, cinfo->comps_in_scan);
  147896. for (i = 0; i < cinfo->comps_in_scan; i++) {
  147897. compptr = cinfo->cur_comp_info[i];
  147898. emit_byte(cinfo, compptr->component_id);
  147899. td = compptr->dc_tbl_no;
  147900. ta = compptr->ac_tbl_no;
  147901. if (cinfo->progressive_mode) {
  147902. if (cinfo->Ss == 0) {
  147903. ta = 0; /* DC scan */
  147904. if (cinfo->Ah != 0 && !cinfo->arith_code)
  147905. td = 0; /* no DC table either */
  147906. } else {
  147907. td = 0; /* AC scan */
  147908. }
  147909. }
  147910. emit_byte(cinfo, (td << 4) + ta);
  147911. }
  147912. emit_byte(cinfo, cinfo->Ss);
  147913. emit_byte(cinfo, cinfo->Se);
  147914. emit_byte(cinfo, (cinfo->Ah << 4) + cinfo->Al);
  147915. }
  147916. LOCAL(void)
  147917. emit_jfif_app0 (j_compress_ptr cinfo)
  147918. {
  147919. emit_marker(cinfo, M_APP0);
  147920. emit_2bytes(cinfo, 2 + 4 + 1 + 2 + 1 + 2 + 2 + 1 + 1); /* length */
  147921. emit_byte(cinfo, 0x4A); /* Identifier: ASCII "JFIF" */
  147922. emit_byte(cinfo, 0x46);
  147923. emit_byte(cinfo, 0x49);
  147924. emit_byte(cinfo, 0x46);
  147925. emit_byte(cinfo, 0);
  147926. emit_byte(cinfo, cinfo->JFIF_major_version); /* Version fields */
  147927. emit_byte(cinfo, cinfo->JFIF_minor_version);
  147928. emit_byte(cinfo, cinfo->density_unit); /* Pixel size information */
  147929. emit_2bytes(cinfo, (int) cinfo->X_density);
  147930. emit_2bytes(cinfo, (int) cinfo->Y_density);
  147931. emit_byte(cinfo, 0); /* No thumbnail image */
  147932. emit_byte(cinfo, 0);
  147933. }
  147934. LOCAL(void)
  147935. emit_adobe_app14 (j_compress_ptr cinfo)
  147936. {
  147937. emit_marker(cinfo, M_APP14);
  147938. emit_2bytes(cinfo, 2 + 5 + 2 + 2 + 2 + 1); /* length */
  147939. emit_byte(cinfo, 0x41); /* Identifier: ASCII "Adobe" */
  147940. emit_byte(cinfo, 0x64);
  147941. emit_byte(cinfo, 0x6F);
  147942. emit_byte(cinfo, 0x62);
  147943. emit_byte(cinfo, 0x65);
  147944. emit_2bytes(cinfo, 100); /* Version */
  147945. emit_2bytes(cinfo, 0); /* Flags0 */
  147946. emit_2bytes(cinfo, 0); /* Flags1 */
  147947. switch (cinfo->jpeg_color_space) {
  147948. case JCS_YCbCr:
  147949. emit_byte(cinfo, 1); /* Color transform = 1 */
  147950. break;
  147951. case JCS_YCCK:
  147952. emit_byte(cinfo, 2); /* Color transform = 2 */
  147953. break;
  147954. default:
  147955. emit_byte(cinfo, 0); /* Color transform = 0 */
  147956. break;
  147957. }
  147958. }
  147959. METHODDEF(void)
  147960. write_marker_header (j_compress_ptr cinfo, int marker, unsigned int datalen)
  147961. {
  147962. if (datalen > (unsigned int) 65533) /* safety check */
  147963. ERREXIT(cinfo, JERR_BAD_LENGTH);
  147964. emit_marker(cinfo, (JPEG_MARKER) marker);
  147965. emit_2bytes(cinfo, (int) (datalen + 2)); /* total length */
  147966. }
  147967. METHODDEF(void)
  147968. write_marker_byte (j_compress_ptr cinfo, int val)
  147969. {
  147970. emit_byte(cinfo, val);
  147971. }
  147972. METHODDEF(void)
  147973. write_file_header (j_compress_ptr cinfo)
  147974. {
  147975. my_marker_ptr marker = (my_marker_ptr) cinfo->marker;
  147976. emit_marker(cinfo, M_SOI); /* first the SOI */
  147977. marker->last_restart_interval = 0;
  147978. if (cinfo->write_JFIF_header) /* next an optional JFIF APP0 */
  147979. emit_jfif_app0(cinfo);
  147980. if (cinfo->write_Adobe_marker) /* next an optional Adobe APP14 */
  147981. emit_adobe_app14(cinfo);
  147982. }
  147983. METHODDEF(void)
  147984. write_frame_header (j_compress_ptr cinfo)
  147985. {
  147986. int ci, prec;
  147987. boolean is_baseline;
  147988. jpeg_component_info *compptr;
  147989. prec = 0;
  147990. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  147991. ci++, compptr++) {
  147992. prec += emit_dqt(cinfo, compptr->quant_tbl_no);
  147993. }
  147994. if (cinfo->arith_code || cinfo->progressive_mode ||
  147995. cinfo->data_precision != 8) {
  147996. is_baseline = FALSE;
  147997. } else {
  147998. is_baseline = TRUE;
  147999. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  148000. ci++, compptr++) {
  148001. if (compptr->dc_tbl_no > 1 || compptr->ac_tbl_no > 1)
  148002. is_baseline = FALSE;
  148003. }
  148004. if (prec && is_baseline) {
  148005. is_baseline = FALSE;
  148006. TRACEMS(cinfo, 0, JTRC_16BIT_TABLES);
  148007. }
  148008. }
  148009. if (cinfo->arith_code) {
  148010. emit_sof(cinfo, M_SOF9); /* SOF code for arithmetic coding */
  148011. } else {
  148012. if (cinfo->progressive_mode)
  148013. emit_sof(cinfo, M_SOF2); /* SOF code for progressive Huffman */
  148014. else if (is_baseline)
  148015. emit_sof(cinfo, M_SOF0); /* SOF code for baseline implementation */
  148016. else
  148017. emit_sof(cinfo, M_SOF1); /* SOF code for non-baseline Huffman file */
  148018. }
  148019. }
  148020. METHODDEF(void)
  148021. write_scan_header (j_compress_ptr cinfo)
  148022. {
  148023. my_marker_ptr marker = (my_marker_ptr) cinfo->marker;
  148024. int i;
  148025. jpeg_component_info *compptr;
  148026. if (cinfo->arith_code) {
  148027. emit_dac(cinfo);
  148028. } else {
  148029. for (i = 0; i < cinfo->comps_in_scan; i++) {
  148030. compptr = cinfo->cur_comp_info[i];
  148031. if (cinfo->progressive_mode) {
  148032. if (cinfo->Ss == 0) {
  148033. if (cinfo->Ah == 0) /* DC needs no table for refinement scan */
  148034. emit_dht(cinfo, compptr->dc_tbl_no, FALSE);
  148035. } else {
  148036. emit_dht(cinfo, compptr->ac_tbl_no, TRUE);
  148037. }
  148038. } else {
  148039. emit_dht(cinfo, compptr->dc_tbl_no, FALSE);
  148040. emit_dht(cinfo, compptr->ac_tbl_no, TRUE);
  148041. }
  148042. }
  148043. }
  148044. if (cinfo->restart_interval != marker->last_restart_interval) {
  148045. emit_dri(cinfo);
  148046. marker->last_restart_interval = cinfo->restart_interval;
  148047. }
  148048. emit_sos(cinfo);
  148049. }
  148050. METHODDEF(void)
  148051. write_file_trailer (j_compress_ptr cinfo)
  148052. {
  148053. emit_marker(cinfo, M_EOI);
  148054. }
  148055. METHODDEF(void)
  148056. write_tables_only (j_compress_ptr cinfo)
  148057. {
  148058. int i;
  148059. emit_marker(cinfo, M_SOI);
  148060. for (i = 0; i < NUM_QUANT_TBLS; i++) {
  148061. if (cinfo->quant_tbl_ptrs[i] != NULL)
  148062. (void) emit_dqt(cinfo, i);
  148063. }
  148064. if (! cinfo->arith_code) {
  148065. for (i = 0; i < NUM_HUFF_TBLS; i++) {
  148066. if (cinfo->dc_huff_tbl_ptrs[i] != NULL)
  148067. emit_dht(cinfo, i, FALSE);
  148068. if (cinfo->ac_huff_tbl_ptrs[i] != NULL)
  148069. emit_dht(cinfo, i, TRUE);
  148070. }
  148071. }
  148072. emit_marker(cinfo, M_EOI);
  148073. }
  148074. GLOBAL(void)
  148075. jinit_marker_writer (j_compress_ptr cinfo)
  148076. {
  148077. my_marker_ptr marker;
  148078. marker = (my_marker_ptr)
  148079. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  148080. SIZEOF(my_marker_writer));
  148081. cinfo->marker = (struct jpeg_marker_writer *) marker;
  148082. marker->pub.write_file_header = write_file_header;
  148083. marker->pub.write_frame_header = write_frame_header;
  148084. marker->pub.write_scan_header = write_scan_header;
  148085. marker->pub.write_file_trailer = write_file_trailer;
  148086. marker->pub.write_tables_only = write_tables_only;
  148087. marker->pub.write_marker_header = write_marker_header;
  148088. marker->pub.write_marker_byte = write_marker_byte;
  148089. marker->last_restart_interval = 0;
  148090. }
  148091. /*** End of inlined file: jcmarker.c ***/
  148092. /*** Start of inlined file: jcmaster.c ***/
  148093. #define JPEG_INTERNALS
  148094. typedef enum {
  148095. main_pass, /* input data, also do first output step */
  148096. huff_opt_pass, /* Huffman code optimization pass */
  148097. output_pass /* data output pass */
  148098. } c_pass_type;
  148099. typedef struct {
  148100. struct jpeg_comp_master pub; /* public fields */
  148101. c_pass_type pass_type; /* the type of the current pass */
  148102. int pass_number; /* # of passes completed */
  148103. int total_passes; /* total # of passes needed */
  148104. int scan_number; /* current index in scan_info[] */
  148105. } my_comp_master;
  148106. typedef my_comp_master * my_master_ptr;
  148107. LOCAL(void)
  148108. initial_setup (j_compress_ptr cinfo)
  148109. {
  148110. int ci;
  148111. jpeg_component_info *compptr;
  148112. long samplesperrow;
  148113. JDIMENSION jd_samplesperrow;
  148114. if (cinfo->image_height <= 0 || cinfo->image_width <= 0
  148115. || cinfo->num_components <= 0 || cinfo->input_components <= 0)
  148116. ERREXIT(cinfo, JERR_EMPTY_IMAGE);
  148117. if ((long) cinfo->image_height > (long) JPEG_MAX_DIMENSION ||
  148118. (long) cinfo->image_width > (long) JPEG_MAX_DIMENSION)
  148119. ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, (unsigned int) JPEG_MAX_DIMENSION);
  148120. samplesperrow = (long) cinfo->image_width * (long) cinfo->input_components;
  148121. jd_samplesperrow = (JDIMENSION) samplesperrow;
  148122. if ((long) jd_samplesperrow != samplesperrow)
  148123. ERREXIT(cinfo, JERR_WIDTH_OVERFLOW);
  148124. if (cinfo->data_precision != BITS_IN_JSAMPLE)
  148125. ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
  148126. if (cinfo->num_components > MAX_COMPONENTS)
  148127. ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->num_components,
  148128. MAX_COMPONENTS);
  148129. cinfo->max_h_samp_factor = 1;
  148130. cinfo->max_v_samp_factor = 1;
  148131. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  148132. ci++, compptr++) {
  148133. if (compptr->h_samp_factor<=0 || compptr->h_samp_factor>MAX_SAMP_FACTOR ||
  148134. compptr->v_samp_factor<=0 || compptr->v_samp_factor>MAX_SAMP_FACTOR)
  148135. ERREXIT(cinfo, JERR_BAD_SAMPLING);
  148136. cinfo->max_h_samp_factor = MAX(cinfo->max_h_samp_factor,
  148137. compptr->h_samp_factor);
  148138. cinfo->max_v_samp_factor = MAX(cinfo->max_v_samp_factor,
  148139. compptr->v_samp_factor);
  148140. }
  148141. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  148142. ci++, compptr++) {
  148143. compptr->component_index = ci;
  148144. compptr->DCT_scaled_size = DCTSIZE;
  148145. compptr->width_in_blocks = (JDIMENSION)
  148146. jdiv_round_up((long) cinfo->image_width * (long) compptr->h_samp_factor,
  148147. (long) (cinfo->max_h_samp_factor * DCTSIZE));
  148148. compptr->height_in_blocks = (JDIMENSION)
  148149. jdiv_round_up((long) cinfo->image_height * (long) compptr->v_samp_factor,
  148150. (long) (cinfo->max_v_samp_factor * DCTSIZE));
  148151. compptr->downsampled_width = (JDIMENSION)
  148152. jdiv_round_up((long) cinfo->image_width * (long) compptr->h_samp_factor,
  148153. (long) cinfo->max_h_samp_factor);
  148154. compptr->downsampled_height = (JDIMENSION)
  148155. jdiv_round_up((long) cinfo->image_height * (long) compptr->v_samp_factor,
  148156. (long) cinfo->max_v_samp_factor);
  148157. compptr->component_needed = TRUE;
  148158. }
  148159. cinfo->total_iMCU_rows = (JDIMENSION)
  148160. jdiv_round_up((long) cinfo->image_height,
  148161. (long) (cinfo->max_v_samp_factor*DCTSIZE));
  148162. }
  148163. #ifdef C_MULTISCAN_FILES_SUPPORTED
  148164. LOCAL(void)
  148165. validate_script (j_compress_ptr cinfo)
  148166. {
  148167. const jpeg_scan_info * scanptr;
  148168. int scanno, ncomps, ci, coefi, thisi;
  148169. int Ss, Se, Ah, Al;
  148170. boolean component_sent[MAX_COMPONENTS];
  148171. #ifdef C_PROGRESSIVE_SUPPORTED
  148172. int * last_bitpos_ptr;
  148173. int last_bitpos[MAX_COMPONENTS][DCTSIZE2];
  148174. #endif
  148175. if (cinfo->num_scans <= 0)
  148176. ERREXIT1(cinfo, JERR_BAD_SCAN_SCRIPT, 0);
  148177. scanptr = cinfo->scan_info;
  148178. if (scanptr->Ss != 0 || scanptr->Se != DCTSIZE2-1) {
  148179. #ifdef C_PROGRESSIVE_SUPPORTED
  148180. cinfo->progressive_mode = TRUE;
  148181. last_bitpos_ptr = & last_bitpos[0][0];
  148182. for (ci = 0; ci < cinfo->num_components; ci++)
  148183. for (coefi = 0; coefi < DCTSIZE2; coefi++)
  148184. *last_bitpos_ptr++ = -1;
  148185. #else
  148186. ERREXIT(cinfo, JERR_NOT_COMPILED);
  148187. #endif
  148188. } else {
  148189. cinfo->progressive_mode = FALSE;
  148190. for (ci = 0; ci < cinfo->num_components; ci++)
  148191. component_sent[ci] = FALSE;
  148192. }
  148193. for (scanno = 1; scanno <= cinfo->num_scans; scanptr++, scanno++) {
  148194. ncomps = scanptr->comps_in_scan;
  148195. if (ncomps <= 0 || ncomps > MAX_COMPS_IN_SCAN)
  148196. ERREXIT2(cinfo, JERR_COMPONENT_COUNT, ncomps, MAX_COMPS_IN_SCAN);
  148197. for (ci = 0; ci < ncomps; ci++) {
  148198. thisi = scanptr->component_index[ci];
  148199. if (thisi < 0 || thisi >= cinfo->num_components)
  148200. ERREXIT1(cinfo, JERR_BAD_SCAN_SCRIPT, scanno);
  148201. if (ci > 0 && thisi <= scanptr->component_index[ci-1])
  148202. ERREXIT1(cinfo, JERR_BAD_SCAN_SCRIPT, scanno);
  148203. }
  148204. Ss = scanptr->Ss;
  148205. Se = scanptr->Se;
  148206. Ah = scanptr->Ah;
  148207. Al = scanptr->Al;
  148208. if (cinfo->progressive_mode) {
  148209. #ifdef C_PROGRESSIVE_SUPPORTED
  148210. #if BITS_IN_JSAMPLE == 8
  148211. #define MAX_AH_AL 10
  148212. #else
  148213. #define MAX_AH_AL 13
  148214. #endif
  148215. if (Ss < 0 || Ss >= DCTSIZE2 || Se < Ss || Se >= DCTSIZE2 ||
  148216. Ah < 0 || Ah > MAX_AH_AL || Al < 0 || Al > MAX_AH_AL)
  148217. ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
  148218. if (Ss == 0) {
  148219. if (Se != 0) /* DC and AC together not OK */
  148220. ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
  148221. } else {
  148222. if (ncomps != 1) /* AC scans must be for only one component */
  148223. ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
  148224. }
  148225. for (ci = 0; ci < ncomps; ci++) {
  148226. last_bitpos_ptr = & last_bitpos[scanptr->component_index[ci]][0];
  148227. if (Ss != 0 && last_bitpos_ptr[0] < 0) /* AC without prior DC scan */
  148228. ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
  148229. for (coefi = Ss; coefi <= Se; coefi++) {
  148230. if (last_bitpos_ptr[coefi] < 0) {
  148231. if (Ah != 0)
  148232. ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
  148233. } else {
  148234. if (Ah != last_bitpos_ptr[coefi] || Al != Ah-1)
  148235. ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
  148236. }
  148237. last_bitpos_ptr[coefi] = Al;
  148238. }
  148239. }
  148240. #endif
  148241. } else {
  148242. if (Ss != 0 || Se != DCTSIZE2-1 || Ah != 0 || Al != 0)
  148243. ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
  148244. for (ci = 0; ci < ncomps; ci++) {
  148245. thisi = scanptr->component_index[ci];
  148246. if (component_sent[thisi])
  148247. ERREXIT1(cinfo, JERR_BAD_SCAN_SCRIPT, scanno);
  148248. component_sent[thisi] = TRUE;
  148249. }
  148250. }
  148251. }
  148252. if (cinfo->progressive_mode) {
  148253. #ifdef C_PROGRESSIVE_SUPPORTED
  148254. for (ci = 0; ci < cinfo->num_components; ci++) {
  148255. if (last_bitpos[ci][0] < 0)
  148256. ERREXIT(cinfo, JERR_MISSING_DATA);
  148257. }
  148258. #endif
  148259. } else {
  148260. for (ci = 0; ci < cinfo->num_components; ci++) {
  148261. if (! component_sent[ci])
  148262. ERREXIT(cinfo, JERR_MISSING_DATA);
  148263. }
  148264. }
  148265. }
  148266. #endif /* C_MULTISCAN_FILES_SUPPORTED */
  148267. LOCAL(void)
  148268. select_scan_parameters (j_compress_ptr cinfo)
  148269. {
  148270. int ci;
  148271. #ifdef C_MULTISCAN_FILES_SUPPORTED
  148272. if (cinfo->scan_info != NULL) {
  148273. my_master_ptr master = (my_master_ptr) cinfo->master;
  148274. const jpeg_scan_info * scanptr = cinfo->scan_info + master->scan_number;
  148275. cinfo->comps_in_scan = scanptr->comps_in_scan;
  148276. for (ci = 0; ci < scanptr->comps_in_scan; ci++) {
  148277. cinfo->cur_comp_info[ci] =
  148278. &cinfo->comp_info[scanptr->component_index[ci]];
  148279. }
  148280. cinfo->Ss = scanptr->Ss;
  148281. cinfo->Se = scanptr->Se;
  148282. cinfo->Ah = scanptr->Ah;
  148283. cinfo->Al = scanptr->Al;
  148284. }
  148285. else
  148286. #endif
  148287. {
  148288. if (cinfo->num_components > MAX_COMPS_IN_SCAN)
  148289. ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->num_components,
  148290. MAX_COMPS_IN_SCAN);
  148291. cinfo->comps_in_scan = cinfo->num_components;
  148292. for (ci = 0; ci < cinfo->num_components; ci++) {
  148293. cinfo->cur_comp_info[ci] = &cinfo->comp_info[ci];
  148294. }
  148295. cinfo->Ss = 0;
  148296. cinfo->Se = DCTSIZE2-1;
  148297. cinfo->Ah = 0;
  148298. cinfo->Al = 0;
  148299. }
  148300. }
  148301. LOCAL(void)
  148302. per_scan_setup (j_compress_ptr cinfo)
  148303. {
  148304. int ci, mcublks, tmp;
  148305. jpeg_component_info *compptr;
  148306. if (cinfo->comps_in_scan == 1) {
  148307. compptr = cinfo->cur_comp_info[0];
  148308. cinfo->MCUs_per_row = compptr->width_in_blocks;
  148309. cinfo->MCU_rows_in_scan = compptr->height_in_blocks;
  148310. compptr->MCU_width = 1;
  148311. compptr->MCU_height = 1;
  148312. compptr->MCU_blocks = 1;
  148313. compptr->MCU_sample_width = DCTSIZE;
  148314. compptr->last_col_width = 1;
  148315. tmp = (int) (compptr->height_in_blocks % compptr->v_samp_factor);
  148316. if (tmp == 0) tmp = compptr->v_samp_factor;
  148317. compptr->last_row_height = tmp;
  148318. cinfo->blocks_in_MCU = 1;
  148319. cinfo->MCU_membership[0] = 0;
  148320. } else {
  148321. if (cinfo->comps_in_scan <= 0 || cinfo->comps_in_scan > MAX_COMPS_IN_SCAN)
  148322. ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->comps_in_scan,
  148323. MAX_COMPS_IN_SCAN);
  148324. cinfo->MCUs_per_row = (JDIMENSION)
  148325. jdiv_round_up((long) cinfo->image_width,
  148326. (long) (cinfo->max_h_samp_factor*DCTSIZE));
  148327. cinfo->MCU_rows_in_scan = (JDIMENSION)
  148328. jdiv_round_up((long) cinfo->image_height,
  148329. (long) (cinfo->max_v_samp_factor*DCTSIZE));
  148330. cinfo->blocks_in_MCU = 0;
  148331. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  148332. compptr = cinfo->cur_comp_info[ci];
  148333. compptr->MCU_width = compptr->h_samp_factor;
  148334. compptr->MCU_height = compptr->v_samp_factor;
  148335. compptr->MCU_blocks = compptr->MCU_width * compptr->MCU_height;
  148336. compptr->MCU_sample_width = compptr->MCU_width * DCTSIZE;
  148337. tmp = (int) (compptr->width_in_blocks % compptr->MCU_width);
  148338. if (tmp == 0) tmp = compptr->MCU_width;
  148339. compptr->last_col_width = tmp;
  148340. tmp = (int) (compptr->height_in_blocks % compptr->MCU_height);
  148341. if (tmp == 0) tmp = compptr->MCU_height;
  148342. compptr->last_row_height = tmp;
  148343. mcublks = compptr->MCU_blocks;
  148344. if (cinfo->blocks_in_MCU + mcublks > C_MAX_BLOCKS_IN_MCU)
  148345. ERREXIT(cinfo, JERR_BAD_MCU_SIZE);
  148346. while (mcublks-- > 0) {
  148347. cinfo->MCU_membership[cinfo->blocks_in_MCU++] = ci;
  148348. }
  148349. }
  148350. }
  148351. if (cinfo->restart_in_rows > 0) {
  148352. long nominal = (long) cinfo->restart_in_rows * (long) cinfo->MCUs_per_row;
  148353. cinfo->restart_interval = (unsigned int) MIN(nominal, 65535L);
  148354. }
  148355. }
  148356. METHODDEF(void)
  148357. prepare_for_pass (j_compress_ptr cinfo)
  148358. {
  148359. my_master_ptr master = (my_master_ptr) cinfo->master;
  148360. switch (master->pass_type) {
  148361. case main_pass:
  148362. select_scan_parameters(cinfo);
  148363. per_scan_setup(cinfo);
  148364. if (! cinfo->raw_data_in) {
  148365. (*cinfo->cconvert->start_pass) (cinfo);
  148366. (*cinfo->downsample->start_pass) (cinfo);
  148367. (*cinfo->prep->start_pass) (cinfo, JBUF_PASS_THRU);
  148368. }
  148369. (*cinfo->fdct->start_pass) (cinfo);
  148370. (*cinfo->entropy->start_pass) (cinfo, cinfo->optimize_coding);
  148371. (*cinfo->coef->start_pass) (cinfo,
  148372. (master->total_passes > 1 ?
  148373. JBUF_SAVE_AND_PASS : JBUF_PASS_THRU));
  148374. (*cinfo->main->start_pass) (cinfo, JBUF_PASS_THRU);
  148375. if (cinfo->optimize_coding) {
  148376. master->pub.call_pass_startup = FALSE;
  148377. } else {
  148378. master->pub.call_pass_startup = TRUE;
  148379. }
  148380. break;
  148381. #ifdef ENTROPY_OPT_SUPPORTED
  148382. case huff_opt_pass:
  148383. select_scan_parameters(cinfo);
  148384. per_scan_setup(cinfo);
  148385. if (cinfo->Ss != 0 || cinfo->Ah == 0 || cinfo->arith_code) {
  148386. (*cinfo->entropy->start_pass) (cinfo, TRUE);
  148387. (*cinfo->coef->start_pass) (cinfo, JBUF_CRANK_DEST);
  148388. master->pub.call_pass_startup = FALSE;
  148389. break;
  148390. }
  148391. master->pass_type = output_pass;
  148392. master->pass_number++;
  148393. #endif
  148394. case output_pass:
  148395. if (! cinfo->optimize_coding) {
  148396. select_scan_parameters(cinfo);
  148397. per_scan_setup(cinfo);
  148398. }
  148399. (*cinfo->entropy->start_pass) (cinfo, FALSE);
  148400. (*cinfo->coef->start_pass) (cinfo, JBUF_CRANK_DEST);
  148401. if (master->scan_number == 0)
  148402. (*cinfo->marker->write_frame_header) (cinfo);
  148403. (*cinfo->marker->write_scan_header) (cinfo);
  148404. master->pub.call_pass_startup = FALSE;
  148405. break;
  148406. default:
  148407. ERREXIT(cinfo, JERR_NOT_COMPILED);
  148408. }
  148409. master->pub.is_last_pass = (master->pass_number == master->total_passes-1);
  148410. if (cinfo->progress != NULL) {
  148411. cinfo->progress->completed_passes = master->pass_number;
  148412. cinfo->progress->total_passes = master->total_passes;
  148413. }
  148414. }
  148415. METHODDEF(void)
  148416. pass_startup (j_compress_ptr cinfo)
  148417. {
  148418. cinfo->master->call_pass_startup = FALSE; /* reset flag so call only once */
  148419. (*cinfo->marker->write_frame_header) (cinfo);
  148420. (*cinfo->marker->write_scan_header) (cinfo);
  148421. }
  148422. METHODDEF(void)
  148423. finish_pass_master (j_compress_ptr cinfo)
  148424. {
  148425. my_master_ptr master = (my_master_ptr) cinfo->master;
  148426. (*cinfo->entropy->finish_pass) (cinfo);
  148427. switch (master->pass_type) {
  148428. case main_pass:
  148429. master->pass_type = output_pass;
  148430. if (! cinfo->optimize_coding)
  148431. master->scan_number++;
  148432. break;
  148433. case huff_opt_pass:
  148434. master->pass_type = output_pass;
  148435. break;
  148436. case output_pass:
  148437. if (cinfo->optimize_coding)
  148438. master->pass_type = huff_opt_pass;
  148439. master->scan_number++;
  148440. break;
  148441. }
  148442. master->pass_number++;
  148443. }
  148444. GLOBAL(void)
  148445. jinit_c_master_control (j_compress_ptr cinfo, boolean transcode_only)
  148446. {
  148447. my_master_ptr master;
  148448. master = (my_master_ptr)
  148449. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  148450. SIZEOF(my_comp_master));
  148451. cinfo->master = (struct jpeg_comp_master *) master;
  148452. master->pub.prepare_for_pass = prepare_for_pass;
  148453. master->pub.pass_startup = pass_startup;
  148454. master->pub.finish_pass = finish_pass_master;
  148455. master->pub.is_last_pass = FALSE;
  148456. initial_setup(cinfo);
  148457. if (cinfo->scan_info != NULL) {
  148458. #ifdef C_MULTISCAN_FILES_SUPPORTED
  148459. validate_script(cinfo);
  148460. #else
  148461. ERREXIT(cinfo, JERR_NOT_COMPILED);
  148462. #endif
  148463. } else {
  148464. cinfo->progressive_mode = FALSE;
  148465. cinfo->num_scans = 1;
  148466. }
  148467. if (cinfo->progressive_mode) /* TEMPORARY HACK ??? */
  148468. cinfo->optimize_coding = TRUE; /* assume default tables no good for progressive mode */
  148469. if (transcode_only) {
  148470. if (cinfo->optimize_coding)
  148471. master->pass_type = huff_opt_pass;
  148472. else
  148473. master->pass_type = output_pass;
  148474. } else {
  148475. master->pass_type = main_pass;
  148476. }
  148477. master->scan_number = 0;
  148478. master->pass_number = 0;
  148479. if (cinfo->optimize_coding)
  148480. master->total_passes = cinfo->num_scans * 2;
  148481. else
  148482. master->total_passes = cinfo->num_scans;
  148483. }
  148484. /*** End of inlined file: jcmaster.c ***/
  148485. /*** Start of inlined file: jcomapi.c ***/
  148486. #define JPEG_INTERNALS
  148487. GLOBAL(void)
  148488. jpeg_abort (j_common_ptr cinfo)
  148489. {
  148490. int pool;
  148491. if (cinfo->mem == NULL)
  148492. return;
  148493. for (pool = JPOOL_NUMPOOLS-1; pool > JPOOL_PERMANENT; pool--) {
  148494. (*cinfo->mem->free_pool) (cinfo, pool);
  148495. }
  148496. if (cinfo->is_decompressor) {
  148497. cinfo->global_state = DSTATE_START;
  148498. ((j_decompress_ptr) cinfo)->marker_list = NULL;
  148499. } else {
  148500. cinfo->global_state = CSTATE_START;
  148501. }
  148502. }
  148503. GLOBAL(void)
  148504. jpeg_destroy (j_common_ptr cinfo)
  148505. {
  148506. if (cinfo->mem != NULL)
  148507. (*cinfo->mem->self_destruct) (cinfo);
  148508. cinfo->mem = NULL; /* be safe if jpeg_destroy is called twice */
  148509. cinfo->global_state = 0; /* mark it destroyed */
  148510. }
  148511. GLOBAL(JQUANT_TBL *)
  148512. jpeg_alloc_quant_table (j_common_ptr cinfo)
  148513. {
  148514. JQUANT_TBL *tbl;
  148515. tbl = (JQUANT_TBL *)
  148516. (*cinfo->mem->alloc_small) (cinfo, JPOOL_PERMANENT, SIZEOF(JQUANT_TBL));
  148517. tbl->sent_table = FALSE; /* make sure this is false in any new table */
  148518. return tbl;
  148519. }
  148520. GLOBAL(JHUFF_TBL *)
  148521. jpeg_alloc_huff_table (j_common_ptr cinfo)
  148522. {
  148523. JHUFF_TBL *tbl;
  148524. tbl = (JHUFF_TBL *)
  148525. (*cinfo->mem->alloc_small) (cinfo, JPOOL_PERMANENT, SIZEOF(JHUFF_TBL));
  148526. tbl->sent_table = FALSE; /* make sure this is false in any new table */
  148527. return tbl;
  148528. }
  148529. /*** End of inlined file: jcomapi.c ***/
  148530. /*** Start of inlined file: jcparam.c ***/
  148531. #define JPEG_INTERNALS
  148532. GLOBAL(void)
  148533. jpeg_add_quant_table (j_compress_ptr cinfo, int which_tbl,
  148534. const unsigned int *basic_table,
  148535. int scale_factor, boolean force_baseline)
  148536. {
  148537. JQUANT_TBL ** qtblptr;
  148538. int i;
  148539. long temp;
  148540. if (cinfo->global_state != CSTATE_START)
  148541. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  148542. if (which_tbl < 0 || which_tbl >= NUM_QUANT_TBLS)
  148543. ERREXIT1(cinfo, JERR_DQT_INDEX, which_tbl);
  148544. qtblptr = & cinfo->quant_tbl_ptrs[which_tbl];
  148545. if (*qtblptr == NULL)
  148546. *qtblptr = jpeg_alloc_quant_table((j_common_ptr) cinfo);
  148547. for (i = 0; i < DCTSIZE2; i++) {
  148548. temp = ((long) basic_table[i] * scale_factor + 50L) / 100L;
  148549. if (temp <= 0L) temp = 1L;
  148550. if (temp > 32767L) temp = 32767L; /* max quantizer needed for 12 bits */
  148551. if (force_baseline && temp > 255L)
  148552. temp = 255L; /* limit to baseline range if requested */
  148553. (*qtblptr)->quantval[i] = (UINT16) temp;
  148554. }
  148555. (*qtblptr)->sent_table = FALSE;
  148556. }
  148557. GLOBAL(void)
  148558. jpeg_set_linear_quality (j_compress_ptr cinfo, int scale_factor,
  148559. boolean force_baseline)
  148560. {
  148561. static const unsigned int std_luminance_quant_tbl[DCTSIZE2] = {
  148562. 16, 11, 10, 16, 24, 40, 51, 61,
  148563. 12, 12, 14, 19, 26, 58, 60, 55,
  148564. 14, 13, 16, 24, 40, 57, 69, 56,
  148565. 14, 17, 22, 29, 51, 87, 80, 62,
  148566. 18, 22, 37, 56, 68, 109, 103, 77,
  148567. 24, 35, 55, 64, 81, 104, 113, 92,
  148568. 49, 64, 78, 87, 103, 121, 120, 101,
  148569. 72, 92, 95, 98, 112, 100, 103, 99
  148570. };
  148571. static const unsigned int std_chrominance_quant_tbl[DCTSIZE2] = {
  148572. 17, 18, 24, 47, 99, 99, 99, 99,
  148573. 18, 21, 26, 66, 99, 99, 99, 99,
  148574. 24, 26, 56, 99, 99, 99, 99, 99,
  148575. 47, 66, 99, 99, 99, 99, 99, 99,
  148576. 99, 99, 99, 99, 99, 99, 99, 99,
  148577. 99, 99, 99, 99, 99, 99, 99, 99,
  148578. 99, 99, 99, 99, 99, 99, 99, 99,
  148579. 99, 99, 99, 99, 99, 99, 99, 99
  148580. };
  148581. jpeg_add_quant_table(cinfo, 0, std_luminance_quant_tbl,
  148582. scale_factor, force_baseline);
  148583. jpeg_add_quant_table(cinfo, 1, std_chrominance_quant_tbl,
  148584. scale_factor, force_baseline);
  148585. }
  148586. GLOBAL(int)
  148587. jpeg_quality_scaling (int quality)
  148588. {
  148589. if (quality <= 0) quality = 1;
  148590. if (quality > 100) quality = 100;
  148591. if (quality < 50)
  148592. quality = 5000 / quality;
  148593. else
  148594. quality = 200 - quality*2;
  148595. return quality;
  148596. }
  148597. GLOBAL(void)
  148598. jpeg_set_quality (j_compress_ptr cinfo, int quality, boolean force_baseline)
  148599. {
  148600. quality = jpeg_quality_scaling(quality);
  148601. jpeg_set_linear_quality(cinfo, quality, force_baseline);
  148602. }
  148603. LOCAL(void)
  148604. add_huff_table (j_compress_ptr cinfo,
  148605. JHUFF_TBL **htblptr, const UINT8 *bits, const UINT8 *val)
  148606. {
  148607. int nsymbols, len;
  148608. if (*htblptr == NULL)
  148609. *htblptr = jpeg_alloc_huff_table((j_common_ptr) cinfo);
  148610. MEMCOPY((*htblptr)->bits, bits, SIZEOF((*htblptr)->bits));
  148611. nsymbols = 0;
  148612. for (len = 1; len <= 16; len++)
  148613. nsymbols += bits[len];
  148614. if (nsymbols < 1 || nsymbols > 256)
  148615. ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
  148616. MEMCOPY((*htblptr)->huffval, val, nsymbols * SIZEOF(UINT8));
  148617. (*htblptr)->sent_table = FALSE;
  148618. }
  148619. LOCAL(void)
  148620. std_huff_tables (j_compress_ptr cinfo)
  148621. {
  148622. static const UINT8 bits_dc_luminance[17] =
  148623. { /* 0-base */ 0, 0, 1, 5, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0 };
  148624. static const UINT8 val_dc_luminance[] =
  148625. { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 };
  148626. static const UINT8 bits_dc_chrominance[17] =
  148627. { /* 0-base */ 0, 0, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0 };
  148628. static const UINT8 val_dc_chrominance[] =
  148629. { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 };
  148630. static const UINT8 bits_ac_luminance[17] =
  148631. { /* 0-base */ 0, 0, 2, 1, 3, 3, 2, 4, 3, 5, 5, 4, 4, 0, 0, 1, 0x7d };
  148632. static const UINT8 val_ac_luminance[] =
  148633. { 0x01, 0x02, 0x03, 0x00, 0x04, 0x11, 0x05, 0x12,
  148634. 0x21, 0x31, 0x41, 0x06, 0x13, 0x51, 0x61, 0x07,
  148635. 0x22, 0x71, 0x14, 0x32, 0x81, 0x91, 0xa1, 0x08,
  148636. 0x23, 0x42, 0xb1, 0xc1, 0x15, 0x52, 0xd1, 0xf0,
  148637. 0x24, 0x33, 0x62, 0x72, 0x82, 0x09, 0x0a, 0x16,
  148638. 0x17, 0x18, 0x19, 0x1a, 0x25, 0x26, 0x27, 0x28,
  148639. 0x29, 0x2a, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39,
  148640. 0x3a, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49,
  148641. 0x4a, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59,
  148642. 0x5a, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69,
  148643. 0x6a, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79,
  148644. 0x7a, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89,
  148645. 0x8a, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98,
  148646. 0x99, 0x9a, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7,
  148647. 0xa8, 0xa9, 0xaa, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6,
  148648. 0xb7, 0xb8, 0xb9, 0xba, 0xc2, 0xc3, 0xc4, 0xc5,
  148649. 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xd2, 0xd3, 0xd4,
  148650. 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda, 0xe1, 0xe2,
  148651. 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, 0xea,
  148652. 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8,
  148653. 0xf9, 0xfa };
  148654. static const UINT8 bits_ac_chrominance[17] =
  148655. { /* 0-base */ 0, 0, 2, 1, 2, 4, 4, 3, 4, 7, 5, 4, 4, 0, 1, 2, 0x77 };
  148656. static const UINT8 val_ac_chrominance[] =
  148657. { 0x00, 0x01, 0x02, 0x03, 0x11, 0x04, 0x05, 0x21,
  148658. 0x31, 0x06, 0x12, 0x41, 0x51, 0x07, 0x61, 0x71,
  148659. 0x13, 0x22, 0x32, 0x81, 0x08, 0x14, 0x42, 0x91,
  148660. 0xa1, 0xb1, 0xc1, 0x09, 0x23, 0x33, 0x52, 0xf0,
  148661. 0x15, 0x62, 0x72, 0xd1, 0x0a, 0x16, 0x24, 0x34,
  148662. 0xe1, 0x25, 0xf1, 0x17, 0x18, 0x19, 0x1a, 0x26,
  148663. 0x27, 0x28, 0x29, 0x2a, 0x35, 0x36, 0x37, 0x38,
  148664. 0x39, 0x3a, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48,
  148665. 0x49, 0x4a, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58,
  148666. 0x59, 0x5a, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68,
  148667. 0x69, 0x6a, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78,
  148668. 0x79, 0x7a, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87,
  148669. 0x88, 0x89, 0x8a, 0x92, 0x93, 0x94, 0x95, 0x96,
  148670. 0x97, 0x98, 0x99, 0x9a, 0xa2, 0xa3, 0xa4, 0xa5,
  148671. 0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xb2, 0xb3, 0xb4,
  148672. 0xb5, 0xb6, 0xb7, 0xb8, 0xb9, 0xba, 0xc2, 0xc3,
  148673. 0xc4, 0xc5, 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xd2,
  148674. 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda,
  148675. 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9,
  148676. 0xea, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8,
  148677. 0xf9, 0xfa };
  148678. add_huff_table(cinfo, &cinfo->dc_huff_tbl_ptrs[0],
  148679. bits_dc_luminance, val_dc_luminance);
  148680. add_huff_table(cinfo, &cinfo->ac_huff_tbl_ptrs[0],
  148681. bits_ac_luminance, val_ac_luminance);
  148682. add_huff_table(cinfo, &cinfo->dc_huff_tbl_ptrs[1],
  148683. bits_dc_chrominance, val_dc_chrominance);
  148684. add_huff_table(cinfo, &cinfo->ac_huff_tbl_ptrs[1],
  148685. bits_ac_chrominance, val_ac_chrominance);
  148686. }
  148687. GLOBAL(void)
  148688. jpeg_set_defaults (j_compress_ptr cinfo)
  148689. {
  148690. int i;
  148691. if (cinfo->global_state != CSTATE_START)
  148692. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  148693. if (cinfo->comp_info == NULL)
  148694. cinfo->comp_info = (jpeg_component_info *)
  148695. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
  148696. MAX_COMPONENTS * SIZEOF(jpeg_component_info));
  148697. cinfo->data_precision = BITS_IN_JSAMPLE;
  148698. jpeg_set_quality(cinfo, 75, TRUE);
  148699. std_huff_tables(cinfo);
  148700. for (i = 0; i < NUM_ARITH_TBLS; i++) {
  148701. cinfo->arith_dc_L[i] = 0;
  148702. cinfo->arith_dc_U[i] = 1;
  148703. cinfo->arith_ac_K[i] = 5;
  148704. }
  148705. cinfo->scan_info = NULL;
  148706. cinfo->num_scans = 0;
  148707. cinfo->raw_data_in = FALSE;
  148708. cinfo->arith_code = FALSE;
  148709. cinfo->optimize_coding = FALSE;
  148710. if (cinfo->data_precision > 8)
  148711. cinfo->optimize_coding = TRUE;
  148712. cinfo->CCIR601_sampling = FALSE;
  148713. cinfo->smoothing_factor = 0;
  148714. cinfo->dct_method = JDCT_DEFAULT;
  148715. cinfo->restart_interval = 0;
  148716. cinfo->restart_in_rows = 0;
  148717. cinfo->JFIF_major_version = 1; /* Default JFIF version = 1.01 */
  148718. cinfo->JFIF_minor_version = 1;
  148719. cinfo->density_unit = 0; /* Pixel size is unknown by default */
  148720. cinfo->X_density = 1; /* Pixel aspect ratio is square by default */
  148721. cinfo->Y_density = 1;
  148722. jpeg_default_colorspace(cinfo);
  148723. }
  148724. GLOBAL(void)
  148725. jpeg_default_colorspace (j_compress_ptr cinfo)
  148726. {
  148727. switch (cinfo->in_color_space) {
  148728. case JCS_GRAYSCALE:
  148729. jpeg_set_colorspace(cinfo, JCS_GRAYSCALE);
  148730. break;
  148731. case JCS_RGB:
  148732. jpeg_set_colorspace(cinfo, JCS_YCbCr);
  148733. break;
  148734. case JCS_YCbCr:
  148735. jpeg_set_colorspace(cinfo, JCS_YCbCr);
  148736. break;
  148737. case JCS_CMYK:
  148738. jpeg_set_colorspace(cinfo, JCS_CMYK); /* By default, no translation */
  148739. break;
  148740. case JCS_YCCK:
  148741. jpeg_set_colorspace(cinfo, JCS_YCCK);
  148742. break;
  148743. case JCS_UNKNOWN:
  148744. jpeg_set_colorspace(cinfo, JCS_UNKNOWN);
  148745. break;
  148746. default:
  148747. ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
  148748. }
  148749. }
  148750. GLOBAL(void)
  148751. jpeg_set_colorspace (j_compress_ptr cinfo, J_COLOR_SPACE colorspace)
  148752. {
  148753. jpeg_component_info * compptr;
  148754. int ci;
  148755. #define SET_COMP(index,id,hsamp,vsamp,quant,dctbl,actbl) \
  148756. (compptr = &cinfo->comp_info[index], \
  148757. compptr->component_id = (id), \
  148758. compptr->h_samp_factor = (hsamp), \
  148759. compptr->v_samp_factor = (vsamp), \
  148760. compptr->quant_tbl_no = (quant), \
  148761. compptr->dc_tbl_no = (dctbl), \
  148762. compptr->ac_tbl_no = (actbl) )
  148763. if (cinfo->global_state != CSTATE_START)
  148764. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  148765. cinfo->jpeg_color_space = colorspace;
  148766. cinfo->write_JFIF_header = FALSE; /* No marker for non-JFIF colorspaces */
  148767. cinfo->write_Adobe_marker = FALSE; /* write no Adobe marker by default */
  148768. switch (colorspace) {
  148769. case JCS_GRAYSCALE:
  148770. cinfo->write_JFIF_header = TRUE; /* Write a JFIF marker */
  148771. cinfo->num_components = 1;
  148772. SET_COMP(0, 1, 1,1, 0, 0,0);
  148773. break;
  148774. case JCS_RGB:
  148775. cinfo->write_Adobe_marker = TRUE; /* write Adobe marker to flag RGB */
  148776. cinfo->num_components = 3;
  148777. SET_COMP(0, 0x52 /* 'R' */, 1,1, 0, 0,0);
  148778. SET_COMP(1, 0x47 /* 'G' */, 1,1, 0, 0,0);
  148779. SET_COMP(2, 0x42 /* 'B' */, 1,1, 0, 0,0);
  148780. break;
  148781. case JCS_YCbCr:
  148782. cinfo->write_JFIF_header = TRUE; /* Write a JFIF marker */
  148783. cinfo->num_components = 3;
  148784. SET_COMP(0, 1, 2,2, 0, 0,0);
  148785. SET_COMP(1, 2, 1,1, 1, 1,1);
  148786. SET_COMP(2, 3, 1,1, 1, 1,1);
  148787. break;
  148788. case JCS_CMYK:
  148789. cinfo->write_Adobe_marker = TRUE; /* write Adobe marker to flag CMYK */
  148790. cinfo->num_components = 4;
  148791. SET_COMP(0, 0x43 /* 'C' */, 1,1, 0, 0,0);
  148792. SET_COMP(1, 0x4D /* 'M' */, 1,1, 0, 0,0);
  148793. SET_COMP(2, 0x59 /* 'Y' */, 1,1, 0, 0,0);
  148794. SET_COMP(3, 0x4B /* 'K' */, 1,1, 0, 0,0);
  148795. break;
  148796. case JCS_YCCK:
  148797. cinfo->write_Adobe_marker = TRUE; /* write Adobe marker to flag YCCK */
  148798. cinfo->num_components = 4;
  148799. SET_COMP(0, 1, 2,2, 0, 0,0);
  148800. SET_COMP(1, 2, 1,1, 1, 1,1);
  148801. SET_COMP(2, 3, 1,1, 1, 1,1);
  148802. SET_COMP(3, 4, 2,2, 0, 0,0);
  148803. break;
  148804. case JCS_UNKNOWN:
  148805. cinfo->num_components = cinfo->input_components;
  148806. if (cinfo->num_components < 1 || cinfo->num_components > MAX_COMPONENTS)
  148807. ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->num_components,
  148808. MAX_COMPONENTS);
  148809. for (ci = 0; ci < cinfo->num_components; ci++) {
  148810. SET_COMP(ci, ci, 1,1, 0, 0,0);
  148811. }
  148812. break;
  148813. default:
  148814. ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
  148815. }
  148816. }
  148817. #ifdef C_PROGRESSIVE_SUPPORTED
  148818. LOCAL(jpeg_scan_info *)
  148819. fill_a_scan (jpeg_scan_info * scanptr, int ci,
  148820. int Ss, int Se, int Ah, int Al)
  148821. {
  148822. scanptr->comps_in_scan = 1;
  148823. scanptr->component_index[0] = ci;
  148824. scanptr->Ss = Ss;
  148825. scanptr->Se = Se;
  148826. scanptr->Ah = Ah;
  148827. scanptr->Al = Al;
  148828. scanptr++;
  148829. return scanptr;
  148830. }
  148831. LOCAL(jpeg_scan_info *)
  148832. fill_scans (jpeg_scan_info * scanptr, int ncomps,
  148833. int Ss, int Se, int Ah, int Al)
  148834. {
  148835. int ci;
  148836. for (ci = 0; ci < ncomps; ci++) {
  148837. scanptr->comps_in_scan = 1;
  148838. scanptr->component_index[0] = ci;
  148839. scanptr->Ss = Ss;
  148840. scanptr->Se = Se;
  148841. scanptr->Ah = Ah;
  148842. scanptr->Al = Al;
  148843. scanptr++;
  148844. }
  148845. return scanptr;
  148846. }
  148847. LOCAL(jpeg_scan_info *)
  148848. fill_dc_scans (jpeg_scan_info * scanptr, int ncomps, int Ah, int Al)
  148849. {
  148850. int ci;
  148851. if (ncomps <= MAX_COMPS_IN_SCAN) {
  148852. scanptr->comps_in_scan = ncomps;
  148853. for (ci = 0; ci < ncomps; ci++)
  148854. scanptr->component_index[ci] = ci;
  148855. scanptr->Ss = scanptr->Se = 0;
  148856. scanptr->Ah = Ah;
  148857. scanptr->Al = Al;
  148858. scanptr++;
  148859. } else {
  148860. scanptr = fill_scans(scanptr, ncomps, 0, 0, Ah, Al);
  148861. }
  148862. return scanptr;
  148863. }
  148864. GLOBAL(void)
  148865. jpeg_simple_progression (j_compress_ptr cinfo)
  148866. {
  148867. int ncomps = cinfo->num_components;
  148868. int nscans;
  148869. jpeg_scan_info * scanptr;
  148870. if (cinfo->global_state != CSTATE_START)
  148871. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  148872. if (ncomps == 3 && cinfo->jpeg_color_space == JCS_YCbCr) {
  148873. nscans = 10;
  148874. } else {
  148875. if (ncomps > MAX_COMPS_IN_SCAN)
  148876. nscans = 6 * ncomps; /* 2 DC + 4 AC scans per component */
  148877. else
  148878. nscans = 2 + 4 * ncomps; /* 2 DC scans; 4 AC scans per component */
  148879. }
  148880. if (cinfo->script_space == NULL || cinfo->script_space_size < nscans) {
  148881. cinfo->script_space_size = MAX(nscans, 10);
  148882. cinfo->script_space = (jpeg_scan_info *)
  148883. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
  148884. cinfo->script_space_size * SIZEOF(jpeg_scan_info));
  148885. }
  148886. scanptr = cinfo->script_space;
  148887. cinfo->scan_info = scanptr;
  148888. cinfo->num_scans = nscans;
  148889. if (ncomps == 3 && cinfo->jpeg_color_space == JCS_YCbCr) {
  148890. scanptr = fill_dc_scans(scanptr, ncomps, 0, 1);
  148891. scanptr = fill_a_scan(scanptr, 0, 1, 5, 0, 2);
  148892. scanptr = fill_a_scan(scanptr, 2, 1, 63, 0, 1);
  148893. scanptr = fill_a_scan(scanptr, 1, 1, 63, 0, 1);
  148894. scanptr = fill_a_scan(scanptr, 0, 6, 63, 0, 2);
  148895. scanptr = fill_a_scan(scanptr, 0, 1, 63, 2, 1);
  148896. scanptr = fill_dc_scans(scanptr, ncomps, 1, 0);
  148897. scanptr = fill_a_scan(scanptr, 2, 1, 63, 1, 0);
  148898. scanptr = fill_a_scan(scanptr, 1, 1, 63, 1, 0);
  148899. scanptr = fill_a_scan(scanptr, 0, 1, 63, 1, 0);
  148900. } else {
  148901. scanptr = fill_dc_scans(scanptr, ncomps, 0, 1);
  148902. scanptr = fill_scans(scanptr, ncomps, 1, 5, 0, 2);
  148903. scanptr = fill_scans(scanptr, ncomps, 6, 63, 0, 2);
  148904. scanptr = fill_scans(scanptr, ncomps, 1, 63, 2, 1);
  148905. scanptr = fill_dc_scans(scanptr, ncomps, 1, 0);
  148906. scanptr = fill_scans(scanptr, ncomps, 1, 63, 1, 0);
  148907. }
  148908. }
  148909. #endif /* C_PROGRESSIVE_SUPPORTED */
  148910. /*** End of inlined file: jcparam.c ***/
  148911. /*** Start of inlined file: jcphuff.c ***/
  148912. #define JPEG_INTERNALS
  148913. #ifdef C_PROGRESSIVE_SUPPORTED
  148914. typedef struct {
  148915. struct jpeg_entropy_encoder pub; /* public fields */
  148916. boolean gather_statistics;
  148917. JOCTET * next_output_byte; /* => next byte to write in buffer */
  148918. size_t free_in_buffer; /* # of byte spaces remaining in buffer */
  148919. INT32 put_buffer; /* current bit-accumulation buffer */
  148920. int put_bits; /* # of bits now in it */
  148921. j_compress_ptr cinfo; /* link to cinfo (needed for dump_buffer) */
  148922. int last_dc_val[MAX_COMPS_IN_SCAN]; /* last DC coef for each component */
  148923. int ac_tbl_no; /* the table number of the single component */
  148924. unsigned int EOBRUN; /* run length of EOBs */
  148925. unsigned int BE; /* # of buffered correction bits before MCU */
  148926. char * bit_buffer; /* buffer for correction bits (1 per char) */
  148927. unsigned int restarts_to_go; /* MCUs left in this restart interval */
  148928. int next_restart_num; /* next restart number to write (0-7) */
  148929. c_derived_tbl * derived_tbls[NUM_HUFF_TBLS];
  148930. long * count_ptrs[NUM_HUFF_TBLS];
  148931. } phuff_entropy_encoder;
  148932. typedef phuff_entropy_encoder * phuff_entropy_ptr;
  148933. #define MAX_CORR_BITS 1000 /* Max # of correction bits I can buffer */
  148934. #ifdef RIGHT_SHIFT_IS_UNSIGNED
  148935. #define ISHIFT_TEMPS int ishift_temp;
  148936. #define IRIGHT_SHIFT(x,shft) \
  148937. ((ishift_temp = (x)) < 0 ? \
  148938. (ishift_temp >> (shft)) | ((~0) << (16-(shft))) : \
  148939. (ishift_temp >> (shft)))
  148940. #else
  148941. #define ISHIFT_TEMPS
  148942. #define IRIGHT_SHIFT(x,shft) ((x) >> (shft))
  148943. #endif
  148944. METHODDEF(boolean) encode_mcu_DC_first JPP((j_compress_ptr cinfo,
  148945. JBLOCKROW *MCU_data));
  148946. METHODDEF(boolean) encode_mcu_AC_first JPP((j_compress_ptr cinfo,
  148947. JBLOCKROW *MCU_data));
  148948. METHODDEF(boolean) encode_mcu_DC_refine JPP((j_compress_ptr cinfo,
  148949. JBLOCKROW *MCU_data));
  148950. METHODDEF(boolean) encode_mcu_AC_refine JPP((j_compress_ptr cinfo,
  148951. JBLOCKROW *MCU_data));
  148952. METHODDEF(void) finish_pass_phuff JPP((j_compress_ptr cinfo));
  148953. METHODDEF(void) finish_pass_gather_phuff JPP((j_compress_ptr cinfo));
  148954. METHODDEF(void)
  148955. start_pass_phuff (j_compress_ptr cinfo, boolean gather_statistics)
  148956. {
  148957. phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
  148958. boolean is_DC_band;
  148959. int ci, tbl;
  148960. jpeg_component_info * compptr;
  148961. entropy->cinfo = cinfo;
  148962. entropy->gather_statistics = gather_statistics;
  148963. is_DC_band = (cinfo->Ss == 0);
  148964. if (cinfo->Ah == 0) {
  148965. if (is_DC_band)
  148966. entropy->pub.encode_mcu = encode_mcu_DC_first;
  148967. else
  148968. entropy->pub.encode_mcu = encode_mcu_AC_first;
  148969. } else {
  148970. if (is_DC_band)
  148971. entropy->pub.encode_mcu = encode_mcu_DC_refine;
  148972. else {
  148973. entropy->pub.encode_mcu = encode_mcu_AC_refine;
  148974. if (entropy->bit_buffer == NULL)
  148975. entropy->bit_buffer = (char *)
  148976. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  148977. MAX_CORR_BITS * SIZEOF(char));
  148978. }
  148979. }
  148980. if (gather_statistics)
  148981. entropy->pub.finish_pass = finish_pass_gather_phuff;
  148982. else
  148983. entropy->pub.finish_pass = finish_pass_phuff;
  148984. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  148985. compptr = cinfo->cur_comp_info[ci];
  148986. entropy->last_dc_val[ci] = 0;
  148987. if (is_DC_band) {
  148988. if (cinfo->Ah != 0) /* DC refinement needs no table */
  148989. continue;
  148990. tbl = compptr->dc_tbl_no;
  148991. } else {
  148992. entropy->ac_tbl_no = tbl = compptr->ac_tbl_no;
  148993. }
  148994. if (gather_statistics) {
  148995. if (tbl < 0 || tbl >= NUM_HUFF_TBLS)
  148996. ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, tbl);
  148997. if (entropy->count_ptrs[tbl] == NULL)
  148998. entropy->count_ptrs[tbl] = (long *)
  148999. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  149000. 257 * SIZEOF(long));
  149001. MEMZERO(entropy->count_ptrs[tbl], 257 * SIZEOF(long));
  149002. } else {
  149003. jpeg_make_c_derived_tbl(cinfo, is_DC_band, tbl,
  149004. & entropy->derived_tbls[tbl]);
  149005. }
  149006. }
  149007. entropy->EOBRUN = 0;
  149008. entropy->BE = 0;
  149009. entropy->put_buffer = 0;
  149010. entropy->put_bits = 0;
  149011. entropy->restarts_to_go = cinfo->restart_interval;
  149012. entropy->next_restart_num = 0;
  149013. }
  149014. #define emit_byte(entropy,val) \
  149015. { *(entropy)->next_output_byte++ = (JOCTET) (val); \
  149016. if (--(entropy)->free_in_buffer == 0) \
  149017. dump_buffer_p(entropy); }
  149018. LOCAL(void)
  149019. dump_buffer_p (phuff_entropy_ptr entropy)
  149020. {
  149021. struct jpeg_destination_mgr * dest = entropy->cinfo->dest;
  149022. if (! (*dest->empty_output_buffer) (entropy->cinfo))
  149023. ERREXIT(entropy->cinfo, JERR_CANT_SUSPEND);
  149024. entropy->next_output_byte = dest->next_output_byte;
  149025. entropy->free_in_buffer = dest->free_in_buffer;
  149026. }
  149027. INLINE
  149028. LOCAL(void)
  149029. emit_bits_p (phuff_entropy_ptr entropy, unsigned int code, int size)
  149030. {
  149031. register INT32 put_buffer = (INT32) code;
  149032. register int put_bits = entropy->put_bits;
  149033. if (size == 0)
  149034. ERREXIT(entropy->cinfo, JERR_HUFF_MISSING_CODE);
  149035. if (entropy->gather_statistics)
  149036. return; /* do nothing if we're only getting stats */
  149037. put_buffer &= (((INT32) 1)<<size) - 1; /* mask off any extra bits in code */
  149038. put_bits += size; /* new number of bits in buffer */
  149039. put_buffer <<= 24 - put_bits; /* align incoming bits */
  149040. put_buffer |= entropy->put_buffer; /* and merge with old buffer contents */
  149041. while (put_bits >= 8) {
  149042. int c = (int) ((put_buffer >> 16) & 0xFF);
  149043. emit_byte(entropy, c);
  149044. if (c == 0xFF) { /* need to stuff a zero byte? */
  149045. emit_byte(entropy, 0);
  149046. }
  149047. put_buffer <<= 8;
  149048. put_bits -= 8;
  149049. }
  149050. entropy->put_buffer = put_buffer; /* update variables */
  149051. entropy->put_bits = put_bits;
  149052. }
  149053. LOCAL(void)
  149054. flush_bits_p (phuff_entropy_ptr entropy)
  149055. {
  149056. emit_bits_p(entropy, 0x7F, 7); /* fill any partial byte with ones */
  149057. entropy->put_buffer = 0; /* and reset bit-buffer to empty */
  149058. entropy->put_bits = 0;
  149059. }
  149060. INLINE
  149061. LOCAL(void)
  149062. emit_symbol (phuff_entropy_ptr entropy, int tbl_no, int symbol)
  149063. {
  149064. if (entropy->gather_statistics)
  149065. entropy->count_ptrs[tbl_no][symbol]++;
  149066. else {
  149067. c_derived_tbl * tbl = entropy->derived_tbls[tbl_no];
  149068. emit_bits_p(entropy, tbl->ehufco[symbol], tbl->ehufsi[symbol]);
  149069. }
  149070. }
  149071. LOCAL(void)
  149072. emit_buffered_bits (phuff_entropy_ptr entropy, char * bufstart,
  149073. unsigned int nbits)
  149074. {
  149075. if (entropy->gather_statistics)
  149076. return; /* no real work */
  149077. while (nbits > 0) {
  149078. emit_bits_p(entropy, (unsigned int) (*bufstart), 1);
  149079. bufstart++;
  149080. nbits--;
  149081. }
  149082. }
  149083. LOCAL(void)
  149084. emit_eobrun (phuff_entropy_ptr entropy)
  149085. {
  149086. register int temp, nbits;
  149087. if (entropy->EOBRUN > 0) { /* if there is any pending EOBRUN */
  149088. temp = entropy->EOBRUN;
  149089. nbits = 0;
  149090. while ((temp >>= 1))
  149091. nbits++;
  149092. if (nbits > 14)
  149093. ERREXIT(entropy->cinfo, JERR_HUFF_MISSING_CODE);
  149094. emit_symbol(entropy, entropy->ac_tbl_no, nbits << 4);
  149095. if (nbits)
  149096. emit_bits_p(entropy, entropy->EOBRUN, nbits);
  149097. entropy->EOBRUN = 0;
  149098. emit_buffered_bits(entropy, entropy->bit_buffer, entropy->BE);
  149099. entropy->BE = 0;
  149100. }
  149101. }
  149102. LOCAL(void)
  149103. emit_restart_p (phuff_entropy_ptr entropy, int restart_num)
  149104. {
  149105. int ci;
  149106. emit_eobrun(entropy);
  149107. if (! entropy->gather_statistics) {
  149108. flush_bits_p(entropy);
  149109. emit_byte(entropy, 0xFF);
  149110. emit_byte(entropy, JPEG_RST0 + restart_num);
  149111. }
  149112. if (entropy->cinfo->Ss == 0) {
  149113. for (ci = 0; ci < entropy->cinfo->comps_in_scan; ci++)
  149114. entropy->last_dc_val[ci] = 0;
  149115. } else {
  149116. entropy->EOBRUN = 0;
  149117. entropy->BE = 0;
  149118. }
  149119. }
  149120. METHODDEF(boolean)
  149121. encode_mcu_DC_first (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
  149122. {
  149123. phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
  149124. register int temp, temp2;
  149125. register int nbits;
  149126. int blkn, ci;
  149127. int Al = cinfo->Al;
  149128. JBLOCKROW block;
  149129. jpeg_component_info * compptr;
  149130. ISHIFT_TEMPS
  149131. entropy->next_output_byte = cinfo->dest->next_output_byte;
  149132. entropy->free_in_buffer = cinfo->dest->free_in_buffer;
  149133. if (cinfo->restart_interval)
  149134. if (entropy->restarts_to_go == 0)
  149135. emit_restart_p(entropy, entropy->next_restart_num);
  149136. for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
  149137. block = MCU_data[blkn];
  149138. ci = cinfo->MCU_membership[blkn];
  149139. compptr = cinfo->cur_comp_info[ci];
  149140. temp2 = IRIGHT_SHIFT((int) ((*block)[0]), Al);
  149141. temp = temp2 - entropy->last_dc_val[ci];
  149142. entropy->last_dc_val[ci] = temp2;
  149143. temp2 = temp;
  149144. if (temp < 0) {
  149145. temp = -temp; /* temp is abs value of input */
  149146. temp2--;
  149147. }
  149148. nbits = 0;
  149149. while (temp) {
  149150. nbits++;
  149151. temp >>= 1;
  149152. }
  149153. if (nbits > MAX_COEF_BITS+1)
  149154. ERREXIT(cinfo, JERR_BAD_DCT_COEF);
  149155. emit_symbol(entropy, compptr->dc_tbl_no, nbits);
  149156. if (nbits) /* emit_bits rejects calls with size 0 */
  149157. emit_bits_p(entropy, (unsigned int) temp2, nbits);
  149158. }
  149159. cinfo->dest->next_output_byte = entropy->next_output_byte;
  149160. cinfo->dest->free_in_buffer = entropy->free_in_buffer;
  149161. if (cinfo->restart_interval) {
  149162. if (entropy->restarts_to_go == 0) {
  149163. entropy->restarts_to_go = cinfo->restart_interval;
  149164. entropy->next_restart_num++;
  149165. entropy->next_restart_num &= 7;
  149166. }
  149167. entropy->restarts_to_go--;
  149168. }
  149169. return TRUE;
  149170. }
  149171. METHODDEF(boolean)
  149172. encode_mcu_AC_first (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
  149173. {
  149174. phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
  149175. register int temp, temp2;
  149176. register int nbits;
  149177. register int r, k;
  149178. int Se = cinfo->Se;
  149179. int Al = cinfo->Al;
  149180. JBLOCKROW block;
  149181. entropy->next_output_byte = cinfo->dest->next_output_byte;
  149182. entropy->free_in_buffer = cinfo->dest->free_in_buffer;
  149183. if (cinfo->restart_interval)
  149184. if (entropy->restarts_to_go == 0)
  149185. emit_restart_p(entropy, entropy->next_restart_num);
  149186. block = MCU_data[0];
  149187. r = 0; /* r = run length of zeros */
  149188. for (k = cinfo->Ss; k <= Se; k++) {
  149189. if ((temp = (*block)[jpeg_natural_order[k]]) == 0) {
  149190. r++;
  149191. continue;
  149192. }
  149193. if (temp < 0) {
  149194. temp = -temp; /* temp is abs value of input */
  149195. temp >>= Al; /* apply the point transform */
  149196. temp2 = ~temp;
  149197. } else {
  149198. temp >>= Al; /* apply the point transform */
  149199. temp2 = temp;
  149200. }
  149201. if (temp == 0) {
  149202. r++;
  149203. continue;
  149204. }
  149205. if (entropy->EOBRUN > 0)
  149206. emit_eobrun(entropy);
  149207. while (r > 15) {
  149208. emit_symbol(entropy, entropy->ac_tbl_no, 0xF0);
  149209. r -= 16;
  149210. }
  149211. nbits = 1; /* there must be at least one 1 bit */
  149212. while ((temp >>= 1))
  149213. nbits++;
  149214. if (nbits > MAX_COEF_BITS)
  149215. ERREXIT(cinfo, JERR_BAD_DCT_COEF);
  149216. emit_symbol(entropy, entropy->ac_tbl_no, (r << 4) + nbits);
  149217. emit_bits_p(entropy, (unsigned int) temp2, nbits);
  149218. r = 0; /* reset zero run length */
  149219. }
  149220. if (r > 0) { /* If there are trailing zeroes, */
  149221. entropy->EOBRUN++; /* count an EOB */
  149222. if (entropy->EOBRUN == 0x7FFF)
  149223. emit_eobrun(entropy); /* force it out to avoid overflow */
  149224. }
  149225. cinfo->dest->next_output_byte = entropy->next_output_byte;
  149226. cinfo->dest->free_in_buffer = entropy->free_in_buffer;
  149227. if (cinfo->restart_interval) {
  149228. if (entropy->restarts_to_go == 0) {
  149229. entropy->restarts_to_go = cinfo->restart_interval;
  149230. entropy->next_restart_num++;
  149231. entropy->next_restart_num &= 7;
  149232. }
  149233. entropy->restarts_to_go--;
  149234. }
  149235. return TRUE;
  149236. }
  149237. METHODDEF(boolean)
  149238. encode_mcu_DC_refine (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
  149239. {
  149240. phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
  149241. register int temp;
  149242. int blkn;
  149243. int Al = cinfo->Al;
  149244. JBLOCKROW block;
  149245. entropy->next_output_byte = cinfo->dest->next_output_byte;
  149246. entropy->free_in_buffer = cinfo->dest->free_in_buffer;
  149247. if (cinfo->restart_interval)
  149248. if (entropy->restarts_to_go == 0)
  149249. emit_restart_p(entropy, entropy->next_restart_num);
  149250. for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
  149251. block = MCU_data[blkn];
  149252. temp = (*block)[0];
  149253. emit_bits_p(entropy, (unsigned int) (temp >> Al), 1);
  149254. }
  149255. cinfo->dest->next_output_byte = entropy->next_output_byte;
  149256. cinfo->dest->free_in_buffer = entropy->free_in_buffer;
  149257. if (cinfo->restart_interval) {
  149258. if (entropy->restarts_to_go == 0) {
  149259. entropy->restarts_to_go = cinfo->restart_interval;
  149260. entropy->next_restart_num++;
  149261. entropy->next_restart_num &= 7;
  149262. }
  149263. entropy->restarts_to_go--;
  149264. }
  149265. return TRUE;
  149266. }
  149267. METHODDEF(boolean)
  149268. encode_mcu_AC_refine (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
  149269. {
  149270. phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
  149271. register int temp;
  149272. register int r, k;
  149273. int EOB;
  149274. char *BR_buffer;
  149275. unsigned int BR;
  149276. int Se = cinfo->Se;
  149277. int Al = cinfo->Al;
  149278. JBLOCKROW block;
  149279. int absvalues[DCTSIZE2];
  149280. entropy->next_output_byte = cinfo->dest->next_output_byte;
  149281. entropy->free_in_buffer = cinfo->dest->free_in_buffer;
  149282. if (cinfo->restart_interval)
  149283. if (entropy->restarts_to_go == 0)
  149284. emit_restart_p(entropy, entropy->next_restart_num);
  149285. block = MCU_data[0];
  149286. EOB = 0;
  149287. for (k = cinfo->Ss; k <= Se; k++) {
  149288. temp = (*block)[jpeg_natural_order[k]];
  149289. if (temp < 0)
  149290. temp = -temp; /* temp is abs value of input */
  149291. temp >>= Al; /* apply the point transform */
  149292. absvalues[k] = temp; /* save abs value for main pass */
  149293. if (temp == 1)
  149294. EOB = k; /* EOB = index of last newly-nonzero coef */
  149295. }
  149296. r = 0; /* r = run length of zeros */
  149297. BR = 0; /* BR = count of buffered bits added now */
  149298. BR_buffer = entropy->bit_buffer + entropy->BE; /* Append bits to buffer */
  149299. for (k = cinfo->Ss; k <= Se; k++) {
  149300. if ((temp = absvalues[k]) == 0) {
  149301. r++;
  149302. continue;
  149303. }
  149304. while (r > 15 && k <= EOB) {
  149305. emit_eobrun(entropy);
  149306. emit_symbol(entropy, entropy->ac_tbl_no, 0xF0);
  149307. r -= 16;
  149308. emit_buffered_bits(entropy, BR_buffer, BR);
  149309. BR_buffer = entropy->bit_buffer; /* BE bits are gone now */
  149310. BR = 0;
  149311. }
  149312. if (temp > 1) {
  149313. BR_buffer[BR++] = (char) (temp & 1);
  149314. continue;
  149315. }
  149316. emit_eobrun(entropy);
  149317. emit_symbol(entropy, entropy->ac_tbl_no, (r << 4) + 1);
  149318. temp = ((*block)[jpeg_natural_order[k]] < 0) ? 0 : 1;
  149319. emit_bits_p(entropy, (unsigned int) temp, 1);
  149320. emit_buffered_bits(entropy, BR_buffer, BR);
  149321. BR_buffer = entropy->bit_buffer; /* BE bits are gone now */
  149322. BR = 0;
  149323. r = 0; /* reset zero run length */
  149324. }
  149325. if (r > 0 || BR > 0) { /* If there are trailing zeroes, */
  149326. entropy->EOBRUN++; /* count an EOB */
  149327. entropy->BE += BR; /* concat my correction bits to older ones */
  149328. if (entropy->EOBRUN == 0x7FFF || entropy->BE > (MAX_CORR_BITS-DCTSIZE2+1))
  149329. emit_eobrun(entropy);
  149330. }
  149331. cinfo->dest->next_output_byte = entropy->next_output_byte;
  149332. cinfo->dest->free_in_buffer = entropy->free_in_buffer;
  149333. if (cinfo->restart_interval) {
  149334. if (entropy->restarts_to_go == 0) {
  149335. entropy->restarts_to_go = cinfo->restart_interval;
  149336. entropy->next_restart_num++;
  149337. entropy->next_restart_num &= 7;
  149338. }
  149339. entropy->restarts_to_go--;
  149340. }
  149341. return TRUE;
  149342. }
  149343. METHODDEF(void)
  149344. finish_pass_phuff (j_compress_ptr cinfo)
  149345. {
  149346. phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
  149347. entropy->next_output_byte = cinfo->dest->next_output_byte;
  149348. entropy->free_in_buffer = cinfo->dest->free_in_buffer;
  149349. emit_eobrun(entropy);
  149350. flush_bits_p(entropy);
  149351. cinfo->dest->next_output_byte = entropy->next_output_byte;
  149352. cinfo->dest->free_in_buffer = entropy->free_in_buffer;
  149353. }
  149354. METHODDEF(void)
  149355. finish_pass_gather_phuff (j_compress_ptr cinfo)
  149356. {
  149357. phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
  149358. boolean is_DC_band;
  149359. int ci, tbl;
  149360. jpeg_component_info * compptr;
  149361. JHUFF_TBL **htblptr;
  149362. boolean did[NUM_HUFF_TBLS];
  149363. emit_eobrun(entropy);
  149364. is_DC_band = (cinfo->Ss == 0);
  149365. MEMZERO(did, SIZEOF(did));
  149366. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  149367. compptr = cinfo->cur_comp_info[ci];
  149368. if (is_DC_band) {
  149369. if (cinfo->Ah != 0) /* DC refinement needs no table */
  149370. continue;
  149371. tbl = compptr->dc_tbl_no;
  149372. } else {
  149373. tbl = compptr->ac_tbl_no;
  149374. }
  149375. if (! did[tbl]) {
  149376. if (is_DC_band)
  149377. htblptr = & cinfo->dc_huff_tbl_ptrs[tbl];
  149378. else
  149379. htblptr = & cinfo->ac_huff_tbl_ptrs[tbl];
  149380. if (*htblptr == NULL)
  149381. *htblptr = jpeg_alloc_huff_table((j_common_ptr) cinfo);
  149382. jpeg_gen_optimal_table(cinfo, *htblptr, entropy->count_ptrs[tbl]);
  149383. did[tbl] = TRUE;
  149384. }
  149385. }
  149386. }
  149387. GLOBAL(void)
  149388. jinit_phuff_encoder (j_compress_ptr cinfo)
  149389. {
  149390. phuff_entropy_ptr entropy;
  149391. int i;
  149392. entropy = (phuff_entropy_ptr)
  149393. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  149394. SIZEOF(phuff_entropy_encoder));
  149395. cinfo->entropy = (struct jpeg_entropy_encoder *) entropy;
  149396. entropy->pub.start_pass = start_pass_phuff;
  149397. for (i = 0; i < NUM_HUFF_TBLS; i++) {
  149398. entropy->derived_tbls[i] = NULL;
  149399. entropy->count_ptrs[i] = NULL;
  149400. }
  149401. entropy->bit_buffer = NULL; /* needed only in AC refinement scan */
  149402. }
  149403. #endif /* C_PROGRESSIVE_SUPPORTED */
  149404. /*** End of inlined file: jcphuff.c ***/
  149405. /*** Start of inlined file: jcprepct.c ***/
  149406. #define JPEG_INTERNALS
  149407. #ifdef INPUT_SMOOTHING_SUPPORTED
  149408. #define CONTEXT_ROWS_SUPPORTED
  149409. #endif
  149410. typedef struct {
  149411. struct jpeg_c_prep_controller pub; /* public fields */
  149412. JSAMPARRAY color_buf[MAX_COMPONENTS];
  149413. JDIMENSION rows_to_go; /* counts rows remaining in source image */
  149414. int next_buf_row; /* index of next row to store in color_buf */
  149415. #ifdef CONTEXT_ROWS_SUPPORTED /* only needed for context case */
  149416. int this_row_group; /* starting row index of group to process */
  149417. int next_buf_stop; /* downsample when we reach this index */
  149418. #endif
  149419. } my_prep_controller;
  149420. typedef my_prep_controller * my_prep_ptr;
  149421. METHODDEF(void)
  149422. start_pass_prep (j_compress_ptr cinfo, J_BUF_MODE pass_mode)
  149423. {
  149424. my_prep_ptr prep = (my_prep_ptr) cinfo->prep;
  149425. if (pass_mode != JBUF_PASS_THRU)
  149426. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  149427. prep->rows_to_go = cinfo->image_height;
  149428. prep->next_buf_row = 0;
  149429. #ifdef CONTEXT_ROWS_SUPPORTED
  149430. prep->this_row_group = 0;
  149431. prep->next_buf_stop = 2 * cinfo->max_v_samp_factor;
  149432. #endif
  149433. }
  149434. LOCAL(void)
  149435. expand_bottom_edge (JSAMPARRAY image_data, JDIMENSION num_cols,
  149436. int input_rows, int output_rows)
  149437. {
  149438. register int row;
  149439. for (row = input_rows; row < output_rows; row++) {
  149440. jcopy_sample_rows(image_data, input_rows-1, image_data, row,
  149441. 1, num_cols);
  149442. }
  149443. }
  149444. METHODDEF(void)
  149445. pre_process_data (j_compress_ptr cinfo,
  149446. JSAMPARRAY input_buf, JDIMENSION *in_row_ctr,
  149447. JDIMENSION in_rows_avail,
  149448. JSAMPIMAGE output_buf, JDIMENSION *out_row_group_ctr,
  149449. JDIMENSION out_row_groups_avail)
  149450. {
  149451. my_prep_ptr prep = (my_prep_ptr) cinfo->prep;
  149452. int numrows, ci;
  149453. JDIMENSION inrows;
  149454. jpeg_component_info * compptr;
  149455. while (*in_row_ctr < in_rows_avail &&
  149456. *out_row_group_ctr < out_row_groups_avail) {
  149457. inrows = in_rows_avail - *in_row_ctr;
  149458. numrows = cinfo->max_v_samp_factor - prep->next_buf_row;
  149459. numrows = (int) MIN((JDIMENSION) numrows, inrows);
  149460. (*cinfo->cconvert->color_convert) (cinfo, input_buf + *in_row_ctr,
  149461. prep->color_buf,
  149462. (JDIMENSION) prep->next_buf_row,
  149463. numrows);
  149464. *in_row_ctr += numrows;
  149465. prep->next_buf_row += numrows;
  149466. prep->rows_to_go -= numrows;
  149467. if (prep->rows_to_go == 0 &&
  149468. prep->next_buf_row < cinfo->max_v_samp_factor) {
  149469. for (ci = 0; ci < cinfo->num_components; ci++) {
  149470. expand_bottom_edge(prep->color_buf[ci], cinfo->image_width,
  149471. prep->next_buf_row, cinfo->max_v_samp_factor);
  149472. }
  149473. prep->next_buf_row = cinfo->max_v_samp_factor;
  149474. }
  149475. if (prep->next_buf_row == cinfo->max_v_samp_factor) {
  149476. (*cinfo->downsample->downsample) (cinfo,
  149477. prep->color_buf, (JDIMENSION) 0,
  149478. output_buf, *out_row_group_ctr);
  149479. prep->next_buf_row = 0;
  149480. (*out_row_group_ctr)++;
  149481. }
  149482. if (prep->rows_to_go == 0 &&
  149483. *out_row_group_ctr < out_row_groups_avail) {
  149484. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  149485. ci++, compptr++) {
  149486. expand_bottom_edge(output_buf[ci],
  149487. compptr->width_in_blocks * DCTSIZE,
  149488. (int) (*out_row_group_ctr * compptr->v_samp_factor),
  149489. (int) (out_row_groups_avail * compptr->v_samp_factor));
  149490. }
  149491. *out_row_group_ctr = out_row_groups_avail;
  149492. break; /* can exit outer loop without test */
  149493. }
  149494. }
  149495. }
  149496. #ifdef CONTEXT_ROWS_SUPPORTED
  149497. METHODDEF(void)
  149498. pre_process_context (j_compress_ptr cinfo,
  149499. JSAMPARRAY input_buf, JDIMENSION *in_row_ctr,
  149500. JDIMENSION in_rows_avail,
  149501. JSAMPIMAGE output_buf, JDIMENSION *out_row_group_ctr,
  149502. JDIMENSION out_row_groups_avail)
  149503. {
  149504. my_prep_ptr prep = (my_prep_ptr) cinfo->prep;
  149505. int numrows, ci;
  149506. int buf_height = cinfo->max_v_samp_factor * 3;
  149507. JDIMENSION inrows;
  149508. while (*out_row_group_ctr < out_row_groups_avail) {
  149509. if (*in_row_ctr < in_rows_avail) {
  149510. inrows = in_rows_avail - *in_row_ctr;
  149511. numrows = prep->next_buf_stop - prep->next_buf_row;
  149512. numrows = (int) MIN((JDIMENSION) numrows, inrows);
  149513. (*cinfo->cconvert->color_convert) (cinfo, input_buf + *in_row_ctr,
  149514. prep->color_buf,
  149515. (JDIMENSION) prep->next_buf_row,
  149516. numrows);
  149517. if (prep->rows_to_go == cinfo->image_height) {
  149518. for (ci = 0; ci < cinfo->num_components; ci++) {
  149519. int row;
  149520. for (row = 1; row <= cinfo->max_v_samp_factor; row++) {
  149521. jcopy_sample_rows(prep->color_buf[ci], 0,
  149522. prep->color_buf[ci], -row,
  149523. 1, cinfo->image_width);
  149524. }
  149525. }
  149526. }
  149527. *in_row_ctr += numrows;
  149528. prep->next_buf_row += numrows;
  149529. prep->rows_to_go -= numrows;
  149530. } else {
  149531. if (prep->rows_to_go != 0)
  149532. break;
  149533. if (prep->next_buf_row < prep->next_buf_stop) {
  149534. for (ci = 0; ci < cinfo->num_components; ci++) {
  149535. expand_bottom_edge(prep->color_buf[ci], cinfo->image_width,
  149536. prep->next_buf_row, prep->next_buf_stop);
  149537. }
  149538. prep->next_buf_row = prep->next_buf_stop;
  149539. }
  149540. }
  149541. if (prep->next_buf_row == prep->next_buf_stop) {
  149542. (*cinfo->downsample->downsample) (cinfo,
  149543. prep->color_buf,
  149544. (JDIMENSION) prep->this_row_group,
  149545. output_buf, *out_row_group_ctr);
  149546. (*out_row_group_ctr)++;
  149547. prep->this_row_group += cinfo->max_v_samp_factor;
  149548. if (prep->this_row_group >= buf_height)
  149549. prep->this_row_group = 0;
  149550. if (prep->next_buf_row >= buf_height)
  149551. prep->next_buf_row = 0;
  149552. prep->next_buf_stop = prep->next_buf_row + cinfo->max_v_samp_factor;
  149553. }
  149554. }
  149555. }
  149556. LOCAL(void)
  149557. create_context_buffer (j_compress_ptr cinfo)
  149558. {
  149559. my_prep_ptr prep = (my_prep_ptr) cinfo->prep;
  149560. int rgroup_height = cinfo->max_v_samp_factor;
  149561. int ci, i;
  149562. jpeg_component_info * compptr;
  149563. JSAMPARRAY true_buffer, fake_buffer;
  149564. fake_buffer = (JSAMPARRAY)
  149565. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  149566. (cinfo->num_components * 5 * rgroup_height) *
  149567. SIZEOF(JSAMPROW));
  149568. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  149569. ci++, compptr++) {
  149570. true_buffer = (*cinfo->mem->alloc_sarray)
  149571. ((j_common_ptr) cinfo, JPOOL_IMAGE,
  149572. (JDIMENSION) (((long) compptr->width_in_blocks * DCTSIZE *
  149573. cinfo->max_h_samp_factor) / compptr->h_samp_factor),
  149574. (JDIMENSION) (3 * rgroup_height));
  149575. MEMCOPY(fake_buffer + rgroup_height, true_buffer,
  149576. 3 * rgroup_height * SIZEOF(JSAMPROW));
  149577. for (i = 0; i < rgroup_height; i++) {
  149578. fake_buffer[i] = true_buffer[2 * rgroup_height + i];
  149579. fake_buffer[4 * rgroup_height + i] = true_buffer[i];
  149580. }
  149581. prep->color_buf[ci] = fake_buffer + rgroup_height;
  149582. fake_buffer += 5 * rgroup_height; /* point to space for next component */
  149583. }
  149584. }
  149585. #endif /* CONTEXT_ROWS_SUPPORTED */
  149586. GLOBAL(void)
  149587. jinit_c_prep_controller (j_compress_ptr cinfo, boolean need_full_buffer)
  149588. {
  149589. my_prep_ptr prep;
  149590. int ci;
  149591. jpeg_component_info * compptr;
  149592. if (need_full_buffer) /* safety check */
  149593. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  149594. prep = (my_prep_ptr)
  149595. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  149596. SIZEOF(my_prep_controller));
  149597. cinfo->prep = (struct jpeg_c_prep_controller *) prep;
  149598. prep->pub.start_pass = start_pass_prep;
  149599. if (cinfo->downsample->need_context_rows) {
  149600. #ifdef CONTEXT_ROWS_SUPPORTED
  149601. prep->pub.pre_process_data = pre_process_context;
  149602. create_context_buffer(cinfo);
  149603. #else
  149604. ERREXIT(cinfo, JERR_NOT_COMPILED);
  149605. #endif
  149606. } else {
  149607. prep->pub.pre_process_data = pre_process_data;
  149608. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  149609. ci++, compptr++) {
  149610. prep->color_buf[ci] = (*cinfo->mem->alloc_sarray)
  149611. ((j_common_ptr) cinfo, JPOOL_IMAGE,
  149612. (JDIMENSION) (((long) compptr->width_in_blocks * DCTSIZE *
  149613. cinfo->max_h_samp_factor) / compptr->h_samp_factor),
  149614. (JDIMENSION) cinfo->max_v_samp_factor);
  149615. }
  149616. }
  149617. }
  149618. /*** End of inlined file: jcprepct.c ***/
  149619. /*** Start of inlined file: jcsample.c ***/
  149620. #define JPEG_INTERNALS
  149621. typedef JMETHOD(void, downsample1_ptr,
  149622. (j_compress_ptr cinfo, jpeg_component_info * compptr,
  149623. JSAMPARRAY input_data, JSAMPARRAY output_data));
  149624. typedef struct {
  149625. struct jpeg_downsampler pub; /* public fields */
  149626. downsample1_ptr methods[MAX_COMPONENTS];
  149627. } my_downsampler;
  149628. typedef my_downsampler * my_downsample_ptr;
  149629. METHODDEF(void)
  149630. start_pass_downsample (j_compress_ptr cinfo)
  149631. {
  149632. }
  149633. LOCAL(void)
  149634. expand_right_edge (JSAMPARRAY image_data, int num_rows,
  149635. JDIMENSION input_cols, JDIMENSION output_cols)
  149636. {
  149637. register JSAMPROW ptr;
  149638. register JSAMPLE pixval;
  149639. register int count;
  149640. int row;
  149641. int numcols = (int) (output_cols - input_cols);
  149642. if (numcols > 0) {
  149643. for (row = 0; row < num_rows; row++) {
  149644. ptr = image_data[row] + input_cols;
  149645. pixval = ptr[-1]; /* don't need GETJSAMPLE() here */
  149646. for (count = numcols; count > 0; count--)
  149647. *ptr++ = pixval;
  149648. }
  149649. }
  149650. }
  149651. METHODDEF(void)
  149652. sep_downsample (j_compress_ptr cinfo,
  149653. JSAMPIMAGE input_buf, JDIMENSION in_row_index,
  149654. JSAMPIMAGE output_buf, JDIMENSION out_row_group_index)
  149655. {
  149656. my_downsample_ptr downsample = (my_downsample_ptr) cinfo->downsample;
  149657. int ci;
  149658. jpeg_component_info * compptr;
  149659. JSAMPARRAY in_ptr, out_ptr;
  149660. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  149661. ci++, compptr++) {
  149662. in_ptr = input_buf[ci] + in_row_index;
  149663. out_ptr = output_buf[ci] + (out_row_group_index * compptr->v_samp_factor);
  149664. (*downsample->methods[ci]) (cinfo, compptr, in_ptr, out_ptr);
  149665. }
  149666. }
  149667. METHODDEF(void)
  149668. int_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr,
  149669. JSAMPARRAY input_data, JSAMPARRAY output_data)
  149670. {
  149671. int inrow, outrow, h_expand, v_expand, numpix, numpix2, h, v;
  149672. JDIMENSION outcol, outcol_h; /* outcol_h == outcol*h_expand */
  149673. JDIMENSION output_cols = compptr->width_in_blocks * DCTSIZE;
  149674. JSAMPROW inptr, outptr;
  149675. INT32 outvalue;
  149676. h_expand = cinfo->max_h_samp_factor / compptr->h_samp_factor;
  149677. v_expand = cinfo->max_v_samp_factor / compptr->v_samp_factor;
  149678. numpix = h_expand * v_expand;
  149679. numpix2 = numpix/2;
  149680. expand_right_edge(input_data, cinfo->max_v_samp_factor,
  149681. cinfo->image_width, output_cols * h_expand);
  149682. inrow = 0;
  149683. for (outrow = 0; outrow < compptr->v_samp_factor; outrow++) {
  149684. outptr = output_data[outrow];
  149685. for (outcol = 0, outcol_h = 0; outcol < output_cols;
  149686. outcol++, outcol_h += h_expand) {
  149687. outvalue = 0;
  149688. for (v = 0; v < v_expand; v++) {
  149689. inptr = input_data[inrow+v] + outcol_h;
  149690. for (h = 0; h < h_expand; h++) {
  149691. outvalue += (INT32) GETJSAMPLE(*inptr++);
  149692. }
  149693. }
  149694. *outptr++ = (JSAMPLE) ((outvalue + numpix2) / numpix);
  149695. }
  149696. inrow += v_expand;
  149697. }
  149698. }
  149699. METHODDEF(void)
  149700. fullsize_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr,
  149701. JSAMPARRAY input_data, JSAMPARRAY output_data)
  149702. {
  149703. jcopy_sample_rows(input_data, 0, output_data, 0,
  149704. cinfo->max_v_samp_factor, cinfo->image_width);
  149705. expand_right_edge(output_data, cinfo->max_v_samp_factor,
  149706. cinfo->image_width, compptr->width_in_blocks * DCTSIZE);
  149707. }
  149708. METHODDEF(void)
  149709. h2v1_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr,
  149710. JSAMPARRAY input_data, JSAMPARRAY output_data)
  149711. {
  149712. int outrow;
  149713. JDIMENSION outcol;
  149714. JDIMENSION output_cols = compptr->width_in_blocks * DCTSIZE;
  149715. register JSAMPROW inptr, outptr;
  149716. register int bias;
  149717. expand_right_edge(input_data, cinfo->max_v_samp_factor,
  149718. cinfo->image_width, output_cols * 2);
  149719. for (outrow = 0; outrow < compptr->v_samp_factor; outrow++) {
  149720. outptr = output_data[outrow];
  149721. inptr = input_data[outrow];
  149722. bias = 0; /* bias = 0,1,0,1,... for successive samples */
  149723. for (outcol = 0; outcol < output_cols; outcol++) {
  149724. *outptr++ = (JSAMPLE) ((GETJSAMPLE(*inptr) + GETJSAMPLE(inptr[1])
  149725. + bias) >> 1);
  149726. bias ^= 1; /* 0=>1, 1=>0 */
  149727. inptr += 2;
  149728. }
  149729. }
  149730. }
  149731. METHODDEF(void)
  149732. h2v2_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr,
  149733. JSAMPARRAY input_data, JSAMPARRAY output_data)
  149734. {
  149735. int inrow, outrow;
  149736. JDIMENSION outcol;
  149737. JDIMENSION output_cols = compptr->width_in_blocks * DCTSIZE;
  149738. register JSAMPROW inptr0, inptr1, outptr;
  149739. register int bias;
  149740. expand_right_edge(input_data, cinfo->max_v_samp_factor,
  149741. cinfo->image_width, output_cols * 2);
  149742. inrow = 0;
  149743. for (outrow = 0; outrow < compptr->v_samp_factor; outrow++) {
  149744. outptr = output_data[outrow];
  149745. inptr0 = input_data[inrow];
  149746. inptr1 = input_data[inrow+1];
  149747. bias = 1; /* bias = 1,2,1,2,... for successive samples */
  149748. for (outcol = 0; outcol < output_cols; outcol++) {
  149749. *outptr++ = (JSAMPLE) ((GETJSAMPLE(*inptr0) + GETJSAMPLE(inptr0[1]) +
  149750. GETJSAMPLE(*inptr1) + GETJSAMPLE(inptr1[1])
  149751. + bias) >> 2);
  149752. bias ^= 3; /* 1=>2, 2=>1 */
  149753. inptr0 += 2; inptr1 += 2;
  149754. }
  149755. inrow += 2;
  149756. }
  149757. }
  149758. #ifdef INPUT_SMOOTHING_SUPPORTED
  149759. METHODDEF(void)
  149760. h2v2_smooth_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr,
  149761. JSAMPARRAY input_data, JSAMPARRAY output_data)
  149762. {
  149763. int inrow, outrow;
  149764. JDIMENSION colctr;
  149765. JDIMENSION output_cols = compptr->width_in_blocks * DCTSIZE;
  149766. register JSAMPROW inptr0, inptr1, above_ptr, below_ptr, outptr;
  149767. INT32 membersum, neighsum, memberscale, neighscale;
  149768. expand_right_edge(input_data - 1, cinfo->max_v_samp_factor + 2,
  149769. cinfo->image_width, output_cols * 2);
  149770. memberscale = 16384 - cinfo->smoothing_factor * 80; /* scaled (1-5*SF)/4 */
  149771. neighscale = cinfo->smoothing_factor * 16; /* scaled SF/4 */
  149772. inrow = 0;
  149773. for (outrow = 0; outrow < compptr->v_samp_factor; outrow++) {
  149774. outptr = output_data[outrow];
  149775. inptr0 = input_data[inrow];
  149776. inptr1 = input_data[inrow+1];
  149777. above_ptr = input_data[inrow-1];
  149778. below_ptr = input_data[inrow+2];
  149779. membersum = GETJSAMPLE(*inptr0) + GETJSAMPLE(inptr0[1]) +
  149780. GETJSAMPLE(*inptr1) + GETJSAMPLE(inptr1[1]);
  149781. neighsum = GETJSAMPLE(*above_ptr) + GETJSAMPLE(above_ptr[1]) +
  149782. GETJSAMPLE(*below_ptr) + GETJSAMPLE(below_ptr[1]) +
  149783. GETJSAMPLE(*inptr0) + GETJSAMPLE(inptr0[2]) +
  149784. GETJSAMPLE(*inptr1) + GETJSAMPLE(inptr1[2]);
  149785. neighsum += neighsum;
  149786. neighsum += GETJSAMPLE(*above_ptr) + GETJSAMPLE(above_ptr[2]) +
  149787. GETJSAMPLE(*below_ptr) + GETJSAMPLE(below_ptr[2]);
  149788. membersum = membersum * memberscale + neighsum * neighscale;
  149789. *outptr++ = (JSAMPLE) ((membersum + 32768) >> 16);
  149790. inptr0 += 2; inptr1 += 2; above_ptr += 2; below_ptr += 2;
  149791. for (colctr = output_cols - 2; colctr > 0; colctr--) {
  149792. membersum = GETJSAMPLE(*inptr0) + GETJSAMPLE(inptr0[1]) +
  149793. GETJSAMPLE(*inptr1) + GETJSAMPLE(inptr1[1]);
  149794. neighsum = GETJSAMPLE(*above_ptr) + GETJSAMPLE(above_ptr[1]) +
  149795. GETJSAMPLE(*below_ptr) + GETJSAMPLE(below_ptr[1]) +
  149796. GETJSAMPLE(inptr0[-1]) + GETJSAMPLE(inptr0[2]) +
  149797. GETJSAMPLE(inptr1[-1]) + GETJSAMPLE(inptr1[2]);
  149798. neighsum += neighsum;
  149799. neighsum += GETJSAMPLE(above_ptr[-1]) + GETJSAMPLE(above_ptr[2]) +
  149800. GETJSAMPLE(below_ptr[-1]) + GETJSAMPLE(below_ptr[2]);
  149801. membersum = membersum * memberscale + neighsum * neighscale;
  149802. *outptr++ = (JSAMPLE) ((membersum + 32768) >> 16);
  149803. inptr0 += 2; inptr1 += 2; above_ptr += 2; below_ptr += 2;
  149804. }
  149805. membersum = GETJSAMPLE(*inptr0) + GETJSAMPLE(inptr0[1]) +
  149806. GETJSAMPLE(*inptr1) + GETJSAMPLE(inptr1[1]);
  149807. neighsum = GETJSAMPLE(*above_ptr) + GETJSAMPLE(above_ptr[1]) +
  149808. GETJSAMPLE(*below_ptr) + GETJSAMPLE(below_ptr[1]) +
  149809. GETJSAMPLE(inptr0[-1]) + GETJSAMPLE(inptr0[1]) +
  149810. GETJSAMPLE(inptr1[-1]) + GETJSAMPLE(inptr1[1]);
  149811. neighsum += neighsum;
  149812. neighsum += GETJSAMPLE(above_ptr[-1]) + GETJSAMPLE(above_ptr[1]) +
  149813. GETJSAMPLE(below_ptr[-1]) + GETJSAMPLE(below_ptr[1]);
  149814. membersum = membersum * memberscale + neighsum * neighscale;
  149815. *outptr = (JSAMPLE) ((membersum + 32768) >> 16);
  149816. inrow += 2;
  149817. }
  149818. }
  149819. METHODDEF(void)
  149820. fullsize_smooth_downsample (j_compress_ptr cinfo, jpeg_component_info *compptr,
  149821. JSAMPARRAY input_data, JSAMPARRAY output_data)
  149822. {
  149823. int outrow;
  149824. JDIMENSION colctr;
  149825. JDIMENSION output_cols = compptr->width_in_blocks * DCTSIZE;
  149826. register JSAMPROW inptr, above_ptr, below_ptr, outptr;
  149827. INT32 membersum, neighsum, memberscale, neighscale;
  149828. int colsum, lastcolsum, nextcolsum;
  149829. expand_right_edge(input_data - 1, cinfo->max_v_samp_factor + 2,
  149830. cinfo->image_width, output_cols);
  149831. memberscale = 65536L - cinfo->smoothing_factor * 512L; /* scaled 1-8*SF */
  149832. neighscale = cinfo->smoothing_factor * 64; /* scaled SF */
  149833. for (outrow = 0; outrow < compptr->v_samp_factor; outrow++) {
  149834. outptr = output_data[outrow];
  149835. inptr = input_data[outrow];
  149836. above_ptr = input_data[outrow-1];
  149837. below_ptr = input_data[outrow+1];
  149838. colsum = GETJSAMPLE(*above_ptr++) + GETJSAMPLE(*below_ptr++) +
  149839. GETJSAMPLE(*inptr);
  149840. membersum = GETJSAMPLE(*inptr++);
  149841. nextcolsum = GETJSAMPLE(*above_ptr) + GETJSAMPLE(*below_ptr) +
  149842. GETJSAMPLE(*inptr);
  149843. neighsum = colsum + (colsum - membersum) + nextcolsum;
  149844. membersum = membersum * memberscale + neighsum * neighscale;
  149845. *outptr++ = (JSAMPLE) ((membersum + 32768) >> 16);
  149846. lastcolsum = colsum; colsum = nextcolsum;
  149847. for (colctr = output_cols - 2; colctr > 0; colctr--) {
  149848. membersum = GETJSAMPLE(*inptr++);
  149849. above_ptr++; below_ptr++;
  149850. nextcolsum = GETJSAMPLE(*above_ptr) + GETJSAMPLE(*below_ptr) +
  149851. GETJSAMPLE(*inptr);
  149852. neighsum = lastcolsum + (colsum - membersum) + nextcolsum;
  149853. membersum = membersum * memberscale + neighsum * neighscale;
  149854. *outptr++ = (JSAMPLE) ((membersum + 32768) >> 16);
  149855. lastcolsum = colsum; colsum = nextcolsum;
  149856. }
  149857. membersum = GETJSAMPLE(*inptr);
  149858. neighsum = lastcolsum + (colsum - membersum) + colsum;
  149859. membersum = membersum * memberscale + neighsum * neighscale;
  149860. *outptr = (JSAMPLE) ((membersum + 32768) >> 16);
  149861. }
  149862. }
  149863. #endif /* INPUT_SMOOTHING_SUPPORTED */
  149864. GLOBAL(void)
  149865. jinit_downsampler (j_compress_ptr cinfo)
  149866. {
  149867. my_downsample_ptr downsample;
  149868. int ci;
  149869. jpeg_component_info * compptr;
  149870. boolean smoothok = TRUE;
  149871. downsample = (my_downsample_ptr)
  149872. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  149873. SIZEOF(my_downsampler));
  149874. cinfo->downsample = (struct jpeg_downsampler *) downsample;
  149875. downsample->pub.start_pass = start_pass_downsample;
  149876. downsample->pub.downsample = sep_downsample;
  149877. downsample->pub.need_context_rows = FALSE;
  149878. if (cinfo->CCIR601_sampling)
  149879. ERREXIT(cinfo, JERR_CCIR601_NOTIMPL);
  149880. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  149881. ci++, compptr++) {
  149882. if (compptr->h_samp_factor == cinfo->max_h_samp_factor &&
  149883. compptr->v_samp_factor == cinfo->max_v_samp_factor) {
  149884. #ifdef INPUT_SMOOTHING_SUPPORTED
  149885. if (cinfo->smoothing_factor) {
  149886. downsample->methods[ci] = fullsize_smooth_downsample;
  149887. downsample->pub.need_context_rows = TRUE;
  149888. } else
  149889. #endif
  149890. downsample->methods[ci] = fullsize_downsample;
  149891. } else if (compptr->h_samp_factor * 2 == cinfo->max_h_samp_factor &&
  149892. compptr->v_samp_factor == cinfo->max_v_samp_factor) {
  149893. smoothok = FALSE;
  149894. downsample->methods[ci] = h2v1_downsample;
  149895. } else if (compptr->h_samp_factor * 2 == cinfo->max_h_samp_factor &&
  149896. compptr->v_samp_factor * 2 == cinfo->max_v_samp_factor) {
  149897. #ifdef INPUT_SMOOTHING_SUPPORTED
  149898. if (cinfo->smoothing_factor) {
  149899. downsample->methods[ci] = h2v2_smooth_downsample;
  149900. downsample->pub.need_context_rows = TRUE;
  149901. } else
  149902. #endif
  149903. downsample->methods[ci] = h2v2_downsample;
  149904. } else if ((cinfo->max_h_samp_factor % compptr->h_samp_factor) == 0 &&
  149905. (cinfo->max_v_samp_factor % compptr->v_samp_factor) == 0) {
  149906. smoothok = FALSE;
  149907. downsample->methods[ci] = int_downsample;
  149908. } else
  149909. ERREXIT(cinfo, JERR_FRACT_SAMPLE_NOTIMPL);
  149910. }
  149911. #ifdef INPUT_SMOOTHING_SUPPORTED
  149912. if (cinfo->smoothing_factor && !smoothok)
  149913. TRACEMS(cinfo, 0, JTRC_SMOOTH_NOTIMPL);
  149914. #endif
  149915. }
  149916. /*** End of inlined file: jcsample.c ***/
  149917. /*** Start of inlined file: jctrans.c ***/
  149918. #define JPEG_INTERNALS
  149919. LOCAL(void) transencode_master_selection
  149920. JPP((j_compress_ptr cinfo, jvirt_barray_ptr * coef_arrays));
  149921. LOCAL(void) transencode_coef_controller
  149922. JPP((j_compress_ptr cinfo, jvirt_barray_ptr * coef_arrays));
  149923. GLOBAL(void)
  149924. jpeg_write_coefficients (j_compress_ptr cinfo, jvirt_barray_ptr * coef_arrays)
  149925. {
  149926. if (cinfo->global_state != CSTATE_START)
  149927. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  149928. jpeg_suppress_tables(cinfo, FALSE);
  149929. (*cinfo->err->reset_error_mgr) ((j_common_ptr) cinfo);
  149930. (*cinfo->dest->init_destination) (cinfo);
  149931. transencode_master_selection(cinfo, coef_arrays);
  149932. cinfo->next_scanline = 0; /* so jpeg_write_marker works */
  149933. cinfo->global_state = CSTATE_WRCOEFS;
  149934. }
  149935. GLOBAL(void)
  149936. jpeg_copy_critical_parameters (j_decompress_ptr srcinfo,
  149937. j_compress_ptr dstinfo)
  149938. {
  149939. JQUANT_TBL ** qtblptr;
  149940. jpeg_component_info *incomp, *outcomp;
  149941. JQUANT_TBL *c_quant, *slot_quant;
  149942. int tblno, ci, coefi;
  149943. if (dstinfo->global_state != CSTATE_START)
  149944. ERREXIT1(dstinfo, JERR_BAD_STATE, dstinfo->global_state);
  149945. dstinfo->image_width = srcinfo->image_width;
  149946. dstinfo->image_height = srcinfo->image_height;
  149947. dstinfo->input_components = srcinfo->num_components;
  149948. dstinfo->in_color_space = srcinfo->jpeg_color_space;
  149949. jpeg_set_defaults(dstinfo);
  149950. jpeg_set_colorspace(dstinfo, srcinfo->jpeg_color_space);
  149951. dstinfo->data_precision = srcinfo->data_precision;
  149952. dstinfo->CCIR601_sampling = srcinfo->CCIR601_sampling;
  149953. for (tblno = 0; tblno < NUM_QUANT_TBLS; tblno++) {
  149954. if (srcinfo->quant_tbl_ptrs[tblno] != NULL) {
  149955. qtblptr = & dstinfo->quant_tbl_ptrs[tblno];
  149956. if (*qtblptr == NULL)
  149957. *qtblptr = jpeg_alloc_quant_table((j_common_ptr) dstinfo);
  149958. MEMCOPY((*qtblptr)->quantval,
  149959. srcinfo->quant_tbl_ptrs[tblno]->quantval,
  149960. SIZEOF((*qtblptr)->quantval));
  149961. (*qtblptr)->sent_table = FALSE;
  149962. }
  149963. }
  149964. dstinfo->num_components = srcinfo->num_components;
  149965. if (dstinfo->num_components < 1 || dstinfo->num_components > MAX_COMPONENTS)
  149966. ERREXIT2(dstinfo, JERR_COMPONENT_COUNT, dstinfo->num_components,
  149967. MAX_COMPONENTS);
  149968. for (ci = 0, incomp = srcinfo->comp_info, outcomp = dstinfo->comp_info;
  149969. ci < dstinfo->num_components; ci++, incomp++, outcomp++) {
  149970. outcomp->component_id = incomp->component_id;
  149971. outcomp->h_samp_factor = incomp->h_samp_factor;
  149972. outcomp->v_samp_factor = incomp->v_samp_factor;
  149973. outcomp->quant_tbl_no = incomp->quant_tbl_no;
  149974. tblno = outcomp->quant_tbl_no;
  149975. if (tblno < 0 || tblno >= NUM_QUANT_TBLS ||
  149976. srcinfo->quant_tbl_ptrs[tblno] == NULL)
  149977. ERREXIT1(dstinfo, JERR_NO_QUANT_TABLE, tblno);
  149978. slot_quant = srcinfo->quant_tbl_ptrs[tblno];
  149979. c_quant = incomp->quant_table;
  149980. if (c_quant != NULL) {
  149981. for (coefi = 0; coefi < DCTSIZE2; coefi++) {
  149982. if (c_quant->quantval[coefi] != slot_quant->quantval[coefi])
  149983. ERREXIT1(dstinfo, JERR_MISMATCHED_QUANT_TABLE, tblno);
  149984. }
  149985. }
  149986. }
  149987. if (srcinfo->saw_JFIF_marker) {
  149988. if (srcinfo->JFIF_major_version == 1) {
  149989. dstinfo->JFIF_major_version = srcinfo->JFIF_major_version;
  149990. dstinfo->JFIF_minor_version = srcinfo->JFIF_minor_version;
  149991. }
  149992. dstinfo->density_unit = srcinfo->density_unit;
  149993. dstinfo->X_density = srcinfo->X_density;
  149994. dstinfo->Y_density = srcinfo->Y_density;
  149995. }
  149996. }
  149997. LOCAL(void)
  149998. transencode_master_selection (j_compress_ptr cinfo,
  149999. jvirt_barray_ptr * coef_arrays)
  150000. {
  150001. cinfo->input_components = 1;
  150002. jinit_c_master_control(cinfo, TRUE /* transcode only */);
  150003. if (cinfo->arith_code) {
  150004. ERREXIT(cinfo, JERR_ARITH_NOTIMPL);
  150005. } else {
  150006. if (cinfo->progressive_mode) {
  150007. #ifdef C_PROGRESSIVE_SUPPORTED
  150008. jinit_phuff_encoder(cinfo);
  150009. #else
  150010. ERREXIT(cinfo, JERR_NOT_COMPILED);
  150011. #endif
  150012. } else
  150013. jinit_huff_encoder(cinfo);
  150014. }
  150015. transencode_coef_controller(cinfo, coef_arrays);
  150016. jinit_marker_writer(cinfo);
  150017. (*cinfo->mem->realize_virt_arrays) ((j_common_ptr) cinfo);
  150018. (*cinfo->marker->write_file_header) (cinfo);
  150019. }
  150020. typedef struct {
  150021. struct jpeg_c_coef_controller pub; /* public fields */
  150022. JDIMENSION iMCU_row_num; /* iMCU row # within image */
  150023. JDIMENSION mcu_ctr; /* counts MCUs processed in current row */
  150024. int MCU_vert_offset; /* counts MCU rows within iMCU row */
  150025. int MCU_rows_per_iMCU_row; /* number of such rows needed */
  150026. jvirt_barray_ptr * whole_image;
  150027. JBLOCKROW dummy_buffer[C_MAX_BLOCKS_IN_MCU];
  150028. } my_coef_controller2;
  150029. typedef my_coef_controller2 * my_coef_ptr2;
  150030. LOCAL(void)
  150031. start_iMCU_row2 (j_compress_ptr cinfo)
  150032. {
  150033. my_coef_ptr2 coef = (my_coef_ptr2) cinfo->coef;
  150034. if (cinfo->comps_in_scan > 1) {
  150035. coef->MCU_rows_per_iMCU_row = 1;
  150036. } else {
  150037. if (coef->iMCU_row_num < (cinfo->total_iMCU_rows-1))
  150038. coef->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
  150039. else
  150040. coef->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
  150041. }
  150042. coef->mcu_ctr = 0;
  150043. coef->MCU_vert_offset = 0;
  150044. }
  150045. METHODDEF(void)
  150046. start_pass_coef2 (j_compress_ptr cinfo, J_BUF_MODE pass_mode)
  150047. {
  150048. my_coef_ptr2 coef = (my_coef_ptr2) cinfo->coef;
  150049. if (pass_mode != JBUF_CRANK_DEST)
  150050. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  150051. coef->iMCU_row_num = 0;
  150052. start_iMCU_row2(cinfo);
  150053. }
  150054. METHODDEF(boolean)
  150055. compress_output2 (j_compress_ptr cinfo, JSAMPIMAGE input_buf)
  150056. {
  150057. my_coef_ptr2 coef = (my_coef_ptr2) cinfo->coef;
  150058. JDIMENSION MCU_col_num; /* index of current MCU within row */
  150059. JDIMENSION last_MCU_col = cinfo->MCUs_per_row - 1;
  150060. JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
  150061. int blkn, ci, xindex, yindex, yoffset, blockcnt;
  150062. JDIMENSION start_col;
  150063. JBLOCKARRAY buffer[MAX_COMPS_IN_SCAN];
  150064. JBLOCKROW MCU_buffer[C_MAX_BLOCKS_IN_MCU];
  150065. JBLOCKROW buffer_ptr;
  150066. jpeg_component_info *compptr;
  150067. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  150068. compptr = cinfo->cur_comp_info[ci];
  150069. buffer[ci] = (*cinfo->mem->access_virt_barray)
  150070. ((j_common_ptr) cinfo, coef->whole_image[compptr->component_index],
  150071. coef->iMCU_row_num * compptr->v_samp_factor,
  150072. (JDIMENSION) compptr->v_samp_factor, FALSE);
  150073. }
  150074. for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
  150075. yoffset++) {
  150076. for (MCU_col_num = coef->mcu_ctr; MCU_col_num < cinfo->MCUs_per_row;
  150077. MCU_col_num++) {
  150078. blkn = 0; /* index of current DCT block within MCU */
  150079. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  150080. compptr = cinfo->cur_comp_info[ci];
  150081. start_col = MCU_col_num * compptr->MCU_width;
  150082. blockcnt = (MCU_col_num < last_MCU_col) ? compptr->MCU_width
  150083. : compptr->last_col_width;
  150084. for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
  150085. if (coef->iMCU_row_num < last_iMCU_row ||
  150086. yindex+yoffset < compptr->last_row_height) {
  150087. buffer_ptr = buffer[ci][yindex+yoffset] + start_col;
  150088. for (xindex = 0; xindex < blockcnt; xindex++)
  150089. MCU_buffer[blkn++] = buffer_ptr++;
  150090. } else {
  150091. xindex = 0;
  150092. }
  150093. for (; xindex < compptr->MCU_width; xindex++) {
  150094. MCU_buffer[blkn] = coef->dummy_buffer[blkn];
  150095. MCU_buffer[blkn][0][0] = MCU_buffer[blkn-1][0][0];
  150096. blkn++;
  150097. }
  150098. }
  150099. }
  150100. if (! (*cinfo->entropy->encode_mcu) (cinfo, MCU_buffer)) {
  150101. coef->MCU_vert_offset = yoffset;
  150102. coef->mcu_ctr = MCU_col_num;
  150103. return FALSE;
  150104. }
  150105. }
  150106. coef->mcu_ctr = 0;
  150107. }
  150108. coef->iMCU_row_num++;
  150109. start_iMCU_row2(cinfo);
  150110. return TRUE;
  150111. }
  150112. LOCAL(void)
  150113. transencode_coef_controller (j_compress_ptr cinfo,
  150114. jvirt_barray_ptr * coef_arrays)
  150115. {
  150116. my_coef_ptr2 coef;
  150117. JBLOCKROW buffer;
  150118. int i;
  150119. coef = (my_coef_ptr2)
  150120. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  150121. SIZEOF(my_coef_controller2));
  150122. cinfo->coef = (struct jpeg_c_coef_controller *) coef;
  150123. coef->pub.start_pass = start_pass_coef2;
  150124. coef->pub.compress_data = compress_output2;
  150125. coef->whole_image = coef_arrays;
  150126. buffer = (JBLOCKROW)
  150127. (*cinfo->mem->alloc_large) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  150128. C_MAX_BLOCKS_IN_MCU * SIZEOF(JBLOCK));
  150129. jzero_far((void FAR *) buffer, C_MAX_BLOCKS_IN_MCU * SIZEOF(JBLOCK));
  150130. for (i = 0; i < C_MAX_BLOCKS_IN_MCU; i++) {
  150131. coef->dummy_buffer[i] = buffer + i;
  150132. }
  150133. }
  150134. /*** End of inlined file: jctrans.c ***/
  150135. /*** Start of inlined file: jdapistd.c ***/
  150136. #define JPEG_INTERNALS
  150137. LOCAL(boolean) output_pass_setup JPP((j_decompress_ptr cinfo));
  150138. GLOBAL(boolean)
  150139. jpeg_start_decompress (j_decompress_ptr cinfo)
  150140. {
  150141. if (cinfo->global_state == DSTATE_READY) {
  150142. jinit_master_decompress(cinfo);
  150143. if (cinfo->buffered_image) {
  150144. cinfo->global_state = DSTATE_BUFIMAGE;
  150145. return TRUE;
  150146. }
  150147. cinfo->global_state = DSTATE_PRELOAD;
  150148. }
  150149. if (cinfo->global_state == DSTATE_PRELOAD) {
  150150. if (cinfo->inputctl->has_multiple_scans) {
  150151. #ifdef D_MULTISCAN_FILES_SUPPORTED
  150152. for (;;) {
  150153. int retcode;
  150154. if (cinfo->progress != NULL)
  150155. (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
  150156. retcode = (*cinfo->inputctl->consume_input) (cinfo);
  150157. if (retcode == JPEG_SUSPENDED)
  150158. return FALSE;
  150159. if (retcode == JPEG_REACHED_EOI)
  150160. break;
  150161. if (cinfo->progress != NULL &&
  150162. (retcode == JPEG_ROW_COMPLETED || retcode == JPEG_REACHED_SOS)) {
  150163. if (++cinfo->progress->pass_counter >= cinfo->progress->pass_limit) {
  150164. cinfo->progress->pass_limit += (long) cinfo->total_iMCU_rows;
  150165. }
  150166. }
  150167. }
  150168. #else
  150169. ERREXIT(cinfo, JERR_NOT_COMPILED);
  150170. #endif /* D_MULTISCAN_FILES_SUPPORTED */
  150171. }
  150172. cinfo->output_scan_number = cinfo->input_scan_number;
  150173. } else if (cinfo->global_state != DSTATE_PRESCAN)
  150174. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  150175. return output_pass_setup(cinfo);
  150176. }
  150177. LOCAL(boolean)
  150178. output_pass_setup (j_decompress_ptr cinfo)
  150179. {
  150180. if (cinfo->global_state != DSTATE_PRESCAN) {
  150181. (*cinfo->master->prepare_for_output_pass) (cinfo);
  150182. cinfo->output_scanline = 0;
  150183. cinfo->global_state = DSTATE_PRESCAN;
  150184. }
  150185. while (cinfo->master->is_dummy_pass) {
  150186. #ifdef QUANT_2PASS_SUPPORTED
  150187. while (cinfo->output_scanline < cinfo->output_height) {
  150188. JDIMENSION last_scanline;
  150189. if (cinfo->progress != NULL) {
  150190. cinfo->progress->pass_counter = (long) cinfo->output_scanline;
  150191. cinfo->progress->pass_limit = (long) cinfo->output_height;
  150192. (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
  150193. }
  150194. last_scanline = cinfo->output_scanline;
  150195. (*cinfo->main->process_data) (cinfo, (JSAMPARRAY) NULL,
  150196. &cinfo->output_scanline, (JDIMENSION) 0);
  150197. if (cinfo->output_scanline == last_scanline)
  150198. return FALSE; /* No progress made, must suspend */
  150199. }
  150200. (*cinfo->master->finish_output_pass) (cinfo);
  150201. (*cinfo->master->prepare_for_output_pass) (cinfo);
  150202. cinfo->output_scanline = 0;
  150203. #else
  150204. ERREXIT(cinfo, JERR_NOT_COMPILED);
  150205. #endif /* QUANT_2PASS_SUPPORTED */
  150206. }
  150207. cinfo->global_state = cinfo->raw_data_out ? DSTATE_RAW_OK : DSTATE_SCANNING;
  150208. return TRUE;
  150209. }
  150210. GLOBAL(JDIMENSION)
  150211. jpeg_read_scanlines (j_decompress_ptr cinfo, JSAMPARRAY scanlines,
  150212. JDIMENSION max_lines)
  150213. {
  150214. JDIMENSION row_ctr;
  150215. if (cinfo->global_state != DSTATE_SCANNING)
  150216. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  150217. if (cinfo->output_scanline >= cinfo->output_height) {
  150218. WARNMS(cinfo, JWRN_TOO_MUCH_DATA);
  150219. return 0;
  150220. }
  150221. if (cinfo->progress != NULL) {
  150222. cinfo->progress->pass_counter = (long) cinfo->output_scanline;
  150223. cinfo->progress->pass_limit = (long) cinfo->output_height;
  150224. (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
  150225. }
  150226. row_ctr = 0;
  150227. (*cinfo->main->process_data) (cinfo, scanlines, &row_ctr, max_lines);
  150228. cinfo->output_scanline += row_ctr;
  150229. return row_ctr;
  150230. }
  150231. GLOBAL(JDIMENSION)
  150232. jpeg_read_raw_data (j_decompress_ptr cinfo, JSAMPIMAGE data,
  150233. JDIMENSION max_lines)
  150234. {
  150235. JDIMENSION lines_per_iMCU_row;
  150236. if (cinfo->global_state != DSTATE_RAW_OK)
  150237. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  150238. if (cinfo->output_scanline >= cinfo->output_height) {
  150239. WARNMS(cinfo, JWRN_TOO_MUCH_DATA);
  150240. return 0;
  150241. }
  150242. if (cinfo->progress != NULL) {
  150243. cinfo->progress->pass_counter = (long) cinfo->output_scanline;
  150244. cinfo->progress->pass_limit = (long) cinfo->output_height;
  150245. (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
  150246. }
  150247. lines_per_iMCU_row = cinfo->max_v_samp_factor * cinfo->min_DCT_scaled_size;
  150248. if (max_lines < lines_per_iMCU_row)
  150249. ERREXIT(cinfo, JERR_BUFFER_SIZE);
  150250. if (! (*cinfo->coef->decompress_data) (cinfo, data))
  150251. return 0; /* suspension forced, can do nothing more */
  150252. cinfo->output_scanline += lines_per_iMCU_row;
  150253. return lines_per_iMCU_row;
  150254. }
  150255. #ifdef D_MULTISCAN_FILES_SUPPORTED
  150256. GLOBAL(boolean)
  150257. jpeg_start_output (j_decompress_ptr cinfo, int scan_number)
  150258. {
  150259. if (cinfo->global_state != DSTATE_BUFIMAGE &&
  150260. cinfo->global_state != DSTATE_PRESCAN)
  150261. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  150262. if (scan_number <= 0)
  150263. scan_number = 1;
  150264. if (cinfo->inputctl->eoi_reached &&
  150265. scan_number > cinfo->input_scan_number)
  150266. scan_number = cinfo->input_scan_number;
  150267. cinfo->output_scan_number = scan_number;
  150268. return output_pass_setup(cinfo);
  150269. }
  150270. GLOBAL(boolean)
  150271. jpeg_finish_output (j_decompress_ptr cinfo)
  150272. {
  150273. if ((cinfo->global_state == DSTATE_SCANNING ||
  150274. cinfo->global_state == DSTATE_RAW_OK) && cinfo->buffered_image) {
  150275. (*cinfo->master->finish_output_pass) (cinfo);
  150276. cinfo->global_state = DSTATE_BUFPOST;
  150277. } else if (cinfo->global_state != DSTATE_BUFPOST) {
  150278. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  150279. }
  150280. while (cinfo->input_scan_number <= cinfo->output_scan_number &&
  150281. ! cinfo->inputctl->eoi_reached) {
  150282. if ((*cinfo->inputctl->consume_input) (cinfo) == JPEG_SUSPENDED)
  150283. return FALSE; /* Suspend, come back later */
  150284. }
  150285. cinfo->global_state = DSTATE_BUFIMAGE;
  150286. return TRUE;
  150287. }
  150288. #endif /* D_MULTISCAN_FILES_SUPPORTED */
  150289. /*** End of inlined file: jdapistd.c ***/
  150290. /*** Start of inlined file: jdapimin.c ***/
  150291. #define JPEG_INTERNALS
  150292. GLOBAL(void)
  150293. jpeg_CreateDecompress (j_decompress_ptr cinfo, int version, size_t structsize)
  150294. {
  150295. int i;
  150296. cinfo->mem = NULL; /* so jpeg_destroy knows mem mgr not called */
  150297. if (version != JPEG_LIB_VERSION)
  150298. ERREXIT2(cinfo, JERR_BAD_LIB_VERSION, JPEG_LIB_VERSION, version);
  150299. if (structsize != SIZEOF(struct jpeg_decompress_struct))
  150300. ERREXIT2(cinfo, JERR_BAD_STRUCT_SIZE,
  150301. (int) SIZEOF(struct jpeg_decompress_struct), (int) structsize);
  150302. {
  150303. struct jpeg_error_mgr * err = cinfo->err;
  150304. void * client_data = cinfo->client_data; /* ignore Purify complaint here */
  150305. MEMZERO(cinfo, SIZEOF(struct jpeg_decompress_struct));
  150306. cinfo->err = err;
  150307. cinfo->client_data = client_data;
  150308. }
  150309. cinfo->is_decompressor = TRUE;
  150310. jinit_memory_mgr((j_common_ptr) cinfo);
  150311. cinfo->progress = NULL;
  150312. cinfo->src = NULL;
  150313. for (i = 0; i < NUM_QUANT_TBLS; i++)
  150314. cinfo->quant_tbl_ptrs[i] = NULL;
  150315. for (i = 0; i < NUM_HUFF_TBLS; i++) {
  150316. cinfo->dc_huff_tbl_ptrs[i] = NULL;
  150317. cinfo->ac_huff_tbl_ptrs[i] = NULL;
  150318. }
  150319. cinfo->marker_list = NULL;
  150320. jinit_marker_reader(cinfo);
  150321. jinit_input_controller(cinfo);
  150322. cinfo->global_state = DSTATE_START;
  150323. }
  150324. GLOBAL(void)
  150325. jpeg_destroy_decompress (j_decompress_ptr cinfo)
  150326. {
  150327. jpeg_destroy((j_common_ptr) cinfo); /* use common routine */
  150328. }
  150329. GLOBAL(void)
  150330. jpeg_abort_decompress (j_decompress_ptr cinfo)
  150331. {
  150332. jpeg_abort((j_common_ptr) cinfo); /* use common routine */
  150333. }
  150334. LOCAL(void)
  150335. default_decompress_parms (j_decompress_ptr cinfo)
  150336. {
  150337. switch (cinfo->num_components) {
  150338. case 1:
  150339. cinfo->jpeg_color_space = JCS_GRAYSCALE;
  150340. cinfo->out_color_space = JCS_GRAYSCALE;
  150341. break;
  150342. case 3:
  150343. if (cinfo->saw_JFIF_marker) {
  150344. cinfo->jpeg_color_space = JCS_YCbCr; /* JFIF implies YCbCr */
  150345. } else if (cinfo->saw_Adobe_marker) {
  150346. switch (cinfo->Adobe_transform) {
  150347. case 0:
  150348. cinfo->jpeg_color_space = JCS_RGB;
  150349. break;
  150350. case 1:
  150351. cinfo->jpeg_color_space = JCS_YCbCr;
  150352. break;
  150353. default:
  150354. WARNMS1(cinfo, JWRN_ADOBE_XFORM, cinfo->Adobe_transform);
  150355. cinfo->jpeg_color_space = JCS_YCbCr; /* assume it's YCbCr */
  150356. break;
  150357. }
  150358. } else {
  150359. int cid0 = cinfo->comp_info[0].component_id;
  150360. int cid1 = cinfo->comp_info[1].component_id;
  150361. int cid2 = cinfo->comp_info[2].component_id;
  150362. if (cid0 == 1 && cid1 == 2 && cid2 == 3)
  150363. cinfo->jpeg_color_space = JCS_YCbCr; /* assume JFIF w/out marker */
  150364. else if (cid0 == 82 && cid1 == 71 && cid2 == 66)
  150365. cinfo->jpeg_color_space = JCS_RGB; /* ASCII 'R', 'G', 'B' */
  150366. else {
  150367. TRACEMS3(cinfo, 1, JTRC_UNKNOWN_IDS, cid0, cid1, cid2);
  150368. cinfo->jpeg_color_space = JCS_YCbCr; /* assume it's YCbCr */
  150369. }
  150370. }
  150371. cinfo->out_color_space = JCS_RGB;
  150372. break;
  150373. case 4:
  150374. if (cinfo->saw_Adobe_marker) {
  150375. switch (cinfo->Adobe_transform) {
  150376. case 0:
  150377. cinfo->jpeg_color_space = JCS_CMYK;
  150378. break;
  150379. case 2:
  150380. cinfo->jpeg_color_space = JCS_YCCK;
  150381. break;
  150382. default:
  150383. WARNMS1(cinfo, JWRN_ADOBE_XFORM, cinfo->Adobe_transform);
  150384. cinfo->jpeg_color_space = JCS_YCCK; /* assume it's YCCK */
  150385. break;
  150386. }
  150387. } else {
  150388. cinfo->jpeg_color_space = JCS_CMYK;
  150389. }
  150390. cinfo->out_color_space = JCS_CMYK;
  150391. break;
  150392. default:
  150393. cinfo->jpeg_color_space = JCS_UNKNOWN;
  150394. cinfo->out_color_space = JCS_UNKNOWN;
  150395. break;
  150396. }
  150397. cinfo->scale_num = 1; /* 1:1 scaling */
  150398. cinfo->scale_denom = 1;
  150399. cinfo->output_gamma = 1.0;
  150400. cinfo->buffered_image = FALSE;
  150401. cinfo->raw_data_out = FALSE;
  150402. cinfo->dct_method = JDCT_DEFAULT;
  150403. cinfo->do_fancy_upsampling = TRUE;
  150404. cinfo->do_block_smoothing = TRUE;
  150405. cinfo->quantize_colors = FALSE;
  150406. cinfo->dither_mode = JDITHER_FS;
  150407. #ifdef QUANT_2PASS_SUPPORTED
  150408. cinfo->two_pass_quantize = TRUE;
  150409. #else
  150410. cinfo->two_pass_quantize = FALSE;
  150411. #endif
  150412. cinfo->desired_number_of_colors = 256;
  150413. cinfo->colormap = NULL;
  150414. cinfo->enable_1pass_quant = FALSE;
  150415. cinfo->enable_external_quant = FALSE;
  150416. cinfo->enable_2pass_quant = FALSE;
  150417. }
  150418. GLOBAL(int)
  150419. jpeg_read_header (j_decompress_ptr cinfo, boolean require_image)
  150420. {
  150421. int retcode;
  150422. if (cinfo->global_state != DSTATE_START &&
  150423. cinfo->global_state != DSTATE_INHEADER)
  150424. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  150425. retcode = jpeg_consume_input(cinfo);
  150426. switch (retcode) {
  150427. case JPEG_REACHED_SOS:
  150428. retcode = JPEG_HEADER_OK;
  150429. break;
  150430. case JPEG_REACHED_EOI:
  150431. if (require_image) /* Complain if application wanted an image */
  150432. ERREXIT(cinfo, JERR_NO_IMAGE);
  150433. jpeg_abort((j_common_ptr) cinfo); /* sets state = DSTATE_START */
  150434. retcode = JPEG_HEADER_TABLES_ONLY;
  150435. break;
  150436. case JPEG_SUSPENDED:
  150437. break;
  150438. }
  150439. return retcode;
  150440. }
  150441. GLOBAL(int)
  150442. jpeg_consume_input (j_decompress_ptr cinfo)
  150443. {
  150444. int retcode = JPEG_SUSPENDED;
  150445. switch (cinfo->global_state) {
  150446. case DSTATE_START:
  150447. (*cinfo->inputctl->reset_input_controller) (cinfo);
  150448. (*cinfo->src->init_source) (cinfo);
  150449. cinfo->global_state = DSTATE_INHEADER;
  150450. case DSTATE_INHEADER:
  150451. retcode = (*cinfo->inputctl->consume_input) (cinfo);
  150452. if (retcode == JPEG_REACHED_SOS) { /* Found SOS, prepare to decompress */
  150453. default_decompress_parms(cinfo);
  150454. cinfo->global_state = DSTATE_READY;
  150455. }
  150456. break;
  150457. case DSTATE_READY:
  150458. retcode = JPEG_REACHED_SOS;
  150459. break;
  150460. case DSTATE_PRELOAD:
  150461. case DSTATE_PRESCAN:
  150462. case DSTATE_SCANNING:
  150463. case DSTATE_RAW_OK:
  150464. case DSTATE_BUFIMAGE:
  150465. case DSTATE_BUFPOST:
  150466. case DSTATE_STOPPING:
  150467. retcode = (*cinfo->inputctl->consume_input) (cinfo);
  150468. break;
  150469. default:
  150470. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  150471. }
  150472. return retcode;
  150473. }
  150474. GLOBAL(boolean)
  150475. jpeg_input_complete (j_decompress_ptr cinfo)
  150476. {
  150477. if (cinfo->global_state < DSTATE_START ||
  150478. cinfo->global_state > DSTATE_STOPPING)
  150479. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  150480. return cinfo->inputctl->eoi_reached;
  150481. }
  150482. GLOBAL(boolean)
  150483. jpeg_has_multiple_scans (j_decompress_ptr cinfo)
  150484. {
  150485. if (cinfo->global_state < DSTATE_READY ||
  150486. cinfo->global_state > DSTATE_STOPPING)
  150487. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  150488. return cinfo->inputctl->has_multiple_scans;
  150489. }
  150490. GLOBAL(boolean)
  150491. jpeg_finish_decompress (j_decompress_ptr cinfo)
  150492. {
  150493. if ((cinfo->global_state == DSTATE_SCANNING ||
  150494. cinfo->global_state == DSTATE_RAW_OK) && ! cinfo->buffered_image) {
  150495. if (cinfo->output_scanline < cinfo->output_height)
  150496. ERREXIT(cinfo, JERR_TOO_LITTLE_DATA);
  150497. (*cinfo->master->finish_output_pass) (cinfo);
  150498. cinfo->global_state = DSTATE_STOPPING;
  150499. } else if (cinfo->global_state == DSTATE_BUFIMAGE) {
  150500. cinfo->global_state = DSTATE_STOPPING;
  150501. } else if (cinfo->global_state != DSTATE_STOPPING) {
  150502. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  150503. }
  150504. while (! cinfo->inputctl->eoi_reached) {
  150505. if ((*cinfo->inputctl->consume_input) (cinfo) == JPEG_SUSPENDED)
  150506. return FALSE; /* Suspend, come back later */
  150507. }
  150508. (*cinfo->src->term_source) (cinfo);
  150509. jpeg_abort((j_common_ptr) cinfo);
  150510. return TRUE;
  150511. }
  150512. /*** End of inlined file: jdapimin.c ***/
  150513. /*** Start of inlined file: jdatasrc.c ***/
  150514. /*** Start of inlined file: jerror.h ***/
  150515. #ifndef JMESSAGE
  150516. #ifndef JERROR_H
  150517. #define JMAKE_ENUM_LIST
  150518. #else
  150519. #define JMESSAGE(code,string)
  150520. #endif /* JERROR_H */
  150521. #endif /* JMESSAGE */
  150522. #ifdef JMAKE_ENUM_LIST
  150523. typedef enum {
  150524. #define JMESSAGE(code,string) code ,
  150525. #endif /* JMAKE_ENUM_LIST */
  150526. JMESSAGE(JMSG_NOMESSAGE, "Bogus message code %d") /* Must be first entry! */
  150527. JMESSAGE(JERR_ARITH_NOTIMPL,
  150528. "Sorry, there are legal restrictions on arithmetic coding")
  150529. JMESSAGE(JERR_BAD_ALIGN_TYPE, "ALIGN_TYPE is wrong, please fix")
  150530. JMESSAGE(JERR_BAD_ALLOC_CHUNK, "MAX_ALLOC_CHUNK is wrong, please fix")
  150531. JMESSAGE(JERR_BAD_BUFFER_MODE, "Bogus buffer control mode")
  150532. JMESSAGE(JERR_BAD_COMPONENT_ID, "Invalid component ID %d in SOS")
  150533. JMESSAGE(JERR_BAD_DCT_COEF, "DCT coefficient out of range")
  150534. JMESSAGE(JERR_BAD_DCTSIZE, "IDCT output block size %d not supported")
  150535. JMESSAGE(JERR_BAD_HUFF_TABLE, "Bogus Huffman table definition")
  150536. JMESSAGE(JERR_BAD_IN_COLORSPACE, "Bogus input colorspace")
  150537. JMESSAGE(JERR_BAD_J_COLORSPACE, "Bogus JPEG colorspace")
  150538. JMESSAGE(JERR_BAD_LENGTH, "Bogus marker length")
  150539. JMESSAGE(JERR_BAD_LIB_VERSION,
  150540. "Wrong JPEG library version: library is %d, caller expects %d")
  150541. JMESSAGE(JERR_BAD_MCU_SIZE, "Sampling factors too large for interleaved scan")
  150542. JMESSAGE(JERR_BAD_POOL_ID, "Invalid memory pool code %d")
  150543. JMESSAGE(JERR_BAD_PRECISION, "Unsupported JPEG data precision %d")
  150544. JMESSAGE(JERR_BAD_PROGRESSION,
  150545. "Invalid progressive parameters Ss=%d Se=%d Ah=%d Al=%d")
  150546. JMESSAGE(JERR_BAD_PROG_SCRIPT,
  150547. "Invalid progressive parameters at scan script entry %d")
  150548. JMESSAGE(JERR_BAD_SAMPLING, "Bogus sampling factors")
  150549. JMESSAGE(JERR_BAD_SCAN_SCRIPT, "Invalid scan script at entry %d")
  150550. JMESSAGE(JERR_BAD_STATE, "Improper call to JPEG library in state %d")
  150551. JMESSAGE(JERR_BAD_STRUCT_SIZE,
  150552. "JPEG parameter struct mismatch: library thinks size is %u, caller expects %u")
  150553. JMESSAGE(JERR_BAD_VIRTUAL_ACCESS, "Bogus virtual array access")
  150554. JMESSAGE(JERR_BUFFER_SIZE, "Buffer passed to JPEG library is too small")
  150555. JMESSAGE(JERR_CANT_SUSPEND, "Suspension not allowed here")
  150556. JMESSAGE(JERR_CCIR601_NOTIMPL, "CCIR601 sampling not implemented yet")
  150557. JMESSAGE(JERR_COMPONENT_COUNT, "Too many color components: %d, max %d")
  150558. JMESSAGE(JERR_CONVERSION_NOTIMPL, "Unsupported color conversion request")
  150559. JMESSAGE(JERR_DAC_INDEX, "Bogus DAC index %d")
  150560. JMESSAGE(JERR_DAC_VALUE, "Bogus DAC value 0x%x")
  150561. JMESSAGE(JERR_DHT_INDEX, "Bogus DHT index %d")
  150562. JMESSAGE(JERR_DQT_INDEX, "Bogus DQT index %d")
  150563. JMESSAGE(JERR_EMPTY_IMAGE, "Empty JPEG image (DNL not supported)")
  150564. JMESSAGE(JERR_EMS_READ, "Read from EMS failed")
  150565. JMESSAGE(JERR_EMS_WRITE, "Write to EMS failed")
  150566. JMESSAGE(JERR_EOI_EXPECTED, "Didn't expect more than one scan")
  150567. JMESSAGE(JERR_FILE_READ, "Input file read error")
  150568. JMESSAGE(JERR_FILE_WRITE, "Output file write error --- out of disk space?")
  150569. JMESSAGE(JERR_FRACT_SAMPLE_NOTIMPL, "Fractional sampling not implemented yet")
  150570. JMESSAGE(JERR_HUFF_CLEN_OVERFLOW, "Huffman code size table overflow")
  150571. JMESSAGE(JERR_HUFF_MISSING_CODE, "Missing Huffman code table entry")
  150572. JMESSAGE(JERR_IMAGE_TOO_BIG, "Maximum supported image dimension is %u pixels")
  150573. JMESSAGE(JERR_INPUT_EMPTY, "Empty input file")
  150574. JMESSAGE(JERR_INPUT_EOF, "Premature end of input file")
  150575. JMESSAGE(JERR_MISMATCHED_QUANT_TABLE,
  150576. "Cannot transcode due to multiple use of quantization table %d")
  150577. JMESSAGE(JERR_MISSING_DATA, "Scan script does not transmit all data")
  150578. JMESSAGE(JERR_MODE_CHANGE, "Invalid color quantization mode change")
  150579. JMESSAGE(JERR_NOTIMPL, "Not implemented yet")
  150580. JMESSAGE(JERR_NOT_COMPILED, "Requested feature was omitted at compile time")
  150581. JMESSAGE(JERR_NO_BACKING_STORE, "Backing store not supported")
  150582. JMESSAGE(JERR_NO_HUFF_TABLE, "Huffman table 0x%02x was not defined")
  150583. JMESSAGE(JERR_NO_IMAGE, "JPEG datastream contains no image")
  150584. JMESSAGE(JERR_NO_QUANT_TABLE, "Quantization table 0x%02x was not defined")
  150585. JMESSAGE(JERR_NO_SOI, "Not a JPEG file: starts with 0x%02x 0x%02x")
  150586. JMESSAGE(JERR_OUT_OF_MEMORY, "Insufficient memory (case %d)")
  150587. JMESSAGE(JERR_QUANT_COMPONENTS,
  150588. "Cannot quantize more than %d color components")
  150589. JMESSAGE(JERR_QUANT_FEW_COLORS, "Cannot quantize to fewer than %d colors")
  150590. JMESSAGE(JERR_QUANT_MANY_COLORS, "Cannot quantize to more than %d colors")
  150591. JMESSAGE(JERR_SOF_DUPLICATE, "Invalid JPEG file structure: two SOF markers")
  150592. JMESSAGE(JERR_SOF_NO_SOS, "Invalid JPEG file structure: missing SOS marker")
  150593. JMESSAGE(JERR_SOF_UNSUPPORTED, "Unsupported JPEG process: SOF type 0x%02x")
  150594. JMESSAGE(JERR_SOI_DUPLICATE, "Invalid JPEG file structure: two SOI markers")
  150595. JMESSAGE(JERR_SOS_NO_SOF, "Invalid JPEG file structure: SOS before SOF")
  150596. JMESSAGE(JERR_TFILE_CREATE, "Failed to create temporary file %s")
  150597. JMESSAGE(JERR_TFILE_READ, "Read failed on temporary file")
  150598. JMESSAGE(JERR_TFILE_SEEK, "Seek failed on temporary file")
  150599. JMESSAGE(JERR_TFILE_WRITE,
  150600. "Write failed on temporary file --- out of disk space?")
  150601. JMESSAGE(JERR_TOO_LITTLE_DATA, "Application transferred too few scanlines")
  150602. JMESSAGE(JERR_UNKNOWN_MARKER, "Unsupported marker type 0x%02x")
  150603. JMESSAGE(JERR_VIRTUAL_BUG, "Virtual array controller messed up")
  150604. JMESSAGE(JERR_WIDTH_OVERFLOW, "Image too wide for this implementation")
  150605. JMESSAGE(JERR_XMS_READ, "Read from XMS failed")
  150606. JMESSAGE(JERR_XMS_WRITE, "Write to XMS failed")
  150607. JMESSAGE(JMSG_COPYRIGHT, JCOPYRIGHT)
  150608. JMESSAGE(JMSG_VERSION, JVERSION)
  150609. JMESSAGE(JTRC_16BIT_TABLES,
  150610. "Caution: quantization tables are too coarse for baseline JPEG")
  150611. JMESSAGE(JTRC_ADOBE,
  150612. "Adobe APP14 marker: version %d, flags 0x%04x 0x%04x, transform %d")
  150613. JMESSAGE(JTRC_APP0, "Unknown APP0 marker (not JFIF), length %u")
  150614. JMESSAGE(JTRC_APP14, "Unknown APP14 marker (not Adobe), length %u")
  150615. JMESSAGE(JTRC_DAC, "Define Arithmetic Table 0x%02x: 0x%02x")
  150616. JMESSAGE(JTRC_DHT, "Define Huffman Table 0x%02x")
  150617. JMESSAGE(JTRC_DQT, "Define Quantization Table %d precision %d")
  150618. JMESSAGE(JTRC_DRI, "Define Restart Interval %u")
  150619. JMESSAGE(JTRC_EMS_CLOSE, "Freed EMS handle %u")
  150620. JMESSAGE(JTRC_EMS_OPEN, "Obtained EMS handle %u")
  150621. JMESSAGE(JTRC_EOI, "End Of Image")
  150622. JMESSAGE(JTRC_HUFFBITS, " %3d %3d %3d %3d %3d %3d %3d %3d")
  150623. JMESSAGE(JTRC_JFIF, "JFIF APP0 marker: version %d.%02d, density %dx%d %d")
  150624. JMESSAGE(JTRC_JFIF_BADTHUMBNAILSIZE,
  150625. "Warning: thumbnail image size does not match data length %u")
  150626. JMESSAGE(JTRC_JFIF_EXTENSION,
  150627. "JFIF extension marker: type 0x%02x, length %u")
  150628. JMESSAGE(JTRC_JFIF_THUMBNAIL, " with %d x %d thumbnail image")
  150629. JMESSAGE(JTRC_MISC_MARKER, "Miscellaneous marker 0x%02x, length %u")
  150630. JMESSAGE(JTRC_PARMLESS_MARKER, "Unexpected marker 0x%02x")
  150631. JMESSAGE(JTRC_QUANTVALS, " %4u %4u %4u %4u %4u %4u %4u %4u")
  150632. JMESSAGE(JTRC_QUANT_3_NCOLORS, "Quantizing to %d = %d*%d*%d colors")
  150633. JMESSAGE(JTRC_QUANT_NCOLORS, "Quantizing to %d colors")
  150634. JMESSAGE(JTRC_QUANT_SELECTED, "Selected %d colors for quantization")
  150635. JMESSAGE(JTRC_RECOVERY_ACTION, "At marker 0x%02x, recovery action %d")
  150636. JMESSAGE(JTRC_RST, "RST%d")
  150637. JMESSAGE(JTRC_SMOOTH_NOTIMPL,
  150638. "Smoothing not supported with nonstandard sampling ratios")
  150639. JMESSAGE(JTRC_SOF, "Start Of Frame 0x%02x: width=%u, height=%u, components=%d")
  150640. JMESSAGE(JTRC_SOF_COMPONENT, " Component %d: %dhx%dv q=%d")
  150641. JMESSAGE(JTRC_SOI, "Start of Image")
  150642. JMESSAGE(JTRC_SOS, "Start Of Scan: %d components")
  150643. JMESSAGE(JTRC_SOS_COMPONENT, " Component %d: dc=%d ac=%d")
  150644. JMESSAGE(JTRC_SOS_PARAMS, " Ss=%d, Se=%d, Ah=%d, Al=%d")
  150645. JMESSAGE(JTRC_TFILE_CLOSE, "Closed temporary file %s")
  150646. JMESSAGE(JTRC_TFILE_OPEN, "Opened temporary file %s")
  150647. JMESSAGE(JTRC_THUMB_JPEG,
  150648. "JFIF extension marker: JPEG-compressed thumbnail image, length %u")
  150649. JMESSAGE(JTRC_THUMB_PALETTE,
  150650. "JFIF extension marker: palette thumbnail image, length %u")
  150651. JMESSAGE(JTRC_THUMB_RGB,
  150652. "JFIF extension marker: RGB thumbnail image, length %u")
  150653. JMESSAGE(JTRC_UNKNOWN_IDS,
  150654. "Unrecognized component IDs %d %d %d, assuming YCbCr")
  150655. JMESSAGE(JTRC_XMS_CLOSE, "Freed XMS handle %u")
  150656. JMESSAGE(JTRC_XMS_OPEN, "Obtained XMS handle %u")
  150657. JMESSAGE(JWRN_ADOBE_XFORM, "Unknown Adobe color transform code %d")
  150658. JMESSAGE(JWRN_BOGUS_PROGRESSION,
  150659. "Inconsistent progression sequence for component %d coefficient %d")
  150660. JMESSAGE(JWRN_EXTRANEOUS_DATA,
  150661. "Corrupt JPEG data: %u extraneous bytes before marker 0x%02x")
  150662. JMESSAGE(JWRN_HIT_MARKER, "Corrupt JPEG data: premature end of data segment")
  150663. JMESSAGE(JWRN_HUFF_BAD_CODE, "Corrupt JPEG data: bad Huffman code")
  150664. JMESSAGE(JWRN_JFIF_MAJOR, "Warning: unknown JFIF revision number %d.%02d")
  150665. JMESSAGE(JWRN_JPEG_EOF, "Premature end of JPEG file")
  150666. JMESSAGE(JWRN_MUST_RESYNC,
  150667. "Corrupt JPEG data: found marker 0x%02x instead of RST%d")
  150668. JMESSAGE(JWRN_NOT_SEQUENTIAL, "Invalid SOS parameters for sequential JPEG")
  150669. JMESSAGE(JWRN_TOO_MUCH_DATA, "Application transferred too many scanlines")
  150670. #ifdef JMAKE_ENUM_LIST
  150671. JMSG_LASTMSGCODE
  150672. } J_MESSAGE_CODE;
  150673. #undef JMAKE_ENUM_LIST
  150674. #endif /* JMAKE_ENUM_LIST */
  150675. #undef JMESSAGE
  150676. #ifndef JERROR_H
  150677. #define JERROR_H
  150678. #define ERREXIT(cinfo,code) \
  150679. ((cinfo)->err->msg_code = (code), \
  150680. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  150681. #define ERREXIT1(cinfo,code,p1) \
  150682. ((cinfo)->err->msg_code = (code), \
  150683. (cinfo)->err->msg_parm.i[0] = (p1), \
  150684. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  150685. #define ERREXIT2(cinfo,code,p1,p2) \
  150686. ((cinfo)->err->msg_code = (code), \
  150687. (cinfo)->err->msg_parm.i[0] = (p1), \
  150688. (cinfo)->err->msg_parm.i[1] = (p2), \
  150689. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  150690. #define ERREXIT3(cinfo,code,p1,p2,p3) \
  150691. ((cinfo)->err->msg_code = (code), \
  150692. (cinfo)->err->msg_parm.i[0] = (p1), \
  150693. (cinfo)->err->msg_parm.i[1] = (p2), \
  150694. (cinfo)->err->msg_parm.i[2] = (p3), \
  150695. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  150696. #define ERREXIT4(cinfo,code,p1,p2,p3,p4) \
  150697. ((cinfo)->err->msg_code = (code), \
  150698. (cinfo)->err->msg_parm.i[0] = (p1), \
  150699. (cinfo)->err->msg_parm.i[1] = (p2), \
  150700. (cinfo)->err->msg_parm.i[2] = (p3), \
  150701. (cinfo)->err->msg_parm.i[3] = (p4), \
  150702. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  150703. #define ERREXITS(cinfo,code,str) \
  150704. ((cinfo)->err->msg_code = (code), \
  150705. strncpy((cinfo)->err->msg_parm.s, (str), JMSG_STR_PARM_MAX), \
  150706. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  150707. #define MAKESTMT(stuff) do { stuff } while (0)
  150708. #define WARNMS(cinfo,code) \
  150709. ((cinfo)->err->msg_code = (code), \
  150710. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), -1))
  150711. #define WARNMS1(cinfo,code,p1) \
  150712. ((cinfo)->err->msg_code = (code), \
  150713. (cinfo)->err->msg_parm.i[0] = (p1), \
  150714. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), -1))
  150715. #define WARNMS2(cinfo,code,p1,p2) \
  150716. ((cinfo)->err->msg_code = (code), \
  150717. (cinfo)->err->msg_parm.i[0] = (p1), \
  150718. (cinfo)->err->msg_parm.i[1] = (p2), \
  150719. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), -1))
  150720. #define TRACEMS(cinfo,lvl,code) \
  150721. ((cinfo)->err->msg_code = (code), \
  150722. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)))
  150723. #define TRACEMS1(cinfo,lvl,code,p1) \
  150724. ((cinfo)->err->msg_code = (code), \
  150725. (cinfo)->err->msg_parm.i[0] = (p1), \
  150726. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)))
  150727. #define TRACEMS2(cinfo,lvl,code,p1,p2) \
  150728. ((cinfo)->err->msg_code = (code), \
  150729. (cinfo)->err->msg_parm.i[0] = (p1), \
  150730. (cinfo)->err->msg_parm.i[1] = (p2), \
  150731. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)))
  150732. #define TRACEMS3(cinfo,lvl,code,p1,p2,p3) \
  150733. MAKESTMT(int * _mp = (cinfo)->err->msg_parm.i; \
  150734. _mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); \
  150735. (cinfo)->err->msg_code = (code); \
  150736. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)); )
  150737. #define TRACEMS4(cinfo,lvl,code,p1,p2,p3,p4) \
  150738. MAKESTMT(int * _mp = (cinfo)->err->msg_parm.i; \
  150739. _mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); _mp[3] = (p4); \
  150740. (cinfo)->err->msg_code = (code); \
  150741. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)); )
  150742. #define TRACEMS5(cinfo,lvl,code,p1,p2,p3,p4,p5) \
  150743. MAKESTMT(int * _mp = (cinfo)->err->msg_parm.i; \
  150744. _mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); _mp[3] = (p4); \
  150745. _mp[4] = (p5); \
  150746. (cinfo)->err->msg_code = (code); \
  150747. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)); )
  150748. #define TRACEMS8(cinfo,lvl,code,p1,p2,p3,p4,p5,p6,p7,p8) \
  150749. MAKESTMT(int * _mp = (cinfo)->err->msg_parm.i; \
  150750. _mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); _mp[3] = (p4); \
  150751. _mp[4] = (p5); _mp[5] = (p6); _mp[6] = (p7); _mp[7] = (p8); \
  150752. (cinfo)->err->msg_code = (code); \
  150753. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)); )
  150754. #define TRACEMSS(cinfo,lvl,code,str) \
  150755. ((cinfo)->err->msg_code = (code), \
  150756. strncpy((cinfo)->err->msg_parm.s, (str), JMSG_STR_PARM_MAX), \
  150757. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)))
  150758. #endif /* JERROR_H */
  150759. /*** End of inlined file: jerror.h ***/
  150760. typedef struct {
  150761. struct jpeg_source_mgr pub; /* public fields */
  150762. FILE * infile; /* source stream */
  150763. JOCTET * buffer; /* start of buffer */
  150764. boolean start_of_file; /* have we gotten any data yet? */
  150765. } my_source_mgr;
  150766. typedef my_source_mgr * my_src_ptr;
  150767. #define INPUT_BUF_SIZE 4096 /* choose an efficiently fread'able size */
  150768. METHODDEF(void)
  150769. init_source (j_decompress_ptr cinfo)
  150770. {
  150771. my_src_ptr src = (my_src_ptr) cinfo->src;
  150772. src->start_of_file = TRUE;
  150773. }
  150774. METHODDEF(boolean)
  150775. fill_input_buffer (j_decompress_ptr cinfo)
  150776. {
  150777. my_src_ptr src = (my_src_ptr) cinfo->src;
  150778. size_t nbytes;
  150779. nbytes = JFREAD(src->infile, src->buffer, INPUT_BUF_SIZE);
  150780. if (nbytes <= 0) {
  150781. if (src->start_of_file) /* Treat empty input file as fatal error */
  150782. ERREXIT(cinfo, JERR_INPUT_EMPTY);
  150783. WARNMS(cinfo, JWRN_JPEG_EOF);
  150784. src->buffer[0] = (JOCTET) 0xFF;
  150785. src->buffer[1] = (JOCTET) JPEG_EOI;
  150786. nbytes = 2;
  150787. }
  150788. src->pub.next_input_byte = src->buffer;
  150789. src->pub.bytes_in_buffer = nbytes;
  150790. src->start_of_file = FALSE;
  150791. return TRUE;
  150792. }
  150793. METHODDEF(void)
  150794. skip_input_data (j_decompress_ptr cinfo, long num_bytes)
  150795. {
  150796. my_src_ptr src = (my_src_ptr) cinfo->src;
  150797. if (num_bytes > 0) {
  150798. while (num_bytes > (long) src->pub.bytes_in_buffer) {
  150799. num_bytes -= (long) src->pub.bytes_in_buffer;
  150800. (void) fill_input_buffer(cinfo);
  150801. }
  150802. src->pub.next_input_byte += (size_t) num_bytes;
  150803. src->pub.bytes_in_buffer -= (size_t) num_bytes;
  150804. }
  150805. }
  150806. METHODDEF(void)
  150807. term_source (j_decompress_ptr cinfo)
  150808. {
  150809. }
  150810. GLOBAL(void)
  150811. jpeg_stdio_src (j_decompress_ptr cinfo, FILE * infile)
  150812. {
  150813. my_src_ptr src;
  150814. if (cinfo->src == NULL) { /* first time for this JPEG object? */
  150815. cinfo->src = (struct jpeg_source_mgr *)
  150816. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
  150817. SIZEOF(my_source_mgr));
  150818. src = (my_src_ptr) cinfo->src;
  150819. src->buffer = (JOCTET *)
  150820. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
  150821. INPUT_BUF_SIZE * SIZEOF(JOCTET));
  150822. }
  150823. src = (my_src_ptr) cinfo->src;
  150824. src->pub.init_source = init_source;
  150825. src->pub.fill_input_buffer = fill_input_buffer;
  150826. src->pub.skip_input_data = skip_input_data;
  150827. src->pub.resync_to_restart = jpeg_resync_to_restart; /* use default method */
  150828. src->pub.term_source = term_source;
  150829. src->infile = infile;
  150830. src->pub.bytes_in_buffer = 0; /* forces fill_input_buffer on first read */
  150831. src->pub.next_input_byte = NULL; /* until buffer loaded */
  150832. }
  150833. /*** End of inlined file: jdatasrc.c ***/
  150834. /*** Start of inlined file: jdcoefct.c ***/
  150835. #define JPEG_INTERNALS
  150836. #ifndef D_PROGRESSIVE_SUPPORTED
  150837. #undef BLOCK_SMOOTHING_SUPPORTED
  150838. #endif
  150839. typedef struct {
  150840. struct jpeg_d_coef_controller pub; /* public fields */
  150841. JDIMENSION MCU_ctr; /* counts MCUs processed in current row */
  150842. int MCU_vert_offset; /* counts MCU rows within iMCU row */
  150843. int MCU_rows_per_iMCU_row; /* number of such rows needed */
  150844. JBLOCKROW MCU_buffer[D_MAX_BLOCKS_IN_MCU];
  150845. #ifdef D_MULTISCAN_FILES_SUPPORTED
  150846. jvirt_barray_ptr whole_image[MAX_COMPONENTS];
  150847. #endif
  150848. #ifdef BLOCK_SMOOTHING_SUPPORTED
  150849. int * coef_bits_latch;
  150850. #define SAVED_COEFS 6 /* we save coef_bits[0..5] */
  150851. #endif
  150852. } my_coef_controller3;
  150853. typedef my_coef_controller3 * my_coef_ptr3;
  150854. METHODDEF(int) decompress_onepass
  150855. JPP((j_decompress_ptr cinfo, JSAMPIMAGE output_buf));
  150856. #ifdef D_MULTISCAN_FILES_SUPPORTED
  150857. METHODDEF(int) decompress_data
  150858. JPP((j_decompress_ptr cinfo, JSAMPIMAGE output_buf));
  150859. #endif
  150860. #ifdef BLOCK_SMOOTHING_SUPPORTED
  150861. LOCAL(boolean) smoothing_ok JPP((j_decompress_ptr cinfo));
  150862. METHODDEF(int) decompress_smooth_data
  150863. JPP((j_decompress_ptr cinfo, JSAMPIMAGE output_buf));
  150864. #endif
  150865. LOCAL(void)
  150866. start_iMCU_row3 (j_decompress_ptr cinfo)
  150867. {
  150868. my_coef_ptr3 coef = (my_coef_ptr3) cinfo->coef;
  150869. if (cinfo->comps_in_scan > 1) {
  150870. coef->MCU_rows_per_iMCU_row = 1;
  150871. } else {
  150872. if (cinfo->input_iMCU_row < (cinfo->total_iMCU_rows-1))
  150873. coef->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
  150874. else
  150875. coef->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
  150876. }
  150877. coef->MCU_ctr = 0;
  150878. coef->MCU_vert_offset = 0;
  150879. }
  150880. METHODDEF(void)
  150881. start_input_pass (j_decompress_ptr cinfo)
  150882. {
  150883. cinfo->input_iMCU_row = 0;
  150884. start_iMCU_row3(cinfo);
  150885. }
  150886. METHODDEF(void)
  150887. start_output_pass (j_decompress_ptr cinfo)
  150888. {
  150889. #ifdef BLOCK_SMOOTHING_SUPPORTED
  150890. my_coef_ptr3 coef = (my_coef_ptr3) cinfo->coef;
  150891. if (coef->pub.coef_arrays != NULL) {
  150892. if (cinfo->do_block_smoothing && smoothing_ok(cinfo))
  150893. coef->pub.decompress_data = decompress_smooth_data;
  150894. else
  150895. coef->pub.decompress_data = decompress_data;
  150896. }
  150897. #endif
  150898. cinfo->output_iMCU_row = 0;
  150899. }
  150900. METHODDEF(int)
  150901. decompress_onepass (j_decompress_ptr cinfo, JSAMPIMAGE output_buf)
  150902. {
  150903. my_coef_ptr3 coef = (my_coef_ptr3) cinfo->coef;
  150904. JDIMENSION MCU_col_num; /* index of current MCU within row */
  150905. JDIMENSION last_MCU_col = cinfo->MCUs_per_row - 1;
  150906. JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
  150907. int blkn, ci, xindex, yindex, yoffset, useful_width;
  150908. JSAMPARRAY output_ptr;
  150909. JDIMENSION start_col, output_col;
  150910. jpeg_component_info *compptr;
  150911. inverse_DCT_method_ptr inverse_DCT;
  150912. for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
  150913. yoffset++) {
  150914. for (MCU_col_num = coef->MCU_ctr; MCU_col_num <= last_MCU_col;
  150915. MCU_col_num++) {
  150916. jzero_far((void FAR *) coef->MCU_buffer[0],
  150917. (size_t) (cinfo->blocks_in_MCU * SIZEOF(JBLOCK)));
  150918. if (! (*cinfo->entropy->decode_mcu) (cinfo, coef->MCU_buffer)) {
  150919. coef->MCU_vert_offset = yoffset;
  150920. coef->MCU_ctr = MCU_col_num;
  150921. return JPEG_SUSPENDED;
  150922. }
  150923. blkn = 0; /* index of current DCT block within MCU */
  150924. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  150925. compptr = cinfo->cur_comp_info[ci];
  150926. if (! compptr->component_needed) {
  150927. blkn += compptr->MCU_blocks;
  150928. continue;
  150929. }
  150930. inverse_DCT = cinfo->idct->inverse_DCT[compptr->component_index];
  150931. useful_width = (MCU_col_num < last_MCU_col) ? compptr->MCU_width
  150932. : compptr->last_col_width;
  150933. output_ptr = output_buf[compptr->component_index] +
  150934. yoffset * compptr->DCT_scaled_size;
  150935. start_col = MCU_col_num * compptr->MCU_sample_width;
  150936. for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
  150937. if (cinfo->input_iMCU_row < last_iMCU_row ||
  150938. yoffset+yindex < compptr->last_row_height) {
  150939. output_col = start_col;
  150940. for (xindex = 0; xindex < useful_width; xindex++) {
  150941. (*inverse_DCT) (cinfo, compptr,
  150942. (JCOEFPTR) coef->MCU_buffer[blkn+xindex],
  150943. output_ptr, output_col);
  150944. output_col += compptr->DCT_scaled_size;
  150945. }
  150946. }
  150947. blkn += compptr->MCU_width;
  150948. output_ptr += compptr->DCT_scaled_size;
  150949. }
  150950. }
  150951. }
  150952. coef->MCU_ctr = 0;
  150953. }
  150954. cinfo->output_iMCU_row++;
  150955. if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
  150956. start_iMCU_row3(cinfo);
  150957. return JPEG_ROW_COMPLETED;
  150958. }
  150959. (*cinfo->inputctl->finish_input_pass) (cinfo);
  150960. return JPEG_SCAN_COMPLETED;
  150961. }
  150962. METHODDEF(int)
  150963. dummy_consume_data (j_decompress_ptr cinfo)
  150964. {
  150965. return JPEG_SUSPENDED; /* Always indicate nothing was done */
  150966. }
  150967. #ifdef D_MULTISCAN_FILES_SUPPORTED
  150968. METHODDEF(int)
  150969. consume_data (j_decompress_ptr cinfo)
  150970. {
  150971. my_coef_ptr3 coef = (my_coef_ptr3) cinfo->coef;
  150972. JDIMENSION MCU_col_num; /* index of current MCU within row */
  150973. int blkn, ci, xindex, yindex, yoffset;
  150974. JDIMENSION start_col;
  150975. JBLOCKARRAY buffer[MAX_COMPS_IN_SCAN];
  150976. JBLOCKROW buffer_ptr;
  150977. jpeg_component_info *compptr;
  150978. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  150979. compptr = cinfo->cur_comp_info[ci];
  150980. buffer[ci] = (*cinfo->mem->access_virt_barray)
  150981. ((j_common_ptr) cinfo, coef->whole_image[compptr->component_index],
  150982. cinfo->input_iMCU_row * compptr->v_samp_factor,
  150983. (JDIMENSION) compptr->v_samp_factor, TRUE);
  150984. }
  150985. for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
  150986. yoffset++) {
  150987. for (MCU_col_num = coef->MCU_ctr; MCU_col_num < cinfo->MCUs_per_row;
  150988. MCU_col_num++) {
  150989. blkn = 0; /* index of current DCT block within MCU */
  150990. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  150991. compptr = cinfo->cur_comp_info[ci];
  150992. start_col = MCU_col_num * compptr->MCU_width;
  150993. for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
  150994. buffer_ptr = buffer[ci][yindex+yoffset] + start_col;
  150995. for (xindex = 0; xindex < compptr->MCU_width; xindex++) {
  150996. coef->MCU_buffer[blkn++] = buffer_ptr++;
  150997. }
  150998. }
  150999. }
  151000. if (! (*cinfo->entropy->decode_mcu) (cinfo, coef->MCU_buffer)) {
  151001. coef->MCU_vert_offset = yoffset;
  151002. coef->MCU_ctr = MCU_col_num;
  151003. return JPEG_SUSPENDED;
  151004. }
  151005. }
  151006. coef->MCU_ctr = 0;
  151007. }
  151008. if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
  151009. start_iMCU_row3(cinfo);
  151010. return JPEG_ROW_COMPLETED;
  151011. }
  151012. (*cinfo->inputctl->finish_input_pass) (cinfo);
  151013. return JPEG_SCAN_COMPLETED;
  151014. }
  151015. METHODDEF(int)
  151016. decompress_data (j_decompress_ptr cinfo, JSAMPIMAGE output_buf)
  151017. {
  151018. my_coef_ptr3 coef = (my_coef_ptr3) cinfo->coef;
  151019. JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
  151020. JDIMENSION block_num;
  151021. int ci, block_row, block_rows;
  151022. JBLOCKARRAY buffer;
  151023. JBLOCKROW buffer_ptr;
  151024. JSAMPARRAY output_ptr;
  151025. JDIMENSION output_col;
  151026. jpeg_component_info *compptr;
  151027. inverse_DCT_method_ptr inverse_DCT;
  151028. while (cinfo->input_scan_number < cinfo->output_scan_number ||
  151029. (cinfo->input_scan_number == cinfo->output_scan_number &&
  151030. cinfo->input_iMCU_row <= cinfo->output_iMCU_row)) {
  151031. if ((*cinfo->inputctl->consume_input)(cinfo) == JPEG_SUSPENDED)
  151032. return JPEG_SUSPENDED;
  151033. }
  151034. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  151035. ci++, compptr++) {
  151036. if (! compptr->component_needed)
  151037. continue;
  151038. buffer = (*cinfo->mem->access_virt_barray)
  151039. ((j_common_ptr) cinfo, coef->whole_image[ci],
  151040. cinfo->output_iMCU_row * compptr->v_samp_factor,
  151041. (JDIMENSION) compptr->v_samp_factor, FALSE);
  151042. if (cinfo->output_iMCU_row < last_iMCU_row)
  151043. block_rows = compptr->v_samp_factor;
  151044. else {
  151045. block_rows = (int) (compptr->height_in_blocks % compptr->v_samp_factor);
  151046. if (block_rows == 0) block_rows = compptr->v_samp_factor;
  151047. }
  151048. inverse_DCT = cinfo->idct->inverse_DCT[ci];
  151049. output_ptr = output_buf[ci];
  151050. for (block_row = 0; block_row < block_rows; block_row++) {
  151051. buffer_ptr = buffer[block_row];
  151052. output_col = 0;
  151053. for (block_num = 0; block_num < compptr->width_in_blocks; block_num++) {
  151054. (*inverse_DCT) (cinfo, compptr, (JCOEFPTR) buffer_ptr,
  151055. output_ptr, output_col);
  151056. buffer_ptr++;
  151057. output_col += compptr->DCT_scaled_size;
  151058. }
  151059. output_ptr += compptr->DCT_scaled_size;
  151060. }
  151061. }
  151062. if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
  151063. return JPEG_ROW_COMPLETED;
  151064. return JPEG_SCAN_COMPLETED;
  151065. }
  151066. #endif /* D_MULTISCAN_FILES_SUPPORTED */
  151067. #ifdef BLOCK_SMOOTHING_SUPPORTED
  151068. #define Q01_POS 1
  151069. #define Q10_POS 8
  151070. #define Q20_POS 16
  151071. #define Q11_POS 9
  151072. #define Q02_POS 2
  151073. LOCAL(boolean)
  151074. smoothing_ok (j_decompress_ptr cinfo)
  151075. {
  151076. my_coef_ptr3 coef = (my_coef_ptr3) cinfo->coef;
  151077. boolean smoothing_useful = FALSE;
  151078. int ci, coefi;
  151079. jpeg_component_info *compptr;
  151080. JQUANT_TBL * qtable;
  151081. int * coef_bits;
  151082. int * coef_bits_latch;
  151083. if (! cinfo->progressive_mode || cinfo->coef_bits == NULL)
  151084. return FALSE;
  151085. if (coef->coef_bits_latch == NULL)
  151086. coef->coef_bits_latch = (int *)
  151087. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  151088. cinfo->num_components *
  151089. (SAVED_COEFS * SIZEOF(int)));
  151090. coef_bits_latch = coef->coef_bits_latch;
  151091. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  151092. ci++, compptr++) {
  151093. if ((qtable = compptr->quant_table) == NULL)
  151094. return FALSE;
  151095. if (qtable->quantval[0] == 0 ||
  151096. qtable->quantval[Q01_POS] == 0 ||
  151097. qtable->quantval[Q10_POS] == 0 ||
  151098. qtable->quantval[Q20_POS] == 0 ||
  151099. qtable->quantval[Q11_POS] == 0 ||
  151100. qtable->quantval[Q02_POS] == 0)
  151101. return FALSE;
  151102. coef_bits = cinfo->coef_bits[ci];
  151103. if (coef_bits[0] < 0)
  151104. return FALSE;
  151105. for (coefi = 1; coefi <= 5; coefi++) {
  151106. coef_bits_latch[coefi] = coef_bits[coefi];
  151107. if (coef_bits[coefi] != 0)
  151108. smoothing_useful = TRUE;
  151109. }
  151110. coef_bits_latch += SAVED_COEFS;
  151111. }
  151112. return smoothing_useful;
  151113. }
  151114. METHODDEF(int)
  151115. decompress_smooth_data (j_decompress_ptr cinfo, JSAMPIMAGE output_buf)
  151116. {
  151117. my_coef_ptr3 coef = (my_coef_ptr3) cinfo->coef;
  151118. JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
  151119. JDIMENSION block_num, last_block_column;
  151120. int ci, block_row, block_rows, access_rows;
  151121. JBLOCKARRAY buffer;
  151122. JBLOCKROW buffer_ptr, prev_block_row, next_block_row;
  151123. JSAMPARRAY output_ptr;
  151124. JDIMENSION output_col;
  151125. jpeg_component_info *compptr;
  151126. inverse_DCT_method_ptr inverse_DCT;
  151127. boolean first_row, last_row;
  151128. JBLOCK workspace;
  151129. int *coef_bits;
  151130. JQUANT_TBL *quanttbl;
  151131. INT32 Q00,Q01,Q02,Q10,Q11,Q20, num;
  151132. int DC1,DC2,DC3,DC4,DC5,DC6,DC7,DC8,DC9;
  151133. int Al, pred;
  151134. while (cinfo->input_scan_number <= cinfo->output_scan_number &&
  151135. ! cinfo->inputctl->eoi_reached) {
  151136. if (cinfo->input_scan_number == cinfo->output_scan_number) {
  151137. JDIMENSION delta = (cinfo->Ss == 0) ? 1 : 0;
  151138. if (cinfo->input_iMCU_row > cinfo->output_iMCU_row+delta)
  151139. break;
  151140. }
  151141. if ((*cinfo->inputctl->consume_input)(cinfo) == JPEG_SUSPENDED)
  151142. return JPEG_SUSPENDED;
  151143. }
  151144. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  151145. ci++, compptr++) {
  151146. if (! compptr->component_needed)
  151147. continue;
  151148. if (cinfo->output_iMCU_row < last_iMCU_row) {
  151149. block_rows = compptr->v_samp_factor;
  151150. access_rows = block_rows * 2; /* this and next iMCU row */
  151151. last_row = FALSE;
  151152. } else {
  151153. block_rows = (int) (compptr->height_in_blocks % compptr->v_samp_factor);
  151154. if (block_rows == 0) block_rows = compptr->v_samp_factor;
  151155. access_rows = block_rows; /* this iMCU row only */
  151156. last_row = TRUE;
  151157. }
  151158. if (cinfo->output_iMCU_row > 0) {
  151159. access_rows += compptr->v_samp_factor; /* prior iMCU row too */
  151160. buffer = (*cinfo->mem->access_virt_barray)
  151161. ((j_common_ptr) cinfo, coef->whole_image[ci],
  151162. (cinfo->output_iMCU_row - 1) * compptr->v_samp_factor,
  151163. (JDIMENSION) access_rows, FALSE);
  151164. buffer += compptr->v_samp_factor; /* point to current iMCU row */
  151165. first_row = FALSE;
  151166. } else {
  151167. buffer = (*cinfo->mem->access_virt_barray)
  151168. ((j_common_ptr) cinfo, coef->whole_image[ci],
  151169. (JDIMENSION) 0, (JDIMENSION) access_rows, FALSE);
  151170. first_row = TRUE;
  151171. }
  151172. coef_bits = coef->coef_bits_latch + (ci * SAVED_COEFS);
  151173. quanttbl = compptr->quant_table;
  151174. Q00 = quanttbl->quantval[0];
  151175. Q01 = quanttbl->quantval[Q01_POS];
  151176. Q10 = quanttbl->quantval[Q10_POS];
  151177. Q20 = quanttbl->quantval[Q20_POS];
  151178. Q11 = quanttbl->quantval[Q11_POS];
  151179. Q02 = quanttbl->quantval[Q02_POS];
  151180. inverse_DCT = cinfo->idct->inverse_DCT[ci];
  151181. output_ptr = output_buf[ci];
  151182. for (block_row = 0; block_row < block_rows; block_row++) {
  151183. buffer_ptr = buffer[block_row];
  151184. if (first_row && block_row == 0)
  151185. prev_block_row = buffer_ptr;
  151186. else
  151187. prev_block_row = buffer[block_row-1];
  151188. if (last_row && block_row == block_rows-1)
  151189. next_block_row = buffer_ptr;
  151190. else
  151191. next_block_row = buffer[block_row+1];
  151192. DC1 = DC2 = DC3 = (int) prev_block_row[0][0];
  151193. DC4 = DC5 = DC6 = (int) buffer_ptr[0][0];
  151194. DC7 = DC8 = DC9 = (int) next_block_row[0][0];
  151195. output_col = 0;
  151196. last_block_column = compptr->width_in_blocks - 1;
  151197. for (block_num = 0; block_num <= last_block_column; block_num++) {
  151198. jcopy_block_row(buffer_ptr, (JBLOCKROW) workspace, (JDIMENSION) 1);
  151199. if (block_num < last_block_column) {
  151200. DC3 = (int) prev_block_row[1][0];
  151201. DC6 = (int) buffer_ptr[1][0];
  151202. DC9 = (int) next_block_row[1][0];
  151203. }
  151204. if ((Al=coef_bits[1]) != 0 && workspace[1] == 0) {
  151205. num = 36 * Q00 * (DC4 - DC6);
  151206. if (num >= 0) {
  151207. pred = (int) (((Q01<<7) + num) / (Q01<<8));
  151208. if (Al > 0 && pred >= (1<<Al))
  151209. pred = (1<<Al)-1;
  151210. } else {
  151211. pred = (int) (((Q01<<7) - num) / (Q01<<8));
  151212. if (Al > 0 && pred >= (1<<Al))
  151213. pred = (1<<Al)-1;
  151214. pred = -pred;
  151215. }
  151216. workspace[1] = (JCOEF) pred;
  151217. }
  151218. if ((Al=coef_bits[2]) != 0 && workspace[8] == 0) {
  151219. num = 36 * Q00 * (DC2 - DC8);
  151220. if (num >= 0) {
  151221. pred = (int) (((Q10<<7) + num) / (Q10<<8));
  151222. if (Al > 0 && pred >= (1<<Al))
  151223. pred = (1<<Al)-1;
  151224. } else {
  151225. pred = (int) (((Q10<<7) - num) / (Q10<<8));
  151226. if (Al > 0 && pred >= (1<<Al))
  151227. pred = (1<<Al)-1;
  151228. pred = -pred;
  151229. }
  151230. workspace[8] = (JCOEF) pred;
  151231. }
  151232. if ((Al=coef_bits[3]) != 0 && workspace[16] == 0) {
  151233. num = 9 * Q00 * (DC2 + DC8 - 2*DC5);
  151234. if (num >= 0) {
  151235. pred = (int) (((Q20<<7) + num) / (Q20<<8));
  151236. if (Al > 0 && pred >= (1<<Al))
  151237. pred = (1<<Al)-1;
  151238. } else {
  151239. pred = (int) (((Q20<<7) - num) / (Q20<<8));
  151240. if (Al > 0 && pred >= (1<<Al))
  151241. pred = (1<<Al)-1;
  151242. pred = -pred;
  151243. }
  151244. workspace[16] = (JCOEF) pred;
  151245. }
  151246. if ((Al=coef_bits[4]) != 0 && workspace[9] == 0) {
  151247. num = 5 * Q00 * (DC1 - DC3 - DC7 + DC9);
  151248. if (num >= 0) {
  151249. pred = (int) (((Q11<<7) + num) / (Q11<<8));
  151250. if (Al > 0 && pred >= (1<<Al))
  151251. pred = (1<<Al)-1;
  151252. } else {
  151253. pred = (int) (((Q11<<7) - num) / (Q11<<8));
  151254. if (Al > 0 && pred >= (1<<Al))
  151255. pred = (1<<Al)-1;
  151256. pred = -pred;
  151257. }
  151258. workspace[9] = (JCOEF) pred;
  151259. }
  151260. if ((Al=coef_bits[5]) != 0 && workspace[2] == 0) {
  151261. num = 9 * Q00 * (DC4 + DC6 - 2*DC5);
  151262. if (num >= 0) {
  151263. pred = (int) (((Q02<<7) + num) / (Q02<<8));
  151264. if (Al > 0 && pred >= (1<<Al))
  151265. pred = (1<<Al)-1;
  151266. } else {
  151267. pred = (int) (((Q02<<7) - num) / (Q02<<8));
  151268. if (Al > 0 && pred >= (1<<Al))
  151269. pred = (1<<Al)-1;
  151270. pred = -pred;
  151271. }
  151272. workspace[2] = (JCOEF) pred;
  151273. }
  151274. (*inverse_DCT) (cinfo, compptr, (JCOEFPTR) workspace,
  151275. output_ptr, output_col);
  151276. DC1 = DC2; DC2 = DC3;
  151277. DC4 = DC5; DC5 = DC6;
  151278. DC7 = DC8; DC8 = DC9;
  151279. buffer_ptr++, prev_block_row++, next_block_row++;
  151280. output_col += compptr->DCT_scaled_size;
  151281. }
  151282. output_ptr += compptr->DCT_scaled_size;
  151283. }
  151284. }
  151285. if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
  151286. return JPEG_ROW_COMPLETED;
  151287. return JPEG_SCAN_COMPLETED;
  151288. }
  151289. #endif /* BLOCK_SMOOTHING_SUPPORTED */
  151290. GLOBAL(void)
  151291. jinit_d_coef_controller (j_decompress_ptr cinfo, boolean need_full_buffer)
  151292. {
  151293. my_coef_ptr3 coef;
  151294. coef = (my_coef_ptr3)
  151295. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  151296. SIZEOF(my_coef_controller3));
  151297. cinfo->coef = (struct jpeg_d_coef_controller *) coef;
  151298. coef->pub.start_input_pass = start_input_pass;
  151299. coef->pub.start_output_pass = start_output_pass;
  151300. #ifdef BLOCK_SMOOTHING_SUPPORTED
  151301. coef->coef_bits_latch = NULL;
  151302. #endif
  151303. if (need_full_buffer) {
  151304. #ifdef D_MULTISCAN_FILES_SUPPORTED
  151305. int ci, access_rows;
  151306. jpeg_component_info *compptr;
  151307. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  151308. ci++, compptr++) {
  151309. access_rows = compptr->v_samp_factor;
  151310. #ifdef BLOCK_SMOOTHING_SUPPORTED
  151311. if (cinfo->progressive_mode)
  151312. access_rows *= 3;
  151313. #endif
  151314. coef->whole_image[ci] = (*cinfo->mem->request_virt_barray)
  151315. ((j_common_ptr) cinfo, JPOOL_IMAGE, TRUE,
  151316. (JDIMENSION) jround_up((long) compptr->width_in_blocks,
  151317. (long) compptr->h_samp_factor),
  151318. (JDIMENSION) jround_up((long) compptr->height_in_blocks,
  151319. (long) compptr->v_samp_factor),
  151320. (JDIMENSION) access_rows);
  151321. }
  151322. coef->pub.consume_data = consume_data;
  151323. coef->pub.decompress_data = decompress_data;
  151324. coef->pub.coef_arrays = coef->whole_image; /* link to virtual arrays */
  151325. #else
  151326. ERREXIT(cinfo, JERR_NOT_COMPILED);
  151327. #endif
  151328. } else {
  151329. JBLOCKROW buffer;
  151330. int i;
  151331. buffer = (JBLOCKROW)
  151332. (*cinfo->mem->alloc_large) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  151333. D_MAX_BLOCKS_IN_MCU * SIZEOF(JBLOCK));
  151334. for (i = 0; i < D_MAX_BLOCKS_IN_MCU; i++) {
  151335. coef->MCU_buffer[i] = buffer + i;
  151336. }
  151337. coef->pub.consume_data = dummy_consume_data;
  151338. coef->pub.decompress_data = decompress_onepass;
  151339. coef->pub.coef_arrays = NULL; /* flag for no virtual arrays */
  151340. }
  151341. }
  151342. /*** End of inlined file: jdcoefct.c ***/
  151343. #undef FIX
  151344. /*** Start of inlined file: jdcolor.c ***/
  151345. #define JPEG_INTERNALS
  151346. typedef struct {
  151347. struct jpeg_color_deconverter pub; /* public fields */
  151348. int * Cr_r_tab; /* => table for Cr to R conversion */
  151349. int * Cb_b_tab; /* => table for Cb to B conversion */
  151350. INT32 * Cr_g_tab; /* => table for Cr to G conversion */
  151351. INT32 * Cb_g_tab; /* => table for Cb to G conversion */
  151352. } my_color_deconverter2;
  151353. typedef my_color_deconverter2 * my_cconvert_ptr2;
  151354. #define SCALEBITS 16 /* speediest right-shift on some machines */
  151355. #define ONE_HALF ((INT32) 1 << (SCALEBITS-1))
  151356. #define FIX(x) ((INT32) ((x) * (1L<<SCALEBITS) + 0.5))
  151357. LOCAL(void)
  151358. build_ycc_rgb_table (j_decompress_ptr cinfo)
  151359. {
  151360. my_cconvert_ptr2 cconvert = (my_cconvert_ptr2) cinfo->cconvert;
  151361. int i;
  151362. INT32 x;
  151363. SHIFT_TEMPS
  151364. cconvert->Cr_r_tab = (int *)
  151365. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  151366. (MAXJSAMPLE+1) * SIZEOF(int));
  151367. cconvert->Cb_b_tab = (int *)
  151368. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  151369. (MAXJSAMPLE+1) * SIZEOF(int));
  151370. cconvert->Cr_g_tab = (INT32 *)
  151371. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  151372. (MAXJSAMPLE+1) * SIZEOF(INT32));
  151373. cconvert->Cb_g_tab = (INT32 *)
  151374. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  151375. (MAXJSAMPLE+1) * SIZEOF(INT32));
  151376. for (i = 0, x = -CENTERJSAMPLE; i <= MAXJSAMPLE; i++, x++) {
  151377. cconvert->Cr_r_tab[i] = (int)
  151378. RIGHT_SHIFT(FIX(1.40200) * x + ONE_HALF, SCALEBITS);
  151379. cconvert->Cb_b_tab[i] = (int)
  151380. RIGHT_SHIFT(FIX(1.77200) * x + ONE_HALF, SCALEBITS);
  151381. cconvert->Cr_g_tab[i] = (- FIX(0.71414)) * x;
  151382. cconvert->Cb_g_tab[i] = (- FIX(0.34414)) * x + ONE_HALF;
  151383. }
  151384. }
  151385. METHODDEF(void)
  151386. ycc_rgb_convert (j_decompress_ptr cinfo,
  151387. JSAMPIMAGE input_buf, JDIMENSION input_row,
  151388. JSAMPARRAY output_buf, int num_rows)
  151389. {
  151390. my_cconvert_ptr2 cconvert = (my_cconvert_ptr2) cinfo->cconvert;
  151391. register int y, cb, cr;
  151392. register JSAMPROW outptr;
  151393. register JSAMPROW inptr0, inptr1, inptr2;
  151394. register JDIMENSION col;
  151395. JDIMENSION num_cols = cinfo->output_width;
  151396. register JSAMPLE * range_limit = cinfo->sample_range_limit;
  151397. register int * Crrtab = cconvert->Cr_r_tab;
  151398. register int * Cbbtab = cconvert->Cb_b_tab;
  151399. register INT32 * Crgtab = cconvert->Cr_g_tab;
  151400. register INT32 * Cbgtab = cconvert->Cb_g_tab;
  151401. SHIFT_TEMPS
  151402. while (--num_rows >= 0) {
  151403. inptr0 = input_buf[0][input_row];
  151404. inptr1 = input_buf[1][input_row];
  151405. inptr2 = input_buf[2][input_row];
  151406. input_row++;
  151407. outptr = *output_buf++;
  151408. for (col = 0; col < num_cols; col++) {
  151409. y = GETJSAMPLE(inptr0[col]);
  151410. cb = GETJSAMPLE(inptr1[col]);
  151411. cr = GETJSAMPLE(inptr2[col]);
  151412. outptr[RGB_RED] = range_limit[y + Crrtab[cr]];
  151413. outptr[RGB_GREEN] = range_limit[y +
  151414. ((int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr],
  151415. SCALEBITS))];
  151416. outptr[RGB_BLUE] = range_limit[y + Cbbtab[cb]];
  151417. outptr += RGB_PIXELSIZE;
  151418. }
  151419. }
  151420. }
  151421. METHODDEF(void)
  151422. null_convert2 (j_decompress_ptr cinfo,
  151423. JSAMPIMAGE input_buf, JDIMENSION input_row,
  151424. JSAMPARRAY output_buf, int num_rows)
  151425. {
  151426. register JSAMPROW inptr, outptr;
  151427. register JDIMENSION count;
  151428. register int num_components = cinfo->num_components;
  151429. JDIMENSION num_cols = cinfo->output_width;
  151430. int ci;
  151431. while (--num_rows >= 0) {
  151432. for (ci = 0; ci < num_components; ci++) {
  151433. inptr = input_buf[ci][input_row];
  151434. outptr = output_buf[0] + ci;
  151435. for (count = num_cols; count > 0; count--) {
  151436. *outptr = *inptr++; /* needn't bother with GETJSAMPLE() here */
  151437. outptr += num_components;
  151438. }
  151439. }
  151440. input_row++;
  151441. output_buf++;
  151442. }
  151443. }
  151444. METHODDEF(void)
  151445. grayscale_convert2 (j_decompress_ptr cinfo,
  151446. JSAMPIMAGE input_buf, JDIMENSION input_row,
  151447. JSAMPARRAY output_buf, int num_rows)
  151448. {
  151449. jcopy_sample_rows(input_buf[0], (int) input_row, output_buf, 0,
  151450. num_rows, cinfo->output_width);
  151451. }
  151452. METHODDEF(void)
  151453. gray_rgb_convert (j_decompress_ptr cinfo,
  151454. JSAMPIMAGE input_buf, JDIMENSION input_row,
  151455. JSAMPARRAY output_buf, int num_rows)
  151456. {
  151457. register JSAMPROW inptr, outptr;
  151458. register JDIMENSION col;
  151459. JDIMENSION num_cols = cinfo->output_width;
  151460. while (--num_rows >= 0) {
  151461. inptr = input_buf[0][input_row++];
  151462. outptr = *output_buf++;
  151463. for (col = 0; col < num_cols; col++) {
  151464. outptr[RGB_RED] = outptr[RGB_GREEN] = outptr[RGB_BLUE] = inptr[col];
  151465. outptr += RGB_PIXELSIZE;
  151466. }
  151467. }
  151468. }
  151469. METHODDEF(void)
  151470. ycck_cmyk_convert (j_decompress_ptr cinfo,
  151471. JSAMPIMAGE input_buf, JDIMENSION input_row,
  151472. JSAMPARRAY output_buf, int num_rows)
  151473. {
  151474. my_cconvert_ptr2 cconvert = (my_cconvert_ptr2) cinfo->cconvert;
  151475. register int y, cb, cr;
  151476. register JSAMPROW outptr;
  151477. register JSAMPROW inptr0, inptr1, inptr2, inptr3;
  151478. register JDIMENSION col;
  151479. JDIMENSION num_cols = cinfo->output_width;
  151480. register JSAMPLE * range_limit = cinfo->sample_range_limit;
  151481. register int * Crrtab = cconvert->Cr_r_tab;
  151482. register int * Cbbtab = cconvert->Cb_b_tab;
  151483. register INT32 * Crgtab = cconvert->Cr_g_tab;
  151484. register INT32 * Cbgtab = cconvert->Cb_g_tab;
  151485. SHIFT_TEMPS
  151486. while (--num_rows >= 0) {
  151487. inptr0 = input_buf[0][input_row];
  151488. inptr1 = input_buf[1][input_row];
  151489. inptr2 = input_buf[2][input_row];
  151490. inptr3 = input_buf[3][input_row];
  151491. input_row++;
  151492. outptr = *output_buf++;
  151493. for (col = 0; col < num_cols; col++) {
  151494. y = GETJSAMPLE(inptr0[col]);
  151495. cb = GETJSAMPLE(inptr1[col]);
  151496. cr = GETJSAMPLE(inptr2[col]);
  151497. outptr[0] = range_limit[MAXJSAMPLE - (y + Crrtab[cr])]; /* red */
  151498. outptr[1] = range_limit[MAXJSAMPLE - (y + /* green */
  151499. ((int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr],
  151500. SCALEBITS)))];
  151501. outptr[2] = range_limit[MAXJSAMPLE - (y + Cbbtab[cb])]; /* blue */
  151502. outptr[3] = inptr3[col]; /* don't need GETJSAMPLE here */
  151503. outptr += 4;
  151504. }
  151505. }
  151506. }
  151507. METHODDEF(void)
  151508. start_pass_dcolor (j_decompress_ptr cinfo)
  151509. {
  151510. }
  151511. GLOBAL(void)
  151512. jinit_color_deconverter (j_decompress_ptr cinfo)
  151513. {
  151514. my_cconvert_ptr2 cconvert;
  151515. int ci;
  151516. cconvert = (my_cconvert_ptr2)
  151517. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  151518. SIZEOF(my_color_deconverter2));
  151519. cinfo->cconvert = (struct jpeg_color_deconverter *) cconvert;
  151520. cconvert->pub.start_pass = start_pass_dcolor;
  151521. switch (cinfo->jpeg_color_space) {
  151522. case JCS_GRAYSCALE:
  151523. if (cinfo->num_components != 1)
  151524. ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
  151525. break;
  151526. case JCS_RGB:
  151527. case JCS_YCbCr:
  151528. if (cinfo->num_components != 3)
  151529. ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
  151530. break;
  151531. case JCS_CMYK:
  151532. case JCS_YCCK:
  151533. if (cinfo->num_components != 4)
  151534. ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
  151535. break;
  151536. default: /* JCS_UNKNOWN can be anything */
  151537. if (cinfo->num_components < 1)
  151538. ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
  151539. break;
  151540. }
  151541. switch (cinfo->out_color_space) {
  151542. case JCS_GRAYSCALE:
  151543. cinfo->out_color_components = 1;
  151544. if (cinfo->jpeg_color_space == JCS_GRAYSCALE ||
  151545. cinfo->jpeg_color_space == JCS_YCbCr) {
  151546. cconvert->pub.color_convert = grayscale_convert2;
  151547. for (ci = 1; ci < cinfo->num_components; ci++)
  151548. cinfo->comp_info[ci].component_needed = FALSE;
  151549. } else
  151550. ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
  151551. break;
  151552. case JCS_RGB:
  151553. cinfo->out_color_components = RGB_PIXELSIZE;
  151554. if (cinfo->jpeg_color_space == JCS_YCbCr) {
  151555. cconvert->pub.color_convert = ycc_rgb_convert;
  151556. build_ycc_rgb_table(cinfo);
  151557. } else if (cinfo->jpeg_color_space == JCS_GRAYSCALE) {
  151558. cconvert->pub.color_convert = gray_rgb_convert;
  151559. } else if (cinfo->jpeg_color_space == JCS_RGB && RGB_PIXELSIZE == 3) {
  151560. cconvert->pub.color_convert = null_convert2;
  151561. } else
  151562. ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
  151563. break;
  151564. case JCS_CMYK:
  151565. cinfo->out_color_components = 4;
  151566. if (cinfo->jpeg_color_space == JCS_YCCK) {
  151567. cconvert->pub.color_convert = ycck_cmyk_convert;
  151568. build_ycc_rgb_table(cinfo);
  151569. } else if (cinfo->jpeg_color_space == JCS_CMYK) {
  151570. cconvert->pub.color_convert = null_convert2;
  151571. } else
  151572. ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
  151573. break;
  151574. default:
  151575. if (cinfo->out_color_space == cinfo->jpeg_color_space) {
  151576. cinfo->out_color_components = cinfo->num_components;
  151577. cconvert->pub.color_convert = null_convert2;
  151578. } else /* unsupported non-null conversion */
  151579. ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
  151580. break;
  151581. }
  151582. if (cinfo->quantize_colors)
  151583. cinfo->output_components = 1; /* single colormapped output component */
  151584. else
  151585. cinfo->output_components = cinfo->out_color_components;
  151586. }
  151587. /*** End of inlined file: jdcolor.c ***/
  151588. #undef FIX
  151589. /*** Start of inlined file: jddctmgr.c ***/
  151590. #define JPEG_INTERNALS
  151591. typedef struct {
  151592. struct jpeg_inverse_dct pub; /* public fields */
  151593. int cur_method[MAX_COMPONENTS];
  151594. } my_idct_controller;
  151595. typedef my_idct_controller * my_idct_ptr;
  151596. typedef union {
  151597. ISLOW_MULT_TYPE islow_array[DCTSIZE2];
  151598. #ifdef DCT_IFAST_SUPPORTED
  151599. IFAST_MULT_TYPE ifast_array[DCTSIZE2];
  151600. #endif
  151601. #ifdef DCT_FLOAT_SUPPORTED
  151602. FLOAT_MULT_TYPE float_array[DCTSIZE2];
  151603. #endif
  151604. } multiplier_table;
  151605. #ifdef DCT_ISLOW_SUPPORTED
  151606. #define PROVIDE_ISLOW_TABLES
  151607. #else
  151608. #ifdef IDCT_SCALING_SUPPORTED
  151609. #define PROVIDE_ISLOW_TABLES
  151610. #endif
  151611. #endif
  151612. METHODDEF(void)
  151613. start_pass (j_decompress_ptr cinfo)
  151614. {
  151615. my_idct_ptr idct = (my_idct_ptr) cinfo->idct;
  151616. int ci, i;
  151617. jpeg_component_info *compptr;
  151618. int method = 0;
  151619. inverse_DCT_method_ptr method_ptr = NULL;
  151620. JQUANT_TBL * qtbl;
  151621. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  151622. ci++, compptr++) {
  151623. switch (compptr->DCT_scaled_size) {
  151624. #ifdef IDCT_SCALING_SUPPORTED
  151625. case 1:
  151626. method_ptr = jpeg_idct_1x1;
  151627. method = JDCT_ISLOW; /* jidctred uses islow-style table */
  151628. break;
  151629. case 2:
  151630. method_ptr = jpeg_idct_2x2;
  151631. method = JDCT_ISLOW; /* jidctred uses islow-style table */
  151632. break;
  151633. case 4:
  151634. method_ptr = jpeg_idct_4x4;
  151635. method = JDCT_ISLOW; /* jidctred uses islow-style table */
  151636. break;
  151637. #endif
  151638. case DCTSIZE:
  151639. switch (cinfo->dct_method) {
  151640. #ifdef DCT_ISLOW_SUPPORTED
  151641. case JDCT_ISLOW:
  151642. method_ptr = jpeg_idct_islow;
  151643. method = JDCT_ISLOW;
  151644. break;
  151645. #endif
  151646. #ifdef DCT_IFAST_SUPPORTED
  151647. case JDCT_IFAST:
  151648. method_ptr = jpeg_idct_ifast;
  151649. method = JDCT_IFAST;
  151650. break;
  151651. #endif
  151652. #ifdef DCT_FLOAT_SUPPORTED
  151653. case JDCT_FLOAT:
  151654. method_ptr = jpeg_idct_float;
  151655. method = JDCT_FLOAT;
  151656. break;
  151657. #endif
  151658. default:
  151659. ERREXIT(cinfo, JERR_NOT_COMPILED);
  151660. break;
  151661. }
  151662. break;
  151663. default:
  151664. ERREXIT1(cinfo, JERR_BAD_DCTSIZE, compptr->DCT_scaled_size);
  151665. break;
  151666. }
  151667. idct->pub.inverse_DCT[ci] = method_ptr;
  151668. if (! compptr->component_needed || idct->cur_method[ci] == method)
  151669. continue;
  151670. qtbl = compptr->quant_table;
  151671. if (qtbl == NULL) /* happens if no data yet for component */
  151672. continue;
  151673. idct->cur_method[ci] = method;
  151674. switch (method) {
  151675. #ifdef PROVIDE_ISLOW_TABLES
  151676. case JDCT_ISLOW:
  151677. {
  151678. ISLOW_MULT_TYPE * ismtbl = (ISLOW_MULT_TYPE *) compptr->dct_table;
  151679. for (i = 0; i < DCTSIZE2; i++) {
  151680. ismtbl[i] = (ISLOW_MULT_TYPE) qtbl->quantval[i];
  151681. }
  151682. }
  151683. break;
  151684. #endif
  151685. #ifdef DCT_IFAST_SUPPORTED
  151686. case JDCT_IFAST:
  151687. {
  151688. IFAST_MULT_TYPE * ifmtbl = (IFAST_MULT_TYPE *) compptr->dct_table;
  151689. #define CONST_BITS 14
  151690. static const INT16 aanscales[DCTSIZE2] = {
  151691. 16384, 22725, 21407, 19266, 16384, 12873, 8867, 4520,
  151692. 22725, 31521, 29692, 26722, 22725, 17855, 12299, 6270,
  151693. 21407, 29692, 27969, 25172, 21407, 16819, 11585, 5906,
  151694. 19266, 26722, 25172, 22654, 19266, 15137, 10426, 5315,
  151695. 16384, 22725, 21407, 19266, 16384, 12873, 8867, 4520,
  151696. 12873, 17855, 16819, 15137, 12873, 10114, 6967, 3552,
  151697. 8867, 12299, 11585, 10426, 8867, 6967, 4799, 2446,
  151698. 4520, 6270, 5906, 5315, 4520, 3552, 2446, 1247
  151699. };
  151700. SHIFT_TEMPS
  151701. for (i = 0; i < DCTSIZE2; i++) {
  151702. ifmtbl[i] = (IFAST_MULT_TYPE)
  151703. DESCALE(MULTIPLY16V16((INT32) qtbl->quantval[i],
  151704. (INT32) aanscales[i]),
  151705. CONST_BITS-IFAST_SCALE_BITS);
  151706. }
  151707. }
  151708. break;
  151709. #endif
  151710. #ifdef DCT_FLOAT_SUPPORTED
  151711. case JDCT_FLOAT:
  151712. {
  151713. FLOAT_MULT_TYPE * fmtbl = (FLOAT_MULT_TYPE *) compptr->dct_table;
  151714. int row, col;
  151715. static const double aanscalefactor[DCTSIZE] = {
  151716. 1.0, 1.387039845, 1.306562965, 1.175875602,
  151717. 1.0, 0.785694958, 0.541196100, 0.275899379
  151718. };
  151719. i = 0;
  151720. for (row = 0; row < DCTSIZE; row++) {
  151721. for (col = 0; col < DCTSIZE; col++) {
  151722. fmtbl[i] = (FLOAT_MULT_TYPE)
  151723. ((double) qtbl->quantval[i] *
  151724. aanscalefactor[row] * aanscalefactor[col]);
  151725. i++;
  151726. }
  151727. }
  151728. }
  151729. break;
  151730. #endif
  151731. default:
  151732. ERREXIT(cinfo, JERR_NOT_COMPILED);
  151733. break;
  151734. }
  151735. }
  151736. }
  151737. GLOBAL(void)
  151738. jinit_inverse_dct (j_decompress_ptr cinfo)
  151739. {
  151740. my_idct_ptr idct;
  151741. int ci;
  151742. jpeg_component_info *compptr;
  151743. idct = (my_idct_ptr)
  151744. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  151745. SIZEOF(my_idct_controller));
  151746. cinfo->idct = (struct jpeg_inverse_dct *) idct;
  151747. idct->pub.start_pass = start_pass;
  151748. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  151749. ci++, compptr++) {
  151750. compptr->dct_table =
  151751. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  151752. SIZEOF(multiplier_table));
  151753. MEMZERO(compptr->dct_table, SIZEOF(multiplier_table));
  151754. idct->cur_method[ci] = -1;
  151755. }
  151756. }
  151757. /*** End of inlined file: jddctmgr.c ***/
  151758. #undef CONST_BITS
  151759. #undef ASSIGN_STATE
  151760. /*** Start of inlined file: jdhuff.c ***/
  151761. #define JPEG_INTERNALS
  151762. /*** Start of inlined file: jdhuff.h ***/
  151763. #ifndef __jdhuff_h__
  151764. #define __jdhuff_h__
  151765. #ifdef NEED_SHORT_EXTERNAL_NAMES
  151766. #define jpeg_make_d_derived_tbl jMkDDerived
  151767. #define jpeg_fill_bit_buffer jFilBitBuf
  151768. #define jpeg_huff_decode jHufDecode
  151769. #endif /* NEED_SHORT_EXTERNAL_NAMES */
  151770. #define HUFF_LOOKAHEAD 8 /* # of bits of lookahead */
  151771. typedef struct {
  151772. INT32 maxcode[18]; /* largest code of length k (-1 if none) */
  151773. INT32 valoffset[17]; /* huffval[] offset for codes of length k */
  151774. JHUFF_TBL *pub;
  151775. int look_nbits[1<<HUFF_LOOKAHEAD]; /* # bits, or 0 if too long */
  151776. UINT8 look_sym[1<<HUFF_LOOKAHEAD]; /* symbol, or unused */
  151777. } d_derived_tbl;
  151778. EXTERN(void) jpeg_make_d_derived_tbl
  151779. JPP((j_decompress_ptr cinfo, boolean isDC, int tblno,
  151780. d_derived_tbl ** pdtbl));
  151781. typedef INT32 bit_buf_type; /* type of bit-extraction buffer */
  151782. #define BIT_BUF_SIZE 32 /* size of buffer in bits */
  151783. typedef struct { /* Bitreading state saved across MCUs */
  151784. bit_buf_type get_buffer; /* current bit-extraction buffer */
  151785. int bits_left; /* # of unused bits in it */
  151786. } bitread_perm_state;
  151787. typedef struct { /* Bitreading working state within an MCU */
  151788. const JOCTET * next_input_byte; /* => next byte to read from source */
  151789. size_t bytes_in_buffer; /* # of bytes remaining in source buffer */
  151790. bit_buf_type get_buffer; /* current bit-extraction buffer */
  151791. int bits_left; /* # of unused bits in it */
  151792. j_decompress_ptr cinfo; /* back link to decompress master record */
  151793. } bitread_working_state;
  151794. #define BITREAD_STATE_VARS \
  151795. register bit_buf_type get_buffer; \
  151796. register int bits_left; \
  151797. bitread_working_state br_state
  151798. #define BITREAD_LOAD_STATE(cinfop,permstate) \
  151799. br_state.cinfo = cinfop; \
  151800. br_state.next_input_byte = cinfop->src->next_input_byte; \
  151801. br_state.bytes_in_buffer = cinfop->src->bytes_in_buffer; \
  151802. get_buffer = permstate.get_buffer; \
  151803. bits_left = permstate.bits_left;
  151804. #define BITREAD_SAVE_STATE(cinfop,permstate) \
  151805. cinfop->src->next_input_byte = br_state.next_input_byte; \
  151806. cinfop->src->bytes_in_buffer = br_state.bytes_in_buffer; \
  151807. permstate.get_buffer = get_buffer; \
  151808. permstate.bits_left = bits_left
  151809. #define CHECK_BIT_BUFFER(state,nbits,action) \
  151810. { if (bits_left < (nbits)) { \
  151811. if (! jpeg_fill_bit_buffer(&(state),get_buffer,bits_left,nbits)) \
  151812. { action; } \
  151813. get_buffer = (state).get_buffer; bits_left = (state).bits_left; } }
  151814. #define GET_BITS(nbits) \
  151815. (((int) (get_buffer >> (bits_left -= (nbits)))) & ((1<<(nbits))-1))
  151816. #define PEEK_BITS(nbits) \
  151817. (((int) (get_buffer >> (bits_left - (nbits)))) & ((1<<(nbits))-1))
  151818. #define DROP_BITS(nbits) \
  151819. (bits_left -= (nbits))
  151820. EXTERN(boolean) jpeg_fill_bit_buffer
  151821. JPP((bitread_working_state * state, register bit_buf_type get_buffer,
  151822. register int bits_left, int nbits));
  151823. #define HUFF_DECODE(result,state,htbl,failaction,slowlabel) \
  151824. { register int nb, look; \
  151825. if (bits_left < HUFF_LOOKAHEAD) { \
  151826. if (! jpeg_fill_bit_buffer(&state,get_buffer,bits_left, 0)) {failaction;} \
  151827. get_buffer = state.get_buffer; bits_left = state.bits_left; \
  151828. if (bits_left < HUFF_LOOKAHEAD) { \
  151829. nb = 1; goto slowlabel; \
  151830. } \
  151831. } \
  151832. look = PEEK_BITS(HUFF_LOOKAHEAD); \
  151833. if ((nb = htbl->look_nbits[look]) != 0) { \
  151834. DROP_BITS(nb); \
  151835. result = htbl->look_sym[look]; \
  151836. } else { \
  151837. nb = HUFF_LOOKAHEAD+1; \
  151838. slowlabel: \
  151839. if ((result=jpeg_huff_decode(&state,get_buffer,bits_left,htbl,nb)) < 0) \
  151840. { failaction; } \
  151841. get_buffer = state.get_buffer; bits_left = state.bits_left; \
  151842. } \
  151843. }
  151844. EXTERN(int) jpeg_huff_decode
  151845. JPP((bitread_working_state * state, register bit_buf_type get_buffer,
  151846. register int bits_left, d_derived_tbl * htbl, int min_bits));
  151847. #endif
  151848. /*** End of inlined file: jdhuff.h ***/
  151849. /* Declarations shared with jdphuff.c */
  151850. typedef struct {
  151851. int last_dc_val[MAX_COMPS_IN_SCAN]; /* last DC coef for each component */
  151852. } savable_state2;
  151853. #ifndef NO_STRUCT_ASSIGN
  151854. #define ASSIGN_STATE(dest,src) ((dest) = (src))
  151855. #else
  151856. #if MAX_COMPS_IN_SCAN == 4
  151857. #define ASSIGN_STATE(dest,src) \
  151858. ((dest).last_dc_val[0] = (src).last_dc_val[0], \
  151859. (dest).last_dc_val[1] = (src).last_dc_val[1], \
  151860. (dest).last_dc_val[2] = (src).last_dc_val[2], \
  151861. (dest).last_dc_val[3] = (src).last_dc_val[3])
  151862. #endif
  151863. #endif
  151864. typedef struct {
  151865. struct jpeg_entropy_decoder pub; /* public fields */
  151866. bitread_perm_state bitstate; /* Bit buffer at start of MCU */
  151867. savable_state2 saved; /* Other state at start of MCU */
  151868. unsigned int restarts_to_go; /* MCUs left in this restart interval */
  151869. d_derived_tbl * dc_derived_tbls[NUM_HUFF_TBLS];
  151870. d_derived_tbl * ac_derived_tbls[NUM_HUFF_TBLS];
  151871. d_derived_tbl * dc_cur_tbls[D_MAX_BLOCKS_IN_MCU];
  151872. d_derived_tbl * ac_cur_tbls[D_MAX_BLOCKS_IN_MCU];
  151873. boolean dc_needed[D_MAX_BLOCKS_IN_MCU];
  151874. boolean ac_needed[D_MAX_BLOCKS_IN_MCU];
  151875. } huff_entropy_decoder2;
  151876. typedef huff_entropy_decoder2 * huff_entropy_ptr2;
  151877. METHODDEF(void)
  151878. start_pass_huff_decoder (j_decompress_ptr cinfo)
  151879. {
  151880. huff_entropy_ptr2 entropy = (huff_entropy_ptr2) cinfo->entropy;
  151881. int ci, blkn, dctbl, actbl;
  151882. jpeg_component_info * compptr;
  151883. if (cinfo->Ss != 0 || cinfo->Se != DCTSIZE2-1 ||
  151884. cinfo->Ah != 0 || cinfo->Al != 0)
  151885. WARNMS(cinfo, JWRN_NOT_SEQUENTIAL);
  151886. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  151887. compptr = cinfo->cur_comp_info[ci];
  151888. dctbl = compptr->dc_tbl_no;
  151889. actbl = compptr->ac_tbl_no;
  151890. jpeg_make_d_derived_tbl(cinfo, TRUE, dctbl,
  151891. & entropy->dc_derived_tbls[dctbl]);
  151892. jpeg_make_d_derived_tbl(cinfo, FALSE, actbl,
  151893. & entropy->ac_derived_tbls[actbl]);
  151894. entropy->saved.last_dc_val[ci] = 0;
  151895. }
  151896. for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
  151897. ci = cinfo->MCU_membership[blkn];
  151898. compptr = cinfo->cur_comp_info[ci];
  151899. entropy->dc_cur_tbls[blkn] = entropy->dc_derived_tbls[compptr->dc_tbl_no];
  151900. entropy->ac_cur_tbls[blkn] = entropy->ac_derived_tbls[compptr->ac_tbl_no];
  151901. if (compptr->component_needed) {
  151902. entropy->dc_needed[blkn] = TRUE;
  151903. entropy->ac_needed[blkn] = (compptr->DCT_scaled_size > 1);
  151904. } else {
  151905. entropy->dc_needed[blkn] = entropy->ac_needed[blkn] = FALSE;
  151906. }
  151907. }
  151908. entropy->bitstate.bits_left = 0;
  151909. entropy->bitstate.get_buffer = 0; /* unnecessary, but keeps Purify quiet */
  151910. entropy->pub.insufficient_data = FALSE;
  151911. entropy->restarts_to_go = cinfo->restart_interval;
  151912. }
  151913. GLOBAL(void)
  151914. jpeg_make_d_derived_tbl (j_decompress_ptr cinfo, boolean isDC, int tblno,
  151915. d_derived_tbl ** pdtbl)
  151916. {
  151917. JHUFF_TBL *htbl;
  151918. d_derived_tbl *dtbl;
  151919. int p, i, l, si, numsymbols;
  151920. int lookbits, ctr;
  151921. char huffsize[257];
  151922. unsigned int huffcode[257];
  151923. unsigned int code;
  151924. if (tblno < 0 || tblno >= NUM_HUFF_TBLS)
  151925. ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, tblno);
  151926. htbl =
  151927. isDC ? cinfo->dc_huff_tbl_ptrs[tblno] : cinfo->ac_huff_tbl_ptrs[tblno];
  151928. if (htbl == NULL)
  151929. ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, tblno);
  151930. if (*pdtbl == NULL)
  151931. *pdtbl = (d_derived_tbl *)
  151932. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  151933. SIZEOF(d_derived_tbl));
  151934. dtbl = *pdtbl;
  151935. dtbl->pub = htbl; /* fill in back link */
  151936. p = 0;
  151937. for (l = 1; l <= 16; l++) {
  151938. i = (int) htbl->bits[l];
  151939. if (i < 0 || p + i > 256) /* protect against table overrun */
  151940. ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
  151941. while (i--)
  151942. huffsize[p++] = (char) l;
  151943. }
  151944. huffsize[p] = 0;
  151945. numsymbols = p;
  151946. code = 0;
  151947. si = huffsize[0];
  151948. p = 0;
  151949. while (huffsize[p]) {
  151950. while (((int) huffsize[p]) == si) {
  151951. huffcode[p++] = code;
  151952. code++;
  151953. }
  151954. if (((INT32) code) >= (((INT32) 1) << si))
  151955. ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
  151956. code <<= 1;
  151957. si++;
  151958. }
  151959. p = 0;
  151960. for (l = 1; l <= 16; l++) {
  151961. if (htbl->bits[l]) {
  151962. dtbl->valoffset[l] = (INT32) p - (INT32) huffcode[p];
  151963. p += htbl->bits[l];
  151964. dtbl->maxcode[l] = huffcode[p-1]; /* maximum code of length l */
  151965. } else {
  151966. dtbl->maxcode[l] = -1; /* -1 if no codes of this length */
  151967. }
  151968. }
  151969. dtbl->maxcode[17] = 0xFFFFFL; /* ensures jpeg_huff_decode terminates */
  151970. MEMZERO(dtbl->look_nbits, SIZEOF(dtbl->look_nbits));
  151971. p = 0;
  151972. for (l = 1; l <= HUFF_LOOKAHEAD; l++) {
  151973. for (i = 1; i <= (int) htbl->bits[l]; i++, p++) {
  151974. lookbits = huffcode[p] << (HUFF_LOOKAHEAD-l);
  151975. for (ctr = 1 << (HUFF_LOOKAHEAD-l); ctr > 0; ctr--) {
  151976. dtbl->look_nbits[lookbits] = l;
  151977. dtbl->look_sym[lookbits] = htbl->huffval[p];
  151978. lookbits++;
  151979. }
  151980. }
  151981. }
  151982. if (isDC) {
  151983. for (i = 0; i < numsymbols; i++) {
  151984. int sym = htbl->huffval[i];
  151985. if (sym < 0 || sym > 15)
  151986. ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
  151987. }
  151988. }
  151989. }
  151990. #ifdef SLOW_SHIFT_32
  151991. #define MIN_GET_BITS 15 /* minimum allowable value */
  151992. #else
  151993. #define MIN_GET_BITS (BIT_BUF_SIZE-7)
  151994. #endif
  151995. GLOBAL(boolean)
  151996. jpeg_fill_bit_buffer (bitread_working_state * state,
  151997. register bit_buf_type get_buffer, register int bits_left,
  151998. int nbits)
  151999. {
  152000. register const JOCTET * next_input_byte = state->next_input_byte;
  152001. register size_t bytes_in_buffer = state->bytes_in_buffer;
  152002. j_decompress_ptr cinfo = state->cinfo;
  152003. if (cinfo->unread_marker == 0) { /* cannot advance past a marker */
  152004. while (bits_left < MIN_GET_BITS) {
  152005. register int c;
  152006. if (bytes_in_buffer == 0) {
  152007. if (! (*cinfo->src->fill_input_buffer) (cinfo))
  152008. return FALSE;
  152009. next_input_byte = cinfo->src->next_input_byte;
  152010. bytes_in_buffer = cinfo->src->bytes_in_buffer;
  152011. }
  152012. bytes_in_buffer--;
  152013. c = GETJOCTET(*next_input_byte++);
  152014. if (c == 0xFF) {
  152015. do {
  152016. if (bytes_in_buffer == 0) {
  152017. if (! (*cinfo->src->fill_input_buffer) (cinfo))
  152018. return FALSE;
  152019. next_input_byte = cinfo->src->next_input_byte;
  152020. bytes_in_buffer = cinfo->src->bytes_in_buffer;
  152021. }
  152022. bytes_in_buffer--;
  152023. c = GETJOCTET(*next_input_byte++);
  152024. } while (c == 0xFF);
  152025. if (c == 0) {
  152026. c = 0xFF;
  152027. } else {
  152028. cinfo->unread_marker = c;
  152029. goto no_more_bytes;
  152030. }
  152031. }
  152032. get_buffer = (get_buffer << 8) | c;
  152033. bits_left += 8;
  152034. } /* end while */
  152035. } else {
  152036. no_more_bytes:
  152037. if (nbits > bits_left) {
  152038. if (! cinfo->entropy->insufficient_data) {
  152039. WARNMS(cinfo, JWRN_HIT_MARKER);
  152040. cinfo->entropy->insufficient_data = TRUE;
  152041. }
  152042. get_buffer <<= MIN_GET_BITS - bits_left;
  152043. bits_left = MIN_GET_BITS;
  152044. }
  152045. }
  152046. state->next_input_byte = next_input_byte;
  152047. state->bytes_in_buffer = bytes_in_buffer;
  152048. state->get_buffer = get_buffer;
  152049. state->bits_left = bits_left;
  152050. return TRUE;
  152051. }
  152052. GLOBAL(int)
  152053. jpeg_huff_decode (bitread_working_state * state,
  152054. register bit_buf_type get_buffer, register int bits_left,
  152055. d_derived_tbl * htbl, int min_bits)
  152056. {
  152057. register int l = min_bits;
  152058. register INT32 code;
  152059. CHECK_BIT_BUFFER(*state, l, return -1);
  152060. code = GET_BITS(l);
  152061. while (code > htbl->maxcode[l]) {
  152062. code <<= 1;
  152063. CHECK_BIT_BUFFER(*state, 1, return -1);
  152064. code |= GET_BITS(1);
  152065. l++;
  152066. }
  152067. state->get_buffer = get_buffer;
  152068. state->bits_left = bits_left;
  152069. if (l > 16) {
  152070. WARNMS(state->cinfo, JWRN_HUFF_BAD_CODE);
  152071. return 0; /* fake a zero as the safest result */
  152072. }
  152073. return htbl->pub->huffval[ (int) (code + htbl->valoffset[l]) ];
  152074. }
  152075. LOCAL(boolean)
  152076. process_restart (j_decompress_ptr cinfo)
  152077. {
  152078. huff_entropy_ptr2 entropy = (huff_entropy_ptr2) cinfo->entropy;
  152079. int ci;
  152080. cinfo->marker->discarded_bytes += entropy->bitstate.bits_left / 8;
  152081. entropy->bitstate.bits_left = 0;
  152082. if (! (*cinfo->marker->read_restart_marker) (cinfo))
  152083. return FALSE;
  152084. for (ci = 0; ci < cinfo->comps_in_scan; ci++)
  152085. entropy->saved.last_dc_val[ci] = 0;
  152086. entropy->restarts_to_go = cinfo->restart_interval;
  152087. if (cinfo->unread_marker == 0)
  152088. entropy->pub.insufficient_data = FALSE;
  152089. return TRUE;
  152090. }
  152091. METHODDEF(boolean)
  152092. decode_mcu (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
  152093. {
  152094. huff_entropy_ptr2 entropy = (huff_entropy_ptr2) cinfo->entropy;
  152095. int blkn;
  152096. BITREAD_STATE_VARS;
  152097. savable_state2 state;
  152098. if (cinfo->restart_interval) {
  152099. if (entropy->restarts_to_go == 0)
  152100. if (! process_restart(cinfo))
  152101. return FALSE;
  152102. }
  152103. if (! entropy->pub.insufficient_data) {
  152104. BITREAD_LOAD_STATE(cinfo,entropy->bitstate);
  152105. ASSIGN_STATE(state, entropy->saved);
  152106. for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
  152107. JBLOCKROW block = MCU_data[blkn];
  152108. d_derived_tbl * dctbl = entropy->dc_cur_tbls[blkn];
  152109. d_derived_tbl * actbl = entropy->ac_cur_tbls[blkn];
  152110. register int s, k, r;
  152111. HUFF_DECODE(s, br_state, dctbl, return FALSE, label1);
  152112. if (s) {
  152113. CHECK_BIT_BUFFER(br_state, s, return FALSE);
  152114. r = GET_BITS(s);
  152115. s = HUFF_EXTEND(r, s);
  152116. }
  152117. if (entropy->dc_needed[blkn]) {
  152118. int ci = cinfo->MCU_membership[blkn];
  152119. s += state.last_dc_val[ci];
  152120. state.last_dc_val[ci] = s;
  152121. (*block)[0] = (JCOEF) s;
  152122. }
  152123. if (entropy->ac_needed[blkn]) {
  152124. for (k = 1; k < DCTSIZE2; k++) {
  152125. HUFF_DECODE(s, br_state, actbl, return FALSE, label2);
  152126. r = s >> 4;
  152127. s &= 15;
  152128. if (s) {
  152129. k += r;
  152130. CHECK_BIT_BUFFER(br_state, s, return FALSE);
  152131. r = GET_BITS(s);
  152132. s = HUFF_EXTEND(r, s);
  152133. (*block)[jpeg_natural_order[k]] = (JCOEF) s;
  152134. } else {
  152135. if (r != 15)
  152136. break;
  152137. k += 15;
  152138. }
  152139. }
  152140. } else {
  152141. for (k = 1; k < DCTSIZE2; k++) {
  152142. HUFF_DECODE(s, br_state, actbl, return FALSE, label3);
  152143. r = s >> 4;
  152144. s &= 15;
  152145. if (s) {
  152146. k += r;
  152147. CHECK_BIT_BUFFER(br_state, s, return FALSE);
  152148. DROP_BITS(s);
  152149. } else {
  152150. if (r != 15)
  152151. break;
  152152. k += 15;
  152153. }
  152154. }
  152155. }
  152156. }
  152157. BITREAD_SAVE_STATE(cinfo,entropy->bitstate);
  152158. ASSIGN_STATE(entropy->saved, state);
  152159. }
  152160. entropy->restarts_to_go--;
  152161. return TRUE;
  152162. }
  152163. GLOBAL(void)
  152164. jinit_huff_decoder (j_decompress_ptr cinfo)
  152165. {
  152166. huff_entropy_ptr2 entropy;
  152167. int i;
  152168. entropy = (huff_entropy_ptr2)
  152169. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  152170. SIZEOF(huff_entropy_decoder2));
  152171. cinfo->entropy = (struct jpeg_entropy_decoder *) entropy;
  152172. entropy->pub.start_pass = start_pass_huff_decoder;
  152173. entropy->pub.decode_mcu = decode_mcu;
  152174. for (i = 0; i < NUM_HUFF_TBLS; i++) {
  152175. entropy->dc_derived_tbls[i] = entropy->ac_derived_tbls[i] = NULL;
  152176. }
  152177. }
  152178. /*** End of inlined file: jdhuff.c ***/
  152179. /*** Start of inlined file: jdinput.c ***/
  152180. #define JPEG_INTERNALS
  152181. typedef struct {
  152182. struct jpeg_input_controller pub; /* public fields */
  152183. boolean inheaders; /* TRUE until first SOS is reached */
  152184. } my_input_controller;
  152185. typedef my_input_controller * my_inputctl_ptr;
  152186. METHODDEF(int) consume_markers JPP((j_decompress_ptr cinfo));
  152187. LOCAL(void)
  152188. initial_setup2 (j_decompress_ptr cinfo)
  152189. {
  152190. int ci;
  152191. jpeg_component_info *compptr;
  152192. if ((long) cinfo->image_height > (long) JPEG_MAX_DIMENSION ||
  152193. (long) cinfo->image_width > (long) JPEG_MAX_DIMENSION)
  152194. ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, (unsigned int) JPEG_MAX_DIMENSION);
  152195. if (cinfo->data_precision != BITS_IN_JSAMPLE)
  152196. ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
  152197. if (cinfo->num_components > MAX_COMPONENTS)
  152198. ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->num_components,
  152199. MAX_COMPONENTS);
  152200. cinfo->max_h_samp_factor = 1;
  152201. cinfo->max_v_samp_factor = 1;
  152202. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  152203. ci++, compptr++) {
  152204. if (compptr->h_samp_factor<=0 || compptr->h_samp_factor>MAX_SAMP_FACTOR ||
  152205. compptr->v_samp_factor<=0 || compptr->v_samp_factor>MAX_SAMP_FACTOR)
  152206. ERREXIT(cinfo, JERR_BAD_SAMPLING);
  152207. cinfo->max_h_samp_factor = MAX(cinfo->max_h_samp_factor,
  152208. compptr->h_samp_factor);
  152209. cinfo->max_v_samp_factor = MAX(cinfo->max_v_samp_factor,
  152210. compptr->v_samp_factor);
  152211. }
  152212. cinfo->min_DCT_scaled_size = DCTSIZE;
  152213. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  152214. ci++, compptr++) {
  152215. compptr->DCT_scaled_size = DCTSIZE;
  152216. compptr->width_in_blocks = (JDIMENSION)
  152217. jdiv_round_up((long) cinfo->image_width * (long) compptr->h_samp_factor,
  152218. (long) (cinfo->max_h_samp_factor * DCTSIZE));
  152219. compptr->height_in_blocks = (JDIMENSION)
  152220. jdiv_round_up((long) cinfo->image_height * (long) compptr->v_samp_factor,
  152221. (long) (cinfo->max_v_samp_factor * DCTSIZE));
  152222. compptr->downsampled_width = (JDIMENSION)
  152223. jdiv_round_up((long) cinfo->image_width * (long) compptr->h_samp_factor,
  152224. (long) cinfo->max_h_samp_factor);
  152225. compptr->downsampled_height = (JDIMENSION)
  152226. jdiv_round_up((long) cinfo->image_height * (long) compptr->v_samp_factor,
  152227. (long) cinfo->max_v_samp_factor);
  152228. compptr->component_needed = TRUE;
  152229. compptr->quant_table = NULL;
  152230. }
  152231. cinfo->total_iMCU_rows = (JDIMENSION)
  152232. jdiv_round_up((long) cinfo->image_height,
  152233. (long) (cinfo->max_v_samp_factor*DCTSIZE));
  152234. if (cinfo->comps_in_scan < cinfo->num_components || cinfo->progressive_mode)
  152235. cinfo->inputctl->has_multiple_scans = TRUE;
  152236. else
  152237. cinfo->inputctl->has_multiple_scans = FALSE;
  152238. }
  152239. LOCAL(void)
  152240. per_scan_setup2 (j_decompress_ptr cinfo)
  152241. {
  152242. int ci, mcublks, tmp;
  152243. jpeg_component_info *compptr;
  152244. if (cinfo->comps_in_scan == 1) {
  152245. compptr = cinfo->cur_comp_info[0];
  152246. cinfo->MCUs_per_row = compptr->width_in_blocks;
  152247. cinfo->MCU_rows_in_scan = compptr->height_in_blocks;
  152248. compptr->MCU_width = 1;
  152249. compptr->MCU_height = 1;
  152250. compptr->MCU_blocks = 1;
  152251. compptr->MCU_sample_width = compptr->DCT_scaled_size;
  152252. compptr->last_col_width = 1;
  152253. tmp = (int) (compptr->height_in_blocks % compptr->v_samp_factor);
  152254. if (tmp == 0) tmp = compptr->v_samp_factor;
  152255. compptr->last_row_height = tmp;
  152256. cinfo->blocks_in_MCU = 1;
  152257. cinfo->MCU_membership[0] = 0;
  152258. } else {
  152259. if (cinfo->comps_in_scan <= 0 || cinfo->comps_in_scan > MAX_COMPS_IN_SCAN)
  152260. ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->comps_in_scan,
  152261. MAX_COMPS_IN_SCAN);
  152262. cinfo->MCUs_per_row = (JDIMENSION)
  152263. jdiv_round_up((long) cinfo->image_width,
  152264. (long) (cinfo->max_h_samp_factor*DCTSIZE));
  152265. cinfo->MCU_rows_in_scan = (JDIMENSION)
  152266. jdiv_round_up((long) cinfo->image_height,
  152267. (long) (cinfo->max_v_samp_factor*DCTSIZE));
  152268. cinfo->blocks_in_MCU = 0;
  152269. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  152270. compptr = cinfo->cur_comp_info[ci];
  152271. compptr->MCU_width = compptr->h_samp_factor;
  152272. compptr->MCU_height = compptr->v_samp_factor;
  152273. compptr->MCU_blocks = compptr->MCU_width * compptr->MCU_height;
  152274. compptr->MCU_sample_width = compptr->MCU_width * compptr->DCT_scaled_size;
  152275. tmp = (int) (compptr->width_in_blocks % compptr->MCU_width);
  152276. if (tmp == 0) tmp = compptr->MCU_width;
  152277. compptr->last_col_width = tmp;
  152278. tmp = (int) (compptr->height_in_blocks % compptr->MCU_height);
  152279. if (tmp == 0) tmp = compptr->MCU_height;
  152280. compptr->last_row_height = tmp;
  152281. mcublks = compptr->MCU_blocks;
  152282. if (cinfo->blocks_in_MCU + mcublks > D_MAX_BLOCKS_IN_MCU)
  152283. ERREXIT(cinfo, JERR_BAD_MCU_SIZE);
  152284. while (mcublks-- > 0) {
  152285. cinfo->MCU_membership[cinfo->blocks_in_MCU++] = ci;
  152286. }
  152287. }
  152288. }
  152289. }
  152290. LOCAL(void)
  152291. latch_quant_tables (j_decompress_ptr cinfo)
  152292. {
  152293. int ci, qtblno;
  152294. jpeg_component_info *compptr;
  152295. JQUANT_TBL * qtbl;
  152296. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  152297. compptr = cinfo->cur_comp_info[ci];
  152298. if (compptr->quant_table != NULL)
  152299. continue;
  152300. qtblno = compptr->quant_tbl_no;
  152301. if (qtblno < 0 || qtblno >= NUM_QUANT_TBLS ||
  152302. cinfo->quant_tbl_ptrs[qtblno] == NULL)
  152303. ERREXIT1(cinfo, JERR_NO_QUANT_TABLE, qtblno);
  152304. qtbl = (JQUANT_TBL *)
  152305. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  152306. SIZEOF(JQUANT_TBL));
  152307. MEMCOPY(qtbl, cinfo->quant_tbl_ptrs[qtblno], SIZEOF(JQUANT_TBL));
  152308. compptr->quant_table = qtbl;
  152309. }
  152310. }
  152311. METHODDEF(void)
  152312. start_input_pass2 (j_decompress_ptr cinfo)
  152313. {
  152314. per_scan_setup2(cinfo);
  152315. latch_quant_tables(cinfo);
  152316. (*cinfo->entropy->start_pass) (cinfo);
  152317. (*cinfo->coef->start_input_pass) (cinfo);
  152318. cinfo->inputctl->consume_input = cinfo->coef->consume_data;
  152319. }
  152320. METHODDEF(void)
  152321. finish_input_pass (j_decompress_ptr cinfo)
  152322. {
  152323. cinfo->inputctl->consume_input = consume_markers;
  152324. }
  152325. METHODDEF(int)
  152326. consume_markers (j_decompress_ptr cinfo)
  152327. {
  152328. my_inputctl_ptr inputctl = (my_inputctl_ptr) cinfo->inputctl;
  152329. int val;
  152330. if (inputctl->pub.eoi_reached) /* After hitting EOI, read no further */
  152331. return JPEG_REACHED_EOI;
  152332. val = (*cinfo->marker->read_markers) (cinfo);
  152333. switch (val) {
  152334. case JPEG_REACHED_SOS: /* Found SOS */
  152335. if (inputctl->inheaders) { /* 1st SOS */
  152336. initial_setup2(cinfo);
  152337. inputctl->inheaders = FALSE;
  152338. } else { /* 2nd or later SOS marker */
  152339. if (! inputctl->pub.has_multiple_scans)
  152340. ERREXIT(cinfo, JERR_EOI_EXPECTED); /* Oops, I wasn't expecting this! */
  152341. start_input_pass2(cinfo);
  152342. }
  152343. break;
  152344. case JPEG_REACHED_EOI: /* Found EOI */
  152345. inputctl->pub.eoi_reached = TRUE;
  152346. if (inputctl->inheaders) { /* Tables-only datastream, apparently */
  152347. if (cinfo->marker->saw_SOF)
  152348. ERREXIT(cinfo, JERR_SOF_NO_SOS);
  152349. } else {
  152350. if (cinfo->output_scan_number > cinfo->input_scan_number)
  152351. cinfo->output_scan_number = cinfo->input_scan_number;
  152352. }
  152353. break;
  152354. case JPEG_SUSPENDED:
  152355. break;
  152356. }
  152357. return val;
  152358. }
  152359. METHODDEF(void)
  152360. reset_input_controller (j_decompress_ptr cinfo)
  152361. {
  152362. my_inputctl_ptr inputctl = (my_inputctl_ptr) cinfo->inputctl;
  152363. inputctl->pub.consume_input = consume_markers;
  152364. inputctl->pub.has_multiple_scans = FALSE; /* "unknown" would be better */
  152365. inputctl->pub.eoi_reached = FALSE;
  152366. inputctl->inheaders = TRUE;
  152367. (*cinfo->err->reset_error_mgr) ((j_common_ptr) cinfo);
  152368. (*cinfo->marker->reset_marker_reader) (cinfo);
  152369. cinfo->coef_bits = NULL;
  152370. }
  152371. GLOBAL(void)
  152372. jinit_input_controller (j_decompress_ptr cinfo)
  152373. {
  152374. my_inputctl_ptr inputctl;
  152375. inputctl = (my_inputctl_ptr)
  152376. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
  152377. SIZEOF(my_input_controller));
  152378. cinfo->inputctl = (struct jpeg_input_controller *) inputctl;
  152379. inputctl->pub.consume_input = consume_markers;
  152380. inputctl->pub.reset_input_controller = reset_input_controller;
  152381. inputctl->pub.start_input_pass = start_input_pass2;
  152382. inputctl->pub.finish_input_pass = finish_input_pass;
  152383. inputctl->pub.has_multiple_scans = FALSE; /* "unknown" would be better */
  152384. inputctl->pub.eoi_reached = FALSE;
  152385. inputctl->inheaders = TRUE;
  152386. }
  152387. /*** End of inlined file: jdinput.c ***/
  152388. /*** Start of inlined file: jdmainct.c ***/
  152389. #define JPEG_INTERNALS
  152390. typedef struct {
  152391. struct jpeg_d_main_controller pub; /* public fields */
  152392. JSAMPARRAY buffer[MAX_COMPONENTS];
  152393. boolean buffer_full; /* Have we gotten an iMCU row from decoder? */
  152394. JDIMENSION rowgroup_ctr; /* counts row groups output to postprocessor */
  152395. JSAMPIMAGE xbuffer[2]; /* pointers to weird pointer lists */
  152396. int whichptr; /* indicates which pointer set is now in use */
  152397. int context_state; /* process_data state machine status */
  152398. JDIMENSION rowgroups_avail; /* row groups available to postprocessor */
  152399. JDIMENSION iMCU_row_ctr; /* counts iMCU rows to detect image top/bot */
  152400. } my_main_controller4;
  152401. typedef my_main_controller4 * my_main_ptr4;
  152402. #define CTX_PREPARE_FOR_IMCU 0 /* need to prepare for MCU row */
  152403. #define CTX_PROCESS_IMCU 1 /* feeding iMCU to postprocessor */
  152404. #define CTX_POSTPONED_ROW 2 /* feeding postponed row group */
  152405. METHODDEF(void) process_data_simple_main2
  152406. JPP((j_decompress_ptr cinfo, JSAMPARRAY output_buf,
  152407. JDIMENSION *out_row_ctr, JDIMENSION out_rows_avail));
  152408. METHODDEF(void) process_data_context_main
  152409. JPP((j_decompress_ptr cinfo, JSAMPARRAY output_buf,
  152410. JDIMENSION *out_row_ctr, JDIMENSION out_rows_avail));
  152411. #ifdef QUANT_2PASS_SUPPORTED
  152412. METHODDEF(void) process_data_crank_post
  152413. JPP((j_decompress_ptr cinfo, JSAMPARRAY output_buf,
  152414. JDIMENSION *out_row_ctr, JDIMENSION out_rows_avail));
  152415. #endif
  152416. LOCAL(void)
  152417. alloc_funny_pointers (j_decompress_ptr cinfo)
  152418. {
  152419. my_main_ptr4 main_ = (my_main_ptr4) cinfo->main;
  152420. int ci, rgroup;
  152421. int M = cinfo->min_DCT_scaled_size;
  152422. jpeg_component_info *compptr;
  152423. JSAMPARRAY xbuf;
  152424. main_->xbuffer[0] = (JSAMPIMAGE)
  152425. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  152426. cinfo->num_components * 2 * SIZEOF(JSAMPARRAY));
  152427. main_->xbuffer[1] = main_->xbuffer[0] + cinfo->num_components;
  152428. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  152429. ci++, compptr++) {
  152430. rgroup = (compptr->v_samp_factor * compptr->DCT_scaled_size) /
  152431. cinfo->min_DCT_scaled_size; /* height of a row group of component */
  152432. xbuf = (JSAMPARRAY)
  152433. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  152434. 2 * (rgroup * (M + 4)) * SIZEOF(JSAMPROW));
  152435. xbuf += rgroup; /* want one row group at negative offsets */
  152436. main_->xbuffer[0][ci] = xbuf;
  152437. xbuf += rgroup * (M + 4);
  152438. main_->xbuffer[1][ci] = xbuf;
  152439. }
  152440. }
  152441. LOCAL(void)
  152442. make_funny_pointers (j_decompress_ptr cinfo)
  152443. {
  152444. my_main_ptr4 main_ = (my_main_ptr4) cinfo->main;
  152445. int ci, i, rgroup;
  152446. int M = cinfo->min_DCT_scaled_size;
  152447. jpeg_component_info *compptr;
  152448. JSAMPARRAY buf, xbuf0, xbuf1;
  152449. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  152450. ci++, compptr++) {
  152451. rgroup = (compptr->v_samp_factor * compptr->DCT_scaled_size) /
  152452. cinfo->min_DCT_scaled_size; /* height of a row group of component */
  152453. xbuf0 = main_->xbuffer[0][ci];
  152454. xbuf1 = main_->xbuffer[1][ci];
  152455. buf = main_->buffer[ci];
  152456. for (i = 0; i < rgroup * (M + 2); i++) {
  152457. xbuf0[i] = xbuf1[i] = buf[i];
  152458. }
  152459. for (i = 0; i < rgroup * 2; i++) {
  152460. xbuf1[rgroup*(M-2) + i] = buf[rgroup*M + i];
  152461. xbuf1[rgroup*M + i] = buf[rgroup*(M-2) + i];
  152462. }
  152463. for (i = 0; i < rgroup; i++) {
  152464. xbuf0[i - rgroup] = xbuf0[0];
  152465. }
  152466. }
  152467. }
  152468. LOCAL(void)
  152469. set_wraparound_pointers (j_decompress_ptr cinfo)
  152470. {
  152471. my_main_ptr4 main_ = (my_main_ptr4) cinfo->main;
  152472. int ci, i, rgroup;
  152473. int M = cinfo->min_DCT_scaled_size;
  152474. jpeg_component_info *compptr;
  152475. JSAMPARRAY xbuf0, xbuf1;
  152476. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  152477. ci++, compptr++) {
  152478. rgroup = (compptr->v_samp_factor * compptr->DCT_scaled_size) /
  152479. cinfo->min_DCT_scaled_size; /* height of a row group of component */
  152480. xbuf0 = main_->xbuffer[0][ci];
  152481. xbuf1 = main_->xbuffer[1][ci];
  152482. for (i = 0; i < rgroup; i++) {
  152483. xbuf0[i - rgroup] = xbuf0[rgroup*(M+1) + i];
  152484. xbuf1[i - rgroup] = xbuf1[rgroup*(M+1) + i];
  152485. xbuf0[rgroup*(M+2) + i] = xbuf0[i];
  152486. xbuf1[rgroup*(M+2) + i] = xbuf1[i];
  152487. }
  152488. }
  152489. }
  152490. LOCAL(void)
  152491. set_bottom_pointers (j_decompress_ptr cinfo)
  152492. {
  152493. my_main_ptr4 main_ = (my_main_ptr4) cinfo->main;
  152494. int ci, i, rgroup, iMCUheight, rows_left;
  152495. jpeg_component_info *compptr;
  152496. JSAMPARRAY xbuf;
  152497. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  152498. ci++, compptr++) {
  152499. iMCUheight = compptr->v_samp_factor * compptr->DCT_scaled_size;
  152500. rgroup = iMCUheight / cinfo->min_DCT_scaled_size;
  152501. rows_left = (int) (compptr->downsampled_height % (JDIMENSION) iMCUheight);
  152502. if (rows_left == 0) rows_left = iMCUheight;
  152503. if (ci == 0) {
  152504. main_->rowgroups_avail = (JDIMENSION) ((rows_left-1) / rgroup + 1);
  152505. }
  152506. xbuf = main_->xbuffer[main_->whichptr][ci];
  152507. for (i = 0; i < rgroup * 2; i++) {
  152508. xbuf[rows_left + i] = xbuf[rows_left-1];
  152509. }
  152510. }
  152511. }
  152512. METHODDEF(void)
  152513. start_pass_main2 (j_decompress_ptr cinfo, J_BUF_MODE pass_mode)
  152514. {
  152515. my_main_ptr4 main_ = (my_main_ptr4) cinfo->main;
  152516. switch (pass_mode) {
  152517. case JBUF_PASS_THRU:
  152518. if (cinfo->upsample->need_context_rows) {
  152519. main_->pub.process_data = process_data_context_main;
  152520. make_funny_pointers(cinfo); /* Create the xbuffer[] lists */
  152521. main_->whichptr = 0; /* Read first iMCU row into xbuffer[0] */
  152522. main_->context_state = CTX_PREPARE_FOR_IMCU;
  152523. main_->iMCU_row_ctr = 0;
  152524. } else {
  152525. main_->pub.process_data = process_data_simple_main2;
  152526. }
  152527. main_->buffer_full = FALSE; /* Mark buffer empty */
  152528. main_->rowgroup_ctr = 0;
  152529. break;
  152530. #ifdef QUANT_2PASS_SUPPORTED
  152531. case JBUF_CRANK_DEST:
  152532. main_->pub.process_data = process_data_crank_post;
  152533. break;
  152534. #endif
  152535. default:
  152536. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  152537. break;
  152538. }
  152539. }
  152540. METHODDEF(void)
  152541. process_data_simple_main2 (j_decompress_ptr cinfo,
  152542. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  152543. JDIMENSION out_rows_avail)
  152544. {
  152545. my_main_ptr4 main_ = (my_main_ptr4) cinfo->main;
  152546. JDIMENSION rowgroups_avail;
  152547. if (! main_->buffer_full) {
  152548. if (! (*cinfo->coef->decompress_data) (cinfo, main_->buffer))
  152549. return; /* suspension forced, can do nothing more */
  152550. main_->buffer_full = TRUE; /* OK, we have an iMCU row to work with */
  152551. }
  152552. rowgroups_avail = (JDIMENSION) cinfo->min_DCT_scaled_size;
  152553. (*cinfo->post->post_process_data) (cinfo, main_->buffer,
  152554. &main_->rowgroup_ctr, rowgroups_avail,
  152555. output_buf, out_row_ctr, out_rows_avail);
  152556. if (main_->rowgroup_ctr >= rowgroups_avail) {
  152557. main_->buffer_full = FALSE;
  152558. main_->rowgroup_ctr = 0;
  152559. }
  152560. }
  152561. METHODDEF(void)
  152562. process_data_context_main (j_decompress_ptr cinfo,
  152563. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  152564. JDIMENSION out_rows_avail)
  152565. {
  152566. my_main_ptr4 main_ = (my_main_ptr4) cinfo->main;
  152567. if (! main_->buffer_full) {
  152568. if (! (*cinfo->coef->decompress_data) (cinfo,
  152569. main_->xbuffer[main_->whichptr]))
  152570. return; /* suspension forced, can do nothing more */
  152571. main_->buffer_full = TRUE; /* OK, we have an iMCU row to work with */
  152572. main_->iMCU_row_ctr++; /* count rows received */
  152573. }
  152574. switch (main_->context_state) {
  152575. case CTX_POSTPONED_ROW:
  152576. (*cinfo->post->post_process_data) (cinfo, main_->xbuffer[main_->whichptr],
  152577. &main_->rowgroup_ctr, main_->rowgroups_avail,
  152578. output_buf, out_row_ctr, out_rows_avail);
  152579. if (main_->rowgroup_ctr < main_->rowgroups_avail)
  152580. return; /* Need to suspend */
  152581. main_->context_state = CTX_PREPARE_FOR_IMCU;
  152582. if (*out_row_ctr >= out_rows_avail)
  152583. return; /* Postprocessor exactly filled output buf */
  152584. case CTX_PREPARE_FOR_IMCU:
  152585. main_->rowgroup_ctr = 0;
  152586. main_->rowgroups_avail = (JDIMENSION) (cinfo->min_DCT_scaled_size - 1);
  152587. if (main_->iMCU_row_ctr == cinfo->total_iMCU_rows)
  152588. set_bottom_pointers(cinfo);
  152589. main_->context_state = CTX_PROCESS_IMCU;
  152590. case CTX_PROCESS_IMCU:
  152591. (*cinfo->post->post_process_data) (cinfo, main_->xbuffer[main_->whichptr],
  152592. &main_->rowgroup_ctr, main_->rowgroups_avail,
  152593. output_buf, out_row_ctr, out_rows_avail);
  152594. if (main_->rowgroup_ctr < main_->rowgroups_avail)
  152595. return; /* Need to suspend */
  152596. if (main_->iMCU_row_ctr == 1)
  152597. set_wraparound_pointers(cinfo);
  152598. main_->whichptr ^= 1; /* 0=>1 or 1=>0 */
  152599. main_->buffer_full = FALSE;
  152600. main_->rowgroup_ctr = (JDIMENSION) (cinfo->min_DCT_scaled_size + 1);
  152601. main_->rowgroups_avail = (JDIMENSION) (cinfo->min_DCT_scaled_size + 2);
  152602. main_->context_state = CTX_POSTPONED_ROW;
  152603. }
  152604. }
  152605. #ifdef QUANT_2PASS_SUPPORTED
  152606. METHODDEF(void)
  152607. process_data_crank_post (j_decompress_ptr cinfo,
  152608. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  152609. JDIMENSION out_rows_avail)
  152610. {
  152611. (*cinfo->post->post_process_data) (cinfo, (JSAMPIMAGE) NULL,
  152612. (JDIMENSION *) NULL, (JDIMENSION) 0,
  152613. output_buf, out_row_ctr, out_rows_avail);
  152614. }
  152615. #endif /* QUANT_2PASS_SUPPORTED */
  152616. GLOBAL(void)
  152617. jinit_d_main_controller (j_decompress_ptr cinfo, boolean need_full_buffer)
  152618. {
  152619. my_main_ptr4 main_;
  152620. int ci, rgroup, ngroups;
  152621. jpeg_component_info *compptr;
  152622. main_ = (my_main_ptr4)
  152623. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  152624. SIZEOF(my_main_controller4));
  152625. cinfo->main = (struct jpeg_d_main_controller *) main_;
  152626. main_->pub.start_pass = start_pass_main2;
  152627. if (need_full_buffer) /* shouldn't happen */
  152628. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  152629. if (cinfo->upsample->need_context_rows) {
  152630. if (cinfo->min_DCT_scaled_size < 2) /* unsupported, see comments above */
  152631. ERREXIT(cinfo, JERR_NOTIMPL);
  152632. alloc_funny_pointers(cinfo); /* Alloc space for xbuffer[] lists */
  152633. ngroups = cinfo->min_DCT_scaled_size + 2;
  152634. } else {
  152635. ngroups = cinfo->min_DCT_scaled_size;
  152636. }
  152637. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  152638. ci++, compptr++) {
  152639. rgroup = (compptr->v_samp_factor * compptr->DCT_scaled_size) /
  152640. cinfo->min_DCT_scaled_size; /* height of a row group of component */
  152641. main_->buffer[ci] = (*cinfo->mem->alloc_sarray)
  152642. ((j_common_ptr) cinfo, JPOOL_IMAGE,
  152643. compptr->width_in_blocks * compptr->DCT_scaled_size,
  152644. (JDIMENSION) (rgroup * ngroups));
  152645. }
  152646. }
  152647. /*** End of inlined file: jdmainct.c ***/
  152648. /*** Start of inlined file: jdmarker.c ***/
  152649. #define JPEG_INTERNALS
  152650. typedef struct {
  152651. struct jpeg_marker_reader pub; /* public fields */
  152652. jpeg_marker_parser_method process_COM;
  152653. jpeg_marker_parser_method process_APPn[16];
  152654. unsigned int length_limit_COM;
  152655. unsigned int length_limit_APPn[16];
  152656. jpeg_saved_marker_ptr cur_marker; /* NULL if not processing a marker */
  152657. unsigned int bytes_read; /* data bytes read so far in marker */
  152658. } my_marker_reader;
  152659. typedef my_marker_reader * my_marker_ptr2;
  152660. #define INPUT_VARS(cinfo) \
  152661. struct jpeg_source_mgr * datasrc = (cinfo)->src; \
  152662. const JOCTET * next_input_byte = datasrc->next_input_byte; \
  152663. size_t bytes_in_buffer = datasrc->bytes_in_buffer
  152664. #define INPUT_SYNC(cinfo) \
  152665. ( datasrc->next_input_byte = next_input_byte, \
  152666. datasrc->bytes_in_buffer = bytes_in_buffer )
  152667. #define INPUT_RELOAD(cinfo) \
  152668. ( next_input_byte = datasrc->next_input_byte, \
  152669. bytes_in_buffer = datasrc->bytes_in_buffer )
  152670. #define MAKE_BYTE_AVAIL(cinfo,action) \
  152671. if (bytes_in_buffer == 0) { \
  152672. if (! (*datasrc->fill_input_buffer) (cinfo)) \
  152673. { action; } \
  152674. INPUT_RELOAD(cinfo); \
  152675. }
  152676. #define INPUT_BYTE(cinfo,V,action) \
  152677. MAKESTMT( MAKE_BYTE_AVAIL(cinfo,action); \
  152678. bytes_in_buffer--; \
  152679. V = GETJOCTET(*next_input_byte++); )
  152680. #define INPUT_2BYTES(cinfo,V,action) \
  152681. MAKESTMT( MAKE_BYTE_AVAIL(cinfo,action); \
  152682. bytes_in_buffer--; \
  152683. V = ((unsigned int) GETJOCTET(*next_input_byte++)) << 8; \
  152684. MAKE_BYTE_AVAIL(cinfo,action); \
  152685. bytes_in_buffer--; \
  152686. V += GETJOCTET(*next_input_byte++); )
  152687. LOCAL(boolean)
  152688. get_soi (j_decompress_ptr cinfo)
  152689. {
  152690. int i;
  152691. TRACEMS(cinfo, 1, JTRC_SOI);
  152692. if (cinfo->marker->saw_SOI)
  152693. ERREXIT(cinfo, JERR_SOI_DUPLICATE);
  152694. for (i = 0; i < NUM_ARITH_TBLS; i++) {
  152695. cinfo->arith_dc_L[i] = 0;
  152696. cinfo->arith_dc_U[i] = 1;
  152697. cinfo->arith_ac_K[i] = 5;
  152698. }
  152699. cinfo->restart_interval = 0;
  152700. cinfo->jpeg_color_space = JCS_UNKNOWN;
  152701. cinfo->CCIR601_sampling = FALSE; /* Assume non-CCIR sampling??? */
  152702. cinfo->saw_JFIF_marker = FALSE;
  152703. cinfo->JFIF_major_version = 1; /* set default JFIF APP0 values */
  152704. cinfo->JFIF_minor_version = 1;
  152705. cinfo->density_unit = 0;
  152706. cinfo->X_density = 1;
  152707. cinfo->Y_density = 1;
  152708. cinfo->saw_Adobe_marker = FALSE;
  152709. cinfo->Adobe_transform = 0;
  152710. cinfo->marker->saw_SOI = TRUE;
  152711. return TRUE;
  152712. }
  152713. LOCAL(boolean)
  152714. get_sof (j_decompress_ptr cinfo, boolean is_prog, boolean is_arith)
  152715. {
  152716. INT32 length;
  152717. int c, ci;
  152718. jpeg_component_info * compptr;
  152719. INPUT_VARS(cinfo);
  152720. cinfo->progressive_mode = is_prog;
  152721. cinfo->arith_code = is_arith;
  152722. INPUT_2BYTES(cinfo, length, return FALSE);
  152723. INPUT_BYTE(cinfo, cinfo->data_precision, return FALSE);
  152724. INPUT_2BYTES(cinfo, cinfo->image_height, return FALSE);
  152725. INPUT_2BYTES(cinfo, cinfo->image_width, return FALSE);
  152726. INPUT_BYTE(cinfo, cinfo->num_components, return FALSE);
  152727. length -= 8;
  152728. TRACEMS4(cinfo, 1, JTRC_SOF, cinfo->unread_marker,
  152729. (int) cinfo->image_width, (int) cinfo->image_height,
  152730. cinfo->num_components);
  152731. if (cinfo->marker->saw_SOF)
  152732. ERREXIT(cinfo, JERR_SOF_DUPLICATE);
  152733. if (cinfo->image_height <= 0 || cinfo->image_width <= 0
  152734. || cinfo->num_components <= 0)
  152735. ERREXIT(cinfo, JERR_EMPTY_IMAGE);
  152736. if (length != (cinfo->num_components * 3))
  152737. ERREXIT(cinfo, JERR_BAD_LENGTH);
  152738. if (cinfo->comp_info == NULL) /* do only once, even if suspend */
  152739. cinfo->comp_info = (jpeg_component_info *) (*cinfo->mem->alloc_small)
  152740. ((j_common_ptr) cinfo, JPOOL_IMAGE,
  152741. cinfo->num_components * SIZEOF(jpeg_component_info));
  152742. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  152743. ci++, compptr++) {
  152744. compptr->component_index = ci;
  152745. INPUT_BYTE(cinfo, compptr->component_id, return FALSE);
  152746. INPUT_BYTE(cinfo, c, return FALSE);
  152747. compptr->h_samp_factor = (c >> 4) & 15;
  152748. compptr->v_samp_factor = (c ) & 15;
  152749. INPUT_BYTE(cinfo, compptr->quant_tbl_no, return FALSE);
  152750. TRACEMS4(cinfo, 1, JTRC_SOF_COMPONENT,
  152751. compptr->component_id, compptr->h_samp_factor,
  152752. compptr->v_samp_factor, compptr->quant_tbl_no);
  152753. }
  152754. cinfo->marker->saw_SOF = TRUE;
  152755. INPUT_SYNC(cinfo);
  152756. return TRUE;
  152757. }
  152758. LOCAL(boolean)
  152759. get_sos (j_decompress_ptr cinfo)
  152760. {
  152761. INT32 length;
  152762. int i, ci, n, c, cc;
  152763. jpeg_component_info * compptr;
  152764. INPUT_VARS(cinfo);
  152765. if (! cinfo->marker->saw_SOF)
  152766. ERREXIT(cinfo, JERR_SOS_NO_SOF);
  152767. INPUT_2BYTES(cinfo, length, return FALSE);
  152768. INPUT_BYTE(cinfo, n, return FALSE); /* Number of components */
  152769. TRACEMS1(cinfo, 1, JTRC_SOS, n);
  152770. if (length != (n * 2 + 6) || n < 1 || n > MAX_COMPS_IN_SCAN)
  152771. ERREXIT(cinfo, JERR_BAD_LENGTH);
  152772. cinfo->comps_in_scan = n;
  152773. for (i = 0; i < n; i++) {
  152774. INPUT_BYTE(cinfo, cc, return FALSE);
  152775. INPUT_BYTE(cinfo, c, return FALSE);
  152776. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  152777. ci++, compptr++) {
  152778. if (cc == compptr->component_id)
  152779. goto id_found;
  152780. }
  152781. ERREXIT1(cinfo, JERR_BAD_COMPONENT_ID, cc);
  152782. id_found:
  152783. cinfo->cur_comp_info[i] = compptr;
  152784. compptr->dc_tbl_no = (c >> 4) & 15;
  152785. compptr->ac_tbl_no = (c ) & 15;
  152786. TRACEMS3(cinfo, 1, JTRC_SOS_COMPONENT, cc,
  152787. compptr->dc_tbl_no, compptr->ac_tbl_no);
  152788. }
  152789. INPUT_BYTE(cinfo, c, return FALSE);
  152790. cinfo->Ss = c;
  152791. INPUT_BYTE(cinfo, c, return FALSE);
  152792. cinfo->Se = c;
  152793. INPUT_BYTE(cinfo, c, return FALSE);
  152794. cinfo->Ah = (c >> 4) & 15;
  152795. cinfo->Al = (c ) & 15;
  152796. TRACEMS4(cinfo, 1, JTRC_SOS_PARAMS, cinfo->Ss, cinfo->Se,
  152797. cinfo->Ah, cinfo->Al);
  152798. cinfo->marker->next_restart_num = 0;
  152799. cinfo->input_scan_number++;
  152800. INPUT_SYNC(cinfo);
  152801. return TRUE;
  152802. }
  152803. #ifdef D_ARITH_CODING_SUPPORTED
  152804. LOCAL(boolean)
  152805. get_dac (j_decompress_ptr cinfo)
  152806. {
  152807. INT32 length;
  152808. int index, val;
  152809. INPUT_VARS(cinfo);
  152810. INPUT_2BYTES(cinfo, length, return FALSE);
  152811. length -= 2;
  152812. while (length > 0) {
  152813. INPUT_BYTE(cinfo, index, return FALSE);
  152814. INPUT_BYTE(cinfo, val, return FALSE);
  152815. length -= 2;
  152816. TRACEMS2(cinfo, 1, JTRC_DAC, index, val);
  152817. if (index < 0 || index >= (2*NUM_ARITH_TBLS))
  152818. ERREXIT1(cinfo, JERR_DAC_INDEX, index);
  152819. if (index >= NUM_ARITH_TBLS) { /* define AC table */
  152820. cinfo->arith_ac_K[index-NUM_ARITH_TBLS] = (UINT8) val;
  152821. } else { /* define DC table */
  152822. cinfo->arith_dc_L[index] = (UINT8) (val & 0x0F);
  152823. cinfo->arith_dc_U[index] = (UINT8) (val >> 4);
  152824. if (cinfo->arith_dc_L[index] > cinfo->arith_dc_U[index])
  152825. ERREXIT1(cinfo, JERR_DAC_VALUE, val);
  152826. }
  152827. }
  152828. if (length != 0)
  152829. ERREXIT(cinfo, JERR_BAD_LENGTH);
  152830. INPUT_SYNC(cinfo);
  152831. return TRUE;
  152832. }
  152833. #else /* ! D_ARITH_CODING_SUPPORTED */
  152834. #define get_dac(cinfo) skip_variable(cinfo)
  152835. #endif /* D_ARITH_CODING_SUPPORTED */
  152836. LOCAL(boolean)
  152837. get_dht (j_decompress_ptr cinfo)
  152838. {
  152839. INT32 length;
  152840. UINT8 bits[17];
  152841. UINT8 huffval[256];
  152842. int i, index, count;
  152843. JHUFF_TBL **htblptr;
  152844. INPUT_VARS(cinfo);
  152845. INPUT_2BYTES(cinfo, length, return FALSE);
  152846. length -= 2;
  152847. while (length > 16) {
  152848. INPUT_BYTE(cinfo, index, return FALSE);
  152849. TRACEMS1(cinfo, 1, JTRC_DHT, index);
  152850. bits[0] = 0;
  152851. count = 0;
  152852. for (i = 1; i <= 16; i++) {
  152853. INPUT_BYTE(cinfo, bits[i], return FALSE);
  152854. count += bits[i];
  152855. }
  152856. length -= 1 + 16;
  152857. TRACEMS8(cinfo, 2, JTRC_HUFFBITS,
  152858. bits[1], bits[2], bits[3], bits[4],
  152859. bits[5], bits[6], bits[7], bits[8]);
  152860. TRACEMS8(cinfo, 2, JTRC_HUFFBITS,
  152861. bits[9], bits[10], bits[11], bits[12],
  152862. bits[13], bits[14], bits[15], bits[16]);
  152863. if (count > 256 || ((INT32) count) > length)
  152864. ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
  152865. for (i = 0; i < count; i++)
  152866. INPUT_BYTE(cinfo, huffval[i], return FALSE);
  152867. length -= count;
  152868. if (index & 0x10) { /* AC table definition */
  152869. index -= 0x10;
  152870. htblptr = &cinfo->ac_huff_tbl_ptrs[index];
  152871. } else { /* DC table definition */
  152872. htblptr = &cinfo->dc_huff_tbl_ptrs[index];
  152873. }
  152874. if (index < 0 || index >= NUM_HUFF_TBLS)
  152875. ERREXIT1(cinfo, JERR_DHT_INDEX, index);
  152876. if (*htblptr == NULL)
  152877. *htblptr = jpeg_alloc_huff_table((j_common_ptr) cinfo);
  152878. MEMCOPY((*htblptr)->bits, bits, SIZEOF((*htblptr)->bits));
  152879. MEMCOPY((*htblptr)->huffval, huffval, SIZEOF((*htblptr)->huffval));
  152880. }
  152881. if (length != 0)
  152882. ERREXIT(cinfo, JERR_BAD_LENGTH);
  152883. INPUT_SYNC(cinfo);
  152884. return TRUE;
  152885. }
  152886. LOCAL(boolean)
  152887. get_dqt (j_decompress_ptr cinfo)
  152888. {
  152889. INT32 length;
  152890. int n, i, prec;
  152891. unsigned int tmp;
  152892. JQUANT_TBL *quant_ptr;
  152893. INPUT_VARS(cinfo);
  152894. INPUT_2BYTES(cinfo, length, return FALSE);
  152895. length -= 2;
  152896. while (length > 0) {
  152897. INPUT_BYTE(cinfo, n, return FALSE);
  152898. prec = n >> 4;
  152899. n &= 0x0F;
  152900. TRACEMS2(cinfo, 1, JTRC_DQT, n, prec);
  152901. if (n >= NUM_QUANT_TBLS)
  152902. ERREXIT1(cinfo, JERR_DQT_INDEX, n);
  152903. if (cinfo->quant_tbl_ptrs[n] == NULL)
  152904. cinfo->quant_tbl_ptrs[n] = jpeg_alloc_quant_table((j_common_ptr) cinfo);
  152905. quant_ptr = cinfo->quant_tbl_ptrs[n];
  152906. for (i = 0; i < DCTSIZE2; i++) {
  152907. if (prec)
  152908. INPUT_2BYTES(cinfo, tmp, return FALSE);
  152909. else
  152910. INPUT_BYTE(cinfo, tmp, return FALSE);
  152911. quant_ptr->quantval[jpeg_natural_order[i]] = (UINT16) tmp;
  152912. }
  152913. if (cinfo->err->trace_level >= 2) {
  152914. for (i = 0; i < DCTSIZE2; i += 8) {
  152915. TRACEMS8(cinfo, 2, JTRC_QUANTVALS,
  152916. quant_ptr->quantval[i], quant_ptr->quantval[i+1],
  152917. quant_ptr->quantval[i+2], quant_ptr->quantval[i+3],
  152918. quant_ptr->quantval[i+4], quant_ptr->quantval[i+5],
  152919. quant_ptr->quantval[i+6], quant_ptr->quantval[i+7]);
  152920. }
  152921. }
  152922. length -= DCTSIZE2+1;
  152923. if (prec) length -= DCTSIZE2;
  152924. }
  152925. if (length != 0)
  152926. ERREXIT(cinfo, JERR_BAD_LENGTH);
  152927. INPUT_SYNC(cinfo);
  152928. return TRUE;
  152929. }
  152930. LOCAL(boolean)
  152931. get_dri (j_decompress_ptr cinfo)
  152932. {
  152933. INT32 length;
  152934. unsigned int tmp;
  152935. INPUT_VARS(cinfo);
  152936. INPUT_2BYTES(cinfo, length, return FALSE);
  152937. if (length != 4)
  152938. ERREXIT(cinfo, JERR_BAD_LENGTH);
  152939. INPUT_2BYTES(cinfo, tmp, return FALSE);
  152940. TRACEMS1(cinfo, 1, JTRC_DRI, tmp);
  152941. cinfo->restart_interval = tmp;
  152942. INPUT_SYNC(cinfo);
  152943. return TRUE;
  152944. }
  152945. #define APP0_DATA_LEN 14 /* Length of interesting data in APP0 */
  152946. #define APP14_DATA_LEN 12 /* Length of interesting data in APP14 */
  152947. #define APPN_DATA_LEN 14 /* Must be the largest of the above!! */
  152948. LOCAL(void)
  152949. examine_app0 (j_decompress_ptr cinfo, JOCTET FAR * data,
  152950. unsigned int datalen, INT32 remaining)
  152951. {
  152952. INT32 totallen = (INT32) datalen + remaining;
  152953. if (datalen >= APP0_DATA_LEN &&
  152954. GETJOCTET(data[0]) == 0x4A &&
  152955. GETJOCTET(data[1]) == 0x46 &&
  152956. GETJOCTET(data[2]) == 0x49 &&
  152957. GETJOCTET(data[3]) == 0x46 &&
  152958. GETJOCTET(data[4]) == 0) {
  152959. cinfo->saw_JFIF_marker = TRUE;
  152960. cinfo->JFIF_major_version = GETJOCTET(data[5]);
  152961. cinfo->JFIF_minor_version = GETJOCTET(data[6]);
  152962. cinfo->density_unit = GETJOCTET(data[7]);
  152963. cinfo->X_density = (GETJOCTET(data[8]) << 8) + GETJOCTET(data[9]);
  152964. cinfo->Y_density = (GETJOCTET(data[10]) << 8) + GETJOCTET(data[11]);
  152965. if (cinfo->JFIF_major_version != 1)
  152966. WARNMS2(cinfo, JWRN_JFIF_MAJOR,
  152967. cinfo->JFIF_major_version, cinfo->JFIF_minor_version);
  152968. TRACEMS5(cinfo, 1, JTRC_JFIF,
  152969. cinfo->JFIF_major_version, cinfo->JFIF_minor_version,
  152970. cinfo->X_density, cinfo->Y_density, cinfo->density_unit);
  152971. if (GETJOCTET(data[12]) | GETJOCTET(data[13]))
  152972. TRACEMS2(cinfo, 1, JTRC_JFIF_THUMBNAIL,
  152973. GETJOCTET(data[12]), GETJOCTET(data[13]));
  152974. totallen -= APP0_DATA_LEN;
  152975. if (totallen !=
  152976. ((INT32)GETJOCTET(data[12]) * (INT32)GETJOCTET(data[13]) * (INT32) 3))
  152977. TRACEMS1(cinfo, 1, JTRC_JFIF_BADTHUMBNAILSIZE, (int) totallen);
  152978. } else if (datalen >= 6 &&
  152979. GETJOCTET(data[0]) == 0x4A &&
  152980. GETJOCTET(data[1]) == 0x46 &&
  152981. GETJOCTET(data[2]) == 0x58 &&
  152982. GETJOCTET(data[3]) == 0x58 &&
  152983. GETJOCTET(data[4]) == 0) {
  152984. switch (GETJOCTET(data[5])) {
  152985. case 0x10:
  152986. TRACEMS1(cinfo, 1, JTRC_THUMB_JPEG, (int) totallen);
  152987. break;
  152988. case 0x11:
  152989. TRACEMS1(cinfo, 1, JTRC_THUMB_PALETTE, (int) totallen);
  152990. break;
  152991. case 0x13:
  152992. TRACEMS1(cinfo, 1, JTRC_THUMB_RGB, (int) totallen);
  152993. break;
  152994. default:
  152995. TRACEMS2(cinfo, 1, JTRC_JFIF_EXTENSION,
  152996. GETJOCTET(data[5]), (int) totallen);
  152997. break;
  152998. }
  152999. } else {
  153000. TRACEMS1(cinfo, 1, JTRC_APP0, (int) totallen);
  153001. }
  153002. }
  153003. LOCAL(void)
  153004. examine_app14 (j_decompress_ptr cinfo, JOCTET FAR * data,
  153005. unsigned int datalen, INT32 remaining)
  153006. {
  153007. unsigned int version, flags0, flags1, transform;
  153008. if (datalen >= APP14_DATA_LEN &&
  153009. GETJOCTET(data[0]) == 0x41 &&
  153010. GETJOCTET(data[1]) == 0x64 &&
  153011. GETJOCTET(data[2]) == 0x6F &&
  153012. GETJOCTET(data[3]) == 0x62 &&
  153013. GETJOCTET(data[4]) == 0x65) {
  153014. version = (GETJOCTET(data[5]) << 8) + GETJOCTET(data[6]);
  153015. flags0 = (GETJOCTET(data[7]) << 8) + GETJOCTET(data[8]);
  153016. flags1 = (GETJOCTET(data[9]) << 8) + GETJOCTET(data[10]);
  153017. transform = GETJOCTET(data[11]);
  153018. TRACEMS4(cinfo, 1, JTRC_ADOBE, version, flags0, flags1, transform);
  153019. cinfo->saw_Adobe_marker = TRUE;
  153020. cinfo->Adobe_transform = (UINT8) transform;
  153021. } else {
  153022. TRACEMS1(cinfo, 1, JTRC_APP14, (int) (datalen + remaining));
  153023. }
  153024. }
  153025. METHODDEF(boolean)
  153026. get_interesting_appn (j_decompress_ptr cinfo)
  153027. {
  153028. INT32 length;
  153029. JOCTET b[APPN_DATA_LEN];
  153030. unsigned int i, numtoread;
  153031. INPUT_VARS(cinfo);
  153032. INPUT_2BYTES(cinfo, length, return FALSE);
  153033. length -= 2;
  153034. if (length >= APPN_DATA_LEN)
  153035. numtoread = APPN_DATA_LEN;
  153036. else if (length > 0)
  153037. numtoread = (unsigned int) length;
  153038. else
  153039. numtoread = 0;
  153040. for (i = 0; i < numtoread; i++)
  153041. INPUT_BYTE(cinfo, b[i], return FALSE);
  153042. length -= numtoread;
  153043. switch (cinfo->unread_marker) {
  153044. case M_APP0:
  153045. examine_app0(cinfo, (JOCTET FAR *) b, numtoread, length);
  153046. break;
  153047. case M_APP14:
  153048. examine_app14(cinfo, (JOCTET FAR *) b, numtoread, length);
  153049. break;
  153050. default:
  153051. ERREXIT1(cinfo, JERR_UNKNOWN_MARKER, cinfo->unread_marker);
  153052. break;
  153053. }
  153054. INPUT_SYNC(cinfo);
  153055. if (length > 0)
  153056. (*cinfo->src->skip_input_data) (cinfo, (long) length);
  153057. return TRUE;
  153058. }
  153059. #ifdef SAVE_MARKERS_SUPPORTED
  153060. METHODDEF(boolean)
  153061. save_marker (j_decompress_ptr cinfo)
  153062. {
  153063. my_marker_ptr2 marker = (my_marker_ptr2) cinfo->marker;
  153064. jpeg_saved_marker_ptr cur_marker = marker->cur_marker;
  153065. unsigned int bytes_read, data_length;
  153066. JOCTET FAR * data;
  153067. INT32 length = 0;
  153068. INPUT_VARS(cinfo);
  153069. if (cur_marker == NULL) {
  153070. INPUT_2BYTES(cinfo, length, return FALSE);
  153071. length -= 2;
  153072. if (length >= 0) { /* watch out for bogus length word */
  153073. unsigned int limit;
  153074. if (cinfo->unread_marker == (int) M_COM)
  153075. limit = marker->length_limit_COM;
  153076. else
  153077. limit = marker->length_limit_APPn[cinfo->unread_marker - (int) M_APP0];
  153078. if ((unsigned int) length < limit)
  153079. limit = (unsigned int) length;
  153080. cur_marker = (jpeg_saved_marker_ptr)
  153081. (*cinfo->mem->alloc_large) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  153082. SIZEOF(struct jpeg_marker_struct) + limit);
  153083. cur_marker->next = NULL;
  153084. cur_marker->marker = (UINT8) cinfo->unread_marker;
  153085. cur_marker->original_length = (unsigned int) length;
  153086. cur_marker->data_length = limit;
  153087. data = cur_marker->data = (JOCTET FAR *) (cur_marker + 1);
  153088. marker->cur_marker = cur_marker;
  153089. marker->bytes_read = 0;
  153090. bytes_read = 0;
  153091. data_length = limit;
  153092. } else {
  153093. bytes_read = data_length = 0;
  153094. data = NULL;
  153095. }
  153096. } else {
  153097. bytes_read = marker->bytes_read;
  153098. data_length = cur_marker->data_length;
  153099. data = cur_marker->data + bytes_read;
  153100. }
  153101. while (bytes_read < data_length) {
  153102. INPUT_SYNC(cinfo); /* move the restart point to here */
  153103. marker->bytes_read = bytes_read;
  153104. MAKE_BYTE_AVAIL(cinfo, return FALSE);
  153105. while (bytes_read < data_length && bytes_in_buffer > 0) {
  153106. *data++ = *next_input_byte++;
  153107. bytes_in_buffer--;
  153108. bytes_read++;
  153109. }
  153110. }
  153111. if (cur_marker != NULL) { /* will be NULL if bogus length word */
  153112. if (cinfo->marker_list == NULL) {
  153113. cinfo->marker_list = cur_marker;
  153114. } else {
  153115. jpeg_saved_marker_ptr prev = cinfo->marker_list;
  153116. while (prev->next != NULL)
  153117. prev = prev->next;
  153118. prev->next = cur_marker;
  153119. }
  153120. data = cur_marker->data;
  153121. length = cur_marker->original_length - data_length;
  153122. }
  153123. marker->cur_marker = NULL;
  153124. switch (cinfo->unread_marker) {
  153125. case M_APP0:
  153126. examine_app0(cinfo, data, data_length, length);
  153127. break;
  153128. case M_APP14:
  153129. examine_app14(cinfo, data, data_length, length);
  153130. break;
  153131. default:
  153132. TRACEMS2(cinfo, 1, JTRC_MISC_MARKER, cinfo->unread_marker,
  153133. (int) (data_length + length));
  153134. break;
  153135. }
  153136. INPUT_SYNC(cinfo); /* do before skip_input_data */
  153137. if (length > 0)
  153138. (*cinfo->src->skip_input_data) (cinfo, (long) length);
  153139. return TRUE;
  153140. }
  153141. #endif /* SAVE_MARKERS_SUPPORTED */
  153142. METHODDEF(boolean)
  153143. skip_variable (j_decompress_ptr cinfo)
  153144. {
  153145. INT32 length;
  153146. INPUT_VARS(cinfo);
  153147. INPUT_2BYTES(cinfo, length, return FALSE);
  153148. length -= 2;
  153149. TRACEMS2(cinfo, 1, JTRC_MISC_MARKER, cinfo->unread_marker, (int) length);
  153150. INPUT_SYNC(cinfo); /* do before skip_input_data */
  153151. if (length > 0)
  153152. (*cinfo->src->skip_input_data) (cinfo, (long) length);
  153153. return TRUE;
  153154. }
  153155. LOCAL(boolean)
  153156. next_marker (j_decompress_ptr cinfo)
  153157. {
  153158. int c;
  153159. INPUT_VARS(cinfo);
  153160. for (;;) {
  153161. INPUT_BYTE(cinfo, c, return FALSE);
  153162. while (c != 0xFF) {
  153163. cinfo->marker->discarded_bytes++;
  153164. INPUT_SYNC(cinfo);
  153165. INPUT_BYTE(cinfo, c, return FALSE);
  153166. }
  153167. do {
  153168. INPUT_BYTE(cinfo, c, return FALSE);
  153169. } while (c == 0xFF);
  153170. if (c != 0)
  153171. break; /* found a valid marker, exit loop */
  153172. cinfo->marker->discarded_bytes += 2;
  153173. INPUT_SYNC(cinfo);
  153174. }
  153175. if (cinfo->marker->discarded_bytes != 0) {
  153176. WARNMS2(cinfo, JWRN_EXTRANEOUS_DATA, cinfo->marker->discarded_bytes, c);
  153177. cinfo->marker->discarded_bytes = 0;
  153178. }
  153179. cinfo->unread_marker = c;
  153180. INPUT_SYNC(cinfo);
  153181. return TRUE;
  153182. }
  153183. LOCAL(boolean)
  153184. first_marker (j_decompress_ptr cinfo)
  153185. {
  153186. int c, c2;
  153187. INPUT_VARS(cinfo);
  153188. INPUT_BYTE(cinfo, c, return FALSE);
  153189. INPUT_BYTE(cinfo, c2, return FALSE);
  153190. if (c != 0xFF || c2 != (int) M_SOI)
  153191. ERREXIT2(cinfo, JERR_NO_SOI, c, c2);
  153192. cinfo->unread_marker = c2;
  153193. INPUT_SYNC(cinfo);
  153194. return TRUE;
  153195. }
  153196. METHODDEF(int)
  153197. read_markers (j_decompress_ptr cinfo)
  153198. {
  153199. for (;;) {
  153200. if (cinfo->unread_marker == 0) {
  153201. if (! cinfo->marker->saw_SOI) {
  153202. if (! first_marker(cinfo))
  153203. return JPEG_SUSPENDED;
  153204. } else {
  153205. if (! next_marker(cinfo))
  153206. return JPEG_SUSPENDED;
  153207. }
  153208. }
  153209. switch (cinfo->unread_marker) {
  153210. case M_SOI:
  153211. if (! get_soi(cinfo))
  153212. return JPEG_SUSPENDED;
  153213. break;
  153214. case M_SOF0: /* Baseline */
  153215. case M_SOF1: /* Extended sequential, Huffman */
  153216. if (! get_sof(cinfo, FALSE, FALSE))
  153217. return JPEG_SUSPENDED;
  153218. break;
  153219. case M_SOF2: /* Progressive, Huffman */
  153220. if (! get_sof(cinfo, TRUE, FALSE))
  153221. return JPEG_SUSPENDED;
  153222. break;
  153223. case M_SOF9: /* Extended sequential, arithmetic */
  153224. if (! get_sof(cinfo, FALSE, TRUE))
  153225. return JPEG_SUSPENDED;
  153226. break;
  153227. case M_SOF10: /* Progressive, arithmetic */
  153228. if (! get_sof(cinfo, TRUE, TRUE))
  153229. return JPEG_SUSPENDED;
  153230. break;
  153231. case M_SOF3: /* Lossless, Huffman */
  153232. case M_SOF5: /* Differential sequential, Huffman */
  153233. case M_SOF6: /* Differential progressive, Huffman */
  153234. case M_SOF7: /* Differential lossless, Huffman */
  153235. case M_JPG: /* Reserved for JPEG extensions */
  153236. case M_SOF11: /* Lossless, arithmetic */
  153237. case M_SOF13: /* Differential sequential, arithmetic */
  153238. case M_SOF14: /* Differential progressive, arithmetic */
  153239. case M_SOF15: /* Differential lossless, arithmetic */
  153240. ERREXIT1(cinfo, JERR_SOF_UNSUPPORTED, cinfo->unread_marker);
  153241. break;
  153242. case M_SOS:
  153243. if (! get_sos(cinfo))
  153244. return JPEG_SUSPENDED;
  153245. cinfo->unread_marker = 0; /* processed the marker */
  153246. return JPEG_REACHED_SOS;
  153247. case M_EOI:
  153248. TRACEMS(cinfo, 1, JTRC_EOI);
  153249. cinfo->unread_marker = 0; /* processed the marker */
  153250. return JPEG_REACHED_EOI;
  153251. case M_DAC:
  153252. if (! get_dac(cinfo))
  153253. return JPEG_SUSPENDED;
  153254. break;
  153255. case M_DHT:
  153256. if (! get_dht(cinfo))
  153257. return JPEG_SUSPENDED;
  153258. break;
  153259. case M_DQT:
  153260. if (! get_dqt(cinfo))
  153261. return JPEG_SUSPENDED;
  153262. break;
  153263. case M_DRI:
  153264. if (! get_dri(cinfo))
  153265. return JPEG_SUSPENDED;
  153266. break;
  153267. case M_APP0:
  153268. case M_APP1:
  153269. case M_APP2:
  153270. case M_APP3:
  153271. case M_APP4:
  153272. case M_APP5:
  153273. case M_APP6:
  153274. case M_APP7:
  153275. case M_APP8:
  153276. case M_APP9:
  153277. case M_APP10:
  153278. case M_APP11:
  153279. case M_APP12:
  153280. case M_APP13:
  153281. case M_APP14:
  153282. case M_APP15:
  153283. if (! (*((my_marker_ptr2) cinfo->marker)->process_APPn[
  153284. cinfo->unread_marker - (int) M_APP0]) (cinfo))
  153285. return JPEG_SUSPENDED;
  153286. break;
  153287. case M_COM:
  153288. if (! (*((my_marker_ptr2) cinfo->marker)->process_COM) (cinfo))
  153289. return JPEG_SUSPENDED;
  153290. break;
  153291. case M_RST0: /* these are all parameterless */
  153292. case M_RST1:
  153293. case M_RST2:
  153294. case M_RST3:
  153295. case M_RST4:
  153296. case M_RST5:
  153297. case M_RST6:
  153298. case M_RST7:
  153299. case M_TEM:
  153300. TRACEMS1(cinfo, 1, JTRC_PARMLESS_MARKER, cinfo->unread_marker);
  153301. break;
  153302. case M_DNL: /* Ignore DNL ... perhaps the wrong thing */
  153303. if (! skip_variable(cinfo))
  153304. return JPEG_SUSPENDED;
  153305. break;
  153306. default: /* must be DHP, EXP, JPGn, or RESn */
  153307. ERREXIT1(cinfo, JERR_UNKNOWN_MARKER, cinfo->unread_marker);
  153308. break;
  153309. }
  153310. cinfo->unread_marker = 0;
  153311. } /* end loop */
  153312. }
  153313. METHODDEF(boolean)
  153314. read_restart_marker (j_decompress_ptr cinfo)
  153315. {
  153316. if (cinfo->unread_marker == 0) {
  153317. if (! next_marker(cinfo))
  153318. return FALSE;
  153319. }
  153320. if (cinfo->unread_marker ==
  153321. ((int) M_RST0 + cinfo->marker->next_restart_num)) {
  153322. TRACEMS1(cinfo, 3, JTRC_RST, cinfo->marker->next_restart_num);
  153323. cinfo->unread_marker = 0;
  153324. } else {
  153325. if (! (*cinfo->src->resync_to_restart) (cinfo,
  153326. cinfo->marker->next_restart_num))
  153327. return FALSE;
  153328. }
  153329. cinfo->marker->next_restart_num = (cinfo->marker->next_restart_num + 1) & 7;
  153330. return TRUE;
  153331. }
  153332. GLOBAL(boolean)
  153333. jpeg_resync_to_restart (j_decompress_ptr cinfo, int desired)
  153334. {
  153335. int marker = cinfo->unread_marker;
  153336. int action = 1;
  153337. WARNMS2(cinfo, JWRN_MUST_RESYNC, marker, desired);
  153338. for (;;) {
  153339. if (marker < (int) M_SOF0)
  153340. action = 2; /* invalid marker */
  153341. else if (marker < (int) M_RST0 || marker > (int) M_RST7)
  153342. action = 3; /* valid non-restart marker */
  153343. else {
  153344. if (marker == ((int) M_RST0 + ((desired+1) & 7)) ||
  153345. marker == ((int) M_RST0 + ((desired+2) & 7)))
  153346. action = 3; /* one of the next two expected restarts */
  153347. else if (marker == ((int) M_RST0 + ((desired-1) & 7)) ||
  153348. marker == ((int) M_RST0 + ((desired-2) & 7)))
  153349. action = 2; /* a prior restart, so advance */
  153350. else
  153351. action = 1; /* desired restart or too far away */
  153352. }
  153353. TRACEMS2(cinfo, 4, JTRC_RECOVERY_ACTION, marker, action);
  153354. switch (action) {
  153355. case 1:
  153356. cinfo->unread_marker = 0;
  153357. return TRUE;
  153358. case 2:
  153359. if (! next_marker(cinfo))
  153360. return FALSE;
  153361. marker = cinfo->unread_marker;
  153362. break;
  153363. case 3:
  153364. return TRUE;
  153365. }
  153366. } /* end loop */
  153367. }
  153368. METHODDEF(void)
  153369. reset_marker_reader (j_decompress_ptr cinfo)
  153370. {
  153371. my_marker_ptr2 marker = (my_marker_ptr2) cinfo->marker;
  153372. cinfo->comp_info = NULL; /* until allocated by get_sof */
  153373. cinfo->input_scan_number = 0; /* no SOS seen yet */
  153374. cinfo->unread_marker = 0; /* no pending marker */
  153375. marker->pub.saw_SOI = FALSE; /* set internal state too */
  153376. marker->pub.saw_SOF = FALSE;
  153377. marker->pub.discarded_bytes = 0;
  153378. marker->cur_marker = NULL;
  153379. }
  153380. GLOBAL(void)
  153381. jinit_marker_reader (j_decompress_ptr cinfo)
  153382. {
  153383. my_marker_ptr2 marker;
  153384. int i;
  153385. marker = (my_marker_ptr2)
  153386. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
  153387. SIZEOF(my_marker_reader));
  153388. cinfo->marker = (struct jpeg_marker_reader *) marker;
  153389. marker->pub.reset_marker_reader = reset_marker_reader;
  153390. marker->pub.read_markers = read_markers;
  153391. marker->pub.read_restart_marker = read_restart_marker;
  153392. marker->process_COM = skip_variable;
  153393. marker->length_limit_COM = 0;
  153394. for (i = 0; i < 16; i++) {
  153395. marker->process_APPn[i] = skip_variable;
  153396. marker->length_limit_APPn[i] = 0;
  153397. }
  153398. marker->process_APPn[0] = get_interesting_appn;
  153399. marker->process_APPn[14] = get_interesting_appn;
  153400. reset_marker_reader(cinfo);
  153401. }
  153402. #ifdef SAVE_MARKERS_SUPPORTED
  153403. GLOBAL(void)
  153404. jpeg_save_markers (j_decompress_ptr cinfo, int marker_code,
  153405. unsigned int length_limit)
  153406. {
  153407. my_marker_ptr2 marker = (my_marker_ptr2) cinfo->marker;
  153408. long maxlength;
  153409. jpeg_marker_parser_method processor;
  153410. maxlength = cinfo->mem->max_alloc_chunk - SIZEOF(struct jpeg_marker_struct);
  153411. if (((long) length_limit) > maxlength)
  153412. length_limit = (unsigned int) maxlength;
  153413. if (length_limit) {
  153414. processor = save_marker;
  153415. if (marker_code == (int) M_APP0 && length_limit < APP0_DATA_LEN)
  153416. length_limit = APP0_DATA_LEN;
  153417. else if (marker_code == (int) M_APP14 && length_limit < APP14_DATA_LEN)
  153418. length_limit = APP14_DATA_LEN;
  153419. } else {
  153420. processor = skip_variable;
  153421. if (marker_code == (int) M_APP0 || marker_code == (int) M_APP14)
  153422. processor = get_interesting_appn;
  153423. }
  153424. if (marker_code == (int) M_COM) {
  153425. marker->process_COM = processor;
  153426. marker->length_limit_COM = length_limit;
  153427. } else if (marker_code >= (int) M_APP0 && marker_code <= (int) M_APP15) {
  153428. marker->process_APPn[marker_code - (int) M_APP0] = processor;
  153429. marker->length_limit_APPn[marker_code - (int) M_APP0] = length_limit;
  153430. } else
  153431. ERREXIT1(cinfo, JERR_UNKNOWN_MARKER, marker_code);
  153432. }
  153433. #endif /* SAVE_MARKERS_SUPPORTED */
  153434. GLOBAL(void)
  153435. jpeg_set_marker_processor (j_decompress_ptr cinfo, int marker_code,
  153436. jpeg_marker_parser_method routine)
  153437. {
  153438. my_marker_ptr2 marker = (my_marker_ptr2) cinfo->marker;
  153439. if (marker_code == (int) M_COM)
  153440. marker->process_COM = routine;
  153441. else if (marker_code >= (int) M_APP0 && marker_code <= (int) M_APP15)
  153442. marker->process_APPn[marker_code - (int) M_APP0] = routine;
  153443. else
  153444. ERREXIT1(cinfo, JERR_UNKNOWN_MARKER, marker_code);
  153445. }
  153446. /*** End of inlined file: jdmarker.c ***/
  153447. /*** Start of inlined file: jdmaster.c ***/
  153448. #define JPEG_INTERNALS
  153449. typedef struct {
  153450. struct jpeg_decomp_master pub; /* public fields */
  153451. int pass_number; /* # of passes completed */
  153452. boolean using_merged_upsample; /* TRUE if using merged upsample/cconvert */
  153453. struct jpeg_color_quantizer * quantizer_1pass;
  153454. struct jpeg_color_quantizer * quantizer_2pass;
  153455. } my_decomp_master;
  153456. typedef my_decomp_master * my_master_ptr6;
  153457. LOCAL(boolean)
  153458. use_merged_upsample (j_decompress_ptr cinfo)
  153459. {
  153460. #ifdef UPSAMPLE_MERGING_SUPPORTED
  153461. if (cinfo->do_fancy_upsampling || cinfo->CCIR601_sampling)
  153462. return FALSE;
  153463. if (cinfo->jpeg_color_space != JCS_YCbCr || cinfo->num_components != 3 ||
  153464. cinfo->out_color_space != JCS_RGB ||
  153465. cinfo->out_color_components != RGB_PIXELSIZE)
  153466. return FALSE;
  153467. if (cinfo->comp_info[0].h_samp_factor != 2 ||
  153468. cinfo->comp_info[1].h_samp_factor != 1 ||
  153469. cinfo->comp_info[2].h_samp_factor != 1 ||
  153470. cinfo->comp_info[0].v_samp_factor > 2 ||
  153471. cinfo->comp_info[1].v_samp_factor != 1 ||
  153472. cinfo->comp_info[2].v_samp_factor != 1)
  153473. return FALSE;
  153474. if (cinfo->comp_info[0].DCT_scaled_size != cinfo->min_DCT_scaled_size ||
  153475. cinfo->comp_info[1].DCT_scaled_size != cinfo->min_DCT_scaled_size ||
  153476. cinfo->comp_info[2].DCT_scaled_size != cinfo->min_DCT_scaled_size)
  153477. return FALSE;
  153478. return TRUE; /* by golly, it'll work... */
  153479. #else
  153480. return FALSE;
  153481. #endif
  153482. }
  153483. GLOBAL(void)
  153484. jpeg_calc_output_dimensions (j_decompress_ptr cinfo)
  153485. {
  153486. #ifdef IDCT_SCALING_SUPPORTED
  153487. int ci;
  153488. jpeg_component_info *compptr;
  153489. #endif
  153490. if (cinfo->global_state != DSTATE_READY)
  153491. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  153492. #ifdef IDCT_SCALING_SUPPORTED
  153493. if (cinfo->scale_num * 8 <= cinfo->scale_denom) {
  153494. cinfo->output_width = (JDIMENSION)
  153495. jdiv_round_up((long) cinfo->image_width, 8L);
  153496. cinfo->output_height = (JDIMENSION)
  153497. jdiv_round_up((long) cinfo->image_height, 8L);
  153498. cinfo->min_DCT_scaled_size = 1;
  153499. } else if (cinfo->scale_num * 4 <= cinfo->scale_denom) {
  153500. cinfo->output_width = (JDIMENSION)
  153501. jdiv_round_up((long) cinfo->image_width, 4L);
  153502. cinfo->output_height = (JDIMENSION)
  153503. jdiv_round_up((long) cinfo->image_height, 4L);
  153504. cinfo->min_DCT_scaled_size = 2;
  153505. } else if (cinfo->scale_num * 2 <= cinfo->scale_denom) {
  153506. cinfo->output_width = (JDIMENSION)
  153507. jdiv_round_up((long) cinfo->image_width, 2L);
  153508. cinfo->output_height = (JDIMENSION)
  153509. jdiv_round_up((long) cinfo->image_height, 2L);
  153510. cinfo->min_DCT_scaled_size = 4;
  153511. } else {
  153512. cinfo->output_width = cinfo->image_width;
  153513. cinfo->output_height = cinfo->image_height;
  153514. cinfo->min_DCT_scaled_size = DCTSIZE;
  153515. }
  153516. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  153517. ci++, compptr++) {
  153518. int ssize = cinfo->min_DCT_scaled_size;
  153519. while (ssize < DCTSIZE &&
  153520. (compptr->h_samp_factor * ssize * 2 <=
  153521. cinfo->max_h_samp_factor * cinfo->min_DCT_scaled_size) &&
  153522. (compptr->v_samp_factor * ssize * 2 <=
  153523. cinfo->max_v_samp_factor * cinfo->min_DCT_scaled_size)) {
  153524. ssize = ssize * 2;
  153525. }
  153526. compptr->DCT_scaled_size = ssize;
  153527. }
  153528. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  153529. ci++, compptr++) {
  153530. compptr->downsampled_width = (JDIMENSION)
  153531. jdiv_round_up((long) cinfo->image_width *
  153532. (long) (compptr->h_samp_factor * compptr->DCT_scaled_size),
  153533. (long) (cinfo->max_h_samp_factor * DCTSIZE));
  153534. compptr->downsampled_height = (JDIMENSION)
  153535. jdiv_round_up((long) cinfo->image_height *
  153536. (long) (compptr->v_samp_factor * compptr->DCT_scaled_size),
  153537. (long) (cinfo->max_v_samp_factor * DCTSIZE));
  153538. }
  153539. #else /* !IDCT_SCALING_SUPPORTED */
  153540. cinfo->output_width = cinfo->image_width;
  153541. cinfo->output_height = cinfo->image_height;
  153542. #endif /* IDCT_SCALING_SUPPORTED */
  153543. switch (cinfo->out_color_space) {
  153544. case JCS_GRAYSCALE:
  153545. cinfo->out_color_components = 1;
  153546. break;
  153547. case JCS_RGB:
  153548. #if RGB_PIXELSIZE != 3
  153549. cinfo->out_color_components = RGB_PIXELSIZE;
  153550. break;
  153551. #endif /* else share code with YCbCr */
  153552. case JCS_YCbCr:
  153553. cinfo->out_color_components = 3;
  153554. break;
  153555. case JCS_CMYK:
  153556. case JCS_YCCK:
  153557. cinfo->out_color_components = 4;
  153558. break;
  153559. default: /* else must be same colorspace as in file */
  153560. cinfo->out_color_components = cinfo->num_components;
  153561. break;
  153562. }
  153563. cinfo->output_components = (cinfo->quantize_colors ? 1 :
  153564. cinfo->out_color_components);
  153565. if (use_merged_upsample(cinfo))
  153566. cinfo->rec_outbuf_height = cinfo->max_v_samp_factor;
  153567. else
  153568. cinfo->rec_outbuf_height = 1;
  153569. }
  153570. LOCAL(void)
  153571. prepare_range_limit_table (j_decompress_ptr cinfo)
  153572. {
  153573. JSAMPLE * table;
  153574. int i;
  153575. table = (JSAMPLE *)
  153576. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  153577. (5 * (MAXJSAMPLE+1) + CENTERJSAMPLE) * SIZEOF(JSAMPLE));
  153578. table += (MAXJSAMPLE+1); /* allow negative subscripts of simple table */
  153579. cinfo->sample_range_limit = table;
  153580. MEMZERO(table - (MAXJSAMPLE+1), (MAXJSAMPLE+1) * SIZEOF(JSAMPLE));
  153581. for (i = 0; i <= MAXJSAMPLE; i++)
  153582. table[i] = (JSAMPLE) i;
  153583. table += CENTERJSAMPLE; /* Point to where post-IDCT table starts */
  153584. for (i = CENTERJSAMPLE; i < 2*(MAXJSAMPLE+1); i++)
  153585. table[i] = MAXJSAMPLE;
  153586. MEMZERO(table + (2 * (MAXJSAMPLE+1)),
  153587. (2 * (MAXJSAMPLE+1) - CENTERJSAMPLE) * SIZEOF(JSAMPLE));
  153588. MEMCOPY(table + (4 * (MAXJSAMPLE+1) - CENTERJSAMPLE),
  153589. cinfo->sample_range_limit, CENTERJSAMPLE * SIZEOF(JSAMPLE));
  153590. }
  153591. LOCAL(void)
  153592. master_selection (j_decompress_ptr cinfo)
  153593. {
  153594. my_master_ptr6 master = (my_master_ptr6) cinfo->master;
  153595. boolean use_c_buffer;
  153596. long samplesperrow;
  153597. JDIMENSION jd_samplesperrow;
  153598. jpeg_calc_output_dimensions(cinfo);
  153599. prepare_range_limit_table(cinfo);
  153600. samplesperrow = (long) cinfo->output_width * (long) cinfo->out_color_components;
  153601. jd_samplesperrow = (JDIMENSION) samplesperrow;
  153602. if ((long) jd_samplesperrow != samplesperrow)
  153603. ERREXIT(cinfo, JERR_WIDTH_OVERFLOW);
  153604. master->pass_number = 0;
  153605. master->using_merged_upsample = use_merged_upsample(cinfo);
  153606. master->quantizer_1pass = NULL;
  153607. master->quantizer_2pass = NULL;
  153608. if (! cinfo->quantize_colors || ! cinfo->buffered_image) {
  153609. cinfo->enable_1pass_quant = FALSE;
  153610. cinfo->enable_external_quant = FALSE;
  153611. cinfo->enable_2pass_quant = FALSE;
  153612. }
  153613. if (cinfo->quantize_colors) {
  153614. if (cinfo->raw_data_out)
  153615. ERREXIT(cinfo, JERR_NOTIMPL);
  153616. if (cinfo->out_color_components != 3) {
  153617. cinfo->enable_1pass_quant = TRUE;
  153618. cinfo->enable_external_quant = FALSE;
  153619. cinfo->enable_2pass_quant = FALSE;
  153620. cinfo->colormap = NULL;
  153621. } else if (cinfo->colormap != NULL) {
  153622. cinfo->enable_external_quant = TRUE;
  153623. } else if (cinfo->two_pass_quantize) {
  153624. cinfo->enable_2pass_quant = TRUE;
  153625. } else {
  153626. cinfo->enable_1pass_quant = TRUE;
  153627. }
  153628. if (cinfo->enable_1pass_quant) {
  153629. #ifdef QUANT_1PASS_SUPPORTED
  153630. jinit_1pass_quantizer(cinfo);
  153631. master->quantizer_1pass = cinfo->cquantize;
  153632. #else
  153633. ERREXIT(cinfo, JERR_NOT_COMPILED);
  153634. #endif
  153635. }
  153636. if (cinfo->enable_2pass_quant || cinfo->enable_external_quant) {
  153637. #ifdef QUANT_2PASS_SUPPORTED
  153638. jinit_2pass_quantizer(cinfo);
  153639. master->quantizer_2pass = cinfo->cquantize;
  153640. #else
  153641. ERREXIT(cinfo, JERR_NOT_COMPILED);
  153642. #endif
  153643. }
  153644. }
  153645. if (! cinfo->raw_data_out) {
  153646. if (master->using_merged_upsample) {
  153647. #ifdef UPSAMPLE_MERGING_SUPPORTED
  153648. jinit_merged_upsampler(cinfo); /* does color conversion too */
  153649. #else
  153650. ERREXIT(cinfo, JERR_NOT_COMPILED);
  153651. #endif
  153652. } else {
  153653. jinit_color_deconverter(cinfo);
  153654. jinit_upsampler(cinfo);
  153655. }
  153656. jinit_d_post_controller(cinfo, cinfo->enable_2pass_quant);
  153657. }
  153658. jinit_inverse_dct(cinfo);
  153659. if (cinfo->arith_code) {
  153660. ERREXIT(cinfo, JERR_ARITH_NOTIMPL);
  153661. } else {
  153662. if (cinfo->progressive_mode) {
  153663. #ifdef D_PROGRESSIVE_SUPPORTED
  153664. jinit_phuff_decoder(cinfo);
  153665. #else
  153666. ERREXIT(cinfo, JERR_NOT_COMPILED);
  153667. #endif
  153668. } else
  153669. jinit_huff_decoder(cinfo);
  153670. }
  153671. use_c_buffer = cinfo->inputctl->has_multiple_scans || cinfo->buffered_image;
  153672. jinit_d_coef_controller(cinfo, use_c_buffer);
  153673. if (! cinfo->raw_data_out)
  153674. jinit_d_main_controller(cinfo, FALSE /* never need full buffer here */);
  153675. (*cinfo->mem->realize_virt_arrays) ((j_common_ptr) cinfo);
  153676. (*cinfo->inputctl->start_input_pass) (cinfo);
  153677. #ifdef D_MULTISCAN_FILES_SUPPORTED
  153678. if (cinfo->progress != NULL && ! cinfo->buffered_image &&
  153679. cinfo->inputctl->has_multiple_scans) {
  153680. int nscans;
  153681. if (cinfo->progressive_mode) {
  153682. nscans = 2 + 3 * cinfo->num_components;
  153683. } else {
  153684. nscans = cinfo->num_components;
  153685. }
  153686. cinfo->progress->pass_counter = 0L;
  153687. cinfo->progress->pass_limit = (long) cinfo->total_iMCU_rows * nscans;
  153688. cinfo->progress->completed_passes = 0;
  153689. cinfo->progress->total_passes = (cinfo->enable_2pass_quant ? 3 : 2);
  153690. master->pass_number++;
  153691. }
  153692. #endif /* D_MULTISCAN_FILES_SUPPORTED */
  153693. }
  153694. METHODDEF(void)
  153695. prepare_for_output_pass (j_decompress_ptr cinfo)
  153696. {
  153697. my_master_ptr6 master = (my_master_ptr6) cinfo->master;
  153698. if (master->pub.is_dummy_pass) {
  153699. #ifdef QUANT_2PASS_SUPPORTED
  153700. master->pub.is_dummy_pass = FALSE;
  153701. (*cinfo->cquantize->start_pass) (cinfo, FALSE);
  153702. (*cinfo->post->start_pass) (cinfo, JBUF_CRANK_DEST);
  153703. (*cinfo->main->start_pass) (cinfo, JBUF_CRANK_DEST);
  153704. #else
  153705. ERREXIT(cinfo, JERR_NOT_COMPILED);
  153706. #endif /* QUANT_2PASS_SUPPORTED */
  153707. } else {
  153708. if (cinfo->quantize_colors && cinfo->colormap == NULL) {
  153709. if (cinfo->two_pass_quantize && cinfo->enable_2pass_quant) {
  153710. cinfo->cquantize = master->quantizer_2pass;
  153711. master->pub.is_dummy_pass = TRUE;
  153712. } else if (cinfo->enable_1pass_quant) {
  153713. cinfo->cquantize = master->quantizer_1pass;
  153714. } else {
  153715. ERREXIT(cinfo, JERR_MODE_CHANGE);
  153716. }
  153717. }
  153718. (*cinfo->idct->start_pass) (cinfo);
  153719. (*cinfo->coef->start_output_pass) (cinfo);
  153720. if (! cinfo->raw_data_out) {
  153721. if (! master->using_merged_upsample)
  153722. (*cinfo->cconvert->start_pass) (cinfo);
  153723. (*cinfo->upsample->start_pass) (cinfo);
  153724. if (cinfo->quantize_colors)
  153725. (*cinfo->cquantize->start_pass) (cinfo, master->pub.is_dummy_pass);
  153726. (*cinfo->post->start_pass) (cinfo,
  153727. (master->pub.is_dummy_pass ? JBUF_SAVE_AND_PASS : JBUF_PASS_THRU));
  153728. (*cinfo->main->start_pass) (cinfo, JBUF_PASS_THRU);
  153729. }
  153730. }
  153731. if (cinfo->progress != NULL) {
  153732. cinfo->progress->completed_passes = master->pass_number;
  153733. cinfo->progress->total_passes = master->pass_number +
  153734. (master->pub.is_dummy_pass ? 2 : 1);
  153735. if (cinfo->buffered_image && ! cinfo->inputctl->eoi_reached) {
  153736. cinfo->progress->total_passes += (cinfo->enable_2pass_quant ? 2 : 1);
  153737. }
  153738. }
  153739. }
  153740. METHODDEF(void)
  153741. finish_output_pass (j_decompress_ptr cinfo)
  153742. {
  153743. my_master_ptr6 master = (my_master_ptr6) cinfo->master;
  153744. if (cinfo->quantize_colors)
  153745. (*cinfo->cquantize->finish_pass) (cinfo);
  153746. master->pass_number++;
  153747. }
  153748. #ifdef D_MULTISCAN_FILES_SUPPORTED
  153749. GLOBAL(void)
  153750. jpeg_new_colormap (j_decompress_ptr cinfo)
  153751. {
  153752. my_master_ptr6 master = (my_master_ptr6) cinfo->master;
  153753. if (cinfo->global_state != DSTATE_BUFIMAGE)
  153754. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  153755. if (cinfo->quantize_colors && cinfo->enable_external_quant &&
  153756. cinfo->colormap != NULL) {
  153757. cinfo->cquantize = master->quantizer_2pass;
  153758. (*cinfo->cquantize->new_color_map) (cinfo);
  153759. master->pub.is_dummy_pass = FALSE; /* just in case */
  153760. } else
  153761. ERREXIT(cinfo, JERR_MODE_CHANGE);
  153762. }
  153763. #endif /* D_MULTISCAN_FILES_SUPPORTED */
  153764. GLOBAL(void)
  153765. jinit_master_decompress (j_decompress_ptr cinfo)
  153766. {
  153767. my_master_ptr6 master;
  153768. master = (my_master_ptr6)
  153769. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  153770. SIZEOF(my_decomp_master));
  153771. cinfo->master = (struct jpeg_decomp_master *) master;
  153772. master->pub.prepare_for_output_pass = prepare_for_output_pass;
  153773. master->pub.finish_output_pass = finish_output_pass;
  153774. master->pub.is_dummy_pass = FALSE;
  153775. master_selection(cinfo);
  153776. }
  153777. /*** End of inlined file: jdmaster.c ***/
  153778. #undef FIX
  153779. /*** Start of inlined file: jdmerge.c ***/
  153780. #define JPEG_INTERNALS
  153781. #ifdef UPSAMPLE_MERGING_SUPPORTED
  153782. typedef struct {
  153783. struct jpeg_upsampler pub; /* public fields */
  153784. JMETHOD(void, upmethod, (j_decompress_ptr cinfo,
  153785. JSAMPIMAGE input_buf, JDIMENSION in_row_group_ctr,
  153786. JSAMPARRAY output_buf));
  153787. int * Cr_r_tab; /* => table for Cr to R conversion */
  153788. int * Cb_b_tab; /* => table for Cb to B conversion */
  153789. INT32 * Cr_g_tab; /* => table for Cr to G conversion */
  153790. INT32 * Cb_g_tab; /* => table for Cb to G conversion */
  153791. JSAMPROW spare_row;
  153792. boolean spare_full; /* T if spare buffer is occupied */
  153793. JDIMENSION out_row_width; /* samples per output row */
  153794. JDIMENSION rows_to_go; /* counts rows remaining in image */
  153795. } my_upsampler;
  153796. typedef my_upsampler * my_upsample_ptr;
  153797. #define SCALEBITS 16 /* speediest right-shift on some machines */
  153798. #define ONE_HALF ((INT32) 1 << (SCALEBITS-1))
  153799. #define FIX(x) ((INT32) ((x) * (1L<<SCALEBITS) + 0.5))
  153800. LOCAL(void)
  153801. build_ycc_rgb_table2 (j_decompress_ptr cinfo)
  153802. {
  153803. my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;
  153804. int i;
  153805. INT32 x;
  153806. SHIFT_TEMPS
  153807. upsample->Cr_r_tab = (int *)
  153808. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  153809. (MAXJSAMPLE+1) * SIZEOF(int));
  153810. upsample->Cb_b_tab = (int *)
  153811. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  153812. (MAXJSAMPLE+1) * SIZEOF(int));
  153813. upsample->Cr_g_tab = (INT32 *)
  153814. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  153815. (MAXJSAMPLE+1) * SIZEOF(INT32));
  153816. upsample->Cb_g_tab = (INT32 *)
  153817. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  153818. (MAXJSAMPLE+1) * SIZEOF(INT32));
  153819. for (i = 0, x = -CENTERJSAMPLE; i <= MAXJSAMPLE; i++, x++) {
  153820. upsample->Cr_r_tab[i] = (int)
  153821. RIGHT_SHIFT(FIX(1.40200) * x + ONE_HALF, SCALEBITS);
  153822. upsample->Cb_b_tab[i] = (int)
  153823. RIGHT_SHIFT(FIX(1.77200) * x + ONE_HALF, SCALEBITS);
  153824. upsample->Cr_g_tab[i] = (- FIX(0.71414)) * x;
  153825. upsample->Cb_g_tab[i] = (- FIX(0.34414)) * x + ONE_HALF;
  153826. }
  153827. }
  153828. METHODDEF(void)
  153829. start_pass_merged_upsample (j_decompress_ptr cinfo)
  153830. {
  153831. my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;
  153832. upsample->spare_full = FALSE;
  153833. upsample->rows_to_go = cinfo->output_height;
  153834. }
  153835. METHODDEF(void)
  153836. merged_2v_upsample (j_decompress_ptr cinfo,
  153837. JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
  153838. JDIMENSION in_row_groups_avail,
  153839. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  153840. JDIMENSION out_rows_avail)
  153841. {
  153842. my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;
  153843. JSAMPROW work_ptrs[2];
  153844. JDIMENSION num_rows; /* number of rows returned to caller */
  153845. if (upsample->spare_full) {
  153846. jcopy_sample_rows(& upsample->spare_row, 0, output_buf + *out_row_ctr, 0,
  153847. 1, upsample->out_row_width);
  153848. num_rows = 1;
  153849. upsample->spare_full = FALSE;
  153850. } else {
  153851. num_rows = 2;
  153852. if (num_rows > upsample->rows_to_go)
  153853. num_rows = upsample->rows_to_go;
  153854. out_rows_avail -= *out_row_ctr;
  153855. if (num_rows > out_rows_avail)
  153856. num_rows = out_rows_avail;
  153857. work_ptrs[0] = output_buf[*out_row_ctr];
  153858. if (num_rows > 1) {
  153859. work_ptrs[1] = output_buf[*out_row_ctr + 1];
  153860. } else {
  153861. work_ptrs[1] = upsample->spare_row;
  153862. upsample->spare_full = TRUE;
  153863. }
  153864. (*upsample->upmethod) (cinfo, input_buf, *in_row_group_ctr, work_ptrs);
  153865. }
  153866. *out_row_ctr += num_rows;
  153867. upsample->rows_to_go -= num_rows;
  153868. if (! upsample->spare_full)
  153869. (*in_row_group_ctr)++;
  153870. }
  153871. METHODDEF(void)
  153872. merged_1v_upsample (j_decompress_ptr cinfo,
  153873. JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
  153874. JDIMENSION in_row_groups_avail,
  153875. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  153876. JDIMENSION out_rows_avail)
  153877. {
  153878. my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;
  153879. (*upsample->upmethod) (cinfo, input_buf, *in_row_group_ctr,
  153880. output_buf + *out_row_ctr);
  153881. (*out_row_ctr)++;
  153882. (*in_row_group_ctr)++;
  153883. }
  153884. METHODDEF(void)
  153885. h2v1_merged_upsample (j_decompress_ptr cinfo,
  153886. JSAMPIMAGE input_buf, JDIMENSION in_row_group_ctr,
  153887. JSAMPARRAY output_buf)
  153888. {
  153889. my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;
  153890. register int y, cred, cgreen, cblue;
  153891. int cb, cr;
  153892. register JSAMPROW outptr;
  153893. JSAMPROW inptr0, inptr1, inptr2;
  153894. JDIMENSION col;
  153895. register JSAMPLE * range_limit = cinfo->sample_range_limit;
  153896. int * Crrtab = upsample->Cr_r_tab;
  153897. int * Cbbtab = upsample->Cb_b_tab;
  153898. INT32 * Crgtab = upsample->Cr_g_tab;
  153899. INT32 * Cbgtab = upsample->Cb_g_tab;
  153900. SHIFT_TEMPS
  153901. inptr0 = input_buf[0][in_row_group_ctr];
  153902. inptr1 = input_buf[1][in_row_group_ctr];
  153903. inptr2 = input_buf[2][in_row_group_ctr];
  153904. outptr = output_buf[0];
  153905. for (col = cinfo->output_width >> 1; col > 0; col--) {
  153906. cb = GETJSAMPLE(*inptr1++);
  153907. cr = GETJSAMPLE(*inptr2++);
  153908. cred = Crrtab[cr];
  153909. cgreen = (int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS);
  153910. cblue = Cbbtab[cb];
  153911. y = GETJSAMPLE(*inptr0++);
  153912. outptr[RGB_RED] = range_limit[y + cred];
  153913. outptr[RGB_GREEN] = range_limit[y + cgreen];
  153914. outptr[RGB_BLUE] = range_limit[y + cblue];
  153915. outptr += RGB_PIXELSIZE;
  153916. y = GETJSAMPLE(*inptr0++);
  153917. outptr[RGB_RED] = range_limit[y + cred];
  153918. outptr[RGB_GREEN] = range_limit[y + cgreen];
  153919. outptr[RGB_BLUE] = range_limit[y + cblue];
  153920. outptr += RGB_PIXELSIZE;
  153921. }
  153922. if (cinfo->output_width & 1) {
  153923. cb = GETJSAMPLE(*inptr1);
  153924. cr = GETJSAMPLE(*inptr2);
  153925. cred = Crrtab[cr];
  153926. cgreen = (int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS);
  153927. cblue = Cbbtab[cb];
  153928. y = GETJSAMPLE(*inptr0);
  153929. outptr[RGB_RED] = range_limit[y + cred];
  153930. outptr[RGB_GREEN] = range_limit[y + cgreen];
  153931. outptr[RGB_BLUE] = range_limit[y + cblue];
  153932. }
  153933. }
  153934. METHODDEF(void)
  153935. h2v2_merged_upsample (j_decompress_ptr cinfo,
  153936. JSAMPIMAGE input_buf, JDIMENSION in_row_group_ctr,
  153937. JSAMPARRAY output_buf)
  153938. {
  153939. my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;
  153940. register int y, cred, cgreen, cblue;
  153941. int cb, cr;
  153942. register JSAMPROW outptr0, outptr1;
  153943. JSAMPROW inptr00, inptr01, inptr1, inptr2;
  153944. JDIMENSION col;
  153945. register JSAMPLE * range_limit = cinfo->sample_range_limit;
  153946. int * Crrtab = upsample->Cr_r_tab;
  153947. int * Cbbtab = upsample->Cb_b_tab;
  153948. INT32 * Crgtab = upsample->Cr_g_tab;
  153949. INT32 * Cbgtab = upsample->Cb_g_tab;
  153950. SHIFT_TEMPS
  153951. inptr00 = input_buf[0][in_row_group_ctr*2];
  153952. inptr01 = input_buf[0][in_row_group_ctr*2 + 1];
  153953. inptr1 = input_buf[1][in_row_group_ctr];
  153954. inptr2 = input_buf[2][in_row_group_ctr];
  153955. outptr0 = output_buf[0];
  153956. outptr1 = output_buf[1];
  153957. for (col = cinfo->output_width >> 1; col > 0; col--) {
  153958. cb = GETJSAMPLE(*inptr1++);
  153959. cr = GETJSAMPLE(*inptr2++);
  153960. cred = Crrtab[cr];
  153961. cgreen = (int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS);
  153962. cblue = Cbbtab[cb];
  153963. y = GETJSAMPLE(*inptr00++);
  153964. outptr0[RGB_RED] = range_limit[y + cred];
  153965. outptr0[RGB_GREEN] = range_limit[y + cgreen];
  153966. outptr0[RGB_BLUE] = range_limit[y + cblue];
  153967. outptr0 += RGB_PIXELSIZE;
  153968. y = GETJSAMPLE(*inptr00++);
  153969. outptr0[RGB_RED] = range_limit[y + cred];
  153970. outptr0[RGB_GREEN] = range_limit[y + cgreen];
  153971. outptr0[RGB_BLUE] = range_limit[y + cblue];
  153972. outptr0 += RGB_PIXELSIZE;
  153973. y = GETJSAMPLE(*inptr01++);
  153974. outptr1[RGB_RED] = range_limit[y + cred];
  153975. outptr1[RGB_GREEN] = range_limit[y + cgreen];
  153976. outptr1[RGB_BLUE] = range_limit[y + cblue];
  153977. outptr1 += RGB_PIXELSIZE;
  153978. y = GETJSAMPLE(*inptr01++);
  153979. outptr1[RGB_RED] = range_limit[y + cred];
  153980. outptr1[RGB_GREEN] = range_limit[y + cgreen];
  153981. outptr1[RGB_BLUE] = range_limit[y + cblue];
  153982. outptr1 += RGB_PIXELSIZE;
  153983. }
  153984. if (cinfo->output_width & 1) {
  153985. cb = GETJSAMPLE(*inptr1);
  153986. cr = GETJSAMPLE(*inptr2);
  153987. cred = Crrtab[cr];
  153988. cgreen = (int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS);
  153989. cblue = Cbbtab[cb];
  153990. y = GETJSAMPLE(*inptr00);
  153991. outptr0[RGB_RED] = range_limit[y + cred];
  153992. outptr0[RGB_GREEN] = range_limit[y + cgreen];
  153993. outptr0[RGB_BLUE] = range_limit[y + cblue];
  153994. y = GETJSAMPLE(*inptr01);
  153995. outptr1[RGB_RED] = range_limit[y + cred];
  153996. outptr1[RGB_GREEN] = range_limit[y + cgreen];
  153997. outptr1[RGB_BLUE] = range_limit[y + cblue];
  153998. }
  153999. }
  154000. GLOBAL(void)
  154001. jinit_merged_upsampler (j_decompress_ptr cinfo)
  154002. {
  154003. my_upsample_ptr upsample;
  154004. upsample = (my_upsample_ptr)
  154005. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  154006. SIZEOF(my_upsampler));
  154007. cinfo->upsample = (struct jpeg_upsampler *) upsample;
  154008. upsample->pub.start_pass = start_pass_merged_upsample;
  154009. upsample->pub.need_context_rows = FALSE;
  154010. upsample->out_row_width = cinfo->output_width * cinfo->out_color_components;
  154011. if (cinfo->max_v_samp_factor == 2) {
  154012. upsample->pub.upsample = merged_2v_upsample;
  154013. upsample->upmethod = h2v2_merged_upsample;
  154014. upsample->spare_row = (JSAMPROW)
  154015. (*cinfo->mem->alloc_large) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  154016. (size_t) (upsample->out_row_width * SIZEOF(JSAMPLE)));
  154017. } else {
  154018. upsample->pub.upsample = merged_1v_upsample;
  154019. upsample->upmethod = h2v1_merged_upsample;
  154020. upsample->spare_row = NULL;
  154021. }
  154022. build_ycc_rgb_table2(cinfo);
  154023. }
  154024. #endif /* UPSAMPLE_MERGING_SUPPORTED */
  154025. /*** End of inlined file: jdmerge.c ***/
  154026. #undef ASSIGN_STATE
  154027. /*** Start of inlined file: jdphuff.c ***/
  154028. #define JPEG_INTERNALS
  154029. #ifdef D_PROGRESSIVE_SUPPORTED
  154030. typedef struct {
  154031. unsigned int EOBRUN; /* remaining EOBs in EOBRUN */
  154032. int last_dc_val[MAX_COMPS_IN_SCAN]; /* last DC coef for each component */
  154033. } savable_state3;
  154034. #ifndef NO_STRUCT_ASSIGN
  154035. #define ASSIGN_STATE(dest,src) ((dest) = (src))
  154036. #else
  154037. #if MAX_COMPS_IN_SCAN == 4
  154038. #define ASSIGN_STATE(dest,src) \
  154039. ((dest).EOBRUN = (src).EOBRUN, \
  154040. (dest).last_dc_val[0] = (src).last_dc_val[0], \
  154041. (dest).last_dc_val[1] = (src).last_dc_val[1], \
  154042. (dest).last_dc_val[2] = (src).last_dc_val[2], \
  154043. (dest).last_dc_val[3] = (src).last_dc_val[3])
  154044. #endif
  154045. #endif
  154046. typedef struct {
  154047. struct jpeg_entropy_decoder pub; /* public fields */
  154048. bitread_perm_state bitstate; /* Bit buffer at start of MCU */
  154049. savable_state3 saved; /* Other state at start of MCU */
  154050. unsigned int restarts_to_go; /* MCUs left in this restart interval */
  154051. d_derived_tbl * derived_tbls[NUM_HUFF_TBLS];
  154052. d_derived_tbl * ac_derived_tbl; /* active table during an AC scan */
  154053. } phuff_entropy_decoder;
  154054. typedef phuff_entropy_decoder * phuff_entropy_ptr2;
  154055. METHODDEF(boolean) decode_mcu_DC_first JPP((j_decompress_ptr cinfo,
  154056. JBLOCKROW *MCU_data));
  154057. METHODDEF(boolean) decode_mcu_AC_first JPP((j_decompress_ptr cinfo,
  154058. JBLOCKROW *MCU_data));
  154059. METHODDEF(boolean) decode_mcu_DC_refine JPP((j_decompress_ptr cinfo,
  154060. JBLOCKROW *MCU_data));
  154061. METHODDEF(boolean) decode_mcu_AC_refine JPP((j_decompress_ptr cinfo,
  154062. JBLOCKROW *MCU_data));
  154063. METHODDEF(void)
  154064. start_pass_phuff_decoder (j_decompress_ptr cinfo)
  154065. {
  154066. phuff_entropy_ptr2 entropy = (phuff_entropy_ptr2) cinfo->entropy;
  154067. boolean is_DC_band, bad;
  154068. int ci, coefi, tbl;
  154069. int *coef_bit_ptr;
  154070. jpeg_component_info * compptr;
  154071. is_DC_band = (cinfo->Ss == 0);
  154072. bad = FALSE;
  154073. if (is_DC_band) {
  154074. if (cinfo->Se != 0)
  154075. bad = TRUE;
  154076. } else {
  154077. if (cinfo->Ss > cinfo->Se || cinfo->Se >= DCTSIZE2)
  154078. bad = TRUE;
  154079. if (cinfo->comps_in_scan != 1)
  154080. bad = TRUE;
  154081. }
  154082. if (cinfo->Ah != 0) {
  154083. if (cinfo->Al != cinfo->Ah-1)
  154084. bad = TRUE;
  154085. }
  154086. if (cinfo->Al > 13) /* need not check for < 0 */
  154087. bad = TRUE;
  154088. if (bad)
  154089. ERREXIT4(cinfo, JERR_BAD_PROGRESSION,
  154090. cinfo->Ss, cinfo->Se, cinfo->Ah, cinfo->Al);
  154091. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  154092. int cindex = cinfo->cur_comp_info[ci]->component_index;
  154093. coef_bit_ptr = & cinfo->coef_bits[cindex][0];
  154094. if (!is_DC_band && coef_bit_ptr[0] < 0) /* AC without prior DC scan */
  154095. WARNMS2(cinfo, JWRN_BOGUS_PROGRESSION, cindex, 0);
  154096. for (coefi = cinfo->Ss; coefi <= cinfo->Se; coefi++) {
  154097. int expected = (coef_bit_ptr[coefi] < 0) ? 0 : coef_bit_ptr[coefi];
  154098. if (cinfo->Ah != expected)
  154099. WARNMS2(cinfo, JWRN_BOGUS_PROGRESSION, cindex, coefi);
  154100. coef_bit_ptr[coefi] = cinfo->Al;
  154101. }
  154102. }
  154103. if (cinfo->Ah == 0) {
  154104. if (is_DC_band)
  154105. entropy->pub.decode_mcu = decode_mcu_DC_first;
  154106. else
  154107. entropy->pub.decode_mcu = decode_mcu_AC_first;
  154108. } else {
  154109. if (is_DC_band)
  154110. entropy->pub.decode_mcu = decode_mcu_DC_refine;
  154111. else
  154112. entropy->pub.decode_mcu = decode_mcu_AC_refine;
  154113. }
  154114. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  154115. compptr = cinfo->cur_comp_info[ci];
  154116. if (is_DC_band) {
  154117. if (cinfo->Ah == 0) { /* DC refinement needs no table */
  154118. tbl = compptr->dc_tbl_no;
  154119. jpeg_make_d_derived_tbl(cinfo, TRUE, tbl,
  154120. & entropy->derived_tbls[tbl]);
  154121. }
  154122. } else {
  154123. tbl = compptr->ac_tbl_no;
  154124. jpeg_make_d_derived_tbl(cinfo, FALSE, tbl,
  154125. & entropy->derived_tbls[tbl]);
  154126. entropy->ac_derived_tbl = entropy->derived_tbls[tbl];
  154127. }
  154128. entropy->saved.last_dc_val[ci] = 0;
  154129. }
  154130. entropy->bitstate.bits_left = 0;
  154131. entropy->bitstate.get_buffer = 0; /* unnecessary, but keeps Purify quiet */
  154132. entropy->pub.insufficient_data = FALSE;
  154133. entropy->saved.EOBRUN = 0;
  154134. entropy->restarts_to_go = cinfo->restart_interval;
  154135. }
  154136. LOCAL(boolean)
  154137. process_restartp (j_decompress_ptr cinfo)
  154138. {
  154139. phuff_entropy_ptr2 entropy = (phuff_entropy_ptr2) cinfo->entropy;
  154140. int ci;
  154141. cinfo->marker->discarded_bytes += entropy->bitstate.bits_left / 8;
  154142. entropy->bitstate.bits_left = 0;
  154143. if (! (*cinfo->marker->read_restart_marker) (cinfo))
  154144. return FALSE;
  154145. for (ci = 0; ci < cinfo->comps_in_scan; ci++)
  154146. entropy->saved.last_dc_val[ci] = 0;
  154147. entropy->saved.EOBRUN = 0;
  154148. entropy->restarts_to_go = cinfo->restart_interval;
  154149. if (cinfo->unread_marker == 0)
  154150. entropy->pub.insufficient_data = FALSE;
  154151. return TRUE;
  154152. }
  154153. METHODDEF(boolean)
  154154. decode_mcu_DC_first (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
  154155. {
  154156. phuff_entropy_ptr2 entropy = (phuff_entropy_ptr2) cinfo->entropy;
  154157. int Al = cinfo->Al;
  154158. register int s, r;
  154159. int blkn, ci;
  154160. JBLOCKROW block;
  154161. BITREAD_STATE_VARS;
  154162. savable_state3 state;
  154163. d_derived_tbl * tbl;
  154164. jpeg_component_info * compptr;
  154165. if (cinfo->restart_interval) {
  154166. if (entropy->restarts_to_go == 0)
  154167. if (! process_restartp(cinfo))
  154168. return FALSE;
  154169. }
  154170. if (! entropy->pub.insufficient_data) {
  154171. BITREAD_LOAD_STATE(cinfo,entropy->bitstate);
  154172. ASSIGN_STATE(state, entropy->saved);
  154173. for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
  154174. block = MCU_data[blkn];
  154175. ci = cinfo->MCU_membership[blkn];
  154176. compptr = cinfo->cur_comp_info[ci];
  154177. tbl = entropy->derived_tbls[compptr->dc_tbl_no];
  154178. HUFF_DECODE(s, br_state, tbl, return FALSE, label1);
  154179. if (s) {
  154180. CHECK_BIT_BUFFER(br_state, s, return FALSE);
  154181. r = GET_BITS(s);
  154182. s = HUFF_EXTEND(r, s);
  154183. }
  154184. s += state.last_dc_val[ci];
  154185. state.last_dc_val[ci] = s;
  154186. (*block)[0] = (JCOEF) (s << Al);
  154187. }
  154188. BITREAD_SAVE_STATE(cinfo,entropy->bitstate);
  154189. ASSIGN_STATE(entropy->saved, state);
  154190. }
  154191. entropy->restarts_to_go--;
  154192. return TRUE;
  154193. }
  154194. METHODDEF(boolean)
  154195. decode_mcu_AC_first (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
  154196. {
  154197. phuff_entropy_ptr2 entropy = (phuff_entropy_ptr2) cinfo->entropy;
  154198. int Se = cinfo->Se;
  154199. int Al = cinfo->Al;
  154200. register int s, k, r;
  154201. unsigned int EOBRUN;
  154202. JBLOCKROW block;
  154203. BITREAD_STATE_VARS;
  154204. d_derived_tbl * tbl;
  154205. if (cinfo->restart_interval) {
  154206. if (entropy->restarts_to_go == 0)
  154207. if (! process_restartp(cinfo))
  154208. return FALSE;
  154209. }
  154210. if (! entropy->pub.insufficient_data) {
  154211. EOBRUN = entropy->saved.EOBRUN; /* only part of saved state we need */
  154212. if (EOBRUN > 0) /* if it's a band of zeroes... */
  154213. EOBRUN--; /* ...process it now (we do nothing) */
  154214. else {
  154215. BITREAD_LOAD_STATE(cinfo,entropy->bitstate);
  154216. block = MCU_data[0];
  154217. tbl = entropy->ac_derived_tbl;
  154218. for (k = cinfo->Ss; k <= Se; k++) {
  154219. HUFF_DECODE(s, br_state, tbl, return FALSE, label2);
  154220. r = s >> 4;
  154221. s &= 15;
  154222. if (s) {
  154223. k += r;
  154224. CHECK_BIT_BUFFER(br_state, s, return FALSE);
  154225. r = GET_BITS(s);
  154226. s = HUFF_EXTEND(r, s);
  154227. (*block)[jpeg_natural_order[k]] = (JCOEF) (s << Al);
  154228. } else {
  154229. if (r == 15) { /* ZRL */
  154230. k += 15; /* skip 15 zeroes in band */
  154231. } else { /* EOBr, run length is 2^r + appended bits */
  154232. EOBRUN = 1 << r;
  154233. if (r) { /* EOBr, r > 0 */
  154234. CHECK_BIT_BUFFER(br_state, r, return FALSE);
  154235. r = GET_BITS(r);
  154236. EOBRUN += r;
  154237. }
  154238. EOBRUN--; /* this band is processed at this moment */
  154239. break; /* force end-of-band */
  154240. }
  154241. }
  154242. }
  154243. BITREAD_SAVE_STATE(cinfo,entropy->bitstate);
  154244. }
  154245. entropy->saved.EOBRUN = EOBRUN; /* only part of saved state we need */
  154246. }
  154247. entropy->restarts_to_go--;
  154248. return TRUE;
  154249. }
  154250. METHODDEF(boolean)
  154251. decode_mcu_DC_refine (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
  154252. {
  154253. phuff_entropy_ptr2 entropy = (phuff_entropy_ptr2) cinfo->entropy;
  154254. int p1 = 1 << cinfo->Al; /* 1 in the bit position being coded */
  154255. int blkn;
  154256. JBLOCKROW block;
  154257. BITREAD_STATE_VARS;
  154258. if (cinfo->restart_interval) {
  154259. if (entropy->restarts_to_go == 0)
  154260. if (! process_restartp(cinfo))
  154261. return FALSE;
  154262. }
  154263. BITREAD_LOAD_STATE(cinfo,entropy->bitstate);
  154264. for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
  154265. block = MCU_data[blkn];
  154266. CHECK_BIT_BUFFER(br_state, 1, return FALSE);
  154267. if (GET_BITS(1))
  154268. (*block)[0] |= p1;
  154269. }
  154270. BITREAD_SAVE_STATE(cinfo,entropy->bitstate);
  154271. entropy->restarts_to_go--;
  154272. return TRUE;
  154273. }
  154274. METHODDEF(boolean)
  154275. decode_mcu_AC_refine (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
  154276. {
  154277. phuff_entropy_ptr2 entropy = (phuff_entropy_ptr2) cinfo->entropy;
  154278. int Se = cinfo->Se;
  154279. int p1 = 1 << cinfo->Al; /* 1 in the bit position being coded */
  154280. int m1 = (-1) << cinfo->Al; /* -1 in the bit position being coded */
  154281. register int s, k, r;
  154282. unsigned int EOBRUN;
  154283. JBLOCKROW block;
  154284. JCOEFPTR thiscoef;
  154285. BITREAD_STATE_VARS;
  154286. d_derived_tbl * tbl;
  154287. int num_newnz;
  154288. int newnz_pos[DCTSIZE2];
  154289. if (cinfo->restart_interval) {
  154290. if (entropy->restarts_to_go == 0)
  154291. if (! process_restartp(cinfo))
  154292. return FALSE;
  154293. }
  154294. if (! entropy->pub.insufficient_data) {
  154295. BITREAD_LOAD_STATE(cinfo,entropy->bitstate);
  154296. EOBRUN = entropy->saved.EOBRUN; /* only part of saved state we need */
  154297. block = MCU_data[0];
  154298. tbl = entropy->ac_derived_tbl;
  154299. num_newnz = 0;
  154300. k = cinfo->Ss;
  154301. if (EOBRUN == 0) {
  154302. for (; k <= Se; k++) {
  154303. HUFF_DECODE(s, br_state, tbl, goto undoit, label3);
  154304. r = s >> 4;
  154305. s &= 15;
  154306. if (s) {
  154307. if (s != 1) /* size of new coef should always be 1 */
  154308. WARNMS(cinfo, JWRN_HUFF_BAD_CODE);
  154309. CHECK_BIT_BUFFER(br_state, 1, goto undoit);
  154310. if (GET_BITS(1))
  154311. s = p1; /* newly nonzero coef is positive */
  154312. else
  154313. s = m1; /* newly nonzero coef is negative */
  154314. } else {
  154315. if (r != 15) {
  154316. EOBRUN = 1 << r; /* EOBr, run length is 2^r + appended bits */
  154317. if (r) {
  154318. CHECK_BIT_BUFFER(br_state, r, goto undoit);
  154319. r = GET_BITS(r);
  154320. EOBRUN += r;
  154321. }
  154322. break; /* rest of block is handled by EOB logic */
  154323. }
  154324. }
  154325. do {
  154326. thiscoef = *block + jpeg_natural_order[k];
  154327. if (*thiscoef != 0) {
  154328. CHECK_BIT_BUFFER(br_state, 1, goto undoit);
  154329. if (GET_BITS(1)) {
  154330. if ((*thiscoef & p1) == 0) { /* do nothing if already set it */
  154331. if (*thiscoef >= 0)
  154332. *thiscoef += p1;
  154333. else
  154334. *thiscoef += m1;
  154335. }
  154336. }
  154337. } else {
  154338. if (--r < 0)
  154339. break; /* reached target zero coefficient */
  154340. }
  154341. k++;
  154342. } while (k <= Se);
  154343. if (s) {
  154344. int pos = jpeg_natural_order[k];
  154345. (*block)[pos] = (JCOEF) s;
  154346. newnz_pos[num_newnz++] = pos;
  154347. }
  154348. }
  154349. }
  154350. if (EOBRUN > 0) {
  154351. for (; k <= Se; k++) {
  154352. thiscoef = *block + jpeg_natural_order[k];
  154353. if (*thiscoef != 0) {
  154354. CHECK_BIT_BUFFER(br_state, 1, goto undoit);
  154355. if (GET_BITS(1)) {
  154356. if ((*thiscoef & p1) == 0) { /* do nothing if already changed it */
  154357. if (*thiscoef >= 0)
  154358. *thiscoef += p1;
  154359. else
  154360. *thiscoef += m1;
  154361. }
  154362. }
  154363. }
  154364. }
  154365. EOBRUN--;
  154366. }
  154367. BITREAD_SAVE_STATE(cinfo,entropy->bitstate);
  154368. entropy->saved.EOBRUN = EOBRUN; /* only part of saved state we need */
  154369. }
  154370. entropy->restarts_to_go--;
  154371. return TRUE;
  154372. undoit:
  154373. while (num_newnz > 0)
  154374. (*block)[newnz_pos[--num_newnz]] = 0;
  154375. return FALSE;
  154376. }
  154377. GLOBAL(void)
  154378. jinit_phuff_decoder (j_decompress_ptr cinfo)
  154379. {
  154380. phuff_entropy_ptr2 entropy;
  154381. int *coef_bit_ptr;
  154382. int ci, i;
  154383. entropy = (phuff_entropy_ptr2)
  154384. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  154385. SIZEOF(phuff_entropy_decoder));
  154386. cinfo->entropy = (struct jpeg_entropy_decoder *) entropy;
  154387. entropy->pub.start_pass = start_pass_phuff_decoder;
  154388. for (i = 0; i < NUM_HUFF_TBLS; i++) {
  154389. entropy->derived_tbls[i] = NULL;
  154390. }
  154391. cinfo->coef_bits = (int (*)[DCTSIZE2])
  154392. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  154393. cinfo->num_components*DCTSIZE2*SIZEOF(int));
  154394. coef_bit_ptr = & cinfo->coef_bits[0][0];
  154395. for (ci = 0; ci < cinfo->num_components; ci++)
  154396. for (i = 0; i < DCTSIZE2; i++)
  154397. *coef_bit_ptr++ = -1;
  154398. }
  154399. #endif /* D_PROGRESSIVE_SUPPORTED */
  154400. /*** End of inlined file: jdphuff.c ***/
  154401. /*** Start of inlined file: jdpostct.c ***/
  154402. #define JPEG_INTERNALS
  154403. typedef struct {
  154404. struct jpeg_d_post_controller pub; /* public fields */
  154405. jvirt_sarray_ptr whole_image; /* virtual array, or NULL if one-pass */
  154406. JSAMPARRAY buffer; /* strip buffer, or current strip of virtual */
  154407. JDIMENSION strip_height; /* buffer size in rows */
  154408. JDIMENSION starting_row; /* row # of first row in current strip */
  154409. JDIMENSION next_row; /* index of next row to fill/empty in strip */
  154410. } my_post_controller;
  154411. typedef my_post_controller * my_post_ptr;
  154412. METHODDEF(void) post_process_1pass
  154413. JPP((j_decompress_ptr cinfo,
  154414. JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
  154415. JDIMENSION in_row_groups_avail,
  154416. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  154417. JDIMENSION out_rows_avail));
  154418. #ifdef QUANT_2PASS_SUPPORTED
  154419. METHODDEF(void) post_process_prepass
  154420. JPP((j_decompress_ptr cinfo,
  154421. JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
  154422. JDIMENSION in_row_groups_avail,
  154423. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  154424. JDIMENSION out_rows_avail));
  154425. METHODDEF(void) post_process_2pass
  154426. JPP((j_decompress_ptr cinfo,
  154427. JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
  154428. JDIMENSION in_row_groups_avail,
  154429. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  154430. JDIMENSION out_rows_avail));
  154431. #endif
  154432. METHODDEF(void)
  154433. start_pass_dpost (j_decompress_ptr cinfo, J_BUF_MODE pass_mode)
  154434. {
  154435. my_post_ptr post = (my_post_ptr) cinfo->post;
  154436. switch (pass_mode) {
  154437. case JBUF_PASS_THRU:
  154438. if (cinfo->quantize_colors) {
  154439. post->pub.post_process_data = post_process_1pass;
  154440. if (post->buffer == NULL) {
  154441. post->buffer = (*cinfo->mem->access_virt_sarray)
  154442. ((j_common_ptr) cinfo, post->whole_image,
  154443. (JDIMENSION) 0, post->strip_height, TRUE);
  154444. }
  154445. } else {
  154446. post->pub.post_process_data = cinfo->upsample->upsample;
  154447. }
  154448. break;
  154449. #ifdef QUANT_2PASS_SUPPORTED
  154450. case JBUF_SAVE_AND_PASS:
  154451. if (post->whole_image == NULL)
  154452. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  154453. post->pub.post_process_data = post_process_prepass;
  154454. break;
  154455. case JBUF_CRANK_DEST:
  154456. if (post->whole_image == NULL)
  154457. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  154458. post->pub.post_process_data = post_process_2pass;
  154459. break;
  154460. #endif /* QUANT_2PASS_SUPPORTED */
  154461. default:
  154462. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  154463. break;
  154464. }
  154465. post->starting_row = post->next_row = 0;
  154466. }
  154467. METHODDEF(void)
  154468. post_process_1pass (j_decompress_ptr cinfo,
  154469. JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
  154470. JDIMENSION in_row_groups_avail,
  154471. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  154472. JDIMENSION out_rows_avail)
  154473. {
  154474. my_post_ptr post = (my_post_ptr) cinfo->post;
  154475. JDIMENSION num_rows, max_rows;
  154476. max_rows = out_rows_avail - *out_row_ctr;
  154477. if (max_rows > post->strip_height)
  154478. max_rows = post->strip_height;
  154479. num_rows = 0;
  154480. (*cinfo->upsample->upsample) (cinfo,
  154481. input_buf, in_row_group_ctr, in_row_groups_avail,
  154482. post->buffer, &num_rows, max_rows);
  154483. (*cinfo->cquantize->color_quantize) (cinfo,
  154484. post->buffer, output_buf + *out_row_ctr, (int) num_rows);
  154485. *out_row_ctr += num_rows;
  154486. }
  154487. #ifdef QUANT_2PASS_SUPPORTED
  154488. METHODDEF(void)
  154489. post_process_prepass (j_decompress_ptr cinfo,
  154490. JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
  154491. JDIMENSION in_row_groups_avail,
  154492. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  154493. JDIMENSION out_rows_avail)
  154494. {
  154495. my_post_ptr post = (my_post_ptr) cinfo->post;
  154496. JDIMENSION old_next_row, num_rows;
  154497. if (post->next_row == 0) {
  154498. post->buffer = (*cinfo->mem->access_virt_sarray)
  154499. ((j_common_ptr) cinfo, post->whole_image,
  154500. post->starting_row, post->strip_height, TRUE);
  154501. }
  154502. old_next_row = post->next_row;
  154503. (*cinfo->upsample->upsample) (cinfo,
  154504. input_buf, in_row_group_ctr, in_row_groups_avail,
  154505. post->buffer, &post->next_row, post->strip_height);
  154506. if (post->next_row > old_next_row) {
  154507. num_rows = post->next_row - old_next_row;
  154508. (*cinfo->cquantize->color_quantize) (cinfo, post->buffer + old_next_row,
  154509. (JSAMPARRAY) NULL, (int) num_rows);
  154510. *out_row_ctr += num_rows;
  154511. }
  154512. if (post->next_row >= post->strip_height) {
  154513. post->starting_row += post->strip_height;
  154514. post->next_row = 0;
  154515. }
  154516. }
  154517. METHODDEF(void)
  154518. post_process_2pass (j_decompress_ptr cinfo,
  154519. JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
  154520. JDIMENSION in_row_groups_avail,
  154521. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  154522. JDIMENSION out_rows_avail)
  154523. {
  154524. my_post_ptr post = (my_post_ptr) cinfo->post;
  154525. JDIMENSION num_rows, max_rows;
  154526. if (post->next_row == 0) {
  154527. post->buffer = (*cinfo->mem->access_virt_sarray)
  154528. ((j_common_ptr) cinfo, post->whole_image,
  154529. post->starting_row, post->strip_height, FALSE);
  154530. }
  154531. num_rows = post->strip_height - post->next_row; /* available in strip */
  154532. max_rows = out_rows_avail - *out_row_ctr; /* available in output area */
  154533. if (num_rows > max_rows)
  154534. num_rows = max_rows;
  154535. max_rows = cinfo->output_height - post->starting_row;
  154536. if (num_rows > max_rows)
  154537. num_rows = max_rows;
  154538. (*cinfo->cquantize->color_quantize) (cinfo,
  154539. post->buffer + post->next_row, output_buf + *out_row_ctr,
  154540. (int) num_rows);
  154541. *out_row_ctr += num_rows;
  154542. post->next_row += num_rows;
  154543. if (post->next_row >= post->strip_height) {
  154544. post->starting_row += post->strip_height;
  154545. post->next_row = 0;
  154546. }
  154547. }
  154548. #endif /* QUANT_2PASS_SUPPORTED */
  154549. GLOBAL(void)
  154550. jinit_d_post_controller (j_decompress_ptr cinfo, boolean need_full_buffer)
  154551. {
  154552. my_post_ptr post;
  154553. post = (my_post_ptr)
  154554. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  154555. SIZEOF(my_post_controller));
  154556. cinfo->post = (struct jpeg_d_post_controller *) post;
  154557. post->pub.start_pass = start_pass_dpost;
  154558. post->whole_image = NULL; /* flag for no virtual arrays */
  154559. post->buffer = NULL; /* flag for no strip buffer */
  154560. if (cinfo->quantize_colors) {
  154561. post->strip_height = (JDIMENSION) cinfo->max_v_samp_factor;
  154562. if (need_full_buffer) {
  154563. #ifdef QUANT_2PASS_SUPPORTED
  154564. post->whole_image = (*cinfo->mem->request_virt_sarray)
  154565. ((j_common_ptr) cinfo, JPOOL_IMAGE, FALSE,
  154566. cinfo->output_width * cinfo->out_color_components,
  154567. (JDIMENSION) jround_up((long) cinfo->output_height,
  154568. (long) post->strip_height),
  154569. post->strip_height);
  154570. #else
  154571. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  154572. #endif /* QUANT_2PASS_SUPPORTED */
  154573. } else {
  154574. post->buffer = (*cinfo->mem->alloc_sarray)
  154575. ((j_common_ptr) cinfo, JPOOL_IMAGE,
  154576. cinfo->output_width * cinfo->out_color_components,
  154577. post->strip_height);
  154578. }
  154579. }
  154580. }
  154581. /*** End of inlined file: jdpostct.c ***/
  154582. #undef FIX
  154583. /*** Start of inlined file: jdsample.c ***/
  154584. #define JPEG_INTERNALS
  154585. typedef JMETHOD(void, upsample1_ptr,
  154586. (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  154587. JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr));
  154588. typedef struct {
  154589. struct jpeg_upsampler pub; /* public fields */
  154590. JSAMPARRAY color_buf[MAX_COMPONENTS];
  154591. upsample1_ptr methods[MAX_COMPONENTS];
  154592. int next_row_out; /* counts rows emitted from color_buf */
  154593. JDIMENSION rows_to_go; /* counts rows remaining in image */
  154594. int rowgroup_height[MAX_COMPONENTS];
  154595. UINT8 h_expand[MAX_COMPONENTS];
  154596. UINT8 v_expand[MAX_COMPONENTS];
  154597. } my_upsampler2;
  154598. typedef my_upsampler2 * my_upsample_ptr2;
  154599. METHODDEF(void)
  154600. start_pass_upsample (j_decompress_ptr cinfo)
  154601. {
  154602. my_upsample_ptr2 upsample = (my_upsample_ptr2) cinfo->upsample;
  154603. upsample->next_row_out = cinfo->max_v_samp_factor;
  154604. upsample->rows_to_go = cinfo->output_height;
  154605. }
  154606. METHODDEF(void)
  154607. sep_upsample (j_decompress_ptr cinfo,
  154608. JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
  154609. JDIMENSION in_row_groups_avail,
  154610. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  154611. JDIMENSION out_rows_avail)
  154612. {
  154613. my_upsample_ptr2 upsample = (my_upsample_ptr2) cinfo->upsample;
  154614. int ci;
  154615. jpeg_component_info * compptr;
  154616. JDIMENSION num_rows;
  154617. if (upsample->next_row_out >= cinfo->max_v_samp_factor) {
  154618. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  154619. ci++, compptr++) {
  154620. (*upsample->methods[ci]) (cinfo, compptr,
  154621. input_buf[ci] + (*in_row_group_ctr * upsample->rowgroup_height[ci]),
  154622. upsample->color_buf + ci);
  154623. }
  154624. upsample->next_row_out = 0;
  154625. }
  154626. num_rows = (JDIMENSION) (cinfo->max_v_samp_factor - upsample->next_row_out);
  154627. if (num_rows > upsample->rows_to_go)
  154628. num_rows = upsample->rows_to_go;
  154629. out_rows_avail -= *out_row_ctr;
  154630. if (num_rows > out_rows_avail)
  154631. num_rows = out_rows_avail;
  154632. (*cinfo->cconvert->color_convert) (cinfo, upsample->color_buf,
  154633. (JDIMENSION) upsample->next_row_out,
  154634. output_buf + *out_row_ctr,
  154635. (int) num_rows);
  154636. *out_row_ctr += num_rows;
  154637. upsample->rows_to_go -= num_rows;
  154638. upsample->next_row_out += num_rows;
  154639. if (upsample->next_row_out >= cinfo->max_v_samp_factor)
  154640. (*in_row_group_ctr)++;
  154641. }
  154642. METHODDEF(void)
  154643. fullsize_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  154644. JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)
  154645. {
  154646. *output_data_ptr = input_data;
  154647. }
  154648. METHODDEF(void)
  154649. noop_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  154650. JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)
  154651. {
  154652. *output_data_ptr = NULL; /* safety check */
  154653. }
  154654. METHODDEF(void)
  154655. int_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  154656. JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)
  154657. {
  154658. my_upsample_ptr2 upsample = (my_upsample_ptr2) cinfo->upsample;
  154659. JSAMPARRAY output_data = *output_data_ptr;
  154660. register JSAMPROW inptr, outptr;
  154661. register JSAMPLE invalue;
  154662. register int h;
  154663. JSAMPROW outend;
  154664. int h_expand, v_expand;
  154665. int inrow, outrow;
  154666. h_expand = upsample->h_expand[compptr->component_index];
  154667. v_expand = upsample->v_expand[compptr->component_index];
  154668. inrow = outrow = 0;
  154669. while (outrow < cinfo->max_v_samp_factor) {
  154670. inptr = input_data[inrow];
  154671. outptr = output_data[outrow];
  154672. outend = outptr + cinfo->output_width;
  154673. while (outptr < outend) {
  154674. invalue = *inptr++; /* don't need GETJSAMPLE() here */
  154675. for (h = h_expand; h > 0; h--) {
  154676. *outptr++ = invalue;
  154677. }
  154678. }
  154679. if (v_expand > 1) {
  154680. jcopy_sample_rows(output_data, outrow, output_data, outrow+1,
  154681. v_expand-1, cinfo->output_width);
  154682. }
  154683. inrow++;
  154684. outrow += v_expand;
  154685. }
  154686. }
  154687. METHODDEF(void)
  154688. h2v1_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  154689. JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)
  154690. {
  154691. JSAMPARRAY output_data = *output_data_ptr;
  154692. register JSAMPROW inptr, outptr;
  154693. register JSAMPLE invalue;
  154694. JSAMPROW outend;
  154695. int inrow;
  154696. for (inrow = 0; inrow < cinfo->max_v_samp_factor; inrow++) {
  154697. inptr = input_data[inrow];
  154698. outptr = output_data[inrow];
  154699. outend = outptr + cinfo->output_width;
  154700. while (outptr < outend) {
  154701. invalue = *inptr++; /* don't need GETJSAMPLE() here */
  154702. *outptr++ = invalue;
  154703. *outptr++ = invalue;
  154704. }
  154705. }
  154706. }
  154707. METHODDEF(void)
  154708. h2v2_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  154709. JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)
  154710. {
  154711. JSAMPARRAY output_data = *output_data_ptr;
  154712. register JSAMPROW inptr, outptr;
  154713. register JSAMPLE invalue;
  154714. JSAMPROW outend;
  154715. int inrow, outrow;
  154716. inrow = outrow = 0;
  154717. while (outrow < cinfo->max_v_samp_factor) {
  154718. inptr = input_data[inrow];
  154719. outptr = output_data[outrow];
  154720. outend = outptr + cinfo->output_width;
  154721. while (outptr < outend) {
  154722. invalue = *inptr++; /* don't need GETJSAMPLE() here */
  154723. *outptr++ = invalue;
  154724. *outptr++ = invalue;
  154725. }
  154726. jcopy_sample_rows(output_data, outrow, output_data, outrow+1,
  154727. 1, cinfo->output_width);
  154728. inrow++;
  154729. outrow += 2;
  154730. }
  154731. }
  154732. METHODDEF(void)
  154733. h2v1_fancy_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  154734. JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)
  154735. {
  154736. JSAMPARRAY output_data = *output_data_ptr;
  154737. register JSAMPROW inptr, outptr;
  154738. register int invalue;
  154739. register JDIMENSION colctr;
  154740. int inrow;
  154741. for (inrow = 0; inrow < cinfo->max_v_samp_factor; inrow++) {
  154742. inptr = input_data[inrow];
  154743. outptr = output_data[inrow];
  154744. invalue = GETJSAMPLE(*inptr++);
  154745. *outptr++ = (JSAMPLE) invalue;
  154746. *outptr++ = (JSAMPLE) ((invalue * 3 + GETJSAMPLE(*inptr) + 2) >> 2);
  154747. for (colctr = compptr->downsampled_width - 2; colctr > 0; colctr--) {
  154748. invalue = GETJSAMPLE(*inptr++) * 3;
  154749. *outptr++ = (JSAMPLE) ((invalue + GETJSAMPLE(inptr[-2]) + 1) >> 2);
  154750. *outptr++ = (JSAMPLE) ((invalue + GETJSAMPLE(*inptr) + 2) >> 2);
  154751. }
  154752. invalue = GETJSAMPLE(*inptr);
  154753. *outptr++ = (JSAMPLE) ((invalue * 3 + GETJSAMPLE(inptr[-1]) + 1) >> 2);
  154754. *outptr++ = (JSAMPLE) invalue;
  154755. }
  154756. }
  154757. METHODDEF(void)
  154758. h2v2_fancy_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  154759. JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)
  154760. {
  154761. JSAMPARRAY output_data = *output_data_ptr;
  154762. register JSAMPROW inptr0, inptr1, outptr;
  154763. #if BITS_IN_JSAMPLE == 8
  154764. register int thiscolsum, lastcolsum, nextcolsum;
  154765. #else
  154766. register INT32 thiscolsum, lastcolsum, nextcolsum;
  154767. #endif
  154768. register JDIMENSION colctr;
  154769. int inrow, outrow, v;
  154770. inrow = outrow = 0;
  154771. while (outrow < cinfo->max_v_samp_factor) {
  154772. for (v = 0; v < 2; v++) {
  154773. inptr0 = input_data[inrow];
  154774. if (v == 0) /* next nearest is row above */
  154775. inptr1 = input_data[inrow-1];
  154776. else /* next nearest is row below */
  154777. inptr1 = input_data[inrow+1];
  154778. outptr = output_data[outrow++];
  154779. thiscolsum = GETJSAMPLE(*inptr0++) * 3 + GETJSAMPLE(*inptr1++);
  154780. nextcolsum = GETJSAMPLE(*inptr0++) * 3 + GETJSAMPLE(*inptr1++);
  154781. *outptr++ = (JSAMPLE) ((thiscolsum * 4 + 8) >> 4);
  154782. *outptr++ = (JSAMPLE) ((thiscolsum * 3 + nextcolsum + 7) >> 4);
  154783. lastcolsum = thiscolsum; thiscolsum = nextcolsum;
  154784. for (colctr = compptr->downsampled_width - 2; colctr > 0; colctr--) {
  154785. nextcolsum = GETJSAMPLE(*inptr0++) * 3 + GETJSAMPLE(*inptr1++);
  154786. *outptr++ = (JSAMPLE) ((thiscolsum * 3 + lastcolsum + 8) >> 4);
  154787. *outptr++ = (JSAMPLE) ((thiscolsum * 3 + nextcolsum + 7) >> 4);
  154788. lastcolsum = thiscolsum; thiscolsum = nextcolsum;
  154789. }
  154790. *outptr++ = (JSAMPLE) ((thiscolsum * 3 + lastcolsum + 8) >> 4);
  154791. *outptr++ = (JSAMPLE) ((thiscolsum * 4 + 7) >> 4);
  154792. }
  154793. inrow++;
  154794. }
  154795. }
  154796. GLOBAL(void)
  154797. jinit_upsampler (j_decompress_ptr cinfo)
  154798. {
  154799. my_upsample_ptr2 upsample;
  154800. int ci;
  154801. jpeg_component_info * compptr;
  154802. boolean need_buffer, do_fancy;
  154803. int h_in_group, v_in_group, h_out_group, v_out_group;
  154804. upsample = (my_upsample_ptr2)
  154805. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  154806. SIZEOF(my_upsampler2));
  154807. cinfo->upsample = (struct jpeg_upsampler *) upsample;
  154808. upsample->pub.start_pass = start_pass_upsample;
  154809. upsample->pub.upsample = sep_upsample;
  154810. upsample->pub.need_context_rows = FALSE; /* until we find out differently */
  154811. if (cinfo->CCIR601_sampling) /* this isn't supported */
  154812. ERREXIT(cinfo, JERR_CCIR601_NOTIMPL);
  154813. do_fancy = cinfo->do_fancy_upsampling && cinfo->min_DCT_scaled_size > 1;
  154814. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  154815. ci++, compptr++) {
  154816. h_in_group = (compptr->h_samp_factor * compptr->DCT_scaled_size) /
  154817. cinfo->min_DCT_scaled_size;
  154818. v_in_group = (compptr->v_samp_factor * compptr->DCT_scaled_size) /
  154819. cinfo->min_DCT_scaled_size;
  154820. h_out_group = cinfo->max_h_samp_factor;
  154821. v_out_group = cinfo->max_v_samp_factor;
  154822. upsample->rowgroup_height[ci] = v_in_group; /* save for use later */
  154823. need_buffer = TRUE;
  154824. if (! compptr->component_needed) {
  154825. upsample->methods[ci] = noop_upsample;
  154826. need_buffer = FALSE;
  154827. } else if (h_in_group == h_out_group && v_in_group == v_out_group) {
  154828. upsample->methods[ci] = fullsize_upsample;
  154829. need_buffer = FALSE;
  154830. } else if (h_in_group * 2 == h_out_group &&
  154831. v_in_group == v_out_group) {
  154832. if (do_fancy && compptr->downsampled_width > 2)
  154833. upsample->methods[ci] = h2v1_fancy_upsample;
  154834. else
  154835. upsample->methods[ci] = h2v1_upsample;
  154836. } else if (h_in_group * 2 == h_out_group &&
  154837. v_in_group * 2 == v_out_group) {
  154838. if (do_fancy && compptr->downsampled_width > 2) {
  154839. upsample->methods[ci] = h2v2_fancy_upsample;
  154840. upsample->pub.need_context_rows = TRUE;
  154841. } else
  154842. upsample->methods[ci] = h2v2_upsample;
  154843. } else if ((h_out_group % h_in_group) == 0 &&
  154844. (v_out_group % v_in_group) == 0) {
  154845. upsample->methods[ci] = int_upsample;
  154846. upsample->h_expand[ci] = (UINT8) (h_out_group / h_in_group);
  154847. upsample->v_expand[ci] = (UINT8) (v_out_group / v_in_group);
  154848. } else
  154849. ERREXIT(cinfo, JERR_FRACT_SAMPLE_NOTIMPL);
  154850. if (need_buffer) {
  154851. upsample->color_buf[ci] = (*cinfo->mem->alloc_sarray)
  154852. ((j_common_ptr) cinfo, JPOOL_IMAGE,
  154853. (JDIMENSION) jround_up((long) cinfo->output_width,
  154854. (long) cinfo->max_h_samp_factor),
  154855. (JDIMENSION) cinfo->max_v_samp_factor);
  154856. }
  154857. }
  154858. }
  154859. /*** End of inlined file: jdsample.c ***/
  154860. /*** Start of inlined file: jdtrans.c ***/
  154861. #define JPEG_INTERNALS
  154862. LOCAL(void) transdecode_master_selection JPP((j_decompress_ptr cinfo));
  154863. GLOBAL(jvirt_barray_ptr *)
  154864. jpeg_read_coefficients (j_decompress_ptr cinfo)
  154865. {
  154866. if (cinfo->global_state == DSTATE_READY) {
  154867. transdecode_master_selection(cinfo);
  154868. cinfo->global_state = DSTATE_RDCOEFS;
  154869. }
  154870. if (cinfo->global_state == DSTATE_RDCOEFS) {
  154871. for (;;) {
  154872. int retcode;
  154873. if (cinfo->progress != NULL)
  154874. (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
  154875. retcode = (*cinfo->inputctl->consume_input) (cinfo);
  154876. if (retcode == JPEG_SUSPENDED)
  154877. return NULL;
  154878. if (retcode == JPEG_REACHED_EOI)
  154879. break;
  154880. if (cinfo->progress != NULL &&
  154881. (retcode == JPEG_ROW_COMPLETED || retcode == JPEG_REACHED_SOS)) {
  154882. if (++cinfo->progress->pass_counter >= cinfo->progress->pass_limit) {
  154883. cinfo->progress->pass_limit += (long) cinfo->total_iMCU_rows;
  154884. }
  154885. }
  154886. }
  154887. cinfo->global_state = DSTATE_STOPPING;
  154888. }
  154889. if ((cinfo->global_state == DSTATE_STOPPING ||
  154890. cinfo->global_state == DSTATE_BUFIMAGE) && cinfo->buffered_image) {
  154891. return cinfo->coef->coef_arrays;
  154892. }
  154893. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  154894. return NULL; /* keep compiler happy */
  154895. }
  154896. LOCAL(void)
  154897. transdecode_master_selection (j_decompress_ptr cinfo)
  154898. {
  154899. cinfo->buffered_image = TRUE;
  154900. if (cinfo->arith_code) {
  154901. ERREXIT(cinfo, JERR_ARITH_NOTIMPL);
  154902. } else {
  154903. if (cinfo->progressive_mode) {
  154904. #ifdef D_PROGRESSIVE_SUPPORTED
  154905. jinit_phuff_decoder(cinfo);
  154906. #else
  154907. ERREXIT(cinfo, JERR_NOT_COMPILED);
  154908. #endif
  154909. } else
  154910. jinit_huff_decoder(cinfo);
  154911. }
  154912. jinit_d_coef_controller(cinfo, TRUE);
  154913. (*cinfo->mem->realize_virt_arrays) ((j_common_ptr) cinfo);
  154914. (*cinfo->inputctl->start_input_pass) (cinfo);
  154915. if (cinfo->progress != NULL) {
  154916. int nscans;
  154917. if (cinfo->progressive_mode) {
  154918. nscans = 2 + 3 * cinfo->num_components;
  154919. } else if (cinfo->inputctl->has_multiple_scans) {
  154920. nscans = cinfo->num_components;
  154921. } else {
  154922. nscans = 1;
  154923. }
  154924. cinfo->progress->pass_counter = 0L;
  154925. cinfo->progress->pass_limit = (long) cinfo->total_iMCU_rows * nscans;
  154926. cinfo->progress->completed_passes = 0;
  154927. cinfo->progress->total_passes = 1;
  154928. }
  154929. }
  154930. /*** End of inlined file: jdtrans.c ***/
  154931. /*** Start of inlined file: jfdctflt.c ***/
  154932. #define JPEG_INTERNALS
  154933. #ifdef DCT_FLOAT_SUPPORTED
  154934. #if DCTSIZE != 8
  154935. Sorry, this code only copes with 8x8 DCTs. /* deliberate syntax err */
  154936. #endif
  154937. GLOBAL(void)
  154938. jpeg_fdct_float (FAST_FLOAT * data)
  154939. {
  154940. FAST_FLOAT tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
  154941. FAST_FLOAT tmp10, tmp11, tmp12, tmp13;
  154942. FAST_FLOAT z1, z2, z3, z4, z5, z11, z13;
  154943. FAST_FLOAT *dataptr;
  154944. int ctr;
  154945. dataptr = data;
  154946. for (ctr = DCTSIZE-1; ctr >= 0; ctr--) {
  154947. tmp0 = dataptr[0] + dataptr[7];
  154948. tmp7 = dataptr[0] - dataptr[7];
  154949. tmp1 = dataptr[1] + dataptr[6];
  154950. tmp6 = dataptr[1] - dataptr[6];
  154951. tmp2 = dataptr[2] + dataptr[5];
  154952. tmp5 = dataptr[2] - dataptr[5];
  154953. tmp3 = dataptr[3] + dataptr[4];
  154954. tmp4 = dataptr[3] - dataptr[4];
  154955. tmp10 = tmp0 + tmp3; /* phase 2 */
  154956. tmp13 = tmp0 - tmp3;
  154957. tmp11 = tmp1 + tmp2;
  154958. tmp12 = tmp1 - tmp2;
  154959. dataptr[0] = tmp10 + tmp11; /* phase 3 */
  154960. dataptr[4] = tmp10 - tmp11;
  154961. z1 = (tmp12 + tmp13) * ((FAST_FLOAT) 0.707106781); /* c4 */
  154962. dataptr[2] = tmp13 + z1; /* phase 5 */
  154963. dataptr[6] = tmp13 - z1;
  154964. tmp10 = tmp4 + tmp5; /* phase 2 */
  154965. tmp11 = tmp5 + tmp6;
  154966. tmp12 = tmp6 + tmp7;
  154967. z5 = (tmp10 - tmp12) * ((FAST_FLOAT) 0.382683433); /* c6 */
  154968. z2 = ((FAST_FLOAT) 0.541196100) * tmp10 + z5; /* c2-c6 */
  154969. z4 = ((FAST_FLOAT) 1.306562965) * tmp12 + z5; /* c2+c6 */
  154970. z3 = tmp11 * ((FAST_FLOAT) 0.707106781); /* c4 */
  154971. z11 = tmp7 + z3; /* phase 5 */
  154972. z13 = tmp7 - z3;
  154973. dataptr[5] = z13 + z2; /* phase 6 */
  154974. dataptr[3] = z13 - z2;
  154975. dataptr[1] = z11 + z4;
  154976. dataptr[7] = z11 - z4;
  154977. dataptr += DCTSIZE; /* advance pointer to next row */
  154978. }
  154979. dataptr = data;
  154980. for (ctr = DCTSIZE-1; ctr >= 0; ctr--) {
  154981. tmp0 = dataptr[DCTSIZE*0] + dataptr[DCTSIZE*7];
  154982. tmp7 = dataptr[DCTSIZE*0] - dataptr[DCTSIZE*7];
  154983. tmp1 = dataptr[DCTSIZE*1] + dataptr[DCTSIZE*6];
  154984. tmp6 = dataptr[DCTSIZE*1] - dataptr[DCTSIZE*6];
  154985. tmp2 = dataptr[DCTSIZE*2] + dataptr[DCTSIZE*5];
  154986. tmp5 = dataptr[DCTSIZE*2] - dataptr[DCTSIZE*5];
  154987. tmp3 = dataptr[DCTSIZE*3] + dataptr[DCTSIZE*4];
  154988. tmp4 = dataptr[DCTSIZE*3] - dataptr[DCTSIZE*4];
  154989. tmp10 = tmp0 + tmp3; /* phase 2 */
  154990. tmp13 = tmp0 - tmp3;
  154991. tmp11 = tmp1 + tmp2;
  154992. tmp12 = tmp1 - tmp2;
  154993. dataptr[DCTSIZE*0] = tmp10 + tmp11; /* phase 3 */
  154994. dataptr[DCTSIZE*4] = tmp10 - tmp11;
  154995. z1 = (tmp12 + tmp13) * ((FAST_FLOAT) 0.707106781); /* c4 */
  154996. dataptr[DCTSIZE*2] = tmp13 + z1; /* phase 5 */
  154997. dataptr[DCTSIZE*6] = tmp13 - z1;
  154998. tmp10 = tmp4 + tmp5; /* phase 2 */
  154999. tmp11 = tmp5 + tmp6;
  155000. tmp12 = tmp6 + tmp7;
  155001. z5 = (tmp10 - tmp12) * ((FAST_FLOAT) 0.382683433); /* c6 */
  155002. z2 = ((FAST_FLOAT) 0.541196100) * tmp10 + z5; /* c2-c6 */
  155003. z4 = ((FAST_FLOAT) 1.306562965) * tmp12 + z5; /* c2+c6 */
  155004. z3 = tmp11 * ((FAST_FLOAT) 0.707106781); /* c4 */
  155005. z11 = tmp7 + z3; /* phase 5 */
  155006. z13 = tmp7 - z3;
  155007. dataptr[DCTSIZE*5] = z13 + z2; /* phase 6 */
  155008. dataptr[DCTSIZE*3] = z13 - z2;
  155009. dataptr[DCTSIZE*1] = z11 + z4;
  155010. dataptr[DCTSIZE*7] = z11 - z4;
  155011. dataptr++; /* advance pointer to next column */
  155012. }
  155013. }
  155014. #endif /* DCT_FLOAT_SUPPORTED */
  155015. /*** End of inlined file: jfdctflt.c ***/
  155016. /*** Start of inlined file: jfdctint.c ***/
  155017. #define JPEG_INTERNALS
  155018. #ifdef DCT_ISLOW_SUPPORTED
  155019. #if DCTSIZE != 8
  155020. Sorry, this code only copes with 8x8 DCTs. /* deliberate syntax err */
  155021. #endif
  155022. #if BITS_IN_JSAMPLE == 8
  155023. #define CONST_BITS 13
  155024. #define PASS1_BITS 2
  155025. #else
  155026. #define CONST_BITS 13
  155027. #define PASS1_BITS 1 /* lose a little precision to avoid overflow */
  155028. #endif
  155029. #if CONST_BITS == 13
  155030. #define FIX_0_298631336 ((INT32) 2446) /* FIX(0.298631336) */
  155031. #define FIX_0_390180644 ((INT32) 3196) /* FIX(0.390180644) */
  155032. #define FIX_0_541196100 ((INT32) 4433) /* FIX(0.541196100) */
  155033. #define FIX_0_765366865 ((INT32) 6270) /* FIX(0.765366865) */
  155034. #define FIX_0_899976223 ((INT32) 7373) /* FIX(0.899976223) */
  155035. #define FIX_1_175875602 ((INT32) 9633) /* FIX(1.175875602) */
  155036. #define FIX_1_501321110 ((INT32) 12299) /* FIX(1.501321110) */
  155037. #define FIX_1_847759065 ((INT32) 15137) /* FIX(1.847759065) */
  155038. #define FIX_1_961570560 ((INT32) 16069) /* FIX(1.961570560) */
  155039. #define FIX_2_053119869 ((INT32) 16819) /* FIX(2.053119869) */
  155040. #define FIX_2_562915447 ((INT32) 20995) /* FIX(2.562915447) */
  155041. #define FIX_3_072711026 ((INT32) 25172) /* FIX(3.072711026) */
  155042. #else
  155043. #define FIX_0_298631336 FIX(0.298631336)
  155044. #define FIX_0_390180644 FIX(0.390180644)
  155045. #define FIX_0_541196100 FIX(0.541196100)
  155046. #define FIX_0_765366865 FIX(0.765366865)
  155047. #define FIX_0_899976223 FIX(0.899976223)
  155048. #define FIX_1_175875602 FIX(1.175875602)
  155049. #define FIX_1_501321110 FIX(1.501321110)
  155050. #define FIX_1_847759065 FIX(1.847759065)
  155051. #define FIX_1_961570560 FIX(1.961570560)
  155052. #define FIX_2_053119869 FIX(2.053119869)
  155053. #define FIX_2_562915447 FIX(2.562915447)
  155054. #define FIX_3_072711026 FIX(3.072711026)
  155055. #endif
  155056. #if BITS_IN_JSAMPLE == 8
  155057. #define MULTIPLY(var,const) MULTIPLY16C16(var,const)
  155058. #else
  155059. #define MULTIPLY(var,const) ((var) * (const))
  155060. #endif
  155061. GLOBAL(void)
  155062. jpeg_fdct_islow (DCTELEM * data)
  155063. {
  155064. INT32 tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
  155065. INT32 tmp10, tmp11, tmp12, tmp13;
  155066. INT32 z1, z2, z3, z4, z5;
  155067. DCTELEM *dataptr;
  155068. int ctr;
  155069. SHIFT_TEMPS
  155070. dataptr = data;
  155071. for (ctr = DCTSIZE-1; ctr >= 0; ctr--) {
  155072. tmp0 = dataptr[0] + dataptr[7];
  155073. tmp7 = dataptr[0] - dataptr[7];
  155074. tmp1 = dataptr[1] + dataptr[6];
  155075. tmp6 = dataptr[1] - dataptr[6];
  155076. tmp2 = dataptr[2] + dataptr[5];
  155077. tmp5 = dataptr[2] - dataptr[5];
  155078. tmp3 = dataptr[3] + dataptr[4];
  155079. tmp4 = dataptr[3] - dataptr[4];
  155080. tmp10 = tmp0 + tmp3;
  155081. tmp13 = tmp0 - tmp3;
  155082. tmp11 = tmp1 + tmp2;
  155083. tmp12 = tmp1 - tmp2;
  155084. dataptr[0] = (DCTELEM) ((tmp10 + tmp11) << PASS1_BITS);
  155085. dataptr[4] = (DCTELEM) ((tmp10 - tmp11) << PASS1_BITS);
  155086. z1 = MULTIPLY(tmp12 + tmp13, FIX_0_541196100);
  155087. dataptr[2] = (DCTELEM) DESCALE(z1 + MULTIPLY(tmp13, FIX_0_765366865),
  155088. CONST_BITS-PASS1_BITS);
  155089. dataptr[6] = (DCTELEM) DESCALE(z1 + MULTIPLY(tmp12, - FIX_1_847759065),
  155090. CONST_BITS-PASS1_BITS);
  155091. z1 = tmp4 + tmp7;
  155092. z2 = tmp5 + tmp6;
  155093. z3 = tmp4 + tmp6;
  155094. z4 = tmp5 + tmp7;
  155095. z5 = MULTIPLY(z3 + z4, FIX_1_175875602); /* sqrt(2) * c3 */
  155096. tmp4 = MULTIPLY(tmp4, FIX_0_298631336); /* sqrt(2) * (-c1+c3+c5-c7) */
  155097. tmp5 = MULTIPLY(tmp5, FIX_2_053119869); /* sqrt(2) * ( c1+c3-c5+c7) */
  155098. tmp6 = MULTIPLY(tmp6, FIX_3_072711026); /* sqrt(2) * ( c1+c3+c5-c7) */
  155099. tmp7 = MULTIPLY(tmp7, FIX_1_501321110); /* sqrt(2) * ( c1+c3-c5-c7) */
  155100. z1 = MULTIPLY(z1, - FIX_0_899976223); /* sqrt(2) * (c7-c3) */
  155101. z2 = MULTIPLY(z2, - FIX_2_562915447); /* sqrt(2) * (-c1-c3) */
  155102. z3 = MULTIPLY(z3, - FIX_1_961570560); /* sqrt(2) * (-c3-c5) */
  155103. z4 = MULTIPLY(z4, - FIX_0_390180644); /* sqrt(2) * (c5-c3) */
  155104. z3 += z5;
  155105. z4 += z5;
  155106. dataptr[7] = (DCTELEM) DESCALE(tmp4 + z1 + z3, CONST_BITS-PASS1_BITS);
  155107. dataptr[5] = (DCTELEM) DESCALE(tmp5 + z2 + z4, CONST_BITS-PASS1_BITS);
  155108. dataptr[3] = (DCTELEM) DESCALE(tmp6 + z2 + z3, CONST_BITS-PASS1_BITS);
  155109. dataptr[1] = (DCTELEM) DESCALE(tmp7 + z1 + z4, CONST_BITS-PASS1_BITS);
  155110. dataptr += DCTSIZE; /* advance pointer to next row */
  155111. }
  155112. dataptr = data;
  155113. for (ctr = DCTSIZE-1; ctr >= 0; ctr--) {
  155114. tmp0 = dataptr[DCTSIZE*0] + dataptr[DCTSIZE*7];
  155115. tmp7 = dataptr[DCTSIZE*0] - dataptr[DCTSIZE*7];
  155116. tmp1 = dataptr[DCTSIZE*1] + dataptr[DCTSIZE*6];
  155117. tmp6 = dataptr[DCTSIZE*1] - dataptr[DCTSIZE*6];
  155118. tmp2 = dataptr[DCTSIZE*2] + dataptr[DCTSIZE*5];
  155119. tmp5 = dataptr[DCTSIZE*2] - dataptr[DCTSIZE*5];
  155120. tmp3 = dataptr[DCTSIZE*3] + dataptr[DCTSIZE*4];
  155121. tmp4 = dataptr[DCTSIZE*3] - dataptr[DCTSIZE*4];
  155122. tmp10 = tmp0 + tmp3;
  155123. tmp13 = tmp0 - tmp3;
  155124. tmp11 = tmp1 + tmp2;
  155125. tmp12 = tmp1 - tmp2;
  155126. dataptr[DCTSIZE*0] = (DCTELEM) DESCALE(tmp10 + tmp11, PASS1_BITS);
  155127. dataptr[DCTSIZE*4] = (DCTELEM) DESCALE(tmp10 - tmp11, PASS1_BITS);
  155128. z1 = MULTIPLY(tmp12 + tmp13, FIX_0_541196100);
  155129. dataptr[DCTSIZE*2] = (DCTELEM) DESCALE(z1 + MULTIPLY(tmp13, FIX_0_765366865),
  155130. CONST_BITS+PASS1_BITS);
  155131. dataptr[DCTSIZE*6] = (DCTELEM) DESCALE(z1 + MULTIPLY(tmp12, - FIX_1_847759065),
  155132. CONST_BITS+PASS1_BITS);
  155133. z1 = tmp4 + tmp7;
  155134. z2 = tmp5 + tmp6;
  155135. z3 = tmp4 + tmp6;
  155136. z4 = tmp5 + tmp7;
  155137. z5 = MULTIPLY(z3 + z4, FIX_1_175875602); /* sqrt(2) * c3 */
  155138. tmp4 = MULTIPLY(tmp4, FIX_0_298631336); /* sqrt(2) * (-c1+c3+c5-c7) */
  155139. tmp5 = MULTIPLY(tmp5, FIX_2_053119869); /* sqrt(2) * ( c1+c3-c5+c7) */
  155140. tmp6 = MULTIPLY(tmp6, FIX_3_072711026); /* sqrt(2) * ( c1+c3+c5-c7) */
  155141. tmp7 = MULTIPLY(tmp7, FIX_1_501321110); /* sqrt(2) * ( c1+c3-c5-c7) */
  155142. z1 = MULTIPLY(z1, - FIX_0_899976223); /* sqrt(2) * (c7-c3) */
  155143. z2 = MULTIPLY(z2, - FIX_2_562915447); /* sqrt(2) * (-c1-c3) */
  155144. z3 = MULTIPLY(z3, - FIX_1_961570560); /* sqrt(2) * (-c3-c5) */
  155145. z4 = MULTIPLY(z4, - FIX_0_390180644); /* sqrt(2) * (c5-c3) */
  155146. z3 += z5;
  155147. z4 += z5;
  155148. dataptr[DCTSIZE*7] = (DCTELEM) DESCALE(tmp4 + z1 + z3,
  155149. CONST_BITS+PASS1_BITS);
  155150. dataptr[DCTSIZE*5] = (DCTELEM) DESCALE(tmp5 + z2 + z4,
  155151. CONST_BITS+PASS1_BITS);
  155152. dataptr[DCTSIZE*3] = (DCTELEM) DESCALE(tmp6 + z2 + z3,
  155153. CONST_BITS+PASS1_BITS);
  155154. dataptr[DCTSIZE*1] = (DCTELEM) DESCALE(tmp7 + z1 + z4,
  155155. CONST_BITS+PASS1_BITS);
  155156. dataptr++; /* advance pointer to next column */
  155157. }
  155158. }
  155159. #endif /* DCT_ISLOW_SUPPORTED */
  155160. /*** End of inlined file: jfdctint.c ***/
  155161. #undef CONST_BITS
  155162. #undef MULTIPLY
  155163. #undef FIX_0_541196100
  155164. /*** Start of inlined file: jfdctfst.c ***/
  155165. #define JPEG_INTERNALS
  155166. #ifdef DCT_IFAST_SUPPORTED
  155167. #if DCTSIZE != 8
  155168. Sorry, this code only copes with 8x8 DCTs. /* deliberate syntax err */
  155169. #endif
  155170. #define CONST_BITS 8
  155171. #if CONST_BITS == 8
  155172. #define FIX_0_382683433 ((INT32) 98) /* FIX(0.382683433) */
  155173. #define FIX_0_541196100 ((INT32) 139) /* FIX(0.541196100) */
  155174. #define FIX_0_707106781 ((INT32) 181) /* FIX(0.707106781) */
  155175. #define FIX_1_306562965 ((INT32) 334) /* FIX(1.306562965) */
  155176. #else
  155177. #define FIX_0_382683433 FIX(0.382683433)
  155178. #define FIX_0_541196100 FIX(0.541196100)
  155179. #define FIX_0_707106781 FIX(0.707106781)
  155180. #define FIX_1_306562965 FIX(1.306562965)
  155181. #endif
  155182. #ifndef USE_ACCURATE_ROUNDING
  155183. #undef DESCALE
  155184. #define DESCALE(x,n) RIGHT_SHIFT(x, n)
  155185. #endif
  155186. #define MULTIPLY(var,const) ((DCTELEM) DESCALE((var) * (const), CONST_BITS))
  155187. GLOBAL(void)
  155188. jpeg_fdct_ifast (DCTELEM * data)
  155189. {
  155190. DCTELEM tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
  155191. DCTELEM tmp10, tmp11, tmp12, tmp13;
  155192. DCTELEM z1, z2, z3, z4, z5, z11, z13;
  155193. DCTELEM *dataptr;
  155194. int ctr;
  155195. SHIFT_TEMPS
  155196. dataptr = data;
  155197. for (ctr = DCTSIZE-1; ctr >= 0; ctr--) {
  155198. tmp0 = dataptr[0] + dataptr[7];
  155199. tmp7 = dataptr[0] - dataptr[7];
  155200. tmp1 = dataptr[1] + dataptr[6];
  155201. tmp6 = dataptr[1] - dataptr[6];
  155202. tmp2 = dataptr[2] + dataptr[5];
  155203. tmp5 = dataptr[2] - dataptr[5];
  155204. tmp3 = dataptr[3] + dataptr[4];
  155205. tmp4 = dataptr[3] - dataptr[4];
  155206. tmp10 = tmp0 + tmp3; /* phase 2 */
  155207. tmp13 = tmp0 - tmp3;
  155208. tmp11 = tmp1 + tmp2;
  155209. tmp12 = tmp1 - tmp2;
  155210. dataptr[0] = tmp10 + tmp11; /* phase 3 */
  155211. dataptr[4] = tmp10 - tmp11;
  155212. z1 = MULTIPLY(tmp12 + tmp13, FIX_0_707106781); /* c4 */
  155213. dataptr[2] = tmp13 + z1; /* phase 5 */
  155214. dataptr[6] = tmp13 - z1;
  155215. tmp10 = tmp4 + tmp5; /* phase 2 */
  155216. tmp11 = tmp5 + tmp6;
  155217. tmp12 = tmp6 + tmp7;
  155218. z5 = MULTIPLY(tmp10 - tmp12, FIX_0_382683433); /* c6 */
  155219. z2 = MULTIPLY(tmp10, FIX_0_541196100) + z5; /* c2-c6 */
  155220. z4 = MULTIPLY(tmp12, FIX_1_306562965) + z5; /* c2+c6 */
  155221. z3 = MULTIPLY(tmp11, FIX_0_707106781); /* c4 */
  155222. z11 = tmp7 + z3; /* phase 5 */
  155223. z13 = tmp7 - z3;
  155224. dataptr[5] = z13 + z2; /* phase 6 */
  155225. dataptr[3] = z13 - z2;
  155226. dataptr[1] = z11 + z4;
  155227. dataptr[7] = z11 - z4;
  155228. dataptr += DCTSIZE; /* advance pointer to next row */
  155229. }
  155230. dataptr = data;
  155231. for (ctr = DCTSIZE-1; ctr >= 0; ctr--) {
  155232. tmp0 = dataptr[DCTSIZE*0] + dataptr[DCTSIZE*7];
  155233. tmp7 = dataptr[DCTSIZE*0] - dataptr[DCTSIZE*7];
  155234. tmp1 = dataptr[DCTSIZE*1] + dataptr[DCTSIZE*6];
  155235. tmp6 = dataptr[DCTSIZE*1] - dataptr[DCTSIZE*6];
  155236. tmp2 = dataptr[DCTSIZE*2] + dataptr[DCTSIZE*5];
  155237. tmp5 = dataptr[DCTSIZE*2] - dataptr[DCTSIZE*5];
  155238. tmp3 = dataptr[DCTSIZE*3] + dataptr[DCTSIZE*4];
  155239. tmp4 = dataptr[DCTSIZE*3] - dataptr[DCTSIZE*4];
  155240. tmp10 = tmp0 + tmp3; /* phase 2 */
  155241. tmp13 = tmp0 - tmp3;
  155242. tmp11 = tmp1 + tmp2;
  155243. tmp12 = tmp1 - tmp2;
  155244. dataptr[DCTSIZE*0] = tmp10 + tmp11; /* phase 3 */
  155245. dataptr[DCTSIZE*4] = tmp10 - tmp11;
  155246. z1 = MULTIPLY(tmp12 + tmp13, FIX_0_707106781); /* c4 */
  155247. dataptr[DCTSIZE*2] = tmp13 + z1; /* phase 5 */
  155248. dataptr[DCTSIZE*6] = tmp13 - z1;
  155249. tmp10 = tmp4 + tmp5; /* phase 2 */
  155250. tmp11 = tmp5 + tmp6;
  155251. tmp12 = tmp6 + tmp7;
  155252. z5 = MULTIPLY(tmp10 - tmp12, FIX_0_382683433); /* c6 */
  155253. z2 = MULTIPLY(tmp10, FIX_0_541196100) + z5; /* c2-c6 */
  155254. z4 = MULTIPLY(tmp12, FIX_1_306562965) + z5; /* c2+c6 */
  155255. z3 = MULTIPLY(tmp11, FIX_0_707106781); /* c4 */
  155256. z11 = tmp7 + z3; /* phase 5 */
  155257. z13 = tmp7 - z3;
  155258. dataptr[DCTSIZE*5] = z13 + z2; /* phase 6 */
  155259. dataptr[DCTSIZE*3] = z13 - z2;
  155260. dataptr[DCTSIZE*1] = z11 + z4;
  155261. dataptr[DCTSIZE*7] = z11 - z4;
  155262. dataptr++; /* advance pointer to next column */
  155263. }
  155264. }
  155265. #endif /* DCT_IFAST_SUPPORTED */
  155266. /*** End of inlined file: jfdctfst.c ***/
  155267. #undef FIX_0_541196100
  155268. /*** Start of inlined file: jidctflt.c ***/
  155269. #define JPEG_INTERNALS
  155270. #ifdef DCT_FLOAT_SUPPORTED
  155271. #if DCTSIZE != 8
  155272. Sorry, this code only copes with 8x8 DCTs. /* deliberate syntax err */
  155273. #endif
  155274. #define DEQUANTIZE(coef,quantval) (((FAST_FLOAT) (coef)) * (quantval))
  155275. GLOBAL(void)
  155276. jpeg_idct_float (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  155277. JCOEFPTR coef_block,
  155278. JSAMPARRAY output_buf, JDIMENSION output_col)
  155279. {
  155280. FAST_FLOAT tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
  155281. FAST_FLOAT tmp10, tmp11, tmp12, tmp13;
  155282. FAST_FLOAT z5, z10, z11, z12, z13;
  155283. JCOEFPTR inptr;
  155284. FLOAT_MULT_TYPE * quantptr;
  155285. FAST_FLOAT * wsptr;
  155286. JSAMPROW outptr;
  155287. JSAMPLE *range_limit = IDCT_range_limit(cinfo);
  155288. int ctr;
  155289. FAST_FLOAT workspace[DCTSIZE2]; /* buffers data between passes */
  155290. SHIFT_TEMPS
  155291. inptr = coef_block;
  155292. quantptr = (FLOAT_MULT_TYPE *) compptr->dct_table;
  155293. wsptr = workspace;
  155294. for (ctr = DCTSIZE; ctr > 0; ctr--) {
  155295. if (inptr[DCTSIZE*1] == 0 && inptr[DCTSIZE*2] == 0 &&
  155296. inptr[DCTSIZE*3] == 0 && inptr[DCTSIZE*4] == 0 &&
  155297. inptr[DCTSIZE*5] == 0 && inptr[DCTSIZE*6] == 0 &&
  155298. inptr[DCTSIZE*7] == 0) {
  155299. FAST_FLOAT dcval = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
  155300. wsptr[DCTSIZE*0] = dcval;
  155301. wsptr[DCTSIZE*1] = dcval;
  155302. wsptr[DCTSIZE*2] = dcval;
  155303. wsptr[DCTSIZE*3] = dcval;
  155304. wsptr[DCTSIZE*4] = dcval;
  155305. wsptr[DCTSIZE*5] = dcval;
  155306. wsptr[DCTSIZE*6] = dcval;
  155307. wsptr[DCTSIZE*7] = dcval;
  155308. inptr++; /* advance pointers to next column */
  155309. quantptr++;
  155310. wsptr++;
  155311. continue;
  155312. }
  155313. tmp0 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
  155314. tmp1 = DEQUANTIZE(inptr[DCTSIZE*2], quantptr[DCTSIZE*2]);
  155315. tmp2 = DEQUANTIZE(inptr[DCTSIZE*4], quantptr[DCTSIZE*4]);
  155316. tmp3 = DEQUANTIZE(inptr[DCTSIZE*6], quantptr[DCTSIZE*6]);
  155317. tmp10 = tmp0 + tmp2; /* phase 3 */
  155318. tmp11 = tmp0 - tmp2;
  155319. tmp13 = tmp1 + tmp3; /* phases 5-3 */
  155320. tmp12 = (tmp1 - tmp3) * ((FAST_FLOAT) 1.414213562) - tmp13; /* 2*c4 */
  155321. tmp0 = tmp10 + tmp13; /* phase 2 */
  155322. tmp3 = tmp10 - tmp13;
  155323. tmp1 = tmp11 + tmp12;
  155324. tmp2 = tmp11 - tmp12;
  155325. tmp4 = DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1]);
  155326. tmp5 = DEQUANTIZE(inptr[DCTSIZE*3], quantptr[DCTSIZE*3]);
  155327. tmp6 = DEQUANTIZE(inptr[DCTSIZE*5], quantptr[DCTSIZE*5]);
  155328. tmp7 = DEQUANTIZE(inptr[DCTSIZE*7], quantptr[DCTSIZE*7]);
  155329. z13 = tmp6 + tmp5; /* phase 6 */
  155330. z10 = tmp6 - tmp5;
  155331. z11 = tmp4 + tmp7;
  155332. z12 = tmp4 - tmp7;
  155333. tmp7 = z11 + z13; /* phase 5 */
  155334. tmp11 = (z11 - z13) * ((FAST_FLOAT) 1.414213562); /* 2*c4 */
  155335. z5 = (z10 + z12) * ((FAST_FLOAT) 1.847759065); /* 2*c2 */
  155336. tmp10 = ((FAST_FLOAT) 1.082392200) * z12 - z5; /* 2*(c2-c6) */
  155337. tmp12 = ((FAST_FLOAT) -2.613125930) * z10 + z5; /* -2*(c2+c6) */
  155338. tmp6 = tmp12 - tmp7; /* phase 2 */
  155339. tmp5 = tmp11 - tmp6;
  155340. tmp4 = tmp10 + tmp5;
  155341. wsptr[DCTSIZE*0] = tmp0 + tmp7;
  155342. wsptr[DCTSIZE*7] = tmp0 - tmp7;
  155343. wsptr[DCTSIZE*1] = tmp1 + tmp6;
  155344. wsptr[DCTSIZE*6] = tmp1 - tmp6;
  155345. wsptr[DCTSIZE*2] = tmp2 + tmp5;
  155346. wsptr[DCTSIZE*5] = tmp2 - tmp5;
  155347. wsptr[DCTSIZE*4] = tmp3 + tmp4;
  155348. wsptr[DCTSIZE*3] = tmp3 - tmp4;
  155349. inptr++; /* advance pointers to next column */
  155350. quantptr++;
  155351. wsptr++;
  155352. }
  155353. wsptr = workspace;
  155354. for (ctr = 0; ctr < DCTSIZE; ctr++) {
  155355. outptr = output_buf[ctr] + output_col;
  155356. tmp10 = wsptr[0] + wsptr[4];
  155357. tmp11 = wsptr[0] - wsptr[4];
  155358. tmp13 = wsptr[2] + wsptr[6];
  155359. tmp12 = (wsptr[2] - wsptr[6]) * ((FAST_FLOAT) 1.414213562) - tmp13;
  155360. tmp0 = tmp10 + tmp13;
  155361. tmp3 = tmp10 - tmp13;
  155362. tmp1 = tmp11 + tmp12;
  155363. tmp2 = tmp11 - tmp12;
  155364. z13 = wsptr[5] + wsptr[3];
  155365. z10 = wsptr[5] - wsptr[3];
  155366. z11 = wsptr[1] + wsptr[7];
  155367. z12 = wsptr[1] - wsptr[7];
  155368. tmp7 = z11 + z13;
  155369. tmp11 = (z11 - z13) * ((FAST_FLOAT) 1.414213562);
  155370. z5 = (z10 + z12) * ((FAST_FLOAT) 1.847759065); /* 2*c2 */
  155371. tmp10 = ((FAST_FLOAT) 1.082392200) * z12 - z5; /* 2*(c2-c6) */
  155372. tmp12 = ((FAST_FLOAT) -2.613125930) * z10 + z5; /* -2*(c2+c6) */
  155373. tmp6 = tmp12 - tmp7;
  155374. tmp5 = tmp11 - tmp6;
  155375. tmp4 = tmp10 + tmp5;
  155376. outptr[0] = range_limit[(int) DESCALE((INT32) (tmp0 + tmp7), 3)
  155377. & RANGE_MASK];
  155378. outptr[7] = range_limit[(int) DESCALE((INT32) (tmp0 - tmp7), 3)
  155379. & RANGE_MASK];
  155380. outptr[1] = range_limit[(int) DESCALE((INT32) (tmp1 + tmp6), 3)
  155381. & RANGE_MASK];
  155382. outptr[6] = range_limit[(int) DESCALE((INT32) (tmp1 - tmp6), 3)
  155383. & RANGE_MASK];
  155384. outptr[2] = range_limit[(int) DESCALE((INT32) (tmp2 + tmp5), 3)
  155385. & RANGE_MASK];
  155386. outptr[5] = range_limit[(int) DESCALE((INT32) (tmp2 - tmp5), 3)
  155387. & RANGE_MASK];
  155388. outptr[4] = range_limit[(int) DESCALE((INT32) (tmp3 + tmp4), 3)
  155389. & RANGE_MASK];
  155390. outptr[3] = range_limit[(int) DESCALE((INT32) (tmp3 - tmp4), 3)
  155391. & RANGE_MASK];
  155392. wsptr += DCTSIZE; /* advance pointer to next row */
  155393. }
  155394. }
  155395. #endif /* DCT_FLOAT_SUPPORTED */
  155396. /*** End of inlined file: jidctflt.c ***/
  155397. #undef CONST_BITS
  155398. #undef FIX_1_847759065
  155399. #undef MULTIPLY
  155400. #undef DEQUANTIZE
  155401. #undef DESCALE
  155402. /*** Start of inlined file: jidctfst.c ***/
  155403. #define JPEG_INTERNALS
  155404. #ifdef DCT_IFAST_SUPPORTED
  155405. #if DCTSIZE != 8
  155406. Sorry, this code only copes with 8x8 DCTs. /* deliberate syntax err */
  155407. #endif
  155408. #if BITS_IN_JSAMPLE == 8
  155409. #define CONST_BITS 8
  155410. #define PASS1_BITS 2
  155411. #else
  155412. #define CONST_BITS 8
  155413. #define PASS1_BITS 1 /* lose a little precision to avoid overflow */
  155414. #endif
  155415. #if CONST_BITS == 8
  155416. #define FIX_1_082392200 ((INT32) 277) /* FIX(1.082392200) */
  155417. #define FIX_1_414213562 ((INT32) 362) /* FIX(1.414213562) */
  155418. #define FIX_1_847759065 ((INT32) 473) /* FIX(1.847759065) */
  155419. #define FIX_2_613125930 ((INT32) 669) /* FIX(2.613125930) */
  155420. #else
  155421. #define FIX_1_082392200 FIX(1.082392200)
  155422. #define FIX_1_414213562 FIX(1.414213562)
  155423. #define FIX_1_847759065 FIX(1.847759065)
  155424. #define FIX_2_613125930 FIX(2.613125930)
  155425. #endif
  155426. #ifndef USE_ACCURATE_ROUNDING
  155427. #undef DESCALE
  155428. #define DESCALE(x,n) RIGHT_SHIFT(x, n)
  155429. #endif
  155430. #define MULTIPLY(var,const) ((DCTELEM) DESCALE((var) * (const), CONST_BITS))
  155431. #if BITS_IN_JSAMPLE == 8
  155432. #define DEQUANTIZE(coef,quantval) (((IFAST_MULT_TYPE) (coef)) * (quantval))
  155433. #else
  155434. #define DEQUANTIZE(coef,quantval) \
  155435. DESCALE((coef)*(quantval), IFAST_SCALE_BITS-PASS1_BITS)
  155436. #endif
  155437. #ifdef RIGHT_SHIFT_IS_UNSIGNED
  155438. #define ISHIFT_TEMPS DCTELEM ishift_temp;
  155439. #if BITS_IN_JSAMPLE == 8
  155440. #define DCTELEMBITS 16 /* DCTELEM may be 16 or 32 bits */
  155441. #else
  155442. #define DCTELEMBITS 32 /* DCTELEM must be 32 bits */
  155443. #endif
  155444. #define IRIGHT_SHIFT(x,shft) \
  155445. ((ishift_temp = (x)) < 0 ? \
  155446. (ishift_temp >> (shft)) | ((~((DCTELEM) 0)) << (DCTELEMBITS-(shft))) : \
  155447. (ishift_temp >> (shft)))
  155448. #else
  155449. #define ISHIFT_TEMPS
  155450. #define IRIGHT_SHIFT(x,shft) ((x) >> (shft))
  155451. #endif
  155452. #ifdef USE_ACCURATE_ROUNDING
  155453. #define IDESCALE(x,n) ((int) IRIGHT_SHIFT((x) + (1 << ((n)-1)), n))
  155454. #else
  155455. #define IDESCALE(x,n) ((int) IRIGHT_SHIFT(x, n))
  155456. #endif
  155457. GLOBAL(void)
  155458. jpeg_idct_ifast (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  155459. JCOEFPTR coef_block,
  155460. JSAMPARRAY output_buf, JDIMENSION output_col)
  155461. {
  155462. DCTELEM tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
  155463. DCTELEM tmp10, tmp11, tmp12, tmp13;
  155464. DCTELEM z5, z10, z11, z12, z13;
  155465. JCOEFPTR inptr;
  155466. IFAST_MULT_TYPE * quantptr;
  155467. int * wsptr;
  155468. JSAMPROW outptr;
  155469. JSAMPLE *range_limit = IDCT_range_limit(cinfo);
  155470. int ctr;
  155471. int workspace[DCTSIZE2]; /* buffers data between passes */
  155472. SHIFT_TEMPS /* for DESCALE */
  155473. ISHIFT_TEMPS /* for IDESCALE */
  155474. inptr = coef_block;
  155475. quantptr = (IFAST_MULT_TYPE *) compptr->dct_table;
  155476. wsptr = workspace;
  155477. for (ctr = DCTSIZE; ctr > 0; ctr--) {
  155478. if (inptr[DCTSIZE*1] == 0 && inptr[DCTSIZE*2] == 0 &&
  155479. inptr[DCTSIZE*3] == 0 && inptr[DCTSIZE*4] == 0 &&
  155480. inptr[DCTSIZE*5] == 0 && inptr[DCTSIZE*6] == 0 &&
  155481. inptr[DCTSIZE*7] == 0) {
  155482. int dcval = (int) DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
  155483. wsptr[DCTSIZE*0] = dcval;
  155484. wsptr[DCTSIZE*1] = dcval;
  155485. wsptr[DCTSIZE*2] = dcval;
  155486. wsptr[DCTSIZE*3] = dcval;
  155487. wsptr[DCTSIZE*4] = dcval;
  155488. wsptr[DCTSIZE*5] = dcval;
  155489. wsptr[DCTSIZE*6] = dcval;
  155490. wsptr[DCTSIZE*7] = dcval;
  155491. inptr++; /* advance pointers to next column */
  155492. quantptr++;
  155493. wsptr++;
  155494. continue;
  155495. }
  155496. tmp0 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
  155497. tmp1 = DEQUANTIZE(inptr[DCTSIZE*2], quantptr[DCTSIZE*2]);
  155498. tmp2 = DEQUANTIZE(inptr[DCTSIZE*4], quantptr[DCTSIZE*4]);
  155499. tmp3 = DEQUANTIZE(inptr[DCTSIZE*6], quantptr[DCTSIZE*6]);
  155500. tmp10 = tmp0 + tmp2; /* phase 3 */
  155501. tmp11 = tmp0 - tmp2;
  155502. tmp13 = tmp1 + tmp3; /* phases 5-3 */
  155503. tmp12 = MULTIPLY(tmp1 - tmp3, FIX_1_414213562) - tmp13; /* 2*c4 */
  155504. tmp0 = tmp10 + tmp13; /* phase 2 */
  155505. tmp3 = tmp10 - tmp13;
  155506. tmp1 = tmp11 + tmp12;
  155507. tmp2 = tmp11 - tmp12;
  155508. tmp4 = DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1]);
  155509. tmp5 = DEQUANTIZE(inptr[DCTSIZE*3], quantptr[DCTSIZE*3]);
  155510. tmp6 = DEQUANTIZE(inptr[DCTSIZE*5], quantptr[DCTSIZE*5]);
  155511. tmp7 = DEQUANTIZE(inptr[DCTSIZE*7], quantptr[DCTSIZE*7]);
  155512. z13 = tmp6 + tmp5; /* phase 6 */
  155513. z10 = tmp6 - tmp5;
  155514. z11 = tmp4 + tmp7;
  155515. z12 = tmp4 - tmp7;
  155516. tmp7 = z11 + z13; /* phase 5 */
  155517. tmp11 = MULTIPLY(z11 - z13, FIX_1_414213562); /* 2*c4 */
  155518. z5 = MULTIPLY(z10 + z12, FIX_1_847759065); /* 2*c2 */
  155519. tmp10 = MULTIPLY(z12, FIX_1_082392200) - z5; /* 2*(c2-c6) */
  155520. tmp12 = MULTIPLY(z10, - FIX_2_613125930) + z5; /* -2*(c2+c6) */
  155521. tmp6 = tmp12 - tmp7; /* phase 2 */
  155522. tmp5 = tmp11 - tmp6;
  155523. tmp4 = tmp10 + tmp5;
  155524. wsptr[DCTSIZE*0] = (int) (tmp0 + tmp7);
  155525. wsptr[DCTSIZE*7] = (int) (tmp0 - tmp7);
  155526. wsptr[DCTSIZE*1] = (int) (tmp1 + tmp6);
  155527. wsptr[DCTSIZE*6] = (int) (tmp1 - tmp6);
  155528. wsptr[DCTSIZE*2] = (int) (tmp2 + tmp5);
  155529. wsptr[DCTSIZE*5] = (int) (tmp2 - tmp5);
  155530. wsptr[DCTSIZE*4] = (int) (tmp3 + tmp4);
  155531. wsptr[DCTSIZE*3] = (int) (tmp3 - tmp4);
  155532. inptr++; /* advance pointers to next column */
  155533. quantptr++;
  155534. wsptr++;
  155535. }
  155536. wsptr = workspace;
  155537. for (ctr = 0; ctr < DCTSIZE; ctr++) {
  155538. outptr = output_buf[ctr] + output_col;
  155539. #ifndef NO_ZERO_ROW_TEST
  155540. if (wsptr[1] == 0 && wsptr[2] == 0 && wsptr[3] == 0 && wsptr[4] == 0 &&
  155541. wsptr[5] == 0 && wsptr[6] == 0 && wsptr[7] == 0) {
  155542. JSAMPLE dcval = range_limit[IDESCALE(wsptr[0], PASS1_BITS+3)
  155543. & RANGE_MASK];
  155544. outptr[0] = dcval;
  155545. outptr[1] = dcval;
  155546. outptr[2] = dcval;
  155547. outptr[3] = dcval;
  155548. outptr[4] = dcval;
  155549. outptr[5] = dcval;
  155550. outptr[6] = dcval;
  155551. outptr[7] = dcval;
  155552. wsptr += DCTSIZE; /* advance pointer to next row */
  155553. continue;
  155554. }
  155555. #endif
  155556. tmp10 = ((DCTELEM) wsptr[0] + (DCTELEM) wsptr[4]);
  155557. tmp11 = ((DCTELEM) wsptr[0] - (DCTELEM) wsptr[4]);
  155558. tmp13 = ((DCTELEM) wsptr[2] + (DCTELEM) wsptr[6]);
  155559. tmp12 = MULTIPLY((DCTELEM) wsptr[2] - (DCTELEM) wsptr[6], FIX_1_414213562)
  155560. - tmp13;
  155561. tmp0 = tmp10 + tmp13;
  155562. tmp3 = tmp10 - tmp13;
  155563. tmp1 = tmp11 + tmp12;
  155564. tmp2 = tmp11 - tmp12;
  155565. z13 = (DCTELEM) wsptr[5] + (DCTELEM) wsptr[3];
  155566. z10 = (DCTELEM) wsptr[5] - (DCTELEM) wsptr[3];
  155567. z11 = (DCTELEM) wsptr[1] + (DCTELEM) wsptr[7];
  155568. z12 = (DCTELEM) wsptr[1] - (DCTELEM) wsptr[7];
  155569. tmp7 = z11 + z13; /* phase 5 */
  155570. tmp11 = MULTIPLY(z11 - z13, FIX_1_414213562); /* 2*c4 */
  155571. z5 = MULTIPLY(z10 + z12, FIX_1_847759065); /* 2*c2 */
  155572. tmp10 = MULTIPLY(z12, FIX_1_082392200) - z5; /* 2*(c2-c6) */
  155573. tmp12 = MULTIPLY(z10, - FIX_2_613125930) + z5; /* -2*(c2+c6) */
  155574. tmp6 = tmp12 - tmp7; /* phase 2 */
  155575. tmp5 = tmp11 - tmp6;
  155576. tmp4 = tmp10 + tmp5;
  155577. outptr[0] = range_limit[IDESCALE(tmp0 + tmp7, PASS1_BITS+3)
  155578. & RANGE_MASK];
  155579. outptr[7] = range_limit[IDESCALE(tmp0 - tmp7, PASS1_BITS+3)
  155580. & RANGE_MASK];
  155581. outptr[1] = range_limit[IDESCALE(tmp1 + tmp6, PASS1_BITS+3)
  155582. & RANGE_MASK];
  155583. outptr[6] = range_limit[IDESCALE(tmp1 - tmp6, PASS1_BITS+3)
  155584. & RANGE_MASK];
  155585. outptr[2] = range_limit[IDESCALE(tmp2 + tmp5, PASS1_BITS+3)
  155586. & RANGE_MASK];
  155587. outptr[5] = range_limit[IDESCALE(tmp2 - tmp5, PASS1_BITS+3)
  155588. & RANGE_MASK];
  155589. outptr[4] = range_limit[IDESCALE(tmp3 + tmp4, PASS1_BITS+3)
  155590. & RANGE_MASK];
  155591. outptr[3] = range_limit[IDESCALE(tmp3 - tmp4, PASS1_BITS+3)
  155592. & RANGE_MASK];
  155593. wsptr += DCTSIZE; /* advance pointer to next row */
  155594. }
  155595. }
  155596. #endif /* DCT_IFAST_SUPPORTED */
  155597. /*** End of inlined file: jidctfst.c ***/
  155598. #undef CONST_BITS
  155599. #undef FIX_1_847759065
  155600. #undef MULTIPLY
  155601. #undef DEQUANTIZE
  155602. /*** Start of inlined file: jidctint.c ***/
  155603. #define JPEG_INTERNALS
  155604. #ifdef DCT_ISLOW_SUPPORTED
  155605. #if DCTSIZE != 8
  155606. Sorry, this code only copes with 8x8 DCTs. /* deliberate syntax err */
  155607. #endif
  155608. #if BITS_IN_JSAMPLE == 8
  155609. #define CONST_BITS 13
  155610. #define PASS1_BITS 2
  155611. #else
  155612. #define CONST_BITS 13
  155613. #define PASS1_BITS 1 /* lose a little precision to avoid overflow */
  155614. #endif
  155615. #if CONST_BITS == 13
  155616. #define FIX_0_298631336 ((INT32) 2446) /* FIX(0.298631336) */
  155617. #define FIX_0_390180644 ((INT32) 3196) /* FIX(0.390180644) */
  155618. #define FIX_0_541196100 ((INT32) 4433) /* FIX(0.541196100) */
  155619. #define FIX_0_765366865 ((INT32) 6270) /* FIX(0.765366865) */
  155620. #define FIX_0_899976223 ((INT32) 7373) /* FIX(0.899976223) */
  155621. #define FIX_1_175875602 ((INT32) 9633) /* FIX(1.175875602) */
  155622. #define FIX_1_501321110 ((INT32) 12299) /* FIX(1.501321110) */
  155623. #define FIX_1_847759065 ((INT32) 15137) /* FIX(1.847759065) */
  155624. #define FIX_1_961570560 ((INT32) 16069) /* FIX(1.961570560) */
  155625. #define FIX_2_053119869 ((INT32) 16819) /* FIX(2.053119869) */
  155626. #define FIX_2_562915447 ((INT32) 20995) /* FIX(2.562915447) */
  155627. #define FIX_3_072711026 ((INT32) 25172) /* FIX(3.072711026) */
  155628. #else
  155629. #define FIX_0_298631336 FIX(0.298631336)
  155630. #define FIX_0_390180644 FIX(0.390180644)
  155631. #define FIX_0_541196100 FIX(0.541196100)
  155632. #define FIX_0_765366865 FIX(0.765366865)
  155633. #define FIX_0_899976223 FIX(0.899976223)
  155634. #define FIX_1_175875602 FIX(1.175875602)
  155635. #define FIX_1_501321110 FIX(1.501321110)
  155636. #define FIX_1_847759065 FIX(1.847759065)
  155637. #define FIX_1_961570560 FIX(1.961570560)
  155638. #define FIX_2_053119869 FIX(2.053119869)
  155639. #define FIX_2_562915447 FIX(2.562915447)
  155640. #define FIX_3_072711026 FIX(3.072711026)
  155641. #endif
  155642. #if BITS_IN_JSAMPLE == 8
  155643. #define MULTIPLY(var,const) MULTIPLY16C16(var,const)
  155644. #else
  155645. #define MULTIPLY(var,const) ((var) * (const))
  155646. #endif
  155647. #define DEQUANTIZE(coef,quantval) (((ISLOW_MULT_TYPE) (coef)) * (quantval))
  155648. GLOBAL(void)
  155649. jpeg_idct_islow (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  155650. JCOEFPTR coef_block,
  155651. JSAMPARRAY output_buf, JDIMENSION output_col)
  155652. {
  155653. INT32 tmp0, tmp1, tmp2, tmp3;
  155654. INT32 tmp10, tmp11, tmp12, tmp13;
  155655. INT32 z1, z2, z3, z4, z5;
  155656. JCOEFPTR inptr;
  155657. ISLOW_MULT_TYPE * quantptr;
  155658. int * wsptr;
  155659. JSAMPROW outptr;
  155660. JSAMPLE *range_limit = IDCT_range_limit(cinfo);
  155661. int ctr;
  155662. int workspace[DCTSIZE2]; /* buffers data between passes */
  155663. SHIFT_TEMPS
  155664. inptr = coef_block;
  155665. quantptr = (ISLOW_MULT_TYPE *) compptr->dct_table;
  155666. wsptr = workspace;
  155667. for (ctr = DCTSIZE; ctr > 0; ctr--) {
  155668. if (inptr[DCTSIZE*1] == 0 && inptr[DCTSIZE*2] == 0 &&
  155669. inptr[DCTSIZE*3] == 0 && inptr[DCTSIZE*4] == 0 &&
  155670. inptr[DCTSIZE*5] == 0 && inptr[DCTSIZE*6] == 0 &&
  155671. inptr[DCTSIZE*7] == 0) {
  155672. int dcval = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]) << PASS1_BITS;
  155673. wsptr[DCTSIZE*0] = dcval;
  155674. wsptr[DCTSIZE*1] = dcval;
  155675. wsptr[DCTSIZE*2] = dcval;
  155676. wsptr[DCTSIZE*3] = dcval;
  155677. wsptr[DCTSIZE*4] = dcval;
  155678. wsptr[DCTSIZE*5] = dcval;
  155679. wsptr[DCTSIZE*6] = dcval;
  155680. wsptr[DCTSIZE*7] = dcval;
  155681. inptr++; /* advance pointers to next column */
  155682. quantptr++;
  155683. wsptr++;
  155684. continue;
  155685. }
  155686. z2 = DEQUANTIZE(inptr[DCTSIZE*2], quantptr[DCTSIZE*2]);
  155687. z3 = DEQUANTIZE(inptr[DCTSIZE*6], quantptr[DCTSIZE*6]);
  155688. z1 = MULTIPLY(z2 + z3, FIX_0_541196100);
  155689. tmp2 = z1 + MULTIPLY(z3, - FIX_1_847759065);
  155690. tmp3 = z1 + MULTIPLY(z2, FIX_0_765366865);
  155691. z2 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
  155692. z3 = DEQUANTIZE(inptr[DCTSIZE*4], quantptr[DCTSIZE*4]);
  155693. tmp0 = (z2 + z3) << CONST_BITS;
  155694. tmp1 = (z2 - z3) << CONST_BITS;
  155695. tmp10 = tmp0 + tmp3;
  155696. tmp13 = tmp0 - tmp3;
  155697. tmp11 = tmp1 + tmp2;
  155698. tmp12 = tmp1 - tmp2;
  155699. tmp0 = DEQUANTIZE(inptr[DCTSIZE*7], quantptr[DCTSIZE*7]);
  155700. tmp1 = DEQUANTIZE(inptr[DCTSIZE*5], quantptr[DCTSIZE*5]);
  155701. tmp2 = DEQUANTIZE(inptr[DCTSIZE*3], quantptr[DCTSIZE*3]);
  155702. tmp3 = DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1]);
  155703. z1 = tmp0 + tmp3;
  155704. z2 = tmp1 + tmp2;
  155705. z3 = tmp0 + tmp2;
  155706. z4 = tmp1 + tmp3;
  155707. z5 = MULTIPLY(z3 + z4, FIX_1_175875602); /* sqrt(2) * c3 */
  155708. tmp0 = MULTIPLY(tmp0, FIX_0_298631336); /* sqrt(2) * (-c1+c3+c5-c7) */
  155709. tmp1 = MULTIPLY(tmp1, FIX_2_053119869); /* sqrt(2) * ( c1+c3-c5+c7) */
  155710. tmp2 = MULTIPLY(tmp2, FIX_3_072711026); /* sqrt(2) * ( c1+c3+c5-c7) */
  155711. tmp3 = MULTIPLY(tmp3, FIX_1_501321110); /* sqrt(2) * ( c1+c3-c5-c7) */
  155712. z1 = MULTIPLY(z1, - FIX_0_899976223); /* sqrt(2) * (c7-c3) */
  155713. z2 = MULTIPLY(z2, - FIX_2_562915447); /* sqrt(2) * (-c1-c3) */
  155714. z3 = MULTIPLY(z3, - FIX_1_961570560); /* sqrt(2) * (-c3-c5) */
  155715. z4 = MULTIPLY(z4, - FIX_0_390180644); /* sqrt(2) * (c5-c3) */
  155716. z3 += z5;
  155717. z4 += z5;
  155718. tmp0 += z1 + z3;
  155719. tmp1 += z2 + z4;
  155720. tmp2 += z2 + z3;
  155721. tmp3 += z1 + z4;
  155722. wsptr[DCTSIZE*0] = (int) DESCALE(tmp10 + tmp3, CONST_BITS-PASS1_BITS);
  155723. wsptr[DCTSIZE*7] = (int) DESCALE(tmp10 - tmp3, CONST_BITS-PASS1_BITS);
  155724. wsptr[DCTSIZE*1] = (int) DESCALE(tmp11 + tmp2, CONST_BITS-PASS1_BITS);
  155725. wsptr[DCTSIZE*6] = (int) DESCALE(tmp11 - tmp2, CONST_BITS-PASS1_BITS);
  155726. wsptr[DCTSIZE*2] = (int) DESCALE(tmp12 + tmp1, CONST_BITS-PASS1_BITS);
  155727. wsptr[DCTSIZE*5] = (int) DESCALE(tmp12 - tmp1, CONST_BITS-PASS1_BITS);
  155728. wsptr[DCTSIZE*3] = (int) DESCALE(tmp13 + tmp0, CONST_BITS-PASS1_BITS);
  155729. wsptr[DCTSIZE*4] = (int) DESCALE(tmp13 - tmp0, CONST_BITS-PASS1_BITS);
  155730. inptr++; /* advance pointers to next column */
  155731. quantptr++;
  155732. wsptr++;
  155733. }
  155734. wsptr = workspace;
  155735. for (ctr = 0; ctr < DCTSIZE; ctr++) {
  155736. outptr = output_buf[ctr] + output_col;
  155737. #ifndef NO_ZERO_ROW_TEST
  155738. if (wsptr[1] == 0 && wsptr[2] == 0 && wsptr[3] == 0 && wsptr[4] == 0 &&
  155739. wsptr[5] == 0 && wsptr[6] == 0 && wsptr[7] == 0) {
  155740. JSAMPLE dcval = range_limit[(int) DESCALE((INT32) wsptr[0], PASS1_BITS+3)
  155741. & RANGE_MASK];
  155742. outptr[0] = dcval;
  155743. outptr[1] = dcval;
  155744. outptr[2] = dcval;
  155745. outptr[3] = dcval;
  155746. outptr[4] = dcval;
  155747. outptr[5] = dcval;
  155748. outptr[6] = dcval;
  155749. outptr[7] = dcval;
  155750. wsptr += DCTSIZE; /* advance pointer to next row */
  155751. continue;
  155752. }
  155753. #endif
  155754. z2 = (INT32) wsptr[2];
  155755. z3 = (INT32) wsptr[6];
  155756. z1 = MULTIPLY(z2 + z3, FIX_0_541196100);
  155757. tmp2 = z1 + MULTIPLY(z3, - FIX_1_847759065);
  155758. tmp3 = z1 + MULTIPLY(z2, FIX_0_765366865);
  155759. tmp0 = ((INT32) wsptr[0] + (INT32) wsptr[4]) << CONST_BITS;
  155760. tmp1 = ((INT32) wsptr[0] - (INT32) wsptr[4]) << CONST_BITS;
  155761. tmp10 = tmp0 + tmp3;
  155762. tmp13 = tmp0 - tmp3;
  155763. tmp11 = tmp1 + tmp2;
  155764. tmp12 = tmp1 - tmp2;
  155765. tmp0 = (INT32) wsptr[7];
  155766. tmp1 = (INT32) wsptr[5];
  155767. tmp2 = (INT32) wsptr[3];
  155768. tmp3 = (INT32) wsptr[1];
  155769. z1 = tmp0 + tmp3;
  155770. z2 = tmp1 + tmp2;
  155771. z3 = tmp0 + tmp2;
  155772. z4 = tmp1 + tmp3;
  155773. z5 = MULTIPLY(z3 + z4, FIX_1_175875602); /* sqrt(2) * c3 */
  155774. tmp0 = MULTIPLY(tmp0, FIX_0_298631336); /* sqrt(2) * (-c1+c3+c5-c7) */
  155775. tmp1 = MULTIPLY(tmp1, FIX_2_053119869); /* sqrt(2) * ( c1+c3-c5+c7) */
  155776. tmp2 = MULTIPLY(tmp2, FIX_3_072711026); /* sqrt(2) * ( c1+c3+c5-c7) */
  155777. tmp3 = MULTIPLY(tmp3, FIX_1_501321110); /* sqrt(2) * ( c1+c3-c5-c7) */
  155778. z1 = MULTIPLY(z1, - FIX_0_899976223); /* sqrt(2) * (c7-c3) */
  155779. z2 = MULTIPLY(z2, - FIX_2_562915447); /* sqrt(2) * (-c1-c3) */
  155780. z3 = MULTIPLY(z3, - FIX_1_961570560); /* sqrt(2) * (-c3-c5) */
  155781. z4 = MULTIPLY(z4, - FIX_0_390180644); /* sqrt(2) * (c5-c3) */
  155782. z3 += z5;
  155783. z4 += z5;
  155784. tmp0 += z1 + z3;
  155785. tmp1 += z2 + z4;
  155786. tmp2 += z2 + z3;
  155787. tmp3 += z1 + z4;
  155788. outptr[0] = range_limit[(int) DESCALE(tmp10 + tmp3,
  155789. CONST_BITS+PASS1_BITS+3)
  155790. & RANGE_MASK];
  155791. outptr[7] = range_limit[(int) DESCALE(tmp10 - tmp3,
  155792. CONST_BITS+PASS1_BITS+3)
  155793. & RANGE_MASK];
  155794. outptr[1] = range_limit[(int) DESCALE(tmp11 + tmp2,
  155795. CONST_BITS+PASS1_BITS+3)
  155796. & RANGE_MASK];
  155797. outptr[6] = range_limit[(int) DESCALE(tmp11 - tmp2,
  155798. CONST_BITS+PASS1_BITS+3)
  155799. & RANGE_MASK];
  155800. outptr[2] = range_limit[(int) DESCALE(tmp12 + tmp1,
  155801. CONST_BITS+PASS1_BITS+3)
  155802. & RANGE_MASK];
  155803. outptr[5] = range_limit[(int) DESCALE(tmp12 - tmp1,
  155804. CONST_BITS+PASS1_BITS+3)
  155805. & RANGE_MASK];
  155806. outptr[3] = range_limit[(int) DESCALE(tmp13 + tmp0,
  155807. CONST_BITS+PASS1_BITS+3)
  155808. & RANGE_MASK];
  155809. outptr[4] = range_limit[(int) DESCALE(tmp13 - tmp0,
  155810. CONST_BITS+PASS1_BITS+3)
  155811. & RANGE_MASK];
  155812. wsptr += DCTSIZE; /* advance pointer to next row */
  155813. }
  155814. }
  155815. #endif /* DCT_ISLOW_SUPPORTED */
  155816. /*** End of inlined file: jidctint.c ***/
  155817. /*** Start of inlined file: jidctred.c ***/
  155818. #define JPEG_INTERNALS
  155819. #ifdef IDCT_SCALING_SUPPORTED
  155820. #if DCTSIZE != 8
  155821. Sorry, this code only copes with 8x8 DCTs. /* deliberate syntax err */
  155822. #endif
  155823. #if BITS_IN_JSAMPLE == 8
  155824. #define CONST_BITS 13
  155825. #define PASS1_BITS 2
  155826. #else
  155827. #define CONST_BITS 13
  155828. #define PASS1_BITS 1 /* lose a little precision to avoid overflow */
  155829. #endif
  155830. #if CONST_BITS == 13
  155831. #define FIX_0_211164243 ((INT32) 1730) /* FIX(0.211164243) */
  155832. #define FIX_0_509795579 ((INT32) 4176) /* FIX(0.509795579) */
  155833. #define FIX_0_601344887 ((INT32) 4926) /* FIX(0.601344887) */
  155834. #define FIX_0_720959822 ((INT32) 5906) /* FIX(0.720959822) */
  155835. #define FIX_0_765366865 ((INT32) 6270) /* FIX(0.765366865) */
  155836. #define FIX_0_850430095 ((INT32) 6967) /* FIX(0.850430095) */
  155837. #define FIX_0_899976223 ((INT32) 7373) /* FIX(0.899976223) */
  155838. #define FIX_1_061594337 ((INT32) 8697) /* FIX(1.061594337) */
  155839. #define FIX_1_272758580 ((INT32) 10426) /* FIX(1.272758580) */
  155840. #define FIX_1_451774981 ((INT32) 11893) /* FIX(1.451774981) */
  155841. #define FIX_1_847759065 ((INT32) 15137) /* FIX(1.847759065) */
  155842. #define FIX_2_172734803 ((INT32) 17799) /* FIX(2.172734803) */
  155843. #define FIX_2_562915447 ((INT32) 20995) /* FIX(2.562915447) */
  155844. #define FIX_3_624509785 ((INT32) 29692) /* FIX(3.624509785) */
  155845. #else
  155846. #define FIX_0_211164243 FIX(0.211164243)
  155847. #define FIX_0_509795579 FIX(0.509795579)
  155848. #define FIX_0_601344887 FIX(0.601344887)
  155849. #define FIX_0_720959822 FIX(0.720959822)
  155850. #define FIX_0_765366865 FIX(0.765366865)
  155851. #define FIX_0_850430095 FIX(0.850430095)
  155852. #define FIX_0_899976223 FIX(0.899976223)
  155853. #define FIX_1_061594337 FIX(1.061594337)
  155854. #define FIX_1_272758580 FIX(1.272758580)
  155855. #define FIX_1_451774981 FIX(1.451774981)
  155856. #define FIX_1_847759065 FIX(1.847759065)
  155857. #define FIX_2_172734803 FIX(2.172734803)
  155858. #define FIX_2_562915447 FIX(2.562915447)
  155859. #define FIX_3_624509785 FIX(3.624509785)
  155860. #endif
  155861. #if BITS_IN_JSAMPLE == 8
  155862. #define MULTIPLY(var,const) MULTIPLY16C16(var,const)
  155863. #else
  155864. #define MULTIPLY(var,const) ((var) * (const))
  155865. #endif
  155866. #define DEQUANTIZE(coef,quantval) (((ISLOW_MULT_TYPE) (coef)) * (quantval))
  155867. GLOBAL(void)
  155868. jpeg_idct_4x4 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  155869. JCOEFPTR coef_block,
  155870. JSAMPARRAY output_buf, JDIMENSION output_col)
  155871. {
  155872. INT32 tmp0, tmp2, tmp10, tmp12;
  155873. INT32 z1, z2, z3, z4;
  155874. JCOEFPTR inptr;
  155875. ISLOW_MULT_TYPE * quantptr;
  155876. int * wsptr;
  155877. JSAMPROW outptr;
  155878. JSAMPLE *range_limit = IDCT_range_limit(cinfo);
  155879. int ctr;
  155880. int workspace[DCTSIZE*4]; /* buffers data between passes */
  155881. SHIFT_TEMPS
  155882. inptr = coef_block;
  155883. quantptr = (ISLOW_MULT_TYPE *) compptr->dct_table;
  155884. wsptr = workspace;
  155885. for (ctr = DCTSIZE; ctr > 0; inptr++, quantptr++, wsptr++, ctr--) {
  155886. if (ctr == DCTSIZE-4)
  155887. continue;
  155888. if (inptr[DCTSIZE*1] == 0 && inptr[DCTSIZE*2] == 0 &&
  155889. inptr[DCTSIZE*3] == 0 && inptr[DCTSIZE*5] == 0 &&
  155890. inptr[DCTSIZE*6] == 0 && inptr[DCTSIZE*7] == 0) {
  155891. int dcval = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]) << PASS1_BITS;
  155892. wsptr[DCTSIZE*0] = dcval;
  155893. wsptr[DCTSIZE*1] = dcval;
  155894. wsptr[DCTSIZE*2] = dcval;
  155895. wsptr[DCTSIZE*3] = dcval;
  155896. continue;
  155897. }
  155898. tmp0 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
  155899. tmp0 <<= (CONST_BITS+1);
  155900. z2 = DEQUANTIZE(inptr[DCTSIZE*2], quantptr[DCTSIZE*2]);
  155901. z3 = DEQUANTIZE(inptr[DCTSIZE*6], quantptr[DCTSIZE*6]);
  155902. tmp2 = MULTIPLY(z2, FIX_1_847759065) + MULTIPLY(z3, - FIX_0_765366865);
  155903. tmp10 = tmp0 + tmp2;
  155904. tmp12 = tmp0 - tmp2;
  155905. z1 = DEQUANTIZE(inptr[DCTSIZE*7], quantptr[DCTSIZE*7]);
  155906. z2 = DEQUANTIZE(inptr[DCTSIZE*5], quantptr[DCTSIZE*5]);
  155907. z3 = DEQUANTIZE(inptr[DCTSIZE*3], quantptr[DCTSIZE*3]);
  155908. z4 = DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1]);
  155909. tmp0 = MULTIPLY(z1, - FIX_0_211164243) /* sqrt(2) * (c3-c1) */
  155910. + MULTIPLY(z2, FIX_1_451774981) /* sqrt(2) * (c3+c7) */
  155911. + MULTIPLY(z3, - FIX_2_172734803) /* sqrt(2) * (-c1-c5) */
  155912. + MULTIPLY(z4, FIX_1_061594337); /* sqrt(2) * (c5+c7) */
  155913. tmp2 = MULTIPLY(z1, - FIX_0_509795579) /* sqrt(2) * (c7-c5) */
  155914. + MULTIPLY(z2, - FIX_0_601344887) /* sqrt(2) * (c5-c1) */
  155915. + MULTIPLY(z3, FIX_0_899976223) /* sqrt(2) * (c3-c7) */
  155916. + MULTIPLY(z4, FIX_2_562915447); /* sqrt(2) * (c1+c3) */
  155917. wsptr[DCTSIZE*0] = (int) DESCALE(tmp10 + tmp2, CONST_BITS-PASS1_BITS+1);
  155918. wsptr[DCTSIZE*3] = (int) DESCALE(tmp10 - tmp2, CONST_BITS-PASS1_BITS+1);
  155919. wsptr[DCTSIZE*1] = (int) DESCALE(tmp12 + tmp0, CONST_BITS-PASS1_BITS+1);
  155920. wsptr[DCTSIZE*2] = (int) DESCALE(tmp12 - tmp0, CONST_BITS-PASS1_BITS+1);
  155921. }
  155922. wsptr = workspace;
  155923. for (ctr = 0; ctr < 4; ctr++) {
  155924. outptr = output_buf[ctr] + output_col;
  155925. #ifndef NO_ZERO_ROW_TEST
  155926. if (wsptr[1] == 0 && wsptr[2] == 0 && wsptr[3] == 0 &&
  155927. wsptr[5] == 0 && wsptr[6] == 0 && wsptr[7] == 0) {
  155928. JSAMPLE dcval = range_limit[(int) DESCALE((INT32) wsptr[0], PASS1_BITS+3)
  155929. & RANGE_MASK];
  155930. outptr[0] = dcval;
  155931. outptr[1] = dcval;
  155932. outptr[2] = dcval;
  155933. outptr[3] = dcval;
  155934. wsptr += DCTSIZE; /* advance pointer to next row */
  155935. continue;
  155936. }
  155937. #endif
  155938. tmp0 = ((INT32) wsptr[0]) << (CONST_BITS+1);
  155939. tmp2 = MULTIPLY((INT32) wsptr[2], FIX_1_847759065)
  155940. + MULTIPLY((INT32) wsptr[6], - FIX_0_765366865);
  155941. tmp10 = tmp0 + tmp2;
  155942. tmp12 = tmp0 - tmp2;
  155943. z1 = (INT32) wsptr[7];
  155944. z2 = (INT32) wsptr[5];
  155945. z3 = (INT32) wsptr[3];
  155946. z4 = (INT32) wsptr[1];
  155947. tmp0 = MULTIPLY(z1, - FIX_0_211164243) /* sqrt(2) * (c3-c1) */
  155948. + MULTIPLY(z2, FIX_1_451774981) /* sqrt(2) * (c3+c7) */
  155949. + MULTIPLY(z3, - FIX_2_172734803) /* sqrt(2) * (-c1-c5) */
  155950. + MULTIPLY(z4, FIX_1_061594337); /* sqrt(2) * (c5+c7) */
  155951. tmp2 = MULTIPLY(z1, - FIX_0_509795579) /* sqrt(2) * (c7-c5) */
  155952. + MULTIPLY(z2, - FIX_0_601344887) /* sqrt(2) * (c5-c1) */
  155953. + MULTIPLY(z3, FIX_0_899976223) /* sqrt(2) * (c3-c7) */
  155954. + MULTIPLY(z4, FIX_2_562915447); /* sqrt(2) * (c1+c3) */
  155955. outptr[0] = range_limit[(int) DESCALE(tmp10 + tmp2,
  155956. CONST_BITS+PASS1_BITS+3+1)
  155957. & RANGE_MASK];
  155958. outptr[3] = range_limit[(int) DESCALE(tmp10 - tmp2,
  155959. CONST_BITS+PASS1_BITS+3+1)
  155960. & RANGE_MASK];
  155961. outptr[1] = range_limit[(int) DESCALE(tmp12 + tmp0,
  155962. CONST_BITS+PASS1_BITS+3+1)
  155963. & RANGE_MASK];
  155964. outptr[2] = range_limit[(int) DESCALE(tmp12 - tmp0,
  155965. CONST_BITS+PASS1_BITS+3+1)
  155966. & RANGE_MASK];
  155967. wsptr += DCTSIZE; /* advance pointer to next row */
  155968. }
  155969. }
  155970. GLOBAL(void)
  155971. jpeg_idct_2x2 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  155972. JCOEFPTR coef_block,
  155973. JSAMPARRAY output_buf, JDIMENSION output_col)
  155974. {
  155975. INT32 tmp0, tmp10, z1;
  155976. JCOEFPTR inptr;
  155977. ISLOW_MULT_TYPE * quantptr;
  155978. int * wsptr;
  155979. JSAMPROW outptr;
  155980. JSAMPLE *range_limit = IDCT_range_limit(cinfo);
  155981. int ctr;
  155982. int workspace[DCTSIZE*2]; /* buffers data between passes */
  155983. SHIFT_TEMPS
  155984. inptr = coef_block;
  155985. quantptr = (ISLOW_MULT_TYPE *) compptr->dct_table;
  155986. wsptr = workspace;
  155987. for (ctr = DCTSIZE; ctr > 0; inptr++, quantptr++, wsptr++, ctr--) {
  155988. if (ctr == DCTSIZE-2 || ctr == DCTSIZE-4 || ctr == DCTSIZE-6)
  155989. continue;
  155990. if (inptr[DCTSIZE*1] == 0 && inptr[DCTSIZE*3] == 0 &&
  155991. inptr[DCTSIZE*5] == 0 && inptr[DCTSIZE*7] == 0) {
  155992. int dcval = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]) << PASS1_BITS;
  155993. wsptr[DCTSIZE*0] = dcval;
  155994. wsptr[DCTSIZE*1] = dcval;
  155995. continue;
  155996. }
  155997. z1 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
  155998. tmp10 = z1 << (CONST_BITS+2);
  155999. z1 = DEQUANTIZE(inptr[DCTSIZE*7], quantptr[DCTSIZE*7]);
  156000. tmp0 = MULTIPLY(z1, - FIX_0_720959822); /* sqrt(2) * (c7-c5+c3-c1) */
  156001. z1 = DEQUANTIZE(inptr[DCTSIZE*5], quantptr[DCTSIZE*5]);
  156002. tmp0 += MULTIPLY(z1, FIX_0_850430095); /* sqrt(2) * (-c1+c3+c5+c7) */
  156003. z1 = DEQUANTIZE(inptr[DCTSIZE*3], quantptr[DCTSIZE*3]);
  156004. tmp0 += MULTIPLY(z1, - FIX_1_272758580); /* sqrt(2) * (-c1+c3-c5-c7) */
  156005. z1 = DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1]);
  156006. tmp0 += MULTIPLY(z1, FIX_3_624509785); /* sqrt(2) * (c1+c3+c5+c7) */
  156007. wsptr[DCTSIZE*0] = (int) DESCALE(tmp10 + tmp0, CONST_BITS-PASS1_BITS+2);
  156008. wsptr[DCTSIZE*1] = (int) DESCALE(tmp10 - tmp0, CONST_BITS-PASS1_BITS+2);
  156009. }
  156010. wsptr = workspace;
  156011. for (ctr = 0; ctr < 2; ctr++) {
  156012. outptr = output_buf[ctr] + output_col;
  156013. #ifndef NO_ZERO_ROW_TEST
  156014. if (wsptr[1] == 0 && wsptr[3] == 0 && wsptr[5] == 0 && wsptr[7] == 0) {
  156015. JSAMPLE dcval = range_limit[(int) DESCALE((INT32) wsptr[0], PASS1_BITS+3)
  156016. & RANGE_MASK];
  156017. outptr[0] = dcval;
  156018. outptr[1] = dcval;
  156019. wsptr += DCTSIZE; /* advance pointer to next row */
  156020. continue;
  156021. }
  156022. #endif
  156023. tmp10 = ((INT32) wsptr[0]) << (CONST_BITS+2);
  156024. tmp0 = MULTIPLY((INT32) wsptr[7], - FIX_0_720959822) /* sqrt(2) * (c7-c5+c3-c1) */
  156025. + MULTIPLY((INT32) wsptr[5], FIX_0_850430095) /* sqrt(2) * (-c1+c3+c5+c7) */
  156026. + MULTIPLY((INT32) wsptr[3], - FIX_1_272758580) /* sqrt(2) * (-c1+c3-c5-c7) */
  156027. + MULTIPLY((INT32) wsptr[1], FIX_3_624509785); /* sqrt(2) * (c1+c3+c5+c7) */
  156028. outptr[0] = range_limit[(int) DESCALE(tmp10 + tmp0,
  156029. CONST_BITS+PASS1_BITS+3+2)
  156030. & RANGE_MASK];
  156031. outptr[1] = range_limit[(int) DESCALE(tmp10 - tmp0,
  156032. CONST_BITS+PASS1_BITS+3+2)
  156033. & RANGE_MASK];
  156034. wsptr += DCTSIZE; /* advance pointer to next row */
  156035. }
  156036. }
  156037. GLOBAL(void)
  156038. jpeg_idct_1x1 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  156039. JCOEFPTR coef_block,
  156040. JSAMPARRAY output_buf, JDIMENSION output_col)
  156041. {
  156042. int dcval;
  156043. ISLOW_MULT_TYPE * quantptr;
  156044. JSAMPLE *range_limit = IDCT_range_limit(cinfo);
  156045. SHIFT_TEMPS
  156046. quantptr = (ISLOW_MULT_TYPE *) compptr->dct_table;
  156047. dcval = DEQUANTIZE(coef_block[0], quantptr[0]);
  156048. dcval = (int) DESCALE((INT32) dcval, 3);
  156049. output_buf[0][output_col] = range_limit[dcval & RANGE_MASK];
  156050. }
  156051. #endif /* IDCT_SCALING_SUPPORTED */
  156052. /*** End of inlined file: jidctred.c ***/
  156053. /*** Start of inlined file: jmemmgr.c ***/
  156054. #define JPEG_INTERNALS
  156055. #define AM_MEMORY_MANAGER /* we define jvirt_Xarray_control structs */
  156056. /*** Start of inlined file: jmemsys.h ***/
  156057. #ifndef __jmemsys_h__
  156058. #define __jmemsys_h__
  156059. #ifdef NEED_SHORT_EXTERNAL_NAMES
  156060. #define jpeg_get_small jGetSmall
  156061. #define jpeg_free_small jFreeSmall
  156062. #define jpeg_get_large jGetLarge
  156063. #define jpeg_free_large jFreeLarge
  156064. #define jpeg_mem_available jMemAvail
  156065. #define jpeg_open_backing_store jOpenBackStore
  156066. #define jpeg_mem_init jMemInit
  156067. #define jpeg_mem_term jMemTerm
  156068. #endif /* NEED_SHORT_EXTERNAL_NAMES */
  156069. EXTERN(void *) jpeg_get_small JPP((j_common_ptr cinfo, size_t sizeofobject));
  156070. EXTERN(void) jpeg_free_small JPP((j_common_ptr cinfo, void * object,
  156071. size_t sizeofobject));
  156072. EXTERN(void FAR *) jpeg_get_large JPP((j_common_ptr cinfo,
  156073. size_t sizeofobject));
  156074. EXTERN(void) jpeg_free_large JPP((j_common_ptr cinfo, void FAR * object,
  156075. size_t sizeofobject));
  156076. #ifndef MAX_ALLOC_CHUNK /* may be overridden in jconfig.h */
  156077. #define MAX_ALLOC_CHUNK 1000000000L
  156078. #endif
  156079. EXTERN(long) jpeg_mem_available JPP((j_common_ptr cinfo,
  156080. long min_bytes_needed,
  156081. long max_bytes_needed,
  156082. long already_allocated));
  156083. #define TEMP_NAME_LENGTH 64 /* max length of a temporary file's name */
  156084. #ifdef USE_MSDOS_MEMMGR /* DOS-specific junk */
  156085. typedef unsigned short XMSH; /* type of extended-memory handles */
  156086. typedef unsigned short EMSH; /* type of expanded-memory handles */
  156087. typedef union {
  156088. short file_handle; /* DOS file handle if it's a temp file */
  156089. XMSH xms_handle; /* handle if it's a chunk of XMS */
  156090. EMSH ems_handle; /* handle if it's a chunk of EMS */
  156091. } handle_union;
  156092. #endif /* USE_MSDOS_MEMMGR */
  156093. #ifdef USE_MAC_MEMMGR /* Mac-specific junk */
  156094. #include <Files.h>
  156095. #endif /* USE_MAC_MEMMGR */
  156096. //typedef struct backing_store_struct * backing_store_ptr;
  156097. typedef struct backing_store_struct {
  156098. JMETHOD(void, read_backing_store, (j_common_ptr cinfo,
  156099. struct backing_store_struct *info,
  156100. void FAR * buffer_address,
  156101. long file_offset, long byte_count));
  156102. JMETHOD(void, write_backing_store, (j_common_ptr cinfo,
  156103. struct backing_store_struct *info,
  156104. void FAR * buffer_address,
  156105. long file_offset, long byte_count));
  156106. JMETHOD(void, close_backing_store, (j_common_ptr cinfo,
  156107. struct backing_store_struct *info));
  156108. #ifdef USE_MSDOS_MEMMGR
  156109. handle_union handle; /* reference to backing-store storage object */
  156110. char temp_name[TEMP_NAME_LENGTH]; /* name if it's a file */
  156111. #else
  156112. #ifdef USE_MAC_MEMMGR
  156113. short temp_file; /* file reference number to temp file */
  156114. FSSpec tempSpec; /* the FSSpec for the temp file */
  156115. char temp_name[TEMP_NAME_LENGTH]; /* name if it's a file */
  156116. #else
  156117. FILE * temp_file; /* stdio reference to temp file */
  156118. char temp_name[TEMP_NAME_LENGTH]; /* name of temp file */
  156119. #endif
  156120. #endif
  156121. } backing_store_info;
  156122. EXTERN(void) jpeg_open_backing_store JPP((j_common_ptr cinfo,
  156123. struct backing_store_struct *info,
  156124. long total_bytes_needed));
  156125. EXTERN(long) jpeg_mem_init JPP((j_common_ptr cinfo));
  156126. EXTERN(void) jpeg_mem_term JPP((j_common_ptr cinfo));
  156127. #endif
  156128. /*** End of inlined file: jmemsys.h ***/
  156129. /* import the system-dependent declarations */
  156130. #ifndef NO_GETENV
  156131. #ifndef HAVE_STDLIB_H /* <stdlib.h> should declare getenv() */
  156132. extern char * getenv JPP((const char * name));
  156133. #endif
  156134. #endif
  156135. #ifndef ALIGN_TYPE /* so can override from jconfig.h */
  156136. #define ALIGN_TYPE double
  156137. #endif
  156138. typedef union small_pool_struct * small_pool_ptr;
  156139. typedef union small_pool_struct {
  156140. struct {
  156141. small_pool_ptr next; /* next in list of pools */
  156142. size_t bytes_used; /* how many bytes already used within pool */
  156143. size_t bytes_left; /* bytes still available in this pool */
  156144. } hdr;
  156145. ALIGN_TYPE dummy; /* included in union to ensure alignment */
  156146. } small_pool_hdr;
  156147. typedef union large_pool_struct FAR * large_pool_ptr;
  156148. typedef union large_pool_struct {
  156149. struct {
  156150. large_pool_ptr next; /* next in list of pools */
  156151. size_t bytes_used; /* how many bytes already used within pool */
  156152. size_t bytes_left; /* bytes still available in this pool */
  156153. } hdr;
  156154. ALIGN_TYPE dummy; /* included in union to ensure alignment */
  156155. } large_pool_hdr;
  156156. typedef struct {
  156157. struct jpeg_memory_mgr pub; /* public fields */
  156158. small_pool_ptr small_list[JPOOL_NUMPOOLS];
  156159. large_pool_ptr large_list[JPOOL_NUMPOOLS];
  156160. jvirt_sarray_ptr virt_sarray_list;
  156161. jvirt_barray_ptr virt_barray_list;
  156162. long total_space_allocated;
  156163. JDIMENSION last_rowsperchunk; /* from most recent alloc_sarray/barray */
  156164. } my_memory_mgr;
  156165. typedef my_memory_mgr * my_mem_ptr;
  156166. struct jvirt_sarray_control {
  156167. JSAMPARRAY mem_buffer; /* => the in-memory buffer */
  156168. JDIMENSION rows_in_array; /* total virtual array height */
  156169. JDIMENSION samplesperrow; /* width of array (and of memory buffer) */
  156170. JDIMENSION maxaccess; /* max rows accessed by access_virt_sarray */
  156171. JDIMENSION rows_in_mem; /* height of memory buffer */
  156172. JDIMENSION rowsperchunk; /* allocation chunk size in mem_buffer */
  156173. JDIMENSION cur_start_row; /* first logical row # in the buffer */
  156174. JDIMENSION first_undef_row; /* row # of first uninitialized row */
  156175. boolean pre_zero; /* pre-zero mode requested? */
  156176. boolean dirty; /* do current buffer contents need written? */
  156177. boolean b_s_open; /* is backing-store data valid? */
  156178. jvirt_sarray_ptr next; /* link to next virtual sarray control block */
  156179. backing_store_info b_s_info; /* System-dependent control info */
  156180. };
  156181. struct jvirt_barray_control {
  156182. JBLOCKARRAY mem_buffer; /* => the in-memory buffer */
  156183. JDIMENSION rows_in_array; /* total virtual array height */
  156184. JDIMENSION blocksperrow; /* width of array (and of memory buffer) */
  156185. JDIMENSION maxaccess; /* max rows accessed by access_virt_barray */
  156186. JDIMENSION rows_in_mem; /* height of memory buffer */
  156187. JDIMENSION rowsperchunk; /* allocation chunk size in mem_buffer */
  156188. JDIMENSION cur_start_row; /* first logical row # in the buffer */
  156189. JDIMENSION first_undef_row; /* row # of first uninitialized row */
  156190. boolean pre_zero; /* pre-zero mode requested? */
  156191. boolean dirty; /* do current buffer contents need written? */
  156192. boolean b_s_open; /* is backing-store data valid? */
  156193. jvirt_barray_ptr next; /* link to next virtual barray control block */
  156194. backing_store_info b_s_info; /* System-dependent control info */
  156195. };
  156196. #ifdef MEM_STATS /* optional extra stuff for statistics */
  156197. LOCAL(void)
  156198. print_mem_stats (j_common_ptr cinfo, int pool_id)
  156199. {
  156200. my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
  156201. small_pool_ptr shdr_ptr;
  156202. large_pool_ptr lhdr_ptr;
  156203. fprintf(stderr, "Freeing pool %d, total space = %ld\n",
  156204. pool_id, mem->total_space_allocated);
  156205. for (lhdr_ptr = mem->large_list[pool_id]; lhdr_ptr != NULL;
  156206. lhdr_ptr = lhdr_ptr->hdr.next) {
  156207. fprintf(stderr, " Large chunk used %ld\n",
  156208. (long) lhdr_ptr->hdr.bytes_used);
  156209. }
  156210. for (shdr_ptr = mem->small_list[pool_id]; shdr_ptr != NULL;
  156211. shdr_ptr = shdr_ptr->hdr.next) {
  156212. fprintf(stderr, " Small chunk used %ld free %ld\n",
  156213. (long) shdr_ptr->hdr.bytes_used,
  156214. (long) shdr_ptr->hdr.bytes_left);
  156215. }
  156216. }
  156217. #endif /* MEM_STATS */
  156218. LOCAL(void)
  156219. out_of_memory (j_common_ptr cinfo, int which)
  156220. {
  156221. #ifdef MEM_STATS
  156222. cinfo->err->trace_level = 2; /* force self_destruct to report stats */
  156223. #endif
  156224. ERREXIT1(cinfo, JERR_OUT_OF_MEMORY, which);
  156225. }
  156226. static const size_t first_pool_slop[JPOOL_NUMPOOLS] =
  156227. {
  156228. 1600, /* first PERMANENT pool */
  156229. 16000 /* first IMAGE pool */
  156230. };
  156231. static const size_t extra_pool_slop[JPOOL_NUMPOOLS] =
  156232. {
  156233. 0, /* additional PERMANENT pools */
  156234. 5000 /* additional IMAGE pools */
  156235. };
  156236. #define MIN_SLOP 50 /* greater than 0 to avoid futile looping */
  156237. METHODDEF(void *)
  156238. alloc_small (j_common_ptr cinfo, int pool_id, size_t sizeofobject)
  156239. {
  156240. my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
  156241. small_pool_ptr hdr_ptr, prev_hdr_ptr;
  156242. char * data_ptr;
  156243. size_t odd_bytes, min_request, slop;
  156244. if (sizeofobject > (size_t) (MAX_ALLOC_CHUNK-SIZEOF(small_pool_hdr)))
  156245. out_of_memory(cinfo, 1); /* request exceeds malloc's ability */
  156246. odd_bytes = sizeofobject % SIZEOF(ALIGN_TYPE);
  156247. if (odd_bytes > 0)
  156248. sizeofobject += SIZEOF(ALIGN_TYPE) - odd_bytes;
  156249. if (pool_id < 0 || pool_id >= JPOOL_NUMPOOLS)
  156250. ERREXIT1(cinfo, JERR_BAD_POOL_ID, pool_id); /* safety check */
  156251. prev_hdr_ptr = NULL;
  156252. hdr_ptr = mem->small_list[pool_id];
  156253. while (hdr_ptr != NULL) {
  156254. if (hdr_ptr->hdr.bytes_left >= sizeofobject)
  156255. break; /* found pool with enough space */
  156256. prev_hdr_ptr = hdr_ptr;
  156257. hdr_ptr = hdr_ptr->hdr.next;
  156258. }
  156259. if (hdr_ptr == NULL) {
  156260. min_request = sizeofobject + SIZEOF(small_pool_hdr);
  156261. if (prev_hdr_ptr == NULL) /* first pool in class? */
  156262. slop = first_pool_slop[pool_id];
  156263. else
  156264. slop = extra_pool_slop[pool_id];
  156265. if (slop > (size_t) (MAX_ALLOC_CHUNK-min_request))
  156266. slop = (size_t) (MAX_ALLOC_CHUNK-min_request);
  156267. for (;;) {
  156268. hdr_ptr = (small_pool_ptr) jpeg_get_small(cinfo, min_request + slop);
  156269. if (hdr_ptr != NULL)
  156270. break;
  156271. slop /= 2;
  156272. if (slop < MIN_SLOP) /* give up when it gets real small */
  156273. out_of_memory(cinfo, 2); /* jpeg_get_small failed */
  156274. }
  156275. mem->total_space_allocated += min_request + slop;
  156276. hdr_ptr->hdr.next = NULL;
  156277. hdr_ptr->hdr.bytes_used = 0;
  156278. hdr_ptr->hdr.bytes_left = sizeofobject + slop;
  156279. if (prev_hdr_ptr == NULL) /* first pool in class? */
  156280. mem->small_list[pool_id] = hdr_ptr;
  156281. else
  156282. prev_hdr_ptr->hdr.next = hdr_ptr;
  156283. }
  156284. data_ptr = (char *) (hdr_ptr + 1); /* point to first data byte in pool */
  156285. data_ptr += hdr_ptr->hdr.bytes_used; /* point to place for object */
  156286. hdr_ptr->hdr.bytes_used += sizeofobject;
  156287. hdr_ptr->hdr.bytes_left -= sizeofobject;
  156288. return (void *) data_ptr;
  156289. }
  156290. METHODDEF(void FAR *)
  156291. alloc_large (j_common_ptr cinfo, int pool_id, size_t sizeofobject)
  156292. {
  156293. my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
  156294. large_pool_ptr hdr_ptr;
  156295. size_t odd_bytes;
  156296. if (sizeofobject > (size_t) (MAX_ALLOC_CHUNK-SIZEOF(large_pool_hdr)))
  156297. out_of_memory(cinfo, 3); /* request exceeds malloc's ability */
  156298. odd_bytes = sizeofobject % SIZEOF(ALIGN_TYPE);
  156299. if (odd_bytes > 0)
  156300. sizeofobject += SIZEOF(ALIGN_TYPE) - odd_bytes;
  156301. if (pool_id < 0 || pool_id >= JPOOL_NUMPOOLS)
  156302. ERREXIT1(cinfo, JERR_BAD_POOL_ID, pool_id); /* safety check */
  156303. hdr_ptr = (large_pool_ptr) jpeg_get_large(cinfo, sizeofobject +
  156304. SIZEOF(large_pool_hdr));
  156305. if (hdr_ptr == NULL)
  156306. out_of_memory(cinfo, 4); /* jpeg_get_large failed */
  156307. mem->total_space_allocated += sizeofobject + SIZEOF(large_pool_hdr);
  156308. hdr_ptr->hdr.next = mem->large_list[pool_id];
  156309. hdr_ptr->hdr.bytes_used = sizeofobject;
  156310. hdr_ptr->hdr.bytes_left = 0;
  156311. mem->large_list[pool_id] = hdr_ptr;
  156312. return (void FAR *) (hdr_ptr + 1); /* point to first data byte in pool */
  156313. }
  156314. METHODDEF(JSAMPARRAY)
  156315. alloc_sarray (j_common_ptr cinfo, int pool_id,
  156316. JDIMENSION samplesperrow, JDIMENSION numrows)
  156317. {
  156318. my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
  156319. JSAMPARRAY result;
  156320. JSAMPROW workspace;
  156321. JDIMENSION rowsperchunk, currow, i;
  156322. long ltemp;
  156323. ltemp = (MAX_ALLOC_CHUNK-SIZEOF(large_pool_hdr)) /
  156324. ((long) samplesperrow * SIZEOF(JSAMPLE));
  156325. if (ltemp <= 0)
  156326. ERREXIT(cinfo, JERR_WIDTH_OVERFLOW);
  156327. if (ltemp < (long) numrows)
  156328. rowsperchunk = (JDIMENSION) ltemp;
  156329. else
  156330. rowsperchunk = numrows;
  156331. mem->last_rowsperchunk = rowsperchunk;
  156332. result = (JSAMPARRAY) alloc_small(cinfo, pool_id,
  156333. (size_t) (numrows * SIZEOF(JSAMPROW)));
  156334. currow = 0;
  156335. while (currow < numrows) {
  156336. rowsperchunk = MIN(rowsperchunk, numrows - currow);
  156337. workspace = (JSAMPROW) alloc_large(cinfo, pool_id,
  156338. (size_t) ((size_t) rowsperchunk * (size_t) samplesperrow
  156339. * SIZEOF(JSAMPLE)));
  156340. for (i = rowsperchunk; i > 0; i--) {
  156341. result[currow++] = workspace;
  156342. workspace += samplesperrow;
  156343. }
  156344. }
  156345. return result;
  156346. }
  156347. METHODDEF(JBLOCKARRAY)
  156348. alloc_barray (j_common_ptr cinfo, int pool_id,
  156349. JDIMENSION blocksperrow, JDIMENSION numrows)
  156350. {
  156351. my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
  156352. JBLOCKARRAY result;
  156353. JBLOCKROW workspace;
  156354. JDIMENSION rowsperchunk, currow, i;
  156355. long ltemp;
  156356. ltemp = (MAX_ALLOC_CHUNK-SIZEOF(large_pool_hdr)) /
  156357. ((long) blocksperrow * SIZEOF(JBLOCK));
  156358. if (ltemp <= 0)
  156359. ERREXIT(cinfo, JERR_WIDTH_OVERFLOW);
  156360. if (ltemp < (long) numrows)
  156361. rowsperchunk = (JDIMENSION) ltemp;
  156362. else
  156363. rowsperchunk = numrows;
  156364. mem->last_rowsperchunk = rowsperchunk;
  156365. result = (JBLOCKARRAY) alloc_small(cinfo, pool_id,
  156366. (size_t) (numrows * SIZEOF(JBLOCKROW)));
  156367. currow = 0;
  156368. while (currow < numrows) {
  156369. rowsperchunk = MIN(rowsperchunk, numrows - currow);
  156370. workspace = (JBLOCKROW) alloc_large(cinfo, pool_id,
  156371. (size_t) ((size_t) rowsperchunk * (size_t) blocksperrow
  156372. * SIZEOF(JBLOCK)));
  156373. for (i = rowsperchunk; i > 0; i--) {
  156374. result[currow++] = workspace;
  156375. workspace += blocksperrow;
  156376. }
  156377. }
  156378. return result;
  156379. }
  156380. METHODDEF(jvirt_sarray_ptr)
  156381. request_virt_sarray (j_common_ptr cinfo, int pool_id, boolean pre_zero,
  156382. JDIMENSION samplesperrow, JDIMENSION numrows,
  156383. JDIMENSION maxaccess)
  156384. {
  156385. my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
  156386. jvirt_sarray_ptr result;
  156387. if (pool_id != JPOOL_IMAGE)
  156388. ERREXIT1(cinfo, JERR_BAD_POOL_ID, pool_id); /* safety check */
  156389. result = (jvirt_sarray_ptr) alloc_small(cinfo, pool_id,
  156390. SIZEOF(struct jvirt_sarray_control));
  156391. result->mem_buffer = NULL; /* marks array not yet realized */
  156392. result->rows_in_array = numrows;
  156393. result->samplesperrow = samplesperrow;
  156394. result->maxaccess = maxaccess;
  156395. result->pre_zero = pre_zero;
  156396. result->b_s_open = FALSE; /* no associated backing-store object */
  156397. result->next = mem->virt_sarray_list; /* add to list of virtual arrays */
  156398. mem->virt_sarray_list = result;
  156399. return result;
  156400. }
  156401. METHODDEF(jvirt_barray_ptr)
  156402. request_virt_barray (j_common_ptr cinfo, int pool_id, boolean pre_zero,
  156403. JDIMENSION blocksperrow, JDIMENSION numrows,
  156404. JDIMENSION maxaccess)
  156405. {
  156406. my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
  156407. jvirt_barray_ptr result;
  156408. if (pool_id != JPOOL_IMAGE)
  156409. ERREXIT1(cinfo, JERR_BAD_POOL_ID, pool_id); /* safety check */
  156410. result = (jvirt_barray_ptr) alloc_small(cinfo, pool_id,
  156411. SIZEOF(struct jvirt_barray_control));
  156412. result->mem_buffer = NULL; /* marks array not yet realized */
  156413. result->rows_in_array = numrows;
  156414. result->blocksperrow = blocksperrow;
  156415. result->maxaccess = maxaccess;
  156416. result->pre_zero = pre_zero;
  156417. result->b_s_open = FALSE; /* no associated backing-store object */
  156418. result->next = mem->virt_barray_list; /* add to list of virtual arrays */
  156419. mem->virt_barray_list = result;
  156420. return result;
  156421. }
  156422. METHODDEF(void)
  156423. realize_virt_arrays (j_common_ptr cinfo)
  156424. {
  156425. my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
  156426. long space_per_minheight, maximum_space, avail_mem;
  156427. long minheights, max_minheights;
  156428. jvirt_sarray_ptr sptr;
  156429. jvirt_barray_ptr bptr;
  156430. space_per_minheight = 0;
  156431. maximum_space = 0;
  156432. for (sptr = mem->virt_sarray_list; sptr != NULL; sptr = sptr->next) {
  156433. if (sptr->mem_buffer == NULL) { /* if not realized yet */
  156434. space_per_minheight += (long) sptr->maxaccess *
  156435. (long) sptr->samplesperrow * SIZEOF(JSAMPLE);
  156436. maximum_space += (long) sptr->rows_in_array *
  156437. (long) sptr->samplesperrow * SIZEOF(JSAMPLE);
  156438. }
  156439. }
  156440. for (bptr = mem->virt_barray_list; bptr != NULL; bptr = bptr->next) {
  156441. if (bptr->mem_buffer == NULL) { /* if not realized yet */
  156442. space_per_minheight += (long) bptr->maxaccess *
  156443. (long) bptr->blocksperrow * SIZEOF(JBLOCK);
  156444. maximum_space += (long) bptr->rows_in_array *
  156445. (long) bptr->blocksperrow * SIZEOF(JBLOCK);
  156446. }
  156447. }
  156448. if (space_per_minheight <= 0)
  156449. return; /* no unrealized arrays, no work */
  156450. avail_mem = jpeg_mem_available(cinfo, space_per_minheight, maximum_space,
  156451. mem->total_space_allocated);
  156452. if (avail_mem >= maximum_space)
  156453. max_minheights = 1000000000L;
  156454. else {
  156455. max_minheights = avail_mem / space_per_minheight;
  156456. if (max_minheights <= 0)
  156457. max_minheights = 1;
  156458. }
  156459. for (sptr = mem->virt_sarray_list; sptr != NULL; sptr = sptr->next) {
  156460. if (sptr->mem_buffer == NULL) { /* if not realized yet */
  156461. minheights = ((long) sptr->rows_in_array - 1L) / sptr->maxaccess + 1L;
  156462. if (minheights <= max_minheights) {
  156463. sptr->rows_in_mem = sptr->rows_in_array;
  156464. } else {
  156465. sptr->rows_in_mem = (JDIMENSION) (max_minheights * sptr->maxaccess);
  156466. jpeg_open_backing_store(cinfo, & sptr->b_s_info,
  156467. (long) sptr->rows_in_array *
  156468. (long) sptr->samplesperrow *
  156469. (long) SIZEOF(JSAMPLE));
  156470. sptr->b_s_open = TRUE;
  156471. }
  156472. sptr->mem_buffer = alloc_sarray(cinfo, JPOOL_IMAGE,
  156473. sptr->samplesperrow, sptr->rows_in_mem);
  156474. sptr->rowsperchunk = mem->last_rowsperchunk;
  156475. sptr->cur_start_row = 0;
  156476. sptr->first_undef_row = 0;
  156477. sptr->dirty = FALSE;
  156478. }
  156479. }
  156480. for (bptr = mem->virt_barray_list; bptr != NULL; bptr = bptr->next) {
  156481. if (bptr->mem_buffer == NULL) { /* if not realized yet */
  156482. minheights = ((long) bptr->rows_in_array - 1L) / bptr->maxaccess + 1L;
  156483. if (minheights <= max_minheights) {
  156484. bptr->rows_in_mem = bptr->rows_in_array;
  156485. } else {
  156486. bptr->rows_in_mem = (JDIMENSION) (max_minheights * bptr->maxaccess);
  156487. jpeg_open_backing_store(cinfo, & bptr->b_s_info,
  156488. (long) bptr->rows_in_array *
  156489. (long) bptr->blocksperrow *
  156490. (long) SIZEOF(JBLOCK));
  156491. bptr->b_s_open = TRUE;
  156492. }
  156493. bptr->mem_buffer = alloc_barray(cinfo, JPOOL_IMAGE,
  156494. bptr->blocksperrow, bptr->rows_in_mem);
  156495. bptr->rowsperchunk = mem->last_rowsperchunk;
  156496. bptr->cur_start_row = 0;
  156497. bptr->first_undef_row = 0;
  156498. bptr->dirty = FALSE;
  156499. }
  156500. }
  156501. }
  156502. LOCAL(void)
  156503. do_sarray_io (j_common_ptr cinfo, jvirt_sarray_ptr ptr, boolean writing)
  156504. {
  156505. long bytesperrow, file_offset, byte_count, rows, thisrow, i;
  156506. bytesperrow = (long) ptr->samplesperrow * SIZEOF(JSAMPLE);
  156507. file_offset = ptr->cur_start_row * bytesperrow;
  156508. for (i = 0; i < (long) ptr->rows_in_mem; i += ptr->rowsperchunk) {
  156509. rows = MIN((long) ptr->rowsperchunk, (long) ptr->rows_in_mem - i);
  156510. thisrow = (long) ptr->cur_start_row + i;
  156511. rows = MIN(rows, (long) ptr->first_undef_row - thisrow);
  156512. rows = MIN(rows, (long) ptr->rows_in_array - thisrow);
  156513. if (rows <= 0) /* this chunk might be past end of file! */
  156514. break;
  156515. byte_count = rows * bytesperrow;
  156516. if (writing)
  156517. (*ptr->b_s_info.write_backing_store) (cinfo, & ptr->b_s_info,
  156518. (void FAR *) ptr->mem_buffer[i],
  156519. file_offset, byte_count);
  156520. else
  156521. (*ptr->b_s_info.read_backing_store) (cinfo, & ptr->b_s_info,
  156522. (void FAR *) ptr->mem_buffer[i],
  156523. file_offset, byte_count);
  156524. file_offset += byte_count;
  156525. }
  156526. }
  156527. LOCAL(void)
  156528. do_barray_io (j_common_ptr cinfo, jvirt_barray_ptr ptr, boolean writing)
  156529. {
  156530. long bytesperrow, file_offset, byte_count, rows, thisrow, i;
  156531. bytesperrow = (long) ptr->blocksperrow * SIZEOF(JBLOCK);
  156532. file_offset = ptr->cur_start_row * bytesperrow;
  156533. for (i = 0; i < (long) ptr->rows_in_mem; i += ptr->rowsperchunk) {
  156534. rows = MIN((long) ptr->rowsperchunk, (long) ptr->rows_in_mem - i);
  156535. thisrow = (long) ptr->cur_start_row + i;
  156536. rows = MIN(rows, (long) ptr->first_undef_row - thisrow);
  156537. rows = MIN(rows, (long) ptr->rows_in_array - thisrow);
  156538. if (rows <= 0) /* this chunk might be past end of file! */
  156539. break;
  156540. byte_count = rows * bytesperrow;
  156541. if (writing)
  156542. (*ptr->b_s_info.write_backing_store) (cinfo, & ptr->b_s_info,
  156543. (void FAR *) ptr->mem_buffer[i],
  156544. file_offset, byte_count);
  156545. else
  156546. (*ptr->b_s_info.read_backing_store) (cinfo, & ptr->b_s_info,
  156547. (void FAR *) ptr->mem_buffer[i],
  156548. file_offset, byte_count);
  156549. file_offset += byte_count;
  156550. }
  156551. }
  156552. METHODDEF(JSAMPARRAY)
  156553. access_virt_sarray (j_common_ptr cinfo, jvirt_sarray_ptr ptr,
  156554. JDIMENSION start_row, JDIMENSION num_rows,
  156555. boolean writable)
  156556. {
  156557. JDIMENSION end_row = start_row + num_rows;
  156558. JDIMENSION undef_row;
  156559. if (end_row > ptr->rows_in_array || num_rows > ptr->maxaccess ||
  156560. ptr->mem_buffer == NULL)
  156561. ERREXIT(cinfo, JERR_BAD_VIRTUAL_ACCESS);
  156562. if (start_row < ptr->cur_start_row ||
  156563. end_row > ptr->cur_start_row+ptr->rows_in_mem) {
  156564. if (! ptr->b_s_open)
  156565. ERREXIT(cinfo, JERR_VIRTUAL_BUG);
  156566. if (ptr->dirty) {
  156567. do_sarray_io(cinfo, ptr, TRUE);
  156568. ptr->dirty = FALSE;
  156569. }
  156570. if (start_row > ptr->cur_start_row) {
  156571. ptr->cur_start_row = start_row;
  156572. } else {
  156573. long ltemp;
  156574. ltemp = (long) end_row - (long) ptr->rows_in_mem;
  156575. if (ltemp < 0)
  156576. ltemp = 0; /* don't fall off front end of file */
  156577. ptr->cur_start_row = (JDIMENSION) ltemp;
  156578. }
  156579. do_sarray_io(cinfo, ptr, FALSE);
  156580. }
  156581. if (ptr->first_undef_row < end_row) {
  156582. if (ptr->first_undef_row < start_row) {
  156583. if (writable) /* writer skipped over a section of array */
  156584. ERREXIT(cinfo, JERR_BAD_VIRTUAL_ACCESS);
  156585. undef_row = start_row; /* but reader is allowed to read ahead */
  156586. } else {
  156587. undef_row = ptr->first_undef_row;
  156588. }
  156589. if (writable)
  156590. ptr->first_undef_row = end_row;
  156591. if (ptr->pre_zero) {
  156592. size_t bytesperrow = (size_t) ptr->samplesperrow * SIZEOF(JSAMPLE);
  156593. undef_row -= ptr->cur_start_row; /* make indexes relative to buffer */
  156594. end_row -= ptr->cur_start_row;
  156595. while (undef_row < end_row) {
  156596. jzero_far((void FAR *) ptr->mem_buffer[undef_row], bytesperrow);
  156597. undef_row++;
  156598. }
  156599. } else {
  156600. if (! writable) /* reader looking at undefined data */
  156601. ERREXIT(cinfo, JERR_BAD_VIRTUAL_ACCESS);
  156602. }
  156603. }
  156604. if (writable)
  156605. ptr->dirty = TRUE;
  156606. return ptr->mem_buffer + (start_row - ptr->cur_start_row);
  156607. }
  156608. METHODDEF(JBLOCKARRAY)
  156609. access_virt_barray (j_common_ptr cinfo, jvirt_barray_ptr ptr,
  156610. JDIMENSION start_row, JDIMENSION num_rows,
  156611. boolean writable)
  156612. {
  156613. JDIMENSION end_row = start_row + num_rows;
  156614. JDIMENSION undef_row;
  156615. if (end_row > ptr->rows_in_array || num_rows > ptr->maxaccess ||
  156616. ptr->mem_buffer == NULL)
  156617. ERREXIT(cinfo, JERR_BAD_VIRTUAL_ACCESS);
  156618. if (start_row < ptr->cur_start_row ||
  156619. end_row > ptr->cur_start_row+ptr->rows_in_mem) {
  156620. if (! ptr->b_s_open)
  156621. ERREXIT(cinfo, JERR_VIRTUAL_BUG);
  156622. if (ptr->dirty) {
  156623. do_barray_io(cinfo, ptr, TRUE);
  156624. ptr->dirty = FALSE;
  156625. }
  156626. if (start_row > ptr->cur_start_row) {
  156627. ptr->cur_start_row = start_row;
  156628. } else {
  156629. long ltemp;
  156630. ltemp = (long) end_row - (long) ptr->rows_in_mem;
  156631. if (ltemp < 0)
  156632. ltemp = 0; /* don't fall off front end of file */
  156633. ptr->cur_start_row = (JDIMENSION) ltemp;
  156634. }
  156635. do_barray_io(cinfo, ptr, FALSE);
  156636. }
  156637. if (ptr->first_undef_row < end_row) {
  156638. if (ptr->first_undef_row < start_row) {
  156639. if (writable) /* writer skipped over a section of array */
  156640. ERREXIT(cinfo, JERR_BAD_VIRTUAL_ACCESS);
  156641. undef_row = start_row; /* but reader is allowed to read ahead */
  156642. } else {
  156643. undef_row = ptr->first_undef_row;
  156644. }
  156645. if (writable)
  156646. ptr->first_undef_row = end_row;
  156647. if (ptr->pre_zero) {
  156648. size_t bytesperrow = (size_t) ptr->blocksperrow * SIZEOF(JBLOCK);
  156649. undef_row -= ptr->cur_start_row; /* make indexes relative to buffer */
  156650. end_row -= ptr->cur_start_row;
  156651. while (undef_row < end_row) {
  156652. jzero_far((void FAR *) ptr->mem_buffer[undef_row], bytesperrow);
  156653. undef_row++;
  156654. }
  156655. } else {
  156656. if (! writable) /* reader looking at undefined data */
  156657. ERREXIT(cinfo, JERR_BAD_VIRTUAL_ACCESS);
  156658. }
  156659. }
  156660. if (writable)
  156661. ptr->dirty = TRUE;
  156662. return ptr->mem_buffer + (start_row - ptr->cur_start_row);
  156663. }
  156664. METHODDEF(void)
  156665. free_pool (j_common_ptr cinfo, int pool_id)
  156666. {
  156667. my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
  156668. small_pool_ptr shdr_ptr;
  156669. large_pool_ptr lhdr_ptr;
  156670. size_t space_freed;
  156671. if (pool_id < 0 || pool_id >= JPOOL_NUMPOOLS)
  156672. ERREXIT1(cinfo, JERR_BAD_POOL_ID, pool_id); /* safety check */
  156673. #ifdef MEM_STATS
  156674. if (cinfo->err->trace_level > 1)
  156675. print_mem_stats(cinfo, pool_id); /* print pool's memory usage statistics */
  156676. #endif
  156677. if (pool_id == JPOOL_IMAGE) {
  156678. jvirt_sarray_ptr sptr;
  156679. jvirt_barray_ptr bptr;
  156680. for (sptr = mem->virt_sarray_list; sptr != NULL; sptr = sptr->next) {
  156681. if (sptr->b_s_open) { /* there may be no backing store */
  156682. sptr->b_s_open = FALSE; /* prevent recursive close if error */
  156683. (*sptr->b_s_info.close_backing_store) (cinfo, & sptr->b_s_info);
  156684. }
  156685. }
  156686. mem->virt_sarray_list = NULL;
  156687. for (bptr = mem->virt_barray_list; bptr != NULL; bptr = bptr->next) {
  156688. if (bptr->b_s_open) { /* there may be no backing store */
  156689. bptr->b_s_open = FALSE; /* prevent recursive close if error */
  156690. (*bptr->b_s_info.close_backing_store) (cinfo, & bptr->b_s_info);
  156691. }
  156692. }
  156693. mem->virt_barray_list = NULL;
  156694. }
  156695. lhdr_ptr = mem->large_list[pool_id];
  156696. mem->large_list[pool_id] = NULL;
  156697. while (lhdr_ptr != NULL) {
  156698. large_pool_ptr next_lhdr_ptr = lhdr_ptr->hdr.next;
  156699. space_freed = lhdr_ptr->hdr.bytes_used +
  156700. lhdr_ptr->hdr.bytes_left +
  156701. SIZEOF(large_pool_hdr);
  156702. jpeg_free_large(cinfo, (void FAR *) lhdr_ptr, space_freed);
  156703. mem->total_space_allocated -= space_freed;
  156704. lhdr_ptr = next_lhdr_ptr;
  156705. }
  156706. shdr_ptr = mem->small_list[pool_id];
  156707. mem->small_list[pool_id] = NULL;
  156708. while (shdr_ptr != NULL) {
  156709. small_pool_ptr next_shdr_ptr = shdr_ptr->hdr.next;
  156710. space_freed = shdr_ptr->hdr.bytes_used +
  156711. shdr_ptr->hdr.bytes_left +
  156712. SIZEOF(small_pool_hdr);
  156713. jpeg_free_small(cinfo, (void *) shdr_ptr, space_freed);
  156714. mem->total_space_allocated -= space_freed;
  156715. shdr_ptr = next_shdr_ptr;
  156716. }
  156717. }
  156718. METHODDEF(void)
  156719. self_destruct (j_common_ptr cinfo)
  156720. {
  156721. int pool;
  156722. for (pool = JPOOL_NUMPOOLS-1; pool >= JPOOL_PERMANENT; pool--) {
  156723. free_pool(cinfo, pool);
  156724. }
  156725. jpeg_free_small(cinfo, (void *) cinfo->mem, SIZEOF(my_memory_mgr));
  156726. cinfo->mem = NULL; /* ensures I will be called only once */
  156727. jpeg_mem_term(cinfo); /* system-dependent cleanup */
  156728. }
  156729. GLOBAL(void)
  156730. jinit_memory_mgr (j_common_ptr cinfo)
  156731. {
  156732. my_mem_ptr mem;
  156733. long max_to_use;
  156734. int pool;
  156735. size_t test_mac;
  156736. cinfo->mem = NULL; /* for safety if init fails */
  156737. if ((SIZEOF(ALIGN_TYPE) & (SIZEOF(ALIGN_TYPE)-1)) != 0)
  156738. ERREXIT(cinfo, JERR_BAD_ALIGN_TYPE);
  156739. test_mac = (size_t) MAX_ALLOC_CHUNK;
  156740. if ((long) test_mac != MAX_ALLOC_CHUNK ||
  156741. (MAX_ALLOC_CHUNK % SIZEOF(ALIGN_TYPE)) != 0)
  156742. ERREXIT(cinfo, JERR_BAD_ALLOC_CHUNK);
  156743. max_to_use = jpeg_mem_init(cinfo); /* system-dependent initialization */
  156744. mem = (my_mem_ptr) jpeg_get_small(cinfo, SIZEOF(my_memory_mgr));
  156745. if (mem == NULL) {
  156746. jpeg_mem_term(cinfo); /* system-dependent cleanup */
  156747. ERREXIT1(cinfo, JERR_OUT_OF_MEMORY, 0);
  156748. }
  156749. mem->pub.alloc_small = alloc_small;
  156750. mem->pub.alloc_large = alloc_large;
  156751. mem->pub.alloc_sarray = alloc_sarray;
  156752. mem->pub.alloc_barray = alloc_barray;
  156753. mem->pub.request_virt_sarray = request_virt_sarray;
  156754. mem->pub.request_virt_barray = request_virt_barray;
  156755. mem->pub.realize_virt_arrays = realize_virt_arrays;
  156756. mem->pub.access_virt_sarray = access_virt_sarray;
  156757. mem->pub.access_virt_barray = access_virt_barray;
  156758. mem->pub.free_pool = free_pool;
  156759. mem->pub.self_destruct = self_destruct;
  156760. mem->pub.max_alloc_chunk = MAX_ALLOC_CHUNK;
  156761. mem->pub.max_memory_to_use = max_to_use;
  156762. for (pool = JPOOL_NUMPOOLS-1; pool >= JPOOL_PERMANENT; pool--) {
  156763. mem->small_list[pool] = NULL;
  156764. mem->large_list[pool] = NULL;
  156765. }
  156766. mem->virt_sarray_list = NULL;
  156767. mem->virt_barray_list = NULL;
  156768. mem->total_space_allocated = SIZEOF(my_memory_mgr);
  156769. cinfo->mem = & mem->pub;
  156770. #ifndef NO_GETENV
  156771. { char * memenv;
  156772. if ((memenv = getenv("JPEGMEM")) != NULL) {
  156773. char ch = 'x';
  156774. if (sscanf(memenv, "%ld%c", &max_to_use, &ch) > 0) {
  156775. if (ch == 'm' || ch == 'M')
  156776. max_to_use *= 1000L;
  156777. mem->pub.max_memory_to_use = max_to_use * 1000L;
  156778. }
  156779. }
  156780. }
  156781. #endif
  156782. }
  156783. /*** End of inlined file: jmemmgr.c ***/
  156784. /*** Start of inlined file: jmemnobs.c ***/
  156785. #define JPEG_INTERNALS
  156786. #ifndef HAVE_STDLIB_H /* <stdlib.h> should declare malloc(),free() */
  156787. extern void * malloc JPP((size_t size));
  156788. extern void free JPP((void *ptr));
  156789. #endif
  156790. GLOBAL(void *)
  156791. jpeg_get_small (j_common_ptr cinfo, size_t sizeofobject)
  156792. {
  156793. return (void *) malloc(sizeofobject);
  156794. }
  156795. GLOBAL(void)
  156796. jpeg_free_small (j_common_ptr cinfo, void * object, size_t sizeofobject)
  156797. {
  156798. free(object);
  156799. }
  156800. GLOBAL(void FAR *)
  156801. jpeg_get_large (j_common_ptr cinfo, size_t sizeofobject)
  156802. {
  156803. return (void FAR *) malloc(sizeofobject);
  156804. }
  156805. GLOBAL(void)
  156806. jpeg_free_large (j_common_ptr cinfo, void FAR * object, size_t sizeofobject)
  156807. {
  156808. free(object);
  156809. }
  156810. GLOBAL(long)
  156811. jpeg_mem_available (j_common_ptr cinfo, long min_bytes_needed,
  156812. long max_bytes_needed, long already_allocated)
  156813. {
  156814. return max_bytes_needed;
  156815. }
  156816. GLOBAL(void)
  156817. jpeg_open_backing_store (j_common_ptr cinfo, struct backing_store_struct *info,
  156818. long total_bytes_needed)
  156819. {
  156820. ERREXIT(cinfo, JERR_NO_BACKING_STORE);
  156821. }
  156822. GLOBAL(long)
  156823. jpeg_mem_init (j_common_ptr cinfo)
  156824. {
  156825. return 0; /* just set max_memory_to_use to 0 */
  156826. }
  156827. GLOBAL(void)
  156828. jpeg_mem_term (j_common_ptr cinfo)
  156829. {
  156830. }
  156831. /*** End of inlined file: jmemnobs.c ***/
  156832. /*** Start of inlined file: jquant1.c ***/
  156833. #define JPEG_INTERNALS
  156834. #ifdef QUANT_1PASS_SUPPORTED
  156835. #define ODITHER_SIZE 16 /* dimension of dither matrix */
  156836. #define ODITHER_CELLS (ODITHER_SIZE*ODITHER_SIZE) /* # cells in matrix */
  156837. #define ODITHER_MASK (ODITHER_SIZE-1) /* mask for wrapping around counters */
  156838. typedef int ODITHER_MATRIX[ODITHER_SIZE][ODITHER_SIZE];
  156839. typedef int (*ODITHER_MATRIX_PTR)[ODITHER_SIZE];
  156840. static const UINT8 base_dither_matrix[ODITHER_SIZE][ODITHER_SIZE] = {
  156841. { 0,192, 48,240, 12,204, 60,252, 3,195, 51,243, 15,207, 63,255 },
  156842. { 128, 64,176,112,140, 76,188,124,131, 67,179,115,143, 79,191,127 },
  156843. { 32,224, 16,208, 44,236, 28,220, 35,227, 19,211, 47,239, 31,223 },
  156844. { 160, 96,144, 80,172,108,156, 92,163, 99,147, 83,175,111,159, 95 },
  156845. { 8,200, 56,248, 4,196, 52,244, 11,203, 59,251, 7,199, 55,247 },
  156846. { 136, 72,184,120,132, 68,180,116,139, 75,187,123,135, 71,183,119 },
  156847. { 40,232, 24,216, 36,228, 20,212, 43,235, 27,219, 39,231, 23,215 },
  156848. { 168,104,152, 88,164,100,148, 84,171,107,155, 91,167,103,151, 87 },
  156849. { 2,194, 50,242, 14,206, 62,254, 1,193, 49,241, 13,205, 61,253 },
  156850. { 130, 66,178,114,142, 78,190,126,129, 65,177,113,141, 77,189,125 },
  156851. { 34,226, 18,210, 46,238, 30,222, 33,225, 17,209, 45,237, 29,221 },
  156852. { 162, 98,146, 82,174,110,158, 94,161, 97,145, 81,173,109,157, 93 },
  156853. { 10,202, 58,250, 6,198, 54,246, 9,201, 57,249, 5,197, 53,245 },
  156854. { 138, 74,186,122,134, 70,182,118,137, 73,185,121,133, 69,181,117 },
  156855. { 42,234, 26,218, 38,230, 22,214, 41,233, 25,217, 37,229, 21,213 },
  156856. { 170,106,154, 90,166,102,150, 86,169,105,153, 89,165,101,149, 85 }
  156857. };
  156858. #if BITS_IN_JSAMPLE == 8
  156859. typedef INT16 FSERROR; /* 16 bits should be enough */
  156860. typedef int LOCFSERROR; /* use 'int' for calculation temps */
  156861. #else
  156862. typedef INT32 FSERROR; /* may need more than 16 bits */
  156863. typedef INT32 LOCFSERROR; /* be sure calculation temps are big enough */
  156864. #endif
  156865. typedef FSERROR FAR *FSERRPTR; /* pointer to error array (in FAR storage!) */
  156866. #define MAX_Q_COMPS 4 /* max components I can handle */
  156867. typedef struct {
  156868. struct jpeg_color_quantizer pub; /* public fields */
  156869. JSAMPARRAY sv_colormap; /* The color map as a 2-D pixel array */
  156870. int sv_actual; /* number of entries in use */
  156871. JSAMPARRAY colorindex; /* Precomputed mapping for speed */
  156872. boolean is_padded; /* is the colorindex padded for odither? */
  156873. int Ncolors[MAX_Q_COMPS]; /* # of values alloced to each component */
  156874. int row_index; /* cur row's vertical index in dither matrix */
  156875. ODITHER_MATRIX_PTR odither[MAX_Q_COMPS]; /* one dither array per component */
  156876. FSERRPTR fserrors[MAX_Q_COMPS]; /* accumulated errors */
  156877. boolean on_odd_row; /* flag to remember which row we are on */
  156878. } my_cquantizer;
  156879. typedef my_cquantizer * my_cquantize_ptr;
  156880. LOCAL(int)
  156881. select_ncolors (j_decompress_ptr cinfo, int Ncolors[])
  156882. {
  156883. int nc = cinfo->out_color_components; /* number of color components */
  156884. int max_colors = cinfo->desired_number_of_colors;
  156885. int total_colors, iroot, i, j;
  156886. boolean changed;
  156887. long temp;
  156888. static const int RGB_order[3] = { RGB_GREEN, RGB_RED, RGB_BLUE };
  156889. iroot = 1;
  156890. do {
  156891. iroot++;
  156892. temp = iroot; /* set temp = iroot ** nc */
  156893. for (i = 1; i < nc; i++)
  156894. temp *= iroot;
  156895. } while (temp <= (long) max_colors); /* repeat till iroot exceeds root */
  156896. iroot--; /* now iroot = floor(root) */
  156897. if (iroot < 2)
  156898. ERREXIT1(cinfo, JERR_QUANT_FEW_COLORS, (int) temp);
  156899. total_colors = 1;
  156900. for (i = 0; i < nc; i++) {
  156901. Ncolors[i] = iroot;
  156902. total_colors *= iroot;
  156903. }
  156904. do {
  156905. changed = FALSE;
  156906. for (i = 0; i < nc; i++) {
  156907. j = (cinfo->out_color_space == JCS_RGB ? RGB_order[i] : i);
  156908. temp = total_colors / Ncolors[j];
  156909. temp *= Ncolors[j]+1; /* done in long arith to avoid oflo */
  156910. if (temp > (long) max_colors)
  156911. break; /* won't fit, done with this pass */
  156912. Ncolors[j]++; /* OK, apply the increment */
  156913. total_colors = (int) temp;
  156914. changed = TRUE;
  156915. }
  156916. } while (changed);
  156917. return total_colors;
  156918. }
  156919. LOCAL(int)
  156920. output_value (j_decompress_ptr cinfo, int ci, int j, int maxj)
  156921. {
  156922. return (int) (((INT32) j * MAXJSAMPLE + maxj/2) / maxj);
  156923. }
  156924. LOCAL(int)
  156925. largest_input_value (j_decompress_ptr cinfo, int ci, int j, int maxj)
  156926. {
  156927. return (int) (((INT32) (2*j + 1) * MAXJSAMPLE + maxj) / (2*maxj));
  156928. }
  156929. LOCAL(void)
  156930. create_colormap (j_decompress_ptr cinfo)
  156931. {
  156932. my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
  156933. JSAMPARRAY colormap; /* Created colormap */
  156934. int total_colors; /* Number of distinct output colors */
  156935. int i,j,k, nci, blksize, blkdist, ptr, val;
  156936. total_colors = select_ncolors(cinfo, cquantize->Ncolors);
  156937. if (cinfo->out_color_components == 3)
  156938. TRACEMS4(cinfo, 1, JTRC_QUANT_3_NCOLORS,
  156939. total_colors, cquantize->Ncolors[0],
  156940. cquantize->Ncolors[1], cquantize->Ncolors[2]);
  156941. else
  156942. TRACEMS1(cinfo, 1, JTRC_QUANT_NCOLORS, total_colors);
  156943. colormap = (*cinfo->mem->alloc_sarray)
  156944. ((j_common_ptr) cinfo, JPOOL_IMAGE,
  156945. (JDIMENSION) total_colors, (JDIMENSION) cinfo->out_color_components);
  156946. blkdist = total_colors;
  156947. for (i = 0; i < cinfo->out_color_components; i++) {
  156948. nci = cquantize->Ncolors[i]; /* # of distinct values for this color */
  156949. blksize = blkdist / nci;
  156950. for (j = 0; j < nci; j++) {
  156951. val = output_value(cinfo, i, j, nci-1);
  156952. for (ptr = j * blksize; ptr < total_colors; ptr += blkdist) {
  156953. for (k = 0; k < blksize; k++)
  156954. colormap[i][ptr+k] = (JSAMPLE) val;
  156955. }
  156956. }
  156957. blkdist = blksize; /* blksize of this color is blkdist of next */
  156958. }
  156959. cquantize->sv_colormap = colormap;
  156960. cquantize->sv_actual = total_colors;
  156961. }
  156962. LOCAL(void)
  156963. create_colorindex (j_decompress_ptr cinfo)
  156964. {
  156965. my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
  156966. JSAMPROW indexptr;
  156967. int i,j,k, nci, blksize, val, pad;
  156968. if (cinfo->dither_mode == JDITHER_ORDERED) {
  156969. pad = MAXJSAMPLE*2;
  156970. cquantize->is_padded = TRUE;
  156971. } else {
  156972. pad = 0;
  156973. cquantize->is_padded = FALSE;
  156974. }
  156975. cquantize->colorindex = (*cinfo->mem->alloc_sarray)
  156976. ((j_common_ptr) cinfo, JPOOL_IMAGE,
  156977. (JDIMENSION) (MAXJSAMPLE+1 + pad),
  156978. (JDIMENSION) cinfo->out_color_components);
  156979. blksize = cquantize->sv_actual;
  156980. for (i = 0; i < cinfo->out_color_components; i++) {
  156981. nci = cquantize->Ncolors[i]; /* # of distinct values for this color */
  156982. blksize = blksize / nci;
  156983. if (pad)
  156984. cquantize->colorindex[i] += MAXJSAMPLE;
  156985. indexptr = cquantize->colorindex[i];
  156986. val = 0;
  156987. k = largest_input_value(cinfo, i, 0, nci-1);
  156988. for (j = 0; j <= MAXJSAMPLE; j++) {
  156989. while (j > k) /* advance val if past boundary */
  156990. k = largest_input_value(cinfo, i, ++val, nci-1);
  156991. indexptr[j] = (JSAMPLE) (val * blksize);
  156992. }
  156993. if (pad)
  156994. for (j = 1; j <= MAXJSAMPLE; j++) {
  156995. indexptr[-j] = indexptr[0];
  156996. indexptr[MAXJSAMPLE+j] = indexptr[MAXJSAMPLE];
  156997. }
  156998. }
  156999. }
  157000. LOCAL(ODITHER_MATRIX_PTR)
  157001. make_odither_array (j_decompress_ptr cinfo, int ncolors)
  157002. {
  157003. ODITHER_MATRIX_PTR odither;
  157004. int j,k;
  157005. INT32 num,den;
  157006. odither = (ODITHER_MATRIX_PTR)
  157007. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  157008. SIZEOF(ODITHER_MATRIX));
  157009. den = 2 * ODITHER_CELLS * ((INT32) (ncolors - 1));
  157010. for (j = 0; j < ODITHER_SIZE; j++) {
  157011. for (k = 0; k < ODITHER_SIZE; k++) {
  157012. num = ((INT32) (ODITHER_CELLS-1 - 2*((int)base_dither_matrix[j][k])))
  157013. * MAXJSAMPLE;
  157014. odither[j][k] = (int) (num<0 ? -((-num)/den) : num/den);
  157015. }
  157016. }
  157017. return odither;
  157018. }
  157019. LOCAL(void)
  157020. create_odither_tables (j_decompress_ptr cinfo)
  157021. {
  157022. my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
  157023. ODITHER_MATRIX_PTR odither;
  157024. int i, j, nci;
  157025. for (i = 0; i < cinfo->out_color_components; i++) {
  157026. nci = cquantize->Ncolors[i]; /* # of distinct values for this color */
  157027. odither = NULL; /* search for matching prior component */
  157028. for (j = 0; j < i; j++) {
  157029. if (nci == cquantize->Ncolors[j]) {
  157030. odither = cquantize->odither[j];
  157031. break;
  157032. }
  157033. }
  157034. if (odither == NULL) /* need a new table? */
  157035. odither = make_odither_array(cinfo, nci);
  157036. cquantize->odither[i] = odither;
  157037. }
  157038. }
  157039. METHODDEF(void)
  157040. color_quantize (j_decompress_ptr cinfo, JSAMPARRAY input_buf,
  157041. JSAMPARRAY output_buf, int num_rows)
  157042. {
  157043. my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
  157044. JSAMPARRAY colorindex = cquantize->colorindex;
  157045. register int pixcode, ci;
  157046. register JSAMPROW ptrin, ptrout;
  157047. int row;
  157048. JDIMENSION col;
  157049. JDIMENSION width = cinfo->output_width;
  157050. register int nc = cinfo->out_color_components;
  157051. for (row = 0; row < num_rows; row++) {
  157052. ptrin = input_buf[row];
  157053. ptrout = output_buf[row];
  157054. for (col = width; col > 0; col--) {
  157055. pixcode = 0;
  157056. for (ci = 0; ci < nc; ci++) {
  157057. pixcode += GETJSAMPLE(colorindex[ci][GETJSAMPLE(*ptrin++)]);
  157058. }
  157059. *ptrout++ = (JSAMPLE) pixcode;
  157060. }
  157061. }
  157062. }
  157063. METHODDEF(void)
  157064. color_quantize3 (j_decompress_ptr cinfo, JSAMPARRAY input_buf,
  157065. JSAMPARRAY output_buf, int num_rows)
  157066. {
  157067. my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
  157068. register int pixcode;
  157069. register JSAMPROW ptrin, ptrout;
  157070. JSAMPROW colorindex0 = cquantize->colorindex[0];
  157071. JSAMPROW colorindex1 = cquantize->colorindex[1];
  157072. JSAMPROW colorindex2 = cquantize->colorindex[2];
  157073. int row;
  157074. JDIMENSION col;
  157075. JDIMENSION width = cinfo->output_width;
  157076. for (row = 0; row < num_rows; row++) {
  157077. ptrin = input_buf[row];
  157078. ptrout = output_buf[row];
  157079. for (col = width; col > 0; col--) {
  157080. pixcode = GETJSAMPLE(colorindex0[GETJSAMPLE(*ptrin++)]);
  157081. pixcode += GETJSAMPLE(colorindex1[GETJSAMPLE(*ptrin++)]);
  157082. pixcode += GETJSAMPLE(colorindex2[GETJSAMPLE(*ptrin++)]);
  157083. *ptrout++ = (JSAMPLE) pixcode;
  157084. }
  157085. }
  157086. }
  157087. METHODDEF(void)
  157088. quantize_ord_dither (j_decompress_ptr cinfo, JSAMPARRAY input_buf,
  157089. JSAMPARRAY output_buf, int num_rows)
  157090. {
  157091. my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
  157092. register JSAMPROW input_ptr;
  157093. register JSAMPROW output_ptr;
  157094. JSAMPROW colorindex_ci;
  157095. int * dither; /* points to active row of dither matrix */
  157096. int row_index, col_index; /* current indexes into dither matrix */
  157097. int nc = cinfo->out_color_components;
  157098. int ci;
  157099. int row;
  157100. JDIMENSION col;
  157101. JDIMENSION width = cinfo->output_width;
  157102. for (row = 0; row < num_rows; row++) {
  157103. jzero_far((void FAR *) output_buf[row],
  157104. (size_t) (width * SIZEOF(JSAMPLE)));
  157105. row_index = cquantize->row_index;
  157106. for (ci = 0; ci < nc; ci++) {
  157107. input_ptr = input_buf[row] + ci;
  157108. output_ptr = output_buf[row];
  157109. colorindex_ci = cquantize->colorindex[ci];
  157110. dither = cquantize->odither[ci][row_index];
  157111. col_index = 0;
  157112. for (col = width; col > 0; col--) {
  157113. *output_ptr += colorindex_ci[GETJSAMPLE(*input_ptr)+dither[col_index]];
  157114. input_ptr += nc;
  157115. output_ptr++;
  157116. col_index = (col_index + 1) & ODITHER_MASK;
  157117. }
  157118. }
  157119. row_index = (row_index + 1) & ODITHER_MASK;
  157120. cquantize->row_index = row_index;
  157121. }
  157122. }
  157123. METHODDEF(void)
  157124. quantize3_ord_dither (j_decompress_ptr cinfo, JSAMPARRAY input_buf,
  157125. JSAMPARRAY output_buf, int num_rows)
  157126. {
  157127. my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
  157128. register int pixcode;
  157129. register JSAMPROW input_ptr;
  157130. register JSAMPROW output_ptr;
  157131. JSAMPROW colorindex0 = cquantize->colorindex[0];
  157132. JSAMPROW colorindex1 = cquantize->colorindex[1];
  157133. JSAMPROW colorindex2 = cquantize->colorindex[2];
  157134. int * dither0; /* points to active row of dither matrix */
  157135. int * dither1;
  157136. int * dither2;
  157137. int row_index, col_index; /* current indexes into dither matrix */
  157138. int row;
  157139. JDIMENSION col;
  157140. JDIMENSION width = cinfo->output_width;
  157141. for (row = 0; row < num_rows; row++) {
  157142. row_index = cquantize->row_index;
  157143. input_ptr = input_buf[row];
  157144. output_ptr = output_buf[row];
  157145. dither0 = cquantize->odither[0][row_index];
  157146. dither1 = cquantize->odither[1][row_index];
  157147. dither2 = cquantize->odither[2][row_index];
  157148. col_index = 0;
  157149. for (col = width; col > 0; col--) {
  157150. pixcode = GETJSAMPLE(colorindex0[GETJSAMPLE(*input_ptr++) +
  157151. dither0[col_index]]);
  157152. pixcode += GETJSAMPLE(colorindex1[GETJSAMPLE(*input_ptr++) +
  157153. dither1[col_index]]);
  157154. pixcode += GETJSAMPLE(colorindex2[GETJSAMPLE(*input_ptr++) +
  157155. dither2[col_index]]);
  157156. *output_ptr++ = (JSAMPLE) pixcode;
  157157. col_index = (col_index + 1) & ODITHER_MASK;
  157158. }
  157159. row_index = (row_index + 1) & ODITHER_MASK;
  157160. cquantize->row_index = row_index;
  157161. }
  157162. }
  157163. METHODDEF(void)
  157164. quantize_fs_dither (j_decompress_ptr cinfo, JSAMPARRAY input_buf,
  157165. JSAMPARRAY output_buf, int num_rows)
  157166. {
  157167. my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
  157168. register LOCFSERROR cur; /* current error or pixel value */
  157169. LOCFSERROR belowerr; /* error for pixel below cur */
  157170. LOCFSERROR bpreverr; /* error for below/prev col */
  157171. LOCFSERROR bnexterr; /* error for below/next col */
  157172. LOCFSERROR delta;
  157173. register FSERRPTR errorptr; /* => fserrors[] at column before current */
  157174. register JSAMPROW input_ptr;
  157175. register JSAMPROW output_ptr;
  157176. JSAMPROW colorindex_ci;
  157177. JSAMPROW colormap_ci;
  157178. int pixcode;
  157179. int nc = cinfo->out_color_components;
  157180. int dir; /* 1 for left-to-right, -1 for right-to-left */
  157181. int dirnc; /* dir * nc */
  157182. int ci;
  157183. int row;
  157184. JDIMENSION col;
  157185. JDIMENSION width = cinfo->output_width;
  157186. JSAMPLE *range_limit = cinfo->sample_range_limit;
  157187. SHIFT_TEMPS
  157188. for (row = 0; row < num_rows; row++) {
  157189. jzero_far((void FAR *) output_buf[row],
  157190. (size_t) (width * SIZEOF(JSAMPLE)));
  157191. for (ci = 0; ci < nc; ci++) {
  157192. input_ptr = input_buf[row] + ci;
  157193. output_ptr = output_buf[row];
  157194. if (cquantize->on_odd_row) {
  157195. input_ptr += (width-1) * nc; /* so point to rightmost pixel */
  157196. output_ptr += width-1;
  157197. dir = -1;
  157198. dirnc = -nc;
  157199. errorptr = cquantize->fserrors[ci] + (width+1); /* => entry after last column */
  157200. } else {
  157201. dir = 1;
  157202. dirnc = nc;
  157203. errorptr = cquantize->fserrors[ci]; /* => entry before first column */
  157204. }
  157205. colorindex_ci = cquantize->colorindex[ci];
  157206. colormap_ci = cquantize->sv_colormap[ci];
  157207. cur = 0;
  157208. belowerr = bpreverr = 0;
  157209. for (col = width; col > 0; col--) {
  157210. cur = RIGHT_SHIFT(cur + errorptr[dir] + 8, 4);
  157211. cur += GETJSAMPLE(*input_ptr);
  157212. cur = GETJSAMPLE(range_limit[cur]);
  157213. pixcode = GETJSAMPLE(colorindex_ci[cur]);
  157214. *output_ptr += (JSAMPLE) pixcode;
  157215. cur -= GETJSAMPLE(colormap_ci[pixcode]);
  157216. bnexterr = cur;
  157217. delta = cur * 2;
  157218. cur += delta; /* form error * 3 */
  157219. errorptr[0] = (FSERROR) (bpreverr + cur);
  157220. cur += delta; /* form error * 5 */
  157221. bpreverr = belowerr + cur;
  157222. belowerr = bnexterr;
  157223. cur += delta; /* form error * 7 */
  157224. input_ptr += dirnc; /* advance input ptr to next column */
  157225. output_ptr += dir; /* advance output ptr to next column */
  157226. errorptr += dir; /* advance errorptr to current column */
  157227. }
  157228. errorptr[0] = (FSERROR) bpreverr; /* unload prev err into array */
  157229. }
  157230. cquantize->on_odd_row = (cquantize->on_odd_row ? FALSE : TRUE);
  157231. }
  157232. }
  157233. LOCAL(void)
  157234. alloc_fs_workspace (j_decompress_ptr cinfo)
  157235. {
  157236. my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
  157237. size_t arraysize;
  157238. int i;
  157239. arraysize = (size_t) ((cinfo->output_width + 2) * SIZEOF(FSERROR));
  157240. for (i = 0; i < cinfo->out_color_components; i++) {
  157241. cquantize->fserrors[i] = (FSERRPTR)
  157242. (*cinfo->mem->alloc_large)((j_common_ptr) cinfo, JPOOL_IMAGE, arraysize);
  157243. }
  157244. }
  157245. METHODDEF(void)
  157246. start_pass_1_quant (j_decompress_ptr cinfo, boolean is_pre_scan)
  157247. {
  157248. my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
  157249. size_t arraysize;
  157250. int i;
  157251. cinfo->colormap = cquantize->sv_colormap;
  157252. cinfo->actual_number_of_colors = cquantize->sv_actual;
  157253. switch (cinfo->dither_mode) {
  157254. case JDITHER_NONE:
  157255. if (cinfo->out_color_components == 3)
  157256. cquantize->pub.color_quantize = color_quantize3;
  157257. else
  157258. cquantize->pub.color_quantize = color_quantize;
  157259. break;
  157260. case JDITHER_ORDERED:
  157261. if (cinfo->out_color_components == 3)
  157262. cquantize->pub.color_quantize = quantize3_ord_dither;
  157263. else
  157264. cquantize->pub.color_quantize = quantize_ord_dither;
  157265. cquantize->row_index = 0; /* initialize state for ordered dither */
  157266. if (! cquantize->is_padded)
  157267. create_colorindex(cinfo);
  157268. if (cquantize->odither[0] == NULL)
  157269. create_odither_tables(cinfo);
  157270. break;
  157271. case JDITHER_FS:
  157272. cquantize->pub.color_quantize = quantize_fs_dither;
  157273. cquantize->on_odd_row = FALSE; /* initialize state for F-S dither */
  157274. if (cquantize->fserrors[0] == NULL)
  157275. alloc_fs_workspace(cinfo);
  157276. arraysize = (size_t) ((cinfo->output_width + 2) * SIZEOF(FSERROR));
  157277. for (i = 0; i < cinfo->out_color_components; i++)
  157278. jzero_far((void FAR *) cquantize->fserrors[i], arraysize);
  157279. break;
  157280. default:
  157281. ERREXIT(cinfo, JERR_NOT_COMPILED);
  157282. break;
  157283. }
  157284. }
  157285. METHODDEF(void)
  157286. finish_pass_1_quant (j_decompress_ptr cinfo)
  157287. {
  157288. }
  157289. METHODDEF(void)
  157290. new_color_map_1_quant (j_decompress_ptr cinfo)
  157291. {
  157292. ERREXIT(cinfo, JERR_MODE_CHANGE);
  157293. }
  157294. GLOBAL(void)
  157295. jinit_1pass_quantizer (j_decompress_ptr cinfo)
  157296. {
  157297. my_cquantize_ptr cquantize;
  157298. cquantize = (my_cquantize_ptr)
  157299. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  157300. SIZEOF(my_cquantizer));
  157301. cinfo->cquantize = (struct jpeg_color_quantizer *) cquantize;
  157302. cquantize->pub.start_pass = start_pass_1_quant;
  157303. cquantize->pub.finish_pass = finish_pass_1_quant;
  157304. cquantize->pub.new_color_map = new_color_map_1_quant;
  157305. cquantize->fserrors[0] = NULL; /* Flag FS workspace not allocated */
  157306. cquantize->odither[0] = NULL; /* Also flag odither arrays not allocated */
  157307. if (cinfo->out_color_components > MAX_Q_COMPS)
  157308. ERREXIT1(cinfo, JERR_QUANT_COMPONENTS, MAX_Q_COMPS);
  157309. if (cinfo->desired_number_of_colors > (MAXJSAMPLE+1))
  157310. ERREXIT1(cinfo, JERR_QUANT_MANY_COLORS, MAXJSAMPLE+1);
  157311. create_colormap(cinfo);
  157312. create_colorindex(cinfo);
  157313. if (cinfo->dither_mode == JDITHER_FS)
  157314. alloc_fs_workspace(cinfo);
  157315. }
  157316. #endif /* QUANT_1PASS_SUPPORTED */
  157317. /*** End of inlined file: jquant1.c ***/
  157318. /*** Start of inlined file: jquant2.c ***/
  157319. #define JPEG_INTERNALS
  157320. #ifdef QUANT_2PASS_SUPPORTED
  157321. #define R_SCALE 2 /* scale R distances by this much */
  157322. #define G_SCALE 3 /* scale G distances by this much */
  157323. #define B_SCALE 1 /* and B by this much */
  157324. #if RGB_RED == 0
  157325. #define C0_SCALE R_SCALE
  157326. #endif
  157327. #if RGB_BLUE == 0
  157328. #define C0_SCALE B_SCALE
  157329. #endif
  157330. #if RGB_GREEN == 1
  157331. #define C1_SCALE G_SCALE
  157332. #endif
  157333. #if RGB_RED == 2
  157334. #define C2_SCALE R_SCALE
  157335. #endif
  157336. #if RGB_BLUE == 2
  157337. #define C2_SCALE B_SCALE
  157338. #endif
  157339. #define MAXNUMCOLORS (MAXJSAMPLE+1) /* maximum size of colormap */
  157340. #define HIST_C0_BITS 5 /* bits of precision in R/B histogram */
  157341. #define HIST_C1_BITS 6 /* bits of precision in G histogram */
  157342. #define HIST_C2_BITS 5 /* bits of precision in B/R histogram */
  157343. #define HIST_C0_ELEMS (1<<HIST_C0_BITS)
  157344. #define HIST_C1_ELEMS (1<<HIST_C1_BITS)
  157345. #define HIST_C2_ELEMS (1<<HIST_C2_BITS)
  157346. #define C0_SHIFT (BITS_IN_JSAMPLE-HIST_C0_BITS)
  157347. #define C1_SHIFT (BITS_IN_JSAMPLE-HIST_C1_BITS)
  157348. #define C2_SHIFT (BITS_IN_JSAMPLE-HIST_C2_BITS)
  157349. typedef UINT16 histcell; /* histogram cell; prefer an unsigned type */
  157350. typedef histcell FAR * histptr; /* for pointers to histogram cells */
  157351. typedef histcell hist1d[HIST_C2_ELEMS]; /* typedefs for the array */
  157352. typedef hist1d FAR * hist2d; /* type for the 2nd-level pointers */
  157353. typedef hist2d * hist3d; /* type for top-level pointer */
  157354. #if BITS_IN_JSAMPLE == 8
  157355. typedef INT16 FSERROR; /* 16 bits should be enough */
  157356. typedef int LOCFSERROR; /* use 'int' for calculation temps */
  157357. #else
  157358. typedef INT32 FSERROR; /* may need more than 16 bits */
  157359. typedef INT32 LOCFSERROR; /* be sure calculation temps are big enough */
  157360. #endif
  157361. typedef FSERROR FAR *FSERRPTR; /* pointer to error array (in FAR storage!) */
  157362. typedef struct {
  157363. struct jpeg_color_quantizer pub; /* public fields */
  157364. JSAMPARRAY sv_colormap; /* colormap allocated at init time */
  157365. int desired; /* desired # of colors = size of colormap */
  157366. hist3d histogram; /* pointer to the histogram */
  157367. boolean needs_zeroed; /* TRUE if next pass must zero histogram */
  157368. FSERRPTR fserrors; /* accumulated errors */
  157369. boolean on_odd_row; /* flag to remember which row we are on */
  157370. int * error_limiter; /* table for clamping the applied error */
  157371. } my_cquantizer2;
  157372. typedef my_cquantizer2 * my_cquantize_ptr2;
  157373. METHODDEF(void)
  157374. prescan_quantize (j_decompress_ptr cinfo, JSAMPARRAY input_buf,
  157375. JSAMPARRAY output_buf, int num_rows)
  157376. {
  157377. my_cquantize_ptr2 cquantize = (my_cquantize_ptr2) cinfo->cquantize;
  157378. register JSAMPROW ptr;
  157379. register histptr histp;
  157380. register hist3d histogram = cquantize->histogram;
  157381. int row;
  157382. JDIMENSION col;
  157383. JDIMENSION width = cinfo->output_width;
  157384. for (row = 0; row < num_rows; row++) {
  157385. ptr = input_buf[row];
  157386. for (col = width; col > 0; col--) {
  157387. histp = & histogram[GETJSAMPLE(ptr[0]) >> C0_SHIFT]
  157388. [GETJSAMPLE(ptr[1]) >> C1_SHIFT]
  157389. [GETJSAMPLE(ptr[2]) >> C2_SHIFT];
  157390. if (++(*histp) <= 0)
  157391. (*histp)--;
  157392. ptr += 3;
  157393. }
  157394. }
  157395. }
  157396. typedef struct {
  157397. int c0min, c0max;
  157398. int c1min, c1max;
  157399. int c2min, c2max;
  157400. INT32 volume;
  157401. long colorcount;
  157402. } box;
  157403. typedef box * boxptr;
  157404. LOCAL(boxptr)
  157405. find_biggest_color_pop (boxptr boxlist, int numboxes)
  157406. {
  157407. register boxptr boxp;
  157408. register int i;
  157409. register long maxc = 0;
  157410. boxptr which = NULL;
  157411. for (i = 0, boxp = boxlist; i < numboxes; i++, boxp++) {
  157412. if (boxp->colorcount > maxc && boxp->volume > 0) {
  157413. which = boxp;
  157414. maxc = boxp->colorcount;
  157415. }
  157416. }
  157417. return which;
  157418. }
  157419. LOCAL(boxptr)
  157420. find_biggest_volume (boxptr boxlist, int numboxes)
  157421. {
  157422. register boxptr boxp;
  157423. register int i;
  157424. register INT32 maxv = 0;
  157425. boxptr which = NULL;
  157426. for (i = 0, boxp = boxlist; i < numboxes; i++, boxp++) {
  157427. if (boxp->volume > maxv) {
  157428. which = boxp;
  157429. maxv = boxp->volume;
  157430. }
  157431. }
  157432. return which;
  157433. }
  157434. LOCAL(void)
  157435. update_box (j_decompress_ptr cinfo, boxptr boxp)
  157436. {
  157437. my_cquantize_ptr2 cquantize = (my_cquantize_ptr2) cinfo->cquantize;
  157438. hist3d histogram = cquantize->histogram;
  157439. histptr histp;
  157440. int c0,c1,c2;
  157441. int c0min,c0max,c1min,c1max,c2min,c2max;
  157442. INT32 dist0,dist1,dist2;
  157443. long ccount;
  157444. c0min = boxp->c0min; c0max = boxp->c0max;
  157445. c1min = boxp->c1min; c1max = boxp->c1max;
  157446. c2min = boxp->c2min; c2max = boxp->c2max;
  157447. if (c0max > c0min)
  157448. for (c0 = c0min; c0 <= c0max; c0++)
  157449. for (c1 = c1min; c1 <= c1max; c1++) {
  157450. histp = & histogram[c0][c1][c2min];
  157451. for (c2 = c2min; c2 <= c2max; c2++)
  157452. if (*histp++ != 0) {
  157453. boxp->c0min = c0min = c0;
  157454. goto have_c0min;
  157455. }
  157456. }
  157457. have_c0min:
  157458. if (c0max > c0min)
  157459. for (c0 = c0max; c0 >= c0min; c0--)
  157460. for (c1 = c1min; c1 <= c1max; c1++) {
  157461. histp = & histogram[c0][c1][c2min];
  157462. for (c2 = c2min; c2 <= c2max; c2++)
  157463. if (*histp++ != 0) {
  157464. boxp->c0max = c0max = c0;
  157465. goto have_c0max;
  157466. }
  157467. }
  157468. have_c0max:
  157469. if (c1max > c1min)
  157470. for (c1 = c1min; c1 <= c1max; c1++)
  157471. for (c0 = c0min; c0 <= c0max; c0++) {
  157472. histp = & histogram[c0][c1][c2min];
  157473. for (c2 = c2min; c2 <= c2max; c2++)
  157474. if (*histp++ != 0) {
  157475. boxp->c1min = c1min = c1;
  157476. goto have_c1min;
  157477. }
  157478. }
  157479. have_c1min:
  157480. if (c1max > c1min)
  157481. for (c1 = c1max; c1 >= c1min; c1--)
  157482. for (c0 = c0min; c0 <= c0max; c0++) {
  157483. histp = & histogram[c0][c1][c2min];
  157484. for (c2 = c2min; c2 <= c2max; c2++)
  157485. if (*histp++ != 0) {
  157486. boxp->c1max = c1max = c1;
  157487. goto have_c1max;
  157488. }
  157489. }
  157490. have_c1max:
  157491. if (c2max > c2min)
  157492. for (c2 = c2min; c2 <= c2max; c2++)
  157493. for (c0 = c0min; c0 <= c0max; c0++) {
  157494. histp = & histogram[c0][c1min][c2];
  157495. for (c1 = c1min; c1 <= c1max; c1++, histp += HIST_C2_ELEMS)
  157496. if (*histp != 0) {
  157497. boxp->c2min = c2min = c2;
  157498. goto have_c2min;
  157499. }
  157500. }
  157501. have_c2min:
  157502. if (c2max > c2min)
  157503. for (c2 = c2max; c2 >= c2min; c2--)
  157504. for (c0 = c0min; c0 <= c0max; c0++) {
  157505. histp = & histogram[c0][c1min][c2];
  157506. for (c1 = c1min; c1 <= c1max; c1++, histp += HIST_C2_ELEMS)
  157507. if (*histp != 0) {
  157508. boxp->c2max = c2max = c2;
  157509. goto have_c2max;
  157510. }
  157511. }
  157512. have_c2max:
  157513. dist0 = ((c0max - c0min) << C0_SHIFT) * C0_SCALE;
  157514. dist1 = ((c1max - c1min) << C1_SHIFT) * C1_SCALE;
  157515. dist2 = ((c2max - c2min) << C2_SHIFT) * C2_SCALE;
  157516. boxp->volume = dist0*dist0 + dist1*dist1 + dist2*dist2;
  157517. ccount = 0;
  157518. for (c0 = c0min; c0 <= c0max; c0++)
  157519. for (c1 = c1min; c1 <= c1max; c1++) {
  157520. histp = & histogram[c0][c1][c2min];
  157521. for (c2 = c2min; c2 <= c2max; c2++, histp++)
  157522. if (*histp != 0) {
  157523. ccount++;
  157524. }
  157525. }
  157526. boxp->colorcount = ccount;
  157527. }
  157528. LOCAL(int)
  157529. median_cut (j_decompress_ptr cinfo, boxptr boxlist, int numboxes,
  157530. int desired_colors)
  157531. {
  157532. int n,lb;
  157533. int c0,c1,c2,cmax;
  157534. register boxptr b1,b2;
  157535. while (numboxes < desired_colors) {
  157536. if (numboxes*2 <= desired_colors) {
  157537. b1 = find_biggest_color_pop(boxlist, numboxes);
  157538. } else {
  157539. b1 = find_biggest_volume(boxlist, numboxes);
  157540. }
  157541. if (b1 == NULL) /* no splittable boxes left! */
  157542. break;
  157543. b2 = &boxlist[numboxes]; /* where new box will go */
  157544. b2->c0max = b1->c0max; b2->c1max = b1->c1max; b2->c2max = b1->c2max;
  157545. b2->c0min = b1->c0min; b2->c1min = b1->c1min; b2->c2min = b1->c2min;
  157546. c0 = ((b1->c0max - b1->c0min) << C0_SHIFT) * C0_SCALE;
  157547. c1 = ((b1->c1max - b1->c1min) << C1_SHIFT) * C1_SCALE;
  157548. c2 = ((b1->c2max - b1->c2min) << C2_SHIFT) * C2_SCALE;
  157549. #if RGB_RED == 0
  157550. cmax = c1; n = 1;
  157551. if (c0 > cmax) { cmax = c0; n = 0; }
  157552. if (c2 > cmax) { n = 2; }
  157553. #else
  157554. cmax = c1; n = 1;
  157555. if (c2 > cmax) { cmax = c2; n = 2; }
  157556. if (c0 > cmax) { n = 0; }
  157557. #endif
  157558. switch (n) {
  157559. case 0:
  157560. lb = (b1->c0max + b1->c0min) / 2;
  157561. b1->c0max = lb;
  157562. b2->c0min = lb+1;
  157563. break;
  157564. case 1:
  157565. lb = (b1->c1max + b1->c1min) / 2;
  157566. b1->c1max = lb;
  157567. b2->c1min = lb+1;
  157568. break;
  157569. case 2:
  157570. lb = (b1->c2max + b1->c2min) / 2;
  157571. b1->c2max = lb;
  157572. b2->c2min = lb+1;
  157573. break;
  157574. }
  157575. update_box(cinfo, b1);
  157576. update_box(cinfo, b2);
  157577. numboxes++;
  157578. }
  157579. return numboxes;
  157580. }
  157581. LOCAL(void)
  157582. compute_color (j_decompress_ptr cinfo, boxptr boxp, int icolor)
  157583. {
  157584. my_cquantize_ptr2 cquantize = (my_cquantize_ptr2) cinfo->cquantize;
  157585. hist3d histogram = cquantize->histogram;
  157586. histptr histp;
  157587. int c0,c1,c2;
  157588. int c0min,c0max,c1min,c1max,c2min,c2max;
  157589. long count;
  157590. long total = 0;
  157591. long c0total = 0;
  157592. long c1total = 0;
  157593. long c2total = 0;
  157594. c0min = boxp->c0min; c0max = boxp->c0max;
  157595. c1min = boxp->c1min; c1max = boxp->c1max;
  157596. c2min = boxp->c2min; c2max = boxp->c2max;
  157597. for (c0 = c0min; c0 <= c0max; c0++)
  157598. for (c1 = c1min; c1 <= c1max; c1++) {
  157599. histp = & histogram[c0][c1][c2min];
  157600. for (c2 = c2min; c2 <= c2max; c2++) {
  157601. if ((count = *histp++) != 0) {
  157602. total += count;
  157603. c0total += ((c0 << C0_SHIFT) + ((1<<C0_SHIFT)>>1)) * count;
  157604. c1total += ((c1 << C1_SHIFT) + ((1<<C1_SHIFT)>>1)) * count;
  157605. c2total += ((c2 << C2_SHIFT) + ((1<<C2_SHIFT)>>1)) * count;
  157606. }
  157607. }
  157608. }
  157609. cinfo->colormap[0][icolor] = (JSAMPLE) ((c0total + (total>>1)) / total);
  157610. cinfo->colormap[1][icolor] = (JSAMPLE) ((c1total + (total>>1)) / total);
  157611. cinfo->colormap[2][icolor] = (JSAMPLE) ((c2total + (total>>1)) / total);
  157612. }
  157613. LOCAL(void)
  157614. select_colors (j_decompress_ptr cinfo, int desired_colors)
  157615. {
  157616. boxptr boxlist;
  157617. int numboxes;
  157618. int i;
  157619. boxlist = (boxptr) (*cinfo->mem->alloc_small)
  157620. ((j_common_ptr) cinfo, JPOOL_IMAGE, desired_colors * SIZEOF(box));
  157621. numboxes = 1;
  157622. boxlist[0].c0min = 0;
  157623. boxlist[0].c0max = MAXJSAMPLE >> C0_SHIFT;
  157624. boxlist[0].c1min = 0;
  157625. boxlist[0].c1max = MAXJSAMPLE >> C1_SHIFT;
  157626. boxlist[0].c2min = 0;
  157627. boxlist[0].c2max = MAXJSAMPLE >> C2_SHIFT;
  157628. update_box(cinfo, & boxlist[0]);
  157629. numboxes = median_cut(cinfo, boxlist, numboxes, desired_colors);
  157630. for (i = 0; i < numboxes; i++)
  157631. compute_color(cinfo, & boxlist[i], i);
  157632. cinfo->actual_number_of_colors = numboxes;
  157633. TRACEMS1(cinfo, 1, JTRC_QUANT_SELECTED, numboxes);
  157634. }
  157635. #define BOX_C0_LOG (HIST_C0_BITS-3)
  157636. #define BOX_C1_LOG (HIST_C1_BITS-3)
  157637. #define BOX_C2_LOG (HIST_C2_BITS-3)
  157638. #define BOX_C0_ELEMS (1<<BOX_C0_LOG) /* # of hist cells in update box */
  157639. #define BOX_C1_ELEMS (1<<BOX_C1_LOG)
  157640. #define BOX_C2_ELEMS (1<<BOX_C2_LOG)
  157641. #define BOX_C0_SHIFT (C0_SHIFT + BOX_C0_LOG)
  157642. #define BOX_C1_SHIFT (C1_SHIFT + BOX_C1_LOG)
  157643. #define BOX_C2_SHIFT (C2_SHIFT + BOX_C2_LOG)
  157644. LOCAL(int)
  157645. find_nearby_colors (j_decompress_ptr cinfo, int minc0, int minc1, int minc2,
  157646. JSAMPLE colorlist[])
  157647. {
  157648. int numcolors = cinfo->actual_number_of_colors;
  157649. int maxc0, maxc1, maxc2;
  157650. int centerc0, centerc1, centerc2;
  157651. int i, x, ncolors;
  157652. INT32 minmaxdist, min_dist, max_dist, tdist;
  157653. INT32 mindist[MAXNUMCOLORS]; /* min distance to colormap entry i */
  157654. maxc0 = minc0 + ((1 << BOX_C0_SHIFT) - (1 << C0_SHIFT));
  157655. centerc0 = (minc0 + maxc0) >> 1;
  157656. maxc1 = minc1 + ((1 << BOX_C1_SHIFT) - (1 << C1_SHIFT));
  157657. centerc1 = (minc1 + maxc1) >> 1;
  157658. maxc2 = minc2 + ((1 << BOX_C2_SHIFT) - (1 << C2_SHIFT));
  157659. centerc2 = (minc2 + maxc2) >> 1;
  157660. minmaxdist = 0x7FFFFFFFL;
  157661. for (i = 0; i < numcolors; i++) {
  157662. x = GETJSAMPLE(cinfo->colormap[0][i]);
  157663. if (x < minc0) {
  157664. tdist = (x - minc0) * C0_SCALE;
  157665. min_dist = tdist*tdist;
  157666. tdist = (x - maxc0) * C0_SCALE;
  157667. max_dist = tdist*tdist;
  157668. } else if (x > maxc0) {
  157669. tdist = (x - maxc0) * C0_SCALE;
  157670. min_dist = tdist*tdist;
  157671. tdist = (x - minc0) * C0_SCALE;
  157672. max_dist = tdist*tdist;
  157673. } else {
  157674. min_dist = 0;
  157675. if (x <= centerc0) {
  157676. tdist = (x - maxc0) * C0_SCALE;
  157677. max_dist = tdist*tdist;
  157678. } else {
  157679. tdist = (x - minc0) * C0_SCALE;
  157680. max_dist = tdist*tdist;
  157681. }
  157682. }
  157683. x = GETJSAMPLE(cinfo->colormap[1][i]);
  157684. if (x < minc1) {
  157685. tdist = (x - minc1) * C1_SCALE;
  157686. min_dist += tdist*tdist;
  157687. tdist = (x - maxc1) * C1_SCALE;
  157688. max_dist += tdist*tdist;
  157689. } else if (x > maxc1) {
  157690. tdist = (x - maxc1) * C1_SCALE;
  157691. min_dist += tdist*tdist;
  157692. tdist = (x - minc1) * C1_SCALE;
  157693. max_dist += tdist*tdist;
  157694. } else {
  157695. if (x <= centerc1) {
  157696. tdist = (x - maxc1) * C1_SCALE;
  157697. max_dist += tdist*tdist;
  157698. } else {
  157699. tdist = (x - minc1) * C1_SCALE;
  157700. max_dist += tdist*tdist;
  157701. }
  157702. }
  157703. x = GETJSAMPLE(cinfo->colormap[2][i]);
  157704. if (x < minc2) {
  157705. tdist = (x - minc2) * C2_SCALE;
  157706. min_dist += tdist*tdist;
  157707. tdist = (x - maxc2) * C2_SCALE;
  157708. max_dist += tdist*tdist;
  157709. } else if (x > maxc2) {
  157710. tdist = (x - maxc2) * C2_SCALE;
  157711. min_dist += tdist*tdist;
  157712. tdist = (x - minc2) * C2_SCALE;
  157713. max_dist += tdist*tdist;
  157714. } else {
  157715. if (x <= centerc2) {
  157716. tdist = (x - maxc2) * C2_SCALE;
  157717. max_dist += tdist*tdist;
  157718. } else {
  157719. tdist = (x - minc2) * C2_SCALE;
  157720. max_dist += tdist*tdist;
  157721. }
  157722. }
  157723. mindist[i] = min_dist; /* save away the results */
  157724. if (max_dist < minmaxdist)
  157725. minmaxdist = max_dist;
  157726. }
  157727. ncolors = 0;
  157728. for (i = 0; i < numcolors; i++) {
  157729. if (mindist[i] <= minmaxdist)
  157730. colorlist[ncolors++] = (JSAMPLE) i;
  157731. }
  157732. return ncolors;
  157733. }
  157734. LOCAL(void)
  157735. find_best_colors (j_decompress_ptr cinfo, int minc0, int minc1, int minc2,
  157736. int numcolors, JSAMPLE colorlist[], JSAMPLE bestcolor[])
  157737. {
  157738. int ic0, ic1, ic2;
  157739. int i, icolor;
  157740. register INT32 * bptr; /* pointer into bestdist[] array */
  157741. JSAMPLE * cptr; /* pointer into bestcolor[] array */
  157742. INT32 dist0, dist1; /* initial distance values */
  157743. register INT32 dist2; /* current distance in inner loop */
  157744. INT32 xx0, xx1; /* distance increments */
  157745. register INT32 xx2;
  157746. INT32 inc0, inc1, inc2; /* initial values for increments */
  157747. INT32 bestdist[BOX_C0_ELEMS * BOX_C1_ELEMS * BOX_C2_ELEMS];
  157748. bptr = bestdist;
  157749. for (i = BOX_C0_ELEMS*BOX_C1_ELEMS*BOX_C2_ELEMS-1; i >= 0; i--)
  157750. *bptr++ = 0x7FFFFFFFL;
  157751. #define STEP_C0 ((1 << C0_SHIFT) * C0_SCALE)
  157752. #define STEP_C1 ((1 << C1_SHIFT) * C1_SCALE)
  157753. #define STEP_C2 ((1 << C2_SHIFT) * C2_SCALE)
  157754. for (i = 0; i < numcolors; i++) {
  157755. icolor = GETJSAMPLE(colorlist[i]);
  157756. inc0 = (minc0 - GETJSAMPLE(cinfo->colormap[0][icolor])) * C0_SCALE;
  157757. dist0 = inc0*inc0;
  157758. inc1 = (minc1 - GETJSAMPLE(cinfo->colormap[1][icolor])) * C1_SCALE;
  157759. dist0 += inc1*inc1;
  157760. inc2 = (minc2 - GETJSAMPLE(cinfo->colormap[2][icolor])) * C2_SCALE;
  157761. dist0 += inc2*inc2;
  157762. inc0 = inc0 * (2 * STEP_C0) + STEP_C0 * STEP_C0;
  157763. inc1 = inc1 * (2 * STEP_C1) + STEP_C1 * STEP_C1;
  157764. inc2 = inc2 * (2 * STEP_C2) + STEP_C2 * STEP_C2;
  157765. bptr = bestdist;
  157766. cptr = bestcolor;
  157767. xx0 = inc0;
  157768. for (ic0 = BOX_C0_ELEMS-1; ic0 >= 0; ic0--) {
  157769. dist1 = dist0;
  157770. xx1 = inc1;
  157771. for (ic1 = BOX_C1_ELEMS-1; ic1 >= 0; ic1--) {
  157772. dist2 = dist1;
  157773. xx2 = inc2;
  157774. for (ic2 = BOX_C2_ELEMS-1; ic2 >= 0; ic2--) {
  157775. if (dist2 < *bptr) {
  157776. *bptr = dist2;
  157777. *cptr = (JSAMPLE) icolor;
  157778. }
  157779. dist2 += xx2;
  157780. xx2 += 2 * STEP_C2 * STEP_C2;
  157781. bptr++;
  157782. cptr++;
  157783. }
  157784. dist1 += xx1;
  157785. xx1 += 2 * STEP_C1 * STEP_C1;
  157786. }
  157787. dist0 += xx0;
  157788. xx0 += 2 * STEP_C0 * STEP_C0;
  157789. }
  157790. }
  157791. }
  157792. LOCAL(void)
  157793. fill_inverse_cmap (j_decompress_ptr cinfo, int c0, int c1, int c2)
  157794. {
  157795. my_cquantize_ptr2 cquantize = (my_cquantize_ptr2) cinfo->cquantize;
  157796. hist3d histogram = cquantize->histogram;
  157797. int minc0, minc1, minc2; /* lower left corner of update box */
  157798. int ic0, ic1, ic2;
  157799. register JSAMPLE * cptr; /* pointer into bestcolor[] array */
  157800. register histptr cachep; /* pointer into main cache array */
  157801. JSAMPLE colorlist[MAXNUMCOLORS];
  157802. int numcolors; /* number of candidate colors */
  157803. JSAMPLE bestcolor[BOX_C0_ELEMS * BOX_C1_ELEMS * BOX_C2_ELEMS];
  157804. c0 >>= BOX_C0_LOG;
  157805. c1 >>= BOX_C1_LOG;
  157806. c2 >>= BOX_C2_LOG;
  157807. minc0 = (c0 << BOX_C0_SHIFT) + ((1 << C0_SHIFT) >> 1);
  157808. minc1 = (c1 << BOX_C1_SHIFT) + ((1 << C1_SHIFT) >> 1);
  157809. minc2 = (c2 << BOX_C2_SHIFT) + ((1 << C2_SHIFT) >> 1);
  157810. numcolors = find_nearby_colors(cinfo, minc0, minc1, minc2, colorlist);
  157811. find_best_colors(cinfo, minc0, minc1, minc2, numcolors, colorlist,
  157812. bestcolor);
  157813. c0 <<= BOX_C0_LOG; /* convert ID back to base cell indexes */
  157814. c1 <<= BOX_C1_LOG;
  157815. c2 <<= BOX_C2_LOG;
  157816. cptr = bestcolor;
  157817. for (ic0 = 0; ic0 < BOX_C0_ELEMS; ic0++) {
  157818. for (ic1 = 0; ic1 < BOX_C1_ELEMS; ic1++) {
  157819. cachep = & histogram[c0+ic0][c1+ic1][c2];
  157820. for (ic2 = 0; ic2 < BOX_C2_ELEMS; ic2++) {
  157821. *cachep++ = (histcell) (GETJSAMPLE(*cptr++) + 1);
  157822. }
  157823. }
  157824. }
  157825. }
  157826. METHODDEF(void)
  157827. pass2_no_dither (j_decompress_ptr cinfo,
  157828. JSAMPARRAY input_buf, JSAMPARRAY output_buf, int num_rows)
  157829. {
  157830. my_cquantize_ptr2 cquantize = (my_cquantize_ptr2) cinfo->cquantize;
  157831. hist3d histogram = cquantize->histogram;
  157832. register JSAMPROW inptr, outptr;
  157833. register histptr cachep;
  157834. register int c0, c1, c2;
  157835. int row;
  157836. JDIMENSION col;
  157837. JDIMENSION width = cinfo->output_width;
  157838. for (row = 0; row < num_rows; row++) {
  157839. inptr = input_buf[row];
  157840. outptr = output_buf[row];
  157841. for (col = width; col > 0; col--) {
  157842. c0 = GETJSAMPLE(*inptr++) >> C0_SHIFT;
  157843. c1 = GETJSAMPLE(*inptr++) >> C1_SHIFT;
  157844. c2 = GETJSAMPLE(*inptr++) >> C2_SHIFT;
  157845. cachep = & histogram[c0][c1][c2];
  157846. if (*cachep == 0)
  157847. fill_inverse_cmap(cinfo, c0,c1,c2);
  157848. *outptr++ = (JSAMPLE) (*cachep - 1);
  157849. }
  157850. }
  157851. }
  157852. METHODDEF(void)
  157853. pass2_fs_dither (j_decompress_ptr cinfo,
  157854. JSAMPARRAY input_buf, JSAMPARRAY output_buf, int num_rows)
  157855. {
  157856. my_cquantize_ptr2 cquantize = (my_cquantize_ptr2) cinfo->cquantize;
  157857. hist3d histogram = cquantize->histogram;
  157858. register LOCFSERROR cur0, cur1, cur2; /* current error or pixel value */
  157859. LOCFSERROR belowerr0, belowerr1, belowerr2; /* error for pixel below cur */
  157860. LOCFSERROR bpreverr0, bpreverr1, bpreverr2; /* error for below/prev col */
  157861. register FSERRPTR errorptr; /* => fserrors[] at column before current */
  157862. JSAMPROW inptr; /* => current input pixel */
  157863. JSAMPROW outptr; /* => current output pixel */
  157864. histptr cachep;
  157865. int dir; /* +1 or -1 depending on direction */
  157866. int dir3; /* 3*dir, for advancing inptr & errorptr */
  157867. int row;
  157868. JDIMENSION col;
  157869. JDIMENSION width = cinfo->output_width;
  157870. JSAMPLE *range_limit = cinfo->sample_range_limit;
  157871. int *error_limit = cquantize->error_limiter;
  157872. JSAMPROW colormap0 = cinfo->colormap[0];
  157873. JSAMPROW colormap1 = cinfo->colormap[1];
  157874. JSAMPROW colormap2 = cinfo->colormap[2];
  157875. SHIFT_TEMPS
  157876. for (row = 0; row < num_rows; row++) {
  157877. inptr = input_buf[row];
  157878. outptr = output_buf[row];
  157879. if (cquantize->on_odd_row) {
  157880. inptr += (width-1) * 3; /* so point to rightmost pixel */
  157881. outptr += width-1;
  157882. dir = -1;
  157883. dir3 = -3;
  157884. errorptr = cquantize->fserrors + (width+1)*3; /* => entry after last column */
  157885. cquantize->on_odd_row = FALSE; /* flip for next time */
  157886. } else {
  157887. dir = 1;
  157888. dir3 = 3;
  157889. errorptr = cquantize->fserrors; /* => entry before first real column */
  157890. cquantize->on_odd_row = TRUE; /* flip for next time */
  157891. }
  157892. cur0 = cur1 = cur2 = 0;
  157893. belowerr0 = belowerr1 = belowerr2 = 0;
  157894. bpreverr0 = bpreverr1 = bpreverr2 = 0;
  157895. for (col = width; col > 0; col--) {
  157896. cur0 = RIGHT_SHIFT(cur0 + errorptr[dir3+0] + 8, 4);
  157897. cur1 = RIGHT_SHIFT(cur1 + errorptr[dir3+1] + 8, 4);
  157898. cur2 = RIGHT_SHIFT(cur2 + errorptr[dir3+2] + 8, 4);
  157899. cur0 = error_limit[cur0];
  157900. cur1 = error_limit[cur1];
  157901. cur2 = error_limit[cur2];
  157902. cur0 += GETJSAMPLE(inptr[0]);
  157903. cur1 += GETJSAMPLE(inptr[1]);
  157904. cur2 += GETJSAMPLE(inptr[2]);
  157905. cur0 = GETJSAMPLE(range_limit[cur0]);
  157906. cur1 = GETJSAMPLE(range_limit[cur1]);
  157907. cur2 = GETJSAMPLE(range_limit[cur2]);
  157908. cachep = & histogram[cur0>>C0_SHIFT][cur1>>C1_SHIFT][cur2>>C2_SHIFT];
  157909. if (*cachep == 0)
  157910. fill_inverse_cmap(cinfo, cur0>>C0_SHIFT,cur1>>C1_SHIFT,cur2>>C2_SHIFT);
  157911. { register int pixcode = *cachep - 1;
  157912. *outptr = (JSAMPLE) pixcode;
  157913. cur0 -= GETJSAMPLE(colormap0[pixcode]);
  157914. cur1 -= GETJSAMPLE(colormap1[pixcode]);
  157915. cur2 -= GETJSAMPLE(colormap2[pixcode]);
  157916. }
  157917. { register LOCFSERROR bnexterr, delta;
  157918. bnexterr = cur0; /* Process component 0 */
  157919. delta = cur0 * 2;
  157920. cur0 += delta; /* form error * 3 */
  157921. errorptr[0] = (FSERROR) (bpreverr0 + cur0);
  157922. cur0 += delta; /* form error * 5 */
  157923. bpreverr0 = belowerr0 + cur0;
  157924. belowerr0 = bnexterr;
  157925. cur0 += delta; /* form error * 7 */
  157926. bnexterr = cur1; /* Process component 1 */
  157927. delta = cur1 * 2;
  157928. cur1 += delta; /* form error * 3 */
  157929. errorptr[1] = (FSERROR) (bpreverr1 + cur1);
  157930. cur1 += delta; /* form error * 5 */
  157931. bpreverr1 = belowerr1 + cur1;
  157932. belowerr1 = bnexterr;
  157933. cur1 += delta; /* form error * 7 */
  157934. bnexterr = cur2; /* Process component 2 */
  157935. delta = cur2 * 2;
  157936. cur2 += delta; /* form error * 3 */
  157937. errorptr[2] = (FSERROR) (bpreverr2 + cur2);
  157938. cur2 += delta; /* form error * 5 */
  157939. bpreverr2 = belowerr2 + cur2;
  157940. belowerr2 = bnexterr;
  157941. cur2 += delta; /* form error * 7 */
  157942. }
  157943. inptr += dir3; /* Advance pixel pointers to next column */
  157944. outptr += dir;
  157945. errorptr += dir3; /* advance errorptr to current column */
  157946. }
  157947. errorptr[0] = (FSERROR) bpreverr0; /* unload prev errs into array */
  157948. errorptr[1] = (FSERROR) bpreverr1;
  157949. errorptr[2] = (FSERROR) bpreverr2;
  157950. }
  157951. }
  157952. LOCAL(void)
  157953. init_error_limit (j_decompress_ptr cinfo)
  157954. {
  157955. my_cquantize_ptr2 cquantize = (my_cquantize_ptr2) cinfo->cquantize;
  157956. int * table;
  157957. int in, out;
  157958. table = (int *) (*cinfo->mem->alloc_small)
  157959. ((j_common_ptr) cinfo, JPOOL_IMAGE, (MAXJSAMPLE*2+1) * SIZEOF(int));
  157960. table += MAXJSAMPLE; /* so can index -MAXJSAMPLE .. +MAXJSAMPLE */
  157961. cquantize->error_limiter = table;
  157962. #define STEPSIZE ((MAXJSAMPLE+1)/16)
  157963. out = 0;
  157964. for (in = 0; in < STEPSIZE; in++, out++) {
  157965. table[in] = out; table[-in] = -out;
  157966. }
  157967. for (; in < STEPSIZE*3; in++, out += (in&1) ? 0 : 1) {
  157968. table[in] = out; table[-in] = -out;
  157969. }
  157970. for (; in <= MAXJSAMPLE; in++) {
  157971. table[in] = out; table[-in] = -out;
  157972. }
  157973. #undef STEPSIZE
  157974. }
  157975. METHODDEF(void)
  157976. finish_pass1 (j_decompress_ptr cinfo)
  157977. {
  157978. my_cquantize_ptr2 cquantize = (my_cquantize_ptr2) cinfo->cquantize;
  157979. cinfo->colormap = cquantize->sv_colormap;
  157980. select_colors(cinfo, cquantize->desired);
  157981. cquantize->needs_zeroed = TRUE;
  157982. }
  157983. METHODDEF(void)
  157984. finish_pass2 (j_decompress_ptr cinfo)
  157985. {
  157986. }
  157987. METHODDEF(void)
  157988. start_pass_2_quant (j_decompress_ptr cinfo, boolean is_pre_scan)
  157989. {
  157990. my_cquantize_ptr2 cquantize = (my_cquantize_ptr2) cinfo->cquantize;
  157991. hist3d histogram = cquantize->histogram;
  157992. int i;
  157993. if (cinfo->dither_mode != JDITHER_NONE)
  157994. cinfo->dither_mode = JDITHER_FS;
  157995. if (is_pre_scan) {
  157996. cquantize->pub.color_quantize = prescan_quantize;
  157997. cquantize->pub.finish_pass = finish_pass1;
  157998. cquantize->needs_zeroed = TRUE; /* Always zero histogram */
  157999. } else {
  158000. if (cinfo->dither_mode == JDITHER_FS)
  158001. cquantize->pub.color_quantize = pass2_fs_dither;
  158002. else
  158003. cquantize->pub.color_quantize = pass2_no_dither;
  158004. cquantize->pub.finish_pass = finish_pass2;
  158005. i = cinfo->actual_number_of_colors;
  158006. if (i < 1)
  158007. ERREXIT1(cinfo, JERR_QUANT_FEW_COLORS, 1);
  158008. if (i > MAXNUMCOLORS)
  158009. ERREXIT1(cinfo, JERR_QUANT_MANY_COLORS, MAXNUMCOLORS);
  158010. if (cinfo->dither_mode == JDITHER_FS) {
  158011. size_t arraysize = (size_t) ((cinfo->output_width + 2) *
  158012. (3 * SIZEOF(FSERROR)));
  158013. if (cquantize->fserrors == NULL)
  158014. cquantize->fserrors = (FSERRPTR) (*cinfo->mem->alloc_large)
  158015. ((j_common_ptr) cinfo, JPOOL_IMAGE, arraysize);
  158016. jzero_far((void FAR *) cquantize->fserrors, arraysize);
  158017. if (cquantize->error_limiter == NULL)
  158018. init_error_limit(cinfo);
  158019. cquantize->on_odd_row = FALSE;
  158020. }
  158021. }
  158022. if (cquantize->needs_zeroed) {
  158023. for (i = 0; i < HIST_C0_ELEMS; i++) {
  158024. jzero_far((void FAR *) histogram[i],
  158025. HIST_C1_ELEMS*HIST_C2_ELEMS * SIZEOF(histcell));
  158026. }
  158027. cquantize->needs_zeroed = FALSE;
  158028. }
  158029. }
  158030. METHODDEF(void)
  158031. new_color_map_2_quant (j_decompress_ptr cinfo)
  158032. {
  158033. my_cquantize_ptr2 cquantize = (my_cquantize_ptr2) cinfo->cquantize;
  158034. cquantize->needs_zeroed = TRUE;
  158035. }
  158036. GLOBAL(void)
  158037. jinit_2pass_quantizer (j_decompress_ptr cinfo)
  158038. {
  158039. my_cquantize_ptr2 cquantize;
  158040. int i;
  158041. cquantize = (my_cquantize_ptr2)
  158042. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  158043. SIZEOF(my_cquantizer2));
  158044. cinfo->cquantize = (struct jpeg_color_quantizer *) cquantize;
  158045. cquantize->pub.start_pass = start_pass_2_quant;
  158046. cquantize->pub.new_color_map = new_color_map_2_quant;
  158047. cquantize->fserrors = NULL; /* flag optional arrays not allocated */
  158048. cquantize->error_limiter = NULL;
  158049. if (cinfo->out_color_components != 3)
  158050. ERREXIT(cinfo, JERR_NOTIMPL);
  158051. cquantize->histogram = (hist3d) (*cinfo->mem->alloc_small)
  158052. ((j_common_ptr) cinfo, JPOOL_IMAGE, HIST_C0_ELEMS * SIZEOF(hist2d));
  158053. for (i = 0; i < HIST_C0_ELEMS; i++) {
  158054. cquantize->histogram[i] = (hist2d) (*cinfo->mem->alloc_large)
  158055. ((j_common_ptr) cinfo, JPOOL_IMAGE,
  158056. HIST_C1_ELEMS*HIST_C2_ELEMS * SIZEOF(histcell));
  158057. }
  158058. cquantize->needs_zeroed = TRUE; /* histogram is garbage now */
  158059. if (cinfo->enable_2pass_quant) {
  158060. int desired = cinfo->desired_number_of_colors;
  158061. if (desired < 8)
  158062. ERREXIT1(cinfo, JERR_QUANT_FEW_COLORS, 8);
  158063. if (desired > MAXNUMCOLORS)
  158064. ERREXIT1(cinfo, JERR_QUANT_MANY_COLORS, MAXNUMCOLORS);
  158065. cquantize->sv_colormap = (*cinfo->mem->alloc_sarray)
  158066. ((j_common_ptr) cinfo,JPOOL_IMAGE, (JDIMENSION) desired, (JDIMENSION) 3);
  158067. cquantize->desired = desired;
  158068. } else
  158069. cquantize->sv_colormap = NULL;
  158070. if (cinfo->dither_mode != JDITHER_NONE)
  158071. cinfo->dither_mode = JDITHER_FS;
  158072. if (cinfo->dither_mode == JDITHER_FS) {
  158073. cquantize->fserrors = (FSERRPTR) (*cinfo->mem->alloc_large)
  158074. ((j_common_ptr) cinfo, JPOOL_IMAGE,
  158075. (size_t) ((cinfo->output_width + 2) * (3 * SIZEOF(FSERROR))));
  158076. init_error_limit(cinfo);
  158077. }
  158078. }
  158079. #endif /* QUANT_2PASS_SUPPORTED */
  158080. /*** End of inlined file: jquant2.c ***/
  158081. /*** Start of inlined file: jutils.c ***/
  158082. #define JPEG_INTERNALS
  158083. #if 0 /* This table is not actually needed in v6a */
  158084. const int jpeg_zigzag_order[DCTSIZE2] = {
  158085. 0, 1, 5, 6, 14, 15, 27, 28,
  158086. 2, 4, 7, 13, 16, 26, 29, 42,
  158087. 3, 8, 12, 17, 25, 30, 41, 43,
  158088. 9, 11, 18, 24, 31, 40, 44, 53,
  158089. 10, 19, 23, 32, 39, 45, 52, 54,
  158090. 20, 22, 33, 38, 46, 51, 55, 60,
  158091. 21, 34, 37, 47, 50, 56, 59, 61,
  158092. 35, 36, 48, 49, 57, 58, 62, 63
  158093. };
  158094. #endif
  158095. const int jpeg_natural_order[DCTSIZE2+16] = {
  158096. 0, 1, 8, 16, 9, 2, 3, 10,
  158097. 17, 24, 32, 25, 18, 11, 4, 5,
  158098. 12, 19, 26, 33, 40, 48, 41, 34,
  158099. 27, 20, 13, 6, 7, 14, 21, 28,
  158100. 35, 42, 49, 56, 57, 50, 43, 36,
  158101. 29, 22, 15, 23, 30, 37, 44, 51,
  158102. 58, 59, 52, 45, 38, 31, 39, 46,
  158103. 53, 60, 61, 54, 47, 55, 62, 63,
  158104. 63, 63, 63, 63, 63, 63, 63, 63, /* extra entries for safety in decoder */
  158105. 63, 63, 63, 63, 63, 63, 63, 63
  158106. };
  158107. GLOBAL(long)
  158108. jdiv_round_up (long a, long b)
  158109. {
  158110. return (a + b - 1L) / b;
  158111. }
  158112. GLOBAL(long)
  158113. jround_up (long a, long b)
  158114. {
  158115. a += b - 1L;
  158116. return a - (a % b);
  158117. }
  158118. #ifndef NEED_FAR_POINTERS /* normal case, same as regular macros */
  158119. #define FMEMCOPY(dest,src,size) MEMCOPY(dest,src,size)
  158120. #define FMEMZERO(target,size) MEMZERO(target,size)
  158121. #else /* 80x86 case, define if we can */
  158122. #ifdef USE_FMEM
  158123. #define FMEMCOPY(dest,src,size) _fmemcpy((void FAR *)(dest), (const void FAR *)(src), (size_t)(size))
  158124. #define FMEMZERO(target,size) _fmemset((void FAR *)(target), 0, (size_t)(size))
  158125. #endif
  158126. #endif
  158127. GLOBAL(void)
  158128. jcopy_sample_rows (JSAMPARRAY input_array, int source_row,
  158129. JSAMPARRAY output_array, int dest_row,
  158130. int num_rows, JDIMENSION num_cols)
  158131. {
  158132. register JSAMPROW inptr, outptr;
  158133. #ifdef FMEMCOPY
  158134. register size_t count = (size_t) (num_cols * SIZEOF(JSAMPLE));
  158135. #else
  158136. register JDIMENSION count;
  158137. #endif
  158138. register int row;
  158139. input_array += source_row;
  158140. output_array += dest_row;
  158141. for (row = num_rows; row > 0; row--) {
  158142. inptr = *input_array++;
  158143. outptr = *output_array++;
  158144. #ifdef FMEMCOPY
  158145. FMEMCOPY(outptr, inptr, count);
  158146. #else
  158147. for (count = num_cols; count > 0; count--)
  158148. *outptr++ = *inptr++; /* needn't bother with GETJSAMPLE() here */
  158149. #endif
  158150. }
  158151. }
  158152. GLOBAL(void)
  158153. jcopy_block_row (JBLOCKROW input_row, JBLOCKROW output_row,
  158154. JDIMENSION num_blocks)
  158155. {
  158156. #ifdef FMEMCOPY
  158157. FMEMCOPY(output_row, input_row, num_blocks * (DCTSIZE2 * SIZEOF(JCOEF)));
  158158. #else
  158159. register JCOEFPTR inptr, outptr;
  158160. register long count;
  158161. inptr = (JCOEFPTR) input_row;
  158162. outptr = (JCOEFPTR) output_row;
  158163. for (count = (long) num_blocks * DCTSIZE2; count > 0; count--) {
  158164. *outptr++ = *inptr++;
  158165. }
  158166. #endif
  158167. }
  158168. GLOBAL(void)
  158169. jzero_far (void FAR * target, size_t bytestozero)
  158170. {
  158171. #ifdef FMEMZERO
  158172. FMEMZERO(target, bytestozero);
  158173. #else
  158174. register char FAR * ptr = (char FAR *) target;
  158175. register size_t count;
  158176. for (count = bytestozero; count > 0; count--) {
  158177. *ptr++ = 0;
  158178. }
  158179. #endif
  158180. }
  158181. /*** End of inlined file: jutils.c ***/
  158182. /*** Start of inlined file: transupp.c ***/
  158183. #define JPEG_INTERNALS
  158184. /*** Start of inlined file: transupp.h ***/
  158185. #ifndef TRANSFORMS_SUPPORTED
  158186. #define TRANSFORMS_SUPPORTED 1 /* 0 disables transform code */
  158187. #endif
  158188. #ifdef NEED_SHORT_EXTERNAL_NAMES
  158189. #define jtransform_request_workspace jTrRequest
  158190. #define jtransform_adjust_parameters jTrAdjust
  158191. #define jtransform_execute_transformation jTrExec
  158192. #define jcopy_markers_setup jCMrkSetup
  158193. #define jcopy_markers_execute jCMrkExec
  158194. #endif /* NEED_SHORT_EXTERNAL_NAMES */
  158195. typedef enum {
  158196. JXFORM_NONE, /* no transformation */
  158197. JXFORM_FLIP_H, /* horizontal flip */
  158198. JXFORM_FLIP_V, /* vertical flip */
  158199. JXFORM_TRANSPOSE, /* transpose across UL-to-LR axis */
  158200. JXFORM_TRANSVERSE, /* transpose across UR-to-LL axis */
  158201. JXFORM_ROT_90, /* 90-degree clockwise rotation */
  158202. JXFORM_ROT_180, /* 180-degree rotation */
  158203. JXFORM_ROT_270 /* 270-degree clockwise (or 90 ccw) */
  158204. } JXFORM_CODE;
  158205. typedef struct {
  158206. JXFORM_CODE transform; /* image transform operator */
  158207. boolean trim; /* if TRUE, trim partial MCUs as needed */
  158208. boolean force_grayscale; /* if TRUE, convert color image to grayscale */
  158209. int num_components; /* # of components in workspace */
  158210. jvirt_barray_ptr * workspace_coef_arrays; /* workspace for transformations */
  158211. } jpeg_transform_info;
  158212. #if TRANSFORMS_SUPPORTED
  158213. EXTERN(void) jtransform_request_workspace
  158214. JPP((j_decompress_ptr srcinfo, jpeg_transform_info *info));
  158215. EXTERN(jvirt_barray_ptr *) jtransform_adjust_parameters
  158216. JPP((j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
  158217. jvirt_barray_ptr *src_coef_arrays,
  158218. jpeg_transform_info *info));
  158219. EXTERN(void) jtransform_execute_transformation
  158220. JPP((j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
  158221. jvirt_barray_ptr *src_coef_arrays,
  158222. jpeg_transform_info *info));
  158223. #endif /* TRANSFORMS_SUPPORTED */
  158224. typedef enum {
  158225. JCOPYOPT_NONE, /* copy no optional markers */
  158226. JCOPYOPT_COMMENTS, /* copy only comment (COM) markers */
  158227. JCOPYOPT_ALL /* copy all optional markers */
  158228. } JCOPY_OPTION;
  158229. #define JCOPYOPT_DEFAULT JCOPYOPT_COMMENTS /* recommended default */
  158230. EXTERN(void) jcopy_markers_setup
  158231. JPP((j_decompress_ptr srcinfo, JCOPY_OPTION option));
  158232. EXTERN(void) jcopy_markers_execute
  158233. JPP((j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
  158234. JCOPY_OPTION option));
  158235. /*** End of inlined file: transupp.h ***/
  158236. /* My own external interface */
  158237. #if TRANSFORMS_SUPPORTED
  158238. LOCAL(void)
  158239. do_flip_h (j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
  158240. jvirt_barray_ptr *src_coef_arrays)
  158241. {
  158242. JDIMENSION MCU_cols, comp_width, blk_x, blk_y;
  158243. int ci, k, offset_y;
  158244. JBLOCKARRAY buffer;
  158245. JCOEFPTR ptr1, ptr2;
  158246. JCOEF temp1, temp2;
  158247. jpeg_component_info *compptr;
  158248. MCU_cols = dstinfo->image_width / (dstinfo->max_h_samp_factor * DCTSIZE);
  158249. for (ci = 0; ci < dstinfo->num_components; ci++) {
  158250. compptr = dstinfo->comp_info + ci;
  158251. comp_width = MCU_cols * compptr->h_samp_factor;
  158252. for (blk_y = 0; blk_y < compptr->height_in_blocks;
  158253. blk_y += compptr->v_samp_factor) {
  158254. buffer = (*srcinfo->mem->access_virt_barray)
  158255. ((j_common_ptr) srcinfo, src_coef_arrays[ci], blk_y,
  158256. (JDIMENSION) compptr->v_samp_factor, TRUE);
  158257. for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) {
  158258. for (blk_x = 0; blk_x * 2 < comp_width; blk_x++) {
  158259. ptr1 = buffer[offset_y][blk_x];
  158260. ptr2 = buffer[offset_y][comp_width - blk_x - 1];
  158261. for (k = 0; k < DCTSIZE2; k += 2) {
  158262. temp1 = *ptr1; /* swap even column */
  158263. temp2 = *ptr2;
  158264. *ptr1++ = temp2;
  158265. *ptr2++ = temp1;
  158266. temp1 = *ptr1; /* swap odd column with sign change */
  158267. temp2 = *ptr2;
  158268. *ptr1++ = -temp2;
  158269. *ptr2++ = -temp1;
  158270. }
  158271. }
  158272. }
  158273. }
  158274. }
  158275. }
  158276. LOCAL(void)
  158277. do_flip_v (j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
  158278. jvirt_barray_ptr *src_coef_arrays,
  158279. jvirt_barray_ptr *dst_coef_arrays)
  158280. {
  158281. JDIMENSION MCU_rows, comp_height, dst_blk_x, dst_blk_y;
  158282. int ci, i, j, offset_y;
  158283. JBLOCKARRAY src_buffer, dst_buffer;
  158284. JBLOCKROW src_row_ptr, dst_row_ptr;
  158285. JCOEFPTR src_ptr, dst_ptr;
  158286. jpeg_component_info *compptr;
  158287. MCU_rows = dstinfo->image_height / (dstinfo->max_v_samp_factor * DCTSIZE);
  158288. for (ci = 0; ci < dstinfo->num_components; ci++) {
  158289. compptr = dstinfo->comp_info + ci;
  158290. comp_height = MCU_rows * compptr->v_samp_factor;
  158291. for (dst_blk_y = 0; dst_blk_y < compptr->height_in_blocks;
  158292. dst_blk_y += compptr->v_samp_factor) {
  158293. dst_buffer = (*srcinfo->mem->access_virt_barray)
  158294. ((j_common_ptr) srcinfo, dst_coef_arrays[ci], dst_blk_y,
  158295. (JDIMENSION) compptr->v_samp_factor, TRUE);
  158296. if (dst_blk_y < comp_height) {
  158297. src_buffer = (*srcinfo->mem->access_virt_barray)
  158298. ((j_common_ptr) srcinfo, src_coef_arrays[ci],
  158299. comp_height - dst_blk_y - (JDIMENSION) compptr->v_samp_factor,
  158300. (JDIMENSION) compptr->v_samp_factor, FALSE);
  158301. } else {
  158302. src_buffer = (*srcinfo->mem->access_virt_barray)
  158303. ((j_common_ptr) srcinfo, src_coef_arrays[ci], dst_blk_y,
  158304. (JDIMENSION) compptr->v_samp_factor, FALSE);
  158305. }
  158306. for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) {
  158307. if (dst_blk_y < comp_height) {
  158308. dst_row_ptr = dst_buffer[offset_y];
  158309. src_row_ptr = src_buffer[compptr->v_samp_factor - offset_y - 1];
  158310. for (dst_blk_x = 0; dst_blk_x < compptr->width_in_blocks;
  158311. dst_blk_x++) {
  158312. dst_ptr = dst_row_ptr[dst_blk_x];
  158313. src_ptr = src_row_ptr[dst_blk_x];
  158314. for (i = 0; i < DCTSIZE; i += 2) {
  158315. for (j = 0; j < DCTSIZE; j++)
  158316. *dst_ptr++ = *src_ptr++;
  158317. for (j = 0; j < DCTSIZE; j++)
  158318. *dst_ptr++ = - *src_ptr++;
  158319. }
  158320. }
  158321. } else {
  158322. jcopy_block_row(src_buffer[offset_y], dst_buffer[offset_y],
  158323. compptr->width_in_blocks);
  158324. }
  158325. }
  158326. }
  158327. }
  158328. }
  158329. LOCAL(void)
  158330. do_transpose (j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
  158331. jvirt_barray_ptr *src_coef_arrays,
  158332. jvirt_barray_ptr *dst_coef_arrays)
  158333. {
  158334. JDIMENSION dst_blk_x, dst_blk_y;
  158335. int ci, i, j, offset_x, offset_y;
  158336. JBLOCKARRAY src_buffer, dst_buffer;
  158337. JCOEFPTR src_ptr, dst_ptr;
  158338. jpeg_component_info *compptr;
  158339. for (ci = 0; ci < dstinfo->num_components; ci++) {
  158340. compptr = dstinfo->comp_info + ci;
  158341. for (dst_blk_y = 0; dst_blk_y < compptr->height_in_blocks;
  158342. dst_blk_y += compptr->v_samp_factor) {
  158343. dst_buffer = (*srcinfo->mem->access_virt_barray)
  158344. ((j_common_ptr) srcinfo, dst_coef_arrays[ci], dst_blk_y,
  158345. (JDIMENSION) compptr->v_samp_factor, TRUE);
  158346. for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) {
  158347. for (dst_blk_x = 0; dst_blk_x < compptr->width_in_blocks;
  158348. dst_blk_x += compptr->h_samp_factor) {
  158349. src_buffer = (*srcinfo->mem->access_virt_barray)
  158350. ((j_common_ptr) srcinfo, src_coef_arrays[ci], dst_blk_x,
  158351. (JDIMENSION) compptr->h_samp_factor, FALSE);
  158352. for (offset_x = 0; offset_x < compptr->h_samp_factor; offset_x++) {
  158353. src_ptr = src_buffer[offset_x][dst_blk_y + offset_y];
  158354. dst_ptr = dst_buffer[offset_y][dst_blk_x + offset_x];
  158355. for (i = 0; i < DCTSIZE; i++)
  158356. for (j = 0; j < DCTSIZE; j++)
  158357. dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
  158358. }
  158359. }
  158360. }
  158361. }
  158362. }
  158363. }
  158364. LOCAL(void)
  158365. do_rot_90 (j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
  158366. jvirt_barray_ptr *src_coef_arrays,
  158367. jvirt_barray_ptr *dst_coef_arrays)
  158368. {
  158369. JDIMENSION MCU_cols, comp_width, dst_blk_x, dst_blk_y;
  158370. int ci, i, j, offset_x, offset_y;
  158371. JBLOCKARRAY src_buffer, dst_buffer;
  158372. JCOEFPTR src_ptr, dst_ptr;
  158373. jpeg_component_info *compptr;
  158374. MCU_cols = dstinfo->image_width / (dstinfo->max_h_samp_factor * DCTSIZE);
  158375. for (ci = 0; ci < dstinfo->num_components; ci++) {
  158376. compptr = dstinfo->comp_info + ci;
  158377. comp_width = MCU_cols * compptr->h_samp_factor;
  158378. for (dst_blk_y = 0; dst_blk_y < compptr->height_in_blocks;
  158379. dst_blk_y += compptr->v_samp_factor) {
  158380. dst_buffer = (*srcinfo->mem->access_virt_barray)
  158381. ((j_common_ptr) srcinfo, dst_coef_arrays[ci], dst_blk_y,
  158382. (JDIMENSION) compptr->v_samp_factor, TRUE);
  158383. for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) {
  158384. for (dst_blk_x = 0; dst_blk_x < compptr->width_in_blocks;
  158385. dst_blk_x += compptr->h_samp_factor) {
  158386. src_buffer = (*srcinfo->mem->access_virt_barray)
  158387. ((j_common_ptr) srcinfo, src_coef_arrays[ci], dst_blk_x,
  158388. (JDIMENSION) compptr->h_samp_factor, FALSE);
  158389. for (offset_x = 0; offset_x < compptr->h_samp_factor; offset_x++) {
  158390. src_ptr = src_buffer[offset_x][dst_blk_y + offset_y];
  158391. if (dst_blk_x < comp_width) {
  158392. dst_ptr = dst_buffer[offset_y]
  158393. [comp_width - dst_blk_x - offset_x - 1];
  158394. for (i = 0; i < DCTSIZE; i++) {
  158395. for (j = 0; j < DCTSIZE; j++)
  158396. dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
  158397. i++;
  158398. for (j = 0; j < DCTSIZE; j++)
  158399. dst_ptr[j*DCTSIZE+i] = -src_ptr[i*DCTSIZE+j];
  158400. }
  158401. } else {
  158402. dst_ptr = dst_buffer[offset_y][dst_blk_x + offset_x];
  158403. for (i = 0; i < DCTSIZE; i++)
  158404. for (j = 0; j < DCTSIZE; j++)
  158405. dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
  158406. }
  158407. }
  158408. }
  158409. }
  158410. }
  158411. }
  158412. }
  158413. LOCAL(void)
  158414. do_rot_270 (j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
  158415. jvirt_barray_ptr *src_coef_arrays,
  158416. jvirt_barray_ptr *dst_coef_arrays)
  158417. {
  158418. JDIMENSION MCU_rows, comp_height, dst_blk_x, dst_blk_y;
  158419. int ci, i, j, offset_x, offset_y;
  158420. JBLOCKARRAY src_buffer, dst_buffer;
  158421. JCOEFPTR src_ptr, dst_ptr;
  158422. jpeg_component_info *compptr;
  158423. MCU_rows = dstinfo->image_height / (dstinfo->max_v_samp_factor * DCTSIZE);
  158424. for (ci = 0; ci < dstinfo->num_components; ci++) {
  158425. compptr = dstinfo->comp_info + ci;
  158426. comp_height = MCU_rows * compptr->v_samp_factor;
  158427. for (dst_blk_y = 0; dst_blk_y < compptr->height_in_blocks;
  158428. dst_blk_y += compptr->v_samp_factor) {
  158429. dst_buffer = (*srcinfo->mem->access_virt_barray)
  158430. ((j_common_ptr) srcinfo, dst_coef_arrays[ci], dst_blk_y,
  158431. (JDIMENSION) compptr->v_samp_factor, TRUE);
  158432. for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) {
  158433. for (dst_blk_x = 0; dst_blk_x < compptr->width_in_blocks;
  158434. dst_blk_x += compptr->h_samp_factor) {
  158435. src_buffer = (*srcinfo->mem->access_virt_barray)
  158436. ((j_common_ptr) srcinfo, src_coef_arrays[ci], dst_blk_x,
  158437. (JDIMENSION) compptr->h_samp_factor, FALSE);
  158438. for (offset_x = 0; offset_x < compptr->h_samp_factor; offset_x++) {
  158439. dst_ptr = dst_buffer[offset_y][dst_blk_x + offset_x];
  158440. if (dst_blk_y < comp_height) {
  158441. src_ptr = src_buffer[offset_x]
  158442. [comp_height - dst_blk_y - offset_y - 1];
  158443. for (i = 0; i < DCTSIZE; i++) {
  158444. for (j = 0; j < DCTSIZE; j++) {
  158445. dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
  158446. j++;
  158447. dst_ptr[j*DCTSIZE+i] = -src_ptr[i*DCTSIZE+j];
  158448. }
  158449. }
  158450. } else {
  158451. src_ptr = src_buffer[offset_x][dst_blk_y + offset_y];
  158452. for (i = 0; i < DCTSIZE; i++)
  158453. for (j = 0; j < DCTSIZE; j++)
  158454. dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
  158455. }
  158456. }
  158457. }
  158458. }
  158459. }
  158460. }
  158461. }
  158462. LOCAL(void)
  158463. do_rot_180 (j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
  158464. jvirt_barray_ptr *src_coef_arrays,
  158465. jvirt_barray_ptr *dst_coef_arrays)
  158466. {
  158467. JDIMENSION MCU_cols, MCU_rows, comp_width, comp_height, dst_blk_x, dst_blk_y;
  158468. int ci, i, j, offset_y;
  158469. JBLOCKARRAY src_buffer, dst_buffer;
  158470. JBLOCKROW src_row_ptr, dst_row_ptr;
  158471. JCOEFPTR src_ptr, dst_ptr;
  158472. jpeg_component_info *compptr;
  158473. MCU_cols = dstinfo->image_width / (dstinfo->max_h_samp_factor * DCTSIZE);
  158474. MCU_rows = dstinfo->image_height / (dstinfo->max_v_samp_factor * DCTSIZE);
  158475. for (ci = 0; ci < dstinfo->num_components; ci++) {
  158476. compptr = dstinfo->comp_info + ci;
  158477. comp_width = MCU_cols * compptr->h_samp_factor;
  158478. comp_height = MCU_rows * compptr->v_samp_factor;
  158479. for (dst_blk_y = 0; dst_blk_y < compptr->height_in_blocks;
  158480. dst_blk_y += compptr->v_samp_factor) {
  158481. dst_buffer = (*srcinfo->mem->access_virt_barray)
  158482. ((j_common_ptr) srcinfo, dst_coef_arrays[ci], dst_blk_y,
  158483. (JDIMENSION) compptr->v_samp_factor, TRUE);
  158484. if (dst_blk_y < comp_height) {
  158485. src_buffer = (*srcinfo->mem->access_virt_barray)
  158486. ((j_common_ptr) srcinfo, src_coef_arrays[ci],
  158487. comp_height - dst_blk_y - (JDIMENSION) compptr->v_samp_factor,
  158488. (JDIMENSION) compptr->v_samp_factor, FALSE);
  158489. } else {
  158490. src_buffer = (*srcinfo->mem->access_virt_barray)
  158491. ((j_common_ptr) srcinfo, src_coef_arrays[ci], dst_blk_y,
  158492. (JDIMENSION) compptr->v_samp_factor, FALSE);
  158493. }
  158494. for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) {
  158495. if (dst_blk_y < comp_height) {
  158496. dst_row_ptr = dst_buffer[offset_y];
  158497. src_row_ptr = src_buffer[compptr->v_samp_factor - offset_y - 1];
  158498. for (dst_blk_x = 0; dst_blk_x < comp_width; dst_blk_x++) {
  158499. dst_ptr = dst_row_ptr[dst_blk_x];
  158500. src_ptr = src_row_ptr[comp_width - dst_blk_x - 1];
  158501. for (i = 0; i < DCTSIZE; i += 2) {
  158502. for (j = 0; j < DCTSIZE; j += 2) {
  158503. *dst_ptr++ = *src_ptr++;
  158504. *dst_ptr++ = - *src_ptr++;
  158505. }
  158506. for (j = 0; j < DCTSIZE; j += 2) {
  158507. *dst_ptr++ = - *src_ptr++;
  158508. *dst_ptr++ = *src_ptr++;
  158509. }
  158510. }
  158511. }
  158512. for (; dst_blk_x < compptr->width_in_blocks; dst_blk_x++) {
  158513. dst_ptr = dst_row_ptr[dst_blk_x];
  158514. src_ptr = src_row_ptr[dst_blk_x];
  158515. for (i = 0; i < DCTSIZE; i += 2) {
  158516. for (j = 0; j < DCTSIZE; j++)
  158517. *dst_ptr++ = *src_ptr++;
  158518. for (j = 0; j < DCTSIZE; j++)
  158519. *dst_ptr++ = - *src_ptr++;
  158520. }
  158521. }
  158522. } else {
  158523. dst_row_ptr = dst_buffer[offset_y];
  158524. src_row_ptr = src_buffer[offset_y];
  158525. for (dst_blk_x = 0; dst_blk_x < comp_width; dst_blk_x++) {
  158526. dst_ptr = dst_row_ptr[dst_blk_x];
  158527. src_ptr = src_row_ptr[comp_width - dst_blk_x - 1];
  158528. for (i = 0; i < DCTSIZE2; i += 2) {
  158529. *dst_ptr++ = *src_ptr++;
  158530. *dst_ptr++ = - *src_ptr++;
  158531. }
  158532. }
  158533. for (; dst_blk_x < compptr->width_in_blocks; dst_blk_x++) {
  158534. dst_ptr = dst_row_ptr[dst_blk_x];
  158535. src_ptr = src_row_ptr[dst_blk_x];
  158536. for (i = 0; i < DCTSIZE2; i++)
  158537. *dst_ptr++ = *src_ptr++;
  158538. }
  158539. }
  158540. }
  158541. }
  158542. }
  158543. }
  158544. LOCAL(void)
  158545. do_transverse (j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
  158546. jvirt_barray_ptr *src_coef_arrays,
  158547. jvirt_barray_ptr *dst_coef_arrays)
  158548. {
  158549. JDIMENSION MCU_cols, MCU_rows, comp_width, comp_height, dst_blk_x, dst_blk_y;
  158550. int ci, i, j, offset_x, offset_y;
  158551. JBLOCKARRAY src_buffer, dst_buffer;
  158552. JCOEFPTR src_ptr, dst_ptr;
  158553. jpeg_component_info *compptr;
  158554. MCU_cols = dstinfo->image_width / (dstinfo->max_h_samp_factor * DCTSIZE);
  158555. MCU_rows = dstinfo->image_height / (dstinfo->max_v_samp_factor * DCTSIZE);
  158556. for (ci = 0; ci < dstinfo->num_components; ci++) {
  158557. compptr = dstinfo->comp_info + ci;
  158558. comp_width = MCU_cols * compptr->h_samp_factor;
  158559. comp_height = MCU_rows * compptr->v_samp_factor;
  158560. for (dst_blk_y = 0; dst_blk_y < compptr->height_in_blocks;
  158561. dst_blk_y += compptr->v_samp_factor) {
  158562. dst_buffer = (*srcinfo->mem->access_virt_barray)
  158563. ((j_common_ptr) srcinfo, dst_coef_arrays[ci], dst_blk_y,
  158564. (JDIMENSION) compptr->v_samp_factor, TRUE);
  158565. for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) {
  158566. for (dst_blk_x = 0; dst_blk_x < compptr->width_in_blocks;
  158567. dst_blk_x += compptr->h_samp_factor) {
  158568. src_buffer = (*srcinfo->mem->access_virt_barray)
  158569. ((j_common_ptr) srcinfo, src_coef_arrays[ci], dst_blk_x,
  158570. (JDIMENSION) compptr->h_samp_factor, FALSE);
  158571. for (offset_x = 0; offset_x < compptr->h_samp_factor; offset_x++) {
  158572. if (dst_blk_y < comp_height) {
  158573. src_ptr = src_buffer[offset_x]
  158574. [comp_height - dst_blk_y - offset_y - 1];
  158575. if (dst_blk_x < comp_width) {
  158576. dst_ptr = dst_buffer[offset_y]
  158577. [comp_width - dst_blk_x - offset_x - 1];
  158578. for (i = 0; i < DCTSIZE; i++) {
  158579. for (j = 0; j < DCTSIZE; j++) {
  158580. dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
  158581. j++;
  158582. dst_ptr[j*DCTSIZE+i] = -src_ptr[i*DCTSIZE+j];
  158583. }
  158584. i++;
  158585. for (j = 0; j < DCTSIZE; j++) {
  158586. dst_ptr[j*DCTSIZE+i] = -src_ptr[i*DCTSIZE+j];
  158587. j++;
  158588. dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
  158589. }
  158590. }
  158591. } else {
  158592. dst_ptr = dst_buffer[offset_y][dst_blk_x + offset_x];
  158593. for (i = 0; i < DCTSIZE; i++) {
  158594. for (j = 0; j < DCTSIZE; j++) {
  158595. dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
  158596. j++;
  158597. dst_ptr[j*DCTSIZE+i] = -src_ptr[i*DCTSIZE+j];
  158598. }
  158599. }
  158600. }
  158601. } else {
  158602. src_ptr = src_buffer[offset_x][dst_blk_y + offset_y];
  158603. if (dst_blk_x < comp_width) {
  158604. dst_ptr = dst_buffer[offset_y]
  158605. [comp_width - dst_blk_x - offset_x - 1];
  158606. for (i = 0; i < DCTSIZE; i++) {
  158607. for (j = 0; j < DCTSIZE; j++)
  158608. dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
  158609. i++;
  158610. for (j = 0; j < DCTSIZE; j++)
  158611. dst_ptr[j*DCTSIZE+i] = -src_ptr[i*DCTSIZE+j];
  158612. }
  158613. } else {
  158614. dst_ptr = dst_buffer[offset_y][dst_blk_x + offset_x];
  158615. for (i = 0; i < DCTSIZE; i++)
  158616. for (j = 0; j < DCTSIZE; j++)
  158617. dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
  158618. }
  158619. }
  158620. }
  158621. }
  158622. }
  158623. }
  158624. }
  158625. }
  158626. GLOBAL(void)
  158627. jtransform_request_workspace (j_decompress_ptr srcinfo,
  158628. jpeg_transform_info *info)
  158629. {
  158630. jvirt_barray_ptr *coef_arrays = NULL;
  158631. jpeg_component_info *compptr;
  158632. int ci;
  158633. if (info->force_grayscale &&
  158634. srcinfo->jpeg_color_space == JCS_YCbCr &&
  158635. srcinfo->num_components == 3) {
  158636. info->num_components = 1;
  158637. } else {
  158638. info->num_components = srcinfo->num_components;
  158639. }
  158640. switch (info->transform) {
  158641. case JXFORM_NONE:
  158642. case JXFORM_FLIP_H:
  158643. break;
  158644. case JXFORM_FLIP_V:
  158645. case JXFORM_ROT_180:
  158646. coef_arrays = (jvirt_barray_ptr *)
  158647. (*srcinfo->mem->alloc_small) ((j_common_ptr) srcinfo, JPOOL_IMAGE,
  158648. SIZEOF(jvirt_barray_ptr) * info->num_components);
  158649. for (ci = 0; ci < info->num_components; ci++) {
  158650. compptr = srcinfo->comp_info + ci;
  158651. coef_arrays[ci] = (*srcinfo->mem->request_virt_barray)
  158652. ((j_common_ptr) srcinfo, JPOOL_IMAGE, FALSE,
  158653. (JDIMENSION) jround_up((long) compptr->width_in_blocks,
  158654. (long) compptr->h_samp_factor),
  158655. (JDIMENSION) jround_up((long) compptr->height_in_blocks,
  158656. (long) compptr->v_samp_factor),
  158657. (JDIMENSION) compptr->v_samp_factor);
  158658. }
  158659. break;
  158660. case JXFORM_TRANSPOSE:
  158661. case JXFORM_TRANSVERSE:
  158662. case JXFORM_ROT_90:
  158663. case JXFORM_ROT_270:
  158664. coef_arrays = (jvirt_barray_ptr *)
  158665. (*srcinfo->mem->alloc_small) ((j_common_ptr) srcinfo, JPOOL_IMAGE,
  158666. SIZEOF(jvirt_barray_ptr) * info->num_components);
  158667. for (ci = 0; ci < info->num_components; ci++) {
  158668. compptr = srcinfo->comp_info + ci;
  158669. coef_arrays[ci] = (*srcinfo->mem->request_virt_barray)
  158670. ((j_common_ptr) srcinfo, JPOOL_IMAGE, FALSE,
  158671. (JDIMENSION) jround_up((long) compptr->height_in_blocks,
  158672. (long) compptr->v_samp_factor),
  158673. (JDIMENSION) jround_up((long) compptr->width_in_blocks,
  158674. (long) compptr->h_samp_factor),
  158675. (JDIMENSION) compptr->h_samp_factor);
  158676. }
  158677. break;
  158678. }
  158679. info->workspace_coef_arrays = coef_arrays;
  158680. }
  158681. LOCAL(void)
  158682. transpose_critical_parameters (j_compress_ptr dstinfo)
  158683. {
  158684. int tblno, i, j, ci, itemp;
  158685. jpeg_component_info *compptr;
  158686. JQUANT_TBL *qtblptr;
  158687. JDIMENSION dtemp;
  158688. UINT16 qtemp;
  158689. dtemp = dstinfo->image_width;
  158690. dstinfo->image_width = dstinfo->image_height;
  158691. dstinfo->image_height = dtemp;
  158692. for (ci = 0; ci < dstinfo->num_components; ci++) {
  158693. compptr = dstinfo->comp_info + ci;
  158694. itemp = compptr->h_samp_factor;
  158695. compptr->h_samp_factor = compptr->v_samp_factor;
  158696. compptr->v_samp_factor = itemp;
  158697. }
  158698. for (tblno = 0; tblno < NUM_QUANT_TBLS; tblno++) {
  158699. qtblptr = dstinfo->quant_tbl_ptrs[tblno];
  158700. if (qtblptr != NULL) {
  158701. for (i = 0; i < DCTSIZE; i++) {
  158702. for (j = 0; j < i; j++) {
  158703. qtemp = qtblptr->quantval[i*DCTSIZE+j];
  158704. qtblptr->quantval[i*DCTSIZE+j] = qtblptr->quantval[j*DCTSIZE+i];
  158705. qtblptr->quantval[j*DCTSIZE+i] = qtemp;
  158706. }
  158707. }
  158708. }
  158709. }
  158710. }
  158711. LOCAL(void)
  158712. trim_right_edge (j_compress_ptr dstinfo)
  158713. {
  158714. int ci, max_h_samp_factor;
  158715. JDIMENSION MCU_cols;
  158716. max_h_samp_factor = 1;
  158717. for (ci = 0; ci < dstinfo->num_components; ci++) {
  158718. int h_samp_factor = dstinfo->comp_info[ci].h_samp_factor;
  158719. max_h_samp_factor = MAX(max_h_samp_factor, h_samp_factor);
  158720. }
  158721. MCU_cols = dstinfo->image_width / (max_h_samp_factor * DCTSIZE);
  158722. if (MCU_cols > 0) /* can't trim to 0 pixels */
  158723. dstinfo->image_width = MCU_cols * (max_h_samp_factor * DCTSIZE);
  158724. }
  158725. LOCAL(void)
  158726. trim_bottom_edge (j_compress_ptr dstinfo)
  158727. {
  158728. int ci, max_v_samp_factor;
  158729. JDIMENSION MCU_rows;
  158730. max_v_samp_factor = 1;
  158731. for (ci = 0; ci < dstinfo->num_components; ci++) {
  158732. int v_samp_factor = dstinfo->comp_info[ci].v_samp_factor;
  158733. max_v_samp_factor = MAX(max_v_samp_factor, v_samp_factor);
  158734. }
  158735. MCU_rows = dstinfo->image_height / (max_v_samp_factor * DCTSIZE);
  158736. if (MCU_rows > 0) /* can't trim to 0 pixels */
  158737. dstinfo->image_height = MCU_rows * (max_v_samp_factor * DCTSIZE);
  158738. }
  158739. GLOBAL(jvirt_barray_ptr *)
  158740. jtransform_adjust_parameters (j_decompress_ptr srcinfo,
  158741. j_compress_ptr dstinfo,
  158742. jvirt_barray_ptr *src_coef_arrays,
  158743. jpeg_transform_info *info)
  158744. {
  158745. if (info->force_grayscale) {
  158746. if ((dstinfo->jpeg_color_space == JCS_YCbCr &&
  158747. dstinfo->num_components == 3) ||
  158748. (dstinfo->jpeg_color_space == JCS_GRAYSCALE &&
  158749. dstinfo->num_components == 1)) {
  158750. int sv_quant_tbl_no = dstinfo->comp_info[0].quant_tbl_no;
  158751. jpeg_set_colorspace(dstinfo, JCS_GRAYSCALE);
  158752. dstinfo->comp_info[0].quant_tbl_no = sv_quant_tbl_no;
  158753. } else {
  158754. ERREXIT(dstinfo, JERR_CONVERSION_NOTIMPL);
  158755. }
  158756. }
  158757. switch (info->transform) {
  158758. case JXFORM_NONE:
  158759. break;
  158760. case JXFORM_FLIP_H:
  158761. if (info->trim)
  158762. trim_right_edge(dstinfo);
  158763. break;
  158764. case JXFORM_FLIP_V:
  158765. if (info->trim)
  158766. trim_bottom_edge(dstinfo);
  158767. break;
  158768. case JXFORM_TRANSPOSE:
  158769. transpose_critical_parameters(dstinfo);
  158770. break;
  158771. case JXFORM_TRANSVERSE:
  158772. transpose_critical_parameters(dstinfo);
  158773. if (info->trim) {
  158774. trim_right_edge(dstinfo);
  158775. trim_bottom_edge(dstinfo);
  158776. }
  158777. break;
  158778. case JXFORM_ROT_90:
  158779. transpose_critical_parameters(dstinfo);
  158780. if (info->trim)
  158781. trim_right_edge(dstinfo);
  158782. break;
  158783. case JXFORM_ROT_180:
  158784. if (info->trim) {
  158785. trim_right_edge(dstinfo);
  158786. trim_bottom_edge(dstinfo);
  158787. }
  158788. break;
  158789. case JXFORM_ROT_270:
  158790. transpose_critical_parameters(dstinfo);
  158791. if (info->trim)
  158792. trim_bottom_edge(dstinfo);
  158793. break;
  158794. }
  158795. if (info->workspace_coef_arrays != NULL)
  158796. return info->workspace_coef_arrays;
  158797. return src_coef_arrays;
  158798. }
  158799. GLOBAL(void)
  158800. jtransform_execute_transformation (j_decompress_ptr srcinfo,
  158801. j_compress_ptr dstinfo,
  158802. jvirt_barray_ptr *src_coef_arrays,
  158803. jpeg_transform_info *info)
  158804. {
  158805. jvirt_barray_ptr *dst_coef_arrays = info->workspace_coef_arrays;
  158806. switch (info->transform) {
  158807. case JXFORM_NONE:
  158808. break;
  158809. case JXFORM_FLIP_H:
  158810. do_flip_h(srcinfo, dstinfo, src_coef_arrays);
  158811. break;
  158812. case JXFORM_FLIP_V:
  158813. do_flip_v(srcinfo, dstinfo, src_coef_arrays, dst_coef_arrays);
  158814. break;
  158815. case JXFORM_TRANSPOSE:
  158816. do_transpose(srcinfo, dstinfo, src_coef_arrays, dst_coef_arrays);
  158817. break;
  158818. case JXFORM_TRANSVERSE:
  158819. do_transverse(srcinfo, dstinfo, src_coef_arrays, dst_coef_arrays);
  158820. break;
  158821. case JXFORM_ROT_90:
  158822. do_rot_90(srcinfo, dstinfo, src_coef_arrays, dst_coef_arrays);
  158823. break;
  158824. case JXFORM_ROT_180:
  158825. do_rot_180(srcinfo, dstinfo, src_coef_arrays, dst_coef_arrays);
  158826. break;
  158827. case JXFORM_ROT_270:
  158828. do_rot_270(srcinfo, dstinfo, src_coef_arrays, dst_coef_arrays);
  158829. break;
  158830. }
  158831. }
  158832. #endif /* TRANSFORMS_SUPPORTED */
  158833. GLOBAL(void)
  158834. jcopy_markers_setup (j_decompress_ptr srcinfo, JCOPY_OPTION option)
  158835. {
  158836. #ifdef SAVE_MARKERS_SUPPORTED
  158837. int m;
  158838. if (option != JCOPYOPT_NONE) {
  158839. jpeg_save_markers(srcinfo, JPEG_COM, 0xFFFF);
  158840. }
  158841. if (option == JCOPYOPT_ALL) {
  158842. for (m = 0; m < 16; m++)
  158843. jpeg_save_markers(srcinfo, JPEG_APP0 + m, 0xFFFF);
  158844. }
  158845. #endif /* SAVE_MARKERS_SUPPORTED */
  158846. }
  158847. GLOBAL(void)
  158848. jcopy_markers_execute (j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
  158849. JCOPY_OPTION option)
  158850. {
  158851. jpeg_saved_marker_ptr marker;
  158852. for (marker = srcinfo->marker_list; marker != NULL; marker = marker->next) {
  158853. if (dstinfo->write_JFIF_header &&
  158854. marker->marker == JPEG_APP0 &&
  158855. marker->data_length >= 5 &&
  158856. GETJOCTET(marker->data[0]) == 0x4A &&
  158857. GETJOCTET(marker->data[1]) == 0x46 &&
  158858. GETJOCTET(marker->data[2]) == 0x49 &&
  158859. GETJOCTET(marker->data[3]) == 0x46 &&
  158860. GETJOCTET(marker->data[4]) == 0)
  158861. continue; /* reject duplicate JFIF */
  158862. if (dstinfo->write_Adobe_marker &&
  158863. marker->marker == JPEG_APP0+14 &&
  158864. marker->data_length >= 5 &&
  158865. GETJOCTET(marker->data[0]) == 0x41 &&
  158866. GETJOCTET(marker->data[1]) == 0x64 &&
  158867. GETJOCTET(marker->data[2]) == 0x6F &&
  158868. GETJOCTET(marker->data[3]) == 0x62 &&
  158869. GETJOCTET(marker->data[4]) == 0x65)
  158870. continue; /* reject duplicate Adobe */
  158871. #ifdef NEED_FAR_POINTERS
  158872. {
  158873. unsigned int i;
  158874. jpeg_write_m_header(dstinfo, marker->marker, marker->data_length);
  158875. for (i = 0; i < marker->data_length; i++)
  158876. jpeg_write_m_byte(dstinfo, marker->data[i]);
  158877. }
  158878. #else
  158879. jpeg_write_marker(dstinfo, marker->marker,
  158880. marker->data, marker->data_length);
  158881. #endif
  158882. }
  158883. }
  158884. /*** End of inlined file: transupp.c ***/
  158885. }
  158886. #else
  158887. #define JPEG_INTERNALS
  158888. #undef FAR
  158889. #include <jpeglib.h>
  158890. #endif
  158891. }
  158892. #if JUCE_MSVC
  158893. #pragma warning (pop)
  158894. #endif
  158895. BEGIN_JUCE_NAMESPACE
  158896. namespace JPEGHelpers
  158897. {
  158898. using namespace jpeglibNamespace;
  158899. #if ! JUCE_MSVC
  158900. using jpeglibNamespace::boolean;
  158901. #endif
  158902. struct JPEGDecodingFailure {};
  158903. static void fatalErrorHandler (j_common_ptr)
  158904. {
  158905. throw JPEGDecodingFailure();
  158906. }
  158907. static void silentErrorCallback1 (j_common_ptr) {}
  158908. static void silentErrorCallback2 (j_common_ptr, int) {}
  158909. static void silentErrorCallback3 (j_common_ptr, char*) {}
  158910. static void setupSilentErrorHandler (struct jpeg_error_mgr& err)
  158911. {
  158912. zerostruct (err);
  158913. err.error_exit = fatalErrorHandler;
  158914. err.emit_message = silentErrorCallback2;
  158915. err.output_message = silentErrorCallback1;
  158916. err.format_message = silentErrorCallback3;
  158917. err.reset_error_mgr = silentErrorCallback1;
  158918. }
  158919. static void dummyCallback1 (j_decompress_ptr)
  158920. {
  158921. }
  158922. static void jpegSkip (j_decompress_ptr decompStruct, long num)
  158923. {
  158924. decompStruct->src->next_input_byte += num;
  158925. num = jmin (num, (long) decompStruct->src->bytes_in_buffer);
  158926. decompStruct->src->bytes_in_buffer -= num;
  158927. }
  158928. static boolean jpegFill (j_decompress_ptr)
  158929. {
  158930. return 0;
  158931. }
  158932. static const int jpegBufferSize = 512;
  158933. struct JuceJpegDest : public jpeg_destination_mgr
  158934. {
  158935. OutputStream* output;
  158936. char* buffer;
  158937. };
  158938. static void jpegWriteInit (j_compress_ptr)
  158939. {
  158940. }
  158941. static void jpegWriteTerminate (j_compress_ptr cinfo)
  158942. {
  158943. JuceJpegDest* const dest = (JuceJpegDest*) cinfo->dest;
  158944. const size_t numToWrite = jpegBufferSize - dest->free_in_buffer;
  158945. dest->output->write (dest->buffer, (int) numToWrite);
  158946. }
  158947. static boolean jpegWriteFlush (j_compress_ptr cinfo)
  158948. {
  158949. JuceJpegDest* const dest = (JuceJpegDest*) cinfo->dest;
  158950. const int numToWrite = jpegBufferSize;
  158951. dest->next_output_byte = (JOCTET*) dest->buffer;
  158952. dest->free_in_buffer = jpegBufferSize;
  158953. return dest->output->write (dest->buffer, numToWrite);
  158954. }
  158955. }
  158956. Image* juce_loadJPEGImageFromStream (InputStream& in)
  158957. {
  158958. using namespace jpeglibNamespace;
  158959. using namespace JPEGHelpers;
  158960. MemoryBlock mb;
  158961. in.readIntoMemoryBlock (mb);
  158962. Image* image = 0;
  158963. if (mb.getSize() > 16)
  158964. {
  158965. struct jpeg_decompress_struct jpegDecompStruct;
  158966. struct jpeg_error_mgr jerr;
  158967. setupSilentErrorHandler (jerr);
  158968. jpegDecompStruct.err = &jerr;
  158969. jpeg_create_decompress (&jpegDecompStruct);
  158970. jpegDecompStruct.src = (jpeg_source_mgr*)(jpegDecompStruct.mem->alloc_small)
  158971. ((j_common_ptr)(&jpegDecompStruct), JPOOL_PERMANENT, sizeof (jpeg_source_mgr));
  158972. jpegDecompStruct.src->init_source = dummyCallback1;
  158973. jpegDecompStruct.src->fill_input_buffer = jpegFill;
  158974. jpegDecompStruct.src->skip_input_data = jpegSkip;
  158975. jpegDecompStruct.src->resync_to_restart = jpeg_resync_to_restart;
  158976. jpegDecompStruct.src->term_source = dummyCallback1;
  158977. jpegDecompStruct.src->next_input_byte = (const unsigned char*) mb.getData();
  158978. jpegDecompStruct.src->bytes_in_buffer = mb.getSize();
  158979. try
  158980. {
  158981. jpeg_read_header (&jpegDecompStruct, TRUE);
  158982. jpeg_calc_output_dimensions (&jpegDecompStruct);
  158983. const int width = jpegDecompStruct.output_width;
  158984. const int height = jpegDecompStruct.output_height;
  158985. jpegDecompStruct.out_color_space = JCS_RGB;
  158986. JSAMPARRAY buffer
  158987. = (*jpegDecompStruct.mem->alloc_sarray) ((j_common_ptr) &jpegDecompStruct,
  158988. JPOOL_IMAGE,
  158989. width * 3, 1);
  158990. if (jpeg_start_decompress (&jpegDecompStruct))
  158991. {
  158992. image = Image::createNativeImage (Image::RGB, width, height, false);
  158993. const bool hasAlphaChan = image->hasAlphaChannel();
  158994. const Image::BitmapData destData (*image, 0, 0, width, height, true);
  158995. for (int y = 0; y < height; ++y)
  158996. {
  158997. jpeg_read_scanlines (&jpegDecompStruct, buffer, 1);
  158998. const uint8* src = *buffer;
  158999. uint8* dest = destData.getLinePointer (y);
  159000. if (hasAlphaChan)
  159001. {
  159002. for (int i = width; --i >= 0;)
  159003. {
  159004. ((PixelARGB*) dest)->setARGB (0xff, src[0], src[1], src[2]);
  159005. ((PixelARGB*) dest)->premultiply();
  159006. dest += destData.pixelStride;
  159007. src += 3;
  159008. }
  159009. }
  159010. else
  159011. {
  159012. for (int i = width; --i >= 0;)
  159013. {
  159014. ((PixelRGB*) dest)->setARGB (0xff, src[0], src[1], src[2]);
  159015. dest += destData.pixelStride;
  159016. src += 3;
  159017. }
  159018. }
  159019. }
  159020. jpeg_finish_decompress (&jpegDecompStruct);
  159021. in.setPosition (((char*) jpegDecompStruct.src->next_input_byte) - (char*) mb.getData());
  159022. }
  159023. jpeg_destroy_decompress (&jpegDecompStruct);
  159024. }
  159025. catch (...)
  159026. {}
  159027. }
  159028. return image;
  159029. }
  159030. bool juce_writeJPEGImageToStream (const Image& image,
  159031. OutputStream& out,
  159032. float quality)
  159033. {
  159034. using namespace jpeglibNamespace;
  159035. using namespace JPEGHelpers;
  159036. if (image.hasAlphaChannel())
  159037. {
  159038. // this method could fill the background in white and still save the image..
  159039. jassertfalse
  159040. return true;
  159041. }
  159042. struct jpeg_compress_struct jpegCompStruct;
  159043. struct jpeg_error_mgr jerr;
  159044. setupSilentErrorHandler (jerr);
  159045. jpegCompStruct.err = &jerr;
  159046. jpeg_create_compress (&jpegCompStruct);
  159047. JuceJpegDest dest;
  159048. jpegCompStruct.dest = &dest;
  159049. dest.output = &out;
  159050. HeapBlock <char> tempBuffer (jpegBufferSize);
  159051. dest.buffer = (char*) tempBuffer;
  159052. dest.next_output_byte = (JOCTET*) dest.buffer;
  159053. dest.free_in_buffer = jpegBufferSize;
  159054. dest.init_destination = jpegWriteInit;
  159055. dest.empty_output_buffer = jpegWriteFlush;
  159056. dest.term_destination = jpegWriteTerminate;
  159057. jpegCompStruct.image_width = image.getWidth();
  159058. jpegCompStruct.image_height = image.getHeight();
  159059. jpegCompStruct.input_components = 3;
  159060. jpegCompStruct.in_color_space = JCS_RGB;
  159061. jpegCompStruct.write_JFIF_header = 1;
  159062. jpegCompStruct.X_density = 72;
  159063. jpegCompStruct.Y_density = 72;
  159064. jpeg_set_defaults (&jpegCompStruct);
  159065. jpegCompStruct.dct_method = JDCT_FLOAT;
  159066. jpegCompStruct.optimize_coding = 1;
  159067. // jpegCompStruct.smoothing_factor = 10;
  159068. if (quality < 0.0f)
  159069. quality = 0.85f;
  159070. jpeg_set_quality (&jpegCompStruct, jlimit (0, 100, roundToInt (quality * 100.0f)), TRUE);
  159071. jpeg_start_compress (&jpegCompStruct, TRUE);
  159072. const int strideBytes = jpegCompStruct.image_width * jpegCompStruct.input_components;
  159073. JSAMPARRAY buffer = (*jpegCompStruct.mem->alloc_sarray) ((j_common_ptr) &jpegCompStruct,
  159074. JPOOL_IMAGE,
  159075. strideBytes, 1);
  159076. const Image::BitmapData srcData (image, 0, 0, jpegCompStruct.image_width, jpegCompStruct.image_height);
  159077. while (jpegCompStruct.next_scanline < jpegCompStruct.image_height)
  159078. {
  159079. const uint8* src = srcData.getLinePointer (jpegCompStruct.next_scanline);
  159080. uint8* dst = *buffer;
  159081. for (int i = jpegCompStruct.image_width; --i >= 0;)
  159082. {
  159083. *dst++ = ((const PixelRGB*) src)->getRed();
  159084. *dst++ = ((const PixelRGB*) src)->getGreen();
  159085. *dst++ = ((const PixelRGB*) src)->getBlue();
  159086. src += srcData.pixelStride;
  159087. }
  159088. jpeg_write_scanlines (&jpegCompStruct, buffer, 1);
  159089. }
  159090. jpeg_finish_compress (&jpegCompStruct);
  159091. jpeg_destroy_compress (&jpegCompStruct);
  159092. out.flush();
  159093. return true;
  159094. }
  159095. END_JUCE_NAMESPACE
  159096. /*** End of inlined file: juce_JPEGLoader.cpp ***/
  159097. /*** Start of inlined file: juce_PNGLoader.cpp ***/
  159098. #ifdef _MSC_VER
  159099. #pragma warning (push)
  159100. #pragma warning (disable: 4390 4611)
  159101. #endif
  159102. namespace zlibNamespace
  159103. {
  159104. #if JUCE_INCLUDE_ZLIB_CODE
  159105. #undef OS_CODE
  159106. #undef fdopen
  159107. #undef OS_CODE
  159108. #else
  159109. #include <zlib.h>
  159110. #endif
  159111. }
  159112. namespace pnglibNamespace
  159113. {
  159114. using namespace zlibNamespace;
  159115. #if JUCE_INCLUDE_PNGLIB_CODE
  159116. #if _MSC_VER != 1310
  159117. using ::calloc; // (causes conflict in VS.NET 2003)
  159118. using ::malloc;
  159119. using ::free;
  159120. #endif
  159121. extern "C"
  159122. {
  159123. using ::abs;
  159124. #define PNG_INTERNAL
  159125. #define NO_DUMMY_DECL
  159126. #define PNG_SETJMP_NOT_SUPPORTED
  159127. /*** Start of inlined file: png.h ***/
  159128. #ifndef PNG_H
  159129. #define PNG_H
  159130. #define PNG_LIBPNG_VER_STRING "1.2.21"
  159131. #define PNG_HEADER_VERSION_STRING \
  159132. " libpng version 1.2.21 - October 4, 2007\n"
  159133. #define PNG_LIBPNG_VER_SONUM 0
  159134. #define PNG_LIBPNG_VER_DLLNUM 13
  159135. #define PNG_LIBPNG_VER_MAJOR 1
  159136. #define PNG_LIBPNG_VER_MINOR 2
  159137. #define PNG_LIBPNG_VER_RELEASE 21
  159138. #define PNG_LIBPNG_VER_BUILD 0
  159139. #define PNG_LIBPNG_BUILD_ALPHA 1
  159140. #define PNG_LIBPNG_BUILD_BETA 2
  159141. #define PNG_LIBPNG_BUILD_RC 3
  159142. #define PNG_LIBPNG_BUILD_STABLE 4
  159143. #define PNG_LIBPNG_BUILD_RELEASE_STATUS_MASK 7
  159144. #define PNG_LIBPNG_BUILD_PATCH 8 /* Can be OR'ed with
  159145. PNG_LIBPNG_BUILD_STABLE only */
  159146. #define PNG_LIBPNG_BUILD_PRIVATE 16 /* Cannot be OR'ed with
  159147. PNG_LIBPNG_BUILD_SPECIAL */
  159148. #define PNG_LIBPNG_BUILD_SPECIAL 32 /* Cannot be OR'ed with
  159149. PNG_LIBPNG_BUILD_PRIVATE */
  159150. #define PNG_LIBPNG_BUILD_BASE_TYPE PNG_LIBPNG_BUILD_STABLE
  159151. #define PNG_LIBPNG_VER 10221 /* 1.2.21 */
  159152. #ifndef PNG_VERSION_INFO_ONLY
  159153. #endif
  159154. /*** Start of inlined file: pngconf.h ***/
  159155. #ifndef PNGCONF_H
  159156. #define PNGCONF_H
  159157. #define PNG_1_2_X
  159158. // These are some Juce config settings that should remove any unnecessary code bloat..
  159159. #define PNG_NO_STDIO 1
  159160. #define PNG_DEBUG 0
  159161. #define PNG_NO_WARNINGS 1
  159162. #define PNG_NO_ERROR_TEXT 1
  159163. #define PNG_NO_ERROR_NUMBERS 1
  159164. #define PNG_NO_USER_MEM 1
  159165. #define PNG_NO_READ_iCCP 1
  159166. #define PNG_NO_READ_UNKNOWN_CHUNKS 1
  159167. #define PNG_NO_READ_USER_CHUNKS 1
  159168. #define PNG_NO_READ_iTXt 1
  159169. #define PNG_NO_READ_sCAL 1
  159170. #define PNG_NO_READ_sPLT 1
  159171. #define png_error(a, b) png_err(a)
  159172. #define png_warning(a, b)
  159173. #define png_chunk_error(a, b) png_err(a)
  159174. #define png_chunk_warning(a, b)
  159175. #ifdef PNG_USER_CONFIG
  159176. # ifndef PNG_USER_PRIVATEBUILD
  159177. # define PNG_USER_PRIVATEBUILD
  159178. # endif
  159179. #include "pngusr.h"
  159180. #endif
  159181. #ifdef PNG_CONFIGURE_LIBPNG
  159182. #ifdef HAVE_CONFIG_H
  159183. #include "config.h"
  159184. #endif
  159185. #endif
  159186. #ifdef __STDC__
  159187. #ifdef SPECIALBUILD
  159188. # pragma message("PNG_LIBPNG_SPECIALBUILD (and deprecated SPECIALBUILD)\
  159189. are now LIBPNG reserved macros. Use PNG_USER_PRIVATEBUILD instead.")
  159190. #endif
  159191. #ifdef PRIVATEBUILD
  159192. # pragma message("PRIVATEBUILD is deprecated.\
  159193. Use PNG_USER_PRIVATEBUILD instead.")
  159194. # define PNG_USER_PRIVATEBUILD PRIVATEBUILD
  159195. #endif
  159196. #endif /* __STDC__ */
  159197. #ifndef PNG_VERSION_INFO_ONLY
  159198. # define PNG_WARN_UNINITIALIZED_ROW 1
  159199. #ifndef PNG_ZBUF_SIZE
  159200. # define PNG_ZBUF_SIZE 8192
  159201. #endif
  159202. #ifndef PNG_NO_READ_SUPPORTED
  159203. # define PNG_READ_SUPPORTED
  159204. #endif
  159205. #ifndef PNG_NO_WRITE_SUPPORTED
  159206. # define PNG_WRITE_SUPPORTED
  159207. #endif
  159208. #if !defined(PNG_1_0_X) && !defined(PNG_NO_MNG_FEATURES)
  159209. # ifndef PNG_MNG_FEATURES_SUPPORTED
  159210. # define PNG_MNG_FEATURES_SUPPORTED
  159211. # endif
  159212. #endif
  159213. #ifndef PNG_NO_FLOATING_POINT_SUPPORTED
  159214. # ifndef PNG_FLOATING_POINT_SUPPORTED
  159215. # define PNG_FLOATING_POINT_SUPPORTED
  159216. # endif
  159217. #endif
  159218. #if defined(MAXSEG_64K) && !defined(PNG_MAX_MALLOC_64K)
  159219. # define PNG_MAX_MALLOC_64K
  159220. #endif
  159221. #if defined(__CYGWIN__)
  159222. # if defined(ALL_STATIC)
  159223. # if defined(PNG_BUILD_DLL)
  159224. # undef PNG_BUILD_DLL
  159225. # endif
  159226. # if defined(PNG_USE_DLL)
  159227. # undef PNG_USE_DLL
  159228. # endif
  159229. # if defined(PNG_DLL)
  159230. # undef PNG_DLL
  159231. # endif
  159232. # if !defined(PNG_STATIC)
  159233. # define PNG_STATIC
  159234. # endif
  159235. # else
  159236. # if defined (PNG_BUILD_DLL)
  159237. # if defined(PNG_STATIC)
  159238. # undef PNG_STATIC
  159239. # endif
  159240. # if defined(PNG_USE_DLL)
  159241. # undef PNG_USE_DLL
  159242. # endif
  159243. # if !defined(PNG_DLL)
  159244. # define PNG_DLL
  159245. # endif
  159246. # else
  159247. # if defined(PNG_STATIC)
  159248. # if defined(PNG_USE_DLL)
  159249. # undef PNG_USE_DLL
  159250. # endif
  159251. # if defined(PNG_DLL)
  159252. # undef PNG_DLL
  159253. # endif
  159254. # else
  159255. # if !defined(PNG_USE_DLL)
  159256. # define PNG_USE_DLL
  159257. # endif
  159258. # if !defined(PNG_DLL)
  159259. # define PNG_DLL
  159260. # endif
  159261. # endif
  159262. # endif
  159263. # endif
  159264. #endif
  159265. #if defined(_WIN32_WCE)
  159266. # include <windows.h>
  159267. # define PNG_NO_CONSOLE_IO
  159268. # ifdef PNG_DEBUG
  159269. # undef PNG_DEBUG
  159270. # endif
  159271. #endif
  159272. #ifdef PNG_BUILD_DLL
  159273. # ifndef PNG_CONSOLE_IO_SUPPORTED
  159274. # ifndef PNG_NO_CONSOLE_IO
  159275. # define PNG_NO_CONSOLE_IO
  159276. # endif
  159277. # endif
  159278. #endif
  159279. # ifdef PNG_NO_STDIO
  159280. # ifndef PNG_NO_CONSOLE_IO
  159281. # define PNG_NO_CONSOLE_IO
  159282. # endif
  159283. # ifdef PNG_DEBUG
  159284. # if (PNG_DEBUG > 0)
  159285. # include <stdio.h>
  159286. # endif
  159287. # endif
  159288. # else
  159289. # if !defined(_WIN32_WCE)
  159290. # include <stdio.h>
  159291. # endif
  159292. # endif
  159293. #ifndef PNGARG
  159294. #ifdef OF /* zlib prototype munger */
  159295. # define PNGARG(arglist) OF(arglist)
  159296. #else
  159297. #ifdef _NO_PROTO
  159298. # define PNGARG(arglist) ()
  159299. # ifndef PNG_TYPECAST_NULL
  159300. # define PNG_TYPECAST_NULL
  159301. # endif
  159302. #else
  159303. # define PNGARG(arglist) arglist
  159304. #endif /* _NO_PROTO */
  159305. #endif /* OF */
  159306. #endif /* PNGARG */
  159307. #ifndef MACOS
  159308. # if (defined(__MWERKS__) && defined(macintosh)) || defined(applec) || \
  159309. defined(THINK_C) || defined(__SC__) || defined(TARGET_OS_MAC)
  159310. # define MACOS
  159311. # endif
  159312. #endif
  159313. #if !defined(MACOS) && !defined(RISCOS) && !defined(_WIN32_WCE)
  159314. # include <sys/types.h>
  159315. #endif
  159316. #if !defined(PNG_SETJMP_NOT_SUPPORTED) && !defined(PNG_NO_SETJMP_SUPPORTED)
  159317. # define PNG_SETJMP_SUPPORTED
  159318. #endif
  159319. #ifdef PNG_SETJMP_SUPPORTED
  159320. # ifdef __linux__
  159321. # ifdef _BSD_SOURCE
  159322. # define PNG_SAVE_BSD_SOURCE
  159323. # undef _BSD_SOURCE
  159324. # endif
  159325. # ifdef _SETJMP_H
  159326. __png.h__ already includes setjmp.h;
  159327. __dont__ include it again.;
  159328. # endif
  159329. # endif /* __linux__ */
  159330. # include <setjmp.h>
  159331. # ifdef __linux__
  159332. # ifdef PNG_SAVE_BSD_SOURCE
  159333. # define _BSD_SOURCE
  159334. # undef PNG_SAVE_BSD_SOURCE
  159335. # endif
  159336. # endif /* __linux__ */
  159337. #endif /* PNG_SETJMP_SUPPORTED */
  159338. #ifdef BSD
  159339. #if ! JUCE_MAC
  159340. # include <strings.h>
  159341. #endif
  159342. #else
  159343. # include <string.h>
  159344. #endif
  159345. #ifdef PNG_INTERNAL
  159346. #include <stdlib.h>
  159347. #define PNG_EXTERN
  159348. #if defined(PNG_FLOATING_POINT_SUPPORTED)
  159349. # if defined(MACOS)
  159350. # if !defined(__MATH_H__) && !defined(__MATH_H) && !defined(__cmath__)
  159351. # include <fp.h>
  159352. # endif
  159353. # else
  159354. # include <math.h>
  159355. # endif
  159356. # if defined(_AMIGA) && defined(__SASC) && defined(_M68881)
  159357. # include <m68881.h>
  159358. # endif
  159359. #endif
  159360. #if (defined(__MWERKS__) && defined(WIN32)) || defined(__STDC__)
  159361. # define PNG_ALWAYS_EXTERN
  159362. #endif
  159363. #if defined(__TURBOC__) && defined(__MSDOS__)
  159364. # include <mem.h>
  159365. # include <alloc.h>
  159366. #endif
  159367. #if defined(_MSC_VER) && (defined(WIN32) || defined(_Windows) || \
  159368. defined(_WINDOWS) || defined(_WIN32) || defined(__WIN32__))
  159369. # include <malloc.h>
  159370. #endif
  159371. #ifndef PNG_DITHER_RED_BITS
  159372. # define PNG_DITHER_RED_BITS 5
  159373. #endif
  159374. #ifndef PNG_DITHER_GREEN_BITS
  159375. # define PNG_DITHER_GREEN_BITS 5
  159376. #endif
  159377. #ifndef PNG_DITHER_BLUE_BITS
  159378. # define PNG_DITHER_BLUE_BITS 5
  159379. #endif
  159380. #ifndef PNG_MAX_GAMMA_8
  159381. # define PNG_MAX_GAMMA_8 11
  159382. #endif
  159383. #ifndef PNG_GAMMA_THRESHOLD
  159384. # define PNG_GAMMA_THRESHOLD 0.05
  159385. #endif
  159386. #endif /* PNG_INTERNAL */
  159387. #ifndef PNG_NO_CONST
  159388. # define PNG_CONST const
  159389. #else
  159390. # define PNG_CONST
  159391. #endif
  159392. #if defined(PNG_1_0_X) || defined (PNG_1_2_X)
  159393. # ifndef PNG_NO_iTXt_SUPPORTED
  159394. # define PNG_NO_iTXt_SUPPORTED
  159395. # endif
  159396. # ifndef PNG_NO_READ_iTXt
  159397. # define PNG_NO_READ_iTXt
  159398. # endif
  159399. # ifndef PNG_NO_WRITE_iTXt
  159400. # define PNG_NO_WRITE_iTXt
  159401. # endif
  159402. #endif
  159403. #if !defined(PNG_NO_iTXt_SUPPORTED)
  159404. # if !defined(PNG_READ_iTXt_SUPPORTED) && !defined(PNG_NO_READ_iTXt)
  159405. # define PNG_READ_iTXt
  159406. # endif
  159407. # if !defined(PNG_WRITE_iTXt_SUPPORTED) && !defined(PNG_NO_WRITE_iTXt)
  159408. # define PNG_WRITE_iTXt
  159409. # endif
  159410. #endif
  159411. #ifdef PNG_LEGACY_SUPPORTED
  159412. # define PNG_NO_FREE_ME
  159413. # define PNG_NO_READ_UNKNOWN_CHUNKS
  159414. # define PNG_NO_WRITE_UNKNOWN_CHUNKS
  159415. # define PNG_NO_READ_USER_CHUNKS
  159416. # define PNG_NO_READ_iCCP
  159417. # define PNG_NO_WRITE_iCCP
  159418. # define PNG_NO_READ_iTXt
  159419. # define PNG_NO_WRITE_iTXt
  159420. # define PNG_NO_READ_sCAL
  159421. # define PNG_NO_WRITE_sCAL
  159422. # define PNG_NO_READ_sPLT
  159423. # define PNG_NO_WRITE_sPLT
  159424. # define PNG_NO_INFO_IMAGE
  159425. # define PNG_NO_READ_RGB_TO_GRAY
  159426. # define PNG_NO_READ_USER_TRANSFORM
  159427. # define PNG_NO_WRITE_USER_TRANSFORM
  159428. # define PNG_NO_USER_MEM
  159429. # define PNG_NO_READ_EMPTY_PLTE
  159430. # define PNG_NO_MNG_FEATURES
  159431. # define PNG_NO_FIXED_POINT_SUPPORTED
  159432. #endif
  159433. #if !defined(PNG_FLOATING_POINT_SUPPORTED) || \
  159434. !defined(PNG_NO_FIXED_POINT_SUPPORTED)
  159435. # define PNG_FIXED_POINT_SUPPORTED
  159436. #endif
  159437. #ifndef PNG_NO_FREE_ME
  159438. # define PNG_FREE_ME_SUPPORTED
  159439. #endif
  159440. #if defined(PNG_READ_SUPPORTED)
  159441. #if !defined(PNG_READ_TRANSFORMS_NOT_SUPPORTED) && \
  159442. !defined(PNG_NO_READ_TRANSFORMS)
  159443. # define PNG_READ_TRANSFORMS_SUPPORTED
  159444. #endif
  159445. #ifdef PNG_READ_TRANSFORMS_SUPPORTED
  159446. # ifndef PNG_NO_READ_EXPAND
  159447. # define PNG_READ_EXPAND_SUPPORTED
  159448. # endif
  159449. # ifndef PNG_NO_READ_SHIFT
  159450. # define PNG_READ_SHIFT_SUPPORTED
  159451. # endif
  159452. # ifndef PNG_NO_READ_PACK
  159453. # define PNG_READ_PACK_SUPPORTED
  159454. # endif
  159455. # ifndef PNG_NO_READ_BGR
  159456. # define PNG_READ_BGR_SUPPORTED
  159457. # endif
  159458. # ifndef PNG_NO_READ_SWAP
  159459. # define PNG_READ_SWAP_SUPPORTED
  159460. # endif
  159461. # ifndef PNG_NO_READ_PACKSWAP
  159462. # define PNG_READ_PACKSWAP_SUPPORTED
  159463. # endif
  159464. # ifndef PNG_NO_READ_INVERT
  159465. # define PNG_READ_INVERT_SUPPORTED
  159466. # endif
  159467. # ifndef PNG_NO_READ_DITHER
  159468. # define PNG_READ_DITHER_SUPPORTED
  159469. # endif
  159470. # ifndef PNG_NO_READ_BACKGROUND
  159471. # define PNG_READ_BACKGROUND_SUPPORTED
  159472. # endif
  159473. # ifndef PNG_NO_READ_16_TO_8
  159474. # define PNG_READ_16_TO_8_SUPPORTED
  159475. # endif
  159476. # ifndef PNG_NO_READ_FILLER
  159477. # define PNG_READ_FILLER_SUPPORTED
  159478. # endif
  159479. # ifndef PNG_NO_READ_GAMMA
  159480. # define PNG_READ_GAMMA_SUPPORTED
  159481. # endif
  159482. # ifndef PNG_NO_READ_GRAY_TO_RGB
  159483. # define PNG_READ_GRAY_TO_RGB_SUPPORTED
  159484. # endif
  159485. # ifndef PNG_NO_READ_SWAP_ALPHA
  159486. # define PNG_READ_SWAP_ALPHA_SUPPORTED
  159487. # endif
  159488. # ifndef PNG_NO_READ_INVERT_ALPHA
  159489. # define PNG_READ_INVERT_ALPHA_SUPPORTED
  159490. # endif
  159491. # ifndef PNG_NO_READ_STRIP_ALPHA
  159492. # define PNG_READ_STRIP_ALPHA_SUPPORTED
  159493. # endif
  159494. # ifndef PNG_NO_READ_USER_TRANSFORM
  159495. # define PNG_READ_USER_TRANSFORM_SUPPORTED
  159496. # endif
  159497. # ifndef PNG_NO_READ_RGB_TO_GRAY
  159498. # define PNG_READ_RGB_TO_GRAY_SUPPORTED
  159499. # endif
  159500. #endif /* PNG_READ_TRANSFORMS_SUPPORTED */
  159501. #if !defined(PNG_NO_PROGRESSIVE_READ) && \
  159502. !defined(PNG_PROGRESSIVE_READ_SUPPORTED) /* if you don't do progressive */
  159503. # define PNG_PROGRESSIVE_READ_SUPPORTED /* reading. This is not talking */
  159504. #endif /* about interlacing capability! You'll */
  159505. #define PNG_READ_INTERLACING_SUPPORTED /* required in PNG-compliant decoders */
  159506. #ifndef PNG_NO_READ_COMPOSITE_NODIV
  159507. # ifndef PNG_NO_READ_COMPOSITED_NODIV /* libpng-1.0.x misspelling */
  159508. # define PNG_READ_COMPOSITE_NODIV_SUPPORTED /* well tested on Intel, SGI */
  159509. # endif
  159510. #endif
  159511. #if defined(PNG_1_0_X) || defined (PNG_1_2_X)
  159512. #ifndef PNG_NO_READ_EMPTY_PLTE
  159513. # define PNG_READ_EMPTY_PLTE_SUPPORTED
  159514. #endif
  159515. #endif
  159516. #endif /* PNG_READ_SUPPORTED */
  159517. #if defined(PNG_WRITE_SUPPORTED)
  159518. # if !defined(PNG_WRITE_TRANSFORMS_NOT_SUPPORTED) && \
  159519. !defined(PNG_NO_WRITE_TRANSFORMS)
  159520. # define PNG_WRITE_TRANSFORMS_SUPPORTED
  159521. #endif
  159522. #ifdef PNG_WRITE_TRANSFORMS_SUPPORTED
  159523. # ifndef PNG_NO_WRITE_SHIFT
  159524. # define PNG_WRITE_SHIFT_SUPPORTED
  159525. # endif
  159526. # ifndef PNG_NO_WRITE_PACK
  159527. # define PNG_WRITE_PACK_SUPPORTED
  159528. # endif
  159529. # ifndef PNG_NO_WRITE_BGR
  159530. # define PNG_WRITE_BGR_SUPPORTED
  159531. # endif
  159532. # ifndef PNG_NO_WRITE_SWAP
  159533. # define PNG_WRITE_SWAP_SUPPORTED
  159534. # endif
  159535. # ifndef PNG_NO_WRITE_PACKSWAP
  159536. # define PNG_WRITE_PACKSWAP_SUPPORTED
  159537. # endif
  159538. # ifndef PNG_NO_WRITE_INVERT
  159539. # define PNG_WRITE_INVERT_SUPPORTED
  159540. # endif
  159541. # ifndef PNG_NO_WRITE_FILLER
  159542. # define PNG_WRITE_FILLER_SUPPORTED /* same as WRITE_STRIP_ALPHA */
  159543. # endif
  159544. # ifndef PNG_NO_WRITE_SWAP_ALPHA
  159545. # define PNG_WRITE_SWAP_ALPHA_SUPPORTED
  159546. # endif
  159547. # ifndef PNG_NO_WRITE_INVERT_ALPHA
  159548. # define PNG_WRITE_INVERT_ALPHA_SUPPORTED
  159549. # endif
  159550. # ifndef PNG_NO_WRITE_USER_TRANSFORM
  159551. # define PNG_WRITE_USER_TRANSFORM_SUPPORTED
  159552. # endif
  159553. #endif /* PNG_WRITE_TRANSFORMS_SUPPORTED */
  159554. #if !defined(PNG_NO_WRITE_INTERLACING_SUPPORTED) && \
  159555. !defined(PNG_WRITE_INTERLACING_SUPPORTED)
  159556. #define PNG_WRITE_INTERLACING_SUPPORTED /* not required for PNG-compliant
  159557. encoders, but can cause trouble
  159558. if left undefined */
  159559. #endif
  159560. #if !defined(PNG_NO_WRITE_WEIGHTED_FILTER) && \
  159561. !defined(PNG_WRITE_WEIGHTED_FILTER) && \
  159562. defined(PNG_FLOATING_POINT_SUPPORTED)
  159563. # define PNG_WRITE_WEIGHTED_FILTER_SUPPORTED
  159564. #endif
  159565. #ifndef PNG_NO_WRITE_FLUSH
  159566. # define PNG_WRITE_FLUSH_SUPPORTED
  159567. #endif
  159568. #if defined(PNG_1_0_X) || defined (PNG_1_2_X)
  159569. #ifndef PNG_NO_WRITE_EMPTY_PLTE
  159570. # define PNG_WRITE_EMPTY_PLTE_SUPPORTED
  159571. #endif
  159572. #endif
  159573. #endif /* PNG_WRITE_SUPPORTED */
  159574. #ifndef PNG_1_0_X
  159575. # ifndef PNG_NO_ERROR_NUMBERS
  159576. # define PNG_ERROR_NUMBERS_SUPPORTED
  159577. # endif
  159578. #endif /* PNG_1_0_X */
  159579. #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \
  159580. defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED)
  159581. # ifndef PNG_NO_USER_TRANSFORM_PTR
  159582. # define PNG_USER_TRANSFORM_PTR_SUPPORTED
  159583. # endif
  159584. #endif
  159585. #ifndef PNG_NO_STDIO
  159586. # define PNG_TIME_RFC1123_SUPPORTED
  159587. #endif
  159588. #if !defined(PNG_NO_EASY_ACCESS) && !defined(PNG_EASY_ACCESS_SUPPORTED)
  159589. # define PNG_EASY_ACCESS_SUPPORTED
  159590. #endif
  159591. #if defined(PNG_READ_SUPPORTED) && !defined(PNG_NO_OPTIMIZED_CODE)
  159592. # ifndef PNG_OPTIMIZED_CODE_SUPPORTED
  159593. # define PNG_OPTIMIZED_CODE_SUPPORTED
  159594. # endif
  159595. #endif
  159596. #if defined(PNG_READ_SUPPORTED) && !defined(PNG_NO_ASSEMBLER_CODE)
  159597. # ifndef PNG_ASSEMBLER_CODE_SUPPORTED
  159598. # define PNG_ASSEMBLER_CODE_SUPPORTED
  159599. # endif
  159600. # if defined(__GNUC__) && defined(__x86_64__) && (__GNUC__ < 4)
  159601. # if !defined(PNG_MMX_CODE_SUPPORTED) && !defined(PNG_NO_MMX_CODE)
  159602. # define PNG_NO_MMX_CODE
  159603. # endif
  159604. # endif
  159605. # if defined(__APPLE__)
  159606. # if !defined(PNG_MMX_CODE_SUPPORTED) && !defined(PNG_NO_MMX_CODE)
  159607. # define PNG_NO_MMX_CODE
  159608. # endif
  159609. # endif
  159610. # if (defined(__MWERKS__) && ((__MWERKS__ < 0x0900) || macintosh))
  159611. # if !defined(PNG_MMX_CODE_SUPPORTED) && !defined(PNG_NO_MMX_CODE)
  159612. # define PNG_NO_MMX_CODE
  159613. # endif
  159614. # endif
  159615. # if !defined(PNG_MMX_CODE_SUPPORTED) && !defined(PNG_NO_MMX_CODE)
  159616. # define PNG_MMX_CODE_SUPPORTED
  159617. # endif
  159618. #endif
  159619. #if !defined(PNG_1_0_X)
  159620. #if !defined(PNG_NO_USER_MEM) && !defined(PNG_USER_MEM_SUPPORTED)
  159621. # define PNG_USER_MEM_SUPPORTED
  159622. #endif
  159623. #endif /* PNG_1_0_X */
  159624. #if !defined(PNG_1_0_X)
  159625. #ifndef PNG_SET_USER_LIMITS_SUPPORTED
  159626. #if !defined(PNG_NO_SET_USER_LIMITS) && !defined(PNG_SET_USER_LIMITS_SUPPORTED)
  159627. # define PNG_SET_USER_LIMITS_SUPPORTED
  159628. #endif
  159629. #endif
  159630. #endif /* PNG_1_0_X */
  159631. #ifndef PNG_USER_WIDTH_MAX
  159632. # define PNG_USER_WIDTH_MAX 1000000L
  159633. #endif
  159634. #ifndef PNG_USER_HEIGHT_MAX
  159635. # define PNG_USER_HEIGHT_MAX 1000000L
  159636. #endif
  159637. #if defined(PNG_READ_SUPPORTED) && \
  159638. !defined(PNG_READ_ANCILLARY_CHUNKS_NOT_SUPPORTED) && \
  159639. !defined(PNG_NO_READ_ANCILLARY_CHUNKS)
  159640. # define PNG_READ_ANCILLARY_CHUNKS_SUPPORTED
  159641. #endif
  159642. #if defined(PNG_WRITE_SUPPORTED) && \
  159643. !defined(PNG_WRITE_ANCILLARY_CHUNKS_NOT_SUPPORTED) && \
  159644. !defined(PNG_NO_WRITE_ANCILLARY_CHUNKS)
  159645. # define PNG_WRITE_ANCILLARY_CHUNKS_SUPPORTED
  159646. #endif
  159647. #ifdef PNG_READ_ANCILLARY_CHUNKS_SUPPORTED
  159648. #ifdef PNG_NO_READ_TEXT
  159649. # define PNG_NO_READ_iTXt
  159650. # define PNG_NO_READ_tEXt
  159651. # define PNG_NO_READ_zTXt
  159652. #endif
  159653. #ifndef PNG_NO_READ_bKGD
  159654. # define PNG_READ_bKGD_SUPPORTED
  159655. # define PNG_bKGD_SUPPORTED
  159656. #endif
  159657. #ifndef PNG_NO_READ_cHRM
  159658. # define PNG_READ_cHRM_SUPPORTED
  159659. # define PNG_cHRM_SUPPORTED
  159660. #endif
  159661. #ifndef PNG_NO_READ_gAMA
  159662. # define PNG_READ_gAMA_SUPPORTED
  159663. # define PNG_gAMA_SUPPORTED
  159664. #endif
  159665. #ifndef PNG_NO_READ_hIST
  159666. # define PNG_READ_hIST_SUPPORTED
  159667. # define PNG_hIST_SUPPORTED
  159668. #endif
  159669. #ifndef PNG_NO_READ_iCCP
  159670. # define PNG_READ_iCCP_SUPPORTED
  159671. # define PNG_iCCP_SUPPORTED
  159672. #endif
  159673. #ifndef PNG_NO_READ_iTXt
  159674. # ifndef PNG_READ_iTXt_SUPPORTED
  159675. # define PNG_READ_iTXt_SUPPORTED
  159676. # endif
  159677. # ifndef PNG_iTXt_SUPPORTED
  159678. # define PNG_iTXt_SUPPORTED
  159679. # endif
  159680. #endif
  159681. #ifndef PNG_NO_READ_oFFs
  159682. # define PNG_READ_oFFs_SUPPORTED
  159683. # define PNG_oFFs_SUPPORTED
  159684. #endif
  159685. #ifndef PNG_NO_READ_pCAL
  159686. # define PNG_READ_pCAL_SUPPORTED
  159687. # define PNG_pCAL_SUPPORTED
  159688. #endif
  159689. #ifndef PNG_NO_READ_sCAL
  159690. # define PNG_READ_sCAL_SUPPORTED
  159691. # define PNG_sCAL_SUPPORTED
  159692. #endif
  159693. #ifndef PNG_NO_READ_pHYs
  159694. # define PNG_READ_pHYs_SUPPORTED
  159695. # define PNG_pHYs_SUPPORTED
  159696. #endif
  159697. #ifndef PNG_NO_READ_sBIT
  159698. # define PNG_READ_sBIT_SUPPORTED
  159699. # define PNG_sBIT_SUPPORTED
  159700. #endif
  159701. #ifndef PNG_NO_READ_sPLT
  159702. # define PNG_READ_sPLT_SUPPORTED
  159703. # define PNG_sPLT_SUPPORTED
  159704. #endif
  159705. #ifndef PNG_NO_READ_sRGB
  159706. # define PNG_READ_sRGB_SUPPORTED
  159707. # define PNG_sRGB_SUPPORTED
  159708. #endif
  159709. #ifndef PNG_NO_READ_tEXt
  159710. # define PNG_READ_tEXt_SUPPORTED
  159711. # define PNG_tEXt_SUPPORTED
  159712. #endif
  159713. #ifndef PNG_NO_READ_tIME
  159714. # define PNG_READ_tIME_SUPPORTED
  159715. # define PNG_tIME_SUPPORTED
  159716. #endif
  159717. #ifndef PNG_NO_READ_tRNS
  159718. # define PNG_READ_tRNS_SUPPORTED
  159719. # define PNG_tRNS_SUPPORTED
  159720. #endif
  159721. #ifndef PNG_NO_READ_zTXt
  159722. # define PNG_READ_zTXt_SUPPORTED
  159723. # define PNG_zTXt_SUPPORTED
  159724. #endif
  159725. #ifndef PNG_NO_READ_UNKNOWN_CHUNKS
  159726. # define PNG_READ_UNKNOWN_CHUNKS_SUPPORTED
  159727. # ifndef PNG_UNKNOWN_CHUNKS_SUPPORTED
  159728. # define PNG_UNKNOWN_CHUNKS_SUPPORTED
  159729. # endif
  159730. # ifndef PNG_NO_HANDLE_AS_UNKNOWN
  159731. # define PNG_HANDLE_AS_UNKNOWN_SUPPORTED
  159732. # endif
  159733. #endif
  159734. #if !defined(PNG_NO_READ_USER_CHUNKS) && \
  159735. defined(PNG_READ_UNKNOWN_CHUNKS_SUPPORTED)
  159736. # define PNG_READ_USER_CHUNKS_SUPPORTED
  159737. # define PNG_USER_CHUNKS_SUPPORTED
  159738. # ifdef PNG_NO_READ_UNKNOWN_CHUNKS
  159739. # undef PNG_NO_READ_UNKNOWN_CHUNKS
  159740. # endif
  159741. # ifdef PNG_NO_HANDLE_AS_UNKNOWN
  159742. # undef PNG_NO_HANDLE_AS_UNKNOWN
  159743. # endif
  159744. #endif
  159745. #ifndef PNG_NO_READ_OPT_PLTE
  159746. # define PNG_READ_OPT_PLTE_SUPPORTED /* only affects support of the */
  159747. #endif /* optional PLTE chunk in RGB and RGBA images */
  159748. #if defined(PNG_READ_iTXt_SUPPORTED) || defined(PNG_READ_tEXt_SUPPORTED) || \
  159749. defined(PNG_READ_zTXt_SUPPORTED)
  159750. # define PNG_READ_TEXT_SUPPORTED
  159751. # define PNG_TEXT_SUPPORTED
  159752. #endif
  159753. #endif /* PNG_READ_ANCILLARY_CHUNKS_SUPPORTED */
  159754. #ifdef PNG_WRITE_ANCILLARY_CHUNKS_SUPPORTED
  159755. #ifdef PNG_NO_WRITE_TEXT
  159756. # define PNG_NO_WRITE_iTXt
  159757. # define PNG_NO_WRITE_tEXt
  159758. # define PNG_NO_WRITE_zTXt
  159759. #endif
  159760. #ifndef PNG_NO_WRITE_bKGD
  159761. # define PNG_WRITE_bKGD_SUPPORTED
  159762. # ifndef PNG_bKGD_SUPPORTED
  159763. # define PNG_bKGD_SUPPORTED
  159764. # endif
  159765. #endif
  159766. #ifndef PNG_NO_WRITE_cHRM
  159767. # define PNG_WRITE_cHRM_SUPPORTED
  159768. # ifndef PNG_cHRM_SUPPORTED
  159769. # define PNG_cHRM_SUPPORTED
  159770. # endif
  159771. #endif
  159772. #ifndef PNG_NO_WRITE_gAMA
  159773. # define PNG_WRITE_gAMA_SUPPORTED
  159774. # ifndef PNG_gAMA_SUPPORTED
  159775. # define PNG_gAMA_SUPPORTED
  159776. # endif
  159777. #endif
  159778. #ifndef PNG_NO_WRITE_hIST
  159779. # define PNG_WRITE_hIST_SUPPORTED
  159780. # ifndef PNG_hIST_SUPPORTED
  159781. # define PNG_hIST_SUPPORTED
  159782. # endif
  159783. #endif
  159784. #ifndef PNG_NO_WRITE_iCCP
  159785. # define PNG_WRITE_iCCP_SUPPORTED
  159786. # ifndef PNG_iCCP_SUPPORTED
  159787. # define PNG_iCCP_SUPPORTED
  159788. # endif
  159789. #endif
  159790. #ifndef PNG_NO_WRITE_iTXt
  159791. # ifndef PNG_WRITE_iTXt_SUPPORTED
  159792. # define PNG_WRITE_iTXt_SUPPORTED
  159793. # endif
  159794. # ifndef PNG_iTXt_SUPPORTED
  159795. # define PNG_iTXt_SUPPORTED
  159796. # endif
  159797. #endif
  159798. #ifndef PNG_NO_WRITE_oFFs
  159799. # define PNG_WRITE_oFFs_SUPPORTED
  159800. # ifndef PNG_oFFs_SUPPORTED
  159801. # define PNG_oFFs_SUPPORTED
  159802. # endif
  159803. #endif
  159804. #ifndef PNG_NO_WRITE_pCAL
  159805. # define PNG_WRITE_pCAL_SUPPORTED
  159806. # ifndef PNG_pCAL_SUPPORTED
  159807. # define PNG_pCAL_SUPPORTED
  159808. # endif
  159809. #endif
  159810. #ifndef PNG_NO_WRITE_sCAL
  159811. # define PNG_WRITE_sCAL_SUPPORTED
  159812. # ifndef PNG_sCAL_SUPPORTED
  159813. # define PNG_sCAL_SUPPORTED
  159814. # endif
  159815. #endif
  159816. #ifndef PNG_NO_WRITE_pHYs
  159817. # define PNG_WRITE_pHYs_SUPPORTED
  159818. # ifndef PNG_pHYs_SUPPORTED
  159819. # define PNG_pHYs_SUPPORTED
  159820. # endif
  159821. #endif
  159822. #ifndef PNG_NO_WRITE_sBIT
  159823. # define PNG_WRITE_sBIT_SUPPORTED
  159824. # ifndef PNG_sBIT_SUPPORTED
  159825. # define PNG_sBIT_SUPPORTED
  159826. # endif
  159827. #endif
  159828. #ifndef PNG_NO_WRITE_sPLT
  159829. # define PNG_WRITE_sPLT_SUPPORTED
  159830. # ifndef PNG_sPLT_SUPPORTED
  159831. # define PNG_sPLT_SUPPORTED
  159832. # endif
  159833. #endif
  159834. #ifndef PNG_NO_WRITE_sRGB
  159835. # define PNG_WRITE_sRGB_SUPPORTED
  159836. # ifndef PNG_sRGB_SUPPORTED
  159837. # define PNG_sRGB_SUPPORTED
  159838. # endif
  159839. #endif
  159840. #ifndef PNG_NO_WRITE_tEXt
  159841. # define PNG_WRITE_tEXt_SUPPORTED
  159842. # ifndef PNG_tEXt_SUPPORTED
  159843. # define PNG_tEXt_SUPPORTED
  159844. # endif
  159845. #endif
  159846. #ifndef PNG_NO_WRITE_tIME
  159847. # define PNG_WRITE_tIME_SUPPORTED
  159848. # ifndef PNG_tIME_SUPPORTED
  159849. # define PNG_tIME_SUPPORTED
  159850. # endif
  159851. #endif
  159852. #ifndef PNG_NO_WRITE_tRNS
  159853. # define PNG_WRITE_tRNS_SUPPORTED
  159854. # ifndef PNG_tRNS_SUPPORTED
  159855. # define PNG_tRNS_SUPPORTED
  159856. # endif
  159857. #endif
  159858. #ifndef PNG_NO_WRITE_zTXt
  159859. # define PNG_WRITE_zTXt_SUPPORTED
  159860. # ifndef PNG_zTXt_SUPPORTED
  159861. # define PNG_zTXt_SUPPORTED
  159862. # endif
  159863. #endif
  159864. #ifndef PNG_NO_WRITE_UNKNOWN_CHUNKS
  159865. # define PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED
  159866. # ifndef PNG_UNKNOWN_CHUNKS_SUPPORTED
  159867. # define PNG_UNKNOWN_CHUNKS_SUPPORTED
  159868. # endif
  159869. # ifndef PNG_NO_HANDLE_AS_UNKNOWN
  159870. # ifndef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
  159871. # define PNG_HANDLE_AS_UNKNOWN_SUPPORTED
  159872. # endif
  159873. # endif
  159874. #endif
  159875. #if defined(PNG_WRITE_iTXt_SUPPORTED) || defined(PNG_WRITE_tEXt_SUPPORTED) || \
  159876. defined(PNG_WRITE_zTXt_SUPPORTED)
  159877. # define PNG_WRITE_TEXT_SUPPORTED
  159878. # ifndef PNG_TEXT_SUPPORTED
  159879. # define PNG_TEXT_SUPPORTED
  159880. # endif
  159881. #endif
  159882. #endif /* PNG_WRITE_ANCILLARY_CHUNKS_SUPPORTED */
  159883. #ifndef PNG_NO_INFO_IMAGE
  159884. # define PNG_INFO_IMAGE_SUPPORTED
  159885. #endif
  159886. #if defined(PNG_tIME_SUPPORTED)
  159887. # if !defined(_WIN32_WCE)
  159888. # include <time.h>
  159889. # endif
  159890. #endif
  159891. typedef unsigned long png_uint_32;
  159892. typedef long png_int_32;
  159893. typedef unsigned short png_uint_16;
  159894. typedef short png_int_16;
  159895. typedef unsigned char png_byte;
  159896. #ifdef PNG_SIZE_T
  159897. typedef PNG_SIZE_T png_size_t;
  159898. # define png_sizeof(x) png_convert_size(sizeof (x))
  159899. #else
  159900. typedef size_t png_size_t;
  159901. # define png_sizeof(x) sizeof (x)
  159902. #endif
  159903. #ifdef __BORLANDC__
  159904. # if defined(__LARGE__) || defined(__HUGE__) || defined(__COMPACT__)
  159905. # define LDATA 1
  159906. # else
  159907. # define LDATA 0
  159908. # endif
  159909. # if !defined(__WIN32__) && !defined(__FLAT__) && !defined(__CYGWIN__)
  159910. # define PNG_MAX_MALLOC_64K
  159911. # if (LDATA != 1)
  159912. # ifndef FAR
  159913. # define FAR __far
  159914. # endif
  159915. # define USE_FAR_KEYWORD
  159916. # endif /* LDATA != 1 */
  159917. # endif /* __WIN32__, __FLAT__, __CYGWIN__ */
  159918. #endif /* __BORLANDC__ */
  159919. #if defined(FAR)
  159920. # if defined(M_I86MM)
  159921. # define USE_FAR_KEYWORD
  159922. # define FARDATA FAR
  159923. # include <dos.h>
  159924. # endif
  159925. #endif
  159926. #ifndef FAR
  159927. # define FAR
  159928. #endif
  159929. #ifndef FARDATA
  159930. # define FARDATA
  159931. #endif
  159932. typedef png_int_32 png_fixed_point;
  159933. typedef void FAR * png_voidp;
  159934. typedef png_byte FAR * png_bytep;
  159935. typedef png_uint_32 FAR * png_uint_32p;
  159936. typedef png_int_32 FAR * png_int_32p;
  159937. typedef png_uint_16 FAR * png_uint_16p;
  159938. typedef png_int_16 FAR * png_int_16p;
  159939. typedef PNG_CONST char FAR * png_const_charp;
  159940. typedef char FAR * png_charp;
  159941. typedef png_fixed_point FAR * png_fixed_point_p;
  159942. #ifndef PNG_NO_STDIO
  159943. #if defined(_WIN32_WCE)
  159944. typedef HANDLE png_FILE_p;
  159945. #else
  159946. typedef FILE * png_FILE_p;
  159947. #endif
  159948. #endif
  159949. #ifdef PNG_FLOATING_POINT_SUPPORTED
  159950. typedef double FAR * png_doublep;
  159951. #endif
  159952. typedef png_byte FAR * FAR * png_bytepp;
  159953. typedef png_uint_32 FAR * FAR * png_uint_32pp;
  159954. typedef png_int_32 FAR * FAR * png_int_32pp;
  159955. typedef png_uint_16 FAR * FAR * png_uint_16pp;
  159956. typedef png_int_16 FAR * FAR * png_int_16pp;
  159957. typedef PNG_CONST char FAR * FAR * png_const_charpp;
  159958. typedef char FAR * FAR * png_charpp;
  159959. typedef png_fixed_point FAR * FAR * png_fixed_point_pp;
  159960. #ifdef PNG_FLOATING_POINT_SUPPORTED
  159961. typedef double FAR * FAR * png_doublepp;
  159962. #endif
  159963. typedef char FAR * FAR * FAR * png_charppp;
  159964. #if 0
  159965. typedef charf * png_zcharp;
  159966. typedef charf * FAR * png_zcharpp;
  159967. typedef z_stream FAR * png_zstreamp;
  159968. #endif /* (PNG_1_0_X) || defined(PNG_1_2_X) */
  159969. #if !defined(PNG_DLL) && (defined(PNG_BUILD_DLL) || defined(PNG_USE_DLL))
  159970. # define PNG_DLL
  159971. #endif
  159972. #if defined(__CYGWIN__)
  159973. # if !defined(PNG_STATIC)
  159974. # if defined(PNG_USE_GLOBAL_ARRAYS)
  159975. # undef PNG_USE_GLOBAL_ARRAYS
  159976. # endif
  159977. # if !defined(PNG_USE_LOCAL_ARRAYS)
  159978. # define PNG_USE_LOCAL_ARRAYS
  159979. # endif
  159980. # else
  159981. # if defined(PNG_USE_LOCAL_ARRAYS) || defined(PNG_NO_GLOBAL_ARRAYS)
  159982. # if defined(PNG_USE_GLOBAL_ARRAYS)
  159983. # undef PNG_USE_GLOBAL_ARRAYS
  159984. # endif
  159985. # endif
  159986. # endif
  159987. # if !defined(PNG_USE_LOCAL_ARRAYS) && !defined(PNG_USE_GLOBAL_ARRAYS)
  159988. # define PNG_USE_LOCAL_ARRAYS
  159989. # endif
  159990. #endif
  159991. #if !defined(PNG_USE_LOCAL_ARRAYS) && !defined(PNG_USE_GLOBAL_ARRAYS)
  159992. # if defined(PNG_NO_GLOBAL_ARRAYS) || \
  159993. (defined(__GNUC__) && defined(PNG_DLL)) || defined(_MSC_VER)
  159994. # define PNG_USE_LOCAL_ARRAYS
  159995. # else
  159996. # define PNG_USE_GLOBAL_ARRAYS
  159997. # endif
  159998. #endif
  159999. #if defined(__CYGWIN__)
  160000. # undef PNGAPI
  160001. # define PNGAPI __cdecl
  160002. # undef PNG_IMPEXP
  160003. # define PNG_IMPEXP
  160004. #endif
  160005. #if defined(__MINGW32__) && !defined(PNG_MODULEDEF)
  160006. # ifndef PNG_NO_MODULEDEF
  160007. # define PNG_NO_MODULEDEF
  160008. # endif
  160009. #endif
  160010. #if !defined(PNG_IMPEXP) && defined(PNG_BUILD_DLL) && !defined(PNG_NO_MODULEDEF)
  160011. # define PNG_IMPEXP
  160012. #endif
  160013. #if defined(PNG_DLL) || defined(_DLL) || defined(__DLL__ ) || \
  160014. (( defined(_Windows) || defined(_WINDOWS) || \
  160015. defined(WIN32) || defined(_WIN32) || defined(__WIN32__) ))
  160016. # ifndef PNGAPI
  160017. # if defined(__GNUC__) || (defined (_MSC_VER) && (_MSC_VER >= 800))
  160018. # define PNGAPI __cdecl
  160019. # else
  160020. # define PNGAPI _cdecl
  160021. # endif
  160022. # endif
  160023. # if !defined(PNG_IMPEXP) && (!defined(PNG_DLL) || \
  160024. 0 /* WINCOMPILER_WITH_NO_SUPPORT_FOR_DECLIMPEXP */)
  160025. # define PNG_IMPEXP
  160026. # endif
  160027. # if !defined(PNG_IMPEXP)
  160028. # define PNG_EXPORT_TYPE1(type,symbol) PNG_IMPEXP type PNGAPI symbol
  160029. # define PNG_EXPORT_TYPE2(type,symbol) type PNG_IMPEXP PNGAPI symbol
  160030. # if defined(_MSC_VER) || defined(__BORLANDC__)
  160031. # if (_MSC_VER >= 800) || (__BORLANDC__ >= 0x500)
  160032. # define PNG_EXPORT PNG_EXPORT_TYPE1
  160033. # else
  160034. # define PNG_EXPORT PNG_EXPORT_TYPE2
  160035. # if defined(PNG_BUILD_DLL)
  160036. # define PNG_IMPEXP __export
  160037. # else
  160038. # define PNG_IMPEXP /*__import */ /* doesn't exist AFAIK in
  160039. VC++ */
  160040. # endif /* Exists in Borland C++ for
  160041. C++ classes (== huge) */
  160042. # endif
  160043. # endif
  160044. # if !defined(PNG_IMPEXP)
  160045. # if defined(PNG_BUILD_DLL)
  160046. # define PNG_IMPEXP __declspec(dllexport)
  160047. # else
  160048. # define PNG_IMPEXP __declspec(dllimport)
  160049. # endif
  160050. # endif
  160051. # endif /* PNG_IMPEXP */
  160052. #else /* !(DLL || non-cygwin WINDOWS) */
  160053. # if (defined(__IBMC__) || defined(__IBMCPP__)) && defined(__OS2__)
  160054. # ifndef PNGAPI
  160055. # define PNGAPI _System
  160056. # endif
  160057. # else
  160058. # if 0 /* ... other platforms, with other meanings */
  160059. # endif
  160060. # endif
  160061. #endif
  160062. #ifndef PNGAPI
  160063. # define PNGAPI
  160064. #endif
  160065. #ifndef PNG_IMPEXP
  160066. # define PNG_IMPEXP
  160067. #endif
  160068. #ifdef PNG_BUILDSYMS
  160069. # ifndef PNG_EXPORT
  160070. # define PNG_EXPORT(type,symbol) PNG_FUNCTION_EXPORT symbol END
  160071. # endif
  160072. # ifdef PNG_USE_GLOBAL_ARRAYS
  160073. # ifndef PNG_EXPORT_VAR
  160074. # define PNG_EXPORT_VAR(type) PNG_DATA_EXPORT
  160075. # endif
  160076. # endif
  160077. #endif
  160078. #ifndef PNG_EXPORT
  160079. # define PNG_EXPORT(type,symbol) PNG_IMPEXP type PNGAPI symbol
  160080. #endif
  160081. #ifdef PNG_USE_GLOBAL_ARRAYS
  160082. # ifndef PNG_EXPORT_VAR
  160083. # define PNG_EXPORT_VAR(type) extern PNG_IMPEXP type
  160084. # endif
  160085. #endif
  160086. #ifndef PNG_ABORT
  160087. # define PNG_ABORT() abort()
  160088. #endif
  160089. #ifdef PNG_SETJMP_SUPPORTED
  160090. # define png_jmpbuf(png_ptr) ((png_ptr)->jmpbuf)
  160091. #else
  160092. # define png_jmpbuf(png_ptr) \
  160093. (LIBPNG_WAS_COMPILED_WITH__PNG_SETJMP_NOT_SUPPORTED)
  160094. #endif
  160095. #if defined(USE_FAR_KEYWORD) /* memory model independent fns */
  160096. # define CHECK 1
  160097. # define NOCHECK 0
  160098. # define CVT_PTR(ptr) (png_far_to_near(png_ptr,ptr,CHECK))
  160099. # define CVT_PTR_NOCHECK(ptr) (png_far_to_near(png_ptr,ptr,NOCHECK))
  160100. # define png_snprintf _fsnprintf /* Added to v 1.2.19 */
  160101. # define png_strcpy _fstrcpy
  160102. # define png_strncpy _fstrncpy /* Added to v 1.2.6 */
  160103. # define png_strlen _fstrlen
  160104. # define png_memcmp _fmemcmp /* SJT: added */
  160105. # define png_memcpy _fmemcpy
  160106. # define png_memset _fmemset
  160107. #else /* use the usual functions */
  160108. # define CVT_PTR(ptr) (ptr)
  160109. # define CVT_PTR_NOCHECK(ptr) (ptr)
  160110. # ifndef PNG_NO_SNPRINTF
  160111. # ifdef _MSC_VER
  160112. # define png_snprintf _snprintf /* Added to v 1.2.19 */
  160113. # define png_snprintf2 _snprintf
  160114. # define png_snprintf6 _snprintf
  160115. # else
  160116. # define png_snprintf snprintf /* Added to v 1.2.19 */
  160117. # define png_snprintf2 snprintf
  160118. # define png_snprintf6 snprintf
  160119. # endif
  160120. # else
  160121. # define png_snprintf(s1,n,fmt,x1) sprintf(s1,fmt,x1)
  160122. # define png_snprintf2(s1,n,fmt,x1,x2) sprintf(s1,fmt,x1,x2)
  160123. # define png_snprintf6(s1,n,fmt,x1,x2,x3,x4,x5,x6) \
  160124. sprintf(s1,fmt,x1,x2,x3,x4,x5,x6)
  160125. # endif
  160126. # define png_strcpy strcpy
  160127. # define png_strncpy strncpy /* Added to v 1.2.6 */
  160128. # define png_strlen strlen
  160129. # define png_memcmp memcmp /* SJT: added */
  160130. # define png_memcpy memcpy
  160131. # define png_memset memset
  160132. #endif
  160133. #if (PNG_ZBUF_SIZE > 65536L) && defined(PNG_MAX_MALLOC_64K)
  160134. # undef PNG_ZBUF_SIZE
  160135. # define PNG_ZBUF_SIZE 65536L
  160136. #endif
  160137. #endif /* PNG_VERSION_INFO_ONLY */
  160138. #endif /* PNGCONF_H */
  160139. /*** End of inlined file: pngconf.h ***/
  160140. #ifdef _MSC_VER
  160141. #pragma warning (disable: 4996 4100)
  160142. #endif
  160143. #if defined(PNG_USER_PRIVATEBUILD)
  160144. # define PNG_LIBPNG_BUILD_TYPE \
  160145. (PNG_LIBPNG_BUILD_BASE_TYPE | PNG_LIBPNG_BUILD_PRIVATE)
  160146. #else
  160147. # if defined(PNG_LIBPNG_SPECIALBUILD)
  160148. # define PNG_LIBPNG_BUILD_TYPE \
  160149. (PNG_LIBPNG_BUILD_BASE_TYPE | PNG_LIBPNG_BUILD_SPECIAL)
  160150. # else
  160151. # define PNG_LIBPNG_BUILD_TYPE (PNG_LIBPNG_BUILD_BASE_TYPE)
  160152. # endif
  160153. #endif
  160154. #ifndef PNG_VERSION_INFO_ONLY
  160155. #ifdef __cplusplus
  160156. extern "C" {
  160157. #endif /* __cplusplus */
  160158. #ifndef PNG_NO_TYPECAST_NULL
  160159. #define int_p_NULL (int *)NULL
  160160. #define png_bytep_NULL (png_bytep)NULL
  160161. #define png_bytepp_NULL (png_bytepp)NULL
  160162. #define png_doublep_NULL (png_doublep)NULL
  160163. #define png_error_ptr_NULL (png_error_ptr)NULL
  160164. #define png_flush_ptr_NULL (png_flush_ptr)NULL
  160165. #define png_free_ptr_NULL (png_free_ptr)NULL
  160166. #define png_infopp_NULL (png_infopp)NULL
  160167. #define png_malloc_ptr_NULL (png_malloc_ptr)NULL
  160168. #define png_read_status_ptr_NULL (png_read_status_ptr)NULL
  160169. #define png_rw_ptr_NULL (png_rw_ptr)NULL
  160170. #define png_structp_NULL (png_structp)NULL
  160171. #define png_uint_16p_NULL (png_uint_16p)NULL
  160172. #define png_voidp_NULL (png_voidp)NULL
  160173. #define png_write_status_ptr_NULL (png_write_status_ptr)NULL
  160174. #else
  160175. #define int_p_NULL NULL
  160176. #define png_bytep_NULL NULL
  160177. #define png_bytepp_NULL NULL
  160178. #define png_doublep_NULL NULL
  160179. #define png_error_ptr_NULL NULL
  160180. #define png_flush_ptr_NULL NULL
  160181. #define png_free_ptr_NULL NULL
  160182. #define png_infopp_NULL NULL
  160183. #define png_malloc_ptr_NULL NULL
  160184. #define png_read_status_ptr_NULL NULL
  160185. #define png_rw_ptr_NULL NULL
  160186. #define png_structp_NULL NULL
  160187. #define png_uint_16p_NULL NULL
  160188. #define png_voidp_NULL NULL
  160189. #define png_write_status_ptr_NULL NULL
  160190. #endif
  160191. #if !defined(PNG_NO_EXTERN) || defined(PNG_ALWAYS_EXTERN)
  160192. #ifdef PNG_USE_GLOBAL_ARRAYS
  160193. PNG_EXPORT_VAR (PNG_CONST char) png_libpng_ver[18];
  160194. #else
  160195. #define png_libpng_ver png_get_header_ver(NULL)
  160196. #endif
  160197. #ifdef PNG_USE_GLOBAL_ARRAYS
  160198. PNG_EXPORT_VAR (PNG_CONST int FARDATA) png_pass_start[7];
  160199. PNG_EXPORT_VAR (PNG_CONST int FARDATA) png_pass_inc[7];
  160200. PNG_EXPORT_VAR (PNG_CONST int FARDATA) png_pass_ystart[7];
  160201. PNG_EXPORT_VAR (PNG_CONST int FARDATA) png_pass_yinc[7];
  160202. PNG_EXPORT_VAR (PNG_CONST int FARDATA) png_pass_mask[7];
  160203. PNG_EXPORT_VAR (PNG_CONST int FARDATA) png_pass_dsp_mask[7];
  160204. #endif
  160205. #endif /* PNG_NO_EXTERN */
  160206. typedef struct png_color_struct
  160207. {
  160208. png_byte red;
  160209. png_byte green;
  160210. png_byte blue;
  160211. } png_color;
  160212. typedef png_color FAR * png_colorp;
  160213. typedef png_color FAR * FAR * png_colorpp;
  160214. typedef struct png_color_16_struct
  160215. {
  160216. png_byte index; /* used for palette files */
  160217. png_uint_16 red; /* for use in red green blue files */
  160218. png_uint_16 green;
  160219. png_uint_16 blue;
  160220. png_uint_16 gray; /* for use in grayscale files */
  160221. } png_color_16;
  160222. typedef png_color_16 FAR * png_color_16p;
  160223. typedef png_color_16 FAR * FAR * png_color_16pp;
  160224. typedef struct png_color_8_struct
  160225. {
  160226. png_byte red; /* for use in red green blue files */
  160227. png_byte green;
  160228. png_byte blue;
  160229. png_byte gray; /* for use in grayscale files */
  160230. png_byte alpha; /* for alpha channel files */
  160231. } png_color_8;
  160232. typedef png_color_8 FAR * png_color_8p;
  160233. typedef png_color_8 FAR * FAR * png_color_8pp;
  160234. typedef struct png_sPLT_entry_struct
  160235. {
  160236. png_uint_16 red;
  160237. png_uint_16 green;
  160238. png_uint_16 blue;
  160239. png_uint_16 alpha;
  160240. png_uint_16 frequency;
  160241. } png_sPLT_entry;
  160242. typedef png_sPLT_entry FAR * png_sPLT_entryp;
  160243. typedef png_sPLT_entry FAR * FAR * png_sPLT_entrypp;
  160244. typedef struct png_sPLT_struct
  160245. {
  160246. png_charp name; /* palette name */
  160247. png_byte depth; /* depth of palette samples */
  160248. png_sPLT_entryp entries; /* palette entries */
  160249. png_int_32 nentries; /* number of palette entries */
  160250. } png_sPLT_t;
  160251. typedef png_sPLT_t FAR * png_sPLT_tp;
  160252. typedef png_sPLT_t FAR * FAR * png_sPLT_tpp;
  160253. #ifdef PNG_TEXT_SUPPORTED
  160254. typedef struct png_text_struct
  160255. {
  160256. int compression; /* compression value:
  160257. -1: tEXt, none
  160258. 0: zTXt, deflate
  160259. 1: iTXt, none
  160260. 2: iTXt, deflate */
  160261. png_charp key; /* keyword, 1-79 character description of "text" */
  160262. png_charp text; /* comment, may be an empty string (ie "")
  160263. or a NULL pointer */
  160264. png_size_t text_length; /* length of the text string */
  160265. #ifdef PNG_iTXt_SUPPORTED
  160266. png_size_t itxt_length; /* length of the itxt string */
  160267. png_charp lang; /* language code, 0-79 characters
  160268. or a NULL pointer */
  160269. png_charp lang_key; /* keyword translated UTF-8 string, 0 or more
  160270. chars or a NULL pointer */
  160271. #endif
  160272. } png_text;
  160273. typedef png_text FAR * png_textp;
  160274. typedef png_text FAR * FAR * png_textpp;
  160275. #endif
  160276. #define PNG_TEXT_COMPRESSION_NONE_WR -3
  160277. #define PNG_TEXT_COMPRESSION_zTXt_WR -2
  160278. #define PNG_TEXT_COMPRESSION_NONE -1
  160279. #define PNG_TEXT_COMPRESSION_zTXt 0
  160280. #define PNG_ITXT_COMPRESSION_NONE 1
  160281. #define PNG_ITXT_COMPRESSION_zTXt 2
  160282. #define PNG_TEXT_COMPRESSION_LAST 3 /* Not a valid value */
  160283. typedef struct png_time_struct
  160284. {
  160285. png_uint_16 year; /* full year, as in, 1995 */
  160286. png_byte month; /* month of year, 1 - 12 */
  160287. png_byte day; /* day of month, 1 - 31 */
  160288. png_byte hour; /* hour of day, 0 - 23 */
  160289. png_byte minute; /* minute of hour, 0 - 59 */
  160290. png_byte second; /* second of minute, 0 - 60 (for leap seconds) */
  160291. } png_time;
  160292. typedef png_time FAR * png_timep;
  160293. typedef png_time FAR * FAR * png_timepp;
  160294. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  160295. typedef struct png_unknown_chunk_t
  160296. {
  160297. png_byte name[5];
  160298. png_byte *data;
  160299. png_size_t size;
  160300. png_byte location; /* mode of operation at read time */
  160301. }
  160302. png_unknown_chunk;
  160303. typedef png_unknown_chunk FAR * png_unknown_chunkp;
  160304. typedef png_unknown_chunk FAR * FAR * png_unknown_chunkpp;
  160305. #endif
  160306. typedef struct png_info_struct
  160307. {
  160308. png_uint_32 width; /* width of image in pixels (from IHDR) */
  160309. png_uint_32 height; /* height of image in pixels (from IHDR) */
  160310. png_uint_32 valid; /* valid chunk data (see PNG_INFO_ below) */
  160311. png_uint_32 rowbytes; /* bytes needed to hold an untransformed row */
  160312. png_colorp palette; /* array of color values (valid & PNG_INFO_PLTE) */
  160313. png_uint_16 num_palette; /* number of color entries in "palette" (PLTE) */
  160314. png_uint_16 num_trans; /* number of transparent palette color (tRNS) */
  160315. png_byte bit_depth; /* 1, 2, 4, 8, or 16 bits/channel (from IHDR) */
  160316. png_byte color_type; /* see PNG_COLOR_TYPE_ below (from IHDR) */
  160317. png_byte compression_type; /* must be PNG_COMPRESSION_TYPE_BASE (IHDR) */
  160318. png_byte filter_type; /* must be PNG_FILTER_TYPE_BASE (from IHDR) */
  160319. png_byte interlace_type; /* One of PNG_INTERLACE_NONE, PNG_INTERLACE_ADAM7 */
  160320. png_byte channels; /* number of data channels per pixel (1, 2, 3, 4) */
  160321. png_byte pixel_depth; /* number of bits per pixel */
  160322. png_byte spare_byte; /* to align the data, and for future use */
  160323. png_byte signature[8]; /* magic bytes read by libpng from start of file */
  160324. #if defined(PNG_gAMA_SUPPORTED) && defined(PNG_FLOATING_POINT_SUPPORTED)
  160325. float gamma; /* gamma value of image, if (valid & PNG_INFO_gAMA) */
  160326. #endif
  160327. #if defined(PNG_sRGB_SUPPORTED)
  160328. png_byte srgb_intent; /* sRGB rendering intent [0, 1, 2, or 3] */
  160329. #endif
  160330. #if defined(PNG_TEXT_SUPPORTED)
  160331. int num_text; /* number of comments read/to write */
  160332. int max_text; /* current size of text array */
  160333. png_textp text; /* array of comments read/to write */
  160334. #endif /* PNG_TEXT_SUPPORTED */
  160335. #if defined(PNG_tIME_SUPPORTED)
  160336. png_time mod_time;
  160337. #endif
  160338. #if defined(PNG_sBIT_SUPPORTED)
  160339. png_color_8 sig_bit; /* significant bits in color channels */
  160340. #endif
  160341. #if defined(PNG_tRNS_SUPPORTED) || defined(PNG_READ_EXPAND_SUPPORTED) || \
  160342. defined(PNG_READ_BACKGROUND_SUPPORTED)
  160343. png_bytep trans; /* transparent values for paletted image */
  160344. png_color_16 trans_values; /* transparent color for non-palette image */
  160345. #endif
  160346. #if defined(PNG_bKGD_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
  160347. png_color_16 background;
  160348. #endif
  160349. #if defined(PNG_oFFs_SUPPORTED)
  160350. png_int_32 x_offset; /* x offset on page */
  160351. png_int_32 y_offset; /* y offset on page */
  160352. png_byte offset_unit_type; /* offset units type */
  160353. #endif
  160354. #if defined(PNG_pHYs_SUPPORTED)
  160355. png_uint_32 x_pixels_per_unit; /* horizontal pixel density */
  160356. png_uint_32 y_pixels_per_unit; /* vertical pixel density */
  160357. png_byte phys_unit_type; /* resolution type (see PNG_RESOLUTION_ below) */
  160358. #endif
  160359. #if defined(PNG_hIST_SUPPORTED)
  160360. png_uint_16p hist;
  160361. #endif
  160362. #ifdef PNG_cHRM_SUPPORTED
  160363. #ifdef PNG_FLOATING_POINT_SUPPORTED
  160364. float x_white;
  160365. float y_white;
  160366. float x_red;
  160367. float y_red;
  160368. float x_green;
  160369. float y_green;
  160370. float x_blue;
  160371. float y_blue;
  160372. #endif
  160373. #endif
  160374. #if defined(PNG_pCAL_SUPPORTED)
  160375. png_charp pcal_purpose; /* pCAL chunk description string */
  160376. png_int_32 pcal_X0; /* minimum value */
  160377. png_int_32 pcal_X1; /* maximum value */
  160378. png_charp pcal_units; /* Latin-1 string giving physical units */
  160379. png_charpp pcal_params; /* ASCII strings containing parameter values */
  160380. png_byte pcal_type; /* equation type (see PNG_EQUATION_ below) */
  160381. png_byte pcal_nparams; /* number of parameters given in pcal_params */
  160382. #endif
  160383. #ifdef PNG_FREE_ME_SUPPORTED
  160384. png_uint_32 free_me; /* flags items libpng is responsible for freeing */
  160385. #endif
  160386. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  160387. png_unknown_chunkp unknown_chunks;
  160388. png_size_t unknown_chunks_num;
  160389. #endif
  160390. #if defined(PNG_iCCP_SUPPORTED)
  160391. png_charp iccp_name; /* profile name */
  160392. png_charp iccp_profile; /* International Color Consortium profile data */
  160393. png_uint_32 iccp_proflen; /* ICC profile data length */
  160394. png_byte iccp_compression; /* Always zero */
  160395. #endif
  160396. #if defined(PNG_sPLT_SUPPORTED)
  160397. png_sPLT_tp splt_palettes;
  160398. png_uint_32 splt_palettes_num;
  160399. #endif
  160400. #if defined(PNG_sCAL_SUPPORTED)
  160401. png_byte scal_unit; /* unit of physical scale */
  160402. #ifdef PNG_FLOATING_POINT_SUPPORTED
  160403. double scal_pixel_width; /* width of one pixel */
  160404. double scal_pixel_height; /* height of one pixel */
  160405. #endif
  160406. #ifdef PNG_FIXED_POINT_SUPPORTED
  160407. png_charp scal_s_width; /* string containing height */
  160408. png_charp scal_s_height; /* string containing width */
  160409. #endif
  160410. #endif
  160411. #if defined(PNG_INFO_IMAGE_SUPPORTED)
  160412. png_bytepp row_pointers; /* the image bits */
  160413. #endif
  160414. #if defined(PNG_FIXED_POINT_SUPPORTED) && defined(PNG_gAMA_SUPPORTED)
  160415. png_fixed_point int_gamma; /* gamma of image, if (valid & PNG_INFO_gAMA) */
  160416. #endif
  160417. #if defined(PNG_cHRM_SUPPORTED) && defined(PNG_FIXED_POINT_SUPPORTED)
  160418. png_fixed_point int_x_white;
  160419. png_fixed_point int_y_white;
  160420. png_fixed_point int_x_red;
  160421. png_fixed_point int_y_red;
  160422. png_fixed_point int_x_green;
  160423. png_fixed_point int_y_green;
  160424. png_fixed_point int_x_blue;
  160425. png_fixed_point int_y_blue;
  160426. #endif
  160427. } png_info;
  160428. typedef png_info FAR * png_infop;
  160429. typedef png_info FAR * FAR * png_infopp;
  160430. #define PNG_UINT_31_MAX ((png_uint_32)0x7fffffffL)
  160431. #define PNG_UINT_32_MAX ((png_uint_32)(-1))
  160432. #define PNG_SIZE_MAX ((png_size_t)(-1))
  160433. #if defined(PNG_1_0_X) || defined (PNG_1_2_X)
  160434. #define PNG_MAX_UINT PNG_UINT_31_MAX
  160435. #endif
  160436. #define PNG_COLOR_MASK_PALETTE 1
  160437. #define PNG_COLOR_MASK_COLOR 2
  160438. #define PNG_COLOR_MASK_ALPHA 4
  160439. #define PNG_COLOR_TYPE_GRAY 0
  160440. #define PNG_COLOR_TYPE_PALETTE (PNG_COLOR_MASK_COLOR | PNG_COLOR_MASK_PALETTE)
  160441. #define PNG_COLOR_TYPE_RGB (PNG_COLOR_MASK_COLOR)
  160442. #define PNG_COLOR_TYPE_RGB_ALPHA (PNG_COLOR_MASK_COLOR | PNG_COLOR_MASK_ALPHA)
  160443. #define PNG_COLOR_TYPE_GRAY_ALPHA (PNG_COLOR_MASK_ALPHA)
  160444. #define PNG_COLOR_TYPE_RGBA PNG_COLOR_TYPE_RGB_ALPHA
  160445. #define PNG_COLOR_TYPE_GA PNG_COLOR_TYPE_GRAY_ALPHA
  160446. #define PNG_COMPRESSION_TYPE_BASE 0 /* Deflate method 8, 32K window */
  160447. #define PNG_COMPRESSION_TYPE_DEFAULT PNG_COMPRESSION_TYPE_BASE
  160448. #define PNG_FILTER_TYPE_BASE 0 /* Single row per-byte filtering */
  160449. #define PNG_INTRAPIXEL_DIFFERENCING 64 /* Used only in MNG datastreams */
  160450. #define PNG_FILTER_TYPE_DEFAULT PNG_FILTER_TYPE_BASE
  160451. #define PNG_INTERLACE_NONE 0 /* Non-interlaced image */
  160452. #define PNG_INTERLACE_ADAM7 1 /* Adam7 interlacing */
  160453. #define PNG_INTERLACE_LAST 2 /* Not a valid value */
  160454. #define PNG_OFFSET_PIXEL 0 /* Offset in pixels */
  160455. #define PNG_OFFSET_MICROMETER 1 /* Offset in micrometers (1/10^6 meter) */
  160456. #define PNG_OFFSET_LAST 2 /* Not a valid value */
  160457. #define PNG_EQUATION_LINEAR 0 /* Linear transformation */
  160458. #define PNG_EQUATION_BASE_E 1 /* Exponential base e transform */
  160459. #define PNG_EQUATION_ARBITRARY 2 /* Arbitrary base exponential transform */
  160460. #define PNG_EQUATION_HYPERBOLIC 3 /* Hyperbolic sine transformation */
  160461. #define PNG_EQUATION_LAST 4 /* Not a valid value */
  160462. #define PNG_SCALE_UNKNOWN 0 /* unknown unit (image scale) */
  160463. #define PNG_SCALE_METER 1 /* meters per pixel */
  160464. #define PNG_SCALE_RADIAN 2 /* radians per pixel */
  160465. #define PNG_SCALE_LAST 3 /* Not a valid value */
  160466. #define PNG_RESOLUTION_UNKNOWN 0 /* pixels/unknown unit (aspect ratio) */
  160467. #define PNG_RESOLUTION_METER 1 /* pixels/meter */
  160468. #define PNG_RESOLUTION_LAST 2 /* Not a valid value */
  160469. #define PNG_sRGB_INTENT_PERCEPTUAL 0
  160470. #define PNG_sRGB_INTENT_RELATIVE 1
  160471. #define PNG_sRGB_INTENT_SATURATION 2
  160472. #define PNG_sRGB_INTENT_ABSOLUTE 3
  160473. #define PNG_sRGB_INTENT_LAST 4 /* Not a valid value */
  160474. #define PNG_KEYWORD_MAX_LENGTH 79
  160475. #define PNG_MAX_PALETTE_LENGTH 256
  160476. #define PNG_INFO_gAMA 0x0001
  160477. #define PNG_INFO_sBIT 0x0002
  160478. #define PNG_INFO_cHRM 0x0004
  160479. #define PNG_INFO_PLTE 0x0008
  160480. #define PNG_INFO_tRNS 0x0010
  160481. #define PNG_INFO_bKGD 0x0020
  160482. #define PNG_INFO_hIST 0x0040
  160483. #define PNG_INFO_pHYs 0x0080
  160484. #define PNG_INFO_oFFs 0x0100
  160485. #define PNG_INFO_tIME 0x0200
  160486. #define PNG_INFO_pCAL 0x0400
  160487. #define PNG_INFO_sRGB 0x0800 /* GR-P, 0.96a */
  160488. #define PNG_INFO_iCCP 0x1000 /* ESR, 1.0.6 */
  160489. #define PNG_INFO_sPLT 0x2000 /* ESR, 1.0.6 */
  160490. #define PNG_INFO_sCAL 0x4000 /* ESR, 1.0.6 */
  160491. #define PNG_INFO_IDAT 0x8000L /* ESR, 1.0.6 */
  160492. typedef struct png_row_info_struct
  160493. {
  160494. png_uint_32 width; /* width of row */
  160495. png_uint_32 rowbytes; /* number of bytes in row */
  160496. png_byte color_type; /* color type of row */
  160497. png_byte bit_depth; /* bit depth of row */
  160498. png_byte channels; /* number of channels (1, 2, 3, or 4) */
  160499. png_byte pixel_depth; /* bits per pixel (depth * channels) */
  160500. } png_row_info;
  160501. typedef png_row_info FAR * png_row_infop;
  160502. typedef png_row_info FAR * FAR * png_row_infopp;
  160503. typedef struct png_struct_def png_struct;
  160504. typedef png_struct FAR * png_structp;
  160505. typedef void (PNGAPI *png_error_ptr) PNGARG((png_structp, png_const_charp));
  160506. typedef void (PNGAPI *png_rw_ptr) PNGARG((png_structp, png_bytep, png_size_t));
  160507. typedef void (PNGAPI *png_flush_ptr) PNGARG((png_structp));
  160508. typedef void (PNGAPI *png_read_status_ptr) PNGARG((png_structp, png_uint_32,
  160509. int));
  160510. typedef void (PNGAPI *png_write_status_ptr) PNGARG((png_structp, png_uint_32,
  160511. int));
  160512. #ifdef PNG_PROGRESSIVE_READ_SUPPORTED
  160513. typedef void (PNGAPI *png_progressive_info_ptr) PNGARG((png_structp, png_infop));
  160514. typedef void (PNGAPI *png_progressive_end_ptr) PNGARG((png_structp, png_infop));
  160515. typedef void (PNGAPI *png_progressive_row_ptr) PNGARG((png_structp, png_bytep,
  160516. png_uint_32, int));
  160517. #endif
  160518. #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \
  160519. defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED) || \
  160520. defined(PNG_LEGACY_SUPPORTED)
  160521. typedef void (PNGAPI *png_user_transform_ptr) PNGARG((png_structp,
  160522. png_row_infop, png_bytep));
  160523. #endif
  160524. #if defined(PNG_USER_CHUNKS_SUPPORTED)
  160525. typedef int (PNGAPI *png_user_chunk_ptr) PNGARG((png_structp, png_unknown_chunkp));
  160526. #endif
  160527. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  160528. typedef void (PNGAPI *png_unknown_chunk_ptr) PNGARG((png_structp));
  160529. #endif
  160530. #define PNG_TRANSFORM_IDENTITY 0x0000 /* read and write */
  160531. #define PNG_TRANSFORM_STRIP_16 0x0001 /* read only */
  160532. #define PNG_TRANSFORM_STRIP_ALPHA 0x0002 /* read only */
  160533. #define PNG_TRANSFORM_PACKING 0x0004 /* read and write */
  160534. #define PNG_TRANSFORM_PACKSWAP 0x0008 /* read and write */
  160535. #define PNG_TRANSFORM_EXPAND 0x0010 /* read only */
  160536. #define PNG_TRANSFORM_INVERT_MONO 0x0020 /* read and write */
  160537. #define PNG_TRANSFORM_SHIFT 0x0040 /* read and write */
  160538. #define PNG_TRANSFORM_BGR 0x0080 /* read and write */
  160539. #define PNG_TRANSFORM_SWAP_ALPHA 0x0100 /* read and write */
  160540. #define PNG_TRANSFORM_SWAP_ENDIAN 0x0200 /* read and write */
  160541. #define PNG_TRANSFORM_INVERT_ALPHA 0x0400 /* read and write */
  160542. #define PNG_TRANSFORM_STRIP_FILLER 0x0800 /* WRITE only */
  160543. #define PNG_FLAG_MNG_EMPTY_PLTE 0x01
  160544. #define PNG_FLAG_MNG_FILTER_64 0x04
  160545. #define PNG_ALL_MNG_FEATURES 0x05
  160546. typedef png_voidp (*png_malloc_ptr) PNGARG((png_structp, png_size_t));
  160547. typedef void (*png_free_ptr) PNGARG((png_structp, png_voidp));
  160548. struct png_struct_def
  160549. {
  160550. #ifdef PNG_SETJMP_SUPPORTED
  160551. jmp_buf jmpbuf; /* used in png_error */
  160552. #endif
  160553. png_error_ptr error_fn; /* function for printing errors and aborting */
  160554. png_error_ptr warning_fn; /* function for printing warnings */
  160555. png_voidp error_ptr; /* user supplied struct for error functions */
  160556. png_rw_ptr write_data_fn; /* function for writing output data */
  160557. png_rw_ptr read_data_fn; /* function for reading input data */
  160558. png_voidp io_ptr; /* ptr to application struct for I/O functions */
  160559. #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED)
  160560. png_user_transform_ptr read_user_transform_fn; /* user read transform */
  160561. #endif
  160562. #if defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED)
  160563. png_user_transform_ptr write_user_transform_fn; /* user write transform */
  160564. #endif
  160565. #if defined(PNG_USER_TRANSFORM_PTR_SUPPORTED)
  160566. #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \
  160567. defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED)
  160568. png_voidp user_transform_ptr; /* user supplied struct for user transform */
  160569. png_byte user_transform_depth; /* bit depth of user transformed pixels */
  160570. png_byte user_transform_channels; /* channels in user transformed pixels */
  160571. #endif
  160572. #endif
  160573. png_uint_32 mode; /* tells us where we are in the PNG file */
  160574. png_uint_32 flags; /* flags indicating various things to libpng */
  160575. png_uint_32 transformations; /* which transformations to perform */
  160576. z_stream zstream; /* pointer to decompression structure (below) */
  160577. png_bytep zbuf; /* buffer for zlib */
  160578. png_size_t zbuf_size; /* size of zbuf */
  160579. int zlib_level; /* holds zlib compression level */
  160580. int zlib_method; /* holds zlib compression method */
  160581. int zlib_window_bits; /* holds zlib compression window bits */
  160582. int zlib_mem_level; /* holds zlib compression memory level */
  160583. int zlib_strategy; /* holds zlib compression strategy */
  160584. png_uint_32 width; /* width of image in pixels */
  160585. png_uint_32 height; /* height of image in pixels */
  160586. png_uint_32 num_rows; /* number of rows in current pass */
  160587. png_uint_32 usr_width; /* width of row at start of write */
  160588. png_uint_32 rowbytes; /* size of row in bytes */
  160589. png_uint_32 irowbytes; /* size of current interlaced row in bytes */
  160590. png_uint_32 iwidth; /* width of current interlaced row in pixels */
  160591. png_uint_32 row_number; /* current row in interlace pass */
  160592. png_bytep prev_row; /* buffer to save previous (unfiltered) row */
  160593. png_bytep row_buf; /* buffer to save current (unfiltered) row */
  160594. png_bytep sub_row; /* buffer to save "sub" row when filtering */
  160595. png_bytep up_row; /* buffer to save "up" row when filtering */
  160596. png_bytep avg_row; /* buffer to save "avg" row when filtering */
  160597. png_bytep paeth_row; /* buffer to save "Paeth" row when filtering */
  160598. png_row_info row_info; /* used for transformation routines */
  160599. png_uint_32 idat_size; /* current IDAT size for read */
  160600. png_uint_32 crc; /* current chunk CRC value */
  160601. png_colorp palette; /* palette from the input file */
  160602. png_uint_16 num_palette; /* number of color entries in palette */
  160603. png_uint_16 num_trans; /* number of transparency values */
  160604. png_byte chunk_name[5]; /* null-terminated name of current chunk */
  160605. png_byte compression; /* file compression type (always 0) */
  160606. png_byte filter; /* file filter type (always 0) */
  160607. png_byte interlaced; /* PNG_INTERLACE_NONE, PNG_INTERLACE_ADAM7 */
  160608. png_byte pass; /* current interlace pass (0 - 6) */
  160609. png_byte do_filter; /* row filter flags (see PNG_FILTER_ below ) */
  160610. png_byte color_type; /* color type of file */
  160611. png_byte bit_depth; /* bit depth of file */
  160612. png_byte usr_bit_depth; /* bit depth of users row */
  160613. png_byte pixel_depth; /* number of bits per pixel */
  160614. png_byte channels; /* number of channels in file */
  160615. png_byte usr_channels; /* channels at start of write */
  160616. png_byte sig_bytes; /* magic bytes read/written from start of file */
  160617. #if defined(PNG_READ_FILLER_SUPPORTED) || defined(PNG_WRITE_FILLER_SUPPORTED)
  160618. #ifdef PNG_LEGACY_SUPPORTED
  160619. png_byte filler; /* filler byte for pixel expansion */
  160620. #else
  160621. png_uint_16 filler; /* filler bytes for pixel expansion */
  160622. #endif
  160623. #endif
  160624. #if defined(PNG_bKGD_SUPPORTED)
  160625. png_byte background_gamma_type;
  160626. # ifdef PNG_FLOATING_POINT_SUPPORTED
  160627. float background_gamma;
  160628. # endif
  160629. png_color_16 background; /* background color in screen gamma space */
  160630. #if defined(PNG_READ_GAMMA_SUPPORTED)
  160631. png_color_16 background_1; /* background normalized to gamma 1.0 */
  160632. #endif
  160633. #endif /* PNG_bKGD_SUPPORTED */
  160634. #if defined(PNG_WRITE_FLUSH_SUPPORTED)
  160635. png_flush_ptr output_flush_fn;/* Function for flushing output */
  160636. png_uint_32 flush_dist; /* how many rows apart to flush, 0 - no flush */
  160637. png_uint_32 flush_rows; /* number of rows written since last flush */
  160638. #endif
  160639. #if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
  160640. int gamma_shift; /* number of "insignificant" bits 16-bit gamma */
  160641. #ifdef PNG_FLOATING_POINT_SUPPORTED
  160642. float gamma; /* file gamma value */
  160643. float screen_gamma; /* screen gamma value (display_exponent) */
  160644. #endif
  160645. #endif
  160646. #if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
  160647. png_bytep gamma_table; /* gamma table for 8-bit depth files */
  160648. png_bytep gamma_from_1; /* converts from 1.0 to screen */
  160649. png_bytep gamma_to_1; /* converts from file to 1.0 */
  160650. png_uint_16pp gamma_16_table; /* gamma table for 16-bit depth files */
  160651. png_uint_16pp gamma_16_from_1; /* converts from 1.0 to screen */
  160652. png_uint_16pp gamma_16_to_1; /* converts from file to 1.0 */
  160653. #endif
  160654. #if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_sBIT_SUPPORTED)
  160655. png_color_8 sig_bit; /* significant bits in each available channel */
  160656. #endif
  160657. #if defined(PNG_READ_SHIFT_SUPPORTED) || defined(PNG_WRITE_SHIFT_SUPPORTED)
  160658. png_color_8 shift; /* shift for significant bit tranformation */
  160659. #endif
  160660. #if defined(PNG_tRNS_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED) \
  160661. || defined(PNG_READ_EXPAND_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
  160662. png_bytep trans; /* transparency values for paletted files */
  160663. png_color_16 trans_values; /* transparency values for non-paletted files */
  160664. #endif
  160665. png_read_status_ptr read_row_fn; /* called after each row is decoded */
  160666. png_write_status_ptr write_row_fn; /* called after each row is encoded */
  160667. #ifdef PNG_PROGRESSIVE_READ_SUPPORTED
  160668. png_progressive_info_ptr info_fn; /* called after header data fully read */
  160669. png_progressive_row_ptr row_fn; /* called after each prog. row is decoded */
  160670. png_progressive_end_ptr end_fn; /* called after image is complete */
  160671. png_bytep save_buffer_ptr; /* current location in save_buffer */
  160672. png_bytep save_buffer; /* buffer for previously read data */
  160673. png_bytep current_buffer_ptr; /* current location in current_buffer */
  160674. png_bytep current_buffer; /* buffer for recently used data */
  160675. png_uint_32 push_length; /* size of current input chunk */
  160676. png_uint_32 skip_length; /* bytes to skip in input data */
  160677. png_size_t save_buffer_size; /* amount of data now in save_buffer */
  160678. png_size_t save_buffer_max; /* total size of save_buffer */
  160679. png_size_t buffer_size; /* total amount of available input data */
  160680. png_size_t current_buffer_size; /* amount of data now in current_buffer */
  160681. int process_mode; /* what push library is currently doing */
  160682. int cur_palette; /* current push library palette index */
  160683. # if defined(PNG_TEXT_SUPPORTED)
  160684. png_size_t current_text_size; /* current size of text input data */
  160685. png_size_t current_text_left; /* how much text left to read in input */
  160686. png_charp current_text; /* current text chunk buffer */
  160687. png_charp current_text_ptr; /* current location in current_text */
  160688. # endif /* PNG_TEXT_SUPPORTED */
  160689. #endif /* PNG_PROGRESSIVE_READ_SUPPORTED */
  160690. #if defined(__TURBOC__) && !defined(_Windows) && !defined(__FLAT__)
  160691. png_bytepp offset_table_ptr;
  160692. png_bytep offset_table;
  160693. png_uint_16 offset_table_number;
  160694. png_uint_16 offset_table_count;
  160695. png_uint_16 offset_table_count_free;
  160696. #endif
  160697. #if defined(PNG_READ_DITHER_SUPPORTED)
  160698. png_bytep palette_lookup; /* lookup table for dithering */
  160699. png_bytep dither_index; /* index translation for palette files */
  160700. #endif
  160701. #if defined(PNG_READ_DITHER_SUPPORTED) || defined(PNG_hIST_SUPPORTED)
  160702. png_uint_16p hist; /* histogram */
  160703. #endif
  160704. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  160705. png_byte heuristic_method; /* heuristic for row filter selection */
  160706. png_byte num_prev_filters; /* number of weights for previous rows */
  160707. png_bytep prev_filters; /* filter type(s) of previous row(s) */
  160708. png_uint_16p filter_weights; /* weight(s) for previous line(s) */
  160709. png_uint_16p inv_filter_weights; /* 1/weight(s) for previous line(s) */
  160710. png_uint_16p filter_costs; /* relative filter calculation cost */
  160711. png_uint_16p inv_filter_costs; /* 1/relative filter calculation cost */
  160712. #endif
  160713. #if defined(PNG_TIME_RFC1123_SUPPORTED)
  160714. png_charp time_buffer; /* String to hold RFC 1123 time text */
  160715. #endif
  160716. #ifdef PNG_FREE_ME_SUPPORTED
  160717. png_uint_32 free_me; /* flags items libpng is responsible for freeing */
  160718. #endif
  160719. #if defined(PNG_USER_CHUNKS_SUPPORTED)
  160720. png_voidp user_chunk_ptr;
  160721. png_user_chunk_ptr read_user_chunk_fn; /* user read chunk handler */
  160722. #endif
  160723. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  160724. int num_chunk_list;
  160725. png_bytep chunk_list;
  160726. #endif
  160727. #if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
  160728. png_byte rgb_to_gray_status;
  160729. png_uint_16 rgb_to_gray_red_coeff;
  160730. png_uint_16 rgb_to_gray_green_coeff;
  160731. png_uint_16 rgb_to_gray_blue_coeff;
  160732. #endif
  160733. #if defined(PNG_MNG_FEATURES_SUPPORTED) || \
  160734. defined(PNG_READ_EMPTY_PLTE_SUPPORTED) || \
  160735. defined(PNG_WRITE_EMPTY_PLTE_SUPPORTED)
  160736. #ifdef PNG_1_0_X
  160737. png_byte mng_features_permitted;
  160738. #else
  160739. png_uint_32 mng_features_permitted;
  160740. #endif /* PNG_1_0_X */
  160741. #endif
  160742. #if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
  160743. png_fixed_point int_gamma;
  160744. #endif
  160745. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  160746. png_byte filter_type;
  160747. #endif
  160748. #if defined(PNG_1_0_X)
  160749. png_uint_32 row_buf_size;
  160750. #endif
  160751. #if defined(PNG_ASSEMBLER_CODE_SUPPORTED)
  160752. # if !defined(PNG_1_0_X)
  160753. # if defined(PNG_MMX_CODE_SUPPORTED)
  160754. png_byte mmx_bitdepth_threshold;
  160755. png_uint_32 mmx_rowbytes_threshold;
  160756. # endif
  160757. png_uint_32 asm_flags;
  160758. # endif
  160759. #endif
  160760. #ifdef PNG_USER_MEM_SUPPORTED
  160761. png_voidp mem_ptr; /* user supplied struct for mem functions */
  160762. png_malloc_ptr malloc_fn; /* function for allocating memory */
  160763. png_free_ptr free_fn; /* function for freeing memory */
  160764. #endif
  160765. png_bytep big_row_buf; /* buffer to save current (unfiltered) row */
  160766. #if defined(PNG_READ_DITHER_SUPPORTED)
  160767. png_bytep dither_sort; /* working sort array */
  160768. png_bytep index_to_palette; /* where the original index currently is */
  160769. png_bytep palette_to_index; /* which original index points to this */
  160770. #endif
  160771. png_byte compression_type;
  160772. #ifdef PNG_SET_USER_LIMITS_SUPPORTED
  160773. png_uint_32 user_width_max;
  160774. png_uint_32 user_height_max;
  160775. #endif
  160776. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  160777. png_unknown_chunk unknown_chunk;
  160778. #endif
  160779. };
  160780. typedef png_structp version_1_2_21;
  160781. typedef png_struct FAR * FAR * png_structpp;
  160782. extern PNG_EXPORT(png_uint_32,png_access_version_number) PNGARG((void));
  160783. extern PNG_EXPORT(void,png_set_sig_bytes) PNGARG((png_structp png_ptr,
  160784. int num_bytes));
  160785. extern PNG_EXPORT(int,png_sig_cmp) PNGARG((png_bytep sig, png_size_t start,
  160786. png_size_t num_to_check));
  160787. extern PNG_EXPORT(int,png_check_sig) PNGARG((png_bytep sig, int num));
  160788. extern PNG_EXPORT(png_structp,png_create_read_struct)
  160789. PNGARG((png_const_charp user_png_ver, png_voidp error_ptr,
  160790. png_error_ptr error_fn, png_error_ptr warn_fn));
  160791. extern PNG_EXPORT(png_structp,png_create_write_struct)
  160792. PNGARG((png_const_charp user_png_ver, png_voidp error_ptr,
  160793. png_error_ptr error_fn, png_error_ptr warn_fn));
  160794. #ifdef PNG_WRITE_SUPPORTED
  160795. extern PNG_EXPORT(png_uint_32,png_get_compression_buffer_size)
  160796. PNGARG((png_structp png_ptr));
  160797. #endif
  160798. #ifdef PNG_WRITE_SUPPORTED
  160799. extern PNG_EXPORT(void,png_set_compression_buffer_size)
  160800. PNGARG((png_structp png_ptr, png_uint_32 size));
  160801. #endif
  160802. extern PNG_EXPORT(int,png_reset_zstream) PNGARG((png_structp png_ptr));
  160803. #ifdef PNG_USER_MEM_SUPPORTED
  160804. extern PNG_EXPORT(png_structp,png_create_read_struct_2)
  160805. PNGARG((png_const_charp user_png_ver, png_voidp error_ptr,
  160806. png_error_ptr error_fn, png_error_ptr warn_fn, png_voidp mem_ptr,
  160807. png_malloc_ptr malloc_fn, png_free_ptr free_fn));
  160808. extern PNG_EXPORT(png_structp,png_create_write_struct_2)
  160809. PNGARG((png_const_charp user_png_ver, png_voidp error_ptr,
  160810. png_error_ptr error_fn, png_error_ptr warn_fn, png_voidp mem_ptr,
  160811. png_malloc_ptr malloc_fn, png_free_ptr free_fn));
  160812. #endif
  160813. extern PNG_EXPORT(void,png_write_chunk) PNGARG((png_structp png_ptr,
  160814. png_bytep chunk_name, png_bytep data, png_size_t length));
  160815. extern PNG_EXPORT(void,png_write_chunk_start) PNGARG((png_structp png_ptr,
  160816. png_bytep chunk_name, png_uint_32 length));
  160817. extern PNG_EXPORT(void,png_write_chunk_data) PNGARG((png_structp png_ptr,
  160818. png_bytep data, png_size_t length));
  160819. extern PNG_EXPORT(void,png_write_chunk_end) PNGARG((png_structp png_ptr));
  160820. extern PNG_EXPORT(png_infop,png_create_info_struct)
  160821. PNGARG((png_structp png_ptr));
  160822. #if defined(PNG_1_0_X) || defined (PNG_1_2_X)
  160823. extern PNG_EXPORT(void,png_info_init) PNGARG((png_infop info_ptr));
  160824. #undef png_info_init
  160825. #define png_info_init(info_ptr) png_info_init_3(&info_ptr,\
  160826. png_sizeof(png_info));
  160827. #endif
  160828. extern PNG_EXPORT(void,png_info_init_3) PNGARG((png_infopp info_ptr,
  160829. png_size_t png_info_struct_size));
  160830. extern PNG_EXPORT(void,png_write_info_before_PLTE) PNGARG((png_structp png_ptr,
  160831. png_infop info_ptr));
  160832. extern PNG_EXPORT(void,png_write_info) PNGARG((png_structp png_ptr,
  160833. png_infop info_ptr));
  160834. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  160835. extern PNG_EXPORT(void,png_read_info) PNGARG((png_structp png_ptr,
  160836. png_infop info_ptr));
  160837. #endif
  160838. #if defined(PNG_TIME_RFC1123_SUPPORTED)
  160839. extern PNG_EXPORT(png_charp,png_convert_to_rfc1123)
  160840. PNGARG((png_structp png_ptr, png_timep ptime));
  160841. #endif
  160842. #if !defined(_WIN32_WCE)
  160843. #if defined(PNG_WRITE_tIME_SUPPORTED)
  160844. extern PNG_EXPORT(void,png_convert_from_struct_tm) PNGARG((png_timep ptime,
  160845. struct tm FAR * ttime));
  160846. extern PNG_EXPORT(void,png_convert_from_time_t) PNGARG((png_timep ptime,
  160847. time_t ttime));
  160848. #endif /* PNG_WRITE_tIME_SUPPORTED */
  160849. #endif /* _WIN32_WCE */
  160850. #if defined(PNG_READ_EXPAND_SUPPORTED)
  160851. extern PNG_EXPORT(void,png_set_expand) PNGARG((png_structp png_ptr));
  160852. #if !defined(PNG_1_0_X)
  160853. extern PNG_EXPORT(void,png_set_expand_gray_1_2_4_to_8) PNGARG((png_structp
  160854. png_ptr));
  160855. #endif
  160856. extern PNG_EXPORT(void,png_set_palette_to_rgb) PNGARG((png_structp png_ptr));
  160857. extern PNG_EXPORT(void,png_set_tRNS_to_alpha) PNGARG((png_structp png_ptr));
  160858. #if defined(PNG_1_0_X) || defined (PNG_1_2_X)
  160859. extern PNG_EXPORT(void,png_set_gray_1_2_4_to_8) PNGARG((png_structp png_ptr));
  160860. #endif
  160861. #endif
  160862. #if defined(PNG_READ_BGR_SUPPORTED) || defined(PNG_WRITE_BGR_SUPPORTED)
  160863. extern PNG_EXPORT(void,png_set_bgr) PNGARG((png_structp png_ptr));
  160864. #endif
  160865. #if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
  160866. extern PNG_EXPORT(void,png_set_gray_to_rgb) PNGARG((png_structp png_ptr));
  160867. #endif
  160868. #if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
  160869. #ifdef PNG_FLOATING_POINT_SUPPORTED
  160870. extern PNG_EXPORT(void,png_set_rgb_to_gray) PNGARG((png_structp png_ptr,
  160871. int error_action, double red, double green ));
  160872. #endif
  160873. extern PNG_EXPORT(void,png_set_rgb_to_gray_fixed) PNGARG((png_structp png_ptr,
  160874. int error_action, png_fixed_point red, png_fixed_point green ));
  160875. extern PNG_EXPORT(png_byte,png_get_rgb_to_gray_status) PNGARG((png_structp
  160876. png_ptr));
  160877. #endif
  160878. extern PNG_EXPORT(void,png_build_grayscale_palette) PNGARG((int bit_depth,
  160879. png_colorp palette));
  160880. #if defined(PNG_READ_STRIP_ALPHA_SUPPORTED)
  160881. extern PNG_EXPORT(void,png_set_strip_alpha) PNGARG((png_structp png_ptr));
  160882. #endif
  160883. #if defined(PNG_READ_SWAP_ALPHA_SUPPORTED) || \
  160884. defined(PNG_WRITE_SWAP_ALPHA_SUPPORTED)
  160885. extern PNG_EXPORT(void,png_set_swap_alpha) PNGARG((png_structp png_ptr));
  160886. #endif
  160887. #if defined(PNG_READ_INVERT_ALPHA_SUPPORTED) || \
  160888. defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED)
  160889. extern PNG_EXPORT(void,png_set_invert_alpha) PNGARG((png_structp png_ptr));
  160890. #endif
  160891. #if defined(PNG_READ_FILLER_SUPPORTED) || defined(PNG_WRITE_FILLER_SUPPORTED)
  160892. extern PNG_EXPORT(void,png_set_filler) PNGARG((png_structp png_ptr,
  160893. png_uint_32 filler, int flags));
  160894. #define PNG_FILLER_BEFORE 0
  160895. #define PNG_FILLER_AFTER 1
  160896. #if !defined(PNG_1_0_X)
  160897. extern PNG_EXPORT(void,png_set_add_alpha) PNGARG((png_structp png_ptr,
  160898. png_uint_32 filler, int flags));
  160899. #endif
  160900. #endif /* PNG_READ_FILLER_SUPPORTED || PNG_WRITE_FILLER_SUPPORTED */
  160901. #if defined(PNG_READ_SWAP_SUPPORTED) || defined(PNG_WRITE_SWAP_SUPPORTED)
  160902. extern PNG_EXPORT(void,png_set_swap) PNGARG((png_structp png_ptr));
  160903. #endif
  160904. #if defined(PNG_READ_PACK_SUPPORTED) || defined(PNG_WRITE_PACK_SUPPORTED)
  160905. extern PNG_EXPORT(void,png_set_packing) PNGARG((png_structp png_ptr));
  160906. #endif
  160907. #if defined(PNG_READ_PACKSWAP_SUPPORTED) || defined(PNG_WRITE_PACKSWAP_SUPPORTED)
  160908. extern PNG_EXPORT(void,png_set_packswap) PNGARG((png_structp png_ptr));
  160909. #endif
  160910. #if defined(PNG_READ_SHIFT_SUPPORTED) || defined(PNG_WRITE_SHIFT_SUPPORTED)
  160911. extern PNG_EXPORT(void,png_set_shift) PNGARG((png_structp png_ptr,
  160912. png_color_8p true_bits));
  160913. #endif
  160914. #if defined(PNG_READ_INTERLACING_SUPPORTED) || \
  160915. defined(PNG_WRITE_INTERLACING_SUPPORTED)
  160916. extern PNG_EXPORT(int,png_set_interlace_handling) PNGARG((png_structp png_ptr));
  160917. #endif
  160918. #if defined(PNG_READ_INVERT_SUPPORTED) || defined(PNG_WRITE_INVERT_SUPPORTED)
  160919. extern PNG_EXPORT(void,png_set_invert_mono) PNGARG((png_structp png_ptr));
  160920. #endif
  160921. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  160922. #ifdef PNG_FLOATING_POINT_SUPPORTED
  160923. extern PNG_EXPORT(void,png_set_background) PNGARG((png_structp png_ptr,
  160924. png_color_16p background_color, int background_gamma_code,
  160925. int need_expand, double background_gamma));
  160926. #endif
  160927. #define PNG_BACKGROUND_GAMMA_UNKNOWN 0
  160928. #define PNG_BACKGROUND_GAMMA_SCREEN 1
  160929. #define PNG_BACKGROUND_GAMMA_FILE 2
  160930. #define PNG_BACKGROUND_GAMMA_UNIQUE 3
  160931. #endif
  160932. #if defined(PNG_READ_16_TO_8_SUPPORTED)
  160933. extern PNG_EXPORT(void,png_set_strip_16) PNGARG((png_structp png_ptr));
  160934. #endif
  160935. #if defined(PNG_READ_DITHER_SUPPORTED)
  160936. extern PNG_EXPORT(void,png_set_dither) PNGARG((png_structp png_ptr,
  160937. png_colorp palette, int num_palette, int maximum_colors,
  160938. png_uint_16p histogram, int full_dither));
  160939. #endif
  160940. #if defined(PNG_READ_GAMMA_SUPPORTED)
  160941. #ifdef PNG_FLOATING_POINT_SUPPORTED
  160942. extern PNG_EXPORT(void,png_set_gamma) PNGARG((png_structp png_ptr,
  160943. double screen_gamma, double default_file_gamma));
  160944. #endif
  160945. #endif
  160946. #if defined(PNG_1_0_X) || defined (PNG_1_2_X)
  160947. #if defined(PNG_READ_EMPTY_PLTE_SUPPORTED) || \
  160948. defined(PNG_WRITE_EMPTY_PLTE_SUPPORTED)
  160949. extern PNG_EXPORT(void,png_permit_empty_plte) PNGARG((png_structp png_ptr,
  160950. int empty_plte_permitted));
  160951. #endif
  160952. #endif
  160953. #if defined(PNG_WRITE_FLUSH_SUPPORTED)
  160954. extern PNG_EXPORT(void,png_set_flush) PNGARG((png_structp png_ptr, int nrows));
  160955. extern PNG_EXPORT(void,png_write_flush) PNGARG((png_structp png_ptr));
  160956. #endif
  160957. extern PNG_EXPORT(void,png_start_read_image) PNGARG((png_structp png_ptr));
  160958. extern PNG_EXPORT(void,png_read_update_info) PNGARG((png_structp png_ptr,
  160959. png_infop info_ptr));
  160960. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  160961. extern PNG_EXPORT(void,png_read_rows) PNGARG((png_structp png_ptr,
  160962. png_bytepp row, png_bytepp display_row, png_uint_32 num_rows));
  160963. #endif
  160964. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  160965. extern PNG_EXPORT(void,png_read_row) PNGARG((png_structp png_ptr,
  160966. png_bytep row,
  160967. png_bytep display_row));
  160968. #endif
  160969. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  160970. extern PNG_EXPORT(void,png_read_image) PNGARG((png_structp png_ptr,
  160971. png_bytepp image));
  160972. #endif
  160973. extern PNG_EXPORT(void,png_write_row) PNGARG((png_structp png_ptr,
  160974. png_bytep row));
  160975. extern PNG_EXPORT(void,png_write_rows) PNGARG((png_structp png_ptr,
  160976. png_bytepp row, png_uint_32 num_rows));
  160977. extern PNG_EXPORT(void,png_write_image) PNGARG((png_structp png_ptr,
  160978. png_bytepp image));
  160979. extern PNG_EXPORT(void,png_write_end) PNGARG((png_structp png_ptr,
  160980. png_infop info_ptr));
  160981. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  160982. extern PNG_EXPORT(void,png_read_end) PNGARG((png_structp png_ptr,
  160983. png_infop info_ptr));
  160984. #endif
  160985. extern PNG_EXPORT(void,png_destroy_info_struct) PNGARG((png_structp png_ptr,
  160986. png_infopp info_ptr_ptr));
  160987. extern PNG_EXPORT(void,png_destroy_read_struct) PNGARG((png_structpp
  160988. png_ptr_ptr, png_infopp info_ptr_ptr, png_infopp end_info_ptr_ptr));
  160989. extern void png_read_destroy PNGARG((png_structp png_ptr, png_infop info_ptr,
  160990. png_infop end_info_ptr));
  160991. extern PNG_EXPORT(void,png_destroy_write_struct)
  160992. PNGARG((png_structpp png_ptr_ptr, png_infopp info_ptr_ptr));
  160993. extern void png_write_destroy PNGARG((png_structp png_ptr));
  160994. extern PNG_EXPORT(void,png_set_crc_action) PNGARG((png_structp png_ptr,
  160995. int crit_action, int ancil_action));
  160996. #define PNG_CRC_DEFAULT 0 /* error/quit warn/discard data */
  160997. #define PNG_CRC_ERROR_QUIT 1 /* error/quit error/quit */
  160998. #define PNG_CRC_WARN_DISCARD 2 /* (INVALID) warn/discard data */
  160999. #define PNG_CRC_WARN_USE 3 /* warn/use data warn/use data */
  161000. #define PNG_CRC_QUIET_USE 4 /* quiet/use data quiet/use data */
  161001. #define PNG_CRC_NO_CHANGE 5 /* use current value use current value */
  161002. extern PNG_EXPORT(void,png_set_filter) PNGARG((png_structp png_ptr, int method,
  161003. int filters));
  161004. #define PNG_NO_FILTERS 0x00
  161005. #define PNG_FILTER_NONE 0x08
  161006. #define PNG_FILTER_SUB 0x10
  161007. #define PNG_FILTER_UP 0x20
  161008. #define PNG_FILTER_AVG 0x40
  161009. #define PNG_FILTER_PAETH 0x80
  161010. #define PNG_ALL_FILTERS (PNG_FILTER_NONE | PNG_FILTER_SUB | PNG_FILTER_UP | \
  161011. PNG_FILTER_AVG | PNG_FILTER_PAETH)
  161012. #define PNG_FILTER_VALUE_NONE 0
  161013. #define PNG_FILTER_VALUE_SUB 1
  161014. #define PNG_FILTER_VALUE_UP 2
  161015. #define PNG_FILTER_VALUE_AVG 3
  161016. #define PNG_FILTER_VALUE_PAETH 4
  161017. #define PNG_FILTER_VALUE_LAST 5
  161018. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED) /* EXPERIMENTAL */
  161019. #ifdef PNG_FLOATING_POINT_SUPPORTED
  161020. extern PNG_EXPORT(void,png_set_filter_heuristics) PNGARG((png_structp png_ptr,
  161021. int heuristic_method, int num_weights, png_doublep filter_weights,
  161022. png_doublep filter_costs));
  161023. #endif
  161024. #endif /* PNG_WRITE_WEIGHTED_FILTER_SUPPORTED */
  161025. #define PNG_FILTER_HEURISTIC_DEFAULT 0 /* Currently "UNWEIGHTED" */
  161026. #define PNG_FILTER_HEURISTIC_UNWEIGHTED 1 /* Used by libpng < 0.95 */
  161027. #define PNG_FILTER_HEURISTIC_WEIGHTED 2 /* Experimental feature */
  161028. #define PNG_FILTER_HEURISTIC_LAST 3 /* Not a valid value */
  161029. extern PNG_EXPORT(void,png_set_compression_level) PNGARG((png_structp png_ptr,
  161030. int level));
  161031. extern PNG_EXPORT(void,png_set_compression_mem_level)
  161032. PNGARG((png_structp png_ptr, int mem_level));
  161033. extern PNG_EXPORT(void,png_set_compression_strategy)
  161034. PNGARG((png_structp png_ptr, int strategy));
  161035. extern PNG_EXPORT(void,png_set_compression_window_bits)
  161036. PNGARG((png_structp png_ptr, int window_bits));
  161037. extern PNG_EXPORT(void,png_set_compression_method) PNGARG((png_structp png_ptr,
  161038. int method));
  161039. #if !defined(PNG_NO_STDIO)
  161040. extern PNG_EXPORT(void,png_init_io) PNGARG((png_structp png_ptr, png_FILE_p fp));
  161041. #endif
  161042. extern PNG_EXPORT(void,png_set_error_fn) PNGARG((png_structp png_ptr,
  161043. png_voidp error_ptr, png_error_ptr error_fn, png_error_ptr warning_fn));
  161044. extern PNG_EXPORT(png_voidp,png_get_error_ptr) PNGARG((png_structp png_ptr));
  161045. extern PNG_EXPORT(void,png_set_write_fn) PNGARG((png_structp png_ptr,
  161046. png_voidp io_ptr, png_rw_ptr write_data_fn, png_flush_ptr output_flush_fn));
  161047. extern PNG_EXPORT(void,png_set_read_fn) PNGARG((png_structp png_ptr,
  161048. png_voidp io_ptr, png_rw_ptr read_data_fn));
  161049. extern PNG_EXPORT(png_voidp,png_get_io_ptr) PNGARG((png_structp png_ptr));
  161050. extern PNG_EXPORT(void,png_set_read_status_fn) PNGARG((png_structp png_ptr,
  161051. png_read_status_ptr read_row_fn));
  161052. extern PNG_EXPORT(void,png_set_write_status_fn) PNGARG((png_structp png_ptr,
  161053. png_write_status_ptr write_row_fn));
  161054. #ifdef PNG_USER_MEM_SUPPORTED
  161055. extern PNG_EXPORT(void,png_set_mem_fn) PNGARG((png_structp png_ptr,
  161056. png_voidp mem_ptr, png_malloc_ptr malloc_fn, png_free_ptr free_fn));
  161057. extern PNG_EXPORT(png_voidp,png_get_mem_ptr) PNGARG((png_structp png_ptr));
  161058. #endif
  161059. #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \
  161060. defined(PNG_LEGACY_SUPPORTED)
  161061. extern PNG_EXPORT(void,png_set_read_user_transform_fn) PNGARG((png_structp
  161062. png_ptr, png_user_transform_ptr read_user_transform_fn));
  161063. #endif
  161064. #if defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED) || \
  161065. defined(PNG_LEGACY_SUPPORTED)
  161066. extern PNG_EXPORT(void,png_set_write_user_transform_fn) PNGARG((png_structp
  161067. png_ptr, png_user_transform_ptr write_user_transform_fn));
  161068. #endif
  161069. #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \
  161070. defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED) || \
  161071. defined(PNG_LEGACY_SUPPORTED)
  161072. extern PNG_EXPORT(void,png_set_user_transform_info) PNGARG((png_structp
  161073. png_ptr, png_voidp user_transform_ptr, int user_transform_depth,
  161074. int user_transform_channels));
  161075. extern PNG_EXPORT(png_voidp,png_get_user_transform_ptr)
  161076. PNGARG((png_structp png_ptr));
  161077. #endif
  161078. #ifdef PNG_USER_CHUNKS_SUPPORTED
  161079. extern PNG_EXPORT(void,png_set_read_user_chunk_fn) PNGARG((png_structp png_ptr,
  161080. png_voidp user_chunk_ptr, png_user_chunk_ptr read_user_chunk_fn));
  161081. extern PNG_EXPORT(png_voidp,png_get_user_chunk_ptr) PNGARG((png_structp
  161082. png_ptr));
  161083. #endif
  161084. #ifdef PNG_PROGRESSIVE_READ_SUPPORTED
  161085. extern PNG_EXPORT(void,png_set_progressive_read_fn) PNGARG((png_structp png_ptr,
  161086. png_voidp progressive_ptr,
  161087. png_progressive_info_ptr info_fn, png_progressive_row_ptr row_fn,
  161088. png_progressive_end_ptr end_fn));
  161089. extern PNG_EXPORT(png_voidp,png_get_progressive_ptr)
  161090. PNGARG((png_structp png_ptr));
  161091. extern PNG_EXPORT(void,png_process_data) PNGARG((png_structp png_ptr,
  161092. png_infop info_ptr, png_bytep buffer, png_size_t buffer_size));
  161093. extern PNG_EXPORT(void,png_progressive_combine_row) PNGARG((png_structp png_ptr,
  161094. png_bytep old_row, png_bytep new_row));
  161095. #endif /* PNG_PROGRESSIVE_READ_SUPPORTED */
  161096. extern PNG_EXPORT(png_voidp,png_malloc) PNGARG((png_structp png_ptr,
  161097. png_uint_32 size));
  161098. #if defined(PNG_1_0_X)
  161099. # define png_malloc_warn png_malloc
  161100. #else
  161101. extern PNG_EXPORT(png_voidp,png_malloc_warn) PNGARG((png_structp png_ptr,
  161102. png_uint_32 size));
  161103. #endif
  161104. extern PNG_EXPORT(void,png_free) PNGARG((png_structp png_ptr, png_voidp ptr));
  161105. #if defined(PNG_1_0_X)
  161106. extern PNG_EXPORT(voidpf,png_zalloc) PNGARG((voidpf png_ptr, uInt items,
  161107. uInt size));
  161108. extern PNG_EXPORT(void,png_zfree) PNGARG((voidpf png_ptr, voidpf ptr));
  161109. #endif
  161110. extern PNG_EXPORT(void,png_free_data) PNGARG((png_structp png_ptr,
  161111. png_infop info_ptr, png_uint_32 free_me, int num));
  161112. #ifdef PNG_FREE_ME_SUPPORTED
  161113. extern PNG_EXPORT(void,png_data_freer) PNGARG((png_structp png_ptr,
  161114. png_infop info_ptr, int freer, png_uint_32 mask));
  161115. #endif
  161116. #define PNG_DESTROY_WILL_FREE_DATA 1
  161117. #define PNG_SET_WILL_FREE_DATA 1
  161118. #define PNG_USER_WILL_FREE_DATA 2
  161119. #define PNG_FREE_HIST 0x0008
  161120. #define PNG_FREE_ICCP 0x0010
  161121. #define PNG_FREE_SPLT 0x0020
  161122. #define PNG_FREE_ROWS 0x0040
  161123. #define PNG_FREE_PCAL 0x0080
  161124. #define PNG_FREE_SCAL 0x0100
  161125. #define PNG_FREE_UNKN 0x0200
  161126. #define PNG_FREE_LIST 0x0400
  161127. #define PNG_FREE_PLTE 0x1000
  161128. #define PNG_FREE_TRNS 0x2000
  161129. #define PNG_FREE_TEXT 0x4000
  161130. #define PNG_FREE_ALL 0x7fff
  161131. #define PNG_FREE_MUL 0x4220 /* PNG_FREE_SPLT|PNG_FREE_TEXT|PNG_FREE_UNKN */
  161132. #ifdef PNG_USER_MEM_SUPPORTED
  161133. extern PNG_EXPORT(png_voidp,png_malloc_default) PNGARG((png_structp png_ptr,
  161134. png_uint_32 size));
  161135. extern PNG_EXPORT(void,png_free_default) PNGARG((png_structp png_ptr,
  161136. png_voidp ptr));
  161137. #endif
  161138. extern PNG_EXPORT(png_voidp,png_memcpy_check) PNGARG((png_structp png_ptr,
  161139. png_voidp s1, png_voidp s2, png_uint_32 size));
  161140. extern PNG_EXPORT(png_voidp,png_memset_check) PNGARG((png_structp png_ptr,
  161141. png_voidp s1, int value, png_uint_32 size));
  161142. #if defined(USE_FAR_KEYWORD) /* memory model conversion function */
  161143. extern void *png_far_to_near PNGARG((png_structp png_ptr,png_voidp ptr,
  161144. int check));
  161145. #endif /* USE_FAR_KEYWORD */
  161146. #ifndef PNG_NO_ERROR_TEXT
  161147. extern PNG_EXPORT(void,png_error) PNGARG((png_structp png_ptr,
  161148. png_const_charp error_message));
  161149. extern PNG_EXPORT(void,png_chunk_error) PNGARG((png_structp png_ptr,
  161150. png_const_charp error_message));
  161151. #else
  161152. extern PNG_EXPORT(void,png_err) PNGARG((png_structp png_ptr));
  161153. #endif
  161154. #ifndef PNG_NO_WARNINGS
  161155. extern PNG_EXPORT(void,png_warning) PNGARG((png_structp png_ptr,
  161156. png_const_charp warning_message));
  161157. #ifdef PNG_READ_SUPPORTED
  161158. extern PNG_EXPORT(void,png_chunk_warning) PNGARG((png_structp png_ptr,
  161159. png_const_charp warning_message));
  161160. #endif /* PNG_READ_SUPPORTED */
  161161. #endif /* PNG_NO_WARNINGS */
  161162. extern PNG_EXPORT(png_uint_32,png_get_valid) PNGARG((png_structp png_ptr,
  161163. png_infop info_ptr, png_uint_32 flag));
  161164. extern PNG_EXPORT(png_uint_32,png_get_rowbytes) PNGARG((png_structp png_ptr,
  161165. png_infop info_ptr));
  161166. #if defined(PNG_INFO_IMAGE_SUPPORTED)
  161167. extern PNG_EXPORT(png_bytepp,png_get_rows) PNGARG((png_structp png_ptr,
  161168. png_infop info_ptr));
  161169. extern PNG_EXPORT(void,png_set_rows) PNGARG((png_structp png_ptr,
  161170. png_infop info_ptr, png_bytepp row_pointers));
  161171. #endif
  161172. extern PNG_EXPORT(png_byte,png_get_channels) PNGARG((png_structp png_ptr,
  161173. png_infop info_ptr));
  161174. #ifdef PNG_EASY_ACCESS_SUPPORTED
  161175. extern PNG_EXPORT(png_uint_32, png_get_image_width) PNGARG((png_structp
  161176. png_ptr, png_infop info_ptr));
  161177. extern PNG_EXPORT(png_uint_32, png_get_image_height) PNGARG((png_structp
  161178. png_ptr, png_infop info_ptr));
  161179. extern PNG_EXPORT(png_byte, png_get_bit_depth) PNGARG((png_structp
  161180. png_ptr, png_infop info_ptr));
  161181. extern PNG_EXPORT(png_byte, png_get_color_type) PNGARG((png_structp
  161182. png_ptr, png_infop info_ptr));
  161183. extern PNG_EXPORT(png_byte, png_get_filter_type) PNGARG((png_structp
  161184. png_ptr, png_infop info_ptr));
  161185. extern PNG_EXPORT(png_byte, png_get_interlace_type) PNGARG((png_structp
  161186. png_ptr, png_infop info_ptr));
  161187. extern PNG_EXPORT(png_byte, png_get_compression_type) PNGARG((png_structp
  161188. png_ptr, png_infop info_ptr));
  161189. extern PNG_EXPORT(png_uint_32, png_get_pixels_per_meter) PNGARG((png_structp
  161190. png_ptr, png_infop info_ptr));
  161191. extern PNG_EXPORT(png_uint_32, png_get_x_pixels_per_meter) PNGARG((png_structp
  161192. png_ptr, png_infop info_ptr));
  161193. extern PNG_EXPORT(png_uint_32, png_get_y_pixels_per_meter) PNGARG((png_structp
  161194. png_ptr, png_infop info_ptr));
  161195. #ifdef PNG_FLOATING_POINT_SUPPORTED
  161196. extern PNG_EXPORT(float, png_get_pixel_aspect_ratio) PNGARG((png_structp
  161197. png_ptr, png_infop info_ptr));
  161198. #endif
  161199. extern PNG_EXPORT(png_int_32, png_get_x_offset_pixels) PNGARG((png_structp
  161200. png_ptr, png_infop info_ptr));
  161201. extern PNG_EXPORT(png_int_32, png_get_y_offset_pixels) PNGARG((png_structp
  161202. png_ptr, png_infop info_ptr));
  161203. extern PNG_EXPORT(png_int_32, png_get_x_offset_microns) PNGARG((png_structp
  161204. png_ptr, png_infop info_ptr));
  161205. extern PNG_EXPORT(png_int_32, png_get_y_offset_microns) PNGARG((png_structp
  161206. png_ptr, png_infop info_ptr));
  161207. #endif /* PNG_EASY_ACCESS_SUPPORTED */
  161208. extern PNG_EXPORT(png_bytep,png_get_signature) PNGARG((png_structp png_ptr,
  161209. png_infop info_ptr));
  161210. #if defined(PNG_bKGD_SUPPORTED)
  161211. extern PNG_EXPORT(png_uint_32,png_get_bKGD) PNGARG((png_structp png_ptr,
  161212. png_infop info_ptr, png_color_16p *background));
  161213. #endif
  161214. #if defined(PNG_bKGD_SUPPORTED)
  161215. extern PNG_EXPORT(void,png_set_bKGD) PNGARG((png_structp png_ptr,
  161216. png_infop info_ptr, png_color_16p background));
  161217. #endif
  161218. #if defined(PNG_cHRM_SUPPORTED)
  161219. #ifdef PNG_FLOATING_POINT_SUPPORTED
  161220. extern PNG_EXPORT(png_uint_32,png_get_cHRM) PNGARG((png_structp png_ptr,
  161221. png_infop info_ptr, double *white_x, double *white_y, double *red_x,
  161222. double *red_y, double *green_x, double *green_y, double *blue_x,
  161223. double *blue_y));
  161224. #endif
  161225. #ifdef PNG_FIXED_POINT_SUPPORTED
  161226. extern PNG_EXPORT(png_uint_32,png_get_cHRM_fixed) PNGARG((png_structp png_ptr,
  161227. png_infop info_ptr, png_fixed_point *int_white_x, png_fixed_point
  161228. *int_white_y, png_fixed_point *int_red_x, png_fixed_point *int_red_y,
  161229. png_fixed_point *int_green_x, png_fixed_point *int_green_y, png_fixed_point
  161230. *int_blue_x, png_fixed_point *int_blue_y));
  161231. #endif
  161232. #endif
  161233. #if defined(PNG_cHRM_SUPPORTED)
  161234. #ifdef PNG_FLOATING_POINT_SUPPORTED
  161235. extern PNG_EXPORT(void,png_set_cHRM) PNGARG((png_structp png_ptr,
  161236. png_infop info_ptr, double white_x, double white_y, double red_x,
  161237. double red_y, double green_x, double green_y, double blue_x, double blue_y));
  161238. #endif
  161239. #ifdef PNG_FIXED_POINT_SUPPORTED
  161240. extern PNG_EXPORT(void,png_set_cHRM_fixed) PNGARG((png_structp png_ptr,
  161241. png_infop info_ptr, png_fixed_point int_white_x, png_fixed_point int_white_y,
  161242. png_fixed_point int_red_x, png_fixed_point int_red_y, png_fixed_point
  161243. int_green_x, png_fixed_point int_green_y, png_fixed_point int_blue_x,
  161244. png_fixed_point int_blue_y));
  161245. #endif
  161246. #endif
  161247. #if defined(PNG_gAMA_SUPPORTED)
  161248. #ifdef PNG_FLOATING_POINT_SUPPORTED
  161249. extern PNG_EXPORT(png_uint_32,png_get_gAMA) PNGARG((png_structp png_ptr,
  161250. png_infop info_ptr, double *file_gamma));
  161251. #endif
  161252. extern PNG_EXPORT(png_uint_32,png_get_gAMA_fixed) PNGARG((png_structp png_ptr,
  161253. png_infop info_ptr, png_fixed_point *int_file_gamma));
  161254. #endif
  161255. #if defined(PNG_gAMA_SUPPORTED)
  161256. #ifdef PNG_FLOATING_POINT_SUPPORTED
  161257. extern PNG_EXPORT(void,png_set_gAMA) PNGARG((png_structp png_ptr,
  161258. png_infop info_ptr, double file_gamma));
  161259. #endif
  161260. extern PNG_EXPORT(void,png_set_gAMA_fixed) PNGARG((png_structp png_ptr,
  161261. png_infop info_ptr, png_fixed_point int_file_gamma));
  161262. #endif
  161263. #if defined(PNG_hIST_SUPPORTED)
  161264. extern PNG_EXPORT(png_uint_32,png_get_hIST) PNGARG((png_structp png_ptr,
  161265. png_infop info_ptr, png_uint_16p *hist));
  161266. #endif
  161267. #if defined(PNG_hIST_SUPPORTED)
  161268. extern PNG_EXPORT(void,png_set_hIST) PNGARG((png_structp png_ptr,
  161269. png_infop info_ptr, png_uint_16p hist));
  161270. #endif
  161271. extern PNG_EXPORT(png_uint_32,png_get_IHDR) PNGARG((png_structp png_ptr,
  161272. png_infop info_ptr, png_uint_32 *width, png_uint_32 *height,
  161273. int *bit_depth, int *color_type, int *interlace_method,
  161274. int *compression_method, int *filter_method));
  161275. extern PNG_EXPORT(void,png_set_IHDR) PNGARG((png_structp png_ptr,
  161276. png_infop info_ptr, png_uint_32 width, png_uint_32 height, int bit_depth,
  161277. int color_type, int interlace_method, int compression_method,
  161278. int filter_method));
  161279. #if defined(PNG_oFFs_SUPPORTED)
  161280. extern PNG_EXPORT(png_uint_32,png_get_oFFs) PNGARG((png_structp png_ptr,
  161281. png_infop info_ptr, png_int_32 *offset_x, png_int_32 *offset_y,
  161282. int *unit_type));
  161283. #endif
  161284. #if defined(PNG_oFFs_SUPPORTED)
  161285. extern PNG_EXPORT(void,png_set_oFFs) PNGARG((png_structp png_ptr,
  161286. png_infop info_ptr, png_int_32 offset_x, png_int_32 offset_y,
  161287. int unit_type));
  161288. #endif
  161289. #if defined(PNG_pCAL_SUPPORTED)
  161290. extern PNG_EXPORT(png_uint_32,png_get_pCAL) PNGARG((png_structp png_ptr,
  161291. png_infop info_ptr, png_charp *purpose, png_int_32 *X0, png_int_32 *X1,
  161292. int *type, int *nparams, png_charp *units, png_charpp *params));
  161293. #endif
  161294. #if defined(PNG_pCAL_SUPPORTED)
  161295. extern PNG_EXPORT(void,png_set_pCAL) PNGARG((png_structp png_ptr,
  161296. png_infop info_ptr, png_charp purpose, png_int_32 X0, png_int_32 X1,
  161297. int type, int nparams, png_charp units, png_charpp params));
  161298. #endif
  161299. #if defined(PNG_pHYs_SUPPORTED)
  161300. extern PNG_EXPORT(png_uint_32,png_get_pHYs) PNGARG((png_structp png_ptr,
  161301. png_infop info_ptr, png_uint_32 *res_x, png_uint_32 *res_y, int *unit_type));
  161302. #endif
  161303. #if defined(PNG_pHYs_SUPPORTED)
  161304. extern PNG_EXPORT(void,png_set_pHYs) PNGARG((png_structp png_ptr,
  161305. png_infop info_ptr, png_uint_32 res_x, png_uint_32 res_y, int unit_type));
  161306. #endif
  161307. extern PNG_EXPORT(png_uint_32,png_get_PLTE) PNGARG((png_structp png_ptr,
  161308. png_infop info_ptr, png_colorp *palette, int *num_palette));
  161309. extern PNG_EXPORT(void,png_set_PLTE) PNGARG((png_structp png_ptr,
  161310. png_infop info_ptr, png_colorp palette, int num_palette));
  161311. #if defined(PNG_sBIT_SUPPORTED)
  161312. extern PNG_EXPORT(png_uint_32,png_get_sBIT) PNGARG((png_structp png_ptr,
  161313. png_infop info_ptr, png_color_8p *sig_bit));
  161314. #endif
  161315. #if defined(PNG_sBIT_SUPPORTED)
  161316. extern PNG_EXPORT(void,png_set_sBIT) PNGARG((png_structp png_ptr,
  161317. png_infop info_ptr, png_color_8p sig_bit));
  161318. #endif
  161319. #if defined(PNG_sRGB_SUPPORTED)
  161320. extern PNG_EXPORT(png_uint_32,png_get_sRGB) PNGARG((png_structp png_ptr,
  161321. png_infop info_ptr, int *intent));
  161322. #endif
  161323. #if defined(PNG_sRGB_SUPPORTED)
  161324. extern PNG_EXPORT(void,png_set_sRGB) PNGARG((png_structp png_ptr,
  161325. png_infop info_ptr, int intent));
  161326. extern PNG_EXPORT(void,png_set_sRGB_gAMA_and_cHRM) PNGARG((png_structp png_ptr,
  161327. png_infop info_ptr, int intent));
  161328. #endif
  161329. #if defined(PNG_iCCP_SUPPORTED)
  161330. extern PNG_EXPORT(png_uint_32,png_get_iCCP) PNGARG((png_structp png_ptr,
  161331. png_infop info_ptr, png_charpp name, int *compression_type,
  161332. png_charpp profile, png_uint_32 *proflen));
  161333. #endif
  161334. #if defined(PNG_iCCP_SUPPORTED)
  161335. extern PNG_EXPORT(void,png_set_iCCP) PNGARG((png_structp png_ptr,
  161336. png_infop info_ptr, png_charp name, int compression_type,
  161337. png_charp profile, png_uint_32 proflen));
  161338. #endif
  161339. #if defined(PNG_sPLT_SUPPORTED)
  161340. extern PNG_EXPORT(png_uint_32,png_get_sPLT) PNGARG((png_structp png_ptr,
  161341. png_infop info_ptr, png_sPLT_tpp entries));
  161342. #endif
  161343. #if defined(PNG_sPLT_SUPPORTED)
  161344. extern PNG_EXPORT(void,png_set_sPLT) PNGARG((png_structp png_ptr,
  161345. png_infop info_ptr, png_sPLT_tp entries, int nentries));
  161346. #endif
  161347. #if defined(PNG_TEXT_SUPPORTED)
  161348. extern PNG_EXPORT(png_uint_32,png_get_text) PNGARG((png_structp png_ptr,
  161349. png_infop info_ptr, png_textp *text_ptr, int *num_text));
  161350. #endif
  161351. #if defined(PNG_TEXT_SUPPORTED)
  161352. extern PNG_EXPORT(void,png_set_text) PNGARG((png_structp png_ptr,
  161353. png_infop info_ptr, png_textp text_ptr, int num_text));
  161354. #endif
  161355. #if defined(PNG_tIME_SUPPORTED)
  161356. extern PNG_EXPORT(png_uint_32,png_get_tIME) PNGARG((png_structp png_ptr,
  161357. png_infop info_ptr, png_timep *mod_time));
  161358. #endif
  161359. #if defined(PNG_tIME_SUPPORTED)
  161360. extern PNG_EXPORT(void,png_set_tIME) PNGARG((png_structp png_ptr,
  161361. png_infop info_ptr, png_timep mod_time));
  161362. #endif
  161363. #if defined(PNG_tRNS_SUPPORTED)
  161364. extern PNG_EXPORT(png_uint_32,png_get_tRNS) PNGARG((png_structp png_ptr,
  161365. png_infop info_ptr, png_bytep *trans, int *num_trans,
  161366. png_color_16p *trans_values));
  161367. #endif
  161368. #if defined(PNG_tRNS_SUPPORTED)
  161369. extern PNG_EXPORT(void,png_set_tRNS) PNGARG((png_structp png_ptr,
  161370. png_infop info_ptr, png_bytep trans, int num_trans,
  161371. png_color_16p trans_values));
  161372. #endif
  161373. #if defined(PNG_tRNS_SUPPORTED)
  161374. #endif
  161375. #if defined(PNG_sCAL_SUPPORTED)
  161376. #ifdef PNG_FLOATING_POINT_SUPPORTED
  161377. extern PNG_EXPORT(png_uint_32,png_get_sCAL) PNGARG((png_structp png_ptr,
  161378. png_infop info_ptr, int *unit, double *width, double *height));
  161379. #else
  161380. #ifdef PNG_FIXED_POINT_SUPPORTED
  161381. extern PNG_EXPORT(png_uint_32,png_get_sCAL_s) PNGARG((png_structp png_ptr,
  161382. png_infop info_ptr, int *unit, png_charpp swidth, png_charpp sheight));
  161383. #endif
  161384. #endif
  161385. #endif /* PNG_sCAL_SUPPORTED */
  161386. #if defined(PNG_sCAL_SUPPORTED)
  161387. #ifdef PNG_FLOATING_POINT_SUPPORTED
  161388. extern PNG_EXPORT(void,png_set_sCAL) PNGARG((png_structp png_ptr,
  161389. png_infop info_ptr, int unit, double width, double height));
  161390. #else
  161391. #ifdef PNG_FIXED_POINT_SUPPORTED
  161392. extern PNG_EXPORT(void,png_set_sCAL_s) PNGARG((png_structp png_ptr,
  161393. png_infop info_ptr, int unit, png_charp swidth, png_charp sheight));
  161394. #endif
  161395. #endif
  161396. #endif /* PNG_sCAL_SUPPORTED || PNG_WRITE_sCAL_SUPPORTED */
  161397. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  161398. extern PNG_EXPORT(void, png_set_keep_unknown_chunks) PNGARG((png_structp
  161399. png_ptr, int keep, png_bytep chunk_list, int num_chunks));
  161400. extern PNG_EXPORT(void, png_set_unknown_chunks) PNGARG((png_structp png_ptr,
  161401. png_infop info_ptr, png_unknown_chunkp unknowns, int num_unknowns));
  161402. extern PNG_EXPORT(void, png_set_unknown_chunk_location)
  161403. PNGARG((png_structp png_ptr, png_infop info_ptr, int chunk, int location));
  161404. extern PNG_EXPORT(png_uint_32,png_get_unknown_chunks) PNGARG((png_structp
  161405. png_ptr, png_infop info_ptr, png_unknown_chunkpp entries));
  161406. #endif
  161407. #ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
  161408. PNG_EXPORT(int,png_handle_as_unknown) PNGARG((png_structp png_ptr, png_bytep
  161409. chunk_name));
  161410. #endif
  161411. extern PNG_EXPORT(void, png_set_invalid) PNGARG((png_structp png_ptr,
  161412. png_infop info_ptr, int mask));
  161413. #if defined(PNG_INFO_IMAGE_SUPPORTED)
  161414. extern PNG_EXPORT(void, png_read_png) PNGARG((png_structp png_ptr,
  161415. png_infop info_ptr,
  161416. int transforms,
  161417. png_voidp params));
  161418. extern PNG_EXPORT(void, png_write_png) PNGARG((png_structp png_ptr,
  161419. png_infop info_ptr,
  161420. int transforms,
  161421. png_voidp params));
  161422. #endif
  161423. #ifdef PNG_DEBUG
  161424. #if (PNG_DEBUG > 0)
  161425. #if !defined(PNG_DEBUG_FILE) && defined(_MSC_VER)
  161426. #include <crtdbg.h>
  161427. #if (PNG_DEBUG > 1)
  161428. #define png_debug(l,m) _RPT0(_CRT_WARN,m)
  161429. #define png_debug1(l,m,p1) _RPT1(_CRT_WARN,m,p1)
  161430. #define png_debug2(l,m,p1,p2) _RPT2(_CRT_WARN,m,p1,p2)
  161431. #endif
  161432. #else /* PNG_DEBUG_FILE || !_MSC_VER */
  161433. #ifndef PNG_DEBUG_FILE
  161434. #define PNG_DEBUG_FILE stderr
  161435. #endif /* PNG_DEBUG_FILE */
  161436. #if (PNG_DEBUG > 1)
  161437. #define png_debug(l,m) \
  161438. { \
  161439. int num_tabs=l; \
  161440. fprintf(PNG_DEBUG_FILE,"%s"m,(num_tabs==1 ? "\t" : \
  161441. (num_tabs==2 ? "\t\t":(num_tabs>2 ? "\t\t\t":"")))); \
  161442. }
  161443. #define png_debug1(l,m,p1) \
  161444. { \
  161445. int num_tabs=l; \
  161446. fprintf(PNG_DEBUG_FILE,"%s"m,(num_tabs==1 ? "\t" : \
  161447. (num_tabs==2 ? "\t\t":(num_tabs>2 ? "\t\t\t":""))),p1); \
  161448. }
  161449. #define png_debug2(l,m,p1,p2) \
  161450. { \
  161451. int num_tabs=l; \
  161452. fprintf(PNG_DEBUG_FILE,"%s"m,(num_tabs==1 ? "\t" : \
  161453. (num_tabs==2 ? "\t\t":(num_tabs>2 ? "\t\t\t":""))),p1,p2); \
  161454. }
  161455. #endif /* (PNG_DEBUG > 1) */
  161456. #endif /* _MSC_VER */
  161457. #endif /* (PNG_DEBUG > 0) */
  161458. #endif /* PNG_DEBUG */
  161459. #ifndef png_debug
  161460. #define png_debug(l, m)
  161461. #endif
  161462. #ifndef png_debug1
  161463. #define png_debug1(l, m, p1)
  161464. #endif
  161465. #ifndef png_debug2
  161466. #define png_debug2(l, m, p1, p2)
  161467. #endif
  161468. extern PNG_EXPORT(png_charp,png_get_copyright) PNGARG((png_structp png_ptr));
  161469. extern PNG_EXPORT(png_charp,png_get_header_ver) PNGARG((png_structp png_ptr));
  161470. extern PNG_EXPORT(png_charp,png_get_header_version) PNGARG((png_structp png_ptr));
  161471. extern PNG_EXPORT(png_charp,png_get_libpng_ver) PNGARG((png_structp png_ptr));
  161472. #ifdef PNG_MNG_FEATURES_SUPPORTED
  161473. extern PNG_EXPORT(png_uint_32,png_permit_mng_features) PNGARG((png_structp
  161474. png_ptr, png_uint_32 mng_features_permitted));
  161475. #endif
  161476. #define PNG_HANDLE_CHUNK_AS_DEFAULT 0
  161477. #define PNG_HANDLE_CHUNK_NEVER 1
  161478. #define PNG_HANDLE_CHUNK_IF_SAFE 2
  161479. #define PNG_HANDLE_CHUNK_ALWAYS 3
  161480. #if defined(PNG_ASSEMBLER_CODE_SUPPORTED)
  161481. #if defined(PNG_MMX_CODE_SUPPORTED)
  161482. #define PNG_ASM_FLAG_MMX_SUPPORT_COMPILED 0x01 /* not user-settable */
  161483. #define PNG_ASM_FLAG_MMX_SUPPORT_IN_CPU 0x02 /* not user-settable */
  161484. #define PNG_ASM_FLAG_MMX_READ_COMBINE_ROW 0x04
  161485. #define PNG_ASM_FLAG_MMX_READ_INTERLACE 0x08
  161486. #define PNG_ASM_FLAG_MMX_READ_FILTER_SUB 0x10
  161487. #define PNG_ASM_FLAG_MMX_READ_FILTER_UP 0x20
  161488. #define PNG_ASM_FLAG_MMX_READ_FILTER_AVG 0x40
  161489. #define PNG_ASM_FLAG_MMX_READ_FILTER_PAETH 0x80
  161490. #define PNG_ASM_FLAGS_INITIALIZED 0x80000000 /* not user-settable */
  161491. #define PNG_MMX_READ_FLAGS ( PNG_ASM_FLAG_MMX_READ_COMBINE_ROW \
  161492. | PNG_ASM_FLAG_MMX_READ_INTERLACE \
  161493. | PNG_ASM_FLAG_MMX_READ_FILTER_SUB \
  161494. | PNG_ASM_FLAG_MMX_READ_FILTER_UP \
  161495. | PNG_ASM_FLAG_MMX_READ_FILTER_AVG \
  161496. | PNG_ASM_FLAG_MMX_READ_FILTER_PAETH )
  161497. #define PNG_MMX_WRITE_FLAGS ( 0 )
  161498. #define PNG_MMX_FLAGS ( PNG_ASM_FLAG_MMX_SUPPORT_COMPILED \
  161499. | PNG_ASM_FLAG_MMX_SUPPORT_IN_CPU \
  161500. | PNG_MMX_READ_FLAGS \
  161501. | PNG_MMX_WRITE_FLAGS )
  161502. #define PNG_SELECT_READ 1
  161503. #define PNG_SELECT_WRITE 2
  161504. #endif /* PNG_MMX_CODE_SUPPORTED */
  161505. #if !defined(PNG_1_0_X)
  161506. extern PNG_EXPORT(png_uint_32,png_get_mmx_flagmask)
  161507. PNGARG((int flag_select, int *compilerID));
  161508. extern PNG_EXPORT(png_uint_32,png_get_asm_flagmask)
  161509. PNGARG((int flag_select));
  161510. extern PNG_EXPORT(png_uint_32,png_get_asm_flags)
  161511. PNGARG((png_structp png_ptr));
  161512. extern PNG_EXPORT(png_byte,png_get_mmx_bitdepth_threshold)
  161513. PNGARG((png_structp png_ptr));
  161514. extern PNG_EXPORT(png_uint_32,png_get_mmx_rowbytes_threshold)
  161515. PNGARG((png_structp png_ptr));
  161516. extern PNG_EXPORT(void,png_set_asm_flags)
  161517. PNGARG((png_structp png_ptr, png_uint_32 asm_flags));
  161518. extern PNG_EXPORT(void,png_set_mmx_thresholds)
  161519. PNGARG((png_structp png_ptr, png_byte mmx_bitdepth_threshold,
  161520. png_uint_32 mmx_rowbytes_threshold));
  161521. #endif /* PNG_1_0_X */
  161522. #if !defined(PNG_1_0_X)
  161523. extern PNG_EXPORT(int,png_mmx_support) PNGARG((void));
  161524. #endif /* PNG_ASSEMBLER_CODE_SUPPORTED */
  161525. #ifdef PNG_ERROR_NUMBERS_SUPPORTED
  161526. extern PNG_EXPORT(void,png_set_strip_error_numbers) PNGARG((png_structp
  161527. png_ptr, png_uint_32 strip_mode));
  161528. #endif
  161529. #endif /* PNG_1_0_X */
  161530. #ifdef PNG_SET_USER_LIMITS_SUPPORTED
  161531. extern PNG_EXPORT(void,png_set_user_limits) PNGARG((png_structp
  161532. png_ptr, png_uint_32 user_width_max, png_uint_32 user_height_max));
  161533. extern PNG_EXPORT(png_uint_32,png_get_user_width_max) PNGARG((png_structp
  161534. png_ptr));
  161535. extern PNG_EXPORT(png_uint_32,png_get_user_height_max) PNGARG((png_structp
  161536. png_ptr));
  161537. #endif
  161538. #ifdef PNG_READ_COMPOSITE_NODIV_SUPPORTED
  161539. # define png_composite(composite, fg, alpha, bg) \
  161540. { png_uint_16 temp = (png_uint_16)((png_uint_16)(fg) * (png_uint_16)(alpha) \
  161541. + (png_uint_16)(bg)*(png_uint_16)(255 - \
  161542. (png_uint_16)(alpha)) + (png_uint_16)128); \
  161543. (composite) = (png_byte)((temp + (temp >> 8)) >> 8); }
  161544. # define png_composite_16(composite, fg, alpha, bg) \
  161545. { png_uint_32 temp = (png_uint_32)((png_uint_32)(fg) * (png_uint_32)(alpha) \
  161546. + (png_uint_32)(bg)*(png_uint_32)(65535L - \
  161547. (png_uint_32)(alpha)) + (png_uint_32)32768L); \
  161548. (composite) = (png_uint_16)((temp + (temp >> 16)) >> 16); }
  161549. #else /* standard method using integer division */
  161550. # define png_composite(composite, fg, alpha, bg) \
  161551. (composite) = (png_byte)(((png_uint_16)(fg) * (png_uint_16)(alpha) + \
  161552. (png_uint_16)(bg) * (png_uint_16)(255 - (png_uint_16)(alpha)) + \
  161553. (png_uint_16)127) / 255)
  161554. # define png_composite_16(composite, fg, alpha, bg) \
  161555. (composite) = (png_uint_16)(((png_uint_32)(fg) * (png_uint_32)(alpha) + \
  161556. (png_uint_32)(bg)*(png_uint_32)(65535L - (png_uint_32)(alpha)) + \
  161557. (png_uint_32)32767) / (png_uint_32)65535L)
  161558. #endif /* PNG_READ_COMPOSITE_NODIV_SUPPORTED */
  161559. #if defined(PNG_READ_BIG_ENDIAN_SUPPORTED)
  161560. # define png_get_uint_32(buf) ( *((png_uint_32p) (buf)))
  161561. # define png_get_uint_16(buf) ( *((png_uint_16p) (buf)))
  161562. # define png_get_int_32(buf) ( *((png_int_32p) (buf)))
  161563. #else
  161564. extern PNG_EXPORT(png_uint_32,png_get_uint_32) PNGARG((png_bytep buf));
  161565. extern PNG_EXPORT(png_uint_16,png_get_uint_16) PNGARG((png_bytep buf));
  161566. extern PNG_EXPORT(png_int_32,png_get_int_32) PNGARG((png_bytep buf));
  161567. #endif /* !PNG_READ_BIG_ENDIAN_SUPPORTED */
  161568. extern PNG_EXPORT(png_uint_32,png_get_uint_31)
  161569. PNGARG((png_structp png_ptr, png_bytep buf));
  161570. extern PNG_EXPORT(void,png_save_uint_32)
  161571. PNGARG((png_bytep buf, png_uint_32 i));
  161572. extern PNG_EXPORT(void,png_save_int_32)
  161573. PNGARG((png_bytep buf, png_int_32 i));
  161574. extern PNG_EXPORT(void,png_save_uint_16)
  161575. PNGARG((png_bytep buf, unsigned int i));
  161576. #define PNG_HAVE_IHDR 0x01
  161577. #define PNG_HAVE_PLTE 0x02
  161578. #define PNG_HAVE_IDAT 0x04
  161579. #define PNG_AFTER_IDAT 0x08 /* Have complete zlib datastream */
  161580. #define PNG_HAVE_IEND 0x10
  161581. #if defined(PNG_INTERNAL)
  161582. #define PNG_HAVE_gAMA 0x20
  161583. #define PNG_HAVE_cHRM 0x40
  161584. #define PNG_HAVE_sRGB 0x80
  161585. #define PNG_HAVE_CHUNK_HEADER 0x100
  161586. #define PNG_WROTE_tIME 0x200
  161587. #define PNG_WROTE_INFO_BEFORE_PLTE 0x400
  161588. #define PNG_BACKGROUND_IS_GRAY 0x800
  161589. #define PNG_HAVE_PNG_SIGNATURE 0x1000
  161590. #define PNG_HAVE_CHUNK_AFTER_IDAT 0x2000 /* Have another chunk after IDAT */
  161591. #define PNG_BGR 0x0001
  161592. #define PNG_INTERLACE 0x0002
  161593. #define PNG_PACK 0x0004
  161594. #define PNG_SHIFT 0x0008
  161595. #define PNG_SWAP_BYTES 0x0010
  161596. #define PNG_INVERT_MONO 0x0020
  161597. #define PNG_DITHER 0x0040
  161598. #define PNG_BACKGROUND 0x0080
  161599. #define PNG_BACKGROUND_EXPAND 0x0100
  161600. #define PNG_16_TO_8 0x0400
  161601. #define PNG_RGBA 0x0800
  161602. #define PNG_EXPAND 0x1000
  161603. #define PNG_GAMMA 0x2000
  161604. #define PNG_GRAY_TO_RGB 0x4000
  161605. #define PNG_FILLER 0x8000L
  161606. #define PNG_PACKSWAP 0x10000L
  161607. #define PNG_SWAP_ALPHA 0x20000L
  161608. #define PNG_STRIP_ALPHA 0x40000L
  161609. #define PNG_INVERT_ALPHA 0x80000L
  161610. #define PNG_USER_TRANSFORM 0x100000L
  161611. #define PNG_RGB_TO_GRAY_ERR 0x200000L
  161612. #define PNG_RGB_TO_GRAY_WARN 0x400000L
  161613. #define PNG_RGB_TO_GRAY 0x600000L /* two bits, RGB_TO_GRAY_ERR|WARN */
  161614. #define PNG_ADD_ALPHA 0x1000000L /* Added to libpng-1.2.7 */
  161615. #define PNG_EXPAND_tRNS 0x2000000L /* Added to libpng-1.2.9 */
  161616. #define PNG_STRUCT_PNG 0x0001
  161617. #define PNG_STRUCT_INFO 0x0002
  161618. #define PNG_WEIGHT_SHIFT 8
  161619. #define PNG_WEIGHT_FACTOR (1<<(PNG_WEIGHT_SHIFT))
  161620. #define PNG_COST_SHIFT 3
  161621. #define PNG_COST_FACTOR (1<<(PNG_COST_SHIFT))
  161622. #define PNG_FLAG_ZLIB_CUSTOM_STRATEGY 0x0001
  161623. #define PNG_FLAG_ZLIB_CUSTOM_LEVEL 0x0002
  161624. #define PNG_FLAG_ZLIB_CUSTOM_MEM_LEVEL 0x0004
  161625. #define PNG_FLAG_ZLIB_CUSTOM_WINDOW_BITS 0x0008
  161626. #define PNG_FLAG_ZLIB_CUSTOM_METHOD 0x0010
  161627. #define PNG_FLAG_ZLIB_FINISHED 0x0020
  161628. #define PNG_FLAG_ROW_INIT 0x0040
  161629. #define PNG_FLAG_FILLER_AFTER 0x0080
  161630. #define PNG_FLAG_CRC_ANCILLARY_USE 0x0100
  161631. #define PNG_FLAG_CRC_ANCILLARY_NOWARN 0x0200
  161632. #define PNG_FLAG_CRC_CRITICAL_USE 0x0400
  161633. #define PNG_FLAG_CRC_CRITICAL_IGNORE 0x0800
  161634. #define PNG_FLAG_FREE_PLTE 0x1000
  161635. #define PNG_FLAG_FREE_TRNS 0x2000
  161636. #define PNG_FLAG_FREE_HIST 0x4000
  161637. #define PNG_FLAG_KEEP_UNKNOWN_CHUNKS 0x8000L
  161638. #define PNG_FLAG_KEEP_UNSAFE_CHUNKS 0x10000L
  161639. #define PNG_FLAG_LIBRARY_MISMATCH 0x20000L
  161640. #define PNG_FLAG_STRIP_ERROR_NUMBERS 0x40000L
  161641. #define PNG_FLAG_STRIP_ERROR_TEXT 0x80000L
  161642. #define PNG_FLAG_MALLOC_NULL_MEM_OK 0x100000L
  161643. #define PNG_FLAG_ADD_ALPHA 0x200000L /* Added to libpng-1.2.8 */
  161644. #define PNG_FLAG_STRIP_ALPHA 0x400000L /* Added to libpng-1.2.8 */
  161645. #define PNG_FLAG_CRC_ANCILLARY_MASK (PNG_FLAG_CRC_ANCILLARY_USE | \
  161646. PNG_FLAG_CRC_ANCILLARY_NOWARN)
  161647. #define PNG_FLAG_CRC_CRITICAL_MASK (PNG_FLAG_CRC_CRITICAL_USE | \
  161648. PNG_FLAG_CRC_CRITICAL_IGNORE)
  161649. #define PNG_FLAG_CRC_MASK (PNG_FLAG_CRC_ANCILLARY_MASK | \
  161650. PNG_FLAG_CRC_CRITICAL_MASK)
  161651. #define PNG_COLOR_DIST(c1, c2) (abs((int)((c1).red) - (int)((c2).red)) + \
  161652. abs((int)((c1).green) - (int)((c2).green)) + \
  161653. abs((int)((c1).blue) - (int)((c2).blue)))
  161654. #define PNG_ROWBYTES(pixel_bits, width) \
  161655. ((pixel_bits) >= 8 ? \
  161656. ((width) * (((png_uint_32)(pixel_bits)) >> 3)) : \
  161657. (( ((width) * ((png_uint_32)(pixel_bits))) + 7) >> 3) )
  161658. #define PNG_OUT_OF_RANGE(value, ideal, delta) \
  161659. ( (value) < (ideal)-(delta) || (value) > (ideal)+(delta) )
  161660. #if !defined(PNG_NO_EXTERN) || defined(PNG_ALWAYS_EXTERN)
  161661. #ifdef PNG_USE_GLOBAL_ARRAYS
  161662. PNG_EXPORT_VAR (PNG_CONST png_byte FARDATA) png_sig[8];
  161663. #else
  161664. #endif
  161665. #endif /* PNG_NO_EXTERN */
  161666. #define PNG_IHDR png_byte png_IHDR[5] = { 73, 72, 68, 82, '\0'}
  161667. #define PNG_IDAT png_byte png_IDAT[5] = { 73, 68, 65, 84, '\0'}
  161668. #define PNG_IEND png_byte png_IEND[5] = { 73, 69, 78, 68, '\0'}
  161669. #define PNG_PLTE png_byte png_PLTE[5] = { 80, 76, 84, 69, '\0'}
  161670. #define PNG_bKGD png_byte png_bKGD[5] = { 98, 75, 71, 68, '\0'}
  161671. #define PNG_cHRM png_byte png_cHRM[5] = { 99, 72, 82, 77, '\0'}
  161672. #define PNG_gAMA png_byte png_gAMA[5] = {103, 65, 77, 65, '\0'}
  161673. #define PNG_hIST png_byte png_hIST[5] = {104, 73, 83, 84, '\0'}
  161674. #define PNG_iCCP png_byte png_iCCP[5] = {105, 67, 67, 80, '\0'}
  161675. #define PNG_iTXt png_byte png_iTXt[5] = {105, 84, 88, 116, '\0'}
  161676. #define PNG_oFFs png_byte png_oFFs[5] = {111, 70, 70, 115, '\0'}
  161677. #define PNG_pCAL png_byte png_pCAL[5] = {112, 67, 65, 76, '\0'}
  161678. #define PNG_sCAL png_byte png_sCAL[5] = {115, 67, 65, 76, '\0'}
  161679. #define PNG_pHYs png_byte png_pHYs[5] = {112, 72, 89, 115, '\0'}
  161680. #define PNG_sBIT png_byte png_sBIT[5] = {115, 66, 73, 84, '\0'}
  161681. #define PNG_sPLT png_byte png_sPLT[5] = {115, 80, 76, 84, '\0'}
  161682. #define PNG_sRGB png_byte png_sRGB[5] = {115, 82, 71, 66, '\0'}
  161683. #define PNG_tEXt png_byte png_tEXt[5] = {116, 69, 88, 116, '\0'}
  161684. #define PNG_tIME png_byte png_tIME[5] = {116, 73, 77, 69, '\0'}
  161685. #define PNG_tRNS png_byte png_tRNS[5] = {116, 82, 78, 83, '\0'}
  161686. #define PNG_zTXt png_byte png_zTXt[5] = {122, 84, 88, 116, '\0'}
  161687. #ifdef PNG_USE_GLOBAL_ARRAYS
  161688. PNG_EXPORT_VAR (png_byte FARDATA) png_IHDR[5];
  161689. PNG_EXPORT_VAR (png_byte FARDATA) png_IDAT[5];
  161690. PNG_EXPORT_VAR (png_byte FARDATA) png_IEND[5];
  161691. PNG_EXPORT_VAR (png_byte FARDATA) png_PLTE[5];
  161692. PNG_EXPORT_VAR (png_byte FARDATA) png_bKGD[5];
  161693. PNG_EXPORT_VAR (png_byte FARDATA) png_cHRM[5];
  161694. PNG_EXPORT_VAR (png_byte FARDATA) png_gAMA[5];
  161695. PNG_EXPORT_VAR (png_byte FARDATA) png_hIST[5];
  161696. PNG_EXPORT_VAR (png_byte FARDATA) png_iCCP[5];
  161697. PNG_EXPORT_VAR (png_byte FARDATA) png_iTXt[5];
  161698. PNG_EXPORT_VAR (png_byte FARDATA) png_oFFs[5];
  161699. PNG_EXPORT_VAR (png_byte FARDATA) png_pCAL[5];
  161700. PNG_EXPORT_VAR (png_byte FARDATA) png_sCAL[5];
  161701. PNG_EXPORT_VAR (png_byte FARDATA) png_pHYs[5];
  161702. PNG_EXPORT_VAR (png_byte FARDATA) png_sBIT[5];
  161703. PNG_EXPORT_VAR (png_byte FARDATA) png_sPLT[5];
  161704. PNG_EXPORT_VAR (png_byte FARDATA) png_sRGB[5];
  161705. PNG_EXPORT_VAR (png_byte FARDATA) png_tEXt[5];
  161706. PNG_EXPORT_VAR (png_byte FARDATA) png_tIME[5];
  161707. PNG_EXPORT_VAR (png_byte FARDATA) png_tRNS[5];
  161708. PNG_EXPORT_VAR (png_byte FARDATA) png_zTXt[5];
  161709. #endif /* PNG_USE_GLOBAL_ARRAYS */
  161710. #if defined(PNG_1_0_X) || defined (PNG_1_2_X)
  161711. extern PNG_EXPORT(void,png_read_init) PNGARG((png_structp png_ptr));
  161712. #undef png_read_init
  161713. #define png_read_init(png_ptr) png_read_init_3(&png_ptr, \
  161714. PNG_LIBPNG_VER_STRING, png_sizeof(png_struct));
  161715. #endif
  161716. extern PNG_EXPORT(void,png_read_init_3) PNGARG((png_structpp ptr_ptr,
  161717. png_const_charp user_png_ver, png_size_t png_struct_size));
  161718. #if defined(PNG_1_0_X) || defined (PNG_1_2_X)
  161719. extern PNG_EXPORT(void,png_read_init_2) PNGARG((png_structp png_ptr,
  161720. png_const_charp user_png_ver, png_size_t png_struct_size, png_size_t
  161721. png_info_size));
  161722. #endif
  161723. #if defined(PNG_1_0_X) || defined (PNG_1_2_X)
  161724. extern PNG_EXPORT(void,png_write_init) PNGARG((png_structp png_ptr));
  161725. #undef png_write_init
  161726. #define png_write_init(png_ptr) png_write_init_3(&png_ptr, \
  161727. PNG_LIBPNG_VER_STRING, png_sizeof(png_struct));
  161728. #endif
  161729. extern PNG_EXPORT(void,png_write_init_3) PNGARG((png_structpp ptr_ptr,
  161730. png_const_charp user_png_ver, png_size_t png_struct_size));
  161731. extern PNG_EXPORT(void,png_write_init_2) PNGARG((png_structp png_ptr,
  161732. png_const_charp user_png_ver, png_size_t png_struct_size, png_size_t
  161733. png_info_size));
  161734. PNG_EXTERN png_voidp png_create_struct PNGARG((int type));
  161735. PNG_EXTERN void png_destroy_struct PNGARG((png_voidp struct_ptr));
  161736. PNG_EXTERN png_voidp png_create_struct_2 PNGARG((int type, png_malloc_ptr
  161737. malloc_fn, png_voidp mem_ptr));
  161738. PNG_EXTERN void png_destroy_struct_2 PNGARG((png_voidp struct_ptr,
  161739. png_free_ptr free_fn, png_voidp mem_ptr));
  161740. PNG_EXTERN void png_info_destroy PNGARG((png_structp png_ptr,
  161741. png_infop info_ptr));
  161742. #ifndef PNG_1_0_X
  161743. PNG_EXTERN voidpf png_zalloc PNGARG((voidpf png_ptr, uInt items, uInt size));
  161744. PNG_EXTERN void png_zfree PNGARG((voidpf png_ptr, voidpf ptr));
  161745. #ifdef PNG_SIZE_T
  161746. PNG_EXTERN png_size_t PNGAPI png_convert_size PNGARG((size_t size));
  161747. #endif
  161748. PNG_EXTERN void PNGAPI png_default_read_data PNGARG((png_structp png_ptr,
  161749. png_bytep data, png_size_t length));
  161750. #ifdef PNG_PROGRESSIVE_READ_SUPPORTED
  161751. PNG_EXTERN void PNGAPI png_push_fill_buffer PNGARG((png_structp png_ptr,
  161752. png_bytep buffer, png_size_t length));
  161753. #endif
  161754. PNG_EXTERN void PNGAPI png_default_write_data PNGARG((png_structp png_ptr,
  161755. png_bytep data, png_size_t length));
  161756. #if defined(PNG_WRITE_FLUSH_SUPPORTED)
  161757. #if !defined(PNG_NO_STDIO)
  161758. PNG_EXTERN void PNGAPI png_default_flush PNGARG((png_structp png_ptr));
  161759. #endif
  161760. #endif
  161761. #else /* PNG_1_0_X */
  161762. #ifdef PNG_PROGRESSIVE_READ_SUPPORTED
  161763. PNG_EXTERN void png_push_fill_buffer PNGARG((png_structp png_ptr,
  161764. png_bytep buffer, png_size_t length));
  161765. #endif
  161766. #endif /* PNG_1_0_X */
  161767. PNG_EXTERN void png_reset_crc PNGARG((png_structp png_ptr));
  161768. PNG_EXTERN void png_write_data PNGARG((png_structp png_ptr, png_bytep data,
  161769. png_size_t length));
  161770. PNG_EXTERN void png_read_data PNGARG((png_structp png_ptr, png_bytep data,
  161771. png_size_t length));
  161772. PNG_EXTERN void png_crc_read PNGARG((png_structp png_ptr, png_bytep buf,
  161773. png_size_t length));
  161774. #if defined(PNG_zTXt_SUPPORTED) || defined(PNG_iTXt_SUPPORTED) || \
  161775. defined(PNG_iCCP_SUPPORTED) || defined(PNG_sPLT_SUPPORTED)
  161776. PNG_EXTERN png_charp png_decompress_chunk PNGARG((png_structp png_ptr,
  161777. int comp_type, png_charp chunkdata, png_size_t chunklength,
  161778. png_size_t prefix_length, png_size_t *data_length));
  161779. #endif
  161780. PNG_EXTERN int png_crc_finish PNGARG((png_structp png_ptr, png_uint_32 skip));
  161781. PNG_EXTERN int png_crc_error PNGARG((png_structp png_ptr));
  161782. PNG_EXTERN void png_calculate_crc PNGARG((png_structp png_ptr, png_bytep ptr,
  161783. png_size_t length));
  161784. #if defined(PNG_WRITE_FLUSH_SUPPORTED)
  161785. PNG_EXTERN void png_flush PNGARG((png_structp png_ptr));
  161786. #endif
  161787. PNG_EXTERN void png_write_sig PNGARG((png_structp png_ptr));
  161788. PNG_EXTERN void png_write_IHDR PNGARG((png_structp png_ptr, png_uint_32 width,
  161789. png_uint_32 height,
  161790. int bit_depth, int color_type, int compression_method, int filter_method,
  161791. int interlace_method));
  161792. PNG_EXTERN void png_write_PLTE PNGARG((png_structp png_ptr, png_colorp palette,
  161793. png_uint_32 num_pal));
  161794. PNG_EXTERN void png_write_IDAT PNGARG((png_structp png_ptr, png_bytep data,
  161795. png_size_t length));
  161796. PNG_EXTERN void png_write_IEND PNGARG((png_structp png_ptr));
  161797. #if defined(PNG_WRITE_gAMA_SUPPORTED)
  161798. #ifdef PNG_FLOATING_POINT_SUPPORTED
  161799. PNG_EXTERN void png_write_gAMA PNGARG((png_structp png_ptr, double file_gamma));
  161800. #endif
  161801. #ifdef PNG_FIXED_POINT_SUPPORTED
  161802. PNG_EXTERN void png_write_gAMA_fixed PNGARG((png_structp png_ptr, png_fixed_point
  161803. file_gamma));
  161804. #endif
  161805. #endif
  161806. #if defined(PNG_WRITE_sBIT_SUPPORTED)
  161807. PNG_EXTERN void png_write_sBIT PNGARG((png_structp png_ptr, png_color_8p sbit,
  161808. int color_type));
  161809. #endif
  161810. #if defined(PNG_WRITE_cHRM_SUPPORTED)
  161811. #ifdef PNG_FLOATING_POINT_SUPPORTED
  161812. PNG_EXTERN void png_write_cHRM PNGARG((png_structp png_ptr,
  161813. double white_x, double white_y,
  161814. double red_x, double red_y, double green_x, double green_y,
  161815. double blue_x, double blue_y));
  161816. #endif
  161817. #ifdef PNG_FIXED_POINT_SUPPORTED
  161818. PNG_EXTERN void png_write_cHRM_fixed PNGARG((png_structp png_ptr,
  161819. png_fixed_point int_white_x, png_fixed_point int_white_y,
  161820. png_fixed_point int_red_x, png_fixed_point int_red_y, png_fixed_point
  161821. int_green_x, png_fixed_point int_green_y, png_fixed_point int_blue_x,
  161822. png_fixed_point int_blue_y));
  161823. #endif
  161824. #endif
  161825. #if defined(PNG_WRITE_sRGB_SUPPORTED)
  161826. PNG_EXTERN void png_write_sRGB PNGARG((png_structp png_ptr,
  161827. int intent));
  161828. #endif
  161829. #if defined(PNG_WRITE_iCCP_SUPPORTED)
  161830. PNG_EXTERN void png_write_iCCP PNGARG((png_structp png_ptr,
  161831. png_charp name, int compression_type,
  161832. png_charp profile, int proflen));
  161833. #endif
  161834. #if defined(PNG_WRITE_sPLT_SUPPORTED)
  161835. PNG_EXTERN void png_write_sPLT PNGARG((png_structp png_ptr,
  161836. png_sPLT_tp palette));
  161837. #endif
  161838. #if defined(PNG_WRITE_tRNS_SUPPORTED)
  161839. PNG_EXTERN void png_write_tRNS PNGARG((png_structp png_ptr, png_bytep trans,
  161840. png_color_16p values, int number, int color_type));
  161841. #endif
  161842. #if defined(PNG_WRITE_bKGD_SUPPORTED)
  161843. PNG_EXTERN void png_write_bKGD PNGARG((png_structp png_ptr,
  161844. png_color_16p values, int color_type));
  161845. #endif
  161846. #if defined(PNG_WRITE_hIST_SUPPORTED)
  161847. PNG_EXTERN void png_write_hIST PNGARG((png_structp png_ptr, png_uint_16p hist,
  161848. int num_hist));
  161849. #endif
  161850. #if defined(PNG_WRITE_TEXT_SUPPORTED) || defined(PNG_WRITE_pCAL_SUPPORTED) || \
  161851. defined(PNG_WRITE_iCCP_SUPPORTED) || defined(PNG_WRITE_sPLT_SUPPORTED)
  161852. PNG_EXTERN png_size_t png_check_keyword PNGARG((png_structp png_ptr,
  161853. png_charp key, png_charpp new_key));
  161854. #endif
  161855. #if defined(PNG_WRITE_tEXt_SUPPORTED)
  161856. PNG_EXTERN void png_write_tEXt PNGARG((png_structp png_ptr, png_charp key,
  161857. png_charp text, png_size_t text_len));
  161858. #endif
  161859. #if defined(PNG_WRITE_zTXt_SUPPORTED)
  161860. PNG_EXTERN void png_write_zTXt PNGARG((png_structp png_ptr, png_charp key,
  161861. png_charp text, png_size_t text_len, int compression));
  161862. #endif
  161863. #if defined(PNG_WRITE_iTXt_SUPPORTED)
  161864. PNG_EXTERN void png_write_iTXt PNGARG((png_structp png_ptr,
  161865. int compression, png_charp key, png_charp lang, png_charp lang_key,
  161866. png_charp text));
  161867. #endif
  161868. #if defined(PNG_TEXT_SUPPORTED) /* Added at version 1.0.14 and 1.2.4 */
  161869. PNG_EXTERN int png_set_text_2 PNGARG((png_structp png_ptr,
  161870. png_infop info_ptr, png_textp text_ptr, int num_text));
  161871. #endif
  161872. #if defined(PNG_WRITE_oFFs_SUPPORTED)
  161873. PNG_EXTERN void png_write_oFFs PNGARG((png_structp png_ptr,
  161874. png_int_32 x_offset, png_int_32 y_offset, int unit_type));
  161875. #endif
  161876. #if defined(PNG_WRITE_pCAL_SUPPORTED)
  161877. PNG_EXTERN void png_write_pCAL PNGARG((png_structp png_ptr, png_charp purpose,
  161878. png_int_32 X0, png_int_32 X1, int type, int nparams,
  161879. png_charp units, png_charpp params));
  161880. #endif
  161881. #if defined(PNG_WRITE_pHYs_SUPPORTED)
  161882. PNG_EXTERN void png_write_pHYs PNGARG((png_structp png_ptr,
  161883. png_uint_32 x_pixels_per_unit, png_uint_32 y_pixels_per_unit,
  161884. int unit_type));
  161885. #endif
  161886. #if defined(PNG_WRITE_tIME_SUPPORTED)
  161887. PNG_EXTERN void png_write_tIME PNGARG((png_structp png_ptr,
  161888. png_timep mod_time));
  161889. #endif
  161890. #if defined(PNG_WRITE_sCAL_SUPPORTED)
  161891. #if defined(PNG_FLOATING_POINT_SUPPORTED) && !defined(PNG_NO_STDIO)
  161892. PNG_EXTERN void png_write_sCAL PNGARG((png_structp png_ptr,
  161893. int unit, double width, double height));
  161894. #else
  161895. #ifdef PNG_FIXED_POINT_SUPPORTED
  161896. PNG_EXTERN void png_write_sCAL_s PNGARG((png_structp png_ptr,
  161897. int unit, png_charp width, png_charp height));
  161898. #endif
  161899. #endif
  161900. #endif
  161901. PNG_EXTERN void png_write_finish_row PNGARG((png_structp png_ptr));
  161902. PNG_EXTERN void png_write_start_row PNGARG((png_structp png_ptr));
  161903. #if defined(PNG_READ_GAMMA_SUPPORTED)
  161904. PNG_EXTERN void png_build_gamma_table PNGARG((png_structp png_ptr));
  161905. #endif
  161906. PNG_EXTERN void png_combine_row PNGARG((png_structp png_ptr, png_bytep row,
  161907. int mask));
  161908. #if defined(PNG_READ_INTERLACING_SUPPORTED)
  161909. PNG_EXTERN void png_do_read_interlace PNGARG((png_structp png_ptr));
  161910. #endif
  161911. #if defined(PNG_WRITE_INTERLACING_SUPPORTED)
  161912. PNG_EXTERN void png_do_write_interlace PNGARG((png_row_infop row_info,
  161913. png_bytep row, int pass));
  161914. #endif
  161915. PNG_EXTERN void png_read_filter_row PNGARG((png_structp png_ptr,
  161916. png_row_infop row_info, png_bytep row, png_bytep prev_row, int filter));
  161917. PNG_EXTERN void png_write_find_filter PNGARG((png_structp png_ptr,
  161918. png_row_infop row_info));
  161919. PNG_EXTERN void png_write_filtered_row PNGARG((png_structp png_ptr,
  161920. png_bytep filtered_row));
  161921. PNG_EXTERN void png_read_finish_row PNGARG((png_structp png_ptr));
  161922. PNG_EXTERN void png_read_start_row PNGARG((png_structp png_ptr));
  161923. PNG_EXTERN void png_read_transform_info PNGARG((png_structp png_ptr,
  161924. png_infop info_ptr));
  161925. #if defined(PNG_READ_FILLER_SUPPORTED)
  161926. PNG_EXTERN void png_do_read_filler PNGARG((png_row_infop row_info,
  161927. png_bytep row, png_uint_32 filler, png_uint_32 flags));
  161928. #endif
  161929. #if defined(PNG_READ_SWAP_ALPHA_SUPPORTED)
  161930. PNG_EXTERN void png_do_read_swap_alpha PNGARG((png_row_infop row_info,
  161931. png_bytep row));
  161932. #endif
  161933. #if defined(PNG_WRITE_SWAP_ALPHA_SUPPORTED)
  161934. PNG_EXTERN void png_do_write_swap_alpha PNGARG((png_row_infop row_info,
  161935. png_bytep row));
  161936. #endif
  161937. #if defined(PNG_READ_INVERT_ALPHA_SUPPORTED)
  161938. PNG_EXTERN void png_do_read_invert_alpha PNGARG((png_row_infop row_info,
  161939. png_bytep row));
  161940. #endif
  161941. #if defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED)
  161942. PNG_EXTERN void png_do_write_invert_alpha PNGARG((png_row_infop row_info,
  161943. png_bytep row));
  161944. #endif
  161945. #if defined(PNG_WRITE_FILLER_SUPPORTED) || \
  161946. defined(PNG_READ_STRIP_ALPHA_SUPPORTED)
  161947. PNG_EXTERN void png_do_strip_filler PNGARG((png_row_infop row_info,
  161948. png_bytep row, png_uint_32 flags));
  161949. #endif
  161950. #if defined(PNG_READ_SWAP_SUPPORTED) || defined(PNG_WRITE_SWAP_SUPPORTED)
  161951. PNG_EXTERN void png_do_swap PNGARG((png_row_infop row_info, png_bytep row));
  161952. #endif
  161953. #if defined(PNG_READ_PACKSWAP_SUPPORTED) || defined(PNG_WRITE_PACKSWAP_SUPPORTED)
  161954. PNG_EXTERN void png_do_packswap PNGARG((png_row_infop row_info, png_bytep row));
  161955. #endif
  161956. #if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
  161957. PNG_EXTERN int png_do_rgb_to_gray PNGARG((png_structp png_ptr, png_row_infop
  161958. row_info, png_bytep row));
  161959. #endif
  161960. #if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
  161961. PNG_EXTERN void png_do_gray_to_rgb PNGARG((png_row_infop row_info,
  161962. png_bytep row));
  161963. #endif
  161964. #if defined(PNG_READ_PACK_SUPPORTED)
  161965. PNG_EXTERN void png_do_unpack PNGARG((png_row_infop row_info, png_bytep row));
  161966. #endif
  161967. #if defined(PNG_READ_SHIFT_SUPPORTED)
  161968. PNG_EXTERN void png_do_unshift PNGARG((png_row_infop row_info, png_bytep row,
  161969. png_color_8p sig_bits));
  161970. #endif
  161971. #if defined(PNG_READ_INVERT_SUPPORTED) || defined(PNG_WRITE_INVERT_SUPPORTED)
  161972. PNG_EXTERN void png_do_invert PNGARG((png_row_infop row_info, png_bytep row));
  161973. #endif
  161974. #if defined(PNG_READ_16_TO_8_SUPPORTED)
  161975. PNG_EXTERN void png_do_chop PNGARG((png_row_infop row_info, png_bytep row));
  161976. #endif
  161977. #if defined(PNG_READ_DITHER_SUPPORTED)
  161978. PNG_EXTERN void png_do_dither PNGARG((png_row_infop row_info,
  161979. png_bytep row, png_bytep palette_lookup, png_bytep dither_lookup));
  161980. # if defined(PNG_CORRECT_PALETTE_SUPPORTED)
  161981. PNG_EXTERN void png_correct_palette PNGARG((png_structp png_ptr,
  161982. png_colorp palette, int num_palette));
  161983. # endif
  161984. #endif
  161985. #if defined(PNG_READ_BGR_SUPPORTED) || defined(PNG_WRITE_BGR_SUPPORTED)
  161986. PNG_EXTERN void png_do_bgr PNGARG((png_row_infop row_info, png_bytep row));
  161987. #endif
  161988. #if defined(PNG_WRITE_PACK_SUPPORTED)
  161989. PNG_EXTERN void png_do_pack PNGARG((png_row_infop row_info,
  161990. png_bytep row, png_uint_32 bit_depth));
  161991. #endif
  161992. #if defined(PNG_WRITE_SHIFT_SUPPORTED)
  161993. PNG_EXTERN void png_do_shift PNGARG((png_row_infop row_info, png_bytep row,
  161994. png_color_8p bit_depth));
  161995. #endif
  161996. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  161997. #if defined(PNG_READ_GAMMA_SUPPORTED)
  161998. PNG_EXTERN void png_do_background PNGARG((png_row_infop row_info, png_bytep row,
  161999. png_color_16p trans_values, png_color_16p background,
  162000. png_color_16p background_1,
  162001. png_bytep gamma_table, png_bytep gamma_from_1, png_bytep gamma_to_1,
  162002. png_uint_16pp gamma_16, png_uint_16pp gamma_16_from_1,
  162003. png_uint_16pp gamma_16_to_1, int gamma_shift));
  162004. #else
  162005. PNG_EXTERN void png_do_background PNGARG((png_row_infop row_info, png_bytep row,
  162006. png_color_16p trans_values, png_color_16p background));
  162007. #endif
  162008. #endif
  162009. #if defined(PNG_READ_GAMMA_SUPPORTED)
  162010. PNG_EXTERN void png_do_gamma PNGARG((png_row_infop row_info, png_bytep row,
  162011. png_bytep gamma_table, png_uint_16pp gamma_16_table,
  162012. int gamma_shift));
  162013. #endif
  162014. #if defined(PNG_READ_EXPAND_SUPPORTED)
  162015. PNG_EXTERN void png_do_expand_palette PNGARG((png_row_infop row_info,
  162016. png_bytep row, png_colorp palette, png_bytep trans, int num_trans));
  162017. PNG_EXTERN void png_do_expand PNGARG((png_row_infop row_info,
  162018. png_bytep row, png_color_16p trans_value));
  162019. #endif
  162020. PNG_EXTERN void png_handle_IHDR PNGARG((png_structp png_ptr, png_infop info_ptr,
  162021. png_uint_32 length));
  162022. PNG_EXTERN void png_handle_PLTE PNGARG((png_structp png_ptr, png_infop info_ptr,
  162023. png_uint_32 length));
  162024. PNG_EXTERN void png_handle_IEND PNGARG((png_structp png_ptr, png_infop info_ptr,
  162025. png_uint_32 length));
  162026. #if defined(PNG_READ_bKGD_SUPPORTED)
  162027. PNG_EXTERN void png_handle_bKGD PNGARG((png_structp png_ptr, png_infop info_ptr,
  162028. png_uint_32 length));
  162029. #endif
  162030. #if defined(PNG_READ_cHRM_SUPPORTED)
  162031. PNG_EXTERN void png_handle_cHRM PNGARG((png_structp png_ptr, png_infop info_ptr,
  162032. png_uint_32 length));
  162033. #endif
  162034. #if defined(PNG_READ_gAMA_SUPPORTED)
  162035. PNG_EXTERN void png_handle_gAMA PNGARG((png_structp png_ptr, png_infop info_ptr,
  162036. png_uint_32 length));
  162037. #endif
  162038. #if defined(PNG_READ_hIST_SUPPORTED)
  162039. PNG_EXTERN void png_handle_hIST PNGARG((png_structp png_ptr, png_infop info_ptr,
  162040. png_uint_32 length));
  162041. #endif
  162042. #if defined(PNG_READ_iCCP_SUPPORTED)
  162043. extern void png_handle_iCCP PNGARG((png_structp png_ptr, png_infop info_ptr,
  162044. png_uint_32 length));
  162045. #endif /* PNG_READ_iCCP_SUPPORTED */
  162046. #if defined(PNG_READ_iTXt_SUPPORTED)
  162047. PNG_EXTERN void png_handle_iTXt PNGARG((png_structp png_ptr, png_infop info_ptr,
  162048. png_uint_32 length));
  162049. #endif
  162050. #if defined(PNG_READ_oFFs_SUPPORTED)
  162051. PNG_EXTERN void png_handle_oFFs PNGARG((png_structp png_ptr, png_infop info_ptr,
  162052. png_uint_32 length));
  162053. #endif
  162054. #if defined(PNG_READ_pCAL_SUPPORTED)
  162055. PNG_EXTERN void png_handle_pCAL PNGARG((png_structp png_ptr, png_infop info_ptr,
  162056. png_uint_32 length));
  162057. #endif
  162058. #if defined(PNG_READ_pHYs_SUPPORTED)
  162059. PNG_EXTERN void png_handle_pHYs PNGARG((png_structp png_ptr, png_infop info_ptr,
  162060. png_uint_32 length));
  162061. #endif
  162062. #if defined(PNG_READ_sBIT_SUPPORTED)
  162063. PNG_EXTERN void png_handle_sBIT PNGARG((png_structp png_ptr, png_infop info_ptr,
  162064. png_uint_32 length));
  162065. #endif
  162066. #if defined(PNG_READ_sCAL_SUPPORTED)
  162067. PNG_EXTERN void png_handle_sCAL PNGARG((png_structp png_ptr, png_infop info_ptr,
  162068. png_uint_32 length));
  162069. #endif
  162070. #if defined(PNG_READ_sPLT_SUPPORTED)
  162071. extern void png_handle_sPLT PNGARG((png_structp png_ptr, png_infop info_ptr,
  162072. png_uint_32 length));
  162073. #endif /* PNG_READ_sPLT_SUPPORTED */
  162074. #if defined(PNG_READ_sRGB_SUPPORTED)
  162075. PNG_EXTERN void png_handle_sRGB PNGARG((png_structp png_ptr, png_infop info_ptr,
  162076. png_uint_32 length));
  162077. #endif
  162078. #if defined(PNG_READ_tEXt_SUPPORTED)
  162079. PNG_EXTERN void png_handle_tEXt PNGARG((png_structp png_ptr, png_infop info_ptr,
  162080. png_uint_32 length));
  162081. #endif
  162082. #if defined(PNG_READ_tIME_SUPPORTED)
  162083. PNG_EXTERN void png_handle_tIME PNGARG((png_structp png_ptr, png_infop info_ptr,
  162084. png_uint_32 length));
  162085. #endif
  162086. #if defined(PNG_READ_tRNS_SUPPORTED)
  162087. PNG_EXTERN void png_handle_tRNS PNGARG((png_structp png_ptr, png_infop info_ptr,
  162088. png_uint_32 length));
  162089. #endif
  162090. #if defined(PNG_READ_zTXt_SUPPORTED)
  162091. PNG_EXTERN void png_handle_zTXt PNGARG((png_structp png_ptr, png_infop info_ptr,
  162092. png_uint_32 length));
  162093. #endif
  162094. PNG_EXTERN void png_handle_unknown PNGARG((png_structp png_ptr,
  162095. png_infop info_ptr, png_uint_32 length));
  162096. PNG_EXTERN void png_check_chunk_name PNGARG((png_structp png_ptr,
  162097. png_bytep chunk_name));
  162098. PNG_EXTERN void png_do_read_transformations PNGARG((png_structp png_ptr));
  162099. PNG_EXTERN void png_do_write_transformations PNGARG((png_structp png_ptr));
  162100. PNG_EXTERN void png_init_read_transformations PNGARG((png_structp png_ptr));
  162101. #ifdef PNG_PROGRESSIVE_READ_SUPPORTED
  162102. PNG_EXTERN void png_push_read_chunk PNGARG((png_structp png_ptr,
  162103. png_infop info_ptr));
  162104. PNG_EXTERN void png_push_read_sig PNGARG((png_structp png_ptr,
  162105. png_infop info_ptr));
  162106. PNG_EXTERN void png_push_check_crc PNGARG((png_structp png_ptr));
  162107. PNG_EXTERN void png_push_crc_skip PNGARG((png_structp png_ptr,
  162108. png_uint_32 length));
  162109. PNG_EXTERN void png_push_crc_finish PNGARG((png_structp png_ptr));
  162110. PNG_EXTERN void png_push_save_buffer PNGARG((png_structp png_ptr));
  162111. PNG_EXTERN void png_push_restore_buffer PNGARG((png_structp png_ptr,
  162112. png_bytep buffer, png_size_t buffer_length));
  162113. PNG_EXTERN void png_push_read_IDAT PNGARG((png_structp png_ptr));
  162114. PNG_EXTERN void png_process_IDAT_data PNGARG((png_structp png_ptr,
  162115. png_bytep buffer, png_size_t buffer_length));
  162116. PNG_EXTERN void png_push_process_row PNGARG((png_structp png_ptr));
  162117. PNG_EXTERN void png_push_handle_unknown PNGARG((png_structp png_ptr,
  162118. png_infop info_ptr, png_uint_32 length));
  162119. PNG_EXTERN void png_push_have_info PNGARG((png_structp png_ptr,
  162120. png_infop info_ptr));
  162121. PNG_EXTERN void png_push_have_end PNGARG((png_structp png_ptr,
  162122. png_infop info_ptr));
  162123. PNG_EXTERN void png_push_have_row PNGARG((png_structp png_ptr, png_bytep row));
  162124. PNG_EXTERN void png_push_read_end PNGARG((png_structp png_ptr,
  162125. png_infop info_ptr));
  162126. PNG_EXTERN void png_process_some_data PNGARG((png_structp png_ptr,
  162127. png_infop info_ptr));
  162128. PNG_EXTERN void png_read_push_finish_row PNGARG((png_structp png_ptr));
  162129. #if defined(PNG_READ_tEXt_SUPPORTED)
  162130. PNG_EXTERN void png_push_handle_tEXt PNGARG((png_structp png_ptr,
  162131. png_infop info_ptr, png_uint_32 length));
  162132. PNG_EXTERN void png_push_read_tEXt PNGARG((png_structp png_ptr,
  162133. png_infop info_ptr));
  162134. #endif
  162135. #if defined(PNG_READ_zTXt_SUPPORTED)
  162136. PNG_EXTERN void png_push_handle_zTXt PNGARG((png_structp png_ptr,
  162137. png_infop info_ptr, png_uint_32 length));
  162138. PNG_EXTERN void png_push_read_zTXt PNGARG((png_structp png_ptr,
  162139. png_infop info_ptr));
  162140. #endif
  162141. #if defined(PNG_READ_iTXt_SUPPORTED)
  162142. PNG_EXTERN void png_push_handle_iTXt PNGARG((png_structp png_ptr,
  162143. png_infop info_ptr, png_uint_32 length));
  162144. PNG_EXTERN void png_push_read_iTXt PNGARG((png_structp png_ptr,
  162145. png_infop info_ptr));
  162146. #endif
  162147. #endif /* PNG_PROGRESSIVE_READ_SUPPORTED */
  162148. #ifdef PNG_MNG_FEATURES_SUPPORTED
  162149. PNG_EXTERN void png_do_read_intrapixel PNGARG((png_row_infop row_info,
  162150. png_bytep row));
  162151. PNG_EXTERN void png_do_write_intrapixel PNGARG((png_row_infop row_info,
  162152. png_bytep row));
  162153. #endif
  162154. #if defined(PNG_ASSEMBLER_CODE_SUPPORTED)
  162155. #if defined(PNG_MMX_CODE_SUPPORTED)
  162156. /* PRIVATE */
  162157. PNG_EXTERN void png_init_mmx_flags PNGARG((png_structp png_ptr));
  162158. #endif
  162159. #endif
  162160. #if defined(PNG_INCH_CONVERSIONS) && defined(PNG_FLOATING_POINT_SUPPORTED)
  162161. PNG_EXTERN png_uint_32 png_get_pixels_per_inch PNGARG((png_structp png_ptr,
  162162. png_infop info_ptr));
  162163. PNG_EXTERN png_uint_32 png_get_x_pixels_per_inch PNGARG((png_structp png_ptr,
  162164. png_infop info_ptr));
  162165. PNG_EXTERN png_uint_32 png_get_y_pixels_per_inch PNGARG((png_structp png_ptr,
  162166. png_infop info_ptr));
  162167. PNG_EXTERN float png_get_x_offset_inches PNGARG((png_structp png_ptr,
  162168. png_infop info_ptr));
  162169. PNG_EXTERN float png_get_y_offset_inches PNGARG((png_structp png_ptr,
  162170. png_infop info_ptr));
  162171. #if defined(PNG_pHYs_SUPPORTED)
  162172. PNG_EXTERN png_uint_32 png_get_pHYs_dpi PNGARG((png_structp png_ptr,
  162173. png_infop info_ptr, png_uint_32 *res_x, png_uint_32 *res_y, int *unit_type));
  162174. #endif /* PNG_pHYs_SUPPORTED */
  162175. #endif /* PNG_INCH_CONVERSIONS && PNG_FLOATING_POINT_SUPPORTED */
  162176. #endif /* PNG_INTERNAL */
  162177. #ifdef __cplusplus
  162178. }
  162179. #endif
  162180. #endif /* PNG_VERSION_INFO_ONLY */
  162181. #endif /* PNG_H */
  162182. /*** End of inlined file: png.h ***/
  162183. #define PNG_NO_EXTERN
  162184. /*** Start of inlined file: png.c ***/
  162185. #define PNG_INTERNAL
  162186. #define PNG_NO_EXTERN
  162187. typedef version_1_2_21 Your_png_h_is_not_version_1_2_21;
  162188. #ifdef PNG_USE_GLOBAL_ARRAYS
  162189. PNG_CONST char png_libpng_ver[18] = PNG_LIBPNG_VER_STRING;
  162190. #ifdef PNG_READ_SUPPORTED
  162191. PNG_CONST png_byte FARDATA png_sig[8] = {137, 80, 78, 71, 13, 10, 26, 10};
  162192. #endif /* PNG_READ_SUPPORTED */
  162193. PNG_IHDR;
  162194. PNG_IDAT;
  162195. PNG_IEND;
  162196. PNG_PLTE;
  162197. PNG_bKGD;
  162198. PNG_cHRM;
  162199. PNG_gAMA;
  162200. PNG_hIST;
  162201. PNG_iCCP;
  162202. PNG_iTXt;
  162203. PNG_oFFs;
  162204. PNG_pCAL;
  162205. PNG_sCAL;
  162206. PNG_pHYs;
  162207. PNG_sBIT;
  162208. PNG_sPLT;
  162209. PNG_sRGB;
  162210. PNG_tEXt;
  162211. PNG_tIME;
  162212. PNG_tRNS;
  162213. PNG_zTXt;
  162214. #ifdef PNG_READ_SUPPORTED
  162215. PNG_CONST int FARDATA png_pass_start[] = {0, 4, 0, 2, 0, 1, 0};
  162216. PNG_CONST int FARDATA png_pass_inc[] = {8, 8, 4, 4, 2, 2, 1};
  162217. PNG_CONST int FARDATA png_pass_ystart[] = {0, 0, 4, 0, 2, 0, 1};
  162218. PNG_CONST int FARDATA png_pass_yinc[] = {8, 8, 8, 4, 4, 2, 2};
  162219. PNG_CONST int FARDATA png_pass_mask[] = {0x80, 0x08, 0x88, 0x22, 0xaa, 0x55, 0xff};
  162220. PNG_CONST int FARDATA png_pass_dsp_mask[]
  162221. = {0xff, 0x0f, 0xff, 0x33, 0xff, 0x55, 0xff};
  162222. #endif /* PNG_READ_SUPPORTED */
  162223. #endif /* PNG_USE_GLOBAL_ARRAYS */
  162224. #ifdef PNG_READ_SUPPORTED
  162225. void PNGAPI
  162226. png_set_sig_bytes(png_structp png_ptr, int num_bytes)
  162227. {
  162228. if(png_ptr == NULL) return;
  162229. png_debug(1, "in png_set_sig_bytes\n");
  162230. if (num_bytes > 8)
  162231. png_error(png_ptr, "Too many bytes for PNG signature.");
  162232. png_ptr->sig_bytes = (png_byte)(num_bytes < 0 ? 0 : num_bytes);
  162233. }
  162234. int PNGAPI
  162235. png_sig_cmp(png_bytep sig, png_size_t start, png_size_t num_to_check)
  162236. {
  162237. png_byte png_signature[8] = {137, 80, 78, 71, 13, 10, 26, 10};
  162238. if (num_to_check > 8)
  162239. num_to_check = 8;
  162240. else if (num_to_check < 1)
  162241. return (-1);
  162242. if (start > 7)
  162243. return (-1);
  162244. if (start + num_to_check > 8)
  162245. num_to_check = 8 - start;
  162246. return ((int)(png_memcmp(&sig[start], &png_signature[start], num_to_check)));
  162247. }
  162248. #if defined(PNG_1_0_X) || defined(PNG_1_2_X)
  162249. int PNGAPI
  162250. png_check_sig(png_bytep sig, int num)
  162251. {
  162252. return ((int)!png_sig_cmp(sig, (png_size_t)0, (png_size_t)num));
  162253. }
  162254. #endif
  162255. #endif /* PNG_READ_SUPPORTED */
  162256. #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
  162257. #ifdef PNG_1_0_X
  162258. voidpf PNGAPI
  162259. #else
  162260. voidpf /* private */
  162261. #endif
  162262. png_zalloc(voidpf png_ptr, uInt items, uInt size)
  162263. {
  162264. png_voidp ptr;
  162265. png_structp p=(png_structp)png_ptr;
  162266. png_uint_32 save_flags=p->flags;
  162267. png_uint_32 num_bytes;
  162268. if(png_ptr == NULL) return (NULL);
  162269. if (items > PNG_UINT_32_MAX/size)
  162270. {
  162271. png_warning (p, "Potential overflow in png_zalloc()");
  162272. return (NULL);
  162273. }
  162274. num_bytes = (png_uint_32)items * size;
  162275. p->flags|=PNG_FLAG_MALLOC_NULL_MEM_OK;
  162276. ptr = (png_voidp)png_malloc((png_structp)png_ptr, num_bytes);
  162277. p->flags=save_flags;
  162278. #if defined(PNG_1_0_X) && !defined(PNG_NO_ZALLOC_ZERO)
  162279. if (ptr == NULL)
  162280. return ((voidpf)ptr);
  162281. if (num_bytes > (png_uint_32)0x8000L)
  162282. {
  162283. png_memset(ptr, 0, (png_size_t)0x8000L);
  162284. png_memset((png_bytep)ptr + (png_size_t)0x8000L, 0,
  162285. (png_size_t)(num_bytes - (png_uint_32)0x8000L));
  162286. }
  162287. else
  162288. {
  162289. png_memset(ptr, 0, (png_size_t)num_bytes);
  162290. }
  162291. #endif
  162292. return ((voidpf)ptr);
  162293. }
  162294. #ifdef PNG_1_0_X
  162295. void PNGAPI
  162296. #else
  162297. void /* private */
  162298. #endif
  162299. png_zfree(voidpf png_ptr, voidpf ptr)
  162300. {
  162301. png_free((png_structp)png_ptr, (png_voidp)ptr);
  162302. }
  162303. void /* PRIVATE */
  162304. png_reset_crc(png_structp png_ptr)
  162305. {
  162306. png_ptr->crc = crc32(0, Z_NULL, 0);
  162307. }
  162308. void /* PRIVATE */
  162309. png_calculate_crc(png_structp png_ptr, png_bytep ptr, png_size_t length)
  162310. {
  162311. int need_crc = 1;
  162312. if (png_ptr->chunk_name[0] & 0x20) /* ancillary */
  162313. {
  162314. if ((png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_MASK) ==
  162315. (PNG_FLAG_CRC_ANCILLARY_USE | PNG_FLAG_CRC_ANCILLARY_NOWARN))
  162316. need_crc = 0;
  162317. }
  162318. else /* critical */
  162319. {
  162320. if (png_ptr->flags & PNG_FLAG_CRC_CRITICAL_IGNORE)
  162321. need_crc = 0;
  162322. }
  162323. if (need_crc)
  162324. png_ptr->crc = crc32(png_ptr->crc, ptr, (uInt)length);
  162325. }
  162326. png_infop PNGAPI
  162327. png_create_info_struct(png_structp png_ptr)
  162328. {
  162329. png_infop info_ptr;
  162330. png_debug(1, "in png_create_info_struct\n");
  162331. if(png_ptr == NULL) return (NULL);
  162332. #ifdef PNG_USER_MEM_SUPPORTED
  162333. info_ptr = (png_infop)png_create_struct_2(PNG_STRUCT_INFO,
  162334. png_ptr->malloc_fn, png_ptr->mem_ptr);
  162335. #else
  162336. info_ptr = (png_infop)png_create_struct(PNG_STRUCT_INFO);
  162337. #endif
  162338. if (info_ptr != NULL)
  162339. png_info_init_3(&info_ptr, png_sizeof(png_info));
  162340. return (info_ptr);
  162341. }
  162342. void PNGAPI
  162343. png_destroy_info_struct(png_structp png_ptr, png_infopp info_ptr_ptr)
  162344. {
  162345. png_infop info_ptr = NULL;
  162346. if(png_ptr == NULL) return;
  162347. png_debug(1, "in png_destroy_info_struct\n");
  162348. if (info_ptr_ptr != NULL)
  162349. info_ptr = *info_ptr_ptr;
  162350. if (info_ptr != NULL)
  162351. {
  162352. png_info_destroy(png_ptr, info_ptr);
  162353. #ifdef PNG_USER_MEM_SUPPORTED
  162354. png_destroy_struct_2((png_voidp)info_ptr, png_ptr->free_fn,
  162355. png_ptr->mem_ptr);
  162356. #else
  162357. png_destroy_struct((png_voidp)info_ptr);
  162358. #endif
  162359. *info_ptr_ptr = NULL;
  162360. }
  162361. }
  162362. #if defined(PNG_1_0_X) || defined(PNG_1_2_X)
  162363. #undef png_info_init
  162364. void PNGAPI
  162365. png_info_init(png_infop info_ptr)
  162366. {
  162367. png_info_init_3(&info_ptr, 0);
  162368. }
  162369. #endif
  162370. void PNGAPI
  162371. png_info_init_3(png_infopp ptr_ptr, png_size_t png_info_struct_size)
  162372. {
  162373. png_infop info_ptr = *ptr_ptr;
  162374. if(info_ptr == NULL) return;
  162375. png_debug(1, "in png_info_init_3\n");
  162376. if(png_sizeof(png_info) > png_info_struct_size)
  162377. {
  162378. png_destroy_struct(info_ptr);
  162379. info_ptr = (png_infop)png_create_struct(PNG_STRUCT_INFO);
  162380. *ptr_ptr = info_ptr;
  162381. }
  162382. png_memset(info_ptr, 0, png_sizeof (png_info));
  162383. }
  162384. #ifdef PNG_FREE_ME_SUPPORTED
  162385. void PNGAPI
  162386. png_data_freer(png_structp png_ptr, png_infop info_ptr,
  162387. int freer, png_uint_32 mask)
  162388. {
  162389. png_debug(1, "in png_data_freer\n");
  162390. if (png_ptr == NULL || info_ptr == NULL)
  162391. return;
  162392. if(freer == PNG_DESTROY_WILL_FREE_DATA)
  162393. info_ptr->free_me |= mask;
  162394. else if(freer == PNG_USER_WILL_FREE_DATA)
  162395. info_ptr->free_me &= ~mask;
  162396. else
  162397. png_warning(png_ptr,
  162398. "Unknown freer parameter in png_data_freer.");
  162399. }
  162400. #endif
  162401. void PNGAPI
  162402. png_free_data(png_structp png_ptr, png_infop info_ptr, png_uint_32 mask,
  162403. int num)
  162404. {
  162405. png_debug(1, "in png_free_data\n");
  162406. if (png_ptr == NULL || info_ptr == NULL)
  162407. return;
  162408. #if defined(PNG_TEXT_SUPPORTED)
  162409. #ifdef PNG_FREE_ME_SUPPORTED
  162410. if ((mask & PNG_FREE_TEXT) & info_ptr->free_me)
  162411. #else
  162412. if (mask & PNG_FREE_TEXT)
  162413. #endif
  162414. {
  162415. if (num != -1)
  162416. {
  162417. if (info_ptr->text && info_ptr->text[num].key)
  162418. {
  162419. png_free(png_ptr, info_ptr->text[num].key);
  162420. info_ptr->text[num].key = NULL;
  162421. }
  162422. }
  162423. else
  162424. {
  162425. int i;
  162426. for (i = 0; i < info_ptr->num_text; i++)
  162427. png_free_data(png_ptr, info_ptr, PNG_FREE_TEXT, i);
  162428. png_free(png_ptr, info_ptr->text);
  162429. info_ptr->text = NULL;
  162430. info_ptr->num_text=0;
  162431. }
  162432. }
  162433. #endif
  162434. #if defined(PNG_tRNS_SUPPORTED)
  162435. #ifdef PNG_FREE_ME_SUPPORTED
  162436. if ((mask & PNG_FREE_TRNS) & info_ptr->free_me)
  162437. #else
  162438. if ((mask & PNG_FREE_TRNS) && (png_ptr->flags & PNG_FLAG_FREE_TRNS))
  162439. #endif
  162440. {
  162441. png_free(png_ptr, info_ptr->trans);
  162442. info_ptr->valid &= ~PNG_INFO_tRNS;
  162443. #ifndef PNG_FREE_ME_SUPPORTED
  162444. png_ptr->flags &= ~PNG_FLAG_FREE_TRNS;
  162445. #endif
  162446. info_ptr->trans = NULL;
  162447. }
  162448. #endif
  162449. #if defined(PNG_sCAL_SUPPORTED)
  162450. #ifdef PNG_FREE_ME_SUPPORTED
  162451. if ((mask & PNG_FREE_SCAL) & info_ptr->free_me)
  162452. #else
  162453. if (mask & PNG_FREE_SCAL)
  162454. #endif
  162455. {
  162456. #if defined(PNG_FIXED_POINT_SUPPORTED) && !defined(PNG_FLOATING_POINT_SUPPORTED)
  162457. png_free(png_ptr, info_ptr->scal_s_width);
  162458. png_free(png_ptr, info_ptr->scal_s_height);
  162459. info_ptr->scal_s_width = NULL;
  162460. info_ptr->scal_s_height = NULL;
  162461. #endif
  162462. info_ptr->valid &= ~PNG_INFO_sCAL;
  162463. }
  162464. #endif
  162465. #if defined(PNG_pCAL_SUPPORTED)
  162466. #ifdef PNG_FREE_ME_SUPPORTED
  162467. if ((mask & PNG_FREE_PCAL) & info_ptr->free_me)
  162468. #else
  162469. if (mask & PNG_FREE_PCAL)
  162470. #endif
  162471. {
  162472. png_free(png_ptr, info_ptr->pcal_purpose);
  162473. png_free(png_ptr, info_ptr->pcal_units);
  162474. info_ptr->pcal_purpose = NULL;
  162475. info_ptr->pcal_units = NULL;
  162476. if (info_ptr->pcal_params != NULL)
  162477. {
  162478. int i;
  162479. for (i = 0; i < (int)info_ptr->pcal_nparams; i++)
  162480. {
  162481. png_free(png_ptr, info_ptr->pcal_params[i]);
  162482. info_ptr->pcal_params[i]=NULL;
  162483. }
  162484. png_free(png_ptr, info_ptr->pcal_params);
  162485. info_ptr->pcal_params = NULL;
  162486. }
  162487. info_ptr->valid &= ~PNG_INFO_pCAL;
  162488. }
  162489. #endif
  162490. #if defined(PNG_iCCP_SUPPORTED)
  162491. #ifdef PNG_FREE_ME_SUPPORTED
  162492. if ((mask & PNG_FREE_ICCP) & info_ptr->free_me)
  162493. #else
  162494. if (mask & PNG_FREE_ICCP)
  162495. #endif
  162496. {
  162497. png_free(png_ptr, info_ptr->iccp_name);
  162498. png_free(png_ptr, info_ptr->iccp_profile);
  162499. info_ptr->iccp_name = NULL;
  162500. info_ptr->iccp_profile = NULL;
  162501. info_ptr->valid &= ~PNG_INFO_iCCP;
  162502. }
  162503. #endif
  162504. #if defined(PNG_sPLT_SUPPORTED)
  162505. #ifdef PNG_FREE_ME_SUPPORTED
  162506. if ((mask & PNG_FREE_SPLT) & info_ptr->free_me)
  162507. #else
  162508. if (mask & PNG_FREE_SPLT)
  162509. #endif
  162510. {
  162511. if (num != -1)
  162512. {
  162513. if(info_ptr->splt_palettes)
  162514. {
  162515. png_free(png_ptr, info_ptr->splt_palettes[num].name);
  162516. png_free(png_ptr, info_ptr->splt_palettes[num].entries);
  162517. info_ptr->splt_palettes[num].name = NULL;
  162518. info_ptr->splt_palettes[num].entries = NULL;
  162519. }
  162520. }
  162521. else
  162522. {
  162523. if(info_ptr->splt_palettes_num)
  162524. {
  162525. int i;
  162526. for (i = 0; i < (int)info_ptr->splt_palettes_num; i++)
  162527. png_free_data(png_ptr, info_ptr, PNG_FREE_SPLT, i);
  162528. png_free(png_ptr, info_ptr->splt_palettes);
  162529. info_ptr->splt_palettes = NULL;
  162530. info_ptr->splt_palettes_num = 0;
  162531. }
  162532. info_ptr->valid &= ~PNG_INFO_sPLT;
  162533. }
  162534. }
  162535. #endif
  162536. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  162537. if(png_ptr->unknown_chunk.data)
  162538. {
  162539. png_free(png_ptr, png_ptr->unknown_chunk.data);
  162540. png_ptr->unknown_chunk.data = NULL;
  162541. }
  162542. #ifdef PNG_FREE_ME_SUPPORTED
  162543. if ((mask & PNG_FREE_UNKN) & info_ptr->free_me)
  162544. #else
  162545. if (mask & PNG_FREE_UNKN)
  162546. #endif
  162547. {
  162548. if (num != -1)
  162549. {
  162550. if(info_ptr->unknown_chunks)
  162551. {
  162552. png_free(png_ptr, info_ptr->unknown_chunks[num].data);
  162553. info_ptr->unknown_chunks[num].data = NULL;
  162554. }
  162555. }
  162556. else
  162557. {
  162558. int i;
  162559. if(info_ptr->unknown_chunks_num)
  162560. {
  162561. for (i = 0; i < (int)info_ptr->unknown_chunks_num; i++)
  162562. png_free_data(png_ptr, info_ptr, PNG_FREE_UNKN, i);
  162563. png_free(png_ptr, info_ptr->unknown_chunks);
  162564. info_ptr->unknown_chunks = NULL;
  162565. info_ptr->unknown_chunks_num = 0;
  162566. }
  162567. }
  162568. }
  162569. #endif
  162570. #if defined(PNG_hIST_SUPPORTED)
  162571. #ifdef PNG_FREE_ME_SUPPORTED
  162572. if ((mask & PNG_FREE_HIST) & info_ptr->free_me)
  162573. #else
  162574. if ((mask & PNG_FREE_HIST) && (png_ptr->flags & PNG_FLAG_FREE_HIST))
  162575. #endif
  162576. {
  162577. png_free(png_ptr, info_ptr->hist);
  162578. info_ptr->hist = NULL;
  162579. info_ptr->valid &= ~PNG_INFO_hIST;
  162580. #ifndef PNG_FREE_ME_SUPPORTED
  162581. png_ptr->flags &= ~PNG_FLAG_FREE_HIST;
  162582. #endif
  162583. }
  162584. #endif
  162585. #ifdef PNG_FREE_ME_SUPPORTED
  162586. if ((mask & PNG_FREE_PLTE) & info_ptr->free_me)
  162587. #else
  162588. if ((mask & PNG_FREE_PLTE) && (png_ptr->flags & PNG_FLAG_FREE_PLTE))
  162589. #endif
  162590. {
  162591. png_zfree(png_ptr, info_ptr->palette);
  162592. info_ptr->palette = NULL;
  162593. info_ptr->valid &= ~PNG_INFO_PLTE;
  162594. #ifndef PNG_FREE_ME_SUPPORTED
  162595. png_ptr->flags &= ~PNG_FLAG_FREE_PLTE;
  162596. #endif
  162597. info_ptr->num_palette = 0;
  162598. }
  162599. #if defined(PNG_INFO_IMAGE_SUPPORTED)
  162600. #ifdef PNG_FREE_ME_SUPPORTED
  162601. if ((mask & PNG_FREE_ROWS) & info_ptr->free_me)
  162602. #else
  162603. if (mask & PNG_FREE_ROWS)
  162604. #endif
  162605. {
  162606. if(info_ptr->row_pointers)
  162607. {
  162608. int row;
  162609. for (row = 0; row < (int)info_ptr->height; row++)
  162610. {
  162611. png_free(png_ptr, info_ptr->row_pointers[row]);
  162612. info_ptr->row_pointers[row]=NULL;
  162613. }
  162614. png_free(png_ptr, info_ptr->row_pointers);
  162615. info_ptr->row_pointers=NULL;
  162616. }
  162617. info_ptr->valid &= ~PNG_INFO_IDAT;
  162618. }
  162619. #endif
  162620. #ifdef PNG_FREE_ME_SUPPORTED
  162621. if(num == -1)
  162622. info_ptr->free_me &= ~mask;
  162623. else
  162624. info_ptr->free_me &= ~(mask & ~PNG_FREE_MUL);
  162625. #endif
  162626. }
  162627. void /* PRIVATE */
  162628. png_info_destroy(png_structp png_ptr, png_infop info_ptr)
  162629. {
  162630. png_debug(1, "in png_info_destroy\n");
  162631. png_free_data(png_ptr, info_ptr, PNG_FREE_ALL, -1);
  162632. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  162633. if (png_ptr->num_chunk_list)
  162634. {
  162635. png_free(png_ptr, png_ptr->chunk_list);
  162636. png_ptr->chunk_list=NULL;
  162637. png_ptr->num_chunk_list=0;
  162638. }
  162639. #endif
  162640. png_info_init_3(&info_ptr, png_sizeof(png_info));
  162641. }
  162642. #endif /* defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) */
  162643. png_voidp PNGAPI
  162644. png_get_io_ptr(png_structp png_ptr)
  162645. {
  162646. if(png_ptr == NULL) return (NULL);
  162647. return (png_ptr->io_ptr);
  162648. }
  162649. #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
  162650. #if !defined(PNG_NO_STDIO)
  162651. void PNGAPI
  162652. png_init_io(png_structp png_ptr, png_FILE_p fp)
  162653. {
  162654. png_debug(1, "in png_init_io\n");
  162655. if(png_ptr == NULL) return;
  162656. png_ptr->io_ptr = (png_voidp)fp;
  162657. }
  162658. #endif
  162659. #if defined(PNG_TIME_RFC1123_SUPPORTED)
  162660. png_charp PNGAPI
  162661. png_convert_to_rfc1123(png_structp png_ptr, png_timep ptime)
  162662. {
  162663. static PNG_CONST char short_months[12][4] =
  162664. {"Jan", "Feb", "Mar", "Apr", "May", "Jun",
  162665. "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
  162666. if(png_ptr == NULL) return (NULL);
  162667. if (png_ptr->time_buffer == NULL)
  162668. {
  162669. png_ptr->time_buffer = (png_charp)png_malloc(png_ptr, (png_uint_32)(29*
  162670. png_sizeof(char)));
  162671. }
  162672. #if defined(_WIN32_WCE)
  162673. {
  162674. wchar_t time_buf[29];
  162675. wsprintf(time_buf, TEXT("%d %S %d %02d:%02d:%02d +0000"),
  162676. ptime->day % 32, short_months[(ptime->month - 1) % 12],
  162677. ptime->year, ptime->hour % 24, ptime->minute % 60,
  162678. ptime->second % 61);
  162679. WideCharToMultiByte(CP_ACP, 0, time_buf, -1, png_ptr->time_buffer, 29,
  162680. NULL, NULL);
  162681. }
  162682. #else
  162683. #ifdef USE_FAR_KEYWORD
  162684. {
  162685. char near_time_buf[29];
  162686. png_snprintf6(near_time_buf,29,"%d %s %d %02d:%02d:%02d +0000",
  162687. ptime->day % 32, short_months[(ptime->month - 1) % 12],
  162688. ptime->year, ptime->hour % 24, ptime->minute % 60,
  162689. ptime->second % 61);
  162690. png_memcpy(png_ptr->time_buffer, near_time_buf,
  162691. 29*png_sizeof(char));
  162692. }
  162693. #else
  162694. png_snprintf6(png_ptr->time_buffer,29,"%d %s %d %02d:%02d:%02d +0000",
  162695. ptime->day % 32, short_months[(ptime->month - 1) % 12],
  162696. ptime->year, ptime->hour % 24, ptime->minute % 60,
  162697. ptime->second % 61);
  162698. #endif
  162699. #endif /* _WIN32_WCE */
  162700. return ((png_charp)png_ptr->time_buffer);
  162701. }
  162702. #endif /* PNG_TIME_RFC1123_SUPPORTED */
  162703. #endif /* defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) */
  162704. png_charp PNGAPI
  162705. png_get_copyright(png_structp png_ptr)
  162706. {
  162707. png_ptr = png_ptr; /* silence compiler warning about unused png_ptr */
  162708. return ((png_charp) "\n libpng version 1.2.21 - October 4, 2007\n\
  162709. Copyright (c) 1998-2007 Glenn Randers-Pehrson\n\
  162710. Copyright (c) 1996-1997 Andreas Dilger\n\
  162711. Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc.\n");
  162712. }
  162713. png_charp PNGAPI
  162714. png_get_libpng_ver(png_structp png_ptr)
  162715. {
  162716. png_ptr = png_ptr; /* silence compiler warning about unused png_ptr */
  162717. return ((png_charp) PNG_LIBPNG_VER_STRING);
  162718. }
  162719. png_charp PNGAPI
  162720. png_get_header_ver(png_structp png_ptr)
  162721. {
  162722. png_ptr = png_ptr; /* silence compiler warning about unused png_ptr */
  162723. return ((png_charp) PNG_LIBPNG_VER_STRING);
  162724. }
  162725. png_charp PNGAPI
  162726. png_get_header_version(png_structp png_ptr)
  162727. {
  162728. png_ptr = png_ptr; /* silence compiler warning about unused png_ptr */
  162729. return ((png_charp) PNG_HEADER_VERSION_STRING
  162730. #ifndef PNG_READ_SUPPORTED
  162731. " (NO READ SUPPORT)"
  162732. #endif
  162733. "\n");
  162734. }
  162735. #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
  162736. #ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
  162737. int PNGAPI
  162738. png_handle_as_unknown(png_structp png_ptr, png_bytep chunk_name)
  162739. {
  162740. int i;
  162741. png_bytep p;
  162742. if(png_ptr == NULL || chunk_name == NULL || png_ptr->num_chunk_list<=0)
  162743. return 0;
  162744. p=png_ptr->chunk_list+png_ptr->num_chunk_list*5-5;
  162745. for (i = png_ptr->num_chunk_list; i; i--, p-=5)
  162746. if (!png_memcmp(chunk_name, p, 4))
  162747. return ((int)*(p+4));
  162748. return 0;
  162749. }
  162750. #endif
  162751. int PNGAPI
  162752. png_reset_zstream(png_structp png_ptr)
  162753. {
  162754. if (png_ptr == NULL) return Z_STREAM_ERROR;
  162755. return (inflateReset(&png_ptr->zstream));
  162756. }
  162757. #endif /* defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) */
  162758. png_uint_32 PNGAPI
  162759. png_access_version_number(void)
  162760. {
  162761. return((png_uint_32) PNG_LIBPNG_VER);
  162762. }
  162763. #if defined(PNG_READ_SUPPORTED) && defined(PNG_ASSEMBLER_CODE_SUPPORTED)
  162764. #if !defined(PNG_1_0_X)
  162765. int PNGAPI
  162766. png_mmx_support(void)
  162767. {
  162768. return -1;
  162769. }
  162770. #endif /* PNG_1_0_X */
  162771. #endif /* PNG_READ_SUPPORTED && PNG_ASSEMBLER_CODE_SUPPORTED */
  162772. #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
  162773. #ifdef PNG_SIZE_T
  162774. PNG_EXTERN png_size_t PNGAPI png_convert_size PNGARG((size_t size));
  162775. png_size_t PNGAPI
  162776. png_convert_size(size_t size)
  162777. {
  162778. if (size > (png_size_t)-1)
  162779. PNG_ABORT(); /* We haven't got access to png_ptr, so no png_error() */
  162780. return ((png_size_t)size);
  162781. }
  162782. #endif /* PNG_SIZE_T */
  162783. #endif /* defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) */
  162784. /*** End of inlined file: png.c ***/
  162785. /*** Start of inlined file: pngerror.c ***/
  162786. #define PNG_INTERNAL
  162787. #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
  162788. static void /* PRIVATE */
  162789. png_default_error PNGARG((png_structp png_ptr,
  162790. png_const_charp error_message));
  162791. #ifndef PNG_NO_WARNINGS
  162792. static void /* PRIVATE */
  162793. png_default_warning PNGARG((png_structp png_ptr,
  162794. png_const_charp warning_message));
  162795. #endif /* PNG_NO_WARNINGS */
  162796. #ifndef PNG_NO_ERROR_TEXT
  162797. void PNGAPI
  162798. png_error(png_structp png_ptr, png_const_charp error_message)
  162799. {
  162800. #ifdef PNG_ERROR_NUMBERS_SUPPORTED
  162801. char msg[16];
  162802. if (png_ptr != NULL)
  162803. {
  162804. if (png_ptr->flags&
  162805. (PNG_FLAG_STRIP_ERROR_NUMBERS|PNG_FLAG_STRIP_ERROR_TEXT))
  162806. {
  162807. if (*error_message == '#')
  162808. {
  162809. int offset;
  162810. for (offset=1; offset<15; offset++)
  162811. if (*(error_message+offset) == ' ')
  162812. break;
  162813. if (png_ptr->flags&PNG_FLAG_STRIP_ERROR_TEXT)
  162814. {
  162815. int i;
  162816. for (i=0; i<offset-1; i++)
  162817. msg[i]=error_message[i+1];
  162818. msg[i]='\0';
  162819. error_message=msg;
  162820. }
  162821. else
  162822. error_message+=offset;
  162823. }
  162824. else
  162825. {
  162826. if (png_ptr->flags&PNG_FLAG_STRIP_ERROR_TEXT)
  162827. {
  162828. msg[0]='0';
  162829. msg[1]='\0';
  162830. error_message=msg;
  162831. }
  162832. }
  162833. }
  162834. }
  162835. #endif
  162836. if (png_ptr != NULL && png_ptr->error_fn != NULL)
  162837. (*(png_ptr->error_fn))(png_ptr, error_message);
  162838. png_default_error(png_ptr, error_message);
  162839. }
  162840. #else
  162841. void PNGAPI
  162842. png_err(png_structp png_ptr)
  162843. {
  162844. if (png_ptr != NULL && png_ptr->error_fn != NULL)
  162845. (*(png_ptr->error_fn))(png_ptr, '\0');
  162846. png_default_error(png_ptr, '\0');
  162847. }
  162848. #endif /* PNG_NO_ERROR_TEXT */
  162849. #ifndef PNG_NO_WARNINGS
  162850. void PNGAPI
  162851. png_warning(png_structp png_ptr, png_const_charp warning_message)
  162852. {
  162853. int offset = 0;
  162854. if (png_ptr != NULL)
  162855. {
  162856. #ifdef PNG_ERROR_NUMBERS_SUPPORTED
  162857. if (png_ptr->flags&
  162858. (PNG_FLAG_STRIP_ERROR_NUMBERS|PNG_FLAG_STRIP_ERROR_TEXT))
  162859. #endif
  162860. {
  162861. if (*warning_message == '#')
  162862. {
  162863. for (offset=1; offset<15; offset++)
  162864. if (*(warning_message+offset) == ' ')
  162865. break;
  162866. }
  162867. }
  162868. if (png_ptr != NULL && png_ptr->warning_fn != NULL)
  162869. (*(png_ptr->warning_fn))(png_ptr, warning_message+offset);
  162870. }
  162871. else
  162872. png_default_warning(png_ptr, warning_message+offset);
  162873. }
  162874. #endif /* PNG_NO_WARNINGS */
  162875. #define isnonalpha(c) ((c) < 65 || (c) > 122 || ((c) > 90 && (c) < 97))
  162876. #if !defined(PNG_NO_WARNINGS) || !defined(PNG_NO_ERROR_TEXT)
  162877. static void /* PRIVATE */
  162878. png_format_buffer(png_structp png_ptr, png_charp buffer, png_const_charp
  162879. error_message)
  162880. {
  162881. int iout = 0, iin = 0;
  162882. while (iin < 4)
  162883. {
  162884. int c = png_ptr->chunk_name[iin++];
  162885. if (isnonalpha(c))
  162886. {
  162887. buffer[iout++] = '[';
  162888. buffer[iout++] = png_digit[(c & 0xf0) >> 4];
  162889. buffer[iout++] = png_digit[c & 0x0f];
  162890. buffer[iout++] = ']';
  162891. }
  162892. else
  162893. {
  162894. buffer[iout++] = (png_byte)c;
  162895. }
  162896. }
  162897. if (error_message == NULL)
  162898. buffer[iout] = 0;
  162899. else
  162900. {
  162901. buffer[iout++] = ':';
  162902. buffer[iout++] = ' ';
  162903. png_strncpy(buffer+iout, error_message, 63);
  162904. buffer[iout+63] = 0;
  162905. }
  162906. }
  162907. #ifdef PNG_READ_SUPPORTED
  162908. void PNGAPI
  162909. png_chunk_error(png_structp png_ptr, png_const_charp error_message)
  162910. {
  162911. char msg[18+64];
  162912. if (png_ptr == NULL)
  162913. png_error(png_ptr, error_message);
  162914. else
  162915. {
  162916. png_format_buffer(png_ptr, msg, error_message);
  162917. png_error(png_ptr, msg);
  162918. }
  162919. }
  162920. #endif /* PNG_READ_SUPPORTED */
  162921. #endif /* !defined(PNG_NO_WARNINGS) || !defined(PNG_NO_ERROR_TEXT) */
  162922. #ifndef PNG_NO_WARNINGS
  162923. void PNGAPI
  162924. png_chunk_warning(png_structp png_ptr, png_const_charp warning_message)
  162925. {
  162926. char msg[18+64];
  162927. if (png_ptr == NULL)
  162928. png_warning(png_ptr, warning_message);
  162929. else
  162930. {
  162931. png_format_buffer(png_ptr, msg, warning_message);
  162932. png_warning(png_ptr, msg);
  162933. }
  162934. }
  162935. #endif /* PNG_NO_WARNINGS */
  162936. static void /* PRIVATE */
  162937. png_default_error(png_structp png_ptr, png_const_charp error_message)
  162938. {
  162939. #ifndef PNG_NO_CONSOLE_IO
  162940. #ifdef PNG_ERROR_NUMBERS_SUPPORTED
  162941. if (*error_message == '#')
  162942. {
  162943. int offset;
  162944. char error_number[16];
  162945. for (offset=0; offset<15; offset++)
  162946. {
  162947. error_number[offset] = *(error_message+offset+1);
  162948. if (*(error_message+offset) == ' ')
  162949. break;
  162950. }
  162951. if((offset > 1) && (offset < 15))
  162952. {
  162953. error_number[offset-1]='\0';
  162954. fprintf(stderr, "libpng error no. %s: %s\n", error_number,
  162955. error_message+offset);
  162956. }
  162957. else
  162958. fprintf(stderr, "libpng error: %s, offset=%d\n", error_message,offset);
  162959. }
  162960. else
  162961. #endif
  162962. fprintf(stderr, "libpng error: %s\n", error_message);
  162963. #endif
  162964. #ifdef PNG_SETJMP_SUPPORTED
  162965. if (png_ptr)
  162966. {
  162967. # ifdef USE_FAR_KEYWORD
  162968. {
  162969. jmp_buf jmpbuf;
  162970. png_memcpy(jmpbuf, png_ptr->jmpbuf, png_sizeof(jmp_buf));
  162971. longjmp(jmpbuf, 1);
  162972. }
  162973. # else
  162974. longjmp(png_ptr->jmpbuf, 1);
  162975. # endif
  162976. }
  162977. #else
  162978. PNG_ABORT();
  162979. #endif
  162980. #ifdef PNG_NO_CONSOLE_IO
  162981. error_message = error_message; /* make compiler happy */
  162982. #endif
  162983. }
  162984. #ifndef PNG_NO_WARNINGS
  162985. static void /* PRIVATE */
  162986. png_default_warning(png_structp png_ptr, png_const_charp warning_message)
  162987. {
  162988. #ifndef PNG_NO_CONSOLE_IO
  162989. # ifdef PNG_ERROR_NUMBERS_SUPPORTED
  162990. if (*warning_message == '#')
  162991. {
  162992. int offset;
  162993. char warning_number[16];
  162994. for (offset=0; offset<15; offset++)
  162995. {
  162996. warning_number[offset]=*(warning_message+offset+1);
  162997. if (*(warning_message+offset) == ' ')
  162998. break;
  162999. }
  163000. if((offset > 1) && (offset < 15))
  163001. {
  163002. warning_number[offset-1]='\0';
  163003. fprintf(stderr, "libpng warning no. %s: %s\n", warning_number,
  163004. warning_message+offset);
  163005. }
  163006. else
  163007. fprintf(stderr, "libpng warning: %s\n", warning_message);
  163008. }
  163009. else
  163010. # endif
  163011. fprintf(stderr, "libpng warning: %s\n", warning_message);
  163012. #else
  163013. warning_message = warning_message; /* make compiler happy */
  163014. #endif
  163015. png_ptr = png_ptr; /* make compiler happy */
  163016. }
  163017. #endif /* PNG_NO_WARNINGS */
  163018. void PNGAPI
  163019. png_set_error_fn(png_structp png_ptr, png_voidp error_ptr,
  163020. png_error_ptr error_fn, png_error_ptr warning_fn)
  163021. {
  163022. if (png_ptr == NULL)
  163023. return;
  163024. png_ptr->error_ptr = error_ptr;
  163025. png_ptr->error_fn = error_fn;
  163026. png_ptr->warning_fn = warning_fn;
  163027. }
  163028. png_voidp PNGAPI
  163029. png_get_error_ptr(png_structp png_ptr)
  163030. {
  163031. if (png_ptr == NULL)
  163032. return NULL;
  163033. return ((png_voidp)png_ptr->error_ptr);
  163034. }
  163035. #ifdef PNG_ERROR_NUMBERS_SUPPORTED
  163036. void PNGAPI
  163037. png_set_strip_error_numbers(png_structp png_ptr, png_uint_32 strip_mode)
  163038. {
  163039. if(png_ptr != NULL)
  163040. {
  163041. png_ptr->flags &=
  163042. ((~(PNG_FLAG_STRIP_ERROR_NUMBERS|PNG_FLAG_STRIP_ERROR_TEXT))&strip_mode);
  163043. }
  163044. }
  163045. #endif
  163046. #endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */
  163047. /*** End of inlined file: pngerror.c ***/
  163048. /*** Start of inlined file: pngget.c ***/
  163049. #define PNG_INTERNAL
  163050. #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
  163051. png_uint_32 PNGAPI
  163052. png_get_valid(png_structp png_ptr, png_infop info_ptr, png_uint_32 flag)
  163053. {
  163054. if (png_ptr != NULL && info_ptr != NULL)
  163055. return(info_ptr->valid & flag);
  163056. else
  163057. return(0);
  163058. }
  163059. png_uint_32 PNGAPI
  163060. png_get_rowbytes(png_structp png_ptr, png_infop info_ptr)
  163061. {
  163062. if (png_ptr != NULL && info_ptr != NULL)
  163063. return(info_ptr->rowbytes);
  163064. else
  163065. return(0);
  163066. }
  163067. #if defined(PNG_INFO_IMAGE_SUPPORTED)
  163068. png_bytepp PNGAPI
  163069. png_get_rows(png_structp png_ptr, png_infop info_ptr)
  163070. {
  163071. if (png_ptr != NULL && info_ptr != NULL)
  163072. return(info_ptr->row_pointers);
  163073. else
  163074. return(0);
  163075. }
  163076. #endif
  163077. #ifdef PNG_EASY_ACCESS_SUPPORTED
  163078. png_uint_32 PNGAPI
  163079. png_get_image_width(png_structp png_ptr, png_infop info_ptr)
  163080. {
  163081. if (png_ptr != NULL && info_ptr != NULL)
  163082. {
  163083. return info_ptr->width;
  163084. }
  163085. return (0);
  163086. }
  163087. png_uint_32 PNGAPI
  163088. png_get_image_height(png_structp png_ptr, png_infop info_ptr)
  163089. {
  163090. if (png_ptr != NULL && info_ptr != NULL)
  163091. {
  163092. return info_ptr->height;
  163093. }
  163094. return (0);
  163095. }
  163096. png_byte PNGAPI
  163097. png_get_bit_depth(png_structp png_ptr, png_infop info_ptr)
  163098. {
  163099. if (png_ptr != NULL && info_ptr != NULL)
  163100. {
  163101. return info_ptr->bit_depth;
  163102. }
  163103. return (0);
  163104. }
  163105. png_byte PNGAPI
  163106. png_get_color_type(png_structp png_ptr, png_infop info_ptr)
  163107. {
  163108. if (png_ptr != NULL && info_ptr != NULL)
  163109. {
  163110. return info_ptr->color_type;
  163111. }
  163112. return (0);
  163113. }
  163114. png_byte PNGAPI
  163115. png_get_filter_type(png_structp png_ptr, png_infop info_ptr)
  163116. {
  163117. if (png_ptr != NULL && info_ptr != NULL)
  163118. {
  163119. return info_ptr->filter_type;
  163120. }
  163121. return (0);
  163122. }
  163123. png_byte PNGAPI
  163124. png_get_interlace_type(png_structp png_ptr, png_infop info_ptr)
  163125. {
  163126. if (png_ptr != NULL && info_ptr != NULL)
  163127. {
  163128. return info_ptr->interlace_type;
  163129. }
  163130. return (0);
  163131. }
  163132. png_byte PNGAPI
  163133. png_get_compression_type(png_structp png_ptr, png_infop info_ptr)
  163134. {
  163135. if (png_ptr != NULL && info_ptr != NULL)
  163136. {
  163137. return info_ptr->compression_type;
  163138. }
  163139. return (0);
  163140. }
  163141. png_uint_32 PNGAPI
  163142. png_get_x_pixels_per_meter(png_structp png_ptr, png_infop info_ptr)
  163143. {
  163144. if (png_ptr != NULL && info_ptr != NULL)
  163145. #if defined(PNG_pHYs_SUPPORTED)
  163146. if (info_ptr->valid & PNG_INFO_pHYs)
  163147. {
  163148. png_debug1(1, "in %s retrieval function\n", "png_get_x_pixels_per_meter");
  163149. if(info_ptr->phys_unit_type != PNG_RESOLUTION_METER)
  163150. return (0);
  163151. else return (info_ptr->x_pixels_per_unit);
  163152. }
  163153. #else
  163154. return (0);
  163155. #endif
  163156. return (0);
  163157. }
  163158. png_uint_32 PNGAPI
  163159. png_get_y_pixels_per_meter(png_structp png_ptr, png_infop info_ptr)
  163160. {
  163161. if (png_ptr != NULL && info_ptr != NULL)
  163162. #if defined(PNG_pHYs_SUPPORTED)
  163163. if (info_ptr->valid & PNG_INFO_pHYs)
  163164. {
  163165. png_debug1(1, "in %s retrieval function\n", "png_get_y_pixels_per_meter");
  163166. if(info_ptr->phys_unit_type != PNG_RESOLUTION_METER)
  163167. return (0);
  163168. else return (info_ptr->y_pixels_per_unit);
  163169. }
  163170. #else
  163171. return (0);
  163172. #endif
  163173. return (0);
  163174. }
  163175. png_uint_32 PNGAPI
  163176. png_get_pixels_per_meter(png_structp png_ptr, png_infop info_ptr)
  163177. {
  163178. if (png_ptr != NULL && info_ptr != NULL)
  163179. #if defined(PNG_pHYs_SUPPORTED)
  163180. if (info_ptr->valid & PNG_INFO_pHYs)
  163181. {
  163182. png_debug1(1, "in %s retrieval function\n", "png_get_pixels_per_meter");
  163183. if(info_ptr->phys_unit_type != PNG_RESOLUTION_METER ||
  163184. info_ptr->x_pixels_per_unit != info_ptr->y_pixels_per_unit)
  163185. return (0);
  163186. else return (info_ptr->x_pixels_per_unit);
  163187. }
  163188. #else
  163189. return (0);
  163190. #endif
  163191. return (0);
  163192. }
  163193. #ifdef PNG_FLOATING_POINT_SUPPORTED
  163194. float PNGAPI
  163195. png_get_pixel_aspect_ratio(png_structp png_ptr, png_infop info_ptr)
  163196. {
  163197. if (png_ptr != NULL && info_ptr != NULL)
  163198. #if defined(PNG_pHYs_SUPPORTED)
  163199. if (info_ptr->valid & PNG_INFO_pHYs)
  163200. {
  163201. png_debug1(1, "in %s retrieval function\n", "png_get_aspect_ratio");
  163202. if (info_ptr->x_pixels_per_unit == 0)
  163203. return ((float)0.0);
  163204. else
  163205. return ((float)((float)info_ptr->y_pixels_per_unit
  163206. /(float)info_ptr->x_pixels_per_unit));
  163207. }
  163208. #else
  163209. return (0.0);
  163210. #endif
  163211. return ((float)0.0);
  163212. }
  163213. #endif
  163214. png_int_32 PNGAPI
  163215. png_get_x_offset_microns(png_structp png_ptr, png_infop info_ptr)
  163216. {
  163217. if (png_ptr != NULL && info_ptr != NULL)
  163218. #if defined(PNG_oFFs_SUPPORTED)
  163219. if (info_ptr->valid & PNG_INFO_oFFs)
  163220. {
  163221. png_debug1(1, "in %s retrieval function\n", "png_get_x_offset_microns");
  163222. if(info_ptr->offset_unit_type != PNG_OFFSET_MICROMETER)
  163223. return (0);
  163224. else return (info_ptr->x_offset);
  163225. }
  163226. #else
  163227. return (0);
  163228. #endif
  163229. return (0);
  163230. }
  163231. png_int_32 PNGAPI
  163232. png_get_y_offset_microns(png_structp png_ptr, png_infop info_ptr)
  163233. {
  163234. if (png_ptr != NULL && info_ptr != NULL)
  163235. #if defined(PNG_oFFs_SUPPORTED)
  163236. if (info_ptr->valid & PNG_INFO_oFFs)
  163237. {
  163238. png_debug1(1, "in %s retrieval function\n", "png_get_y_offset_microns");
  163239. if(info_ptr->offset_unit_type != PNG_OFFSET_MICROMETER)
  163240. return (0);
  163241. else return (info_ptr->y_offset);
  163242. }
  163243. #else
  163244. return (0);
  163245. #endif
  163246. return (0);
  163247. }
  163248. png_int_32 PNGAPI
  163249. png_get_x_offset_pixels(png_structp png_ptr, png_infop info_ptr)
  163250. {
  163251. if (png_ptr != NULL && info_ptr != NULL)
  163252. #if defined(PNG_oFFs_SUPPORTED)
  163253. if (info_ptr->valid & PNG_INFO_oFFs)
  163254. {
  163255. png_debug1(1, "in %s retrieval function\n", "png_get_x_offset_microns");
  163256. if(info_ptr->offset_unit_type != PNG_OFFSET_PIXEL)
  163257. return (0);
  163258. else return (info_ptr->x_offset);
  163259. }
  163260. #else
  163261. return (0);
  163262. #endif
  163263. return (0);
  163264. }
  163265. png_int_32 PNGAPI
  163266. png_get_y_offset_pixels(png_structp png_ptr, png_infop info_ptr)
  163267. {
  163268. if (png_ptr != NULL && info_ptr != NULL)
  163269. #if defined(PNG_oFFs_SUPPORTED)
  163270. if (info_ptr->valid & PNG_INFO_oFFs)
  163271. {
  163272. png_debug1(1, "in %s retrieval function\n", "png_get_y_offset_microns");
  163273. if(info_ptr->offset_unit_type != PNG_OFFSET_PIXEL)
  163274. return (0);
  163275. else return (info_ptr->y_offset);
  163276. }
  163277. #else
  163278. return (0);
  163279. #endif
  163280. return (0);
  163281. }
  163282. #if defined(PNG_INCH_CONVERSIONS) && defined(PNG_FLOATING_POINT_SUPPORTED)
  163283. png_uint_32 PNGAPI
  163284. png_get_pixels_per_inch(png_structp png_ptr, png_infop info_ptr)
  163285. {
  163286. return ((png_uint_32)((float)png_get_pixels_per_meter(png_ptr, info_ptr)
  163287. *.0254 +.5));
  163288. }
  163289. png_uint_32 PNGAPI
  163290. png_get_x_pixels_per_inch(png_structp png_ptr, png_infop info_ptr)
  163291. {
  163292. return ((png_uint_32)((float)png_get_x_pixels_per_meter(png_ptr, info_ptr)
  163293. *.0254 +.5));
  163294. }
  163295. png_uint_32 PNGAPI
  163296. png_get_y_pixels_per_inch(png_structp png_ptr, png_infop info_ptr)
  163297. {
  163298. return ((png_uint_32)((float)png_get_y_pixels_per_meter(png_ptr, info_ptr)
  163299. *.0254 +.5));
  163300. }
  163301. float PNGAPI
  163302. png_get_x_offset_inches(png_structp png_ptr, png_infop info_ptr)
  163303. {
  163304. return ((float)png_get_x_offset_microns(png_ptr, info_ptr)
  163305. *.00003937);
  163306. }
  163307. float PNGAPI
  163308. png_get_y_offset_inches(png_structp png_ptr, png_infop info_ptr)
  163309. {
  163310. return ((float)png_get_y_offset_microns(png_ptr, info_ptr)
  163311. *.00003937);
  163312. }
  163313. #if defined(PNG_pHYs_SUPPORTED)
  163314. png_uint_32 PNGAPI
  163315. png_get_pHYs_dpi(png_structp png_ptr, png_infop info_ptr,
  163316. png_uint_32 *res_x, png_uint_32 *res_y, int *unit_type)
  163317. {
  163318. png_uint_32 retval = 0;
  163319. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs))
  163320. {
  163321. png_debug1(1, "in %s retrieval function\n", "pHYs");
  163322. if (res_x != NULL)
  163323. {
  163324. *res_x = info_ptr->x_pixels_per_unit;
  163325. retval |= PNG_INFO_pHYs;
  163326. }
  163327. if (res_y != NULL)
  163328. {
  163329. *res_y = info_ptr->y_pixels_per_unit;
  163330. retval |= PNG_INFO_pHYs;
  163331. }
  163332. if (unit_type != NULL)
  163333. {
  163334. *unit_type = (int)info_ptr->phys_unit_type;
  163335. retval |= PNG_INFO_pHYs;
  163336. if(*unit_type == 1)
  163337. {
  163338. if (res_x != NULL) *res_x = (png_uint_32)(*res_x * .0254 + .50);
  163339. if (res_y != NULL) *res_y = (png_uint_32)(*res_y * .0254 + .50);
  163340. }
  163341. }
  163342. }
  163343. return (retval);
  163344. }
  163345. #endif /* PNG_pHYs_SUPPORTED */
  163346. #endif /* PNG_INCH_CONVERSIONS && PNG_FLOATING_POINT_SUPPORTED */
  163347. #endif /* PNG_EASY_ACCESS_SUPPORTED */
  163348. png_byte PNGAPI
  163349. png_get_channels(png_structp png_ptr, png_infop info_ptr)
  163350. {
  163351. if (png_ptr != NULL && info_ptr != NULL)
  163352. return(info_ptr->channels);
  163353. else
  163354. return (0);
  163355. }
  163356. png_bytep PNGAPI
  163357. png_get_signature(png_structp png_ptr, png_infop info_ptr)
  163358. {
  163359. if (png_ptr != NULL && info_ptr != NULL)
  163360. return(info_ptr->signature);
  163361. else
  163362. return (NULL);
  163363. }
  163364. #if defined(PNG_bKGD_SUPPORTED)
  163365. png_uint_32 PNGAPI
  163366. png_get_bKGD(png_structp png_ptr, png_infop info_ptr,
  163367. png_color_16p *background)
  163368. {
  163369. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_bKGD)
  163370. && background != NULL)
  163371. {
  163372. png_debug1(1, "in %s retrieval function\n", "bKGD");
  163373. *background = &(info_ptr->background);
  163374. return (PNG_INFO_bKGD);
  163375. }
  163376. return (0);
  163377. }
  163378. #endif
  163379. #if defined(PNG_cHRM_SUPPORTED)
  163380. #ifdef PNG_FLOATING_POINT_SUPPORTED
  163381. png_uint_32 PNGAPI
  163382. png_get_cHRM(png_structp png_ptr, png_infop info_ptr,
  163383. double *white_x, double *white_y, double *red_x, double *red_y,
  163384. double *green_x, double *green_y, double *blue_x, double *blue_y)
  163385. {
  163386. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_cHRM))
  163387. {
  163388. png_debug1(1, "in %s retrieval function\n", "cHRM");
  163389. if (white_x != NULL)
  163390. *white_x = (double)info_ptr->x_white;
  163391. if (white_y != NULL)
  163392. *white_y = (double)info_ptr->y_white;
  163393. if (red_x != NULL)
  163394. *red_x = (double)info_ptr->x_red;
  163395. if (red_y != NULL)
  163396. *red_y = (double)info_ptr->y_red;
  163397. if (green_x != NULL)
  163398. *green_x = (double)info_ptr->x_green;
  163399. if (green_y != NULL)
  163400. *green_y = (double)info_ptr->y_green;
  163401. if (blue_x != NULL)
  163402. *blue_x = (double)info_ptr->x_blue;
  163403. if (blue_y != NULL)
  163404. *blue_y = (double)info_ptr->y_blue;
  163405. return (PNG_INFO_cHRM);
  163406. }
  163407. return (0);
  163408. }
  163409. #endif
  163410. #ifdef PNG_FIXED_POINT_SUPPORTED
  163411. png_uint_32 PNGAPI
  163412. png_get_cHRM_fixed(png_structp png_ptr, png_infop info_ptr,
  163413. png_fixed_point *white_x, png_fixed_point *white_y, png_fixed_point *red_x,
  163414. png_fixed_point *red_y, png_fixed_point *green_x, png_fixed_point *green_y,
  163415. png_fixed_point *blue_x, png_fixed_point *blue_y)
  163416. {
  163417. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_cHRM))
  163418. {
  163419. png_debug1(1, "in %s retrieval function\n", "cHRM");
  163420. if (white_x != NULL)
  163421. *white_x = info_ptr->int_x_white;
  163422. if (white_y != NULL)
  163423. *white_y = info_ptr->int_y_white;
  163424. if (red_x != NULL)
  163425. *red_x = info_ptr->int_x_red;
  163426. if (red_y != NULL)
  163427. *red_y = info_ptr->int_y_red;
  163428. if (green_x != NULL)
  163429. *green_x = info_ptr->int_x_green;
  163430. if (green_y != NULL)
  163431. *green_y = info_ptr->int_y_green;
  163432. if (blue_x != NULL)
  163433. *blue_x = info_ptr->int_x_blue;
  163434. if (blue_y != NULL)
  163435. *blue_y = info_ptr->int_y_blue;
  163436. return (PNG_INFO_cHRM);
  163437. }
  163438. return (0);
  163439. }
  163440. #endif
  163441. #endif
  163442. #if defined(PNG_gAMA_SUPPORTED)
  163443. #ifdef PNG_FLOATING_POINT_SUPPORTED
  163444. png_uint_32 PNGAPI
  163445. png_get_gAMA(png_structp png_ptr, png_infop info_ptr, double *file_gamma)
  163446. {
  163447. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_gAMA)
  163448. && file_gamma != NULL)
  163449. {
  163450. png_debug1(1, "in %s retrieval function\n", "gAMA");
  163451. *file_gamma = (double)info_ptr->gamma;
  163452. return (PNG_INFO_gAMA);
  163453. }
  163454. return (0);
  163455. }
  163456. #endif
  163457. #ifdef PNG_FIXED_POINT_SUPPORTED
  163458. png_uint_32 PNGAPI
  163459. png_get_gAMA_fixed(png_structp png_ptr, png_infop info_ptr,
  163460. png_fixed_point *int_file_gamma)
  163461. {
  163462. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_gAMA)
  163463. && int_file_gamma != NULL)
  163464. {
  163465. png_debug1(1, "in %s retrieval function\n", "gAMA");
  163466. *int_file_gamma = info_ptr->int_gamma;
  163467. return (PNG_INFO_gAMA);
  163468. }
  163469. return (0);
  163470. }
  163471. #endif
  163472. #endif
  163473. #if defined(PNG_sRGB_SUPPORTED)
  163474. png_uint_32 PNGAPI
  163475. png_get_sRGB(png_structp png_ptr, png_infop info_ptr, int *file_srgb_intent)
  163476. {
  163477. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_sRGB)
  163478. && file_srgb_intent != NULL)
  163479. {
  163480. png_debug1(1, "in %s retrieval function\n", "sRGB");
  163481. *file_srgb_intent = (int)info_ptr->srgb_intent;
  163482. return (PNG_INFO_sRGB);
  163483. }
  163484. return (0);
  163485. }
  163486. #endif
  163487. #if defined(PNG_iCCP_SUPPORTED)
  163488. png_uint_32 PNGAPI
  163489. png_get_iCCP(png_structp png_ptr, png_infop info_ptr,
  163490. png_charpp name, int *compression_type,
  163491. png_charpp profile, png_uint_32 *proflen)
  163492. {
  163493. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_iCCP)
  163494. && name != NULL && profile != NULL && proflen != NULL)
  163495. {
  163496. png_debug1(1, "in %s retrieval function\n", "iCCP");
  163497. *name = info_ptr->iccp_name;
  163498. *profile = info_ptr->iccp_profile;
  163499. *proflen = (int)info_ptr->iccp_proflen;
  163500. *compression_type = (int)info_ptr->iccp_compression;
  163501. return (PNG_INFO_iCCP);
  163502. }
  163503. return (0);
  163504. }
  163505. #endif
  163506. #if defined(PNG_sPLT_SUPPORTED)
  163507. png_uint_32 PNGAPI
  163508. png_get_sPLT(png_structp png_ptr, png_infop info_ptr,
  163509. png_sPLT_tpp spalettes)
  163510. {
  163511. if (png_ptr != NULL && info_ptr != NULL && spalettes != NULL)
  163512. {
  163513. *spalettes = info_ptr->splt_palettes;
  163514. return ((png_uint_32)info_ptr->splt_palettes_num);
  163515. }
  163516. return (0);
  163517. }
  163518. #endif
  163519. #if defined(PNG_hIST_SUPPORTED)
  163520. png_uint_32 PNGAPI
  163521. png_get_hIST(png_structp png_ptr, png_infop info_ptr, png_uint_16p *hist)
  163522. {
  163523. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_hIST)
  163524. && hist != NULL)
  163525. {
  163526. png_debug1(1, "in %s retrieval function\n", "hIST");
  163527. *hist = info_ptr->hist;
  163528. return (PNG_INFO_hIST);
  163529. }
  163530. return (0);
  163531. }
  163532. #endif
  163533. png_uint_32 PNGAPI
  163534. png_get_IHDR(png_structp png_ptr, png_infop info_ptr,
  163535. png_uint_32 *width, png_uint_32 *height, int *bit_depth,
  163536. int *color_type, int *interlace_type, int *compression_type,
  163537. int *filter_type)
  163538. {
  163539. if (png_ptr != NULL && info_ptr != NULL && width != NULL && height != NULL &&
  163540. bit_depth != NULL && color_type != NULL)
  163541. {
  163542. png_debug1(1, "in %s retrieval function\n", "IHDR");
  163543. *width = info_ptr->width;
  163544. *height = info_ptr->height;
  163545. *bit_depth = info_ptr->bit_depth;
  163546. if (info_ptr->bit_depth < 1 || info_ptr->bit_depth > 16)
  163547. png_error(png_ptr, "Invalid bit depth");
  163548. *color_type = info_ptr->color_type;
  163549. if (info_ptr->color_type > 6)
  163550. png_error(png_ptr, "Invalid color type");
  163551. if (compression_type != NULL)
  163552. *compression_type = info_ptr->compression_type;
  163553. if (filter_type != NULL)
  163554. *filter_type = info_ptr->filter_type;
  163555. if (interlace_type != NULL)
  163556. *interlace_type = info_ptr->interlace_type;
  163557. if (*width == 0 || *width > PNG_UINT_31_MAX)
  163558. png_error(png_ptr, "Invalid image width");
  163559. if (*height == 0 || *height > PNG_UINT_31_MAX)
  163560. png_error(png_ptr, "Invalid image height");
  163561. if (info_ptr->width > (PNG_UINT_32_MAX
  163562. >> 3) /* 8-byte RGBA pixels */
  163563. - 64 /* bigrowbuf hack */
  163564. - 1 /* filter byte */
  163565. - 7*8 /* rounding of width to multiple of 8 pixels */
  163566. - 8) /* extra max_pixel_depth pad */
  163567. {
  163568. png_warning(png_ptr,
  163569. "Width too large for libpng to process image data.");
  163570. }
  163571. return (1);
  163572. }
  163573. return (0);
  163574. }
  163575. #if defined(PNG_oFFs_SUPPORTED)
  163576. png_uint_32 PNGAPI
  163577. png_get_oFFs(png_structp png_ptr, png_infop info_ptr,
  163578. png_int_32 *offset_x, png_int_32 *offset_y, int *unit_type)
  163579. {
  163580. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_oFFs)
  163581. && offset_x != NULL && offset_y != NULL && unit_type != NULL)
  163582. {
  163583. png_debug1(1, "in %s retrieval function\n", "oFFs");
  163584. *offset_x = info_ptr->x_offset;
  163585. *offset_y = info_ptr->y_offset;
  163586. *unit_type = (int)info_ptr->offset_unit_type;
  163587. return (PNG_INFO_oFFs);
  163588. }
  163589. return (0);
  163590. }
  163591. #endif
  163592. #if defined(PNG_pCAL_SUPPORTED)
  163593. png_uint_32 PNGAPI
  163594. png_get_pCAL(png_structp png_ptr, png_infop info_ptr,
  163595. png_charp *purpose, png_int_32 *X0, png_int_32 *X1, int *type, int *nparams,
  163596. png_charp *units, png_charpp *params)
  163597. {
  163598. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pCAL)
  163599. && purpose != NULL && X0 != NULL && X1 != NULL && type != NULL &&
  163600. nparams != NULL && units != NULL && params != NULL)
  163601. {
  163602. png_debug1(1, "in %s retrieval function\n", "pCAL");
  163603. *purpose = info_ptr->pcal_purpose;
  163604. *X0 = info_ptr->pcal_X0;
  163605. *X1 = info_ptr->pcal_X1;
  163606. *type = (int)info_ptr->pcal_type;
  163607. *nparams = (int)info_ptr->pcal_nparams;
  163608. *units = info_ptr->pcal_units;
  163609. *params = info_ptr->pcal_params;
  163610. return (PNG_INFO_pCAL);
  163611. }
  163612. return (0);
  163613. }
  163614. #endif
  163615. #if defined(PNG_sCAL_SUPPORTED)
  163616. #ifdef PNG_FLOATING_POINT_SUPPORTED
  163617. png_uint_32 PNGAPI
  163618. png_get_sCAL(png_structp png_ptr, png_infop info_ptr,
  163619. int *unit, double *width, double *height)
  163620. {
  163621. if (png_ptr != NULL && info_ptr != NULL &&
  163622. (info_ptr->valid & PNG_INFO_sCAL))
  163623. {
  163624. *unit = info_ptr->scal_unit;
  163625. *width = info_ptr->scal_pixel_width;
  163626. *height = info_ptr->scal_pixel_height;
  163627. return (PNG_INFO_sCAL);
  163628. }
  163629. return(0);
  163630. }
  163631. #else
  163632. #ifdef PNG_FIXED_POINT_SUPPORTED
  163633. png_uint_32 PNGAPI
  163634. png_get_sCAL_s(png_structp png_ptr, png_infop info_ptr,
  163635. int *unit, png_charpp width, png_charpp height)
  163636. {
  163637. if (png_ptr != NULL && info_ptr != NULL &&
  163638. (info_ptr->valid & PNG_INFO_sCAL))
  163639. {
  163640. *unit = info_ptr->scal_unit;
  163641. *width = info_ptr->scal_s_width;
  163642. *height = info_ptr->scal_s_height;
  163643. return (PNG_INFO_sCAL);
  163644. }
  163645. return(0);
  163646. }
  163647. #endif
  163648. #endif
  163649. #endif
  163650. #if defined(PNG_pHYs_SUPPORTED)
  163651. png_uint_32 PNGAPI
  163652. png_get_pHYs(png_structp png_ptr, png_infop info_ptr,
  163653. png_uint_32 *res_x, png_uint_32 *res_y, int *unit_type)
  163654. {
  163655. png_uint_32 retval = 0;
  163656. if (png_ptr != NULL && info_ptr != NULL &&
  163657. (info_ptr->valid & PNG_INFO_pHYs))
  163658. {
  163659. png_debug1(1, "in %s retrieval function\n", "pHYs");
  163660. if (res_x != NULL)
  163661. {
  163662. *res_x = info_ptr->x_pixels_per_unit;
  163663. retval |= PNG_INFO_pHYs;
  163664. }
  163665. if (res_y != NULL)
  163666. {
  163667. *res_y = info_ptr->y_pixels_per_unit;
  163668. retval |= PNG_INFO_pHYs;
  163669. }
  163670. if (unit_type != NULL)
  163671. {
  163672. *unit_type = (int)info_ptr->phys_unit_type;
  163673. retval |= PNG_INFO_pHYs;
  163674. }
  163675. }
  163676. return (retval);
  163677. }
  163678. #endif
  163679. png_uint_32 PNGAPI
  163680. png_get_PLTE(png_structp png_ptr, png_infop info_ptr, png_colorp *palette,
  163681. int *num_palette)
  163682. {
  163683. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_PLTE)
  163684. && palette != NULL)
  163685. {
  163686. png_debug1(1, "in %s retrieval function\n", "PLTE");
  163687. *palette = info_ptr->palette;
  163688. *num_palette = info_ptr->num_palette;
  163689. png_debug1(3, "num_palette = %d\n", *num_palette);
  163690. return (PNG_INFO_PLTE);
  163691. }
  163692. return (0);
  163693. }
  163694. #if defined(PNG_sBIT_SUPPORTED)
  163695. png_uint_32 PNGAPI
  163696. png_get_sBIT(png_structp png_ptr, png_infop info_ptr, png_color_8p *sig_bit)
  163697. {
  163698. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_sBIT)
  163699. && sig_bit != NULL)
  163700. {
  163701. png_debug1(1, "in %s retrieval function\n", "sBIT");
  163702. *sig_bit = &(info_ptr->sig_bit);
  163703. return (PNG_INFO_sBIT);
  163704. }
  163705. return (0);
  163706. }
  163707. #endif
  163708. #if defined(PNG_TEXT_SUPPORTED)
  163709. png_uint_32 PNGAPI
  163710. png_get_text(png_structp png_ptr, png_infop info_ptr, png_textp *text_ptr,
  163711. int *num_text)
  163712. {
  163713. if (png_ptr != NULL && info_ptr != NULL && info_ptr->num_text > 0)
  163714. {
  163715. png_debug1(1, "in %s retrieval function\n",
  163716. (png_ptr->chunk_name[0] == '\0' ? "text"
  163717. : (png_const_charp)png_ptr->chunk_name));
  163718. if (text_ptr != NULL)
  163719. *text_ptr = info_ptr->text;
  163720. if (num_text != NULL)
  163721. *num_text = info_ptr->num_text;
  163722. return ((png_uint_32)info_ptr->num_text);
  163723. }
  163724. if (num_text != NULL)
  163725. *num_text = 0;
  163726. return(0);
  163727. }
  163728. #endif
  163729. #if defined(PNG_tIME_SUPPORTED)
  163730. png_uint_32 PNGAPI
  163731. png_get_tIME(png_structp png_ptr, png_infop info_ptr, png_timep *mod_time)
  163732. {
  163733. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_tIME)
  163734. && mod_time != NULL)
  163735. {
  163736. png_debug1(1, "in %s retrieval function\n", "tIME");
  163737. *mod_time = &(info_ptr->mod_time);
  163738. return (PNG_INFO_tIME);
  163739. }
  163740. return (0);
  163741. }
  163742. #endif
  163743. #if defined(PNG_tRNS_SUPPORTED)
  163744. png_uint_32 PNGAPI
  163745. png_get_tRNS(png_structp png_ptr, png_infop info_ptr,
  163746. png_bytep *trans, int *num_trans, png_color_16p *trans_values)
  163747. {
  163748. png_uint_32 retval = 0;
  163749. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_tRNS))
  163750. {
  163751. png_debug1(1, "in %s retrieval function\n", "tRNS");
  163752. if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  163753. {
  163754. if (trans != NULL)
  163755. {
  163756. *trans = info_ptr->trans;
  163757. retval |= PNG_INFO_tRNS;
  163758. }
  163759. if (trans_values != NULL)
  163760. *trans_values = &(info_ptr->trans_values);
  163761. }
  163762. else /* if (info_ptr->color_type != PNG_COLOR_TYPE_PALETTE) */
  163763. {
  163764. if (trans_values != NULL)
  163765. {
  163766. *trans_values = &(info_ptr->trans_values);
  163767. retval |= PNG_INFO_tRNS;
  163768. }
  163769. if(trans != NULL)
  163770. *trans = NULL;
  163771. }
  163772. if(num_trans != NULL)
  163773. {
  163774. *num_trans = info_ptr->num_trans;
  163775. retval |= PNG_INFO_tRNS;
  163776. }
  163777. }
  163778. return (retval);
  163779. }
  163780. #endif
  163781. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  163782. png_uint_32 PNGAPI
  163783. png_get_unknown_chunks(png_structp png_ptr, png_infop info_ptr,
  163784. png_unknown_chunkpp unknowns)
  163785. {
  163786. if (png_ptr != NULL && info_ptr != NULL && unknowns != NULL)
  163787. {
  163788. *unknowns = info_ptr->unknown_chunks;
  163789. return ((png_uint_32)info_ptr->unknown_chunks_num);
  163790. }
  163791. return (0);
  163792. }
  163793. #endif
  163794. #if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
  163795. png_byte PNGAPI
  163796. png_get_rgb_to_gray_status (png_structp png_ptr)
  163797. {
  163798. return (png_byte)(png_ptr? png_ptr->rgb_to_gray_status : 0);
  163799. }
  163800. #endif
  163801. #if defined(PNG_USER_CHUNKS_SUPPORTED)
  163802. png_voidp PNGAPI
  163803. png_get_user_chunk_ptr(png_structp png_ptr)
  163804. {
  163805. return (png_ptr? png_ptr->user_chunk_ptr : NULL);
  163806. }
  163807. #endif
  163808. #ifdef PNG_WRITE_SUPPORTED
  163809. png_uint_32 PNGAPI
  163810. png_get_compression_buffer_size(png_structp png_ptr)
  163811. {
  163812. return (png_uint_32)(png_ptr? png_ptr->zbuf_size : 0L);
  163813. }
  163814. #endif
  163815. #ifdef PNG_ASSEMBLER_CODE_SUPPORTED
  163816. #ifndef PNG_1_0_X
  163817. png_uint_32 PNGAPI
  163818. png_get_asm_flags (png_structp png_ptr)
  163819. {
  163820. return (png_ptr? 0L: 0L);
  163821. }
  163822. png_uint_32 PNGAPI
  163823. png_get_asm_flagmask (int flag_select)
  163824. {
  163825. flag_select=flag_select;
  163826. return 0L;
  163827. }
  163828. png_uint_32 PNGAPI
  163829. png_get_mmx_flagmask (int flag_select, int *compilerID)
  163830. {
  163831. flag_select=flag_select;
  163832. *compilerID = -1; /* unknown (i.e., no asm/MMX code compiled) */
  163833. return 0L;
  163834. }
  163835. png_byte PNGAPI
  163836. png_get_mmx_bitdepth_threshold (png_structp png_ptr)
  163837. {
  163838. return (png_ptr? 0: 0);
  163839. }
  163840. png_uint_32 PNGAPI
  163841. png_get_mmx_rowbytes_threshold (png_structp png_ptr)
  163842. {
  163843. return (png_ptr? 0L: 0L);
  163844. }
  163845. #endif /* ?PNG_1_0_X */
  163846. #endif /* ?PNG_ASSEMBLER_CODE_SUPPORTED */
  163847. #ifdef PNG_SET_USER_LIMITS_SUPPORTED
  163848. png_uint_32 PNGAPI
  163849. png_get_user_width_max (png_structp png_ptr)
  163850. {
  163851. return (png_ptr? png_ptr->user_width_max : 0);
  163852. }
  163853. png_uint_32 PNGAPI
  163854. png_get_user_height_max (png_structp png_ptr)
  163855. {
  163856. return (png_ptr? png_ptr->user_height_max : 0);
  163857. }
  163858. #endif /* ?PNG_SET_USER_LIMITS_SUPPORTED */
  163859. #endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */
  163860. /*** End of inlined file: pngget.c ***/
  163861. /*** Start of inlined file: pngmem.c ***/
  163862. #define PNG_INTERNAL
  163863. #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
  163864. #if defined(__TURBOC__) && !defined(_Windows) && !defined(__FLAT__)
  163865. png_voidp /* PRIVATE */
  163866. png_create_struct(int type)
  163867. {
  163868. #ifdef PNG_USER_MEM_SUPPORTED
  163869. return (png_create_struct_2(type, png_malloc_ptr_NULL, png_voidp_NULL));
  163870. }
  163871. png_voidp /* PRIVATE */
  163872. png_create_struct_2(int type, png_malloc_ptr malloc_fn, png_voidp mem_ptr)
  163873. {
  163874. #endif /* PNG_USER_MEM_SUPPORTED */
  163875. png_size_t size;
  163876. png_voidp struct_ptr;
  163877. if (type == PNG_STRUCT_INFO)
  163878. size = png_sizeof(png_info);
  163879. else if (type == PNG_STRUCT_PNG)
  163880. size = png_sizeof(png_struct);
  163881. else
  163882. return (png_get_copyright(NULL));
  163883. #ifdef PNG_USER_MEM_SUPPORTED
  163884. if(malloc_fn != NULL)
  163885. {
  163886. png_struct dummy_struct;
  163887. png_structp png_ptr = &dummy_struct;
  163888. png_ptr->mem_ptr=mem_ptr;
  163889. struct_ptr = (*(malloc_fn))(png_ptr, (png_uint_32)size);
  163890. }
  163891. else
  163892. #endif /* PNG_USER_MEM_SUPPORTED */
  163893. struct_ptr = (png_voidp)farmalloc(size);
  163894. if (struct_ptr != NULL)
  163895. png_memset(struct_ptr, 0, size);
  163896. return (struct_ptr);
  163897. }
  163898. void /* PRIVATE */
  163899. png_destroy_struct(png_voidp struct_ptr)
  163900. {
  163901. #ifdef PNG_USER_MEM_SUPPORTED
  163902. png_destroy_struct_2(struct_ptr, png_free_ptr_NULL, png_voidp_NULL);
  163903. }
  163904. void /* PRIVATE */
  163905. png_destroy_struct_2(png_voidp struct_ptr, png_free_ptr free_fn,
  163906. png_voidp mem_ptr)
  163907. {
  163908. #endif
  163909. if (struct_ptr != NULL)
  163910. {
  163911. #ifdef PNG_USER_MEM_SUPPORTED
  163912. if(free_fn != NULL)
  163913. {
  163914. png_struct dummy_struct;
  163915. png_structp png_ptr = &dummy_struct;
  163916. png_ptr->mem_ptr=mem_ptr;
  163917. (*(free_fn))(png_ptr, struct_ptr);
  163918. return;
  163919. }
  163920. #endif /* PNG_USER_MEM_SUPPORTED */
  163921. farfree (struct_ptr);
  163922. }
  163923. }
  163924. png_voidp PNGAPI
  163925. png_malloc(png_structp png_ptr, png_uint_32 size)
  163926. {
  163927. png_voidp ret;
  163928. if (png_ptr == NULL || size == 0)
  163929. return (NULL);
  163930. #ifdef PNG_USER_MEM_SUPPORTED
  163931. if(png_ptr->malloc_fn != NULL)
  163932. ret = ((png_voidp)(*(png_ptr->malloc_fn))(png_ptr, (png_size_t)size));
  163933. else
  163934. ret = (png_malloc_default(png_ptr, size));
  163935. if (ret == NULL && (png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
  163936. png_error(png_ptr, "Out of memory!");
  163937. return (ret);
  163938. }
  163939. png_voidp PNGAPI
  163940. png_malloc_default(png_structp png_ptr, png_uint_32 size)
  163941. {
  163942. png_voidp ret;
  163943. #endif /* PNG_USER_MEM_SUPPORTED */
  163944. if (png_ptr == NULL || size == 0)
  163945. return (NULL);
  163946. #ifdef PNG_MAX_MALLOC_64K
  163947. if (size > (png_uint_32)65536L)
  163948. {
  163949. png_warning(png_ptr, "Cannot Allocate > 64K");
  163950. ret = NULL;
  163951. }
  163952. else
  163953. #endif
  163954. if (size != (size_t)size)
  163955. ret = NULL;
  163956. else if (size == (png_uint_32)65536L)
  163957. {
  163958. if (png_ptr->offset_table == NULL)
  163959. {
  163960. ret = farmalloc(size);
  163961. if (ret == NULL || ((png_size_t)ret & 0xffff))
  163962. {
  163963. int num_blocks;
  163964. png_uint_32 total_size;
  163965. png_bytep table;
  163966. int i;
  163967. png_byte huge * hptr;
  163968. if (ret != NULL)
  163969. {
  163970. farfree(ret);
  163971. ret = NULL;
  163972. }
  163973. if(png_ptr->zlib_window_bits > 14)
  163974. num_blocks = (int)(1 << (png_ptr->zlib_window_bits - 14));
  163975. else
  163976. num_blocks = 1;
  163977. if (png_ptr->zlib_mem_level >= 7)
  163978. num_blocks += (int)(1 << (png_ptr->zlib_mem_level - 7));
  163979. else
  163980. num_blocks++;
  163981. total_size = ((png_uint_32)65536L) * (png_uint_32)num_blocks+16;
  163982. table = farmalloc(total_size);
  163983. if (table == NULL)
  163984. {
  163985. #ifndef PNG_USER_MEM_SUPPORTED
  163986. if ((png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
  163987. png_error(png_ptr, "Out Of Memory."); /* Note "O" and "M" */
  163988. else
  163989. png_warning(png_ptr, "Out Of Memory.");
  163990. #endif
  163991. return (NULL);
  163992. }
  163993. if ((png_size_t)table & 0xfff0)
  163994. {
  163995. #ifndef PNG_USER_MEM_SUPPORTED
  163996. if ((png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
  163997. png_error(png_ptr,
  163998. "Farmalloc didn't return normalized pointer");
  163999. else
  164000. png_warning(png_ptr,
  164001. "Farmalloc didn't return normalized pointer");
  164002. #endif
  164003. return (NULL);
  164004. }
  164005. png_ptr->offset_table = table;
  164006. png_ptr->offset_table_ptr = farmalloc(num_blocks *
  164007. png_sizeof (png_bytep));
  164008. if (png_ptr->offset_table_ptr == NULL)
  164009. {
  164010. #ifndef PNG_USER_MEM_SUPPORTED
  164011. if ((png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
  164012. png_error(png_ptr, "Out Of memory."); /* Note "O" and "M" */
  164013. else
  164014. png_warning(png_ptr, "Out Of memory.");
  164015. #endif
  164016. return (NULL);
  164017. }
  164018. hptr = (png_byte huge *)table;
  164019. if ((png_size_t)hptr & 0xf)
  164020. {
  164021. hptr = (png_byte huge *)((long)(hptr) & 0xfffffff0L);
  164022. hptr = hptr + 16L; /* "hptr += 16L" fails on Turbo C++ 3.0 */
  164023. }
  164024. for (i = 0; i < num_blocks; i++)
  164025. {
  164026. png_ptr->offset_table_ptr[i] = (png_bytep)hptr;
  164027. hptr = hptr + (png_uint_32)65536L; /* "+=" fails on TC++3.0 */
  164028. }
  164029. png_ptr->offset_table_number = num_blocks;
  164030. png_ptr->offset_table_count = 0;
  164031. png_ptr->offset_table_count_free = 0;
  164032. }
  164033. }
  164034. if (png_ptr->offset_table_count >= png_ptr->offset_table_number)
  164035. {
  164036. #ifndef PNG_USER_MEM_SUPPORTED
  164037. if ((png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
  164038. png_error(png_ptr, "Out of Memory."); /* Note "o" and "M" */
  164039. else
  164040. png_warning(png_ptr, "Out of Memory.");
  164041. #endif
  164042. return (NULL);
  164043. }
  164044. ret = png_ptr->offset_table_ptr[png_ptr->offset_table_count++];
  164045. }
  164046. else
  164047. ret = farmalloc(size);
  164048. #ifndef PNG_USER_MEM_SUPPORTED
  164049. if (ret == NULL)
  164050. {
  164051. if ((png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
  164052. png_error(png_ptr, "Out of memory."); /* Note "o" and "m" */
  164053. else
  164054. png_warning(png_ptr, "Out of memory."); /* Note "o" and "m" */
  164055. }
  164056. #endif
  164057. return (ret);
  164058. }
  164059. void PNGAPI
  164060. png_free(png_structp png_ptr, png_voidp ptr)
  164061. {
  164062. if (png_ptr == NULL || ptr == NULL)
  164063. return;
  164064. #ifdef PNG_USER_MEM_SUPPORTED
  164065. if (png_ptr->free_fn != NULL)
  164066. {
  164067. (*(png_ptr->free_fn))(png_ptr, ptr);
  164068. return;
  164069. }
  164070. else png_free_default(png_ptr, ptr);
  164071. }
  164072. void PNGAPI
  164073. png_free_default(png_structp png_ptr, png_voidp ptr)
  164074. {
  164075. #endif /* PNG_USER_MEM_SUPPORTED */
  164076. if(png_ptr == NULL) return;
  164077. if (png_ptr->offset_table != NULL)
  164078. {
  164079. int i;
  164080. for (i = 0; i < png_ptr->offset_table_count; i++)
  164081. {
  164082. if (ptr == png_ptr->offset_table_ptr[i])
  164083. {
  164084. ptr = NULL;
  164085. png_ptr->offset_table_count_free++;
  164086. break;
  164087. }
  164088. }
  164089. if (png_ptr->offset_table_count_free == png_ptr->offset_table_count)
  164090. {
  164091. farfree(png_ptr->offset_table);
  164092. farfree(png_ptr->offset_table_ptr);
  164093. png_ptr->offset_table = NULL;
  164094. png_ptr->offset_table_ptr = NULL;
  164095. }
  164096. }
  164097. if (ptr != NULL)
  164098. {
  164099. farfree(ptr);
  164100. }
  164101. }
  164102. #else /* Not the Borland DOS special memory handler */
  164103. png_voidp /* PRIVATE */
  164104. png_create_struct(int type)
  164105. {
  164106. #ifdef PNG_USER_MEM_SUPPORTED
  164107. return (png_create_struct_2(type, png_malloc_ptr_NULL, png_voidp_NULL));
  164108. }
  164109. png_voidp /* PRIVATE */
  164110. png_create_struct_2(int type, png_malloc_ptr malloc_fn, png_voidp mem_ptr)
  164111. {
  164112. #endif /* PNG_USER_MEM_SUPPORTED */
  164113. png_size_t size;
  164114. png_voidp struct_ptr;
  164115. if (type == PNG_STRUCT_INFO)
  164116. size = png_sizeof(png_info);
  164117. else if (type == PNG_STRUCT_PNG)
  164118. size = png_sizeof(png_struct);
  164119. else
  164120. return (NULL);
  164121. #ifdef PNG_USER_MEM_SUPPORTED
  164122. if(malloc_fn != NULL)
  164123. {
  164124. png_struct dummy_struct;
  164125. png_structp png_ptr = &dummy_struct;
  164126. png_ptr->mem_ptr=mem_ptr;
  164127. struct_ptr = (*(malloc_fn))(png_ptr, size);
  164128. if (struct_ptr != NULL)
  164129. png_memset(struct_ptr, 0, size);
  164130. return (struct_ptr);
  164131. }
  164132. #endif /* PNG_USER_MEM_SUPPORTED */
  164133. #if defined(__TURBOC__) && !defined(__FLAT__)
  164134. struct_ptr = (png_voidp)farmalloc(size);
  164135. #else
  164136. # if defined(_MSC_VER) && defined(MAXSEG_64K)
  164137. struct_ptr = (png_voidp)halloc(size,1);
  164138. # else
  164139. struct_ptr = (png_voidp)malloc(size);
  164140. # endif
  164141. #endif
  164142. if (struct_ptr != NULL)
  164143. png_memset(struct_ptr, 0, size);
  164144. return (struct_ptr);
  164145. }
  164146. void /* PRIVATE */
  164147. png_destroy_struct(png_voidp struct_ptr)
  164148. {
  164149. #ifdef PNG_USER_MEM_SUPPORTED
  164150. png_destroy_struct_2(struct_ptr, png_free_ptr_NULL, png_voidp_NULL);
  164151. }
  164152. void /* PRIVATE */
  164153. png_destroy_struct_2(png_voidp struct_ptr, png_free_ptr free_fn,
  164154. png_voidp mem_ptr)
  164155. {
  164156. #endif /* PNG_USER_MEM_SUPPORTED */
  164157. if (struct_ptr != NULL)
  164158. {
  164159. #ifdef PNG_USER_MEM_SUPPORTED
  164160. if(free_fn != NULL)
  164161. {
  164162. png_struct dummy_struct;
  164163. png_structp png_ptr = &dummy_struct;
  164164. png_ptr->mem_ptr=mem_ptr;
  164165. (*(free_fn))(png_ptr, struct_ptr);
  164166. return;
  164167. }
  164168. #endif /* PNG_USER_MEM_SUPPORTED */
  164169. #if defined(__TURBOC__) && !defined(__FLAT__)
  164170. farfree(struct_ptr);
  164171. #else
  164172. # if defined(_MSC_VER) && defined(MAXSEG_64K)
  164173. hfree(struct_ptr);
  164174. # else
  164175. free(struct_ptr);
  164176. # endif
  164177. #endif
  164178. }
  164179. }
  164180. png_voidp PNGAPI
  164181. png_malloc(png_structp png_ptr, png_uint_32 size)
  164182. {
  164183. png_voidp ret;
  164184. #ifdef PNG_USER_MEM_SUPPORTED
  164185. if (png_ptr == NULL || size == 0)
  164186. return (NULL);
  164187. if(png_ptr->malloc_fn != NULL)
  164188. ret = ((png_voidp)(*(png_ptr->malloc_fn))(png_ptr, (png_size_t)size));
  164189. else
  164190. ret = (png_malloc_default(png_ptr, size));
  164191. if (ret == NULL && (png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
  164192. png_error(png_ptr, "Out of Memory!");
  164193. return (ret);
  164194. }
  164195. png_voidp PNGAPI
  164196. png_malloc_default(png_structp png_ptr, png_uint_32 size)
  164197. {
  164198. png_voidp ret;
  164199. #endif /* PNG_USER_MEM_SUPPORTED */
  164200. if (png_ptr == NULL || size == 0)
  164201. return (NULL);
  164202. #ifdef PNG_MAX_MALLOC_64K
  164203. if (size > (png_uint_32)65536L)
  164204. {
  164205. #ifndef PNG_USER_MEM_SUPPORTED
  164206. if(png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
  164207. png_error(png_ptr, "Cannot Allocate > 64K");
  164208. else
  164209. #endif
  164210. return NULL;
  164211. }
  164212. #endif
  164213. #if defined(__TURBOC__) && !defined(__FLAT__)
  164214. if (size != (unsigned long)size)
  164215. ret = NULL;
  164216. else
  164217. ret = farmalloc(size);
  164218. #else
  164219. # if defined(_MSC_VER) && defined(MAXSEG_64K)
  164220. if (size != (unsigned long)size)
  164221. ret = NULL;
  164222. else
  164223. ret = halloc(size, 1);
  164224. # else
  164225. if (size != (size_t)size)
  164226. ret = NULL;
  164227. else
  164228. ret = malloc((size_t)size);
  164229. # endif
  164230. #endif
  164231. #ifndef PNG_USER_MEM_SUPPORTED
  164232. if (ret == NULL && (png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
  164233. png_error(png_ptr, "Out of Memory");
  164234. #endif
  164235. return (ret);
  164236. }
  164237. void PNGAPI
  164238. png_free(png_structp png_ptr, png_voidp ptr)
  164239. {
  164240. if (png_ptr == NULL || ptr == NULL)
  164241. return;
  164242. #ifdef PNG_USER_MEM_SUPPORTED
  164243. if (png_ptr->free_fn != NULL)
  164244. {
  164245. (*(png_ptr->free_fn))(png_ptr, ptr);
  164246. return;
  164247. }
  164248. else png_free_default(png_ptr, ptr);
  164249. }
  164250. void PNGAPI
  164251. png_free_default(png_structp png_ptr, png_voidp ptr)
  164252. {
  164253. if (png_ptr == NULL || ptr == NULL)
  164254. return;
  164255. #endif /* PNG_USER_MEM_SUPPORTED */
  164256. #if defined(__TURBOC__) && !defined(__FLAT__)
  164257. farfree(ptr);
  164258. #else
  164259. # if defined(_MSC_VER) && defined(MAXSEG_64K)
  164260. hfree(ptr);
  164261. # else
  164262. free(ptr);
  164263. # endif
  164264. #endif
  164265. }
  164266. #endif /* Not Borland DOS special memory handler */
  164267. #if defined(PNG_1_0_X)
  164268. # define png_malloc_warn png_malloc
  164269. #else
  164270. png_voidp PNGAPI
  164271. png_malloc_warn(png_structp png_ptr, png_uint_32 size)
  164272. {
  164273. png_voidp ptr;
  164274. png_uint_32 save_flags;
  164275. if(png_ptr == NULL) return (NULL);
  164276. save_flags=png_ptr->flags;
  164277. png_ptr->flags|=PNG_FLAG_MALLOC_NULL_MEM_OK;
  164278. ptr = (png_voidp)png_malloc((png_structp)png_ptr, size);
  164279. png_ptr->flags=save_flags;
  164280. return(ptr);
  164281. }
  164282. #endif
  164283. png_voidp PNGAPI
  164284. png_memcpy_check (png_structp png_ptr, png_voidp s1, png_voidp s2,
  164285. png_uint_32 length)
  164286. {
  164287. png_size_t size;
  164288. size = (png_size_t)length;
  164289. if ((png_uint_32)size != length)
  164290. png_error(png_ptr,"Overflow in png_memcpy_check.");
  164291. return(png_memcpy (s1, s2, size));
  164292. }
  164293. png_voidp PNGAPI
  164294. png_memset_check (png_structp png_ptr, png_voidp s1, int value,
  164295. png_uint_32 length)
  164296. {
  164297. png_size_t size;
  164298. size = (png_size_t)length;
  164299. if ((png_uint_32)size != length)
  164300. png_error(png_ptr,"Overflow in png_memset_check.");
  164301. return (png_memset (s1, value, size));
  164302. }
  164303. #ifdef PNG_USER_MEM_SUPPORTED
  164304. void PNGAPI
  164305. png_set_mem_fn(png_structp png_ptr, png_voidp mem_ptr, png_malloc_ptr
  164306. malloc_fn, png_free_ptr free_fn)
  164307. {
  164308. if(png_ptr != NULL) {
  164309. png_ptr->mem_ptr = mem_ptr;
  164310. png_ptr->malloc_fn = malloc_fn;
  164311. png_ptr->free_fn = free_fn;
  164312. }
  164313. }
  164314. png_voidp PNGAPI
  164315. png_get_mem_ptr(png_structp png_ptr)
  164316. {
  164317. if(png_ptr == NULL) return (NULL);
  164318. return ((png_voidp)png_ptr->mem_ptr);
  164319. }
  164320. #endif /* PNG_USER_MEM_SUPPORTED */
  164321. #endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */
  164322. /*** End of inlined file: pngmem.c ***/
  164323. /*** Start of inlined file: pngread.c ***/
  164324. #define PNG_INTERNAL
  164325. #if defined(PNG_READ_SUPPORTED)
  164326. png_structp PNGAPI
  164327. png_create_read_struct(png_const_charp user_png_ver, png_voidp error_ptr,
  164328. png_error_ptr error_fn, png_error_ptr warn_fn)
  164329. {
  164330. #ifdef PNG_USER_MEM_SUPPORTED
  164331. return (png_create_read_struct_2(user_png_ver, error_ptr, error_fn,
  164332. warn_fn, png_voidp_NULL, png_malloc_ptr_NULL, png_free_ptr_NULL));
  164333. }
  164334. png_structp PNGAPI
  164335. png_create_read_struct_2(png_const_charp user_png_ver, png_voidp error_ptr,
  164336. png_error_ptr error_fn, png_error_ptr warn_fn, png_voidp mem_ptr,
  164337. png_malloc_ptr malloc_fn, png_free_ptr free_fn)
  164338. {
  164339. #endif /* PNG_USER_MEM_SUPPORTED */
  164340. png_structp png_ptr;
  164341. #ifdef PNG_SETJMP_SUPPORTED
  164342. #ifdef USE_FAR_KEYWORD
  164343. jmp_buf jmpbuf;
  164344. #endif
  164345. #endif
  164346. int i;
  164347. png_debug(1, "in png_create_read_struct\n");
  164348. #ifdef PNG_USER_MEM_SUPPORTED
  164349. png_ptr = (png_structp)png_create_struct_2(PNG_STRUCT_PNG,
  164350. (png_malloc_ptr)malloc_fn, (png_voidp)mem_ptr);
  164351. #else
  164352. png_ptr = (png_structp)png_create_struct(PNG_STRUCT_PNG);
  164353. #endif
  164354. if (png_ptr == NULL)
  164355. return (NULL);
  164356. #ifdef PNG_SET_USER_LIMITS_SUPPORTED
  164357. png_ptr->user_width_max=PNG_USER_WIDTH_MAX;
  164358. png_ptr->user_height_max=PNG_USER_HEIGHT_MAX;
  164359. #endif
  164360. #ifdef PNG_SETJMP_SUPPORTED
  164361. #ifdef USE_FAR_KEYWORD
  164362. if (setjmp(jmpbuf))
  164363. #else
  164364. if (setjmp(png_ptr->jmpbuf))
  164365. #endif
  164366. {
  164367. png_free(png_ptr, png_ptr->zbuf);
  164368. png_ptr->zbuf=NULL;
  164369. #ifdef PNG_USER_MEM_SUPPORTED
  164370. png_destroy_struct_2((png_voidp)png_ptr,
  164371. (png_free_ptr)free_fn, (png_voidp)mem_ptr);
  164372. #else
  164373. png_destroy_struct((png_voidp)png_ptr);
  164374. #endif
  164375. return (NULL);
  164376. }
  164377. #ifdef USE_FAR_KEYWORD
  164378. png_memcpy(png_ptr->jmpbuf,jmpbuf,png_sizeof(jmp_buf));
  164379. #endif
  164380. #endif
  164381. #ifdef PNG_USER_MEM_SUPPORTED
  164382. png_set_mem_fn(png_ptr, mem_ptr, malloc_fn, free_fn);
  164383. #endif
  164384. png_set_error_fn(png_ptr, error_ptr, error_fn, warn_fn);
  164385. i=0;
  164386. do
  164387. {
  164388. if(user_png_ver[i] != png_libpng_ver[i])
  164389. png_ptr->flags |= PNG_FLAG_LIBRARY_MISMATCH;
  164390. } while (png_libpng_ver[i++]);
  164391. if (png_ptr->flags & PNG_FLAG_LIBRARY_MISMATCH)
  164392. {
  164393. if (user_png_ver == NULL || user_png_ver[0] != png_libpng_ver[0] ||
  164394. (user_png_ver[0] == '1' && user_png_ver[2] != png_libpng_ver[2]) ||
  164395. (user_png_ver[0] == '0' && user_png_ver[2] < '9'))
  164396. {
  164397. #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)
  164398. char msg[80];
  164399. if (user_png_ver)
  164400. {
  164401. png_snprintf(msg, 80,
  164402. "Application was compiled with png.h from libpng-%.20s",
  164403. user_png_ver);
  164404. png_warning(png_ptr, msg);
  164405. }
  164406. png_snprintf(msg, 80,
  164407. "Application is running with png.c from libpng-%.20s",
  164408. png_libpng_ver);
  164409. png_warning(png_ptr, msg);
  164410. #endif
  164411. #ifdef PNG_ERROR_NUMBERS_SUPPORTED
  164412. png_ptr->flags=0;
  164413. #endif
  164414. png_error(png_ptr,
  164415. "Incompatible libpng version in application and library");
  164416. }
  164417. }
  164418. png_ptr->zbuf_size = PNG_ZBUF_SIZE;
  164419. png_ptr->zbuf = (png_bytep)png_malloc(png_ptr,
  164420. (png_uint_32)png_ptr->zbuf_size);
  164421. png_ptr->zstream.zalloc = png_zalloc;
  164422. png_ptr->zstream.zfree = png_zfree;
  164423. png_ptr->zstream.opaque = (voidpf)png_ptr;
  164424. switch (inflateInit(&png_ptr->zstream))
  164425. {
  164426. case Z_OK: /* Do nothing */ break;
  164427. case Z_MEM_ERROR:
  164428. case Z_STREAM_ERROR: png_error(png_ptr, "zlib memory error"); break;
  164429. case Z_VERSION_ERROR: png_error(png_ptr, "zlib version error"); break;
  164430. default: png_error(png_ptr, "Unknown zlib error");
  164431. }
  164432. png_ptr->zstream.next_out = png_ptr->zbuf;
  164433. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  164434. png_set_read_fn(png_ptr, png_voidp_NULL, png_rw_ptr_NULL);
  164435. #ifdef PNG_SETJMP_SUPPORTED
  164436. #ifdef USE_FAR_KEYWORD
  164437. if (setjmp(jmpbuf))
  164438. PNG_ABORT();
  164439. png_memcpy(png_ptr->jmpbuf,jmpbuf,png_sizeof(jmp_buf));
  164440. #else
  164441. if (setjmp(png_ptr->jmpbuf))
  164442. PNG_ABORT();
  164443. #endif
  164444. #endif
  164445. return (png_ptr);
  164446. }
  164447. #if defined(PNG_1_0_X) || defined(PNG_1_2_X)
  164448. #undef png_read_init
  164449. void PNGAPI
  164450. png_read_init(png_structp png_ptr)
  164451. {
  164452. png_read_init_2(png_ptr, "1.0.6 or earlier", 0, 0);
  164453. }
  164454. void PNGAPI
  164455. png_read_init_2(png_structp png_ptr, png_const_charp user_png_ver,
  164456. png_size_t png_struct_size, png_size_t png_info_size)
  164457. {
  164458. if(png_ptr == NULL) return;
  164459. #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)
  164460. if(png_sizeof(png_struct) > png_struct_size ||
  164461. png_sizeof(png_info) > png_info_size)
  164462. {
  164463. char msg[80];
  164464. png_ptr->warning_fn=NULL;
  164465. if (user_png_ver)
  164466. {
  164467. png_snprintf(msg, 80,
  164468. "Application was compiled with png.h from libpng-%.20s",
  164469. user_png_ver);
  164470. png_warning(png_ptr, msg);
  164471. }
  164472. png_snprintf(msg, 80,
  164473. "Application is running with png.c from libpng-%.20s",
  164474. png_libpng_ver);
  164475. png_warning(png_ptr, msg);
  164476. }
  164477. #endif
  164478. if(png_sizeof(png_struct) > png_struct_size)
  164479. {
  164480. png_ptr->error_fn=NULL;
  164481. #ifdef PNG_ERROR_NUMBERS_SUPPORTED
  164482. png_ptr->flags=0;
  164483. #endif
  164484. png_error(png_ptr,
  164485. "The png struct allocated by the application for reading is too small.");
  164486. }
  164487. if(png_sizeof(png_info) > png_info_size)
  164488. {
  164489. png_ptr->error_fn=NULL;
  164490. #ifdef PNG_ERROR_NUMBERS_SUPPORTED
  164491. png_ptr->flags=0;
  164492. #endif
  164493. png_error(png_ptr,
  164494. "The info struct allocated by application for reading is too small.");
  164495. }
  164496. png_read_init_3(&png_ptr, user_png_ver, png_struct_size);
  164497. }
  164498. #endif /* PNG_1_0_X || PNG_1_2_X */
  164499. void PNGAPI
  164500. png_read_init_3(png_structpp ptr_ptr, png_const_charp user_png_ver,
  164501. png_size_t png_struct_size)
  164502. {
  164503. #ifdef PNG_SETJMP_SUPPORTED
  164504. jmp_buf tmp_jmp; /* to save current jump buffer */
  164505. #endif
  164506. int i=0;
  164507. png_structp png_ptr=*ptr_ptr;
  164508. if(png_ptr == NULL) return;
  164509. do
  164510. {
  164511. if(user_png_ver[i] != png_libpng_ver[i])
  164512. {
  164513. #ifdef PNG_LEGACY_SUPPORTED
  164514. png_ptr->flags |= PNG_FLAG_LIBRARY_MISMATCH;
  164515. #else
  164516. png_ptr->warning_fn=NULL;
  164517. png_warning(png_ptr,
  164518. "Application uses deprecated png_read_init() and should be recompiled.");
  164519. break;
  164520. #endif
  164521. }
  164522. } while (png_libpng_ver[i++]);
  164523. png_debug(1, "in png_read_init_3\n");
  164524. #ifdef PNG_SETJMP_SUPPORTED
  164525. png_memcpy(tmp_jmp, png_ptr->jmpbuf, png_sizeof (jmp_buf));
  164526. #endif
  164527. if(png_sizeof(png_struct) > png_struct_size)
  164528. {
  164529. png_destroy_struct(png_ptr);
  164530. *ptr_ptr = (png_structp)png_create_struct(PNG_STRUCT_PNG);
  164531. png_ptr = *ptr_ptr;
  164532. }
  164533. png_memset(png_ptr, 0, png_sizeof (png_struct));
  164534. #ifdef PNG_SETJMP_SUPPORTED
  164535. png_memcpy(png_ptr->jmpbuf, tmp_jmp, png_sizeof (jmp_buf));
  164536. #endif
  164537. #ifdef PNG_SET_USER_LIMITS_SUPPORTED
  164538. png_ptr->user_width_max=PNG_USER_WIDTH_MAX;
  164539. png_ptr->user_height_max=PNG_USER_HEIGHT_MAX;
  164540. #endif
  164541. png_ptr->zbuf_size = PNG_ZBUF_SIZE;
  164542. png_ptr->zbuf = (png_bytep)png_malloc(png_ptr,
  164543. (png_uint_32)png_ptr->zbuf_size);
  164544. png_ptr->zstream.zalloc = png_zalloc;
  164545. png_ptr->zstream.zfree = png_zfree;
  164546. png_ptr->zstream.opaque = (voidpf)png_ptr;
  164547. switch (inflateInit(&png_ptr->zstream))
  164548. {
  164549. case Z_OK: /* Do nothing */ break;
  164550. case Z_MEM_ERROR:
  164551. case Z_STREAM_ERROR: png_error(png_ptr, "zlib memory"); break;
  164552. case Z_VERSION_ERROR: png_error(png_ptr, "zlib version"); break;
  164553. default: png_error(png_ptr, "Unknown zlib error");
  164554. }
  164555. png_ptr->zstream.next_out = png_ptr->zbuf;
  164556. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  164557. png_set_read_fn(png_ptr, png_voidp_NULL, png_rw_ptr_NULL);
  164558. }
  164559. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  164560. void PNGAPI
  164561. png_read_info(png_structp png_ptr, png_infop info_ptr)
  164562. {
  164563. if(png_ptr == NULL) return;
  164564. png_debug(1, "in png_read_info\n");
  164565. if (png_ptr->sig_bytes < 8)
  164566. {
  164567. png_size_t num_checked = png_ptr->sig_bytes,
  164568. num_to_check = 8 - num_checked;
  164569. png_read_data(png_ptr, &(info_ptr->signature[num_checked]), num_to_check);
  164570. png_ptr->sig_bytes = 8;
  164571. if (png_sig_cmp(info_ptr->signature, num_checked, num_to_check))
  164572. {
  164573. if (num_checked < 4 &&
  164574. png_sig_cmp(info_ptr->signature, num_checked, num_to_check - 4))
  164575. png_error(png_ptr, "Not a PNG file");
  164576. else
  164577. png_error(png_ptr, "PNG file corrupted by ASCII conversion");
  164578. }
  164579. if (num_checked < 3)
  164580. png_ptr->mode |= PNG_HAVE_PNG_SIGNATURE;
  164581. }
  164582. for(;;)
  164583. {
  164584. #ifdef PNG_USE_LOCAL_ARRAYS
  164585. PNG_CONST PNG_IHDR;
  164586. PNG_CONST PNG_IDAT;
  164587. PNG_CONST PNG_IEND;
  164588. PNG_CONST PNG_PLTE;
  164589. #if defined(PNG_READ_bKGD_SUPPORTED)
  164590. PNG_CONST PNG_bKGD;
  164591. #endif
  164592. #if defined(PNG_READ_cHRM_SUPPORTED)
  164593. PNG_CONST PNG_cHRM;
  164594. #endif
  164595. #if defined(PNG_READ_gAMA_SUPPORTED)
  164596. PNG_CONST PNG_gAMA;
  164597. #endif
  164598. #if defined(PNG_READ_hIST_SUPPORTED)
  164599. PNG_CONST PNG_hIST;
  164600. #endif
  164601. #if defined(PNG_READ_iCCP_SUPPORTED)
  164602. PNG_CONST PNG_iCCP;
  164603. #endif
  164604. #if defined(PNG_READ_iTXt_SUPPORTED)
  164605. PNG_CONST PNG_iTXt;
  164606. #endif
  164607. #if defined(PNG_READ_oFFs_SUPPORTED)
  164608. PNG_CONST PNG_oFFs;
  164609. #endif
  164610. #if defined(PNG_READ_pCAL_SUPPORTED)
  164611. PNG_CONST PNG_pCAL;
  164612. #endif
  164613. #if defined(PNG_READ_pHYs_SUPPORTED)
  164614. PNG_CONST PNG_pHYs;
  164615. #endif
  164616. #if defined(PNG_READ_sBIT_SUPPORTED)
  164617. PNG_CONST PNG_sBIT;
  164618. #endif
  164619. #if defined(PNG_READ_sCAL_SUPPORTED)
  164620. PNG_CONST PNG_sCAL;
  164621. #endif
  164622. #if defined(PNG_READ_sPLT_SUPPORTED)
  164623. PNG_CONST PNG_sPLT;
  164624. #endif
  164625. #if defined(PNG_READ_sRGB_SUPPORTED)
  164626. PNG_CONST PNG_sRGB;
  164627. #endif
  164628. #if defined(PNG_READ_tEXt_SUPPORTED)
  164629. PNG_CONST PNG_tEXt;
  164630. #endif
  164631. #if defined(PNG_READ_tIME_SUPPORTED)
  164632. PNG_CONST PNG_tIME;
  164633. #endif
  164634. #if defined(PNG_READ_tRNS_SUPPORTED)
  164635. PNG_CONST PNG_tRNS;
  164636. #endif
  164637. #if defined(PNG_READ_zTXt_SUPPORTED)
  164638. PNG_CONST PNG_zTXt;
  164639. #endif
  164640. #endif /* PNG_USE_LOCAL_ARRAYS */
  164641. png_byte chunk_length[4];
  164642. png_uint_32 length;
  164643. png_read_data(png_ptr, chunk_length, 4);
  164644. length = png_get_uint_31(png_ptr,chunk_length);
  164645. png_reset_crc(png_ptr);
  164646. png_crc_read(png_ptr, png_ptr->chunk_name, 4);
  164647. png_debug2(0, "Reading %s chunk, length=%lu.\n", png_ptr->chunk_name,
  164648. length);
  164649. if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  164650. if(png_ptr->mode & PNG_AFTER_IDAT)
  164651. png_ptr->mode |= PNG_HAVE_CHUNK_AFTER_IDAT;
  164652. if (!png_memcmp(png_ptr->chunk_name, png_IHDR, 4))
  164653. png_handle_IHDR(png_ptr, info_ptr, length);
  164654. else if (!png_memcmp(png_ptr->chunk_name, png_IEND, 4))
  164655. png_handle_IEND(png_ptr, info_ptr, length);
  164656. #ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
  164657. else if (png_handle_as_unknown(png_ptr, png_ptr->chunk_name))
  164658. {
  164659. if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  164660. png_ptr->mode |= PNG_HAVE_IDAT;
  164661. png_handle_unknown(png_ptr, info_ptr, length);
  164662. if (!png_memcmp(png_ptr->chunk_name, png_PLTE, 4))
  164663. png_ptr->mode |= PNG_HAVE_PLTE;
  164664. else if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  164665. {
  164666. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  164667. png_error(png_ptr, "Missing IHDR before IDAT");
  164668. else if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE &&
  164669. !(png_ptr->mode & PNG_HAVE_PLTE))
  164670. png_error(png_ptr, "Missing PLTE before IDAT");
  164671. break;
  164672. }
  164673. }
  164674. #endif
  164675. else if (!png_memcmp(png_ptr->chunk_name, png_PLTE, 4))
  164676. png_handle_PLTE(png_ptr, info_ptr, length);
  164677. else if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  164678. {
  164679. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  164680. png_error(png_ptr, "Missing IHDR before IDAT");
  164681. else if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE &&
  164682. !(png_ptr->mode & PNG_HAVE_PLTE))
  164683. png_error(png_ptr, "Missing PLTE before IDAT");
  164684. png_ptr->idat_size = length;
  164685. png_ptr->mode |= PNG_HAVE_IDAT;
  164686. break;
  164687. }
  164688. #if defined(PNG_READ_bKGD_SUPPORTED)
  164689. else if (!png_memcmp(png_ptr->chunk_name, png_bKGD, 4))
  164690. png_handle_bKGD(png_ptr, info_ptr, length);
  164691. #endif
  164692. #if defined(PNG_READ_cHRM_SUPPORTED)
  164693. else if (!png_memcmp(png_ptr->chunk_name, png_cHRM, 4))
  164694. png_handle_cHRM(png_ptr, info_ptr, length);
  164695. #endif
  164696. #if defined(PNG_READ_gAMA_SUPPORTED)
  164697. else if (!png_memcmp(png_ptr->chunk_name, png_gAMA, 4))
  164698. png_handle_gAMA(png_ptr, info_ptr, length);
  164699. #endif
  164700. #if defined(PNG_READ_hIST_SUPPORTED)
  164701. else if (!png_memcmp(png_ptr->chunk_name, png_hIST, 4))
  164702. png_handle_hIST(png_ptr, info_ptr, length);
  164703. #endif
  164704. #if defined(PNG_READ_oFFs_SUPPORTED)
  164705. else if (!png_memcmp(png_ptr->chunk_name, png_oFFs, 4))
  164706. png_handle_oFFs(png_ptr, info_ptr, length);
  164707. #endif
  164708. #if defined(PNG_READ_pCAL_SUPPORTED)
  164709. else if (!png_memcmp(png_ptr->chunk_name, png_pCAL, 4))
  164710. png_handle_pCAL(png_ptr, info_ptr, length);
  164711. #endif
  164712. #if defined(PNG_READ_sCAL_SUPPORTED)
  164713. else if (!png_memcmp(png_ptr->chunk_name, png_sCAL, 4))
  164714. png_handle_sCAL(png_ptr, info_ptr, length);
  164715. #endif
  164716. #if defined(PNG_READ_pHYs_SUPPORTED)
  164717. else if (!png_memcmp(png_ptr->chunk_name, png_pHYs, 4))
  164718. png_handle_pHYs(png_ptr, info_ptr, length);
  164719. #endif
  164720. #if defined(PNG_READ_sBIT_SUPPORTED)
  164721. else if (!png_memcmp(png_ptr->chunk_name, png_sBIT, 4))
  164722. png_handle_sBIT(png_ptr, info_ptr, length);
  164723. #endif
  164724. #if defined(PNG_READ_sRGB_SUPPORTED)
  164725. else if (!png_memcmp(png_ptr->chunk_name, png_sRGB, 4))
  164726. png_handle_sRGB(png_ptr, info_ptr, length);
  164727. #endif
  164728. #if defined(PNG_READ_iCCP_SUPPORTED)
  164729. else if (!png_memcmp(png_ptr->chunk_name, png_iCCP, 4))
  164730. png_handle_iCCP(png_ptr, info_ptr, length);
  164731. #endif
  164732. #if defined(PNG_READ_sPLT_SUPPORTED)
  164733. else if (!png_memcmp(png_ptr->chunk_name, png_sPLT, 4))
  164734. png_handle_sPLT(png_ptr, info_ptr, length);
  164735. #endif
  164736. #if defined(PNG_READ_tEXt_SUPPORTED)
  164737. else if (!png_memcmp(png_ptr->chunk_name, png_tEXt, 4))
  164738. png_handle_tEXt(png_ptr, info_ptr, length);
  164739. #endif
  164740. #if defined(PNG_READ_tIME_SUPPORTED)
  164741. else if (!png_memcmp(png_ptr->chunk_name, png_tIME, 4))
  164742. png_handle_tIME(png_ptr, info_ptr, length);
  164743. #endif
  164744. #if defined(PNG_READ_tRNS_SUPPORTED)
  164745. else if (!png_memcmp(png_ptr->chunk_name, png_tRNS, 4))
  164746. png_handle_tRNS(png_ptr, info_ptr, length);
  164747. #endif
  164748. #if defined(PNG_READ_zTXt_SUPPORTED)
  164749. else if (!png_memcmp(png_ptr->chunk_name, png_zTXt, 4))
  164750. png_handle_zTXt(png_ptr, info_ptr, length);
  164751. #endif
  164752. #if defined(PNG_READ_iTXt_SUPPORTED)
  164753. else if (!png_memcmp(png_ptr->chunk_name, png_iTXt, 4))
  164754. png_handle_iTXt(png_ptr, info_ptr, length);
  164755. #endif
  164756. else
  164757. png_handle_unknown(png_ptr, info_ptr, length);
  164758. }
  164759. }
  164760. #endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */
  164761. void PNGAPI
  164762. png_read_update_info(png_structp png_ptr, png_infop info_ptr)
  164763. {
  164764. png_debug(1, "in png_read_update_info\n");
  164765. if(png_ptr == NULL) return;
  164766. if (!(png_ptr->flags & PNG_FLAG_ROW_INIT))
  164767. png_read_start_row(png_ptr);
  164768. else
  164769. png_warning(png_ptr,
  164770. "Ignoring extra png_read_update_info() call; row buffer not reallocated");
  164771. png_read_transform_info(png_ptr, info_ptr);
  164772. }
  164773. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  164774. void PNGAPI
  164775. png_start_read_image(png_structp png_ptr)
  164776. {
  164777. png_debug(1, "in png_start_read_image\n");
  164778. if(png_ptr == NULL) return;
  164779. if (!(png_ptr->flags & PNG_FLAG_ROW_INIT))
  164780. png_read_start_row(png_ptr);
  164781. }
  164782. #endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */
  164783. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  164784. void PNGAPI
  164785. png_read_row(png_structp png_ptr, png_bytep row, png_bytep dsp_row)
  164786. {
  164787. #ifdef PNG_USE_LOCAL_ARRAYS
  164788. PNG_CONST PNG_IDAT;
  164789. PNG_CONST int png_pass_dsp_mask[7] = {0xff, 0x0f, 0xff, 0x33, 0xff, 0x55,
  164790. 0xff};
  164791. PNG_CONST int png_pass_mask[7] = {0x80, 0x08, 0x88, 0x22, 0xaa, 0x55, 0xff};
  164792. #endif
  164793. int ret;
  164794. if(png_ptr == NULL) return;
  164795. png_debug2(1, "in png_read_row (row %lu, pass %d)\n",
  164796. png_ptr->row_number, png_ptr->pass);
  164797. if (!(png_ptr->flags & PNG_FLAG_ROW_INIT))
  164798. png_read_start_row(png_ptr);
  164799. if (png_ptr->row_number == 0 && png_ptr->pass == 0)
  164800. {
  164801. #if defined(PNG_WRITE_INVERT_SUPPORTED) && !defined(PNG_READ_INVERT_SUPPORTED)
  164802. if (png_ptr->transformations & PNG_INVERT_MONO)
  164803. png_warning(png_ptr, "PNG_READ_INVERT_SUPPORTED is not defined.");
  164804. #endif
  164805. #if defined(PNG_WRITE_FILLER_SUPPORTED) && !defined(PNG_READ_FILLER_SUPPORTED)
  164806. if (png_ptr->transformations & PNG_FILLER)
  164807. png_warning(png_ptr, "PNG_READ_FILLER_SUPPORTED is not defined.");
  164808. #endif
  164809. #if defined(PNG_WRITE_PACKSWAP_SUPPORTED) && !defined(PNG_READ_PACKSWAP_SUPPORTED)
  164810. if (png_ptr->transformations & PNG_PACKSWAP)
  164811. png_warning(png_ptr, "PNG_READ_PACKSWAP_SUPPORTED is not defined.");
  164812. #endif
  164813. #if defined(PNG_WRITE_PACK_SUPPORTED) && !defined(PNG_READ_PACK_SUPPORTED)
  164814. if (png_ptr->transformations & PNG_PACK)
  164815. png_warning(png_ptr, "PNG_READ_PACK_SUPPORTED is not defined.");
  164816. #endif
  164817. #if defined(PNG_WRITE_SHIFT_SUPPORTED) && !defined(PNG_READ_SHIFT_SUPPORTED)
  164818. if (png_ptr->transformations & PNG_SHIFT)
  164819. png_warning(png_ptr, "PNG_READ_SHIFT_SUPPORTED is not defined.");
  164820. #endif
  164821. #if defined(PNG_WRITE_BGR_SUPPORTED) && !defined(PNG_READ_BGR_SUPPORTED)
  164822. if (png_ptr->transformations & PNG_BGR)
  164823. png_warning(png_ptr, "PNG_READ_BGR_SUPPORTED is not defined.");
  164824. #endif
  164825. #if defined(PNG_WRITE_SWAP_SUPPORTED) && !defined(PNG_READ_SWAP_SUPPORTED)
  164826. if (png_ptr->transformations & PNG_SWAP_BYTES)
  164827. png_warning(png_ptr, "PNG_READ_SWAP_SUPPORTED is not defined.");
  164828. #endif
  164829. }
  164830. #if defined(PNG_READ_INTERLACING_SUPPORTED)
  164831. if (png_ptr->interlaced && (png_ptr->transformations & PNG_INTERLACE))
  164832. {
  164833. switch (png_ptr->pass)
  164834. {
  164835. case 0:
  164836. if (png_ptr->row_number & 0x07)
  164837. {
  164838. if (dsp_row != NULL)
  164839. png_combine_row(png_ptr, dsp_row,
  164840. png_pass_dsp_mask[png_ptr->pass]);
  164841. png_read_finish_row(png_ptr);
  164842. return;
  164843. }
  164844. break;
  164845. case 1:
  164846. if ((png_ptr->row_number & 0x07) || png_ptr->width < 5)
  164847. {
  164848. if (dsp_row != NULL)
  164849. png_combine_row(png_ptr, dsp_row,
  164850. png_pass_dsp_mask[png_ptr->pass]);
  164851. png_read_finish_row(png_ptr);
  164852. return;
  164853. }
  164854. break;
  164855. case 2:
  164856. if ((png_ptr->row_number & 0x07) != 4)
  164857. {
  164858. if (dsp_row != NULL && (png_ptr->row_number & 4))
  164859. png_combine_row(png_ptr, dsp_row,
  164860. png_pass_dsp_mask[png_ptr->pass]);
  164861. png_read_finish_row(png_ptr);
  164862. return;
  164863. }
  164864. break;
  164865. case 3:
  164866. if ((png_ptr->row_number & 3) || png_ptr->width < 3)
  164867. {
  164868. if (dsp_row != NULL)
  164869. png_combine_row(png_ptr, dsp_row,
  164870. png_pass_dsp_mask[png_ptr->pass]);
  164871. png_read_finish_row(png_ptr);
  164872. return;
  164873. }
  164874. break;
  164875. case 4:
  164876. if ((png_ptr->row_number & 3) != 2)
  164877. {
  164878. if (dsp_row != NULL && (png_ptr->row_number & 2))
  164879. png_combine_row(png_ptr, dsp_row,
  164880. png_pass_dsp_mask[png_ptr->pass]);
  164881. png_read_finish_row(png_ptr);
  164882. return;
  164883. }
  164884. break;
  164885. case 5:
  164886. if ((png_ptr->row_number & 1) || png_ptr->width < 2)
  164887. {
  164888. if (dsp_row != NULL)
  164889. png_combine_row(png_ptr, dsp_row,
  164890. png_pass_dsp_mask[png_ptr->pass]);
  164891. png_read_finish_row(png_ptr);
  164892. return;
  164893. }
  164894. break;
  164895. case 6:
  164896. if (!(png_ptr->row_number & 1))
  164897. {
  164898. png_read_finish_row(png_ptr);
  164899. return;
  164900. }
  164901. break;
  164902. }
  164903. }
  164904. #endif
  164905. if (!(png_ptr->mode & PNG_HAVE_IDAT))
  164906. png_error(png_ptr, "Invalid attempt to read row data");
  164907. png_ptr->zstream.next_out = png_ptr->row_buf;
  164908. png_ptr->zstream.avail_out = (uInt)png_ptr->irowbytes;
  164909. do
  164910. {
  164911. if (!(png_ptr->zstream.avail_in))
  164912. {
  164913. while (!png_ptr->idat_size)
  164914. {
  164915. png_byte chunk_length[4];
  164916. png_crc_finish(png_ptr, 0);
  164917. png_read_data(png_ptr, chunk_length, 4);
  164918. png_ptr->idat_size = png_get_uint_31(png_ptr,chunk_length);
  164919. png_reset_crc(png_ptr);
  164920. png_crc_read(png_ptr, png_ptr->chunk_name, 4);
  164921. if (png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  164922. png_error(png_ptr, "Not enough image data");
  164923. }
  164924. png_ptr->zstream.avail_in = (uInt)png_ptr->zbuf_size;
  164925. png_ptr->zstream.next_in = png_ptr->zbuf;
  164926. if (png_ptr->zbuf_size > png_ptr->idat_size)
  164927. png_ptr->zstream.avail_in = (uInt)png_ptr->idat_size;
  164928. png_crc_read(png_ptr, png_ptr->zbuf,
  164929. (png_size_t)png_ptr->zstream.avail_in);
  164930. png_ptr->idat_size -= png_ptr->zstream.avail_in;
  164931. }
  164932. ret = inflate(&png_ptr->zstream, Z_PARTIAL_FLUSH);
  164933. if (ret == Z_STREAM_END)
  164934. {
  164935. if (png_ptr->zstream.avail_out || png_ptr->zstream.avail_in ||
  164936. png_ptr->idat_size)
  164937. png_error(png_ptr, "Extra compressed data");
  164938. png_ptr->mode |= PNG_AFTER_IDAT;
  164939. png_ptr->flags |= PNG_FLAG_ZLIB_FINISHED;
  164940. break;
  164941. }
  164942. if (ret != Z_OK)
  164943. png_error(png_ptr, png_ptr->zstream.msg ? png_ptr->zstream.msg :
  164944. "Decompression error");
  164945. } while (png_ptr->zstream.avail_out);
  164946. png_ptr->row_info.color_type = png_ptr->color_type;
  164947. png_ptr->row_info.width = png_ptr->iwidth;
  164948. png_ptr->row_info.channels = png_ptr->channels;
  164949. png_ptr->row_info.bit_depth = png_ptr->bit_depth;
  164950. png_ptr->row_info.pixel_depth = png_ptr->pixel_depth;
  164951. png_ptr->row_info.rowbytes = PNG_ROWBYTES(png_ptr->row_info.pixel_depth,
  164952. png_ptr->row_info.width);
  164953. if(png_ptr->row_buf[0])
  164954. png_read_filter_row(png_ptr, &(png_ptr->row_info),
  164955. png_ptr->row_buf + 1, png_ptr->prev_row + 1,
  164956. (int)(png_ptr->row_buf[0]));
  164957. png_memcpy_check(png_ptr, png_ptr->prev_row, png_ptr->row_buf,
  164958. png_ptr->rowbytes + 1);
  164959. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  164960. if((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) &&
  164961. (png_ptr->filter_type == PNG_INTRAPIXEL_DIFFERENCING))
  164962. {
  164963. png_do_read_intrapixel(&(png_ptr->row_info), png_ptr->row_buf + 1);
  164964. }
  164965. #endif
  164966. if (png_ptr->transformations || (png_ptr->flags&PNG_FLAG_STRIP_ALPHA))
  164967. png_do_read_transformations(png_ptr);
  164968. #if defined(PNG_READ_INTERLACING_SUPPORTED)
  164969. if (png_ptr->interlaced &&
  164970. (png_ptr->transformations & PNG_INTERLACE))
  164971. {
  164972. if (png_ptr->pass < 6)
  164973. png_do_read_interlace(png_ptr);
  164974. if (dsp_row != NULL)
  164975. png_combine_row(png_ptr, dsp_row,
  164976. png_pass_dsp_mask[png_ptr->pass]);
  164977. if (row != NULL)
  164978. png_combine_row(png_ptr, row,
  164979. png_pass_mask[png_ptr->pass]);
  164980. }
  164981. else
  164982. #endif
  164983. {
  164984. if (row != NULL)
  164985. png_combine_row(png_ptr, row, 0xff);
  164986. if (dsp_row != NULL)
  164987. png_combine_row(png_ptr, dsp_row, 0xff);
  164988. }
  164989. png_read_finish_row(png_ptr);
  164990. if (png_ptr->read_row_fn != NULL)
  164991. (*(png_ptr->read_row_fn))(png_ptr, png_ptr->row_number, png_ptr->pass);
  164992. }
  164993. #endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */
  164994. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  164995. void PNGAPI
  164996. png_read_rows(png_structp png_ptr, png_bytepp row,
  164997. png_bytepp display_row, png_uint_32 num_rows)
  164998. {
  164999. png_uint_32 i;
  165000. png_bytepp rp;
  165001. png_bytepp dp;
  165002. png_debug(1, "in png_read_rows\n");
  165003. if(png_ptr == NULL) return;
  165004. rp = row;
  165005. dp = display_row;
  165006. if (rp != NULL && dp != NULL)
  165007. for (i = 0; i < num_rows; i++)
  165008. {
  165009. png_bytep rptr = *rp++;
  165010. png_bytep dptr = *dp++;
  165011. png_read_row(png_ptr, rptr, dptr);
  165012. }
  165013. else if(rp != NULL)
  165014. for (i = 0; i < num_rows; i++)
  165015. {
  165016. png_bytep rptr = *rp;
  165017. png_read_row(png_ptr, rptr, png_bytep_NULL);
  165018. rp++;
  165019. }
  165020. else if(dp != NULL)
  165021. for (i = 0; i < num_rows; i++)
  165022. {
  165023. png_bytep dptr = *dp;
  165024. png_read_row(png_ptr, png_bytep_NULL, dptr);
  165025. dp++;
  165026. }
  165027. }
  165028. #endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */
  165029. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  165030. void PNGAPI
  165031. png_read_image(png_structp png_ptr, png_bytepp image)
  165032. {
  165033. png_uint_32 i,image_height;
  165034. int pass, j;
  165035. png_bytepp rp;
  165036. png_debug(1, "in png_read_image\n");
  165037. if(png_ptr == NULL) return;
  165038. #ifdef PNG_READ_INTERLACING_SUPPORTED
  165039. pass = png_set_interlace_handling(png_ptr);
  165040. #else
  165041. if (png_ptr->interlaced)
  165042. png_error(png_ptr,
  165043. "Cannot read interlaced image -- interlace handler disabled.");
  165044. pass = 1;
  165045. #endif
  165046. image_height=png_ptr->height;
  165047. png_ptr->num_rows = image_height; /* Make sure this is set correctly */
  165048. for (j = 0; j < pass; j++)
  165049. {
  165050. rp = image;
  165051. for (i = 0; i < image_height; i++)
  165052. {
  165053. png_read_row(png_ptr, *rp, png_bytep_NULL);
  165054. rp++;
  165055. }
  165056. }
  165057. }
  165058. #endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */
  165059. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  165060. void PNGAPI
  165061. png_read_end(png_structp png_ptr, png_infop info_ptr)
  165062. {
  165063. png_byte chunk_length[4];
  165064. png_uint_32 length;
  165065. png_debug(1, "in png_read_end\n");
  165066. if(png_ptr == NULL) return;
  165067. png_crc_finish(png_ptr, 0); /* Finish off CRC from last IDAT chunk */
  165068. do
  165069. {
  165070. #ifdef PNG_USE_LOCAL_ARRAYS
  165071. PNG_CONST PNG_IHDR;
  165072. PNG_CONST PNG_IDAT;
  165073. PNG_CONST PNG_IEND;
  165074. PNG_CONST PNG_PLTE;
  165075. #if defined(PNG_READ_bKGD_SUPPORTED)
  165076. PNG_CONST PNG_bKGD;
  165077. #endif
  165078. #if defined(PNG_READ_cHRM_SUPPORTED)
  165079. PNG_CONST PNG_cHRM;
  165080. #endif
  165081. #if defined(PNG_READ_gAMA_SUPPORTED)
  165082. PNG_CONST PNG_gAMA;
  165083. #endif
  165084. #if defined(PNG_READ_hIST_SUPPORTED)
  165085. PNG_CONST PNG_hIST;
  165086. #endif
  165087. #if defined(PNG_READ_iCCP_SUPPORTED)
  165088. PNG_CONST PNG_iCCP;
  165089. #endif
  165090. #if defined(PNG_READ_iTXt_SUPPORTED)
  165091. PNG_CONST PNG_iTXt;
  165092. #endif
  165093. #if defined(PNG_READ_oFFs_SUPPORTED)
  165094. PNG_CONST PNG_oFFs;
  165095. #endif
  165096. #if defined(PNG_READ_pCAL_SUPPORTED)
  165097. PNG_CONST PNG_pCAL;
  165098. #endif
  165099. #if defined(PNG_READ_pHYs_SUPPORTED)
  165100. PNG_CONST PNG_pHYs;
  165101. #endif
  165102. #if defined(PNG_READ_sBIT_SUPPORTED)
  165103. PNG_CONST PNG_sBIT;
  165104. #endif
  165105. #if defined(PNG_READ_sCAL_SUPPORTED)
  165106. PNG_CONST PNG_sCAL;
  165107. #endif
  165108. #if defined(PNG_READ_sPLT_SUPPORTED)
  165109. PNG_CONST PNG_sPLT;
  165110. #endif
  165111. #if defined(PNG_READ_sRGB_SUPPORTED)
  165112. PNG_CONST PNG_sRGB;
  165113. #endif
  165114. #if defined(PNG_READ_tEXt_SUPPORTED)
  165115. PNG_CONST PNG_tEXt;
  165116. #endif
  165117. #if defined(PNG_READ_tIME_SUPPORTED)
  165118. PNG_CONST PNG_tIME;
  165119. #endif
  165120. #if defined(PNG_READ_tRNS_SUPPORTED)
  165121. PNG_CONST PNG_tRNS;
  165122. #endif
  165123. #if defined(PNG_READ_zTXt_SUPPORTED)
  165124. PNG_CONST PNG_zTXt;
  165125. #endif
  165126. #endif /* PNG_USE_LOCAL_ARRAYS */
  165127. png_read_data(png_ptr, chunk_length, 4);
  165128. length = png_get_uint_31(png_ptr,chunk_length);
  165129. png_reset_crc(png_ptr);
  165130. png_crc_read(png_ptr, png_ptr->chunk_name, 4);
  165131. png_debug1(0, "Reading %s chunk.\n", png_ptr->chunk_name);
  165132. if (!png_memcmp(png_ptr->chunk_name, png_IHDR, 4))
  165133. png_handle_IHDR(png_ptr, info_ptr, length);
  165134. else if (!png_memcmp(png_ptr->chunk_name, png_IEND, 4))
  165135. png_handle_IEND(png_ptr, info_ptr, length);
  165136. #ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
  165137. else if (png_handle_as_unknown(png_ptr, png_ptr->chunk_name))
  165138. {
  165139. if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  165140. {
  165141. if ((length > 0) || (png_ptr->mode & PNG_HAVE_CHUNK_AFTER_IDAT))
  165142. png_error(png_ptr, "Too many IDAT's found");
  165143. }
  165144. png_handle_unknown(png_ptr, info_ptr, length);
  165145. if (!png_memcmp(png_ptr->chunk_name, png_PLTE, 4))
  165146. png_ptr->mode |= PNG_HAVE_PLTE;
  165147. }
  165148. #endif
  165149. else if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  165150. {
  165151. if ((length > 0) || (png_ptr->mode & PNG_HAVE_CHUNK_AFTER_IDAT))
  165152. png_error(png_ptr, "Too many IDAT's found");
  165153. png_crc_finish(png_ptr, length);
  165154. }
  165155. else if (!png_memcmp(png_ptr->chunk_name, png_PLTE, 4))
  165156. png_handle_PLTE(png_ptr, info_ptr, length);
  165157. #if defined(PNG_READ_bKGD_SUPPORTED)
  165158. else if (!png_memcmp(png_ptr->chunk_name, png_bKGD, 4))
  165159. png_handle_bKGD(png_ptr, info_ptr, length);
  165160. #endif
  165161. #if defined(PNG_READ_cHRM_SUPPORTED)
  165162. else if (!png_memcmp(png_ptr->chunk_name, png_cHRM, 4))
  165163. png_handle_cHRM(png_ptr, info_ptr, length);
  165164. #endif
  165165. #if defined(PNG_READ_gAMA_SUPPORTED)
  165166. else if (!png_memcmp(png_ptr->chunk_name, png_gAMA, 4))
  165167. png_handle_gAMA(png_ptr, info_ptr, length);
  165168. #endif
  165169. #if defined(PNG_READ_hIST_SUPPORTED)
  165170. else if (!png_memcmp(png_ptr->chunk_name, png_hIST, 4))
  165171. png_handle_hIST(png_ptr, info_ptr, length);
  165172. #endif
  165173. #if defined(PNG_READ_oFFs_SUPPORTED)
  165174. else if (!png_memcmp(png_ptr->chunk_name, png_oFFs, 4))
  165175. png_handle_oFFs(png_ptr, info_ptr, length);
  165176. #endif
  165177. #if defined(PNG_READ_pCAL_SUPPORTED)
  165178. else if (!png_memcmp(png_ptr->chunk_name, png_pCAL, 4))
  165179. png_handle_pCAL(png_ptr, info_ptr, length);
  165180. #endif
  165181. #if defined(PNG_READ_sCAL_SUPPORTED)
  165182. else if (!png_memcmp(png_ptr->chunk_name, png_sCAL, 4))
  165183. png_handle_sCAL(png_ptr, info_ptr, length);
  165184. #endif
  165185. #if defined(PNG_READ_pHYs_SUPPORTED)
  165186. else if (!png_memcmp(png_ptr->chunk_name, png_pHYs, 4))
  165187. png_handle_pHYs(png_ptr, info_ptr, length);
  165188. #endif
  165189. #if defined(PNG_READ_sBIT_SUPPORTED)
  165190. else if (!png_memcmp(png_ptr->chunk_name, png_sBIT, 4))
  165191. png_handle_sBIT(png_ptr, info_ptr, length);
  165192. #endif
  165193. #if defined(PNG_READ_sRGB_SUPPORTED)
  165194. else if (!png_memcmp(png_ptr->chunk_name, png_sRGB, 4))
  165195. png_handle_sRGB(png_ptr, info_ptr, length);
  165196. #endif
  165197. #if defined(PNG_READ_iCCP_SUPPORTED)
  165198. else if (!png_memcmp(png_ptr->chunk_name, png_iCCP, 4))
  165199. png_handle_iCCP(png_ptr, info_ptr, length);
  165200. #endif
  165201. #if defined(PNG_READ_sPLT_SUPPORTED)
  165202. else if (!png_memcmp(png_ptr->chunk_name, png_sPLT, 4))
  165203. png_handle_sPLT(png_ptr, info_ptr, length);
  165204. #endif
  165205. #if defined(PNG_READ_tEXt_SUPPORTED)
  165206. else if (!png_memcmp(png_ptr->chunk_name, png_tEXt, 4))
  165207. png_handle_tEXt(png_ptr, info_ptr, length);
  165208. #endif
  165209. #if defined(PNG_READ_tIME_SUPPORTED)
  165210. else if (!png_memcmp(png_ptr->chunk_name, png_tIME, 4))
  165211. png_handle_tIME(png_ptr, info_ptr, length);
  165212. #endif
  165213. #if defined(PNG_READ_tRNS_SUPPORTED)
  165214. else if (!png_memcmp(png_ptr->chunk_name, png_tRNS, 4))
  165215. png_handle_tRNS(png_ptr, info_ptr, length);
  165216. #endif
  165217. #if defined(PNG_READ_zTXt_SUPPORTED)
  165218. else if (!png_memcmp(png_ptr->chunk_name, png_zTXt, 4))
  165219. png_handle_zTXt(png_ptr, info_ptr, length);
  165220. #endif
  165221. #if defined(PNG_READ_iTXt_SUPPORTED)
  165222. else if (!png_memcmp(png_ptr->chunk_name, png_iTXt, 4))
  165223. png_handle_iTXt(png_ptr, info_ptr, length);
  165224. #endif
  165225. else
  165226. png_handle_unknown(png_ptr, info_ptr, length);
  165227. } while (!(png_ptr->mode & PNG_HAVE_IEND));
  165228. }
  165229. #endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */
  165230. void PNGAPI
  165231. png_destroy_read_struct(png_structpp png_ptr_ptr, png_infopp info_ptr_ptr,
  165232. png_infopp end_info_ptr_ptr)
  165233. {
  165234. png_structp png_ptr = NULL;
  165235. png_infop info_ptr = NULL, end_info_ptr = NULL;
  165236. #ifdef PNG_USER_MEM_SUPPORTED
  165237. png_free_ptr free_fn;
  165238. png_voidp mem_ptr;
  165239. #endif
  165240. png_debug(1, "in png_destroy_read_struct\n");
  165241. if (png_ptr_ptr != NULL)
  165242. png_ptr = *png_ptr_ptr;
  165243. if (info_ptr_ptr != NULL)
  165244. info_ptr = *info_ptr_ptr;
  165245. if (end_info_ptr_ptr != NULL)
  165246. end_info_ptr = *end_info_ptr_ptr;
  165247. #ifdef PNG_USER_MEM_SUPPORTED
  165248. free_fn = png_ptr->free_fn;
  165249. mem_ptr = png_ptr->mem_ptr;
  165250. #endif
  165251. png_read_destroy(png_ptr, info_ptr, end_info_ptr);
  165252. if (info_ptr != NULL)
  165253. {
  165254. #if defined(PNG_TEXT_SUPPORTED)
  165255. png_free_data(png_ptr, info_ptr, PNG_FREE_TEXT, -1);
  165256. #endif
  165257. #ifdef PNG_USER_MEM_SUPPORTED
  165258. png_destroy_struct_2((png_voidp)info_ptr, (png_free_ptr)free_fn,
  165259. (png_voidp)mem_ptr);
  165260. #else
  165261. png_destroy_struct((png_voidp)info_ptr);
  165262. #endif
  165263. *info_ptr_ptr = NULL;
  165264. }
  165265. if (end_info_ptr != NULL)
  165266. {
  165267. #if defined(PNG_READ_TEXT_SUPPORTED)
  165268. png_free_data(png_ptr, end_info_ptr, PNG_FREE_TEXT, -1);
  165269. #endif
  165270. #ifdef PNG_USER_MEM_SUPPORTED
  165271. png_destroy_struct_2((png_voidp)end_info_ptr, (png_free_ptr)free_fn,
  165272. (png_voidp)mem_ptr);
  165273. #else
  165274. png_destroy_struct((png_voidp)end_info_ptr);
  165275. #endif
  165276. *end_info_ptr_ptr = NULL;
  165277. }
  165278. if (png_ptr != NULL)
  165279. {
  165280. #ifdef PNG_USER_MEM_SUPPORTED
  165281. png_destroy_struct_2((png_voidp)png_ptr, (png_free_ptr)free_fn,
  165282. (png_voidp)mem_ptr);
  165283. #else
  165284. png_destroy_struct((png_voidp)png_ptr);
  165285. #endif
  165286. *png_ptr_ptr = NULL;
  165287. }
  165288. }
  165289. void /* PRIVATE */
  165290. png_read_destroy(png_structp png_ptr, png_infop info_ptr, png_infop end_info_ptr)
  165291. {
  165292. #ifdef PNG_SETJMP_SUPPORTED
  165293. jmp_buf tmp_jmp;
  165294. #endif
  165295. png_error_ptr error_fn;
  165296. png_error_ptr warning_fn;
  165297. png_voidp error_ptr;
  165298. #ifdef PNG_USER_MEM_SUPPORTED
  165299. png_free_ptr free_fn;
  165300. #endif
  165301. png_debug(1, "in png_read_destroy\n");
  165302. if (info_ptr != NULL)
  165303. png_info_destroy(png_ptr, info_ptr);
  165304. if (end_info_ptr != NULL)
  165305. png_info_destroy(png_ptr, end_info_ptr);
  165306. png_free(png_ptr, png_ptr->zbuf);
  165307. png_free(png_ptr, png_ptr->big_row_buf);
  165308. png_free(png_ptr, png_ptr->prev_row);
  165309. #if defined(PNG_READ_DITHER_SUPPORTED)
  165310. png_free(png_ptr, png_ptr->palette_lookup);
  165311. png_free(png_ptr, png_ptr->dither_index);
  165312. #endif
  165313. #if defined(PNG_READ_GAMMA_SUPPORTED)
  165314. png_free(png_ptr, png_ptr->gamma_table);
  165315. #endif
  165316. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  165317. png_free(png_ptr, png_ptr->gamma_from_1);
  165318. png_free(png_ptr, png_ptr->gamma_to_1);
  165319. #endif
  165320. #ifdef PNG_FREE_ME_SUPPORTED
  165321. if (png_ptr->free_me & PNG_FREE_PLTE)
  165322. png_zfree(png_ptr, png_ptr->palette);
  165323. png_ptr->free_me &= ~PNG_FREE_PLTE;
  165324. #else
  165325. if (png_ptr->flags & PNG_FLAG_FREE_PLTE)
  165326. png_zfree(png_ptr, png_ptr->palette);
  165327. png_ptr->flags &= ~PNG_FLAG_FREE_PLTE;
  165328. #endif
  165329. #if defined(PNG_tRNS_SUPPORTED) || \
  165330. defined(PNG_READ_EXPAND_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
  165331. #ifdef PNG_FREE_ME_SUPPORTED
  165332. if (png_ptr->free_me & PNG_FREE_TRNS)
  165333. png_free(png_ptr, png_ptr->trans);
  165334. png_ptr->free_me &= ~PNG_FREE_TRNS;
  165335. #else
  165336. if (png_ptr->flags & PNG_FLAG_FREE_TRNS)
  165337. png_free(png_ptr, png_ptr->trans);
  165338. png_ptr->flags &= ~PNG_FLAG_FREE_TRNS;
  165339. #endif
  165340. #endif
  165341. #if defined(PNG_READ_hIST_SUPPORTED)
  165342. #ifdef PNG_FREE_ME_SUPPORTED
  165343. if (png_ptr->free_me & PNG_FREE_HIST)
  165344. png_free(png_ptr, png_ptr->hist);
  165345. png_ptr->free_me &= ~PNG_FREE_HIST;
  165346. #else
  165347. if (png_ptr->flags & PNG_FLAG_FREE_HIST)
  165348. png_free(png_ptr, png_ptr->hist);
  165349. png_ptr->flags &= ~PNG_FLAG_FREE_HIST;
  165350. #endif
  165351. #endif
  165352. #if defined(PNG_READ_GAMMA_SUPPORTED)
  165353. if (png_ptr->gamma_16_table != NULL)
  165354. {
  165355. int i;
  165356. int istop = (1 << (8 - png_ptr->gamma_shift));
  165357. for (i = 0; i < istop; i++)
  165358. {
  165359. png_free(png_ptr, png_ptr->gamma_16_table[i]);
  165360. }
  165361. png_free(png_ptr, png_ptr->gamma_16_table);
  165362. }
  165363. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  165364. if (png_ptr->gamma_16_from_1 != NULL)
  165365. {
  165366. int i;
  165367. int istop = (1 << (8 - png_ptr->gamma_shift));
  165368. for (i = 0; i < istop; i++)
  165369. {
  165370. png_free(png_ptr, png_ptr->gamma_16_from_1[i]);
  165371. }
  165372. png_free(png_ptr, png_ptr->gamma_16_from_1);
  165373. }
  165374. if (png_ptr->gamma_16_to_1 != NULL)
  165375. {
  165376. int i;
  165377. int istop = (1 << (8 - png_ptr->gamma_shift));
  165378. for (i = 0; i < istop; i++)
  165379. {
  165380. png_free(png_ptr, png_ptr->gamma_16_to_1[i]);
  165381. }
  165382. png_free(png_ptr, png_ptr->gamma_16_to_1);
  165383. }
  165384. #endif
  165385. #endif
  165386. #if defined(PNG_TIME_RFC1123_SUPPORTED)
  165387. png_free(png_ptr, png_ptr->time_buffer);
  165388. #endif
  165389. inflateEnd(&png_ptr->zstream);
  165390. #ifdef PNG_PROGRESSIVE_READ_SUPPORTED
  165391. png_free(png_ptr, png_ptr->save_buffer);
  165392. #endif
  165393. #ifdef PNG_PROGRESSIVE_READ_SUPPORTED
  165394. #ifdef PNG_TEXT_SUPPORTED
  165395. png_free(png_ptr, png_ptr->current_text);
  165396. #endif /* PNG_TEXT_SUPPORTED */
  165397. #endif /* PNG_PROGRESSIVE_READ_SUPPORTED */
  165398. #ifdef PNG_SETJMP_SUPPORTED
  165399. png_memcpy(tmp_jmp, png_ptr->jmpbuf, png_sizeof (jmp_buf));
  165400. #endif
  165401. error_fn = png_ptr->error_fn;
  165402. warning_fn = png_ptr->warning_fn;
  165403. error_ptr = png_ptr->error_ptr;
  165404. #ifdef PNG_USER_MEM_SUPPORTED
  165405. free_fn = png_ptr->free_fn;
  165406. #endif
  165407. png_memset(png_ptr, 0, png_sizeof (png_struct));
  165408. png_ptr->error_fn = error_fn;
  165409. png_ptr->warning_fn = warning_fn;
  165410. png_ptr->error_ptr = error_ptr;
  165411. #ifdef PNG_USER_MEM_SUPPORTED
  165412. png_ptr->free_fn = free_fn;
  165413. #endif
  165414. #ifdef PNG_SETJMP_SUPPORTED
  165415. png_memcpy(png_ptr->jmpbuf, tmp_jmp, png_sizeof (jmp_buf));
  165416. #endif
  165417. }
  165418. void PNGAPI
  165419. png_set_read_status_fn(png_structp png_ptr, png_read_status_ptr read_row_fn)
  165420. {
  165421. if(png_ptr == NULL) return;
  165422. png_ptr->read_row_fn = read_row_fn;
  165423. }
  165424. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  165425. #if defined(PNG_INFO_IMAGE_SUPPORTED)
  165426. void PNGAPI
  165427. png_read_png(png_structp png_ptr, png_infop info_ptr,
  165428. int transforms,
  165429. voidp params)
  165430. {
  165431. int row;
  165432. if(png_ptr == NULL) return;
  165433. #if defined(PNG_READ_INVERT_ALPHA_SUPPORTED)
  165434. if (transforms & PNG_TRANSFORM_INVERT_ALPHA)
  165435. png_set_invert_alpha(png_ptr);
  165436. #endif
  165437. png_read_info(png_ptr, info_ptr);
  165438. if (info_ptr->height > PNG_UINT_32_MAX/png_sizeof(png_bytep))
  165439. png_error(png_ptr,"Image is too high to process with png_read_png()");
  165440. #if defined(PNG_READ_16_TO_8_SUPPORTED)
  165441. if (transforms & PNG_TRANSFORM_STRIP_16)
  165442. png_set_strip_16(png_ptr);
  165443. #endif
  165444. #if defined(PNG_READ_STRIP_ALPHA_SUPPORTED)
  165445. if (transforms & PNG_TRANSFORM_STRIP_ALPHA)
  165446. png_set_strip_alpha(png_ptr);
  165447. #endif
  165448. #if defined(PNG_READ_PACK_SUPPORTED) && !defined(PNG_READ_EXPAND_SUPPORTED)
  165449. if (transforms & PNG_TRANSFORM_PACKING)
  165450. png_set_packing(png_ptr);
  165451. #endif
  165452. #if defined(PNG_READ_PACKSWAP_SUPPORTED)
  165453. if (transforms & PNG_TRANSFORM_PACKSWAP)
  165454. png_set_packswap(png_ptr);
  165455. #endif
  165456. #if defined(PNG_READ_EXPAND_SUPPORTED)
  165457. if (transforms & PNG_TRANSFORM_EXPAND)
  165458. if ((png_ptr->bit_depth < 8) ||
  165459. (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE) ||
  165460. (png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS)))
  165461. png_set_expand(png_ptr);
  165462. #endif
  165463. #if defined(PNG_READ_INVERT_SUPPORTED)
  165464. if (transforms & PNG_TRANSFORM_INVERT_MONO)
  165465. png_set_invert_mono(png_ptr);
  165466. #endif
  165467. #if defined(PNG_READ_SHIFT_SUPPORTED)
  165468. if ((transforms & PNG_TRANSFORM_SHIFT)
  165469. && png_get_valid(png_ptr, info_ptr, PNG_INFO_sBIT))
  165470. {
  165471. png_color_8p sig_bit;
  165472. png_get_sBIT(png_ptr, info_ptr, &sig_bit);
  165473. png_set_shift(png_ptr, sig_bit);
  165474. }
  165475. #endif
  165476. #if defined(PNG_READ_BGR_SUPPORTED)
  165477. if (transforms & PNG_TRANSFORM_BGR)
  165478. png_set_bgr(png_ptr);
  165479. #endif
  165480. #if defined(PNG_READ_SWAP_ALPHA_SUPPORTED)
  165481. if (transforms & PNG_TRANSFORM_SWAP_ALPHA)
  165482. png_set_swap_alpha(png_ptr);
  165483. #endif
  165484. #if defined(PNG_READ_SWAP_SUPPORTED)
  165485. if (transforms & PNG_TRANSFORM_SWAP_ENDIAN)
  165486. png_set_swap(png_ptr);
  165487. #endif
  165488. png_read_update_info(png_ptr, info_ptr);
  165489. #ifdef PNG_FREE_ME_SUPPORTED
  165490. png_free_data(png_ptr, info_ptr, PNG_FREE_ROWS, 0);
  165491. #endif
  165492. if(info_ptr->row_pointers == NULL)
  165493. {
  165494. info_ptr->row_pointers = (png_bytepp)png_malloc(png_ptr,
  165495. info_ptr->height * png_sizeof(png_bytep));
  165496. #ifdef PNG_FREE_ME_SUPPORTED
  165497. info_ptr->free_me |= PNG_FREE_ROWS;
  165498. #endif
  165499. for (row = 0; row < (int)info_ptr->height; row++)
  165500. {
  165501. info_ptr->row_pointers[row] = (png_bytep)png_malloc(png_ptr,
  165502. png_get_rowbytes(png_ptr, info_ptr));
  165503. }
  165504. }
  165505. png_read_image(png_ptr, info_ptr->row_pointers);
  165506. info_ptr->valid |= PNG_INFO_IDAT;
  165507. png_read_end(png_ptr, info_ptr);
  165508. transforms = transforms; /* quiet compiler warnings */
  165509. params = params;
  165510. }
  165511. #endif /* PNG_INFO_IMAGE_SUPPORTED */
  165512. #endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */
  165513. #endif /* PNG_READ_SUPPORTED */
  165514. /*** End of inlined file: pngread.c ***/
  165515. /*** Start of inlined file: pngpread.c ***/
  165516. #define PNG_INTERNAL
  165517. #ifdef PNG_PROGRESSIVE_READ_SUPPORTED
  165518. #define PNG_READ_SIG_MODE 0
  165519. #define PNG_READ_CHUNK_MODE 1
  165520. #define PNG_READ_IDAT_MODE 2
  165521. #define PNG_SKIP_MODE 3
  165522. #define PNG_READ_tEXt_MODE 4
  165523. #define PNG_READ_zTXt_MODE 5
  165524. #define PNG_READ_DONE_MODE 6
  165525. #define PNG_READ_iTXt_MODE 7
  165526. #define PNG_ERROR_MODE 8
  165527. void PNGAPI
  165528. png_process_data(png_structp png_ptr, png_infop info_ptr,
  165529. png_bytep buffer, png_size_t buffer_size)
  165530. {
  165531. if(png_ptr == NULL) return;
  165532. png_push_restore_buffer(png_ptr, buffer, buffer_size);
  165533. while (png_ptr->buffer_size)
  165534. {
  165535. png_process_some_data(png_ptr, info_ptr);
  165536. }
  165537. }
  165538. void /* PRIVATE */
  165539. png_process_some_data(png_structp png_ptr, png_infop info_ptr)
  165540. {
  165541. if(png_ptr == NULL) return;
  165542. switch (png_ptr->process_mode)
  165543. {
  165544. case PNG_READ_SIG_MODE:
  165545. {
  165546. png_push_read_sig(png_ptr, info_ptr);
  165547. break;
  165548. }
  165549. case PNG_READ_CHUNK_MODE:
  165550. {
  165551. png_push_read_chunk(png_ptr, info_ptr);
  165552. break;
  165553. }
  165554. case PNG_READ_IDAT_MODE:
  165555. {
  165556. png_push_read_IDAT(png_ptr);
  165557. break;
  165558. }
  165559. #if defined(PNG_READ_tEXt_SUPPORTED)
  165560. case PNG_READ_tEXt_MODE:
  165561. {
  165562. png_push_read_tEXt(png_ptr, info_ptr);
  165563. break;
  165564. }
  165565. #endif
  165566. #if defined(PNG_READ_zTXt_SUPPORTED)
  165567. case PNG_READ_zTXt_MODE:
  165568. {
  165569. png_push_read_zTXt(png_ptr, info_ptr);
  165570. break;
  165571. }
  165572. #endif
  165573. #if defined(PNG_READ_iTXt_SUPPORTED)
  165574. case PNG_READ_iTXt_MODE:
  165575. {
  165576. png_push_read_iTXt(png_ptr, info_ptr);
  165577. break;
  165578. }
  165579. #endif
  165580. case PNG_SKIP_MODE:
  165581. {
  165582. png_push_crc_finish(png_ptr);
  165583. break;
  165584. }
  165585. default:
  165586. {
  165587. png_ptr->buffer_size = 0;
  165588. break;
  165589. }
  165590. }
  165591. }
  165592. void /* PRIVATE */
  165593. png_push_read_sig(png_structp png_ptr, png_infop info_ptr)
  165594. {
  165595. png_size_t num_checked = png_ptr->sig_bytes,
  165596. num_to_check = 8 - num_checked;
  165597. if (png_ptr->buffer_size < num_to_check)
  165598. {
  165599. num_to_check = png_ptr->buffer_size;
  165600. }
  165601. png_push_fill_buffer(png_ptr, &(info_ptr->signature[num_checked]),
  165602. num_to_check);
  165603. png_ptr->sig_bytes = (png_byte)(png_ptr->sig_bytes+num_to_check);
  165604. if (png_sig_cmp(info_ptr->signature, num_checked, num_to_check))
  165605. {
  165606. if (num_checked < 4 &&
  165607. png_sig_cmp(info_ptr->signature, num_checked, num_to_check - 4))
  165608. png_error(png_ptr, "Not a PNG file");
  165609. else
  165610. png_error(png_ptr, "PNG file corrupted by ASCII conversion");
  165611. }
  165612. else
  165613. {
  165614. if (png_ptr->sig_bytes >= 8)
  165615. {
  165616. png_ptr->process_mode = PNG_READ_CHUNK_MODE;
  165617. }
  165618. }
  165619. }
  165620. void /* PRIVATE */
  165621. png_push_read_chunk(png_structp png_ptr, png_infop info_ptr)
  165622. {
  165623. #ifdef PNG_USE_LOCAL_ARRAYS
  165624. PNG_CONST PNG_IHDR;
  165625. PNG_CONST PNG_IDAT;
  165626. PNG_CONST PNG_IEND;
  165627. PNG_CONST PNG_PLTE;
  165628. #if defined(PNG_READ_bKGD_SUPPORTED)
  165629. PNG_CONST PNG_bKGD;
  165630. #endif
  165631. #if defined(PNG_READ_cHRM_SUPPORTED)
  165632. PNG_CONST PNG_cHRM;
  165633. #endif
  165634. #if defined(PNG_READ_gAMA_SUPPORTED)
  165635. PNG_CONST PNG_gAMA;
  165636. #endif
  165637. #if defined(PNG_READ_hIST_SUPPORTED)
  165638. PNG_CONST PNG_hIST;
  165639. #endif
  165640. #if defined(PNG_READ_iCCP_SUPPORTED)
  165641. PNG_CONST PNG_iCCP;
  165642. #endif
  165643. #if defined(PNG_READ_iTXt_SUPPORTED)
  165644. PNG_CONST PNG_iTXt;
  165645. #endif
  165646. #if defined(PNG_READ_oFFs_SUPPORTED)
  165647. PNG_CONST PNG_oFFs;
  165648. #endif
  165649. #if defined(PNG_READ_pCAL_SUPPORTED)
  165650. PNG_CONST PNG_pCAL;
  165651. #endif
  165652. #if defined(PNG_READ_pHYs_SUPPORTED)
  165653. PNG_CONST PNG_pHYs;
  165654. #endif
  165655. #if defined(PNG_READ_sBIT_SUPPORTED)
  165656. PNG_CONST PNG_sBIT;
  165657. #endif
  165658. #if defined(PNG_READ_sCAL_SUPPORTED)
  165659. PNG_CONST PNG_sCAL;
  165660. #endif
  165661. #if defined(PNG_READ_sRGB_SUPPORTED)
  165662. PNG_CONST PNG_sRGB;
  165663. #endif
  165664. #if defined(PNG_READ_sPLT_SUPPORTED)
  165665. PNG_CONST PNG_sPLT;
  165666. #endif
  165667. #if defined(PNG_READ_tEXt_SUPPORTED)
  165668. PNG_CONST PNG_tEXt;
  165669. #endif
  165670. #if defined(PNG_READ_tIME_SUPPORTED)
  165671. PNG_CONST PNG_tIME;
  165672. #endif
  165673. #if defined(PNG_READ_tRNS_SUPPORTED)
  165674. PNG_CONST PNG_tRNS;
  165675. #endif
  165676. #if defined(PNG_READ_zTXt_SUPPORTED)
  165677. PNG_CONST PNG_zTXt;
  165678. #endif
  165679. #endif /* PNG_USE_LOCAL_ARRAYS */
  165680. if (!(png_ptr->mode & PNG_HAVE_CHUNK_HEADER))
  165681. {
  165682. png_byte chunk_length[4];
  165683. if (png_ptr->buffer_size < 8)
  165684. {
  165685. png_push_save_buffer(png_ptr);
  165686. return;
  165687. }
  165688. png_push_fill_buffer(png_ptr, chunk_length, 4);
  165689. png_ptr->push_length = png_get_uint_31(png_ptr,chunk_length);
  165690. png_reset_crc(png_ptr);
  165691. png_crc_read(png_ptr, png_ptr->chunk_name, 4);
  165692. png_ptr->mode |= PNG_HAVE_CHUNK_HEADER;
  165693. }
  165694. if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  165695. if(png_ptr->mode & PNG_AFTER_IDAT)
  165696. png_ptr->mode |= PNG_HAVE_CHUNK_AFTER_IDAT;
  165697. if (!png_memcmp(png_ptr->chunk_name, png_IHDR, 4))
  165698. {
  165699. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  165700. {
  165701. png_push_save_buffer(png_ptr);
  165702. return;
  165703. }
  165704. png_handle_IHDR(png_ptr, info_ptr, png_ptr->push_length);
  165705. }
  165706. else if (!png_memcmp(png_ptr->chunk_name, png_IEND, 4))
  165707. {
  165708. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  165709. {
  165710. png_push_save_buffer(png_ptr);
  165711. return;
  165712. }
  165713. png_handle_IEND(png_ptr, info_ptr, png_ptr->push_length);
  165714. png_ptr->process_mode = PNG_READ_DONE_MODE;
  165715. png_push_have_end(png_ptr, info_ptr);
  165716. }
  165717. #ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
  165718. else if (png_handle_as_unknown(png_ptr, png_ptr->chunk_name))
  165719. {
  165720. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  165721. {
  165722. png_push_save_buffer(png_ptr);
  165723. return;
  165724. }
  165725. if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  165726. png_ptr->mode |= PNG_HAVE_IDAT;
  165727. png_handle_unknown(png_ptr, info_ptr, png_ptr->push_length);
  165728. if (!png_memcmp(png_ptr->chunk_name, png_PLTE, 4))
  165729. png_ptr->mode |= PNG_HAVE_PLTE;
  165730. else if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  165731. {
  165732. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  165733. png_error(png_ptr, "Missing IHDR before IDAT");
  165734. else if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE &&
  165735. !(png_ptr->mode & PNG_HAVE_PLTE))
  165736. png_error(png_ptr, "Missing PLTE before IDAT");
  165737. }
  165738. }
  165739. #endif
  165740. else if (!png_memcmp(png_ptr->chunk_name, png_PLTE, 4))
  165741. {
  165742. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  165743. {
  165744. png_push_save_buffer(png_ptr);
  165745. return;
  165746. }
  165747. png_handle_PLTE(png_ptr, info_ptr, png_ptr->push_length);
  165748. }
  165749. else if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  165750. {
  165751. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  165752. png_error(png_ptr, "Missing IHDR before IDAT");
  165753. else if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE &&
  165754. !(png_ptr->mode & PNG_HAVE_PLTE))
  165755. png_error(png_ptr, "Missing PLTE before IDAT");
  165756. if (png_ptr->mode & PNG_HAVE_IDAT)
  165757. {
  165758. if (!(png_ptr->mode & PNG_HAVE_CHUNK_AFTER_IDAT))
  165759. if (png_ptr->push_length == 0)
  165760. return;
  165761. if (png_ptr->mode & PNG_AFTER_IDAT)
  165762. png_error(png_ptr, "Too many IDAT's found");
  165763. }
  165764. png_ptr->idat_size = png_ptr->push_length;
  165765. png_ptr->mode |= PNG_HAVE_IDAT;
  165766. png_ptr->process_mode = PNG_READ_IDAT_MODE;
  165767. png_push_have_info(png_ptr, info_ptr);
  165768. png_ptr->zstream.avail_out = (uInt)png_ptr->irowbytes;
  165769. png_ptr->zstream.next_out = png_ptr->row_buf;
  165770. return;
  165771. }
  165772. #if defined(PNG_READ_gAMA_SUPPORTED)
  165773. else if (!png_memcmp(png_ptr->chunk_name, png_gAMA, 4))
  165774. {
  165775. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  165776. {
  165777. png_push_save_buffer(png_ptr);
  165778. return;
  165779. }
  165780. png_handle_gAMA(png_ptr, info_ptr, png_ptr->push_length);
  165781. }
  165782. #endif
  165783. #if defined(PNG_READ_sBIT_SUPPORTED)
  165784. else if (!png_memcmp(png_ptr->chunk_name, png_sBIT, 4))
  165785. {
  165786. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  165787. {
  165788. png_push_save_buffer(png_ptr);
  165789. return;
  165790. }
  165791. png_handle_sBIT(png_ptr, info_ptr, png_ptr->push_length);
  165792. }
  165793. #endif
  165794. #if defined(PNG_READ_cHRM_SUPPORTED)
  165795. else if (!png_memcmp(png_ptr->chunk_name, png_cHRM, 4))
  165796. {
  165797. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  165798. {
  165799. png_push_save_buffer(png_ptr);
  165800. return;
  165801. }
  165802. png_handle_cHRM(png_ptr, info_ptr, png_ptr->push_length);
  165803. }
  165804. #endif
  165805. #if defined(PNG_READ_sRGB_SUPPORTED)
  165806. else if (!png_memcmp(png_ptr->chunk_name, png_sRGB, 4))
  165807. {
  165808. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  165809. {
  165810. png_push_save_buffer(png_ptr);
  165811. return;
  165812. }
  165813. png_handle_sRGB(png_ptr, info_ptr, png_ptr->push_length);
  165814. }
  165815. #endif
  165816. #if defined(PNG_READ_iCCP_SUPPORTED)
  165817. else if (!png_memcmp(png_ptr->chunk_name, png_iCCP, 4))
  165818. {
  165819. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  165820. {
  165821. png_push_save_buffer(png_ptr);
  165822. return;
  165823. }
  165824. png_handle_iCCP(png_ptr, info_ptr, png_ptr->push_length);
  165825. }
  165826. #endif
  165827. #if defined(PNG_READ_sPLT_SUPPORTED)
  165828. else if (!png_memcmp(png_ptr->chunk_name, png_sPLT, 4))
  165829. {
  165830. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  165831. {
  165832. png_push_save_buffer(png_ptr);
  165833. return;
  165834. }
  165835. png_handle_sPLT(png_ptr, info_ptr, png_ptr->push_length);
  165836. }
  165837. #endif
  165838. #if defined(PNG_READ_tRNS_SUPPORTED)
  165839. else if (!png_memcmp(png_ptr->chunk_name, png_tRNS, 4))
  165840. {
  165841. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  165842. {
  165843. png_push_save_buffer(png_ptr);
  165844. return;
  165845. }
  165846. png_handle_tRNS(png_ptr, info_ptr, png_ptr->push_length);
  165847. }
  165848. #endif
  165849. #if defined(PNG_READ_bKGD_SUPPORTED)
  165850. else if (!png_memcmp(png_ptr->chunk_name, png_bKGD, 4))
  165851. {
  165852. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  165853. {
  165854. png_push_save_buffer(png_ptr);
  165855. return;
  165856. }
  165857. png_handle_bKGD(png_ptr, info_ptr, png_ptr->push_length);
  165858. }
  165859. #endif
  165860. #if defined(PNG_READ_hIST_SUPPORTED)
  165861. else if (!png_memcmp(png_ptr->chunk_name, png_hIST, 4))
  165862. {
  165863. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  165864. {
  165865. png_push_save_buffer(png_ptr);
  165866. return;
  165867. }
  165868. png_handle_hIST(png_ptr, info_ptr, png_ptr->push_length);
  165869. }
  165870. #endif
  165871. #if defined(PNG_READ_pHYs_SUPPORTED)
  165872. else if (!png_memcmp(png_ptr->chunk_name, png_pHYs, 4))
  165873. {
  165874. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  165875. {
  165876. png_push_save_buffer(png_ptr);
  165877. return;
  165878. }
  165879. png_handle_pHYs(png_ptr, info_ptr, png_ptr->push_length);
  165880. }
  165881. #endif
  165882. #if defined(PNG_READ_oFFs_SUPPORTED)
  165883. else if (!png_memcmp(png_ptr->chunk_name, png_oFFs, 4))
  165884. {
  165885. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  165886. {
  165887. png_push_save_buffer(png_ptr);
  165888. return;
  165889. }
  165890. png_handle_oFFs(png_ptr, info_ptr, png_ptr->push_length);
  165891. }
  165892. #endif
  165893. #if defined(PNG_READ_pCAL_SUPPORTED)
  165894. else if (!png_memcmp(png_ptr->chunk_name, png_pCAL, 4))
  165895. {
  165896. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  165897. {
  165898. png_push_save_buffer(png_ptr);
  165899. return;
  165900. }
  165901. png_handle_pCAL(png_ptr, info_ptr, png_ptr->push_length);
  165902. }
  165903. #endif
  165904. #if defined(PNG_READ_sCAL_SUPPORTED)
  165905. else if (!png_memcmp(png_ptr->chunk_name, png_sCAL, 4))
  165906. {
  165907. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  165908. {
  165909. png_push_save_buffer(png_ptr);
  165910. return;
  165911. }
  165912. png_handle_sCAL(png_ptr, info_ptr, png_ptr->push_length);
  165913. }
  165914. #endif
  165915. #if defined(PNG_READ_tIME_SUPPORTED)
  165916. else if (!png_memcmp(png_ptr->chunk_name, png_tIME, 4))
  165917. {
  165918. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  165919. {
  165920. png_push_save_buffer(png_ptr);
  165921. return;
  165922. }
  165923. png_handle_tIME(png_ptr, info_ptr, png_ptr->push_length);
  165924. }
  165925. #endif
  165926. #if defined(PNG_READ_tEXt_SUPPORTED)
  165927. else if (!png_memcmp(png_ptr->chunk_name, png_tEXt, 4))
  165928. {
  165929. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  165930. {
  165931. png_push_save_buffer(png_ptr);
  165932. return;
  165933. }
  165934. png_push_handle_tEXt(png_ptr, info_ptr, png_ptr->push_length);
  165935. }
  165936. #endif
  165937. #if defined(PNG_READ_zTXt_SUPPORTED)
  165938. else if (!png_memcmp(png_ptr->chunk_name, png_zTXt, 4))
  165939. {
  165940. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  165941. {
  165942. png_push_save_buffer(png_ptr);
  165943. return;
  165944. }
  165945. png_push_handle_zTXt(png_ptr, info_ptr, png_ptr->push_length);
  165946. }
  165947. #endif
  165948. #if defined(PNG_READ_iTXt_SUPPORTED)
  165949. else if (!png_memcmp(png_ptr->chunk_name, png_iTXt, 4))
  165950. {
  165951. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  165952. {
  165953. png_push_save_buffer(png_ptr);
  165954. return;
  165955. }
  165956. png_push_handle_iTXt(png_ptr, info_ptr, png_ptr->push_length);
  165957. }
  165958. #endif
  165959. else
  165960. {
  165961. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  165962. {
  165963. png_push_save_buffer(png_ptr);
  165964. return;
  165965. }
  165966. png_push_handle_unknown(png_ptr, info_ptr, png_ptr->push_length);
  165967. }
  165968. png_ptr->mode &= ~PNG_HAVE_CHUNK_HEADER;
  165969. }
  165970. void /* PRIVATE */
  165971. png_push_crc_skip(png_structp png_ptr, png_uint_32 skip)
  165972. {
  165973. png_ptr->process_mode = PNG_SKIP_MODE;
  165974. png_ptr->skip_length = skip;
  165975. }
  165976. void /* PRIVATE */
  165977. png_push_crc_finish(png_structp png_ptr)
  165978. {
  165979. if (png_ptr->skip_length && png_ptr->save_buffer_size)
  165980. {
  165981. png_size_t save_size;
  165982. if (png_ptr->skip_length < (png_uint_32)png_ptr->save_buffer_size)
  165983. save_size = (png_size_t)png_ptr->skip_length;
  165984. else
  165985. save_size = png_ptr->save_buffer_size;
  165986. png_calculate_crc(png_ptr, png_ptr->save_buffer_ptr, save_size);
  165987. png_ptr->skip_length -= save_size;
  165988. png_ptr->buffer_size -= save_size;
  165989. png_ptr->save_buffer_size -= save_size;
  165990. png_ptr->save_buffer_ptr += save_size;
  165991. }
  165992. if (png_ptr->skip_length && png_ptr->current_buffer_size)
  165993. {
  165994. png_size_t save_size;
  165995. if (png_ptr->skip_length < (png_uint_32)png_ptr->current_buffer_size)
  165996. save_size = (png_size_t)png_ptr->skip_length;
  165997. else
  165998. save_size = png_ptr->current_buffer_size;
  165999. png_calculate_crc(png_ptr, png_ptr->current_buffer_ptr, save_size);
  166000. png_ptr->skip_length -= save_size;
  166001. png_ptr->buffer_size -= save_size;
  166002. png_ptr->current_buffer_size -= save_size;
  166003. png_ptr->current_buffer_ptr += save_size;
  166004. }
  166005. if (!png_ptr->skip_length)
  166006. {
  166007. if (png_ptr->buffer_size < 4)
  166008. {
  166009. png_push_save_buffer(png_ptr);
  166010. return;
  166011. }
  166012. png_crc_finish(png_ptr, 0);
  166013. png_ptr->process_mode = PNG_READ_CHUNK_MODE;
  166014. }
  166015. }
  166016. void PNGAPI
  166017. png_push_fill_buffer(png_structp png_ptr, png_bytep buffer, png_size_t length)
  166018. {
  166019. png_bytep ptr;
  166020. if(png_ptr == NULL) return;
  166021. ptr = buffer;
  166022. if (png_ptr->save_buffer_size)
  166023. {
  166024. png_size_t save_size;
  166025. if (length < png_ptr->save_buffer_size)
  166026. save_size = length;
  166027. else
  166028. save_size = png_ptr->save_buffer_size;
  166029. png_memcpy(ptr, png_ptr->save_buffer_ptr, save_size);
  166030. length -= save_size;
  166031. ptr += save_size;
  166032. png_ptr->buffer_size -= save_size;
  166033. png_ptr->save_buffer_size -= save_size;
  166034. png_ptr->save_buffer_ptr += save_size;
  166035. }
  166036. if (length && png_ptr->current_buffer_size)
  166037. {
  166038. png_size_t save_size;
  166039. if (length < png_ptr->current_buffer_size)
  166040. save_size = length;
  166041. else
  166042. save_size = png_ptr->current_buffer_size;
  166043. png_memcpy(ptr, png_ptr->current_buffer_ptr, save_size);
  166044. png_ptr->buffer_size -= save_size;
  166045. png_ptr->current_buffer_size -= save_size;
  166046. png_ptr->current_buffer_ptr += save_size;
  166047. }
  166048. }
  166049. void /* PRIVATE */
  166050. png_push_save_buffer(png_structp png_ptr)
  166051. {
  166052. if (png_ptr->save_buffer_size)
  166053. {
  166054. if (png_ptr->save_buffer_ptr != png_ptr->save_buffer)
  166055. {
  166056. png_size_t i,istop;
  166057. png_bytep sp;
  166058. png_bytep dp;
  166059. istop = png_ptr->save_buffer_size;
  166060. for (i = 0, sp = png_ptr->save_buffer_ptr, dp = png_ptr->save_buffer;
  166061. i < istop; i++, sp++, dp++)
  166062. {
  166063. *dp = *sp;
  166064. }
  166065. }
  166066. }
  166067. if (png_ptr->save_buffer_size + png_ptr->current_buffer_size >
  166068. png_ptr->save_buffer_max)
  166069. {
  166070. png_size_t new_max;
  166071. png_bytep old_buffer;
  166072. if (png_ptr->save_buffer_size > PNG_SIZE_MAX -
  166073. (png_ptr->current_buffer_size + 256))
  166074. {
  166075. png_error(png_ptr, "Potential overflow of save_buffer");
  166076. }
  166077. new_max = png_ptr->save_buffer_size + png_ptr->current_buffer_size + 256;
  166078. old_buffer = png_ptr->save_buffer;
  166079. png_ptr->save_buffer = (png_bytep)png_malloc(png_ptr,
  166080. (png_uint_32)new_max);
  166081. png_memcpy(png_ptr->save_buffer, old_buffer, png_ptr->save_buffer_size);
  166082. png_free(png_ptr, old_buffer);
  166083. png_ptr->save_buffer_max = new_max;
  166084. }
  166085. if (png_ptr->current_buffer_size)
  166086. {
  166087. png_memcpy(png_ptr->save_buffer + png_ptr->save_buffer_size,
  166088. png_ptr->current_buffer_ptr, png_ptr->current_buffer_size);
  166089. png_ptr->save_buffer_size += png_ptr->current_buffer_size;
  166090. png_ptr->current_buffer_size = 0;
  166091. }
  166092. png_ptr->save_buffer_ptr = png_ptr->save_buffer;
  166093. png_ptr->buffer_size = 0;
  166094. }
  166095. void /* PRIVATE */
  166096. png_push_restore_buffer(png_structp png_ptr, png_bytep buffer,
  166097. png_size_t buffer_length)
  166098. {
  166099. png_ptr->current_buffer = buffer;
  166100. png_ptr->current_buffer_size = buffer_length;
  166101. png_ptr->buffer_size = buffer_length + png_ptr->save_buffer_size;
  166102. png_ptr->current_buffer_ptr = png_ptr->current_buffer;
  166103. }
  166104. void /* PRIVATE */
  166105. png_push_read_IDAT(png_structp png_ptr)
  166106. {
  166107. #ifdef PNG_USE_LOCAL_ARRAYS
  166108. PNG_CONST PNG_IDAT;
  166109. #endif
  166110. if (!(png_ptr->mode & PNG_HAVE_CHUNK_HEADER))
  166111. {
  166112. png_byte chunk_length[4];
  166113. if (png_ptr->buffer_size < 8)
  166114. {
  166115. png_push_save_buffer(png_ptr);
  166116. return;
  166117. }
  166118. png_push_fill_buffer(png_ptr, chunk_length, 4);
  166119. png_ptr->push_length = png_get_uint_31(png_ptr,chunk_length);
  166120. png_reset_crc(png_ptr);
  166121. png_crc_read(png_ptr, png_ptr->chunk_name, 4);
  166122. png_ptr->mode |= PNG_HAVE_CHUNK_HEADER;
  166123. if (png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  166124. {
  166125. png_ptr->process_mode = PNG_READ_CHUNK_MODE;
  166126. if (!(png_ptr->flags & PNG_FLAG_ZLIB_FINISHED))
  166127. png_error(png_ptr, "Not enough compressed data");
  166128. return;
  166129. }
  166130. png_ptr->idat_size = png_ptr->push_length;
  166131. }
  166132. if (png_ptr->idat_size && png_ptr->save_buffer_size)
  166133. {
  166134. png_size_t save_size;
  166135. if (png_ptr->idat_size < (png_uint_32)png_ptr->save_buffer_size)
  166136. {
  166137. save_size = (png_size_t)png_ptr->idat_size;
  166138. if((png_uint_32)save_size != png_ptr->idat_size)
  166139. png_error(png_ptr, "save_size overflowed in pngpread");
  166140. }
  166141. else
  166142. save_size = png_ptr->save_buffer_size;
  166143. png_calculate_crc(png_ptr, png_ptr->save_buffer_ptr, save_size);
  166144. if (!(png_ptr->flags & PNG_FLAG_ZLIB_FINISHED))
  166145. png_process_IDAT_data(png_ptr, png_ptr->save_buffer_ptr, save_size);
  166146. png_ptr->idat_size -= save_size;
  166147. png_ptr->buffer_size -= save_size;
  166148. png_ptr->save_buffer_size -= save_size;
  166149. png_ptr->save_buffer_ptr += save_size;
  166150. }
  166151. if (png_ptr->idat_size && png_ptr->current_buffer_size)
  166152. {
  166153. png_size_t save_size;
  166154. if (png_ptr->idat_size < (png_uint_32)png_ptr->current_buffer_size)
  166155. {
  166156. save_size = (png_size_t)png_ptr->idat_size;
  166157. if((png_uint_32)save_size != png_ptr->idat_size)
  166158. png_error(png_ptr, "save_size overflowed in pngpread");
  166159. }
  166160. else
  166161. save_size = png_ptr->current_buffer_size;
  166162. png_calculate_crc(png_ptr, png_ptr->current_buffer_ptr, save_size);
  166163. if (!(png_ptr->flags & PNG_FLAG_ZLIB_FINISHED))
  166164. png_process_IDAT_data(png_ptr, png_ptr->current_buffer_ptr, save_size);
  166165. png_ptr->idat_size -= save_size;
  166166. png_ptr->buffer_size -= save_size;
  166167. png_ptr->current_buffer_size -= save_size;
  166168. png_ptr->current_buffer_ptr += save_size;
  166169. }
  166170. if (!png_ptr->idat_size)
  166171. {
  166172. if (png_ptr->buffer_size < 4)
  166173. {
  166174. png_push_save_buffer(png_ptr);
  166175. return;
  166176. }
  166177. png_crc_finish(png_ptr, 0);
  166178. png_ptr->mode &= ~PNG_HAVE_CHUNK_HEADER;
  166179. png_ptr->mode |= PNG_AFTER_IDAT;
  166180. }
  166181. }
  166182. void /* PRIVATE */
  166183. png_process_IDAT_data(png_structp png_ptr, png_bytep buffer,
  166184. png_size_t buffer_length)
  166185. {
  166186. int ret;
  166187. if ((png_ptr->flags & PNG_FLAG_ZLIB_FINISHED) && buffer_length)
  166188. png_error(png_ptr, "Extra compression data");
  166189. png_ptr->zstream.next_in = buffer;
  166190. png_ptr->zstream.avail_in = (uInt)buffer_length;
  166191. for(;;)
  166192. {
  166193. ret = inflate(&png_ptr->zstream, Z_PARTIAL_FLUSH);
  166194. if (ret != Z_OK)
  166195. {
  166196. if (ret == Z_STREAM_END)
  166197. {
  166198. if (png_ptr->zstream.avail_in)
  166199. png_error(png_ptr, "Extra compressed data");
  166200. if (!(png_ptr->zstream.avail_out))
  166201. {
  166202. png_push_process_row(png_ptr);
  166203. }
  166204. png_ptr->mode |= PNG_AFTER_IDAT;
  166205. png_ptr->flags |= PNG_FLAG_ZLIB_FINISHED;
  166206. break;
  166207. }
  166208. else if (ret == Z_BUF_ERROR)
  166209. break;
  166210. else
  166211. png_error(png_ptr, "Decompression Error");
  166212. }
  166213. if (!(png_ptr->zstream.avail_out))
  166214. {
  166215. if ((
  166216. #if defined(PNG_READ_INTERLACING_SUPPORTED)
  166217. png_ptr->interlaced && png_ptr->pass > 6) ||
  166218. (!png_ptr->interlaced &&
  166219. #endif
  166220. png_ptr->row_number == png_ptr->num_rows))
  166221. {
  166222. if (png_ptr->zstream.avail_in)
  166223. {
  166224. png_warning(png_ptr, "Too much data in IDAT chunks");
  166225. }
  166226. png_ptr->flags |= PNG_FLAG_ZLIB_FINISHED;
  166227. break;
  166228. }
  166229. png_push_process_row(png_ptr);
  166230. png_ptr->zstream.avail_out = (uInt)png_ptr->irowbytes;
  166231. png_ptr->zstream.next_out = png_ptr->row_buf;
  166232. }
  166233. else
  166234. break;
  166235. }
  166236. }
  166237. void /* PRIVATE */
  166238. png_push_process_row(png_structp png_ptr)
  166239. {
  166240. png_ptr->row_info.color_type = png_ptr->color_type;
  166241. png_ptr->row_info.width = png_ptr->iwidth;
  166242. png_ptr->row_info.channels = png_ptr->channels;
  166243. png_ptr->row_info.bit_depth = png_ptr->bit_depth;
  166244. png_ptr->row_info.pixel_depth = png_ptr->pixel_depth;
  166245. png_ptr->row_info.rowbytes = PNG_ROWBYTES(png_ptr->row_info.pixel_depth,
  166246. png_ptr->row_info.width);
  166247. png_read_filter_row(png_ptr, &(png_ptr->row_info),
  166248. png_ptr->row_buf + 1, png_ptr->prev_row + 1,
  166249. (int)(png_ptr->row_buf[0]));
  166250. png_memcpy_check(png_ptr, png_ptr->prev_row, png_ptr->row_buf,
  166251. png_ptr->rowbytes + 1);
  166252. if (png_ptr->transformations || (png_ptr->flags&PNG_FLAG_STRIP_ALPHA))
  166253. png_do_read_transformations(png_ptr);
  166254. #if defined(PNG_READ_INTERLACING_SUPPORTED)
  166255. if (png_ptr->interlaced && (png_ptr->transformations & PNG_INTERLACE))
  166256. {
  166257. if (png_ptr->pass < 6)
  166258. png_do_read_interlace(png_ptr);
  166259. switch (png_ptr->pass)
  166260. {
  166261. case 0:
  166262. {
  166263. int i;
  166264. for (i = 0; i < 8 && png_ptr->pass == 0; i++)
  166265. {
  166266. png_push_have_row(png_ptr, png_ptr->row_buf + 1);
  166267. png_read_push_finish_row(png_ptr); /* updates png_ptr->pass */
  166268. }
  166269. if (png_ptr->pass == 2) /* pass 1 might be empty */
  166270. {
  166271. for (i = 0; i < 4 && png_ptr->pass == 2; i++)
  166272. {
  166273. png_push_have_row(png_ptr, png_bytep_NULL);
  166274. png_read_push_finish_row(png_ptr);
  166275. }
  166276. }
  166277. if (png_ptr->pass == 4 && png_ptr->height <= 4)
  166278. {
  166279. for (i = 0; i < 2 && png_ptr->pass == 4; i++)
  166280. {
  166281. png_push_have_row(png_ptr, png_bytep_NULL);
  166282. png_read_push_finish_row(png_ptr);
  166283. }
  166284. }
  166285. if (png_ptr->pass == 6 && png_ptr->height <= 4)
  166286. {
  166287. png_push_have_row(png_ptr, png_bytep_NULL);
  166288. png_read_push_finish_row(png_ptr);
  166289. }
  166290. break;
  166291. }
  166292. case 1:
  166293. {
  166294. int i;
  166295. for (i = 0; i < 8 && png_ptr->pass == 1; i++)
  166296. {
  166297. png_push_have_row(png_ptr, png_ptr->row_buf + 1);
  166298. png_read_push_finish_row(png_ptr);
  166299. }
  166300. if (png_ptr->pass == 2) /* skip top 4 generated rows */
  166301. {
  166302. for (i = 0; i < 4 && png_ptr->pass == 2; i++)
  166303. {
  166304. png_push_have_row(png_ptr, png_bytep_NULL);
  166305. png_read_push_finish_row(png_ptr);
  166306. }
  166307. }
  166308. break;
  166309. }
  166310. case 2:
  166311. {
  166312. int i;
  166313. for (i = 0; i < 4 && png_ptr->pass == 2; i++)
  166314. {
  166315. png_push_have_row(png_ptr, png_ptr->row_buf + 1);
  166316. png_read_push_finish_row(png_ptr);
  166317. }
  166318. for (i = 0; i < 4 && png_ptr->pass == 2; i++)
  166319. {
  166320. png_push_have_row(png_ptr, png_bytep_NULL);
  166321. png_read_push_finish_row(png_ptr);
  166322. }
  166323. if (png_ptr->pass == 4) /* pass 3 might be empty */
  166324. {
  166325. for (i = 0; i < 2 && png_ptr->pass == 4; i++)
  166326. {
  166327. png_push_have_row(png_ptr, png_bytep_NULL);
  166328. png_read_push_finish_row(png_ptr);
  166329. }
  166330. }
  166331. break;
  166332. }
  166333. case 3:
  166334. {
  166335. int i;
  166336. for (i = 0; i < 4 && png_ptr->pass == 3; i++)
  166337. {
  166338. png_push_have_row(png_ptr, png_ptr->row_buf + 1);
  166339. png_read_push_finish_row(png_ptr);
  166340. }
  166341. if (png_ptr->pass == 4) /* skip top two generated rows */
  166342. {
  166343. for (i = 0; i < 2 && png_ptr->pass == 4; i++)
  166344. {
  166345. png_push_have_row(png_ptr, png_bytep_NULL);
  166346. png_read_push_finish_row(png_ptr);
  166347. }
  166348. }
  166349. break;
  166350. }
  166351. case 4:
  166352. {
  166353. int i;
  166354. for (i = 0; i < 2 && png_ptr->pass == 4; i++)
  166355. {
  166356. png_push_have_row(png_ptr, png_ptr->row_buf + 1);
  166357. png_read_push_finish_row(png_ptr);
  166358. }
  166359. for (i = 0; i < 2 && png_ptr->pass == 4; i++)
  166360. {
  166361. png_push_have_row(png_ptr, png_bytep_NULL);
  166362. png_read_push_finish_row(png_ptr);
  166363. }
  166364. if (png_ptr->pass == 6) /* pass 5 might be empty */
  166365. {
  166366. png_push_have_row(png_ptr, png_bytep_NULL);
  166367. png_read_push_finish_row(png_ptr);
  166368. }
  166369. break;
  166370. }
  166371. case 5:
  166372. {
  166373. int i;
  166374. for (i = 0; i < 2 && png_ptr->pass == 5; i++)
  166375. {
  166376. png_push_have_row(png_ptr, png_ptr->row_buf + 1);
  166377. png_read_push_finish_row(png_ptr);
  166378. }
  166379. if (png_ptr->pass == 6) /* skip top generated row */
  166380. {
  166381. png_push_have_row(png_ptr, png_bytep_NULL);
  166382. png_read_push_finish_row(png_ptr);
  166383. }
  166384. break;
  166385. }
  166386. case 6:
  166387. {
  166388. png_push_have_row(png_ptr, png_ptr->row_buf + 1);
  166389. png_read_push_finish_row(png_ptr);
  166390. if (png_ptr->pass != 6)
  166391. break;
  166392. png_push_have_row(png_ptr, png_bytep_NULL);
  166393. png_read_push_finish_row(png_ptr);
  166394. }
  166395. }
  166396. }
  166397. else
  166398. #endif
  166399. {
  166400. png_push_have_row(png_ptr, png_ptr->row_buf + 1);
  166401. png_read_push_finish_row(png_ptr);
  166402. }
  166403. }
  166404. void /* PRIVATE */
  166405. png_read_push_finish_row(png_structp png_ptr)
  166406. {
  166407. #ifdef PNG_USE_LOCAL_ARRAYS
  166408. PNG_CONST int FARDATA png_pass_start[] = {0, 4, 0, 2, 0, 1, 0};
  166409. PNG_CONST int FARDATA png_pass_inc[] = {8, 8, 4, 4, 2, 2, 1};
  166410. PNG_CONST int FARDATA png_pass_ystart[] = {0, 0, 4, 0, 2, 0, 1};
  166411. PNG_CONST int FARDATA png_pass_yinc[] = {8, 8, 8, 4, 4, 2, 2};
  166412. #endif
  166413. png_ptr->row_number++;
  166414. if (png_ptr->row_number < png_ptr->num_rows)
  166415. return;
  166416. if (png_ptr->interlaced)
  166417. {
  166418. png_ptr->row_number = 0;
  166419. png_memset_check(png_ptr, png_ptr->prev_row, 0,
  166420. png_ptr->rowbytes + 1);
  166421. do
  166422. {
  166423. png_ptr->pass++;
  166424. if ((png_ptr->pass == 1 && png_ptr->width < 5) ||
  166425. (png_ptr->pass == 3 && png_ptr->width < 3) ||
  166426. (png_ptr->pass == 5 && png_ptr->width < 2))
  166427. png_ptr->pass++;
  166428. if (png_ptr->pass > 7)
  166429. png_ptr->pass--;
  166430. if (png_ptr->pass >= 7)
  166431. break;
  166432. png_ptr->iwidth = (png_ptr->width +
  166433. png_pass_inc[png_ptr->pass] - 1 -
  166434. png_pass_start[png_ptr->pass]) /
  166435. png_pass_inc[png_ptr->pass];
  166436. png_ptr->irowbytes = PNG_ROWBYTES(png_ptr->pixel_depth,
  166437. png_ptr->iwidth) + 1;
  166438. if (png_ptr->transformations & PNG_INTERLACE)
  166439. break;
  166440. png_ptr->num_rows = (png_ptr->height +
  166441. png_pass_yinc[png_ptr->pass] - 1 -
  166442. png_pass_ystart[png_ptr->pass]) /
  166443. png_pass_yinc[png_ptr->pass];
  166444. } while (png_ptr->iwidth == 0 || png_ptr->num_rows == 0);
  166445. }
  166446. }
  166447. #if defined(PNG_READ_tEXt_SUPPORTED)
  166448. void /* PRIVATE */
  166449. png_push_handle_tEXt(png_structp png_ptr, png_infop info_ptr, png_uint_32
  166450. length)
  166451. {
  166452. if (!(png_ptr->mode & PNG_HAVE_IHDR) || (png_ptr->mode & PNG_HAVE_IEND))
  166453. {
  166454. png_error(png_ptr, "Out of place tEXt");
  166455. info_ptr = info_ptr; /* to quiet some compiler warnings */
  166456. }
  166457. #ifdef PNG_MAX_MALLOC_64K
  166458. png_ptr->skip_length = 0; /* This may not be necessary */
  166459. if (length > (png_uint_32)65535L) /* Can't hold entire string in memory */
  166460. {
  166461. png_warning(png_ptr, "tEXt chunk too large to fit in memory");
  166462. png_ptr->skip_length = length - (png_uint_32)65535L;
  166463. length = (png_uint_32)65535L;
  166464. }
  166465. #endif
  166466. png_ptr->current_text = (png_charp)png_malloc(png_ptr,
  166467. (png_uint_32)(length+1));
  166468. png_ptr->current_text[length] = '\0';
  166469. png_ptr->current_text_ptr = png_ptr->current_text;
  166470. png_ptr->current_text_size = (png_size_t)length;
  166471. png_ptr->current_text_left = (png_size_t)length;
  166472. png_ptr->process_mode = PNG_READ_tEXt_MODE;
  166473. }
  166474. void /* PRIVATE */
  166475. png_push_read_tEXt(png_structp png_ptr, png_infop info_ptr)
  166476. {
  166477. if (png_ptr->buffer_size && png_ptr->current_text_left)
  166478. {
  166479. png_size_t text_size;
  166480. if (png_ptr->buffer_size < png_ptr->current_text_left)
  166481. text_size = png_ptr->buffer_size;
  166482. else
  166483. text_size = png_ptr->current_text_left;
  166484. png_crc_read(png_ptr, (png_bytep)png_ptr->current_text_ptr, text_size);
  166485. png_ptr->current_text_left -= text_size;
  166486. png_ptr->current_text_ptr += text_size;
  166487. }
  166488. if (!(png_ptr->current_text_left))
  166489. {
  166490. png_textp text_ptr;
  166491. png_charp text;
  166492. png_charp key;
  166493. int ret;
  166494. if (png_ptr->buffer_size < 4)
  166495. {
  166496. png_push_save_buffer(png_ptr);
  166497. return;
  166498. }
  166499. png_push_crc_finish(png_ptr);
  166500. #if defined(PNG_MAX_MALLOC_64K)
  166501. if (png_ptr->skip_length)
  166502. return;
  166503. #endif
  166504. key = png_ptr->current_text;
  166505. for (text = key; *text; text++)
  166506. ;
  166507. if (text < key + png_ptr->current_text_size)
  166508. text++;
  166509. text_ptr = (png_textp)png_malloc(png_ptr,
  166510. (png_uint_32)png_sizeof(png_text));
  166511. text_ptr->compression = PNG_TEXT_COMPRESSION_NONE;
  166512. text_ptr->key = key;
  166513. #ifdef PNG_iTXt_SUPPORTED
  166514. text_ptr->lang = NULL;
  166515. text_ptr->lang_key = NULL;
  166516. #endif
  166517. text_ptr->text = text;
  166518. ret = png_set_text_2(png_ptr, info_ptr, text_ptr, 1);
  166519. png_free(png_ptr, key);
  166520. png_free(png_ptr, text_ptr);
  166521. png_ptr->current_text = NULL;
  166522. if (ret)
  166523. png_warning(png_ptr, "Insufficient memory to store text chunk.");
  166524. }
  166525. }
  166526. #endif
  166527. #if defined(PNG_READ_zTXt_SUPPORTED)
  166528. void /* PRIVATE */
  166529. png_push_handle_zTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32
  166530. length)
  166531. {
  166532. if (!(png_ptr->mode & PNG_HAVE_IHDR) || (png_ptr->mode & PNG_HAVE_IEND))
  166533. {
  166534. png_error(png_ptr, "Out of place zTXt");
  166535. info_ptr = info_ptr; /* to quiet some compiler warnings */
  166536. }
  166537. #ifdef PNG_MAX_MALLOC_64K
  166538. if (length > (png_uint_32)65535L)
  166539. {
  166540. png_warning(png_ptr, "zTXt chunk too large to fit in memory");
  166541. png_push_crc_skip(png_ptr, length);
  166542. return;
  166543. }
  166544. #endif
  166545. png_ptr->current_text = (png_charp)png_malloc(png_ptr,
  166546. (png_uint_32)(length+1));
  166547. png_ptr->current_text[length] = '\0';
  166548. png_ptr->current_text_ptr = png_ptr->current_text;
  166549. png_ptr->current_text_size = (png_size_t)length;
  166550. png_ptr->current_text_left = (png_size_t)length;
  166551. png_ptr->process_mode = PNG_READ_zTXt_MODE;
  166552. }
  166553. void /* PRIVATE */
  166554. png_push_read_zTXt(png_structp png_ptr, png_infop info_ptr)
  166555. {
  166556. if (png_ptr->buffer_size && png_ptr->current_text_left)
  166557. {
  166558. png_size_t text_size;
  166559. if (png_ptr->buffer_size < (png_uint_32)png_ptr->current_text_left)
  166560. text_size = png_ptr->buffer_size;
  166561. else
  166562. text_size = png_ptr->current_text_left;
  166563. png_crc_read(png_ptr, (png_bytep)png_ptr->current_text_ptr, text_size);
  166564. png_ptr->current_text_left -= text_size;
  166565. png_ptr->current_text_ptr += text_size;
  166566. }
  166567. if (!(png_ptr->current_text_left))
  166568. {
  166569. png_textp text_ptr;
  166570. png_charp text;
  166571. png_charp key;
  166572. int ret;
  166573. png_size_t text_size, key_size;
  166574. if (png_ptr->buffer_size < 4)
  166575. {
  166576. png_push_save_buffer(png_ptr);
  166577. return;
  166578. }
  166579. png_push_crc_finish(png_ptr);
  166580. key = png_ptr->current_text;
  166581. for (text = key; *text; text++)
  166582. ;
  166583. if (text >= key + png_ptr->current_text_size)
  166584. {
  166585. png_ptr->current_text = NULL;
  166586. png_free(png_ptr, key);
  166587. return;
  166588. }
  166589. text++;
  166590. if (*text != PNG_TEXT_COMPRESSION_zTXt) /* check compression byte */
  166591. {
  166592. png_ptr->current_text = NULL;
  166593. png_free(png_ptr, key);
  166594. return;
  166595. }
  166596. text++;
  166597. png_ptr->zstream.next_in = (png_bytep )text;
  166598. png_ptr->zstream.avail_in = (uInt)(png_ptr->current_text_size -
  166599. (text - key));
  166600. png_ptr->zstream.next_out = png_ptr->zbuf;
  166601. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  166602. key_size = text - key;
  166603. text_size = 0;
  166604. text = NULL;
  166605. ret = Z_STREAM_END;
  166606. while (png_ptr->zstream.avail_in)
  166607. {
  166608. ret = inflate(&png_ptr->zstream, Z_PARTIAL_FLUSH);
  166609. if (ret != Z_OK && ret != Z_STREAM_END)
  166610. {
  166611. inflateReset(&png_ptr->zstream);
  166612. png_ptr->zstream.avail_in = 0;
  166613. png_ptr->current_text = NULL;
  166614. png_free(png_ptr, key);
  166615. png_free(png_ptr, text);
  166616. return;
  166617. }
  166618. if (!(png_ptr->zstream.avail_out) || ret == Z_STREAM_END)
  166619. {
  166620. if (text == NULL)
  166621. {
  166622. text = (png_charp)png_malloc(png_ptr,
  166623. (png_uint_32)(png_ptr->zbuf_size - png_ptr->zstream.avail_out
  166624. + key_size + 1));
  166625. png_memcpy(text + key_size, png_ptr->zbuf,
  166626. png_ptr->zbuf_size - png_ptr->zstream.avail_out);
  166627. png_memcpy(text, key, key_size);
  166628. text_size = key_size + png_ptr->zbuf_size -
  166629. png_ptr->zstream.avail_out;
  166630. *(text + text_size) = '\0';
  166631. }
  166632. else
  166633. {
  166634. png_charp tmp;
  166635. tmp = text;
  166636. text = (png_charp)png_malloc(png_ptr, text_size +
  166637. (png_uint_32)(png_ptr->zbuf_size - png_ptr->zstream.avail_out
  166638. + 1));
  166639. png_memcpy(text, tmp, text_size);
  166640. png_free(png_ptr, tmp);
  166641. png_memcpy(text + text_size, png_ptr->zbuf,
  166642. png_ptr->zbuf_size - png_ptr->zstream.avail_out);
  166643. text_size += png_ptr->zbuf_size - png_ptr->zstream.avail_out;
  166644. *(text + text_size) = '\0';
  166645. }
  166646. if (ret != Z_STREAM_END)
  166647. {
  166648. png_ptr->zstream.next_out = png_ptr->zbuf;
  166649. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  166650. }
  166651. }
  166652. else
  166653. {
  166654. break;
  166655. }
  166656. if (ret == Z_STREAM_END)
  166657. break;
  166658. }
  166659. inflateReset(&png_ptr->zstream);
  166660. png_ptr->zstream.avail_in = 0;
  166661. if (ret != Z_STREAM_END)
  166662. {
  166663. png_ptr->current_text = NULL;
  166664. png_free(png_ptr, key);
  166665. png_free(png_ptr, text);
  166666. return;
  166667. }
  166668. png_ptr->current_text = NULL;
  166669. png_free(png_ptr, key);
  166670. key = text;
  166671. text += key_size;
  166672. text_ptr = (png_textp)png_malloc(png_ptr,
  166673. (png_uint_32)png_sizeof(png_text));
  166674. text_ptr->compression = PNG_TEXT_COMPRESSION_zTXt;
  166675. text_ptr->key = key;
  166676. #ifdef PNG_iTXt_SUPPORTED
  166677. text_ptr->lang = NULL;
  166678. text_ptr->lang_key = NULL;
  166679. #endif
  166680. text_ptr->text = text;
  166681. ret = png_set_text_2(png_ptr, info_ptr, text_ptr, 1);
  166682. png_free(png_ptr, key);
  166683. png_free(png_ptr, text_ptr);
  166684. if (ret)
  166685. png_warning(png_ptr, "Insufficient memory to store text chunk.");
  166686. }
  166687. }
  166688. #endif
  166689. #if defined(PNG_READ_iTXt_SUPPORTED)
  166690. void /* PRIVATE */
  166691. png_push_handle_iTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32
  166692. length)
  166693. {
  166694. if (!(png_ptr->mode & PNG_HAVE_IHDR) || (png_ptr->mode & PNG_HAVE_IEND))
  166695. {
  166696. png_error(png_ptr, "Out of place iTXt");
  166697. info_ptr = info_ptr; /* to quiet some compiler warnings */
  166698. }
  166699. #ifdef PNG_MAX_MALLOC_64K
  166700. png_ptr->skip_length = 0; /* This may not be necessary */
  166701. if (length > (png_uint_32)65535L) /* Can't hold entire string in memory */
  166702. {
  166703. png_warning(png_ptr, "iTXt chunk too large to fit in memory");
  166704. png_ptr->skip_length = length - (png_uint_32)65535L;
  166705. length = (png_uint_32)65535L;
  166706. }
  166707. #endif
  166708. png_ptr->current_text = (png_charp)png_malloc(png_ptr,
  166709. (png_uint_32)(length+1));
  166710. png_ptr->current_text[length] = '\0';
  166711. png_ptr->current_text_ptr = png_ptr->current_text;
  166712. png_ptr->current_text_size = (png_size_t)length;
  166713. png_ptr->current_text_left = (png_size_t)length;
  166714. png_ptr->process_mode = PNG_READ_iTXt_MODE;
  166715. }
  166716. void /* PRIVATE */
  166717. png_push_read_iTXt(png_structp png_ptr, png_infop info_ptr)
  166718. {
  166719. if (png_ptr->buffer_size && png_ptr->current_text_left)
  166720. {
  166721. png_size_t text_size;
  166722. if (png_ptr->buffer_size < png_ptr->current_text_left)
  166723. text_size = png_ptr->buffer_size;
  166724. else
  166725. text_size = png_ptr->current_text_left;
  166726. png_crc_read(png_ptr, (png_bytep)png_ptr->current_text_ptr, text_size);
  166727. png_ptr->current_text_left -= text_size;
  166728. png_ptr->current_text_ptr += text_size;
  166729. }
  166730. if (!(png_ptr->current_text_left))
  166731. {
  166732. png_textp text_ptr;
  166733. png_charp key;
  166734. int comp_flag;
  166735. png_charp lang;
  166736. png_charp lang_key;
  166737. png_charp text;
  166738. int ret;
  166739. if (png_ptr->buffer_size < 4)
  166740. {
  166741. png_push_save_buffer(png_ptr);
  166742. return;
  166743. }
  166744. png_push_crc_finish(png_ptr);
  166745. #if defined(PNG_MAX_MALLOC_64K)
  166746. if (png_ptr->skip_length)
  166747. return;
  166748. #endif
  166749. key = png_ptr->current_text;
  166750. for (lang = key; *lang; lang++)
  166751. ;
  166752. if (lang < key + png_ptr->current_text_size - 3)
  166753. lang++;
  166754. comp_flag = *lang++;
  166755. lang++; /* skip comp_type, always zero */
  166756. for (lang_key = lang; *lang_key; lang_key++)
  166757. ;
  166758. lang_key++; /* skip NUL separator */
  166759. text=lang_key;
  166760. if (lang_key < key + png_ptr->current_text_size - 1)
  166761. {
  166762. for (; *text; text++)
  166763. ;
  166764. }
  166765. if (text < key + png_ptr->current_text_size)
  166766. text++;
  166767. text_ptr = (png_textp)png_malloc(png_ptr,
  166768. (png_uint_32)png_sizeof(png_text));
  166769. text_ptr->compression = comp_flag + 2;
  166770. text_ptr->key = key;
  166771. text_ptr->lang = lang;
  166772. text_ptr->lang_key = lang_key;
  166773. text_ptr->text = text;
  166774. text_ptr->text_length = 0;
  166775. text_ptr->itxt_length = png_strlen(text);
  166776. ret = png_set_text_2(png_ptr, info_ptr, text_ptr, 1);
  166777. png_ptr->current_text = NULL;
  166778. png_free(png_ptr, text_ptr);
  166779. if (ret)
  166780. png_warning(png_ptr, "Insufficient memory to store iTXt chunk.");
  166781. }
  166782. }
  166783. #endif
  166784. void /* PRIVATE */
  166785. png_push_handle_unknown(png_structp png_ptr, png_infop info_ptr, png_uint_32
  166786. length)
  166787. {
  166788. png_uint_32 skip=0;
  166789. png_check_chunk_name(png_ptr, png_ptr->chunk_name);
  166790. if (!(png_ptr->chunk_name[0] & 0x20))
  166791. {
  166792. #if defined(PNG_READ_UNKNOWN_CHUNKS_SUPPORTED)
  166793. if(png_handle_as_unknown(png_ptr, png_ptr->chunk_name) !=
  166794. PNG_HANDLE_CHUNK_ALWAYS
  166795. #if defined(PNG_READ_USER_CHUNKS_SUPPORTED)
  166796. && png_ptr->read_user_chunk_fn == NULL
  166797. #endif
  166798. )
  166799. #endif
  166800. png_chunk_error(png_ptr, "unknown critical chunk");
  166801. info_ptr = info_ptr; /* to quiet some compiler warnings */
  166802. }
  166803. #if defined(PNG_READ_UNKNOWN_CHUNKS_SUPPORTED)
  166804. if (png_ptr->flags & PNG_FLAG_KEEP_UNKNOWN_CHUNKS)
  166805. {
  166806. #ifdef PNG_MAX_MALLOC_64K
  166807. if (length > (png_uint_32)65535L)
  166808. {
  166809. png_warning(png_ptr, "unknown chunk too large to fit in memory");
  166810. skip = length - (png_uint_32)65535L;
  166811. length = (png_uint_32)65535L;
  166812. }
  166813. #endif
  166814. png_strncpy((png_charp)png_ptr->unknown_chunk.name,
  166815. (png_charp)png_ptr->chunk_name, 5);
  166816. png_ptr->unknown_chunk.data = (png_bytep)png_malloc(png_ptr, length);
  166817. png_ptr->unknown_chunk.size = (png_size_t)length;
  166818. png_crc_read(png_ptr, (png_bytep)png_ptr->unknown_chunk.data, length);
  166819. #if defined(PNG_READ_USER_CHUNKS_SUPPORTED)
  166820. if(png_ptr->read_user_chunk_fn != NULL)
  166821. {
  166822. int ret;
  166823. ret = (*(png_ptr->read_user_chunk_fn))
  166824. (png_ptr, &png_ptr->unknown_chunk);
  166825. if (ret < 0)
  166826. png_chunk_error(png_ptr, "error in user chunk");
  166827. if (ret == 0)
  166828. {
  166829. if (!(png_ptr->chunk_name[0] & 0x20))
  166830. if(png_handle_as_unknown(png_ptr, png_ptr->chunk_name) !=
  166831. PNG_HANDLE_CHUNK_ALWAYS)
  166832. png_chunk_error(png_ptr, "unknown critical chunk");
  166833. png_set_unknown_chunks(png_ptr, info_ptr,
  166834. &png_ptr->unknown_chunk, 1);
  166835. }
  166836. }
  166837. #else
  166838. png_set_unknown_chunks(png_ptr, info_ptr, &png_ptr->unknown_chunk, 1);
  166839. #endif
  166840. png_free(png_ptr, png_ptr->unknown_chunk.data);
  166841. png_ptr->unknown_chunk.data = NULL;
  166842. }
  166843. else
  166844. #endif
  166845. skip=length;
  166846. png_push_crc_skip(png_ptr, skip);
  166847. }
  166848. void /* PRIVATE */
  166849. png_push_have_info(png_structp png_ptr, png_infop info_ptr)
  166850. {
  166851. if (png_ptr->info_fn != NULL)
  166852. (*(png_ptr->info_fn))(png_ptr, info_ptr);
  166853. }
  166854. void /* PRIVATE */
  166855. png_push_have_end(png_structp png_ptr, png_infop info_ptr)
  166856. {
  166857. if (png_ptr->end_fn != NULL)
  166858. (*(png_ptr->end_fn))(png_ptr, info_ptr);
  166859. }
  166860. void /* PRIVATE */
  166861. png_push_have_row(png_structp png_ptr, png_bytep row)
  166862. {
  166863. if (png_ptr->row_fn != NULL)
  166864. (*(png_ptr->row_fn))(png_ptr, row, png_ptr->row_number,
  166865. (int)png_ptr->pass);
  166866. }
  166867. void PNGAPI
  166868. png_progressive_combine_row (png_structp png_ptr,
  166869. png_bytep old_row, png_bytep new_row)
  166870. {
  166871. #ifdef PNG_USE_LOCAL_ARRAYS
  166872. PNG_CONST int FARDATA png_pass_dsp_mask[7] =
  166873. {0xff, 0x0f, 0xff, 0x33, 0xff, 0x55, 0xff};
  166874. #endif
  166875. if(png_ptr == NULL) return;
  166876. if (new_row != NULL) /* new_row must == png_ptr->row_buf here. */
  166877. png_combine_row(png_ptr, old_row, png_pass_dsp_mask[png_ptr->pass]);
  166878. }
  166879. void PNGAPI
  166880. png_set_progressive_read_fn(png_structp png_ptr, png_voidp progressive_ptr,
  166881. png_progressive_info_ptr info_fn, png_progressive_row_ptr row_fn,
  166882. png_progressive_end_ptr end_fn)
  166883. {
  166884. if(png_ptr == NULL) return;
  166885. png_ptr->info_fn = info_fn;
  166886. png_ptr->row_fn = row_fn;
  166887. png_ptr->end_fn = end_fn;
  166888. png_set_read_fn(png_ptr, progressive_ptr, png_push_fill_buffer);
  166889. }
  166890. png_voidp PNGAPI
  166891. png_get_progressive_ptr(png_structp png_ptr)
  166892. {
  166893. if(png_ptr == NULL) return (NULL);
  166894. return png_ptr->io_ptr;
  166895. }
  166896. #endif /* PNG_PROGRESSIVE_READ_SUPPORTED */
  166897. /*** End of inlined file: pngpread.c ***/
  166898. /*** Start of inlined file: pngrio.c ***/
  166899. #define PNG_INTERNAL
  166900. #if defined(PNG_READ_SUPPORTED)
  166901. void /* PRIVATE */
  166902. png_read_data(png_structp png_ptr, png_bytep data, png_size_t length)
  166903. {
  166904. png_debug1(4,"reading %d bytes\n", (int)length);
  166905. if (png_ptr->read_data_fn != NULL)
  166906. (*(png_ptr->read_data_fn))(png_ptr, data, length);
  166907. else
  166908. png_error(png_ptr, "Call to NULL read function");
  166909. }
  166910. #if !defined(PNG_NO_STDIO)
  166911. #ifndef USE_FAR_KEYWORD
  166912. void PNGAPI
  166913. png_default_read_data(png_structp png_ptr, png_bytep data, png_size_t length)
  166914. {
  166915. png_size_t check;
  166916. if(png_ptr == NULL) return;
  166917. #if defined(_WIN32_WCE)
  166918. if ( !ReadFile((HANDLE)(png_ptr->io_ptr), data, length, &check, NULL) )
  166919. check = 0;
  166920. #else
  166921. check = (png_size_t)fread(data, (png_size_t)1, length,
  166922. (png_FILE_p)png_ptr->io_ptr);
  166923. #endif
  166924. if (check != length)
  166925. png_error(png_ptr, "Read Error");
  166926. }
  166927. #else
  166928. #define NEAR_BUF_SIZE 1024
  166929. #define MIN(a,b) (a <= b ? a : b)
  166930. static void PNGAPI
  166931. png_default_read_data(png_structp png_ptr, png_bytep data, png_size_t length)
  166932. {
  166933. int check;
  166934. png_byte *n_data;
  166935. png_FILE_p io_ptr;
  166936. if(png_ptr == NULL) return;
  166937. n_data = (png_byte *)CVT_PTR_NOCHECK(data);
  166938. io_ptr = (png_FILE_p)CVT_PTR(png_ptr->io_ptr);
  166939. if ((png_bytep)n_data == data)
  166940. {
  166941. #if defined(_WIN32_WCE)
  166942. if ( !ReadFile((HANDLE)(png_ptr->io_ptr), data, length, &check, NULL) )
  166943. check = 0;
  166944. #else
  166945. check = fread(n_data, 1, length, io_ptr);
  166946. #endif
  166947. }
  166948. else
  166949. {
  166950. png_byte buf[NEAR_BUF_SIZE];
  166951. png_size_t read, remaining, err;
  166952. check = 0;
  166953. remaining = length;
  166954. do
  166955. {
  166956. read = MIN(NEAR_BUF_SIZE, remaining);
  166957. #if defined(_WIN32_WCE)
  166958. if ( !ReadFile((HANDLE)(io_ptr), buf, read, &err, NULL) )
  166959. err = 0;
  166960. #else
  166961. err = fread(buf, (png_size_t)1, read, io_ptr);
  166962. #endif
  166963. png_memcpy(data, buf, read); /* copy far buffer to near buffer */
  166964. if(err != read)
  166965. break;
  166966. else
  166967. check += err;
  166968. data += read;
  166969. remaining -= read;
  166970. }
  166971. while (remaining != 0);
  166972. }
  166973. if ((png_uint_32)check != (png_uint_32)length)
  166974. png_error(png_ptr, "read Error");
  166975. }
  166976. #endif
  166977. #endif
  166978. void PNGAPI
  166979. png_set_read_fn(png_structp png_ptr, png_voidp io_ptr,
  166980. png_rw_ptr read_data_fn)
  166981. {
  166982. if(png_ptr == NULL) return;
  166983. png_ptr->io_ptr = io_ptr;
  166984. #if !defined(PNG_NO_STDIO)
  166985. if (read_data_fn != NULL)
  166986. png_ptr->read_data_fn = read_data_fn;
  166987. else
  166988. png_ptr->read_data_fn = png_default_read_data;
  166989. #else
  166990. png_ptr->read_data_fn = read_data_fn;
  166991. #endif
  166992. if (png_ptr->write_data_fn != NULL)
  166993. {
  166994. png_ptr->write_data_fn = NULL;
  166995. png_warning(png_ptr,
  166996. "It's an error to set both read_data_fn and write_data_fn in the ");
  166997. png_warning(png_ptr,
  166998. "same structure. Resetting write_data_fn to NULL.");
  166999. }
  167000. #if defined(PNG_WRITE_FLUSH_SUPPORTED)
  167001. png_ptr->output_flush_fn = NULL;
  167002. #endif
  167003. }
  167004. #endif /* PNG_READ_SUPPORTED */
  167005. /*** End of inlined file: pngrio.c ***/
  167006. /*** Start of inlined file: pngrtran.c ***/
  167007. #define PNG_INTERNAL
  167008. #if defined(PNG_READ_SUPPORTED)
  167009. void PNGAPI
  167010. png_set_crc_action(png_structp png_ptr, int crit_action, int ancil_action)
  167011. {
  167012. png_debug(1, "in png_set_crc_action\n");
  167013. if(png_ptr == NULL) return;
  167014. switch (crit_action)
  167015. {
  167016. case PNG_CRC_NO_CHANGE: /* leave setting as is */
  167017. break;
  167018. case PNG_CRC_WARN_USE: /* warn/use data */
  167019. png_ptr->flags &= ~PNG_FLAG_CRC_CRITICAL_MASK;
  167020. png_ptr->flags |= PNG_FLAG_CRC_CRITICAL_USE;
  167021. break;
  167022. case PNG_CRC_QUIET_USE: /* quiet/use data */
  167023. png_ptr->flags &= ~PNG_FLAG_CRC_CRITICAL_MASK;
  167024. png_ptr->flags |= PNG_FLAG_CRC_CRITICAL_USE |
  167025. PNG_FLAG_CRC_CRITICAL_IGNORE;
  167026. break;
  167027. case PNG_CRC_WARN_DISCARD: /* not a valid action for critical data */
  167028. png_warning(png_ptr, "Can't discard critical data on CRC error.");
  167029. case PNG_CRC_ERROR_QUIT: /* error/quit */
  167030. case PNG_CRC_DEFAULT:
  167031. default:
  167032. png_ptr->flags &= ~PNG_FLAG_CRC_CRITICAL_MASK;
  167033. break;
  167034. }
  167035. switch (ancil_action)
  167036. {
  167037. case PNG_CRC_NO_CHANGE: /* leave setting as is */
  167038. break;
  167039. case PNG_CRC_WARN_USE: /* warn/use data */
  167040. png_ptr->flags &= ~PNG_FLAG_CRC_ANCILLARY_MASK;
  167041. png_ptr->flags |= PNG_FLAG_CRC_ANCILLARY_USE;
  167042. break;
  167043. case PNG_CRC_QUIET_USE: /* quiet/use data */
  167044. png_ptr->flags &= ~PNG_FLAG_CRC_ANCILLARY_MASK;
  167045. png_ptr->flags |= PNG_FLAG_CRC_ANCILLARY_USE |
  167046. PNG_FLAG_CRC_ANCILLARY_NOWARN;
  167047. break;
  167048. case PNG_CRC_ERROR_QUIT: /* error/quit */
  167049. png_ptr->flags &= ~PNG_FLAG_CRC_ANCILLARY_MASK;
  167050. png_ptr->flags |= PNG_FLAG_CRC_ANCILLARY_NOWARN;
  167051. break;
  167052. case PNG_CRC_WARN_DISCARD: /* warn/discard data */
  167053. case PNG_CRC_DEFAULT:
  167054. default:
  167055. png_ptr->flags &= ~PNG_FLAG_CRC_ANCILLARY_MASK;
  167056. break;
  167057. }
  167058. }
  167059. #if defined(PNG_READ_BACKGROUND_SUPPORTED) && \
  167060. defined(PNG_FLOATING_POINT_SUPPORTED)
  167061. void PNGAPI
  167062. png_set_background(png_structp png_ptr,
  167063. png_color_16p background_color, int background_gamma_code,
  167064. int need_expand, double background_gamma)
  167065. {
  167066. png_debug(1, "in png_set_background\n");
  167067. if(png_ptr == NULL) return;
  167068. if (background_gamma_code == PNG_BACKGROUND_GAMMA_UNKNOWN)
  167069. {
  167070. png_warning(png_ptr, "Application must supply a known background gamma");
  167071. return;
  167072. }
  167073. png_ptr->transformations |= PNG_BACKGROUND;
  167074. png_memcpy(&(png_ptr->background), background_color,
  167075. png_sizeof(png_color_16));
  167076. png_ptr->background_gamma = (float)background_gamma;
  167077. png_ptr->background_gamma_type = (png_byte)(background_gamma_code);
  167078. png_ptr->transformations |= (need_expand ? PNG_BACKGROUND_EXPAND : 0);
  167079. }
  167080. #endif
  167081. #if defined(PNG_READ_16_TO_8_SUPPORTED)
  167082. void PNGAPI
  167083. png_set_strip_16(png_structp png_ptr)
  167084. {
  167085. png_debug(1, "in png_set_strip_16\n");
  167086. if(png_ptr == NULL) return;
  167087. png_ptr->transformations |= PNG_16_TO_8;
  167088. }
  167089. #endif
  167090. #if defined(PNG_READ_STRIP_ALPHA_SUPPORTED)
  167091. void PNGAPI
  167092. png_set_strip_alpha(png_structp png_ptr)
  167093. {
  167094. png_debug(1, "in png_set_strip_alpha\n");
  167095. if(png_ptr == NULL) return;
  167096. png_ptr->flags |= PNG_FLAG_STRIP_ALPHA;
  167097. }
  167098. #endif
  167099. #if defined(PNG_READ_DITHER_SUPPORTED)
  167100. typedef struct png_dsort_struct
  167101. {
  167102. struct png_dsort_struct FAR * next;
  167103. png_byte left;
  167104. png_byte right;
  167105. } png_dsort;
  167106. typedef png_dsort FAR * png_dsortp;
  167107. typedef png_dsort FAR * FAR * png_dsortpp;
  167108. void PNGAPI
  167109. png_set_dither(png_structp png_ptr, png_colorp palette,
  167110. int num_palette, int maximum_colors, png_uint_16p histogram,
  167111. int full_dither)
  167112. {
  167113. png_debug(1, "in png_set_dither\n");
  167114. if(png_ptr == NULL) return;
  167115. png_ptr->transformations |= PNG_DITHER;
  167116. if (!full_dither)
  167117. {
  167118. int i;
  167119. png_ptr->dither_index = (png_bytep)png_malloc(png_ptr,
  167120. (png_uint_32)(num_palette * png_sizeof (png_byte)));
  167121. for (i = 0; i < num_palette; i++)
  167122. png_ptr->dither_index[i] = (png_byte)i;
  167123. }
  167124. if (num_palette > maximum_colors)
  167125. {
  167126. if (histogram != NULL)
  167127. {
  167128. int i;
  167129. png_ptr->dither_sort = (png_bytep)png_malloc(png_ptr,
  167130. (png_uint_32)(num_palette * png_sizeof (png_byte)));
  167131. for (i = 0; i < num_palette; i++)
  167132. png_ptr->dither_sort[i] = (png_byte)i;
  167133. for (i = num_palette - 1; i >= maximum_colors; i--)
  167134. {
  167135. int done; /* to stop early if the list is pre-sorted */
  167136. int j;
  167137. done = 1;
  167138. for (j = 0; j < i; j++)
  167139. {
  167140. if (histogram[png_ptr->dither_sort[j]]
  167141. < histogram[png_ptr->dither_sort[j + 1]])
  167142. {
  167143. png_byte t;
  167144. t = png_ptr->dither_sort[j];
  167145. png_ptr->dither_sort[j] = png_ptr->dither_sort[j + 1];
  167146. png_ptr->dither_sort[j + 1] = t;
  167147. done = 0;
  167148. }
  167149. }
  167150. if (done)
  167151. break;
  167152. }
  167153. if (full_dither)
  167154. {
  167155. int j = num_palette;
  167156. for (i = 0; i < maximum_colors; i++)
  167157. {
  167158. if ((int)png_ptr->dither_sort[i] >= maximum_colors)
  167159. {
  167160. do
  167161. j--;
  167162. while ((int)png_ptr->dither_sort[j] >= maximum_colors);
  167163. palette[i] = palette[j];
  167164. }
  167165. }
  167166. }
  167167. else
  167168. {
  167169. int j = num_palette;
  167170. for (i = 0; i < maximum_colors; i++)
  167171. {
  167172. if ((int)png_ptr->dither_sort[i] >= maximum_colors)
  167173. {
  167174. png_color tmp_color;
  167175. do
  167176. j--;
  167177. while ((int)png_ptr->dither_sort[j] >= maximum_colors);
  167178. tmp_color = palette[j];
  167179. palette[j] = palette[i];
  167180. palette[i] = tmp_color;
  167181. png_ptr->dither_index[j] = (png_byte)i;
  167182. png_ptr->dither_index[i] = (png_byte)j;
  167183. }
  167184. }
  167185. for (i = 0; i < num_palette; i++)
  167186. {
  167187. if ((int)png_ptr->dither_index[i] >= maximum_colors)
  167188. {
  167189. int min_d, k, min_k, d_index;
  167190. d_index = png_ptr->dither_index[i];
  167191. min_d = PNG_COLOR_DIST(palette[d_index], palette[0]);
  167192. for (k = 1, min_k = 0; k < maximum_colors; k++)
  167193. {
  167194. int d;
  167195. d = PNG_COLOR_DIST(palette[d_index], palette[k]);
  167196. if (d < min_d)
  167197. {
  167198. min_d = d;
  167199. min_k = k;
  167200. }
  167201. }
  167202. png_ptr->dither_index[i] = (png_byte)min_k;
  167203. }
  167204. }
  167205. }
  167206. png_free(png_ptr, png_ptr->dither_sort);
  167207. png_ptr->dither_sort=NULL;
  167208. }
  167209. else
  167210. {
  167211. int i;
  167212. int max_d;
  167213. int num_new_palette;
  167214. png_dsortp t;
  167215. png_dsortpp hash;
  167216. t=NULL;
  167217. png_ptr->index_to_palette = (png_bytep)png_malloc(png_ptr,
  167218. (png_uint_32)(num_palette * png_sizeof (png_byte)));
  167219. png_ptr->palette_to_index = (png_bytep)png_malloc(png_ptr,
  167220. (png_uint_32)(num_palette * png_sizeof (png_byte)));
  167221. for (i = 0; i < num_palette; i++)
  167222. {
  167223. png_ptr->index_to_palette[i] = (png_byte)i;
  167224. png_ptr->palette_to_index[i] = (png_byte)i;
  167225. }
  167226. hash = (png_dsortpp)png_malloc(png_ptr, (png_uint_32)(769 *
  167227. png_sizeof (png_dsortp)));
  167228. for (i = 0; i < 769; i++)
  167229. hash[i] = NULL;
  167230. num_new_palette = num_palette;
  167231. max_d = 96;
  167232. while (num_new_palette > maximum_colors)
  167233. {
  167234. for (i = 0; i < num_new_palette - 1; i++)
  167235. {
  167236. int j;
  167237. for (j = i + 1; j < num_new_palette; j++)
  167238. {
  167239. int d;
  167240. d = PNG_COLOR_DIST(palette[i], palette[j]);
  167241. if (d <= max_d)
  167242. {
  167243. t = (png_dsortp)png_malloc_warn(png_ptr,
  167244. (png_uint_32)(png_sizeof(png_dsort)));
  167245. if (t == NULL)
  167246. break;
  167247. t->next = hash[d];
  167248. t->left = (png_byte)i;
  167249. t->right = (png_byte)j;
  167250. hash[d] = t;
  167251. }
  167252. }
  167253. if (t == NULL)
  167254. break;
  167255. }
  167256. if (t != NULL)
  167257. for (i = 0; i <= max_d; i++)
  167258. {
  167259. if (hash[i] != NULL)
  167260. {
  167261. png_dsortp p;
  167262. for (p = hash[i]; p; p = p->next)
  167263. {
  167264. if ((int)png_ptr->index_to_palette[p->left]
  167265. < num_new_palette &&
  167266. (int)png_ptr->index_to_palette[p->right]
  167267. < num_new_palette)
  167268. {
  167269. int j, next_j;
  167270. if (num_new_palette & 0x01)
  167271. {
  167272. j = p->left;
  167273. next_j = p->right;
  167274. }
  167275. else
  167276. {
  167277. j = p->right;
  167278. next_j = p->left;
  167279. }
  167280. num_new_palette--;
  167281. palette[png_ptr->index_to_palette[j]]
  167282. = palette[num_new_palette];
  167283. if (!full_dither)
  167284. {
  167285. int k;
  167286. for (k = 0; k < num_palette; k++)
  167287. {
  167288. if (png_ptr->dither_index[k] ==
  167289. png_ptr->index_to_palette[j])
  167290. png_ptr->dither_index[k] =
  167291. png_ptr->index_to_palette[next_j];
  167292. if ((int)png_ptr->dither_index[k] ==
  167293. num_new_palette)
  167294. png_ptr->dither_index[k] =
  167295. png_ptr->index_to_palette[j];
  167296. }
  167297. }
  167298. png_ptr->index_to_palette[png_ptr->palette_to_index
  167299. [num_new_palette]] = png_ptr->index_to_palette[j];
  167300. png_ptr->palette_to_index[png_ptr->index_to_palette[j]]
  167301. = png_ptr->palette_to_index[num_new_palette];
  167302. png_ptr->index_to_palette[j] = (png_byte)num_new_palette;
  167303. png_ptr->palette_to_index[num_new_palette] = (png_byte)j;
  167304. }
  167305. if (num_new_palette <= maximum_colors)
  167306. break;
  167307. }
  167308. if (num_new_palette <= maximum_colors)
  167309. break;
  167310. }
  167311. }
  167312. for (i = 0; i < 769; i++)
  167313. {
  167314. if (hash[i] != NULL)
  167315. {
  167316. png_dsortp p = hash[i];
  167317. while (p)
  167318. {
  167319. t = p->next;
  167320. png_free(png_ptr, p);
  167321. p = t;
  167322. }
  167323. }
  167324. hash[i] = 0;
  167325. }
  167326. max_d += 96;
  167327. }
  167328. png_free(png_ptr, hash);
  167329. png_free(png_ptr, png_ptr->palette_to_index);
  167330. png_free(png_ptr, png_ptr->index_to_palette);
  167331. png_ptr->palette_to_index=NULL;
  167332. png_ptr->index_to_palette=NULL;
  167333. }
  167334. num_palette = maximum_colors;
  167335. }
  167336. if (png_ptr->palette == NULL)
  167337. {
  167338. png_ptr->palette = palette;
  167339. }
  167340. png_ptr->num_palette = (png_uint_16)num_palette;
  167341. if (full_dither)
  167342. {
  167343. int i;
  167344. png_bytep distance;
  167345. int total_bits = PNG_DITHER_RED_BITS + PNG_DITHER_GREEN_BITS +
  167346. PNG_DITHER_BLUE_BITS;
  167347. int num_red = (1 << PNG_DITHER_RED_BITS);
  167348. int num_green = (1 << PNG_DITHER_GREEN_BITS);
  167349. int num_blue = (1 << PNG_DITHER_BLUE_BITS);
  167350. png_size_t num_entries = ((png_size_t)1 << total_bits);
  167351. png_ptr->palette_lookup = (png_bytep )png_malloc(png_ptr,
  167352. (png_uint_32)(num_entries * png_sizeof (png_byte)));
  167353. png_memset(png_ptr->palette_lookup, 0, num_entries *
  167354. png_sizeof (png_byte));
  167355. distance = (png_bytep)png_malloc(png_ptr, (png_uint_32)(num_entries *
  167356. png_sizeof(png_byte)));
  167357. png_memset(distance, 0xff, num_entries * png_sizeof(png_byte));
  167358. for (i = 0; i < num_palette; i++)
  167359. {
  167360. int ir, ig, ib;
  167361. int r = (palette[i].red >> (8 - PNG_DITHER_RED_BITS));
  167362. int g = (palette[i].green >> (8 - PNG_DITHER_GREEN_BITS));
  167363. int b = (palette[i].blue >> (8 - PNG_DITHER_BLUE_BITS));
  167364. for (ir = 0; ir < num_red; ir++)
  167365. {
  167366. int dr = ((ir > r) ? ir - r : r - ir);
  167367. int index_r = (ir << (PNG_DITHER_BLUE_BITS + PNG_DITHER_GREEN_BITS));
  167368. for (ig = 0; ig < num_green; ig++)
  167369. {
  167370. int dg = ((ig > g) ? ig - g : g - ig);
  167371. int dt = dr + dg;
  167372. int dm = ((dr > dg) ? dr : dg);
  167373. int index_g = index_r | (ig << PNG_DITHER_BLUE_BITS);
  167374. for (ib = 0; ib < num_blue; ib++)
  167375. {
  167376. int d_index = index_g | ib;
  167377. int db = ((ib > b) ? ib - b : b - ib);
  167378. int dmax = ((dm > db) ? dm : db);
  167379. int d = dmax + dt + db;
  167380. if (d < (int)distance[d_index])
  167381. {
  167382. distance[d_index] = (png_byte)d;
  167383. png_ptr->palette_lookup[d_index] = (png_byte)i;
  167384. }
  167385. }
  167386. }
  167387. }
  167388. }
  167389. png_free(png_ptr, distance);
  167390. }
  167391. }
  167392. #endif
  167393. #if defined(PNG_READ_GAMMA_SUPPORTED) && defined(PNG_FLOATING_POINT_SUPPORTED)
  167394. void PNGAPI
  167395. png_set_gamma(png_structp png_ptr, double scrn_gamma, double file_gamma)
  167396. {
  167397. png_debug(1, "in png_set_gamma\n");
  167398. if(png_ptr == NULL) return;
  167399. if ((fabs(scrn_gamma * file_gamma - 1.0) > PNG_GAMMA_THRESHOLD) ||
  167400. (png_ptr->color_type & PNG_COLOR_MASK_ALPHA) ||
  167401. (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE))
  167402. png_ptr->transformations |= PNG_GAMMA;
  167403. png_ptr->gamma = (float)file_gamma;
  167404. png_ptr->screen_gamma = (float)scrn_gamma;
  167405. }
  167406. #endif
  167407. #if defined(PNG_READ_EXPAND_SUPPORTED)
  167408. void PNGAPI
  167409. png_set_expand(png_structp png_ptr)
  167410. {
  167411. png_debug(1, "in png_set_expand\n");
  167412. if(png_ptr == NULL) return;
  167413. png_ptr->transformations |= (PNG_EXPAND | PNG_EXPAND_tRNS);
  167414. #ifdef PNG_WARN_UNINITIALIZED_ROW
  167415. png_ptr->flags &= ~PNG_FLAG_ROW_INIT;
  167416. #endif
  167417. }
  167418. void PNGAPI
  167419. png_set_palette_to_rgb(png_structp png_ptr)
  167420. {
  167421. png_debug(1, "in png_set_palette_to_rgb\n");
  167422. if(png_ptr == NULL) return;
  167423. png_ptr->transformations |= (PNG_EXPAND | PNG_EXPAND_tRNS);
  167424. #ifdef PNG_WARN_UNINITIALIZED_ROW
  167425. png_ptr->flags &= !(PNG_FLAG_ROW_INIT);
  167426. png_ptr->flags &= ~PNG_FLAG_ROW_INIT;
  167427. #endif
  167428. }
  167429. #if !defined(PNG_1_0_X)
  167430. void PNGAPI
  167431. png_set_expand_gray_1_2_4_to_8(png_structp png_ptr)
  167432. {
  167433. png_debug(1, "in png_set_expand_gray_1_2_4_to_8\n");
  167434. if(png_ptr == NULL) return;
  167435. png_ptr->transformations |= PNG_EXPAND;
  167436. #ifdef PNG_WARN_UNINITIALIZED_ROW
  167437. png_ptr->flags &= ~PNG_FLAG_ROW_INIT;
  167438. #endif
  167439. }
  167440. #endif
  167441. #if defined(PNG_1_0_X) || defined(PNG_1_2_X)
  167442. void PNGAPI
  167443. png_set_gray_1_2_4_to_8(png_structp png_ptr)
  167444. {
  167445. png_debug(1, "in png_set_gray_1_2_4_to_8\n");
  167446. if(png_ptr == NULL) return;
  167447. png_ptr->transformations |= (PNG_EXPAND | PNG_EXPAND_tRNS);
  167448. }
  167449. #endif
  167450. void PNGAPI
  167451. png_set_tRNS_to_alpha(png_structp png_ptr)
  167452. {
  167453. png_debug(1, "in png_set_tRNS_to_alpha\n");
  167454. png_ptr->transformations |= (PNG_EXPAND | PNG_EXPAND_tRNS);
  167455. #ifdef PNG_WARN_UNINITIALIZED_ROW
  167456. png_ptr->flags &= ~PNG_FLAG_ROW_INIT;
  167457. #endif
  167458. }
  167459. #endif /* defined(PNG_READ_EXPAND_SUPPORTED) */
  167460. #if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
  167461. void PNGAPI
  167462. png_set_gray_to_rgb(png_structp png_ptr)
  167463. {
  167464. png_debug(1, "in png_set_gray_to_rgb\n");
  167465. png_ptr->transformations |= PNG_GRAY_TO_RGB;
  167466. #ifdef PNG_WARN_UNINITIALIZED_ROW
  167467. png_ptr->flags &= ~PNG_FLAG_ROW_INIT;
  167468. #endif
  167469. }
  167470. #endif
  167471. #if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
  167472. #if defined(PNG_FLOATING_POINT_SUPPORTED)
  167473. void PNGAPI
  167474. png_set_rgb_to_gray(png_structp png_ptr, int error_action, double red,
  167475. double green)
  167476. {
  167477. int red_fixed = (int)((float)red*100000.0 + 0.5);
  167478. int green_fixed = (int)((float)green*100000.0 + 0.5);
  167479. if(png_ptr == NULL) return;
  167480. png_set_rgb_to_gray_fixed(png_ptr, error_action, red_fixed, green_fixed);
  167481. }
  167482. #endif
  167483. void PNGAPI
  167484. png_set_rgb_to_gray_fixed(png_structp png_ptr, int error_action,
  167485. png_fixed_point red, png_fixed_point green)
  167486. {
  167487. png_debug(1, "in png_set_rgb_to_gray\n");
  167488. if(png_ptr == NULL) return;
  167489. switch(error_action)
  167490. {
  167491. case 1: png_ptr->transformations |= PNG_RGB_TO_GRAY;
  167492. break;
  167493. case 2: png_ptr->transformations |= PNG_RGB_TO_GRAY_WARN;
  167494. break;
  167495. case 3: png_ptr->transformations |= PNG_RGB_TO_GRAY_ERR;
  167496. }
  167497. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  167498. #if defined(PNG_READ_EXPAND_SUPPORTED)
  167499. png_ptr->transformations |= PNG_EXPAND;
  167500. #else
  167501. {
  167502. png_warning(png_ptr, "Cannot do RGB_TO_GRAY without EXPAND_SUPPORTED.");
  167503. png_ptr->transformations &= ~PNG_RGB_TO_GRAY;
  167504. }
  167505. #endif
  167506. {
  167507. png_uint_16 red_int, green_int;
  167508. if(red < 0 || green < 0)
  167509. {
  167510. red_int = 6968; /* .212671 * 32768 + .5 */
  167511. green_int = 23434; /* .715160 * 32768 + .5 */
  167512. }
  167513. else if(red + green < 100000L)
  167514. {
  167515. red_int = (png_uint_16)(((png_uint_32)red*32768L)/100000L);
  167516. green_int = (png_uint_16)(((png_uint_32)green*32768L)/100000L);
  167517. }
  167518. else
  167519. {
  167520. png_warning(png_ptr, "ignoring out of range rgb_to_gray coefficients");
  167521. red_int = 6968;
  167522. green_int = 23434;
  167523. }
  167524. png_ptr->rgb_to_gray_red_coeff = red_int;
  167525. png_ptr->rgb_to_gray_green_coeff = green_int;
  167526. png_ptr->rgb_to_gray_blue_coeff = (png_uint_16)(32768-red_int-green_int);
  167527. }
  167528. }
  167529. #endif
  167530. #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \
  167531. defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED) || \
  167532. defined(PNG_LEGACY_SUPPORTED)
  167533. void PNGAPI
  167534. png_set_read_user_transform_fn(png_structp png_ptr, png_user_transform_ptr
  167535. read_user_transform_fn)
  167536. {
  167537. png_debug(1, "in png_set_read_user_transform_fn\n");
  167538. if(png_ptr == NULL) return;
  167539. #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED)
  167540. png_ptr->transformations |= PNG_USER_TRANSFORM;
  167541. png_ptr->read_user_transform_fn = read_user_transform_fn;
  167542. #endif
  167543. #ifdef PNG_LEGACY_SUPPORTED
  167544. if(read_user_transform_fn)
  167545. png_warning(png_ptr,
  167546. "This version of libpng does not support user transforms");
  167547. #endif
  167548. }
  167549. #endif
  167550. void /* PRIVATE */
  167551. png_init_read_transformations(png_structp png_ptr)
  167552. {
  167553. png_debug(1, "in png_init_read_transformations\n");
  167554. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  167555. if(png_ptr != NULL)
  167556. #endif
  167557. {
  167558. #if defined(PNG_READ_BACKGROUND_SUPPORTED) || defined(PNG_READ_SHIFT_SUPPORTED) \
  167559. || defined(PNG_READ_GAMMA_SUPPORTED)
  167560. int color_type = png_ptr->color_type;
  167561. #endif
  167562. #if defined(PNG_READ_EXPAND_SUPPORTED) && defined(PNG_READ_BACKGROUND_SUPPORTED)
  167563. #if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
  167564. if ((png_ptr->transformations & PNG_BACKGROUND_EXPAND) &&
  167565. !(color_type & PNG_COLOR_MASK_COLOR))
  167566. {
  167567. png_ptr->mode |= PNG_BACKGROUND_IS_GRAY;
  167568. } else if ((png_ptr->transformations & PNG_BACKGROUND) &&
  167569. !(png_ptr->transformations & PNG_BACKGROUND_EXPAND) &&
  167570. (png_ptr->transformations & PNG_GRAY_TO_RGB) &&
  167571. png_ptr->background.red == png_ptr->background.green &&
  167572. png_ptr->background.red == png_ptr->background.blue)
  167573. {
  167574. png_ptr->mode |= PNG_BACKGROUND_IS_GRAY;
  167575. png_ptr->background.gray = png_ptr->background.red;
  167576. }
  167577. #endif
  167578. if ((png_ptr->transformations & PNG_BACKGROUND_EXPAND) &&
  167579. (png_ptr->transformations & PNG_EXPAND))
  167580. {
  167581. if (!(color_type & PNG_COLOR_MASK_COLOR)) /* i.e., GRAY or GRAY_ALPHA */
  167582. {
  167583. switch (png_ptr->bit_depth)
  167584. {
  167585. case 1:
  167586. png_ptr->background.gray *= (png_uint_16)0xff;
  167587. png_ptr->background.red = png_ptr->background.green
  167588. = png_ptr->background.blue = png_ptr->background.gray;
  167589. if (!(png_ptr->transformations & PNG_EXPAND_tRNS))
  167590. {
  167591. png_ptr->trans_values.gray *= (png_uint_16)0xff;
  167592. png_ptr->trans_values.red = png_ptr->trans_values.green
  167593. = png_ptr->trans_values.blue = png_ptr->trans_values.gray;
  167594. }
  167595. break;
  167596. case 2:
  167597. png_ptr->background.gray *= (png_uint_16)0x55;
  167598. png_ptr->background.red = png_ptr->background.green
  167599. = png_ptr->background.blue = png_ptr->background.gray;
  167600. if (!(png_ptr->transformations & PNG_EXPAND_tRNS))
  167601. {
  167602. png_ptr->trans_values.gray *= (png_uint_16)0x55;
  167603. png_ptr->trans_values.red = png_ptr->trans_values.green
  167604. = png_ptr->trans_values.blue = png_ptr->trans_values.gray;
  167605. }
  167606. break;
  167607. case 4:
  167608. png_ptr->background.gray *= (png_uint_16)0x11;
  167609. png_ptr->background.red = png_ptr->background.green
  167610. = png_ptr->background.blue = png_ptr->background.gray;
  167611. if (!(png_ptr->transformations & PNG_EXPAND_tRNS))
  167612. {
  167613. png_ptr->trans_values.gray *= (png_uint_16)0x11;
  167614. png_ptr->trans_values.red = png_ptr->trans_values.green
  167615. = png_ptr->trans_values.blue = png_ptr->trans_values.gray;
  167616. }
  167617. break;
  167618. case 8:
  167619. case 16:
  167620. png_ptr->background.red = png_ptr->background.green
  167621. = png_ptr->background.blue = png_ptr->background.gray;
  167622. break;
  167623. }
  167624. }
  167625. else if (color_type == PNG_COLOR_TYPE_PALETTE)
  167626. {
  167627. png_ptr->background.red =
  167628. png_ptr->palette[png_ptr->background.index].red;
  167629. png_ptr->background.green =
  167630. png_ptr->palette[png_ptr->background.index].green;
  167631. png_ptr->background.blue =
  167632. png_ptr->palette[png_ptr->background.index].blue;
  167633. #if defined(PNG_READ_INVERT_ALPHA_SUPPORTED)
  167634. if (png_ptr->transformations & PNG_INVERT_ALPHA)
  167635. {
  167636. #if defined(PNG_READ_EXPAND_SUPPORTED)
  167637. if (!(png_ptr->transformations & PNG_EXPAND_tRNS))
  167638. #endif
  167639. {
  167640. int i,istop;
  167641. istop=(int)png_ptr->num_trans;
  167642. for (i=0; i<istop; i++)
  167643. png_ptr->trans[i] = (png_byte)(255 - png_ptr->trans[i]);
  167644. }
  167645. }
  167646. #endif
  167647. }
  167648. }
  167649. #endif
  167650. #if defined(PNG_READ_BACKGROUND_SUPPORTED) && defined(PNG_READ_GAMMA_SUPPORTED)
  167651. png_ptr->background_1 = png_ptr->background;
  167652. #endif
  167653. #if defined(PNG_READ_GAMMA_SUPPORTED) && defined(PNG_FLOATING_POINT_SUPPORTED)
  167654. if ((color_type == PNG_COLOR_TYPE_PALETTE && png_ptr->num_trans != 0)
  167655. && (fabs(png_ptr->screen_gamma * png_ptr->gamma - 1.0)
  167656. < PNG_GAMMA_THRESHOLD))
  167657. {
  167658. int i,k;
  167659. k=0;
  167660. for (i=0; i<png_ptr->num_trans; i++)
  167661. {
  167662. if (png_ptr->trans[i] != 0 && png_ptr->trans[i] != 0xff)
  167663. k=1; /* partial transparency is present */
  167664. }
  167665. if (k == 0)
  167666. png_ptr->transformations &= (~PNG_GAMMA);
  167667. }
  167668. if ((png_ptr->transformations & (PNG_GAMMA | PNG_RGB_TO_GRAY)) &&
  167669. png_ptr->gamma != 0.0)
  167670. {
  167671. png_build_gamma_table(png_ptr);
  167672. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  167673. if (png_ptr->transformations & PNG_BACKGROUND)
  167674. {
  167675. if (color_type == PNG_COLOR_TYPE_PALETTE)
  167676. {
  167677. png_color back, back_1;
  167678. png_colorp palette = png_ptr->palette;
  167679. int num_palette = png_ptr->num_palette;
  167680. int i;
  167681. if (png_ptr->background_gamma_type == PNG_BACKGROUND_GAMMA_FILE)
  167682. {
  167683. back.red = png_ptr->gamma_table[png_ptr->background.red];
  167684. back.green = png_ptr->gamma_table[png_ptr->background.green];
  167685. back.blue = png_ptr->gamma_table[png_ptr->background.blue];
  167686. back_1.red = png_ptr->gamma_to_1[png_ptr->background.red];
  167687. back_1.green = png_ptr->gamma_to_1[png_ptr->background.green];
  167688. back_1.blue = png_ptr->gamma_to_1[png_ptr->background.blue];
  167689. }
  167690. else
  167691. {
  167692. double g, gs;
  167693. switch (png_ptr->background_gamma_type)
  167694. {
  167695. case PNG_BACKGROUND_GAMMA_SCREEN:
  167696. g = (png_ptr->screen_gamma);
  167697. gs = 1.0;
  167698. break;
  167699. case PNG_BACKGROUND_GAMMA_FILE:
  167700. g = 1.0 / (png_ptr->gamma);
  167701. gs = 1.0 / (png_ptr->gamma * png_ptr->screen_gamma);
  167702. break;
  167703. case PNG_BACKGROUND_GAMMA_UNIQUE:
  167704. g = 1.0 / (png_ptr->background_gamma);
  167705. gs = 1.0 / (png_ptr->background_gamma *
  167706. png_ptr->screen_gamma);
  167707. break;
  167708. default:
  167709. g = 1.0; /* back_1 */
  167710. gs = 1.0; /* back */
  167711. }
  167712. if ( fabs(gs - 1.0) < PNG_GAMMA_THRESHOLD)
  167713. {
  167714. back.red = (png_byte)png_ptr->background.red;
  167715. back.green = (png_byte)png_ptr->background.green;
  167716. back.blue = (png_byte)png_ptr->background.blue;
  167717. }
  167718. else
  167719. {
  167720. back.red = (png_byte)(pow(
  167721. (double)png_ptr->background.red/255, gs) * 255.0 + .5);
  167722. back.green = (png_byte)(pow(
  167723. (double)png_ptr->background.green/255, gs) * 255.0 + .5);
  167724. back.blue = (png_byte)(pow(
  167725. (double)png_ptr->background.blue/255, gs) * 255.0 + .5);
  167726. }
  167727. back_1.red = (png_byte)(pow(
  167728. (double)png_ptr->background.red/255, g) * 255.0 + .5);
  167729. back_1.green = (png_byte)(pow(
  167730. (double)png_ptr->background.green/255, g) * 255.0 + .5);
  167731. back_1.blue = (png_byte)(pow(
  167732. (double)png_ptr->background.blue/255, g) * 255.0 + .5);
  167733. }
  167734. for (i = 0; i < num_palette; i++)
  167735. {
  167736. if (i < (int)png_ptr->num_trans && png_ptr->trans[i] != 0xff)
  167737. {
  167738. if (png_ptr->trans[i] == 0)
  167739. {
  167740. palette[i] = back;
  167741. }
  167742. else /* if (png_ptr->trans[i] != 0xff) */
  167743. {
  167744. png_byte v, w;
  167745. v = png_ptr->gamma_to_1[palette[i].red];
  167746. png_composite(w, v, png_ptr->trans[i], back_1.red);
  167747. palette[i].red = png_ptr->gamma_from_1[w];
  167748. v = png_ptr->gamma_to_1[palette[i].green];
  167749. png_composite(w, v, png_ptr->trans[i], back_1.green);
  167750. palette[i].green = png_ptr->gamma_from_1[w];
  167751. v = png_ptr->gamma_to_1[palette[i].blue];
  167752. png_composite(w, v, png_ptr->trans[i], back_1.blue);
  167753. palette[i].blue = png_ptr->gamma_from_1[w];
  167754. }
  167755. }
  167756. else
  167757. {
  167758. palette[i].red = png_ptr->gamma_table[palette[i].red];
  167759. palette[i].green = png_ptr->gamma_table[palette[i].green];
  167760. palette[i].blue = png_ptr->gamma_table[palette[i].blue];
  167761. }
  167762. }
  167763. }
  167764. else
  167765. {
  167766. double m = (double)(((png_uint_32)1 << png_ptr->bit_depth) - 1);
  167767. double g = 1.0;
  167768. double gs = 1.0;
  167769. switch (png_ptr->background_gamma_type)
  167770. {
  167771. case PNG_BACKGROUND_GAMMA_SCREEN:
  167772. g = (png_ptr->screen_gamma);
  167773. gs = 1.0;
  167774. break;
  167775. case PNG_BACKGROUND_GAMMA_FILE:
  167776. g = 1.0 / (png_ptr->gamma);
  167777. gs = 1.0 / (png_ptr->gamma * png_ptr->screen_gamma);
  167778. break;
  167779. case PNG_BACKGROUND_GAMMA_UNIQUE:
  167780. g = 1.0 / (png_ptr->background_gamma);
  167781. gs = 1.0 / (png_ptr->background_gamma *
  167782. png_ptr->screen_gamma);
  167783. break;
  167784. }
  167785. png_ptr->background_1.gray = (png_uint_16)(pow(
  167786. (double)png_ptr->background.gray / m, g) * m + .5);
  167787. png_ptr->background.gray = (png_uint_16)(pow(
  167788. (double)png_ptr->background.gray / m, gs) * m + .5);
  167789. if ((png_ptr->background.red != png_ptr->background.green) ||
  167790. (png_ptr->background.red != png_ptr->background.blue) ||
  167791. (png_ptr->background.red != png_ptr->background.gray))
  167792. {
  167793. png_ptr->background_1.red = (png_uint_16)(pow(
  167794. (double)png_ptr->background.red / m, g) * m + .5);
  167795. png_ptr->background_1.green = (png_uint_16)(pow(
  167796. (double)png_ptr->background.green / m, g) * m + .5);
  167797. png_ptr->background_1.blue = (png_uint_16)(pow(
  167798. (double)png_ptr->background.blue / m, g) * m + .5);
  167799. png_ptr->background.red = (png_uint_16)(pow(
  167800. (double)png_ptr->background.red / m, gs) * m + .5);
  167801. png_ptr->background.green = (png_uint_16)(pow(
  167802. (double)png_ptr->background.green / m, gs) * m + .5);
  167803. png_ptr->background.blue = (png_uint_16)(pow(
  167804. (double)png_ptr->background.blue / m, gs) * m + .5);
  167805. }
  167806. else
  167807. {
  167808. png_ptr->background_1.red = png_ptr->background_1.green
  167809. = png_ptr->background_1.blue = png_ptr->background_1.gray;
  167810. png_ptr->background.red = png_ptr->background.green
  167811. = png_ptr->background.blue = png_ptr->background.gray;
  167812. }
  167813. }
  167814. }
  167815. else
  167816. #endif /* PNG_READ_BACKGROUND_SUPPORTED */
  167817. if (color_type == PNG_COLOR_TYPE_PALETTE)
  167818. {
  167819. png_colorp palette = png_ptr->palette;
  167820. int num_palette = png_ptr->num_palette;
  167821. int i;
  167822. for (i = 0; i < num_palette; i++)
  167823. {
  167824. palette[i].red = png_ptr->gamma_table[palette[i].red];
  167825. palette[i].green = png_ptr->gamma_table[palette[i].green];
  167826. palette[i].blue = png_ptr->gamma_table[palette[i].blue];
  167827. }
  167828. }
  167829. }
  167830. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  167831. else
  167832. #endif
  167833. #endif /* PNG_READ_GAMMA_SUPPORTED && PNG_FLOATING_POINT_SUPPORTED */
  167834. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  167835. if ((png_ptr->transformations & PNG_BACKGROUND) &&
  167836. (color_type == PNG_COLOR_TYPE_PALETTE))
  167837. {
  167838. int i;
  167839. int istop = (int)png_ptr->num_trans;
  167840. png_color back;
  167841. png_colorp palette = png_ptr->palette;
  167842. back.red = (png_byte)png_ptr->background.red;
  167843. back.green = (png_byte)png_ptr->background.green;
  167844. back.blue = (png_byte)png_ptr->background.blue;
  167845. for (i = 0; i < istop; i++)
  167846. {
  167847. if (png_ptr->trans[i] == 0)
  167848. {
  167849. palette[i] = back;
  167850. }
  167851. else if (png_ptr->trans[i] != 0xff)
  167852. {
  167853. png_composite(palette[i].red, palette[i].red,
  167854. png_ptr->trans[i], back.red);
  167855. png_composite(palette[i].green, palette[i].green,
  167856. png_ptr->trans[i], back.green);
  167857. png_composite(palette[i].blue, palette[i].blue,
  167858. png_ptr->trans[i], back.blue);
  167859. }
  167860. }
  167861. }
  167862. #endif /* PNG_READ_BACKGROUND_SUPPORTED */
  167863. #if defined(PNG_READ_SHIFT_SUPPORTED)
  167864. if ((png_ptr->transformations & PNG_SHIFT) &&
  167865. (color_type == PNG_COLOR_TYPE_PALETTE))
  167866. {
  167867. png_uint_16 i;
  167868. png_uint_16 istop = png_ptr->num_palette;
  167869. int sr = 8 - png_ptr->sig_bit.red;
  167870. int sg = 8 - png_ptr->sig_bit.green;
  167871. int sb = 8 - png_ptr->sig_bit.blue;
  167872. if (sr < 0 || sr > 8)
  167873. sr = 0;
  167874. if (sg < 0 || sg > 8)
  167875. sg = 0;
  167876. if (sb < 0 || sb > 8)
  167877. sb = 0;
  167878. for (i = 0; i < istop; i++)
  167879. {
  167880. png_ptr->palette[i].red >>= sr;
  167881. png_ptr->palette[i].green >>= sg;
  167882. png_ptr->palette[i].blue >>= sb;
  167883. }
  167884. }
  167885. #endif /* PNG_READ_SHIFT_SUPPORTED */
  167886. }
  167887. #if !defined(PNG_READ_GAMMA_SUPPORTED) && !defined(PNG_READ_SHIFT_SUPPORTED) \
  167888. && !defined(PNG_READ_BACKGROUND_SUPPORTED)
  167889. if(png_ptr)
  167890. return;
  167891. #endif
  167892. }
  167893. void /* PRIVATE */
  167894. png_read_transform_info(png_structp png_ptr, png_infop info_ptr)
  167895. {
  167896. png_debug(1, "in png_read_transform_info\n");
  167897. #if defined(PNG_READ_EXPAND_SUPPORTED)
  167898. if (png_ptr->transformations & PNG_EXPAND)
  167899. {
  167900. if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  167901. {
  167902. if (png_ptr->num_trans && (png_ptr->transformations & PNG_EXPAND_tRNS))
  167903. info_ptr->color_type = PNG_COLOR_TYPE_RGB_ALPHA;
  167904. else
  167905. info_ptr->color_type = PNG_COLOR_TYPE_RGB;
  167906. info_ptr->bit_depth = 8;
  167907. info_ptr->num_trans = 0;
  167908. }
  167909. else
  167910. {
  167911. if (png_ptr->num_trans)
  167912. {
  167913. if (png_ptr->transformations & PNG_EXPAND_tRNS)
  167914. info_ptr->color_type |= PNG_COLOR_MASK_ALPHA;
  167915. else
  167916. info_ptr->color_type |= PNG_COLOR_MASK_COLOR;
  167917. }
  167918. if (info_ptr->bit_depth < 8)
  167919. info_ptr->bit_depth = 8;
  167920. info_ptr->num_trans = 0;
  167921. }
  167922. }
  167923. #endif
  167924. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  167925. if (png_ptr->transformations & PNG_BACKGROUND)
  167926. {
  167927. info_ptr->color_type &= ~PNG_COLOR_MASK_ALPHA;
  167928. info_ptr->num_trans = 0;
  167929. info_ptr->background = png_ptr->background;
  167930. }
  167931. #endif
  167932. #if defined(PNG_READ_GAMMA_SUPPORTED)
  167933. if (png_ptr->transformations & PNG_GAMMA)
  167934. {
  167935. #ifdef PNG_FLOATING_POINT_SUPPORTED
  167936. info_ptr->gamma = png_ptr->gamma;
  167937. #endif
  167938. #ifdef PNG_FIXED_POINT_SUPPORTED
  167939. info_ptr->int_gamma = png_ptr->int_gamma;
  167940. #endif
  167941. }
  167942. #endif
  167943. #if defined(PNG_READ_16_TO_8_SUPPORTED)
  167944. if ((png_ptr->transformations & PNG_16_TO_8) && (info_ptr->bit_depth == 16))
  167945. info_ptr->bit_depth = 8;
  167946. #endif
  167947. #if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
  167948. if (png_ptr->transformations & PNG_GRAY_TO_RGB)
  167949. info_ptr->color_type |= PNG_COLOR_MASK_COLOR;
  167950. #endif
  167951. #if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
  167952. if (png_ptr->transformations & PNG_RGB_TO_GRAY)
  167953. info_ptr->color_type &= ~PNG_COLOR_MASK_COLOR;
  167954. #endif
  167955. #if defined(PNG_READ_DITHER_SUPPORTED)
  167956. if (png_ptr->transformations & PNG_DITHER)
  167957. {
  167958. if (((info_ptr->color_type == PNG_COLOR_TYPE_RGB) ||
  167959. (info_ptr->color_type == PNG_COLOR_TYPE_RGB_ALPHA)) &&
  167960. png_ptr->palette_lookup && info_ptr->bit_depth == 8)
  167961. {
  167962. info_ptr->color_type = PNG_COLOR_TYPE_PALETTE;
  167963. }
  167964. }
  167965. #endif
  167966. #if defined(PNG_READ_PACK_SUPPORTED)
  167967. if ((png_ptr->transformations & PNG_PACK) && (info_ptr->bit_depth < 8))
  167968. info_ptr->bit_depth = 8;
  167969. #endif
  167970. if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  167971. info_ptr->channels = 1;
  167972. else if (info_ptr->color_type & PNG_COLOR_MASK_COLOR)
  167973. info_ptr->channels = 3;
  167974. else
  167975. info_ptr->channels = 1;
  167976. #if defined(PNG_READ_STRIP_ALPHA_SUPPORTED)
  167977. if (png_ptr->flags & PNG_FLAG_STRIP_ALPHA)
  167978. info_ptr->color_type &= ~PNG_COLOR_MASK_ALPHA;
  167979. #endif
  167980. if (info_ptr->color_type & PNG_COLOR_MASK_ALPHA)
  167981. info_ptr->channels++;
  167982. #if defined(PNG_READ_FILLER_SUPPORTED)
  167983. if ((png_ptr->transformations & PNG_FILLER) &&
  167984. ((info_ptr->color_type == PNG_COLOR_TYPE_RGB) ||
  167985. (info_ptr->color_type == PNG_COLOR_TYPE_GRAY)))
  167986. {
  167987. info_ptr->channels++;
  167988. #if !defined(PNG_1_0_X)
  167989. if (png_ptr->transformations & PNG_ADD_ALPHA)
  167990. info_ptr->color_type |= PNG_COLOR_MASK_ALPHA;
  167991. #endif
  167992. }
  167993. #endif
  167994. #if defined(PNG_USER_TRANSFORM_PTR_SUPPORTED) && \
  167995. defined(PNG_READ_USER_TRANSFORM_SUPPORTED)
  167996. if(png_ptr->transformations & PNG_USER_TRANSFORM)
  167997. {
  167998. if(info_ptr->bit_depth < png_ptr->user_transform_depth)
  167999. info_ptr->bit_depth = png_ptr->user_transform_depth;
  168000. if(info_ptr->channels < png_ptr->user_transform_channels)
  168001. info_ptr->channels = png_ptr->user_transform_channels;
  168002. }
  168003. #endif
  168004. info_ptr->pixel_depth = (png_byte)(info_ptr->channels *
  168005. info_ptr->bit_depth);
  168006. info_ptr->rowbytes = PNG_ROWBYTES(info_ptr->pixel_depth,info_ptr->width);
  168007. #if !defined(PNG_READ_EXPAND_SUPPORTED)
  168008. if(png_ptr)
  168009. return;
  168010. #endif
  168011. }
  168012. void /* PRIVATE */
  168013. png_do_read_transformations(png_structp png_ptr)
  168014. {
  168015. png_debug(1, "in png_do_read_transformations\n");
  168016. if (png_ptr->row_buf == NULL)
  168017. {
  168018. #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)
  168019. char msg[50];
  168020. png_snprintf2(msg, 50,
  168021. "NULL row buffer for row %ld, pass %d", png_ptr->row_number,
  168022. png_ptr->pass);
  168023. png_error(png_ptr, msg);
  168024. #else
  168025. png_error(png_ptr, "NULL row buffer");
  168026. #endif
  168027. }
  168028. #ifdef PNG_WARN_UNINITIALIZED_ROW
  168029. if (!(png_ptr->flags & PNG_FLAG_ROW_INIT))
  168030. #if (PNG_WARN_UNINITIALIZED_ROW==1)
  168031. png_error(png_ptr, "Uninitialized row");
  168032. #else
  168033. png_warning(png_ptr, "Uninitialized row");
  168034. #endif
  168035. #endif
  168036. #if defined(PNG_READ_EXPAND_SUPPORTED)
  168037. if (png_ptr->transformations & PNG_EXPAND)
  168038. {
  168039. if (png_ptr->row_info.color_type == PNG_COLOR_TYPE_PALETTE)
  168040. {
  168041. png_do_expand_palette(&(png_ptr->row_info), png_ptr->row_buf + 1,
  168042. png_ptr->palette, png_ptr->trans, png_ptr->num_trans);
  168043. }
  168044. else
  168045. {
  168046. if (png_ptr->num_trans &&
  168047. (png_ptr->transformations & PNG_EXPAND_tRNS))
  168048. png_do_expand(&(png_ptr->row_info), png_ptr->row_buf + 1,
  168049. &(png_ptr->trans_values));
  168050. else
  168051. png_do_expand(&(png_ptr->row_info), png_ptr->row_buf + 1,
  168052. NULL);
  168053. }
  168054. }
  168055. #endif
  168056. #if defined(PNG_READ_STRIP_ALPHA_SUPPORTED)
  168057. if (png_ptr->flags & PNG_FLAG_STRIP_ALPHA)
  168058. png_do_strip_filler(&(png_ptr->row_info), png_ptr->row_buf + 1,
  168059. PNG_FLAG_FILLER_AFTER | (png_ptr->flags & PNG_FLAG_STRIP_ALPHA));
  168060. #endif
  168061. #if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
  168062. if (png_ptr->transformations & PNG_RGB_TO_GRAY)
  168063. {
  168064. int rgb_error =
  168065. png_do_rgb_to_gray(png_ptr, &(png_ptr->row_info), png_ptr->row_buf + 1);
  168066. if(rgb_error)
  168067. {
  168068. png_ptr->rgb_to_gray_status=1;
  168069. if((png_ptr->transformations & PNG_RGB_TO_GRAY) ==
  168070. PNG_RGB_TO_GRAY_WARN)
  168071. png_warning(png_ptr, "png_do_rgb_to_gray found nongray pixel");
  168072. if((png_ptr->transformations & PNG_RGB_TO_GRAY) ==
  168073. PNG_RGB_TO_GRAY_ERR)
  168074. png_error(png_ptr, "png_do_rgb_to_gray found nongray pixel");
  168075. }
  168076. }
  168077. #endif
  168078. #if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
  168079. if ((png_ptr->transformations & PNG_GRAY_TO_RGB) &&
  168080. !(png_ptr->mode & PNG_BACKGROUND_IS_GRAY))
  168081. png_do_gray_to_rgb(&(png_ptr->row_info), png_ptr->row_buf + 1);
  168082. #endif
  168083. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  168084. if ((png_ptr->transformations & PNG_BACKGROUND) &&
  168085. ((png_ptr->num_trans != 0 ) ||
  168086. (png_ptr->color_type & PNG_COLOR_MASK_ALPHA)))
  168087. png_do_background(&(png_ptr->row_info), png_ptr->row_buf + 1,
  168088. &(png_ptr->trans_values), &(png_ptr->background)
  168089. #if defined(PNG_READ_GAMMA_SUPPORTED)
  168090. , &(png_ptr->background_1),
  168091. png_ptr->gamma_table, png_ptr->gamma_from_1,
  168092. png_ptr->gamma_to_1, png_ptr->gamma_16_table,
  168093. png_ptr->gamma_16_from_1, png_ptr->gamma_16_to_1,
  168094. png_ptr->gamma_shift
  168095. #endif
  168096. );
  168097. #endif
  168098. #if defined(PNG_READ_GAMMA_SUPPORTED)
  168099. if ((png_ptr->transformations & PNG_GAMMA) &&
  168100. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  168101. !((png_ptr->transformations & PNG_BACKGROUND) &&
  168102. ((png_ptr->num_trans != 0) ||
  168103. (png_ptr->color_type & PNG_COLOR_MASK_ALPHA))) &&
  168104. #endif
  168105. (png_ptr->color_type != PNG_COLOR_TYPE_PALETTE))
  168106. png_do_gamma(&(png_ptr->row_info), png_ptr->row_buf + 1,
  168107. png_ptr->gamma_table, png_ptr->gamma_16_table,
  168108. png_ptr->gamma_shift);
  168109. #endif
  168110. #if defined(PNG_READ_16_TO_8_SUPPORTED)
  168111. if (png_ptr->transformations & PNG_16_TO_8)
  168112. png_do_chop(&(png_ptr->row_info), png_ptr->row_buf + 1);
  168113. #endif
  168114. #if defined(PNG_READ_DITHER_SUPPORTED)
  168115. if (png_ptr->transformations & PNG_DITHER)
  168116. {
  168117. png_do_dither((png_row_infop)&(png_ptr->row_info), png_ptr->row_buf + 1,
  168118. png_ptr->palette_lookup, png_ptr->dither_index);
  168119. if(png_ptr->row_info.rowbytes == (png_uint_32)0)
  168120. png_error(png_ptr, "png_do_dither returned rowbytes=0");
  168121. }
  168122. #endif
  168123. #if defined(PNG_READ_INVERT_SUPPORTED)
  168124. if (png_ptr->transformations & PNG_INVERT_MONO)
  168125. png_do_invert(&(png_ptr->row_info), png_ptr->row_buf + 1);
  168126. #endif
  168127. #if defined(PNG_READ_SHIFT_SUPPORTED)
  168128. if (png_ptr->transformations & PNG_SHIFT)
  168129. png_do_unshift(&(png_ptr->row_info), png_ptr->row_buf + 1,
  168130. &(png_ptr->shift));
  168131. #endif
  168132. #if defined(PNG_READ_PACK_SUPPORTED)
  168133. if (png_ptr->transformations & PNG_PACK)
  168134. png_do_unpack(&(png_ptr->row_info), png_ptr->row_buf + 1);
  168135. #endif
  168136. #if defined(PNG_READ_BGR_SUPPORTED)
  168137. if (png_ptr->transformations & PNG_BGR)
  168138. png_do_bgr(&(png_ptr->row_info), png_ptr->row_buf + 1);
  168139. #endif
  168140. #if defined(PNG_READ_PACKSWAP_SUPPORTED)
  168141. if (png_ptr->transformations & PNG_PACKSWAP)
  168142. png_do_packswap(&(png_ptr->row_info), png_ptr->row_buf + 1);
  168143. #endif
  168144. #if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
  168145. if ((png_ptr->transformations & PNG_GRAY_TO_RGB) &&
  168146. (png_ptr->mode & PNG_BACKGROUND_IS_GRAY))
  168147. png_do_gray_to_rgb(&(png_ptr->row_info), png_ptr->row_buf + 1);
  168148. #endif
  168149. #if defined(PNG_READ_FILLER_SUPPORTED)
  168150. if (png_ptr->transformations & PNG_FILLER)
  168151. png_do_read_filler(&(png_ptr->row_info), png_ptr->row_buf + 1,
  168152. (png_uint_32)png_ptr->filler, png_ptr->flags);
  168153. #endif
  168154. #if defined(PNG_READ_INVERT_ALPHA_SUPPORTED)
  168155. if (png_ptr->transformations & PNG_INVERT_ALPHA)
  168156. png_do_read_invert_alpha(&(png_ptr->row_info), png_ptr->row_buf + 1);
  168157. #endif
  168158. #if defined(PNG_READ_SWAP_ALPHA_SUPPORTED)
  168159. if (png_ptr->transformations & PNG_SWAP_ALPHA)
  168160. png_do_read_swap_alpha(&(png_ptr->row_info), png_ptr->row_buf + 1);
  168161. #endif
  168162. #if defined(PNG_READ_SWAP_SUPPORTED)
  168163. if (png_ptr->transformations & PNG_SWAP_BYTES)
  168164. png_do_swap(&(png_ptr->row_info), png_ptr->row_buf + 1);
  168165. #endif
  168166. #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED)
  168167. if (png_ptr->transformations & PNG_USER_TRANSFORM)
  168168. {
  168169. if(png_ptr->read_user_transform_fn != NULL)
  168170. (*(png_ptr->read_user_transform_fn)) /* user read transform function */
  168171. (png_ptr, /* png_ptr */
  168172. &(png_ptr->row_info), /* row_info: */
  168173. png_ptr->row_buf + 1); /* start of pixel data for row */
  168174. #if defined(PNG_USER_TRANSFORM_PTR_SUPPORTED)
  168175. if(png_ptr->user_transform_depth)
  168176. png_ptr->row_info.bit_depth = png_ptr->user_transform_depth;
  168177. if(png_ptr->user_transform_channels)
  168178. png_ptr->row_info.channels = png_ptr->user_transform_channels;
  168179. #endif
  168180. png_ptr->row_info.pixel_depth = (png_byte)(png_ptr->row_info.bit_depth *
  168181. png_ptr->row_info.channels);
  168182. png_ptr->row_info.rowbytes = PNG_ROWBYTES(png_ptr->row_info.pixel_depth,
  168183. png_ptr->row_info.width);
  168184. }
  168185. #endif
  168186. }
  168187. #if defined(PNG_READ_PACK_SUPPORTED)
  168188. void /* PRIVATE */
  168189. png_do_unpack(png_row_infop row_info, png_bytep row)
  168190. {
  168191. png_debug(1, "in png_do_unpack\n");
  168192. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  168193. if (row != NULL && row_info != NULL && row_info->bit_depth < 8)
  168194. #else
  168195. if (row_info->bit_depth < 8)
  168196. #endif
  168197. {
  168198. png_uint_32 i;
  168199. png_uint_32 row_width=row_info->width;
  168200. switch (row_info->bit_depth)
  168201. {
  168202. case 1:
  168203. {
  168204. png_bytep sp = row + (png_size_t)((row_width - 1) >> 3);
  168205. png_bytep dp = row + (png_size_t)row_width - 1;
  168206. png_uint_32 shift = 7 - (int)((row_width + 7) & 0x07);
  168207. for (i = 0; i < row_width; i++)
  168208. {
  168209. *dp = (png_byte)((*sp >> shift) & 0x01);
  168210. if (shift == 7)
  168211. {
  168212. shift = 0;
  168213. sp--;
  168214. }
  168215. else
  168216. shift++;
  168217. dp--;
  168218. }
  168219. break;
  168220. }
  168221. case 2:
  168222. {
  168223. png_bytep sp = row + (png_size_t)((row_width - 1) >> 2);
  168224. png_bytep dp = row + (png_size_t)row_width - 1;
  168225. png_uint_32 shift = (int)((3 - ((row_width + 3) & 0x03)) << 1);
  168226. for (i = 0; i < row_width; i++)
  168227. {
  168228. *dp = (png_byte)((*sp >> shift) & 0x03);
  168229. if (shift == 6)
  168230. {
  168231. shift = 0;
  168232. sp--;
  168233. }
  168234. else
  168235. shift += 2;
  168236. dp--;
  168237. }
  168238. break;
  168239. }
  168240. case 4:
  168241. {
  168242. png_bytep sp = row + (png_size_t)((row_width - 1) >> 1);
  168243. png_bytep dp = row + (png_size_t)row_width - 1;
  168244. png_uint_32 shift = (int)((1 - ((row_width + 1) & 0x01)) << 2);
  168245. for (i = 0; i < row_width; i++)
  168246. {
  168247. *dp = (png_byte)((*sp >> shift) & 0x0f);
  168248. if (shift == 4)
  168249. {
  168250. shift = 0;
  168251. sp--;
  168252. }
  168253. else
  168254. shift = 4;
  168255. dp--;
  168256. }
  168257. break;
  168258. }
  168259. }
  168260. row_info->bit_depth = 8;
  168261. row_info->pixel_depth = (png_byte)(8 * row_info->channels);
  168262. row_info->rowbytes = row_width * row_info->channels;
  168263. }
  168264. }
  168265. #endif
  168266. #if defined(PNG_READ_SHIFT_SUPPORTED)
  168267. void /* PRIVATE */
  168268. png_do_unshift(png_row_infop row_info, png_bytep row, png_color_8p sig_bits)
  168269. {
  168270. png_debug(1, "in png_do_unshift\n");
  168271. if (
  168272. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  168273. row != NULL && row_info != NULL && sig_bits != NULL &&
  168274. #endif
  168275. row_info->color_type != PNG_COLOR_TYPE_PALETTE)
  168276. {
  168277. int shift[4];
  168278. int channels = 0;
  168279. int c;
  168280. png_uint_16 value = 0;
  168281. png_uint_32 row_width = row_info->width;
  168282. if (row_info->color_type & PNG_COLOR_MASK_COLOR)
  168283. {
  168284. shift[channels++] = row_info->bit_depth - sig_bits->red;
  168285. shift[channels++] = row_info->bit_depth - sig_bits->green;
  168286. shift[channels++] = row_info->bit_depth - sig_bits->blue;
  168287. }
  168288. else
  168289. {
  168290. shift[channels++] = row_info->bit_depth - sig_bits->gray;
  168291. }
  168292. if (row_info->color_type & PNG_COLOR_MASK_ALPHA)
  168293. {
  168294. shift[channels++] = row_info->bit_depth - sig_bits->alpha;
  168295. }
  168296. for (c = 0; c < channels; c++)
  168297. {
  168298. if (shift[c] <= 0)
  168299. shift[c] = 0;
  168300. else
  168301. value = 1;
  168302. }
  168303. if (!value)
  168304. return;
  168305. switch (row_info->bit_depth)
  168306. {
  168307. case 2:
  168308. {
  168309. png_bytep bp;
  168310. png_uint_32 i;
  168311. png_uint_32 istop = row_info->rowbytes;
  168312. for (bp = row, i = 0; i < istop; i++)
  168313. {
  168314. *bp >>= 1;
  168315. *bp++ &= 0x55;
  168316. }
  168317. break;
  168318. }
  168319. case 4:
  168320. {
  168321. png_bytep bp = row;
  168322. png_uint_32 i;
  168323. png_uint_32 istop = row_info->rowbytes;
  168324. png_byte mask = (png_byte)((((int)0xf0 >> shift[0]) & (int)0xf0) |
  168325. (png_byte)((int)0xf >> shift[0]));
  168326. for (i = 0; i < istop; i++)
  168327. {
  168328. *bp >>= shift[0];
  168329. *bp++ &= mask;
  168330. }
  168331. break;
  168332. }
  168333. case 8:
  168334. {
  168335. png_bytep bp = row;
  168336. png_uint_32 i;
  168337. png_uint_32 istop = row_width * channels;
  168338. for (i = 0; i < istop; i++)
  168339. {
  168340. *bp++ >>= shift[i%channels];
  168341. }
  168342. break;
  168343. }
  168344. case 16:
  168345. {
  168346. png_bytep bp = row;
  168347. png_uint_32 i;
  168348. png_uint_32 istop = channels * row_width;
  168349. for (i = 0; i < istop; i++)
  168350. {
  168351. value = (png_uint_16)((*bp << 8) + *(bp + 1));
  168352. value >>= shift[i%channels];
  168353. *bp++ = (png_byte)(value >> 8);
  168354. *bp++ = (png_byte)(value & 0xff);
  168355. }
  168356. break;
  168357. }
  168358. }
  168359. }
  168360. }
  168361. #endif
  168362. #if defined(PNG_READ_16_TO_8_SUPPORTED)
  168363. void /* PRIVATE */
  168364. png_do_chop(png_row_infop row_info, png_bytep row)
  168365. {
  168366. png_debug(1, "in png_do_chop\n");
  168367. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  168368. if (row != NULL && row_info != NULL && row_info->bit_depth == 16)
  168369. #else
  168370. if (row_info->bit_depth == 16)
  168371. #endif
  168372. {
  168373. png_bytep sp = row;
  168374. png_bytep dp = row;
  168375. png_uint_32 i;
  168376. png_uint_32 istop = row_info->width * row_info->channels;
  168377. for (i = 0; i<istop; i++, sp += 2, dp++)
  168378. {
  168379. #if defined(PNG_READ_16_TO_8_ACCURATE_SCALE_SUPPORTED)
  168380. *dp = *sp + ((((int)(*(sp + 1)) - *sp) > 128) ? 1 : 0);
  168381. #else
  168382. *dp = *sp;
  168383. #endif
  168384. }
  168385. row_info->bit_depth = 8;
  168386. row_info->pixel_depth = (png_byte)(8 * row_info->channels);
  168387. row_info->rowbytes = row_info->width * row_info->channels;
  168388. }
  168389. }
  168390. #endif
  168391. #if defined(PNG_READ_SWAP_ALPHA_SUPPORTED)
  168392. void /* PRIVATE */
  168393. png_do_read_swap_alpha(png_row_infop row_info, png_bytep row)
  168394. {
  168395. png_debug(1, "in png_do_read_swap_alpha\n");
  168396. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  168397. if (row != NULL && row_info != NULL)
  168398. #endif
  168399. {
  168400. png_uint_32 row_width = row_info->width;
  168401. if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  168402. {
  168403. if (row_info->bit_depth == 8)
  168404. {
  168405. png_bytep sp = row + row_info->rowbytes;
  168406. png_bytep dp = sp;
  168407. png_byte save;
  168408. png_uint_32 i;
  168409. for (i = 0; i < row_width; i++)
  168410. {
  168411. save = *(--sp);
  168412. *(--dp) = *(--sp);
  168413. *(--dp) = *(--sp);
  168414. *(--dp) = *(--sp);
  168415. *(--dp) = save;
  168416. }
  168417. }
  168418. else
  168419. {
  168420. png_bytep sp = row + row_info->rowbytes;
  168421. png_bytep dp = sp;
  168422. png_byte save[2];
  168423. png_uint_32 i;
  168424. for (i = 0; i < row_width; i++)
  168425. {
  168426. save[0] = *(--sp);
  168427. save[1] = *(--sp);
  168428. *(--dp) = *(--sp);
  168429. *(--dp) = *(--sp);
  168430. *(--dp) = *(--sp);
  168431. *(--dp) = *(--sp);
  168432. *(--dp) = *(--sp);
  168433. *(--dp) = *(--sp);
  168434. *(--dp) = save[0];
  168435. *(--dp) = save[1];
  168436. }
  168437. }
  168438. }
  168439. else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
  168440. {
  168441. if (row_info->bit_depth == 8)
  168442. {
  168443. png_bytep sp = row + row_info->rowbytes;
  168444. png_bytep dp = sp;
  168445. png_byte save;
  168446. png_uint_32 i;
  168447. for (i = 0; i < row_width; i++)
  168448. {
  168449. save = *(--sp);
  168450. *(--dp) = *(--sp);
  168451. *(--dp) = save;
  168452. }
  168453. }
  168454. else
  168455. {
  168456. png_bytep sp = row + row_info->rowbytes;
  168457. png_bytep dp = sp;
  168458. png_byte save[2];
  168459. png_uint_32 i;
  168460. for (i = 0; i < row_width; i++)
  168461. {
  168462. save[0] = *(--sp);
  168463. save[1] = *(--sp);
  168464. *(--dp) = *(--sp);
  168465. *(--dp) = *(--sp);
  168466. *(--dp) = save[0];
  168467. *(--dp) = save[1];
  168468. }
  168469. }
  168470. }
  168471. }
  168472. }
  168473. #endif
  168474. #if defined(PNG_READ_INVERT_ALPHA_SUPPORTED)
  168475. void /* PRIVATE */
  168476. png_do_read_invert_alpha(png_row_infop row_info, png_bytep row)
  168477. {
  168478. png_debug(1, "in png_do_read_invert_alpha\n");
  168479. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  168480. if (row != NULL && row_info != NULL)
  168481. #endif
  168482. {
  168483. png_uint_32 row_width = row_info->width;
  168484. if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  168485. {
  168486. if (row_info->bit_depth == 8)
  168487. {
  168488. png_bytep sp = row + row_info->rowbytes;
  168489. png_bytep dp = sp;
  168490. png_uint_32 i;
  168491. for (i = 0; i < row_width; i++)
  168492. {
  168493. *(--dp) = (png_byte)(255 - *(--sp));
  168494. sp-=3;
  168495. dp=sp;
  168496. }
  168497. }
  168498. else
  168499. {
  168500. png_bytep sp = row + row_info->rowbytes;
  168501. png_bytep dp = sp;
  168502. png_uint_32 i;
  168503. for (i = 0; i < row_width; i++)
  168504. {
  168505. *(--dp) = (png_byte)(255 - *(--sp));
  168506. *(--dp) = (png_byte)(255 - *(--sp));
  168507. sp-=6;
  168508. dp=sp;
  168509. }
  168510. }
  168511. }
  168512. else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
  168513. {
  168514. if (row_info->bit_depth == 8)
  168515. {
  168516. png_bytep sp = row + row_info->rowbytes;
  168517. png_bytep dp = sp;
  168518. png_uint_32 i;
  168519. for (i = 0; i < row_width; i++)
  168520. {
  168521. *(--dp) = (png_byte)(255 - *(--sp));
  168522. *(--dp) = *(--sp);
  168523. }
  168524. }
  168525. else
  168526. {
  168527. png_bytep sp = row + row_info->rowbytes;
  168528. png_bytep dp = sp;
  168529. png_uint_32 i;
  168530. for (i = 0; i < row_width; i++)
  168531. {
  168532. *(--dp) = (png_byte)(255 - *(--sp));
  168533. *(--dp) = (png_byte)(255 - *(--sp));
  168534. sp-=2;
  168535. dp=sp;
  168536. }
  168537. }
  168538. }
  168539. }
  168540. }
  168541. #endif
  168542. #if defined(PNG_READ_FILLER_SUPPORTED)
  168543. void /* PRIVATE */
  168544. png_do_read_filler(png_row_infop row_info, png_bytep row,
  168545. png_uint_32 filler, png_uint_32 flags)
  168546. {
  168547. png_uint_32 i;
  168548. png_uint_32 row_width = row_info->width;
  168549. png_byte hi_filler = (png_byte)((filler>>8) & 0xff);
  168550. png_byte lo_filler = (png_byte)(filler & 0xff);
  168551. png_debug(1, "in png_do_read_filler\n");
  168552. if (
  168553. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  168554. row != NULL && row_info != NULL &&
  168555. #endif
  168556. row_info->color_type == PNG_COLOR_TYPE_GRAY)
  168557. {
  168558. if(row_info->bit_depth == 8)
  168559. {
  168560. if (flags & PNG_FLAG_FILLER_AFTER)
  168561. {
  168562. png_bytep sp = row + (png_size_t)row_width;
  168563. png_bytep dp = sp + (png_size_t)row_width;
  168564. for (i = 1; i < row_width; i++)
  168565. {
  168566. *(--dp) = lo_filler;
  168567. *(--dp) = *(--sp);
  168568. }
  168569. *(--dp) = lo_filler;
  168570. row_info->channels = 2;
  168571. row_info->pixel_depth = 16;
  168572. row_info->rowbytes = row_width * 2;
  168573. }
  168574. else
  168575. {
  168576. png_bytep sp = row + (png_size_t)row_width;
  168577. png_bytep dp = sp + (png_size_t)row_width;
  168578. for (i = 0; i < row_width; i++)
  168579. {
  168580. *(--dp) = *(--sp);
  168581. *(--dp) = lo_filler;
  168582. }
  168583. row_info->channels = 2;
  168584. row_info->pixel_depth = 16;
  168585. row_info->rowbytes = row_width * 2;
  168586. }
  168587. }
  168588. else if(row_info->bit_depth == 16)
  168589. {
  168590. if (flags & PNG_FLAG_FILLER_AFTER)
  168591. {
  168592. png_bytep sp = row + (png_size_t)row_width * 2;
  168593. png_bytep dp = sp + (png_size_t)row_width * 2;
  168594. for (i = 1; i < row_width; i++)
  168595. {
  168596. *(--dp) = hi_filler;
  168597. *(--dp) = lo_filler;
  168598. *(--dp) = *(--sp);
  168599. *(--dp) = *(--sp);
  168600. }
  168601. *(--dp) = hi_filler;
  168602. *(--dp) = lo_filler;
  168603. row_info->channels = 2;
  168604. row_info->pixel_depth = 32;
  168605. row_info->rowbytes = row_width * 4;
  168606. }
  168607. else
  168608. {
  168609. png_bytep sp = row + (png_size_t)row_width * 2;
  168610. png_bytep dp = sp + (png_size_t)row_width * 2;
  168611. for (i = 0; i < row_width; i++)
  168612. {
  168613. *(--dp) = *(--sp);
  168614. *(--dp) = *(--sp);
  168615. *(--dp) = hi_filler;
  168616. *(--dp) = lo_filler;
  168617. }
  168618. row_info->channels = 2;
  168619. row_info->pixel_depth = 32;
  168620. row_info->rowbytes = row_width * 4;
  168621. }
  168622. }
  168623. } /* COLOR_TYPE == GRAY */
  168624. else if (row_info->color_type == PNG_COLOR_TYPE_RGB)
  168625. {
  168626. if(row_info->bit_depth == 8)
  168627. {
  168628. if (flags & PNG_FLAG_FILLER_AFTER)
  168629. {
  168630. png_bytep sp = row + (png_size_t)row_width * 3;
  168631. png_bytep dp = sp + (png_size_t)row_width;
  168632. for (i = 1; i < row_width; i++)
  168633. {
  168634. *(--dp) = lo_filler;
  168635. *(--dp) = *(--sp);
  168636. *(--dp) = *(--sp);
  168637. *(--dp) = *(--sp);
  168638. }
  168639. *(--dp) = lo_filler;
  168640. row_info->channels = 4;
  168641. row_info->pixel_depth = 32;
  168642. row_info->rowbytes = row_width * 4;
  168643. }
  168644. else
  168645. {
  168646. png_bytep sp = row + (png_size_t)row_width * 3;
  168647. png_bytep dp = sp + (png_size_t)row_width;
  168648. for (i = 0; i < row_width; i++)
  168649. {
  168650. *(--dp) = *(--sp);
  168651. *(--dp) = *(--sp);
  168652. *(--dp) = *(--sp);
  168653. *(--dp) = lo_filler;
  168654. }
  168655. row_info->channels = 4;
  168656. row_info->pixel_depth = 32;
  168657. row_info->rowbytes = row_width * 4;
  168658. }
  168659. }
  168660. else if(row_info->bit_depth == 16)
  168661. {
  168662. if (flags & PNG_FLAG_FILLER_AFTER)
  168663. {
  168664. png_bytep sp = row + (png_size_t)row_width * 6;
  168665. png_bytep dp = sp + (png_size_t)row_width * 2;
  168666. for (i = 1; i < row_width; i++)
  168667. {
  168668. *(--dp) = hi_filler;
  168669. *(--dp) = lo_filler;
  168670. *(--dp) = *(--sp);
  168671. *(--dp) = *(--sp);
  168672. *(--dp) = *(--sp);
  168673. *(--dp) = *(--sp);
  168674. *(--dp) = *(--sp);
  168675. *(--dp) = *(--sp);
  168676. }
  168677. *(--dp) = hi_filler;
  168678. *(--dp) = lo_filler;
  168679. row_info->channels = 4;
  168680. row_info->pixel_depth = 64;
  168681. row_info->rowbytes = row_width * 8;
  168682. }
  168683. else
  168684. {
  168685. png_bytep sp = row + (png_size_t)row_width * 6;
  168686. png_bytep dp = sp + (png_size_t)row_width * 2;
  168687. for (i = 0; i < row_width; i++)
  168688. {
  168689. *(--dp) = *(--sp);
  168690. *(--dp) = *(--sp);
  168691. *(--dp) = *(--sp);
  168692. *(--dp) = *(--sp);
  168693. *(--dp) = *(--sp);
  168694. *(--dp) = *(--sp);
  168695. *(--dp) = hi_filler;
  168696. *(--dp) = lo_filler;
  168697. }
  168698. row_info->channels = 4;
  168699. row_info->pixel_depth = 64;
  168700. row_info->rowbytes = row_width * 8;
  168701. }
  168702. }
  168703. } /* COLOR_TYPE == RGB */
  168704. }
  168705. #endif
  168706. #if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
  168707. void /* PRIVATE */
  168708. png_do_gray_to_rgb(png_row_infop row_info, png_bytep row)
  168709. {
  168710. png_uint_32 i;
  168711. png_uint_32 row_width = row_info->width;
  168712. png_debug(1, "in png_do_gray_to_rgb\n");
  168713. if (row_info->bit_depth >= 8 &&
  168714. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  168715. row != NULL && row_info != NULL &&
  168716. #endif
  168717. !(row_info->color_type & PNG_COLOR_MASK_COLOR))
  168718. {
  168719. if (row_info->color_type == PNG_COLOR_TYPE_GRAY)
  168720. {
  168721. if (row_info->bit_depth == 8)
  168722. {
  168723. png_bytep sp = row + (png_size_t)row_width - 1;
  168724. png_bytep dp = sp + (png_size_t)row_width * 2;
  168725. for (i = 0; i < row_width; i++)
  168726. {
  168727. *(dp--) = *sp;
  168728. *(dp--) = *sp;
  168729. *(dp--) = *(sp--);
  168730. }
  168731. }
  168732. else
  168733. {
  168734. png_bytep sp = row + (png_size_t)row_width * 2 - 1;
  168735. png_bytep dp = sp + (png_size_t)row_width * 4;
  168736. for (i = 0; i < row_width; i++)
  168737. {
  168738. *(dp--) = *sp;
  168739. *(dp--) = *(sp - 1);
  168740. *(dp--) = *sp;
  168741. *(dp--) = *(sp - 1);
  168742. *(dp--) = *(sp--);
  168743. *(dp--) = *(sp--);
  168744. }
  168745. }
  168746. }
  168747. else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
  168748. {
  168749. if (row_info->bit_depth == 8)
  168750. {
  168751. png_bytep sp = row + (png_size_t)row_width * 2 - 1;
  168752. png_bytep dp = sp + (png_size_t)row_width * 2;
  168753. for (i = 0; i < row_width; i++)
  168754. {
  168755. *(dp--) = *(sp--);
  168756. *(dp--) = *sp;
  168757. *(dp--) = *sp;
  168758. *(dp--) = *(sp--);
  168759. }
  168760. }
  168761. else
  168762. {
  168763. png_bytep sp = row + (png_size_t)row_width * 4 - 1;
  168764. png_bytep dp = sp + (png_size_t)row_width * 4;
  168765. for (i = 0; i < row_width; i++)
  168766. {
  168767. *(dp--) = *(sp--);
  168768. *(dp--) = *(sp--);
  168769. *(dp--) = *sp;
  168770. *(dp--) = *(sp - 1);
  168771. *(dp--) = *sp;
  168772. *(dp--) = *(sp - 1);
  168773. *(dp--) = *(sp--);
  168774. *(dp--) = *(sp--);
  168775. }
  168776. }
  168777. }
  168778. row_info->channels += (png_byte)2;
  168779. row_info->color_type |= PNG_COLOR_MASK_COLOR;
  168780. row_info->pixel_depth = (png_byte)(row_info->channels *
  168781. row_info->bit_depth);
  168782. row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,row_width);
  168783. }
  168784. }
  168785. #endif
  168786. #if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
  168787. int /* PRIVATE */
  168788. png_do_rgb_to_gray(png_structp png_ptr, png_row_infop row_info, png_bytep row)
  168789. {
  168790. png_uint_32 i;
  168791. png_uint_32 row_width = row_info->width;
  168792. int rgb_error = 0;
  168793. png_debug(1, "in png_do_rgb_to_gray\n");
  168794. if (
  168795. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  168796. row != NULL && row_info != NULL &&
  168797. #endif
  168798. (row_info->color_type & PNG_COLOR_MASK_COLOR))
  168799. {
  168800. png_uint_32 rc = png_ptr->rgb_to_gray_red_coeff;
  168801. png_uint_32 gc = png_ptr->rgb_to_gray_green_coeff;
  168802. png_uint_32 bc = png_ptr->rgb_to_gray_blue_coeff;
  168803. if (row_info->color_type == PNG_COLOR_TYPE_RGB)
  168804. {
  168805. if (row_info->bit_depth == 8)
  168806. {
  168807. #if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
  168808. if (png_ptr->gamma_from_1 != NULL && png_ptr->gamma_to_1 != NULL)
  168809. {
  168810. png_bytep sp = row;
  168811. png_bytep dp = row;
  168812. for (i = 0; i < row_width; i++)
  168813. {
  168814. png_byte red = png_ptr->gamma_to_1[*(sp++)];
  168815. png_byte green = png_ptr->gamma_to_1[*(sp++)];
  168816. png_byte blue = png_ptr->gamma_to_1[*(sp++)];
  168817. if(red != green || red != blue)
  168818. {
  168819. rgb_error |= 1;
  168820. *(dp++) = png_ptr->gamma_from_1[
  168821. (rc*red+gc*green+bc*blue)>>15];
  168822. }
  168823. else
  168824. *(dp++) = *(sp-1);
  168825. }
  168826. }
  168827. else
  168828. #endif
  168829. {
  168830. png_bytep sp = row;
  168831. png_bytep dp = row;
  168832. for (i = 0; i < row_width; i++)
  168833. {
  168834. png_byte red = *(sp++);
  168835. png_byte green = *(sp++);
  168836. png_byte blue = *(sp++);
  168837. if(red != green || red != blue)
  168838. {
  168839. rgb_error |= 1;
  168840. *(dp++) = (png_byte)((rc*red+gc*green+bc*blue)>>15);
  168841. }
  168842. else
  168843. *(dp++) = *(sp-1);
  168844. }
  168845. }
  168846. }
  168847. else /* RGB bit_depth == 16 */
  168848. {
  168849. #if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
  168850. if (png_ptr->gamma_16_to_1 != NULL &&
  168851. png_ptr->gamma_16_from_1 != NULL)
  168852. {
  168853. png_bytep sp = row;
  168854. png_bytep dp = row;
  168855. for (i = 0; i < row_width; i++)
  168856. {
  168857. png_uint_16 red, green, blue, w;
  168858. red = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
  168859. green = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
  168860. blue = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
  168861. if(red == green && red == blue)
  168862. w = red;
  168863. else
  168864. {
  168865. png_uint_16 red_1 = png_ptr->gamma_16_to_1[(red&0xff) >>
  168866. png_ptr->gamma_shift][red>>8];
  168867. png_uint_16 green_1 = png_ptr->gamma_16_to_1[(green&0xff) >>
  168868. png_ptr->gamma_shift][green>>8];
  168869. png_uint_16 blue_1 = png_ptr->gamma_16_to_1[(blue&0xff) >>
  168870. png_ptr->gamma_shift][blue>>8];
  168871. png_uint_16 gray16 = (png_uint_16)((rc*red_1 + gc*green_1
  168872. + bc*blue_1)>>15);
  168873. w = png_ptr->gamma_16_from_1[(gray16&0xff) >>
  168874. png_ptr->gamma_shift][gray16 >> 8];
  168875. rgb_error |= 1;
  168876. }
  168877. *(dp++) = (png_byte)((w>>8) & 0xff);
  168878. *(dp++) = (png_byte)(w & 0xff);
  168879. }
  168880. }
  168881. else
  168882. #endif
  168883. {
  168884. png_bytep sp = row;
  168885. png_bytep dp = row;
  168886. for (i = 0; i < row_width; i++)
  168887. {
  168888. png_uint_16 red, green, blue, gray16;
  168889. red = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
  168890. green = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
  168891. blue = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
  168892. if(red != green || red != blue)
  168893. rgb_error |= 1;
  168894. gray16 = (png_uint_16)((rc*red + gc*green + bc*blue)>>15);
  168895. *(dp++) = (png_byte)((gray16>>8) & 0xff);
  168896. *(dp++) = (png_byte)(gray16 & 0xff);
  168897. }
  168898. }
  168899. }
  168900. }
  168901. if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  168902. {
  168903. if (row_info->bit_depth == 8)
  168904. {
  168905. #if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
  168906. if (png_ptr->gamma_from_1 != NULL && png_ptr->gamma_to_1 != NULL)
  168907. {
  168908. png_bytep sp = row;
  168909. png_bytep dp = row;
  168910. for (i = 0; i < row_width; i++)
  168911. {
  168912. png_byte red = png_ptr->gamma_to_1[*(sp++)];
  168913. png_byte green = png_ptr->gamma_to_1[*(sp++)];
  168914. png_byte blue = png_ptr->gamma_to_1[*(sp++)];
  168915. if(red != green || red != blue)
  168916. rgb_error |= 1;
  168917. *(dp++) = png_ptr->gamma_from_1
  168918. [(rc*red + gc*green + bc*blue)>>15];
  168919. *(dp++) = *(sp++); /* alpha */
  168920. }
  168921. }
  168922. else
  168923. #endif
  168924. {
  168925. png_bytep sp = row;
  168926. png_bytep dp = row;
  168927. for (i = 0; i < row_width; i++)
  168928. {
  168929. png_byte red = *(sp++);
  168930. png_byte green = *(sp++);
  168931. png_byte blue = *(sp++);
  168932. if(red != green || red != blue)
  168933. rgb_error |= 1;
  168934. *(dp++) = (png_byte)((rc*red + gc*green + bc*blue)>>15);
  168935. *(dp++) = *(sp++); /* alpha */
  168936. }
  168937. }
  168938. }
  168939. else /* RGBA bit_depth == 16 */
  168940. {
  168941. #if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
  168942. if (png_ptr->gamma_16_to_1 != NULL &&
  168943. png_ptr->gamma_16_from_1 != NULL)
  168944. {
  168945. png_bytep sp = row;
  168946. png_bytep dp = row;
  168947. for (i = 0; i < row_width; i++)
  168948. {
  168949. png_uint_16 red, green, blue, w;
  168950. red = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
  168951. green = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
  168952. blue = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
  168953. if(red == green && red == blue)
  168954. w = red;
  168955. else
  168956. {
  168957. png_uint_16 red_1 = png_ptr->gamma_16_to_1[(red&0xff) >>
  168958. png_ptr->gamma_shift][red>>8];
  168959. png_uint_16 green_1 = png_ptr->gamma_16_to_1[(green&0xff) >>
  168960. png_ptr->gamma_shift][green>>8];
  168961. png_uint_16 blue_1 = png_ptr->gamma_16_to_1[(blue&0xff) >>
  168962. png_ptr->gamma_shift][blue>>8];
  168963. png_uint_16 gray16 = (png_uint_16)((rc * red_1
  168964. + gc * green_1 + bc * blue_1)>>15);
  168965. w = png_ptr->gamma_16_from_1[(gray16&0xff) >>
  168966. png_ptr->gamma_shift][gray16 >> 8];
  168967. rgb_error |= 1;
  168968. }
  168969. *(dp++) = (png_byte)((w>>8) & 0xff);
  168970. *(dp++) = (png_byte)(w & 0xff);
  168971. *(dp++) = *(sp++); /* alpha */
  168972. *(dp++) = *(sp++);
  168973. }
  168974. }
  168975. else
  168976. #endif
  168977. {
  168978. png_bytep sp = row;
  168979. png_bytep dp = row;
  168980. for (i = 0; i < row_width; i++)
  168981. {
  168982. png_uint_16 red, green, blue, gray16;
  168983. red = (png_uint_16)((*(sp)<<8) | *(sp+1)); sp+=2;
  168984. green = (png_uint_16)((*(sp)<<8) | *(sp+1)); sp+=2;
  168985. blue = (png_uint_16)((*(sp)<<8) | *(sp+1)); sp+=2;
  168986. if(red != green || red != blue)
  168987. rgb_error |= 1;
  168988. gray16 = (png_uint_16)((rc*red + gc*green + bc*blue)>>15);
  168989. *(dp++) = (png_byte)((gray16>>8) & 0xff);
  168990. *(dp++) = (png_byte)(gray16 & 0xff);
  168991. *(dp++) = *(sp++); /* alpha */
  168992. *(dp++) = *(sp++);
  168993. }
  168994. }
  168995. }
  168996. }
  168997. row_info->channels -= (png_byte)2;
  168998. row_info->color_type &= ~PNG_COLOR_MASK_COLOR;
  168999. row_info->pixel_depth = (png_byte)(row_info->channels *
  169000. row_info->bit_depth);
  169001. row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,row_width);
  169002. }
  169003. return rgb_error;
  169004. }
  169005. #endif
  169006. void PNGAPI
  169007. png_build_grayscale_palette(int bit_depth, png_colorp palette)
  169008. {
  169009. int num_palette;
  169010. int color_inc;
  169011. int i;
  169012. int v;
  169013. png_debug(1, "in png_do_build_grayscale_palette\n");
  169014. if (palette == NULL)
  169015. return;
  169016. switch (bit_depth)
  169017. {
  169018. case 1:
  169019. num_palette = 2;
  169020. color_inc = 0xff;
  169021. break;
  169022. case 2:
  169023. num_palette = 4;
  169024. color_inc = 0x55;
  169025. break;
  169026. case 4:
  169027. num_palette = 16;
  169028. color_inc = 0x11;
  169029. break;
  169030. case 8:
  169031. num_palette = 256;
  169032. color_inc = 1;
  169033. break;
  169034. default:
  169035. num_palette = 0;
  169036. color_inc = 0;
  169037. break;
  169038. }
  169039. for (i = 0, v = 0; i < num_palette; i++, v += color_inc)
  169040. {
  169041. palette[i].red = (png_byte)v;
  169042. palette[i].green = (png_byte)v;
  169043. palette[i].blue = (png_byte)v;
  169044. }
  169045. }
  169046. #if defined(PNG_READ_DITHER_SUPPORTED) && defined(PNG_CORRECT_PALETTE_SUPPORTED)
  169047. void /* PRIVATE */
  169048. png_correct_palette(png_structp png_ptr, png_colorp palette,
  169049. int num_palette)
  169050. {
  169051. png_debug(1, "in png_correct_palette\n");
  169052. #if defined(PNG_READ_BACKGROUND_SUPPORTED) && \
  169053. defined(PNG_READ_GAMMA_SUPPORTED) && defined(PNG_FLOATING_POINT_SUPPORTED)
  169054. if (png_ptr->transformations & (PNG_GAMMA | PNG_BACKGROUND))
  169055. {
  169056. png_color back, back_1;
  169057. if (png_ptr->background_gamma_type == PNG_BACKGROUND_GAMMA_FILE)
  169058. {
  169059. back.red = png_ptr->gamma_table[png_ptr->background.red];
  169060. back.green = png_ptr->gamma_table[png_ptr->background.green];
  169061. back.blue = png_ptr->gamma_table[png_ptr->background.blue];
  169062. back_1.red = png_ptr->gamma_to_1[png_ptr->background.red];
  169063. back_1.green = png_ptr->gamma_to_1[png_ptr->background.green];
  169064. back_1.blue = png_ptr->gamma_to_1[png_ptr->background.blue];
  169065. }
  169066. else
  169067. {
  169068. double g;
  169069. g = 1.0 / (png_ptr->background_gamma * png_ptr->screen_gamma);
  169070. if (png_ptr->background_gamma_type == PNG_BACKGROUND_GAMMA_SCREEN ||
  169071. fabs(g - 1.0) < PNG_GAMMA_THRESHOLD)
  169072. {
  169073. back.red = png_ptr->background.red;
  169074. back.green = png_ptr->background.green;
  169075. back.blue = png_ptr->background.blue;
  169076. }
  169077. else
  169078. {
  169079. back.red =
  169080. (png_byte)(pow((double)png_ptr->background.red/255, g) *
  169081. 255.0 + 0.5);
  169082. back.green =
  169083. (png_byte)(pow((double)png_ptr->background.green/255, g) *
  169084. 255.0 + 0.5);
  169085. back.blue =
  169086. (png_byte)(pow((double)png_ptr->background.blue/255, g) *
  169087. 255.0 + 0.5);
  169088. }
  169089. g = 1.0 / png_ptr->background_gamma;
  169090. back_1.red =
  169091. (png_byte)(pow((double)png_ptr->background.red/255, g) *
  169092. 255.0 + 0.5);
  169093. back_1.green =
  169094. (png_byte)(pow((double)png_ptr->background.green/255, g) *
  169095. 255.0 + 0.5);
  169096. back_1.blue =
  169097. (png_byte)(pow((double)png_ptr->background.blue/255, g) *
  169098. 255.0 + 0.5);
  169099. }
  169100. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  169101. {
  169102. png_uint_32 i;
  169103. for (i = 0; i < (png_uint_32)num_palette; i++)
  169104. {
  169105. if (i < png_ptr->num_trans && png_ptr->trans[i] == 0)
  169106. {
  169107. palette[i] = back;
  169108. }
  169109. else if (i < png_ptr->num_trans && png_ptr->trans[i] != 0xff)
  169110. {
  169111. png_byte v, w;
  169112. v = png_ptr->gamma_to_1[png_ptr->palette[i].red];
  169113. png_composite(w, v, png_ptr->trans[i], back_1.red);
  169114. palette[i].red = png_ptr->gamma_from_1[w];
  169115. v = png_ptr->gamma_to_1[png_ptr->palette[i].green];
  169116. png_composite(w, v, png_ptr->trans[i], back_1.green);
  169117. palette[i].green = png_ptr->gamma_from_1[w];
  169118. v = png_ptr->gamma_to_1[png_ptr->palette[i].blue];
  169119. png_composite(w, v, png_ptr->trans[i], back_1.blue);
  169120. palette[i].blue = png_ptr->gamma_from_1[w];
  169121. }
  169122. else
  169123. {
  169124. palette[i].red = png_ptr->gamma_table[palette[i].red];
  169125. palette[i].green = png_ptr->gamma_table[palette[i].green];
  169126. palette[i].blue = png_ptr->gamma_table[palette[i].blue];
  169127. }
  169128. }
  169129. }
  169130. else
  169131. {
  169132. int i;
  169133. for (i = 0; i < num_palette; i++)
  169134. {
  169135. if (palette[i].red == (png_byte)png_ptr->trans_values.gray)
  169136. {
  169137. palette[i] = back;
  169138. }
  169139. else
  169140. {
  169141. palette[i].red = png_ptr->gamma_table[palette[i].red];
  169142. palette[i].green = png_ptr->gamma_table[palette[i].green];
  169143. palette[i].blue = png_ptr->gamma_table[palette[i].blue];
  169144. }
  169145. }
  169146. }
  169147. }
  169148. else
  169149. #endif
  169150. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169151. if (png_ptr->transformations & PNG_GAMMA)
  169152. {
  169153. int i;
  169154. for (i = 0; i < num_palette; i++)
  169155. {
  169156. palette[i].red = png_ptr->gamma_table[palette[i].red];
  169157. palette[i].green = png_ptr->gamma_table[palette[i].green];
  169158. palette[i].blue = png_ptr->gamma_table[palette[i].blue];
  169159. }
  169160. }
  169161. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  169162. else
  169163. #endif
  169164. #endif
  169165. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  169166. if (png_ptr->transformations & PNG_BACKGROUND)
  169167. {
  169168. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  169169. {
  169170. png_color back;
  169171. back.red = (png_byte)png_ptr->background.red;
  169172. back.green = (png_byte)png_ptr->background.green;
  169173. back.blue = (png_byte)png_ptr->background.blue;
  169174. for (i = 0; i < (int)png_ptr->num_trans; i++)
  169175. {
  169176. if (png_ptr->trans[i] == 0)
  169177. {
  169178. palette[i].red = back.red;
  169179. palette[i].green = back.green;
  169180. palette[i].blue = back.blue;
  169181. }
  169182. else if (png_ptr->trans[i] != 0xff)
  169183. {
  169184. png_composite(palette[i].red, png_ptr->palette[i].red,
  169185. png_ptr->trans[i], back.red);
  169186. png_composite(palette[i].green, png_ptr->palette[i].green,
  169187. png_ptr->trans[i], back.green);
  169188. png_composite(palette[i].blue, png_ptr->palette[i].blue,
  169189. png_ptr->trans[i], back.blue);
  169190. }
  169191. }
  169192. }
  169193. else /* assume grayscale palette (what else could it be?) */
  169194. {
  169195. int i;
  169196. for (i = 0; i < num_palette; i++)
  169197. {
  169198. if (i == (png_byte)png_ptr->trans_values.gray)
  169199. {
  169200. palette[i].red = (png_byte)png_ptr->background.red;
  169201. palette[i].green = (png_byte)png_ptr->background.green;
  169202. palette[i].blue = (png_byte)png_ptr->background.blue;
  169203. }
  169204. }
  169205. }
  169206. }
  169207. #endif
  169208. }
  169209. #endif
  169210. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  169211. void /* PRIVATE */
  169212. png_do_background(png_row_infop row_info, png_bytep row,
  169213. png_color_16p trans_values, png_color_16p background
  169214. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169215. , png_color_16p background_1,
  169216. png_bytep gamma_table, png_bytep gamma_from_1, png_bytep gamma_to_1,
  169217. png_uint_16pp gamma_16, png_uint_16pp gamma_16_from_1,
  169218. png_uint_16pp gamma_16_to_1, int gamma_shift
  169219. #endif
  169220. )
  169221. {
  169222. png_bytep sp, dp;
  169223. png_uint_32 i;
  169224. png_uint_32 row_width=row_info->width;
  169225. int shift;
  169226. png_debug(1, "in png_do_background\n");
  169227. if (background != NULL &&
  169228. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  169229. row != NULL && row_info != NULL &&
  169230. #endif
  169231. (!(row_info->color_type & PNG_COLOR_MASK_ALPHA) ||
  169232. (row_info->color_type != PNG_COLOR_TYPE_PALETTE && trans_values)))
  169233. {
  169234. switch (row_info->color_type)
  169235. {
  169236. case PNG_COLOR_TYPE_GRAY:
  169237. {
  169238. switch (row_info->bit_depth)
  169239. {
  169240. case 1:
  169241. {
  169242. sp = row;
  169243. shift = 7;
  169244. for (i = 0; i < row_width; i++)
  169245. {
  169246. if ((png_uint_16)((*sp >> shift) & 0x01)
  169247. == trans_values->gray)
  169248. {
  169249. *sp &= (png_byte)((0x7f7f >> (7 - shift)) & 0xff);
  169250. *sp |= (png_byte)(background->gray << shift);
  169251. }
  169252. if (!shift)
  169253. {
  169254. shift = 7;
  169255. sp++;
  169256. }
  169257. else
  169258. shift--;
  169259. }
  169260. break;
  169261. }
  169262. case 2:
  169263. {
  169264. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169265. if (gamma_table != NULL)
  169266. {
  169267. sp = row;
  169268. shift = 6;
  169269. for (i = 0; i < row_width; i++)
  169270. {
  169271. if ((png_uint_16)((*sp >> shift) & 0x03)
  169272. == trans_values->gray)
  169273. {
  169274. *sp &= (png_byte)((0x3f3f >> (6 - shift)) & 0xff);
  169275. *sp |= (png_byte)(background->gray << shift);
  169276. }
  169277. else
  169278. {
  169279. png_byte p = (png_byte)((*sp >> shift) & 0x03);
  169280. png_byte g = (png_byte)((gamma_table [p | (p << 2) |
  169281. (p << 4) | (p << 6)] >> 6) & 0x03);
  169282. *sp &= (png_byte)((0x3f3f >> (6 - shift)) & 0xff);
  169283. *sp |= (png_byte)(g << shift);
  169284. }
  169285. if (!shift)
  169286. {
  169287. shift = 6;
  169288. sp++;
  169289. }
  169290. else
  169291. shift -= 2;
  169292. }
  169293. }
  169294. else
  169295. #endif
  169296. {
  169297. sp = row;
  169298. shift = 6;
  169299. for (i = 0; i < row_width; i++)
  169300. {
  169301. if ((png_uint_16)((*sp >> shift) & 0x03)
  169302. == trans_values->gray)
  169303. {
  169304. *sp &= (png_byte)((0x3f3f >> (6 - shift)) & 0xff);
  169305. *sp |= (png_byte)(background->gray << shift);
  169306. }
  169307. if (!shift)
  169308. {
  169309. shift = 6;
  169310. sp++;
  169311. }
  169312. else
  169313. shift -= 2;
  169314. }
  169315. }
  169316. break;
  169317. }
  169318. case 4:
  169319. {
  169320. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169321. if (gamma_table != NULL)
  169322. {
  169323. sp = row;
  169324. shift = 4;
  169325. for (i = 0; i < row_width; i++)
  169326. {
  169327. if ((png_uint_16)((*sp >> shift) & 0x0f)
  169328. == trans_values->gray)
  169329. {
  169330. *sp &= (png_byte)((0xf0f >> (4 - shift)) & 0xff);
  169331. *sp |= (png_byte)(background->gray << shift);
  169332. }
  169333. else
  169334. {
  169335. png_byte p = (png_byte)((*sp >> shift) & 0x0f);
  169336. png_byte g = (png_byte)((gamma_table[p |
  169337. (p << 4)] >> 4) & 0x0f);
  169338. *sp &= (png_byte)((0xf0f >> (4 - shift)) & 0xff);
  169339. *sp |= (png_byte)(g << shift);
  169340. }
  169341. if (!shift)
  169342. {
  169343. shift = 4;
  169344. sp++;
  169345. }
  169346. else
  169347. shift -= 4;
  169348. }
  169349. }
  169350. else
  169351. #endif
  169352. {
  169353. sp = row;
  169354. shift = 4;
  169355. for (i = 0; i < row_width; i++)
  169356. {
  169357. if ((png_uint_16)((*sp >> shift) & 0x0f)
  169358. == trans_values->gray)
  169359. {
  169360. *sp &= (png_byte)((0xf0f >> (4 - shift)) & 0xff);
  169361. *sp |= (png_byte)(background->gray << shift);
  169362. }
  169363. if (!shift)
  169364. {
  169365. shift = 4;
  169366. sp++;
  169367. }
  169368. else
  169369. shift -= 4;
  169370. }
  169371. }
  169372. break;
  169373. }
  169374. case 8:
  169375. {
  169376. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169377. if (gamma_table != NULL)
  169378. {
  169379. sp = row;
  169380. for (i = 0; i < row_width; i++, sp++)
  169381. {
  169382. if (*sp == trans_values->gray)
  169383. {
  169384. *sp = (png_byte)background->gray;
  169385. }
  169386. else
  169387. {
  169388. *sp = gamma_table[*sp];
  169389. }
  169390. }
  169391. }
  169392. else
  169393. #endif
  169394. {
  169395. sp = row;
  169396. for (i = 0; i < row_width; i++, sp++)
  169397. {
  169398. if (*sp == trans_values->gray)
  169399. {
  169400. *sp = (png_byte)background->gray;
  169401. }
  169402. }
  169403. }
  169404. break;
  169405. }
  169406. case 16:
  169407. {
  169408. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169409. if (gamma_16 != NULL)
  169410. {
  169411. sp = row;
  169412. for (i = 0; i < row_width; i++, sp += 2)
  169413. {
  169414. png_uint_16 v;
  169415. v = (png_uint_16)(((*sp) << 8) + *(sp + 1));
  169416. if (v == trans_values->gray)
  169417. {
  169418. *sp = (png_byte)((background->gray >> 8) & 0xff);
  169419. *(sp + 1) = (png_byte)(background->gray & 0xff);
  169420. }
  169421. else
  169422. {
  169423. v = gamma_16[*(sp + 1) >> gamma_shift][*sp];
  169424. *sp = (png_byte)((v >> 8) & 0xff);
  169425. *(sp + 1) = (png_byte)(v & 0xff);
  169426. }
  169427. }
  169428. }
  169429. else
  169430. #endif
  169431. {
  169432. sp = row;
  169433. for (i = 0; i < row_width; i++, sp += 2)
  169434. {
  169435. png_uint_16 v;
  169436. v = (png_uint_16)(((*sp) << 8) + *(sp + 1));
  169437. if (v == trans_values->gray)
  169438. {
  169439. *sp = (png_byte)((background->gray >> 8) & 0xff);
  169440. *(sp + 1) = (png_byte)(background->gray & 0xff);
  169441. }
  169442. }
  169443. }
  169444. break;
  169445. }
  169446. }
  169447. break;
  169448. }
  169449. case PNG_COLOR_TYPE_RGB:
  169450. {
  169451. if (row_info->bit_depth == 8)
  169452. {
  169453. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169454. if (gamma_table != NULL)
  169455. {
  169456. sp = row;
  169457. for (i = 0; i < row_width; i++, sp += 3)
  169458. {
  169459. if (*sp == trans_values->red &&
  169460. *(sp + 1) == trans_values->green &&
  169461. *(sp + 2) == trans_values->blue)
  169462. {
  169463. *sp = (png_byte)background->red;
  169464. *(sp + 1) = (png_byte)background->green;
  169465. *(sp + 2) = (png_byte)background->blue;
  169466. }
  169467. else
  169468. {
  169469. *sp = gamma_table[*sp];
  169470. *(sp + 1) = gamma_table[*(sp + 1)];
  169471. *(sp + 2) = gamma_table[*(sp + 2)];
  169472. }
  169473. }
  169474. }
  169475. else
  169476. #endif
  169477. {
  169478. sp = row;
  169479. for (i = 0; i < row_width; i++, sp += 3)
  169480. {
  169481. if (*sp == trans_values->red &&
  169482. *(sp + 1) == trans_values->green &&
  169483. *(sp + 2) == trans_values->blue)
  169484. {
  169485. *sp = (png_byte)background->red;
  169486. *(sp + 1) = (png_byte)background->green;
  169487. *(sp + 2) = (png_byte)background->blue;
  169488. }
  169489. }
  169490. }
  169491. }
  169492. else /* if (row_info->bit_depth == 16) */
  169493. {
  169494. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169495. if (gamma_16 != NULL)
  169496. {
  169497. sp = row;
  169498. for (i = 0; i < row_width; i++, sp += 6)
  169499. {
  169500. png_uint_16 r = (png_uint_16)(((*sp) << 8) + *(sp + 1));
  169501. png_uint_16 g = (png_uint_16)(((*(sp+2)) << 8) + *(sp+3));
  169502. png_uint_16 b = (png_uint_16)(((*(sp+4)) << 8) + *(sp+5));
  169503. if (r == trans_values->red && g == trans_values->green &&
  169504. b == trans_values->blue)
  169505. {
  169506. *sp = (png_byte)((background->red >> 8) & 0xff);
  169507. *(sp + 1) = (png_byte)(background->red & 0xff);
  169508. *(sp + 2) = (png_byte)((background->green >> 8) & 0xff);
  169509. *(sp + 3) = (png_byte)(background->green & 0xff);
  169510. *(sp + 4) = (png_byte)((background->blue >> 8) & 0xff);
  169511. *(sp + 5) = (png_byte)(background->blue & 0xff);
  169512. }
  169513. else
  169514. {
  169515. png_uint_16 v = gamma_16[*(sp + 1) >> gamma_shift][*sp];
  169516. *sp = (png_byte)((v >> 8) & 0xff);
  169517. *(sp + 1) = (png_byte)(v & 0xff);
  169518. v = gamma_16[*(sp + 3) >> gamma_shift][*(sp + 2)];
  169519. *(sp + 2) = (png_byte)((v >> 8) & 0xff);
  169520. *(sp + 3) = (png_byte)(v & 0xff);
  169521. v = gamma_16[*(sp + 5) >> gamma_shift][*(sp + 4)];
  169522. *(sp + 4) = (png_byte)((v >> 8) & 0xff);
  169523. *(sp + 5) = (png_byte)(v & 0xff);
  169524. }
  169525. }
  169526. }
  169527. else
  169528. #endif
  169529. {
  169530. sp = row;
  169531. for (i = 0; i < row_width; i++, sp += 6)
  169532. {
  169533. png_uint_16 r = (png_uint_16)(((*sp) << 8) + *(sp+1));
  169534. png_uint_16 g = (png_uint_16)(((*(sp+2)) << 8) + *(sp+3));
  169535. png_uint_16 b = (png_uint_16)(((*(sp+4)) << 8) + *(sp+5));
  169536. if (r == trans_values->red && g == trans_values->green &&
  169537. b == trans_values->blue)
  169538. {
  169539. *sp = (png_byte)((background->red >> 8) & 0xff);
  169540. *(sp + 1) = (png_byte)(background->red & 0xff);
  169541. *(sp + 2) = (png_byte)((background->green >> 8) & 0xff);
  169542. *(sp + 3) = (png_byte)(background->green & 0xff);
  169543. *(sp + 4) = (png_byte)((background->blue >> 8) & 0xff);
  169544. *(sp + 5) = (png_byte)(background->blue & 0xff);
  169545. }
  169546. }
  169547. }
  169548. }
  169549. break;
  169550. }
  169551. case PNG_COLOR_TYPE_GRAY_ALPHA:
  169552. {
  169553. if (row_info->bit_depth == 8)
  169554. {
  169555. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169556. if (gamma_to_1 != NULL && gamma_from_1 != NULL &&
  169557. gamma_table != NULL)
  169558. {
  169559. sp = row;
  169560. dp = row;
  169561. for (i = 0; i < row_width; i++, sp += 2, dp++)
  169562. {
  169563. png_uint_16 a = *(sp + 1);
  169564. if (a == 0xff)
  169565. {
  169566. *dp = gamma_table[*sp];
  169567. }
  169568. else if (a == 0)
  169569. {
  169570. *dp = (png_byte)background->gray;
  169571. }
  169572. else
  169573. {
  169574. png_byte v, w;
  169575. v = gamma_to_1[*sp];
  169576. png_composite(w, v, a, background_1->gray);
  169577. *dp = gamma_from_1[w];
  169578. }
  169579. }
  169580. }
  169581. else
  169582. #endif
  169583. {
  169584. sp = row;
  169585. dp = row;
  169586. for (i = 0; i < row_width; i++, sp += 2, dp++)
  169587. {
  169588. png_byte a = *(sp + 1);
  169589. if (a == 0xff)
  169590. {
  169591. *dp = *sp;
  169592. }
  169593. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169594. else if (a == 0)
  169595. {
  169596. *dp = (png_byte)background->gray;
  169597. }
  169598. else
  169599. {
  169600. png_composite(*dp, *sp, a, background_1->gray);
  169601. }
  169602. #else
  169603. *dp = (png_byte)background->gray;
  169604. #endif
  169605. }
  169606. }
  169607. }
  169608. else /* if (png_ptr->bit_depth == 16) */
  169609. {
  169610. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169611. if (gamma_16 != NULL && gamma_16_from_1 != NULL &&
  169612. gamma_16_to_1 != NULL)
  169613. {
  169614. sp = row;
  169615. dp = row;
  169616. for (i = 0; i < row_width; i++, sp += 4, dp += 2)
  169617. {
  169618. png_uint_16 a = (png_uint_16)(((*(sp+2)) << 8) + *(sp+3));
  169619. if (a == (png_uint_16)0xffff)
  169620. {
  169621. png_uint_16 v;
  169622. v = gamma_16[*(sp + 1) >> gamma_shift][*sp];
  169623. *dp = (png_byte)((v >> 8) & 0xff);
  169624. *(dp + 1) = (png_byte)(v & 0xff);
  169625. }
  169626. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169627. else if (a == 0)
  169628. #else
  169629. else
  169630. #endif
  169631. {
  169632. *dp = (png_byte)((background->gray >> 8) & 0xff);
  169633. *(dp + 1) = (png_byte)(background->gray & 0xff);
  169634. }
  169635. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169636. else
  169637. {
  169638. png_uint_16 g, v, w;
  169639. g = gamma_16_to_1[*(sp + 1) >> gamma_shift][*sp];
  169640. png_composite_16(v, g, a, background_1->gray);
  169641. w = gamma_16_from_1[(v&0xff) >> gamma_shift][v >> 8];
  169642. *dp = (png_byte)((w >> 8) & 0xff);
  169643. *(dp + 1) = (png_byte)(w & 0xff);
  169644. }
  169645. #endif
  169646. }
  169647. }
  169648. else
  169649. #endif
  169650. {
  169651. sp = row;
  169652. dp = row;
  169653. for (i = 0; i < row_width; i++, sp += 4, dp += 2)
  169654. {
  169655. png_uint_16 a = (png_uint_16)(((*(sp+2)) << 8) + *(sp+3));
  169656. if (a == (png_uint_16)0xffff)
  169657. {
  169658. png_memcpy(dp, sp, 2);
  169659. }
  169660. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169661. else if (a == 0)
  169662. #else
  169663. else
  169664. #endif
  169665. {
  169666. *dp = (png_byte)((background->gray >> 8) & 0xff);
  169667. *(dp + 1) = (png_byte)(background->gray & 0xff);
  169668. }
  169669. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169670. else
  169671. {
  169672. png_uint_16 g, v;
  169673. g = (png_uint_16)(((*sp) << 8) + *(sp + 1));
  169674. png_composite_16(v, g, a, background_1->gray);
  169675. *dp = (png_byte)((v >> 8) & 0xff);
  169676. *(dp + 1) = (png_byte)(v & 0xff);
  169677. }
  169678. #endif
  169679. }
  169680. }
  169681. }
  169682. break;
  169683. }
  169684. case PNG_COLOR_TYPE_RGB_ALPHA:
  169685. {
  169686. if (row_info->bit_depth == 8)
  169687. {
  169688. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169689. if (gamma_to_1 != NULL && gamma_from_1 != NULL &&
  169690. gamma_table != NULL)
  169691. {
  169692. sp = row;
  169693. dp = row;
  169694. for (i = 0; i < row_width; i++, sp += 4, dp += 3)
  169695. {
  169696. png_byte a = *(sp + 3);
  169697. if (a == 0xff)
  169698. {
  169699. *dp = gamma_table[*sp];
  169700. *(dp + 1) = gamma_table[*(sp + 1)];
  169701. *(dp + 2) = gamma_table[*(sp + 2)];
  169702. }
  169703. else if (a == 0)
  169704. {
  169705. *dp = (png_byte)background->red;
  169706. *(dp + 1) = (png_byte)background->green;
  169707. *(dp + 2) = (png_byte)background->blue;
  169708. }
  169709. else
  169710. {
  169711. png_byte v, w;
  169712. v = gamma_to_1[*sp];
  169713. png_composite(w, v, a, background_1->red);
  169714. *dp = gamma_from_1[w];
  169715. v = gamma_to_1[*(sp + 1)];
  169716. png_composite(w, v, a, background_1->green);
  169717. *(dp + 1) = gamma_from_1[w];
  169718. v = gamma_to_1[*(sp + 2)];
  169719. png_composite(w, v, a, background_1->blue);
  169720. *(dp + 2) = gamma_from_1[w];
  169721. }
  169722. }
  169723. }
  169724. else
  169725. #endif
  169726. {
  169727. sp = row;
  169728. dp = row;
  169729. for (i = 0; i < row_width; i++, sp += 4, dp += 3)
  169730. {
  169731. png_byte a = *(sp + 3);
  169732. if (a == 0xff)
  169733. {
  169734. *dp = *sp;
  169735. *(dp + 1) = *(sp + 1);
  169736. *(dp + 2) = *(sp + 2);
  169737. }
  169738. else if (a == 0)
  169739. {
  169740. *dp = (png_byte)background->red;
  169741. *(dp + 1) = (png_byte)background->green;
  169742. *(dp + 2) = (png_byte)background->blue;
  169743. }
  169744. else
  169745. {
  169746. png_composite(*dp, *sp, a, background->red);
  169747. png_composite(*(dp + 1), *(sp + 1), a,
  169748. background->green);
  169749. png_composite(*(dp + 2), *(sp + 2), a,
  169750. background->blue);
  169751. }
  169752. }
  169753. }
  169754. }
  169755. else /* if (row_info->bit_depth == 16) */
  169756. {
  169757. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169758. if (gamma_16 != NULL && gamma_16_from_1 != NULL &&
  169759. gamma_16_to_1 != NULL)
  169760. {
  169761. sp = row;
  169762. dp = row;
  169763. for (i = 0; i < row_width; i++, sp += 8, dp += 6)
  169764. {
  169765. png_uint_16 a = (png_uint_16)(((png_uint_16)(*(sp + 6))
  169766. << 8) + (png_uint_16)(*(sp + 7)));
  169767. if (a == (png_uint_16)0xffff)
  169768. {
  169769. png_uint_16 v;
  169770. v = gamma_16[*(sp + 1) >> gamma_shift][*sp];
  169771. *dp = (png_byte)((v >> 8) & 0xff);
  169772. *(dp + 1) = (png_byte)(v & 0xff);
  169773. v = gamma_16[*(sp + 3) >> gamma_shift][*(sp + 2)];
  169774. *(dp + 2) = (png_byte)((v >> 8) & 0xff);
  169775. *(dp + 3) = (png_byte)(v & 0xff);
  169776. v = gamma_16[*(sp + 5) >> gamma_shift][*(sp + 4)];
  169777. *(dp + 4) = (png_byte)((v >> 8) & 0xff);
  169778. *(dp + 5) = (png_byte)(v & 0xff);
  169779. }
  169780. else if (a == 0)
  169781. {
  169782. *dp = (png_byte)((background->red >> 8) & 0xff);
  169783. *(dp + 1) = (png_byte)(background->red & 0xff);
  169784. *(dp + 2) = (png_byte)((background->green >> 8) & 0xff);
  169785. *(dp + 3) = (png_byte)(background->green & 0xff);
  169786. *(dp + 4) = (png_byte)((background->blue >> 8) & 0xff);
  169787. *(dp + 5) = (png_byte)(background->blue & 0xff);
  169788. }
  169789. else
  169790. {
  169791. png_uint_16 v, w, x;
  169792. v = gamma_16_to_1[*(sp + 1) >> gamma_shift][*sp];
  169793. png_composite_16(w, v, a, background_1->red);
  169794. x = gamma_16_from_1[((w&0xff) >> gamma_shift)][w >> 8];
  169795. *dp = (png_byte)((x >> 8) & 0xff);
  169796. *(dp + 1) = (png_byte)(x & 0xff);
  169797. v = gamma_16_to_1[*(sp + 3) >> gamma_shift][*(sp + 2)];
  169798. png_composite_16(w, v, a, background_1->green);
  169799. x = gamma_16_from_1[((w&0xff) >> gamma_shift)][w >> 8];
  169800. *(dp + 2) = (png_byte)((x >> 8) & 0xff);
  169801. *(dp + 3) = (png_byte)(x & 0xff);
  169802. v = gamma_16_to_1[*(sp + 5) >> gamma_shift][*(sp + 4)];
  169803. png_composite_16(w, v, a, background_1->blue);
  169804. x = gamma_16_from_1[(w & 0xff) >> gamma_shift][w >> 8];
  169805. *(dp + 4) = (png_byte)((x >> 8) & 0xff);
  169806. *(dp + 5) = (png_byte)(x & 0xff);
  169807. }
  169808. }
  169809. }
  169810. else
  169811. #endif
  169812. {
  169813. sp = row;
  169814. dp = row;
  169815. for (i = 0; i < row_width; i++, sp += 8, dp += 6)
  169816. {
  169817. png_uint_16 a = (png_uint_16)(((png_uint_16)(*(sp + 6))
  169818. << 8) + (png_uint_16)(*(sp + 7)));
  169819. if (a == (png_uint_16)0xffff)
  169820. {
  169821. png_memcpy(dp, sp, 6);
  169822. }
  169823. else if (a == 0)
  169824. {
  169825. *dp = (png_byte)((background->red >> 8) & 0xff);
  169826. *(dp + 1) = (png_byte)(background->red & 0xff);
  169827. *(dp + 2) = (png_byte)((background->green >> 8) & 0xff);
  169828. *(dp + 3) = (png_byte)(background->green & 0xff);
  169829. *(dp + 4) = (png_byte)((background->blue >> 8) & 0xff);
  169830. *(dp + 5) = (png_byte)(background->blue & 0xff);
  169831. }
  169832. else
  169833. {
  169834. png_uint_16 v;
  169835. png_uint_16 r = (png_uint_16)(((*sp) << 8) + *(sp + 1));
  169836. png_uint_16 g = (png_uint_16)(((*(sp + 2)) << 8)
  169837. + *(sp + 3));
  169838. png_uint_16 b = (png_uint_16)(((*(sp + 4)) << 8)
  169839. + *(sp + 5));
  169840. png_composite_16(v, r, a, background->red);
  169841. *dp = (png_byte)((v >> 8) & 0xff);
  169842. *(dp + 1) = (png_byte)(v & 0xff);
  169843. png_composite_16(v, g, a, background->green);
  169844. *(dp + 2) = (png_byte)((v >> 8) & 0xff);
  169845. *(dp + 3) = (png_byte)(v & 0xff);
  169846. png_composite_16(v, b, a, background->blue);
  169847. *(dp + 4) = (png_byte)((v >> 8) & 0xff);
  169848. *(dp + 5) = (png_byte)(v & 0xff);
  169849. }
  169850. }
  169851. }
  169852. }
  169853. break;
  169854. }
  169855. }
  169856. if (row_info->color_type & PNG_COLOR_MASK_ALPHA)
  169857. {
  169858. row_info->color_type &= ~PNG_COLOR_MASK_ALPHA;
  169859. row_info->channels--;
  169860. row_info->pixel_depth = (png_byte)(row_info->channels *
  169861. row_info->bit_depth);
  169862. row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,row_width);
  169863. }
  169864. }
  169865. }
  169866. #endif
  169867. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169868. void /* PRIVATE */
  169869. png_do_gamma(png_row_infop row_info, png_bytep row,
  169870. png_bytep gamma_table, png_uint_16pp gamma_16_table,
  169871. int gamma_shift)
  169872. {
  169873. png_bytep sp;
  169874. png_uint_32 i;
  169875. png_uint_32 row_width=row_info->width;
  169876. png_debug(1, "in png_do_gamma\n");
  169877. if (
  169878. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  169879. row != NULL && row_info != NULL &&
  169880. #endif
  169881. ((row_info->bit_depth <= 8 && gamma_table != NULL) ||
  169882. (row_info->bit_depth == 16 && gamma_16_table != NULL)))
  169883. {
  169884. switch (row_info->color_type)
  169885. {
  169886. case PNG_COLOR_TYPE_RGB:
  169887. {
  169888. if (row_info->bit_depth == 8)
  169889. {
  169890. sp = row;
  169891. for (i = 0; i < row_width; i++)
  169892. {
  169893. *sp = gamma_table[*sp];
  169894. sp++;
  169895. *sp = gamma_table[*sp];
  169896. sp++;
  169897. *sp = gamma_table[*sp];
  169898. sp++;
  169899. }
  169900. }
  169901. else /* if (row_info->bit_depth == 16) */
  169902. {
  169903. sp = row;
  169904. for (i = 0; i < row_width; i++)
  169905. {
  169906. png_uint_16 v;
  169907. v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp];
  169908. *sp = (png_byte)((v >> 8) & 0xff);
  169909. *(sp + 1) = (png_byte)(v & 0xff);
  169910. sp += 2;
  169911. v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp];
  169912. *sp = (png_byte)((v >> 8) & 0xff);
  169913. *(sp + 1) = (png_byte)(v & 0xff);
  169914. sp += 2;
  169915. v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp];
  169916. *sp = (png_byte)((v >> 8) & 0xff);
  169917. *(sp + 1) = (png_byte)(v & 0xff);
  169918. sp += 2;
  169919. }
  169920. }
  169921. break;
  169922. }
  169923. case PNG_COLOR_TYPE_RGB_ALPHA:
  169924. {
  169925. if (row_info->bit_depth == 8)
  169926. {
  169927. sp = row;
  169928. for (i = 0; i < row_width; i++)
  169929. {
  169930. *sp = gamma_table[*sp];
  169931. sp++;
  169932. *sp = gamma_table[*sp];
  169933. sp++;
  169934. *sp = gamma_table[*sp];
  169935. sp++;
  169936. sp++;
  169937. }
  169938. }
  169939. else /* if (row_info->bit_depth == 16) */
  169940. {
  169941. sp = row;
  169942. for (i = 0; i < row_width; i++)
  169943. {
  169944. png_uint_16 v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp];
  169945. *sp = (png_byte)((v >> 8) & 0xff);
  169946. *(sp + 1) = (png_byte)(v & 0xff);
  169947. sp += 2;
  169948. v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp];
  169949. *sp = (png_byte)((v >> 8) & 0xff);
  169950. *(sp + 1) = (png_byte)(v & 0xff);
  169951. sp += 2;
  169952. v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp];
  169953. *sp = (png_byte)((v >> 8) & 0xff);
  169954. *(sp + 1) = (png_byte)(v & 0xff);
  169955. sp += 4;
  169956. }
  169957. }
  169958. break;
  169959. }
  169960. case PNG_COLOR_TYPE_GRAY_ALPHA:
  169961. {
  169962. if (row_info->bit_depth == 8)
  169963. {
  169964. sp = row;
  169965. for (i = 0; i < row_width; i++)
  169966. {
  169967. *sp = gamma_table[*sp];
  169968. sp += 2;
  169969. }
  169970. }
  169971. else /* if (row_info->bit_depth == 16) */
  169972. {
  169973. sp = row;
  169974. for (i = 0; i < row_width; i++)
  169975. {
  169976. png_uint_16 v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp];
  169977. *sp = (png_byte)((v >> 8) & 0xff);
  169978. *(sp + 1) = (png_byte)(v & 0xff);
  169979. sp += 4;
  169980. }
  169981. }
  169982. break;
  169983. }
  169984. case PNG_COLOR_TYPE_GRAY:
  169985. {
  169986. if (row_info->bit_depth == 2)
  169987. {
  169988. sp = row;
  169989. for (i = 0; i < row_width; i += 4)
  169990. {
  169991. int a = *sp & 0xc0;
  169992. int b = *sp & 0x30;
  169993. int c = *sp & 0x0c;
  169994. int d = *sp & 0x03;
  169995. *sp = (png_byte)(
  169996. ((((int)gamma_table[a|(a>>2)|(a>>4)|(a>>6)]) ) & 0xc0)|
  169997. ((((int)gamma_table[(b<<2)|b|(b>>2)|(b>>4)])>>2) & 0x30)|
  169998. ((((int)gamma_table[(c<<4)|(c<<2)|c|(c>>2)])>>4) & 0x0c)|
  169999. ((((int)gamma_table[(d<<6)|(d<<4)|(d<<2)|d])>>6) ));
  170000. sp++;
  170001. }
  170002. }
  170003. if (row_info->bit_depth == 4)
  170004. {
  170005. sp = row;
  170006. for (i = 0; i < row_width; i += 2)
  170007. {
  170008. int msb = *sp & 0xf0;
  170009. int lsb = *sp & 0x0f;
  170010. *sp = (png_byte)((((int)gamma_table[msb | (msb >> 4)]) & 0xf0)
  170011. | (((int)gamma_table[(lsb << 4) | lsb]) >> 4));
  170012. sp++;
  170013. }
  170014. }
  170015. else if (row_info->bit_depth == 8)
  170016. {
  170017. sp = row;
  170018. for (i = 0; i < row_width; i++)
  170019. {
  170020. *sp = gamma_table[*sp];
  170021. sp++;
  170022. }
  170023. }
  170024. else if (row_info->bit_depth == 16)
  170025. {
  170026. sp = row;
  170027. for (i = 0; i < row_width; i++)
  170028. {
  170029. png_uint_16 v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp];
  170030. *sp = (png_byte)((v >> 8) & 0xff);
  170031. *(sp + 1) = (png_byte)(v & 0xff);
  170032. sp += 2;
  170033. }
  170034. }
  170035. break;
  170036. }
  170037. }
  170038. }
  170039. }
  170040. #endif
  170041. #if defined(PNG_READ_EXPAND_SUPPORTED)
  170042. void /* PRIVATE */
  170043. png_do_expand_palette(png_row_infop row_info, png_bytep row,
  170044. png_colorp palette, png_bytep trans, int num_trans)
  170045. {
  170046. int shift, value;
  170047. png_bytep sp, dp;
  170048. png_uint_32 i;
  170049. png_uint_32 row_width=row_info->width;
  170050. png_debug(1, "in png_do_expand_palette\n");
  170051. if (
  170052. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  170053. row != NULL && row_info != NULL &&
  170054. #endif
  170055. row_info->color_type == PNG_COLOR_TYPE_PALETTE)
  170056. {
  170057. if (row_info->bit_depth < 8)
  170058. {
  170059. switch (row_info->bit_depth)
  170060. {
  170061. case 1:
  170062. {
  170063. sp = row + (png_size_t)((row_width - 1) >> 3);
  170064. dp = row + (png_size_t)row_width - 1;
  170065. shift = 7 - (int)((row_width + 7) & 0x07);
  170066. for (i = 0; i < row_width; i++)
  170067. {
  170068. if ((*sp >> shift) & 0x01)
  170069. *dp = 1;
  170070. else
  170071. *dp = 0;
  170072. if (shift == 7)
  170073. {
  170074. shift = 0;
  170075. sp--;
  170076. }
  170077. else
  170078. shift++;
  170079. dp--;
  170080. }
  170081. break;
  170082. }
  170083. case 2:
  170084. {
  170085. sp = row + (png_size_t)((row_width - 1) >> 2);
  170086. dp = row + (png_size_t)row_width - 1;
  170087. shift = (int)((3 - ((row_width + 3) & 0x03)) << 1);
  170088. for (i = 0; i < row_width; i++)
  170089. {
  170090. value = (*sp >> shift) & 0x03;
  170091. *dp = (png_byte)value;
  170092. if (shift == 6)
  170093. {
  170094. shift = 0;
  170095. sp--;
  170096. }
  170097. else
  170098. shift += 2;
  170099. dp--;
  170100. }
  170101. break;
  170102. }
  170103. case 4:
  170104. {
  170105. sp = row + (png_size_t)((row_width - 1) >> 1);
  170106. dp = row + (png_size_t)row_width - 1;
  170107. shift = (int)((row_width & 0x01) << 2);
  170108. for (i = 0; i < row_width; i++)
  170109. {
  170110. value = (*sp >> shift) & 0x0f;
  170111. *dp = (png_byte)value;
  170112. if (shift == 4)
  170113. {
  170114. shift = 0;
  170115. sp--;
  170116. }
  170117. else
  170118. shift += 4;
  170119. dp--;
  170120. }
  170121. break;
  170122. }
  170123. }
  170124. row_info->bit_depth = 8;
  170125. row_info->pixel_depth = 8;
  170126. row_info->rowbytes = row_width;
  170127. }
  170128. switch (row_info->bit_depth)
  170129. {
  170130. case 8:
  170131. {
  170132. if (trans != NULL)
  170133. {
  170134. sp = row + (png_size_t)row_width - 1;
  170135. dp = row + (png_size_t)(row_width << 2) - 1;
  170136. for (i = 0; i < row_width; i++)
  170137. {
  170138. if ((int)(*sp) >= num_trans)
  170139. *dp-- = 0xff;
  170140. else
  170141. *dp-- = trans[*sp];
  170142. *dp-- = palette[*sp].blue;
  170143. *dp-- = palette[*sp].green;
  170144. *dp-- = palette[*sp].red;
  170145. sp--;
  170146. }
  170147. row_info->bit_depth = 8;
  170148. row_info->pixel_depth = 32;
  170149. row_info->rowbytes = row_width * 4;
  170150. row_info->color_type = 6;
  170151. row_info->channels = 4;
  170152. }
  170153. else
  170154. {
  170155. sp = row + (png_size_t)row_width - 1;
  170156. dp = row + (png_size_t)(row_width * 3) - 1;
  170157. for (i = 0; i < row_width; i++)
  170158. {
  170159. *dp-- = palette[*sp].blue;
  170160. *dp-- = palette[*sp].green;
  170161. *dp-- = palette[*sp].red;
  170162. sp--;
  170163. }
  170164. row_info->bit_depth = 8;
  170165. row_info->pixel_depth = 24;
  170166. row_info->rowbytes = row_width * 3;
  170167. row_info->color_type = 2;
  170168. row_info->channels = 3;
  170169. }
  170170. break;
  170171. }
  170172. }
  170173. }
  170174. }
  170175. void /* PRIVATE */
  170176. png_do_expand(png_row_infop row_info, png_bytep row,
  170177. png_color_16p trans_value)
  170178. {
  170179. int shift, value;
  170180. png_bytep sp, dp;
  170181. png_uint_32 i;
  170182. png_uint_32 row_width=row_info->width;
  170183. png_debug(1, "in png_do_expand\n");
  170184. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  170185. if (row != NULL && row_info != NULL)
  170186. #endif
  170187. {
  170188. if (row_info->color_type == PNG_COLOR_TYPE_GRAY)
  170189. {
  170190. png_uint_16 gray = (png_uint_16)(trans_value ? trans_value->gray : 0);
  170191. if (row_info->bit_depth < 8)
  170192. {
  170193. switch (row_info->bit_depth)
  170194. {
  170195. case 1:
  170196. {
  170197. gray = (png_uint_16)((gray&0x01)*0xff);
  170198. sp = row + (png_size_t)((row_width - 1) >> 3);
  170199. dp = row + (png_size_t)row_width - 1;
  170200. shift = 7 - (int)((row_width + 7) & 0x07);
  170201. for (i = 0; i < row_width; i++)
  170202. {
  170203. if ((*sp >> shift) & 0x01)
  170204. *dp = 0xff;
  170205. else
  170206. *dp = 0;
  170207. if (shift == 7)
  170208. {
  170209. shift = 0;
  170210. sp--;
  170211. }
  170212. else
  170213. shift++;
  170214. dp--;
  170215. }
  170216. break;
  170217. }
  170218. case 2:
  170219. {
  170220. gray = (png_uint_16)((gray&0x03)*0x55);
  170221. sp = row + (png_size_t)((row_width - 1) >> 2);
  170222. dp = row + (png_size_t)row_width - 1;
  170223. shift = (int)((3 - ((row_width + 3) & 0x03)) << 1);
  170224. for (i = 0; i < row_width; i++)
  170225. {
  170226. value = (*sp >> shift) & 0x03;
  170227. *dp = (png_byte)(value | (value << 2) | (value << 4) |
  170228. (value << 6));
  170229. if (shift == 6)
  170230. {
  170231. shift = 0;
  170232. sp--;
  170233. }
  170234. else
  170235. shift += 2;
  170236. dp--;
  170237. }
  170238. break;
  170239. }
  170240. case 4:
  170241. {
  170242. gray = (png_uint_16)((gray&0x0f)*0x11);
  170243. sp = row + (png_size_t)((row_width - 1) >> 1);
  170244. dp = row + (png_size_t)row_width - 1;
  170245. shift = (int)((1 - ((row_width + 1) & 0x01)) << 2);
  170246. for (i = 0; i < row_width; i++)
  170247. {
  170248. value = (*sp >> shift) & 0x0f;
  170249. *dp = (png_byte)(value | (value << 4));
  170250. if (shift == 4)
  170251. {
  170252. shift = 0;
  170253. sp--;
  170254. }
  170255. else
  170256. shift = 4;
  170257. dp--;
  170258. }
  170259. break;
  170260. }
  170261. }
  170262. row_info->bit_depth = 8;
  170263. row_info->pixel_depth = 8;
  170264. row_info->rowbytes = row_width;
  170265. }
  170266. if (trans_value != NULL)
  170267. {
  170268. if (row_info->bit_depth == 8)
  170269. {
  170270. gray = gray & 0xff;
  170271. sp = row + (png_size_t)row_width - 1;
  170272. dp = row + (png_size_t)(row_width << 1) - 1;
  170273. for (i = 0; i < row_width; i++)
  170274. {
  170275. if (*sp == gray)
  170276. *dp-- = 0;
  170277. else
  170278. *dp-- = 0xff;
  170279. *dp-- = *sp--;
  170280. }
  170281. }
  170282. else if (row_info->bit_depth == 16)
  170283. {
  170284. png_byte gray_high = (gray >> 8) & 0xff;
  170285. png_byte gray_low = gray & 0xff;
  170286. sp = row + row_info->rowbytes - 1;
  170287. dp = row + (row_info->rowbytes << 1) - 1;
  170288. for (i = 0; i < row_width; i++)
  170289. {
  170290. if (*(sp-1) == gray_high && *(sp) == gray_low)
  170291. {
  170292. *dp-- = 0;
  170293. *dp-- = 0;
  170294. }
  170295. else
  170296. {
  170297. *dp-- = 0xff;
  170298. *dp-- = 0xff;
  170299. }
  170300. *dp-- = *sp--;
  170301. *dp-- = *sp--;
  170302. }
  170303. }
  170304. row_info->color_type = PNG_COLOR_TYPE_GRAY_ALPHA;
  170305. row_info->channels = 2;
  170306. row_info->pixel_depth = (png_byte)(row_info->bit_depth << 1);
  170307. row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,
  170308. row_width);
  170309. }
  170310. }
  170311. else if (row_info->color_type == PNG_COLOR_TYPE_RGB && trans_value)
  170312. {
  170313. if (row_info->bit_depth == 8)
  170314. {
  170315. png_byte red = trans_value->red & 0xff;
  170316. png_byte green = trans_value->green & 0xff;
  170317. png_byte blue = trans_value->blue & 0xff;
  170318. sp = row + (png_size_t)row_info->rowbytes - 1;
  170319. dp = row + (png_size_t)(row_width << 2) - 1;
  170320. for (i = 0; i < row_width; i++)
  170321. {
  170322. if (*(sp - 2) == red && *(sp - 1) == green && *(sp) == blue)
  170323. *dp-- = 0;
  170324. else
  170325. *dp-- = 0xff;
  170326. *dp-- = *sp--;
  170327. *dp-- = *sp--;
  170328. *dp-- = *sp--;
  170329. }
  170330. }
  170331. else if (row_info->bit_depth == 16)
  170332. {
  170333. png_byte red_high = (trans_value->red >> 8) & 0xff;
  170334. png_byte green_high = (trans_value->green >> 8) & 0xff;
  170335. png_byte blue_high = (trans_value->blue >> 8) & 0xff;
  170336. png_byte red_low = trans_value->red & 0xff;
  170337. png_byte green_low = trans_value->green & 0xff;
  170338. png_byte blue_low = trans_value->blue & 0xff;
  170339. sp = row + row_info->rowbytes - 1;
  170340. dp = row + (png_size_t)(row_width << 3) - 1;
  170341. for (i = 0; i < row_width; i++)
  170342. {
  170343. if (*(sp - 5) == red_high &&
  170344. *(sp - 4) == red_low &&
  170345. *(sp - 3) == green_high &&
  170346. *(sp - 2) == green_low &&
  170347. *(sp - 1) == blue_high &&
  170348. *(sp ) == blue_low)
  170349. {
  170350. *dp-- = 0;
  170351. *dp-- = 0;
  170352. }
  170353. else
  170354. {
  170355. *dp-- = 0xff;
  170356. *dp-- = 0xff;
  170357. }
  170358. *dp-- = *sp--;
  170359. *dp-- = *sp--;
  170360. *dp-- = *sp--;
  170361. *dp-- = *sp--;
  170362. *dp-- = *sp--;
  170363. *dp-- = *sp--;
  170364. }
  170365. }
  170366. row_info->color_type = PNG_COLOR_TYPE_RGB_ALPHA;
  170367. row_info->channels = 4;
  170368. row_info->pixel_depth = (png_byte)(row_info->bit_depth << 2);
  170369. row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,row_width);
  170370. }
  170371. }
  170372. }
  170373. #endif
  170374. #if defined(PNG_READ_DITHER_SUPPORTED)
  170375. void /* PRIVATE */
  170376. png_do_dither(png_row_infop row_info, png_bytep row,
  170377. png_bytep palette_lookup, png_bytep dither_lookup)
  170378. {
  170379. png_bytep sp, dp;
  170380. png_uint_32 i;
  170381. png_uint_32 row_width=row_info->width;
  170382. png_debug(1, "in png_do_dither\n");
  170383. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  170384. if (row != NULL && row_info != NULL)
  170385. #endif
  170386. {
  170387. if (row_info->color_type == PNG_COLOR_TYPE_RGB &&
  170388. palette_lookup && row_info->bit_depth == 8)
  170389. {
  170390. int r, g, b, p;
  170391. sp = row;
  170392. dp = row;
  170393. for (i = 0; i < row_width; i++)
  170394. {
  170395. r = *sp++;
  170396. g = *sp++;
  170397. b = *sp++;
  170398. p = (((r >> (8 - PNG_DITHER_RED_BITS)) &
  170399. ((1 << PNG_DITHER_RED_BITS) - 1)) <<
  170400. (PNG_DITHER_GREEN_BITS + PNG_DITHER_BLUE_BITS)) |
  170401. (((g >> (8 - PNG_DITHER_GREEN_BITS)) &
  170402. ((1 << PNG_DITHER_GREEN_BITS) - 1)) <<
  170403. (PNG_DITHER_BLUE_BITS)) |
  170404. ((b >> (8 - PNG_DITHER_BLUE_BITS)) &
  170405. ((1 << PNG_DITHER_BLUE_BITS) - 1));
  170406. *dp++ = palette_lookup[p];
  170407. }
  170408. row_info->color_type = PNG_COLOR_TYPE_PALETTE;
  170409. row_info->channels = 1;
  170410. row_info->pixel_depth = row_info->bit_depth;
  170411. row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,row_width);
  170412. }
  170413. else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA &&
  170414. palette_lookup != NULL && row_info->bit_depth == 8)
  170415. {
  170416. int r, g, b, p;
  170417. sp = row;
  170418. dp = row;
  170419. for (i = 0; i < row_width; i++)
  170420. {
  170421. r = *sp++;
  170422. g = *sp++;
  170423. b = *sp++;
  170424. sp++;
  170425. p = (((r >> (8 - PNG_DITHER_RED_BITS)) &
  170426. ((1 << PNG_DITHER_RED_BITS) - 1)) <<
  170427. (PNG_DITHER_GREEN_BITS + PNG_DITHER_BLUE_BITS)) |
  170428. (((g >> (8 - PNG_DITHER_GREEN_BITS)) &
  170429. ((1 << PNG_DITHER_GREEN_BITS) - 1)) <<
  170430. (PNG_DITHER_BLUE_BITS)) |
  170431. ((b >> (8 - PNG_DITHER_BLUE_BITS)) &
  170432. ((1 << PNG_DITHER_BLUE_BITS) - 1));
  170433. *dp++ = palette_lookup[p];
  170434. }
  170435. row_info->color_type = PNG_COLOR_TYPE_PALETTE;
  170436. row_info->channels = 1;
  170437. row_info->pixel_depth = row_info->bit_depth;
  170438. row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,row_width);
  170439. }
  170440. else if (row_info->color_type == PNG_COLOR_TYPE_PALETTE &&
  170441. dither_lookup && row_info->bit_depth == 8)
  170442. {
  170443. sp = row;
  170444. for (i = 0; i < row_width; i++, sp++)
  170445. {
  170446. *sp = dither_lookup[*sp];
  170447. }
  170448. }
  170449. }
  170450. }
  170451. #endif
  170452. #ifdef PNG_FLOATING_POINT_SUPPORTED
  170453. #if defined(PNG_READ_GAMMA_SUPPORTED)
  170454. static PNG_CONST int png_gamma_shift[] =
  170455. {0x10, 0x21, 0x42, 0x84, 0x110, 0x248, 0x550, 0xff0, 0x00};
  170456. void /* PRIVATE */
  170457. png_build_gamma_table(png_structp png_ptr)
  170458. {
  170459. png_debug(1, "in png_build_gamma_table\n");
  170460. if (png_ptr->bit_depth <= 8)
  170461. {
  170462. int i;
  170463. double g;
  170464. if (png_ptr->screen_gamma > .000001)
  170465. g = 1.0 / (png_ptr->gamma * png_ptr->screen_gamma);
  170466. else
  170467. g = 1.0;
  170468. png_ptr->gamma_table = (png_bytep)png_malloc(png_ptr,
  170469. (png_uint_32)256);
  170470. for (i = 0; i < 256; i++)
  170471. {
  170472. png_ptr->gamma_table[i] = (png_byte)(pow((double)i / 255.0,
  170473. g) * 255.0 + .5);
  170474. }
  170475. #if defined(PNG_READ_BACKGROUND_SUPPORTED) || \
  170476. defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
  170477. if (png_ptr->transformations & ((PNG_BACKGROUND) | PNG_RGB_TO_GRAY))
  170478. {
  170479. g = 1.0 / (png_ptr->gamma);
  170480. png_ptr->gamma_to_1 = (png_bytep)png_malloc(png_ptr,
  170481. (png_uint_32)256);
  170482. for (i = 0; i < 256; i++)
  170483. {
  170484. png_ptr->gamma_to_1[i] = (png_byte)(pow((double)i / 255.0,
  170485. g) * 255.0 + .5);
  170486. }
  170487. png_ptr->gamma_from_1 = (png_bytep)png_malloc(png_ptr,
  170488. (png_uint_32)256);
  170489. if(png_ptr->screen_gamma > 0.000001)
  170490. g = 1.0 / png_ptr->screen_gamma;
  170491. else
  170492. g = png_ptr->gamma; /* probably doing rgb_to_gray */
  170493. for (i = 0; i < 256; i++)
  170494. {
  170495. png_ptr->gamma_from_1[i] = (png_byte)(pow((double)i / 255.0,
  170496. g) * 255.0 + .5);
  170497. }
  170498. }
  170499. #endif /* PNG_READ_BACKGROUND_SUPPORTED || PNG_RGB_TO_GRAY_SUPPORTED */
  170500. }
  170501. else
  170502. {
  170503. double g;
  170504. int i, j, shift, num;
  170505. int sig_bit;
  170506. png_uint_32 ig;
  170507. if (png_ptr->color_type & PNG_COLOR_MASK_COLOR)
  170508. {
  170509. sig_bit = (int)png_ptr->sig_bit.red;
  170510. if ((int)png_ptr->sig_bit.green > sig_bit)
  170511. sig_bit = png_ptr->sig_bit.green;
  170512. if ((int)png_ptr->sig_bit.blue > sig_bit)
  170513. sig_bit = png_ptr->sig_bit.blue;
  170514. }
  170515. else
  170516. {
  170517. sig_bit = (int)png_ptr->sig_bit.gray;
  170518. }
  170519. if (sig_bit > 0)
  170520. shift = 16 - sig_bit;
  170521. else
  170522. shift = 0;
  170523. if (png_ptr->transformations & PNG_16_TO_8)
  170524. {
  170525. if (shift < (16 - PNG_MAX_GAMMA_8))
  170526. shift = (16 - PNG_MAX_GAMMA_8);
  170527. }
  170528. if (shift > 8)
  170529. shift = 8;
  170530. if (shift < 0)
  170531. shift = 0;
  170532. png_ptr->gamma_shift = (png_byte)shift;
  170533. num = (1 << (8 - shift));
  170534. if (png_ptr->screen_gamma > .000001)
  170535. g = 1.0 / (png_ptr->gamma * png_ptr->screen_gamma);
  170536. else
  170537. g = 1.0;
  170538. png_ptr->gamma_16_table = (png_uint_16pp)png_malloc(png_ptr,
  170539. (png_uint_32)(num * png_sizeof (png_uint_16p)));
  170540. if (png_ptr->transformations & (PNG_16_TO_8 | PNG_BACKGROUND))
  170541. {
  170542. double fin, fout;
  170543. png_uint_32 last, max;
  170544. for (i = 0; i < num; i++)
  170545. {
  170546. png_ptr->gamma_16_table[i] = (png_uint_16p)png_malloc(png_ptr,
  170547. (png_uint_32)(256 * png_sizeof (png_uint_16)));
  170548. }
  170549. g = 1.0 / g;
  170550. last = 0;
  170551. for (i = 0; i < 256; i++)
  170552. {
  170553. fout = ((double)i + 0.5) / 256.0;
  170554. fin = pow(fout, g);
  170555. max = (png_uint_32)(fin * (double)((png_uint_32)num << 8));
  170556. while (last <= max)
  170557. {
  170558. png_ptr->gamma_16_table[(int)(last & (0xff >> shift))]
  170559. [(int)(last >> (8 - shift))] = (png_uint_16)(
  170560. (png_uint_16)i | ((png_uint_16)i << 8));
  170561. last++;
  170562. }
  170563. }
  170564. while (last < ((png_uint_32)num << 8))
  170565. {
  170566. png_ptr->gamma_16_table[(int)(last & (0xff >> shift))]
  170567. [(int)(last >> (8 - shift))] = (png_uint_16)65535L;
  170568. last++;
  170569. }
  170570. }
  170571. else
  170572. {
  170573. for (i = 0; i < num; i++)
  170574. {
  170575. png_ptr->gamma_16_table[i] = (png_uint_16p)png_malloc(png_ptr,
  170576. (png_uint_32)(256 * png_sizeof (png_uint_16)));
  170577. ig = (((png_uint_32)i * (png_uint_32)png_gamma_shift[shift]) >> 4);
  170578. for (j = 0; j < 256; j++)
  170579. {
  170580. png_ptr->gamma_16_table[i][j] =
  170581. (png_uint_16)(pow((double)(ig + ((png_uint_32)j << 8)) /
  170582. 65535.0, g) * 65535.0 + .5);
  170583. }
  170584. }
  170585. }
  170586. #if defined(PNG_READ_BACKGROUND_SUPPORTED) || \
  170587. defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
  170588. if (png_ptr->transformations & (PNG_BACKGROUND | PNG_RGB_TO_GRAY))
  170589. {
  170590. g = 1.0 / (png_ptr->gamma);
  170591. png_ptr->gamma_16_to_1 = (png_uint_16pp)png_malloc(png_ptr,
  170592. (png_uint_32)(num * png_sizeof (png_uint_16p )));
  170593. for (i = 0; i < num; i++)
  170594. {
  170595. png_ptr->gamma_16_to_1[i] = (png_uint_16p)png_malloc(png_ptr,
  170596. (png_uint_32)(256 * png_sizeof (png_uint_16)));
  170597. ig = (((png_uint_32)i *
  170598. (png_uint_32)png_gamma_shift[shift]) >> 4);
  170599. for (j = 0; j < 256; j++)
  170600. {
  170601. png_ptr->gamma_16_to_1[i][j] =
  170602. (png_uint_16)(pow((double)(ig + ((png_uint_32)j << 8)) /
  170603. 65535.0, g) * 65535.0 + .5);
  170604. }
  170605. }
  170606. if(png_ptr->screen_gamma > 0.000001)
  170607. g = 1.0 / png_ptr->screen_gamma;
  170608. else
  170609. g = png_ptr->gamma; /* probably doing rgb_to_gray */
  170610. png_ptr->gamma_16_from_1 = (png_uint_16pp)png_malloc(png_ptr,
  170611. (png_uint_32)(num * png_sizeof (png_uint_16p)));
  170612. for (i = 0; i < num; i++)
  170613. {
  170614. png_ptr->gamma_16_from_1[i] = (png_uint_16p)png_malloc(png_ptr,
  170615. (png_uint_32)(256 * png_sizeof (png_uint_16)));
  170616. ig = (((png_uint_32)i *
  170617. (png_uint_32)png_gamma_shift[shift]) >> 4);
  170618. for (j = 0; j < 256; j++)
  170619. {
  170620. png_ptr->gamma_16_from_1[i][j] =
  170621. (png_uint_16)(pow((double)(ig + ((png_uint_32)j << 8)) /
  170622. 65535.0, g) * 65535.0 + .5);
  170623. }
  170624. }
  170625. }
  170626. #endif /* PNG_READ_BACKGROUND_SUPPORTED || PNG_RGB_TO_GRAY_SUPPORTED */
  170627. }
  170628. }
  170629. #endif
  170630. #endif
  170631. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  170632. void /* PRIVATE */
  170633. png_do_read_intrapixel(png_row_infop row_info, png_bytep row)
  170634. {
  170635. png_debug(1, "in png_do_read_intrapixel\n");
  170636. if (
  170637. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  170638. row != NULL && row_info != NULL &&
  170639. #endif
  170640. (row_info->color_type & PNG_COLOR_MASK_COLOR))
  170641. {
  170642. int bytes_per_pixel;
  170643. png_uint_32 row_width = row_info->width;
  170644. if (row_info->bit_depth == 8)
  170645. {
  170646. png_bytep rp;
  170647. png_uint_32 i;
  170648. if (row_info->color_type == PNG_COLOR_TYPE_RGB)
  170649. bytes_per_pixel = 3;
  170650. else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  170651. bytes_per_pixel = 4;
  170652. else
  170653. return;
  170654. for (i = 0, rp = row; i < row_width; i++, rp += bytes_per_pixel)
  170655. {
  170656. *(rp) = (png_byte)((256 + *rp + *(rp+1))&0xff);
  170657. *(rp+2) = (png_byte)((256 + *(rp+2) + *(rp+1))&0xff);
  170658. }
  170659. }
  170660. else if (row_info->bit_depth == 16)
  170661. {
  170662. png_bytep rp;
  170663. png_uint_32 i;
  170664. if (row_info->color_type == PNG_COLOR_TYPE_RGB)
  170665. bytes_per_pixel = 6;
  170666. else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  170667. bytes_per_pixel = 8;
  170668. else
  170669. return;
  170670. for (i = 0, rp = row; i < row_width; i++, rp += bytes_per_pixel)
  170671. {
  170672. png_uint_32 s0 = (*(rp ) << 8) | *(rp+1);
  170673. png_uint_32 s1 = (*(rp+2) << 8) | *(rp+3);
  170674. png_uint_32 s2 = (*(rp+4) << 8) | *(rp+5);
  170675. png_uint_32 red = (png_uint_32)((s0+s1+65536L) & 0xffffL);
  170676. png_uint_32 blue = (png_uint_32)((s2+s1+65536L) & 0xffffL);
  170677. *(rp ) = (png_byte)((red >> 8) & 0xff);
  170678. *(rp+1) = (png_byte)(red & 0xff);
  170679. *(rp+4) = (png_byte)((blue >> 8) & 0xff);
  170680. *(rp+5) = (png_byte)(blue & 0xff);
  170681. }
  170682. }
  170683. }
  170684. }
  170685. #endif /* PNG_MNG_FEATURES_SUPPORTED */
  170686. #endif /* PNG_READ_SUPPORTED */
  170687. /*** End of inlined file: pngrtran.c ***/
  170688. /*** Start of inlined file: pngrutil.c ***/
  170689. #define PNG_INTERNAL
  170690. #if defined(PNG_READ_SUPPORTED)
  170691. #if defined(_WIN32_WCE) && (_WIN32_WCE<0x500)
  170692. # define WIN32_WCE_OLD
  170693. #endif
  170694. #ifdef PNG_FLOATING_POINT_SUPPORTED
  170695. # if defined(WIN32_WCE_OLD)
  170696. __inline double png_strtod(png_structp png_ptr, PNG_CONST char *nptr, char **endptr)
  170697. {
  170698. double result = 0;
  170699. int len;
  170700. wchar_t *str, *end;
  170701. len = MultiByteToWideChar(CP_ACP, 0, nptr, -1, NULL, 0);
  170702. str = (wchar_t *)png_malloc(png_ptr, len * sizeof(wchar_t));
  170703. if ( NULL != str )
  170704. {
  170705. MultiByteToWideChar(CP_ACP, 0, nptr, -1, str, len);
  170706. result = wcstod(str, &end);
  170707. len = WideCharToMultiByte(CP_ACP, 0, end, -1, NULL, 0, NULL, NULL);
  170708. *endptr = (char *)nptr + (png_strlen(nptr) - len + 1);
  170709. png_free(png_ptr, str);
  170710. }
  170711. return result;
  170712. }
  170713. # else
  170714. # define png_strtod(p,a,b) strtod(a,b)
  170715. # endif
  170716. #endif
  170717. png_uint_32 PNGAPI
  170718. png_get_uint_31(png_structp png_ptr, png_bytep buf)
  170719. {
  170720. png_uint_32 i = png_get_uint_32(buf);
  170721. if (i > PNG_UINT_31_MAX)
  170722. png_error(png_ptr, "PNG unsigned integer out of range.");
  170723. return (i);
  170724. }
  170725. #ifndef PNG_READ_BIG_ENDIAN_SUPPORTED
  170726. png_uint_32 PNGAPI
  170727. png_get_uint_32(png_bytep buf)
  170728. {
  170729. png_uint_32 i = ((png_uint_32)(*buf) << 24) +
  170730. ((png_uint_32)(*(buf + 1)) << 16) +
  170731. ((png_uint_32)(*(buf + 2)) << 8) +
  170732. (png_uint_32)(*(buf + 3));
  170733. return (i);
  170734. }
  170735. png_int_32 PNGAPI
  170736. png_get_int_32(png_bytep buf)
  170737. {
  170738. png_int_32 i = ((png_int_32)(*buf) << 24) +
  170739. ((png_int_32)(*(buf + 1)) << 16) +
  170740. ((png_int_32)(*(buf + 2)) << 8) +
  170741. (png_int_32)(*(buf + 3));
  170742. return (i);
  170743. }
  170744. png_uint_16 PNGAPI
  170745. png_get_uint_16(png_bytep buf)
  170746. {
  170747. png_uint_16 i = (png_uint_16)(((png_uint_16)(*buf) << 8) +
  170748. (png_uint_16)(*(buf + 1)));
  170749. return (i);
  170750. }
  170751. #endif /* PNG_READ_BIG_ENDIAN_SUPPORTED */
  170752. void /* PRIVATE */
  170753. png_crc_read(png_structp png_ptr, png_bytep buf, png_size_t length)
  170754. {
  170755. if(png_ptr == NULL) return;
  170756. png_read_data(png_ptr, buf, length);
  170757. png_calculate_crc(png_ptr, buf, length);
  170758. }
  170759. int /* PRIVATE */
  170760. png_crc_finish(png_structp png_ptr, png_uint_32 skip)
  170761. {
  170762. png_size_t i;
  170763. png_size_t istop = png_ptr->zbuf_size;
  170764. for (i = (png_size_t)skip; i > istop; i -= istop)
  170765. {
  170766. png_crc_read(png_ptr, png_ptr->zbuf, png_ptr->zbuf_size);
  170767. }
  170768. if (i)
  170769. {
  170770. png_crc_read(png_ptr, png_ptr->zbuf, i);
  170771. }
  170772. if (png_crc_error(png_ptr))
  170773. {
  170774. if (((png_ptr->chunk_name[0] & 0x20) && /* Ancillary */
  170775. !(png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_NOWARN)) ||
  170776. (!(png_ptr->chunk_name[0] & 0x20) && /* Critical */
  170777. (png_ptr->flags & PNG_FLAG_CRC_CRITICAL_USE)))
  170778. {
  170779. png_chunk_warning(png_ptr, "CRC error");
  170780. }
  170781. else
  170782. {
  170783. png_chunk_error(png_ptr, "CRC error");
  170784. }
  170785. return (1);
  170786. }
  170787. return (0);
  170788. }
  170789. int /* PRIVATE */
  170790. png_crc_error(png_structp png_ptr)
  170791. {
  170792. png_byte crc_bytes[4];
  170793. png_uint_32 crc;
  170794. int need_crc = 1;
  170795. if (png_ptr->chunk_name[0] & 0x20) /* ancillary */
  170796. {
  170797. if ((png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_MASK) ==
  170798. (PNG_FLAG_CRC_ANCILLARY_USE | PNG_FLAG_CRC_ANCILLARY_NOWARN))
  170799. need_crc = 0;
  170800. }
  170801. else /* critical */
  170802. {
  170803. if (png_ptr->flags & PNG_FLAG_CRC_CRITICAL_IGNORE)
  170804. need_crc = 0;
  170805. }
  170806. png_read_data(png_ptr, crc_bytes, 4);
  170807. if (need_crc)
  170808. {
  170809. crc = png_get_uint_32(crc_bytes);
  170810. return ((int)(crc != png_ptr->crc));
  170811. }
  170812. else
  170813. return (0);
  170814. }
  170815. #if defined(PNG_READ_zTXt_SUPPORTED) || defined(PNG_READ_iTXt_SUPPORTED) || \
  170816. defined(PNG_READ_iCCP_SUPPORTED)
  170817. png_charp /* PRIVATE */
  170818. png_decompress_chunk(png_structp png_ptr, int comp_type,
  170819. png_charp chunkdata, png_size_t chunklength,
  170820. png_size_t prefix_size, png_size_t *newlength)
  170821. {
  170822. static PNG_CONST char msg[] = "Error decoding compressed text";
  170823. png_charp text;
  170824. png_size_t text_size;
  170825. if (comp_type == PNG_COMPRESSION_TYPE_BASE)
  170826. {
  170827. int ret = Z_OK;
  170828. png_ptr->zstream.next_in = (png_bytep)(chunkdata + prefix_size);
  170829. png_ptr->zstream.avail_in = (uInt)(chunklength - prefix_size);
  170830. png_ptr->zstream.next_out = png_ptr->zbuf;
  170831. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  170832. text_size = 0;
  170833. text = NULL;
  170834. while (png_ptr->zstream.avail_in)
  170835. {
  170836. ret = inflate(&png_ptr->zstream, Z_PARTIAL_FLUSH);
  170837. if (ret != Z_OK && ret != Z_STREAM_END)
  170838. {
  170839. if (png_ptr->zstream.msg != NULL)
  170840. png_warning(png_ptr, png_ptr->zstream.msg);
  170841. else
  170842. png_warning(png_ptr, msg);
  170843. inflateReset(&png_ptr->zstream);
  170844. png_ptr->zstream.avail_in = 0;
  170845. if (text == NULL)
  170846. {
  170847. text_size = prefix_size + png_sizeof(msg) + 1;
  170848. text = (png_charp)png_malloc_warn(png_ptr, text_size);
  170849. if (text == NULL)
  170850. {
  170851. png_free(png_ptr,chunkdata);
  170852. png_error(png_ptr,"Not enough memory to decompress chunk");
  170853. }
  170854. png_memcpy(text, chunkdata, prefix_size);
  170855. }
  170856. text[text_size - 1] = 0x00;
  170857. text_size = (png_size_t)(chunklength - (text - chunkdata) - 1);
  170858. text_size = png_sizeof(msg) > text_size ? text_size :
  170859. png_sizeof(msg);
  170860. png_memcpy(text + prefix_size, msg, text_size + 1);
  170861. break;
  170862. }
  170863. if (!png_ptr->zstream.avail_out || ret == Z_STREAM_END)
  170864. {
  170865. if (text == NULL)
  170866. {
  170867. text_size = prefix_size +
  170868. png_ptr->zbuf_size - png_ptr->zstream.avail_out;
  170869. text = (png_charp)png_malloc_warn(png_ptr, text_size + 1);
  170870. if (text == NULL)
  170871. {
  170872. png_free(png_ptr,chunkdata);
  170873. png_error(png_ptr,"Not enough memory to decompress chunk.");
  170874. }
  170875. png_memcpy(text + prefix_size, png_ptr->zbuf,
  170876. text_size - prefix_size);
  170877. png_memcpy(text, chunkdata, prefix_size);
  170878. *(text + text_size) = 0x00;
  170879. }
  170880. else
  170881. {
  170882. png_charp tmp;
  170883. tmp = text;
  170884. text = (png_charp)png_malloc_warn(png_ptr,
  170885. (png_uint_32)(text_size +
  170886. png_ptr->zbuf_size - png_ptr->zstream.avail_out + 1));
  170887. if (text == NULL)
  170888. {
  170889. png_free(png_ptr, tmp);
  170890. png_free(png_ptr, chunkdata);
  170891. png_error(png_ptr,"Not enough memory to decompress chunk..");
  170892. }
  170893. png_memcpy(text, tmp, text_size);
  170894. png_free(png_ptr, tmp);
  170895. png_memcpy(text + text_size, png_ptr->zbuf,
  170896. (png_ptr->zbuf_size - png_ptr->zstream.avail_out));
  170897. text_size += png_ptr->zbuf_size - png_ptr->zstream.avail_out;
  170898. *(text + text_size) = 0x00;
  170899. }
  170900. if (ret == Z_STREAM_END)
  170901. break;
  170902. else
  170903. {
  170904. png_ptr->zstream.next_out = png_ptr->zbuf;
  170905. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  170906. }
  170907. }
  170908. }
  170909. if (ret != Z_STREAM_END)
  170910. {
  170911. #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)
  170912. char umsg[52];
  170913. if (ret == Z_BUF_ERROR)
  170914. png_snprintf(umsg, 52,
  170915. "Buffer error in compressed datastream in %s chunk",
  170916. png_ptr->chunk_name);
  170917. else if (ret == Z_DATA_ERROR)
  170918. png_snprintf(umsg, 52,
  170919. "Data error in compressed datastream in %s chunk",
  170920. png_ptr->chunk_name);
  170921. else
  170922. png_snprintf(umsg, 52,
  170923. "Incomplete compressed datastream in %s chunk",
  170924. png_ptr->chunk_name);
  170925. png_warning(png_ptr, umsg);
  170926. #else
  170927. png_warning(png_ptr,
  170928. "Incomplete compressed datastream in chunk other than IDAT");
  170929. #endif
  170930. text_size=prefix_size;
  170931. if (text == NULL)
  170932. {
  170933. text = (png_charp)png_malloc_warn(png_ptr, text_size+1);
  170934. if (text == NULL)
  170935. {
  170936. png_free(png_ptr, chunkdata);
  170937. png_error(png_ptr,"Not enough memory for text.");
  170938. }
  170939. png_memcpy(text, chunkdata, prefix_size);
  170940. }
  170941. *(text + text_size) = 0x00;
  170942. }
  170943. inflateReset(&png_ptr->zstream);
  170944. png_ptr->zstream.avail_in = 0;
  170945. png_free(png_ptr, chunkdata);
  170946. chunkdata = text;
  170947. *newlength=text_size;
  170948. }
  170949. else /* if (comp_type != PNG_COMPRESSION_TYPE_BASE) */
  170950. {
  170951. #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)
  170952. char umsg[50];
  170953. png_snprintf(umsg, 50,
  170954. "Unknown zTXt compression type %d", comp_type);
  170955. png_warning(png_ptr, umsg);
  170956. #else
  170957. png_warning(png_ptr, "Unknown zTXt compression type");
  170958. #endif
  170959. *(chunkdata + prefix_size) = 0x00;
  170960. *newlength=prefix_size;
  170961. }
  170962. return chunkdata;
  170963. }
  170964. #endif
  170965. void /* PRIVATE */
  170966. png_handle_IHDR(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  170967. {
  170968. png_byte buf[13];
  170969. png_uint_32 width, height;
  170970. int bit_depth, color_type, compression_type, filter_type;
  170971. int interlace_type;
  170972. png_debug(1, "in png_handle_IHDR\n");
  170973. if (png_ptr->mode & PNG_HAVE_IHDR)
  170974. png_error(png_ptr, "Out of place IHDR");
  170975. if (length != 13)
  170976. png_error(png_ptr, "Invalid IHDR chunk");
  170977. png_ptr->mode |= PNG_HAVE_IHDR;
  170978. png_crc_read(png_ptr, buf, 13);
  170979. png_crc_finish(png_ptr, 0);
  170980. width = png_get_uint_31(png_ptr, buf);
  170981. height = png_get_uint_31(png_ptr, buf + 4);
  170982. bit_depth = buf[8];
  170983. color_type = buf[9];
  170984. compression_type = buf[10];
  170985. filter_type = buf[11];
  170986. interlace_type = buf[12];
  170987. png_ptr->width = width;
  170988. png_ptr->height = height;
  170989. png_ptr->bit_depth = (png_byte)bit_depth;
  170990. png_ptr->interlaced = (png_byte)interlace_type;
  170991. png_ptr->color_type = (png_byte)color_type;
  170992. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  170993. png_ptr->filter_type = (png_byte)filter_type;
  170994. #endif
  170995. png_ptr->compression_type = (png_byte)compression_type;
  170996. switch (png_ptr->color_type)
  170997. {
  170998. case PNG_COLOR_TYPE_GRAY:
  170999. case PNG_COLOR_TYPE_PALETTE:
  171000. png_ptr->channels = 1;
  171001. break;
  171002. case PNG_COLOR_TYPE_RGB:
  171003. png_ptr->channels = 3;
  171004. break;
  171005. case PNG_COLOR_TYPE_GRAY_ALPHA:
  171006. png_ptr->channels = 2;
  171007. break;
  171008. case PNG_COLOR_TYPE_RGB_ALPHA:
  171009. png_ptr->channels = 4;
  171010. break;
  171011. }
  171012. png_ptr->pixel_depth = (png_byte)(png_ptr->bit_depth *
  171013. png_ptr->channels);
  171014. png_ptr->rowbytes = PNG_ROWBYTES(png_ptr->pixel_depth,png_ptr->width);
  171015. png_debug1(3,"bit_depth = %d\n", png_ptr->bit_depth);
  171016. png_debug1(3,"channels = %d\n", png_ptr->channels);
  171017. png_debug1(3,"rowbytes = %lu\n", png_ptr->rowbytes);
  171018. png_set_IHDR(png_ptr, info_ptr, width, height, bit_depth,
  171019. color_type, interlace_type, compression_type, filter_type);
  171020. }
  171021. void /* PRIVATE */
  171022. png_handle_PLTE(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  171023. {
  171024. png_color palette[PNG_MAX_PALETTE_LENGTH];
  171025. int num, i;
  171026. #ifndef PNG_NO_POINTER_INDEXING
  171027. png_colorp pal_ptr;
  171028. #endif
  171029. png_debug(1, "in png_handle_PLTE\n");
  171030. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  171031. png_error(png_ptr, "Missing IHDR before PLTE");
  171032. else if (png_ptr->mode & PNG_HAVE_IDAT)
  171033. {
  171034. png_warning(png_ptr, "Invalid PLTE after IDAT");
  171035. png_crc_finish(png_ptr, length);
  171036. return;
  171037. }
  171038. else if (png_ptr->mode & PNG_HAVE_PLTE)
  171039. png_error(png_ptr, "Duplicate PLTE chunk");
  171040. png_ptr->mode |= PNG_HAVE_PLTE;
  171041. if (!(png_ptr->color_type&PNG_COLOR_MASK_COLOR))
  171042. {
  171043. png_warning(png_ptr,
  171044. "Ignoring PLTE chunk in grayscale PNG");
  171045. png_crc_finish(png_ptr, length);
  171046. return;
  171047. }
  171048. #if !defined(PNG_READ_OPT_PLTE_SUPPORTED)
  171049. if (png_ptr->color_type != PNG_COLOR_TYPE_PALETTE)
  171050. {
  171051. png_crc_finish(png_ptr, length);
  171052. return;
  171053. }
  171054. #endif
  171055. if (length > 3*PNG_MAX_PALETTE_LENGTH || length % 3)
  171056. {
  171057. if (png_ptr->color_type != PNG_COLOR_TYPE_PALETTE)
  171058. {
  171059. png_warning(png_ptr, "Invalid palette chunk");
  171060. png_crc_finish(png_ptr, length);
  171061. return;
  171062. }
  171063. else
  171064. {
  171065. png_error(png_ptr, "Invalid palette chunk");
  171066. }
  171067. }
  171068. num = (int)length / 3;
  171069. #ifndef PNG_NO_POINTER_INDEXING
  171070. for (i = 0, pal_ptr = palette; i < num; i++, pal_ptr++)
  171071. {
  171072. png_byte buf[3];
  171073. png_crc_read(png_ptr, buf, 3);
  171074. pal_ptr->red = buf[0];
  171075. pal_ptr->green = buf[1];
  171076. pal_ptr->blue = buf[2];
  171077. }
  171078. #else
  171079. for (i = 0; i < num; i++)
  171080. {
  171081. png_byte buf[3];
  171082. png_crc_read(png_ptr, buf, 3);
  171083. palette[i].red = buf[0];
  171084. palette[i].green = buf[1];
  171085. palette[i].blue = buf[2];
  171086. }
  171087. #endif
  171088. #if !defined(PNG_READ_OPT_PLTE_SUPPORTED)
  171089. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  171090. #endif
  171091. {
  171092. png_crc_finish(png_ptr, 0);
  171093. }
  171094. #if !defined(PNG_READ_OPT_PLTE_SUPPORTED)
  171095. else if (png_crc_error(png_ptr)) /* Only if we have a CRC error */
  171096. {
  171097. if (!(png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_USE))
  171098. {
  171099. if (png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_NOWARN)
  171100. {
  171101. png_chunk_error(png_ptr, "CRC error");
  171102. }
  171103. else
  171104. {
  171105. png_chunk_warning(png_ptr, "CRC error");
  171106. return;
  171107. }
  171108. }
  171109. else if (!(png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_NOWARN))
  171110. {
  171111. png_chunk_warning(png_ptr, "CRC error");
  171112. }
  171113. }
  171114. #endif
  171115. png_set_PLTE(png_ptr, info_ptr, palette, num);
  171116. #if defined(PNG_READ_tRNS_SUPPORTED)
  171117. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  171118. {
  171119. if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_tRNS))
  171120. {
  171121. if (png_ptr->num_trans > (png_uint_16)num)
  171122. {
  171123. png_warning(png_ptr, "Truncating incorrect tRNS chunk length");
  171124. png_ptr->num_trans = (png_uint_16)num;
  171125. }
  171126. if (info_ptr->num_trans > (png_uint_16)num)
  171127. {
  171128. png_warning(png_ptr, "Truncating incorrect info tRNS chunk length");
  171129. info_ptr->num_trans = (png_uint_16)num;
  171130. }
  171131. }
  171132. }
  171133. #endif
  171134. }
  171135. void /* PRIVATE */
  171136. png_handle_IEND(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  171137. {
  171138. png_debug(1, "in png_handle_IEND\n");
  171139. if (!(png_ptr->mode & PNG_HAVE_IHDR) || !(png_ptr->mode & PNG_HAVE_IDAT))
  171140. {
  171141. png_error(png_ptr, "No image in file");
  171142. }
  171143. png_ptr->mode |= (PNG_AFTER_IDAT | PNG_HAVE_IEND);
  171144. if (length != 0)
  171145. {
  171146. png_warning(png_ptr, "Incorrect IEND chunk length");
  171147. }
  171148. png_crc_finish(png_ptr, length);
  171149. info_ptr =info_ptr; /* quiet compiler warnings about unused info_ptr */
  171150. }
  171151. #if defined(PNG_READ_gAMA_SUPPORTED)
  171152. void /* PRIVATE */
  171153. png_handle_gAMA(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  171154. {
  171155. png_fixed_point igamma;
  171156. #ifdef PNG_FLOATING_POINT_SUPPORTED
  171157. float file_gamma;
  171158. #endif
  171159. png_byte buf[4];
  171160. png_debug(1, "in png_handle_gAMA\n");
  171161. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  171162. png_error(png_ptr, "Missing IHDR before gAMA");
  171163. else if (png_ptr->mode & PNG_HAVE_IDAT)
  171164. {
  171165. png_warning(png_ptr, "Invalid gAMA after IDAT");
  171166. png_crc_finish(png_ptr, length);
  171167. return;
  171168. }
  171169. else if (png_ptr->mode & PNG_HAVE_PLTE)
  171170. png_warning(png_ptr, "Out of place gAMA chunk");
  171171. if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_gAMA)
  171172. #if defined(PNG_READ_sRGB_SUPPORTED)
  171173. && !(info_ptr->valid & PNG_INFO_sRGB)
  171174. #endif
  171175. )
  171176. {
  171177. png_warning(png_ptr, "Duplicate gAMA chunk");
  171178. png_crc_finish(png_ptr, length);
  171179. return;
  171180. }
  171181. if (length != 4)
  171182. {
  171183. png_warning(png_ptr, "Incorrect gAMA chunk length");
  171184. png_crc_finish(png_ptr, length);
  171185. return;
  171186. }
  171187. png_crc_read(png_ptr, buf, 4);
  171188. if (png_crc_finish(png_ptr, 0))
  171189. return;
  171190. igamma = (png_fixed_point)png_get_uint_32(buf);
  171191. if (igamma == 0)
  171192. {
  171193. png_warning(png_ptr,
  171194. "Ignoring gAMA chunk with gamma=0");
  171195. return;
  171196. }
  171197. #if defined(PNG_READ_sRGB_SUPPORTED)
  171198. if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_sRGB))
  171199. if (PNG_OUT_OF_RANGE(igamma, 45500L, 500))
  171200. {
  171201. png_warning(png_ptr,
  171202. "Ignoring incorrect gAMA value when sRGB is also present");
  171203. #ifndef PNG_NO_CONSOLE_IO
  171204. fprintf(stderr, "gamma = (%d/100000)\n", (int)igamma);
  171205. #endif
  171206. return;
  171207. }
  171208. #endif /* PNG_READ_sRGB_SUPPORTED */
  171209. #ifdef PNG_FLOATING_POINT_SUPPORTED
  171210. file_gamma = (float)igamma / (float)100000.0;
  171211. # ifdef PNG_READ_GAMMA_SUPPORTED
  171212. png_ptr->gamma = file_gamma;
  171213. # endif
  171214. png_set_gAMA(png_ptr, info_ptr, file_gamma);
  171215. #endif
  171216. #ifdef PNG_FIXED_POINT_SUPPORTED
  171217. png_set_gAMA_fixed(png_ptr, info_ptr, igamma);
  171218. #endif
  171219. }
  171220. #endif
  171221. #if defined(PNG_READ_sBIT_SUPPORTED)
  171222. void /* PRIVATE */
  171223. png_handle_sBIT(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  171224. {
  171225. png_size_t truelen;
  171226. png_byte buf[4];
  171227. png_debug(1, "in png_handle_sBIT\n");
  171228. buf[0] = buf[1] = buf[2] = buf[3] = 0;
  171229. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  171230. png_error(png_ptr, "Missing IHDR before sBIT");
  171231. else if (png_ptr->mode & PNG_HAVE_IDAT)
  171232. {
  171233. png_warning(png_ptr, "Invalid sBIT after IDAT");
  171234. png_crc_finish(png_ptr, length);
  171235. return;
  171236. }
  171237. else if (png_ptr->mode & PNG_HAVE_PLTE)
  171238. {
  171239. png_warning(png_ptr, "Out of place sBIT chunk");
  171240. }
  171241. if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_sBIT))
  171242. {
  171243. png_warning(png_ptr, "Duplicate sBIT chunk");
  171244. png_crc_finish(png_ptr, length);
  171245. return;
  171246. }
  171247. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  171248. truelen = 3;
  171249. else
  171250. truelen = (png_size_t)png_ptr->channels;
  171251. if (length != truelen || length > 4)
  171252. {
  171253. png_warning(png_ptr, "Incorrect sBIT chunk length");
  171254. png_crc_finish(png_ptr, length);
  171255. return;
  171256. }
  171257. png_crc_read(png_ptr, buf, truelen);
  171258. if (png_crc_finish(png_ptr, 0))
  171259. return;
  171260. if (png_ptr->color_type & PNG_COLOR_MASK_COLOR)
  171261. {
  171262. png_ptr->sig_bit.red = buf[0];
  171263. png_ptr->sig_bit.green = buf[1];
  171264. png_ptr->sig_bit.blue = buf[2];
  171265. png_ptr->sig_bit.alpha = buf[3];
  171266. }
  171267. else
  171268. {
  171269. png_ptr->sig_bit.gray = buf[0];
  171270. png_ptr->sig_bit.red = buf[0];
  171271. png_ptr->sig_bit.green = buf[0];
  171272. png_ptr->sig_bit.blue = buf[0];
  171273. png_ptr->sig_bit.alpha = buf[1];
  171274. }
  171275. png_set_sBIT(png_ptr, info_ptr, &(png_ptr->sig_bit));
  171276. }
  171277. #endif
  171278. #if defined(PNG_READ_cHRM_SUPPORTED)
  171279. void /* PRIVATE */
  171280. png_handle_cHRM(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  171281. {
  171282. png_byte buf[4];
  171283. #ifdef PNG_FLOATING_POINT_SUPPORTED
  171284. float white_x, white_y, red_x, red_y, green_x, green_y, blue_x, blue_y;
  171285. #endif
  171286. png_fixed_point int_x_white, int_y_white, int_x_red, int_y_red, int_x_green,
  171287. int_y_green, int_x_blue, int_y_blue;
  171288. png_uint_32 uint_x, uint_y;
  171289. png_debug(1, "in png_handle_cHRM\n");
  171290. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  171291. png_error(png_ptr, "Missing IHDR before cHRM");
  171292. else if (png_ptr->mode & PNG_HAVE_IDAT)
  171293. {
  171294. png_warning(png_ptr, "Invalid cHRM after IDAT");
  171295. png_crc_finish(png_ptr, length);
  171296. return;
  171297. }
  171298. else if (png_ptr->mode & PNG_HAVE_PLTE)
  171299. png_warning(png_ptr, "Missing PLTE before cHRM");
  171300. if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_cHRM)
  171301. #if defined(PNG_READ_sRGB_SUPPORTED)
  171302. && !(info_ptr->valid & PNG_INFO_sRGB)
  171303. #endif
  171304. )
  171305. {
  171306. png_warning(png_ptr, "Duplicate cHRM chunk");
  171307. png_crc_finish(png_ptr, length);
  171308. return;
  171309. }
  171310. if (length != 32)
  171311. {
  171312. png_warning(png_ptr, "Incorrect cHRM chunk length");
  171313. png_crc_finish(png_ptr, length);
  171314. return;
  171315. }
  171316. png_crc_read(png_ptr, buf, 4);
  171317. uint_x = png_get_uint_32(buf);
  171318. png_crc_read(png_ptr, buf, 4);
  171319. uint_y = png_get_uint_32(buf);
  171320. if (uint_x > 80000L || uint_y > 80000L ||
  171321. uint_x + uint_y > 100000L)
  171322. {
  171323. png_warning(png_ptr, "Invalid cHRM white point");
  171324. png_crc_finish(png_ptr, 24);
  171325. return;
  171326. }
  171327. int_x_white = (png_fixed_point)uint_x;
  171328. int_y_white = (png_fixed_point)uint_y;
  171329. png_crc_read(png_ptr, buf, 4);
  171330. uint_x = png_get_uint_32(buf);
  171331. png_crc_read(png_ptr, buf, 4);
  171332. uint_y = png_get_uint_32(buf);
  171333. if (uint_x + uint_y > 100000L)
  171334. {
  171335. png_warning(png_ptr, "Invalid cHRM red point");
  171336. png_crc_finish(png_ptr, 16);
  171337. return;
  171338. }
  171339. int_x_red = (png_fixed_point)uint_x;
  171340. int_y_red = (png_fixed_point)uint_y;
  171341. png_crc_read(png_ptr, buf, 4);
  171342. uint_x = png_get_uint_32(buf);
  171343. png_crc_read(png_ptr, buf, 4);
  171344. uint_y = png_get_uint_32(buf);
  171345. if (uint_x + uint_y > 100000L)
  171346. {
  171347. png_warning(png_ptr, "Invalid cHRM green point");
  171348. png_crc_finish(png_ptr, 8);
  171349. return;
  171350. }
  171351. int_x_green = (png_fixed_point)uint_x;
  171352. int_y_green = (png_fixed_point)uint_y;
  171353. png_crc_read(png_ptr, buf, 4);
  171354. uint_x = png_get_uint_32(buf);
  171355. png_crc_read(png_ptr, buf, 4);
  171356. uint_y = png_get_uint_32(buf);
  171357. if (uint_x + uint_y > 100000L)
  171358. {
  171359. png_warning(png_ptr, "Invalid cHRM blue point");
  171360. png_crc_finish(png_ptr, 0);
  171361. return;
  171362. }
  171363. int_x_blue = (png_fixed_point)uint_x;
  171364. int_y_blue = (png_fixed_point)uint_y;
  171365. #ifdef PNG_FLOATING_POINT_SUPPORTED
  171366. white_x = (float)int_x_white / (float)100000.0;
  171367. white_y = (float)int_y_white / (float)100000.0;
  171368. red_x = (float)int_x_red / (float)100000.0;
  171369. red_y = (float)int_y_red / (float)100000.0;
  171370. green_x = (float)int_x_green / (float)100000.0;
  171371. green_y = (float)int_y_green / (float)100000.0;
  171372. blue_x = (float)int_x_blue / (float)100000.0;
  171373. blue_y = (float)int_y_blue / (float)100000.0;
  171374. #endif
  171375. #if defined(PNG_READ_sRGB_SUPPORTED)
  171376. if ((info_ptr != NULL) && (info_ptr->valid & PNG_INFO_sRGB))
  171377. {
  171378. if (PNG_OUT_OF_RANGE(int_x_white, 31270, 1000) ||
  171379. PNG_OUT_OF_RANGE(int_y_white, 32900, 1000) ||
  171380. PNG_OUT_OF_RANGE(int_x_red, 64000L, 1000) ||
  171381. PNG_OUT_OF_RANGE(int_y_red, 33000, 1000) ||
  171382. PNG_OUT_OF_RANGE(int_x_green, 30000, 1000) ||
  171383. PNG_OUT_OF_RANGE(int_y_green, 60000L, 1000) ||
  171384. PNG_OUT_OF_RANGE(int_x_blue, 15000, 1000) ||
  171385. PNG_OUT_OF_RANGE(int_y_blue, 6000, 1000))
  171386. {
  171387. png_warning(png_ptr,
  171388. "Ignoring incorrect cHRM value when sRGB is also present");
  171389. #ifndef PNG_NO_CONSOLE_IO
  171390. #ifdef PNG_FLOATING_POINT_SUPPORTED
  171391. fprintf(stderr,"wx=%f, wy=%f, rx=%f, ry=%f\n",
  171392. white_x, white_y, red_x, red_y);
  171393. fprintf(stderr,"gx=%f, gy=%f, bx=%f, by=%f\n",
  171394. green_x, green_y, blue_x, blue_y);
  171395. #else
  171396. fprintf(stderr,"wx=%ld, wy=%ld, rx=%ld, ry=%ld\n",
  171397. int_x_white, int_y_white, int_x_red, int_y_red);
  171398. fprintf(stderr,"gx=%ld, gy=%ld, bx=%ld, by=%ld\n",
  171399. int_x_green, int_y_green, int_x_blue, int_y_blue);
  171400. #endif
  171401. #endif /* PNG_NO_CONSOLE_IO */
  171402. }
  171403. png_crc_finish(png_ptr, 0);
  171404. return;
  171405. }
  171406. #endif /* PNG_READ_sRGB_SUPPORTED */
  171407. #ifdef PNG_FLOATING_POINT_SUPPORTED
  171408. png_set_cHRM(png_ptr, info_ptr,
  171409. white_x, white_y, red_x, red_y, green_x, green_y, blue_x, blue_y);
  171410. #endif
  171411. #ifdef PNG_FIXED_POINT_SUPPORTED
  171412. png_set_cHRM_fixed(png_ptr, info_ptr,
  171413. int_x_white, int_y_white, int_x_red, int_y_red, int_x_green,
  171414. int_y_green, int_x_blue, int_y_blue);
  171415. #endif
  171416. if (png_crc_finish(png_ptr, 0))
  171417. return;
  171418. }
  171419. #endif
  171420. #if defined(PNG_READ_sRGB_SUPPORTED)
  171421. void /* PRIVATE */
  171422. png_handle_sRGB(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  171423. {
  171424. int intent;
  171425. png_byte buf[1];
  171426. png_debug(1, "in png_handle_sRGB\n");
  171427. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  171428. png_error(png_ptr, "Missing IHDR before sRGB");
  171429. else if (png_ptr->mode & PNG_HAVE_IDAT)
  171430. {
  171431. png_warning(png_ptr, "Invalid sRGB after IDAT");
  171432. png_crc_finish(png_ptr, length);
  171433. return;
  171434. }
  171435. else if (png_ptr->mode & PNG_HAVE_PLTE)
  171436. png_warning(png_ptr, "Out of place sRGB chunk");
  171437. if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_sRGB))
  171438. {
  171439. png_warning(png_ptr, "Duplicate sRGB chunk");
  171440. png_crc_finish(png_ptr, length);
  171441. return;
  171442. }
  171443. if (length != 1)
  171444. {
  171445. png_warning(png_ptr, "Incorrect sRGB chunk length");
  171446. png_crc_finish(png_ptr, length);
  171447. return;
  171448. }
  171449. png_crc_read(png_ptr, buf, 1);
  171450. if (png_crc_finish(png_ptr, 0))
  171451. return;
  171452. intent = buf[0];
  171453. if (intent >= PNG_sRGB_INTENT_LAST)
  171454. {
  171455. png_warning(png_ptr, "Unknown sRGB intent");
  171456. return;
  171457. }
  171458. #if defined(PNG_READ_gAMA_SUPPORTED) && defined(PNG_READ_GAMMA_SUPPORTED)
  171459. if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_gAMA))
  171460. {
  171461. png_fixed_point igamma;
  171462. #ifdef PNG_FIXED_POINT_SUPPORTED
  171463. igamma=info_ptr->int_gamma;
  171464. #else
  171465. # ifdef PNG_FLOATING_POINT_SUPPORTED
  171466. igamma=(png_fixed_point)(info_ptr->gamma * 100000.);
  171467. # endif
  171468. #endif
  171469. if (PNG_OUT_OF_RANGE(igamma, 45500L, 500))
  171470. {
  171471. png_warning(png_ptr,
  171472. "Ignoring incorrect gAMA value when sRGB is also present");
  171473. #ifndef PNG_NO_CONSOLE_IO
  171474. # ifdef PNG_FIXED_POINT_SUPPORTED
  171475. fprintf(stderr,"incorrect gamma=(%d/100000)\n",(int)png_ptr->int_gamma);
  171476. # else
  171477. # ifdef PNG_FLOATING_POINT_SUPPORTED
  171478. fprintf(stderr,"incorrect gamma=%f\n",png_ptr->gamma);
  171479. # endif
  171480. # endif
  171481. #endif
  171482. }
  171483. }
  171484. #endif /* PNG_READ_gAMA_SUPPORTED */
  171485. #ifdef PNG_READ_cHRM_SUPPORTED
  171486. #ifdef PNG_FIXED_POINT_SUPPORTED
  171487. if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_cHRM))
  171488. if (PNG_OUT_OF_RANGE(info_ptr->int_x_white, 31270, 1000) ||
  171489. PNG_OUT_OF_RANGE(info_ptr->int_y_white, 32900, 1000) ||
  171490. PNG_OUT_OF_RANGE(info_ptr->int_x_red, 64000L, 1000) ||
  171491. PNG_OUT_OF_RANGE(info_ptr->int_y_red, 33000, 1000) ||
  171492. PNG_OUT_OF_RANGE(info_ptr->int_x_green, 30000, 1000) ||
  171493. PNG_OUT_OF_RANGE(info_ptr->int_y_green, 60000L, 1000) ||
  171494. PNG_OUT_OF_RANGE(info_ptr->int_x_blue, 15000, 1000) ||
  171495. PNG_OUT_OF_RANGE(info_ptr->int_y_blue, 6000, 1000))
  171496. {
  171497. png_warning(png_ptr,
  171498. "Ignoring incorrect cHRM value when sRGB is also present");
  171499. }
  171500. #endif /* PNG_FIXED_POINT_SUPPORTED */
  171501. #endif /* PNG_READ_cHRM_SUPPORTED */
  171502. png_set_sRGB_gAMA_and_cHRM(png_ptr, info_ptr, intent);
  171503. }
  171504. #endif /* PNG_READ_sRGB_SUPPORTED */
  171505. #if defined(PNG_READ_iCCP_SUPPORTED)
  171506. void /* PRIVATE */
  171507. png_handle_iCCP(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  171508. {
  171509. png_charp chunkdata;
  171510. png_byte compression_type;
  171511. png_bytep pC;
  171512. png_charp profile;
  171513. png_uint_32 skip = 0;
  171514. png_uint_32 profile_size, profile_length;
  171515. png_size_t slength, prefix_length, data_length;
  171516. png_debug(1, "in png_handle_iCCP\n");
  171517. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  171518. png_error(png_ptr, "Missing IHDR before iCCP");
  171519. else if (png_ptr->mode & PNG_HAVE_IDAT)
  171520. {
  171521. png_warning(png_ptr, "Invalid iCCP after IDAT");
  171522. png_crc_finish(png_ptr, length);
  171523. return;
  171524. }
  171525. else if (png_ptr->mode & PNG_HAVE_PLTE)
  171526. png_warning(png_ptr, "Out of place iCCP chunk");
  171527. if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_iCCP))
  171528. {
  171529. png_warning(png_ptr, "Duplicate iCCP chunk");
  171530. png_crc_finish(png_ptr, length);
  171531. return;
  171532. }
  171533. #ifdef PNG_MAX_MALLOC_64K
  171534. if (length > (png_uint_32)65535L)
  171535. {
  171536. png_warning(png_ptr, "iCCP chunk too large to fit in memory");
  171537. skip = length - (png_uint_32)65535L;
  171538. length = (png_uint_32)65535L;
  171539. }
  171540. #endif
  171541. chunkdata = (png_charp)png_malloc(png_ptr, length + 1);
  171542. slength = (png_size_t)length;
  171543. png_crc_read(png_ptr, (png_bytep)chunkdata, slength);
  171544. if (png_crc_finish(png_ptr, skip))
  171545. {
  171546. png_free(png_ptr, chunkdata);
  171547. return;
  171548. }
  171549. chunkdata[slength] = 0x00;
  171550. for (profile = chunkdata; *profile; profile++)
  171551. ;
  171552. ++profile;
  171553. if ( profile >= chunkdata + slength - 1)
  171554. {
  171555. png_free(png_ptr, chunkdata);
  171556. png_warning(png_ptr, "Malformed iCCP chunk");
  171557. return;
  171558. }
  171559. compression_type = *profile++;
  171560. if (compression_type)
  171561. {
  171562. png_warning(png_ptr, "Ignoring nonzero compression type in iCCP chunk");
  171563. compression_type=0x00; /* Reset it to zero (libpng-1.0.6 through 1.0.8
  171564. wrote nonzero) */
  171565. }
  171566. prefix_length = profile - chunkdata;
  171567. chunkdata = png_decompress_chunk(png_ptr, compression_type, chunkdata,
  171568. slength, prefix_length, &data_length);
  171569. profile_length = data_length - prefix_length;
  171570. if ( prefix_length > data_length || profile_length < 4)
  171571. {
  171572. png_free(png_ptr, chunkdata);
  171573. png_warning(png_ptr, "Profile size field missing from iCCP chunk");
  171574. return;
  171575. }
  171576. pC = (png_bytep)(chunkdata+prefix_length);
  171577. profile_size = ((*(pC ))<<24) |
  171578. ((*(pC+1))<<16) |
  171579. ((*(pC+2))<< 8) |
  171580. ((*(pC+3)) );
  171581. if(profile_size < profile_length)
  171582. profile_length = profile_size;
  171583. if(profile_size > profile_length)
  171584. {
  171585. png_free(png_ptr, chunkdata);
  171586. png_warning(png_ptr, "Ignoring truncated iCCP profile.");
  171587. return;
  171588. }
  171589. png_set_iCCP(png_ptr, info_ptr, chunkdata, compression_type,
  171590. chunkdata + prefix_length, profile_length);
  171591. png_free(png_ptr, chunkdata);
  171592. }
  171593. #endif /* PNG_READ_iCCP_SUPPORTED */
  171594. #if defined(PNG_READ_sPLT_SUPPORTED)
  171595. void /* PRIVATE */
  171596. png_handle_sPLT(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  171597. {
  171598. png_bytep chunkdata;
  171599. png_bytep entry_start;
  171600. png_sPLT_t new_palette;
  171601. #ifdef PNG_NO_POINTER_INDEXING
  171602. png_sPLT_entryp pp;
  171603. #endif
  171604. int data_length, entry_size, i;
  171605. png_uint_32 skip = 0;
  171606. png_size_t slength;
  171607. png_debug(1, "in png_handle_sPLT\n");
  171608. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  171609. png_error(png_ptr, "Missing IHDR before sPLT");
  171610. else if (png_ptr->mode & PNG_HAVE_IDAT)
  171611. {
  171612. png_warning(png_ptr, "Invalid sPLT after IDAT");
  171613. png_crc_finish(png_ptr, length);
  171614. return;
  171615. }
  171616. #ifdef PNG_MAX_MALLOC_64K
  171617. if (length > (png_uint_32)65535L)
  171618. {
  171619. png_warning(png_ptr, "sPLT chunk too large to fit in memory");
  171620. skip = length - (png_uint_32)65535L;
  171621. length = (png_uint_32)65535L;
  171622. }
  171623. #endif
  171624. chunkdata = (png_bytep)png_malloc(png_ptr, length + 1);
  171625. slength = (png_size_t)length;
  171626. png_crc_read(png_ptr, (png_bytep)chunkdata, slength);
  171627. if (png_crc_finish(png_ptr, skip))
  171628. {
  171629. png_free(png_ptr, chunkdata);
  171630. return;
  171631. }
  171632. chunkdata[slength] = 0x00;
  171633. for (entry_start = chunkdata; *entry_start; entry_start++)
  171634. ;
  171635. ++entry_start;
  171636. if (entry_start > chunkdata + slength - 2)
  171637. {
  171638. png_free(png_ptr, chunkdata);
  171639. png_warning(png_ptr, "malformed sPLT chunk");
  171640. return;
  171641. }
  171642. new_palette.depth = *entry_start++;
  171643. entry_size = (new_palette.depth == 8 ? 6 : 10);
  171644. data_length = (slength - (entry_start - chunkdata));
  171645. if (data_length % entry_size)
  171646. {
  171647. png_free(png_ptr, chunkdata);
  171648. png_warning(png_ptr, "sPLT chunk has bad length");
  171649. return;
  171650. }
  171651. new_palette.nentries = (png_int_32) ( data_length / entry_size);
  171652. if ((png_uint_32) new_palette.nentries > (png_uint_32) (PNG_SIZE_MAX /
  171653. png_sizeof(png_sPLT_entry)))
  171654. {
  171655. png_warning(png_ptr, "sPLT chunk too long");
  171656. return;
  171657. }
  171658. new_palette.entries = (png_sPLT_entryp)png_malloc_warn(
  171659. png_ptr, new_palette.nentries * png_sizeof(png_sPLT_entry));
  171660. if (new_palette.entries == NULL)
  171661. {
  171662. png_warning(png_ptr, "sPLT chunk requires too much memory");
  171663. return;
  171664. }
  171665. #ifndef PNG_NO_POINTER_INDEXING
  171666. for (i = 0; i < new_palette.nentries; i++)
  171667. {
  171668. png_sPLT_entryp pp = new_palette.entries + i;
  171669. if (new_palette.depth == 8)
  171670. {
  171671. pp->red = *entry_start++;
  171672. pp->green = *entry_start++;
  171673. pp->blue = *entry_start++;
  171674. pp->alpha = *entry_start++;
  171675. }
  171676. else
  171677. {
  171678. pp->red = png_get_uint_16(entry_start); entry_start += 2;
  171679. pp->green = png_get_uint_16(entry_start); entry_start += 2;
  171680. pp->blue = png_get_uint_16(entry_start); entry_start += 2;
  171681. pp->alpha = png_get_uint_16(entry_start); entry_start += 2;
  171682. }
  171683. pp->frequency = png_get_uint_16(entry_start); entry_start += 2;
  171684. }
  171685. #else
  171686. pp = new_palette.entries;
  171687. for (i = 0; i < new_palette.nentries; i++)
  171688. {
  171689. if (new_palette.depth == 8)
  171690. {
  171691. pp[i].red = *entry_start++;
  171692. pp[i].green = *entry_start++;
  171693. pp[i].blue = *entry_start++;
  171694. pp[i].alpha = *entry_start++;
  171695. }
  171696. else
  171697. {
  171698. pp[i].red = png_get_uint_16(entry_start); entry_start += 2;
  171699. pp[i].green = png_get_uint_16(entry_start); entry_start += 2;
  171700. pp[i].blue = png_get_uint_16(entry_start); entry_start += 2;
  171701. pp[i].alpha = png_get_uint_16(entry_start); entry_start += 2;
  171702. }
  171703. pp->frequency = png_get_uint_16(entry_start); entry_start += 2;
  171704. }
  171705. #endif
  171706. new_palette.name = (png_charp)chunkdata;
  171707. png_set_sPLT(png_ptr, info_ptr, &new_palette, 1);
  171708. png_free(png_ptr, chunkdata);
  171709. png_free(png_ptr, new_palette.entries);
  171710. }
  171711. #endif /* PNG_READ_sPLT_SUPPORTED */
  171712. #if defined(PNG_READ_tRNS_SUPPORTED)
  171713. void /* PRIVATE */
  171714. png_handle_tRNS(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  171715. {
  171716. png_byte readbuf[PNG_MAX_PALETTE_LENGTH];
  171717. int bit_mask;
  171718. png_debug(1, "in png_handle_tRNS\n");
  171719. bit_mask = (1 << png_ptr->bit_depth) - 1;
  171720. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  171721. png_error(png_ptr, "Missing IHDR before tRNS");
  171722. else if (png_ptr->mode & PNG_HAVE_IDAT)
  171723. {
  171724. png_warning(png_ptr, "Invalid tRNS after IDAT");
  171725. png_crc_finish(png_ptr, length);
  171726. return;
  171727. }
  171728. else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_tRNS))
  171729. {
  171730. png_warning(png_ptr, "Duplicate tRNS chunk");
  171731. png_crc_finish(png_ptr, length);
  171732. return;
  171733. }
  171734. if (png_ptr->color_type == PNG_COLOR_TYPE_GRAY)
  171735. {
  171736. png_byte buf[2];
  171737. if (length != 2)
  171738. {
  171739. png_warning(png_ptr, "Incorrect tRNS chunk length");
  171740. png_crc_finish(png_ptr, length);
  171741. return;
  171742. }
  171743. png_crc_read(png_ptr, buf, 2);
  171744. png_ptr->num_trans = 1;
  171745. png_ptr->trans_values.gray = png_get_uint_16(buf) & bit_mask;
  171746. }
  171747. else if (png_ptr->color_type == PNG_COLOR_TYPE_RGB)
  171748. {
  171749. png_byte buf[6];
  171750. if (length != 6)
  171751. {
  171752. png_warning(png_ptr, "Incorrect tRNS chunk length");
  171753. png_crc_finish(png_ptr, length);
  171754. return;
  171755. }
  171756. png_crc_read(png_ptr, buf, (png_size_t)length);
  171757. png_ptr->num_trans = 1;
  171758. png_ptr->trans_values.red = png_get_uint_16(buf) & bit_mask;
  171759. png_ptr->trans_values.green = png_get_uint_16(buf + 2) & bit_mask;
  171760. png_ptr->trans_values.blue = png_get_uint_16(buf + 4) & bit_mask;
  171761. }
  171762. else if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  171763. {
  171764. if (!(png_ptr->mode & PNG_HAVE_PLTE))
  171765. {
  171766. png_warning(png_ptr, "Missing PLTE before tRNS");
  171767. }
  171768. if (length > (png_uint_32)png_ptr->num_palette ||
  171769. length > PNG_MAX_PALETTE_LENGTH)
  171770. {
  171771. png_warning(png_ptr, "Incorrect tRNS chunk length");
  171772. png_crc_finish(png_ptr, length);
  171773. return;
  171774. }
  171775. if (length == 0)
  171776. {
  171777. png_warning(png_ptr, "Zero length tRNS chunk");
  171778. png_crc_finish(png_ptr, length);
  171779. return;
  171780. }
  171781. png_crc_read(png_ptr, readbuf, (png_size_t)length);
  171782. png_ptr->num_trans = (png_uint_16)length;
  171783. }
  171784. else
  171785. {
  171786. png_warning(png_ptr, "tRNS chunk not allowed with alpha channel");
  171787. png_crc_finish(png_ptr, length);
  171788. return;
  171789. }
  171790. if (png_crc_finish(png_ptr, 0))
  171791. {
  171792. png_ptr->num_trans = 0;
  171793. return;
  171794. }
  171795. png_set_tRNS(png_ptr, info_ptr, readbuf, png_ptr->num_trans,
  171796. &(png_ptr->trans_values));
  171797. }
  171798. #endif
  171799. #if defined(PNG_READ_bKGD_SUPPORTED)
  171800. void /* PRIVATE */
  171801. png_handle_bKGD(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  171802. {
  171803. png_size_t truelen;
  171804. png_byte buf[6];
  171805. png_debug(1, "in png_handle_bKGD\n");
  171806. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  171807. png_error(png_ptr, "Missing IHDR before bKGD");
  171808. else if (png_ptr->mode & PNG_HAVE_IDAT)
  171809. {
  171810. png_warning(png_ptr, "Invalid bKGD after IDAT");
  171811. png_crc_finish(png_ptr, length);
  171812. return;
  171813. }
  171814. else if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE &&
  171815. !(png_ptr->mode & PNG_HAVE_PLTE))
  171816. {
  171817. png_warning(png_ptr, "Missing PLTE before bKGD");
  171818. png_crc_finish(png_ptr, length);
  171819. return;
  171820. }
  171821. else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_bKGD))
  171822. {
  171823. png_warning(png_ptr, "Duplicate bKGD chunk");
  171824. png_crc_finish(png_ptr, length);
  171825. return;
  171826. }
  171827. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  171828. truelen = 1;
  171829. else if (png_ptr->color_type & PNG_COLOR_MASK_COLOR)
  171830. truelen = 6;
  171831. else
  171832. truelen = 2;
  171833. if (length != truelen)
  171834. {
  171835. png_warning(png_ptr, "Incorrect bKGD chunk length");
  171836. png_crc_finish(png_ptr, length);
  171837. return;
  171838. }
  171839. png_crc_read(png_ptr, buf, truelen);
  171840. if (png_crc_finish(png_ptr, 0))
  171841. return;
  171842. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  171843. {
  171844. png_ptr->background.index = buf[0];
  171845. if(info_ptr->num_palette)
  171846. {
  171847. if(buf[0] > info_ptr->num_palette)
  171848. {
  171849. png_warning(png_ptr, "Incorrect bKGD chunk index value");
  171850. return;
  171851. }
  171852. png_ptr->background.red =
  171853. (png_uint_16)png_ptr->palette[buf[0]].red;
  171854. png_ptr->background.green =
  171855. (png_uint_16)png_ptr->palette[buf[0]].green;
  171856. png_ptr->background.blue =
  171857. (png_uint_16)png_ptr->palette[buf[0]].blue;
  171858. }
  171859. }
  171860. else if (!(png_ptr->color_type & PNG_COLOR_MASK_COLOR)) /* GRAY */
  171861. {
  171862. png_ptr->background.red =
  171863. png_ptr->background.green =
  171864. png_ptr->background.blue =
  171865. png_ptr->background.gray = png_get_uint_16(buf);
  171866. }
  171867. else
  171868. {
  171869. png_ptr->background.red = png_get_uint_16(buf);
  171870. png_ptr->background.green = png_get_uint_16(buf + 2);
  171871. png_ptr->background.blue = png_get_uint_16(buf + 4);
  171872. }
  171873. png_set_bKGD(png_ptr, info_ptr, &(png_ptr->background));
  171874. }
  171875. #endif
  171876. #if defined(PNG_READ_hIST_SUPPORTED)
  171877. void /* PRIVATE */
  171878. png_handle_hIST(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  171879. {
  171880. unsigned int num, i;
  171881. png_uint_16 readbuf[PNG_MAX_PALETTE_LENGTH];
  171882. png_debug(1, "in png_handle_hIST\n");
  171883. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  171884. png_error(png_ptr, "Missing IHDR before hIST");
  171885. else if (png_ptr->mode & PNG_HAVE_IDAT)
  171886. {
  171887. png_warning(png_ptr, "Invalid hIST after IDAT");
  171888. png_crc_finish(png_ptr, length);
  171889. return;
  171890. }
  171891. else if (!(png_ptr->mode & PNG_HAVE_PLTE))
  171892. {
  171893. png_warning(png_ptr, "Missing PLTE before hIST");
  171894. png_crc_finish(png_ptr, length);
  171895. return;
  171896. }
  171897. else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_hIST))
  171898. {
  171899. png_warning(png_ptr, "Duplicate hIST chunk");
  171900. png_crc_finish(png_ptr, length);
  171901. return;
  171902. }
  171903. num = length / 2 ;
  171904. if (num != (unsigned int) png_ptr->num_palette || num >
  171905. (unsigned int) PNG_MAX_PALETTE_LENGTH)
  171906. {
  171907. png_warning(png_ptr, "Incorrect hIST chunk length");
  171908. png_crc_finish(png_ptr, length);
  171909. return;
  171910. }
  171911. for (i = 0; i < num; i++)
  171912. {
  171913. png_byte buf[2];
  171914. png_crc_read(png_ptr, buf, 2);
  171915. readbuf[i] = png_get_uint_16(buf);
  171916. }
  171917. if (png_crc_finish(png_ptr, 0))
  171918. return;
  171919. png_set_hIST(png_ptr, info_ptr, readbuf);
  171920. }
  171921. #endif
  171922. #if defined(PNG_READ_pHYs_SUPPORTED)
  171923. void /* PRIVATE */
  171924. png_handle_pHYs(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  171925. {
  171926. png_byte buf[9];
  171927. png_uint_32 res_x, res_y;
  171928. int unit_type;
  171929. png_debug(1, "in png_handle_pHYs\n");
  171930. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  171931. png_error(png_ptr, "Missing IHDR before pHYs");
  171932. else if (png_ptr->mode & PNG_HAVE_IDAT)
  171933. {
  171934. png_warning(png_ptr, "Invalid pHYs after IDAT");
  171935. png_crc_finish(png_ptr, length);
  171936. return;
  171937. }
  171938. else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs))
  171939. {
  171940. png_warning(png_ptr, "Duplicate pHYs chunk");
  171941. png_crc_finish(png_ptr, length);
  171942. return;
  171943. }
  171944. if (length != 9)
  171945. {
  171946. png_warning(png_ptr, "Incorrect pHYs chunk length");
  171947. png_crc_finish(png_ptr, length);
  171948. return;
  171949. }
  171950. png_crc_read(png_ptr, buf, 9);
  171951. if (png_crc_finish(png_ptr, 0))
  171952. return;
  171953. res_x = png_get_uint_32(buf);
  171954. res_y = png_get_uint_32(buf + 4);
  171955. unit_type = buf[8];
  171956. png_set_pHYs(png_ptr, info_ptr, res_x, res_y, unit_type);
  171957. }
  171958. #endif
  171959. #if defined(PNG_READ_oFFs_SUPPORTED)
  171960. void /* PRIVATE */
  171961. png_handle_oFFs(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  171962. {
  171963. png_byte buf[9];
  171964. png_int_32 offset_x, offset_y;
  171965. int unit_type;
  171966. png_debug(1, "in png_handle_oFFs\n");
  171967. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  171968. png_error(png_ptr, "Missing IHDR before oFFs");
  171969. else if (png_ptr->mode & PNG_HAVE_IDAT)
  171970. {
  171971. png_warning(png_ptr, "Invalid oFFs after IDAT");
  171972. png_crc_finish(png_ptr, length);
  171973. return;
  171974. }
  171975. else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_oFFs))
  171976. {
  171977. png_warning(png_ptr, "Duplicate oFFs chunk");
  171978. png_crc_finish(png_ptr, length);
  171979. return;
  171980. }
  171981. if (length != 9)
  171982. {
  171983. png_warning(png_ptr, "Incorrect oFFs chunk length");
  171984. png_crc_finish(png_ptr, length);
  171985. return;
  171986. }
  171987. png_crc_read(png_ptr, buf, 9);
  171988. if (png_crc_finish(png_ptr, 0))
  171989. return;
  171990. offset_x = png_get_int_32(buf);
  171991. offset_y = png_get_int_32(buf + 4);
  171992. unit_type = buf[8];
  171993. png_set_oFFs(png_ptr, info_ptr, offset_x, offset_y, unit_type);
  171994. }
  171995. #endif
  171996. #if defined(PNG_READ_pCAL_SUPPORTED)
  171997. void /* PRIVATE */
  171998. png_handle_pCAL(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  171999. {
  172000. png_charp purpose;
  172001. png_int_32 X0, X1;
  172002. png_byte type, nparams;
  172003. png_charp buf, units, endptr;
  172004. png_charpp params;
  172005. png_size_t slength;
  172006. int i;
  172007. png_debug(1, "in png_handle_pCAL\n");
  172008. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  172009. png_error(png_ptr, "Missing IHDR before pCAL");
  172010. else if (png_ptr->mode & PNG_HAVE_IDAT)
  172011. {
  172012. png_warning(png_ptr, "Invalid pCAL after IDAT");
  172013. png_crc_finish(png_ptr, length);
  172014. return;
  172015. }
  172016. else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_pCAL))
  172017. {
  172018. png_warning(png_ptr, "Duplicate pCAL chunk");
  172019. png_crc_finish(png_ptr, length);
  172020. return;
  172021. }
  172022. png_debug1(2, "Allocating and reading pCAL chunk data (%lu bytes)\n",
  172023. length + 1);
  172024. purpose = (png_charp)png_malloc_warn(png_ptr, length + 1);
  172025. if (purpose == NULL)
  172026. {
  172027. png_warning(png_ptr, "No memory for pCAL purpose.");
  172028. return;
  172029. }
  172030. slength = (png_size_t)length;
  172031. png_crc_read(png_ptr, (png_bytep)purpose, slength);
  172032. if (png_crc_finish(png_ptr, 0))
  172033. {
  172034. png_free(png_ptr, purpose);
  172035. return;
  172036. }
  172037. purpose[slength] = 0x00; /* null terminate the last string */
  172038. png_debug(3, "Finding end of pCAL purpose string\n");
  172039. for (buf = purpose; *buf; buf++)
  172040. ;
  172041. endptr = purpose + slength;
  172042. if (endptr <= buf + 12)
  172043. {
  172044. png_warning(png_ptr, "Invalid pCAL data");
  172045. png_free(png_ptr, purpose);
  172046. return;
  172047. }
  172048. png_debug(3, "Reading pCAL X0, X1, type, nparams, and units\n");
  172049. X0 = png_get_int_32((png_bytep)buf+1);
  172050. X1 = png_get_int_32((png_bytep)buf+5);
  172051. type = buf[9];
  172052. nparams = buf[10];
  172053. units = buf + 11;
  172054. png_debug(3, "Checking pCAL equation type and number of parameters\n");
  172055. if ((type == PNG_EQUATION_LINEAR && nparams != 2) ||
  172056. (type == PNG_EQUATION_BASE_E && nparams != 3) ||
  172057. (type == PNG_EQUATION_ARBITRARY && nparams != 3) ||
  172058. (type == PNG_EQUATION_HYPERBOLIC && nparams != 4))
  172059. {
  172060. png_warning(png_ptr, "Invalid pCAL parameters for equation type");
  172061. png_free(png_ptr, purpose);
  172062. return;
  172063. }
  172064. else if (type >= PNG_EQUATION_LAST)
  172065. {
  172066. png_warning(png_ptr, "Unrecognized equation type for pCAL chunk");
  172067. }
  172068. for (buf = units; *buf; buf++)
  172069. ;
  172070. png_debug(3, "Allocating pCAL parameters array\n");
  172071. params = (png_charpp)png_malloc_warn(png_ptr, (png_uint_32)(nparams
  172072. *png_sizeof(png_charp))) ;
  172073. if (params == NULL)
  172074. {
  172075. png_free(png_ptr, purpose);
  172076. png_warning(png_ptr, "No memory for pCAL params.");
  172077. return;
  172078. }
  172079. for (i = 0; i < (int)nparams; i++)
  172080. {
  172081. buf++; /* Skip the null string terminator from previous parameter. */
  172082. png_debug1(3, "Reading pCAL parameter %d\n", i);
  172083. for (params[i] = buf; buf <= endptr && *buf != 0x00; buf++)
  172084. ;
  172085. if (buf > endptr)
  172086. {
  172087. png_warning(png_ptr, "Invalid pCAL data");
  172088. png_free(png_ptr, purpose);
  172089. png_free(png_ptr, params);
  172090. return;
  172091. }
  172092. }
  172093. png_set_pCAL(png_ptr, info_ptr, purpose, X0, X1, type, nparams,
  172094. units, params);
  172095. png_free(png_ptr, purpose);
  172096. png_free(png_ptr, params);
  172097. }
  172098. #endif
  172099. #if defined(PNG_READ_sCAL_SUPPORTED)
  172100. void /* PRIVATE */
  172101. png_handle_sCAL(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  172102. {
  172103. png_charp buffer, ep;
  172104. #ifdef PNG_FLOATING_POINT_SUPPORTED
  172105. double width, height;
  172106. png_charp vp;
  172107. #else
  172108. #ifdef PNG_FIXED_POINT_SUPPORTED
  172109. png_charp swidth, sheight;
  172110. #endif
  172111. #endif
  172112. png_size_t slength;
  172113. png_debug(1, "in png_handle_sCAL\n");
  172114. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  172115. png_error(png_ptr, "Missing IHDR before sCAL");
  172116. else if (png_ptr->mode & PNG_HAVE_IDAT)
  172117. {
  172118. png_warning(png_ptr, "Invalid sCAL after IDAT");
  172119. png_crc_finish(png_ptr, length);
  172120. return;
  172121. }
  172122. else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_sCAL))
  172123. {
  172124. png_warning(png_ptr, "Duplicate sCAL chunk");
  172125. png_crc_finish(png_ptr, length);
  172126. return;
  172127. }
  172128. png_debug1(2, "Allocating and reading sCAL chunk data (%lu bytes)\n",
  172129. length + 1);
  172130. buffer = (png_charp)png_malloc_warn(png_ptr, length + 1);
  172131. if (buffer == NULL)
  172132. {
  172133. png_warning(png_ptr, "Out of memory while processing sCAL chunk");
  172134. return;
  172135. }
  172136. slength = (png_size_t)length;
  172137. png_crc_read(png_ptr, (png_bytep)buffer, slength);
  172138. if (png_crc_finish(png_ptr, 0))
  172139. {
  172140. png_free(png_ptr, buffer);
  172141. return;
  172142. }
  172143. buffer[slength] = 0x00; /* null terminate the last string */
  172144. ep = buffer + 1; /* skip unit byte */
  172145. #ifdef PNG_FLOATING_POINT_SUPPORTED
  172146. width = png_strtod(png_ptr, ep, &vp);
  172147. if (*vp)
  172148. {
  172149. png_warning(png_ptr, "malformed width string in sCAL chunk");
  172150. return;
  172151. }
  172152. #else
  172153. #ifdef PNG_FIXED_POINT_SUPPORTED
  172154. swidth = (png_charp)png_malloc_warn(png_ptr, png_strlen(ep) + 1);
  172155. if (swidth == NULL)
  172156. {
  172157. png_warning(png_ptr, "Out of memory while processing sCAL chunk width");
  172158. return;
  172159. }
  172160. png_memcpy(swidth, ep, (png_size_t)png_strlen(ep));
  172161. #endif
  172162. #endif
  172163. for (ep = buffer; *ep; ep++)
  172164. ;
  172165. ep++;
  172166. if (buffer + slength < ep)
  172167. {
  172168. png_warning(png_ptr, "Truncated sCAL chunk");
  172169. #if defined(PNG_FIXED_POINT_SUPPORTED) && \
  172170. !defined(PNG_FLOATING_POINT_SUPPORTED)
  172171. png_free(png_ptr, swidth);
  172172. #endif
  172173. png_free(png_ptr, buffer);
  172174. return;
  172175. }
  172176. #ifdef PNG_FLOATING_POINT_SUPPORTED
  172177. height = png_strtod(png_ptr, ep, &vp);
  172178. if (*vp)
  172179. {
  172180. png_warning(png_ptr, "malformed height string in sCAL chunk");
  172181. return;
  172182. }
  172183. #else
  172184. #ifdef PNG_FIXED_POINT_SUPPORTED
  172185. sheight = (png_charp)png_malloc_warn(png_ptr, png_strlen(ep) + 1);
  172186. if (swidth == NULL)
  172187. {
  172188. png_warning(png_ptr, "Out of memory while processing sCAL chunk height");
  172189. return;
  172190. }
  172191. png_memcpy(sheight, ep, (png_size_t)png_strlen(ep));
  172192. #endif
  172193. #endif
  172194. if (buffer + slength < ep
  172195. #ifdef PNG_FLOATING_POINT_SUPPORTED
  172196. || width <= 0. || height <= 0.
  172197. #endif
  172198. )
  172199. {
  172200. png_warning(png_ptr, "Invalid sCAL data");
  172201. png_free(png_ptr, buffer);
  172202. #if defined(PNG_FIXED_POINT_SUPPORTED) && !defined(PNG_FLOATING_POINT_SUPPORTED)
  172203. png_free(png_ptr, swidth);
  172204. png_free(png_ptr, sheight);
  172205. #endif
  172206. return;
  172207. }
  172208. #ifdef PNG_FLOATING_POINT_SUPPORTED
  172209. png_set_sCAL(png_ptr, info_ptr, buffer[0], width, height);
  172210. #else
  172211. #ifdef PNG_FIXED_POINT_SUPPORTED
  172212. png_set_sCAL_s(png_ptr, info_ptr, buffer[0], swidth, sheight);
  172213. #endif
  172214. #endif
  172215. png_free(png_ptr, buffer);
  172216. #if defined(PNG_FIXED_POINT_SUPPORTED) && !defined(PNG_FLOATING_POINT_SUPPORTED)
  172217. png_free(png_ptr, swidth);
  172218. png_free(png_ptr, sheight);
  172219. #endif
  172220. }
  172221. #endif
  172222. #if defined(PNG_READ_tIME_SUPPORTED)
  172223. void /* PRIVATE */
  172224. png_handle_tIME(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  172225. {
  172226. png_byte buf[7];
  172227. png_time mod_time;
  172228. png_debug(1, "in png_handle_tIME\n");
  172229. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  172230. png_error(png_ptr, "Out of place tIME chunk");
  172231. else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_tIME))
  172232. {
  172233. png_warning(png_ptr, "Duplicate tIME chunk");
  172234. png_crc_finish(png_ptr, length);
  172235. return;
  172236. }
  172237. if (png_ptr->mode & PNG_HAVE_IDAT)
  172238. png_ptr->mode |= PNG_AFTER_IDAT;
  172239. if (length != 7)
  172240. {
  172241. png_warning(png_ptr, "Incorrect tIME chunk length");
  172242. png_crc_finish(png_ptr, length);
  172243. return;
  172244. }
  172245. png_crc_read(png_ptr, buf, 7);
  172246. if (png_crc_finish(png_ptr, 0))
  172247. return;
  172248. mod_time.second = buf[6];
  172249. mod_time.minute = buf[5];
  172250. mod_time.hour = buf[4];
  172251. mod_time.day = buf[3];
  172252. mod_time.month = buf[2];
  172253. mod_time.year = png_get_uint_16(buf);
  172254. png_set_tIME(png_ptr, info_ptr, &mod_time);
  172255. }
  172256. #endif
  172257. #if defined(PNG_READ_tEXt_SUPPORTED)
  172258. void /* PRIVATE */
  172259. png_handle_tEXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  172260. {
  172261. png_textp text_ptr;
  172262. png_charp key;
  172263. png_charp text;
  172264. png_uint_32 skip = 0;
  172265. png_size_t slength;
  172266. int ret;
  172267. png_debug(1, "in png_handle_tEXt\n");
  172268. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  172269. png_error(png_ptr, "Missing IHDR before tEXt");
  172270. if (png_ptr->mode & PNG_HAVE_IDAT)
  172271. png_ptr->mode |= PNG_AFTER_IDAT;
  172272. #ifdef PNG_MAX_MALLOC_64K
  172273. if (length > (png_uint_32)65535L)
  172274. {
  172275. png_warning(png_ptr, "tEXt chunk too large to fit in memory");
  172276. skip = length - (png_uint_32)65535L;
  172277. length = (png_uint_32)65535L;
  172278. }
  172279. #endif
  172280. key = (png_charp)png_malloc_warn(png_ptr, length + 1);
  172281. if (key == NULL)
  172282. {
  172283. png_warning(png_ptr, "No memory to process text chunk.");
  172284. return;
  172285. }
  172286. slength = (png_size_t)length;
  172287. png_crc_read(png_ptr, (png_bytep)key, slength);
  172288. if (png_crc_finish(png_ptr, skip))
  172289. {
  172290. png_free(png_ptr, key);
  172291. return;
  172292. }
  172293. key[slength] = 0x00;
  172294. for (text = key; *text; text++)
  172295. ;
  172296. if (text != key + slength)
  172297. text++;
  172298. text_ptr = (png_textp)png_malloc_warn(png_ptr,
  172299. (png_uint_32)png_sizeof(png_text));
  172300. if (text_ptr == NULL)
  172301. {
  172302. png_warning(png_ptr, "Not enough memory to process text chunk.");
  172303. png_free(png_ptr, key);
  172304. return;
  172305. }
  172306. text_ptr->compression = PNG_TEXT_COMPRESSION_NONE;
  172307. text_ptr->key = key;
  172308. #ifdef PNG_iTXt_SUPPORTED
  172309. text_ptr->lang = NULL;
  172310. text_ptr->lang_key = NULL;
  172311. text_ptr->itxt_length = 0;
  172312. #endif
  172313. text_ptr->text = text;
  172314. text_ptr->text_length = png_strlen(text);
  172315. ret=png_set_text_2(png_ptr, info_ptr, text_ptr, 1);
  172316. png_free(png_ptr, key);
  172317. png_free(png_ptr, text_ptr);
  172318. if (ret)
  172319. png_warning(png_ptr, "Insufficient memory to process text chunk.");
  172320. }
  172321. #endif
  172322. #if defined(PNG_READ_zTXt_SUPPORTED)
  172323. void /* PRIVATE */
  172324. png_handle_zTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  172325. {
  172326. png_textp text_ptr;
  172327. png_charp chunkdata;
  172328. png_charp text;
  172329. int comp_type;
  172330. int ret;
  172331. png_size_t slength, prefix_len, data_len;
  172332. png_debug(1, "in png_handle_zTXt\n");
  172333. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  172334. png_error(png_ptr, "Missing IHDR before zTXt");
  172335. if (png_ptr->mode & PNG_HAVE_IDAT)
  172336. png_ptr->mode |= PNG_AFTER_IDAT;
  172337. #ifdef PNG_MAX_MALLOC_64K
  172338. if (length > (png_uint_32)65535L)
  172339. {
  172340. png_warning(png_ptr,"zTXt chunk too large to fit in memory");
  172341. png_crc_finish(png_ptr, length);
  172342. return;
  172343. }
  172344. #endif
  172345. chunkdata = (png_charp)png_malloc_warn(png_ptr, length + 1);
  172346. if (chunkdata == NULL)
  172347. {
  172348. png_warning(png_ptr,"Out of memory processing zTXt chunk.");
  172349. return;
  172350. }
  172351. slength = (png_size_t)length;
  172352. png_crc_read(png_ptr, (png_bytep)chunkdata, slength);
  172353. if (png_crc_finish(png_ptr, 0))
  172354. {
  172355. png_free(png_ptr, chunkdata);
  172356. return;
  172357. }
  172358. chunkdata[slength] = 0x00;
  172359. for (text = chunkdata; *text; text++)
  172360. ;
  172361. if (text >= chunkdata + slength - 2)
  172362. {
  172363. png_warning(png_ptr, "Truncated zTXt chunk");
  172364. png_free(png_ptr, chunkdata);
  172365. return;
  172366. }
  172367. else
  172368. {
  172369. comp_type = *(++text);
  172370. if (comp_type != PNG_TEXT_COMPRESSION_zTXt)
  172371. {
  172372. png_warning(png_ptr, "Unknown compression type in zTXt chunk");
  172373. comp_type = PNG_TEXT_COMPRESSION_zTXt;
  172374. }
  172375. text++; /* skip the compression_method byte */
  172376. }
  172377. prefix_len = text - chunkdata;
  172378. chunkdata = (png_charp)png_decompress_chunk(png_ptr, comp_type, chunkdata,
  172379. (png_size_t)length, prefix_len, &data_len);
  172380. text_ptr = (png_textp)png_malloc_warn(png_ptr,
  172381. (png_uint_32)png_sizeof(png_text));
  172382. if (text_ptr == NULL)
  172383. {
  172384. png_warning(png_ptr,"Not enough memory to process zTXt chunk.");
  172385. png_free(png_ptr, chunkdata);
  172386. return;
  172387. }
  172388. text_ptr->compression = comp_type;
  172389. text_ptr->key = chunkdata;
  172390. #ifdef PNG_iTXt_SUPPORTED
  172391. text_ptr->lang = NULL;
  172392. text_ptr->lang_key = NULL;
  172393. text_ptr->itxt_length = 0;
  172394. #endif
  172395. text_ptr->text = chunkdata + prefix_len;
  172396. text_ptr->text_length = data_len;
  172397. ret=png_set_text_2(png_ptr, info_ptr, text_ptr, 1);
  172398. png_free(png_ptr, text_ptr);
  172399. png_free(png_ptr, chunkdata);
  172400. if (ret)
  172401. png_error(png_ptr, "Insufficient memory to store zTXt chunk.");
  172402. }
  172403. #endif
  172404. #if defined(PNG_READ_iTXt_SUPPORTED)
  172405. void /* PRIVATE */
  172406. png_handle_iTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  172407. {
  172408. png_textp text_ptr;
  172409. png_charp chunkdata;
  172410. png_charp key, lang, text, lang_key;
  172411. int comp_flag;
  172412. int comp_type = 0;
  172413. int ret;
  172414. png_size_t slength, prefix_len, data_len;
  172415. png_debug(1, "in png_handle_iTXt\n");
  172416. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  172417. png_error(png_ptr, "Missing IHDR before iTXt");
  172418. if (png_ptr->mode & PNG_HAVE_IDAT)
  172419. png_ptr->mode |= PNG_AFTER_IDAT;
  172420. #ifdef PNG_MAX_MALLOC_64K
  172421. if (length > (png_uint_32)65535L)
  172422. {
  172423. png_warning(png_ptr,"iTXt chunk too large to fit in memory");
  172424. png_crc_finish(png_ptr, length);
  172425. return;
  172426. }
  172427. #endif
  172428. chunkdata = (png_charp)png_malloc_warn(png_ptr, length + 1);
  172429. if (chunkdata == NULL)
  172430. {
  172431. png_warning(png_ptr, "No memory to process iTXt chunk.");
  172432. return;
  172433. }
  172434. slength = (png_size_t)length;
  172435. png_crc_read(png_ptr, (png_bytep)chunkdata, slength);
  172436. if (png_crc_finish(png_ptr, 0))
  172437. {
  172438. png_free(png_ptr, chunkdata);
  172439. return;
  172440. }
  172441. chunkdata[slength] = 0x00;
  172442. for (lang = chunkdata; *lang; lang++)
  172443. ;
  172444. lang++; /* skip NUL separator */
  172445. if (lang >= chunkdata + slength - 3)
  172446. {
  172447. png_warning(png_ptr, "Truncated iTXt chunk");
  172448. png_free(png_ptr, chunkdata);
  172449. return;
  172450. }
  172451. else
  172452. {
  172453. comp_flag = *lang++;
  172454. comp_type = *lang++;
  172455. }
  172456. for (lang_key = lang; *lang_key; lang_key++)
  172457. ;
  172458. lang_key++; /* skip NUL separator */
  172459. if (lang_key >= chunkdata + slength)
  172460. {
  172461. png_warning(png_ptr, "Truncated iTXt chunk");
  172462. png_free(png_ptr, chunkdata);
  172463. return;
  172464. }
  172465. for (text = lang_key; *text; text++)
  172466. ;
  172467. text++; /* skip NUL separator */
  172468. if (text >= chunkdata + slength)
  172469. {
  172470. png_warning(png_ptr, "Malformed iTXt chunk");
  172471. png_free(png_ptr, chunkdata);
  172472. return;
  172473. }
  172474. prefix_len = text - chunkdata;
  172475. key=chunkdata;
  172476. if (comp_flag)
  172477. chunkdata = png_decompress_chunk(png_ptr, comp_type, chunkdata,
  172478. (size_t)length, prefix_len, &data_len);
  172479. else
  172480. data_len=png_strlen(chunkdata + prefix_len);
  172481. text_ptr = (png_textp)png_malloc_warn(png_ptr,
  172482. (png_uint_32)png_sizeof(png_text));
  172483. if (text_ptr == NULL)
  172484. {
  172485. png_warning(png_ptr,"Not enough memory to process iTXt chunk.");
  172486. png_free(png_ptr, chunkdata);
  172487. return;
  172488. }
  172489. text_ptr->compression = (int)comp_flag + 1;
  172490. text_ptr->lang_key = chunkdata+(lang_key-key);
  172491. text_ptr->lang = chunkdata+(lang-key);
  172492. text_ptr->itxt_length = data_len;
  172493. text_ptr->text_length = 0;
  172494. text_ptr->key = chunkdata;
  172495. text_ptr->text = chunkdata + prefix_len;
  172496. ret=png_set_text_2(png_ptr, info_ptr, text_ptr, 1);
  172497. png_free(png_ptr, text_ptr);
  172498. png_free(png_ptr, chunkdata);
  172499. if (ret)
  172500. png_error(png_ptr, "Insufficient memory to store iTXt chunk.");
  172501. }
  172502. #endif
  172503. void /* PRIVATE */
  172504. png_handle_unknown(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  172505. {
  172506. png_uint_32 skip = 0;
  172507. png_debug(1, "in png_handle_unknown\n");
  172508. if (png_ptr->mode & PNG_HAVE_IDAT)
  172509. {
  172510. #ifdef PNG_USE_LOCAL_ARRAYS
  172511. PNG_CONST PNG_IDAT;
  172512. #endif
  172513. if (png_memcmp(png_ptr->chunk_name, png_IDAT, 4)) /* not an IDAT */
  172514. png_ptr->mode |= PNG_AFTER_IDAT;
  172515. }
  172516. png_check_chunk_name(png_ptr, png_ptr->chunk_name);
  172517. if (!(png_ptr->chunk_name[0] & 0x20))
  172518. {
  172519. #if defined(PNG_READ_UNKNOWN_CHUNKS_SUPPORTED)
  172520. if(png_handle_as_unknown(png_ptr, png_ptr->chunk_name) !=
  172521. PNG_HANDLE_CHUNK_ALWAYS
  172522. #if defined(PNG_READ_USER_CHUNKS_SUPPORTED)
  172523. && png_ptr->read_user_chunk_fn == NULL
  172524. #endif
  172525. )
  172526. #endif
  172527. png_chunk_error(png_ptr, "unknown critical chunk");
  172528. }
  172529. #if defined(PNG_READ_UNKNOWN_CHUNKS_SUPPORTED)
  172530. if ((png_ptr->flags & PNG_FLAG_KEEP_UNKNOWN_CHUNKS) ||
  172531. (png_ptr->read_user_chunk_fn != NULL))
  172532. {
  172533. #ifdef PNG_MAX_MALLOC_64K
  172534. if (length > (png_uint_32)65535L)
  172535. {
  172536. png_warning(png_ptr, "unknown chunk too large to fit in memory");
  172537. skip = length - (png_uint_32)65535L;
  172538. length = (png_uint_32)65535L;
  172539. }
  172540. #endif
  172541. png_strncpy((png_charp)png_ptr->unknown_chunk.name,
  172542. (png_charp)png_ptr->chunk_name, 5);
  172543. png_ptr->unknown_chunk.data = (png_bytep)png_malloc(png_ptr, length);
  172544. png_ptr->unknown_chunk.size = (png_size_t)length;
  172545. png_crc_read(png_ptr, (png_bytep)png_ptr->unknown_chunk.data, length);
  172546. #if defined(PNG_READ_USER_CHUNKS_SUPPORTED)
  172547. if(png_ptr->read_user_chunk_fn != NULL)
  172548. {
  172549. int ret;
  172550. ret = (*(png_ptr->read_user_chunk_fn))
  172551. (png_ptr, &png_ptr->unknown_chunk);
  172552. if (ret < 0)
  172553. png_chunk_error(png_ptr, "error in user chunk");
  172554. if (ret == 0)
  172555. {
  172556. if (!(png_ptr->chunk_name[0] & 0x20))
  172557. if(png_handle_as_unknown(png_ptr, png_ptr->chunk_name) !=
  172558. PNG_HANDLE_CHUNK_ALWAYS)
  172559. png_chunk_error(png_ptr, "unknown critical chunk");
  172560. png_set_unknown_chunks(png_ptr, info_ptr,
  172561. &png_ptr->unknown_chunk, 1);
  172562. }
  172563. }
  172564. #else
  172565. png_set_unknown_chunks(png_ptr, info_ptr, &png_ptr->unknown_chunk, 1);
  172566. #endif
  172567. png_free(png_ptr, png_ptr->unknown_chunk.data);
  172568. png_ptr->unknown_chunk.data = NULL;
  172569. }
  172570. else
  172571. #endif
  172572. skip = length;
  172573. png_crc_finish(png_ptr, skip);
  172574. #if !defined(PNG_READ_USER_CHUNKS_SUPPORTED)
  172575. info_ptr = info_ptr; /* quiet compiler warnings about unused info_ptr */
  172576. #endif
  172577. }
  172578. #define isnonalpha(c) ((c) < 65 || (c) > 122 || ((c) > 90 && (c) < 97))
  172579. void /* PRIVATE */
  172580. png_check_chunk_name(png_structp png_ptr, png_bytep chunk_name)
  172581. {
  172582. png_debug(1, "in png_check_chunk_name\n");
  172583. if (isnonalpha(chunk_name[0]) || isnonalpha(chunk_name[1]) ||
  172584. isnonalpha(chunk_name[2]) || isnonalpha(chunk_name[3]))
  172585. {
  172586. png_chunk_error(png_ptr, "invalid chunk type");
  172587. }
  172588. }
  172589. void /* PRIVATE */
  172590. png_combine_row(png_structp png_ptr, png_bytep row, int mask)
  172591. {
  172592. png_debug(1,"in png_combine_row\n");
  172593. if (mask == 0xff)
  172594. {
  172595. png_memcpy(row, png_ptr->row_buf + 1,
  172596. PNG_ROWBYTES(png_ptr->row_info.pixel_depth, png_ptr->width));
  172597. }
  172598. else
  172599. {
  172600. switch (png_ptr->row_info.pixel_depth)
  172601. {
  172602. case 1:
  172603. {
  172604. png_bytep sp = png_ptr->row_buf + 1;
  172605. png_bytep dp = row;
  172606. int s_inc, s_start, s_end;
  172607. int m = 0x80;
  172608. int shift;
  172609. png_uint_32 i;
  172610. png_uint_32 row_width = png_ptr->width;
  172611. #if defined(PNG_READ_PACKSWAP_SUPPORTED)
  172612. if (png_ptr->transformations & PNG_PACKSWAP)
  172613. {
  172614. s_start = 0;
  172615. s_end = 7;
  172616. s_inc = 1;
  172617. }
  172618. else
  172619. #endif
  172620. {
  172621. s_start = 7;
  172622. s_end = 0;
  172623. s_inc = -1;
  172624. }
  172625. shift = s_start;
  172626. for (i = 0; i < row_width; i++)
  172627. {
  172628. if (m & mask)
  172629. {
  172630. int value;
  172631. value = (*sp >> shift) & 0x01;
  172632. *dp &= (png_byte)((0x7f7f >> (7 - shift)) & 0xff);
  172633. *dp |= (png_byte)(value << shift);
  172634. }
  172635. if (shift == s_end)
  172636. {
  172637. shift = s_start;
  172638. sp++;
  172639. dp++;
  172640. }
  172641. else
  172642. shift += s_inc;
  172643. if (m == 1)
  172644. m = 0x80;
  172645. else
  172646. m >>= 1;
  172647. }
  172648. break;
  172649. }
  172650. case 2:
  172651. {
  172652. png_bytep sp = png_ptr->row_buf + 1;
  172653. png_bytep dp = row;
  172654. int s_start, s_end, s_inc;
  172655. int m = 0x80;
  172656. int shift;
  172657. png_uint_32 i;
  172658. png_uint_32 row_width = png_ptr->width;
  172659. int value;
  172660. #if defined(PNG_READ_PACKSWAP_SUPPORTED)
  172661. if (png_ptr->transformations & PNG_PACKSWAP)
  172662. {
  172663. s_start = 0;
  172664. s_end = 6;
  172665. s_inc = 2;
  172666. }
  172667. else
  172668. #endif
  172669. {
  172670. s_start = 6;
  172671. s_end = 0;
  172672. s_inc = -2;
  172673. }
  172674. shift = s_start;
  172675. for (i = 0; i < row_width; i++)
  172676. {
  172677. if (m & mask)
  172678. {
  172679. value = (*sp >> shift) & 0x03;
  172680. *dp &= (png_byte)((0x3f3f >> (6 - shift)) & 0xff);
  172681. *dp |= (png_byte)(value << shift);
  172682. }
  172683. if (shift == s_end)
  172684. {
  172685. shift = s_start;
  172686. sp++;
  172687. dp++;
  172688. }
  172689. else
  172690. shift += s_inc;
  172691. if (m == 1)
  172692. m = 0x80;
  172693. else
  172694. m >>= 1;
  172695. }
  172696. break;
  172697. }
  172698. case 4:
  172699. {
  172700. png_bytep sp = png_ptr->row_buf + 1;
  172701. png_bytep dp = row;
  172702. int s_start, s_end, s_inc;
  172703. int m = 0x80;
  172704. int shift;
  172705. png_uint_32 i;
  172706. png_uint_32 row_width = png_ptr->width;
  172707. int value;
  172708. #if defined(PNG_READ_PACKSWAP_SUPPORTED)
  172709. if (png_ptr->transformations & PNG_PACKSWAP)
  172710. {
  172711. s_start = 0;
  172712. s_end = 4;
  172713. s_inc = 4;
  172714. }
  172715. else
  172716. #endif
  172717. {
  172718. s_start = 4;
  172719. s_end = 0;
  172720. s_inc = -4;
  172721. }
  172722. shift = s_start;
  172723. for (i = 0; i < row_width; i++)
  172724. {
  172725. if (m & mask)
  172726. {
  172727. value = (*sp >> shift) & 0xf;
  172728. *dp &= (png_byte)((0xf0f >> (4 - shift)) & 0xff);
  172729. *dp |= (png_byte)(value << shift);
  172730. }
  172731. if (shift == s_end)
  172732. {
  172733. shift = s_start;
  172734. sp++;
  172735. dp++;
  172736. }
  172737. else
  172738. shift += s_inc;
  172739. if (m == 1)
  172740. m = 0x80;
  172741. else
  172742. m >>= 1;
  172743. }
  172744. break;
  172745. }
  172746. default:
  172747. {
  172748. png_bytep sp = png_ptr->row_buf + 1;
  172749. png_bytep dp = row;
  172750. png_size_t pixel_bytes = (png_ptr->row_info.pixel_depth >> 3);
  172751. png_uint_32 i;
  172752. png_uint_32 row_width = png_ptr->width;
  172753. png_byte m = 0x80;
  172754. for (i = 0; i < row_width; i++)
  172755. {
  172756. if (m & mask)
  172757. {
  172758. png_memcpy(dp, sp, pixel_bytes);
  172759. }
  172760. sp += pixel_bytes;
  172761. dp += pixel_bytes;
  172762. if (m == 1)
  172763. m = 0x80;
  172764. else
  172765. m >>= 1;
  172766. }
  172767. break;
  172768. }
  172769. }
  172770. }
  172771. }
  172772. #ifdef PNG_READ_INTERLACING_SUPPORTED
  172773. void /* PRIVATE */
  172774. png_do_read_interlace(png_structp png_ptr)
  172775. {
  172776. png_row_infop row_info = &(png_ptr->row_info);
  172777. png_bytep row = png_ptr->row_buf + 1;
  172778. int pass = png_ptr->pass;
  172779. png_uint_32 transformations = png_ptr->transformations;
  172780. #ifdef PNG_USE_LOCAL_ARRAYS
  172781. PNG_CONST int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};
  172782. #endif
  172783. png_debug(1,"in png_do_read_interlace\n");
  172784. if (row != NULL && row_info != NULL)
  172785. {
  172786. png_uint_32 final_width;
  172787. final_width = row_info->width * png_pass_inc[pass];
  172788. switch (row_info->pixel_depth)
  172789. {
  172790. case 1:
  172791. {
  172792. png_bytep sp = row + (png_size_t)((row_info->width - 1) >> 3);
  172793. png_bytep dp = row + (png_size_t)((final_width - 1) >> 3);
  172794. int sshift, dshift;
  172795. int s_start, s_end, s_inc;
  172796. int jstop = png_pass_inc[pass];
  172797. png_byte v;
  172798. png_uint_32 i;
  172799. int j;
  172800. #if defined(PNG_READ_PACKSWAP_SUPPORTED)
  172801. if (transformations & PNG_PACKSWAP)
  172802. {
  172803. sshift = (int)((row_info->width + 7) & 0x07);
  172804. dshift = (int)((final_width + 7) & 0x07);
  172805. s_start = 7;
  172806. s_end = 0;
  172807. s_inc = -1;
  172808. }
  172809. else
  172810. #endif
  172811. {
  172812. sshift = 7 - (int)((row_info->width + 7) & 0x07);
  172813. dshift = 7 - (int)((final_width + 7) & 0x07);
  172814. s_start = 0;
  172815. s_end = 7;
  172816. s_inc = 1;
  172817. }
  172818. for (i = 0; i < row_info->width; i++)
  172819. {
  172820. v = (png_byte)((*sp >> sshift) & 0x01);
  172821. for (j = 0; j < jstop; j++)
  172822. {
  172823. *dp &= (png_byte)((0x7f7f >> (7 - dshift)) & 0xff);
  172824. *dp |= (png_byte)(v << dshift);
  172825. if (dshift == s_end)
  172826. {
  172827. dshift = s_start;
  172828. dp--;
  172829. }
  172830. else
  172831. dshift += s_inc;
  172832. }
  172833. if (sshift == s_end)
  172834. {
  172835. sshift = s_start;
  172836. sp--;
  172837. }
  172838. else
  172839. sshift += s_inc;
  172840. }
  172841. break;
  172842. }
  172843. case 2:
  172844. {
  172845. png_bytep sp = row + (png_uint_32)((row_info->width - 1) >> 2);
  172846. png_bytep dp = row + (png_uint_32)((final_width - 1) >> 2);
  172847. int sshift, dshift;
  172848. int s_start, s_end, s_inc;
  172849. int jstop = png_pass_inc[pass];
  172850. png_uint_32 i;
  172851. #if defined(PNG_READ_PACKSWAP_SUPPORTED)
  172852. if (transformations & PNG_PACKSWAP)
  172853. {
  172854. sshift = (int)(((row_info->width + 3) & 0x03) << 1);
  172855. dshift = (int)(((final_width + 3) & 0x03) << 1);
  172856. s_start = 6;
  172857. s_end = 0;
  172858. s_inc = -2;
  172859. }
  172860. else
  172861. #endif
  172862. {
  172863. sshift = (int)((3 - ((row_info->width + 3) & 0x03)) << 1);
  172864. dshift = (int)((3 - ((final_width + 3) & 0x03)) << 1);
  172865. s_start = 0;
  172866. s_end = 6;
  172867. s_inc = 2;
  172868. }
  172869. for (i = 0; i < row_info->width; i++)
  172870. {
  172871. png_byte v;
  172872. int j;
  172873. v = (png_byte)((*sp >> sshift) & 0x03);
  172874. for (j = 0; j < jstop; j++)
  172875. {
  172876. *dp &= (png_byte)((0x3f3f >> (6 - dshift)) & 0xff);
  172877. *dp |= (png_byte)(v << dshift);
  172878. if (dshift == s_end)
  172879. {
  172880. dshift = s_start;
  172881. dp--;
  172882. }
  172883. else
  172884. dshift += s_inc;
  172885. }
  172886. if (sshift == s_end)
  172887. {
  172888. sshift = s_start;
  172889. sp--;
  172890. }
  172891. else
  172892. sshift += s_inc;
  172893. }
  172894. break;
  172895. }
  172896. case 4:
  172897. {
  172898. png_bytep sp = row + (png_size_t)((row_info->width - 1) >> 1);
  172899. png_bytep dp = row + (png_size_t)((final_width - 1) >> 1);
  172900. int sshift, dshift;
  172901. int s_start, s_end, s_inc;
  172902. png_uint_32 i;
  172903. int jstop = png_pass_inc[pass];
  172904. #if defined(PNG_READ_PACKSWAP_SUPPORTED)
  172905. if (transformations & PNG_PACKSWAP)
  172906. {
  172907. sshift = (int)(((row_info->width + 1) & 0x01) << 2);
  172908. dshift = (int)(((final_width + 1) & 0x01) << 2);
  172909. s_start = 4;
  172910. s_end = 0;
  172911. s_inc = -4;
  172912. }
  172913. else
  172914. #endif
  172915. {
  172916. sshift = (int)((1 - ((row_info->width + 1) & 0x01)) << 2);
  172917. dshift = (int)((1 - ((final_width + 1) & 0x01)) << 2);
  172918. s_start = 0;
  172919. s_end = 4;
  172920. s_inc = 4;
  172921. }
  172922. for (i = 0; i < row_info->width; i++)
  172923. {
  172924. png_byte v = (png_byte)((*sp >> sshift) & 0xf);
  172925. int j;
  172926. for (j = 0; j < jstop; j++)
  172927. {
  172928. *dp &= (png_byte)((0xf0f >> (4 - dshift)) & 0xff);
  172929. *dp |= (png_byte)(v << dshift);
  172930. if (dshift == s_end)
  172931. {
  172932. dshift = s_start;
  172933. dp--;
  172934. }
  172935. else
  172936. dshift += s_inc;
  172937. }
  172938. if (sshift == s_end)
  172939. {
  172940. sshift = s_start;
  172941. sp--;
  172942. }
  172943. else
  172944. sshift += s_inc;
  172945. }
  172946. break;
  172947. }
  172948. default:
  172949. {
  172950. png_size_t pixel_bytes = (row_info->pixel_depth >> 3);
  172951. png_bytep sp = row + (png_size_t)(row_info->width - 1) * pixel_bytes;
  172952. png_bytep dp = row + (png_size_t)(final_width - 1) * pixel_bytes;
  172953. int jstop = png_pass_inc[pass];
  172954. png_uint_32 i;
  172955. for (i = 0; i < row_info->width; i++)
  172956. {
  172957. png_byte v[8];
  172958. int j;
  172959. png_memcpy(v, sp, pixel_bytes);
  172960. for (j = 0; j < jstop; j++)
  172961. {
  172962. png_memcpy(dp, v, pixel_bytes);
  172963. dp -= pixel_bytes;
  172964. }
  172965. sp -= pixel_bytes;
  172966. }
  172967. break;
  172968. }
  172969. }
  172970. row_info->width = final_width;
  172971. row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,final_width);
  172972. }
  172973. #if !defined(PNG_READ_PACKSWAP_SUPPORTED)
  172974. transformations = transformations; /* silence compiler warning */
  172975. #endif
  172976. }
  172977. #endif /* PNG_READ_INTERLACING_SUPPORTED */
  172978. void /* PRIVATE */
  172979. png_read_filter_row(png_structp png_ptr, png_row_infop row_info, png_bytep row,
  172980. png_bytep prev_row, int filter)
  172981. {
  172982. png_debug(1, "in png_read_filter_row\n");
  172983. png_debug2(2,"row = %lu, filter = %d\n", png_ptr->row_number, filter);
  172984. switch (filter)
  172985. {
  172986. case PNG_FILTER_VALUE_NONE:
  172987. break;
  172988. case PNG_FILTER_VALUE_SUB:
  172989. {
  172990. png_uint_32 i;
  172991. png_uint_32 istop = row_info->rowbytes;
  172992. png_uint_32 bpp = (row_info->pixel_depth + 7) >> 3;
  172993. png_bytep rp = row + bpp;
  172994. png_bytep lp = row;
  172995. for (i = bpp; i < istop; i++)
  172996. {
  172997. *rp = (png_byte)(((int)(*rp) + (int)(*lp++)) & 0xff);
  172998. rp++;
  172999. }
  173000. break;
  173001. }
  173002. case PNG_FILTER_VALUE_UP:
  173003. {
  173004. png_uint_32 i;
  173005. png_uint_32 istop = row_info->rowbytes;
  173006. png_bytep rp = row;
  173007. png_bytep pp = prev_row;
  173008. for (i = 0; i < istop; i++)
  173009. {
  173010. *rp = (png_byte)(((int)(*rp) + (int)(*pp++)) & 0xff);
  173011. rp++;
  173012. }
  173013. break;
  173014. }
  173015. case PNG_FILTER_VALUE_AVG:
  173016. {
  173017. png_uint_32 i;
  173018. png_bytep rp = row;
  173019. png_bytep pp = prev_row;
  173020. png_bytep lp = row;
  173021. png_uint_32 bpp = (row_info->pixel_depth + 7) >> 3;
  173022. png_uint_32 istop = row_info->rowbytes - bpp;
  173023. for (i = 0; i < bpp; i++)
  173024. {
  173025. *rp = (png_byte)(((int)(*rp) +
  173026. ((int)(*pp++) / 2 )) & 0xff);
  173027. rp++;
  173028. }
  173029. for (i = 0; i < istop; i++)
  173030. {
  173031. *rp = (png_byte)(((int)(*rp) +
  173032. (int)(*pp++ + *lp++) / 2 ) & 0xff);
  173033. rp++;
  173034. }
  173035. break;
  173036. }
  173037. case PNG_FILTER_VALUE_PAETH:
  173038. {
  173039. png_uint_32 i;
  173040. png_bytep rp = row;
  173041. png_bytep pp = prev_row;
  173042. png_bytep lp = row;
  173043. png_bytep cp = prev_row;
  173044. png_uint_32 bpp = (row_info->pixel_depth + 7) >> 3;
  173045. png_uint_32 istop=row_info->rowbytes - bpp;
  173046. for (i = 0; i < bpp; i++)
  173047. {
  173048. *rp = (png_byte)(((int)(*rp) + (int)(*pp++)) & 0xff);
  173049. rp++;
  173050. }
  173051. for (i = 0; i < istop; i++) /* use leftover rp,pp */
  173052. {
  173053. int a, b, c, pa, pb, pc, p;
  173054. a = *lp++;
  173055. b = *pp++;
  173056. c = *cp++;
  173057. p = b - c;
  173058. pc = a - c;
  173059. #ifdef PNG_USE_ABS
  173060. pa = abs(p);
  173061. pb = abs(pc);
  173062. pc = abs(p + pc);
  173063. #else
  173064. pa = p < 0 ? -p : p;
  173065. pb = pc < 0 ? -pc : pc;
  173066. pc = (p + pc) < 0 ? -(p + pc) : p + pc;
  173067. #endif
  173068. p = (pa <= pb && pa <=pc) ? a : (pb <= pc) ? b : c;
  173069. *rp = (png_byte)(((int)(*rp) + p) & 0xff);
  173070. rp++;
  173071. }
  173072. break;
  173073. }
  173074. default:
  173075. png_warning(png_ptr, "Ignoring bad adaptive filter type");
  173076. *row=0;
  173077. break;
  173078. }
  173079. }
  173080. void /* PRIVATE */
  173081. png_read_finish_row(png_structp png_ptr)
  173082. {
  173083. #ifdef PNG_USE_LOCAL_ARRAYS
  173084. PNG_CONST int png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0};
  173085. PNG_CONST int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};
  173086. PNG_CONST int png_pass_ystart[7] = {0, 0, 4, 0, 2, 0, 1};
  173087. PNG_CONST int png_pass_yinc[7] = {8, 8, 8, 4, 4, 2, 2};
  173088. #endif
  173089. png_debug(1, "in png_read_finish_row\n");
  173090. png_ptr->row_number++;
  173091. if (png_ptr->row_number < png_ptr->num_rows)
  173092. return;
  173093. if (png_ptr->interlaced)
  173094. {
  173095. png_ptr->row_number = 0;
  173096. png_memset_check(png_ptr, png_ptr->prev_row, 0,
  173097. png_ptr->rowbytes + 1);
  173098. do
  173099. {
  173100. png_ptr->pass++;
  173101. if (png_ptr->pass >= 7)
  173102. break;
  173103. png_ptr->iwidth = (png_ptr->width +
  173104. png_pass_inc[png_ptr->pass] - 1 -
  173105. png_pass_start[png_ptr->pass]) /
  173106. png_pass_inc[png_ptr->pass];
  173107. png_ptr->irowbytes = PNG_ROWBYTES(png_ptr->pixel_depth,
  173108. png_ptr->iwidth) + 1;
  173109. if (!(png_ptr->transformations & PNG_INTERLACE))
  173110. {
  173111. png_ptr->num_rows = (png_ptr->height +
  173112. png_pass_yinc[png_ptr->pass] - 1 -
  173113. png_pass_ystart[png_ptr->pass]) /
  173114. png_pass_yinc[png_ptr->pass];
  173115. if (!(png_ptr->num_rows))
  173116. continue;
  173117. }
  173118. else /* if (png_ptr->transformations & PNG_INTERLACE) */
  173119. break;
  173120. } while (png_ptr->iwidth == 0);
  173121. if (png_ptr->pass < 7)
  173122. return;
  173123. }
  173124. if (!(png_ptr->flags & PNG_FLAG_ZLIB_FINISHED))
  173125. {
  173126. #ifdef PNG_USE_LOCAL_ARRAYS
  173127. PNG_CONST PNG_IDAT;
  173128. #endif
  173129. char extra;
  173130. int ret;
  173131. png_ptr->zstream.next_out = (Bytef *)&extra;
  173132. png_ptr->zstream.avail_out = (uInt)1;
  173133. for(;;)
  173134. {
  173135. if (!(png_ptr->zstream.avail_in))
  173136. {
  173137. while (!png_ptr->idat_size)
  173138. {
  173139. png_byte chunk_length[4];
  173140. png_crc_finish(png_ptr, 0);
  173141. png_read_data(png_ptr, chunk_length, 4);
  173142. png_ptr->idat_size = png_get_uint_31(png_ptr, chunk_length);
  173143. png_reset_crc(png_ptr);
  173144. png_crc_read(png_ptr, png_ptr->chunk_name, 4);
  173145. if (png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  173146. png_error(png_ptr, "Not enough image data");
  173147. }
  173148. png_ptr->zstream.avail_in = (uInt)png_ptr->zbuf_size;
  173149. png_ptr->zstream.next_in = png_ptr->zbuf;
  173150. if (png_ptr->zbuf_size > png_ptr->idat_size)
  173151. png_ptr->zstream.avail_in = (uInt)png_ptr->idat_size;
  173152. png_crc_read(png_ptr, png_ptr->zbuf, png_ptr->zstream.avail_in);
  173153. png_ptr->idat_size -= png_ptr->zstream.avail_in;
  173154. }
  173155. ret = inflate(&png_ptr->zstream, Z_PARTIAL_FLUSH);
  173156. if (ret == Z_STREAM_END)
  173157. {
  173158. if (!(png_ptr->zstream.avail_out) || png_ptr->zstream.avail_in ||
  173159. png_ptr->idat_size)
  173160. png_warning(png_ptr, "Extra compressed data");
  173161. png_ptr->mode |= PNG_AFTER_IDAT;
  173162. png_ptr->flags |= PNG_FLAG_ZLIB_FINISHED;
  173163. break;
  173164. }
  173165. if (ret != Z_OK)
  173166. png_error(png_ptr, png_ptr->zstream.msg ? png_ptr->zstream.msg :
  173167. "Decompression Error");
  173168. if (!(png_ptr->zstream.avail_out))
  173169. {
  173170. png_warning(png_ptr, "Extra compressed data.");
  173171. png_ptr->mode |= PNG_AFTER_IDAT;
  173172. png_ptr->flags |= PNG_FLAG_ZLIB_FINISHED;
  173173. break;
  173174. }
  173175. }
  173176. png_ptr->zstream.avail_out = 0;
  173177. }
  173178. if (png_ptr->idat_size || png_ptr->zstream.avail_in)
  173179. png_warning(png_ptr, "Extra compression data");
  173180. inflateReset(&png_ptr->zstream);
  173181. png_ptr->mode |= PNG_AFTER_IDAT;
  173182. }
  173183. void /* PRIVATE */
  173184. png_read_start_row(png_structp png_ptr)
  173185. {
  173186. #ifdef PNG_USE_LOCAL_ARRAYS
  173187. PNG_CONST int png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0};
  173188. PNG_CONST int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};
  173189. PNG_CONST int png_pass_ystart[7] = {0, 0, 4, 0, 2, 0, 1};
  173190. PNG_CONST int png_pass_yinc[7] = {8, 8, 8, 4, 4, 2, 2};
  173191. #endif
  173192. int max_pixel_depth;
  173193. png_uint_32 row_bytes;
  173194. png_debug(1, "in png_read_start_row\n");
  173195. png_ptr->zstream.avail_in = 0;
  173196. png_init_read_transformations(png_ptr);
  173197. if (png_ptr->interlaced)
  173198. {
  173199. if (!(png_ptr->transformations & PNG_INTERLACE))
  173200. png_ptr->num_rows = (png_ptr->height + png_pass_yinc[0] - 1 -
  173201. png_pass_ystart[0]) / png_pass_yinc[0];
  173202. else
  173203. png_ptr->num_rows = png_ptr->height;
  173204. png_ptr->iwidth = (png_ptr->width +
  173205. png_pass_inc[png_ptr->pass] - 1 -
  173206. png_pass_start[png_ptr->pass]) /
  173207. png_pass_inc[png_ptr->pass];
  173208. row_bytes = PNG_ROWBYTES(png_ptr->pixel_depth,png_ptr->iwidth) + 1;
  173209. png_ptr->irowbytes = (png_size_t)row_bytes;
  173210. if((png_uint_32)png_ptr->irowbytes != row_bytes)
  173211. png_error(png_ptr, "Rowbytes overflow in png_read_start_row");
  173212. }
  173213. else
  173214. {
  173215. png_ptr->num_rows = png_ptr->height;
  173216. png_ptr->iwidth = png_ptr->width;
  173217. png_ptr->irowbytes = png_ptr->rowbytes + 1;
  173218. }
  173219. max_pixel_depth = png_ptr->pixel_depth;
  173220. #if defined(PNG_READ_PACK_SUPPORTED)
  173221. if ((png_ptr->transformations & PNG_PACK) && png_ptr->bit_depth < 8)
  173222. max_pixel_depth = 8;
  173223. #endif
  173224. #if defined(PNG_READ_EXPAND_SUPPORTED)
  173225. if (png_ptr->transformations & PNG_EXPAND)
  173226. {
  173227. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  173228. {
  173229. if (png_ptr->num_trans)
  173230. max_pixel_depth = 32;
  173231. else
  173232. max_pixel_depth = 24;
  173233. }
  173234. else if (png_ptr->color_type == PNG_COLOR_TYPE_GRAY)
  173235. {
  173236. if (max_pixel_depth < 8)
  173237. max_pixel_depth = 8;
  173238. if (png_ptr->num_trans)
  173239. max_pixel_depth *= 2;
  173240. }
  173241. else if (png_ptr->color_type == PNG_COLOR_TYPE_RGB)
  173242. {
  173243. if (png_ptr->num_trans)
  173244. {
  173245. max_pixel_depth *= 4;
  173246. max_pixel_depth /= 3;
  173247. }
  173248. }
  173249. }
  173250. #endif
  173251. #if defined(PNG_READ_FILLER_SUPPORTED)
  173252. if (png_ptr->transformations & (PNG_FILLER))
  173253. {
  173254. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  173255. max_pixel_depth = 32;
  173256. else if (png_ptr->color_type == PNG_COLOR_TYPE_GRAY)
  173257. {
  173258. if (max_pixel_depth <= 8)
  173259. max_pixel_depth = 16;
  173260. else
  173261. max_pixel_depth = 32;
  173262. }
  173263. else if (png_ptr->color_type == PNG_COLOR_TYPE_RGB)
  173264. {
  173265. if (max_pixel_depth <= 32)
  173266. max_pixel_depth = 32;
  173267. else
  173268. max_pixel_depth = 64;
  173269. }
  173270. }
  173271. #endif
  173272. #if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
  173273. if (png_ptr->transformations & PNG_GRAY_TO_RGB)
  173274. {
  173275. if (
  173276. #if defined(PNG_READ_EXPAND_SUPPORTED)
  173277. (png_ptr->num_trans && (png_ptr->transformations & PNG_EXPAND)) ||
  173278. #endif
  173279. #if defined(PNG_READ_FILLER_SUPPORTED)
  173280. (png_ptr->transformations & (PNG_FILLER)) ||
  173281. #endif
  173282. png_ptr->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
  173283. {
  173284. if (max_pixel_depth <= 16)
  173285. max_pixel_depth = 32;
  173286. else
  173287. max_pixel_depth = 64;
  173288. }
  173289. else
  173290. {
  173291. if (max_pixel_depth <= 8)
  173292. {
  173293. if (png_ptr->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  173294. max_pixel_depth = 32;
  173295. else
  173296. max_pixel_depth = 24;
  173297. }
  173298. else if (png_ptr->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  173299. max_pixel_depth = 64;
  173300. else
  173301. max_pixel_depth = 48;
  173302. }
  173303. }
  173304. #endif
  173305. #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) && \
  173306. defined(PNG_USER_TRANSFORM_PTR_SUPPORTED)
  173307. if(png_ptr->transformations & PNG_USER_TRANSFORM)
  173308. {
  173309. int user_pixel_depth=png_ptr->user_transform_depth*
  173310. png_ptr->user_transform_channels;
  173311. if(user_pixel_depth > max_pixel_depth)
  173312. max_pixel_depth=user_pixel_depth;
  173313. }
  173314. #endif
  173315. row_bytes = ((png_ptr->width + 7) & ~((png_uint_32)7));
  173316. row_bytes = PNG_ROWBYTES(max_pixel_depth,row_bytes) +
  173317. 1 + ((max_pixel_depth + 7) >> 3);
  173318. #ifdef PNG_MAX_MALLOC_64K
  173319. if (row_bytes > (png_uint_32)65536L)
  173320. png_error(png_ptr, "This image requires a row greater than 64KB");
  173321. #endif
  173322. png_ptr->big_row_buf = (png_bytep)png_malloc(png_ptr, row_bytes+64);
  173323. png_ptr->row_buf = png_ptr->big_row_buf+32;
  173324. #ifdef PNG_MAX_MALLOC_64K
  173325. if ((png_uint_32)png_ptr->rowbytes + 1 > (png_uint_32)65536L)
  173326. png_error(png_ptr, "This image requires a row greater than 64KB");
  173327. #endif
  173328. if ((png_uint_32)png_ptr->rowbytes > (png_uint_32)(PNG_SIZE_MAX - 1))
  173329. png_error(png_ptr, "Row has too many bytes to allocate in memory.");
  173330. png_ptr->prev_row = (png_bytep)png_malloc(png_ptr, (png_uint_32)(
  173331. png_ptr->rowbytes + 1));
  173332. png_memset_check(png_ptr, png_ptr->prev_row, 0, png_ptr->rowbytes + 1);
  173333. png_debug1(3, "width = %lu,\n", png_ptr->width);
  173334. png_debug1(3, "height = %lu,\n", png_ptr->height);
  173335. png_debug1(3, "iwidth = %lu,\n", png_ptr->iwidth);
  173336. png_debug1(3, "num_rows = %lu\n", png_ptr->num_rows);
  173337. png_debug1(3, "rowbytes = %lu,\n", png_ptr->rowbytes);
  173338. png_debug1(3, "irowbytes = %lu,\n", png_ptr->irowbytes);
  173339. png_ptr->flags |= PNG_FLAG_ROW_INIT;
  173340. }
  173341. #endif /* PNG_READ_SUPPORTED */
  173342. /*** End of inlined file: pngrutil.c ***/
  173343. /*** Start of inlined file: pngset.c ***/
  173344. #define PNG_INTERNAL
  173345. #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
  173346. #if defined(PNG_bKGD_SUPPORTED)
  173347. void PNGAPI
  173348. png_set_bKGD(png_structp png_ptr, png_infop info_ptr, png_color_16p background)
  173349. {
  173350. png_debug1(1, "in %s storage function\n", "bKGD");
  173351. if (png_ptr == NULL || info_ptr == NULL)
  173352. return;
  173353. png_memcpy(&(info_ptr->background), background, png_sizeof(png_color_16));
  173354. info_ptr->valid |= PNG_INFO_bKGD;
  173355. }
  173356. #endif
  173357. #if defined(PNG_cHRM_SUPPORTED)
  173358. #ifdef PNG_FLOATING_POINT_SUPPORTED
  173359. void PNGAPI
  173360. png_set_cHRM(png_structp png_ptr, png_infop info_ptr,
  173361. double white_x, double white_y, double red_x, double red_y,
  173362. double green_x, double green_y, double blue_x, double blue_y)
  173363. {
  173364. png_debug1(1, "in %s storage function\n", "cHRM");
  173365. if (png_ptr == NULL || info_ptr == NULL)
  173366. return;
  173367. if (white_x < 0.0 || white_y < 0.0 ||
  173368. red_x < 0.0 || red_y < 0.0 ||
  173369. green_x < 0.0 || green_y < 0.0 ||
  173370. blue_x < 0.0 || blue_y < 0.0)
  173371. {
  173372. png_warning(png_ptr,
  173373. "Ignoring attempt to set negative chromaticity value");
  173374. return;
  173375. }
  173376. if (white_x > 21474.83 || white_y > 21474.83 ||
  173377. red_x > 21474.83 || red_y > 21474.83 ||
  173378. green_x > 21474.83 || green_y > 21474.83 ||
  173379. blue_x > 21474.83 || blue_y > 21474.83)
  173380. {
  173381. png_warning(png_ptr,
  173382. "Ignoring attempt to set chromaticity value exceeding 21474.83");
  173383. return;
  173384. }
  173385. info_ptr->x_white = (float)white_x;
  173386. info_ptr->y_white = (float)white_y;
  173387. info_ptr->x_red = (float)red_x;
  173388. info_ptr->y_red = (float)red_y;
  173389. info_ptr->x_green = (float)green_x;
  173390. info_ptr->y_green = (float)green_y;
  173391. info_ptr->x_blue = (float)blue_x;
  173392. info_ptr->y_blue = (float)blue_y;
  173393. #ifdef PNG_FIXED_POINT_SUPPORTED
  173394. info_ptr->int_x_white = (png_fixed_point)(white_x*100000.+0.5);
  173395. info_ptr->int_y_white = (png_fixed_point)(white_y*100000.+0.5);
  173396. info_ptr->int_x_red = (png_fixed_point)( red_x*100000.+0.5);
  173397. info_ptr->int_y_red = (png_fixed_point)( red_y*100000.+0.5);
  173398. info_ptr->int_x_green = (png_fixed_point)(green_x*100000.+0.5);
  173399. info_ptr->int_y_green = (png_fixed_point)(green_y*100000.+0.5);
  173400. info_ptr->int_x_blue = (png_fixed_point)( blue_x*100000.+0.5);
  173401. info_ptr->int_y_blue = (png_fixed_point)( blue_y*100000.+0.5);
  173402. #endif
  173403. info_ptr->valid |= PNG_INFO_cHRM;
  173404. }
  173405. #endif
  173406. #ifdef PNG_FIXED_POINT_SUPPORTED
  173407. void PNGAPI
  173408. png_set_cHRM_fixed(png_structp png_ptr, png_infop info_ptr,
  173409. png_fixed_point white_x, png_fixed_point white_y, png_fixed_point red_x,
  173410. png_fixed_point red_y, png_fixed_point green_x, png_fixed_point green_y,
  173411. png_fixed_point blue_x, png_fixed_point blue_y)
  173412. {
  173413. png_debug1(1, "in %s storage function\n", "cHRM");
  173414. if (png_ptr == NULL || info_ptr == NULL)
  173415. return;
  173416. if (white_x < 0 || white_y < 0 ||
  173417. red_x < 0 || red_y < 0 ||
  173418. green_x < 0 || green_y < 0 ||
  173419. blue_x < 0 || blue_y < 0)
  173420. {
  173421. png_warning(png_ptr,
  173422. "Ignoring attempt to set negative chromaticity value");
  173423. return;
  173424. }
  173425. #ifdef PNG_FLOATING_POINT_SUPPORTED
  173426. if (white_x > (double) PNG_UINT_31_MAX ||
  173427. white_y > (double) PNG_UINT_31_MAX ||
  173428. red_x > (double) PNG_UINT_31_MAX ||
  173429. red_y > (double) PNG_UINT_31_MAX ||
  173430. green_x > (double) PNG_UINT_31_MAX ||
  173431. green_y > (double) PNG_UINT_31_MAX ||
  173432. blue_x > (double) PNG_UINT_31_MAX ||
  173433. blue_y > (double) PNG_UINT_31_MAX)
  173434. #else
  173435. if (white_x > (png_fixed_point) PNG_UINT_31_MAX/100000L ||
  173436. white_y > (png_fixed_point) PNG_UINT_31_MAX/100000L ||
  173437. red_x > (png_fixed_point) PNG_UINT_31_MAX/100000L ||
  173438. red_y > (png_fixed_point) PNG_UINT_31_MAX/100000L ||
  173439. green_x > (png_fixed_point) PNG_UINT_31_MAX/100000L ||
  173440. green_y > (png_fixed_point) PNG_UINT_31_MAX/100000L ||
  173441. blue_x > (png_fixed_point) PNG_UINT_31_MAX/100000L ||
  173442. blue_y > (png_fixed_point) PNG_UINT_31_MAX/100000L)
  173443. #endif
  173444. {
  173445. png_warning(png_ptr,
  173446. "Ignoring attempt to set chromaticity value exceeding 21474.83");
  173447. return;
  173448. }
  173449. info_ptr->int_x_white = white_x;
  173450. info_ptr->int_y_white = white_y;
  173451. info_ptr->int_x_red = red_x;
  173452. info_ptr->int_y_red = red_y;
  173453. info_ptr->int_x_green = green_x;
  173454. info_ptr->int_y_green = green_y;
  173455. info_ptr->int_x_blue = blue_x;
  173456. info_ptr->int_y_blue = blue_y;
  173457. #ifdef PNG_FLOATING_POINT_SUPPORTED
  173458. info_ptr->x_white = (float)(white_x/100000.);
  173459. info_ptr->y_white = (float)(white_y/100000.);
  173460. info_ptr->x_red = (float)( red_x/100000.);
  173461. info_ptr->y_red = (float)( red_y/100000.);
  173462. info_ptr->x_green = (float)(green_x/100000.);
  173463. info_ptr->y_green = (float)(green_y/100000.);
  173464. info_ptr->x_blue = (float)( blue_x/100000.);
  173465. info_ptr->y_blue = (float)( blue_y/100000.);
  173466. #endif
  173467. info_ptr->valid |= PNG_INFO_cHRM;
  173468. }
  173469. #endif
  173470. #endif
  173471. #if defined(PNG_gAMA_SUPPORTED)
  173472. #ifdef PNG_FLOATING_POINT_SUPPORTED
  173473. void PNGAPI
  173474. png_set_gAMA(png_structp png_ptr, png_infop info_ptr, double file_gamma)
  173475. {
  173476. double gamma;
  173477. png_debug1(1, "in %s storage function\n", "gAMA");
  173478. if (png_ptr == NULL || info_ptr == NULL)
  173479. return;
  173480. if (file_gamma > 21474.83)
  173481. {
  173482. png_warning(png_ptr, "Limiting gamma to 21474.83");
  173483. gamma=21474.83;
  173484. }
  173485. else
  173486. gamma=file_gamma;
  173487. info_ptr->gamma = (float)gamma;
  173488. #ifdef PNG_FIXED_POINT_SUPPORTED
  173489. info_ptr->int_gamma = (int)(gamma*100000.+.5);
  173490. #endif
  173491. info_ptr->valid |= PNG_INFO_gAMA;
  173492. if(gamma == 0.0)
  173493. png_warning(png_ptr, "Setting gamma=0");
  173494. }
  173495. #endif
  173496. void PNGAPI
  173497. png_set_gAMA_fixed(png_structp png_ptr, png_infop info_ptr, png_fixed_point
  173498. int_gamma)
  173499. {
  173500. png_fixed_point gamma;
  173501. png_debug1(1, "in %s storage function\n", "gAMA");
  173502. if (png_ptr == NULL || info_ptr == NULL)
  173503. return;
  173504. if (int_gamma > (png_fixed_point) PNG_UINT_31_MAX)
  173505. {
  173506. png_warning(png_ptr, "Limiting gamma to 21474.83");
  173507. gamma=PNG_UINT_31_MAX;
  173508. }
  173509. else
  173510. {
  173511. if (int_gamma < 0)
  173512. {
  173513. png_warning(png_ptr, "Setting negative gamma to zero");
  173514. gamma=0;
  173515. }
  173516. else
  173517. gamma=int_gamma;
  173518. }
  173519. #ifdef PNG_FLOATING_POINT_SUPPORTED
  173520. info_ptr->gamma = (float)(gamma/100000.);
  173521. #endif
  173522. #ifdef PNG_FIXED_POINT_SUPPORTED
  173523. info_ptr->int_gamma = gamma;
  173524. #endif
  173525. info_ptr->valid |= PNG_INFO_gAMA;
  173526. if(gamma == 0)
  173527. png_warning(png_ptr, "Setting gamma=0");
  173528. }
  173529. #endif
  173530. #if defined(PNG_hIST_SUPPORTED)
  173531. void PNGAPI
  173532. png_set_hIST(png_structp png_ptr, png_infop info_ptr, png_uint_16p hist)
  173533. {
  173534. int i;
  173535. png_debug1(1, "in %s storage function\n", "hIST");
  173536. if (png_ptr == NULL || info_ptr == NULL)
  173537. return;
  173538. if (info_ptr->num_palette == 0 || info_ptr->num_palette
  173539. > PNG_MAX_PALETTE_LENGTH)
  173540. {
  173541. png_warning(png_ptr,
  173542. "Invalid palette size, hIST allocation skipped.");
  173543. return;
  173544. }
  173545. #ifdef PNG_FREE_ME_SUPPORTED
  173546. png_free_data(png_ptr, info_ptr, PNG_FREE_HIST, 0);
  173547. #endif
  173548. png_ptr->hist = (png_uint_16p)png_malloc_warn(png_ptr,
  173549. (png_uint_32)(PNG_MAX_PALETTE_LENGTH * png_sizeof (png_uint_16)));
  173550. if (png_ptr->hist == NULL)
  173551. {
  173552. png_warning(png_ptr, "Insufficient memory for hIST chunk data.");
  173553. return;
  173554. }
  173555. for (i = 0; i < info_ptr->num_palette; i++)
  173556. png_ptr->hist[i] = hist[i];
  173557. info_ptr->hist = png_ptr->hist;
  173558. info_ptr->valid |= PNG_INFO_hIST;
  173559. #ifdef PNG_FREE_ME_SUPPORTED
  173560. info_ptr->free_me |= PNG_FREE_HIST;
  173561. #else
  173562. png_ptr->flags |= PNG_FLAG_FREE_HIST;
  173563. #endif
  173564. }
  173565. #endif
  173566. void PNGAPI
  173567. png_set_IHDR(png_structp png_ptr, png_infop info_ptr,
  173568. png_uint_32 width, png_uint_32 height, int bit_depth,
  173569. int color_type, int interlace_type, int compression_type,
  173570. int filter_type)
  173571. {
  173572. png_debug1(1, "in %s storage function\n", "IHDR");
  173573. if (png_ptr == NULL || info_ptr == NULL)
  173574. return;
  173575. if (width == 0 || height == 0)
  173576. png_error(png_ptr, "Image width or height is zero in IHDR");
  173577. #ifdef PNG_SET_USER_LIMITS_SUPPORTED
  173578. if (width > png_ptr->user_width_max || height > png_ptr->user_height_max)
  173579. png_error(png_ptr, "image size exceeds user limits in IHDR");
  173580. #else
  173581. if (width > PNG_USER_WIDTH_MAX || height > PNG_USER_HEIGHT_MAX)
  173582. png_error(png_ptr, "image size exceeds user limits in IHDR");
  173583. #endif
  173584. if (width > PNG_UINT_31_MAX || height > PNG_UINT_31_MAX)
  173585. png_error(png_ptr, "Invalid image size in IHDR");
  173586. if ( width > (PNG_UINT_32_MAX
  173587. >> 3) /* 8-byte RGBA pixels */
  173588. - 64 /* bigrowbuf hack */
  173589. - 1 /* filter byte */
  173590. - 7*8 /* rounding of width to multiple of 8 pixels */
  173591. - 8) /* extra max_pixel_depth pad */
  173592. png_warning(png_ptr, "Width is too large for libpng to process pixels");
  173593. if (bit_depth != 1 && bit_depth != 2 && bit_depth != 4 &&
  173594. bit_depth != 8 && bit_depth != 16)
  173595. png_error(png_ptr, "Invalid bit depth in IHDR");
  173596. if (color_type < 0 || color_type == 1 ||
  173597. color_type == 5 || color_type > 6)
  173598. png_error(png_ptr, "Invalid color type in IHDR");
  173599. if (((color_type == PNG_COLOR_TYPE_PALETTE) && bit_depth > 8) ||
  173600. ((color_type == PNG_COLOR_TYPE_RGB ||
  173601. color_type == PNG_COLOR_TYPE_GRAY_ALPHA ||
  173602. color_type == PNG_COLOR_TYPE_RGB_ALPHA) && bit_depth < 8))
  173603. png_error(png_ptr, "Invalid color type/bit depth combination in IHDR");
  173604. if (interlace_type >= PNG_INTERLACE_LAST)
  173605. png_error(png_ptr, "Unknown interlace method in IHDR");
  173606. if (compression_type != PNG_COMPRESSION_TYPE_BASE)
  173607. png_error(png_ptr, "Unknown compression method in IHDR");
  173608. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  173609. if((png_ptr->mode&PNG_HAVE_PNG_SIGNATURE)&&png_ptr->mng_features_permitted)
  173610. png_warning(png_ptr,"MNG features are not allowed in a PNG datastream");
  173611. if(filter_type != PNG_FILTER_TYPE_BASE)
  173612. {
  173613. if(!((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) &&
  173614. (filter_type == PNG_INTRAPIXEL_DIFFERENCING) &&
  173615. ((png_ptr->mode&PNG_HAVE_PNG_SIGNATURE) == 0) &&
  173616. (color_type == PNG_COLOR_TYPE_RGB ||
  173617. color_type == PNG_COLOR_TYPE_RGB_ALPHA)))
  173618. png_error(png_ptr, "Unknown filter method in IHDR");
  173619. if(png_ptr->mode&PNG_HAVE_PNG_SIGNATURE)
  173620. png_warning(png_ptr, "Invalid filter method in IHDR");
  173621. }
  173622. #else
  173623. if(filter_type != PNG_FILTER_TYPE_BASE)
  173624. png_error(png_ptr, "Unknown filter method in IHDR");
  173625. #endif
  173626. info_ptr->width = width;
  173627. info_ptr->height = height;
  173628. info_ptr->bit_depth = (png_byte)bit_depth;
  173629. info_ptr->color_type =(png_byte) color_type;
  173630. info_ptr->compression_type = (png_byte)compression_type;
  173631. info_ptr->filter_type = (png_byte)filter_type;
  173632. info_ptr->interlace_type = (png_byte)interlace_type;
  173633. if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  173634. info_ptr->channels = 1;
  173635. else if (info_ptr->color_type & PNG_COLOR_MASK_COLOR)
  173636. info_ptr->channels = 3;
  173637. else
  173638. info_ptr->channels = 1;
  173639. if (info_ptr->color_type & PNG_COLOR_MASK_ALPHA)
  173640. info_ptr->channels++;
  173641. info_ptr->pixel_depth = (png_byte)(info_ptr->channels * info_ptr->bit_depth);
  173642. if (width > (PNG_UINT_32_MAX
  173643. >> 3) /* 8-byte RGBA pixels */
  173644. - 64 /* bigrowbuf hack */
  173645. - 1 /* filter byte */
  173646. - 7*8 /* rounding of width to multiple of 8 pixels */
  173647. - 8) /* extra max_pixel_depth pad */
  173648. info_ptr->rowbytes = (png_size_t)0;
  173649. else
  173650. info_ptr->rowbytes = PNG_ROWBYTES(info_ptr->pixel_depth,width);
  173651. }
  173652. #if defined(PNG_oFFs_SUPPORTED)
  173653. void PNGAPI
  173654. png_set_oFFs(png_structp png_ptr, png_infop info_ptr,
  173655. png_int_32 offset_x, png_int_32 offset_y, int unit_type)
  173656. {
  173657. png_debug1(1, "in %s storage function\n", "oFFs");
  173658. if (png_ptr == NULL || info_ptr == NULL)
  173659. return;
  173660. info_ptr->x_offset = offset_x;
  173661. info_ptr->y_offset = offset_y;
  173662. info_ptr->offset_unit_type = (png_byte)unit_type;
  173663. info_ptr->valid |= PNG_INFO_oFFs;
  173664. }
  173665. #endif
  173666. #if defined(PNG_pCAL_SUPPORTED)
  173667. void PNGAPI
  173668. png_set_pCAL(png_structp png_ptr, png_infop info_ptr,
  173669. png_charp purpose, png_int_32 X0, png_int_32 X1, int type, int nparams,
  173670. png_charp units, png_charpp params)
  173671. {
  173672. png_uint_32 length;
  173673. int i;
  173674. png_debug1(1, "in %s storage function\n", "pCAL");
  173675. if (png_ptr == NULL || info_ptr == NULL)
  173676. return;
  173677. length = png_strlen(purpose) + 1;
  173678. png_debug1(3, "allocating purpose for info (%lu bytes)\n", length);
  173679. info_ptr->pcal_purpose = (png_charp)png_malloc_warn(png_ptr, length);
  173680. if (info_ptr->pcal_purpose == NULL)
  173681. {
  173682. png_warning(png_ptr, "Insufficient memory for pCAL purpose.");
  173683. return;
  173684. }
  173685. png_memcpy(info_ptr->pcal_purpose, purpose, (png_size_t)length);
  173686. png_debug(3, "storing X0, X1, type, and nparams in info\n");
  173687. info_ptr->pcal_X0 = X0;
  173688. info_ptr->pcal_X1 = X1;
  173689. info_ptr->pcal_type = (png_byte)type;
  173690. info_ptr->pcal_nparams = (png_byte)nparams;
  173691. length = png_strlen(units) + 1;
  173692. png_debug1(3, "allocating units for info (%lu bytes)\n", length);
  173693. info_ptr->pcal_units = (png_charp)png_malloc_warn(png_ptr, length);
  173694. if (info_ptr->pcal_units == NULL)
  173695. {
  173696. png_warning(png_ptr, "Insufficient memory for pCAL units.");
  173697. return;
  173698. }
  173699. png_memcpy(info_ptr->pcal_units, units, (png_size_t)length);
  173700. info_ptr->pcal_params = (png_charpp)png_malloc_warn(png_ptr,
  173701. (png_uint_32)((nparams + 1) * png_sizeof(png_charp)));
  173702. if (info_ptr->pcal_params == NULL)
  173703. {
  173704. png_warning(png_ptr, "Insufficient memory for pCAL params.");
  173705. return;
  173706. }
  173707. info_ptr->pcal_params[nparams] = NULL;
  173708. for (i = 0; i < nparams; i++)
  173709. {
  173710. length = png_strlen(params[i]) + 1;
  173711. png_debug2(3, "allocating parameter %d for info (%lu bytes)\n", i, length);
  173712. info_ptr->pcal_params[i] = (png_charp)png_malloc_warn(png_ptr, length);
  173713. if (info_ptr->pcal_params[i] == NULL)
  173714. {
  173715. png_warning(png_ptr, "Insufficient memory for pCAL parameter.");
  173716. return;
  173717. }
  173718. png_memcpy(info_ptr->pcal_params[i], params[i], (png_size_t)length);
  173719. }
  173720. info_ptr->valid |= PNG_INFO_pCAL;
  173721. #ifdef PNG_FREE_ME_SUPPORTED
  173722. info_ptr->free_me |= PNG_FREE_PCAL;
  173723. #endif
  173724. }
  173725. #endif
  173726. #if defined(PNG_READ_sCAL_SUPPORTED) || defined(PNG_WRITE_sCAL_SUPPORTED)
  173727. #ifdef PNG_FLOATING_POINT_SUPPORTED
  173728. void PNGAPI
  173729. png_set_sCAL(png_structp png_ptr, png_infop info_ptr,
  173730. int unit, double width, double height)
  173731. {
  173732. png_debug1(1, "in %s storage function\n", "sCAL");
  173733. if (png_ptr == NULL || info_ptr == NULL)
  173734. return;
  173735. info_ptr->scal_unit = (png_byte)unit;
  173736. info_ptr->scal_pixel_width = width;
  173737. info_ptr->scal_pixel_height = height;
  173738. info_ptr->valid |= PNG_INFO_sCAL;
  173739. }
  173740. #else
  173741. #ifdef PNG_FIXED_POINT_SUPPORTED
  173742. void PNGAPI
  173743. png_set_sCAL_s(png_structp png_ptr, png_infop info_ptr,
  173744. int unit, png_charp swidth, png_charp sheight)
  173745. {
  173746. png_uint_32 length;
  173747. png_debug1(1, "in %s storage function\n", "sCAL");
  173748. if (png_ptr == NULL || info_ptr == NULL)
  173749. return;
  173750. info_ptr->scal_unit = (png_byte)unit;
  173751. length = png_strlen(swidth) + 1;
  173752. png_debug1(3, "allocating unit for info (%d bytes)\n", length);
  173753. info_ptr->scal_s_width = (png_charp)png_malloc_warn(png_ptr, length);
  173754. if (info_ptr->scal_s_width == NULL)
  173755. {
  173756. png_warning(png_ptr,
  173757. "Memory allocation failed while processing sCAL.");
  173758. }
  173759. png_memcpy(info_ptr->scal_s_width, swidth, (png_size_t)length);
  173760. length = png_strlen(sheight) + 1;
  173761. png_debug1(3, "allocating unit for info (%d bytes)\n", length);
  173762. info_ptr->scal_s_height = (png_charp)png_malloc_warn(png_ptr, length);
  173763. if (info_ptr->scal_s_height == NULL)
  173764. {
  173765. png_free (png_ptr, info_ptr->scal_s_width);
  173766. png_warning(png_ptr,
  173767. "Memory allocation failed while processing sCAL.");
  173768. }
  173769. png_memcpy(info_ptr->scal_s_height, sheight, (png_size_t)length);
  173770. info_ptr->valid |= PNG_INFO_sCAL;
  173771. #ifdef PNG_FREE_ME_SUPPORTED
  173772. info_ptr->free_me |= PNG_FREE_SCAL;
  173773. #endif
  173774. }
  173775. #endif
  173776. #endif
  173777. #endif
  173778. #if defined(PNG_pHYs_SUPPORTED)
  173779. void PNGAPI
  173780. png_set_pHYs(png_structp png_ptr, png_infop info_ptr,
  173781. png_uint_32 res_x, png_uint_32 res_y, int unit_type)
  173782. {
  173783. png_debug1(1, "in %s storage function\n", "pHYs");
  173784. if (png_ptr == NULL || info_ptr == NULL)
  173785. return;
  173786. info_ptr->x_pixels_per_unit = res_x;
  173787. info_ptr->y_pixels_per_unit = res_y;
  173788. info_ptr->phys_unit_type = (png_byte)unit_type;
  173789. info_ptr->valid |= PNG_INFO_pHYs;
  173790. }
  173791. #endif
  173792. void PNGAPI
  173793. png_set_PLTE(png_structp png_ptr, png_infop info_ptr,
  173794. png_colorp palette, int num_palette)
  173795. {
  173796. png_debug1(1, "in %s storage function\n", "PLTE");
  173797. if (png_ptr == NULL || info_ptr == NULL)
  173798. return;
  173799. if (num_palette < 0 || num_palette > PNG_MAX_PALETTE_LENGTH)
  173800. {
  173801. if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  173802. png_error(png_ptr, "Invalid palette length");
  173803. else
  173804. {
  173805. png_warning(png_ptr, "Invalid palette length");
  173806. return;
  173807. }
  173808. }
  173809. #ifdef PNG_FREE_ME_SUPPORTED
  173810. png_free_data(png_ptr, info_ptr, PNG_FREE_PLTE, 0);
  173811. #endif
  173812. png_ptr->palette = (png_colorp)png_malloc(png_ptr,
  173813. PNG_MAX_PALETTE_LENGTH * png_sizeof(png_color));
  173814. png_memset(png_ptr->palette, 0, PNG_MAX_PALETTE_LENGTH *
  173815. png_sizeof(png_color));
  173816. png_memcpy(png_ptr->palette, palette, num_palette * png_sizeof (png_color));
  173817. info_ptr->palette = png_ptr->palette;
  173818. info_ptr->num_palette = png_ptr->num_palette = (png_uint_16)num_palette;
  173819. #ifdef PNG_FREE_ME_SUPPORTED
  173820. info_ptr->free_me |= PNG_FREE_PLTE;
  173821. #else
  173822. png_ptr->flags |= PNG_FLAG_FREE_PLTE;
  173823. #endif
  173824. info_ptr->valid |= PNG_INFO_PLTE;
  173825. }
  173826. #if defined(PNG_sBIT_SUPPORTED)
  173827. void PNGAPI
  173828. png_set_sBIT(png_structp png_ptr, png_infop info_ptr,
  173829. png_color_8p sig_bit)
  173830. {
  173831. png_debug1(1, "in %s storage function\n", "sBIT");
  173832. if (png_ptr == NULL || info_ptr == NULL)
  173833. return;
  173834. png_memcpy(&(info_ptr->sig_bit), sig_bit, png_sizeof (png_color_8));
  173835. info_ptr->valid |= PNG_INFO_sBIT;
  173836. }
  173837. #endif
  173838. #if defined(PNG_sRGB_SUPPORTED)
  173839. void PNGAPI
  173840. png_set_sRGB(png_structp png_ptr, png_infop info_ptr, int intent)
  173841. {
  173842. png_debug1(1, "in %s storage function\n", "sRGB");
  173843. if (png_ptr == NULL || info_ptr == NULL)
  173844. return;
  173845. info_ptr->srgb_intent = (png_byte)intent;
  173846. info_ptr->valid |= PNG_INFO_sRGB;
  173847. }
  173848. void PNGAPI
  173849. png_set_sRGB_gAMA_and_cHRM(png_structp png_ptr, png_infop info_ptr,
  173850. int intent)
  173851. {
  173852. #if defined(PNG_gAMA_SUPPORTED)
  173853. #ifdef PNG_FLOATING_POINT_SUPPORTED
  173854. float file_gamma;
  173855. #endif
  173856. #ifdef PNG_FIXED_POINT_SUPPORTED
  173857. png_fixed_point int_file_gamma;
  173858. #endif
  173859. #endif
  173860. #if defined(PNG_cHRM_SUPPORTED)
  173861. #ifdef PNG_FLOATING_POINT_SUPPORTED
  173862. float white_x, white_y, red_x, red_y, green_x, green_y, blue_x, blue_y;
  173863. #endif
  173864. #ifdef PNG_FIXED_POINT_SUPPORTED
  173865. png_fixed_point int_white_x, int_white_y, int_red_x, int_red_y, int_green_x,
  173866. int_green_y, int_blue_x, int_blue_y;
  173867. #endif
  173868. #endif
  173869. png_debug1(1, "in %s storage function\n", "sRGB_gAMA_and_cHRM");
  173870. if (png_ptr == NULL || info_ptr == NULL)
  173871. return;
  173872. png_set_sRGB(png_ptr, info_ptr, intent);
  173873. #if defined(PNG_gAMA_SUPPORTED)
  173874. #ifdef PNG_FLOATING_POINT_SUPPORTED
  173875. file_gamma = (float).45455;
  173876. png_set_gAMA(png_ptr, info_ptr, file_gamma);
  173877. #endif
  173878. #ifdef PNG_FIXED_POINT_SUPPORTED
  173879. int_file_gamma = 45455L;
  173880. png_set_gAMA_fixed(png_ptr, info_ptr, int_file_gamma);
  173881. #endif
  173882. #endif
  173883. #if defined(PNG_cHRM_SUPPORTED)
  173884. #ifdef PNG_FIXED_POINT_SUPPORTED
  173885. int_white_x = 31270L;
  173886. int_white_y = 32900L;
  173887. int_red_x = 64000L;
  173888. int_red_y = 33000L;
  173889. int_green_x = 30000L;
  173890. int_green_y = 60000L;
  173891. int_blue_x = 15000L;
  173892. int_blue_y = 6000L;
  173893. png_set_cHRM_fixed(png_ptr, info_ptr,
  173894. int_white_x, int_white_y, int_red_x, int_red_y, int_green_x, int_green_y,
  173895. int_blue_x, int_blue_y);
  173896. #endif
  173897. #ifdef PNG_FLOATING_POINT_SUPPORTED
  173898. white_x = (float).3127;
  173899. white_y = (float).3290;
  173900. red_x = (float).64;
  173901. red_y = (float).33;
  173902. green_x = (float).30;
  173903. green_y = (float).60;
  173904. blue_x = (float).15;
  173905. blue_y = (float).06;
  173906. png_set_cHRM(png_ptr, info_ptr,
  173907. white_x, white_y, red_x, red_y, green_x, green_y, blue_x, blue_y);
  173908. #endif
  173909. #endif
  173910. }
  173911. #endif
  173912. #if defined(PNG_iCCP_SUPPORTED)
  173913. void PNGAPI
  173914. png_set_iCCP(png_structp png_ptr, png_infop info_ptr,
  173915. png_charp name, int compression_type,
  173916. png_charp profile, png_uint_32 proflen)
  173917. {
  173918. png_charp new_iccp_name;
  173919. png_charp new_iccp_profile;
  173920. png_debug1(1, "in %s storage function\n", "iCCP");
  173921. if (png_ptr == NULL || info_ptr == NULL || name == NULL || profile == NULL)
  173922. return;
  173923. new_iccp_name = (png_charp)png_malloc_warn(png_ptr, png_strlen(name)+1);
  173924. if (new_iccp_name == NULL)
  173925. {
  173926. png_warning(png_ptr, "Insufficient memory to process iCCP chunk.");
  173927. return;
  173928. }
  173929. png_strncpy(new_iccp_name, name, png_strlen(name)+1);
  173930. new_iccp_profile = (png_charp)png_malloc_warn(png_ptr, proflen);
  173931. if (new_iccp_profile == NULL)
  173932. {
  173933. png_free (png_ptr, new_iccp_name);
  173934. png_warning(png_ptr, "Insufficient memory to process iCCP profile.");
  173935. return;
  173936. }
  173937. png_memcpy(new_iccp_profile, profile, (png_size_t)proflen);
  173938. png_free_data(png_ptr, info_ptr, PNG_FREE_ICCP, 0);
  173939. info_ptr->iccp_proflen = proflen;
  173940. info_ptr->iccp_name = new_iccp_name;
  173941. info_ptr->iccp_profile = new_iccp_profile;
  173942. info_ptr->iccp_compression = (png_byte)compression_type;
  173943. #ifdef PNG_FREE_ME_SUPPORTED
  173944. info_ptr->free_me |= PNG_FREE_ICCP;
  173945. #endif
  173946. info_ptr->valid |= PNG_INFO_iCCP;
  173947. }
  173948. #endif
  173949. #if defined(PNG_TEXT_SUPPORTED)
  173950. void PNGAPI
  173951. png_set_text(png_structp png_ptr, png_infop info_ptr, png_textp text_ptr,
  173952. int num_text)
  173953. {
  173954. int ret;
  173955. ret=png_set_text_2(png_ptr, info_ptr, text_ptr, num_text);
  173956. if (ret)
  173957. png_error(png_ptr, "Insufficient memory to store text");
  173958. }
  173959. int /* PRIVATE */
  173960. png_set_text_2(png_structp png_ptr, png_infop info_ptr, png_textp text_ptr,
  173961. int num_text)
  173962. {
  173963. int i;
  173964. png_debug1(1, "in %s storage function\n", (png_ptr->chunk_name[0] == '\0' ?
  173965. "text" : (png_const_charp)png_ptr->chunk_name));
  173966. if (png_ptr == NULL || info_ptr == NULL || num_text == 0)
  173967. return(0);
  173968. if (info_ptr->num_text + num_text > info_ptr->max_text)
  173969. {
  173970. if (info_ptr->text != NULL)
  173971. {
  173972. png_textp old_text;
  173973. int old_max;
  173974. old_max = info_ptr->max_text;
  173975. info_ptr->max_text = info_ptr->num_text + num_text + 8;
  173976. old_text = info_ptr->text;
  173977. info_ptr->text = (png_textp)png_malloc_warn(png_ptr,
  173978. (png_uint_32)(info_ptr->max_text * png_sizeof (png_text)));
  173979. if (info_ptr->text == NULL)
  173980. {
  173981. png_free(png_ptr, old_text);
  173982. return(1);
  173983. }
  173984. png_memcpy(info_ptr->text, old_text, (png_size_t)(old_max *
  173985. png_sizeof(png_text)));
  173986. png_free(png_ptr, old_text);
  173987. }
  173988. else
  173989. {
  173990. info_ptr->max_text = num_text + 8;
  173991. info_ptr->num_text = 0;
  173992. info_ptr->text = (png_textp)png_malloc_warn(png_ptr,
  173993. (png_uint_32)(info_ptr->max_text * png_sizeof (png_text)));
  173994. if (info_ptr->text == NULL)
  173995. return(1);
  173996. #ifdef PNG_FREE_ME_SUPPORTED
  173997. info_ptr->free_me |= PNG_FREE_TEXT;
  173998. #endif
  173999. }
  174000. png_debug1(3, "allocated %d entries for info_ptr->text\n",
  174001. info_ptr->max_text);
  174002. }
  174003. for (i = 0; i < num_text; i++)
  174004. {
  174005. png_size_t text_length,key_len;
  174006. png_size_t lang_len,lang_key_len;
  174007. png_textp textp = &(info_ptr->text[info_ptr->num_text]);
  174008. if (text_ptr[i].key == NULL)
  174009. continue;
  174010. key_len = png_strlen(text_ptr[i].key);
  174011. if(text_ptr[i].compression <= 0)
  174012. {
  174013. lang_len = 0;
  174014. lang_key_len = 0;
  174015. }
  174016. else
  174017. #ifdef PNG_iTXt_SUPPORTED
  174018. {
  174019. if (text_ptr[i].lang != NULL)
  174020. lang_len = png_strlen(text_ptr[i].lang);
  174021. else
  174022. lang_len = 0;
  174023. if (text_ptr[i].lang_key != NULL)
  174024. lang_key_len = png_strlen(text_ptr[i].lang_key);
  174025. else
  174026. lang_key_len = 0;
  174027. }
  174028. #else
  174029. {
  174030. png_warning(png_ptr, "iTXt chunk not supported.");
  174031. continue;
  174032. }
  174033. #endif
  174034. if (text_ptr[i].text == NULL || text_ptr[i].text[0] == '\0')
  174035. {
  174036. text_length = 0;
  174037. #ifdef PNG_iTXt_SUPPORTED
  174038. if(text_ptr[i].compression > 0)
  174039. textp->compression = PNG_ITXT_COMPRESSION_NONE;
  174040. else
  174041. #endif
  174042. textp->compression = PNG_TEXT_COMPRESSION_NONE;
  174043. }
  174044. else
  174045. {
  174046. text_length = png_strlen(text_ptr[i].text);
  174047. textp->compression = text_ptr[i].compression;
  174048. }
  174049. textp->key = (png_charp)png_malloc_warn(png_ptr,
  174050. (png_uint_32)(key_len + text_length + lang_len + lang_key_len + 4));
  174051. if (textp->key == NULL)
  174052. return(1);
  174053. png_debug2(2, "Allocated %lu bytes at %x in png_set_text\n",
  174054. (png_uint_32)(key_len + lang_len + lang_key_len + text_length + 4),
  174055. (int)textp->key);
  174056. png_memcpy(textp->key, text_ptr[i].key,
  174057. (png_size_t)(key_len));
  174058. *(textp->key+key_len) = '\0';
  174059. #ifdef PNG_iTXt_SUPPORTED
  174060. if (text_ptr[i].compression > 0)
  174061. {
  174062. textp->lang=textp->key + key_len + 1;
  174063. png_memcpy(textp->lang, text_ptr[i].lang, lang_len);
  174064. *(textp->lang+lang_len) = '\0';
  174065. textp->lang_key=textp->lang + lang_len + 1;
  174066. png_memcpy(textp->lang_key, text_ptr[i].lang_key, lang_key_len);
  174067. *(textp->lang_key+lang_key_len) = '\0';
  174068. textp->text=textp->lang_key + lang_key_len + 1;
  174069. }
  174070. else
  174071. #endif
  174072. {
  174073. #ifdef PNG_iTXt_SUPPORTED
  174074. textp->lang=NULL;
  174075. textp->lang_key=NULL;
  174076. #endif
  174077. textp->text=textp->key + key_len + 1;
  174078. }
  174079. if(text_length)
  174080. png_memcpy(textp->text, text_ptr[i].text,
  174081. (png_size_t)(text_length));
  174082. *(textp->text+text_length) = '\0';
  174083. #ifdef PNG_iTXt_SUPPORTED
  174084. if(textp->compression > 0)
  174085. {
  174086. textp->text_length = 0;
  174087. textp->itxt_length = text_length;
  174088. }
  174089. else
  174090. #endif
  174091. {
  174092. textp->text_length = text_length;
  174093. #ifdef PNG_iTXt_SUPPORTED
  174094. textp->itxt_length = 0;
  174095. #endif
  174096. }
  174097. info_ptr->num_text++;
  174098. png_debug1(3, "transferred text chunk %d\n", info_ptr->num_text);
  174099. }
  174100. return(0);
  174101. }
  174102. #endif
  174103. #if defined(PNG_tIME_SUPPORTED)
  174104. void PNGAPI
  174105. png_set_tIME(png_structp png_ptr, png_infop info_ptr, png_timep mod_time)
  174106. {
  174107. png_debug1(1, "in %s storage function\n", "tIME");
  174108. if (png_ptr == NULL || info_ptr == NULL ||
  174109. (png_ptr->mode & PNG_WROTE_tIME))
  174110. return;
  174111. png_memcpy(&(info_ptr->mod_time), mod_time, png_sizeof (png_time));
  174112. info_ptr->valid |= PNG_INFO_tIME;
  174113. }
  174114. #endif
  174115. #if defined(PNG_tRNS_SUPPORTED)
  174116. void PNGAPI
  174117. png_set_tRNS(png_structp png_ptr, png_infop info_ptr,
  174118. png_bytep trans, int num_trans, png_color_16p trans_values)
  174119. {
  174120. png_debug1(1, "in %s storage function\n", "tRNS");
  174121. if (png_ptr == NULL || info_ptr == NULL)
  174122. return;
  174123. if (trans != NULL)
  174124. {
  174125. #ifdef PNG_FREE_ME_SUPPORTED
  174126. png_free_data(png_ptr, info_ptr, PNG_FREE_TRNS, 0);
  174127. #endif
  174128. png_ptr->trans = info_ptr->trans = (png_bytep)png_malloc(png_ptr,
  174129. (png_uint_32)PNG_MAX_PALETTE_LENGTH);
  174130. if (num_trans <= PNG_MAX_PALETTE_LENGTH)
  174131. png_memcpy(info_ptr->trans, trans, (png_size_t)num_trans);
  174132. #ifdef PNG_FREE_ME_SUPPORTED
  174133. info_ptr->free_me |= PNG_FREE_TRNS;
  174134. #else
  174135. png_ptr->flags |= PNG_FLAG_FREE_TRNS;
  174136. #endif
  174137. }
  174138. if (trans_values != NULL)
  174139. {
  174140. png_memcpy(&(info_ptr->trans_values), trans_values,
  174141. png_sizeof(png_color_16));
  174142. if (num_trans == 0)
  174143. num_trans = 1;
  174144. }
  174145. info_ptr->num_trans = (png_uint_16)num_trans;
  174146. info_ptr->valid |= PNG_INFO_tRNS;
  174147. }
  174148. #endif
  174149. #if defined(PNG_sPLT_SUPPORTED)
  174150. void PNGAPI
  174151. png_set_sPLT(png_structp png_ptr,
  174152. png_infop info_ptr, png_sPLT_tp entries, int nentries)
  174153. {
  174154. png_sPLT_tp np;
  174155. int i;
  174156. if (png_ptr == NULL || info_ptr == NULL)
  174157. return;
  174158. np = (png_sPLT_tp)png_malloc_warn(png_ptr,
  174159. (info_ptr->splt_palettes_num + nentries) * png_sizeof(png_sPLT_t));
  174160. if (np == NULL)
  174161. {
  174162. png_warning(png_ptr, "No memory for sPLT palettes.");
  174163. return;
  174164. }
  174165. png_memcpy(np, info_ptr->splt_palettes,
  174166. info_ptr->splt_palettes_num * png_sizeof(png_sPLT_t));
  174167. png_free(png_ptr, info_ptr->splt_palettes);
  174168. info_ptr->splt_palettes=NULL;
  174169. for (i = 0; i < nentries; i++)
  174170. {
  174171. png_sPLT_tp to = np + info_ptr->splt_palettes_num + i;
  174172. png_sPLT_tp from = entries + i;
  174173. to->name = (png_charp)png_malloc_warn(png_ptr,
  174174. png_strlen(from->name) + 1);
  174175. if (to->name == NULL)
  174176. {
  174177. png_warning(png_ptr,
  174178. "Out of memory while processing sPLT chunk");
  174179. }
  174180. png_strncpy(to->name, from->name, png_strlen(from->name)+1);
  174181. to->entries = (png_sPLT_entryp)png_malloc_warn(png_ptr,
  174182. from->nentries * png_sizeof(png_sPLT_entry));
  174183. png_memcpy(to->entries, from->entries,
  174184. from->nentries * png_sizeof(png_sPLT_entry));
  174185. if (to->entries == NULL)
  174186. {
  174187. png_warning(png_ptr,
  174188. "Out of memory while processing sPLT chunk");
  174189. png_free(png_ptr,to->name);
  174190. to->name = NULL;
  174191. }
  174192. to->nentries = from->nentries;
  174193. to->depth = from->depth;
  174194. }
  174195. info_ptr->splt_palettes = np;
  174196. info_ptr->splt_palettes_num += nentries;
  174197. info_ptr->valid |= PNG_INFO_sPLT;
  174198. #ifdef PNG_FREE_ME_SUPPORTED
  174199. info_ptr->free_me |= PNG_FREE_SPLT;
  174200. #endif
  174201. }
  174202. #endif /* PNG_sPLT_SUPPORTED */
  174203. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  174204. void PNGAPI
  174205. png_set_unknown_chunks(png_structp png_ptr,
  174206. png_infop info_ptr, png_unknown_chunkp unknowns, int num_unknowns)
  174207. {
  174208. png_unknown_chunkp np;
  174209. int i;
  174210. if (png_ptr == NULL || info_ptr == NULL || num_unknowns == 0)
  174211. return;
  174212. np = (png_unknown_chunkp)png_malloc_warn(png_ptr,
  174213. (info_ptr->unknown_chunks_num + num_unknowns) *
  174214. png_sizeof(png_unknown_chunk));
  174215. if (np == NULL)
  174216. {
  174217. png_warning(png_ptr,
  174218. "Out of memory while processing unknown chunk.");
  174219. return;
  174220. }
  174221. png_memcpy(np, info_ptr->unknown_chunks,
  174222. info_ptr->unknown_chunks_num * png_sizeof(png_unknown_chunk));
  174223. png_free(png_ptr, info_ptr->unknown_chunks);
  174224. info_ptr->unknown_chunks=NULL;
  174225. for (i = 0; i < num_unknowns; i++)
  174226. {
  174227. png_unknown_chunkp to = np + info_ptr->unknown_chunks_num + i;
  174228. png_unknown_chunkp from = unknowns + i;
  174229. png_strncpy((png_charp)to->name, (png_charp)from->name, 5);
  174230. to->data = (png_bytep)png_malloc_warn(png_ptr, from->size);
  174231. if (to->data == NULL)
  174232. {
  174233. png_warning(png_ptr,
  174234. "Out of memory while processing unknown chunk.");
  174235. }
  174236. else
  174237. {
  174238. png_memcpy(to->data, from->data, from->size);
  174239. to->size = from->size;
  174240. to->location = (png_byte)(png_ptr->mode & 0xff);
  174241. }
  174242. }
  174243. info_ptr->unknown_chunks = np;
  174244. info_ptr->unknown_chunks_num += num_unknowns;
  174245. #ifdef PNG_FREE_ME_SUPPORTED
  174246. info_ptr->free_me |= PNG_FREE_UNKN;
  174247. #endif
  174248. }
  174249. void PNGAPI
  174250. png_set_unknown_chunk_location(png_structp png_ptr, png_infop info_ptr,
  174251. int chunk, int location)
  174252. {
  174253. if(png_ptr != NULL && info_ptr != NULL && chunk >= 0 && chunk <
  174254. (int)info_ptr->unknown_chunks_num)
  174255. info_ptr->unknown_chunks[chunk].location = (png_byte)location;
  174256. }
  174257. #endif
  174258. #if defined(PNG_1_0_X) || defined(PNG_1_2_X)
  174259. #if defined(PNG_READ_EMPTY_PLTE_SUPPORTED) || \
  174260. defined(PNG_WRITE_EMPTY_PLTE_SUPPORTED)
  174261. void PNGAPI
  174262. png_permit_empty_plte (png_structp png_ptr, int empty_plte_permitted)
  174263. {
  174264. png_debug(1, "in png_permit_empty_plte, DEPRECATED.\n");
  174265. if (png_ptr == NULL)
  174266. return;
  174267. png_ptr->mng_features_permitted = (png_byte)
  174268. ((png_ptr->mng_features_permitted & (~(PNG_FLAG_MNG_EMPTY_PLTE))) |
  174269. ((empty_plte_permitted & PNG_FLAG_MNG_EMPTY_PLTE)));
  174270. }
  174271. #endif
  174272. #endif
  174273. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  174274. png_uint_32 PNGAPI
  174275. png_permit_mng_features (png_structp png_ptr, png_uint_32 mng_features)
  174276. {
  174277. png_debug(1, "in png_permit_mng_features\n");
  174278. if (png_ptr == NULL)
  174279. return (png_uint_32)0;
  174280. png_ptr->mng_features_permitted =
  174281. (png_byte)(mng_features & PNG_ALL_MNG_FEATURES);
  174282. return (png_uint_32)png_ptr->mng_features_permitted;
  174283. }
  174284. #endif
  174285. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  174286. void PNGAPI
  174287. png_set_keep_unknown_chunks(png_structp png_ptr, int keep, png_bytep
  174288. chunk_list, int num_chunks)
  174289. {
  174290. png_bytep new_list, p;
  174291. int i, old_num_chunks;
  174292. if (png_ptr == NULL)
  174293. return;
  174294. if (num_chunks == 0)
  174295. {
  174296. if(keep == PNG_HANDLE_CHUNK_ALWAYS || keep == PNG_HANDLE_CHUNK_IF_SAFE)
  174297. png_ptr->flags |= PNG_FLAG_KEEP_UNKNOWN_CHUNKS;
  174298. else
  174299. png_ptr->flags &= ~PNG_FLAG_KEEP_UNKNOWN_CHUNKS;
  174300. if(keep == PNG_HANDLE_CHUNK_ALWAYS)
  174301. png_ptr->flags |= PNG_FLAG_KEEP_UNSAFE_CHUNKS;
  174302. else
  174303. png_ptr->flags &= ~PNG_FLAG_KEEP_UNSAFE_CHUNKS;
  174304. return;
  174305. }
  174306. if (chunk_list == NULL)
  174307. return;
  174308. old_num_chunks=png_ptr->num_chunk_list;
  174309. new_list=(png_bytep)png_malloc(png_ptr,
  174310. (png_uint_32)(5*(num_chunks+old_num_chunks)));
  174311. if(png_ptr->chunk_list != NULL)
  174312. {
  174313. png_memcpy(new_list, png_ptr->chunk_list,
  174314. (png_size_t)(5*old_num_chunks));
  174315. png_free(png_ptr, png_ptr->chunk_list);
  174316. png_ptr->chunk_list=NULL;
  174317. }
  174318. png_memcpy(new_list+5*old_num_chunks, chunk_list,
  174319. (png_size_t)(5*num_chunks));
  174320. for (p=new_list+5*old_num_chunks+4, i=0; i<num_chunks; i++, p+=5)
  174321. *p=(png_byte)keep;
  174322. png_ptr->num_chunk_list=old_num_chunks+num_chunks;
  174323. png_ptr->chunk_list=new_list;
  174324. #ifdef PNG_FREE_ME_SUPPORTED
  174325. png_ptr->free_me |= PNG_FREE_LIST;
  174326. #endif
  174327. }
  174328. #endif
  174329. #if defined(PNG_READ_USER_CHUNKS_SUPPORTED)
  174330. void PNGAPI
  174331. png_set_read_user_chunk_fn(png_structp png_ptr, png_voidp user_chunk_ptr,
  174332. png_user_chunk_ptr read_user_chunk_fn)
  174333. {
  174334. png_debug(1, "in png_set_read_user_chunk_fn\n");
  174335. if (png_ptr == NULL)
  174336. return;
  174337. png_ptr->read_user_chunk_fn = read_user_chunk_fn;
  174338. png_ptr->user_chunk_ptr = user_chunk_ptr;
  174339. }
  174340. #endif
  174341. #if defined(PNG_INFO_IMAGE_SUPPORTED)
  174342. void PNGAPI
  174343. png_set_rows(png_structp png_ptr, png_infop info_ptr, png_bytepp row_pointers)
  174344. {
  174345. png_debug1(1, "in %s storage function\n", "rows");
  174346. if (png_ptr == NULL || info_ptr == NULL)
  174347. return;
  174348. if(info_ptr->row_pointers && (info_ptr->row_pointers != row_pointers))
  174349. png_free_data(png_ptr, info_ptr, PNG_FREE_ROWS, 0);
  174350. info_ptr->row_pointers = row_pointers;
  174351. if(row_pointers)
  174352. info_ptr->valid |= PNG_INFO_IDAT;
  174353. }
  174354. #endif
  174355. #ifdef PNG_WRITE_SUPPORTED
  174356. void PNGAPI
  174357. png_set_compression_buffer_size(png_structp png_ptr, png_uint_32 size)
  174358. {
  174359. if (png_ptr == NULL)
  174360. return;
  174361. if(png_ptr->zbuf)
  174362. png_free(png_ptr, png_ptr->zbuf);
  174363. png_ptr->zbuf_size = (png_size_t)size;
  174364. png_ptr->zbuf = (png_bytep)png_malloc(png_ptr, size);
  174365. png_ptr->zstream.next_out = png_ptr->zbuf;
  174366. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  174367. }
  174368. #endif
  174369. void PNGAPI
  174370. png_set_invalid(png_structp png_ptr, png_infop info_ptr, int mask)
  174371. {
  174372. if (png_ptr && info_ptr)
  174373. info_ptr->valid &= ~(mask);
  174374. }
  174375. #ifndef PNG_1_0_X
  174376. #ifdef PNG_ASSEMBLER_CODE_SUPPORTED
  174377. void PNGAPI
  174378. png_set_asm_flags (png_structp png_ptr, png_uint_32 asm_flags)
  174379. {
  174380. if (png_ptr != NULL)
  174381. png_ptr->asm_flags = 0;
  174382. }
  174383. void PNGAPI
  174384. png_set_mmx_thresholds (png_structp png_ptr,
  174385. png_byte mmx_bitdepth_threshold,
  174386. png_uint_32 mmx_rowbytes_threshold)
  174387. {
  174388. if (png_ptr == NULL)
  174389. return;
  174390. }
  174391. #endif /* ?PNG_ASSEMBLER_CODE_SUPPORTED */
  174392. #ifdef PNG_SET_USER_LIMITS_SUPPORTED
  174393. void PNGAPI
  174394. png_set_user_limits (png_structp png_ptr, png_uint_32 user_width_max,
  174395. png_uint_32 user_height_max)
  174396. {
  174397. if(png_ptr == NULL) return;
  174398. png_ptr->user_width_max = user_width_max;
  174399. png_ptr->user_height_max = user_height_max;
  174400. }
  174401. #endif /* ?PNG_SET_USER_LIMITS_SUPPORTED */
  174402. #endif /* ?PNG_1_0_X */
  174403. #endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */
  174404. /*** End of inlined file: pngset.c ***/
  174405. /*** Start of inlined file: pngtrans.c ***/
  174406. #define PNG_INTERNAL
  174407. #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
  174408. #if defined(PNG_READ_BGR_SUPPORTED) || defined(PNG_WRITE_BGR_SUPPORTED)
  174409. void PNGAPI
  174410. png_set_bgr(png_structp png_ptr)
  174411. {
  174412. png_debug(1, "in png_set_bgr\n");
  174413. if(png_ptr == NULL) return;
  174414. png_ptr->transformations |= PNG_BGR;
  174415. }
  174416. #endif
  174417. #if defined(PNG_READ_SWAP_SUPPORTED) || defined(PNG_WRITE_SWAP_SUPPORTED)
  174418. void PNGAPI
  174419. png_set_swap(png_structp png_ptr)
  174420. {
  174421. png_debug(1, "in png_set_swap\n");
  174422. if(png_ptr == NULL) return;
  174423. if (png_ptr->bit_depth == 16)
  174424. png_ptr->transformations |= PNG_SWAP_BYTES;
  174425. }
  174426. #endif
  174427. #if defined(PNG_READ_PACK_SUPPORTED) || defined(PNG_WRITE_PACK_SUPPORTED)
  174428. void PNGAPI
  174429. png_set_packing(png_structp png_ptr)
  174430. {
  174431. png_debug(1, "in png_set_packing\n");
  174432. if(png_ptr == NULL) return;
  174433. if (png_ptr->bit_depth < 8)
  174434. {
  174435. png_ptr->transformations |= PNG_PACK;
  174436. png_ptr->usr_bit_depth = 8;
  174437. }
  174438. }
  174439. #endif
  174440. #if defined(PNG_READ_PACKSWAP_SUPPORTED)||defined(PNG_WRITE_PACKSWAP_SUPPORTED)
  174441. void PNGAPI
  174442. png_set_packswap(png_structp png_ptr)
  174443. {
  174444. png_debug(1, "in png_set_packswap\n");
  174445. if(png_ptr == NULL) return;
  174446. if (png_ptr->bit_depth < 8)
  174447. png_ptr->transformations |= PNG_PACKSWAP;
  174448. }
  174449. #endif
  174450. #if defined(PNG_READ_SHIFT_SUPPORTED) || defined(PNG_WRITE_SHIFT_SUPPORTED)
  174451. void PNGAPI
  174452. png_set_shift(png_structp png_ptr, png_color_8p true_bits)
  174453. {
  174454. png_debug(1, "in png_set_shift\n");
  174455. if(png_ptr == NULL) return;
  174456. png_ptr->transformations |= PNG_SHIFT;
  174457. png_ptr->shift = *true_bits;
  174458. }
  174459. #endif
  174460. #if defined(PNG_READ_INTERLACING_SUPPORTED) || \
  174461. defined(PNG_WRITE_INTERLACING_SUPPORTED)
  174462. int PNGAPI
  174463. png_set_interlace_handling(png_structp png_ptr)
  174464. {
  174465. png_debug(1, "in png_set_interlace handling\n");
  174466. if (png_ptr && png_ptr->interlaced)
  174467. {
  174468. png_ptr->transformations |= PNG_INTERLACE;
  174469. return (7);
  174470. }
  174471. return (1);
  174472. }
  174473. #endif
  174474. #if defined(PNG_READ_FILLER_SUPPORTED) || defined(PNG_WRITE_FILLER_SUPPORTED)
  174475. void PNGAPI
  174476. png_set_filler(png_structp png_ptr, png_uint_32 filler, int filler_loc)
  174477. {
  174478. png_debug(1, "in png_set_filler\n");
  174479. if(png_ptr == NULL) return;
  174480. png_ptr->transformations |= PNG_FILLER;
  174481. png_ptr->filler = (png_byte)filler;
  174482. if (filler_loc == PNG_FILLER_AFTER)
  174483. png_ptr->flags |= PNG_FLAG_FILLER_AFTER;
  174484. else
  174485. png_ptr->flags &= ~PNG_FLAG_FILLER_AFTER;
  174486. if (png_ptr->color_type == PNG_COLOR_TYPE_RGB)
  174487. {
  174488. png_ptr->usr_channels = 4;
  174489. }
  174490. if (png_ptr->color_type == PNG_COLOR_TYPE_GRAY && png_ptr->bit_depth >= 8)
  174491. {
  174492. png_ptr->usr_channels = 2;
  174493. }
  174494. }
  174495. #if !defined(PNG_1_0_X)
  174496. void PNGAPI
  174497. png_set_add_alpha(png_structp png_ptr, png_uint_32 filler, int filler_loc)
  174498. {
  174499. png_debug(1, "in png_set_add_alpha\n");
  174500. if(png_ptr == NULL) return;
  174501. png_set_filler(png_ptr, filler, filler_loc);
  174502. png_ptr->transformations |= PNG_ADD_ALPHA;
  174503. }
  174504. #endif
  174505. #endif
  174506. #if defined(PNG_READ_SWAP_ALPHA_SUPPORTED) || \
  174507. defined(PNG_WRITE_SWAP_ALPHA_SUPPORTED)
  174508. void PNGAPI
  174509. png_set_swap_alpha(png_structp png_ptr)
  174510. {
  174511. png_debug(1, "in png_set_swap_alpha\n");
  174512. if(png_ptr == NULL) return;
  174513. png_ptr->transformations |= PNG_SWAP_ALPHA;
  174514. }
  174515. #endif
  174516. #if defined(PNG_READ_INVERT_ALPHA_SUPPORTED) || \
  174517. defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED)
  174518. void PNGAPI
  174519. png_set_invert_alpha(png_structp png_ptr)
  174520. {
  174521. png_debug(1, "in png_set_invert_alpha\n");
  174522. if(png_ptr == NULL) return;
  174523. png_ptr->transformations |= PNG_INVERT_ALPHA;
  174524. }
  174525. #endif
  174526. #if defined(PNG_READ_INVERT_SUPPORTED) || defined(PNG_WRITE_INVERT_SUPPORTED)
  174527. void PNGAPI
  174528. png_set_invert_mono(png_structp png_ptr)
  174529. {
  174530. png_debug(1, "in png_set_invert_mono\n");
  174531. if(png_ptr == NULL) return;
  174532. png_ptr->transformations |= PNG_INVERT_MONO;
  174533. }
  174534. void /* PRIVATE */
  174535. png_do_invert(png_row_infop row_info, png_bytep row)
  174536. {
  174537. png_debug(1, "in png_do_invert\n");
  174538. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  174539. if (row == NULL || row_info == NULL)
  174540. return;
  174541. #endif
  174542. if (row_info->color_type == PNG_COLOR_TYPE_GRAY)
  174543. {
  174544. png_bytep rp = row;
  174545. png_uint_32 i;
  174546. png_uint_32 istop = row_info->rowbytes;
  174547. for (i = 0; i < istop; i++)
  174548. {
  174549. *rp = (png_byte)(~(*rp));
  174550. rp++;
  174551. }
  174552. }
  174553. else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA &&
  174554. row_info->bit_depth == 8)
  174555. {
  174556. png_bytep rp = row;
  174557. png_uint_32 i;
  174558. png_uint_32 istop = row_info->rowbytes;
  174559. for (i = 0; i < istop; i+=2)
  174560. {
  174561. *rp = (png_byte)(~(*rp));
  174562. rp+=2;
  174563. }
  174564. }
  174565. else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA &&
  174566. row_info->bit_depth == 16)
  174567. {
  174568. png_bytep rp = row;
  174569. png_uint_32 i;
  174570. png_uint_32 istop = row_info->rowbytes;
  174571. for (i = 0; i < istop; i+=4)
  174572. {
  174573. *rp = (png_byte)(~(*rp));
  174574. *(rp+1) = (png_byte)(~(*(rp+1)));
  174575. rp+=4;
  174576. }
  174577. }
  174578. }
  174579. #endif
  174580. #if defined(PNG_READ_SWAP_SUPPORTED) || defined(PNG_WRITE_SWAP_SUPPORTED)
  174581. void /* PRIVATE */
  174582. png_do_swap(png_row_infop row_info, png_bytep row)
  174583. {
  174584. png_debug(1, "in png_do_swap\n");
  174585. if (
  174586. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  174587. row != NULL && row_info != NULL &&
  174588. #endif
  174589. row_info->bit_depth == 16)
  174590. {
  174591. png_bytep rp = row;
  174592. png_uint_32 i;
  174593. png_uint_32 istop= row_info->width * row_info->channels;
  174594. for (i = 0; i < istop; i++, rp += 2)
  174595. {
  174596. png_byte t = *rp;
  174597. *rp = *(rp + 1);
  174598. *(rp + 1) = t;
  174599. }
  174600. }
  174601. }
  174602. #endif
  174603. #if defined(PNG_READ_PACKSWAP_SUPPORTED)||defined(PNG_WRITE_PACKSWAP_SUPPORTED)
  174604. static PNG_CONST png_byte onebppswaptable[256] = {
  174605. 0x00, 0x80, 0x40, 0xC0, 0x20, 0xA0, 0x60, 0xE0,
  174606. 0x10, 0x90, 0x50, 0xD0, 0x30, 0xB0, 0x70, 0xF0,
  174607. 0x08, 0x88, 0x48, 0xC8, 0x28, 0xA8, 0x68, 0xE8,
  174608. 0x18, 0x98, 0x58, 0xD8, 0x38, 0xB8, 0x78, 0xF8,
  174609. 0x04, 0x84, 0x44, 0xC4, 0x24, 0xA4, 0x64, 0xE4,
  174610. 0x14, 0x94, 0x54, 0xD4, 0x34, 0xB4, 0x74, 0xF4,
  174611. 0x0C, 0x8C, 0x4C, 0xCC, 0x2C, 0xAC, 0x6C, 0xEC,
  174612. 0x1C, 0x9C, 0x5C, 0xDC, 0x3C, 0xBC, 0x7C, 0xFC,
  174613. 0x02, 0x82, 0x42, 0xC2, 0x22, 0xA2, 0x62, 0xE2,
  174614. 0x12, 0x92, 0x52, 0xD2, 0x32, 0xB2, 0x72, 0xF2,
  174615. 0x0A, 0x8A, 0x4A, 0xCA, 0x2A, 0xAA, 0x6A, 0xEA,
  174616. 0x1A, 0x9A, 0x5A, 0xDA, 0x3A, 0xBA, 0x7A, 0xFA,
  174617. 0x06, 0x86, 0x46, 0xC6, 0x26, 0xA6, 0x66, 0xE6,
  174618. 0x16, 0x96, 0x56, 0xD6, 0x36, 0xB6, 0x76, 0xF6,
  174619. 0x0E, 0x8E, 0x4E, 0xCE, 0x2E, 0xAE, 0x6E, 0xEE,
  174620. 0x1E, 0x9E, 0x5E, 0xDE, 0x3E, 0xBE, 0x7E, 0xFE,
  174621. 0x01, 0x81, 0x41, 0xC1, 0x21, 0xA1, 0x61, 0xE1,
  174622. 0x11, 0x91, 0x51, 0xD1, 0x31, 0xB1, 0x71, 0xF1,
  174623. 0x09, 0x89, 0x49, 0xC9, 0x29, 0xA9, 0x69, 0xE9,
  174624. 0x19, 0x99, 0x59, 0xD9, 0x39, 0xB9, 0x79, 0xF9,
  174625. 0x05, 0x85, 0x45, 0xC5, 0x25, 0xA5, 0x65, 0xE5,
  174626. 0x15, 0x95, 0x55, 0xD5, 0x35, 0xB5, 0x75, 0xF5,
  174627. 0x0D, 0x8D, 0x4D, 0xCD, 0x2D, 0xAD, 0x6D, 0xED,
  174628. 0x1D, 0x9D, 0x5D, 0xDD, 0x3D, 0xBD, 0x7D, 0xFD,
  174629. 0x03, 0x83, 0x43, 0xC3, 0x23, 0xA3, 0x63, 0xE3,
  174630. 0x13, 0x93, 0x53, 0xD3, 0x33, 0xB3, 0x73, 0xF3,
  174631. 0x0B, 0x8B, 0x4B, 0xCB, 0x2B, 0xAB, 0x6B, 0xEB,
  174632. 0x1B, 0x9B, 0x5B, 0xDB, 0x3B, 0xBB, 0x7B, 0xFB,
  174633. 0x07, 0x87, 0x47, 0xC7, 0x27, 0xA7, 0x67, 0xE7,
  174634. 0x17, 0x97, 0x57, 0xD7, 0x37, 0xB7, 0x77, 0xF7,
  174635. 0x0F, 0x8F, 0x4F, 0xCF, 0x2F, 0xAF, 0x6F, 0xEF,
  174636. 0x1F, 0x9F, 0x5F, 0xDF, 0x3F, 0xBF, 0x7F, 0xFF
  174637. };
  174638. static PNG_CONST png_byte twobppswaptable[256] = {
  174639. 0x00, 0x40, 0x80, 0xC0, 0x10, 0x50, 0x90, 0xD0,
  174640. 0x20, 0x60, 0xA0, 0xE0, 0x30, 0x70, 0xB0, 0xF0,
  174641. 0x04, 0x44, 0x84, 0xC4, 0x14, 0x54, 0x94, 0xD4,
  174642. 0x24, 0x64, 0xA4, 0xE4, 0x34, 0x74, 0xB4, 0xF4,
  174643. 0x08, 0x48, 0x88, 0xC8, 0x18, 0x58, 0x98, 0xD8,
  174644. 0x28, 0x68, 0xA8, 0xE8, 0x38, 0x78, 0xB8, 0xF8,
  174645. 0x0C, 0x4C, 0x8C, 0xCC, 0x1C, 0x5C, 0x9C, 0xDC,
  174646. 0x2C, 0x6C, 0xAC, 0xEC, 0x3C, 0x7C, 0xBC, 0xFC,
  174647. 0x01, 0x41, 0x81, 0xC1, 0x11, 0x51, 0x91, 0xD1,
  174648. 0x21, 0x61, 0xA1, 0xE1, 0x31, 0x71, 0xB1, 0xF1,
  174649. 0x05, 0x45, 0x85, 0xC5, 0x15, 0x55, 0x95, 0xD5,
  174650. 0x25, 0x65, 0xA5, 0xE5, 0x35, 0x75, 0xB5, 0xF5,
  174651. 0x09, 0x49, 0x89, 0xC9, 0x19, 0x59, 0x99, 0xD9,
  174652. 0x29, 0x69, 0xA9, 0xE9, 0x39, 0x79, 0xB9, 0xF9,
  174653. 0x0D, 0x4D, 0x8D, 0xCD, 0x1D, 0x5D, 0x9D, 0xDD,
  174654. 0x2D, 0x6D, 0xAD, 0xED, 0x3D, 0x7D, 0xBD, 0xFD,
  174655. 0x02, 0x42, 0x82, 0xC2, 0x12, 0x52, 0x92, 0xD2,
  174656. 0x22, 0x62, 0xA2, 0xE2, 0x32, 0x72, 0xB2, 0xF2,
  174657. 0x06, 0x46, 0x86, 0xC6, 0x16, 0x56, 0x96, 0xD6,
  174658. 0x26, 0x66, 0xA6, 0xE6, 0x36, 0x76, 0xB6, 0xF6,
  174659. 0x0A, 0x4A, 0x8A, 0xCA, 0x1A, 0x5A, 0x9A, 0xDA,
  174660. 0x2A, 0x6A, 0xAA, 0xEA, 0x3A, 0x7A, 0xBA, 0xFA,
  174661. 0x0E, 0x4E, 0x8E, 0xCE, 0x1E, 0x5E, 0x9E, 0xDE,
  174662. 0x2E, 0x6E, 0xAE, 0xEE, 0x3E, 0x7E, 0xBE, 0xFE,
  174663. 0x03, 0x43, 0x83, 0xC3, 0x13, 0x53, 0x93, 0xD3,
  174664. 0x23, 0x63, 0xA3, 0xE3, 0x33, 0x73, 0xB3, 0xF3,
  174665. 0x07, 0x47, 0x87, 0xC7, 0x17, 0x57, 0x97, 0xD7,
  174666. 0x27, 0x67, 0xA7, 0xE7, 0x37, 0x77, 0xB7, 0xF7,
  174667. 0x0B, 0x4B, 0x8B, 0xCB, 0x1B, 0x5B, 0x9B, 0xDB,
  174668. 0x2B, 0x6B, 0xAB, 0xEB, 0x3B, 0x7B, 0xBB, 0xFB,
  174669. 0x0F, 0x4F, 0x8F, 0xCF, 0x1F, 0x5F, 0x9F, 0xDF,
  174670. 0x2F, 0x6F, 0xAF, 0xEF, 0x3F, 0x7F, 0xBF, 0xFF
  174671. };
  174672. static PNG_CONST png_byte fourbppswaptable[256] = {
  174673. 0x00, 0x10, 0x20, 0x30, 0x40, 0x50, 0x60, 0x70,
  174674. 0x80, 0x90, 0xA0, 0xB0, 0xC0, 0xD0, 0xE0, 0xF0,
  174675. 0x01, 0x11, 0x21, 0x31, 0x41, 0x51, 0x61, 0x71,
  174676. 0x81, 0x91, 0xA1, 0xB1, 0xC1, 0xD1, 0xE1, 0xF1,
  174677. 0x02, 0x12, 0x22, 0x32, 0x42, 0x52, 0x62, 0x72,
  174678. 0x82, 0x92, 0xA2, 0xB2, 0xC2, 0xD2, 0xE2, 0xF2,
  174679. 0x03, 0x13, 0x23, 0x33, 0x43, 0x53, 0x63, 0x73,
  174680. 0x83, 0x93, 0xA3, 0xB3, 0xC3, 0xD3, 0xE3, 0xF3,
  174681. 0x04, 0x14, 0x24, 0x34, 0x44, 0x54, 0x64, 0x74,
  174682. 0x84, 0x94, 0xA4, 0xB4, 0xC4, 0xD4, 0xE4, 0xF4,
  174683. 0x05, 0x15, 0x25, 0x35, 0x45, 0x55, 0x65, 0x75,
  174684. 0x85, 0x95, 0xA5, 0xB5, 0xC5, 0xD5, 0xE5, 0xF5,
  174685. 0x06, 0x16, 0x26, 0x36, 0x46, 0x56, 0x66, 0x76,
  174686. 0x86, 0x96, 0xA6, 0xB6, 0xC6, 0xD6, 0xE6, 0xF6,
  174687. 0x07, 0x17, 0x27, 0x37, 0x47, 0x57, 0x67, 0x77,
  174688. 0x87, 0x97, 0xA7, 0xB7, 0xC7, 0xD7, 0xE7, 0xF7,
  174689. 0x08, 0x18, 0x28, 0x38, 0x48, 0x58, 0x68, 0x78,
  174690. 0x88, 0x98, 0xA8, 0xB8, 0xC8, 0xD8, 0xE8, 0xF8,
  174691. 0x09, 0x19, 0x29, 0x39, 0x49, 0x59, 0x69, 0x79,
  174692. 0x89, 0x99, 0xA9, 0xB9, 0xC9, 0xD9, 0xE9, 0xF9,
  174693. 0x0A, 0x1A, 0x2A, 0x3A, 0x4A, 0x5A, 0x6A, 0x7A,
  174694. 0x8A, 0x9A, 0xAA, 0xBA, 0xCA, 0xDA, 0xEA, 0xFA,
  174695. 0x0B, 0x1B, 0x2B, 0x3B, 0x4B, 0x5B, 0x6B, 0x7B,
  174696. 0x8B, 0x9B, 0xAB, 0xBB, 0xCB, 0xDB, 0xEB, 0xFB,
  174697. 0x0C, 0x1C, 0x2C, 0x3C, 0x4C, 0x5C, 0x6C, 0x7C,
  174698. 0x8C, 0x9C, 0xAC, 0xBC, 0xCC, 0xDC, 0xEC, 0xFC,
  174699. 0x0D, 0x1D, 0x2D, 0x3D, 0x4D, 0x5D, 0x6D, 0x7D,
  174700. 0x8D, 0x9D, 0xAD, 0xBD, 0xCD, 0xDD, 0xED, 0xFD,
  174701. 0x0E, 0x1E, 0x2E, 0x3E, 0x4E, 0x5E, 0x6E, 0x7E,
  174702. 0x8E, 0x9E, 0xAE, 0xBE, 0xCE, 0xDE, 0xEE, 0xFE,
  174703. 0x0F, 0x1F, 0x2F, 0x3F, 0x4F, 0x5F, 0x6F, 0x7F,
  174704. 0x8F, 0x9F, 0xAF, 0xBF, 0xCF, 0xDF, 0xEF, 0xFF
  174705. };
  174706. void /* PRIVATE */
  174707. png_do_packswap(png_row_infop row_info, png_bytep row)
  174708. {
  174709. png_debug(1, "in png_do_packswap\n");
  174710. if (
  174711. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  174712. row != NULL && row_info != NULL &&
  174713. #endif
  174714. row_info->bit_depth < 8)
  174715. {
  174716. png_bytep rp, end, table;
  174717. end = row + row_info->rowbytes;
  174718. if (row_info->bit_depth == 1)
  174719. table = (png_bytep)onebppswaptable;
  174720. else if (row_info->bit_depth == 2)
  174721. table = (png_bytep)twobppswaptable;
  174722. else if (row_info->bit_depth == 4)
  174723. table = (png_bytep)fourbppswaptable;
  174724. else
  174725. return;
  174726. for (rp = row; rp < end; rp++)
  174727. *rp = table[*rp];
  174728. }
  174729. }
  174730. #endif /* PNG_READ_PACKSWAP_SUPPORTED or PNG_WRITE_PACKSWAP_SUPPORTED */
  174731. #if defined(PNG_WRITE_FILLER_SUPPORTED) || \
  174732. defined(PNG_READ_STRIP_ALPHA_SUPPORTED)
  174733. void /* PRIVATE */
  174734. png_do_strip_filler(png_row_infop row_info, png_bytep row, png_uint_32 flags)
  174735. {
  174736. png_debug(1, "in png_do_strip_filler\n");
  174737. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  174738. if (row != NULL && row_info != NULL)
  174739. #endif
  174740. {
  174741. png_bytep sp=row;
  174742. png_bytep dp=row;
  174743. png_uint_32 row_width=row_info->width;
  174744. png_uint_32 i;
  174745. if ((row_info->color_type == PNG_COLOR_TYPE_RGB ||
  174746. (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA &&
  174747. (flags & PNG_FLAG_STRIP_ALPHA))) &&
  174748. row_info->channels == 4)
  174749. {
  174750. if (row_info->bit_depth == 8)
  174751. {
  174752. if (flags & PNG_FLAG_FILLER_AFTER)
  174753. {
  174754. dp+=3; sp+=4;
  174755. for (i = 1; i < row_width; i++)
  174756. {
  174757. *dp++ = *sp++;
  174758. *dp++ = *sp++;
  174759. *dp++ = *sp++;
  174760. sp++;
  174761. }
  174762. }
  174763. else
  174764. {
  174765. for (i = 0; i < row_width; i++)
  174766. {
  174767. sp++;
  174768. *dp++ = *sp++;
  174769. *dp++ = *sp++;
  174770. *dp++ = *sp++;
  174771. }
  174772. }
  174773. row_info->pixel_depth = 24;
  174774. row_info->rowbytes = row_width * 3;
  174775. }
  174776. else /* if (row_info->bit_depth == 16) */
  174777. {
  174778. if (flags & PNG_FLAG_FILLER_AFTER)
  174779. {
  174780. sp += 8; dp += 6;
  174781. for (i = 1; i < row_width; i++)
  174782. {
  174783. *dp++ = *sp++;
  174784. *dp++ = *sp++;
  174785. *dp++ = *sp++;
  174786. *dp++ = *sp++;
  174787. *dp++ = *sp++;
  174788. *dp++ = *sp++;
  174789. sp += 2;
  174790. }
  174791. }
  174792. else
  174793. {
  174794. for (i = 0; i < row_width; i++)
  174795. {
  174796. sp+=2;
  174797. *dp++ = *sp++;
  174798. *dp++ = *sp++;
  174799. *dp++ = *sp++;
  174800. *dp++ = *sp++;
  174801. *dp++ = *sp++;
  174802. *dp++ = *sp++;
  174803. }
  174804. }
  174805. row_info->pixel_depth = 48;
  174806. row_info->rowbytes = row_width * 6;
  174807. }
  174808. row_info->channels = 3;
  174809. }
  174810. else if ((row_info->color_type == PNG_COLOR_TYPE_GRAY ||
  174811. (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA &&
  174812. (flags & PNG_FLAG_STRIP_ALPHA))) &&
  174813. row_info->channels == 2)
  174814. {
  174815. if (row_info->bit_depth == 8)
  174816. {
  174817. if (flags & PNG_FLAG_FILLER_AFTER)
  174818. {
  174819. for (i = 0; i < row_width; i++)
  174820. {
  174821. *dp++ = *sp++;
  174822. sp++;
  174823. }
  174824. }
  174825. else
  174826. {
  174827. for (i = 0; i < row_width; i++)
  174828. {
  174829. sp++;
  174830. *dp++ = *sp++;
  174831. }
  174832. }
  174833. row_info->pixel_depth = 8;
  174834. row_info->rowbytes = row_width;
  174835. }
  174836. else /* if (row_info->bit_depth == 16) */
  174837. {
  174838. if (flags & PNG_FLAG_FILLER_AFTER)
  174839. {
  174840. sp += 4; dp += 2;
  174841. for (i = 1; i < row_width; i++)
  174842. {
  174843. *dp++ = *sp++;
  174844. *dp++ = *sp++;
  174845. sp += 2;
  174846. }
  174847. }
  174848. else
  174849. {
  174850. for (i = 0; i < row_width; i++)
  174851. {
  174852. sp += 2;
  174853. *dp++ = *sp++;
  174854. *dp++ = *sp++;
  174855. }
  174856. }
  174857. row_info->pixel_depth = 16;
  174858. row_info->rowbytes = row_width * 2;
  174859. }
  174860. row_info->channels = 1;
  174861. }
  174862. if (flags & PNG_FLAG_STRIP_ALPHA)
  174863. row_info->color_type &= ~PNG_COLOR_MASK_ALPHA;
  174864. }
  174865. }
  174866. #endif
  174867. #if defined(PNG_READ_BGR_SUPPORTED) || defined(PNG_WRITE_BGR_SUPPORTED)
  174868. void /* PRIVATE */
  174869. png_do_bgr(png_row_infop row_info, png_bytep row)
  174870. {
  174871. png_debug(1, "in png_do_bgr\n");
  174872. if (
  174873. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  174874. row != NULL && row_info != NULL &&
  174875. #endif
  174876. (row_info->color_type & PNG_COLOR_MASK_COLOR))
  174877. {
  174878. png_uint_32 row_width = row_info->width;
  174879. if (row_info->bit_depth == 8)
  174880. {
  174881. if (row_info->color_type == PNG_COLOR_TYPE_RGB)
  174882. {
  174883. png_bytep rp;
  174884. png_uint_32 i;
  174885. for (i = 0, rp = row; i < row_width; i++, rp += 3)
  174886. {
  174887. png_byte save = *rp;
  174888. *rp = *(rp + 2);
  174889. *(rp + 2) = save;
  174890. }
  174891. }
  174892. else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  174893. {
  174894. png_bytep rp;
  174895. png_uint_32 i;
  174896. for (i = 0, rp = row; i < row_width; i++, rp += 4)
  174897. {
  174898. png_byte save = *rp;
  174899. *rp = *(rp + 2);
  174900. *(rp + 2) = save;
  174901. }
  174902. }
  174903. }
  174904. else if (row_info->bit_depth == 16)
  174905. {
  174906. if (row_info->color_type == PNG_COLOR_TYPE_RGB)
  174907. {
  174908. png_bytep rp;
  174909. png_uint_32 i;
  174910. for (i = 0, rp = row; i < row_width; i++, rp += 6)
  174911. {
  174912. png_byte save = *rp;
  174913. *rp = *(rp + 4);
  174914. *(rp + 4) = save;
  174915. save = *(rp + 1);
  174916. *(rp + 1) = *(rp + 5);
  174917. *(rp + 5) = save;
  174918. }
  174919. }
  174920. else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  174921. {
  174922. png_bytep rp;
  174923. png_uint_32 i;
  174924. for (i = 0, rp = row; i < row_width; i++, rp += 8)
  174925. {
  174926. png_byte save = *rp;
  174927. *rp = *(rp + 4);
  174928. *(rp + 4) = save;
  174929. save = *(rp + 1);
  174930. *(rp + 1) = *(rp + 5);
  174931. *(rp + 5) = save;
  174932. }
  174933. }
  174934. }
  174935. }
  174936. }
  174937. #endif /* PNG_READ_BGR_SUPPORTED or PNG_WRITE_BGR_SUPPORTED */
  174938. #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \
  174939. defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED) || \
  174940. defined(PNG_LEGACY_SUPPORTED)
  174941. void PNGAPI
  174942. png_set_user_transform_info(png_structp png_ptr, png_voidp
  174943. user_transform_ptr, int user_transform_depth, int user_transform_channels)
  174944. {
  174945. png_debug(1, "in png_set_user_transform_info\n");
  174946. if(png_ptr == NULL) return;
  174947. #if defined(PNG_USER_TRANSFORM_PTR_SUPPORTED)
  174948. png_ptr->user_transform_ptr = user_transform_ptr;
  174949. png_ptr->user_transform_depth = (png_byte)user_transform_depth;
  174950. png_ptr->user_transform_channels = (png_byte)user_transform_channels;
  174951. #else
  174952. if(user_transform_ptr || user_transform_depth || user_transform_channels)
  174953. png_warning(png_ptr,
  174954. "This version of libpng does not support user transform info");
  174955. #endif
  174956. }
  174957. #endif
  174958. png_voidp PNGAPI
  174959. png_get_user_transform_ptr(png_structp png_ptr)
  174960. {
  174961. #if defined(PNG_USER_TRANSFORM_PTR_SUPPORTED)
  174962. if (png_ptr == NULL) return (NULL);
  174963. return ((png_voidp)png_ptr->user_transform_ptr);
  174964. #else
  174965. return (NULL);
  174966. #endif
  174967. }
  174968. #endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */
  174969. /*** End of inlined file: pngtrans.c ***/
  174970. /*** Start of inlined file: pngwio.c ***/
  174971. #define PNG_INTERNAL
  174972. #ifdef PNG_WRITE_SUPPORTED
  174973. void /* PRIVATE */
  174974. png_write_data(png_structp png_ptr, png_bytep data, png_size_t length)
  174975. {
  174976. if (png_ptr->write_data_fn != NULL )
  174977. (*(png_ptr->write_data_fn))(png_ptr, data, length);
  174978. else
  174979. png_error(png_ptr, "Call to NULL write function");
  174980. }
  174981. #if !defined(PNG_NO_STDIO)
  174982. #ifndef USE_FAR_KEYWORD
  174983. void PNGAPI
  174984. png_default_write_data(png_structp png_ptr, png_bytep data, png_size_t length)
  174985. {
  174986. png_uint_32 check;
  174987. if(png_ptr == NULL) return;
  174988. #if defined(_WIN32_WCE)
  174989. if ( !WriteFile((HANDLE)(png_ptr->io_ptr), data, length, &check, NULL) )
  174990. check = 0;
  174991. #else
  174992. check = fwrite(data, 1, length, (png_FILE_p)(png_ptr->io_ptr));
  174993. #endif
  174994. if (check != length)
  174995. png_error(png_ptr, "Write Error");
  174996. }
  174997. #else
  174998. #define NEAR_BUF_SIZE 1024
  174999. #define MIN(a,b) (a <= b ? a : b)
  175000. void PNGAPI
  175001. png_default_write_data(png_structp png_ptr, png_bytep data, png_size_t length)
  175002. {
  175003. png_uint_32 check;
  175004. png_byte *near_data; /* Needs to be "png_byte *" instead of "png_bytep" */
  175005. png_FILE_p io_ptr;
  175006. if(png_ptr == NULL) return;
  175007. near_data = (png_byte *)CVT_PTR_NOCHECK(data);
  175008. io_ptr = (png_FILE_p)CVT_PTR(png_ptr->io_ptr);
  175009. if ((png_bytep)near_data == data)
  175010. {
  175011. #if defined(_WIN32_WCE)
  175012. if ( !WriteFile(io_ptr, near_data, length, &check, NULL) )
  175013. check = 0;
  175014. #else
  175015. check = fwrite(near_data, 1, length, io_ptr);
  175016. #endif
  175017. }
  175018. else
  175019. {
  175020. png_byte buf[NEAR_BUF_SIZE];
  175021. png_size_t written, remaining, err;
  175022. check = 0;
  175023. remaining = length;
  175024. do
  175025. {
  175026. written = MIN(NEAR_BUF_SIZE, remaining);
  175027. png_memcpy(buf, data, written); /* copy far buffer to near buffer */
  175028. #if defined(_WIN32_WCE)
  175029. if ( !WriteFile(io_ptr, buf, written, &err, NULL) )
  175030. err = 0;
  175031. #else
  175032. err = fwrite(buf, 1, written, io_ptr);
  175033. #endif
  175034. if (err != written)
  175035. break;
  175036. else
  175037. check += err;
  175038. data += written;
  175039. remaining -= written;
  175040. }
  175041. while (remaining != 0);
  175042. }
  175043. if (check != length)
  175044. png_error(png_ptr, "Write Error");
  175045. }
  175046. #endif
  175047. #endif
  175048. #if defined(PNG_WRITE_FLUSH_SUPPORTED)
  175049. void /* PRIVATE */
  175050. png_flush(png_structp png_ptr)
  175051. {
  175052. if (png_ptr->output_flush_fn != NULL)
  175053. (*(png_ptr->output_flush_fn))(png_ptr);
  175054. }
  175055. #if !defined(PNG_NO_STDIO)
  175056. void PNGAPI
  175057. png_default_flush(png_structp png_ptr)
  175058. {
  175059. #if !defined(_WIN32_WCE)
  175060. png_FILE_p io_ptr;
  175061. #endif
  175062. if(png_ptr == NULL) return;
  175063. #if !defined(_WIN32_WCE)
  175064. io_ptr = (png_FILE_p)CVT_PTR((png_ptr->io_ptr));
  175065. if (io_ptr != NULL)
  175066. fflush(io_ptr);
  175067. #endif
  175068. }
  175069. #endif
  175070. #endif
  175071. void PNGAPI
  175072. png_set_write_fn(png_structp png_ptr, png_voidp io_ptr,
  175073. png_rw_ptr write_data_fn, png_flush_ptr output_flush_fn)
  175074. {
  175075. if(png_ptr == NULL) return;
  175076. png_ptr->io_ptr = io_ptr;
  175077. #if !defined(PNG_NO_STDIO)
  175078. if (write_data_fn != NULL)
  175079. png_ptr->write_data_fn = write_data_fn;
  175080. else
  175081. png_ptr->write_data_fn = png_default_write_data;
  175082. #else
  175083. png_ptr->write_data_fn = write_data_fn;
  175084. #endif
  175085. #if defined(PNG_WRITE_FLUSH_SUPPORTED)
  175086. #if !defined(PNG_NO_STDIO)
  175087. if (output_flush_fn != NULL)
  175088. png_ptr->output_flush_fn = output_flush_fn;
  175089. else
  175090. png_ptr->output_flush_fn = png_default_flush;
  175091. #else
  175092. png_ptr->output_flush_fn = output_flush_fn;
  175093. #endif
  175094. #endif /* PNG_WRITE_FLUSH_SUPPORTED */
  175095. if (png_ptr->read_data_fn != NULL)
  175096. {
  175097. png_ptr->read_data_fn = NULL;
  175098. png_warning(png_ptr,
  175099. "Attempted to set both read_data_fn and write_data_fn in");
  175100. png_warning(png_ptr,
  175101. "the same structure. Resetting read_data_fn to NULL.");
  175102. }
  175103. }
  175104. #if defined(USE_FAR_KEYWORD)
  175105. #if defined(_MSC_VER)
  175106. void *png_far_to_near(png_structp png_ptr,png_voidp ptr, int check)
  175107. {
  175108. void *near_ptr;
  175109. void FAR *far_ptr;
  175110. FP_OFF(near_ptr) = FP_OFF(ptr);
  175111. far_ptr = (void FAR *)near_ptr;
  175112. if(check != 0)
  175113. if(FP_SEG(ptr) != FP_SEG(far_ptr))
  175114. png_error(png_ptr,"segment lost in conversion");
  175115. return(near_ptr);
  175116. }
  175117. # else
  175118. void *png_far_to_near(png_structp png_ptr,png_voidp ptr, int check)
  175119. {
  175120. void *near_ptr;
  175121. void FAR *far_ptr;
  175122. near_ptr = (void FAR *)ptr;
  175123. far_ptr = (void FAR *)near_ptr;
  175124. if(check != 0)
  175125. if(far_ptr != ptr)
  175126. png_error(png_ptr,"segment lost in conversion");
  175127. return(near_ptr);
  175128. }
  175129. # endif
  175130. # endif
  175131. #endif /* PNG_WRITE_SUPPORTED */
  175132. /*** End of inlined file: pngwio.c ***/
  175133. /*** Start of inlined file: pngwrite.c ***/
  175134. #define PNG_INTERNAL
  175135. #ifdef PNG_WRITE_SUPPORTED
  175136. void PNGAPI
  175137. png_write_info_before_PLTE(png_structp png_ptr, png_infop info_ptr)
  175138. {
  175139. png_debug(1, "in png_write_info_before_PLTE\n");
  175140. if (png_ptr == NULL || info_ptr == NULL)
  175141. return;
  175142. if (!(png_ptr->mode & PNG_WROTE_INFO_BEFORE_PLTE))
  175143. {
  175144. png_write_sig(png_ptr); /* write PNG signature */
  175145. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  175146. if((png_ptr->mode&PNG_HAVE_PNG_SIGNATURE)&&(png_ptr->mng_features_permitted))
  175147. {
  175148. png_warning(png_ptr,"MNG features are not allowed in a PNG datastream");
  175149. png_ptr->mng_features_permitted=0;
  175150. }
  175151. #endif
  175152. png_write_IHDR(png_ptr, info_ptr->width, info_ptr->height,
  175153. info_ptr->bit_depth, info_ptr->color_type, info_ptr->compression_type,
  175154. info_ptr->filter_type,
  175155. #if defined(PNG_WRITE_INTERLACING_SUPPORTED)
  175156. info_ptr->interlace_type);
  175157. #else
  175158. 0);
  175159. #endif
  175160. #if defined(PNG_WRITE_gAMA_SUPPORTED)
  175161. if (info_ptr->valid & PNG_INFO_gAMA)
  175162. {
  175163. # ifdef PNG_FLOATING_POINT_SUPPORTED
  175164. png_write_gAMA(png_ptr, info_ptr->gamma);
  175165. #else
  175166. #ifdef PNG_FIXED_POINT_SUPPORTED
  175167. png_write_gAMA_fixed(png_ptr, info_ptr->int_gamma);
  175168. # endif
  175169. #endif
  175170. }
  175171. #endif
  175172. #if defined(PNG_WRITE_sRGB_SUPPORTED)
  175173. if (info_ptr->valid & PNG_INFO_sRGB)
  175174. png_write_sRGB(png_ptr, (int)info_ptr->srgb_intent);
  175175. #endif
  175176. #if defined(PNG_WRITE_iCCP_SUPPORTED)
  175177. if (info_ptr->valid & PNG_INFO_iCCP)
  175178. png_write_iCCP(png_ptr, info_ptr->iccp_name, PNG_COMPRESSION_TYPE_BASE,
  175179. info_ptr->iccp_profile, (int)info_ptr->iccp_proflen);
  175180. #endif
  175181. #if defined(PNG_WRITE_sBIT_SUPPORTED)
  175182. if (info_ptr->valid & PNG_INFO_sBIT)
  175183. png_write_sBIT(png_ptr, &(info_ptr->sig_bit), info_ptr->color_type);
  175184. #endif
  175185. #if defined(PNG_WRITE_cHRM_SUPPORTED)
  175186. if (info_ptr->valid & PNG_INFO_cHRM)
  175187. {
  175188. #ifdef PNG_FLOATING_POINT_SUPPORTED
  175189. png_write_cHRM(png_ptr,
  175190. info_ptr->x_white, info_ptr->y_white,
  175191. info_ptr->x_red, info_ptr->y_red,
  175192. info_ptr->x_green, info_ptr->y_green,
  175193. info_ptr->x_blue, info_ptr->y_blue);
  175194. #else
  175195. # ifdef PNG_FIXED_POINT_SUPPORTED
  175196. png_write_cHRM_fixed(png_ptr,
  175197. info_ptr->int_x_white, info_ptr->int_y_white,
  175198. info_ptr->int_x_red, info_ptr->int_y_red,
  175199. info_ptr->int_x_green, info_ptr->int_y_green,
  175200. info_ptr->int_x_blue, info_ptr->int_y_blue);
  175201. # endif
  175202. #endif
  175203. }
  175204. #endif
  175205. #if defined(PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED)
  175206. if (info_ptr->unknown_chunks_num)
  175207. {
  175208. png_unknown_chunk *up;
  175209. png_debug(5, "writing extra chunks\n");
  175210. for (up = info_ptr->unknown_chunks;
  175211. up < info_ptr->unknown_chunks + info_ptr->unknown_chunks_num;
  175212. up++)
  175213. {
  175214. int keep=png_handle_as_unknown(png_ptr, up->name);
  175215. if (keep != PNG_HANDLE_CHUNK_NEVER &&
  175216. up->location && !(up->location & PNG_HAVE_PLTE) &&
  175217. !(up->location & PNG_HAVE_IDAT) &&
  175218. ((up->name[3] & 0x20) || keep == PNG_HANDLE_CHUNK_ALWAYS ||
  175219. (png_ptr->flags & PNG_FLAG_KEEP_UNSAFE_CHUNKS)))
  175220. {
  175221. png_write_chunk(png_ptr, up->name, up->data, up->size);
  175222. }
  175223. }
  175224. }
  175225. #endif
  175226. png_ptr->mode |= PNG_WROTE_INFO_BEFORE_PLTE;
  175227. }
  175228. }
  175229. void PNGAPI
  175230. png_write_info(png_structp png_ptr, png_infop info_ptr)
  175231. {
  175232. #if defined(PNG_WRITE_TEXT_SUPPORTED) || defined(PNG_WRITE_sPLT_SUPPORTED)
  175233. int i;
  175234. #endif
  175235. png_debug(1, "in png_write_info\n");
  175236. if (png_ptr == NULL || info_ptr == NULL)
  175237. return;
  175238. png_write_info_before_PLTE(png_ptr, info_ptr);
  175239. if (info_ptr->valid & PNG_INFO_PLTE)
  175240. png_write_PLTE(png_ptr, info_ptr->palette,
  175241. (png_uint_32)info_ptr->num_palette);
  175242. else if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  175243. png_error(png_ptr, "Valid palette required for paletted images");
  175244. #if defined(PNG_WRITE_tRNS_SUPPORTED)
  175245. if (info_ptr->valid & PNG_INFO_tRNS)
  175246. {
  175247. #if defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED)
  175248. if ((png_ptr->transformations & PNG_INVERT_ALPHA) &&
  175249. info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  175250. {
  175251. int j;
  175252. for (j=0; j<(int)info_ptr->num_trans; j++)
  175253. info_ptr->trans[j] = (png_byte)(255 - info_ptr->trans[j]);
  175254. }
  175255. #endif
  175256. png_write_tRNS(png_ptr, info_ptr->trans, &(info_ptr->trans_values),
  175257. info_ptr->num_trans, info_ptr->color_type);
  175258. }
  175259. #endif
  175260. #if defined(PNG_WRITE_bKGD_SUPPORTED)
  175261. if (info_ptr->valid & PNG_INFO_bKGD)
  175262. png_write_bKGD(png_ptr, &(info_ptr->background), info_ptr->color_type);
  175263. #endif
  175264. #if defined(PNG_WRITE_hIST_SUPPORTED)
  175265. if (info_ptr->valid & PNG_INFO_hIST)
  175266. png_write_hIST(png_ptr, info_ptr->hist, info_ptr->num_palette);
  175267. #endif
  175268. #if defined(PNG_WRITE_oFFs_SUPPORTED)
  175269. if (info_ptr->valid & PNG_INFO_oFFs)
  175270. png_write_oFFs(png_ptr, info_ptr->x_offset, info_ptr->y_offset,
  175271. info_ptr->offset_unit_type);
  175272. #endif
  175273. #if defined(PNG_WRITE_pCAL_SUPPORTED)
  175274. if (info_ptr->valid & PNG_INFO_pCAL)
  175275. png_write_pCAL(png_ptr, info_ptr->pcal_purpose, info_ptr->pcal_X0,
  175276. info_ptr->pcal_X1, info_ptr->pcal_type, info_ptr->pcal_nparams,
  175277. info_ptr->pcal_units, info_ptr->pcal_params);
  175278. #endif
  175279. #if defined(PNG_WRITE_sCAL_SUPPORTED)
  175280. if (info_ptr->valid & PNG_INFO_sCAL)
  175281. #if defined(PNG_FLOATING_POINT_SUPPORTED) && !defined(PNG_NO_STDIO)
  175282. png_write_sCAL(png_ptr, (int)info_ptr->scal_unit,
  175283. info_ptr->scal_pixel_width, info_ptr->scal_pixel_height);
  175284. #else
  175285. #ifdef PNG_FIXED_POINT_SUPPORTED
  175286. png_write_sCAL_s(png_ptr, (int)info_ptr->scal_unit,
  175287. info_ptr->scal_s_width, info_ptr->scal_s_height);
  175288. #else
  175289. png_warning(png_ptr,
  175290. "png_write_sCAL not supported; sCAL chunk not written.");
  175291. #endif
  175292. #endif
  175293. #endif
  175294. #if defined(PNG_WRITE_pHYs_SUPPORTED)
  175295. if (info_ptr->valid & PNG_INFO_pHYs)
  175296. png_write_pHYs(png_ptr, info_ptr->x_pixels_per_unit,
  175297. info_ptr->y_pixels_per_unit, info_ptr->phys_unit_type);
  175298. #endif
  175299. #if defined(PNG_WRITE_tIME_SUPPORTED)
  175300. if (info_ptr->valid & PNG_INFO_tIME)
  175301. {
  175302. png_write_tIME(png_ptr, &(info_ptr->mod_time));
  175303. png_ptr->mode |= PNG_WROTE_tIME;
  175304. }
  175305. #endif
  175306. #if defined(PNG_WRITE_sPLT_SUPPORTED)
  175307. if (info_ptr->valid & PNG_INFO_sPLT)
  175308. for (i = 0; i < (int)info_ptr->splt_palettes_num; i++)
  175309. png_write_sPLT(png_ptr, info_ptr->splt_palettes + i);
  175310. #endif
  175311. #if defined(PNG_WRITE_TEXT_SUPPORTED)
  175312. for (i = 0; i < info_ptr->num_text; i++)
  175313. {
  175314. png_debug2(2, "Writing header text chunk %d, type %d\n", i,
  175315. info_ptr->text[i].compression);
  175316. if (info_ptr->text[i].compression > 0)
  175317. {
  175318. #if defined(PNG_WRITE_iTXt_SUPPORTED)
  175319. png_write_iTXt(png_ptr,
  175320. info_ptr->text[i].compression,
  175321. info_ptr->text[i].key,
  175322. info_ptr->text[i].lang,
  175323. info_ptr->text[i].lang_key,
  175324. info_ptr->text[i].text);
  175325. #else
  175326. png_warning(png_ptr, "Unable to write international text");
  175327. #endif
  175328. info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_NONE_WR;
  175329. }
  175330. else if (info_ptr->text[i].compression == PNG_TEXT_COMPRESSION_zTXt)
  175331. {
  175332. #if defined(PNG_WRITE_zTXt_SUPPORTED)
  175333. png_write_zTXt(png_ptr, info_ptr->text[i].key,
  175334. info_ptr->text[i].text, 0,
  175335. info_ptr->text[i].compression);
  175336. #else
  175337. png_warning(png_ptr, "Unable to write compressed text");
  175338. #endif
  175339. info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_zTXt_WR;
  175340. }
  175341. else if (info_ptr->text[i].compression == PNG_TEXT_COMPRESSION_NONE)
  175342. {
  175343. #if defined(PNG_WRITE_tEXt_SUPPORTED)
  175344. png_write_tEXt(png_ptr, info_ptr->text[i].key,
  175345. info_ptr->text[i].text,
  175346. 0);
  175347. #else
  175348. png_warning(png_ptr, "Unable to write uncompressed text");
  175349. #endif
  175350. info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_NONE_WR;
  175351. }
  175352. }
  175353. #endif
  175354. #if defined(PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED)
  175355. if (info_ptr->unknown_chunks_num)
  175356. {
  175357. png_unknown_chunk *up;
  175358. png_debug(5, "writing extra chunks\n");
  175359. for (up = info_ptr->unknown_chunks;
  175360. up < info_ptr->unknown_chunks + info_ptr->unknown_chunks_num;
  175361. up++)
  175362. {
  175363. int keep=png_handle_as_unknown(png_ptr, up->name);
  175364. if (keep != PNG_HANDLE_CHUNK_NEVER &&
  175365. up->location && (up->location & PNG_HAVE_PLTE) &&
  175366. !(up->location & PNG_HAVE_IDAT) &&
  175367. ((up->name[3] & 0x20) || keep == PNG_HANDLE_CHUNK_ALWAYS ||
  175368. (png_ptr->flags & PNG_FLAG_KEEP_UNSAFE_CHUNKS)))
  175369. {
  175370. png_write_chunk(png_ptr, up->name, up->data, up->size);
  175371. }
  175372. }
  175373. }
  175374. #endif
  175375. }
  175376. void PNGAPI
  175377. png_write_end(png_structp png_ptr, png_infop info_ptr)
  175378. {
  175379. png_debug(1, "in png_write_end\n");
  175380. if (png_ptr == NULL)
  175381. return;
  175382. if (!(png_ptr->mode & PNG_HAVE_IDAT))
  175383. png_error(png_ptr, "No IDATs written into file");
  175384. if (info_ptr != NULL)
  175385. {
  175386. #if defined(PNG_WRITE_TEXT_SUPPORTED)
  175387. int i; /* local index variable */
  175388. #endif
  175389. #if defined(PNG_WRITE_tIME_SUPPORTED)
  175390. if ((info_ptr->valid & PNG_INFO_tIME) &&
  175391. !(png_ptr->mode & PNG_WROTE_tIME))
  175392. png_write_tIME(png_ptr, &(info_ptr->mod_time));
  175393. #endif
  175394. #if defined(PNG_WRITE_TEXT_SUPPORTED)
  175395. for (i = 0; i < info_ptr->num_text; i++)
  175396. {
  175397. png_debug2(2, "Writing trailer text chunk %d, type %d\n", i,
  175398. info_ptr->text[i].compression);
  175399. if (info_ptr->text[i].compression > 0)
  175400. {
  175401. #if defined(PNG_WRITE_iTXt_SUPPORTED)
  175402. png_write_iTXt(png_ptr,
  175403. info_ptr->text[i].compression,
  175404. info_ptr->text[i].key,
  175405. info_ptr->text[i].lang,
  175406. info_ptr->text[i].lang_key,
  175407. info_ptr->text[i].text);
  175408. #else
  175409. png_warning(png_ptr, "Unable to write international text");
  175410. #endif
  175411. info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_NONE_WR;
  175412. }
  175413. else if (info_ptr->text[i].compression >= PNG_TEXT_COMPRESSION_zTXt)
  175414. {
  175415. #if defined(PNG_WRITE_zTXt_SUPPORTED)
  175416. png_write_zTXt(png_ptr, info_ptr->text[i].key,
  175417. info_ptr->text[i].text, 0,
  175418. info_ptr->text[i].compression);
  175419. #else
  175420. png_warning(png_ptr, "Unable to write compressed text");
  175421. #endif
  175422. info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_zTXt_WR;
  175423. }
  175424. else if (info_ptr->text[i].compression == PNG_TEXT_COMPRESSION_NONE)
  175425. {
  175426. #if defined(PNG_WRITE_tEXt_SUPPORTED)
  175427. png_write_tEXt(png_ptr, info_ptr->text[i].key,
  175428. info_ptr->text[i].text, 0);
  175429. #else
  175430. png_warning(png_ptr, "Unable to write uncompressed text");
  175431. #endif
  175432. info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_NONE_WR;
  175433. }
  175434. }
  175435. #endif
  175436. #if defined(PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED)
  175437. if (info_ptr->unknown_chunks_num)
  175438. {
  175439. png_unknown_chunk *up;
  175440. png_debug(5, "writing extra chunks\n");
  175441. for (up = info_ptr->unknown_chunks;
  175442. up < info_ptr->unknown_chunks + info_ptr->unknown_chunks_num;
  175443. up++)
  175444. {
  175445. int keep=png_handle_as_unknown(png_ptr, up->name);
  175446. if (keep != PNG_HANDLE_CHUNK_NEVER &&
  175447. up->location && (up->location & PNG_AFTER_IDAT) &&
  175448. ((up->name[3] & 0x20) || keep == PNG_HANDLE_CHUNK_ALWAYS ||
  175449. (png_ptr->flags & PNG_FLAG_KEEP_UNSAFE_CHUNKS)))
  175450. {
  175451. png_write_chunk(png_ptr, up->name, up->data, up->size);
  175452. }
  175453. }
  175454. }
  175455. #endif
  175456. }
  175457. png_ptr->mode |= PNG_AFTER_IDAT;
  175458. png_write_IEND(png_ptr);
  175459. }
  175460. #if defined(PNG_WRITE_tIME_SUPPORTED)
  175461. #if !defined(_WIN32_WCE)
  175462. void PNGAPI
  175463. png_convert_from_struct_tm(png_timep ptime, struct tm FAR * ttime)
  175464. {
  175465. png_debug(1, "in png_convert_from_struct_tm\n");
  175466. ptime->year = (png_uint_16)(1900 + ttime->tm_year);
  175467. ptime->month = (png_byte)(ttime->tm_mon + 1);
  175468. ptime->day = (png_byte)ttime->tm_mday;
  175469. ptime->hour = (png_byte)ttime->tm_hour;
  175470. ptime->minute = (png_byte)ttime->tm_min;
  175471. ptime->second = (png_byte)ttime->tm_sec;
  175472. }
  175473. void PNGAPI
  175474. png_convert_from_time_t(png_timep ptime, time_t ttime)
  175475. {
  175476. struct tm *tbuf;
  175477. png_debug(1, "in png_convert_from_time_t\n");
  175478. tbuf = gmtime(&ttime);
  175479. png_convert_from_struct_tm(ptime, tbuf);
  175480. }
  175481. #endif
  175482. #endif
  175483. png_structp PNGAPI
  175484. png_create_write_struct(png_const_charp user_png_ver, png_voidp error_ptr,
  175485. png_error_ptr error_fn, png_error_ptr warn_fn)
  175486. {
  175487. #ifdef PNG_USER_MEM_SUPPORTED
  175488. return (png_create_write_struct_2(user_png_ver, error_ptr, error_fn,
  175489. warn_fn, png_voidp_NULL, png_malloc_ptr_NULL, png_free_ptr_NULL));
  175490. }
  175491. png_structp PNGAPI
  175492. png_create_write_struct_2(png_const_charp user_png_ver, png_voidp error_ptr,
  175493. png_error_ptr error_fn, png_error_ptr warn_fn, png_voidp mem_ptr,
  175494. png_malloc_ptr malloc_fn, png_free_ptr free_fn)
  175495. {
  175496. #endif /* PNG_USER_MEM_SUPPORTED */
  175497. png_structp png_ptr;
  175498. #ifdef PNG_SETJMP_SUPPORTED
  175499. #ifdef USE_FAR_KEYWORD
  175500. jmp_buf jmpbuf;
  175501. #endif
  175502. #endif
  175503. int i;
  175504. png_debug(1, "in png_create_write_struct\n");
  175505. #ifdef PNG_USER_MEM_SUPPORTED
  175506. png_ptr = (png_structp)png_create_struct_2(PNG_STRUCT_PNG,
  175507. (png_malloc_ptr)malloc_fn, (png_voidp)mem_ptr);
  175508. #else
  175509. png_ptr = (png_structp)png_create_struct(PNG_STRUCT_PNG);
  175510. #endif /* PNG_USER_MEM_SUPPORTED */
  175511. if (png_ptr == NULL)
  175512. return (NULL);
  175513. #ifdef PNG_SET_USER_LIMITS_SUPPORTED
  175514. png_ptr->user_width_max=PNG_USER_WIDTH_MAX;
  175515. png_ptr->user_height_max=PNG_USER_HEIGHT_MAX;
  175516. #endif
  175517. #ifdef PNG_SETJMP_SUPPORTED
  175518. #ifdef USE_FAR_KEYWORD
  175519. if (setjmp(jmpbuf))
  175520. #else
  175521. if (setjmp(png_ptr->jmpbuf))
  175522. #endif
  175523. {
  175524. png_free(png_ptr, png_ptr->zbuf);
  175525. png_ptr->zbuf=NULL;
  175526. png_destroy_struct(png_ptr);
  175527. return (NULL);
  175528. }
  175529. #ifdef USE_FAR_KEYWORD
  175530. png_memcpy(png_ptr->jmpbuf,jmpbuf,png_sizeof(jmp_buf));
  175531. #endif
  175532. #endif
  175533. #ifdef PNG_USER_MEM_SUPPORTED
  175534. png_set_mem_fn(png_ptr, mem_ptr, malloc_fn, free_fn);
  175535. #endif /* PNG_USER_MEM_SUPPORTED */
  175536. png_set_error_fn(png_ptr, error_ptr, error_fn, warn_fn);
  175537. i=0;
  175538. do
  175539. {
  175540. if(user_png_ver[i] != png_libpng_ver[i])
  175541. png_ptr->flags |= PNG_FLAG_LIBRARY_MISMATCH;
  175542. } while (png_libpng_ver[i++]);
  175543. if (png_ptr->flags & PNG_FLAG_LIBRARY_MISMATCH)
  175544. {
  175545. if (user_png_ver == NULL || user_png_ver[0] != png_libpng_ver[0] ||
  175546. (user_png_ver[0] == '1' && user_png_ver[2] != png_libpng_ver[2]) ||
  175547. (user_png_ver[0] == '0' && user_png_ver[2] < '9'))
  175548. {
  175549. #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)
  175550. char msg[80];
  175551. if (user_png_ver)
  175552. {
  175553. png_snprintf(msg, 80,
  175554. "Application was compiled with png.h from libpng-%.20s",
  175555. user_png_ver);
  175556. png_warning(png_ptr, msg);
  175557. }
  175558. png_snprintf(msg, 80,
  175559. "Application is running with png.c from libpng-%.20s",
  175560. png_libpng_ver);
  175561. png_warning(png_ptr, msg);
  175562. #endif
  175563. #ifdef PNG_ERROR_NUMBERS_SUPPORTED
  175564. png_ptr->flags=0;
  175565. #endif
  175566. png_error(png_ptr,
  175567. "Incompatible libpng version in application and library");
  175568. }
  175569. }
  175570. png_ptr->zbuf_size = PNG_ZBUF_SIZE;
  175571. png_ptr->zbuf = (png_bytep)png_malloc(png_ptr,
  175572. (png_uint_32)png_ptr->zbuf_size);
  175573. png_set_write_fn(png_ptr, png_voidp_NULL, png_rw_ptr_NULL,
  175574. png_flush_ptr_NULL);
  175575. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  175576. png_set_filter_heuristics(png_ptr, PNG_FILTER_HEURISTIC_DEFAULT,
  175577. 1, png_doublep_NULL, png_doublep_NULL);
  175578. #endif
  175579. #ifdef PNG_SETJMP_SUPPORTED
  175580. #ifdef USE_FAR_KEYWORD
  175581. if (setjmp(jmpbuf))
  175582. PNG_ABORT();
  175583. png_memcpy(png_ptr->jmpbuf,jmpbuf,png_sizeof(jmp_buf));
  175584. #else
  175585. if (setjmp(png_ptr->jmpbuf))
  175586. PNG_ABORT();
  175587. #endif
  175588. #endif
  175589. return (png_ptr);
  175590. }
  175591. #if defined(PNG_1_0_X) || defined(PNG_1_2_X)
  175592. #undef png_write_init
  175593. void PNGAPI
  175594. png_write_init(png_structp png_ptr)
  175595. {
  175596. png_write_init_2(png_ptr, "1.0.6 or earlier", 0, 0);
  175597. }
  175598. void PNGAPI
  175599. png_write_init_2(png_structp png_ptr, png_const_charp user_png_ver,
  175600. png_size_t png_struct_size, png_size_t png_info_size)
  175601. {
  175602. if(png_ptr == NULL) return;
  175603. #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)
  175604. if(png_sizeof(png_struct) > png_struct_size ||
  175605. png_sizeof(png_info) > png_info_size)
  175606. {
  175607. char msg[80];
  175608. png_ptr->warning_fn=NULL;
  175609. if (user_png_ver)
  175610. {
  175611. png_snprintf(msg, 80,
  175612. "Application was compiled with png.h from libpng-%.20s",
  175613. user_png_ver);
  175614. png_warning(png_ptr, msg);
  175615. }
  175616. png_snprintf(msg, 80,
  175617. "Application is running with png.c from libpng-%.20s",
  175618. png_libpng_ver);
  175619. png_warning(png_ptr, msg);
  175620. }
  175621. #endif
  175622. if(png_sizeof(png_struct) > png_struct_size)
  175623. {
  175624. png_ptr->error_fn=NULL;
  175625. #ifdef PNG_ERROR_NUMBERS_SUPPORTED
  175626. png_ptr->flags=0;
  175627. #endif
  175628. png_error(png_ptr,
  175629. "The png struct allocated by the application for writing is too small.");
  175630. }
  175631. if(png_sizeof(png_info) > png_info_size)
  175632. {
  175633. png_ptr->error_fn=NULL;
  175634. #ifdef PNG_ERROR_NUMBERS_SUPPORTED
  175635. png_ptr->flags=0;
  175636. #endif
  175637. png_error(png_ptr,
  175638. "The info struct allocated by the application for writing is too small.");
  175639. }
  175640. png_write_init_3(&png_ptr, user_png_ver, png_struct_size);
  175641. }
  175642. #endif /* PNG_1_0_X || PNG_1_2_X */
  175643. void PNGAPI
  175644. png_write_init_3(png_structpp ptr_ptr, png_const_charp user_png_ver,
  175645. png_size_t png_struct_size)
  175646. {
  175647. png_structp png_ptr=*ptr_ptr;
  175648. #ifdef PNG_SETJMP_SUPPORTED
  175649. jmp_buf tmp_jmp; /* to save current jump buffer */
  175650. #endif
  175651. int i = 0;
  175652. if (png_ptr == NULL)
  175653. return;
  175654. do
  175655. {
  175656. if (user_png_ver[i] != png_libpng_ver[i])
  175657. {
  175658. #ifdef PNG_LEGACY_SUPPORTED
  175659. png_ptr->flags |= PNG_FLAG_LIBRARY_MISMATCH;
  175660. #else
  175661. png_ptr->warning_fn=NULL;
  175662. png_warning(png_ptr,
  175663. "Application uses deprecated png_write_init() and should be recompiled.");
  175664. break;
  175665. #endif
  175666. }
  175667. } while (png_libpng_ver[i++]);
  175668. png_debug(1, "in png_write_init_3\n");
  175669. #ifdef PNG_SETJMP_SUPPORTED
  175670. png_memcpy(tmp_jmp, png_ptr->jmpbuf, png_sizeof (jmp_buf));
  175671. #endif
  175672. if (png_sizeof(png_struct) > png_struct_size)
  175673. {
  175674. png_destroy_struct(png_ptr);
  175675. png_ptr = (png_structp)png_create_struct(PNG_STRUCT_PNG);
  175676. *ptr_ptr = png_ptr;
  175677. }
  175678. png_memset(png_ptr, 0, png_sizeof (png_struct));
  175679. #ifdef PNG_SET_USER_LIMITS_SUPPORTED
  175680. png_ptr->user_width_max=PNG_USER_WIDTH_MAX;
  175681. png_ptr->user_height_max=PNG_USER_HEIGHT_MAX;
  175682. #endif
  175683. #ifdef PNG_SETJMP_SUPPORTED
  175684. png_memcpy(png_ptr->jmpbuf, tmp_jmp, png_sizeof (jmp_buf));
  175685. #endif
  175686. png_set_write_fn(png_ptr, png_voidp_NULL, png_rw_ptr_NULL,
  175687. png_flush_ptr_NULL);
  175688. png_ptr->zbuf_size = PNG_ZBUF_SIZE;
  175689. png_ptr->zbuf = (png_bytep)png_malloc(png_ptr,
  175690. (png_uint_32)png_ptr->zbuf_size);
  175691. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  175692. png_set_filter_heuristics(png_ptr, PNG_FILTER_HEURISTIC_DEFAULT,
  175693. 1, png_doublep_NULL, png_doublep_NULL);
  175694. #endif
  175695. }
  175696. void PNGAPI
  175697. png_write_rows(png_structp png_ptr, png_bytepp row,
  175698. png_uint_32 num_rows)
  175699. {
  175700. png_uint_32 i; /* row counter */
  175701. png_bytepp rp; /* row pointer */
  175702. png_debug(1, "in png_write_rows\n");
  175703. if (png_ptr == NULL)
  175704. return;
  175705. for (i = 0, rp = row; i < num_rows; i++, rp++)
  175706. {
  175707. png_write_row(png_ptr, *rp);
  175708. }
  175709. }
  175710. void PNGAPI
  175711. png_write_image(png_structp png_ptr, png_bytepp image)
  175712. {
  175713. png_uint_32 i; /* row index */
  175714. int pass, num_pass; /* pass variables */
  175715. png_bytepp rp; /* points to current row */
  175716. if (png_ptr == NULL)
  175717. return;
  175718. png_debug(1, "in png_write_image\n");
  175719. #if defined(PNG_WRITE_INTERLACING_SUPPORTED)
  175720. num_pass = png_set_interlace_handling(png_ptr);
  175721. #else
  175722. num_pass = 1;
  175723. #endif
  175724. for (pass = 0; pass < num_pass; pass++)
  175725. {
  175726. for (i = 0, rp = image; i < png_ptr->height; i++, rp++)
  175727. {
  175728. png_write_row(png_ptr, *rp);
  175729. }
  175730. }
  175731. }
  175732. void PNGAPI
  175733. png_write_row(png_structp png_ptr, png_bytep row)
  175734. {
  175735. if (png_ptr == NULL)
  175736. return;
  175737. png_debug2(1, "in png_write_row (row %ld, pass %d)\n",
  175738. png_ptr->row_number, png_ptr->pass);
  175739. if (png_ptr->row_number == 0 && png_ptr->pass == 0)
  175740. {
  175741. if (!(png_ptr->mode & PNG_WROTE_INFO_BEFORE_PLTE))
  175742. png_error(png_ptr,
  175743. "png_write_info was never called before png_write_row.");
  175744. #if !defined(PNG_WRITE_INVERT_SUPPORTED) && defined(PNG_READ_INVERT_SUPPORTED)
  175745. if (png_ptr->transformations & PNG_INVERT_MONO)
  175746. png_warning(png_ptr, "PNG_WRITE_INVERT_SUPPORTED is not defined.");
  175747. #endif
  175748. #if !defined(PNG_WRITE_FILLER_SUPPORTED) && defined(PNG_READ_FILLER_SUPPORTED)
  175749. if (png_ptr->transformations & PNG_FILLER)
  175750. png_warning(png_ptr, "PNG_WRITE_FILLER_SUPPORTED is not defined.");
  175751. #endif
  175752. #if !defined(PNG_WRITE_PACKSWAP_SUPPORTED) && defined(PNG_READ_PACKSWAP_SUPPORTED)
  175753. if (png_ptr->transformations & PNG_PACKSWAP)
  175754. png_warning(png_ptr, "PNG_WRITE_PACKSWAP_SUPPORTED is not defined.");
  175755. #endif
  175756. #if !defined(PNG_WRITE_PACK_SUPPORTED) && defined(PNG_READ_PACK_SUPPORTED)
  175757. if (png_ptr->transformations & PNG_PACK)
  175758. png_warning(png_ptr, "PNG_WRITE_PACK_SUPPORTED is not defined.");
  175759. #endif
  175760. #if !defined(PNG_WRITE_SHIFT_SUPPORTED) && defined(PNG_READ_SHIFT_SUPPORTED)
  175761. if (png_ptr->transformations & PNG_SHIFT)
  175762. png_warning(png_ptr, "PNG_WRITE_SHIFT_SUPPORTED is not defined.");
  175763. #endif
  175764. #if !defined(PNG_WRITE_BGR_SUPPORTED) && defined(PNG_READ_BGR_SUPPORTED)
  175765. if (png_ptr->transformations & PNG_BGR)
  175766. png_warning(png_ptr, "PNG_WRITE_BGR_SUPPORTED is not defined.");
  175767. #endif
  175768. #if !defined(PNG_WRITE_SWAP_SUPPORTED) && defined(PNG_READ_SWAP_SUPPORTED)
  175769. if (png_ptr->transformations & PNG_SWAP_BYTES)
  175770. png_warning(png_ptr, "PNG_WRITE_SWAP_SUPPORTED is not defined.");
  175771. #endif
  175772. png_write_start_row(png_ptr);
  175773. }
  175774. #if defined(PNG_WRITE_INTERLACING_SUPPORTED)
  175775. if (png_ptr->interlaced && (png_ptr->transformations & PNG_INTERLACE))
  175776. {
  175777. switch (png_ptr->pass)
  175778. {
  175779. case 0:
  175780. if (png_ptr->row_number & 0x07)
  175781. {
  175782. png_write_finish_row(png_ptr);
  175783. return;
  175784. }
  175785. break;
  175786. case 1:
  175787. if ((png_ptr->row_number & 0x07) || png_ptr->width < 5)
  175788. {
  175789. png_write_finish_row(png_ptr);
  175790. return;
  175791. }
  175792. break;
  175793. case 2:
  175794. if ((png_ptr->row_number & 0x07) != 4)
  175795. {
  175796. png_write_finish_row(png_ptr);
  175797. return;
  175798. }
  175799. break;
  175800. case 3:
  175801. if ((png_ptr->row_number & 0x03) || png_ptr->width < 3)
  175802. {
  175803. png_write_finish_row(png_ptr);
  175804. return;
  175805. }
  175806. break;
  175807. case 4:
  175808. if ((png_ptr->row_number & 0x03) != 2)
  175809. {
  175810. png_write_finish_row(png_ptr);
  175811. return;
  175812. }
  175813. break;
  175814. case 5:
  175815. if ((png_ptr->row_number & 0x01) || png_ptr->width < 2)
  175816. {
  175817. png_write_finish_row(png_ptr);
  175818. return;
  175819. }
  175820. break;
  175821. case 6:
  175822. if (!(png_ptr->row_number & 0x01))
  175823. {
  175824. png_write_finish_row(png_ptr);
  175825. return;
  175826. }
  175827. break;
  175828. }
  175829. }
  175830. #endif
  175831. png_ptr->row_info.color_type = png_ptr->color_type;
  175832. png_ptr->row_info.width = png_ptr->usr_width;
  175833. png_ptr->row_info.channels = png_ptr->usr_channels;
  175834. png_ptr->row_info.bit_depth = png_ptr->usr_bit_depth;
  175835. png_ptr->row_info.pixel_depth = (png_byte)(png_ptr->row_info.bit_depth *
  175836. png_ptr->row_info.channels);
  175837. png_ptr->row_info.rowbytes = PNG_ROWBYTES(png_ptr->row_info.pixel_depth,
  175838. png_ptr->row_info.width);
  175839. png_debug1(3, "row_info->color_type = %d\n", png_ptr->row_info.color_type);
  175840. png_debug1(3, "row_info->width = %lu\n", png_ptr->row_info.width);
  175841. png_debug1(3, "row_info->channels = %d\n", png_ptr->row_info.channels);
  175842. png_debug1(3, "row_info->bit_depth = %d\n", png_ptr->row_info.bit_depth);
  175843. png_debug1(3, "row_info->pixel_depth = %d\n", png_ptr->row_info.pixel_depth);
  175844. png_debug1(3, "row_info->rowbytes = %lu\n", png_ptr->row_info.rowbytes);
  175845. png_memcpy_check(png_ptr, png_ptr->row_buf + 1, row,
  175846. png_ptr->row_info.rowbytes);
  175847. #if defined(PNG_WRITE_INTERLACING_SUPPORTED)
  175848. if (png_ptr->interlaced && png_ptr->pass < 6 &&
  175849. (png_ptr->transformations & PNG_INTERLACE))
  175850. {
  175851. png_do_write_interlace(&(png_ptr->row_info),
  175852. png_ptr->row_buf + 1, png_ptr->pass);
  175853. if (!(png_ptr->row_info.width))
  175854. {
  175855. png_write_finish_row(png_ptr);
  175856. return;
  175857. }
  175858. }
  175859. #endif
  175860. if (png_ptr->transformations)
  175861. png_do_write_transformations(png_ptr);
  175862. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  175863. if((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) &&
  175864. (png_ptr->filter_type == PNG_INTRAPIXEL_DIFFERENCING))
  175865. {
  175866. png_do_write_intrapixel(&(png_ptr->row_info), png_ptr->row_buf + 1);
  175867. }
  175868. #endif
  175869. png_write_find_filter(png_ptr, &(png_ptr->row_info));
  175870. if (png_ptr->write_row_fn != NULL)
  175871. (*(png_ptr->write_row_fn))(png_ptr, png_ptr->row_number, png_ptr->pass);
  175872. }
  175873. #if defined(PNG_WRITE_FLUSH_SUPPORTED)
  175874. void PNGAPI
  175875. png_set_flush(png_structp png_ptr, int nrows)
  175876. {
  175877. png_debug(1, "in png_set_flush\n");
  175878. if (png_ptr == NULL)
  175879. return;
  175880. png_ptr->flush_dist = (nrows < 0 ? 0 : nrows);
  175881. }
  175882. void PNGAPI
  175883. png_write_flush(png_structp png_ptr)
  175884. {
  175885. int wrote_IDAT;
  175886. png_debug(1, "in png_write_flush\n");
  175887. if (png_ptr == NULL)
  175888. return;
  175889. if (png_ptr->row_number >= png_ptr->num_rows)
  175890. return;
  175891. do
  175892. {
  175893. int ret;
  175894. ret = deflate(&png_ptr->zstream, Z_SYNC_FLUSH);
  175895. wrote_IDAT = 0;
  175896. if (ret != Z_OK)
  175897. {
  175898. if (png_ptr->zstream.msg != NULL)
  175899. png_error(png_ptr, png_ptr->zstream.msg);
  175900. else
  175901. png_error(png_ptr, "zlib error");
  175902. }
  175903. if (!(png_ptr->zstream.avail_out))
  175904. {
  175905. png_write_IDAT(png_ptr, png_ptr->zbuf,
  175906. png_ptr->zbuf_size);
  175907. png_ptr->zstream.next_out = png_ptr->zbuf;
  175908. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  175909. wrote_IDAT = 1;
  175910. }
  175911. } while(wrote_IDAT == 1);
  175912. if (png_ptr->zbuf_size != png_ptr->zstream.avail_out)
  175913. {
  175914. png_write_IDAT(png_ptr, png_ptr->zbuf,
  175915. png_ptr->zbuf_size - png_ptr->zstream.avail_out);
  175916. png_ptr->zstream.next_out = png_ptr->zbuf;
  175917. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  175918. }
  175919. png_ptr->flush_rows = 0;
  175920. png_flush(png_ptr);
  175921. }
  175922. #endif /* PNG_WRITE_FLUSH_SUPPORTED */
  175923. void PNGAPI
  175924. png_destroy_write_struct(png_structpp png_ptr_ptr, png_infopp info_ptr_ptr)
  175925. {
  175926. png_structp png_ptr = NULL;
  175927. png_infop info_ptr = NULL;
  175928. #ifdef PNG_USER_MEM_SUPPORTED
  175929. png_free_ptr free_fn = NULL;
  175930. png_voidp mem_ptr = NULL;
  175931. #endif
  175932. png_debug(1, "in png_destroy_write_struct\n");
  175933. if (png_ptr_ptr != NULL)
  175934. {
  175935. png_ptr = *png_ptr_ptr;
  175936. #ifdef PNG_USER_MEM_SUPPORTED
  175937. free_fn = png_ptr->free_fn;
  175938. mem_ptr = png_ptr->mem_ptr;
  175939. #endif
  175940. }
  175941. if (info_ptr_ptr != NULL)
  175942. info_ptr = *info_ptr_ptr;
  175943. if (info_ptr != NULL)
  175944. {
  175945. png_free_data(png_ptr, info_ptr, PNG_FREE_ALL, -1);
  175946. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  175947. if (png_ptr->num_chunk_list)
  175948. {
  175949. png_free(png_ptr, png_ptr->chunk_list);
  175950. png_ptr->chunk_list=NULL;
  175951. png_ptr->num_chunk_list=0;
  175952. }
  175953. #endif
  175954. #ifdef PNG_USER_MEM_SUPPORTED
  175955. png_destroy_struct_2((png_voidp)info_ptr, (png_free_ptr)free_fn,
  175956. (png_voidp)mem_ptr);
  175957. #else
  175958. png_destroy_struct((png_voidp)info_ptr);
  175959. #endif
  175960. *info_ptr_ptr = NULL;
  175961. }
  175962. if (png_ptr != NULL)
  175963. {
  175964. png_write_destroy(png_ptr);
  175965. #ifdef PNG_USER_MEM_SUPPORTED
  175966. png_destroy_struct_2((png_voidp)png_ptr, (png_free_ptr)free_fn,
  175967. (png_voidp)mem_ptr);
  175968. #else
  175969. png_destroy_struct((png_voidp)png_ptr);
  175970. #endif
  175971. *png_ptr_ptr = NULL;
  175972. }
  175973. }
  175974. void /* PRIVATE */
  175975. png_write_destroy(png_structp png_ptr)
  175976. {
  175977. #ifdef PNG_SETJMP_SUPPORTED
  175978. jmp_buf tmp_jmp; /* save jump buffer */
  175979. #endif
  175980. png_error_ptr error_fn;
  175981. png_error_ptr warning_fn;
  175982. png_voidp error_ptr;
  175983. #ifdef PNG_USER_MEM_SUPPORTED
  175984. png_free_ptr free_fn;
  175985. #endif
  175986. png_debug(1, "in png_write_destroy\n");
  175987. deflateEnd(&png_ptr->zstream);
  175988. png_free(png_ptr, png_ptr->zbuf);
  175989. png_free(png_ptr, png_ptr->row_buf);
  175990. png_free(png_ptr, png_ptr->prev_row);
  175991. png_free(png_ptr, png_ptr->sub_row);
  175992. png_free(png_ptr, png_ptr->up_row);
  175993. png_free(png_ptr, png_ptr->avg_row);
  175994. png_free(png_ptr, png_ptr->paeth_row);
  175995. #if defined(PNG_TIME_RFC1123_SUPPORTED)
  175996. png_free(png_ptr, png_ptr->time_buffer);
  175997. #endif
  175998. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  175999. png_free(png_ptr, png_ptr->prev_filters);
  176000. png_free(png_ptr, png_ptr->filter_weights);
  176001. png_free(png_ptr, png_ptr->inv_filter_weights);
  176002. png_free(png_ptr, png_ptr->filter_costs);
  176003. png_free(png_ptr, png_ptr->inv_filter_costs);
  176004. #endif
  176005. #ifdef PNG_SETJMP_SUPPORTED
  176006. png_memcpy(tmp_jmp, png_ptr->jmpbuf, png_sizeof (jmp_buf));
  176007. #endif
  176008. error_fn = png_ptr->error_fn;
  176009. warning_fn = png_ptr->warning_fn;
  176010. error_ptr = png_ptr->error_ptr;
  176011. #ifdef PNG_USER_MEM_SUPPORTED
  176012. free_fn = png_ptr->free_fn;
  176013. #endif
  176014. png_memset(png_ptr, 0, png_sizeof (png_struct));
  176015. png_ptr->error_fn = error_fn;
  176016. png_ptr->warning_fn = warning_fn;
  176017. png_ptr->error_ptr = error_ptr;
  176018. #ifdef PNG_USER_MEM_SUPPORTED
  176019. png_ptr->free_fn = free_fn;
  176020. #endif
  176021. #ifdef PNG_SETJMP_SUPPORTED
  176022. png_memcpy(png_ptr->jmpbuf, tmp_jmp, png_sizeof (jmp_buf));
  176023. #endif
  176024. }
  176025. void PNGAPI
  176026. png_set_filter(png_structp png_ptr, int method, int filters)
  176027. {
  176028. png_debug(1, "in png_set_filter\n");
  176029. if (png_ptr == NULL)
  176030. return;
  176031. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  176032. if((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) &&
  176033. (method == PNG_INTRAPIXEL_DIFFERENCING))
  176034. method = PNG_FILTER_TYPE_BASE;
  176035. #endif
  176036. if (method == PNG_FILTER_TYPE_BASE)
  176037. {
  176038. switch (filters & (PNG_ALL_FILTERS | 0x07))
  176039. {
  176040. #ifndef PNG_NO_WRITE_FILTER
  176041. case 5:
  176042. case 6:
  176043. case 7: png_warning(png_ptr, "Unknown row filter for method 0");
  176044. #endif /* PNG_NO_WRITE_FILTER */
  176045. case PNG_FILTER_VALUE_NONE:
  176046. png_ptr->do_filter=PNG_FILTER_NONE; break;
  176047. #ifndef PNG_NO_WRITE_FILTER
  176048. case PNG_FILTER_VALUE_SUB:
  176049. png_ptr->do_filter=PNG_FILTER_SUB; break;
  176050. case PNG_FILTER_VALUE_UP:
  176051. png_ptr->do_filter=PNG_FILTER_UP; break;
  176052. case PNG_FILTER_VALUE_AVG:
  176053. png_ptr->do_filter=PNG_FILTER_AVG; break;
  176054. case PNG_FILTER_VALUE_PAETH:
  176055. png_ptr->do_filter=PNG_FILTER_PAETH; break;
  176056. default: png_ptr->do_filter = (png_byte)filters; break;
  176057. #else
  176058. default: png_warning(png_ptr, "Unknown row filter for method 0");
  176059. #endif /* PNG_NO_WRITE_FILTER */
  176060. }
  176061. if (png_ptr->row_buf != NULL)
  176062. {
  176063. #ifndef PNG_NO_WRITE_FILTER
  176064. if ((png_ptr->do_filter & PNG_FILTER_SUB) && png_ptr->sub_row == NULL)
  176065. {
  176066. png_ptr->sub_row = (png_bytep)png_malloc(png_ptr,
  176067. (png_ptr->rowbytes + 1));
  176068. png_ptr->sub_row[0] = PNG_FILTER_VALUE_SUB;
  176069. }
  176070. if ((png_ptr->do_filter & PNG_FILTER_UP) && png_ptr->up_row == NULL)
  176071. {
  176072. if (png_ptr->prev_row == NULL)
  176073. {
  176074. png_warning(png_ptr, "Can't add Up filter after starting");
  176075. png_ptr->do_filter &= ~PNG_FILTER_UP;
  176076. }
  176077. else
  176078. {
  176079. png_ptr->up_row = (png_bytep)png_malloc(png_ptr,
  176080. (png_ptr->rowbytes + 1));
  176081. png_ptr->up_row[0] = PNG_FILTER_VALUE_UP;
  176082. }
  176083. }
  176084. if ((png_ptr->do_filter & PNG_FILTER_AVG) && png_ptr->avg_row == NULL)
  176085. {
  176086. if (png_ptr->prev_row == NULL)
  176087. {
  176088. png_warning(png_ptr, "Can't add Average filter after starting");
  176089. png_ptr->do_filter &= ~PNG_FILTER_AVG;
  176090. }
  176091. else
  176092. {
  176093. png_ptr->avg_row = (png_bytep)png_malloc(png_ptr,
  176094. (png_ptr->rowbytes + 1));
  176095. png_ptr->avg_row[0] = PNG_FILTER_VALUE_AVG;
  176096. }
  176097. }
  176098. if ((png_ptr->do_filter & PNG_FILTER_PAETH) &&
  176099. png_ptr->paeth_row == NULL)
  176100. {
  176101. if (png_ptr->prev_row == NULL)
  176102. {
  176103. png_warning(png_ptr, "Can't add Paeth filter after starting");
  176104. png_ptr->do_filter &= (png_byte)(~PNG_FILTER_PAETH);
  176105. }
  176106. else
  176107. {
  176108. png_ptr->paeth_row = (png_bytep)png_malloc(png_ptr,
  176109. (png_ptr->rowbytes + 1));
  176110. png_ptr->paeth_row[0] = PNG_FILTER_VALUE_PAETH;
  176111. }
  176112. }
  176113. if (png_ptr->do_filter == PNG_NO_FILTERS)
  176114. #endif /* PNG_NO_WRITE_FILTER */
  176115. png_ptr->do_filter = PNG_FILTER_NONE;
  176116. }
  176117. }
  176118. else
  176119. png_error(png_ptr, "Unknown custom filter method");
  176120. }
  176121. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED) /* GRR 970116 */
  176122. void PNGAPI
  176123. png_set_filter_heuristics(png_structp png_ptr, int heuristic_method,
  176124. int num_weights, png_doublep filter_weights,
  176125. png_doublep filter_costs)
  176126. {
  176127. int i;
  176128. png_debug(1, "in png_set_filter_heuristics\n");
  176129. if (png_ptr == NULL)
  176130. return;
  176131. if (heuristic_method >= PNG_FILTER_HEURISTIC_LAST)
  176132. {
  176133. png_warning(png_ptr, "Unknown filter heuristic method");
  176134. return;
  176135. }
  176136. if (heuristic_method == PNG_FILTER_HEURISTIC_DEFAULT)
  176137. {
  176138. heuristic_method = PNG_FILTER_HEURISTIC_UNWEIGHTED;
  176139. }
  176140. if (num_weights < 0 || filter_weights == NULL ||
  176141. heuristic_method == PNG_FILTER_HEURISTIC_UNWEIGHTED)
  176142. {
  176143. num_weights = 0;
  176144. }
  176145. png_ptr->num_prev_filters = (png_byte)num_weights;
  176146. png_ptr->heuristic_method = (png_byte)heuristic_method;
  176147. if (num_weights > 0)
  176148. {
  176149. if (png_ptr->prev_filters == NULL)
  176150. {
  176151. png_ptr->prev_filters = (png_bytep)png_malloc(png_ptr,
  176152. (png_uint_32)(png_sizeof(png_byte) * num_weights));
  176153. for (i = 0; i < num_weights; i++)
  176154. {
  176155. png_ptr->prev_filters[i] = 255;
  176156. }
  176157. }
  176158. if (png_ptr->filter_weights == NULL)
  176159. {
  176160. png_ptr->filter_weights = (png_uint_16p)png_malloc(png_ptr,
  176161. (png_uint_32)(png_sizeof(png_uint_16) * num_weights));
  176162. png_ptr->inv_filter_weights = (png_uint_16p)png_malloc(png_ptr,
  176163. (png_uint_32)(png_sizeof(png_uint_16) * num_weights));
  176164. for (i = 0; i < num_weights; i++)
  176165. {
  176166. png_ptr->inv_filter_weights[i] =
  176167. png_ptr->filter_weights[i] = PNG_WEIGHT_FACTOR;
  176168. }
  176169. }
  176170. for (i = 0; i < num_weights; i++)
  176171. {
  176172. if (filter_weights[i] < 0.0)
  176173. {
  176174. png_ptr->inv_filter_weights[i] =
  176175. png_ptr->filter_weights[i] = PNG_WEIGHT_FACTOR;
  176176. }
  176177. else
  176178. {
  176179. png_ptr->inv_filter_weights[i] =
  176180. (png_uint_16)((double)PNG_WEIGHT_FACTOR*filter_weights[i]+0.5);
  176181. png_ptr->filter_weights[i] =
  176182. (png_uint_16)((double)PNG_WEIGHT_FACTOR/filter_weights[i]+0.5);
  176183. }
  176184. }
  176185. }
  176186. if (png_ptr->filter_costs == NULL)
  176187. {
  176188. png_ptr->filter_costs = (png_uint_16p)png_malloc(png_ptr,
  176189. (png_uint_32)(png_sizeof(png_uint_16) * PNG_FILTER_VALUE_LAST));
  176190. png_ptr->inv_filter_costs = (png_uint_16p)png_malloc(png_ptr,
  176191. (png_uint_32)(png_sizeof(png_uint_16) * PNG_FILTER_VALUE_LAST));
  176192. for (i = 0; i < PNG_FILTER_VALUE_LAST; i++)
  176193. {
  176194. png_ptr->inv_filter_costs[i] =
  176195. png_ptr->filter_costs[i] = PNG_COST_FACTOR;
  176196. }
  176197. }
  176198. for (i = 0; i < PNG_FILTER_VALUE_LAST; i++)
  176199. {
  176200. if (filter_costs == NULL || filter_costs[i] < 0.0)
  176201. {
  176202. png_ptr->inv_filter_costs[i] =
  176203. png_ptr->filter_costs[i] = PNG_COST_FACTOR;
  176204. }
  176205. else if (filter_costs[i] >= 1.0)
  176206. {
  176207. png_ptr->inv_filter_costs[i] =
  176208. (png_uint_16)((double)PNG_COST_FACTOR / filter_costs[i] + 0.5);
  176209. png_ptr->filter_costs[i] =
  176210. (png_uint_16)((double)PNG_COST_FACTOR * filter_costs[i] + 0.5);
  176211. }
  176212. }
  176213. }
  176214. #endif /* PNG_WRITE_WEIGHTED_FILTER_SUPPORTED */
  176215. void PNGAPI
  176216. png_set_compression_level(png_structp png_ptr, int level)
  176217. {
  176218. png_debug(1, "in png_set_compression_level\n");
  176219. if (png_ptr == NULL)
  176220. return;
  176221. png_ptr->flags |= PNG_FLAG_ZLIB_CUSTOM_LEVEL;
  176222. png_ptr->zlib_level = level;
  176223. }
  176224. void PNGAPI
  176225. png_set_compression_mem_level(png_structp png_ptr, int mem_level)
  176226. {
  176227. png_debug(1, "in png_set_compression_mem_level\n");
  176228. if (png_ptr == NULL)
  176229. return;
  176230. png_ptr->flags |= PNG_FLAG_ZLIB_CUSTOM_MEM_LEVEL;
  176231. png_ptr->zlib_mem_level = mem_level;
  176232. }
  176233. void PNGAPI
  176234. png_set_compression_strategy(png_structp png_ptr, int strategy)
  176235. {
  176236. png_debug(1, "in png_set_compression_strategy\n");
  176237. if (png_ptr == NULL)
  176238. return;
  176239. png_ptr->flags |= PNG_FLAG_ZLIB_CUSTOM_STRATEGY;
  176240. png_ptr->zlib_strategy = strategy;
  176241. }
  176242. void PNGAPI
  176243. png_set_compression_window_bits(png_structp png_ptr, int window_bits)
  176244. {
  176245. if (png_ptr == NULL)
  176246. return;
  176247. if (window_bits > 15)
  176248. png_warning(png_ptr, "Only compression windows <= 32k supported by PNG");
  176249. else if (window_bits < 8)
  176250. png_warning(png_ptr, "Only compression windows >= 256 supported by PNG");
  176251. #ifndef WBITS_8_OK
  176252. if (window_bits == 8)
  176253. {
  176254. png_warning(png_ptr, "Compression window is being reset to 512");
  176255. window_bits=9;
  176256. }
  176257. #endif
  176258. png_ptr->flags |= PNG_FLAG_ZLIB_CUSTOM_WINDOW_BITS;
  176259. png_ptr->zlib_window_bits = window_bits;
  176260. }
  176261. void PNGAPI
  176262. png_set_compression_method(png_structp png_ptr, int method)
  176263. {
  176264. png_debug(1, "in png_set_compression_method\n");
  176265. if (png_ptr == NULL)
  176266. return;
  176267. if (method != 8)
  176268. png_warning(png_ptr, "Only compression method 8 is supported by PNG");
  176269. png_ptr->flags |= PNG_FLAG_ZLIB_CUSTOM_METHOD;
  176270. png_ptr->zlib_method = method;
  176271. }
  176272. void PNGAPI
  176273. png_set_write_status_fn(png_structp png_ptr, png_write_status_ptr write_row_fn)
  176274. {
  176275. if (png_ptr == NULL)
  176276. return;
  176277. png_ptr->write_row_fn = write_row_fn;
  176278. }
  176279. #if defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED)
  176280. void PNGAPI
  176281. png_set_write_user_transform_fn(png_structp png_ptr, png_user_transform_ptr
  176282. write_user_transform_fn)
  176283. {
  176284. png_debug(1, "in png_set_write_user_transform_fn\n");
  176285. if (png_ptr == NULL)
  176286. return;
  176287. png_ptr->transformations |= PNG_USER_TRANSFORM;
  176288. png_ptr->write_user_transform_fn = write_user_transform_fn;
  176289. }
  176290. #endif
  176291. #if defined(PNG_INFO_IMAGE_SUPPORTED)
  176292. void PNGAPI
  176293. png_write_png(png_structp png_ptr, png_infop info_ptr,
  176294. int transforms, voidp params)
  176295. {
  176296. if (png_ptr == NULL || info_ptr == NULL)
  176297. return;
  176298. #if defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED)
  176299. if (transforms & PNG_TRANSFORM_INVERT_ALPHA)
  176300. png_set_invert_alpha(png_ptr);
  176301. #endif
  176302. png_write_info(png_ptr, info_ptr);
  176303. #if defined(PNG_WRITE_INVERT_SUPPORTED)
  176304. if (transforms & PNG_TRANSFORM_INVERT_MONO)
  176305. png_set_invert_mono(png_ptr);
  176306. #endif
  176307. #if defined(PNG_WRITE_SHIFT_SUPPORTED)
  176308. if ((transforms & PNG_TRANSFORM_SHIFT)
  176309. && (info_ptr->valid & PNG_INFO_sBIT))
  176310. png_set_shift(png_ptr, &info_ptr->sig_bit);
  176311. #endif
  176312. #if defined(PNG_WRITE_PACK_SUPPORTED)
  176313. if (transforms & PNG_TRANSFORM_PACKING)
  176314. png_set_packing(png_ptr);
  176315. #endif
  176316. #if defined(PNG_WRITE_SWAP_ALPHA_SUPPORTED)
  176317. if (transforms & PNG_TRANSFORM_SWAP_ALPHA)
  176318. png_set_swap_alpha(png_ptr);
  176319. #endif
  176320. #if defined(PNG_WRITE_FILLER_SUPPORTED)
  176321. if (transforms & PNG_TRANSFORM_STRIP_FILLER)
  176322. png_set_filler(png_ptr, 0, PNG_FILLER_BEFORE);
  176323. #endif
  176324. #if defined(PNG_WRITE_BGR_SUPPORTED)
  176325. if (transforms & PNG_TRANSFORM_BGR)
  176326. png_set_bgr(png_ptr);
  176327. #endif
  176328. #if defined(PNG_WRITE_SWAP_SUPPORTED)
  176329. if (transforms & PNG_TRANSFORM_SWAP_ENDIAN)
  176330. png_set_swap(png_ptr);
  176331. #endif
  176332. #if defined(PNG_WRITE_PACKSWAP_SUPPORTED)
  176333. if (transforms & PNG_TRANSFORM_PACKSWAP)
  176334. png_set_packswap(png_ptr);
  176335. #endif
  176336. if (info_ptr->valid & PNG_INFO_IDAT)
  176337. png_write_image(png_ptr, info_ptr->row_pointers);
  176338. png_write_end(png_ptr, info_ptr);
  176339. transforms = transforms; /* quiet compiler warnings */
  176340. params = params;
  176341. }
  176342. #endif
  176343. #endif /* PNG_WRITE_SUPPORTED */
  176344. /*** End of inlined file: pngwrite.c ***/
  176345. /*** Start of inlined file: pngwtran.c ***/
  176346. #define PNG_INTERNAL
  176347. #ifdef PNG_WRITE_SUPPORTED
  176348. void /* PRIVATE */
  176349. png_do_write_transformations(png_structp png_ptr)
  176350. {
  176351. png_debug(1, "in png_do_write_transformations\n");
  176352. if (png_ptr == NULL)
  176353. return;
  176354. #if defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED)
  176355. if (png_ptr->transformations & PNG_USER_TRANSFORM)
  176356. if(png_ptr->write_user_transform_fn != NULL)
  176357. (*(png_ptr->write_user_transform_fn)) /* user write transform function */
  176358. (png_ptr, /* png_ptr */
  176359. &(png_ptr->row_info), /* row_info: */
  176360. png_ptr->row_buf + 1); /* start of pixel data for row */
  176361. #endif
  176362. #if defined(PNG_WRITE_FILLER_SUPPORTED)
  176363. if (png_ptr->transformations & PNG_FILLER)
  176364. png_do_strip_filler(&(png_ptr->row_info), png_ptr->row_buf + 1,
  176365. png_ptr->flags);
  176366. #endif
  176367. #if defined(PNG_WRITE_PACKSWAP_SUPPORTED)
  176368. if (png_ptr->transformations & PNG_PACKSWAP)
  176369. png_do_packswap(&(png_ptr->row_info), png_ptr->row_buf + 1);
  176370. #endif
  176371. #if defined(PNG_WRITE_PACK_SUPPORTED)
  176372. if (png_ptr->transformations & PNG_PACK)
  176373. png_do_pack(&(png_ptr->row_info), png_ptr->row_buf + 1,
  176374. (png_uint_32)png_ptr->bit_depth);
  176375. #endif
  176376. #if defined(PNG_WRITE_SWAP_SUPPORTED)
  176377. if (png_ptr->transformations & PNG_SWAP_BYTES)
  176378. png_do_swap(&(png_ptr->row_info), png_ptr->row_buf + 1);
  176379. #endif
  176380. #if defined(PNG_WRITE_SHIFT_SUPPORTED)
  176381. if (png_ptr->transformations & PNG_SHIFT)
  176382. png_do_shift(&(png_ptr->row_info), png_ptr->row_buf + 1,
  176383. &(png_ptr->shift));
  176384. #endif
  176385. #if defined(PNG_WRITE_SWAP_ALPHA_SUPPORTED)
  176386. if (png_ptr->transformations & PNG_SWAP_ALPHA)
  176387. png_do_write_swap_alpha(&(png_ptr->row_info), png_ptr->row_buf + 1);
  176388. #endif
  176389. #if defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED)
  176390. if (png_ptr->transformations & PNG_INVERT_ALPHA)
  176391. png_do_write_invert_alpha(&(png_ptr->row_info), png_ptr->row_buf + 1);
  176392. #endif
  176393. #if defined(PNG_WRITE_BGR_SUPPORTED)
  176394. if (png_ptr->transformations & PNG_BGR)
  176395. png_do_bgr(&(png_ptr->row_info), png_ptr->row_buf + 1);
  176396. #endif
  176397. #if defined(PNG_WRITE_INVERT_SUPPORTED)
  176398. if (png_ptr->transformations & PNG_INVERT_MONO)
  176399. png_do_invert(&(png_ptr->row_info), png_ptr->row_buf + 1);
  176400. #endif
  176401. }
  176402. #if defined(PNG_WRITE_PACK_SUPPORTED)
  176403. void /* PRIVATE */
  176404. png_do_pack(png_row_infop row_info, png_bytep row, png_uint_32 bit_depth)
  176405. {
  176406. png_debug(1, "in png_do_pack\n");
  176407. if (row_info->bit_depth == 8 &&
  176408. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  176409. row != NULL && row_info != NULL &&
  176410. #endif
  176411. row_info->channels == 1)
  176412. {
  176413. switch ((int)bit_depth)
  176414. {
  176415. case 1:
  176416. {
  176417. png_bytep sp, dp;
  176418. int mask, v;
  176419. png_uint_32 i;
  176420. png_uint_32 row_width = row_info->width;
  176421. sp = row;
  176422. dp = row;
  176423. mask = 0x80;
  176424. v = 0;
  176425. for (i = 0; i < row_width; i++)
  176426. {
  176427. if (*sp != 0)
  176428. v |= mask;
  176429. sp++;
  176430. if (mask > 1)
  176431. mask >>= 1;
  176432. else
  176433. {
  176434. mask = 0x80;
  176435. *dp = (png_byte)v;
  176436. dp++;
  176437. v = 0;
  176438. }
  176439. }
  176440. if (mask != 0x80)
  176441. *dp = (png_byte)v;
  176442. break;
  176443. }
  176444. case 2:
  176445. {
  176446. png_bytep sp, dp;
  176447. int shift, v;
  176448. png_uint_32 i;
  176449. png_uint_32 row_width = row_info->width;
  176450. sp = row;
  176451. dp = row;
  176452. shift = 6;
  176453. v = 0;
  176454. for (i = 0; i < row_width; i++)
  176455. {
  176456. png_byte value;
  176457. value = (png_byte)(*sp & 0x03);
  176458. v |= (value << shift);
  176459. if (shift == 0)
  176460. {
  176461. shift = 6;
  176462. *dp = (png_byte)v;
  176463. dp++;
  176464. v = 0;
  176465. }
  176466. else
  176467. shift -= 2;
  176468. sp++;
  176469. }
  176470. if (shift != 6)
  176471. *dp = (png_byte)v;
  176472. break;
  176473. }
  176474. case 4:
  176475. {
  176476. png_bytep sp, dp;
  176477. int shift, v;
  176478. png_uint_32 i;
  176479. png_uint_32 row_width = row_info->width;
  176480. sp = row;
  176481. dp = row;
  176482. shift = 4;
  176483. v = 0;
  176484. for (i = 0; i < row_width; i++)
  176485. {
  176486. png_byte value;
  176487. value = (png_byte)(*sp & 0x0f);
  176488. v |= (value << shift);
  176489. if (shift == 0)
  176490. {
  176491. shift = 4;
  176492. *dp = (png_byte)v;
  176493. dp++;
  176494. v = 0;
  176495. }
  176496. else
  176497. shift -= 4;
  176498. sp++;
  176499. }
  176500. if (shift != 4)
  176501. *dp = (png_byte)v;
  176502. break;
  176503. }
  176504. }
  176505. row_info->bit_depth = (png_byte)bit_depth;
  176506. row_info->pixel_depth = (png_byte)(bit_depth * row_info->channels);
  176507. row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,
  176508. row_info->width);
  176509. }
  176510. }
  176511. #endif
  176512. #if defined(PNG_WRITE_SHIFT_SUPPORTED)
  176513. void /* PRIVATE */
  176514. png_do_shift(png_row_infop row_info, png_bytep row, png_color_8p bit_depth)
  176515. {
  176516. png_debug(1, "in png_do_shift\n");
  176517. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  176518. if (row != NULL && row_info != NULL &&
  176519. #else
  176520. if (
  176521. #endif
  176522. row_info->color_type != PNG_COLOR_TYPE_PALETTE)
  176523. {
  176524. int shift_start[4], shift_dec[4];
  176525. int channels = 0;
  176526. if (row_info->color_type & PNG_COLOR_MASK_COLOR)
  176527. {
  176528. shift_start[channels] = row_info->bit_depth - bit_depth->red;
  176529. shift_dec[channels] = bit_depth->red;
  176530. channels++;
  176531. shift_start[channels] = row_info->bit_depth - bit_depth->green;
  176532. shift_dec[channels] = bit_depth->green;
  176533. channels++;
  176534. shift_start[channels] = row_info->bit_depth - bit_depth->blue;
  176535. shift_dec[channels] = bit_depth->blue;
  176536. channels++;
  176537. }
  176538. else
  176539. {
  176540. shift_start[channels] = row_info->bit_depth - bit_depth->gray;
  176541. shift_dec[channels] = bit_depth->gray;
  176542. channels++;
  176543. }
  176544. if (row_info->color_type & PNG_COLOR_MASK_ALPHA)
  176545. {
  176546. shift_start[channels] = row_info->bit_depth - bit_depth->alpha;
  176547. shift_dec[channels] = bit_depth->alpha;
  176548. channels++;
  176549. }
  176550. if (row_info->bit_depth < 8)
  176551. {
  176552. png_bytep bp = row;
  176553. png_uint_32 i;
  176554. png_byte mask;
  176555. png_uint_32 row_bytes = row_info->rowbytes;
  176556. if (bit_depth->gray == 1 && row_info->bit_depth == 2)
  176557. mask = 0x55;
  176558. else if (row_info->bit_depth == 4 && bit_depth->gray == 3)
  176559. mask = 0x11;
  176560. else
  176561. mask = 0xff;
  176562. for (i = 0; i < row_bytes; i++, bp++)
  176563. {
  176564. png_uint_16 v;
  176565. int j;
  176566. v = *bp;
  176567. *bp = 0;
  176568. for (j = shift_start[0]; j > -shift_dec[0]; j -= shift_dec[0])
  176569. {
  176570. if (j > 0)
  176571. *bp |= (png_byte)((v << j) & 0xff);
  176572. else
  176573. *bp |= (png_byte)((v >> (-j)) & mask);
  176574. }
  176575. }
  176576. }
  176577. else if (row_info->bit_depth == 8)
  176578. {
  176579. png_bytep bp = row;
  176580. png_uint_32 i;
  176581. png_uint_32 istop = channels * row_info->width;
  176582. for (i = 0; i < istop; i++, bp++)
  176583. {
  176584. png_uint_16 v;
  176585. int j;
  176586. int c = (int)(i%channels);
  176587. v = *bp;
  176588. *bp = 0;
  176589. for (j = shift_start[c]; j > -shift_dec[c]; j -= shift_dec[c])
  176590. {
  176591. if (j > 0)
  176592. *bp |= (png_byte)((v << j) & 0xff);
  176593. else
  176594. *bp |= (png_byte)((v >> (-j)) & 0xff);
  176595. }
  176596. }
  176597. }
  176598. else
  176599. {
  176600. png_bytep bp;
  176601. png_uint_32 i;
  176602. png_uint_32 istop = channels * row_info->width;
  176603. for (bp = row, i = 0; i < istop; i++)
  176604. {
  176605. int c = (int)(i%channels);
  176606. png_uint_16 value, v;
  176607. int j;
  176608. v = (png_uint_16)(((png_uint_16)(*bp) << 8) + *(bp + 1));
  176609. value = 0;
  176610. for (j = shift_start[c]; j > -shift_dec[c]; j -= shift_dec[c])
  176611. {
  176612. if (j > 0)
  176613. value |= (png_uint_16)((v << j) & (png_uint_16)0xffff);
  176614. else
  176615. value |= (png_uint_16)((v >> (-j)) & (png_uint_16)0xffff);
  176616. }
  176617. *bp++ = (png_byte)(value >> 8);
  176618. *bp++ = (png_byte)(value & 0xff);
  176619. }
  176620. }
  176621. }
  176622. }
  176623. #endif
  176624. #if defined(PNG_WRITE_SWAP_ALPHA_SUPPORTED)
  176625. void /* PRIVATE */
  176626. png_do_write_swap_alpha(png_row_infop row_info, png_bytep row)
  176627. {
  176628. png_debug(1, "in png_do_write_swap_alpha\n");
  176629. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  176630. if (row != NULL && row_info != NULL)
  176631. #endif
  176632. {
  176633. if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  176634. {
  176635. if (row_info->bit_depth == 8)
  176636. {
  176637. png_bytep sp, dp;
  176638. png_uint_32 i;
  176639. png_uint_32 row_width = row_info->width;
  176640. for (i = 0, sp = dp = row; i < row_width; i++)
  176641. {
  176642. png_byte save = *(sp++);
  176643. *(dp++) = *(sp++);
  176644. *(dp++) = *(sp++);
  176645. *(dp++) = *(sp++);
  176646. *(dp++) = save;
  176647. }
  176648. }
  176649. else
  176650. {
  176651. png_bytep sp, dp;
  176652. png_uint_32 i;
  176653. png_uint_32 row_width = row_info->width;
  176654. for (i = 0, sp = dp = row; i < row_width; i++)
  176655. {
  176656. png_byte save[2];
  176657. save[0] = *(sp++);
  176658. save[1] = *(sp++);
  176659. *(dp++) = *(sp++);
  176660. *(dp++) = *(sp++);
  176661. *(dp++) = *(sp++);
  176662. *(dp++) = *(sp++);
  176663. *(dp++) = *(sp++);
  176664. *(dp++) = *(sp++);
  176665. *(dp++) = save[0];
  176666. *(dp++) = save[1];
  176667. }
  176668. }
  176669. }
  176670. else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
  176671. {
  176672. if (row_info->bit_depth == 8)
  176673. {
  176674. png_bytep sp, dp;
  176675. png_uint_32 i;
  176676. png_uint_32 row_width = row_info->width;
  176677. for (i = 0, sp = dp = row; i < row_width; i++)
  176678. {
  176679. png_byte save = *(sp++);
  176680. *(dp++) = *(sp++);
  176681. *(dp++) = save;
  176682. }
  176683. }
  176684. else
  176685. {
  176686. png_bytep sp, dp;
  176687. png_uint_32 i;
  176688. png_uint_32 row_width = row_info->width;
  176689. for (i = 0, sp = dp = row; i < row_width; i++)
  176690. {
  176691. png_byte save[2];
  176692. save[0] = *(sp++);
  176693. save[1] = *(sp++);
  176694. *(dp++) = *(sp++);
  176695. *(dp++) = *(sp++);
  176696. *(dp++) = save[0];
  176697. *(dp++) = save[1];
  176698. }
  176699. }
  176700. }
  176701. }
  176702. }
  176703. #endif
  176704. #if defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED)
  176705. void /* PRIVATE */
  176706. png_do_write_invert_alpha(png_row_infop row_info, png_bytep row)
  176707. {
  176708. png_debug(1, "in png_do_write_invert_alpha\n");
  176709. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  176710. if (row != NULL && row_info != NULL)
  176711. #endif
  176712. {
  176713. if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  176714. {
  176715. if (row_info->bit_depth == 8)
  176716. {
  176717. png_bytep sp, dp;
  176718. png_uint_32 i;
  176719. png_uint_32 row_width = row_info->width;
  176720. for (i = 0, sp = dp = row; i < row_width; i++)
  176721. {
  176722. sp+=3; dp = sp;
  176723. *(dp++) = (png_byte)(255 - *(sp++));
  176724. }
  176725. }
  176726. else
  176727. {
  176728. png_bytep sp, dp;
  176729. png_uint_32 i;
  176730. png_uint_32 row_width = row_info->width;
  176731. for (i = 0, sp = dp = row; i < row_width; i++)
  176732. {
  176733. sp+=6; dp = sp;
  176734. *(dp++) = (png_byte)(255 - *(sp++));
  176735. *(dp++) = (png_byte)(255 - *(sp++));
  176736. }
  176737. }
  176738. }
  176739. else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
  176740. {
  176741. if (row_info->bit_depth == 8)
  176742. {
  176743. png_bytep sp, dp;
  176744. png_uint_32 i;
  176745. png_uint_32 row_width = row_info->width;
  176746. for (i = 0, sp = dp = row; i < row_width; i++)
  176747. {
  176748. *(dp++) = *(sp++);
  176749. *(dp++) = (png_byte)(255 - *(sp++));
  176750. }
  176751. }
  176752. else
  176753. {
  176754. png_bytep sp, dp;
  176755. png_uint_32 i;
  176756. png_uint_32 row_width = row_info->width;
  176757. for (i = 0, sp = dp = row; i < row_width; i++)
  176758. {
  176759. sp+=2; dp = sp;
  176760. *(dp++) = (png_byte)(255 - *(sp++));
  176761. *(dp++) = (png_byte)(255 - *(sp++));
  176762. }
  176763. }
  176764. }
  176765. }
  176766. }
  176767. #endif
  176768. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  176769. void /* PRIVATE */
  176770. png_do_write_intrapixel(png_row_infop row_info, png_bytep row)
  176771. {
  176772. png_debug(1, "in png_do_write_intrapixel\n");
  176773. if (
  176774. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  176775. row != NULL && row_info != NULL &&
  176776. #endif
  176777. (row_info->color_type & PNG_COLOR_MASK_COLOR))
  176778. {
  176779. int bytes_per_pixel;
  176780. png_uint_32 row_width = row_info->width;
  176781. if (row_info->bit_depth == 8)
  176782. {
  176783. png_bytep rp;
  176784. png_uint_32 i;
  176785. if (row_info->color_type == PNG_COLOR_TYPE_RGB)
  176786. bytes_per_pixel = 3;
  176787. else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  176788. bytes_per_pixel = 4;
  176789. else
  176790. return;
  176791. for (i = 0, rp = row; i < row_width; i++, rp += bytes_per_pixel)
  176792. {
  176793. *(rp) = (png_byte)((*rp - *(rp+1))&0xff);
  176794. *(rp+2) = (png_byte)((*(rp+2) - *(rp+1))&0xff);
  176795. }
  176796. }
  176797. else if (row_info->bit_depth == 16)
  176798. {
  176799. png_bytep rp;
  176800. png_uint_32 i;
  176801. if (row_info->color_type == PNG_COLOR_TYPE_RGB)
  176802. bytes_per_pixel = 6;
  176803. else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  176804. bytes_per_pixel = 8;
  176805. else
  176806. return;
  176807. for (i = 0, rp = row; i < row_width; i++, rp += bytes_per_pixel)
  176808. {
  176809. png_uint_32 s0 = (*(rp ) << 8) | *(rp+1);
  176810. png_uint_32 s1 = (*(rp+2) << 8) | *(rp+3);
  176811. png_uint_32 s2 = (*(rp+4) << 8) | *(rp+5);
  176812. png_uint_32 red = (png_uint_32)((s0-s1) & 0xffffL);
  176813. png_uint_32 blue = (png_uint_32)((s2-s1) & 0xffffL);
  176814. *(rp ) = (png_byte)((red >> 8) & 0xff);
  176815. *(rp+1) = (png_byte)(red & 0xff);
  176816. *(rp+4) = (png_byte)((blue >> 8) & 0xff);
  176817. *(rp+5) = (png_byte)(blue & 0xff);
  176818. }
  176819. }
  176820. }
  176821. }
  176822. #endif /* PNG_MNG_FEATURES_SUPPORTED */
  176823. #endif /* PNG_WRITE_SUPPORTED */
  176824. /*** End of inlined file: pngwtran.c ***/
  176825. /*** Start of inlined file: pngwutil.c ***/
  176826. #define PNG_INTERNAL
  176827. #ifdef PNG_WRITE_SUPPORTED
  176828. void PNGAPI
  176829. png_save_uint_32(png_bytep buf, png_uint_32 i)
  176830. {
  176831. buf[0] = (png_byte)((i >> 24) & 0xff);
  176832. buf[1] = (png_byte)((i >> 16) & 0xff);
  176833. buf[2] = (png_byte)((i >> 8) & 0xff);
  176834. buf[3] = (png_byte)(i & 0xff);
  176835. }
  176836. void PNGAPI
  176837. png_save_int_32(png_bytep buf, png_int_32 i)
  176838. {
  176839. buf[0] = (png_byte)((i >> 24) & 0xff);
  176840. buf[1] = (png_byte)((i >> 16) & 0xff);
  176841. buf[2] = (png_byte)((i >> 8) & 0xff);
  176842. buf[3] = (png_byte)(i & 0xff);
  176843. }
  176844. void PNGAPI
  176845. png_save_uint_16(png_bytep buf, unsigned int i)
  176846. {
  176847. buf[0] = (png_byte)((i >> 8) & 0xff);
  176848. buf[1] = (png_byte)(i & 0xff);
  176849. }
  176850. void PNGAPI
  176851. png_write_chunk(png_structp png_ptr, png_bytep chunk_name,
  176852. png_bytep data, png_size_t length)
  176853. {
  176854. if(png_ptr == NULL) return;
  176855. png_write_chunk_start(png_ptr, chunk_name, (png_uint_32)length);
  176856. png_write_chunk_data(png_ptr, data, length);
  176857. png_write_chunk_end(png_ptr);
  176858. }
  176859. void PNGAPI
  176860. png_write_chunk_start(png_structp png_ptr, png_bytep chunk_name,
  176861. png_uint_32 length)
  176862. {
  176863. png_byte buf[4];
  176864. png_debug2(0, "Writing %s chunk (%lu bytes)\n", chunk_name, length);
  176865. if(png_ptr == NULL) return;
  176866. png_save_uint_32(buf, length);
  176867. png_write_data(png_ptr, buf, (png_size_t)4);
  176868. png_write_data(png_ptr, chunk_name, (png_size_t)4);
  176869. png_reset_crc(png_ptr);
  176870. png_calculate_crc(png_ptr, chunk_name, (png_size_t)4);
  176871. }
  176872. void PNGAPI
  176873. png_write_chunk_data(png_structp png_ptr, png_bytep data, png_size_t length)
  176874. {
  176875. if(png_ptr == NULL) return;
  176876. if (data != NULL && length > 0)
  176877. {
  176878. png_calculate_crc(png_ptr, data, length);
  176879. png_write_data(png_ptr, data, length);
  176880. }
  176881. }
  176882. void PNGAPI
  176883. png_write_chunk_end(png_structp png_ptr)
  176884. {
  176885. png_byte buf[4];
  176886. if(png_ptr == NULL) return;
  176887. png_save_uint_32(buf, png_ptr->crc);
  176888. png_write_data(png_ptr, buf, (png_size_t)4);
  176889. }
  176890. void /* PRIVATE */
  176891. png_write_sig(png_structp png_ptr)
  176892. {
  176893. png_byte png_signature[8] = {137, 80, 78, 71, 13, 10, 26, 10};
  176894. png_write_data(png_ptr, &png_signature[png_ptr->sig_bytes],
  176895. (png_size_t)8 - png_ptr->sig_bytes);
  176896. if(png_ptr->sig_bytes < 3)
  176897. png_ptr->mode |= PNG_HAVE_PNG_SIGNATURE;
  176898. }
  176899. #if defined(PNG_WRITE_TEXT_SUPPORTED) || defined(PNG_WRITE_iCCP_SUPPORTED)
  176900. typedef struct
  176901. {
  176902. char *input; /* the uncompressed input data */
  176903. int input_len; /* its length */
  176904. int num_output_ptr; /* number of output pointers used */
  176905. int max_output_ptr; /* size of output_ptr */
  176906. png_charpp output_ptr; /* array of pointers to output */
  176907. } compression_state;
  176908. static int /* PRIVATE */
  176909. png_text_compress(png_structp png_ptr,
  176910. png_charp text, png_size_t text_len, int compression,
  176911. compression_state *comp)
  176912. {
  176913. int ret;
  176914. comp->num_output_ptr = 0;
  176915. comp->max_output_ptr = 0;
  176916. comp->output_ptr = NULL;
  176917. comp->input = NULL;
  176918. comp->input_len = 0;
  176919. if (compression == PNG_TEXT_COMPRESSION_NONE)
  176920. {
  176921. comp->input = text;
  176922. comp->input_len = text_len;
  176923. return((int)text_len);
  176924. }
  176925. if (compression >= PNG_TEXT_COMPRESSION_LAST)
  176926. {
  176927. #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)
  176928. char msg[50];
  176929. png_snprintf(msg, 50, "Unknown compression type %d", compression);
  176930. png_warning(png_ptr, msg);
  176931. #else
  176932. png_warning(png_ptr, "Unknown compression type");
  176933. #endif
  176934. }
  176935. png_ptr->zstream.avail_in = (uInt)text_len;
  176936. png_ptr->zstream.next_in = (Bytef *)text;
  176937. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  176938. png_ptr->zstream.next_out = (Bytef *)png_ptr->zbuf;
  176939. do
  176940. {
  176941. ret = deflate(&png_ptr->zstream, Z_NO_FLUSH);
  176942. if (ret != Z_OK)
  176943. {
  176944. if (png_ptr->zstream.msg != NULL)
  176945. png_error(png_ptr, png_ptr->zstream.msg);
  176946. else
  176947. png_error(png_ptr, "zlib error");
  176948. }
  176949. if (!(png_ptr->zstream.avail_out))
  176950. {
  176951. if (comp->num_output_ptr >= comp->max_output_ptr)
  176952. {
  176953. int old_max;
  176954. old_max = comp->max_output_ptr;
  176955. comp->max_output_ptr = comp->num_output_ptr + 4;
  176956. if (comp->output_ptr != NULL)
  176957. {
  176958. png_charpp old_ptr;
  176959. old_ptr = comp->output_ptr;
  176960. comp->output_ptr = (png_charpp)png_malloc(png_ptr,
  176961. (png_uint_32)(comp->max_output_ptr *
  176962. png_sizeof (png_charpp)));
  176963. png_memcpy(comp->output_ptr, old_ptr, old_max
  176964. * png_sizeof (png_charp));
  176965. png_free(png_ptr, old_ptr);
  176966. }
  176967. else
  176968. comp->output_ptr = (png_charpp)png_malloc(png_ptr,
  176969. (png_uint_32)(comp->max_output_ptr *
  176970. png_sizeof (png_charp)));
  176971. }
  176972. comp->output_ptr[comp->num_output_ptr] = (png_charp)png_malloc(png_ptr,
  176973. (png_uint_32)png_ptr->zbuf_size);
  176974. png_memcpy(comp->output_ptr[comp->num_output_ptr], png_ptr->zbuf,
  176975. png_ptr->zbuf_size);
  176976. comp->num_output_ptr++;
  176977. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  176978. png_ptr->zstream.next_out = png_ptr->zbuf;
  176979. }
  176980. } while (png_ptr->zstream.avail_in);
  176981. do
  176982. {
  176983. ret = deflate(&png_ptr->zstream, Z_FINISH);
  176984. if (ret == Z_OK)
  176985. {
  176986. if (!(png_ptr->zstream.avail_out))
  176987. {
  176988. if (comp->num_output_ptr >= comp->max_output_ptr)
  176989. {
  176990. int old_max;
  176991. old_max = comp->max_output_ptr;
  176992. comp->max_output_ptr = comp->num_output_ptr + 4;
  176993. if (comp->output_ptr != NULL)
  176994. {
  176995. png_charpp old_ptr;
  176996. old_ptr = comp->output_ptr;
  176997. comp->output_ptr = (png_charpp)png_malloc(png_ptr,
  176998. (png_uint_32)(comp->max_output_ptr *
  176999. png_sizeof (png_charpp)));
  177000. png_memcpy(comp->output_ptr, old_ptr,
  177001. old_max * png_sizeof (png_charp));
  177002. png_free(png_ptr, old_ptr);
  177003. }
  177004. else
  177005. comp->output_ptr = (png_charpp)png_malloc(png_ptr,
  177006. (png_uint_32)(comp->max_output_ptr *
  177007. png_sizeof (png_charp)));
  177008. }
  177009. comp->output_ptr[comp->num_output_ptr] =
  177010. (png_charp)png_malloc(png_ptr, (png_uint_32)png_ptr->zbuf_size);
  177011. png_memcpy(comp->output_ptr[comp->num_output_ptr], png_ptr->zbuf,
  177012. png_ptr->zbuf_size);
  177013. comp->num_output_ptr++;
  177014. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  177015. png_ptr->zstream.next_out = png_ptr->zbuf;
  177016. }
  177017. }
  177018. else if (ret != Z_STREAM_END)
  177019. {
  177020. if (png_ptr->zstream.msg != NULL)
  177021. png_error(png_ptr, png_ptr->zstream.msg);
  177022. else
  177023. png_error(png_ptr, "zlib error");
  177024. }
  177025. } while (ret != Z_STREAM_END);
  177026. text_len = png_ptr->zbuf_size * comp->num_output_ptr;
  177027. if (png_ptr->zstream.avail_out < png_ptr->zbuf_size)
  177028. text_len += png_ptr->zbuf_size - (png_size_t)png_ptr->zstream.avail_out;
  177029. return((int)text_len);
  177030. }
  177031. static void /* PRIVATE */
  177032. png_write_compressed_data_out(png_structp png_ptr, compression_state *comp)
  177033. {
  177034. int i;
  177035. if (comp->input)
  177036. {
  177037. png_write_chunk_data(png_ptr, (png_bytep)comp->input,
  177038. (png_size_t)comp->input_len);
  177039. return;
  177040. }
  177041. for (i = 0; i < comp->num_output_ptr; i++)
  177042. {
  177043. png_write_chunk_data(png_ptr,(png_bytep)comp->output_ptr[i],
  177044. png_ptr->zbuf_size);
  177045. png_free(png_ptr, comp->output_ptr[i]);
  177046. comp->output_ptr[i]=NULL;
  177047. }
  177048. if (comp->max_output_ptr != 0)
  177049. png_free(png_ptr, comp->output_ptr);
  177050. comp->output_ptr=NULL;
  177051. if (png_ptr->zstream.avail_out < (png_uint_32)png_ptr->zbuf_size)
  177052. png_write_chunk_data(png_ptr, png_ptr->zbuf,
  177053. png_ptr->zbuf_size - png_ptr->zstream.avail_out);
  177054. deflateReset(&png_ptr->zstream);
  177055. png_ptr->zstream.data_type = Z_BINARY;
  177056. }
  177057. #endif
  177058. void /* PRIVATE */
  177059. png_write_IHDR(png_structp png_ptr, png_uint_32 width, png_uint_32 height,
  177060. int bit_depth, int color_type, int compression_type, int filter_type,
  177061. int interlace_type)
  177062. {
  177063. #ifdef PNG_USE_LOCAL_ARRAYS
  177064. PNG_IHDR;
  177065. #endif
  177066. png_byte buf[13]; /* buffer to store the IHDR info */
  177067. png_debug(1, "in png_write_IHDR\n");
  177068. switch (color_type)
  177069. {
  177070. case PNG_COLOR_TYPE_GRAY:
  177071. switch (bit_depth)
  177072. {
  177073. case 1:
  177074. case 2:
  177075. case 4:
  177076. case 8:
  177077. case 16: png_ptr->channels = 1; break;
  177078. default: png_error(png_ptr,"Invalid bit depth for grayscale image");
  177079. }
  177080. break;
  177081. case PNG_COLOR_TYPE_RGB:
  177082. if (bit_depth != 8 && bit_depth != 16)
  177083. png_error(png_ptr, "Invalid bit depth for RGB image");
  177084. png_ptr->channels = 3;
  177085. break;
  177086. case PNG_COLOR_TYPE_PALETTE:
  177087. switch (bit_depth)
  177088. {
  177089. case 1:
  177090. case 2:
  177091. case 4:
  177092. case 8: png_ptr->channels = 1; break;
  177093. default: png_error(png_ptr, "Invalid bit depth for paletted image");
  177094. }
  177095. break;
  177096. case PNG_COLOR_TYPE_GRAY_ALPHA:
  177097. if (bit_depth != 8 && bit_depth != 16)
  177098. png_error(png_ptr, "Invalid bit depth for grayscale+alpha image");
  177099. png_ptr->channels = 2;
  177100. break;
  177101. case PNG_COLOR_TYPE_RGB_ALPHA:
  177102. if (bit_depth != 8 && bit_depth != 16)
  177103. png_error(png_ptr, "Invalid bit depth for RGBA image");
  177104. png_ptr->channels = 4;
  177105. break;
  177106. default:
  177107. png_error(png_ptr, "Invalid image color type specified");
  177108. }
  177109. if (compression_type != PNG_COMPRESSION_TYPE_BASE)
  177110. {
  177111. png_warning(png_ptr, "Invalid compression type specified");
  177112. compression_type = PNG_COMPRESSION_TYPE_BASE;
  177113. }
  177114. if (
  177115. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  177116. !((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) &&
  177117. ((png_ptr->mode&PNG_HAVE_PNG_SIGNATURE) == 0) &&
  177118. (color_type == PNG_COLOR_TYPE_RGB ||
  177119. color_type == PNG_COLOR_TYPE_RGB_ALPHA) &&
  177120. (filter_type == PNG_INTRAPIXEL_DIFFERENCING)) &&
  177121. #endif
  177122. filter_type != PNG_FILTER_TYPE_BASE)
  177123. {
  177124. png_warning(png_ptr, "Invalid filter type specified");
  177125. filter_type = PNG_FILTER_TYPE_BASE;
  177126. }
  177127. #ifdef PNG_WRITE_INTERLACING_SUPPORTED
  177128. if (interlace_type != PNG_INTERLACE_NONE &&
  177129. interlace_type != PNG_INTERLACE_ADAM7)
  177130. {
  177131. png_warning(png_ptr, "Invalid interlace type specified");
  177132. interlace_type = PNG_INTERLACE_ADAM7;
  177133. }
  177134. #else
  177135. interlace_type=PNG_INTERLACE_NONE;
  177136. #endif
  177137. png_ptr->bit_depth = (png_byte)bit_depth;
  177138. png_ptr->color_type = (png_byte)color_type;
  177139. png_ptr->interlaced = (png_byte)interlace_type;
  177140. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  177141. png_ptr->filter_type = (png_byte)filter_type;
  177142. #endif
  177143. png_ptr->compression_type = (png_byte)compression_type;
  177144. png_ptr->width = width;
  177145. png_ptr->height = height;
  177146. png_ptr->pixel_depth = (png_byte)(bit_depth * png_ptr->channels);
  177147. png_ptr->rowbytes = PNG_ROWBYTES(png_ptr->pixel_depth, width);
  177148. png_ptr->usr_width = png_ptr->width;
  177149. png_ptr->usr_bit_depth = png_ptr->bit_depth;
  177150. png_ptr->usr_channels = png_ptr->channels;
  177151. png_save_uint_32(buf, width);
  177152. png_save_uint_32(buf + 4, height);
  177153. buf[8] = (png_byte)bit_depth;
  177154. buf[9] = (png_byte)color_type;
  177155. buf[10] = (png_byte)compression_type;
  177156. buf[11] = (png_byte)filter_type;
  177157. buf[12] = (png_byte)interlace_type;
  177158. png_write_chunk(png_ptr, png_IHDR, buf, (png_size_t)13);
  177159. png_ptr->zstream.zalloc = png_zalloc;
  177160. png_ptr->zstream.zfree = png_zfree;
  177161. png_ptr->zstream.opaque = (voidpf)png_ptr;
  177162. if (!(png_ptr->do_filter))
  177163. {
  177164. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE ||
  177165. png_ptr->bit_depth < 8)
  177166. png_ptr->do_filter = PNG_FILTER_NONE;
  177167. else
  177168. png_ptr->do_filter = PNG_ALL_FILTERS;
  177169. }
  177170. if (!(png_ptr->flags & PNG_FLAG_ZLIB_CUSTOM_STRATEGY))
  177171. {
  177172. if (png_ptr->do_filter != PNG_FILTER_NONE)
  177173. png_ptr->zlib_strategy = Z_FILTERED;
  177174. else
  177175. png_ptr->zlib_strategy = Z_DEFAULT_STRATEGY;
  177176. }
  177177. if (!(png_ptr->flags & PNG_FLAG_ZLIB_CUSTOM_LEVEL))
  177178. png_ptr->zlib_level = Z_DEFAULT_COMPRESSION;
  177179. if (!(png_ptr->flags & PNG_FLAG_ZLIB_CUSTOM_MEM_LEVEL))
  177180. png_ptr->zlib_mem_level = 8;
  177181. if (!(png_ptr->flags & PNG_FLAG_ZLIB_CUSTOM_WINDOW_BITS))
  177182. png_ptr->zlib_window_bits = 15;
  177183. if (!(png_ptr->flags & PNG_FLAG_ZLIB_CUSTOM_METHOD))
  177184. png_ptr->zlib_method = 8;
  177185. if (deflateInit2(&png_ptr->zstream, png_ptr->zlib_level,
  177186. png_ptr->zlib_method, png_ptr->zlib_window_bits,
  177187. png_ptr->zlib_mem_level, png_ptr->zlib_strategy) != Z_OK)
  177188. png_error(png_ptr, "zlib failed to initialize compressor");
  177189. png_ptr->zstream.next_out = png_ptr->zbuf;
  177190. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  177191. png_ptr->zstream.data_type = Z_BINARY;
  177192. png_ptr->mode = PNG_HAVE_IHDR;
  177193. }
  177194. void /* PRIVATE */
  177195. png_write_PLTE(png_structp png_ptr, png_colorp palette, png_uint_32 num_pal)
  177196. {
  177197. #ifdef PNG_USE_LOCAL_ARRAYS
  177198. PNG_PLTE;
  177199. #endif
  177200. png_uint_32 i;
  177201. png_colorp pal_ptr;
  177202. png_byte buf[3];
  177203. png_debug(1, "in png_write_PLTE\n");
  177204. if ((
  177205. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  177206. !(png_ptr->mng_features_permitted & PNG_FLAG_MNG_EMPTY_PLTE) &&
  177207. #endif
  177208. num_pal == 0) || num_pal > 256)
  177209. {
  177210. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  177211. {
  177212. png_error(png_ptr, "Invalid number of colors in palette");
  177213. }
  177214. else
  177215. {
  177216. png_warning(png_ptr, "Invalid number of colors in palette");
  177217. return;
  177218. }
  177219. }
  177220. if (!(png_ptr->color_type&PNG_COLOR_MASK_COLOR))
  177221. {
  177222. png_warning(png_ptr,
  177223. "Ignoring request to write a PLTE chunk in grayscale PNG");
  177224. return;
  177225. }
  177226. png_ptr->num_palette = (png_uint_16)num_pal;
  177227. png_debug1(3, "num_palette = %d\n", png_ptr->num_palette);
  177228. png_write_chunk_start(png_ptr, png_PLTE, num_pal * 3);
  177229. #ifndef PNG_NO_POINTER_INDEXING
  177230. for (i = 0, pal_ptr = palette; i < num_pal; i++, pal_ptr++)
  177231. {
  177232. buf[0] = pal_ptr->red;
  177233. buf[1] = pal_ptr->green;
  177234. buf[2] = pal_ptr->blue;
  177235. png_write_chunk_data(png_ptr, buf, (png_size_t)3);
  177236. }
  177237. #else
  177238. pal_ptr=palette;
  177239. for (i = 0; i < num_pal; i++)
  177240. {
  177241. buf[0] = pal_ptr[i].red;
  177242. buf[1] = pal_ptr[i].green;
  177243. buf[2] = pal_ptr[i].blue;
  177244. png_write_chunk_data(png_ptr, buf, (png_size_t)3);
  177245. }
  177246. #endif
  177247. png_write_chunk_end(png_ptr);
  177248. png_ptr->mode |= PNG_HAVE_PLTE;
  177249. }
  177250. void /* PRIVATE */
  177251. png_write_IDAT(png_structp png_ptr, png_bytep data, png_size_t length)
  177252. {
  177253. #ifdef PNG_USE_LOCAL_ARRAYS
  177254. PNG_IDAT;
  177255. #endif
  177256. png_debug(1, "in png_write_IDAT\n");
  177257. if (!(png_ptr->mode & PNG_HAVE_IDAT) &&
  177258. png_ptr->compression_type == PNG_COMPRESSION_TYPE_BASE)
  177259. {
  177260. unsigned int z_cmf = data[0]; /* zlib compression method and flags */
  177261. if ((z_cmf & 0x0f) == 8 && (z_cmf & 0xf0) <= 0x70)
  177262. {
  177263. if (length >= 2 &&
  177264. png_ptr->height < 16384 && png_ptr->width < 16384)
  177265. {
  177266. png_uint_32 uncompressed_idat_size = png_ptr->height *
  177267. ((png_ptr->width *
  177268. png_ptr->channels * png_ptr->bit_depth + 15) >> 3);
  177269. unsigned int z_cinfo = z_cmf >> 4;
  177270. unsigned int half_z_window_size = 1 << (z_cinfo + 7);
  177271. while (uncompressed_idat_size <= half_z_window_size &&
  177272. half_z_window_size >= 256)
  177273. {
  177274. z_cinfo--;
  177275. half_z_window_size >>= 1;
  177276. }
  177277. z_cmf = (z_cmf & 0x0f) | (z_cinfo << 4);
  177278. if (data[0] != (png_byte)z_cmf)
  177279. {
  177280. data[0] = (png_byte)z_cmf;
  177281. data[1] &= 0xe0;
  177282. data[1] += (png_byte)(0x1f - ((z_cmf << 8) + data[1]) % 0x1f);
  177283. }
  177284. }
  177285. }
  177286. else
  177287. png_error(png_ptr,
  177288. "Invalid zlib compression method or flags in IDAT");
  177289. }
  177290. png_write_chunk(png_ptr, png_IDAT, data, length);
  177291. png_ptr->mode |= PNG_HAVE_IDAT;
  177292. }
  177293. void /* PRIVATE */
  177294. png_write_IEND(png_structp png_ptr)
  177295. {
  177296. #ifdef PNG_USE_LOCAL_ARRAYS
  177297. PNG_IEND;
  177298. #endif
  177299. png_debug(1, "in png_write_IEND\n");
  177300. png_write_chunk(png_ptr, png_IEND, png_bytep_NULL,
  177301. (png_size_t)0);
  177302. png_ptr->mode |= PNG_HAVE_IEND;
  177303. }
  177304. #if defined(PNG_WRITE_gAMA_SUPPORTED)
  177305. #ifdef PNG_FLOATING_POINT_SUPPORTED
  177306. void /* PRIVATE */
  177307. png_write_gAMA(png_structp png_ptr, double file_gamma)
  177308. {
  177309. #ifdef PNG_USE_LOCAL_ARRAYS
  177310. PNG_gAMA;
  177311. #endif
  177312. png_uint_32 igamma;
  177313. png_byte buf[4];
  177314. png_debug(1, "in png_write_gAMA\n");
  177315. igamma = (png_uint_32)(file_gamma * 100000.0 + 0.5);
  177316. png_save_uint_32(buf, igamma);
  177317. png_write_chunk(png_ptr, png_gAMA, buf, (png_size_t)4);
  177318. }
  177319. #endif
  177320. #ifdef PNG_FIXED_POINT_SUPPORTED
  177321. void /* PRIVATE */
  177322. png_write_gAMA_fixed(png_structp png_ptr, png_fixed_point file_gamma)
  177323. {
  177324. #ifdef PNG_USE_LOCAL_ARRAYS
  177325. PNG_gAMA;
  177326. #endif
  177327. png_byte buf[4];
  177328. png_debug(1, "in png_write_gAMA\n");
  177329. png_save_uint_32(buf, (png_uint_32)file_gamma);
  177330. png_write_chunk(png_ptr, png_gAMA, buf, (png_size_t)4);
  177331. }
  177332. #endif
  177333. #endif
  177334. #if defined(PNG_WRITE_sRGB_SUPPORTED)
  177335. void /* PRIVATE */
  177336. png_write_sRGB(png_structp png_ptr, int srgb_intent)
  177337. {
  177338. #ifdef PNG_USE_LOCAL_ARRAYS
  177339. PNG_sRGB;
  177340. #endif
  177341. png_byte buf[1];
  177342. png_debug(1, "in png_write_sRGB\n");
  177343. if(srgb_intent >= PNG_sRGB_INTENT_LAST)
  177344. png_warning(png_ptr,
  177345. "Invalid sRGB rendering intent specified");
  177346. buf[0]=(png_byte)srgb_intent;
  177347. png_write_chunk(png_ptr, png_sRGB, buf, (png_size_t)1);
  177348. }
  177349. #endif
  177350. #if defined(PNG_WRITE_iCCP_SUPPORTED)
  177351. void /* PRIVATE */
  177352. png_write_iCCP(png_structp png_ptr, png_charp name, int compression_type,
  177353. png_charp profile, int profile_len)
  177354. {
  177355. #ifdef PNG_USE_LOCAL_ARRAYS
  177356. PNG_iCCP;
  177357. #endif
  177358. png_size_t name_len;
  177359. png_charp new_name;
  177360. compression_state comp;
  177361. int embedded_profile_len = 0;
  177362. png_debug(1, "in png_write_iCCP\n");
  177363. comp.num_output_ptr = 0;
  177364. comp.max_output_ptr = 0;
  177365. comp.output_ptr = NULL;
  177366. comp.input = NULL;
  177367. comp.input_len = 0;
  177368. if (name == NULL || (name_len = png_check_keyword(png_ptr, name,
  177369. &new_name)) == 0)
  177370. {
  177371. png_warning(png_ptr, "Empty keyword in iCCP chunk");
  177372. return;
  177373. }
  177374. if (compression_type != PNG_COMPRESSION_TYPE_BASE)
  177375. png_warning(png_ptr, "Unknown compression type in iCCP chunk");
  177376. if (profile == NULL)
  177377. profile_len = 0;
  177378. if (profile_len > 3)
  177379. embedded_profile_len =
  177380. ((*( (png_bytep)profile ))<<24) |
  177381. ((*( (png_bytep)profile+1))<<16) |
  177382. ((*( (png_bytep)profile+2))<< 8) |
  177383. ((*( (png_bytep)profile+3)) );
  177384. if (profile_len < embedded_profile_len)
  177385. {
  177386. png_warning(png_ptr,
  177387. "Embedded profile length too large in iCCP chunk");
  177388. return;
  177389. }
  177390. if (profile_len > embedded_profile_len)
  177391. {
  177392. png_warning(png_ptr,
  177393. "Truncating profile to actual length in iCCP chunk");
  177394. profile_len = embedded_profile_len;
  177395. }
  177396. if (profile_len)
  177397. profile_len = png_text_compress(png_ptr, profile, (png_size_t)profile_len,
  177398. PNG_COMPRESSION_TYPE_BASE, &comp);
  177399. png_write_chunk_start(png_ptr, png_iCCP,
  177400. (png_uint_32)name_len+profile_len+2);
  177401. new_name[name_len+1]=0x00;
  177402. png_write_chunk_data(png_ptr, (png_bytep)new_name, name_len + 2);
  177403. if (profile_len)
  177404. png_write_compressed_data_out(png_ptr, &comp);
  177405. png_write_chunk_end(png_ptr);
  177406. png_free(png_ptr, new_name);
  177407. }
  177408. #endif
  177409. #if defined(PNG_WRITE_sPLT_SUPPORTED)
  177410. void /* PRIVATE */
  177411. png_write_sPLT(png_structp png_ptr, png_sPLT_tp spalette)
  177412. {
  177413. #ifdef PNG_USE_LOCAL_ARRAYS
  177414. PNG_sPLT;
  177415. #endif
  177416. png_size_t name_len;
  177417. png_charp new_name;
  177418. png_byte entrybuf[10];
  177419. int entry_size = (spalette->depth == 8 ? 6 : 10);
  177420. int palette_size = entry_size * spalette->nentries;
  177421. png_sPLT_entryp ep;
  177422. #ifdef PNG_NO_POINTER_INDEXING
  177423. int i;
  177424. #endif
  177425. png_debug(1, "in png_write_sPLT\n");
  177426. if (spalette->name == NULL || (name_len = png_check_keyword(png_ptr,
  177427. spalette->name, &new_name))==0)
  177428. {
  177429. png_warning(png_ptr, "Empty keyword in sPLT chunk");
  177430. return;
  177431. }
  177432. png_write_chunk_start(png_ptr, png_sPLT,
  177433. (png_uint_32)(name_len + 2 + palette_size));
  177434. png_write_chunk_data(png_ptr, (png_bytep)new_name, name_len + 1);
  177435. png_write_chunk_data(png_ptr, (png_bytep)&spalette->depth, 1);
  177436. #ifndef PNG_NO_POINTER_INDEXING
  177437. for (ep = spalette->entries; ep<spalette->entries+spalette->nentries; ep++)
  177438. {
  177439. if (spalette->depth == 8)
  177440. {
  177441. entrybuf[0] = (png_byte)ep->red;
  177442. entrybuf[1] = (png_byte)ep->green;
  177443. entrybuf[2] = (png_byte)ep->blue;
  177444. entrybuf[3] = (png_byte)ep->alpha;
  177445. png_save_uint_16(entrybuf + 4, ep->frequency);
  177446. }
  177447. else
  177448. {
  177449. png_save_uint_16(entrybuf + 0, ep->red);
  177450. png_save_uint_16(entrybuf + 2, ep->green);
  177451. png_save_uint_16(entrybuf + 4, ep->blue);
  177452. png_save_uint_16(entrybuf + 6, ep->alpha);
  177453. png_save_uint_16(entrybuf + 8, ep->frequency);
  177454. }
  177455. png_write_chunk_data(png_ptr, entrybuf, (png_size_t)entry_size);
  177456. }
  177457. #else
  177458. ep=spalette->entries;
  177459. for (i=0; i>spalette->nentries; i++)
  177460. {
  177461. if (spalette->depth == 8)
  177462. {
  177463. entrybuf[0] = (png_byte)ep[i].red;
  177464. entrybuf[1] = (png_byte)ep[i].green;
  177465. entrybuf[2] = (png_byte)ep[i].blue;
  177466. entrybuf[3] = (png_byte)ep[i].alpha;
  177467. png_save_uint_16(entrybuf + 4, ep[i].frequency);
  177468. }
  177469. else
  177470. {
  177471. png_save_uint_16(entrybuf + 0, ep[i].red);
  177472. png_save_uint_16(entrybuf + 2, ep[i].green);
  177473. png_save_uint_16(entrybuf + 4, ep[i].blue);
  177474. png_save_uint_16(entrybuf + 6, ep[i].alpha);
  177475. png_save_uint_16(entrybuf + 8, ep[i].frequency);
  177476. }
  177477. png_write_chunk_data(png_ptr, entrybuf, entry_size);
  177478. }
  177479. #endif
  177480. png_write_chunk_end(png_ptr);
  177481. png_free(png_ptr, new_name);
  177482. }
  177483. #endif
  177484. #if defined(PNG_WRITE_sBIT_SUPPORTED)
  177485. void /* PRIVATE */
  177486. png_write_sBIT(png_structp png_ptr, png_color_8p sbit, int color_type)
  177487. {
  177488. #ifdef PNG_USE_LOCAL_ARRAYS
  177489. PNG_sBIT;
  177490. #endif
  177491. png_byte buf[4];
  177492. png_size_t size;
  177493. png_debug(1, "in png_write_sBIT\n");
  177494. if (color_type & PNG_COLOR_MASK_COLOR)
  177495. {
  177496. png_byte maxbits;
  177497. maxbits = (png_byte)(color_type==PNG_COLOR_TYPE_PALETTE ? 8 :
  177498. png_ptr->usr_bit_depth);
  177499. if (sbit->red == 0 || sbit->red > maxbits ||
  177500. sbit->green == 0 || sbit->green > maxbits ||
  177501. sbit->blue == 0 || sbit->blue > maxbits)
  177502. {
  177503. png_warning(png_ptr, "Invalid sBIT depth specified");
  177504. return;
  177505. }
  177506. buf[0] = sbit->red;
  177507. buf[1] = sbit->green;
  177508. buf[2] = sbit->blue;
  177509. size = 3;
  177510. }
  177511. else
  177512. {
  177513. if (sbit->gray == 0 || sbit->gray > png_ptr->usr_bit_depth)
  177514. {
  177515. png_warning(png_ptr, "Invalid sBIT depth specified");
  177516. return;
  177517. }
  177518. buf[0] = sbit->gray;
  177519. size = 1;
  177520. }
  177521. if (color_type & PNG_COLOR_MASK_ALPHA)
  177522. {
  177523. if (sbit->alpha == 0 || sbit->alpha > png_ptr->usr_bit_depth)
  177524. {
  177525. png_warning(png_ptr, "Invalid sBIT depth specified");
  177526. return;
  177527. }
  177528. buf[size++] = sbit->alpha;
  177529. }
  177530. png_write_chunk(png_ptr, png_sBIT, buf, size);
  177531. }
  177532. #endif
  177533. #if defined(PNG_WRITE_cHRM_SUPPORTED)
  177534. #ifdef PNG_FLOATING_POINT_SUPPORTED
  177535. void /* PRIVATE */
  177536. png_write_cHRM(png_structp png_ptr, double white_x, double white_y,
  177537. double red_x, double red_y, double green_x, double green_y,
  177538. double blue_x, double blue_y)
  177539. {
  177540. #ifdef PNG_USE_LOCAL_ARRAYS
  177541. PNG_cHRM;
  177542. #endif
  177543. png_byte buf[32];
  177544. png_uint_32 itemp;
  177545. png_debug(1, "in png_write_cHRM\n");
  177546. if (white_x < 0 || white_x > 0.8 || white_y < 0 || white_y > 0.8 ||
  177547. white_x + white_y > 1.0)
  177548. {
  177549. png_warning(png_ptr, "Invalid cHRM white point specified");
  177550. #if !defined(PNG_NO_CONSOLE_IO)
  177551. fprintf(stderr,"white_x=%f, white_y=%f\n",white_x, white_y);
  177552. #endif
  177553. return;
  177554. }
  177555. itemp = (png_uint_32)(white_x * 100000.0 + 0.5);
  177556. png_save_uint_32(buf, itemp);
  177557. itemp = (png_uint_32)(white_y * 100000.0 + 0.5);
  177558. png_save_uint_32(buf + 4, itemp);
  177559. if (red_x < 0 || red_y < 0 || red_x + red_y > 1.0)
  177560. {
  177561. png_warning(png_ptr, "Invalid cHRM red point specified");
  177562. return;
  177563. }
  177564. itemp = (png_uint_32)(red_x * 100000.0 + 0.5);
  177565. png_save_uint_32(buf + 8, itemp);
  177566. itemp = (png_uint_32)(red_y * 100000.0 + 0.5);
  177567. png_save_uint_32(buf + 12, itemp);
  177568. if (green_x < 0 || green_y < 0 || green_x + green_y > 1.0)
  177569. {
  177570. png_warning(png_ptr, "Invalid cHRM green point specified");
  177571. return;
  177572. }
  177573. itemp = (png_uint_32)(green_x * 100000.0 + 0.5);
  177574. png_save_uint_32(buf + 16, itemp);
  177575. itemp = (png_uint_32)(green_y * 100000.0 + 0.5);
  177576. png_save_uint_32(buf + 20, itemp);
  177577. if (blue_x < 0 || blue_y < 0 || blue_x + blue_y > 1.0)
  177578. {
  177579. png_warning(png_ptr, "Invalid cHRM blue point specified");
  177580. return;
  177581. }
  177582. itemp = (png_uint_32)(blue_x * 100000.0 + 0.5);
  177583. png_save_uint_32(buf + 24, itemp);
  177584. itemp = (png_uint_32)(blue_y * 100000.0 + 0.5);
  177585. png_save_uint_32(buf + 28, itemp);
  177586. png_write_chunk(png_ptr, png_cHRM, buf, (png_size_t)32);
  177587. }
  177588. #endif
  177589. #ifdef PNG_FIXED_POINT_SUPPORTED
  177590. void /* PRIVATE */
  177591. png_write_cHRM_fixed(png_structp png_ptr, png_fixed_point white_x,
  177592. png_fixed_point white_y, png_fixed_point red_x, png_fixed_point red_y,
  177593. png_fixed_point green_x, png_fixed_point green_y, png_fixed_point blue_x,
  177594. png_fixed_point blue_y)
  177595. {
  177596. #ifdef PNG_USE_LOCAL_ARRAYS
  177597. PNG_cHRM;
  177598. #endif
  177599. png_byte buf[32];
  177600. png_debug(1, "in png_write_cHRM\n");
  177601. if (white_x > 80000L || white_y > 80000L || white_x + white_y > 100000L)
  177602. {
  177603. png_warning(png_ptr, "Invalid fixed cHRM white point specified");
  177604. #if !defined(PNG_NO_CONSOLE_IO)
  177605. fprintf(stderr,"white_x=%ld, white_y=%ld\n",white_x, white_y);
  177606. #endif
  177607. return;
  177608. }
  177609. png_save_uint_32(buf, (png_uint_32)white_x);
  177610. png_save_uint_32(buf + 4, (png_uint_32)white_y);
  177611. if (red_x + red_y > 100000L)
  177612. {
  177613. png_warning(png_ptr, "Invalid cHRM fixed red point specified");
  177614. return;
  177615. }
  177616. png_save_uint_32(buf + 8, (png_uint_32)red_x);
  177617. png_save_uint_32(buf + 12, (png_uint_32)red_y);
  177618. if (green_x + green_y > 100000L)
  177619. {
  177620. png_warning(png_ptr, "Invalid fixed cHRM green point specified");
  177621. return;
  177622. }
  177623. png_save_uint_32(buf + 16, (png_uint_32)green_x);
  177624. png_save_uint_32(buf + 20, (png_uint_32)green_y);
  177625. if (blue_x + blue_y > 100000L)
  177626. {
  177627. png_warning(png_ptr, "Invalid fixed cHRM blue point specified");
  177628. return;
  177629. }
  177630. png_save_uint_32(buf + 24, (png_uint_32)blue_x);
  177631. png_save_uint_32(buf + 28, (png_uint_32)blue_y);
  177632. png_write_chunk(png_ptr, png_cHRM, buf, (png_size_t)32);
  177633. }
  177634. #endif
  177635. #endif
  177636. #if defined(PNG_WRITE_tRNS_SUPPORTED)
  177637. void /* PRIVATE */
  177638. png_write_tRNS(png_structp png_ptr, png_bytep trans, png_color_16p tran,
  177639. int num_trans, int color_type)
  177640. {
  177641. #ifdef PNG_USE_LOCAL_ARRAYS
  177642. PNG_tRNS;
  177643. #endif
  177644. png_byte buf[6];
  177645. png_debug(1, "in png_write_tRNS\n");
  177646. if (color_type == PNG_COLOR_TYPE_PALETTE)
  177647. {
  177648. if (num_trans <= 0 || num_trans > (int)png_ptr->num_palette)
  177649. {
  177650. png_warning(png_ptr,"Invalid number of transparent colors specified");
  177651. return;
  177652. }
  177653. png_write_chunk(png_ptr, png_tRNS, trans, (png_size_t)num_trans);
  177654. }
  177655. else if (color_type == PNG_COLOR_TYPE_GRAY)
  177656. {
  177657. if(tran->gray >= (1 << png_ptr->bit_depth))
  177658. {
  177659. png_warning(png_ptr,
  177660. "Ignoring attempt to write tRNS chunk out-of-range for bit_depth");
  177661. return;
  177662. }
  177663. png_save_uint_16(buf, tran->gray);
  177664. png_write_chunk(png_ptr, png_tRNS, buf, (png_size_t)2);
  177665. }
  177666. else if (color_type == PNG_COLOR_TYPE_RGB)
  177667. {
  177668. png_save_uint_16(buf, tran->red);
  177669. png_save_uint_16(buf + 2, tran->green);
  177670. png_save_uint_16(buf + 4, tran->blue);
  177671. if(png_ptr->bit_depth == 8 && (buf[0] | buf[2] | buf[4]))
  177672. {
  177673. png_warning(png_ptr,
  177674. "Ignoring attempt to write 16-bit tRNS chunk when bit_depth is 8");
  177675. return;
  177676. }
  177677. png_write_chunk(png_ptr, png_tRNS, buf, (png_size_t)6);
  177678. }
  177679. else
  177680. {
  177681. png_warning(png_ptr, "Can't write tRNS with an alpha channel");
  177682. }
  177683. }
  177684. #endif
  177685. #if defined(PNG_WRITE_bKGD_SUPPORTED)
  177686. void /* PRIVATE */
  177687. png_write_bKGD(png_structp png_ptr, png_color_16p back, int color_type)
  177688. {
  177689. #ifdef PNG_USE_LOCAL_ARRAYS
  177690. PNG_bKGD;
  177691. #endif
  177692. png_byte buf[6];
  177693. png_debug(1, "in png_write_bKGD\n");
  177694. if (color_type == PNG_COLOR_TYPE_PALETTE)
  177695. {
  177696. if (
  177697. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  177698. (png_ptr->num_palette ||
  177699. (!(png_ptr->mng_features_permitted & PNG_FLAG_MNG_EMPTY_PLTE))) &&
  177700. #endif
  177701. back->index > png_ptr->num_palette)
  177702. {
  177703. png_warning(png_ptr, "Invalid background palette index");
  177704. return;
  177705. }
  177706. buf[0] = back->index;
  177707. png_write_chunk(png_ptr, png_bKGD, buf, (png_size_t)1);
  177708. }
  177709. else if (color_type & PNG_COLOR_MASK_COLOR)
  177710. {
  177711. png_save_uint_16(buf, back->red);
  177712. png_save_uint_16(buf + 2, back->green);
  177713. png_save_uint_16(buf + 4, back->blue);
  177714. if(png_ptr->bit_depth == 8 && (buf[0] | buf[2] | buf[4]))
  177715. {
  177716. png_warning(png_ptr,
  177717. "Ignoring attempt to write 16-bit bKGD chunk when bit_depth is 8");
  177718. return;
  177719. }
  177720. png_write_chunk(png_ptr, png_bKGD, buf, (png_size_t)6);
  177721. }
  177722. else
  177723. {
  177724. if(back->gray >= (1 << png_ptr->bit_depth))
  177725. {
  177726. png_warning(png_ptr,
  177727. "Ignoring attempt to write bKGD chunk out-of-range for bit_depth");
  177728. return;
  177729. }
  177730. png_save_uint_16(buf, back->gray);
  177731. png_write_chunk(png_ptr, png_bKGD, buf, (png_size_t)2);
  177732. }
  177733. }
  177734. #endif
  177735. #if defined(PNG_WRITE_hIST_SUPPORTED)
  177736. void /* PRIVATE */
  177737. png_write_hIST(png_structp png_ptr, png_uint_16p hist, int num_hist)
  177738. {
  177739. #ifdef PNG_USE_LOCAL_ARRAYS
  177740. PNG_hIST;
  177741. #endif
  177742. int i;
  177743. png_byte buf[3];
  177744. png_debug(1, "in png_write_hIST\n");
  177745. if (num_hist > (int)png_ptr->num_palette)
  177746. {
  177747. png_debug2(3, "num_hist = %d, num_palette = %d\n", num_hist,
  177748. png_ptr->num_palette);
  177749. png_warning(png_ptr, "Invalid number of histogram entries specified");
  177750. return;
  177751. }
  177752. png_write_chunk_start(png_ptr, png_hIST, (png_uint_32)(num_hist * 2));
  177753. for (i = 0; i < num_hist; i++)
  177754. {
  177755. png_save_uint_16(buf, hist[i]);
  177756. png_write_chunk_data(png_ptr, buf, (png_size_t)2);
  177757. }
  177758. png_write_chunk_end(png_ptr);
  177759. }
  177760. #endif
  177761. #if defined(PNG_WRITE_TEXT_SUPPORTED) || defined(PNG_WRITE_pCAL_SUPPORTED) || \
  177762. defined(PNG_WRITE_iCCP_SUPPORTED) || defined(PNG_WRITE_sPLT_SUPPORTED)
  177763. png_size_t /* PRIVATE */
  177764. png_check_keyword(png_structp png_ptr, png_charp key, png_charpp new_key)
  177765. {
  177766. png_size_t key_len;
  177767. png_charp kp, dp;
  177768. int kflag;
  177769. int kwarn=0;
  177770. png_debug(1, "in png_check_keyword\n");
  177771. *new_key = NULL;
  177772. if (key == NULL || (key_len = png_strlen(key)) == 0)
  177773. {
  177774. png_warning(png_ptr, "zero length keyword");
  177775. return ((png_size_t)0);
  177776. }
  177777. png_debug1(2, "Keyword to be checked is '%s'\n", key);
  177778. *new_key = (png_charp)png_malloc_warn(png_ptr, (png_uint_32)(key_len + 2));
  177779. if (*new_key == NULL)
  177780. {
  177781. png_warning(png_ptr, "Out of memory while procesing keyword");
  177782. return ((png_size_t)0);
  177783. }
  177784. for (kp = key, dp = *new_key; *kp != '\0'; kp++, dp++)
  177785. {
  177786. if ((png_byte)*kp < 0x20 ||
  177787. ((png_byte)*kp > 0x7E && (png_byte)*kp < 0xA1))
  177788. {
  177789. #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)
  177790. char msg[40];
  177791. png_snprintf(msg, 40,
  177792. "invalid keyword character 0x%02X", (png_byte)*kp);
  177793. png_warning(png_ptr, msg);
  177794. #else
  177795. png_warning(png_ptr, "invalid character in keyword");
  177796. #endif
  177797. *dp = ' ';
  177798. }
  177799. else
  177800. {
  177801. *dp = *kp;
  177802. }
  177803. }
  177804. *dp = '\0';
  177805. kp = *new_key + key_len - 1;
  177806. if (*kp == ' ')
  177807. {
  177808. png_warning(png_ptr, "trailing spaces removed from keyword");
  177809. while (*kp == ' ')
  177810. {
  177811. *(kp--) = '\0';
  177812. key_len--;
  177813. }
  177814. }
  177815. kp = *new_key;
  177816. if (*kp == ' ')
  177817. {
  177818. png_warning(png_ptr, "leading spaces removed from keyword");
  177819. while (*kp == ' ')
  177820. {
  177821. kp++;
  177822. key_len--;
  177823. }
  177824. }
  177825. png_debug1(2, "Checking for multiple internal spaces in '%s'\n", kp);
  177826. for (kflag = 0, dp = *new_key; *kp != '\0'; kp++)
  177827. {
  177828. if (*kp == ' ' && kflag == 0)
  177829. {
  177830. *(dp++) = *kp;
  177831. kflag = 1;
  177832. }
  177833. else if (*kp == ' ')
  177834. {
  177835. key_len--;
  177836. kwarn=1;
  177837. }
  177838. else
  177839. {
  177840. *(dp++) = *kp;
  177841. kflag = 0;
  177842. }
  177843. }
  177844. *dp = '\0';
  177845. if(kwarn)
  177846. png_warning(png_ptr, "extra interior spaces removed from keyword");
  177847. if (key_len == 0)
  177848. {
  177849. png_free(png_ptr, *new_key);
  177850. *new_key=NULL;
  177851. png_warning(png_ptr, "Zero length keyword");
  177852. }
  177853. if (key_len > 79)
  177854. {
  177855. png_warning(png_ptr, "keyword length must be 1 - 79 characters");
  177856. new_key[79] = '\0';
  177857. key_len = 79;
  177858. }
  177859. return (key_len);
  177860. }
  177861. #endif
  177862. #if defined(PNG_WRITE_tEXt_SUPPORTED)
  177863. void /* PRIVATE */
  177864. png_write_tEXt(png_structp png_ptr, png_charp key, png_charp text,
  177865. png_size_t text_len)
  177866. {
  177867. #ifdef PNG_USE_LOCAL_ARRAYS
  177868. PNG_tEXt;
  177869. #endif
  177870. png_size_t key_len;
  177871. png_charp new_key;
  177872. png_debug(1, "in png_write_tEXt\n");
  177873. if (key == NULL || (key_len = png_check_keyword(png_ptr, key, &new_key))==0)
  177874. {
  177875. png_warning(png_ptr, "Empty keyword in tEXt chunk");
  177876. return;
  177877. }
  177878. if (text == NULL || *text == '\0')
  177879. text_len = 0;
  177880. else
  177881. text_len = png_strlen(text);
  177882. png_write_chunk_start(png_ptr, png_tEXt, (png_uint_32)key_len+text_len+1);
  177883. png_write_chunk_data(png_ptr, (png_bytep)new_key, key_len + 1);
  177884. if (text_len)
  177885. png_write_chunk_data(png_ptr, (png_bytep)text, text_len);
  177886. png_write_chunk_end(png_ptr);
  177887. png_free(png_ptr, new_key);
  177888. }
  177889. #endif
  177890. #if defined(PNG_WRITE_zTXt_SUPPORTED)
  177891. void /* PRIVATE */
  177892. png_write_zTXt(png_structp png_ptr, png_charp key, png_charp text,
  177893. png_size_t text_len, int compression)
  177894. {
  177895. #ifdef PNG_USE_LOCAL_ARRAYS
  177896. PNG_zTXt;
  177897. #endif
  177898. png_size_t key_len;
  177899. char buf[1];
  177900. png_charp new_key;
  177901. compression_state comp;
  177902. png_debug(1, "in png_write_zTXt\n");
  177903. comp.num_output_ptr = 0;
  177904. comp.max_output_ptr = 0;
  177905. comp.output_ptr = NULL;
  177906. comp.input = NULL;
  177907. comp.input_len = 0;
  177908. if (key == NULL || (key_len = png_check_keyword(png_ptr, key, &new_key))==0)
  177909. {
  177910. png_warning(png_ptr, "Empty keyword in zTXt chunk");
  177911. return;
  177912. }
  177913. if (text == NULL || *text == '\0' || compression==PNG_TEXT_COMPRESSION_NONE)
  177914. {
  177915. png_write_tEXt(png_ptr, new_key, text, (png_size_t)0);
  177916. png_free(png_ptr, new_key);
  177917. return;
  177918. }
  177919. text_len = png_strlen(text);
  177920. text_len = png_text_compress(png_ptr, text, text_len, compression,
  177921. &comp);
  177922. png_write_chunk_start(png_ptr, png_zTXt, (png_uint_32)
  177923. (key_len+text_len+2));
  177924. png_write_chunk_data(png_ptr, (png_bytep)new_key, key_len + 1);
  177925. png_free(png_ptr, new_key);
  177926. buf[0] = (png_byte)compression;
  177927. png_write_chunk_data(png_ptr, (png_bytep)buf, (png_size_t)1);
  177928. png_write_compressed_data_out(png_ptr, &comp);
  177929. png_write_chunk_end(png_ptr);
  177930. }
  177931. #endif
  177932. #if defined(PNG_WRITE_iTXt_SUPPORTED)
  177933. void /* PRIVATE */
  177934. png_write_iTXt(png_structp png_ptr, int compression, png_charp key,
  177935. png_charp lang, png_charp lang_key, png_charp text)
  177936. {
  177937. #ifdef PNG_USE_LOCAL_ARRAYS
  177938. PNG_iTXt;
  177939. #endif
  177940. png_size_t lang_len, key_len, lang_key_len, text_len;
  177941. png_charp new_lang, new_key;
  177942. png_byte cbuf[2];
  177943. compression_state comp;
  177944. png_debug(1, "in png_write_iTXt\n");
  177945. comp.num_output_ptr = 0;
  177946. comp.max_output_ptr = 0;
  177947. comp.output_ptr = NULL;
  177948. comp.input = NULL;
  177949. if (key == NULL || (key_len = png_check_keyword(png_ptr, key, &new_key))==0)
  177950. {
  177951. png_warning(png_ptr, "Empty keyword in iTXt chunk");
  177952. return;
  177953. }
  177954. if (lang == NULL || (lang_len = png_check_keyword(png_ptr, lang, &new_lang))==0)
  177955. {
  177956. png_warning(png_ptr, "Empty language field in iTXt chunk");
  177957. new_lang = NULL;
  177958. lang_len = 0;
  177959. }
  177960. if (lang_key == NULL)
  177961. lang_key_len = 0;
  177962. else
  177963. lang_key_len = png_strlen(lang_key);
  177964. if (text == NULL)
  177965. text_len = 0;
  177966. else
  177967. text_len = png_strlen(text);
  177968. text_len = png_text_compress(png_ptr, text, text_len, compression-2,
  177969. &comp);
  177970. png_write_chunk_start(png_ptr, png_iTXt,
  177971. (png_uint_32)(
  177972. 5 /* comp byte, comp flag, terminators for key, lang and lang_key */
  177973. + key_len
  177974. + lang_len
  177975. + lang_key_len
  177976. + text_len));
  177977. png_write_chunk_data(png_ptr, (png_bytep)new_key, key_len + 1);
  177978. if (compression == PNG_ITXT_COMPRESSION_NONE || \
  177979. compression == PNG_TEXT_COMPRESSION_NONE)
  177980. cbuf[0] = 0;
  177981. else /* compression == PNG_ITXT_COMPRESSION_zTXt */
  177982. cbuf[0] = 1;
  177983. cbuf[1] = 0;
  177984. png_write_chunk_data(png_ptr, cbuf, 2);
  177985. cbuf[0] = 0;
  177986. png_write_chunk_data(png_ptr, (new_lang ? (png_bytep)new_lang : cbuf), lang_len + 1);
  177987. png_write_chunk_data(png_ptr, (lang_key ? (png_bytep)lang_key : cbuf), lang_key_len + 1);
  177988. png_write_compressed_data_out(png_ptr, &comp);
  177989. png_write_chunk_end(png_ptr);
  177990. png_free(png_ptr, new_key);
  177991. if (new_lang)
  177992. png_free(png_ptr, new_lang);
  177993. }
  177994. #endif
  177995. #if defined(PNG_WRITE_oFFs_SUPPORTED)
  177996. void /* PRIVATE */
  177997. png_write_oFFs(png_structp png_ptr, png_int_32 x_offset, png_int_32 y_offset,
  177998. int unit_type)
  177999. {
  178000. #ifdef PNG_USE_LOCAL_ARRAYS
  178001. PNG_oFFs;
  178002. #endif
  178003. png_byte buf[9];
  178004. png_debug(1, "in png_write_oFFs\n");
  178005. if (unit_type >= PNG_OFFSET_LAST)
  178006. png_warning(png_ptr, "Unrecognized unit type for oFFs chunk");
  178007. png_save_int_32(buf, x_offset);
  178008. png_save_int_32(buf + 4, y_offset);
  178009. buf[8] = (png_byte)unit_type;
  178010. png_write_chunk(png_ptr, png_oFFs, buf, (png_size_t)9);
  178011. }
  178012. #endif
  178013. #if defined(PNG_WRITE_pCAL_SUPPORTED)
  178014. void /* PRIVATE */
  178015. png_write_pCAL(png_structp png_ptr, png_charp purpose, png_int_32 X0,
  178016. png_int_32 X1, int type, int nparams, png_charp units, png_charpp params)
  178017. {
  178018. #ifdef PNG_USE_LOCAL_ARRAYS
  178019. PNG_pCAL;
  178020. #endif
  178021. png_size_t purpose_len, units_len, total_len;
  178022. png_uint_32p params_len;
  178023. png_byte buf[10];
  178024. png_charp new_purpose;
  178025. int i;
  178026. png_debug1(1, "in png_write_pCAL (%d parameters)\n", nparams);
  178027. if (type >= PNG_EQUATION_LAST)
  178028. png_warning(png_ptr, "Unrecognized equation type for pCAL chunk");
  178029. purpose_len = png_check_keyword(png_ptr, purpose, &new_purpose) + 1;
  178030. png_debug1(3, "pCAL purpose length = %d\n", (int)purpose_len);
  178031. units_len = png_strlen(units) + (nparams == 0 ? 0 : 1);
  178032. png_debug1(3, "pCAL units length = %d\n", (int)units_len);
  178033. total_len = purpose_len + units_len + 10;
  178034. params_len = (png_uint_32p)png_malloc(png_ptr, (png_uint_32)(nparams
  178035. *png_sizeof(png_uint_32)));
  178036. for (i = 0; i < nparams; i++)
  178037. {
  178038. params_len[i] = png_strlen(params[i]) + (i == nparams - 1 ? 0 : 1);
  178039. png_debug2(3, "pCAL parameter %d length = %lu\n", i, params_len[i]);
  178040. total_len += (png_size_t)params_len[i];
  178041. }
  178042. png_debug1(3, "pCAL total length = %d\n", (int)total_len);
  178043. png_write_chunk_start(png_ptr, png_pCAL, (png_uint_32)total_len);
  178044. png_write_chunk_data(png_ptr, (png_bytep)new_purpose, purpose_len);
  178045. png_save_int_32(buf, X0);
  178046. png_save_int_32(buf + 4, X1);
  178047. buf[8] = (png_byte)type;
  178048. buf[9] = (png_byte)nparams;
  178049. png_write_chunk_data(png_ptr, buf, (png_size_t)10);
  178050. png_write_chunk_data(png_ptr, (png_bytep)units, (png_size_t)units_len);
  178051. png_free(png_ptr, new_purpose);
  178052. for (i = 0; i < nparams; i++)
  178053. {
  178054. png_write_chunk_data(png_ptr, (png_bytep)params[i],
  178055. (png_size_t)params_len[i]);
  178056. }
  178057. png_free(png_ptr, params_len);
  178058. png_write_chunk_end(png_ptr);
  178059. }
  178060. #endif
  178061. #if defined(PNG_WRITE_sCAL_SUPPORTED)
  178062. #if defined(PNG_FLOATING_POINT_SUPPORTED) && !defined(PNG_NO_STDIO)
  178063. void /* PRIVATE */
  178064. png_write_sCAL(png_structp png_ptr, int unit, double width, double height)
  178065. {
  178066. #ifdef PNG_USE_LOCAL_ARRAYS
  178067. PNG_sCAL;
  178068. #endif
  178069. char buf[64];
  178070. png_size_t total_len;
  178071. png_debug(1, "in png_write_sCAL\n");
  178072. buf[0] = (char)unit;
  178073. #if defined(_WIN32_WCE)
  178074. {
  178075. wchar_t wc_buf[32];
  178076. size_t wc_len;
  178077. swprintf(wc_buf, TEXT("%12.12e"), width);
  178078. wc_len = wcslen(wc_buf);
  178079. WideCharToMultiByte(CP_ACP, 0, wc_buf, -1, buf + 1, wc_len, NULL, NULL);
  178080. total_len = wc_len + 2;
  178081. swprintf(wc_buf, TEXT("%12.12e"), height);
  178082. wc_len = wcslen(wc_buf);
  178083. WideCharToMultiByte(CP_ACP, 0, wc_buf, -1, buf + total_len, wc_len,
  178084. NULL, NULL);
  178085. total_len += wc_len;
  178086. }
  178087. #else
  178088. png_snprintf(buf + 1, 63, "%12.12e", width);
  178089. total_len = 1 + png_strlen(buf + 1) + 1;
  178090. png_snprintf(buf + total_len, 64-total_len, "%12.12e", height);
  178091. total_len += png_strlen(buf + total_len);
  178092. #endif
  178093. png_debug1(3, "sCAL total length = %u\n", (unsigned int)total_len);
  178094. png_write_chunk(png_ptr, png_sCAL, (png_bytep)buf, total_len);
  178095. }
  178096. #else
  178097. #ifdef PNG_FIXED_POINT_SUPPORTED
  178098. void /* PRIVATE */
  178099. png_write_sCAL_s(png_structp png_ptr, int unit, png_charp width,
  178100. png_charp height)
  178101. {
  178102. #ifdef PNG_USE_LOCAL_ARRAYS
  178103. PNG_sCAL;
  178104. #endif
  178105. png_byte buf[64];
  178106. png_size_t wlen, hlen, total_len;
  178107. png_debug(1, "in png_write_sCAL_s\n");
  178108. wlen = png_strlen(width);
  178109. hlen = png_strlen(height);
  178110. total_len = wlen + hlen + 2;
  178111. if (total_len > 64)
  178112. {
  178113. png_warning(png_ptr, "Can't write sCAL (buffer too small)");
  178114. return;
  178115. }
  178116. buf[0] = (png_byte)unit;
  178117. png_memcpy(buf + 1, width, wlen + 1); /* append the '\0' here */
  178118. png_memcpy(buf + wlen + 2, height, hlen); /* do NOT append the '\0' here */
  178119. png_debug1(3, "sCAL total length = %u\n", (unsigned int)total_len);
  178120. png_write_chunk(png_ptr, png_sCAL, buf, total_len);
  178121. }
  178122. #endif
  178123. #endif
  178124. #endif
  178125. #if defined(PNG_WRITE_pHYs_SUPPORTED)
  178126. void /* PRIVATE */
  178127. png_write_pHYs(png_structp png_ptr, png_uint_32 x_pixels_per_unit,
  178128. png_uint_32 y_pixels_per_unit,
  178129. int unit_type)
  178130. {
  178131. #ifdef PNG_USE_LOCAL_ARRAYS
  178132. PNG_pHYs;
  178133. #endif
  178134. png_byte buf[9];
  178135. png_debug(1, "in png_write_pHYs\n");
  178136. if (unit_type >= PNG_RESOLUTION_LAST)
  178137. png_warning(png_ptr, "Unrecognized unit type for pHYs chunk");
  178138. png_save_uint_32(buf, x_pixels_per_unit);
  178139. png_save_uint_32(buf + 4, y_pixels_per_unit);
  178140. buf[8] = (png_byte)unit_type;
  178141. png_write_chunk(png_ptr, png_pHYs, buf, (png_size_t)9);
  178142. }
  178143. #endif
  178144. #if defined(PNG_WRITE_tIME_SUPPORTED)
  178145. void /* PRIVATE */
  178146. png_write_tIME(png_structp png_ptr, png_timep mod_time)
  178147. {
  178148. #ifdef PNG_USE_LOCAL_ARRAYS
  178149. PNG_tIME;
  178150. #endif
  178151. png_byte buf[7];
  178152. png_debug(1, "in png_write_tIME\n");
  178153. if (mod_time->month > 12 || mod_time->month < 1 ||
  178154. mod_time->day > 31 || mod_time->day < 1 ||
  178155. mod_time->hour > 23 || mod_time->second > 60)
  178156. {
  178157. png_warning(png_ptr, "Invalid time specified for tIME chunk");
  178158. return;
  178159. }
  178160. png_save_uint_16(buf, mod_time->year);
  178161. buf[2] = mod_time->month;
  178162. buf[3] = mod_time->day;
  178163. buf[4] = mod_time->hour;
  178164. buf[5] = mod_time->minute;
  178165. buf[6] = mod_time->second;
  178166. png_write_chunk(png_ptr, png_tIME, buf, (png_size_t)7);
  178167. }
  178168. #endif
  178169. void /* PRIVATE */
  178170. png_write_start_row(png_structp png_ptr)
  178171. {
  178172. #ifdef PNG_WRITE_INTERLACING_SUPPORTED
  178173. #ifdef PNG_USE_LOCAL_ARRAYS
  178174. int png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0};
  178175. int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};
  178176. int png_pass_ystart[7] = {0, 0, 4, 0, 2, 0, 1};
  178177. int png_pass_yinc[7] = {8, 8, 8, 4, 4, 2, 2};
  178178. #endif
  178179. #endif
  178180. png_size_t buf_size;
  178181. png_debug(1, "in png_write_start_row\n");
  178182. buf_size = (png_size_t)(PNG_ROWBYTES(
  178183. png_ptr->usr_channels*png_ptr->usr_bit_depth,png_ptr->width)+1);
  178184. png_ptr->row_buf = (png_bytep)png_malloc(png_ptr, (png_uint_32)buf_size);
  178185. png_ptr->row_buf[0] = PNG_FILTER_VALUE_NONE;
  178186. #ifndef PNG_NO_WRITE_FILTERING
  178187. if (png_ptr->do_filter & PNG_FILTER_SUB)
  178188. {
  178189. png_ptr->sub_row = (png_bytep)png_malloc(png_ptr,
  178190. (png_ptr->rowbytes + 1));
  178191. png_ptr->sub_row[0] = PNG_FILTER_VALUE_SUB;
  178192. }
  178193. if (png_ptr->do_filter & (PNG_FILTER_AVG | PNG_FILTER_UP | PNG_FILTER_PAETH))
  178194. {
  178195. png_ptr->prev_row = (png_bytep)png_malloc(png_ptr, (png_uint_32)buf_size);
  178196. png_memset(png_ptr->prev_row, 0, buf_size);
  178197. if (png_ptr->do_filter & PNG_FILTER_UP)
  178198. {
  178199. png_ptr->up_row = (png_bytep)png_malloc(png_ptr,
  178200. (png_ptr->rowbytes + 1));
  178201. png_ptr->up_row[0] = PNG_FILTER_VALUE_UP;
  178202. }
  178203. if (png_ptr->do_filter & PNG_FILTER_AVG)
  178204. {
  178205. png_ptr->avg_row = (png_bytep)png_malloc(png_ptr,
  178206. (png_ptr->rowbytes + 1));
  178207. png_ptr->avg_row[0] = PNG_FILTER_VALUE_AVG;
  178208. }
  178209. if (png_ptr->do_filter & PNG_FILTER_PAETH)
  178210. {
  178211. png_ptr->paeth_row = (png_bytep)png_malloc(png_ptr,
  178212. (png_ptr->rowbytes + 1));
  178213. png_ptr->paeth_row[0] = PNG_FILTER_VALUE_PAETH;
  178214. }
  178215. #endif /* PNG_NO_WRITE_FILTERING */
  178216. }
  178217. #ifdef PNG_WRITE_INTERLACING_SUPPORTED
  178218. if (png_ptr->interlaced)
  178219. {
  178220. if (!(png_ptr->transformations & PNG_INTERLACE))
  178221. {
  178222. png_ptr->num_rows = (png_ptr->height + png_pass_yinc[0] - 1 -
  178223. png_pass_ystart[0]) / png_pass_yinc[0];
  178224. png_ptr->usr_width = (png_ptr->width + png_pass_inc[0] - 1 -
  178225. png_pass_start[0]) / png_pass_inc[0];
  178226. }
  178227. else
  178228. {
  178229. png_ptr->num_rows = png_ptr->height;
  178230. png_ptr->usr_width = png_ptr->width;
  178231. }
  178232. }
  178233. else
  178234. #endif
  178235. {
  178236. png_ptr->num_rows = png_ptr->height;
  178237. png_ptr->usr_width = png_ptr->width;
  178238. }
  178239. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  178240. png_ptr->zstream.next_out = png_ptr->zbuf;
  178241. }
  178242. void /* PRIVATE */
  178243. png_write_finish_row(png_structp png_ptr)
  178244. {
  178245. #ifdef PNG_WRITE_INTERLACING_SUPPORTED
  178246. #ifdef PNG_USE_LOCAL_ARRAYS
  178247. int png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0};
  178248. int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};
  178249. int png_pass_ystart[7] = {0, 0, 4, 0, 2, 0, 1};
  178250. int png_pass_yinc[7] = {8, 8, 8, 4, 4, 2, 2};
  178251. #endif
  178252. #endif
  178253. int ret;
  178254. png_debug(1, "in png_write_finish_row\n");
  178255. png_ptr->row_number++;
  178256. if (png_ptr->row_number < png_ptr->num_rows)
  178257. return;
  178258. #ifdef PNG_WRITE_INTERLACING_SUPPORTED
  178259. if (png_ptr->interlaced)
  178260. {
  178261. png_ptr->row_number = 0;
  178262. if (png_ptr->transformations & PNG_INTERLACE)
  178263. {
  178264. png_ptr->pass++;
  178265. }
  178266. else
  178267. {
  178268. do
  178269. {
  178270. png_ptr->pass++;
  178271. if (png_ptr->pass >= 7)
  178272. break;
  178273. png_ptr->usr_width = (png_ptr->width +
  178274. png_pass_inc[png_ptr->pass] - 1 -
  178275. png_pass_start[png_ptr->pass]) /
  178276. png_pass_inc[png_ptr->pass];
  178277. png_ptr->num_rows = (png_ptr->height +
  178278. png_pass_yinc[png_ptr->pass] - 1 -
  178279. png_pass_ystart[png_ptr->pass]) /
  178280. png_pass_yinc[png_ptr->pass];
  178281. if (png_ptr->transformations & PNG_INTERLACE)
  178282. break;
  178283. } while (png_ptr->usr_width == 0 || png_ptr->num_rows == 0);
  178284. }
  178285. if (png_ptr->pass < 7)
  178286. {
  178287. if (png_ptr->prev_row != NULL)
  178288. png_memset(png_ptr->prev_row, 0,
  178289. (png_size_t)(PNG_ROWBYTES(png_ptr->usr_channels*
  178290. png_ptr->usr_bit_depth,png_ptr->width))+1);
  178291. return;
  178292. }
  178293. }
  178294. #endif
  178295. do
  178296. {
  178297. ret = deflate(&png_ptr->zstream, Z_FINISH);
  178298. if (ret == Z_OK)
  178299. {
  178300. if (!(png_ptr->zstream.avail_out))
  178301. {
  178302. png_write_IDAT(png_ptr, png_ptr->zbuf, png_ptr->zbuf_size);
  178303. png_ptr->zstream.next_out = png_ptr->zbuf;
  178304. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  178305. }
  178306. }
  178307. else if (ret != Z_STREAM_END)
  178308. {
  178309. if (png_ptr->zstream.msg != NULL)
  178310. png_error(png_ptr, png_ptr->zstream.msg);
  178311. else
  178312. png_error(png_ptr, "zlib error");
  178313. }
  178314. } while (ret != Z_STREAM_END);
  178315. if (png_ptr->zstream.avail_out < png_ptr->zbuf_size)
  178316. {
  178317. png_write_IDAT(png_ptr, png_ptr->zbuf, png_ptr->zbuf_size -
  178318. png_ptr->zstream.avail_out);
  178319. }
  178320. deflateReset(&png_ptr->zstream);
  178321. png_ptr->zstream.data_type = Z_BINARY;
  178322. }
  178323. #if defined(PNG_WRITE_INTERLACING_SUPPORTED)
  178324. void /* PRIVATE */
  178325. png_do_write_interlace(png_row_infop row_info, png_bytep row, int pass)
  178326. {
  178327. #ifdef PNG_USE_LOCAL_ARRAYS
  178328. int png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0};
  178329. int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};
  178330. #endif
  178331. png_debug(1, "in png_do_write_interlace\n");
  178332. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  178333. if (row != NULL && row_info != NULL && pass < 6)
  178334. #else
  178335. if (pass < 6)
  178336. #endif
  178337. {
  178338. switch (row_info->pixel_depth)
  178339. {
  178340. case 1:
  178341. {
  178342. png_bytep sp;
  178343. png_bytep dp;
  178344. int shift;
  178345. int d;
  178346. int value;
  178347. png_uint_32 i;
  178348. png_uint_32 row_width = row_info->width;
  178349. dp = row;
  178350. d = 0;
  178351. shift = 7;
  178352. for (i = png_pass_start[pass]; i < row_width;
  178353. i += png_pass_inc[pass])
  178354. {
  178355. sp = row + (png_size_t)(i >> 3);
  178356. value = (int)(*sp >> (7 - (int)(i & 0x07))) & 0x01;
  178357. d |= (value << shift);
  178358. if (shift == 0)
  178359. {
  178360. shift = 7;
  178361. *dp++ = (png_byte)d;
  178362. d = 0;
  178363. }
  178364. else
  178365. shift--;
  178366. }
  178367. if (shift != 7)
  178368. *dp = (png_byte)d;
  178369. break;
  178370. }
  178371. case 2:
  178372. {
  178373. png_bytep sp;
  178374. png_bytep dp;
  178375. int shift;
  178376. int d;
  178377. int value;
  178378. png_uint_32 i;
  178379. png_uint_32 row_width = row_info->width;
  178380. dp = row;
  178381. shift = 6;
  178382. d = 0;
  178383. for (i = png_pass_start[pass]; i < row_width;
  178384. i += png_pass_inc[pass])
  178385. {
  178386. sp = row + (png_size_t)(i >> 2);
  178387. value = (*sp >> ((3 - (int)(i & 0x03)) << 1)) & 0x03;
  178388. d |= (value << shift);
  178389. if (shift == 0)
  178390. {
  178391. shift = 6;
  178392. *dp++ = (png_byte)d;
  178393. d = 0;
  178394. }
  178395. else
  178396. shift -= 2;
  178397. }
  178398. if (shift != 6)
  178399. *dp = (png_byte)d;
  178400. break;
  178401. }
  178402. case 4:
  178403. {
  178404. png_bytep sp;
  178405. png_bytep dp;
  178406. int shift;
  178407. int d;
  178408. int value;
  178409. png_uint_32 i;
  178410. png_uint_32 row_width = row_info->width;
  178411. dp = row;
  178412. shift = 4;
  178413. d = 0;
  178414. for (i = png_pass_start[pass]; i < row_width;
  178415. i += png_pass_inc[pass])
  178416. {
  178417. sp = row + (png_size_t)(i >> 1);
  178418. value = (*sp >> ((1 - (int)(i & 0x01)) << 2)) & 0x0f;
  178419. d |= (value << shift);
  178420. if (shift == 0)
  178421. {
  178422. shift = 4;
  178423. *dp++ = (png_byte)d;
  178424. d = 0;
  178425. }
  178426. else
  178427. shift -= 4;
  178428. }
  178429. if (shift != 4)
  178430. *dp = (png_byte)d;
  178431. break;
  178432. }
  178433. default:
  178434. {
  178435. png_bytep sp;
  178436. png_bytep dp;
  178437. png_uint_32 i;
  178438. png_uint_32 row_width = row_info->width;
  178439. png_size_t pixel_bytes;
  178440. dp = row;
  178441. pixel_bytes = (row_info->pixel_depth >> 3);
  178442. for (i = png_pass_start[pass]; i < row_width;
  178443. i += png_pass_inc[pass])
  178444. {
  178445. sp = row + (png_size_t)i * pixel_bytes;
  178446. if (dp != sp)
  178447. png_memcpy(dp, sp, pixel_bytes);
  178448. dp += pixel_bytes;
  178449. }
  178450. break;
  178451. }
  178452. }
  178453. row_info->width = (row_info->width +
  178454. png_pass_inc[pass] - 1 -
  178455. png_pass_start[pass]) /
  178456. png_pass_inc[pass];
  178457. row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,
  178458. row_info->width);
  178459. }
  178460. }
  178461. #endif
  178462. #define PNG_MAXSUM (((png_uint_32)(-1)) >> 1)
  178463. #define PNG_HISHIFT 10
  178464. #define PNG_LOMASK ((png_uint_32)0xffffL)
  178465. #define PNG_HIMASK ((png_uint_32)(~PNG_LOMASK >> PNG_HISHIFT))
  178466. void /* PRIVATE */
  178467. png_write_find_filter(png_structp png_ptr, png_row_infop row_info)
  178468. {
  178469. png_bytep best_row;
  178470. #ifndef PNG_NO_WRITE_FILTER
  178471. png_bytep prev_row, row_buf;
  178472. png_uint_32 mins, bpp;
  178473. png_byte filter_to_do = png_ptr->do_filter;
  178474. png_uint_32 row_bytes = row_info->rowbytes;
  178475. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  178476. int num_p_filters = (int)png_ptr->num_prev_filters;
  178477. #endif
  178478. png_debug(1, "in png_write_find_filter\n");
  178479. bpp = (row_info->pixel_depth + 7) >> 3;
  178480. prev_row = png_ptr->prev_row;
  178481. #endif
  178482. best_row = png_ptr->row_buf;
  178483. #ifndef PNG_NO_WRITE_FILTER
  178484. row_buf = best_row;
  178485. mins = PNG_MAXSUM;
  178486. if ((filter_to_do & PNG_FILTER_NONE) &&
  178487. filter_to_do != PNG_FILTER_NONE)
  178488. {
  178489. png_bytep rp;
  178490. png_uint_32 sum = 0;
  178491. png_uint_32 i;
  178492. int v;
  178493. for (i = 0, rp = row_buf + 1; i < row_bytes; i++, rp++)
  178494. {
  178495. v = *rp;
  178496. sum += (v < 128) ? v : 256 - v;
  178497. }
  178498. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  178499. if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
  178500. {
  178501. png_uint_32 sumhi, sumlo;
  178502. int j;
  178503. sumlo = sum & PNG_LOMASK;
  178504. sumhi = (sum >> PNG_HISHIFT) & PNG_HIMASK; /* Gives us some footroom */
  178505. for (j = 0; j < num_p_filters; j++)
  178506. {
  178507. if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_NONE)
  178508. {
  178509. sumlo = (sumlo * png_ptr->filter_weights[j]) >>
  178510. PNG_WEIGHT_SHIFT;
  178511. sumhi = (sumhi * png_ptr->filter_weights[j]) >>
  178512. PNG_WEIGHT_SHIFT;
  178513. }
  178514. }
  178515. sumlo = (sumlo * png_ptr->filter_costs[PNG_FILTER_VALUE_NONE]) >>
  178516. PNG_COST_SHIFT;
  178517. sumhi = (sumhi * png_ptr->filter_costs[PNG_FILTER_VALUE_NONE]) >>
  178518. PNG_COST_SHIFT;
  178519. if (sumhi > PNG_HIMASK)
  178520. sum = PNG_MAXSUM;
  178521. else
  178522. sum = (sumhi << PNG_HISHIFT) + sumlo;
  178523. }
  178524. #endif
  178525. mins = sum;
  178526. }
  178527. if (filter_to_do == PNG_FILTER_SUB)
  178528. {
  178529. png_bytep rp, lp, dp;
  178530. png_uint_32 i;
  178531. for (i = 0, rp = row_buf + 1, dp = png_ptr->sub_row + 1; i < bpp;
  178532. i++, rp++, dp++)
  178533. {
  178534. *dp = *rp;
  178535. }
  178536. for (lp = row_buf + 1; i < row_bytes;
  178537. i++, rp++, lp++, dp++)
  178538. {
  178539. *dp = (png_byte)(((int)*rp - (int)*lp) & 0xff);
  178540. }
  178541. best_row = png_ptr->sub_row;
  178542. }
  178543. else if (filter_to_do & PNG_FILTER_SUB)
  178544. {
  178545. png_bytep rp, dp, lp;
  178546. png_uint_32 sum = 0, lmins = mins;
  178547. png_uint_32 i;
  178548. int v;
  178549. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  178550. if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
  178551. {
  178552. int j;
  178553. png_uint_32 lmhi, lmlo;
  178554. lmlo = lmins & PNG_LOMASK;
  178555. lmhi = (lmins >> PNG_HISHIFT) & PNG_HIMASK;
  178556. for (j = 0; j < num_p_filters; j++)
  178557. {
  178558. if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_SUB)
  178559. {
  178560. lmlo = (lmlo * png_ptr->inv_filter_weights[j]) >>
  178561. PNG_WEIGHT_SHIFT;
  178562. lmhi = (lmhi * png_ptr->inv_filter_weights[j]) >>
  178563. PNG_WEIGHT_SHIFT;
  178564. }
  178565. }
  178566. lmlo = (lmlo * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_SUB]) >>
  178567. PNG_COST_SHIFT;
  178568. lmhi = (lmhi * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_SUB]) >>
  178569. PNG_COST_SHIFT;
  178570. if (lmhi > PNG_HIMASK)
  178571. lmins = PNG_MAXSUM;
  178572. else
  178573. lmins = (lmhi << PNG_HISHIFT) + lmlo;
  178574. }
  178575. #endif
  178576. for (i = 0, rp = row_buf + 1, dp = png_ptr->sub_row + 1; i < bpp;
  178577. i++, rp++, dp++)
  178578. {
  178579. v = *dp = *rp;
  178580. sum += (v < 128) ? v : 256 - v;
  178581. }
  178582. for (lp = row_buf + 1; i < row_bytes;
  178583. i++, rp++, lp++, dp++)
  178584. {
  178585. v = *dp = (png_byte)(((int)*rp - (int)*lp) & 0xff);
  178586. sum += (v < 128) ? v : 256 - v;
  178587. if (sum > lmins) /* We are already worse, don't continue. */
  178588. break;
  178589. }
  178590. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  178591. if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
  178592. {
  178593. int j;
  178594. png_uint_32 sumhi, sumlo;
  178595. sumlo = sum & PNG_LOMASK;
  178596. sumhi = (sum >> PNG_HISHIFT) & PNG_HIMASK;
  178597. for (j = 0; j < num_p_filters; j++)
  178598. {
  178599. if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_SUB)
  178600. {
  178601. sumlo = (sumlo * png_ptr->inv_filter_weights[j]) >>
  178602. PNG_WEIGHT_SHIFT;
  178603. sumhi = (sumhi * png_ptr->inv_filter_weights[j]) >>
  178604. PNG_WEIGHT_SHIFT;
  178605. }
  178606. }
  178607. sumlo = (sumlo * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_SUB]) >>
  178608. PNG_COST_SHIFT;
  178609. sumhi = (sumhi * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_SUB]) >>
  178610. PNG_COST_SHIFT;
  178611. if (sumhi > PNG_HIMASK)
  178612. sum = PNG_MAXSUM;
  178613. else
  178614. sum = (sumhi << PNG_HISHIFT) + sumlo;
  178615. }
  178616. #endif
  178617. if (sum < mins)
  178618. {
  178619. mins = sum;
  178620. best_row = png_ptr->sub_row;
  178621. }
  178622. }
  178623. if (filter_to_do == PNG_FILTER_UP)
  178624. {
  178625. png_bytep rp, dp, pp;
  178626. png_uint_32 i;
  178627. for (i = 0, rp = row_buf + 1, dp = png_ptr->up_row + 1,
  178628. pp = prev_row + 1; i < row_bytes;
  178629. i++, rp++, pp++, dp++)
  178630. {
  178631. *dp = (png_byte)(((int)*rp - (int)*pp) & 0xff);
  178632. }
  178633. best_row = png_ptr->up_row;
  178634. }
  178635. else if (filter_to_do & PNG_FILTER_UP)
  178636. {
  178637. png_bytep rp, dp, pp;
  178638. png_uint_32 sum = 0, lmins = mins;
  178639. png_uint_32 i;
  178640. int v;
  178641. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  178642. if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
  178643. {
  178644. int j;
  178645. png_uint_32 lmhi, lmlo;
  178646. lmlo = lmins & PNG_LOMASK;
  178647. lmhi = (lmins >> PNG_HISHIFT) & PNG_HIMASK;
  178648. for (j = 0; j < num_p_filters; j++)
  178649. {
  178650. if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_UP)
  178651. {
  178652. lmlo = (lmlo * png_ptr->inv_filter_weights[j]) >>
  178653. PNG_WEIGHT_SHIFT;
  178654. lmhi = (lmhi * png_ptr->inv_filter_weights[j]) >>
  178655. PNG_WEIGHT_SHIFT;
  178656. }
  178657. }
  178658. lmlo = (lmlo * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_UP]) >>
  178659. PNG_COST_SHIFT;
  178660. lmhi = (lmhi * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_UP]) >>
  178661. PNG_COST_SHIFT;
  178662. if (lmhi > PNG_HIMASK)
  178663. lmins = PNG_MAXSUM;
  178664. else
  178665. lmins = (lmhi << PNG_HISHIFT) + lmlo;
  178666. }
  178667. #endif
  178668. for (i = 0, rp = row_buf + 1, dp = png_ptr->up_row + 1,
  178669. pp = prev_row + 1; i < row_bytes; i++)
  178670. {
  178671. v = *dp++ = (png_byte)(((int)*rp++ - (int)*pp++) & 0xff);
  178672. sum += (v < 128) ? v : 256 - v;
  178673. if (sum > lmins) /* We are already worse, don't continue. */
  178674. break;
  178675. }
  178676. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  178677. if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
  178678. {
  178679. int j;
  178680. png_uint_32 sumhi, sumlo;
  178681. sumlo = sum & PNG_LOMASK;
  178682. sumhi = (sum >> PNG_HISHIFT) & PNG_HIMASK;
  178683. for (j = 0; j < num_p_filters; j++)
  178684. {
  178685. if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_UP)
  178686. {
  178687. sumlo = (sumlo * png_ptr->filter_weights[j]) >>
  178688. PNG_WEIGHT_SHIFT;
  178689. sumhi = (sumhi * png_ptr->filter_weights[j]) >>
  178690. PNG_WEIGHT_SHIFT;
  178691. }
  178692. }
  178693. sumlo = (sumlo * png_ptr->filter_costs[PNG_FILTER_VALUE_UP]) >>
  178694. PNG_COST_SHIFT;
  178695. sumhi = (sumhi * png_ptr->filter_costs[PNG_FILTER_VALUE_UP]) >>
  178696. PNG_COST_SHIFT;
  178697. if (sumhi > PNG_HIMASK)
  178698. sum = PNG_MAXSUM;
  178699. else
  178700. sum = (sumhi << PNG_HISHIFT) + sumlo;
  178701. }
  178702. #endif
  178703. if (sum < mins)
  178704. {
  178705. mins = sum;
  178706. best_row = png_ptr->up_row;
  178707. }
  178708. }
  178709. if (filter_to_do == PNG_FILTER_AVG)
  178710. {
  178711. png_bytep rp, dp, pp, lp;
  178712. png_uint_32 i;
  178713. for (i = 0, rp = row_buf + 1, dp = png_ptr->avg_row + 1,
  178714. pp = prev_row + 1; i < bpp; i++)
  178715. {
  178716. *dp++ = (png_byte)(((int)*rp++ - ((int)*pp++ / 2)) & 0xff);
  178717. }
  178718. for (lp = row_buf + 1; i < row_bytes; i++)
  178719. {
  178720. *dp++ = (png_byte)(((int)*rp++ - (((int)*pp++ + (int)*lp++) / 2))
  178721. & 0xff);
  178722. }
  178723. best_row = png_ptr->avg_row;
  178724. }
  178725. else if (filter_to_do & PNG_FILTER_AVG)
  178726. {
  178727. png_bytep rp, dp, pp, lp;
  178728. png_uint_32 sum = 0, lmins = mins;
  178729. png_uint_32 i;
  178730. int v;
  178731. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  178732. if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
  178733. {
  178734. int j;
  178735. png_uint_32 lmhi, lmlo;
  178736. lmlo = lmins & PNG_LOMASK;
  178737. lmhi = (lmins >> PNG_HISHIFT) & PNG_HIMASK;
  178738. for (j = 0; j < num_p_filters; j++)
  178739. {
  178740. if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_AVG)
  178741. {
  178742. lmlo = (lmlo * png_ptr->inv_filter_weights[j]) >>
  178743. PNG_WEIGHT_SHIFT;
  178744. lmhi = (lmhi * png_ptr->inv_filter_weights[j]) >>
  178745. PNG_WEIGHT_SHIFT;
  178746. }
  178747. }
  178748. lmlo = (lmlo * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_AVG]) >>
  178749. PNG_COST_SHIFT;
  178750. lmhi = (lmhi * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_AVG]) >>
  178751. PNG_COST_SHIFT;
  178752. if (lmhi > PNG_HIMASK)
  178753. lmins = PNG_MAXSUM;
  178754. else
  178755. lmins = (lmhi << PNG_HISHIFT) + lmlo;
  178756. }
  178757. #endif
  178758. for (i = 0, rp = row_buf + 1, dp = png_ptr->avg_row + 1,
  178759. pp = prev_row + 1; i < bpp; i++)
  178760. {
  178761. v = *dp++ = (png_byte)(((int)*rp++ - ((int)*pp++ / 2)) & 0xff);
  178762. sum += (v < 128) ? v : 256 - v;
  178763. }
  178764. for (lp = row_buf + 1; i < row_bytes; i++)
  178765. {
  178766. v = *dp++ =
  178767. (png_byte)(((int)*rp++ - (((int)*pp++ + (int)*lp++) / 2)) & 0xff);
  178768. sum += (v < 128) ? v : 256 - v;
  178769. if (sum > lmins) /* We are already worse, don't continue. */
  178770. break;
  178771. }
  178772. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  178773. if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
  178774. {
  178775. int j;
  178776. png_uint_32 sumhi, sumlo;
  178777. sumlo = sum & PNG_LOMASK;
  178778. sumhi = (sum >> PNG_HISHIFT) & PNG_HIMASK;
  178779. for (j = 0; j < num_p_filters; j++)
  178780. {
  178781. if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_NONE)
  178782. {
  178783. sumlo = (sumlo * png_ptr->filter_weights[j]) >>
  178784. PNG_WEIGHT_SHIFT;
  178785. sumhi = (sumhi * png_ptr->filter_weights[j]) >>
  178786. PNG_WEIGHT_SHIFT;
  178787. }
  178788. }
  178789. sumlo = (sumlo * png_ptr->filter_costs[PNG_FILTER_VALUE_AVG]) >>
  178790. PNG_COST_SHIFT;
  178791. sumhi = (sumhi * png_ptr->filter_costs[PNG_FILTER_VALUE_AVG]) >>
  178792. PNG_COST_SHIFT;
  178793. if (sumhi > PNG_HIMASK)
  178794. sum = PNG_MAXSUM;
  178795. else
  178796. sum = (sumhi << PNG_HISHIFT) + sumlo;
  178797. }
  178798. #endif
  178799. if (sum < mins)
  178800. {
  178801. mins = sum;
  178802. best_row = png_ptr->avg_row;
  178803. }
  178804. }
  178805. if (filter_to_do == PNG_FILTER_PAETH)
  178806. {
  178807. png_bytep rp, dp, pp, cp, lp;
  178808. png_uint_32 i;
  178809. for (i = 0, rp = row_buf + 1, dp = png_ptr->paeth_row + 1,
  178810. pp = prev_row + 1; i < bpp; i++)
  178811. {
  178812. *dp++ = (png_byte)(((int)*rp++ - (int)*pp++) & 0xff);
  178813. }
  178814. for (lp = row_buf + 1, cp = prev_row + 1; i < row_bytes; i++)
  178815. {
  178816. int a, b, c, pa, pb, pc, p;
  178817. b = *pp++;
  178818. c = *cp++;
  178819. a = *lp++;
  178820. p = b - c;
  178821. pc = a - c;
  178822. #ifdef PNG_USE_ABS
  178823. pa = abs(p);
  178824. pb = abs(pc);
  178825. pc = abs(p + pc);
  178826. #else
  178827. pa = p < 0 ? -p : p;
  178828. pb = pc < 0 ? -pc : pc;
  178829. pc = (p + pc) < 0 ? -(p + pc) : p + pc;
  178830. #endif
  178831. p = (pa <= pb && pa <=pc) ? a : (pb <= pc) ? b : c;
  178832. *dp++ = (png_byte)(((int)*rp++ - p) & 0xff);
  178833. }
  178834. best_row = png_ptr->paeth_row;
  178835. }
  178836. else if (filter_to_do & PNG_FILTER_PAETH)
  178837. {
  178838. png_bytep rp, dp, pp, cp, lp;
  178839. png_uint_32 sum = 0, lmins = mins;
  178840. png_uint_32 i;
  178841. int v;
  178842. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  178843. if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
  178844. {
  178845. int j;
  178846. png_uint_32 lmhi, lmlo;
  178847. lmlo = lmins & PNG_LOMASK;
  178848. lmhi = (lmins >> PNG_HISHIFT) & PNG_HIMASK;
  178849. for (j = 0; j < num_p_filters; j++)
  178850. {
  178851. if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_PAETH)
  178852. {
  178853. lmlo = (lmlo * png_ptr->inv_filter_weights[j]) >>
  178854. PNG_WEIGHT_SHIFT;
  178855. lmhi = (lmhi * png_ptr->inv_filter_weights[j]) >>
  178856. PNG_WEIGHT_SHIFT;
  178857. }
  178858. }
  178859. lmlo = (lmlo * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_PAETH]) >>
  178860. PNG_COST_SHIFT;
  178861. lmhi = (lmhi * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_PAETH]) >>
  178862. PNG_COST_SHIFT;
  178863. if (lmhi > PNG_HIMASK)
  178864. lmins = PNG_MAXSUM;
  178865. else
  178866. lmins = (lmhi << PNG_HISHIFT) + lmlo;
  178867. }
  178868. #endif
  178869. for (i = 0, rp = row_buf + 1, dp = png_ptr->paeth_row + 1,
  178870. pp = prev_row + 1; i < bpp; i++)
  178871. {
  178872. v = *dp++ = (png_byte)(((int)*rp++ - (int)*pp++) & 0xff);
  178873. sum += (v < 128) ? v : 256 - v;
  178874. }
  178875. for (lp = row_buf + 1, cp = prev_row + 1; i < row_bytes; i++)
  178876. {
  178877. int a, b, c, pa, pb, pc, p;
  178878. b = *pp++;
  178879. c = *cp++;
  178880. a = *lp++;
  178881. #ifndef PNG_SLOW_PAETH
  178882. p = b - c;
  178883. pc = a - c;
  178884. #ifdef PNG_USE_ABS
  178885. pa = abs(p);
  178886. pb = abs(pc);
  178887. pc = abs(p + pc);
  178888. #else
  178889. pa = p < 0 ? -p : p;
  178890. pb = pc < 0 ? -pc : pc;
  178891. pc = (p + pc) < 0 ? -(p + pc) : p + pc;
  178892. #endif
  178893. p = (pa <= pb && pa <=pc) ? a : (pb <= pc) ? b : c;
  178894. #else /* PNG_SLOW_PAETH */
  178895. p = a + b - c;
  178896. pa = abs(p - a);
  178897. pb = abs(p - b);
  178898. pc = abs(p - c);
  178899. if (pa <= pb && pa <= pc)
  178900. p = a;
  178901. else if (pb <= pc)
  178902. p = b;
  178903. else
  178904. p = c;
  178905. #endif /* PNG_SLOW_PAETH */
  178906. v = *dp++ = (png_byte)(((int)*rp++ - p) & 0xff);
  178907. sum += (v < 128) ? v : 256 - v;
  178908. if (sum > lmins) /* We are already worse, don't continue. */
  178909. break;
  178910. }
  178911. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  178912. if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
  178913. {
  178914. int j;
  178915. png_uint_32 sumhi, sumlo;
  178916. sumlo = sum & PNG_LOMASK;
  178917. sumhi = (sum >> PNG_HISHIFT) & PNG_HIMASK;
  178918. for (j = 0; j < num_p_filters; j++)
  178919. {
  178920. if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_PAETH)
  178921. {
  178922. sumlo = (sumlo * png_ptr->filter_weights[j]) >>
  178923. PNG_WEIGHT_SHIFT;
  178924. sumhi = (sumhi * png_ptr->filter_weights[j]) >>
  178925. PNG_WEIGHT_SHIFT;
  178926. }
  178927. }
  178928. sumlo = (sumlo * png_ptr->filter_costs[PNG_FILTER_VALUE_PAETH]) >>
  178929. PNG_COST_SHIFT;
  178930. sumhi = (sumhi * png_ptr->filter_costs[PNG_FILTER_VALUE_PAETH]) >>
  178931. PNG_COST_SHIFT;
  178932. if (sumhi > PNG_HIMASK)
  178933. sum = PNG_MAXSUM;
  178934. else
  178935. sum = (sumhi << PNG_HISHIFT) + sumlo;
  178936. }
  178937. #endif
  178938. if (sum < mins)
  178939. {
  178940. best_row = png_ptr->paeth_row;
  178941. }
  178942. }
  178943. #endif /* PNG_NO_WRITE_FILTER */
  178944. png_write_filtered_row(png_ptr, best_row);
  178945. #ifndef PNG_NO_WRITE_FILTER
  178946. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  178947. if (png_ptr->num_prev_filters > 0)
  178948. {
  178949. int j;
  178950. for (j = 1; j < num_p_filters; j++)
  178951. {
  178952. png_ptr->prev_filters[j] = png_ptr->prev_filters[j - 1];
  178953. }
  178954. png_ptr->prev_filters[j] = best_row[0];
  178955. }
  178956. #endif
  178957. #endif /* PNG_NO_WRITE_FILTER */
  178958. }
  178959. void /* PRIVATE */
  178960. png_write_filtered_row(png_structp png_ptr, png_bytep filtered_row)
  178961. {
  178962. png_debug(1, "in png_write_filtered_row\n");
  178963. png_debug1(2, "filter = %d\n", filtered_row[0]);
  178964. png_ptr->zstream.next_in = filtered_row;
  178965. png_ptr->zstream.avail_in = (uInt)png_ptr->row_info.rowbytes + 1;
  178966. do
  178967. {
  178968. int ret; /* return of zlib */
  178969. ret = deflate(&png_ptr->zstream, Z_NO_FLUSH);
  178970. if (ret != Z_OK)
  178971. {
  178972. if (png_ptr->zstream.msg != NULL)
  178973. png_error(png_ptr, png_ptr->zstream.msg);
  178974. else
  178975. png_error(png_ptr, "zlib error");
  178976. }
  178977. if (!(png_ptr->zstream.avail_out))
  178978. {
  178979. png_write_IDAT(png_ptr, png_ptr->zbuf, png_ptr->zbuf_size);
  178980. png_ptr->zstream.next_out = png_ptr->zbuf;
  178981. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  178982. }
  178983. } while (png_ptr->zstream.avail_in);
  178984. if (png_ptr->prev_row != NULL)
  178985. {
  178986. png_bytep tptr;
  178987. tptr = png_ptr->prev_row;
  178988. png_ptr->prev_row = png_ptr->row_buf;
  178989. png_ptr->row_buf = tptr;
  178990. }
  178991. png_write_finish_row(png_ptr);
  178992. #if defined(PNG_WRITE_FLUSH_SUPPORTED)
  178993. png_ptr->flush_rows++;
  178994. if (png_ptr->flush_dist > 0 &&
  178995. png_ptr->flush_rows >= png_ptr->flush_dist)
  178996. {
  178997. png_write_flush(png_ptr);
  178998. }
  178999. #endif
  179000. }
  179001. #endif /* PNG_WRITE_SUPPORTED */
  179002. /*** End of inlined file: pngwutil.c ***/
  179003. }
  179004. #else
  179005. #define PNG_INTERNAL
  179006. #define PNG_SETJMP_NOT_SUPPORTED
  179007. #include <png.h>
  179008. #include <pngconf.h>
  179009. #endif
  179010. }
  179011. #ifdef _MSC_VER
  179012. #pragma warning (pop)
  179013. #endif
  179014. BEGIN_JUCE_NAMESPACE
  179015. using ::calloc;
  179016. using ::malloc;
  179017. using ::free;
  179018. namespace PNGHelpers
  179019. {
  179020. using namespace pnglibNamespace;
  179021. static void readCallback (png_structp pngReadStruct, png_bytep data, png_size_t length)
  179022. {
  179023. using namespace pnglibNamespace;
  179024. InputStream* const in = (InputStream*) png_get_io_ptr (pngReadStruct);
  179025. in->read (data, (int) length);
  179026. }
  179027. struct PNGErrorStruct {};
  179028. static void errorCallback (png_structp, png_const_charp)
  179029. {
  179030. throw PNGErrorStruct();
  179031. }
  179032. static void writeDataCallback (png_structp png_ptr, png_bytep data, png_size_t length)
  179033. {
  179034. OutputStream* const out = (OutputStream*) png_ptr->io_ptr;
  179035. const bool ok = out->write (data, (int) length);
  179036. (void) ok;
  179037. jassert (ok);
  179038. }
  179039. }
  179040. Image* juce_loadPNGImageFromStream (InputStream& in)
  179041. {
  179042. using namespace pnglibNamespace;
  179043. Image* image = 0;
  179044. png_structp pngReadStruct;
  179045. png_infop pngInfoStruct;
  179046. pngReadStruct = png_create_read_struct (PNG_LIBPNG_VER_STRING, 0, 0, 0);
  179047. if (pngReadStruct != 0)
  179048. {
  179049. pngInfoStruct = png_create_info_struct (pngReadStruct);
  179050. if (pngInfoStruct == 0)
  179051. {
  179052. png_destroy_read_struct (&pngReadStruct, 0, 0);
  179053. return 0;
  179054. }
  179055. png_set_error_fn (pngReadStruct, 0, PNGHelpers::errorCallback, PNGHelpers::errorCallback );
  179056. // read the header..
  179057. png_set_read_fn (pngReadStruct, &in, PNGHelpers::readCallback);
  179058. png_uint_32 width, height;
  179059. int bitDepth, colorType, interlaceType;
  179060. png_read_info (pngReadStruct, pngInfoStruct);
  179061. png_get_IHDR (pngReadStruct, pngInfoStruct,
  179062. &width, &height,
  179063. &bitDepth, &colorType,
  179064. &interlaceType, 0, 0);
  179065. if (bitDepth == 16)
  179066. png_set_strip_16 (pngReadStruct);
  179067. if (colorType == PNG_COLOR_TYPE_PALETTE)
  179068. png_set_expand (pngReadStruct);
  179069. if (bitDepth < 8)
  179070. png_set_expand (pngReadStruct);
  179071. if (png_get_valid (pngReadStruct, pngInfoStruct, PNG_INFO_tRNS))
  179072. png_set_expand (pngReadStruct);
  179073. if (colorType == PNG_COLOR_TYPE_GRAY || colorType == PNG_COLOR_TYPE_GRAY_ALPHA)
  179074. png_set_gray_to_rgb (pngReadStruct);
  179075. png_set_add_alpha (pngReadStruct, 0xff, PNG_FILLER_AFTER);
  179076. bool hasAlphaChan = (colorType & PNG_COLOR_MASK_ALPHA) != 0
  179077. || pngInfoStruct->num_trans > 0;
  179078. // Load the image into a temp buffer in the pnglib format..
  179079. HeapBlock <uint8> tempBuffer (height * (width << 2));
  179080. {
  179081. HeapBlock <png_bytep> rows (height);
  179082. for (int y = (int) height; --y >= 0;)
  179083. rows[y] = (png_bytep) (tempBuffer + (width << 2) * y);
  179084. png_read_image (pngReadStruct, rows);
  179085. png_read_end (pngReadStruct, pngInfoStruct);
  179086. }
  179087. png_destroy_read_struct (&pngReadStruct, &pngInfoStruct, 0);
  179088. // now convert the data to a juce image format..
  179089. image = Image::createNativeImage (hasAlphaChan ? Image::ARGB : Image::RGB,
  179090. (int) width, (int) height, hasAlphaChan);
  179091. hasAlphaChan = image->hasAlphaChannel(); // (the native image creator may not give back what we expect)
  179092. const Image::BitmapData destData (*image, 0, 0, (int) width, (int) height, true);
  179093. uint8* srcRow = tempBuffer;
  179094. uint8* destRow = destData.data;
  179095. for (int y = 0; y < (int) height; ++y)
  179096. {
  179097. const uint8* src = srcRow;
  179098. srcRow += (width << 2);
  179099. uint8* dest = destRow;
  179100. destRow += destData.lineStride;
  179101. if (hasAlphaChan)
  179102. {
  179103. for (int i = (int) width; --i >= 0;)
  179104. {
  179105. ((PixelARGB*) dest)->setARGB (src[3], src[0], src[1], src[2]);
  179106. ((PixelARGB*) dest)->premultiply();
  179107. dest += destData.pixelStride;
  179108. src += 4;
  179109. }
  179110. }
  179111. else
  179112. {
  179113. for (int i = (int) width; --i >= 0;)
  179114. {
  179115. ((PixelRGB*) dest)->setARGB (0, src[0], src[1], src[2]);
  179116. dest += destData.pixelStride;
  179117. src += 4;
  179118. }
  179119. }
  179120. }
  179121. }
  179122. return image;
  179123. }
  179124. bool juce_writePNGImageToStream (const Image& image, OutputStream& out)
  179125. {
  179126. using namespace pnglibNamespace;
  179127. const int width = image.getWidth();
  179128. const int height = image.getHeight();
  179129. png_structp pngWriteStruct = png_create_write_struct (PNG_LIBPNG_VER_STRING, 0, 0, 0);
  179130. if (pngWriteStruct == 0)
  179131. return false;
  179132. png_infop pngInfoStruct = png_create_info_struct (pngWriteStruct);
  179133. if (pngInfoStruct == 0)
  179134. {
  179135. png_destroy_write_struct (&pngWriteStruct, (png_infopp) 0);
  179136. return false;
  179137. }
  179138. png_set_write_fn (pngWriteStruct, &out, PNGHelpers::writeDataCallback, 0);
  179139. png_set_IHDR (pngWriteStruct, pngInfoStruct, width, height, 8,
  179140. image.hasAlphaChannel() ? PNG_COLOR_TYPE_RGB_ALPHA
  179141. : PNG_COLOR_TYPE_RGB,
  179142. PNG_INTERLACE_NONE,
  179143. PNG_COMPRESSION_TYPE_BASE,
  179144. PNG_FILTER_TYPE_BASE);
  179145. HeapBlock <png_byte> rowData (width * 4);
  179146. png_color_8 sig_bit;
  179147. sig_bit.red = 8;
  179148. sig_bit.green = 8;
  179149. sig_bit.blue = 8;
  179150. sig_bit.alpha = 8;
  179151. png_set_sBIT (pngWriteStruct, pngInfoStruct, &sig_bit);
  179152. png_write_info (pngWriteStruct, pngInfoStruct);
  179153. png_set_shift (pngWriteStruct, &sig_bit);
  179154. png_set_packing (pngWriteStruct);
  179155. const Image::BitmapData srcData (image, 0, 0, width, height);
  179156. for (int y = 0; y < height; ++y)
  179157. {
  179158. uint8* dst = (uint8*) rowData;
  179159. const uint8* src = srcData.getLinePointer (y);
  179160. if (image.hasAlphaChannel())
  179161. {
  179162. for (int i = width; --i >= 0;)
  179163. {
  179164. PixelARGB p (*(const PixelARGB*) src);
  179165. p.unpremultiply();
  179166. *dst++ = p.getRed();
  179167. *dst++ = p.getGreen();
  179168. *dst++ = p.getBlue();
  179169. *dst++ = p.getAlpha();
  179170. src += srcData.pixelStride;
  179171. }
  179172. }
  179173. else
  179174. {
  179175. for (int i = width; --i >= 0;)
  179176. {
  179177. *dst++ = ((const PixelRGB*) src)->getRed();
  179178. *dst++ = ((const PixelRGB*) src)->getGreen();
  179179. *dst++ = ((const PixelRGB*) src)->getBlue();
  179180. src += srcData.pixelStride;
  179181. }
  179182. }
  179183. png_write_rows (pngWriteStruct, &rowData, 1);
  179184. }
  179185. png_write_end (pngWriteStruct, pngInfoStruct);
  179186. png_destroy_write_struct (&pngWriteStruct, &pngInfoStruct);
  179187. out.flush();
  179188. return true;
  179189. }
  179190. END_JUCE_NAMESPACE
  179191. /*** End of inlined file: juce_PNGLoader.cpp ***/
  179192. #endif
  179193. //==============================================================================
  179194. #if JUCE_BUILD_NATIVE
  179195. #if JUCE_WINDOWS
  179196. /*** Start of inlined file: juce_win32_NativeCode.cpp ***/
  179197. #if JUCE_WINDOWS
  179198. BEGIN_JUCE_NAMESPACE
  179199. #define JUCE_INCLUDED_FILE 1
  179200. // Now include the actual code files..
  179201. /*** Start of inlined file: juce_win32_DynamicLibraryLoader.cpp ***/
  179202. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  179203. // compiled on its own).
  179204. #if JUCE_INCLUDED_FILE
  179205. /*** Start of inlined file: juce_win32_DynamicLibraryLoader.h ***/
  179206. #ifndef __JUCE_WIN32_DYNAMICLIBRARYLOADER_JUCEHEADER__
  179207. #define __JUCE_WIN32_DYNAMICLIBRARYLOADER_JUCEHEADER__
  179208. #ifndef DOXYGEN
  179209. // use with DynamicLibraryLoader to simplify importing functions
  179210. //
  179211. // functionName: function to import
  179212. // localFunctionName: name you want to use to actually call it (must be different)
  179213. // returnType: the return type
  179214. // object: the DynamicLibraryLoader to use
  179215. // params: list of params (bracketed)
  179216. //
  179217. #define DynamicLibraryImport(functionName, localFunctionName, returnType, object, params) \
  179218. typedef returnType (WINAPI *type##localFunctionName) params; \
  179219. type##localFunctionName localFunctionName \
  179220. = (type##localFunctionName)object.findProcAddress (#functionName);
  179221. // loads and unloads a DLL automatically
  179222. class JUCE_API DynamicLibraryLoader
  179223. {
  179224. public:
  179225. DynamicLibraryLoader (const String& name);
  179226. ~DynamicLibraryLoader();
  179227. void* findProcAddress (const String& functionName);
  179228. private:
  179229. void* libHandle;
  179230. };
  179231. #endif
  179232. #endif // __JUCE_WIN32_DYNAMICLIBRARYLOADER_JUCEHEADER__
  179233. /*** End of inlined file: juce_win32_DynamicLibraryLoader.h ***/
  179234. DynamicLibraryLoader::DynamicLibraryLoader (const String& name)
  179235. {
  179236. libHandle = LoadLibrary (name);
  179237. }
  179238. DynamicLibraryLoader::~DynamicLibraryLoader()
  179239. {
  179240. FreeLibrary ((HMODULE) libHandle);
  179241. }
  179242. void* DynamicLibraryLoader::findProcAddress (const String& functionName)
  179243. {
  179244. return (void*) GetProcAddress ((HMODULE) libHandle, functionName.toCString());
  179245. }
  179246. #endif
  179247. /*** End of inlined file: juce_win32_DynamicLibraryLoader.cpp ***/
  179248. /*** Start of inlined file: juce_win32_SystemStats.cpp ***/
  179249. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  179250. // compiled on its own).
  179251. #if JUCE_INCLUDED_FILE
  179252. extern void juce_initialiseThreadEvents();
  179253. void Logger::outputDebugString (const String& text) throw()
  179254. {
  179255. OutputDebugString (text + T("\n"));
  179256. }
  179257. static int64 hiResTicksPerSecond;
  179258. static double hiResTicksScaleFactor;
  179259. #if JUCE_USE_INTRINSICS
  179260. // CPU info functions using intrinsics...
  179261. #pragma intrinsic (__cpuid)
  179262. #pragma intrinsic (__rdtsc)
  179263. const String SystemStats::getCpuVendor() throw()
  179264. {
  179265. int info [4];
  179266. __cpuid (info, 0);
  179267. char v [12];
  179268. memcpy (v, info + 1, 4);
  179269. memcpy (v + 4, info + 3, 4);
  179270. memcpy (v + 8, info + 2, 4);
  179271. return String (v, 12);
  179272. }
  179273. #else
  179274. // CPU info functions using old fashioned inline asm...
  179275. static void juce_getCpuVendor (char* const v)
  179276. {
  179277. int vendor[4];
  179278. zeromem (vendor, 16);
  179279. #ifdef JUCE_64BIT
  179280. #else
  179281. #ifndef __MINGW32__
  179282. __try
  179283. #endif
  179284. {
  179285. #if JUCE_GCC
  179286. unsigned int dummy = 0;
  179287. __asm__ ("cpuid" : "=a" (dummy), "=b" (vendor[0]), "=c" (vendor[2]),"=d" (vendor[1]) : "a" (0));
  179288. #else
  179289. __asm
  179290. {
  179291. mov eax, 0
  179292. cpuid
  179293. mov [vendor], ebx
  179294. mov [vendor + 4], edx
  179295. mov [vendor + 8], ecx
  179296. }
  179297. #endif
  179298. }
  179299. #ifndef __MINGW32__
  179300. __except (EXCEPTION_EXECUTE_HANDLER)
  179301. {
  179302. *v = 0;
  179303. }
  179304. #endif
  179305. #endif
  179306. memcpy (v, vendor, 16);
  179307. }
  179308. const String SystemStats::getCpuVendor() throw()
  179309. {
  179310. char v [16];
  179311. juce_getCpuVendor (v);
  179312. return String (v, 16);
  179313. }
  179314. #endif
  179315. struct CPUFlags
  179316. {
  179317. bool hasMMX : 1;
  179318. bool hasSSE : 1;
  179319. bool hasSSE2 : 1;
  179320. bool has3DNow : 1;
  179321. };
  179322. static CPUFlags cpuFlags;
  179323. bool SystemStats::hasMMX() throw()
  179324. {
  179325. return cpuFlags.hasMMX;
  179326. }
  179327. bool SystemStats::hasSSE() throw()
  179328. {
  179329. return cpuFlags.hasSSE;
  179330. }
  179331. bool SystemStats::hasSSE2() throw()
  179332. {
  179333. return cpuFlags.hasSSE2;
  179334. }
  179335. bool SystemStats::has3DNow() throw()
  179336. {
  179337. return cpuFlags.has3DNow;
  179338. }
  179339. void SystemStats::initialiseStats() throw()
  179340. {
  179341. juce_initialiseThreadEvents();
  179342. cpuFlags.hasMMX = IsProcessorFeaturePresent (PF_MMX_INSTRUCTIONS_AVAILABLE) != 0;
  179343. cpuFlags.hasSSE = IsProcessorFeaturePresent (PF_XMMI_INSTRUCTIONS_AVAILABLE) != 0;
  179344. cpuFlags.hasSSE2 = IsProcessorFeaturePresent (PF_XMMI64_INSTRUCTIONS_AVAILABLE) != 0;
  179345. #ifdef PF_AMD3D_INSTRUCTIONS_AVAILABLE
  179346. cpuFlags.has3DNow = IsProcessorFeaturePresent (PF_AMD3D_INSTRUCTIONS_AVAILABLE) != 0;
  179347. #else
  179348. cpuFlags.has3DNow = IsProcessorFeaturePresent (PF_3DNOW_INSTRUCTIONS_AVAILABLE) != 0;
  179349. #endif
  179350. LARGE_INTEGER f;
  179351. QueryPerformanceFrequency (&f);
  179352. hiResTicksPerSecond = f.QuadPart;
  179353. hiResTicksScaleFactor = 1000.0 / hiResTicksPerSecond;
  179354. String s (SystemStats::getJUCEVersion());
  179355. #ifdef JUCE_DEBUG
  179356. const MMRESULT res = timeBeginPeriod (1);
  179357. jassert (res == TIMERR_NOERROR);
  179358. #else
  179359. timeBeginPeriod (1);
  179360. #endif
  179361. #if defined (JUCE_DEBUG) && JUCE_MSVC && JUCE_CHECK_MEMORY_LEAKS
  179362. _CrtSetDbgFlag (_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);
  179363. #endif
  179364. }
  179365. SystemStats::OperatingSystemType SystemStats::getOperatingSystemType() throw()
  179366. {
  179367. OSVERSIONINFO info;
  179368. info.dwOSVersionInfoSize = sizeof (info);
  179369. GetVersionEx (&info);
  179370. if (info.dwPlatformId == VER_PLATFORM_WIN32_NT)
  179371. {
  179372. switch (info.dwMajorVersion)
  179373. {
  179374. case 5: return (info.dwMinorVersion == 0) ? Win2000 : WinXP;
  179375. case 6: return (info.dwMinorVersion == 0) ? WinVista : Windows7;
  179376. default: jassertfalse; break; // !! not a supported OS!
  179377. }
  179378. }
  179379. else if (info.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS)
  179380. {
  179381. jassert (info.dwMinorVersion != 0); // !! still running on Windows 95??
  179382. return Win98;
  179383. }
  179384. return UnknownOS;
  179385. }
  179386. const String SystemStats::getOperatingSystemName() throw()
  179387. {
  179388. const char* name = "Unknown OS";
  179389. switch (getOperatingSystemType())
  179390. {
  179391. case Windows7: name = "Windows 7"; break;
  179392. case WinVista: name = "Windows Vista"; break;
  179393. case WinXP: name = "Windows XP"; break;
  179394. case Win2000: name = "Windows 2000"; break;
  179395. case Win98: name = "Windows 98"; break;
  179396. default: jassertfalse; break; // !! new type of OS?
  179397. }
  179398. return name;
  179399. }
  179400. bool SystemStats::isOperatingSystem64Bit() throw()
  179401. {
  179402. #ifdef _WIN64
  179403. return true;
  179404. #else
  179405. typedef BOOL (WINAPI* LPFN_ISWOW64PROCESS) (HANDLE, PBOOL);
  179406. LPFN_ISWOW64PROCESS fnIsWow64Process = (LPFN_ISWOW64PROCESS) GetProcAddress (GetModuleHandle (L"kernel32"), "IsWow64Process");
  179407. BOOL isWow64 = FALSE;
  179408. return (fnIsWow64Process != 0)
  179409. && fnIsWow64Process (GetCurrentProcess(), &isWow64)
  179410. && (isWow64 != FALSE);
  179411. #endif
  179412. }
  179413. int SystemStats::getMemorySizeInMegabytes() throw()
  179414. {
  179415. MEMORYSTATUSEX mem;
  179416. mem.dwLength = sizeof (mem);
  179417. GlobalMemoryStatusEx (&mem);
  179418. return (int) (mem.ullTotalPhys / (1024 * 1024)) + 1;
  179419. }
  179420. int SystemStats::getNumCpus() throw()
  179421. {
  179422. SYSTEM_INFO systemInfo;
  179423. GetSystemInfo (&systemInfo);
  179424. return systemInfo.dwNumberOfProcessors;
  179425. }
  179426. uint32 juce_millisecondsSinceStartup() throw()
  179427. {
  179428. return (uint32) GetTickCount();
  179429. }
  179430. int64 Time::getHighResolutionTicks() throw()
  179431. {
  179432. LARGE_INTEGER ticks;
  179433. QueryPerformanceCounter (&ticks);
  179434. const int64 mainCounterAsHiResTicks = (GetTickCount() * hiResTicksPerSecond) / 1000;
  179435. const int64 newOffset = mainCounterAsHiResTicks - ticks.QuadPart;
  179436. // fix for a very obscure PCI hardware bug that can make the counter
  179437. // sometimes jump forwards by a few seconds..
  179438. static int64 hiResTicksOffset = 0;
  179439. const int64 offsetDrift = abs64 (newOffset - hiResTicksOffset);
  179440. if (offsetDrift > (hiResTicksPerSecond >> 1))
  179441. hiResTicksOffset = newOffset;
  179442. return ticks.QuadPart + hiResTicksOffset;
  179443. }
  179444. double Time::getMillisecondCounterHiRes() throw()
  179445. {
  179446. return getHighResolutionTicks() * hiResTicksScaleFactor;
  179447. }
  179448. int64 Time::getHighResolutionTicksPerSecond() throw()
  179449. {
  179450. return hiResTicksPerSecond;
  179451. }
  179452. int64 SystemStats::getClockCycleCounter() throw()
  179453. {
  179454. #if JUCE_USE_INTRINSICS
  179455. // MS intrinsics version...
  179456. return __rdtsc();
  179457. #elif JUCE_GCC
  179458. // GNU inline asm version...
  179459. unsigned int hi = 0, lo = 0;
  179460. __asm__ __volatile__ (
  179461. "xor %%eax, %%eax \n\
  179462. xor %%edx, %%edx \n\
  179463. rdtsc \n\
  179464. movl %%eax, %[lo] \n\
  179465. movl %%edx, %[hi]"
  179466. :
  179467. : [hi] "m" (hi),
  179468. [lo] "m" (lo)
  179469. : "cc", "eax", "ebx", "ecx", "edx", "memory");
  179470. return (int64) ((((uint64) hi) << 32) | lo);
  179471. #else
  179472. // MSVC inline asm version...
  179473. unsigned int hi = 0, lo = 0;
  179474. __asm
  179475. {
  179476. xor eax, eax
  179477. xor edx, edx
  179478. rdtsc
  179479. mov lo, eax
  179480. mov hi, edx
  179481. }
  179482. return (int64) ((((uint64) hi) << 32) | lo);
  179483. #endif
  179484. }
  179485. int SystemStats::getCpuSpeedInMegaherz() throw()
  179486. {
  179487. const int64 cycles = SystemStats::getClockCycleCounter();
  179488. const uint32 millis = Time::getMillisecondCounter();
  179489. int lastResult = 0;
  179490. for (;;)
  179491. {
  179492. int n = 1000000;
  179493. while (--n > 0) {}
  179494. const uint32 millisElapsed = Time::getMillisecondCounter() - millis;
  179495. const int64 cyclesNow = SystemStats::getClockCycleCounter();
  179496. if (millisElapsed > 80)
  179497. {
  179498. const int newResult = (int) (((cyclesNow - cycles) / millisElapsed) / 1000);
  179499. if (millisElapsed > 500 || (lastResult == newResult && newResult > 100))
  179500. return newResult;
  179501. lastResult = newResult;
  179502. }
  179503. }
  179504. }
  179505. bool Time::setSystemTimeToThisTime() const throw()
  179506. {
  179507. SYSTEMTIME st;
  179508. st.wDayOfWeek = 0;
  179509. st.wYear = (WORD) getYear();
  179510. st.wMonth = (WORD) (getMonth() + 1);
  179511. st.wDay = (WORD) getDayOfMonth();
  179512. st.wHour = (WORD) getHours();
  179513. st.wMinute = (WORD) getMinutes();
  179514. st.wSecond = (WORD) getSeconds();
  179515. st.wMilliseconds = (WORD) (millisSinceEpoch % 1000);
  179516. // do this twice because of daylight saving conversion problems - the
  179517. // first one sets it up, the second one kicks it in.
  179518. return SetLocalTime (&st) != 0
  179519. && SetLocalTime (&st) != 0;
  179520. }
  179521. int SystemStats::getPageSize() throw()
  179522. {
  179523. SYSTEM_INFO systemInfo;
  179524. GetSystemInfo (&systemInfo);
  179525. return systemInfo.dwPageSize;
  179526. }
  179527. const String SystemStats::getLogonName()
  179528. {
  179529. TCHAR text [256];
  179530. DWORD len = numElementsInArray (text) - 2;
  179531. zerostruct (text);
  179532. GetUserName (text, &len);
  179533. return String (text, len);
  179534. }
  179535. const String SystemStats::getFullUserName()
  179536. {
  179537. return getLogonName();
  179538. }
  179539. #endif
  179540. /*** End of inlined file: juce_win32_SystemStats.cpp ***/
  179541. /*** Start of inlined file: juce_win32_Threads.cpp ***/
  179542. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  179543. // compiled on its own).
  179544. #if JUCE_INCLUDED_FILE
  179545. #if ! JUCE_ONLY_BUILD_CORE_LIBRARY
  179546. extern HWND juce_messageWindowHandle;
  179547. #endif
  179548. #if ! JUCE_USE_INTRINSICS
  179549. // In newer compilers, the inline versions of these are used (in juce_Atomic.h), but in
  179550. // older ones we have to actually call the ops as win32 functions..
  179551. void Atomic::increment (int32& variable) { InterlockedIncrement (reinterpret_cast <volatile long*> (&variable)); }
  179552. int32 Atomic::incrementAndReturn (int32& variable) { return InterlockedIncrement (reinterpret_cast <volatile long*> (&variable)); }
  179553. void Atomic::decrement (int32& variable) { InterlockedDecrement (reinterpret_cast <volatile long*> (&variable)); }
  179554. int32 Atomic::decrementAndReturn (int32& variable) { return InterlockedDecrement (reinterpret_cast <volatile long*> (&variable)); }
  179555. int32 Atomic::compareAndExchange (int32& destination, int32 newValue, int32 oldValue)
  179556. { return InterlockedCompareExchange (reinterpret_cast <volatile long*> (&destination), newValue, oldValue); }
  179557. #endif
  179558. void* Atomic::swapPointers (void* volatile* value1, void* volatile value2) { return InterlockedExchangePointer (value1, value2); }
  179559. CriticalSection::CriticalSection() throw()
  179560. {
  179561. // (just to check the MS haven't changed this structure and broken things...)
  179562. #if _MSC_VER >= 1400
  179563. static_jassert (sizeof (CRITICAL_SECTION) <= sizeof (internal));
  179564. #else
  179565. static_jassert (sizeof (CRITICAL_SECTION) <= 24);
  179566. #endif
  179567. InitializeCriticalSection ((CRITICAL_SECTION*) internal);
  179568. }
  179569. CriticalSection::~CriticalSection() throw()
  179570. {
  179571. DeleteCriticalSection ((CRITICAL_SECTION*) internal);
  179572. }
  179573. void CriticalSection::enter() const throw()
  179574. {
  179575. EnterCriticalSection ((CRITICAL_SECTION*) internal);
  179576. }
  179577. bool CriticalSection::tryEnter() const throw()
  179578. {
  179579. return TryEnterCriticalSection ((CRITICAL_SECTION*) internal) != FALSE;
  179580. }
  179581. void CriticalSection::exit() const throw()
  179582. {
  179583. LeaveCriticalSection ((CRITICAL_SECTION*) internal);
  179584. }
  179585. WaitableEvent::WaitableEvent() throw()
  179586. : internal (CreateEvent (0, FALSE, FALSE, 0))
  179587. {
  179588. }
  179589. WaitableEvent::~WaitableEvent() throw()
  179590. {
  179591. CloseHandle (internal);
  179592. }
  179593. bool WaitableEvent::wait (const int timeOutMillisecs) const throw()
  179594. {
  179595. return WaitForSingleObject (internal, timeOutMillisecs) == WAIT_OBJECT_0;
  179596. }
  179597. void WaitableEvent::signal() const throw()
  179598. {
  179599. SetEvent (internal);
  179600. }
  179601. void WaitableEvent::reset() const throw()
  179602. {
  179603. ResetEvent (internal);
  179604. }
  179605. void JUCE_API juce_threadEntryPoint (void*);
  179606. static unsigned int __stdcall threadEntryProc (void* userData)
  179607. {
  179608. #if ! JUCE_ONLY_BUILD_CORE_LIBRARY
  179609. AttachThreadInput (GetWindowThreadProcessId (juce_messageWindowHandle, 0),
  179610. GetCurrentThreadId(), TRUE);
  179611. #endif
  179612. juce_threadEntryPoint (userData);
  179613. _endthreadex (0);
  179614. return 0;
  179615. }
  179616. void juce_CloseThreadHandle (void* handle)
  179617. {
  179618. CloseHandle ((HANDLE) handle);
  179619. }
  179620. void* juce_createThread (void* userData)
  179621. {
  179622. unsigned int threadId;
  179623. return (void*) _beginthreadex (0, 0,
  179624. &threadEntryProc,
  179625. userData,
  179626. 0, &threadId);
  179627. }
  179628. void juce_killThread (void* handle)
  179629. {
  179630. if (handle != 0)
  179631. {
  179632. #ifdef JUCE_DEBUG
  179633. OutputDebugString (_T("** Warning - Forced thread termination **\n"));
  179634. #endif
  179635. TerminateThread (handle, 0);
  179636. }
  179637. }
  179638. void juce_setCurrentThreadName (const String& name)
  179639. {
  179640. #if defined (JUCE_DEBUG) && JUCE_MSVC
  179641. struct
  179642. {
  179643. DWORD dwType;
  179644. LPCSTR szName;
  179645. DWORD dwThreadID;
  179646. DWORD dwFlags;
  179647. } info;
  179648. info.dwType = 0x1000;
  179649. info.szName = name.toCString();
  179650. info.dwThreadID = GetCurrentThreadId();
  179651. info.dwFlags = 0;
  179652. #define MS_VC_EXCEPTION 0x406d1388
  179653. __try
  179654. {
  179655. RaiseException (MS_VC_EXCEPTION, 0, sizeof (info) / sizeof (ULONG_PTR), (ULONG_PTR*) &info);
  179656. }
  179657. __except (EXCEPTION_CONTINUE_EXECUTION)
  179658. {}
  179659. #else
  179660. (void) name;
  179661. #endif
  179662. }
  179663. Thread::ThreadID Thread::getCurrentThreadId()
  179664. {
  179665. return (ThreadID) (pointer_sized_int) GetCurrentThreadId();
  179666. }
  179667. // priority 1 to 10 where 5=normal, 1=low
  179668. bool juce_setThreadPriority (void* threadHandle, int priority)
  179669. {
  179670. int pri = THREAD_PRIORITY_TIME_CRITICAL;
  179671. if (priority < 1)
  179672. pri = THREAD_PRIORITY_IDLE;
  179673. else if (priority < 2)
  179674. pri = THREAD_PRIORITY_LOWEST;
  179675. else if (priority < 5)
  179676. pri = THREAD_PRIORITY_BELOW_NORMAL;
  179677. else if (priority < 7)
  179678. pri = THREAD_PRIORITY_NORMAL;
  179679. else if (priority < 9)
  179680. pri = THREAD_PRIORITY_ABOVE_NORMAL;
  179681. else if (priority < 10)
  179682. pri = THREAD_PRIORITY_HIGHEST;
  179683. if (threadHandle == 0)
  179684. threadHandle = GetCurrentThread();
  179685. return SetThreadPriority (threadHandle, pri) != FALSE;
  179686. }
  179687. void Thread::setCurrentThreadAffinityMask (const uint32 affinityMask)
  179688. {
  179689. SetThreadAffinityMask (GetCurrentThread(), affinityMask);
  179690. }
  179691. static HANDLE sleepEvent = 0;
  179692. void juce_initialiseThreadEvents()
  179693. {
  179694. if (sleepEvent == 0)
  179695. #ifdef JUCE_DEBUG
  179696. sleepEvent = CreateEvent (0, 0, 0, _T("Juce Sleep Event"));
  179697. #else
  179698. sleepEvent = CreateEvent (0, 0, 0, 0);
  179699. #endif
  179700. }
  179701. void Thread::yield()
  179702. {
  179703. Sleep (0);
  179704. }
  179705. void JUCE_CALLTYPE Thread::sleep (const int millisecs)
  179706. {
  179707. if (millisecs >= 10)
  179708. {
  179709. Sleep (millisecs);
  179710. }
  179711. else
  179712. {
  179713. jassert (sleepEvent != 0);
  179714. // unlike Sleep() this is guaranteed to return to the current thread after
  179715. // the time expires, so we'll use this for short waits, which are more likely
  179716. // to need to be accurate
  179717. WaitForSingleObject (sleepEvent, millisecs);
  179718. }
  179719. }
  179720. static int lastProcessPriority = -1;
  179721. // called by WindowDriver because Windows does wierd things to process priority
  179722. // when you swap apps, and this forces an update when the app is brought to the front.
  179723. void juce_repeatLastProcessPriority()
  179724. {
  179725. if (lastProcessPriority >= 0) // (avoid changing this if it's not been explicitly set by the app..)
  179726. {
  179727. DWORD p;
  179728. switch (lastProcessPriority)
  179729. {
  179730. case Process::LowPriority:
  179731. p = IDLE_PRIORITY_CLASS;
  179732. break;
  179733. case Process::NormalPriority:
  179734. p = NORMAL_PRIORITY_CLASS;
  179735. break;
  179736. case Process::HighPriority:
  179737. p = HIGH_PRIORITY_CLASS;
  179738. break;
  179739. case Process::RealtimePriority:
  179740. p = REALTIME_PRIORITY_CLASS;
  179741. break;
  179742. default:
  179743. jassertfalse // bad priority value
  179744. return;
  179745. }
  179746. SetPriorityClass (GetCurrentProcess(), p);
  179747. }
  179748. }
  179749. void Process::setPriority (ProcessPriority prior)
  179750. {
  179751. if (lastProcessPriority != (int) prior)
  179752. {
  179753. lastProcessPriority = (int) prior;
  179754. juce_repeatLastProcessPriority();
  179755. }
  179756. }
  179757. bool JUCE_PUBLIC_FUNCTION juce_isRunningUnderDebugger()
  179758. {
  179759. return IsDebuggerPresent() != FALSE;
  179760. }
  179761. bool JUCE_CALLTYPE Process::isRunningUnderDebugger()
  179762. {
  179763. return juce_isRunningUnderDebugger();
  179764. }
  179765. void Process::raisePrivilege()
  179766. {
  179767. jassertfalse // xxx not implemented
  179768. }
  179769. void Process::lowerPrivilege()
  179770. {
  179771. jassertfalse // xxx not implemented
  179772. }
  179773. void Process::terminate()
  179774. {
  179775. #if defined (JUCE_DEBUG) && JUCE_MSVC && JUCE_CHECK_MEMORY_LEAKS
  179776. _CrtDumpMemoryLeaks();
  179777. #endif
  179778. // bullet in the head in case there's a problem shutting down..
  179779. ExitProcess (0);
  179780. }
  179781. void* PlatformUtilities::loadDynamicLibrary (const String& name)
  179782. {
  179783. void* result = 0;
  179784. JUCE_TRY
  179785. {
  179786. result = (void*) LoadLibrary (name);
  179787. }
  179788. JUCE_CATCH_ALL
  179789. return result;
  179790. }
  179791. void PlatformUtilities::freeDynamicLibrary (void* h)
  179792. {
  179793. JUCE_TRY
  179794. {
  179795. if (h != 0)
  179796. FreeLibrary ((HMODULE) h);
  179797. }
  179798. JUCE_CATCH_ALL
  179799. }
  179800. void* PlatformUtilities::getProcedureEntryPoint (void* h, const String& name)
  179801. {
  179802. return (h != 0) ? (void*) GetProcAddress ((HMODULE) h, name.toCString()) : 0;
  179803. }
  179804. InterProcessLock::InterProcessLock (const String& name_)
  179805. : internal (0),
  179806. name (name_),
  179807. reentrancyLevel (0)
  179808. {
  179809. }
  179810. InterProcessLock::~InterProcessLock()
  179811. {
  179812. exit();
  179813. }
  179814. bool InterProcessLock::enter (const int timeOutMillisecs)
  179815. {
  179816. if (reentrancyLevel++ == 0)
  179817. {
  179818. internal = CreateMutex (0, TRUE, "Global\\" + name);
  179819. if (internal != 0 && GetLastError() == ERROR_ALREADY_EXISTS)
  179820. {
  179821. if (timeOutMillisecs == 0
  179822. || WaitForSingleObject (internal, (timeOutMillisecs < 0) ? INFINITE : timeOutMillisecs)
  179823. == WAIT_TIMEOUT)
  179824. {
  179825. ReleaseMutex (internal);
  179826. CloseHandle (internal);
  179827. internal = 0;
  179828. }
  179829. }
  179830. }
  179831. return (internal != 0);
  179832. }
  179833. void InterProcessLock::exit()
  179834. {
  179835. if (--reentrancyLevel == 0 && internal != 0)
  179836. {
  179837. ReleaseMutex (internal);
  179838. CloseHandle (internal);
  179839. internal = 0;
  179840. }
  179841. }
  179842. #endif
  179843. /*** End of inlined file: juce_win32_Threads.cpp ***/
  179844. /*** Start of inlined file: juce_win32_Files.cpp ***/
  179845. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  179846. // compiled on its own).
  179847. #if JUCE_INCLUDED_FILE
  179848. #ifndef CSIDL_MYMUSIC
  179849. #define CSIDL_MYMUSIC 0x000d
  179850. #endif
  179851. #ifndef CSIDL_MYVIDEO
  179852. #define CSIDL_MYVIDEO 0x000e
  179853. #endif
  179854. const tchar File::separator = T('\\');
  179855. const tchar* File::separatorString = T("\\");
  179856. bool juce_fileExists (const String& fileName, const bool dontCountDirectories)
  179857. {
  179858. if (fileName.isEmpty())
  179859. return false;
  179860. const DWORD attr = GetFileAttributes (fileName);
  179861. return dontCountDirectories ? ((attr & FILE_ATTRIBUTE_DIRECTORY) == 0)
  179862. : (attr != 0xffffffff);
  179863. }
  179864. bool juce_isDirectory (const String& fileName)
  179865. {
  179866. const DWORD attr = GetFileAttributes (fileName);
  179867. return (attr != 0xffffffff)
  179868. && ((attr & FILE_ATTRIBUTE_DIRECTORY) != 0);
  179869. }
  179870. bool juce_canWriteToFile (const String& fileName)
  179871. {
  179872. const DWORD attr = GetFileAttributes (fileName);
  179873. return ((attr & FILE_ATTRIBUTE_READONLY) == 0);
  179874. }
  179875. bool juce_setFileReadOnly (const String& fileName, bool isReadOnly)
  179876. {
  179877. DWORD attr = GetFileAttributes (fileName);
  179878. if (attr == 0xffffffff)
  179879. return false;
  179880. if (isReadOnly != juce_canWriteToFile (fileName))
  179881. return true;
  179882. if (isReadOnly)
  179883. attr |= FILE_ATTRIBUTE_READONLY;
  179884. else
  179885. attr &= ~FILE_ATTRIBUTE_READONLY;
  179886. return SetFileAttributes (fileName, attr) != FALSE;
  179887. }
  179888. bool File::isHidden() const
  179889. {
  179890. return (GetFileAttributes (getFullPathName()) & FILE_ATTRIBUTE_HIDDEN) != 0;
  179891. }
  179892. bool juce_deleteFile (const String& fileName)
  179893. {
  179894. if (juce_isDirectory (fileName))
  179895. return RemoveDirectory (fileName) != 0;
  179896. return DeleteFile (fileName) != 0;
  179897. }
  179898. bool File::moveToTrash() const
  179899. {
  179900. if (! exists())
  179901. return true;
  179902. SHFILEOPSTRUCT fos;
  179903. zerostruct (fos);
  179904. // The string we pass in must be double null terminated..
  179905. String doubleNullTermPath (getFullPathName() + " ");
  179906. TCHAR* p = (TCHAR*) (const TCHAR*) doubleNullTermPath;
  179907. p [getFullPathName().length()] = 0;
  179908. fos.wFunc = FO_DELETE;
  179909. fos.hwnd = (HWND) 0;
  179910. fos.pFrom = p;
  179911. fos.pTo = NULL;
  179912. fos.fFlags = FOF_ALLOWUNDO | FOF_NOERRORUI | FOF_SILENT | FOF_NOCONFIRMATION
  179913. | FOF_NOCONFIRMMKDIR | FOF_RENAMEONCOLLISION;
  179914. return SHFileOperation (&fos) == 0;
  179915. }
  179916. bool juce_moveFile (const String& source, const String& dest)
  179917. {
  179918. return MoveFile (source, dest) != 0;
  179919. }
  179920. bool juce_copyFile (const String& source, const String& dest)
  179921. {
  179922. return CopyFile (source, dest, false) != 0;
  179923. }
  179924. void juce_createDirectory (const String& fileName)
  179925. {
  179926. if (! juce_fileExists (fileName, true))
  179927. {
  179928. CreateDirectory (fileName, 0);
  179929. }
  179930. }
  179931. // return 0 if not possible
  179932. void* juce_fileOpen (const String& fileName, bool forWriting)
  179933. {
  179934. HANDLE h;
  179935. if (forWriting)
  179936. {
  179937. h = CreateFile (fileName, GENERIC_WRITE, FILE_SHARE_READ, 0,
  179938. OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);
  179939. if (h != INVALID_HANDLE_VALUE)
  179940. SetFilePointer (h, 0, 0, FILE_END);
  179941. else
  179942. h = 0;
  179943. }
  179944. else
  179945. {
  179946. h = CreateFile (fileName, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, 0,
  179947. OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN, 0);
  179948. if (h == INVALID_HANDLE_VALUE)
  179949. h = 0;
  179950. }
  179951. return (void*) h;
  179952. }
  179953. void juce_fileClose (void* handle)
  179954. {
  179955. CloseHandle (handle);
  179956. }
  179957. int juce_fileRead (void* handle, void* buffer, int size)
  179958. {
  179959. DWORD num = 0;
  179960. ReadFile ((HANDLE) handle, buffer, size, &num, 0);
  179961. return num;
  179962. }
  179963. int juce_fileWrite (void* handle, const void* buffer, int size)
  179964. {
  179965. DWORD num;
  179966. WriteFile ((HANDLE) handle,
  179967. buffer, size,
  179968. &num, 0);
  179969. return num;
  179970. }
  179971. int64 juce_fileSetPosition (void* handle, int64 pos)
  179972. {
  179973. LARGE_INTEGER li;
  179974. li.QuadPart = pos;
  179975. li.LowPart = SetFilePointer ((HANDLE) handle,
  179976. li.LowPart,
  179977. &li.HighPart,
  179978. FILE_BEGIN); // (returns -1 if it fails)
  179979. return li.QuadPart;
  179980. }
  179981. int64 juce_fileGetPosition (void* handle)
  179982. {
  179983. LARGE_INTEGER li;
  179984. li.QuadPart = 0;
  179985. li.LowPart = SetFilePointer ((HANDLE) handle,
  179986. 0, &li.HighPart,
  179987. FILE_CURRENT); // (returns -1 if it fails)
  179988. return jmax ((int64) 0, li.QuadPart);
  179989. }
  179990. void juce_fileFlush (void* handle)
  179991. {
  179992. FlushFileBuffers ((HANDLE) handle);
  179993. }
  179994. int64 juce_getFileSize (const String& fileName)
  179995. {
  179996. WIN32_FILE_ATTRIBUTE_DATA attributes;
  179997. if (GetFileAttributesEx (fileName, GetFileExInfoStandard, &attributes))
  179998. {
  179999. return (((int64) attributes.nFileSizeHigh) << 32)
  180000. | attributes.nFileSizeLow;
  180001. }
  180002. return 0;
  180003. }
  180004. static int64 fileTimeToTime (const FILETIME* const ft)
  180005. {
  180006. // tell me if this fails!
  180007. static_jassert (sizeof (ULARGE_INTEGER) == sizeof (FILETIME));
  180008. #if JUCE_GCC
  180009. return (((const ULARGE_INTEGER*) ft)->QuadPart - 116444736000000000LL) / 10000;
  180010. #else
  180011. return (((const ULARGE_INTEGER*) ft)->QuadPart - 116444736000000000) / 10000;
  180012. #endif
  180013. }
  180014. static void timeToFileTime (const int64 time, FILETIME* const ft)
  180015. {
  180016. #if JUCE_GCC
  180017. ((ULARGE_INTEGER*) ft)->QuadPart = time * 10000 + 116444736000000000LL;
  180018. #else
  180019. ((ULARGE_INTEGER*) ft)->QuadPart = time * 10000 + 116444736000000000;
  180020. #endif
  180021. }
  180022. void juce_getFileTimes (const String& fileName,
  180023. int64& modificationTime,
  180024. int64& accessTime,
  180025. int64& creationTime)
  180026. {
  180027. WIN32_FILE_ATTRIBUTE_DATA attributes;
  180028. if (GetFileAttributesEx (fileName, GetFileExInfoStandard, &attributes))
  180029. {
  180030. modificationTime = fileTimeToTime (&attributes.ftLastWriteTime);
  180031. creationTime = fileTimeToTime (&attributes.ftCreationTime);
  180032. accessTime = fileTimeToTime (&attributes.ftLastAccessTime);
  180033. }
  180034. else
  180035. {
  180036. creationTime = accessTime = modificationTime = 0;
  180037. }
  180038. }
  180039. bool juce_setFileTimes (const String& fileName,
  180040. int64 modificationTime,
  180041. int64 accessTime,
  180042. int64 creationTime)
  180043. {
  180044. FILETIME m, a, c;
  180045. if (modificationTime > 0)
  180046. timeToFileTime (modificationTime, &m);
  180047. if (accessTime > 0)
  180048. timeToFileTime (accessTime, &a);
  180049. if (creationTime > 0)
  180050. timeToFileTime (creationTime, &c);
  180051. void* const h = juce_fileOpen (fileName, true);
  180052. bool ok = false;
  180053. if (h != 0)
  180054. {
  180055. ok = SetFileTime ((HANDLE) h,
  180056. (creationTime > 0) ? &c : 0,
  180057. (accessTime > 0) ? &a : 0,
  180058. (modificationTime > 0) ? &m : 0) != 0;
  180059. juce_fileClose (h);
  180060. }
  180061. return ok;
  180062. }
  180063. // return '\0' separated list of strings
  180064. const StringArray juce_getFileSystemRoots()
  180065. {
  180066. TCHAR buffer [2048];
  180067. buffer[0] = 0;
  180068. buffer[1] = 0;
  180069. GetLogicalDriveStrings (2048, buffer);
  180070. TCHAR* n = buffer;
  180071. StringArray roots;
  180072. while (*n != 0)
  180073. {
  180074. roots.add (String (n));
  180075. while (*n++ != 0)
  180076. {
  180077. }
  180078. }
  180079. roots.sort (true);
  180080. return roots;
  180081. }
  180082. const String juce_getVolumeLabel (const String& filenameOnVolume,
  180083. int& volumeSerialNumber)
  180084. {
  180085. TCHAR n [4];
  180086. n[0] = *(const TCHAR*) filenameOnVolume;
  180087. n[1] = L':';
  180088. n[2] = L'\\';
  180089. n[3] = 0;
  180090. TCHAR dest [64];
  180091. DWORD serialNum;
  180092. if (! GetVolumeInformation (n, dest, 64, (DWORD*) &serialNum, 0, 0, 0, 0))
  180093. {
  180094. dest[0] = 0;
  180095. serialNum = 0;
  180096. }
  180097. volumeSerialNumber = serialNum;
  180098. return String (dest);
  180099. }
  180100. static int64 getDiskSpaceInfo (String fn, const bool total)
  180101. {
  180102. if (fn[1] == T(':'))
  180103. fn = fn.substring (0, 2) + T("\\");
  180104. ULARGE_INTEGER spc, tot, totFree;
  180105. if (GetDiskFreeSpaceEx (fn, &spc, &tot, &totFree))
  180106. return (int64) (total ? tot.QuadPart
  180107. : spc.QuadPart);
  180108. return 0;
  180109. }
  180110. int64 File::getBytesFreeOnVolume() const
  180111. {
  180112. return getDiskSpaceInfo (getFullPathName(), false);
  180113. }
  180114. int64 File::getVolumeTotalSize() const
  180115. {
  180116. return getDiskSpaceInfo (getFullPathName(), true);
  180117. }
  180118. static unsigned int getWindowsDriveType (const String& fileName)
  180119. {
  180120. TCHAR n[4];
  180121. n[0] = *(const TCHAR*) fileName;
  180122. n[1] = L':';
  180123. n[2] = L'\\';
  180124. n[3] = 0;
  180125. return GetDriveType (n);
  180126. }
  180127. bool File::isOnCDRomDrive() const
  180128. {
  180129. return getWindowsDriveType (getFullPathName()) == DRIVE_CDROM;
  180130. }
  180131. bool File::isOnHardDisk() const
  180132. {
  180133. if (fullPath.isEmpty())
  180134. return false;
  180135. const unsigned int n = getWindowsDriveType (getFullPathName());
  180136. if (fullPath.toLowerCase()[0] <= 'b'
  180137. && fullPath[1] == T(':'))
  180138. {
  180139. return n != DRIVE_REMOVABLE;
  180140. }
  180141. else
  180142. {
  180143. return n != DRIVE_CDROM && n != DRIVE_REMOTE;
  180144. }
  180145. }
  180146. bool File::isOnRemovableDrive() const
  180147. {
  180148. if (fullPath.isEmpty())
  180149. return false;
  180150. const unsigned int n = getWindowsDriveType (getFullPathName());
  180151. return n == DRIVE_CDROM
  180152. || n == DRIVE_REMOTE
  180153. || n == DRIVE_REMOVABLE
  180154. || n == DRIVE_RAMDISK;
  180155. }
  180156. static const File juce_getSpecialFolderPath (int type)
  180157. {
  180158. WCHAR path [MAX_PATH + 256];
  180159. if (SHGetSpecialFolderPath (0, path, type, 0))
  180160. return File (String (path));
  180161. return File::nonexistent;
  180162. }
  180163. const File JUCE_CALLTYPE File::getSpecialLocation (const SpecialLocationType type)
  180164. {
  180165. int csidlType = 0;
  180166. switch (type)
  180167. {
  180168. case userHomeDirectory:
  180169. csidlType = CSIDL_PROFILE;
  180170. break;
  180171. case userDocumentsDirectory:
  180172. csidlType = CSIDL_PERSONAL;
  180173. break;
  180174. case userDesktopDirectory:
  180175. csidlType = CSIDL_DESKTOP;
  180176. break;
  180177. case userApplicationDataDirectory:
  180178. csidlType = CSIDL_APPDATA;
  180179. break;
  180180. case commonApplicationDataDirectory:
  180181. csidlType = CSIDL_COMMON_APPDATA;
  180182. break;
  180183. case globalApplicationsDirectory:
  180184. csidlType = CSIDL_PROGRAM_FILES;
  180185. break;
  180186. case userMusicDirectory:
  180187. csidlType = CSIDL_MYMUSIC;
  180188. break;
  180189. case userMoviesDirectory:
  180190. csidlType = CSIDL_MYVIDEO;
  180191. break;
  180192. case tempDirectory:
  180193. {
  180194. WCHAR dest [2048];
  180195. dest[0] = 0;
  180196. GetTempPath (2048, dest);
  180197. return File (String (dest));
  180198. }
  180199. case invokedExecutableFile:
  180200. case currentExecutableFile:
  180201. case currentApplicationFile:
  180202. {
  180203. HINSTANCE moduleHandle = (HINSTANCE) PlatformUtilities::getCurrentModuleInstanceHandle();
  180204. WCHAR dest [MAX_PATH + 256];
  180205. dest[0] = 0;
  180206. GetModuleFileName (moduleHandle, dest, numElementsInArray (dest));
  180207. return File (String (dest));
  180208. }
  180209. break;
  180210. default:
  180211. jassertfalse // unknown type?
  180212. return File::nonexistent;
  180213. }
  180214. return juce_getSpecialFolderPath (csidlType);
  180215. }
  180216. const File File::getCurrentWorkingDirectory()
  180217. {
  180218. WCHAR dest [MAX_PATH + 256];
  180219. dest[0] = 0;
  180220. GetCurrentDirectory (numElementsInArray (dest), dest);
  180221. return File (String (dest));
  180222. }
  180223. bool File::setAsCurrentWorkingDirectory() const
  180224. {
  180225. return SetCurrentDirectory (getFullPathName()) != FALSE;
  180226. }
  180227. const String File::getVersion() const
  180228. {
  180229. String result;
  180230. DWORD handle = 0;
  180231. DWORD bufferSize = GetFileVersionInfoSize (getFullPathName(), &handle);
  180232. HeapBlock <char> buffer;
  180233. buffer.calloc (bufferSize);
  180234. if (GetFileVersionInfo (getFullPathName(), 0, bufferSize, buffer))
  180235. {
  180236. VS_FIXEDFILEINFO* vffi;
  180237. UINT len = 0;
  180238. if (VerQueryValue (buffer, (LPTSTR) _T("\\"), (LPVOID*) &vffi, &len))
  180239. {
  180240. result << (int) HIWORD (vffi->dwFileVersionMS) << "."
  180241. << (int) LOWORD (vffi->dwFileVersionMS) << "."
  180242. << (int) HIWORD (vffi->dwFileVersionLS) << "."
  180243. << (int) LOWORD (vffi->dwFileVersionLS);
  180244. }
  180245. }
  180246. return result;
  180247. }
  180248. const File File::getLinkedTarget() const
  180249. {
  180250. File result (*this);
  180251. String p (getFullPathName());
  180252. if (! exists())
  180253. p += T(".lnk");
  180254. else if (getFileExtension() != T(".lnk"))
  180255. return result;
  180256. ComSmartPtr <IShellLink> shellLink;
  180257. if (SUCCEEDED (shellLink.CoCreateInstance (CLSID_ShellLink, CLSCTX_INPROC_SERVER)))
  180258. {
  180259. ComSmartPtr <IPersistFile> persistFile;
  180260. if (SUCCEEDED (shellLink->QueryInterface (IID_IPersistFile, (LPVOID*) &persistFile)))
  180261. {
  180262. if (SUCCEEDED (persistFile->Load ((const WCHAR*) p, STGM_READ))
  180263. && SUCCEEDED (shellLink->Resolve (0, SLR_ANY_MATCH | SLR_NO_UI)))
  180264. {
  180265. WIN32_FIND_DATA winFindData;
  180266. WCHAR resolvedPath [MAX_PATH];
  180267. if (SUCCEEDED (shellLink->GetPath (resolvedPath, MAX_PATH, &winFindData, SLGP_UNCPRIORITY)))
  180268. result = File (resolvedPath);
  180269. }
  180270. }
  180271. }
  180272. return result;
  180273. }
  180274. template <class FindDataType>
  180275. static void getFindFileInfo (FindDataType& findData,
  180276. String& filename, bool* const isDir, bool* const isHidden,
  180277. int64* const fileSize, Time* const modTime, Time* const creationTime,
  180278. bool* const isReadOnly)
  180279. {
  180280. filename = findData.cFileName;
  180281. if (isDir != 0)
  180282. *isDir = ((findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0);
  180283. if (isHidden != 0)
  180284. *isHidden = ((findData.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN) != 0);
  180285. if (fileSize != 0)
  180286. *fileSize = findData.nFileSizeLow + (((int64) findData.nFileSizeHigh) << 32);
  180287. if (modTime != 0)
  180288. *modTime = fileTimeToTime (&findData.ftLastWriteTime);
  180289. if (creationTime != 0)
  180290. *creationTime = fileTimeToTime (&findData.ftCreationTime);
  180291. if (isReadOnly != 0)
  180292. *isReadOnly = ((findData.dwFileAttributes & FILE_ATTRIBUTE_READONLY) != 0);
  180293. }
  180294. void* juce_findFileStart (const String& directory, const String& wildCard, String& firstResult,
  180295. bool* isDir, bool* isHidden, int64* fileSize,
  180296. Time* modTime, Time* creationTime, bool* isReadOnly)
  180297. {
  180298. String wc (directory);
  180299. if (! wc.endsWithChar (File::separator))
  180300. wc += File::separator;
  180301. wc += wildCard;
  180302. WIN32_FIND_DATA findData;
  180303. HANDLE h = FindFirstFile (wc, &findData);
  180304. if (h != INVALID_HANDLE_VALUE)
  180305. {
  180306. getFindFileInfo (findData, firstResult, isDir, isHidden, fileSize,
  180307. modTime, creationTime, isReadOnly);
  180308. return h;
  180309. }
  180310. firstResult = String::empty;
  180311. return 0;
  180312. }
  180313. bool juce_findFileNext (void* handle, String& resultFile,
  180314. bool* isDir, bool* isHidden, int64* fileSize,
  180315. Time* modTime, Time* creationTime, bool* isReadOnly)
  180316. {
  180317. WIN32_FIND_DATA findData;
  180318. if (handle != 0 && FindNextFile ((HANDLE) handle, &findData) != 0)
  180319. {
  180320. getFindFileInfo (findData, resultFile, isDir, isHidden, fileSize,
  180321. modTime, creationTime, isReadOnly);
  180322. return true;
  180323. }
  180324. resultFile = String::empty;
  180325. return false;
  180326. }
  180327. void juce_findFileClose (void* handle)
  180328. {
  180329. FindClose (handle);
  180330. }
  180331. bool juce_launchFile (const String& fileName,
  180332. const String& parameters)
  180333. {
  180334. HINSTANCE hInstance = 0;
  180335. JUCE_TRY
  180336. {
  180337. hInstance = ShellExecute (0, 0, fileName, parameters, 0, SW_SHOWDEFAULT);
  180338. }
  180339. JUCE_CATCH_ALL
  180340. return hInstance > (HINSTANCE) 32;
  180341. }
  180342. void File::revealToUser() const
  180343. {
  180344. if (isDirectory())
  180345. startAsProcess();
  180346. else if (getParentDirectory().exists())
  180347. getParentDirectory().startAsProcess();
  180348. }
  180349. class NamedPipeInternal
  180350. {
  180351. public:
  180352. NamedPipeInternal (const String& file, const bool isPipe_)
  180353. : pipeH (0),
  180354. cancelEvent (0),
  180355. connected (false),
  180356. isPipe (isPipe_)
  180357. {
  180358. cancelEvent = CreateEvent (0, FALSE, FALSE, 0);
  180359. pipeH = isPipe ? CreateNamedPipe (file, PIPE_ACCESS_DUPLEX | FILE_FLAG_OVERLAPPED, 0,
  180360. PIPE_UNLIMITED_INSTANCES, 4096, 4096, 0, 0)
  180361. : CreateFile (file, GENERIC_READ | GENERIC_WRITE, 0, 0,
  180362. OPEN_EXISTING, FILE_FLAG_OVERLAPPED, 0);
  180363. }
  180364. ~NamedPipeInternal()
  180365. {
  180366. disconnectPipe();
  180367. if (pipeH != 0)
  180368. CloseHandle (pipeH);
  180369. CloseHandle (cancelEvent);
  180370. }
  180371. bool connect (const int timeOutMs)
  180372. {
  180373. if (! isPipe)
  180374. return true;
  180375. if (! connected)
  180376. {
  180377. OVERLAPPED over;
  180378. zerostruct (over);
  180379. over.hEvent = CreateEvent (0, TRUE, FALSE, 0);
  180380. if (ConnectNamedPipe (pipeH, &over))
  180381. {
  180382. connected = false; // yes, you read that right. In overlapped mode it should always return 0.
  180383. }
  180384. else
  180385. {
  180386. const int err = GetLastError();
  180387. if (err == ERROR_IO_PENDING || err == ERROR_PIPE_LISTENING)
  180388. {
  180389. HANDLE handles[] = { over.hEvent, cancelEvent };
  180390. if (WaitForMultipleObjects (2, handles, FALSE,
  180391. timeOutMs >= 0 ? timeOutMs : INFINITE) == WAIT_OBJECT_0)
  180392. connected = true;
  180393. }
  180394. else if (err == ERROR_PIPE_CONNECTED)
  180395. {
  180396. connected = true;
  180397. }
  180398. }
  180399. CloseHandle (over.hEvent);
  180400. }
  180401. return connected;
  180402. }
  180403. void disconnectPipe()
  180404. {
  180405. if (connected)
  180406. {
  180407. DisconnectNamedPipe (pipeH);
  180408. connected = false;
  180409. }
  180410. }
  180411. HANDLE pipeH;
  180412. HANDLE cancelEvent;
  180413. bool connected, isPipe;
  180414. };
  180415. void NamedPipe::close()
  180416. {
  180417. cancelPendingReads();
  180418. const ScopedLock sl (lock);
  180419. delete static_cast<NamedPipeInternal*> (internal);
  180420. internal = 0;
  180421. }
  180422. bool NamedPipe::openInternal (const String& pipeName, const bool createPipe)
  180423. {
  180424. close();
  180425. ScopedPointer<NamedPipeInternal> intern (new NamedPipeInternal ("\\\\.\\pipe\\" + pipeName, createPipe));
  180426. if (intern->pipeH != INVALID_HANDLE_VALUE)
  180427. {
  180428. internal = intern.release();
  180429. return true;
  180430. }
  180431. return false;
  180432. }
  180433. int NamedPipe::read (void* destBuffer, int maxBytesToRead, int timeOutMilliseconds)
  180434. {
  180435. const ScopedLock sl (lock);
  180436. int bytesRead = -1;
  180437. bool waitAgain = true;
  180438. while (waitAgain && internal != 0)
  180439. {
  180440. NamedPipeInternal* const intern = static_cast<NamedPipeInternal*> (internal);
  180441. waitAgain = false;
  180442. if (! intern->connect (timeOutMilliseconds))
  180443. break;
  180444. if (maxBytesToRead <= 0)
  180445. return 0;
  180446. OVERLAPPED over;
  180447. zerostruct (over);
  180448. over.hEvent = CreateEvent (0, TRUE, FALSE, 0);
  180449. unsigned long numRead;
  180450. if (ReadFile (intern->pipeH, destBuffer, maxBytesToRead, &numRead, &over))
  180451. {
  180452. bytesRead = (int) numRead;
  180453. }
  180454. else if (GetLastError() == ERROR_IO_PENDING)
  180455. {
  180456. HANDLE handles[] = { over.hEvent, intern->cancelEvent };
  180457. DWORD waitResult = WaitForMultipleObjects (2, handles, FALSE,
  180458. timeOutMilliseconds >= 0 ? timeOutMilliseconds
  180459. : INFINITE);
  180460. if (waitResult != WAIT_OBJECT_0)
  180461. {
  180462. // if the operation timed out, let's cancel it...
  180463. CancelIo (intern->pipeH);
  180464. WaitForSingleObject (over.hEvent, INFINITE); // makes sure cancel is complete
  180465. }
  180466. if (GetOverlappedResult (intern->pipeH, &over, &numRead, FALSE))
  180467. {
  180468. bytesRead = (int) numRead;
  180469. }
  180470. else if (GetLastError() == ERROR_BROKEN_PIPE && intern->isPipe)
  180471. {
  180472. intern->disconnectPipe();
  180473. waitAgain = true;
  180474. }
  180475. }
  180476. else
  180477. {
  180478. waitAgain = internal != 0;
  180479. Sleep (5);
  180480. }
  180481. CloseHandle (over.hEvent);
  180482. }
  180483. return bytesRead;
  180484. }
  180485. int NamedPipe::write (const void* sourceBuffer, int numBytesToWrite, int timeOutMilliseconds)
  180486. {
  180487. int bytesWritten = -1;
  180488. NamedPipeInternal* const intern = static_cast<NamedPipeInternal*> (internal);
  180489. if (intern != 0 && intern->connect (timeOutMilliseconds))
  180490. {
  180491. if (numBytesToWrite <= 0)
  180492. return 0;
  180493. OVERLAPPED over;
  180494. zerostruct (over);
  180495. over.hEvent = CreateEvent (0, TRUE, FALSE, 0);
  180496. unsigned long numWritten;
  180497. if (WriteFile (intern->pipeH, sourceBuffer, numBytesToWrite, &numWritten, &over))
  180498. {
  180499. bytesWritten = (int) numWritten;
  180500. }
  180501. else if (GetLastError() == ERROR_IO_PENDING)
  180502. {
  180503. HANDLE handles[] = { over.hEvent, intern->cancelEvent };
  180504. DWORD waitResult;
  180505. waitResult = WaitForMultipleObjects (2, handles, FALSE,
  180506. timeOutMilliseconds >= 0 ? timeOutMilliseconds
  180507. : INFINITE);
  180508. if (waitResult != WAIT_OBJECT_0)
  180509. {
  180510. CancelIo (intern->pipeH);
  180511. WaitForSingleObject (over.hEvent, INFINITE);
  180512. }
  180513. if (GetOverlappedResult (intern->pipeH, &over, &numWritten, FALSE))
  180514. {
  180515. bytesWritten = (int) numWritten;
  180516. }
  180517. else if (GetLastError() == ERROR_BROKEN_PIPE && intern->isPipe)
  180518. {
  180519. intern->disconnectPipe();
  180520. }
  180521. }
  180522. CloseHandle (over.hEvent);
  180523. }
  180524. return bytesWritten;
  180525. }
  180526. void NamedPipe::cancelPendingReads()
  180527. {
  180528. if (internal != 0)
  180529. SetEvent (static_cast<NamedPipeInternal*> (internal)->cancelEvent);
  180530. }
  180531. #endif
  180532. /*** End of inlined file: juce_win32_Files.cpp ***/
  180533. /*** Start of inlined file: juce_win32_Network.cpp ***/
  180534. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  180535. // compiled on its own).
  180536. #if JUCE_INCLUDED_FILE
  180537. #ifndef INTERNET_FLAG_NEED_FILE
  180538. #define INTERNET_FLAG_NEED_FILE 0x00000010
  180539. #endif
  180540. #ifndef INTERNET_OPTION_DISABLE_AUTODIAL
  180541. #define INTERNET_OPTION_DISABLE_AUTODIAL 70
  180542. #endif
  180543. bool juce_isOnLine()
  180544. {
  180545. DWORD connectionType;
  180546. return InternetGetConnectedState (&connectionType, 0) != 0
  180547. || (connectionType & (INTERNET_CONNECTION_LAN | INTERNET_CONNECTION_PROXY)) != 0;
  180548. }
  180549. struct ConnectionAndRequestStruct
  180550. {
  180551. HINTERNET connection, request;
  180552. };
  180553. static HINTERNET sessionHandle = 0;
  180554. #ifndef WORKAROUND_TIMEOUT_BUG
  180555. //#define WORKAROUND_TIMEOUT_BUG 1
  180556. #endif
  180557. #if WORKAROUND_TIMEOUT_BUG
  180558. // Required because of a Microsoft bug in setting a timeout
  180559. class InternetConnectThread : public Thread
  180560. {
  180561. public:
  180562. InternetConnectThread (URL_COMPONENTS& uc_, HINTERNET& connection_, const bool isFtp_)
  180563. : Thread ("Internet"), uc (uc_), connection (connection_), isFtp (isFtp_)
  180564. {
  180565. startThread();
  180566. }
  180567. ~InternetConnectThread()
  180568. {
  180569. stopThread (60000);
  180570. }
  180571. void run()
  180572. {
  180573. connection = InternetConnect (sessionHandle, uc.lpszHostName,
  180574. uc.nPort, _T(""), _T(""),
  180575. isFtp ? INTERNET_SERVICE_FTP
  180576. : INTERNET_SERVICE_HTTP,
  180577. 0, 0);
  180578. notify();
  180579. }
  180580. juce_UseDebuggingNewOperator
  180581. private:
  180582. URL_COMPONENTS& uc;
  180583. HINTERNET& connection;
  180584. const bool isFtp;
  180585. InternetConnectThread (const InternetConnectThread&);
  180586. InternetConnectThread& operator= (const InternetConnectThread&);
  180587. };
  180588. #endif
  180589. void* juce_openInternetFile (const String& url,
  180590. const String& headers,
  180591. const MemoryBlock& postData,
  180592. const bool isPost,
  180593. URL::OpenStreamProgressCallback* callback,
  180594. void* callbackContext,
  180595. int timeOutMs)
  180596. {
  180597. if (sessionHandle == 0)
  180598. sessionHandle = InternetOpen (_T("juce"),
  180599. INTERNET_OPEN_TYPE_PRECONFIG,
  180600. 0, 0, 0);
  180601. if (sessionHandle != 0)
  180602. {
  180603. // break up the url..
  180604. TCHAR file[1024], server[1024];
  180605. URL_COMPONENTS uc;
  180606. zerostruct (uc);
  180607. uc.dwStructSize = sizeof (uc);
  180608. uc.dwUrlPathLength = sizeof (file);
  180609. uc.dwHostNameLength = sizeof (server);
  180610. uc.lpszUrlPath = file;
  180611. uc.lpszHostName = server;
  180612. if (InternetCrackUrl (url, 0, 0, &uc))
  180613. {
  180614. int disable = 1;
  180615. InternetSetOption (sessionHandle, INTERNET_OPTION_DISABLE_AUTODIAL, &disable, sizeof (disable));
  180616. if (timeOutMs == 0)
  180617. timeOutMs = 30000;
  180618. else if (timeOutMs < 0)
  180619. timeOutMs = -1;
  180620. InternetSetOption (sessionHandle, INTERNET_OPTION_CONNECT_TIMEOUT, &timeOutMs, sizeof (timeOutMs));
  180621. const bool isFtp = url.startsWithIgnoreCase (T("ftp:"));
  180622. #if WORKAROUND_TIMEOUT_BUG
  180623. HINTERNET connection = 0;
  180624. {
  180625. InternetConnectThread connectThread (uc, connection, isFtp);
  180626. connectThread.wait (timeOutMs);
  180627. if (connection == 0)
  180628. {
  180629. InternetCloseHandle (sessionHandle);
  180630. sessionHandle = 0;
  180631. }
  180632. }
  180633. #else
  180634. HINTERNET connection = InternetConnect (sessionHandle,
  180635. uc.lpszHostName,
  180636. uc.nPort,
  180637. _T(""), _T(""),
  180638. isFtp ? INTERNET_SERVICE_FTP
  180639. : INTERNET_SERVICE_HTTP,
  180640. 0, 0);
  180641. #endif
  180642. if (connection != 0)
  180643. {
  180644. if (isFtp)
  180645. {
  180646. HINTERNET request = FtpOpenFile (connection,
  180647. uc.lpszUrlPath,
  180648. GENERIC_READ,
  180649. FTP_TRANSFER_TYPE_BINARY | INTERNET_FLAG_NEED_FILE,
  180650. 0);
  180651. ConnectionAndRequestStruct* const result = new ConnectionAndRequestStruct();
  180652. result->connection = connection;
  180653. result->request = request;
  180654. return result;
  180655. }
  180656. else
  180657. {
  180658. const TCHAR* mimeTypes[] = { _T("*/*"), 0 };
  180659. DWORD flags = INTERNET_FLAG_RELOAD | INTERNET_FLAG_NO_CACHE_WRITE;
  180660. if (url.startsWithIgnoreCase (T("https:")))
  180661. flags |= INTERNET_FLAG_SECURE; // (this flag only seems necessary if the OS is running IE6 -
  180662. // IE7 seems to automatically work out when it's https)
  180663. HINTERNET request = HttpOpenRequest (connection,
  180664. isPost ? _T("POST")
  180665. : _T("GET"),
  180666. uc.lpszUrlPath,
  180667. 0, 0, mimeTypes, flags, 0);
  180668. if (request != 0)
  180669. {
  180670. INTERNET_BUFFERS buffers;
  180671. zerostruct (buffers);
  180672. buffers.dwStructSize = sizeof (INTERNET_BUFFERS);
  180673. buffers.lpcszHeader = (LPCTSTR) headers;
  180674. buffers.dwHeadersLength = headers.length();
  180675. buffers.dwBufferTotal = (DWORD) postData.getSize();
  180676. ConnectionAndRequestStruct* result = 0;
  180677. if (HttpSendRequestEx (request, &buffers, 0, HSR_INITIATE, 0))
  180678. {
  180679. int bytesSent = 0;
  180680. for (;;)
  180681. {
  180682. const int bytesToDo = jmin (1024, (int) postData.getSize() - bytesSent);
  180683. DWORD bytesDone = 0;
  180684. if (bytesToDo > 0
  180685. && ! InternetWriteFile (request,
  180686. ((const char*) postData.getData()) + bytesSent,
  180687. bytesToDo, &bytesDone))
  180688. {
  180689. break;
  180690. }
  180691. if (bytesToDo == 0 || (int) bytesDone < bytesToDo)
  180692. {
  180693. result = new ConnectionAndRequestStruct();
  180694. result->connection = connection;
  180695. result->request = request;
  180696. HttpEndRequest (request, 0, 0, 0);
  180697. return result;
  180698. }
  180699. bytesSent += bytesDone;
  180700. if (callback != 0 && ! callback (callbackContext, bytesSent, postData.getSize()))
  180701. break;
  180702. }
  180703. }
  180704. InternetCloseHandle (request);
  180705. }
  180706. InternetCloseHandle (connection);
  180707. }
  180708. }
  180709. }
  180710. }
  180711. return 0;
  180712. }
  180713. int juce_readFromInternetFile (void* handle, void* buffer, int bytesToRead)
  180714. {
  180715. DWORD bytesRead = 0;
  180716. const ConnectionAndRequestStruct* const crs = (const ConnectionAndRequestStruct*) handle;
  180717. if (crs != 0)
  180718. InternetReadFile (crs->request,
  180719. buffer, bytesToRead,
  180720. &bytesRead);
  180721. return bytesRead;
  180722. }
  180723. int juce_seekInInternetFile (void* handle, int newPosition)
  180724. {
  180725. if (handle != 0)
  180726. {
  180727. const ConnectionAndRequestStruct* const crs = (const ConnectionAndRequestStruct*) handle;
  180728. return InternetSetFilePointer (crs->request,
  180729. newPosition, 0,
  180730. FILE_BEGIN, 0);
  180731. }
  180732. else
  180733. {
  180734. return -1;
  180735. }
  180736. }
  180737. int64 juce_getInternetFileContentLength (void* handle)
  180738. {
  180739. const ConnectionAndRequestStruct* const crs = (const ConnectionAndRequestStruct*) handle;
  180740. if (crs != 0)
  180741. {
  180742. DWORD index = 0;
  180743. DWORD result = 0;
  180744. DWORD size = sizeof (result);
  180745. if (HttpQueryInfo (crs->request,
  180746. HTTP_QUERY_CONTENT_LENGTH | HTTP_QUERY_FLAG_NUMBER,
  180747. &result,
  180748. &size,
  180749. &index))
  180750. {
  180751. return (int64) result;
  180752. }
  180753. }
  180754. return -1;
  180755. }
  180756. void juce_closeInternetFile (void* handle)
  180757. {
  180758. if (handle != 0)
  180759. {
  180760. ConnectionAndRequestStruct* const crs = (ConnectionAndRequestStruct*) handle;
  180761. InternetCloseHandle (crs->request);
  180762. InternetCloseHandle (crs->connection);
  180763. delete crs;
  180764. }
  180765. }
  180766. static int getMACAddressViaGetAdaptersInfo (int64* addresses, int maxNum, const bool littleEndian) throw()
  180767. {
  180768. int numFound = 0;
  180769. DynamicLibraryLoader dll ("iphlpapi.dll");
  180770. DynamicLibraryImport (GetAdaptersInfo, getAdaptersInfo, DWORD, dll, (PIP_ADAPTER_INFO, PULONG))
  180771. if (getAdaptersInfo != 0)
  180772. {
  180773. ULONG len = sizeof (IP_ADAPTER_INFO);
  180774. MemoryBlock mb;
  180775. PIP_ADAPTER_INFO adapterInfo = (PIP_ADAPTER_INFO) mb.getData();
  180776. if (getAdaptersInfo (adapterInfo, &len) == ERROR_BUFFER_OVERFLOW)
  180777. {
  180778. mb.setSize (len);
  180779. adapterInfo = (PIP_ADAPTER_INFO) mb.getData();
  180780. }
  180781. if (getAdaptersInfo (adapterInfo, &len) == NO_ERROR)
  180782. {
  180783. PIP_ADAPTER_INFO adapter = adapterInfo;
  180784. while (adapter != 0)
  180785. {
  180786. int64 mac = 0;
  180787. for (unsigned int i = 0; i < adapter->AddressLength; ++i)
  180788. mac = (mac << 8) | adapter->Address[i];
  180789. if (littleEndian)
  180790. mac = (int64) ByteOrder::swap ((uint64) mac);
  180791. if (numFound < maxNum && mac != 0)
  180792. addresses [numFound++] = mac;
  180793. adapter = adapter->Next;
  180794. }
  180795. }
  180796. }
  180797. return numFound;
  180798. }
  180799. struct ASTAT
  180800. {
  180801. ADAPTER_STATUS adapt;
  180802. NAME_BUFFER NameBuff [30];
  180803. };
  180804. static int getMACAddressesViaNetBios (int64* addresses, int maxNum, const bool littleEndian) throw()
  180805. {
  180806. int numFound = 0;
  180807. DynamicLibraryLoader dll ("netapi32.dll");
  180808. DynamicLibraryImport (Netbios, NetbiosCall, UCHAR, dll, (PNCB))
  180809. if (NetbiosCall != 0)
  180810. {
  180811. NCB ncb;
  180812. zerostruct (ncb);
  180813. ASTAT astat;
  180814. zerostruct (astat);
  180815. LANA_ENUM enums;
  180816. zerostruct (enums);
  180817. ncb.ncb_command = NCBENUM;
  180818. ncb.ncb_buffer = (unsigned char*) &enums;
  180819. ncb.ncb_length = sizeof (LANA_ENUM);
  180820. NetbiosCall (&ncb);
  180821. for (int i = 0; i < enums.length; ++i)
  180822. {
  180823. zerostruct (ncb);
  180824. ncb.ncb_command = NCBRESET;
  180825. ncb.ncb_lana_num = enums.lana[i];
  180826. if (NetbiosCall (&ncb) == 0)
  180827. {
  180828. zerostruct (ncb);
  180829. memcpy (ncb.ncb_callname, "* ", NCBNAMSZ);
  180830. ncb.ncb_command = NCBASTAT;
  180831. ncb.ncb_lana_num = enums.lana[i];
  180832. ncb.ncb_buffer = (unsigned char*) &astat;
  180833. ncb.ncb_length = sizeof (ASTAT);
  180834. if (NetbiosCall (&ncb) == 0)
  180835. {
  180836. if (astat.adapt.adapter_type == 0xfe)
  180837. {
  180838. uint64 mac = 0;
  180839. for (int i = 6; --i >= 0;)
  180840. mac = (mac << 8) | astat.adapt.adapter_address [littleEndian ? i : (5 - i)];
  180841. if (numFound < maxNum && mac != 0)
  180842. addresses [numFound++] = mac;
  180843. }
  180844. }
  180845. }
  180846. }
  180847. }
  180848. return numFound;
  180849. }
  180850. int SystemStats::getMACAddresses (int64* addresses, int maxNum, const bool littleEndian)
  180851. {
  180852. int numFound = getMACAddressViaGetAdaptersInfo (addresses, maxNum, littleEndian);
  180853. if (numFound == 0)
  180854. numFound = getMACAddressesViaNetBios (addresses, maxNum, littleEndian);
  180855. return numFound;
  180856. }
  180857. typedef ULONG (WINAPI *MAPISendMailType) (LHANDLE, ULONG, lpMapiMessage, ::FLAGS, ULONG);
  180858. bool PlatformUtilities::launchEmailWithAttachments (const String& targetEmailAddress,
  180859. const String& emailSubject,
  180860. const String& bodyText,
  180861. const StringArray& filesToAttach)
  180862. {
  180863. HMODULE h = LoadLibraryA ("MAPI32.dll");
  180864. MAPISendMailType mapiSendMail = (MAPISendMailType) GetProcAddress (h, "MAPISendMail");
  180865. bool ok = false;
  180866. if (mapiSendMail != 0)
  180867. {
  180868. MapiMessage message;
  180869. zerostruct (message);
  180870. message.lpszSubject = (LPSTR) emailSubject.toCString();
  180871. message.lpszNoteText = (LPSTR) bodyText.toCString();
  180872. MapiRecipDesc recip;
  180873. zerostruct (recip);
  180874. recip.ulRecipClass = MAPI_TO;
  180875. String targetEmailAddress_ (targetEmailAddress);
  180876. if (targetEmailAddress_.isEmpty())
  180877. targetEmailAddress_ = " "; // (Windows Mail can't deal with a blank address)
  180878. recip.lpszName = (LPSTR) targetEmailAddress_.toCString();
  180879. message.nRecipCount = 1;
  180880. message.lpRecips = &recip;
  180881. MemoryBlock mb (sizeof (MapiFileDesc) * filesToAttach.size());
  180882. mb.fillWith (0);
  180883. MapiFileDesc* files = (MapiFileDesc*) mb.getData();
  180884. message.nFileCount = filesToAttach.size();
  180885. message.lpFiles = files;
  180886. for (int i = 0; i < filesToAttach.size(); ++i)
  180887. {
  180888. files[i].nPosition = (ULONG) -1;
  180889. files[i].lpszPathName = (LPSTR) filesToAttach[i].toCString();
  180890. }
  180891. ok = (mapiSendMail (0, 0, &message, MAPI_DIALOG | MAPI_LOGON_UI, 0) == SUCCESS_SUCCESS);
  180892. }
  180893. FreeLibrary (h);
  180894. return ok;
  180895. }
  180896. #endif
  180897. /*** End of inlined file: juce_win32_Network.cpp ***/
  180898. /*** Start of inlined file: juce_win32_PlatformUtils.cpp ***/
  180899. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  180900. // compiled on its own).
  180901. #if JUCE_INCLUDED_FILE
  180902. static HKEY findKeyForPath (String name,
  180903. const bool createForWriting,
  180904. String& valueName)
  180905. {
  180906. HKEY rootKey = 0;
  180907. if (name.startsWithIgnoreCase (T("HKEY_CURRENT_USER\\")))
  180908. rootKey = HKEY_CURRENT_USER;
  180909. else if (name.startsWithIgnoreCase (T("HKEY_LOCAL_MACHINE\\")))
  180910. rootKey = HKEY_LOCAL_MACHINE;
  180911. else if (name.startsWithIgnoreCase (T("HKEY_CLASSES_ROOT\\")))
  180912. rootKey = HKEY_CLASSES_ROOT;
  180913. if (rootKey != 0)
  180914. {
  180915. name = name.substring (name.indexOfChar (T('\\')) + 1);
  180916. const int lastSlash = name.lastIndexOfChar (T('\\'));
  180917. valueName = name.substring (lastSlash + 1);
  180918. name = name.substring (0, lastSlash);
  180919. HKEY key;
  180920. DWORD result;
  180921. if (createForWriting)
  180922. {
  180923. if (RegCreateKeyEx (rootKey, name, 0, 0, REG_OPTION_NON_VOLATILE,
  180924. (KEY_WRITE | KEY_QUERY_VALUE), 0, &key, &result) == ERROR_SUCCESS)
  180925. return key;
  180926. }
  180927. else
  180928. {
  180929. if (RegOpenKeyEx (rootKey, name, 0, KEY_READ, &key) == ERROR_SUCCESS)
  180930. return key;
  180931. }
  180932. }
  180933. return 0;
  180934. }
  180935. const String PlatformUtilities::getRegistryValue (const String& regValuePath,
  180936. const String& defaultValue)
  180937. {
  180938. String valueName, result (defaultValue);
  180939. HKEY k = findKeyForPath (regValuePath, false, valueName);
  180940. if (k != 0)
  180941. {
  180942. WCHAR buffer [2048];
  180943. unsigned long bufferSize = sizeof (buffer);
  180944. DWORD type = REG_SZ;
  180945. if (RegQueryValueEx (k, valueName, 0, &type, (LPBYTE) buffer, &bufferSize) == ERROR_SUCCESS)
  180946. {
  180947. if (type == REG_SZ)
  180948. result = buffer;
  180949. else if (type == REG_DWORD)
  180950. result = String ((int) *(DWORD*) buffer);
  180951. }
  180952. RegCloseKey (k);
  180953. }
  180954. return result;
  180955. }
  180956. void PlatformUtilities::setRegistryValue (const String& regValuePath,
  180957. const String& value)
  180958. {
  180959. String valueName;
  180960. HKEY k = findKeyForPath (regValuePath, true, valueName);
  180961. if (k != 0)
  180962. {
  180963. RegSetValueEx (k, valueName, 0, REG_SZ,
  180964. (const BYTE*) (const WCHAR*) value,
  180965. sizeof (WCHAR) * (value.length() + 1));
  180966. RegCloseKey (k);
  180967. }
  180968. }
  180969. bool PlatformUtilities::registryValueExists (const String& regValuePath)
  180970. {
  180971. bool exists = false;
  180972. String valueName;
  180973. HKEY k = findKeyForPath (regValuePath, false, valueName);
  180974. if (k != 0)
  180975. {
  180976. unsigned char buffer [2048];
  180977. unsigned long bufferSize = sizeof (buffer);
  180978. DWORD type = 0;
  180979. if (RegQueryValueEx (k, valueName, 0, &type, buffer, &bufferSize) == ERROR_SUCCESS)
  180980. exists = true;
  180981. RegCloseKey (k);
  180982. }
  180983. return exists;
  180984. }
  180985. void PlatformUtilities::deleteRegistryValue (const String& regValuePath)
  180986. {
  180987. String valueName;
  180988. HKEY k = findKeyForPath (regValuePath, true, valueName);
  180989. if (k != 0)
  180990. {
  180991. RegDeleteValue (k, valueName);
  180992. RegCloseKey (k);
  180993. }
  180994. }
  180995. void PlatformUtilities::deleteRegistryKey (const String& regKeyPath)
  180996. {
  180997. String valueName;
  180998. HKEY k = findKeyForPath (regKeyPath, true, valueName);
  180999. if (k != 0)
  181000. {
  181001. RegDeleteKey (k, valueName);
  181002. RegCloseKey (k);
  181003. }
  181004. }
  181005. void PlatformUtilities::registerFileAssociation (const String& fileExtension,
  181006. const String& symbolicDescription,
  181007. const String& fullDescription,
  181008. const File& targetExecutable,
  181009. int iconResourceNumber)
  181010. {
  181011. setRegistryValue ("HKEY_CLASSES_ROOT\\" + fileExtension + "\\", symbolicDescription);
  181012. const String key ("HKEY_CLASSES_ROOT\\" + symbolicDescription);
  181013. if (iconResourceNumber != 0)
  181014. setRegistryValue (key + "\\DefaultIcon\\",
  181015. targetExecutable.getFullPathName() + "," + String (-iconResourceNumber));
  181016. setRegistryValue (key + "\\", fullDescription);
  181017. setRegistryValue (key + "\\shell\\open\\command\\",
  181018. targetExecutable.getFullPathName() + " %1");
  181019. }
  181020. bool juce_IsRunningInWine()
  181021. {
  181022. HKEY key;
  181023. if (RegOpenKeyEx (HKEY_CURRENT_USER, _T("Software\\Wine"), 0, KEY_READ, &key) == ERROR_SUCCESS)
  181024. {
  181025. RegCloseKey (key);
  181026. return true;
  181027. }
  181028. return false;
  181029. }
  181030. const String JUCE_CALLTYPE PlatformUtilities::getCurrentCommandLineParams() throw()
  181031. {
  181032. String s (::GetCommandLineW());
  181033. StringArray tokens;
  181034. tokens.addTokens (s, true); // tokenise so that we can remove the initial filename argument
  181035. return tokens.joinIntoString (T(" "), 1);
  181036. }
  181037. static void* currentModuleHandle = 0;
  181038. void* PlatformUtilities::getCurrentModuleInstanceHandle() throw()
  181039. {
  181040. if (currentModuleHandle == 0)
  181041. currentModuleHandle = GetModuleHandle (0);
  181042. return currentModuleHandle;
  181043. }
  181044. void PlatformUtilities::setCurrentModuleInstanceHandle (void* const newHandle) throw()
  181045. {
  181046. currentModuleHandle = newHandle;
  181047. }
  181048. void PlatformUtilities::fpuReset()
  181049. {
  181050. #if JUCE_MSVC
  181051. _clearfp();
  181052. #endif
  181053. }
  181054. void PlatformUtilities::beep()
  181055. {
  181056. MessageBeep (MB_OK);
  181057. }
  181058. #endif
  181059. /*** End of inlined file: juce_win32_PlatformUtils.cpp ***/
  181060. #if ! JUCE_ONLY_BUILD_CORE_LIBRARY
  181061. /*** Start of inlined file: juce_win32_Messaging.cpp ***/
  181062. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  181063. // compiled on its own).
  181064. #if JUCE_INCLUDED_FILE
  181065. static const unsigned int specialId = WM_APP + 0x4400;
  181066. static const unsigned int broadcastId = WM_APP + 0x4403;
  181067. static const unsigned int specialCallbackId = WM_APP + 0x4402;
  181068. static const TCHAR* const messageWindowName = _T("JUCEWindow");
  181069. HWND juce_messageWindowHandle = 0;
  181070. extern long improbableWindowNumber; // defined in windowing.cpp
  181071. #ifndef WM_APPCOMMAND
  181072. #define WM_APPCOMMAND 0x0319
  181073. #endif
  181074. static LRESULT CALLBACK juce_MessageWndProc (HWND h,
  181075. const UINT message,
  181076. const WPARAM wParam,
  181077. const LPARAM lParam) throw()
  181078. {
  181079. JUCE_TRY
  181080. {
  181081. if (h == juce_messageWindowHandle)
  181082. {
  181083. if (message == specialCallbackId)
  181084. {
  181085. MessageCallbackFunction* const func = (MessageCallbackFunction*) wParam;
  181086. return (LRESULT) (*func) ((void*) lParam);
  181087. }
  181088. else if (message == specialId)
  181089. {
  181090. // these are trapped early in the dispatch call, but must also be checked
  181091. // here in case there are windows modal dialog boxes doing their own
  181092. // dispatch loop and not calling our version
  181093. MessageManager::getInstance()->deliverMessage ((void*) lParam);
  181094. return 0;
  181095. }
  181096. else if (message == broadcastId)
  181097. {
  181098. const ScopedPointer <String> messageString ((String*) lParam);
  181099. MessageManager::getInstance()->deliverBroadcastMessage (*messageString);
  181100. return 0;
  181101. }
  181102. else if (message == WM_COPYDATA && ((const COPYDATASTRUCT*) lParam)->dwData == broadcastId)
  181103. {
  181104. const String messageString ((const juce_wchar*) ((const COPYDATASTRUCT*) lParam)->lpData,
  181105. ((const COPYDATASTRUCT*) lParam)->cbData / sizeof (juce_wchar));
  181106. PostMessage (juce_messageWindowHandle, broadcastId, 0, (LPARAM) new String (messageString));
  181107. return 0;
  181108. }
  181109. }
  181110. }
  181111. JUCE_CATCH_EXCEPTION
  181112. return DefWindowProc (h, message, wParam, lParam);
  181113. }
  181114. static bool isEventBlockedByModalComps (MSG& m)
  181115. {
  181116. if (Component::getNumCurrentlyModalComponents() == 0
  181117. || GetWindowLong (m.hwnd, GWLP_USERDATA) == improbableWindowNumber)
  181118. return false;
  181119. switch (m.message)
  181120. {
  181121. case WM_MOUSEMOVE:
  181122. case WM_NCMOUSEMOVE:
  181123. case 0x020A: /* WM_MOUSEWHEEL */
  181124. case 0x020E: /* WM_MOUSEHWHEEL */
  181125. case WM_KEYUP:
  181126. case WM_SYSKEYUP:
  181127. case WM_CHAR:
  181128. case WM_APPCOMMAND:
  181129. case WM_LBUTTONUP:
  181130. case WM_MBUTTONUP:
  181131. case WM_RBUTTONUP:
  181132. case WM_MOUSEACTIVATE:
  181133. case WM_NCMOUSEHOVER:
  181134. case WM_MOUSEHOVER:
  181135. return true;
  181136. case WM_NCLBUTTONDOWN:
  181137. case WM_NCLBUTTONDBLCLK:
  181138. case WM_NCRBUTTONDOWN:
  181139. case WM_NCRBUTTONDBLCLK:
  181140. case WM_NCMBUTTONDOWN:
  181141. case WM_NCMBUTTONDBLCLK:
  181142. case WM_LBUTTONDOWN:
  181143. case WM_LBUTTONDBLCLK:
  181144. case WM_MBUTTONDOWN:
  181145. case WM_MBUTTONDBLCLK:
  181146. case WM_RBUTTONDOWN:
  181147. case WM_RBUTTONDBLCLK:
  181148. case WM_KEYDOWN:
  181149. case WM_SYSKEYDOWN:
  181150. {
  181151. Component* const modal = Component::getCurrentlyModalComponent (0);
  181152. if (modal != 0)
  181153. modal->inputAttemptWhenModal();
  181154. return true;
  181155. }
  181156. default:
  181157. break;
  181158. }
  181159. return false;
  181160. }
  181161. bool juce_dispatchNextMessageOnSystemQueue (const bool returnIfNoPendingMessages)
  181162. {
  181163. MSG m;
  181164. if (returnIfNoPendingMessages && ! PeekMessage (&m, (HWND) 0, 0, 0, 0))
  181165. return false;
  181166. if (GetMessage (&m, (HWND) 0, 0, 0) >= 0)
  181167. {
  181168. if (m.message == specialId && m.hwnd == juce_messageWindowHandle)
  181169. {
  181170. MessageManager::getInstance()->deliverMessage ((void*) m.lParam);
  181171. }
  181172. else if (m.message == WM_QUIT)
  181173. {
  181174. if (JUCEApplication::getInstance())
  181175. JUCEApplication::getInstance()->systemRequestedQuit();
  181176. }
  181177. else if (! isEventBlockedByModalComps (m))
  181178. {
  181179. if ((m.message == WM_LBUTTONDOWN || m.message == WM_RBUTTONDOWN)
  181180. && GetWindowLong (m.hwnd, GWLP_USERDATA) != improbableWindowNumber)
  181181. {
  181182. // if it's someone else's window being clicked on, and the focus is
  181183. // currently on a juce window, pass the kb focus over..
  181184. HWND currentFocus = GetFocus();
  181185. if (currentFocus == 0 || GetWindowLong (currentFocus, GWLP_USERDATA) == improbableWindowNumber)
  181186. SetFocus (m.hwnd);
  181187. }
  181188. TranslateMessage (&m);
  181189. DispatchMessage (&m);
  181190. }
  181191. }
  181192. return true;
  181193. }
  181194. bool juce_postMessageToSystemQueue (void* message)
  181195. {
  181196. return PostMessage (juce_messageWindowHandle, specialId, 0, (LPARAM) message) != 0;
  181197. }
  181198. void* MessageManager::callFunctionOnMessageThread (MessageCallbackFunction* callback,
  181199. void* userData)
  181200. {
  181201. if (MessageManager::getInstance()->isThisTheMessageThread())
  181202. {
  181203. return (*callback) (userData);
  181204. }
  181205. else
  181206. {
  181207. // If a thread has a MessageManagerLock and then tries to call this method, it'll
  181208. // deadlock because the message manager is blocked from running, and can't
  181209. // call your function..
  181210. jassert (! MessageManager::getInstance()->currentThreadHasLockedMessageManager());
  181211. return (void*) SendMessage (juce_messageWindowHandle,
  181212. specialCallbackId,
  181213. (WPARAM) callback,
  181214. (LPARAM) userData);
  181215. }
  181216. }
  181217. static BOOL CALLBACK BroadcastEnumWindowProc (HWND hwnd, LPARAM lParam)
  181218. {
  181219. if (hwnd != juce_messageWindowHandle)
  181220. (reinterpret_cast <VoidArray*> (lParam))->add ((void*) hwnd);
  181221. return TRUE;
  181222. }
  181223. void MessageManager::broadcastMessage (const String& value) throw()
  181224. {
  181225. VoidArray windows;
  181226. EnumWindows (&BroadcastEnumWindowProc, (LPARAM) &windows);
  181227. const String localCopy (value);
  181228. COPYDATASTRUCT data;
  181229. data.dwData = broadcastId;
  181230. data.cbData = (localCopy.length() + 1) * sizeof (juce_wchar);
  181231. data.lpData = (void*) (const juce_wchar*) localCopy;
  181232. for (int i = windows.size(); --i >= 0;)
  181233. {
  181234. HWND hwnd = (HWND) windows.getUnchecked(i);
  181235. TCHAR windowName [64]; // no need to read longer strings than this
  181236. GetWindowText (hwnd, windowName, 64);
  181237. windowName [63] = 0;
  181238. if (String (windowName) == String (messageWindowName))
  181239. {
  181240. DWORD_PTR result;
  181241. SendMessageTimeout (hwnd, WM_COPYDATA,
  181242. (WPARAM) juce_messageWindowHandle,
  181243. (LPARAM) &data,
  181244. SMTO_BLOCK | SMTO_ABORTIFHUNG,
  181245. 8000,
  181246. &result);
  181247. }
  181248. }
  181249. }
  181250. static const String getMessageWindowClassName()
  181251. {
  181252. // this name has to be different for each app/dll instance because otherwise
  181253. // poor old Win32 can get a bit confused (even despite it not being a process-global
  181254. // window class).
  181255. static int number = 0;
  181256. if (number == 0)
  181257. number = 0x7fffffff & (int) Time::getHighResolutionTicks();
  181258. return T("JUCEcs_") + String (number);
  181259. }
  181260. void MessageManager::doPlatformSpecificInitialisation()
  181261. {
  181262. OleInitialize (0);
  181263. const String className (getMessageWindowClassName());
  181264. HMODULE hmod = (HMODULE) PlatformUtilities::getCurrentModuleInstanceHandle();
  181265. WNDCLASSEX wc;
  181266. zerostruct (wc);
  181267. wc.cbSize = sizeof (wc);
  181268. wc.lpfnWndProc = (WNDPROC) juce_MessageWndProc;
  181269. wc.cbWndExtra = 4;
  181270. wc.hInstance = hmod;
  181271. wc.lpszClassName = className;
  181272. RegisterClassEx (&wc);
  181273. juce_messageWindowHandle = CreateWindow (wc.lpszClassName,
  181274. messageWindowName,
  181275. 0, 0, 0, 0, 0, 0, 0,
  181276. hmod, 0);
  181277. }
  181278. void MessageManager::doPlatformSpecificShutdown()
  181279. {
  181280. DestroyWindow (juce_messageWindowHandle);
  181281. UnregisterClass (getMessageWindowClassName(), 0);
  181282. OleUninitialize();
  181283. }
  181284. #endif
  181285. /*** End of inlined file: juce_win32_Messaging.cpp ***/
  181286. /*** Start of inlined file: juce_win32_Windowing.cpp ***/
  181287. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  181288. // compiled on its own).
  181289. #if JUCE_INCLUDED_FILE
  181290. #undef GetSystemMetrics // multimon overrides this for some reason and causes a mess..
  181291. // these are in the windows SDK, but need to be repeated here for GCC..
  181292. #ifndef GET_APPCOMMAND_LPARAM
  181293. #define FAPPCOMMAND_MASK 0xF000
  181294. #define GET_APPCOMMAND_LPARAM(lParam) ((short) (HIWORD (lParam) & ~FAPPCOMMAND_MASK))
  181295. #define APPCOMMAND_MEDIA_NEXTTRACK 11
  181296. #define APPCOMMAND_MEDIA_PREVIOUSTRACK 12
  181297. #define APPCOMMAND_MEDIA_STOP 13
  181298. #define APPCOMMAND_MEDIA_PLAY_PAUSE 14
  181299. #define WM_APPCOMMAND 0x0319
  181300. #endif
  181301. extern void juce_repeatLastProcessPriority(); // in juce_win32_Threads.cpp
  181302. extern void juce_CheckCurrentlyFocusedTopLevelWindow(); // in juce_TopLevelWindow.cpp
  181303. extern bool juce_IsRunningInWine();
  181304. #ifndef ULW_ALPHA
  181305. #define ULW_ALPHA 0x00000002
  181306. #endif
  181307. #ifndef AC_SRC_ALPHA
  181308. #define AC_SRC_ALPHA 0x01
  181309. #endif
  181310. static HPALETTE palette = 0;
  181311. static bool createPaletteIfNeeded = true;
  181312. static bool shouldDeactivateTitleBar = true;
  181313. static HICON createHICONFromImage (const Image& image, const BOOL isIcon, int hotspotX, int hotspotY) throw();
  181314. #define WM_TRAYNOTIFY WM_USER + 100
  181315. using ::abs;
  181316. typedef BOOL (WINAPI* UpdateLayeredWinFunc) (HWND, HDC, POINT*, SIZE*, HDC, POINT*, COLORREF, BLENDFUNCTION*, DWORD);
  181317. static UpdateLayeredWinFunc updateLayeredWindow = 0;
  181318. bool Desktop::canUseSemiTransparentWindows() throw()
  181319. {
  181320. if (updateLayeredWindow == 0)
  181321. {
  181322. if (! juce_IsRunningInWine())
  181323. {
  181324. HMODULE user32Mod = GetModuleHandle (_T("user32.dll"));
  181325. updateLayeredWindow = (UpdateLayeredWinFunc) GetProcAddress (user32Mod, "UpdateLayeredWindow");
  181326. }
  181327. }
  181328. return updateLayeredWindow != 0;
  181329. }
  181330. const int extendedKeyModifier = 0x10000;
  181331. const int KeyPress::spaceKey = VK_SPACE;
  181332. const int KeyPress::returnKey = VK_RETURN;
  181333. const int KeyPress::escapeKey = VK_ESCAPE;
  181334. const int KeyPress::backspaceKey = VK_BACK;
  181335. const int KeyPress::deleteKey = VK_DELETE | extendedKeyModifier;
  181336. const int KeyPress::insertKey = VK_INSERT | extendedKeyModifier;
  181337. const int KeyPress::tabKey = VK_TAB;
  181338. const int KeyPress::leftKey = VK_LEFT | extendedKeyModifier;
  181339. const int KeyPress::rightKey = VK_RIGHT | extendedKeyModifier;
  181340. const int KeyPress::upKey = VK_UP | extendedKeyModifier;
  181341. const int KeyPress::downKey = VK_DOWN | extendedKeyModifier;
  181342. const int KeyPress::homeKey = VK_HOME | extendedKeyModifier;
  181343. const int KeyPress::endKey = VK_END | extendedKeyModifier;
  181344. const int KeyPress::pageUpKey = VK_PRIOR | extendedKeyModifier;
  181345. const int KeyPress::pageDownKey = VK_NEXT | extendedKeyModifier;
  181346. const int KeyPress::F1Key = VK_F1 | extendedKeyModifier;
  181347. const int KeyPress::F2Key = VK_F2 | extendedKeyModifier;
  181348. const int KeyPress::F3Key = VK_F3 | extendedKeyModifier;
  181349. const int KeyPress::F4Key = VK_F4 | extendedKeyModifier;
  181350. const int KeyPress::F5Key = VK_F5 | extendedKeyModifier;
  181351. const int KeyPress::F6Key = VK_F6 | extendedKeyModifier;
  181352. const int KeyPress::F7Key = VK_F7 | extendedKeyModifier;
  181353. const int KeyPress::F8Key = VK_F8 | extendedKeyModifier;
  181354. const int KeyPress::F9Key = VK_F9 | extendedKeyModifier;
  181355. const int KeyPress::F10Key = VK_F10 | extendedKeyModifier;
  181356. const int KeyPress::F11Key = VK_F11 | extendedKeyModifier;
  181357. const int KeyPress::F12Key = VK_F12 | extendedKeyModifier;
  181358. const int KeyPress::F13Key = VK_F13 | extendedKeyModifier;
  181359. const int KeyPress::F14Key = VK_F14 | extendedKeyModifier;
  181360. const int KeyPress::F15Key = VK_F15 | extendedKeyModifier;
  181361. const int KeyPress::F16Key = VK_F16 | extendedKeyModifier;
  181362. const int KeyPress::numberPad0 = VK_NUMPAD0 | extendedKeyModifier;
  181363. const int KeyPress::numberPad1 = VK_NUMPAD1 | extendedKeyModifier;
  181364. const int KeyPress::numberPad2 = VK_NUMPAD2 | extendedKeyModifier;
  181365. const int KeyPress::numberPad3 = VK_NUMPAD3 | extendedKeyModifier;
  181366. const int KeyPress::numberPad4 = VK_NUMPAD4 | extendedKeyModifier;
  181367. const int KeyPress::numberPad5 = VK_NUMPAD5 | extendedKeyModifier;
  181368. const int KeyPress::numberPad6 = VK_NUMPAD6 | extendedKeyModifier;
  181369. const int KeyPress::numberPad7 = VK_NUMPAD7 | extendedKeyModifier;
  181370. const int KeyPress::numberPad8 = VK_NUMPAD8 | extendedKeyModifier;
  181371. const int KeyPress::numberPad9 = VK_NUMPAD9 | extendedKeyModifier;
  181372. const int KeyPress::numberPadAdd = VK_ADD | extendedKeyModifier;
  181373. const int KeyPress::numberPadSubtract = VK_SUBTRACT | extendedKeyModifier;
  181374. const int KeyPress::numberPadMultiply = VK_MULTIPLY | extendedKeyModifier;
  181375. const int KeyPress::numberPadDivide = VK_DIVIDE | extendedKeyModifier;
  181376. const int KeyPress::numberPadSeparator = VK_SEPARATOR | extendedKeyModifier;
  181377. const int KeyPress::numberPadDecimalPoint = VK_DECIMAL | extendedKeyModifier;
  181378. const int KeyPress::numberPadEquals = 0x92 /*VK_OEM_NEC_EQUAL*/ | extendedKeyModifier;
  181379. const int KeyPress::numberPadDelete = VK_DELETE | extendedKeyModifier;
  181380. const int KeyPress::playKey = 0x30000;
  181381. const int KeyPress::stopKey = 0x30001;
  181382. const int KeyPress::fastForwardKey = 0x30002;
  181383. const int KeyPress::rewindKey = 0x30003;
  181384. class WindowsBitmapImage : public Image
  181385. {
  181386. public:
  181387. HBITMAP hBitmap;
  181388. BITMAPV4HEADER bitmapInfo;
  181389. HDC hdc;
  181390. unsigned char* bitmapData;
  181391. WindowsBitmapImage (const PixelFormat format_,
  181392. const int w, const int h, const bool clearImage)
  181393. : Image (format_, w, h)
  181394. {
  181395. jassert (format_ == RGB || format_ == ARGB);
  181396. pixelStride = (format_ == RGB) ? 3 : 4;
  181397. zerostruct (bitmapInfo);
  181398. bitmapInfo.bV4Size = sizeof (BITMAPV4HEADER);
  181399. bitmapInfo.bV4Width = w;
  181400. bitmapInfo.bV4Height = h;
  181401. bitmapInfo.bV4Planes = 1;
  181402. bitmapInfo.bV4CSType = 1;
  181403. bitmapInfo.bV4BitCount = (unsigned short) (pixelStride * 8);
  181404. if (format_ == ARGB)
  181405. {
  181406. bitmapInfo.bV4AlphaMask = 0xff000000;
  181407. bitmapInfo.bV4RedMask = 0xff0000;
  181408. bitmapInfo.bV4GreenMask = 0xff00;
  181409. bitmapInfo.bV4BlueMask = 0xff;
  181410. bitmapInfo.bV4V4Compression = BI_BITFIELDS;
  181411. }
  181412. else
  181413. {
  181414. bitmapInfo.bV4V4Compression = BI_RGB;
  181415. }
  181416. lineStride = -((w * pixelStride + 3) & ~3);
  181417. HDC dc = GetDC (0);
  181418. hdc = CreateCompatibleDC (dc);
  181419. ReleaseDC (0, dc);
  181420. SetMapMode (hdc, MM_TEXT);
  181421. hBitmap = CreateDIBSection (hdc,
  181422. (BITMAPINFO*) &(bitmapInfo),
  181423. DIB_RGB_COLORS,
  181424. (void**) &bitmapData,
  181425. 0, 0);
  181426. SelectObject (hdc, hBitmap);
  181427. if (format_ == ARGB && clearImage)
  181428. zeromem (bitmapData, abs (h * lineStride));
  181429. imageData = bitmapData - (lineStride * (h - 1));
  181430. }
  181431. ~WindowsBitmapImage()
  181432. {
  181433. DeleteDC (hdc);
  181434. DeleteObject (hBitmap);
  181435. }
  181436. void blitToWindow (HWND hwnd, HDC dc, const bool transparent,
  181437. const int x, const int y,
  181438. const RectangleList& maskedRegion) throw()
  181439. {
  181440. static HDRAWDIB hdd = 0;
  181441. static bool needToCreateDrawDib = true;
  181442. if (needToCreateDrawDib)
  181443. {
  181444. needToCreateDrawDib = false;
  181445. HDC dc = GetDC (0);
  181446. const int n = GetDeviceCaps (dc, BITSPIXEL);
  181447. ReleaseDC (0, dc);
  181448. // only open if we're not palettised
  181449. if (n > 8)
  181450. hdd = DrawDibOpen();
  181451. }
  181452. if (createPaletteIfNeeded)
  181453. {
  181454. HDC dc = GetDC (0);
  181455. const int n = GetDeviceCaps (dc, BITSPIXEL);
  181456. ReleaseDC (0, dc);
  181457. if (n <= 8)
  181458. palette = CreateHalftonePalette (dc);
  181459. createPaletteIfNeeded = false;
  181460. }
  181461. if (palette != 0)
  181462. {
  181463. SelectPalette (dc, palette, FALSE);
  181464. RealizePalette (dc);
  181465. SetStretchBltMode (dc, HALFTONE);
  181466. }
  181467. SetMapMode (dc, MM_TEXT);
  181468. if (transparent)
  181469. {
  181470. POINT p, pos;
  181471. SIZE size;
  181472. RECT windowBounds;
  181473. GetWindowRect (hwnd, &windowBounds);
  181474. p.x = -x;
  181475. p.y = -y;
  181476. pos.x = windowBounds.left;
  181477. pos.y = windowBounds.top;
  181478. size.cx = windowBounds.right - windowBounds.left;
  181479. size.cy = windowBounds.bottom - windowBounds.top;
  181480. BLENDFUNCTION bf;
  181481. bf.AlphaFormat = AC_SRC_ALPHA;
  181482. bf.BlendFlags = 0;
  181483. bf.BlendOp = AC_SRC_OVER;
  181484. bf.SourceConstantAlpha = 0xff;
  181485. if (! maskedRegion.isEmpty())
  181486. {
  181487. for (RectangleList::Iterator i (maskedRegion); i.next();)
  181488. {
  181489. const Rectangle<int>& r = *i.getRectangle();
  181490. ExcludeClipRect (hdc, r.getX(), r.getY(), r.getRight(), r.getBottom());
  181491. }
  181492. }
  181493. updateLayeredWindow (hwnd, 0, &pos, &size, hdc, &p, 0, &bf, ULW_ALPHA);
  181494. }
  181495. else
  181496. {
  181497. int savedDC = 0;
  181498. if (! maskedRegion.isEmpty())
  181499. {
  181500. savedDC = SaveDC (dc);
  181501. for (RectangleList::Iterator i (maskedRegion); i.next();)
  181502. {
  181503. const Rectangle<int>& r = *i.getRectangle();
  181504. ExcludeClipRect (dc, r.getX(), r.getY(), r.getRight(), r.getBottom());
  181505. }
  181506. }
  181507. const int w = getWidth();
  181508. const int h = getHeight();
  181509. if (hdd == 0)
  181510. {
  181511. StretchDIBits (dc,
  181512. x, y, w, h,
  181513. 0, 0, w, h,
  181514. bitmapData, (const BITMAPINFO*) &bitmapInfo,
  181515. DIB_RGB_COLORS, SRCCOPY);
  181516. }
  181517. else
  181518. {
  181519. DrawDibDraw (hdd, dc, x, y, -1, -1,
  181520. (BITMAPINFOHEADER*) &bitmapInfo, bitmapData,
  181521. 0, 0, w, h, 0);
  181522. }
  181523. if (! maskedRegion.isEmpty())
  181524. RestoreDC (dc, savedDC);
  181525. }
  181526. }
  181527. juce_UseDebuggingNewOperator
  181528. private:
  181529. WindowsBitmapImage (const WindowsBitmapImage&);
  181530. WindowsBitmapImage& operator= (const WindowsBitmapImage&);
  181531. };
  181532. long improbableWindowNumber = 0xf965aa01; // also referenced by messaging.cpp
  181533. bool KeyPress::isKeyCurrentlyDown (const int keyCode) throw()
  181534. {
  181535. SHORT k = (SHORT) keyCode;
  181536. if ((keyCode & extendedKeyModifier) == 0
  181537. && (k >= (SHORT) T('a') && k <= (SHORT) T('z')))
  181538. k += (SHORT) T('A') - (SHORT) T('a');
  181539. const SHORT translatedValues[] = { (SHORT) ',', VK_OEM_COMMA,
  181540. (SHORT) '+', VK_OEM_PLUS,
  181541. (SHORT) '-', VK_OEM_MINUS,
  181542. (SHORT) '.', VK_OEM_PERIOD,
  181543. (SHORT) ';', VK_OEM_1,
  181544. (SHORT) ':', VK_OEM_1,
  181545. (SHORT) '/', VK_OEM_2,
  181546. (SHORT) '?', VK_OEM_2,
  181547. (SHORT) '[', VK_OEM_4,
  181548. (SHORT) ']', VK_OEM_6 };
  181549. for (int i = 0; i < numElementsInArray (translatedValues); i += 2)
  181550. if (k == translatedValues [i])
  181551. k = translatedValues [i + 1];
  181552. return (GetKeyState (k) & 0x8000) != 0;
  181553. }
  181554. static void* callFunctionIfNotLocked (MessageCallbackFunction* callback, void* userData)
  181555. {
  181556. if (MessageManager::getInstance()->currentThreadHasLockedMessageManager())
  181557. return callback (userData);
  181558. else
  181559. return MessageManager::getInstance()->callFunctionOnMessageThread (callback, userData);
  181560. }
  181561. class Win32ComponentPeer : public ComponentPeer
  181562. {
  181563. public:
  181564. Win32ComponentPeer (Component* const component,
  181565. const int windowStyleFlags)
  181566. : ComponentPeer (component, windowStyleFlags),
  181567. dontRepaint (false),
  181568. fullScreen (false),
  181569. isDragging (false),
  181570. isMouseOver (false),
  181571. hasCreatedCaret (false),
  181572. currentWindowIcon (0),
  181573. taskBarIcon (0),
  181574. dropTarget (0)
  181575. {
  181576. callFunctionIfNotLocked (&createWindowCallback, (void*) this);
  181577. setTitle (component->getName());
  181578. if ((windowStyleFlags & windowHasDropShadow) != 0
  181579. && Desktop::canUseSemiTransparentWindows())
  181580. {
  181581. shadower = component->getLookAndFeel().createDropShadowerForComponent (component);
  181582. if (shadower != 0)
  181583. shadower->setOwner (component);
  181584. }
  181585. else
  181586. {
  181587. shadower = 0;
  181588. }
  181589. }
  181590. ~Win32ComponentPeer()
  181591. {
  181592. setTaskBarIcon (0);
  181593. deleteAndZero (shadower);
  181594. // do this before the next bit to avoid messages arriving for this window
  181595. // before it's destroyed
  181596. SetWindowLongPtr (hwnd, GWLP_USERDATA, 0);
  181597. callFunctionIfNotLocked (&destroyWindowCallback, (void*) hwnd);
  181598. if (currentWindowIcon != 0)
  181599. DestroyIcon (currentWindowIcon);
  181600. if (dropTarget != 0)
  181601. {
  181602. dropTarget->Release();
  181603. dropTarget = 0;
  181604. }
  181605. }
  181606. void* getNativeHandle() const
  181607. {
  181608. return (void*) hwnd;
  181609. }
  181610. void setVisible (bool shouldBeVisible)
  181611. {
  181612. ShowWindow (hwnd, shouldBeVisible ? SW_SHOWNA : SW_HIDE);
  181613. if (shouldBeVisible)
  181614. InvalidateRect (hwnd, 0, 0);
  181615. else
  181616. lastPaintTime = 0;
  181617. }
  181618. void setTitle (const String& title)
  181619. {
  181620. SetWindowText (hwnd, title);
  181621. }
  181622. void setPosition (int x, int y)
  181623. {
  181624. offsetWithinParent (x, y);
  181625. SetWindowPos (hwnd, 0,
  181626. x - windowBorder.getLeft(),
  181627. y - windowBorder.getTop(),
  181628. 0, 0,
  181629. SWP_NOACTIVATE | SWP_NOSIZE | SWP_NOZORDER | SWP_NOOWNERZORDER);
  181630. }
  181631. void repaintNowIfTransparent()
  181632. {
  181633. if (isTransparent() && lastPaintTime > 0 && Time::getMillisecondCounter() > lastPaintTime + 30)
  181634. handlePaintMessage();
  181635. }
  181636. void updateBorderSize()
  181637. {
  181638. WINDOWINFO info;
  181639. info.cbSize = sizeof (info);
  181640. if (GetWindowInfo (hwnd, &info))
  181641. {
  181642. windowBorder = BorderSize (info.rcClient.top - info.rcWindow.top,
  181643. info.rcClient.left - info.rcWindow.left,
  181644. info.rcWindow.bottom - info.rcClient.bottom,
  181645. info.rcWindow.right - info.rcClient.right);
  181646. }
  181647. }
  181648. void setSize (int w, int h)
  181649. {
  181650. SetWindowPos (hwnd, 0, 0, 0,
  181651. w + windowBorder.getLeftAndRight(),
  181652. h + windowBorder.getTopAndBottom(),
  181653. SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOZORDER | SWP_NOOWNERZORDER);
  181654. updateBorderSize();
  181655. repaintNowIfTransparent();
  181656. }
  181657. void setBounds (int x, int y, int w, int h, const bool isNowFullScreen)
  181658. {
  181659. fullScreen = isNowFullScreen;
  181660. offsetWithinParent (x, y);
  181661. SetWindowPos (hwnd, 0,
  181662. x - windowBorder.getLeft(),
  181663. y - windowBorder.getTop(),
  181664. w + windowBorder.getLeftAndRight(),
  181665. h + windowBorder.getTopAndBottom(),
  181666. SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOOWNERZORDER);
  181667. updateBorderSize();
  181668. repaintNowIfTransparent();
  181669. }
  181670. const Rectangle<int> getBounds() const
  181671. {
  181672. RECT r;
  181673. GetWindowRect (hwnd, &r);
  181674. Rectangle<int> bounds (r.left, r.top, r.right - r.left, r.bottom - r.top);
  181675. HWND parentH = GetParent (hwnd);
  181676. if (parentH != 0)
  181677. {
  181678. GetWindowRect (parentH, &r);
  181679. bounds.translate (-r.left, -r.top);
  181680. }
  181681. return windowBorder.subtractedFrom (bounds);
  181682. }
  181683. const Point<int> getScreenPosition() const
  181684. {
  181685. RECT r;
  181686. GetWindowRect (hwnd, &r);
  181687. return Point<int> (r.left + windowBorder.getLeft(),
  181688. r.top + windowBorder.getTop());
  181689. }
  181690. const Point<int> relativePositionToGlobal (const Point<int>& relativePosition)
  181691. {
  181692. return relativePosition + getScreenPosition();
  181693. }
  181694. const Point<int> globalPositionToRelative (const Point<int>& screenPosition)
  181695. {
  181696. return screenPosition - getScreenPosition();
  181697. }
  181698. void setMinimised (bool shouldBeMinimised)
  181699. {
  181700. if (shouldBeMinimised != isMinimised())
  181701. ShowWindow (hwnd, shouldBeMinimised ? SW_MINIMIZE : SW_SHOWNORMAL);
  181702. }
  181703. bool isMinimised() const
  181704. {
  181705. WINDOWPLACEMENT wp;
  181706. wp.length = sizeof (WINDOWPLACEMENT);
  181707. GetWindowPlacement (hwnd, &wp);
  181708. return wp.showCmd == SW_SHOWMINIMIZED;
  181709. }
  181710. void setFullScreen (bool shouldBeFullScreen)
  181711. {
  181712. setMinimised (false);
  181713. if (fullScreen != shouldBeFullScreen)
  181714. {
  181715. fullScreen = shouldBeFullScreen;
  181716. const Component::SafePointer<Component> deletionChecker (component);
  181717. if (! fullScreen)
  181718. {
  181719. const Rectangle<int> boundsCopy (lastNonFullscreenBounds);
  181720. if (hasTitleBar())
  181721. ShowWindow (hwnd, SW_SHOWNORMAL);
  181722. if (! boundsCopy.isEmpty())
  181723. {
  181724. setBounds (boundsCopy.getX(),
  181725. boundsCopy.getY(),
  181726. boundsCopy.getWidth(),
  181727. boundsCopy.getHeight(),
  181728. false);
  181729. }
  181730. }
  181731. else
  181732. {
  181733. if (hasTitleBar())
  181734. ShowWindow (hwnd, SW_SHOWMAXIMIZED);
  181735. else
  181736. SendMessageW (hwnd, WM_SETTINGCHANGE, 0, 0);
  181737. }
  181738. if (deletionChecker != 0)
  181739. handleMovedOrResized();
  181740. }
  181741. }
  181742. bool isFullScreen() const
  181743. {
  181744. if (! hasTitleBar())
  181745. return fullScreen;
  181746. WINDOWPLACEMENT wp;
  181747. wp.length = sizeof (wp);
  181748. GetWindowPlacement (hwnd, &wp);
  181749. return wp.showCmd == SW_SHOWMAXIMIZED;
  181750. }
  181751. bool contains (const Point<int>& position, bool trueIfInAChildWindow) const
  181752. {
  181753. if (((unsigned int) position.getX()) >= (unsigned int) component->getWidth()
  181754. || ((unsigned int) position.getY()) >= (unsigned int) component->getHeight())
  181755. return false;
  181756. RECT r;
  181757. GetWindowRect (hwnd, &r);
  181758. POINT p;
  181759. p.x = position.getX() + r.left + windowBorder.getLeft();
  181760. p.y = position.getY() + r.top + windowBorder.getTop();
  181761. HWND w = WindowFromPoint (p);
  181762. return w == hwnd || (trueIfInAChildWindow && (IsChild (hwnd, w) != 0));
  181763. }
  181764. const BorderSize getFrameSize() const
  181765. {
  181766. return windowBorder;
  181767. }
  181768. bool setAlwaysOnTop (bool alwaysOnTop)
  181769. {
  181770. const bool oldDeactivate = shouldDeactivateTitleBar;
  181771. shouldDeactivateTitleBar = ((styleFlags & windowIsTemporary) == 0);
  181772. SetWindowPos (hwnd, alwaysOnTop ? HWND_TOPMOST : HWND_NOTOPMOST,
  181773. 0, 0, 0, 0,
  181774. SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE | SWP_NOSENDCHANGING);
  181775. shouldDeactivateTitleBar = oldDeactivate;
  181776. if (shadower != 0)
  181777. shadower->componentBroughtToFront (*component);
  181778. return true;
  181779. }
  181780. void toFront (bool makeActive)
  181781. {
  181782. setMinimised (false);
  181783. const bool oldDeactivate = shouldDeactivateTitleBar;
  181784. shouldDeactivateTitleBar = ((styleFlags & windowIsTemporary) == 0);
  181785. callFunctionIfNotLocked (makeActive ? &toFrontCallback1
  181786. : &toFrontCallback2,
  181787. (void*) hwnd);
  181788. shouldDeactivateTitleBar = oldDeactivate;
  181789. if (! makeActive)
  181790. {
  181791. // in this case a broughttofront call won't have occured, so do it now..
  181792. handleBroughtToFront();
  181793. }
  181794. }
  181795. void toBehind (ComponentPeer* other)
  181796. {
  181797. Win32ComponentPeer* const otherPeer = dynamic_cast <Win32ComponentPeer*> (other);
  181798. jassert (otherPeer != 0); // wrong type of window?
  181799. if (otherPeer != 0)
  181800. {
  181801. setMinimised (false);
  181802. // must be careful not to try to put a topmost window behind a normal one, or win32
  181803. // promotes the normal one to be topmost!
  181804. if (getComponent()->isAlwaysOnTop() == otherPeer->getComponent()->isAlwaysOnTop())
  181805. SetWindowPos (hwnd, otherPeer->hwnd, 0, 0, 0, 0,
  181806. SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE | SWP_NOSENDCHANGING);
  181807. else if (otherPeer->getComponent()->isAlwaysOnTop())
  181808. SetWindowPos (hwnd, HWND_TOP, 0, 0, 0, 0,
  181809. SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE | SWP_NOSENDCHANGING);
  181810. }
  181811. }
  181812. bool isFocused() const
  181813. {
  181814. return callFunctionIfNotLocked (&getFocusCallback, 0) == (void*) hwnd;
  181815. }
  181816. void grabFocus()
  181817. {
  181818. const bool oldDeactivate = shouldDeactivateTitleBar;
  181819. shouldDeactivateTitleBar = ((styleFlags & windowIsTemporary) == 0);
  181820. callFunctionIfNotLocked (&setFocusCallback, (void*) hwnd);
  181821. shouldDeactivateTitleBar = oldDeactivate;
  181822. }
  181823. void textInputRequired (const Point<int>&)
  181824. {
  181825. if (! hasCreatedCaret)
  181826. {
  181827. hasCreatedCaret = true;
  181828. CreateCaret (hwnd, (HBITMAP) 1, 0, 0);
  181829. }
  181830. ShowCaret (hwnd);
  181831. SetCaretPos (0, 0);
  181832. }
  181833. void repaint (int x, int y, int w, int h)
  181834. {
  181835. const RECT r = { x, y, x + w, y + h };
  181836. InvalidateRect (hwnd, &r, FALSE);
  181837. }
  181838. void performAnyPendingRepaintsNow()
  181839. {
  181840. MSG m;
  181841. if (component->isVisible() && PeekMessage (&m, hwnd, WM_PAINT, WM_PAINT, PM_REMOVE))
  181842. DispatchMessage (&m);
  181843. }
  181844. static Win32ComponentPeer* getOwnerOfWindow (HWND h) throw()
  181845. {
  181846. if (h != 0 && GetWindowLongPtr (h, GWLP_USERDATA) == improbableWindowNumber)
  181847. return (Win32ComponentPeer*) (pointer_sized_int) GetWindowLongPtr (h, 8);
  181848. return 0;
  181849. }
  181850. void setTaskBarIcon (const Image* const image)
  181851. {
  181852. if (image != 0)
  181853. {
  181854. HICON hicon = createHICONFromImage (*image, TRUE, 0, 0);
  181855. if (taskBarIcon == 0)
  181856. {
  181857. taskBarIcon = new NOTIFYICONDATA();
  181858. taskBarIcon->cbSize = sizeof (NOTIFYICONDATA);
  181859. taskBarIcon->hWnd = (HWND) hwnd;
  181860. taskBarIcon->uID = (int) (pointer_sized_int) hwnd;
  181861. taskBarIcon->uFlags = NIF_ICON | NIF_MESSAGE | NIF_TIP;
  181862. taskBarIcon->uCallbackMessage = WM_TRAYNOTIFY;
  181863. taskBarIcon->hIcon = hicon;
  181864. taskBarIcon->szTip[0] = 0;
  181865. Shell_NotifyIcon (NIM_ADD, taskBarIcon);
  181866. }
  181867. else
  181868. {
  181869. HICON oldIcon = taskBarIcon->hIcon;
  181870. taskBarIcon->hIcon = hicon;
  181871. taskBarIcon->uFlags = NIF_ICON;
  181872. Shell_NotifyIcon (NIM_MODIFY, taskBarIcon);
  181873. DestroyIcon (oldIcon);
  181874. }
  181875. DestroyIcon (hicon);
  181876. }
  181877. else if (taskBarIcon != 0)
  181878. {
  181879. taskBarIcon->uFlags = 0;
  181880. Shell_NotifyIcon (NIM_DELETE, taskBarIcon);
  181881. DestroyIcon (taskBarIcon->hIcon);
  181882. deleteAndZero (taskBarIcon);
  181883. }
  181884. }
  181885. void setTaskBarIconToolTip (const String& toolTip) const
  181886. {
  181887. if (taskBarIcon != 0)
  181888. {
  181889. taskBarIcon->uFlags = NIF_TIP;
  181890. toolTip.copyToUnicode (taskBarIcon->szTip, sizeof (taskBarIcon->szTip) - 1);
  181891. Shell_NotifyIcon (NIM_MODIFY, taskBarIcon);
  181892. }
  181893. }
  181894. bool isInside (HWND h) const
  181895. {
  181896. return GetAncestor (hwnd, GA_ROOT) == h;
  181897. }
  181898. static void updateKeyModifiers() throw()
  181899. {
  181900. int keyMods = 0;
  181901. if (GetKeyState (VK_SHIFT) & 0x8000) keyMods |= ModifierKeys::shiftModifier;
  181902. if (GetKeyState (VK_CONTROL) & 0x8000) keyMods |= ModifierKeys::ctrlModifier;
  181903. if (GetKeyState (VK_MENU) & 0x8000) keyMods |= ModifierKeys::altModifier;
  181904. if (GetKeyState (VK_RMENU) & 0x8000) keyMods &= ~(ModifierKeys::ctrlModifier | ModifierKeys::altModifier);
  181905. currentModifiers = currentModifiers.withOnlyMouseButtons().withFlags (keyMods);
  181906. }
  181907. static void updateModifiersFromWParam (const WPARAM wParam)
  181908. {
  181909. int mouseMods = 0;
  181910. if (wParam & MK_LBUTTON) mouseMods |= ModifierKeys::leftButtonModifier;
  181911. if (wParam & MK_RBUTTON) mouseMods |= ModifierKeys::rightButtonModifier;
  181912. if (wParam & MK_MBUTTON) mouseMods |= ModifierKeys::middleButtonModifier;
  181913. currentModifiers = currentModifiers.withoutMouseButtons().withFlags (mouseMods);
  181914. updateKeyModifiers();
  181915. }
  181916. static int64 getMouseEventTime()
  181917. {
  181918. static int64 eventTimeOffset = 0;
  181919. static DWORD lastMessageTime = 0;
  181920. const DWORD thisMessageTime = GetMessageTime();
  181921. if (thisMessageTime < lastMessageTime || lastMessageTime == 0)
  181922. {
  181923. lastMessageTime = thisMessageTime;
  181924. eventTimeOffset = Time::currentTimeMillis() - thisMessageTime;
  181925. }
  181926. return eventTimeOffset + thisMessageTime;
  181927. }
  181928. juce_UseDebuggingNewOperator
  181929. bool dontRepaint;
  181930. static ModifierKeys currentModifiers;
  181931. static ModifierKeys modifiersAtLastCallback;
  181932. private:
  181933. HWND hwnd;
  181934. DropShadower* shadower;
  181935. bool fullScreen, isDragging, isMouseOver, hasCreatedCaret;
  181936. BorderSize windowBorder;
  181937. HICON currentWindowIcon;
  181938. NOTIFYICONDATA* taskBarIcon;
  181939. IDropTarget* dropTarget;
  181940. class TemporaryImage : public Timer
  181941. {
  181942. public:
  181943. TemporaryImage()
  181944. : image (0)
  181945. {
  181946. }
  181947. ~TemporaryImage()
  181948. {
  181949. delete image;
  181950. }
  181951. WindowsBitmapImage* getImage (const bool transparent, const int w, const int h) throw()
  181952. {
  181953. const Image::PixelFormat format = transparent ? Image::ARGB : Image::RGB;
  181954. if (image == 0 || image->getWidth() < w || image->getHeight() < h || image->getFormat() != format)
  181955. {
  181956. delete image;
  181957. image = new WindowsBitmapImage (format, (w + 31) & ~31, (h + 31) & ~31, false);
  181958. }
  181959. startTimer (3000);
  181960. return image;
  181961. }
  181962. void timerCallback()
  181963. {
  181964. stopTimer();
  181965. deleteAndZero (image);
  181966. }
  181967. private:
  181968. WindowsBitmapImage* image;
  181969. TemporaryImage (const TemporaryImage&);
  181970. TemporaryImage& operator= (const TemporaryImage&);
  181971. };
  181972. TemporaryImage offscreenImageGenerator;
  181973. class WindowClassHolder : public DeletedAtShutdown
  181974. {
  181975. public:
  181976. WindowClassHolder()
  181977. : windowClassName ("JUCE_")
  181978. {
  181979. // this name has to be different for each app/dll instance because otherwise
  181980. // poor old Win32 can get a bit confused (even despite it not being a process-global
  181981. // window class).
  181982. windowClassName << (int) (Time::currentTimeMillis() & 0x7fffffff);
  181983. HINSTANCE moduleHandle = (HINSTANCE) PlatformUtilities::getCurrentModuleInstanceHandle();
  181984. TCHAR moduleFile [1024];
  181985. moduleFile[0] = 0;
  181986. GetModuleFileName (moduleHandle, moduleFile, 1024);
  181987. WORD iconNum = 0;
  181988. WNDCLASSEX wcex;
  181989. wcex.cbSize = sizeof (wcex);
  181990. wcex.style = CS_OWNDC;
  181991. wcex.lpfnWndProc = (WNDPROC) windowProc;
  181992. wcex.lpszClassName = windowClassName;
  181993. wcex.cbClsExtra = 0;
  181994. wcex.cbWndExtra = 32;
  181995. wcex.hInstance = moduleHandle;
  181996. wcex.hIcon = ExtractAssociatedIcon (moduleHandle, moduleFile, &iconNum);
  181997. iconNum = 1;
  181998. wcex.hIconSm = ExtractAssociatedIcon (moduleHandle, moduleFile, &iconNum);
  181999. wcex.hCursor = 0;
  182000. wcex.hbrBackground = 0;
  182001. wcex.lpszMenuName = 0;
  182002. RegisterClassEx (&wcex);
  182003. }
  182004. ~WindowClassHolder()
  182005. {
  182006. if (ComponentPeer::getNumPeers() == 0)
  182007. UnregisterClass (windowClassName, (HINSTANCE) PlatformUtilities::getCurrentModuleInstanceHandle());
  182008. clearSingletonInstance();
  182009. }
  182010. String windowClassName;
  182011. juce_DeclareSingleton_SingleThreaded_Minimal (WindowClassHolder);
  182012. };
  182013. static void* createWindowCallback (void* userData)
  182014. {
  182015. ((Win32ComponentPeer*) userData)->createWindow();
  182016. return 0;
  182017. }
  182018. void createWindow()
  182019. {
  182020. DWORD exstyle = WS_EX_ACCEPTFILES;
  182021. DWORD type = WS_CLIPSIBLINGS | WS_CLIPCHILDREN;
  182022. if (hasTitleBar())
  182023. {
  182024. type |= WS_OVERLAPPED;
  182025. exstyle |= WS_EX_APPWINDOW;
  182026. if ((styleFlags & windowHasCloseButton) != 0)
  182027. {
  182028. type |= WS_SYSMENU;
  182029. }
  182030. else
  182031. {
  182032. // annoyingly, windows won't let you have a min/max button without a close button
  182033. jassert ((styleFlags & (windowHasMinimiseButton | windowHasMaximiseButton)) == 0);
  182034. }
  182035. if ((styleFlags & windowIsResizable) != 0)
  182036. type |= WS_THICKFRAME;
  182037. }
  182038. else
  182039. {
  182040. type |= WS_POPUP | WS_SYSMENU;
  182041. if ((styleFlags & windowAppearsOnTaskbar) == 0)
  182042. exstyle |= WS_EX_TOOLWINDOW;
  182043. else
  182044. exstyle |= WS_EX_APPWINDOW;
  182045. }
  182046. if ((styleFlags & windowHasMinimiseButton) != 0)
  182047. type |= WS_MINIMIZEBOX;
  182048. if ((styleFlags & windowHasMaximiseButton) != 0)
  182049. type |= WS_MAXIMIZEBOX;
  182050. if ((styleFlags & windowIgnoresMouseClicks) != 0)
  182051. exstyle |= WS_EX_TRANSPARENT;
  182052. if ((styleFlags & windowIsSemiTransparent) != 0
  182053. && Desktop::canUseSemiTransparentWindows())
  182054. exstyle |= WS_EX_LAYERED;
  182055. hwnd = CreateWindowEx (exstyle, WindowClassHolder::getInstance()->windowClassName, L"", type, 0, 0, 0, 0, 0, 0, 0, 0);
  182056. if (hwnd != 0)
  182057. {
  182058. SetWindowLongPtr (hwnd, 0, 0);
  182059. SetWindowLongPtr (hwnd, 8, (LONG_PTR) this);
  182060. SetWindowLongPtr (hwnd, GWLP_USERDATA, improbableWindowNumber);
  182061. if (dropTarget == 0)
  182062. dropTarget = new JuceDropTarget (this);
  182063. RegisterDragDrop (hwnd, dropTarget);
  182064. updateBorderSize();
  182065. // Calling this function here is (for some reason) necessary to make Windows
  182066. // correctly enable the menu items that we specify in the wm_initmenu message.
  182067. GetSystemMenu (hwnd, false);
  182068. }
  182069. else
  182070. {
  182071. jassertfalse
  182072. }
  182073. }
  182074. static void* destroyWindowCallback (void* handle)
  182075. {
  182076. RevokeDragDrop ((HWND) handle);
  182077. DestroyWindow ((HWND) handle);
  182078. return 0;
  182079. }
  182080. static void* toFrontCallback1 (void* h)
  182081. {
  182082. SetForegroundWindow ((HWND) h);
  182083. return 0;
  182084. }
  182085. static void* toFrontCallback2 (void* h)
  182086. {
  182087. SetWindowPos ((HWND) h, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE | SWP_NOSENDCHANGING);
  182088. return 0;
  182089. }
  182090. static void* setFocusCallback (void* h)
  182091. {
  182092. SetFocus ((HWND) h);
  182093. return 0;
  182094. }
  182095. static void* getFocusCallback (void*)
  182096. {
  182097. return (void*) GetFocus();
  182098. }
  182099. void offsetWithinParent (int& x, int& y) const
  182100. {
  182101. if (isTransparent())
  182102. {
  182103. HWND parentHwnd = GetParent (hwnd);
  182104. if (parentHwnd != 0)
  182105. {
  182106. RECT parentRect;
  182107. GetWindowRect (parentHwnd, &parentRect);
  182108. x += parentRect.left;
  182109. y += parentRect.top;
  182110. }
  182111. }
  182112. }
  182113. bool isTransparent() const
  182114. {
  182115. return (GetWindowLong (hwnd, GWL_EXSTYLE) & WS_EX_LAYERED) != 0;
  182116. }
  182117. inline bool hasTitleBar() const throw() { return (styleFlags & windowHasTitleBar) != 0; }
  182118. void setIcon (const Image& newIcon)
  182119. {
  182120. HICON hicon = createHICONFromImage (newIcon, TRUE, 0, 0);
  182121. if (hicon != 0)
  182122. {
  182123. SendMessage (hwnd, WM_SETICON, ICON_BIG, (LPARAM) hicon);
  182124. SendMessage (hwnd, WM_SETICON, ICON_SMALL, (LPARAM) hicon);
  182125. if (currentWindowIcon != 0)
  182126. DestroyIcon (currentWindowIcon);
  182127. currentWindowIcon = hicon;
  182128. }
  182129. }
  182130. void handlePaintMessage()
  182131. {
  182132. HRGN rgn = CreateRectRgn (0, 0, 0, 0);
  182133. const int regionType = GetUpdateRgn (hwnd, rgn, false);
  182134. PAINTSTRUCT paintStruct;
  182135. HDC dc = BeginPaint (hwnd, &paintStruct); // Note this can immediately generate a WM_NCPAINT
  182136. // message and become re-entrant, but that's OK
  182137. // if something in a paint handler calls, e.g. a message box, this can become reentrant and
  182138. // corrupt the image it's using to paint into, so do a check here.
  182139. static bool reentrant = false;
  182140. if (reentrant)
  182141. {
  182142. DeleteObject (rgn);
  182143. EndPaint (hwnd, &paintStruct);
  182144. return;
  182145. }
  182146. reentrant = true;
  182147. // this is the rectangle to update..
  182148. int x = paintStruct.rcPaint.left;
  182149. int y = paintStruct.rcPaint.top;
  182150. int w = paintStruct.rcPaint.right - x;
  182151. int h = paintStruct.rcPaint.bottom - y;
  182152. const bool transparent = isTransparent();
  182153. if (transparent)
  182154. {
  182155. // it's not possible to have a transparent window with a title bar at the moment!
  182156. jassert (! hasTitleBar());
  182157. RECT r;
  182158. GetWindowRect (hwnd, &r);
  182159. x = y = 0;
  182160. w = r.right - r.left;
  182161. h = r.bottom - r.top;
  182162. }
  182163. if (w > 0 && h > 0)
  182164. {
  182165. clearMaskedRegion();
  182166. WindowsBitmapImage* const offscreenImage = offscreenImageGenerator.getImage (transparent, w, h);
  182167. RectangleList contextClip;
  182168. bool needToPaintAll = true;
  182169. if (regionType == COMPLEXREGION && ! transparent)
  182170. {
  182171. HRGN clipRgn = CreateRectRgnIndirect (&paintStruct.rcPaint);
  182172. CombineRgn (rgn, rgn, clipRgn, RGN_AND);
  182173. DeleteObject (clipRgn);
  182174. char rgnData [8192];
  182175. const DWORD res = GetRegionData (rgn, sizeof (rgnData), (RGNDATA*) rgnData);
  182176. if (res > 0 && res <= sizeof (rgnData))
  182177. {
  182178. const RGNDATAHEADER* const hdr = &(((const RGNDATA*) rgnData)->rdh);
  182179. if (hdr->iType == RDH_RECTANGLES
  182180. && hdr->rcBound.right - hdr->rcBound.left >= w
  182181. && hdr->rcBound.bottom - hdr->rcBound.top >= h)
  182182. {
  182183. needToPaintAll = false;
  182184. const RECT* rects = (const RECT*) (rgnData + sizeof (RGNDATAHEADER));
  182185. int num = ((RGNDATA*) rgnData)->rdh.nCount;
  182186. while (--num >= 0)
  182187. {
  182188. // (need to move this one pixel to the left because of a win32 bug)
  182189. const int cx = jmax (x, (int) rects->left - 1);
  182190. const int cy = rects->top;
  182191. const int cw = rects->right - cx;
  182192. const int ch = rects->bottom - rects->top;
  182193. if (cx + cw - x <= w && cy + ch - y <= h)
  182194. {
  182195. contextClip.addWithoutMerging (Rectangle<int> (cx - x, cy - y, cw, ch));
  182196. }
  182197. else
  182198. {
  182199. needToPaintAll = true;
  182200. break;
  182201. }
  182202. ++rects;
  182203. }
  182204. }
  182205. }
  182206. }
  182207. if (needToPaintAll)
  182208. {
  182209. contextClip.clear();
  182210. contextClip.addWithoutMerging (Rectangle<int> (0, 0, w, h));
  182211. }
  182212. if (transparent)
  182213. {
  182214. RectangleList::Iterator i (contextClip);
  182215. while (i.next())
  182216. {
  182217. const Rectangle<int>& r = *i.getRectangle();
  182218. offscreenImage->clear (r.getX(), r.getY(), r.getWidth(), r.getHeight());
  182219. }
  182220. }
  182221. // if the component's not opaque, this won't draw properly unless the platform can support this
  182222. jassert (Desktop::canUseSemiTransparentWindows() || component->isOpaque());
  182223. updateCurrentModifiers();
  182224. LowLevelGraphicsSoftwareRenderer context (*offscreenImage);
  182225. context.clipToRectangleList (contextClip);
  182226. context.setOrigin (-x, -y);
  182227. handlePaint (context);
  182228. if (! dontRepaint)
  182229. offscreenImage->blitToWindow (hwnd, dc, transparent, x, y, maskedRegion);
  182230. }
  182231. DeleteObject (rgn);
  182232. EndPaint (hwnd, &paintStruct);
  182233. reentrant = false;
  182234. #ifndef JUCE_GCC //xxx should add this fn for gcc..
  182235. _fpreset(); // because some graphics cards can unmask FP exceptions
  182236. #endif
  182237. lastPaintTime = Time::getMillisecondCounter();
  182238. }
  182239. void doMouseEvent (const Point<int>& position)
  182240. {
  182241. handleMouseEvent (0, position, currentModifiers, getMouseEventTime());
  182242. }
  182243. void doMouseMove (const Point<int>& position)
  182244. {
  182245. if (! isMouseOver)
  182246. {
  182247. isMouseOver = true;
  182248. updateKeyModifiers();
  182249. TRACKMOUSEEVENT tme;
  182250. tme.cbSize = sizeof (tme);
  182251. tme.dwFlags = TME_LEAVE;
  182252. tme.hwndTrack = hwnd;
  182253. tme.dwHoverTime = 0;
  182254. if (! TrackMouseEvent (&tme))
  182255. jassertfalse;
  182256. Desktop::getInstance().getMainMouseSource().forceMouseCursorUpdate();
  182257. }
  182258. else if (! isDragging)
  182259. {
  182260. if (! contains (position, false))
  182261. return;
  182262. }
  182263. // (Throttling the incoming queue of mouse-events seems to still be required in XP..)
  182264. static uint32 lastMouseTime = 0;
  182265. const uint32 now = Time::getMillisecondCounter();
  182266. const int maxMouseMovesPerSecond = 60;
  182267. if (now > lastMouseTime + 1000 / maxMouseMovesPerSecond)
  182268. {
  182269. lastMouseTime = now;
  182270. doMouseEvent (position);
  182271. }
  182272. }
  182273. void doMouseDown (const Point<int>& position, const WPARAM wParam)
  182274. {
  182275. if (GetCapture() != hwnd)
  182276. SetCapture (hwnd);
  182277. doMouseMove (position);
  182278. updateModifiersFromWParam (wParam);
  182279. isDragging = true;
  182280. doMouseEvent (position);
  182281. }
  182282. void doMouseUp (const Point<int>& position, const WPARAM wParam)
  182283. {
  182284. updateModifiersFromWParam (wParam);
  182285. isDragging = false;
  182286. // release the mouse capture if the user has released all buttons
  182287. if ((wParam & (MK_LBUTTON | MK_RBUTTON | MK_MBUTTON)) == 0 && hwnd == GetCapture())
  182288. ReleaseCapture();
  182289. doMouseEvent (position);
  182290. }
  182291. void doCaptureChanged()
  182292. {
  182293. if (isDragging)
  182294. doMouseUp (getCurrentMousePos(), (WPARAM) 0);
  182295. }
  182296. void doMouseExit()
  182297. {
  182298. isMouseOver = false;
  182299. doMouseEvent (getCurrentMousePos());
  182300. }
  182301. void doMouseWheel (const Point<int>& position, const WPARAM wParam, const bool isVertical)
  182302. {
  182303. updateKeyModifiers();
  182304. const float amount = jlimit (-1000.0f, 1000.0f, 0.75f * (short) HIWORD (wParam));
  182305. handleMouseWheel (0, position, getMouseEventTime(),
  182306. isVertical ? 0.0f : amount,
  182307. isVertical ? amount : 0.0f);
  182308. }
  182309. void sendModifierKeyChangeIfNeeded()
  182310. {
  182311. if (modifiersAtLastCallback != currentModifiers)
  182312. {
  182313. modifiersAtLastCallback = currentModifiers;
  182314. handleModifierKeysChange();
  182315. }
  182316. }
  182317. bool doKeyUp (const WPARAM key)
  182318. {
  182319. updateKeyModifiers();
  182320. switch (key)
  182321. {
  182322. case VK_SHIFT:
  182323. case VK_CONTROL:
  182324. case VK_MENU:
  182325. case VK_CAPITAL:
  182326. case VK_LWIN:
  182327. case VK_RWIN:
  182328. case VK_APPS:
  182329. case VK_NUMLOCK:
  182330. case VK_SCROLL:
  182331. case VK_LSHIFT:
  182332. case VK_RSHIFT:
  182333. case VK_LCONTROL:
  182334. case VK_LMENU:
  182335. case VK_RCONTROL:
  182336. case VK_RMENU:
  182337. sendModifierKeyChangeIfNeeded();
  182338. }
  182339. return handleKeyUpOrDown (false)
  182340. || Component::getCurrentlyModalComponent() != 0;
  182341. }
  182342. bool doKeyDown (const WPARAM key)
  182343. {
  182344. updateKeyModifiers();
  182345. bool used = false;
  182346. switch (key)
  182347. {
  182348. case VK_SHIFT:
  182349. case VK_LSHIFT:
  182350. case VK_RSHIFT:
  182351. case VK_CONTROL:
  182352. case VK_LCONTROL:
  182353. case VK_RCONTROL:
  182354. case VK_MENU:
  182355. case VK_LMENU:
  182356. case VK_RMENU:
  182357. case VK_LWIN:
  182358. case VK_RWIN:
  182359. case VK_CAPITAL:
  182360. case VK_NUMLOCK:
  182361. case VK_SCROLL:
  182362. case VK_APPS:
  182363. sendModifierKeyChangeIfNeeded();
  182364. break;
  182365. case VK_LEFT:
  182366. case VK_RIGHT:
  182367. case VK_UP:
  182368. case VK_DOWN:
  182369. case VK_PRIOR:
  182370. case VK_NEXT:
  182371. case VK_HOME:
  182372. case VK_END:
  182373. case VK_DELETE:
  182374. case VK_INSERT:
  182375. case VK_F1:
  182376. case VK_F2:
  182377. case VK_F3:
  182378. case VK_F4:
  182379. case VK_F5:
  182380. case VK_F6:
  182381. case VK_F7:
  182382. case VK_F8:
  182383. case VK_F9:
  182384. case VK_F10:
  182385. case VK_F11:
  182386. case VK_F12:
  182387. case VK_F13:
  182388. case VK_F14:
  182389. case VK_F15:
  182390. case VK_F16:
  182391. used = handleKeyUpOrDown (true);
  182392. used = handleKeyPress (extendedKeyModifier | (int) key, 0) || used;
  182393. break;
  182394. case VK_ADD:
  182395. case VK_SUBTRACT:
  182396. case VK_MULTIPLY:
  182397. case VK_DIVIDE:
  182398. case VK_SEPARATOR:
  182399. case VK_DECIMAL:
  182400. used = handleKeyUpOrDown (true);
  182401. break;
  182402. default:
  182403. used = handleKeyUpOrDown (true);
  182404. {
  182405. MSG msg;
  182406. if (! PeekMessage (&msg, hwnd, WM_CHAR, WM_DEADCHAR, PM_NOREMOVE))
  182407. {
  182408. // if there isn't a WM_CHAR or WM_DEADCHAR message pending, we need to
  182409. // manually generate the key-press event that matches this key-down.
  182410. const UINT keyChar = MapVirtualKey (key, 2);
  182411. used = handleKeyPress ((int) LOWORD (keyChar), 0) || used;
  182412. }
  182413. }
  182414. break;
  182415. }
  182416. if (Component::getCurrentlyModalComponent() != 0)
  182417. used = true;
  182418. return used;
  182419. }
  182420. bool doKeyChar (int key, const LPARAM flags)
  182421. {
  182422. updateKeyModifiers();
  182423. juce_wchar textChar = (juce_wchar) key;
  182424. const int virtualScanCode = (flags >> 16) & 0xff;
  182425. if (key >= '0' && key <= '9')
  182426. {
  182427. switch (virtualScanCode) // check for a numeric keypad scan-code
  182428. {
  182429. case 0x52:
  182430. case 0x4f:
  182431. case 0x50:
  182432. case 0x51:
  182433. case 0x4b:
  182434. case 0x4c:
  182435. case 0x4d:
  182436. case 0x47:
  182437. case 0x48:
  182438. case 0x49:
  182439. key = (key - '0') + KeyPress::numberPad0;
  182440. break;
  182441. default:
  182442. break;
  182443. }
  182444. }
  182445. else
  182446. {
  182447. // convert the scan code to an unmodified character code..
  182448. const UINT virtualKey = MapVirtualKey (virtualScanCode, 1);
  182449. UINT keyChar = MapVirtualKey (virtualKey, 2);
  182450. keyChar = LOWORD (keyChar);
  182451. if (keyChar != 0)
  182452. key = (int) keyChar;
  182453. // avoid sending junk text characters for some control-key combinations
  182454. if (textChar < ' ' && currentModifiers.testFlags (ModifierKeys::ctrlModifier | ModifierKeys::altModifier))
  182455. textChar = 0;
  182456. }
  182457. return handleKeyPress (key, textChar);
  182458. }
  182459. bool doAppCommand (const LPARAM lParam)
  182460. {
  182461. int key = 0;
  182462. switch (GET_APPCOMMAND_LPARAM (lParam))
  182463. {
  182464. case APPCOMMAND_MEDIA_PLAY_PAUSE:
  182465. key = KeyPress::playKey;
  182466. break;
  182467. case APPCOMMAND_MEDIA_STOP:
  182468. key = KeyPress::stopKey;
  182469. break;
  182470. case APPCOMMAND_MEDIA_NEXTTRACK:
  182471. key = KeyPress::fastForwardKey;
  182472. break;
  182473. case APPCOMMAND_MEDIA_PREVIOUSTRACK:
  182474. key = KeyPress::rewindKey;
  182475. break;
  182476. }
  182477. if (key != 0)
  182478. {
  182479. updateKeyModifiers();
  182480. if (hwnd == GetActiveWindow())
  182481. {
  182482. handleKeyPress (key, 0);
  182483. return true;
  182484. }
  182485. }
  182486. return false;
  182487. }
  182488. class JuceDropTarget : public IDropTarget
  182489. {
  182490. public:
  182491. JuceDropTarget (Win32ComponentPeer* const owner_)
  182492. : owner (owner_),
  182493. refCount (1)
  182494. {
  182495. }
  182496. virtual ~JuceDropTarget()
  182497. {
  182498. jassert (refCount == 0);
  182499. }
  182500. HRESULT __stdcall QueryInterface (REFIID id, void __RPC_FAR* __RPC_FAR* result)
  182501. {
  182502. if (id == IID_IUnknown || id == IID_IDropTarget)
  182503. {
  182504. AddRef();
  182505. *result = this;
  182506. return S_OK;
  182507. }
  182508. *result = 0;
  182509. return E_NOINTERFACE;
  182510. }
  182511. ULONG __stdcall AddRef() { return ++refCount; }
  182512. ULONG __stdcall Release() { jassert (refCount > 0); const int r = --refCount; if (r == 0) delete this; return r; }
  182513. HRESULT __stdcall DragEnter (IDataObject* pDataObject, DWORD /*grfKeyState*/, POINTL mousePos, DWORD* pdwEffect)
  182514. {
  182515. updateFileList (pDataObject);
  182516. owner->handleFileDragMove (files, owner->globalPositionToRelative (Point<int> (mousePos.x, mousePos.y)));
  182517. *pdwEffect = DROPEFFECT_COPY;
  182518. return S_OK;
  182519. }
  182520. HRESULT __stdcall DragLeave()
  182521. {
  182522. owner->handleFileDragExit (files);
  182523. return S_OK;
  182524. }
  182525. HRESULT __stdcall DragOver (DWORD /*grfKeyState*/, POINTL mousePos, DWORD* pdwEffect)
  182526. {
  182527. owner->handleFileDragMove (files, owner->globalPositionToRelative (Point<int> (mousePos.x, mousePos.y)));
  182528. *pdwEffect = DROPEFFECT_COPY;
  182529. return S_OK;
  182530. }
  182531. HRESULT __stdcall Drop (IDataObject* pDataObject, DWORD /*grfKeyState*/, POINTL mousePos, DWORD* pdwEffect)
  182532. {
  182533. updateFileList (pDataObject);
  182534. owner->handleFileDragDrop (files, owner->globalPositionToRelative (Point<int> (mousePos.x, mousePos.y)));
  182535. *pdwEffect = DROPEFFECT_COPY;
  182536. return S_OK;
  182537. }
  182538. private:
  182539. Win32ComponentPeer* const owner;
  182540. int refCount;
  182541. StringArray files;
  182542. void updateFileList (IDataObject* const pDataObject)
  182543. {
  182544. files.clear();
  182545. FORMATETC format = { CF_HDROP, 0, DVASPECT_CONTENT, -1, TYMED_HGLOBAL };
  182546. STGMEDIUM medium = { TYMED_HGLOBAL, { 0 }, 0 };
  182547. if (pDataObject->GetData (&format, &medium) == S_OK)
  182548. {
  182549. const SIZE_T totalLen = GlobalSize (medium.hGlobal);
  182550. const LPDROPFILES pDropFiles = (const LPDROPFILES) GlobalLock (medium.hGlobal);
  182551. unsigned int i = 0;
  182552. if (pDropFiles->fWide)
  182553. {
  182554. const WCHAR* const fname = (WCHAR*) (((const char*) pDropFiles) + sizeof (DROPFILES));
  182555. for (;;)
  182556. {
  182557. unsigned int len = 0;
  182558. while (i + len < totalLen && fname [i + len] != 0)
  182559. ++len;
  182560. if (len == 0)
  182561. break;
  182562. files.add (String (fname + i, len));
  182563. i += len + 1;
  182564. }
  182565. }
  182566. else
  182567. {
  182568. const char* const fname = ((const char*) pDropFiles) + sizeof (DROPFILES);
  182569. for (;;)
  182570. {
  182571. unsigned int len = 0;
  182572. while (i + len < totalLen && fname [i + len] != 0)
  182573. ++len;
  182574. if (len == 0)
  182575. break;
  182576. files.add (String (fname + i, len));
  182577. i += len + 1;
  182578. }
  182579. }
  182580. GlobalUnlock (medium.hGlobal);
  182581. }
  182582. }
  182583. JuceDropTarget (const JuceDropTarget&);
  182584. JuceDropTarget& operator= (const JuceDropTarget&);
  182585. };
  182586. void doSettingChange()
  182587. {
  182588. Desktop::getInstance().refreshMonitorSizes();
  182589. if (fullScreen && ! isMinimised())
  182590. {
  182591. const Rectangle<int> r (component->getParentMonitorArea());
  182592. SetWindowPos (hwnd, 0,
  182593. r.getX(), r.getY(), r.getWidth(), r.getHeight(),
  182594. SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOZORDER | SWP_NOSENDCHANGING);
  182595. }
  182596. }
  182597. public:
  182598. static LRESULT CALLBACK windowProc (HWND h, UINT message, WPARAM wParam, LPARAM lParam)
  182599. {
  182600. Win32ComponentPeer* const peer = getOwnerOfWindow (h);
  182601. if (peer != 0)
  182602. return peer->peerWindowProc (h, message, wParam, lParam);
  182603. return DefWindowProcW (h, message, wParam, lParam);
  182604. }
  182605. private:
  182606. static const Point<int> getPointFromLParam (LPARAM lParam) throw()
  182607. {
  182608. return Point<int> (GET_X_LPARAM (lParam), GET_Y_LPARAM (lParam));
  182609. }
  182610. const Point<int> getCurrentMousePos() throw()
  182611. {
  182612. RECT wr;
  182613. GetWindowRect (hwnd, &wr);
  182614. const DWORD mp = GetMessagePos();
  182615. return Point<int> (GET_X_LPARAM (mp) - wr.left - windowBorder.getLeft(),
  182616. GET_Y_LPARAM (mp) - wr.top - windowBorder.getTop());
  182617. }
  182618. LRESULT peerWindowProc (HWND h, UINT message, WPARAM wParam, LPARAM lParam)
  182619. {
  182620. if (isValidPeer (this))
  182621. {
  182622. switch (message)
  182623. {
  182624. case WM_NCHITTEST:
  182625. if ((styleFlags & windowIgnoresMouseClicks) != 0)
  182626. return HTTRANSPARENT;
  182627. if (hasTitleBar())
  182628. break;
  182629. return HTCLIENT;
  182630. case WM_PAINT:
  182631. handlePaintMessage();
  182632. return 0;
  182633. case WM_NCPAINT:
  182634. if (wParam != 1)
  182635. handlePaintMessage();
  182636. if (hasTitleBar())
  182637. break;
  182638. return 0;
  182639. case WM_ERASEBKGND:
  182640. case WM_NCCALCSIZE:
  182641. if (hasTitleBar())
  182642. break;
  182643. return 1;
  182644. case WM_MOUSEMOVE:
  182645. doMouseMove (getPointFromLParam (lParam));
  182646. return 0;
  182647. case WM_MOUSELEAVE:
  182648. doMouseExit();
  182649. return 0;
  182650. case WM_LBUTTONDOWN:
  182651. case WM_MBUTTONDOWN:
  182652. case WM_RBUTTONDOWN:
  182653. doMouseDown (getPointFromLParam (lParam), wParam);
  182654. return 0;
  182655. case WM_LBUTTONUP:
  182656. case WM_MBUTTONUP:
  182657. case WM_RBUTTONUP:
  182658. doMouseUp (getPointFromLParam (lParam), wParam);
  182659. return 0;
  182660. case WM_CAPTURECHANGED:
  182661. doCaptureChanged();
  182662. return 0;
  182663. case WM_NCMOUSEMOVE:
  182664. if (hasTitleBar())
  182665. break;
  182666. return 0;
  182667. case 0x020A: /* WM_MOUSEWHEEL */
  182668. doMouseWheel (getCurrentMousePos(), wParam, true);
  182669. return 0;
  182670. case 0x020E: /* WM_MOUSEHWHEEL */
  182671. doMouseWheel (getCurrentMousePos(), wParam, false);
  182672. return 0;
  182673. case WM_WINDOWPOSCHANGING:
  182674. if ((styleFlags & (windowHasTitleBar | windowIsResizable)) == (windowHasTitleBar | windowIsResizable))
  182675. {
  182676. WINDOWPOS* const wp = (WINDOWPOS*) lParam;
  182677. if ((wp->flags & (SWP_NOMOVE | SWP_NOSIZE)) != (SWP_NOMOVE | SWP_NOSIZE))
  182678. {
  182679. if (constrainer != 0)
  182680. {
  182681. const Rectangle<int> current (component->getX() - windowBorder.getLeft(),
  182682. component->getY() - windowBorder.getTop(),
  182683. component->getWidth() + windowBorder.getLeftAndRight(),
  182684. component->getHeight() + windowBorder.getTopAndBottom());
  182685. Rectangle<int> pos (wp->x, wp->y, wp->cx, wp->cy);
  182686. constrainer->checkBounds (pos, current,
  182687. Desktop::getInstance().getAllMonitorDisplayAreas().getBounds(),
  182688. pos.getY() != current.getY() && pos.getBottom() == current.getBottom(),
  182689. pos.getX() != current.getX() && pos.getRight() == current.getRight(),
  182690. pos.getY() == current.getY() && pos.getBottom() != current.getBottom(),
  182691. pos.getX() == current.getX() && pos.getRight() != current.getRight());
  182692. wp->x = pos.getX();
  182693. wp->y = pos.getY();
  182694. wp->cx = pos.getWidth();
  182695. wp->cy = pos.getHeight();
  182696. }
  182697. }
  182698. }
  182699. return 0;
  182700. case WM_WINDOWPOSCHANGED:
  182701. handleMovedOrResized();
  182702. if (dontRepaint)
  182703. break; // needed for non-accelerated openGL windows to draw themselves correctly..
  182704. return 0;
  182705. case WM_KEYDOWN:
  182706. case WM_SYSKEYDOWN:
  182707. if (doKeyDown (wParam))
  182708. return 0;
  182709. break;
  182710. case WM_KEYUP:
  182711. case WM_SYSKEYUP:
  182712. if (doKeyUp (wParam))
  182713. return 0;
  182714. break;
  182715. case WM_CHAR:
  182716. if (doKeyChar ((int) wParam, lParam))
  182717. return 0;
  182718. break;
  182719. case WM_APPCOMMAND:
  182720. if (doAppCommand (lParam))
  182721. return TRUE;
  182722. break;
  182723. case WM_SETFOCUS:
  182724. updateKeyModifiers();
  182725. handleFocusGain();
  182726. break;
  182727. case WM_KILLFOCUS:
  182728. if (hasCreatedCaret)
  182729. {
  182730. hasCreatedCaret = false;
  182731. DestroyCaret();
  182732. }
  182733. handleFocusLoss();
  182734. break;
  182735. case WM_ACTIVATEAPP:
  182736. // Windows does weird things to process priority when you swap apps,
  182737. // so this forces an update when the app is brought to the front
  182738. if (wParam != FALSE)
  182739. juce_repeatLastProcessPriority();
  182740. else
  182741. Desktop::getInstance().setKioskModeComponent (0); // turn kiosk mode off if we lose focus
  182742. juce_CheckCurrentlyFocusedTopLevelWindow();
  182743. modifiersAtLastCallback = -1;
  182744. return 0;
  182745. case WM_ACTIVATE:
  182746. if (LOWORD (wParam) == WA_ACTIVE || LOWORD (wParam) == WA_CLICKACTIVE)
  182747. {
  182748. modifiersAtLastCallback = -1;
  182749. updateKeyModifiers();
  182750. if (isMinimised())
  182751. {
  182752. component->repaint();
  182753. handleMovedOrResized();
  182754. if (! ComponentPeer::isValidPeer (this))
  182755. return 0;
  182756. }
  182757. if (LOWORD (wParam) == WA_CLICKACTIVE
  182758. && component->isCurrentlyBlockedByAnotherModalComponent())
  182759. {
  182760. const Point<int> mousePos (component->getMouseXYRelative());
  182761. Component* const underMouse = component->getComponentAt (mousePos.getX(), mousePos.getY());
  182762. if (underMouse != 0 && underMouse->isCurrentlyBlockedByAnotherModalComponent())
  182763. Component::getCurrentlyModalComponent()->inputAttemptWhenModal();
  182764. return 0;
  182765. }
  182766. handleBroughtToFront();
  182767. if (component->isCurrentlyBlockedByAnotherModalComponent())
  182768. Component::getCurrentlyModalComponent()->toFront (true);
  182769. return 0;
  182770. }
  182771. break;
  182772. case WM_NCACTIVATE:
  182773. // while a temporary window is being shown, prevent Windows from deactivating the
  182774. // title bars of our main windows.
  182775. if (wParam == 0 && ! shouldDeactivateTitleBar)
  182776. wParam = TRUE; // change this and let it get passed to the DefWindowProc.
  182777. break;
  182778. case WM_MOUSEACTIVATE:
  182779. if (! component->getMouseClickGrabsKeyboardFocus())
  182780. return MA_NOACTIVATE;
  182781. break;
  182782. case WM_SHOWWINDOW:
  182783. if (wParam != 0)
  182784. handleBroughtToFront();
  182785. break;
  182786. case WM_CLOSE:
  182787. if (! component->isCurrentlyBlockedByAnotherModalComponent())
  182788. handleUserClosingWindow();
  182789. return 0;
  182790. case WM_QUERYENDSESSION:
  182791. if (JUCEApplication::getInstance() != 0)
  182792. {
  182793. JUCEApplication::getInstance()->systemRequestedQuit();
  182794. return MessageManager::getInstance()->hasStopMessageBeenSent();
  182795. }
  182796. return TRUE;
  182797. case WM_TRAYNOTIFY:
  182798. if (component->isCurrentlyBlockedByAnotherModalComponent())
  182799. {
  182800. if (lParam == WM_LBUTTONDOWN || lParam == WM_RBUTTONDOWN
  182801. || lParam == WM_LBUTTONDBLCLK || lParam == WM_LBUTTONDBLCLK)
  182802. {
  182803. Component* const current = Component::getCurrentlyModalComponent();
  182804. if (current != 0)
  182805. current->inputAttemptWhenModal();
  182806. }
  182807. }
  182808. else
  182809. {
  182810. ModifierKeys eventMods (ModifierKeys::getCurrentModifiersRealtime());
  182811. if (lParam == WM_LBUTTONDOWN || lParam == WM_LBUTTONDBLCLK)
  182812. eventMods = eventMods.withFlags (ModifierKeys::leftButtonModifier);
  182813. else if (lParam == WM_RBUTTONDOWN || lParam == WM_RBUTTONDBLCLK)
  182814. eventMods = eventMods.withFlags (ModifierKeys::rightButtonModifier);
  182815. else if (lParam == WM_LBUTTONUP || lParam == WM_RBUTTONUP)
  182816. eventMods = eventMods.withoutMouseButtons();
  182817. const MouseEvent e (Desktop::getInstance().getMainMouseSource(),
  182818. Point<int>(), eventMods, component, getMouseEventTime(),
  182819. Point<int>(), getMouseEventTime(), 1, false);
  182820. if (lParam == WM_LBUTTONDOWN || lParam == WM_RBUTTONDOWN)
  182821. {
  182822. SetFocus (hwnd);
  182823. SetForegroundWindow (hwnd);
  182824. component->mouseDown (e);
  182825. }
  182826. else if (lParam == WM_LBUTTONUP || lParam == WM_RBUTTONUP)
  182827. {
  182828. component->mouseUp (e);
  182829. }
  182830. else if (lParam == WM_LBUTTONDBLCLK || lParam == WM_LBUTTONDBLCLK)
  182831. {
  182832. component->mouseDoubleClick (e);
  182833. }
  182834. else if (lParam == WM_MOUSEMOVE)
  182835. {
  182836. component->mouseMove (e);
  182837. }
  182838. }
  182839. break;
  182840. case WM_SYNCPAINT:
  182841. return 0;
  182842. case WM_PALETTECHANGED:
  182843. InvalidateRect (h, 0, 0);
  182844. break;
  182845. case WM_DISPLAYCHANGE:
  182846. InvalidateRect (h, 0, 0);
  182847. createPaletteIfNeeded = true;
  182848. // intentional fall-through...
  182849. case WM_SETTINGCHANGE: // note the fall-through in the previous case!
  182850. doSettingChange();
  182851. break;
  182852. case WM_INITMENU:
  182853. if (! hasTitleBar())
  182854. {
  182855. if (isFullScreen())
  182856. {
  182857. EnableMenuItem ((HMENU) wParam, SC_RESTORE, MF_BYCOMMAND | MF_ENABLED);
  182858. EnableMenuItem ((HMENU) wParam, SC_MOVE, MF_BYCOMMAND | MF_GRAYED);
  182859. }
  182860. else if (! isMinimised())
  182861. {
  182862. EnableMenuItem ((HMENU) wParam, SC_MAXIMIZE, MF_BYCOMMAND | MF_GRAYED);
  182863. }
  182864. }
  182865. break;
  182866. case WM_SYSCOMMAND:
  182867. switch (wParam & 0xfff0)
  182868. {
  182869. case SC_CLOSE:
  182870. if (sendInputAttemptWhenModalMessage())
  182871. return 0;
  182872. if (hasTitleBar())
  182873. {
  182874. PostMessage (h, WM_CLOSE, 0, 0);
  182875. return 0;
  182876. }
  182877. break;
  182878. case SC_KEYMENU:
  182879. // (NB mustn't call sendInputAttemptWhenModalMessage() here because of very
  182880. // obscure situations that can arise if a modal loop is started from an alt-key
  182881. // keypress).
  182882. if (hasTitleBar() && h == GetCapture())
  182883. ReleaseCapture();
  182884. break;
  182885. case SC_MAXIMIZE:
  182886. if (sendInputAttemptWhenModalMessage())
  182887. return 0;
  182888. setFullScreen (true);
  182889. return 0;
  182890. case SC_MINIMIZE:
  182891. if (sendInputAttemptWhenModalMessage())
  182892. return 0;
  182893. if (! hasTitleBar())
  182894. {
  182895. setMinimised (true);
  182896. return 0;
  182897. }
  182898. break;
  182899. case SC_RESTORE:
  182900. if (sendInputAttemptWhenModalMessage())
  182901. return 0;
  182902. if (hasTitleBar())
  182903. {
  182904. if (isFullScreen())
  182905. {
  182906. setFullScreen (false);
  182907. return 0;
  182908. }
  182909. }
  182910. else
  182911. {
  182912. if (isMinimised())
  182913. setMinimised (false);
  182914. else if (isFullScreen())
  182915. setFullScreen (false);
  182916. return 0;
  182917. }
  182918. break;
  182919. }
  182920. break;
  182921. case WM_NCLBUTTONDOWN:
  182922. case WM_NCRBUTTONDOWN:
  182923. case WM_NCMBUTTONDOWN:
  182924. sendInputAttemptWhenModalMessage();
  182925. break;
  182926. //case WM_IME_STARTCOMPOSITION;
  182927. // return 0;
  182928. case WM_GETDLGCODE:
  182929. return DLGC_WANTALLKEYS;
  182930. default:
  182931. break;
  182932. }
  182933. }
  182934. return DefWindowProcW (h, message, wParam, lParam);
  182935. }
  182936. bool sendInputAttemptWhenModalMessage()
  182937. {
  182938. if (component->isCurrentlyBlockedByAnotherModalComponent())
  182939. {
  182940. Component* const current = Component::getCurrentlyModalComponent();
  182941. if (current != 0)
  182942. current->inputAttemptWhenModal();
  182943. return true;
  182944. }
  182945. return false;
  182946. }
  182947. Win32ComponentPeer (const Win32ComponentPeer&);
  182948. Win32ComponentPeer& operator= (const Win32ComponentPeer&);
  182949. };
  182950. ModifierKeys Win32ComponentPeer::currentModifiers;
  182951. ModifierKeys Win32ComponentPeer::modifiersAtLastCallback;
  182952. ComponentPeer* Component::createNewPeer (int styleFlags, void* /*nativeWindowToAttachTo*/)
  182953. {
  182954. return new Win32ComponentPeer (this, styleFlags);
  182955. }
  182956. juce_ImplementSingleton_SingleThreaded (Win32ComponentPeer::WindowClassHolder);
  182957. void ModifierKeys::updateCurrentModifiers() throw()
  182958. {
  182959. currentModifiers = Win32ComponentPeer::currentModifiers;
  182960. }
  182961. const ModifierKeys ModifierKeys::getCurrentModifiersRealtime() throw()
  182962. {
  182963. Win32ComponentPeer::updateKeyModifiers();
  182964. int keyMods = 0;
  182965. if ((GetKeyState (VK_LBUTTON) & 0x8000) != 0) keyMods |= ModifierKeys::leftButtonModifier;
  182966. if ((GetKeyState (VK_RBUTTON) & 0x8000) != 0) keyMods |= ModifierKeys::rightButtonModifier;
  182967. if ((GetKeyState (VK_MBUTTON) & 0x8000) != 0) keyMods |= ModifierKeys::middleButtonModifier;
  182968. Win32ComponentPeer::currentModifiers
  182969. = Win32ComponentPeer::currentModifiers.withOnlyMouseButtons().withFlags (keyMods);
  182970. return Win32ComponentPeer::currentModifiers;
  182971. }
  182972. void SystemTrayIconComponent::setIconImage (const Image& newImage)
  182973. {
  182974. Win32ComponentPeer* const wp = dynamic_cast <Win32ComponentPeer*> (getPeer());
  182975. if (wp != 0)
  182976. wp->setTaskBarIcon (&newImage);
  182977. }
  182978. void SystemTrayIconComponent::setIconTooltip (const String& tooltip)
  182979. {
  182980. Win32ComponentPeer* const wp = dynamic_cast <Win32ComponentPeer*> (getPeer());
  182981. if (wp != 0)
  182982. wp->setTaskBarIconToolTip (tooltip);
  182983. }
  182984. void juce_setWindowStyleBit (HWND h, const int styleType, const int feature, const bool bitIsSet) throw()
  182985. {
  182986. DWORD val = GetWindowLong (h, styleType);
  182987. if (bitIsSet)
  182988. val |= feature;
  182989. else
  182990. val &= ~feature;
  182991. SetWindowLongPtr (h, styleType, val);
  182992. SetWindowPos (h, 0, 0, 0, 0, 0,
  182993. SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER
  182994. | SWP_NOOWNERZORDER | SWP_FRAMECHANGED | SWP_NOSENDCHANGING);
  182995. }
  182996. bool Process::isForegroundProcess()
  182997. {
  182998. HWND fg = GetForegroundWindow();
  182999. if (fg == 0)
  183000. return true;
  183001. // when running as a plugin in IE8, the browser UI runs in a different process to the plugin, so
  183002. // process ID isn't a reliable way to check if the foreground window belongs to us - instead, we
  183003. // have to see if any of our windows are children of the foreground window
  183004. fg = GetAncestor (fg, GA_ROOT);
  183005. for (int i = ComponentPeer::getNumPeers(); --i >= 0;)
  183006. {
  183007. Win32ComponentPeer* const wp = dynamic_cast <Win32ComponentPeer*> (ComponentPeer::getPeer (i));
  183008. if (wp != 0 && wp->isInside (fg))
  183009. return true;
  183010. }
  183011. return false;
  183012. }
  183013. bool AlertWindow::showNativeDialogBox (const String& title,
  183014. const String& bodyText,
  183015. bool isOkCancel)
  183016. {
  183017. return MessageBox (0, bodyText, title,
  183018. MB_SETFOREGROUND | (isOkCancel ? MB_OKCANCEL
  183019. : MB_OK)) == IDOK;
  183020. }
  183021. void Desktop::createMouseInputSources()
  183022. {
  183023. mouseSources.add (new MouseInputSource (0, true));
  183024. }
  183025. const Point<int> Desktop::getMousePosition()
  183026. {
  183027. POINT mousePos;
  183028. GetCursorPos (&mousePos);
  183029. return Point<int> (mousePos.x, mousePos.y);
  183030. }
  183031. void Desktop::setMousePosition (const Point<int>& newPosition)
  183032. {
  183033. SetCursorPos (newPosition.getX(), newPosition.getY());
  183034. }
  183035. Image* Image::createNativeImage (const PixelFormat format, const int imageWidth, const int imageHeight, const bool clearImage)
  183036. {
  183037. return new Image (format, imageWidth, imageHeight, clearImage);
  183038. }
  183039. class ScreenSaverDefeater : public Timer,
  183040. public DeletedAtShutdown
  183041. {
  183042. public:
  183043. ScreenSaverDefeater() throw()
  183044. {
  183045. startTimer (10000);
  183046. timerCallback();
  183047. }
  183048. ~ScreenSaverDefeater() {}
  183049. void timerCallback()
  183050. {
  183051. if (Process::isForegroundProcess())
  183052. {
  183053. // simulate a shift key getting pressed..
  183054. INPUT input[2];
  183055. input[0].type = INPUT_KEYBOARD;
  183056. input[0].ki.wVk = VK_SHIFT;
  183057. input[0].ki.dwFlags = 0;
  183058. input[0].ki.dwExtraInfo = 0;
  183059. input[1].type = INPUT_KEYBOARD;
  183060. input[1].ki.wVk = VK_SHIFT;
  183061. input[1].ki.dwFlags = KEYEVENTF_KEYUP;
  183062. input[1].ki.dwExtraInfo = 0;
  183063. SendInput (2, input, sizeof (INPUT));
  183064. }
  183065. }
  183066. };
  183067. static ScreenSaverDefeater* screenSaverDefeater = 0;
  183068. void Desktop::setScreenSaverEnabled (const bool isEnabled) throw()
  183069. {
  183070. if (isEnabled)
  183071. {
  183072. deleteAndZero (screenSaverDefeater);
  183073. }
  183074. else if (screenSaverDefeater == 0)
  183075. {
  183076. screenSaverDefeater = new ScreenSaverDefeater();
  183077. }
  183078. }
  183079. bool Desktop::isScreenSaverEnabled() throw()
  183080. {
  183081. return screenSaverDefeater == 0;
  183082. }
  183083. void juce_setKioskComponent (Component* kioskModeComponent, bool enableOrDisable, bool /*allowMenusAndBars*/)
  183084. {
  183085. if (enableOrDisable)
  183086. kioskModeComponent->setBounds (Desktop::getInstance().getMainMonitorArea (false));
  183087. }
  183088. static BOOL CALLBACK enumMonitorsProc (HMONITOR, HDC, LPRECT r, LPARAM userInfo)
  183089. {
  183090. Array <Rectangle<int> >* const monitorCoords = (Array <Rectangle<int> >*) userInfo;
  183091. monitorCoords->add (Rectangle<int> (r->left, r->top, r->right - r->left, r->bottom - r->top));
  183092. return TRUE;
  183093. }
  183094. void juce_updateMultiMonitorInfo (Array <Rectangle<int> >& monitorCoords, const bool clipToWorkArea)
  183095. {
  183096. EnumDisplayMonitors (0, 0, &enumMonitorsProc, (LPARAM) &monitorCoords);
  183097. // make sure the first in the list is the main monitor
  183098. for (int i = 1; i < monitorCoords.size(); ++i)
  183099. if (monitorCoords[i].getX() == 0 && monitorCoords[i].getY() == 0)
  183100. monitorCoords.swap (i, 0);
  183101. if (monitorCoords.size() == 0)
  183102. {
  183103. RECT r;
  183104. GetWindowRect (GetDesktopWindow(), &r);
  183105. monitorCoords.add (Rectangle<int> (r.left, r.top, r.right - r.left, r.bottom - r.top));
  183106. }
  183107. if (clipToWorkArea)
  183108. {
  183109. // clip the main monitor to the active non-taskbar area
  183110. RECT r;
  183111. SystemParametersInfo (SPI_GETWORKAREA, 0, &r, 0);
  183112. Rectangle<int>& screen = monitorCoords.getReference (0);
  183113. screen.setPosition (jmax (screen.getX(), (int) r.left),
  183114. jmax (screen.getY(), (int) r.top));
  183115. screen.setSize (jmin (screen.getRight(), (int) r.right) - screen.getX(),
  183116. jmin (screen.getBottom(), (int) r.bottom) - screen.getY());
  183117. }
  183118. }
  183119. static Image* createImageFromHBITMAP (HBITMAP bitmap) throw()
  183120. {
  183121. Image* im = 0;
  183122. if (bitmap != 0)
  183123. {
  183124. BITMAP bm;
  183125. if (GetObject (bitmap, sizeof (BITMAP), &bm)
  183126. && bm.bmWidth > 0 && bm.bmHeight > 0)
  183127. {
  183128. HDC tempDC = GetDC (0);
  183129. HDC dc = CreateCompatibleDC (tempDC);
  183130. ReleaseDC (0, tempDC);
  183131. SelectObject (dc, bitmap);
  183132. im = new Image (Image::ARGB, bm.bmWidth, bm.bmHeight, true);
  183133. for (int y = bm.bmHeight; --y >= 0;)
  183134. {
  183135. for (int x = bm.bmWidth; --x >= 0;)
  183136. {
  183137. COLORREF col = GetPixel (dc, x, y);
  183138. im->setPixelAt (x, y, Colour ((uint8) GetRValue (col),
  183139. (uint8) GetGValue (col),
  183140. (uint8) GetBValue (col)));
  183141. }
  183142. }
  183143. DeleteDC (dc);
  183144. }
  183145. }
  183146. return im;
  183147. }
  183148. static Image* createImageFromHICON (HICON icon) throw()
  183149. {
  183150. ICONINFO info;
  183151. if (GetIconInfo (icon, &info))
  183152. {
  183153. Image* const mask = createImageFromHBITMAP (info.hbmMask);
  183154. if (mask == 0)
  183155. return 0;
  183156. Image* const image = createImageFromHBITMAP (info.hbmColor);
  183157. if (image == 0)
  183158. return mask;
  183159. for (int y = image->getHeight(); --y >= 0;)
  183160. {
  183161. for (int x = image->getWidth(); --x >= 0;)
  183162. {
  183163. const float brightness = mask->getPixelAt (x, y).getBrightness();
  183164. if (brightness > 0.0f)
  183165. image->multiplyAlphaAt (x, y, 1.0f - brightness);
  183166. }
  183167. }
  183168. delete mask;
  183169. return image;
  183170. }
  183171. return 0;
  183172. }
  183173. static HICON createHICONFromImage (const Image& image, const BOOL isIcon, int hotspotX, int hotspotY) throw()
  183174. {
  183175. HBITMAP mask = CreateBitmap (image.getWidth(), image.getHeight(), 1, 1, 0);
  183176. ICONINFO info;
  183177. info.fIcon = isIcon;
  183178. info.xHotspot = hotspotX;
  183179. info.yHotspot = hotspotY;
  183180. info.hbmMask = mask;
  183181. HICON hi = 0;
  183182. if (SystemStats::getOperatingSystemType() >= SystemStats::WinXP)
  183183. {
  183184. WindowsBitmapImage bitmap (Image::ARGB, image.getWidth(), image.getHeight(), true);
  183185. Graphics g (bitmap);
  183186. g.drawImageAt (&image, 0, 0);
  183187. info.hbmColor = bitmap.hBitmap;
  183188. hi = CreateIconIndirect (&info);
  183189. }
  183190. else
  183191. {
  183192. HBITMAP colour = CreateCompatibleBitmap (GetDC (0), image.getWidth(), image.getHeight());
  183193. HDC colDC = CreateCompatibleDC (GetDC (0));
  183194. HDC alphaDC = CreateCompatibleDC (GetDC (0));
  183195. SelectObject (colDC, colour);
  183196. SelectObject (alphaDC, mask);
  183197. for (int y = image.getHeight(); --y >= 0;)
  183198. {
  183199. for (int x = image.getWidth(); --x >= 0;)
  183200. {
  183201. const Colour c (image.getPixelAt (x, y));
  183202. SetPixel (colDC, x, y, COLORREF (c.getRed() | (c.getGreen() << 8) | (c.getBlue() << 16)));
  183203. SetPixel (alphaDC, x, y, COLORREF (0xffffff - (c.getAlpha() | (c.getAlpha() << 8) | (c.getAlpha() << 16))));
  183204. }
  183205. }
  183206. DeleteDC (colDC);
  183207. DeleteDC (alphaDC);
  183208. info.hbmColor = colour;
  183209. hi = CreateIconIndirect (&info);
  183210. DeleteObject (colour);
  183211. }
  183212. DeleteObject (mask);
  183213. return hi;
  183214. }
  183215. Image* juce_createIconForFile (const File& file)
  183216. {
  183217. Image* image = 0;
  183218. WCHAR filename [1024];
  183219. file.getFullPathName().copyToUnicode (filename, 1023);
  183220. WORD iconNum = 0;
  183221. HICON icon = ExtractAssociatedIcon ((HINSTANCE) PlatformUtilities::getCurrentModuleInstanceHandle(),
  183222. filename, &iconNum);
  183223. if (icon != 0)
  183224. {
  183225. image = createImageFromHICON (icon);
  183226. DestroyIcon (icon);
  183227. }
  183228. return image;
  183229. }
  183230. void* juce_createMouseCursorFromImage (const Image& image, int hotspotX, int hotspotY) throw()
  183231. {
  183232. const int maxW = GetSystemMetrics (SM_CXCURSOR);
  183233. const int maxH = GetSystemMetrics (SM_CYCURSOR);
  183234. const Image* im = &image;
  183235. Image* newIm = 0;
  183236. if (image.getWidth() > maxW || image.getHeight() > maxH)
  183237. {
  183238. im = newIm = image.createCopy (maxW, maxH);
  183239. hotspotX = (hotspotX * maxW) / image.getWidth();
  183240. hotspotY = (hotspotY * maxH) / image.getHeight();
  183241. }
  183242. void* cursorH = 0;
  183243. const SystemStats::OperatingSystemType os = SystemStats::getOperatingSystemType();
  183244. if (os == SystemStats::WinXP)
  183245. {
  183246. cursorH = (void*) createHICONFromImage (*im, FALSE, hotspotX, hotspotY);
  183247. }
  183248. else
  183249. {
  183250. const int stride = (maxW + 7) >> 3;
  183251. HeapBlock <uint8> andPlane, xorPlane;
  183252. andPlane.calloc (stride * maxH);
  183253. xorPlane.calloc (stride * maxH);
  183254. int index = 0;
  183255. for (int y = 0; y < maxH; ++y)
  183256. {
  183257. for (int x = 0; x < maxW; ++x)
  183258. {
  183259. const unsigned char bit = (unsigned char) (1 << (7 - (x & 7)));
  183260. const Colour pixelColour (im->getPixelAt (x, y));
  183261. if (pixelColour.getAlpha() < 127)
  183262. andPlane [index + (x >> 3)] |= bit;
  183263. else if (pixelColour.getBrightness() >= 0.5f)
  183264. xorPlane [index + (x >> 3)] |= bit;
  183265. }
  183266. index += stride;
  183267. }
  183268. cursorH = CreateCursor (0, hotspotX, hotspotY, maxW, maxH, andPlane, xorPlane);
  183269. }
  183270. delete newIm;
  183271. return cursorH;
  183272. }
  183273. void juce_deleteMouseCursor (void* const cursorHandle, const bool isStandard) throw()
  183274. {
  183275. if (cursorHandle != 0 && ! isStandard)
  183276. DestroyCursor ((HCURSOR) cursorHandle);
  183277. }
  183278. void* juce_createStandardMouseCursor (MouseCursor::StandardCursorType type) throw()
  183279. {
  183280. LPCTSTR cursorName = IDC_ARROW;
  183281. switch (type)
  183282. {
  183283. case MouseCursor::NormalCursor:
  183284. cursorName = IDC_ARROW;
  183285. break;
  183286. case MouseCursor::NoCursor:
  183287. return 0;
  183288. case MouseCursor::DraggingHandCursor:
  183289. {
  183290. static void* dragHandCursor = 0;
  183291. if (dragHandCursor == 0)
  183292. {
  183293. static const unsigned char dragHandData[] =
  183294. { 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,
  183295. 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,
  183296. 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 };
  183297. const ScopedPointer <Image> image (ImageFileFormat::loadFrom ((const char*) dragHandData, sizeof (dragHandData)));
  183298. dragHandCursor = juce_createMouseCursorFromImage (*image, 8, 7);
  183299. }
  183300. return dragHandCursor;
  183301. }
  183302. case MouseCursor::WaitCursor:
  183303. cursorName = IDC_WAIT;
  183304. break;
  183305. case MouseCursor::IBeamCursor:
  183306. cursorName = IDC_IBEAM;
  183307. break;
  183308. case MouseCursor::PointingHandCursor:
  183309. cursorName = MAKEINTRESOURCE(32649);
  183310. break;
  183311. case MouseCursor::LeftRightResizeCursor:
  183312. case MouseCursor::LeftEdgeResizeCursor:
  183313. case MouseCursor::RightEdgeResizeCursor:
  183314. cursorName = IDC_SIZEWE;
  183315. break;
  183316. case MouseCursor::UpDownResizeCursor:
  183317. case MouseCursor::TopEdgeResizeCursor:
  183318. case MouseCursor::BottomEdgeResizeCursor:
  183319. cursorName = IDC_SIZENS;
  183320. break;
  183321. case MouseCursor::TopLeftCornerResizeCursor:
  183322. case MouseCursor::BottomRightCornerResizeCursor:
  183323. cursorName = IDC_SIZENWSE;
  183324. break;
  183325. case MouseCursor::TopRightCornerResizeCursor:
  183326. case MouseCursor::BottomLeftCornerResizeCursor:
  183327. cursorName = IDC_SIZENESW;
  183328. break;
  183329. case MouseCursor::UpDownLeftRightResizeCursor:
  183330. cursorName = IDC_SIZEALL;
  183331. break;
  183332. case MouseCursor::CrosshairCursor:
  183333. cursorName = IDC_CROSS;
  183334. break;
  183335. case MouseCursor::CopyingCursor:
  183336. // can't seem to find one of these in the win32 list..
  183337. break;
  183338. }
  183339. HCURSOR cursorH = LoadCursor (0, cursorName);
  183340. if (cursorH == 0)
  183341. cursorH = LoadCursor (0, IDC_ARROW);
  183342. return (void*) cursorH;
  183343. }
  183344. void MouseCursor::showInWindow (ComponentPeer*) const throw()
  183345. {
  183346. SetCursor ((HCURSOR) getHandle());
  183347. }
  183348. void MouseCursor::showInAllWindows() const throw()
  183349. {
  183350. showInWindow (0);
  183351. }
  183352. class JuceDropSource : public IDropSource
  183353. {
  183354. int refCount;
  183355. public:
  183356. JuceDropSource()
  183357. : refCount (1)
  183358. {
  183359. }
  183360. virtual ~JuceDropSource()
  183361. {
  183362. jassert (refCount == 0);
  183363. }
  183364. HRESULT __stdcall QueryInterface (REFIID id, void __RPC_FAR* __RPC_FAR* result)
  183365. {
  183366. if (id == IID_IUnknown || id == IID_IDropSource)
  183367. {
  183368. AddRef();
  183369. *result = this;
  183370. return S_OK;
  183371. }
  183372. *result = 0;
  183373. return E_NOINTERFACE;
  183374. }
  183375. ULONG __stdcall AddRef() { return ++refCount; }
  183376. ULONG __stdcall Release() { jassert (refCount > 0); const int r = --refCount; if (r == 0) delete this; return r; }
  183377. HRESULT __stdcall QueryContinueDrag (BOOL escapePressed, DWORD keys)
  183378. {
  183379. if (escapePressed)
  183380. return DRAGDROP_S_CANCEL;
  183381. if ((keys & (MK_LBUTTON | MK_RBUTTON)) == 0)
  183382. return DRAGDROP_S_DROP;
  183383. return S_OK;
  183384. }
  183385. HRESULT __stdcall GiveFeedback (DWORD)
  183386. {
  183387. return DRAGDROP_S_USEDEFAULTCURSORS;
  183388. }
  183389. };
  183390. class JuceEnumFormatEtc : public IEnumFORMATETC
  183391. {
  183392. public:
  183393. JuceEnumFormatEtc (const FORMATETC* const format_)
  183394. : refCount (1),
  183395. format (format_),
  183396. index (0)
  183397. {
  183398. }
  183399. virtual ~JuceEnumFormatEtc()
  183400. {
  183401. jassert (refCount == 0);
  183402. }
  183403. HRESULT __stdcall QueryInterface (REFIID id, void __RPC_FAR* __RPC_FAR* result)
  183404. {
  183405. if (id == IID_IUnknown || id == IID_IEnumFORMATETC)
  183406. {
  183407. AddRef();
  183408. *result = this;
  183409. return S_OK;
  183410. }
  183411. *result = 0;
  183412. return E_NOINTERFACE;
  183413. }
  183414. ULONG __stdcall AddRef() { return ++refCount; }
  183415. ULONG __stdcall Release() { jassert (refCount > 0); const int r = --refCount; if (r == 0) delete this; return r; }
  183416. HRESULT __stdcall Clone (IEnumFORMATETC** result)
  183417. {
  183418. if (result == 0)
  183419. return E_POINTER;
  183420. JuceEnumFormatEtc* const newOne = new JuceEnumFormatEtc (format);
  183421. newOne->index = index;
  183422. *result = newOne;
  183423. return S_OK;
  183424. }
  183425. HRESULT __stdcall Next (ULONG celt, LPFORMATETC lpFormatEtc, ULONG* pceltFetched)
  183426. {
  183427. if (pceltFetched != 0)
  183428. *pceltFetched = 0;
  183429. else if (celt != 1)
  183430. return S_FALSE;
  183431. if (index == 0 && celt > 0 && lpFormatEtc != 0)
  183432. {
  183433. copyFormatEtc (lpFormatEtc [0], *format);
  183434. ++index;
  183435. if (pceltFetched != 0)
  183436. *pceltFetched = 1;
  183437. return S_OK;
  183438. }
  183439. return S_FALSE;
  183440. }
  183441. HRESULT __stdcall Skip (ULONG celt)
  183442. {
  183443. if (index + (int) celt >= 1)
  183444. return S_FALSE;
  183445. index += celt;
  183446. return S_OK;
  183447. }
  183448. HRESULT __stdcall Reset()
  183449. {
  183450. index = 0;
  183451. return S_OK;
  183452. }
  183453. private:
  183454. int refCount;
  183455. const FORMATETC* const format;
  183456. int index;
  183457. static void copyFormatEtc (FORMATETC& dest, const FORMATETC& source)
  183458. {
  183459. dest = source;
  183460. if (source.ptd != 0)
  183461. {
  183462. dest.ptd = (DVTARGETDEVICE*) CoTaskMemAlloc (sizeof (DVTARGETDEVICE));
  183463. *(dest.ptd) = *(source.ptd);
  183464. }
  183465. }
  183466. JuceEnumFormatEtc (const JuceEnumFormatEtc&);
  183467. JuceEnumFormatEtc& operator= (const JuceEnumFormatEtc&);
  183468. };
  183469. class JuceDataObject : public IDataObject
  183470. {
  183471. JuceDropSource* const dropSource;
  183472. const FORMATETC* const format;
  183473. const STGMEDIUM* const medium;
  183474. int refCount;
  183475. JuceDataObject (const JuceDataObject&);
  183476. JuceDataObject& operator= (const JuceDataObject&);
  183477. public:
  183478. JuceDataObject (JuceDropSource* const dropSource_,
  183479. const FORMATETC* const format_,
  183480. const STGMEDIUM* const medium_)
  183481. : dropSource (dropSource_),
  183482. format (format_),
  183483. medium (medium_),
  183484. refCount (1)
  183485. {
  183486. }
  183487. virtual ~JuceDataObject()
  183488. {
  183489. jassert (refCount == 0);
  183490. }
  183491. HRESULT __stdcall QueryInterface (REFIID id, void __RPC_FAR* __RPC_FAR* result)
  183492. {
  183493. if (id == IID_IUnknown || id == IID_IDataObject)
  183494. {
  183495. AddRef();
  183496. *result = this;
  183497. return S_OK;
  183498. }
  183499. *result = 0;
  183500. return E_NOINTERFACE;
  183501. }
  183502. ULONG __stdcall AddRef() { return ++refCount; }
  183503. ULONG __stdcall Release() { jassert (refCount > 0); const int r = --refCount; if (r == 0) delete this; return r; }
  183504. HRESULT __stdcall GetData (FORMATETC __RPC_FAR* pFormatEtc, STGMEDIUM __RPC_FAR* pMedium)
  183505. {
  183506. if ((pFormatEtc->tymed & format->tymed) != 0
  183507. && pFormatEtc->cfFormat == format->cfFormat
  183508. && pFormatEtc->dwAspect == format->dwAspect)
  183509. {
  183510. pMedium->tymed = format->tymed;
  183511. pMedium->pUnkForRelease = 0;
  183512. if (format->tymed == TYMED_HGLOBAL)
  183513. {
  183514. const SIZE_T len = GlobalSize (medium->hGlobal);
  183515. void* const src = GlobalLock (medium->hGlobal);
  183516. void* const dst = GlobalAlloc (GMEM_FIXED, len);
  183517. memcpy (dst, src, len);
  183518. GlobalUnlock (medium->hGlobal);
  183519. pMedium->hGlobal = dst;
  183520. return S_OK;
  183521. }
  183522. }
  183523. return DV_E_FORMATETC;
  183524. }
  183525. HRESULT __stdcall QueryGetData (FORMATETC __RPC_FAR* f)
  183526. {
  183527. if (f == 0)
  183528. return E_INVALIDARG;
  183529. if (f->tymed == format->tymed
  183530. && f->cfFormat == format->cfFormat
  183531. && f->dwAspect == format->dwAspect)
  183532. return S_OK;
  183533. return DV_E_FORMATETC;
  183534. }
  183535. HRESULT __stdcall GetCanonicalFormatEtc (FORMATETC __RPC_FAR*, FORMATETC __RPC_FAR* pFormatEtcOut)
  183536. {
  183537. pFormatEtcOut->ptd = 0;
  183538. return E_NOTIMPL;
  183539. }
  183540. HRESULT __stdcall EnumFormatEtc (DWORD direction, IEnumFORMATETC __RPC_FAR *__RPC_FAR *result)
  183541. {
  183542. if (result == 0)
  183543. return E_POINTER;
  183544. if (direction == DATADIR_GET)
  183545. {
  183546. *result = new JuceEnumFormatEtc (format);
  183547. return S_OK;
  183548. }
  183549. *result = 0;
  183550. return E_NOTIMPL;
  183551. }
  183552. HRESULT __stdcall GetDataHere (FORMATETC __RPC_FAR*, STGMEDIUM __RPC_FAR*) { return DATA_E_FORMATETC; }
  183553. HRESULT __stdcall SetData (FORMATETC __RPC_FAR*, STGMEDIUM __RPC_FAR*, BOOL) { return E_NOTIMPL; }
  183554. HRESULT __stdcall DAdvise (FORMATETC __RPC_FAR*, DWORD, IAdviseSink __RPC_FAR*, DWORD __RPC_FAR*) { return OLE_E_ADVISENOTSUPPORTED; }
  183555. HRESULT __stdcall DUnadvise (DWORD) { return E_NOTIMPL; }
  183556. HRESULT __stdcall EnumDAdvise (IEnumSTATDATA __RPC_FAR *__RPC_FAR *) { return OLE_E_ADVISENOTSUPPORTED; }
  183557. };
  183558. static HDROP createHDrop (const StringArray& fileNames) throw()
  183559. {
  183560. int totalChars = 0;
  183561. for (int i = fileNames.size(); --i >= 0;)
  183562. totalChars += fileNames[i].length() + 1;
  183563. HDROP hDrop = (HDROP) GlobalAlloc (GMEM_MOVEABLE | GMEM_ZEROINIT,
  183564. sizeof (DROPFILES)
  183565. + sizeof (WCHAR) * (totalChars + 2));
  183566. if (hDrop != 0)
  183567. {
  183568. LPDROPFILES pDropFiles = (LPDROPFILES) GlobalLock (hDrop);
  183569. pDropFiles->pFiles = sizeof (DROPFILES);
  183570. pDropFiles->fWide = true;
  183571. WCHAR* fname = (WCHAR*) (((char*) pDropFiles) + sizeof (DROPFILES));
  183572. for (int i = 0; i < fileNames.size(); ++i)
  183573. {
  183574. fileNames[i].copyToUnicode (fname, 2048);
  183575. fname += fileNames[i].length() + 1;
  183576. }
  183577. *fname = 0;
  183578. GlobalUnlock (hDrop);
  183579. }
  183580. return hDrop;
  183581. }
  183582. static bool performDragDrop (FORMATETC* const format, STGMEDIUM* const medium, const DWORD whatToDo) throw()
  183583. {
  183584. JuceDropSource* const source = new JuceDropSource();
  183585. JuceDataObject* const data = new JuceDataObject (source, format, medium);
  183586. DWORD effect;
  183587. const HRESULT res = DoDragDrop (data, source, whatToDo, &effect);
  183588. data->Release();
  183589. source->Release();
  183590. return res == DRAGDROP_S_DROP;
  183591. }
  183592. bool DragAndDropContainer::performExternalDragDropOfFiles (const StringArray& files, const bool canMove)
  183593. {
  183594. FORMATETC format = { CF_HDROP, 0, DVASPECT_CONTENT, -1, TYMED_HGLOBAL };
  183595. STGMEDIUM medium = { TYMED_HGLOBAL, { 0 }, 0 };
  183596. medium.hGlobal = createHDrop (files);
  183597. return performDragDrop (&format, &medium, canMove ? (DROPEFFECT_COPY | DROPEFFECT_MOVE)
  183598. : DROPEFFECT_COPY);
  183599. }
  183600. bool DragAndDropContainer::performExternalDragDropOfText (const String& text)
  183601. {
  183602. FORMATETC format = { CF_TEXT, 0, DVASPECT_CONTENT, -1, TYMED_HGLOBAL };
  183603. STGMEDIUM medium = { TYMED_HGLOBAL, { 0 }, 0 };
  183604. const int numChars = text.length();
  183605. medium.hGlobal = GlobalAlloc (GMEM_MOVEABLE | GMEM_ZEROINIT, (numChars + 2) * sizeof (WCHAR));
  183606. char* d = (char*) GlobalLock (medium.hGlobal);
  183607. text.copyToUnicode ((WCHAR*) d, numChars + 1);
  183608. format.cfFormat = CF_UNICODETEXT;
  183609. GlobalUnlock (medium.hGlobal);
  183610. return performDragDrop (&format, &medium, DROPEFFECT_COPY | DROPEFFECT_MOVE);
  183611. }
  183612. #endif
  183613. /*** End of inlined file: juce_win32_Windowing.cpp ***/
  183614. /*** Start of inlined file: juce_win32_Fonts.cpp ***/
  183615. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  183616. // compiled on its own).
  183617. #if JUCE_INCLUDED_FILE
  183618. static int CALLBACK wfontEnum2 (ENUMLOGFONTEXW* lpelfe,
  183619. NEWTEXTMETRICEXW*,
  183620. int type,
  183621. LPARAM lParam)
  183622. {
  183623. if (lpelfe != 0 && (type & RASTER_FONTTYPE) == 0)
  183624. {
  183625. const String fontName (lpelfe->elfLogFont.lfFaceName);
  183626. ((StringArray*) lParam)->addIfNotAlreadyThere (fontName.removeCharacters (T("@")));
  183627. }
  183628. return 1;
  183629. }
  183630. static int CALLBACK wfontEnum1 (ENUMLOGFONTEXW* lpelfe,
  183631. NEWTEXTMETRICEXW*,
  183632. int type,
  183633. LPARAM lParam)
  183634. {
  183635. if (lpelfe != 0 && (type & RASTER_FONTTYPE) == 0)
  183636. {
  183637. LOGFONTW lf;
  183638. zerostruct (lf);
  183639. lf.lfWeight = FW_DONTCARE;
  183640. lf.lfOutPrecision = OUT_OUTLINE_PRECIS;
  183641. lf.lfQuality = DEFAULT_QUALITY;
  183642. lf.lfCharSet = DEFAULT_CHARSET;
  183643. lf.lfClipPrecision = CLIP_DEFAULT_PRECIS;
  183644. lf.lfPitchAndFamily = FF_DONTCARE;
  183645. const String fontName (lpelfe->elfLogFont.lfFaceName);
  183646. fontName.copyToUnicode (lf.lfFaceName, LF_FACESIZE - 1);
  183647. HDC dc = CreateCompatibleDC (0);
  183648. EnumFontFamiliesEx (dc, &lf,
  183649. (FONTENUMPROCW) &wfontEnum2,
  183650. lParam, 0);
  183651. DeleteDC (dc);
  183652. }
  183653. return 1;
  183654. }
  183655. const StringArray Font::findAllTypefaceNames() throw()
  183656. {
  183657. StringArray results;
  183658. HDC dc = CreateCompatibleDC (0);
  183659. {
  183660. LOGFONTW lf;
  183661. zerostruct (lf);
  183662. lf.lfWeight = FW_DONTCARE;
  183663. lf.lfOutPrecision = OUT_OUTLINE_PRECIS;
  183664. lf.lfQuality = DEFAULT_QUALITY;
  183665. lf.lfCharSet = DEFAULT_CHARSET;
  183666. lf.lfClipPrecision = CLIP_DEFAULT_PRECIS;
  183667. lf.lfPitchAndFamily = FF_DONTCARE;
  183668. lf.lfFaceName[0] = 0;
  183669. EnumFontFamiliesEx (dc, &lf,
  183670. (FONTENUMPROCW) &wfontEnum1,
  183671. (LPARAM) &results, 0);
  183672. }
  183673. DeleteDC (dc);
  183674. results.sort (true);
  183675. return results;
  183676. }
  183677. extern bool juce_IsRunningInWine();
  183678. void Font::getPlatformDefaultFontNames (String& defaultSans, String& defaultSerif, String& defaultFixed) throw()
  183679. {
  183680. if (juce_IsRunningInWine())
  183681. {
  183682. // If we're running in Wine, then use fonts that might be available on Linux..
  183683. defaultSans = "Bitstream Vera Sans";
  183684. defaultSerif = "Bitstream Vera Serif";
  183685. defaultFixed = "Bitstream Vera Sans Mono";
  183686. }
  183687. else
  183688. {
  183689. defaultSans = "Verdana";
  183690. defaultSerif = "Times";
  183691. defaultFixed = "Lucida Console";
  183692. }
  183693. }
  183694. class FontDCHolder : private DeletedAtShutdown
  183695. {
  183696. public:
  183697. FontDCHolder() throw()
  183698. : dc (0), numKPs (0), size (0),
  183699. bold (false), italic (false)
  183700. {
  183701. }
  183702. ~FontDCHolder() throw()
  183703. {
  183704. if (dc != 0)
  183705. {
  183706. DeleteDC (dc);
  183707. DeleteObject (fontH);
  183708. }
  183709. clearSingletonInstance();
  183710. }
  183711. juce_DeclareSingleton_SingleThreaded_Minimal (FontDCHolder);
  183712. HDC loadFont (const String& fontName_, const bool bold_, const bool italic_, const int size_) throw()
  183713. {
  183714. if (fontName != fontName_ || bold != bold_ || italic != italic_ || size != size_)
  183715. {
  183716. fontName = fontName_;
  183717. bold = bold_;
  183718. italic = italic_;
  183719. size = size_;
  183720. if (dc != 0)
  183721. {
  183722. DeleteDC (dc);
  183723. DeleteObject (fontH);
  183724. kps.free();
  183725. }
  183726. fontH = 0;
  183727. dc = CreateCompatibleDC (0);
  183728. SetMapperFlags (dc, 0);
  183729. SetMapMode (dc, MM_TEXT);
  183730. LOGFONTW lfw;
  183731. zerostruct (lfw);
  183732. lfw.lfCharSet = DEFAULT_CHARSET;
  183733. lfw.lfClipPrecision = CLIP_DEFAULT_PRECIS;
  183734. lfw.lfOutPrecision = OUT_OUTLINE_PRECIS;
  183735. lfw.lfPitchAndFamily = DEFAULT_PITCH | FF_DONTCARE;
  183736. lfw.lfQuality = PROOF_QUALITY;
  183737. lfw.lfItalic = (BYTE) (italic ? TRUE : FALSE);
  183738. lfw.lfWeight = bold ? FW_BOLD : FW_NORMAL;
  183739. fontName.copyToUnicode (lfw.lfFaceName, LF_FACESIZE - 1);
  183740. lfw.lfHeight = size > 0 ? size : -256;
  183741. HFONT standardSizedFont = CreateFontIndirect (&lfw);
  183742. if (standardSizedFont != 0)
  183743. {
  183744. if (SelectObject (dc, standardSizedFont) != 0)
  183745. {
  183746. fontH = standardSizedFont;
  183747. if (size == 0)
  183748. {
  183749. OUTLINETEXTMETRIC otm;
  183750. if (GetOutlineTextMetrics (dc, sizeof (otm), &otm) != 0)
  183751. {
  183752. lfw.lfHeight = -(int) otm.otmEMSquare;
  183753. fontH = CreateFontIndirect (&lfw);
  183754. SelectObject (dc, fontH);
  183755. DeleteObject (standardSizedFont);
  183756. }
  183757. }
  183758. }
  183759. else
  183760. {
  183761. jassertfalse
  183762. }
  183763. }
  183764. else
  183765. {
  183766. jassertfalse
  183767. }
  183768. }
  183769. return dc;
  183770. }
  183771. KERNINGPAIR* getKerningPairs (int& numKPs_) throw()
  183772. {
  183773. if (kps == 0)
  183774. {
  183775. numKPs = GetKerningPairs (dc, 0, 0);
  183776. kps.calloc (numKPs);
  183777. GetKerningPairs (dc, numKPs, kps);
  183778. }
  183779. numKPs_ = numKPs;
  183780. return kps;
  183781. }
  183782. private:
  183783. HFONT fontH;
  183784. HDC dc;
  183785. String fontName;
  183786. HeapBlock <KERNINGPAIR> kps;
  183787. int numKPs, size;
  183788. bool bold, italic;
  183789. FontDCHolder (const FontDCHolder&);
  183790. FontDCHolder& operator= (const FontDCHolder&);
  183791. };
  183792. juce_ImplementSingleton_SingleThreaded (FontDCHolder);
  183793. class WindowsTypeface : public CustomTypeface
  183794. {
  183795. public:
  183796. WindowsTypeface (const Font& font)
  183797. {
  183798. HDC dc = FontDCHolder::getInstance()->loadFont (font.getTypefaceName(),
  183799. font.isBold(), font.isItalic(), 0);
  183800. TEXTMETRIC tm;
  183801. tm.tmAscent = tm.tmHeight = 1;
  183802. tm.tmDefaultChar = 0;
  183803. GetTextMetrics (dc, &tm);
  183804. setCharacteristics (font.getTypefaceName(),
  183805. tm.tmAscent / (float) tm.tmHeight,
  183806. font.isBold(), font.isItalic(),
  183807. tm.tmDefaultChar);
  183808. }
  183809. bool loadGlyphIfPossible (const juce_wchar character)
  183810. {
  183811. HDC dc = FontDCHolder::getInstance()->loadFont (name, isBold, isItalic, 0);
  183812. GLYPHMETRICS gm;
  183813. {
  183814. const WCHAR charToTest[] = { (WCHAR) character, 0 };
  183815. WORD index = 0;
  183816. if (GetGlyphIndices (dc, charToTest, 1, &index, GGI_MARK_NONEXISTING_GLYPHS) != GDI_ERROR
  183817. && index == 0xffff)
  183818. {
  183819. return false;
  183820. }
  183821. }
  183822. Path glyphPath;
  183823. TEXTMETRIC tm;
  183824. if (! GetTextMetrics (dc, &tm))
  183825. {
  183826. addGlyph (character, glyphPath, 0);
  183827. return true;
  183828. }
  183829. const float height = (float) tm.tmHeight;
  183830. static const MAT2 identityMatrix = { { 0, 1 }, { 0, 0 }, { 0, 0 }, { 0, 1 } };
  183831. const int bufSize = GetGlyphOutline (dc, character, GGO_NATIVE,
  183832. &gm, 0, 0, &identityMatrix);
  183833. if (bufSize > 0)
  183834. {
  183835. HeapBlock<char> data (bufSize);
  183836. GetGlyphOutline (dc, character, GGO_NATIVE, &gm,
  183837. bufSize, data, &identityMatrix);
  183838. const TTPOLYGONHEADER* pheader = reinterpret_cast<TTPOLYGONHEADER*> (data.getData());
  183839. const float scaleX = 1.0f / height;
  183840. const float scaleY = -1.0f / height;
  183841. while ((char*) pheader < data + bufSize)
  183842. {
  183843. float x = scaleX * pheader->pfxStart.x.value;
  183844. float y = scaleY * pheader->pfxStart.y.value;
  183845. glyphPath.startNewSubPath (x, y);
  183846. const TTPOLYCURVE* curve = (const TTPOLYCURVE*) ((const char*) pheader + sizeof (TTPOLYGONHEADER));
  183847. const char* const curveEnd = ((const char*) pheader) + pheader->cb;
  183848. while ((const char*) curve < curveEnd)
  183849. {
  183850. if (curve->wType == TT_PRIM_LINE)
  183851. {
  183852. for (int i = 0; i < curve->cpfx; ++i)
  183853. {
  183854. x = scaleX * curve->apfx[i].x.value;
  183855. y = scaleY * curve->apfx[i].y.value;
  183856. glyphPath.lineTo (x, y);
  183857. }
  183858. }
  183859. else if (curve->wType == TT_PRIM_QSPLINE)
  183860. {
  183861. for (int i = 0; i < curve->cpfx - 1; ++i)
  183862. {
  183863. const float x2 = scaleX * curve->apfx[i].x.value;
  183864. const float y2 = scaleY * curve->apfx[i].y.value;
  183865. float x3, y3;
  183866. if (i < curve->cpfx - 2)
  183867. {
  183868. x3 = 0.5f * (x2 + scaleX * curve->apfx[i + 1].x.value);
  183869. y3 = 0.5f * (y2 + scaleY * curve->apfx[i + 1].y.value);
  183870. }
  183871. else
  183872. {
  183873. x3 = scaleX * curve->apfx[i + 1].x.value;
  183874. y3 = scaleY * curve->apfx[i + 1].y.value;
  183875. }
  183876. glyphPath.quadraticTo (x2, y2, x3, y3);
  183877. x = x3;
  183878. y = y3;
  183879. }
  183880. }
  183881. curve = (const TTPOLYCURVE*) &(curve->apfx [curve->cpfx]);
  183882. }
  183883. pheader = (const TTPOLYGONHEADER*) curve;
  183884. glyphPath.closeSubPath();
  183885. }
  183886. }
  183887. addGlyph (character, glyphPath, gm.gmCellIncX / height);
  183888. int numKPs;
  183889. const KERNINGPAIR* const kps = FontDCHolder::getInstance()->getKerningPairs (numKPs);
  183890. for (int i = 0; i < numKPs; ++i)
  183891. {
  183892. if (kps[i].wFirst == character)
  183893. addKerningPair (kps[i].wFirst, kps[i].wSecond,
  183894. kps[i].iKernAmount / height);
  183895. }
  183896. return true;
  183897. }
  183898. };
  183899. const Typeface::Ptr Typeface::createSystemTypefaceFor (const Font& font)
  183900. {
  183901. return new WindowsTypeface (font);
  183902. }
  183903. #endif
  183904. /*** End of inlined file: juce_win32_Fonts.cpp ***/
  183905. /*** Start of inlined file: juce_win32_FileChooser.cpp ***/
  183906. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  183907. // compiled on its own).
  183908. #if JUCE_INCLUDED_FILE
  183909. static const void* defaultDirPath = 0;
  183910. static String returnedString; // need this to get non-existent pathnames from the directory chooser
  183911. static Component* currentExtraFileWin = 0;
  183912. static bool areThereAnyAlwaysOnTopWindows()
  183913. {
  183914. for (int i = Desktop::getInstance().getNumComponents(); --i >= 0;)
  183915. {
  183916. Component* c = Desktop::getInstance().getComponent (i);
  183917. if (c != 0 && c->isAlwaysOnTop() && c->isShowing())
  183918. return true;
  183919. }
  183920. return false;
  183921. }
  183922. static int CALLBACK browseCallbackProc (HWND hWnd, UINT msg, LPARAM lParam, LPARAM /*lpData*/)
  183923. {
  183924. if (msg == BFFM_INITIALIZED)
  183925. {
  183926. SendMessage (hWnd, BFFM_SETSELECTIONW, TRUE, (LPARAM) defaultDirPath);
  183927. }
  183928. else if (msg == BFFM_VALIDATEFAILEDW)
  183929. {
  183930. returnedString = (LPCWSTR) lParam;
  183931. }
  183932. else if (msg == BFFM_VALIDATEFAILEDA)
  183933. {
  183934. returnedString = (const char*) lParam;
  183935. }
  183936. return 0;
  183937. }
  183938. void juce_setWindowStyleBit (HWND h, const int styleType, const int feature, const bool bitIsSet) throw();
  183939. static UINT_PTR CALLBACK openCallback (HWND hdlg, UINT uiMsg, WPARAM /*wParam*/, LPARAM lParam)
  183940. {
  183941. if (currentExtraFileWin != 0)
  183942. {
  183943. if (uiMsg == WM_INITDIALOG)
  183944. {
  183945. HWND dialogH = GetParent (hdlg);
  183946. jassert (dialogH != 0);
  183947. if (dialogH == 0)
  183948. dialogH = hdlg;
  183949. RECT r, cr;
  183950. GetWindowRect (dialogH, &r);
  183951. GetClientRect (dialogH, &cr);
  183952. SetWindowPos (dialogH, 0,
  183953. r.left, r.top,
  183954. currentExtraFileWin->getWidth() + jmax (150, (int) (r.right - r.left)),
  183955. jmax (150, (int) (r.bottom - r.top)),
  183956. SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOZORDER);
  183957. currentExtraFileWin->setBounds (cr.right, cr.top, currentExtraFileWin->getWidth(), cr.bottom - cr.top);
  183958. currentExtraFileWin->getChildComponent(0)->setBounds (0, 0, currentExtraFileWin->getWidth(), currentExtraFileWin->getHeight());
  183959. SetParent ((HWND) currentExtraFileWin->getWindowHandle(), (HWND) dialogH);
  183960. juce_setWindowStyleBit ((HWND)currentExtraFileWin->getWindowHandle(), GWL_STYLE, WS_CHILD, (dialogH != 0));
  183961. juce_setWindowStyleBit ((HWND)currentExtraFileWin->getWindowHandle(), GWL_STYLE, WS_POPUP, (dialogH == 0));
  183962. }
  183963. else if (uiMsg == WM_NOTIFY)
  183964. {
  183965. LPOFNOTIFY ofn = (LPOFNOTIFY) lParam;
  183966. if (ofn->hdr.code == CDN_SELCHANGE)
  183967. {
  183968. FilePreviewComponent* comp = (FilePreviewComponent*) currentExtraFileWin->getChildComponent(0);
  183969. if (comp != 0)
  183970. {
  183971. TCHAR path [MAX_PATH * 2];
  183972. path[0] = 0;
  183973. CommDlg_OpenSave_GetFilePath (GetParent (hdlg), (LPARAM) &path, MAX_PATH);
  183974. const String fn ((const WCHAR*) path);
  183975. comp->selectedFileChanged (File (fn));
  183976. }
  183977. }
  183978. }
  183979. }
  183980. return 0;
  183981. }
  183982. class FPComponentHolder : public Component
  183983. {
  183984. public:
  183985. FPComponentHolder()
  183986. {
  183987. setVisible (true);
  183988. setOpaque (true);
  183989. }
  183990. ~FPComponentHolder()
  183991. {
  183992. }
  183993. void paint (Graphics& g)
  183994. {
  183995. g.fillAll (Colours::lightgrey);
  183996. }
  183997. private:
  183998. FPComponentHolder (const FPComponentHolder&);
  183999. FPComponentHolder& operator= (const FPComponentHolder&);
  184000. };
  184001. void FileChooser::showPlatformDialog (Array<File>& results,
  184002. const String& title,
  184003. const File& currentFileOrDirectory,
  184004. const String& filter,
  184005. bool selectsDirectory,
  184006. bool /*selectsFiles*/,
  184007. bool isSaveDialogue,
  184008. bool warnAboutOverwritingExistingFiles,
  184009. bool selectMultipleFiles,
  184010. FilePreviewComponent* extraInfoComponent)
  184011. {
  184012. const int numCharsAvailable = 32768;
  184013. MemoryBlock filenameSpace ((numCharsAvailable + 1) * sizeof (WCHAR), true);
  184014. WCHAR* const fname = (WCHAR*) filenameSpace.getData();
  184015. int fnameIdx = 0;
  184016. JUCE_TRY
  184017. {
  184018. // use a modal window as the parent for this dialog box
  184019. // to block input from other app windows
  184020. const Rectangle<int> mainMon (Desktop::getInstance().getMainMonitorArea());
  184021. Component w (String::empty);
  184022. w.setBounds (mainMon.getX() + mainMon.getWidth() / 4,
  184023. mainMon.getY() + mainMon.getHeight() / 4,
  184024. 0, 0);
  184025. w.setOpaque (true);
  184026. w.setAlwaysOnTop (areThereAnyAlwaysOnTopWindows());
  184027. w.addToDesktop (0);
  184028. if (extraInfoComponent == 0)
  184029. w.enterModalState();
  184030. String initialDir;
  184031. if (currentFileOrDirectory.isDirectory())
  184032. {
  184033. initialDir = currentFileOrDirectory.getFullPathName();
  184034. }
  184035. else
  184036. {
  184037. currentFileOrDirectory.getFileName().copyToUnicode (fname, numCharsAvailable);
  184038. initialDir = currentFileOrDirectory.getParentDirectory().getFullPathName();
  184039. }
  184040. if (currentExtraFileWin->isValidComponent())
  184041. {
  184042. jassertfalse
  184043. return;
  184044. }
  184045. if (selectsDirectory)
  184046. {
  184047. LPITEMIDLIST list = 0;
  184048. filenameSpace.fillWith (0);
  184049. {
  184050. BROWSEINFO bi;
  184051. zerostruct (bi);
  184052. bi.hwndOwner = (HWND) w.getWindowHandle();
  184053. bi.pszDisplayName = fname;
  184054. bi.lpszTitle = title;
  184055. bi.lpfn = browseCallbackProc;
  184056. #ifdef BIF_USENEWUI
  184057. bi.ulFlags = BIF_USENEWUI | BIF_VALIDATE;
  184058. #else
  184059. bi.ulFlags = 0x50;
  184060. #endif
  184061. defaultDirPath = (const WCHAR*) initialDir;
  184062. list = SHBrowseForFolder (&bi);
  184063. if (! SHGetPathFromIDListW (list, fname))
  184064. {
  184065. fname[0] = 0;
  184066. returnedString = String::empty;
  184067. }
  184068. }
  184069. LPMALLOC al;
  184070. if (list != 0 && SUCCEEDED (SHGetMalloc (&al)))
  184071. al->Free (list);
  184072. defaultDirPath = 0;
  184073. if (returnedString.isNotEmpty())
  184074. {
  184075. const String stringFName (fname);
  184076. results.add (File (stringFName).getSiblingFile (returnedString));
  184077. returnedString = String::empty;
  184078. return;
  184079. }
  184080. }
  184081. else
  184082. {
  184083. DWORD flags = OFN_EXPLORER | OFN_PATHMUSTEXIST | OFN_NOCHANGEDIR | OFN_HIDEREADONLY;
  184084. if (warnAboutOverwritingExistingFiles)
  184085. flags |= OFN_OVERWRITEPROMPT;
  184086. if (selectMultipleFiles)
  184087. flags |= OFN_ALLOWMULTISELECT;
  184088. if (extraInfoComponent != 0)
  184089. {
  184090. flags |= OFN_ENABLEHOOK;
  184091. currentExtraFileWin = new FPComponentHolder();
  184092. currentExtraFileWin->addAndMakeVisible (extraInfoComponent);
  184093. currentExtraFileWin->setSize (jlimit (20, 800, extraInfoComponent->getWidth()),
  184094. extraInfoComponent->getHeight());
  184095. currentExtraFileWin->addToDesktop (0);
  184096. currentExtraFileWin->enterModalState();
  184097. }
  184098. {
  184099. WCHAR filters [1024];
  184100. zeromem (filters, sizeof (filters));
  184101. filter.copyToUnicode (filters, 1024);
  184102. filter.copyToUnicode (filters + filter.length() + 1,
  184103. 1022 - filter.length());
  184104. OPENFILENAMEW of;
  184105. zerostruct (of);
  184106. #ifdef OPENFILENAME_SIZE_VERSION_400W
  184107. of.lStructSize = OPENFILENAME_SIZE_VERSION_400W;
  184108. #else
  184109. of.lStructSize = sizeof (of);
  184110. #endif
  184111. of.hwndOwner = (HWND) w.getWindowHandle();
  184112. of.lpstrFilter = filters;
  184113. of.nFilterIndex = 1;
  184114. of.lpstrFile = fname;
  184115. of.nMaxFile = numCharsAvailable;
  184116. of.lpstrInitialDir = initialDir;
  184117. of.lpstrTitle = title;
  184118. of.Flags = flags;
  184119. if (extraInfoComponent != 0)
  184120. of.lpfnHook = &openCallback;
  184121. if (isSaveDialogue)
  184122. {
  184123. if (! GetSaveFileName (&of))
  184124. fname[0] = 0;
  184125. else
  184126. fnameIdx = of.nFileOffset;
  184127. }
  184128. else
  184129. {
  184130. if (! GetOpenFileName (&of))
  184131. fname[0] = 0;
  184132. else
  184133. fnameIdx = of.nFileOffset;
  184134. }
  184135. }
  184136. }
  184137. }
  184138. #if JUCE_CATCH_UNHANDLED_EXCEPTIONS
  184139. catch (...)
  184140. {
  184141. fname[0] = 0;
  184142. }
  184143. #endif
  184144. deleteAndZero (currentExtraFileWin);
  184145. const WCHAR* const files = fname;
  184146. if (selectMultipleFiles && fnameIdx > 0 && files [fnameIdx - 1] == 0)
  184147. {
  184148. const WCHAR* filename = files + fnameIdx;
  184149. while (*filename != 0)
  184150. {
  184151. const String filepath (String (files) + T("\\") + String (filename));
  184152. results.add (File (filepath));
  184153. filename += CharacterFunctions::length (filename) + 1;
  184154. }
  184155. }
  184156. else if (files[0] != 0)
  184157. {
  184158. results.add (File (files));
  184159. }
  184160. }
  184161. #endif
  184162. /*** End of inlined file: juce_win32_FileChooser.cpp ***/
  184163. /*** Start of inlined file: juce_win32_Misc.cpp ***/
  184164. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  184165. // compiled on its own).
  184166. #if JUCE_INCLUDED_FILE
  184167. void SystemClipboard::copyTextToClipboard (const String& text) throw()
  184168. {
  184169. if (OpenClipboard (0) != 0)
  184170. {
  184171. if (EmptyClipboard() != 0)
  184172. {
  184173. const int len = text.length();
  184174. if (len > 0)
  184175. {
  184176. HGLOBAL bufH = GlobalAlloc (GMEM_MOVEABLE | GMEM_DDESHARE,
  184177. (len + 1) * sizeof (wchar_t));
  184178. if (bufH != 0)
  184179. {
  184180. WCHAR* const data = (WCHAR*) GlobalLock (bufH);
  184181. text.copyToUnicode (data, len);
  184182. GlobalUnlock (bufH);
  184183. SetClipboardData (CF_UNICODETEXT, bufH);
  184184. }
  184185. }
  184186. }
  184187. CloseClipboard();
  184188. }
  184189. }
  184190. const String SystemClipboard::getTextFromClipboard() throw()
  184191. {
  184192. String result;
  184193. if (OpenClipboard (0) != 0)
  184194. {
  184195. HANDLE bufH = GetClipboardData (CF_UNICODETEXT);
  184196. if (bufH != 0)
  184197. {
  184198. const wchar_t* const data = (const wchar_t*) GlobalLock (bufH);
  184199. if (data != 0)
  184200. {
  184201. result = String (data, (int) (GlobalSize (bufH) / sizeof (tchar)));
  184202. GlobalUnlock (bufH);
  184203. }
  184204. }
  184205. CloseClipboard();
  184206. }
  184207. return result;
  184208. }
  184209. #endif
  184210. /*** End of inlined file: juce_win32_Misc.cpp ***/
  184211. /*** Start of inlined file: juce_win32_ActiveXComponent.cpp ***/
  184212. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  184213. // compiled on its own).
  184214. #if JUCE_INCLUDED_FILE
  184215. namespace ActiveXHelpers
  184216. {
  184217. class JuceIStorage : public IStorage
  184218. {
  184219. int refCount;
  184220. public:
  184221. JuceIStorage() : refCount (1) {}
  184222. virtual ~JuceIStorage()
  184223. {
  184224. jassert (refCount == 0);
  184225. }
  184226. HRESULT __stdcall QueryInterface (REFIID id, void __RPC_FAR* __RPC_FAR* result)
  184227. {
  184228. if (id == IID_IUnknown || id == IID_IStorage)
  184229. {
  184230. AddRef();
  184231. *result = this;
  184232. return S_OK;
  184233. }
  184234. *result = 0;
  184235. return E_NOINTERFACE;
  184236. }
  184237. ULONG __stdcall AddRef() { return ++refCount; }
  184238. ULONG __stdcall Release() { const int r = --refCount; if (r == 0) delete this; return r; }
  184239. HRESULT __stdcall CreateStream (const WCHAR*, DWORD, DWORD, DWORD, IStream**) { return E_NOTIMPL; }
  184240. HRESULT __stdcall OpenStream (const WCHAR*, void*, DWORD, DWORD, IStream**) { return E_NOTIMPL; }
  184241. HRESULT __stdcall CreateStorage (const WCHAR*, DWORD, DWORD, DWORD, IStorage**) { return E_NOTIMPL; }
  184242. HRESULT __stdcall OpenStorage (const WCHAR*, IStorage*, DWORD, SNB, DWORD, IStorage**) { return E_NOTIMPL; }
  184243. HRESULT __stdcall CopyTo (DWORD, IID const*, SNB, IStorage*) { return E_NOTIMPL; }
  184244. HRESULT __stdcall MoveElementTo (const OLECHAR*,IStorage*, const OLECHAR*, DWORD) { return E_NOTIMPL; }
  184245. HRESULT __stdcall Commit (DWORD) { return E_NOTIMPL; }
  184246. HRESULT __stdcall Revert() { return E_NOTIMPL; }
  184247. HRESULT __stdcall EnumElements (DWORD, void*, DWORD, IEnumSTATSTG**) { return E_NOTIMPL; }
  184248. HRESULT __stdcall DestroyElement (const OLECHAR*) { return E_NOTIMPL; }
  184249. HRESULT __stdcall RenameElement (const WCHAR*, const WCHAR*) { return E_NOTIMPL; }
  184250. HRESULT __stdcall SetElementTimes (const WCHAR*, FILETIME const*, FILETIME const*, FILETIME const*) { return E_NOTIMPL; }
  184251. HRESULT __stdcall SetClass (REFCLSID) { return S_OK; }
  184252. HRESULT __stdcall SetStateBits (DWORD, DWORD) { return E_NOTIMPL; }
  184253. HRESULT __stdcall Stat (STATSTG*, DWORD) { return E_NOTIMPL; }
  184254. juce_UseDebuggingNewOperator
  184255. };
  184256. class JuceOleInPlaceFrame : public IOleInPlaceFrame
  184257. {
  184258. int refCount;
  184259. HWND window;
  184260. public:
  184261. JuceOleInPlaceFrame (HWND window_)
  184262. : refCount (1),
  184263. window (window_)
  184264. {
  184265. }
  184266. virtual ~JuceOleInPlaceFrame()
  184267. {
  184268. jassert (refCount == 0);
  184269. }
  184270. HRESULT __stdcall QueryInterface (REFIID id, void __RPC_FAR* __RPC_FAR* result)
  184271. {
  184272. if (id == IID_IUnknown || id == IID_IOleInPlaceFrame)
  184273. {
  184274. AddRef();
  184275. *result = this;
  184276. return S_OK;
  184277. }
  184278. *result = 0;
  184279. return E_NOINTERFACE;
  184280. }
  184281. ULONG __stdcall AddRef() { return ++refCount; }
  184282. ULONG __stdcall Release() { const int r = --refCount; if (r == 0) delete this; return r; }
  184283. HRESULT __stdcall GetWindow (HWND* lphwnd) { *lphwnd = window; return S_OK; }
  184284. HRESULT __stdcall ContextSensitiveHelp (BOOL) { return E_NOTIMPL; }
  184285. HRESULT __stdcall GetBorder (LPRECT) { return E_NOTIMPL; }
  184286. HRESULT __stdcall RequestBorderSpace (LPCBORDERWIDTHS) { return E_NOTIMPL; }
  184287. HRESULT __stdcall SetBorderSpace (LPCBORDERWIDTHS) { return E_NOTIMPL; }
  184288. HRESULT __stdcall SetActiveObject (IOleInPlaceActiveObject*, LPCOLESTR) { return S_OK; }
  184289. HRESULT __stdcall InsertMenus (HMENU, LPOLEMENUGROUPWIDTHS) { return E_NOTIMPL; }
  184290. HRESULT __stdcall SetMenu (HMENU, HOLEMENU, HWND) { return S_OK; }
  184291. HRESULT __stdcall RemoveMenus (HMENU) { return E_NOTIMPL; }
  184292. HRESULT __stdcall SetStatusText (LPCOLESTR) { return S_OK; }
  184293. HRESULT __stdcall EnableModeless (BOOL) { return S_OK; }
  184294. HRESULT __stdcall TranslateAccelerator(LPMSG, WORD) { return E_NOTIMPL; }
  184295. juce_UseDebuggingNewOperator
  184296. };
  184297. class JuceIOleInPlaceSite : public IOleInPlaceSite
  184298. {
  184299. int refCount;
  184300. HWND window;
  184301. JuceOleInPlaceFrame* frame;
  184302. public:
  184303. JuceIOleInPlaceSite (HWND window_)
  184304. : refCount (1),
  184305. window (window_)
  184306. {
  184307. frame = new JuceOleInPlaceFrame (window);
  184308. }
  184309. virtual ~JuceIOleInPlaceSite()
  184310. {
  184311. jassert (refCount == 0);
  184312. frame->Release();
  184313. }
  184314. HRESULT __stdcall QueryInterface (REFIID id, void __RPC_FAR* __RPC_FAR* result)
  184315. {
  184316. if (id == IID_IUnknown || id == IID_IOleInPlaceSite)
  184317. {
  184318. AddRef();
  184319. *result = this;
  184320. return S_OK;
  184321. }
  184322. *result = 0;
  184323. return E_NOINTERFACE;
  184324. }
  184325. ULONG __stdcall AddRef() { return ++refCount; }
  184326. ULONG __stdcall Release() { const int r = --refCount; if (r == 0) delete this; return r; }
  184327. HRESULT __stdcall GetWindow (HWND* lphwnd) { *lphwnd = window; return S_OK; }
  184328. HRESULT __stdcall ContextSensitiveHelp (BOOL) { return E_NOTIMPL; }
  184329. HRESULT __stdcall CanInPlaceActivate() { return S_OK; }
  184330. HRESULT __stdcall OnInPlaceActivate() { return S_OK; }
  184331. HRESULT __stdcall OnUIActivate() { return S_OK; }
  184332. HRESULT __stdcall GetWindowContext (LPOLEINPLACEFRAME* lplpFrame, LPOLEINPLACEUIWINDOW* lplpDoc, LPRECT, LPRECT, LPOLEINPLACEFRAMEINFO lpFrameInfo)
  184333. {
  184334. // frame->AddRef(); // MS docs are unclear about whether this is needed, but it seems to lead to a memory leak..
  184335. *lplpFrame = frame;
  184336. *lplpDoc = 0;
  184337. lpFrameInfo->fMDIApp = FALSE;
  184338. lpFrameInfo->hwndFrame = window;
  184339. lpFrameInfo->haccel = 0;
  184340. lpFrameInfo->cAccelEntries = 0;
  184341. return S_OK;
  184342. }
  184343. HRESULT __stdcall Scroll (SIZE) { return E_NOTIMPL; }
  184344. HRESULT __stdcall OnUIDeactivate (BOOL) { return S_OK; }
  184345. HRESULT __stdcall OnInPlaceDeactivate() { return S_OK; }
  184346. HRESULT __stdcall DiscardUndoState() { return E_NOTIMPL; }
  184347. HRESULT __stdcall DeactivateAndUndo() { return E_NOTIMPL; }
  184348. HRESULT __stdcall OnPosRectChange (LPCRECT) { return S_OK; }
  184349. juce_UseDebuggingNewOperator
  184350. };
  184351. class JuceIOleClientSite : public IOleClientSite
  184352. {
  184353. int refCount;
  184354. JuceIOleInPlaceSite* inplaceSite;
  184355. public:
  184356. JuceIOleClientSite (HWND window)
  184357. : refCount (1)
  184358. {
  184359. inplaceSite = new JuceIOleInPlaceSite (window);
  184360. }
  184361. virtual ~JuceIOleClientSite()
  184362. {
  184363. jassert (refCount == 0);
  184364. inplaceSite->Release();
  184365. }
  184366. HRESULT __stdcall QueryInterface (REFIID id, void __RPC_FAR* __RPC_FAR* result)
  184367. {
  184368. if (id == IID_IUnknown || id == IID_IOleClientSite)
  184369. {
  184370. AddRef();
  184371. *result = this;
  184372. return S_OK;
  184373. }
  184374. else if (id == IID_IOleInPlaceSite)
  184375. {
  184376. inplaceSite->AddRef();
  184377. *result = inplaceSite;
  184378. return S_OK;
  184379. }
  184380. *result = 0;
  184381. return E_NOINTERFACE;
  184382. }
  184383. ULONG __stdcall AddRef() { return ++refCount; }
  184384. ULONG __stdcall Release() { const int r = --refCount; if (r == 0) delete this; return r; }
  184385. HRESULT __stdcall SaveObject() { return E_NOTIMPL; }
  184386. HRESULT __stdcall GetMoniker (DWORD, DWORD, IMoniker**) { return E_NOTIMPL; }
  184387. HRESULT __stdcall GetContainer (LPOLECONTAINER* ppContainer) { *ppContainer = 0; return E_NOINTERFACE; }
  184388. HRESULT __stdcall ShowObject() { return S_OK; }
  184389. HRESULT __stdcall OnShowWindow (BOOL) { return E_NOTIMPL; }
  184390. HRESULT __stdcall RequestNewObjectLayout() { return E_NOTIMPL; }
  184391. juce_UseDebuggingNewOperator
  184392. };
  184393. static VoidArray activeXComps;
  184394. static HWND getHWND (const ActiveXControlComponent* const component)
  184395. {
  184396. HWND hwnd = 0;
  184397. const IID iid = IID_IOleWindow;
  184398. IOleWindow* const window = (IOleWindow*) component->queryInterface (&iid);
  184399. if (window != 0)
  184400. {
  184401. window->GetWindow (&hwnd);
  184402. window->Release();
  184403. }
  184404. return hwnd;
  184405. }
  184406. static void offerActiveXMouseEventToPeer (ComponentPeer* const peer, HWND hwnd, UINT message, LPARAM lParam)
  184407. {
  184408. RECT activeXRect, peerRect;
  184409. GetWindowRect (hwnd, &activeXRect);
  184410. GetWindowRect ((HWND) peer->getNativeHandle(), &peerRect);
  184411. const Point<int> mousePos (GET_X_LPARAM (lParam) + activeXRect.left - peerRect.left,
  184412. GET_Y_LPARAM (lParam) + activeXRect.top - peerRect.top);
  184413. const int64 mouseEventTime = Win32ComponentPeer::getMouseEventTime();
  184414. ModifierKeys::getCurrentModifiersRealtime(); // to update the mouse button flags
  184415. switch (message)
  184416. {
  184417. case WM_MOUSEMOVE:
  184418. case WM_LBUTTONDOWN:
  184419. case WM_MBUTTONDOWN:
  184420. case WM_RBUTTONDOWN:
  184421. case WM_LBUTTONUP:
  184422. case WM_MBUTTONUP:
  184423. case WM_RBUTTONUP:
  184424. peer->handleMouseEvent (0, mousePos, Win32ComponentPeer::currentModifiers, mouseEventTime);
  184425. break;
  184426. default:
  184427. break;
  184428. }
  184429. }
  184430. }
  184431. class ActiveXControlComponent::ActiveXControlData : public ComponentMovementWatcher
  184432. {
  184433. ActiveXControlComponent* const owner;
  184434. bool wasShowing;
  184435. public:
  184436. HWND controlHWND;
  184437. IStorage* storage;
  184438. IOleClientSite* clientSite;
  184439. IOleObject* control;
  184440. ActiveXControlData (HWND hwnd,
  184441. ActiveXControlComponent* const owner_)
  184442. : ComponentMovementWatcher (owner_),
  184443. owner (owner_),
  184444. wasShowing (owner_ != 0 && owner_->isShowing()),
  184445. controlHWND (0),
  184446. storage (new ActiveXHelpers::JuceIStorage()),
  184447. clientSite (new ActiveXHelpers::JuceIOleClientSite (hwnd)),
  184448. control (0)
  184449. {
  184450. }
  184451. ~ActiveXControlData()
  184452. {
  184453. if (control != 0)
  184454. {
  184455. control->Close (OLECLOSE_NOSAVE);
  184456. control->Release();
  184457. }
  184458. clientSite->Release();
  184459. storage->Release();
  184460. }
  184461. void componentMovedOrResized (bool /*wasMoved*/, bool /*wasResized*/)
  184462. {
  184463. Component* const topComp = owner->getTopLevelComponent();
  184464. if (topComp->getPeer() != 0)
  184465. {
  184466. const Point<int> pos (owner->relativePositionToOtherComponent (topComp, Point<int>()));
  184467. owner->setControlBounds (Rectangle<int> (pos.getX(), pos.getY(), owner->getWidth(), owner->getHeight()));
  184468. }
  184469. }
  184470. void componentPeerChanged()
  184471. {
  184472. const bool isShowingNow = owner->isShowing();
  184473. if (wasShowing != isShowingNow)
  184474. {
  184475. wasShowing = isShowingNow;
  184476. owner->setControlVisible (isShowingNow);
  184477. }
  184478. componentMovedOrResized (true, true);
  184479. }
  184480. void componentVisibilityChanged (Component&)
  184481. {
  184482. componentPeerChanged();
  184483. }
  184484. static bool doesWindowMatch (const ActiveXControlComponent* const ax, HWND hwnd)
  184485. {
  184486. return ((ActiveXControlData*) ax->control) != 0
  184487. && ((ActiveXControlData*) ax->control)->controlHWND == hwnd;
  184488. }
  184489. // intercepts events going to an activeX control, so we can sneakily use the mouse events
  184490. static LRESULT CALLBACK activeXHookWndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
  184491. {
  184492. for (int i = ActiveXHelpers::activeXComps.size(); --i >= 0;)
  184493. {
  184494. const ActiveXControlComponent* const ax = (const ActiveXControlComponent*) ActiveXHelpers::activeXComps.getUnchecked(i);
  184495. if (doesWindowMatch (ax, hwnd))
  184496. {
  184497. switch (message)
  184498. {
  184499. case WM_MOUSEMOVE:
  184500. case WM_LBUTTONDOWN:
  184501. case WM_MBUTTONDOWN:
  184502. case WM_RBUTTONDOWN:
  184503. case WM_LBUTTONUP:
  184504. case WM_MBUTTONUP:
  184505. case WM_RBUTTONUP:
  184506. case WM_LBUTTONDBLCLK:
  184507. case WM_MBUTTONDBLCLK:
  184508. case WM_RBUTTONDBLCLK:
  184509. if (ax->isShowing())
  184510. {
  184511. ComponentPeer* const peer = ax->getPeer();
  184512. if (peer != 0)
  184513. {
  184514. ActiveXHelpers::offerActiveXMouseEventToPeer (peer, hwnd, message, lParam);
  184515. if (! ax->areMouseEventsAllowed())
  184516. return 0;
  184517. }
  184518. }
  184519. break;
  184520. default:
  184521. break;
  184522. }
  184523. return CallWindowProc ((WNDPROC) (ax->originalWndProc), hwnd, message, wParam, lParam);
  184524. }
  184525. }
  184526. return DefWindowProc (hwnd, message, wParam, lParam);
  184527. }
  184528. };
  184529. ActiveXControlComponent::ActiveXControlComponent()
  184530. : originalWndProc (0),
  184531. control (0),
  184532. mouseEventsAllowed (true)
  184533. {
  184534. ActiveXHelpers::activeXComps.add (this);
  184535. }
  184536. ActiveXControlComponent::~ActiveXControlComponent()
  184537. {
  184538. deleteControl();
  184539. ActiveXHelpers::activeXComps.removeValue (this);
  184540. }
  184541. void ActiveXControlComponent::paint (Graphics& g)
  184542. {
  184543. if (control == 0)
  184544. g.fillAll (Colours::lightgrey);
  184545. }
  184546. bool ActiveXControlComponent::createControl (const void* controlIID)
  184547. {
  184548. deleteControl();
  184549. ComponentPeer* const peer = getPeer();
  184550. // the component must have already been added to a real window when you call this!
  184551. jassert (dynamic_cast <Win32ComponentPeer*> (peer) != 0);
  184552. if (dynamic_cast <Win32ComponentPeer*> (peer) != 0)
  184553. {
  184554. const Point<int> pos (relativePositionToOtherComponent (getTopLevelComponent(), Point<int>()));
  184555. HWND hwnd = (HWND) peer->getNativeHandle();
  184556. ScopedPointer <ActiveXControlData> info (new ActiveXControlData (hwnd, this));
  184557. HRESULT hr;
  184558. if ((hr = OleCreate (*(const IID*) controlIID, IID_IOleObject, 1 /*OLERENDER_DRAW*/, 0,
  184559. info->clientSite, info->storage,
  184560. (void**) &(info->control))) == S_OK)
  184561. {
  184562. info->control->SetHostNames (L"Juce", 0);
  184563. if (OleSetContainedObject (info->control, TRUE) == S_OK)
  184564. {
  184565. RECT rect;
  184566. rect.left = pos.getX();
  184567. rect.top = pos.getY();
  184568. rect.right = pos.getX() + getWidth();
  184569. rect.bottom = pos.getY() + getHeight();
  184570. if (info->control->DoVerb (OLEIVERB_SHOW, 0, info->clientSite, 0, hwnd, &rect) == S_OK)
  184571. {
  184572. control = info.release();
  184573. setControlBounds (Rectangle<int> (pos.getX(), pos.getY(), getWidth(), getHeight()));
  184574. ((ActiveXControlData*) control)->controlHWND = ActiveXHelpers::getHWND (this);
  184575. if (((ActiveXControlData*) control)->controlHWND != 0)
  184576. {
  184577. originalWndProc = (void*) (pointer_sized_int) GetWindowLongPtr ((HWND) ((ActiveXControlData*) control)->controlHWND, GWLP_WNDPROC);
  184578. SetWindowLongPtr ((HWND) ((ActiveXControlData*) control)->controlHWND, GWLP_WNDPROC, (LONG_PTR) ActiveXControlData::activeXHookWndProc);
  184579. }
  184580. return true;
  184581. }
  184582. }
  184583. }
  184584. }
  184585. return false;
  184586. }
  184587. void ActiveXControlComponent::deleteControl()
  184588. {
  184589. ActiveXControlData* const info = (ActiveXControlData*) control;
  184590. if (info != 0)
  184591. {
  184592. delete info;
  184593. control = 0;
  184594. originalWndProc = 0;
  184595. }
  184596. }
  184597. void* ActiveXControlComponent::queryInterface (const void* iid) const
  184598. {
  184599. ActiveXControlData* const info = (ActiveXControlData*) control;
  184600. void* result = 0;
  184601. if (info != 0 && info->control != 0
  184602. && info->control->QueryInterface (*(const IID*) iid, &result) == S_OK)
  184603. return result;
  184604. return 0;
  184605. }
  184606. void ActiveXControlComponent::setControlBounds (const Rectangle<int>& newBounds) const
  184607. {
  184608. HWND hwnd = ((ActiveXControlData*) control)->controlHWND;
  184609. if (hwnd != 0)
  184610. MoveWindow (hwnd, newBounds.getX(), newBounds.getY(), newBounds.getWidth(), newBounds.getHeight(), TRUE);
  184611. }
  184612. void ActiveXControlComponent::setControlVisible (const bool shouldBeVisible) const
  184613. {
  184614. HWND hwnd = ((ActiveXControlData*) control)->controlHWND;
  184615. if (hwnd != 0)
  184616. ShowWindow (hwnd, shouldBeVisible ? SW_SHOWNA : SW_HIDE);
  184617. }
  184618. void ActiveXControlComponent::setMouseEventsAllowed (const bool eventsCanReachControl)
  184619. {
  184620. mouseEventsAllowed = eventsCanReachControl;
  184621. }
  184622. #endif
  184623. /*** End of inlined file: juce_win32_ActiveXComponent.cpp ***/
  184624. /*** Start of inlined file: juce_win32_QuickTimeMovieComponent.cpp ***/
  184625. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  184626. // compiled on its own).
  184627. #if JUCE_INCLUDED_FILE && JUCE_QUICKTIME
  184628. using namespace QTOLibrary;
  184629. using namespace QTOControlLib;
  184630. bool juce_OpenQuickTimeMovieFromStream (InputStream* input, Movie& movie, Handle& dataHandle);
  184631. static bool isQTAvailable = false;
  184632. class QuickTimeMovieComponent::Pimpl
  184633. {
  184634. public:
  184635. Pimpl() : dataHandle (0)
  184636. {
  184637. }
  184638. ~Pimpl()
  184639. {
  184640. clearHandle();
  184641. }
  184642. void clearHandle()
  184643. {
  184644. if (dataHandle != 0)
  184645. {
  184646. DisposeHandle (dataHandle);
  184647. dataHandle = 0;
  184648. }
  184649. }
  184650. IQTControlPtr qtControl;
  184651. IQTMoviePtr qtMovie;
  184652. Handle dataHandle;
  184653. };
  184654. QuickTimeMovieComponent::QuickTimeMovieComponent()
  184655. : movieLoaded (false),
  184656. controllerVisible (true)
  184657. {
  184658. pimpl = new Pimpl();
  184659. setMouseEventsAllowed (false);
  184660. }
  184661. QuickTimeMovieComponent::~QuickTimeMovieComponent()
  184662. {
  184663. closeMovie();
  184664. pimpl->qtControl = 0;
  184665. deleteControl();
  184666. pimpl = 0;
  184667. }
  184668. bool QuickTimeMovieComponent::isQuickTimeAvailable() throw()
  184669. {
  184670. if (! isQTAvailable)
  184671. isQTAvailable = (InitializeQTML (0) == noErr) && (EnterMovies() == noErr);
  184672. return isQTAvailable;
  184673. }
  184674. void QuickTimeMovieComponent::createControlIfNeeded()
  184675. {
  184676. if (isShowing() && ! isControlCreated())
  184677. {
  184678. const IID qtIID = __uuidof (QTControl);
  184679. if (createControl (&qtIID))
  184680. {
  184681. const IID qtInterfaceIID = __uuidof (IQTControl);
  184682. pimpl->qtControl = (IQTControl*) queryInterface (&qtInterfaceIID);
  184683. if (pimpl->qtControl != 0)
  184684. {
  184685. pimpl->qtControl->Release(); // it has one ref too many at this point
  184686. pimpl->qtControl->QuickTimeInitialize();
  184687. pimpl->qtControl->PutSizing (qtMovieFitsControl);
  184688. if (movieFile != File::nonexistent)
  184689. loadMovie (movieFile, controllerVisible);
  184690. }
  184691. }
  184692. }
  184693. }
  184694. bool QuickTimeMovieComponent::isControlCreated() const
  184695. {
  184696. return isControlOpen();
  184697. }
  184698. bool QuickTimeMovieComponent::loadMovie (InputStream* movieStream,
  184699. const bool isControllerVisible)
  184700. {
  184701. const ScopedPointer<InputStream> movieStreamDeleter (movieStream);
  184702. movieFile = File::nonexistent;
  184703. movieLoaded = false;
  184704. pimpl->qtMovie = 0;
  184705. controllerVisible = isControllerVisible;
  184706. createControlIfNeeded();
  184707. if (isControlCreated())
  184708. {
  184709. if (pimpl->qtControl != 0)
  184710. {
  184711. pimpl->qtControl->Put_MovieHandle (0);
  184712. pimpl->clearHandle();
  184713. Movie movie;
  184714. if (juce_OpenQuickTimeMovieFromStream (movieStream, movie, pimpl->dataHandle))
  184715. {
  184716. pimpl->qtControl->Put_MovieHandle ((long) (pointer_sized_int) movie);
  184717. pimpl->qtMovie = pimpl->qtControl->GetMovie();
  184718. if (pimpl->qtMovie != 0)
  184719. pimpl->qtMovie->PutMovieControllerType (isControllerVisible ? qtMovieControllerTypeStandard
  184720. : qtMovieControllerTypeNone);
  184721. }
  184722. if (movie == 0)
  184723. pimpl->clearHandle();
  184724. }
  184725. movieLoaded = (pimpl->qtMovie != 0);
  184726. }
  184727. else
  184728. {
  184729. // You're trying to open a movie when the control hasn't yet been created, probably because
  184730. // you've not yet added this component to a Window and made the whole component hierarchy visible.
  184731. jassertfalse
  184732. }
  184733. return movieLoaded;
  184734. }
  184735. void QuickTimeMovieComponent::closeMovie()
  184736. {
  184737. stop();
  184738. movieFile = File::nonexistent;
  184739. movieLoaded = false;
  184740. pimpl->qtMovie = 0;
  184741. if (pimpl->qtControl != 0)
  184742. pimpl->qtControl->Put_MovieHandle (0);
  184743. pimpl->clearHandle();
  184744. }
  184745. const File QuickTimeMovieComponent::getCurrentMovieFile() const
  184746. {
  184747. return movieFile;
  184748. }
  184749. bool QuickTimeMovieComponent::isMovieOpen() const
  184750. {
  184751. return movieLoaded;
  184752. }
  184753. double QuickTimeMovieComponent::getMovieDuration() const
  184754. {
  184755. if (pimpl->qtMovie != 0)
  184756. return pimpl->qtMovie->GetDuration() / (double) pimpl->qtMovie->GetTimeScale();
  184757. return 0.0;
  184758. }
  184759. void QuickTimeMovieComponent::getMovieNormalSize (int& width, int& height) const
  184760. {
  184761. if (pimpl->qtMovie != 0)
  184762. {
  184763. struct QTRECT r = pimpl->qtMovie->GetNaturalRect();
  184764. width = r.right - r.left;
  184765. height = r.bottom - r.top;
  184766. }
  184767. else
  184768. {
  184769. width = height = 0;
  184770. }
  184771. }
  184772. void QuickTimeMovieComponent::play()
  184773. {
  184774. if (pimpl->qtMovie != 0)
  184775. pimpl->qtMovie->Play();
  184776. }
  184777. void QuickTimeMovieComponent::stop()
  184778. {
  184779. if (pimpl->qtMovie != 0)
  184780. pimpl->qtMovie->Stop();
  184781. }
  184782. bool QuickTimeMovieComponent::isPlaying() const
  184783. {
  184784. return pimpl->qtMovie != 0 && pimpl->qtMovie->GetRate() != 0.0f;
  184785. }
  184786. void QuickTimeMovieComponent::setPosition (const double seconds)
  184787. {
  184788. if (pimpl->qtMovie != 0)
  184789. pimpl->qtMovie->PutTime ((long) (seconds * pimpl->qtMovie->GetTimeScale()));
  184790. }
  184791. double QuickTimeMovieComponent::getPosition() const
  184792. {
  184793. if (pimpl->qtMovie != 0)
  184794. return pimpl->qtMovie->GetTime() / (double) pimpl->qtMovie->GetTimeScale();
  184795. return 0.0;
  184796. }
  184797. void QuickTimeMovieComponent::setSpeed (const float newSpeed)
  184798. {
  184799. if (pimpl->qtMovie != 0)
  184800. pimpl->qtMovie->PutRate (newSpeed);
  184801. }
  184802. void QuickTimeMovieComponent::setMovieVolume (const float newVolume)
  184803. {
  184804. if (pimpl->qtMovie != 0)
  184805. {
  184806. pimpl->qtMovie->PutAudioVolume (newVolume);
  184807. pimpl->qtMovie->PutAudioMute (newVolume <= 0);
  184808. }
  184809. }
  184810. float QuickTimeMovieComponent::getMovieVolume() const
  184811. {
  184812. if (pimpl->qtMovie != 0)
  184813. return pimpl->qtMovie->GetAudioVolume();
  184814. return 0.0f;
  184815. }
  184816. void QuickTimeMovieComponent::setLooping (const bool shouldLoop)
  184817. {
  184818. if (pimpl->qtMovie != 0)
  184819. pimpl->qtMovie->PutLoop (shouldLoop);
  184820. }
  184821. bool QuickTimeMovieComponent::isLooping() const
  184822. {
  184823. return pimpl->qtMovie != 0 && pimpl->qtMovie->GetLoop();
  184824. }
  184825. bool QuickTimeMovieComponent::isControllerVisible() const
  184826. {
  184827. return controllerVisible;
  184828. }
  184829. void QuickTimeMovieComponent::parentHierarchyChanged()
  184830. {
  184831. createControlIfNeeded();
  184832. QTCompBaseClass::parentHierarchyChanged();
  184833. }
  184834. void QuickTimeMovieComponent::visibilityChanged()
  184835. {
  184836. createControlIfNeeded();
  184837. QTCompBaseClass::visibilityChanged();
  184838. }
  184839. void QuickTimeMovieComponent::paint (Graphics& g)
  184840. {
  184841. if (! isControlCreated())
  184842. g.fillAll (Colours::black);
  184843. }
  184844. static Handle createHandleDataRef (Handle dataHandle, const char* fileName)
  184845. {
  184846. Handle dataRef = 0;
  184847. OSStatus err = PtrToHand (&dataHandle, &dataRef, sizeof (Handle));
  184848. if (err == noErr)
  184849. {
  184850. Str255 suffix;
  184851. CharacterFunctions::copy ((char*) suffix, fileName, 128);
  184852. StringPtr name = suffix;
  184853. err = PtrAndHand (name, dataRef, name[0] + 1);
  184854. if (err == noErr)
  184855. {
  184856. long atoms[3];
  184857. atoms[0] = EndianU32_NtoB (3 * sizeof (long));
  184858. atoms[1] = EndianU32_NtoB (kDataRefExtensionMacOSFileType);
  184859. atoms[2] = EndianU32_NtoB (MovieFileType);
  184860. err = PtrAndHand (atoms, dataRef, 3 * sizeof (long));
  184861. if (err == noErr)
  184862. return dataRef;
  184863. }
  184864. DisposeHandle (dataRef);
  184865. }
  184866. return 0;
  184867. }
  184868. static CFStringRef juceStringToCFString (const String& s)
  184869. {
  184870. const int len = s.length();
  184871. const juce_wchar* const t = (const juce_wchar*) s;
  184872. HeapBlock <UniChar> temp (len + 2);
  184873. for (int i = 0; i <= len; ++i)
  184874. temp[i] = t[i];
  184875. return CFStringCreateWithCharacters (kCFAllocatorDefault, temp, len);
  184876. }
  184877. static bool openMovie (QTNewMoviePropertyElement* props, int prop, Movie& movie)
  184878. {
  184879. Boolean trueBool = true;
  184880. props[prop].propClass = kQTPropertyClass_MovieInstantiation;
  184881. props[prop].propID = kQTMovieInstantiationPropertyID_DontResolveDataRefs;
  184882. props[prop].propValueSize = sizeof (trueBool);
  184883. props[prop].propValueAddress = &trueBool;
  184884. ++prop;
  184885. props[prop].propClass = kQTPropertyClass_MovieInstantiation;
  184886. props[prop].propID = kQTMovieInstantiationPropertyID_AsyncOK;
  184887. props[prop].propValueSize = sizeof (trueBool);
  184888. props[prop].propValueAddress = &trueBool;
  184889. ++prop;
  184890. Boolean isActive = true;
  184891. props[prop].propClass = kQTPropertyClass_NewMovieProperty;
  184892. props[prop].propID = kQTNewMoviePropertyID_Active;
  184893. props[prop].propValueSize = sizeof (isActive);
  184894. props[prop].propValueAddress = &isActive;
  184895. ++prop;
  184896. MacSetPort (0);
  184897. jassert (prop <= 5);
  184898. OSStatus err = NewMovieFromProperties (prop, props, 0, 0, &movie);
  184899. return err == noErr;
  184900. }
  184901. bool juce_OpenQuickTimeMovieFromStream (InputStream* input, Movie& movie, Handle& dataHandle)
  184902. {
  184903. if (input == 0)
  184904. return false;
  184905. dataHandle = 0;
  184906. bool ok = false;
  184907. QTNewMoviePropertyElement props[5];
  184908. zeromem (props, sizeof (props));
  184909. int prop = 0;
  184910. DataReferenceRecord dr;
  184911. props[prop].propClass = kQTPropertyClass_DataLocation;
  184912. props[prop].propID = kQTDataLocationPropertyID_DataReference;
  184913. props[prop].propValueSize = sizeof (dr);
  184914. props[prop].propValueAddress = (void*) &dr;
  184915. ++prop;
  184916. FileInputStream* const fin = dynamic_cast <FileInputStream*> (input);
  184917. if (fin != 0)
  184918. {
  184919. CFStringRef filePath = juceStringToCFString (fin->getFile().getFullPathName());
  184920. QTNewDataReferenceFromFullPathCFString (filePath, (QTPathStyle) kQTNativeDefaultPathStyle, 0,
  184921. &dr.dataRef, &dr.dataRefType);
  184922. ok = openMovie (props, prop, movie);
  184923. DisposeHandle (dr.dataRef);
  184924. CFRelease (filePath);
  184925. }
  184926. else
  184927. {
  184928. // sanity-check because this currently needs to load the whole stream into memory..
  184929. jassert (input->getTotalLength() < 50 * 1024 * 1024);
  184930. dataHandle = NewHandle ((Size) input->getTotalLength());
  184931. HLock (dataHandle);
  184932. // read the entire stream into memory - this is a pain, but can't get it to work
  184933. // properly using a custom callback to supply the data.
  184934. input->read (*dataHandle, (int) input->getTotalLength());
  184935. HUnlock (dataHandle);
  184936. // different types to get QT to try. (We should really be a bit smarter here by
  184937. // working out in advance which one the stream contains, rather than just trying
  184938. // each one)
  184939. const char* const suffixesToTry[] = { "\04.mov", "\04.mp3",
  184940. "\04.avi", "\04.m4a" };
  184941. for (int i = 0; i < numElementsInArray (suffixesToTry) && ! ok; ++i)
  184942. {
  184943. dr.dataRef = createHandleDataRef (dataHandle, suffixesToTry [i]);
  184944. dr.dataRefType = HandleDataHandlerSubType;
  184945. ok = openMovie (props, prop, movie);
  184946. DisposeHandle (dr.dataRef);
  184947. }
  184948. }
  184949. return ok;
  184950. }
  184951. bool QuickTimeMovieComponent::loadMovie (const File& movieFile_,
  184952. const bool isControllerVisible)
  184953. {
  184954. const bool ok = loadMovie (static_cast <InputStream*> (movieFile_.createInputStream()), isControllerVisible);
  184955. movieFile = movieFile_;
  184956. return ok;
  184957. }
  184958. bool QuickTimeMovieComponent::loadMovie (const URL& movieURL,
  184959. const bool isControllerVisible)
  184960. {
  184961. return loadMovie (static_cast <InputStream*> (movieURL.createInputStream (false)), isControllerVisible);
  184962. }
  184963. void QuickTimeMovieComponent::goToStart()
  184964. {
  184965. setPosition (0.0);
  184966. }
  184967. void QuickTimeMovieComponent::setBoundsWithCorrectAspectRatio (const Rectangle<int>& spaceToFitWithin,
  184968. const RectanglePlacement& placement)
  184969. {
  184970. int normalWidth, normalHeight;
  184971. getMovieNormalSize (normalWidth, normalHeight);
  184972. if (normalWidth > 0 && normalHeight > 0 && ! spaceToFitWithin.isEmpty())
  184973. {
  184974. double x = 0.0, y = 0.0, w = normalWidth, h = normalHeight;
  184975. placement.applyTo (x, y, w, h,
  184976. spaceToFitWithin.getX(), spaceToFitWithin.getY(),
  184977. spaceToFitWithin.getWidth(), spaceToFitWithin.getHeight());
  184978. if (w > 0 && h > 0)
  184979. {
  184980. setBounds (roundToInt (x), roundToInt (y),
  184981. roundToInt (w), roundToInt (h));
  184982. }
  184983. }
  184984. else
  184985. {
  184986. setBounds (spaceToFitWithin);
  184987. }
  184988. }
  184989. #endif
  184990. /*** End of inlined file: juce_win32_QuickTimeMovieComponent.cpp ***/
  184991. /*** Start of inlined file: juce_win32_WebBrowserComponent.cpp ***/
  184992. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  184993. // compiled on its own).
  184994. #if JUCE_INCLUDED_FILE && JUCE_WEB_BROWSER
  184995. class WebBrowserComponentInternal : public ActiveXControlComponent
  184996. {
  184997. public:
  184998. WebBrowserComponentInternal()
  184999. : browser (0),
  185000. connectionPoint (0),
  185001. adviseCookie (0)
  185002. {
  185003. }
  185004. ~WebBrowserComponentInternal()
  185005. {
  185006. if (connectionPoint != 0)
  185007. connectionPoint->Unadvise (adviseCookie);
  185008. if (browser != 0)
  185009. browser->Release();
  185010. }
  185011. void createBrowser()
  185012. {
  185013. createControl (&CLSID_WebBrowser);
  185014. browser = (IWebBrowser2*) queryInterface (&IID_IWebBrowser2);
  185015. IConnectionPointContainer* connectionPointContainer = (IConnectionPointContainer*) queryInterface (&IID_IConnectionPointContainer);
  185016. if (connectionPointContainer != 0)
  185017. {
  185018. connectionPointContainer->FindConnectionPoint (DIID_DWebBrowserEvents2,
  185019. &connectionPoint);
  185020. if (connectionPoint != 0)
  185021. {
  185022. WebBrowserComponent* const owner = dynamic_cast <WebBrowserComponent*> (getParentComponent());
  185023. jassert (owner != 0);
  185024. EventHandler* handler = new EventHandler (owner);
  185025. connectionPoint->Advise (handler, &adviseCookie);
  185026. }
  185027. }
  185028. }
  185029. void goToURL (const String& url,
  185030. const StringArray* headers,
  185031. const MemoryBlock* postData)
  185032. {
  185033. if (browser != 0)
  185034. {
  185035. LPSAFEARRAY sa = 0;
  185036. VARIANT flags, frame, postDataVar, headersVar; // (_variant_t isn't available in all compilers)
  185037. VariantInit (&flags);
  185038. VariantInit (&frame);
  185039. VariantInit (&postDataVar);
  185040. VariantInit (&headersVar);
  185041. if (headers != 0)
  185042. {
  185043. V_VT (&headersVar) = VT_BSTR;
  185044. V_BSTR (&headersVar) = SysAllocString ((const tchar*) headers->joinIntoString ("\r\n"));
  185045. }
  185046. if (postData != 0 && postData->getSize() > 0)
  185047. {
  185048. LPSAFEARRAY sa = SafeArrayCreateVector (VT_UI1, 0, postData->getSize());
  185049. if (sa != 0)
  185050. {
  185051. void* data = 0;
  185052. SafeArrayAccessData (sa, &data);
  185053. jassert (data != 0);
  185054. if (data != 0)
  185055. {
  185056. postData->copyTo (data, 0, postData->getSize());
  185057. SafeArrayUnaccessData (sa);
  185058. VARIANT postDataVar2;
  185059. VariantInit (&postDataVar2);
  185060. V_VT (&postDataVar2) = VT_ARRAY | VT_UI1;
  185061. V_ARRAY (&postDataVar2) = sa;
  185062. postDataVar = postDataVar2;
  185063. }
  185064. }
  185065. }
  185066. browser->Navigate ((BSTR) (const OLECHAR*) url,
  185067. &flags, &frame,
  185068. &postDataVar, &headersVar);
  185069. if (sa != 0)
  185070. SafeArrayDestroy (sa);
  185071. VariantClear (&flags);
  185072. VariantClear (&frame);
  185073. VariantClear (&postDataVar);
  185074. VariantClear (&headersVar);
  185075. }
  185076. }
  185077. IWebBrowser2* browser;
  185078. juce_UseDebuggingNewOperator
  185079. private:
  185080. IConnectionPoint* connectionPoint;
  185081. DWORD adviseCookie;
  185082. class EventHandler : public IDispatch,
  185083. public ComponentMovementWatcher
  185084. {
  185085. public:
  185086. EventHandler (WebBrowserComponent* owner_)
  185087. : ComponentMovementWatcher (owner_),
  185088. owner (owner_),
  185089. refCount (0)
  185090. {
  185091. }
  185092. ~EventHandler()
  185093. {
  185094. }
  185095. HRESULT __stdcall QueryInterface (REFIID id, void __RPC_FAR* __RPC_FAR* result)
  185096. {
  185097. if (id == IID_IUnknown || id == IID_IDispatch || id == DIID_DWebBrowserEvents2)
  185098. {
  185099. AddRef();
  185100. *result = this;
  185101. return S_OK;
  185102. }
  185103. *result = 0;
  185104. return E_NOINTERFACE;
  185105. }
  185106. ULONG __stdcall AddRef() { return ++refCount; }
  185107. ULONG __stdcall Release() { jassert (refCount > 0); const int r = --refCount; if (r == 0) delete this; return r; }
  185108. HRESULT __stdcall GetTypeInfoCount (UINT __RPC_FAR*) { return E_NOTIMPL; }
  185109. HRESULT __stdcall GetTypeInfo (UINT, LCID, ITypeInfo __RPC_FAR *__RPC_FAR*) { return E_NOTIMPL; }
  185110. HRESULT __stdcall GetIDsOfNames (REFIID, LPOLESTR __RPC_FAR*, UINT, LCID, DISPID __RPC_FAR*) { return E_NOTIMPL; }
  185111. HRESULT __stdcall Invoke (DISPID dispIdMember, REFIID /*riid*/, LCID /*lcid*/,
  185112. WORD /*wFlags*/, DISPPARAMS __RPC_FAR* pDispParams,
  185113. VARIANT __RPC_FAR* /*pVarResult*/, EXCEPINFO __RPC_FAR* /*pExcepInfo*/,
  185114. UINT __RPC_FAR* /*puArgErr*/)
  185115. {
  185116. switch (dispIdMember)
  185117. {
  185118. case DISPID_BEFORENAVIGATE2:
  185119. {
  185120. VARIANT* const vurl = pDispParams->rgvarg[5].pvarVal;
  185121. String url;
  185122. if ((vurl->vt & VT_BYREF) != 0)
  185123. url = *vurl->pbstrVal;
  185124. else
  185125. url = vurl->bstrVal;
  185126. *pDispParams->rgvarg->pboolVal
  185127. = owner->pageAboutToLoad (url) ? VARIANT_FALSE
  185128. : VARIANT_TRUE;
  185129. return S_OK;
  185130. }
  185131. default:
  185132. break;
  185133. }
  185134. return E_NOTIMPL;
  185135. }
  185136. void componentMovedOrResized (bool /*wasMoved*/, bool /*wasResized*/) {}
  185137. void componentPeerChanged() {}
  185138. void componentVisibilityChanged (Component&)
  185139. {
  185140. owner->visibilityChanged();
  185141. }
  185142. juce_UseDebuggingNewOperator
  185143. private:
  185144. WebBrowserComponent* const owner;
  185145. int refCount;
  185146. EventHandler (const EventHandler&);
  185147. EventHandler& operator= (const EventHandler&);
  185148. };
  185149. };
  185150. WebBrowserComponent::WebBrowserComponent (const bool unloadPageWhenBrowserIsHidden_)
  185151. : browser (0),
  185152. blankPageShown (false),
  185153. unloadPageWhenBrowserIsHidden (unloadPageWhenBrowserIsHidden_)
  185154. {
  185155. setOpaque (true);
  185156. addAndMakeVisible (browser = new WebBrowserComponentInternal());
  185157. }
  185158. WebBrowserComponent::~WebBrowserComponent()
  185159. {
  185160. delete browser;
  185161. }
  185162. void WebBrowserComponent::goToURL (const String& url,
  185163. const StringArray* headers,
  185164. const MemoryBlock* postData)
  185165. {
  185166. lastURL = url;
  185167. lastHeaders.clear();
  185168. if (headers != 0)
  185169. lastHeaders = *headers;
  185170. lastPostData.setSize (0);
  185171. if (postData != 0)
  185172. lastPostData = *postData;
  185173. blankPageShown = false;
  185174. browser->goToURL (url, headers, postData);
  185175. }
  185176. void WebBrowserComponent::stop()
  185177. {
  185178. if (browser->browser != 0)
  185179. browser->browser->Stop();
  185180. }
  185181. void WebBrowserComponent::goBack()
  185182. {
  185183. lastURL = String::empty;
  185184. blankPageShown = false;
  185185. if (browser->browser != 0)
  185186. browser->browser->GoBack();
  185187. }
  185188. void WebBrowserComponent::goForward()
  185189. {
  185190. lastURL = String::empty;
  185191. if (browser->browser != 0)
  185192. browser->browser->GoForward();
  185193. }
  185194. void WebBrowserComponent::refresh()
  185195. {
  185196. if (browser->browser != 0)
  185197. browser->browser->Refresh();
  185198. }
  185199. void WebBrowserComponent::paint (Graphics& g)
  185200. {
  185201. if (browser->browser == 0)
  185202. g.fillAll (Colours::white);
  185203. }
  185204. void WebBrowserComponent::checkWindowAssociation()
  185205. {
  185206. if (isShowing())
  185207. {
  185208. if (browser->browser == 0 && getPeer() != 0)
  185209. {
  185210. browser->createBrowser();
  185211. reloadLastURL();
  185212. }
  185213. else
  185214. {
  185215. if (blankPageShown)
  185216. goBack();
  185217. }
  185218. }
  185219. else
  185220. {
  185221. if (browser != 0 && unloadPageWhenBrowserIsHidden && ! blankPageShown)
  185222. {
  185223. // when the component becomes invisible, some stuff like flash
  185224. // carries on playing audio, so we need to force it onto a blank
  185225. // page to avoid this..
  185226. blankPageShown = true;
  185227. browser->goToURL ("about:blank", 0, 0);
  185228. }
  185229. }
  185230. }
  185231. void WebBrowserComponent::reloadLastURL()
  185232. {
  185233. if (lastURL.isNotEmpty())
  185234. {
  185235. goToURL (lastURL, &lastHeaders, &lastPostData);
  185236. lastURL = String::empty;
  185237. }
  185238. }
  185239. void WebBrowserComponent::parentHierarchyChanged()
  185240. {
  185241. checkWindowAssociation();
  185242. }
  185243. void WebBrowserComponent::resized()
  185244. {
  185245. browser->setSize (getWidth(), getHeight());
  185246. }
  185247. void WebBrowserComponent::visibilityChanged()
  185248. {
  185249. checkWindowAssociation();
  185250. }
  185251. bool WebBrowserComponent::pageAboutToLoad (const String&)
  185252. {
  185253. return true;
  185254. }
  185255. #endif
  185256. /*** End of inlined file: juce_win32_WebBrowserComponent.cpp ***/
  185257. /*** Start of inlined file: juce_win32_OpenGLComponent.cpp ***/
  185258. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  185259. // compiled on its own).
  185260. #if JUCE_INCLUDED_FILE && JUCE_OPENGL
  185261. #define WGL_EXT_FUNCTION_INIT(extType, extFunc) \
  185262. ((extFunc = (extType) wglGetProcAddress (#extFunc)) != 0)
  185263. typedef const char* (WINAPI* PFNWGLGETEXTENSIONSSTRINGARBPROC) (HDC hdc);
  185264. typedef BOOL (WINAPI * PFNWGLGETPIXELFORMATATTRIBIVARBPROC) (HDC hdc, int iPixelFormat, int iLayerPlane, UINT nAttributes, const int *piAttributes, int *piValues);
  185265. typedef BOOL (WINAPI * PFNWGLCHOOSEPIXELFORMATARBPROC) (HDC hdc, const int* piAttribIList, const FLOAT *pfAttribFList, UINT nMaxFormats, int *piFormats, UINT *nNumFormats);
  185266. typedef BOOL (WINAPI * PFNWGLSWAPINTERVALEXTPROC) (int interval);
  185267. typedef int (WINAPI * PFNWGLGETSWAPINTERVALEXTPROC) (void);
  185268. #define WGL_NUMBER_PIXEL_FORMATS_ARB 0x2000
  185269. #define WGL_DRAW_TO_WINDOW_ARB 0x2001
  185270. #define WGL_ACCELERATION_ARB 0x2003
  185271. #define WGL_SWAP_METHOD_ARB 0x2007
  185272. #define WGL_SUPPORT_OPENGL_ARB 0x2010
  185273. #define WGL_PIXEL_TYPE_ARB 0x2013
  185274. #define WGL_DOUBLE_BUFFER_ARB 0x2011
  185275. #define WGL_COLOR_BITS_ARB 0x2014
  185276. #define WGL_RED_BITS_ARB 0x2015
  185277. #define WGL_GREEN_BITS_ARB 0x2017
  185278. #define WGL_BLUE_BITS_ARB 0x2019
  185279. #define WGL_ALPHA_BITS_ARB 0x201B
  185280. #define WGL_DEPTH_BITS_ARB 0x2022
  185281. #define WGL_STENCIL_BITS_ARB 0x2023
  185282. #define WGL_FULL_ACCELERATION_ARB 0x2027
  185283. #define WGL_ACCUM_RED_BITS_ARB 0x201E
  185284. #define WGL_ACCUM_GREEN_BITS_ARB 0x201F
  185285. #define WGL_ACCUM_BLUE_BITS_ARB 0x2020
  185286. #define WGL_ACCUM_ALPHA_BITS_ARB 0x2021
  185287. #define WGL_STEREO_ARB 0x2012
  185288. #define WGL_SAMPLE_BUFFERS_ARB 0x2041
  185289. #define WGL_SAMPLES_ARB 0x2042
  185290. #define WGL_TYPE_RGBA_ARB 0x202B
  185291. static void getWglExtensions (HDC dc, StringArray& result) throw()
  185292. {
  185293. PFNWGLGETEXTENSIONSSTRINGARBPROC wglGetExtensionsStringARB = 0;
  185294. if (WGL_EXT_FUNCTION_INIT (PFNWGLGETEXTENSIONSSTRINGARBPROC, wglGetExtensionsStringARB))
  185295. result.addTokens (String (wglGetExtensionsStringARB (dc)), false);
  185296. else
  185297. jassertfalse // If this fails, it may be because you didn't activate the openGL context
  185298. }
  185299. class WindowedGLContext : public OpenGLContext
  185300. {
  185301. public:
  185302. WindowedGLContext (Component* const component_,
  185303. HGLRC contextToShareWith,
  185304. const OpenGLPixelFormat& pixelFormat)
  185305. : renderContext (0),
  185306. nativeWindow (0),
  185307. dc (0),
  185308. component (component_)
  185309. {
  185310. jassert (component != 0);
  185311. createNativeWindow();
  185312. // Use a default pixel format that should be supported everywhere
  185313. PIXELFORMATDESCRIPTOR pfd;
  185314. zerostruct (pfd);
  185315. pfd.nSize = sizeof (pfd);
  185316. pfd.nVersion = 1;
  185317. pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
  185318. pfd.iPixelType = PFD_TYPE_RGBA;
  185319. pfd.cColorBits = 24;
  185320. pfd.cDepthBits = 16;
  185321. const int format = ChoosePixelFormat (dc, &pfd);
  185322. if (format != 0)
  185323. SetPixelFormat (dc, format, &pfd);
  185324. renderContext = wglCreateContext (dc);
  185325. makeActive();
  185326. setPixelFormat (pixelFormat);
  185327. if (contextToShareWith != 0 && renderContext != 0)
  185328. wglShareLists (contextToShareWith, renderContext);
  185329. }
  185330. ~WindowedGLContext()
  185331. {
  185332. makeInactive();
  185333. wglDeleteContext (renderContext);
  185334. ReleaseDC ((HWND) nativeWindow->getNativeHandle(), dc);
  185335. delete nativeWindow;
  185336. }
  185337. bool makeActive() const throw()
  185338. {
  185339. jassert (renderContext != 0);
  185340. return wglMakeCurrent (dc, renderContext) != 0;
  185341. }
  185342. bool makeInactive() const throw()
  185343. {
  185344. return (! isActive()) || (wglMakeCurrent (0, 0) != 0);
  185345. }
  185346. bool isActive() const throw()
  185347. {
  185348. return wglGetCurrentContext() == renderContext;
  185349. }
  185350. const OpenGLPixelFormat getPixelFormat() const
  185351. {
  185352. OpenGLPixelFormat pf;
  185353. makeActive();
  185354. StringArray availableExtensions;
  185355. getWglExtensions (dc, availableExtensions);
  185356. fillInPixelFormatDetails (GetPixelFormat (dc), pf, availableExtensions);
  185357. return pf;
  185358. }
  185359. void* getRawContext() const throw()
  185360. {
  185361. return renderContext;
  185362. }
  185363. bool setPixelFormat (const OpenGLPixelFormat& pixelFormat)
  185364. {
  185365. makeActive();
  185366. PIXELFORMATDESCRIPTOR pfd;
  185367. zerostruct (pfd);
  185368. pfd.nSize = sizeof (pfd);
  185369. pfd.nVersion = 1;
  185370. pfd.dwFlags = PFD_SUPPORT_OPENGL | PFD_DRAW_TO_WINDOW | PFD_DOUBLEBUFFER;
  185371. pfd.iPixelType = PFD_TYPE_RGBA;
  185372. pfd.iLayerType = PFD_MAIN_PLANE;
  185373. pfd.cColorBits = (BYTE) (pixelFormat.redBits + pixelFormat.greenBits + pixelFormat.blueBits);
  185374. pfd.cRedBits = (BYTE) pixelFormat.redBits;
  185375. pfd.cGreenBits = (BYTE) pixelFormat.greenBits;
  185376. pfd.cBlueBits = (BYTE) pixelFormat.blueBits;
  185377. pfd.cAlphaBits = (BYTE) pixelFormat.alphaBits;
  185378. pfd.cDepthBits = (BYTE) pixelFormat.depthBufferBits;
  185379. pfd.cStencilBits = (BYTE) pixelFormat.stencilBufferBits;
  185380. pfd.cAccumBits = (BYTE) (pixelFormat.accumulationBufferRedBits + pixelFormat.accumulationBufferGreenBits
  185381. + pixelFormat.accumulationBufferBlueBits + pixelFormat.accumulationBufferAlphaBits);
  185382. pfd.cAccumRedBits = (BYTE) pixelFormat.accumulationBufferRedBits;
  185383. pfd.cAccumGreenBits = (BYTE) pixelFormat.accumulationBufferGreenBits;
  185384. pfd.cAccumBlueBits = (BYTE) pixelFormat.accumulationBufferBlueBits;
  185385. pfd.cAccumAlphaBits = (BYTE) pixelFormat.accumulationBufferAlphaBits;
  185386. int format = 0;
  185387. PFNWGLCHOOSEPIXELFORMATARBPROC wglChoosePixelFormatARB = 0;
  185388. StringArray availableExtensions;
  185389. getWglExtensions (dc, availableExtensions);
  185390. if (availableExtensions.contains ("WGL_ARB_pixel_format")
  185391. && WGL_EXT_FUNCTION_INIT (PFNWGLCHOOSEPIXELFORMATARBPROC, wglChoosePixelFormatARB))
  185392. {
  185393. int attributes[64];
  185394. int n = 0;
  185395. attributes[n++] = WGL_DRAW_TO_WINDOW_ARB;
  185396. attributes[n++] = GL_TRUE;
  185397. attributes[n++] = WGL_SUPPORT_OPENGL_ARB;
  185398. attributes[n++] = GL_TRUE;
  185399. attributes[n++] = WGL_ACCELERATION_ARB;
  185400. attributes[n++] = WGL_FULL_ACCELERATION_ARB;
  185401. attributes[n++] = WGL_DOUBLE_BUFFER_ARB;
  185402. attributes[n++] = GL_TRUE;
  185403. attributes[n++] = WGL_PIXEL_TYPE_ARB;
  185404. attributes[n++] = WGL_TYPE_RGBA_ARB;
  185405. attributes[n++] = WGL_COLOR_BITS_ARB;
  185406. attributes[n++] = pfd.cColorBits;
  185407. attributes[n++] = WGL_RED_BITS_ARB;
  185408. attributes[n++] = pixelFormat.redBits;
  185409. attributes[n++] = WGL_GREEN_BITS_ARB;
  185410. attributes[n++] = pixelFormat.greenBits;
  185411. attributes[n++] = WGL_BLUE_BITS_ARB;
  185412. attributes[n++] = pixelFormat.blueBits;
  185413. attributes[n++] = WGL_ALPHA_BITS_ARB;
  185414. attributes[n++] = pixelFormat.alphaBits;
  185415. attributes[n++] = WGL_DEPTH_BITS_ARB;
  185416. attributes[n++] = pixelFormat.depthBufferBits;
  185417. if (pixelFormat.stencilBufferBits > 0)
  185418. {
  185419. attributes[n++] = WGL_STENCIL_BITS_ARB;
  185420. attributes[n++] = pixelFormat.stencilBufferBits;
  185421. }
  185422. attributes[n++] = WGL_ACCUM_RED_BITS_ARB;
  185423. attributes[n++] = pixelFormat.accumulationBufferRedBits;
  185424. attributes[n++] = WGL_ACCUM_GREEN_BITS_ARB;
  185425. attributes[n++] = pixelFormat.accumulationBufferGreenBits;
  185426. attributes[n++] = WGL_ACCUM_BLUE_BITS_ARB;
  185427. attributes[n++] = pixelFormat.accumulationBufferBlueBits;
  185428. attributes[n++] = WGL_ACCUM_ALPHA_BITS_ARB;
  185429. attributes[n++] = pixelFormat.accumulationBufferAlphaBits;
  185430. if (availableExtensions.contains ("WGL_ARB_multisample")
  185431. && pixelFormat.fullSceneAntiAliasingNumSamples > 0)
  185432. {
  185433. attributes[n++] = WGL_SAMPLE_BUFFERS_ARB;
  185434. attributes[n++] = 1;
  185435. attributes[n++] = WGL_SAMPLES_ARB;
  185436. attributes[n++] = pixelFormat.fullSceneAntiAliasingNumSamples;
  185437. }
  185438. attributes[n++] = 0;
  185439. UINT formatsCount;
  185440. const BOOL ok = wglChoosePixelFormatARB (dc, attributes, 0, 1, &format, &formatsCount);
  185441. (void) ok;
  185442. jassert (ok);
  185443. }
  185444. else
  185445. {
  185446. format = ChoosePixelFormat (dc, &pfd);
  185447. }
  185448. if (format != 0)
  185449. {
  185450. makeInactive();
  185451. // win32 can't change the pixel format of a window, so need to delete the
  185452. // old one and create a new one..
  185453. jassert (nativeWindow != 0);
  185454. ReleaseDC ((HWND) nativeWindow->getNativeHandle(), dc);
  185455. delete nativeWindow;
  185456. createNativeWindow();
  185457. if (SetPixelFormat (dc, format, &pfd))
  185458. {
  185459. wglDeleteContext (renderContext);
  185460. renderContext = wglCreateContext (dc);
  185461. jassert (renderContext != 0);
  185462. return renderContext != 0;
  185463. }
  185464. }
  185465. return false;
  185466. }
  185467. void updateWindowPosition (int x, int y, int w, int h, int)
  185468. {
  185469. SetWindowPos ((HWND) nativeWindow->getNativeHandle(), 0,
  185470. x, y, w, h,
  185471. SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOOWNERZORDER);
  185472. }
  185473. void repaint()
  185474. {
  185475. const Rectangle<int> bounds (nativeWindow->getBounds());
  185476. nativeWindow->repaint (0, 0, bounds.getWidth(), bounds.getHeight());
  185477. }
  185478. void swapBuffers()
  185479. {
  185480. SwapBuffers (dc);
  185481. }
  185482. bool setSwapInterval (const int numFramesPerSwap)
  185483. {
  185484. makeActive();
  185485. StringArray availableExtensions;
  185486. getWglExtensions (dc, availableExtensions);
  185487. PFNWGLSWAPINTERVALEXTPROC wglSwapIntervalEXT = 0;
  185488. return availableExtensions.contains ("WGL_EXT_swap_control")
  185489. && WGL_EXT_FUNCTION_INIT (PFNWGLSWAPINTERVALEXTPROC, wglSwapIntervalEXT)
  185490. && wglSwapIntervalEXT (numFramesPerSwap) != FALSE;
  185491. }
  185492. int getSwapInterval() const
  185493. {
  185494. makeActive();
  185495. StringArray availableExtensions;
  185496. getWglExtensions (dc, availableExtensions);
  185497. PFNWGLGETSWAPINTERVALEXTPROC wglGetSwapIntervalEXT = 0;
  185498. if (availableExtensions.contains ("WGL_EXT_swap_control")
  185499. && WGL_EXT_FUNCTION_INIT (PFNWGLGETSWAPINTERVALEXTPROC, wglGetSwapIntervalEXT))
  185500. return wglGetSwapIntervalEXT();
  185501. return 0;
  185502. }
  185503. void findAlternativeOpenGLPixelFormats (OwnedArray <OpenGLPixelFormat>& results)
  185504. {
  185505. jassert (isActive());
  185506. StringArray availableExtensions;
  185507. getWglExtensions (dc, availableExtensions);
  185508. PFNWGLGETPIXELFORMATATTRIBIVARBPROC wglGetPixelFormatAttribivARB = 0;
  185509. int numTypes = 0;
  185510. if (availableExtensions.contains("WGL_ARB_pixel_format")
  185511. && WGL_EXT_FUNCTION_INIT (PFNWGLGETPIXELFORMATATTRIBIVARBPROC, wglGetPixelFormatAttribivARB))
  185512. {
  185513. int attributes = WGL_NUMBER_PIXEL_FORMATS_ARB;
  185514. if (! wglGetPixelFormatAttribivARB (dc, 1, 0, 1, &attributes, &numTypes))
  185515. jassertfalse
  185516. }
  185517. else
  185518. {
  185519. numTypes = DescribePixelFormat (dc, 0, 0, 0);
  185520. }
  185521. OpenGLPixelFormat pf;
  185522. for (int i = 0; i < numTypes; ++i)
  185523. {
  185524. if (fillInPixelFormatDetails (i + 1, pf, availableExtensions))
  185525. {
  185526. bool alreadyListed = false;
  185527. for (int j = results.size(); --j >= 0;)
  185528. if (pf == *results.getUnchecked(j))
  185529. alreadyListed = true;
  185530. if (! alreadyListed)
  185531. results.add (new OpenGLPixelFormat (pf));
  185532. }
  185533. }
  185534. }
  185535. void* getNativeWindowHandle() const
  185536. {
  185537. return nativeWindow != 0 ? nativeWindow->getNativeHandle() : 0;
  185538. }
  185539. juce_UseDebuggingNewOperator
  185540. HGLRC renderContext;
  185541. private:
  185542. Win32ComponentPeer* nativeWindow;
  185543. Component* const component;
  185544. HDC dc;
  185545. void createNativeWindow()
  185546. {
  185547. nativeWindow = new Win32ComponentPeer (component, 0);
  185548. nativeWindow->dontRepaint = true;
  185549. nativeWindow->setVisible (true);
  185550. HWND hwnd = (HWND) nativeWindow->getNativeHandle();
  185551. Win32ComponentPeer* const peer = dynamic_cast <Win32ComponentPeer*> (component->getTopLevelComponent()->getPeer());
  185552. if (peer != 0)
  185553. {
  185554. SetParent (hwnd, (HWND) peer->getNativeHandle());
  185555. juce_setWindowStyleBit (hwnd, GWL_STYLE, WS_CHILD, true);
  185556. juce_setWindowStyleBit (hwnd, GWL_STYLE, WS_POPUP, false);
  185557. }
  185558. dc = GetDC (hwnd);
  185559. }
  185560. bool fillInPixelFormatDetails (const int pixelFormatIndex,
  185561. OpenGLPixelFormat& result,
  185562. const StringArray& availableExtensions) const throw()
  185563. {
  185564. PFNWGLGETPIXELFORMATATTRIBIVARBPROC wglGetPixelFormatAttribivARB = 0;
  185565. if (availableExtensions.contains ("WGL_ARB_pixel_format")
  185566. && WGL_EXT_FUNCTION_INIT (PFNWGLGETPIXELFORMATATTRIBIVARBPROC, wglGetPixelFormatAttribivARB))
  185567. {
  185568. int attributes[32];
  185569. int numAttributes = 0;
  185570. attributes[numAttributes++] = WGL_DRAW_TO_WINDOW_ARB;
  185571. attributes[numAttributes++] = WGL_SUPPORT_OPENGL_ARB;
  185572. attributes[numAttributes++] = WGL_ACCELERATION_ARB;
  185573. attributes[numAttributes++] = WGL_DOUBLE_BUFFER_ARB;
  185574. attributes[numAttributes++] = WGL_PIXEL_TYPE_ARB;
  185575. attributes[numAttributes++] = WGL_RED_BITS_ARB;
  185576. attributes[numAttributes++] = WGL_GREEN_BITS_ARB;
  185577. attributes[numAttributes++] = WGL_BLUE_BITS_ARB;
  185578. attributes[numAttributes++] = WGL_ALPHA_BITS_ARB;
  185579. attributes[numAttributes++] = WGL_DEPTH_BITS_ARB;
  185580. attributes[numAttributes++] = WGL_STENCIL_BITS_ARB;
  185581. attributes[numAttributes++] = WGL_ACCUM_RED_BITS_ARB;
  185582. attributes[numAttributes++] = WGL_ACCUM_GREEN_BITS_ARB;
  185583. attributes[numAttributes++] = WGL_ACCUM_BLUE_BITS_ARB;
  185584. attributes[numAttributes++] = WGL_ACCUM_ALPHA_BITS_ARB;
  185585. if (availableExtensions.contains ("WGL_ARB_multisample"))
  185586. attributes[numAttributes++] = WGL_SAMPLES_ARB;
  185587. int values[32];
  185588. zeromem (values, sizeof (values));
  185589. if (wglGetPixelFormatAttribivARB (dc, pixelFormatIndex, 0, numAttributes, attributes, values))
  185590. {
  185591. int n = 0;
  185592. bool isValidFormat = (values[n++] == GL_TRUE); // WGL_DRAW_TO_WINDOW_ARB
  185593. isValidFormat = (values[n++] == GL_TRUE) && isValidFormat; // WGL_SUPPORT_OPENGL_ARB
  185594. isValidFormat = (values[n++] == WGL_FULL_ACCELERATION_ARB) && isValidFormat; // WGL_ACCELERATION_ARB
  185595. isValidFormat = (values[n++] == GL_TRUE) && isValidFormat; // WGL_DOUBLE_BUFFER_ARB:
  185596. isValidFormat = (values[n++] == WGL_TYPE_RGBA_ARB) && isValidFormat; // WGL_PIXEL_TYPE_ARB
  185597. result.redBits = values[n++]; // WGL_RED_BITS_ARB
  185598. result.greenBits = values[n++]; // WGL_GREEN_BITS_ARB
  185599. result.blueBits = values[n++]; // WGL_BLUE_BITS_ARB
  185600. result.alphaBits = values[n++]; // WGL_ALPHA_BITS_ARB
  185601. result.depthBufferBits = values[n++]; // WGL_DEPTH_BITS_ARB
  185602. result.stencilBufferBits = values[n++]; // WGL_STENCIL_BITS_ARB
  185603. result.accumulationBufferRedBits = values[n++]; // WGL_ACCUM_RED_BITS_ARB
  185604. result.accumulationBufferGreenBits = values[n++]; // WGL_ACCUM_GREEN_BITS_ARB
  185605. result.accumulationBufferBlueBits = values[n++]; // WGL_ACCUM_BLUE_BITS_ARB
  185606. result.accumulationBufferAlphaBits = values[n++]; // WGL_ACCUM_ALPHA_BITS_ARB
  185607. result.fullSceneAntiAliasingNumSamples = (uint8) values[n++]; // WGL_SAMPLES_ARB
  185608. return isValidFormat;
  185609. }
  185610. else
  185611. {
  185612. jassertfalse
  185613. }
  185614. }
  185615. else
  185616. {
  185617. PIXELFORMATDESCRIPTOR pfd;
  185618. if (DescribePixelFormat (dc, pixelFormatIndex, sizeof (pfd), &pfd))
  185619. {
  185620. result.redBits = pfd.cRedBits;
  185621. result.greenBits = pfd.cGreenBits;
  185622. result.blueBits = pfd.cBlueBits;
  185623. result.alphaBits = pfd.cAlphaBits;
  185624. result.depthBufferBits = pfd.cDepthBits;
  185625. result.stencilBufferBits = pfd.cStencilBits;
  185626. result.accumulationBufferRedBits = pfd.cAccumRedBits;
  185627. result.accumulationBufferGreenBits = pfd.cAccumGreenBits;
  185628. result.accumulationBufferBlueBits = pfd.cAccumBlueBits;
  185629. result.accumulationBufferAlphaBits = pfd.cAccumAlphaBits;
  185630. result.fullSceneAntiAliasingNumSamples = 0;
  185631. return true;
  185632. }
  185633. else
  185634. {
  185635. jassertfalse
  185636. }
  185637. }
  185638. return false;
  185639. }
  185640. WindowedGLContext (const WindowedGLContext&);
  185641. WindowedGLContext& operator= (const WindowedGLContext&);
  185642. };
  185643. OpenGLContext* OpenGLComponent::createContext()
  185644. {
  185645. ScopedPointer<WindowedGLContext> c (new WindowedGLContext (this,
  185646. contextToShareListsWith != 0 ? (HGLRC) contextToShareListsWith->getRawContext() : 0,
  185647. preferredPixelFormat));
  185648. return (c->renderContext != 0) ? c.release() : 0;
  185649. }
  185650. void* OpenGLComponent::getNativeWindowHandle() const
  185651. {
  185652. return context != 0 ? ((WindowedGLContext*) context)->getNativeWindowHandle() : 0;
  185653. }
  185654. void juce_glViewport (const int w, const int h)
  185655. {
  185656. glViewport (0, 0, w, h);
  185657. }
  185658. void OpenGLPixelFormat::getAvailablePixelFormats (Component* component,
  185659. OwnedArray <OpenGLPixelFormat>& results)
  185660. {
  185661. Component tempComp;
  185662. {
  185663. WindowedGLContext wc (component, 0, OpenGLPixelFormat (8, 8, 16, 0));
  185664. wc.makeActive();
  185665. wc.findAlternativeOpenGLPixelFormats (results);
  185666. }
  185667. }
  185668. #endif
  185669. /*** End of inlined file: juce_win32_OpenGLComponent.cpp ***/
  185670. /*** Start of inlined file: juce_win32_AudioCDReader.cpp ***/
  185671. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  185672. // compiled on its own).
  185673. #if JUCE_INCLUDED_FILE
  185674. #if JUCE_USE_CDREADER
  185675. namespace CDReaderHelpers
  185676. {
  185677. //***************************************************************************
  185678. // %%% TARGET STATUS VALUES %%%
  185679. //***************************************************************************
  185680. #define STATUS_GOOD 0x00 // Status Good
  185681. #define STATUS_CHKCOND 0x02 // Check Condition
  185682. #define STATUS_CONDMET 0x04 // Condition Met
  185683. #define STATUS_BUSY 0x08 // Busy
  185684. #define STATUS_INTERM 0x10 // Intermediate
  185685. #define STATUS_INTCDMET 0x14 // Intermediate-condition met
  185686. #define STATUS_RESCONF 0x18 // Reservation conflict
  185687. #define STATUS_COMTERM 0x22 // Command Terminated
  185688. #define STATUS_QFULL 0x28 // Queue full
  185689. //***************************************************************************
  185690. // %%% SCSI MISCELLANEOUS EQUATES %%%
  185691. //***************************************************************************
  185692. #define MAXLUN 7 // Maximum Logical Unit Id
  185693. #define MAXTARG 7 // Maximum Target Id
  185694. #define MAX_SCSI_LUNS 64 // Maximum Number of SCSI LUNs
  185695. #define MAX_NUM_HA 8 // Maximum Number of SCSI HA's
  185696. //***************************************************************************
  185697. // %%% Commands for all Device Types %%%
  185698. //***************************************************************************
  185699. #define SCSI_CHANGE_DEF 0x40 // Change Definition (Optional)
  185700. #define SCSI_COMPARE 0x39 // Compare (O)
  185701. #define SCSI_COPY 0x18 // Copy (O)
  185702. #define SCSI_COP_VERIFY 0x3A // Copy and Verify (O)
  185703. #define SCSI_INQUIRY 0x12 // Inquiry (MANDATORY)
  185704. #define SCSI_LOG_SELECT 0x4C // Log Select (O)
  185705. #define SCSI_LOG_SENSE 0x4D // Log Sense (O)
  185706. #define SCSI_MODE_SEL6 0x15 // Mode Select 6-byte (Device Specific)
  185707. #define SCSI_MODE_SEL10 0x55 // Mode Select 10-byte (Device Specific)
  185708. #define SCSI_MODE_SEN6 0x1A // Mode Sense 6-byte (Device Specific)
  185709. #define SCSI_MODE_SEN10 0x5A // Mode Sense 10-byte (Device Specific)
  185710. #define SCSI_READ_BUFF 0x3C // Read Buffer (O)
  185711. #define SCSI_REQ_SENSE 0x03 // Request Sense (MANDATORY)
  185712. #define SCSI_SEND_DIAG 0x1D // Send Diagnostic (O)
  185713. #define SCSI_TST_U_RDY 0x00 // Test Unit Ready (MANDATORY)
  185714. #define SCSI_WRITE_BUFF 0x3B // Write Buffer (O)
  185715. //***************************************************************************
  185716. // %%% Commands Unique to Direct Access Devices %%%
  185717. //***************************************************************************
  185718. #define SCSI_COMPARE 0x39 // Compare (O)
  185719. #define SCSI_FORMAT 0x04 // Format Unit (MANDATORY)
  185720. #define SCSI_LCK_UN_CAC 0x36 // Lock Unlock Cache (O)
  185721. #define SCSI_PREFETCH 0x34 // Prefetch (O)
  185722. #define SCSI_MED_REMOVL 0x1E // Prevent/Allow medium Removal (O)
  185723. #define SCSI_READ6 0x08 // Read 6-byte (MANDATORY)
  185724. #define SCSI_READ10 0x28 // Read 10-byte (MANDATORY)
  185725. #define SCSI_RD_CAPAC 0x25 // Read Capacity (MANDATORY)
  185726. #define SCSI_RD_DEFECT 0x37 // Read Defect Data (O)
  185727. #define SCSI_READ_LONG 0x3E // Read Long (O)
  185728. #define SCSI_REASS_BLK 0x07 // Reassign Blocks (O)
  185729. #define SCSI_RCV_DIAG 0x1C // Receive Diagnostic Results (O)
  185730. #define SCSI_RELEASE 0x17 // Release Unit (MANDATORY)
  185731. #define SCSI_REZERO 0x01 // Rezero Unit (O)
  185732. #define SCSI_SRCH_DAT_E 0x31 // Search Data Equal (O)
  185733. #define SCSI_SRCH_DAT_H 0x30 // Search Data High (O)
  185734. #define SCSI_SRCH_DAT_L 0x32 // Search Data Low (O)
  185735. #define SCSI_SEEK6 0x0B // Seek 6-Byte (O)
  185736. #define SCSI_SEEK10 0x2B // Seek 10-Byte (O)
  185737. #define SCSI_SEND_DIAG 0x1D // Send Diagnostics (MANDATORY)
  185738. #define SCSI_SET_LIMIT 0x33 // Set Limits (O)
  185739. #define SCSI_START_STP 0x1B // Start/Stop Unit (O)
  185740. #define SCSI_SYNC_CACHE 0x35 // Synchronize Cache (O)
  185741. #define SCSI_VERIFY 0x2F // Verify (O)
  185742. #define SCSI_WRITE6 0x0A // Write 6-Byte (MANDATORY)
  185743. #define SCSI_WRITE10 0x2A // Write 10-Byte (MANDATORY)
  185744. #define SCSI_WRT_VERIFY 0x2E // Write and Verify (O)
  185745. #define SCSI_WRITE_LONG 0x3F // Write Long (O)
  185746. #define SCSI_WRITE_SAME 0x41 // Write Same (O)
  185747. //***************************************************************************
  185748. // %%% Commands Unique to Sequential Access Devices %%%
  185749. //***************************************************************************
  185750. #define SCSI_ERASE 0x19 // Erase (MANDATORY)
  185751. #define SCSI_LOAD_UN 0x1b // Load/Unload (O)
  185752. #define SCSI_LOCATE 0x2B // Locate (O)
  185753. #define SCSI_RD_BLK_LIM 0x05 // Read Block Limits (MANDATORY)
  185754. #define SCSI_READ_POS 0x34 // Read Position (O)
  185755. #define SCSI_READ_REV 0x0F // Read Reverse (O)
  185756. #define SCSI_REC_BF_DAT 0x14 // Recover Buffer Data (O)
  185757. #define SCSI_RESERVE 0x16 // Reserve Unit (MANDATORY)
  185758. #define SCSI_REWIND 0x01 // Rewind (MANDATORY)
  185759. #define SCSI_SPACE 0x11 // Space (MANDATORY)
  185760. #define SCSI_VERIFY_T 0x13 // Verify (Tape) (O)
  185761. #define SCSI_WRT_FILE 0x10 // Write Filemarks (MANDATORY)
  185762. //***************************************************************************
  185763. // %%% Commands Unique to Printer Devices %%%
  185764. //***************************************************************************
  185765. #define SCSI_PRINT 0x0A // Print (MANDATORY)
  185766. #define SCSI_SLEW_PNT 0x0B // Slew and Print (O)
  185767. #define SCSI_STOP_PNT 0x1B // Stop Print (O)
  185768. #define SCSI_SYNC_BUFF 0x10 // Synchronize Buffer (O)
  185769. //***************************************************************************
  185770. // %%% Commands Unique to Processor Devices %%%
  185771. //***************************************************************************
  185772. #define SCSI_RECEIVE 0x08 // Receive (O)
  185773. #define SCSI_SEND 0x0A // Send (O)
  185774. //***************************************************************************
  185775. // %%% Commands Unique to Write-Once Devices %%%
  185776. //***************************************************************************
  185777. #define SCSI_MEDIUM_SCN 0x38 // Medium Scan (O)
  185778. #define SCSI_SRCHDATE10 0x31 // Search Data Equal 10-Byte (O)
  185779. #define SCSI_SRCHDATE12 0xB1 // Search Data Equal 12-Byte (O)
  185780. #define SCSI_SRCHDATH10 0x30 // Search Data High 10-Byte (O)
  185781. #define SCSI_SRCHDATH12 0xB0 // Search Data High 12-Byte (O)
  185782. #define SCSI_SRCHDATL10 0x32 // Search Data Low 10-Byte (O)
  185783. #define SCSI_SRCHDATL12 0xB2 // Search Data Low 12-Byte (O)
  185784. #define SCSI_SET_LIM_10 0x33 // Set Limits 10-Byte (O)
  185785. #define SCSI_SET_LIM_12 0xB3 // Set Limits 10-Byte (O)
  185786. #define SCSI_VERIFY10 0x2F // Verify 10-Byte (O)
  185787. #define SCSI_VERIFY12 0xAF // Verify 12-Byte (O)
  185788. #define SCSI_WRITE12 0xAA // Write 12-Byte (O)
  185789. #define SCSI_WRT_VER10 0x2E // Write and Verify 10-Byte (O)
  185790. #define SCSI_WRT_VER12 0xAE // Write and Verify 12-Byte (O)
  185791. //***************************************************************************
  185792. // %%% Commands Unique to CD-ROM Devices %%%
  185793. //***************************************************************************
  185794. #define SCSI_PLAYAUD_10 0x45 // Play Audio 10-Byte (O)
  185795. #define SCSI_PLAYAUD_12 0xA5 // Play Audio 12-Byte 12-Byte (O)
  185796. #define SCSI_PLAYAUDMSF 0x47 // Play Audio MSF (O)
  185797. #define SCSI_PLAYA_TKIN 0x48 // Play Audio Track/Index (O)
  185798. #define SCSI_PLYTKREL10 0x49 // Play Track Relative 10-Byte (O)
  185799. #define SCSI_PLYTKREL12 0xA9 // Play Track Relative 12-Byte (O)
  185800. #define SCSI_READCDCAP 0x25 // Read CD-ROM Capacity (MANDATORY)
  185801. #define SCSI_READHEADER 0x44 // Read Header (O)
  185802. #define SCSI_SUBCHANNEL 0x42 // Read Subchannel (O)
  185803. #define SCSI_READ_TOC 0x43 // Read TOC (O)
  185804. //***************************************************************************
  185805. // %%% Commands Unique to Scanner Devices %%%
  185806. //***************************************************************************
  185807. #define SCSI_GETDBSTAT 0x34 // Get Data Buffer Status (O)
  185808. #define SCSI_GETWINDOW 0x25 // Get Window (O)
  185809. #define SCSI_OBJECTPOS 0x31 // Object Postion (O)
  185810. #define SCSI_SCAN 0x1B // Scan (O)
  185811. #define SCSI_SETWINDOW 0x24 // Set Window (MANDATORY)
  185812. //***************************************************************************
  185813. // %%% Commands Unique to Optical Memory Devices %%%
  185814. //***************************************************************************
  185815. #define SCSI_UpdateBlk 0x3D // Update Block (O)
  185816. //***************************************************************************
  185817. // %%% Commands Unique to Medium Changer Devices %%%
  185818. //***************************************************************************
  185819. #define SCSI_EXCHMEDIUM 0xA6 // Exchange Medium (O)
  185820. #define SCSI_INITELSTAT 0x07 // Initialize Element Status (O)
  185821. #define SCSI_POSTOELEM 0x2B // Position to Element (O)
  185822. #define SCSI_REQ_VE_ADD 0xB5 // Request Volume Element Address (O)
  185823. #define SCSI_SENDVOLTAG 0xB6 // Send Volume Tag (O)
  185824. //***************************************************************************
  185825. // %%% Commands Unique to Communication Devices %%%
  185826. //***************************************************************************
  185827. #define SCSI_GET_MSG_6 0x08 // Get Message 6-Byte (MANDATORY)
  185828. #define SCSI_GET_MSG_10 0x28 // Get Message 10-Byte (O)
  185829. #define SCSI_GET_MSG_12 0xA8 // Get Message 12-Byte (O)
  185830. #define SCSI_SND_MSG_6 0x0A // Send Message 6-Byte (MANDATORY)
  185831. #define SCSI_SND_MSG_10 0x2A // Send Message 10-Byte (O)
  185832. #define SCSI_SND_MSG_12 0xAA // Send Message 12-Byte (O)
  185833. //***************************************************************************
  185834. // %%% Request Sense Data Format %%%
  185835. //***************************************************************************
  185836. typedef struct {
  185837. BYTE ErrorCode; // Error Code (70H or 71H)
  185838. BYTE SegmentNum; // Number of current segment descriptor
  185839. BYTE SenseKey; // Sense Key(See bit definitions too)
  185840. BYTE InfoByte0; // Information MSB
  185841. BYTE InfoByte1; // Information MID
  185842. BYTE InfoByte2; // Information MID
  185843. BYTE InfoByte3; // Information LSB
  185844. BYTE AddSenLen; // Additional Sense Length
  185845. BYTE ComSpecInf0; // Command Specific Information MSB
  185846. BYTE ComSpecInf1; // Command Specific Information MID
  185847. BYTE ComSpecInf2; // Command Specific Information MID
  185848. BYTE ComSpecInf3; // Command Specific Information LSB
  185849. BYTE AddSenseCode; // Additional Sense Code
  185850. BYTE AddSenQual; // Additional Sense Code Qualifier
  185851. BYTE FieldRepUCode; // Field Replaceable Unit Code
  185852. BYTE SenKeySpec15; // Sense Key Specific 15th byte
  185853. BYTE SenKeySpec16; // Sense Key Specific 16th byte
  185854. BYTE SenKeySpec17; // Sense Key Specific 17th byte
  185855. BYTE AddSenseBytes; // Additional Sense Bytes
  185856. } SENSE_DATA_FMT;
  185857. //***************************************************************************
  185858. // %%% REQUEST SENSE ERROR CODE %%%
  185859. //***************************************************************************
  185860. #define SERROR_CURRENT 0x70 // Current Errors
  185861. #define SERROR_DEFERED 0x71 // Deferred Errors
  185862. //***************************************************************************
  185863. // %%% REQUEST SENSE BIT DEFINITIONS %%%
  185864. //***************************************************************************
  185865. #define SENSE_VALID 0x80 // Byte 0 Bit 7
  185866. #define SENSE_FILEMRK 0x80 // Byte 2 Bit 7
  185867. #define SENSE_EOM 0x40 // Byte 2 Bit 6
  185868. #define SENSE_ILI 0x20 // Byte 2 Bit 5
  185869. //***************************************************************************
  185870. // %%% REQUEST SENSE SENSE KEY DEFINITIONS %%%
  185871. //***************************************************************************
  185872. #define KEY_NOSENSE 0x00 // No Sense
  185873. #define KEY_RECERROR 0x01 // Recovered Error
  185874. #define KEY_NOTREADY 0x02 // Not Ready
  185875. #define KEY_MEDIUMERR 0x03 // Medium Error
  185876. #define KEY_HARDERROR 0x04 // Hardware Error
  185877. #define KEY_ILLGLREQ 0x05 // Illegal Request
  185878. #define KEY_UNITATT 0x06 // Unit Attention
  185879. #define KEY_DATAPROT 0x07 // Data Protect
  185880. #define KEY_BLANKCHK 0x08 // Blank Check
  185881. #define KEY_VENDSPEC 0x09 // Vendor Specific
  185882. #define KEY_COPYABORT 0x0A // Copy Abort
  185883. #define KEY_EQUAL 0x0C // Equal (Search)
  185884. #define KEY_VOLOVRFLW 0x0D // Volume Overflow
  185885. #define KEY_MISCOMP 0x0E // Miscompare (Search)
  185886. #define KEY_RESERVED 0x0F // Reserved
  185887. //***************************************************************************
  185888. // %%% PERIPHERAL DEVICE TYPE DEFINITIONS %%%
  185889. //***************************************************************************
  185890. #define DTYPE_DASD 0x00 // Disk Device
  185891. #define DTYPE_SEQD 0x01 // Tape Device
  185892. #define DTYPE_PRNT 0x02 // Printer
  185893. #define DTYPE_PROC 0x03 // Processor
  185894. #define DTYPE_WORM 0x04 // Write-once read-multiple
  185895. #define DTYPE_CROM 0x05 // CD-ROM device
  185896. #define DTYPE_SCAN 0x06 // Scanner device
  185897. #define DTYPE_OPTI 0x07 // Optical memory device
  185898. #define DTYPE_JUKE 0x08 // Medium Changer device
  185899. #define DTYPE_COMM 0x09 // Communications device
  185900. #define DTYPE_RESL 0x0A // Reserved (low)
  185901. #define DTYPE_RESH 0x1E // Reserved (high)
  185902. #define DTYPE_UNKNOWN 0x1F // Unknown or no device type
  185903. //***************************************************************************
  185904. // %%% ANSI APPROVED VERSION DEFINITIONS %%%
  185905. //***************************************************************************
  185906. #define ANSI_MAYBE 0x0 // Device may or may not be ANSI approved stand
  185907. #define ANSI_SCSI1 0x1 // Device complies to ANSI X3.131-1986 (SCSI-1)
  185908. #define ANSI_SCSI2 0x2 // Device complies to SCSI-2
  185909. #define ANSI_RESLO 0x3 // Reserved (low)
  185910. #define ANSI_RESHI 0x7 // Reserved (high)
  185911. typedef struct
  185912. {
  185913. USHORT Length;
  185914. UCHAR ScsiStatus;
  185915. UCHAR PathId;
  185916. UCHAR TargetId;
  185917. UCHAR Lun;
  185918. UCHAR CdbLength;
  185919. UCHAR SenseInfoLength;
  185920. UCHAR DataIn;
  185921. ULONG DataTransferLength;
  185922. ULONG TimeOutValue;
  185923. ULONG DataBufferOffset;
  185924. ULONG SenseInfoOffset;
  185925. UCHAR Cdb[16];
  185926. } SCSI_PASS_THROUGH, *PSCSI_PASS_THROUGH;
  185927. typedef struct
  185928. {
  185929. USHORT Length;
  185930. UCHAR ScsiStatus;
  185931. UCHAR PathId;
  185932. UCHAR TargetId;
  185933. UCHAR Lun;
  185934. UCHAR CdbLength;
  185935. UCHAR SenseInfoLength;
  185936. UCHAR DataIn;
  185937. ULONG DataTransferLength;
  185938. ULONG TimeOutValue;
  185939. PVOID DataBuffer;
  185940. ULONG SenseInfoOffset;
  185941. UCHAR Cdb[16];
  185942. } SCSI_PASS_THROUGH_DIRECT, *PSCSI_PASS_THROUGH_DIRECT;
  185943. typedef struct
  185944. {
  185945. SCSI_PASS_THROUGH_DIRECT spt;
  185946. ULONG Filler;
  185947. UCHAR ucSenseBuf[32];
  185948. } SCSI_PASS_THROUGH_DIRECT_WITH_BUFFER, *PSCSI_PASS_THROUGH_DIRECT_WITH_BUFFER;
  185949. typedef struct
  185950. {
  185951. ULONG Length;
  185952. UCHAR PortNumber;
  185953. UCHAR PathId;
  185954. UCHAR TargetId;
  185955. UCHAR Lun;
  185956. } SCSI_ADDRESS, *PSCSI_ADDRESS;
  185957. #define METHOD_BUFFERED 0
  185958. #define METHOD_IN_DIRECT 1
  185959. #define METHOD_OUT_DIRECT 2
  185960. #define METHOD_NEITHER 3
  185961. #define FILE_ANY_ACCESS 0
  185962. #ifndef FILE_READ_ACCESS
  185963. #define FILE_READ_ACCESS (0x0001)
  185964. #endif
  185965. #ifndef FILE_WRITE_ACCESS
  185966. #define FILE_WRITE_ACCESS (0x0002)
  185967. #endif
  185968. #define IOCTL_SCSI_BASE 0x00000004
  185969. #define SCSI_IOCTL_DATA_OUT 0
  185970. #define SCSI_IOCTL_DATA_IN 1
  185971. #define SCSI_IOCTL_DATA_UNSPECIFIED 2
  185972. #define CTL_CODE2( DevType, Function, Method, Access ) ( \
  185973. ((DevType) << 16) | ((Access) << 14) | ((Function) << 2) | (Method) \
  185974. )
  185975. #define IOCTL_SCSI_PASS_THROUGH CTL_CODE2( IOCTL_SCSI_BASE, 0x0401, METHOD_BUFFERED, FILE_READ_ACCESS | FILE_WRITE_ACCESS )
  185976. #define IOCTL_SCSI_GET_CAPABILITIES CTL_CODE2( IOCTL_SCSI_BASE, 0x0404, METHOD_BUFFERED, FILE_ANY_ACCESS)
  185977. #define IOCTL_SCSI_PASS_THROUGH_DIRECT CTL_CODE2( IOCTL_SCSI_BASE, 0x0405, METHOD_BUFFERED, FILE_READ_ACCESS | FILE_WRITE_ACCESS )
  185978. #define IOCTL_SCSI_GET_ADDRESS CTL_CODE2( IOCTL_SCSI_BASE, 0x0406, METHOD_BUFFERED, FILE_ANY_ACCESS )
  185979. #define SENSE_LEN 14
  185980. #define SRB_DIR_SCSI 0x00
  185981. #define SRB_POSTING 0x01
  185982. #define SRB_ENABLE_RESIDUAL_COUNT 0x04
  185983. #define SRB_DIR_IN 0x08
  185984. #define SRB_DIR_OUT 0x10
  185985. #define SRB_EVENT_NOTIFY 0x40
  185986. #define RESIDUAL_COUNT_SUPPORTED 0x02
  185987. #define MAX_SRB_TIMEOUT 1080001u
  185988. #define DEFAULT_SRB_TIMEOUT 1080001u
  185989. #define SC_HA_INQUIRY 0x00
  185990. #define SC_GET_DEV_TYPE 0x01
  185991. #define SC_EXEC_SCSI_CMD 0x02
  185992. #define SC_ABORT_SRB 0x03
  185993. #define SC_RESET_DEV 0x04
  185994. #define SC_SET_HA_PARMS 0x05
  185995. #define SC_GET_DISK_INFO 0x06
  185996. #define SC_RESCAN_SCSI_BUS 0x07
  185997. #define SC_GETSET_TIMEOUTS 0x08
  185998. #define SS_PENDING 0x00
  185999. #define SS_COMP 0x01
  186000. #define SS_ABORTED 0x02
  186001. #define SS_ABORT_FAIL 0x03
  186002. #define SS_ERR 0x04
  186003. #define SS_INVALID_CMD 0x80
  186004. #define SS_INVALID_HA 0x81
  186005. #define SS_NO_DEVICE 0x82
  186006. #define SS_INVALID_SRB 0xE0
  186007. #define SS_OLD_MANAGER 0xE1
  186008. #define SS_BUFFER_ALIGN 0xE1
  186009. #define SS_ILLEGAL_MODE 0xE2
  186010. #define SS_NO_ASPI 0xE3
  186011. #define SS_FAILED_INIT 0xE4
  186012. #define SS_ASPI_IS_BUSY 0xE5
  186013. #define SS_BUFFER_TO_BIG 0xE6
  186014. #define SS_BUFFER_TOO_BIG 0xE6
  186015. #define SS_MISMATCHED_COMPONENTS 0xE7
  186016. #define SS_NO_ADAPTERS 0xE8
  186017. #define SS_INSUFFICIENT_RESOURCES 0xE9
  186018. #define SS_ASPI_IS_SHUTDOWN 0xEA
  186019. #define SS_BAD_INSTALL 0xEB
  186020. #define HASTAT_OK 0x00
  186021. #define HASTAT_SEL_TO 0x11
  186022. #define HASTAT_DO_DU 0x12
  186023. #define HASTAT_BUS_FREE 0x13
  186024. #define HASTAT_PHASE_ERR 0x14
  186025. #define HASTAT_TIMEOUT 0x09
  186026. #define HASTAT_COMMAND_TIMEOUT 0x0B
  186027. #define HASTAT_MESSAGE_REJECT 0x0D
  186028. #define HASTAT_BUS_RESET 0x0E
  186029. #define HASTAT_PARITY_ERROR 0x0F
  186030. #define HASTAT_REQUEST_SENSE_FAILED 0x10
  186031. #define PACKED
  186032. #pragma pack(1)
  186033. typedef struct
  186034. {
  186035. BYTE SRB_Cmd;
  186036. BYTE SRB_Status;
  186037. BYTE SRB_HaID;
  186038. BYTE SRB_Flags;
  186039. DWORD SRB_Hdr_Rsvd;
  186040. BYTE HA_Count;
  186041. BYTE HA_SCSI_ID;
  186042. BYTE HA_ManagerId[16];
  186043. BYTE HA_Identifier[16];
  186044. BYTE HA_Unique[16];
  186045. WORD HA_Rsvd1;
  186046. BYTE pad[20];
  186047. } PACKED SRB_HAInquiry, *PSRB_HAInquiry, FAR *LPSRB_HAInquiry;
  186048. typedef struct
  186049. {
  186050. BYTE SRB_Cmd;
  186051. BYTE SRB_Status;
  186052. BYTE SRB_HaID;
  186053. BYTE SRB_Flags;
  186054. DWORD SRB_Hdr_Rsvd;
  186055. BYTE SRB_Target;
  186056. BYTE SRB_Lun;
  186057. BYTE SRB_DeviceType;
  186058. BYTE SRB_Rsvd1;
  186059. BYTE pad[68];
  186060. } PACKED SRB_GDEVBlock, *PSRB_GDEVBlock, FAR *LPSRB_GDEVBlock;
  186061. typedef struct
  186062. {
  186063. BYTE SRB_Cmd;
  186064. BYTE SRB_Status;
  186065. BYTE SRB_HaID;
  186066. BYTE SRB_Flags;
  186067. DWORD SRB_Hdr_Rsvd;
  186068. BYTE SRB_Target;
  186069. BYTE SRB_Lun;
  186070. WORD SRB_Rsvd1;
  186071. DWORD SRB_BufLen;
  186072. BYTE FAR *SRB_BufPointer;
  186073. BYTE SRB_SenseLen;
  186074. BYTE SRB_CDBLen;
  186075. BYTE SRB_HaStat;
  186076. BYTE SRB_TargStat;
  186077. VOID FAR *SRB_PostProc;
  186078. BYTE SRB_Rsvd2[20];
  186079. BYTE CDBByte[16];
  186080. BYTE SenseArea[SENSE_LEN+2];
  186081. } PACKED SRB_ExecSCSICmd, *PSRB_ExecSCSICmd, FAR *LPSRB_ExecSCSICmd;
  186082. typedef struct
  186083. {
  186084. BYTE SRB_Cmd;
  186085. BYTE SRB_Status;
  186086. BYTE SRB_HaId;
  186087. BYTE SRB_Flags;
  186088. DWORD SRB_Hdr_Rsvd;
  186089. } PACKED SRB, *PSRB, FAR *LPSRB;
  186090. #pragma pack()
  186091. struct CDDeviceInfo
  186092. {
  186093. char vendor[9];
  186094. char productId[17];
  186095. char rev[5];
  186096. char vendorSpec[21];
  186097. BYTE ha;
  186098. BYTE tgt;
  186099. BYTE lun;
  186100. char scsiDriveLetter; // will be 0 if not using scsi
  186101. };
  186102. class CDReadBuffer
  186103. {
  186104. public:
  186105. int startFrame;
  186106. int numFrames;
  186107. int dataStartOffset;
  186108. int dataLength;
  186109. BYTE* buffer;
  186110. int bufferSize;
  186111. int index;
  186112. bool wantsIndex;
  186113. CDReadBuffer (const int numberOfFrames)
  186114. : startFrame (0),
  186115. numFrames (0),
  186116. dataStartOffset (0),
  186117. dataLength (0),
  186118. index (0),
  186119. wantsIndex (false)
  186120. {
  186121. bufferSize = 2352 * numberOfFrames;
  186122. buffer = (BYTE*) juce_malloc (bufferSize);
  186123. }
  186124. ~CDReadBuffer()
  186125. {
  186126. juce_free (buffer);
  186127. }
  186128. bool isZero() const
  186129. {
  186130. BYTE* p = buffer + dataStartOffset;
  186131. for (int i = dataLength; --i >= 0;)
  186132. if (*p++ != 0)
  186133. return false;
  186134. return true;
  186135. }
  186136. };
  186137. class CDDeviceHandle;
  186138. class CDController
  186139. {
  186140. public:
  186141. CDController();
  186142. virtual ~CDController();
  186143. virtual bool read (CDReadBuffer* t) = 0;
  186144. virtual void shutDown();
  186145. bool readAudio (CDReadBuffer* t, CDReadBuffer* overlapBuffer = 0);
  186146. int getLastIndex();
  186147. public:
  186148. bool initialised;
  186149. CDDeviceHandle* deviceInfo;
  186150. int framesToCheck, framesOverlap;
  186151. void prepare (SRB_ExecSCSICmd& s);
  186152. void perform (SRB_ExecSCSICmd& s);
  186153. void setPaused (bool paused);
  186154. };
  186155. #pragma pack(1)
  186156. struct TOCTRACK
  186157. {
  186158. BYTE rsvd;
  186159. BYTE ADR;
  186160. BYTE trackNumber;
  186161. BYTE rsvd2;
  186162. BYTE addr[4];
  186163. };
  186164. struct TOC
  186165. {
  186166. WORD tocLen;
  186167. BYTE firstTrack;
  186168. BYTE lastTrack;
  186169. TOCTRACK tracks[100];
  186170. };
  186171. #pragma pack()
  186172. enum
  186173. {
  186174. READTYPE_ANY = 0,
  186175. READTYPE_ATAPI1 = 1,
  186176. READTYPE_ATAPI2 = 2,
  186177. READTYPE_READ6 = 3,
  186178. READTYPE_READ10 = 4,
  186179. READTYPE_READ_D8 = 5,
  186180. READTYPE_READ_D4 = 6,
  186181. READTYPE_READ_D4_1 = 7,
  186182. READTYPE_READ10_2 = 8
  186183. };
  186184. class CDDeviceHandle
  186185. {
  186186. public:
  186187. CDDeviceHandle (const CDDeviceInfo* const device)
  186188. : scsiHandle (0),
  186189. readType (READTYPE_ANY),
  186190. controller (0)
  186191. {
  186192. memcpy (&info, device, sizeof (info));
  186193. }
  186194. ~CDDeviceHandle()
  186195. {
  186196. if (controller != 0)
  186197. {
  186198. controller->shutDown();
  186199. controller = 0;
  186200. }
  186201. if (scsiHandle != 0)
  186202. CloseHandle (scsiHandle);
  186203. }
  186204. bool readTOC (TOC* lpToc, bool useMSF);
  186205. bool readAudio (CDReadBuffer* buffer, CDReadBuffer* overlapBuffer = 0);
  186206. void openDrawer (bool shouldBeOpen);
  186207. CDDeviceInfo info;
  186208. HANDLE scsiHandle;
  186209. BYTE readType;
  186210. private:
  186211. ScopedPointer<CDController> controller;
  186212. bool testController (const int readType,
  186213. CDController* const newController,
  186214. CDReadBuffer* const bufferToUse);
  186215. };
  186216. DWORD (*fGetASPI32SupportInfo)(void);
  186217. DWORD (*fSendASPI32Command)(LPSRB);
  186218. static HINSTANCE winAspiLib = 0;
  186219. static bool usingScsi = false;
  186220. static bool initialised = false;
  186221. static bool InitialiseCDRipper()
  186222. {
  186223. if (! initialised)
  186224. {
  186225. initialised = true;
  186226. OSVERSIONINFO info;
  186227. info.dwOSVersionInfoSize = sizeof (info);
  186228. GetVersionEx (&info);
  186229. usingScsi = (info.dwPlatformId == VER_PLATFORM_WIN32_NT) && (info.dwMajorVersion > 4);
  186230. if (! usingScsi)
  186231. {
  186232. fGetASPI32SupportInfo = 0;
  186233. fSendASPI32Command = 0;
  186234. winAspiLib = LoadLibrary (_T("WNASPI32.DLL"));
  186235. if (winAspiLib != 0)
  186236. {
  186237. fGetASPI32SupportInfo = (DWORD(*)(void)) GetProcAddress (winAspiLib, "GetASPI32SupportInfo");
  186238. fSendASPI32Command = (DWORD(*)(LPSRB)) GetProcAddress (winAspiLib, "SendASPI32Command");
  186239. if (fGetASPI32SupportInfo == 0 || fSendASPI32Command == 0)
  186240. return false;
  186241. }
  186242. else
  186243. {
  186244. usingScsi = true;
  186245. }
  186246. }
  186247. }
  186248. return true;
  186249. }
  186250. static void DeinitialiseCDRipper()
  186251. {
  186252. if (winAspiLib != 0)
  186253. {
  186254. fGetASPI32SupportInfo = 0;
  186255. fSendASPI32Command = 0;
  186256. FreeLibrary (winAspiLib);
  186257. winAspiLib = 0;
  186258. }
  186259. initialised = false;
  186260. }
  186261. static HANDLE CreateSCSIDeviceHandle (char driveLetter)
  186262. {
  186263. TCHAR devicePath[] = { '\\', '\\', '.', '\\', driveLetter, ':', 0, 0 };
  186264. OSVERSIONINFO info;
  186265. info.dwOSVersionInfoSize = sizeof (info);
  186266. GetVersionEx (&info);
  186267. DWORD flags = GENERIC_READ;
  186268. if ((info.dwPlatformId == VER_PLATFORM_WIN32_NT) && (info.dwMajorVersion > 4))
  186269. flags = GENERIC_READ | GENERIC_WRITE;
  186270. HANDLE h = CreateFile (devicePath, flags, FILE_SHARE_WRITE | FILE_SHARE_READ, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
  186271. if (h == INVALID_HANDLE_VALUE)
  186272. {
  186273. flags ^= GENERIC_WRITE;
  186274. h = CreateFile (devicePath, flags, FILE_SHARE_WRITE | FILE_SHARE_READ, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
  186275. }
  186276. return h;
  186277. }
  186278. static DWORD performScsiPassThroughCommand (const LPSRB_ExecSCSICmd srb,
  186279. const char driveLetter,
  186280. HANDLE& deviceHandle,
  186281. const bool retryOnFailure = true)
  186282. {
  186283. SCSI_PASS_THROUGH_DIRECT_WITH_BUFFER s;
  186284. zerostruct (s);
  186285. s.spt.Length = sizeof (SCSI_PASS_THROUGH);
  186286. s.spt.CdbLength = srb->SRB_CDBLen;
  186287. s.spt.DataIn = (BYTE) ((srb->SRB_Flags & SRB_DIR_IN)
  186288. ? SCSI_IOCTL_DATA_IN
  186289. : ((srb->SRB_Flags & SRB_DIR_OUT)
  186290. ? SCSI_IOCTL_DATA_OUT
  186291. : SCSI_IOCTL_DATA_UNSPECIFIED));
  186292. s.spt.DataTransferLength = srb->SRB_BufLen;
  186293. s.spt.TimeOutValue = 5;
  186294. s.spt.DataBuffer = srb->SRB_BufPointer;
  186295. s.spt.SenseInfoOffset = offsetof (SCSI_PASS_THROUGH_DIRECT_WITH_BUFFER, ucSenseBuf);
  186296. memcpy (s.spt.Cdb, srb->CDBByte, srb->SRB_CDBLen);
  186297. srb->SRB_Status = SS_ERR;
  186298. srb->SRB_TargStat = 0x0004;
  186299. DWORD bytesReturned = 0;
  186300. if (DeviceIoControl (deviceHandle, IOCTL_SCSI_PASS_THROUGH_DIRECT,
  186301. &s, sizeof (s),
  186302. &s, sizeof (s),
  186303. &bytesReturned, 0) != 0)
  186304. {
  186305. srb->SRB_Status = SS_COMP;
  186306. }
  186307. else if (retryOnFailure)
  186308. {
  186309. const DWORD error = GetLastError();
  186310. if ((error == ERROR_MEDIA_CHANGED) || (error == ERROR_INVALID_HANDLE))
  186311. {
  186312. if (error != ERROR_INVALID_HANDLE)
  186313. CloseHandle (deviceHandle);
  186314. deviceHandle = CreateSCSIDeviceHandle (driveLetter);
  186315. return performScsiPassThroughCommand (srb, driveLetter, deviceHandle, false);
  186316. }
  186317. }
  186318. return srb->SRB_Status;
  186319. }
  186320. // Controller types..
  186321. class ControllerType1 : public CDController
  186322. {
  186323. public:
  186324. ControllerType1() {}
  186325. ~ControllerType1() {}
  186326. bool read (CDReadBuffer* rb)
  186327. {
  186328. if (rb->numFrames * 2352 > rb->bufferSize)
  186329. return false;
  186330. SRB_ExecSCSICmd s;
  186331. prepare (s);
  186332. s.SRB_Flags = SRB_DIR_IN | SRB_EVENT_NOTIFY;
  186333. s.SRB_BufLen = rb->bufferSize;
  186334. s.SRB_BufPointer = rb->buffer;
  186335. s.SRB_CDBLen = 12;
  186336. s.CDBByte[0] = 0xBE;
  186337. s.CDBByte[3] = (BYTE)((rb->startFrame >> 16) & 0xFF);
  186338. s.CDBByte[4] = (BYTE)((rb->startFrame >> 8) & 0xFF);
  186339. s.CDBByte[5] = (BYTE)(rb->startFrame & 0xFF);
  186340. s.CDBByte[8] = (BYTE)(rb->numFrames & 0xFF);
  186341. s.CDBByte[9] = (BYTE)((deviceInfo->readType == READTYPE_ATAPI1) ? 0x10 : 0xF0);
  186342. perform (s);
  186343. if (s.SRB_Status != SS_COMP)
  186344. return false;
  186345. rb->dataLength = rb->numFrames * 2352;
  186346. rb->dataStartOffset = 0;
  186347. return true;
  186348. }
  186349. };
  186350. class ControllerType2 : public CDController
  186351. {
  186352. public:
  186353. ControllerType2() {}
  186354. ~ControllerType2() {}
  186355. void shutDown()
  186356. {
  186357. if (initialised)
  186358. {
  186359. BYTE bufPointer[] = { 0, 0, 0, 8, 83, 0, 0, 0, 0, 0, 8, 0 };
  186360. SRB_ExecSCSICmd s;
  186361. prepare (s);
  186362. s.SRB_Flags = SRB_EVENT_NOTIFY | SRB_ENABLE_RESIDUAL_COUNT;
  186363. s.SRB_BufLen = 0x0C;
  186364. s.SRB_BufPointer = bufPointer;
  186365. s.SRB_CDBLen = 6;
  186366. s.CDBByte[0] = 0x15;
  186367. s.CDBByte[4] = 0x0C;
  186368. perform (s);
  186369. }
  186370. }
  186371. bool init()
  186372. {
  186373. SRB_ExecSCSICmd s;
  186374. s.SRB_Status = SS_ERR;
  186375. if (deviceInfo->readType == READTYPE_READ10_2)
  186376. {
  186377. BYTE bufPointer1[] = { 0, 0, 0, 8, 0, 0, 0, 0, 0, 0, 9, 48, 35, 6, 0, 0, 0, 0, 0, 128 };
  186378. BYTE bufPointer2[] = { 0, 0, 0, 8, 0, 0, 0, 0, 0, 0, 9, 48, 1, 6, 32, 7, 0, 0, 0, 0 };
  186379. for (int i = 0; i < 2; ++i)
  186380. {
  186381. prepare (s);
  186382. s.SRB_Flags = SRB_EVENT_NOTIFY;
  186383. s.SRB_BufLen = 0x14;
  186384. s.SRB_BufPointer = (i == 0) ? bufPointer1 : bufPointer2;
  186385. s.SRB_CDBLen = 6;
  186386. s.CDBByte[0] = 0x15;
  186387. s.CDBByte[1] = 0x10;
  186388. s.CDBByte[4] = 0x14;
  186389. perform (s);
  186390. if (s.SRB_Status != SS_COMP)
  186391. return false;
  186392. }
  186393. }
  186394. else
  186395. {
  186396. BYTE bufPointer[] = { 0, 0, 0, 8, 0, 0, 0, 0, 0, 0, 9, 48 };
  186397. prepare (s);
  186398. s.SRB_Flags = SRB_EVENT_NOTIFY;
  186399. s.SRB_BufLen = 0x0C;
  186400. s.SRB_BufPointer = bufPointer;
  186401. s.SRB_CDBLen = 6;
  186402. s.CDBByte[0] = 0x15;
  186403. s.CDBByte[4] = 0x0C;
  186404. perform (s);
  186405. }
  186406. return s.SRB_Status == SS_COMP;
  186407. }
  186408. bool read (CDReadBuffer* rb)
  186409. {
  186410. if (rb->numFrames * 2352 > rb->bufferSize)
  186411. return false;
  186412. if (!initialised)
  186413. {
  186414. initialised = init();
  186415. if (!initialised)
  186416. return false;
  186417. }
  186418. SRB_ExecSCSICmd s;
  186419. prepare (s);
  186420. s.SRB_Flags = SRB_DIR_IN | SRB_EVENT_NOTIFY;
  186421. s.SRB_BufLen = rb->bufferSize;
  186422. s.SRB_BufPointer = rb->buffer;
  186423. s.SRB_CDBLen = 10;
  186424. s.CDBByte[0] = 0x28;
  186425. s.CDBByte[1] = (BYTE)(deviceInfo->info.lun << 5);
  186426. s.CDBByte[3] = (BYTE)((rb->startFrame >> 16) & 0xFF);
  186427. s.CDBByte[4] = (BYTE)((rb->startFrame >> 8) & 0xFF);
  186428. s.CDBByte[5] = (BYTE)(rb->startFrame & 0xFF);
  186429. s.CDBByte[8] = (BYTE)(rb->numFrames & 0xFF);
  186430. perform (s);
  186431. if (s.SRB_Status != SS_COMP)
  186432. return false;
  186433. rb->dataLength = rb->numFrames * 2352;
  186434. rb->dataStartOffset = 0;
  186435. return true;
  186436. }
  186437. };
  186438. class ControllerType3 : public CDController
  186439. {
  186440. public:
  186441. ControllerType3() {}
  186442. ~ControllerType3() {}
  186443. bool read (CDReadBuffer* rb)
  186444. {
  186445. if (rb->numFrames * 2352 > rb->bufferSize)
  186446. return false;
  186447. if (!initialised)
  186448. {
  186449. setPaused (false);
  186450. initialised = true;
  186451. }
  186452. SRB_ExecSCSICmd s;
  186453. prepare (s);
  186454. s.SRB_Flags = SRB_DIR_IN | SRB_EVENT_NOTIFY;
  186455. s.SRB_BufLen = rb->numFrames * 2352;
  186456. s.SRB_BufPointer = rb->buffer;
  186457. s.SRB_CDBLen = 12;
  186458. s.CDBByte[0] = 0xD8;
  186459. s.CDBByte[3] = (BYTE)((rb->startFrame >> 16) & 0xFF);
  186460. s.CDBByte[4] = (BYTE)((rb->startFrame >> 8) & 0xFF);
  186461. s.CDBByte[5] = (BYTE)(rb->startFrame & 0xFF);
  186462. s.CDBByte[9] = (BYTE)(rb->numFrames & 0xFF);
  186463. perform (s);
  186464. if (s.SRB_Status != SS_COMP)
  186465. return false;
  186466. rb->dataLength = rb->numFrames * 2352;
  186467. rb->dataStartOffset = 0;
  186468. return true;
  186469. }
  186470. };
  186471. class ControllerType4 : public CDController
  186472. {
  186473. public:
  186474. ControllerType4() {}
  186475. ~ControllerType4() {}
  186476. bool selectD4Mode()
  186477. {
  186478. BYTE bufPointer[12] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9, 48 };
  186479. SRB_ExecSCSICmd s;
  186480. prepare (s);
  186481. s.SRB_Flags = SRB_EVENT_NOTIFY;
  186482. s.SRB_CDBLen = 6;
  186483. s.SRB_BufLen = 12;
  186484. s.SRB_BufPointer = bufPointer;
  186485. s.CDBByte[0] = 0x15;
  186486. s.CDBByte[1] = 0x10;
  186487. s.CDBByte[4] = 0x08;
  186488. perform (s);
  186489. return s.SRB_Status == SS_COMP;
  186490. }
  186491. bool read (CDReadBuffer* rb)
  186492. {
  186493. if (rb->numFrames * 2352 > rb->bufferSize)
  186494. return false;
  186495. if (!initialised)
  186496. {
  186497. setPaused (true);
  186498. if (deviceInfo->readType == READTYPE_READ_D4_1)
  186499. selectD4Mode();
  186500. initialised = true;
  186501. }
  186502. SRB_ExecSCSICmd s;
  186503. prepare (s);
  186504. s.SRB_Flags = SRB_DIR_IN | SRB_EVENT_NOTIFY;
  186505. s.SRB_BufLen = rb->bufferSize;
  186506. s.SRB_BufPointer = rb->buffer;
  186507. s.SRB_CDBLen = 10;
  186508. s.CDBByte[0] = 0xD4;
  186509. s.CDBByte[3] = (BYTE)((rb->startFrame >> 16) & 0xFF);
  186510. s.CDBByte[4] = (BYTE)((rb->startFrame >> 8) & 0xFF);
  186511. s.CDBByte[5] = (BYTE)(rb->startFrame & 0xFF);
  186512. s.CDBByte[8] = (BYTE)(rb->numFrames & 0xFF);
  186513. perform (s);
  186514. if (s.SRB_Status != SS_COMP)
  186515. return false;
  186516. rb->dataLength = rb->numFrames * 2352;
  186517. rb->dataStartOffset = 0;
  186518. return true;
  186519. }
  186520. };
  186521. CDController::CDController() : initialised (false)
  186522. {
  186523. }
  186524. CDController::~CDController()
  186525. {
  186526. }
  186527. void CDController::prepare (SRB_ExecSCSICmd& s)
  186528. {
  186529. zerostruct (s);
  186530. s.SRB_Cmd = SC_EXEC_SCSI_CMD;
  186531. s.SRB_HaID = deviceInfo->info.ha;
  186532. s.SRB_Target = deviceInfo->info.tgt;
  186533. s.SRB_Lun = deviceInfo->info.lun;
  186534. s.SRB_SenseLen = SENSE_LEN;
  186535. }
  186536. void CDController::perform (SRB_ExecSCSICmd& s)
  186537. {
  186538. HANDLE event = CreateEvent (0, TRUE, FALSE, 0);
  186539. s.SRB_PostProc = (void*)event;
  186540. ResetEvent (event);
  186541. DWORD status = (usingScsi) ? performScsiPassThroughCommand ((LPSRB_ExecSCSICmd)&s,
  186542. deviceInfo->info.scsiDriveLetter,
  186543. deviceInfo->scsiHandle)
  186544. : fSendASPI32Command ((LPSRB)&s);
  186545. if (status == SS_PENDING)
  186546. WaitForSingleObject (event, 4000);
  186547. CloseHandle (event);
  186548. }
  186549. void CDController::setPaused (bool paused)
  186550. {
  186551. SRB_ExecSCSICmd s;
  186552. prepare (s);
  186553. s.SRB_Flags = SRB_EVENT_NOTIFY;
  186554. s.SRB_CDBLen = 10;
  186555. s.CDBByte[0] = 0x4B;
  186556. s.CDBByte[8] = (BYTE) (paused ? 0 : 1);
  186557. perform (s);
  186558. }
  186559. void CDController::shutDown()
  186560. {
  186561. }
  186562. bool CDController::readAudio (CDReadBuffer* rb, CDReadBuffer* overlapBuffer)
  186563. {
  186564. if (overlapBuffer != 0)
  186565. {
  186566. const bool canDoJitter = (overlapBuffer->bufferSize >= 2352 * framesToCheck);
  186567. const bool doJitter = canDoJitter && ! overlapBuffer->isZero();
  186568. if (doJitter
  186569. && overlapBuffer->startFrame > 0
  186570. && overlapBuffer->numFrames > 0
  186571. && overlapBuffer->dataLength > 0)
  186572. {
  186573. const int numFrames = rb->numFrames;
  186574. if (overlapBuffer->startFrame == (rb->startFrame - framesToCheck))
  186575. {
  186576. rb->startFrame -= framesOverlap;
  186577. if (framesToCheck < framesOverlap
  186578. && numFrames + framesOverlap <= rb->bufferSize / 2352)
  186579. rb->numFrames += framesOverlap;
  186580. }
  186581. else
  186582. {
  186583. overlapBuffer->dataLength = 0;
  186584. overlapBuffer->startFrame = 0;
  186585. overlapBuffer->numFrames = 0;
  186586. }
  186587. }
  186588. if (! read (rb))
  186589. return false;
  186590. if (doJitter)
  186591. {
  186592. const int checkLen = framesToCheck * 2352;
  186593. const int maxToCheck = rb->dataLength - checkLen;
  186594. if (overlapBuffer->dataLength == 0 || overlapBuffer->isZero())
  186595. return true;
  186596. BYTE* const p = overlapBuffer->buffer + overlapBuffer->dataStartOffset;
  186597. bool found = false;
  186598. for (int i = 0; i < maxToCheck; ++i)
  186599. {
  186600. if (!memcmp (p, rb->buffer + i, checkLen))
  186601. {
  186602. i += checkLen;
  186603. rb->dataStartOffset = i;
  186604. rb->dataLength -= i;
  186605. rb->startFrame = overlapBuffer->startFrame + framesToCheck;
  186606. found = true;
  186607. break;
  186608. }
  186609. }
  186610. rb->numFrames = rb->dataLength / 2352;
  186611. rb->dataLength = 2352 * rb->numFrames;
  186612. if (!found)
  186613. return false;
  186614. }
  186615. if (canDoJitter)
  186616. {
  186617. memcpy (overlapBuffer->buffer,
  186618. rb->buffer + rb->dataStartOffset + 2352 * (rb->numFrames - framesToCheck),
  186619. 2352 * framesToCheck);
  186620. overlapBuffer->startFrame = rb->startFrame + rb->numFrames - framesToCheck;
  186621. overlapBuffer->numFrames = framesToCheck;
  186622. overlapBuffer->dataLength = 2352 * framesToCheck;
  186623. overlapBuffer->dataStartOffset = 0;
  186624. }
  186625. else
  186626. {
  186627. overlapBuffer->startFrame = 0;
  186628. overlapBuffer->numFrames = 0;
  186629. overlapBuffer->dataLength = 0;
  186630. }
  186631. return true;
  186632. }
  186633. else
  186634. {
  186635. return read (rb);
  186636. }
  186637. }
  186638. int CDController::getLastIndex()
  186639. {
  186640. char qdata[100];
  186641. SRB_ExecSCSICmd s;
  186642. prepare (s);
  186643. s.SRB_Flags = SRB_DIR_IN | SRB_EVENT_NOTIFY;
  186644. s.SRB_BufLen = sizeof (qdata);
  186645. s.SRB_BufPointer = (BYTE*)qdata;
  186646. s.SRB_CDBLen = 12;
  186647. s.CDBByte[0] = 0x42;
  186648. s.CDBByte[1] = (BYTE)(deviceInfo->info.lun << 5);
  186649. s.CDBByte[2] = 64;
  186650. s.CDBByte[3] = 1; // get current position
  186651. s.CDBByte[7] = 0;
  186652. s.CDBByte[8] = (BYTE)sizeof (qdata);
  186653. perform (s);
  186654. if (s.SRB_Status == SS_COMP)
  186655. return qdata[7];
  186656. return 0;
  186657. }
  186658. bool CDDeviceHandle::readTOC (TOC* lpToc, bool useMSF)
  186659. {
  186660. HANDLE event = CreateEvent (0, TRUE, FALSE, 0);
  186661. SRB_ExecSCSICmd s;
  186662. zerostruct (s);
  186663. s.SRB_Cmd = SC_EXEC_SCSI_CMD;
  186664. s.SRB_HaID = info.ha;
  186665. s.SRB_Target = info.tgt;
  186666. s.SRB_Lun = info.lun;
  186667. s.SRB_Flags = SRB_DIR_IN | SRB_EVENT_NOTIFY;
  186668. s.SRB_BufLen = 0x324;
  186669. s.SRB_BufPointer = (BYTE*)lpToc;
  186670. s.SRB_SenseLen = 0x0E;
  186671. s.SRB_CDBLen = 0x0A;
  186672. s.SRB_PostProc = (void*)event;
  186673. s.CDBByte[0] = 0x43;
  186674. s.CDBByte[1] = (BYTE)(useMSF ? 0x02 : 0x00);
  186675. s.CDBByte[7] = 0x03;
  186676. s.CDBByte[8] = 0x24;
  186677. ResetEvent (event);
  186678. DWORD status = (usingScsi) ? performScsiPassThroughCommand ((LPSRB_ExecSCSICmd)&s, info.scsiDriveLetter, scsiHandle)
  186679. : fSendASPI32Command ((LPSRB)&s);
  186680. if (status == SS_PENDING)
  186681. WaitForSingleObject (event, 4000);
  186682. CloseHandle (event);
  186683. return (s.SRB_Status == SS_COMP);
  186684. }
  186685. bool CDDeviceHandle::readAudio (CDReadBuffer* const buffer,
  186686. CDReadBuffer* const overlapBuffer)
  186687. {
  186688. if (controller == 0)
  186689. {
  186690. testController (READTYPE_ATAPI2, new ControllerType1(), buffer)
  186691. || testController (READTYPE_ATAPI1, new ControllerType1(), buffer)
  186692. || testController (READTYPE_READ10_2, new ControllerType2(), buffer)
  186693. || testController (READTYPE_READ10, new ControllerType2(), buffer)
  186694. || testController (READTYPE_READ_D8, new ControllerType3(), buffer)
  186695. || testController (READTYPE_READ_D4, new ControllerType4(), buffer)
  186696. || testController (READTYPE_READ_D4_1, new ControllerType4(), buffer);
  186697. }
  186698. buffer->index = 0;
  186699. if ((controller != 0)
  186700. && controller->readAudio (buffer, overlapBuffer))
  186701. {
  186702. if (buffer->wantsIndex)
  186703. buffer->index = controller->getLastIndex();
  186704. return true;
  186705. }
  186706. return false;
  186707. }
  186708. void CDDeviceHandle::openDrawer (bool shouldBeOpen)
  186709. {
  186710. if (shouldBeOpen)
  186711. {
  186712. if (controller != 0)
  186713. {
  186714. controller->shutDown();
  186715. controller = 0;
  186716. }
  186717. if (scsiHandle != 0)
  186718. {
  186719. CloseHandle (scsiHandle);
  186720. scsiHandle = 0;
  186721. }
  186722. }
  186723. SRB_ExecSCSICmd s;
  186724. zerostruct (s);
  186725. s.SRB_Cmd = SC_EXEC_SCSI_CMD;
  186726. s.SRB_HaID = info.ha;
  186727. s.SRB_Target = info.tgt;
  186728. s.SRB_Lun = info.lun;
  186729. s.SRB_SenseLen = SENSE_LEN;
  186730. s.SRB_Flags = SRB_DIR_IN | SRB_EVENT_NOTIFY;
  186731. s.SRB_BufLen = 0;
  186732. s.SRB_BufPointer = 0;
  186733. s.SRB_CDBLen = 12;
  186734. s.CDBByte[0] = 0x1b;
  186735. s.CDBByte[1] = (BYTE)(info.lun << 5);
  186736. s.CDBByte[4] = (BYTE)((shouldBeOpen) ? 2 : 3);
  186737. HANDLE event = CreateEvent (0, TRUE, FALSE, 0);
  186738. s.SRB_PostProc = (void*)event;
  186739. ResetEvent (event);
  186740. DWORD status = (usingScsi) ? performScsiPassThroughCommand ((LPSRB_ExecSCSICmd)&s, info.scsiDriveLetter, scsiHandle)
  186741. : fSendASPI32Command ((LPSRB)&s);
  186742. if (status == SS_PENDING)
  186743. WaitForSingleObject (event, 4000);
  186744. CloseHandle (event);
  186745. }
  186746. bool CDDeviceHandle::testController (const int type,
  186747. CDController* const newController,
  186748. CDReadBuffer* const rb)
  186749. {
  186750. controller = newController;
  186751. readType = (BYTE)type;
  186752. controller->deviceInfo = this;
  186753. controller->framesToCheck = 1;
  186754. controller->framesOverlap = 3;
  186755. bool passed = false;
  186756. memset (rb->buffer, 0xcd, rb->bufferSize);
  186757. if (controller->read (rb))
  186758. {
  186759. passed = true;
  186760. int* p = (int*) (rb->buffer + rb->dataStartOffset);
  186761. int wrong = 0;
  186762. for (int i = rb->dataLength / 4; --i >= 0;)
  186763. {
  186764. if (*p++ == (int) 0xcdcdcdcd)
  186765. {
  186766. if (++wrong == 4)
  186767. {
  186768. passed = false;
  186769. break;
  186770. }
  186771. }
  186772. else
  186773. {
  186774. wrong = 0;
  186775. }
  186776. }
  186777. }
  186778. if (! passed)
  186779. {
  186780. controller->shutDown();
  186781. controller = 0;
  186782. }
  186783. return passed;
  186784. }
  186785. static void GetAspiDeviceInfo (CDDeviceInfo* dev, BYTE ha, BYTE tgt, BYTE lun)
  186786. {
  186787. HANDLE event = CreateEvent (0, TRUE, FALSE, 0);
  186788. const int bufSize = 128;
  186789. BYTE buffer[bufSize];
  186790. zeromem (buffer, bufSize);
  186791. SRB_ExecSCSICmd s;
  186792. zerostruct (s);
  186793. s.SRB_Cmd = SC_EXEC_SCSI_CMD;
  186794. s.SRB_HaID = ha;
  186795. s.SRB_Target = tgt;
  186796. s.SRB_Lun = lun;
  186797. s.SRB_Flags = SRB_DIR_IN | SRB_EVENT_NOTIFY;
  186798. s.SRB_BufLen = bufSize;
  186799. s.SRB_BufPointer = buffer;
  186800. s.SRB_SenseLen = SENSE_LEN;
  186801. s.SRB_CDBLen = 6;
  186802. s.SRB_PostProc = (void*)event;
  186803. s.CDBByte[0] = SCSI_INQUIRY;
  186804. s.CDBByte[4] = 100;
  186805. ResetEvent (event);
  186806. if (fSendASPI32Command ((LPSRB)&s) == SS_PENDING)
  186807. WaitForSingleObject (event, 4000);
  186808. CloseHandle (event);
  186809. if (s.SRB_Status == SS_COMP)
  186810. {
  186811. memcpy (dev->vendor, &buffer[8], 8);
  186812. memcpy (dev->productId, &buffer[16], 16);
  186813. memcpy (dev->rev, &buffer[32], 4);
  186814. memcpy (dev->vendorSpec, &buffer[36], 20);
  186815. }
  186816. }
  186817. static int FindCDDevices (CDDeviceInfo* const list,
  186818. int maxItems)
  186819. {
  186820. int count = 0;
  186821. if (usingScsi)
  186822. {
  186823. for (char driveLetter = 'b'; driveLetter <= 'z'; ++driveLetter)
  186824. {
  186825. TCHAR drivePath[8];
  186826. drivePath[0] = driveLetter;
  186827. drivePath[1] = ':';
  186828. drivePath[2] = '\\';
  186829. drivePath[3] = 0;
  186830. if (GetDriveType (drivePath) == DRIVE_CDROM)
  186831. {
  186832. HANDLE h = CreateSCSIDeviceHandle (driveLetter);
  186833. if (h != INVALID_HANDLE_VALUE)
  186834. {
  186835. BYTE buffer[100], passThroughStruct[1024];
  186836. zeromem (buffer, sizeof (buffer));
  186837. zeromem (passThroughStruct, sizeof (passThroughStruct));
  186838. PSCSI_PASS_THROUGH_DIRECT_WITH_BUFFER p = (PSCSI_PASS_THROUGH_DIRECT_WITH_BUFFER)passThroughStruct;
  186839. p->spt.Length = sizeof (SCSI_PASS_THROUGH);
  186840. p->spt.CdbLength = 6;
  186841. p->spt.SenseInfoLength = 24;
  186842. p->spt.DataIn = SCSI_IOCTL_DATA_IN;
  186843. p->spt.DataTransferLength = 100;
  186844. p->spt.TimeOutValue = 2;
  186845. p->spt.DataBuffer = buffer;
  186846. p->spt.SenseInfoOffset = offsetof (SCSI_PASS_THROUGH_DIRECT_WITH_BUFFER, ucSenseBuf);
  186847. p->spt.Cdb[0] = 0x12;
  186848. p->spt.Cdb[4] = 100;
  186849. DWORD bytesReturned = 0;
  186850. if (DeviceIoControl (h, IOCTL_SCSI_PASS_THROUGH_DIRECT,
  186851. p, sizeof (SCSI_PASS_THROUGH_DIRECT_WITH_BUFFER),
  186852. p, sizeof (SCSI_PASS_THROUGH_DIRECT_WITH_BUFFER),
  186853. &bytesReturned, 0) != 0)
  186854. {
  186855. zeromem (&list[count], sizeof (CDDeviceInfo));
  186856. list[count].scsiDriveLetter = driveLetter;
  186857. memcpy (list[count].vendor, &buffer[8], 8);
  186858. memcpy (list[count].productId, &buffer[16], 16);
  186859. memcpy (list[count].rev, &buffer[32], 4);
  186860. memcpy (list[count].vendorSpec, &buffer[36], 20);
  186861. zeromem (passThroughStruct, sizeof (passThroughStruct));
  186862. PSCSI_ADDRESS scsiAddr = (PSCSI_ADDRESS)passThroughStruct;
  186863. scsiAddr->Length = sizeof (SCSI_ADDRESS);
  186864. if (DeviceIoControl (h, IOCTL_SCSI_GET_ADDRESS,
  186865. 0, 0, scsiAddr, sizeof (SCSI_ADDRESS),
  186866. &bytesReturned, 0) != 0)
  186867. {
  186868. list[count].ha = scsiAddr->PortNumber;
  186869. list[count].tgt = scsiAddr->TargetId;
  186870. list[count].lun = scsiAddr->Lun;
  186871. ++count;
  186872. }
  186873. }
  186874. CloseHandle (h);
  186875. }
  186876. }
  186877. }
  186878. }
  186879. else
  186880. {
  186881. const DWORD d = fGetASPI32SupportInfo();
  186882. BYTE status = HIBYTE (LOWORD (d));
  186883. if (status != SS_COMP || status == SS_NO_ADAPTERS)
  186884. return 0;
  186885. const int numAdapters = LOBYTE (LOWORD (d));
  186886. for (BYTE ha = 0; ha < numAdapters; ++ha)
  186887. {
  186888. SRB_HAInquiry s;
  186889. zerostruct (s);
  186890. s.SRB_Cmd = SC_HA_INQUIRY;
  186891. s.SRB_HaID = ha;
  186892. fSendASPI32Command ((LPSRB)&s);
  186893. if (s.SRB_Status == SS_COMP)
  186894. {
  186895. maxItems = (int)s.HA_Unique[3];
  186896. if (maxItems == 0)
  186897. maxItems = 8;
  186898. for (BYTE tgt = 0; tgt < maxItems; ++tgt)
  186899. {
  186900. for (BYTE lun = 0; lun < 8; ++lun)
  186901. {
  186902. SRB_GDEVBlock sb;
  186903. zerostruct (sb);
  186904. sb.SRB_Cmd = SC_GET_DEV_TYPE;
  186905. sb.SRB_HaID = ha;
  186906. sb.SRB_Target = tgt;
  186907. sb.SRB_Lun = lun;
  186908. fSendASPI32Command ((LPSRB) &sb);
  186909. if (sb.SRB_Status == SS_COMP
  186910. && sb.SRB_DeviceType == DTYPE_CROM)
  186911. {
  186912. zeromem (&list[count], sizeof (CDDeviceInfo));
  186913. list[count].ha = ha;
  186914. list[count].tgt = tgt;
  186915. list[count].lun = lun;
  186916. GetAspiDeviceInfo (&(list[count]), ha, tgt, lun);
  186917. ++count;
  186918. }
  186919. }
  186920. }
  186921. }
  186922. }
  186923. }
  186924. return count;
  186925. }
  186926. static int ripperUsers = 0;
  186927. static bool initialisedOk = false;
  186928. class DeinitialiseTimer : private Timer,
  186929. private DeletedAtShutdown
  186930. {
  186931. DeinitialiseTimer (const DeinitialiseTimer&);
  186932. DeinitialiseTimer& operator= (const DeinitialiseTimer&);
  186933. public:
  186934. DeinitialiseTimer()
  186935. {
  186936. startTimer (4000);
  186937. }
  186938. ~DeinitialiseTimer()
  186939. {
  186940. if (--ripperUsers == 0)
  186941. DeinitialiseCDRipper();
  186942. }
  186943. void timerCallback()
  186944. {
  186945. delete this;
  186946. }
  186947. juce_UseDebuggingNewOperator
  186948. };
  186949. static void incUserCount()
  186950. {
  186951. if (ripperUsers++ == 0)
  186952. initialisedOk = InitialiseCDRipper();
  186953. }
  186954. static void decUserCount()
  186955. {
  186956. new DeinitialiseTimer();
  186957. }
  186958. struct CDDeviceWrapper
  186959. {
  186960. ScopedPointer<CDDeviceHandle> cdH;
  186961. ScopedPointer<CDReadBuffer> overlapBuffer;
  186962. bool jitter;
  186963. };
  186964. static int getAddressOf (const TOCTRACK* const t)
  186965. {
  186966. return (((DWORD)t->addr[0]) << 24) + (((DWORD)t->addr[1]) << 16) +
  186967. (((DWORD)t->addr[2]) << 8) + ((DWORD)t->addr[3]);
  186968. }
  186969. static int getMSFAddressOf (const TOCTRACK* const t)
  186970. {
  186971. return 60 * t->addr[1] + t->addr[2];
  186972. }
  186973. static const int samplesPerFrame = 44100 / 75;
  186974. static const int bytesPerFrame = samplesPerFrame * 4;
  186975. static CDDeviceHandle* openHandle (const CDDeviceInfo* const device)
  186976. {
  186977. SRB_GDEVBlock s;
  186978. zerostruct (s);
  186979. s.SRB_Cmd = SC_GET_DEV_TYPE;
  186980. s.SRB_HaID = device->ha;
  186981. s.SRB_Target = device->tgt;
  186982. s.SRB_Lun = device->lun;
  186983. if (usingScsi)
  186984. {
  186985. HANDLE h = CreateSCSIDeviceHandle (device->scsiDriveLetter);
  186986. if (h != INVALID_HANDLE_VALUE)
  186987. {
  186988. CDDeviceHandle* cdh = new CDDeviceHandle (device);
  186989. cdh->scsiHandle = h;
  186990. return cdh;
  186991. }
  186992. }
  186993. else
  186994. {
  186995. if (fSendASPI32Command ((LPSRB)&s) == SS_COMP
  186996. && s.SRB_DeviceType == DTYPE_CROM)
  186997. {
  186998. return new CDDeviceHandle (device);
  186999. }
  187000. }
  187001. return 0;
  187002. }
  187003. }
  187004. const StringArray AudioCDReader::getAvailableCDNames()
  187005. {
  187006. using namespace CDReaderHelpers;
  187007. StringArray results;
  187008. incUserCount();
  187009. if (initialisedOk)
  187010. {
  187011. CDDeviceInfo list[8];
  187012. const int num = FindCDDevices (list, 8);
  187013. decUserCount();
  187014. for (int i = 0; i < num; ++i)
  187015. {
  187016. String s;
  187017. if (list[i].scsiDriveLetter > 0)
  187018. s << String::charToString (list[i].scsiDriveLetter).toUpperCase() << T(": ");
  187019. s << String (list[i].vendor).trim()
  187020. << T(" ") << String (list[i].productId).trim()
  187021. << T(" ") << String (list[i].rev).trim();
  187022. results.add (s);
  187023. }
  187024. }
  187025. return results;
  187026. }
  187027. AudioCDReader* AudioCDReader::createReaderForCD (const int deviceIndex)
  187028. {
  187029. using namespace CDReaderHelpers;
  187030. incUserCount();
  187031. if (initialisedOk)
  187032. {
  187033. CDDeviceInfo list[8];
  187034. const int num = FindCDDevices (list, 8);
  187035. if (((unsigned int) deviceIndex) < (unsigned int) num)
  187036. {
  187037. CDDeviceHandle* const handle = openHandle (&(list[deviceIndex]));
  187038. if (handle != 0)
  187039. {
  187040. CDDeviceWrapper* const d = new CDDeviceWrapper();
  187041. d->cdH = handle;
  187042. d->overlapBuffer = new CDReadBuffer(3);
  187043. return new AudioCDReader (d);
  187044. }
  187045. }
  187046. }
  187047. decUserCount();
  187048. return 0;
  187049. }
  187050. AudioCDReader::AudioCDReader (void* handle_)
  187051. : AudioFormatReader (0, T("CD Audio")),
  187052. handle (handle_),
  187053. indexingEnabled (false),
  187054. lastIndex (0),
  187055. firstFrameInBuffer (0),
  187056. samplesInBuffer (0)
  187057. {
  187058. using namespace CDReaderHelpers;
  187059. jassert (handle_ != 0);
  187060. refreshTrackLengths();
  187061. sampleRate = 44100.0;
  187062. bitsPerSample = 16;
  187063. lengthInSamples = getPositionOfTrackStart (numTracks);
  187064. numChannels = 2;
  187065. usesFloatingPointData = false;
  187066. buffer.setSize (4 * bytesPerFrame, true);
  187067. }
  187068. AudioCDReader::~AudioCDReader()
  187069. {
  187070. using namespace CDReaderHelpers;
  187071. CDDeviceWrapper* const device = (CDDeviceWrapper*) handle;
  187072. delete device;
  187073. decUserCount();
  187074. }
  187075. bool AudioCDReader::readSamples (int** destSamples, int numDestChannels, int startOffsetInDestBuffer,
  187076. int64 startSampleInFile, int numSamples)
  187077. {
  187078. using namespace CDReaderHelpers;
  187079. CDDeviceWrapper* const device = (CDDeviceWrapper*) handle;
  187080. bool ok = true;
  187081. while (numSamples > 0)
  187082. {
  187083. const int bufferStartSample = firstFrameInBuffer * samplesPerFrame;
  187084. const int bufferEndSample = bufferStartSample + samplesInBuffer;
  187085. if (startSampleInFile >= bufferStartSample
  187086. && startSampleInFile < bufferEndSample)
  187087. {
  187088. const int toDo = (int) jmin ((int64) numSamples, bufferEndSample - startSampleInFile);
  187089. int* const l = destSamples[0] + startOffsetInDestBuffer;
  187090. int* const r = numDestChannels > 1 ? (destSamples[1] + startOffsetInDestBuffer) : 0;
  187091. const short* src = (const short*) buffer.getData();
  187092. src += 2 * (startSampleInFile - bufferStartSample);
  187093. for (int i = 0; i < toDo; ++i)
  187094. {
  187095. l[i] = src [i << 1] << 16;
  187096. if (r != 0)
  187097. r[i] = src [(i << 1) + 1] << 16;
  187098. }
  187099. startOffsetInDestBuffer += toDo;
  187100. startSampleInFile += toDo;
  187101. numSamples -= toDo;
  187102. }
  187103. else
  187104. {
  187105. const int framesInBuffer = buffer.getSize() / bytesPerFrame;
  187106. const int frameNeeded = (int) (startSampleInFile / samplesPerFrame);
  187107. if (firstFrameInBuffer + framesInBuffer != frameNeeded)
  187108. {
  187109. device->overlapBuffer->dataLength = 0;
  187110. device->overlapBuffer->startFrame = 0;
  187111. device->overlapBuffer->numFrames = 0;
  187112. device->jitter = false;
  187113. }
  187114. firstFrameInBuffer = frameNeeded;
  187115. lastIndex = 0;
  187116. CDReadBuffer readBuffer (framesInBuffer + 4);
  187117. readBuffer.wantsIndex = indexingEnabled;
  187118. int i;
  187119. for (i = 5; --i >= 0;)
  187120. {
  187121. readBuffer.startFrame = frameNeeded;
  187122. readBuffer.numFrames = framesInBuffer;
  187123. if (device->cdH->readAudio (&readBuffer, (device->jitter) ? device->overlapBuffer : 0))
  187124. break;
  187125. else
  187126. device->overlapBuffer->dataLength = 0;
  187127. }
  187128. if (i >= 0)
  187129. {
  187130. memcpy ((char*) buffer.getData(),
  187131. readBuffer.buffer + readBuffer.dataStartOffset,
  187132. readBuffer.dataLength);
  187133. samplesInBuffer = readBuffer.dataLength >> 2;
  187134. lastIndex = readBuffer.index;
  187135. }
  187136. else
  187137. {
  187138. int* l = destSamples[0] + startOffsetInDestBuffer;
  187139. int* r = numDestChannels > 1 ? (destSamples[1] + startOffsetInDestBuffer) : 0;
  187140. while (--numSamples >= 0)
  187141. {
  187142. *l++ = 0;
  187143. if (r != 0)
  187144. *r++ = 0;
  187145. }
  187146. // sometimes the read fails for just the very last couple of blocks, so
  187147. // we'll ignore and errors in the last half-second of the disk..
  187148. ok = startSampleInFile > (trackStarts [numTracks] - 20000);
  187149. break;
  187150. }
  187151. }
  187152. }
  187153. return ok;
  187154. }
  187155. bool AudioCDReader::isCDStillPresent() const
  187156. {
  187157. using namespace CDReaderHelpers;
  187158. TOC toc;
  187159. zerostruct (toc);
  187160. return ((CDDeviceWrapper*) handle)->cdH->readTOC (&toc, false);
  187161. }
  187162. int AudioCDReader::getNumTracks() const
  187163. {
  187164. return numTracks;
  187165. }
  187166. int AudioCDReader::getPositionOfTrackStart (int trackNum) const
  187167. {
  187168. using namespace CDReaderHelpers;
  187169. return (trackNum >= 0 && trackNum <= numTracks) ? trackStarts [trackNum] * samplesPerFrame
  187170. : 0;
  187171. }
  187172. void AudioCDReader::refreshTrackLengths()
  187173. {
  187174. using namespace CDReaderHelpers;
  187175. zeromem (trackStarts, sizeof (trackStarts));
  187176. zeromem (audioTracks, sizeof (audioTracks));
  187177. TOC toc;
  187178. zerostruct (toc);
  187179. if (((CDDeviceWrapper*)handle)->cdH->readTOC (&toc, false))
  187180. {
  187181. numTracks = 1 + toc.lastTrack - toc.firstTrack;
  187182. for (int i = 0; i <= numTracks; ++i)
  187183. {
  187184. trackStarts[i] = getAddressOf (&toc.tracks[i]);
  187185. audioTracks[i] = ((toc.tracks[i].ADR & 4) == 0);
  187186. }
  187187. }
  187188. else
  187189. {
  187190. numTracks = 0;
  187191. }
  187192. }
  187193. bool AudioCDReader::isTrackAudio (int trackNum) const
  187194. {
  187195. return (trackNum >= 0 && trackNum <= numTracks) ? audioTracks [trackNum]
  187196. : false;
  187197. }
  187198. void AudioCDReader::enableIndexScanning (bool b)
  187199. {
  187200. indexingEnabled = b;
  187201. }
  187202. int AudioCDReader::getLastIndex() const
  187203. {
  187204. return lastIndex;
  187205. }
  187206. const int framesPerIndexRead = 4;
  187207. int AudioCDReader::getIndexAt (int samplePos)
  187208. {
  187209. using namespace CDReaderHelpers;
  187210. CDDeviceWrapper* const device = (CDDeviceWrapper*) handle;
  187211. const int frameNeeded = samplePos / samplesPerFrame;
  187212. device->overlapBuffer->dataLength = 0;
  187213. device->overlapBuffer->startFrame = 0;
  187214. device->overlapBuffer->numFrames = 0;
  187215. device->jitter = false;
  187216. firstFrameInBuffer = 0;
  187217. lastIndex = 0;
  187218. CDReadBuffer readBuffer (4 + framesPerIndexRead);
  187219. readBuffer.wantsIndex = true;
  187220. int i;
  187221. for (i = 5; --i >= 0;)
  187222. {
  187223. readBuffer.startFrame = frameNeeded;
  187224. readBuffer.numFrames = framesPerIndexRead;
  187225. if (device->cdH->readAudio (&readBuffer, (false) ? device->overlapBuffer : 0))
  187226. break;
  187227. }
  187228. if (i >= 0)
  187229. return readBuffer.index;
  187230. return -1;
  187231. }
  187232. const Array <int> AudioCDReader::findIndexesInTrack (const int trackNumber)
  187233. {
  187234. using namespace CDReaderHelpers;
  187235. Array <int> indexes;
  187236. const int trackStart = getPositionOfTrackStart (trackNumber);
  187237. const int trackEnd = getPositionOfTrackStart (trackNumber + 1);
  187238. bool needToScan = true;
  187239. if (trackEnd - trackStart > 20 * 44100)
  187240. {
  187241. // check the end of the track for indexes before scanning the whole thing
  187242. needToScan = false;
  187243. int pos = jmax (trackStart, trackEnd - 44100 * 5);
  187244. bool seenAnIndex = false;
  187245. while (pos <= trackEnd - samplesPerFrame)
  187246. {
  187247. const int index = getIndexAt (pos);
  187248. if (index == 0)
  187249. {
  187250. // lead-out, so skip back a bit if we've not found any indexes yet..
  187251. if (seenAnIndex)
  187252. break;
  187253. pos -= 44100 * 5;
  187254. if (pos < trackStart)
  187255. break;
  187256. }
  187257. else
  187258. {
  187259. if (index > 0)
  187260. seenAnIndex = true;
  187261. if (index > 1)
  187262. {
  187263. needToScan = true;
  187264. break;
  187265. }
  187266. pos += samplesPerFrame * framesPerIndexRead;
  187267. }
  187268. }
  187269. }
  187270. if (needToScan)
  187271. {
  187272. CDDeviceWrapper* const device = (CDDeviceWrapper*) handle;
  187273. int pos = trackStart;
  187274. int last = -1;
  187275. while (pos < trackEnd - samplesPerFrame * 10)
  187276. {
  187277. const int frameNeeded = pos / samplesPerFrame;
  187278. device->overlapBuffer->dataLength = 0;
  187279. device->overlapBuffer->startFrame = 0;
  187280. device->overlapBuffer->numFrames = 0;
  187281. device->jitter = false;
  187282. firstFrameInBuffer = 0;
  187283. CDReadBuffer readBuffer (4);
  187284. readBuffer.wantsIndex = true;
  187285. int i;
  187286. for (i = 5; --i >= 0;)
  187287. {
  187288. readBuffer.startFrame = frameNeeded;
  187289. readBuffer.numFrames = framesPerIndexRead;
  187290. if (device->cdH->readAudio (&readBuffer, (false) ? device->overlapBuffer : 0))
  187291. break;
  187292. }
  187293. if (i < 0)
  187294. break;
  187295. if (readBuffer.index > last && readBuffer.index > 1)
  187296. {
  187297. last = readBuffer.index;
  187298. indexes.add (pos);
  187299. }
  187300. pos += samplesPerFrame * framesPerIndexRead;
  187301. }
  187302. indexes.removeValue (trackStart);
  187303. }
  187304. return indexes;
  187305. }
  187306. int AudioCDReader::getCDDBId()
  187307. {
  187308. using namespace CDReaderHelpers;
  187309. refreshTrackLengths();
  187310. if (numTracks > 0)
  187311. {
  187312. TOC toc;
  187313. zerostruct (toc);
  187314. if (((CDDeviceWrapper*) handle)->cdH->readTOC (&toc, true))
  187315. {
  187316. int n = 0;
  187317. for (int i = numTracks; --i >= 0;)
  187318. {
  187319. int j = getMSFAddressOf (&toc.tracks[i]);
  187320. while (j > 0)
  187321. {
  187322. n += (j % 10);
  187323. j /= 10;
  187324. }
  187325. }
  187326. if (n != 0)
  187327. {
  187328. const int t = getMSFAddressOf (&toc.tracks[numTracks])
  187329. - getMSFAddressOf (&toc.tracks[0]);
  187330. return ((n % 0xff) << 24) | (t << 8) | numTracks;
  187331. }
  187332. }
  187333. }
  187334. return 0;
  187335. }
  187336. void AudioCDReader::ejectDisk()
  187337. {
  187338. using namespace CDReaderHelpers;
  187339. ((CDDeviceWrapper*) handle)->cdH->openDrawer (true);
  187340. }
  187341. #endif
  187342. #if JUCE_USE_CDBURNER
  187343. static IDiscRecorder* enumCDBurners (StringArray* list, int indexToOpen, IDiscMaster** master)
  187344. {
  187345. CoInitialize (0);
  187346. IDiscMaster* dm;
  187347. IDiscRecorder* result = 0;
  187348. if (SUCCEEDED (CoCreateInstance (CLSID_MSDiscMasterObj, 0,
  187349. CLSCTX_INPROC_SERVER | CLSCTX_LOCAL_SERVER,
  187350. IID_IDiscMaster,
  187351. (void**) &dm)))
  187352. {
  187353. if (SUCCEEDED (dm->Open()))
  187354. {
  187355. IEnumDiscRecorders* drEnum = 0;
  187356. if (SUCCEEDED (dm->EnumDiscRecorders (&drEnum)))
  187357. {
  187358. IDiscRecorder* dr = 0;
  187359. DWORD dummy;
  187360. int index = 0;
  187361. while (drEnum->Next (1, &dr, &dummy) == S_OK)
  187362. {
  187363. if (indexToOpen == index)
  187364. {
  187365. result = dr;
  187366. break;
  187367. }
  187368. else if (list != 0)
  187369. {
  187370. BSTR path;
  187371. if (SUCCEEDED (dr->GetPath (&path)))
  187372. list->add ((const WCHAR*) path);
  187373. }
  187374. ++index;
  187375. dr->Release();
  187376. }
  187377. drEnum->Release();
  187378. }
  187379. if (master == 0)
  187380. dm->Close();
  187381. }
  187382. if (master != 0)
  187383. *master = dm;
  187384. else
  187385. dm->Release();
  187386. }
  187387. return result;
  187388. }
  187389. class AudioCDBurner::Pimpl : public IDiscMasterProgressEvents,
  187390. public Timer
  187391. {
  187392. public:
  187393. Pimpl (AudioCDBurner& owner_, IDiscMaster* discMaster_, IDiscRecorder* discRecorder_)
  187394. : owner (owner_), discMaster (discMaster_), discRecorder (discRecorder_), redbook (0),
  187395. listener (0), progress (0), shouldCancel (false), refCount (1)
  187396. {
  187397. HRESULT hr = discMaster->SetActiveDiscMasterFormat (IID_IRedbookDiscMaster, (void**) &redbook);
  187398. jassert (SUCCEEDED (hr));
  187399. hr = discMaster->SetActiveDiscRecorder (discRecorder);
  187400. //jassert (SUCCEEDED (hr));
  187401. lastState = getDiskState();
  187402. startTimer (2000);
  187403. }
  187404. ~Pimpl() {}
  187405. void releaseObjects()
  187406. {
  187407. discRecorder->Close();
  187408. if (redbook != 0)
  187409. redbook->Release();
  187410. discRecorder->Release();
  187411. discMaster->Release();
  187412. Release();
  187413. }
  187414. HRESULT __stdcall QueryInterface (REFIID id, void __RPC_FAR* __RPC_FAR* result)
  187415. {
  187416. if (result == 0)
  187417. return E_POINTER;
  187418. if (id == IID_IUnknown || id == IID_IDiscMasterProgressEvents)
  187419. {
  187420. AddRef();
  187421. *result = this;
  187422. return S_OK;
  187423. }
  187424. *result = 0;
  187425. return E_NOINTERFACE;
  187426. }
  187427. ULONG __stdcall AddRef() { return ++refCount; }
  187428. ULONG __stdcall Release() { jassert (refCount > 0); const int r = --refCount; if (r == 0) delete this; return r; }
  187429. HRESULT __stdcall QueryCancel (boolean* pbCancel)
  187430. {
  187431. if (listener != 0 && ! shouldCancel)
  187432. shouldCancel = listener->audioCDBurnProgress (progress);
  187433. *pbCancel = shouldCancel;
  187434. return S_OK;
  187435. }
  187436. HRESULT __stdcall NotifyBlockProgress (long nCompleted, long nTotal)
  187437. {
  187438. progress = nCompleted / (float) nTotal;
  187439. shouldCancel = listener != 0 && listener->audioCDBurnProgress (progress);
  187440. return E_NOTIMPL;
  187441. }
  187442. HRESULT __stdcall NotifyPnPActivity (void) { return E_NOTIMPL; }
  187443. HRESULT __stdcall NotifyAddProgress (long /*nCompletedSteps*/, long /*nTotalSteps*/) { return E_NOTIMPL; }
  187444. HRESULT __stdcall NotifyTrackProgress (long /*nCurrentTrack*/, long /*nTotalTracks*/) { return E_NOTIMPL; }
  187445. HRESULT __stdcall NotifyPreparingBurn (long /*nEstimatedSeconds*/) { return E_NOTIMPL; }
  187446. HRESULT __stdcall NotifyClosingDisc (long /*nEstimatedSeconds*/) { return E_NOTIMPL; }
  187447. HRESULT __stdcall NotifyBurnComplete (HRESULT /*status*/) { return E_NOTIMPL; }
  187448. HRESULT __stdcall NotifyEraseComplete (HRESULT /*status*/) { return E_NOTIMPL; }
  187449. class ScopedDiscOpener
  187450. {
  187451. public:
  187452. ScopedDiscOpener (Pimpl& p) : pimpl (p) { pimpl.discRecorder->OpenExclusive(); }
  187453. ~ScopedDiscOpener() { pimpl.discRecorder->Close(); }
  187454. private:
  187455. Pimpl& pimpl;
  187456. ScopedDiscOpener (const ScopedDiscOpener&);
  187457. ScopedDiscOpener& operator= (const ScopedDiscOpener&);
  187458. };
  187459. DiskState getDiskState()
  187460. {
  187461. const ScopedDiscOpener opener (*this);
  187462. long type, flags;
  187463. HRESULT hr = discRecorder->QueryMediaType (&type, &flags);
  187464. if (FAILED (hr))
  187465. return unknown;
  187466. if (type != 0 && (flags & MEDIA_WRITABLE) != 0)
  187467. return writableDiskPresent;
  187468. if (type == 0)
  187469. return noDisc;
  187470. else
  187471. return readOnlyDiskPresent;
  187472. }
  187473. int getIntProperty (const LPOLESTR name, const int defaultReturn) const
  187474. {
  187475. ComSmartPtr<IPropertyStorage> prop;
  187476. if (FAILED (discRecorder->GetRecorderProperties (&prop)))
  187477. return defaultReturn;
  187478. PROPSPEC iPropSpec;
  187479. iPropSpec.ulKind = PRSPEC_LPWSTR;
  187480. iPropSpec.lpwstr = name;
  187481. PROPVARIANT iPropVariant;
  187482. return FAILED (prop->ReadMultiple (1, &iPropSpec, &iPropVariant))
  187483. ? defaultReturn : (int) iPropVariant.lVal;
  187484. }
  187485. bool setIntProperty (const LPOLESTR name, const int value) const
  187486. {
  187487. ComSmartPtr<IPropertyStorage> prop;
  187488. if (FAILED (discRecorder->GetRecorderProperties (&prop)))
  187489. return false;
  187490. PROPSPEC iPropSpec;
  187491. iPropSpec.ulKind = PRSPEC_LPWSTR;
  187492. iPropSpec.lpwstr = name;
  187493. PROPVARIANT iPropVariant;
  187494. if (FAILED (prop->ReadMultiple (1, &iPropSpec, &iPropVariant)))
  187495. return false;
  187496. iPropVariant.lVal = (long) value;
  187497. return SUCCEEDED (prop->WriteMultiple (1, &iPropSpec, &iPropVariant, iPropVariant.vt))
  187498. && SUCCEEDED (discRecorder->SetRecorderProperties (prop));
  187499. }
  187500. void timerCallback()
  187501. {
  187502. const DiskState state = getDiskState();
  187503. if (state != lastState)
  187504. {
  187505. lastState = state;
  187506. owner.sendChangeMessage (&owner);
  187507. }
  187508. }
  187509. AudioCDBurner& owner;
  187510. DiskState lastState;
  187511. IDiscMaster* discMaster;
  187512. IDiscRecorder* discRecorder;
  187513. IRedbookDiscMaster* redbook;
  187514. AudioCDBurner::BurnProgressListener* listener;
  187515. float progress;
  187516. bool shouldCancel;
  187517. private:
  187518. int refCount;
  187519. };
  187520. AudioCDBurner::AudioCDBurner (const int deviceIndex)
  187521. {
  187522. IDiscMaster* discMaster = 0;
  187523. IDiscRecorder* discRecorder = enumCDBurners (0, deviceIndex, &discMaster);
  187524. if (discRecorder != 0)
  187525. pimpl = new Pimpl (*this, discMaster, discRecorder);
  187526. }
  187527. AudioCDBurner::~AudioCDBurner()
  187528. {
  187529. if (pimpl != 0)
  187530. pimpl.release()->releaseObjects();
  187531. }
  187532. const StringArray AudioCDBurner::findAvailableDevices()
  187533. {
  187534. StringArray devs;
  187535. enumCDBurners (&devs, -1, 0);
  187536. return devs;
  187537. }
  187538. AudioCDBurner* AudioCDBurner::openDevice (const int deviceIndex)
  187539. {
  187540. ScopedPointer<AudioCDBurner> b (new AudioCDBurner (deviceIndex));
  187541. if (b->pimpl == 0)
  187542. b = 0;
  187543. return b.release();
  187544. }
  187545. AudioCDBurner::DiskState AudioCDBurner::getDiskState() const
  187546. {
  187547. return pimpl->getDiskState();
  187548. }
  187549. bool AudioCDBurner::isDiskPresent() const
  187550. {
  187551. return getDiskState() == writableDiskPresent;
  187552. }
  187553. bool AudioCDBurner::openTray()
  187554. {
  187555. const Pimpl::ScopedDiscOpener opener (*pimpl);
  187556. return SUCCEEDED (pimpl->discRecorder->Eject());
  187557. }
  187558. AudioCDBurner::DiskState AudioCDBurner::waitUntilStateChange (int timeOutMilliseconds)
  187559. {
  187560. const int64 timeout = Time::currentTimeMillis() + timeOutMilliseconds;
  187561. DiskState oldState = getDiskState();
  187562. DiskState newState = oldState;
  187563. while (newState == oldState && Time::currentTimeMillis() < timeout)
  187564. {
  187565. newState = getDiskState();
  187566. Thread::sleep (jmin (250, (int) (timeout - Time::currentTimeMillis())));
  187567. }
  187568. return newState;
  187569. }
  187570. const Array<int> AudioCDBurner::getAvailableWriteSpeeds() const
  187571. {
  187572. Array<int> results;
  187573. const int maxSpeed = pimpl->getIntProperty (L"MaxWriteSpeed", 1);
  187574. const int speeds[] = { 1, 2, 4, 8, 12, 16, 20, 24, 32, 40, 64, 80 };
  187575. for (int i = 0; i < numElementsInArray (speeds); ++i)
  187576. if (speeds[i] <= maxSpeed)
  187577. results.add (speeds[i]);
  187578. results.addIfNotAlreadyThere (maxSpeed);
  187579. return results;
  187580. }
  187581. bool AudioCDBurner::setBufferUnderrunProtection (const bool shouldBeEnabled)
  187582. {
  187583. if (pimpl->getIntProperty (L"BufferUnderrunFreeCapable", 0) == 0)
  187584. return false;
  187585. pimpl->setIntProperty (L"EnableBufferUnderrunFree", shouldBeEnabled ? -1 : 0);
  187586. return pimpl->getIntProperty (L"EnableBufferUnderrunFree", 0) != 0;
  187587. }
  187588. int AudioCDBurner::getNumAvailableAudioBlocks() const
  187589. {
  187590. long blocksFree = 0;
  187591. pimpl->redbook->GetAvailableAudioTrackBlocks (&blocksFree);
  187592. return blocksFree;
  187593. }
  187594. const String AudioCDBurner::burn (AudioCDBurner::BurnProgressListener* listener, bool ejectDiscAfterwards,
  187595. bool performFakeBurnForTesting, int writeSpeed)
  187596. {
  187597. pimpl->setIntProperty (L"WriteSpeed", writeSpeed > 0 ? writeSpeed : -1);
  187598. pimpl->listener = listener;
  187599. pimpl->progress = 0;
  187600. pimpl->shouldCancel = false;
  187601. UINT_PTR cookie;
  187602. HRESULT hr = pimpl->discMaster->ProgressAdvise ((AudioCDBurner::Pimpl*) pimpl, &cookie);
  187603. hr = pimpl->discMaster->RecordDisc (performFakeBurnForTesting,
  187604. ejectDiscAfterwards);
  187605. String error;
  187606. if (hr != S_OK)
  187607. {
  187608. const char* e = "Couldn't open or write to the CD device";
  187609. if (hr == IMAPI_E_USERABORT)
  187610. e = "User cancelled the write operation";
  187611. else if (hr == IMAPI_E_MEDIUM_NOTPRESENT || hr == IMAPI_E_TRACKOPEN)
  187612. e = "No Disk present";
  187613. error = e;
  187614. }
  187615. pimpl->discMaster->ProgressUnadvise (cookie);
  187616. pimpl->listener = 0;
  187617. return error;
  187618. }
  187619. bool AudioCDBurner::addAudioTrack (AudioSource* audioSource, int numSamples)
  187620. {
  187621. if (audioSource == 0)
  187622. return false;
  187623. ScopedPointer<AudioSource> source (audioSource);
  187624. long bytesPerBlock;
  187625. HRESULT hr = pimpl->redbook->GetAudioBlockSize (&bytesPerBlock);
  187626. const int samplesPerBlock = bytesPerBlock / 4;
  187627. bool ok = true;
  187628. hr = pimpl->redbook->CreateAudioTrack ((long) numSamples / (bytesPerBlock * 4));
  187629. HeapBlock <byte> buffer (bytesPerBlock);
  187630. AudioSampleBuffer sourceBuffer (2, samplesPerBlock);
  187631. int samplesDone = 0;
  187632. source->prepareToPlay (samplesPerBlock, 44100.0);
  187633. while (ok)
  187634. {
  187635. {
  187636. AudioSourceChannelInfo info;
  187637. info.buffer = &sourceBuffer;
  187638. info.numSamples = samplesPerBlock;
  187639. info.startSample = 0;
  187640. sourceBuffer.clear();
  187641. source->getNextAudioBlock (info);
  187642. }
  187643. zeromem (buffer, bytesPerBlock);
  187644. AudioDataConverters::convertFloatToInt16LE (sourceBuffer.getSampleData (0, 0),
  187645. buffer, samplesPerBlock, 4);
  187646. AudioDataConverters::convertFloatToInt16LE (sourceBuffer.getSampleData (1, 0),
  187647. buffer + 2, samplesPerBlock, 4);
  187648. hr = pimpl->redbook->AddAudioTrackBlocks (buffer, bytesPerBlock);
  187649. if (FAILED (hr))
  187650. ok = false;
  187651. samplesDone += samplesPerBlock;
  187652. if (samplesDone >= numSamples)
  187653. break;
  187654. }
  187655. hr = pimpl->redbook->CloseAudioTrack();
  187656. return ok && hr == S_OK;
  187657. }
  187658. #endif
  187659. #endif
  187660. /*** End of inlined file: juce_win32_AudioCDReader.cpp ***/
  187661. /*** Start of inlined file: juce_win32_Midi.cpp ***/
  187662. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  187663. // compiled on its own).
  187664. #if JUCE_INCLUDED_FILE
  187665. using ::free;
  187666. namespace MidiConstants
  187667. {
  187668. static const int midiBufferSize = 1024 * 10;
  187669. static const int numInHeaders = 32;
  187670. static const int inBufferSize = 256;
  187671. }
  187672. class MidiInThread : public Thread
  187673. {
  187674. public:
  187675. MidiInThread (MidiInput* const input_,
  187676. MidiInputCallback* const callback_)
  187677. : Thread ("Juce Midi"),
  187678. hIn (0),
  187679. input (input_),
  187680. callback (callback_),
  187681. isStarted (false),
  187682. startTime (0),
  187683. pendingLength(0)
  187684. {
  187685. for (int i = MidiConstants::numInHeaders; --i >= 0;)
  187686. {
  187687. zeromem (&hdr[i], sizeof (MIDIHDR));
  187688. hdr[i].lpData = inData[i];
  187689. hdr[i].dwBufferLength = MidiConstants::inBufferSize;
  187690. }
  187691. };
  187692. ~MidiInThread()
  187693. {
  187694. stop();
  187695. if (hIn != 0)
  187696. {
  187697. int count = 5;
  187698. while (--count >= 0)
  187699. {
  187700. if (midiInClose (hIn) == MMSYSERR_NOERROR)
  187701. break;
  187702. Sleep (20);
  187703. }
  187704. }
  187705. }
  187706. void handle (const uint32 message, const uint32 timeStamp) throw()
  187707. {
  187708. const int byte = message & 0xff;
  187709. if (byte < 0x80)
  187710. return;
  187711. const int numBytes = MidiMessage::getMessageLengthFromFirstByte ((uint8) byte);
  187712. const double time = timeStampToTime (timeStamp);
  187713. {
  187714. const ScopedLock sl (lock);
  187715. if (pendingLength < MidiConstants::midiBufferSize - 12)
  187716. {
  187717. char* const p = pending + pendingLength;
  187718. *(double*) p = time;
  187719. *(uint32*) (p + 8) = numBytes;
  187720. *(uint32*) (p + 12) = message;
  187721. pendingLength += 12 + numBytes;
  187722. }
  187723. else
  187724. {
  187725. jassertfalse // midi buffer overflow! You might need to increase the size..
  187726. }
  187727. }
  187728. notify();
  187729. }
  187730. void handleSysEx (MIDIHDR* const hdr, const uint32 timeStamp) throw()
  187731. {
  187732. const int num = hdr->dwBytesRecorded;
  187733. if (num > 0)
  187734. {
  187735. const double time = timeStampToTime (timeStamp);
  187736. {
  187737. const ScopedLock sl (lock);
  187738. if (pendingLength < MidiConstants::midiBufferSize - (8 + num))
  187739. {
  187740. char* const p = pending + pendingLength;
  187741. *(double*) p = time;
  187742. *(uint32*) (p + 8) = num;
  187743. memcpy (p + 12, hdr->lpData, num);
  187744. pendingLength += 12 + num;
  187745. }
  187746. else
  187747. {
  187748. jassertfalse // midi buffer overflow! You might need to increase the size..
  187749. }
  187750. }
  187751. notify();
  187752. }
  187753. }
  187754. void writeBlock (const int i) throw()
  187755. {
  187756. hdr[i].dwBytesRecorded = 0;
  187757. MMRESULT res = midiInPrepareHeader (hIn, &hdr[i], sizeof (MIDIHDR));
  187758. jassert (res == MMSYSERR_NOERROR);
  187759. res = midiInAddBuffer (hIn, &hdr[i], sizeof (MIDIHDR));
  187760. jassert (res == MMSYSERR_NOERROR);
  187761. }
  187762. void run()
  187763. {
  187764. MemoryBlock pendingCopy (64);
  187765. while (! threadShouldExit())
  187766. {
  187767. for (int i = 0; i < MidiConstants::numInHeaders; ++i)
  187768. {
  187769. if ((hdr[i].dwFlags & WHDR_DONE) != 0)
  187770. {
  187771. MMRESULT res = midiInUnprepareHeader (hIn, &hdr[i], sizeof (MIDIHDR));
  187772. (void) res;
  187773. jassert (res == MMSYSERR_NOERROR);
  187774. writeBlock (i);
  187775. }
  187776. }
  187777. int len;
  187778. {
  187779. const ScopedLock sl (lock);
  187780. len = pendingLength;
  187781. if (len > 0)
  187782. {
  187783. pendingCopy.ensureSize (len);
  187784. pendingCopy.copyFrom (pending, 0, len);
  187785. pendingLength = 0;
  187786. }
  187787. }
  187788. //xxx needs to figure out if blocks are broken up or not
  187789. if (len == 0)
  187790. {
  187791. wait (500);
  187792. }
  187793. else
  187794. {
  187795. const char* p = (const char*) pendingCopy.getData();
  187796. while (len > 0)
  187797. {
  187798. const double time = *(const double*) p;
  187799. const int messageLen = *(const int*) (p + 8);
  187800. const MidiMessage message ((const uint8*) (p + 12), messageLen, time);
  187801. callback->handleIncomingMidiMessage (input, message);
  187802. p += 12 + messageLen;
  187803. len -= 12 + messageLen;
  187804. }
  187805. }
  187806. }
  187807. }
  187808. void start() throw()
  187809. {
  187810. jassert (hIn != 0);
  187811. if (hIn != 0 && ! isStarted)
  187812. {
  187813. stop();
  187814. activeMidiThreads.addIfNotAlreadyThere (this);
  187815. int i;
  187816. for (i = 0; i < MidiConstants::numInHeaders; ++i)
  187817. writeBlock (i);
  187818. startTime = Time::getMillisecondCounter();
  187819. MMRESULT res = midiInStart (hIn);
  187820. jassert (res == MMSYSERR_NOERROR);
  187821. if (res == MMSYSERR_NOERROR)
  187822. {
  187823. isStarted = true;
  187824. pendingLength = 0;
  187825. startThread (6);
  187826. }
  187827. }
  187828. }
  187829. void stop() throw()
  187830. {
  187831. if (isStarted)
  187832. {
  187833. stopThread (5000);
  187834. midiInReset (hIn);
  187835. midiInStop (hIn);
  187836. activeMidiThreads.removeValue (this);
  187837. { const ScopedLock sl (lock); }
  187838. for (int i = MidiConstants::numInHeaders; --i >= 0;)
  187839. {
  187840. if ((hdr[i].dwFlags & WHDR_DONE) != 0)
  187841. {
  187842. int c = 10;
  187843. while (--c >= 0 && midiInUnprepareHeader (hIn, &hdr[i], sizeof (MIDIHDR)) == MIDIERR_STILLPLAYING)
  187844. Sleep (20);
  187845. jassert (c >= 0);
  187846. }
  187847. }
  187848. isStarted = false;
  187849. pendingLength = 0;
  187850. }
  187851. }
  187852. static void CALLBACK midiInCallback (HMIDIIN, UINT uMsg, DWORD_PTR dwInstance, DWORD_PTR midiMessage, DWORD_PTR timeStamp)
  187853. {
  187854. MidiInThread* const thread = reinterpret_cast <MidiInThread*> (dwInstance);
  187855. if (thread != 0 && activeMidiThreads.contains (thread))
  187856. {
  187857. if (uMsg == MIM_DATA)
  187858. thread->handle ((uint32) midiMessage, (uint32) timeStamp);
  187859. else if (uMsg == MIM_LONGDATA)
  187860. thread->handleSysEx ((MIDIHDR*) midiMessage, (uint32) timeStamp);
  187861. }
  187862. }
  187863. juce_UseDebuggingNewOperator
  187864. HMIDIIN hIn;
  187865. private:
  187866. static Array <void*, CriticalSection> activeMidiThreads;
  187867. MidiInput* input;
  187868. MidiInputCallback* callback;
  187869. bool isStarted;
  187870. uint32 startTime;
  187871. CriticalSection lock;
  187872. MIDIHDR hdr [MidiConstants::numInHeaders];
  187873. char inData [MidiConstants::numInHeaders] [MidiConstants::inBufferSize];
  187874. int pendingLength;
  187875. char pending [MidiConstants::midiBufferSize];
  187876. double timeStampToTime (uint32 timeStamp) throw()
  187877. {
  187878. timeStamp += startTime;
  187879. const uint32 now = Time::getMillisecondCounter();
  187880. if (timeStamp > now)
  187881. {
  187882. if (timeStamp > now + 2)
  187883. --startTime;
  187884. timeStamp = now;
  187885. }
  187886. return 0.001 * timeStamp;
  187887. }
  187888. MidiInThread (const MidiInThread&);
  187889. MidiInThread& operator= (const MidiInThread&);
  187890. };
  187891. Array <void*, CriticalSection> MidiInThread::activeMidiThreads;
  187892. const StringArray MidiInput::getDevices()
  187893. {
  187894. StringArray s;
  187895. const int num = midiInGetNumDevs();
  187896. for (int i = 0; i < num; ++i)
  187897. {
  187898. MIDIINCAPS mc;
  187899. zerostruct (mc);
  187900. if (midiInGetDevCaps (i, &mc, sizeof (mc)) == MMSYSERR_NOERROR)
  187901. s.add (String (mc.szPname, sizeof (mc.szPname)));
  187902. }
  187903. return s;
  187904. }
  187905. int MidiInput::getDefaultDeviceIndex()
  187906. {
  187907. return 0;
  187908. }
  187909. MidiInput* MidiInput::openDevice (const int index, MidiInputCallback* const callback)
  187910. {
  187911. if (callback == 0)
  187912. return 0;
  187913. UINT deviceId = MIDI_MAPPER;
  187914. int n = 0;
  187915. String name;
  187916. const int num = midiInGetNumDevs();
  187917. for (int i = 0; i < num; ++i)
  187918. {
  187919. MIDIINCAPS mc;
  187920. zerostruct (mc);
  187921. if (midiInGetDevCaps (i, &mc, sizeof (mc)) == MMSYSERR_NOERROR)
  187922. {
  187923. if (index == n)
  187924. {
  187925. deviceId = i;
  187926. name = String (mc.szPname, sizeof (mc.szPname));
  187927. break;
  187928. }
  187929. ++n;
  187930. }
  187931. }
  187932. ScopedPointer <MidiInput> in (new MidiInput (name));
  187933. ScopedPointer <MidiInThread> thread (new MidiInThread (in, callback));
  187934. HMIDIIN h;
  187935. HRESULT err = midiInOpen (&h, deviceId,
  187936. (DWORD_PTR) &MidiInThread::midiInCallback,
  187937. (DWORD_PTR) (MidiInThread*) thread,
  187938. CALLBACK_FUNCTION);
  187939. if (err == MMSYSERR_NOERROR)
  187940. {
  187941. thread->hIn = h;
  187942. in->internal = (void*) thread.release();
  187943. return in.release();
  187944. }
  187945. return 0;
  187946. }
  187947. MidiInput::MidiInput (const String& name_)
  187948. : name (name_),
  187949. internal (0)
  187950. {
  187951. }
  187952. MidiInput::~MidiInput()
  187953. {
  187954. delete static_cast <MidiInThread*> (internal);
  187955. }
  187956. void MidiInput::start()
  187957. {
  187958. static_cast <MidiInThread*> (internal)->start();
  187959. }
  187960. void MidiInput::stop()
  187961. {
  187962. static_cast <MidiInThread*> (internal)->stop();
  187963. }
  187964. struct MidiOutHandle
  187965. {
  187966. int refCount;
  187967. UINT deviceId;
  187968. HMIDIOUT handle;
  187969. static Array<MidiOutHandle*> activeHandles;
  187970. juce_UseDebuggingNewOperator
  187971. };
  187972. Array<MidiOutHandle*> MidiOutHandle::activeHandles;
  187973. const StringArray MidiOutput::getDevices()
  187974. {
  187975. StringArray s;
  187976. const int num = midiOutGetNumDevs();
  187977. for (int i = 0; i < num; ++i)
  187978. {
  187979. MIDIOUTCAPS mc;
  187980. zerostruct (mc);
  187981. if (midiOutGetDevCaps (i, &mc, sizeof (mc)) == MMSYSERR_NOERROR)
  187982. s.add (String (mc.szPname, sizeof (mc.szPname)));
  187983. }
  187984. return s;
  187985. }
  187986. int MidiOutput::getDefaultDeviceIndex()
  187987. {
  187988. const int num = midiOutGetNumDevs();
  187989. int n = 0;
  187990. for (int i = 0; i < num; ++i)
  187991. {
  187992. MIDIOUTCAPS mc;
  187993. zerostruct (mc);
  187994. if (midiOutGetDevCaps (i, &mc, sizeof (mc)) == MMSYSERR_NOERROR)
  187995. {
  187996. if ((mc.wTechnology & MOD_MAPPER) != 0)
  187997. return n;
  187998. ++n;
  187999. }
  188000. }
  188001. return 0;
  188002. }
  188003. MidiOutput* MidiOutput::openDevice (int index)
  188004. {
  188005. UINT deviceId = MIDI_MAPPER;
  188006. const int num = midiOutGetNumDevs();
  188007. int i, n = 0;
  188008. for (i = 0; i < num; ++i)
  188009. {
  188010. MIDIOUTCAPS mc;
  188011. zerostruct (mc);
  188012. if (midiOutGetDevCaps (i, &mc, sizeof (mc)) == MMSYSERR_NOERROR)
  188013. {
  188014. // use the microsoft sw synth as a default - best not to allow deviceId
  188015. // to be MIDI_MAPPER, or else device sharing breaks
  188016. if (String (mc.szPname, sizeof (mc.szPname)).containsIgnoreCase (T("microsoft")))
  188017. deviceId = i;
  188018. if (index == n)
  188019. {
  188020. deviceId = i;
  188021. break;
  188022. }
  188023. ++n;
  188024. }
  188025. }
  188026. for (i = MidiOutHandle::activeHandles.size(); --i >= 0;)
  188027. {
  188028. MidiOutHandle* const han = MidiOutHandle::activeHandles.getUnchecked(i);
  188029. if (han != 0 && han->deviceId == deviceId)
  188030. {
  188031. han->refCount++;
  188032. MidiOutput* const out = new MidiOutput();
  188033. out->internal = (void*) han;
  188034. return out;
  188035. }
  188036. }
  188037. for (i = 4; --i >= 0;)
  188038. {
  188039. HMIDIOUT h = 0;
  188040. MMRESULT res = midiOutOpen (&h, deviceId, 0, 0, CALLBACK_NULL);
  188041. if (res == MMSYSERR_NOERROR)
  188042. {
  188043. MidiOutHandle* const han = new MidiOutHandle();
  188044. han->deviceId = deviceId;
  188045. han->refCount = 1;
  188046. han->handle = h;
  188047. MidiOutHandle::activeHandles.add (han);
  188048. MidiOutput* const out = new MidiOutput();
  188049. out->internal = (void*) han;
  188050. return out;
  188051. }
  188052. else if (res == MMSYSERR_ALLOCATED)
  188053. {
  188054. Sleep (100);
  188055. }
  188056. else
  188057. {
  188058. break;
  188059. }
  188060. }
  188061. return 0;
  188062. }
  188063. MidiOutput::~MidiOutput()
  188064. {
  188065. MidiOutHandle* const h = static_cast <MidiOutHandle*> (internal);
  188066. if (MidiOutHandle::activeHandles.contains (h) && --(h->refCount) == 0)
  188067. {
  188068. midiOutClose (h->handle);
  188069. MidiOutHandle::activeHandles.removeValue (h);
  188070. delete h;
  188071. }
  188072. }
  188073. void MidiOutput::reset()
  188074. {
  188075. const MidiOutHandle* const h = static_cast <const MidiOutHandle*> (internal);
  188076. midiOutReset (h->handle);
  188077. }
  188078. bool MidiOutput::getVolume (float& leftVol,
  188079. float& rightVol)
  188080. {
  188081. const MidiOutHandle* const handle = static_cast <const MidiOutHandle*> (internal);
  188082. DWORD n;
  188083. if (midiOutGetVolume (handle->handle, &n) == MMSYSERR_NOERROR)
  188084. {
  188085. const unsigned short* const nn = (const unsigned short*) &n;
  188086. rightVol = nn[0] / (float) 0xffff;
  188087. leftVol = nn[1] / (float) 0xffff;
  188088. return true;
  188089. }
  188090. else
  188091. {
  188092. rightVol = leftVol = 1.0f;
  188093. return false;
  188094. }
  188095. }
  188096. void MidiOutput::setVolume (float leftVol,
  188097. float rightVol)
  188098. {
  188099. const MidiOutHandle* const handle = static_cast <MidiOutHandle*> (internal);
  188100. DWORD n;
  188101. unsigned short* const nn = (unsigned short*) &n;
  188102. nn[0] = (unsigned short) jlimit (0, 0xffff, (int) (rightVol * 0xffff));
  188103. nn[1] = (unsigned short) jlimit (0, 0xffff, (int) (leftVol * 0xffff));
  188104. midiOutSetVolume (handle->handle, n);
  188105. }
  188106. void MidiOutput::sendMessageNow (const MidiMessage& message)
  188107. {
  188108. const MidiOutHandle* const handle = static_cast <const MidiOutHandle*> (internal);
  188109. if (message.getRawDataSize() > 3
  188110. || message.isSysEx())
  188111. {
  188112. MIDIHDR h;
  188113. zerostruct (h);
  188114. h.lpData = (char*) message.getRawData();
  188115. h.dwBufferLength = message.getRawDataSize();
  188116. h.dwBytesRecorded = message.getRawDataSize();
  188117. if (midiOutPrepareHeader (handle->handle, &h, sizeof (MIDIHDR)) == MMSYSERR_NOERROR)
  188118. {
  188119. MMRESULT res = midiOutLongMsg (handle->handle, &h, sizeof (MIDIHDR));
  188120. if (res == MMSYSERR_NOERROR)
  188121. {
  188122. while ((h.dwFlags & MHDR_DONE) == 0)
  188123. Sleep (1);
  188124. int count = 500; // 1 sec timeout
  188125. while (--count >= 0)
  188126. {
  188127. res = midiOutUnprepareHeader (handle->handle, &h, sizeof (MIDIHDR));
  188128. if (res == MIDIERR_STILLPLAYING)
  188129. Sleep (2);
  188130. else
  188131. break;
  188132. }
  188133. }
  188134. }
  188135. }
  188136. else
  188137. {
  188138. midiOutShortMsg (handle->handle,
  188139. *(unsigned int*) message.getRawData());
  188140. }
  188141. }
  188142. #endif
  188143. /*** End of inlined file: juce_win32_Midi.cpp ***/
  188144. /*** Start of inlined file: juce_win32_ASIO.cpp ***/
  188145. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  188146. // compiled on its own).
  188147. #if JUCE_INCLUDED_FILE && JUCE_ASIO
  188148. #undef WINDOWS
  188149. // #define ASIO_DEBUGGING
  188150. #ifdef ASIO_DEBUGGING
  188151. #define log(a) { Logger::writeToLog (a); DBG (a) }
  188152. #else
  188153. #define log(a) {}
  188154. #endif
  188155. #ifdef ASIO_DEBUGGING
  188156. static void logError (const String& context, long error)
  188157. {
  188158. String err ("unknown error");
  188159. if (error == ASE_NotPresent)
  188160. err = "Not Present";
  188161. else if (error == ASE_HWMalfunction)
  188162. err = "Hardware Malfunction";
  188163. else if (error == ASE_InvalidParameter)
  188164. err = "Invalid Parameter";
  188165. else if (error == ASE_InvalidMode)
  188166. err = "Invalid Mode";
  188167. else if (error == ASE_SPNotAdvancing)
  188168. err = "Sample position not advancing";
  188169. else if (error == ASE_NoClock)
  188170. err = "No Clock";
  188171. else if (error == ASE_NoMemory)
  188172. err = "Out of memory";
  188173. log (T("!!error: ") + context + T(" - ") + err);
  188174. }
  188175. #else
  188176. #define logError(a, b) {}
  188177. #endif
  188178. class ASIOAudioIODevice;
  188179. static ASIOAudioIODevice* volatile currentASIODev[3] = { 0, 0, 0 };
  188180. static const int maxASIOChannels = 160;
  188181. class JUCE_API ASIOAudioIODevice : public AudioIODevice,
  188182. private Timer
  188183. {
  188184. public:
  188185. Component ourWindow;
  188186. ASIOAudioIODevice (const String& name_, const CLSID classId_, const int slotNumber,
  188187. const String& optionalDllForDirectLoading_)
  188188. : AudioIODevice (name_, T("ASIO")),
  188189. asioObject (0),
  188190. classId (classId_),
  188191. optionalDllForDirectLoading (optionalDllForDirectLoading_),
  188192. currentBitDepth (16),
  188193. currentSampleRate (0),
  188194. isOpen_ (false),
  188195. isStarted (false),
  188196. postOutput (true),
  188197. insideControlPanelModalLoop (false),
  188198. shouldUsePreferredSize (false)
  188199. {
  188200. name = name_;
  188201. ourWindow.addToDesktop (0);
  188202. windowHandle = ourWindow.getWindowHandle();
  188203. jassert (currentASIODev [slotNumber] == 0);
  188204. currentASIODev [slotNumber] = this;
  188205. openDevice();
  188206. }
  188207. ~ASIOAudioIODevice()
  188208. {
  188209. for (int i = 0; i < numElementsInArray (currentASIODev); ++i)
  188210. if (currentASIODev[i] == this)
  188211. currentASIODev[i] = 0;
  188212. close();
  188213. log ("ASIO - exiting");
  188214. removeCurrentDriver();
  188215. }
  188216. void updateSampleRates()
  188217. {
  188218. // find a list of sample rates..
  188219. const double possibleSampleRates[] = { 44100.0, 48000.0, 88200.0, 96000.0, 176400.0, 192000.0 };
  188220. sampleRates.clear();
  188221. if (asioObject != 0)
  188222. {
  188223. for (int index = 0; index < numElementsInArray (possibleSampleRates); ++index)
  188224. {
  188225. const long err = asioObject->canSampleRate (possibleSampleRates[index]);
  188226. if (err == 0)
  188227. {
  188228. sampleRates.add ((int) possibleSampleRates[index]);
  188229. log (T("rate: ") + String ((int) possibleSampleRates[index]));
  188230. }
  188231. else if (err != ASE_NoClock)
  188232. {
  188233. logError (T("CanSampleRate"), err);
  188234. }
  188235. }
  188236. if (sampleRates.size() == 0)
  188237. {
  188238. double cr = 0;
  188239. const long err = asioObject->getSampleRate (&cr);
  188240. log (T("No sample rates supported - current rate: ") + String ((int) cr));
  188241. if (err == 0)
  188242. sampleRates.add ((int) cr);
  188243. }
  188244. }
  188245. }
  188246. const StringArray getOutputChannelNames()
  188247. {
  188248. return outputChannelNames;
  188249. }
  188250. const StringArray getInputChannelNames()
  188251. {
  188252. return inputChannelNames;
  188253. }
  188254. int getNumSampleRates()
  188255. {
  188256. return sampleRates.size();
  188257. }
  188258. double getSampleRate (int index)
  188259. {
  188260. return sampleRates [index];
  188261. }
  188262. int getNumBufferSizesAvailable()
  188263. {
  188264. return bufferSizes.size();
  188265. }
  188266. int getBufferSizeSamples (int index)
  188267. {
  188268. return bufferSizes [index];
  188269. }
  188270. int getDefaultBufferSize()
  188271. {
  188272. return preferredSize;
  188273. }
  188274. const String open (const BigInteger& inputChannels,
  188275. const BigInteger& outputChannels,
  188276. double sr,
  188277. int bufferSizeSamples)
  188278. {
  188279. close();
  188280. currentCallback = 0;
  188281. if (bufferSizeSamples <= 0)
  188282. shouldUsePreferredSize = true;
  188283. if (asioObject == 0 || ! isASIOOpen)
  188284. {
  188285. log ("Warning: device not open");
  188286. const String err (openDevice());
  188287. if (asioObject == 0 || ! isASIOOpen)
  188288. return err;
  188289. }
  188290. isStarted = false;
  188291. bufferIndex = -1;
  188292. long err = 0;
  188293. long newPreferredSize = 0;
  188294. // if the preferred size has just changed, assume it's a control panel thing and use it as the new value.
  188295. minSize = 0;
  188296. maxSize = 0;
  188297. newPreferredSize = 0;
  188298. granularity = 0;
  188299. if (asioObject->getBufferSize (&minSize, &maxSize, &newPreferredSize, &granularity) == 0)
  188300. {
  188301. if (preferredSize != 0 && newPreferredSize != 0 && newPreferredSize != preferredSize)
  188302. shouldUsePreferredSize = true;
  188303. preferredSize = newPreferredSize;
  188304. }
  188305. // unfortunate workaround for certain manufacturers whose drivers crash horribly if you make
  188306. // dynamic changes to the buffer size...
  188307. shouldUsePreferredSize = shouldUsePreferredSize
  188308. || getName().containsIgnoreCase (T("Digidesign"));
  188309. if (shouldUsePreferredSize)
  188310. {
  188311. log ("Using preferred size for buffer..");
  188312. if ((err = asioObject->getBufferSize (&minSize, &maxSize, &preferredSize, &granularity)) == 0)
  188313. {
  188314. bufferSizeSamples = preferredSize;
  188315. }
  188316. else
  188317. {
  188318. bufferSizeSamples = 1024;
  188319. logError ("GetBufferSize1", err);
  188320. }
  188321. shouldUsePreferredSize = false;
  188322. }
  188323. int sampleRate = roundDoubleToInt (sr);
  188324. currentSampleRate = sampleRate;
  188325. currentBlockSizeSamples = bufferSizeSamples;
  188326. currentChansOut.clear();
  188327. currentChansIn.clear();
  188328. zeromem (inBuffers, sizeof (inBuffers));
  188329. zeromem (outBuffers, sizeof (outBuffers));
  188330. updateSampleRates();
  188331. if (sampleRate == 0 || (sampleRates.size() > 0 && ! sampleRates.contains (sampleRate)))
  188332. sampleRate = sampleRates[0];
  188333. jassert (sampleRate != 0);
  188334. if (sampleRate == 0)
  188335. sampleRate = 44100;
  188336. long numSources = 32;
  188337. ASIOClockSource clocks[32];
  188338. zeromem (clocks, sizeof (clocks));
  188339. asioObject->getClockSources (clocks, &numSources);
  188340. bool isSourceSet = false;
  188341. // careful not to remove this loop because it does more than just logging!
  188342. int i;
  188343. for (i = 0; i < numSources; ++i)
  188344. {
  188345. String s ("clock: ");
  188346. s += clocks[i].name;
  188347. if (clocks[i].isCurrentSource)
  188348. {
  188349. isSourceSet = true;
  188350. s << " (cur)";
  188351. }
  188352. log (s);
  188353. }
  188354. if (numSources > 1 && ! isSourceSet)
  188355. {
  188356. log ("setting clock source");
  188357. asioObject->setClockSource (clocks[0].index);
  188358. Thread::sleep (20);
  188359. }
  188360. else
  188361. {
  188362. if (numSources == 0)
  188363. {
  188364. log ("ASIO - no clock sources!");
  188365. }
  188366. }
  188367. double cr = 0;
  188368. err = asioObject->getSampleRate (&cr);
  188369. if (err == 0)
  188370. {
  188371. currentSampleRate = cr;
  188372. }
  188373. else
  188374. {
  188375. logError ("GetSampleRate", err);
  188376. currentSampleRate = 0;
  188377. }
  188378. error = String::empty;
  188379. needToReset = false;
  188380. isReSync = false;
  188381. err = 0;
  188382. bool buffersCreated = false;
  188383. if (currentSampleRate != sampleRate)
  188384. {
  188385. log (T("ASIO samplerate: ") + String (currentSampleRate) + T(" to ") + String (sampleRate));
  188386. err = asioObject->setSampleRate (sampleRate);
  188387. if (err == ASE_NoClock && numSources > 0)
  188388. {
  188389. log ("trying to set a clock source..");
  188390. Thread::sleep (10);
  188391. err = asioObject->setClockSource (clocks[0].index);
  188392. if (err != 0)
  188393. {
  188394. logError ("SetClock", err);
  188395. }
  188396. Thread::sleep (10);
  188397. err = asioObject->setSampleRate (sampleRate);
  188398. }
  188399. }
  188400. if (err == 0)
  188401. {
  188402. currentSampleRate = sampleRate;
  188403. if (needToReset)
  188404. {
  188405. if (isReSync)
  188406. {
  188407. log ("Resync request");
  188408. }
  188409. log ("! Resetting ASIO after sample rate change");
  188410. removeCurrentDriver();
  188411. loadDriver();
  188412. const String error (initDriver());
  188413. if (error.isNotEmpty())
  188414. {
  188415. log (T("ASIOInit: ") + error);
  188416. }
  188417. needToReset = false;
  188418. isReSync = false;
  188419. }
  188420. numActiveInputChans = 0;
  188421. numActiveOutputChans = 0;
  188422. ASIOBufferInfo* info = bufferInfos;
  188423. int i;
  188424. for (i = 0; i < totalNumInputChans; ++i)
  188425. {
  188426. if (inputChannels[i])
  188427. {
  188428. currentChansIn.setBit (i);
  188429. info->isInput = 1;
  188430. info->channelNum = i;
  188431. info->buffers[0] = info->buffers[1] = 0;
  188432. ++info;
  188433. ++numActiveInputChans;
  188434. }
  188435. }
  188436. for (i = 0; i < totalNumOutputChans; ++i)
  188437. {
  188438. if (outputChannels[i])
  188439. {
  188440. currentChansOut.setBit (i);
  188441. info->isInput = 0;
  188442. info->channelNum = i;
  188443. info->buffers[0] = info->buffers[1] = 0;
  188444. ++info;
  188445. ++numActiveOutputChans;
  188446. }
  188447. }
  188448. const int totalBuffers = numActiveInputChans + numActiveOutputChans;
  188449. callbacks.sampleRateDidChange = &sampleRateChangedCallback;
  188450. if (currentASIODev[0] == this)
  188451. {
  188452. callbacks.bufferSwitch = &bufferSwitchCallback0;
  188453. callbacks.asioMessage = &asioMessagesCallback0;
  188454. callbacks.bufferSwitchTimeInfo = &bufferSwitchTimeInfoCallback0;
  188455. }
  188456. else if (currentASIODev[1] == this)
  188457. {
  188458. callbacks.bufferSwitch = &bufferSwitchCallback1;
  188459. callbacks.asioMessage = &asioMessagesCallback1;
  188460. callbacks.bufferSwitchTimeInfo = &bufferSwitchTimeInfoCallback1;
  188461. }
  188462. else if (currentASIODev[2] == this)
  188463. {
  188464. callbacks.bufferSwitch = &bufferSwitchCallback2;
  188465. callbacks.asioMessage = &asioMessagesCallback2;
  188466. callbacks.bufferSwitchTimeInfo = &bufferSwitchTimeInfoCallback2;
  188467. }
  188468. else
  188469. {
  188470. jassertfalse
  188471. }
  188472. log ("disposing buffers");
  188473. err = asioObject->disposeBuffers();
  188474. log (T("creating buffers: ") + String (totalBuffers) + T(", ") + String (currentBlockSizeSamples));
  188475. err = asioObject->createBuffers (bufferInfos,
  188476. totalBuffers,
  188477. currentBlockSizeSamples,
  188478. &callbacks);
  188479. if (err != 0)
  188480. {
  188481. currentBlockSizeSamples = preferredSize;
  188482. logError ("create buffers 2", err);
  188483. asioObject->disposeBuffers();
  188484. err = asioObject->createBuffers (bufferInfos,
  188485. totalBuffers,
  188486. currentBlockSizeSamples,
  188487. &callbacks);
  188488. }
  188489. if (err == 0)
  188490. {
  188491. buffersCreated = true;
  188492. tempBuffer.calloc (totalBuffers * currentBlockSizeSamples + 32);
  188493. int n = 0;
  188494. Array <int> types;
  188495. currentBitDepth = 16;
  188496. for (i = 0; i < jmin ((int) totalNumInputChans, maxASIOChannels); ++i)
  188497. {
  188498. if (inputChannels[i])
  188499. {
  188500. inBuffers[n] = tempBuffer + (currentBlockSizeSamples * n);
  188501. ASIOChannelInfo channelInfo;
  188502. zerostruct (channelInfo);
  188503. channelInfo.channel = i;
  188504. channelInfo.isInput = 1;
  188505. asioObject->getChannelInfo (&channelInfo);
  188506. types.addIfNotAlreadyThere (channelInfo.type);
  188507. typeToFormatParameters (channelInfo.type,
  188508. inputChannelBitDepths[n],
  188509. inputChannelBytesPerSample[n],
  188510. inputChannelIsFloat[n],
  188511. inputChannelLittleEndian[n]);
  188512. currentBitDepth = jmax (currentBitDepth, inputChannelBitDepths[n]);
  188513. ++n;
  188514. }
  188515. }
  188516. jassert (numActiveInputChans == n);
  188517. n = 0;
  188518. for (i = 0; i < jmin ((int) totalNumOutputChans, maxASIOChannels); ++i)
  188519. {
  188520. if (outputChannels[i])
  188521. {
  188522. outBuffers[n] = tempBuffer + (currentBlockSizeSamples * (numActiveInputChans + n));
  188523. ASIOChannelInfo channelInfo;
  188524. zerostruct (channelInfo);
  188525. channelInfo.channel = i;
  188526. channelInfo.isInput = 0;
  188527. asioObject->getChannelInfo (&channelInfo);
  188528. types.addIfNotAlreadyThere (channelInfo.type);
  188529. typeToFormatParameters (channelInfo.type,
  188530. outputChannelBitDepths[n],
  188531. outputChannelBytesPerSample[n],
  188532. outputChannelIsFloat[n],
  188533. outputChannelLittleEndian[n]);
  188534. currentBitDepth = jmax (currentBitDepth, outputChannelBitDepths[n]);
  188535. ++n;
  188536. }
  188537. }
  188538. jassert (numActiveOutputChans == n);
  188539. for (i = types.size(); --i >= 0;)
  188540. {
  188541. log (T("channel format: ") + String (types[i]));
  188542. }
  188543. jassert (n <= totalBuffers);
  188544. for (i = 0; i < numActiveOutputChans; ++i)
  188545. {
  188546. const int size = currentBlockSizeSamples * (outputChannelBitDepths[i] >> 3);
  188547. if (bufferInfos [numActiveInputChans + i].buffers[0] == 0
  188548. || bufferInfos [numActiveInputChans + i].buffers[1] == 0)
  188549. {
  188550. log ("!! Null buffers");
  188551. }
  188552. else
  188553. {
  188554. zeromem (bufferInfos[numActiveInputChans + i].buffers[0], size);
  188555. zeromem (bufferInfos[numActiveInputChans + i].buffers[1], size);
  188556. }
  188557. }
  188558. inputLatency = outputLatency = 0;
  188559. if (asioObject->getLatencies (&inputLatency, &outputLatency) != 0)
  188560. {
  188561. log ("ASIO - no latencies");
  188562. }
  188563. else
  188564. {
  188565. log (T("ASIO latencies: ")
  188566. + String ((int) outputLatency)
  188567. + T(", ")
  188568. + String ((int) inputLatency));
  188569. }
  188570. isOpen_ = true;
  188571. log ("starting ASIO");
  188572. calledback = false;
  188573. err = asioObject->start();
  188574. if (err != 0)
  188575. {
  188576. isOpen_ = false;
  188577. log ("ASIO - stop on failure");
  188578. Thread::sleep (10);
  188579. asioObject->stop();
  188580. error = "Can't start device";
  188581. Thread::sleep (10);
  188582. }
  188583. else
  188584. {
  188585. int count = 300;
  188586. while (--count > 0 && ! calledback)
  188587. Thread::sleep (10);
  188588. isStarted = true;
  188589. if (! calledback)
  188590. {
  188591. error = "Device didn't start correctly";
  188592. log ("ASIO didn't callback - stopping..");
  188593. asioObject->stop();
  188594. }
  188595. }
  188596. }
  188597. else
  188598. {
  188599. error = "Can't create i/o buffers";
  188600. }
  188601. }
  188602. else
  188603. {
  188604. error = "Can't set sample rate: ";
  188605. error << sampleRate;
  188606. }
  188607. if (error.isNotEmpty())
  188608. {
  188609. logError (error, err);
  188610. if (asioObject != 0 && buffersCreated)
  188611. asioObject->disposeBuffers();
  188612. Thread::sleep (20);
  188613. isStarted = false;
  188614. isOpen_ = false;
  188615. close();
  188616. }
  188617. needToReset = false;
  188618. isReSync = false;
  188619. return error;
  188620. }
  188621. void close()
  188622. {
  188623. error = String::empty;
  188624. stopTimer();
  188625. stop();
  188626. if (isASIOOpen && isOpen_)
  188627. {
  188628. const ScopedLock sl (callbackLock);
  188629. isOpen_ = false;
  188630. isStarted = false;
  188631. needToReset = false;
  188632. isReSync = false;
  188633. log ("ASIO - stopping");
  188634. if (asioObject != 0)
  188635. {
  188636. Thread::sleep (20);
  188637. asioObject->stop();
  188638. Thread::sleep (10);
  188639. asioObject->disposeBuffers();
  188640. }
  188641. Thread::sleep (10);
  188642. }
  188643. }
  188644. bool isOpen()
  188645. {
  188646. return isOpen_ || insideControlPanelModalLoop;
  188647. }
  188648. int getCurrentBufferSizeSamples()
  188649. {
  188650. return currentBlockSizeSamples;
  188651. }
  188652. double getCurrentSampleRate()
  188653. {
  188654. return currentSampleRate;
  188655. }
  188656. const BigInteger getActiveOutputChannels() const
  188657. {
  188658. return currentChansOut;
  188659. }
  188660. const BigInteger getActiveInputChannels() const
  188661. {
  188662. return currentChansIn;
  188663. }
  188664. int getCurrentBitDepth()
  188665. {
  188666. return currentBitDepth;
  188667. }
  188668. int getOutputLatencyInSamples()
  188669. {
  188670. return outputLatency + currentBlockSizeSamples / 4;
  188671. }
  188672. int getInputLatencyInSamples()
  188673. {
  188674. return inputLatency + currentBlockSizeSamples / 4;
  188675. }
  188676. void start (AudioIODeviceCallback* callback)
  188677. {
  188678. if (callback != 0)
  188679. {
  188680. callback->audioDeviceAboutToStart (this);
  188681. const ScopedLock sl (callbackLock);
  188682. currentCallback = callback;
  188683. }
  188684. }
  188685. void stop()
  188686. {
  188687. AudioIODeviceCallback* const lastCallback = currentCallback;
  188688. {
  188689. const ScopedLock sl (callbackLock);
  188690. currentCallback = 0;
  188691. }
  188692. if (lastCallback != 0)
  188693. lastCallback->audioDeviceStopped();
  188694. }
  188695. bool isPlaying()
  188696. {
  188697. return isASIOOpen && (currentCallback != 0);
  188698. }
  188699. const String getLastError()
  188700. {
  188701. return error;
  188702. }
  188703. bool hasControlPanel() const
  188704. {
  188705. return true;
  188706. }
  188707. bool showControlPanel()
  188708. {
  188709. log ("ASIO - showing control panel");
  188710. Component modalWindow (String::empty);
  188711. modalWindow.setOpaque (true);
  188712. modalWindow.addToDesktop (0);
  188713. modalWindow.enterModalState();
  188714. bool done = false;
  188715. JUCE_TRY
  188716. {
  188717. // are there are devices that need to be closed before showing their control panel?
  188718. // close();
  188719. insideControlPanelModalLoop = true;
  188720. const uint32 started = Time::getMillisecondCounter();
  188721. if (asioObject != 0)
  188722. {
  188723. asioObject->controlPanel();
  188724. const int spent = (int) Time::getMillisecondCounter() - (int) started;
  188725. log (T("spent: ") + String (spent));
  188726. if (spent > 300)
  188727. {
  188728. shouldUsePreferredSize = true;
  188729. done = true;
  188730. }
  188731. }
  188732. }
  188733. JUCE_CATCH_ALL
  188734. insideControlPanelModalLoop = false;
  188735. return done;
  188736. }
  188737. void resetRequest() throw()
  188738. {
  188739. needToReset = true;
  188740. }
  188741. void resyncRequest() throw()
  188742. {
  188743. needToReset = true;
  188744. isReSync = true;
  188745. }
  188746. void timerCallback()
  188747. {
  188748. if (! insideControlPanelModalLoop)
  188749. {
  188750. stopTimer();
  188751. // used to cause a reset
  188752. log ("! ASIO restart request!");
  188753. if (isOpen_)
  188754. {
  188755. AudioIODeviceCallback* const oldCallback = currentCallback;
  188756. close();
  188757. open (BigInteger (currentChansIn), BigInteger (currentChansOut),
  188758. currentSampleRate, currentBlockSizeSamples);
  188759. if (oldCallback != 0)
  188760. start (oldCallback);
  188761. }
  188762. }
  188763. else
  188764. {
  188765. startTimer (100);
  188766. }
  188767. }
  188768. juce_UseDebuggingNewOperator
  188769. private:
  188770. IASIO* volatile asioObject;
  188771. ASIOCallbacks callbacks;
  188772. void* windowHandle;
  188773. CLSID classId;
  188774. const String optionalDllForDirectLoading;
  188775. String error;
  188776. long totalNumInputChans, totalNumOutputChans;
  188777. StringArray inputChannelNames, outputChannelNames;
  188778. Array<int> sampleRates, bufferSizes;
  188779. long inputLatency, outputLatency;
  188780. long minSize, maxSize, preferredSize, granularity;
  188781. int volatile currentBlockSizeSamples;
  188782. int volatile currentBitDepth;
  188783. double volatile currentSampleRate;
  188784. BigInteger currentChansOut, currentChansIn;
  188785. AudioIODeviceCallback* volatile currentCallback;
  188786. CriticalSection callbackLock;
  188787. ASIOBufferInfo bufferInfos [maxASIOChannels];
  188788. float* inBuffers [maxASIOChannels];
  188789. float* outBuffers [maxASIOChannels];
  188790. int inputChannelBitDepths [maxASIOChannels];
  188791. int outputChannelBitDepths [maxASIOChannels];
  188792. int inputChannelBytesPerSample [maxASIOChannels];
  188793. int outputChannelBytesPerSample [maxASIOChannels];
  188794. bool inputChannelIsFloat [maxASIOChannels];
  188795. bool outputChannelIsFloat [maxASIOChannels];
  188796. bool inputChannelLittleEndian [maxASIOChannels];
  188797. bool outputChannelLittleEndian [maxASIOChannels];
  188798. WaitableEvent event1;
  188799. HeapBlock <float> tempBuffer;
  188800. int volatile bufferIndex, numActiveInputChans, numActiveOutputChans;
  188801. bool isOpen_, isStarted;
  188802. bool volatile isASIOOpen;
  188803. bool volatile calledback;
  188804. bool volatile littleEndian, postOutput, needToReset, isReSync;
  188805. bool volatile insideControlPanelModalLoop;
  188806. bool volatile shouldUsePreferredSize;
  188807. void removeCurrentDriver()
  188808. {
  188809. if (asioObject != 0)
  188810. {
  188811. asioObject->Release();
  188812. asioObject = 0;
  188813. }
  188814. }
  188815. bool loadDriver()
  188816. {
  188817. removeCurrentDriver();
  188818. JUCE_TRY
  188819. {
  188820. if (CoCreateInstance (classId, 0, CLSCTX_INPROC_SERVER,
  188821. classId, (void**) &asioObject) == S_OK)
  188822. {
  188823. return true;
  188824. }
  188825. // If a class isn't registered but we have a path for it, we can fallback to
  188826. // doing a direct load of the COM object (only available via the juce_createASIOAudioIODeviceForGUID function).
  188827. if (optionalDllForDirectLoading.isNotEmpty())
  188828. {
  188829. HMODULE h = LoadLibrary (optionalDllForDirectLoading);
  188830. if (h != 0)
  188831. {
  188832. typedef HRESULT (CALLBACK* DllGetClassObjectFunc) (REFCLSID clsid, REFIID iid, LPVOID* ppv);
  188833. DllGetClassObjectFunc dllGetClassObject = (DllGetClassObjectFunc) GetProcAddress (h, "DllGetClassObject");
  188834. if (dllGetClassObject != 0)
  188835. {
  188836. IClassFactory* classFactory = 0;
  188837. HRESULT hr = dllGetClassObject (classId, IID_IClassFactory, (void**) &classFactory);
  188838. if (classFactory != 0)
  188839. {
  188840. hr = classFactory->CreateInstance (0, classId, (void**) &asioObject);
  188841. classFactory->Release();
  188842. }
  188843. return asioObject != 0;
  188844. }
  188845. }
  188846. }
  188847. }
  188848. JUCE_CATCH_ALL
  188849. asioObject = 0;
  188850. return false;
  188851. }
  188852. const String initDriver()
  188853. {
  188854. if (asioObject != 0)
  188855. {
  188856. char buffer [256];
  188857. zeromem (buffer, sizeof (buffer));
  188858. if (! asioObject->init (windowHandle))
  188859. {
  188860. asioObject->getErrorMessage (buffer);
  188861. return String (buffer, sizeof (buffer) - 1);
  188862. }
  188863. // just in case any daft drivers expect this to be called..
  188864. asioObject->getDriverName (buffer);
  188865. return String::empty;
  188866. }
  188867. return "No Driver";
  188868. }
  188869. const String openDevice()
  188870. {
  188871. // use this in case the driver starts opening dialog boxes..
  188872. Component modalWindow (String::empty);
  188873. modalWindow.setOpaque (true);
  188874. modalWindow.addToDesktop (0);
  188875. modalWindow.enterModalState();
  188876. // open the device and get its info..
  188877. log (T("opening ASIO device: ") + getName());
  188878. needToReset = false;
  188879. isReSync = false;
  188880. outputChannelNames.clear();
  188881. inputChannelNames.clear();
  188882. bufferSizes.clear();
  188883. sampleRates.clear();
  188884. isASIOOpen = false;
  188885. isOpen_ = false;
  188886. totalNumInputChans = 0;
  188887. totalNumOutputChans = 0;
  188888. numActiveInputChans = 0;
  188889. numActiveOutputChans = 0;
  188890. currentCallback = 0;
  188891. error = String::empty;
  188892. if (getName().isEmpty())
  188893. return error;
  188894. long err = 0;
  188895. if (loadDriver())
  188896. {
  188897. if ((error = initDriver()).isEmpty())
  188898. {
  188899. numActiveInputChans = 0;
  188900. numActiveOutputChans = 0;
  188901. totalNumInputChans = 0;
  188902. totalNumOutputChans = 0;
  188903. if (asioObject != 0
  188904. && (err = asioObject->getChannels (&totalNumInputChans, &totalNumOutputChans)) == 0)
  188905. {
  188906. log (String ((int) totalNumInputChans) + T(" in, ") + String ((int) totalNumOutputChans) + T(" out"));
  188907. if ((err = asioObject->getBufferSize (&minSize, &maxSize, &preferredSize, &granularity)) == 0)
  188908. {
  188909. // find a list of buffer sizes..
  188910. log (String ((int) minSize) + T(" ") + String ((int) maxSize) + T(" ") + String ((int)preferredSize) + T(" ") + String ((int)granularity));
  188911. if (granularity >= 0)
  188912. {
  188913. granularity = jmax (1, (int) granularity);
  188914. for (int i = jmax ((int) minSize, (int) granularity); i < jmin (6400, (int) maxSize); i += granularity)
  188915. bufferSizes.addIfNotAlreadyThere (granularity * (i / granularity));
  188916. }
  188917. else if (granularity < 0)
  188918. {
  188919. for (int i = 0; i < 18; ++i)
  188920. {
  188921. const int s = (1 << i);
  188922. if (s >= minSize && s <= maxSize)
  188923. bufferSizes.add (s);
  188924. }
  188925. }
  188926. if (! bufferSizes.contains (preferredSize))
  188927. bufferSizes.insert (0, preferredSize);
  188928. double currentRate = 0;
  188929. asioObject->getSampleRate (&currentRate);
  188930. if (currentRate <= 0.0 || currentRate > 192001.0)
  188931. {
  188932. log ("setting sample rate");
  188933. err = asioObject->setSampleRate (44100.0);
  188934. if (err != 0)
  188935. {
  188936. logError ("setting sample rate", err);
  188937. }
  188938. asioObject->getSampleRate (&currentRate);
  188939. }
  188940. currentSampleRate = currentRate;
  188941. postOutput = (asioObject->outputReady() == 0);
  188942. if (postOutput)
  188943. {
  188944. log ("ASIO outputReady = ok");
  188945. }
  188946. updateSampleRates();
  188947. // ..because cubase does it at this point
  188948. inputLatency = outputLatency = 0;
  188949. if (asioObject->getLatencies (&inputLatency, &outputLatency) != 0)
  188950. {
  188951. log ("ASIO - no latencies");
  188952. }
  188953. log (String ("latencies: ")
  188954. + String ((int) inputLatency)
  188955. + T(", ") + String ((int) outputLatency));
  188956. // create some dummy buffers now.. because cubase does..
  188957. numActiveInputChans = 0;
  188958. numActiveOutputChans = 0;
  188959. ASIOBufferInfo* info = bufferInfos;
  188960. int i, numChans = 0;
  188961. for (i = 0; i < jmin (2, (int) totalNumInputChans); ++i)
  188962. {
  188963. info->isInput = 1;
  188964. info->channelNum = i;
  188965. info->buffers[0] = info->buffers[1] = 0;
  188966. ++info;
  188967. ++numChans;
  188968. }
  188969. const int outputBufferIndex = numChans;
  188970. for (i = 0; i < jmin (2, (int) totalNumOutputChans); ++i)
  188971. {
  188972. info->isInput = 0;
  188973. info->channelNum = i;
  188974. info->buffers[0] = info->buffers[1] = 0;
  188975. ++info;
  188976. ++numChans;
  188977. }
  188978. callbacks.sampleRateDidChange = &sampleRateChangedCallback;
  188979. if (currentASIODev[0] == this)
  188980. {
  188981. callbacks.bufferSwitch = &bufferSwitchCallback0;
  188982. callbacks.asioMessage = &asioMessagesCallback0;
  188983. callbacks.bufferSwitchTimeInfo = &bufferSwitchTimeInfoCallback0;
  188984. }
  188985. else if (currentASIODev[1] == this)
  188986. {
  188987. callbacks.bufferSwitch = &bufferSwitchCallback1;
  188988. callbacks.asioMessage = &asioMessagesCallback1;
  188989. callbacks.bufferSwitchTimeInfo = &bufferSwitchTimeInfoCallback1;
  188990. }
  188991. else if (currentASIODev[2] == this)
  188992. {
  188993. callbacks.bufferSwitch = &bufferSwitchCallback2;
  188994. callbacks.asioMessage = &asioMessagesCallback2;
  188995. callbacks.bufferSwitchTimeInfo = &bufferSwitchTimeInfoCallback2;
  188996. }
  188997. else
  188998. {
  188999. jassertfalse
  189000. }
  189001. log (T("creating buffers (dummy): ") + String (numChans)
  189002. + T(", ") + String ((int) preferredSize));
  189003. if (preferredSize > 0)
  189004. {
  189005. err = asioObject->createBuffers (bufferInfos, numChans, preferredSize, &callbacks);
  189006. if (err != 0)
  189007. {
  189008. logError ("dummy buffers", err);
  189009. }
  189010. }
  189011. long newInps = 0, newOuts = 0;
  189012. asioObject->getChannels (&newInps, &newOuts);
  189013. if (totalNumInputChans != newInps || totalNumOutputChans != newOuts)
  189014. {
  189015. totalNumInputChans = newInps;
  189016. totalNumOutputChans = newOuts;
  189017. log (String ((int) totalNumInputChans) + T(" in; ")
  189018. + String ((int) totalNumOutputChans) + T(" out"));
  189019. }
  189020. updateSampleRates();
  189021. ASIOChannelInfo channelInfo;
  189022. channelInfo.type = 0;
  189023. for (i = 0; i < totalNumInputChans; ++i)
  189024. {
  189025. zerostruct (channelInfo);
  189026. channelInfo.channel = i;
  189027. channelInfo.isInput = 1;
  189028. asioObject->getChannelInfo (&channelInfo);
  189029. inputChannelNames.add (String (channelInfo.name));
  189030. }
  189031. for (i = 0; i < totalNumOutputChans; ++i)
  189032. {
  189033. zerostruct (channelInfo);
  189034. channelInfo.channel = i;
  189035. channelInfo.isInput = 0;
  189036. asioObject->getChannelInfo (&channelInfo);
  189037. outputChannelNames.add (String (channelInfo.name));
  189038. typeToFormatParameters (channelInfo.type,
  189039. outputChannelBitDepths[i],
  189040. outputChannelBytesPerSample[i],
  189041. outputChannelIsFloat[i],
  189042. outputChannelLittleEndian[i]);
  189043. if (i < 2)
  189044. {
  189045. // clear the channels that are used with the dummy stuff
  189046. const int bytesPerBuffer = preferredSize * (outputChannelBitDepths[i] >> 3);
  189047. zeromem (bufferInfos [outputBufferIndex + i].buffers[0], bytesPerBuffer);
  189048. zeromem (bufferInfos [outputBufferIndex + i].buffers[1], bytesPerBuffer);
  189049. }
  189050. }
  189051. outputChannelNames.trim();
  189052. inputChannelNames.trim();
  189053. outputChannelNames.appendNumbersToDuplicates (false, true);
  189054. inputChannelNames.appendNumbersToDuplicates (false, true);
  189055. // start and stop because cubase does it..
  189056. asioObject->getLatencies (&inputLatency, &outputLatency);
  189057. if ((err = asioObject->start()) != 0)
  189058. {
  189059. // ignore an error here, as it might start later after setting other stuff up
  189060. logError ("ASIO start", err);
  189061. }
  189062. Thread::sleep (100);
  189063. asioObject->stop();
  189064. }
  189065. else
  189066. {
  189067. error = "Can't detect buffer sizes";
  189068. }
  189069. }
  189070. else
  189071. {
  189072. error = "Can't detect asio channels";
  189073. }
  189074. }
  189075. }
  189076. else
  189077. {
  189078. error = "No such device";
  189079. }
  189080. if (error.isNotEmpty())
  189081. {
  189082. logError (error, err);
  189083. if (asioObject != 0)
  189084. asioObject->disposeBuffers();
  189085. removeCurrentDriver();
  189086. isASIOOpen = false;
  189087. }
  189088. else
  189089. {
  189090. isASIOOpen = true;
  189091. log ("ASIO device open");
  189092. }
  189093. isOpen_ = false;
  189094. needToReset = false;
  189095. isReSync = false;
  189096. return error;
  189097. }
  189098. void callback (const long index) throw()
  189099. {
  189100. if (isStarted)
  189101. {
  189102. bufferIndex = index;
  189103. processBuffer();
  189104. }
  189105. else
  189106. {
  189107. if (postOutput && (asioObject != 0))
  189108. asioObject->outputReady();
  189109. }
  189110. calledback = true;
  189111. }
  189112. void processBuffer() throw()
  189113. {
  189114. const ASIOBufferInfo* const infos = bufferInfos;
  189115. const int bi = bufferIndex;
  189116. const ScopedLock sl (callbackLock);
  189117. if (needToReset)
  189118. {
  189119. needToReset = false;
  189120. if (isReSync)
  189121. {
  189122. log ("! ASIO resync");
  189123. isReSync = false;
  189124. }
  189125. else
  189126. {
  189127. startTimer (20);
  189128. }
  189129. }
  189130. if (bi >= 0)
  189131. {
  189132. const int samps = currentBlockSizeSamples;
  189133. if (currentCallback != 0)
  189134. {
  189135. int i;
  189136. for (i = 0; i < numActiveInputChans; ++i)
  189137. {
  189138. float* const dst = inBuffers[i];
  189139. jassert (dst != 0);
  189140. const char* const src = (const char*) (infos[i].buffers[bi]);
  189141. if (inputChannelIsFloat[i])
  189142. {
  189143. memcpy (dst, src, samps * sizeof (float));
  189144. }
  189145. else
  189146. {
  189147. jassert (dst == tempBuffer + (samps * i));
  189148. switch (inputChannelBitDepths[i])
  189149. {
  189150. case 16:
  189151. convertInt16ToFloat (src, dst, inputChannelBytesPerSample[i],
  189152. samps, inputChannelLittleEndian[i]);
  189153. break;
  189154. case 24:
  189155. convertInt24ToFloat (src, dst, inputChannelBytesPerSample[i],
  189156. samps, inputChannelLittleEndian[i]);
  189157. break;
  189158. case 32:
  189159. convertInt32ToFloat (src, dst, inputChannelBytesPerSample[i],
  189160. samps, inputChannelLittleEndian[i]);
  189161. break;
  189162. case 64:
  189163. jassertfalse
  189164. break;
  189165. }
  189166. }
  189167. }
  189168. currentCallback->audioDeviceIOCallback ((const float**) inBuffers,
  189169. numActiveInputChans,
  189170. outBuffers,
  189171. numActiveOutputChans,
  189172. samps);
  189173. for (i = 0; i < numActiveOutputChans; ++i)
  189174. {
  189175. float* const src = outBuffers[i];
  189176. jassert (src != 0);
  189177. char* const dst = (char*) (infos [numActiveInputChans + i].buffers[bi]);
  189178. if (outputChannelIsFloat[i])
  189179. {
  189180. memcpy (dst, src, samps * sizeof (float));
  189181. }
  189182. else
  189183. {
  189184. jassert (src == tempBuffer + (samps * (numActiveInputChans + i)));
  189185. switch (outputChannelBitDepths[i])
  189186. {
  189187. case 16:
  189188. convertFloatToInt16 (src, dst, outputChannelBytesPerSample[i],
  189189. samps, outputChannelLittleEndian[i]);
  189190. break;
  189191. case 24:
  189192. convertFloatToInt24 (src, dst, outputChannelBytesPerSample[i],
  189193. samps, outputChannelLittleEndian[i]);
  189194. break;
  189195. case 32:
  189196. convertFloatToInt32 (src, dst, outputChannelBytesPerSample[i],
  189197. samps, outputChannelLittleEndian[i]);
  189198. break;
  189199. case 64:
  189200. jassertfalse
  189201. break;
  189202. }
  189203. }
  189204. }
  189205. }
  189206. else
  189207. {
  189208. for (int i = 0; i < numActiveOutputChans; ++i)
  189209. {
  189210. const int bytesPerBuffer = samps * (outputChannelBitDepths[i] >> 3);
  189211. zeromem (infos[numActiveInputChans + i].buffers[bi], bytesPerBuffer);
  189212. }
  189213. }
  189214. }
  189215. if (postOutput)
  189216. asioObject->outputReady();
  189217. }
  189218. static ASIOTime* bufferSwitchTimeInfoCallback0 (ASIOTime*, long index, long) throw()
  189219. {
  189220. if (currentASIODev[0] != 0)
  189221. currentASIODev[0]->callback (index);
  189222. return 0;
  189223. }
  189224. static ASIOTime* bufferSwitchTimeInfoCallback1 (ASIOTime*, long index, long) throw()
  189225. {
  189226. if (currentASIODev[1] != 0)
  189227. currentASIODev[1]->callback (index);
  189228. return 0;
  189229. }
  189230. static ASIOTime* bufferSwitchTimeInfoCallback2 (ASIOTime*, long index, long) throw()
  189231. {
  189232. if (currentASIODev[2] != 0)
  189233. currentASIODev[2]->callback (index);
  189234. return 0;
  189235. }
  189236. static void bufferSwitchCallback0 (long index, long) throw()
  189237. {
  189238. if (currentASIODev[0] != 0)
  189239. currentASIODev[0]->callback (index);
  189240. }
  189241. static void bufferSwitchCallback1 (long index, long) throw()
  189242. {
  189243. if (currentASIODev[1] != 0)
  189244. currentASIODev[1]->callback (index);
  189245. }
  189246. static void bufferSwitchCallback2 (long index, long) throw()
  189247. {
  189248. if (currentASIODev[2] != 0)
  189249. currentASIODev[2]->callback (index);
  189250. }
  189251. static long asioMessagesCallback0 (long selector, long value, void*, double*) throw()
  189252. {
  189253. return asioMessagesCallback (selector, value, 0);
  189254. }
  189255. static long asioMessagesCallback1 (long selector, long value, void*, double*) throw()
  189256. {
  189257. return asioMessagesCallback (selector, value, 1);
  189258. }
  189259. static long asioMessagesCallback2 (long selector, long value, void*, double*) throw()
  189260. {
  189261. return asioMessagesCallback (selector, value, 2);
  189262. }
  189263. static long asioMessagesCallback (long selector, long value, const int deviceIndex) throw()
  189264. {
  189265. switch (selector)
  189266. {
  189267. case kAsioSelectorSupported:
  189268. if (value == kAsioResetRequest
  189269. || value == kAsioEngineVersion
  189270. || value == kAsioResyncRequest
  189271. || value == kAsioLatenciesChanged
  189272. || value == kAsioSupportsInputMonitor)
  189273. return 1;
  189274. break;
  189275. case kAsioBufferSizeChange:
  189276. break;
  189277. case kAsioResetRequest:
  189278. if (currentASIODev[deviceIndex] != 0)
  189279. currentASIODev[deviceIndex]->resetRequest();
  189280. return 1;
  189281. case kAsioResyncRequest:
  189282. if (currentASIODev[deviceIndex] != 0)
  189283. currentASIODev[deviceIndex]->resyncRequest();
  189284. return 1;
  189285. case kAsioLatenciesChanged:
  189286. return 1;
  189287. case kAsioEngineVersion:
  189288. return 2;
  189289. case kAsioSupportsTimeInfo:
  189290. case kAsioSupportsTimeCode:
  189291. return 0;
  189292. }
  189293. return 0;
  189294. }
  189295. static void sampleRateChangedCallback (ASIOSampleRate) throw()
  189296. {
  189297. }
  189298. static void convertInt16ToFloat (const char* src,
  189299. float* dest,
  189300. const int srcStrideBytes,
  189301. int numSamples,
  189302. const bool littleEndian) throw()
  189303. {
  189304. const double g = 1.0 / 32768.0;
  189305. if (littleEndian)
  189306. {
  189307. while (--numSamples >= 0)
  189308. {
  189309. *dest++ = (float) (g * (short) ByteOrder::littleEndianShort (src));
  189310. src += srcStrideBytes;
  189311. }
  189312. }
  189313. else
  189314. {
  189315. while (--numSamples >= 0)
  189316. {
  189317. *dest++ = (float) (g * (short) ByteOrder::bigEndianShort (src));
  189318. src += srcStrideBytes;
  189319. }
  189320. }
  189321. }
  189322. static void convertFloatToInt16 (const float* src,
  189323. char* dest,
  189324. const int dstStrideBytes,
  189325. int numSamples,
  189326. const bool littleEndian) throw()
  189327. {
  189328. const double maxVal = (double) 0x7fff;
  189329. if (littleEndian)
  189330. {
  189331. while (--numSamples >= 0)
  189332. {
  189333. *(uint16*) dest = ByteOrder::swapIfBigEndian ((uint16) (short) roundDoubleToInt (jlimit (-maxVal, maxVal, maxVal * *src++)));
  189334. dest += dstStrideBytes;
  189335. }
  189336. }
  189337. else
  189338. {
  189339. while (--numSamples >= 0)
  189340. {
  189341. *(uint16*) dest = ByteOrder::swapIfLittleEndian ((uint16) (short) roundDoubleToInt (jlimit (-maxVal, maxVal, maxVal * *src++)));
  189342. dest += dstStrideBytes;
  189343. }
  189344. }
  189345. }
  189346. static void convertInt24ToFloat (const char* src,
  189347. float* dest,
  189348. const int srcStrideBytes,
  189349. int numSamples,
  189350. const bool littleEndian) throw()
  189351. {
  189352. const double g = 1.0 / 0x7fffff;
  189353. if (littleEndian)
  189354. {
  189355. while (--numSamples >= 0)
  189356. {
  189357. *dest++ = (float) (g * ByteOrder::littleEndian24Bit (src));
  189358. src += srcStrideBytes;
  189359. }
  189360. }
  189361. else
  189362. {
  189363. while (--numSamples >= 0)
  189364. {
  189365. *dest++ = (float) (g * ByteOrder::bigEndian24Bit (src));
  189366. src += srcStrideBytes;
  189367. }
  189368. }
  189369. }
  189370. static void convertFloatToInt24 (const float* src,
  189371. char* dest,
  189372. const int dstStrideBytes,
  189373. int numSamples,
  189374. const bool littleEndian) throw()
  189375. {
  189376. const double maxVal = (double) 0x7fffff;
  189377. if (littleEndian)
  189378. {
  189379. while (--numSamples >= 0)
  189380. {
  189381. ByteOrder::littleEndian24BitToChars ((uint32) roundDoubleToInt (jlimit (-maxVal, maxVal, maxVal * *src++)), dest);
  189382. dest += dstStrideBytes;
  189383. }
  189384. }
  189385. else
  189386. {
  189387. while (--numSamples >= 0)
  189388. {
  189389. ByteOrder::bigEndian24BitToChars ((uint32) roundDoubleToInt (jlimit (-maxVal, maxVal, maxVal * *src++)), dest);
  189390. dest += dstStrideBytes;
  189391. }
  189392. }
  189393. }
  189394. static void convertInt32ToFloat (const char* src,
  189395. float* dest,
  189396. const int srcStrideBytes,
  189397. int numSamples,
  189398. const bool littleEndian) throw()
  189399. {
  189400. const double g = 1.0 / 0x7fffffff;
  189401. if (littleEndian)
  189402. {
  189403. while (--numSamples >= 0)
  189404. {
  189405. *dest++ = (float) (g * (int) ByteOrder::littleEndianInt (src));
  189406. src += srcStrideBytes;
  189407. }
  189408. }
  189409. else
  189410. {
  189411. while (--numSamples >= 0)
  189412. {
  189413. *dest++ = (float) (g * (int) ByteOrder::bigEndianInt (src));
  189414. src += srcStrideBytes;
  189415. }
  189416. }
  189417. }
  189418. static void convertFloatToInt32 (const float* src,
  189419. char* dest,
  189420. const int dstStrideBytes,
  189421. int numSamples,
  189422. const bool littleEndian) throw()
  189423. {
  189424. const double maxVal = (double) 0x7fffffff;
  189425. if (littleEndian)
  189426. {
  189427. while (--numSamples >= 0)
  189428. {
  189429. *(uint32*) dest = ByteOrder::swapIfBigEndian ((uint32) roundDoubleToInt (jlimit (-maxVal, maxVal, maxVal * *src++)));
  189430. dest += dstStrideBytes;
  189431. }
  189432. }
  189433. else
  189434. {
  189435. while (--numSamples >= 0)
  189436. {
  189437. *(uint32*) dest = ByteOrder::swapIfLittleEndian ((uint32) roundDoubleToInt (jlimit (-maxVal, maxVal, maxVal * *src++)));
  189438. dest += dstStrideBytes;
  189439. }
  189440. }
  189441. }
  189442. static void typeToFormatParameters (const long type,
  189443. int& bitDepth,
  189444. int& byteStride,
  189445. bool& formatIsFloat,
  189446. bool& littleEndian) throw()
  189447. {
  189448. bitDepth = 0;
  189449. littleEndian = false;
  189450. formatIsFloat = false;
  189451. switch (type)
  189452. {
  189453. case ASIOSTInt16MSB:
  189454. case ASIOSTInt16LSB:
  189455. case ASIOSTInt32MSB16:
  189456. case ASIOSTInt32LSB16:
  189457. bitDepth = 16; break;
  189458. case ASIOSTFloat32MSB:
  189459. case ASIOSTFloat32LSB:
  189460. formatIsFloat = true;
  189461. bitDepth = 32; break;
  189462. case ASIOSTInt32MSB:
  189463. case ASIOSTInt32LSB:
  189464. bitDepth = 32; break;
  189465. case ASIOSTInt24MSB:
  189466. case ASIOSTInt24LSB:
  189467. case ASIOSTInt32MSB24:
  189468. case ASIOSTInt32LSB24:
  189469. case ASIOSTInt32MSB18:
  189470. case ASIOSTInt32MSB20:
  189471. case ASIOSTInt32LSB18:
  189472. case ASIOSTInt32LSB20:
  189473. bitDepth = 24; break;
  189474. case ASIOSTFloat64MSB:
  189475. case ASIOSTFloat64LSB:
  189476. default:
  189477. bitDepth = 64;
  189478. break;
  189479. }
  189480. switch (type)
  189481. {
  189482. case ASIOSTInt16MSB:
  189483. case ASIOSTInt32MSB16:
  189484. case ASIOSTFloat32MSB:
  189485. case ASIOSTFloat64MSB:
  189486. case ASIOSTInt32MSB:
  189487. case ASIOSTInt32MSB18:
  189488. case ASIOSTInt32MSB20:
  189489. case ASIOSTInt32MSB24:
  189490. case ASIOSTInt24MSB:
  189491. littleEndian = false; break;
  189492. case ASIOSTInt16LSB:
  189493. case ASIOSTInt32LSB16:
  189494. case ASIOSTFloat32LSB:
  189495. case ASIOSTFloat64LSB:
  189496. case ASIOSTInt32LSB:
  189497. case ASIOSTInt32LSB18:
  189498. case ASIOSTInt32LSB20:
  189499. case ASIOSTInt32LSB24:
  189500. case ASIOSTInt24LSB:
  189501. littleEndian = true; break;
  189502. default:
  189503. break;
  189504. }
  189505. switch (type)
  189506. {
  189507. case ASIOSTInt16LSB:
  189508. case ASIOSTInt16MSB:
  189509. byteStride = 2; break;
  189510. case ASIOSTInt24LSB:
  189511. case ASIOSTInt24MSB:
  189512. byteStride = 3; break;
  189513. case ASIOSTInt32MSB16:
  189514. case ASIOSTInt32LSB16:
  189515. case ASIOSTInt32MSB:
  189516. case ASIOSTInt32MSB18:
  189517. case ASIOSTInt32MSB20:
  189518. case ASIOSTInt32MSB24:
  189519. case ASIOSTInt32LSB:
  189520. case ASIOSTInt32LSB18:
  189521. case ASIOSTInt32LSB20:
  189522. case ASIOSTInt32LSB24:
  189523. case ASIOSTFloat32LSB:
  189524. case ASIOSTFloat32MSB:
  189525. byteStride = 4; break;
  189526. case ASIOSTFloat64MSB:
  189527. case ASIOSTFloat64LSB:
  189528. byteStride = 8; break;
  189529. default:
  189530. break;
  189531. }
  189532. }
  189533. };
  189534. class ASIOAudioIODeviceType : public AudioIODeviceType
  189535. {
  189536. public:
  189537. ASIOAudioIODeviceType()
  189538. : AudioIODeviceType (T("ASIO")),
  189539. hasScanned (false)
  189540. {
  189541. CoInitialize (0);
  189542. }
  189543. ~ASIOAudioIODeviceType()
  189544. {
  189545. }
  189546. void scanForDevices()
  189547. {
  189548. hasScanned = true;
  189549. deviceNames.clear();
  189550. classIds.clear();
  189551. HKEY hk = 0;
  189552. int index = 0;
  189553. if (RegOpenKeyA (HKEY_LOCAL_MACHINE, "software\\asio", &hk) == ERROR_SUCCESS)
  189554. {
  189555. for (;;)
  189556. {
  189557. char name [256];
  189558. if (RegEnumKeyA (hk, index++, name, 256) == ERROR_SUCCESS)
  189559. {
  189560. addDriverInfo (name, hk);
  189561. }
  189562. else
  189563. {
  189564. break;
  189565. }
  189566. }
  189567. RegCloseKey (hk);
  189568. }
  189569. }
  189570. const StringArray getDeviceNames (const bool /*wantInputNames*/) const
  189571. {
  189572. jassert (hasScanned); // need to call scanForDevices() before doing this
  189573. return deviceNames;
  189574. }
  189575. int getDefaultDeviceIndex (const bool) const
  189576. {
  189577. jassert (hasScanned); // need to call scanForDevices() before doing this
  189578. for (int i = deviceNames.size(); --i >= 0;)
  189579. if (deviceNames[i].containsIgnoreCase (T("asio4all")))
  189580. return i; // asio4all is a safe choice for a default..
  189581. #if JUCE_DEBUG
  189582. if (deviceNames.size() > 1 && deviceNames[0].containsIgnoreCase (T("digidesign")))
  189583. return 1; // (the digi m-box driver crashes the app when you run
  189584. // it in the debugger, which can be a bit annoying)
  189585. #endif
  189586. return 0;
  189587. }
  189588. static int findFreeSlot()
  189589. {
  189590. for (int i = 0; i < numElementsInArray (currentASIODev); ++i)
  189591. if (currentASIODev[i] == 0)
  189592. return i;
  189593. jassertfalse; // unfortunately you can only have a finite number
  189594. // of ASIO devices open at the same time..
  189595. return -1;
  189596. }
  189597. int getIndexOfDevice (AudioIODevice* d, const bool /*asInput*/) const
  189598. {
  189599. jassert (hasScanned); // need to call scanForDevices() before doing this
  189600. return d == 0 ? -1 : deviceNames.indexOf (d->getName());
  189601. }
  189602. bool hasSeparateInputsAndOutputs() const { return false; }
  189603. AudioIODevice* createDevice (const String& outputDeviceName,
  189604. const String& inputDeviceName)
  189605. {
  189606. // ASIO can't open two different devices for input and output - they must be the same one.
  189607. jassert (inputDeviceName == outputDeviceName || outputDeviceName.isEmpty() || inputDeviceName.isEmpty());
  189608. jassert (hasScanned); // need to call scanForDevices() before doing this
  189609. const int index = deviceNames.indexOf (outputDeviceName.isNotEmpty() ? outputDeviceName
  189610. : inputDeviceName);
  189611. if (index >= 0)
  189612. {
  189613. const int freeSlot = findFreeSlot();
  189614. if (freeSlot >= 0)
  189615. return new ASIOAudioIODevice (outputDeviceName, *(classIds [index]), freeSlot, String::empty);
  189616. }
  189617. return 0;
  189618. }
  189619. juce_UseDebuggingNewOperator
  189620. private:
  189621. StringArray deviceNames;
  189622. OwnedArray <CLSID> classIds;
  189623. bool hasScanned;
  189624. static bool checkClassIsOk (const String& classId)
  189625. {
  189626. HKEY hk = 0;
  189627. bool ok = false;
  189628. if (RegOpenKey (HKEY_CLASSES_ROOT, _T("clsid"), &hk) == ERROR_SUCCESS)
  189629. {
  189630. int index = 0;
  189631. for (;;)
  189632. {
  189633. WCHAR buf [512];
  189634. if (RegEnumKey (hk, index++, buf, 512) == ERROR_SUCCESS)
  189635. {
  189636. if (classId.equalsIgnoreCase (buf))
  189637. {
  189638. HKEY subKey, pathKey;
  189639. if (RegOpenKeyEx (hk, buf, 0, KEY_READ, &subKey) == ERROR_SUCCESS)
  189640. {
  189641. if (RegOpenKeyEx (subKey, _T("InprocServer32"), 0, KEY_READ, &pathKey) == ERROR_SUCCESS)
  189642. {
  189643. WCHAR pathName [1024];
  189644. DWORD dtype = REG_SZ;
  189645. DWORD dsize = sizeof (pathName);
  189646. if (RegQueryValueEx (pathKey, 0, 0, &dtype, (LPBYTE) pathName, &dsize) == ERROR_SUCCESS)
  189647. ok = File (pathName).exists();
  189648. RegCloseKey (pathKey);
  189649. }
  189650. RegCloseKey (subKey);
  189651. }
  189652. break;
  189653. }
  189654. }
  189655. else
  189656. {
  189657. break;
  189658. }
  189659. }
  189660. RegCloseKey (hk);
  189661. }
  189662. return ok;
  189663. }
  189664. void addDriverInfo (const String& keyName, HKEY hk)
  189665. {
  189666. HKEY subKey;
  189667. if (RegOpenKeyEx (hk, keyName, 0, KEY_READ, &subKey) == ERROR_SUCCESS)
  189668. {
  189669. WCHAR buf [256];
  189670. zerostruct (buf);
  189671. DWORD dtype = REG_SZ;
  189672. DWORD dsize = sizeof (buf);
  189673. if (RegQueryValueEx (subKey, _T("clsid"), 0, &dtype, (LPBYTE) buf, &dsize) == ERROR_SUCCESS)
  189674. {
  189675. if (dsize > 0 && checkClassIsOk (buf))
  189676. {
  189677. CLSID classId;
  189678. if (CLSIDFromString ((LPOLESTR) buf, &classId) == S_OK)
  189679. {
  189680. dtype = REG_SZ;
  189681. dsize = sizeof (buf);
  189682. String deviceName;
  189683. if (RegQueryValueEx (subKey, _T("description"), 0, &dtype, (LPBYTE) buf, &dsize) == ERROR_SUCCESS)
  189684. deviceName = buf;
  189685. else
  189686. deviceName = keyName;
  189687. log (T("found ") + deviceName);
  189688. deviceNames.add (deviceName);
  189689. classIds.add (new CLSID (classId));
  189690. }
  189691. }
  189692. RegCloseKey (subKey);
  189693. }
  189694. }
  189695. }
  189696. ASIOAudioIODeviceType (const ASIOAudioIODeviceType&);
  189697. ASIOAudioIODeviceType& operator= (const ASIOAudioIODeviceType&);
  189698. };
  189699. AudioIODeviceType* juce_createAudioIODeviceType_ASIO()
  189700. {
  189701. return new ASIOAudioIODeviceType();
  189702. }
  189703. AudioIODevice* juce_createASIOAudioIODeviceForGUID (const String& name,
  189704. void* guid,
  189705. const String& optionalDllForDirectLoading)
  189706. {
  189707. const int freeSlot = ASIOAudioIODeviceType::findFreeSlot();
  189708. if (freeSlot < 0)
  189709. return 0;
  189710. return new ASIOAudioIODevice (name, *(CLSID*) guid, freeSlot, optionalDllForDirectLoading);
  189711. }
  189712. #undef log
  189713. #endif
  189714. /*** End of inlined file: juce_win32_ASIO.cpp ***/
  189715. /*** Start of inlined file: juce_win32_DirectSound.cpp ***/
  189716. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  189717. // compiled on its own).
  189718. #if JUCE_INCLUDED_FILE && JUCE_DIRECTSOUND
  189719. END_JUCE_NAMESPACE
  189720. extern "C"
  189721. {
  189722. // Declare just the minimum number of interfaces for the DSound objects that we need..
  189723. typedef struct typeDSBUFFERDESC
  189724. {
  189725. DWORD dwSize;
  189726. DWORD dwFlags;
  189727. DWORD dwBufferBytes;
  189728. DWORD dwReserved;
  189729. LPWAVEFORMATEX lpwfxFormat;
  189730. GUID guid3DAlgorithm;
  189731. } DSBUFFERDESC;
  189732. struct IDirectSoundBuffer;
  189733. #undef INTERFACE
  189734. #define INTERFACE IDirectSound
  189735. DECLARE_INTERFACE_(IDirectSound, IUnknown)
  189736. {
  189737. STDMETHOD(QueryInterface) (THIS_ REFIID, LPVOID*) PURE;
  189738. STDMETHOD_(ULONG,AddRef) (THIS) PURE;
  189739. STDMETHOD_(ULONG,Release) (THIS) PURE;
  189740. STDMETHOD(CreateSoundBuffer) (THIS_ DSBUFFERDESC*, IDirectSoundBuffer**, LPUNKNOWN) PURE;
  189741. STDMETHOD(GetCaps) (THIS_ void*) PURE;
  189742. STDMETHOD(DuplicateSoundBuffer) (THIS_ IDirectSoundBuffer*, IDirectSoundBuffer**) PURE;
  189743. STDMETHOD(SetCooperativeLevel) (THIS_ HWND, DWORD) PURE;
  189744. STDMETHOD(Compact) (THIS) PURE;
  189745. STDMETHOD(GetSpeakerConfig) (THIS_ LPDWORD) PURE;
  189746. STDMETHOD(SetSpeakerConfig) (THIS_ DWORD) PURE;
  189747. STDMETHOD(Initialize) (THIS_ const GUID*) PURE;
  189748. };
  189749. #undef INTERFACE
  189750. #define INTERFACE IDirectSoundBuffer
  189751. DECLARE_INTERFACE_(IDirectSoundBuffer, IUnknown)
  189752. {
  189753. STDMETHOD(QueryInterface) (THIS_ REFIID, LPVOID*) PURE;
  189754. STDMETHOD_(ULONG,AddRef) (THIS) PURE;
  189755. STDMETHOD_(ULONG,Release) (THIS) PURE;
  189756. STDMETHOD(GetCaps) (THIS_ void*) PURE;
  189757. STDMETHOD(GetCurrentPosition) (THIS_ LPDWORD, LPDWORD) PURE;
  189758. STDMETHOD(GetFormat) (THIS_ LPWAVEFORMATEX, DWORD, LPDWORD) PURE;
  189759. STDMETHOD(GetVolume) (THIS_ LPLONG) PURE;
  189760. STDMETHOD(GetPan) (THIS_ LPLONG) PURE;
  189761. STDMETHOD(GetFrequency) (THIS_ LPDWORD) PURE;
  189762. STDMETHOD(GetStatus) (THIS_ LPDWORD) PURE;
  189763. STDMETHOD(Initialize) (THIS_ IDirectSound*, DSBUFFERDESC*) PURE;
  189764. STDMETHOD(Lock) (THIS_ DWORD, DWORD, LPVOID*, LPDWORD, LPVOID*, LPDWORD, DWORD) PURE;
  189765. STDMETHOD(Play) (THIS_ DWORD, DWORD, DWORD) PURE;
  189766. STDMETHOD(SetCurrentPosition) (THIS_ DWORD) PURE;
  189767. STDMETHOD(SetFormat) (THIS_ const WAVEFORMATEX*) PURE;
  189768. STDMETHOD(SetVolume) (THIS_ LONG) PURE;
  189769. STDMETHOD(SetPan) (THIS_ LONG) PURE;
  189770. STDMETHOD(SetFrequency) (THIS_ DWORD) PURE;
  189771. STDMETHOD(Stop) (THIS) PURE;
  189772. STDMETHOD(Unlock) (THIS_ LPVOID, DWORD, LPVOID, DWORD) PURE;
  189773. STDMETHOD(Restore) (THIS) PURE;
  189774. };
  189775. typedef struct typeDSCBUFFERDESC
  189776. {
  189777. DWORD dwSize;
  189778. DWORD dwFlags;
  189779. DWORD dwBufferBytes;
  189780. DWORD dwReserved;
  189781. LPWAVEFORMATEX lpwfxFormat;
  189782. } DSCBUFFERDESC;
  189783. struct IDirectSoundCaptureBuffer;
  189784. #undef INTERFACE
  189785. #define INTERFACE IDirectSoundCapture
  189786. DECLARE_INTERFACE_(IDirectSoundCapture, IUnknown)
  189787. {
  189788. STDMETHOD(QueryInterface) (THIS_ REFIID, LPVOID*) PURE;
  189789. STDMETHOD_(ULONG,AddRef) (THIS) PURE;
  189790. STDMETHOD_(ULONG,Release) (THIS) PURE;
  189791. STDMETHOD(CreateCaptureBuffer) (THIS_ DSCBUFFERDESC*, IDirectSoundCaptureBuffer**, LPUNKNOWN) PURE;
  189792. STDMETHOD(GetCaps) (THIS_ void*) PURE;
  189793. STDMETHOD(Initialize) (THIS_ const GUID*) PURE;
  189794. };
  189795. #undef INTERFACE
  189796. #define INTERFACE IDirectSoundCaptureBuffer
  189797. DECLARE_INTERFACE_(IDirectSoundCaptureBuffer, IUnknown)
  189798. {
  189799. STDMETHOD(QueryInterface) (THIS_ REFIID, LPVOID*) PURE;
  189800. STDMETHOD_(ULONG,AddRef) (THIS) PURE;
  189801. STDMETHOD_(ULONG,Release) (THIS) PURE;
  189802. STDMETHOD(GetCaps) (THIS_ void*) PURE;
  189803. STDMETHOD(GetCurrentPosition) (THIS_ LPDWORD, LPDWORD) PURE;
  189804. STDMETHOD(GetFormat) (THIS_ LPWAVEFORMATEX, DWORD, LPDWORD) PURE;
  189805. STDMETHOD(GetStatus) (THIS_ LPDWORD) PURE;
  189806. STDMETHOD(Initialize) (THIS_ IDirectSoundCapture*, DSCBUFFERDESC*) PURE;
  189807. STDMETHOD(Lock) (THIS_ DWORD, DWORD, LPVOID*, LPDWORD, LPVOID*, LPDWORD, DWORD) PURE;
  189808. STDMETHOD(Start) (THIS_ DWORD) PURE;
  189809. STDMETHOD(Stop) (THIS) PURE;
  189810. STDMETHOD(Unlock) (THIS_ LPVOID, DWORD, LPVOID, DWORD) PURE;
  189811. };
  189812. };
  189813. BEGIN_JUCE_NAMESPACE
  189814. static const String getDSErrorMessage (HRESULT hr)
  189815. {
  189816. const char* result = 0;
  189817. switch (hr)
  189818. {
  189819. case MAKE_HRESULT(1, 0x878, 10):
  189820. result = "Device already allocated";
  189821. break;
  189822. case MAKE_HRESULT(1, 0x878, 30):
  189823. result = "Control unavailable";
  189824. break;
  189825. case E_INVALIDARG:
  189826. result = "Invalid parameter";
  189827. break;
  189828. case MAKE_HRESULT(1, 0x878, 50):
  189829. result = "Invalid call";
  189830. break;
  189831. case E_FAIL:
  189832. result = "Generic error";
  189833. break;
  189834. case MAKE_HRESULT(1, 0x878, 70):
  189835. result = "Priority level error";
  189836. break;
  189837. case E_OUTOFMEMORY:
  189838. result = "Out of memory";
  189839. break;
  189840. case MAKE_HRESULT(1, 0x878, 100):
  189841. result = "Bad format";
  189842. break;
  189843. case E_NOTIMPL:
  189844. result = "Unsupported function";
  189845. break;
  189846. case MAKE_HRESULT(1, 0x878, 120):
  189847. result = "No driver";
  189848. break;
  189849. case MAKE_HRESULT(1, 0x878, 130):
  189850. result = "Already initialised";
  189851. break;
  189852. case CLASS_E_NOAGGREGATION:
  189853. result = "No aggregation";
  189854. break;
  189855. case MAKE_HRESULT(1, 0x878, 150):
  189856. result = "Buffer lost";
  189857. break;
  189858. case MAKE_HRESULT(1, 0x878, 160):
  189859. result = "Another app has priority";
  189860. break;
  189861. case MAKE_HRESULT(1, 0x878, 170):
  189862. result = "Uninitialised";
  189863. break;
  189864. case E_NOINTERFACE:
  189865. result = "No interface";
  189866. break;
  189867. case S_OK:
  189868. result = "No error";
  189869. break;
  189870. default:
  189871. return "Unknown error: " + String ((int) hr);
  189872. }
  189873. return result;
  189874. }
  189875. #define DS_DEBUGGING 1
  189876. #ifdef DS_DEBUGGING
  189877. #define CATCH JUCE_CATCH_EXCEPTION
  189878. #undef log
  189879. #define log(a) Logger::writeToLog(a);
  189880. #undef logError
  189881. #define logError(a) logDSError(a, __LINE__);
  189882. static void logDSError (HRESULT hr, int lineNum)
  189883. {
  189884. if (hr != S_OK)
  189885. {
  189886. String error ("DS error at line ");
  189887. error << lineNum << T(" - ") << getDSErrorMessage (hr);
  189888. log (error);
  189889. }
  189890. }
  189891. #else
  189892. #define CATCH JUCE_CATCH_ALL
  189893. #define log(a)
  189894. #define logError(a)
  189895. #endif
  189896. #define DSOUND_FUNCTION(functionName, params) \
  189897. typedef HRESULT (WINAPI *type##functionName) params; \
  189898. static type##functionName ds##functionName = 0;
  189899. #define DSOUND_FUNCTION_LOAD(functionName) \
  189900. ds##functionName = (type##functionName) GetProcAddress (h, #functionName); \
  189901. jassert (ds##functionName != 0);
  189902. typedef BOOL (CALLBACK *LPDSENUMCALLBACKW) (LPGUID, LPCWSTR, LPCWSTR, LPVOID);
  189903. typedef BOOL (CALLBACK *LPDSENUMCALLBACKA) (LPGUID, LPCSTR, LPCSTR, LPVOID);
  189904. DSOUND_FUNCTION (DirectSoundCreate, (const GUID*, IDirectSound**, LPUNKNOWN))
  189905. DSOUND_FUNCTION (DirectSoundCaptureCreate, (const GUID*, IDirectSoundCapture**, LPUNKNOWN))
  189906. DSOUND_FUNCTION (DirectSoundEnumerateW, (LPDSENUMCALLBACKW, LPVOID))
  189907. DSOUND_FUNCTION (DirectSoundCaptureEnumerateW, (LPDSENUMCALLBACKW, LPVOID))
  189908. static void initialiseDSoundFunctions()
  189909. {
  189910. if (dsDirectSoundCreate == 0)
  189911. {
  189912. HMODULE h = LoadLibraryA ("dsound.dll");
  189913. DSOUND_FUNCTION_LOAD (DirectSoundCreate)
  189914. DSOUND_FUNCTION_LOAD (DirectSoundCaptureCreate)
  189915. DSOUND_FUNCTION_LOAD (DirectSoundEnumerateW)
  189916. DSOUND_FUNCTION_LOAD (DirectSoundCaptureEnumerateW)
  189917. }
  189918. }
  189919. class DSoundInternalOutChannel
  189920. {
  189921. String name;
  189922. LPGUID guid;
  189923. int sampleRate, bufferSizeSamples;
  189924. float* leftBuffer;
  189925. float* rightBuffer;
  189926. IDirectSound* pDirectSound;
  189927. IDirectSoundBuffer* pOutputBuffer;
  189928. DWORD writeOffset;
  189929. int totalBytesPerBuffer;
  189930. int bytesPerBuffer;
  189931. unsigned int lastPlayCursor;
  189932. public:
  189933. int bitDepth;
  189934. bool doneFlag;
  189935. DSoundInternalOutChannel (const String& name_,
  189936. LPGUID guid_,
  189937. int rate,
  189938. int bufferSize,
  189939. float* left,
  189940. float* right)
  189941. : name (name_),
  189942. guid (guid_),
  189943. sampleRate (rate),
  189944. bufferSizeSamples (bufferSize),
  189945. leftBuffer (left),
  189946. rightBuffer (right),
  189947. pDirectSound (0),
  189948. pOutputBuffer (0),
  189949. bitDepth (16)
  189950. {
  189951. }
  189952. ~DSoundInternalOutChannel()
  189953. {
  189954. close();
  189955. }
  189956. void close()
  189957. {
  189958. HRESULT hr;
  189959. if (pOutputBuffer != 0)
  189960. {
  189961. JUCE_TRY
  189962. {
  189963. log (T("closing dsound out: ") + name);
  189964. hr = pOutputBuffer->Stop();
  189965. logError (hr);
  189966. }
  189967. CATCH
  189968. JUCE_TRY
  189969. {
  189970. hr = pOutputBuffer->Release();
  189971. logError (hr);
  189972. }
  189973. CATCH
  189974. pOutputBuffer = 0;
  189975. }
  189976. if (pDirectSound != 0)
  189977. {
  189978. JUCE_TRY
  189979. {
  189980. hr = pDirectSound->Release();
  189981. logError (hr);
  189982. }
  189983. CATCH
  189984. pDirectSound = 0;
  189985. }
  189986. }
  189987. const String open()
  189988. {
  189989. log (T("opening dsound out device: ") + name
  189990. + T(" rate=") + String (sampleRate)
  189991. + T(" bits=") + String (bitDepth)
  189992. + T(" buf=") + String (bufferSizeSamples));
  189993. pDirectSound = 0;
  189994. pOutputBuffer = 0;
  189995. writeOffset = 0;
  189996. String error;
  189997. HRESULT hr = E_NOINTERFACE;
  189998. if (dsDirectSoundCreate != 0)
  189999. hr = dsDirectSoundCreate (guid, &pDirectSound, 0);
  190000. if (hr == S_OK)
  190001. {
  190002. bytesPerBuffer = (bufferSizeSamples * (bitDepth >> 2)) & ~15;
  190003. totalBytesPerBuffer = (3 * bytesPerBuffer) & ~15;
  190004. const int numChannels = 2;
  190005. hr = pDirectSound->SetCooperativeLevel (GetDesktopWindow(), 2 /* DSSCL_PRIORITY */);
  190006. logError (hr);
  190007. if (hr == S_OK)
  190008. {
  190009. IDirectSoundBuffer* pPrimaryBuffer;
  190010. DSBUFFERDESC primaryDesc;
  190011. zerostruct (primaryDesc);
  190012. primaryDesc.dwSize = sizeof (DSBUFFERDESC);
  190013. primaryDesc.dwFlags = 1 /* DSBCAPS_PRIMARYBUFFER */;
  190014. primaryDesc.dwBufferBytes = 0;
  190015. primaryDesc.lpwfxFormat = 0;
  190016. log ("opening dsound out step 2");
  190017. hr = pDirectSound->CreateSoundBuffer (&primaryDesc, &pPrimaryBuffer, 0);
  190018. logError (hr);
  190019. if (hr == S_OK)
  190020. {
  190021. WAVEFORMATEX wfFormat;
  190022. wfFormat.wFormatTag = WAVE_FORMAT_PCM;
  190023. wfFormat.nChannels = (unsigned short) numChannels;
  190024. wfFormat.nSamplesPerSec = sampleRate;
  190025. wfFormat.wBitsPerSample = (unsigned short) bitDepth;
  190026. wfFormat.nBlockAlign = (unsigned short) (wfFormat.nChannels * wfFormat.wBitsPerSample / 8);
  190027. wfFormat.nAvgBytesPerSec = wfFormat.nSamplesPerSec * wfFormat.nBlockAlign;
  190028. wfFormat.cbSize = 0;
  190029. hr = pPrimaryBuffer->SetFormat (&wfFormat);
  190030. logError (hr);
  190031. if (hr == S_OK)
  190032. {
  190033. DSBUFFERDESC secondaryDesc;
  190034. zerostruct (secondaryDesc);
  190035. secondaryDesc.dwSize = sizeof (DSBUFFERDESC);
  190036. secondaryDesc.dwFlags = 0x8000 /* DSBCAPS_GLOBALFOCUS */
  190037. | 0x10000 /* DSBCAPS_GETCURRENTPOSITION2 */;
  190038. secondaryDesc.dwBufferBytes = totalBytesPerBuffer;
  190039. secondaryDesc.lpwfxFormat = &wfFormat;
  190040. hr = pDirectSound->CreateSoundBuffer (&secondaryDesc, &pOutputBuffer, 0);
  190041. logError (hr);
  190042. if (hr == S_OK)
  190043. {
  190044. log ("opening dsound out step 3");
  190045. DWORD dwDataLen;
  190046. unsigned char* pDSBuffData;
  190047. hr = pOutputBuffer->Lock (0, totalBytesPerBuffer,
  190048. (LPVOID*) &pDSBuffData, &dwDataLen, 0, 0, 0);
  190049. logError (hr);
  190050. if (hr == S_OK)
  190051. {
  190052. zeromem (pDSBuffData, dwDataLen);
  190053. hr = pOutputBuffer->Unlock (pDSBuffData, dwDataLen, 0, 0);
  190054. if (hr == S_OK)
  190055. {
  190056. hr = pOutputBuffer->SetCurrentPosition (0);
  190057. if (hr == S_OK)
  190058. {
  190059. hr = pOutputBuffer->Play (0, 0, 1 /* DSBPLAY_LOOPING */);
  190060. if (hr == S_OK)
  190061. return String::empty;
  190062. }
  190063. }
  190064. }
  190065. }
  190066. }
  190067. }
  190068. }
  190069. }
  190070. error = getDSErrorMessage (hr);
  190071. close();
  190072. return error;
  190073. }
  190074. void synchronisePosition()
  190075. {
  190076. if (pOutputBuffer != 0)
  190077. {
  190078. DWORD playCursor;
  190079. pOutputBuffer->GetCurrentPosition (&playCursor, &writeOffset);
  190080. }
  190081. }
  190082. bool service()
  190083. {
  190084. if (pOutputBuffer == 0)
  190085. return true;
  190086. DWORD playCursor, writeCursor;
  190087. for (;;)
  190088. {
  190089. HRESULT hr = pOutputBuffer->GetCurrentPosition (&playCursor, &writeCursor);
  190090. if (hr == MAKE_HRESULT (1, 0x878, 150)) // DSERR_BUFFERLOST
  190091. {
  190092. pOutputBuffer->Restore();
  190093. continue;
  190094. }
  190095. if (hr == S_OK)
  190096. break;
  190097. logError (hr);
  190098. jassertfalse
  190099. return true;
  190100. }
  190101. int playWriteGap = writeCursor - playCursor;
  190102. if (playWriteGap < 0)
  190103. playWriteGap += totalBytesPerBuffer;
  190104. int bytesEmpty = playCursor - writeOffset;
  190105. if (bytesEmpty < 0)
  190106. bytesEmpty += totalBytesPerBuffer;
  190107. if (bytesEmpty > (totalBytesPerBuffer - playWriteGap))
  190108. {
  190109. writeOffset = writeCursor;
  190110. bytesEmpty = totalBytesPerBuffer - playWriteGap;
  190111. }
  190112. if (bytesEmpty >= bytesPerBuffer)
  190113. {
  190114. LPBYTE lpbuf1 = 0;
  190115. LPBYTE lpbuf2 = 0;
  190116. DWORD dwSize1 = 0;
  190117. DWORD dwSize2 = 0;
  190118. HRESULT hr = pOutputBuffer->Lock (writeOffset,
  190119. bytesPerBuffer,
  190120. (void**) &lpbuf1, &dwSize1,
  190121. (void**) &lpbuf2, &dwSize2, 0);
  190122. if (hr == MAKE_HRESULT (1, 0x878, 150)) // DSERR_BUFFERLOST
  190123. {
  190124. pOutputBuffer->Restore();
  190125. hr = pOutputBuffer->Lock (writeOffset,
  190126. bytesPerBuffer,
  190127. (void**) &lpbuf1, &dwSize1,
  190128. (void**) &lpbuf2, &dwSize2, 0);
  190129. }
  190130. if (hr == S_OK)
  190131. {
  190132. if (bitDepth == 16)
  190133. {
  190134. const float gainL = 32767.0f;
  190135. const float gainR = 32767.0f;
  190136. int* dest = (int*)lpbuf1;
  190137. const float* left = leftBuffer;
  190138. const float* right = rightBuffer;
  190139. int samples1 = dwSize1 >> 2;
  190140. int samples2 = dwSize2 >> 2;
  190141. if (left == 0)
  190142. {
  190143. while (--samples1 >= 0)
  190144. {
  190145. int r = roundToInt (gainR * *right++);
  190146. if (r < -32768)
  190147. r = -32768;
  190148. else if (r > 32767)
  190149. r = 32767;
  190150. *dest++ = (r << 16);
  190151. }
  190152. dest = (int*)lpbuf2;
  190153. while (--samples2 >= 0)
  190154. {
  190155. int r = roundToInt (gainR * *right++);
  190156. if (r < -32768)
  190157. r = -32768;
  190158. else if (r > 32767)
  190159. r = 32767;
  190160. *dest++ = (r << 16);
  190161. }
  190162. }
  190163. else if (right == 0)
  190164. {
  190165. while (--samples1 >= 0)
  190166. {
  190167. int l = roundToInt (gainL * *left++);
  190168. if (l < -32768)
  190169. l = -32768;
  190170. else if (l > 32767)
  190171. l = 32767;
  190172. l &= 0xffff;
  190173. *dest++ = l;
  190174. }
  190175. dest = (int*)lpbuf2;
  190176. while (--samples2 >= 0)
  190177. {
  190178. int l = roundToInt (gainL * *left++);
  190179. if (l < -32768)
  190180. l = -32768;
  190181. else if (l > 32767)
  190182. l = 32767;
  190183. l &= 0xffff;
  190184. *dest++ = l;
  190185. }
  190186. }
  190187. else
  190188. {
  190189. while (--samples1 >= 0)
  190190. {
  190191. int l = roundToInt (gainL * *left++);
  190192. if (l < -32768)
  190193. l = -32768;
  190194. else if (l > 32767)
  190195. l = 32767;
  190196. l &= 0xffff;
  190197. int r = roundToInt (gainR * *right++);
  190198. if (r < -32768)
  190199. r = -32768;
  190200. else if (r > 32767)
  190201. r = 32767;
  190202. *dest++ = (r << 16) | l;
  190203. }
  190204. dest = (int*)lpbuf2;
  190205. while (--samples2 >= 0)
  190206. {
  190207. int l = roundToInt (gainL * *left++);
  190208. if (l < -32768)
  190209. l = -32768;
  190210. else if (l > 32767)
  190211. l = 32767;
  190212. l &= 0xffff;
  190213. int r = roundToInt (gainR * *right++);
  190214. if (r < -32768)
  190215. r = -32768;
  190216. else if (r > 32767)
  190217. r = 32767;
  190218. *dest++ = (r << 16) | l;
  190219. }
  190220. }
  190221. }
  190222. else
  190223. {
  190224. jassertfalse
  190225. }
  190226. writeOffset = (writeOffset + dwSize1 + dwSize2) % totalBytesPerBuffer;
  190227. pOutputBuffer->Unlock (lpbuf1, dwSize1, lpbuf2, dwSize2);
  190228. }
  190229. else
  190230. {
  190231. jassertfalse
  190232. logError (hr);
  190233. }
  190234. bytesEmpty -= bytesPerBuffer;
  190235. return true;
  190236. }
  190237. else
  190238. {
  190239. return false;
  190240. }
  190241. }
  190242. };
  190243. struct DSoundInternalInChannel
  190244. {
  190245. String name;
  190246. LPGUID guid;
  190247. int sampleRate, bufferSizeSamples;
  190248. float* leftBuffer;
  190249. float* rightBuffer;
  190250. IDirectSound* pDirectSound;
  190251. IDirectSoundCapture* pDirectSoundCapture;
  190252. IDirectSoundCaptureBuffer* pInputBuffer;
  190253. public:
  190254. unsigned int readOffset;
  190255. int bytesPerBuffer, totalBytesPerBuffer;
  190256. int bitDepth;
  190257. bool doneFlag;
  190258. DSoundInternalInChannel (const String& name_,
  190259. LPGUID guid_,
  190260. int rate,
  190261. int bufferSize,
  190262. float* left,
  190263. float* right)
  190264. : name (name_),
  190265. guid (guid_),
  190266. sampleRate (rate),
  190267. bufferSizeSamples (bufferSize),
  190268. leftBuffer (left),
  190269. rightBuffer (right),
  190270. pDirectSound (0),
  190271. pDirectSoundCapture (0),
  190272. pInputBuffer (0),
  190273. bitDepth (16)
  190274. {
  190275. }
  190276. ~DSoundInternalInChannel()
  190277. {
  190278. close();
  190279. }
  190280. void close()
  190281. {
  190282. HRESULT hr;
  190283. if (pInputBuffer != 0)
  190284. {
  190285. JUCE_TRY
  190286. {
  190287. log (T("closing dsound in: ") + name);
  190288. hr = pInputBuffer->Stop();
  190289. logError (hr);
  190290. }
  190291. CATCH
  190292. JUCE_TRY
  190293. {
  190294. hr = pInputBuffer->Release();
  190295. logError (hr);
  190296. }
  190297. CATCH
  190298. pInputBuffer = 0;
  190299. }
  190300. if (pDirectSoundCapture != 0)
  190301. {
  190302. JUCE_TRY
  190303. {
  190304. hr = pDirectSoundCapture->Release();
  190305. logError (hr);
  190306. }
  190307. CATCH
  190308. pDirectSoundCapture = 0;
  190309. }
  190310. if (pDirectSound != 0)
  190311. {
  190312. JUCE_TRY
  190313. {
  190314. hr = pDirectSound->Release();
  190315. logError (hr);
  190316. }
  190317. CATCH
  190318. pDirectSound = 0;
  190319. }
  190320. }
  190321. const String open()
  190322. {
  190323. log (T("opening dsound in device: ") + name
  190324. + T(" rate=") + String (sampleRate) + T(" bits=") + String (bitDepth) + T(" buf=") + String (bufferSizeSamples));
  190325. pDirectSound = 0;
  190326. pDirectSoundCapture = 0;
  190327. pInputBuffer = 0;
  190328. readOffset = 0;
  190329. totalBytesPerBuffer = 0;
  190330. String error;
  190331. HRESULT hr = E_NOINTERFACE;
  190332. if (dsDirectSoundCaptureCreate != 0)
  190333. hr = dsDirectSoundCaptureCreate (guid, &pDirectSoundCapture, 0);
  190334. logError (hr);
  190335. if (hr == S_OK)
  190336. {
  190337. const int numChannels = 2;
  190338. bytesPerBuffer = (bufferSizeSamples * (bitDepth >> 2)) & ~15;
  190339. totalBytesPerBuffer = (3 * bytesPerBuffer) & ~15;
  190340. WAVEFORMATEX wfFormat;
  190341. wfFormat.wFormatTag = WAVE_FORMAT_PCM;
  190342. wfFormat.nChannels = (unsigned short)numChannels;
  190343. wfFormat.nSamplesPerSec = sampleRate;
  190344. wfFormat.wBitsPerSample = (unsigned short)bitDepth;
  190345. wfFormat.nBlockAlign = (unsigned short)(wfFormat.nChannels * (wfFormat.wBitsPerSample / 8));
  190346. wfFormat.nAvgBytesPerSec = wfFormat.nSamplesPerSec * wfFormat.nBlockAlign;
  190347. wfFormat.cbSize = 0;
  190348. DSCBUFFERDESC captureDesc;
  190349. zerostruct (captureDesc);
  190350. captureDesc.dwSize = sizeof (DSCBUFFERDESC);
  190351. captureDesc.dwFlags = 0;
  190352. captureDesc.dwBufferBytes = totalBytesPerBuffer;
  190353. captureDesc.lpwfxFormat = &wfFormat;
  190354. log (T("opening dsound in step 2"));
  190355. hr = pDirectSoundCapture->CreateCaptureBuffer (&captureDesc, &pInputBuffer, 0);
  190356. logError (hr);
  190357. if (hr == S_OK)
  190358. {
  190359. hr = pInputBuffer->Start (1 /* DSCBSTART_LOOPING */);
  190360. logError (hr);
  190361. if (hr == S_OK)
  190362. return String::empty;
  190363. }
  190364. }
  190365. error = getDSErrorMessage (hr);
  190366. close();
  190367. return error;
  190368. }
  190369. void synchronisePosition()
  190370. {
  190371. if (pInputBuffer != 0)
  190372. {
  190373. DWORD capturePos;
  190374. pInputBuffer->GetCurrentPosition (&capturePos, (DWORD*)&readOffset);
  190375. }
  190376. }
  190377. bool service()
  190378. {
  190379. if (pInputBuffer == 0)
  190380. return true;
  190381. DWORD capturePos, readPos;
  190382. HRESULT hr = pInputBuffer->GetCurrentPosition (&capturePos, &readPos);
  190383. logError (hr);
  190384. if (hr != S_OK)
  190385. return true;
  190386. int bytesFilled = readPos - readOffset;
  190387. if (bytesFilled < 0)
  190388. bytesFilled += totalBytesPerBuffer;
  190389. if (bytesFilled >= bytesPerBuffer)
  190390. {
  190391. LPBYTE lpbuf1 = 0;
  190392. LPBYTE lpbuf2 = 0;
  190393. DWORD dwsize1 = 0;
  190394. DWORD dwsize2 = 0;
  190395. HRESULT hr = pInputBuffer->Lock (readOffset,
  190396. bytesPerBuffer,
  190397. (void**) &lpbuf1, &dwsize1,
  190398. (void**) &lpbuf2, &dwsize2, 0);
  190399. if (hr == S_OK)
  190400. {
  190401. if (bitDepth == 16)
  190402. {
  190403. const float g = 1.0f / 32768.0f;
  190404. float* destL = leftBuffer;
  190405. float* destR = rightBuffer;
  190406. int samples1 = dwsize1 >> 2;
  190407. int samples2 = dwsize2 >> 2;
  190408. const short* src = (const short*)lpbuf1;
  190409. if (destL == 0)
  190410. {
  190411. while (--samples1 >= 0)
  190412. {
  190413. ++src;
  190414. *destR++ = *src++ * g;
  190415. }
  190416. src = (const short*)lpbuf2;
  190417. while (--samples2 >= 0)
  190418. {
  190419. ++src;
  190420. *destR++ = *src++ * g;
  190421. }
  190422. }
  190423. else if (destR == 0)
  190424. {
  190425. while (--samples1 >= 0)
  190426. {
  190427. *destL++ = *src++ * g;
  190428. ++src;
  190429. }
  190430. src = (const short*)lpbuf2;
  190431. while (--samples2 >= 0)
  190432. {
  190433. *destL++ = *src++ * g;
  190434. ++src;
  190435. }
  190436. }
  190437. else
  190438. {
  190439. while (--samples1 >= 0)
  190440. {
  190441. *destL++ = *src++ * g;
  190442. *destR++ = *src++ * g;
  190443. }
  190444. src = (const short*)lpbuf2;
  190445. while (--samples2 >= 0)
  190446. {
  190447. *destL++ = *src++ * g;
  190448. *destR++ = *src++ * g;
  190449. }
  190450. }
  190451. }
  190452. else
  190453. {
  190454. jassertfalse
  190455. }
  190456. readOffset = (readOffset + dwsize1 + dwsize2) % totalBytesPerBuffer;
  190457. pInputBuffer->Unlock (lpbuf1, dwsize1, lpbuf2, dwsize2);
  190458. }
  190459. else
  190460. {
  190461. logError (hr);
  190462. jassertfalse
  190463. }
  190464. bytesFilled -= bytesPerBuffer;
  190465. return true;
  190466. }
  190467. else
  190468. {
  190469. return false;
  190470. }
  190471. }
  190472. };
  190473. class DSoundAudioIODevice : public AudioIODevice,
  190474. public Thread
  190475. {
  190476. public:
  190477. DSoundAudioIODevice (const String& deviceName,
  190478. const int outputDeviceIndex_,
  190479. const int inputDeviceIndex_)
  190480. : AudioIODevice (deviceName, "DirectSound"),
  190481. Thread ("Juce DSound"),
  190482. isOpen_ (false),
  190483. isStarted (false),
  190484. outputDeviceIndex (outputDeviceIndex_),
  190485. inputDeviceIndex (inputDeviceIndex_),
  190486. numInputBuffers (0),
  190487. numOutputBuffers (0),
  190488. totalSamplesOut (0),
  190489. sampleRate (0.0),
  190490. inputBuffers (0),
  190491. outputBuffers (0),
  190492. callback (0),
  190493. bufferSizeSamples (0)
  190494. {
  190495. if (outputDeviceIndex_ >= 0)
  190496. {
  190497. outChannels.add (TRANS("Left"));
  190498. outChannels.add (TRANS("Right"));
  190499. }
  190500. if (inputDeviceIndex_ >= 0)
  190501. {
  190502. inChannels.add (TRANS("Left"));
  190503. inChannels.add (TRANS("Right"));
  190504. }
  190505. }
  190506. ~DSoundAudioIODevice()
  190507. {
  190508. close();
  190509. }
  190510. const StringArray getOutputChannelNames()
  190511. {
  190512. return outChannels;
  190513. }
  190514. const StringArray getInputChannelNames()
  190515. {
  190516. return inChannels;
  190517. }
  190518. int getNumSampleRates()
  190519. {
  190520. return 4;
  190521. }
  190522. double getSampleRate (int index)
  190523. {
  190524. const double samps[] = { 44100.0, 48000.0, 88200.0, 96000.0 };
  190525. return samps [jlimit (0, 3, index)];
  190526. }
  190527. int getNumBufferSizesAvailable()
  190528. {
  190529. return 50;
  190530. }
  190531. int getBufferSizeSamples (int index)
  190532. {
  190533. int n = 64;
  190534. for (int i = 0; i < index; ++i)
  190535. n += (n < 512) ? 32
  190536. : ((n < 1024) ? 64
  190537. : ((n < 2048) ? 128 : 256));
  190538. return n;
  190539. }
  190540. int getDefaultBufferSize()
  190541. {
  190542. return 2560;
  190543. }
  190544. const String open (const BigInteger& inputChannels,
  190545. const BigInteger& outputChannels,
  190546. double sampleRate,
  190547. int bufferSizeSamples)
  190548. {
  190549. lastError = openDevice (inputChannels, outputChannels, sampleRate, bufferSizeSamples);
  190550. isOpen_ = lastError.isEmpty();
  190551. return lastError;
  190552. }
  190553. void close()
  190554. {
  190555. stop();
  190556. if (isOpen_)
  190557. {
  190558. closeDevice();
  190559. isOpen_ = false;
  190560. }
  190561. }
  190562. bool isOpen()
  190563. {
  190564. return isOpen_ && isThreadRunning();
  190565. }
  190566. int getCurrentBufferSizeSamples()
  190567. {
  190568. return bufferSizeSamples;
  190569. }
  190570. double getCurrentSampleRate()
  190571. {
  190572. return sampleRate;
  190573. }
  190574. int getCurrentBitDepth()
  190575. {
  190576. int i, bits = 256;
  190577. for (i = inChans.size(); --i >= 0;)
  190578. bits = jmin (bits, inChans[i]->bitDepth);
  190579. for (i = outChans.size(); --i >= 0;)
  190580. bits = jmin (bits, outChans[i]->bitDepth);
  190581. if (bits > 32)
  190582. bits = 16;
  190583. return bits;
  190584. }
  190585. const BigInteger getActiveOutputChannels() const
  190586. {
  190587. return enabledOutputs;
  190588. }
  190589. const BigInteger getActiveInputChannels() const
  190590. {
  190591. return enabledInputs;
  190592. }
  190593. int getOutputLatencyInSamples()
  190594. {
  190595. return (int) (getCurrentBufferSizeSamples() * 1.5);
  190596. }
  190597. int getInputLatencyInSamples()
  190598. {
  190599. return getOutputLatencyInSamples();
  190600. }
  190601. void start (AudioIODeviceCallback* call)
  190602. {
  190603. if (isOpen_ && call != 0 && ! isStarted)
  190604. {
  190605. if (! isThreadRunning())
  190606. {
  190607. // something gone wrong and the thread's stopped..
  190608. isOpen_ = false;
  190609. return;
  190610. }
  190611. call->audioDeviceAboutToStart (this);
  190612. const ScopedLock sl (startStopLock);
  190613. callback = call;
  190614. isStarted = true;
  190615. }
  190616. }
  190617. void stop()
  190618. {
  190619. if (isStarted)
  190620. {
  190621. AudioIODeviceCallback* const callbackLocal = callback;
  190622. {
  190623. const ScopedLock sl (startStopLock);
  190624. isStarted = false;
  190625. }
  190626. if (callbackLocal != 0)
  190627. callbackLocal->audioDeviceStopped();
  190628. }
  190629. }
  190630. bool isPlaying()
  190631. {
  190632. return isStarted && isOpen_ && isThreadRunning();
  190633. }
  190634. const String getLastError()
  190635. {
  190636. return lastError;
  190637. }
  190638. juce_UseDebuggingNewOperator
  190639. StringArray inChannels, outChannels;
  190640. int outputDeviceIndex, inputDeviceIndex;
  190641. private:
  190642. bool isOpen_;
  190643. bool isStarted;
  190644. String lastError;
  190645. OwnedArray <DSoundInternalInChannel> inChans;
  190646. OwnedArray <DSoundInternalOutChannel> outChans;
  190647. WaitableEvent startEvent;
  190648. int numInputBuffers, numOutputBuffers, bufferSizeSamples;
  190649. int volatile totalSamplesOut;
  190650. int64 volatile lastBlockTime;
  190651. double sampleRate;
  190652. BigInteger enabledInputs, enabledOutputs;
  190653. HeapBlock <float*> inputBuffers, outputBuffers;
  190654. AudioIODeviceCallback* callback;
  190655. CriticalSection startStopLock;
  190656. DSoundAudioIODevice (const DSoundAudioIODevice&);
  190657. DSoundAudioIODevice& operator= (const DSoundAudioIODevice&);
  190658. const String openDevice (const BigInteger& inputChannels,
  190659. const BigInteger& outputChannels,
  190660. double sampleRate_,
  190661. int bufferSizeSamples_);
  190662. void closeDevice()
  190663. {
  190664. isStarted = false;
  190665. stopThread (5000);
  190666. inChans.clear();
  190667. outChans.clear();
  190668. int i;
  190669. for (i = 0; i < numInputBuffers; ++i)
  190670. juce_free (inputBuffers[i]);
  190671. inputBuffers.free();
  190672. numInputBuffers = 0;
  190673. for (i = 0; i < numOutputBuffers; ++i)
  190674. juce_free (outputBuffers[i]);
  190675. outputBuffers.free();
  190676. numOutputBuffers = 0;
  190677. }
  190678. void resync()
  190679. {
  190680. if (! threadShouldExit())
  190681. {
  190682. sleep (5);
  190683. int i;
  190684. for (i = 0; i < outChans.size(); ++i)
  190685. outChans.getUnchecked(i)->synchronisePosition();
  190686. for (i = 0; i < inChans.size(); ++i)
  190687. inChans.getUnchecked(i)->synchronisePosition();
  190688. }
  190689. }
  190690. public:
  190691. void run()
  190692. {
  190693. while (! threadShouldExit())
  190694. {
  190695. if (wait (100))
  190696. break;
  190697. }
  190698. const int latencyMs = (int) (bufferSizeSamples * 1000.0 / sampleRate);
  190699. const int maxTimeMS = jmax (5, 3 * latencyMs);
  190700. while (! threadShouldExit())
  190701. {
  190702. int numToDo = 0;
  190703. uint32 startTime = Time::getMillisecondCounter();
  190704. int i;
  190705. for (i = inChans.size(); --i >= 0;)
  190706. {
  190707. inChans.getUnchecked(i)->doneFlag = false;
  190708. ++numToDo;
  190709. }
  190710. for (i = outChans.size(); --i >= 0;)
  190711. {
  190712. outChans.getUnchecked(i)->doneFlag = false;
  190713. ++numToDo;
  190714. }
  190715. if (numToDo > 0)
  190716. {
  190717. const int maxCount = 3;
  190718. int count = maxCount;
  190719. for (;;)
  190720. {
  190721. for (i = inChans.size(); --i >= 0;)
  190722. {
  190723. DSoundInternalInChannel* const in = inChans.getUnchecked(i);
  190724. if ((! in->doneFlag) && in->service())
  190725. {
  190726. in->doneFlag = true;
  190727. --numToDo;
  190728. }
  190729. }
  190730. for (i = outChans.size(); --i >= 0;)
  190731. {
  190732. DSoundInternalOutChannel* const out = outChans.getUnchecked(i);
  190733. if ((! out->doneFlag) && out->service())
  190734. {
  190735. out->doneFlag = true;
  190736. --numToDo;
  190737. }
  190738. }
  190739. if (numToDo <= 0)
  190740. break;
  190741. if (Time::getMillisecondCounter() > startTime + maxTimeMS)
  190742. {
  190743. resync();
  190744. break;
  190745. }
  190746. if (--count <= 0)
  190747. {
  190748. Sleep (1);
  190749. count = maxCount;
  190750. }
  190751. if (threadShouldExit())
  190752. return;
  190753. }
  190754. }
  190755. else
  190756. {
  190757. sleep (1);
  190758. }
  190759. const ScopedLock sl (startStopLock);
  190760. if (isStarted)
  190761. {
  190762. JUCE_TRY
  190763. {
  190764. callback->audioDeviceIOCallback (const_cast <const float**> (inputBuffers.getData()),
  190765. numInputBuffers,
  190766. outputBuffers,
  190767. numOutputBuffers,
  190768. bufferSizeSamples);
  190769. }
  190770. JUCE_CATCH_EXCEPTION
  190771. totalSamplesOut += bufferSizeSamples;
  190772. }
  190773. else
  190774. {
  190775. for (i = 0; i < numOutputBuffers; ++i)
  190776. if (outputBuffers[i] != 0)
  190777. zeromem (outputBuffers[i], bufferSizeSamples * sizeof (float));
  190778. totalSamplesOut = 0;
  190779. sleep (1);
  190780. }
  190781. }
  190782. }
  190783. };
  190784. class DSoundAudioIODeviceType : public AudioIODeviceType
  190785. {
  190786. public:
  190787. DSoundAudioIODeviceType()
  190788. : AudioIODeviceType (T("DirectSound")),
  190789. hasScanned (false)
  190790. {
  190791. initialiseDSoundFunctions();
  190792. }
  190793. ~DSoundAudioIODeviceType()
  190794. {
  190795. }
  190796. void scanForDevices()
  190797. {
  190798. hasScanned = true;
  190799. outputDeviceNames.clear();
  190800. outputGuids.clear();
  190801. inputDeviceNames.clear();
  190802. inputGuids.clear();
  190803. if (dsDirectSoundEnumerateW != 0)
  190804. {
  190805. dsDirectSoundEnumerateW (outputEnumProcW, this);
  190806. dsDirectSoundCaptureEnumerateW (inputEnumProcW, this);
  190807. }
  190808. }
  190809. const StringArray getDeviceNames (const bool wantInputNames) const
  190810. {
  190811. jassert (hasScanned); // need to call scanForDevices() before doing this
  190812. return wantInputNames ? inputDeviceNames
  190813. : outputDeviceNames;
  190814. }
  190815. int getDefaultDeviceIndex (const bool /*forInput*/) const
  190816. {
  190817. jassert (hasScanned); // need to call scanForDevices() before doing this
  190818. return 0;
  190819. }
  190820. int getIndexOfDevice (AudioIODevice* device, const bool asInput) const
  190821. {
  190822. jassert (hasScanned); // need to call scanForDevices() before doing this
  190823. DSoundAudioIODevice* const d = dynamic_cast <DSoundAudioIODevice*> (device);
  190824. if (d == 0)
  190825. return -1;
  190826. return asInput ? d->inputDeviceIndex
  190827. : d->outputDeviceIndex;
  190828. }
  190829. bool hasSeparateInputsAndOutputs() const { return true; }
  190830. AudioIODevice* createDevice (const String& outputDeviceName,
  190831. const String& inputDeviceName)
  190832. {
  190833. jassert (hasScanned); // need to call scanForDevices() before doing this
  190834. const int outputIndex = outputDeviceNames.indexOf (outputDeviceName);
  190835. const int inputIndex = inputDeviceNames.indexOf (inputDeviceName);
  190836. if (outputIndex >= 0 || inputIndex >= 0)
  190837. return new DSoundAudioIODevice (outputDeviceName.isNotEmpty() ? outputDeviceName
  190838. : inputDeviceName,
  190839. outputIndex, inputIndex);
  190840. return 0;
  190841. }
  190842. juce_UseDebuggingNewOperator
  190843. StringArray outputDeviceNames;
  190844. OwnedArray <GUID> outputGuids;
  190845. StringArray inputDeviceNames;
  190846. OwnedArray <GUID> inputGuids;
  190847. private:
  190848. bool hasScanned;
  190849. BOOL outputEnumProc (LPGUID lpGUID, String desc)
  190850. {
  190851. desc = desc.trim();
  190852. if (desc.isNotEmpty())
  190853. {
  190854. const String origDesc (desc);
  190855. int n = 2;
  190856. while (outputDeviceNames.contains (desc))
  190857. desc = origDesc + T(" (") + String (n++) + T(")");
  190858. outputDeviceNames.add (desc);
  190859. if (lpGUID != 0)
  190860. outputGuids.add (new GUID (*lpGUID));
  190861. else
  190862. outputGuids.add (0);
  190863. }
  190864. return TRUE;
  190865. }
  190866. static BOOL CALLBACK outputEnumProcW (LPGUID lpGUID, LPCWSTR description, LPCWSTR, LPVOID object)
  190867. {
  190868. return ((DSoundAudioIODeviceType*) object)
  190869. ->outputEnumProc (lpGUID, String (description));
  190870. }
  190871. static BOOL CALLBACK outputEnumProcA (LPGUID lpGUID, LPCTSTR description, LPCTSTR, LPVOID object)
  190872. {
  190873. return ((DSoundAudioIODeviceType*) object)
  190874. ->outputEnumProc (lpGUID, String (description));
  190875. }
  190876. BOOL CALLBACK inputEnumProc (LPGUID lpGUID, String desc)
  190877. {
  190878. desc = desc.trim();
  190879. if (desc.isNotEmpty())
  190880. {
  190881. const String origDesc (desc);
  190882. int n = 2;
  190883. while (inputDeviceNames.contains (desc))
  190884. desc = origDesc + T(" (") + String (n++) + T(")");
  190885. inputDeviceNames.add (desc);
  190886. if (lpGUID != 0)
  190887. inputGuids.add (new GUID (*lpGUID));
  190888. else
  190889. inputGuids.add (0);
  190890. }
  190891. return TRUE;
  190892. }
  190893. static BOOL CALLBACK inputEnumProcW (LPGUID lpGUID, LPCWSTR description, LPCWSTR, LPVOID object)
  190894. {
  190895. return ((DSoundAudioIODeviceType*) object)
  190896. ->inputEnumProc (lpGUID, String (description));
  190897. }
  190898. static BOOL CALLBACK inputEnumProcA (LPGUID lpGUID, LPCTSTR description, LPCTSTR, LPVOID object)
  190899. {
  190900. return ((DSoundAudioIODeviceType*) object)
  190901. ->inputEnumProc (lpGUID, String (description));
  190902. }
  190903. DSoundAudioIODeviceType (const DSoundAudioIODeviceType&);
  190904. DSoundAudioIODeviceType& operator= (const DSoundAudioIODeviceType&);
  190905. };
  190906. const String DSoundAudioIODevice::openDevice (const BigInteger& inputChannels,
  190907. const BigInteger& outputChannels,
  190908. double sampleRate_,
  190909. int bufferSizeSamples_)
  190910. {
  190911. closeDevice();
  190912. totalSamplesOut = 0;
  190913. sampleRate = sampleRate_;
  190914. if (bufferSizeSamples_ <= 0)
  190915. bufferSizeSamples_ = 960; // use as a default size if none is set.
  190916. bufferSizeSamples = bufferSizeSamples_ & ~7;
  190917. DSoundAudioIODeviceType dlh;
  190918. dlh.scanForDevices();
  190919. enabledInputs = inputChannels;
  190920. enabledInputs.setRange (inChannels.size(),
  190921. enabledInputs.getHighestBit() + 1 - inChannels.size(),
  190922. false);
  190923. numInputBuffers = enabledInputs.countNumberOfSetBits();
  190924. inputBuffers.calloc (numInputBuffers + 2);
  190925. int i, numIns = 0;
  190926. for (i = 0; i <= enabledInputs.getHighestBit(); i += 2)
  190927. {
  190928. float* left = 0;
  190929. float* right = 0;
  190930. if (enabledInputs[i])
  190931. left = inputBuffers[numIns++] = (float*) juce_calloc ((bufferSizeSamples + 16) * sizeof (float));
  190932. if (enabledInputs[i + 1])
  190933. right = inputBuffers[numIns++] = (float*) juce_calloc ((bufferSizeSamples + 16) * sizeof (float));
  190934. if (left != 0 || right != 0)
  190935. inChans.add (new DSoundInternalInChannel (dlh.inputDeviceNames [inputDeviceIndex],
  190936. dlh.inputGuids [inputDeviceIndex],
  190937. (int) sampleRate, bufferSizeSamples,
  190938. left, right));
  190939. }
  190940. enabledOutputs = outputChannels;
  190941. enabledOutputs.setRange (outChannels.size(),
  190942. enabledOutputs.getHighestBit() + 1 - outChannels.size(),
  190943. false);
  190944. numOutputBuffers = enabledOutputs.countNumberOfSetBits();
  190945. outputBuffers.calloc (numOutputBuffers + 2);
  190946. int numOuts = 0;
  190947. for (i = 0; i <= enabledOutputs.getHighestBit(); i += 2)
  190948. {
  190949. float* left = 0;
  190950. float* right = 0;
  190951. if (enabledOutputs[i])
  190952. left = outputBuffers[numOuts++] = (float*) juce_calloc ((bufferSizeSamples + 16) * sizeof (float));
  190953. if (enabledOutputs[i + 1])
  190954. right = outputBuffers[numOuts++] = (float*) juce_calloc ((bufferSizeSamples + 16) * sizeof (float));
  190955. if (left != 0 || right != 0)
  190956. outChans.add (new DSoundInternalOutChannel (dlh.outputDeviceNames[outputDeviceIndex],
  190957. dlh.outputGuids [outputDeviceIndex],
  190958. (int) sampleRate, bufferSizeSamples,
  190959. left, right));
  190960. }
  190961. String error;
  190962. // boost our priority while opening the devices to try to get better sync between them
  190963. const int oldThreadPri = GetThreadPriority (GetCurrentThread());
  190964. const int oldProcPri = GetPriorityClass (GetCurrentProcess());
  190965. SetThreadPriority (GetCurrentThread(), THREAD_PRIORITY_TIME_CRITICAL);
  190966. SetPriorityClass (GetCurrentProcess(), REALTIME_PRIORITY_CLASS);
  190967. for (i = 0; i < outChans.size(); ++i)
  190968. {
  190969. error = outChans[i]->open();
  190970. if (error.isNotEmpty())
  190971. {
  190972. error = T("Error opening ") + dlh.outputDeviceNames[i]
  190973. + T(": \"") + error + T("\"");
  190974. break;
  190975. }
  190976. }
  190977. if (error.isEmpty())
  190978. {
  190979. for (i = 0; i < inChans.size(); ++i)
  190980. {
  190981. error = inChans[i]->open();
  190982. if (error.isNotEmpty())
  190983. {
  190984. error = T("Error opening ") + dlh.inputDeviceNames[i]
  190985. + T(": \"") + error + T("\"");
  190986. break;
  190987. }
  190988. }
  190989. }
  190990. if (error.isEmpty())
  190991. {
  190992. totalSamplesOut = 0;
  190993. for (i = 0; i < outChans.size(); ++i)
  190994. outChans.getUnchecked(i)->synchronisePosition();
  190995. for (i = 0; i < inChans.size(); ++i)
  190996. inChans.getUnchecked(i)->synchronisePosition();
  190997. startThread (9);
  190998. sleep (10);
  190999. notify();
  191000. }
  191001. else
  191002. {
  191003. log (error);
  191004. }
  191005. SetThreadPriority (GetCurrentThread(), oldThreadPri);
  191006. SetPriorityClass (GetCurrentProcess(), oldProcPri);
  191007. return error;
  191008. }
  191009. AudioIODeviceType* juce_createAudioIODeviceType_DirectSound()
  191010. {
  191011. return new DSoundAudioIODeviceType();
  191012. }
  191013. #undef log
  191014. #endif
  191015. /*** End of inlined file: juce_win32_DirectSound.cpp ***/
  191016. /*** Start of inlined file: juce_win32_WASAPI.cpp ***/
  191017. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  191018. // compiled on its own).
  191019. #if JUCE_INCLUDED_FILE && JUCE_WASAPI
  191020. #if 1
  191021. const String getAudioErrorDesc (HRESULT hr)
  191022. {
  191023. const char* e = 0;
  191024. switch (hr)
  191025. {
  191026. case E_POINTER: e = "E_POINTER"; break;
  191027. case E_INVALIDARG: e = "E_INVALIDARG"; break;
  191028. case AUDCLNT_E_NOT_INITIALIZED: e = "AUDCLNT_E_NOT_INITIALIZED"; break;
  191029. case AUDCLNT_E_ALREADY_INITIALIZED: e = "AUDCLNT_E_ALREADY_INITIALIZED"; break;
  191030. case AUDCLNT_E_WRONG_ENDPOINT_TYPE: e = "AUDCLNT_E_WRONG_ENDPOINT_TYPE"; break;
  191031. case AUDCLNT_E_DEVICE_INVALIDATED: e = "AUDCLNT_E_DEVICE_INVALIDATED"; break;
  191032. case AUDCLNT_E_NOT_STOPPED: e = "AUDCLNT_E_NOT_STOPPED"; break;
  191033. case AUDCLNT_E_BUFFER_TOO_LARGE: e = "AUDCLNT_E_BUFFER_TOO_LARGE"; break;
  191034. case AUDCLNT_E_OUT_OF_ORDER: e = "AUDCLNT_E_OUT_OF_ORDER"; break;
  191035. case AUDCLNT_E_UNSUPPORTED_FORMAT: e = "AUDCLNT_E_UNSUPPORTED_FORMAT"; break;
  191036. case AUDCLNT_E_INVALID_SIZE: e = "AUDCLNT_E_INVALID_SIZE"; break;
  191037. case AUDCLNT_E_DEVICE_IN_USE: e = "AUDCLNT_E_DEVICE_IN_USE"; break;
  191038. case AUDCLNT_E_BUFFER_OPERATION_PENDING: e = "AUDCLNT_E_BUFFER_OPERATION_PENDING"; break;
  191039. case AUDCLNT_E_THREAD_NOT_REGISTERED: e = "AUDCLNT_E_THREAD_NOT_REGISTERED"; break;
  191040. case AUDCLNT_E_EXCLUSIVE_MODE_NOT_ALLOWED: e = "AUDCLNT_E_EXCLUSIVE_MODE_NOT_ALLOWED"; break;
  191041. case AUDCLNT_E_ENDPOINT_CREATE_FAILED: e = "AUDCLNT_E_ENDPOINT_CREATE_FAILED"; break;
  191042. case AUDCLNT_E_SERVICE_NOT_RUNNING: e = "AUDCLNT_E_SERVICE_NOT_RUNNING"; break;
  191043. case AUDCLNT_E_EVENTHANDLE_NOT_EXPECTED: e = "AUDCLNT_E_EVENTHANDLE_NOT_EXPECTED"; break;
  191044. case AUDCLNT_E_EXCLUSIVE_MODE_ONLY: e = "AUDCLNT_E_EXCLUSIVE_MODE_ONLY"; break;
  191045. case AUDCLNT_E_BUFDURATION_PERIOD_NOT_EQUAL: e = "AUDCLNT_E_BUFDURATION_PERIOD_NOT_EQUAL"; break;
  191046. case AUDCLNT_E_EVENTHANDLE_NOT_SET: e = "AUDCLNT_E_EVENTHANDLE_NOT_SET"; break;
  191047. case AUDCLNT_E_INCORRECT_BUFFER_SIZE: e = "AUDCLNT_E_INCORRECT_BUFFER_SIZE"; break;
  191048. case AUDCLNT_E_BUFFER_SIZE_ERROR: e = "AUDCLNT_E_BUFFER_SIZE_ERROR"; break;
  191049. case AUDCLNT_S_BUFFER_EMPTY: e = "AUDCLNT_S_BUFFER_EMPTY"; break;
  191050. case AUDCLNT_S_THREAD_ALREADY_REGISTERED: e = "AUDCLNT_S_THREAD_ALREADY_REGISTERED"; break;
  191051. default: return String::toHexString ((int) hr);
  191052. }
  191053. return e;
  191054. }
  191055. #define logFailure(hr) { if (FAILED (hr)) { DBG ("WASAPI FAIL! " + getAudioErrorDesc (hr)); jassertfalse } }
  191056. #define OK(a) wasapi_checkResult(a)
  191057. static bool wasapi_checkResult (HRESULT hr)
  191058. {
  191059. logFailure (hr);
  191060. return SUCCEEDED (hr);
  191061. }
  191062. #else
  191063. #define logFailure(hr) {}
  191064. #define OK(a) SUCCEEDED(a)
  191065. #endif
  191066. static const String wasapi_getDeviceID (IMMDevice* const device)
  191067. {
  191068. String s;
  191069. WCHAR* deviceId = 0;
  191070. if (OK (device->GetId (&deviceId)))
  191071. {
  191072. s = String (deviceId);
  191073. CoTaskMemFree (deviceId);
  191074. }
  191075. return s;
  191076. }
  191077. static EDataFlow wasapi_getDataFlow (IMMDevice* const device)
  191078. {
  191079. EDataFlow flow = eRender;
  191080. ComSmartPtr <IMMEndpoint> endPoint;
  191081. if (OK (device->QueryInterface (__uuidof (IMMEndpoint), (void**) &endPoint)))
  191082. (void) OK (endPoint->GetDataFlow (&flow));
  191083. return flow;
  191084. }
  191085. static int wasapi_refTimeToSamples (const REFERENCE_TIME& t, const double sampleRate) throw()
  191086. {
  191087. return roundDoubleToInt (sampleRate * ((double) t) * 0.0000001);
  191088. }
  191089. static void wasapi_copyWavFormat (WAVEFORMATEXTENSIBLE& dest, const WAVEFORMATEX* const src) throw()
  191090. {
  191091. memcpy (&dest, src, src->wFormatTag == WAVE_FORMAT_EXTENSIBLE ? sizeof (WAVEFORMATEXTENSIBLE)
  191092. : sizeof (WAVEFORMATEX));
  191093. }
  191094. class WASAPIDeviceBase
  191095. {
  191096. public:
  191097. WASAPIDeviceBase (const ComSmartPtr <IMMDevice>& device_, const bool useExclusiveMode_)
  191098. : device (device_),
  191099. sampleRate (0),
  191100. numChannels (0),
  191101. actualNumChannels (0),
  191102. defaultSampleRate (0),
  191103. minBufferSize (0),
  191104. defaultBufferSize (0),
  191105. latencySamples (0),
  191106. useExclusiveMode (useExclusiveMode_)
  191107. {
  191108. clientEvent = CreateEvent (0, false, false, _T("JuceWASAPI"));
  191109. ComSmartPtr <IAudioClient> tempClient (createClient());
  191110. if (tempClient == 0)
  191111. return;
  191112. REFERENCE_TIME defaultPeriod, minPeriod;
  191113. if (! OK (tempClient->GetDevicePeriod (&defaultPeriod, &minPeriod)))
  191114. return;
  191115. WAVEFORMATEX* mixFormat = 0;
  191116. if (! OK (tempClient->GetMixFormat (&mixFormat)))
  191117. return;
  191118. WAVEFORMATEXTENSIBLE format;
  191119. wasapi_copyWavFormat (format, mixFormat);
  191120. CoTaskMemFree (mixFormat);
  191121. actualNumChannels = numChannels = format.Format.nChannels;
  191122. defaultSampleRate = format.Format.nSamplesPerSec;
  191123. minBufferSize = wasapi_refTimeToSamples (minPeriod, defaultSampleRate);
  191124. defaultBufferSize = wasapi_refTimeToSamples (defaultPeriod, defaultSampleRate);
  191125. FloatElementComparator<double> comparator;
  191126. rates.addSorted (comparator, defaultSampleRate);
  191127. static const double ratesToTest[] = { 44100.0, 48000.0, 88200.0, 96000.0 };
  191128. for (int i = 0; i < numElementsInArray (ratesToTest); ++i)
  191129. {
  191130. if (ratesToTest[i] == defaultSampleRate)
  191131. continue;
  191132. format.Format.nSamplesPerSec = roundDoubleToInt (ratesToTest[i]);
  191133. if (SUCCEEDED (tempClient->IsFormatSupported (useExclusiveMode ? AUDCLNT_SHAREMODE_EXCLUSIVE : AUDCLNT_SHAREMODE_SHARED,
  191134. (WAVEFORMATEX*) &format, 0)))
  191135. if (! rates.contains (ratesToTest[i]))
  191136. rates.addSorted (comparator, ratesToTest[i]);
  191137. }
  191138. }
  191139. ~WASAPIDeviceBase()
  191140. {
  191141. device = 0;
  191142. CloseHandle (clientEvent);
  191143. }
  191144. bool isOk() const throw() { return defaultBufferSize > 0 && defaultSampleRate > 0; }
  191145. bool openClient (const double newSampleRate, const BigInteger& newChannels)
  191146. {
  191147. sampleRate = newSampleRate;
  191148. channels = newChannels;
  191149. channels.setRange (actualNumChannels, channels.getHighestBit() + 1 - actualNumChannels, false);
  191150. numChannels = channels.getHighestBit() + 1;
  191151. if (numChannels == 0)
  191152. return true;
  191153. client = createClient();
  191154. if (client != 0
  191155. && (tryInitialisingWithFormat (true, 4) || tryInitialisingWithFormat (false, 4)
  191156. || tryInitialisingWithFormat (false, 3) || tryInitialisingWithFormat (false, 2)))
  191157. {
  191158. channelMaps.clear();
  191159. for (int i = 0; i <= channels.getHighestBit(); ++i)
  191160. if (channels[i])
  191161. channelMaps.add (i);
  191162. REFERENCE_TIME latency;
  191163. if (OK (client->GetStreamLatency (&latency)))
  191164. latencySamples = wasapi_refTimeToSamples (latency, sampleRate);
  191165. (void) OK (client->GetBufferSize (&actualBufferSize));
  191166. return OK (client->SetEventHandle (clientEvent));
  191167. }
  191168. return false;
  191169. }
  191170. void closeClient()
  191171. {
  191172. if (client != 0)
  191173. client->Stop();
  191174. client = 0;
  191175. ResetEvent (clientEvent);
  191176. }
  191177. ComSmartPtr <IMMDevice> device;
  191178. ComSmartPtr <IAudioClient> client;
  191179. double sampleRate, defaultSampleRate;
  191180. int numChannels, actualNumChannels;
  191181. int minBufferSize, defaultBufferSize, latencySamples;
  191182. const bool useExclusiveMode;
  191183. Array <double> rates;
  191184. HANDLE clientEvent;
  191185. BigInteger channels;
  191186. AudioDataConverters::DataFormat dataFormat;
  191187. Array <int> channelMaps;
  191188. UINT32 actualBufferSize;
  191189. int bytesPerSample;
  191190. private:
  191191. const ComSmartPtr <IAudioClient> createClient()
  191192. {
  191193. ComSmartPtr <IAudioClient> client;
  191194. if (device != 0)
  191195. {
  191196. HRESULT hr = device->Activate (__uuidof (IAudioClient), CLSCTX_INPROC_SERVER, 0, (void**) &client);
  191197. logFailure (hr);
  191198. }
  191199. return client;
  191200. }
  191201. bool tryInitialisingWithFormat (const bool useFloat, const int bytesPerSampleToTry)
  191202. {
  191203. WAVEFORMATEXTENSIBLE format;
  191204. zerostruct (format);
  191205. if (numChannels <= 2 && bytesPerSampleToTry <= 2)
  191206. {
  191207. format.Format.wFormatTag = WAVE_FORMAT_PCM;
  191208. }
  191209. else
  191210. {
  191211. format.Format.wFormatTag = WAVE_FORMAT_EXTENSIBLE;
  191212. format.Format.cbSize = sizeof (WAVEFORMATEXTENSIBLE) - sizeof (WAVEFORMATEX);
  191213. }
  191214. format.Format.nSamplesPerSec = roundDoubleToInt (sampleRate);
  191215. format.Format.nChannels = (WORD) numChannels;
  191216. format.Format.wBitsPerSample = (WORD) (8 * bytesPerSampleToTry);
  191217. format.Format.nAvgBytesPerSec = (DWORD) (format.Format.nSamplesPerSec * numChannels * bytesPerSampleToTry);
  191218. format.Format.nBlockAlign = (WORD) (numChannels * bytesPerSampleToTry);
  191219. format.SubFormat = useFloat ? KSDATAFORMAT_SUBTYPE_IEEE_FLOAT : KSDATAFORMAT_SUBTYPE_PCM;
  191220. format.Samples.wValidBitsPerSample = format.Format.wBitsPerSample;
  191221. switch (numChannels)
  191222. {
  191223. case 1: format.dwChannelMask = SPEAKER_FRONT_CENTER; break;
  191224. case 2: format.dwChannelMask = SPEAKER_FRONT_LEFT | SPEAKER_FRONT_RIGHT; break;
  191225. case 4: format.dwChannelMask = SPEAKER_FRONT_LEFT | SPEAKER_FRONT_RIGHT | SPEAKER_BACK_LEFT | SPEAKER_BACK_RIGHT; break;
  191226. case 6: format.dwChannelMask = SPEAKER_FRONT_LEFT | SPEAKER_FRONT_RIGHT | SPEAKER_FRONT_CENTER | SPEAKER_LOW_FREQUENCY | SPEAKER_BACK_LEFT | SPEAKER_BACK_RIGHT; break;
  191227. 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;
  191228. default: break;
  191229. }
  191230. WAVEFORMATEXTENSIBLE* nearestFormat = 0;
  191231. HRESULT hr = client->IsFormatSupported (useExclusiveMode ? AUDCLNT_SHAREMODE_EXCLUSIVE : AUDCLNT_SHAREMODE_SHARED,
  191232. (WAVEFORMATEX*) &format, useExclusiveMode ? 0 : (WAVEFORMATEX**) &nearestFormat);
  191233. logFailure (hr);
  191234. if (hr == S_FALSE && format.Format.nSamplesPerSec == nearestFormat->Format.nSamplesPerSec)
  191235. {
  191236. wasapi_copyWavFormat (format, (WAVEFORMATEX*) nearestFormat);
  191237. hr = S_OK;
  191238. }
  191239. CoTaskMemFree (nearestFormat);
  191240. REFERENCE_TIME defaultPeriod = 0, minPeriod = 0;
  191241. if (useExclusiveMode)
  191242. OK (client->GetDevicePeriod (&defaultPeriod, &minPeriod));
  191243. GUID session;
  191244. if (hr == S_OK
  191245. && OK (client->Initialize (useExclusiveMode ? AUDCLNT_SHAREMODE_EXCLUSIVE : AUDCLNT_SHAREMODE_SHARED,
  191246. AUDCLNT_STREAMFLAGS_EVENTCALLBACK,
  191247. defaultPeriod, defaultPeriod, (WAVEFORMATEX*) &format, &session)))
  191248. {
  191249. actualNumChannels = format.Format.nChannels;
  191250. const bool isFloat = format.Format.wFormatTag == WAVE_FORMAT_EXTENSIBLE && format.SubFormat == KSDATAFORMAT_SUBTYPE_IEEE_FLOAT;
  191251. bytesPerSample = format.Format.wBitsPerSample / 8;
  191252. dataFormat = isFloat ? AudioDataConverters::float32LE
  191253. : (bytesPerSample == 4 ? AudioDataConverters::int32LE
  191254. : ((bytesPerSample == 3 ? AudioDataConverters::int24LE
  191255. : AudioDataConverters::int16LE)));
  191256. return true;
  191257. }
  191258. return false;
  191259. }
  191260. };
  191261. class WASAPIInputDevice : public WASAPIDeviceBase
  191262. {
  191263. public:
  191264. WASAPIInputDevice (const ComSmartPtr <IMMDevice>& device_, const bool useExclusiveMode_)
  191265. : WASAPIDeviceBase (device_, useExclusiveMode_),
  191266. reservoir (1, 1)
  191267. {
  191268. }
  191269. ~WASAPIInputDevice()
  191270. {
  191271. close();
  191272. }
  191273. bool open (const double newSampleRate, const BigInteger& newChannels)
  191274. {
  191275. reservoirSize = 0;
  191276. reservoirCapacity = 16384;
  191277. reservoir.setSize (actualNumChannels * reservoirCapacity * sizeof (float));
  191278. return openClient (newSampleRate, newChannels)
  191279. && (numChannels == 0 || OK (client->GetService (__uuidof (IAudioCaptureClient), (void**) &captureClient)));
  191280. }
  191281. void close()
  191282. {
  191283. closeClient();
  191284. captureClient = 0;
  191285. reservoir.setSize (0);
  191286. }
  191287. void copyBuffers (float** destBuffers, int numDestBuffers, int bufferSize, Thread& thread)
  191288. {
  191289. if (numChannels <= 0)
  191290. return;
  191291. int offset = 0;
  191292. while (bufferSize > 0)
  191293. {
  191294. if (reservoirSize > 0) // There's stuff in the reservoir, so use that...
  191295. {
  191296. const int samplesToDo = jmin (bufferSize, (int) reservoirSize);
  191297. for (int i = 0; i < numDestBuffers; ++i)
  191298. {
  191299. float* const dest = destBuffers[i] + offset;
  191300. const int srcChan = channelMaps.getUnchecked(i);
  191301. switch (dataFormat)
  191302. {
  191303. case AudioDataConverters::float32LE:
  191304. AudioDataConverters::convertFloat32LEToFloat (((uint8*) reservoir.getData()) + 4 * srcChan, dest, samplesToDo, 4 * actualNumChannels);
  191305. break;
  191306. case AudioDataConverters::int32LE:
  191307. AudioDataConverters::convertInt32LEToFloat (((uint8*) reservoir.getData()) + 4 * srcChan, dest, samplesToDo, 4 * actualNumChannels);
  191308. break;
  191309. case AudioDataConverters::int24LE:
  191310. AudioDataConverters::convertInt24LEToFloat (((uint8*) reservoir.getData()) + 3 * srcChan, dest, samplesToDo, 3 * actualNumChannels);
  191311. break;
  191312. case AudioDataConverters::int16LE:
  191313. AudioDataConverters::convertInt16LEToFloat (((uint8*) reservoir.getData()) + 2 * srcChan, dest, samplesToDo, 2 * actualNumChannels);
  191314. break;
  191315. default: jassertfalse; break;
  191316. }
  191317. }
  191318. bufferSize -= samplesToDo;
  191319. offset += samplesToDo;
  191320. reservoirSize -= samplesToDo;
  191321. }
  191322. else
  191323. {
  191324. UINT32 packetLength = 0;
  191325. if (! OK (captureClient->GetNextPacketSize (&packetLength)))
  191326. break;
  191327. if (packetLength == 0)
  191328. {
  191329. if (thread.threadShouldExit())
  191330. break;
  191331. Thread::sleep (1);
  191332. continue;
  191333. }
  191334. uint8* inputData = 0;
  191335. UINT32 numSamplesAvailable;
  191336. DWORD flags;
  191337. if (OK (captureClient->GetBuffer (&inputData, &numSamplesAvailable, &flags, 0, 0)))
  191338. {
  191339. const int samplesToDo = jmin (bufferSize, (int) numSamplesAvailable);
  191340. for (int i = 0; i < numDestBuffers; ++i)
  191341. {
  191342. float* const dest = destBuffers[i] + offset;
  191343. const int srcChan = channelMaps.getUnchecked(i);
  191344. switch (dataFormat)
  191345. {
  191346. case AudioDataConverters::float32LE:
  191347. AudioDataConverters::convertFloat32LEToFloat (inputData + 4 * srcChan, dest, samplesToDo, 4 * actualNumChannels);
  191348. break;
  191349. case AudioDataConverters::int32LE:
  191350. AudioDataConverters::convertInt32LEToFloat (inputData + 4 * srcChan, dest, samplesToDo, 4 * actualNumChannels);
  191351. break;
  191352. case AudioDataConverters::int24LE:
  191353. AudioDataConverters::convertInt24LEToFloat (inputData + 3 * srcChan, dest, samplesToDo, 3 * actualNumChannels);
  191354. break;
  191355. case AudioDataConverters::int16LE:
  191356. AudioDataConverters::convertInt16LEToFloat (inputData + 2 * srcChan, dest, samplesToDo, 2 * actualNumChannels);
  191357. break;
  191358. default: jassertfalse; break;
  191359. }
  191360. }
  191361. bufferSize -= samplesToDo;
  191362. offset += samplesToDo;
  191363. if (samplesToDo < (int) numSamplesAvailable)
  191364. {
  191365. reservoirSize = jmin ((int) (numSamplesAvailable - samplesToDo), reservoirCapacity);
  191366. memcpy ((uint8*) reservoir.getData(), inputData + bytesPerSample * actualNumChannels * samplesToDo,
  191367. bytesPerSample * actualNumChannels * reservoirSize);
  191368. }
  191369. captureClient->ReleaseBuffer (numSamplesAvailable);
  191370. }
  191371. }
  191372. }
  191373. }
  191374. ComSmartPtr <IAudioCaptureClient> captureClient;
  191375. MemoryBlock reservoir;
  191376. int reservoirSize, reservoirCapacity;
  191377. };
  191378. class WASAPIOutputDevice : public WASAPIDeviceBase
  191379. {
  191380. public:
  191381. WASAPIOutputDevice (const ComSmartPtr <IMMDevice>& device_, const bool useExclusiveMode_)
  191382. : WASAPIDeviceBase (device_, useExclusiveMode_)
  191383. {
  191384. }
  191385. ~WASAPIOutputDevice()
  191386. {
  191387. close();
  191388. }
  191389. bool open (const double newSampleRate, const BigInteger& newChannels)
  191390. {
  191391. return openClient (newSampleRate, newChannels)
  191392. && (numChannels == 0 || OK (client->GetService (__uuidof (IAudioRenderClient), (void**) &renderClient)));
  191393. }
  191394. void close()
  191395. {
  191396. closeClient();
  191397. renderClient = 0;
  191398. }
  191399. void copyBuffers (const float** const srcBuffers, const int numSrcBuffers, int bufferSize, Thread& thread)
  191400. {
  191401. if (numChannels <= 0)
  191402. return;
  191403. int offset = 0;
  191404. while (bufferSize > 0)
  191405. {
  191406. UINT32 padding = 0;
  191407. if (! OK (client->GetCurrentPadding (&padding)))
  191408. return;
  191409. int samplesToDo = useExclusiveMode ? bufferSize
  191410. : jmin ((int) (actualBufferSize - padding), bufferSize);
  191411. if (samplesToDo <= 0)
  191412. {
  191413. if (thread.threadShouldExit())
  191414. break;
  191415. Thread::sleep (0);
  191416. continue;
  191417. }
  191418. uint8* outputData = 0;
  191419. if (OK (renderClient->GetBuffer (samplesToDo, &outputData)))
  191420. {
  191421. for (int i = 0; i < numSrcBuffers; ++i)
  191422. {
  191423. const float* const source = srcBuffers[i] + offset;
  191424. const int destChan = channelMaps.getUnchecked(i);
  191425. switch (dataFormat)
  191426. {
  191427. case AudioDataConverters::float32LE:
  191428. AudioDataConverters::convertFloatToFloat32LE (source, outputData + 4 * destChan, samplesToDo, 4 * actualNumChannels);
  191429. break;
  191430. case AudioDataConverters::int32LE:
  191431. AudioDataConverters::convertFloatToInt32LE (source, outputData + 4 * destChan, samplesToDo, 4 * actualNumChannels);
  191432. break;
  191433. case AudioDataConverters::int24LE:
  191434. AudioDataConverters::convertFloatToInt24LE (source, outputData + 3 * destChan, samplesToDo, 3 * actualNumChannels);
  191435. break;
  191436. case AudioDataConverters::int16LE:
  191437. AudioDataConverters::convertFloatToInt16LE (source, outputData + 2 * destChan, samplesToDo, 2 * actualNumChannels);
  191438. break;
  191439. default: jassertfalse; break;
  191440. }
  191441. }
  191442. renderClient->ReleaseBuffer (samplesToDo, 0);
  191443. offset += samplesToDo;
  191444. bufferSize -= samplesToDo;
  191445. }
  191446. }
  191447. }
  191448. ComSmartPtr <IAudioRenderClient> renderClient;
  191449. };
  191450. class WASAPIAudioIODevice : public AudioIODevice,
  191451. public Thread
  191452. {
  191453. public:
  191454. WASAPIAudioIODevice (const String& deviceName,
  191455. const String& outputDeviceId_,
  191456. const String& inputDeviceId_,
  191457. const bool useExclusiveMode_)
  191458. : AudioIODevice (deviceName, "Windows Audio"),
  191459. Thread ("Juce WASAPI"),
  191460. isOpen_ (false),
  191461. isStarted (false),
  191462. outputDevice (0),
  191463. outputDeviceId (outputDeviceId_),
  191464. inputDevice (0),
  191465. inputDeviceId (inputDeviceId_),
  191466. useExclusiveMode (useExclusiveMode_),
  191467. currentBufferSizeSamples (0),
  191468. currentSampleRate (0),
  191469. callback (0)
  191470. {
  191471. }
  191472. ~WASAPIAudioIODevice()
  191473. {
  191474. close();
  191475. deleteAndZero (inputDevice);
  191476. deleteAndZero (outputDevice);
  191477. }
  191478. bool initialise()
  191479. {
  191480. double defaultSampleRateIn = 0, defaultSampleRateOut = 0;
  191481. int minBufferSizeIn = 0, defaultBufferSizeIn = 0, minBufferSizeOut = 0, defaultBufferSizeOut = 0;
  191482. latencyIn = latencyOut = 0;
  191483. Array <double> ratesIn, ratesOut;
  191484. if (createDevices())
  191485. {
  191486. jassert (inputDevice != 0 || outputDevice != 0);
  191487. if (inputDevice != 0 && outputDevice != 0)
  191488. {
  191489. defaultSampleRate = jmin (inputDevice->defaultSampleRate, outputDevice->defaultSampleRate);
  191490. minBufferSize = jmin (inputDevice->minBufferSize, outputDevice->minBufferSize);
  191491. defaultBufferSize = jmax (inputDevice->defaultBufferSize, outputDevice->defaultBufferSize);
  191492. sampleRates = inputDevice->rates;
  191493. sampleRates.removeValuesNotIn (outputDevice->rates);
  191494. }
  191495. else
  191496. {
  191497. WASAPIDeviceBase* const d = inputDevice != 0 ? (WASAPIDeviceBase*) inputDevice : (WASAPIDeviceBase*) outputDevice;
  191498. defaultSampleRate = d->defaultSampleRate;
  191499. minBufferSize = d->minBufferSize;
  191500. defaultBufferSize = d->defaultBufferSize;
  191501. sampleRates = d->rates;
  191502. }
  191503. IntegerElementComparator<int> comparator;
  191504. bufferSizes.addSorted (comparator, defaultBufferSize);
  191505. if (minBufferSize != defaultBufferSize)
  191506. bufferSizes.addSorted (comparator, minBufferSize);
  191507. int n = 64;
  191508. for (int i = 0; i < 40; ++i)
  191509. {
  191510. if (n >= minBufferSize && n <= 2048 && ! bufferSizes.contains (n))
  191511. bufferSizes.addSorted (comparator, n);
  191512. n += (n < 512) ? 32 : (n < 1024 ? 64 : 128);
  191513. }
  191514. return true;
  191515. }
  191516. return false;
  191517. }
  191518. const StringArray getOutputChannelNames()
  191519. {
  191520. StringArray outChannels;
  191521. if (outputDevice != 0)
  191522. for (int i = 1; i <= outputDevice->actualNumChannels; ++i)
  191523. outChannels.add ("Output channel " + String (i));
  191524. return outChannels;
  191525. }
  191526. const StringArray getInputChannelNames()
  191527. {
  191528. StringArray inChannels;
  191529. if (inputDevice != 0)
  191530. for (int i = 1; i <= inputDevice->actualNumChannels; ++i)
  191531. inChannels.add ("Input channel " + String (i));
  191532. return inChannels;
  191533. }
  191534. int getNumSampleRates() { return sampleRates.size(); }
  191535. double getSampleRate (int index) { return sampleRates [index]; }
  191536. int getNumBufferSizesAvailable() { return bufferSizes.size(); }
  191537. int getBufferSizeSamples (int index) { return bufferSizes [index]; }
  191538. int getDefaultBufferSize() { return defaultBufferSize; }
  191539. int getCurrentBufferSizeSamples() { return currentBufferSizeSamples; }
  191540. double getCurrentSampleRate() { return currentSampleRate; }
  191541. int getCurrentBitDepth() { return 32; }
  191542. int getOutputLatencyInSamples() { return latencyOut; }
  191543. int getInputLatencyInSamples() { return latencyIn; }
  191544. const BigInteger getActiveOutputChannels() const { return outputDevice != 0 ? outputDevice->channels : BigInteger(); }
  191545. const BigInteger getActiveInputChannels() const { return inputDevice != 0 ? inputDevice->channels : BigInteger(); }
  191546. const String getLastError() { return lastError; }
  191547. const String open (const BigInteger& inputChannels, const BigInteger& outputChannels,
  191548. double sampleRate, int bufferSizeSamples)
  191549. {
  191550. close();
  191551. lastError = String::empty;
  191552. if (sampleRates.size() == 0 && inputDevice != 0 && outputDevice != 0)
  191553. {
  191554. lastError = "The input and output devices don't share a common sample rate!";
  191555. return lastError;
  191556. }
  191557. currentBufferSizeSamples = bufferSizeSamples <= 0 ? defaultBufferSize : jmax (bufferSizeSamples, minBufferSize);
  191558. currentSampleRate = sampleRate > 0 ? sampleRate : defaultSampleRate;
  191559. if (inputDevice != 0 && ! inputDevice->open (currentSampleRate, inputChannels))
  191560. {
  191561. lastError = "Couldn't open the input device!";
  191562. return lastError;
  191563. }
  191564. if (outputDevice != 0 && ! outputDevice->open (currentSampleRate, outputChannels))
  191565. {
  191566. close();
  191567. lastError = "Couldn't open the output device!";
  191568. return lastError;
  191569. }
  191570. if (inputDevice != 0)
  191571. ResetEvent (inputDevice->clientEvent);
  191572. if (outputDevice != 0)
  191573. ResetEvent (outputDevice->clientEvent);
  191574. startThread (8);
  191575. Thread::sleep (5);
  191576. if (inputDevice != 0 && inputDevice->client != 0)
  191577. {
  191578. latencyIn = inputDevice->latencySamples + inputDevice->actualBufferSize + inputDevice->minBufferSize;
  191579. HRESULT hr = inputDevice->client->Start();
  191580. logFailure (hr); //xxx handle this
  191581. }
  191582. if (outputDevice != 0 && outputDevice->client != 0)
  191583. {
  191584. latencyOut = outputDevice->latencySamples + outputDevice->actualBufferSize + outputDevice->minBufferSize;
  191585. HRESULT hr = outputDevice->client->Start();
  191586. logFailure (hr); //xxx handle this
  191587. }
  191588. isOpen_ = true;
  191589. return lastError;
  191590. }
  191591. void close()
  191592. {
  191593. stop();
  191594. if (inputDevice != 0)
  191595. SetEvent (inputDevice->clientEvent);
  191596. if (outputDevice != 0)
  191597. SetEvent (outputDevice->clientEvent);
  191598. stopThread (5000);
  191599. if (inputDevice != 0)
  191600. inputDevice->close();
  191601. if (outputDevice != 0)
  191602. outputDevice->close();
  191603. isOpen_ = false;
  191604. }
  191605. bool isOpen() { return isOpen_ && isThreadRunning(); }
  191606. bool isPlaying() { return isStarted && isOpen_ && isThreadRunning(); }
  191607. void start (AudioIODeviceCallback* call)
  191608. {
  191609. if (isOpen_ && call != 0 && ! isStarted)
  191610. {
  191611. if (! isThreadRunning())
  191612. {
  191613. // something's gone wrong and the thread's stopped..
  191614. isOpen_ = false;
  191615. return;
  191616. }
  191617. call->audioDeviceAboutToStart (this);
  191618. const ScopedLock sl (startStopLock);
  191619. callback = call;
  191620. isStarted = true;
  191621. }
  191622. }
  191623. void stop()
  191624. {
  191625. if (isStarted)
  191626. {
  191627. AudioIODeviceCallback* const callbackLocal = callback;
  191628. {
  191629. const ScopedLock sl (startStopLock);
  191630. isStarted = false;
  191631. }
  191632. if (callbackLocal != 0)
  191633. callbackLocal->audioDeviceStopped();
  191634. }
  191635. }
  191636. void setMMThreadPriority()
  191637. {
  191638. DynamicLibraryLoader dll ("avrt.dll");
  191639. DynamicLibraryImport (AvSetMmThreadCharacteristics, avSetMmThreadCharacteristics, HANDLE, dll, (LPCTSTR, LPDWORD))
  191640. DynamicLibraryImport (AvSetMmThreadPriority, avSetMmThreadPriority, HANDLE, dll, (HANDLE, AVRT_PRIORITY))
  191641. if (avSetMmThreadCharacteristics != 0 && avSetMmThreadPriority != 0)
  191642. {
  191643. DWORD dummy = 0;
  191644. HANDLE h = avSetMmThreadCharacteristics (_T("Pro Audio"), &dummy);
  191645. if (h != 0)
  191646. avSetMmThreadPriority (h, AVRT_PRIORITY_NORMAL);
  191647. }
  191648. }
  191649. void run()
  191650. {
  191651. setMMThreadPriority();
  191652. const int bufferSize = currentBufferSizeSamples;
  191653. HANDLE events[2];
  191654. int numEvents = 0;
  191655. if (inputDevice != 0)
  191656. events [numEvents++] = inputDevice->clientEvent;
  191657. if (outputDevice != 0)
  191658. events [numEvents++] = outputDevice->clientEvent;
  191659. const int numInputBuffers = getActiveInputChannels().countNumberOfSetBits();
  191660. const int numOutputBuffers = getActiveOutputChannels().countNumberOfSetBits();
  191661. AudioSampleBuffer ins (jmax (1, numInputBuffers), bufferSize + 32);
  191662. AudioSampleBuffer outs (jmax (1, numOutputBuffers), bufferSize + 32);
  191663. float** const inputBuffers = ins.getArrayOfChannels();
  191664. float** const outputBuffers = outs.getArrayOfChannels();
  191665. ins.clear();
  191666. while (! threadShouldExit())
  191667. {
  191668. const DWORD result = useExclusiveMode ? WaitForSingleObject (inputDevice->clientEvent, 1000)
  191669. : WaitForMultipleObjects (numEvents, events, true, 1000);
  191670. if (result == WAIT_TIMEOUT)
  191671. continue;
  191672. if (threadShouldExit())
  191673. break;
  191674. if (inputDevice != 0)
  191675. inputDevice->copyBuffers (inputBuffers, numInputBuffers, bufferSize, *this);
  191676. // Make the callback..
  191677. {
  191678. const ScopedLock sl (startStopLock);
  191679. if (isStarted)
  191680. {
  191681. JUCE_TRY
  191682. {
  191683. callback->audioDeviceIOCallback ((const float**) inputBuffers,
  191684. numInputBuffers,
  191685. outputBuffers,
  191686. numOutputBuffers,
  191687. bufferSize);
  191688. }
  191689. JUCE_CATCH_EXCEPTION
  191690. }
  191691. else
  191692. {
  191693. outs.clear();
  191694. }
  191695. }
  191696. if (useExclusiveMode && WaitForSingleObject (outputDevice->clientEvent, 1000) == WAIT_TIMEOUT)
  191697. continue;
  191698. if (outputDevice != 0)
  191699. outputDevice->copyBuffers ((const float**) outputBuffers, numOutputBuffers, bufferSize, *this);
  191700. }
  191701. }
  191702. juce_UseDebuggingNewOperator
  191703. String outputDeviceId, inputDeviceId;
  191704. String lastError;
  191705. private:
  191706. // Device stats...
  191707. WASAPIInputDevice* inputDevice;
  191708. WASAPIOutputDevice* outputDevice;
  191709. const bool useExclusiveMode;
  191710. double defaultSampleRate;
  191711. int minBufferSize, defaultBufferSize;
  191712. int latencyIn, latencyOut;
  191713. Array <double> sampleRates;
  191714. Array <int> bufferSizes;
  191715. // Active state...
  191716. bool isOpen_, isStarted;
  191717. int currentBufferSizeSamples;
  191718. double currentSampleRate;
  191719. AudioIODeviceCallback* callback;
  191720. CriticalSection startStopLock;
  191721. bool createDevices()
  191722. {
  191723. ComSmartPtr <IMMDeviceEnumerator> enumerator;
  191724. if (! OK (enumerator.CoCreateInstance (__uuidof (MMDeviceEnumerator), CLSCTX_INPROC_SERVER)))
  191725. return false;
  191726. ComSmartPtr <IMMDeviceCollection> deviceCollection;
  191727. if (! OK (enumerator->EnumAudioEndpoints (eAll, DEVICE_STATE_ACTIVE, &deviceCollection)))
  191728. return false;
  191729. UINT32 numDevices = 0;
  191730. if (! OK (deviceCollection->GetCount (&numDevices)))
  191731. return false;
  191732. for (UINT32 i = 0; i < numDevices; ++i)
  191733. {
  191734. ComSmartPtr <IMMDevice> device;
  191735. if (! OK (deviceCollection->Item (i, &device)))
  191736. continue;
  191737. const String deviceId (wasapi_getDeviceID (device));
  191738. if (deviceId.isEmpty())
  191739. continue;
  191740. const EDataFlow flow = wasapi_getDataFlow (device);
  191741. if (deviceId == inputDeviceId && flow == eCapture)
  191742. inputDevice = new WASAPIInputDevice (device, useExclusiveMode);
  191743. else if (deviceId == outputDeviceId && flow == eRender)
  191744. outputDevice = new WASAPIOutputDevice (device, useExclusiveMode);
  191745. }
  191746. return (outputDeviceId.isEmpty() || (outputDevice != 0 && outputDevice->isOk()))
  191747. && (inputDeviceId.isEmpty() || (inputDevice != 0 && inputDevice->isOk()));
  191748. }
  191749. WASAPIAudioIODevice (const WASAPIAudioIODevice&);
  191750. WASAPIAudioIODevice& operator= (const WASAPIAudioIODevice&);
  191751. };
  191752. class WASAPIAudioIODeviceType : public AudioIODeviceType
  191753. {
  191754. public:
  191755. WASAPIAudioIODeviceType()
  191756. : AudioIODeviceType (T("Windows Audio")),
  191757. hasScanned (false)
  191758. {
  191759. }
  191760. ~WASAPIAudioIODeviceType()
  191761. {
  191762. }
  191763. void scanForDevices()
  191764. {
  191765. hasScanned = true;
  191766. outputDeviceNames.clear();
  191767. inputDeviceNames.clear();
  191768. outputDeviceIds.clear();
  191769. inputDeviceIds.clear();
  191770. ComSmartPtr <IMMDeviceEnumerator> enumerator;
  191771. if (! OK (enumerator.CoCreateInstance (__uuidof (MMDeviceEnumerator), CLSCTX_INPROC_SERVER)))
  191772. return;
  191773. const String defaultRenderer = getDefaultEndpoint (enumerator, false);
  191774. const String defaultCapture = getDefaultEndpoint (enumerator, true);
  191775. ComSmartPtr <IMMDeviceCollection> deviceCollection;
  191776. UINT32 numDevices = 0;
  191777. if (! (OK (enumerator->EnumAudioEndpoints (eAll, DEVICE_STATE_ACTIVE, &deviceCollection))
  191778. && OK (deviceCollection->GetCount (&numDevices))))
  191779. return;
  191780. for (UINT32 i = 0; i < numDevices; ++i)
  191781. {
  191782. ComSmartPtr <IMMDevice> device;
  191783. if (! OK (deviceCollection->Item (i, &device)))
  191784. continue;
  191785. const String deviceId (wasapi_getDeviceID (device));
  191786. DWORD state = 0;
  191787. if (! OK (device->GetState (&state)))
  191788. continue;
  191789. if (state != DEVICE_STATE_ACTIVE)
  191790. continue;
  191791. String name;
  191792. {
  191793. ComSmartPtr <IPropertyStore> properties;
  191794. if (! OK (device->OpenPropertyStore (STGM_READ, &properties)))
  191795. continue;
  191796. PROPVARIANT value;
  191797. PropVariantInit (&value);
  191798. if (OK (properties->GetValue (PKEY_Device_FriendlyName, &value)))
  191799. name = value.pwszVal;
  191800. PropVariantClear (&value);
  191801. }
  191802. const EDataFlow flow = wasapi_getDataFlow (device);
  191803. if (flow == eRender)
  191804. {
  191805. const int index = (deviceId == defaultRenderer) ? 0 : -1;
  191806. outputDeviceIds.insert (index, deviceId);
  191807. outputDeviceNames.insert (index, name);
  191808. }
  191809. else if (flow == eCapture)
  191810. {
  191811. const int index = (deviceId == defaultCapture) ? 0 : -1;
  191812. inputDeviceIds.insert (index, deviceId);
  191813. inputDeviceNames.insert (index, name);
  191814. }
  191815. }
  191816. inputDeviceNames.appendNumbersToDuplicates (false, false);
  191817. outputDeviceNames.appendNumbersToDuplicates (false, false);
  191818. }
  191819. const StringArray getDeviceNames (const bool wantInputNames) const
  191820. {
  191821. jassert (hasScanned); // need to call scanForDevices() before doing this
  191822. return wantInputNames ? inputDeviceNames
  191823. : outputDeviceNames;
  191824. }
  191825. int getDefaultDeviceIndex (const bool /*forInput*/) const
  191826. {
  191827. jassert (hasScanned); // need to call scanForDevices() before doing this
  191828. return 0;
  191829. }
  191830. int getIndexOfDevice (AudioIODevice* device, const bool asInput) const
  191831. {
  191832. jassert (hasScanned); // need to call scanForDevices() before doing this
  191833. WASAPIAudioIODevice* const d = dynamic_cast <WASAPIAudioIODevice*> (device);
  191834. return d == 0 ? -1 : (asInput ? inputDeviceIds.indexOf (d->inputDeviceId)
  191835. : outputDeviceIds.indexOf (d->outputDeviceId));
  191836. }
  191837. bool hasSeparateInputsAndOutputs() const { return true; }
  191838. AudioIODevice* createDevice (const String& outputDeviceName,
  191839. const String& inputDeviceName)
  191840. {
  191841. jassert (hasScanned); // need to call scanForDevices() before doing this
  191842. const bool useExclusiveMode = false;
  191843. WASAPIAudioIODevice* d = 0;
  191844. const int outputIndex = outputDeviceNames.indexOf (outputDeviceName);
  191845. const int inputIndex = inputDeviceNames.indexOf (inputDeviceName);
  191846. if (outputIndex >= 0 || inputIndex >= 0)
  191847. {
  191848. d = new WASAPIAudioIODevice (outputDeviceName.isNotEmpty() ? outputDeviceName
  191849. : inputDeviceName,
  191850. outputDeviceIds [outputIndex],
  191851. inputDeviceIds [inputIndex],
  191852. useExclusiveMode);
  191853. if (! d->initialise())
  191854. deleteAndZero (d);
  191855. }
  191856. return d;
  191857. }
  191858. juce_UseDebuggingNewOperator
  191859. StringArray outputDeviceNames, outputDeviceIds;
  191860. StringArray inputDeviceNames, inputDeviceIds;
  191861. private:
  191862. bool hasScanned;
  191863. static const String getDefaultEndpoint (IMMDeviceEnumerator* const enumerator, const bool forCapture)
  191864. {
  191865. String s;
  191866. IMMDevice* dev = 0;
  191867. if (OK (enumerator->GetDefaultAudioEndpoint (forCapture ? eCapture : eRender,
  191868. eMultimedia, &dev)))
  191869. {
  191870. WCHAR* deviceId = 0;
  191871. if (OK (dev->GetId (&deviceId)))
  191872. {
  191873. s = String (deviceId);
  191874. CoTaskMemFree (deviceId);
  191875. }
  191876. dev->Release();
  191877. }
  191878. return s;
  191879. }
  191880. WASAPIAudioIODeviceType (const WASAPIAudioIODeviceType&);
  191881. WASAPIAudioIODeviceType& operator= (const WASAPIAudioIODeviceType&);
  191882. };
  191883. AudioIODeviceType* juce_createAudioIODeviceType_WASAPI()
  191884. {
  191885. return new WASAPIAudioIODeviceType();
  191886. }
  191887. #undef logFailure
  191888. #undef OK
  191889. #endif
  191890. /*** End of inlined file: juce_win32_WASAPI.cpp ***/
  191891. /*** Start of inlined file: juce_win32_CameraDevice.cpp ***/
  191892. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  191893. // compiled on its own).
  191894. #if JUCE_INCLUDED_FILE && JUCE_USE_CAMERA
  191895. class DShowCameraDeviceInteral : public ChangeBroadcaster
  191896. {
  191897. public:
  191898. DShowCameraDeviceInteral (CameraDevice* const owner_,
  191899. const ComSmartPtr <ICaptureGraphBuilder2>& captureGraphBuilder_,
  191900. const ComSmartPtr <IBaseFilter>& filter_,
  191901. int minWidth, int minHeight,
  191902. int maxWidth, int maxHeight)
  191903. : owner (owner_),
  191904. captureGraphBuilder (captureGraphBuilder_),
  191905. filter (filter_),
  191906. ok (false),
  191907. imageNeedsFlipping (false),
  191908. width (0),
  191909. height (0),
  191910. activeUsers (0),
  191911. recordNextFrameTime (false),
  191912. activeImage (0),
  191913. loadingImage (0)
  191914. {
  191915. HRESULT hr = graphBuilder.CoCreateInstance (CLSID_FilterGraph, CLSCTX_INPROC);
  191916. if (FAILED (hr))
  191917. return;
  191918. hr = captureGraphBuilder->SetFiltergraph (graphBuilder);
  191919. if (FAILED (hr))
  191920. return;
  191921. hr = graphBuilder->QueryInterface (IID_IMediaControl, (void**) &mediaControl);
  191922. if (FAILED (hr))
  191923. return;
  191924. {
  191925. ComSmartPtr <IAMStreamConfig> streamConfig;
  191926. hr = captureGraphBuilder->FindInterface (&PIN_CATEGORY_CAPTURE, 0, filter,
  191927. IID_IAMStreamConfig, (void**) &streamConfig);
  191928. if (streamConfig != 0)
  191929. {
  191930. getVideoSizes (streamConfig);
  191931. if (! selectVideoSize (streamConfig, minWidth, minHeight, maxWidth, maxHeight))
  191932. return;
  191933. }
  191934. }
  191935. hr = graphBuilder->AddFilter (filter, _T("Video Capture"));
  191936. if (FAILED (hr))
  191937. return;
  191938. hr = smartTee.CoCreateInstance (CLSID_SmartTee, CLSCTX_INPROC_SERVER);
  191939. if (FAILED (hr))
  191940. return;
  191941. hr = graphBuilder->AddFilter (smartTee, _T("Smart Tee"));
  191942. if (FAILED (hr))
  191943. return;
  191944. if (! connectFilters (filter, smartTee))
  191945. return;
  191946. ComSmartPtr <IBaseFilter> sampleGrabberBase;
  191947. hr = sampleGrabberBase.CoCreateInstance (CLSID_SampleGrabber, CLSCTX_INPROC_SERVER);
  191948. if (FAILED (hr))
  191949. return;
  191950. hr = sampleGrabberBase->QueryInterface (IID_ISampleGrabber, (void**) &sampleGrabber);
  191951. if (FAILED (hr))
  191952. return;
  191953. AM_MEDIA_TYPE mt;
  191954. zerostruct (mt);
  191955. mt.majortype = MEDIATYPE_Video;
  191956. mt.subtype = MEDIASUBTYPE_RGB24;
  191957. mt.formattype = FORMAT_VideoInfo;
  191958. sampleGrabber->SetMediaType (&mt);
  191959. callback = new GrabberCallback (*this);
  191960. sampleGrabber->SetCallback (callback, 1);
  191961. hr = graphBuilder->AddFilter (sampleGrabberBase, _T("Sample Grabber"));
  191962. if (FAILED (hr))
  191963. return;
  191964. ComSmartPtr <IPin> grabberInputPin;
  191965. if (! (getPin (smartTee, PINDIR_OUTPUT, &smartTeeCaptureOutputPin, "capture")
  191966. && getPin (smartTee, PINDIR_OUTPUT, &smartTeePreviewOutputPin, "preview")
  191967. && getPin (sampleGrabberBase, PINDIR_INPUT, &grabberInputPin)))
  191968. return;
  191969. hr = graphBuilder->Connect (smartTeePreviewOutputPin, grabberInputPin);
  191970. if (FAILED (hr))
  191971. return;
  191972. zerostruct (mt);
  191973. hr = sampleGrabber->GetConnectedMediaType (&mt);
  191974. VIDEOINFOHEADER* pVih = (VIDEOINFOHEADER*) (mt.pbFormat);
  191975. width = pVih->bmiHeader.biWidth;
  191976. height = pVih->bmiHeader.biHeight;
  191977. ComSmartPtr <IBaseFilter> nullFilter;
  191978. hr = nullFilter.CoCreateInstance (CLSID_NullRenderer, CLSCTX_INPROC_SERVER);
  191979. hr = graphBuilder->AddFilter (nullFilter, _T("Null Renderer"));
  191980. if (connectFilters (sampleGrabberBase, nullFilter)
  191981. && addGraphToRot())
  191982. {
  191983. activeImage = new Image (Image::RGB, width, height, true);
  191984. loadingImage = new Image (Image::RGB, width, height, true);
  191985. ok = true;
  191986. }
  191987. }
  191988. ~DShowCameraDeviceInteral()
  191989. {
  191990. if (mediaControl != 0)
  191991. mediaControl->Stop();
  191992. removeGraphFromRot();
  191993. for (int i = viewerComps.size(); --i >= 0;)
  191994. ((DShowCaptureViewerComp*) viewerComps.getUnchecked(i))->ownerDeleted();
  191995. callback = 0;
  191996. graphBuilder = 0;
  191997. sampleGrabber = 0;
  191998. mediaControl = 0;
  191999. filter = 0;
  192000. captureGraphBuilder = 0;
  192001. smartTee = 0;
  192002. smartTeePreviewOutputPin = 0;
  192003. smartTeeCaptureOutputPin = 0;
  192004. asfWriter = 0;
  192005. delete activeImage;
  192006. delete loadingImage;
  192007. }
  192008. void addUser()
  192009. {
  192010. if (ok && activeUsers++ == 0)
  192011. mediaControl->Run();
  192012. }
  192013. void removeUser()
  192014. {
  192015. if (ok && --activeUsers == 0)
  192016. mediaControl->Stop();
  192017. }
  192018. void handleFrame (double /*time*/, BYTE* buffer, long /*bufferSize*/)
  192019. {
  192020. if (recordNextFrameTime)
  192021. {
  192022. const double defaultCameraLatency = 0.1;
  192023. firstRecordedTime = Time::getCurrentTime() - RelativeTime (defaultCameraLatency);
  192024. recordNextFrameTime = false;
  192025. ComSmartPtr <IPin> pin;
  192026. if (getPin (filter, PINDIR_OUTPUT, &pin))
  192027. {
  192028. ComSmartPtr <IAMPushSource> pushSource;
  192029. HRESULT hr = pin->QueryInterface (IID_IAMPushSource, (void**) &pushSource);
  192030. if (pushSource != 0)
  192031. {
  192032. REFERENCE_TIME latency = 0;
  192033. hr = pushSource->GetLatency (&latency);
  192034. firstRecordedTime = firstRecordedTime - RelativeTime ((double) latency);
  192035. }
  192036. }
  192037. }
  192038. {
  192039. const int lineStride = width * 3;
  192040. const ScopedLock sl (imageSwapLock);
  192041. {
  192042. const Image::BitmapData destData (*loadingImage, 0, 0, width, height, true);
  192043. for (int i = 0; i < height; ++i)
  192044. memcpy (destData.getLinePointer ((height - 1) - i),
  192045. buffer + lineStride * i,
  192046. lineStride);
  192047. }
  192048. imageNeedsFlipping = true;
  192049. }
  192050. if (listeners.size() > 0)
  192051. callListeners (*loadingImage);
  192052. sendChangeMessage (this);
  192053. }
  192054. void drawCurrentImage (Graphics& g, int x, int y, int w, int h)
  192055. {
  192056. if (imageNeedsFlipping)
  192057. {
  192058. const ScopedLock sl (imageSwapLock);
  192059. swapVariables (loadingImage, activeImage);
  192060. imageNeedsFlipping = false;
  192061. }
  192062. RectanglePlacement rp (RectanglePlacement::centred);
  192063. double dx = 0, dy = 0, dw = width, dh = height;
  192064. rp.applyTo (dx, dy, dw, dh, x, y, w, h);
  192065. const int rx = roundToInt (dx), ry = roundToInt (dy);
  192066. const int rw = roundToInt (dw), rh = roundToInt (dh);
  192067. g.saveState();
  192068. g.excludeClipRegion (Rectangle<int> (rx, ry, rw, rh));
  192069. g.fillAll (Colours::black);
  192070. g.restoreState();
  192071. g.drawImage (activeImage, rx, ry, rw, rh, 0, 0, width, height);
  192072. }
  192073. bool createFileCaptureFilter (const File& file)
  192074. {
  192075. removeFileCaptureFilter();
  192076. file.deleteFile();
  192077. mediaControl->Stop();
  192078. firstRecordedTime = Time();
  192079. recordNextFrameTime = true;
  192080. HRESULT hr = asfWriter.CoCreateInstance (CLSID_WMAsfWriter, CLSCTX_INPROC_SERVER);
  192081. if (SUCCEEDED (hr))
  192082. {
  192083. ComSmartPtr <IFileSinkFilter> fileSink;
  192084. hr = asfWriter->QueryInterface (IID_IFileSinkFilter, (void**) &fileSink);
  192085. if (SUCCEEDED (hr))
  192086. {
  192087. hr = fileSink->SetFileName (file.getFullPathName(), 0);
  192088. if (SUCCEEDED (hr))
  192089. {
  192090. hr = graphBuilder->AddFilter (asfWriter, _T("AsfWriter"));
  192091. if (SUCCEEDED (hr))
  192092. {
  192093. ComSmartPtr <IConfigAsfWriter> asfConfig;
  192094. hr = asfWriter->QueryInterface (IID_IConfigAsfWriter, (void**) &asfConfig);
  192095. asfConfig->SetIndexMode (true);
  192096. ComSmartPtr <IWMProfileManager> profileManager;
  192097. hr = WMCreateProfileManager (&profileManager);
  192098. // This gibberish is the DirectShow profile for a video-only wmv file.
  192099. String prof ("<profile version=\"589824\" storageformat=\"1\" name=\"Quality\" description=\"Quality type for output.\"><streamconfig "
  192100. "majortype=\"{73646976-0000-0010-8000-00AA00389B71}\" streamnumber=\"1\" streamname=\"Video Stream\" inputname=\"Video409\" bitrate=\"894960\" "
  192101. "bufferwindow=\"0\" reliabletransport=\"1\" decodercomplexity=\"AU\" rfc1766langid=\"en-us\"><videomediaprops maxkeyframespacing=\"50000000\" quality=\"90\"/>"
  192102. "<wmmediatype subtype=\"{33564D57-0000-0010-8000-00AA00389B71}\" bfixedsizesamples=\"0\" btemporalcompression=\"1\" lsamplesize=\"0\"> <videoinfoheader "
  192103. "dwbitrate=\"894960\" dwbiterrorrate=\"0\" avgtimeperframe=\"100000\"><rcsource left=\"0\" top=\"0\" right=\"$WIDTH\" bottom=\"$HEIGHT\"/> <rctarget "
  192104. "left=\"0\" top=\"0\" right=\"$WIDTH\" bottom=\"$HEIGHT\"/> <bitmapinfoheader biwidth=\"$WIDTH\" biheight=\"$HEIGHT\" biplanes=\"1\" bibitcount=\"24\" "
  192105. "bicompression=\"WMV3\" bisizeimage=\"0\" bixpelspermeter=\"0\" biypelspermeter=\"0\" biclrused=\"0\" biclrimportant=\"0\"/> "
  192106. "</videoinfoheader></wmmediatype></streamconfig></profile>");
  192107. prof = prof.replace (T("$WIDTH"), String (width))
  192108. .replace (T("$HEIGHT"), String (height));
  192109. ComSmartPtr <IWMProfile> currentProfile;
  192110. hr = profileManager->LoadProfileByData ((const WCHAR*) prof, &currentProfile);
  192111. hr = asfConfig->ConfigureFilterUsingProfile (currentProfile);
  192112. if (SUCCEEDED (hr))
  192113. {
  192114. ComSmartPtr <IPin> asfWriterInputPin;
  192115. if (getPin (asfWriter, PINDIR_INPUT, &asfWriterInputPin, "Video Input 01"))
  192116. {
  192117. hr = graphBuilder->Connect (smartTeeCaptureOutputPin, asfWriterInputPin);
  192118. if (SUCCEEDED (hr)
  192119. && ok && activeUsers > 0
  192120. && SUCCEEDED (mediaControl->Run()))
  192121. {
  192122. return true;
  192123. }
  192124. }
  192125. }
  192126. }
  192127. }
  192128. }
  192129. }
  192130. removeFileCaptureFilter();
  192131. if (ok && activeUsers > 0)
  192132. mediaControl->Run();
  192133. return false;
  192134. }
  192135. void removeFileCaptureFilter()
  192136. {
  192137. mediaControl->Stop();
  192138. if (asfWriter != 0)
  192139. {
  192140. graphBuilder->RemoveFilter (asfWriter);
  192141. asfWriter = 0;
  192142. }
  192143. if (ok && activeUsers > 0)
  192144. mediaControl->Run();
  192145. }
  192146. void addListener (CameraImageListener* listenerToAdd)
  192147. {
  192148. const ScopedLock sl (listenerLock);
  192149. if (listeners.size() == 0)
  192150. addUser();
  192151. listeners.addIfNotAlreadyThere (listenerToAdd);
  192152. }
  192153. void removeListener (CameraImageListener* listenerToRemove)
  192154. {
  192155. const ScopedLock sl (listenerLock);
  192156. listeners.removeValue (listenerToRemove);
  192157. if (listeners.size() == 0)
  192158. removeUser();
  192159. }
  192160. void callListeners (Image& image)
  192161. {
  192162. const ScopedLock sl (listenerLock);
  192163. for (int i = listeners.size(); --i >= 0;)
  192164. {
  192165. CameraImageListener* l = (CameraImageListener*) listeners[i];
  192166. if (l != 0)
  192167. l->imageReceived (image);
  192168. }
  192169. }
  192170. class DShowCaptureViewerComp : public Component,
  192171. public ChangeListener
  192172. {
  192173. public:
  192174. DShowCaptureViewerComp (DShowCameraDeviceInteral* const owner_)
  192175. : owner (owner_)
  192176. {
  192177. setOpaque (true);
  192178. owner->addChangeListener (this);
  192179. owner->addUser();
  192180. owner->viewerComps.add (this);
  192181. setSize (owner_->width, owner_->height);
  192182. }
  192183. ~DShowCaptureViewerComp()
  192184. {
  192185. if (owner != 0)
  192186. {
  192187. owner->viewerComps.removeValue (this);
  192188. owner->removeUser();
  192189. owner->removeChangeListener (this);
  192190. }
  192191. }
  192192. void ownerDeleted()
  192193. {
  192194. owner = 0;
  192195. }
  192196. void paint (Graphics& g)
  192197. {
  192198. g.setColour (Colours::black);
  192199. g.setImageResamplingQuality (Graphics::lowResamplingQuality);
  192200. if (owner != 0)
  192201. owner->drawCurrentImage (g, 0, 0, getWidth(), getHeight());
  192202. else
  192203. g.fillAll (Colours::black);
  192204. }
  192205. void changeListenerCallback (void*)
  192206. {
  192207. repaint();
  192208. }
  192209. private:
  192210. DShowCameraDeviceInteral* owner;
  192211. };
  192212. bool ok;
  192213. int width, height;
  192214. Time firstRecordedTime;
  192215. VoidArray viewerComps;
  192216. private:
  192217. CameraDevice* const owner;
  192218. ComSmartPtr <ICaptureGraphBuilder2> captureGraphBuilder;
  192219. ComSmartPtr <IBaseFilter> filter;
  192220. ComSmartPtr <IBaseFilter> smartTee;
  192221. ComSmartPtr <IGraphBuilder> graphBuilder;
  192222. ComSmartPtr <ISampleGrabber> sampleGrabber;
  192223. ComSmartPtr <IMediaControl> mediaControl;
  192224. ComSmartPtr <IPin> smartTeePreviewOutputPin;
  192225. ComSmartPtr <IPin> smartTeeCaptureOutputPin;
  192226. ComSmartPtr <IBaseFilter> asfWriter;
  192227. int activeUsers;
  192228. Array <int> widths, heights;
  192229. DWORD graphRegistrationID;
  192230. CriticalSection imageSwapLock;
  192231. bool imageNeedsFlipping;
  192232. Image* loadingImage;
  192233. Image* activeImage;
  192234. bool recordNextFrameTime;
  192235. void getVideoSizes (IAMStreamConfig* const streamConfig)
  192236. {
  192237. widths.clear();
  192238. heights.clear();
  192239. int count = 0, size = 0;
  192240. streamConfig->GetNumberOfCapabilities (&count, &size);
  192241. if (size == sizeof (VIDEO_STREAM_CONFIG_CAPS))
  192242. {
  192243. for (int i = 0; i < count; ++i)
  192244. {
  192245. VIDEO_STREAM_CONFIG_CAPS scc;
  192246. AM_MEDIA_TYPE* config;
  192247. HRESULT hr = streamConfig->GetStreamCaps (i, &config, (BYTE*) &scc);
  192248. if (SUCCEEDED (hr))
  192249. {
  192250. const int w = scc.InputSize.cx;
  192251. const int h = scc.InputSize.cy;
  192252. bool duplicate = false;
  192253. for (int j = widths.size(); --j >= 0;)
  192254. {
  192255. if (w == widths.getUnchecked (j) && h == heights.getUnchecked (j))
  192256. {
  192257. duplicate = true;
  192258. break;
  192259. }
  192260. }
  192261. if (! duplicate)
  192262. {
  192263. DBG ("Camera capture size: " + String (w) + ", " + String (h));
  192264. widths.add (w);
  192265. heights.add (h);
  192266. }
  192267. deleteMediaType (config);
  192268. }
  192269. }
  192270. }
  192271. }
  192272. bool selectVideoSize (IAMStreamConfig* const streamConfig,
  192273. const int minWidth, const int minHeight,
  192274. const int maxWidth, const int maxHeight)
  192275. {
  192276. int count = 0, size = 0, bestArea = 0, bestIndex = -1;
  192277. streamConfig->GetNumberOfCapabilities (&count, &size);
  192278. if (size == sizeof (VIDEO_STREAM_CONFIG_CAPS))
  192279. {
  192280. AM_MEDIA_TYPE* config;
  192281. VIDEO_STREAM_CONFIG_CAPS scc;
  192282. for (int i = 0; i < count; ++i)
  192283. {
  192284. HRESULT hr = streamConfig->GetStreamCaps (i, &config, (BYTE*) &scc);
  192285. if (SUCCEEDED (hr))
  192286. {
  192287. if (scc.InputSize.cx >= minWidth
  192288. && scc.InputSize.cy >= minHeight
  192289. && scc.InputSize.cx <= maxWidth
  192290. && scc.InputSize.cy <= maxHeight)
  192291. {
  192292. int area = scc.InputSize.cx * scc.InputSize.cy;
  192293. if (area > bestArea)
  192294. {
  192295. bestIndex = i;
  192296. bestArea = area;
  192297. }
  192298. }
  192299. deleteMediaType (config);
  192300. }
  192301. }
  192302. if (bestIndex >= 0)
  192303. {
  192304. HRESULT hr = streamConfig->GetStreamCaps (bestIndex, &config, (BYTE*) &scc);
  192305. hr = streamConfig->SetFormat (config);
  192306. deleteMediaType (config);
  192307. return SUCCEEDED (hr);
  192308. }
  192309. }
  192310. return false;
  192311. }
  192312. static bool getPin (IBaseFilter* filter, const PIN_DIRECTION wantedDirection, IPin** result, const char* pinName = 0)
  192313. {
  192314. ComSmartPtr <IEnumPins> enumerator;
  192315. ComSmartPtr <IPin> pin;
  192316. filter->EnumPins (&enumerator);
  192317. while (enumerator->Next (1, &pin, 0) == S_OK)
  192318. {
  192319. PIN_DIRECTION dir;
  192320. pin->QueryDirection (&dir);
  192321. if (wantedDirection == dir)
  192322. {
  192323. PIN_INFO info;
  192324. zerostruct (info);
  192325. pin->QueryPinInfo (&info);
  192326. if (pinName == 0 || String (pinName).equalsIgnoreCase (String (info.achName)))
  192327. {
  192328. pin.p->AddRef();
  192329. *result = pin;
  192330. return true;
  192331. }
  192332. }
  192333. }
  192334. return false;
  192335. }
  192336. bool connectFilters (IBaseFilter* const first, IBaseFilter* const second) const
  192337. {
  192338. ComSmartPtr <IPin> in, out;
  192339. return getPin (first, PINDIR_OUTPUT, &out)
  192340. && getPin (second, PINDIR_INPUT, &in)
  192341. && SUCCEEDED (graphBuilder->Connect (out, in));
  192342. }
  192343. bool addGraphToRot()
  192344. {
  192345. ComSmartPtr <IRunningObjectTable> rot;
  192346. if (FAILED (GetRunningObjectTable (0, &rot)))
  192347. return false;
  192348. ComSmartPtr <IMoniker> moniker;
  192349. WCHAR buffer[128];
  192350. HRESULT hr = CreateItemMoniker (_T("!"), buffer, &moniker);
  192351. if (FAILED (hr))
  192352. return false;
  192353. graphRegistrationID = 0;
  192354. return SUCCEEDED (rot->Register (0, graphBuilder, moniker, &graphRegistrationID));
  192355. }
  192356. void removeGraphFromRot()
  192357. {
  192358. ComSmartPtr <IRunningObjectTable> rot;
  192359. if (SUCCEEDED (GetRunningObjectTable (0, &rot)))
  192360. rot->Revoke (graphRegistrationID);
  192361. }
  192362. static void deleteMediaType (AM_MEDIA_TYPE* const pmt)
  192363. {
  192364. if (pmt->cbFormat != 0)
  192365. CoTaskMemFree ((PVOID) pmt->pbFormat);
  192366. if (pmt->pUnk != 0)
  192367. pmt->pUnk->Release();
  192368. CoTaskMemFree (pmt);
  192369. }
  192370. class GrabberCallback : public ISampleGrabberCB
  192371. {
  192372. public:
  192373. GrabberCallback (DShowCameraDeviceInteral& owner_)
  192374. : owner (owner_)
  192375. {
  192376. }
  192377. HRESULT __stdcall QueryInterface (REFIID id, void** result)
  192378. {
  192379. if (id == IID_IUnknown)
  192380. *result = dynamic_cast <IUnknown*> (this);
  192381. else if (id == IID_ISampleGrabberCB)
  192382. *result = dynamic_cast <ISampleGrabberCB*> (this);
  192383. else
  192384. {
  192385. *result = 0;
  192386. return E_NOINTERFACE;
  192387. }
  192388. AddRef();
  192389. return S_OK;
  192390. }
  192391. ULONG __stdcall AddRef() { return ++refCount; }
  192392. ULONG __stdcall Release() { const int r = --refCount; if (r == 0) delete this; return r; }
  192393. STDMETHODIMP SampleCB (double /*SampleTime*/, IMediaSample* /*pSample*/)
  192394. {
  192395. return E_FAIL;
  192396. }
  192397. STDMETHODIMP BufferCB (double time, BYTE* buffer, long bufferSize)
  192398. {
  192399. owner.handleFrame (time, buffer, bufferSize);
  192400. return S_OK;
  192401. }
  192402. private:
  192403. int refCount;
  192404. DShowCameraDeviceInteral& owner;
  192405. GrabberCallback (const GrabberCallback&);
  192406. GrabberCallback& operator= (const GrabberCallback&);
  192407. };
  192408. ComSmartPtr <GrabberCallback> callback;
  192409. VoidArray listeners;
  192410. CriticalSection listenerLock;
  192411. DShowCameraDeviceInteral (const DShowCameraDeviceInteral&);
  192412. DShowCameraDeviceInteral& operator= (const DShowCameraDeviceInteral&);
  192413. };
  192414. CameraDevice::CameraDevice (const String& name_, int /*index*/)
  192415. : name (name_)
  192416. {
  192417. isRecording = false;
  192418. }
  192419. CameraDevice::~CameraDevice()
  192420. {
  192421. stopRecording();
  192422. delete (DShowCameraDeviceInteral*) internal;
  192423. internal = 0;
  192424. }
  192425. Component* CameraDevice::createViewerComponent()
  192426. {
  192427. return new DShowCameraDeviceInteral::DShowCaptureViewerComp ((DShowCameraDeviceInteral*) internal);
  192428. }
  192429. const String CameraDevice::getFileExtension()
  192430. {
  192431. return ".wmv";
  192432. }
  192433. void CameraDevice::startRecordingToFile (const File& file, int quality)
  192434. {
  192435. stopRecording();
  192436. DShowCameraDeviceInteral* const d = (DShowCameraDeviceInteral*) internal;
  192437. d->addUser();
  192438. isRecording = d->createFileCaptureFilter (file);
  192439. }
  192440. const Time CameraDevice::getTimeOfFirstRecordedFrame() const
  192441. {
  192442. DShowCameraDeviceInteral* const d = (DShowCameraDeviceInteral*) internal;
  192443. return d->firstRecordedTime;
  192444. }
  192445. void CameraDevice::stopRecording()
  192446. {
  192447. if (isRecording)
  192448. {
  192449. DShowCameraDeviceInteral* const d = (DShowCameraDeviceInteral*) internal;
  192450. d->removeFileCaptureFilter();
  192451. d->removeUser();
  192452. isRecording = false;
  192453. }
  192454. }
  192455. void CameraDevice::addListener (CameraImageListener* listenerToAdd)
  192456. {
  192457. DShowCameraDeviceInteral* const d = (DShowCameraDeviceInteral*) internal;
  192458. if (listenerToAdd != 0)
  192459. d->addListener (listenerToAdd);
  192460. }
  192461. void CameraDevice::removeListener (CameraImageListener* listenerToRemove)
  192462. {
  192463. DShowCameraDeviceInteral* const d = (DShowCameraDeviceInteral*) internal;
  192464. if (listenerToRemove != 0)
  192465. d->removeListener (listenerToRemove);
  192466. }
  192467. static ComSmartPtr <IBaseFilter> enumerateCameras (StringArray* const names,
  192468. const int deviceIndexToOpen,
  192469. String& name)
  192470. {
  192471. int index = 0;
  192472. ComSmartPtr <IBaseFilter> result;
  192473. ComSmartPtr <ICreateDevEnum> pDevEnum;
  192474. HRESULT hr = pDevEnum.CoCreateInstance (CLSID_SystemDeviceEnum, CLSCTX_INPROC);
  192475. if (SUCCEEDED (hr))
  192476. {
  192477. ComSmartPtr <IEnumMoniker> enumerator;
  192478. hr = pDevEnum->CreateClassEnumerator (CLSID_VideoInputDeviceCategory, &enumerator, 0);
  192479. if (SUCCEEDED (hr) && enumerator != 0)
  192480. {
  192481. ComSmartPtr <IBaseFilter> captureFilter;
  192482. ComSmartPtr <IMoniker> moniker;
  192483. ULONG fetched;
  192484. while (enumerator->Next (1, &moniker, &fetched) == S_OK)
  192485. {
  192486. hr = moniker->BindToObject (0, 0, IID_IBaseFilter, (void**) &captureFilter);
  192487. if (SUCCEEDED (hr))
  192488. {
  192489. ComSmartPtr <IPropertyBag> propertyBag;
  192490. hr = moniker->BindToStorage (0, 0, IID_IPropertyBag, (void**) &propertyBag);
  192491. if (SUCCEEDED (hr))
  192492. {
  192493. VARIANT var;
  192494. var.vt = VT_BSTR;
  192495. hr = propertyBag->Read (_T("FriendlyName"), &var, 0);
  192496. propertyBag = 0;
  192497. if (SUCCEEDED (hr))
  192498. {
  192499. if (names != 0)
  192500. names->add (var.bstrVal);
  192501. if (index == deviceIndexToOpen)
  192502. {
  192503. name = var.bstrVal;
  192504. result = captureFilter;
  192505. captureFilter = 0;
  192506. break;
  192507. }
  192508. ++index;
  192509. }
  192510. moniker = 0;
  192511. }
  192512. captureFilter = 0;
  192513. }
  192514. }
  192515. }
  192516. }
  192517. return result;
  192518. }
  192519. const StringArray CameraDevice::getAvailableDevices()
  192520. {
  192521. StringArray devs;
  192522. String dummy;
  192523. enumerateCameras (&devs, -1, dummy);
  192524. return devs;
  192525. }
  192526. CameraDevice* CameraDevice::openDevice (int index,
  192527. int minWidth, int minHeight,
  192528. int maxWidth, int maxHeight)
  192529. {
  192530. ComSmartPtr <ICaptureGraphBuilder2> captureGraphBuilder;
  192531. HRESULT hr = captureGraphBuilder.CoCreateInstance (CLSID_CaptureGraphBuilder2, CLSCTX_INPROC);
  192532. if (SUCCEEDED (hr))
  192533. {
  192534. String name;
  192535. const ComSmartPtr <IBaseFilter> filter (enumerateCameras (0, index, name));
  192536. if (filter != 0)
  192537. {
  192538. CameraDevice* const cam = new CameraDevice (name, index);
  192539. DShowCameraDeviceInteral* const intern
  192540. = new DShowCameraDeviceInteral (cam, captureGraphBuilder, filter,
  192541. minWidth, minHeight, maxWidth, maxHeight);
  192542. cam->internal = intern;
  192543. if (intern->ok)
  192544. return cam;
  192545. else
  192546. delete cam;
  192547. }
  192548. }
  192549. return 0;
  192550. }
  192551. #endif
  192552. /*** End of inlined file: juce_win32_CameraDevice.cpp ***/
  192553. #endif
  192554. // Auto-link the other win32 libs that are needed by library calls..
  192555. #if (JUCE_AMALGAMATED_TEMPLATE || defined (JUCE_DLL_BUILD)) && JUCE_MSVC && ! DONT_AUTOLINK_TO_WIN32_LIBRARIES
  192556. /*** Start of inlined file: juce_win32_AutoLinkLibraries.h ***/
  192557. // Auto-links to various win32 libs that are needed by library calls..
  192558. #pragma comment(lib, "kernel32.lib")
  192559. #pragma comment(lib, "user32.lib")
  192560. #pragma comment(lib, "shell32.lib")
  192561. #pragma comment(lib, "gdi32.lib")
  192562. #pragma comment(lib, "vfw32.lib")
  192563. #pragma comment(lib, "comdlg32.lib")
  192564. #pragma comment(lib, "winmm.lib")
  192565. #pragma comment(lib, "wininet.lib")
  192566. #pragma comment(lib, "ole32.lib")
  192567. #pragma comment(lib, "oleaut32.lib")
  192568. #pragma comment(lib, "advapi32.lib")
  192569. #pragma comment(lib, "ws2_32.lib")
  192570. #pragma comment(lib, "comsupp.lib")
  192571. #pragma comment(lib, "version.lib")
  192572. #if JUCE_OPENGL
  192573. #pragma comment(lib, "OpenGL32.Lib")
  192574. #pragma comment(lib, "GlU32.Lib")
  192575. #endif
  192576. #if JUCE_QUICKTIME
  192577. #pragma comment (lib, "QTMLClient.lib")
  192578. #endif
  192579. #if JUCE_USE_CAMERA
  192580. #pragma comment (lib, "Strmiids.lib")
  192581. #pragma comment (lib, "wmvcore.lib")
  192582. #endif
  192583. /*** End of inlined file: juce_win32_AutoLinkLibraries.h ***/
  192584. #endif
  192585. END_JUCE_NAMESPACE
  192586. #endif
  192587. /*** End of inlined file: juce_win32_NativeCode.cpp ***/
  192588. #endif
  192589. #if JUCE_LINUX
  192590. /*** Start of inlined file: juce_linux_NativeCode.cpp ***/
  192591. #if JUCE_LINUX
  192592. BEGIN_JUCE_NAMESPACE
  192593. #if defined (CPU_ISSET) && ! defined (SUPPORT_AFFINITIES)
  192594. #define SUPPORT_AFFINITIES 1
  192595. #endif
  192596. #define JUCE_INCLUDED_FILE 1
  192597. // Now include the actual code files..
  192598. /*** Start of inlined file: juce_posix_SharedCode.h ***/
  192599. CriticalSection::CriticalSection() throw()
  192600. {
  192601. pthread_mutexattr_t atts;
  192602. pthread_mutexattr_init (&atts);
  192603. pthread_mutexattr_settype (&atts, PTHREAD_MUTEX_RECURSIVE);
  192604. pthread_mutex_init (&internal, &atts);
  192605. }
  192606. CriticalSection::~CriticalSection() throw()
  192607. {
  192608. pthread_mutex_destroy (&internal);
  192609. }
  192610. void CriticalSection::enter() const throw()
  192611. {
  192612. pthread_mutex_lock (&internal);
  192613. }
  192614. bool CriticalSection::tryEnter() const throw()
  192615. {
  192616. return pthread_mutex_trylock (&internal) == 0;
  192617. }
  192618. void CriticalSection::exit() const throw()
  192619. {
  192620. pthread_mutex_unlock (&internal);
  192621. }
  192622. class WaitableEventImpl
  192623. {
  192624. public:
  192625. WaitableEventImpl()
  192626. : triggered (false)
  192627. {
  192628. pthread_cond_init (&condition, 0);
  192629. pthread_mutex_init (&mutex, 0);
  192630. }
  192631. ~WaitableEventImpl()
  192632. {
  192633. pthread_cond_destroy (&condition);
  192634. pthread_mutex_destroy (&mutex);
  192635. }
  192636. bool wait (const int timeOutMillisecs) throw()
  192637. {
  192638. pthread_mutex_lock (&mutex);
  192639. if (! triggered)
  192640. {
  192641. if (timeOutMillisecs < 0)
  192642. {
  192643. do
  192644. {
  192645. pthread_cond_wait (&condition, &mutex);
  192646. }
  192647. while (! triggered);
  192648. }
  192649. else
  192650. {
  192651. struct timeval now;
  192652. gettimeofday (&now, 0);
  192653. struct timespec time;
  192654. time.tv_sec = now.tv_sec + (timeOutMillisecs / 1000);
  192655. time.tv_nsec = (now.tv_usec + ((timeOutMillisecs % 1000) * 1000)) * 1000;
  192656. if (time.tv_nsec >= 1000000000)
  192657. {
  192658. time.tv_nsec -= 1000000000;
  192659. time.tv_sec++;
  192660. }
  192661. do
  192662. {
  192663. if (pthread_cond_timedwait (&condition, &mutex, &time) == ETIMEDOUT)
  192664. {
  192665. pthread_mutex_unlock (&mutex);
  192666. return false;
  192667. }
  192668. }
  192669. while (! triggered);
  192670. }
  192671. }
  192672. triggered = false;
  192673. pthread_mutex_unlock (&mutex);
  192674. return true;
  192675. }
  192676. void signal() throw()
  192677. {
  192678. pthread_mutex_lock (&mutex);
  192679. triggered = true;
  192680. pthread_cond_broadcast (&condition);
  192681. pthread_mutex_unlock (&mutex);
  192682. }
  192683. void reset() throw()
  192684. {
  192685. pthread_mutex_lock (&mutex);
  192686. triggered = false;
  192687. pthread_mutex_unlock (&mutex);
  192688. }
  192689. private:
  192690. pthread_cond_t condition;
  192691. pthread_mutex_t mutex;
  192692. bool triggered;
  192693. WaitableEventImpl (const WaitableEventImpl&);
  192694. WaitableEventImpl& operator= (const WaitableEventImpl&);
  192695. };
  192696. WaitableEvent::WaitableEvent() throw()
  192697. : internal (new WaitableEventImpl())
  192698. {
  192699. }
  192700. WaitableEvent::~WaitableEvent() throw()
  192701. {
  192702. delete static_cast <WaitableEventImpl*> (internal);
  192703. }
  192704. bool WaitableEvent::wait (const int timeOutMillisecs) const throw()
  192705. {
  192706. return static_cast <WaitableEventImpl*> (internal)->wait (timeOutMillisecs);
  192707. }
  192708. void WaitableEvent::signal() const throw()
  192709. {
  192710. static_cast <WaitableEventImpl*> (internal)->signal();
  192711. }
  192712. void WaitableEvent::reset() const throw()
  192713. {
  192714. static_cast <WaitableEventImpl*> (internal)->reset();
  192715. }
  192716. void JUCE_CALLTYPE Thread::sleep (int millisecs)
  192717. {
  192718. struct timespec time;
  192719. time.tv_sec = millisecs / 1000;
  192720. time.tv_nsec = (millisecs % 1000) * 1000000;
  192721. nanosleep (&time, 0);
  192722. }
  192723. const tchar File::separator = T('/');
  192724. const tchar* File::separatorString = T("/");
  192725. const File File::getCurrentWorkingDirectory()
  192726. {
  192727. HeapBlock<char> heapBuffer;
  192728. char localBuffer [1024];
  192729. char* cwd = getcwd (localBuffer, sizeof (localBuffer) - 1);
  192730. int bufferSize = 4096;
  192731. while (cwd == 0 && errno == ERANGE)
  192732. {
  192733. heapBuffer.malloc (bufferSize);
  192734. cwd = getcwd (heapBuffer, bufferSize - 1);
  192735. bufferSize += 1024;
  192736. }
  192737. return File (String::fromUTF8 (cwd));
  192738. }
  192739. bool File::setAsCurrentWorkingDirectory() const
  192740. {
  192741. return chdir (getFullPathName().toUTF8()) == 0;
  192742. }
  192743. bool juce_copyFile (const String& s, const String& d);
  192744. static bool juce_stat (const String& fileName, struct stat& info)
  192745. {
  192746. return fileName.isNotEmpty()
  192747. && (stat (fileName.toUTF8(), &info) == 0);
  192748. }
  192749. bool juce_isDirectory (const String& fileName)
  192750. {
  192751. struct stat info;
  192752. return fileName.isEmpty()
  192753. || (juce_stat (fileName, info)
  192754. && ((info.st_mode & S_IFDIR) != 0));
  192755. }
  192756. bool juce_fileExists (const String& fileName, const bool dontCountDirectories)
  192757. {
  192758. if (fileName.isEmpty())
  192759. return false;
  192760. const char* const fileNameUTF8 = fileName.toUTF8();
  192761. bool exists = access (fileNameUTF8, F_OK) == 0;
  192762. if (exists && dontCountDirectories)
  192763. {
  192764. struct stat info;
  192765. const int res = stat (fileNameUTF8, &info);
  192766. if (res == 0 && (info.st_mode & S_IFDIR) != 0)
  192767. exists = false;
  192768. }
  192769. return exists;
  192770. }
  192771. int64 juce_getFileSize (const String& fileName)
  192772. {
  192773. struct stat info;
  192774. return juce_stat (fileName, info) ? info.st_size : 0;
  192775. }
  192776. bool juce_canWriteToFile (const String& fileName)
  192777. {
  192778. return access (fileName.toUTF8(), W_OK) == 0;
  192779. }
  192780. bool juce_deleteFile (const String& fileName)
  192781. {
  192782. if (juce_isDirectory (fileName))
  192783. return rmdir (fileName.toUTF8()) == 0;
  192784. else
  192785. return remove (fileName.toUTF8()) == 0;
  192786. }
  192787. bool juce_moveFile (const String& source, const String& dest)
  192788. {
  192789. if (rename (source.toUTF8(), dest.toUTF8()) == 0)
  192790. return true;
  192791. if (juce_canWriteToFile (source)
  192792. && juce_copyFile (source, dest))
  192793. {
  192794. if (juce_deleteFile (source))
  192795. return true;
  192796. juce_deleteFile (dest);
  192797. }
  192798. return false;
  192799. }
  192800. void juce_createDirectory (const String& fileName)
  192801. {
  192802. mkdir (fileName.toUTF8(), 0777);
  192803. }
  192804. void* juce_fileOpen (const String& fileName, bool forWriting)
  192805. {
  192806. int flags = O_RDONLY;
  192807. if (forWriting)
  192808. {
  192809. if (juce_fileExists (fileName, false))
  192810. {
  192811. const int f = open (fileName.toUTF8(), O_RDWR, 00644);
  192812. if (f != -1)
  192813. lseek (f, 0, SEEK_END);
  192814. return (void*) f;
  192815. }
  192816. else
  192817. {
  192818. flags = O_RDWR + O_CREAT;
  192819. }
  192820. }
  192821. return (void*) open (fileName.toUTF8(), flags, 00644);
  192822. }
  192823. void juce_fileClose (void* handle)
  192824. {
  192825. if (handle != 0)
  192826. close ((int) (pointer_sized_int) handle);
  192827. }
  192828. int juce_fileRead (void* handle, void* buffer, int size)
  192829. {
  192830. if (handle != 0)
  192831. return (int) read ((int) (pointer_sized_int) handle, buffer, size);
  192832. return 0;
  192833. }
  192834. int juce_fileWrite (void* handle, const void* buffer, int size)
  192835. {
  192836. if (handle != 0)
  192837. return (int) write ((int) (pointer_sized_int) handle, buffer, size);
  192838. return 0;
  192839. }
  192840. int64 juce_fileSetPosition (void* handle, int64 pos)
  192841. {
  192842. if (handle != 0 && lseek ((int) (pointer_sized_int) handle, pos, SEEK_SET) == pos)
  192843. return pos;
  192844. return -1;
  192845. }
  192846. int64 juce_fileGetPosition (void* handle)
  192847. {
  192848. if (handle != 0)
  192849. return lseek ((int) (pointer_sized_int) handle, 0, SEEK_CUR);
  192850. else
  192851. return -1;
  192852. }
  192853. void juce_fileFlush (void* handle)
  192854. {
  192855. if (handle != 0)
  192856. fsync ((int) (pointer_sized_int) handle);
  192857. }
  192858. const File juce_getExecutableFile()
  192859. {
  192860. Dl_info exeInfo;
  192861. dladdr ((const void*) juce_getExecutableFile, &exeInfo);
  192862. return File (String::fromUTF8 (exeInfo.dli_fname));
  192863. }
  192864. // if this file doesn't exist, find a parent of it that does..
  192865. static bool doStatFS (const File* file, struct statfs& result)
  192866. {
  192867. File f (*file);
  192868. for (int i = 5; --i >= 0;)
  192869. {
  192870. if (f.exists())
  192871. break;
  192872. f = f.getParentDirectory();
  192873. }
  192874. return statfs (f.getFullPathName().toUTF8(), &result) == 0;
  192875. }
  192876. int64 File::getBytesFreeOnVolume() const
  192877. {
  192878. struct statfs buf;
  192879. if (doStatFS (this, buf))
  192880. return (int64) buf.f_bsize * (int64) buf.f_bavail; // Note: this returns space available to non-super user
  192881. return 0;
  192882. }
  192883. int64 File::getVolumeTotalSize() const
  192884. {
  192885. struct statfs buf;
  192886. if (doStatFS (this, buf))
  192887. return (int64) buf.f_bsize * (int64) buf.f_blocks;
  192888. return 0;
  192889. }
  192890. const String juce_getVolumeLabel (const String& filenameOnVolume,
  192891. int& volumeSerialNumber)
  192892. {
  192893. volumeSerialNumber = 0;
  192894. #if JUCE_MAC
  192895. struct VolAttrBuf
  192896. {
  192897. u_int32_t length;
  192898. attrreference_t mountPointRef;
  192899. char mountPointSpace [MAXPATHLEN];
  192900. } attrBuf;
  192901. struct attrlist attrList;
  192902. zerostruct (attrList);
  192903. attrList.bitmapcount = ATTR_BIT_MAP_COUNT;
  192904. attrList.volattr = ATTR_VOL_INFO | ATTR_VOL_NAME;
  192905. File f (filenameOnVolume);
  192906. for (;;)
  192907. {
  192908. if (getattrlist (f.getFullPathName().toUTF8(),
  192909. &attrList, &attrBuf, sizeof(attrBuf), 0) == 0)
  192910. {
  192911. return String::fromUTF8 (((const char*) &attrBuf.mountPointRef) + attrBuf.mountPointRef.attr_dataoffset,
  192912. (int) attrBuf.mountPointRef.attr_length);
  192913. }
  192914. const File parent (f.getParentDirectory());
  192915. if (f == parent)
  192916. break;
  192917. f = parent;
  192918. }
  192919. #endif
  192920. return String::empty;
  192921. }
  192922. void juce_runSystemCommand (const String& command)
  192923. {
  192924. int result = system (command.toUTF8());
  192925. (void) result;
  192926. }
  192927. const String juce_getOutputFromCommand (const String& command)
  192928. {
  192929. // slight bodge here, as we just pipe the output into a temp file and read it...
  192930. const File tempFile (File::getSpecialLocation (File::tempDirectory)
  192931. .getNonexistentChildFile (String::toHexString (Random::getSystemRandom().nextInt()), ".tmp", false));
  192932. juce_runSystemCommand (command + " > " + tempFile.getFullPathName());
  192933. String result (tempFile.loadFileAsString());
  192934. tempFile.deleteFile();
  192935. return result;
  192936. }
  192937. InterProcessLock::InterProcessLock (const String& name_)
  192938. : internal (0),
  192939. name (name_),
  192940. reentrancyLevel (0)
  192941. {
  192942. #if JUCE_MAC
  192943. // (don't use getSpecialLocation() to avoid the temp folder being different for each app)
  192944. const File temp (File (T("~/Library/Caches/Juce")).getChildFile (name));
  192945. #else
  192946. const File temp (File::getSpecialLocation (File::tempDirectory).getChildFile (name));
  192947. #endif
  192948. temp.create();
  192949. internal = open (temp.getFullPathName().toUTF8(), O_RDWR);
  192950. }
  192951. InterProcessLock::~InterProcessLock()
  192952. {
  192953. while (reentrancyLevel > 0)
  192954. this->exit();
  192955. close (internal);
  192956. }
  192957. bool InterProcessLock::enter (const int timeOutMillisecs)
  192958. {
  192959. if (internal == 0)
  192960. return false;
  192961. if (reentrancyLevel != 0)
  192962. return true;
  192963. const int64 endTime = Time::currentTimeMillis() + timeOutMillisecs;
  192964. struct flock fl;
  192965. zerostruct (fl);
  192966. fl.l_whence = SEEK_SET;
  192967. fl.l_type = F_WRLCK;
  192968. for (;;)
  192969. {
  192970. const int result = fcntl (internal, F_SETLK, &fl);
  192971. if (result >= 0)
  192972. {
  192973. ++reentrancyLevel;
  192974. return true;
  192975. }
  192976. if (errno != EINTR)
  192977. {
  192978. if (timeOutMillisecs == 0
  192979. || (timeOutMillisecs > 0 && Time::currentTimeMillis() >= endTime))
  192980. break;
  192981. Thread::sleep (10);
  192982. }
  192983. }
  192984. return false;
  192985. }
  192986. void InterProcessLock::exit()
  192987. {
  192988. if (reentrancyLevel > 0 && internal != 0)
  192989. {
  192990. --reentrancyLevel;
  192991. struct flock fl;
  192992. zerostruct (fl);
  192993. fl.l_whence = SEEK_SET;
  192994. fl.l_type = F_UNLCK;
  192995. for (;;)
  192996. {
  192997. const int result = fcntl (internal, F_SETLKW, &fl);
  192998. if (result >= 0 || errno != EINTR)
  192999. break;
  193000. }
  193001. }
  193002. }
  193003. /*** End of inlined file: juce_posix_SharedCode.h ***/
  193004. /*** Start of inlined file: juce_linux_Files.cpp ***/
  193005. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  193006. // compiled on its own).
  193007. #if JUCE_INCLUDED_FILE
  193008. static const short U_ISOFS_SUPER_MAGIC = 0x9660; // linux/iso_fs.h
  193009. static const short U_MSDOS_SUPER_MAGIC = 0x4d44; // linux/msdos_fs.h
  193010. static const short U_NFS_SUPER_MAGIC = 0x6969; // linux/nfs_fs.h
  193011. static const short U_SMB_SUPER_MAGIC = 0x517B; // linux/smb_fs.h
  193012. void juce_getFileTimes (const String& fileName,
  193013. int64& modificationTime,
  193014. int64& accessTime,
  193015. int64& creationTime)
  193016. {
  193017. modificationTime = 0;
  193018. accessTime = 0;
  193019. creationTime = 0;
  193020. struct stat info;
  193021. const int res = stat (fileName.toUTF8(), &info);
  193022. if (res == 0)
  193023. {
  193024. modificationTime = (int64) info.st_mtime * 1000;
  193025. accessTime = (int64) info.st_atime * 1000;
  193026. creationTime = (int64) info.st_ctime * 1000;
  193027. }
  193028. }
  193029. bool juce_setFileTimes (const String& fileName,
  193030. int64 modificationTime,
  193031. int64 accessTime,
  193032. int64 creationTime)
  193033. {
  193034. struct utimbuf times;
  193035. times.actime = (time_t) (accessTime / 1000);
  193036. times.modtime = (time_t) (modificationTime / 1000);
  193037. return utime (fileName.toUTF8(), &times) == 0;
  193038. }
  193039. bool juce_setFileReadOnly (const String& fileName, bool isReadOnly)
  193040. {
  193041. struct stat info;
  193042. const int res = stat (fileName.toUTF8(), &info);
  193043. if (res != 0)
  193044. return false;
  193045. info.st_mode &= 0777; // Just permissions
  193046. if( isReadOnly )
  193047. info.st_mode &= ~(S_IWUSR | S_IWGRP | S_IWOTH);
  193048. else
  193049. // Give everybody write permission?
  193050. info.st_mode |= S_IWUSR | S_IWGRP | S_IWOTH;
  193051. return chmod (fileName.toUTF8(), info.st_mode) == 0;
  193052. }
  193053. bool juce_copyFile (const String& s, const String& d)
  193054. {
  193055. const File source (s), dest (d);
  193056. FileInputStream* in = source.createInputStream();
  193057. bool ok = false;
  193058. if (in != 0)
  193059. {
  193060. if (dest.deleteFile())
  193061. {
  193062. FileOutputStream* const out = dest.createOutputStream();
  193063. if (out != 0)
  193064. {
  193065. const int bytesCopied = out->writeFromInputStream (*in, -1);
  193066. delete out;
  193067. ok = (bytesCopied == source.getSize());
  193068. if (! ok)
  193069. dest.deleteFile();
  193070. }
  193071. }
  193072. delete in;
  193073. }
  193074. return ok;
  193075. }
  193076. const StringArray juce_getFileSystemRoots()
  193077. {
  193078. StringArray s;
  193079. s.add (T("/"));
  193080. return s;
  193081. }
  193082. bool File::isOnCDRomDrive() const
  193083. {
  193084. struct statfs buf;
  193085. if (statfs (getFullPathName().toUTF8(), &buf) == 0)
  193086. return (buf.f_type == U_ISOFS_SUPER_MAGIC);
  193087. // Assume not if this fails for some reason
  193088. return false;
  193089. }
  193090. bool File::isOnHardDisk() const
  193091. {
  193092. struct statfs buf;
  193093. if (statfs (getFullPathName().toUTF8(), &buf) == 0)
  193094. {
  193095. switch (buf.f_type)
  193096. {
  193097. case U_ISOFS_SUPER_MAGIC: // CD-ROM
  193098. case U_MSDOS_SUPER_MAGIC: // Probably floppy (but could be mounted FAT filesystem)
  193099. case U_NFS_SUPER_MAGIC: // Network NFS
  193100. case U_SMB_SUPER_MAGIC: // Network Samba
  193101. return false;
  193102. default:
  193103. // Assume anything else is a hard-disk (but note it could
  193104. // be a RAM disk. There isn't a good way of determining
  193105. // this for sure)
  193106. return true;
  193107. }
  193108. }
  193109. // Assume so if this fails for some reason
  193110. return true;
  193111. }
  193112. bool File::isOnRemovableDrive() const
  193113. {
  193114. jassertfalse // xxx not implemented for linux!
  193115. return false;
  193116. }
  193117. bool File::isHidden() const
  193118. {
  193119. return getFileName().startsWithChar (T('.'));
  193120. }
  193121. const char* juce_Argv0 = 0; // referenced from juce_Application.cpp
  193122. const File File::getSpecialLocation (const SpecialLocationType type)
  193123. {
  193124. switch (type)
  193125. {
  193126. case userHomeDirectory:
  193127. {
  193128. const char* homeDir = getenv ("HOME");
  193129. if (homeDir == 0)
  193130. {
  193131. struct passwd* const pw = getpwuid (getuid());
  193132. if (pw != 0)
  193133. homeDir = pw->pw_dir;
  193134. }
  193135. return File (String::fromUTF8 (homeDir));
  193136. }
  193137. case userDocumentsDirectory:
  193138. case userMusicDirectory:
  193139. case userMoviesDirectory:
  193140. case userApplicationDataDirectory:
  193141. return File ("~");
  193142. case userDesktopDirectory:
  193143. return File ("~/Desktop");
  193144. case commonApplicationDataDirectory:
  193145. return File ("/var");
  193146. case globalApplicationsDirectory:
  193147. return File ("/usr");
  193148. case tempDirectory:
  193149. {
  193150. File tmp ("/var/tmp");
  193151. if (! tmp.isDirectory())
  193152. {
  193153. tmp = T("/tmp");
  193154. if (! tmp.isDirectory())
  193155. tmp = File::getCurrentWorkingDirectory();
  193156. }
  193157. return tmp;
  193158. }
  193159. case invokedExecutableFile:
  193160. if (juce_Argv0 != 0)
  193161. return File (String::fromUTF8 (juce_Argv0));
  193162. // deliberate fall-through...
  193163. case currentExecutableFile:
  193164. case currentApplicationFile:
  193165. return juce_getExecutableFile();
  193166. default:
  193167. jassertfalse // unknown type?
  193168. break;
  193169. }
  193170. return File::nonexistent;
  193171. }
  193172. const String File::getVersion() const
  193173. {
  193174. return String::empty; // xxx not yet implemented
  193175. }
  193176. const File File::getLinkedTarget() const
  193177. {
  193178. char buffer [4096];
  193179. size_t numChars = readlink (getFullPathName().toUTF8(),
  193180. buffer, sizeof (buffer));
  193181. if (numChars > 0 && numChars <= sizeof (buffer))
  193182. return File (String::fromUTF8 (buffer, (int) numChars));
  193183. return *this;
  193184. }
  193185. bool File::moveToTrash() const
  193186. {
  193187. if (! exists())
  193188. return true;
  193189. File trashCan (T("~/.Trash"));
  193190. if (! trashCan.isDirectory())
  193191. trashCan = T("~/.local/share/Trash/files");
  193192. if (! trashCan.isDirectory())
  193193. return false;
  193194. return moveFileTo (trashCan.getNonexistentChildFile (getFileNameWithoutExtension(),
  193195. getFileExtension()));
  193196. }
  193197. struct FindFileStruct
  193198. {
  193199. String parentDir, wildCard;
  193200. DIR* dir;
  193201. bool getNextMatch (String& result, bool* const isDir, bool* const isHidden, int64* const fileSize,
  193202. Time* const modTime, Time* const creationTime, bool* const isReadOnly)
  193203. {
  193204. const char* const wildcardUTF8 = wildCard.toUTF8();
  193205. for (;;)
  193206. {
  193207. struct dirent* const de = readdir (dir);
  193208. if (de == 0)
  193209. break;
  193210. if (fnmatch (wildcardUTF8, de->d_name, FNM_CASEFOLD) == 0)
  193211. {
  193212. result = String::fromUTF8 (de->d_name);
  193213. const String path (parentDir + result);
  193214. if (isDir != 0 || fileSize != 0)
  193215. {
  193216. struct stat info;
  193217. const bool statOk = (stat (path.toUTF8(), &info) == 0);
  193218. if (isDir != 0)
  193219. *isDir = path.isEmpty() || (statOk && ((info.st_mode & S_IFDIR) != 0));
  193220. if (isHidden != 0)
  193221. *isHidden = (de->d_name[0] == '.');
  193222. if (fileSize != 0)
  193223. *fileSize = statOk ? info.st_size : 0;
  193224. }
  193225. if (modTime != 0 || creationTime != 0)
  193226. {
  193227. int64 m, a, c;
  193228. juce_getFileTimes (path, m, a, c);
  193229. if (modTime != 0)
  193230. *modTime = m;
  193231. if (creationTime != 0)
  193232. *creationTime = c;
  193233. }
  193234. if (isReadOnly != 0)
  193235. *isReadOnly = ! juce_canWriteToFile (path);
  193236. return true;
  193237. }
  193238. }
  193239. return false;
  193240. }
  193241. };
  193242. // returns 0 on failure
  193243. void* juce_findFileStart (const String& directory, const String& wildCard, String& firstResultFile,
  193244. bool* isDir, bool* isHidden, int64* fileSize, Time* modTime,
  193245. Time* creationTime, bool* isReadOnly)
  193246. {
  193247. DIR* d = opendir (directory.toUTF8());
  193248. if (d != 0)
  193249. {
  193250. FindFileStruct* ff = new FindFileStruct();
  193251. ff->parentDir = directory;
  193252. if (!ff->parentDir.endsWithChar (File::separator))
  193253. ff->parentDir += File::separator;
  193254. ff->wildCard = wildCard;
  193255. if (wildCard == T("*.*"))
  193256. ff->wildCard = T("*");
  193257. ff->dir = d;
  193258. if (ff->getNextMatch (firstResultFile, isDir, isHidden, fileSize, modTime, creationTime, isReadOnly))
  193259. {
  193260. return ff;
  193261. }
  193262. else
  193263. {
  193264. firstResultFile = String::empty;
  193265. isDir = false;
  193266. isHidden = false;
  193267. closedir (d);
  193268. delete ff;
  193269. }
  193270. }
  193271. return 0;
  193272. }
  193273. bool juce_findFileNext (void* handle, String& resultFile,
  193274. bool* isDir, bool* isHidden, int64* fileSize, Time* modTime, Time* creationTime, bool* isReadOnly)
  193275. {
  193276. FindFileStruct* const ff = (FindFileStruct*) handle;
  193277. if (ff != 0)
  193278. return ff->getNextMatch (resultFile, isDir, isHidden, fileSize, modTime, creationTime, isReadOnly);
  193279. return false;
  193280. }
  193281. void juce_findFileClose (void* handle)
  193282. {
  193283. FindFileStruct* const ff = (FindFileStruct*) handle;
  193284. if (ff != 0)
  193285. {
  193286. closedir (ff->dir);
  193287. delete ff;
  193288. }
  193289. }
  193290. bool juce_launchFile (const String& fileName,
  193291. const String& parameters)
  193292. {
  193293. String cmdString (fileName.replace (T(" "), T("\\ "),false));
  193294. cmdString << " " << parameters;
  193295. if (URL::isProbablyAWebsiteURL (fileName)
  193296. || cmdString.startsWithIgnoreCase (T("file:"))
  193297. || URL::isProbablyAnEmailAddress (fileName))
  193298. {
  193299. // create a command that tries to launch a bunch of likely browsers
  193300. const char* const browserNames[] = { "xdg-open", "/etc/alternatives/x-www-browser", "firefox", "mozilla", "konqueror", "opera" };
  193301. StringArray cmdLines;
  193302. for (int i = 0; i < numElementsInArray (browserNames); ++i)
  193303. cmdLines.add (String (browserNames[i]) + T(" ") + cmdString.trim().quoted());
  193304. cmdString = cmdLines.joinIntoString (T(" || "));
  193305. }
  193306. const char* const argv[4] = { "/bin/sh", "-c", cmdString.toUTF8(), 0 };
  193307. const int cpid = fork();
  193308. if (cpid == 0)
  193309. {
  193310. setsid();
  193311. // Child process
  193312. execve (argv[0], (char**) argv, environ);
  193313. exit (0);
  193314. }
  193315. return cpid >= 0;
  193316. }
  193317. void File::revealToUser() const
  193318. {
  193319. if (isDirectory())
  193320. startAsProcess();
  193321. else if (getParentDirectory().exists())
  193322. getParentDirectory().startAsProcess();
  193323. }
  193324. #endif
  193325. /*** End of inlined file: juce_linux_Files.cpp ***/
  193326. /*** Start of inlined file: juce_posix_NamedPipe.cpp ***/
  193327. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  193328. // compiled on its own).
  193329. #if JUCE_INCLUDED_FILE
  193330. struct NamedPipeInternal
  193331. {
  193332. String pipeInName, pipeOutName;
  193333. int pipeIn, pipeOut;
  193334. bool volatile createdPipe, blocked, stopReadOperation;
  193335. static void signalHandler (int) {}
  193336. };
  193337. void NamedPipe::cancelPendingReads()
  193338. {
  193339. while (internal != 0 && ((NamedPipeInternal*) internal)->blocked)
  193340. {
  193341. NamedPipeInternal* const intern = (NamedPipeInternal*) internal;
  193342. intern->stopReadOperation = true;
  193343. char buffer [1] = { 0 };
  193344. int bytesWritten = (int) ::write (intern->pipeIn, buffer, 1);
  193345. (void) bytesWritten;
  193346. int timeout = 2000;
  193347. while (intern->blocked && --timeout >= 0)
  193348. Thread::sleep (2);
  193349. intern->stopReadOperation = false;
  193350. }
  193351. }
  193352. void NamedPipe::close()
  193353. {
  193354. NamedPipeInternal* const intern = (NamedPipeInternal*) internal;
  193355. if (intern != 0)
  193356. {
  193357. internal = 0;
  193358. if (intern->pipeIn != -1)
  193359. ::close (intern->pipeIn);
  193360. if (intern->pipeOut != -1)
  193361. ::close (intern->pipeOut);
  193362. if (intern->createdPipe)
  193363. {
  193364. unlink (intern->pipeInName.toUTF8());
  193365. unlink (intern->pipeOutName.toUTF8());
  193366. }
  193367. delete intern;
  193368. }
  193369. }
  193370. bool NamedPipe::openInternal (const String& pipeName, const bool createPipe)
  193371. {
  193372. close();
  193373. NamedPipeInternal* const intern = new NamedPipeInternal();
  193374. internal = intern;
  193375. intern->createdPipe = createPipe;
  193376. intern->blocked = false;
  193377. intern->stopReadOperation = false;
  193378. signal (SIGPIPE, NamedPipeInternal::signalHandler);
  193379. siginterrupt (SIGPIPE, 1);
  193380. const String pipePath (T("/tmp/") + File::createLegalFileName (pipeName));
  193381. intern->pipeInName = pipePath + T("_in");
  193382. intern->pipeOutName = pipePath + T("_out");
  193383. intern->pipeIn = -1;
  193384. intern->pipeOut = -1;
  193385. if (createPipe)
  193386. {
  193387. if ((mkfifo (intern->pipeInName.toUTF8(), 0666) && errno != EEXIST)
  193388. || (mkfifo (intern->pipeOutName.toUTF8(), 0666) && errno != EEXIST))
  193389. {
  193390. delete intern;
  193391. internal = 0;
  193392. return false;
  193393. }
  193394. }
  193395. return true;
  193396. }
  193397. int NamedPipe::read (void* destBuffer, int maxBytesToRead, int /*timeOutMilliseconds*/)
  193398. {
  193399. int bytesRead = -1;
  193400. NamedPipeInternal* const intern = (NamedPipeInternal*) internal;
  193401. if (intern != 0)
  193402. {
  193403. intern->blocked = true;
  193404. if (intern->pipeIn == -1)
  193405. {
  193406. if (intern->createdPipe)
  193407. intern->pipeIn = ::open (intern->pipeInName.toUTF8(), O_RDWR);
  193408. else
  193409. intern->pipeIn = ::open (intern->pipeOutName.toUTF8(), O_RDWR);
  193410. if (intern->pipeIn == -1)
  193411. {
  193412. intern->blocked = false;
  193413. return -1;
  193414. }
  193415. }
  193416. bytesRead = 0;
  193417. char* p = (char*) destBuffer;
  193418. while (bytesRead < maxBytesToRead)
  193419. {
  193420. const int bytesThisTime = maxBytesToRead - bytesRead;
  193421. const int numRead = (int) ::read (intern->pipeIn, p, bytesThisTime);
  193422. if (numRead <= 0 || intern->stopReadOperation)
  193423. {
  193424. bytesRead = -1;
  193425. break;
  193426. }
  193427. bytesRead += numRead;
  193428. p += bytesRead;
  193429. }
  193430. intern->blocked = false;
  193431. }
  193432. return bytesRead;
  193433. }
  193434. int NamedPipe::write (const void* sourceBuffer, int numBytesToWrite, int timeOutMilliseconds)
  193435. {
  193436. int bytesWritten = -1;
  193437. NamedPipeInternal* const intern = (NamedPipeInternal*) internal;
  193438. if (intern != 0)
  193439. {
  193440. if (intern->pipeOut == -1)
  193441. {
  193442. if (intern->createdPipe)
  193443. intern->pipeOut = ::open (intern->pipeOutName.toUTF8(), O_WRONLY);
  193444. else
  193445. intern->pipeOut = ::open (intern->pipeInName.toUTF8(), O_WRONLY);
  193446. if (intern->pipeOut == -1)
  193447. {
  193448. return -1;
  193449. }
  193450. }
  193451. const char* p = (const char*) sourceBuffer;
  193452. bytesWritten = 0;
  193453. const uint32 timeOutTime = Time::getMillisecondCounter() + timeOutMilliseconds;
  193454. while (bytesWritten < numBytesToWrite
  193455. && (timeOutMilliseconds < 0 || Time::getMillisecondCounter() < timeOutTime))
  193456. {
  193457. const int bytesThisTime = numBytesToWrite - bytesWritten;
  193458. const int numWritten = (int) ::write (intern->pipeOut, p, bytesThisTime);
  193459. if (numWritten <= 0)
  193460. {
  193461. bytesWritten = -1;
  193462. break;
  193463. }
  193464. bytesWritten += numWritten;
  193465. p += bytesWritten;
  193466. }
  193467. }
  193468. return bytesWritten;
  193469. }
  193470. #endif
  193471. /*** End of inlined file: juce_posix_NamedPipe.cpp ***/
  193472. /*** Start of inlined file: juce_linux_Network.cpp ***/
  193473. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  193474. // compiled on its own).
  193475. #if JUCE_INCLUDED_FILE
  193476. int SystemStats::getMACAddresses (int64* addresses, int maxNum, const bool littleEndian)
  193477. {
  193478. int numResults = 0;
  193479. const int s = socket (AF_INET, SOCK_DGRAM, 0);
  193480. if (s != -1)
  193481. {
  193482. char buf [1024];
  193483. struct ifconf ifc;
  193484. ifc.ifc_len = sizeof (buf);
  193485. ifc.ifc_buf = buf;
  193486. ioctl (s, SIOCGIFCONF, &ifc);
  193487. for (unsigned int i = 0; i < ifc.ifc_len / sizeof (struct ifreq); ++i)
  193488. {
  193489. struct ifreq ifr;
  193490. strcpy (ifr.ifr_name, ifc.ifc_req[i].ifr_name);
  193491. if (ioctl (s, SIOCGIFFLAGS, &ifr) == 0
  193492. && (ifr.ifr_flags & IFF_LOOPBACK) == 0
  193493. && ioctl (s, SIOCGIFHWADDR, &ifr) == 0
  193494. && numResults < maxNum)
  193495. {
  193496. int64 a = 0;
  193497. for (int j = 6; --j >= 0;)
  193498. a = (a << 8) | (uint8) ifr.ifr_hwaddr.sa_data [littleEndian ? j : (5 - j)];
  193499. *addresses++ = a;
  193500. ++numResults;
  193501. }
  193502. }
  193503. close (s);
  193504. }
  193505. return numResults;
  193506. }
  193507. bool PlatformUtilities::launchEmailWithAttachments (const String& targetEmailAddress,
  193508. const String& emailSubject,
  193509. const String& bodyText,
  193510. const StringArray& filesToAttach)
  193511. {
  193512. jassertfalse // xxx todo
  193513. return false;
  193514. }
  193515. class JUCE_HTTPSocketStream
  193516. {
  193517. public:
  193518. JUCE_HTTPSocketStream()
  193519. : readPosition (0),
  193520. socketHandle (-1),
  193521. levelsOfRedirection (0),
  193522. timeoutSeconds (15)
  193523. {
  193524. }
  193525. ~JUCE_HTTPSocketStream()
  193526. {
  193527. closeSocket();
  193528. }
  193529. bool open (const String& url,
  193530. const String& headers,
  193531. const MemoryBlock& postData,
  193532. const bool isPost,
  193533. URL::OpenStreamProgressCallback* callback,
  193534. void* callbackContext,
  193535. int timeOutMs)
  193536. {
  193537. closeSocket();
  193538. uint32 timeOutTime = Time::getMillisecondCounter();
  193539. if (timeOutMs == 0)
  193540. timeOutTime += 60000;
  193541. else if (timeOutMs < 0)
  193542. timeOutTime = 0xffffffff;
  193543. else
  193544. timeOutTime += timeOutMs;
  193545. String hostName, hostPath;
  193546. int hostPort;
  193547. if (! decomposeURL (url, hostName, hostPath, hostPort))
  193548. return false;
  193549. const struct hostent* host = 0;
  193550. int port = 0;
  193551. String proxyName, proxyPath;
  193552. int proxyPort = 0;
  193553. String proxyURL (getenv ("http_proxy"));
  193554. if (proxyURL.startsWithIgnoreCase (T("http://")))
  193555. {
  193556. if (! decomposeURL (proxyURL, proxyName, proxyPath, proxyPort))
  193557. return false;
  193558. host = gethostbyname (proxyName.toUTF8());
  193559. port = proxyPort;
  193560. }
  193561. else
  193562. {
  193563. host = gethostbyname (hostName.toUTF8());
  193564. port = hostPort;
  193565. }
  193566. if (host == 0)
  193567. return false;
  193568. struct sockaddr_in address;
  193569. zerostruct (address);
  193570. memcpy ((void*) &address.sin_addr, (const void*) host->h_addr, host->h_length);
  193571. address.sin_family = host->h_addrtype;
  193572. address.sin_port = htons (port);
  193573. socketHandle = socket (host->h_addrtype, SOCK_STREAM, 0);
  193574. if (socketHandle == -1)
  193575. return false;
  193576. int receiveBufferSize = 16384;
  193577. setsockopt (socketHandle, SOL_SOCKET, SO_RCVBUF, (char*) &receiveBufferSize, sizeof (receiveBufferSize));
  193578. setsockopt (socketHandle, SOL_SOCKET, SO_KEEPALIVE, 0, 0);
  193579. #if JUCE_MAC
  193580. setsockopt (socketHandle, SOL_SOCKET, SO_NOSIGPIPE, 0, 0);
  193581. #endif
  193582. if (connect (socketHandle, (struct sockaddr*) &address, sizeof (address)) == -1)
  193583. {
  193584. closeSocket();
  193585. return false;
  193586. }
  193587. const MemoryBlock requestHeader (createRequestHeader (hostName, hostPort,
  193588. proxyName, proxyPort,
  193589. hostPath, url,
  193590. headers, postData,
  193591. isPost));
  193592. size_t totalHeaderSent = 0;
  193593. while (totalHeaderSent < requestHeader.getSize())
  193594. {
  193595. if (Time::getMillisecondCounter() > timeOutTime)
  193596. {
  193597. closeSocket();
  193598. return false;
  193599. }
  193600. const int numToSend = jmin (1024, (int) (requestHeader.getSize() - totalHeaderSent));
  193601. if (send (socketHandle,
  193602. ((const char*) requestHeader.getData()) + totalHeaderSent,
  193603. numToSend, 0)
  193604. != numToSend)
  193605. {
  193606. closeSocket();
  193607. return false;
  193608. }
  193609. totalHeaderSent += numToSend;
  193610. if (callback != 0 && ! callback (callbackContext, totalHeaderSent, requestHeader.getSize()))
  193611. {
  193612. closeSocket();
  193613. return false;
  193614. }
  193615. }
  193616. const String responseHeader (readResponse (timeOutTime));
  193617. if (responseHeader.isNotEmpty())
  193618. {
  193619. //DBG (responseHeader);
  193620. StringArray lines;
  193621. lines.addLines (responseHeader);
  193622. // NB - using charToString() here instead of just T(" "), because that was
  193623. // causing a mysterious gcc internal compiler error...
  193624. const int statusCode = responseHeader.fromFirstOccurrenceOf (String::charToString (T(' ')), false, false)
  193625. .substring (0, 3).getIntValue();
  193626. //int contentLength = findHeaderItem (lines, T("Content-Length:")).getIntValue();
  193627. //bool isChunked = findHeaderItem (lines, T("Transfer-Encoding:")).equalsIgnoreCase ("chunked");
  193628. String location (findHeaderItem (lines, T("Location:")));
  193629. if (statusCode >= 300 && statusCode < 400
  193630. && location.isNotEmpty())
  193631. {
  193632. if (! location.startsWithIgnoreCase (T("http://")))
  193633. location = T("http://") + location;
  193634. if (levelsOfRedirection++ < 3)
  193635. return open (location, headers, postData, isPost, callback, callbackContext, timeOutMs);
  193636. }
  193637. else
  193638. {
  193639. levelsOfRedirection = 0;
  193640. return true;
  193641. }
  193642. }
  193643. closeSocket();
  193644. return false;
  193645. }
  193646. int read (void* buffer, int bytesToRead)
  193647. {
  193648. fd_set readbits;
  193649. FD_ZERO (&readbits);
  193650. FD_SET (socketHandle, &readbits);
  193651. struct timeval tv;
  193652. tv.tv_sec = timeoutSeconds;
  193653. tv.tv_usec = 0;
  193654. if (select (socketHandle + 1, &readbits, 0, 0, &tv) <= 0)
  193655. return 0; // (timeout)
  193656. const int bytesRead = jmax (0, (int) recv (socketHandle, buffer, bytesToRead, MSG_WAITALL));
  193657. readPosition += bytesRead;
  193658. return bytesRead;
  193659. }
  193660. int readPosition;
  193661. juce_UseDebuggingNewOperator
  193662. private:
  193663. int socketHandle, levelsOfRedirection;
  193664. const int timeoutSeconds;
  193665. void closeSocket()
  193666. {
  193667. if (socketHandle >= 0)
  193668. close (socketHandle);
  193669. socketHandle = -1;
  193670. }
  193671. const MemoryBlock createRequestHeader (const String& hostName,
  193672. const int hostPort,
  193673. const String& proxyName,
  193674. const int proxyPort,
  193675. const String& hostPath,
  193676. const String& originalURL,
  193677. const String& headers,
  193678. const MemoryBlock& postData,
  193679. const bool isPost)
  193680. {
  193681. String header (isPost ? "POST " : "GET ");
  193682. if (proxyName.isEmpty())
  193683. {
  193684. header << hostPath << " HTTP/1.0\r\nHost: "
  193685. << hostName << ':' << hostPort;
  193686. }
  193687. else
  193688. {
  193689. header << originalURL << " HTTP/1.0\r\nHost: "
  193690. << proxyName << ':' << proxyPort;
  193691. }
  193692. header << "\r\nUser-Agent: JUCE/"
  193693. << JUCE_MAJOR_VERSION << '.' << JUCE_MINOR_VERSION
  193694. << "\r\nConnection: Close\r\nContent-Length: "
  193695. << postData.getSize() << "\r\n"
  193696. << headers << "\r\n";
  193697. MemoryBlock mb;
  193698. mb.append (header.toUTF8(), (int) strlen (header.toUTF8()));
  193699. mb.append (postData.getData(), postData.getSize());
  193700. return mb;
  193701. }
  193702. const String readResponse (const uint32 timeOutTime)
  193703. {
  193704. int bytesRead = 0, numConsecutiveLFs = 0;
  193705. MemoryBlock buffer (1024, true);
  193706. while (numConsecutiveLFs < 2 && bytesRead < 32768
  193707. && Time::getMillisecondCounter() <= timeOutTime)
  193708. {
  193709. fd_set readbits;
  193710. FD_ZERO (&readbits);
  193711. FD_SET (socketHandle, &readbits);
  193712. struct timeval tv;
  193713. tv.tv_sec = timeoutSeconds;
  193714. tv.tv_usec = 0;
  193715. if (select (socketHandle + 1, &readbits, 0, 0, &tv) <= 0)
  193716. return String::empty; // (timeout)
  193717. buffer.ensureSize (bytesRead + 8, true);
  193718. char* const dest = (char*) buffer.getData() + bytesRead;
  193719. if (recv (socketHandle, dest, 1, 0) == -1)
  193720. return String::empty;
  193721. const char lastByte = *dest;
  193722. ++bytesRead;
  193723. if (lastByte == '\n')
  193724. ++numConsecutiveLFs;
  193725. else if (lastByte != '\r')
  193726. numConsecutiveLFs = 0;
  193727. }
  193728. const String header (String::fromUTF8 ((const char*) buffer.getData()));
  193729. if (header.startsWithIgnoreCase (T("HTTP/")))
  193730. return header.trimEnd();
  193731. return String::empty;
  193732. }
  193733. static bool decomposeURL (const String& url,
  193734. String& host, String& path, int& port)
  193735. {
  193736. if (! url.startsWithIgnoreCase (T("http://")))
  193737. return false;
  193738. const int nextSlash = url.indexOfChar (7, '/');
  193739. int nextColon = url.indexOfChar (7, ':');
  193740. if (nextColon > nextSlash && nextSlash > 0)
  193741. nextColon = -1;
  193742. if (nextColon >= 0)
  193743. {
  193744. host = url.substring (7, nextColon);
  193745. if (nextSlash >= 0)
  193746. port = url.substring (nextColon + 1, nextSlash).getIntValue();
  193747. else
  193748. port = url.substring (nextColon + 1).getIntValue();
  193749. }
  193750. else
  193751. {
  193752. port = 80;
  193753. if (nextSlash >= 0)
  193754. host = url.substring (7, nextSlash);
  193755. else
  193756. host = url.substring (7);
  193757. }
  193758. if (nextSlash >= 0)
  193759. path = url.substring (nextSlash);
  193760. else
  193761. path = T("/");
  193762. return true;
  193763. }
  193764. static const String findHeaderItem (const StringArray& lines, const String& itemName)
  193765. {
  193766. for (int i = 0; i < lines.size(); ++i)
  193767. if (lines[i].startsWithIgnoreCase (itemName))
  193768. return lines[i].substring (itemName.length()).trim();
  193769. return String::empty;
  193770. }
  193771. };
  193772. bool juce_isOnLine()
  193773. {
  193774. return true;
  193775. }
  193776. void* juce_openInternetFile (const String& url,
  193777. const String& headers,
  193778. const MemoryBlock& postData,
  193779. const bool isPost,
  193780. URL::OpenStreamProgressCallback* callback,
  193781. void* callbackContext,
  193782. int timeOutMs)
  193783. {
  193784. JUCE_HTTPSocketStream* const s = new JUCE_HTTPSocketStream();
  193785. if (s->open (url, headers, postData, isPost,
  193786. callback, callbackContext, timeOutMs))
  193787. return s;
  193788. delete s;
  193789. return 0;
  193790. }
  193791. void juce_closeInternetFile (void* handle)
  193792. {
  193793. JUCE_HTTPSocketStream* const s = (JUCE_HTTPSocketStream*) handle;
  193794. if (s != 0)
  193795. delete s;
  193796. }
  193797. int juce_readFromInternetFile (void* handle, void* buffer, int bytesToRead)
  193798. {
  193799. JUCE_HTTPSocketStream* const s = (JUCE_HTTPSocketStream*) handle;
  193800. if (s != 0)
  193801. return s->read (buffer, bytesToRead);
  193802. return 0;
  193803. }
  193804. int64 juce_getInternetFileContentLength (void* handle)
  193805. {
  193806. JUCE_HTTPSocketStream* const s = (JUCE_HTTPSocketStream*) handle;
  193807. if (s != 0)
  193808. {
  193809. //xxx todo
  193810. jassertfalse
  193811. }
  193812. return -1;
  193813. }
  193814. int juce_seekInInternetFile (void* handle, int newPosition)
  193815. {
  193816. JUCE_HTTPSocketStream* const s = (JUCE_HTTPSocketStream*) handle;
  193817. if (s != 0)
  193818. return s->readPosition;
  193819. return 0;
  193820. }
  193821. #endif
  193822. /*** End of inlined file: juce_linux_Network.cpp ***/
  193823. /*** Start of inlined file: juce_linux_SystemStats.cpp ***/
  193824. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  193825. // compiled on its own).
  193826. #if JUCE_INCLUDED_FILE
  193827. void Logger::outputDebugString (const String& text) throw()
  193828. {
  193829. std::cerr << text << std::endl;
  193830. }
  193831. SystemStats::OperatingSystemType SystemStats::getOperatingSystemType() throw()
  193832. {
  193833. return Linux;
  193834. }
  193835. const String SystemStats::getOperatingSystemName() throw()
  193836. {
  193837. return T("Linux");
  193838. }
  193839. bool SystemStats::isOperatingSystem64Bit() throw()
  193840. {
  193841. #if JUCE_64BIT
  193842. return true;
  193843. #else
  193844. //xxx not sure how to find this out?..
  193845. return false;
  193846. #endif
  193847. }
  193848. static const String getCpuInfo (const char* key, bool lastOne = false) throw()
  193849. {
  193850. String info;
  193851. char buf [256];
  193852. FILE* f = fopen ("/proc/cpuinfo", "r");
  193853. while (f != 0 && fgets (buf, sizeof(buf), f))
  193854. {
  193855. if (strncmp (buf, key, strlen (key)) == 0)
  193856. {
  193857. char* p = buf;
  193858. while (*p && *p != '\n')
  193859. ++p;
  193860. if (*p != 0)
  193861. *p = 0;
  193862. p = buf;
  193863. while (*p != 0 && *p != ':')
  193864. ++p;
  193865. if (*p != 0 && *(p + 1) != 0)
  193866. info = p + 2;
  193867. if (! lastOne)
  193868. break;
  193869. }
  193870. }
  193871. fclose (f);
  193872. return info;
  193873. }
  193874. bool SystemStats::hasMMX() throw()
  193875. {
  193876. return getCpuInfo ("flags").contains (T("mmx"));
  193877. }
  193878. bool SystemStats::hasSSE() throw()
  193879. {
  193880. return getCpuInfo ("flags").contains (T("sse"));
  193881. }
  193882. bool SystemStats::hasSSE2() throw()
  193883. {
  193884. return getCpuInfo ("flags").contains (T("sse2"));
  193885. }
  193886. bool SystemStats::has3DNow() throw()
  193887. {
  193888. return getCpuInfo ("flags").contains (T("3dnow"));
  193889. }
  193890. const String SystemStats::getCpuVendor() throw()
  193891. {
  193892. return getCpuInfo ("vendor_id");
  193893. }
  193894. int SystemStats::getCpuSpeedInMegaherz() throw()
  193895. {
  193896. const String speed (getCpuInfo ("cpu MHz"));
  193897. return (int) (speed.getFloatValue() + 0.5f);
  193898. }
  193899. int SystemStats::getMemorySizeInMegabytes() throw()
  193900. {
  193901. struct sysinfo sysi;
  193902. if (sysinfo (&sysi) == 0)
  193903. return (sysi.totalram * sysi.mem_unit / (1024 * 1024));
  193904. return 0;
  193905. }
  193906. uint32 juce_millisecondsSinceStartup() throw()
  193907. {
  193908. static unsigned int calibrate = 0;
  193909. static bool calibrated = false;
  193910. timeval t;
  193911. unsigned int ret = 0;
  193912. if (! gettimeofday (&t, 0))
  193913. {
  193914. if (! calibrated)
  193915. {
  193916. struct sysinfo sysi;
  193917. if (sysinfo (&sysi) == 0)
  193918. // Safe to assume system was not brought up earlier than 1970!
  193919. calibrate = t.tv_sec - sysi.uptime;
  193920. calibrated = true;
  193921. }
  193922. ret = 1000 * (t.tv_sec - calibrate) + (t.tv_usec / 1000);
  193923. }
  193924. return ret;
  193925. }
  193926. double Time::getMillisecondCounterHiRes() throw()
  193927. {
  193928. return getHighResolutionTicks() * 0.001;
  193929. }
  193930. int64 Time::getHighResolutionTicks() throw()
  193931. {
  193932. timeval t;
  193933. if (gettimeofday (&t, 0))
  193934. return 0;
  193935. return ((int64) t.tv_sec * (int64) 1000000) + (int64) t.tv_usec;
  193936. }
  193937. int64 Time::getHighResolutionTicksPerSecond() throw()
  193938. {
  193939. // Microseconds
  193940. return 1000000;
  193941. }
  193942. bool Time::setSystemTimeToThisTime() const throw()
  193943. {
  193944. timeval t;
  193945. t.tv_sec = millisSinceEpoch % 1000000;
  193946. t.tv_usec = millisSinceEpoch - t.tv_sec;
  193947. return settimeofday (&t, NULL) ? false : true;
  193948. }
  193949. int SystemStats::getPageSize() throw()
  193950. {
  193951. static int systemPageSize = 0;
  193952. if (systemPageSize == 0)
  193953. systemPageSize = sysconf (_SC_PAGESIZE);
  193954. return systemPageSize;
  193955. }
  193956. int SystemStats::getNumCpus() throw()
  193957. {
  193958. const int lastCpu = getCpuInfo ("processor", true).getIntValue();
  193959. return lastCpu + 1;
  193960. }
  193961. const String SystemStats::getLogonName()
  193962. {
  193963. const char* user = getenv ("USER");
  193964. if (user == 0)
  193965. {
  193966. struct passwd* const pw = getpwuid (getuid());
  193967. if (pw != 0)
  193968. user = pw->pw_name;
  193969. }
  193970. return String::fromUTF8 (user);
  193971. }
  193972. const String SystemStats::getFullUserName()
  193973. {
  193974. return getLogonName();
  193975. }
  193976. void SystemStats::initialiseStats() throw()
  193977. {
  193978. // Process starts off as root when running suid
  193979. Process::lowerPrivilege();
  193980. String s (SystemStats::getJUCEVersion());
  193981. }
  193982. void PlatformUtilities::fpuReset()
  193983. {
  193984. }
  193985. #endif
  193986. /*** End of inlined file: juce_linux_SystemStats.cpp ***/
  193987. /*** Start of inlined file: juce_linux_Threads.cpp ***/
  193988. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  193989. // compiled on its own).
  193990. #if JUCE_INCLUDED_FILE
  193991. void JUCE_API juce_threadEntryPoint (void*);
  193992. void* threadEntryProc (void* value)
  193993. {
  193994. // New threads start off as root when running suid
  193995. Process::lowerPrivilege();
  193996. juce_threadEntryPoint (value);
  193997. return 0;
  193998. }
  193999. void* juce_createThread (void* userData)
  194000. {
  194001. pthread_t handle = 0;
  194002. if (pthread_create (&handle, 0, threadEntryProc, userData) == 0)
  194003. {
  194004. pthread_detach (handle);
  194005. return (void*)handle;
  194006. }
  194007. return 0;
  194008. }
  194009. void juce_killThread (void* handle)
  194010. {
  194011. if (handle != 0)
  194012. pthread_cancel ((pthread_t)handle);
  194013. }
  194014. void juce_setCurrentThreadName (const String& /*name*/)
  194015. {
  194016. }
  194017. Thread::ThreadID Thread::getCurrentThreadId()
  194018. {
  194019. return (ThreadID) pthread_self();
  194020. }
  194021. // priority 1 to 10 where 5=normal, 1=low. If the handle is 0, sets the
  194022. // priority of the current thread
  194023. bool juce_setThreadPriority (void* handle, int priority)
  194024. {
  194025. struct sched_param param;
  194026. int policy, maxp, minp, pri;
  194027. if (handle == 0)
  194028. handle = (void*) pthread_self();
  194029. if (pthread_getschedparam ((pthread_t) handle, &policy, &param) == 0
  194030. && policy != SCHED_OTHER)
  194031. {
  194032. minp = sched_get_priority_min(policy);
  194033. maxp = sched_get_priority_max(policy);
  194034. pri = ((maxp - minp) / 2) * (priority - 1) / 9;
  194035. if (param.__sched_priority >= (minp + (maxp - minp) / 2))
  194036. // Realtime process priority
  194037. param.__sched_priority = minp + ((maxp - minp) / 2) + pri;
  194038. else
  194039. // High process priority
  194040. param.__sched_priority = minp + pri;
  194041. param.sched_priority = jlimit (1, 127, 1 + (priority * 126) / 11);
  194042. return pthread_setschedparam ((pthread_t) handle, policy, &param) == 0;
  194043. }
  194044. return false;
  194045. }
  194046. void Thread::setCurrentThreadAffinityMask (const uint32 affinityMask)
  194047. {
  194048. #if SUPPORT_AFFINITIES
  194049. cpu_set_t affinity;
  194050. CPU_ZERO (&affinity);
  194051. for (int i = 0; i < 32; ++i)
  194052. if ((affinityMask & (1 << i)) != 0)
  194053. CPU_SET (i, &affinity);
  194054. sched_setaffinity (getpid(), sizeof (cpu_set_t), &affinity);
  194055. sched_yield();
  194056. #else
  194057. /* affinities aren't supported because either the appropriate header files weren't found,
  194058. or the SUPPORT_AFFINITIES macro was turned off in linuxheaders.h
  194059. */
  194060. jassertfalse
  194061. #endif
  194062. }
  194063. void Thread::yield()
  194064. {
  194065. sched_yield();
  194066. }
  194067. // sets the process to 0=low priority, 1=normal, 2=high, 3=realtime
  194068. void Process::setPriority (ProcessPriority prior)
  194069. {
  194070. struct sched_param param;
  194071. int policy, maxp, minp;
  194072. const int p = (int) prior;
  194073. if (p <= 1)
  194074. policy = SCHED_OTHER;
  194075. else
  194076. policy = SCHED_RR;
  194077. minp = sched_get_priority_min (policy);
  194078. maxp = sched_get_priority_max (policy);
  194079. if (p < 2)
  194080. param.__sched_priority = 0;
  194081. else if (p == 2 )
  194082. // Set to middle of lower realtime priority range
  194083. param.__sched_priority = minp + (maxp - minp) / 4;
  194084. else
  194085. // Set to middle of higher realtime priority range
  194086. param.__sched_priority = minp + (3 * (maxp - minp) / 4);
  194087. pthread_setschedparam (pthread_self(), policy, &param);
  194088. }
  194089. void Process::terminate()
  194090. {
  194091. exit (0);
  194092. }
  194093. bool JUCE_PUBLIC_FUNCTION juce_isRunningUnderDebugger()
  194094. {
  194095. static char testResult = 0;
  194096. if (testResult == 0)
  194097. {
  194098. testResult = (char) ptrace (PT_TRACE_ME, 0, 0, 0);
  194099. if (testResult >= 0)
  194100. {
  194101. ptrace (PT_DETACH, 0, (caddr_t) 1, 0);
  194102. testResult = 1;
  194103. }
  194104. }
  194105. return testResult < 0;
  194106. }
  194107. bool JUCE_CALLTYPE Process::isRunningUnderDebugger()
  194108. {
  194109. return juce_isRunningUnderDebugger();
  194110. }
  194111. void Process::raisePrivilege()
  194112. {
  194113. // If running suid root, change effective user
  194114. // to root
  194115. if (geteuid() != 0 && getuid() == 0)
  194116. {
  194117. setreuid (geteuid(), getuid());
  194118. setregid (getegid(), getgid());
  194119. }
  194120. }
  194121. void Process::lowerPrivilege()
  194122. {
  194123. // If runing suid root, change effective user
  194124. // back to real user
  194125. if (geteuid() == 0 && getuid() != 0)
  194126. {
  194127. setreuid (geteuid(), getuid());
  194128. setregid (getegid(), getgid());
  194129. }
  194130. }
  194131. #if ! JUCE_ONLY_BUILD_CORE_LIBRARY
  194132. void* PlatformUtilities::loadDynamicLibrary (const String& name)
  194133. {
  194134. return dlopen (name.toUTF8(), RTLD_LOCAL | RTLD_NOW);
  194135. }
  194136. void PlatformUtilities::freeDynamicLibrary (void* handle)
  194137. {
  194138. dlclose(handle);
  194139. }
  194140. void* PlatformUtilities::getProcedureEntryPoint (void* libraryHandle, const String& procedureName)
  194141. {
  194142. return dlsym (libraryHandle, procedureName.toCString());
  194143. }
  194144. #endif
  194145. #endif
  194146. /*** End of inlined file: juce_linux_Threads.cpp ***/
  194147. #if ! JUCE_ONLY_BUILD_CORE_LIBRARY
  194148. /*** Start of inlined file: juce_linux_Clipboard.cpp ***/
  194149. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  194150. // compiled on its own).
  194151. #if JUCE_INCLUDED_FILE
  194152. #ifdef JUCE_DEBUG
  194153. #define JUCE_DEBUG_XERRORS 1
  194154. #endif
  194155. extern Display* display;
  194156. extern Window juce_messageWindowHandle;
  194157. static String localClipboardContent;
  194158. static Atom atom_UTF8_STRING;
  194159. static Atom atom_CLIPBOARD;
  194160. static Atom atom_TARGETS;
  194161. static void initSelectionAtoms()
  194162. {
  194163. static bool isInitialised = false;
  194164. if (! isInitialised)
  194165. {
  194166. atom_UTF8_STRING = XInternAtom (display, "UTF8_STRING", False);
  194167. atom_CLIPBOARD = XInternAtom (display, "CLIPBOARD", False);
  194168. atom_TARGETS = XInternAtom (display, "TARGETS", False);
  194169. }
  194170. }
  194171. // Read the content of a window property as either a locale-dependent string or an utf8 string
  194172. // works only for strings shorter than 1000000 bytes
  194173. static String juce_readWindowProperty (Window window, Atom prop,
  194174. Atom fmt, // XA_STRING or UTF8_STRING
  194175. bool deleteAfterReading)
  194176. {
  194177. String returnData;
  194178. char* clipData;
  194179. Atom actualType;
  194180. int actualFormat;
  194181. unsigned long numItems, bytesLeft;
  194182. if (XGetWindowProperty (display, window, prop,
  194183. 0L /* offset */, 1000000 /* length (max) */, False,
  194184. AnyPropertyType /* format */,
  194185. &actualType, &actualFormat, &numItems, &bytesLeft,
  194186. (unsigned char**) &clipData) == Success)
  194187. {
  194188. if (actualType == atom_UTF8_STRING && actualFormat == 8)
  194189. {
  194190. returnData = String::fromUTF8 (clipData, numItems);
  194191. }
  194192. else if (actualType == XA_STRING && actualFormat == 8)
  194193. {
  194194. returnData = String (clipData, numItems);
  194195. }
  194196. if (clipData != 0)
  194197. XFree (clipData);
  194198. jassert (bytesLeft == 0 || numItems == 1000000);
  194199. }
  194200. if (deleteAfterReading)
  194201. XDeleteProperty (display, window, prop);
  194202. return returnData;
  194203. }
  194204. // Send a SelectionRequest to the window owning the selection and waits for its answer (with a timeout) */
  194205. static bool juce_requestSelectionContent (String &selection_content, Atom selection, Atom requested_format)
  194206. {
  194207. Atom property_name = XInternAtom (display, "JUCE_SEL", false);
  194208. // The selection owner will be asked to set the JUCE_SEL property on the
  194209. // juce_messageWindowHandle with the selection content
  194210. XConvertSelection (display, selection, requested_format, property_name,
  194211. juce_messageWindowHandle, CurrentTime);
  194212. int timeoutMs = 200; // will wait at most for 200 ms
  194213. do
  194214. {
  194215. XEvent event;
  194216. if (XCheckTypedWindowEvent (display, juce_messageWindowHandle, SelectionNotify, &event))
  194217. {
  194218. if (event.xselection.property == property_name)
  194219. {
  194220. jassert (event.xselection.requestor == juce_messageWindowHandle);
  194221. selection_content = juce_readWindowProperty (event.xselection.requestor,
  194222. event.xselection.property,
  194223. requested_format, true);
  194224. return true;
  194225. }
  194226. else
  194227. {
  194228. return false; // the format we asked for was denied.. (event.xselection.property == None)
  194229. }
  194230. }
  194231. // not very elegant.. we could do a select() or something like that...
  194232. // however clipboard content requesting is inherently slow on x11, it
  194233. // often takes 50ms or more so...
  194234. Thread::sleep (4);
  194235. timeoutMs -= 4;
  194236. }
  194237. while (timeoutMs > 0);
  194238. DBG("timeout for juce_requestSelectionContent");
  194239. return false;
  194240. }
  194241. // Called from the event loop in juce_linux_Messaging in response to SelectionRequest events
  194242. void juce_handleSelectionRequest (XSelectionRequestEvent &evt)
  194243. {
  194244. initSelectionAtoms();
  194245. // the selection content is sent to the target window as a window property
  194246. XSelectionEvent reply;
  194247. reply.type = SelectionNotify;
  194248. reply.display = evt.display;
  194249. reply.requestor = evt.requestor;
  194250. reply.selection = evt.selection;
  194251. reply.target = evt.target;
  194252. reply.property = None; // == "fail"
  194253. reply.time = evt.time;
  194254. HeapBlock <char> data;
  194255. int propertyFormat = 0, numDataItems = 0;
  194256. if (evt.selection == XA_PRIMARY || evt.selection == atom_CLIPBOARD)
  194257. {
  194258. if (evt.target == XA_STRING)
  194259. {
  194260. // format data according to system locale
  194261. numDataItems = localClipboardContent.getNumBytesAsCString() + 1;
  194262. data.calloc (numDataItems + 1);
  194263. localClipboardContent.copyToCString (data, numDataItems);
  194264. propertyFormat = 8; // bits/item
  194265. }
  194266. else if (evt.target == atom_UTF8_STRING)
  194267. {
  194268. // translate to utf8
  194269. numDataItems = localClipboardContent.getNumBytesAsUTF8() + 1;
  194270. data.calloc (numDataItems + 1);
  194271. localClipboardContent.copyToUTF8 (data, numDataItems);
  194272. propertyFormat = 8; // bits/item
  194273. }
  194274. else if (evt.target == atom_TARGETS)
  194275. {
  194276. // another application wants to know what we are able to send
  194277. numDataItems = 2;
  194278. propertyFormat = 32; // atoms are 32-bit
  194279. data.calloc (numDataItems * 4);
  194280. Atom* atoms = reinterpret_cast<Atom*> (data.getData());
  194281. atoms[0] = atom_UTF8_STRING;
  194282. atoms[1] = XA_STRING;
  194283. }
  194284. }
  194285. else
  194286. {
  194287. DBG ("requested unsupported clipboard");
  194288. }
  194289. if (data != 0)
  194290. {
  194291. const int maxReasonableSelectionSize = 1000000;
  194292. // for very big chunks of data, we should use the "INCR" protocol , which is a pain in the *ss
  194293. if (evt.property != None && numDataItems < maxReasonableSelectionSize)
  194294. {
  194295. XChangeProperty (evt.display, evt.requestor,
  194296. evt.property, evt.target,
  194297. propertyFormat /* 8 or 32 */, PropModeReplace,
  194298. reinterpret_cast<const unsigned char*> (data.getData()), numDataItems);
  194299. reply.property = evt.property; // " == success"
  194300. }
  194301. }
  194302. XSendEvent (evt.display, evt.requestor, 0, NoEventMask, (XEvent*) &reply);
  194303. }
  194304. void SystemClipboard::copyTextToClipboard (const String& clipText) throw()
  194305. {
  194306. initSelectionAtoms();
  194307. localClipboardContent = clipText;
  194308. XSetSelectionOwner (display, XA_PRIMARY, juce_messageWindowHandle, CurrentTime);
  194309. XSetSelectionOwner (display, atom_CLIPBOARD, juce_messageWindowHandle, CurrentTime);
  194310. }
  194311. const String SystemClipboard::getTextFromClipboard() throw()
  194312. {
  194313. initSelectionAtoms();
  194314. String content;
  194315. Atom selection = XA_PRIMARY;
  194316. Window selectionOwner = None;
  194317. if ((selectionOwner = XGetSelectionOwner (display, selection)) == None)
  194318. {
  194319. selection = atom_CLIPBOARD;
  194320. selectionOwner = XGetSelectionOwner (display, selection);
  194321. }
  194322. if (selectionOwner != None)
  194323. {
  194324. if (selectionOwner == juce_messageWindowHandle)
  194325. {
  194326. content = localClipboardContent;
  194327. }
  194328. else
  194329. {
  194330. // first try: we want an utf8 string
  194331. bool ok = juce_requestSelectionContent (content, selection, atom_UTF8_STRING);
  194332. if (! ok)
  194333. {
  194334. // second chance, ask for a good old locale-dependent string ..
  194335. ok = juce_requestSelectionContent (content, selection, XA_STRING);
  194336. }
  194337. }
  194338. }
  194339. return content;
  194340. }
  194341. #endif
  194342. /*** End of inlined file: juce_linux_Clipboard.cpp ***/
  194343. /*** Start of inlined file: juce_linux_Messaging.cpp ***/
  194344. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  194345. // compiled on its own).
  194346. #if JUCE_INCLUDED_FILE
  194347. #ifdef JUCE_DEBUG
  194348. #define JUCE_DEBUG_XERRORS 1
  194349. #endif
  194350. Display* display = 0; // This is also referenced from WindowDriver.cpp
  194351. Window juce_messageWindowHandle = None;
  194352. XContext improbableNumber; // This is referenced from Windowing.cpp
  194353. extern void juce_windowMessageReceive (XEvent* event); // Defined in Windowing.cpp
  194354. extern void juce_handleSelectionRequest (XSelectionRequestEvent &evt); // Defined in Clipboard.cpp
  194355. ScopedXLock::ScopedXLock() { XLockDisplay (display); }
  194356. ScopedXLock::~ScopedXLock() { XUnlockDisplay (display); }
  194357. class InternalMessageQueue
  194358. {
  194359. public:
  194360. InternalMessageQueue()
  194361. : bytesInSocket (0)
  194362. {
  194363. int ret = ::socketpair (AF_LOCAL, SOCK_STREAM, 0, fd);
  194364. (void) ret; jassert (ret == 0);
  194365. //setNonBlocking (fd[0]);
  194366. //setNonBlocking (fd[1]);
  194367. }
  194368. ~InternalMessageQueue()
  194369. {
  194370. close (fd[0]);
  194371. close (fd[1]);
  194372. }
  194373. void postMessage (Message* msg)
  194374. {
  194375. const int maxBytesInSocketQueue = 128;
  194376. ScopedLock sl (lock);
  194377. queue.add (msg);
  194378. if (bytesInSocket < maxBytesInSocketQueue)
  194379. {
  194380. ++bytesInSocket;
  194381. ScopedUnlock ul (lock);
  194382. const unsigned char x = 0xff;
  194383. size_t bytesWritten = write (fd[0], &x, 1);
  194384. (void) bytesWritten;
  194385. }
  194386. }
  194387. bool isEmpty() const
  194388. {
  194389. ScopedLock sl (lock);
  194390. return queue.size() == 0;
  194391. }
  194392. Message* popNextMessage()
  194393. {
  194394. ScopedLock sl (lock);
  194395. if (bytesInSocket > 0)
  194396. {
  194397. --bytesInSocket;
  194398. ScopedUnlock ul (lock);
  194399. unsigned char x;
  194400. size_t numBytes = read (fd[1], &x, 1);
  194401. (void) numBytes;
  194402. }
  194403. Message* m = queue[0];
  194404. queue.remove (0, false /* deleteObject */);
  194405. return m;
  194406. }
  194407. int getWaitHandle() const { return fd[1]; }
  194408. private:
  194409. CriticalSection lock;
  194410. OwnedArray <Message> queue;
  194411. int fd[2];
  194412. int bytesInSocket;
  194413. static bool setNonBlocking (int handle)
  194414. {
  194415. int socketFlags = fcntl (handle, F_GETFL, 0);
  194416. if (socketFlags == -1)
  194417. return false;
  194418. socketFlags |= O_NONBLOCK;
  194419. return fcntl (handle, F_SETFL, socketFlags) == 0;
  194420. }
  194421. };
  194422. struct MessageThreadFuncCall
  194423. {
  194424. enum { uniqueID = 0x73774623 };
  194425. MessageCallbackFunction* func;
  194426. void* parameter;
  194427. void* result;
  194428. CriticalSection lock;
  194429. WaitableEvent event;
  194430. };
  194431. static InternalMessageQueue* juce_internalMessageQueue = 0;
  194432. // error handling in X11
  194433. static bool errorOccurred = false;
  194434. static bool keyboardBreakOccurred = false;
  194435. static XErrorHandler oldErrorHandler = (XErrorHandler) 0;
  194436. static XIOErrorHandler oldIOErrorHandler = (XIOErrorHandler) 0;
  194437. // Usually happens when client-server connection is broken
  194438. static int ioErrorHandler (Display* display)
  194439. {
  194440. DBG (T("ERROR: connection to X server broken.. terminating."));
  194441. errorOccurred = true;
  194442. if (JUCEApplication::getInstance() != 0)
  194443. Process::terminate();
  194444. return 0;
  194445. }
  194446. // A protocol error has occurred
  194447. static int errorHandler (Display* display, XErrorEvent* event)
  194448. {
  194449. #ifdef JUCE_DEBUG_XERRORS
  194450. char errorStr[64] = { 0 };
  194451. char requestStr[64] = { 0 };
  194452. XGetErrorText (display, event->error_code, errorStr, 64);
  194453. XGetErrorDatabaseText (display, "XRequest", String (event->request_code).toCString(),
  194454. "Unknown", requestStr, 64);
  194455. DBG (T("ERROR: X returned ") + String (errorStr) + T(" for operation ") + String (requestStr));
  194456. #endif
  194457. return 0;
  194458. }
  194459. // Breakin from keyboard
  194460. static void signalHandler (int sig)
  194461. {
  194462. if (sig == SIGINT)
  194463. {
  194464. keyboardBreakOccurred = true;
  194465. return;
  194466. }
  194467. static bool reentrant = false;
  194468. if (! reentrant)
  194469. {
  194470. reentrant = true;
  194471. // Illegal instruction
  194472. fflush (stdout);
  194473. Logger::outputDebugString ("ERROR: Program executed illegal instruction.. terminating");
  194474. errorOccurred = true;
  194475. if (JUCEApplication::getInstance() != 0)
  194476. Process::terminate();
  194477. }
  194478. else
  194479. {
  194480. if (JUCEApplication::getInstance() != 0)
  194481. exit(0);
  194482. }
  194483. }
  194484. void MessageManager::doPlatformSpecificInitialisation()
  194485. {
  194486. // Initialise xlib for multiple thread support
  194487. static bool initThreadCalled = false;
  194488. if (! initThreadCalled)
  194489. {
  194490. if (! XInitThreads())
  194491. {
  194492. // This is fatal! Print error and closedown
  194493. Logger::outputDebugString ("Failed to initialise xlib thread support.");
  194494. if (JUCEApplication::getInstance() != 0)
  194495. Process::terminate();
  194496. return;
  194497. }
  194498. initThreadCalled = true;
  194499. }
  194500. // This is called if the client/server connection is broken
  194501. oldIOErrorHandler = XSetIOErrorHandler (ioErrorHandler);
  194502. // This is called if a protocol error occurs
  194503. oldErrorHandler = XSetErrorHandler (errorHandler);
  194504. // Install signal handler for break-in
  194505. struct sigaction saction;
  194506. sigset_t maskSet;
  194507. sigemptyset (&maskSet);
  194508. saction.sa_handler = signalHandler;
  194509. saction.sa_mask = maskSet;
  194510. saction.sa_flags = 0;
  194511. sigaction (SIGINT, &saction, NULL);
  194512. #ifndef _DEBUG
  194513. // Setup signal handlers for various fatal errors
  194514. sigaction (SIGILL, &saction, NULL);
  194515. sigaction (SIGBUS, &saction, NULL);
  194516. sigaction (SIGFPE, &saction, NULL);
  194517. sigaction (SIGSEGV, &saction, NULL);
  194518. sigaction (SIGSYS, &saction, NULL);
  194519. #endif
  194520. // Create the internal message queue
  194521. juce_internalMessageQueue = new InternalMessageQueue();
  194522. // Try to connect to a display
  194523. String displayName (getenv ("DISPLAY"));
  194524. if (displayName.isEmpty())
  194525. displayName = ":0.0";
  194526. display = XOpenDisplay (displayName.toCString());
  194527. if (display == 0)
  194528. {
  194529. // This is not fatal! we can run headless.
  194530. return;
  194531. }
  194532. // Get defaults for various properties
  194533. int screen = DefaultScreen (display);
  194534. Window root = RootWindow (display, screen);
  194535. Visual* visual = DefaultVisual (display, screen);
  194536. // Create a context to store user data associated with Windows we
  194537. // create in WindowDriver
  194538. improbableNumber = XUniqueContext();
  194539. // We're only interested in client messages for this window
  194540. // which are always sent
  194541. XSetWindowAttributes swa;
  194542. swa.event_mask = NoEventMask;
  194543. // Create our message window (this will never be mapped)
  194544. juce_messageWindowHandle = XCreateWindow (display, root,
  194545. 0, 0, 1, 1, 0, 0, InputOnly,
  194546. visual, CWEventMask, &swa);
  194547. }
  194548. void MessageManager::doPlatformSpecificShutdown()
  194549. {
  194550. deleteAndZero (juce_internalMessageQueue);
  194551. if (display != 0 && ! errorOccurred)
  194552. {
  194553. XDestroyWindow (display, juce_messageWindowHandle);
  194554. XCloseDisplay (display);
  194555. // reset pointers
  194556. juce_messageWindowHandle = 0;
  194557. display = 0;
  194558. // Restore original error handlers
  194559. XSetIOErrorHandler (oldIOErrorHandler);
  194560. oldIOErrorHandler = 0;
  194561. XSetErrorHandler (oldErrorHandler);
  194562. oldErrorHandler = 0;
  194563. }
  194564. }
  194565. bool juce_postMessageToSystemQueue (void* message)
  194566. {
  194567. if (errorOccurred)
  194568. return false;
  194569. juce_internalMessageQueue->postMessage ((Message*) message);
  194570. return true;
  194571. }
  194572. void MessageManager::broadcastMessage (const String& value) throw()
  194573. {
  194574. }
  194575. void* MessageManager::callFunctionOnMessageThread (MessageCallbackFunction* func,
  194576. void* parameter)
  194577. {
  194578. if (errorOccurred)
  194579. return 0;
  194580. if (! isThisTheMessageThread())
  194581. {
  194582. MessageThreadFuncCall messageCallContext;
  194583. messageCallContext.func = func;
  194584. messageCallContext.parameter = parameter;
  194585. juce_internalMessageQueue->postMessage (new Message (MessageThreadFuncCall::uniqueID,
  194586. 0, 0, &messageCallContext));
  194587. // Wait for it to complete before continuing
  194588. messageCallContext.event.wait();
  194589. return messageCallContext.result;
  194590. }
  194591. else
  194592. {
  194593. // Just call the function directly
  194594. return func (parameter);
  194595. }
  194596. }
  194597. // Wait for an event (either XEvent, or an internal Message)
  194598. static bool juce_sleepUntilEvent (const int timeoutMs)
  194599. {
  194600. if (! juce_internalMessageQueue->isEmpty())
  194601. return true;
  194602. if (display != 0)
  194603. {
  194604. ScopedXLock xlock;
  194605. if (XPending (display))
  194606. return true;
  194607. }
  194608. struct timeval tv;
  194609. tv.tv_sec = 0;
  194610. tv.tv_usec = timeoutMs * 1000;
  194611. int fd0 = juce_internalMessageQueue->getWaitHandle();
  194612. int fdmax = fd0;
  194613. fd_set readset;
  194614. FD_ZERO (&readset);
  194615. FD_SET (fd0, &readset);
  194616. if (display != 0)
  194617. {
  194618. ScopedXLock xlock;
  194619. int fd1 = XConnectionNumber (display);
  194620. FD_SET (fd1, &readset);
  194621. fdmax = jmax (fd0, fd1);
  194622. }
  194623. const int ret = select (fdmax + 1, &readset, 0, 0, &tv);
  194624. return (ret > 0); // ret <= 0 if error or timeout
  194625. }
  194626. // Handle next XEvent (if any)
  194627. static bool juce_dispatchNextXEvent()
  194628. {
  194629. if (display == 0)
  194630. return false;
  194631. XEvent evt;
  194632. {
  194633. ScopedXLock xlock;
  194634. if (! XPending (display))
  194635. return false;
  194636. XNextEvent (display, &evt);
  194637. }
  194638. if (evt.type == SelectionRequest && evt.xany.window == juce_messageWindowHandle)
  194639. {
  194640. juce_handleSelectionRequest (evt.xselectionrequest);
  194641. }
  194642. else if (evt.xany.window != juce_messageWindowHandle)
  194643. {
  194644. juce_windowMessageReceive (&evt);
  194645. }
  194646. return true;
  194647. }
  194648. // Handle next internal Message (if any)
  194649. static bool juce_dispatchNextInternalMessage()
  194650. {
  194651. ScopedPointer <Message> msg (juce_internalMessageQueue->popNextMessage());
  194652. if (msg == 0)
  194653. return false;
  194654. if (msg->intParameter1 == MessageThreadFuncCall::uniqueID)
  194655. {
  194656. // Handle callback message
  194657. MessageThreadFuncCall* const call = (MessageThreadFuncCall*) msg->pointerParameter;
  194658. call->result = (*(call->func)) (call->parameter);
  194659. call->event.signal();
  194660. }
  194661. else
  194662. {
  194663. // Handle "normal" messages
  194664. MessageManager::getInstance()->deliverMessage (msg.release());
  194665. }
  194666. return true;
  194667. }
  194668. // this function expects that it will NEVER be called simultaneously for two concurrent threads
  194669. bool juce_dispatchNextMessageOnSystemQueue (bool returnIfNoPendingMessages)
  194670. {
  194671. for (;;)
  194672. {
  194673. if (errorOccurred)
  194674. break;
  194675. if (keyboardBreakOccurred)
  194676. {
  194677. errorOccurred = true;
  194678. if (JUCEApplication::getInstance() != 0)
  194679. Process::terminate();
  194680. break;
  194681. }
  194682. static int totalEventCount = 0;
  194683. ++totalEventCount;
  194684. // The purpose here is to give either priority to XEvents or
  194685. // to internal messages This is necessary to keep a "good"
  194686. // behaviour when the cpu is overloaded
  194687. if (totalEventCount & 1)
  194688. {
  194689. if (juce_dispatchNextXEvent() || juce_dispatchNextInternalMessage())
  194690. return true;
  194691. }
  194692. else
  194693. {
  194694. if (juce_dispatchNextInternalMessage() || juce_dispatchNextXEvent())
  194695. return true;
  194696. }
  194697. if (returnIfNoPendingMessages) // early exit
  194698. break;
  194699. // the timeout is to be on the safe side, but it does not seem to be useful
  194700. juce_sleepUntilEvent (2000);
  194701. }
  194702. return false;
  194703. }
  194704. #endif
  194705. /*** End of inlined file: juce_linux_Messaging.cpp ***/
  194706. /*** Start of inlined file: juce_linux_Fonts.cpp ***/
  194707. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  194708. // compiled on its own).
  194709. #if JUCE_INCLUDED_FILE
  194710. class FreeTypeFontFace
  194711. {
  194712. public:
  194713. enum FontStyle
  194714. {
  194715. Plain = 0,
  194716. Bold = 1,
  194717. Italic = 2
  194718. };
  194719. struct FontNameIndex
  194720. {
  194721. String fileName;
  194722. int faceIndex;
  194723. };
  194724. FreeTypeFontFace (const String& familyName) throw()
  194725. : hasSerif (false),
  194726. monospaced (false)
  194727. {
  194728. family = familyName;
  194729. }
  194730. void setFileName (const String& name, const int faceIndex, FontStyle style) throw()
  194731. {
  194732. if (names [(int) style].fileName.isEmpty())
  194733. {
  194734. names [(int) style].fileName = name;
  194735. names [(int) style].faceIndex = faceIndex;
  194736. }
  194737. }
  194738. const String& getFamilyName() const throw() { return family; }
  194739. const String& getFileName (const int style, int& faceIndex) const throw()
  194740. {
  194741. faceIndex = names[style].faceIndex;
  194742. return names[style].fileName;
  194743. }
  194744. void setMonospaced (bool mono) throw() { monospaced = mono; }
  194745. bool getMonospaced() const throw() { return monospaced; }
  194746. void setSerif (const bool serif) throw() { hasSerif = serif; }
  194747. bool getSerif() const throw() { return hasSerif; }
  194748. private:
  194749. String family;
  194750. FontNameIndex names[4];
  194751. bool hasSerif, monospaced;
  194752. };
  194753. class FreeTypeInterface : public DeletedAtShutdown
  194754. {
  194755. public:
  194756. FreeTypeInterface() throw()
  194757. : lastFace (0),
  194758. lastBold (false),
  194759. lastItalic (false)
  194760. {
  194761. if (FT_Init_FreeType (&ftLib) != 0)
  194762. {
  194763. ftLib = 0;
  194764. DBG (T("Failed to initialize FreeType"));
  194765. }
  194766. StringArray fontDirs;
  194767. fontDirs.addTokens (String::fromUTF8 (getenv ("JUCE_FONT_PATH")), ";,", String::empty);
  194768. fontDirs.removeEmptyStrings (true);
  194769. if (fontDirs.size() == 0)
  194770. {
  194771. XmlDocument fontsConfig (File ("/etc/fonts/fonts.conf"));
  194772. XmlElement* const fontsInfo = fontsConfig.getDocumentElement();
  194773. if (fontsInfo != 0)
  194774. {
  194775. forEachXmlChildElementWithTagName (*fontsInfo, e, T("dir"))
  194776. {
  194777. fontDirs.add (e->getAllSubText().trim());
  194778. }
  194779. delete fontsInfo;
  194780. }
  194781. }
  194782. if (fontDirs.size() == 0)
  194783. fontDirs.add ("/usr/X11R6/lib/X11/fonts");
  194784. for (int i = 0; i < fontDirs.size(); ++i)
  194785. enumerateFaces (fontDirs[i]);
  194786. }
  194787. ~FreeTypeInterface() throw()
  194788. {
  194789. if (lastFace != 0)
  194790. FT_Done_Face (lastFace);
  194791. if (ftLib != 0)
  194792. FT_Done_FreeType (ftLib);
  194793. clearSingletonInstance();
  194794. }
  194795. FreeTypeFontFace* findOrCreate (const String& familyName,
  194796. const bool create = false) throw()
  194797. {
  194798. for (int i = 0; i < faces.size(); i++)
  194799. if (faces[i]->getFamilyName() == familyName)
  194800. return faces[i];
  194801. if (! create)
  194802. return NULL;
  194803. FreeTypeFontFace* newFace = new FreeTypeFontFace (familyName);
  194804. faces.add (newFace);
  194805. return newFace;
  194806. }
  194807. // Enumerate all font faces available in a given directory
  194808. void enumerateFaces (const String& path) throw()
  194809. {
  194810. File dirPath (path);
  194811. if (path.isEmpty() || ! dirPath.isDirectory())
  194812. return;
  194813. DirectoryIterator di (dirPath, true);
  194814. while (di.next())
  194815. {
  194816. File possible (di.getFile());
  194817. if (possible.hasFileExtension (T("ttf"))
  194818. || possible.hasFileExtension (T("pfb"))
  194819. || possible.hasFileExtension (T("pcf")))
  194820. {
  194821. FT_Face face;
  194822. int faceIndex = 0;
  194823. int numFaces = 0;
  194824. do
  194825. {
  194826. if (FT_New_Face (ftLib, possible.getFullPathName().toUTF8(),
  194827. faceIndex, &face) == 0)
  194828. {
  194829. if (faceIndex == 0)
  194830. numFaces = face->num_faces;
  194831. if ((face->face_flags & FT_FACE_FLAG_SCALABLE) != 0)
  194832. {
  194833. FreeTypeFontFace* const newFace = findOrCreate (face->family_name, true);
  194834. int style = (int) FreeTypeFontFace::Plain;
  194835. if ((face->style_flags & FT_STYLE_FLAG_BOLD) != 0)
  194836. style |= (int) FreeTypeFontFace::Bold;
  194837. if ((face->style_flags & FT_STYLE_FLAG_ITALIC) != 0)
  194838. style |= (int) FreeTypeFontFace::Italic;
  194839. newFace->setFileName (possible.getFullPathName(), faceIndex, (FreeTypeFontFace::FontStyle) style);
  194840. newFace->setMonospaced ((face->face_flags & FT_FACE_FLAG_FIXED_WIDTH) != 0);
  194841. // Surely there must be a better way to do this?
  194842. const String name (face->family_name);
  194843. newFace->setSerif (! (name.containsIgnoreCase (T("Sans"))
  194844. || name.containsIgnoreCase (T("Verdana"))
  194845. || name.containsIgnoreCase (T("Arial"))));
  194846. }
  194847. FT_Done_Face (face);
  194848. }
  194849. ++faceIndex;
  194850. }
  194851. while (faceIndex < numFaces);
  194852. }
  194853. }
  194854. }
  194855. // Create a FreeType face object for a given font
  194856. FT_Face createFT_Face (const String& fontName,
  194857. const bool bold,
  194858. const bool italic) throw()
  194859. {
  194860. FT_Face face = 0;
  194861. if (fontName == lastFontName && bold == lastBold && italic == lastItalic)
  194862. {
  194863. face = lastFace;
  194864. }
  194865. else
  194866. {
  194867. if (lastFace != 0)
  194868. {
  194869. FT_Done_Face (lastFace);
  194870. lastFace = 0;
  194871. }
  194872. lastFontName = fontName;
  194873. lastBold = bold;
  194874. lastItalic = italic;
  194875. FreeTypeFontFace* const ftFace = findOrCreate (fontName);
  194876. if (ftFace != 0)
  194877. {
  194878. int style = (int) FreeTypeFontFace::Plain;
  194879. if (bold)
  194880. style |= (int) FreeTypeFontFace::Bold;
  194881. if (italic)
  194882. style |= (int) FreeTypeFontFace::Italic;
  194883. int faceIndex;
  194884. String fileName (ftFace->getFileName (style, faceIndex));
  194885. if (fileName.isEmpty())
  194886. {
  194887. style ^= (int) FreeTypeFontFace::Bold;
  194888. fileName = ftFace->getFileName (style, faceIndex);
  194889. if (fileName.isEmpty())
  194890. {
  194891. style ^= (int) FreeTypeFontFace::Bold;
  194892. style ^= (int) FreeTypeFontFace::Italic;
  194893. fileName = ftFace->getFileName (style, faceIndex);
  194894. if (! fileName.length())
  194895. {
  194896. style ^= (int) FreeTypeFontFace::Bold;
  194897. fileName = ftFace->getFileName (style, faceIndex);
  194898. }
  194899. }
  194900. }
  194901. if (! FT_New_Face (ftLib, fileName.toUTF8(), faceIndex, &lastFace))
  194902. {
  194903. face = lastFace;
  194904. // If there isn't a unicode charmap then select the first one.
  194905. if (FT_Select_Charmap (face, ft_encoding_unicode))
  194906. FT_Set_Charmap (face, face->charmaps[0]);
  194907. }
  194908. }
  194909. }
  194910. return face;
  194911. }
  194912. bool addGlyph (FT_Face face, CustomTypeface& dest, uint32 character) throw()
  194913. {
  194914. const unsigned int glyphIndex = FT_Get_Char_Index (face, character);
  194915. const float height = (float) (face->ascender - face->descender);
  194916. const float scaleX = 1.0f / height;
  194917. const float scaleY = -1.0f / height;
  194918. Path destShape;
  194919. if (FT_Load_Glyph (face, glyphIndex, FT_LOAD_NO_SCALE | FT_LOAD_NO_BITMAP | FT_LOAD_IGNORE_TRANSFORM) != 0
  194920. || face->glyph->format != ft_glyph_format_outline)
  194921. {
  194922. return false;
  194923. }
  194924. const FT_Outline* const outline = &face->glyph->outline;
  194925. const short* const contours = outline->contours;
  194926. const char* const tags = outline->tags;
  194927. FT_Vector* const points = outline->points;
  194928. for (int c = 0; c < outline->n_contours; c++)
  194929. {
  194930. const int startPoint = (c == 0) ? 0 : contours [c - 1] + 1;
  194931. const int endPoint = contours[c];
  194932. for (int p = startPoint; p <= endPoint; p++)
  194933. {
  194934. const float x = scaleX * points[p].x;
  194935. const float y = scaleY * points[p].y;
  194936. if (p == startPoint)
  194937. {
  194938. if (FT_CURVE_TAG (tags[p]) == FT_Curve_Tag_Conic)
  194939. {
  194940. float x2 = scaleX * points [endPoint].x;
  194941. float y2 = scaleY * points [endPoint].y;
  194942. if (FT_CURVE_TAG (tags[endPoint]) != FT_Curve_Tag_On)
  194943. {
  194944. x2 = (x + x2) * 0.5f;
  194945. y2 = (y + y2) * 0.5f;
  194946. }
  194947. destShape.startNewSubPath (x2, y2);
  194948. }
  194949. else
  194950. {
  194951. destShape.startNewSubPath (x, y);
  194952. }
  194953. }
  194954. if (FT_CURVE_TAG (tags[p]) == FT_Curve_Tag_On)
  194955. {
  194956. if (p != startPoint)
  194957. destShape.lineTo (x, y);
  194958. }
  194959. else if (FT_CURVE_TAG (tags[p]) == FT_Curve_Tag_Conic)
  194960. {
  194961. const int nextIndex = (p == endPoint) ? startPoint : p + 1;
  194962. float x2 = scaleX * points [nextIndex].x;
  194963. float y2 = scaleY * points [nextIndex].y;
  194964. if (FT_CURVE_TAG (tags [nextIndex]) == FT_Curve_Tag_Conic)
  194965. {
  194966. x2 = (x + x2) * 0.5f;
  194967. y2 = (y + y2) * 0.5f;
  194968. }
  194969. else
  194970. {
  194971. ++p;
  194972. }
  194973. destShape.quadraticTo (x, y, x2, y2);
  194974. }
  194975. else if (FT_CURVE_TAG (tags[p]) == FT_Curve_Tag_Cubic)
  194976. {
  194977. if (p >= endPoint)
  194978. return false;
  194979. const int next1 = p + 1;
  194980. const int next2 = (p == (endPoint - 1)) ? startPoint : p + 2;
  194981. const float x2 = scaleX * points [next1].x;
  194982. const float y2 = scaleY * points [next1].y;
  194983. const float x3 = scaleX * points [next2].x;
  194984. const float y3 = scaleY * points [next2].y;
  194985. if (FT_CURVE_TAG (tags[next1]) != FT_Curve_Tag_Cubic
  194986. || FT_CURVE_TAG (tags[next2]) != FT_Curve_Tag_On)
  194987. return false;
  194988. destShape.cubicTo (x, y, x2, y2, x3, y3);
  194989. p += 2;
  194990. }
  194991. }
  194992. destShape.closeSubPath();
  194993. }
  194994. dest.addGlyph (character, destShape, face->glyph->metrics.horiAdvance / height);
  194995. if ((face->face_flags & FT_FACE_FLAG_KERNING) != 0)
  194996. addKerning (face, dest, character, glyphIndex);
  194997. return true;
  194998. }
  194999. void addKerning (FT_Face face, CustomTypeface& dest, const uint32 character, const uint32 glyphIndex) throw()
  195000. {
  195001. const float height = (float) (face->ascender - face->descender);
  195002. uint32 rightGlyphIndex;
  195003. uint32 rightCharCode = FT_Get_First_Char (face, &rightGlyphIndex);
  195004. while (rightGlyphIndex != 0)
  195005. {
  195006. FT_Vector kerning;
  195007. if (FT_Get_Kerning (face, glyphIndex, rightGlyphIndex, ft_kerning_unscaled, &kerning) == 0)
  195008. {
  195009. if (kerning.x != 0)
  195010. dest.addKerningPair (character, rightCharCode, kerning.x / height);
  195011. }
  195012. rightCharCode = FT_Get_Next_Char (face, rightCharCode, &rightGlyphIndex);
  195013. }
  195014. }
  195015. // Add a glyph to a font
  195016. bool addGlyphToFont (const uint32 character,
  195017. const tchar* fontName, bool bold, bool italic,
  195018. CustomTypeface& dest) throw()
  195019. {
  195020. FT_Face face = createFT_Face (fontName, bold, italic);
  195021. if (face != 0)
  195022. return addGlyph (face, dest, character);
  195023. return false;
  195024. }
  195025. void getFamilyNames (StringArray& familyNames) const throw()
  195026. {
  195027. for (int i = 0; i < faces.size(); i++)
  195028. familyNames.add (faces[i]->getFamilyName());
  195029. }
  195030. void getMonospacedNames (StringArray& monoSpaced) const throw()
  195031. {
  195032. for (int i = 0; i < faces.size(); i++)
  195033. if (faces[i]->getMonospaced())
  195034. monoSpaced.add (faces[i]->getFamilyName());
  195035. }
  195036. void getSerifNames (StringArray& serif) const throw()
  195037. {
  195038. for (int i = 0; i < faces.size(); i++)
  195039. if (faces[i]->getSerif())
  195040. serif.add (faces[i]->getFamilyName());
  195041. }
  195042. void getSansSerifNames (StringArray& sansSerif) const throw()
  195043. {
  195044. for (int i = 0; i < faces.size(); i++)
  195045. if (! faces[i]->getSerif())
  195046. sansSerif.add (faces[i]->getFamilyName());
  195047. }
  195048. juce_DeclareSingleton_SingleThreaded_Minimal (FreeTypeInterface)
  195049. private:
  195050. FT_Library ftLib;
  195051. FT_Face lastFace;
  195052. String lastFontName;
  195053. bool lastBold, lastItalic;
  195054. OwnedArray<FreeTypeFontFace> faces;
  195055. };
  195056. juce_ImplementSingleton_SingleThreaded (FreeTypeInterface)
  195057. class FreetypeTypeface : public CustomTypeface
  195058. {
  195059. public:
  195060. FreetypeTypeface (const Font& font)
  195061. {
  195062. FT_Face face = FreeTypeInterface::getInstance()
  195063. ->createFT_Face (font.getTypefaceName(), font.isBold(), font.isItalic());
  195064. if (face == 0)
  195065. {
  195066. #ifdef JUCE_DEBUG
  195067. String msg (T("Failed to create typeface: "));
  195068. msg << font.getTypefaceName() << " " << (font.isBold() ? 'B' : ' ') << (font.isItalic() ? 'I' : ' ');
  195069. DBG (msg);
  195070. #endif
  195071. }
  195072. else
  195073. {
  195074. setCharacteristics (font.getTypefaceName(),
  195075. face->ascender / (float) (face->ascender - face->descender),
  195076. font.isBold(), font.isItalic(),
  195077. L' ');
  195078. }
  195079. }
  195080. bool loadGlyphIfPossible (const juce_wchar character)
  195081. {
  195082. return FreeTypeInterface::getInstance()
  195083. ->addGlyphToFont (character, name, isBold, isItalic, *this);
  195084. }
  195085. };
  195086. const Typeface::Ptr Typeface::createSystemTypefaceFor (const Font& font)
  195087. {
  195088. return new FreetypeTypeface (font);
  195089. }
  195090. const StringArray Font::findAllTypefaceNames() throw()
  195091. {
  195092. StringArray s;
  195093. FreeTypeInterface::getInstance()->getFamilyNames (s);
  195094. s.sort (true);
  195095. return s;
  195096. }
  195097. static const String pickBestFont (const StringArray& names,
  195098. const char* const choicesString)
  195099. {
  195100. StringArray choices;
  195101. choices.addTokens (String (choicesString), ",", String::empty);
  195102. choices.trim();
  195103. choices.removeEmptyStrings();
  195104. int i, j;
  195105. for (j = 0; j < choices.size(); ++j)
  195106. if (names.contains (choices[j], true))
  195107. return choices[j];
  195108. for (j = 0; j < choices.size(); ++j)
  195109. for (i = 0; i < names.size(); i++)
  195110. if (names[i].startsWithIgnoreCase (choices[j]))
  195111. return names[i];
  195112. for (j = 0; j < choices.size(); ++j)
  195113. for (i = 0; i < names.size(); i++)
  195114. if (names[i].containsIgnoreCase (choices[j]))
  195115. return names[i];
  195116. return names[0];
  195117. }
  195118. static const String linux_getDefaultSansSerifFontName()
  195119. {
  195120. StringArray allFonts;
  195121. FreeTypeInterface::getInstance()->getSansSerifNames (allFonts);
  195122. return pickBestFont (allFonts, "Verdana, Bitstream Vera Sans, Luxi Sans, Sans");
  195123. }
  195124. static const String linux_getDefaultSerifFontName()
  195125. {
  195126. StringArray allFonts;
  195127. FreeTypeInterface::getInstance()->getSerifNames (allFonts);
  195128. return pickBestFont (allFonts, "Bitstream Vera Serif, Times, Nimbus Roman, Serif");
  195129. }
  195130. static const String linux_getDefaultMonospacedFontName()
  195131. {
  195132. StringArray allFonts;
  195133. FreeTypeInterface::getInstance()->getMonospacedNames (allFonts);
  195134. return pickBestFont (allFonts, "Bitstream Vera Sans Mono, Courier, Sans Mono, Mono");
  195135. }
  195136. void Font::getPlatformDefaultFontNames (String& defaultSans, String& defaultSerif, String& defaultFixed) throw()
  195137. {
  195138. defaultSans = linux_getDefaultSansSerifFontName();
  195139. defaultSerif = linux_getDefaultSerifFontName();
  195140. defaultFixed = linux_getDefaultMonospacedFontName();
  195141. }
  195142. #endif
  195143. /*** End of inlined file: juce_linux_Fonts.cpp ***/
  195144. /*** Start of inlined file: juce_linux_Windowing.cpp ***/
  195145. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  195146. // compiled on its own).
  195147. #if JUCE_INCLUDED_FILE
  195148. namespace Atoms
  195149. {
  195150. enum ProtocolItems
  195151. {
  195152. TAKE_FOCUS = 0,
  195153. DELETE_WINDOW = 1
  195154. };
  195155. static Atom Protocols, ProtocolList[2], ChangeState, State,
  195156. ActiveWin, Pid, WindowType, WindowState,
  195157. XdndAware, XdndEnter, XdndLeave, XdndPosition, XdndStatus,
  195158. XdndDrop, XdndFinished, XdndSelection, XdndTypeList, XdndActionList,
  195159. XdndActionDescription, XdndActionCopy,
  195160. allowedActions[5],
  195161. allowedMimeTypes[2];
  195162. const unsigned long DndVersion = 3;
  195163. static void initialiseAtoms()
  195164. {
  195165. static bool atomsInitialised = false;
  195166. if (! atomsInitialised)
  195167. {
  195168. atomsInitialised = true;
  195169. Protocols = XInternAtom (display, "WM_PROTOCOLS", True);
  195170. ProtocolList [TAKE_FOCUS] = XInternAtom (display, "WM_TAKE_FOCUS", True);
  195171. ProtocolList [DELETE_WINDOW] = XInternAtom (display, "WM_DELETE_WINDOW", True);
  195172. ChangeState = XInternAtom (display, "WM_CHANGE_STATE", True);
  195173. State = XInternAtom (display, "WM_STATE", True);
  195174. ActiveWin = XInternAtom (display, "_NET_ACTIVE_WINDOW", False);
  195175. Pid = XInternAtom (display, "_NET_WM_PID", False);
  195176. WindowType = XInternAtom (display, "_NET_WM_WINDOW_TYPE", True);
  195177. WindowState = XInternAtom (display, "_NET_WM_WINDOW_STATE", True);
  195178. XdndAware = XInternAtom (display, "XdndAware", False);
  195179. XdndEnter = XInternAtom (display, "XdndEnter", False);
  195180. XdndLeave = XInternAtom (display, "XdndLeave", False);
  195181. XdndPosition = XInternAtom (display, "XdndPosition", False);
  195182. XdndStatus = XInternAtom (display, "XdndStatus", False);
  195183. XdndDrop = XInternAtom (display, "XdndDrop", False);
  195184. XdndFinished = XInternAtom (display, "XdndFinished", False);
  195185. XdndSelection = XInternAtom (display, "XdndSelection", False);
  195186. XdndTypeList = XInternAtom (display, "XdndTypeList", False);
  195187. XdndActionList = XInternAtom (display, "XdndActionList", False);
  195188. XdndActionCopy = XInternAtom (display, "XdndActionCopy", False);
  195189. XdndActionDescription = XInternAtom (display, "XdndActionDescription", False);
  195190. allowedMimeTypes [0] = XInternAtom (display, "text/plain", False);
  195191. allowedMimeTypes [1] = XInternAtom (display, "text/uri-list", False);
  195192. allowedActions [0] = XInternAtom (display, "XdndActionMove", False);
  195193. allowedActions [1] = XdndActionCopy;
  195194. allowedActions [2] = XInternAtom (display, "XdndActionLink", False);
  195195. allowedActions [3] = XInternAtom (display, "XdndActionAsk", False);
  195196. allowedActions [4] = XInternAtom (display, "XdndActionPrivate", False);
  195197. }
  195198. }
  195199. }
  195200. enum SystemTrayValues
  195201. {
  195202. SYSTEM_TRAY_REQUEST_DOCK = 0,
  195203. SYSTEM_TRAY_BEGIN_MESSAGE = 1,
  195204. SYSTEM_TRAY_CANCEL_MESSAGE = 2
  195205. };
  195206. static XErrorHandler oldHandler = 0;
  195207. static int trappedErrorCode = 0;
  195208. extern "C" int errorTrapHandler (Display* dpy, XErrorEvent* err)
  195209. {
  195210. trappedErrorCode = err->error_code;
  195211. return 0;
  195212. }
  195213. static void trapErrors()
  195214. {
  195215. trappedErrorCode = 0;
  195216. oldHandler = XSetErrorHandler (errorTrapHandler);
  195217. }
  195218. static bool untrapErrors()
  195219. {
  195220. XSetErrorHandler (oldHandler);
  195221. return (trappedErrorCode == 0);
  195222. }
  195223. static bool isActiveApplication = false;
  195224. bool Process::isForegroundProcess()
  195225. {
  195226. return isActiveApplication;
  195227. }
  195228. // These are defined in juce_linux_Messaging.cpp
  195229. extern Display* display;
  195230. extern XContext improbableNumber;
  195231. static const int eventMask = NoEventMask | KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask
  195232. | EnterWindowMask | LeaveWindowMask | PointerMotionMask | KeymapStateMask
  195233. | ExposureMask | StructureNotifyMask | FocusChangeMask;
  195234. namespace Keys
  195235. {
  195236. enum MouseButtons
  195237. {
  195238. NoButton = 0,
  195239. LeftButton = 1,
  195240. MiddleButton = 2,
  195241. RightButton = 3,
  195242. WheelUp = 4,
  195243. WheelDown = 5
  195244. };
  195245. static int AltMask = 0;
  195246. static int NumLockMask = 0;
  195247. static bool numLock = false;
  195248. static bool capsLock = false;
  195249. static char keyStates [32];
  195250. static const int extendedKeyModifier = 0x10000000;
  195251. }
  195252. bool KeyPress::isKeyCurrentlyDown (const int keyCode) throw()
  195253. {
  195254. int keysym;
  195255. if (keyCode & Keys::extendedKeyModifier)
  195256. {
  195257. keysym = 0xff00 | (keyCode & 0xff);
  195258. }
  195259. else
  195260. {
  195261. keysym = keyCode;
  195262. if (keysym == (XK_Tab & 0xff)
  195263. || keysym == (XK_Return & 0xff)
  195264. || keysym == (XK_Escape & 0xff)
  195265. || keysym == (XK_BackSpace & 0xff))
  195266. {
  195267. keysym |= 0xff00;
  195268. }
  195269. }
  195270. ScopedXLock xlock;
  195271. const int keycode = XKeysymToKeycode (display, keysym);
  195272. const int keybyte = keycode >> 3;
  195273. const int keybit = (1 << (keycode & 7));
  195274. return (Keys::keyStates [keybyte] & keybit) != 0;
  195275. }
  195276. #if JUCE_USE_XSHM
  195277. static bool isShmAvailable() throw()
  195278. {
  195279. static bool isChecked = false;
  195280. static bool isAvailable = false;
  195281. if (! isChecked)
  195282. {
  195283. isChecked = true;
  195284. int major, minor;
  195285. Bool pixmaps;
  195286. ScopedXLock xlock;
  195287. if (XShmQueryVersion (display, &major, &minor, &pixmaps))
  195288. {
  195289. trapErrors();
  195290. XShmSegmentInfo segmentInfo;
  195291. zerostruct (segmentInfo);
  195292. XImage* xImage = XShmCreateImage (display, DefaultVisual (display, DefaultScreen (display)),
  195293. 24, ZPixmap, 0, &segmentInfo, 50, 50);
  195294. if ((segmentInfo.shmid = shmget (IPC_PRIVATE,
  195295. xImage->bytes_per_line * xImage->height,
  195296. IPC_CREAT | 0777)) >= 0)
  195297. {
  195298. segmentInfo.shmaddr = (char*) shmat (segmentInfo.shmid, 0, 0);
  195299. if (segmentInfo.shmaddr != (void*) -1)
  195300. {
  195301. segmentInfo.readOnly = False;
  195302. xImage->data = segmentInfo.shmaddr;
  195303. XSync (display, False);
  195304. if (XShmAttach (display, &segmentInfo) != 0)
  195305. {
  195306. XSync (display, False);
  195307. XShmDetach (display, &segmentInfo);
  195308. isAvailable = true;
  195309. }
  195310. }
  195311. XFlush (display);
  195312. XDestroyImage (xImage);
  195313. shmdt (segmentInfo.shmaddr);
  195314. }
  195315. shmctl (segmentInfo.shmid, IPC_RMID, 0);
  195316. isAvailable &= untrapErrors();
  195317. }
  195318. }
  195319. return isAvailable;
  195320. }
  195321. #endif
  195322. #if JUCE_USE_XRENDER
  195323. namespace XRender
  195324. {
  195325. typedef Status (*tXRenderQueryVersion) (Display*, int*, int*);
  195326. typedef XRenderPictFormat* (*tXrenderFindStandardFormat) (Display*, int);
  195327. typedef XRenderPictFormat* (*tXRenderFindFormat) (Display*, unsigned long, XRenderPictFormat*, int);
  195328. typedef XRenderPictFormat* (*tXRenderFindVisualFormat) (Display*, Visual*);
  195329. static tXRenderQueryVersion xRenderQueryVersion = 0;
  195330. static tXrenderFindStandardFormat xRenderFindStandardFormat = 0;
  195331. static tXRenderFindFormat xRenderFindFormat = 0;
  195332. static tXRenderFindVisualFormat xRenderFindVisualFormat = 0;
  195333. static bool isAvailable()
  195334. {
  195335. static bool isChecked = false;
  195336. static bool isAvailable = false;
  195337. if (! isChecked)
  195338. {
  195339. ScopedXLock xlock;
  195340. isChecked = true;
  195341. if (xRenderQueryVersion == 0)
  195342. {
  195343. void* h = dlopen ("libXrender.so", RTLD_GLOBAL | RTLD_NOW);
  195344. if (h != 0)
  195345. {
  195346. xRenderQueryVersion = (tXRenderQueryVersion) dlsym (h, "XRenderQueryVersion");
  195347. xRenderFindStandardFormat = (tXrenderFindStandardFormat) dlsym (h, "XrenderFindStandardFormat");
  195348. xRenderFindFormat = (tXRenderFindFormat) dlsym (h, "XRenderFindFormat");
  195349. xRenderFindVisualFormat = (tXRenderFindVisualFormat) dlsym (h, "XRenderFindVisualFormat");
  195350. }
  195351. }
  195352. if (xRenderQueryVersion != 0
  195353. && xRenderFindStandardFormat != 0
  195354. && xRenderFindFormat != 0
  195355. && xRenderFindVisualFormat != 0)
  195356. {
  195357. int major, minor;
  195358. if (xRenderQueryVersion (display, &major, &minor))
  195359. isAvailable = true;
  195360. }
  195361. }
  195362. return isAvailable;
  195363. }
  195364. static XRenderPictFormat* findPictureFormat()
  195365. {
  195366. ScopedXLock xlock;
  195367. XRenderPictFormat* pictFormat = 0;
  195368. if (isAvailable())
  195369. {
  195370. pictFormat = xRenderFindStandardFormat (display, PictStandardARGB32);
  195371. if (pictFormat == 0)
  195372. {
  195373. XRenderPictFormat desiredFormat;
  195374. desiredFormat.type = PictTypeDirect;
  195375. desiredFormat.depth = 32;
  195376. desiredFormat.direct.alphaMask = 0xff;
  195377. desiredFormat.direct.redMask = 0xff;
  195378. desiredFormat.direct.greenMask = 0xff;
  195379. desiredFormat.direct.blueMask = 0xff;
  195380. desiredFormat.direct.alpha = 24;
  195381. desiredFormat.direct.red = 16;
  195382. desiredFormat.direct.green = 8;
  195383. desiredFormat.direct.blue = 0;
  195384. pictFormat = xRenderFindFormat (display,
  195385. PictFormatType | PictFormatDepth
  195386. | PictFormatRedMask | PictFormatRed
  195387. | PictFormatGreenMask | PictFormatGreen
  195388. | PictFormatBlueMask | PictFormatBlue
  195389. | PictFormatAlphaMask | PictFormatAlpha,
  195390. &desiredFormat,
  195391. 0);
  195392. }
  195393. }
  195394. return pictFormat;
  195395. }
  195396. }
  195397. #endif
  195398. namespace Visuals
  195399. {
  195400. static Visual* findVisualWithDepth (const int desiredDepth) throw()
  195401. {
  195402. ScopedXLock xlock;
  195403. Visual* visual = 0;
  195404. int numVisuals = 0;
  195405. long desiredMask = VisualNoMask;
  195406. XVisualInfo desiredVisual;
  195407. desiredVisual.screen = DefaultScreen (display);
  195408. desiredVisual.depth = desiredDepth;
  195409. desiredMask = VisualScreenMask | VisualDepthMask;
  195410. if (desiredDepth == 32)
  195411. {
  195412. desiredVisual.c_class = TrueColor;
  195413. desiredVisual.red_mask = 0x00FF0000;
  195414. desiredVisual.green_mask = 0x0000FF00;
  195415. desiredVisual.blue_mask = 0x000000FF;
  195416. desiredVisual.bits_per_rgb = 8;
  195417. desiredMask |= VisualClassMask;
  195418. desiredMask |= VisualRedMaskMask;
  195419. desiredMask |= VisualGreenMaskMask;
  195420. desiredMask |= VisualBlueMaskMask;
  195421. desiredMask |= VisualBitsPerRGBMask;
  195422. }
  195423. XVisualInfo* xvinfos = XGetVisualInfo (display,
  195424. desiredMask,
  195425. &desiredVisual,
  195426. &numVisuals);
  195427. if (xvinfos != 0)
  195428. {
  195429. for (int i = 0; i < numVisuals; i++)
  195430. {
  195431. if (xvinfos[i].depth == desiredDepth)
  195432. {
  195433. visual = xvinfos[i].visual;
  195434. break;
  195435. }
  195436. }
  195437. XFree (xvinfos);
  195438. }
  195439. return visual;
  195440. }
  195441. static Visual* findVisualFormat (const int desiredDepth, int& matchedDepth) throw()
  195442. {
  195443. Visual* visual = 0;
  195444. if (desiredDepth == 32)
  195445. {
  195446. #if JUCE_USE_XSHM
  195447. if (isShmAvailable())
  195448. {
  195449. #if JUCE_USE_XRENDER
  195450. if (XRender::isAvailable())
  195451. {
  195452. XRenderPictFormat* pictFormat = XRender::findPictureFormat();
  195453. if (pictFormat != 0)
  195454. {
  195455. int numVisuals = 0;
  195456. XVisualInfo desiredVisual;
  195457. desiredVisual.screen = DefaultScreen (display);
  195458. desiredVisual.depth = 32;
  195459. desiredVisual.bits_per_rgb = 8;
  195460. XVisualInfo* xvinfos = XGetVisualInfo (display,
  195461. VisualScreenMask | VisualDepthMask | VisualBitsPerRGBMask,
  195462. &desiredVisual, &numVisuals);
  195463. if (xvinfos != 0)
  195464. {
  195465. for (int i = 0; i < numVisuals; ++i)
  195466. {
  195467. XRenderPictFormat* pictVisualFormat = XRender::xRenderFindVisualFormat (display, xvinfos[i].visual);
  195468. if (pictVisualFormat != 0
  195469. && pictVisualFormat->type == PictTypeDirect
  195470. && pictVisualFormat->direct.alphaMask)
  195471. {
  195472. visual = xvinfos[i].visual;
  195473. matchedDepth = 32;
  195474. break;
  195475. }
  195476. }
  195477. XFree (xvinfos);
  195478. }
  195479. }
  195480. }
  195481. #endif
  195482. if (visual == 0)
  195483. {
  195484. visual = findVisualWithDepth (32);
  195485. if (visual != 0)
  195486. matchedDepth = 32;
  195487. }
  195488. }
  195489. #endif
  195490. }
  195491. if (visual == 0 && desiredDepth >= 24)
  195492. {
  195493. visual = findVisualWithDepth (24);
  195494. if (visual != 0)
  195495. matchedDepth = 24;
  195496. }
  195497. if (visual == 0 && desiredDepth >= 16)
  195498. {
  195499. visual = findVisualWithDepth (16);
  195500. if (visual != 0)
  195501. matchedDepth = 16;
  195502. }
  195503. return visual;
  195504. }
  195505. }
  195506. class XBitmapImage : public Image
  195507. {
  195508. public:
  195509. XBitmapImage (const PixelFormat format_, const int w, const int h,
  195510. const bool clearImage, const int imageDepth_, Visual* visual)
  195511. : Image (format_, w, h),
  195512. imageDepth (imageDepth_),
  195513. gc (None)
  195514. {
  195515. jassert (format_ == RGB || format_ == ARGB);
  195516. pixelStride = (format_ == RGB) ? 3 : 4;
  195517. lineStride = ((w * pixelStride + 3) & ~3);
  195518. ScopedXLock xlock;
  195519. #if JUCE_USE_XSHM
  195520. usingXShm = false;
  195521. if ((imageDepth > 16) && isShmAvailable())
  195522. {
  195523. zerostruct (segmentInfo);
  195524. segmentInfo.shmid = -1;
  195525. segmentInfo.shmaddr = (char *) -1;
  195526. segmentInfo.readOnly = False;
  195527. xImage = XShmCreateImage (display, visual, imageDepth, ZPixmap, 0, &segmentInfo, w, h);
  195528. if (xImage != 0)
  195529. {
  195530. if ((segmentInfo.shmid = shmget (IPC_PRIVATE,
  195531. xImage->bytes_per_line * xImage->height,
  195532. IPC_CREAT | 0777)) >= 0)
  195533. {
  195534. if (segmentInfo.shmid != -1)
  195535. {
  195536. segmentInfo.shmaddr = (char*) shmat (segmentInfo.shmid, 0, 0);
  195537. if (segmentInfo.shmaddr != (void*) -1)
  195538. {
  195539. segmentInfo.readOnly = False;
  195540. xImage->data = segmentInfo.shmaddr;
  195541. imageData = (uint8*) segmentInfo.shmaddr;
  195542. if (XShmAttach (display, &segmentInfo) != 0)
  195543. {
  195544. usingXShm = true;
  195545. }
  195546. else
  195547. {
  195548. jassertfalse
  195549. }
  195550. }
  195551. else
  195552. {
  195553. shmctl (segmentInfo.shmid, IPC_RMID, 0);
  195554. }
  195555. }
  195556. }
  195557. }
  195558. }
  195559. if (! usingXShm)
  195560. #endif
  195561. {
  195562. imageDataAllocated.malloc (lineStride * h);
  195563. imageData = imageDataAllocated;
  195564. if (format_ == ARGB && clearImage)
  195565. zeromem (imageData, h * lineStride);
  195566. xImage = (XImage*) juce_calloc (sizeof (XImage));
  195567. xImage->width = w;
  195568. xImage->height = h;
  195569. xImage->xoffset = 0;
  195570. xImage->format = ZPixmap;
  195571. xImage->data = (char*) imageData;
  195572. xImage->byte_order = ImageByteOrder (display);
  195573. xImage->bitmap_unit = BitmapUnit (display);
  195574. xImage->bitmap_bit_order = BitmapBitOrder (display);
  195575. xImage->bitmap_pad = 32;
  195576. xImage->depth = pixelStride * 8;
  195577. xImage->bytes_per_line = lineStride;
  195578. xImage->bits_per_pixel = pixelStride * 8;
  195579. xImage->red_mask = 0x00FF0000;
  195580. xImage->green_mask = 0x0000FF00;
  195581. xImage->blue_mask = 0x000000FF;
  195582. if (imageDepth == 16)
  195583. {
  195584. const int pixelStride = 2;
  195585. const int lineStride = ((w * pixelStride + 3) & ~3);
  195586. imageData16Bit.malloc (lineStride * h);
  195587. xImage->data = imageData16Bit;
  195588. xImage->bitmap_pad = 16;
  195589. xImage->depth = pixelStride * 8;
  195590. xImage->bytes_per_line = lineStride;
  195591. xImage->bits_per_pixel = pixelStride * 8;
  195592. xImage->red_mask = visual->red_mask;
  195593. xImage->green_mask = visual->green_mask;
  195594. xImage->blue_mask = visual->blue_mask;
  195595. }
  195596. if (! XInitImage (xImage))
  195597. {
  195598. jassertfalse
  195599. }
  195600. }
  195601. }
  195602. ~XBitmapImage()
  195603. {
  195604. ScopedXLock xlock;
  195605. #if JUCE_USE_XSHM
  195606. if (usingXShm)
  195607. {
  195608. XShmDetach (display, &segmentInfo);
  195609. XFlush (display);
  195610. XDestroyImage (xImage);
  195611. shmdt (segmentInfo.shmaddr);
  195612. shmctl (segmentInfo.shmid, IPC_RMID, 0);
  195613. }
  195614. else
  195615. #endif
  195616. {
  195617. xImage->data = 0;
  195618. XDestroyImage (xImage);
  195619. }
  195620. }
  195621. void blitToWindow (Window window, int dx, int dy, int dw, int dh, int sx, int sy)
  195622. {
  195623. ScopedXLock xlock;
  195624. if (gc == 0)
  195625. {
  195626. XGCValues gcvalues;
  195627. gcvalues.foreground = None;
  195628. gcvalues.background = None;
  195629. gcvalues.function = GXcopy;
  195630. gcvalues.plane_mask = AllPlanes;
  195631. gcvalues.clip_mask = None;
  195632. gcvalues.graphics_exposures = False;
  195633. gc = XCreateGC (display, window,
  195634. GCBackground | GCForeground | GCFunction | GCPlaneMask | GCClipMask | GCGraphicsExposures,
  195635. &gcvalues);
  195636. }
  195637. if (imageDepth == 16)
  195638. {
  195639. const uint32 rMask = xImage->red_mask;
  195640. const uint32 rShiftL = jmax (0, getShiftNeeded (rMask));
  195641. const uint32 rShiftR = jmax (0, -getShiftNeeded (rMask));
  195642. const uint32 gMask = xImage->green_mask;
  195643. const uint32 gShiftL = jmax (0, getShiftNeeded (gMask));
  195644. const uint32 gShiftR = jmax (0, -getShiftNeeded (gMask));
  195645. const uint32 bMask = xImage->blue_mask;
  195646. const uint32 bShiftL = jmax (0, getShiftNeeded (bMask));
  195647. const uint32 bShiftR = jmax (0, -getShiftNeeded (bMask));
  195648. const Image::BitmapData srcData (*this, 0, 0, getWidth(), getHeight());
  195649. for (int y = sy; y < sy + dh; ++y)
  195650. {
  195651. const uint8* p = srcData.getPixelPointer (sx, y);
  195652. for (int x = sx; x < sx + dw; ++x)
  195653. {
  195654. const PixelRGB* const pixel = (const PixelRGB*) p;
  195655. p += srcData.pixelStride;
  195656. XPutPixel (xImage, x, y,
  195657. (((((uint32) pixel->getRed()) << rShiftL) >> rShiftR) & rMask)
  195658. | (((((uint32) pixel->getGreen()) << gShiftL) >> gShiftR) & gMask)
  195659. | (((((uint32) pixel->getBlue()) << bShiftL) >> bShiftR) & bMask));
  195660. }
  195661. }
  195662. }
  195663. // blit results to screen.
  195664. #if JUCE_USE_XSHM
  195665. if (usingXShm)
  195666. XShmPutImage (display, (::Drawable) window, gc, xImage, sx, sy, dx, dy, dw, dh, True);
  195667. else
  195668. #endif
  195669. XPutImage (display, (::Drawable) window, gc, xImage, sx, sy, dx, dy, dw, dh);
  195670. }
  195671. juce_UseDebuggingNewOperator
  195672. private:
  195673. XImage* xImage;
  195674. const int imageDepth;
  195675. HeapBlock <char> imageData16Bit;
  195676. GC gc;
  195677. #if JUCE_USE_XSHM
  195678. XShmSegmentInfo segmentInfo;
  195679. bool usingXShm;
  195680. #endif
  195681. static int getShiftNeeded (const uint32 mask) throw()
  195682. {
  195683. for (int i = 32; --i >= 0;)
  195684. if (((mask >> i) & 1) != 0)
  195685. return i - 7;
  195686. jassertfalse
  195687. return 0;
  195688. }
  195689. };
  195690. class LinuxComponentPeer : public ComponentPeer
  195691. {
  195692. public:
  195693. LinuxComponentPeer (Component* const component, const int windowStyleFlags)
  195694. : ComponentPeer (component, windowStyleFlags),
  195695. windowH (0),
  195696. parentWindow (0),
  195697. wx (0),
  195698. wy (0),
  195699. ww (0),
  195700. wh (0),
  195701. taskbarImage (0),
  195702. fullScreen (false),
  195703. mapped (false),
  195704. visual (0),
  195705. depth (0)
  195706. {
  195707. // it's dangerous to create a window on a thread other than the message thread..
  195708. jassert (MessageManager::getInstance()->currentThreadHasLockedMessageManager());
  195709. repainter = new LinuxRepaintManager (this);
  195710. createWindow();
  195711. setTitle (component->getName());
  195712. }
  195713. ~LinuxComponentPeer()
  195714. {
  195715. // it's dangerous to delete a window on a thread other than the message thread..
  195716. jassert (MessageManager::getInstance()->currentThreadHasLockedMessageManager());
  195717. deleteTaskBarIcon();
  195718. deleteIconPixmaps();
  195719. destroyWindow();
  195720. windowH = 0;
  195721. }
  195722. void* getNativeHandle() const
  195723. {
  195724. return (void*) windowH;
  195725. }
  195726. static LinuxComponentPeer* getPeerFor (Window windowHandle) throw()
  195727. {
  195728. XPointer peer = 0;
  195729. ScopedXLock xlock;
  195730. if (! XFindContext (display, (XID) windowHandle, improbableNumber, &peer))
  195731. {
  195732. if (peer != 0 && ! ComponentPeer::isValidPeer ((LinuxComponentPeer*) peer))
  195733. peer = 0;
  195734. }
  195735. return (LinuxComponentPeer*) peer;
  195736. }
  195737. void setVisible (bool shouldBeVisible)
  195738. {
  195739. ScopedXLock xlock;
  195740. if (shouldBeVisible)
  195741. XMapWindow (display, windowH);
  195742. else
  195743. XUnmapWindow (display, windowH);
  195744. }
  195745. void setTitle (const String& title)
  195746. {
  195747. setWindowTitle (windowH, title);
  195748. }
  195749. void setPosition (int x, int y)
  195750. {
  195751. setBounds (x, y, ww, wh, false);
  195752. }
  195753. void setSize (int w, int h)
  195754. {
  195755. setBounds (wx, wy, w, h, false);
  195756. }
  195757. void setBounds (int x, int y, int w, int h, const bool isNowFullScreen)
  195758. {
  195759. fullScreen = isNowFullScreen;
  195760. if (windowH != 0)
  195761. {
  195762. Component::SafePointer<Component> deletionChecker (component);
  195763. wx = x;
  195764. wy = y;
  195765. ww = jmax (1, w);
  195766. wh = jmax (1, h);
  195767. ScopedXLock xlock;
  195768. // Make sure the Window manager does what we want
  195769. XSizeHints* hints = XAllocSizeHints();
  195770. hints->flags = USSize | USPosition;
  195771. hints->width = ww;
  195772. hints->height = wh;
  195773. hints->x = wx;
  195774. hints->y = wy;
  195775. if ((getStyleFlags() & (windowHasTitleBar | windowIsResizable)) == windowHasTitleBar)
  195776. {
  195777. hints->min_width = hints->max_width = hints->width;
  195778. hints->min_height = hints->max_height = hints->height;
  195779. hints->flags |= PMinSize | PMaxSize;
  195780. }
  195781. XSetWMNormalHints (display, windowH, hints);
  195782. XFree (hints);
  195783. XMoveResizeWindow (display, windowH,
  195784. wx - windowBorder.getLeft(),
  195785. wy - windowBorder.getTop(), ww, wh);
  195786. if (deletionChecker != 0)
  195787. {
  195788. updateBorderSize();
  195789. handleMovedOrResized();
  195790. }
  195791. }
  195792. }
  195793. const Rectangle<int> getBounds() const { return Rectangle<int> (wx, wy, ww, wh); }
  195794. const Point<int> getScreenPosition() const { return Point<int> (wx, wy); }
  195795. const Point<int> relativePositionToGlobal (const Point<int>& relativePosition)
  195796. {
  195797. return relativePosition + getScreenPosition();
  195798. }
  195799. const Point<int> globalPositionToRelative (const Point<int>& screenPosition)
  195800. {
  195801. return screenPosition - getScreenPosition();
  195802. }
  195803. void setMinimised (bool shouldBeMinimised)
  195804. {
  195805. if (shouldBeMinimised)
  195806. {
  195807. Window root = RootWindow (display, DefaultScreen (display));
  195808. XClientMessageEvent clientMsg;
  195809. clientMsg.display = display;
  195810. clientMsg.window = windowH;
  195811. clientMsg.type = ClientMessage;
  195812. clientMsg.format = 32;
  195813. clientMsg.message_type = Atoms::ChangeState;
  195814. clientMsg.data.l[0] = IconicState;
  195815. ScopedXLock xlock;
  195816. XSendEvent (display, root, false,
  195817. SubstructureRedirectMask | SubstructureNotifyMask,
  195818. (XEvent*) &clientMsg);
  195819. }
  195820. else
  195821. {
  195822. setVisible (true);
  195823. }
  195824. }
  195825. bool isMinimised() const
  195826. {
  195827. bool minimised = false;
  195828. unsigned char* stateProp;
  195829. unsigned long nitems, bytesLeft;
  195830. Atom actualType;
  195831. int actualFormat;
  195832. ScopedXLock xlock;
  195833. if (XGetWindowProperty (display, windowH, Atoms::State, 0, 64, False,
  195834. Atoms::State, &actualType, &actualFormat, &nitems, &bytesLeft,
  195835. &stateProp) == Success
  195836. && actualType == Atoms::State
  195837. && actualFormat == 32
  195838. && nitems > 0)
  195839. {
  195840. if (((unsigned long*) stateProp)[0] == IconicState)
  195841. minimised = true;
  195842. XFree (stateProp);
  195843. }
  195844. return minimised;
  195845. }
  195846. void setFullScreen (const bool shouldBeFullScreen)
  195847. {
  195848. Rectangle<int> r (lastNonFullscreenBounds); // (get a copy of this before de-minimising)
  195849. setMinimised (false);
  195850. if (fullScreen != shouldBeFullScreen)
  195851. {
  195852. if (shouldBeFullScreen)
  195853. r = Desktop::getInstance().getMainMonitorArea();
  195854. if (! r.isEmpty())
  195855. setBounds (r.getX(), r.getY(), r.getWidth(), r.getHeight(), shouldBeFullScreen);
  195856. getComponent()->repaint();
  195857. }
  195858. }
  195859. bool isFullScreen() const
  195860. {
  195861. return fullScreen;
  195862. }
  195863. bool isChildWindowOf (Window possibleParent) const
  195864. {
  195865. Window* windowList = 0;
  195866. uint32 windowListSize = 0;
  195867. Window parent, root;
  195868. ScopedXLock xlock;
  195869. if (XQueryTree (display, windowH, &root, &parent, &windowList, &windowListSize) != 0)
  195870. {
  195871. if (windowList != 0)
  195872. XFree (windowList);
  195873. return parent == possibleParent;
  195874. }
  195875. return false;
  195876. }
  195877. bool isFrontWindow() const
  195878. {
  195879. Window* windowList = 0;
  195880. uint32 windowListSize = 0;
  195881. bool result = false;
  195882. ScopedXLock xlock;
  195883. Window parent, root = RootWindow (display, DefaultScreen (display));
  195884. if (XQueryTree (display, root, &root, &parent, &windowList, &windowListSize) != 0)
  195885. {
  195886. for (int i = windowListSize; --i >= 0;)
  195887. {
  195888. LinuxComponentPeer* const peer = LinuxComponentPeer::getPeerFor (windowList[i]);
  195889. if (peer != 0)
  195890. {
  195891. result = (peer == this);
  195892. break;
  195893. }
  195894. }
  195895. }
  195896. if (windowList != 0)
  195897. XFree (windowList);
  195898. return result;
  195899. }
  195900. bool contains (const Point<int>& position, bool trueIfInAChildWindow) const
  195901. {
  195902. int x = position.getX();
  195903. int y = position.getY();
  195904. if (((unsigned int) x) >= (unsigned int) ww
  195905. || ((unsigned int) y) >= (unsigned int) wh)
  195906. return false;
  195907. bool inFront = false;
  195908. for (int i = 0; i < Desktop::getInstance().getNumComponents(); ++i)
  195909. {
  195910. Component* const c = Desktop::getInstance().getComponent (i);
  195911. if (inFront)
  195912. {
  195913. if (c->contains (x + wx - c->getScreenX(),
  195914. y + wy - c->getScreenY()))
  195915. {
  195916. return false;
  195917. }
  195918. }
  195919. else if (c == getComponent())
  195920. {
  195921. inFront = true;
  195922. }
  195923. }
  195924. if (trueIfInAChildWindow)
  195925. return true;
  195926. ::Window root, child;
  195927. unsigned int bw, depth;
  195928. int wx, wy, w, h;
  195929. ScopedXLock xlock;
  195930. if (! XGetGeometry (display, (::Drawable) windowH, &root,
  195931. &wx, &wy, (unsigned int*) &w, (unsigned int*) &h,
  195932. &bw, &depth))
  195933. {
  195934. return false;
  195935. }
  195936. if (! XTranslateCoordinates (display, windowH, windowH, x, y, &wx, &wy, &child))
  195937. return false;
  195938. return child == None;
  195939. }
  195940. const BorderSize getFrameSize() const
  195941. {
  195942. return BorderSize();
  195943. }
  195944. bool setAlwaysOnTop (bool alwaysOnTop)
  195945. {
  195946. if (windowH != 0)
  195947. {
  195948. const bool wasVisible = component->isVisible();
  195949. if (wasVisible)
  195950. setVisible (false); // doesn't always seem to work if the window is visible when this is done..
  195951. {
  195952. ScopedXLock xlock;
  195953. XSetWindowAttributes swa;
  195954. swa.override_redirect = alwaysOnTop ? True : False;
  195955. XChangeWindowAttributes (display, windowH, CWOverrideRedirect, &swa);
  195956. }
  195957. if (wasVisible)
  195958. setVisible (true);
  195959. }
  195960. return true;
  195961. }
  195962. void toFront (bool makeActive)
  195963. {
  195964. if (makeActive)
  195965. {
  195966. setVisible (true);
  195967. grabFocus();
  195968. }
  195969. XEvent ev;
  195970. ev.xclient.type = ClientMessage;
  195971. ev.xclient.serial = 0;
  195972. ev.xclient.send_event = True;
  195973. ev.xclient.message_type = Atoms::ActiveWin;
  195974. ev.xclient.window = windowH;
  195975. ev.xclient.format = 32;
  195976. ev.xclient.data.l[0] = 2;
  195977. ev.xclient.data.l[1] = CurrentTime;
  195978. ev.xclient.data.l[2] = 0;
  195979. ev.xclient.data.l[3] = 0;
  195980. ev.xclient.data.l[4] = 0;
  195981. {
  195982. ScopedXLock xlock;
  195983. XSendEvent (display, RootWindow (display, DefaultScreen (display)),
  195984. False,
  195985. SubstructureRedirectMask | SubstructureNotifyMask,
  195986. &ev);
  195987. XWindowAttributes attr;
  195988. XGetWindowAttributes (display, windowH, &attr);
  195989. if (attr.override_redirect)
  195990. XRaiseWindow (display, windowH);
  195991. XSync (display, False);
  195992. }
  195993. handleBroughtToFront();
  195994. }
  195995. void toBehind (ComponentPeer* other)
  195996. {
  195997. LinuxComponentPeer* const otherPeer = dynamic_cast <LinuxComponentPeer*> (other);
  195998. jassert (otherPeer != 0); // wrong type of window?
  195999. if (otherPeer != 0)
  196000. {
  196001. setMinimised (false);
  196002. Window newStack[] = { otherPeer->windowH, windowH };
  196003. ScopedXLock xlock;
  196004. XRestackWindows (display, newStack, 2);
  196005. }
  196006. }
  196007. bool isFocused() const
  196008. {
  196009. int revert;
  196010. Window focusedWindow = 0;
  196011. ScopedXLock xlock;
  196012. XGetInputFocus (display, &focusedWindow, &revert);
  196013. return focusedWindow == windowH;
  196014. }
  196015. void grabFocus()
  196016. {
  196017. XWindowAttributes atts;
  196018. ScopedXLock xlock;
  196019. if (windowH != 0
  196020. && XGetWindowAttributes (display, windowH, &atts)
  196021. && atts.map_state == IsViewable
  196022. && ! isFocused())
  196023. {
  196024. XSetInputFocus (display, windowH, RevertToParent, CurrentTime);
  196025. isActiveApplication = true;
  196026. }
  196027. }
  196028. void textInputRequired (const Point<int>&)
  196029. {
  196030. }
  196031. void repaint (int x, int y, int w, int h)
  196032. {
  196033. if (Rectangle<int>::intersectRectangles (x, y, w, h,
  196034. 0, 0,
  196035. getComponent()->getWidth(),
  196036. getComponent()->getHeight()))
  196037. {
  196038. repainter->repaint (x, y, w, h);
  196039. }
  196040. }
  196041. void performAnyPendingRepaintsNow()
  196042. {
  196043. repainter->performAnyPendingRepaintsNow();
  196044. }
  196045. static Pixmap juce_createColourPixmapFromImage (Display* display, const Image& image)
  196046. {
  196047. ScopedXLock xlock;
  196048. const int width = image.getWidth();
  196049. const int height = image.getHeight();
  196050. HeapBlock <uint32> colour (width * height);
  196051. int index = 0;
  196052. for (int y = 0; y < height; ++y)
  196053. for (int x = 0; x < width; ++x)
  196054. colour[index++] = image.getPixelAt (x, y).getARGB();
  196055. XImage* ximage = XCreateImage (display, CopyFromParent, 24, ZPixmap,
  196056. 0, reinterpret_cast<char*> (colour.getData()),
  196057. width, height, 32, 0);
  196058. Pixmap pixmap = XCreatePixmap (display, DefaultRootWindow (display),
  196059. width, height, 24);
  196060. GC gc = XCreateGC (display, pixmap, 0, 0);
  196061. XPutImage (display, pixmap, gc, ximage, 0, 0, 0, 0, width, height);
  196062. XFreeGC (display, gc);
  196063. return pixmap;
  196064. }
  196065. static Pixmap juce_createMaskPixmapFromImage (Display* display, const Image& image)
  196066. {
  196067. ScopedXLock xlock;
  196068. const int width = image.getWidth();
  196069. const int height = image.getHeight();
  196070. const int stride = (width + 7) >> 3;
  196071. HeapBlock <uint8> mask;
  196072. mask.calloc (stride * height);
  196073. const bool msbfirst = (BitmapBitOrder (display) == MSBFirst);
  196074. for (int y = 0; y < height; ++y)
  196075. {
  196076. for (int x = 0; x < width; ++x)
  196077. {
  196078. const uint8 bit = (uint8) (1 << (msbfirst ? (7 - (x & 7)) : (x & 7)));
  196079. const int offset = y * stride + (x >> 3);
  196080. if (image.getPixelAt (x, y).getAlpha() >= 128)
  196081. mask[offset] |= bit;
  196082. }
  196083. }
  196084. return XCreatePixmapFromBitmapData (display, DefaultRootWindow (display),
  196085. reinterpret_cast<char*> (mask.getData()), width, height, 1, 0, 1);
  196086. }
  196087. void setIcon (const Image& newIcon)
  196088. {
  196089. const int dataSize = newIcon.getWidth() * newIcon.getHeight() + 2;
  196090. HeapBlock <unsigned long> data (dataSize);
  196091. int index = 0;
  196092. data[index++] = newIcon.getWidth();
  196093. data[index++] = newIcon.getHeight();
  196094. for (int y = 0; y < newIcon.getHeight(); ++y)
  196095. for (int x = 0; x < newIcon.getWidth(); ++x)
  196096. data[index++] = newIcon.getPixelAt (x, y).getARGB();
  196097. ScopedXLock xlock;
  196098. XChangeProperty (display, windowH,
  196099. XInternAtom (display, "_NET_WM_ICON", False),
  196100. XA_CARDINAL, 32, PropModeReplace,
  196101. reinterpret_cast<unsigned char*> (data.getData()), dataSize);
  196102. deleteIconPixmaps();
  196103. XWMHints* wmHints = XGetWMHints (display, windowH);
  196104. if (wmHints == 0)
  196105. wmHints = XAllocWMHints();
  196106. wmHints->flags |= IconPixmapHint | IconMaskHint;
  196107. wmHints->icon_pixmap = juce_createColourPixmapFromImage (display, newIcon);
  196108. wmHints->icon_mask = juce_createMaskPixmapFromImage (display, newIcon);
  196109. XSetWMHints (display, windowH, wmHints);
  196110. XFree (wmHints);
  196111. XSync (display, False);
  196112. }
  196113. void deleteIconPixmaps()
  196114. {
  196115. ScopedXLock xlock;
  196116. XWMHints* wmHints = XGetWMHints (display, windowH);
  196117. if (wmHints != 0)
  196118. {
  196119. if ((wmHints->flags & IconPixmapHint) != 0)
  196120. {
  196121. wmHints->flags &= ~IconPixmapHint;
  196122. XFreePixmap (display, wmHints->icon_pixmap);
  196123. }
  196124. if ((wmHints->flags & IconMaskHint) != 0)
  196125. {
  196126. wmHints->flags &= ~IconMaskHint;
  196127. XFreePixmap (display, wmHints->icon_mask);
  196128. }
  196129. XSetWMHints (display, windowH, wmHints);
  196130. XFree (wmHints);
  196131. }
  196132. }
  196133. void handleWindowMessage (XEvent* event)
  196134. {
  196135. switch (event->xany.type)
  196136. {
  196137. case 2: // 'KeyPress'
  196138. {
  196139. ScopedXLock xlock;
  196140. XKeyEvent* const keyEvent = (XKeyEvent*) &event->xkey;
  196141. updateKeyStates (keyEvent->keycode, true);
  196142. char utf8 [64];
  196143. zeromem (utf8, sizeof (utf8));
  196144. KeySym sym;
  196145. {
  196146. const char* oldLocale = ::setlocale (LC_ALL, 0);
  196147. ::setlocale (LC_ALL, "");
  196148. XLookupString (keyEvent, utf8, sizeof (utf8), &sym, 0);
  196149. ::setlocale (LC_ALL, oldLocale);
  196150. }
  196151. const juce_wchar unicodeChar = *(const juce_wchar*) String::fromUTF8 (utf8, sizeof (utf8) - 1);
  196152. int keyCode = (int) unicodeChar;
  196153. if (keyCode < 0x20)
  196154. keyCode = XKeycodeToKeysym (display, keyEvent->keycode, currentModifiers.isShiftDown() ? 1 : 0);
  196155. const ModifierKeys oldMods (currentModifiers);
  196156. bool keyPressed = false;
  196157. const bool keyDownChange = (sym != NoSymbol) && ! updateKeyModifiersFromSym (sym, true);
  196158. if ((sym & 0xff00) == 0xff00)
  196159. {
  196160. // Translate keypad
  196161. if (sym == XK_KP_Divide)
  196162. keyCode = XK_slash;
  196163. else if (sym == XK_KP_Multiply)
  196164. keyCode = XK_asterisk;
  196165. else if (sym == XK_KP_Subtract)
  196166. keyCode = XK_hyphen;
  196167. else if (sym == XK_KP_Add)
  196168. keyCode = XK_plus;
  196169. else if (sym == XK_KP_Enter)
  196170. keyCode = XK_Return;
  196171. else if (sym == XK_KP_Decimal)
  196172. keyCode = Keys::numLock ? XK_period : XK_Delete;
  196173. else if (sym == XK_KP_0)
  196174. keyCode = Keys::numLock ? XK_0 : XK_Insert;
  196175. else if (sym == XK_KP_1)
  196176. keyCode = Keys::numLock ? XK_1 : XK_End;
  196177. else if (sym == XK_KP_2)
  196178. keyCode = Keys::numLock ? XK_2 : XK_Down;
  196179. else if (sym == XK_KP_3)
  196180. keyCode = Keys::numLock ? XK_3 : XK_Page_Down;
  196181. else if (sym == XK_KP_4)
  196182. keyCode = Keys::numLock ? XK_4 : XK_Left;
  196183. else if (sym == XK_KP_5)
  196184. keyCode = XK_5;
  196185. else if (sym == XK_KP_6)
  196186. keyCode = Keys::numLock ? XK_6 : XK_Right;
  196187. else if (sym == XK_KP_7)
  196188. keyCode = Keys::numLock ? XK_7 : XK_Home;
  196189. else if (sym == XK_KP_8)
  196190. keyCode = Keys::numLock ? XK_8 : XK_Up;
  196191. else if (sym == XK_KP_9)
  196192. keyCode = Keys::numLock ? XK_9 : XK_Page_Up;
  196193. switch (sym)
  196194. {
  196195. case XK_Left:
  196196. case XK_Right:
  196197. case XK_Up:
  196198. case XK_Down:
  196199. case XK_Page_Up:
  196200. case XK_Page_Down:
  196201. case XK_End:
  196202. case XK_Home:
  196203. case XK_Delete:
  196204. case XK_Insert:
  196205. keyPressed = true;
  196206. keyCode = (sym & 0xff) | Keys::extendedKeyModifier;
  196207. break;
  196208. case XK_Tab:
  196209. case XK_Return:
  196210. case XK_Escape:
  196211. case XK_BackSpace:
  196212. keyPressed = true;
  196213. keyCode &= 0xff;
  196214. break;
  196215. default:
  196216. {
  196217. if (sym >= XK_F1 && sym <= XK_F16)
  196218. {
  196219. keyPressed = true;
  196220. keyCode = (sym & 0xff) | Keys::extendedKeyModifier;
  196221. }
  196222. break;
  196223. }
  196224. }
  196225. }
  196226. if (utf8[0] != 0 || ((sym & 0xff00) == 0 && sym >= 8))
  196227. keyPressed = true;
  196228. if (oldMods != currentModifiers)
  196229. handleModifierKeysChange();
  196230. if (keyDownChange)
  196231. handleKeyUpOrDown (true);
  196232. if (keyPressed)
  196233. handleKeyPress (keyCode, unicodeChar);
  196234. break;
  196235. }
  196236. case KeyRelease:
  196237. {
  196238. const XKeyEvent* const keyEvent = (const XKeyEvent*) &event->xkey;
  196239. updateKeyStates (keyEvent->keycode, false);
  196240. ScopedXLock xlock;
  196241. KeySym sym = XKeycodeToKeysym (display, keyEvent->keycode, 0);
  196242. const ModifierKeys oldMods (currentModifiers);
  196243. const bool keyDownChange = (sym != NoSymbol) && ! updateKeyModifiersFromSym (sym, false);
  196244. if (oldMods != currentModifiers)
  196245. handleModifierKeysChange();
  196246. if (keyDownChange)
  196247. handleKeyUpOrDown (false);
  196248. break;
  196249. }
  196250. case ButtonPress:
  196251. {
  196252. const XButtonPressedEvent* const buttonPressEvent = (const XButtonPressedEvent*) &event->xbutton;
  196253. updateKeyModifiers (buttonPressEvent->state);
  196254. bool buttonMsg = false;
  196255. const int map = pointerMap [buttonPressEvent->button - Button1];
  196256. if (map == Keys::WheelUp || map == Keys::WheelDown)
  196257. {
  196258. handleMouseWheel (0, Point<int> (buttonPressEvent->x, buttonPressEvent->y),
  196259. getEventTime (buttonPressEvent->time), 0, map == Keys::WheelDown ? -84.0f : 84.0f);
  196260. }
  196261. if (map == Keys::LeftButton)
  196262. {
  196263. currentModifiers = currentModifiers.withFlags (ModifierKeys::leftButtonModifier);
  196264. buttonMsg = true;
  196265. }
  196266. else if (map == Keys::RightButton)
  196267. {
  196268. currentModifiers = currentModifiers.withFlags (ModifierKeys::rightButtonModifier);
  196269. buttonMsg = true;
  196270. }
  196271. else if (map == Keys::MiddleButton)
  196272. {
  196273. currentModifiers = currentModifiers.withFlags (ModifierKeys::middleButtonModifier);
  196274. buttonMsg = true;
  196275. }
  196276. if (buttonMsg)
  196277. {
  196278. toFront (true);
  196279. handleMouseEvent (0, Point<int> (buttonPressEvent->x, buttonPressEvent->y), currentModifiers,
  196280. getEventTime (buttonPressEvent->time));
  196281. }
  196282. clearLastMousePos();
  196283. break;
  196284. }
  196285. case ButtonRelease:
  196286. {
  196287. const XButtonReleasedEvent* const buttonRelEvent = (const XButtonReleasedEvent*) &event->xbutton;
  196288. updateKeyModifiers (buttonRelEvent->state);
  196289. const int map = pointerMap [buttonRelEvent->button - Button1];
  196290. if (map == Keys::LeftButton)
  196291. currentModifiers = currentModifiers.withoutFlags (ModifierKeys::leftButtonModifier);
  196292. else if (map == Keys::RightButton)
  196293. currentModifiers = currentModifiers.withoutFlags (ModifierKeys::rightButtonModifier);
  196294. else if (map == Keys::MiddleButton)
  196295. currentModifiers = currentModifiers.withoutFlags (ModifierKeys::middleButtonModifier);
  196296. handleMouseEvent (0, Point<int> (buttonRelEvent->x, buttonRelEvent->y), currentModifiers,
  196297. getEventTime (buttonRelEvent->time));
  196298. clearLastMousePos();
  196299. break;
  196300. }
  196301. case MotionNotify:
  196302. {
  196303. const XPointerMovedEvent* const movedEvent = (const XPointerMovedEvent*) &event->xmotion;
  196304. updateKeyModifiers (movedEvent->state);
  196305. const Point<int> mousePos (Desktop::getMousePosition());
  196306. if (lastMousePos != mousePos)
  196307. {
  196308. lastMousePos = mousePos;
  196309. if (parentWindow != 0 && (styleFlags & windowHasTitleBar) == 0)
  196310. {
  196311. Window wRoot = 0, wParent = 0;
  196312. {
  196313. ScopedXLock xlock;
  196314. unsigned int numChildren;
  196315. Window* wChild = 0;
  196316. XQueryTree (display, windowH, &wRoot, &wParent, &wChild, &numChildren);
  196317. }
  196318. if (wParent != 0
  196319. && wParent != windowH
  196320. && wParent != wRoot)
  196321. {
  196322. parentWindow = wParent;
  196323. updateBounds();
  196324. }
  196325. else
  196326. {
  196327. parentWindow = 0;
  196328. }
  196329. }
  196330. handleMouseEvent (0, mousePos - getScreenPosition(), currentModifiers, getEventTime (movedEvent->time));
  196331. }
  196332. break;
  196333. }
  196334. case EnterNotify:
  196335. {
  196336. clearLastMousePos();
  196337. const XEnterWindowEvent* const enterEvent = (const XEnterWindowEvent*) &event->xcrossing;
  196338. if (! currentModifiers.isAnyMouseButtonDown())
  196339. {
  196340. updateKeyModifiers (enterEvent->state);
  196341. handleMouseEvent (0, Point<int> (enterEvent->x, enterEvent->y), currentModifiers, getEventTime (enterEvent->time));
  196342. }
  196343. break;
  196344. }
  196345. case LeaveNotify:
  196346. {
  196347. const XLeaveWindowEvent* const leaveEvent = (const XLeaveWindowEvent*) &event->xcrossing;
  196348. // Suppress the normal leave if we've got a pointer grab, or if
  196349. // it's a bogus one caused by clicking a mouse button when running
  196350. // in a Window manager
  196351. if (((! currentModifiers.isAnyMouseButtonDown()) && leaveEvent->mode == NotifyNormal)
  196352. || leaveEvent->mode == NotifyUngrab)
  196353. {
  196354. updateKeyModifiers (leaveEvent->state);
  196355. handleMouseEvent (0, Point<int> (leaveEvent->x, leaveEvent->y), currentModifiers, getEventTime (leaveEvent->time));
  196356. }
  196357. break;
  196358. }
  196359. case FocusIn:
  196360. {
  196361. isActiveApplication = true;
  196362. if (isFocused())
  196363. handleFocusGain();
  196364. break;
  196365. }
  196366. case FocusOut:
  196367. {
  196368. isActiveApplication = false;
  196369. if (! isFocused())
  196370. handleFocusLoss();
  196371. break;
  196372. }
  196373. case Expose:
  196374. {
  196375. // Batch together all pending expose events
  196376. XExposeEvent* exposeEvent = (XExposeEvent*) &event->xexpose;
  196377. XEvent nextEvent;
  196378. ScopedXLock xlock;
  196379. if (exposeEvent->window != windowH)
  196380. {
  196381. Window child;
  196382. XTranslateCoordinates (display, exposeEvent->window, windowH,
  196383. exposeEvent->x, exposeEvent->y, &exposeEvent->x, &exposeEvent->y,
  196384. &child);
  196385. }
  196386. repaint (exposeEvent->x, exposeEvent->y,
  196387. exposeEvent->width, exposeEvent->height);
  196388. while (XEventsQueued (display, QueuedAfterFlush) > 0)
  196389. {
  196390. XPeekEvent (display, (XEvent*) &nextEvent);
  196391. if (nextEvent.type != Expose || nextEvent.xany.window != event->xany.window)
  196392. break;
  196393. XNextEvent (display, (XEvent*) &nextEvent);
  196394. XExposeEvent* nextExposeEvent = (XExposeEvent*) &nextEvent.xexpose;
  196395. repaint (nextExposeEvent->x, nextExposeEvent->y,
  196396. nextExposeEvent->width, nextExposeEvent->height);
  196397. }
  196398. break;
  196399. }
  196400. case CirculateNotify:
  196401. case CreateNotify:
  196402. case DestroyNotify:
  196403. // Think we can ignore these
  196404. break;
  196405. case ConfigureNotify:
  196406. {
  196407. updateBounds();
  196408. updateBorderSize();
  196409. handleMovedOrResized();
  196410. // if the native title bar is dragged, need to tell any active menus, etc.
  196411. if ((styleFlags & windowHasTitleBar) != 0
  196412. && component->isCurrentlyBlockedByAnotherModalComponent())
  196413. {
  196414. Component* const currentModalComp = Component::getCurrentlyModalComponent();
  196415. if (currentModalComp != 0)
  196416. currentModalComp->inputAttemptWhenModal();
  196417. }
  196418. XConfigureEvent* const confEvent = (XConfigureEvent*) &event->xconfigure;
  196419. if (confEvent->window == windowH
  196420. && confEvent->above != 0
  196421. && isFrontWindow())
  196422. {
  196423. handleBroughtToFront();
  196424. }
  196425. break;
  196426. }
  196427. case ReparentNotify:
  196428. case GravityNotify:
  196429. {
  196430. parentWindow = 0;
  196431. Window wRoot = 0;
  196432. Window* wChild = 0;
  196433. unsigned int numChildren;
  196434. {
  196435. ScopedXLock xlock;
  196436. XQueryTree (display, windowH, &wRoot, &parentWindow, &wChild, &numChildren);
  196437. }
  196438. if (parentWindow == windowH || parentWindow == wRoot)
  196439. parentWindow = 0;
  196440. updateBounds();
  196441. updateBorderSize();
  196442. handleMovedOrResized();
  196443. break;
  196444. }
  196445. case MapNotify:
  196446. mapped = true;
  196447. handleBroughtToFront();
  196448. break;
  196449. case UnmapNotify:
  196450. mapped = false;
  196451. break;
  196452. case MappingNotify:
  196453. {
  196454. XMappingEvent* mappingEvent = (XMappingEvent*) &event->xmapping;
  196455. if (mappingEvent->request != MappingPointer)
  196456. {
  196457. // Deal with modifier/keyboard mapping
  196458. ScopedXLock xlock;
  196459. XRefreshKeyboardMapping (mappingEvent);
  196460. updateModifierMappings();
  196461. }
  196462. break;
  196463. }
  196464. case ClientMessage:
  196465. {
  196466. const XClientMessageEvent* const clientMsg = (const XClientMessageEvent*) &event->xclient;
  196467. if (clientMsg->message_type == Atoms::Protocols && clientMsg->format == 32)
  196468. {
  196469. const Atom atom = (Atom) clientMsg->data.l[0];
  196470. if (atom == Atoms::ProtocolList [Atoms::TAKE_FOCUS])
  196471. {
  196472. XWindowAttributes atts;
  196473. ScopedXLock xlock;
  196474. if (clientMsg->window != 0
  196475. && XGetWindowAttributes (display, clientMsg->window, &atts))
  196476. {
  196477. if (atts.map_state == IsViewable)
  196478. XSetInputFocus (display, clientMsg->window, RevertToParent, clientMsg->data.l[1]);
  196479. }
  196480. }
  196481. else if (atom == Atoms::ProtocolList [Atoms::DELETE_WINDOW])
  196482. {
  196483. handleUserClosingWindow();
  196484. }
  196485. }
  196486. else if (clientMsg->message_type == Atoms::XdndEnter)
  196487. {
  196488. handleDragAndDropEnter (clientMsg);
  196489. }
  196490. else if (clientMsg->message_type == Atoms::XdndLeave)
  196491. {
  196492. resetDragAndDrop();
  196493. }
  196494. else if (clientMsg->message_type == Atoms::XdndPosition)
  196495. {
  196496. handleDragAndDropPosition (clientMsg);
  196497. }
  196498. else if (clientMsg->message_type == Atoms::XdndDrop)
  196499. {
  196500. handleDragAndDropDrop (clientMsg);
  196501. }
  196502. else if (clientMsg->message_type == Atoms::XdndStatus)
  196503. {
  196504. handleDragAndDropStatus (clientMsg);
  196505. }
  196506. else if (clientMsg->message_type == Atoms::XdndFinished)
  196507. {
  196508. resetDragAndDrop();
  196509. }
  196510. break;
  196511. }
  196512. case SelectionNotify:
  196513. handleDragAndDropSelection (event);
  196514. break;
  196515. case SelectionClear:
  196516. case SelectionRequest:
  196517. break;
  196518. default:
  196519. #if JUCE_USE_XSHM
  196520. {
  196521. ScopedXLock xlock;
  196522. if (event->xany.type == XShmGetEventBase (display))
  196523. repainter->notifyPaintCompleted();
  196524. }
  196525. #endif
  196526. break;
  196527. }
  196528. }
  196529. void showMouseCursor (Cursor cursor) throw()
  196530. {
  196531. ScopedXLock xlock;
  196532. XDefineCursor (display, windowH, cursor);
  196533. }
  196534. void setTaskBarIcon (const Image& image)
  196535. {
  196536. ScopedXLock xlock;
  196537. deleteTaskBarIcon();
  196538. taskbarImage = image.createCopy();
  196539. Screen* const screen = XDefaultScreenOfDisplay (display);
  196540. const int screenNumber = XScreenNumberOfScreen (screen);
  196541. String screenAtom ("_NET_SYSTEM_TRAY_S");
  196542. screenAtom << screenNumber;
  196543. Atom selectionAtom = XInternAtom (display, screenAtom.toUTF8(), false);
  196544. XGrabServer (display);
  196545. Window managerWin = XGetSelectionOwner (display, selectionAtom);
  196546. if (managerWin != None)
  196547. XSelectInput (display, managerWin, StructureNotifyMask);
  196548. XUngrabServer (display);
  196549. XFlush (display);
  196550. if (managerWin != None)
  196551. {
  196552. XEvent ev;
  196553. zerostruct (ev);
  196554. ev.xclient.type = ClientMessage;
  196555. ev.xclient.window = managerWin;
  196556. ev.xclient.message_type = XInternAtom (display, "_NET_SYSTEM_TRAY_OPCODE", False);
  196557. ev.xclient.format = 32;
  196558. ev.xclient.data.l[0] = CurrentTime;
  196559. ev.xclient.data.l[1] = SYSTEM_TRAY_REQUEST_DOCK;
  196560. ev.xclient.data.l[2] = windowH;
  196561. ev.xclient.data.l[3] = 0;
  196562. ev.xclient.data.l[4] = 0;
  196563. XSendEvent (display, managerWin, False, NoEventMask, &ev);
  196564. XSync (display, False);
  196565. }
  196566. // For older KDE's ...
  196567. long atomData = 1;
  196568. Atom trayAtom = XInternAtom (display, "KWM_DOCKWINDOW", false);
  196569. XChangeProperty (display, windowH, trayAtom, trayAtom, 32, PropModeReplace, (unsigned char*) &atomData, 1);
  196570. // For more recent KDE's...
  196571. trayAtom = XInternAtom (display, "_KDE_NET_WM_SYSTEM_TRAY_WINDOW_FOR", false);
  196572. XChangeProperty (display, windowH, trayAtom, XA_WINDOW, 32, PropModeReplace, (unsigned char*) &windowH, 1);
  196573. // a minimum size must be specified for GNOME and Xfce, otherwise the icon is displayed with a width of 1
  196574. XSizeHints* hints = XAllocSizeHints();
  196575. hints->flags = PMinSize;
  196576. hints->min_width = 22;
  196577. hints->min_height = 22;
  196578. XSetWMNormalHints (display, windowH, hints);
  196579. XFree (hints);
  196580. }
  196581. void deleteTaskBarIcon()
  196582. {
  196583. deleteAndZero (taskbarImage);
  196584. }
  196585. const Image* getTaskbarIcon() const throw() { return taskbarImage; }
  196586. juce_UseDebuggingNewOperator
  196587. bool dontRepaint;
  196588. static ModifierKeys currentModifiers;
  196589. private:
  196590. class LinuxRepaintManager : public Timer
  196591. {
  196592. public:
  196593. LinuxRepaintManager (LinuxComponentPeer* const peer_)
  196594. : peer (peer_),
  196595. lastTimeImageUsed (0)
  196596. {
  196597. #if JUCE_USE_XSHM
  196598. shmCompletedDrawing = true;
  196599. useARGBImagesForRendering = isShmAvailable();
  196600. if (useARGBImagesForRendering)
  196601. {
  196602. ScopedXLock xlock;
  196603. XShmSegmentInfo segmentinfo;
  196604. XImage* const testImage
  196605. = XShmCreateImage (display, DefaultVisual (display, DefaultScreen (display)),
  196606. 24, ZPixmap, 0, &segmentinfo, 64, 64);
  196607. useARGBImagesForRendering = (testImage->bits_per_pixel == 32);
  196608. XDestroyImage (testImage);
  196609. }
  196610. #endif
  196611. }
  196612. ~LinuxRepaintManager()
  196613. {
  196614. }
  196615. void timerCallback()
  196616. {
  196617. #if JUCE_USE_XSHM
  196618. if (! shmCompletedDrawing)
  196619. return;
  196620. #endif
  196621. if (! regionsNeedingRepaint.isEmpty())
  196622. {
  196623. stopTimer();
  196624. performAnyPendingRepaintsNow();
  196625. }
  196626. else if (Time::getApproximateMillisecondCounter() > lastTimeImageUsed + 3000)
  196627. {
  196628. stopTimer();
  196629. image = 0;
  196630. }
  196631. }
  196632. void repaint (int x, int y, int w, int h)
  196633. {
  196634. if (! isTimerRunning())
  196635. startTimer (repaintTimerPeriod);
  196636. regionsNeedingRepaint.add (x, y, w, h);
  196637. }
  196638. void performAnyPendingRepaintsNow()
  196639. {
  196640. #if JUCE_USE_XSHM
  196641. if (! shmCompletedDrawing)
  196642. {
  196643. startTimer (repaintTimerPeriod);
  196644. return;
  196645. }
  196646. #endif
  196647. peer->clearMaskedRegion();
  196648. RectangleList originalRepaintRegion (regionsNeedingRepaint);
  196649. regionsNeedingRepaint.clear();
  196650. const Rectangle<int> totalArea (originalRepaintRegion.getBounds());
  196651. if (! totalArea.isEmpty())
  196652. {
  196653. if (image == 0 || image->getWidth() < totalArea.getWidth()
  196654. || image->getHeight() < totalArea.getHeight())
  196655. {
  196656. #if JUCE_USE_XSHM
  196657. image = new XBitmapImage (useARGBImagesForRendering ? Image::ARGB
  196658. : Image::RGB,
  196659. #else
  196660. image = new XBitmapImage (Image::RGB,
  196661. #endif
  196662. (totalArea.getWidth() + 31) & ~31,
  196663. (totalArea.getHeight() + 31) & ~31,
  196664. false,
  196665. peer->depth,
  196666. peer->visual);
  196667. }
  196668. startTimer (repaintTimerPeriod);
  196669. LowLevelGraphicsSoftwareRenderer context (*image);
  196670. context.setOrigin (-totalArea.getX(), -totalArea.getY());
  196671. if (context.clipToRectangleList (originalRepaintRegion))
  196672. {
  196673. if (peer->depth == 32)
  196674. {
  196675. RectangleList::Iterator i (originalRepaintRegion);
  196676. while (i.next())
  196677. {
  196678. const Rectangle<int>& r = *i.getRectangle();
  196679. image->clear (r.getX() - totalArea.getX(), r.getY() - totalArea.getY(), r.getWidth(), r.getHeight());
  196680. }
  196681. }
  196682. peer->handlePaint (context);
  196683. }
  196684. if (! peer->maskedRegion.isEmpty())
  196685. originalRepaintRegion.subtract (peer->maskedRegion);
  196686. for (RectangleList::Iterator i (originalRepaintRegion); i.next();)
  196687. {
  196688. #if JUCE_USE_XSHM
  196689. shmCompletedDrawing = false;
  196690. #endif
  196691. const Rectangle<int>& r = *i.getRectangle();
  196692. image->blitToWindow (peer->windowH,
  196693. r.getX(), r.getY(), r.getWidth(), r.getHeight(),
  196694. r.getX() - totalArea.getX(), r.getY() - totalArea.getY());
  196695. }
  196696. }
  196697. lastTimeImageUsed = Time::getApproximateMillisecondCounter();
  196698. startTimer (repaintTimerPeriod);
  196699. }
  196700. #if JUCE_USE_XSHM
  196701. void notifyPaintCompleted() { shmCompletedDrawing = true; }
  196702. #endif
  196703. private:
  196704. enum { repaintTimerPeriod = 1000 / 100 };
  196705. LinuxComponentPeer* const peer;
  196706. ScopedPointer <XBitmapImage> image;
  196707. uint32 lastTimeImageUsed;
  196708. RectangleList regionsNeedingRepaint;
  196709. #if JUCE_USE_XSHM
  196710. bool useARGBImagesForRendering, shmCompletedDrawing;
  196711. #endif
  196712. LinuxRepaintManager (const LinuxRepaintManager&);
  196713. LinuxRepaintManager& operator= (const LinuxRepaintManager&);
  196714. };
  196715. ScopedPointer <LinuxRepaintManager> repainter;
  196716. friend class LinuxRepaintManager;
  196717. Window windowH, parentWindow;
  196718. int wx, wy, ww, wh;
  196719. Image* taskbarImage;
  196720. bool fullScreen, mapped;
  196721. Visual* visual;
  196722. int depth;
  196723. BorderSize windowBorder;
  196724. struct MotifWmHints
  196725. {
  196726. unsigned long flags;
  196727. unsigned long functions;
  196728. unsigned long decorations;
  196729. long input_mode;
  196730. unsigned long status;
  196731. };
  196732. static void updateKeyStates (const int keycode, const bool press) throw()
  196733. {
  196734. const int keybyte = keycode >> 3;
  196735. const int keybit = (1 << (keycode & 7));
  196736. if (press)
  196737. Keys::keyStates [keybyte] |= keybit;
  196738. else
  196739. Keys::keyStates [keybyte] &= ~keybit;
  196740. }
  196741. static void updateKeyModifiers (const int status) throw()
  196742. {
  196743. int keyMods = 0;
  196744. if (status & ShiftMask) keyMods |= ModifierKeys::shiftModifier;
  196745. if (status & ControlMask) keyMods |= ModifierKeys::ctrlModifier;
  196746. if (status & Keys::AltMask) keyMods |= ModifierKeys::altModifier;
  196747. currentModifiers = currentModifiers.withOnlyMouseButtons().withFlags (keyMods);
  196748. Keys::numLock = ((status & Keys::NumLockMask) != 0);
  196749. Keys::capsLock = ((status & LockMask) != 0);
  196750. }
  196751. static bool updateKeyModifiersFromSym (KeySym sym, const bool press) throw()
  196752. {
  196753. int modifier = 0;
  196754. bool isModifier = true;
  196755. switch (sym)
  196756. {
  196757. case XK_Shift_L:
  196758. case XK_Shift_R:
  196759. modifier = ModifierKeys::shiftModifier;
  196760. break;
  196761. case XK_Control_L:
  196762. case XK_Control_R:
  196763. modifier = ModifierKeys::ctrlModifier;
  196764. break;
  196765. case XK_Alt_L:
  196766. case XK_Alt_R:
  196767. modifier = ModifierKeys::altModifier;
  196768. break;
  196769. case XK_Num_Lock:
  196770. if (press)
  196771. Keys::numLock = ! Keys::numLock;
  196772. break;
  196773. case XK_Caps_Lock:
  196774. if (press)
  196775. Keys::capsLock = ! Keys::capsLock;
  196776. break;
  196777. case XK_Scroll_Lock:
  196778. break;
  196779. default:
  196780. isModifier = false;
  196781. break;
  196782. }
  196783. if (modifier != 0)
  196784. {
  196785. if (press)
  196786. currentModifiers = currentModifiers.withFlags (modifier);
  196787. else
  196788. currentModifiers = currentModifiers.withoutFlags (modifier);
  196789. }
  196790. return isModifier;
  196791. }
  196792. // Alt and Num lock are not defined by standard X
  196793. // modifier constants: check what they're mapped to
  196794. static void updateModifierMappings() throw()
  196795. {
  196796. ScopedXLock xlock;
  196797. const int altLeftCode = XKeysymToKeycode (display, XK_Alt_L);
  196798. const int numLockCode = XKeysymToKeycode (display, XK_Num_Lock);
  196799. Keys::AltMask = 0;
  196800. Keys::NumLockMask = 0;
  196801. XModifierKeymap* mapping = XGetModifierMapping (display);
  196802. if (mapping)
  196803. {
  196804. for (int i = 0; i < 8; i++)
  196805. {
  196806. if (mapping->modifiermap [i << 1] == altLeftCode)
  196807. Keys::AltMask = 1 << i;
  196808. else if (mapping->modifiermap [i << 1] == numLockCode)
  196809. Keys::NumLockMask = 1 << i;
  196810. }
  196811. XFreeModifiermap (mapping);
  196812. }
  196813. }
  196814. void removeWindowDecorations (Window wndH)
  196815. {
  196816. Atom hints = XInternAtom (display, "_MOTIF_WM_HINTS", True);
  196817. if (hints != None)
  196818. {
  196819. MotifWmHints motifHints;
  196820. zerostruct (motifHints);
  196821. motifHints.flags = 2; /* MWM_HINTS_DECORATIONS */
  196822. motifHints.decorations = 0;
  196823. ScopedXLock xlock;
  196824. XChangeProperty (display, wndH, hints, hints, 32, PropModeReplace,
  196825. (unsigned char*) &motifHints, 4);
  196826. }
  196827. hints = XInternAtom (display, "_WIN_HINTS", True);
  196828. if (hints != None)
  196829. {
  196830. long gnomeHints = 0;
  196831. ScopedXLock xlock;
  196832. XChangeProperty (display, wndH, hints, hints, 32, PropModeReplace,
  196833. (unsigned char*) &gnomeHints, 1);
  196834. }
  196835. hints = XInternAtom (display, "KWM_WIN_DECORATION", True);
  196836. if (hints != None)
  196837. {
  196838. long kwmHints = 2; /*KDE_tinyDecoration*/
  196839. ScopedXLock xlock;
  196840. XChangeProperty (display, wndH, hints, hints, 32, PropModeReplace,
  196841. (unsigned char*) &kwmHints, 1);
  196842. }
  196843. }
  196844. void addWindowButtons (Window wndH)
  196845. {
  196846. ScopedXLock xlock;
  196847. Atom hints = XInternAtom (display, "_MOTIF_WM_HINTS", True);
  196848. if (hints != None)
  196849. {
  196850. MotifWmHints motifHints;
  196851. zerostruct (motifHints);
  196852. motifHints.flags = 1 | 2; /* MWM_HINTS_FUNCTIONS | MWM_HINTS_DECORATIONS */
  196853. motifHints.decorations = 2 /* MWM_DECOR_BORDER */ | 8 /* MWM_DECOR_TITLE */ | 16; /* MWM_DECOR_MENU */
  196854. motifHints.functions = 4 /* MWM_FUNC_MOVE */;
  196855. if ((styleFlags & windowHasCloseButton) != 0)
  196856. motifHints.functions |= 32; /* MWM_FUNC_CLOSE */
  196857. if ((styleFlags & windowHasMinimiseButton) != 0)
  196858. {
  196859. motifHints.functions |= 8; /* MWM_FUNC_MINIMIZE */
  196860. motifHints.decorations |= 0x20; /* MWM_DECOR_MINIMIZE */
  196861. }
  196862. if ((styleFlags & windowHasMaximiseButton) != 0)
  196863. {
  196864. motifHints.functions |= 0x10; /* MWM_FUNC_MAXIMIZE */
  196865. motifHints.decorations |= 0x40; /* MWM_DECOR_MAXIMIZE */
  196866. }
  196867. if ((styleFlags & windowIsResizable) != 0)
  196868. {
  196869. motifHints.functions |= 2; /* MWM_FUNC_RESIZE */
  196870. motifHints.decorations |= 0x4; /* MWM_DECOR_RESIZEH */
  196871. }
  196872. XChangeProperty (display, wndH, hints, hints, 32, 0, (unsigned char*) &motifHints, 5);
  196873. }
  196874. hints = XInternAtom (display, "_NET_WM_ALLOWED_ACTIONS", True);
  196875. if (hints != None)
  196876. {
  196877. int netHints [6];
  196878. int num = 0;
  196879. netHints [num++] = XInternAtom (display, "_NET_WM_ACTION_RESIZE", (styleFlags & windowIsResizable) ? True : False);
  196880. netHints [num++] = XInternAtom (display, "_NET_WM_ACTION_FULLSCREEN", (styleFlags & windowHasMaximiseButton) ? True : False);
  196881. netHints [num++] = XInternAtom (display, "_NET_WM_ACTION_MINIMIZE", (styleFlags & windowHasMinimiseButton) ? True : False);
  196882. netHints [num++] = XInternAtom (display, "_NET_WM_ACTION_CLOSE", (styleFlags & windowHasCloseButton) ? True : False);
  196883. XChangeProperty (display, wndH, hints, XA_ATOM, 32, PropModeReplace,
  196884. (unsigned char*) &netHints, num);
  196885. }
  196886. }
  196887. void setWindowType (Window wndH)
  196888. {
  196889. int netHints [2];
  196890. int numHints = 0;
  196891. if ((styleFlags & windowIsTemporary) != 0
  196892. || ((styleFlags & windowHasDropShadow) == 0 && Desktop::canUseSemiTransparentWindows()))
  196893. {
  196894. netHints [numHints] = XInternAtom (display, "_NET_WM_WINDOW_TYPE_COMBO", True);
  196895. }
  196896. else
  196897. {
  196898. netHints [numHints] = XInternAtom (display, "_NET_WM_WINDOW_TYPE_NORMAL", True);
  196899. }
  196900. if (netHints [numHints] != 0)
  196901. ++numHints;
  196902. netHints[numHints] = XInternAtom (display, "_KDE_NET_WM_WINDOW_TYPE_OVERRIDE", True);
  196903. if (netHints [numHints] != 0)
  196904. ++numHints;
  196905. XChangeProperty (display, wndH, Atoms::WindowType, XA_ATOM, 32, PropModeReplace,
  196906. (unsigned char*) &netHints, numHints);
  196907. if ((styleFlags & windowAppearsOnTaskbar) == 0)
  196908. {
  196909. }
  196910. }
  196911. void createWindow()
  196912. {
  196913. ScopedXLock xlock;
  196914. Atoms::initialiseAtoms();
  196915. resetDragAndDrop();
  196916. // Get defaults for various properties
  196917. const int screen = DefaultScreen (display);
  196918. Window root = RootWindow (display, screen);
  196919. // Try to obtain a 32-bit visual or fallback to 24 or 16
  196920. visual = Visuals::findVisualFormat ((styleFlags & windowIsSemiTransparent) ? 32 : 24, depth);
  196921. if (visual == 0)
  196922. {
  196923. Logger::outputDebugString ("ERROR: System doesn't support 32, 24 or 16 bit RGB display.\n");
  196924. Process::terminate();
  196925. }
  196926. // Create and install a colormap suitable fr our visual
  196927. Colormap colormap = XCreateColormap (display, root, visual, AllocNone);
  196928. XInstallColormap (display, colormap);
  196929. // Set up the window attributes
  196930. XSetWindowAttributes swa;
  196931. swa.border_pixel = 0;
  196932. swa.background_pixmap = None;
  196933. swa.colormap = colormap;
  196934. swa.override_redirect = getComponent()->isAlwaysOnTop() ? True : False;
  196935. swa.event_mask = eventMask;
  196936. Window wndH = XCreateWindow (display, root,
  196937. 0, 0, 1, 1,
  196938. 0, depth, InputOutput, visual,
  196939. CWBorderPixel | CWColormap | CWBackPixmap | CWEventMask | CWOverrideRedirect,
  196940. &swa);
  196941. XGrabButton (display, AnyButton, AnyModifier, wndH, False,
  196942. ButtonPressMask | ButtonReleaseMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask,
  196943. GrabModeAsync, GrabModeAsync, None, None);
  196944. // Set the window context to identify the window handle object
  196945. if (XSaveContext (display, (XID) wndH, improbableNumber, (XPointer) this))
  196946. {
  196947. // Failed
  196948. jassertfalse
  196949. Logger::outputDebugString ("Failed to create context information for window.\n");
  196950. XDestroyWindow (display, wndH);
  196951. wndH = 0;
  196952. }
  196953. // Set window manager hints
  196954. XWMHints* wmHints = XAllocWMHints();
  196955. wmHints->flags = InputHint | StateHint;
  196956. wmHints->input = True; // Locally active input model
  196957. wmHints->initial_state = NormalState;
  196958. XSetWMHints (display, wndH, wmHints);
  196959. XFree (wmHints);
  196960. // Set the window type
  196961. setWindowType (wndH);
  196962. // Define decoration
  196963. if ((styleFlags & windowHasTitleBar) == 0)
  196964. removeWindowDecorations (wndH);
  196965. else
  196966. addWindowButtons (wndH);
  196967. // Set window name
  196968. setWindowTitle (wndH, getComponent()->getName());
  196969. // Associate the PID, allowing to be shut down when something goes wrong
  196970. unsigned long pid = getpid();
  196971. XChangeProperty (display, wndH, Atoms::Pid, XA_CARDINAL, 32, PropModeReplace,
  196972. (unsigned char*) &pid, 1);
  196973. // Set window manager protocols
  196974. XChangeProperty (display, wndH, Atoms::Protocols, XA_ATOM, 32, PropModeReplace,
  196975. (unsigned char*) Atoms::ProtocolList, 2);
  196976. // Set drag and drop flags
  196977. XChangeProperty (display, wndH, Atoms::XdndTypeList, XA_ATOM, 32, PropModeReplace,
  196978. (const unsigned char*) Atoms::allowedMimeTypes, numElementsInArray (Atoms::allowedMimeTypes));
  196979. XChangeProperty (display, wndH, Atoms::XdndActionList, XA_ATOM, 32, PropModeReplace,
  196980. (const unsigned char*) Atoms::allowedActions, numElementsInArray (Atoms::allowedActions));
  196981. XChangeProperty (display, wndH, Atoms::XdndActionDescription, XA_STRING, 8, PropModeReplace,
  196982. (const unsigned char*) "", 0);
  196983. unsigned long dndVersion = Atoms::DndVersion;
  196984. XChangeProperty (display, wndH, Atoms::XdndAware, XA_ATOM, 32, PropModeReplace,
  196985. (const unsigned char*) &dndVersion, 1);
  196986. // Initialise the pointer and keyboard mapping
  196987. // This is not the same as the logical pointer mapping the X server uses:
  196988. // we don't mess with this.
  196989. static bool mappingInitialised = false;
  196990. if (! mappingInitialised)
  196991. {
  196992. mappingInitialised = true;
  196993. const int numButtons = XGetPointerMapping (display, 0, 0);
  196994. if (numButtons == 2)
  196995. {
  196996. pointerMap[0] = Keys::LeftButton;
  196997. pointerMap[1] = Keys::RightButton;
  196998. pointerMap[2] = pointerMap[3] = pointerMap[4] = Keys::NoButton;
  196999. }
  197000. else if (numButtons >= 3)
  197001. {
  197002. pointerMap[0] = Keys::LeftButton;
  197003. pointerMap[1] = Keys::MiddleButton;
  197004. pointerMap[2] = Keys::RightButton;
  197005. if (numButtons >= 5)
  197006. {
  197007. pointerMap[3] = Keys::WheelUp;
  197008. pointerMap[4] = Keys::WheelDown;
  197009. }
  197010. }
  197011. updateModifierMappings();
  197012. }
  197013. windowH = wndH;
  197014. }
  197015. void destroyWindow()
  197016. {
  197017. ScopedXLock xlock;
  197018. XPointer handlePointer;
  197019. if (! XFindContext (display, (XID) windowH, improbableNumber, &handlePointer))
  197020. XDeleteContext (display, (XID) windowH, improbableNumber);
  197021. XDestroyWindow (display, windowH);
  197022. // Wait for it to complete and then remove any events for this
  197023. // window from the event queue.
  197024. XSync (display, false);
  197025. XEvent event;
  197026. while (XCheckWindowEvent (display, windowH, eventMask, &event) == True)
  197027. {}
  197028. }
  197029. static int64 getEventTime (::Time t)
  197030. {
  197031. static int64 eventTimeOffset = 0x12345678;
  197032. const int64 thisMessageTime = t;
  197033. if (eventTimeOffset == 0x12345678)
  197034. eventTimeOffset = Time::currentTimeMillis() - thisMessageTime;
  197035. return eventTimeOffset + thisMessageTime;
  197036. }
  197037. static void setWindowTitle (Window xwin, const String& title)
  197038. {
  197039. XTextProperty nameProperty;
  197040. char* strings[] = { const_cast <char*> (title.toUTF8()) };
  197041. ScopedXLock xlock;
  197042. if (XStringListToTextProperty (strings, 1, &nameProperty))
  197043. {
  197044. XSetWMName (display, xwin, &nameProperty);
  197045. XSetWMIconName (display, xwin, &nameProperty);
  197046. XFree (nameProperty.value);
  197047. }
  197048. }
  197049. void updateBorderSize()
  197050. {
  197051. if ((styleFlags & windowHasTitleBar) == 0)
  197052. {
  197053. windowBorder = BorderSize (0);
  197054. }
  197055. else if (windowBorder.getTopAndBottom() == 0 && windowBorder.getLeftAndRight() == 0)
  197056. {
  197057. ScopedXLock xlock;
  197058. Atom hints = XInternAtom (display, "_NET_FRAME_EXTENTS", True);
  197059. if (hints != None)
  197060. {
  197061. unsigned char* data = 0;
  197062. unsigned long nitems, bytesLeft;
  197063. Atom actualType;
  197064. int actualFormat;
  197065. if (XGetWindowProperty (display, windowH, hints, 0, 4, False,
  197066. XA_CARDINAL, &actualType, &actualFormat, &nitems, &bytesLeft,
  197067. &data) == Success)
  197068. {
  197069. const unsigned long* const sizes = (const unsigned long*) data;
  197070. if (actualFormat == 32)
  197071. windowBorder = BorderSize ((int) sizes[2], (int) sizes[0],
  197072. (int) sizes[3], (int) sizes[1]);
  197073. XFree (data);
  197074. }
  197075. }
  197076. }
  197077. }
  197078. void updateBounds()
  197079. {
  197080. jassert (windowH != 0);
  197081. if (windowH != 0)
  197082. {
  197083. Window root, child;
  197084. unsigned int bw, depth;
  197085. ScopedXLock xlock;
  197086. if (! XGetGeometry (display, (::Drawable) windowH, &root,
  197087. &wx, &wy, (unsigned int*) &ww, (unsigned int*) &wh,
  197088. &bw, &depth))
  197089. {
  197090. wx = wy = ww = wh = 0;
  197091. }
  197092. else if (! XTranslateCoordinates (display, windowH, root, 0, 0, &wx, &wy, &child))
  197093. {
  197094. wx = wy = 0;
  197095. }
  197096. }
  197097. }
  197098. void resetDragAndDrop()
  197099. {
  197100. dragAndDropFiles.clear();
  197101. lastDropPos = Point<int> (-1, -1);
  197102. dragAndDropCurrentMimeType = 0;
  197103. dragAndDropSourceWindow = 0;
  197104. srcMimeTypeAtomList.clear();
  197105. }
  197106. void sendDragAndDropMessage (XClientMessageEvent& msg)
  197107. {
  197108. msg.type = ClientMessage;
  197109. msg.display = display;
  197110. msg.window = dragAndDropSourceWindow;
  197111. msg.format = 32;
  197112. msg.data.l[0] = windowH;
  197113. ScopedXLock xlock;
  197114. XSendEvent (display, dragAndDropSourceWindow, False, 0, (XEvent*) &msg);
  197115. }
  197116. void sendDragAndDropStatus (const bool acceptDrop, Atom dropAction)
  197117. {
  197118. XClientMessageEvent msg;
  197119. zerostruct (msg);
  197120. msg.message_type = Atoms::XdndStatus;
  197121. msg.data.l[1] = (acceptDrop ? 1 : 0) | 2; // 2 indicates that we want to receive position messages
  197122. msg.data.l[4] = dropAction;
  197123. sendDragAndDropMessage (msg);
  197124. }
  197125. void sendDragAndDropLeave()
  197126. {
  197127. XClientMessageEvent msg;
  197128. zerostruct (msg);
  197129. msg.message_type = Atoms::XdndLeave;
  197130. sendDragAndDropMessage (msg);
  197131. }
  197132. void sendDragAndDropFinish()
  197133. {
  197134. XClientMessageEvent msg;
  197135. zerostruct (msg);
  197136. msg.message_type = Atoms::XdndFinished;
  197137. sendDragAndDropMessage (msg);
  197138. }
  197139. void handleDragAndDropStatus (const XClientMessageEvent* const clientMsg)
  197140. {
  197141. if ((clientMsg->data.l[1] & 1) == 0)
  197142. {
  197143. sendDragAndDropLeave();
  197144. if (dragAndDropFiles.size() > 0)
  197145. handleFileDragExit (dragAndDropFiles);
  197146. dragAndDropFiles.clear();
  197147. }
  197148. }
  197149. void handleDragAndDropPosition (const XClientMessageEvent* const clientMsg)
  197150. {
  197151. if (dragAndDropSourceWindow == 0)
  197152. return;
  197153. dragAndDropSourceWindow = clientMsg->data.l[0];
  197154. Point<int> dropPos ((int) clientMsg->data.l[2] >> 16,
  197155. (int) clientMsg->data.l[2] & 0xffff);
  197156. dropPos -= getScreenPosition();
  197157. if (lastDropPos != dropPos)
  197158. {
  197159. lastDropPos = dropPos;
  197160. dragAndDropTimestamp = clientMsg->data.l[3];
  197161. Atom targetAction = Atoms::XdndActionCopy;
  197162. for (int i = numElementsInArray (Atoms::allowedActions); --i >= 0;)
  197163. {
  197164. if ((Atom) clientMsg->data.l[4] == Atoms::allowedActions[i])
  197165. {
  197166. targetAction = Atoms::allowedActions[i];
  197167. break;
  197168. }
  197169. }
  197170. sendDragAndDropStatus (true, targetAction);
  197171. if (dragAndDropFiles.size() == 0)
  197172. updateDraggedFileList (clientMsg);
  197173. if (dragAndDropFiles.size() > 0)
  197174. handleFileDragMove (dragAndDropFiles, dropPos);
  197175. }
  197176. }
  197177. void handleDragAndDropDrop (const XClientMessageEvent* const clientMsg)
  197178. {
  197179. if (dragAndDropFiles.size() == 0)
  197180. updateDraggedFileList (clientMsg);
  197181. const StringArray files (dragAndDropFiles);
  197182. const Point<int> lastPos (lastDropPos);
  197183. sendDragAndDropFinish();
  197184. resetDragAndDrop();
  197185. if (files.size() > 0)
  197186. handleFileDragDrop (files, lastPos);
  197187. }
  197188. void handleDragAndDropEnter (const XClientMessageEvent* const clientMsg)
  197189. {
  197190. dragAndDropFiles.clear();
  197191. srcMimeTypeAtomList.clear();
  197192. dragAndDropCurrentMimeType = 0;
  197193. const unsigned long dndCurrentVersion = static_cast <unsigned long> (clientMsg->data.l[1] & 0xff000000) >> 24;
  197194. if (dndCurrentVersion < 3 || dndCurrentVersion > Atoms::DndVersion)
  197195. {
  197196. dragAndDropSourceWindow = 0;
  197197. return;
  197198. }
  197199. dragAndDropSourceWindow = clientMsg->data.l[0];
  197200. if ((clientMsg->data.l[1] & 1) != 0)
  197201. {
  197202. Atom actual;
  197203. int format;
  197204. unsigned long count = 0, remaining = 0;
  197205. unsigned char* data = 0;
  197206. ScopedXLock xlock;
  197207. XGetWindowProperty (display, dragAndDropSourceWindow, Atoms::XdndTypeList,
  197208. 0, 0x8000000L, False, XA_ATOM, &actual, &format,
  197209. &count, &remaining, &data);
  197210. if (data != 0)
  197211. {
  197212. if (actual == XA_ATOM && format == 32 && count != 0)
  197213. {
  197214. const unsigned long* const types = (const unsigned long*) data;
  197215. for (unsigned int i = 0; i < count; ++i)
  197216. if (types[i] != None)
  197217. srcMimeTypeAtomList.add (types[i]);
  197218. }
  197219. XFree (data);
  197220. }
  197221. }
  197222. if (srcMimeTypeAtomList.size() == 0)
  197223. {
  197224. for (int i = 2; i < 5; ++i)
  197225. if (clientMsg->data.l[i] != None)
  197226. srcMimeTypeAtomList.add (clientMsg->data.l[i]);
  197227. if (srcMimeTypeAtomList.size() == 0)
  197228. {
  197229. dragAndDropSourceWindow = 0;
  197230. return;
  197231. }
  197232. }
  197233. for (int i = 0; i < srcMimeTypeAtomList.size() && dragAndDropCurrentMimeType == 0; ++i)
  197234. for (int j = 0; j < numElementsInArray (Atoms::allowedMimeTypes); ++j)
  197235. if (srcMimeTypeAtomList[i] == Atoms::allowedMimeTypes[j])
  197236. dragAndDropCurrentMimeType = Atoms::allowedMimeTypes[j];
  197237. handleDragAndDropPosition (clientMsg);
  197238. }
  197239. void handleDragAndDropSelection (const XEvent* const evt)
  197240. {
  197241. dragAndDropFiles.clear();
  197242. if (evt->xselection.property != 0)
  197243. {
  197244. StringArray lines;
  197245. {
  197246. MemoryBlock dropData;
  197247. for (;;)
  197248. {
  197249. Atom actual;
  197250. uint8* data = 0;
  197251. unsigned long count = 0, remaining = 0;
  197252. int format = 0;
  197253. ScopedXLock xlock;
  197254. if (XGetWindowProperty (display, evt->xany.window, evt->xselection.property,
  197255. dropData.getSize() / 4, 65536, 1, AnyPropertyType, &actual,
  197256. &format, &count, &remaining, &data) == Success)
  197257. {
  197258. dropData.append (data, count * format / 8);
  197259. XFree (data);
  197260. if (remaining == 0)
  197261. break;
  197262. }
  197263. else
  197264. {
  197265. XFree (data);
  197266. break;
  197267. }
  197268. }
  197269. lines.addLines (dropData.toString());
  197270. }
  197271. for (int i = 0; i < lines.size(); ++i)
  197272. dragAndDropFiles.add (URL::removeEscapeChars (lines[i].fromFirstOccurrenceOf (T("file://"), false, true)));
  197273. dragAndDropFiles.trim();
  197274. dragAndDropFiles.removeEmptyStrings();
  197275. }
  197276. }
  197277. void updateDraggedFileList (const XClientMessageEvent* const clientMsg)
  197278. {
  197279. dragAndDropFiles.clear();
  197280. if (dragAndDropSourceWindow != None
  197281. && dragAndDropCurrentMimeType != 0)
  197282. {
  197283. dragAndDropTimestamp = clientMsg->data.l[2];
  197284. ScopedXLock xlock;
  197285. XConvertSelection (display,
  197286. Atoms::XdndSelection,
  197287. dragAndDropCurrentMimeType,
  197288. XInternAtom (display, "JXSelectionWindowProperty", 0),
  197289. windowH,
  197290. dragAndDropTimestamp);
  197291. }
  197292. }
  197293. StringArray dragAndDropFiles;
  197294. int dragAndDropTimestamp;
  197295. Point<int> lastDropPos;
  197296. Atom dragAndDropCurrentMimeType;
  197297. Window dragAndDropSourceWindow;
  197298. Array <Atom> srcMimeTypeAtomList;
  197299. static int pointerMap[5];
  197300. static Point<int> lastMousePos;
  197301. static void clearLastMousePos() throw()
  197302. {
  197303. lastMousePos = Point<int> (0x100000, 0x100000);
  197304. }
  197305. };
  197306. ModifierKeys LinuxComponentPeer::currentModifiers;
  197307. int LinuxComponentPeer::pointerMap[5];
  197308. Point<int> LinuxComponentPeer::lastMousePos;
  197309. void ModifierKeys::updateCurrentModifiers() throw()
  197310. {
  197311. currentModifiers = LinuxComponentPeer::currentModifiers;
  197312. }
  197313. const ModifierKeys ModifierKeys::getCurrentModifiersRealtime() throw()
  197314. {
  197315. Window root, child;
  197316. int x, y, winx, winy;
  197317. unsigned int mask;
  197318. int mouseMods = 0;
  197319. ScopedXLock xlock;
  197320. if (XQueryPointer (display, RootWindow (display, DefaultScreen (display)),
  197321. &root, &child, &x, &y, &winx, &winy, &mask) != False)
  197322. {
  197323. if ((mask & Button1Mask) != 0) mouseMods |= ModifierKeys::leftButtonModifier;
  197324. if ((mask & Button2Mask) != 0) mouseMods |= ModifierKeys::middleButtonModifier;
  197325. if ((mask & Button3Mask) != 0) mouseMods |= ModifierKeys::rightButtonModifier;
  197326. }
  197327. LinuxComponentPeer::currentModifiers = LinuxComponentPeer::currentModifiers.withoutMouseButtons().withFlags (mouseMods);
  197328. return LinuxComponentPeer::currentModifiers;
  197329. }
  197330. void juce_setKioskComponent (Component* kioskModeComponent, bool enableOrDisable, bool allowMenusAndBars)
  197331. {
  197332. if (enableOrDisable)
  197333. kioskModeComponent->setBounds (Desktop::getInstance().getMainMonitorArea (false));
  197334. }
  197335. ComponentPeer* Component::createNewPeer (int styleFlags, void* /*nativeWindowToAttachTo*/)
  197336. {
  197337. return new LinuxComponentPeer (this, styleFlags);
  197338. }
  197339. // (this callback is hooked up in the messaging code)
  197340. void juce_windowMessageReceive (XEvent* event)
  197341. {
  197342. if (event->xany.window != None)
  197343. {
  197344. LinuxComponentPeer* const peer = LinuxComponentPeer::getPeerFor (event->xany.window);
  197345. if (ComponentPeer::isValidPeer (peer))
  197346. peer->handleWindowMessage (event);
  197347. }
  197348. else
  197349. {
  197350. switch (event->xany.type)
  197351. {
  197352. case KeymapNotify:
  197353. {
  197354. const XKeymapEvent* const keymapEvent = (const XKeymapEvent*) &event->xkeymap;
  197355. memcpy (Keys::keyStates, keymapEvent->key_vector, 32);
  197356. break;
  197357. }
  197358. default:
  197359. break;
  197360. }
  197361. }
  197362. }
  197363. void juce_updateMultiMonitorInfo (Array <Rectangle<int> >& monitorCoords, const bool /*clipToWorkArea*/)
  197364. {
  197365. if (display == 0)
  197366. return;
  197367. #if JUCE_USE_XINERAMA
  197368. int major_opcode, first_event, first_error;
  197369. ScopedXLock xlock;
  197370. if (XQueryExtension (display, "XINERAMA", &major_opcode, &first_event, &first_error))
  197371. {
  197372. typedef Bool (*tXineramaIsActive) (Display*);
  197373. typedef XineramaScreenInfo* (*tXineramaQueryScreens) (Display*, int*);
  197374. static tXineramaIsActive xXineramaIsActive = 0;
  197375. static tXineramaQueryScreens xXineramaQueryScreens = 0;
  197376. if (xXineramaIsActive == 0 || xXineramaQueryScreens == 0)
  197377. {
  197378. void* h = dlopen ("libXinerama.so", RTLD_GLOBAL | RTLD_NOW);
  197379. if (h != 0)
  197380. {
  197381. xXineramaIsActive = (tXineramaIsActive) dlsym (h, "XineramaIsActive");
  197382. xXineramaQueryScreens = (tXineramaQueryScreens) dlsym (h, "XineramaQueryScreens");
  197383. }
  197384. }
  197385. if (xXineramaIsActive != 0
  197386. && xXineramaQueryScreens != 0
  197387. && xXineramaIsActive (display))
  197388. {
  197389. int numMonitors = 0;
  197390. XineramaScreenInfo* const screens = xXineramaQueryScreens (display, &numMonitors);
  197391. if (screens != 0)
  197392. {
  197393. for (int i = numMonitors; --i >= 0;)
  197394. {
  197395. int index = screens[i].screen_number;
  197396. if (index >= 0)
  197397. {
  197398. while (monitorCoords.size() < index)
  197399. monitorCoords.add (Rectangle<int>());
  197400. monitorCoords.set (index, Rectangle<int> (screens[i].x_org,
  197401. screens[i].y_org,
  197402. screens[i].width,
  197403. screens[i].height));
  197404. }
  197405. }
  197406. XFree (screens);
  197407. }
  197408. }
  197409. }
  197410. if (monitorCoords.size() == 0)
  197411. #endif
  197412. {
  197413. Atom hints = XInternAtom (display, "_NET_WORKAREA", True);
  197414. if (hints != None)
  197415. {
  197416. const int numMonitors = ScreenCount (display);
  197417. for (int i = 0; i < numMonitors; ++i)
  197418. {
  197419. Window root = RootWindow (display, i);
  197420. unsigned long nitems, bytesLeft;
  197421. Atom actualType;
  197422. int actualFormat;
  197423. unsigned char* data = 0;
  197424. if (XGetWindowProperty (display, root, hints, 0, 4, False,
  197425. XA_CARDINAL, &actualType, &actualFormat, &nitems, &bytesLeft,
  197426. &data) == Success)
  197427. {
  197428. const long* const position = (const long*) data;
  197429. if (actualType == XA_CARDINAL && actualFormat == 32 && nitems == 4)
  197430. monitorCoords.add (Rectangle<int> (position[0], position[1],
  197431. position[2], position[3]));
  197432. XFree (data);
  197433. }
  197434. }
  197435. }
  197436. if (monitorCoords.size() == 0)
  197437. {
  197438. monitorCoords.add (Rectangle<int> (0, 0,
  197439. DisplayWidth (display, DefaultScreen (display)),
  197440. DisplayHeight (display, DefaultScreen (display))));
  197441. }
  197442. }
  197443. }
  197444. void Desktop::createMouseInputSources()
  197445. {
  197446. mouseSources.add (new MouseInputSource (0, true));
  197447. }
  197448. bool Desktop::canUseSemiTransparentWindows() throw()
  197449. {
  197450. int matchedDepth = 0;
  197451. const int desiredDepth = 32;
  197452. return Visuals::findVisualFormat (desiredDepth, matchedDepth) != 0
  197453. && (matchedDepth == desiredDepth);
  197454. }
  197455. const Point<int> Desktop::getMousePosition()
  197456. {
  197457. Window root, child;
  197458. int x, y, winx, winy;
  197459. unsigned int mask;
  197460. ScopedXLock xlock;
  197461. if (XQueryPointer (display,
  197462. RootWindow (display, DefaultScreen (display)),
  197463. &root, &child,
  197464. &x, &y, &winx, &winy, &mask) == False)
  197465. {
  197466. // Pointer not on the default screen
  197467. x = y = -1;
  197468. }
  197469. return Point<int> (x, y);
  197470. }
  197471. void Desktop::setMousePosition (const Point<int>& newPosition)
  197472. {
  197473. ScopedXLock xlock;
  197474. Window root = RootWindow (display, DefaultScreen (display));
  197475. XWarpPointer (display, None, root, 0, 0, 0, 0, newPosition.getX(), newPosition.getY());
  197476. }
  197477. static bool screenSaverAllowed = true;
  197478. void Desktop::setScreenSaverEnabled (const bool isEnabled) throw()
  197479. {
  197480. if (screenSaverAllowed != isEnabled)
  197481. {
  197482. screenSaverAllowed = isEnabled;
  197483. typedef void (*tXScreenSaverSuspend) (Display*, Bool);
  197484. static tXScreenSaverSuspend xScreenSaverSuspend = 0;
  197485. if (xScreenSaverSuspend == 0)
  197486. {
  197487. void* h = dlopen ("libXss.so", RTLD_GLOBAL | RTLD_NOW);
  197488. if (h != 0)
  197489. xScreenSaverSuspend = (tXScreenSaverSuspend) dlsym (h, "XScreenSaverSuspend");
  197490. }
  197491. ScopedXLock xlock;
  197492. if (xScreenSaverSuspend != 0)
  197493. xScreenSaverSuspend (display, ! isEnabled);
  197494. }
  197495. }
  197496. bool Desktop::isScreenSaverEnabled() throw()
  197497. {
  197498. return screenSaverAllowed;
  197499. }
  197500. void* juce_createMouseCursorFromImage (const Image& image, int hotspotX, int hotspotY) throw()
  197501. {
  197502. ScopedXLock xlock;
  197503. Window root = RootWindow (display, DefaultScreen (display));
  197504. const unsigned int imageW = image.getWidth();
  197505. const unsigned int imageH = image.getHeight();
  197506. unsigned int cursorW, cursorH;
  197507. if (! XQueryBestCursor (display, root, imageW, imageH, &cursorW, &cursorH))
  197508. return 0;
  197509. Image im (Image::ARGB, cursorW, cursorH, true);
  197510. Graphics g (im);
  197511. if (imageW > cursorW || imageH > cursorH)
  197512. {
  197513. hotspotX = (hotspotX * cursorW) / imageW;
  197514. hotspotY = (hotspotY * cursorH) / imageH;
  197515. g.drawImageWithin (&image, 0, 0, imageW, imageH,
  197516. RectanglePlacement::xLeft | RectanglePlacement::yTop | RectanglePlacement::onlyReduceInSize,
  197517. false);
  197518. }
  197519. else
  197520. {
  197521. g.drawImageAt (&image, 0, 0);
  197522. }
  197523. const int stride = (cursorW + 7) >> 3;
  197524. HeapBlock <uint8> maskPlane, sourcePlane;
  197525. maskPlane.calloc (stride * cursorH);
  197526. sourcePlane.calloc (stride * cursorH);
  197527. const bool msbfirst = (BitmapBitOrder (display) == MSBFirst);
  197528. for (int y = cursorH; --y >= 0;)
  197529. {
  197530. for (int x = cursorW; --x >= 0;)
  197531. {
  197532. const uint8 mask = (uint8) (1 << (msbfirst ? (7 - (x & 7)) : (x & 7)));
  197533. const int offset = y * stride + (x >> 3);
  197534. const Colour c (im.getPixelAt (x, y));
  197535. if (c.getAlpha() >= 128)
  197536. maskPlane[offset] |= mask;
  197537. if (c.getBrightness() >= 0.5f)
  197538. sourcePlane[offset] |= mask;
  197539. }
  197540. }
  197541. Pixmap sourcePixmap = XCreatePixmapFromBitmapData (display, root, reinterpret_cast <char*> (sourcePlane.getData()), cursorW, cursorH, 0xffff, 0, 1);
  197542. Pixmap maskPixmap = XCreatePixmapFromBitmapData (display, root, reinterpret_cast <char*> (maskPlane.getData()), cursorW, cursorH, 0xffff, 0, 1);
  197543. XColor white, black;
  197544. black.red = black.green = black.blue = 0;
  197545. white.red = white.green = white.blue = 0xffff;
  197546. void* result = (void*) XCreatePixmapCursor (display, sourcePixmap, maskPixmap, &white, &black, hotspotX, hotspotY);
  197547. XFreePixmap (display, sourcePixmap);
  197548. XFreePixmap (display, maskPixmap);
  197549. return result;
  197550. }
  197551. void juce_deleteMouseCursor (void* const cursorHandle, const bool) throw()
  197552. {
  197553. ScopedXLock xlock;
  197554. if (cursorHandle != None)
  197555. XFreeCursor (display, (Cursor) cursorHandle);
  197556. }
  197557. void* juce_createStandardMouseCursor (MouseCursor::StandardCursorType type) throw()
  197558. {
  197559. unsigned int shape;
  197560. switch (type)
  197561. {
  197562. case MouseCursor::NoCursor:
  197563. {
  197564. const Image im (Image::ARGB, 16, 16, true);
  197565. return juce_createMouseCursorFromImage (im, 0, 0);
  197566. }
  197567. case MouseCursor::NormalCursor:
  197568. return (void*) None; // Use parent cursor
  197569. case MouseCursor::DraggingHandCursor:
  197570. {
  197571. static unsigned char dragHandData[] = {71,73,70,56,57,97,16,0,16,0,145,2,0,0,0,0,255,255,255,0,
  197572. 0,0,0,0,0,33,249,4,1,0,0,2,0,44,0,0,0,0,16,0,
  197573. 16,0,0,2,52,148,47,0,200,185,16,130,90,12,74,139,107,84,123,39,
  197574. 132,117,151,116,132,146,248,60,209,138,98,22,203,114,34,236,37,52,77,217,
  197575. 247,154,191,119,110,240,193,128,193,95,163,56,60,234,98,135,2,0,59 };
  197576. const int dragHandDataSize = 99;
  197577. const ScopedPointer <Image> im (ImageFileFormat::loadFrom ((const char*) dragHandData, dragHandDataSize));
  197578. return juce_createMouseCursorFromImage (*im, 8, 7);
  197579. }
  197580. case MouseCursor::CopyingCursor:
  197581. {
  197582. static unsigned char copyCursorData[] = {71,73,70,56,57,97,21,0,21,0,145,0,0,0,0,0,255,255,255,0,
  197583. 128,128,255,255,255,33,249,4,1,0,0,3,0,44,0,0,0,0,21,0,
  197584. 21,0,0,2,72,4,134,169,171,16,199,98,11,79,90,71,161,93,56,111,
  197585. 78,133,218,215,137,31,82,154,100,200,86,91,202,142,12,108,212,87,235,174,
  197586. 15,54,214,126,237,226,37,96,59,141,16,37,18,201,142,157,230,204,51,112,
  197587. 252,114,147,74,83,5,50,68,147,208,217,16,71,149,252,124,5,0,59,0,0 };
  197588. const int copyCursorSize = 119;
  197589. const ScopedPointer <Image> im (ImageFileFormat::loadFrom ((const char*) copyCursorData, copyCursorSize));
  197590. return juce_createMouseCursorFromImage (*im, 1, 3);
  197591. }
  197592. case MouseCursor::WaitCursor:
  197593. shape = XC_watch;
  197594. break;
  197595. case MouseCursor::IBeamCursor:
  197596. shape = XC_xterm;
  197597. break;
  197598. case MouseCursor::PointingHandCursor:
  197599. shape = XC_hand2;
  197600. break;
  197601. case MouseCursor::LeftRightResizeCursor:
  197602. shape = XC_sb_h_double_arrow;
  197603. break;
  197604. case MouseCursor::UpDownResizeCursor:
  197605. shape = XC_sb_v_double_arrow;
  197606. break;
  197607. case MouseCursor::UpDownLeftRightResizeCursor:
  197608. shape = XC_fleur;
  197609. break;
  197610. case MouseCursor::TopEdgeResizeCursor:
  197611. shape = XC_top_side;
  197612. break;
  197613. case MouseCursor::BottomEdgeResizeCursor:
  197614. shape = XC_bottom_side;
  197615. break;
  197616. case MouseCursor::LeftEdgeResizeCursor:
  197617. shape = XC_left_side;
  197618. break;
  197619. case MouseCursor::RightEdgeResizeCursor:
  197620. shape = XC_right_side;
  197621. break;
  197622. case MouseCursor::TopLeftCornerResizeCursor:
  197623. shape = XC_top_left_corner;
  197624. break;
  197625. case MouseCursor::TopRightCornerResizeCursor:
  197626. shape = XC_top_right_corner;
  197627. break;
  197628. case MouseCursor::BottomLeftCornerResizeCursor:
  197629. shape = XC_bottom_left_corner;
  197630. break;
  197631. case MouseCursor::BottomRightCornerResizeCursor:
  197632. shape = XC_bottom_right_corner;
  197633. break;
  197634. case MouseCursor::CrosshairCursor:
  197635. shape = XC_crosshair;
  197636. break;
  197637. default:
  197638. return (void*) None; // Use parent cursor
  197639. }
  197640. ScopedXLock xlock;
  197641. return (void*) XCreateFontCursor (display, shape);
  197642. }
  197643. void MouseCursor::showInWindow (ComponentPeer* peer) const throw()
  197644. {
  197645. LinuxComponentPeer* const lp = dynamic_cast <LinuxComponentPeer*> (peer);
  197646. if (lp != 0)
  197647. lp->showMouseCursor ((Cursor) getHandle());
  197648. }
  197649. void MouseCursor::showInAllWindows() const throw()
  197650. {
  197651. for (int i = ComponentPeer::getNumPeers(); --i >= 0;)
  197652. showInWindow (ComponentPeer::getPeer (i));
  197653. }
  197654. Image* juce_createIconForFile (const File& file)
  197655. {
  197656. return 0;
  197657. }
  197658. Image* Image::createNativeImage (const PixelFormat format, const int imageWidth, const int imageHeight, const bool clearImage)
  197659. {
  197660. return new Image (format, imageWidth, imageHeight, clearImage);
  197661. }
  197662. #if JUCE_OPENGL
  197663. class WindowedGLContext : public OpenGLContext
  197664. {
  197665. public:
  197666. WindowedGLContext (Component* const component,
  197667. const OpenGLPixelFormat& pixelFormat_,
  197668. GLXContext sharedContext)
  197669. : renderContext (0),
  197670. embeddedWindow (0),
  197671. pixelFormat (pixelFormat_)
  197672. {
  197673. jassert (component != 0);
  197674. LinuxComponentPeer* const peer = dynamic_cast <LinuxComponentPeer*> (component->getTopLevelComponent()->getPeer());
  197675. if (peer == 0)
  197676. return;
  197677. ScopedXLock xlock;
  197678. XSync (display, False);
  197679. GLint attribs [64];
  197680. int n = 0;
  197681. attribs[n++] = GLX_RGBA;
  197682. attribs[n++] = GLX_DOUBLEBUFFER;
  197683. attribs[n++] = GLX_RED_SIZE;
  197684. attribs[n++] = pixelFormat.redBits;
  197685. attribs[n++] = GLX_GREEN_SIZE;
  197686. attribs[n++] = pixelFormat.greenBits;
  197687. attribs[n++] = GLX_BLUE_SIZE;
  197688. attribs[n++] = pixelFormat.blueBits;
  197689. attribs[n++] = GLX_ALPHA_SIZE;
  197690. attribs[n++] = pixelFormat.alphaBits;
  197691. attribs[n++] = GLX_DEPTH_SIZE;
  197692. attribs[n++] = pixelFormat.depthBufferBits;
  197693. attribs[n++] = GLX_STENCIL_SIZE;
  197694. attribs[n++] = pixelFormat.stencilBufferBits;
  197695. attribs[n++] = GLX_ACCUM_RED_SIZE;
  197696. attribs[n++] = pixelFormat.accumulationBufferRedBits;
  197697. attribs[n++] = GLX_ACCUM_GREEN_SIZE;
  197698. attribs[n++] = pixelFormat.accumulationBufferGreenBits;
  197699. attribs[n++] = GLX_ACCUM_BLUE_SIZE;
  197700. attribs[n++] = pixelFormat.accumulationBufferBlueBits;
  197701. attribs[n++] = GLX_ACCUM_ALPHA_SIZE;
  197702. attribs[n++] = pixelFormat.accumulationBufferAlphaBits;
  197703. // xxx not sure how to do fullSceneAntiAliasingNumSamples on linux..
  197704. attribs[n++] = None;
  197705. XVisualInfo* const bestVisual = glXChooseVisual (display, DefaultScreen (display), attribs);
  197706. if (bestVisual == 0)
  197707. return;
  197708. renderContext = glXCreateContext (display, bestVisual, sharedContext, GL_TRUE);
  197709. Window windowH = (Window) peer->getNativeHandle();
  197710. Colormap colourMap = XCreateColormap (display, windowH, bestVisual->visual, AllocNone);
  197711. XSetWindowAttributes swa;
  197712. swa.colormap = colourMap;
  197713. swa.border_pixel = 0;
  197714. swa.event_mask = ExposureMask | StructureNotifyMask;
  197715. embeddedWindow = XCreateWindow (display, windowH,
  197716. 0, 0, 1, 1, 0,
  197717. bestVisual->depth,
  197718. InputOutput,
  197719. bestVisual->visual,
  197720. CWBorderPixel | CWColormap | CWEventMask,
  197721. &swa);
  197722. XSaveContext (display, (XID) embeddedWindow, improbableNumber, (XPointer) peer);
  197723. XMapWindow (display, embeddedWindow);
  197724. XFreeColormap (display, colourMap);
  197725. XFree (bestVisual);
  197726. XSync (display, False);
  197727. }
  197728. ~WindowedGLContext()
  197729. {
  197730. makeInactive();
  197731. ScopedXLock xlock;
  197732. glXDestroyContext (display, renderContext);
  197733. XUnmapWindow (display, embeddedWindow);
  197734. XDestroyWindow (display, embeddedWindow);
  197735. }
  197736. bool makeActive() const throw()
  197737. {
  197738. jassert (renderContext != 0);
  197739. ScopedXLock xlock;
  197740. return glXMakeCurrent (display, embeddedWindow, renderContext)
  197741. && XSync (display, False);
  197742. }
  197743. bool makeInactive() const throw()
  197744. {
  197745. ScopedXLock xlock;
  197746. return (! isActive()) || glXMakeCurrent (display, None, 0);
  197747. }
  197748. bool isActive() const throw()
  197749. {
  197750. ScopedXLock xlock;
  197751. return glXGetCurrentContext() == renderContext;
  197752. }
  197753. const OpenGLPixelFormat getPixelFormat() const
  197754. {
  197755. return pixelFormat;
  197756. }
  197757. void* getRawContext() const throw()
  197758. {
  197759. return renderContext;
  197760. }
  197761. void updateWindowPosition (int x, int y, int w, int h, int)
  197762. {
  197763. ScopedXLock xlock;
  197764. XMoveResizeWindow (display, embeddedWindow,
  197765. x, y, jmax (1, w), jmax (1, h));
  197766. }
  197767. void swapBuffers()
  197768. {
  197769. ScopedXLock xlock;
  197770. glXSwapBuffers (display, embeddedWindow);
  197771. }
  197772. bool setSwapInterval (const int numFramesPerSwap)
  197773. {
  197774. // xxx needs doing..
  197775. return false;
  197776. }
  197777. int getSwapInterval() const
  197778. {
  197779. // xxx needs doing..
  197780. return 0;
  197781. }
  197782. void repaint()
  197783. {
  197784. }
  197785. juce_UseDebuggingNewOperator
  197786. GLXContext renderContext;
  197787. private:
  197788. Window embeddedWindow;
  197789. OpenGLPixelFormat pixelFormat;
  197790. WindowedGLContext (const WindowedGLContext&);
  197791. WindowedGLContext& operator= (const WindowedGLContext&);
  197792. };
  197793. OpenGLContext* OpenGLComponent::createContext()
  197794. {
  197795. ScopedPointer<WindowedGLContext> c (new WindowedGLContext (this, preferredPixelFormat,
  197796. contextToShareListsWith != 0 ? (GLXContext) contextToShareListsWith->getRawContext() : 0));
  197797. return (c->renderContext != 0) ? c.release() : 0;
  197798. }
  197799. void juce_glViewport (const int w, const int h)
  197800. {
  197801. glViewport (0, 0, w, h);
  197802. }
  197803. void OpenGLPixelFormat::getAvailablePixelFormats (Component* component,
  197804. OwnedArray <OpenGLPixelFormat>& results)
  197805. {
  197806. results.add (new OpenGLPixelFormat()); // xxx
  197807. }
  197808. #endif
  197809. bool DragAndDropContainer::performExternalDragDropOfFiles (const StringArray& files, const bool canMoveFiles)
  197810. {
  197811. jassertfalse // not implemented!
  197812. return false;
  197813. }
  197814. bool DragAndDropContainer::performExternalDragDropOfText (const String& text)
  197815. {
  197816. jassertfalse // not implemented!
  197817. return false;
  197818. }
  197819. void SystemTrayIconComponent::setIconImage (const Image& newImage)
  197820. {
  197821. if (! isOnDesktop ())
  197822. addToDesktop (0);
  197823. LinuxComponentPeer* const wp = dynamic_cast <LinuxComponentPeer*> (getPeer());
  197824. if (wp != 0)
  197825. {
  197826. wp->setTaskBarIcon (newImage);
  197827. setVisible (true);
  197828. toFront (false);
  197829. repaint();
  197830. }
  197831. }
  197832. void SystemTrayIconComponent::paint (Graphics& g)
  197833. {
  197834. LinuxComponentPeer* const wp = dynamic_cast <LinuxComponentPeer*> (getPeer());
  197835. if (wp != 0)
  197836. {
  197837. const Image* const image = wp->getTaskbarIcon();
  197838. if (image != 0)
  197839. {
  197840. g.drawImageWithin (image, 0, 0, getWidth(), getHeight(),
  197841. RectanglePlacement::xLeft | RectanglePlacement::yTop | RectanglePlacement::onlyReduceInSize,
  197842. false);
  197843. }
  197844. }
  197845. }
  197846. void SystemTrayIconComponent::setIconTooltip (const String& tooltip)
  197847. {
  197848. // xxx not yet implemented!
  197849. }
  197850. void PlatformUtilities::beep()
  197851. {
  197852. std::cout << "\a" << std::flush;
  197853. }
  197854. bool AlertWindow::showNativeDialogBox (const String& title,
  197855. const String& bodyText,
  197856. bool isOkCancel)
  197857. {
  197858. // use a non-native one for the time being..
  197859. if (isOkCancel)
  197860. return AlertWindow::showOkCancelBox (AlertWindow::NoIcon, title, bodyText);
  197861. else
  197862. AlertWindow::showMessageBox (AlertWindow::NoIcon, title, bodyText);
  197863. return true;
  197864. }
  197865. const int KeyPress::spaceKey = XK_space & 0xff;
  197866. const int KeyPress::returnKey = XK_Return & 0xff;
  197867. const int KeyPress::escapeKey = XK_Escape & 0xff;
  197868. const int KeyPress::backspaceKey = XK_BackSpace & 0xff;
  197869. const int KeyPress::leftKey = (XK_Left & 0xff) | Keys::extendedKeyModifier;
  197870. const int KeyPress::rightKey = (XK_Right & 0xff) | Keys::extendedKeyModifier;
  197871. const int KeyPress::upKey = (XK_Up & 0xff) | Keys::extendedKeyModifier;
  197872. const int KeyPress::downKey = (XK_Down & 0xff) | Keys::extendedKeyModifier;
  197873. const int KeyPress::pageUpKey = (XK_Page_Up & 0xff) | Keys::extendedKeyModifier;
  197874. const int KeyPress::pageDownKey = (XK_Page_Down & 0xff) | Keys::extendedKeyModifier;
  197875. const int KeyPress::endKey = (XK_End & 0xff) | Keys::extendedKeyModifier;
  197876. const int KeyPress::homeKey = (XK_Home & 0xff) | Keys::extendedKeyModifier;
  197877. const int KeyPress::insertKey = (XK_Insert & 0xff) | Keys::extendedKeyModifier;
  197878. const int KeyPress::deleteKey = (XK_Delete & 0xff) | Keys::extendedKeyModifier;
  197879. const int KeyPress::tabKey = XK_Tab & 0xff;
  197880. const int KeyPress::F1Key = (XK_F1 & 0xff) | Keys::extendedKeyModifier;
  197881. const int KeyPress::F2Key = (XK_F2 & 0xff) | Keys::extendedKeyModifier;
  197882. const int KeyPress::F3Key = (XK_F3 & 0xff) | Keys::extendedKeyModifier;
  197883. const int KeyPress::F4Key = (XK_F4 & 0xff) | Keys::extendedKeyModifier;
  197884. const int KeyPress::F5Key = (XK_F5 & 0xff) | Keys::extendedKeyModifier;
  197885. const int KeyPress::F6Key = (XK_F6 & 0xff) | Keys::extendedKeyModifier;
  197886. const int KeyPress::F7Key = (XK_F7 & 0xff) | Keys::extendedKeyModifier;
  197887. const int KeyPress::F8Key = (XK_F8 & 0xff) | Keys::extendedKeyModifier;
  197888. const int KeyPress::F9Key = (XK_F9 & 0xff) | Keys::extendedKeyModifier;
  197889. const int KeyPress::F10Key = (XK_F10 & 0xff) | Keys::extendedKeyModifier;
  197890. const int KeyPress::F11Key = (XK_F11 & 0xff) | Keys::extendedKeyModifier;
  197891. const int KeyPress::F12Key = (XK_F12 & 0xff) | Keys::extendedKeyModifier;
  197892. const int KeyPress::F13Key = (XK_F13 & 0xff) | Keys::extendedKeyModifier;
  197893. const int KeyPress::F14Key = (XK_F14 & 0xff) | Keys::extendedKeyModifier;
  197894. const int KeyPress::F15Key = (XK_F15 & 0xff) | Keys::extendedKeyModifier;
  197895. const int KeyPress::F16Key = (XK_F16 & 0xff) | Keys::extendedKeyModifier;
  197896. const int KeyPress::numberPad0 = (XK_KP_0 & 0xff) | Keys::extendedKeyModifier;
  197897. const int KeyPress::numberPad1 = (XK_KP_1 & 0xff) | Keys::extendedKeyModifier;
  197898. const int KeyPress::numberPad2 = (XK_KP_2 & 0xff) | Keys::extendedKeyModifier;
  197899. const int KeyPress::numberPad3 = (XK_KP_3 & 0xff) | Keys::extendedKeyModifier;
  197900. const int KeyPress::numberPad4 = (XK_KP_4 & 0xff) | Keys::extendedKeyModifier;
  197901. const int KeyPress::numberPad5 = (XK_KP_5 & 0xff) | Keys::extendedKeyModifier;
  197902. const int KeyPress::numberPad6 = (XK_KP_6 & 0xff) | Keys::extendedKeyModifier;
  197903. const int KeyPress::numberPad7 = (XK_KP_7 & 0xff)| Keys::extendedKeyModifier;
  197904. const int KeyPress::numberPad8 = (XK_KP_8 & 0xff)| Keys::extendedKeyModifier;
  197905. const int KeyPress::numberPad9 = (XK_KP_9 & 0xff)| Keys::extendedKeyModifier;
  197906. const int KeyPress::numberPadAdd = (XK_KP_Add & 0xff)| Keys::extendedKeyModifier;
  197907. const int KeyPress::numberPadSubtract = (XK_KP_Subtract & 0xff)| Keys::extendedKeyModifier;
  197908. const int KeyPress::numberPadMultiply = (XK_KP_Multiply & 0xff)| Keys::extendedKeyModifier;
  197909. const int KeyPress::numberPadDivide = (XK_KP_Divide & 0xff)| Keys::extendedKeyModifier;
  197910. const int KeyPress::numberPadSeparator = (XK_KP_Separator & 0xff)| Keys::extendedKeyModifier;
  197911. const int KeyPress::numberPadDecimalPoint = (XK_KP_Decimal & 0xff)| Keys::extendedKeyModifier;
  197912. const int KeyPress::numberPadEquals = (XK_KP_Equal & 0xff)| Keys::extendedKeyModifier;
  197913. const int KeyPress::numberPadDelete = (XK_KP_Delete & 0xff)| Keys::extendedKeyModifier;
  197914. const int KeyPress::playKey = (0xffeeff00) | Keys::extendedKeyModifier;
  197915. const int KeyPress::stopKey = (0xffeeff01) | Keys::extendedKeyModifier;
  197916. const int KeyPress::fastForwardKey = (0xffeeff02) | Keys::extendedKeyModifier;
  197917. const int KeyPress::rewindKey = (0xffeeff03) | Keys::extendedKeyModifier;
  197918. #endif
  197919. /*** End of inlined file: juce_linux_Windowing.cpp ***/
  197920. /*** Start of inlined file: juce_linux_Audio.cpp ***/
  197921. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  197922. // compiled on its own).
  197923. #if JUCE_INCLUDED_FILE && JUCE_ALSA
  197924. static const int maxNumChans = 64;
  197925. static void getDeviceSampleRates (snd_pcm_t* handle, Array <int>& rates)
  197926. {
  197927. const int ratesToTry[] = { 22050, 32000, 44100, 48000, 88200, 96000, 176400, 192000, 0 };
  197928. snd_pcm_hw_params_t* hwParams;
  197929. snd_pcm_hw_params_alloca (&hwParams);
  197930. for (int i = 0; ratesToTry[i] != 0; ++i)
  197931. {
  197932. if (snd_pcm_hw_params_any (handle, hwParams) >= 0
  197933. && snd_pcm_hw_params_test_rate (handle, hwParams, ratesToTry[i], 0) == 0)
  197934. {
  197935. rates.addIfNotAlreadyThere (ratesToTry[i]);
  197936. }
  197937. }
  197938. }
  197939. static void getDeviceNumChannels (snd_pcm_t* handle, unsigned int* minChans, unsigned int* maxChans)
  197940. {
  197941. snd_pcm_hw_params_t *params;
  197942. snd_pcm_hw_params_alloca (&params);
  197943. if (snd_pcm_hw_params_any (handle, params) >= 0)
  197944. {
  197945. snd_pcm_hw_params_get_channels_min (params, minChans);
  197946. snd_pcm_hw_params_get_channels_max (params, maxChans);
  197947. }
  197948. }
  197949. static void getDeviceProperties (const String& deviceID,
  197950. unsigned int& minChansOut,
  197951. unsigned int& maxChansOut,
  197952. unsigned int& minChansIn,
  197953. unsigned int& maxChansIn,
  197954. Array <int>& rates)
  197955. {
  197956. if (deviceID.isEmpty())
  197957. return;
  197958. snd_ctl_t* handle;
  197959. if (snd_ctl_open (&handle, deviceID.upToLastOccurrenceOf (T(","), false, false).toUTF8(), SND_CTL_NONBLOCK) >= 0)
  197960. {
  197961. snd_pcm_info_t* info;
  197962. snd_pcm_info_alloca (&info);
  197963. snd_pcm_info_set_stream (info, SND_PCM_STREAM_PLAYBACK);
  197964. snd_pcm_info_set_device (info, deviceID.fromLastOccurrenceOf (T(","), false, false).getIntValue());
  197965. snd_pcm_info_set_subdevice (info, 0);
  197966. if (snd_ctl_pcm_info (handle, info) >= 0)
  197967. {
  197968. snd_pcm_t* pcmHandle;
  197969. if (snd_pcm_open (&pcmHandle, deviceID.toUTF8(), SND_PCM_STREAM_PLAYBACK, SND_PCM_ASYNC | SND_PCM_NONBLOCK ) >= 0)
  197970. {
  197971. getDeviceNumChannels (pcmHandle, &minChansOut, &maxChansOut);
  197972. getDeviceSampleRates (pcmHandle, rates);
  197973. snd_pcm_close (pcmHandle);
  197974. }
  197975. }
  197976. snd_pcm_info_set_stream (info, SND_PCM_STREAM_CAPTURE);
  197977. if (snd_ctl_pcm_info (handle, info) >= 0)
  197978. {
  197979. snd_pcm_t* pcmHandle;
  197980. if (snd_pcm_open (&pcmHandle, deviceID.toUTF8(), SND_PCM_STREAM_CAPTURE, SND_PCM_ASYNC | SND_PCM_NONBLOCK ) >= 0)
  197981. {
  197982. getDeviceNumChannels (pcmHandle, &minChansIn, &maxChansIn);
  197983. if (rates.size() == 0)
  197984. getDeviceSampleRates (pcmHandle, rates);
  197985. snd_pcm_close (pcmHandle);
  197986. }
  197987. }
  197988. snd_ctl_close (handle);
  197989. }
  197990. }
  197991. class ALSADevice
  197992. {
  197993. public:
  197994. ALSADevice (const String& deviceID,
  197995. const bool forInput)
  197996. : handle (0),
  197997. bitDepth (16),
  197998. numChannelsRunning (0),
  197999. isInput (forInput),
  198000. sampleFormat (AudioDataConverters::int16LE)
  198001. {
  198002. failed (snd_pcm_open (&handle, deviceID.toUTF8(),
  198003. forInput ? SND_PCM_STREAM_CAPTURE : SND_PCM_STREAM_PLAYBACK,
  198004. SND_PCM_ASYNC));
  198005. }
  198006. ~ALSADevice()
  198007. {
  198008. if (handle != 0)
  198009. snd_pcm_close (handle);
  198010. }
  198011. bool setParameters (unsigned int sampleRate, int numChannels, int bufferSize)
  198012. {
  198013. if (handle == 0)
  198014. return false;
  198015. snd_pcm_hw_params_t* hwParams;
  198016. snd_pcm_hw_params_alloca (&hwParams);
  198017. if (failed (snd_pcm_hw_params_any (handle, hwParams)))
  198018. return false;
  198019. if (snd_pcm_hw_params_set_access (handle, hwParams, SND_PCM_ACCESS_RW_NONINTERLEAVED) >= 0)
  198020. isInterleaved = false;
  198021. else if (snd_pcm_hw_params_set_access (handle, hwParams, SND_PCM_ACCESS_RW_INTERLEAVED) >= 0)
  198022. isInterleaved = true;
  198023. else
  198024. {
  198025. jassertfalse
  198026. return false;
  198027. }
  198028. const int formatsToTry[] = { SND_PCM_FORMAT_FLOAT_LE, 32, AudioDataConverters::float32LE,
  198029. SND_PCM_FORMAT_FLOAT_BE, 32, AudioDataConverters::float32BE,
  198030. SND_PCM_FORMAT_S32_LE, 32, AudioDataConverters::int32LE,
  198031. SND_PCM_FORMAT_S32_BE, 32, AudioDataConverters::int32BE,
  198032. SND_PCM_FORMAT_S24_3LE, 24, AudioDataConverters::int24LE,
  198033. SND_PCM_FORMAT_S24_3BE, 24, AudioDataConverters::int24BE,
  198034. SND_PCM_FORMAT_S16_LE, 16, AudioDataConverters::int16LE,
  198035. SND_PCM_FORMAT_S16_BE, 16, AudioDataConverters::int16BE };
  198036. bitDepth = 0;
  198037. for (int i = 0; i < numElementsInArray (formatsToTry); i += 3)
  198038. {
  198039. if (snd_pcm_hw_params_set_format (handle, hwParams, (_snd_pcm_format) formatsToTry [i]) >= 0)
  198040. {
  198041. bitDepth = formatsToTry [i + 1];
  198042. sampleFormat = (AudioDataConverters::DataFormat) formatsToTry [i + 2];
  198043. break;
  198044. }
  198045. }
  198046. if (bitDepth == 0)
  198047. {
  198048. error = "device doesn't support a compatible PCM format";
  198049. DBG (T("ALSA error: ") + error + T("\n"));
  198050. return false;
  198051. }
  198052. int dir = 0;
  198053. unsigned int periods = 4;
  198054. snd_pcm_uframes_t samplesPerPeriod = bufferSize;
  198055. if (failed (snd_pcm_hw_params_set_rate_near (handle, hwParams, &sampleRate, 0))
  198056. || failed (snd_pcm_hw_params_set_channels (handle, hwParams, numChannels))
  198057. || failed (snd_pcm_hw_params_set_periods_near (handle, hwParams, &periods, &dir))
  198058. || failed (snd_pcm_hw_params_set_period_size_near (handle, hwParams, &samplesPerPeriod, &dir))
  198059. || failed (snd_pcm_hw_params (handle, hwParams)))
  198060. {
  198061. return false;
  198062. }
  198063. snd_pcm_sw_params_t* swParams;
  198064. snd_pcm_sw_params_alloca (&swParams);
  198065. snd_pcm_uframes_t boundary;
  198066. if (failed (snd_pcm_sw_params_current (handle, swParams))
  198067. || failed (snd_pcm_sw_params_get_boundary (swParams, &boundary))
  198068. || failed (snd_pcm_sw_params_set_silence_threshold (handle, swParams, 0))
  198069. || failed (snd_pcm_sw_params_set_silence_size (handle, swParams, boundary))
  198070. || failed (snd_pcm_sw_params_set_start_threshold (handle, swParams, samplesPerPeriod))
  198071. || failed (snd_pcm_sw_params_set_stop_threshold (handle, swParams, boundary))
  198072. || failed (snd_pcm_sw_params (handle, swParams)))
  198073. {
  198074. return false;
  198075. }
  198076. numChannelsRunning = numChannels;
  198077. return true;
  198078. }
  198079. bool write (float** const data, const int numSamples)
  198080. {
  198081. if (isInterleaved)
  198082. {
  198083. scratch.ensureSize (sizeof (float) * numSamples * numChannelsRunning, false);
  198084. float* interleaved = reinterpret_cast <float*> (scratch.getData());
  198085. AudioDataConverters::interleaveSamples ((const float**) data, interleaved, numSamples, numChannelsRunning);
  198086. AudioDataConverters::convertFloatToFormat (sampleFormat, interleaved, interleaved, numSamples * numChannelsRunning);
  198087. snd_pcm_sframes_t num = snd_pcm_writei (handle, (void*) interleaved, numSamples);
  198088. if (failed (num) && num != -EPIPE && num != -ESTRPIPE)
  198089. return false;
  198090. }
  198091. else
  198092. {
  198093. for (int i = 0; i < numChannelsRunning; ++i)
  198094. if (data[i] != 0)
  198095. AudioDataConverters::convertFloatToFormat (sampleFormat, data[i], data[i], numSamples);
  198096. snd_pcm_sframes_t num = snd_pcm_writen (handle, (void**) data, numSamples);
  198097. if (failed (num))
  198098. {
  198099. if (num == -EPIPE)
  198100. {
  198101. if (failed (snd_pcm_prepare (handle)))
  198102. return false;
  198103. }
  198104. else if (num != -ESTRPIPE)
  198105. return false;
  198106. }
  198107. }
  198108. return true;
  198109. }
  198110. bool read (float** const data, const int numSamples)
  198111. {
  198112. if (isInterleaved)
  198113. {
  198114. scratch.ensureSize (sizeof (float) * numSamples * numChannelsRunning, false);
  198115. float* interleaved = reinterpret_cast <float*> (scratch.getData());
  198116. snd_pcm_sframes_t num = snd_pcm_readi (handle, (void*) interleaved, numSamples);
  198117. if (failed (num))
  198118. {
  198119. if (num == -EPIPE)
  198120. {
  198121. if (failed (snd_pcm_prepare (handle)))
  198122. return false;
  198123. }
  198124. else if (num != -ESTRPIPE)
  198125. return false;
  198126. }
  198127. AudioDataConverters::convertFormatToFloat (sampleFormat, interleaved, interleaved, numSamples * numChannelsRunning);
  198128. AudioDataConverters::deinterleaveSamples (interleaved, data, numSamples, numChannelsRunning);
  198129. }
  198130. else
  198131. {
  198132. snd_pcm_sframes_t num = snd_pcm_readn (handle, (void**) data, numSamples);
  198133. if (failed (num) && num != -EPIPE && num != -ESTRPIPE)
  198134. return false;
  198135. for (int i = 0; i < numChannelsRunning; ++i)
  198136. if (data[i] != 0)
  198137. AudioDataConverters::convertFormatToFloat (sampleFormat, data[i], data[i], numSamples);
  198138. }
  198139. return true;
  198140. }
  198141. juce_UseDebuggingNewOperator
  198142. snd_pcm_t* handle;
  198143. String error;
  198144. int bitDepth, numChannelsRunning;
  198145. private:
  198146. const bool isInput;
  198147. bool isInterleaved;
  198148. MemoryBlock scratch;
  198149. AudioDataConverters::DataFormat sampleFormat;
  198150. bool failed (const int errorNum)
  198151. {
  198152. if (errorNum >= 0)
  198153. return false;
  198154. error = snd_strerror (errorNum);
  198155. DBG (T("ALSA error: ") + error + T("\n"));
  198156. return true;
  198157. }
  198158. };
  198159. class ALSAThread : public Thread
  198160. {
  198161. public:
  198162. ALSAThread (const String& inputId_,
  198163. const String& outputId_)
  198164. : Thread ("Juce ALSA"),
  198165. sampleRate (0),
  198166. bufferSize (0),
  198167. callback (0),
  198168. inputId (inputId_),
  198169. outputId (outputId_),
  198170. outputDevice (0),
  198171. inputDevice (0),
  198172. numCallbacks (0),
  198173. totalNumInputChannels (0),
  198174. totalNumOutputChannels (0)
  198175. {
  198176. zeromem (outputChannelData, sizeof (outputChannelData));
  198177. zeromem (outputChannelDataForCallback, sizeof (outputChannelDataForCallback));
  198178. zeromem (inputChannelData, sizeof (inputChannelData));
  198179. zeromem (inputChannelDataForCallback, sizeof (inputChannelDataForCallback));
  198180. initialiseRatesAndChannels();
  198181. }
  198182. ~ALSAThread()
  198183. {
  198184. close();
  198185. }
  198186. void open (BigInteger inputChannels,
  198187. BigInteger outputChannels,
  198188. const double sampleRate_,
  198189. const int bufferSize_)
  198190. {
  198191. close();
  198192. error = String::empty;
  198193. sampleRate = sampleRate_;
  198194. bufferSize = bufferSize_;
  198195. currentInputChans.clear();
  198196. currentOutputChans.clear();
  198197. if (inputChannels.getHighestBit() >= 0)
  198198. {
  198199. for (int i = 0; i <= jmax (inputChannels.getHighestBit(), (int) minChansIn); ++i)
  198200. {
  198201. inputChannelData [i] = (float*) juce_calloc (sizeof (float) * bufferSize);
  198202. if (inputChannels[i])
  198203. {
  198204. inputChannelDataForCallback [totalNumInputChannels++] = inputChannelData [i];
  198205. currentInputChans.setBit (i);
  198206. }
  198207. }
  198208. }
  198209. if (outputChannels.getHighestBit() >= 0)
  198210. {
  198211. for (int i = 0; i <= jmax (outputChannels.getHighestBit(), (int) minChansOut); ++i)
  198212. {
  198213. outputChannelData [i] = (float*) juce_calloc (sizeof (float) * bufferSize);
  198214. if (outputChannels[i])
  198215. {
  198216. outputChannelDataForCallback [totalNumOutputChannels++] = outputChannelData [i];
  198217. currentOutputChans.setBit (i);
  198218. }
  198219. }
  198220. }
  198221. if (totalNumOutputChannels > 0 && outputId.isNotEmpty())
  198222. {
  198223. outputDevice = new ALSADevice (outputId, false);
  198224. if (outputDevice->error.isNotEmpty())
  198225. {
  198226. error = outputDevice->error;
  198227. deleteAndZero (outputDevice);
  198228. return;
  198229. }
  198230. currentOutputChans.setRange (0, minChansOut, true);
  198231. if (! outputDevice->setParameters ((unsigned int) sampleRate,
  198232. jlimit ((int) minChansOut, (int) maxChansOut, currentOutputChans.getHighestBit() + 1),
  198233. bufferSize))
  198234. {
  198235. error = outputDevice->error;
  198236. deleteAndZero (outputDevice);
  198237. return;
  198238. }
  198239. }
  198240. if (totalNumInputChannels > 0 && inputId.isNotEmpty())
  198241. {
  198242. inputDevice = new ALSADevice (inputId, true);
  198243. if (inputDevice->error.isNotEmpty())
  198244. {
  198245. error = inputDevice->error;
  198246. deleteAndZero (inputDevice);
  198247. return;
  198248. }
  198249. currentInputChans.setRange (0, minChansIn, true);
  198250. if (! inputDevice->setParameters ((unsigned int) sampleRate,
  198251. jlimit ((int) minChansIn, (int) maxChansIn, currentInputChans.getHighestBit() + 1),
  198252. bufferSize))
  198253. {
  198254. error = inputDevice->error;
  198255. deleteAndZero (inputDevice);
  198256. return;
  198257. }
  198258. }
  198259. if (outputDevice == 0 && inputDevice == 0)
  198260. {
  198261. error = "no channels";
  198262. return;
  198263. }
  198264. if (outputDevice != 0 && inputDevice != 0)
  198265. {
  198266. snd_pcm_link (outputDevice->handle, inputDevice->handle);
  198267. }
  198268. if (inputDevice != 0 && failed (snd_pcm_prepare (inputDevice->handle)))
  198269. return;
  198270. if (outputDevice != 0 && failed (snd_pcm_prepare (outputDevice->handle)))
  198271. return;
  198272. startThread (9);
  198273. int count = 1000;
  198274. while (numCallbacks == 0)
  198275. {
  198276. sleep (5);
  198277. if (--count < 0 || ! isThreadRunning())
  198278. {
  198279. error = "device didn't start";
  198280. break;
  198281. }
  198282. }
  198283. }
  198284. void close()
  198285. {
  198286. stopThread (6000);
  198287. deleteAndZero (inputDevice);
  198288. deleteAndZero (outputDevice);
  198289. for (int i = 0; i < maxNumChans; ++i)
  198290. {
  198291. juce_free (inputChannelData [i]);
  198292. juce_free (outputChannelData [i]);
  198293. }
  198294. zeromem (outputChannelData, sizeof (outputChannelData));
  198295. zeromem (outputChannelDataForCallback, sizeof (outputChannelDataForCallback));
  198296. zeromem (inputChannelData, sizeof (inputChannelData));
  198297. zeromem (inputChannelDataForCallback, sizeof (inputChannelDataForCallback));
  198298. totalNumOutputChannels = 0;
  198299. totalNumInputChannels = 0;
  198300. numCallbacks = 0;
  198301. }
  198302. void setCallback (AudioIODeviceCallback* const newCallback) throw()
  198303. {
  198304. const ScopedLock sl (callbackLock);
  198305. callback = newCallback;
  198306. }
  198307. void run()
  198308. {
  198309. while (! threadShouldExit())
  198310. {
  198311. if (inputDevice != 0)
  198312. {
  198313. if (! inputDevice->read (inputChannelData, bufferSize))
  198314. {
  198315. DBG ("ALSA: read failure");
  198316. break;
  198317. }
  198318. }
  198319. if (threadShouldExit())
  198320. break;
  198321. {
  198322. const ScopedLock sl (callbackLock);
  198323. ++numCallbacks;
  198324. if (callback != 0)
  198325. {
  198326. callback->audioDeviceIOCallback ((const float**) inputChannelDataForCallback,
  198327. totalNumInputChannels,
  198328. outputChannelDataForCallback,
  198329. totalNumOutputChannels,
  198330. bufferSize);
  198331. }
  198332. else
  198333. {
  198334. for (int i = 0; i < totalNumOutputChannels; ++i)
  198335. zeromem (outputChannelDataForCallback[i], sizeof (float) * bufferSize);
  198336. }
  198337. }
  198338. if (outputDevice != 0)
  198339. {
  198340. failed (snd_pcm_wait (outputDevice->handle, 2000));
  198341. if (threadShouldExit())
  198342. break;
  198343. failed (snd_pcm_avail_update (outputDevice->handle));
  198344. if (! outputDevice->write (outputChannelData, bufferSize))
  198345. {
  198346. DBG ("ALSA: write failure");
  198347. break;
  198348. }
  198349. }
  198350. }
  198351. }
  198352. int getBitDepth() const throw()
  198353. {
  198354. if (outputDevice != 0)
  198355. return outputDevice->bitDepth;
  198356. if (inputDevice != 0)
  198357. return inputDevice->bitDepth;
  198358. return 16;
  198359. }
  198360. juce_UseDebuggingNewOperator
  198361. String error;
  198362. double sampleRate;
  198363. int bufferSize;
  198364. BigInteger currentInputChans, currentOutputChans;
  198365. Array <int> sampleRates;
  198366. StringArray channelNamesOut, channelNamesIn;
  198367. AudioIODeviceCallback* callback;
  198368. private:
  198369. const String inputId, outputId;
  198370. ALSADevice* outputDevice;
  198371. ALSADevice* inputDevice;
  198372. int numCallbacks;
  198373. CriticalSection callbackLock;
  198374. float* outputChannelData [maxNumChans];
  198375. float* outputChannelDataForCallback [maxNumChans];
  198376. int totalNumInputChannels;
  198377. float* inputChannelData [maxNumChans];
  198378. float* inputChannelDataForCallback [maxNumChans];
  198379. int totalNumOutputChannels;
  198380. unsigned int minChansOut, maxChansOut;
  198381. unsigned int minChansIn, maxChansIn;
  198382. bool failed (const int errorNum) throw()
  198383. {
  198384. if (errorNum >= 0)
  198385. return false;
  198386. error = snd_strerror (errorNum);
  198387. DBG (T("ALSA error: ") + error + T("\n"));
  198388. return true;
  198389. }
  198390. void initialiseRatesAndChannels() throw()
  198391. {
  198392. sampleRates.clear();
  198393. channelNamesOut.clear();
  198394. channelNamesIn.clear();
  198395. minChansOut = 0;
  198396. maxChansOut = 0;
  198397. minChansIn = 0;
  198398. maxChansIn = 0;
  198399. unsigned int dummy = 0;
  198400. getDeviceProperties (inputId, dummy, dummy, minChansIn, maxChansIn, sampleRates);
  198401. getDeviceProperties (outputId, minChansOut, maxChansOut, dummy, dummy, sampleRates);
  198402. unsigned int i;
  198403. for (i = 0; i < maxChansOut; ++i)
  198404. channelNamesOut.add (T("channel ") + String ((int) i + 1));
  198405. for (i = 0; i < maxChansIn; ++i)
  198406. channelNamesIn.add (T("channel ") + String ((int) i + 1));
  198407. }
  198408. };
  198409. class ALSAAudioIODevice : public AudioIODevice
  198410. {
  198411. public:
  198412. ALSAAudioIODevice (const String& deviceName,
  198413. const String& inputId_,
  198414. const String& outputId_)
  198415. : AudioIODevice (deviceName, T("ALSA")),
  198416. inputId (inputId_),
  198417. outputId (outputId_),
  198418. isOpen_ (false),
  198419. isStarted (false),
  198420. internal (0)
  198421. {
  198422. internal = new ALSAThread (inputId, outputId);
  198423. }
  198424. ~ALSAAudioIODevice()
  198425. {
  198426. delete internal;
  198427. }
  198428. const StringArray getOutputChannelNames()
  198429. {
  198430. return internal->channelNamesOut;
  198431. }
  198432. const StringArray getInputChannelNames()
  198433. {
  198434. return internal->channelNamesIn;
  198435. }
  198436. int getNumSampleRates()
  198437. {
  198438. return internal->sampleRates.size();
  198439. }
  198440. double getSampleRate (int index)
  198441. {
  198442. return internal->sampleRates [index];
  198443. }
  198444. int getNumBufferSizesAvailable()
  198445. {
  198446. return 50;
  198447. }
  198448. int getBufferSizeSamples (int index)
  198449. {
  198450. int n = 16;
  198451. for (int i = 0; i < index; ++i)
  198452. n += n < 64 ? 16
  198453. : (n < 512 ? 32
  198454. : (n < 1024 ? 64
  198455. : (n < 2048 ? 128 : 256)));
  198456. return n;
  198457. }
  198458. int getDefaultBufferSize()
  198459. {
  198460. return 512;
  198461. }
  198462. const String open (const BigInteger& inputChannels,
  198463. const BigInteger& outputChannels,
  198464. double sampleRate,
  198465. int bufferSizeSamples)
  198466. {
  198467. close();
  198468. if (bufferSizeSamples <= 0)
  198469. bufferSizeSamples = getDefaultBufferSize();
  198470. if (sampleRate <= 0)
  198471. {
  198472. for (int i = 0; i < getNumSampleRates(); ++i)
  198473. {
  198474. if (getSampleRate (i) >= 44100)
  198475. {
  198476. sampleRate = getSampleRate (i);
  198477. break;
  198478. }
  198479. }
  198480. }
  198481. internal->open (inputChannels, outputChannels,
  198482. sampleRate, bufferSizeSamples);
  198483. isOpen_ = internal->error.isEmpty();
  198484. return internal->error;
  198485. }
  198486. void close()
  198487. {
  198488. stop();
  198489. internal->close();
  198490. isOpen_ = false;
  198491. }
  198492. bool isOpen()
  198493. {
  198494. return isOpen_;
  198495. }
  198496. int getCurrentBufferSizeSamples()
  198497. {
  198498. return internal->bufferSize;
  198499. }
  198500. double getCurrentSampleRate()
  198501. {
  198502. return internal->sampleRate;
  198503. }
  198504. int getCurrentBitDepth()
  198505. {
  198506. return internal->getBitDepth();
  198507. }
  198508. const BigInteger getActiveOutputChannels() const
  198509. {
  198510. return internal->currentOutputChans;
  198511. }
  198512. const BigInteger getActiveInputChannels() const
  198513. {
  198514. return internal->currentInputChans;
  198515. }
  198516. int getOutputLatencyInSamples()
  198517. {
  198518. return 0;
  198519. }
  198520. int getInputLatencyInSamples()
  198521. {
  198522. return 0;
  198523. }
  198524. void start (AudioIODeviceCallback* callback)
  198525. {
  198526. if (! isOpen_)
  198527. callback = 0;
  198528. internal->setCallback (callback);
  198529. if (callback != 0)
  198530. callback->audioDeviceAboutToStart (this);
  198531. isStarted = (callback != 0);
  198532. }
  198533. void stop()
  198534. {
  198535. AudioIODeviceCallback* const oldCallback = internal->callback;
  198536. start (0);
  198537. if (oldCallback != 0)
  198538. oldCallback->audioDeviceStopped();
  198539. }
  198540. bool isPlaying()
  198541. {
  198542. return isStarted && internal->error.isEmpty();
  198543. }
  198544. const String getLastError()
  198545. {
  198546. return internal->error;
  198547. }
  198548. String inputId, outputId;
  198549. private:
  198550. bool isOpen_, isStarted;
  198551. ALSAThread* internal;
  198552. };
  198553. class ALSAAudioIODeviceType : public AudioIODeviceType
  198554. {
  198555. public:
  198556. ALSAAudioIODeviceType()
  198557. : AudioIODeviceType (T("ALSA")),
  198558. hasScanned (false)
  198559. {
  198560. }
  198561. ~ALSAAudioIODeviceType()
  198562. {
  198563. }
  198564. void scanForDevices()
  198565. {
  198566. if (hasScanned)
  198567. return;
  198568. hasScanned = true;
  198569. inputNames.clear();
  198570. inputIds.clear();
  198571. outputNames.clear();
  198572. outputIds.clear();
  198573. snd_ctl_t* handle;
  198574. snd_ctl_card_info_t* info;
  198575. snd_ctl_card_info_alloca (&info);
  198576. int cardNum = -1;
  198577. while (outputIds.size() + inputIds.size() <= 32)
  198578. {
  198579. snd_card_next (&cardNum);
  198580. if (cardNum < 0)
  198581. break;
  198582. if (snd_ctl_open (&handle, ("hw:" + String (cardNum)).toUTF8(), SND_CTL_NONBLOCK) >= 0)
  198583. {
  198584. if (snd_ctl_card_info (handle, info) >= 0)
  198585. {
  198586. String cardId (snd_ctl_card_info_get_id (info));
  198587. if (cardId.removeCharacters (T("0123456789")).isEmpty())
  198588. cardId = String (cardNum);
  198589. int device = -1;
  198590. for (;;)
  198591. {
  198592. if (snd_ctl_pcm_next_device (handle, &device) < 0 || device < 0)
  198593. break;
  198594. String id, name;
  198595. id << "hw:" << cardId << ',' << device;
  198596. bool isInput, isOutput;
  198597. if (testDevice (id, isInput, isOutput))
  198598. {
  198599. name << snd_ctl_card_info_get_name (info);
  198600. if (name.isEmpty())
  198601. name = id;
  198602. if (isInput)
  198603. {
  198604. inputNames.add (name);
  198605. inputIds.add (id);
  198606. }
  198607. if (isOutput)
  198608. {
  198609. outputNames.add (name);
  198610. outputIds.add (id);
  198611. }
  198612. }
  198613. }
  198614. }
  198615. snd_ctl_close (handle);
  198616. }
  198617. }
  198618. inputNames.appendNumbersToDuplicates (false, true);
  198619. outputNames.appendNumbersToDuplicates (false, true);
  198620. }
  198621. const StringArray getDeviceNames (const bool wantInputNames) const
  198622. {
  198623. jassert (hasScanned); // need to call scanForDevices() before doing this
  198624. return wantInputNames ? inputNames : outputNames;
  198625. }
  198626. int getDefaultDeviceIndex (const bool forInput) const
  198627. {
  198628. jassert (hasScanned); // need to call scanForDevices() before doing this
  198629. return 0;
  198630. }
  198631. bool hasSeparateInputsAndOutputs() const { return true; }
  198632. int getIndexOfDevice (AudioIODevice* device, const bool asInput) const
  198633. {
  198634. jassert (hasScanned); // need to call scanForDevices() before doing this
  198635. ALSAAudioIODevice* const d = dynamic_cast <ALSAAudioIODevice*> (device);
  198636. if (d == 0)
  198637. return -1;
  198638. return asInput ? inputIds.indexOf (d->inputId)
  198639. : outputIds.indexOf (d->outputId);
  198640. }
  198641. AudioIODevice* createDevice (const String& outputDeviceName,
  198642. const String& inputDeviceName)
  198643. {
  198644. jassert (hasScanned); // need to call scanForDevices() before doing this
  198645. const int inputIndex = inputNames.indexOf (inputDeviceName);
  198646. const int outputIndex = outputNames.indexOf (outputDeviceName);
  198647. String deviceName (outputIndex >= 0 ? outputDeviceName
  198648. : inputDeviceName);
  198649. if (inputIndex >= 0 || outputIndex >= 0)
  198650. return new ALSAAudioIODevice (deviceName,
  198651. inputIds [inputIndex],
  198652. outputIds [outputIndex]);
  198653. return 0;
  198654. }
  198655. juce_UseDebuggingNewOperator
  198656. private:
  198657. StringArray inputNames, outputNames, inputIds, outputIds;
  198658. bool hasScanned;
  198659. static bool testDevice (const String& id, bool& isInput, bool& isOutput)
  198660. {
  198661. unsigned int minChansOut = 0, maxChansOut = 0;
  198662. unsigned int minChansIn = 0, maxChansIn = 0;
  198663. Array <int> rates;
  198664. getDeviceProperties (id, minChansOut, maxChansOut, minChansIn, maxChansIn, rates);
  198665. DBG (T("ALSA device: ") + id
  198666. + T(" outs=") + String ((int) minChansOut) + T("-") + String ((int) maxChansOut)
  198667. + T(" ins=") + String ((int) minChansIn) + T("-") + String ((int) maxChansIn)
  198668. + T(" rates=") + String (rates.size()));
  198669. isInput = maxChansIn > 0;
  198670. isOutput = maxChansOut > 0;
  198671. return (isInput || isOutput) && rates.size() > 0;
  198672. }
  198673. ALSAAudioIODeviceType (const ALSAAudioIODeviceType&);
  198674. ALSAAudioIODeviceType& operator= (const ALSAAudioIODeviceType&);
  198675. };
  198676. AudioIODeviceType* juce_createAudioIODeviceType_ALSA()
  198677. {
  198678. return new ALSAAudioIODeviceType();
  198679. }
  198680. #endif
  198681. /*** End of inlined file: juce_linux_Audio.cpp ***/
  198682. /*** Start of inlined file: juce_linux_JackAudio.cpp ***/
  198683. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  198684. // compiled on its own).
  198685. #ifdef JUCE_INCLUDED_FILE
  198686. #if JUCE_JACK
  198687. static void* juce_libjack_handle = 0;
  198688. void* juce_load_jack_function (const char* const name)
  198689. {
  198690. if (juce_libjack_handle == 0)
  198691. return 0;
  198692. return dlsym (juce_libjack_handle, name);
  198693. }
  198694. #define JUCE_DECL_JACK_FUNCTION(return_type, fn_name, argument_types, arguments) \
  198695. typedef return_type (*fn_name##_ptr_t)argument_types; \
  198696. return_type fn_name argument_types { \
  198697. static fn_name##_ptr_t fn = 0; \
  198698. if (fn == 0) { fn = (fn_name##_ptr_t)juce_load_jack_function(#fn_name); } \
  198699. if (fn) return (*fn)arguments; \
  198700. else return 0; \
  198701. }
  198702. #define JUCE_DECL_VOID_JACK_FUNCTION(fn_name, argument_types, arguments) \
  198703. typedef void (*fn_name##_ptr_t)argument_types; \
  198704. void fn_name argument_types { \
  198705. static fn_name##_ptr_t fn = 0; \
  198706. if (fn == 0) { fn = (fn_name##_ptr_t)juce_load_jack_function(#fn_name); } \
  198707. if (fn) (*fn)arguments; \
  198708. }
  198709. 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));
  198710. JUCE_DECL_JACK_FUNCTION (int, jack_client_close, (jack_client_t *client), (client));
  198711. JUCE_DECL_JACK_FUNCTION (int, jack_activate, (jack_client_t* client), (client));
  198712. JUCE_DECL_JACK_FUNCTION (int, jack_deactivate, (jack_client_t* client), (client));
  198713. JUCE_DECL_JACK_FUNCTION (jack_nframes_t, jack_get_buffer_size, (jack_client_t* client), (client));
  198714. JUCE_DECL_JACK_FUNCTION (jack_nframes_t, jack_get_sample_rate, (jack_client_t* client), (client));
  198715. JUCE_DECL_VOID_JACK_FUNCTION (jack_on_shutdown, (jack_client_t* client, void (*function)(void* arg), void* arg), (client, function, arg));
  198716. JUCE_DECL_JACK_FUNCTION (void* , jack_port_get_buffer, (jack_port_t* port, jack_nframes_t nframes), (port, nframes));
  198717. JUCE_DECL_JACK_FUNCTION (jack_nframes_t, jack_port_get_total_latency, (jack_client_t* client, jack_port_t* port), (client, port));
  198718. 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));
  198719. JUCE_DECL_VOID_JACK_FUNCTION (jack_set_error_function, (void (*func)(const char*)), (func));
  198720. JUCE_DECL_JACK_FUNCTION (int, jack_set_process_callback, (jack_client_t* client, JackProcessCallback process_callback, void* arg), (client, process_callback, arg));
  198721. 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));
  198722. JUCE_DECL_JACK_FUNCTION (int, jack_connect, (jack_client_t* client, const char* source_port, const char* destination_port), (client, source_port, destination_port));
  198723. JUCE_DECL_JACK_FUNCTION (const char*, jack_port_name, (const jack_port_t* port), (port));
  198724. JUCE_DECL_JACK_FUNCTION (int, jack_set_port_connect_callback, (jack_client_t* client, JackPortConnectCallback connect_callback, void* arg), (client, connect_callback, arg));
  198725. JUCE_DECL_JACK_FUNCTION (jack_port_t* , jack_port_by_id, (jack_client_t* client, jack_port_id_t port_id), (client, port_id));
  198726. JUCE_DECL_JACK_FUNCTION (int, jack_port_connected, (const jack_port_t* port), (port));
  198727. JUCE_DECL_JACK_FUNCTION (int, jack_port_connected_to, (const jack_port_t* port, const char* port_name), (port, port_name));
  198728. #if JUCE_DEBUG
  198729. #define JACK_LOGGING_ENABLED 1
  198730. #endif
  198731. #if JACK_LOGGING_ENABLED
  198732. static void jack_Log (const String& s)
  198733. {
  198734. std::cerr << s << std::endl;
  198735. }
  198736. static void dumpJackErrorMessage (const jack_status_t status) throw()
  198737. {
  198738. if (status & JackServerFailed || status & JackServerError)
  198739. jack_Log ("Unable to connect to JACK server");
  198740. if (status & JackVersionError)
  198741. jack_Log ("Client's protocol version does not match");
  198742. if (status & JackInvalidOption)
  198743. jack_Log ("The operation contained an invalid or unsupported option");
  198744. if (status & JackNameNotUnique)
  198745. jack_Log ("The desired client name was not unique");
  198746. if (status & JackNoSuchClient)
  198747. jack_Log ("Requested client does not exist");
  198748. if (status & JackInitFailure)
  198749. jack_Log ("Unable to initialize client");
  198750. }
  198751. #else
  198752. #define dumpJackErrorMessage(a) {}
  198753. #define jack_Log(...) {}
  198754. #endif
  198755. #ifndef JUCE_JACK_CLIENT_NAME
  198756. #define JUCE_JACK_CLIENT_NAME "JuceJack"
  198757. #endif
  198758. class JackAudioIODevice : public AudioIODevice
  198759. {
  198760. public:
  198761. JackAudioIODevice (const String& deviceName,
  198762. const String& inputId_,
  198763. const String& outputId_)
  198764. : AudioIODevice (deviceName, T("JACK")),
  198765. inputId (inputId_),
  198766. outputId (outputId_),
  198767. isOpen_ (false),
  198768. callback (0),
  198769. totalNumberOfInputChannels (0),
  198770. totalNumberOfOutputChannels (0)
  198771. {
  198772. jassert (deviceName.isNotEmpty());
  198773. jack_status_t status;
  198774. client = JUCE_NAMESPACE::jack_client_open (JUCE_JACK_CLIENT_NAME, JackNoStartServer, &status);
  198775. if (client == 0)
  198776. {
  198777. dumpJackErrorMessage (status);
  198778. }
  198779. else
  198780. {
  198781. JUCE_NAMESPACE::jack_set_error_function (errorCallback);
  198782. // open input ports
  198783. const StringArray inputChannels (getInputChannelNames());
  198784. for (int i = 0; i < inputChannels.size(); i++)
  198785. {
  198786. String inputName;
  198787. inputName << "in_" << ++totalNumberOfInputChannels;
  198788. inputPorts.add (JUCE_NAMESPACE::jack_port_register (client, inputName.toUTF8(),
  198789. JACK_DEFAULT_AUDIO_TYPE, JackPortIsInput, 0));
  198790. }
  198791. // open output ports
  198792. const StringArray outputChannels (getOutputChannelNames());
  198793. for (int i = 0; i < outputChannels.size (); i++)
  198794. {
  198795. String outputName;
  198796. outputName << "out_" << ++totalNumberOfOutputChannels;
  198797. outputPorts.add (JUCE_NAMESPACE::jack_port_register (client, outputName.toUTF8(),
  198798. JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput, 0));
  198799. }
  198800. inChans.calloc (totalNumberOfInputChannels + 2);
  198801. outChans.calloc (totalNumberOfOutputChannels + 2);
  198802. }
  198803. }
  198804. ~JackAudioIODevice()
  198805. {
  198806. close();
  198807. if (client != 0)
  198808. {
  198809. JUCE_NAMESPACE::jack_client_close (client);
  198810. client = 0;
  198811. }
  198812. }
  198813. const StringArray getChannelNames (bool forInput) const
  198814. {
  198815. StringArray names;
  198816. const char** const ports = JUCE_NAMESPACE::jack_get_ports (client, 0, 0, /* JackPortIsPhysical | */
  198817. forInput ? JackPortIsInput : JackPortIsOutput);
  198818. if (ports != 0)
  198819. {
  198820. int j = 0;
  198821. while (ports[j] != 0)
  198822. {
  198823. const String portName (ports [j++]);
  198824. if (portName.upToFirstOccurrenceOf (T(":"), false, false) == getName())
  198825. names.add (portName.fromFirstOccurrenceOf (T(":"), false, false));
  198826. }
  198827. free (ports);
  198828. }
  198829. return names;
  198830. }
  198831. const StringArray getOutputChannelNames() { return getChannelNames (false); }
  198832. const StringArray getInputChannelNames() { return getChannelNames (true); }
  198833. int getNumSampleRates() { return client != 0 ? 1 : 0; }
  198834. double getSampleRate (int index) { return client != 0 ? JUCE_NAMESPACE::jack_get_sample_rate (client) : 0; }
  198835. int getNumBufferSizesAvailable() { return client != 0 ? 1 : 0; }
  198836. int getBufferSizeSamples (int index) { return getDefaultBufferSize(); }
  198837. int getDefaultBufferSize() { return client != 0 ? JUCE_NAMESPACE::jack_get_buffer_size (client) : 0; }
  198838. const String open (const BigInteger& inputChannels, const BigInteger& outputChannels,
  198839. double sampleRate, int bufferSizeSamples)
  198840. {
  198841. if (client == 0)
  198842. {
  198843. lastError = T("No JACK client running");
  198844. return lastError;
  198845. }
  198846. lastError = String::empty;
  198847. close();
  198848. JUCE_NAMESPACE::jack_set_process_callback (client, processCallback, this);
  198849. JUCE_NAMESPACE::jack_on_shutdown (client, shutdownCallback, this);
  198850. JUCE_NAMESPACE::jack_activate (client);
  198851. isOpen_ = true;
  198852. if (! inputChannels.isZero())
  198853. {
  198854. const char** const ports = JUCE_NAMESPACE::jack_get_ports (client, 0, 0, /* JackPortIsPhysical | */ JackPortIsOutput);
  198855. if (ports != 0)
  198856. {
  198857. const int numInputChannels = inputChannels.getHighestBit() + 1;
  198858. for (int i = 0; i < numInputChannels; ++i)
  198859. {
  198860. const String portName (ports[i]);
  198861. if (inputChannels[i] && portName.upToFirstOccurrenceOf (T(":"), false, false) == getName())
  198862. {
  198863. int error = JUCE_NAMESPACE::jack_connect (client, ports[i], JUCE_NAMESPACE::jack_port_name ((jack_port_t*) inputPorts[i]));
  198864. if (error != 0)
  198865. jack_Log ("Cannot connect input port " + String (i) + " (" + String (ports[i]) + "), error " + String (error));
  198866. }
  198867. }
  198868. free (ports);
  198869. }
  198870. }
  198871. if (! outputChannels.isZero())
  198872. {
  198873. const char** const ports = JUCE_NAMESPACE::jack_get_ports (client, 0, 0, /* JackPortIsPhysical | */ JackPortIsInput);
  198874. if (ports != 0)
  198875. {
  198876. const int numOutputChannels = outputChannels.getHighestBit() + 1;
  198877. for (int i = 0; i < numOutputChannels; ++i)
  198878. {
  198879. const String portName (ports[i]);
  198880. if (outputChannels[i] && portName.upToFirstOccurrenceOf (T(":"), false, false) == getName())
  198881. {
  198882. int error = JUCE_NAMESPACE::jack_connect (client, JUCE_NAMESPACE::jack_port_name ((jack_port_t*) outputPorts[i]), ports[i]);
  198883. if (error != 0)
  198884. jack_Log ("Cannot connect output port " + String (i) + " (" + String (ports[i]) + "), error " + String (error));
  198885. }
  198886. }
  198887. free (ports);
  198888. }
  198889. }
  198890. return lastError;
  198891. }
  198892. void close()
  198893. {
  198894. stop();
  198895. if (client != 0)
  198896. {
  198897. JUCE_NAMESPACE::jack_deactivate (client);
  198898. JUCE_NAMESPACE::jack_set_process_callback (client, processCallback, 0);
  198899. JUCE_NAMESPACE::jack_on_shutdown (client, shutdownCallback, 0);
  198900. }
  198901. isOpen_ = false;
  198902. }
  198903. void start (AudioIODeviceCallback* newCallback)
  198904. {
  198905. if (isOpen_ && newCallback != callback)
  198906. {
  198907. if (newCallback != 0)
  198908. newCallback->audioDeviceAboutToStart (this);
  198909. AudioIODeviceCallback* const oldCallback = callback;
  198910. {
  198911. const ScopedLock sl (callbackLock);
  198912. callback = newCallback;
  198913. }
  198914. if (oldCallback != 0)
  198915. oldCallback->audioDeviceStopped();
  198916. }
  198917. }
  198918. void stop()
  198919. {
  198920. start (0);
  198921. }
  198922. bool isOpen() { return isOpen_; }
  198923. bool isPlaying() { return callback != 0; }
  198924. int getCurrentBufferSizeSamples() { return getBufferSizeSamples (0); }
  198925. double getCurrentSampleRate() { return getSampleRate (0); }
  198926. int getCurrentBitDepth() { return 32; }
  198927. const String getLastError() { return lastError; }
  198928. const BigInteger getActiveOutputChannels() const
  198929. {
  198930. BigInteger outputBits;
  198931. for (int i = 0; i < outputPorts.size(); i++)
  198932. if (JUCE_NAMESPACE::jack_port_connected ((jack_port_t*) outputPorts [i]))
  198933. outputBits.setBit (i);
  198934. return outputBits;
  198935. }
  198936. const BigInteger getActiveInputChannels() const
  198937. {
  198938. BigInteger inputBits;
  198939. for (int i = 0; i < inputPorts.size(); i++)
  198940. if (JUCE_NAMESPACE::jack_port_connected ((jack_port_t*) inputPorts [i]))
  198941. inputBits.setBit (i);
  198942. return inputBits;
  198943. }
  198944. int getOutputLatencyInSamples()
  198945. {
  198946. int latency = 0;
  198947. for (int i = 0; i < outputPorts.size(); i++)
  198948. latency = jmax (latency, (int) JUCE_NAMESPACE::jack_port_get_total_latency (client, (jack_port_t*) outputPorts [i]));
  198949. return latency;
  198950. }
  198951. int getInputLatencyInSamples()
  198952. {
  198953. int latency = 0;
  198954. for (int i = 0; i < inputPorts.size(); i++)
  198955. latency = jmax (latency, (int) JUCE_NAMESPACE::jack_port_get_total_latency (client, (jack_port_t*) inputPorts [i]));
  198956. return latency;
  198957. }
  198958. String inputId, outputId;
  198959. private:
  198960. void process (const int numSamples)
  198961. {
  198962. int i, numActiveInChans = 0, numActiveOutChans = 0;
  198963. for (i = 0; i < totalNumberOfInputChannels; ++i)
  198964. {
  198965. jack_default_audio_sample_t* in
  198966. = (jack_default_audio_sample_t*) JUCE_NAMESPACE::jack_port_get_buffer ((jack_port_t*) inputPorts.getUnchecked(i), numSamples);
  198967. if (in != 0)
  198968. inChans [numActiveInChans++] = (float*) in;
  198969. }
  198970. for (i = 0; i < totalNumberOfOutputChannels; ++i)
  198971. {
  198972. jack_default_audio_sample_t* out
  198973. = (jack_default_audio_sample_t*) JUCE_NAMESPACE::jack_port_get_buffer ((jack_port_t*) outputPorts.getUnchecked(i), numSamples);
  198974. if (out != 0)
  198975. outChans [numActiveOutChans++] = (float*) out;
  198976. }
  198977. const ScopedLock sl (callbackLock);
  198978. if (callback != 0)
  198979. {
  198980. callback->audioDeviceIOCallback (const_cast<const float**> (inChans.getData()), numActiveInChans,
  198981. outChans, numActiveOutChans, numSamples);
  198982. }
  198983. else
  198984. {
  198985. for (i = 0; i < numActiveOutChans; ++i)
  198986. zeromem (outChans[i], sizeof (float) * numSamples);
  198987. }
  198988. }
  198989. static int processCallback (jack_nframes_t nframes, void* callbackArgument)
  198990. {
  198991. if (callbackArgument != 0)
  198992. ((JackAudioIODevice*) callbackArgument)->process (nframes);
  198993. return 0;
  198994. }
  198995. static void threadInitCallback (void* callbackArgument)
  198996. {
  198997. jack_Log ("JackAudioIODevice::initialise");
  198998. }
  198999. static void shutdownCallback (void* callbackArgument)
  199000. {
  199001. jack_Log ("JackAudioIODevice::shutdown");
  199002. JackAudioIODevice* device = (JackAudioIODevice*) callbackArgument;
  199003. if (device != 0)
  199004. {
  199005. device->client = 0;
  199006. device->close();
  199007. }
  199008. }
  199009. static void errorCallback (const char* msg)
  199010. {
  199011. jack_Log ("JackAudioIODevice::errorCallback " + String (msg));
  199012. }
  199013. bool isOpen_;
  199014. jack_client_t* client;
  199015. String lastError;
  199016. AudioIODeviceCallback* callback;
  199017. CriticalSection callbackLock;
  199018. HeapBlock <float*> inChans, outChans;
  199019. int totalNumberOfInputChannels;
  199020. int totalNumberOfOutputChannels;
  199021. VoidArray inputPorts, outputPorts;
  199022. };
  199023. class JackAudioIODeviceType : public AudioIODeviceType
  199024. {
  199025. public:
  199026. JackAudioIODeviceType()
  199027. : AudioIODeviceType (T("JACK")),
  199028. hasScanned (false)
  199029. {
  199030. }
  199031. ~JackAudioIODeviceType()
  199032. {
  199033. }
  199034. void scanForDevices()
  199035. {
  199036. hasScanned = true;
  199037. inputNames.clear();
  199038. inputIds.clear();
  199039. outputNames.clear();
  199040. outputIds.clear();
  199041. if (juce_libjack_handle == 0)
  199042. {
  199043. juce_libjack_handle = dlopen ("libjack.so", RTLD_LAZY);
  199044. if (juce_libjack_handle == 0)
  199045. return;
  199046. }
  199047. // open a dummy client
  199048. jack_status_t status;
  199049. jack_client_t* client = JUCE_NAMESPACE::jack_client_open ("JuceJackDummy", JackNoStartServer, &status);
  199050. if (client == 0)
  199051. {
  199052. dumpJackErrorMessage (status);
  199053. }
  199054. else
  199055. {
  199056. // scan for output devices
  199057. const char** ports = JUCE_NAMESPACE::jack_get_ports (client, 0, 0, /* JackPortIsPhysical | */ JackPortIsOutput);
  199058. if (ports != 0)
  199059. {
  199060. int j = 0;
  199061. while (ports[j] != 0)
  199062. {
  199063. String clientName (ports[j]);
  199064. clientName = clientName.upToFirstOccurrenceOf (T(":"), false, false);
  199065. if (clientName != String (JUCE_JACK_CLIENT_NAME)
  199066. && ! inputNames.contains (clientName))
  199067. {
  199068. inputNames.add (clientName);
  199069. inputIds.add (ports [j]);
  199070. }
  199071. ++j;
  199072. }
  199073. free (ports);
  199074. }
  199075. // scan for input devices
  199076. ports = JUCE_NAMESPACE::jack_get_ports (client, 0, 0, /* JackPortIsPhysical | */ JackPortIsInput);
  199077. if (ports != 0)
  199078. {
  199079. int j = 0;
  199080. while (ports[j] != 0)
  199081. {
  199082. String clientName (ports[j]);
  199083. clientName = clientName.upToFirstOccurrenceOf (T(":"), false, false);
  199084. if (clientName != String (JUCE_JACK_CLIENT_NAME)
  199085. && ! outputNames.contains (clientName))
  199086. {
  199087. outputNames.add (clientName);
  199088. outputIds.add (ports [j]);
  199089. }
  199090. ++j;
  199091. }
  199092. free (ports);
  199093. }
  199094. JUCE_NAMESPACE::jack_client_close (client);
  199095. }
  199096. }
  199097. const StringArray getDeviceNames (const bool wantInputNames) const
  199098. {
  199099. jassert (hasScanned); // need to call scanForDevices() before doing this
  199100. return wantInputNames ? inputNames : outputNames;
  199101. }
  199102. int getDefaultDeviceIndex (const bool forInput) const
  199103. {
  199104. jassert (hasScanned); // need to call scanForDevices() before doing this
  199105. return 0;
  199106. }
  199107. bool hasSeparateInputsAndOutputs() const { return true; }
  199108. int getIndexOfDevice (AudioIODevice* device, const bool asInput) const
  199109. {
  199110. jassert (hasScanned); // need to call scanForDevices() before doing this
  199111. JackAudioIODevice* const d = dynamic_cast <JackAudioIODevice*> (device);
  199112. if (d == 0)
  199113. return -1;
  199114. return asInput ? inputIds.indexOf (d->inputId)
  199115. : outputIds.indexOf (d->outputId);
  199116. }
  199117. AudioIODevice* createDevice (const String& outputDeviceName,
  199118. const String& inputDeviceName)
  199119. {
  199120. jassert (hasScanned); // need to call scanForDevices() before doing this
  199121. const int inputIndex = inputNames.indexOf (inputDeviceName);
  199122. const int outputIndex = outputNames.indexOf (outputDeviceName);
  199123. if (inputIndex >= 0 || outputIndex >= 0)
  199124. return new JackAudioIODevice (outputIndex >= 0 ? outputDeviceName
  199125. : inputDeviceName,
  199126. inputIds [inputIndex],
  199127. outputIds [outputIndex]);
  199128. return 0;
  199129. }
  199130. juce_UseDebuggingNewOperator
  199131. private:
  199132. StringArray inputNames, outputNames, inputIds, outputIds;
  199133. bool hasScanned;
  199134. JackAudioIODeviceType (const JackAudioIODeviceType&);
  199135. JackAudioIODeviceType& operator= (const JackAudioIODeviceType&);
  199136. };
  199137. AudioIODeviceType* juce_createAudioIODeviceType_JACK()
  199138. {
  199139. return new JackAudioIODeviceType();
  199140. }
  199141. #else // if JACK is turned off..
  199142. AudioIODeviceType* juce_createAudioIODeviceType_JACK() { return 0; }
  199143. #endif
  199144. #endif
  199145. /*** End of inlined file: juce_linux_JackAudio.cpp ***/
  199146. /*** Start of inlined file: juce_linux_Midi.cpp ***/
  199147. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  199148. // compiled on its own).
  199149. #if JUCE_INCLUDED_FILE
  199150. #if JUCE_ALSA
  199151. static snd_seq_t* iterateDevices (const bool forInput,
  199152. StringArray& deviceNamesFound,
  199153. const int deviceIndexToOpen)
  199154. {
  199155. snd_seq_t* returnedHandle = 0;
  199156. snd_seq_t* seqHandle;
  199157. if (snd_seq_open (&seqHandle, "default", forInput ? SND_SEQ_OPEN_INPUT
  199158. : SND_SEQ_OPEN_OUTPUT, 0) == 0)
  199159. {
  199160. snd_seq_system_info_t* systemInfo;
  199161. snd_seq_client_info_t* clientInfo;
  199162. if (snd_seq_system_info_malloc (&systemInfo) == 0)
  199163. {
  199164. if (snd_seq_system_info (seqHandle, systemInfo) == 0
  199165. && snd_seq_client_info_malloc (&clientInfo) == 0)
  199166. {
  199167. int numClients = snd_seq_system_info_get_cur_clients (systemInfo);
  199168. while (--numClients >= 0 && returnedHandle == 0)
  199169. {
  199170. if (snd_seq_query_next_client (seqHandle, clientInfo) == 0)
  199171. {
  199172. snd_seq_port_info_t* portInfo;
  199173. if (snd_seq_port_info_malloc (&portInfo) == 0)
  199174. {
  199175. int numPorts = snd_seq_client_info_get_num_ports (clientInfo);
  199176. const int client = snd_seq_client_info_get_client (clientInfo);
  199177. snd_seq_port_info_set_client (portInfo, client);
  199178. snd_seq_port_info_set_port (portInfo, -1);
  199179. while (--numPorts >= 0)
  199180. {
  199181. if (snd_seq_query_next_port (seqHandle, portInfo) == 0
  199182. && (snd_seq_port_info_get_capability (portInfo)
  199183. & (forInput ? SND_SEQ_PORT_CAP_READ
  199184. : SND_SEQ_PORT_CAP_WRITE)) != 0)
  199185. {
  199186. deviceNamesFound.add (snd_seq_client_info_get_name (clientInfo));
  199187. if (deviceNamesFound.size() == deviceIndexToOpen + 1)
  199188. {
  199189. const int sourcePort = snd_seq_port_info_get_port (portInfo);
  199190. const int sourceClient = snd_seq_client_info_get_client (clientInfo);
  199191. if (sourcePort != -1)
  199192. {
  199193. snd_seq_set_client_name (seqHandle,
  199194. forInput ? "Juce Midi Input"
  199195. : "Juce Midi Output");
  199196. const int portId
  199197. = snd_seq_create_simple_port (seqHandle,
  199198. forInput ? "Juce Midi In Port"
  199199. : "Juce Midi Out Port",
  199200. forInput ? (SND_SEQ_PORT_CAP_WRITE | SND_SEQ_PORT_CAP_SUBS_WRITE)
  199201. : (SND_SEQ_PORT_CAP_READ | SND_SEQ_PORT_CAP_SUBS_READ),
  199202. SND_SEQ_PORT_TYPE_MIDI_GENERIC);
  199203. snd_seq_connect_from (seqHandle, portId, sourceClient, sourcePort);
  199204. returnedHandle = seqHandle;
  199205. }
  199206. }
  199207. }
  199208. }
  199209. snd_seq_port_info_free (portInfo);
  199210. }
  199211. }
  199212. }
  199213. snd_seq_client_info_free (clientInfo);
  199214. }
  199215. snd_seq_system_info_free (systemInfo);
  199216. }
  199217. if (returnedHandle == 0)
  199218. snd_seq_close (seqHandle);
  199219. }
  199220. deviceNamesFound.appendNumbersToDuplicates (true, true);
  199221. return returnedHandle;
  199222. }
  199223. static snd_seq_t* createDevice (const bool forInput,
  199224. const String& deviceNameToOpen)
  199225. {
  199226. snd_seq_t* seqHandle = 0;
  199227. if (snd_seq_open (&seqHandle, "default", forInput ? SND_SEQ_OPEN_INPUT
  199228. : SND_SEQ_OPEN_OUTPUT, 0) == 0)
  199229. {
  199230. snd_seq_set_client_name (seqHandle,
  199231. (deviceNameToOpen + (forInput ? " Input" : " Output")).toCString());
  199232. const int portId
  199233. = snd_seq_create_simple_port (seqHandle,
  199234. forInput ? "in"
  199235. : "out",
  199236. forInput ? (SND_SEQ_PORT_CAP_WRITE | SND_SEQ_PORT_CAP_SUBS_WRITE)
  199237. : (SND_SEQ_PORT_CAP_READ | SND_SEQ_PORT_CAP_SUBS_READ),
  199238. forInput ? SND_SEQ_PORT_TYPE_APPLICATION
  199239. : SND_SEQ_PORT_TYPE_MIDI_GENERIC);
  199240. if (portId < 0)
  199241. {
  199242. snd_seq_close (seqHandle);
  199243. seqHandle = 0;
  199244. }
  199245. }
  199246. return seqHandle;
  199247. }
  199248. class MidiOutputDevice
  199249. {
  199250. public:
  199251. MidiOutputDevice (MidiOutput* const midiOutput_,
  199252. snd_seq_t* const seqHandle_)
  199253. :
  199254. midiOutput (midiOutput_),
  199255. seqHandle (seqHandle_),
  199256. maxEventSize (16 * 1024)
  199257. {
  199258. jassert (seqHandle != 0 && midiOutput != 0);
  199259. snd_midi_event_new (maxEventSize, &midiParser);
  199260. }
  199261. ~MidiOutputDevice()
  199262. {
  199263. snd_midi_event_free (midiParser);
  199264. snd_seq_close (seqHandle);
  199265. }
  199266. void sendMessageNow (const MidiMessage& message)
  199267. {
  199268. if (message.getRawDataSize() > maxEventSize)
  199269. {
  199270. maxEventSize = message.getRawDataSize();
  199271. snd_midi_event_free (midiParser);
  199272. snd_midi_event_new (maxEventSize, &midiParser);
  199273. }
  199274. snd_seq_event_t event;
  199275. snd_seq_ev_clear (&event);
  199276. snd_midi_event_encode (midiParser,
  199277. message.getRawData(),
  199278. message.getRawDataSize(),
  199279. &event);
  199280. snd_midi_event_reset_encode (midiParser);
  199281. snd_seq_ev_set_source (&event, 0);
  199282. snd_seq_ev_set_subs (&event);
  199283. snd_seq_ev_set_direct (&event);
  199284. snd_seq_event_output (seqHandle, &event);
  199285. snd_seq_drain_output (seqHandle);
  199286. }
  199287. juce_UseDebuggingNewOperator
  199288. private:
  199289. MidiOutput* const midiOutput;
  199290. snd_seq_t* const seqHandle;
  199291. snd_midi_event_t* midiParser;
  199292. int maxEventSize;
  199293. };
  199294. const StringArray MidiOutput::getDevices()
  199295. {
  199296. StringArray devices;
  199297. iterateDevices (false, devices, -1);
  199298. return devices;
  199299. }
  199300. int MidiOutput::getDefaultDeviceIndex()
  199301. {
  199302. return 0;
  199303. }
  199304. MidiOutput* MidiOutput::openDevice (int deviceIndex)
  199305. {
  199306. MidiOutput* newDevice = 0;
  199307. StringArray devices;
  199308. snd_seq_t* const handle = iterateDevices (false, devices, deviceIndex);
  199309. if (handle != 0)
  199310. {
  199311. newDevice = new MidiOutput();
  199312. newDevice->internal = new MidiOutputDevice (newDevice, handle);
  199313. }
  199314. return newDevice;
  199315. }
  199316. MidiOutput* MidiOutput::createNewDevice (const String& deviceName)
  199317. {
  199318. MidiOutput* newDevice = 0;
  199319. snd_seq_t* const handle = createDevice (false, deviceName);
  199320. if (handle != 0)
  199321. {
  199322. newDevice = new MidiOutput();
  199323. newDevice->internal = new MidiOutputDevice (newDevice, handle);
  199324. }
  199325. return newDevice;
  199326. }
  199327. MidiOutput::~MidiOutput()
  199328. {
  199329. MidiOutputDevice* const device = (MidiOutputDevice*) internal;
  199330. delete device;
  199331. }
  199332. void MidiOutput::reset()
  199333. {
  199334. }
  199335. bool MidiOutput::getVolume (float& leftVol, float& rightVol)
  199336. {
  199337. return false;
  199338. }
  199339. void MidiOutput::setVolume (float leftVol, float rightVol)
  199340. {
  199341. }
  199342. void MidiOutput::sendMessageNow (const MidiMessage& message)
  199343. {
  199344. ((MidiOutputDevice*) internal)->sendMessageNow (message);
  199345. }
  199346. class MidiInputThread : public Thread
  199347. {
  199348. public:
  199349. MidiInputThread (MidiInput* const midiInput_,
  199350. snd_seq_t* const seqHandle_,
  199351. MidiInputCallback* const callback_)
  199352. : Thread (T("Juce MIDI Input")),
  199353. midiInput (midiInput_),
  199354. seqHandle (seqHandle_),
  199355. callback (callback_)
  199356. {
  199357. jassert (seqHandle != 0 && callback != 0 && midiInput != 0);
  199358. }
  199359. ~MidiInputThread()
  199360. {
  199361. snd_seq_close (seqHandle);
  199362. }
  199363. void run()
  199364. {
  199365. const int maxEventSize = 16 * 1024;
  199366. snd_midi_event_t* midiParser;
  199367. if (snd_midi_event_new (maxEventSize, &midiParser) >= 0)
  199368. {
  199369. HeapBlock <uint8> buffer (maxEventSize);
  199370. const int numPfds = snd_seq_poll_descriptors_count (seqHandle, POLLIN);
  199371. struct pollfd* const pfd = (struct pollfd*) alloca (numPfds * sizeof (struct pollfd));
  199372. snd_seq_poll_descriptors (seqHandle, pfd, numPfds, POLLIN);
  199373. while (! threadShouldExit())
  199374. {
  199375. if (poll (pfd, numPfds, 500) > 0)
  199376. {
  199377. snd_seq_event_t* inputEvent = 0;
  199378. snd_seq_nonblock (seqHandle, 1);
  199379. do
  199380. {
  199381. if (snd_seq_event_input (seqHandle, &inputEvent) >= 0)
  199382. {
  199383. // xxx what about SYSEXes that are too big for the buffer?
  199384. const int numBytes = snd_midi_event_decode (midiParser, buffer, maxEventSize, inputEvent);
  199385. snd_midi_event_reset_decode (midiParser);
  199386. if (numBytes > 0)
  199387. {
  199388. const MidiMessage message ((const uint8*) buffer,
  199389. numBytes,
  199390. Time::getMillisecondCounter() * 0.001);
  199391. callback->handleIncomingMidiMessage (midiInput, message);
  199392. }
  199393. snd_seq_free_event (inputEvent);
  199394. }
  199395. }
  199396. while (snd_seq_event_input_pending (seqHandle, 0) > 0);
  199397. snd_seq_free_event (inputEvent);
  199398. }
  199399. }
  199400. snd_midi_event_free (midiParser);
  199401. }
  199402. };
  199403. juce_UseDebuggingNewOperator
  199404. private:
  199405. MidiInput* const midiInput;
  199406. snd_seq_t* const seqHandle;
  199407. MidiInputCallback* const callback;
  199408. };
  199409. MidiInput::MidiInput (const String& name_)
  199410. : name (name_),
  199411. internal (0)
  199412. {
  199413. }
  199414. MidiInput::~MidiInput()
  199415. {
  199416. stop();
  199417. MidiInputThread* const thread = (MidiInputThread*) internal;
  199418. delete thread;
  199419. }
  199420. void MidiInput::start()
  199421. {
  199422. ((MidiInputThread*) internal)->startThread();
  199423. }
  199424. void MidiInput::stop()
  199425. {
  199426. ((MidiInputThread*) internal)->stopThread (3000);
  199427. }
  199428. int MidiInput::getDefaultDeviceIndex()
  199429. {
  199430. return 0;
  199431. }
  199432. const StringArray MidiInput::getDevices()
  199433. {
  199434. StringArray devices;
  199435. iterateDevices (true, devices, -1);
  199436. return devices;
  199437. }
  199438. MidiInput* MidiInput::openDevice (int deviceIndex, MidiInputCallback* callback)
  199439. {
  199440. MidiInput* newDevice = 0;
  199441. StringArray devices;
  199442. snd_seq_t* const handle = iterateDevices (true, devices, deviceIndex);
  199443. if (handle != 0)
  199444. {
  199445. newDevice = new MidiInput (devices [deviceIndex]);
  199446. newDevice->internal = new MidiInputThread (newDevice, handle, callback);
  199447. }
  199448. return newDevice;
  199449. }
  199450. MidiInput* MidiInput::createNewDevice (const String& deviceName, MidiInputCallback* callback)
  199451. {
  199452. MidiInput* newDevice = 0;
  199453. snd_seq_t* const handle = createDevice (true, deviceName);
  199454. if (handle != 0)
  199455. {
  199456. newDevice = new MidiInput (deviceName);
  199457. newDevice->internal = new MidiInputThread (newDevice, handle, callback);
  199458. }
  199459. return newDevice;
  199460. }
  199461. #else
  199462. // (These are just stub functions if ALSA is unavailable...)
  199463. const StringArray MidiOutput::getDevices() { return StringArray(); }
  199464. int MidiOutput::getDefaultDeviceIndex() { return 0; }
  199465. MidiOutput* MidiOutput::openDevice (int) { return 0; }
  199466. MidiOutput* MidiOutput::createNewDevice (const String&) { return 0; }
  199467. MidiOutput::~MidiOutput() {}
  199468. void MidiOutput::reset() {}
  199469. bool MidiOutput::getVolume (float&, float&) { return false; }
  199470. void MidiOutput::setVolume (float, float) {}
  199471. void MidiOutput::sendMessageNow (const MidiMessage&) {}
  199472. MidiInput::MidiInput (const String& name_) : name (name_), internal (0) {}
  199473. MidiInput::~MidiInput() {}
  199474. void MidiInput::start() {}
  199475. void MidiInput::stop() {}
  199476. int MidiInput::getDefaultDeviceIndex() { return 0; }
  199477. const StringArray MidiInput::getDevices() { return StringArray(); }
  199478. MidiInput* MidiInput::openDevice (int, MidiInputCallback*) { return 0; }
  199479. MidiInput* MidiInput::createNewDevice (const String&, MidiInputCallback*) { return 0; }
  199480. #endif
  199481. #endif
  199482. /*** End of inlined file: juce_linux_Midi.cpp ***/
  199483. /*** Start of inlined file: juce_linux_AudioCDReader.cpp ***/
  199484. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  199485. // compiled on its own).
  199486. #if JUCE_INCLUDED_FILE && JUCE_USE_CDREADER
  199487. AudioCDReader::AudioCDReader()
  199488. : AudioFormatReader (0, T("CD Audio"))
  199489. {
  199490. }
  199491. const StringArray AudioCDReader::getAvailableCDNames()
  199492. {
  199493. StringArray names;
  199494. return names;
  199495. }
  199496. AudioCDReader* AudioCDReader::createReaderForCD (const int index)
  199497. {
  199498. return 0;
  199499. }
  199500. AudioCDReader::~AudioCDReader()
  199501. {
  199502. }
  199503. void AudioCDReader::refreshTrackLengths()
  199504. {
  199505. }
  199506. bool AudioCDReader::readSamples (int** destSamples, int numDestChannels, int startOffsetInDestBuffer,
  199507. int64 startSampleInFile, int numSamples)
  199508. {
  199509. return false;
  199510. }
  199511. bool AudioCDReader::isCDStillPresent() const
  199512. {
  199513. return false;
  199514. }
  199515. int AudioCDReader::getNumTracks() const
  199516. {
  199517. return 0;
  199518. }
  199519. int AudioCDReader::getPositionOfTrackStart (int trackNum) const
  199520. {
  199521. return 0;
  199522. }
  199523. bool AudioCDReader::isTrackAudio (int trackNum) const
  199524. {
  199525. return false;
  199526. }
  199527. void AudioCDReader::enableIndexScanning (bool b)
  199528. {
  199529. }
  199530. int AudioCDReader::getLastIndex() const
  199531. {
  199532. return 0;
  199533. }
  199534. const Array<int> AudioCDReader::findIndexesInTrack (const int trackNumber)
  199535. {
  199536. return Array<int>();
  199537. }
  199538. int AudioCDReader::getCDDBId()
  199539. {
  199540. return 0;
  199541. }
  199542. #endif
  199543. /*** End of inlined file: juce_linux_AudioCDReader.cpp ***/
  199544. /*** Start of inlined file: juce_linux_FileChooser.cpp ***/
  199545. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  199546. // compiled on its own).
  199547. #if JUCE_INCLUDED_FILE
  199548. void FileChooser::showPlatformDialog (Array<File>& results,
  199549. const String& title,
  199550. const File& file,
  199551. const String& filters,
  199552. bool isDirectory,
  199553. bool selectsFiles,
  199554. bool isSave,
  199555. bool warnAboutOverwritingExistingFiles,
  199556. bool selectMultipleFiles,
  199557. FilePreviewComponent* previewComponent)
  199558. {
  199559. const tchar* const separator = T(":");
  199560. String command ("zenity --file-selection");
  199561. if (title.isNotEmpty())
  199562. command << " --title=\"" << title << "\"";
  199563. if (file != File::nonexistent)
  199564. command << " --filename=\"" << file.getFullPathName () << "\"";
  199565. if (isDirectory)
  199566. command << " --directory";
  199567. if (isSave)
  199568. command << " --save";
  199569. if (selectMultipleFiles)
  199570. command << " --multiple --separator=\"" << separator << "\"";
  199571. command << " 2>&1";
  199572. MemoryOutputStream result;
  199573. int status = -1;
  199574. FILE* stream = popen (command.toUTF8(), "r");
  199575. if (stream != 0)
  199576. {
  199577. for (;;)
  199578. {
  199579. char buffer [1024];
  199580. const int bytesRead = fread (buffer, 1, sizeof (buffer), stream);
  199581. if (bytesRead <= 0)
  199582. break;
  199583. result.write (buffer, bytesRead);
  199584. }
  199585. status = pclose (stream);
  199586. }
  199587. if (status == 0)
  199588. {
  199589. String resultString (String::fromUTF8 (result.getData(), result.getDataSize()));
  199590. StringArray tokens;
  199591. if (selectMultipleFiles)
  199592. tokens.addTokens (resultString, separator, String::empty);
  199593. else
  199594. tokens.add (resultString);
  199595. for (int i = 0; i < tokens.size(); i++)
  199596. results.add (File (tokens[i]));
  199597. return;
  199598. }
  199599. //xxx ain't got one!
  199600. jassertfalse
  199601. }
  199602. #endif
  199603. /*** End of inlined file: juce_linux_FileChooser.cpp ***/
  199604. /*** Start of inlined file: juce_linux_WebBrowserComponent.cpp ***/
  199605. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  199606. // compiled on its own).
  199607. #if JUCE_INCLUDED_FILE && JUCE_WEB_BROWSER
  199608. WebBrowserComponent::WebBrowserComponent (const bool unloadPageWhenBrowserIsHidden_)
  199609. : browser (0),
  199610. blankPageShown (false),
  199611. unloadPageWhenBrowserIsHidden (unloadPageWhenBrowserIsHidden_)
  199612. {
  199613. setOpaque (true);
  199614. }
  199615. WebBrowserComponent::~WebBrowserComponent()
  199616. {
  199617. }
  199618. void WebBrowserComponent::goToURL (const String& url,
  199619. const StringArray* headers,
  199620. const MemoryBlock* postData)
  199621. {
  199622. lastURL = url;
  199623. lastHeaders.clear();
  199624. if (headers != 0)
  199625. lastHeaders = *headers;
  199626. lastPostData.setSize (0);
  199627. if (postData != 0)
  199628. lastPostData = *postData;
  199629. blankPageShown = false;
  199630. }
  199631. void WebBrowserComponent::stop()
  199632. {
  199633. }
  199634. void WebBrowserComponent::goBack()
  199635. {
  199636. lastURL = String::empty;
  199637. blankPageShown = false;
  199638. }
  199639. void WebBrowserComponent::goForward()
  199640. {
  199641. lastURL = String::empty;
  199642. }
  199643. void WebBrowserComponent::refresh()
  199644. {
  199645. }
  199646. void WebBrowserComponent::paint (Graphics& g)
  199647. {
  199648. g.fillAll (Colours::white);
  199649. }
  199650. void WebBrowserComponent::checkWindowAssociation()
  199651. {
  199652. }
  199653. void WebBrowserComponent::reloadLastURL()
  199654. {
  199655. if (lastURL.isNotEmpty())
  199656. {
  199657. goToURL (lastURL, &lastHeaders, &lastPostData);
  199658. lastURL = String::empty;
  199659. }
  199660. }
  199661. void WebBrowserComponent::parentHierarchyChanged()
  199662. {
  199663. checkWindowAssociation();
  199664. }
  199665. void WebBrowserComponent::resized()
  199666. {
  199667. }
  199668. void WebBrowserComponent::visibilityChanged()
  199669. {
  199670. checkWindowAssociation();
  199671. }
  199672. bool WebBrowserComponent::pageAboutToLoad (const String& url)
  199673. {
  199674. return true;
  199675. }
  199676. #endif
  199677. /*** End of inlined file: juce_linux_WebBrowserComponent.cpp ***/
  199678. #endif
  199679. END_JUCE_NAMESPACE
  199680. #endif
  199681. /*** End of inlined file: juce_linux_NativeCode.cpp ***/
  199682. #endif
  199683. #if JUCE_MAC || JUCE_IPHONE
  199684. /*** Start of inlined file: juce_mac_NativeCode.mm ***/
  199685. #if JUCE_MAC || JUCE_IPHONE
  199686. BEGIN_JUCE_NAMESPACE
  199687. #undef Point
  199688. #define JUCE_INCLUDED_FILE 1
  199689. // Now include the actual code files..
  199690. /*** Start of inlined file: juce_mac_ObjCSuffix.h ***/
  199691. #ifndef JUCE_ObjCExtraSuffix
  199692. #define JUCE_ObjCExtraSuffix 3
  199693. #endif
  199694. #define appendMacro1(a, b, c, d, e) a ## _ ## b ## _ ## c ## _ ## d ## _ ## e
  199695. #define appendMacro2(a, b, c, d, e) appendMacro1(a, b, c, d, e)
  199696. #define MakeObjCClassName(rootName) appendMacro2 (rootName, JUCE_MAJOR_VERSION, JUCE_MINOR_VERSION, JUCE_BUILDNUMBER, JUCE_ObjCExtraSuffix)
  199697. /*** End of inlined file: juce_mac_ObjCSuffix.h ***/
  199698. /*** Start of inlined file: juce_mac_Strings.mm ***/
  199699. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  199700. // compiled on its own).
  199701. #if JUCE_INCLUDED_FILE
  199702. static const String nsStringToJuce (NSString* s)
  199703. {
  199704. return String::fromUTF8 ([s UTF8String]);
  199705. }
  199706. static NSString* juceStringToNS (const String& s)
  199707. {
  199708. return [NSString stringWithUTF8String: s.toUTF8()];
  199709. }
  199710. static const String convertUTF16ToString (const UniChar* utf16)
  199711. {
  199712. String s;
  199713. while (*utf16 != 0)
  199714. s += (juce_wchar) *utf16++;
  199715. return s;
  199716. }
  199717. const String PlatformUtilities::cfStringToJuceString (CFStringRef cfString)
  199718. {
  199719. String result;
  199720. if (cfString != 0)
  199721. {
  199722. CFRange range = { 0, CFStringGetLength (cfString) };
  199723. HeapBlock <UniChar> u (range.length + 1);
  199724. CFStringGetCharacters (cfString, range, u);
  199725. u[range.length] = 0;
  199726. result = convertUTF16ToString (u);
  199727. }
  199728. return result;
  199729. }
  199730. CFStringRef PlatformUtilities::juceStringToCFString (const String& s)
  199731. {
  199732. const int len = s.length();
  199733. const juce_wchar* t = (const juce_wchar*) s;
  199734. HeapBlock <UniChar> temp (len + 2);
  199735. for (int i = 0; i <= len; ++i)
  199736. temp[i] = t[i];
  199737. return CFStringCreateWithCharacters (kCFAllocatorDefault, temp, len);
  199738. }
  199739. const String PlatformUtilities::convertToPrecomposedUnicode (const String& s)
  199740. {
  199741. #if JUCE_IPHONE
  199742. const ScopedAutoReleasePool pool;
  199743. return nsStringToJuce ([juceStringToNS (s) precomposedStringWithCanonicalMapping]);
  199744. #else
  199745. UnicodeMapping map;
  199746. map.unicodeEncoding = CreateTextEncoding (kTextEncodingUnicodeDefault,
  199747. kUnicodeNoSubset,
  199748. kTextEncodingDefaultFormat);
  199749. map.otherEncoding = CreateTextEncoding (kTextEncodingUnicodeDefault,
  199750. kUnicodeCanonicalCompVariant,
  199751. kTextEncodingDefaultFormat);
  199752. map.mappingVersion = kUnicodeUseLatestMapping;
  199753. UnicodeToTextInfo conversionInfo = 0;
  199754. String result;
  199755. if (CreateUnicodeToTextInfo (&map, &conversionInfo) == noErr)
  199756. {
  199757. const int len = s.length();
  199758. HeapBlock <UniChar> tempIn, tempOut;
  199759. tempIn.calloc (len + 2);
  199760. tempOut.calloc (len + 2);
  199761. for (int i = 0; i <= len; ++i)
  199762. tempIn[i] = s[i];
  199763. ByteCount bytesRead = 0;
  199764. ByteCount outputBufferSize = 0;
  199765. if (ConvertFromUnicodeToText (conversionInfo,
  199766. len * sizeof (UniChar), tempIn,
  199767. kUnicodeDefaultDirectionMask,
  199768. 0, 0, 0, 0,
  199769. len * sizeof (UniChar), &bytesRead,
  199770. &outputBufferSize, tempOut) == noErr)
  199771. {
  199772. result.preallocateStorage (bytesRead / sizeof (UniChar) + 2);
  199773. tchar* t = const_cast <tchar*> ((const tchar*) result);
  199774. unsigned int i;
  199775. for (i = 0; i < bytesRead / sizeof (UniChar); ++i)
  199776. t[i] = (tchar) tempOut[i];
  199777. t[i] = 0;
  199778. }
  199779. DisposeUnicodeToTextInfo (&conversionInfo);
  199780. }
  199781. return result;
  199782. #endif
  199783. }
  199784. #if ! JUCE_ONLY_BUILD_CORE_LIBRARY
  199785. void SystemClipboard::copyTextToClipboard (const String& text) throw()
  199786. {
  199787. #if JUCE_IPHONE
  199788. [[UIPasteboard generalPasteboard] setValue: juceStringToNS (text)
  199789. forPasteboardType: @"public.text"];
  199790. #else
  199791. [[NSPasteboard generalPasteboard] declareTypes: [NSArray arrayWithObject: NSStringPboardType]
  199792. owner: nil];
  199793. [[NSPasteboard generalPasteboard] setString: juceStringToNS (text)
  199794. forType: NSStringPboardType];
  199795. #endif
  199796. }
  199797. const String SystemClipboard::getTextFromClipboard() throw()
  199798. {
  199799. #if JUCE_IPHONE
  199800. NSString* text = [[UIPasteboard generalPasteboard] valueForPasteboardType: @"public.text"];
  199801. #else
  199802. NSString* text = [[NSPasteboard generalPasteboard] stringForType: NSStringPboardType];
  199803. #endif
  199804. return text == 0 ? String::empty
  199805. : nsStringToJuce (text);
  199806. }
  199807. #endif
  199808. #endif
  199809. /*** End of inlined file: juce_mac_Strings.mm ***/
  199810. /*** Start of inlined file: juce_mac_SystemStats.mm ***/
  199811. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  199812. // compiled on its own).
  199813. #if JUCE_INCLUDED_FILE
  199814. namespace SystemStatsHelpers
  199815. {
  199816. static int64 highResTimerFrequency = 0;
  199817. static double highResTimerToMillisecRatio = 0;
  199818. #if JUCE_INTEL
  199819. static void juce_getCpuVendor (char* const v) throw()
  199820. {
  199821. int vendor[4];
  199822. zerostruct (vendor);
  199823. int dummy = 0;
  199824. asm ("mov %%ebx, %%esi \n\t"
  199825. "cpuid \n\t"
  199826. "xchg %%esi, %%ebx"
  199827. : "=a" (dummy), "=S" (vendor[0]), "=c" (vendor[2]), "=d" (vendor[1]) : "a" (0));
  199828. memcpy (v, vendor, 16);
  199829. }
  199830. static unsigned int getCPUIDWord (unsigned int& familyModel, unsigned int& extFeatures)
  199831. {
  199832. unsigned int cpu = 0;
  199833. unsigned int ext = 0;
  199834. unsigned int family = 0;
  199835. unsigned int dummy = 0;
  199836. asm ("mov %%ebx, %%esi \n\t"
  199837. "cpuid \n\t"
  199838. "xchg %%esi, %%ebx"
  199839. : "=a" (family), "=S" (ext), "=c" (dummy), "=d" (cpu) : "a" (1));
  199840. familyModel = family;
  199841. extFeatures = ext;
  199842. return cpu;
  199843. }
  199844. struct CPUFlags
  199845. {
  199846. bool hasMMX : 1;
  199847. bool hasSSE : 1;
  199848. bool hasSSE2 : 1;
  199849. bool has3DNow : 1;
  199850. };
  199851. static CPUFlags cpuFlags;
  199852. #endif
  199853. }
  199854. void SystemStats::initialiseStats() throw()
  199855. {
  199856. using namespace SystemStatsHelpers;
  199857. static bool initialised = false;
  199858. if (! initialised)
  199859. {
  199860. initialised = true;
  199861. #if JUCE_MAC
  199862. // extremely annoying: adding this line stops the apple menu items from working. Of
  199863. // course, not adding it means that carbon windows (e.g. in plugins) won't get
  199864. // any events.
  199865. //NSApplicationLoad();
  199866. [NSApplication sharedApplication];
  199867. #endif
  199868. #if JUCE_INTEL
  199869. {
  199870. unsigned int familyModel, extFeatures;
  199871. const unsigned int features = getCPUIDWord (familyModel, extFeatures);
  199872. cpuFlags.hasMMX = ((features & (1 << 23)) != 0);
  199873. cpuFlags.hasSSE = ((features & (1 << 25)) != 0);
  199874. cpuFlags.hasSSE2 = ((features & (1 << 26)) != 0);
  199875. cpuFlags.has3DNow = ((extFeatures & (1 << 31)) != 0);
  199876. }
  199877. #endif
  199878. mach_timebase_info_data_t timebase;
  199879. (void) mach_timebase_info (&timebase);
  199880. highResTimerFrequency = (int64) (1.0e9 * timebase.denom / timebase.numer);
  199881. highResTimerToMillisecRatio = timebase.numer / (1.0e6 * timebase.denom);
  199882. String s (SystemStats::getJUCEVersion());
  199883. rlimit lim;
  199884. getrlimit (RLIMIT_NOFILE, &lim);
  199885. lim.rlim_cur = lim.rlim_max = RLIM_INFINITY;
  199886. setrlimit (RLIMIT_NOFILE, &lim);
  199887. }
  199888. }
  199889. SystemStats::OperatingSystemType SystemStats::getOperatingSystemType() throw()
  199890. {
  199891. return MacOSX;
  199892. }
  199893. const String SystemStats::getOperatingSystemName() throw()
  199894. {
  199895. return T("Mac OS X");
  199896. }
  199897. bool SystemStats::isOperatingSystem64Bit() throw()
  199898. {
  199899. #if JUCE_64BIT
  199900. return true;
  199901. #else
  199902. //xxx not sure how to find this out?..
  199903. return false;
  199904. #endif
  199905. }
  199906. int SystemStats::getMemorySizeInMegabytes() throw()
  199907. {
  199908. uint64 mem = 0;
  199909. size_t memSize = sizeof (mem);
  199910. int mib[] = { CTL_HW, HW_MEMSIZE };
  199911. sysctl (mib, 2, &mem, &memSize, 0, 0);
  199912. return (int) (mem / (1024 * 1024));
  199913. }
  199914. bool SystemStats::hasMMX() throw()
  199915. {
  199916. #if JUCE_INTEL
  199917. return SystemStatsHelpers::cpuFlags.hasMMX;
  199918. #else
  199919. return false;
  199920. #endif
  199921. }
  199922. bool SystemStats::hasSSE() throw()
  199923. {
  199924. #if JUCE_INTEL
  199925. return SystemStatsHelpers::cpuFlags.hasSSE;
  199926. #else
  199927. return false;
  199928. #endif
  199929. }
  199930. bool SystemStats::hasSSE2() throw()
  199931. {
  199932. #if JUCE_INTEL
  199933. return SystemStatsHelpers::cpuFlags.hasSSE2;
  199934. #else
  199935. return false;
  199936. #endif
  199937. }
  199938. bool SystemStats::has3DNow() throw()
  199939. {
  199940. #if JUCE_INTEL
  199941. return SystemStatsHelpers::cpuFlags.has3DNow;
  199942. #else
  199943. return false;
  199944. #endif
  199945. }
  199946. const String SystemStats::getCpuVendor() throw()
  199947. {
  199948. #if JUCE_INTEL
  199949. char v [16];
  199950. SystemStatsHelpers::juce_getCpuVendor (v);
  199951. return String (v, 16);
  199952. #else
  199953. return String::empty;
  199954. #endif
  199955. }
  199956. int SystemStats::getCpuSpeedInMegaherz() throw()
  199957. {
  199958. uint64 speedHz = 0;
  199959. size_t speedSize = sizeof (speedHz);
  199960. int mib[] = { CTL_HW, HW_CPU_FREQ };
  199961. sysctl (mib, 2, &speedHz, &speedSize, 0, 0);
  199962. #if JUCE_BIG_ENDIAN
  199963. if (speedSize == 4)
  199964. speedHz >>= 32;
  199965. #endif
  199966. return (int) (speedHz / 1000000);
  199967. }
  199968. int SystemStats::getNumCpus() throw()
  199969. {
  199970. #if JUCE_IPHONE || (MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5)
  199971. return (int) [[NSProcessInfo processInfo] activeProcessorCount];
  199972. #else
  199973. return MPProcessors();
  199974. #endif
  199975. }
  199976. const String SystemStats::getLogonName()
  199977. {
  199978. return nsStringToJuce (NSUserName());
  199979. }
  199980. const String SystemStats::getFullUserName()
  199981. {
  199982. return nsStringToJuce (NSFullUserName());
  199983. }
  199984. uint32 juce_millisecondsSinceStartup() throw()
  199985. {
  199986. return (uint32) (mach_absolute_time() * SystemStatsHelpers::highResTimerToMillisecRatio);
  199987. }
  199988. double Time::getMillisecondCounterHiRes() throw()
  199989. {
  199990. return mach_absolute_time() * SystemStatsHelpers::highResTimerToMillisecRatio;
  199991. }
  199992. int64 Time::getHighResolutionTicks() throw()
  199993. {
  199994. return (int64) mach_absolute_time();
  199995. }
  199996. int64 Time::getHighResolutionTicksPerSecond() throw()
  199997. {
  199998. return SystemStatsHelpers::highResTimerFrequency;
  199999. }
  200000. int64 SystemStats::getClockCycleCounter() throw()
  200001. {
  200002. return (int64) mach_absolute_time();
  200003. }
  200004. bool Time::setSystemTimeToThisTime() const throw()
  200005. {
  200006. jassertfalse
  200007. return false;
  200008. }
  200009. int SystemStats::getPageSize() throw()
  200010. {
  200011. return (int) NSPageSize();
  200012. }
  200013. void PlatformUtilities::fpuReset()
  200014. {
  200015. }
  200016. #endif
  200017. /*** End of inlined file: juce_mac_SystemStats.mm ***/
  200018. /*** Start of inlined file: juce_mac_Network.mm ***/
  200019. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  200020. // compiled on its own).
  200021. #if JUCE_INCLUDED_FILE
  200022. int SystemStats::getMACAddresses (int64* addresses, int maxNum, const bool littleEndian)
  200023. {
  200024. #ifndef IFT_ETHER
  200025. #define IFT_ETHER 6
  200026. #endif
  200027. ifaddrs* addrs = 0;
  200028. int numResults = 0;
  200029. if (getifaddrs (&addrs) == 0)
  200030. {
  200031. const ifaddrs* cursor = addrs;
  200032. while (cursor != 0 && numResults < maxNum)
  200033. {
  200034. sockaddr_storage* sto = (sockaddr_storage*) cursor->ifa_addr;
  200035. if (sto->ss_family == AF_LINK)
  200036. {
  200037. const sockaddr_dl* const sadd = (const sockaddr_dl*) cursor->ifa_addr;
  200038. if (sadd->sdl_type == IFT_ETHER)
  200039. {
  200040. const uint8* const addr = ((const uint8*) sadd->sdl_data) + sadd->sdl_nlen;
  200041. uint64 a = 0;
  200042. for (int i = 6; --i >= 0;)
  200043. a = (a << 8) | addr [littleEndian ? i : (5 - i)];
  200044. *addresses++ = (int64) a;
  200045. ++numResults;
  200046. }
  200047. }
  200048. cursor = cursor->ifa_next;
  200049. }
  200050. freeifaddrs (addrs);
  200051. }
  200052. return numResults;
  200053. }
  200054. bool PlatformUtilities::launchEmailWithAttachments (const String& targetEmailAddress,
  200055. const String& emailSubject,
  200056. const String& bodyText,
  200057. const StringArray& filesToAttach)
  200058. {
  200059. #if JUCE_IPHONE
  200060. //xxx probably need to use MFMailComposeViewController
  200061. jassertfalse
  200062. return false;
  200063. #else
  200064. const ScopedAutoReleasePool pool;
  200065. String script;
  200066. script << "tell application \"Mail\"\r\n"
  200067. "set newMessage to make new outgoing message with properties {subject:\""
  200068. << emailSubject.replace (T("\""), T("\\\""))
  200069. << "\", content:\""
  200070. << bodyText.replace (T("\""), T("\\\""))
  200071. << "\" & return & return}\r\n"
  200072. "tell newMessage\r\n"
  200073. "set visible to true\r\n"
  200074. "set sender to \"sdfsdfsdfewf\"\r\n"
  200075. "make new to recipient at end of to recipients with properties {address:\""
  200076. << targetEmailAddress
  200077. << "\"}\r\n";
  200078. for (int i = 0; i < filesToAttach.size(); ++i)
  200079. {
  200080. script << "tell content\r\n"
  200081. "make new attachment with properties {file name:\""
  200082. << filesToAttach[i].replace (T("\""), T("\\\""))
  200083. << "\"} at after the last paragraph\r\n"
  200084. "end tell\r\n";
  200085. }
  200086. script << "end tell\r\n"
  200087. "end tell\r\n";
  200088. NSAppleScript* s = [[NSAppleScript alloc]
  200089. initWithSource: juceStringToNS (script)];
  200090. NSDictionary* error = 0;
  200091. const bool ok = [s executeAndReturnError: &error] != nil;
  200092. [s release];
  200093. return ok;
  200094. #endif
  200095. }
  200096. END_JUCE_NAMESPACE
  200097. using namespace JUCE_NAMESPACE;
  200098. #define JuceURLConnection MakeObjCClassName(JuceURLConnection)
  200099. @interface JuceURLConnection : NSObject
  200100. {
  200101. @public
  200102. NSURLRequest* request;
  200103. NSURLConnection* connection;
  200104. NSMutableData* data;
  200105. Thread* runLoopThread;
  200106. bool initialised, hasFailed, hasFinished;
  200107. int position;
  200108. int64 contentLength;
  200109. NSLock* dataLock;
  200110. }
  200111. - (JuceURLConnection*) initWithRequest: (NSURLRequest*) req withCallback: (URL::OpenStreamProgressCallback*) callback withContext: (void*) context;
  200112. - (void) dealloc;
  200113. - (void) connection: (NSURLConnection*) connection didReceiveResponse: (NSURLResponse*) response;
  200114. - (void) connection: (NSURLConnection*) connection didFailWithError: (NSError*) error;
  200115. - (void) connection: (NSURLConnection*) connection didReceiveData: (NSData*) data;
  200116. - (void) connectionDidFinishLoading: (NSURLConnection*) connection;
  200117. - (BOOL) isOpen;
  200118. - (int) read: (char*) dest numBytes: (int) num;
  200119. - (int) readPosition;
  200120. - (void) stop;
  200121. - (void) createConnection;
  200122. @end
  200123. class JuceURLConnectionMessageThread : public Thread
  200124. {
  200125. JuceURLConnection* owner;
  200126. public:
  200127. JuceURLConnectionMessageThread (JuceURLConnection* owner_)
  200128. : Thread (T("http connection")),
  200129. owner (owner_)
  200130. {
  200131. }
  200132. ~JuceURLConnectionMessageThread()
  200133. {
  200134. stopThread (10000);
  200135. }
  200136. void run()
  200137. {
  200138. [owner createConnection];
  200139. while (! threadShouldExit())
  200140. {
  200141. const ScopedAutoReleasePool pool;
  200142. [[NSRunLoop currentRunLoop] runUntilDate: [NSDate dateWithTimeIntervalSinceNow: 0.01]];
  200143. }
  200144. }
  200145. };
  200146. @implementation JuceURLConnection
  200147. - (JuceURLConnection*) initWithRequest: (NSURLRequest*) req
  200148. withCallback: (URL::OpenStreamProgressCallback*) callback
  200149. withContext: (void*) context;
  200150. {
  200151. [super init];
  200152. request = req;
  200153. [request retain];
  200154. data = [[NSMutableData data] retain];
  200155. dataLock = [[NSLock alloc] init];
  200156. connection = 0;
  200157. initialised = false;
  200158. hasFailed = false;
  200159. hasFinished = false;
  200160. contentLength = -1;
  200161. runLoopThread = new JuceURLConnectionMessageThread (self);
  200162. runLoopThread->startThread();
  200163. while (runLoopThread->isThreadRunning() && ! initialised)
  200164. {
  200165. if (callback != 0)
  200166. callback (context, -1, (int) [[request HTTPBody] length]);
  200167. Thread::sleep (1);
  200168. }
  200169. return self;
  200170. }
  200171. - (void) dealloc
  200172. {
  200173. [self stop];
  200174. delete runLoopThread;
  200175. [connection release];
  200176. [data release];
  200177. [dataLock release];
  200178. [request release];
  200179. [super dealloc];
  200180. }
  200181. - (void) createConnection
  200182. {
  200183. connection = [[NSURLConnection alloc] initWithRequest: request
  200184. delegate: [self retain]];
  200185. if (connection == nil)
  200186. runLoopThread->signalThreadShouldExit();
  200187. }
  200188. - (void) connection: (NSURLConnection*) connection didReceiveResponse: (NSURLResponse*) response
  200189. {
  200190. [dataLock lock];
  200191. [data setLength: 0];
  200192. [dataLock unlock];
  200193. initialised = true;
  200194. contentLength = [response expectedContentLength];
  200195. }
  200196. - (void) connection: (NSURLConnection*) connection didFailWithError: (NSError*) error
  200197. {
  200198. DBG (nsStringToJuce ([error description]));
  200199. hasFailed = true;
  200200. initialised = true;
  200201. runLoopThread->signalThreadShouldExit();
  200202. }
  200203. - (void) connection: (NSURLConnection*) connection didReceiveData: (NSData*) newData
  200204. {
  200205. [dataLock lock];
  200206. [data appendData: newData];
  200207. [dataLock unlock];
  200208. initialised = true;
  200209. }
  200210. - (void) connectionDidFinishLoading: (NSURLConnection*) connection
  200211. {
  200212. hasFinished = true;
  200213. initialised = true;
  200214. runLoopThread->signalThreadShouldExit();
  200215. }
  200216. - (BOOL) isOpen
  200217. {
  200218. return connection != 0 && ! hasFailed;
  200219. }
  200220. - (int) readPosition
  200221. {
  200222. return position;
  200223. }
  200224. - (int) read: (char*) dest numBytes: (int) numNeeded
  200225. {
  200226. int numDone = 0;
  200227. while (numNeeded > 0)
  200228. {
  200229. int available = jmin (numNeeded, (int) [data length]);
  200230. if (available > 0)
  200231. {
  200232. [dataLock lock];
  200233. [data getBytes: dest length: available];
  200234. [data replaceBytesInRange: NSMakeRange (0, available) withBytes: nil length: 0];
  200235. [dataLock unlock];
  200236. numDone += available;
  200237. numNeeded -= available;
  200238. dest += available;
  200239. }
  200240. else
  200241. {
  200242. if (hasFailed || hasFinished)
  200243. break;
  200244. Thread::sleep (1);
  200245. }
  200246. }
  200247. position += numDone;
  200248. return numDone;
  200249. }
  200250. - (void) stop
  200251. {
  200252. [connection cancel];
  200253. runLoopThread->stopThread (10000);
  200254. }
  200255. @end
  200256. BEGIN_JUCE_NAMESPACE
  200257. bool juce_isOnLine()
  200258. {
  200259. return true;
  200260. }
  200261. void* juce_openInternetFile (const String& url,
  200262. const String& headers,
  200263. const MemoryBlock& postData,
  200264. const bool isPost,
  200265. URL::OpenStreamProgressCallback* callback,
  200266. void* callbackContext,
  200267. int timeOutMs)
  200268. {
  200269. const ScopedAutoReleasePool pool;
  200270. NSMutableURLRequest* req = [NSMutableURLRequest
  200271. requestWithURL: [NSURL URLWithString: juceStringToNS (url)]
  200272. cachePolicy: NSURLRequestUseProtocolCachePolicy
  200273. timeoutInterval: timeOutMs <= 0 ? 60.0 : (timeOutMs / 1000.0)];
  200274. if (req == nil)
  200275. return 0;
  200276. [req setHTTPMethod: isPost ? @"POST" : @"GET"];
  200277. //[req setCachePolicy: NSURLRequestReloadIgnoringLocalAndRemoteCacheData];
  200278. StringArray headerLines;
  200279. headerLines.addLines (headers);
  200280. headerLines.removeEmptyStrings (true);
  200281. for (int i = 0; i < headerLines.size(); ++i)
  200282. {
  200283. const String key (headerLines[i].upToFirstOccurrenceOf (T(":"), false, false).trim());
  200284. const String value (headerLines[i].fromFirstOccurrenceOf (T(":"), false, false).trim());
  200285. if (key.isNotEmpty() && value.isNotEmpty())
  200286. [req addValue: juceStringToNS (value) forHTTPHeaderField: juceStringToNS (key)];
  200287. }
  200288. if (isPost && postData.getSize() > 0)
  200289. {
  200290. [req setHTTPBody: [NSData dataWithBytes: postData.getData()
  200291. length: postData.getSize()]];
  200292. }
  200293. JuceURLConnection* const s = [[JuceURLConnection alloc] initWithRequest: req
  200294. withCallback: callback
  200295. withContext: callbackContext];
  200296. if ([s isOpen])
  200297. return s;
  200298. [s release];
  200299. return 0;
  200300. }
  200301. void juce_closeInternetFile (void* handle)
  200302. {
  200303. JuceURLConnection* const s = (JuceURLConnection*) handle;
  200304. if (s != 0)
  200305. {
  200306. const ScopedAutoReleasePool pool;
  200307. [s stop];
  200308. [s release];
  200309. }
  200310. }
  200311. int juce_readFromInternetFile (void* handle, void* buffer, int bytesToRead)
  200312. {
  200313. JuceURLConnection* const s = (JuceURLConnection*) handle;
  200314. if (s != 0)
  200315. {
  200316. const ScopedAutoReleasePool pool;
  200317. return [s read: (char*) buffer numBytes: bytesToRead];
  200318. }
  200319. return 0;
  200320. }
  200321. int64 juce_getInternetFileContentLength (void* handle)
  200322. {
  200323. JuceURLConnection* const s = (JuceURLConnection*) handle;
  200324. if (s != 0)
  200325. return s->contentLength;
  200326. return -1;
  200327. }
  200328. int juce_seekInInternetFile (void* handle, int newPosition)
  200329. {
  200330. JuceURLConnection* const s = (JuceURLConnection*) handle;
  200331. if (s != 0)
  200332. return [s readPosition];
  200333. return 0;
  200334. }
  200335. #endif
  200336. /*** End of inlined file: juce_mac_Network.mm ***/
  200337. /*** Start of inlined file: juce_posix_NamedPipe.cpp ***/
  200338. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  200339. // compiled on its own).
  200340. #if JUCE_INCLUDED_FILE
  200341. struct NamedPipeInternal
  200342. {
  200343. String pipeInName, pipeOutName;
  200344. int pipeIn, pipeOut;
  200345. bool volatile createdPipe, blocked, stopReadOperation;
  200346. static void signalHandler (int) {}
  200347. };
  200348. void NamedPipe::cancelPendingReads()
  200349. {
  200350. while (internal != 0 && ((NamedPipeInternal*) internal)->blocked)
  200351. {
  200352. NamedPipeInternal* const intern = (NamedPipeInternal*) internal;
  200353. intern->stopReadOperation = true;
  200354. char buffer [1] = { 0 };
  200355. int bytesWritten = (int) ::write (intern->pipeIn, buffer, 1);
  200356. (void) bytesWritten;
  200357. int timeout = 2000;
  200358. while (intern->blocked && --timeout >= 0)
  200359. Thread::sleep (2);
  200360. intern->stopReadOperation = false;
  200361. }
  200362. }
  200363. void NamedPipe::close()
  200364. {
  200365. NamedPipeInternal* const intern = (NamedPipeInternal*) internal;
  200366. if (intern != 0)
  200367. {
  200368. internal = 0;
  200369. if (intern->pipeIn != -1)
  200370. ::close (intern->pipeIn);
  200371. if (intern->pipeOut != -1)
  200372. ::close (intern->pipeOut);
  200373. if (intern->createdPipe)
  200374. {
  200375. unlink (intern->pipeInName.toUTF8());
  200376. unlink (intern->pipeOutName.toUTF8());
  200377. }
  200378. delete intern;
  200379. }
  200380. }
  200381. bool NamedPipe::openInternal (const String& pipeName, const bool createPipe)
  200382. {
  200383. close();
  200384. NamedPipeInternal* const intern = new NamedPipeInternal();
  200385. internal = intern;
  200386. intern->createdPipe = createPipe;
  200387. intern->blocked = false;
  200388. intern->stopReadOperation = false;
  200389. signal (SIGPIPE, NamedPipeInternal::signalHandler);
  200390. siginterrupt (SIGPIPE, 1);
  200391. const String pipePath (T("/tmp/") + File::createLegalFileName (pipeName));
  200392. intern->pipeInName = pipePath + T("_in");
  200393. intern->pipeOutName = pipePath + T("_out");
  200394. intern->pipeIn = -1;
  200395. intern->pipeOut = -1;
  200396. if (createPipe)
  200397. {
  200398. if ((mkfifo (intern->pipeInName.toUTF8(), 0666) && errno != EEXIST)
  200399. || (mkfifo (intern->pipeOutName.toUTF8(), 0666) && errno != EEXIST))
  200400. {
  200401. delete intern;
  200402. internal = 0;
  200403. return false;
  200404. }
  200405. }
  200406. return true;
  200407. }
  200408. int NamedPipe::read (void* destBuffer, int maxBytesToRead, int /*timeOutMilliseconds*/)
  200409. {
  200410. int bytesRead = -1;
  200411. NamedPipeInternal* const intern = (NamedPipeInternal*) internal;
  200412. if (intern != 0)
  200413. {
  200414. intern->blocked = true;
  200415. if (intern->pipeIn == -1)
  200416. {
  200417. if (intern->createdPipe)
  200418. intern->pipeIn = ::open (intern->pipeInName.toUTF8(), O_RDWR);
  200419. else
  200420. intern->pipeIn = ::open (intern->pipeOutName.toUTF8(), O_RDWR);
  200421. if (intern->pipeIn == -1)
  200422. {
  200423. intern->blocked = false;
  200424. return -1;
  200425. }
  200426. }
  200427. bytesRead = 0;
  200428. char* p = (char*) destBuffer;
  200429. while (bytesRead < maxBytesToRead)
  200430. {
  200431. const int bytesThisTime = maxBytesToRead - bytesRead;
  200432. const int numRead = (int) ::read (intern->pipeIn, p, bytesThisTime);
  200433. if (numRead <= 0 || intern->stopReadOperation)
  200434. {
  200435. bytesRead = -1;
  200436. break;
  200437. }
  200438. bytesRead += numRead;
  200439. p += bytesRead;
  200440. }
  200441. intern->blocked = false;
  200442. }
  200443. return bytesRead;
  200444. }
  200445. int NamedPipe::write (const void* sourceBuffer, int numBytesToWrite, int timeOutMilliseconds)
  200446. {
  200447. int bytesWritten = -1;
  200448. NamedPipeInternal* const intern = (NamedPipeInternal*) internal;
  200449. if (intern != 0)
  200450. {
  200451. if (intern->pipeOut == -1)
  200452. {
  200453. if (intern->createdPipe)
  200454. intern->pipeOut = ::open (intern->pipeOutName.toUTF8(), O_WRONLY);
  200455. else
  200456. intern->pipeOut = ::open (intern->pipeInName.toUTF8(), O_WRONLY);
  200457. if (intern->pipeOut == -1)
  200458. {
  200459. return -1;
  200460. }
  200461. }
  200462. const char* p = (const char*) sourceBuffer;
  200463. bytesWritten = 0;
  200464. const uint32 timeOutTime = Time::getMillisecondCounter() + timeOutMilliseconds;
  200465. while (bytesWritten < numBytesToWrite
  200466. && (timeOutMilliseconds < 0 || Time::getMillisecondCounter() < timeOutTime))
  200467. {
  200468. const int bytesThisTime = numBytesToWrite - bytesWritten;
  200469. const int numWritten = (int) ::write (intern->pipeOut, p, bytesThisTime);
  200470. if (numWritten <= 0)
  200471. {
  200472. bytesWritten = -1;
  200473. break;
  200474. }
  200475. bytesWritten += numWritten;
  200476. p += bytesWritten;
  200477. }
  200478. }
  200479. return bytesWritten;
  200480. }
  200481. #endif
  200482. /*** End of inlined file: juce_posix_NamedPipe.cpp ***/
  200483. /*** Start of inlined file: juce_mac_Threads.mm ***/
  200484. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  200485. // compiled on its own).
  200486. #if JUCE_INCLUDED_FILE
  200487. void JUCE_API juce_threadEntryPoint (void*);
  200488. void* threadEntryProc (void* userData)
  200489. {
  200490. const ScopedAutoReleasePool pool;
  200491. juce_threadEntryPoint (userData);
  200492. return 0;
  200493. }
  200494. void* juce_createThread (void* userData)
  200495. {
  200496. pthread_t handle = 0;
  200497. if (pthread_create (&handle, 0, threadEntryProc, userData) == 0)
  200498. {
  200499. pthread_detach (handle);
  200500. return (void*) handle;
  200501. }
  200502. return 0;
  200503. }
  200504. void juce_killThread (void* handle)
  200505. {
  200506. if (handle != 0)
  200507. pthread_cancel ((pthread_t) handle);
  200508. }
  200509. void juce_setCurrentThreadName (const String& /*name*/)
  200510. {
  200511. }
  200512. bool juce_setThreadPriority (void* handle, int priority)
  200513. {
  200514. if (handle == 0)
  200515. handle = (void*) pthread_self();
  200516. struct sched_param param;
  200517. int policy;
  200518. pthread_getschedparam ((pthread_t) handle, &policy, &param);
  200519. param.sched_priority = jlimit (1, 127, 1 + (priority * 126) / 11);
  200520. return pthread_setschedparam ((pthread_t) handle, policy, &param) == 0;
  200521. }
  200522. Thread::ThreadID Thread::getCurrentThreadId()
  200523. {
  200524. return static_cast <ThreadID> (pthread_self());
  200525. }
  200526. void Thread::yield()
  200527. {
  200528. sched_yield();
  200529. }
  200530. void Thread::setCurrentThreadAffinityMask (const uint32 affinityMask)
  200531. {
  200532. // xxx
  200533. jassertfalse
  200534. }
  200535. bool Process::isForegroundProcess()
  200536. {
  200537. #if JUCE_MAC
  200538. return [NSApp isActive];
  200539. #else
  200540. return true; // xxx change this if more than one app is ever possible on the iPhone!
  200541. #endif
  200542. }
  200543. void Process::raisePrivilege()
  200544. {
  200545. jassertfalse
  200546. }
  200547. void Process::lowerPrivilege()
  200548. {
  200549. jassertfalse
  200550. }
  200551. void Process::terminate()
  200552. {
  200553. exit (0);
  200554. }
  200555. void Process::setPriority (ProcessPriority p)
  200556. {
  200557. // xxx
  200558. }
  200559. #endif
  200560. /*** End of inlined file: juce_mac_Threads.mm ***/
  200561. /*** Start of inlined file: juce_posix_SharedCode.h ***/
  200562. CriticalSection::CriticalSection() throw()
  200563. {
  200564. pthread_mutexattr_t atts;
  200565. pthread_mutexattr_init (&atts);
  200566. pthread_mutexattr_settype (&atts, PTHREAD_MUTEX_RECURSIVE);
  200567. pthread_mutex_init (&internal, &atts);
  200568. }
  200569. CriticalSection::~CriticalSection() throw()
  200570. {
  200571. pthread_mutex_destroy (&internal);
  200572. }
  200573. void CriticalSection::enter() const throw()
  200574. {
  200575. pthread_mutex_lock (&internal);
  200576. }
  200577. bool CriticalSection::tryEnter() const throw()
  200578. {
  200579. return pthread_mutex_trylock (&internal) == 0;
  200580. }
  200581. void CriticalSection::exit() const throw()
  200582. {
  200583. pthread_mutex_unlock (&internal);
  200584. }
  200585. class WaitableEventImpl
  200586. {
  200587. public:
  200588. WaitableEventImpl()
  200589. : triggered (false)
  200590. {
  200591. pthread_cond_init (&condition, 0);
  200592. pthread_mutex_init (&mutex, 0);
  200593. }
  200594. ~WaitableEventImpl()
  200595. {
  200596. pthread_cond_destroy (&condition);
  200597. pthread_mutex_destroy (&mutex);
  200598. }
  200599. bool wait (const int timeOutMillisecs) throw()
  200600. {
  200601. pthread_mutex_lock (&mutex);
  200602. if (! triggered)
  200603. {
  200604. if (timeOutMillisecs < 0)
  200605. {
  200606. do
  200607. {
  200608. pthread_cond_wait (&condition, &mutex);
  200609. }
  200610. while (! triggered);
  200611. }
  200612. else
  200613. {
  200614. struct timeval now;
  200615. gettimeofday (&now, 0);
  200616. struct timespec time;
  200617. time.tv_sec = now.tv_sec + (timeOutMillisecs / 1000);
  200618. time.tv_nsec = (now.tv_usec + ((timeOutMillisecs % 1000) * 1000)) * 1000;
  200619. if (time.tv_nsec >= 1000000000)
  200620. {
  200621. time.tv_nsec -= 1000000000;
  200622. time.tv_sec++;
  200623. }
  200624. do
  200625. {
  200626. if (pthread_cond_timedwait (&condition, &mutex, &time) == ETIMEDOUT)
  200627. {
  200628. pthread_mutex_unlock (&mutex);
  200629. return false;
  200630. }
  200631. }
  200632. while (! triggered);
  200633. }
  200634. }
  200635. triggered = false;
  200636. pthread_mutex_unlock (&mutex);
  200637. return true;
  200638. }
  200639. void signal() throw()
  200640. {
  200641. pthread_mutex_lock (&mutex);
  200642. triggered = true;
  200643. pthread_cond_broadcast (&condition);
  200644. pthread_mutex_unlock (&mutex);
  200645. }
  200646. void reset() throw()
  200647. {
  200648. pthread_mutex_lock (&mutex);
  200649. triggered = false;
  200650. pthread_mutex_unlock (&mutex);
  200651. }
  200652. private:
  200653. pthread_cond_t condition;
  200654. pthread_mutex_t mutex;
  200655. bool triggered;
  200656. WaitableEventImpl (const WaitableEventImpl&);
  200657. WaitableEventImpl& operator= (const WaitableEventImpl&);
  200658. };
  200659. WaitableEvent::WaitableEvent() throw()
  200660. : internal (new WaitableEventImpl())
  200661. {
  200662. }
  200663. WaitableEvent::~WaitableEvent() throw()
  200664. {
  200665. delete static_cast <WaitableEventImpl*> (internal);
  200666. }
  200667. bool WaitableEvent::wait (const int timeOutMillisecs) const throw()
  200668. {
  200669. return static_cast <WaitableEventImpl*> (internal)->wait (timeOutMillisecs);
  200670. }
  200671. void WaitableEvent::signal() const throw()
  200672. {
  200673. static_cast <WaitableEventImpl*> (internal)->signal();
  200674. }
  200675. void WaitableEvent::reset() const throw()
  200676. {
  200677. static_cast <WaitableEventImpl*> (internal)->reset();
  200678. }
  200679. void JUCE_CALLTYPE Thread::sleep (int millisecs)
  200680. {
  200681. struct timespec time;
  200682. time.tv_sec = millisecs / 1000;
  200683. time.tv_nsec = (millisecs % 1000) * 1000000;
  200684. nanosleep (&time, 0);
  200685. }
  200686. const tchar File::separator = T('/');
  200687. const tchar* File::separatorString = T("/");
  200688. const File File::getCurrentWorkingDirectory()
  200689. {
  200690. HeapBlock<char> heapBuffer;
  200691. char localBuffer [1024];
  200692. char* cwd = getcwd (localBuffer, sizeof (localBuffer) - 1);
  200693. int bufferSize = 4096;
  200694. while (cwd == 0 && errno == ERANGE)
  200695. {
  200696. heapBuffer.malloc (bufferSize);
  200697. cwd = getcwd (heapBuffer, bufferSize - 1);
  200698. bufferSize += 1024;
  200699. }
  200700. return File (String::fromUTF8 (cwd));
  200701. }
  200702. bool File::setAsCurrentWorkingDirectory() const
  200703. {
  200704. return chdir (getFullPathName().toUTF8()) == 0;
  200705. }
  200706. bool juce_copyFile (const String& s, const String& d);
  200707. static bool juce_stat (const String& fileName, struct stat& info)
  200708. {
  200709. return fileName.isNotEmpty()
  200710. && (stat (fileName.toUTF8(), &info) == 0);
  200711. }
  200712. bool juce_isDirectory (const String& fileName)
  200713. {
  200714. struct stat info;
  200715. return fileName.isEmpty()
  200716. || (juce_stat (fileName, info)
  200717. && ((info.st_mode & S_IFDIR) != 0));
  200718. }
  200719. bool juce_fileExists (const String& fileName, const bool dontCountDirectories)
  200720. {
  200721. if (fileName.isEmpty())
  200722. return false;
  200723. const char* const fileNameUTF8 = fileName.toUTF8();
  200724. bool exists = access (fileNameUTF8, F_OK) == 0;
  200725. if (exists && dontCountDirectories)
  200726. {
  200727. struct stat info;
  200728. const int res = stat (fileNameUTF8, &info);
  200729. if (res == 0 && (info.st_mode & S_IFDIR) != 0)
  200730. exists = false;
  200731. }
  200732. return exists;
  200733. }
  200734. int64 juce_getFileSize (const String& fileName)
  200735. {
  200736. struct stat info;
  200737. return juce_stat (fileName, info) ? info.st_size : 0;
  200738. }
  200739. bool juce_canWriteToFile (const String& fileName)
  200740. {
  200741. return access (fileName.toUTF8(), W_OK) == 0;
  200742. }
  200743. bool juce_deleteFile (const String& fileName)
  200744. {
  200745. if (juce_isDirectory (fileName))
  200746. return rmdir (fileName.toUTF8()) == 0;
  200747. else
  200748. return remove (fileName.toUTF8()) == 0;
  200749. }
  200750. bool juce_moveFile (const String& source, const String& dest)
  200751. {
  200752. if (rename (source.toUTF8(), dest.toUTF8()) == 0)
  200753. return true;
  200754. if (juce_canWriteToFile (source)
  200755. && juce_copyFile (source, dest))
  200756. {
  200757. if (juce_deleteFile (source))
  200758. return true;
  200759. juce_deleteFile (dest);
  200760. }
  200761. return false;
  200762. }
  200763. void juce_createDirectory (const String& fileName)
  200764. {
  200765. mkdir (fileName.toUTF8(), 0777);
  200766. }
  200767. void* juce_fileOpen (const String& fileName, bool forWriting)
  200768. {
  200769. int flags = O_RDONLY;
  200770. if (forWriting)
  200771. {
  200772. if (juce_fileExists (fileName, false))
  200773. {
  200774. const int f = open (fileName.toUTF8(), O_RDWR, 00644);
  200775. if (f != -1)
  200776. lseek (f, 0, SEEK_END);
  200777. return (void*) f;
  200778. }
  200779. else
  200780. {
  200781. flags = O_RDWR + O_CREAT;
  200782. }
  200783. }
  200784. return (void*) open (fileName.toUTF8(), flags, 00644);
  200785. }
  200786. void juce_fileClose (void* handle)
  200787. {
  200788. if (handle != 0)
  200789. close ((int) (pointer_sized_int) handle);
  200790. }
  200791. int juce_fileRead (void* handle, void* buffer, int size)
  200792. {
  200793. if (handle != 0)
  200794. return (int) read ((int) (pointer_sized_int) handle, buffer, size);
  200795. return 0;
  200796. }
  200797. int juce_fileWrite (void* handle, const void* buffer, int size)
  200798. {
  200799. if (handle != 0)
  200800. return (int) write ((int) (pointer_sized_int) handle, buffer, size);
  200801. return 0;
  200802. }
  200803. int64 juce_fileSetPosition (void* handle, int64 pos)
  200804. {
  200805. if (handle != 0 && lseek ((int) (pointer_sized_int) handle, pos, SEEK_SET) == pos)
  200806. return pos;
  200807. return -1;
  200808. }
  200809. int64 juce_fileGetPosition (void* handle)
  200810. {
  200811. if (handle != 0)
  200812. return lseek ((int) (pointer_sized_int) handle, 0, SEEK_CUR);
  200813. else
  200814. return -1;
  200815. }
  200816. void juce_fileFlush (void* handle)
  200817. {
  200818. if (handle != 0)
  200819. fsync ((int) (pointer_sized_int) handle);
  200820. }
  200821. const File juce_getExecutableFile()
  200822. {
  200823. Dl_info exeInfo;
  200824. dladdr ((const void*) juce_getExecutableFile, &exeInfo);
  200825. return File (String::fromUTF8 (exeInfo.dli_fname));
  200826. }
  200827. // if this file doesn't exist, find a parent of it that does..
  200828. static bool doStatFS (const File* file, struct statfs& result)
  200829. {
  200830. File f (*file);
  200831. for (int i = 5; --i >= 0;)
  200832. {
  200833. if (f.exists())
  200834. break;
  200835. f = f.getParentDirectory();
  200836. }
  200837. return statfs (f.getFullPathName().toUTF8(), &result) == 0;
  200838. }
  200839. int64 File::getBytesFreeOnVolume() const
  200840. {
  200841. struct statfs buf;
  200842. if (doStatFS (this, buf))
  200843. return (int64) buf.f_bsize * (int64) buf.f_bavail; // Note: this returns space available to non-super user
  200844. return 0;
  200845. }
  200846. int64 File::getVolumeTotalSize() const
  200847. {
  200848. struct statfs buf;
  200849. if (doStatFS (this, buf))
  200850. return (int64) buf.f_bsize * (int64) buf.f_blocks;
  200851. return 0;
  200852. }
  200853. const String juce_getVolumeLabel (const String& filenameOnVolume,
  200854. int& volumeSerialNumber)
  200855. {
  200856. volumeSerialNumber = 0;
  200857. #if JUCE_MAC
  200858. struct VolAttrBuf
  200859. {
  200860. u_int32_t length;
  200861. attrreference_t mountPointRef;
  200862. char mountPointSpace [MAXPATHLEN];
  200863. } attrBuf;
  200864. struct attrlist attrList;
  200865. zerostruct (attrList);
  200866. attrList.bitmapcount = ATTR_BIT_MAP_COUNT;
  200867. attrList.volattr = ATTR_VOL_INFO | ATTR_VOL_NAME;
  200868. File f (filenameOnVolume);
  200869. for (;;)
  200870. {
  200871. if (getattrlist (f.getFullPathName().toUTF8(),
  200872. &attrList, &attrBuf, sizeof(attrBuf), 0) == 0)
  200873. {
  200874. return String::fromUTF8 (((const char*) &attrBuf.mountPointRef) + attrBuf.mountPointRef.attr_dataoffset,
  200875. (int) attrBuf.mountPointRef.attr_length);
  200876. }
  200877. const File parent (f.getParentDirectory());
  200878. if (f == parent)
  200879. break;
  200880. f = parent;
  200881. }
  200882. #endif
  200883. return String::empty;
  200884. }
  200885. void juce_runSystemCommand (const String& command)
  200886. {
  200887. int result = system (command.toUTF8());
  200888. (void) result;
  200889. }
  200890. const String juce_getOutputFromCommand (const String& command)
  200891. {
  200892. // slight bodge here, as we just pipe the output into a temp file and read it...
  200893. const File tempFile (File::getSpecialLocation (File::tempDirectory)
  200894. .getNonexistentChildFile (String::toHexString (Random::getSystemRandom().nextInt()), ".tmp", false));
  200895. juce_runSystemCommand (command + " > " + tempFile.getFullPathName());
  200896. String result (tempFile.loadFileAsString());
  200897. tempFile.deleteFile();
  200898. return result;
  200899. }
  200900. InterProcessLock::InterProcessLock (const String& name_)
  200901. : internal (0),
  200902. name (name_),
  200903. reentrancyLevel (0)
  200904. {
  200905. #if JUCE_MAC
  200906. // (don't use getSpecialLocation() to avoid the temp folder being different for each app)
  200907. const File temp (File (T("~/Library/Caches/Juce")).getChildFile (name));
  200908. #else
  200909. const File temp (File::getSpecialLocation (File::tempDirectory).getChildFile (name));
  200910. #endif
  200911. temp.create();
  200912. internal = open (temp.getFullPathName().toUTF8(), O_RDWR);
  200913. }
  200914. InterProcessLock::~InterProcessLock()
  200915. {
  200916. while (reentrancyLevel > 0)
  200917. this->exit();
  200918. close (internal);
  200919. }
  200920. bool InterProcessLock::enter (const int timeOutMillisecs)
  200921. {
  200922. if (internal == 0)
  200923. return false;
  200924. if (reentrancyLevel != 0)
  200925. return true;
  200926. const int64 endTime = Time::currentTimeMillis() + timeOutMillisecs;
  200927. struct flock fl;
  200928. zerostruct (fl);
  200929. fl.l_whence = SEEK_SET;
  200930. fl.l_type = F_WRLCK;
  200931. for (;;)
  200932. {
  200933. const int result = fcntl (internal, F_SETLK, &fl);
  200934. if (result >= 0)
  200935. {
  200936. ++reentrancyLevel;
  200937. return true;
  200938. }
  200939. if (errno != EINTR)
  200940. {
  200941. if (timeOutMillisecs == 0
  200942. || (timeOutMillisecs > 0 && Time::currentTimeMillis() >= endTime))
  200943. break;
  200944. Thread::sleep (10);
  200945. }
  200946. }
  200947. return false;
  200948. }
  200949. void InterProcessLock::exit()
  200950. {
  200951. if (reentrancyLevel > 0 && internal != 0)
  200952. {
  200953. --reentrancyLevel;
  200954. struct flock fl;
  200955. zerostruct (fl);
  200956. fl.l_whence = SEEK_SET;
  200957. fl.l_type = F_UNLCK;
  200958. for (;;)
  200959. {
  200960. const int result = fcntl (internal, F_SETLKW, &fl);
  200961. if (result >= 0 || errno != EINTR)
  200962. break;
  200963. }
  200964. }
  200965. }
  200966. /*** End of inlined file: juce_posix_SharedCode.h ***/
  200967. /*** Start of inlined file: juce_mac_Files.mm ***/
  200968. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  200969. // compiled on its own).
  200970. #if JUCE_INCLUDED_FILE
  200971. void juce_getFileTimes (const String& fileName,
  200972. int64& modificationTime,
  200973. int64& accessTime,
  200974. int64& creationTime)
  200975. {
  200976. modificationTime = 0;
  200977. accessTime = 0;
  200978. creationTime = 0;
  200979. struct stat info;
  200980. const int res = stat (fileName.toUTF8(), &info);
  200981. if (res == 0)
  200982. {
  200983. modificationTime = (int64) info.st_mtime * 1000;
  200984. accessTime = (int64) info.st_atime * 1000;
  200985. creationTime = (int64) info.st_ctime * 1000;
  200986. }
  200987. }
  200988. bool juce_setFileTimes (const String& fileName,
  200989. int64 modificationTime,
  200990. int64 accessTime,
  200991. int64 creationTime)
  200992. {
  200993. struct utimbuf times;
  200994. times.actime = (time_t) (accessTime / 1000);
  200995. times.modtime = (time_t) (modificationTime / 1000);
  200996. return utime (fileName.toUTF8(), &times) == 0;
  200997. }
  200998. bool juce_setFileReadOnly (const String& fileName, bool isReadOnly)
  200999. {
  201000. struct stat info;
  201001. const int res = stat (fileName.toUTF8(), &info);
  201002. if (res != 0)
  201003. return false;
  201004. info.st_mode &= 0777; // Just permissions
  201005. if (isReadOnly)
  201006. info.st_mode &= ~(S_IWUSR | S_IWGRP | S_IWOTH);
  201007. else
  201008. // Give everybody write permission?
  201009. info.st_mode |= S_IWUSR | S_IWGRP | S_IWOTH;
  201010. return chmod (fileName.toUTF8(), info.st_mode) == 0;
  201011. }
  201012. bool juce_copyFile (const String& src, const String& dst)
  201013. {
  201014. const ScopedAutoReleasePool pool;
  201015. NSFileManager* fm = [NSFileManager defaultManager];
  201016. return [fm fileExistsAtPath: juceStringToNS (src)]
  201017. #if defined (MAC_OS_X_VERSION_10_6) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
  201018. && [fm copyItemAtPath: juceStringToNS (src)
  201019. toPath: juceStringToNS (dst)
  201020. error: nil];
  201021. #else
  201022. && [fm copyPath: juceStringToNS (src)
  201023. toPath: juceStringToNS (dst)
  201024. handler: nil];
  201025. #endif
  201026. }
  201027. const StringArray juce_getFileSystemRoots()
  201028. {
  201029. StringArray s;
  201030. s.add (T("/"));
  201031. return s;
  201032. }
  201033. static bool isFileOnDriveType (const File* const f, const char** types)
  201034. {
  201035. struct statfs buf;
  201036. if (doStatFS (f, buf))
  201037. {
  201038. const String type (buf.f_fstypename);
  201039. while (*types != 0)
  201040. if (type.equalsIgnoreCase (*types++))
  201041. return true;
  201042. }
  201043. return false;
  201044. }
  201045. bool File::isOnCDRomDrive() const
  201046. {
  201047. static const char* const cdTypes[] = { "cd9660", "cdfs", "cddafs", "udf", 0 };
  201048. return isFileOnDriveType (this, (const char**) cdTypes);
  201049. }
  201050. bool File::isOnHardDisk() const
  201051. {
  201052. static const char* const nonHDTypes[] = { "nfs", "smbfs", "ramfs", 0 };
  201053. return ! (isOnCDRomDrive() || isFileOnDriveType (this, (const char**) nonHDTypes));
  201054. }
  201055. bool File::isOnRemovableDrive() const
  201056. {
  201057. #if JUCE_IPHONE
  201058. return false; // xxx is this possible?
  201059. #else
  201060. const ScopedAutoReleasePool pool;
  201061. BOOL removable = false;
  201062. [[NSWorkspace sharedWorkspace]
  201063. getFileSystemInfoForPath: juceStringToNS (getFullPathName())
  201064. isRemovable: &removable
  201065. isWritable: nil
  201066. isUnmountable: nil
  201067. description: nil
  201068. type: nil];
  201069. return removable;
  201070. #endif
  201071. }
  201072. static bool juce_isHiddenFile (const String& path)
  201073. {
  201074. #if JUCE_IPHONE
  201075. return File (path).getFileName().startsWithChar (T('.'));
  201076. #else
  201077. FSRef ref;
  201078. if (! PlatformUtilities::makeFSRefFromPath (&ref, path))
  201079. return false;
  201080. FSCatalogInfo info;
  201081. FSGetCatalogInfo (&ref, kFSCatInfoNodeFlags | kFSCatInfoFinderInfo, &info, 0, 0, 0);
  201082. if ((info.nodeFlags & kFSNodeIsDirectoryBit) != 0)
  201083. return (((FolderInfo*) &info.finderInfo)->finderFlags & kIsInvisible) != 0;
  201084. return (((FileInfo*) &info.finderInfo)->finderFlags & kIsInvisible) != 0;
  201085. #endif
  201086. }
  201087. bool File::isHidden() const
  201088. {
  201089. return juce_isHiddenFile (getFullPathName());
  201090. }
  201091. const char* juce_Argv0 = 0; // referenced from juce_Application.cpp
  201092. const File File::getSpecialLocation (const SpecialLocationType type)
  201093. {
  201094. const ScopedAutoReleasePool pool;
  201095. String resultPath;
  201096. switch (type)
  201097. {
  201098. case userHomeDirectory:
  201099. resultPath = nsStringToJuce (NSHomeDirectory());
  201100. break;
  201101. case userDocumentsDirectory:
  201102. resultPath = "~/Documents";
  201103. break;
  201104. case userDesktopDirectory:
  201105. resultPath = "~/Desktop";
  201106. break;
  201107. case userApplicationDataDirectory:
  201108. resultPath = "~/Library";
  201109. break;
  201110. case commonApplicationDataDirectory:
  201111. resultPath = "/Library";
  201112. break;
  201113. case globalApplicationsDirectory:
  201114. resultPath = "/Applications";
  201115. break;
  201116. case userMusicDirectory:
  201117. resultPath = "~/Music";
  201118. break;
  201119. case userMoviesDirectory:
  201120. resultPath = "~/Movies";
  201121. break;
  201122. case tempDirectory:
  201123. {
  201124. File tmp (T("~/Library/Caches/") + juce_getExecutableFile().getFileNameWithoutExtension());
  201125. tmp.createDirectory();
  201126. return tmp.getFullPathName();
  201127. }
  201128. case invokedExecutableFile:
  201129. if (juce_Argv0 != 0)
  201130. return File (String::fromUTF8 (juce_Argv0));
  201131. // deliberate fall-through...
  201132. case currentExecutableFile:
  201133. return juce_getExecutableFile();
  201134. case currentApplicationFile:
  201135. {
  201136. const File exe (juce_getExecutableFile());
  201137. const File parent (exe.getParentDirectory());
  201138. return parent.getFullPathName().endsWithIgnoreCase (T("Contents/MacOS"))
  201139. ? parent.getParentDirectory().getParentDirectory()
  201140. : exe;
  201141. }
  201142. default:
  201143. jassertfalse // unknown type?
  201144. break;
  201145. }
  201146. if (resultPath.isNotEmpty())
  201147. return File (PlatformUtilities::convertToPrecomposedUnicode (resultPath));
  201148. return File::nonexistent;
  201149. }
  201150. const String File::getVersion() const
  201151. {
  201152. const ScopedAutoReleasePool pool;
  201153. String result;
  201154. NSBundle* bundle = [NSBundle bundleWithPath: juceStringToNS (getFullPathName())];
  201155. if (bundle != 0)
  201156. {
  201157. NSDictionary* info = [bundle infoDictionary];
  201158. if (info != 0)
  201159. {
  201160. NSString* name = [info valueForKey: @"CFBundleShortVersionString"];
  201161. if (name != nil)
  201162. result = nsStringToJuce (name);
  201163. }
  201164. }
  201165. return result;
  201166. }
  201167. const File File::getLinkedTarget() const
  201168. {
  201169. #if JUCE_IPHONE || (defined (MAC_OS_X_VERSION_10_5) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5)
  201170. NSString* dest = [[NSFileManager defaultManager] destinationOfSymbolicLinkAtPath: juceStringToNS (getFullPathName()) error: nil];
  201171. #else
  201172. NSString* dest = [[NSFileManager defaultManager] pathContentOfSymbolicLinkAtPath: juceStringToNS (getFullPathName())];
  201173. #endif
  201174. if (dest != nil)
  201175. return File (nsStringToJuce (dest));
  201176. return *this;
  201177. }
  201178. bool File::moveToTrash() const
  201179. {
  201180. if (! exists())
  201181. return true;
  201182. #if JUCE_IPHONE
  201183. return deleteFile(); //xxx is there a trashcan on the iPhone?
  201184. #else
  201185. const ScopedAutoReleasePool pool;
  201186. NSString* p = juceStringToNS (getFullPathName());
  201187. return [[NSWorkspace sharedWorkspace]
  201188. performFileOperation: NSWorkspaceRecycleOperation
  201189. source: [p stringByDeletingLastPathComponent]
  201190. destination: @""
  201191. files: [NSArray arrayWithObject: [p lastPathComponent]]
  201192. tag: nil ];
  201193. #endif
  201194. }
  201195. struct FindFileStruct
  201196. {
  201197. NSDirectoryEnumerator* enumerator;
  201198. String parentDir, wildCard;
  201199. };
  201200. bool juce_findFileNext (void* handle, String& resultFile,
  201201. bool* isDir, bool* isHidden, int64* fileSize, Time* modTime, Time* creationTime, bool* isReadOnly)
  201202. {
  201203. ScopedAutoReleasePool pool;
  201204. FindFileStruct* ff = (FindFileStruct*) handle;
  201205. NSString* file;
  201206. const char* const wildcardUTF8 = ff->wildCard.toUTF8();
  201207. for (;;)
  201208. {
  201209. if (ff == 0 || (file = [ff->enumerator nextObject]) == 0)
  201210. return false;
  201211. [ff->enumerator skipDescendents];
  201212. resultFile = nsStringToJuce (file);
  201213. if (fnmatch (wildcardUTF8, resultFile.toUTF8(), FNM_CASEFOLD) != 0)
  201214. continue;
  201215. const String path (ff->parentDir + resultFile);
  201216. if (isDir != 0 || fileSize != 0)
  201217. {
  201218. struct stat info;
  201219. const bool statOk = juce_stat (path, info);
  201220. if (isDir != 0)
  201221. *isDir = statOk && ((info.st_mode & S_IFDIR) != 0);
  201222. if (isHidden != 0)
  201223. *isHidden = juce_isHiddenFile (path);
  201224. if (fileSize != 0)
  201225. *fileSize = statOk ? info.st_size : 0;
  201226. }
  201227. if (modTime != 0 || creationTime != 0)
  201228. {
  201229. int64 m, a, c;
  201230. juce_getFileTimes (path, m, a, c);
  201231. if (modTime != 0)
  201232. *modTime = m;
  201233. if (creationTime != 0)
  201234. *creationTime = c;
  201235. }
  201236. if (isReadOnly != 0)
  201237. *isReadOnly = ! juce_canWriteToFile (path);
  201238. return true;
  201239. }
  201240. }
  201241. void* juce_findFileStart (const String& directory, const String& wildCard, String& firstResultFile,
  201242. bool* isDir, bool* isHidden, int64* fileSize, Time* modTime,
  201243. Time* creationTime, bool* isReadOnly)
  201244. {
  201245. ScopedAutoReleasePool pool;
  201246. NSDirectoryEnumerator* e = [[NSFileManager defaultManager] enumeratorAtPath: juceStringToNS (directory)];
  201247. if (e != 0)
  201248. {
  201249. ScopedPointer <FindFileStruct> ff (new FindFileStruct());
  201250. ff->enumerator = [e retain];
  201251. ff->parentDir = directory;
  201252. ff->wildCard = wildCard;
  201253. if (! ff->parentDir.endsWithChar (File::separator))
  201254. ff->parentDir += File::separator;
  201255. if (juce_findFileNext (ff, firstResultFile, isDir, isHidden, fileSize, modTime, creationTime, isReadOnly))
  201256. return ff.release();
  201257. [e release];
  201258. }
  201259. return 0;
  201260. }
  201261. void juce_findFileClose (void* handle)
  201262. {
  201263. ScopedAutoReleasePool pool;
  201264. ScopedPointer <FindFileStruct> ff ((FindFileStruct*) handle);
  201265. [ff->enumerator release];
  201266. }
  201267. bool juce_launchExecutable (const String& pathAndArguments)
  201268. {
  201269. const char* const argv[4] = { "/bin/sh", "-c", pathAndArguments.toUTF8(), 0 };
  201270. const int cpid = fork();
  201271. if (cpid == 0)
  201272. {
  201273. // Child process
  201274. if (execve (argv[0], (char**) argv, 0) < 0)
  201275. exit (0);
  201276. }
  201277. else
  201278. {
  201279. if (cpid < 0)
  201280. return false;
  201281. }
  201282. return true;
  201283. }
  201284. bool juce_launchFile (const String& fileName, const String& parameters)
  201285. {
  201286. #if JUCE_IPHONE
  201287. return [[UIApplication sharedApplication] openURL: [NSURL fileURLWithPath: juceStringToNS (fileName)]];
  201288. #else
  201289. const ScopedAutoReleasePool pool;
  201290. if (parameters.isEmpty())
  201291. {
  201292. return [[NSWorkspace sharedWorkspace] openFile: juceStringToNS (fileName)]
  201293. || [[NSWorkspace sharedWorkspace] openURL: [NSURL URLWithString: juceStringToNS (fileName)]];
  201294. }
  201295. bool ok = false;
  201296. FSRef ref;
  201297. if (PlatformUtilities::makeFSRefFromPath (&ref, fileName))
  201298. {
  201299. if (PlatformUtilities::isBundle (fileName))
  201300. {
  201301. NSMutableArray* urls = [NSMutableArray array];
  201302. StringArray docs;
  201303. docs.addTokens (parameters, true);
  201304. for (int i = 0; i < docs.size(); ++i)
  201305. [urls addObject: juceStringToNS (docs[i])];
  201306. ok = [[NSWorkspace sharedWorkspace] openURLs: urls
  201307. withAppBundleIdentifier: [[NSBundle bundleWithPath: juceStringToNS (fileName)] bundleIdentifier]
  201308. options: 0
  201309. additionalEventParamDescriptor: nil
  201310. launchIdentifiers: nil];
  201311. }
  201312. else
  201313. {
  201314. ok = juce_launchExecutable (T("\"") + fileName + T("\" ") + parameters);
  201315. }
  201316. }
  201317. return ok;
  201318. #endif
  201319. }
  201320. void File::revealToUser() const
  201321. {
  201322. #if ! JUCE_IPHONE
  201323. if (exists())
  201324. [[NSWorkspace sharedWorkspace] selectFile: juceStringToNS (getFullPathName()) inFileViewerRootedAtPath: @""];
  201325. else if (getParentDirectory().exists())
  201326. getParentDirectory().revealToUser();
  201327. #endif
  201328. }
  201329. #if ! JUCE_IPHONE
  201330. bool PlatformUtilities::makeFSRefFromPath (FSRef* destFSRef, const String& path)
  201331. {
  201332. return FSPathMakeRef ((const UInt8*) path.toUTF8(), destFSRef, 0) == noErr;
  201333. }
  201334. const String PlatformUtilities::makePathFromFSRef (FSRef* file)
  201335. {
  201336. char path [2048];
  201337. zerostruct (path);
  201338. if (FSRefMakePath (file, (UInt8*) path, sizeof (path) - 1) == noErr)
  201339. return PlatformUtilities::convertToPrecomposedUnicode (String::fromUTF8 (path));
  201340. return String::empty;
  201341. }
  201342. #endif
  201343. OSType PlatformUtilities::getTypeOfFile (const String& filename)
  201344. {
  201345. const ScopedAutoReleasePool pool;
  201346. #if JUCE_IPHONE || (defined (MAC_OS_X_VERSION_10_5) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5)
  201347. NSDictionary* fileDict = [[NSFileManager defaultManager] attributesOfItemAtPath: juceStringToNS (filename) error: nil];
  201348. #else
  201349. NSDictionary* fileDict = [[NSFileManager defaultManager] fileAttributesAtPath: juceStringToNS (filename) traverseLink: NO];
  201350. #endif
  201351. //return (OSType) [fileDict objectForKey: NSFileHFSTypeCode];
  201352. return [fileDict fileHFSTypeCode];
  201353. }
  201354. bool PlatformUtilities::isBundle (const String& filename)
  201355. {
  201356. #if JUCE_IPHONE
  201357. return false; // xxx can't find a sensible way to do this without trying to open the bundle..
  201358. #else
  201359. const ScopedAutoReleasePool pool;
  201360. return [[NSWorkspace sharedWorkspace] isFilePackageAtPath: juceStringToNS (filename)];
  201361. #endif
  201362. }
  201363. #endif
  201364. /*** End of inlined file: juce_mac_Files.mm ***/
  201365. #if JUCE_IPHONE
  201366. /*** Start of inlined file: juce_iphone_MiscUtilities.mm ***/
  201367. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  201368. // compiled on its own).
  201369. #if JUCE_INCLUDED_FILE
  201370. static JUCEApplication* juce_intialisingApp;
  201371. END_JUCE_NAMESPACE
  201372. @interface JuceAppStartupDelegate : NSObject <UIApplicationDelegate>
  201373. {
  201374. }
  201375. - (void) applicationDidFinishLaunching: (UIApplication*) application;
  201376. - (void) applicationWillResignActive: (UIApplication*) application;
  201377. @end
  201378. @implementation JuceAppStartupDelegate
  201379. - (void) applicationDidFinishLaunching: (UIApplication*) application
  201380. {
  201381. String dummy;
  201382. if (! juce_intialisingApp->initialiseApp (dummy))
  201383. exit (0);
  201384. }
  201385. - (void) applicationWillResignActive: (UIApplication*) application
  201386. {
  201387. JUCEApplication::shutdownAppAndClearUp();
  201388. }
  201389. @end
  201390. BEGIN_JUCE_NAMESPACE
  201391. int juce_IPhoneMain (int argc, const char* argv[], JUCEApplication* app)
  201392. {
  201393. juce_intialisingApp = app;
  201394. return UIApplicationMain (argc, const_cast<char**> (argv), nil, @"JuceAppStartupDelegate");
  201395. }
  201396. ScopedAutoReleasePool::ScopedAutoReleasePool()
  201397. {
  201398. pool = [[NSAutoreleasePool alloc] init];
  201399. }
  201400. ScopedAutoReleasePool::~ScopedAutoReleasePool()
  201401. {
  201402. [((NSAutoreleasePool*) pool) release];
  201403. }
  201404. void PlatformUtilities::beep()
  201405. {
  201406. //xxx
  201407. //AudioServicesPlaySystemSound ();
  201408. }
  201409. void PlatformUtilities::addItemToDock (const File& file)
  201410. {
  201411. }
  201412. #if ! JUCE_ONLY_BUILD_CORE_LIBRARY
  201413. END_JUCE_NAMESPACE
  201414. @interface JuceAlertBoxDelegate : NSObject
  201415. {
  201416. @public
  201417. bool clickedOk;
  201418. }
  201419. - (void) alertView: (UIAlertView*) alertView clickedButtonAtIndex: (NSInteger) buttonIndex;
  201420. @end
  201421. @implementation JuceAlertBoxDelegate
  201422. - (void) alertView: (UIAlertView*) alertView clickedButtonAtIndex: (NSInteger) buttonIndex
  201423. {
  201424. clickedOk = (buttonIndex == 0);
  201425. alertView.hidden = true;
  201426. }
  201427. @end
  201428. BEGIN_JUCE_NAMESPACE
  201429. // (This function is used directly by other bits of code)
  201430. bool juce_iPhoneShowModalAlert (const String& title,
  201431. const String& bodyText,
  201432. NSString* okButtonText,
  201433. NSString* cancelButtonText)
  201434. {
  201435. const ScopedAutoReleasePool pool;
  201436. JuceAlertBoxDelegate* callback = [[JuceAlertBoxDelegate alloc] init];
  201437. UIAlertView* alert = [[UIAlertView alloc] initWithTitle: juceStringToNS (title)
  201438. message: juceStringToNS (bodyText)
  201439. delegate: callback
  201440. cancelButtonTitle: okButtonText
  201441. otherButtonTitles: cancelButtonText, nil];
  201442. [alert retain];
  201443. [alert show];
  201444. while (! alert.hidden && alert.superview != nil)
  201445. [[NSRunLoop mainRunLoop] runUntilDate: [NSDate dateWithTimeIntervalSinceNow: 0.01]];
  201446. const bool result = callback->clickedOk;
  201447. [alert release];
  201448. [callback release];
  201449. return result;
  201450. }
  201451. bool AlertWindow::showNativeDialogBox (const String& title,
  201452. const String& bodyText,
  201453. bool isOkCancel)
  201454. {
  201455. return juce_iPhoneShowModalAlert (title, bodyText,
  201456. @"OK",
  201457. isOkCancel ? @"Cancel" : nil);
  201458. }
  201459. bool DragAndDropContainer::performExternalDragDropOfFiles (const StringArray& files, const bool canMoveFiles)
  201460. {
  201461. jassertfalse // no such thing on the iphone!
  201462. return false;
  201463. }
  201464. bool DragAndDropContainer::performExternalDragDropOfText (const String& text)
  201465. {
  201466. jassertfalse // no such thing on the iphone!
  201467. return false;
  201468. }
  201469. void Desktop::setScreenSaverEnabled (const bool isEnabled) throw()
  201470. {
  201471. [[UIApplication sharedApplication] setIdleTimerDisabled: ! isEnabled];
  201472. }
  201473. bool Desktop::isScreenSaverEnabled() throw()
  201474. {
  201475. return ! [[UIApplication sharedApplication] isIdleTimerDisabled];
  201476. }
  201477. void juce_updateMultiMonitorInfo (Array <Rectangle <int> >& monitorCoords, const bool clipToWorkArea)
  201478. {
  201479. const ScopedAutoReleasePool pool;
  201480. monitorCoords.clear();
  201481. CGRect r = clipToWorkArea ? [[UIScreen mainScreen] applicationFrame]
  201482. : [[UIScreen mainScreen] bounds];
  201483. monitorCoords.add (Rectangle<int> ((int) r.origin.x,
  201484. (int) r.origin.y,
  201485. (int) r.size.width,
  201486. (int) r.size.height));
  201487. }
  201488. #endif
  201489. #endif
  201490. /*** End of inlined file: juce_iphone_MiscUtilities.mm ***/
  201491. #else
  201492. /*** Start of inlined file: juce_mac_MiscUtilities.mm ***/
  201493. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  201494. // compiled on its own).
  201495. #if JUCE_INCLUDED_FILE
  201496. ScopedAutoReleasePool::ScopedAutoReleasePool()
  201497. {
  201498. pool = [[NSAutoreleasePool alloc] init];
  201499. }
  201500. ScopedAutoReleasePool::~ScopedAutoReleasePool()
  201501. {
  201502. [((NSAutoreleasePool*) pool) release];
  201503. }
  201504. void PlatformUtilities::beep()
  201505. {
  201506. NSBeep();
  201507. }
  201508. void PlatformUtilities::addItemToDock (const File& file)
  201509. {
  201510. // check that it's not already there...
  201511. if (! juce_getOutputFromCommand ("defaults read com.apple.dock persistent-apps")
  201512. .containsIgnoreCase (file.getFullPathName()))
  201513. {
  201514. 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>"
  201515. + file.getFullPathName() + "</string><key>_CFURLStringType</key><integer>0</integer></dict></dict></dict>\"");
  201516. juce_runSystemCommand ("osascript -e \"tell application \\\"Dock\\\" to quit\"");
  201517. }
  201518. }
  201519. int PlatformUtilities::getOSXMinorVersionNumber()
  201520. {
  201521. SInt32 versionMinor = 0;
  201522. OSErr err = Gestalt (gestaltSystemVersionMinor, &versionMinor);
  201523. (void) err;
  201524. jassert (err == noErr);
  201525. return (int) versionMinor;
  201526. }
  201527. #if ! JUCE_ONLY_BUILD_CORE_LIBRARY
  201528. bool AlertWindow::showNativeDialogBox (const String& title,
  201529. const String& bodyText,
  201530. bool isOkCancel)
  201531. {
  201532. const ScopedAutoReleasePool pool;
  201533. return NSRunAlertPanel (juceStringToNS (title),
  201534. juceStringToNS (bodyText),
  201535. @"Ok",
  201536. isOkCancel ? @"Cancel" : nil,
  201537. nil) == NSAlertDefaultReturn;
  201538. }
  201539. bool DragAndDropContainer::performExternalDragDropOfFiles (const StringArray& files, const bool canMoveFiles)
  201540. {
  201541. if (files.size() == 0)
  201542. return false;
  201543. MouseInputSource* draggingSource = Desktop::getInstance().getDraggingMouseSource(0);
  201544. if (draggingSource == 0)
  201545. {
  201546. jassertfalse // This method must be called in response to a component's mouseDown or mouseDrag event!
  201547. return false;
  201548. }
  201549. Component* sourceComp = draggingSource->getComponentUnderMouse();
  201550. if (sourceComp == 0)
  201551. {
  201552. jassertfalse // This method must be called in response to a component's mouseDown or mouseDrag event!
  201553. return false;
  201554. }
  201555. const ScopedAutoReleasePool pool;
  201556. NSView* view = (NSView*) sourceComp->getWindowHandle();
  201557. if (view == 0)
  201558. return false;
  201559. NSPasteboard* pboard = [NSPasteboard pasteboardWithName: NSDragPboard];
  201560. [pboard declareTypes: [NSArray arrayWithObject: NSFilenamesPboardType]
  201561. owner: nil];
  201562. NSMutableArray* filesArray = [NSMutableArray arrayWithCapacity: 4];
  201563. for (int i = 0; i < files.size(); ++i)
  201564. [filesArray addObject: juceStringToNS (files[i])];
  201565. [pboard setPropertyList: filesArray
  201566. forType: NSFilenamesPboardType];
  201567. NSPoint dragPosition = [view convertPoint: [[[view window] currentEvent] locationInWindow]
  201568. fromView: nil];
  201569. dragPosition.x -= 16;
  201570. dragPosition.y -= 16;
  201571. [view dragImage: [[NSWorkspace sharedWorkspace] iconForFile: juceStringToNS (files[0])]
  201572. at: dragPosition
  201573. offset: NSMakeSize (0, 0)
  201574. event: [[view window] currentEvent]
  201575. pasteboard: pboard
  201576. source: view
  201577. slideBack: YES];
  201578. return true;
  201579. }
  201580. bool DragAndDropContainer::performExternalDragDropOfText (const String& text)
  201581. {
  201582. jassertfalse // not implemented!
  201583. return false;
  201584. }
  201585. bool Desktop::canUseSemiTransparentWindows() throw()
  201586. {
  201587. return true;
  201588. }
  201589. const Point<int> Desktop::getMousePosition()
  201590. {
  201591. const ScopedAutoReleasePool pool;
  201592. const NSPoint p ([NSEvent mouseLocation]);
  201593. return Point<int> (roundToInt (p.x), roundToInt ([[[NSScreen screens] objectAtIndex: 0] frame].size.height - p.y));
  201594. }
  201595. void Desktop::setMousePosition (const Point<int>& newPosition)
  201596. {
  201597. // this rubbish needs to be done around the warp call, to avoid causing a
  201598. // bizarre glitch..
  201599. CGAssociateMouseAndMouseCursorPosition (false);
  201600. CGWarpMouseCursorPosition (CGPointMake (newPosition.getX(), newPosition.getY()));
  201601. CGAssociateMouseAndMouseCursorPosition (true);
  201602. }
  201603. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  201604. class ScreenSaverDefeater : public Timer,
  201605. public DeletedAtShutdown
  201606. {
  201607. public:
  201608. ScreenSaverDefeater() throw()
  201609. {
  201610. startTimer (10000);
  201611. timerCallback();
  201612. }
  201613. ~ScreenSaverDefeater() {}
  201614. void timerCallback()
  201615. {
  201616. if (Process::isForegroundProcess())
  201617. UpdateSystemActivity (UsrActivity);
  201618. }
  201619. };
  201620. static ScreenSaverDefeater* screenSaverDefeater = 0;
  201621. void Desktop::setScreenSaverEnabled (const bool isEnabled) throw()
  201622. {
  201623. if (isEnabled)
  201624. {
  201625. deleteAndZero (screenSaverDefeater);
  201626. }
  201627. else if (screenSaverDefeater == 0)
  201628. {
  201629. screenSaverDefeater = new ScreenSaverDefeater();
  201630. }
  201631. }
  201632. bool Desktop::isScreenSaverEnabled() throw()
  201633. {
  201634. return screenSaverDefeater == 0;
  201635. }
  201636. #else
  201637. static IOPMAssertionID screenSaverDisablerID = 0;
  201638. void Desktop::setScreenSaverEnabled (const bool isEnabled) throw()
  201639. {
  201640. if (isEnabled)
  201641. {
  201642. if (screenSaverDisablerID != 0)
  201643. {
  201644. IOPMAssertionRelease (screenSaverDisablerID);
  201645. screenSaverDisablerID = 0;
  201646. }
  201647. }
  201648. else
  201649. {
  201650. if (screenSaverDisablerID == 0)
  201651. {
  201652. #if defined (MAC_OS_X_VERSION_10_6) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
  201653. IOPMAssertionCreateWithName (kIOPMAssertionTypeNoIdleSleep, kIOPMAssertionLevelOn,
  201654. CFSTR ("Juce"), &screenSaverDisablerID);
  201655. #else
  201656. IOPMAssertionCreate (kIOPMAssertionTypeNoIdleSleep, kIOPMAssertionLevelOn,
  201657. &screenSaverDisablerID);
  201658. #endif
  201659. }
  201660. }
  201661. }
  201662. bool Desktop::isScreenSaverEnabled() throw()
  201663. {
  201664. return screenSaverDisablerID == 0;
  201665. }
  201666. #endif
  201667. void juce_updateMultiMonitorInfo (Array <Rectangle<int> >& monitorCoords, const bool clipToWorkArea)
  201668. {
  201669. const ScopedAutoReleasePool pool;
  201670. monitorCoords.clear();
  201671. NSArray* screens = [NSScreen screens];
  201672. const CGFloat mainScreenBottom = [[[NSScreen screens] objectAtIndex: 0] frame].size.height;
  201673. for (unsigned int i = 0; i < [screens count]; ++i)
  201674. {
  201675. NSScreen* s = (NSScreen*) [screens objectAtIndex: i];
  201676. NSRect r = clipToWorkArea ? [s visibleFrame]
  201677. : [s frame];
  201678. monitorCoords.add (Rectangle<int> ((int) r.origin.x,
  201679. (int) (mainScreenBottom - (r.origin.y + r.size.height)),
  201680. (int) r.size.width,
  201681. (int) r.size.height));
  201682. }
  201683. jassert (monitorCoords.size() > 0);
  201684. }
  201685. #endif
  201686. #endif
  201687. /*** End of inlined file: juce_mac_MiscUtilities.mm ***/
  201688. #endif
  201689. /*** Start of inlined file: juce_mac_Debugging.mm ***/
  201690. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  201691. // compiled on its own).
  201692. #if JUCE_INCLUDED_FILE
  201693. void Logger::outputDebugString (const String& text) throw()
  201694. {
  201695. std::cerr << text << std::endl;
  201696. }
  201697. bool JUCE_PUBLIC_FUNCTION juce_isRunningUnderDebugger()
  201698. {
  201699. static char testResult = 0;
  201700. if (testResult == 0)
  201701. {
  201702. struct kinfo_proc info;
  201703. int m[] = { CTL_KERN, KERN_PROC, KERN_PROC_PID, getpid() };
  201704. size_t sz = sizeof (info);
  201705. sysctl (m, 4, &info, &sz, 0, 0);
  201706. testResult = ((info.kp_proc.p_flag & P_TRACED) != 0) ? 1 : -1;
  201707. }
  201708. return testResult > 0;
  201709. }
  201710. bool JUCE_CALLTYPE Process::isRunningUnderDebugger()
  201711. {
  201712. return juce_isRunningUnderDebugger();
  201713. }
  201714. #endif
  201715. /*** End of inlined file: juce_mac_Debugging.mm ***/
  201716. #if ! JUCE_ONLY_BUILD_CORE_LIBRARY
  201717. #if JUCE_IPHONE
  201718. /*** Start of inlined file: juce_mac_Fonts.mm ***/
  201719. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  201720. // compiled on its own).
  201721. #if JUCE_INCLUDED_FILE
  201722. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  201723. #define SUPPORT_10_4_FONTS 1
  201724. #define NEW_CGFONT_FUNCTIONS_UNAVAILABLE (CGFontCreateWithFontName == 0)
  201725. #if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_5
  201726. #define SUPPORT_ONLY_10_4_FONTS 1
  201727. #endif
  201728. END_JUCE_NAMESPACE
  201729. @interface NSFont (PrivateHack)
  201730. - (NSGlyph) _defaultGlyphForChar: (unichar) theChar;
  201731. @end
  201732. BEGIN_JUCE_NAMESPACE
  201733. #endif
  201734. class MacTypeface : public Typeface
  201735. {
  201736. public:
  201737. MacTypeface (const Font& font)
  201738. : Typeface (font.getTypefaceName())
  201739. {
  201740. const ScopedAutoReleasePool pool;
  201741. renderingTransform = CGAffineTransformIdentity;
  201742. bool needsItalicTransform = false;
  201743. #if JUCE_IPHONE
  201744. NSString* fontName = juceStringToNS (font.getTypefaceName());
  201745. if (font.isItalic() || font.isBold())
  201746. {
  201747. NSArray* familyFonts = [UIFont fontNamesForFamilyName: juceStringToNS (font.getTypefaceName())];
  201748. for (NSString* i in familyFonts)
  201749. {
  201750. const String fn (nsStringToJuce (i));
  201751. const String afterDash (fn.fromFirstOccurrenceOf (T("-"), false, false));
  201752. const bool probablyBold = afterDash.containsIgnoreCase (T("bold")) || fn.endsWithIgnoreCase (T("bold"));
  201753. const bool probablyItalic = afterDash.containsIgnoreCase (T("oblique"))
  201754. || afterDash.containsIgnoreCase (T("italic"))
  201755. || fn.endsWithIgnoreCase (T("oblique"))
  201756. || fn.endsWithIgnoreCase (T("italic"));
  201757. if (probablyBold == font.isBold()
  201758. && probablyItalic == font.isItalic())
  201759. {
  201760. fontName = i;
  201761. needsItalicTransform = false;
  201762. break;
  201763. }
  201764. else if (probablyBold && (! probablyItalic) && probablyBold == font.isBold())
  201765. {
  201766. fontName = i;
  201767. needsItalicTransform = true; // not ideal, so carry on in case we find a better one
  201768. }
  201769. }
  201770. if (needsItalicTransform)
  201771. renderingTransform.c = 0.15f;
  201772. }
  201773. fontRef = CGFontCreateWithFontName ((CFStringRef) fontName);
  201774. const int ascender = abs (CGFontGetAscent (fontRef));
  201775. const float totalHeight = ascender + abs (CGFontGetDescent (fontRef));
  201776. ascent = ascender / totalHeight;
  201777. unitsToHeightScaleFactor = 1.0f / totalHeight;
  201778. fontHeightToCGSizeFactor = CGFontGetUnitsPerEm (fontRef) / totalHeight;
  201779. #else
  201780. nsFont = [NSFont fontWithName: juceStringToNS (font.getTypefaceName()) size: 1024];
  201781. if (font.isItalic())
  201782. {
  201783. NSFont* newFont = [[NSFontManager sharedFontManager] convertFont: nsFont
  201784. toHaveTrait: NSItalicFontMask];
  201785. if (newFont == nsFont)
  201786. needsItalicTransform = true; // couldn't find a proper italic version, so fake it with a transform..
  201787. nsFont = newFont;
  201788. }
  201789. if (font.isBold())
  201790. nsFont = [[NSFontManager sharedFontManager] convertFont: nsFont toHaveTrait: NSBoldFontMask];
  201791. [nsFont retain];
  201792. ascent = fabsf ((float) [nsFont ascender]);
  201793. float totalSize = ascent + fabsf ((float) [nsFont descender]);
  201794. ascent /= totalSize;
  201795. pathTransform = AffineTransform::identity.scale (1.0f / totalSize, 1.0f / totalSize);
  201796. if (needsItalicTransform)
  201797. {
  201798. pathTransform = pathTransform.sheared (-0.15f, 0.0f);
  201799. renderingTransform.c = 0.15f;
  201800. }
  201801. #if SUPPORT_ONLY_10_4_FONTS
  201802. ATSFontRef atsFont = ATSFontFindFromName ((CFStringRef) [nsFont fontName], kATSOptionFlagsDefault);
  201803. if (atsFont == 0)
  201804. atsFont = ATSFontFindFromPostScriptName ((CFStringRef) [nsFont fontName], kATSOptionFlagsDefault);
  201805. fontRef = CGFontCreateWithPlatformFont ((void*) &atsFont);
  201806. const float totalHeight = fabsf ([nsFont ascender]) + fabsf([nsFont descender]);
  201807. unitsToHeightScaleFactor = 1.0f / totalHeight;
  201808. fontHeightToCGSizeFactor = 1024.0f / totalHeight;
  201809. #else
  201810. #if SUPPORT_10_4_FONTS
  201811. if (NEW_CGFONT_FUNCTIONS_UNAVAILABLE)
  201812. {
  201813. ATSFontRef atsFont = ATSFontFindFromName ((CFStringRef) [nsFont fontName], kATSOptionFlagsDefault);
  201814. if (atsFont == 0)
  201815. atsFont = ATSFontFindFromPostScriptName ((CFStringRef) [nsFont fontName], kATSOptionFlagsDefault);
  201816. fontRef = CGFontCreateWithPlatformFont ((void*) &atsFont);
  201817. const float totalHeight = fabsf ([nsFont ascender]) + fabsf([nsFont descender]);
  201818. unitsToHeightScaleFactor = 1.0f / totalHeight;
  201819. fontHeightToCGSizeFactor = 1024.0f / totalHeight;
  201820. }
  201821. else
  201822. #endif
  201823. {
  201824. fontRef = CGFontCreateWithFontName ((CFStringRef) [nsFont fontName]);
  201825. const int totalHeight = abs (CGFontGetAscent (fontRef)) + abs (CGFontGetDescent (fontRef));
  201826. unitsToHeightScaleFactor = 1.0f / totalHeight;
  201827. fontHeightToCGSizeFactor = CGFontGetUnitsPerEm (fontRef) / (float) totalHeight;
  201828. }
  201829. #endif
  201830. #endif
  201831. }
  201832. ~MacTypeface()
  201833. {
  201834. #if ! JUCE_IPHONE
  201835. [nsFont release];
  201836. #endif
  201837. if (fontRef != 0)
  201838. CGFontRelease (fontRef);
  201839. }
  201840. float getAscent() const
  201841. {
  201842. return ascent;
  201843. }
  201844. float getDescent() const
  201845. {
  201846. return 1.0f - ascent;
  201847. }
  201848. float getStringWidth (const String& text)
  201849. {
  201850. if (fontRef == 0 || text.isEmpty())
  201851. return 0;
  201852. const int length = text.length();
  201853. HeapBlock <CGGlyph> glyphs;
  201854. createGlyphsForString (text, length, glyphs);
  201855. float x = 0;
  201856. #if SUPPORT_ONLY_10_4_FONTS
  201857. HeapBlock <NSSize> advances (length);
  201858. [nsFont getAdvancements: advances forGlyphs: reinterpret_cast <NSGlyph*> (glyphs.getData()) count: length];
  201859. for (int i = 0; i < length; ++i)
  201860. x += advances[i].width;
  201861. #else
  201862. #if SUPPORT_10_4_FONTS
  201863. if (NEW_CGFONT_FUNCTIONS_UNAVAILABLE)
  201864. {
  201865. HeapBlock <NSSize> advances (length);
  201866. [nsFont getAdvancements: advances forGlyphs: reinterpret_cast<NSGlyph*> (glyphs.getData()) count: length];
  201867. for (int i = 0; i < length; ++i)
  201868. x += advances[i].width;
  201869. }
  201870. else
  201871. #endif
  201872. {
  201873. HeapBlock <int> advances (length);
  201874. if (CGFontGetGlyphAdvances (fontRef, glyphs, length, advances))
  201875. for (int i = 0; i < length; ++i)
  201876. x += advances[i];
  201877. }
  201878. #endif
  201879. return x * unitsToHeightScaleFactor;
  201880. }
  201881. void getGlyphPositions (const String& text, Array <int>& resultGlyphs, Array <float>& xOffsets)
  201882. {
  201883. xOffsets.add (0);
  201884. if (fontRef == 0 || text.isEmpty())
  201885. return;
  201886. const int length = text.length();
  201887. HeapBlock <CGGlyph> glyphs;
  201888. createGlyphsForString (text, length, glyphs);
  201889. #if SUPPORT_ONLY_10_4_FONTS
  201890. HeapBlock <NSSize> advances (length);
  201891. [nsFont getAdvancements: advances forGlyphs: reinterpret_cast <NSGlyph*> (glyphs.getData()) count: length];
  201892. int x = 0;
  201893. for (int i = 0; i < length; ++i)
  201894. {
  201895. x += advances[i].width;
  201896. xOffsets.add (x * unitsToHeightScaleFactor);
  201897. resultGlyphs.add (reinterpret_cast <NSGlyph*> (glyphs.getData())[i]);
  201898. }
  201899. #else
  201900. #if SUPPORT_10_4_FONTS
  201901. if (NEW_CGFONT_FUNCTIONS_UNAVAILABLE)
  201902. {
  201903. HeapBlock <NSSize> advances (length);
  201904. NSGlyph* const nsGlyphs = reinterpret_cast<NSGlyph*> (glyphs.getData());
  201905. [nsFont getAdvancements: advances forGlyphs: nsGlyphs count: length];
  201906. float x = 0;
  201907. for (int i = 0; i < length; ++i)
  201908. {
  201909. x += advances[i].width;
  201910. xOffsets.add (x * unitsToHeightScaleFactor);
  201911. resultGlyphs.add (nsGlyphs[i]);
  201912. }
  201913. }
  201914. else
  201915. #endif
  201916. {
  201917. HeapBlock <int> advances (length);
  201918. if (CGFontGetGlyphAdvances (fontRef, glyphs, length, advances))
  201919. {
  201920. int x = 0;
  201921. for (int i = 0; i < length; ++i)
  201922. {
  201923. x += advances [i];
  201924. xOffsets.add (x * unitsToHeightScaleFactor);
  201925. resultGlyphs.add (glyphs[i]);
  201926. }
  201927. }
  201928. }
  201929. #endif
  201930. }
  201931. bool getOutlineForGlyph (int glyphNumber, Path& path)
  201932. {
  201933. #if JUCE_IPHONE
  201934. return false;
  201935. #else
  201936. if (nsFont == 0)
  201937. return false;
  201938. // we might need to apply a transform to the path, so it mustn't have anything else in it
  201939. jassert (path.isEmpty());
  201940. const ScopedAutoReleasePool pool;
  201941. NSBezierPath* bez = [NSBezierPath bezierPath];
  201942. [bez moveToPoint: NSMakePoint (0, 0)];
  201943. [bez appendBezierPathWithGlyph: (NSGlyph) glyphNumber
  201944. inFont: nsFont];
  201945. for (int i = 0; i < [bez elementCount]; ++i)
  201946. {
  201947. NSPoint p[3];
  201948. switch ([bez elementAtIndex: i associatedPoints: p])
  201949. {
  201950. case NSMoveToBezierPathElement:
  201951. path.startNewSubPath ((float) p[0].x, (float) -p[0].y);
  201952. break;
  201953. case NSLineToBezierPathElement:
  201954. path.lineTo ((float) p[0].x, (float) -p[0].y);
  201955. break;
  201956. case NSCurveToBezierPathElement:
  201957. 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);
  201958. break;
  201959. case NSClosePathBezierPathElement:
  201960. path.closeSubPath();
  201961. break;
  201962. default:
  201963. jassertfalse
  201964. break;
  201965. }
  201966. }
  201967. path.applyTransform (pathTransform);
  201968. return true;
  201969. #endif
  201970. }
  201971. juce_UseDebuggingNewOperator
  201972. CGFontRef fontRef;
  201973. float fontHeightToCGSizeFactor;
  201974. CGAffineTransform renderingTransform;
  201975. private:
  201976. float ascent, unitsToHeightScaleFactor;
  201977. #if JUCE_IPHONE
  201978. #else
  201979. NSFont* nsFont;
  201980. AffineTransform pathTransform;
  201981. #endif
  201982. void createGlyphsForString (const juce_wchar* const text, const int length, HeapBlock <CGGlyph>& glyphs)
  201983. {
  201984. #if SUPPORT_10_4_FONTS
  201985. #if ! SUPPORT_ONLY_10_4_FONTS
  201986. if (NEW_CGFONT_FUNCTIONS_UNAVAILABLE)
  201987. #endif
  201988. {
  201989. glyphs.malloc (sizeof (NSGlyph) * length, 1);
  201990. NSGlyph* const nsGlyphs = reinterpret_cast<NSGlyph*> (glyphs.getData());
  201991. for (int i = 0; i < length; ++i)
  201992. nsGlyphs[i] = (NSGlyph) [nsFont _defaultGlyphForChar: text[i]];
  201993. return;
  201994. }
  201995. #endif
  201996. #if ! SUPPORT_ONLY_10_4_FONTS
  201997. if (charToGlyphMapper == 0)
  201998. charToGlyphMapper = new CharToGlyphMapper (fontRef);
  201999. glyphs.malloc (length);
  202000. for (int i = 0; i < length; ++i)
  202001. glyphs[i] = (CGGlyph) charToGlyphMapper->getGlyphForCharacter (text[i]);
  202002. #endif
  202003. }
  202004. #if ! SUPPORT_ONLY_10_4_FONTS
  202005. // Reads a CGFontRef's character map table to convert unicode into glyph numbers
  202006. class CharToGlyphMapper
  202007. {
  202008. public:
  202009. CharToGlyphMapper (CGFontRef fontRef)
  202010. : segCount (0), endCode (0), startCode (0), idDelta (0),
  202011. idRangeOffset (0), glyphIndexes (0)
  202012. {
  202013. CFDataRef cmapTable = CGFontCopyTableForTag (fontRef, 'cmap');
  202014. if (cmapTable != 0)
  202015. {
  202016. const int numSubtables = getValue16 (cmapTable, 2);
  202017. for (int i = 0; i < numSubtables; ++i)
  202018. {
  202019. if (getValue16 (cmapTable, i * 8 + 4) == 0) // check for platform ID of 0
  202020. {
  202021. const int offset = getValue32 (cmapTable, i * 8 + 8);
  202022. if (getValue16 (cmapTable, offset) == 4) // check that it's format 4..
  202023. {
  202024. const int length = getValue16 (cmapTable, offset + 2);
  202025. const int segCountX2 = getValue16 (cmapTable, offset + 6);
  202026. segCount = segCountX2 / 2;
  202027. const int endCodeOffset = offset + 14;
  202028. const int startCodeOffset = endCodeOffset + 2 + segCountX2;
  202029. const int idDeltaOffset = startCodeOffset + segCountX2;
  202030. const int idRangeOffsetOffset = idDeltaOffset + segCountX2;
  202031. const int glyphIndexesOffset = idRangeOffsetOffset + segCountX2;
  202032. endCode = CFDataCreate (kCFAllocatorDefault, CFDataGetBytePtr (cmapTable) + endCodeOffset, segCountX2);
  202033. startCode = CFDataCreate (kCFAllocatorDefault, CFDataGetBytePtr (cmapTable) + startCodeOffset, segCountX2);
  202034. idDelta = CFDataCreate (kCFAllocatorDefault, CFDataGetBytePtr (cmapTable) + idDeltaOffset, segCountX2);
  202035. idRangeOffset = CFDataCreate (kCFAllocatorDefault, CFDataGetBytePtr (cmapTable) + idRangeOffsetOffset, segCountX2);
  202036. glyphIndexes = CFDataCreate (kCFAllocatorDefault, CFDataGetBytePtr (cmapTable) + glyphIndexesOffset, offset + length - glyphIndexesOffset);
  202037. }
  202038. break;
  202039. }
  202040. }
  202041. CFRelease (cmapTable);
  202042. }
  202043. }
  202044. ~CharToGlyphMapper()
  202045. {
  202046. if (endCode != 0)
  202047. {
  202048. CFRelease (endCode);
  202049. CFRelease (startCode);
  202050. CFRelease (idDelta);
  202051. CFRelease (idRangeOffset);
  202052. CFRelease (glyphIndexes);
  202053. }
  202054. }
  202055. int getGlyphForCharacter (const juce_wchar c) const
  202056. {
  202057. for (int i = 0; i < segCount; ++i)
  202058. {
  202059. if (getValue16 (endCode, i * 2) >= c)
  202060. {
  202061. const int start = getValue16 (startCode, i * 2);
  202062. if (start > c)
  202063. break;
  202064. const int delta = getValue16 (idDelta, i * 2);
  202065. const int rangeOffset = getValue16 (idRangeOffset, i * 2);
  202066. if (rangeOffset == 0)
  202067. return delta + c;
  202068. else
  202069. return getValue16 (glyphIndexes, 2 * ((rangeOffset / 2) + (c - start) - (segCount - i)));
  202070. }
  202071. }
  202072. // If we failed to find it "properly", this dodgy fall-back seems to do the trick for most fonts!
  202073. return jmax (-1, c - 29);
  202074. }
  202075. private:
  202076. int segCount;
  202077. CFDataRef endCode, startCode, idDelta, idRangeOffset, glyphIndexes;
  202078. static uint16 getValue16 (CFDataRef data, const int index)
  202079. {
  202080. return CFSwapInt16BigToHost (*(UInt16*) (CFDataGetBytePtr (data) + index));
  202081. }
  202082. static uint32 getValue32 (CFDataRef data, const int index)
  202083. {
  202084. return CFSwapInt32BigToHost (*(UInt32*) (CFDataGetBytePtr (data) + index));
  202085. }
  202086. };
  202087. ScopedPointer <CharToGlyphMapper> charToGlyphMapper;
  202088. #endif
  202089. MacTypeface (const MacTypeface&);
  202090. MacTypeface& operator= (const MacTypeface&);
  202091. };
  202092. const Typeface::Ptr Typeface::createSystemTypefaceFor (const Font& font)
  202093. {
  202094. return new MacTypeface (font);
  202095. }
  202096. const StringArray Font::findAllTypefaceNames() throw()
  202097. {
  202098. StringArray names;
  202099. const ScopedAutoReleasePool pool;
  202100. #if JUCE_IPHONE
  202101. NSArray* fonts = [UIFont familyNames];
  202102. #else
  202103. NSArray* fonts = [[NSFontManager sharedFontManager] availableFontFamilies];
  202104. #endif
  202105. for (unsigned int i = 0; i < [fonts count]; ++i)
  202106. names.add (nsStringToJuce ((NSString*) [fonts objectAtIndex: i]));
  202107. names.sort (true);
  202108. return names;
  202109. }
  202110. void Font::getPlatformDefaultFontNames (String& defaultSans, String& defaultSerif, String& defaultFixed) throw()
  202111. {
  202112. #if JUCE_IPHONE
  202113. defaultSans = "Helvetica";
  202114. defaultSerif = "Times New Roman";
  202115. defaultFixed = "Courier New";
  202116. #else
  202117. defaultSans = "Lucida Grande";
  202118. defaultSerif = "Times New Roman";
  202119. defaultFixed = "Monaco";
  202120. #endif
  202121. }
  202122. #endif
  202123. /*** End of inlined file: juce_mac_Fonts.mm ***/
  202124. /*** Start of inlined file: juce_mac_CoreGraphicsContext.mm ***/
  202125. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  202126. // compiled on its own).
  202127. #if JUCE_INCLUDED_FILE
  202128. class CoreGraphicsImage : public Image
  202129. {
  202130. public:
  202131. CoreGraphicsImage (const PixelFormat format_,
  202132. const int imageWidth_,
  202133. const int imageHeight_,
  202134. const bool clearImage)
  202135. : Image (format_, imageWidth_, imageHeight_, clearImage)
  202136. {
  202137. CGColorSpaceRef colourSpace = (format == Image::SingleChannel) ? CGColorSpaceCreateDeviceGray()
  202138. : CGColorSpaceCreateDeviceRGB();
  202139. context = CGBitmapContextCreate (imageData, imageWidth, imageHeight, 8, lineStride,
  202140. colourSpace, getCGImageFlags (*this));
  202141. CGColorSpaceRelease (colourSpace);
  202142. }
  202143. ~CoreGraphicsImage()
  202144. {
  202145. CGContextRelease (context);
  202146. }
  202147. LowLevelGraphicsContext* createLowLevelContext();
  202148. static CGImageRef createImage (const Image& juceImage, const bool forAlpha, CGColorSpaceRef colourSpace)
  202149. {
  202150. const CoreGraphicsImage* nativeImage = dynamic_cast <const CoreGraphicsImage*> (&juceImage);
  202151. if (nativeImage != 0 && (juceImage.getFormat() == Image::SingleChannel || ! forAlpha))
  202152. {
  202153. return CGBitmapContextCreateImage (nativeImage->context);
  202154. }
  202155. else
  202156. {
  202157. const Image::BitmapData srcData (juceImage, 0, 0, juceImage.getWidth(), juceImage.getHeight());
  202158. CGDataProviderRef provider = CGDataProviderCreateWithData (0, srcData.data, srcData.lineStride * srcData.height, 0);
  202159. CGImageRef imageRef = CGImageCreate (srcData.width, srcData.height,
  202160. 8, srcData.pixelStride * 8, srcData.lineStride,
  202161. colourSpace, getCGImageFlags (juceImage), provider,
  202162. 0, true, kCGRenderingIntentDefault);
  202163. CGDataProviderRelease (provider);
  202164. return imageRef;
  202165. }
  202166. }
  202167. #if JUCE_MAC
  202168. static NSImage* createNSImage (const Image& image)
  202169. {
  202170. const ScopedAutoReleasePool pool;
  202171. NSImage* im = [[NSImage alloc] init];
  202172. [im setSize: NSMakeSize (image.getWidth(), image.getHeight())];
  202173. [im lockFocus];
  202174. CGColorSpaceRef colourSpace = CGColorSpaceCreateDeviceRGB();
  202175. CGImageRef imageRef = createImage (image, false, colourSpace);
  202176. CGColorSpaceRelease (colourSpace);
  202177. CGContextRef cg = (CGContextRef) [[NSGraphicsContext currentContext] graphicsPort];
  202178. CGContextDrawImage (cg, CGRectMake (0, 0, image.getWidth(), image.getHeight()), imageRef);
  202179. CGImageRelease (imageRef);
  202180. [im unlockFocus];
  202181. return im;
  202182. }
  202183. #endif
  202184. CGContextRef context;
  202185. private:
  202186. static CGBitmapInfo getCGImageFlags (const Image& image)
  202187. {
  202188. #if JUCE_BIG_ENDIAN
  202189. return image.getFormat() == Image::ARGB ? (kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Big) : kCGBitmapByteOrderDefault;
  202190. #else
  202191. return image.getFormat() == Image::ARGB ? (kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Little) : kCGBitmapByteOrderDefault;
  202192. #endif
  202193. }
  202194. };
  202195. Image* Image::createNativeImage (const PixelFormat format, const int imageWidth, const int imageHeight, const bool clearImage)
  202196. {
  202197. #if USE_COREGRAPHICS_RENDERING
  202198. return new CoreGraphicsImage (format == RGB ? ARGB : format, imageWidth, imageHeight, clearImage);
  202199. #else
  202200. return new Image (format, imageWidth, imageHeight, clearImage);
  202201. #endif
  202202. }
  202203. class CoreGraphicsContext : public LowLevelGraphicsContext
  202204. {
  202205. public:
  202206. CoreGraphicsContext (CGContextRef context_, const float flipHeight_)
  202207. : context (context_),
  202208. flipHeight (flipHeight_),
  202209. state (new SavedState()),
  202210. numGradientLookupEntries (0)
  202211. {
  202212. CGContextRetain (context);
  202213. CGContextSaveGState(context);
  202214. CGContextSetShouldSmoothFonts (context, true);
  202215. CGContextSetShouldAntialias (context, true);
  202216. CGContextSetBlendMode (context, kCGBlendModeNormal);
  202217. rgbColourSpace = CGColorSpaceCreateDeviceRGB();
  202218. greyColourSpace = CGColorSpaceCreateDeviceGray();
  202219. gradientCallbacks.version = 0;
  202220. gradientCallbacks.evaluate = gradientCallback;
  202221. gradientCallbacks.releaseInfo = 0;
  202222. setFont (Font());
  202223. }
  202224. ~CoreGraphicsContext()
  202225. {
  202226. CGContextRestoreGState (context);
  202227. CGContextRelease (context);
  202228. CGColorSpaceRelease (rgbColourSpace);
  202229. CGColorSpaceRelease (greyColourSpace);
  202230. }
  202231. bool isVectorDevice() const { return false; }
  202232. void setOrigin (int x, int y)
  202233. {
  202234. CGContextTranslateCTM (context, x, -y);
  202235. }
  202236. bool clipToRectangle (const Rectangle<int>& r)
  202237. {
  202238. CGContextClipToRect (context, CGRectMake (r.getX(), flipHeight - r.getBottom(), r.getWidth(), r.getHeight()));
  202239. return ! isClipEmpty();
  202240. }
  202241. bool clipToRectangleList (const RectangleList& clipRegion)
  202242. {
  202243. if (clipRegion.isEmpty())
  202244. {
  202245. CGContextClipToRect (context, CGRectMake (0, 0, 0, 0));
  202246. return false;
  202247. }
  202248. else
  202249. {
  202250. const int numRects = clipRegion.getNumRectangles();
  202251. HeapBlock <CGRect> rects (numRects);
  202252. for (int i = 0; i < numRects; ++i)
  202253. {
  202254. const Rectangle<int>& r = clipRegion.getRectangle(i);
  202255. rects[i] = CGRectMake (r.getX(), flipHeight - r.getBottom(), r.getWidth(), r.getHeight());
  202256. }
  202257. CGContextClipToRects (context, rects, numRects);
  202258. return ! isClipEmpty();
  202259. }
  202260. }
  202261. void excludeClipRectangle (const Rectangle<int>& r)
  202262. {
  202263. RectangleList remaining (getClipBounds());
  202264. remaining.subtract (r);
  202265. clipToRectangleList (remaining);
  202266. }
  202267. void clipToPath (const Path& path, const AffineTransform& transform)
  202268. {
  202269. createPath (path, transform);
  202270. CGContextClip (context);
  202271. }
  202272. void clipToImageAlpha (const Image& sourceImage, const Rectangle<int>& srcClip, const AffineTransform& transform)
  202273. {
  202274. if (! transform.isSingularity())
  202275. {
  202276. Image* singleChannelImage = createAlphaChannelImage (sourceImage);
  202277. CGImageRef image = CoreGraphicsImage::createImage (*singleChannelImage, true, greyColourSpace);
  202278. flip();
  202279. AffineTransform t (AffineTransform::scale (1.0f, -1.0f).translated (0, sourceImage.getHeight()).followedBy (transform));
  202280. applyTransform (t);
  202281. CGRect r = CGRectMake (0, 0, sourceImage.getWidth(), sourceImage.getHeight());
  202282. CGContextClipToMask (context, r, image);
  202283. applyTransform (t.inverted());
  202284. flip();
  202285. CGImageRelease (image);
  202286. deleteAlphaChannelImage (sourceImage, singleChannelImage);
  202287. }
  202288. }
  202289. bool clipRegionIntersects (const Rectangle<int>& r)
  202290. {
  202291. return getClipBounds().intersects (r);
  202292. }
  202293. const Rectangle<int> getClipBounds() const
  202294. {
  202295. CGRect bounds = CGRectIntegral (CGContextGetClipBoundingBox (context));
  202296. return Rectangle<int> (roundToInt (bounds.origin.x),
  202297. roundToInt (flipHeight - (bounds.origin.y + bounds.size.height)),
  202298. roundToInt (bounds.size.width),
  202299. roundToInt (bounds.size.height));
  202300. }
  202301. bool isClipEmpty() const
  202302. {
  202303. return CGRectIsEmpty (CGContextGetClipBoundingBox (context));
  202304. }
  202305. void saveState()
  202306. {
  202307. CGContextSaveGState (context);
  202308. stateStack.add (new SavedState (*state));
  202309. }
  202310. void restoreState()
  202311. {
  202312. CGContextRestoreGState (context);
  202313. SavedState* const top = stateStack.getLast();
  202314. if (top != 0)
  202315. {
  202316. state = top;
  202317. stateStack.removeLast (1, false);
  202318. }
  202319. else
  202320. {
  202321. jassertfalse // trying to pop with an empty stack!
  202322. }
  202323. }
  202324. void setFill (const FillType& fillType)
  202325. {
  202326. state->fillType = fillType;
  202327. if (fillType.isColour())
  202328. {
  202329. CGContextSetRGBFillColor (context, fillType.colour.getFloatRed(), fillType.colour.getFloatGreen(),
  202330. fillType.colour.getFloatBlue(), fillType.colour.getFloatAlpha());
  202331. CGContextSetAlpha (context, 1.0f);
  202332. }
  202333. }
  202334. void setOpacity (float newOpacity)
  202335. {
  202336. state->fillType.setOpacity (newOpacity);
  202337. setFill (state->fillType);
  202338. }
  202339. void setInterpolationQuality (Graphics::ResamplingQuality quality)
  202340. {
  202341. CGContextSetInterpolationQuality (context, quality == Graphics::lowResamplingQuality
  202342. ? kCGInterpolationLow
  202343. : kCGInterpolationHigh);
  202344. }
  202345. void fillRect (const Rectangle<int>& r, const bool replaceExistingContents)
  202346. {
  202347. CGRect cgRect = CGRectMake (r.getX(), flipHeight - r.getBottom(), r.getWidth(), r.getHeight());
  202348. if (replaceExistingContents)
  202349. {
  202350. #if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_5
  202351. CGContextClearRect (context, cgRect);
  202352. #else
  202353. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  202354. if (CGContextDrawLinearGradient == 0) // (just a way of checking whether we're running in 10.5 or later)
  202355. CGContextClearRect (context, cgRect);
  202356. else
  202357. #endif
  202358. CGContextSetBlendMode (context, kCGBlendModeCopy);
  202359. #endif
  202360. fillRect (r, false);
  202361. CGContextSetBlendMode (context, kCGBlendModeNormal);
  202362. }
  202363. else
  202364. {
  202365. if (state->fillType.isColour())
  202366. {
  202367. CGContextFillRect (context, cgRect);
  202368. }
  202369. else if (state->fillType.isGradient())
  202370. {
  202371. CGContextSaveGState (context);
  202372. CGContextClipToRect (context, cgRect);
  202373. drawGradient();
  202374. CGContextRestoreGState (context);
  202375. }
  202376. else
  202377. {
  202378. CGContextSaveGState (context);
  202379. CGContextClipToRect (context, cgRect);
  202380. drawImage (*(state->fillType.image), state->fillType.image->getBounds(), state->fillType.transform, true);
  202381. CGContextRestoreGState (context);
  202382. }
  202383. }
  202384. }
  202385. void fillPath (const Path& path, const AffineTransform& transform)
  202386. {
  202387. CGContextSaveGState (context);
  202388. if (state->fillType.isColour())
  202389. {
  202390. flip();
  202391. applyTransform (transform);
  202392. createPath (path);
  202393. if (path.isUsingNonZeroWinding())
  202394. CGContextFillPath (context);
  202395. else
  202396. CGContextEOFillPath (context);
  202397. }
  202398. else
  202399. {
  202400. createPath (path, transform);
  202401. if (path.isUsingNonZeroWinding())
  202402. CGContextClip (context);
  202403. else
  202404. CGContextEOClip (context);
  202405. if (state->fillType.isGradient())
  202406. drawGradient();
  202407. else
  202408. drawImage (*(state->fillType.image), state->fillType.image->getBounds(), state->fillType.transform, true);
  202409. }
  202410. CGContextRestoreGState (context);
  202411. }
  202412. void drawImage (const Image& sourceImage, const Rectangle<int>& srcClip,
  202413. const AffineTransform& transform, const bool fillEntireClipAsTiles)
  202414. {
  202415. jassert (sourceImage.getBounds().contains (srcClip));
  202416. CGImageRef fullImage = CoreGraphicsImage::createImage (sourceImage, false, rgbColourSpace);
  202417. CGImageRef image = fullImage;
  202418. if (srcClip != sourceImage.getBounds())
  202419. {
  202420. image = CGImageCreateWithImageInRect (fullImage, CGRectMake (srcClip.getX(), srcClip.getY(),
  202421. srcClip.getWidth(), srcClip.getHeight()));
  202422. CGImageRelease (fullImage);
  202423. }
  202424. CGContextSaveGState (context);
  202425. CGContextSetAlpha (context, state->fillType.getOpacity());
  202426. flip();
  202427. applyTransform (AffineTransform::scale (1.0f, -1.0f).translated (0, srcClip.getHeight()).followedBy (transform));
  202428. CGRect imageRect = CGRectMake (0, 0, srcClip.getWidth(), srcClip.getHeight());
  202429. if (fillEntireClipAsTiles)
  202430. {
  202431. #if JUCE_IPHONE || (MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5)
  202432. CGContextDrawTiledImage (context, imageRect, image);
  202433. #else
  202434. #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
  202435. // There's a bug in CGContextDrawTiledImage that makes it incredibly slow
  202436. // if it's doing a transformation - it's quicker to just draw lots of images manually
  202437. if (CGContextDrawTiledImage != 0 && transform.isOnlyTranslation())
  202438. CGContextDrawTiledImage (context, imageRect, image);
  202439. else
  202440. #endif
  202441. {
  202442. // Fallback to manually doing a tiled fill on 10.4
  202443. CGRect clip = CGRectIntegral (CGContextGetClipBoundingBox (context));
  202444. const int iw = srcClip.getWidth();
  202445. const int ih = srcClip.getHeight();
  202446. int x = 0, y = 0;
  202447. while (x > clip.origin.x) x -= iw;
  202448. while (y > clip.origin.y) y -= ih;
  202449. const int right = (int) (clip.origin.x + clip.size.width);
  202450. const int bottom = (int) (clip.origin.y + clip.size.height);
  202451. while (y < bottom)
  202452. {
  202453. for (int x2 = x; x2 < right; x2 += iw)
  202454. CGContextDrawImage (context, CGRectMake (x2, y, iw, ih), image);
  202455. y += ih;
  202456. }
  202457. }
  202458. #endif
  202459. }
  202460. else
  202461. {
  202462. CGContextDrawImage (context, imageRect, image);
  202463. }
  202464. CGImageRelease (image); // (This causes a memory bug in iPhone sim 3.0 - try upgrading to a later version if you hit this)
  202465. CGContextRestoreGState (context);
  202466. }
  202467. void drawLine (double x1, double y1, double x2, double y2)
  202468. {
  202469. CGContextSetLineCap (context, kCGLineCapSquare);
  202470. CGContextSetLineWidth (context, 1.0f);
  202471. CGContextSetRGBStrokeColor (context,
  202472. state->fillType.colour.getFloatRed(), state->fillType.colour.getFloatGreen(),
  202473. state->fillType.colour.getFloatBlue(), state->fillType.colour.getFloatAlpha());
  202474. CGPoint line[] = { { (CGFloat) x1, flipHeight - (CGFloat) y1 },
  202475. { (CGFloat) x2, flipHeight - (CGFloat) y2 } };
  202476. CGContextStrokeLineSegments (context, line, 1);
  202477. }
  202478. void drawVerticalLine (const int x, double top, double bottom)
  202479. {
  202480. #if MAC_OS_X_VERSION_MIN_REQUIRED > MAC_OS_X_VERSION_10_5
  202481. CGContextFillRect (context, CGRectMake (x, flipHeight - (float) bottom, 1.0f, (float) (bottom - top)));
  202482. #else
  202483. // On Leopard, unless both co-ordinates are non-integer, it disables anti-aliasing, so nudge
  202484. // the x co-ord slightly to trick it..
  202485. CGContextFillRect (context, CGRectMake (x + 1.0f / 256.0f, flipHeight - (float) bottom, 1.0f + 1.0f / 256.0f, (float) (bottom - top)));
  202486. #endif
  202487. }
  202488. void drawHorizontalLine (const int y, double left, double right)
  202489. {
  202490. #if MAC_OS_X_VERSION_MIN_REQUIRED > MAC_OS_X_VERSION_10_5
  202491. CGContextFillRect (context, CGRectMake ((float) left, flipHeight - (y + 1.0f), (float) (right - left), 1.0f));
  202492. #else
  202493. // On Leopard, unless both co-ordinates are non-integer, it disables anti-aliasing, so nudge
  202494. // the x co-ord slightly to trick it..
  202495. CGContextFillRect (context, CGRectMake ((float) left, flipHeight - (y + (1.0f + 1.0f / 256.0f)), (float) (right - left), 1.0f + 1.0f / 256.0f));
  202496. #endif
  202497. }
  202498. void setFont (const Font& newFont)
  202499. {
  202500. if (state->font != newFont)
  202501. {
  202502. state->fontRef = 0;
  202503. state->font = newFont;
  202504. MacTypeface* mf = dynamic_cast <MacTypeface*> ((Typeface*) state->font.getTypeface());
  202505. if (mf != 0)
  202506. {
  202507. state->fontRef = mf->fontRef;
  202508. CGContextSetFont (context, state->fontRef);
  202509. CGContextSetFontSize (context, state->font.getHeight() * mf->fontHeightToCGSizeFactor);
  202510. state->fontTransform = mf->renderingTransform;
  202511. state->fontTransform.a *= state->font.getHorizontalScale();
  202512. CGContextSetTextMatrix (context, state->fontTransform);
  202513. }
  202514. }
  202515. }
  202516. const Font getFont()
  202517. {
  202518. return state->font;
  202519. }
  202520. void drawGlyph (int glyphNumber, const AffineTransform& transform)
  202521. {
  202522. if (state->fontRef != 0 && state->fillType.isColour())
  202523. {
  202524. if (transform.isOnlyTranslation())
  202525. {
  202526. CGGlyph g = glyphNumber;
  202527. CGContextShowGlyphsAtPoint (context, transform.getTranslationX(),
  202528. flipHeight - roundToInt (transform.getTranslationY()), &g, 1);
  202529. }
  202530. else
  202531. {
  202532. CGContextSaveGState (context);
  202533. flip();
  202534. applyTransform (transform);
  202535. CGAffineTransform t = state->fontTransform;
  202536. t.d = -t.d;
  202537. CGContextSetTextMatrix (context, t);
  202538. CGGlyph g = glyphNumber;
  202539. CGContextShowGlyphsAtPoint (context, 0, 0, &g, 1);
  202540. CGContextSetTextMatrix (context, state->fontTransform);
  202541. CGContextRestoreGState (context);
  202542. }
  202543. }
  202544. else
  202545. {
  202546. Path p;
  202547. Font& f = state->font;
  202548. f.getTypeface()->getOutlineForGlyph (glyphNumber, p);
  202549. fillPath (p, AffineTransform::scale (f.getHeight() * f.getHorizontalScale(), f.getHeight())
  202550. .followedBy (transform));
  202551. }
  202552. }
  202553. private:
  202554. CGContextRef context;
  202555. const CGFloat flipHeight;
  202556. CGColorSpaceRef rgbColourSpace, greyColourSpace;
  202557. CGFunctionCallbacks gradientCallbacks;
  202558. struct SavedState
  202559. {
  202560. SavedState()
  202561. : font (1.0f), fontRef (0), fontTransform (CGAffineTransformIdentity)
  202562. {
  202563. }
  202564. SavedState (const SavedState& other)
  202565. : fillType (other.fillType), font (other.font), fontRef (other.fontRef),
  202566. fontTransform (other.fontTransform)
  202567. {
  202568. }
  202569. ~SavedState()
  202570. {
  202571. }
  202572. FillType fillType;
  202573. Font font;
  202574. CGFontRef fontRef;
  202575. CGAffineTransform fontTransform;
  202576. };
  202577. ScopedPointer <SavedState> state;
  202578. OwnedArray <SavedState> stateStack;
  202579. HeapBlock <PixelARGB> gradientLookupTable;
  202580. int numGradientLookupEntries;
  202581. static void gradientCallback (void* info, const CGFloat* inData, CGFloat* outData)
  202582. {
  202583. const CoreGraphicsContext* const g = (const CoreGraphicsContext*) info;
  202584. const int index = roundToInt (g->numGradientLookupEntries * inData[0]);
  202585. PixelARGB colour (g->gradientLookupTable [jlimit (0, g->numGradientLookupEntries, index)]);
  202586. colour.unpremultiply();
  202587. outData[0] = colour.getRed() / 255.0f;
  202588. outData[1] = colour.getGreen() / 255.0f;
  202589. outData[2] = colour.getBlue() / 255.0f;
  202590. outData[3] = colour.getAlpha() / 255.0f;
  202591. }
  202592. CGShadingRef createGradient (const AffineTransform& transform, ColourGradient gradient)
  202593. {
  202594. numGradientLookupEntries = gradient.createLookupTable (transform, gradientLookupTable);
  202595. --numGradientLookupEntries;
  202596. CGShadingRef result = 0;
  202597. CGFunctionRef function = CGFunctionCreate ((void*) this, 1, 0, 4, 0, &gradientCallbacks);
  202598. CGPoint p1 (CGPointMake (gradient.x1, gradient.y1));
  202599. if (gradient.isRadial)
  202600. {
  202601. result = CGShadingCreateRadial (rgbColourSpace, p1, 0,
  202602. p1, hypotf (gradient.x1 - gradient.x2, gradient.y1 - gradient.y2),
  202603. function, true, true);
  202604. }
  202605. else
  202606. {
  202607. result = CGShadingCreateAxial (rgbColourSpace, p1,
  202608. CGPointMake (gradient.x2, gradient.y2),
  202609. function, true, true);
  202610. }
  202611. CGFunctionRelease (function);
  202612. return result;
  202613. }
  202614. void drawGradient()
  202615. {
  202616. flip();
  202617. applyTransform (state->fillType.transform);
  202618. CGContextSetInterpolationQuality (context, kCGInterpolationDefault); // (This is required for 10.4, where there's a crash if
  202619. // you draw a gradient with high quality interp enabled).
  202620. CGShadingRef shading = createGradient (state->fillType.transform, *(state->fillType.gradient));
  202621. CGContextSetAlpha (context, state->fillType.getOpacity());
  202622. CGContextDrawShading (context, shading);
  202623. CGShadingRelease (shading);
  202624. }
  202625. void createPath (const Path& path) const
  202626. {
  202627. CGContextBeginPath (context);
  202628. Path::Iterator i (path);
  202629. while (i.next())
  202630. {
  202631. switch (i.elementType)
  202632. {
  202633. case Path::Iterator::startNewSubPath:
  202634. CGContextMoveToPoint (context, i.x1, i.y1);
  202635. break;
  202636. case Path::Iterator::lineTo:
  202637. CGContextAddLineToPoint (context, i.x1, i.y1);
  202638. break;
  202639. case Path::Iterator::quadraticTo:
  202640. CGContextAddQuadCurveToPoint (context, i.x1, i.y1, i.x2, i.y2);
  202641. break;
  202642. case Path::Iterator::cubicTo:
  202643. CGContextAddCurveToPoint (context, i.x1, i.y1, i.x2, i.y2, i.x3, i.y3);
  202644. break;
  202645. case Path::Iterator::closePath:
  202646. CGContextClosePath (context); break;
  202647. default:
  202648. jassertfalse
  202649. break;
  202650. }
  202651. }
  202652. }
  202653. void createPath (const Path& path, const AffineTransform& transform) const
  202654. {
  202655. CGContextBeginPath (context);
  202656. Path::Iterator i (path);
  202657. while (i.next())
  202658. {
  202659. switch (i.elementType)
  202660. {
  202661. case Path::Iterator::startNewSubPath:
  202662. transform.transformPoint (i.x1, i.y1);
  202663. CGContextMoveToPoint (context, i.x1, flipHeight - i.y1);
  202664. break;
  202665. case Path::Iterator::lineTo:
  202666. transform.transformPoint (i.x1, i.y1);
  202667. CGContextAddLineToPoint (context, i.x1, flipHeight - i.y1);
  202668. break;
  202669. case Path::Iterator::quadraticTo:
  202670. transform.transformPoint (i.x1, i.y1);
  202671. transform.transformPoint (i.x2, i.y2);
  202672. CGContextAddQuadCurveToPoint (context, i.x1, flipHeight - i.y1, i.x2, flipHeight - i.y2);
  202673. break;
  202674. case Path::Iterator::cubicTo:
  202675. transform.transformPoint (i.x1, i.y1);
  202676. transform.transformPoint (i.x2, i.y2);
  202677. transform.transformPoint (i.x3, i.y3);
  202678. CGContextAddCurveToPoint (context, i.x1, flipHeight - i.y1, i.x2, flipHeight - i.y2, i.x3, flipHeight - i.y3);
  202679. break;
  202680. case Path::Iterator::closePath:
  202681. CGContextClosePath (context); break;
  202682. default:
  202683. jassertfalse
  202684. break;
  202685. }
  202686. }
  202687. }
  202688. static Image* createAlphaChannelImage (const Image& im)
  202689. {
  202690. if (im.getFormat() == Image::SingleChannel)
  202691. return const_cast <Image*> (&im);
  202692. return im.createCopyOfAlphaChannel();
  202693. }
  202694. static void deleteAlphaChannelImage (const Image& im, Image* const alphaIm)
  202695. {
  202696. if (im.getFormat() != Image::SingleChannel)
  202697. delete alphaIm;
  202698. }
  202699. void flip() const
  202700. {
  202701. CGContextConcatCTM (context, CGAffineTransformMake (1, 0, 0, -1, 0, flipHeight));
  202702. }
  202703. void applyTransform (const AffineTransform& transform) const
  202704. {
  202705. CGAffineTransform t;
  202706. t.a = transform.mat00;
  202707. t.b = transform.mat10;
  202708. t.c = transform.mat01;
  202709. t.d = transform.mat11;
  202710. t.tx = transform.mat02;
  202711. t.ty = transform.mat12;
  202712. CGContextConcatCTM (context, t);
  202713. }
  202714. CoreGraphicsContext (const CoreGraphicsContext&);
  202715. CoreGraphicsContext& operator= (const CoreGraphicsContext&);
  202716. };
  202717. LowLevelGraphicsContext* CoreGraphicsImage::createLowLevelContext()
  202718. {
  202719. return new CoreGraphicsContext (context, imageHeight);
  202720. }
  202721. #endif
  202722. /*** End of inlined file: juce_mac_CoreGraphicsContext.mm ***/
  202723. /*** Start of inlined file: juce_iphone_UIViewComponentPeer.mm ***/
  202724. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  202725. // compiled on its own).
  202726. #if JUCE_INCLUDED_FILE
  202727. class UIViewComponentPeer;
  202728. END_JUCE_NAMESPACE
  202729. #define JuceUIView MakeObjCClassName(JuceUIView)
  202730. @interface JuceUIView : UIView
  202731. {
  202732. @public
  202733. UIViewComponentPeer* owner;
  202734. }
  202735. - (JuceUIView*) initWithOwner: (UIViewComponentPeer*) owner withFrame: (CGRect) frame;
  202736. - (void) dealloc;
  202737. - (void) drawRect: (CGRect) r;
  202738. - (void) touchesBegan: (NSSet*) touches withEvent: (UIEvent*) event;
  202739. - (void) touchesMoved: (NSSet*) touches withEvent: (UIEvent*) event;
  202740. - (void) touchesEnded: (NSSet*) touches withEvent: (UIEvent*) event;
  202741. - (void) touchesCancelled: (NSSet*) touches withEvent: (UIEvent*) event;
  202742. - (BOOL) becomeFirstResponder;
  202743. - (BOOL) resignFirstResponder;
  202744. - (BOOL) canBecomeFirstResponder;
  202745. - (void) asyncRepaint: (id) rect;
  202746. @end
  202747. #define JuceUIWindow MakeObjCClassName(JuceUIWindow)
  202748. @interface JuceUIWindow : UIWindow
  202749. {
  202750. @private
  202751. UIViewComponentPeer* owner;
  202752. bool isZooming;
  202753. }
  202754. - (void) setOwner: (UIViewComponentPeer*) owner;
  202755. - (void) becomeKeyWindow;
  202756. @end
  202757. BEGIN_JUCE_NAMESPACE
  202758. class UIViewComponentPeer : public ComponentPeer
  202759. {
  202760. public:
  202761. UIViewComponentPeer (Component* const component,
  202762. const int windowStyleFlags,
  202763. UIView* viewToAttachTo);
  202764. ~UIViewComponentPeer();
  202765. void* getNativeHandle() const;
  202766. void setVisible (bool shouldBeVisible);
  202767. void setTitle (const String& title);
  202768. void setPosition (int x, int y);
  202769. void setSize (int w, int h);
  202770. void setBounds (int x, int y, int w, int h, const bool isNowFullScreen);
  202771. const Rectangle<int> getBounds() const;
  202772. const Rectangle<int> getBounds (const bool global) const;
  202773. const Point<int> getScreenPosition() const;
  202774. const Point<int> relativePositionToGlobal (const Point<int>& relativePosition);
  202775. const Point<int> globalPositionToRelative (const Point<int>& screenPosition);
  202776. void setMinimised (bool shouldBeMinimised);
  202777. bool isMinimised() const;
  202778. void setFullScreen (bool shouldBeFullScreen);
  202779. bool isFullScreen() const;
  202780. bool contains (const Point<int>& position, bool trueIfInAChildWindow) const;
  202781. const BorderSize getFrameSize() const;
  202782. bool setAlwaysOnTop (bool alwaysOnTop);
  202783. void toFront (bool makeActiveWindow);
  202784. void toBehind (ComponentPeer* other);
  202785. void setIcon (const Image& newIcon);
  202786. virtual void drawRect (CGRect r);
  202787. virtual bool canBecomeKeyWindow();
  202788. virtual bool windowShouldClose();
  202789. virtual void redirectMovedOrResized();
  202790. virtual CGRect constrainRect (CGRect r);
  202791. virtual void viewFocusGain();
  202792. virtual void viewFocusLoss();
  202793. bool isFocused() const;
  202794. void grabFocus();
  202795. void textInputRequired (const Point<int>& position);
  202796. void handleTouches (UIEvent* e, bool isDown, bool isUp, bool isCancel);
  202797. void repaint (int x, int y, int w, int h);
  202798. void performAnyPendingRepaintsNow();
  202799. juce_UseDebuggingNewOperator
  202800. UIWindow* window;
  202801. JuceUIView* view;
  202802. bool isSharedWindow, fullScreen, insideDrawRect;
  202803. static ModifierKeys currentModifiers;
  202804. static int64 getMouseTime (UIEvent* e)
  202805. {
  202806. return (Time::currentTimeMillis() - Time::getMillisecondCounter())
  202807. + (int64) ([e timestamp] * 1000.0);
  202808. }
  202809. Array <UITouch*> currentTouches;
  202810. };
  202811. END_JUCE_NAMESPACE
  202812. @implementation JuceUIView
  202813. - (JuceUIView*) initWithOwner: (UIViewComponentPeer*) owner_
  202814. withFrame: (CGRect) frame
  202815. {
  202816. [super initWithFrame: frame];
  202817. owner = owner_;
  202818. return self;
  202819. }
  202820. - (void) dealloc
  202821. {
  202822. [super dealloc];
  202823. }
  202824. - (void) drawRect: (CGRect) r
  202825. {
  202826. if (owner != 0)
  202827. owner->drawRect (r);
  202828. }
  202829. bool KeyPress::isKeyCurrentlyDown (const int keyCode) throw()
  202830. {
  202831. return false;
  202832. }
  202833. ModifierKeys UIViewComponentPeer::currentModifiers;
  202834. const ModifierKeys ModifierKeys::getCurrentModifiersRealtime() throw()
  202835. {
  202836. return UIViewComponentPeer::currentModifiers;
  202837. }
  202838. void ModifierKeys::updateCurrentModifiers() throw()
  202839. {
  202840. currentModifiers = UIViewComponentPeer::currentModifiers;
  202841. }
  202842. JUCE_NAMESPACE::Point<int> juce_lastMousePos;
  202843. - (void) touchesBegan: (NSSet*) touches withEvent: (UIEvent*) event
  202844. {
  202845. if (owner != 0)
  202846. owner->handleTouches (event, true, false, false);
  202847. }
  202848. - (void) touchesMoved: (NSSet*) touches withEvent: (UIEvent*) event
  202849. {
  202850. if (owner != 0)
  202851. owner->handleTouches (event, false, false, false);
  202852. }
  202853. - (void) touchesEnded: (NSSet*) touches withEvent: (UIEvent*) event
  202854. {
  202855. if (owner != 0)
  202856. owner->handleTouches (event, false, true, false);
  202857. }
  202858. - (void) touchesCancelled: (NSSet*) touches withEvent: (UIEvent*) event
  202859. {
  202860. if (owner != 0)
  202861. owner->handleTouches (event, false, true, true);
  202862. [self touchesEnded: touches withEvent: event];
  202863. }
  202864. - (BOOL) becomeFirstResponder
  202865. {
  202866. if (owner != 0)
  202867. owner->viewFocusGain();
  202868. return true;
  202869. }
  202870. - (BOOL) resignFirstResponder
  202871. {
  202872. if (owner != 0)
  202873. owner->viewFocusLoss();
  202874. return true;
  202875. }
  202876. - (BOOL) canBecomeFirstResponder
  202877. {
  202878. return owner != 0 && owner->canBecomeKeyWindow();
  202879. }
  202880. - (void) asyncRepaint: (id) rect
  202881. {
  202882. CGRect* r = (CGRect*) [((NSData*) rect) bytes];
  202883. [self setNeedsDisplayInRect: *r];
  202884. }
  202885. @end
  202886. @implementation JuceUIWindow
  202887. - (void) setOwner: (UIViewComponentPeer*) owner_
  202888. {
  202889. owner = owner_;
  202890. isZooming = false;
  202891. }
  202892. - (void) becomeKeyWindow
  202893. {
  202894. [super becomeKeyWindow];
  202895. if (owner != 0)
  202896. owner->grabFocus();
  202897. }
  202898. @end
  202899. BEGIN_JUCE_NAMESPACE
  202900. UIViewComponentPeer::UIViewComponentPeer (Component* const component,
  202901. const int windowStyleFlags,
  202902. UIView* viewToAttachTo)
  202903. : ComponentPeer (component, windowStyleFlags),
  202904. window (0),
  202905. view (0),
  202906. isSharedWindow (viewToAttachTo != 0),
  202907. fullScreen (false),
  202908. insideDrawRect (false)
  202909. {
  202910. CGRect r = CGRectMake (0, 0, (float) component->getWidth(), (float) component->getHeight());
  202911. view = [[JuceUIView alloc] initWithOwner: this withFrame: r];
  202912. if (isSharedWindow)
  202913. {
  202914. window = [viewToAttachTo window];
  202915. [viewToAttachTo addSubview: view];
  202916. setVisible (component->isVisible());
  202917. }
  202918. else
  202919. {
  202920. r.origin.x = (float) component->getX();
  202921. r.origin.y = (float) component->getY();
  202922. r.origin.y = [[UIScreen mainScreen] bounds].size.height - (r.origin.y + r.size.height);
  202923. window = [[JuceUIWindow alloc] init];
  202924. window.frame = r;
  202925. window.opaque = component->isOpaque();
  202926. view.opaque = component->isOpaque();
  202927. window.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent: 0];
  202928. view.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent: 0];
  202929. [((JuceUIWindow*) window) setOwner: this];
  202930. if (component->isAlwaysOnTop())
  202931. window.windowLevel = UIWindowLevelAlert;
  202932. [window addSubview: view];
  202933. view.frame = CGRectMake (0, 0, r.size.width, r.size.height);
  202934. view.hidden = ! component->isVisible();
  202935. window.hidden = ! component->isVisible();
  202936. view.multipleTouchEnabled = YES;
  202937. }
  202938. setTitle (component->getName());
  202939. }
  202940. UIViewComponentPeer::~UIViewComponentPeer()
  202941. {
  202942. view->owner = 0;
  202943. [view removeFromSuperview];
  202944. [view release];
  202945. if (! isSharedWindow)
  202946. {
  202947. [((JuceUIWindow*) window) setOwner: 0];
  202948. [window release];
  202949. }
  202950. }
  202951. void* UIViewComponentPeer::getNativeHandle() const
  202952. {
  202953. return view;
  202954. }
  202955. void UIViewComponentPeer::setVisible (bool shouldBeVisible)
  202956. {
  202957. view.hidden = ! shouldBeVisible;
  202958. if (! isSharedWindow)
  202959. window.hidden = ! shouldBeVisible;
  202960. }
  202961. void UIViewComponentPeer::setTitle (const String& title)
  202962. {
  202963. // xxx is this possible?
  202964. }
  202965. void UIViewComponentPeer::setPosition (int x, int y)
  202966. {
  202967. setBounds (x, y, component->getWidth(), component->getHeight(), false);
  202968. }
  202969. void UIViewComponentPeer::setSize (int w, int h)
  202970. {
  202971. setBounds (component->getX(), component->getY(), w, h, false);
  202972. }
  202973. void UIViewComponentPeer::setBounds (int x, int y, int w, int h, const bool isNowFullScreen)
  202974. {
  202975. fullScreen = isNowFullScreen;
  202976. w = jmax (0, w);
  202977. h = jmax (0, h);
  202978. CGRect r;
  202979. r.origin.x = (float) x;
  202980. r.origin.y = (float) y;
  202981. r.size.width = (float) w;
  202982. r.size.height = (float) h;
  202983. if (isSharedWindow)
  202984. {
  202985. //r.origin.y = [[view superview] frame].size.height - (r.origin.y + r.size.height);
  202986. if ([view frame].size.width != r.size.width
  202987. || [view frame].size.height != r.size.height)
  202988. [view setNeedsDisplay];
  202989. view.frame = r;
  202990. }
  202991. else
  202992. {
  202993. window.frame = r;
  202994. view.frame = CGRectMake (0, 0, r.size.width, r.size.height);
  202995. }
  202996. }
  202997. const Rectangle<int> UIViewComponentPeer::getBounds (const bool global) const
  202998. {
  202999. CGRect r = [view frame];
  203000. if (global && [view window] != 0)
  203001. {
  203002. r = [view convertRect: r toView: nil];
  203003. CGRect wr = [[view window] frame];
  203004. r.origin.x += wr.origin.x;
  203005. r.origin.y += wr.origin.y;
  203006. }
  203007. return Rectangle<int> ((int) r.origin.x, (int) r.origin.y,
  203008. (int) r.size.width, (int) r.size.height);
  203009. }
  203010. const Rectangle<int> UIViewComponentPeer::getBounds() const
  203011. {
  203012. return getBounds (! isSharedWindow);
  203013. }
  203014. const Point<int> UIViewComponentPeer::getScreenPosition() const
  203015. {
  203016. return getBounds (true).getPosition();
  203017. }
  203018. const Point<int> UIViewComponentPeer::relativePositionToGlobal (const Point<int>& relativePosition)
  203019. {
  203020. return relativePosition + getScreenPosition();
  203021. }
  203022. const Point<int> UIViewComponentPeer::globalPositionToRelative (const Point<int>& screenPosition)
  203023. {
  203024. return screenPosition - getScreenPosition();
  203025. }
  203026. CGRect UIViewComponentPeer::constrainRect (CGRect r)
  203027. {
  203028. if (constrainer != 0)
  203029. {
  203030. CGRect current = [window frame];
  203031. current.origin.y = [[UIScreen mainScreen] bounds].size.height - current.origin.y - current.size.height;
  203032. r.origin.y = [[UIScreen mainScreen] bounds].size.height - r.origin.y - r.size.height;
  203033. Rectangle<int> pos ((int) r.origin.x, (int) r.origin.y,
  203034. (int) r.size.width, (int) r.size.height);
  203035. Rectangle<int> original ((int) current.origin.x, (int) current.origin.y,
  203036. (int) current.size.width, (int) current.size.height);
  203037. constrainer->checkBounds (pos, original,
  203038. Desktop::getInstance().getAllMonitorDisplayAreas().getBounds(),
  203039. pos.getY() != original.getY() && pos.getBottom() == original.getBottom(),
  203040. pos.getX() != original.getX() && pos.getRight() == original.getRight(),
  203041. pos.getY() == original.getY() && pos.getBottom() != original.getBottom(),
  203042. pos.getX() == original.getX() && pos.getRight() != original.getRight());
  203043. r.origin.x = pos.getX();
  203044. r.origin.y = [[UIScreen mainScreen] bounds].size.height - r.size.height - pos.getY();
  203045. r.size.width = pos.getWidth();
  203046. r.size.height = pos.getHeight();
  203047. }
  203048. return r;
  203049. }
  203050. void UIViewComponentPeer::setMinimised (bool shouldBeMinimised)
  203051. {
  203052. // xxx
  203053. }
  203054. bool UIViewComponentPeer::isMinimised() const
  203055. {
  203056. return false;
  203057. }
  203058. void UIViewComponentPeer::setFullScreen (bool shouldBeFullScreen)
  203059. {
  203060. if (! isSharedWindow)
  203061. {
  203062. Rectangle<int> r (lastNonFullscreenBounds);
  203063. setMinimised (false);
  203064. if (fullScreen != shouldBeFullScreen)
  203065. {
  203066. if (shouldBeFullScreen)
  203067. r = Desktop::getInstance().getMainMonitorArea();
  203068. // (can't call the component's setBounds method because that'll reset our fullscreen flag)
  203069. if (r != getComponent()->getBounds() && ! r.isEmpty())
  203070. setBounds (r.getX(), r.getY(), r.getWidth(), r.getHeight(), shouldBeFullScreen);
  203071. }
  203072. }
  203073. }
  203074. bool UIViewComponentPeer::isFullScreen() const
  203075. {
  203076. return fullScreen;
  203077. }
  203078. bool UIViewComponentPeer::contains (const Point<int>& position, bool trueIfInAChildWindow) const
  203079. {
  203080. if (((unsigned int) position.getX()) >= (unsigned int) component->getWidth()
  203081. || ((unsigned int) position.getY()) >= (unsigned int) component->getHeight())
  203082. return false;
  203083. CGPoint p;
  203084. p.x = (float) position.getX();
  203085. p.y = (float) position.getY();
  203086. UIView* v = [view hitTest: p withEvent: nil];
  203087. if (trueIfInAChildWindow)
  203088. return v != nil;
  203089. return v == view;
  203090. }
  203091. const BorderSize UIViewComponentPeer::getFrameSize() const
  203092. {
  203093. BorderSize b;
  203094. if (! isSharedWindow)
  203095. {
  203096. CGRect v = [view convertRect: [view frame] toView: nil];
  203097. CGRect w = [window frame];
  203098. b.setTop ((int) (w.size.height - (v.origin.y + v.size.height)));
  203099. b.setBottom ((int) v.origin.y);
  203100. b.setLeft ((int) v.origin.x);
  203101. b.setRight ((int) (w.size.width - (v.origin.x + v.size.width)));
  203102. }
  203103. return b;
  203104. }
  203105. bool UIViewComponentPeer::setAlwaysOnTop (bool alwaysOnTop)
  203106. {
  203107. if (! isSharedWindow)
  203108. window.windowLevel = alwaysOnTop ? UIWindowLevelAlert : UIWindowLevelNormal;
  203109. return true;
  203110. }
  203111. void UIViewComponentPeer::toFront (bool makeActiveWindow)
  203112. {
  203113. if (isSharedWindow)
  203114. [[view superview] bringSubviewToFront: view];
  203115. if (window != 0 && component->isVisible())
  203116. [window makeKeyAndVisible];
  203117. }
  203118. void UIViewComponentPeer::toBehind (ComponentPeer* other)
  203119. {
  203120. UIViewComponentPeer* o = (UIViewComponentPeer*) other;
  203121. if (isSharedWindow)
  203122. {
  203123. [[view superview] insertSubview: view belowSubview: o->view];
  203124. }
  203125. else
  203126. {
  203127. jassertfalse // don't know how to do this
  203128. }
  203129. }
  203130. void UIViewComponentPeer::setIcon (const Image& /*newIcon*/)
  203131. {
  203132. // to do..
  203133. }
  203134. void UIViewComponentPeer::handleTouches (UIEvent* event, const bool isDown, const bool isUp, bool isCancel)
  203135. {
  203136. NSArray* touches = [[event touchesForView: view] allObjects];
  203137. for (unsigned int i = 0; i < [touches count]; ++i)
  203138. {
  203139. UITouch* touch = [touches objectAtIndex: i];
  203140. CGPoint p = [touch locationInView: view];
  203141. const Point<int> pos ((int) p.x, (int) p.y);
  203142. juce_lastMousePos = pos + getScreenPosition();
  203143. const int64 time = getMouseTime (event);
  203144. int touchIndex = currentTouches.indexOf (touch);
  203145. if (touchIndex < 0)
  203146. {
  203147. touchIndex = currentTouches.size();
  203148. currentTouches.add (touch);
  203149. }
  203150. if (isDown)
  203151. {
  203152. currentModifiers = currentModifiers.withoutMouseButtons();
  203153. handleMouseEvent (touchIndex, pos, currentModifiers, time);
  203154. currentModifiers = currentModifiers.withoutMouseButtons().withFlags (ModifierKeys::leftButtonModifier);
  203155. }
  203156. else if (isUp)
  203157. {
  203158. currentModifiers = currentModifiers.withoutMouseButtons();
  203159. currentTouches.remove (touchIndex);
  203160. }
  203161. if (isCancel)
  203162. currentTouches.clear();
  203163. handleMouseEvent (touchIndex, pos, currentModifiers, time);
  203164. }
  203165. }
  203166. static UIViewComponentPeer* currentlyFocusedPeer = 0;
  203167. void UIViewComponentPeer::viewFocusGain()
  203168. {
  203169. if (currentlyFocusedPeer != this)
  203170. {
  203171. if (ComponentPeer::isValidPeer (currentlyFocusedPeer))
  203172. currentlyFocusedPeer->handleFocusLoss();
  203173. currentlyFocusedPeer = this;
  203174. handleFocusGain();
  203175. }
  203176. }
  203177. void UIViewComponentPeer::viewFocusLoss()
  203178. {
  203179. if (currentlyFocusedPeer == this)
  203180. {
  203181. currentlyFocusedPeer = 0;
  203182. handleFocusLoss();
  203183. }
  203184. }
  203185. void juce_HandleProcessFocusChange()
  203186. {
  203187. if (UIViewComponentPeer::isValidPeer (currentlyFocusedPeer))
  203188. {
  203189. if (Process::isForegroundProcess())
  203190. {
  203191. currentlyFocusedPeer->handleFocusGain();
  203192. ComponentPeer::bringModalComponentToFront();
  203193. }
  203194. else
  203195. {
  203196. currentlyFocusedPeer->handleFocusLoss();
  203197. // turn kiosk mode off if we lose focus..
  203198. Desktop::getInstance().setKioskModeComponent (0);
  203199. }
  203200. }
  203201. }
  203202. bool UIViewComponentPeer::isFocused() const
  203203. {
  203204. return isSharedWindow ? this == currentlyFocusedPeer
  203205. : (window != 0 && [window isKeyWindow]);
  203206. }
  203207. void UIViewComponentPeer::grabFocus()
  203208. {
  203209. if (window != 0)
  203210. {
  203211. [window makeKeyWindow];
  203212. viewFocusGain();
  203213. }
  203214. }
  203215. void UIViewComponentPeer::textInputRequired (const Point<int>&)
  203216. {
  203217. }
  203218. void UIViewComponentPeer::drawRect (CGRect r)
  203219. {
  203220. if (r.size.width < 1.0f || r.size.height < 1.0f)
  203221. return;
  203222. CGContextRef cg = UIGraphicsGetCurrentContext();
  203223. if (! component->isOpaque())
  203224. CGContextClearRect (cg, CGContextGetClipBoundingBox (cg));
  203225. CGContextConcatCTM (cg, CGAffineTransformMake (1, 0, 0, -1, 0, view.bounds.size.height));
  203226. CoreGraphicsContext g (cg, view.bounds.size.height);
  203227. insideDrawRect = true;
  203228. handlePaint (g);
  203229. insideDrawRect = false;
  203230. }
  203231. bool UIViewComponentPeer::canBecomeKeyWindow()
  203232. {
  203233. return (getStyleFlags() & JUCE_NAMESPACE::ComponentPeer::windowIgnoresKeyPresses) == 0;
  203234. }
  203235. bool UIViewComponentPeer::windowShouldClose()
  203236. {
  203237. if (! isValidPeer (this))
  203238. return YES;
  203239. handleUserClosingWindow();
  203240. return NO;
  203241. }
  203242. void UIViewComponentPeer::redirectMovedOrResized()
  203243. {
  203244. handleMovedOrResized();
  203245. }
  203246. void juce_setKioskComponent (Component* kioskModeComponent, bool enableOrDisable, bool allowMenusAndBars)
  203247. {
  203248. }
  203249. class AsyncRepaintMessage : public CallbackMessage
  203250. {
  203251. public:
  203252. UIViewComponentPeer* const peer;
  203253. const Rectangle<int> rect;
  203254. AsyncRepaintMessage (UIViewComponentPeer* const peer_, const Rectangle<int>& rect_)
  203255. : peer (peer_), rect (rect_)
  203256. {
  203257. }
  203258. void messageCallback()
  203259. {
  203260. if (ComponentPeer::isValidPeer (peer))
  203261. peer->repaint (rect.getX(), rect.getY(), rect.getWidth(), rect.getHeight());
  203262. }
  203263. };
  203264. void UIViewComponentPeer::repaint (int x, int y, int w, int h)
  203265. {
  203266. if (insideDrawRect || ! MessageManager::getInstance()->isThisTheMessageThread())
  203267. {
  203268. (new AsyncRepaintMessage (this, Rectangle<int> (x, y, w, h)))->post();
  203269. }
  203270. else
  203271. {
  203272. [view setNeedsDisplayInRect: CGRectMake ((float) x, (float) y, (float) w, (float) h)];
  203273. }
  203274. }
  203275. void UIViewComponentPeer::performAnyPendingRepaintsNow()
  203276. {
  203277. }
  203278. ComponentPeer* Component::createNewPeer (int styleFlags, void* windowToAttachTo)
  203279. {
  203280. return new UIViewComponentPeer (this, styleFlags, (UIView*) windowToAttachTo);
  203281. }
  203282. Image* juce_createIconForFile (const File& file)
  203283. {
  203284. return 0;
  203285. }
  203286. void Desktop::createMouseInputSources()
  203287. {
  203288. for (int i = 0; i < 10; ++i)
  203289. mouseSources.add (new MouseInputSource (i, false));
  203290. }
  203291. bool Desktop::canUseSemiTransparentWindows() throw()
  203292. {
  203293. return true;
  203294. }
  203295. const Point<int> Desktop::getMousePosition()
  203296. {
  203297. return juce_lastMousePos;
  203298. }
  203299. void Desktop::setMousePosition (const Point<int>&)
  203300. {
  203301. }
  203302. const int KeyPress::spaceKey = ' ';
  203303. const int KeyPress::returnKey = 0x0d;
  203304. const int KeyPress::escapeKey = 0x1b;
  203305. const int KeyPress::backspaceKey = 0x7f;
  203306. const int KeyPress::leftKey = 0x1000;
  203307. const int KeyPress::rightKey = 0x1001;
  203308. const int KeyPress::upKey = 0x1002;
  203309. const int KeyPress::downKey = 0x1003;
  203310. const int KeyPress::pageUpKey = 0x1004;
  203311. const int KeyPress::pageDownKey = 0x1005;
  203312. const int KeyPress::endKey = 0x1006;
  203313. const int KeyPress::homeKey = 0x1007;
  203314. const int KeyPress::deleteKey = 0x1008;
  203315. const int KeyPress::insertKey = -1;
  203316. const int KeyPress::tabKey = 9;
  203317. const int KeyPress::F1Key = 0x2001;
  203318. const int KeyPress::F2Key = 0x2002;
  203319. const int KeyPress::F3Key = 0x2003;
  203320. const int KeyPress::F4Key = 0x2004;
  203321. const int KeyPress::F5Key = 0x2005;
  203322. const int KeyPress::F6Key = 0x2006;
  203323. const int KeyPress::F7Key = 0x2007;
  203324. const int KeyPress::F8Key = 0x2008;
  203325. const int KeyPress::F9Key = 0x2009;
  203326. const int KeyPress::F10Key = 0x200a;
  203327. const int KeyPress::F11Key = 0x200b;
  203328. const int KeyPress::F12Key = 0x200c;
  203329. const int KeyPress::F13Key = 0x200d;
  203330. const int KeyPress::F14Key = 0x200e;
  203331. const int KeyPress::F15Key = 0x200f;
  203332. const int KeyPress::F16Key = 0x2010;
  203333. const int KeyPress::numberPad0 = 0x30020;
  203334. const int KeyPress::numberPad1 = 0x30021;
  203335. const int KeyPress::numberPad2 = 0x30022;
  203336. const int KeyPress::numberPad3 = 0x30023;
  203337. const int KeyPress::numberPad4 = 0x30024;
  203338. const int KeyPress::numberPad5 = 0x30025;
  203339. const int KeyPress::numberPad6 = 0x30026;
  203340. const int KeyPress::numberPad7 = 0x30027;
  203341. const int KeyPress::numberPad8 = 0x30028;
  203342. const int KeyPress::numberPad9 = 0x30029;
  203343. const int KeyPress::numberPadAdd = 0x3002a;
  203344. const int KeyPress::numberPadSubtract = 0x3002b;
  203345. const int KeyPress::numberPadMultiply = 0x3002c;
  203346. const int KeyPress::numberPadDivide = 0x3002d;
  203347. const int KeyPress::numberPadSeparator = 0x3002e;
  203348. const int KeyPress::numberPadDecimalPoint = 0x3002f;
  203349. const int KeyPress::numberPadEquals = 0x30030;
  203350. const int KeyPress::numberPadDelete = 0x30031;
  203351. const int KeyPress::playKey = 0x30000;
  203352. const int KeyPress::stopKey = 0x30001;
  203353. const int KeyPress::fastForwardKey = 0x30002;
  203354. const int KeyPress::rewindKey = 0x30003;
  203355. #endif
  203356. /*** End of inlined file: juce_iphone_UIViewComponentPeer.mm ***/
  203357. /*** Start of inlined file: juce_iphone_MessageManager.mm ***/
  203358. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  203359. // compiled on its own).
  203360. #if JUCE_INCLUDED_FILE
  203361. struct CallbackMessagePayload
  203362. {
  203363. MessageCallbackFunction* function;
  203364. void* parameter;
  203365. void* volatile result;
  203366. bool volatile hasBeenExecuted;
  203367. };
  203368. END_JUCE_NAMESPACE
  203369. using namespace JUCE_NAMESPACE;
  203370. @interface JuceAppDelegate : NSObject <UIApplicationDelegate>
  203371. {
  203372. }
  203373. - (JuceAppDelegate*) init;
  203374. - (void) dealloc;
  203375. - (BOOL) application: (UIApplication*) application handleOpenURL: (NSURL*) url;
  203376. - (void) applicationDidBecomeActive: (NSNotification*) aNotification;
  203377. - (void) applicationDidResignActive: (NSNotification*) aNotification;
  203378. - (void) applicationWillUnhide: (NSNotification*) aNotification;
  203379. - (void) customEvent: (id) data;
  203380. - (void) performCallback: (id) info;
  203381. @end
  203382. @implementation JuceAppDelegate
  203383. - (JuceAppDelegate*) init
  203384. {
  203385. [super init];
  203386. [[UIApplication sharedApplication] setDelegate: self];
  203387. return self;
  203388. }
  203389. - (void) dealloc
  203390. {
  203391. [[UIApplication sharedApplication] setDelegate: nil];
  203392. [super dealloc];
  203393. }
  203394. - (BOOL) application: (UIApplication*) application handleOpenURL: (NSURL*) url
  203395. {
  203396. if (JUCEApplication::getInstance() != 0)
  203397. {
  203398. JUCEApplication::getInstance()->anotherInstanceStarted (nsStringToJuce ([url absoluteString]));
  203399. return YES;
  203400. }
  203401. return NO;
  203402. }
  203403. - (void) applicationDidBecomeActive: (NSNotification*) aNotification
  203404. {
  203405. juce_HandleProcessFocusChange();
  203406. }
  203407. - (void) applicationDidResignActive: (NSNotification*) aNotification
  203408. {
  203409. juce_HandleProcessFocusChange();
  203410. }
  203411. - (void) applicationWillUnhide: (NSNotification*) aNotification
  203412. {
  203413. juce_HandleProcessFocusChange();
  203414. }
  203415. - (void) customEvent: (id) n
  203416. {
  203417. NSData* data = (NSData*) n;
  203418. void* message = 0;
  203419. [data getBytes: &message length: sizeof (message)];
  203420. [data release];
  203421. if (message != 0)
  203422. MessageManager::getInstance()->deliverMessage (message);
  203423. }
  203424. - (void) performCallback: (id) info
  203425. {
  203426. if ([info isKindOfClass: [NSData class]])
  203427. {
  203428. CallbackMessagePayload* pl = (CallbackMessagePayload*) [((NSData*) info) bytes];
  203429. if (pl != 0)
  203430. {
  203431. pl->result = (*pl->function) (pl->parameter);
  203432. pl->hasBeenExecuted = true;
  203433. }
  203434. }
  203435. else
  203436. {
  203437. jassertfalse // should never get here!
  203438. }
  203439. }
  203440. @end
  203441. BEGIN_JUCE_NAMESPACE
  203442. static JuceAppDelegate* juceAppDelegate = 0;
  203443. void MessageManager::runDispatchLoop()
  203444. {
  203445. jassert (isThisTheMessageThread()); // must only be called by the message thread
  203446. runDispatchLoopUntil (-1);
  203447. }
  203448. void MessageManager::stopDispatchLoop()
  203449. {
  203450. exit (0); // iPhone apps get no mercy..
  203451. }
  203452. bool MessageManager::runDispatchLoopUntil (int millisecondsToRunFor)
  203453. {
  203454. const ScopedAutoReleasePool pool;
  203455. jassert (isThisTheMessageThread()); // must only be called by the message thread
  203456. uint32 endTime = Time::getMillisecondCounter() + millisecondsToRunFor;
  203457. NSDate* endDate = [NSDate dateWithTimeIntervalSinceNow: millisecondsToRunFor * 0.001];
  203458. while (! quitMessagePosted)
  203459. {
  203460. const ScopedAutoReleasePool pool;
  203461. [[NSRunLoop currentRunLoop] runMode: NSDefaultRunLoopMode
  203462. beforeDate: endDate];
  203463. if (millisecondsToRunFor >= 0 && Time::getMillisecondCounter() >= endTime)
  203464. break;
  203465. }
  203466. return ! quitMessagePosted;
  203467. }
  203468. static CFRunLoopRef runLoop = 0;
  203469. static CFRunLoopSourceRef runLoopSource = 0;
  203470. static Array <void*, CriticalSection>* pendingMessages = 0;
  203471. static void runLoopSourceCallback (void*)
  203472. {
  203473. if (pendingMessages != 0)
  203474. {
  203475. int numDispatched = 0;
  203476. do
  203477. {
  203478. void* const nextMessage = pendingMessages->remove (0);
  203479. if (nextMessage == 0)
  203480. return;
  203481. const ScopedAutoReleasePool pool;
  203482. MessageManager::getInstance()->deliverMessage (nextMessage);
  203483. } while (++numDispatched <= 4);
  203484. CFRunLoopSourceSignal (runLoopSource);
  203485. CFRunLoopWakeUp (runLoop);
  203486. }
  203487. }
  203488. void MessageManager::doPlatformSpecificInitialisation()
  203489. {
  203490. pendingMessages = new Array <void*, CriticalSection>();
  203491. runLoop = CFRunLoopGetCurrent();
  203492. CFRunLoopSourceContext sourceContext;
  203493. zerostruct (sourceContext);
  203494. sourceContext.perform = runLoopSourceCallback;
  203495. runLoopSource = CFRunLoopSourceCreate (kCFAllocatorDefault, 1, &sourceContext);
  203496. CFRunLoopAddSource (runLoop, runLoopSource, kCFRunLoopCommonModes);
  203497. if (juceAppDelegate == 0)
  203498. juceAppDelegate = [[JuceAppDelegate alloc] init];
  203499. }
  203500. void MessageManager::doPlatformSpecificShutdown()
  203501. {
  203502. CFRunLoopSourceInvalidate (runLoopSource);
  203503. CFRelease (runLoopSource);
  203504. runLoopSource = 0;
  203505. if (pendingMessages != 0)
  203506. {
  203507. while (pendingMessages->size() > 0)
  203508. delete ((Message*) pendingMessages->remove(0));
  203509. deleteAndZero (pendingMessages);
  203510. }
  203511. if (juceAppDelegate != 0)
  203512. {
  203513. [[NSRunLoop currentRunLoop] cancelPerformSelectorsWithTarget: juceAppDelegate];
  203514. [juceAppDelegate release];
  203515. juceAppDelegate = 0;
  203516. }
  203517. }
  203518. bool juce_postMessageToSystemQueue (void* message)
  203519. {
  203520. if (pendingMessages != 0)
  203521. {
  203522. pendingMessages->add (message);
  203523. CFRunLoopSourceSignal (runLoopSource);
  203524. CFRunLoopWakeUp (runLoop);
  203525. }
  203526. return true;
  203527. }
  203528. void MessageManager::broadcastMessage (const String& value) throw()
  203529. {
  203530. }
  203531. void* MessageManager::callFunctionOnMessageThread (MessageCallbackFunction* callback,
  203532. void* data)
  203533. {
  203534. if (isThisTheMessageThread())
  203535. {
  203536. return (*callback) (data);
  203537. }
  203538. else
  203539. {
  203540. // If a thread has a MessageManagerLock and then tries to call this method, it'll
  203541. // deadlock because the message manager is blocked from running, so can never
  203542. // call your function..
  203543. jassert (! MessageManager::getInstance()->currentThreadHasLockedMessageManager());
  203544. const ScopedAutoReleasePool pool;
  203545. CallbackMessagePayload cmp;
  203546. cmp.function = callback;
  203547. cmp.parameter = data;
  203548. cmp.result = 0;
  203549. cmp.hasBeenExecuted = false;
  203550. [juceAppDelegate performSelectorOnMainThread: @selector (performCallback:)
  203551. withObject: [NSData dataWithBytesNoCopy: &cmp
  203552. length: sizeof (cmp)
  203553. freeWhenDone: NO]
  203554. waitUntilDone: YES];
  203555. return cmp.result;
  203556. }
  203557. }
  203558. #endif
  203559. /*** End of inlined file: juce_iphone_MessageManager.mm ***/
  203560. /*** Start of inlined file: juce_mac_FileChooser.mm ***/
  203561. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  203562. // compiled on its own).
  203563. #if JUCE_INCLUDED_FILE
  203564. #if JUCE_MAC
  203565. END_JUCE_NAMESPACE
  203566. using namespace JUCE_NAMESPACE;
  203567. #define JuceFileChooserDelegate MakeObjCClassName(JuceFileChooserDelegate)
  203568. #if defined (MAC_OS_X_VERSION_10_6) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
  203569. @interface JuceFileChooserDelegate : NSObject <NSOpenSavePanelDelegate>
  203570. #else
  203571. @interface JuceFileChooserDelegate : NSObject
  203572. #endif
  203573. {
  203574. StringArray* filters;
  203575. }
  203576. - (JuceFileChooserDelegate*) initWithFilters: (StringArray*) filters_;
  203577. - (void) dealloc;
  203578. - (BOOL) panel: (id) sender shouldShowFilename: (NSString*) filename;
  203579. @end
  203580. @implementation JuceFileChooserDelegate
  203581. - (JuceFileChooserDelegate*) initWithFilters: (StringArray*) filters_
  203582. {
  203583. [super init];
  203584. filters = filters_;
  203585. return self;
  203586. }
  203587. - (void) dealloc
  203588. {
  203589. delete filters;
  203590. [super dealloc];
  203591. }
  203592. - (BOOL) panel: (id) sender shouldShowFilename: (NSString*) filename
  203593. {
  203594. const File f (nsStringToJuce (filename));
  203595. for (int i = filters->size(); --i >= 0;)
  203596. if (f.getFileName().matchesWildcard ((*filters)[i], true))
  203597. return true;
  203598. return f.isDirectory();
  203599. }
  203600. @end
  203601. BEGIN_JUCE_NAMESPACE
  203602. void FileChooser::showPlatformDialog (Array<File>& results,
  203603. const String& title,
  203604. const File& currentFileOrDirectory,
  203605. const String& filter,
  203606. bool selectsDirectory,
  203607. bool selectsFiles,
  203608. bool isSaveDialogue,
  203609. bool warnAboutOverwritingExistingFiles,
  203610. bool selectMultipleFiles,
  203611. FilePreviewComponent* extraInfoComponent)
  203612. {
  203613. const ScopedAutoReleasePool pool;
  203614. StringArray* filters = new StringArray();
  203615. filters->addTokens (filter.replaceCharacters (T(",:"), T(";;")), T(";"), String::empty);
  203616. filters->trim();
  203617. filters->removeEmptyStrings();
  203618. JuceFileChooserDelegate* delegate = [[JuceFileChooserDelegate alloc] initWithFilters: filters];
  203619. [delegate autorelease];
  203620. NSSavePanel* panel = isSaveDialogue ? [NSSavePanel savePanel]
  203621. : [NSOpenPanel openPanel];
  203622. [panel setTitle: juceStringToNS (title)];
  203623. if (! isSaveDialogue)
  203624. {
  203625. NSOpenPanel* openPanel = (NSOpenPanel*) panel;
  203626. [openPanel setCanChooseDirectories: selectsDirectory];
  203627. [openPanel setCanChooseFiles: selectsFiles];
  203628. [openPanel setAllowsMultipleSelection: selectMultipleFiles];
  203629. }
  203630. [panel setDelegate: delegate];
  203631. if (isSaveDialogue || selectsDirectory)
  203632. [panel setCanCreateDirectories: YES];
  203633. String directory, filename;
  203634. if (currentFileOrDirectory.isDirectory())
  203635. {
  203636. directory = currentFileOrDirectory.getFullPathName();
  203637. }
  203638. else
  203639. {
  203640. directory = currentFileOrDirectory.getParentDirectory().getFullPathName();
  203641. filename = currentFileOrDirectory.getFileName();
  203642. }
  203643. if ([panel runModalForDirectory: juceStringToNS (directory)
  203644. file: juceStringToNS (filename)]
  203645. == NSOKButton)
  203646. {
  203647. if (isSaveDialogue)
  203648. {
  203649. results.add (File (nsStringToJuce ([panel filename])));
  203650. }
  203651. else
  203652. {
  203653. NSOpenPanel* openPanel = (NSOpenPanel*) panel;
  203654. NSArray* urls = [openPanel filenames];
  203655. for (unsigned int i = 0; i < [urls count]; ++i)
  203656. {
  203657. NSString* f = [urls objectAtIndex: i];
  203658. results.add (File (nsStringToJuce (f)));
  203659. }
  203660. }
  203661. }
  203662. [panel setDelegate: nil];
  203663. }
  203664. #else
  203665. void FileChooser::showPlatformDialog (Array<File>& results,
  203666. const String& title,
  203667. const File& currentFileOrDirectory,
  203668. const String& filter,
  203669. bool selectsDirectory,
  203670. bool selectsFiles,
  203671. bool isSaveDialogue,
  203672. bool warnAboutOverwritingExistingFiles,
  203673. bool selectMultipleFiles,
  203674. FilePreviewComponent* extraInfoComponent)
  203675. {
  203676. const ScopedAutoReleasePool pool;
  203677. jassertfalse //xxx to do
  203678. }
  203679. #endif
  203680. #endif
  203681. /*** End of inlined file: juce_mac_FileChooser.mm ***/
  203682. /*** Start of inlined file: juce_mac_OpenGLComponent.mm ***/
  203683. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  203684. // compiled on its own).
  203685. #if JUCE_INCLUDED_FILE && JUCE_OPENGL
  203686. #if JUCE_MAC
  203687. END_JUCE_NAMESPACE
  203688. #define ThreadSafeNSOpenGLView MakeObjCClassName(ThreadSafeNSOpenGLView)
  203689. @interface ThreadSafeNSOpenGLView : NSOpenGLView
  203690. {
  203691. CriticalSection* contextLock;
  203692. bool needsUpdate;
  203693. }
  203694. - (id) initWithFrame: (NSRect) frameRect pixelFormat: (NSOpenGLPixelFormat*) format;
  203695. - (bool) makeActive;
  203696. - (void) makeInactive;
  203697. - (void) reshape;
  203698. @end
  203699. @implementation ThreadSafeNSOpenGLView
  203700. - (id) initWithFrame: (NSRect) frameRect
  203701. pixelFormat: (NSOpenGLPixelFormat*) format
  203702. {
  203703. contextLock = new CriticalSection();
  203704. self = [super initWithFrame: frameRect pixelFormat: format];
  203705. if (self != nil)
  203706. [[NSNotificationCenter defaultCenter] addObserver: self
  203707. selector: @selector (_surfaceNeedsUpdate:)
  203708. name: NSViewGlobalFrameDidChangeNotification
  203709. object: self];
  203710. return self;
  203711. }
  203712. - (void) dealloc
  203713. {
  203714. [[NSNotificationCenter defaultCenter] removeObserver: self];
  203715. delete contextLock;
  203716. [super dealloc];
  203717. }
  203718. - (bool) makeActive
  203719. {
  203720. const ScopedLock sl (*contextLock);
  203721. if ([self openGLContext] == 0)
  203722. return false;
  203723. [[self openGLContext] makeCurrentContext];
  203724. if (needsUpdate)
  203725. {
  203726. [super update];
  203727. needsUpdate = false;
  203728. }
  203729. return true;
  203730. }
  203731. - (void) makeInactive
  203732. {
  203733. const ScopedLock sl (*contextLock);
  203734. [NSOpenGLContext clearCurrentContext];
  203735. }
  203736. - (void) _surfaceNeedsUpdate: (NSNotification*) notification
  203737. {
  203738. const ScopedLock sl (*contextLock);
  203739. needsUpdate = true;
  203740. }
  203741. - (void) update
  203742. {
  203743. const ScopedLock sl (*contextLock);
  203744. needsUpdate = true;
  203745. }
  203746. - (void) reshape
  203747. {
  203748. const ScopedLock sl (*contextLock);
  203749. needsUpdate = true;
  203750. }
  203751. @end
  203752. BEGIN_JUCE_NAMESPACE
  203753. class WindowedGLContext : public OpenGLContext
  203754. {
  203755. public:
  203756. WindowedGLContext (Component* const component,
  203757. const OpenGLPixelFormat& pixelFormat_,
  203758. NSOpenGLContext* sharedContext)
  203759. : renderContext (0),
  203760. pixelFormat (pixelFormat_)
  203761. {
  203762. jassert (component != 0);
  203763. NSOpenGLPixelFormatAttribute attribs [64];
  203764. int n = 0;
  203765. attribs[n++] = NSOpenGLPFADoubleBuffer;
  203766. attribs[n++] = NSOpenGLPFAAccelerated;
  203767. attribs[n++] = NSOpenGLPFAMPSafe; // NSOpenGLPFAAccelerated, NSOpenGLPFAMultiScreen, NSOpenGLPFASingleRenderer
  203768. attribs[n++] = NSOpenGLPFAColorSize;
  203769. attribs[n++] = (NSOpenGLPixelFormatAttribute) jmax (pixelFormat.redBits,
  203770. pixelFormat.greenBits,
  203771. pixelFormat.blueBits);
  203772. attribs[n++] = NSOpenGLPFAAlphaSize;
  203773. attribs[n++] = (NSOpenGLPixelFormatAttribute) pixelFormat.alphaBits;
  203774. attribs[n++] = NSOpenGLPFADepthSize;
  203775. attribs[n++] = (NSOpenGLPixelFormatAttribute) pixelFormat.depthBufferBits;
  203776. attribs[n++] = NSOpenGLPFAStencilSize;
  203777. attribs[n++] = (NSOpenGLPixelFormatAttribute) pixelFormat.stencilBufferBits;
  203778. attribs[n++] = NSOpenGLPFAAccumSize;
  203779. attribs[n++] = (NSOpenGLPixelFormatAttribute) jmax (pixelFormat.accumulationBufferRedBits,
  203780. pixelFormat.accumulationBufferGreenBits,
  203781. pixelFormat.accumulationBufferBlueBits,
  203782. pixelFormat.accumulationBufferAlphaBits);
  203783. // xxx not sure how to do fullSceneAntiAliasingNumSamples..
  203784. attribs[n++] = NSOpenGLPFASampleBuffers;
  203785. attribs[n++] = (NSOpenGLPixelFormatAttribute) 1;
  203786. attribs[n++] = NSOpenGLPFAClosestPolicy;
  203787. attribs[n++] = NSOpenGLPFANoRecovery;
  203788. attribs[n++] = (NSOpenGLPixelFormatAttribute) 0;
  203789. NSOpenGLPixelFormat* format
  203790. = [[NSOpenGLPixelFormat alloc] initWithAttributes: attribs];
  203791. view = [[ThreadSafeNSOpenGLView alloc] initWithFrame: NSMakeRect (0, 0, 100.0f, 100.0f)
  203792. pixelFormat: format];
  203793. renderContext = [[[NSOpenGLContext alloc] initWithFormat: format
  203794. shareContext: sharedContext] autorelease];
  203795. const GLint swapInterval = 1;
  203796. [renderContext setValues: &swapInterval forParameter: NSOpenGLCPSwapInterval];
  203797. [view setOpenGLContext: renderContext];
  203798. [renderContext setView: view];
  203799. [format release];
  203800. viewHolder = new NSViewComponentInternal (view, component);
  203801. }
  203802. ~WindowedGLContext()
  203803. {
  203804. makeInactive();
  203805. [renderContext clearDrawable];
  203806. viewHolder = 0;
  203807. }
  203808. bool makeActive() const throw()
  203809. {
  203810. jassert (renderContext != 0);
  203811. [view makeActive];
  203812. return isActive();
  203813. }
  203814. bool makeInactive() const throw()
  203815. {
  203816. [view makeInactive];
  203817. return true;
  203818. }
  203819. bool isActive() const throw()
  203820. {
  203821. return [NSOpenGLContext currentContext] == renderContext;
  203822. }
  203823. const OpenGLPixelFormat getPixelFormat() const { return pixelFormat; }
  203824. void* getRawContext() const throw() { return renderContext; }
  203825. void updateWindowPosition (int x, int y, int w, int h, int outerWindowHeight)
  203826. {
  203827. }
  203828. void swapBuffers()
  203829. {
  203830. [renderContext flushBuffer];
  203831. }
  203832. bool setSwapInterval (const int numFramesPerSwap)
  203833. {
  203834. [renderContext setValues: (const GLint*) &numFramesPerSwap
  203835. forParameter: NSOpenGLCPSwapInterval];
  203836. return true;
  203837. }
  203838. int getSwapInterval() const
  203839. {
  203840. GLint numFrames = 0;
  203841. [renderContext getValues: &numFrames
  203842. forParameter: NSOpenGLCPSwapInterval];
  203843. return numFrames;
  203844. }
  203845. void repaint()
  203846. {
  203847. // we need to invalidate the juce view that holds this gl view, to make it
  203848. // cause a repaint callback
  203849. NSView* v = (NSView*) viewHolder->view;
  203850. NSRect r = [v frame];
  203851. // bit of a bodge here.. if we only invalidate the area of the gl component,
  203852. // it's completely covered by the NSOpenGLView, so the OS throws away the
  203853. // repaint message, thus never causing our paint() callback, and never repainting
  203854. // the comp. So invalidating just a little bit around the edge helps..
  203855. [[v superview] setNeedsDisplayInRect: NSInsetRect (r, -2.0f, -2.0f)];
  203856. }
  203857. void* getNativeWindowHandle() const { return viewHolder->view; }
  203858. juce_UseDebuggingNewOperator
  203859. NSOpenGLContext* renderContext;
  203860. ThreadSafeNSOpenGLView* view;
  203861. private:
  203862. OpenGLPixelFormat pixelFormat;
  203863. ScopedPointer <NSViewComponentInternal> viewHolder;
  203864. WindowedGLContext (const WindowedGLContext&);
  203865. WindowedGLContext& operator= (const WindowedGLContext&);
  203866. };
  203867. OpenGLContext* OpenGLComponent::createContext()
  203868. {
  203869. ScopedPointer<WindowedGLContext> c (new WindowedGLContext (this, preferredPixelFormat,
  203870. contextToShareListsWith != 0 ? (NSOpenGLContext*) contextToShareListsWith->getRawContext() : 0));
  203871. return (c->renderContext != 0) ? c.release() : 0;
  203872. }
  203873. void* OpenGLComponent::getNativeWindowHandle() const
  203874. {
  203875. return context != 0 ? ((WindowedGLContext*) context)->getNativeWindowHandle()
  203876. : 0;
  203877. }
  203878. void juce_glViewport (const int w, const int h)
  203879. {
  203880. glViewport (0, 0, w, h);
  203881. }
  203882. void OpenGLPixelFormat::getAvailablePixelFormats (Component* /*component*/,
  203883. OwnedArray <OpenGLPixelFormat>& results)
  203884. {
  203885. /* GLint attribs [64];
  203886. int n = 0;
  203887. attribs[n++] = AGL_RGBA;
  203888. attribs[n++] = AGL_DOUBLEBUFFER;
  203889. attribs[n++] = AGL_ACCELERATED;
  203890. attribs[n++] = AGL_NO_RECOVERY;
  203891. attribs[n++] = AGL_NONE;
  203892. AGLPixelFormat p = aglChoosePixelFormat (0, 0, attribs);
  203893. while (p != 0)
  203894. {
  203895. OpenGLPixelFormat* const pf = new OpenGLPixelFormat();
  203896. pf->redBits = getAGLAttribute (p, AGL_RED_SIZE);
  203897. pf->greenBits = getAGLAttribute (p, AGL_GREEN_SIZE);
  203898. pf->blueBits = getAGLAttribute (p, AGL_BLUE_SIZE);
  203899. pf->alphaBits = getAGLAttribute (p, AGL_ALPHA_SIZE);
  203900. pf->depthBufferBits = getAGLAttribute (p, AGL_DEPTH_SIZE);
  203901. pf->stencilBufferBits = getAGLAttribute (p, AGL_STENCIL_SIZE);
  203902. pf->accumulationBufferRedBits = getAGLAttribute (p, AGL_ACCUM_RED_SIZE);
  203903. pf->accumulationBufferGreenBits = getAGLAttribute (p, AGL_ACCUM_GREEN_SIZE);
  203904. pf->accumulationBufferBlueBits = getAGLAttribute (p, AGL_ACCUM_BLUE_SIZE);
  203905. pf->accumulationBufferAlphaBits = getAGLAttribute (p, AGL_ACCUM_ALPHA_SIZE);
  203906. results.add (pf);
  203907. p = aglNextPixelFormat (p);
  203908. }*/
  203909. //jassertfalse //xxx can't see how you do this in cocoa!
  203910. }
  203911. #else
  203912. END_JUCE_NAMESPACE
  203913. @interface JuceGLView : UIView
  203914. {
  203915. }
  203916. + (Class) layerClass;
  203917. @end
  203918. @implementation JuceGLView
  203919. + (Class) layerClass
  203920. {
  203921. return [CAEAGLLayer class];
  203922. }
  203923. @end
  203924. BEGIN_JUCE_NAMESPACE
  203925. class GLESContext : public OpenGLContext
  203926. {
  203927. public:
  203928. GLESContext (UIViewComponentPeer* peer,
  203929. Component* const component_,
  203930. const OpenGLPixelFormat& pixelFormat_,
  203931. const GLESContext* const sharedContext,
  203932. NSUInteger apiType)
  203933. : component (component_), pixelFormat (pixelFormat_), glLayer (0), context (0),
  203934. useDepthBuffer (pixelFormat_.depthBufferBits > 0), frameBufferHandle (0), colorBufferHandle (0),
  203935. depthBufferHandle (0), lastWidth (0), lastHeight (0)
  203936. {
  203937. view = [[JuceGLView alloc] initWithFrame: CGRectMake (0, 0, 64, 64)];
  203938. view.opaque = YES;
  203939. view.hidden = NO;
  203940. view.backgroundColor = [UIColor redColor];
  203941. glLayer = (CAEAGLLayer*) [view layer];
  203942. [peer->view addSubview: view];
  203943. if (sharedContext != 0)
  203944. context = [[EAGLContext alloc] initWithAPI: apiType
  203945. sharegroup: [sharedContext->context sharegroup]];
  203946. else
  203947. context = [[EAGLContext alloc] initWithAPI: apiType];
  203948. createGLBuffers();
  203949. }
  203950. ~GLESContext()
  203951. {
  203952. makeInactive();
  203953. [context release];
  203954. [view removeFromSuperview];
  203955. [view release];
  203956. freeGLBuffers();
  203957. }
  203958. bool makeActive() const throw()
  203959. {
  203960. jassert (context != 0);
  203961. [EAGLContext setCurrentContext: context];
  203962. glBindFramebufferOES (GL_FRAMEBUFFER_OES, frameBufferHandle);
  203963. return true;
  203964. }
  203965. void swapBuffers()
  203966. {
  203967. glBindRenderbufferOES (GL_RENDERBUFFER_OES, colorBufferHandle);
  203968. [context presentRenderbuffer: GL_RENDERBUFFER_OES];
  203969. }
  203970. bool makeInactive() const throw()
  203971. {
  203972. return [EAGLContext setCurrentContext: nil];
  203973. }
  203974. bool isActive() const throw()
  203975. {
  203976. return [EAGLContext currentContext] == context;
  203977. }
  203978. const OpenGLPixelFormat getPixelFormat() const { return pixelFormat; }
  203979. void* getRawContext() const throw() { return (void*) glLayer; }
  203980. void updateWindowPosition (int x, int y, int w, int h, int outerWindowHeight)
  203981. {
  203982. view.frame = CGRectMake ((CGFloat) x, (CGFloat) y, (CGFloat) w, (CGFloat) h);
  203983. if (lastWidth != w || lastHeight != h)
  203984. {
  203985. lastWidth = w;
  203986. lastHeight = h;
  203987. freeGLBuffers();
  203988. createGLBuffers();
  203989. }
  203990. }
  203991. bool setSwapInterval (const int numFramesPerSwap)
  203992. {
  203993. numFrames = numFramesPerSwap;
  203994. return true;
  203995. }
  203996. int getSwapInterval() const
  203997. {
  203998. return numFrames;
  203999. }
  204000. void repaint()
  204001. {
  204002. }
  204003. void createGLBuffers()
  204004. {
  204005. makeActive();
  204006. glGenFramebuffersOES (1, &frameBufferHandle);
  204007. glGenRenderbuffersOES (1, &colorBufferHandle);
  204008. glGenRenderbuffersOES (1, &depthBufferHandle);
  204009. glBindRenderbufferOES (GL_RENDERBUFFER_OES, colorBufferHandle);
  204010. [context renderbufferStorage: GL_RENDERBUFFER_OES fromDrawable: glLayer];
  204011. GLint width, height;
  204012. glGetRenderbufferParameterivOES (GL_RENDERBUFFER_OES, GL_RENDERBUFFER_WIDTH_OES, &width);
  204013. glGetRenderbufferParameterivOES (GL_RENDERBUFFER_OES, GL_RENDERBUFFER_HEIGHT_OES, &height);
  204014. if (useDepthBuffer)
  204015. {
  204016. glBindRenderbufferOES (GL_RENDERBUFFER_OES, depthBufferHandle);
  204017. glRenderbufferStorageOES (GL_RENDERBUFFER_OES, GL_DEPTH_COMPONENT16_OES, width, height);
  204018. }
  204019. glBindRenderbufferOES (GL_RENDERBUFFER_OES, colorBufferHandle);
  204020. glBindFramebufferOES (GL_FRAMEBUFFER_OES, frameBufferHandle);
  204021. glFramebufferRenderbufferOES (GL_FRAMEBUFFER_OES, GL_COLOR_ATTACHMENT0_OES, GL_RENDERBUFFER_OES, colorBufferHandle);
  204022. if (useDepthBuffer)
  204023. glFramebufferRenderbufferOES (GL_FRAMEBUFFER_OES, GL_DEPTH_ATTACHMENT_OES, GL_RENDERBUFFER_OES, depthBufferHandle);
  204024. jassert (glCheckFramebufferStatusOES (GL_FRAMEBUFFER_OES) == GL_FRAMEBUFFER_COMPLETE_OES);
  204025. }
  204026. void freeGLBuffers()
  204027. {
  204028. if (frameBufferHandle != 0)
  204029. {
  204030. glDeleteFramebuffersOES (1, &frameBufferHandle);
  204031. frameBufferHandle = 0;
  204032. }
  204033. if (colorBufferHandle != 0)
  204034. {
  204035. glDeleteRenderbuffersOES (1, &colorBufferHandle);
  204036. colorBufferHandle = 0;
  204037. }
  204038. if (depthBufferHandle != 0)
  204039. {
  204040. glDeleteRenderbuffersOES (1, &depthBufferHandle);
  204041. depthBufferHandle = 0;
  204042. }
  204043. }
  204044. juce_UseDebuggingNewOperator
  204045. private:
  204046. Component::SafePointer<Component> component;
  204047. OpenGLPixelFormat pixelFormat;
  204048. JuceGLView* view;
  204049. CAEAGLLayer* glLayer;
  204050. EAGLContext* context;
  204051. bool useDepthBuffer;
  204052. GLuint frameBufferHandle, colorBufferHandle, depthBufferHandle;
  204053. int numFrames;
  204054. int lastWidth, lastHeight;
  204055. GLESContext (const GLESContext&);
  204056. GLESContext& operator= (const GLESContext&);
  204057. };
  204058. OpenGLContext* OpenGLComponent::createContext()
  204059. {
  204060. ScopedAutoReleasePool pool;
  204061. UIViewComponentPeer* peer = dynamic_cast <UIViewComponentPeer*> (getPeer());
  204062. if (peer != 0)
  204063. return new GLESContext (peer, this, preferredPixelFormat,
  204064. dynamic_cast <const GLESContext*> (contextToShareListsWith),
  204065. type == openGLES2 ? kEAGLRenderingAPIOpenGLES2 : kEAGLRenderingAPIOpenGLES1);
  204066. return 0;
  204067. }
  204068. void OpenGLPixelFormat::getAvailablePixelFormats (Component* /*component*/,
  204069. OwnedArray <OpenGLPixelFormat>& /*results*/)
  204070. {
  204071. }
  204072. void juce_glViewport (const int w, const int h)
  204073. {
  204074. glViewport (0, 0, w, h);
  204075. }
  204076. #endif
  204077. #endif
  204078. /*** End of inlined file: juce_mac_OpenGLComponent.mm ***/
  204079. /*** Start of inlined file: juce_mac_MouseCursor.mm ***/
  204080. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  204081. // compiled on its own).
  204082. #if JUCE_INCLUDED_FILE
  204083. #if JUCE_MAC
  204084. Image* juce_loadPNGImageFromStream (InputStream& inputStream);
  204085. void* juce_createMouseCursorFromImage (const Image& image, int hotspotX, int hotspotY) throw()
  204086. {
  204087. NSImage* im = CoreGraphicsImage::createNSImage (image);
  204088. NSCursor* c = [[NSCursor alloc] initWithImage: im
  204089. hotSpot: NSMakePoint (hotspotX, hotspotY)];
  204090. [im release];
  204091. return (void*) c;
  204092. }
  204093. static void* juce_cursorFromData (const unsigned char* data, const size_t size, float hx, float hy) throw()
  204094. {
  204095. MemoryInputStream stream (data, size, false);
  204096. ScopedPointer <Image> im (juce_loadPNGImageFromStream (stream));
  204097. jassert (im != 0);
  204098. if (im == 0)
  204099. return 0;
  204100. return juce_createMouseCursorFromImage (*im,
  204101. (int) (hx * im->getWidth()),
  204102. (int) (hy * im->getHeight()));
  204103. }
  204104. static void* juce_cursorFromWebKitFile (const char* filename, float hx, float hy)
  204105. {
  204106. File f ("/System/Library/Frameworks/WebKit.framework/Frameworks/WebCore.framework/Resources");
  204107. MemoryBlock mb;
  204108. if (f.getChildFile (filename).loadFileAsData (mb))
  204109. return juce_cursorFromData ((const unsigned char*) mb.getData(), mb.getSize(), hx, hy);
  204110. return 0;
  204111. }
  204112. void* juce_createStandardMouseCursor (MouseCursor::StandardCursorType type) throw()
  204113. {
  204114. const ScopedAutoReleasePool pool;
  204115. NSCursor* c = 0;
  204116. switch (type)
  204117. {
  204118. case MouseCursor::NormalCursor:
  204119. c = [NSCursor arrowCursor];
  204120. break;
  204121. case MouseCursor::NoCursor:
  204122. return juce_createMouseCursorFromImage (Image (Image::ARGB, 8, 8, true), 0, 0);
  204123. case MouseCursor::DraggingHandCursor:
  204124. c = [NSCursor openHandCursor];
  204125. break;
  204126. case MouseCursor::CopyingCursor:
  204127. return juce_cursorFromWebKitFile ("copyCursor.png", 0, 0);
  204128. case MouseCursor::WaitCursor:
  204129. c = [NSCursor arrowCursor]; // avoid this on the mac, let the OS provide the beachball
  204130. break;
  204131. //return juce_cursorFromWebKitFile ("waitCursor.png", 0.5f, 0.5f);
  204132. case MouseCursor::IBeamCursor:
  204133. c = [NSCursor IBeamCursor];
  204134. break;
  204135. case MouseCursor::PointingHandCursor:
  204136. c = [NSCursor pointingHandCursor];
  204137. break;
  204138. case MouseCursor::LeftRightResizeCursor:
  204139. c = [NSCursor resizeLeftRightCursor];
  204140. break;
  204141. case MouseCursor::LeftEdgeResizeCursor:
  204142. c = [NSCursor resizeLeftCursor];
  204143. break;
  204144. case MouseCursor::RightEdgeResizeCursor:
  204145. c = [NSCursor resizeRightCursor];
  204146. break;
  204147. case MouseCursor::UpDownResizeCursor:
  204148. case MouseCursor::TopEdgeResizeCursor:
  204149. case MouseCursor::BottomEdgeResizeCursor:
  204150. return juce_cursorFromWebKitFile ("northSouthResizeCursor.png", 0.5f, 0.5f);
  204151. case MouseCursor::TopLeftCornerResizeCursor:
  204152. case MouseCursor::BottomRightCornerResizeCursor:
  204153. return juce_cursorFromWebKitFile ("northWestSouthEastResizeCursor.png", 0.5f, 0.5f);
  204154. case MouseCursor::TopRightCornerResizeCursor:
  204155. case MouseCursor::BottomLeftCornerResizeCursor:
  204156. return juce_cursorFromWebKitFile ("northEastSouthWestResizeCursor.png", 0.5f, 0.5f);
  204157. case MouseCursor::UpDownLeftRightResizeCursor:
  204158. return juce_cursorFromWebKitFile ("moveCursor.png", 0.5f, 0.5f);
  204159. case MouseCursor::CrosshairCursor:
  204160. c = [NSCursor crosshairCursor];
  204161. break;
  204162. }
  204163. [c retain];
  204164. return (void*) c;
  204165. }
  204166. void juce_deleteMouseCursor (void* const cursorHandle, const bool isStandard) throw()
  204167. {
  204168. NSCursor* c = (NSCursor*) cursorHandle;
  204169. [c release];
  204170. }
  204171. void MouseCursor::showInAllWindows() const throw()
  204172. {
  204173. showInWindow (0);
  204174. }
  204175. void MouseCursor::showInWindow (ComponentPeer*) const throw()
  204176. {
  204177. NSCursor* const c = (NSCursor*) getHandle();
  204178. [c set];
  204179. }
  204180. #else
  204181. void* juce_createMouseCursorFromImage (const Image& image, int hotspotX, int hotspotY) throw() { return 0; }
  204182. void* juce_createStandardMouseCursor (MouseCursor::StandardCursorType type) throw() { return 0; }
  204183. void juce_deleteMouseCursor (void* const cursorHandle, const bool isStandard) throw() {}
  204184. void MouseCursor::showInAllWindows() const throw() {}
  204185. void MouseCursor::showInWindow (ComponentPeer*) const throw() {}
  204186. #endif
  204187. #endif
  204188. /*** End of inlined file: juce_mac_MouseCursor.mm ***/
  204189. /*** Start of inlined file: juce_mac_WebBrowserComponent.mm ***/
  204190. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  204191. // compiled on its own).
  204192. #if JUCE_INCLUDED_FILE && JUCE_WEB_BROWSER
  204193. #if JUCE_MAC
  204194. END_JUCE_NAMESPACE
  204195. #define DownloadClickDetector MakeObjCClassName(DownloadClickDetector)
  204196. @interface DownloadClickDetector : NSObject
  204197. {
  204198. JUCE_NAMESPACE::WebBrowserComponent* ownerComponent;
  204199. }
  204200. - (DownloadClickDetector*) initWithWebBrowserOwner: (JUCE_NAMESPACE::WebBrowserComponent*) ownerComponent;
  204201. - (void) webView: (WebView*) webView decidePolicyForNavigationAction: (NSDictionary*) actionInformation
  204202. request: (NSURLRequest*) request
  204203. frame: (WebFrame*) frame
  204204. decisionListener: (id<WebPolicyDecisionListener>) listener;
  204205. @end
  204206. @implementation DownloadClickDetector
  204207. - (DownloadClickDetector*) initWithWebBrowserOwner: (JUCE_NAMESPACE::WebBrowserComponent*) ownerComponent_
  204208. {
  204209. [super init];
  204210. ownerComponent = ownerComponent_;
  204211. return self;
  204212. }
  204213. - (void) webView: (WebView*) sender decidePolicyForNavigationAction: (NSDictionary*) actionInformation
  204214. request: (NSURLRequest*) request
  204215. frame: (WebFrame*) frame
  204216. decisionListener: (id <WebPolicyDecisionListener>) listener
  204217. {
  204218. NSURL* url = [actionInformation valueForKey: @"WebActionOriginalURLKey"];
  204219. if (ownerComponent->pageAboutToLoad (nsStringToJuce ([url absoluteString])))
  204220. [listener use];
  204221. else
  204222. [listener ignore];
  204223. }
  204224. @end
  204225. BEGIN_JUCE_NAMESPACE
  204226. class WebBrowserComponentInternal : public NSViewComponent
  204227. {
  204228. public:
  204229. WebBrowserComponentInternal (WebBrowserComponent* owner)
  204230. {
  204231. webView = [[WebView alloc] initWithFrame: NSMakeRect (0, 0, 100.0f, 100.0f)
  204232. frameName: @""
  204233. groupName: @""];
  204234. setView (webView);
  204235. clickListener = [[DownloadClickDetector alloc] initWithWebBrowserOwner: owner];
  204236. [webView setPolicyDelegate: clickListener];
  204237. }
  204238. ~WebBrowserComponentInternal()
  204239. {
  204240. [webView setPolicyDelegate: nil];
  204241. [clickListener release];
  204242. setView (0);
  204243. }
  204244. void goToURL (const String& url,
  204245. const StringArray* headers,
  204246. const MemoryBlock* postData)
  204247. {
  204248. NSMutableURLRequest* r
  204249. = [NSMutableURLRequest requestWithURL: [NSURL URLWithString: juceStringToNS (url)]
  204250. cachePolicy: NSURLRequestUseProtocolCachePolicy
  204251. timeoutInterval: 30.0];
  204252. if (postData != 0 && postData->getSize() > 0)
  204253. {
  204254. [r setHTTPMethod: @"POST"];
  204255. [r setHTTPBody: [NSData dataWithBytes: postData->getData()
  204256. length: postData->getSize()]];
  204257. }
  204258. if (headers != 0)
  204259. {
  204260. for (int i = 0; i < headers->size(); ++i)
  204261. {
  204262. const String headerName ((*headers)[i].upToFirstOccurrenceOf (T(":"), false, false).trim());
  204263. const String headerValue ((*headers)[i].fromFirstOccurrenceOf (T(":"), false, false).trim());
  204264. [r setValue: juceStringToNS (headerValue)
  204265. forHTTPHeaderField: juceStringToNS (headerName)];
  204266. }
  204267. }
  204268. stop();
  204269. [[webView mainFrame] loadRequest: r];
  204270. }
  204271. void goBack()
  204272. {
  204273. [webView goBack];
  204274. }
  204275. void goForward()
  204276. {
  204277. [webView goForward];
  204278. }
  204279. void stop()
  204280. {
  204281. [webView stopLoading: nil];
  204282. }
  204283. void refresh()
  204284. {
  204285. [webView reload: nil];
  204286. }
  204287. private:
  204288. WebView* webView;
  204289. DownloadClickDetector* clickListener;
  204290. };
  204291. WebBrowserComponent::WebBrowserComponent (const bool unloadPageWhenBrowserIsHidden_)
  204292. : browser (0),
  204293. blankPageShown (false),
  204294. unloadPageWhenBrowserIsHidden (unloadPageWhenBrowserIsHidden_)
  204295. {
  204296. setOpaque (true);
  204297. addAndMakeVisible (browser = new WebBrowserComponentInternal (this));
  204298. }
  204299. WebBrowserComponent::~WebBrowserComponent()
  204300. {
  204301. deleteAndZero (browser);
  204302. }
  204303. void WebBrowserComponent::goToURL (const String& url,
  204304. const StringArray* headers,
  204305. const MemoryBlock* postData)
  204306. {
  204307. lastURL = url;
  204308. lastHeaders.clear();
  204309. if (headers != 0)
  204310. lastHeaders = *headers;
  204311. lastPostData.setSize (0);
  204312. if (postData != 0)
  204313. lastPostData = *postData;
  204314. blankPageShown = false;
  204315. browser->goToURL (url, headers, postData);
  204316. }
  204317. void WebBrowserComponent::stop()
  204318. {
  204319. browser->stop();
  204320. }
  204321. void WebBrowserComponent::goBack()
  204322. {
  204323. lastURL = String::empty;
  204324. blankPageShown = false;
  204325. browser->goBack();
  204326. }
  204327. void WebBrowserComponent::goForward()
  204328. {
  204329. lastURL = String::empty;
  204330. browser->goForward();
  204331. }
  204332. void WebBrowserComponent::refresh()
  204333. {
  204334. browser->refresh();
  204335. }
  204336. void WebBrowserComponent::paint (Graphics& g)
  204337. {
  204338. }
  204339. void WebBrowserComponent::checkWindowAssociation()
  204340. {
  204341. if (isShowing())
  204342. {
  204343. if (blankPageShown)
  204344. goBack();
  204345. }
  204346. else
  204347. {
  204348. if (unloadPageWhenBrowserIsHidden && ! blankPageShown)
  204349. {
  204350. // when the component becomes invisible, some stuff like flash
  204351. // carries on playing audio, so we need to force it onto a blank
  204352. // page to avoid this, (and send it back when it's made visible again).
  204353. blankPageShown = true;
  204354. browser->goToURL ("about:blank", 0, 0);
  204355. }
  204356. }
  204357. }
  204358. void WebBrowserComponent::reloadLastURL()
  204359. {
  204360. if (lastURL.isNotEmpty())
  204361. {
  204362. goToURL (lastURL, &lastHeaders, &lastPostData);
  204363. lastURL = String::empty;
  204364. }
  204365. }
  204366. void WebBrowserComponent::parentHierarchyChanged()
  204367. {
  204368. checkWindowAssociation();
  204369. }
  204370. void WebBrowserComponent::resized()
  204371. {
  204372. browser->setSize (getWidth(), getHeight());
  204373. }
  204374. void WebBrowserComponent::visibilityChanged()
  204375. {
  204376. checkWindowAssociation();
  204377. }
  204378. bool WebBrowserComponent::pageAboutToLoad (const String& url)
  204379. {
  204380. return true;
  204381. }
  204382. #else
  204383. WebBrowserComponent::WebBrowserComponent (const bool unloadPageWhenBrowserIsHidden_)
  204384. {
  204385. }
  204386. WebBrowserComponent::~WebBrowserComponent()
  204387. {
  204388. }
  204389. void WebBrowserComponent::goToURL (const String& url,
  204390. const StringArray* headers,
  204391. const MemoryBlock* postData)
  204392. {
  204393. }
  204394. void WebBrowserComponent::stop()
  204395. {
  204396. }
  204397. void WebBrowserComponent::goBack()
  204398. {
  204399. }
  204400. void WebBrowserComponent::goForward()
  204401. {
  204402. }
  204403. void WebBrowserComponent::refresh()
  204404. {
  204405. }
  204406. void WebBrowserComponent::paint (Graphics& g)
  204407. {
  204408. }
  204409. void WebBrowserComponent::checkWindowAssociation()
  204410. {
  204411. }
  204412. void WebBrowserComponent::reloadLastURL()
  204413. {
  204414. }
  204415. void WebBrowserComponent::parentHierarchyChanged()
  204416. {
  204417. }
  204418. void WebBrowserComponent::resized()
  204419. {
  204420. }
  204421. void WebBrowserComponent::visibilityChanged()
  204422. {
  204423. }
  204424. bool WebBrowserComponent::pageAboutToLoad (const String& url)
  204425. {
  204426. return true;
  204427. }
  204428. #endif
  204429. #endif
  204430. /*** End of inlined file: juce_mac_WebBrowserComponent.mm ***/
  204431. /*** Start of inlined file: juce_iphone_Audio.cpp ***/
  204432. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  204433. // compiled on its own).
  204434. #if JUCE_INCLUDED_FILE
  204435. class IPhoneAudioIODevice : public AudioIODevice
  204436. {
  204437. public:
  204438. IPhoneAudioIODevice (const String& deviceName)
  204439. : AudioIODevice (deviceName, T("Audio")),
  204440. audioUnit (0),
  204441. isRunning (false),
  204442. callback (0),
  204443. actualBufferSize (0),
  204444. floatData (1, 2)
  204445. {
  204446. numInputChannels = 2;
  204447. numOutputChannels = 2;
  204448. preferredBufferSize = 0;
  204449. AudioSessionInitialize (0, 0, interruptionListenerStatic, this);
  204450. updateDeviceInfo();
  204451. }
  204452. ~IPhoneAudioIODevice()
  204453. {
  204454. close();
  204455. }
  204456. const StringArray getOutputChannelNames()
  204457. {
  204458. StringArray s;
  204459. s.add ("Left");
  204460. s.add ("Right");
  204461. return s;
  204462. }
  204463. const StringArray getInputChannelNames()
  204464. {
  204465. StringArray s;
  204466. if (audioInputIsAvailable)
  204467. {
  204468. s.add ("Left");
  204469. s.add ("Right");
  204470. }
  204471. return s;
  204472. }
  204473. int getNumSampleRates()
  204474. {
  204475. return 1;
  204476. }
  204477. double getSampleRate (int index)
  204478. {
  204479. return sampleRate;
  204480. }
  204481. int getNumBufferSizesAvailable()
  204482. {
  204483. return 1;
  204484. }
  204485. int getBufferSizeSamples (int index)
  204486. {
  204487. return getDefaultBufferSize();
  204488. }
  204489. int getDefaultBufferSize()
  204490. {
  204491. return 1024;
  204492. }
  204493. const String open (const BigInteger& inputChannels,
  204494. const BigInteger& outputChannels,
  204495. double sampleRate,
  204496. int bufferSize)
  204497. {
  204498. close();
  204499. lastError = String::empty;
  204500. preferredBufferSize = (bufferSize <= 0) ? getDefaultBufferSize() : bufferSize;
  204501. // xxx set up channel mapping
  204502. activeOutputChans = outputChannels;
  204503. activeOutputChans.setRange (2, activeOutputChans.getHighestBit(), false);
  204504. numOutputChannels = activeOutputChans.countNumberOfSetBits();
  204505. monoOutputChannelNumber = activeOutputChans.findNextSetBit (0);
  204506. activeInputChans = inputChannels;
  204507. activeInputChans.setRange (2, activeInputChans.getHighestBit(), false);
  204508. numInputChannels = activeInputChans.countNumberOfSetBits();
  204509. monoInputChannelNumber = activeInputChans.findNextSetBit (0);
  204510. AudioSessionSetActive (true);
  204511. UInt32 audioCategory = kAudioSessionCategory_PlayAndRecord;
  204512. AudioSessionSetProperty (kAudioSessionProperty_AudioCategory, sizeof (audioCategory), &audioCategory);
  204513. AudioSessionAddPropertyListener (kAudioSessionProperty_AudioRouteChange, propertyChangedStatic, this);
  204514. fixAudioRouteIfSetToReceiver();
  204515. updateDeviceInfo();
  204516. Float32 bufferDuration = preferredBufferSize / sampleRate;
  204517. AudioSessionSetProperty (kAudioSessionProperty_PreferredHardwareIOBufferDuration, sizeof (bufferDuration), &bufferDuration);
  204518. actualBufferSize = preferredBufferSize;
  204519. prepareFloatBuffers();
  204520. isRunning = true;
  204521. propertyChanged (0, 0, 0); // creates and starts the AU
  204522. lastError = audioUnit != 0 ? String::empty
  204523. : T("Couldn't open the device");
  204524. return lastError;
  204525. }
  204526. void close()
  204527. {
  204528. if (isRunning)
  204529. {
  204530. isRunning = false;
  204531. AudioSessionSetActive (false);
  204532. if (audioUnit != 0)
  204533. {
  204534. AudioComponentInstanceDispose (audioUnit);
  204535. audioUnit = 0;
  204536. }
  204537. }
  204538. }
  204539. bool isOpen()
  204540. {
  204541. return isRunning;
  204542. }
  204543. int getCurrentBufferSizeSamples()
  204544. {
  204545. return actualBufferSize;
  204546. }
  204547. double getCurrentSampleRate()
  204548. {
  204549. return sampleRate;
  204550. }
  204551. int getCurrentBitDepth()
  204552. {
  204553. return 16;
  204554. }
  204555. const BigInteger getActiveOutputChannels() const
  204556. {
  204557. return activeOutputChans;
  204558. }
  204559. const BigInteger getActiveInputChannels() const
  204560. {
  204561. return activeInputChans;
  204562. }
  204563. int getOutputLatencyInSamples()
  204564. {
  204565. return 0; //xxx
  204566. }
  204567. int getInputLatencyInSamples()
  204568. {
  204569. return 0; //xxx
  204570. }
  204571. void start (AudioIODeviceCallback* callback_)
  204572. {
  204573. if (isRunning && callback != callback_)
  204574. {
  204575. if (callback_ != 0)
  204576. callback_->audioDeviceAboutToStart (this);
  204577. const ScopedLock sl (callbackLock);
  204578. callback = callback_;
  204579. }
  204580. }
  204581. void stop()
  204582. {
  204583. if (isRunning)
  204584. {
  204585. AudioIODeviceCallback* lastCallback;
  204586. {
  204587. const ScopedLock sl (callbackLock);
  204588. lastCallback = callback;
  204589. callback = 0;
  204590. }
  204591. if (lastCallback != 0)
  204592. lastCallback->audioDeviceStopped();
  204593. }
  204594. }
  204595. bool isPlaying()
  204596. {
  204597. return isRunning && callback != 0;
  204598. }
  204599. const String getLastError()
  204600. {
  204601. return lastError;
  204602. }
  204603. private:
  204604. CriticalSection callbackLock;
  204605. Float64 sampleRate;
  204606. int numInputChannels, numOutputChannels;
  204607. int preferredBufferSize;
  204608. int actualBufferSize;
  204609. bool isRunning;
  204610. String lastError;
  204611. AudioStreamBasicDescription format;
  204612. AudioUnit audioUnit;
  204613. UInt32 audioInputIsAvailable;
  204614. AudioIODeviceCallback* callback;
  204615. BigInteger activeOutputChans, activeInputChans;
  204616. AudioSampleBuffer floatData;
  204617. float* inputChannels[3];
  204618. float* outputChannels[3];
  204619. bool monoInputChannelNumber, monoOutputChannelNumber;
  204620. void prepareFloatBuffers()
  204621. {
  204622. floatData.setSize (numInputChannels + numOutputChannels, actualBufferSize);
  204623. zerostruct (inputChannels);
  204624. zerostruct (outputChannels);
  204625. for (int i = 0; i < numInputChannels; ++i)
  204626. inputChannels[i] = floatData.getSampleData (i);
  204627. for (int i = 0; i < numOutputChannels; ++i)
  204628. outputChannels[i] = floatData.getSampleData (i + numInputChannels);
  204629. }
  204630. OSStatus process (AudioUnitRenderActionFlags* ioActionFlags, const AudioTimeStamp* inTimeStamp,
  204631. UInt32 inBusNumber, UInt32 inNumberFrames, AudioBufferList* ioData)
  204632. {
  204633. OSStatus err = noErr;
  204634. if (audioInputIsAvailable)
  204635. err = AudioUnitRender (audioUnit, ioActionFlags, inTimeStamp, 1, inNumberFrames, ioData);
  204636. const ScopedLock sl (callbackLock);
  204637. if (callback != 0)
  204638. {
  204639. if (audioInputIsAvailable && numInputChannels > 0)
  204640. {
  204641. short* shortData = (short*) ioData->mBuffers[0].mData;
  204642. if (numInputChannels >= 2)
  204643. {
  204644. for (UInt32 i = 0; i < inNumberFrames; ++i)
  204645. {
  204646. inputChannels[0][i] = *shortData++ * (1.0f / 32768.0f);
  204647. inputChannels[1][i] = *shortData++ * (1.0f / 32768.0f);
  204648. }
  204649. }
  204650. else
  204651. {
  204652. if (monoInputChannelNumber > 0)
  204653. ++shortData;
  204654. for (UInt32 i = 0; i < inNumberFrames; ++i)
  204655. {
  204656. inputChannels[0][i] = *shortData++ * (1.0f / 32768.0f);
  204657. ++shortData;
  204658. }
  204659. }
  204660. }
  204661. else
  204662. {
  204663. for (int i = numInputChannels; --i >= 0;)
  204664. zeromem (inputChannels[i], sizeof (float) * inNumberFrames);
  204665. }
  204666. callback->audioDeviceIOCallback ((const float**) inputChannels, numInputChannels,
  204667. outputChannels, numOutputChannels,
  204668. (int) inNumberFrames);
  204669. short* shortData = (short*) ioData->mBuffers[0].mData;
  204670. int n = 0;
  204671. if (numOutputChannels >= 2)
  204672. {
  204673. for (UInt32 i = 0; i < inNumberFrames; ++i)
  204674. {
  204675. shortData [n++] = (short) (outputChannels[0][i] * 32767.0f);
  204676. shortData [n++] = (short) (outputChannels[1][i] * 32767.0f);
  204677. }
  204678. }
  204679. else if (numOutputChannels == 1)
  204680. {
  204681. for (UInt32 i = 0; i < inNumberFrames; ++i)
  204682. {
  204683. const short s = (short) (outputChannels[monoOutputChannelNumber][i] * 32767.0f);
  204684. shortData [n++] = s;
  204685. shortData [n++] = s;
  204686. }
  204687. }
  204688. else
  204689. {
  204690. zeromem (ioData->mBuffers[0].mData, 2 * sizeof (short) * inNumberFrames);
  204691. }
  204692. }
  204693. else
  204694. {
  204695. zeromem (ioData->mBuffers[0].mData, 2 * sizeof (short) * inNumberFrames);
  204696. }
  204697. return err;
  204698. }
  204699. void updateDeviceInfo()
  204700. {
  204701. UInt32 size = sizeof (sampleRate);
  204702. AudioSessionGetProperty (kAudioSessionProperty_CurrentHardwareSampleRate, &size, &sampleRate);
  204703. size = sizeof (audioInputIsAvailable);
  204704. AudioSessionGetProperty (kAudioSessionProperty_AudioInputAvailable, &size, &audioInputIsAvailable);
  204705. }
  204706. void propertyChanged (AudioSessionPropertyID inID, UInt32 inDataSize, const void* inPropertyValue)
  204707. {
  204708. if (! isRunning)
  204709. return;
  204710. if (inPropertyValue != 0)
  204711. {
  204712. CFDictionaryRef routeChangeDictionary = (CFDictionaryRef) inPropertyValue;
  204713. CFNumberRef routeChangeReasonRef = (CFNumberRef) CFDictionaryGetValue (routeChangeDictionary,
  204714. CFSTR (kAudioSession_AudioRouteChangeKey_Reason));
  204715. SInt32 routeChangeReason;
  204716. CFNumberGetValue (routeChangeReasonRef, kCFNumberSInt32Type, &routeChangeReason);
  204717. if (routeChangeReason == kAudioSessionRouteChangeReason_OldDeviceUnavailable)
  204718. fixAudioRouteIfSetToReceiver();
  204719. }
  204720. updateDeviceInfo();
  204721. createAudioUnit();
  204722. AudioSessionSetActive (true);
  204723. if (audioUnit != 0)
  204724. {
  204725. UInt32 formatSize = sizeof (format);
  204726. AudioUnitGetProperty (audioUnit, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Output, 1, &format, &formatSize);
  204727. Float32 bufferDuration = preferredBufferSize / sampleRate;
  204728. UInt32 bufferDurationSize = sizeof (bufferDuration);
  204729. AudioSessionGetProperty (kAudioSessionProperty_CurrentHardwareIOBufferDuration, &bufferDurationSize, &bufferDurationSize);
  204730. actualBufferSize = (int) (sampleRate * bufferDuration + 0.5);
  204731. AudioOutputUnitStart (audioUnit);
  204732. }
  204733. }
  204734. void interruptionListener (UInt32 inInterruption)
  204735. {
  204736. if (inInterruption == kAudioSessionEndInterruption)
  204737. {
  204738. isRunning = true;
  204739. AudioSessionSetActive (true);
  204740. AudioOutputUnitStart (audioUnit);
  204741. }
  204742. }
  204743. static OSStatus processStatic (void* inRefCon, AudioUnitRenderActionFlags* ioActionFlags, const AudioTimeStamp* inTimeStamp,
  204744. UInt32 inBusNumber, UInt32 inNumberFrames, AudioBufferList* ioData)
  204745. {
  204746. return ((IPhoneAudioIODevice*) inRefCon)->process (ioActionFlags, inTimeStamp, inBusNumber, inNumberFrames, ioData);
  204747. }
  204748. static void propertyChangedStatic (void* inClientData, AudioSessionPropertyID inID, UInt32 inDataSize, const void* inPropertyValue)
  204749. {
  204750. ((IPhoneAudioIODevice*) inClientData)->propertyChanged (inID, inDataSize, inPropertyValue);
  204751. }
  204752. static void interruptionListenerStatic (void* inClientData, UInt32 inInterruption)
  204753. {
  204754. ((IPhoneAudioIODevice*) inClientData)->interruptionListener (inInterruption);
  204755. }
  204756. void resetFormat (const int numChannels)
  204757. {
  204758. memset (&format, 0, sizeof (format));
  204759. format.mFormatID = kAudioFormatLinearPCM;
  204760. format.mFormatFlags = kLinearPCMFormatFlagIsSignedInteger | kLinearPCMFormatFlagIsPacked;
  204761. format.mBitsPerChannel = 8 * sizeof (short);
  204762. format.mChannelsPerFrame = 2;
  204763. format.mFramesPerPacket = 1;
  204764. format.mBytesPerFrame = format.mBytesPerPacket = 2 * sizeof (short);
  204765. }
  204766. bool createAudioUnit()
  204767. {
  204768. if (audioUnit != 0)
  204769. {
  204770. AudioComponentInstanceDispose (audioUnit);
  204771. audioUnit = 0;
  204772. }
  204773. resetFormat (2);
  204774. AudioComponentDescription desc;
  204775. desc.componentType = kAudioUnitType_Output;
  204776. desc.componentSubType = kAudioUnitSubType_RemoteIO;
  204777. desc.componentManufacturer = kAudioUnitManufacturer_Apple;
  204778. desc.componentFlags = 0;
  204779. desc.componentFlagsMask = 0;
  204780. AudioComponent comp = AudioComponentFindNext (0, &desc);
  204781. AudioComponentInstanceNew (comp, &audioUnit);
  204782. if (audioUnit == 0)
  204783. return false;
  204784. const UInt32 one = 1;
  204785. AudioUnitSetProperty (audioUnit, kAudioOutputUnitProperty_EnableIO, kAudioUnitScope_Input, 1, &one, sizeof (one));
  204786. AudioChannelLayout layout;
  204787. layout.mChannelBitmap = 0;
  204788. layout.mNumberChannelDescriptions = 0;
  204789. layout.mChannelLayoutTag = kAudioChannelLayoutTag_Stereo;
  204790. AudioUnitSetProperty (audioUnit, kAudioUnitProperty_AudioChannelLayout, kAudioUnitScope_Input, 0, &layout, sizeof (layout));
  204791. AudioUnitSetProperty (audioUnit, kAudioUnitProperty_AudioChannelLayout, kAudioUnitScope_Output, 0, &layout, sizeof (layout));
  204792. AURenderCallbackStruct inputProc;
  204793. inputProc.inputProc = processStatic;
  204794. inputProc.inputProcRefCon = this;
  204795. AudioUnitSetProperty (audioUnit, kAudioUnitProperty_SetRenderCallback, kAudioUnitScope_Input, 0, &inputProc, sizeof (inputProc));
  204796. AudioUnitSetProperty (audioUnit, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Input, 0, &format, sizeof (format));
  204797. AudioUnitSetProperty (audioUnit, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Output, 1, &format, sizeof (format));
  204798. AudioUnitInitialize (audioUnit);
  204799. return true;
  204800. }
  204801. // If the routing is set to go through the receiver (i.e. the speaker, but quiet), this re-routes it
  204802. // to make it loud. Needed because by default when using an input + output, the output is kept quiet.
  204803. static void fixAudioRouteIfSetToReceiver()
  204804. {
  204805. CFStringRef audioRoute = 0;
  204806. UInt32 propertySize = sizeof (audioRoute);
  204807. if (AudioSessionGetProperty (kAudioSessionProperty_AudioRoute, &propertySize, &audioRoute) == noErr)
  204808. {
  204809. NSString* route = (NSString*) audioRoute;
  204810. //DBG ("audio route: " + nsStringToJuce (route));
  204811. if ([route hasPrefix: @"Receiver"])
  204812. {
  204813. UInt32 audioRouteOverride = kAudioSessionOverrideAudioRoute_Speaker;
  204814. AudioSessionSetProperty (kAudioSessionProperty_OverrideAudioRoute, sizeof (audioRouteOverride), &audioRouteOverride);
  204815. }
  204816. CFRelease (audioRoute);
  204817. }
  204818. }
  204819. IPhoneAudioIODevice (const IPhoneAudioIODevice&);
  204820. IPhoneAudioIODevice& operator= (const IPhoneAudioIODevice&);
  204821. };
  204822. class IPhoneAudioIODeviceType : public AudioIODeviceType
  204823. {
  204824. public:
  204825. IPhoneAudioIODeviceType()
  204826. : AudioIODeviceType (T("iPhone Audio"))
  204827. {
  204828. }
  204829. ~IPhoneAudioIODeviceType()
  204830. {
  204831. }
  204832. void scanForDevices()
  204833. {
  204834. }
  204835. const StringArray getDeviceNames (const bool wantInputNames) const
  204836. {
  204837. StringArray s;
  204838. s.add ("iPhone Audio");
  204839. return s;
  204840. }
  204841. int getDefaultDeviceIndex (const bool forInput) const
  204842. {
  204843. return 0;
  204844. }
  204845. int getIndexOfDevice (AudioIODevice* device, const bool asInput) const
  204846. {
  204847. return device != 0 ? 0 : -1;
  204848. }
  204849. bool hasSeparateInputsAndOutputs() const { return false; }
  204850. AudioIODevice* createDevice (const String& outputDeviceName,
  204851. const String& inputDeviceName)
  204852. {
  204853. if (outputDeviceName.isNotEmpty() || inputDeviceName.isNotEmpty())
  204854. {
  204855. return new IPhoneAudioIODevice (outputDeviceName.isNotEmpty() ? outputDeviceName
  204856. : inputDeviceName);
  204857. }
  204858. return 0;
  204859. }
  204860. juce_UseDebuggingNewOperator
  204861. private:
  204862. IPhoneAudioIODeviceType (const IPhoneAudioIODeviceType&);
  204863. IPhoneAudioIODeviceType& operator= (const IPhoneAudioIODeviceType&);
  204864. };
  204865. AudioIODeviceType* juce_createAudioIODeviceType_iPhoneAudio()
  204866. {
  204867. return new IPhoneAudioIODeviceType();
  204868. }
  204869. #endif
  204870. /*** End of inlined file: juce_iphone_Audio.cpp ***/
  204871. /*** Start of inlined file: juce_mac_CoreMidi.cpp ***/
  204872. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  204873. // compiled on its own).
  204874. #if JUCE_INCLUDED_FILE
  204875. #if JUCE_MAC
  204876. #undef log
  204877. #define log(a) Logger::writeToLog(a)
  204878. static bool logAnyErrorsMidi (const OSStatus err, const int lineNum)
  204879. {
  204880. if (err == noErr)
  204881. return true;
  204882. log (T("CoreMidi error: ") + String (lineNum) + T(" - ") + String::toHexString ((int)err));
  204883. jassertfalse
  204884. return false;
  204885. }
  204886. #undef OK
  204887. #define OK(a) logAnyErrorsMidi(a, __LINE__)
  204888. static const String getEndpointName (MIDIEndpointRef endpoint, bool isExternal)
  204889. {
  204890. String result;
  204891. CFStringRef str = 0;
  204892. MIDIObjectGetStringProperty (endpoint, kMIDIPropertyName, &str);
  204893. if (str != 0)
  204894. {
  204895. result = PlatformUtilities::cfStringToJuceString (str);
  204896. CFRelease (str);
  204897. str = 0;
  204898. }
  204899. MIDIEntityRef entity = 0;
  204900. MIDIEndpointGetEntity (endpoint, &entity);
  204901. if (entity == 0)
  204902. return result; // probably virtual
  204903. if (result.isEmpty())
  204904. {
  204905. // endpoint name has zero length - try the entity
  204906. MIDIObjectGetStringProperty (entity, kMIDIPropertyName, &str);
  204907. if (str != 0)
  204908. {
  204909. result += PlatformUtilities::cfStringToJuceString (str);
  204910. CFRelease (str);
  204911. str = 0;
  204912. }
  204913. }
  204914. // now consider the device's name
  204915. MIDIDeviceRef device = 0;
  204916. MIDIEntityGetDevice (entity, &device);
  204917. if (device == 0)
  204918. return result;
  204919. MIDIObjectGetStringProperty (device, kMIDIPropertyName, &str);
  204920. if (str != 0)
  204921. {
  204922. const String s (PlatformUtilities::cfStringToJuceString (str));
  204923. CFRelease (str);
  204924. // if an external device has only one entity, throw away
  204925. // the endpoint name and just use the device name
  204926. if (isExternal && MIDIDeviceGetNumberOfEntities (device) < 2)
  204927. {
  204928. result = s;
  204929. }
  204930. else if (! result.startsWithIgnoreCase (s))
  204931. {
  204932. // prepend the device name to the entity name
  204933. result = (s + T(" ") + result).trimEnd();
  204934. }
  204935. }
  204936. return result;
  204937. }
  204938. static const String getConnectedEndpointName (MIDIEndpointRef endpoint)
  204939. {
  204940. String result;
  204941. // Does the endpoint have connections?
  204942. CFDataRef connections = 0;
  204943. int numConnections = 0;
  204944. MIDIObjectGetDataProperty (endpoint, kMIDIPropertyConnectionUniqueID, &connections);
  204945. if (connections != 0)
  204946. {
  204947. numConnections = (int) (CFDataGetLength (connections) / sizeof (MIDIUniqueID));
  204948. if (numConnections > 0)
  204949. {
  204950. const SInt32* pid = reinterpret_cast <const SInt32*> (CFDataGetBytePtr (connections));
  204951. for (int i = 0; i < numConnections; ++i, ++pid)
  204952. {
  204953. MIDIUniqueID uid = EndianS32_BtoN (*pid);
  204954. MIDIObjectRef connObject;
  204955. MIDIObjectType connObjectType;
  204956. OSStatus err = MIDIObjectFindByUniqueID (uid, &connObject, &connObjectType);
  204957. if (err == noErr)
  204958. {
  204959. String s;
  204960. if (connObjectType == kMIDIObjectType_ExternalSource
  204961. || connObjectType == kMIDIObjectType_ExternalDestination)
  204962. {
  204963. // Connected to an external device's endpoint (10.3 and later).
  204964. s = getEndpointName (static_cast <MIDIEndpointRef> (connObject), true);
  204965. }
  204966. else
  204967. {
  204968. // Connected to an external device (10.2) (or something else, catch-all)
  204969. CFStringRef str = 0;
  204970. MIDIObjectGetStringProperty (connObject, kMIDIPropertyName, &str);
  204971. if (str != 0)
  204972. {
  204973. s = PlatformUtilities::cfStringToJuceString (str);
  204974. CFRelease (str);
  204975. }
  204976. }
  204977. if (s.isNotEmpty())
  204978. {
  204979. if (result.isNotEmpty())
  204980. result += (", ");
  204981. result += s;
  204982. }
  204983. }
  204984. }
  204985. }
  204986. CFRelease (connections);
  204987. }
  204988. if (result.isNotEmpty())
  204989. return result;
  204990. // Here, either the endpoint had no connections, or we failed to obtain names for any of them.
  204991. return getEndpointName (endpoint, false);
  204992. }
  204993. const StringArray MidiOutput::getDevices()
  204994. {
  204995. StringArray s;
  204996. const ItemCount num = MIDIGetNumberOfDestinations();
  204997. for (ItemCount i = 0; i < num; ++i)
  204998. {
  204999. MIDIEndpointRef dest = MIDIGetDestination (i);
  205000. if (dest != 0)
  205001. {
  205002. String name (getConnectedEndpointName (dest));
  205003. if (name.isEmpty())
  205004. name = "<error>";
  205005. s.add (name);
  205006. }
  205007. else
  205008. {
  205009. s.add ("<error>");
  205010. }
  205011. }
  205012. return s;
  205013. }
  205014. int MidiOutput::getDefaultDeviceIndex()
  205015. {
  205016. return 0;
  205017. }
  205018. static MIDIClientRef globalMidiClient;
  205019. static bool hasGlobalClientBeenCreated = false;
  205020. static bool makeSureClientExists()
  205021. {
  205022. if (! hasGlobalClientBeenCreated)
  205023. {
  205024. String name (T("JUCE"));
  205025. if (JUCEApplication::getInstance() != 0)
  205026. name = JUCEApplication::getInstance()->getApplicationName();
  205027. CFStringRef appName = PlatformUtilities::juceStringToCFString (name);
  205028. hasGlobalClientBeenCreated = OK (MIDIClientCreate (appName, 0, 0, &globalMidiClient));
  205029. CFRelease (appName);
  205030. }
  205031. return hasGlobalClientBeenCreated;
  205032. }
  205033. class MidiPortAndEndpoint
  205034. {
  205035. public:
  205036. MidiPortAndEndpoint (MIDIPortRef port_, MIDIEndpointRef endPoint_)
  205037. : port (port_), endPoint (endPoint_)
  205038. {
  205039. }
  205040. ~MidiPortAndEndpoint()
  205041. {
  205042. if (port != 0)
  205043. MIDIPortDispose (port);
  205044. if (port == 0 && endPoint != 0) // if port == 0, it means we created the endpoint, so it's safe to delete it
  205045. MIDIEndpointDispose (endPoint);
  205046. }
  205047. MIDIPortRef port;
  205048. MIDIEndpointRef endPoint;
  205049. };
  205050. MidiOutput* MidiOutput::openDevice (int index)
  205051. {
  205052. MidiOutput* mo = 0;
  205053. if (((unsigned int) index) < (unsigned int) MIDIGetNumberOfDestinations())
  205054. {
  205055. MIDIEndpointRef endPoint = MIDIGetDestination (index);
  205056. CFStringRef pname;
  205057. if (OK (MIDIObjectGetStringProperty (endPoint, kMIDIPropertyName, &pname)))
  205058. {
  205059. log (T("CoreMidi - opening out: ") + PlatformUtilities::cfStringToJuceString (pname));
  205060. if (makeSureClientExists())
  205061. {
  205062. MIDIPortRef port;
  205063. if (OK (MIDIOutputPortCreate (globalMidiClient, pname, &port)))
  205064. {
  205065. mo = new MidiOutput();
  205066. mo->internal = (void*) new MidiPortAndEndpoint (port, endPoint);
  205067. }
  205068. }
  205069. CFRelease (pname);
  205070. }
  205071. }
  205072. return mo;
  205073. }
  205074. MidiOutput* MidiOutput::createNewDevice (const String& deviceName)
  205075. {
  205076. MidiOutput* mo = 0;
  205077. if (makeSureClientExists())
  205078. {
  205079. MIDIEndpointRef endPoint;
  205080. CFStringRef name = PlatformUtilities::juceStringToCFString (deviceName);
  205081. if (OK (MIDISourceCreate (globalMidiClient, name, &endPoint)))
  205082. {
  205083. mo = new MidiOutput();
  205084. mo->internal = (void*) new MidiPortAndEndpoint (0, endPoint);
  205085. }
  205086. CFRelease (name);
  205087. }
  205088. return mo;
  205089. }
  205090. MidiOutput::~MidiOutput()
  205091. {
  205092. delete (MidiPortAndEndpoint*) internal;
  205093. }
  205094. void MidiOutput::reset()
  205095. {
  205096. }
  205097. bool MidiOutput::getVolume (float& leftVol, float& rightVol)
  205098. {
  205099. return false;
  205100. }
  205101. void MidiOutput::setVolume (float leftVol, float rightVol)
  205102. {
  205103. }
  205104. void MidiOutput::sendMessageNow (const MidiMessage& message)
  205105. {
  205106. MidiPortAndEndpoint* const mpe = (MidiPortAndEndpoint*) internal;
  205107. if (message.isSysEx())
  205108. {
  205109. const int maxPacketSize = 256;
  205110. int pos = 0, bytesLeft = message.getRawDataSize();
  205111. const int numPackets = (bytesLeft + maxPacketSize - 1) / maxPacketSize;
  205112. HeapBlock <MIDIPacketList> packets;
  205113. packets.malloc (32 * numPackets + message.getRawDataSize(), 1);
  205114. packets->numPackets = numPackets;
  205115. MIDIPacket* p = packets->packet;
  205116. for (int i = 0; i < numPackets; ++i)
  205117. {
  205118. p->timeStamp = 0;
  205119. p->length = jmin (maxPacketSize, bytesLeft);
  205120. memcpy (p->data, message.getRawData() + pos, p->length);
  205121. pos += p->length;
  205122. bytesLeft -= p->length;
  205123. p = MIDIPacketNext (p);
  205124. }
  205125. if (mpe->port != 0)
  205126. MIDISend (mpe->port, mpe->endPoint, packets);
  205127. else
  205128. MIDIReceived (mpe->endPoint, packets);
  205129. }
  205130. else
  205131. {
  205132. MIDIPacketList packets;
  205133. packets.numPackets = 1;
  205134. packets.packet[0].timeStamp = 0;
  205135. packets.packet[0].length = message.getRawDataSize();
  205136. *(int*) (packets.packet[0].data) = *(const int*) message.getRawData();
  205137. if (mpe->port != 0)
  205138. MIDISend (mpe->port, mpe->endPoint, &packets);
  205139. else
  205140. MIDIReceived (mpe->endPoint, &packets);
  205141. }
  205142. }
  205143. const StringArray MidiInput::getDevices()
  205144. {
  205145. StringArray s;
  205146. const ItemCount num = MIDIGetNumberOfSources();
  205147. for (ItemCount i = 0; i < num; ++i)
  205148. {
  205149. MIDIEndpointRef source = MIDIGetSource (i);
  205150. if (source != 0)
  205151. {
  205152. String name (getConnectedEndpointName (source));
  205153. if (name.isEmpty())
  205154. name = "<error>";
  205155. s.add (name);
  205156. }
  205157. else
  205158. {
  205159. s.add ("<error>");
  205160. }
  205161. }
  205162. return s;
  205163. }
  205164. int MidiInput::getDefaultDeviceIndex()
  205165. {
  205166. return 0;
  205167. }
  205168. struct MidiPortAndCallback
  205169. {
  205170. MidiInput* input;
  205171. MidiPortAndEndpoint* portAndEndpoint;
  205172. MidiInputCallback* callback;
  205173. MemoryBlock pendingData;
  205174. int pendingBytes;
  205175. double pendingDataTime;
  205176. bool active;
  205177. void processSysex (const uint8*& d, int& size, const double time)
  205178. {
  205179. if (*d == 0xf0)
  205180. {
  205181. pendingBytes = 0;
  205182. pendingDataTime = time;
  205183. }
  205184. pendingData.ensureSize (pendingBytes + size, false);
  205185. uint8* totalMessage = (uint8*) pendingData.getData();
  205186. uint8* dest = totalMessage + pendingBytes;
  205187. while (size > 0)
  205188. {
  205189. if (pendingBytes > 0 && *d >= 0x80)
  205190. {
  205191. if (*d >= 0xfa || *d == 0xf8)
  205192. {
  205193. callback->handleIncomingMidiMessage (input, MidiMessage (*d, time));
  205194. ++d;
  205195. --size;
  205196. }
  205197. else
  205198. {
  205199. if (*d == 0xf7)
  205200. {
  205201. *dest++ = *d++;
  205202. pendingBytes++;
  205203. --size;
  205204. }
  205205. break;
  205206. }
  205207. }
  205208. else
  205209. {
  205210. *dest++ = *d++;
  205211. pendingBytes++;
  205212. --size;
  205213. }
  205214. }
  205215. if (totalMessage [pendingBytes - 1] == 0xf7)
  205216. {
  205217. callback->handleIncomingMidiMessage (input, MidiMessage (totalMessage, pendingBytes, pendingDataTime));
  205218. pendingBytes = 0;
  205219. }
  205220. else
  205221. {
  205222. callback->handlePartialSysexMessage (input, totalMessage, pendingBytes, pendingDataTime);
  205223. }
  205224. }
  205225. };
  205226. namespace CoreMidiCallbacks
  205227. {
  205228. static CriticalSection callbackLock;
  205229. static VoidArray activeCallbacks;
  205230. }
  205231. static void midiInputProc (const MIDIPacketList* pktlist,
  205232. void* readProcRefCon,
  205233. void* srcConnRefCon)
  205234. {
  205235. double time = Time::getMillisecondCounterHiRes() * 0.001;
  205236. const double originalTime = time;
  205237. MidiPortAndCallback* const mpc = (MidiPortAndCallback*) readProcRefCon;
  205238. const ScopedLock sl (CoreMidiCallbacks::callbackLock);
  205239. if (CoreMidiCallbacks::activeCallbacks.contains (mpc) && mpc->active)
  205240. {
  205241. const MIDIPacket* packet = &pktlist->packet[0];
  205242. for (unsigned int i = 0; i < pktlist->numPackets; ++i)
  205243. {
  205244. const uint8* d = (const uint8*) (packet->data);
  205245. int size = packet->length;
  205246. while (size > 0)
  205247. {
  205248. time = originalTime;
  205249. if (mpc->pendingBytes > 0 || d[0] == 0xf0)
  205250. {
  205251. mpc->processSysex (d, size, time);
  205252. }
  205253. else
  205254. {
  205255. int used = 0;
  205256. const MidiMessage m (d, size, used, 0, time);
  205257. if (used <= 0)
  205258. {
  205259. jassertfalse // malformed midi message
  205260. break;
  205261. }
  205262. else
  205263. {
  205264. mpc->callback->handleIncomingMidiMessage (mpc->input, m);
  205265. }
  205266. size -= used;
  205267. d += used;
  205268. }
  205269. }
  205270. packet = MIDIPacketNext (packet);
  205271. }
  205272. }
  205273. }
  205274. MidiInput* MidiInput::openDevice (int index, MidiInputCallback* callback)
  205275. {
  205276. MidiInput* mi = 0;
  205277. if (((unsigned int) index) < (unsigned int) MIDIGetNumberOfSources())
  205278. {
  205279. MIDIEndpointRef endPoint = MIDIGetSource (index);
  205280. if (endPoint != 0)
  205281. {
  205282. CFStringRef pname;
  205283. if (OK (MIDIObjectGetStringProperty (endPoint, kMIDIPropertyName, &pname)))
  205284. {
  205285. log (T("CoreMidi - opening inp: ") + PlatformUtilities::cfStringToJuceString (pname));
  205286. if (makeSureClientExists())
  205287. {
  205288. MIDIPortRef port;
  205289. ScopedPointer <MidiPortAndCallback> mpc (new MidiPortAndCallback());
  205290. mpc->active = false;
  205291. if (OK (MIDIInputPortCreate (globalMidiClient, pname, midiInputProc, mpc, &port)))
  205292. {
  205293. if (OK (MIDIPortConnectSource (port, endPoint, 0)))
  205294. {
  205295. mpc->portAndEndpoint = new MidiPortAndEndpoint (port, endPoint);
  205296. mpc->callback = callback;
  205297. mpc->pendingBytes = 0;
  205298. mpc->pendingData.ensureSize (128);
  205299. mi = new MidiInput (getDevices() [index]);
  205300. mpc->input = mi;
  205301. mi->internal = (void*) mpc;
  205302. const ScopedLock sl (CoreMidiCallbacks::callbackLock);
  205303. CoreMidiCallbacks::activeCallbacks.add (mpc.release());
  205304. }
  205305. else
  205306. {
  205307. OK (MIDIPortDispose (port));
  205308. }
  205309. }
  205310. }
  205311. }
  205312. CFRelease (pname);
  205313. }
  205314. }
  205315. return mi;
  205316. }
  205317. MidiInput* MidiInput::createNewDevice (const String& deviceName, MidiInputCallback* callback)
  205318. {
  205319. MidiInput* mi = 0;
  205320. if (makeSureClientExists())
  205321. {
  205322. ScopedPointer <MidiPortAndCallback> mpc (new MidiPortAndCallback());
  205323. mpc->active = false;
  205324. MIDIEndpointRef endPoint;
  205325. CFStringRef name = PlatformUtilities::juceStringToCFString(deviceName);
  205326. if (OK (MIDIDestinationCreate (globalMidiClient, name, midiInputProc, mpc, &endPoint)))
  205327. {
  205328. mpc->portAndEndpoint = new MidiPortAndEndpoint (0, endPoint);
  205329. mpc->callback = callback;
  205330. mpc->pendingBytes = 0;
  205331. mpc->pendingData.ensureSize (128);
  205332. mi = new MidiInput (deviceName);
  205333. mpc->input = mi;
  205334. mi->internal = (void*) mpc;
  205335. const ScopedLock sl (CoreMidiCallbacks::callbackLock);
  205336. CoreMidiCallbacks::activeCallbacks.add (mpc.release());
  205337. }
  205338. CFRelease (name);
  205339. }
  205340. return mi;
  205341. }
  205342. MidiInput::MidiInput (const String& name_)
  205343. : name (name_)
  205344. {
  205345. }
  205346. MidiInput::~MidiInput()
  205347. {
  205348. MidiPortAndCallback* const mpc = (MidiPortAndCallback*) internal;
  205349. mpc->active = false;
  205350. {
  205351. const ScopedLock sl (CoreMidiCallbacks::callbackLock);
  205352. CoreMidiCallbacks::activeCallbacks.removeValue (mpc);
  205353. }
  205354. if (mpc->portAndEndpoint->port != 0)
  205355. OK (MIDIPortDisconnectSource (mpc->portAndEndpoint->port, mpc->portAndEndpoint->endPoint));
  205356. delete mpc->portAndEndpoint;
  205357. delete mpc;
  205358. }
  205359. void MidiInput::start()
  205360. {
  205361. const ScopedLock sl (CoreMidiCallbacks::callbackLock);
  205362. ((MidiPortAndCallback*) internal)->active = true;
  205363. }
  205364. void MidiInput::stop()
  205365. {
  205366. const ScopedLock sl (CoreMidiCallbacks::callbackLock);
  205367. ((MidiPortAndCallback*) internal)->active = false;
  205368. }
  205369. #undef log
  205370. #else
  205371. MidiOutput::~MidiOutput()
  205372. {
  205373. }
  205374. void MidiOutput::reset()
  205375. {
  205376. }
  205377. bool MidiOutput::getVolume (float& leftVol, float& rightVol)
  205378. {
  205379. return false;
  205380. }
  205381. void MidiOutput::setVolume (float leftVol, float rightVol)
  205382. {
  205383. }
  205384. void MidiOutput::sendMessageNow (const MidiMessage& message)
  205385. {
  205386. }
  205387. const StringArray MidiOutput::getDevices()
  205388. {
  205389. return StringArray();
  205390. }
  205391. MidiOutput* MidiOutput::openDevice (int index)
  205392. {
  205393. return 0;
  205394. }
  205395. const StringArray MidiInput::getDevices()
  205396. {
  205397. return StringArray();
  205398. }
  205399. MidiInput* MidiInput::openDevice (int index, MidiInputCallback* callback)
  205400. {
  205401. return 0;
  205402. }
  205403. #endif
  205404. #endif
  205405. /*** End of inlined file: juce_mac_CoreMidi.cpp ***/
  205406. #else
  205407. /*** Start of inlined file: juce_mac_Fonts.mm ***/
  205408. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  205409. // compiled on its own).
  205410. #if JUCE_INCLUDED_FILE
  205411. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  205412. #define SUPPORT_10_4_FONTS 1
  205413. #define NEW_CGFONT_FUNCTIONS_UNAVAILABLE (CGFontCreateWithFontName == 0)
  205414. #if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_5
  205415. #define SUPPORT_ONLY_10_4_FONTS 1
  205416. #endif
  205417. END_JUCE_NAMESPACE
  205418. @interface NSFont (PrivateHack)
  205419. - (NSGlyph) _defaultGlyphForChar: (unichar) theChar;
  205420. @end
  205421. BEGIN_JUCE_NAMESPACE
  205422. #endif
  205423. class MacTypeface : public Typeface
  205424. {
  205425. public:
  205426. MacTypeface (const Font& font)
  205427. : Typeface (font.getTypefaceName())
  205428. {
  205429. const ScopedAutoReleasePool pool;
  205430. renderingTransform = CGAffineTransformIdentity;
  205431. bool needsItalicTransform = false;
  205432. #if JUCE_IPHONE
  205433. NSString* fontName = juceStringToNS (font.getTypefaceName());
  205434. if (font.isItalic() || font.isBold())
  205435. {
  205436. NSArray* familyFonts = [UIFont fontNamesForFamilyName: juceStringToNS (font.getTypefaceName())];
  205437. for (NSString* i in familyFonts)
  205438. {
  205439. const String fn (nsStringToJuce (i));
  205440. const String afterDash (fn.fromFirstOccurrenceOf (T("-"), false, false));
  205441. const bool probablyBold = afterDash.containsIgnoreCase (T("bold")) || fn.endsWithIgnoreCase (T("bold"));
  205442. const bool probablyItalic = afterDash.containsIgnoreCase (T("oblique"))
  205443. || afterDash.containsIgnoreCase (T("italic"))
  205444. || fn.endsWithIgnoreCase (T("oblique"))
  205445. || fn.endsWithIgnoreCase (T("italic"));
  205446. if (probablyBold == font.isBold()
  205447. && probablyItalic == font.isItalic())
  205448. {
  205449. fontName = i;
  205450. needsItalicTransform = false;
  205451. break;
  205452. }
  205453. else if (probablyBold && (! probablyItalic) && probablyBold == font.isBold())
  205454. {
  205455. fontName = i;
  205456. needsItalicTransform = true; // not ideal, so carry on in case we find a better one
  205457. }
  205458. }
  205459. if (needsItalicTransform)
  205460. renderingTransform.c = 0.15f;
  205461. }
  205462. fontRef = CGFontCreateWithFontName ((CFStringRef) fontName);
  205463. const int ascender = abs (CGFontGetAscent (fontRef));
  205464. const float totalHeight = ascender + abs (CGFontGetDescent (fontRef));
  205465. ascent = ascender / totalHeight;
  205466. unitsToHeightScaleFactor = 1.0f / totalHeight;
  205467. fontHeightToCGSizeFactor = CGFontGetUnitsPerEm (fontRef) / totalHeight;
  205468. #else
  205469. nsFont = [NSFont fontWithName: juceStringToNS (font.getTypefaceName()) size: 1024];
  205470. if (font.isItalic())
  205471. {
  205472. NSFont* newFont = [[NSFontManager sharedFontManager] convertFont: nsFont
  205473. toHaveTrait: NSItalicFontMask];
  205474. if (newFont == nsFont)
  205475. needsItalicTransform = true; // couldn't find a proper italic version, so fake it with a transform..
  205476. nsFont = newFont;
  205477. }
  205478. if (font.isBold())
  205479. nsFont = [[NSFontManager sharedFontManager] convertFont: nsFont toHaveTrait: NSBoldFontMask];
  205480. [nsFont retain];
  205481. ascent = fabsf ((float) [nsFont ascender]);
  205482. float totalSize = ascent + fabsf ((float) [nsFont descender]);
  205483. ascent /= totalSize;
  205484. pathTransform = AffineTransform::identity.scale (1.0f / totalSize, 1.0f / totalSize);
  205485. if (needsItalicTransform)
  205486. {
  205487. pathTransform = pathTransform.sheared (-0.15f, 0.0f);
  205488. renderingTransform.c = 0.15f;
  205489. }
  205490. #if SUPPORT_ONLY_10_4_FONTS
  205491. ATSFontRef atsFont = ATSFontFindFromName ((CFStringRef) [nsFont fontName], kATSOptionFlagsDefault);
  205492. if (atsFont == 0)
  205493. atsFont = ATSFontFindFromPostScriptName ((CFStringRef) [nsFont fontName], kATSOptionFlagsDefault);
  205494. fontRef = CGFontCreateWithPlatformFont ((void*) &atsFont);
  205495. const float totalHeight = fabsf ([nsFont ascender]) + fabsf([nsFont descender]);
  205496. unitsToHeightScaleFactor = 1.0f / totalHeight;
  205497. fontHeightToCGSizeFactor = 1024.0f / totalHeight;
  205498. #else
  205499. #if SUPPORT_10_4_FONTS
  205500. if (NEW_CGFONT_FUNCTIONS_UNAVAILABLE)
  205501. {
  205502. ATSFontRef atsFont = ATSFontFindFromName ((CFStringRef) [nsFont fontName], kATSOptionFlagsDefault);
  205503. if (atsFont == 0)
  205504. atsFont = ATSFontFindFromPostScriptName ((CFStringRef) [nsFont fontName], kATSOptionFlagsDefault);
  205505. fontRef = CGFontCreateWithPlatformFont ((void*) &atsFont);
  205506. const float totalHeight = fabsf ([nsFont ascender]) + fabsf([nsFont descender]);
  205507. unitsToHeightScaleFactor = 1.0f / totalHeight;
  205508. fontHeightToCGSizeFactor = 1024.0f / totalHeight;
  205509. }
  205510. else
  205511. #endif
  205512. {
  205513. fontRef = CGFontCreateWithFontName ((CFStringRef) [nsFont fontName]);
  205514. const int totalHeight = abs (CGFontGetAscent (fontRef)) + abs (CGFontGetDescent (fontRef));
  205515. unitsToHeightScaleFactor = 1.0f / totalHeight;
  205516. fontHeightToCGSizeFactor = CGFontGetUnitsPerEm (fontRef) / (float) totalHeight;
  205517. }
  205518. #endif
  205519. #endif
  205520. }
  205521. ~MacTypeface()
  205522. {
  205523. #if ! JUCE_IPHONE
  205524. [nsFont release];
  205525. #endif
  205526. if (fontRef != 0)
  205527. CGFontRelease (fontRef);
  205528. }
  205529. float getAscent() const
  205530. {
  205531. return ascent;
  205532. }
  205533. float getDescent() const
  205534. {
  205535. return 1.0f - ascent;
  205536. }
  205537. float getStringWidth (const String& text)
  205538. {
  205539. if (fontRef == 0 || text.isEmpty())
  205540. return 0;
  205541. const int length = text.length();
  205542. HeapBlock <CGGlyph> glyphs;
  205543. createGlyphsForString (text, length, glyphs);
  205544. float x = 0;
  205545. #if SUPPORT_ONLY_10_4_FONTS
  205546. HeapBlock <NSSize> advances (length);
  205547. [nsFont getAdvancements: advances forGlyphs: reinterpret_cast <NSGlyph*> (glyphs.getData()) count: length];
  205548. for (int i = 0; i < length; ++i)
  205549. x += advances[i].width;
  205550. #else
  205551. #if SUPPORT_10_4_FONTS
  205552. if (NEW_CGFONT_FUNCTIONS_UNAVAILABLE)
  205553. {
  205554. HeapBlock <NSSize> advances (length);
  205555. [nsFont getAdvancements: advances forGlyphs: reinterpret_cast<NSGlyph*> (glyphs.getData()) count: length];
  205556. for (int i = 0; i < length; ++i)
  205557. x += advances[i].width;
  205558. }
  205559. else
  205560. #endif
  205561. {
  205562. HeapBlock <int> advances (length);
  205563. if (CGFontGetGlyphAdvances (fontRef, glyphs, length, advances))
  205564. for (int i = 0; i < length; ++i)
  205565. x += advances[i];
  205566. }
  205567. #endif
  205568. return x * unitsToHeightScaleFactor;
  205569. }
  205570. void getGlyphPositions (const String& text, Array <int>& resultGlyphs, Array <float>& xOffsets)
  205571. {
  205572. xOffsets.add (0);
  205573. if (fontRef == 0 || text.isEmpty())
  205574. return;
  205575. const int length = text.length();
  205576. HeapBlock <CGGlyph> glyphs;
  205577. createGlyphsForString (text, length, glyphs);
  205578. #if SUPPORT_ONLY_10_4_FONTS
  205579. HeapBlock <NSSize> advances (length);
  205580. [nsFont getAdvancements: advances forGlyphs: reinterpret_cast <NSGlyph*> (glyphs.getData()) count: length];
  205581. int x = 0;
  205582. for (int i = 0; i < length; ++i)
  205583. {
  205584. x += advances[i].width;
  205585. xOffsets.add (x * unitsToHeightScaleFactor);
  205586. resultGlyphs.add (reinterpret_cast <NSGlyph*> (glyphs.getData())[i]);
  205587. }
  205588. #else
  205589. #if SUPPORT_10_4_FONTS
  205590. if (NEW_CGFONT_FUNCTIONS_UNAVAILABLE)
  205591. {
  205592. HeapBlock <NSSize> advances (length);
  205593. NSGlyph* const nsGlyphs = reinterpret_cast<NSGlyph*> (glyphs.getData());
  205594. [nsFont getAdvancements: advances forGlyphs: nsGlyphs count: length];
  205595. float x = 0;
  205596. for (int i = 0; i < length; ++i)
  205597. {
  205598. x += advances[i].width;
  205599. xOffsets.add (x * unitsToHeightScaleFactor);
  205600. resultGlyphs.add (nsGlyphs[i]);
  205601. }
  205602. }
  205603. else
  205604. #endif
  205605. {
  205606. HeapBlock <int> advances (length);
  205607. if (CGFontGetGlyphAdvances (fontRef, glyphs, length, advances))
  205608. {
  205609. int x = 0;
  205610. for (int i = 0; i < length; ++i)
  205611. {
  205612. x += advances [i];
  205613. xOffsets.add (x * unitsToHeightScaleFactor);
  205614. resultGlyphs.add (glyphs[i]);
  205615. }
  205616. }
  205617. }
  205618. #endif
  205619. }
  205620. bool getOutlineForGlyph (int glyphNumber, Path& path)
  205621. {
  205622. #if JUCE_IPHONE
  205623. return false;
  205624. #else
  205625. if (nsFont == 0)
  205626. return false;
  205627. // we might need to apply a transform to the path, so it mustn't have anything else in it
  205628. jassert (path.isEmpty());
  205629. const ScopedAutoReleasePool pool;
  205630. NSBezierPath* bez = [NSBezierPath bezierPath];
  205631. [bez moveToPoint: NSMakePoint (0, 0)];
  205632. [bez appendBezierPathWithGlyph: (NSGlyph) glyphNumber
  205633. inFont: nsFont];
  205634. for (int i = 0; i < [bez elementCount]; ++i)
  205635. {
  205636. NSPoint p[3];
  205637. switch ([bez elementAtIndex: i associatedPoints: p])
  205638. {
  205639. case NSMoveToBezierPathElement:
  205640. path.startNewSubPath ((float) p[0].x, (float) -p[0].y);
  205641. break;
  205642. case NSLineToBezierPathElement:
  205643. path.lineTo ((float) p[0].x, (float) -p[0].y);
  205644. break;
  205645. case NSCurveToBezierPathElement:
  205646. 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);
  205647. break;
  205648. case NSClosePathBezierPathElement:
  205649. path.closeSubPath();
  205650. break;
  205651. default:
  205652. jassertfalse
  205653. break;
  205654. }
  205655. }
  205656. path.applyTransform (pathTransform);
  205657. return true;
  205658. #endif
  205659. }
  205660. juce_UseDebuggingNewOperator
  205661. CGFontRef fontRef;
  205662. float fontHeightToCGSizeFactor;
  205663. CGAffineTransform renderingTransform;
  205664. private:
  205665. float ascent, unitsToHeightScaleFactor;
  205666. #if JUCE_IPHONE
  205667. #else
  205668. NSFont* nsFont;
  205669. AffineTransform pathTransform;
  205670. #endif
  205671. void createGlyphsForString (const juce_wchar* const text, const int length, HeapBlock <CGGlyph>& glyphs)
  205672. {
  205673. #if SUPPORT_10_4_FONTS
  205674. #if ! SUPPORT_ONLY_10_4_FONTS
  205675. if (NEW_CGFONT_FUNCTIONS_UNAVAILABLE)
  205676. #endif
  205677. {
  205678. glyphs.malloc (sizeof (NSGlyph) * length, 1);
  205679. NSGlyph* const nsGlyphs = reinterpret_cast<NSGlyph*> (glyphs.getData());
  205680. for (int i = 0; i < length; ++i)
  205681. nsGlyphs[i] = (NSGlyph) [nsFont _defaultGlyphForChar: text[i]];
  205682. return;
  205683. }
  205684. #endif
  205685. #if ! SUPPORT_ONLY_10_4_FONTS
  205686. if (charToGlyphMapper == 0)
  205687. charToGlyphMapper = new CharToGlyphMapper (fontRef);
  205688. glyphs.malloc (length);
  205689. for (int i = 0; i < length; ++i)
  205690. glyphs[i] = (CGGlyph) charToGlyphMapper->getGlyphForCharacter (text[i]);
  205691. #endif
  205692. }
  205693. #if ! SUPPORT_ONLY_10_4_FONTS
  205694. // Reads a CGFontRef's character map table to convert unicode into glyph numbers
  205695. class CharToGlyphMapper
  205696. {
  205697. public:
  205698. CharToGlyphMapper (CGFontRef fontRef)
  205699. : segCount (0), endCode (0), startCode (0), idDelta (0),
  205700. idRangeOffset (0), glyphIndexes (0)
  205701. {
  205702. CFDataRef cmapTable = CGFontCopyTableForTag (fontRef, 'cmap');
  205703. if (cmapTable != 0)
  205704. {
  205705. const int numSubtables = getValue16 (cmapTable, 2);
  205706. for (int i = 0; i < numSubtables; ++i)
  205707. {
  205708. if (getValue16 (cmapTable, i * 8 + 4) == 0) // check for platform ID of 0
  205709. {
  205710. const int offset = getValue32 (cmapTable, i * 8 + 8);
  205711. if (getValue16 (cmapTable, offset) == 4) // check that it's format 4..
  205712. {
  205713. const int length = getValue16 (cmapTable, offset + 2);
  205714. const int segCountX2 = getValue16 (cmapTable, offset + 6);
  205715. segCount = segCountX2 / 2;
  205716. const int endCodeOffset = offset + 14;
  205717. const int startCodeOffset = endCodeOffset + 2 + segCountX2;
  205718. const int idDeltaOffset = startCodeOffset + segCountX2;
  205719. const int idRangeOffsetOffset = idDeltaOffset + segCountX2;
  205720. const int glyphIndexesOffset = idRangeOffsetOffset + segCountX2;
  205721. endCode = CFDataCreate (kCFAllocatorDefault, CFDataGetBytePtr (cmapTable) + endCodeOffset, segCountX2);
  205722. startCode = CFDataCreate (kCFAllocatorDefault, CFDataGetBytePtr (cmapTable) + startCodeOffset, segCountX2);
  205723. idDelta = CFDataCreate (kCFAllocatorDefault, CFDataGetBytePtr (cmapTable) + idDeltaOffset, segCountX2);
  205724. idRangeOffset = CFDataCreate (kCFAllocatorDefault, CFDataGetBytePtr (cmapTable) + idRangeOffsetOffset, segCountX2);
  205725. glyphIndexes = CFDataCreate (kCFAllocatorDefault, CFDataGetBytePtr (cmapTable) + glyphIndexesOffset, offset + length - glyphIndexesOffset);
  205726. }
  205727. break;
  205728. }
  205729. }
  205730. CFRelease (cmapTable);
  205731. }
  205732. }
  205733. ~CharToGlyphMapper()
  205734. {
  205735. if (endCode != 0)
  205736. {
  205737. CFRelease (endCode);
  205738. CFRelease (startCode);
  205739. CFRelease (idDelta);
  205740. CFRelease (idRangeOffset);
  205741. CFRelease (glyphIndexes);
  205742. }
  205743. }
  205744. int getGlyphForCharacter (const juce_wchar c) const
  205745. {
  205746. for (int i = 0; i < segCount; ++i)
  205747. {
  205748. if (getValue16 (endCode, i * 2) >= c)
  205749. {
  205750. const int start = getValue16 (startCode, i * 2);
  205751. if (start > c)
  205752. break;
  205753. const int delta = getValue16 (idDelta, i * 2);
  205754. const int rangeOffset = getValue16 (idRangeOffset, i * 2);
  205755. if (rangeOffset == 0)
  205756. return delta + c;
  205757. else
  205758. return getValue16 (glyphIndexes, 2 * ((rangeOffset / 2) + (c - start) - (segCount - i)));
  205759. }
  205760. }
  205761. // If we failed to find it "properly", this dodgy fall-back seems to do the trick for most fonts!
  205762. return jmax (-1, c - 29);
  205763. }
  205764. private:
  205765. int segCount;
  205766. CFDataRef endCode, startCode, idDelta, idRangeOffset, glyphIndexes;
  205767. static uint16 getValue16 (CFDataRef data, const int index)
  205768. {
  205769. return CFSwapInt16BigToHost (*(UInt16*) (CFDataGetBytePtr (data) + index));
  205770. }
  205771. static uint32 getValue32 (CFDataRef data, const int index)
  205772. {
  205773. return CFSwapInt32BigToHost (*(UInt32*) (CFDataGetBytePtr (data) + index));
  205774. }
  205775. };
  205776. ScopedPointer <CharToGlyphMapper> charToGlyphMapper;
  205777. #endif
  205778. MacTypeface (const MacTypeface&);
  205779. MacTypeface& operator= (const MacTypeface&);
  205780. };
  205781. const Typeface::Ptr Typeface::createSystemTypefaceFor (const Font& font)
  205782. {
  205783. return new MacTypeface (font);
  205784. }
  205785. const StringArray Font::findAllTypefaceNames() throw()
  205786. {
  205787. StringArray names;
  205788. const ScopedAutoReleasePool pool;
  205789. #if JUCE_IPHONE
  205790. NSArray* fonts = [UIFont familyNames];
  205791. #else
  205792. NSArray* fonts = [[NSFontManager sharedFontManager] availableFontFamilies];
  205793. #endif
  205794. for (unsigned int i = 0; i < [fonts count]; ++i)
  205795. names.add (nsStringToJuce ((NSString*) [fonts objectAtIndex: i]));
  205796. names.sort (true);
  205797. return names;
  205798. }
  205799. void Font::getPlatformDefaultFontNames (String& defaultSans, String& defaultSerif, String& defaultFixed) throw()
  205800. {
  205801. #if JUCE_IPHONE
  205802. defaultSans = "Helvetica";
  205803. defaultSerif = "Times New Roman";
  205804. defaultFixed = "Courier New";
  205805. #else
  205806. defaultSans = "Lucida Grande";
  205807. defaultSerif = "Times New Roman";
  205808. defaultFixed = "Monaco";
  205809. #endif
  205810. }
  205811. #endif
  205812. /*** End of inlined file: juce_mac_Fonts.mm ***/
  205813. // (must go before juce_mac_CoreGraphicsContext.mm)
  205814. /*** Start of inlined file: juce_mac_CoreGraphicsContext.mm ***/
  205815. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  205816. // compiled on its own).
  205817. #if JUCE_INCLUDED_FILE
  205818. class CoreGraphicsImage : public Image
  205819. {
  205820. public:
  205821. CoreGraphicsImage (const PixelFormat format_,
  205822. const int imageWidth_,
  205823. const int imageHeight_,
  205824. const bool clearImage)
  205825. : Image (format_, imageWidth_, imageHeight_, clearImage)
  205826. {
  205827. CGColorSpaceRef colourSpace = (format == Image::SingleChannel) ? CGColorSpaceCreateDeviceGray()
  205828. : CGColorSpaceCreateDeviceRGB();
  205829. context = CGBitmapContextCreate (imageData, imageWidth, imageHeight, 8, lineStride,
  205830. colourSpace, getCGImageFlags (*this));
  205831. CGColorSpaceRelease (colourSpace);
  205832. }
  205833. ~CoreGraphicsImage()
  205834. {
  205835. CGContextRelease (context);
  205836. }
  205837. LowLevelGraphicsContext* createLowLevelContext();
  205838. static CGImageRef createImage (const Image& juceImage, const bool forAlpha, CGColorSpaceRef colourSpace)
  205839. {
  205840. const CoreGraphicsImage* nativeImage = dynamic_cast <const CoreGraphicsImage*> (&juceImage);
  205841. if (nativeImage != 0 && (juceImage.getFormat() == Image::SingleChannel || ! forAlpha))
  205842. {
  205843. return CGBitmapContextCreateImage (nativeImage->context);
  205844. }
  205845. else
  205846. {
  205847. const Image::BitmapData srcData (juceImage, 0, 0, juceImage.getWidth(), juceImage.getHeight());
  205848. CGDataProviderRef provider = CGDataProviderCreateWithData (0, srcData.data, srcData.lineStride * srcData.height, 0);
  205849. CGImageRef imageRef = CGImageCreate (srcData.width, srcData.height,
  205850. 8, srcData.pixelStride * 8, srcData.lineStride,
  205851. colourSpace, getCGImageFlags (juceImage), provider,
  205852. 0, true, kCGRenderingIntentDefault);
  205853. CGDataProviderRelease (provider);
  205854. return imageRef;
  205855. }
  205856. }
  205857. #if JUCE_MAC
  205858. static NSImage* createNSImage (const Image& image)
  205859. {
  205860. const ScopedAutoReleasePool pool;
  205861. NSImage* im = [[NSImage alloc] init];
  205862. [im setSize: NSMakeSize (image.getWidth(), image.getHeight())];
  205863. [im lockFocus];
  205864. CGColorSpaceRef colourSpace = CGColorSpaceCreateDeviceRGB();
  205865. CGImageRef imageRef = createImage (image, false, colourSpace);
  205866. CGColorSpaceRelease (colourSpace);
  205867. CGContextRef cg = (CGContextRef) [[NSGraphicsContext currentContext] graphicsPort];
  205868. CGContextDrawImage (cg, CGRectMake (0, 0, image.getWidth(), image.getHeight()), imageRef);
  205869. CGImageRelease (imageRef);
  205870. [im unlockFocus];
  205871. return im;
  205872. }
  205873. #endif
  205874. CGContextRef context;
  205875. private:
  205876. static CGBitmapInfo getCGImageFlags (const Image& image)
  205877. {
  205878. #if JUCE_BIG_ENDIAN
  205879. return image.getFormat() == Image::ARGB ? (kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Big) : kCGBitmapByteOrderDefault;
  205880. #else
  205881. return image.getFormat() == Image::ARGB ? (kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Little) : kCGBitmapByteOrderDefault;
  205882. #endif
  205883. }
  205884. };
  205885. Image* Image::createNativeImage (const PixelFormat format, const int imageWidth, const int imageHeight, const bool clearImage)
  205886. {
  205887. #if USE_COREGRAPHICS_RENDERING
  205888. return new CoreGraphicsImage (format == RGB ? ARGB : format, imageWidth, imageHeight, clearImage);
  205889. #else
  205890. return new Image (format, imageWidth, imageHeight, clearImage);
  205891. #endif
  205892. }
  205893. class CoreGraphicsContext : public LowLevelGraphicsContext
  205894. {
  205895. public:
  205896. CoreGraphicsContext (CGContextRef context_, const float flipHeight_)
  205897. : context (context_),
  205898. flipHeight (flipHeight_),
  205899. state (new SavedState()),
  205900. numGradientLookupEntries (0)
  205901. {
  205902. CGContextRetain (context);
  205903. CGContextSaveGState(context);
  205904. CGContextSetShouldSmoothFonts (context, true);
  205905. CGContextSetShouldAntialias (context, true);
  205906. CGContextSetBlendMode (context, kCGBlendModeNormal);
  205907. rgbColourSpace = CGColorSpaceCreateDeviceRGB();
  205908. greyColourSpace = CGColorSpaceCreateDeviceGray();
  205909. gradientCallbacks.version = 0;
  205910. gradientCallbacks.evaluate = gradientCallback;
  205911. gradientCallbacks.releaseInfo = 0;
  205912. setFont (Font());
  205913. }
  205914. ~CoreGraphicsContext()
  205915. {
  205916. CGContextRestoreGState (context);
  205917. CGContextRelease (context);
  205918. CGColorSpaceRelease (rgbColourSpace);
  205919. CGColorSpaceRelease (greyColourSpace);
  205920. }
  205921. bool isVectorDevice() const { return false; }
  205922. void setOrigin (int x, int y)
  205923. {
  205924. CGContextTranslateCTM (context, x, -y);
  205925. }
  205926. bool clipToRectangle (const Rectangle<int>& r)
  205927. {
  205928. CGContextClipToRect (context, CGRectMake (r.getX(), flipHeight - r.getBottom(), r.getWidth(), r.getHeight()));
  205929. return ! isClipEmpty();
  205930. }
  205931. bool clipToRectangleList (const RectangleList& clipRegion)
  205932. {
  205933. if (clipRegion.isEmpty())
  205934. {
  205935. CGContextClipToRect (context, CGRectMake (0, 0, 0, 0));
  205936. return false;
  205937. }
  205938. else
  205939. {
  205940. const int numRects = clipRegion.getNumRectangles();
  205941. HeapBlock <CGRect> rects (numRects);
  205942. for (int i = 0; i < numRects; ++i)
  205943. {
  205944. const Rectangle<int>& r = clipRegion.getRectangle(i);
  205945. rects[i] = CGRectMake (r.getX(), flipHeight - r.getBottom(), r.getWidth(), r.getHeight());
  205946. }
  205947. CGContextClipToRects (context, rects, numRects);
  205948. return ! isClipEmpty();
  205949. }
  205950. }
  205951. void excludeClipRectangle (const Rectangle<int>& r)
  205952. {
  205953. RectangleList remaining (getClipBounds());
  205954. remaining.subtract (r);
  205955. clipToRectangleList (remaining);
  205956. }
  205957. void clipToPath (const Path& path, const AffineTransform& transform)
  205958. {
  205959. createPath (path, transform);
  205960. CGContextClip (context);
  205961. }
  205962. void clipToImageAlpha (const Image& sourceImage, const Rectangle<int>& srcClip, const AffineTransform& transform)
  205963. {
  205964. if (! transform.isSingularity())
  205965. {
  205966. Image* singleChannelImage = createAlphaChannelImage (sourceImage);
  205967. CGImageRef image = CoreGraphicsImage::createImage (*singleChannelImage, true, greyColourSpace);
  205968. flip();
  205969. AffineTransform t (AffineTransform::scale (1.0f, -1.0f).translated (0, sourceImage.getHeight()).followedBy (transform));
  205970. applyTransform (t);
  205971. CGRect r = CGRectMake (0, 0, sourceImage.getWidth(), sourceImage.getHeight());
  205972. CGContextClipToMask (context, r, image);
  205973. applyTransform (t.inverted());
  205974. flip();
  205975. CGImageRelease (image);
  205976. deleteAlphaChannelImage (sourceImage, singleChannelImage);
  205977. }
  205978. }
  205979. bool clipRegionIntersects (const Rectangle<int>& r)
  205980. {
  205981. return getClipBounds().intersects (r);
  205982. }
  205983. const Rectangle<int> getClipBounds() const
  205984. {
  205985. CGRect bounds = CGRectIntegral (CGContextGetClipBoundingBox (context));
  205986. return Rectangle<int> (roundToInt (bounds.origin.x),
  205987. roundToInt (flipHeight - (bounds.origin.y + bounds.size.height)),
  205988. roundToInt (bounds.size.width),
  205989. roundToInt (bounds.size.height));
  205990. }
  205991. bool isClipEmpty() const
  205992. {
  205993. return CGRectIsEmpty (CGContextGetClipBoundingBox (context));
  205994. }
  205995. void saveState()
  205996. {
  205997. CGContextSaveGState (context);
  205998. stateStack.add (new SavedState (*state));
  205999. }
  206000. void restoreState()
  206001. {
  206002. CGContextRestoreGState (context);
  206003. SavedState* const top = stateStack.getLast();
  206004. if (top != 0)
  206005. {
  206006. state = top;
  206007. stateStack.removeLast (1, false);
  206008. }
  206009. else
  206010. {
  206011. jassertfalse // trying to pop with an empty stack!
  206012. }
  206013. }
  206014. void setFill (const FillType& fillType)
  206015. {
  206016. state->fillType = fillType;
  206017. if (fillType.isColour())
  206018. {
  206019. CGContextSetRGBFillColor (context, fillType.colour.getFloatRed(), fillType.colour.getFloatGreen(),
  206020. fillType.colour.getFloatBlue(), fillType.colour.getFloatAlpha());
  206021. CGContextSetAlpha (context, 1.0f);
  206022. }
  206023. }
  206024. void setOpacity (float newOpacity)
  206025. {
  206026. state->fillType.setOpacity (newOpacity);
  206027. setFill (state->fillType);
  206028. }
  206029. void setInterpolationQuality (Graphics::ResamplingQuality quality)
  206030. {
  206031. CGContextSetInterpolationQuality (context, quality == Graphics::lowResamplingQuality
  206032. ? kCGInterpolationLow
  206033. : kCGInterpolationHigh);
  206034. }
  206035. void fillRect (const Rectangle<int>& r, const bool replaceExistingContents)
  206036. {
  206037. CGRect cgRect = CGRectMake (r.getX(), flipHeight - r.getBottom(), r.getWidth(), r.getHeight());
  206038. if (replaceExistingContents)
  206039. {
  206040. #if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_5
  206041. CGContextClearRect (context, cgRect);
  206042. #else
  206043. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  206044. if (CGContextDrawLinearGradient == 0) // (just a way of checking whether we're running in 10.5 or later)
  206045. CGContextClearRect (context, cgRect);
  206046. else
  206047. #endif
  206048. CGContextSetBlendMode (context, kCGBlendModeCopy);
  206049. #endif
  206050. fillRect (r, false);
  206051. CGContextSetBlendMode (context, kCGBlendModeNormal);
  206052. }
  206053. else
  206054. {
  206055. if (state->fillType.isColour())
  206056. {
  206057. CGContextFillRect (context, cgRect);
  206058. }
  206059. else if (state->fillType.isGradient())
  206060. {
  206061. CGContextSaveGState (context);
  206062. CGContextClipToRect (context, cgRect);
  206063. drawGradient();
  206064. CGContextRestoreGState (context);
  206065. }
  206066. else
  206067. {
  206068. CGContextSaveGState (context);
  206069. CGContextClipToRect (context, cgRect);
  206070. drawImage (*(state->fillType.image), state->fillType.image->getBounds(), state->fillType.transform, true);
  206071. CGContextRestoreGState (context);
  206072. }
  206073. }
  206074. }
  206075. void fillPath (const Path& path, const AffineTransform& transform)
  206076. {
  206077. CGContextSaveGState (context);
  206078. if (state->fillType.isColour())
  206079. {
  206080. flip();
  206081. applyTransform (transform);
  206082. createPath (path);
  206083. if (path.isUsingNonZeroWinding())
  206084. CGContextFillPath (context);
  206085. else
  206086. CGContextEOFillPath (context);
  206087. }
  206088. else
  206089. {
  206090. createPath (path, transform);
  206091. if (path.isUsingNonZeroWinding())
  206092. CGContextClip (context);
  206093. else
  206094. CGContextEOClip (context);
  206095. if (state->fillType.isGradient())
  206096. drawGradient();
  206097. else
  206098. drawImage (*(state->fillType.image), state->fillType.image->getBounds(), state->fillType.transform, true);
  206099. }
  206100. CGContextRestoreGState (context);
  206101. }
  206102. void drawImage (const Image& sourceImage, const Rectangle<int>& srcClip,
  206103. const AffineTransform& transform, const bool fillEntireClipAsTiles)
  206104. {
  206105. jassert (sourceImage.getBounds().contains (srcClip));
  206106. CGImageRef fullImage = CoreGraphicsImage::createImage (sourceImage, false, rgbColourSpace);
  206107. CGImageRef image = fullImage;
  206108. if (srcClip != sourceImage.getBounds())
  206109. {
  206110. image = CGImageCreateWithImageInRect (fullImage, CGRectMake (srcClip.getX(), srcClip.getY(),
  206111. srcClip.getWidth(), srcClip.getHeight()));
  206112. CGImageRelease (fullImage);
  206113. }
  206114. CGContextSaveGState (context);
  206115. CGContextSetAlpha (context, state->fillType.getOpacity());
  206116. flip();
  206117. applyTransform (AffineTransform::scale (1.0f, -1.0f).translated (0, srcClip.getHeight()).followedBy (transform));
  206118. CGRect imageRect = CGRectMake (0, 0, srcClip.getWidth(), srcClip.getHeight());
  206119. if (fillEntireClipAsTiles)
  206120. {
  206121. #if JUCE_IPHONE || (MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5)
  206122. CGContextDrawTiledImage (context, imageRect, image);
  206123. #else
  206124. #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
  206125. // There's a bug in CGContextDrawTiledImage that makes it incredibly slow
  206126. // if it's doing a transformation - it's quicker to just draw lots of images manually
  206127. if (CGContextDrawTiledImage != 0 && transform.isOnlyTranslation())
  206128. CGContextDrawTiledImage (context, imageRect, image);
  206129. else
  206130. #endif
  206131. {
  206132. // Fallback to manually doing a tiled fill on 10.4
  206133. CGRect clip = CGRectIntegral (CGContextGetClipBoundingBox (context));
  206134. const int iw = srcClip.getWidth();
  206135. const int ih = srcClip.getHeight();
  206136. int x = 0, y = 0;
  206137. while (x > clip.origin.x) x -= iw;
  206138. while (y > clip.origin.y) y -= ih;
  206139. const int right = (int) (clip.origin.x + clip.size.width);
  206140. const int bottom = (int) (clip.origin.y + clip.size.height);
  206141. while (y < bottom)
  206142. {
  206143. for (int x2 = x; x2 < right; x2 += iw)
  206144. CGContextDrawImage (context, CGRectMake (x2, y, iw, ih), image);
  206145. y += ih;
  206146. }
  206147. }
  206148. #endif
  206149. }
  206150. else
  206151. {
  206152. CGContextDrawImage (context, imageRect, image);
  206153. }
  206154. CGImageRelease (image); // (This causes a memory bug in iPhone sim 3.0 - try upgrading to a later version if you hit this)
  206155. CGContextRestoreGState (context);
  206156. }
  206157. void drawLine (double x1, double y1, double x2, double y2)
  206158. {
  206159. CGContextSetLineCap (context, kCGLineCapSquare);
  206160. CGContextSetLineWidth (context, 1.0f);
  206161. CGContextSetRGBStrokeColor (context,
  206162. state->fillType.colour.getFloatRed(), state->fillType.colour.getFloatGreen(),
  206163. state->fillType.colour.getFloatBlue(), state->fillType.colour.getFloatAlpha());
  206164. CGPoint line[] = { { (CGFloat) x1, flipHeight - (CGFloat) y1 },
  206165. { (CGFloat) x2, flipHeight - (CGFloat) y2 } };
  206166. CGContextStrokeLineSegments (context, line, 1);
  206167. }
  206168. void drawVerticalLine (const int x, double top, double bottom)
  206169. {
  206170. #if MAC_OS_X_VERSION_MIN_REQUIRED > MAC_OS_X_VERSION_10_5
  206171. CGContextFillRect (context, CGRectMake (x, flipHeight - (float) bottom, 1.0f, (float) (bottom - top)));
  206172. #else
  206173. // On Leopard, unless both co-ordinates are non-integer, it disables anti-aliasing, so nudge
  206174. // the x co-ord slightly to trick it..
  206175. CGContextFillRect (context, CGRectMake (x + 1.0f / 256.0f, flipHeight - (float) bottom, 1.0f + 1.0f / 256.0f, (float) (bottom - top)));
  206176. #endif
  206177. }
  206178. void drawHorizontalLine (const int y, double left, double right)
  206179. {
  206180. #if MAC_OS_X_VERSION_MIN_REQUIRED > MAC_OS_X_VERSION_10_5
  206181. CGContextFillRect (context, CGRectMake ((float) left, flipHeight - (y + 1.0f), (float) (right - left), 1.0f));
  206182. #else
  206183. // On Leopard, unless both co-ordinates are non-integer, it disables anti-aliasing, so nudge
  206184. // the x co-ord slightly to trick it..
  206185. CGContextFillRect (context, CGRectMake ((float) left, flipHeight - (y + (1.0f + 1.0f / 256.0f)), (float) (right - left), 1.0f + 1.0f / 256.0f));
  206186. #endif
  206187. }
  206188. void setFont (const Font& newFont)
  206189. {
  206190. if (state->font != newFont)
  206191. {
  206192. state->fontRef = 0;
  206193. state->font = newFont;
  206194. MacTypeface* mf = dynamic_cast <MacTypeface*> ((Typeface*) state->font.getTypeface());
  206195. if (mf != 0)
  206196. {
  206197. state->fontRef = mf->fontRef;
  206198. CGContextSetFont (context, state->fontRef);
  206199. CGContextSetFontSize (context, state->font.getHeight() * mf->fontHeightToCGSizeFactor);
  206200. state->fontTransform = mf->renderingTransform;
  206201. state->fontTransform.a *= state->font.getHorizontalScale();
  206202. CGContextSetTextMatrix (context, state->fontTransform);
  206203. }
  206204. }
  206205. }
  206206. const Font getFont()
  206207. {
  206208. return state->font;
  206209. }
  206210. void drawGlyph (int glyphNumber, const AffineTransform& transform)
  206211. {
  206212. if (state->fontRef != 0 && state->fillType.isColour())
  206213. {
  206214. if (transform.isOnlyTranslation())
  206215. {
  206216. CGGlyph g = glyphNumber;
  206217. CGContextShowGlyphsAtPoint (context, transform.getTranslationX(),
  206218. flipHeight - roundToInt (transform.getTranslationY()), &g, 1);
  206219. }
  206220. else
  206221. {
  206222. CGContextSaveGState (context);
  206223. flip();
  206224. applyTransform (transform);
  206225. CGAffineTransform t = state->fontTransform;
  206226. t.d = -t.d;
  206227. CGContextSetTextMatrix (context, t);
  206228. CGGlyph g = glyphNumber;
  206229. CGContextShowGlyphsAtPoint (context, 0, 0, &g, 1);
  206230. CGContextSetTextMatrix (context, state->fontTransform);
  206231. CGContextRestoreGState (context);
  206232. }
  206233. }
  206234. else
  206235. {
  206236. Path p;
  206237. Font& f = state->font;
  206238. f.getTypeface()->getOutlineForGlyph (glyphNumber, p);
  206239. fillPath (p, AffineTransform::scale (f.getHeight() * f.getHorizontalScale(), f.getHeight())
  206240. .followedBy (transform));
  206241. }
  206242. }
  206243. private:
  206244. CGContextRef context;
  206245. const CGFloat flipHeight;
  206246. CGColorSpaceRef rgbColourSpace, greyColourSpace;
  206247. CGFunctionCallbacks gradientCallbacks;
  206248. struct SavedState
  206249. {
  206250. SavedState()
  206251. : font (1.0f), fontRef (0), fontTransform (CGAffineTransformIdentity)
  206252. {
  206253. }
  206254. SavedState (const SavedState& other)
  206255. : fillType (other.fillType), font (other.font), fontRef (other.fontRef),
  206256. fontTransform (other.fontTransform)
  206257. {
  206258. }
  206259. ~SavedState()
  206260. {
  206261. }
  206262. FillType fillType;
  206263. Font font;
  206264. CGFontRef fontRef;
  206265. CGAffineTransform fontTransform;
  206266. };
  206267. ScopedPointer <SavedState> state;
  206268. OwnedArray <SavedState> stateStack;
  206269. HeapBlock <PixelARGB> gradientLookupTable;
  206270. int numGradientLookupEntries;
  206271. static void gradientCallback (void* info, const CGFloat* inData, CGFloat* outData)
  206272. {
  206273. const CoreGraphicsContext* const g = (const CoreGraphicsContext*) info;
  206274. const int index = roundToInt (g->numGradientLookupEntries * inData[0]);
  206275. PixelARGB colour (g->gradientLookupTable [jlimit (0, g->numGradientLookupEntries, index)]);
  206276. colour.unpremultiply();
  206277. outData[0] = colour.getRed() / 255.0f;
  206278. outData[1] = colour.getGreen() / 255.0f;
  206279. outData[2] = colour.getBlue() / 255.0f;
  206280. outData[3] = colour.getAlpha() / 255.0f;
  206281. }
  206282. CGShadingRef createGradient (const AffineTransform& transform, ColourGradient gradient)
  206283. {
  206284. numGradientLookupEntries = gradient.createLookupTable (transform, gradientLookupTable);
  206285. --numGradientLookupEntries;
  206286. CGShadingRef result = 0;
  206287. CGFunctionRef function = CGFunctionCreate ((void*) this, 1, 0, 4, 0, &gradientCallbacks);
  206288. CGPoint p1 (CGPointMake (gradient.x1, gradient.y1));
  206289. if (gradient.isRadial)
  206290. {
  206291. result = CGShadingCreateRadial (rgbColourSpace, p1, 0,
  206292. p1, hypotf (gradient.x1 - gradient.x2, gradient.y1 - gradient.y2),
  206293. function, true, true);
  206294. }
  206295. else
  206296. {
  206297. result = CGShadingCreateAxial (rgbColourSpace, p1,
  206298. CGPointMake (gradient.x2, gradient.y2),
  206299. function, true, true);
  206300. }
  206301. CGFunctionRelease (function);
  206302. return result;
  206303. }
  206304. void drawGradient()
  206305. {
  206306. flip();
  206307. applyTransform (state->fillType.transform);
  206308. CGContextSetInterpolationQuality (context, kCGInterpolationDefault); // (This is required for 10.4, where there's a crash if
  206309. // you draw a gradient with high quality interp enabled).
  206310. CGShadingRef shading = createGradient (state->fillType.transform, *(state->fillType.gradient));
  206311. CGContextSetAlpha (context, state->fillType.getOpacity());
  206312. CGContextDrawShading (context, shading);
  206313. CGShadingRelease (shading);
  206314. }
  206315. void createPath (const Path& path) const
  206316. {
  206317. CGContextBeginPath (context);
  206318. Path::Iterator i (path);
  206319. while (i.next())
  206320. {
  206321. switch (i.elementType)
  206322. {
  206323. case Path::Iterator::startNewSubPath:
  206324. CGContextMoveToPoint (context, i.x1, i.y1);
  206325. break;
  206326. case Path::Iterator::lineTo:
  206327. CGContextAddLineToPoint (context, i.x1, i.y1);
  206328. break;
  206329. case Path::Iterator::quadraticTo:
  206330. CGContextAddQuadCurveToPoint (context, i.x1, i.y1, i.x2, i.y2);
  206331. break;
  206332. case Path::Iterator::cubicTo:
  206333. CGContextAddCurveToPoint (context, i.x1, i.y1, i.x2, i.y2, i.x3, i.y3);
  206334. break;
  206335. case Path::Iterator::closePath:
  206336. CGContextClosePath (context); break;
  206337. default:
  206338. jassertfalse
  206339. break;
  206340. }
  206341. }
  206342. }
  206343. void createPath (const Path& path, const AffineTransform& transform) const
  206344. {
  206345. CGContextBeginPath (context);
  206346. Path::Iterator i (path);
  206347. while (i.next())
  206348. {
  206349. switch (i.elementType)
  206350. {
  206351. case Path::Iterator::startNewSubPath:
  206352. transform.transformPoint (i.x1, i.y1);
  206353. CGContextMoveToPoint (context, i.x1, flipHeight - i.y1);
  206354. break;
  206355. case Path::Iterator::lineTo:
  206356. transform.transformPoint (i.x1, i.y1);
  206357. CGContextAddLineToPoint (context, i.x1, flipHeight - i.y1);
  206358. break;
  206359. case Path::Iterator::quadraticTo:
  206360. transform.transformPoint (i.x1, i.y1);
  206361. transform.transformPoint (i.x2, i.y2);
  206362. CGContextAddQuadCurveToPoint (context, i.x1, flipHeight - i.y1, i.x2, flipHeight - i.y2);
  206363. break;
  206364. case Path::Iterator::cubicTo:
  206365. transform.transformPoint (i.x1, i.y1);
  206366. transform.transformPoint (i.x2, i.y2);
  206367. transform.transformPoint (i.x3, i.y3);
  206368. CGContextAddCurveToPoint (context, i.x1, flipHeight - i.y1, i.x2, flipHeight - i.y2, i.x3, flipHeight - i.y3);
  206369. break;
  206370. case Path::Iterator::closePath:
  206371. CGContextClosePath (context); break;
  206372. default:
  206373. jassertfalse
  206374. break;
  206375. }
  206376. }
  206377. }
  206378. static Image* createAlphaChannelImage (const Image& im)
  206379. {
  206380. if (im.getFormat() == Image::SingleChannel)
  206381. return const_cast <Image*> (&im);
  206382. return im.createCopyOfAlphaChannel();
  206383. }
  206384. static void deleteAlphaChannelImage (const Image& im, Image* const alphaIm)
  206385. {
  206386. if (im.getFormat() != Image::SingleChannel)
  206387. delete alphaIm;
  206388. }
  206389. void flip() const
  206390. {
  206391. CGContextConcatCTM (context, CGAffineTransformMake (1, 0, 0, -1, 0, flipHeight));
  206392. }
  206393. void applyTransform (const AffineTransform& transform) const
  206394. {
  206395. CGAffineTransform t;
  206396. t.a = transform.mat00;
  206397. t.b = transform.mat10;
  206398. t.c = transform.mat01;
  206399. t.d = transform.mat11;
  206400. t.tx = transform.mat02;
  206401. t.ty = transform.mat12;
  206402. CGContextConcatCTM (context, t);
  206403. }
  206404. CoreGraphicsContext (const CoreGraphicsContext&);
  206405. CoreGraphicsContext& operator= (const CoreGraphicsContext&);
  206406. };
  206407. LowLevelGraphicsContext* CoreGraphicsImage::createLowLevelContext()
  206408. {
  206409. return new CoreGraphicsContext (context, imageHeight);
  206410. }
  206411. #endif
  206412. /*** End of inlined file: juce_mac_CoreGraphicsContext.mm ***/
  206413. /*** Start of inlined file: juce_mac_NSViewComponentPeer.mm ***/
  206414. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  206415. // compiled on its own).
  206416. #if JUCE_INCLUDED_FILE
  206417. class NSViewComponentPeer;
  206418. END_JUCE_NAMESPACE
  206419. #define JuceNSView MakeObjCClassName(JuceNSView)
  206420. @interface JuceNSView : NSView<NSTextInput>
  206421. {
  206422. @public
  206423. NSViewComponentPeer* owner;
  206424. NSNotificationCenter* notificationCenter;
  206425. String* stringBeingComposed;
  206426. bool textWasInserted;
  206427. }
  206428. - (JuceNSView*) initWithOwner: (NSViewComponentPeer*) owner withFrame: (NSRect) frame;
  206429. - (void) dealloc;
  206430. - (BOOL) isOpaque;
  206431. - (void) drawRect: (NSRect) r;
  206432. - (void) mouseDown: (NSEvent*) ev;
  206433. - (void) asyncMouseDown: (NSEvent*) ev;
  206434. - (void) mouseUp: (NSEvent*) ev;
  206435. - (void) asyncMouseUp: (NSEvent*) ev;
  206436. - (void) mouseDragged: (NSEvent*) ev;
  206437. - (void) mouseMoved: (NSEvent*) ev;
  206438. - (void) mouseEntered: (NSEvent*) ev;
  206439. - (void) mouseExited: (NSEvent*) ev;
  206440. - (void) rightMouseDown: (NSEvent*) ev;
  206441. - (void) rightMouseDragged: (NSEvent*) ev;
  206442. - (void) rightMouseUp: (NSEvent*) ev;
  206443. - (void) otherMouseDown: (NSEvent*) ev;
  206444. - (void) otherMouseDragged: (NSEvent*) ev;
  206445. - (void) otherMouseUp: (NSEvent*) ev;
  206446. - (void) scrollWheel: (NSEvent*) ev;
  206447. - (BOOL) acceptsFirstMouse: (NSEvent*) ev;
  206448. - (void) frameChanged: (NSNotification*) n;
  206449. - (void) viewDidMoveToWindow;
  206450. - (void) keyDown: (NSEvent*) ev;
  206451. - (void) keyUp: (NSEvent*) ev;
  206452. // NSTextInput Methods
  206453. - (void) insertText: (id) aString;
  206454. - (void) doCommandBySelector: (SEL) aSelector;
  206455. - (void) setMarkedText: (id) aString selectedRange: (NSRange) selRange;
  206456. - (void) unmarkText;
  206457. - (BOOL) hasMarkedText;
  206458. - (long) conversationIdentifier;
  206459. - (NSAttributedString*) attributedSubstringFromRange: (NSRange) theRange;
  206460. - (NSRange) markedRange;
  206461. - (NSRange) selectedRange;
  206462. - (NSRect) firstRectForCharacterRange: (NSRange) theRange;
  206463. - (unsigned int) characterIndexForPoint: (NSPoint) thePoint;
  206464. - (NSArray*) validAttributesForMarkedText;
  206465. - (void) flagsChanged: (NSEvent*) ev;
  206466. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  206467. - (BOOL) performKeyEquivalent: (NSEvent*) ev;
  206468. #endif
  206469. - (BOOL) becomeFirstResponder;
  206470. - (BOOL) resignFirstResponder;
  206471. - (BOOL) acceptsFirstResponder;
  206472. - (void) asyncRepaint: (id) rect;
  206473. - (NSArray*) getSupportedDragTypes;
  206474. - (BOOL) sendDragCallback: (int) type sender: (id <NSDraggingInfo>) sender;
  206475. - (NSDragOperation) draggingEntered: (id <NSDraggingInfo>) sender;
  206476. - (NSDragOperation) draggingUpdated: (id <NSDraggingInfo>) sender;
  206477. - (void) draggingEnded: (id <NSDraggingInfo>) sender;
  206478. - (void) draggingExited: (id <NSDraggingInfo>) sender;
  206479. - (BOOL) prepareForDragOperation: (id <NSDraggingInfo>) sender;
  206480. - (BOOL) performDragOperation: (id <NSDraggingInfo>) sender;
  206481. - (void) concludeDragOperation: (id <NSDraggingInfo>) sender;
  206482. @end
  206483. #define JuceNSWindow MakeObjCClassName(JuceNSWindow)
  206484. #if defined (MAC_OS_X_VERSION_10_6) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
  206485. @interface JuceNSWindow : NSWindow <NSWindowDelegate>
  206486. #else
  206487. @interface JuceNSWindow : NSWindow
  206488. #endif
  206489. {
  206490. @private
  206491. NSViewComponentPeer* owner;
  206492. bool isZooming;
  206493. }
  206494. - (void) setOwner: (NSViewComponentPeer*) owner;
  206495. - (BOOL) canBecomeKeyWindow;
  206496. - (void) becomeKeyWindow;
  206497. - (BOOL) windowShouldClose: (id) window;
  206498. - (NSRect) constrainFrameRect: (NSRect) frameRect toScreen: (NSScreen*) screen;
  206499. - (NSSize) windowWillResize: (NSWindow*) window toSize: (NSSize) proposedFrameSize;
  206500. - (void) zoom: (id) sender;
  206501. @end
  206502. BEGIN_JUCE_NAMESPACE
  206503. class NSViewComponentPeer : public ComponentPeer
  206504. {
  206505. public:
  206506. NSViewComponentPeer (Component* const component,
  206507. const int windowStyleFlags,
  206508. NSView* viewToAttachTo);
  206509. ~NSViewComponentPeer();
  206510. void* getNativeHandle() const;
  206511. void setVisible (bool shouldBeVisible);
  206512. void setTitle (const String& title);
  206513. void setPosition (int x, int y);
  206514. void setSize (int w, int h);
  206515. void setBounds (int x, int y, int w, int h, const bool isNowFullScreen);
  206516. const Rectangle<int> getBounds (const bool global) const;
  206517. const Rectangle<int> getBounds() const;
  206518. const Point<int> getScreenPosition() const;
  206519. const Point<int> relativePositionToGlobal (const Point<int>& relativePosition);
  206520. const Point<int> globalPositionToRelative (const Point<int>& screenPosition);
  206521. void setMinimised (bool shouldBeMinimised);
  206522. bool isMinimised() const;
  206523. void setFullScreen (bool shouldBeFullScreen);
  206524. bool isFullScreen() const;
  206525. bool contains (const Point<int>& position, bool trueIfInAChildWindow) const;
  206526. const BorderSize getFrameSize() const;
  206527. bool setAlwaysOnTop (bool alwaysOnTop);
  206528. void toFront (bool makeActiveWindow);
  206529. void toBehind (ComponentPeer* other);
  206530. void setIcon (const Image& newIcon);
  206531. const StringArray getAvailableRenderingEngines() throw();
  206532. int getCurrentRenderingEngine() throw();
  206533. void setCurrentRenderingEngine (int index) throw();
  206534. virtual void redirectMouseDown (NSEvent* ev);
  206535. virtual void redirectMouseUp (NSEvent* ev);
  206536. virtual void redirectMouseDrag (NSEvent* ev);
  206537. virtual void redirectMouseMove (NSEvent* ev);
  206538. virtual void redirectMouseEnter (NSEvent* ev);
  206539. virtual void redirectMouseExit (NSEvent* ev);
  206540. virtual void redirectMouseWheel (NSEvent* ev);
  206541. void sendMouseEvent (NSEvent* ev);
  206542. bool handleKeyEvent (NSEvent* ev, bool isKeyDown);
  206543. virtual bool redirectKeyDown (NSEvent* ev);
  206544. virtual bool redirectKeyUp (NSEvent* ev);
  206545. virtual void redirectModKeyChange (NSEvent* ev);
  206546. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  206547. virtual bool redirectPerformKeyEquivalent (NSEvent* ev);
  206548. #endif
  206549. virtual BOOL sendDragCallback (int type, id <NSDraggingInfo> sender);
  206550. virtual bool isOpaque();
  206551. virtual void drawRect (NSRect r);
  206552. virtual bool canBecomeKeyWindow();
  206553. virtual bool windowShouldClose();
  206554. virtual void redirectMovedOrResized();
  206555. virtual void viewMovedToWindow();
  206556. virtual NSRect constrainRect (NSRect r);
  206557. static void showArrowCursorIfNeeded();
  206558. static void updateModifiers (NSEvent* e);
  206559. static void updateKeysDown (NSEvent* ev, bool isKeyDown);
  206560. static int getKeyCodeFromEvent (NSEvent* ev)
  206561. {
  206562. const String unmodified (nsStringToJuce ([ev charactersIgnoringModifiers]));
  206563. int keyCode = unmodified[0];
  206564. if (keyCode == 0x19) // (backwards-tab)
  206565. keyCode = '\t';
  206566. else if (keyCode == 0x03) // (enter)
  206567. keyCode = '\r';
  206568. return keyCode;
  206569. }
  206570. static int64 getMouseTime (NSEvent* e)
  206571. {
  206572. return (Time::currentTimeMillis() - Time::getMillisecondCounter())
  206573. + (int64) ([e timestamp] * 1000.0);
  206574. }
  206575. static const Point<int> getMousePos (NSEvent* e, NSView* view)
  206576. {
  206577. NSPoint p = [view convertPoint: [e locationInWindow] fromView: nil];
  206578. return Point<int> (roundToInt (p.x), roundToInt ([view frame].size.height - p.y));
  206579. }
  206580. static int getModifierForButtonNumber (const NSInteger num)
  206581. {
  206582. return num == 0 ? ModifierKeys::leftButtonModifier
  206583. : (num == 1 ? ModifierKeys::rightButtonModifier
  206584. : (num == 2 ? ModifierKeys::middleButtonModifier : 0));
  206585. }
  206586. virtual void viewFocusGain();
  206587. virtual void viewFocusLoss();
  206588. bool isFocused() const;
  206589. void grabFocus();
  206590. void textInputRequired (const Point<int>& position);
  206591. void repaint (int x, int y, int w, int h);
  206592. void performAnyPendingRepaintsNow();
  206593. juce_UseDebuggingNewOperator
  206594. NSWindow* window;
  206595. JuceNSView* view;
  206596. bool isSharedWindow, fullScreen, insideDrawRect, usingCoreGraphics, recursiveToFrontCall;
  206597. static ModifierKeys currentModifiers;
  206598. static ComponentPeer* currentlyFocusedPeer;
  206599. static VoidArray keysCurrentlyDown;
  206600. };
  206601. END_JUCE_NAMESPACE
  206602. @implementation JuceNSView
  206603. - (JuceNSView*) initWithOwner: (NSViewComponentPeer*) owner_
  206604. withFrame: (NSRect) frame
  206605. {
  206606. [super initWithFrame: frame];
  206607. owner = owner_;
  206608. stringBeingComposed = 0;
  206609. textWasInserted = false;
  206610. notificationCenter = [NSNotificationCenter defaultCenter];
  206611. [notificationCenter addObserver: self
  206612. selector: @selector (frameChanged:)
  206613. name: NSViewFrameDidChangeNotification
  206614. object: self];
  206615. if (! owner_->isSharedWindow)
  206616. {
  206617. [notificationCenter addObserver: self
  206618. selector: @selector (frameChanged:)
  206619. name: NSWindowDidMoveNotification
  206620. object: owner_->window];
  206621. }
  206622. [self registerForDraggedTypes: [self getSupportedDragTypes]];
  206623. return self;
  206624. }
  206625. - (void) dealloc
  206626. {
  206627. [notificationCenter removeObserver: self];
  206628. delete stringBeingComposed;
  206629. [super dealloc];
  206630. }
  206631. - (void) drawRect: (NSRect) r
  206632. {
  206633. if (owner != 0)
  206634. owner->drawRect (r);
  206635. }
  206636. - (BOOL) isOpaque
  206637. {
  206638. return owner == 0 || owner->isOpaque();
  206639. }
  206640. - (void) mouseDown: (NSEvent*) ev
  206641. {
  206642. // In some host situations, the host will stop modal loops from working
  206643. // correctly if they're called from a mouse event, so we'll trigger
  206644. // the event asynchronously..
  206645. if (JUCEApplication::getInstance() == 0)
  206646. [self performSelectorOnMainThread: @selector (asyncMouseDown:)
  206647. withObject: ev
  206648. waitUntilDone: NO];
  206649. else
  206650. [self asyncMouseDown: ev];
  206651. }
  206652. - (void) asyncMouseDown: (NSEvent*) ev
  206653. {
  206654. if (owner != 0)
  206655. owner->redirectMouseDown (ev);
  206656. }
  206657. - (void) mouseUp: (NSEvent*) ev
  206658. {
  206659. // In some host situations, the host will stop modal loops from working
  206660. // correctly if they're called from a mouse event, so we'll trigger
  206661. // the event asynchronously..
  206662. if (JUCEApplication::getInstance() == 0)
  206663. [self performSelectorOnMainThread: @selector (asyncMouseUp:)
  206664. withObject: ev
  206665. waitUntilDone: NO];
  206666. else
  206667. [self asyncMouseUp: ev];
  206668. }
  206669. - (void) asyncMouseUp: (NSEvent*) ev
  206670. {
  206671. if (owner != 0)
  206672. owner->redirectMouseUp (ev);
  206673. }
  206674. - (void) mouseDragged: (NSEvent*) ev
  206675. {
  206676. if (owner != 0)
  206677. owner->redirectMouseDrag (ev);
  206678. }
  206679. - (void) mouseMoved: (NSEvent*) ev
  206680. {
  206681. if (owner != 0)
  206682. owner->redirectMouseMove (ev);
  206683. }
  206684. - (void) mouseEntered: (NSEvent*) ev
  206685. {
  206686. if (owner != 0)
  206687. owner->redirectMouseEnter (ev);
  206688. }
  206689. - (void) mouseExited: (NSEvent*) ev
  206690. {
  206691. if (owner != 0)
  206692. owner->redirectMouseExit (ev);
  206693. }
  206694. - (void) rightMouseDown: (NSEvent*) ev
  206695. {
  206696. [self mouseDown: ev];
  206697. }
  206698. - (void) rightMouseDragged: (NSEvent*) ev
  206699. {
  206700. [self mouseDragged: ev];
  206701. }
  206702. - (void) rightMouseUp: (NSEvent*) ev
  206703. {
  206704. [self mouseUp: ev];
  206705. }
  206706. - (void) otherMouseDown: (NSEvent*) ev
  206707. {
  206708. [self mouseDown: ev];
  206709. }
  206710. - (void) otherMouseDragged: (NSEvent*) ev
  206711. {
  206712. [self mouseDragged: ev];
  206713. }
  206714. - (void) otherMouseUp: (NSEvent*) ev
  206715. {
  206716. [self mouseUp: ev];
  206717. }
  206718. - (void) scrollWheel: (NSEvent*) ev
  206719. {
  206720. if (owner != 0)
  206721. owner->redirectMouseWheel (ev);
  206722. }
  206723. - (BOOL) acceptsFirstMouse: (NSEvent*) ev
  206724. {
  206725. return YES;
  206726. }
  206727. - (void) frameChanged: (NSNotification*) n
  206728. {
  206729. if (owner != 0)
  206730. owner->redirectMovedOrResized();
  206731. }
  206732. - (void) viewDidMoveToWindow
  206733. {
  206734. if (owner != 0)
  206735. owner->viewMovedToWindow();
  206736. }
  206737. - (void) asyncRepaint: (id) rect
  206738. {
  206739. NSRect* r = (NSRect*) [((NSData*) rect) bytes];
  206740. [self setNeedsDisplayInRect: *r];
  206741. }
  206742. - (void) keyDown: (NSEvent*) ev
  206743. {
  206744. TextInputTarget* const target = owner->findCurrentTextInputTarget();
  206745. textWasInserted = false;
  206746. if (target != 0)
  206747. [self interpretKeyEvents: [NSArray arrayWithObject: ev]];
  206748. else
  206749. deleteAndZero (stringBeingComposed);
  206750. if ((! textWasInserted) && (owner == 0 || ! owner->redirectKeyDown (ev)))
  206751. [super keyDown: ev];
  206752. }
  206753. - (void) keyUp: (NSEvent*) ev
  206754. {
  206755. if (owner == 0 || ! owner->redirectKeyUp (ev))
  206756. [super keyUp: ev];
  206757. }
  206758. - (void) insertText: (id) aString
  206759. {
  206760. // This commits multi-byte text when return is pressed, or after every keypress for western keyboards
  206761. if ([aString length] > 0)
  206762. {
  206763. TextInputTarget* const target = owner->findCurrentTextInputTarget();
  206764. if (target != 0)
  206765. {
  206766. target->insertTextAtCaret (nsStringToJuce ([aString isKindOfClass: [NSAttributedString class]] ? [aString string] : aString));
  206767. textWasInserted = true;
  206768. }
  206769. }
  206770. deleteAndZero (stringBeingComposed);
  206771. }
  206772. - (void) doCommandBySelector: (SEL) aSelector
  206773. {
  206774. }
  206775. - (void) setMarkedText: (id) aString selectedRange: (NSRange) selectionRange
  206776. {
  206777. if (stringBeingComposed == 0)
  206778. stringBeingComposed = new String();
  206779. *stringBeingComposed = nsStringToJuce ([aString isKindOfClass:[NSAttributedString class]] ? [aString string] : aString);
  206780. TextInputTarget* const target = owner->findCurrentTextInputTarget();
  206781. if (target != 0)
  206782. {
  206783. const Range<int> currentHighlight (target->getHighlightedRegion());
  206784. target->insertTextAtCaret (*stringBeingComposed);
  206785. target->setHighlightedRegion (currentHighlight.withLength (stringBeingComposed->length()));
  206786. textWasInserted = true;
  206787. }
  206788. }
  206789. - (void) unmarkText
  206790. {
  206791. if (stringBeingComposed != 0)
  206792. {
  206793. TextInputTarget* const target = owner->findCurrentTextInputTarget();
  206794. if (target != 0)
  206795. {
  206796. target->insertTextAtCaret (*stringBeingComposed);
  206797. textWasInserted = true;
  206798. }
  206799. }
  206800. deleteAndZero (stringBeingComposed);
  206801. }
  206802. - (BOOL) hasMarkedText
  206803. {
  206804. return stringBeingComposed != 0;
  206805. }
  206806. - (long) conversationIdentifier
  206807. {
  206808. return (long) (pointer_sized_int) self;
  206809. }
  206810. - (NSAttributedString*) attributedSubstringFromRange: (NSRange) theRange
  206811. {
  206812. TextInputTarget* const target = owner->findCurrentTextInputTarget();
  206813. if (target != 0)
  206814. {
  206815. const Range<int> r ((int) theRange.location,
  206816. (int) (theRange.location + theRange.length));
  206817. return [[[NSAttributedString alloc] initWithString: juceStringToNS (target->getTextInRange (r))] autorelease];
  206818. }
  206819. return nil;
  206820. }
  206821. - (NSRange) markedRange
  206822. {
  206823. return stringBeingComposed != 0 ? NSMakeRange (0, stringBeingComposed->length())
  206824. : NSMakeRange (NSNotFound, 0);
  206825. }
  206826. - (NSRange) selectedRange
  206827. {
  206828. TextInputTarget* const target = owner->findCurrentTextInputTarget();
  206829. if (target != 0)
  206830. {
  206831. const Range<int> highlight (target->getHighlightedRegion());
  206832. if (! highlight.isEmpty())
  206833. return NSMakeRange (highlight.getStart(), highlight.getLength());
  206834. }
  206835. return NSMakeRange (NSNotFound, 0);
  206836. }
  206837. - (NSRect) firstRectForCharacterRange: (NSRange) theRange
  206838. {
  206839. JUCE_NAMESPACE::Component* const comp = dynamic_cast <JUCE_NAMESPACE::Component*> (owner->findCurrentTextInputTarget());
  206840. if (comp == 0)
  206841. return NSMakeRect (0, 0, 0, 0);
  206842. const Rectangle<int> bounds (comp->getScreenBounds());
  206843. return NSMakeRect (bounds.getX(),
  206844. [[[NSScreen screens] objectAtIndex: 0] frame].size.height - bounds.getY(),
  206845. bounds.getWidth(),
  206846. bounds.getHeight());
  206847. }
  206848. - (unsigned int) characterIndexForPoint: (NSPoint) thePoint
  206849. {
  206850. return NSNotFound;
  206851. }
  206852. - (NSArray*) validAttributesForMarkedText
  206853. {
  206854. return [NSArray array];
  206855. }
  206856. - (void) flagsChanged: (NSEvent*) ev
  206857. {
  206858. if (owner != 0)
  206859. owner->redirectModKeyChange (ev);
  206860. }
  206861. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  206862. - (BOOL) performKeyEquivalent: (NSEvent*) ev
  206863. {
  206864. if (owner != 0 && owner->redirectPerformKeyEquivalent (ev))
  206865. return true;
  206866. return [super performKeyEquivalent: ev];
  206867. }
  206868. #endif
  206869. - (BOOL) becomeFirstResponder
  206870. {
  206871. if (owner != 0)
  206872. owner->viewFocusGain();
  206873. return true;
  206874. }
  206875. - (BOOL) resignFirstResponder
  206876. {
  206877. if (owner != 0)
  206878. owner->viewFocusLoss();
  206879. return true;
  206880. }
  206881. - (BOOL) acceptsFirstResponder
  206882. {
  206883. return owner != 0 && owner->canBecomeKeyWindow();
  206884. }
  206885. - (NSArray*) getSupportedDragTypes
  206886. {
  206887. return [NSArray arrayWithObjects: NSFilenamesPboardType, /*NSFilesPromisePboardType, NSStringPboardType,*/ nil];
  206888. }
  206889. - (BOOL) sendDragCallback: (int) type sender: (id <NSDraggingInfo>) sender
  206890. {
  206891. return owner != 0 && owner->sendDragCallback (type, sender);
  206892. }
  206893. - (NSDragOperation) draggingEntered: (id <NSDraggingInfo>) sender
  206894. {
  206895. if ([self sendDragCallback: 0 sender: sender])
  206896. return NSDragOperationCopy | NSDragOperationMove | NSDragOperationGeneric;
  206897. else
  206898. return NSDragOperationNone;
  206899. }
  206900. - (NSDragOperation) draggingUpdated: (id <NSDraggingInfo>) sender
  206901. {
  206902. if ([self sendDragCallback: 0 sender: sender])
  206903. return NSDragOperationCopy | NSDragOperationMove | NSDragOperationGeneric;
  206904. else
  206905. return NSDragOperationNone;
  206906. }
  206907. - (void) draggingEnded: (id <NSDraggingInfo>) sender
  206908. {
  206909. [self sendDragCallback: 1 sender: sender];
  206910. }
  206911. - (void) draggingExited: (id <NSDraggingInfo>) sender
  206912. {
  206913. [self sendDragCallback: 1 sender: sender];
  206914. }
  206915. - (BOOL) prepareForDragOperation: (id <NSDraggingInfo>) sender
  206916. {
  206917. return YES;
  206918. }
  206919. - (BOOL) performDragOperation: (id <NSDraggingInfo>) sender
  206920. {
  206921. return [self sendDragCallback: 2 sender: sender];
  206922. }
  206923. - (void) concludeDragOperation: (id <NSDraggingInfo>) sender
  206924. {
  206925. }
  206926. @end
  206927. @implementation JuceNSWindow
  206928. - (void) setOwner: (NSViewComponentPeer*) owner_
  206929. {
  206930. owner = owner_;
  206931. isZooming = false;
  206932. }
  206933. - (BOOL) canBecomeKeyWindow
  206934. {
  206935. return owner != 0 && owner->canBecomeKeyWindow();
  206936. }
  206937. - (void) becomeKeyWindow
  206938. {
  206939. [super becomeKeyWindow];
  206940. if (owner != 0)
  206941. owner->grabFocus();
  206942. }
  206943. - (BOOL) windowShouldClose: (id) window
  206944. {
  206945. return owner == 0 || owner->windowShouldClose();
  206946. }
  206947. - (NSRect) constrainFrameRect: (NSRect) frameRect toScreen: (NSScreen*) screen
  206948. {
  206949. if (owner != 0)
  206950. frameRect = owner->constrainRect (frameRect);
  206951. return frameRect;
  206952. }
  206953. - (NSSize) windowWillResize: (NSWindow*) window toSize: (NSSize) proposedFrameSize
  206954. {
  206955. if (isZooming)
  206956. return proposedFrameSize;
  206957. NSRect frameRect = [self frame];
  206958. frameRect.origin.y -= proposedFrameSize.height - frameRect.size.height;
  206959. frameRect.size = proposedFrameSize;
  206960. if (owner != 0)
  206961. frameRect = owner->constrainRect (frameRect);
  206962. return frameRect.size;
  206963. }
  206964. - (void) zoom: (id) sender
  206965. {
  206966. isZooming = true;
  206967. [super zoom: sender];
  206968. isZooming = false;
  206969. }
  206970. - (void) windowWillMove: (NSNotification*) notification
  206971. {
  206972. if (JUCE_NAMESPACE::Component::getCurrentlyModalComponent() != 0
  206973. && owner->getComponent()->isCurrentlyBlockedByAnotherModalComponent()
  206974. && (owner->getStyleFlags() & JUCE_NAMESPACE::ComponentPeer::windowHasTitleBar) != 0)
  206975. JUCE_NAMESPACE::Component::getCurrentlyModalComponent()->inputAttemptWhenModal();
  206976. }
  206977. @end
  206978. BEGIN_JUCE_NAMESPACE
  206979. ModifierKeys NSViewComponentPeer::currentModifiers;
  206980. ComponentPeer* NSViewComponentPeer::currentlyFocusedPeer = 0;
  206981. VoidArray NSViewComponentPeer::keysCurrentlyDown;
  206982. bool KeyPress::isKeyCurrentlyDown (const int keyCode) throw()
  206983. {
  206984. if (NSViewComponentPeer::keysCurrentlyDown.contains ((void*) keyCode))
  206985. return true;
  206986. if (keyCode >= 'A' && keyCode <= 'Z'
  206987. && NSViewComponentPeer::keysCurrentlyDown.contains ((void*) (int) CharacterFunctions::toLowerCase ((tchar) keyCode)))
  206988. return true;
  206989. if (keyCode >= 'a' && keyCode <= 'z'
  206990. && NSViewComponentPeer::keysCurrentlyDown.contains ((void*) (int) CharacterFunctions::toUpperCase ((tchar) keyCode)))
  206991. return true;
  206992. return false;
  206993. }
  206994. void NSViewComponentPeer::updateModifiers (NSEvent* e)
  206995. {
  206996. int m = 0;
  206997. if (([e modifierFlags] & NSShiftKeyMask) != 0) m |= ModifierKeys::shiftModifier;
  206998. if (([e modifierFlags] & NSControlKeyMask) != 0) m |= ModifierKeys::ctrlModifier;
  206999. if (([e modifierFlags] & NSAlternateKeyMask) != 0) m |= ModifierKeys::altModifier;
  207000. if (([e modifierFlags] & NSCommandKeyMask) != 0) m |= ModifierKeys::commandModifier;
  207001. currentModifiers = currentModifiers.withOnlyMouseButtons().withFlags (m);
  207002. }
  207003. void NSViewComponentPeer::updateKeysDown (NSEvent* ev, bool isKeyDown)
  207004. {
  207005. updateModifiers (ev);
  207006. int keyCode = getKeyCodeFromEvent (ev);
  207007. if (keyCode != 0)
  207008. {
  207009. if (isKeyDown)
  207010. keysCurrentlyDown.addIfNotAlreadyThere ((void*) keyCode);
  207011. else
  207012. keysCurrentlyDown.removeValue ((void*) keyCode);
  207013. }
  207014. }
  207015. const ModifierKeys ModifierKeys::getCurrentModifiersRealtime() throw()
  207016. {
  207017. return NSViewComponentPeer::currentModifiers;
  207018. }
  207019. void ModifierKeys::updateCurrentModifiers() throw()
  207020. {
  207021. currentModifiers = NSViewComponentPeer::currentModifiers;
  207022. }
  207023. NSViewComponentPeer::NSViewComponentPeer (Component* const component_,
  207024. const int windowStyleFlags,
  207025. NSView* viewToAttachTo)
  207026. : ComponentPeer (component_, windowStyleFlags),
  207027. window (0),
  207028. view (0),
  207029. isSharedWindow (viewToAttachTo != 0),
  207030. fullScreen (false),
  207031. insideDrawRect (false),
  207032. #if USE_COREGRAPHICS_RENDERING
  207033. usingCoreGraphics (true),
  207034. #else
  207035. usingCoreGraphics (false),
  207036. #endif
  207037. recursiveToFrontCall (false)
  207038. {
  207039. NSRect r;
  207040. r.origin.x = 0;
  207041. r.origin.y = 0;
  207042. r.size.width = (float) component->getWidth();
  207043. r.size.height = (float) component->getHeight();
  207044. view = [[JuceNSView alloc] initWithOwner: this withFrame: r];
  207045. [view setPostsFrameChangedNotifications: YES];
  207046. if (isSharedWindow)
  207047. {
  207048. window = [viewToAttachTo window];
  207049. [viewToAttachTo addSubview: view];
  207050. setVisible (component->isVisible());
  207051. }
  207052. else
  207053. {
  207054. r.origin.x = (float) component->getX();
  207055. r.origin.y = (float) component->getY();
  207056. r.origin.y = [[[NSScreen screens] objectAtIndex: 0] frame].size.height - (r.origin.y + r.size.height);
  207057. unsigned int style = 0;
  207058. if ((windowStyleFlags & windowHasTitleBar) == 0)
  207059. style = NSBorderlessWindowMask;
  207060. else
  207061. style = NSTitledWindowMask;
  207062. if ((windowStyleFlags & windowHasMinimiseButton) != 0)
  207063. style |= NSMiniaturizableWindowMask;
  207064. if ((windowStyleFlags & windowHasCloseButton) != 0)
  207065. style |= NSClosableWindowMask;
  207066. if ((windowStyleFlags & windowIsResizable) != 0)
  207067. style |= NSResizableWindowMask;
  207068. window = [[JuceNSWindow alloc] initWithContentRect: r
  207069. styleMask: style
  207070. backing: NSBackingStoreBuffered
  207071. defer: YES];
  207072. [((JuceNSWindow*) window) setOwner: this];
  207073. [window orderOut: nil];
  207074. [window setDelegate: (JuceNSWindow*) window];
  207075. [window setOpaque: component->isOpaque()];
  207076. [window setHasShadow: ((windowStyleFlags & windowHasDropShadow) != 0)];
  207077. if (component->isAlwaysOnTop())
  207078. [window setLevel: NSFloatingWindowLevel];
  207079. [window setContentView: view];
  207080. [window setAutodisplay: YES];
  207081. [window setAcceptsMouseMovedEvents: YES];
  207082. // We'll both retain and also release this on closing because plugin hosts can unexpectedly
  207083. // close the window for us, and also tend to get cause trouble if setReleasedWhenClosed is NO.
  207084. [window setReleasedWhenClosed: YES];
  207085. [window retain];
  207086. [window setExcludedFromWindowsMenu: (windowStyleFlags & windowIsTemporary) != 0];
  207087. [window setIgnoresMouseEvents: (windowStyleFlags & windowIgnoresMouseClicks) != 0];
  207088. }
  207089. setTitle (component->getName());
  207090. }
  207091. NSViewComponentPeer::~NSViewComponentPeer()
  207092. {
  207093. view->owner = 0;
  207094. [view removeFromSuperview];
  207095. [view release];
  207096. if (! isSharedWindow)
  207097. {
  207098. [((JuceNSWindow*) window) setOwner: 0];
  207099. [window close];
  207100. [window release];
  207101. }
  207102. }
  207103. void* NSViewComponentPeer::getNativeHandle() const
  207104. {
  207105. return view;
  207106. }
  207107. void NSViewComponentPeer::setVisible (bool shouldBeVisible)
  207108. {
  207109. if (isSharedWindow)
  207110. {
  207111. [view setHidden: ! shouldBeVisible];
  207112. }
  207113. else
  207114. {
  207115. if (shouldBeVisible)
  207116. {
  207117. [window orderFront: nil];
  207118. handleBroughtToFront();
  207119. }
  207120. else
  207121. {
  207122. [window orderOut: nil];
  207123. }
  207124. }
  207125. }
  207126. void NSViewComponentPeer::setTitle (const String& title)
  207127. {
  207128. const ScopedAutoReleasePool pool;
  207129. if (! isSharedWindow)
  207130. [window setTitle: juceStringToNS (title)];
  207131. }
  207132. void NSViewComponentPeer::setPosition (int x, int y)
  207133. {
  207134. setBounds (x, y, component->getWidth(), component->getHeight(), false);
  207135. }
  207136. void NSViewComponentPeer::setSize (int w, int h)
  207137. {
  207138. setBounds (component->getX(), component->getY(), w, h, false);
  207139. }
  207140. void NSViewComponentPeer::setBounds (int x, int y, int w, int h, const bool isNowFullScreen)
  207141. {
  207142. fullScreen = isNowFullScreen;
  207143. w = jmax (0, w);
  207144. h = jmax (0, h);
  207145. NSRect r;
  207146. r.origin.x = (float) x;
  207147. r.origin.y = (float) y;
  207148. r.size.width = (float) w;
  207149. r.size.height = (float) h;
  207150. if (isSharedWindow)
  207151. {
  207152. r.origin.y = [[view superview] frame].size.height - (r.origin.y + r.size.height);
  207153. if ([view frame].size.width != r.size.width
  207154. || [view frame].size.height != r.size.height)
  207155. [view setNeedsDisplay: true];
  207156. [view setFrame: r];
  207157. }
  207158. else
  207159. {
  207160. r.origin.y = [[[NSScreen screens] objectAtIndex: 0] frame].size.height - (r.origin.y + r.size.height);
  207161. [window setFrame: [window frameRectForContentRect: r]
  207162. display: true];
  207163. }
  207164. }
  207165. const Rectangle<int> NSViewComponentPeer::getBounds (const bool global) const
  207166. {
  207167. NSRect r = [view frame];
  207168. if (global && [view window] != 0)
  207169. {
  207170. r = [view convertRect: r toView: nil];
  207171. NSRect wr = [[view window] frame];
  207172. r.origin.x += wr.origin.x;
  207173. r.origin.y += wr.origin.y;
  207174. r.origin.y = [[[NSScreen screens] objectAtIndex: 0] frame].size.height - r.origin.y - r.size.height;
  207175. }
  207176. else
  207177. {
  207178. r.origin.y = [[view superview] frame].size.height - r.origin.y - r.size.height;
  207179. }
  207180. return Rectangle<int> ((int) r.origin.x, (int) r.origin.y, (int) r.size.width, (int) r.size.height);
  207181. }
  207182. const Rectangle<int> NSViewComponentPeer::getBounds() const
  207183. {
  207184. return getBounds (! isSharedWindow);
  207185. }
  207186. const Point<int> NSViewComponentPeer::getScreenPosition() const
  207187. {
  207188. return getBounds (true).getPosition();
  207189. }
  207190. const Point<int> NSViewComponentPeer::relativePositionToGlobal (const Point<int>& relativePosition)
  207191. {
  207192. return relativePosition + getScreenPosition();
  207193. }
  207194. const Point<int> NSViewComponentPeer::globalPositionToRelative (const Point<int>& screenPosition)
  207195. {
  207196. return screenPosition - getScreenPosition();
  207197. }
  207198. NSRect NSViewComponentPeer::constrainRect (NSRect r)
  207199. {
  207200. if (constrainer != 0)
  207201. {
  207202. NSRect current = [window frame];
  207203. current.origin.y = [[[NSScreen screens] objectAtIndex: 0] frame].size.height - current.origin.y - current.size.height;
  207204. r.origin.y = [[[NSScreen screens] objectAtIndex: 0] frame].size.height - r.origin.y - r.size.height;
  207205. Rectangle<int> pos ((int) r.origin.x, (int) r.origin.y,
  207206. (int) r.size.width, (int) r.size.height);
  207207. Rectangle<int> original ((int) current.origin.x, (int) current.origin.y,
  207208. (int) current.size.width, (int) current.size.height);
  207209. constrainer->checkBounds (pos, original,
  207210. Desktop::getInstance().getAllMonitorDisplayAreas().getBounds(),
  207211. pos.getY() != original.getY() && pos.getBottom() == original.getBottom(),
  207212. pos.getX() != original.getX() && pos.getRight() == original.getRight(),
  207213. pos.getY() == original.getY() && pos.getBottom() != original.getBottom(),
  207214. pos.getX() == original.getX() && pos.getRight() != original.getRight());
  207215. r.origin.x = pos.getX();
  207216. r.origin.y = [[[NSScreen screens] objectAtIndex: 0] frame].size.height - r.size.height - pos.getY();
  207217. r.size.width = pos.getWidth();
  207218. r.size.height = pos.getHeight();
  207219. }
  207220. return r;
  207221. }
  207222. void NSViewComponentPeer::setMinimised (bool shouldBeMinimised)
  207223. {
  207224. if (! isSharedWindow)
  207225. {
  207226. if (shouldBeMinimised)
  207227. [window miniaturize: nil];
  207228. else
  207229. [window deminiaturize: nil];
  207230. }
  207231. }
  207232. bool NSViewComponentPeer::isMinimised() const
  207233. {
  207234. return window != 0 && [window isMiniaturized];
  207235. }
  207236. void NSViewComponentPeer::setFullScreen (bool shouldBeFullScreen)
  207237. {
  207238. if (! isSharedWindow)
  207239. {
  207240. Rectangle<int> r (lastNonFullscreenBounds);
  207241. setMinimised (false);
  207242. if (fullScreen != shouldBeFullScreen)
  207243. {
  207244. if (shouldBeFullScreen && (getStyleFlags() & windowHasTitleBar) != 0)
  207245. {
  207246. fullScreen = true;
  207247. [window performZoom: nil];
  207248. }
  207249. else
  207250. {
  207251. if (shouldBeFullScreen)
  207252. r = Desktop::getInstance().getMainMonitorArea();
  207253. // (can't call the component's setBounds method because that'll reset our fullscreen flag)
  207254. if (r != getComponent()->getBounds() && ! r.isEmpty())
  207255. setBounds (r.getX(), r.getY(), r.getWidth(), r.getHeight(), shouldBeFullScreen);
  207256. }
  207257. }
  207258. }
  207259. }
  207260. bool NSViewComponentPeer::isFullScreen() const
  207261. {
  207262. return fullScreen;
  207263. }
  207264. bool NSViewComponentPeer::contains (const Point<int>& position, bool trueIfInAChildWindow) const
  207265. {
  207266. if (((unsigned int) position.getX()) >= (unsigned int) component->getWidth()
  207267. || ((unsigned int) position.getY()) >= (unsigned int) component->getHeight())
  207268. return false;
  207269. NSPoint p;
  207270. p.x = (float) position.getX();
  207271. p.y = (float) position.getY();
  207272. NSView* v = [view hitTest: p];
  207273. if (trueIfInAChildWindow)
  207274. return v != nil;
  207275. return v == view;
  207276. }
  207277. const BorderSize NSViewComponentPeer::getFrameSize() const
  207278. {
  207279. BorderSize b;
  207280. if (! isSharedWindow)
  207281. {
  207282. NSRect v = [view convertRect: [view frame] toView: nil];
  207283. NSRect w = [window frame];
  207284. b.setTop ((int) (w.size.height - (v.origin.y + v.size.height)));
  207285. b.setBottom ((int) v.origin.y);
  207286. b.setLeft ((int) v.origin.x);
  207287. b.setRight ((int) (w.size.width - (v.origin.x + v.size.width)));
  207288. }
  207289. return b;
  207290. }
  207291. bool NSViewComponentPeer::setAlwaysOnTop (bool alwaysOnTop)
  207292. {
  207293. if (! isSharedWindow)
  207294. {
  207295. [window setLevel: alwaysOnTop ? NSFloatingWindowLevel
  207296. : NSNormalWindowLevel];
  207297. }
  207298. return true;
  207299. }
  207300. void NSViewComponentPeer::toFront (bool makeActiveWindow)
  207301. {
  207302. if (isSharedWindow)
  207303. {
  207304. [[view superview] addSubview: view
  207305. positioned: NSWindowAbove
  207306. relativeTo: nil];
  207307. }
  207308. if (window != 0 && component->isVisible())
  207309. {
  207310. if (makeActiveWindow)
  207311. [window makeKeyAndOrderFront: nil];
  207312. else
  207313. [window orderFront: nil];
  207314. if (! recursiveToFrontCall)
  207315. {
  207316. recursiveToFrontCall = true;
  207317. Desktop::getInstance().getMainMouseSource().forceMouseCursorUpdate();
  207318. handleBroughtToFront();
  207319. recursiveToFrontCall = false;
  207320. }
  207321. }
  207322. }
  207323. void NSViewComponentPeer::toBehind (ComponentPeer* other)
  207324. {
  207325. NSViewComponentPeer* o = (NSViewComponentPeer*) other;
  207326. if (isSharedWindow)
  207327. {
  207328. [[view superview] addSubview: view
  207329. positioned: NSWindowBelow
  207330. relativeTo: o->view];
  207331. }
  207332. else
  207333. {
  207334. [window orderWindow: NSWindowBelow
  207335. relativeTo: o->window != 0 ? [o->window windowNumber]
  207336. : nil ];
  207337. }
  207338. }
  207339. void NSViewComponentPeer::setIcon (const Image& /*newIcon*/)
  207340. {
  207341. // to do..
  207342. }
  207343. void NSViewComponentPeer::viewFocusGain()
  207344. {
  207345. if (currentlyFocusedPeer != this)
  207346. {
  207347. if (ComponentPeer::isValidPeer (currentlyFocusedPeer))
  207348. currentlyFocusedPeer->handleFocusLoss();
  207349. currentlyFocusedPeer = this;
  207350. handleFocusGain();
  207351. }
  207352. }
  207353. void NSViewComponentPeer::viewFocusLoss()
  207354. {
  207355. if (currentlyFocusedPeer == this)
  207356. {
  207357. currentlyFocusedPeer = 0;
  207358. handleFocusLoss();
  207359. }
  207360. }
  207361. void juce_HandleProcessFocusChange()
  207362. {
  207363. NSViewComponentPeer::keysCurrentlyDown.clear();
  207364. if (NSViewComponentPeer::isValidPeer (NSViewComponentPeer::currentlyFocusedPeer))
  207365. {
  207366. if (Process::isForegroundProcess())
  207367. {
  207368. NSViewComponentPeer::currentlyFocusedPeer->handleFocusGain();
  207369. ComponentPeer::bringModalComponentToFront();
  207370. }
  207371. else
  207372. {
  207373. NSViewComponentPeer::currentlyFocusedPeer->handleFocusLoss();
  207374. // turn kiosk mode off if we lose focus..
  207375. Desktop::getInstance().setKioskModeComponent (0);
  207376. }
  207377. }
  207378. }
  207379. bool NSViewComponentPeer::isFocused() const
  207380. {
  207381. return isSharedWindow ? this == currentlyFocusedPeer
  207382. : (window != 0 && [window isKeyWindow]);
  207383. }
  207384. void NSViewComponentPeer::grabFocus()
  207385. {
  207386. if (window != 0)
  207387. {
  207388. [window makeKeyWindow];
  207389. [window makeFirstResponder: view];
  207390. viewFocusGain();
  207391. }
  207392. }
  207393. void NSViewComponentPeer::textInputRequired (const Point<int>&)
  207394. {
  207395. }
  207396. bool NSViewComponentPeer::handleKeyEvent (NSEvent* ev, bool isKeyDown)
  207397. {
  207398. String unicode (nsStringToJuce ([ev characters]));
  207399. String unmodified (nsStringToJuce ([ev charactersIgnoringModifiers]));
  207400. int keyCode = getKeyCodeFromEvent (ev);
  207401. //DBG ("unicode: " + unicode + " " + String::toHexString ((int) unicode[0]));
  207402. //DBG ("unmodified: " + unmodified + " " + String::toHexString ((int) unmodified[0]));
  207403. if (unicode.isNotEmpty() || keyCode != 0)
  207404. {
  207405. if (isKeyDown)
  207406. {
  207407. bool used = false;
  207408. while (unicode.length() > 0)
  207409. {
  207410. juce_wchar textCharacter = unicode[0];
  207411. unicode = unicode.substring (1);
  207412. if (([ev modifierFlags] & NSCommandKeyMask) != 0)
  207413. textCharacter = 0;
  207414. used = handleKeyUpOrDown (true) || used;
  207415. used = handleKeyPress (keyCode, textCharacter) || used;
  207416. }
  207417. return used;
  207418. }
  207419. else
  207420. {
  207421. if (handleKeyUpOrDown (false))
  207422. return true;
  207423. }
  207424. }
  207425. return false;
  207426. }
  207427. bool NSViewComponentPeer::redirectKeyDown (NSEvent* ev)
  207428. {
  207429. updateKeysDown (ev, true);
  207430. bool used = handleKeyEvent (ev, true);
  207431. if (([ev modifierFlags] & NSCommandKeyMask) != 0)
  207432. {
  207433. // for command keys, the key-up event is thrown away, so simulate one..
  207434. updateKeysDown (ev, false);
  207435. used = (isValidPeer (this) && handleKeyEvent (ev, false)) || used;
  207436. }
  207437. // (If we're running modally, don't allow unused keystrokes to be passed
  207438. // along to other blocked views..)
  207439. if (Component::getCurrentlyModalComponent() != 0)
  207440. used = true;
  207441. return used;
  207442. }
  207443. bool NSViewComponentPeer::redirectKeyUp (NSEvent* ev)
  207444. {
  207445. updateKeysDown (ev, false);
  207446. return handleKeyEvent (ev, false)
  207447. || Component::getCurrentlyModalComponent() != 0;
  207448. }
  207449. void NSViewComponentPeer::redirectModKeyChange (NSEvent* ev)
  207450. {
  207451. keysCurrentlyDown.clear();
  207452. handleKeyUpOrDown (true);
  207453. updateModifiers (ev);
  207454. handleModifierKeysChange();
  207455. }
  207456. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  207457. bool NSViewComponentPeer::redirectPerformKeyEquivalent (NSEvent* ev)
  207458. {
  207459. if ([ev type] == NSKeyDown)
  207460. return redirectKeyDown (ev);
  207461. else if ([ev type] == NSKeyUp)
  207462. return redirectKeyUp (ev);
  207463. return false;
  207464. }
  207465. #endif
  207466. void NSViewComponentPeer::sendMouseEvent (NSEvent* ev)
  207467. {
  207468. updateModifiers (ev);
  207469. handleMouseEvent (0, getMousePos (ev, view), currentModifiers, getMouseTime (ev));
  207470. }
  207471. void NSViewComponentPeer::redirectMouseDown (NSEvent* ev)
  207472. {
  207473. currentModifiers = currentModifiers.withFlags (getModifierForButtonNumber ([ev buttonNumber]));
  207474. sendMouseEvent (ev);
  207475. }
  207476. void NSViewComponentPeer::redirectMouseUp (NSEvent* ev)
  207477. {
  207478. currentModifiers = currentModifiers.withoutFlags (getModifierForButtonNumber ([ev buttonNumber]));
  207479. sendMouseEvent (ev);
  207480. showArrowCursorIfNeeded();
  207481. }
  207482. void NSViewComponentPeer::redirectMouseDrag (NSEvent* ev)
  207483. {
  207484. currentModifiers = currentModifiers.withFlags (getModifierForButtonNumber ([ev buttonNumber]));
  207485. sendMouseEvent (ev);
  207486. }
  207487. void NSViewComponentPeer::redirectMouseMove (NSEvent* ev)
  207488. {
  207489. currentModifiers = currentModifiers.withoutMouseButtons();
  207490. sendMouseEvent (ev);
  207491. showArrowCursorIfNeeded();
  207492. }
  207493. void NSViewComponentPeer::redirectMouseEnter (NSEvent* ev)
  207494. {
  207495. Desktop::getInstance().getMainMouseSource().forceMouseCursorUpdate();
  207496. currentModifiers = currentModifiers.withoutMouseButtons();
  207497. sendMouseEvent (ev);
  207498. }
  207499. void NSViewComponentPeer::redirectMouseExit (NSEvent* ev)
  207500. {
  207501. currentModifiers = currentModifiers.withoutMouseButtons();
  207502. sendMouseEvent (ev);
  207503. }
  207504. void NSViewComponentPeer::redirectMouseWheel (NSEvent* ev)
  207505. {
  207506. updateModifiers (ev);
  207507. handleMouseWheel (0, getMousePos (ev, view), getMouseTime (ev),
  207508. [ev deltaX] * 10.0f, [ev deltaY] * 10.0f);
  207509. }
  207510. void NSViewComponentPeer::showArrowCursorIfNeeded()
  207511. {
  207512. MouseInputSource& mouse = Desktop::getInstance().getMainMouseSource();
  207513. if (mouse.getComponentUnderMouse() == 0
  207514. && Desktop::getInstance().findComponentAt (mouse.getScreenPosition()) == 0)
  207515. {
  207516. [[NSCursor arrowCursor] set];
  207517. }
  207518. }
  207519. BOOL NSViewComponentPeer::sendDragCallback (int type, id <NSDraggingInfo> sender)
  207520. {
  207521. NSString* bestType
  207522. = [[sender draggingPasteboard] availableTypeFromArray: [view getSupportedDragTypes]];
  207523. if (bestType == nil)
  207524. return false;
  207525. NSPoint p = [view convertPoint: [sender draggingLocation] fromView: nil];
  207526. const Point<int> pos ((int) p.x, (int) ([view frame].size.height - p.y));
  207527. StringArray files;
  207528. id list = [[sender draggingPasteboard] propertyListForType: bestType];
  207529. if (list == nil)
  207530. return false;
  207531. if ([list isKindOfClass: [NSArray class]])
  207532. {
  207533. NSArray* items = (NSArray*) list;
  207534. for (unsigned int i = 0; i < [items count]; ++i)
  207535. files.add (nsStringToJuce ((NSString*) [items objectAtIndex: i]));
  207536. }
  207537. if (files.size() == 0)
  207538. return false;
  207539. if (type == 0)
  207540. handleFileDragMove (files, pos);
  207541. else if (type == 1)
  207542. handleFileDragExit (files);
  207543. else if (type == 2)
  207544. handleFileDragDrop (files, pos);
  207545. return true;
  207546. }
  207547. bool NSViewComponentPeer::isOpaque()
  207548. {
  207549. return component == 0 || component->isOpaque();
  207550. }
  207551. void NSViewComponentPeer::drawRect (NSRect r)
  207552. {
  207553. if (r.size.width < 1.0f || r.size.height < 1.0f)
  207554. return;
  207555. CGContextRef cg = (CGContextRef) [[NSGraphicsContext currentContext] graphicsPort];
  207556. if (! component->isOpaque())
  207557. CGContextClearRect (cg, CGContextGetClipBoundingBox (cg));
  207558. #if USE_COREGRAPHICS_RENDERING
  207559. if (usingCoreGraphics)
  207560. {
  207561. CoreGraphicsContext context (cg, (float) [view frame].size.height);
  207562. insideDrawRect = true;
  207563. handlePaint (context);
  207564. insideDrawRect = false;
  207565. }
  207566. else
  207567. #endif
  207568. {
  207569. Image temp (getComponent()->isOpaque() ? Image::RGB : Image::ARGB,
  207570. (int) (r.size.width + 0.5f),
  207571. (int) (r.size.height + 0.5f),
  207572. ! getComponent()->isOpaque());
  207573. LowLevelGraphicsSoftwareRenderer context (temp);
  207574. context.setOrigin (-roundToInt (r.origin.x),
  207575. -roundToInt ([view frame].size.height - (r.origin.y + r.size.height)));
  207576. const NSRect* rects = 0;
  207577. NSInteger numRects = 0;
  207578. [view getRectsBeingDrawn: &rects count: &numRects];
  207579. RectangleList clip;
  207580. for (int i = 0; i < numRects; ++i)
  207581. {
  207582. clip.addWithoutMerging (Rectangle<int> (roundToInt (rects[i].origin.x),
  207583. roundToInt ([view frame].size.height - (rects[i].origin.y + rects[i].size.height)),
  207584. roundToInt (rects[i].size.width),
  207585. roundToInt (rects[i].size.height)));
  207586. }
  207587. if (context.clipToRectangleList (clip))
  207588. {
  207589. insideDrawRect = true;
  207590. handlePaint (context);
  207591. insideDrawRect = false;
  207592. CGColorSpaceRef colourSpace = CGColorSpaceCreateDeviceRGB();
  207593. CGImageRef image = CoreGraphicsImage::createImage (temp, false, colourSpace);
  207594. CGColorSpaceRelease (colourSpace);
  207595. CGContextDrawImage (cg, CGRectMake (r.origin.x, r.origin.y, temp.getWidth(), temp.getHeight()), image);
  207596. CGImageRelease (image);
  207597. }
  207598. }
  207599. }
  207600. const StringArray NSViewComponentPeer::getAvailableRenderingEngines() throw()
  207601. {
  207602. StringArray s;
  207603. s.add ("Software Renderer");
  207604. #if USE_COREGRAPHICS_RENDERING
  207605. s.add ("CoreGraphics Renderer");
  207606. #endif
  207607. return s;
  207608. }
  207609. int NSViewComponentPeer::getCurrentRenderingEngine() throw()
  207610. {
  207611. return usingCoreGraphics ? 1 : 0;
  207612. }
  207613. void NSViewComponentPeer::setCurrentRenderingEngine (int index) throw()
  207614. {
  207615. #if USE_COREGRAPHICS_RENDERING
  207616. if (usingCoreGraphics != (index > 0))
  207617. {
  207618. usingCoreGraphics = index > 0;
  207619. [view setNeedsDisplay: true];
  207620. }
  207621. #endif
  207622. }
  207623. bool NSViewComponentPeer::canBecomeKeyWindow()
  207624. {
  207625. return (getStyleFlags() & JUCE_NAMESPACE::ComponentPeer::windowIgnoresKeyPresses) == 0;
  207626. }
  207627. bool NSViewComponentPeer::windowShouldClose()
  207628. {
  207629. if (! isValidPeer (this))
  207630. return YES;
  207631. handleUserClosingWindow();
  207632. return NO;
  207633. }
  207634. void NSViewComponentPeer::redirectMovedOrResized()
  207635. {
  207636. handleMovedOrResized();
  207637. }
  207638. void NSViewComponentPeer::viewMovedToWindow()
  207639. {
  207640. if (isSharedWindow)
  207641. window = [view window];
  207642. }
  207643. void Desktop::createMouseInputSources()
  207644. {
  207645. mouseSources.add (new MouseInputSource (0, true));
  207646. }
  207647. void juce_setKioskComponent (Component* kioskModeComponent, bool enableOrDisable, bool allowMenusAndBars)
  207648. {
  207649. // Very annoyingly, this function has to use the old SetSystemUIMode function,
  207650. // which is in Carbon.framework. But, because there's no Cocoa equivalent, it
  207651. // is apparently still available in 64-bit apps..
  207652. if (enableOrDisable)
  207653. {
  207654. SetSystemUIMode (kUIModeAllSuppressed, allowMenusAndBars ? kUIOptionAutoShowMenuBar : 0);
  207655. kioskModeComponent->setBounds (Desktop::getInstance().getMainMonitorArea (false));
  207656. }
  207657. else
  207658. {
  207659. SetSystemUIMode (kUIModeNormal, 0);
  207660. }
  207661. }
  207662. class AsyncRepaintMessage : public CallbackMessage
  207663. {
  207664. public:
  207665. NSViewComponentPeer* const peer;
  207666. const Rectangle<int> rect;
  207667. AsyncRepaintMessage (NSViewComponentPeer* const peer_, const Rectangle<int>& rect_)
  207668. : peer (peer_), rect (rect_)
  207669. {
  207670. }
  207671. void messageCallback()
  207672. {
  207673. if (ComponentPeer::isValidPeer (peer))
  207674. peer->repaint (rect.getX(), rect.getY(), rect.getWidth(), rect.getHeight());
  207675. }
  207676. };
  207677. void NSViewComponentPeer::repaint (int x, int y, int w, int h)
  207678. {
  207679. if (insideDrawRect)
  207680. {
  207681. (new AsyncRepaintMessage (this, Rectangle<int> (x, y, w, h)))->post();
  207682. }
  207683. else
  207684. {
  207685. [view setNeedsDisplayInRect: NSMakeRect ((float) x, (float) ([view frame].size.height - (y + h)),
  207686. (float) w, (float) h)];
  207687. }
  207688. }
  207689. void NSViewComponentPeer::performAnyPendingRepaintsNow()
  207690. {
  207691. [view displayIfNeeded];
  207692. }
  207693. ComponentPeer* Component::createNewPeer (int styleFlags, void* windowToAttachTo)
  207694. {
  207695. return new NSViewComponentPeer (this, styleFlags, (NSView*) windowToAttachTo);
  207696. }
  207697. Image* juce_createIconForFile (const File& file)
  207698. {
  207699. const ScopedAutoReleasePool pool;
  207700. NSImage* image = [[NSWorkspace sharedWorkspace] iconForFile: juceStringToNS (file.getFullPathName())];
  207701. CoreGraphicsImage* result = new CoreGraphicsImage (Image::ARGB, (int) [image size].width, (int) [image size].height, true);
  207702. [NSGraphicsContext saveGraphicsState];
  207703. [NSGraphicsContext setCurrentContext: [NSGraphicsContext graphicsContextWithGraphicsPort: result->context flipped: false]];
  207704. [image drawAtPoint: NSMakePoint (0, 0)
  207705. fromRect: NSMakeRect (0, 0, [image size].width, [image size].height)
  207706. operation: NSCompositeSourceOver fraction: 1.0f];
  207707. [[NSGraphicsContext currentContext] flushGraphics];
  207708. [NSGraphicsContext restoreGraphicsState];
  207709. return result;
  207710. }
  207711. const int KeyPress::spaceKey = ' ';
  207712. const int KeyPress::returnKey = 0x0d;
  207713. const int KeyPress::escapeKey = 0x1b;
  207714. const int KeyPress::backspaceKey = 0x7f;
  207715. const int KeyPress::leftKey = NSLeftArrowFunctionKey;
  207716. const int KeyPress::rightKey = NSRightArrowFunctionKey;
  207717. const int KeyPress::upKey = NSUpArrowFunctionKey;
  207718. const int KeyPress::downKey = NSDownArrowFunctionKey;
  207719. const int KeyPress::pageUpKey = NSPageUpFunctionKey;
  207720. const int KeyPress::pageDownKey = NSPageDownFunctionKey;
  207721. const int KeyPress::endKey = NSEndFunctionKey;
  207722. const int KeyPress::homeKey = NSHomeFunctionKey;
  207723. const int KeyPress::deleteKey = NSDeleteFunctionKey;
  207724. const int KeyPress::insertKey = -1;
  207725. const int KeyPress::tabKey = 9;
  207726. const int KeyPress::F1Key = NSF1FunctionKey;
  207727. const int KeyPress::F2Key = NSF2FunctionKey;
  207728. const int KeyPress::F3Key = NSF3FunctionKey;
  207729. const int KeyPress::F4Key = NSF4FunctionKey;
  207730. const int KeyPress::F5Key = NSF5FunctionKey;
  207731. const int KeyPress::F6Key = NSF6FunctionKey;
  207732. const int KeyPress::F7Key = NSF7FunctionKey;
  207733. const int KeyPress::F8Key = NSF8FunctionKey;
  207734. const int KeyPress::F9Key = NSF9FunctionKey;
  207735. const int KeyPress::F10Key = NSF10FunctionKey;
  207736. const int KeyPress::F11Key = NSF1FunctionKey;
  207737. const int KeyPress::F12Key = NSF12FunctionKey;
  207738. const int KeyPress::F13Key = NSF13FunctionKey;
  207739. const int KeyPress::F14Key = NSF14FunctionKey;
  207740. const int KeyPress::F15Key = NSF15FunctionKey;
  207741. const int KeyPress::F16Key = NSF16FunctionKey;
  207742. const int KeyPress::numberPad0 = 0x30020;
  207743. const int KeyPress::numberPad1 = 0x30021;
  207744. const int KeyPress::numberPad2 = 0x30022;
  207745. const int KeyPress::numberPad3 = 0x30023;
  207746. const int KeyPress::numberPad4 = 0x30024;
  207747. const int KeyPress::numberPad5 = 0x30025;
  207748. const int KeyPress::numberPad6 = 0x30026;
  207749. const int KeyPress::numberPad7 = 0x30027;
  207750. const int KeyPress::numberPad8 = 0x30028;
  207751. const int KeyPress::numberPad9 = 0x30029;
  207752. const int KeyPress::numberPadAdd = 0x3002a;
  207753. const int KeyPress::numberPadSubtract = 0x3002b;
  207754. const int KeyPress::numberPadMultiply = 0x3002c;
  207755. const int KeyPress::numberPadDivide = 0x3002d;
  207756. const int KeyPress::numberPadSeparator = 0x3002e;
  207757. const int KeyPress::numberPadDecimalPoint = 0x3002f;
  207758. const int KeyPress::numberPadEquals = 0x30030;
  207759. const int KeyPress::numberPadDelete = 0x30031;
  207760. const int KeyPress::playKey = 0x30000;
  207761. const int KeyPress::stopKey = 0x30001;
  207762. const int KeyPress::fastForwardKey = 0x30002;
  207763. const int KeyPress::rewindKey = 0x30003;
  207764. #endif
  207765. /*** End of inlined file: juce_mac_NSViewComponentPeer.mm ***/
  207766. /*** Start of inlined file: juce_mac_MouseCursor.mm ***/
  207767. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  207768. // compiled on its own).
  207769. #if JUCE_INCLUDED_FILE
  207770. #if JUCE_MAC
  207771. Image* juce_loadPNGImageFromStream (InputStream& inputStream);
  207772. void* juce_createMouseCursorFromImage (const Image& image, int hotspotX, int hotspotY) throw()
  207773. {
  207774. NSImage* im = CoreGraphicsImage::createNSImage (image);
  207775. NSCursor* c = [[NSCursor alloc] initWithImage: im
  207776. hotSpot: NSMakePoint (hotspotX, hotspotY)];
  207777. [im release];
  207778. return (void*) c;
  207779. }
  207780. static void* juce_cursorFromData (const unsigned char* data, const size_t size, float hx, float hy) throw()
  207781. {
  207782. MemoryInputStream stream (data, size, false);
  207783. ScopedPointer <Image> im (juce_loadPNGImageFromStream (stream));
  207784. jassert (im != 0);
  207785. if (im == 0)
  207786. return 0;
  207787. return juce_createMouseCursorFromImage (*im,
  207788. (int) (hx * im->getWidth()),
  207789. (int) (hy * im->getHeight()));
  207790. }
  207791. static void* juce_cursorFromWebKitFile (const char* filename, float hx, float hy)
  207792. {
  207793. File f ("/System/Library/Frameworks/WebKit.framework/Frameworks/WebCore.framework/Resources");
  207794. MemoryBlock mb;
  207795. if (f.getChildFile (filename).loadFileAsData (mb))
  207796. return juce_cursorFromData ((const unsigned char*) mb.getData(), mb.getSize(), hx, hy);
  207797. return 0;
  207798. }
  207799. void* juce_createStandardMouseCursor (MouseCursor::StandardCursorType type) throw()
  207800. {
  207801. const ScopedAutoReleasePool pool;
  207802. NSCursor* c = 0;
  207803. switch (type)
  207804. {
  207805. case MouseCursor::NormalCursor:
  207806. c = [NSCursor arrowCursor];
  207807. break;
  207808. case MouseCursor::NoCursor:
  207809. return juce_createMouseCursorFromImage (Image (Image::ARGB, 8, 8, true), 0, 0);
  207810. case MouseCursor::DraggingHandCursor:
  207811. c = [NSCursor openHandCursor];
  207812. break;
  207813. case MouseCursor::CopyingCursor:
  207814. return juce_cursorFromWebKitFile ("copyCursor.png", 0, 0);
  207815. case MouseCursor::WaitCursor:
  207816. c = [NSCursor arrowCursor]; // avoid this on the mac, let the OS provide the beachball
  207817. break;
  207818. //return juce_cursorFromWebKitFile ("waitCursor.png", 0.5f, 0.5f);
  207819. case MouseCursor::IBeamCursor:
  207820. c = [NSCursor IBeamCursor];
  207821. break;
  207822. case MouseCursor::PointingHandCursor:
  207823. c = [NSCursor pointingHandCursor];
  207824. break;
  207825. case MouseCursor::LeftRightResizeCursor:
  207826. c = [NSCursor resizeLeftRightCursor];
  207827. break;
  207828. case MouseCursor::LeftEdgeResizeCursor:
  207829. c = [NSCursor resizeLeftCursor];
  207830. break;
  207831. case MouseCursor::RightEdgeResizeCursor:
  207832. c = [NSCursor resizeRightCursor];
  207833. break;
  207834. case MouseCursor::UpDownResizeCursor:
  207835. case MouseCursor::TopEdgeResizeCursor:
  207836. case MouseCursor::BottomEdgeResizeCursor:
  207837. return juce_cursorFromWebKitFile ("northSouthResizeCursor.png", 0.5f, 0.5f);
  207838. case MouseCursor::TopLeftCornerResizeCursor:
  207839. case MouseCursor::BottomRightCornerResizeCursor:
  207840. return juce_cursorFromWebKitFile ("northWestSouthEastResizeCursor.png", 0.5f, 0.5f);
  207841. case MouseCursor::TopRightCornerResizeCursor:
  207842. case MouseCursor::BottomLeftCornerResizeCursor:
  207843. return juce_cursorFromWebKitFile ("northEastSouthWestResizeCursor.png", 0.5f, 0.5f);
  207844. case MouseCursor::UpDownLeftRightResizeCursor:
  207845. return juce_cursorFromWebKitFile ("moveCursor.png", 0.5f, 0.5f);
  207846. case MouseCursor::CrosshairCursor:
  207847. c = [NSCursor crosshairCursor];
  207848. break;
  207849. }
  207850. [c retain];
  207851. return (void*) c;
  207852. }
  207853. void juce_deleteMouseCursor (void* const cursorHandle, const bool isStandard) throw()
  207854. {
  207855. NSCursor* c = (NSCursor*) cursorHandle;
  207856. [c release];
  207857. }
  207858. void MouseCursor::showInAllWindows() const throw()
  207859. {
  207860. showInWindow (0);
  207861. }
  207862. void MouseCursor::showInWindow (ComponentPeer*) const throw()
  207863. {
  207864. NSCursor* const c = (NSCursor*) getHandle();
  207865. [c set];
  207866. }
  207867. #else
  207868. void* juce_createMouseCursorFromImage (const Image& image, int hotspotX, int hotspotY) throw() { return 0; }
  207869. void* juce_createStandardMouseCursor (MouseCursor::StandardCursorType type) throw() { return 0; }
  207870. void juce_deleteMouseCursor (void* const cursorHandle, const bool isStandard) throw() {}
  207871. void MouseCursor::showInAllWindows() const throw() {}
  207872. void MouseCursor::showInWindow (ComponentPeer*) const throw() {}
  207873. #endif
  207874. #endif
  207875. /*** End of inlined file: juce_mac_MouseCursor.mm ***/
  207876. /*** Start of inlined file: juce_mac_NSViewComponent.mm ***/
  207877. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  207878. // compiled on its own).
  207879. #if JUCE_INCLUDED_FILE
  207880. class NSViewComponentInternal : public ComponentMovementWatcher
  207881. {
  207882. Component* const owner;
  207883. NSViewComponentPeer* currentPeer;
  207884. bool wasShowing;
  207885. public:
  207886. NSView* const view;
  207887. NSViewComponentInternal (NSView* const view_, Component* const owner_)
  207888. : ComponentMovementWatcher (owner_),
  207889. owner (owner_),
  207890. currentPeer (0),
  207891. wasShowing (false),
  207892. view (view_)
  207893. {
  207894. [view_ retain];
  207895. if (owner_->isShowing())
  207896. componentPeerChanged();
  207897. }
  207898. ~NSViewComponentInternal()
  207899. {
  207900. [view removeFromSuperview];
  207901. [view release];
  207902. }
  207903. void componentMovedOrResized (Component& comp, bool wasMoved, bool wasResized)
  207904. {
  207905. ComponentMovementWatcher::componentMovedOrResized (comp, wasMoved, wasResized);
  207906. // The ComponentMovementWatcher version of this method avoids calling
  207907. // us when the top-level comp is resized, but for an NSView we need to know this
  207908. // because with inverted co-ords, we need to update the position even if the
  207909. // top-left pos hasn't changed
  207910. if (comp.isOnDesktop() && wasResized)
  207911. componentMovedOrResized (wasMoved, wasResized);
  207912. }
  207913. void componentMovedOrResized (bool /*wasMoved*/, bool /*wasResized*/)
  207914. {
  207915. Component* const topComp = owner->getTopLevelComponent();
  207916. if (topComp->getPeer() != 0)
  207917. {
  207918. const Point<int> pos (owner->relativePositionToOtherComponent (topComp, Point<int>()));
  207919. NSRect r;
  207920. r.origin.x = (float) pos.getX();
  207921. r.origin.y = (float) pos.getY();
  207922. r.size.width = (float) owner->getWidth();
  207923. r.size.height = (float) owner->getHeight();
  207924. r.origin.y = [[view superview] frame].size.height - (r.origin.y + r.size.height);
  207925. [view setFrame: r];
  207926. }
  207927. }
  207928. void componentPeerChanged()
  207929. {
  207930. NSViewComponentPeer* const peer = dynamic_cast <NSViewComponentPeer*> (owner->getPeer());
  207931. if (currentPeer != peer)
  207932. {
  207933. [view removeFromSuperview];
  207934. currentPeer = peer;
  207935. if (peer != 0)
  207936. {
  207937. [peer->view addSubview: view];
  207938. componentMovedOrResized (false, false);
  207939. }
  207940. }
  207941. [view setHidden: ! owner->isShowing()];
  207942. }
  207943. void componentVisibilityChanged (Component&)
  207944. {
  207945. componentPeerChanged();
  207946. }
  207947. juce_UseDebuggingNewOperator
  207948. private:
  207949. NSViewComponentInternal (const NSViewComponentInternal&);
  207950. NSViewComponentInternal& operator= (const NSViewComponentInternal&);
  207951. };
  207952. NSViewComponent::NSViewComponent()
  207953. {
  207954. }
  207955. NSViewComponent::~NSViewComponent()
  207956. {
  207957. }
  207958. void NSViewComponent::setView (void* view)
  207959. {
  207960. if (view != getView())
  207961. {
  207962. if (view != 0)
  207963. info = new NSViewComponentInternal ((NSView*) view, this);
  207964. else
  207965. info = 0;
  207966. }
  207967. }
  207968. void* NSViewComponent::getView() const
  207969. {
  207970. return info == 0 ? 0 : info->view;
  207971. }
  207972. void NSViewComponent::paint (Graphics& g)
  207973. {
  207974. }
  207975. #endif
  207976. /*** End of inlined file: juce_mac_NSViewComponent.mm ***/
  207977. /*** Start of inlined file: juce_mac_AppleRemote.mm ***/
  207978. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  207979. // compiled on its own).
  207980. #if JUCE_INCLUDED_FILE
  207981. AppleRemoteDevice::AppleRemoteDevice()
  207982. : device (0),
  207983. queue (0),
  207984. remoteId (0)
  207985. {
  207986. }
  207987. AppleRemoteDevice::~AppleRemoteDevice()
  207988. {
  207989. stop();
  207990. }
  207991. static io_object_t getAppleRemoteDevice()
  207992. {
  207993. CFMutableDictionaryRef dict = IOServiceMatching ("AppleIRController");
  207994. io_iterator_t iter = 0;
  207995. io_object_t iod = 0;
  207996. if (IOServiceGetMatchingServices (kIOMasterPortDefault, dict, &iter) == kIOReturnSuccess
  207997. && iter != 0)
  207998. {
  207999. iod = IOIteratorNext (iter);
  208000. }
  208001. IOObjectRelease (iter);
  208002. return iod;
  208003. }
  208004. static bool createAppleRemoteInterface (io_object_t iod, void** device)
  208005. {
  208006. jassert (*device == 0);
  208007. io_name_t classname;
  208008. if (IOObjectGetClass (iod, classname) == kIOReturnSuccess)
  208009. {
  208010. IOCFPlugInInterface** cfPlugInInterface = 0;
  208011. SInt32 score = 0;
  208012. if (IOCreatePlugInInterfaceForService (iod,
  208013. kIOHIDDeviceUserClientTypeID,
  208014. kIOCFPlugInInterfaceID,
  208015. &cfPlugInInterface,
  208016. &score) == kIOReturnSuccess)
  208017. {
  208018. HRESULT hr = (*cfPlugInInterface)->QueryInterface (cfPlugInInterface,
  208019. CFUUIDGetUUIDBytes (kIOHIDDeviceInterfaceID),
  208020. device);
  208021. (void) hr;
  208022. (*cfPlugInInterface)->Release (cfPlugInInterface);
  208023. }
  208024. }
  208025. return *device != 0;
  208026. }
  208027. bool AppleRemoteDevice::start (const bool inExclusiveMode)
  208028. {
  208029. if (queue != 0)
  208030. return true;
  208031. stop();
  208032. bool result = false;
  208033. io_object_t iod = getAppleRemoteDevice();
  208034. if (iod != 0)
  208035. {
  208036. if (createAppleRemoteInterface (iod, &device) && open (inExclusiveMode))
  208037. result = true;
  208038. else
  208039. stop();
  208040. IOObjectRelease (iod);
  208041. }
  208042. return result;
  208043. }
  208044. void AppleRemoteDevice::stop()
  208045. {
  208046. if (queue != 0)
  208047. {
  208048. (*(IOHIDQueueInterface**) queue)->stop ((IOHIDQueueInterface**) queue);
  208049. (*(IOHIDQueueInterface**) queue)->dispose ((IOHIDQueueInterface**) queue);
  208050. (*(IOHIDQueueInterface**) queue)->Release ((IOHIDQueueInterface**) queue);
  208051. queue = 0;
  208052. }
  208053. if (device != 0)
  208054. {
  208055. (*(IOHIDDeviceInterface**) device)->close ((IOHIDDeviceInterface**) device);
  208056. (*(IOHIDDeviceInterface**) device)->Release ((IOHIDDeviceInterface**) device);
  208057. device = 0;
  208058. }
  208059. }
  208060. bool AppleRemoteDevice::isActive() const
  208061. {
  208062. return queue != 0;
  208063. }
  208064. static void appleRemoteQueueCallback (void* const target, const IOReturn result, void*, void*)
  208065. {
  208066. if (result == kIOReturnSuccess)
  208067. ((AppleRemoteDevice*) target)->handleCallbackInternal();
  208068. }
  208069. bool AppleRemoteDevice::open (const bool openInExclusiveMode)
  208070. {
  208071. Array <int> cookies;
  208072. CFArrayRef elements;
  208073. IOHIDDeviceInterface122** const device122 = (IOHIDDeviceInterface122**) device;
  208074. if ((*device122)->copyMatchingElements (device122, 0, &elements) != kIOReturnSuccess)
  208075. return false;
  208076. for (int i = 0; i < CFArrayGetCount (elements); ++i)
  208077. {
  208078. CFDictionaryRef element = (CFDictionaryRef) CFArrayGetValueAtIndex (elements, i);
  208079. // get the cookie
  208080. CFTypeRef object = CFDictionaryGetValue (element, CFSTR (kIOHIDElementCookieKey));
  208081. if (object == 0 || CFGetTypeID (object) != CFNumberGetTypeID())
  208082. continue;
  208083. long number;
  208084. if (! CFNumberGetValue ((CFNumberRef) object, kCFNumberLongType, &number))
  208085. continue;
  208086. cookies.add ((int) number);
  208087. }
  208088. CFRelease (elements);
  208089. if ((*(IOHIDDeviceInterface**) device)
  208090. ->open ((IOHIDDeviceInterface**) device,
  208091. openInExclusiveMode ? kIOHIDOptionsTypeSeizeDevice
  208092. : kIOHIDOptionsTypeNone) == KERN_SUCCESS)
  208093. {
  208094. queue = (*(IOHIDDeviceInterface**) device)->allocQueue ((IOHIDDeviceInterface**) device);
  208095. if (queue != 0)
  208096. {
  208097. (*(IOHIDQueueInterface**) queue)->create ((IOHIDQueueInterface**) queue, 0, 12);
  208098. for (int i = 0; i < cookies.size(); ++i)
  208099. {
  208100. IOHIDElementCookie cookie = (IOHIDElementCookie) cookies.getUnchecked(i);
  208101. (*(IOHIDQueueInterface**) queue)->addElement ((IOHIDQueueInterface**) queue, cookie, 0);
  208102. }
  208103. CFRunLoopSourceRef eventSource;
  208104. if ((*(IOHIDQueueInterface**) queue)
  208105. ->createAsyncEventSource ((IOHIDQueueInterface**) queue, &eventSource) == KERN_SUCCESS)
  208106. {
  208107. if ((*(IOHIDQueueInterface**) queue)->setEventCallout ((IOHIDQueueInterface**) queue,
  208108. appleRemoteQueueCallback, this, 0) == KERN_SUCCESS)
  208109. {
  208110. CFRunLoopAddSource (CFRunLoopGetCurrent(), eventSource, kCFRunLoopDefaultMode);
  208111. (*(IOHIDQueueInterface**) queue)->start ((IOHIDQueueInterface**) queue);
  208112. return true;
  208113. }
  208114. }
  208115. }
  208116. }
  208117. return false;
  208118. }
  208119. void AppleRemoteDevice::handleCallbackInternal()
  208120. {
  208121. int totalValues = 0;
  208122. AbsoluteTime nullTime = { 0, 0 };
  208123. char cookies [12];
  208124. int numCookies = 0;
  208125. while (numCookies < numElementsInArray (cookies))
  208126. {
  208127. IOHIDEventStruct e;
  208128. if ((*(IOHIDQueueInterface**) queue)->getNextEvent ((IOHIDQueueInterface**) queue, &e, nullTime, 0) != kIOReturnSuccess)
  208129. break;
  208130. if ((int) e.elementCookie == 19)
  208131. {
  208132. remoteId = e.value;
  208133. buttonPressed (switched, false);
  208134. }
  208135. else
  208136. {
  208137. totalValues += e.value;
  208138. cookies [numCookies++] = (char) (pointer_sized_int) e.elementCookie;
  208139. }
  208140. }
  208141. cookies [numCookies++] = 0;
  208142. //DBG (String::toHexString ((uint8*) cookies, numCookies, 1) + " " + String (totalValues));
  208143. static const char buttonPatterns[] =
  208144. {
  208145. 0x1f, 0x14, 0x12, 0x1f, 0x14, 0x12, 0,
  208146. 0x1f, 0x15, 0x12, 0x1f, 0x15, 0x12, 0,
  208147. 0x1f, 0x1d, 0x1c, 0x12, 0,
  208148. 0x1f, 0x1e, 0x1c, 0x12, 0,
  208149. 0x1f, 0x16, 0x12, 0x1f, 0x16, 0x12, 0,
  208150. 0x1f, 0x17, 0x12, 0x1f, 0x17, 0x12, 0,
  208151. 0x1f, 0x12, 0x04, 0x02, 0,
  208152. 0x1f, 0x12, 0x03, 0x02, 0,
  208153. 0x1f, 0x12, 0x1f, 0x12, 0,
  208154. 0x23, 0x1f, 0x12, 0x23, 0x1f, 0x12, 0,
  208155. 19, 0
  208156. };
  208157. int buttonNum = (int) menuButton;
  208158. int i = 0;
  208159. while (i < numElementsInArray (buttonPatterns))
  208160. {
  208161. if (strcmp (cookies, buttonPatterns + i) == 0)
  208162. {
  208163. buttonPressed ((ButtonType) buttonNum, totalValues > 0);
  208164. break;
  208165. }
  208166. i += (int) strlen (buttonPatterns + i) + 1;
  208167. ++buttonNum;
  208168. }
  208169. }
  208170. #endif
  208171. /*** End of inlined file: juce_mac_AppleRemote.mm ***/
  208172. /*** Start of inlined file: juce_mac_OpenGLComponent.mm ***/
  208173. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  208174. // compiled on its own).
  208175. #if JUCE_INCLUDED_FILE && JUCE_OPENGL
  208176. #if JUCE_MAC
  208177. END_JUCE_NAMESPACE
  208178. #define ThreadSafeNSOpenGLView MakeObjCClassName(ThreadSafeNSOpenGLView)
  208179. @interface ThreadSafeNSOpenGLView : NSOpenGLView
  208180. {
  208181. CriticalSection* contextLock;
  208182. bool needsUpdate;
  208183. }
  208184. - (id) initWithFrame: (NSRect) frameRect pixelFormat: (NSOpenGLPixelFormat*) format;
  208185. - (bool) makeActive;
  208186. - (void) makeInactive;
  208187. - (void) reshape;
  208188. @end
  208189. @implementation ThreadSafeNSOpenGLView
  208190. - (id) initWithFrame: (NSRect) frameRect
  208191. pixelFormat: (NSOpenGLPixelFormat*) format
  208192. {
  208193. contextLock = new CriticalSection();
  208194. self = [super initWithFrame: frameRect pixelFormat: format];
  208195. if (self != nil)
  208196. [[NSNotificationCenter defaultCenter] addObserver: self
  208197. selector: @selector (_surfaceNeedsUpdate:)
  208198. name: NSViewGlobalFrameDidChangeNotification
  208199. object: self];
  208200. return self;
  208201. }
  208202. - (void) dealloc
  208203. {
  208204. [[NSNotificationCenter defaultCenter] removeObserver: self];
  208205. delete contextLock;
  208206. [super dealloc];
  208207. }
  208208. - (bool) makeActive
  208209. {
  208210. const ScopedLock sl (*contextLock);
  208211. if ([self openGLContext] == 0)
  208212. return false;
  208213. [[self openGLContext] makeCurrentContext];
  208214. if (needsUpdate)
  208215. {
  208216. [super update];
  208217. needsUpdate = false;
  208218. }
  208219. return true;
  208220. }
  208221. - (void) makeInactive
  208222. {
  208223. const ScopedLock sl (*contextLock);
  208224. [NSOpenGLContext clearCurrentContext];
  208225. }
  208226. - (void) _surfaceNeedsUpdate: (NSNotification*) notification
  208227. {
  208228. const ScopedLock sl (*contextLock);
  208229. needsUpdate = true;
  208230. }
  208231. - (void) update
  208232. {
  208233. const ScopedLock sl (*contextLock);
  208234. needsUpdate = true;
  208235. }
  208236. - (void) reshape
  208237. {
  208238. const ScopedLock sl (*contextLock);
  208239. needsUpdate = true;
  208240. }
  208241. @end
  208242. BEGIN_JUCE_NAMESPACE
  208243. class WindowedGLContext : public OpenGLContext
  208244. {
  208245. public:
  208246. WindowedGLContext (Component* const component,
  208247. const OpenGLPixelFormat& pixelFormat_,
  208248. NSOpenGLContext* sharedContext)
  208249. : renderContext (0),
  208250. pixelFormat (pixelFormat_)
  208251. {
  208252. jassert (component != 0);
  208253. NSOpenGLPixelFormatAttribute attribs [64];
  208254. int n = 0;
  208255. attribs[n++] = NSOpenGLPFADoubleBuffer;
  208256. attribs[n++] = NSOpenGLPFAAccelerated;
  208257. attribs[n++] = NSOpenGLPFAMPSafe; // NSOpenGLPFAAccelerated, NSOpenGLPFAMultiScreen, NSOpenGLPFASingleRenderer
  208258. attribs[n++] = NSOpenGLPFAColorSize;
  208259. attribs[n++] = (NSOpenGLPixelFormatAttribute) jmax (pixelFormat.redBits,
  208260. pixelFormat.greenBits,
  208261. pixelFormat.blueBits);
  208262. attribs[n++] = NSOpenGLPFAAlphaSize;
  208263. attribs[n++] = (NSOpenGLPixelFormatAttribute) pixelFormat.alphaBits;
  208264. attribs[n++] = NSOpenGLPFADepthSize;
  208265. attribs[n++] = (NSOpenGLPixelFormatAttribute) pixelFormat.depthBufferBits;
  208266. attribs[n++] = NSOpenGLPFAStencilSize;
  208267. attribs[n++] = (NSOpenGLPixelFormatAttribute) pixelFormat.stencilBufferBits;
  208268. attribs[n++] = NSOpenGLPFAAccumSize;
  208269. attribs[n++] = (NSOpenGLPixelFormatAttribute) jmax (pixelFormat.accumulationBufferRedBits,
  208270. pixelFormat.accumulationBufferGreenBits,
  208271. pixelFormat.accumulationBufferBlueBits,
  208272. pixelFormat.accumulationBufferAlphaBits);
  208273. // xxx not sure how to do fullSceneAntiAliasingNumSamples..
  208274. attribs[n++] = NSOpenGLPFASampleBuffers;
  208275. attribs[n++] = (NSOpenGLPixelFormatAttribute) 1;
  208276. attribs[n++] = NSOpenGLPFAClosestPolicy;
  208277. attribs[n++] = NSOpenGLPFANoRecovery;
  208278. attribs[n++] = (NSOpenGLPixelFormatAttribute) 0;
  208279. NSOpenGLPixelFormat* format
  208280. = [[NSOpenGLPixelFormat alloc] initWithAttributes: attribs];
  208281. view = [[ThreadSafeNSOpenGLView alloc] initWithFrame: NSMakeRect (0, 0, 100.0f, 100.0f)
  208282. pixelFormat: format];
  208283. renderContext = [[[NSOpenGLContext alloc] initWithFormat: format
  208284. shareContext: sharedContext] autorelease];
  208285. const GLint swapInterval = 1;
  208286. [renderContext setValues: &swapInterval forParameter: NSOpenGLCPSwapInterval];
  208287. [view setOpenGLContext: renderContext];
  208288. [renderContext setView: view];
  208289. [format release];
  208290. viewHolder = new NSViewComponentInternal (view, component);
  208291. }
  208292. ~WindowedGLContext()
  208293. {
  208294. makeInactive();
  208295. [renderContext clearDrawable];
  208296. viewHolder = 0;
  208297. }
  208298. bool makeActive() const throw()
  208299. {
  208300. jassert (renderContext != 0);
  208301. [view makeActive];
  208302. return isActive();
  208303. }
  208304. bool makeInactive() const throw()
  208305. {
  208306. [view makeInactive];
  208307. return true;
  208308. }
  208309. bool isActive() const throw()
  208310. {
  208311. return [NSOpenGLContext currentContext] == renderContext;
  208312. }
  208313. const OpenGLPixelFormat getPixelFormat() const { return pixelFormat; }
  208314. void* getRawContext() const throw() { return renderContext; }
  208315. void updateWindowPosition (int x, int y, int w, int h, int outerWindowHeight)
  208316. {
  208317. }
  208318. void swapBuffers()
  208319. {
  208320. [renderContext flushBuffer];
  208321. }
  208322. bool setSwapInterval (const int numFramesPerSwap)
  208323. {
  208324. [renderContext setValues: (const GLint*) &numFramesPerSwap
  208325. forParameter: NSOpenGLCPSwapInterval];
  208326. return true;
  208327. }
  208328. int getSwapInterval() const
  208329. {
  208330. GLint numFrames = 0;
  208331. [renderContext getValues: &numFrames
  208332. forParameter: NSOpenGLCPSwapInterval];
  208333. return numFrames;
  208334. }
  208335. void repaint()
  208336. {
  208337. // we need to invalidate the juce view that holds this gl view, to make it
  208338. // cause a repaint callback
  208339. NSView* v = (NSView*) viewHolder->view;
  208340. NSRect r = [v frame];
  208341. // bit of a bodge here.. if we only invalidate the area of the gl component,
  208342. // it's completely covered by the NSOpenGLView, so the OS throws away the
  208343. // repaint message, thus never causing our paint() callback, and never repainting
  208344. // the comp. So invalidating just a little bit around the edge helps..
  208345. [[v superview] setNeedsDisplayInRect: NSInsetRect (r, -2.0f, -2.0f)];
  208346. }
  208347. void* getNativeWindowHandle() const { return viewHolder->view; }
  208348. juce_UseDebuggingNewOperator
  208349. NSOpenGLContext* renderContext;
  208350. ThreadSafeNSOpenGLView* view;
  208351. private:
  208352. OpenGLPixelFormat pixelFormat;
  208353. ScopedPointer <NSViewComponentInternal> viewHolder;
  208354. WindowedGLContext (const WindowedGLContext&);
  208355. WindowedGLContext& operator= (const WindowedGLContext&);
  208356. };
  208357. OpenGLContext* OpenGLComponent::createContext()
  208358. {
  208359. ScopedPointer<WindowedGLContext> c (new WindowedGLContext (this, preferredPixelFormat,
  208360. contextToShareListsWith != 0 ? (NSOpenGLContext*) contextToShareListsWith->getRawContext() : 0));
  208361. return (c->renderContext != 0) ? c.release() : 0;
  208362. }
  208363. void* OpenGLComponent::getNativeWindowHandle() const
  208364. {
  208365. return context != 0 ? ((WindowedGLContext*) context)->getNativeWindowHandle()
  208366. : 0;
  208367. }
  208368. void juce_glViewport (const int w, const int h)
  208369. {
  208370. glViewport (0, 0, w, h);
  208371. }
  208372. void OpenGLPixelFormat::getAvailablePixelFormats (Component* /*component*/,
  208373. OwnedArray <OpenGLPixelFormat>& results)
  208374. {
  208375. /* GLint attribs [64];
  208376. int n = 0;
  208377. attribs[n++] = AGL_RGBA;
  208378. attribs[n++] = AGL_DOUBLEBUFFER;
  208379. attribs[n++] = AGL_ACCELERATED;
  208380. attribs[n++] = AGL_NO_RECOVERY;
  208381. attribs[n++] = AGL_NONE;
  208382. AGLPixelFormat p = aglChoosePixelFormat (0, 0, attribs);
  208383. while (p != 0)
  208384. {
  208385. OpenGLPixelFormat* const pf = new OpenGLPixelFormat();
  208386. pf->redBits = getAGLAttribute (p, AGL_RED_SIZE);
  208387. pf->greenBits = getAGLAttribute (p, AGL_GREEN_SIZE);
  208388. pf->blueBits = getAGLAttribute (p, AGL_BLUE_SIZE);
  208389. pf->alphaBits = getAGLAttribute (p, AGL_ALPHA_SIZE);
  208390. pf->depthBufferBits = getAGLAttribute (p, AGL_DEPTH_SIZE);
  208391. pf->stencilBufferBits = getAGLAttribute (p, AGL_STENCIL_SIZE);
  208392. pf->accumulationBufferRedBits = getAGLAttribute (p, AGL_ACCUM_RED_SIZE);
  208393. pf->accumulationBufferGreenBits = getAGLAttribute (p, AGL_ACCUM_GREEN_SIZE);
  208394. pf->accumulationBufferBlueBits = getAGLAttribute (p, AGL_ACCUM_BLUE_SIZE);
  208395. pf->accumulationBufferAlphaBits = getAGLAttribute (p, AGL_ACCUM_ALPHA_SIZE);
  208396. results.add (pf);
  208397. p = aglNextPixelFormat (p);
  208398. }*/
  208399. //jassertfalse //xxx can't see how you do this in cocoa!
  208400. }
  208401. #else
  208402. END_JUCE_NAMESPACE
  208403. @interface JuceGLView : UIView
  208404. {
  208405. }
  208406. + (Class) layerClass;
  208407. @end
  208408. @implementation JuceGLView
  208409. + (Class) layerClass
  208410. {
  208411. return [CAEAGLLayer class];
  208412. }
  208413. @end
  208414. BEGIN_JUCE_NAMESPACE
  208415. class GLESContext : public OpenGLContext
  208416. {
  208417. public:
  208418. GLESContext (UIViewComponentPeer* peer,
  208419. Component* const component_,
  208420. const OpenGLPixelFormat& pixelFormat_,
  208421. const GLESContext* const sharedContext,
  208422. NSUInteger apiType)
  208423. : component (component_), pixelFormat (pixelFormat_), glLayer (0), context (0),
  208424. useDepthBuffer (pixelFormat_.depthBufferBits > 0), frameBufferHandle (0), colorBufferHandle (0),
  208425. depthBufferHandle (0), lastWidth (0), lastHeight (0)
  208426. {
  208427. view = [[JuceGLView alloc] initWithFrame: CGRectMake (0, 0, 64, 64)];
  208428. view.opaque = YES;
  208429. view.hidden = NO;
  208430. view.backgroundColor = [UIColor redColor];
  208431. glLayer = (CAEAGLLayer*) [view layer];
  208432. [peer->view addSubview: view];
  208433. if (sharedContext != 0)
  208434. context = [[EAGLContext alloc] initWithAPI: apiType
  208435. sharegroup: [sharedContext->context sharegroup]];
  208436. else
  208437. context = [[EAGLContext alloc] initWithAPI: apiType];
  208438. createGLBuffers();
  208439. }
  208440. ~GLESContext()
  208441. {
  208442. makeInactive();
  208443. [context release];
  208444. [view removeFromSuperview];
  208445. [view release];
  208446. freeGLBuffers();
  208447. }
  208448. bool makeActive() const throw()
  208449. {
  208450. jassert (context != 0);
  208451. [EAGLContext setCurrentContext: context];
  208452. glBindFramebufferOES (GL_FRAMEBUFFER_OES, frameBufferHandle);
  208453. return true;
  208454. }
  208455. void swapBuffers()
  208456. {
  208457. glBindRenderbufferOES (GL_RENDERBUFFER_OES, colorBufferHandle);
  208458. [context presentRenderbuffer: GL_RENDERBUFFER_OES];
  208459. }
  208460. bool makeInactive() const throw()
  208461. {
  208462. return [EAGLContext setCurrentContext: nil];
  208463. }
  208464. bool isActive() const throw()
  208465. {
  208466. return [EAGLContext currentContext] == context;
  208467. }
  208468. const OpenGLPixelFormat getPixelFormat() const { return pixelFormat; }
  208469. void* getRawContext() const throw() { return (void*) glLayer; }
  208470. void updateWindowPosition (int x, int y, int w, int h, int outerWindowHeight)
  208471. {
  208472. view.frame = CGRectMake ((CGFloat) x, (CGFloat) y, (CGFloat) w, (CGFloat) h);
  208473. if (lastWidth != w || lastHeight != h)
  208474. {
  208475. lastWidth = w;
  208476. lastHeight = h;
  208477. freeGLBuffers();
  208478. createGLBuffers();
  208479. }
  208480. }
  208481. bool setSwapInterval (const int numFramesPerSwap)
  208482. {
  208483. numFrames = numFramesPerSwap;
  208484. return true;
  208485. }
  208486. int getSwapInterval() const
  208487. {
  208488. return numFrames;
  208489. }
  208490. void repaint()
  208491. {
  208492. }
  208493. void createGLBuffers()
  208494. {
  208495. makeActive();
  208496. glGenFramebuffersOES (1, &frameBufferHandle);
  208497. glGenRenderbuffersOES (1, &colorBufferHandle);
  208498. glGenRenderbuffersOES (1, &depthBufferHandle);
  208499. glBindRenderbufferOES (GL_RENDERBUFFER_OES, colorBufferHandle);
  208500. [context renderbufferStorage: GL_RENDERBUFFER_OES fromDrawable: glLayer];
  208501. GLint width, height;
  208502. glGetRenderbufferParameterivOES (GL_RENDERBUFFER_OES, GL_RENDERBUFFER_WIDTH_OES, &width);
  208503. glGetRenderbufferParameterivOES (GL_RENDERBUFFER_OES, GL_RENDERBUFFER_HEIGHT_OES, &height);
  208504. if (useDepthBuffer)
  208505. {
  208506. glBindRenderbufferOES (GL_RENDERBUFFER_OES, depthBufferHandle);
  208507. glRenderbufferStorageOES (GL_RENDERBUFFER_OES, GL_DEPTH_COMPONENT16_OES, width, height);
  208508. }
  208509. glBindRenderbufferOES (GL_RENDERBUFFER_OES, colorBufferHandle);
  208510. glBindFramebufferOES (GL_FRAMEBUFFER_OES, frameBufferHandle);
  208511. glFramebufferRenderbufferOES (GL_FRAMEBUFFER_OES, GL_COLOR_ATTACHMENT0_OES, GL_RENDERBUFFER_OES, colorBufferHandle);
  208512. if (useDepthBuffer)
  208513. glFramebufferRenderbufferOES (GL_FRAMEBUFFER_OES, GL_DEPTH_ATTACHMENT_OES, GL_RENDERBUFFER_OES, depthBufferHandle);
  208514. jassert (glCheckFramebufferStatusOES (GL_FRAMEBUFFER_OES) == GL_FRAMEBUFFER_COMPLETE_OES);
  208515. }
  208516. void freeGLBuffers()
  208517. {
  208518. if (frameBufferHandle != 0)
  208519. {
  208520. glDeleteFramebuffersOES (1, &frameBufferHandle);
  208521. frameBufferHandle = 0;
  208522. }
  208523. if (colorBufferHandle != 0)
  208524. {
  208525. glDeleteRenderbuffersOES (1, &colorBufferHandle);
  208526. colorBufferHandle = 0;
  208527. }
  208528. if (depthBufferHandle != 0)
  208529. {
  208530. glDeleteRenderbuffersOES (1, &depthBufferHandle);
  208531. depthBufferHandle = 0;
  208532. }
  208533. }
  208534. juce_UseDebuggingNewOperator
  208535. private:
  208536. Component::SafePointer<Component> component;
  208537. OpenGLPixelFormat pixelFormat;
  208538. JuceGLView* view;
  208539. CAEAGLLayer* glLayer;
  208540. EAGLContext* context;
  208541. bool useDepthBuffer;
  208542. GLuint frameBufferHandle, colorBufferHandle, depthBufferHandle;
  208543. int numFrames;
  208544. int lastWidth, lastHeight;
  208545. GLESContext (const GLESContext&);
  208546. GLESContext& operator= (const GLESContext&);
  208547. };
  208548. OpenGLContext* OpenGLComponent::createContext()
  208549. {
  208550. ScopedAutoReleasePool pool;
  208551. UIViewComponentPeer* peer = dynamic_cast <UIViewComponentPeer*> (getPeer());
  208552. if (peer != 0)
  208553. return new GLESContext (peer, this, preferredPixelFormat,
  208554. dynamic_cast <const GLESContext*> (contextToShareListsWith),
  208555. type == openGLES2 ? kEAGLRenderingAPIOpenGLES2 : kEAGLRenderingAPIOpenGLES1);
  208556. return 0;
  208557. }
  208558. void OpenGLPixelFormat::getAvailablePixelFormats (Component* /*component*/,
  208559. OwnedArray <OpenGLPixelFormat>& /*results*/)
  208560. {
  208561. }
  208562. void juce_glViewport (const int w, const int h)
  208563. {
  208564. glViewport (0, 0, w, h);
  208565. }
  208566. #endif
  208567. #endif
  208568. /*** End of inlined file: juce_mac_OpenGLComponent.mm ***/
  208569. /*** Start of inlined file: juce_mac_MainMenu.mm ***/
  208570. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  208571. // compiled on its own).
  208572. #if JUCE_INCLUDED_FILE
  208573. class JuceMainMenuHandler;
  208574. END_JUCE_NAMESPACE
  208575. using namespace JUCE_NAMESPACE;
  208576. #define JuceMenuCallback MakeObjCClassName(JuceMenuCallback)
  208577. #if defined (MAC_OS_X_VERSION_10_6) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
  208578. @interface JuceMenuCallback : NSObject <NSMenuDelegate>
  208579. #else
  208580. @interface JuceMenuCallback : NSObject
  208581. #endif
  208582. {
  208583. JuceMainMenuHandler* owner;
  208584. }
  208585. - (JuceMenuCallback*) initWithOwner: (JuceMainMenuHandler*) owner_;
  208586. - (void) dealloc;
  208587. - (void) menuItemInvoked: (id) menu;
  208588. - (void) menuNeedsUpdate: (NSMenu*) menu;
  208589. @end
  208590. BEGIN_JUCE_NAMESPACE
  208591. class JuceMainMenuHandler : private MenuBarModelListener,
  208592. private DeletedAtShutdown
  208593. {
  208594. public:
  208595. static JuceMainMenuHandler* instance;
  208596. JuceMainMenuHandler()
  208597. : currentModel (0),
  208598. lastUpdateTime (0)
  208599. {
  208600. callback = [[JuceMenuCallback alloc] initWithOwner: this];
  208601. }
  208602. ~JuceMainMenuHandler()
  208603. {
  208604. setMenu (0);
  208605. jassert (instance == this);
  208606. instance = 0;
  208607. [callback release];
  208608. }
  208609. void setMenu (MenuBarModel* const newMenuBarModel)
  208610. {
  208611. if (currentModel != newMenuBarModel)
  208612. {
  208613. if (currentModel != 0)
  208614. currentModel->removeListener (this);
  208615. currentModel = newMenuBarModel;
  208616. if (currentModel != 0)
  208617. currentModel->addListener (this);
  208618. menuBarItemsChanged (0);
  208619. }
  208620. }
  208621. void addSubMenu (NSMenu* parent, const PopupMenu& child,
  208622. const String& name, const int menuId, const int tag)
  208623. {
  208624. NSMenuItem* item = [parent addItemWithTitle: juceStringToNS (name)
  208625. action: nil
  208626. keyEquivalent: @""];
  208627. [item setTag: tag];
  208628. NSMenu* sub = createMenu (child, name, menuId, tag);
  208629. [parent setSubmenu: sub forItem: item];
  208630. [sub setAutoenablesItems: false];
  208631. [sub release];
  208632. }
  208633. void updateSubMenu (NSMenuItem* parentItem, const PopupMenu& menuToCopy,
  208634. const String& name, const int menuId, const int tag)
  208635. {
  208636. [parentItem setTag: tag];
  208637. NSMenu* menu = [parentItem submenu];
  208638. [menu setTitle: juceStringToNS (name)];
  208639. while ([menu numberOfItems] > 0)
  208640. [menu removeItemAtIndex: 0];
  208641. PopupMenu::MenuItemIterator iter (menuToCopy);
  208642. while (iter.next())
  208643. addMenuItem (iter, menu, menuId, tag);
  208644. [menu setAutoenablesItems: false];
  208645. [menu update];
  208646. }
  208647. void menuBarItemsChanged (MenuBarModel*)
  208648. {
  208649. lastUpdateTime = Time::getMillisecondCounter();
  208650. StringArray menuNames;
  208651. if (currentModel != 0)
  208652. menuNames = currentModel->getMenuBarNames();
  208653. NSMenu* menuBar = [NSApp mainMenu];
  208654. while ([menuBar numberOfItems] > 1 + menuNames.size())
  208655. [menuBar removeItemAtIndex: [menuBar numberOfItems] - 1];
  208656. int menuId = 1;
  208657. for (int i = 0; i < menuNames.size(); ++i)
  208658. {
  208659. const PopupMenu menu (currentModel->getMenuForIndex (i, menuNames [i]));
  208660. if (i >= [menuBar numberOfItems] - 1)
  208661. addSubMenu (menuBar, menu, menuNames[i], menuId, i);
  208662. else
  208663. updateSubMenu ([menuBar itemAtIndex: 1 + i], menu, menuNames[i], menuId, i);
  208664. }
  208665. }
  208666. static void flashMenuBar (NSMenu* menu)
  208667. {
  208668. if ([[menu title] isEqualToString: @"Apple"])
  208669. return;
  208670. [menu retain];
  208671. const unichar f35Key = NSF35FunctionKey;
  208672. NSString* f35String = [NSString stringWithCharacters: &f35Key length: 1];
  208673. NSMenuItem* item = [[NSMenuItem alloc] initWithTitle: @"x"
  208674. action: nil
  208675. keyEquivalent: f35String];
  208676. [item setTarget: nil];
  208677. [menu insertItem: item atIndex: [menu numberOfItems]];
  208678. [item release];
  208679. if ([menu indexOfItem: item] >= 0)
  208680. {
  208681. NSEvent* f35Event = [NSEvent keyEventWithType: NSKeyDown
  208682. location: NSZeroPoint
  208683. modifierFlags: NSCommandKeyMask
  208684. timestamp: 0
  208685. windowNumber: 0
  208686. context: [NSGraphicsContext currentContext]
  208687. characters: f35String
  208688. charactersIgnoringModifiers: f35String
  208689. isARepeat: NO
  208690. keyCode: 0];
  208691. [menu performKeyEquivalent: f35Event];
  208692. [menu removeItem: item]; // (this throws if the item isn't actually in the menu)
  208693. }
  208694. [menu release];
  208695. }
  208696. static NSMenuItem* findMenuItem (NSMenu* const menu, const ApplicationCommandTarget::InvocationInfo& info)
  208697. {
  208698. for (NSInteger i = [menu numberOfItems]; --i >= 0;)
  208699. {
  208700. NSMenuItem* m = [menu itemAtIndex: i];
  208701. if ([m tag] == info.commandID)
  208702. return m;
  208703. if ([m submenu] != 0)
  208704. {
  208705. NSMenuItem* found = findMenuItem ([m submenu], info);
  208706. if (found != 0)
  208707. return found;
  208708. }
  208709. }
  208710. return 0;
  208711. }
  208712. void menuCommandInvoked (MenuBarModel*, const ApplicationCommandTarget::InvocationInfo& info)
  208713. {
  208714. NSMenuItem* item = findMenuItem ([NSApp mainMenu], info);
  208715. if (item != 0)
  208716. flashMenuBar ([item menu]);
  208717. }
  208718. void updateMenus()
  208719. {
  208720. if (Time::getMillisecondCounter() > lastUpdateTime + 500)
  208721. menuBarItemsChanged (0);
  208722. }
  208723. void invoke (const int commandId, ApplicationCommandManager* const commandManager, const int topLevelIndex) const
  208724. {
  208725. if (currentModel != 0)
  208726. {
  208727. if (commandManager != 0)
  208728. {
  208729. ApplicationCommandTarget::InvocationInfo info (commandId);
  208730. info.invocationMethod = ApplicationCommandTarget::InvocationInfo::fromMenu;
  208731. commandManager->invoke (info, true);
  208732. }
  208733. currentModel->menuItemSelected (commandId, topLevelIndex);
  208734. }
  208735. }
  208736. MenuBarModel* currentModel;
  208737. uint32 lastUpdateTime;
  208738. void addMenuItem (PopupMenu::MenuItemIterator& iter, NSMenu* menuToAddTo,
  208739. const int topLevelMenuId, const int topLevelIndex)
  208740. {
  208741. NSString* text = juceStringToNS (iter.itemName.upToFirstOccurrenceOf (T("<end>"), false, true));
  208742. if (text == 0)
  208743. text = @"";
  208744. if (iter.isSeparator)
  208745. {
  208746. [menuToAddTo addItem: [NSMenuItem separatorItem]];
  208747. }
  208748. else if (iter.isSectionHeader)
  208749. {
  208750. NSMenuItem* item = [menuToAddTo addItemWithTitle: text
  208751. action: nil
  208752. keyEquivalent: @""];
  208753. [item setEnabled: false];
  208754. }
  208755. else if (iter.subMenu != 0)
  208756. {
  208757. NSMenuItem* item = [menuToAddTo addItemWithTitle: text
  208758. action: nil
  208759. keyEquivalent: @""];
  208760. [item setTag: iter.itemId];
  208761. [item setEnabled: iter.isEnabled];
  208762. NSMenu* sub = createMenu (*iter.subMenu, iter.itemName, topLevelMenuId, topLevelIndex);
  208763. [sub setDelegate: nil];
  208764. [menuToAddTo setSubmenu: sub forItem: item];
  208765. [sub release];
  208766. }
  208767. else
  208768. {
  208769. NSMenuItem* item = [menuToAddTo addItemWithTitle: text
  208770. action: @selector (menuItemInvoked:)
  208771. keyEquivalent: @""];
  208772. [item setTag: iter.itemId];
  208773. [item setEnabled: iter.isEnabled];
  208774. [item setState: iter.isTicked ? NSOnState : NSOffState];
  208775. [item setTarget: (id) callback];
  208776. NSMutableArray* info = [NSMutableArray arrayWithObject: [NSNumber numberWithUnsignedLongLong: (pointer_sized_int) (void*) iter.commandManager]];
  208777. [info addObject: [NSNumber numberWithInt: topLevelIndex]];
  208778. [item setRepresentedObject: info];
  208779. if (iter.commandManager != 0)
  208780. {
  208781. const Array <KeyPress> keyPresses (iter.commandManager->getKeyMappings()
  208782. ->getKeyPressesAssignedToCommand (iter.itemId));
  208783. if (keyPresses.size() > 0)
  208784. {
  208785. const KeyPress& kp = keyPresses.getReference(0);
  208786. juce_wchar key = kp.getTextCharacter();
  208787. if (kp.getKeyCode() == KeyPress::backspaceKey)
  208788. key = NSBackspaceCharacter;
  208789. else if (kp.getKeyCode() == KeyPress::deleteKey)
  208790. key = NSDeleteCharacter;
  208791. else if (key == 0)
  208792. key = (juce_wchar) kp.getKeyCode();
  208793. unsigned int mods = 0;
  208794. if (kp.getModifiers().isShiftDown())
  208795. mods |= NSShiftKeyMask;
  208796. if (kp.getModifiers().isCtrlDown())
  208797. mods |= NSControlKeyMask;
  208798. if (kp.getModifiers().isAltDown())
  208799. mods |= NSAlternateKeyMask;
  208800. if (kp.getModifiers().isCommandDown())
  208801. mods |= NSCommandKeyMask;
  208802. [item setKeyEquivalent: juceStringToNS (String::charToString (key))];
  208803. [item setKeyEquivalentModifierMask: mods];
  208804. }
  208805. }
  208806. }
  208807. }
  208808. JuceMenuCallback* callback;
  208809. private:
  208810. NSMenu* createMenu (const PopupMenu menu,
  208811. const String& menuName,
  208812. const int topLevelMenuId,
  208813. const int topLevelIndex)
  208814. {
  208815. NSMenu* m = [[NSMenu alloc] initWithTitle: juceStringToNS (menuName)];
  208816. [m setAutoenablesItems: false];
  208817. [m setDelegate: callback];
  208818. PopupMenu::MenuItemIterator iter (menu);
  208819. while (iter.next())
  208820. addMenuItem (iter, m, topLevelMenuId, topLevelIndex);
  208821. [m update];
  208822. return m;
  208823. }
  208824. };
  208825. JuceMainMenuHandler* JuceMainMenuHandler::instance = 0;
  208826. END_JUCE_NAMESPACE
  208827. @implementation JuceMenuCallback
  208828. - (JuceMenuCallback*) initWithOwner: (JuceMainMenuHandler*) owner_
  208829. {
  208830. [super init];
  208831. owner = owner_;
  208832. return self;
  208833. }
  208834. - (void) dealloc
  208835. {
  208836. [super dealloc];
  208837. }
  208838. - (void) menuItemInvoked: (id) menu
  208839. {
  208840. NSMenuItem* item = (NSMenuItem*) menu;
  208841. if ([[item representedObject] isKindOfClass: [NSArray class]])
  208842. {
  208843. // 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
  208844. // our own components, which may have wanted to intercept it. So, rather than dispatching directly, we'll feed it back
  208845. // into the focused component and let it trigger the menu item indirectly.
  208846. NSEvent* e = [NSApp currentEvent];
  208847. if ([e type] == NSKeyDown || [e type] == NSKeyUp)
  208848. {
  208849. if (JUCE_NAMESPACE::Component::getCurrentlyFocusedComponent() != 0)
  208850. {
  208851. JUCE_NAMESPACE::NSViewComponentPeer* peer = dynamic_cast <JUCE_NAMESPACE::NSViewComponentPeer*> (JUCE_NAMESPACE::Component::getCurrentlyFocusedComponent()->getPeer());
  208852. if (peer != 0)
  208853. {
  208854. if ([e type] == NSKeyDown)
  208855. peer->redirectKeyDown (e);
  208856. else
  208857. peer->redirectKeyUp (e);
  208858. return;
  208859. }
  208860. }
  208861. }
  208862. NSArray* info = (NSArray*) [item representedObject];
  208863. owner->invoke ((int) [item tag],
  208864. (ApplicationCommandManager*) (pointer_sized_int)
  208865. [((NSNumber*) [info objectAtIndex: 0]) unsignedLongLongValue],
  208866. (int) [((NSNumber*) [info objectAtIndex: 1]) intValue]);
  208867. }
  208868. }
  208869. - (void) menuNeedsUpdate: (NSMenu*) menu;
  208870. {
  208871. if (JuceMainMenuHandler::instance != 0)
  208872. JuceMainMenuHandler::instance->updateMenus();
  208873. }
  208874. @end
  208875. BEGIN_JUCE_NAMESPACE
  208876. static NSMenu* createStandardAppMenu (NSMenu* menu, const String& appName,
  208877. const PopupMenu* extraItems)
  208878. {
  208879. if (extraItems != 0 && JuceMainMenuHandler::instance != 0 && extraItems->getNumItems() > 0)
  208880. {
  208881. PopupMenu::MenuItemIterator iter (*extraItems);
  208882. while (iter.next())
  208883. JuceMainMenuHandler::instance->addMenuItem (iter, menu, 0, -1);
  208884. [menu addItem: [NSMenuItem separatorItem]];
  208885. }
  208886. NSMenuItem* item;
  208887. // Services...
  208888. item = [[NSMenuItem alloc] initWithTitle: NSLocalizedString (@"Services", nil)
  208889. action: nil keyEquivalent: @""];
  208890. [menu addItem: item];
  208891. [item release];
  208892. NSMenu* servicesMenu = [[NSMenu alloc] initWithTitle: @"Services"];
  208893. [menu setSubmenu: servicesMenu forItem: item];
  208894. [NSApp setServicesMenu: servicesMenu];
  208895. [servicesMenu release];
  208896. [menu addItem: [NSMenuItem separatorItem]];
  208897. // Hide + Show stuff...
  208898. item = [[NSMenuItem alloc] initWithTitle: juceStringToNS ("Hide " + appName)
  208899. action: @selector (hide:) keyEquivalent: @"h"];
  208900. [item setTarget: NSApp];
  208901. [menu addItem: item];
  208902. [item release];
  208903. item = [[NSMenuItem alloc] initWithTitle: NSLocalizedString (@"Hide Others", nil)
  208904. action: @selector (hideOtherApplications:) keyEquivalent: @"h"];
  208905. [item setKeyEquivalentModifierMask: NSCommandKeyMask | NSAlternateKeyMask];
  208906. [item setTarget: NSApp];
  208907. [menu addItem: item];
  208908. [item release];
  208909. item = [[NSMenuItem alloc] initWithTitle: NSLocalizedString (@"Show All", nil)
  208910. action: @selector (unhideAllApplications:) keyEquivalent: @""];
  208911. [item setTarget: NSApp];
  208912. [menu addItem: item];
  208913. [item release];
  208914. [menu addItem: [NSMenuItem separatorItem]];
  208915. // Quit item....
  208916. item = [[NSMenuItem alloc] initWithTitle: juceStringToNS ("Quit " + appName)
  208917. action: @selector (terminate:) keyEquivalent: @"q"];
  208918. [item setTarget: NSApp];
  208919. [menu addItem: item];
  208920. [item release];
  208921. return menu;
  208922. }
  208923. // Since our app has no NIB, this initialises a standard app menu...
  208924. static void rebuildMainMenu (const PopupMenu* extraItems)
  208925. {
  208926. // this can't be used in a plugin!
  208927. jassert (JUCEApplication::getInstance() != 0);
  208928. if (JUCEApplication::getInstance() != 0)
  208929. {
  208930. const ScopedAutoReleasePool pool;
  208931. NSMenu* mainMenu = [[NSMenu alloc] initWithTitle: @"MainMenu"];
  208932. NSMenuItem* item = [mainMenu addItemWithTitle: @"Apple" action: nil keyEquivalent: @""];
  208933. NSMenu* appMenu = [[NSMenu alloc] initWithTitle: @"Apple"];
  208934. [NSApp performSelector: @selector (setAppleMenu:) withObject: appMenu];
  208935. [mainMenu setSubmenu: appMenu forItem: item];
  208936. [NSApp setMainMenu: mainMenu];
  208937. createStandardAppMenu (appMenu, JUCEApplication::getInstance()->getApplicationName(), extraItems);
  208938. [appMenu release];
  208939. [mainMenu release];
  208940. }
  208941. }
  208942. void MenuBarModel::setMacMainMenu (MenuBarModel* newMenuBarModel,
  208943. const PopupMenu* extraAppleMenuItems)
  208944. {
  208945. if (getMacMainMenu() != newMenuBarModel)
  208946. {
  208947. const ScopedAutoReleasePool pool;
  208948. if (newMenuBarModel == 0)
  208949. {
  208950. delete JuceMainMenuHandler::instance;
  208951. jassert (JuceMainMenuHandler::instance == 0); // should be zeroed in the destructor
  208952. jassert (extraAppleMenuItems == 0); // you can't specify some extra items without also supplying a model
  208953. extraAppleMenuItems = 0;
  208954. }
  208955. else
  208956. {
  208957. if (JuceMainMenuHandler::instance == 0)
  208958. JuceMainMenuHandler::instance = new JuceMainMenuHandler();
  208959. JuceMainMenuHandler::instance->setMenu (newMenuBarModel);
  208960. }
  208961. }
  208962. rebuildMainMenu (extraAppleMenuItems);
  208963. if (newMenuBarModel != 0)
  208964. newMenuBarModel->menuItemsChanged();
  208965. }
  208966. MenuBarModel* MenuBarModel::getMacMainMenu()
  208967. {
  208968. return JuceMainMenuHandler::instance != 0
  208969. ? JuceMainMenuHandler::instance->currentModel : 0;
  208970. }
  208971. void initialiseMainMenu()
  208972. {
  208973. if (JUCEApplication::getInstance() != 0) // only needed in an app
  208974. rebuildMainMenu (0);
  208975. }
  208976. #endif
  208977. /*** End of inlined file: juce_mac_MainMenu.mm ***/
  208978. /*** Start of inlined file: juce_mac_FileChooser.mm ***/
  208979. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  208980. // compiled on its own).
  208981. #if JUCE_INCLUDED_FILE
  208982. #if JUCE_MAC
  208983. END_JUCE_NAMESPACE
  208984. using namespace JUCE_NAMESPACE;
  208985. #define JuceFileChooserDelegate MakeObjCClassName(JuceFileChooserDelegate)
  208986. #if defined (MAC_OS_X_VERSION_10_6) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
  208987. @interface JuceFileChooserDelegate : NSObject <NSOpenSavePanelDelegate>
  208988. #else
  208989. @interface JuceFileChooserDelegate : NSObject
  208990. #endif
  208991. {
  208992. StringArray* filters;
  208993. }
  208994. - (JuceFileChooserDelegate*) initWithFilters: (StringArray*) filters_;
  208995. - (void) dealloc;
  208996. - (BOOL) panel: (id) sender shouldShowFilename: (NSString*) filename;
  208997. @end
  208998. @implementation JuceFileChooserDelegate
  208999. - (JuceFileChooserDelegate*) initWithFilters: (StringArray*) filters_
  209000. {
  209001. [super init];
  209002. filters = filters_;
  209003. return self;
  209004. }
  209005. - (void) dealloc
  209006. {
  209007. delete filters;
  209008. [super dealloc];
  209009. }
  209010. - (BOOL) panel: (id) sender shouldShowFilename: (NSString*) filename
  209011. {
  209012. const File f (nsStringToJuce (filename));
  209013. for (int i = filters->size(); --i >= 0;)
  209014. if (f.getFileName().matchesWildcard ((*filters)[i], true))
  209015. return true;
  209016. return f.isDirectory();
  209017. }
  209018. @end
  209019. BEGIN_JUCE_NAMESPACE
  209020. void FileChooser::showPlatformDialog (Array<File>& results,
  209021. const String& title,
  209022. const File& currentFileOrDirectory,
  209023. const String& filter,
  209024. bool selectsDirectory,
  209025. bool selectsFiles,
  209026. bool isSaveDialogue,
  209027. bool warnAboutOverwritingExistingFiles,
  209028. bool selectMultipleFiles,
  209029. FilePreviewComponent* extraInfoComponent)
  209030. {
  209031. const ScopedAutoReleasePool pool;
  209032. StringArray* filters = new StringArray();
  209033. filters->addTokens (filter.replaceCharacters (T(",:"), T(";;")), T(";"), String::empty);
  209034. filters->trim();
  209035. filters->removeEmptyStrings();
  209036. JuceFileChooserDelegate* delegate = [[JuceFileChooserDelegate alloc] initWithFilters: filters];
  209037. [delegate autorelease];
  209038. NSSavePanel* panel = isSaveDialogue ? [NSSavePanel savePanel]
  209039. : [NSOpenPanel openPanel];
  209040. [panel setTitle: juceStringToNS (title)];
  209041. if (! isSaveDialogue)
  209042. {
  209043. NSOpenPanel* openPanel = (NSOpenPanel*) panel;
  209044. [openPanel setCanChooseDirectories: selectsDirectory];
  209045. [openPanel setCanChooseFiles: selectsFiles];
  209046. [openPanel setAllowsMultipleSelection: selectMultipleFiles];
  209047. }
  209048. [panel setDelegate: delegate];
  209049. if (isSaveDialogue || selectsDirectory)
  209050. [panel setCanCreateDirectories: YES];
  209051. String directory, filename;
  209052. if (currentFileOrDirectory.isDirectory())
  209053. {
  209054. directory = currentFileOrDirectory.getFullPathName();
  209055. }
  209056. else
  209057. {
  209058. directory = currentFileOrDirectory.getParentDirectory().getFullPathName();
  209059. filename = currentFileOrDirectory.getFileName();
  209060. }
  209061. if ([panel runModalForDirectory: juceStringToNS (directory)
  209062. file: juceStringToNS (filename)]
  209063. == NSOKButton)
  209064. {
  209065. if (isSaveDialogue)
  209066. {
  209067. results.add (File (nsStringToJuce ([panel filename])));
  209068. }
  209069. else
  209070. {
  209071. NSOpenPanel* openPanel = (NSOpenPanel*) panel;
  209072. NSArray* urls = [openPanel filenames];
  209073. for (unsigned int i = 0; i < [urls count]; ++i)
  209074. {
  209075. NSString* f = [urls objectAtIndex: i];
  209076. results.add (File (nsStringToJuce (f)));
  209077. }
  209078. }
  209079. }
  209080. [panel setDelegate: nil];
  209081. }
  209082. #else
  209083. void FileChooser::showPlatformDialog (Array<File>& results,
  209084. const String& title,
  209085. const File& currentFileOrDirectory,
  209086. const String& filter,
  209087. bool selectsDirectory,
  209088. bool selectsFiles,
  209089. bool isSaveDialogue,
  209090. bool warnAboutOverwritingExistingFiles,
  209091. bool selectMultipleFiles,
  209092. FilePreviewComponent* extraInfoComponent)
  209093. {
  209094. const ScopedAutoReleasePool pool;
  209095. jassertfalse //xxx to do
  209096. }
  209097. #endif
  209098. #endif
  209099. /*** End of inlined file: juce_mac_FileChooser.mm ***/
  209100. /*** Start of inlined file: juce_mac_QuickTimeMovieComponent.mm ***/
  209101. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  209102. // compiled on its own).
  209103. #if JUCE_INCLUDED_FILE && JUCE_QUICKTIME
  209104. END_JUCE_NAMESPACE
  209105. #define NonInterceptingQTMovieView MakeObjCClassName(NonInterceptingQTMovieView)
  209106. @interface NonInterceptingQTMovieView : QTMovieView
  209107. {
  209108. }
  209109. - (id) initWithFrame: (NSRect) frame;
  209110. - (BOOL) acceptsFirstMouse: (NSEvent*) theEvent;
  209111. - (NSView*) hitTest: (NSPoint) p;
  209112. @end
  209113. @implementation NonInterceptingQTMovieView
  209114. - (id) initWithFrame: (NSRect) frame
  209115. {
  209116. self = [super initWithFrame: frame];
  209117. [self setNextResponder: [self superview]];
  209118. return self;
  209119. }
  209120. - (void) dealloc
  209121. {
  209122. [super dealloc];
  209123. }
  209124. - (NSView*) hitTest: (NSPoint) point
  209125. {
  209126. return [self isControllerVisible] ? [super hitTest: point] : nil;
  209127. }
  209128. - (BOOL) acceptsFirstMouse: (NSEvent*) theEvent
  209129. {
  209130. return YES;
  209131. }
  209132. @end
  209133. BEGIN_JUCE_NAMESPACE
  209134. #define theMovie (static_cast <QTMovie*> (movie))
  209135. QuickTimeMovieComponent::QuickTimeMovieComponent()
  209136. : movie (0)
  209137. {
  209138. setOpaque (true);
  209139. setVisible (true);
  209140. QTMovieView* view = [[NonInterceptingQTMovieView alloc] initWithFrame: NSMakeRect (0, 0, 100.0f, 100.0f)];
  209141. setView (view);
  209142. [view release];
  209143. }
  209144. QuickTimeMovieComponent::~QuickTimeMovieComponent()
  209145. {
  209146. closeMovie();
  209147. setView (0);
  209148. }
  209149. bool QuickTimeMovieComponent::isQuickTimeAvailable() throw()
  209150. {
  209151. return true;
  209152. }
  209153. static QTMovie* openMovieFromStream (InputStream* movieStream, File& movieFile)
  209154. {
  209155. // unfortunately, QTMovie objects can only be created on the main thread..
  209156. jassert (MessageManager::getInstance()->isThisTheMessageThread());
  209157. QTMovie* movie = 0;
  209158. FileInputStream* const fin = dynamic_cast <FileInputStream*> (movieStream);
  209159. if (fin != 0)
  209160. {
  209161. movieFile = fin->getFile();
  209162. movie = [QTMovie movieWithFile: juceStringToNS (movieFile.getFullPathName())
  209163. error: nil];
  209164. }
  209165. else
  209166. {
  209167. MemoryBlock temp;
  209168. movieStream->readIntoMemoryBlock (temp);
  209169. const char* const suffixesToTry[] = { ".mov", ".mp3", ".avi", ".m4a" };
  209170. for (int i = 0; i < numElementsInArray (suffixesToTry); ++i)
  209171. {
  209172. movie = [QTMovie movieWithDataReference: [QTDataReference dataReferenceWithReferenceToData: [NSData dataWithBytes: temp.getData()
  209173. length: temp.getSize()]
  209174. name: [NSString stringWithUTF8String: suffixesToTry[i]]
  209175. MIMEType: @""]
  209176. error: nil];
  209177. if (movie != 0)
  209178. break;
  209179. }
  209180. }
  209181. return movie;
  209182. }
  209183. bool QuickTimeMovieComponent::loadMovie (const File& movieFile_,
  209184. const bool isControllerVisible_)
  209185. {
  209186. return loadMovie ((InputStream*) movieFile_.createInputStream(), isControllerVisible_);
  209187. }
  209188. bool QuickTimeMovieComponent::loadMovie (InputStream* movieStream,
  209189. const bool controllerVisible_)
  209190. {
  209191. closeMovie();
  209192. if (getPeer() == 0)
  209193. {
  209194. // To open a movie, this component must be visible inside a functioning window, so that
  209195. // the QT control can be assigned to the window.
  209196. jassertfalse
  209197. return false;
  209198. }
  209199. movie = openMovieFromStream (movieStream, movieFile);
  209200. [theMovie retain];
  209201. QTMovieView* view = (QTMovieView*) getView();
  209202. [view setMovie: theMovie];
  209203. [view setControllerVisible: controllerVisible_];
  209204. setLooping (looping);
  209205. return movie != nil;
  209206. }
  209207. bool QuickTimeMovieComponent::loadMovie (const URL& movieURL,
  209208. const bool isControllerVisible_)
  209209. {
  209210. // unfortunately, QTMovie objects can only be created on the main thread..
  209211. jassert (MessageManager::getInstance()->isThisTheMessageThread());
  209212. closeMovie();
  209213. if (getPeer() == 0)
  209214. {
  209215. // To open a movie, this component must be visible inside a functioning window, so that
  209216. // the QT control can be assigned to the window.
  209217. jassertfalse
  209218. return false;
  209219. }
  209220. NSURL* url = [NSURL URLWithString: juceStringToNS (movieURL.toString (true))];
  209221. NSError* err;
  209222. if ([QTMovie canInitWithURL: url])
  209223. movie = [QTMovie movieWithURL: url error: &err];
  209224. [theMovie retain];
  209225. QTMovieView* view = (QTMovieView*) getView();
  209226. [view setMovie: theMovie];
  209227. [view setControllerVisible: controllerVisible];
  209228. setLooping (looping);
  209229. return movie != nil;
  209230. }
  209231. void QuickTimeMovieComponent::closeMovie()
  209232. {
  209233. stop();
  209234. QTMovieView* view = (QTMovieView*) getView();
  209235. [view setMovie: nil];
  209236. [theMovie release];
  209237. movie = 0;
  209238. movieFile = File::nonexistent;
  209239. }
  209240. bool QuickTimeMovieComponent::isMovieOpen() const
  209241. {
  209242. return movie != nil;
  209243. }
  209244. const File QuickTimeMovieComponent::getCurrentMovieFile() const
  209245. {
  209246. return movieFile;
  209247. }
  209248. void QuickTimeMovieComponent::play()
  209249. {
  209250. [theMovie play];
  209251. }
  209252. void QuickTimeMovieComponent::stop()
  209253. {
  209254. [theMovie stop];
  209255. }
  209256. bool QuickTimeMovieComponent::isPlaying() const
  209257. {
  209258. return movie != 0 && [theMovie rate] != 0;
  209259. }
  209260. void QuickTimeMovieComponent::setPosition (const double seconds)
  209261. {
  209262. if (movie != 0)
  209263. {
  209264. QTTime t;
  209265. t.timeValue = (uint64) (100000.0 * seconds);
  209266. t.timeScale = 100000;
  209267. t.flags = 0;
  209268. [theMovie setCurrentTime: t];
  209269. }
  209270. }
  209271. double QuickTimeMovieComponent::getPosition() const
  209272. {
  209273. if (movie == 0)
  209274. return 0.0;
  209275. QTTime t = [theMovie currentTime];
  209276. return t.timeValue / (double) t.timeScale;
  209277. }
  209278. void QuickTimeMovieComponent::setSpeed (const float newSpeed)
  209279. {
  209280. [theMovie setRate: newSpeed];
  209281. }
  209282. double QuickTimeMovieComponent::getMovieDuration() const
  209283. {
  209284. if (movie == 0)
  209285. return 0.0;
  209286. QTTime t = [theMovie duration];
  209287. return t.timeValue / (double) t.timeScale;
  209288. }
  209289. void QuickTimeMovieComponent::setLooping (const bool shouldLoop)
  209290. {
  209291. looping = shouldLoop;
  209292. [theMovie setAttribute: [NSNumber numberWithBool: shouldLoop]
  209293. forKey: QTMovieLoopsAttribute];
  209294. }
  209295. bool QuickTimeMovieComponent::isLooping() const
  209296. {
  209297. return looping;
  209298. }
  209299. void QuickTimeMovieComponent::setMovieVolume (const float newVolume)
  209300. {
  209301. [theMovie setVolume: newVolume];
  209302. }
  209303. float QuickTimeMovieComponent::getMovieVolume() const
  209304. {
  209305. return movie != 0 ? [theMovie volume] : 0.0f;
  209306. }
  209307. void QuickTimeMovieComponent::getMovieNormalSize (int& width, int& height) const
  209308. {
  209309. width = 0;
  209310. height = 0;
  209311. if (movie != 0)
  209312. {
  209313. NSSize s = [[theMovie attributeForKey: QTMovieNaturalSizeAttribute] sizeValue];
  209314. width = (int) s.width;
  209315. height = (int) s.height;
  209316. }
  209317. }
  209318. void QuickTimeMovieComponent::paint (Graphics& g)
  209319. {
  209320. if (movie == 0)
  209321. g.fillAll (Colours::black);
  209322. }
  209323. bool QuickTimeMovieComponent::isControllerVisible() const
  209324. {
  209325. return controllerVisible;
  209326. }
  209327. void QuickTimeMovieComponent::goToStart()
  209328. {
  209329. setPosition (0.0);
  209330. }
  209331. void QuickTimeMovieComponent::setBoundsWithCorrectAspectRatio (const Rectangle<int>& spaceToFitWithin,
  209332. const RectanglePlacement& placement)
  209333. {
  209334. int normalWidth, normalHeight;
  209335. getMovieNormalSize (normalWidth, normalHeight);
  209336. if (normalWidth > 0 && normalHeight > 0 && ! spaceToFitWithin.isEmpty())
  209337. {
  209338. double x = 0.0, y = 0.0, w = normalWidth, h = normalHeight;
  209339. placement.applyTo (x, y, w, h,
  209340. spaceToFitWithin.getX(), spaceToFitWithin.getY(),
  209341. spaceToFitWithin.getWidth(), spaceToFitWithin.getHeight());
  209342. if (w > 0 && h > 0)
  209343. {
  209344. setBounds (roundToInt (x), roundToInt (y),
  209345. roundToInt (w), roundToInt (h));
  209346. }
  209347. }
  209348. else
  209349. {
  209350. setBounds (spaceToFitWithin);
  209351. }
  209352. }
  209353. #if ! (JUCE_MAC && JUCE_64BIT)
  209354. bool juce_OpenQuickTimeMovieFromStream (InputStream* movieStream, Movie& result, Handle& dataHandle)
  209355. {
  209356. if (movieStream == 0)
  209357. return false;
  209358. File file;
  209359. QTMovie* movie = openMovieFromStream (movieStream, file);
  209360. if (movie != nil)
  209361. result = [movie quickTimeMovie];
  209362. return movie != nil;
  209363. }
  209364. #endif
  209365. #endif
  209366. /*** End of inlined file: juce_mac_QuickTimeMovieComponent.mm ***/
  209367. /*** Start of inlined file: juce_mac_AudioCDBurner.mm ***/
  209368. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  209369. // compiled on its own).
  209370. #if JUCE_INCLUDED_FILE && JUCE_USE_CDBURNER
  209371. const int kilobytesPerSecond1x = 176;
  209372. END_JUCE_NAMESPACE
  209373. #define OpenDiskDevice MakeObjCClassName(OpenDiskDevice)
  209374. @interface OpenDiskDevice : NSObject
  209375. {
  209376. @public
  209377. DRDevice* device;
  209378. NSMutableArray* tracks;
  209379. bool underrunProtection;
  209380. }
  209381. - (OpenDiskDevice*) initWithDRDevice: (DRDevice*) device;
  209382. - (void) dealloc;
  209383. - (void) addSourceTrack: (JUCE_NAMESPACE::AudioSource*) source numSamples: (int) numSamples_;
  209384. - (void) burn: (JUCE_NAMESPACE::AudioCDBurner::BurnProgressListener*) listener errorString: (JUCE_NAMESPACE::String*) error
  209385. ejectAfterwards: (bool) shouldEject isFake: (bool) peformFakeBurnForTesting speed: (int) burnSpeed;
  209386. @end
  209387. #define AudioTrackProducer MakeObjCClassName(AudioTrackProducer)
  209388. @interface AudioTrackProducer : NSObject
  209389. {
  209390. JUCE_NAMESPACE::AudioSource* source;
  209391. int readPosition, lengthInFrames;
  209392. }
  209393. - (AudioTrackProducer*) init: (int) lengthInFrames;
  209394. - (AudioTrackProducer*) initWithAudioSource: (JUCE_NAMESPACE::AudioSource*) source numSamples: (int) lengthInSamples;
  209395. - (void) dealloc;
  209396. - (void) setupTrackProperties: (DRTrack*) track;
  209397. - (void) cleanupTrackAfterBurn: (DRTrack*) track;
  209398. - (BOOL) cleanupTrackAfterVerification:(DRTrack*)track;
  209399. - (uint64_t) estimateLengthOfTrack:(DRTrack*)track;
  209400. - (BOOL) prepareTrack:(DRTrack*)track forBurn:(DRBurn*)burn
  209401. toMedia:(NSDictionary*)mediaInfo;
  209402. - (BOOL) prepareTrackForVerification:(DRTrack*)track;
  209403. - (uint32_t) produceDataForTrack:(DRTrack*)track intoBuffer:(char*)buffer
  209404. length:(uint32_t)bufferLength atAddress:(uint64_t)address
  209405. blockSize:(uint32_t)blockSize ioFlags:(uint32_t*)flags;
  209406. - (uint32_t) producePreGapForTrack:(DRTrack*)track
  209407. intoBuffer:(char*)buffer length:(uint32_t)bufferLength
  209408. atAddress:(uint64_t)address blockSize:(uint32_t)blockSize
  209409. ioFlags:(uint32_t*)flags;
  209410. - (BOOL) verifyDataForTrack:(DRTrack*)track inBuffer:(const char*)buffer
  209411. length:(uint32_t)bufferLength atAddress:(uint64_t)address
  209412. blockSize:(uint32_t)blockSize ioFlags:(uint32_t*)flags;
  209413. - (uint32_t) producePreGapForTrack:(DRTrack*)track
  209414. intoBuffer:(char*)buffer length:(uint32_t)bufferLength
  209415. atAddress:(uint64_t)address blockSize:(uint32_t)blockSize
  209416. ioFlags:(uint32_t*)flags;
  209417. @end
  209418. @implementation OpenDiskDevice
  209419. - (OpenDiskDevice*) initWithDRDevice: (DRDevice*) device_
  209420. {
  209421. [super init];
  209422. device = device_;
  209423. tracks = [[NSMutableArray alloc] init];
  209424. underrunProtection = true;
  209425. return self;
  209426. }
  209427. - (void) dealloc
  209428. {
  209429. [tracks release];
  209430. [super dealloc];
  209431. }
  209432. - (void) addSourceTrack: (JUCE_NAMESPACE::AudioSource*) source_ numSamples: (int) numSamples_
  209433. {
  209434. AudioTrackProducer* p = [[AudioTrackProducer alloc] initWithAudioSource: source_ numSamples: numSamples_];
  209435. DRTrack* t = [[DRTrack alloc] initWithProducer: p];
  209436. [p setupTrackProperties: t];
  209437. [tracks addObject: t];
  209438. [t release];
  209439. [p release];
  209440. }
  209441. - (void) burn: (JUCE_NAMESPACE::AudioCDBurner::BurnProgressListener*) listener errorString: (JUCE_NAMESPACE::String*) error
  209442. ejectAfterwards: (bool) shouldEject isFake: (bool) peformFakeBurnForTesting speed: (int) burnSpeed
  209443. {
  209444. DRBurn* burn = [DRBurn burnForDevice: device];
  209445. if (! [device acquireExclusiveAccess])
  209446. {
  209447. *error = "Couldn't open or write to the CD device";
  209448. return;
  209449. }
  209450. [device acquireMediaReservation];
  209451. NSMutableDictionary* d = [[burn properties] mutableCopy];
  209452. [d autorelease];
  209453. [d setObject: [NSNumber numberWithBool: peformFakeBurnForTesting] forKey: DRBurnTestingKey];
  209454. [d setObject: [NSNumber numberWithBool: false] forKey: DRBurnVerifyDiscKey];
  209455. [d setObject: (shouldEject ? DRBurnCompletionActionEject : DRBurnCompletionActionMount) forKey: DRBurnCompletionActionKey];
  209456. if (burnSpeed > 0)
  209457. [d setObject: [NSNumber numberWithFloat: burnSpeed * JUCE_NAMESPACE::kilobytesPerSecond1x] forKey: DRBurnRequestedSpeedKey];
  209458. if (! underrunProtection)
  209459. [d setObject: [NSNumber numberWithBool: false] forKey: DRBurnUnderrunProtectionKey];
  209460. [burn setProperties: d];
  209461. [burn writeLayout: tracks];
  209462. for (;;)
  209463. {
  209464. JUCE_NAMESPACE::Thread::sleep (300);
  209465. float progress = [[[burn status] objectForKey: DRStatusPercentCompleteKey] floatValue];
  209466. if (listener != 0 && listener->audioCDBurnProgress (progress))
  209467. {
  209468. [burn abort];
  209469. *error = "User cancelled the write operation";
  209470. break;
  209471. }
  209472. if ([[[burn status] objectForKey: DRStatusStateKey] isEqualTo: DRStatusStateFailed])
  209473. {
  209474. *error = "Write operation failed";
  209475. break;
  209476. }
  209477. else if ([[[burn status] objectForKey: DRStatusStateKey] isEqualTo: DRStatusStateDone])
  209478. {
  209479. break;
  209480. }
  209481. NSString* err = (NSString*) [[[burn status] objectForKey: DRErrorStatusKey]
  209482. objectForKey: DRErrorStatusErrorStringKey];
  209483. if ([err length] > 0)
  209484. {
  209485. *error = JUCE_NAMESPACE::String::fromUTF8 ([err UTF8String]);
  209486. break;
  209487. }
  209488. }
  209489. [device releaseMediaReservation];
  209490. [device releaseExclusiveAccess];
  209491. }
  209492. @end
  209493. @implementation AudioTrackProducer
  209494. - (AudioTrackProducer*) init: (int) lengthInFrames_
  209495. {
  209496. lengthInFrames = lengthInFrames_;
  209497. readPosition = 0;
  209498. return self;
  209499. }
  209500. - (void) setupTrackProperties: (DRTrack*) track
  209501. {
  209502. NSMutableDictionary* p = [[track properties] mutableCopy];
  209503. [p setObject:[DRMSF msfWithFrames: lengthInFrames] forKey: DRTrackLengthKey];
  209504. [p setObject:[NSNumber numberWithUnsignedShort:2352] forKey: DRBlockSizeKey];
  209505. [p setObject:[NSNumber numberWithInt:0] forKey: DRDataFormKey];
  209506. [p setObject:[NSNumber numberWithInt:0] forKey: DRBlockTypeKey];
  209507. [p setObject:[NSNumber numberWithInt:0] forKey: DRTrackModeKey];
  209508. [p setObject:[NSNumber numberWithInt:0] forKey: DRSessionFormatKey];
  209509. [track setProperties: p];
  209510. [p release];
  209511. }
  209512. - (AudioTrackProducer*) initWithAudioSource: (JUCE_NAMESPACE::AudioSource*) source_ numSamples: (int) lengthInSamples
  209513. {
  209514. AudioTrackProducer* s = [self init: (lengthInSamples + 587) / 588];
  209515. if (s != nil)
  209516. s->source = source_;
  209517. return s;
  209518. }
  209519. - (void) dealloc
  209520. {
  209521. if (source != 0)
  209522. {
  209523. source->releaseResources();
  209524. delete source;
  209525. }
  209526. [super dealloc];
  209527. }
  209528. - (void) cleanupTrackAfterBurn: (DRTrack*) track
  209529. {
  209530. }
  209531. - (BOOL) cleanupTrackAfterVerification: (DRTrack*) track
  209532. {
  209533. return true;
  209534. }
  209535. - (uint64_t) estimateLengthOfTrack: (DRTrack*) track
  209536. {
  209537. return lengthInFrames;
  209538. }
  209539. - (BOOL) prepareTrack: (DRTrack*) track forBurn: (DRBurn*) burn
  209540. toMedia: (NSDictionary*) mediaInfo
  209541. {
  209542. if (source != 0)
  209543. source->prepareToPlay (44100 / 75, 44100);
  209544. readPosition = 0;
  209545. return true;
  209546. }
  209547. - (BOOL) prepareTrackForVerification: (DRTrack*) track
  209548. {
  209549. if (source != 0)
  209550. source->prepareToPlay (44100 / 75, 44100);
  209551. return true;
  209552. }
  209553. - (uint32_t) produceDataForTrack: (DRTrack*) track intoBuffer: (char*) buffer
  209554. length: (uint32_t) bufferLength atAddress: (uint64_t) address
  209555. blockSize: (uint32_t) blockSize ioFlags: (uint32_t*) flags
  209556. {
  209557. if (source != 0)
  209558. {
  209559. const int numSamples = JUCE_NAMESPACE::jmin ((int) bufferLength / 4, (lengthInFrames * (44100 / 75)) - readPosition);
  209560. if (numSamples > 0)
  209561. {
  209562. JUCE_NAMESPACE::AudioSampleBuffer tempBuffer (2, numSamples);
  209563. JUCE_NAMESPACE::AudioSourceChannelInfo info;
  209564. info.buffer = &tempBuffer;
  209565. info.startSample = 0;
  209566. info.numSamples = numSamples;
  209567. source->getNextAudioBlock (info);
  209568. JUCE_NAMESPACE::AudioDataConverters::convertFloatToInt16LE (tempBuffer.getSampleData (0),
  209569. buffer, numSamples, 4);
  209570. JUCE_NAMESPACE::AudioDataConverters::convertFloatToInt16LE (tempBuffer.getSampleData (1),
  209571. buffer + 2, numSamples, 4);
  209572. readPosition += numSamples;
  209573. }
  209574. return numSamples * 4;
  209575. }
  209576. return 0;
  209577. }
  209578. - (uint32_t) producePreGapForTrack: (DRTrack*) track
  209579. intoBuffer: (char*) buffer length: (uint32_t) bufferLength
  209580. atAddress: (uint64_t) address blockSize: (uint32_t) blockSize
  209581. ioFlags: (uint32_t*) flags
  209582. {
  209583. zeromem (buffer, bufferLength);
  209584. return bufferLength;
  209585. }
  209586. - (BOOL) verifyDataForTrack: (DRTrack*) track inBuffer: (const char*) buffer
  209587. length: (uint32_t) bufferLength atAddress: (uint64_t) address
  209588. blockSize: (uint32_t) blockSize ioFlags: (uint32_t*) flags
  209589. {
  209590. return true;
  209591. }
  209592. @end
  209593. BEGIN_JUCE_NAMESPACE
  209594. class AudioCDBurner::Pimpl : public Timer
  209595. {
  209596. public:
  209597. Pimpl (AudioCDBurner& owner_, const int deviceIndex)
  209598. : device (0), owner (owner_)
  209599. {
  209600. DRDevice* dev = [[DRDevice devices] objectAtIndex: deviceIndex];
  209601. if (dev != 0)
  209602. {
  209603. device = [[OpenDiskDevice alloc] initWithDRDevice: dev];
  209604. lastState = getDiskState();
  209605. startTimer (1000);
  209606. }
  209607. }
  209608. ~Pimpl()
  209609. {
  209610. stopTimer();
  209611. [device release];
  209612. }
  209613. void timerCallback()
  209614. {
  209615. const DiskState state = getDiskState();
  209616. if (state != lastState)
  209617. {
  209618. lastState = state;
  209619. owner.sendChangeMessage (&owner);
  209620. }
  209621. }
  209622. DiskState getDiskState() const
  209623. {
  209624. if ([device->device isValid])
  209625. {
  209626. NSDictionary* status = [device->device status];
  209627. NSString* state = [status objectForKey: DRDeviceMediaStateKey];
  209628. if ([state isEqualTo: DRDeviceMediaStateNone])
  209629. {
  209630. if ([[status objectForKey: DRDeviceIsTrayOpenKey] boolValue])
  209631. return trayOpen;
  209632. return noDisc;
  209633. }
  209634. if ([state isEqualTo: DRDeviceMediaStateMediaPresent])
  209635. {
  209636. if ([[[status objectForKey: DRDeviceMediaInfoKey] objectForKey: DRDeviceMediaBlocksFreeKey] intValue] > 0)
  209637. return writableDiskPresent;
  209638. else
  209639. return readOnlyDiskPresent;
  209640. }
  209641. }
  209642. return unknown;
  209643. }
  209644. bool openTray() { return [device->device isValid] && [device->device ejectMedia]; }
  209645. const Array<int> getAvailableWriteSpeeds() const
  209646. {
  209647. Array<int> results;
  209648. if ([device->device isValid])
  209649. {
  209650. NSArray* speeds = [[[device->device status] objectForKey: DRDeviceMediaInfoKey] objectForKey: DRDeviceBurnSpeedsKey];
  209651. for (unsigned int i = 0; i < [speeds count]; ++i)
  209652. {
  209653. const int kbPerSec = [[speeds objectAtIndex: i] intValue];
  209654. results.add (kbPerSec / kilobytesPerSecond1x);
  209655. }
  209656. }
  209657. return results;
  209658. }
  209659. bool setBufferUnderrunProtection (const bool shouldBeEnabled)
  209660. {
  209661. if ([device->device isValid])
  209662. {
  209663. device->underrunProtection = shouldBeEnabled;
  209664. return shouldBeEnabled && [[[device->device status] objectForKey: DRDeviceCanUnderrunProtectCDKey] boolValue];
  209665. }
  209666. return false;
  209667. }
  209668. int getNumAvailableAudioBlocks() const
  209669. {
  209670. return [[[[device->device status] objectForKey: DRDeviceMediaInfoKey]
  209671. objectForKey: DRDeviceMediaBlocksFreeKey] intValue];
  209672. }
  209673. OpenDiskDevice* device;
  209674. private:
  209675. DiskState lastState;
  209676. AudioCDBurner& owner;
  209677. };
  209678. AudioCDBurner::AudioCDBurner (const int deviceIndex)
  209679. {
  209680. pimpl = new Pimpl (*this, deviceIndex);
  209681. }
  209682. AudioCDBurner::~AudioCDBurner()
  209683. {
  209684. }
  209685. AudioCDBurner* AudioCDBurner::openDevice (const int deviceIndex)
  209686. {
  209687. ScopedPointer <AudioCDBurner> b (new AudioCDBurner (deviceIndex));
  209688. if (b->pimpl->device == 0)
  209689. b = 0;
  209690. return b.release();
  209691. }
  209692. static NSArray* findDiskBurnerDevices()
  209693. {
  209694. NSMutableArray* results = [NSMutableArray array];
  209695. NSArray* devs = [DRDevice devices];
  209696. if (devs != 0)
  209697. {
  209698. int num = [devs count];
  209699. int i;
  209700. for (i = 0; i < num; ++i)
  209701. {
  209702. NSDictionary* dic = [[devs objectAtIndex: i] info];
  209703. NSString* name = [dic valueForKey: DRDeviceProductNameKey];
  209704. if (name != nil)
  209705. [results addObject: name];
  209706. }
  209707. }
  209708. return results;
  209709. }
  209710. const StringArray AudioCDBurner::findAvailableDevices()
  209711. {
  209712. NSArray* names = findDiskBurnerDevices();
  209713. StringArray s;
  209714. for (unsigned int i = 0; i < [names count]; ++i)
  209715. s.add (String::fromUTF8 ([[names objectAtIndex: i] UTF8String]));
  209716. return s;
  209717. }
  209718. AudioCDBurner::DiskState AudioCDBurner::getDiskState() const
  209719. {
  209720. return pimpl->getDiskState();
  209721. }
  209722. bool AudioCDBurner::isDiskPresent() const
  209723. {
  209724. return getDiskState() == writableDiskPresent;
  209725. }
  209726. bool AudioCDBurner::openTray()
  209727. {
  209728. return pimpl->openTray();
  209729. }
  209730. AudioCDBurner::DiskState AudioCDBurner::waitUntilStateChange (int timeOutMilliseconds)
  209731. {
  209732. const int64 timeout = Time::currentTimeMillis() + timeOutMilliseconds;
  209733. DiskState oldState = getDiskState();
  209734. DiskState newState = oldState;
  209735. while (newState == oldState && Time::currentTimeMillis() < timeout)
  209736. {
  209737. newState = getDiskState();
  209738. Thread::sleep (100);
  209739. }
  209740. return newState;
  209741. }
  209742. const Array<int> AudioCDBurner::getAvailableWriteSpeeds() const
  209743. {
  209744. return pimpl->getAvailableWriteSpeeds();
  209745. }
  209746. bool AudioCDBurner::setBufferUnderrunProtection (const bool shouldBeEnabled)
  209747. {
  209748. return pimpl->setBufferUnderrunProtection (shouldBeEnabled);
  209749. }
  209750. int AudioCDBurner::getNumAvailableAudioBlocks() const
  209751. {
  209752. return pimpl->getNumAvailableAudioBlocks();
  209753. }
  209754. bool AudioCDBurner::addAudioTrack (AudioSource* source, int numSamps)
  209755. {
  209756. if ([pimpl->device->device isValid])
  209757. {
  209758. [pimpl->device addSourceTrack: source numSamples: numSamps];
  209759. return true;
  209760. }
  209761. return false;
  209762. }
  209763. const String AudioCDBurner::burn (JUCE_NAMESPACE::AudioCDBurner::BurnProgressListener* listener,
  209764. bool ejectDiscAfterwards,
  209765. bool performFakeBurnForTesting,
  209766. int writeSpeed)
  209767. {
  209768. String error ("Couldn't open or write to the CD device");
  209769. if ([pimpl->device->device isValid])
  209770. {
  209771. error = String::empty;
  209772. [pimpl->device burn: listener
  209773. errorString: &error
  209774. ejectAfterwards: ejectDiscAfterwards
  209775. isFake: performFakeBurnForTesting
  209776. speed: writeSpeed];
  209777. }
  209778. return error;
  209779. }
  209780. #endif
  209781. #if JUCE_INCLUDED_FILE && JUCE_USE_CDREADER
  209782. void AudioCDReader::ejectDisk()
  209783. {
  209784. const ScopedAutoReleasePool p;
  209785. [[NSWorkspace sharedWorkspace] unmountAndEjectDeviceAtPath: juceStringToNS (volumeDir.getFullPathName())];
  209786. }
  209787. #endif
  209788. /*** End of inlined file: juce_mac_AudioCDBurner.mm ***/
  209789. /*** Start of inlined file: juce_mac_MessageManager.mm ***/
  209790. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  209791. // compiled on its own).
  209792. #if JUCE_INCLUDED_FILE
  209793. class AppDelegateRedirector
  209794. {
  209795. public:
  209796. AppDelegateRedirector()
  209797. {
  209798. #if MAC_OS_X_VERSION_MIN_REQUIRED > MAC_OS_X_VERSION_10_4
  209799. runLoop = CFRunLoopGetMain();
  209800. #else
  209801. runLoop = CFRunLoopGetCurrent();
  209802. #endif
  209803. CFRunLoopSourceContext sourceContext;
  209804. zerostruct (sourceContext);
  209805. sourceContext.info = this;
  209806. sourceContext.perform = runLoopSourceCallback;
  209807. runLoopSource = CFRunLoopSourceCreate (kCFAllocatorDefault, 1, &sourceContext);
  209808. CFRunLoopAddSource (runLoop, runLoopSource, kCFRunLoopCommonModes);
  209809. }
  209810. virtual ~AppDelegateRedirector()
  209811. {
  209812. CFRunLoopRemoveSource (runLoop, runLoopSource, kCFRunLoopCommonModes);
  209813. CFRunLoopSourceInvalidate (runLoopSource);
  209814. CFRelease (runLoopSource);
  209815. while (messages.size() > 0)
  209816. delete ((Message*) messages.remove(0));
  209817. }
  209818. virtual NSApplicationTerminateReply shouldTerminate()
  209819. {
  209820. if (JUCEApplication::getInstance() != 0)
  209821. {
  209822. JUCEApplication::getInstance()->systemRequestedQuit();
  209823. return NSTerminateCancel;
  209824. }
  209825. return NSTerminateNow;
  209826. }
  209827. virtual BOOL openFile (const NSString* filename)
  209828. {
  209829. if (JUCEApplication::getInstance() != 0)
  209830. {
  209831. JUCEApplication::getInstance()->anotherInstanceStarted (nsStringToJuce (filename));
  209832. return YES;
  209833. }
  209834. return NO;
  209835. }
  209836. virtual void openFiles (NSArray* filenames)
  209837. {
  209838. StringArray files;
  209839. for (unsigned int i = 0; i < [filenames count]; ++i)
  209840. {
  209841. String filename (nsStringToJuce ((NSString*) [filenames objectAtIndex: i]));
  209842. if (filename.containsChar (T(' ')))
  209843. filename = filename.quoted('"');
  209844. files.add (filename);
  209845. }
  209846. if (files.size() > 0 && JUCEApplication::getInstance() != 0)
  209847. {
  209848. JUCEApplication::getInstance()->anotherInstanceStarted (files.joinIntoString (T(" ")));
  209849. }
  209850. }
  209851. virtual void focusChanged()
  209852. {
  209853. juce_HandleProcessFocusChange();
  209854. }
  209855. struct CallbackMessagePayload
  209856. {
  209857. MessageCallbackFunction* function;
  209858. void* parameter;
  209859. void* volatile result;
  209860. bool volatile hasBeenExecuted;
  209861. };
  209862. virtual void performCallback (CallbackMessagePayload* pl)
  209863. {
  209864. pl->result = (*pl->function) (pl->parameter);
  209865. pl->hasBeenExecuted = true;
  209866. }
  209867. virtual void deleteSelf()
  209868. {
  209869. delete this;
  209870. }
  209871. void postMessage (void* m)
  209872. {
  209873. messages.add (m);
  209874. CFRunLoopSourceSignal (runLoopSource);
  209875. CFRunLoopWakeUp (runLoop);
  209876. }
  209877. private:
  209878. CFRunLoopRef runLoop;
  209879. CFRunLoopSourceRef runLoopSource;
  209880. Array <void*, CriticalSection> messages;
  209881. void runLoopCallback()
  209882. {
  209883. int numDispatched = 0;
  209884. do
  209885. {
  209886. void* const nextMessage = messages.remove (0);
  209887. if (nextMessage == 0)
  209888. return;
  209889. const ScopedAutoReleasePool pool;
  209890. MessageManager::getInstance()->deliverMessage (nextMessage);
  209891. } while (++numDispatched <= 4);
  209892. CFRunLoopSourceSignal (runLoopSource);
  209893. CFRunLoopWakeUp (runLoop);
  209894. }
  209895. static void runLoopSourceCallback (void* info)
  209896. {
  209897. ((AppDelegateRedirector*) info)->runLoopCallback();
  209898. }
  209899. };
  209900. END_JUCE_NAMESPACE
  209901. using namespace JUCE_NAMESPACE;
  209902. #define JuceAppDelegate MakeObjCClassName(JuceAppDelegate)
  209903. @interface JuceAppDelegate : NSObject
  209904. {
  209905. @private
  209906. id oldDelegate;
  209907. @public
  209908. AppDelegateRedirector* redirector;
  209909. }
  209910. - (JuceAppDelegate*) init;
  209911. - (void) dealloc;
  209912. - (BOOL) application: (NSApplication*) theApplication openFile: (NSString*) filename;
  209913. - (void) application: (NSApplication*) sender openFiles: (NSArray*) filenames;
  209914. - (NSApplicationTerminateReply) applicationShouldTerminate: (NSApplication*) app;
  209915. - (void) applicationDidBecomeActive: (NSNotification*) aNotification;
  209916. - (void) applicationDidResignActive: (NSNotification*) aNotification;
  209917. - (void) applicationWillUnhide: (NSNotification*) aNotification;
  209918. - (void) performCallback: (id) info;
  209919. - (void) dummyMethod;
  209920. @end
  209921. @implementation JuceAppDelegate
  209922. - (JuceAppDelegate*) init
  209923. {
  209924. [super init];
  209925. redirector = new AppDelegateRedirector();
  209926. NSNotificationCenter* center = [NSNotificationCenter defaultCenter];
  209927. if (JUCEApplication::getInstance() != 0)
  209928. {
  209929. oldDelegate = [NSApp delegate];
  209930. [NSApp setDelegate: self];
  209931. }
  209932. else
  209933. {
  209934. oldDelegate = 0;
  209935. [center addObserver: self selector: @selector (applicationDidResignActive:)
  209936. name: NSApplicationDidResignActiveNotification object: NSApp];
  209937. [center addObserver: self selector: @selector (applicationDidBecomeActive:)
  209938. name: NSApplicationDidBecomeActiveNotification object: NSApp];
  209939. [center addObserver: self selector: @selector (applicationWillUnhide:)
  209940. name: NSApplicationWillUnhideNotification object: NSApp];
  209941. }
  209942. return self;
  209943. }
  209944. - (void) dealloc
  209945. {
  209946. if (oldDelegate != 0)
  209947. [NSApp setDelegate: oldDelegate];
  209948. redirector->deleteSelf();
  209949. [super dealloc];
  209950. }
  209951. - (NSApplicationTerminateReply) applicationShouldTerminate: (NSApplication*) app
  209952. {
  209953. return redirector->shouldTerminate();
  209954. }
  209955. - (BOOL) application: (NSApplication*) app openFile: (NSString*) filename
  209956. {
  209957. return redirector->openFile (filename);
  209958. }
  209959. - (void) application: (NSApplication*) sender openFiles: (NSArray*) filenames
  209960. {
  209961. return redirector->openFiles (filenames);
  209962. }
  209963. - (void) applicationDidBecomeActive: (NSNotification*) aNotification
  209964. {
  209965. redirector->focusChanged();
  209966. }
  209967. - (void) applicationDidResignActive: (NSNotification*) aNotification
  209968. {
  209969. redirector->focusChanged();
  209970. }
  209971. - (void) applicationWillUnhide: (NSNotification*) aNotification
  209972. {
  209973. redirector->focusChanged();
  209974. }
  209975. - (void) performCallback: (id) info
  209976. {
  209977. if ([info isKindOfClass: [NSData class]])
  209978. {
  209979. AppDelegateRedirector::CallbackMessagePayload* pl
  209980. = (AppDelegateRedirector::CallbackMessagePayload*) [((NSData*) info) bytes];
  209981. if (pl != 0)
  209982. redirector->performCallback (pl);
  209983. }
  209984. else
  209985. {
  209986. jassertfalse // should never get here!
  209987. }
  209988. }
  209989. - (void) dummyMethod {} // (used as a way of running a dummy thread)
  209990. @end
  209991. BEGIN_JUCE_NAMESPACE
  209992. static JuceAppDelegate* juceAppDelegate = 0;
  209993. void MessageManager::runDispatchLoop()
  209994. {
  209995. if (! quitMessagePosted) // check that the quit message wasn't already posted..
  209996. {
  209997. const ScopedAutoReleasePool pool;
  209998. // must only be called by the message thread!
  209999. jassert (isThisTheMessageThread());
  210000. #if JUCE_CATCH_UNHANDLED_EXCEPTIONS
  210001. @try
  210002. {
  210003. [NSApp run];
  210004. }
  210005. @catch (NSException* e)
  210006. {
  210007. // An AppKit exception will kill the app, but at least this provides a chance to log it.,
  210008. std::runtime_error ex (std::string ("NSException: ") + [[e name] UTF8String] + ", Reason:" + [[e reason] UTF8String]);
  210009. JUCEApplication::sendUnhandledException (&ex, __FILE__, __LINE__);
  210010. }
  210011. @finally
  210012. {
  210013. }
  210014. #else
  210015. [NSApp run];
  210016. #endif
  210017. }
  210018. }
  210019. void MessageManager::stopDispatchLoop()
  210020. {
  210021. quitMessagePosted = true;
  210022. [NSApp stop: nil];
  210023. [NSApp activateIgnoringOtherApps: YES]; // (if the app is inactive, it sits there and ignores the quit request until the next time it gets activated)
  210024. [NSEvent startPeriodicEventsAfterDelay: 0 withPeriod: 0.1];
  210025. }
  210026. static bool isEventBlockedByModalComps (NSEvent* e)
  210027. {
  210028. if (Component::getNumCurrentlyModalComponents() == 0)
  210029. return false;
  210030. NSWindow* const w = [e window];
  210031. if (w == 0 || [w worksWhenModal])
  210032. return false;
  210033. bool isKey = false, isInputAttempt = false;
  210034. switch ([e type])
  210035. {
  210036. case NSKeyDown:
  210037. case NSKeyUp:
  210038. isKey = isInputAttempt = true;
  210039. break;
  210040. case NSLeftMouseDown:
  210041. case NSRightMouseDown:
  210042. case NSOtherMouseDown:
  210043. isInputAttempt = true;
  210044. break;
  210045. case NSLeftMouseDragged:
  210046. case NSRightMouseDragged:
  210047. case NSLeftMouseUp:
  210048. case NSRightMouseUp:
  210049. case NSOtherMouseUp:
  210050. case NSOtherMouseDragged:
  210051. if (Desktop::getInstance().getDraggingMouseSource(0) != 0)
  210052. return false;
  210053. break;
  210054. case NSMouseMoved:
  210055. case NSMouseEntered:
  210056. case NSMouseExited:
  210057. case NSCursorUpdate:
  210058. case NSScrollWheel:
  210059. case NSTabletPoint:
  210060. case NSTabletProximity:
  210061. break;
  210062. default:
  210063. return false;
  210064. }
  210065. for (int i = ComponentPeer::getNumPeers(); --i >= 0;)
  210066. {
  210067. ComponentPeer* const peer = ComponentPeer::getPeer (i);
  210068. NSView* const compView = (NSView*) peer->getNativeHandle();
  210069. if ([compView window] == w)
  210070. {
  210071. if (isKey)
  210072. {
  210073. if (compView == [w firstResponder])
  210074. return false;
  210075. }
  210076. else
  210077. {
  210078. if (NSPointInRect ([compView convertPoint: [e locationInWindow] fromView: nil],
  210079. [compView bounds]))
  210080. return false;
  210081. }
  210082. }
  210083. }
  210084. if (isInputAttempt)
  210085. {
  210086. if (! [NSApp isActive])
  210087. [NSApp activateIgnoringOtherApps: YES];
  210088. Component* const modal = Component::getCurrentlyModalComponent (0);
  210089. if (modal != 0)
  210090. modal->inputAttemptWhenModal();
  210091. }
  210092. return true;
  210093. }
  210094. bool MessageManager::runDispatchLoopUntil (int millisecondsToRunFor)
  210095. {
  210096. const ScopedAutoReleasePool pool;
  210097. jassert (isThisTheMessageThread()); // must only be called by the message thread
  210098. uint32 endTime = Time::getMillisecondCounter() + millisecondsToRunFor;
  210099. while (! quitMessagePosted)
  210100. {
  210101. const ScopedAutoReleasePool pool2;
  210102. CFRunLoopRunInMode (kCFRunLoopDefaultMode, 0.001, true);
  210103. NSEvent* e = [NSApp nextEventMatchingMask: NSAnyEventMask
  210104. untilDate: [NSDate dateWithTimeIntervalSinceNow: 0.001]
  210105. inMode: NSDefaultRunLoopMode
  210106. dequeue: YES];
  210107. if (e != 0 && ! isEventBlockedByModalComps (e))
  210108. [NSApp sendEvent: e];
  210109. if (Time::getMillisecondCounter() >= endTime)
  210110. break;
  210111. }
  210112. return ! quitMessagePosted;
  210113. }
  210114. void MessageManager::doPlatformSpecificInitialisation()
  210115. {
  210116. if (juceAppDelegate == 0)
  210117. juceAppDelegate = [[JuceAppDelegate alloc] init];
  210118. // This launches a dummy thread, which forces Cocoa to initialise NSThreads
  210119. // correctly (needed prior to 10.5)
  210120. if (! [NSThread isMultiThreaded])
  210121. [NSThread detachNewThreadSelector: @selector (dummyMethod)
  210122. toTarget: juceAppDelegate
  210123. withObject: nil];
  210124. initialiseMainMenu();
  210125. }
  210126. void MessageManager::doPlatformSpecificShutdown()
  210127. {
  210128. if (juceAppDelegate != 0)
  210129. {
  210130. [[NSRunLoop currentRunLoop] cancelPerformSelectorsWithTarget: juceAppDelegate];
  210131. [[NSNotificationCenter defaultCenter] removeObserver: juceAppDelegate];
  210132. [juceAppDelegate release];
  210133. juceAppDelegate = 0;
  210134. }
  210135. }
  210136. bool juce_postMessageToSystemQueue (void* message)
  210137. {
  210138. juceAppDelegate->redirector->postMessage (message);
  210139. return true;
  210140. }
  210141. void MessageManager::broadcastMessage (const String& value) throw()
  210142. {
  210143. }
  210144. void* MessageManager::callFunctionOnMessageThread (MessageCallbackFunction* callback,
  210145. void* data)
  210146. {
  210147. if (isThisTheMessageThread())
  210148. {
  210149. return (*callback) (data);
  210150. }
  210151. else
  210152. {
  210153. // If a thread has a MessageManagerLock and then tries to call this method, it'll
  210154. // deadlock because the message manager is blocked from running, so can never
  210155. // call your function..
  210156. jassert (! MessageManager::getInstance()->currentThreadHasLockedMessageManager());
  210157. const ScopedAutoReleasePool pool;
  210158. AppDelegateRedirector::CallbackMessagePayload cmp;
  210159. cmp.function = callback;
  210160. cmp.parameter = data;
  210161. cmp.result = 0;
  210162. cmp.hasBeenExecuted = false;
  210163. [juceAppDelegate performSelectorOnMainThread: @selector (performCallback:)
  210164. withObject: [NSData dataWithBytesNoCopy: &cmp
  210165. length: sizeof (cmp)
  210166. freeWhenDone: NO]
  210167. waitUntilDone: YES];
  210168. return cmp.result;
  210169. }
  210170. }
  210171. #endif
  210172. /*** End of inlined file: juce_mac_MessageManager.mm ***/
  210173. /*** Start of inlined file: juce_mac_WebBrowserComponent.mm ***/
  210174. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  210175. // compiled on its own).
  210176. #if JUCE_INCLUDED_FILE && JUCE_WEB_BROWSER
  210177. #if JUCE_MAC
  210178. END_JUCE_NAMESPACE
  210179. #define DownloadClickDetector MakeObjCClassName(DownloadClickDetector)
  210180. @interface DownloadClickDetector : NSObject
  210181. {
  210182. JUCE_NAMESPACE::WebBrowserComponent* ownerComponent;
  210183. }
  210184. - (DownloadClickDetector*) initWithWebBrowserOwner: (JUCE_NAMESPACE::WebBrowserComponent*) ownerComponent;
  210185. - (void) webView: (WebView*) webView decidePolicyForNavigationAction: (NSDictionary*) actionInformation
  210186. request: (NSURLRequest*) request
  210187. frame: (WebFrame*) frame
  210188. decisionListener: (id<WebPolicyDecisionListener>) listener;
  210189. @end
  210190. @implementation DownloadClickDetector
  210191. - (DownloadClickDetector*) initWithWebBrowserOwner: (JUCE_NAMESPACE::WebBrowserComponent*) ownerComponent_
  210192. {
  210193. [super init];
  210194. ownerComponent = ownerComponent_;
  210195. return self;
  210196. }
  210197. - (void) webView: (WebView*) sender decidePolicyForNavigationAction: (NSDictionary*) actionInformation
  210198. request: (NSURLRequest*) request
  210199. frame: (WebFrame*) frame
  210200. decisionListener: (id <WebPolicyDecisionListener>) listener
  210201. {
  210202. NSURL* url = [actionInformation valueForKey: @"WebActionOriginalURLKey"];
  210203. if (ownerComponent->pageAboutToLoad (nsStringToJuce ([url absoluteString])))
  210204. [listener use];
  210205. else
  210206. [listener ignore];
  210207. }
  210208. @end
  210209. BEGIN_JUCE_NAMESPACE
  210210. class WebBrowserComponentInternal : public NSViewComponent
  210211. {
  210212. public:
  210213. WebBrowserComponentInternal (WebBrowserComponent* owner)
  210214. {
  210215. webView = [[WebView alloc] initWithFrame: NSMakeRect (0, 0, 100.0f, 100.0f)
  210216. frameName: @""
  210217. groupName: @""];
  210218. setView (webView);
  210219. clickListener = [[DownloadClickDetector alloc] initWithWebBrowserOwner: owner];
  210220. [webView setPolicyDelegate: clickListener];
  210221. }
  210222. ~WebBrowserComponentInternal()
  210223. {
  210224. [webView setPolicyDelegate: nil];
  210225. [clickListener release];
  210226. setView (0);
  210227. }
  210228. void goToURL (const String& url,
  210229. const StringArray* headers,
  210230. const MemoryBlock* postData)
  210231. {
  210232. NSMutableURLRequest* r
  210233. = [NSMutableURLRequest requestWithURL: [NSURL URLWithString: juceStringToNS (url)]
  210234. cachePolicy: NSURLRequestUseProtocolCachePolicy
  210235. timeoutInterval: 30.0];
  210236. if (postData != 0 && postData->getSize() > 0)
  210237. {
  210238. [r setHTTPMethod: @"POST"];
  210239. [r setHTTPBody: [NSData dataWithBytes: postData->getData()
  210240. length: postData->getSize()]];
  210241. }
  210242. if (headers != 0)
  210243. {
  210244. for (int i = 0; i < headers->size(); ++i)
  210245. {
  210246. const String headerName ((*headers)[i].upToFirstOccurrenceOf (T(":"), false, false).trim());
  210247. const String headerValue ((*headers)[i].fromFirstOccurrenceOf (T(":"), false, false).trim());
  210248. [r setValue: juceStringToNS (headerValue)
  210249. forHTTPHeaderField: juceStringToNS (headerName)];
  210250. }
  210251. }
  210252. stop();
  210253. [[webView mainFrame] loadRequest: r];
  210254. }
  210255. void goBack()
  210256. {
  210257. [webView goBack];
  210258. }
  210259. void goForward()
  210260. {
  210261. [webView goForward];
  210262. }
  210263. void stop()
  210264. {
  210265. [webView stopLoading: nil];
  210266. }
  210267. void refresh()
  210268. {
  210269. [webView reload: nil];
  210270. }
  210271. private:
  210272. WebView* webView;
  210273. DownloadClickDetector* clickListener;
  210274. };
  210275. WebBrowserComponent::WebBrowserComponent (const bool unloadPageWhenBrowserIsHidden_)
  210276. : browser (0),
  210277. blankPageShown (false),
  210278. unloadPageWhenBrowserIsHidden (unloadPageWhenBrowserIsHidden_)
  210279. {
  210280. setOpaque (true);
  210281. addAndMakeVisible (browser = new WebBrowserComponentInternal (this));
  210282. }
  210283. WebBrowserComponent::~WebBrowserComponent()
  210284. {
  210285. deleteAndZero (browser);
  210286. }
  210287. void WebBrowserComponent::goToURL (const String& url,
  210288. const StringArray* headers,
  210289. const MemoryBlock* postData)
  210290. {
  210291. lastURL = url;
  210292. lastHeaders.clear();
  210293. if (headers != 0)
  210294. lastHeaders = *headers;
  210295. lastPostData.setSize (0);
  210296. if (postData != 0)
  210297. lastPostData = *postData;
  210298. blankPageShown = false;
  210299. browser->goToURL (url, headers, postData);
  210300. }
  210301. void WebBrowserComponent::stop()
  210302. {
  210303. browser->stop();
  210304. }
  210305. void WebBrowserComponent::goBack()
  210306. {
  210307. lastURL = String::empty;
  210308. blankPageShown = false;
  210309. browser->goBack();
  210310. }
  210311. void WebBrowserComponent::goForward()
  210312. {
  210313. lastURL = String::empty;
  210314. browser->goForward();
  210315. }
  210316. void WebBrowserComponent::refresh()
  210317. {
  210318. browser->refresh();
  210319. }
  210320. void WebBrowserComponent::paint (Graphics& g)
  210321. {
  210322. }
  210323. void WebBrowserComponent::checkWindowAssociation()
  210324. {
  210325. if (isShowing())
  210326. {
  210327. if (blankPageShown)
  210328. goBack();
  210329. }
  210330. else
  210331. {
  210332. if (unloadPageWhenBrowserIsHidden && ! blankPageShown)
  210333. {
  210334. // when the component becomes invisible, some stuff like flash
  210335. // carries on playing audio, so we need to force it onto a blank
  210336. // page to avoid this, (and send it back when it's made visible again).
  210337. blankPageShown = true;
  210338. browser->goToURL ("about:blank", 0, 0);
  210339. }
  210340. }
  210341. }
  210342. void WebBrowserComponent::reloadLastURL()
  210343. {
  210344. if (lastURL.isNotEmpty())
  210345. {
  210346. goToURL (lastURL, &lastHeaders, &lastPostData);
  210347. lastURL = String::empty;
  210348. }
  210349. }
  210350. void WebBrowserComponent::parentHierarchyChanged()
  210351. {
  210352. checkWindowAssociation();
  210353. }
  210354. void WebBrowserComponent::resized()
  210355. {
  210356. browser->setSize (getWidth(), getHeight());
  210357. }
  210358. void WebBrowserComponent::visibilityChanged()
  210359. {
  210360. checkWindowAssociation();
  210361. }
  210362. bool WebBrowserComponent::pageAboutToLoad (const String& url)
  210363. {
  210364. return true;
  210365. }
  210366. #else
  210367. WebBrowserComponent::WebBrowserComponent (const bool unloadPageWhenBrowserIsHidden_)
  210368. {
  210369. }
  210370. WebBrowserComponent::~WebBrowserComponent()
  210371. {
  210372. }
  210373. void WebBrowserComponent::goToURL (const String& url,
  210374. const StringArray* headers,
  210375. const MemoryBlock* postData)
  210376. {
  210377. }
  210378. void WebBrowserComponent::stop()
  210379. {
  210380. }
  210381. void WebBrowserComponent::goBack()
  210382. {
  210383. }
  210384. void WebBrowserComponent::goForward()
  210385. {
  210386. }
  210387. void WebBrowserComponent::refresh()
  210388. {
  210389. }
  210390. void WebBrowserComponent::paint (Graphics& g)
  210391. {
  210392. }
  210393. void WebBrowserComponent::checkWindowAssociation()
  210394. {
  210395. }
  210396. void WebBrowserComponent::reloadLastURL()
  210397. {
  210398. }
  210399. void WebBrowserComponent::parentHierarchyChanged()
  210400. {
  210401. }
  210402. void WebBrowserComponent::resized()
  210403. {
  210404. }
  210405. void WebBrowserComponent::visibilityChanged()
  210406. {
  210407. }
  210408. bool WebBrowserComponent::pageAboutToLoad (const String& url)
  210409. {
  210410. return true;
  210411. }
  210412. #endif
  210413. #endif
  210414. /*** End of inlined file: juce_mac_WebBrowserComponent.mm ***/
  210415. /*** Start of inlined file: juce_mac_CoreAudio.cpp ***/
  210416. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  210417. // compiled on its own).
  210418. #if JUCE_INCLUDED_FILE
  210419. #ifndef JUCE_COREAUDIO_ERROR_LOGGING_ENABLED
  210420. #define JUCE_COREAUDIO_ERROR_LOGGING_ENABLED 1
  210421. #endif
  210422. #undef log
  210423. #if JUCE_COREAUDIO_LOGGING_ENABLED
  210424. #define log(a) Logger::writeToLog (a)
  210425. #else
  210426. #define log(a)
  210427. #endif
  210428. #undef OK
  210429. #if JUCE_COREAUDIO_ERROR_LOGGING_ENABLED
  210430. static bool logAnyErrors_CoreAudio (const OSStatus err, const int lineNum)
  210431. {
  210432. if (err == noErr)
  210433. return true;
  210434. Logger::writeToLog (T("CoreAudio error: ") + String (lineNum) + T(" - ") + String::toHexString ((int)err));
  210435. jassertfalse
  210436. return false;
  210437. }
  210438. #define OK(a) logAnyErrors_CoreAudio (a, __LINE__)
  210439. #else
  210440. #define OK(a) (a == noErr)
  210441. #endif
  210442. class CoreAudioInternal : public Timer
  210443. {
  210444. public:
  210445. CoreAudioInternal (AudioDeviceID id)
  210446. : inputLatency (0),
  210447. outputLatency (0),
  210448. callback (0),
  210449. #if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5
  210450. audioProcID (0),
  210451. #endif
  210452. inputDevice (0),
  210453. isSlaveDevice (false),
  210454. deviceID (id),
  210455. started (false),
  210456. sampleRate (0),
  210457. bufferSize (512),
  210458. numInputChans (0),
  210459. numOutputChans (0),
  210460. callbacksAllowed (true),
  210461. numInputChannelInfos (0),
  210462. numOutputChannelInfos (0)
  210463. {
  210464. jassert (deviceID != 0);
  210465. updateDetailsFromDevice();
  210466. AudioObjectPropertyAddress pa;
  210467. pa.mSelector = kAudioObjectPropertySelectorWildcard;
  210468. pa.mScope = kAudioObjectPropertyScopeWildcard;
  210469. pa.mElement = kAudioObjectPropertyElementWildcard;
  210470. AudioObjectAddPropertyListener (deviceID, &pa, deviceListenerProc, this);
  210471. }
  210472. ~CoreAudioInternal()
  210473. {
  210474. AudioObjectPropertyAddress pa;
  210475. pa.mSelector = kAudioObjectPropertySelectorWildcard;
  210476. pa.mScope = kAudioObjectPropertyScopeWildcard;
  210477. pa.mElement = kAudioObjectPropertyElementWildcard;
  210478. AudioObjectRemovePropertyListener (deviceID, &pa, deviceListenerProc, this);
  210479. stop (false);
  210480. delete inputDevice;
  210481. }
  210482. void allocateTempBuffers()
  210483. {
  210484. const int tempBufSize = bufferSize + 4;
  210485. audioBuffer.calloc ((numInputChans + numOutputChans) * tempBufSize);
  210486. tempInputBuffers.calloc (numInputChans + 2);
  210487. tempOutputBuffers.calloc (numOutputChans + 2);
  210488. int i, count = 0;
  210489. for (i = 0; i < numInputChans; ++i)
  210490. tempInputBuffers[i] = audioBuffer + count++ * tempBufSize;
  210491. for (i = 0; i < numOutputChans; ++i)
  210492. tempOutputBuffers[i] = audioBuffer + count++ * tempBufSize;
  210493. }
  210494. // returns the number of actual available channels
  210495. void fillInChannelInfo (const bool input)
  210496. {
  210497. int chanNum = 0;
  210498. UInt32 size;
  210499. AudioObjectPropertyAddress pa;
  210500. pa.mSelector = kAudioDevicePropertyStreamConfiguration;
  210501. pa.mScope = input ? kAudioDevicePropertyScopeInput : kAudioDevicePropertyScopeOutput;
  210502. pa.mElement = kAudioObjectPropertyElementMaster;
  210503. if (OK (AudioObjectGetPropertyDataSize (deviceID, &pa, 0, 0, &size)))
  210504. {
  210505. HeapBlock <AudioBufferList> bufList;
  210506. bufList.calloc (size, 1);
  210507. if (OK (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, bufList)))
  210508. {
  210509. const int numStreams = bufList->mNumberBuffers;
  210510. for (int i = 0; i < numStreams; ++i)
  210511. {
  210512. const AudioBuffer& b = bufList->mBuffers[i];
  210513. for (unsigned int j = 0; j < b.mNumberChannels; ++j)
  210514. {
  210515. String name;
  210516. {
  210517. char channelName [256];
  210518. zerostruct (channelName);
  210519. UInt32 nameSize = sizeof (channelName);
  210520. UInt32 channelNum = chanNum + 1;
  210521. pa.mSelector = kAudioDevicePropertyChannelName;
  210522. if (AudioObjectGetPropertyData (deviceID, &pa, sizeof (channelNum), &channelNum, &nameSize, channelName) == noErr)
  210523. name = String::fromUTF8 (channelName, nameSize);
  210524. }
  210525. if (input)
  210526. {
  210527. if (activeInputChans[chanNum])
  210528. {
  210529. inputChannelInfo [numInputChannelInfos].streamNum = i;
  210530. inputChannelInfo [numInputChannelInfos].dataOffsetSamples = j;
  210531. inputChannelInfo [numInputChannelInfos].dataStrideSamples = b.mNumberChannels;
  210532. ++numInputChannelInfos;
  210533. }
  210534. if (name.isEmpty())
  210535. name << "Input " << (chanNum + 1);
  210536. inChanNames.add (name);
  210537. }
  210538. else
  210539. {
  210540. if (activeOutputChans[chanNum])
  210541. {
  210542. outputChannelInfo [numOutputChannelInfos].streamNum = i;
  210543. outputChannelInfo [numOutputChannelInfos].dataOffsetSamples = j;
  210544. outputChannelInfo [numOutputChannelInfos].dataStrideSamples = b.mNumberChannels;
  210545. ++numOutputChannelInfos;
  210546. }
  210547. if (name.isEmpty())
  210548. name << "Output " << (chanNum + 1);
  210549. outChanNames.add (name);
  210550. }
  210551. ++chanNum;
  210552. }
  210553. }
  210554. }
  210555. }
  210556. }
  210557. void updateDetailsFromDevice()
  210558. {
  210559. stopTimer();
  210560. if (deviceID == 0)
  210561. return;
  210562. const ScopedLock sl (callbackLock);
  210563. Float64 sr;
  210564. UInt32 size = sizeof (Float64);
  210565. AudioObjectPropertyAddress pa;
  210566. pa.mSelector = kAudioDevicePropertyNominalSampleRate;
  210567. pa.mScope = kAudioObjectPropertyScopeWildcard;
  210568. pa.mElement = kAudioObjectPropertyElementMaster;
  210569. if (OK (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, &sr)))
  210570. sampleRate = sr;
  210571. UInt32 framesPerBuf;
  210572. size = sizeof (framesPerBuf);
  210573. pa.mSelector = kAudioDevicePropertyBufferFrameSize;
  210574. if (OK (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, &framesPerBuf)))
  210575. {
  210576. bufferSize = framesPerBuf;
  210577. allocateTempBuffers();
  210578. }
  210579. bufferSizes.clear();
  210580. pa.mSelector = kAudioDevicePropertyBufferFrameSizeRange;
  210581. if (OK (AudioObjectGetPropertyDataSize (deviceID, &pa, 0, 0, &size)))
  210582. {
  210583. HeapBlock <AudioValueRange> ranges;
  210584. ranges.calloc (size, 1);
  210585. if (OK (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, ranges)))
  210586. {
  210587. bufferSizes.add ((int) ranges[0].mMinimum);
  210588. for (int i = 32; i < 2048; i += 32)
  210589. {
  210590. for (int j = size / (int) sizeof (AudioValueRange); --j >= 0;)
  210591. {
  210592. if (i >= ranges[j].mMinimum && i <= ranges[j].mMaximum)
  210593. {
  210594. bufferSizes.addIfNotAlreadyThere (i);
  210595. break;
  210596. }
  210597. }
  210598. }
  210599. if (bufferSize > 0)
  210600. bufferSizes.addIfNotAlreadyThere (bufferSize);
  210601. }
  210602. }
  210603. if (bufferSizes.size() == 0 && bufferSize > 0)
  210604. bufferSizes.add (bufferSize);
  210605. sampleRates.clear();
  210606. const double possibleRates[] = { 44100.0, 48000.0, 88200.0, 96000.0, 176400.0, 192000.0 };
  210607. String rates;
  210608. pa.mSelector = kAudioDevicePropertyAvailableNominalSampleRates;
  210609. if (OK (AudioObjectGetPropertyDataSize (deviceID, &pa, 0, 0, &size)))
  210610. {
  210611. HeapBlock <AudioValueRange> ranges;
  210612. ranges.calloc (size, 1);
  210613. if (OK (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, ranges)))
  210614. {
  210615. for (int i = 0; i < numElementsInArray (possibleRates); ++i)
  210616. {
  210617. bool ok = false;
  210618. for (int j = size / (int) sizeof (AudioValueRange); --j >= 0;)
  210619. if (possibleRates[i] >= ranges[j].mMinimum - 2 && possibleRates[i] <= ranges[j].mMaximum + 2)
  210620. ok = true;
  210621. if (ok)
  210622. {
  210623. sampleRates.add (possibleRates[i]);
  210624. rates << possibleRates[i] << T(" ");
  210625. }
  210626. }
  210627. }
  210628. }
  210629. if (sampleRates.size() == 0 && sampleRate > 0)
  210630. {
  210631. sampleRates.add (sampleRate);
  210632. rates << sampleRate;
  210633. }
  210634. log (T("sr: ") + rates);
  210635. inputLatency = 0;
  210636. outputLatency = 0;
  210637. UInt32 lat;
  210638. size = sizeof (lat);
  210639. pa.mSelector = kAudioDevicePropertyLatency;
  210640. pa.mScope = kAudioDevicePropertyScopeInput;
  210641. //if (AudioDeviceGetProperty (deviceID, 0, true, kAudioDevicePropertyLatency, &size, &lat) == noErr)
  210642. if (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, &lat) == noErr)
  210643. inputLatency = (int) lat;
  210644. pa.mScope = kAudioDevicePropertyScopeOutput;
  210645. size = sizeof (lat);
  210646. if (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, &lat) == noErr)
  210647. outputLatency = (int) lat;
  210648. log (T("lat: ") + String (inputLatency) + T(" ") + String (outputLatency));
  210649. inChanNames.clear();
  210650. outChanNames.clear();
  210651. inputChannelInfo.calloc (numInputChans + 2);
  210652. numInputChannelInfos = 0;
  210653. outputChannelInfo.calloc (numOutputChans + 2);
  210654. numOutputChannelInfos = 0;
  210655. fillInChannelInfo (true);
  210656. fillInChannelInfo (false);
  210657. }
  210658. const StringArray getSources (bool input)
  210659. {
  210660. StringArray s;
  210661. HeapBlock <OSType> types;
  210662. const int num = getAllDataSourcesForDevice (deviceID, input, types);
  210663. for (int i = 0; i < num; ++i)
  210664. {
  210665. AudioValueTranslation avt;
  210666. char buffer[256];
  210667. avt.mInputData = (void*) &(types[i]);
  210668. avt.mInputDataSize = sizeof (UInt32);
  210669. avt.mOutputData = buffer;
  210670. avt.mOutputDataSize = 256;
  210671. UInt32 transSize = sizeof (avt);
  210672. AudioObjectPropertyAddress pa;
  210673. pa.mSelector = kAudioDevicePropertyDataSourceNameForID;
  210674. pa.mScope = input ? kAudioDevicePropertyScopeInput : kAudioDevicePropertyScopeOutput;
  210675. pa.mElement = kAudioObjectPropertyElementMaster;
  210676. if (OK (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &transSize, &avt)))
  210677. {
  210678. DBG (buffer);
  210679. s.add (buffer);
  210680. }
  210681. }
  210682. return s;
  210683. }
  210684. int getCurrentSourceIndex (bool input) const
  210685. {
  210686. OSType currentSourceID = 0;
  210687. UInt32 size = sizeof (currentSourceID);
  210688. int result = -1;
  210689. AudioObjectPropertyAddress pa;
  210690. pa.mSelector = kAudioDevicePropertyDataSource;
  210691. pa.mScope = input ? kAudioDevicePropertyScopeInput : kAudioDevicePropertyScopeOutput;
  210692. pa.mElement = kAudioObjectPropertyElementMaster;
  210693. if (deviceID != 0)
  210694. {
  210695. if (OK (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, &currentSourceID)))
  210696. {
  210697. HeapBlock <OSType> types;
  210698. const int num = getAllDataSourcesForDevice (deviceID, input, types);
  210699. for (int i = 0; i < num; ++i)
  210700. {
  210701. if (types[num] == currentSourceID)
  210702. {
  210703. result = i;
  210704. break;
  210705. }
  210706. }
  210707. }
  210708. }
  210709. return result;
  210710. }
  210711. void setCurrentSourceIndex (int index, bool input)
  210712. {
  210713. if (deviceID != 0)
  210714. {
  210715. HeapBlock <OSType> types;
  210716. const int num = getAllDataSourcesForDevice (deviceID, input, types);
  210717. if (((unsigned int) index) < (unsigned int) num)
  210718. {
  210719. AudioObjectPropertyAddress pa;
  210720. pa.mSelector = kAudioDevicePropertyDataSource;
  210721. pa.mScope = input ? kAudioDevicePropertyScopeInput : kAudioDevicePropertyScopeOutput;
  210722. pa.mElement = kAudioObjectPropertyElementMaster;
  210723. OSType typeId = types[index];
  210724. OK (AudioObjectSetPropertyData (deviceID, &pa, 0, 0, sizeof (typeId), &typeId));
  210725. }
  210726. }
  210727. }
  210728. const String reopen (const BigInteger& inputChannels,
  210729. const BigInteger& outputChannels,
  210730. double newSampleRate,
  210731. int bufferSizeSamples)
  210732. {
  210733. String error;
  210734. log ("CoreAudio reopen");
  210735. callbacksAllowed = false;
  210736. stopTimer();
  210737. stop (false);
  210738. activeInputChans = inputChannels;
  210739. activeInputChans.setRange (inChanNames.size(),
  210740. activeInputChans.getHighestBit() + 1 - inChanNames.size(),
  210741. false);
  210742. activeOutputChans = outputChannels;
  210743. activeOutputChans.setRange (outChanNames.size(),
  210744. activeOutputChans.getHighestBit() + 1 - outChanNames.size(),
  210745. false);
  210746. numInputChans = activeInputChans.countNumberOfSetBits();
  210747. numOutputChans = activeOutputChans.countNumberOfSetBits();
  210748. // set sample rate
  210749. AudioObjectPropertyAddress pa;
  210750. pa.mSelector = kAudioDevicePropertyNominalSampleRate;
  210751. pa.mScope = kAudioObjectPropertyScopeWildcard;
  210752. pa.mElement = kAudioObjectPropertyElementMaster;
  210753. Float64 sr = newSampleRate;
  210754. if (! OK (AudioObjectSetPropertyData (deviceID, &pa, 0, 0, sizeof (sr), &sr)))
  210755. {
  210756. error = "Couldn't change sample rate";
  210757. }
  210758. else
  210759. {
  210760. // change buffer size
  210761. UInt32 framesPerBuf = bufferSizeSamples;
  210762. pa.mSelector = kAudioDevicePropertyBufferFrameSize;
  210763. if (! OK (AudioObjectSetPropertyData (deviceID, &pa, 0, 0, sizeof (framesPerBuf), &framesPerBuf)))
  210764. {
  210765. error = "Couldn't change buffer size";
  210766. }
  210767. else
  210768. {
  210769. // Annoyingly, after changing the rate and buffer size, some devices fail to
  210770. // correctly report their new settings until some random time in the future, so
  210771. // after calling updateDetailsFromDevice, we need to manually bodge these values
  210772. // to make sure we're using the correct numbers..
  210773. updateDetailsFromDevice();
  210774. sampleRate = newSampleRate;
  210775. bufferSize = bufferSizeSamples;
  210776. if (sampleRates.size() == 0)
  210777. error = "Device has no available sample-rates";
  210778. else if (bufferSizes.size() == 0)
  210779. error = "Device has no available buffer-sizes";
  210780. else if (inputDevice != 0)
  210781. error = inputDevice->reopen (inputChannels,
  210782. outputChannels,
  210783. newSampleRate,
  210784. bufferSizeSamples);
  210785. }
  210786. }
  210787. callbacksAllowed = true;
  210788. return error;
  210789. }
  210790. bool start (AudioIODeviceCallback* cb)
  210791. {
  210792. if (! started)
  210793. {
  210794. callback = 0;
  210795. if (deviceID != 0)
  210796. {
  210797. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  210798. if (OK (AudioDeviceAddIOProc (deviceID, audioIOProc, (void*) this)))
  210799. #else
  210800. if (OK (AudioDeviceCreateIOProcID (deviceID, audioIOProc, (void*) this, &audioProcID)))
  210801. #endif
  210802. {
  210803. if (OK (AudioDeviceStart (deviceID, audioIOProc)))
  210804. {
  210805. started = true;
  210806. }
  210807. else
  210808. {
  210809. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  210810. OK (AudioDeviceRemoveIOProc (deviceID, audioIOProc));
  210811. #else
  210812. OK (AudioDeviceDestroyIOProcID (deviceID, audioProcID));
  210813. audioProcID = 0;
  210814. #endif
  210815. }
  210816. }
  210817. }
  210818. }
  210819. if (started)
  210820. {
  210821. const ScopedLock sl (callbackLock);
  210822. callback = cb;
  210823. }
  210824. if (inputDevice != 0)
  210825. return started && inputDevice->start (cb);
  210826. else
  210827. return started;
  210828. }
  210829. void stop (bool leaveInterruptRunning)
  210830. {
  210831. {
  210832. const ScopedLock sl (callbackLock);
  210833. callback = 0;
  210834. }
  210835. if (started
  210836. && (deviceID != 0)
  210837. && ! leaveInterruptRunning)
  210838. {
  210839. OK (AudioDeviceStop (deviceID, audioIOProc));
  210840. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  210841. OK (AudioDeviceRemoveIOProc (deviceID, audioIOProc));
  210842. #else
  210843. OK (AudioDeviceDestroyIOProcID (deviceID, audioProcID));
  210844. audioProcID = 0;
  210845. #endif
  210846. started = false;
  210847. { const ScopedLock sl (callbackLock); }
  210848. // wait until it's definately stopped calling back..
  210849. for (int i = 40; --i >= 0;)
  210850. {
  210851. Thread::sleep (50);
  210852. UInt32 running = 0;
  210853. UInt32 size = sizeof (running);
  210854. AudioObjectPropertyAddress pa;
  210855. pa.mSelector = kAudioDevicePropertyDeviceIsRunning;
  210856. pa.mScope = kAudioObjectPropertyScopeWildcard;
  210857. pa.mElement = kAudioObjectPropertyElementMaster;
  210858. OK (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, &running));
  210859. if (running == 0)
  210860. break;
  210861. }
  210862. const ScopedLock sl (callbackLock);
  210863. }
  210864. if (inputDevice != 0)
  210865. inputDevice->stop (leaveInterruptRunning);
  210866. }
  210867. double getSampleRate() const
  210868. {
  210869. return sampleRate;
  210870. }
  210871. int getBufferSize() const
  210872. {
  210873. return bufferSize;
  210874. }
  210875. void audioCallback (const AudioBufferList* inInputData,
  210876. AudioBufferList* outOutputData)
  210877. {
  210878. int i;
  210879. const ScopedLock sl (callbackLock);
  210880. if (callback != 0)
  210881. {
  210882. if (inputDevice == 0)
  210883. {
  210884. for (i = numInputChans; --i >= 0;)
  210885. {
  210886. const CallbackDetailsForChannel& info = inputChannelInfo[i];
  210887. float* dest = tempInputBuffers [i];
  210888. const float* src = ((const float*) inInputData->mBuffers[info.streamNum].mData)
  210889. + info.dataOffsetSamples;
  210890. const int stride = info.dataStrideSamples;
  210891. if (stride != 0) // if this is zero, info is invalid
  210892. {
  210893. for (int j = bufferSize; --j >= 0;)
  210894. {
  210895. *dest++ = *src;
  210896. src += stride;
  210897. }
  210898. }
  210899. }
  210900. }
  210901. if (! isSlaveDevice)
  210902. {
  210903. if (inputDevice == 0)
  210904. {
  210905. callback->audioDeviceIOCallback (const_cast<const float**> (tempInputBuffers.getData()),
  210906. numInputChans,
  210907. tempOutputBuffers,
  210908. numOutputChans,
  210909. bufferSize);
  210910. }
  210911. else
  210912. {
  210913. jassert (inputDevice->bufferSize == bufferSize);
  210914. // Sometimes the two linked devices seem to get their callbacks in
  210915. // parallel, so we need to lock both devices to stop the input data being
  210916. // changed while inside our callback..
  210917. const ScopedLock sl2 (inputDevice->callbackLock);
  210918. callback->audioDeviceIOCallback (const_cast<const float**> (inputDevice->tempInputBuffers.getData()),
  210919. inputDevice->numInputChans,
  210920. tempOutputBuffers,
  210921. numOutputChans,
  210922. bufferSize);
  210923. }
  210924. for (i = numOutputChans; --i >= 0;)
  210925. {
  210926. const CallbackDetailsForChannel& info = outputChannelInfo[i];
  210927. const float* src = tempOutputBuffers [i];
  210928. float* dest = ((float*) outOutputData->mBuffers[info.streamNum].mData)
  210929. + info.dataOffsetSamples;
  210930. const int stride = info.dataStrideSamples;
  210931. if (stride != 0) // if this is zero, info is invalid
  210932. {
  210933. for (int j = bufferSize; --j >= 0;)
  210934. {
  210935. *dest = *src++;
  210936. dest += stride;
  210937. }
  210938. }
  210939. }
  210940. }
  210941. }
  210942. else
  210943. {
  210944. for (i = jmin (numOutputChans, numOutputChannelInfos); --i >= 0;)
  210945. {
  210946. const CallbackDetailsForChannel& info = outputChannelInfo[i];
  210947. float* dest = ((float*) outOutputData->mBuffers[info.streamNum].mData)
  210948. + info.dataOffsetSamples;
  210949. const int stride = info.dataStrideSamples;
  210950. if (stride != 0) // if this is zero, info is invalid
  210951. {
  210952. for (int j = bufferSize; --j >= 0;)
  210953. {
  210954. *dest = 0.0f;
  210955. dest += stride;
  210956. }
  210957. }
  210958. }
  210959. }
  210960. }
  210961. // called by callbacks
  210962. void deviceDetailsChanged()
  210963. {
  210964. if (callbacksAllowed)
  210965. startTimer (100);
  210966. }
  210967. void timerCallback()
  210968. {
  210969. stopTimer();
  210970. log ("CoreAudio device changed callback");
  210971. const double oldSampleRate = sampleRate;
  210972. const int oldBufferSize = bufferSize;
  210973. updateDetailsFromDevice();
  210974. if (oldBufferSize != bufferSize || oldSampleRate != sampleRate)
  210975. {
  210976. callbacksAllowed = false;
  210977. stop (false);
  210978. updateDetailsFromDevice();
  210979. callbacksAllowed = true;
  210980. }
  210981. }
  210982. CoreAudioInternal* getRelatedDevice() const
  210983. {
  210984. UInt32 size = 0;
  210985. ScopedPointer <CoreAudioInternal> result;
  210986. AudioObjectPropertyAddress pa;
  210987. pa.mSelector = kAudioDevicePropertyRelatedDevices;
  210988. pa.mScope = kAudioObjectPropertyScopeWildcard;
  210989. pa.mElement = kAudioObjectPropertyElementMaster;
  210990. if (deviceID != 0
  210991. && AudioObjectGetPropertyDataSize (deviceID, &pa, 0, 0, &size) == noErr
  210992. && size > 0)
  210993. {
  210994. HeapBlock <AudioDeviceID> devs;
  210995. devs.calloc (size, 1);
  210996. if (OK (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, devs)))
  210997. {
  210998. for (unsigned int i = 0; i < size / sizeof (AudioDeviceID); ++i)
  210999. {
  211000. if (devs[i] != deviceID && devs[i] != 0)
  211001. {
  211002. result = new CoreAudioInternal (devs[i]);
  211003. const bool thisIsInput = inChanNames.size() > 0 && outChanNames.size() == 0;
  211004. const bool otherIsInput = result->inChanNames.size() > 0 && result->outChanNames.size() == 0;
  211005. if (thisIsInput != otherIsInput
  211006. || (inChanNames.size() + outChanNames.size() == 0)
  211007. || (result->inChanNames.size() + result->outChanNames.size()) == 0)
  211008. break;
  211009. result = 0;
  211010. }
  211011. }
  211012. }
  211013. }
  211014. return result.release();
  211015. }
  211016. juce_UseDebuggingNewOperator
  211017. int inputLatency, outputLatency;
  211018. BigInteger activeInputChans, activeOutputChans;
  211019. StringArray inChanNames, outChanNames;
  211020. Array <double> sampleRates;
  211021. Array <int> bufferSizes;
  211022. AudioIODeviceCallback* callback;
  211023. #if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5
  211024. AudioDeviceIOProcID audioProcID;
  211025. #endif
  211026. CoreAudioInternal* inputDevice;
  211027. bool isSlaveDevice;
  211028. private:
  211029. CriticalSection callbackLock;
  211030. AudioDeviceID deviceID;
  211031. bool started;
  211032. double sampleRate;
  211033. int bufferSize;
  211034. HeapBlock <float> audioBuffer;
  211035. int numInputChans, numOutputChans;
  211036. bool callbacksAllowed;
  211037. struct CallbackDetailsForChannel
  211038. {
  211039. int streamNum;
  211040. int dataOffsetSamples;
  211041. int dataStrideSamples;
  211042. };
  211043. int numInputChannelInfos, numOutputChannelInfos;
  211044. HeapBlock <CallbackDetailsForChannel> inputChannelInfo, outputChannelInfo;
  211045. HeapBlock <float*> tempInputBuffers, tempOutputBuffers;
  211046. CoreAudioInternal (const CoreAudioInternal&);
  211047. CoreAudioInternal& operator= (const CoreAudioInternal&);
  211048. static OSStatus audioIOProc (AudioDeviceID inDevice,
  211049. const AudioTimeStamp* inNow,
  211050. const AudioBufferList* inInputData,
  211051. const AudioTimeStamp* inInputTime,
  211052. AudioBufferList* outOutputData,
  211053. const AudioTimeStamp* inOutputTime,
  211054. void* device)
  211055. {
  211056. ((CoreAudioInternal*) device)->audioCallback (inInputData, outOutputData);
  211057. return noErr;
  211058. }
  211059. static OSStatus deviceListenerProc (AudioDeviceID /*inDevice*/, UInt32 /*inLine*/, const AudioObjectPropertyAddress* pa, void* inClientData)
  211060. {
  211061. CoreAudioInternal* const intern = (CoreAudioInternal*) inClientData;
  211062. switch (pa->mSelector)
  211063. {
  211064. case kAudioDevicePropertyBufferSize:
  211065. case kAudioDevicePropertyBufferFrameSize:
  211066. case kAudioDevicePropertyNominalSampleRate:
  211067. case kAudioDevicePropertyStreamFormat:
  211068. case kAudioDevicePropertyDeviceIsAlive:
  211069. intern->deviceDetailsChanged();
  211070. break;
  211071. case kAudioDevicePropertyBufferSizeRange:
  211072. case kAudioDevicePropertyVolumeScalar:
  211073. case kAudioDevicePropertyMute:
  211074. case kAudioDevicePropertyPlayThru:
  211075. case kAudioDevicePropertyDataSource:
  211076. case kAudioDevicePropertyDeviceIsRunning:
  211077. break;
  211078. }
  211079. return noErr;
  211080. }
  211081. static int getAllDataSourcesForDevice (AudioDeviceID deviceID, const bool input, HeapBlock <OSType>& types)
  211082. {
  211083. AudioObjectPropertyAddress pa;
  211084. pa.mSelector = kAudioDevicePropertyDataSources;
  211085. pa.mScope = kAudioObjectPropertyScopeWildcard;
  211086. pa.mElement = kAudioObjectPropertyElementMaster;
  211087. UInt32 size = 0;
  211088. if (deviceID != 0
  211089. && OK (AudioObjectGetPropertyDataSize (deviceID, &pa, 0, 0, &size)))
  211090. {
  211091. types.calloc (size, 1);
  211092. if (OK (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, types)))
  211093. return size / (int) sizeof (OSType);
  211094. }
  211095. return 0;
  211096. }
  211097. };
  211098. class CoreAudioIODevice : public AudioIODevice
  211099. {
  211100. public:
  211101. CoreAudioIODevice (const String& deviceName,
  211102. AudioDeviceID inputDeviceId,
  211103. const int inputIndex_,
  211104. AudioDeviceID outputDeviceId,
  211105. const int outputIndex_)
  211106. : AudioIODevice (deviceName, "CoreAudio"),
  211107. inputIndex (inputIndex_),
  211108. outputIndex (outputIndex_),
  211109. isOpen_ (false),
  211110. isStarted (false)
  211111. {
  211112. internal = 0;
  211113. CoreAudioInternal* device = 0;
  211114. if (outputDeviceId == 0 || outputDeviceId == inputDeviceId)
  211115. {
  211116. jassert (inputDeviceId != 0);
  211117. device = new CoreAudioInternal (inputDeviceId);
  211118. }
  211119. else
  211120. {
  211121. device = new CoreAudioInternal (outputDeviceId);
  211122. if (inputDeviceId != 0)
  211123. {
  211124. CoreAudioInternal* secondDevice = new CoreAudioInternal (inputDeviceId);
  211125. device->inputDevice = secondDevice;
  211126. secondDevice->isSlaveDevice = true;
  211127. }
  211128. }
  211129. internal = device;
  211130. AudioObjectPropertyAddress pa;
  211131. pa.mSelector = kAudioObjectPropertySelectorWildcard;
  211132. pa.mScope = kAudioObjectPropertyScopeWildcard;
  211133. pa.mElement = kAudioObjectPropertyElementWildcard;
  211134. AudioObjectAddPropertyListener (kAudioObjectSystemObject, &pa, hardwareListenerProc, internal);
  211135. }
  211136. ~CoreAudioIODevice()
  211137. {
  211138. AudioObjectPropertyAddress pa;
  211139. pa.mSelector = kAudioObjectPropertySelectorWildcard;
  211140. pa.mScope = kAudioObjectPropertyScopeWildcard;
  211141. pa.mElement = kAudioObjectPropertyElementWildcard;
  211142. AudioObjectRemovePropertyListener (kAudioObjectSystemObject, &pa, hardwareListenerProc, internal);
  211143. delete internal;
  211144. }
  211145. const StringArray getOutputChannelNames()
  211146. {
  211147. return internal->outChanNames;
  211148. }
  211149. const StringArray getInputChannelNames()
  211150. {
  211151. if (internal->inputDevice != 0)
  211152. return internal->inputDevice->inChanNames;
  211153. else
  211154. return internal->inChanNames;
  211155. }
  211156. int getNumSampleRates()
  211157. {
  211158. return internal->sampleRates.size();
  211159. }
  211160. double getSampleRate (int index)
  211161. {
  211162. return internal->sampleRates [index];
  211163. }
  211164. int getNumBufferSizesAvailable()
  211165. {
  211166. return internal->bufferSizes.size();
  211167. }
  211168. int getBufferSizeSamples (int index)
  211169. {
  211170. return internal->bufferSizes [index];
  211171. }
  211172. int getDefaultBufferSize()
  211173. {
  211174. for (int i = 0; i < getNumBufferSizesAvailable(); ++i)
  211175. if (getBufferSizeSamples(i) >= 512)
  211176. return getBufferSizeSamples(i);
  211177. return 512;
  211178. }
  211179. const String open (const BigInteger& inputChannels,
  211180. const BigInteger& outputChannels,
  211181. double sampleRate,
  211182. int bufferSizeSamples)
  211183. {
  211184. isOpen_ = true;
  211185. if (bufferSizeSamples <= 0)
  211186. bufferSizeSamples = getDefaultBufferSize();
  211187. lastError = internal->reopen (inputChannels, outputChannels, sampleRate, bufferSizeSamples);
  211188. isOpen_ = lastError.isEmpty();
  211189. return lastError;
  211190. }
  211191. void close()
  211192. {
  211193. isOpen_ = false;
  211194. internal->stop (false);
  211195. }
  211196. bool isOpen()
  211197. {
  211198. return isOpen_;
  211199. }
  211200. int getCurrentBufferSizeSamples()
  211201. {
  211202. return internal != 0 ? internal->getBufferSize() : 512;
  211203. }
  211204. double getCurrentSampleRate()
  211205. {
  211206. return internal != 0 ? internal->getSampleRate() : 0;
  211207. }
  211208. int getCurrentBitDepth()
  211209. {
  211210. return 32; // no way to find out, so just assume it's high..
  211211. }
  211212. const BigInteger getActiveOutputChannels() const
  211213. {
  211214. return internal != 0 ? internal->activeOutputChans : BigInteger();
  211215. }
  211216. const BigInteger getActiveInputChannels() const
  211217. {
  211218. BigInteger chans;
  211219. if (internal != 0)
  211220. {
  211221. chans = internal->activeInputChans;
  211222. if (internal->inputDevice != 0)
  211223. chans |= internal->inputDevice->activeInputChans;
  211224. }
  211225. return chans;
  211226. }
  211227. int getOutputLatencyInSamples()
  211228. {
  211229. if (internal == 0)
  211230. return 0;
  211231. // this seems like a good guess at getting the latency right - comparing
  211232. // this with a round-trip measurement, it gets it to within a few millisecs
  211233. // for the built-in mac soundcard
  211234. return internal->outputLatency + internal->getBufferSize() * 2;
  211235. }
  211236. int getInputLatencyInSamples()
  211237. {
  211238. if (internal == 0)
  211239. return 0;
  211240. return internal->inputLatency + internal->getBufferSize() * 2;
  211241. }
  211242. void start (AudioIODeviceCallback* callback)
  211243. {
  211244. if (internal != 0 && ! isStarted)
  211245. {
  211246. if (callback != 0)
  211247. callback->audioDeviceAboutToStart (this);
  211248. isStarted = true;
  211249. internal->start (callback);
  211250. }
  211251. }
  211252. void stop()
  211253. {
  211254. if (isStarted && internal != 0)
  211255. {
  211256. AudioIODeviceCallback* const lastCallback = internal->callback;
  211257. isStarted = false;
  211258. internal->stop (true);
  211259. if (lastCallback != 0)
  211260. lastCallback->audioDeviceStopped();
  211261. }
  211262. }
  211263. bool isPlaying()
  211264. {
  211265. if (internal->callback == 0)
  211266. isStarted = false;
  211267. return isStarted;
  211268. }
  211269. const String getLastError()
  211270. {
  211271. return lastError;
  211272. }
  211273. int inputIndex, outputIndex;
  211274. juce_UseDebuggingNewOperator
  211275. private:
  211276. CoreAudioInternal* internal;
  211277. bool isOpen_, isStarted;
  211278. String lastError;
  211279. static OSStatus hardwareListenerProc (AudioDeviceID /*inDevice*/, UInt32 /*inLine*/, const AudioObjectPropertyAddress* pa, void* inClientData)
  211280. {
  211281. CoreAudioInternal* const intern = (CoreAudioInternal*) inClientData;
  211282. switch (pa->mSelector)
  211283. {
  211284. case kAudioHardwarePropertyDevices:
  211285. intern->deviceDetailsChanged();
  211286. break;
  211287. case kAudioHardwarePropertyDefaultOutputDevice:
  211288. case kAudioHardwarePropertyDefaultInputDevice:
  211289. case kAudioHardwarePropertyDefaultSystemOutputDevice:
  211290. break;
  211291. }
  211292. return noErr;
  211293. }
  211294. CoreAudioIODevice (const CoreAudioIODevice&);
  211295. CoreAudioIODevice& operator= (const CoreAudioIODevice&);
  211296. };
  211297. class CoreAudioIODeviceType : public AudioIODeviceType
  211298. {
  211299. public:
  211300. CoreAudioIODeviceType()
  211301. : AudioIODeviceType (T("CoreAudio")),
  211302. hasScanned (false)
  211303. {
  211304. }
  211305. ~CoreAudioIODeviceType()
  211306. {
  211307. }
  211308. void scanForDevices()
  211309. {
  211310. hasScanned = true;
  211311. inputDeviceNames.clear();
  211312. outputDeviceNames.clear();
  211313. inputIds.clear();
  211314. outputIds.clear();
  211315. UInt32 size;
  211316. AudioObjectPropertyAddress pa;
  211317. pa.mSelector = kAudioHardwarePropertyDevices;
  211318. pa.mScope = kAudioObjectPropertyScopeWildcard;
  211319. pa.mElement = kAudioObjectPropertyElementMaster;
  211320. if (OK (AudioObjectGetPropertyDataSize (kAudioObjectSystemObject, &pa, 0, 0, &size)))
  211321. {
  211322. HeapBlock <AudioDeviceID> devs;
  211323. devs.calloc (size, 1);
  211324. if (OK (AudioObjectGetPropertyData (kAudioObjectSystemObject, &pa, 0, 0, &size, devs)))
  211325. {
  211326. static bool alreadyLogged = false;
  211327. const int num = size / (int) sizeof (AudioDeviceID);
  211328. for (int i = 0; i < num; ++i)
  211329. {
  211330. char name [1024];
  211331. size = sizeof (name);
  211332. pa.mSelector = kAudioDevicePropertyDeviceName;
  211333. if (OK (AudioObjectGetPropertyData (devs[i], &pa, 0, 0, &size, name)))
  211334. {
  211335. const String nameString (String::fromUTF8 (name, (int) strlen (name)));
  211336. if (! alreadyLogged)
  211337. log (T("CoreAudio device: ") + nameString);
  211338. const int numIns = getNumChannels (devs[i], true);
  211339. const int numOuts = getNumChannels (devs[i], false);
  211340. if (numIns > 0)
  211341. {
  211342. inputDeviceNames.add (nameString);
  211343. inputIds.add (devs[i]);
  211344. }
  211345. if (numOuts > 0)
  211346. {
  211347. outputDeviceNames.add (nameString);
  211348. outputIds.add (devs[i]);
  211349. }
  211350. }
  211351. }
  211352. alreadyLogged = true;
  211353. }
  211354. }
  211355. inputDeviceNames.appendNumbersToDuplicates (false, true);
  211356. outputDeviceNames.appendNumbersToDuplicates (false, true);
  211357. }
  211358. const StringArray getDeviceNames (const bool wantInputNames) const
  211359. {
  211360. jassert (hasScanned); // need to call scanForDevices() before doing this
  211361. if (wantInputNames)
  211362. return inputDeviceNames;
  211363. else
  211364. return outputDeviceNames;
  211365. }
  211366. int getDefaultDeviceIndex (const bool forInput) const
  211367. {
  211368. jassert (hasScanned); // need to call scanForDevices() before doing this
  211369. AudioDeviceID deviceID;
  211370. UInt32 size = sizeof (deviceID);
  211371. // if they're asking for any input channels at all, use the default input, so we
  211372. // get the built-in mic rather than the built-in output with no inputs..
  211373. AudioObjectPropertyAddress pa;
  211374. pa.mSelector = forInput ? kAudioHardwarePropertyDefaultInputDevice : kAudioHardwarePropertyDefaultOutputDevice;
  211375. pa.mScope = kAudioObjectPropertyScopeWildcard;
  211376. pa.mElement = kAudioObjectPropertyElementMaster;
  211377. if (AudioObjectGetPropertyData (kAudioObjectSystemObject, &pa, 0, 0, &size, &deviceID) == noErr)
  211378. {
  211379. if (forInput)
  211380. {
  211381. for (int i = inputIds.size(); --i >= 0;)
  211382. if (inputIds[i] == deviceID)
  211383. return i;
  211384. }
  211385. else
  211386. {
  211387. for (int i = outputIds.size(); --i >= 0;)
  211388. if (outputIds[i] == deviceID)
  211389. return i;
  211390. }
  211391. }
  211392. return 0;
  211393. }
  211394. int getIndexOfDevice (AudioIODevice* device, const bool asInput) const
  211395. {
  211396. jassert (hasScanned); // need to call scanForDevices() before doing this
  211397. CoreAudioIODevice* const d = dynamic_cast <CoreAudioIODevice*> (device);
  211398. if (d == 0)
  211399. return -1;
  211400. return asInput ? d->inputIndex
  211401. : d->outputIndex;
  211402. }
  211403. bool hasSeparateInputsAndOutputs() const { return true; }
  211404. AudioIODevice* createDevice (const String& outputDeviceName,
  211405. const String& inputDeviceName)
  211406. {
  211407. jassert (hasScanned); // need to call scanForDevices() before doing this
  211408. const int inputIndex = inputDeviceNames.indexOf (inputDeviceName);
  211409. const int outputIndex = outputDeviceNames.indexOf (outputDeviceName);
  211410. String deviceName (outputDeviceName);
  211411. if (deviceName.isEmpty())
  211412. deviceName = inputDeviceName;
  211413. if (index >= 0)
  211414. return new CoreAudioIODevice (deviceName,
  211415. inputIds [inputIndex],
  211416. inputIndex,
  211417. outputIds [outputIndex],
  211418. outputIndex);
  211419. return 0;
  211420. }
  211421. juce_UseDebuggingNewOperator
  211422. private:
  211423. StringArray inputDeviceNames, outputDeviceNames;
  211424. Array <AudioDeviceID> inputIds, outputIds;
  211425. bool hasScanned;
  211426. static int getNumChannels (AudioDeviceID deviceID, bool input)
  211427. {
  211428. int total = 0;
  211429. UInt32 size;
  211430. AudioObjectPropertyAddress pa;
  211431. pa.mSelector = kAudioDevicePropertyStreamConfiguration;
  211432. pa.mScope = input ? kAudioDevicePropertyScopeInput : kAudioDevicePropertyScopeOutput;
  211433. pa.mElement = kAudioObjectPropertyElementMaster;
  211434. if (OK (AudioObjectGetPropertyDataSize (deviceID, &pa, 0, 0, &size)))
  211435. {
  211436. HeapBlock <AudioBufferList> bufList;
  211437. bufList.calloc (size, 1);
  211438. if (OK (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, bufList)))
  211439. {
  211440. const int numStreams = bufList->mNumberBuffers;
  211441. for (int i = 0; i < numStreams; ++i)
  211442. {
  211443. const AudioBuffer& b = bufList->mBuffers[i];
  211444. total += b.mNumberChannels;
  211445. }
  211446. }
  211447. }
  211448. return total;
  211449. }
  211450. CoreAudioIODeviceType (const CoreAudioIODeviceType&);
  211451. CoreAudioIODeviceType& operator= (const CoreAudioIODeviceType&);
  211452. };
  211453. AudioIODeviceType* juce_createAudioIODeviceType_CoreAudio()
  211454. {
  211455. return new CoreAudioIODeviceType();
  211456. }
  211457. #undef log
  211458. #endif
  211459. /*** End of inlined file: juce_mac_CoreAudio.cpp ***/
  211460. /*** Start of inlined file: juce_mac_CoreMidi.cpp ***/
  211461. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  211462. // compiled on its own).
  211463. #if JUCE_INCLUDED_FILE
  211464. #if JUCE_MAC
  211465. #undef log
  211466. #define log(a) Logger::writeToLog(a)
  211467. static bool logAnyErrorsMidi (const OSStatus err, const int lineNum)
  211468. {
  211469. if (err == noErr)
  211470. return true;
  211471. log (T("CoreMidi error: ") + String (lineNum) + T(" - ") + String::toHexString ((int)err));
  211472. jassertfalse
  211473. return false;
  211474. }
  211475. #undef OK
  211476. #define OK(a) logAnyErrorsMidi(a, __LINE__)
  211477. static const String getEndpointName (MIDIEndpointRef endpoint, bool isExternal)
  211478. {
  211479. String result;
  211480. CFStringRef str = 0;
  211481. MIDIObjectGetStringProperty (endpoint, kMIDIPropertyName, &str);
  211482. if (str != 0)
  211483. {
  211484. result = PlatformUtilities::cfStringToJuceString (str);
  211485. CFRelease (str);
  211486. str = 0;
  211487. }
  211488. MIDIEntityRef entity = 0;
  211489. MIDIEndpointGetEntity (endpoint, &entity);
  211490. if (entity == 0)
  211491. return result; // probably virtual
  211492. if (result.isEmpty())
  211493. {
  211494. // endpoint name has zero length - try the entity
  211495. MIDIObjectGetStringProperty (entity, kMIDIPropertyName, &str);
  211496. if (str != 0)
  211497. {
  211498. result += PlatformUtilities::cfStringToJuceString (str);
  211499. CFRelease (str);
  211500. str = 0;
  211501. }
  211502. }
  211503. // now consider the device's name
  211504. MIDIDeviceRef device = 0;
  211505. MIDIEntityGetDevice (entity, &device);
  211506. if (device == 0)
  211507. return result;
  211508. MIDIObjectGetStringProperty (device, kMIDIPropertyName, &str);
  211509. if (str != 0)
  211510. {
  211511. const String s (PlatformUtilities::cfStringToJuceString (str));
  211512. CFRelease (str);
  211513. // if an external device has only one entity, throw away
  211514. // the endpoint name and just use the device name
  211515. if (isExternal && MIDIDeviceGetNumberOfEntities (device) < 2)
  211516. {
  211517. result = s;
  211518. }
  211519. else if (! result.startsWithIgnoreCase (s))
  211520. {
  211521. // prepend the device name to the entity name
  211522. result = (s + T(" ") + result).trimEnd();
  211523. }
  211524. }
  211525. return result;
  211526. }
  211527. static const String getConnectedEndpointName (MIDIEndpointRef endpoint)
  211528. {
  211529. String result;
  211530. // Does the endpoint have connections?
  211531. CFDataRef connections = 0;
  211532. int numConnections = 0;
  211533. MIDIObjectGetDataProperty (endpoint, kMIDIPropertyConnectionUniqueID, &connections);
  211534. if (connections != 0)
  211535. {
  211536. numConnections = (int) (CFDataGetLength (connections) / sizeof (MIDIUniqueID));
  211537. if (numConnections > 0)
  211538. {
  211539. const SInt32* pid = reinterpret_cast <const SInt32*> (CFDataGetBytePtr (connections));
  211540. for (int i = 0; i < numConnections; ++i, ++pid)
  211541. {
  211542. MIDIUniqueID uid = EndianS32_BtoN (*pid);
  211543. MIDIObjectRef connObject;
  211544. MIDIObjectType connObjectType;
  211545. OSStatus err = MIDIObjectFindByUniqueID (uid, &connObject, &connObjectType);
  211546. if (err == noErr)
  211547. {
  211548. String s;
  211549. if (connObjectType == kMIDIObjectType_ExternalSource
  211550. || connObjectType == kMIDIObjectType_ExternalDestination)
  211551. {
  211552. // Connected to an external device's endpoint (10.3 and later).
  211553. s = getEndpointName (static_cast <MIDIEndpointRef> (connObject), true);
  211554. }
  211555. else
  211556. {
  211557. // Connected to an external device (10.2) (or something else, catch-all)
  211558. CFStringRef str = 0;
  211559. MIDIObjectGetStringProperty (connObject, kMIDIPropertyName, &str);
  211560. if (str != 0)
  211561. {
  211562. s = PlatformUtilities::cfStringToJuceString (str);
  211563. CFRelease (str);
  211564. }
  211565. }
  211566. if (s.isNotEmpty())
  211567. {
  211568. if (result.isNotEmpty())
  211569. result += (", ");
  211570. result += s;
  211571. }
  211572. }
  211573. }
  211574. }
  211575. CFRelease (connections);
  211576. }
  211577. if (result.isNotEmpty())
  211578. return result;
  211579. // Here, either the endpoint had no connections, or we failed to obtain names for any of them.
  211580. return getEndpointName (endpoint, false);
  211581. }
  211582. const StringArray MidiOutput::getDevices()
  211583. {
  211584. StringArray s;
  211585. const ItemCount num = MIDIGetNumberOfDestinations();
  211586. for (ItemCount i = 0; i < num; ++i)
  211587. {
  211588. MIDIEndpointRef dest = MIDIGetDestination (i);
  211589. if (dest != 0)
  211590. {
  211591. String name (getConnectedEndpointName (dest));
  211592. if (name.isEmpty())
  211593. name = "<error>";
  211594. s.add (name);
  211595. }
  211596. else
  211597. {
  211598. s.add ("<error>");
  211599. }
  211600. }
  211601. return s;
  211602. }
  211603. int MidiOutput::getDefaultDeviceIndex()
  211604. {
  211605. return 0;
  211606. }
  211607. static MIDIClientRef globalMidiClient;
  211608. static bool hasGlobalClientBeenCreated = false;
  211609. static bool makeSureClientExists()
  211610. {
  211611. if (! hasGlobalClientBeenCreated)
  211612. {
  211613. String name (T("JUCE"));
  211614. if (JUCEApplication::getInstance() != 0)
  211615. name = JUCEApplication::getInstance()->getApplicationName();
  211616. CFStringRef appName = PlatformUtilities::juceStringToCFString (name);
  211617. hasGlobalClientBeenCreated = OK (MIDIClientCreate (appName, 0, 0, &globalMidiClient));
  211618. CFRelease (appName);
  211619. }
  211620. return hasGlobalClientBeenCreated;
  211621. }
  211622. class MidiPortAndEndpoint
  211623. {
  211624. public:
  211625. MidiPortAndEndpoint (MIDIPortRef port_, MIDIEndpointRef endPoint_)
  211626. : port (port_), endPoint (endPoint_)
  211627. {
  211628. }
  211629. ~MidiPortAndEndpoint()
  211630. {
  211631. if (port != 0)
  211632. MIDIPortDispose (port);
  211633. if (port == 0 && endPoint != 0) // if port == 0, it means we created the endpoint, so it's safe to delete it
  211634. MIDIEndpointDispose (endPoint);
  211635. }
  211636. MIDIPortRef port;
  211637. MIDIEndpointRef endPoint;
  211638. };
  211639. MidiOutput* MidiOutput::openDevice (int index)
  211640. {
  211641. MidiOutput* mo = 0;
  211642. if (((unsigned int) index) < (unsigned int) MIDIGetNumberOfDestinations())
  211643. {
  211644. MIDIEndpointRef endPoint = MIDIGetDestination (index);
  211645. CFStringRef pname;
  211646. if (OK (MIDIObjectGetStringProperty (endPoint, kMIDIPropertyName, &pname)))
  211647. {
  211648. log (T("CoreMidi - opening out: ") + PlatformUtilities::cfStringToJuceString (pname));
  211649. if (makeSureClientExists())
  211650. {
  211651. MIDIPortRef port;
  211652. if (OK (MIDIOutputPortCreate (globalMidiClient, pname, &port)))
  211653. {
  211654. mo = new MidiOutput();
  211655. mo->internal = (void*) new MidiPortAndEndpoint (port, endPoint);
  211656. }
  211657. }
  211658. CFRelease (pname);
  211659. }
  211660. }
  211661. return mo;
  211662. }
  211663. MidiOutput* MidiOutput::createNewDevice (const String& deviceName)
  211664. {
  211665. MidiOutput* mo = 0;
  211666. if (makeSureClientExists())
  211667. {
  211668. MIDIEndpointRef endPoint;
  211669. CFStringRef name = PlatformUtilities::juceStringToCFString (deviceName);
  211670. if (OK (MIDISourceCreate (globalMidiClient, name, &endPoint)))
  211671. {
  211672. mo = new MidiOutput();
  211673. mo->internal = (void*) new MidiPortAndEndpoint (0, endPoint);
  211674. }
  211675. CFRelease (name);
  211676. }
  211677. return mo;
  211678. }
  211679. MidiOutput::~MidiOutput()
  211680. {
  211681. delete (MidiPortAndEndpoint*) internal;
  211682. }
  211683. void MidiOutput::reset()
  211684. {
  211685. }
  211686. bool MidiOutput::getVolume (float& leftVol, float& rightVol)
  211687. {
  211688. return false;
  211689. }
  211690. void MidiOutput::setVolume (float leftVol, float rightVol)
  211691. {
  211692. }
  211693. void MidiOutput::sendMessageNow (const MidiMessage& message)
  211694. {
  211695. MidiPortAndEndpoint* const mpe = (MidiPortAndEndpoint*) internal;
  211696. if (message.isSysEx())
  211697. {
  211698. const int maxPacketSize = 256;
  211699. int pos = 0, bytesLeft = message.getRawDataSize();
  211700. const int numPackets = (bytesLeft + maxPacketSize - 1) / maxPacketSize;
  211701. HeapBlock <MIDIPacketList> packets;
  211702. packets.malloc (32 * numPackets + message.getRawDataSize(), 1);
  211703. packets->numPackets = numPackets;
  211704. MIDIPacket* p = packets->packet;
  211705. for (int i = 0; i < numPackets; ++i)
  211706. {
  211707. p->timeStamp = 0;
  211708. p->length = jmin (maxPacketSize, bytesLeft);
  211709. memcpy (p->data, message.getRawData() + pos, p->length);
  211710. pos += p->length;
  211711. bytesLeft -= p->length;
  211712. p = MIDIPacketNext (p);
  211713. }
  211714. if (mpe->port != 0)
  211715. MIDISend (mpe->port, mpe->endPoint, packets);
  211716. else
  211717. MIDIReceived (mpe->endPoint, packets);
  211718. }
  211719. else
  211720. {
  211721. MIDIPacketList packets;
  211722. packets.numPackets = 1;
  211723. packets.packet[0].timeStamp = 0;
  211724. packets.packet[0].length = message.getRawDataSize();
  211725. *(int*) (packets.packet[0].data) = *(const int*) message.getRawData();
  211726. if (mpe->port != 0)
  211727. MIDISend (mpe->port, mpe->endPoint, &packets);
  211728. else
  211729. MIDIReceived (mpe->endPoint, &packets);
  211730. }
  211731. }
  211732. const StringArray MidiInput::getDevices()
  211733. {
  211734. StringArray s;
  211735. const ItemCount num = MIDIGetNumberOfSources();
  211736. for (ItemCount i = 0; i < num; ++i)
  211737. {
  211738. MIDIEndpointRef source = MIDIGetSource (i);
  211739. if (source != 0)
  211740. {
  211741. String name (getConnectedEndpointName (source));
  211742. if (name.isEmpty())
  211743. name = "<error>";
  211744. s.add (name);
  211745. }
  211746. else
  211747. {
  211748. s.add ("<error>");
  211749. }
  211750. }
  211751. return s;
  211752. }
  211753. int MidiInput::getDefaultDeviceIndex()
  211754. {
  211755. return 0;
  211756. }
  211757. struct MidiPortAndCallback
  211758. {
  211759. MidiInput* input;
  211760. MidiPortAndEndpoint* portAndEndpoint;
  211761. MidiInputCallback* callback;
  211762. MemoryBlock pendingData;
  211763. int pendingBytes;
  211764. double pendingDataTime;
  211765. bool active;
  211766. void processSysex (const uint8*& d, int& size, const double time)
  211767. {
  211768. if (*d == 0xf0)
  211769. {
  211770. pendingBytes = 0;
  211771. pendingDataTime = time;
  211772. }
  211773. pendingData.ensureSize (pendingBytes + size, false);
  211774. uint8* totalMessage = (uint8*) pendingData.getData();
  211775. uint8* dest = totalMessage + pendingBytes;
  211776. while (size > 0)
  211777. {
  211778. if (pendingBytes > 0 && *d >= 0x80)
  211779. {
  211780. if (*d >= 0xfa || *d == 0xf8)
  211781. {
  211782. callback->handleIncomingMidiMessage (input, MidiMessage (*d, time));
  211783. ++d;
  211784. --size;
  211785. }
  211786. else
  211787. {
  211788. if (*d == 0xf7)
  211789. {
  211790. *dest++ = *d++;
  211791. pendingBytes++;
  211792. --size;
  211793. }
  211794. break;
  211795. }
  211796. }
  211797. else
  211798. {
  211799. *dest++ = *d++;
  211800. pendingBytes++;
  211801. --size;
  211802. }
  211803. }
  211804. if (totalMessage [pendingBytes - 1] == 0xf7)
  211805. {
  211806. callback->handleIncomingMidiMessage (input, MidiMessage (totalMessage, pendingBytes, pendingDataTime));
  211807. pendingBytes = 0;
  211808. }
  211809. else
  211810. {
  211811. callback->handlePartialSysexMessage (input, totalMessage, pendingBytes, pendingDataTime);
  211812. }
  211813. }
  211814. };
  211815. namespace CoreMidiCallbacks
  211816. {
  211817. static CriticalSection callbackLock;
  211818. static VoidArray activeCallbacks;
  211819. }
  211820. static void midiInputProc (const MIDIPacketList* pktlist,
  211821. void* readProcRefCon,
  211822. void* srcConnRefCon)
  211823. {
  211824. double time = Time::getMillisecondCounterHiRes() * 0.001;
  211825. const double originalTime = time;
  211826. MidiPortAndCallback* const mpc = (MidiPortAndCallback*) readProcRefCon;
  211827. const ScopedLock sl (CoreMidiCallbacks::callbackLock);
  211828. if (CoreMidiCallbacks::activeCallbacks.contains (mpc) && mpc->active)
  211829. {
  211830. const MIDIPacket* packet = &pktlist->packet[0];
  211831. for (unsigned int i = 0; i < pktlist->numPackets; ++i)
  211832. {
  211833. const uint8* d = (const uint8*) (packet->data);
  211834. int size = packet->length;
  211835. while (size > 0)
  211836. {
  211837. time = originalTime;
  211838. if (mpc->pendingBytes > 0 || d[0] == 0xf0)
  211839. {
  211840. mpc->processSysex (d, size, time);
  211841. }
  211842. else
  211843. {
  211844. int used = 0;
  211845. const MidiMessage m (d, size, used, 0, time);
  211846. if (used <= 0)
  211847. {
  211848. jassertfalse // malformed midi message
  211849. break;
  211850. }
  211851. else
  211852. {
  211853. mpc->callback->handleIncomingMidiMessage (mpc->input, m);
  211854. }
  211855. size -= used;
  211856. d += used;
  211857. }
  211858. }
  211859. packet = MIDIPacketNext (packet);
  211860. }
  211861. }
  211862. }
  211863. MidiInput* MidiInput::openDevice (int index, MidiInputCallback* callback)
  211864. {
  211865. MidiInput* mi = 0;
  211866. if (((unsigned int) index) < (unsigned int) MIDIGetNumberOfSources())
  211867. {
  211868. MIDIEndpointRef endPoint = MIDIGetSource (index);
  211869. if (endPoint != 0)
  211870. {
  211871. CFStringRef pname;
  211872. if (OK (MIDIObjectGetStringProperty (endPoint, kMIDIPropertyName, &pname)))
  211873. {
  211874. log (T("CoreMidi - opening inp: ") + PlatformUtilities::cfStringToJuceString (pname));
  211875. if (makeSureClientExists())
  211876. {
  211877. MIDIPortRef port;
  211878. ScopedPointer <MidiPortAndCallback> mpc (new MidiPortAndCallback());
  211879. mpc->active = false;
  211880. if (OK (MIDIInputPortCreate (globalMidiClient, pname, midiInputProc, mpc, &port)))
  211881. {
  211882. if (OK (MIDIPortConnectSource (port, endPoint, 0)))
  211883. {
  211884. mpc->portAndEndpoint = new MidiPortAndEndpoint (port, endPoint);
  211885. mpc->callback = callback;
  211886. mpc->pendingBytes = 0;
  211887. mpc->pendingData.ensureSize (128);
  211888. mi = new MidiInput (getDevices() [index]);
  211889. mpc->input = mi;
  211890. mi->internal = (void*) mpc;
  211891. const ScopedLock sl (CoreMidiCallbacks::callbackLock);
  211892. CoreMidiCallbacks::activeCallbacks.add (mpc.release());
  211893. }
  211894. else
  211895. {
  211896. OK (MIDIPortDispose (port));
  211897. }
  211898. }
  211899. }
  211900. }
  211901. CFRelease (pname);
  211902. }
  211903. }
  211904. return mi;
  211905. }
  211906. MidiInput* MidiInput::createNewDevice (const String& deviceName, MidiInputCallback* callback)
  211907. {
  211908. MidiInput* mi = 0;
  211909. if (makeSureClientExists())
  211910. {
  211911. ScopedPointer <MidiPortAndCallback> mpc (new MidiPortAndCallback());
  211912. mpc->active = false;
  211913. MIDIEndpointRef endPoint;
  211914. CFStringRef name = PlatformUtilities::juceStringToCFString(deviceName);
  211915. if (OK (MIDIDestinationCreate (globalMidiClient, name, midiInputProc, mpc, &endPoint)))
  211916. {
  211917. mpc->portAndEndpoint = new MidiPortAndEndpoint (0, endPoint);
  211918. mpc->callback = callback;
  211919. mpc->pendingBytes = 0;
  211920. mpc->pendingData.ensureSize (128);
  211921. mi = new MidiInput (deviceName);
  211922. mpc->input = mi;
  211923. mi->internal = (void*) mpc;
  211924. const ScopedLock sl (CoreMidiCallbacks::callbackLock);
  211925. CoreMidiCallbacks::activeCallbacks.add (mpc.release());
  211926. }
  211927. CFRelease (name);
  211928. }
  211929. return mi;
  211930. }
  211931. MidiInput::MidiInput (const String& name_)
  211932. : name (name_)
  211933. {
  211934. }
  211935. MidiInput::~MidiInput()
  211936. {
  211937. MidiPortAndCallback* const mpc = (MidiPortAndCallback*) internal;
  211938. mpc->active = false;
  211939. {
  211940. const ScopedLock sl (CoreMidiCallbacks::callbackLock);
  211941. CoreMidiCallbacks::activeCallbacks.removeValue (mpc);
  211942. }
  211943. if (mpc->portAndEndpoint->port != 0)
  211944. OK (MIDIPortDisconnectSource (mpc->portAndEndpoint->port, mpc->portAndEndpoint->endPoint));
  211945. delete mpc->portAndEndpoint;
  211946. delete mpc;
  211947. }
  211948. void MidiInput::start()
  211949. {
  211950. const ScopedLock sl (CoreMidiCallbacks::callbackLock);
  211951. ((MidiPortAndCallback*) internal)->active = true;
  211952. }
  211953. void MidiInput::stop()
  211954. {
  211955. const ScopedLock sl (CoreMidiCallbacks::callbackLock);
  211956. ((MidiPortAndCallback*) internal)->active = false;
  211957. }
  211958. #undef log
  211959. #else
  211960. MidiOutput::~MidiOutput()
  211961. {
  211962. }
  211963. void MidiOutput::reset()
  211964. {
  211965. }
  211966. bool MidiOutput::getVolume (float& leftVol, float& rightVol)
  211967. {
  211968. return false;
  211969. }
  211970. void MidiOutput::setVolume (float leftVol, float rightVol)
  211971. {
  211972. }
  211973. void MidiOutput::sendMessageNow (const MidiMessage& message)
  211974. {
  211975. }
  211976. const StringArray MidiOutput::getDevices()
  211977. {
  211978. return StringArray();
  211979. }
  211980. MidiOutput* MidiOutput::openDevice (int index)
  211981. {
  211982. return 0;
  211983. }
  211984. const StringArray MidiInput::getDevices()
  211985. {
  211986. return StringArray();
  211987. }
  211988. MidiInput* MidiInput::openDevice (int index, MidiInputCallback* callback)
  211989. {
  211990. return 0;
  211991. }
  211992. #endif
  211993. #endif
  211994. /*** End of inlined file: juce_mac_CoreMidi.cpp ***/
  211995. /*** Start of inlined file: juce_mac_CameraDevice.mm ***/
  211996. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  211997. // compiled on its own).
  211998. #if JUCE_INCLUDED_FILE && JUCE_USE_CAMERA
  211999. #if ! JUCE_QUICKTIME
  212000. #error "On the Mac, cameras use Quicktime, so if you turn on JUCE_USE_CAMERA, you also need to enable JUCE_QUICKTIME"
  212001. #endif
  212002. #define QTCaptureCallbackDelegate MakeObjCClassName(QTCaptureCallbackDelegate)
  212003. class QTCameraDeviceInteral;
  212004. END_JUCE_NAMESPACE
  212005. @interface QTCaptureCallbackDelegate : NSObject
  212006. {
  212007. @public
  212008. CameraDevice* owner;
  212009. QTCameraDeviceInteral* internal;
  212010. int64 firstPresentationTime;
  212011. int64 averageTimeOffset;
  212012. }
  212013. - (QTCaptureCallbackDelegate*) initWithOwner: (CameraDevice*) owner internalDev: (QTCameraDeviceInteral*) d;
  212014. - (void) dealloc;
  212015. - (void) captureOutput: (QTCaptureOutput*) captureOutput
  212016. didOutputVideoFrame: (CVImageBufferRef) videoFrame
  212017. withSampleBuffer: (QTSampleBuffer*) sampleBuffer
  212018. fromConnection: (QTCaptureConnection*) connection;
  212019. - (void) captureOutput: (QTCaptureFileOutput*) captureOutput
  212020. didOutputSampleBuffer: (QTSampleBuffer*) sampleBuffer
  212021. fromConnection: (QTCaptureConnection*) connection;
  212022. @end
  212023. BEGIN_JUCE_NAMESPACE
  212024. class QTCameraDeviceInteral
  212025. {
  212026. public:
  212027. QTCameraDeviceInteral (CameraDevice* owner, int index)
  212028. {
  212029. const ScopedAutoReleasePool pool;
  212030. session = [[QTCaptureSession alloc] init];
  212031. NSArray* devs = [QTCaptureDevice inputDevicesWithMediaType: QTMediaTypeVideo];
  212032. device = (QTCaptureDevice*) [devs objectAtIndex: index];
  212033. input = 0;
  212034. audioInput = 0;
  212035. audioDevice = 0;
  212036. fileOutput = 0;
  212037. imageOutput = 0;
  212038. callbackDelegate = [[QTCaptureCallbackDelegate alloc] initWithOwner: owner
  212039. internalDev: this];
  212040. NSError* err = 0;
  212041. [device retain];
  212042. [device open: &err];
  212043. if (err == 0)
  212044. {
  212045. input = [[QTCaptureDeviceInput alloc] initWithDevice: device];
  212046. audioInput = [[QTCaptureDeviceInput alloc] initWithDevice: device];
  212047. [session addInput: input error: &err];
  212048. if (err == 0)
  212049. {
  212050. resetFile();
  212051. imageOutput = [[QTCaptureDecompressedVideoOutput alloc] init];
  212052. [imageOutput setDelegate: callbackDelegate];
  212053. if (err == 0)
  212054. {
  212055. [session startRunning];
  212056. return;
  212057. }
  212058. }
  212059. }
  212060. openingError = nsStringToJuce ([err description]);
  212061. DBG (openingError);
  212062. }
  212063. ~QTCameraDeviceInteral()
  212064. {
  212065. [session stopRunning];
  212066. [session removeOutput: imageOutput];
  212067. [session release];
  212068. [input release];
  212069. [device release];
  212070. [audioDevice release];
  212071. [audioInput release];
  212072. [fileOutput release];
  212073. [imageOutput release];
  212074. [callbackDelegate release];
  212075. }
  212076. void resetFile()
  212077. {
  212078. [fileOutput recordToOutputFileURL: nil];
  212079. [session removeOutput: fileOutput];
  212080. [fileOutput release];
  212081. fileOutput = [[QTCaptureMovieFileOutput alloc] init];
  212082. [session removeInput: audioInput];
  212083. [audioInput release];
  212084. audioInput = 0;
  212085. [audioDevice release];
  212086. audioDevice = 0;
  212087. [fileOutput setDelegate: callbackDelegate];
  212088. }
  212089. void addDefaultAudioInput()
  212090. {
  212091. NSError* err = nil;
  212092. audioDevice = [QTCaptureDevice defaultInputDeviceWithMediaType: QTMediaTypeSound];
  212093. if ([audioDevice open: &err])
  212094. [audioDevice retain];
  212095. else
  212096. audioDevice = nil;
  212097. if (audioDevice != 0)
  212098. {
  212099. audioInput = [[QTCaptureDeviceInput alloc] initWithDevice: audioDevice];
  212100. [session addInput: audioInput error: &err];
  212101. }
  212102. }
  212103. void addListener (CameraImageListener* listenerToAdd)
  212104. {
  212105. const ScopedLock sl (listenerLock);
  212106. if (listeners.size() == 0)
  212107. [session addOutput: imageOutput error: nil];
  212108. listeners.addIfNotAlreadyThere (listenerToAdd);
  212109. }
  212110. void removeListener (CameraImageListener* listenerToRemove)
  212111. {
  212112. const ScopedLock sl (listenerLock);
  212113. listeners.removeValue (listenerToRemove);
  212114. if (listeners.size() == 0)
  212115. [session removeOutput: imageOutput];
  212116. }
  212117. void callListeners (CIImage* frame, int w, int h)
  212118. {
  212119. CoreGraphicsImage image (Image::ARGB, w, h, false);
  212120. CIContext* cic = [CIContext contextWithCGContext: image.context options: nil];
  212121. [cic drawImage: frame inRect: CGRectMake (0, 0, w, h) fromRect: CGRectMake (0, 0, w, h)];
  212122. CGContextFlush (image.context);
  212123. const ScopedLock sl (listenerLock);
  212124. for (int i = listeners.size(); --i >= 0;)
  212125. {
  212126. CameraImageListener* l = (CameraImageListener*) listeners[i];
  212127. if (l != 0)
  212128. l->imageReceived (image);
  212129. }
  212130. }
  212131. QTCaptureDevice* device;
  212132. QTCaptureDeviceInput* input;
  212133. QTCaptureDevice* audioDevice;
  212134. QTCaptureDeviceInput* audioInput;
  212135. QTCaptureSession* session;
  212136. QTCaptureMovieFileOutput* fileOutput;
  212137. QTCaptureDecompressedVideoOutput* imageOutput;
  212138. QTCaptureCallbackDelegate* callbackDelegate;
  212139. String openingError;
  212140. VoidArray listeners;
  212141. CriticalSection listenerLock;
  212142. };
  212143. END_JUCE_NAMESPACE
  212144. @implementation QTCaptureCallbackDelegate
  212145. - (QTCaptureCallbackDelegate*) initWithOwner: (CameraDevice*) owner_
  212146. internalDev: (QTCameraDeviceInteral*) d
  212147. {
  212148. [super init];
  212149. owner = owner_;
  212150. internal = d;
  212151. firstPresentationTime = 0;
  212152. averageTimeOffset = 0;
  212153. return self;
  212154. }
  212155. - (void) dealloc
  212156. {
  212157. [super dealloc];
  212158. }
  212159. - (void) captureOutput: (QTCaptureOutput*) captureOutput
  212160. didOutputVideoFrame: (CVImageBufferRef) videoFrame
  212161. withSampleBuffer: (QTSampleBuffer*) sampleBuffer
  212162. fromConnection: (QTCaptureConnection*) connection
  212163. {
  212164. if (internal->listeners.size() > 0)
  212165. {
  212166. const ScopedAutoReleasePool pool;
  212167. internal->callListeners ([CIImage imageWithCVImageBuffer: videoFrame],
  212168. CVPixelBufferGetWidth (videoFrame),
  212169. CVPixelBufferGetHeight (videoFrame));
  212170. }
  212171. }
  212172. - (void) captureOutput: (QTCaptureFileOutput*) captureOutput
  212173. didOutputSampleBuffer: (QTSampleBuffer*) sampleBuffer
  212174. fromConnection: (QTCaptureConnection*) connection
  212175. {
  212176. const Time now (Time::getCurrentTime());
  212177. #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
  212178. NSNumber* hosttime = (NSNumber*) [sampleBuffer attributeForKey: QTSampleBufferHostTimeAttribute];
  212179. #else
  212180. NSNumber* hosttime = (NSNumber*) [sampleBuffer attributeForKey: @"hostTime"];
  212181. #endif
  212182. int64 presentationTime = (hosttime != nil)
  212183. ? ((int64) AudioConvertHostTimeToNanos ([hosttime unsignedLongLongValue]) / 1000000 + 40)
  212184. : (([sampleBuffer presentationTime].timeValue * 1000) / [sampleBuffer presentationTime].timeScale + 50);
  212185. const int64 timeDiff = now.toMilliseconds() - presentationTime;
  212186. if (firstPresentationTime == 0)
  212187. {
  212188. firstPresentationTime = presentationTime;
  212189. averageTimeOffset = timeDiff;
  212190. }
  212191. else
  212192. {
  212193. averageTimeOffset = (averageTimeOffset * 120 + timeDiff * 8) / 128;
  212194. }
  212195. }
  212196. @end
  212197. BEGIN_JUCE_NAMESPACE
  212198. class QTCaptureViewerComp : public NSViewComponent
  212199. {
  212200. public:
  212201. QTCaptureViewerComp (CameraDevice* const cameraDevice, QTCameraDeviceInteral* const internal)
  212202. {
  212203. const ScopedAutoReleasePool pool;
  212204. captureView = [[QTCaptureView alloc] init];
  212205. [captureView setCaptureSession: internal->session];
  212206. setSize (640, 480); // xxx need to somehow get the movie size - how?
  212207. setView (captureView);
  212208. }
  212209. ~QTCaptureViewerComp()
  212210. {
  212211. setView (0);
  212212. [captureView setCaptureSession: nil];
  212213. [captureView release];
  212214. }
  212215. QTCaptureView* captureView;
  212216. };
  212217. CameraDevice::CameraDevice (const String& name_, int index)
  212218. : name (name_)
  212219. {
  212220. isRecording = false;
  212221. internal = new QTCameraDeviceInteral (this, index);
  212222. }
  212223. CameraDevice::~CameraDevice()
  212224. {
  212225. stopRecording();
  212226. delete static_cast <QTCameraDeviceInteral*> (internal);
  212227. internal = 0;
  212228. }
  212229. Component* CameraDevice::createViewerComponent()
  212230. {
  212231. return new QTCaptureViewerComp (this, static_cast <QTCameraDeviceInteral*> (internal));
  212232. }
  212233. const String CameraDevice::getFileExtension()
  212234. {
  212235. return ".mov";
  212236. }
  212237. void CameraDevice::startRecordingToFile (const File& file, int quality)
  212238. {
  212239. stopRecording();
  212240. QTCameraDeviceInteral* const d = static_cast <QTCameraDeviceInteral*> (internal);
  212241. d->callbackDelegate->firstPresentationTime = 0;
  212242. file.deleteFile();
  212243. // In some versions of QT (e.g. on 10.5), if you record video without audio, the speed comes
  212244. // out wrong, so we'll put some audio in there too..,
  212245. d->addDefaultAudioInput();
  212246. [d->session addOutput: d->fileOutput error: nil];
  212247. NSEnumerator* connectionEnumerator = [[d->fileOutput connections] objectEnumerator];
  212248. for (;;)
  212249. {
  212250. QTCaptureConnection* connection = [connectionEnumerator nextObject];
  212251. if (connection == 0)
  212252. break;
  212253. QTCompressionOptions* options = 0;
  212254. NSString* mediaType = [connection mediaType];
  212255. if ([mediaType isEqualToString: QTMediaTypeVideo])
  212256. options = [QTCompressionOptions compressionOptionsWithIdentifier:
  212257. quality >= 1 ? @"QTCompressionOptionsSD480SizeH264Video"
  212258. : @"QTCompressionOptions240SizeH264Video"];
  212259. else if ([mediaType isEqualToString: QTMediaTypeSound])
  212260. options = [QTCompressionOptions compressionOptionsWithIdentifier: @"QTCompressionOptionsHighQualityAACAudio"];
  212261. [d->fileOutput setCompressionOptions: options forConnection: connection];
  212262. }
  212263. [d->fileOutput recordToOutputFileURL: [NSURL fileURLWithPath: juceStringToNS (file.getFullPathName())]];
  212264. isRecording = true;
  212265. }
  212266. const Time CameraDevice::getTimeOfFirstRecordedFrame() const
  212267. {
  212268. QTCameraDeviceInteral* const d = static_cast <QTCameraDeviceInteral*> (internal);
  212269. if (d->callbackDelegate->firstPresentationTime != 0)
  212270. return Time (d->callbackDelegate->firstPresentationTime + d->callbackDelegate->averageTimeOffset);
  212271. return Time();
  212272. }
  212273. void CameraDevice::stopRecording()
  212274. {
  212275. if (isRecording)
  212276. {
  212277. static_cast <QTCameraDeviceInteral*> (internal)->resetFile();
  212278. isRecording = false;
  212279. }
  212280. }
  212281. void CameraDevice::addListener (CameraImageListener* listenerToAdd)
  212282. {
  212283. if (listenerToAdd != 0)
  212284. static_cast <QTCameraDeviceInteral*> (internal)->addListener (listenerToAdd);
  212285. }
  212286. void CameraDevice::removeListener (CameraImageListener* listenerToRemove)
  212287. {
  212288. if (listenerToRemove != 0)
  212289. static_cast <QTCameraDeviceInteral*> (internal)->removeListener (listenerToRemove);
  212290. }
  212291. const StringArray CameraDevice::getAvailableDevices()
  212292. {
  212293. const ScopedAutoReleasePool pool;
  212294. StringArray results;
  212295. NSArray* devs = [QTCaptureDevice inputDevicesWithMediaType: QTMediaTypeVideo];
  212296. for (int i = 0; i < (int) [devs count]; ++i)
  212297. {
  212298. QTCaptureDevice* dev = (QTCaptureDevice*) [devs objectAtIndex: i];
  212299. results.add (nsStringToJuce ([dev localizedDisplayName]));
  212300. }
  212301. return results;
  212302. }
  212303. CameraDevice* CameraDevice::openDevice (int index,
  212304. int minWidth, int minHeight,
  212305. int maxWidth, int maxHeight)
  212306. {
  212307. ScopedPointer <CameraDevice> d (new CameraDevice (getAvailableDevices() [index], index));
  212308. if (static_cast <QTCameraDeviceInteral*> (d->internal)->openingError.isEmpty())
  212309. return d.release();
  212310. return 0;
  212311. }
  212312. #endif
  212313. /*** End of inlined file: juce_mac_CameraDevice.mm ***/
  212314. #endif
  212315. #endif
  212316. END_JUCE_NAMESPACE
  212317. #endif
  212318. /*** End of inlined file: juce_mac_NativeCode.mm ***/
  212319. #endif
  212320. #endif